Skip to content

Commit 8545aef

Browse files
committed
Fix errors resolving PNG changes (#2713) against dev
1 parent 2f62732 commit 8545aef

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

cpp/core/file/png.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,16 @@ Writer::Writer(const Header &H, const std::string &filename)
216216
break;
217217
case DataType::Float32:
218218
bit_depth = 8;
219-
multiplier = std::numeric_limits<uint8_t>::infinity();
219+
multiplier = std::numeric_limits<uint8_t>::max();
220220
break;
221221
case DataType::UInt16:
222222
case DataType::UInt32:
223223
case DataType::UInt64:
224+
bit_depth = 16;
225+
break;
224226
case DataType::Float64:
225227
bit_depth = 16;
226-
multiplier = std::numeric_limits<uint16_t>::infinity();
228+
multiplier = std::numeric_limits<uint16_t>::max();
227229
break;
228230
}
229231
// Detect cases where one axis has a size of 1, and hence represents the image plane

cpp/core/file/png.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ class Writer {
8585

8686
template <typename T>
8787
void Writer::fill(uint8_t *in_ptr, uint8_t *out_ptr, const DataType data_type, const size_t num_elements) {
88-
auto fetch_func = __set_fetch_function<default_type>(data_type);
88+
std::function<default_type(const void *, size_t, default_type, default_type)> fetch_func;
89+
std::function<void(default_type, void *, size_t, default_type, default_type)> store_func;
90+
__set_fetch_store_scale_functions<default_type>(fetch_func, store_func, data_type);
8991
for (size_t i = 0; i != num_elements; ++i) {
90-
Raw::store_BE<T>(std::min(default_type(std::numeric_limits<T>::max()), //
91-
std::max(0.0, std::round(multiplier * fetch_func(in_ptr, 0)))), //
92-
out_ptr, //
93-
i); //
94-
in_ptr += data_type.bytes();
95-
out_ptr += sizeof(T);
92+
Raw::store_BE<T>(std::min(default_type(std::numeric_limits<T>::max()), //
93+
std::max(0.0, std::round(multiplier * fetch_func(in_ptr, i, 0.0, 1.0)))), //
94+
out_ptr, //
95+
i); //
9696
}
9797
};
9898

cpp/core/image_io/png.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace MR::ImageIO {
2727
void PNG::load(const Header &header, size_t) {
2828
DEBUG(std::string("loading PNG image") + (files.size() > 1 ? "s" : "") + " \"" + header.name() + "\"");
2929
segsize = (header.datatype().bits() * voxel_count(header) + 7) / 8;
30+
addresses.resize(1);
3031
addresses[0].reset(new uint8_t[segsize]);
3132
if (is_new) {
3233
memset(addresses[0].get(), 0x00, segsize);

testing/binaries/tests/mrconvert/format_png

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ rm -f tmp-*.png
88

99
mrconvert mrconvert/in.mif tmp-gray[].png
1010
mrcalc mrconvert/in.mif 0 -max - | \
11-
mrtransform - -replace identity.txt tmp-gray.mif -force
11+
mrtransform - -replace identity.txt tmp-gray.mif -force
1212
testing_diff_image tmp-gray[].png tmp-gray.mif
1313

1414
mrconvert unit_warp.mif tmp-rgb[].png -datatype uint8
1515
mrcalc unit_warp.mif 0 -max -round - | \
16-
mrtransform - -replace identity.txt - | \
17-
mrconvert - -vox 1,1,1 tmp-rgb.mif -force
16+
mrtransform - -replace identity.txt - | \
17+
mrconvert - -vox 1,1,1 tmp-rgb.mif -force
1818
testing_diff_image tmp-rgb[].png tmp-rgb.mif
1919

2020
# Now some more advanced tests:

0 commit comments

Comments
 (0)