6 # include <vcl_msvc_warnings.h> 13 static std::string date_and_time()
17 clock = std::time(
nullptr);
18 t_m = std::localtime(&clock);
21 std::strftime(tmp,
sizeof(datetime),
"%Y-%m-%d %H:%M:%S",t_m);
23 std::sprintf(datetime,
"%19s",tmp);
24 return std::string(datetime);
27 static void read_string(TIFF* tif, ttag_t tag, std::string& stag, std::string
const& deflt =
"not_defined")
30 TIFFGetField(tif, tag, &adr);
32 stag = std::string(adr);
37 static void read_short_tag(TIFF* tif, ttag_t tag,
ushort_tag& utag, vxl_uint_16 deflt =0)
39 utag.
valid = TIFFGetField(tif, tag, &(utag.
val))>0;
44 static void read_long_tag(TIFF* tif, ttag_t tag,
ulong_tag& utag, vxl_uint_32 deflt = 0)
46 utag.
valid = TIFFGetField(tif, tag, &(utag.
val))>0;
51 static void read_float_tag(TIFF* tif, ttag_t tag,
float& val,
bool& valid,
float deflt = 0)
53 valid = TIFFGetField(tif, tag, &(val))>0;
58 #if 0 // unused static function 60 static bool read_long_array(TIFF* tif, ttag_t tag,
61 std::vector<vxl_uint_32>& array)
64 if (TIFFGetField(tif, tag, &a))
66 for (vxl_uint_32 i=0; i<array.size(); ++i) { array[i]=a[i]; }
71 #endif // unused static function 73 static void write_short_tag(TIFF* tif, ttag_t tag,
ushort_tag const& ustag)
76 TIFFSetField(tif, tag, ustag.
val);
79 static void write_long_tag(TIFF* tif, ttag_t tag,
ulong_tag const& ultag)
82 TIFFSetField(tif, tag, ultag.
val);
85 #if 0 // not currently used... 86 static void write_float_tag(TIFF* tif, ttag_t tag,
float const val,
bool const valid)
89 TIFFSetField(tif, tag, val);
93 static void write_string(TIFF* tif, ttag_t tag, std::string
const& stag)
95 TIFFSetField(tif, tag, stag.c_str());
103 std::cout << date_and_time() <<
'\n';
133 TIFFGetField(
tif_,TIFFTAG_COLORMAP, &cm[0], &cm[1], &cm[2]);
136 for (
unsigned i = 0; i<size; ++i)
138 std::vector<vxl_uint_16> rgb(3);
139 rgb[0]=cm[0][i]; rgb[1]=cm[1][i]; rgb[2]=cm[2][i];
142 std::cout <<
"RGB[" << i <<
"]=(" << rgb[0] <<
' ' << rgb[1] <<
' ' << rgb[2] <<
")\n";
153 vxl_uint_16* sample_info=
nullptr;
156 int const ret_extrasamples = TIFFGetField(
tif_, TIFFTAG_EXTRASAMPLES, &
extra_samples.
val, &sample_info);
161 vxl_uint_16* gc=
nullptr;
162 TIFFGetField(
tif_,TIFFTAG_GRAYRESPONSECURVE, &gc);
168 read_string(
tif_,TIFFTAG_MAKE,
make);
186 for (vxl_uint_32 i = 0; i<size; ++i)
199 for (vxl_uint_32 i = 0; i<size; ++i)
200 std::cout <<
"SOFF[" << i <<
"]=" <<
strip_offsets[i] <<
'\n';
220 for (vxl_uint_32 i = 0; i<size; ++i)
221 std::cout <<
"TOFF[" << i <<
"]=" <<
tile_offsets[i] <<
'\n';
233 for (vxl_uint_32 i = 0; i<size; ++i)
272 bool vil_tiff_header::is_GEOTIFF()
const 276 return TIFFGetField(
tif_, 34735 , &count, &data)!=0;
302 return (bits_per_line + 7)/8;
307 return TIFFScanlineSize(
tif_);
343 return TIFFTileSize(
tif_);
349 return TIFFNumberOfDirectories(
tif_);
393 case (
sizeof(
float)):
396 case (
sizeof(
double)):
687 const unsigned size_block_i,
688 const unsigned size_block_j)
719 if (size_block_i>0&&size_block_j>0)
729 unsigned n_rows = size_block_j;
739 software =
"https://vxl.github.io/ vil image library";
747 const unsigned size_block_i,
const unsigned size_block_j)
759 write_string(
tif_, TIFFTAG_DATETIME, date_and_time());
768 #if 1 // Handle Alpha channel, assuming it is the last channel 773 vxl_uint_32 num_extra_samples = 1;
774 vxl_uint_16 extra_sample_values[] = { EXTRASAMPLE_ASSOCALPHA };
775 TIFFSetField(
tif_, TIFFTAG_EXTRASAMPLES, num_extra_samples, extra_sample_values);