core/vil/file_formats/vil_nitf2_data_mask_table.h
Go to the documentation of this file.
00001 // vil_nitf2: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of
00002 // Stellar Science Ltd. Co. (stellarscience.com) for
00003 // Air Force Research Laboratory, 2005.
00004 
00005 #ifndef VIL_NITF2_DATA_MASK_TABLE_H
00006 #define VIL_NITF2_DATA_MASK_TABLE_H
00007 //:
00008 // \file
00009 
00010 #include <vcl_vector.h>
00011 #include <vxl_config.h>
00012 #include <vcl_string.h>
00013 #include <vil/vil_pixel_format.h>
00014 
00015 class vil_stream;
00016 
00017 //: This class is responsible for parsing a NITF 2.1 data mask table.
00018 //  When present, a vil_nitf2_image_subheader() will use this class
00019 //  to extract the table from the file.  It reads a vil_stream, via
00020 //  the parse() method and will return false if it failed.
00021 class vil_nitf2_data_mask_table
00022 {
00023  public:
00024   vil_nitf2_data_mask_table( unsigned int numBlocksX, unsigned int numBlocksY,
00025                              unsigned int numBands, const vcl_string imode );
00026   bool parse( vil_stream* stream );
00027 
00028   //: If this function returns true, then you may call \sa block_band_offset()
00029   bool has_offset_table() const { return BMR_n_BND_m.size() > 0; }
00030 
00031   //: If this function returns true, then you may call \sa pad_pixel()
00032   bool has_pad_pixel_table() const { return TMR_n_BND_m.size() > 0; }
00033 
00034   vxl_uint_32 blocked_image_data_offset() const;
00035 
00036   //: Returns true iff this block is present in the data.  False otherwise.
00037   //  If this returns false, then there is not sense calling block_band_offset
00038   //  for this band/block combination. It will return 0xFFFFFFFF.
00039   //  If this returns false, then this entire block/band is considered to be blank.
00040   vxl_uint_32 block_band_present( unsigned int block_x, unsigned int block_y, int band = -1) const;
00041 
00042   //:
00043   //  if imode == "S", then the band argument is used and I will return the offset to 'band'
00044   //  if imode != "S", then the band argument is ignored, and I will return the offset to the
00045   //  beginning of the requested block
00046   vxl_uint_32 block_band_offset( unsigned int block_x, unsigned int block_y, int band = -1) const;
00047 
00048   //:
00049   // band argument is ignored if imode != "S"... i.e. all bands have the same pad pixel in that case
00050   vxl_uint_32 pad_pixel( unsigned int block_x, unsigned int block_y, int band ) const;
00051 
00052   vxl_uint_32 block_band_has_pad( unsigned int block_x, unsigned int block_y, int band = -1) const;
00053 
00054   static void maybe_endian_swap( char* a, unsigned sizeOfAInBytes, vil_pixel_format pixFormat );
00055   static void maybe_endian_swap( char* a, unsigned sizeOfAInBytes, unsigned int bytesPerSample );
00056  protected:
00057   //Blocked Image Data Offset (in bytes)
00058   vxl_uint_32 IMDATOFF;
00059   //Block Mask Record Length (in bytes)
00060   vxl_uint_16 BMRLNTH;
00061   //Pad Pixel Mask Record Length (in bytes)
00062   vxl_uint_16 TMRLNTH;
00063   //Pad Output Pixel Code Length (in bits)
00064   vxl_uint_16 TPXCDLNTH;
00065   //Pad Output Pixel Code
00066   // (it's an integer, but its length is TPXCDLNTH rounded up to the nearest byte)
00067 #if VXL_HAS_INT_64
00068   vxl_uint_64 TPXCD;
00069 #else
00070   vxl_uint_32 TPXCD;
00071 #endif //VXL_HAS_INT_64
00072 
00073   //Block n, Band m Offset
00074   //indexed BMR_n_BND_m[row][col][band] for i_mode = "S" else
00075   //indexed BMR_n_BND_m[row][col]
00076   vcl_vector< vcl_vector< vcl_vector< vxl_uint_32 > > > BMR_n_BND_m;
00077   //Pad Pixel n, Band m
00078   //indexed TMR_n_BND_m[row][col][band] for i_mode = "S" else
00079   //indexed TMR_n_BND_m[row][col]
00080   vcl_vector< vcl_vector< vcl_vector< vxl_uint_32 > > > TMR_n_BND_m;
00081 
00082   unsigned int num_blocks_x;
00083   unsigned int num_blocks_y;
00084   unsigned int num_bands;
00085   vcl_string i_mode;
00086 };
00087 
00088 #endif // VIL_NITF2_DATA_MASK_TABLE_H