2 #ifndef vil_tiff_file_format_h_ 3 #define vil_tiff_file_format_h_ 28 # include <vcl_msvc_warnings.h> 31 #include <vil/vil_config.h> 49 char const *
tag()
const override;
67 char const* temp_dir)
override;
80 unsigned size_block_i,
81 unsigned size_block_j,
107 #endif // HAS_GEOTIFF 139 return (
tptr_ !=
nullptr)? false :
true;
178 unsigned nplanes()
const override;
179 unsigned ni()
const override;
180 unsigned nj()
const override;
189 bool is_GEOTIFF() {
return h_->is_GEOTIFF(); }
207 unsigned block_index_j )
const override;
209 bool put_block(
unsigned block_index_i,
unsigned block_index_j,
220 bool get_property(
char const *
tag,
void *prop =
nullptr)
const override;
259 void clear_TIFF() {
t_ = 0; }
274 unsigned bits_per_sample)
const;
283 unsigned block_index_j )
const;
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;
291 bool put_block(
unsigned bi,
unsigned bj,
unsigned i0,
294 unsigned block_index(
unsigned block_i,
unsigned block_j)
const;
298 unsigned iclip,
unsigned jclip,
299 unsigned bytes_per_pixel,
300 vxl_byte* block_buf);
304 unsigned i0,
unsigned j0,
305 unsigned ioff,
unsigned joff,
306 unsigned iclip,
unsigned jclip,
308 vxl_byte*& block_buf);
311 const vxl_byte* in_block_buf,
312 vxl_byte* out_block_buf);
315 unsigned block_size_bytes,
316 vxl_byte* block_buf);
360 { std::cout <<
"level[" << l <<
"] hindex " <<
header_index_ <<
" scale: " <<
scale_ <<
" width: " <<
ni_ << std::endl; }
381 inline unsigned ni()
const override 386 inline unsigned nj()
const override 404 unsigned j0,
unsigned n_j,
405 unsigned level)
const override;
411 unsigned j0,
unsigned n_j,
413 float& actual_scale)
const override;
424 void print(
const unsigned level)
override 463 unsigned sample_offset = i0 / (
sizeof(T)*8 );
464 unsigned bit_offset = i0 % (
sizeof(T)*8 );
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 ){
474 if ( strip_right > 0 ){
478 for (
int i = 0 ; i < strip_right ; i++ ) temp /= 2;
481 else if ( strip_right < 0 ){
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 );
489 T next = in_val[sample_offset+1];
491 int new_strip_right = strip_right + (
sizeof(T)*8);
492 for (
int i = 0 ; i < new_strip_right ; i++ ) next /= 2;
494 unsigned new_strip_left = 1- strip_right;
495 temp <<= new_strip_left;
500 std::cout <<
"Out val = " << std::hex << temp << std::dec <<
'\n';
561 assert( in_bits_per_sample <
sizeof(T)*8 );
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 );
569 bit_offset+=in_bits_per_sample;
575 template<>
bool*
tiff_byte_align_data<bool>(
bool* in_data,
unsigned num_samples,
unsigned in_bits_per_sample,
bool* out_data );
577 #endif // vil_tiff_file_format_h_ unsigned nlevels() const override
number of pyramid levels.
float scale_
scale associated with level.
vil_image_view_base_sptr fill_block_from_tile(vil_memory_chunk_sptr const &buf) const
the key methods for decoding the file data.
An abstract base class of smart pointers to actual image data in memory.
tif_smart_ptr(tif_ref_cnt *tptr)
unsigned n_block_j() const override
Number of blocks in image height.
char const * file_format() const override
Return a string describing the file format.
void normalize_scales()
normalize the scale factors so that the base image scale = 1.0.
char const * file_format() const override
returns "tiff".
enum vil_pixel_format compute_pixel_format()
void print(const unsigned level) override
for debug purposes.
bool get_property(char const *tag, void *prop=nullptr) const override
Return true if the property given in the first argument has been set.
T tiff_get_bits(const T *in_val, unsigned i0, unsigned ni)
This function does a lot of work for.
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.
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.
enum vil_pixel_format pixel_format() const override
Pixel Format.
unsigned nj() const override
The number of pixels in each column.
unsigned int nimages_
number of images in the file.
unsigned nplanes_
the number of planes.
vil_image_resource_sptr get_resource(const unsigned level) const override
returns the image resource at the specified pyramid level.
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.
------— Representation of Pyramid Images by multi-image TIFF ----—
unsigned block_index(unsigned block_i, unsigned block_j) const
unsigned header_index_
the tiff header index.
unsigned samples_per_block() const
the number of samples in a block.
bool * tiff_byte_align_data< bool >(bool *in_data, unsigned num_samples, unsigned in_bits_per_sample, bool *out_data)
vil_tiff_pyramid_resource()
default constructor.
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.
unsigned nj_
the image length.
std::vector< tiff_pyramid_level * > levels_
tif_smart_ptr t_
the tiff handle.
Stream interface for VIL image loaders.
tiff_pyramid_level * closest(const float scale) const
find the image resource with scale closest to specified scale.
A blocked representation of the image_resource.
bool read_
If true resource is open for read, else open for write.
unsigned size_block_j() const override
Block size in rows (must be a multiple of 16).
vil_tiff_header * h_
the TIFF header information.
unsigned size_block_i() const override
Block size in columns (must be a multiple of 16).
void print(const unsigned l)
unsigned n_block_i() const override
Number of blocks in image width.
bool set_compression_quality(int quality)
Representation of a pyramid resolution hierarchy.
Pyramid resource built on the multi-image capability of the TIFF format.
enum vil_pixel_format pixel_format() const override
Pixel Format.
tiff_pyramid_level(unsigned header_index, unsigned ni, unsigned nj, unsigned nplanes, vil_pixel_format fmt)
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.
vil_tiff_image(tif_smart_ptr const &tif, vil_tiff_header *th, const unsigned nimages=1)
~tiff_pyramid_level()=default
unsigned cur_level_
temporary variable for current level.
unsigned int index() const
the image index for multiple image files.
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).
void set_index(const unsigned int index)
point to a particular image in the file.
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.
tif_smart_ptr const & tiff() const
Get a smart pointer to opentiff object.
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.
unsigned ni_
the image width.
unsigned ni() const override
Dimensions: Planes x ni x nj.
unsigned nplanes() const override
Dimensions: planes x width x height x components.
~vil_tiff_pyramid_resource() override
Representation of a generic image source or destination.
vil_image_view_base_sptr fill_block_from_strip(vil_memory_chunk_sptr const &buf) const
unsigned int nimages() const
indicates the number of images in the tiff file.
tif_smart_ptr(tif_smart_ptr const &tp)
bool set_compression_method(compression_methods cm)
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.
unsigned nplanes() const override
The number of planes (or components) of the image.
vil_pixel_format pix_fmt_
the pixel format.
vil_image_view_base_sptr get_block(unsigned block_index_i, unsigned block_index_j) const override
Block access.
unsigned ni() const override
The number of pixels in each row.
TIFF * tif() const
Convenient get TIFF* for header construction; assumes temporary use.
void bitpack_block(unsigned bytes_per_block, const vxl_byte *in_block_buf, vxl_byte *out_block_buf)
bool operator!() const
Inverse bool.
unsigned int index_
the default image header index.
~vil_tiff_image() override
unsigned nj() const override
Dimensions: Planes x ni x nj.
bool write_block_to_file(unsigned bi, unsigned bj, unsigned block_size_bytes, vxl_byte *block_buf)
tif_smart_ptr t_
the TIFF handle to the open resource file.