@@ -122,6 +122,10 @@ string saveToTiffFile(
122122 // nodata_as_int,
123123 // static_cast<MathSize>(no_data)
124124 // );
125+ constexpr auto bps = sizeof (R) * 8 ;
126+ logging::check_fatal (
127+ bps != bits_per_sample, " Cannot have mismatched bps and type (%ld != %ld)" , bps, bits_per_sample
128+ );
125129 TIFFSetField (tif, TIFFTAG_GDAL_NODATA, str);
126130 logging::extensive (" %s takes %d bits" , string (base_name).c_str (), bits_per_sample);
127131 TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, num_columns);
@@ -139,6 +143,7 @@ string saveToTiffFile(
139143 size_t tileSize = tileWidth * tileHeight;
140144 const auto buf_size = tileSize * sizeof (R);
141145 logging::extensive (" %s has buffer size %d" , string (base_name).c_str (), buf_size);
146+ // HACK: using R means size changes on different cpu types
142147 auto buf = static_cast <R*>(_TIFFmalloc (buf_size));
143148 for (uint32_t co = 0 ; co < num_columns; co += tileWidth)
144149 {
@@ -312,27 +317,25 @@ string GridBase::saveToTiffFileFloat(
312317 const int nodata_as_int
313318) const
314319{
315- constexpr auto bits_per_sample = 16 ;
320+ // HACK: use whatever hardware does for float for now
321+ constexpr auto bits_per_sample = 8 * sizeof (float );
322+ // constexpr auto bits_per_sample = 16;
316323 constexpr auto sample_format = SAMPLEFORMAT_IEEEFP;
317- if (16 = = bits_per_sample)
324+ if (16 ! = bits_per_sample)
318325 {
319- return saveToTiffFile<float >(
320- *this ,
321- columns,
322- rows,
323- bounds,
324- dir,
325- base_name,
326- bits_per_sample,
327- sample_format,
328- [&](Location idx) { return static_cast <float >(value_at (idx)); },
329- nodata_as_int
330- );
326+ logging::warning (" Hardware uses %ld bits for float" , bits_per_sample);
331327 }
332- return logging::fatal<string>(
333- " Invalid combination of BITSPERSAMPLE (%d) and SAMPLEFORMAT (%d)" ,
328+ return saveToTiffFile<float >(
329+ *this ,
330+ columns,
331+ rows,
332+ bounds,
333+ dir,
334+ base_name,
334335 bits_per_sample,
335- sample_format
336+ sample_format,
337+ [&](Location idx) { return static_cast <float >(value_at (idx)); },
338+ nodata_as_int
336339 );
337340}
338341GridBase::GridBase (
0 commit comments