00001
00002 #ifndef vil_tiff_header_h_
00003 #define vil_tiff_header_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <vcl_string.h>
00038 #include <vcl_vector.h>
00039 #include <vxl_config.h>
00040 #include <vcl_cmath.h>
00041 #include <vil/vil_config.h>
00042 #include <vil/vil_pixel_format.h>
00043 #include <tiffio.h>
00044
00045 struct ushort_tag
00046 {
00047 ushort_tag(): valid(false) {}
00048 vxl_uint_16 val;
00049 bool valid;
00050 };
00051
00052 struct ulong_tag
00053 {
00054 ulong_tag() : valid(false) {}
00055 vxl_uint_32 val;
00056 bool valid;
00057 };
00058
00059
00060
00061
00062
00063
00064 class vil_tiff_header
00065 {
00066 public:
00067 vil_tiff_header(TIFF* tif): tif_(tif) {format_supported = read_header();}
00068
00069 vil_tiff_header(TIFF* tif, const unsigned ni, const unsigned nj,
00070 const unsigned nplanes, vil_pixel_format const& fmt,
00071 const unsigned size_block_i, const unsigned size_block_j);
00072
00073 vcl_string artist;
00074
00075
00076
00077
00078 ushort_tag bits_per_sample;
00079 vxl_uint_16 bytes_per_sample() const
00080 { return bits_per_sample.valid ? (bits_per_sample.val + 7)/8 : 0; }
00081
00082 ushort_tag cell_length;
00083
00084 ushort_tag cell_width;
00085
00086
00087
00088 vcl_vector<vcl_vector<vxl_uint_16> >color_map;
00089 bool color_map_valid;
00090
00091 ushort_tag compression;
00092
00093 vcl_string copyright;
00094
00095 vcl_string date_time;
00096
00097
00098 ushort_tag extra_samples;
00099
00100 ushort_tag fill_order;
00101
00102
00103
00104 vcl_vector<vxl_uint_16> gray_response_curve;
00105 bool grey_response_curve_valid;
00106
00107
00108 ushort_tag gray_response_unit;
00109
00110 vcl_string host_computer;
00111 vcl_string image_description;
00112
00113 ulong_tag image_length;
00114
00115
00116 vxl_uint_32 bytes_per_line() const;
00117
00118
00119 vxl_uint_32 actual_bytes_per_line() const;
00120
00121 ulong_tag image_width;
00122
00123 unsigned nplanes;
00124
00125 vcl_string make;
00126
00127 ushort_tag max_sample_value;
00128
00129 ushort_tag min_sample_value;
00130
00131 vcl_string model;
00132
00133 ushort_tag orientation;
00134
00135 ushort_tag photometric;
00136
00137 ushort_tag planar_config;
00138
00139 ushort_tag resolution_unit;
00140
00141 ulong_tag rows_per_strip;
00142
00143 vxl_uint_32 rows_in_strip() const;
00144
00145 vxl_uint_32 strips_per_image() const
00146 { return rows_per_strip.valid ?
00147 static_cast<vxl_uint_32>(vcl_floor(1.0+(image_length.val-1)/rows_per_strip.val)) : 0L;
00148 }
00149
00150
00151 vxl_uint_32 actual_bytes_per_strip(const vxl_uint_32 strip_index) const;
00152
00153
00154 vxl_uint_32 bytes_per_strip() const;
00155
00156 ushort_tag sample_format;
00157 ushort_tag samples_per_pixel;
00158
00159 vcl_string software;
00160
00161
00162
00163
00164
00165
00166 vxl_uint_32* strip_byte_counts;
00167 bool strip_byte_counts_valid;
00168 vxl_uint_32* strip_offsets;
00169 bool strip_offsets_valid;
00170
00171 ushort_tag subfile_type;
00172
00173 ushort_tag thresholding;
00174
00175 double x_resolution;
00176 bool x_resolution_valid;
00177
00178 double y_resolution;
00179 bool y_resolution_valid;
00180
00181
00182 bool is_tiled_flag;
00183
00184 ulong_tag tile_width;
00185
00186 ulong_tag tile_length;
00187
00188
00189
00190
00191
00192
00193 vxl_uint_32* tile_offsets;
00194 bool tile_offsets_valid;
00195 vxl_uint_32* tile_byte_counts;
00196 bool tile_byte_counts_valid;
00197
00198 vxl_uint_32 tiles_across() const
00199 { return tile_width.valid ?
00200 static_cast<vxl_uint_32>(vcl_floor(1.0+(image_width.val-1)/tile_width.val)) : 0L;
00201 }
00202
00203 vxl_uint_32 tiles_down() const
00204 { return tile_length.valid ?
00205 static_cast<vxl_uint_32>(vcl_floor(1.0+(image_length.val-1)/tile_length.val)) : 0L;
00206 }
00207
00208 vxl_uint_32 tiles_per_image() const {return tiles_across()*tiles_down();}
00209
00210 vxl_uint_32 bytes_per_tile() const;
00211
00212
00213 unsigned n_separate_image_planes() const;
00214
00215
00216 unsigned encoded_bytes_per_block() const;
00217
00218
00219 unsigned samples_per_line() const;
00220
00221
00222 bool is_tiled() const;
00223
00224
00225 bool is_striped() const;
00226
00227 #if HAS_GEOTIFF
00228 bool is_GEOTIFF() const;
00229 #endif
00230
00231 bool need_byte_swap()
00232 { return file_is_big_endian_!=machine_is_big_endian_ &&
00233 bits_per_sample.val%8 != 0;
00234 }
00235
00236 vil_pixel_format pix_fmt;
00237
00238
00239
00240 bool format_supported;
00241
00242
00243 vxl_uint_16 n_images();
00244 private:
00245 TIFF* tif_;
00246
00247
00248 bool read_header();
00249
00250 bool set_header(unsigned ni, unsigned nj, unsigned nplanes,
00251 vil_pixel_format const& fmt,
00252 const unsigned size_block_i,
00253 const unsigned size_block_j);
00254
00255 bool compute_pixel_format();
00256
00257 bool parse_pixel_format(vil_pixel_format const& fmt);
00258 bool file_is_big_endian_;
00259 bool machine_is_big_endian_;
00260 };
00261
00262 #endif //vil_tiff_header_h_