27 struct jpeg_error_mgr
pub;
39 (*cinfo->err->output_message) (cinfo);
66 std::vector<ossim_uint8>& out )
const 80 struct jpeg_compress_struct cinfo;
81 struct jpeg_error_mgr jerr;
82 cinfo.err = jpeg_std_error( &jerr );
83 jpeg_create_compress(&cinfo);
94 if ( (INPUT_BANDS == 1) || (INPUT_BANDS == 3) )
96 cinfo.input_components = INPUT_BANDS;
100 if ( INPUT_BANDS < 3 )
102 cinfo.input_components = 1;
106 cinfo.input_components = 3;
111 if ( cinfo.input_components == 3)
113 cinfo.in_color_space = JCS_RGB;
117 cinfo.in_color_space = JCS_GRAYSCALE;
121 jpeg_set_defaults( &cinfo );
126 jpeg_start_compress( &cinfo,
TRUE );
129 ossim_uint32 buf_size = cinfo.input_components*cinfo.image_width;
130 std::vector<ossim_uint8> buf(buf_size);
134 JSAMPROW row_pointer[1];
135 row_pointer[0] = (JSAMPLE*)&buf.front();
138 std::vector<const ossim_uint8*> inBuf(cinfo.input_components);
139 for (
ossim_int32 band = 0; band < cinfo.input_components; ++band )
145 for (
ossim_uint32 line=0; line< cinfo.image_height; ++line)
151 for (
ossim_int32 band = 0; band < cinfo.input_components; ++band )
153 buf[outIdx++] = inBuf[band][inIdx];
159 jpeg_write_scanlines( &cinfo, row_pointer, 1 );
163 jpeg_finish_compress( &cinfo );
164 jpeg_destroy_compress( &cinfo );
167 out.resize(jpegStreamBuf.str().size());
168 jpegStreamBuf.seekg(0, std::ios_base::beg);
169 jpegStreamBuf.read((
char*)&out.front(), jpegStreamBuf.str().size());
176 <<
"ossimCodecFactory::encodeJpeg ERROR:" 177 <<
"\nPassing non-eight bit data to eight bit encoder!" << std::endl;
194 if ( (in[0] == 0xff) &&
202 else if (in[3] == 0xdb)
220 jpeg_decompress_struct cinfo;
231 cinfo.err = jpeg_std_error(&jerr.
pub);
241 jpeg_CreateDecompress(&cinfo, JPEG_LIB_VERSION,
sizeof(cinfo));
250 jpeg_read_header(&cinfo,
TRUE);
255 jpeg_start_decompress(&cinfo);
265 <<
"jpeg cinfo.output_width: " << cinfo.output_width
266 <<
"\njpeg cinfo.output_height: " << cinfo.output_height
267 <<
"\njpeg cinfo.out_color_space: " << cinfo.out_color_space
285 std::vector<ossim_uint8*> destinationBuffer(BANDS);
291 std::vector<ossim_uint8> lineBuffer(SAMPLES * cinfo.output_components);
293 jbuf[0] = (JSAMPROW) &(lineBuffer.front());
295 while (cinfo.output_scanline < LINES)
298 jpeg_read_scanlines(&cinfo, jbuf, 1);
305 for (
ossim_uint32 sample = 0; sample < SAMPLES; ++sample)
309 destinationBuffer[band][sample] = lineBuffer[index];
316 destinationBuffer[band] += SAMPLES;
325 jpeg_finish_decompress(&cinfo);
329 jpeg_destroy_decompress(&cinfo);
342 if ( jpegColorSpace == JCS_CMYK )
349 if ( cmykTile.
valid() )
352 if ( INPUT_BANDS == 4 )
373 std::vector<const ossim_uint8*> inBands(INPUT_BANDS);
374 for ( band = 0; band < INPUT_BANDS; ++band )
378 std::vector<ossim_uint8*> outBands(INPUT_BANDS);
379 for ( band = 0; band < OUTPUT_BANDS; ++band )
387 std::vector<ossim_float32> cmyk(INPUT_BANDS, 0.0);
388 std::vector<ossim_float32> rgb(OUTPUT_BANDS, 0.0);
392 for (
ossim_uint32 sample = 0; sample < SAMPLES; ++sample)
402 cmyk[0] = inBands[0][sample];
403 cmyk[1] = inBands[1][sample];
404 cmyk[2] = inBands[2][sample];
405 cmyk[3] = inBands[3][sample];
415 rgb[0] = (cmyk[0]) * cmyk[3]/255.0;
416 rgb[1] = (cmyk[1]) * cmyk[3]/255.0;
417 rgb[2] = (cmyk[2]) * cmyk[3]/255.0;
419 outBands[0][sample] =
420 ( (rgb[0] >= 0.0) ? ( (rgb[0] <= 255.0) ?
422 outBands[1][sample] =
423 ( (rgb[1] >= 0.0) ? ( (rgb[1] <= 255.0) ?
425 outBands[2][sample] =
426 ( (rgb[2] >= 0.0) ? ( (rgb[2] <= 255.0) ?
432 for (
ossim_uint32 band = 0; band < OUTPUT_BANDS; ++band)
434 inBands[band] += SAMPLES;
435 outBands[band] += SAMPLES;
437 inBands[3] += SAMPLES;
454 <<
"ossimJpegCodec::decodeJpegRgb: WARNING: " 455 <<
"Unhandled jpeg output color space!" << std::endl;
464 J_COLOR_SPACE result = JCS_UNKNOWN;
468 jpeg_decompress_struct cinfo;
470 cinfo.err = jpeg_std_error(&jerr.
pub);
476 jpeg_CreateDecompress(&cinfo, JPEG_LIB_VERSION,
sizeof(cinfo));
478 jpeg_read_header(&cinfo,
TRUE);
479 result = cinfo.out_color_space;
480 jpeg_destroy_decompress(&cinfo);
490 m_quality =
property->valueToString().toUInt32();
virtual ossim_uint32 getWidth() const
virtual ossim_uint32 getNumberOfBands() const
std::basic_stringstream< char > stringstream
Class for char mixed input and output memory streams.
virtual const ossim_uint8 * getUcharBuf() const
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossim_uint32 height() const
static ossimString toString(bool aValue)
Numeric to string methods.
bool decodeJpegToRgb(const std::vector< ossim_uint8 > &in, ossimRefPtr< ossimImageData > &out) const
For decoding color spaces other that mono and rgb.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
ossim_uint32 toUInt32() const
void ossimJpegErrorExit(jpeg_common_struct *cinfo)
Error routine that will replace jpeg's standard error_exit method.
virtual void initialize()
Initialize the data buffer.
struct jpeg_error_mgr pub
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossim_int32 getColorSpace(const std::vector< ossim_uint8 > &in) const
OSSIM_DLL void ossimJpegMemorySrc(jpeg_decompress_struct *cinfo, const ossim_uint8 *buffer, std::size_t bufsize)
Method which uses memory instead of a FILE* to read from.
virtual ossimDataObjectStatus validate() const
virtual void setImageRectangleAndBands(const ossimIrect &rect, ossim_uint32 numberOfBands)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Save the state of the codec to the keywordlist.
virtual const std::string & getExtension() const
unsigned int ossim_uint32
virtual ~ossimJpegCodec()
bool decodeJpeg(const std::vector< ossim_uint8 > &in, ossimRefPtr< ossimImageData > &out) const
For decoding standard jpeg block.
virtual ossimIrect getImageRectangle() const
struct ossimJpegErrorMgr * ossimJpegErrorPtr
virtual bool encode(const ossimRefPtr< ossimImageData > &in, std::vector< ossim_uint8 > &out) const
Encode jpeg method.
ossim_uint32 width() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Allocate the state of the object thorugh a factory load/keywordlist.
virtual ossimScalarType getScalarType() const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
Interface to get the value of a specific property.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Ineterface to allow for specific properties to be set.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Get a list of all supported property names.
virtual ossimString getCodecType() const
virtual bool decode(const std::vector< ossim_uint8 > &in, ossimRefPtr< ossimImageData > &out) const
Decode jpeg method.
OSSIM_DLL void jpeg_cpp_stream_dest(jpeg_compress_struct *cinfo, std::ostream &stream)
Method which uses memory instead of a FILE* to write to.
static const char * QUALITY_KW
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
const ossimString & getName() const