vil_tiff.h
Go to the documentation of this file.
1 // This is core/vil/file_formats/vil_tiff.h
2 #ifndef vil_tiff_file_format_h_
3 #define vil_tiff_file_format_h_
4 //:
5 // \file
6 // \author awf@robots.ox.ac.uk
7 // \date 16 Feb 2000
8 //
9 // \verbatim
10 // Modifications
11 // 3 Oct 2001 Peter Vanroose - Implemented get_property and set_property
12 // 5 Jan 2002 Ian Scott - Converted to vil
13 // 9 Dec 2003 Peter Vanroose - Added support for 1-bit pixel (bitmapped) images
14 // 21 Dec 2005 J.L. Mundy - Substantial rewrite to handle a more
15 // complete tiff 6.0 standard. Files with tiles can now be read and
16 // written. Only tiled images are considered blocked, i.e. not strips.
17 // Block dimensions must be a multiple of 16, for compatibility with
18 // compression schemes. Tiff files with separate color bands are not handled
19 // 24 Mar 2007 J.L. Mundy - added smart pointer on TIFF handle to support
20 // multiple resources from a single tiff file; required for pyramid
21 // KNOWN BUG - 24bit samples for both nplanes = 1 and nplanes = 3
22 // KNOWN BUG - bool pixel format write - crashes due to incorrect block size
23 // \endverbatim
24 
25 #include <vector>
26 #include <iostream>
27 #ifdef _MSC_VER
28 # include <vcl_msvc_warnings.h>
29 #endif
30 #include <cassert>
31 #include <vil/vil_config.h>
32 #include <vil/vil_file_format.h>
33 #include <vil/vil_image_resource.h>
34 #include <vil/vil_memory_chunk.h>
38 #include <tiffio.h>
39 #if HAS_GEOTIFF
40 #include <xtiffio.h>
42 #endif
43 
44 
45 //: Loader for tiff files
47 {
48  public:
49  char const *tag() const override;
51 
53  make_input_pyramid_image(char const* file) override;
54 
55  //: Construct a pyramid image resource from a base image.
56  // All levels are stored in the same resource file. Each level has the same
57  // scale ratio (0.5) to the preceding level. Level 0 is the original
58  // base image. The resource is returned open for reading.
59  // The temporary directory is for storing intermediate image
60  // resources during the construction of the pyramid. Files are
61  // be removed from the directory after completion. If temp_dir is 0
62  // then the intermediate resources are created in memory.
64  make_pyramid_image_from_base(char const* filename,
65  vil_image_resource_sptr const& base_image,
66  unsigned nlevels,
67  char const* temp_dir) override;
68 
70  unsigned ni,
71  unsigned nj,
72  unsigned nplanes,
73  enum vil_pixel_format) override;
74 
77  unsigned ni,
78  unsigned nj,
79  unsigned nplanes,
80  unsigned size_block_i,
81  unsigned size_block_j,
82  enum vil_pixel_format) override;
83 
84 
86  make_pyramid_output_image(char const* file) override;
87 };
88 
90 class vil_tiff_header;
91 //Need to create a smartpointer mechanism for the tiff
92 //file in order to handle multiple images, e.g. for pyramid
93 //resource
94 //A reference counting wrapper for the TIFF handle
96 {
97  tif_ref_cnt(TIFF* tif):tif_(tif), cnt_(0){}
98  TIFF* tif(){return tif_;}
99  void ref(){cnt_++;}
100  void unref(){
101  if (--cnt_<=0)
102  {
103 #if HAS_GEOTIFF
104  XTIFFClose(tif_);
105 #else
106  TIFFClose(tif_);
107 #endif // HAS_GEOTIFF
108  delete this;
109  }
110  }
111  private:
112  TIFF* tif_;
113  unsigned cnt_;
114 };
115 
116 //The smart pointer to the tiff handle
118 {
119  tif_smart_ptr(): tptr_(nullptr){}
120 
122  { if (tptr_) tptr_->ref(); }
123 
125  {tptr_ = tp.tptr_; if (tptr_) tptr_->ref();}
126 
128  {
129  // the strange order of events in this function is to avoid
130  // heap corruption if unref() causes *this to be deleted.
131  tif_ref_cnt* old_ptr = tptr_;
132  tptr_ = nullptr;
133  if (old_ptr)
134  old_ptr->unref();
135  }
136  //: Inverse bool
137  bool operator!() const
138  {
139  return (tptr_ != nullptr)? false : true;
140  }
141 
142  //: Convenient get TIFF* for header construction; assumes temporary use
143  TIFF* tif() const {if (tptr_) return tptr_->tif(); return nullptr;}
144  private:
146 };
147 
148 //: Generic image interface for image TIFF image files (could have multiple images)
150 {
151  friend class vil_tiff_file_format;
152  public:
154  {
155  // the enum value must correspond to COMPRESSION_* constants defined in tiff.h.
156  // and has the same integer value. For instance, NONE corresponds to COMPRESSION_NONE
157  NONE = 1, /* dump mode */
158  LZW = 5, /* Lempel-Ziv & Welch */
159  OJPEG = 6, /* !6.0 JPEG */
160  JPEG = 7, /* %JPEG DCT compression */
161  PACKBITS = 32773, /* Macintosh RLE */
162  THUNDERSCAN = 32809, /* ThunderScan RLE */
163  PIXARFILM =32908, /* Pixar companded 10bit LZW */
164  PIXARLOG = 32909, /* Pixar companded 11bit ZIP */
165  DEFLATE = 32946, /* Deflate compression */
166  ADOBE_DEFLATE = 8, /* Deflate compression,
167  as recognized by Adobe */
168  JP2000 = 34712, /* Leadtools JPEG2000 */
169  LZMA = 34925 /* LZMA2 */
170  };
171  public:
172  vil_tiff_image(tif_smart_ptr const& tif,
173  vil_tiff_header* th, const unsigned nimages = 1);
174 
175  ~vil_tiff_image() override;
176 
177  //: Dimensions: planes x width x height x components
178  unsigned nplanes() const override;
179  unsigned ni() const override;
180  unsigned nj() const override;
181 
182  enum vil_pixel_format pixel_format() const override;
183 
184  //: returns "tiff"
185  char const *file_format() const override;
186 
187 #if HAS_GEOTIFF
188  //: are there any geotiff tags
189  bool is_GEOTIFF() { return h_->is_GEOTIFF(); }
190 #endif
191 
192  // --- Block interface ---
193 
194  //: Block size in columns (must be a multiple of 16)
195  unsigned size_block_i() const override;
196 
197  //: Block size in rows (must be a multiple of 16)
198  unsigned size_block_j() const override;
199 
200  //: Number of blocks in image width
201  unsigned n_block_i() const override;
202 
203  //: Number of blocks in image height
204  unsigned n_block_j() const override;
205 
206  vil_image_view_base_sptr get_block( unsigned block_index_i,
207  unsigned block_index_j ) const override;
208 
209  bool put_block( unsigned block_index_i, unsigned block_index_j,
210  const vil_image_view_base& blk ) override;
211 
212  //: Put the data in this view back into the image source.
213  bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0) override;
214 
215  //: Return true if the property given in the first argument has been set.
216  // currently defined:
217  // "quantisation_depth" - number of relevant bits per pixel
218  // "size_block_i" and "size_block_j" - block dimensions
219 
220  bool get_property(char const *tag, void *prop = nullptr) const override;
221 
223 
224  bool set_compression_quality(int quality);
225 
226 #if HAS_GEOTIFF
227  //* returns null if the tiff file does not include any geotiff tags
228  vil_geotiff_header* get_geotiff_header();
229 #endif
230 
232 
233  //:indicates the number of images in the tiff file
234  unsigned int nimages() const {return nimages_;}
235 
236  //:the image index for multiple image files
237  unsigned int index() const {return index_;}
238  //:point to a particular image in the file
239  void set_index(const unsigned int index)
240  {assert(index<nimages_); index_=index;}
241  //: Get a smart pointer to opentiff object
242  tif_smart_ptr const& tiff() const
243  {
244  return t_;
245  }
246  private:
247  //: the TIFF handle to the open resource file
249 
250  //: the TIFF header information
252  //: the default image header index
253  unsigned int index_;
254  //: number of images in the file
255  unsigned int nimages_;
256 #if 0
257  //to keep the tiff file open during reuse of multiple tiff resources
258  //in a single file otherwise the resource destructor would close the file
259  void clear_TIFF() { t_ = 0; }
260 #endif
261  //: the number of samples in a block
262  unsigned samples_per_block() const;
263 
265 
266  void copy_byte_block(vxl_byte* data, const vxl_uint_32 nbytes,
267  vil_memory_chunk_sptr& cnk) const;
268 
269  //: convert a packed block to an expanded view
272  vil_memory_chunk_sptr const& buf,
273  unsigned samples_per_block,
274  unsigned bits_per_sample) const;
275 
276  //: the key methods for decoding the file data
278 
280 
281 #if 0
282  vil_image_view_base_sptr get_block_internal( unsigned block_index_i,
283  unsigned block_index_j ) const;
284  void
285  get_blocks_internal( unsigned start_block_i,
286  unsigned end_block_i,
287  unsigned start_block_j,
288  unsigned end_block_j,
289  std::vector< std::vector< vil_image_view_base_sptr > >& blocks ) const;
290 #endif
291  bool put_block(unsigned bi, unsigned bj, unsigned i0,
292  unsigned j0, const vil_image_view_base& im);
293 
294  unsigned block_index(unsigned block_i, unsigned block_j) const;
295 
296  //: fill out the block with leading zeros or trailing zeros if necessary
297  void pad_block_with_zeros(unsigned ioff, unsigned joff,
298  unsigned iclip, unsigned jclip,
299  unsigned bytes_per_pixel,
300  vxl_byte* block_buf);
301 
302  //: fill the block with view data
303  void fill_block_from_view(unsigned bi, unsigned bj,
304  unsigned i0, unsigned j0,
305  unsigned ioff, unsigned joff,
306  unsigned iclip, unsigned jclip,
307  const vil_image_view_base& im,
308  vxl_byte*& block_buf);
309 
310  void bitpack_block(unsigned bytes_per_block,
311  const vxl_byte* in_block_buf,
312  vxl_byte* out_block_buf);
313 
314  bool write_block_to_file(unsigned bi, unsigned bj,
315  unsigned block_size_bytes,
316  vxl_byte* block_buf);
317 }; //End of single image TIFF resource
318 
319 
320 ///--------- Representation of Pyramid Images by multi-image TIFF -------
321 //
322 //
323 // It is assumed that image scales are not necessarily ordered with
324 // respect to tiff header index. This data structure maintains essential
325 // information about each pyramid level. The struct can be sorted on scale
326 // to form an ordered pyramid.
328 {
329  public:
330  tiff_pyramid_level(unsigned header_index, unsigned ni,
331  unsigned nj, unsigned nplanes, vil_pixel_format fmt)
332  : header_index_(header_index), scale_(1.0f), ni_(ni), nj_(nj),
333  nplanes_(nplanes), pix_fmt_(fmt), cur_level_(0)
334  {}
335 
336  ~tiff_pyramid_level() = default;
337 
338  //:the tiff header index
339  unsigned header_index_;
340 
341  //:scale associated with level
342  float scale_;
343 
344  //:the image width
345  unsigned ni_;
346 
347  //: the image length
348  unsigned nj_;
349 
350  //:the number of planes
351  unsigned nplanes_;
352 
353  //: the pixel format
355 
356  //: temporary variable for current level
357  unsigned cur_level_;
358 
359  void print(const unsigned l)
360  { std::cout << "level[" << l << "] hindex " << header_index_ << " scale: " << scale_ << " width: " << ni_ << std::endl; }
361 };
362 
363 //:Pyramid resource built on the multi-image capability of the TIFF format
364 // If read is true then the resource is open for reading else it is open for writing
366 {
367  public:
368  vil_tiff_pyramid_resource(tif_smart_ptr const& t, bool read = true);
369 
370  ~vil_tiff_pyramid_resource() override;
371 
372  //: The number of planes (or components) of the image.
373  // This method refers to the base (max resolution) image
374  // Dimensions: Planes x ni x nj.
375  // This concept is treated as a synonym to components.
376  inline unsigned nplanes() const override
377  { if (levels_[0]) return levels_[0]->nplanes_; return 1; }
378 
379  //: The number of pixels in each row.
380  // Dimensions: Planes x ni x nj.
381  inline unsigned ni() const override
382  { if (levels_[0]) return levels_[0]->ni_; return 0; }
383 
384  //: The number of pixels in each column.
385  // Dimensions: Planes x ni x nj.
386  inline unsigned nj() const override
387  { if (levels_[0]) return levels_[0]->nj_; return 0; }
388 
389  //: Pixel Format.
390  inline enum vil_pixel_format pixel_format() const override
391  { if (levels_[0]) return levels_[0]->pix_fmt_; return VIL_PIXEL_FORMAT_UNKNOWN; }
392 
393  //: Return a string describing the file format.
394  // Only file images have a format, others return 0
395  char const* file_format() const override { return "ptif"; }
396 
397  // --- Methods particular to pyramid resource ---
398 
399  //: number of pyramid levels
400  unsigned nlevels() const override { return (unsigned)(levels_.size()); }
401 
402  //:Get a partial view from the image from a specified pyramid level
403  vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
404  unsigned j0, unsigned n_j,
405  unsigned level) const override;
406 
407  //:Get a partial view from the image in the pyramid closest to scale.
408  // The origin and size parameters are in the coordinate system of the base image.
409  // The scale factor is with respect to the base image (base scale = 1.0).
410  vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
411  unsigned j0, unsigned n_j,
412  const float scale,
413  float& actual_scale) const override;
414 
415  //:
416  // Caution! The resource is assigned a header and the data is permanently
417  // written into the file. Be sure you want to commit to the file.
418  bool put_resource(vil_image_resource_sptr const& resc) override;
419 
420  //: returns the image resource at the specified pyramid level
421  vil_image_resource_sptr get_resource(const unsigned level) const override;
422 
423  //: for debug purposes
424  void print(const unsigned level) override
425  { if (level<levels_.size()) levels_[level]->print(level); }
426  protected:
427  //:default constructor
429  //utility methods
430  //:normalize the scale factors so that the base image scale = 1.0
431  void normalize_scales();
432 
433  //:find the image resource with scale closest to specified scale
434  tiff_pyramid_level* closest(const float scale) const;
435 
436  //: If true resource is open for read, else open for write
437  bool read_;
438 
439  //: the tiff handle
441 
442  //The set of images in the pyramid. levels_[0] is the base image
443  std::vector<tiff_pyramid_level*> levels_;
444 }; //End of pyramid image
445 
446 
447 //------------------------ Lifted from vil_nitf2_image ------------------------
448 // If this happens again then maybe should elevate to a
449 // utility class -- JLM
450 //
451 
452 //:
453 // This function does a lot of work for \sa byte_align_data(). It will strip one value
454 // of ni bits and return it as a value of type T (with zero padding on the MSBs).
455 // Both io and ni are lengths (in bits - not bytes).
456 //
457 // \param i0: Offset (in bits - not bytes) from in_val[0]. This will be the start
458 // of the bits extracted from in_val.
459 // \param ni: number of bits (starting from i0) that will be extracted from in_val.
460 template< class T >
461 T tiff_get_bits( const T* in_val, unsigned i0, unsigned ni )
462 {
463  unsigned sample_offset = i0 / ( sizeof(T)*8 );
464  unsigned bit_offset = i0 % ( sizeof(T)*8 );
465 
466  unsigned strip_left = bit_offset;
467  int strip_right = ( sizeof( T ) * 8 ) - ( bit_offset + ni );
468  T temp = in_val[sample_offset];
469  if ( strip_left > 0 ){
470  //strip off the appropriate bits from the std::left (replacing them with zeros)
471  temp <<= strip_left;
472  temp >>= strip_left;
473  }
474  if ( strip_right > 0 ){
475  //strip off the appropriate bits from the std::right
476  //the bit shift operator wasn't having the correct effect, so that'w
477  //why the for loop
478  for ( int i = 0 ; i < strip_right ; i++ ) temp /= 2;
479  //temp >>= strip_right;
480  }
481  else if ( strip_right < 0 ){
482  //we didn't have enough bits in the first element of the in_val array
483  //need to get some from the next element
484 
485  for ( int i = 0 ; i < (-strip_right) ; ++i ) temp *= 2;
486  temp += tiff_get_bits<T>( in_val+sample_offset+1, 0, -strip_right );
487 
488 #if 0
489  T next = in_val[sample_offset+1];
490  //shift right a bigger amount
491  int new_strip_right = strip_right + (sizeof(T)*8);
492  for ( int i = 0 ; i < new_strip_right ; i++ ) next /= 2;
493  // next is the LSB part
494  unsigned new_strip_left = 1- strip_right;
495  temp <<= new_strip_left;
496  temp += next;
497 #endif
498  }
499 #ifdef DEBUG
500  std::cout << "Out val = " << std::hex << temp << std::dec << '\n';
501 #endif
502  return temp;
503 }
504 
505 //:
506 // This function will byte align the data in in_data and store the result in out_data. For example, let's
507 // say that you had in_data is of type unsigned char and contains the following data: 110010111001111010000110.
508 // In other words:
509 // in_data[0] = 203 (11001011)
510 // in_data[1] = 158 (10011110)
511 // in_data[2] = 134 (10000110)
512 // Let's further say you called this function like this: byte_align_data( in_data, 8, 3, out_data ).
513 // Then, when the function finished, out_data would look like this:
514 // out_data[0] = 6 (00000110)
515 // out_data[1] = 2 (00000010)
516 // out_data[2] = 7 (00000111)
517 // out_data[3] = 1 (00000001)
518 // out_data[4] = 7 (00000111)
519 // out_data[5] = 2 (00000010)
520 // out_data[6] = 0 (00000000)
521 // out_data[7] = 6 (00000110)
522 //
523 // Basically, what the function did was group the bitstream into groups of three and then store all of the
524 // values into out_data. It had to zero pad all the values (on the MSB side) to get them into out_data. That's
525 // why out_data is bigger.
526 //
527 // This function works with other unsigned types of data too. For example, let's say in_data was of type unsigned int
528 // and contained the following bits: 0100110010111000 0111101100000000 1111000011110000 (note that this bitstream is shown
529 // in big endian notation, that will not be the case if you are on a little endian machine -- this is just for illustration)
530 // in other words:
531 // in_data[0] = 19640 (0100110010111000) [shown in big endian for illustrative purposes only]
532 // in_data[1] = 31488 (0111101100000000) [shown in big endian for illustrative purposes only]
533 // in_data[2] = 61680 (1111000011110000) [shown in big endian for illustrative purposes only]
534 // Let's further say, you called this function like this byte_align_data( in_data, 4, 12, out_data ).
535 // Then out_data would be aligned along two byte (sixteen bit) boundaries and would look like this:
536 // out_data[0] = 1227 (0000010011001011) [shown in big endian for illustrative purposes only]
537 // out_data[1] = 2171 (0000100001111011) [shown in big endian for illustrative purposes only]
538 // out_data[2] = 15 (0000000000001111) [shown in big endian for illustrative purposes only]
539 // out_data[3] = 240 (0000000011110000) [shown in big endian for illustrative purposes only]
540 //
541 // Because of the fact that this function uses bit shifting operators, and the behavior of the std::right
542 // shift operator is implementation specific when applied to a negative number, you should probably
543 // only use this function on unsigned data.
544 //
545 // \param in_data: The input data. It must be at least (num_samples*in_bits_per_sample/8) bytes long.
546 // The values should have the endianness of your platform.
547 // \param num_samples: The number of actual samples in in_data.
548 // \param in_bits_per_sample: The bits per sample in in_data
549 // \param out_data: I'll store the output data here. It must be at least (num_samples*sizeof(T)) bytes long
550 // The values will have the endianness of your platform.
551 //
552 // Note that inBitsPerSampe must not be >= sizeof(T). If they were to be equal, then this function
553 // would have nothing to do (in_data is already byte aligned). If in_bits_per_sample were less than sizeof(T),
554 // then each element of out_data would be too small to store the corresponding elements in in_data.
555 //
556 // Note that there is a specialization for the bool case which just casts it to an 8 bit quantity then calls
557 // this same function. This is because the logic in get_bits<> doesn't work for the bool case.
558 template< class T >
559 T* tiff_byte_align_data( T* in_data, unsigned num_samples, unsigned in_bits_per_sample, T* out_data )
560 {
561  assert( in_bits_per_sample < sizeof(T)*8 );
562 
563  //grab each value from the bitstream (in_data) that we need... one
564  //at a time
565  unsigned bit_offset = 0;
566  for ( unsigned o = 0 ; o < num_samples ; o++ ){
567  out_data[o] = tiff_get_bits<T>( in_data, bit_offset, in_bits_per_sample );
568  //printf("bo = %i, in = %x, out = %x\n", bit_offset, in_data[o], out_data[o]);
569  bit_offset+=in_bits_per_sample;
570  }
571 
572  return out_data;
573 }
574 
575 template<> bool* tiff_byte_align_data<bool>( bool* in_data, unsigned num_samples, unsigned in_bits_per_sample, bool* out_data );
576 
577 #endif // vil_tiff_file_format_h_
unsigned nlevels() const override
number of pyramid levels.
Definition: vil_tiff.h:400
vil_pyramid_image_resource_sptr make_pyramid_image_from_base(char const *filename, vil_image_resource_sptr const &base_image, unsigned nlevels, char const *temp_dir) override
Construct a pyramid image resource from a base image.
Definition: vil_tiff.cxx:259
float scale_
scale associated with level.
Definition: vil_tiff.h:342
vil_image_view_base_sptr fill_block_from_tile(vil_memory_chunk_sptr const &buf) const
the key methods for decoding the file data.
Definition: vil_tiff.cxx:864
An abstract base class of smart pointers to actual image data in memory.
vil_pixel_format
Describes the type of the concrete data.
tif_smart_ptr(tif_ref_cnt *tptr)
Definition: vil_tiff.h:121
unsigned n_block_j() const override
Number of blocks in image height.
Definition: vil_tiff.cxx:629
char const * file_format() const override
Return a string describing the file format.
Definition: vil_tiff.h:395
void normalize_scales()
normalize the scale factors so that the base image scale = 1.0.
Definition: vil_tiff.cxx:1258
char const * file_format() const override
returns "tiff".
Definition: vil_tiff.cxx:464
enum vil_pixel_format compute_pixel_format()
void print(const unsigned level) override
for debug purposes.
Definition: vil_tiff.h:424
bool get_property(char const *tag, void *prop=nullptr) const override
Return true if the property given in the first argument has been set.
Definition: vil_tiff.cxx:385
T tiff_get_bits(const T *in_val, unsigned i0, unsigned ni)
This function does a lot of work for.
Definition: vil_tiff.h:461
void fill_block_from_view(unsigned bi, unsigned bj, unsigned i0, unsigned j0, unsigned ioff, unsigned joff, unsigned iclip, unsigned jclip, const vil_image_view_base &im, vxl_byte *&block_buf)
fill the block with view data.
Definition: vil_tiff.cxx:1003
vil_pyramid_image_resource_sptr make_input_pyramid_image(char const *file) override
Read a pyramid resource from a list of image files in a directory.
Definition: vil_tiff.cxx:223
vil_blocked_image_resource_sptr make_blocked_output_image(vil_stream *vs, unsigned ni, unsigned nj, unsigned nplanes, unsigned size_block_i, unsigned size_block_j, enum vil_pixel_format) override
Construct a blocked output image resource.
Definition: vil_tiff.cxx:302
vil_image_view_base_sptr view_from_buffer(vil_pixel_format &fmt, vil_memory_chunk_sptr const &buf, unsigned samples_per_block, unsigned bits_per_sample) const
convert a packed block to an expanded view.
Definition: vil_tiff.cxx:667
enum vil_pixel_format pixel_format() const override
Pixel Format.
Definition: vil_tiff.cxx:451
unsigned nj() const override
The number of pixels in each column.
Definition: vil_tiff.h:386
unsigned int nimages_
number of images in the file.
Definition: vil_tiff.h:255
unsigned nplanes_
the number of planes.
Definition: vil_tiff.h:351
vil_image_resource_sptr make_output_image(vil_stream *vs, unsigned ni, unsigned nj, unsigned nplanes, enum vil_pixel_format) override
Make a "generic_image" on which put_section may be applied.
Definition: vil_tiff.cxx:348
void unref()
Definition: vil_tiff.h:100
vil_image_resource_sptr get_resource(const unsigned level) const override
returns the image resource at the specified pyramid level.
Definition: vil_tiff.cxx:1425
tif_ref_cnt * tptr_
Definition: vil_tiff.h:145
Representation of a pyramid resolution hierarchy; mostly pure virtual methods.
void copy_byte_block(vxl_byte *data, const vxl_uint_32 nbytes, vil_memory_chunk_sptr &cnk) const
Transfer data from block to memory chunk, row by row.
Definition: vil_tiff.cxx:655
------— Representation of Pyramid Images by multi-image TIFF ----—
Definition: vil_tiff.h:327
unsigned block_index(unsigned block_i, unsigned block_j) const
Definition: vil_tiff.cxx:639
vil_pyramid_image_resource_sptr make_pyramid_output_image(char const *file) override
Definition: vil_tiff.cxx:358
unsigned header_index_
the tiff header index.
Definition: vil_tiff.h:339
Base class for image formats.
unsigned samples_per_block() const
the number of samples in a block.
Definition: vil_tiff.cxx:645
bool * tiff_byte_align_data< bool >(bool *in_data, unsigned num_samples, unsigned in_bits_per_sample, bool *out_data)
Definition: vil_tiff.cxx:495
vil_tiff_pyramid_resource()
default constructor.
Definition: vil_tiff.cxx:1296
T * tiff_byte_align_data(T *in_data, unsigned num_samples, unsigned in_bits_per_sample, T *out_data)
This function will byte align the data in in_data and store the result in out_data.
Definition: vil_tiff.h:559
vil_image_resource_sptr make_input_image(vil_stream *vs) override
Attempt to make a generic_image which will read from vil_stream vs.
Definition: vil_tiff.cxx:195
unsigned nj_
the image length.
Definition: vil_tiff.h:348
std::vector< tiff_pyramid_level * > levels_
Definition: vil_tiff.h:443
tif_smart_ptr t_
the tiff handle.
Definition: vil_tiff.h:440
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
tiff_pyramid_level * closest(const float scale) const
find the image resource with scale closest to specified scale.
Definition: vil_tiff.cxx:1272
A blocked representation of the image_resource.
bool read_
If true resource is open for read, else open for write.
Definition: vil_tiff.h:437
unsigned size_block_j() const override
Block size in rows (must be a multiple of 16).
Definition: vil_tiff.cxx:608
vil_tiff_header * h_
the TIFF header information.
Definition: vil_tiff.h:251
unsigned size_block_i() const override
Block size in columns (must be a multiple of 16).
Definition: vil_tiff.cxx:594
void print(const unsigned l)
Definition: vil_tiff.h:359
unsigned n_block_i() const override
Number of blocks in image width.
Definition: vil_tiff.cxx:621
bool set_compression_quality(int quality)
Definition: vil_tiff.cxx:426
TIFF * tif()
Definition: vil_tiff.h:98
Representation of a pyramid resolution hierarchy.
Pyramid resource built on the multi-image capability of the TIFF format.
Definition: vil_tiff.h:365
enum vil_pixel_format pixel_format() const override
Pixel Format.
Definition: vil_tiff.h:390
tiff_pyramid_level(unsigned header_index, unsigned ni, unsigned nj, unsigned nplanes, vil_pixel_format fmt)
Definition: vil_tiff.h:330
bool put_view(const vil_image_view_base &im, unsigned i0, unsigned j0) override
Put the data in this view back into the image source.
Definition: vil_tiff.cxx:1205
vil_tiff_image(tif_smart_ptr const &tif, vil_tiff_header *th, const unsigned nimages=1)
Definition: vil_tiff.cxx:379
~tiff_pyramid_level()=default
unsigned cur_level_
temporary variable for current level.
Definition: vil_tiff.h:357
unsigned int index() const
the image index for multiple image files.
Definition: vil_tiff.h:237
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
Generic image interface for image TIFF image files (could have multiple images).
Definition: vil_tiff.h:149
void set_index(const unsigned int index)
point to a particular image in the file.
Definition: vil_tiff.h:239
tif_ref_cnt(TIFF *tif)
Definition: vil_tiff.h:97
char const * tag() const override
Return a character string which uniquely identifies this format.
Definition: vil_tiff.cxx:368
void pad_block_with_zeros(unsigned ioff, unsigned joff, unsigned iclip, unsigned jclip, unsigned bytes_per_pixel, vxl_byte *block_buf)
fill out the block with leading zeros or trailing zeros if necessary.
Definition: vil_tiff.cxx:966
TIFF * tif_
Definition: vil_tiff.h:112
tif_smart_ptr const & tiff() const
Get a smart pointer to opentiff object.
Definition: vil_tiff.h:242
bool put_block(unsigned block_index_i, unsigned block_index_j, const vil_image_view_base &blk) override
put the block into the resource at the indicated location.
Definition: vil_tiff.cxx:1227
unsigned ni_
the image width.
Definition: vil_tiff.h:345
unsigned ni() const override
Dimensions: Planes x ni x nj.
Definition: vil_tiff.cxx:579
unsigned nplanes() const override
Dimensions: planes x width x height x components.
Definition: vil_tiff.cxx:574
A header structure for geotiff files.
~vil_tiff_pyramid_resource() override
Definition: vil_tiff.cxx:1342
Representation of a generic image source or destination.
vil_image_view_base_sptr fill_block_from_strip(vil_memory_chunk_sptr const &buf) const
Definition: vil_tiff.cxx:884
unsigned int nimages() const
indicates the number of images in the tiff file.
Definition: vil_tiff.h:234
tif_smart_ptr(tif_smart_ptr const &tp)
Definition: vil_tiff.h:124
Loader for tiff files.
Definition: vil_tiff.h:46
bool set_compression_method(compression_methods cm)
Definition: vil_tiff.cxx:414
bool put_resource(vil_image_resource_sptr const &resc) override
Caution! The resource is assigned a header and the data is permanently written into the file.
Definition: vil_tiff.cxx:1395
Base class for image formats.
unsigned nplanes() const override
The number of planes (or components) of the image.
Definition: vil_tiff.h:376
vil_pixel_format pix_fmt_
the pixel format.
Definition: vil_tiff.h:354
unsigned cnt_
Definition: vil_tiff.h:113
vil_image_view_base_sptr get_block(unsigned block_index_i, unsigned block_index_j) const override
Block access.
Definition: vil_tiff.cxx:710
unsigned ni() const override
The number of pixels in each row.
Definition: vil_tiff.h:381
TIFF * tif() const
Convenient get TIFF* for header construction; assumes temporary use.
Definition: vil_tiff.h:143
A header structure for tiff files.
void bitpack_block(unsigned bytes_per_block, const vxl_byte *in_block_buf, vxl_byte *out_block_buf)
Definition: vil_tiff.cxx:1106
bool operator!() const
Inverse bool.
Definition: vil_tiff.h:137
unsigned int index_
the default image header index.
Definition: vil_tiff.h:253
~vil_tiff_image() override
Definition: vil_tiff.cxx:456
unsigned nj() const override
Dimensions: Planes x ni x nj.
Definition: vil_tiff.cxx:586
bool write_block_to_file(unsigned bi, unsigned bj, unsigned block_size_bytes, vxl_byte *block_buf)
Definition: vil_tiff.cxx:1090
void ref()
Definition: vil_tiff.h:99
tif_smart_ptr t_
the TIFF handle to the open resource file.
Definition: vil_tiff.h:248