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
a34f8026
Commit
a34f8026
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
cleanup ctd
parent
07fee311
No related branches found
No related tags found
1 merge request
!1628
simplify and unify API and code for reading or writing data files
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Device/IO/ReadWriteTiff.cpp
+17
-18
17 additions, 18 deletions
Device/IO/ReadWriteTiff.cpp
with
17 additions
and
18 deletions
Device/IO/ReadWriteTiff.cpp
+
17
−
18
View file @
a34f8026
...
...
@@ -86,19 +86,17 @@ void IO::writeTiff(const Datafield& data, std::ostream& output_stream)
Datafield
*
IO
::
readTiff
(
std
::
istream
&
input_stream
)
{
TIFF
*
m_tiff
;
uint16_t
m_bitsPerSample
,
m_samplesPerPixel
,
m_sampleFormat
;
std
::
unique_ptr
<
Datafield
>
m_data
;
m_tiff
=
TIFFStreamOpen
(
"MemTIFF"
,
&
input_stream
);
if
(
!
m_
tiff
)
TIFF
*
tiffstream
=
TIFFStreamOpen
(
"MemTIFF"
,
&
input_stream
);
if
(
!
tiff
stream
)
throw
std
::
runtime_error
(
"Cannot open the TIFF file"
);
//... Read header.
uint32_t
w
,
h
;
if
(
!
TIFFGetField
(
m_
tiff
,
TIFFTAG_IMAGEWIDTH
,
&
w
)
||
!
TIFFGetField
(
m_
tiff
,
TIFFTAG_IMAGELENGTH
,
&
h
))
{
if
(
!
TIFFGetField
(
tiff
stream
,
TIFFTAG_IMAGEWIDTH
,
&
w
)
||
!
TIFFGetField
(
tiff
stream
,
TIFFTAG_IMAGELENGTH
,
&
h
))
{
throw
std
::
runtime_error
(
"Cannot read TIFF file: missing width/height in header"
);
}
...
...
@@ -106,23 +104,23 @@ Datafield* IO::readTiff(std::istream& input_stream)
const
size_t
height
=
(
size_t
)
h
;
uint16_t
orientationTag
(
0
);
TIFFGetField
(
m_
tiff
,
TIFFTAG_ORIENTATION
,
&
orientationTag
);
TIFFGetField
(
tiff
stream
,
TIFFTAG_ORIENTATION
,
&
orientationTag
);
bool
good
=
true
;
// BitsPerSample defaults to 1 according to the TIFF spec.
if
(
!
TIFFGetField
(
m_
tiff
,
TIFFTAG_BITSPERSAMPLE
,
&
m_bitsPerSample
))
if
(
!
TIFFGetField
(
tiff
stream
,
TIFFTAG_BITSPERSAMPLE
,
&
m_bitsPerSample
))
m_bitsPerSample
=
1
;
if
(
8
!=
m_bitsPerSample
&&
16
!=
m_bitsPerSample
&&
32
!=
m_bitsPerSample
)
good
=
false
;
// they may be e.g. grayscale with 2 samples per pixel
if
(
!
TIFFGetField
(
m_
tiff
,
TIFFTAG_SAMPLESPERPIXEL
,
&
m_samplesPerPixel
))
if
(
!
TIFFGetField
(
tiff
stream
,
TIFFTAG_SAMPLESPERPIXEL
,
&
m_samplesPerPixel
))
m_samplesPerPixel
=
1
;
if
(
m_samplesPerPixel
!=
1
)
good
=
false
;
if
(
!
TIFFGetField
(
m_
tiff
,
TIFFTAG_SAMPLEFORMAT
,
&
m_sampleFormat
))
if
(
!
TIFFGetField
(
tiff
stream
,
TIFFTAG_SAMPLEFORMAT
,
&
m_sampleFormat
))
m_sampleFormat
=
1
;
switch
(
m_sampleFormat
)
{
...
...
@@ -150,7 +148,7 @@ Datafield* IO::readTiff(std::istream& input_stream)
ASSERT
(
0
==
m_bitsPerSample
%
8
);
uint16_t
bytesPerSample
=
m_bitsPerSample
/
8
;
tmsize_t
buf_size
=
TIFFScanlineSize
(
m_
tiff
);
tmsize_t
buf_size
=
TIFFScanlineSize
(
tiff
stream
);
tmsize_t
expected_size
=
bytesPerSample
*
width
;
if
(
buf_size
!=
expected_size
)
throw
std
::
runtime_error
(
"Cannot read TIFF file: wrong scanline size"
);
...
...
@@ -159,8 +157,9 @@ Datafield* IO::readTiff(std::istream& input_stream)
if
(
!
buf
)
throw
std
::
runtime_error
(
"Cannot read TIFF file: failed allocating buffer"
);
m_data
.
reset
(
new
Datafield
({
newEquiDivision
(
"x"
,
width
,
0.0
,
double
(
width
)),
newEquiDivision
(
"y"
,
height
,
0.0
,
double
(
height
))}));
auto
data
=
std
::
make_unique
<
Datafield
>
(
std
::
vector
<
const
Scale
*>
{
newEquiDivision
(
"x"
,
width
,
0.0
,
double
(
width
)),
newEquiDivision
(
"y"
,
height
,
0.0
,
double
(
height
))});
std
::
vector
<
int8_t
>
line_buf
;
line_buf
.
resize
(
buf_size
,
0
);
...
...
@@ -168,7 +167,7 @@ Datafield* IO::readTiff(std::istream& input_stream)
std
::
vector
<
unsigned
>
axes_indices
(
2
);
for
(
uint32_t
row
=
0
;
row
<
(
uint32_t
)
height
;
row
++
)
{
if
(
TIFFReadScanline
(
m_
tiff
,
buf
,
row
)
<
0
)
if
(
TIFFReadScanline
(
tiff
stream
,
buf
,
row
)
<
0
)
throw
std
::
runtime_error
(
"Cannot read TIFF file: error in scanline."
);
memcpy
(
&
line_buf
[
0
],
buf
,
buf_size
);
...
...
@@ -176,7 +175,7 @@ Datafield* IO::readTiff(std::istream& input_stream)
for
(
unsigned
col
=
0
;
col
<
width
;
++
col
)
{
axes_indices
[
0
]
=
col
;
axes_indices
[
1
]
=
static_cast
<
unsigned
>
(
height
)
-
1
-
row
;
size_t
global_index
=
m_
data
->
frame
().
toGlobalIndex
(
axes_indices
);
size_t
global_index
=
data
->
frame
().
toGlobalIndex
(
axes_indices
);
void
*
incoming
=
&
line_buf
[
col
*
bytesPerSample
];
double
sample
=
0
;
...
...
@@ -215,13 +214,13 @@ Datafield* IO::readTiff(std::istream& input_stream)
throw
std
::
runtime_error
(
"Cannot read TIFF file: unexpected sample format"
);
}
(
*
m_
data
)[
global_index
]
=
sample
;
(
*
data
)[
global_index
]
=
sample
;
}
}
_TIFFfree
(
buf
);
TIFFClose
(
m_
tiff
);
TIFFClose
(
tiff
stream
);
return
m_
data
->
clon
e
();
return
data
.
releas
e
();
}
#endif // BA_TIFF_SUPPORT
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