32 #include <jpeg12/jpeglib.h> 33 #include <jpeg12/jerror.h> 35 static ossimTrace traceDebug(
"ossimJpeg12NitrReader:debug");
38 "ossimJpeg12NitfReader",
44 struct jpeg12_error_mgr pub;
45 jmp_buf setjmp_buffer;
56 (*cinfo->err->output_message) (cinfo);
59 longjmp(myerr->setjmp_buffer, 1);
87 <<
"ossimJpeg12NitrReader::uncompressJpegBlock DEBUG:" 88 <<
"\nblockNumber: " << blockNumber
106 <<
"ossimJpeg12NitrReader::uncompressJpegBlock scan for offsets error!" 107 <<
"\nReturning error..." << endl;
126 if (!
theFileStr->read((
char*)&(compressedBuf.front()),
131 <<
"ossimJpeg12NitrReader::uncompressJpegBlock Read Error!" 132 <<
"\nReturning error..." << endl;
136 jpeg12_decompress_struct cinfo;
138 ossimJpegErrorMgr12 jerr;
140 cinfo.err = jpeg12_std_error(&jerr.pub);
145 if (setjmp(jerr.setjmp_buffer))
147 jpeg12_destroy_decompress(&cinfo);
152 jpeg12_CreateDecompress(&cinfo, JPEG12_LIB_VERSION,
sizeof(cinfo));
159 &(compressedBuf.front()),
164 jpeg12_read_header(&cinfo,
TRUE);
168 if (cinfo.quant_tbl_ptrs[0] == NULL)
173 jpeg12_destroy_decompress(&cinfo);
179 if (cinfo.ac_huff_tbl_ptrs[0] == NULL)
184 jpeg12_destroy_decompress(&cinfo);
197 jpeg12_start_decompress(&cinfo);
215 const ossim_uint32 ROW_STRIDE = SAMPLES * cinfo.output_components;
218 static bool TRACED =
false;
222 <<
"\nSAMPLES: " << SAMPLES
223 <<
"\nLINES_TO_READ: " << LINES_TO_READ
224 <<
"\nROW_STRIDE: " << ROW_STRIDE
225 <<
"\nJPEG12_BITS_IN_JSAMPLE: " << JPEG12_BITS_IN_JSAMPLE
226 <<
"\nsizeof jsamp: " <<
sizeof(JSAMPLE)
227 <<
"\ndata_precision: " << cinfo.data_precision
228 <<
"\ntotal_iMCU_rows: " << cinfo.total_iMCU_rows
235 if ( (SAMPLES < theCacheTile->getWidth() ) ||
244 jpeg12_finish_decompress(&cinfo);
245 jpeg12_destroy_decompress(&cinfo);
258 std::vector<ossim_uint16> lineBuffer(ROW_STRIDE);
261 jbuf[0] = (JSAMPROW) &(lineBuffer.front());
263 while (cinfo.output_scanline < LINES_TO_READ)
266 jpeg12_read_scanlines(&cinfo, jbuf, 1);
269 for (
ossim_uint32 sample = 0; sample < SAMPLES; ++sample)
273 destinationBuffer[band][sample] = lineBuffer[index];
284 jpeg12_finish_decompress(&cinfo);
285 jpeg12_destroy_decompress(&cinfo);
291 jpeg12_decompress_struct& cinfo)
const 301 if (comrat.
size() >= 4)
305 s.
push_back(comrat[static_cast<std::string::size_type>(3)]);
307 if ( (comTbl > 0) && (comTbl < 6) )
309 tableIndex = comTbl-1;
314 <<
"ossimJpeg12NitrReader::loadJpegQuantizationTables WARNING\n" 315 <<
"\nNo quantization tables specified!" 321 cinfo.quant_tbl_ptrs[0] = jpeg12_alloc_quant_table((j12_common_ptr) &cinfo);
323 JQUANT_TBL* quant_ptr = cinfo.quant_tbl_ptrs[0];
328 quant_ptr->quantval[i] = QTABLE_ARRAY[tableIndex][i];
335 if ( (cinfo.ac_huff_tbl_ptrs[0] != NULL) &&
336 (cinfo.dc_huff_tbl_ptrs[0] != NULL) )
341 cinfo.ac_huff_tbl_ptrs[0] = jpeg12_alloc_huff_table((j12_common_ptr)&cinfo);
342 cinfo.dc_huff_tbl_ptrs[0] = jpeg12_alloc_huff_table((j12_common_ptr)&cinfo);
348 huff_ptr = cinfo.ac_huff_tbl_ptrs[0];
349 for (i = 0; i < 16; ++i)
352 huff_ptr->bits[i+1] = AC_BITS[i];
355 for (i = 0; i < 256; ++i)
357 huff_ptr->huffval[i] = AC_HUFFVAL[i];
361 huff_ptr = cinfo.dc_huff_tbl_ptrs[0];
362 for (i = 0; i < 16; ++i)
365 huff_ptr->bits[i+1] = DC_BITS[i];
368 for (i = 0; i < 256; i++)
371 huff_ptr->huffval[i] = DC_HUFFVAL[i];
virtual ossim_uint32 getWidth() const
struct ossimJpegErrorMgr12 * ossimJpegErrorPtr12
virtual const ossim_uint16 * getUshortBuf() const
ossim_uint32 theNumberOfInputBands
virtual bool uncompressJpegBlock(ossim_uint32 x, ossim_uint32 y)
Uncompresses a jpeg block using the jpeg-6b library.
std::shared_ptr< ossim::istream > theFileStr
void ossimJpegErrorExit12(jpeg12_common_struct *cinfo)
std::vector< ossim_uint32 > theNitfBlockSize
ossim_uint32 theReadBlockSizeInBytes
virtual ossim_uint32 getHeight() const
bool loadJpeg12HuffmanTables(jpeg12_decompress_struct &cinfo) const
Loads default huffman tables.
static const ossimErrorCode OSSIM_ERROR
void ossimJpegMemorySrc12(j12_decompress_ptr cinfo, const ossim_uint8 *buffer, std::size_t bufsize)
ossimJpeg12NitfReader class for reading NITF images with 12 bit jpeg compressed blocks using libjpeg-...
virtual bool canUncompress(const ossimNitfImageHeader *hdr) const
ossim_int32 toInt32() const
void push_back(char c)
Equivalent to insert(end(), c).
std::string::size_type size() const
unsigned int ossim_uint32
ossimRefPtr< ossimImageData > theCacheTile
RTTI_DEF1_INST(ossimJpeg12NitfReader, "ossimJpeg12NitfReader", ossimNitfTileSource) struct OSSIM_DLL ossimJpegErrorMgr12
Extended error handler struct for jpeg code.
const ossimNitfImageHeader * getCurrentImageHeader() const
ossimErrorCode theErrorStatus
virtual void makeBlank()
Initializes data to null pixel values.
virtual bool scanForJpegBlockOffsets()
scans the file storing in offsets in "theNitfBlockOffset" and block sizes in "theNitfBlockSize".
ossim_uint32 getBlockNumber(const ossimIpt &block_origin) const
virtual bool canUncompress(const ossimNitfImageHeader *hdr) const
bool loadJpeg12QuantizationTables(jpeg12_decompress_struct &cinfo) const
Loads one of the default tables based on COMRAT value.
std::vector< std::streamoff > theNitfBlockOffset
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)