Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
dbc6ac3b
Commit
dbc6ac3b
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Plain Diff
[j.833] correct Tiff r/w, fix Galaxi example read-in (
#833
) (Closes
#833
)
Merging branch 'j.833' into 'main'. See merge request
!2132
parents
1588714c
26fe8d1a
No related branches found
No related tags found
1 merge request
!2132
correct Tiff r/w, fix Galaxi example read-in (#833)
Pipeline
#119977
passed
1 year ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Device/IO/ReadWriteTiff.cpp
+8
-22
8 additions, 22 deletions
Device/IO/ReadWriteTiff.cpp
with
8 additions
and
22 deletions
Device/IO/ReadWriteTiff.cpp
+
8
−
22
View file @
dbc6ac3b
...
...
@@ -102,13 +102,10 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
//... Read data.
const
size_t
width
=
(
size_t
)
w
;
const
size_t
height
=
(
size_t
)
h
;
ASSERT
(
0
==
bitsPerSample
%
8
);
uint16_t
bytesPerSample
=
bitsPerSample
/
8
;
tmsize_t
buf_size
=
TIFFScanlineSize
(
tiffstream
);
tmsize_t
expected_size
=
bytesPerSample
*
w
idth
;
tmsize_t
expected_size
=
bytesPerSample
*
w
;
if
(
buf_size
!=
expected_size
)
throw
std
::
runtime_error
(
"Cannot read TIFF file: wrong scanline size"
+
ref_to_doc
);
...
...
@@ -117,25 +114,19 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
throw
std
::
runtime_error
(
"Cannot read TIFF file: failed allocating buffer"
+
ref_to_doc
);
auto
data
=
std
::
make_unique
<
Datafield
>
(
std
::
vector
<
const
Scale
*>
{
newEquiDivision
(
"u (bin)"
,
w
idth
,
0.0
,
double
(
w
idth
)),
newEquiDivision
(
"v (bin)"
,
h
eight
,
0.0
,
double
(
h
eight
))});
std
::
vector
<
const
Scale
*>
{
newEquiDivision
(
"u (bin)"
,
w
,
0.0
,
double
(
w
)),
newEquiDivision
(
"v (bin)"
,
h
,
0.0
,
double
(
h
))});
std
::
vector
<
int8_t
>
line_buf
;
line_buf
.
resize
(
buf_size
,
0
);
std
::
vector
<
unsigned
>
axes_indices
(
2
);
for
(
uint32_t
row
=
0
;
row
<
(
uint32_t
)
height
;
row
++
)
{
for
(
uint32_t
row
=
0
;
row
<
h
;
row
++
)
{
if
(
TIFFReadScanline
(
tiffstream
,
buf
,
row
)
<
0
)
throw
std
::
runtime_error
(
"Cannot read TIFF file: error in scanline."
+
ref_to_doc
);
memcpy
(
&
line_buf
[
0
],
buf
,
buf_size
);
for
(
unsigned
col
=
0
;
col
<
width
;
++
col
)
{
axes_indices
[
0
]
=
col
;
axes_indices
[
1
]
=
static_cast
<
unsigned
>
(
height
)
-
1
-
row
;
size_t
global_index
=
data
->
frame
().
toGlobalIndex
(
axes_indices
);
for
(
unsigned
col
=
0
;
col
<
w
;
++
col
)
{
void
*
incoming
=
&
line_buf
[
col
*
bytesPerSample
];
double
sample
=
0
;
...
...
@@ -174,7 +165,7 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
+
ref_to_doc
);
}
(
*
data
)[
global_index
]
=
sample
;
(
*
data
)[
(
h
-
1
-
row
)
*
w
+
col
]
=
sample
;
}
}
_TIFFfree
(
buf
);
...
...
@@ -223,14 +214,9 @@ void Util::RW::writeTiff(const Datafield& data, std::ostream& output_stream)
std
::
vector
<
sample_t
>
line_buf
;
line_buf
.
resize
(
m_width
,
0
);
std
::
vector
<
unsigned
>
axes_indices
(
2
);
for
(
unsigned
row
=
0
;
row
<
(
uint32_t
)
m_height
;
row
++
)
{
for
(
unsigned
col
=
0
;
col
<
line_buf
.
size
();
++
col
)
{
axes_indices
[
0
]
=
col
;
axes_indices
[
1
]
=
static_cast
<
unsigned
>
(
m_height
)
-
1
-
row
;
const
size_t
global_index
=
data
.
frame
().
toGlobalIndex
(
axes_indices
);
line_buf
[
col
]
=
static_cast
<
sample_t
>
(
data
[
global_index
]);
}
for
(
unsigned
col
=
0
;
col
<
line_buf
.
size
();
++
col
)
line_buf
[
col
]
=
static_cast
<
sample_t
>
(
data
[(
m_height
-
1
-
row
)
*
m_width
+
col
]);
memcpy
(
buf
,
&
line_buf
[
0
],
buf_size
);
if
(
TIFFWriteScanline
(
tiffstream
,
buf
,
row
)
<
0
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment