|
|
|
@ -103,7 +103,7 @@ struct JPEGSourceManager : public jpeg_source_mgr {
|
|
|
|
|
/* Do not replace boolean with bool, it's the libjpeg boolean type */
|
|
|
|
|
static boolean gvFillInputBuffer(j_decompress_ptr cinfo) {
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("FillInputBuffer called!");
|
|
|
|
|
tqDebug("FillInputBuffer called!");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
JPEGSourceManager* src = (JPEGSourceManager*)cinfo->src;
|
|
|
|
@ -115,7 +115,7 @@ struct JPEGSourceManager : public jpeg_source_mgr {
|
|
|
|
|
src->bytes_in_buffer = 2;
|
|
|
|
|
src->next_input_byte = (JOCTET *) src->jpeg_buffer;
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("...returning true!");
|
|
|
|
|
tqDebug("...returning true!");
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
@ -127,7 +127,7 @@ struct JPEGSourceManager : public jpeg_source_mgr {
|
|
|
|
|
if(num_bytes <= 0) return; /* required noop */
|
|
|
|
|
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("SkipInputData (%d) called!", num_bytes);
|
|
|
|
|
tqDebug("SkipInputData (%d) called!", num_bytes);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
JPEGSourceManager* src = (JPEGSourceManager*)cinfo->src;
|
|
|
|
@ -136,10 +136,10 @@ struct JPEGSourceManager : public jpeg_source_mgr {
|
|
|
|
|
unsigned int skipbytes = kMin(src->bytes_in_buffer, src->skip_input_bytes);
|
|
|
|
|
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("skip_input_bytes is now %d", src->skip_input_bytes);
|
|
|
|
|
qDebug("skipbytes is now %d", skipbytes);
|
|
|
|
|
qDebug("valid_buffer_length is before %d", src->valid_buffer_length);
|
|
|
|
|
qDebug("bytes_in_buffer is %d", src->bytes_in_buffer);
|
|
|
|
|
tqDebug("skip_input_bytes is now %d", src->skip_input_bytes);
|
|
|
|
|
tqDebug("skipbytes is now %d", skipbytes);
|
|
|
|
|
tqDebug("valid_buffer_length is before %d", src->valid_buffer_length);
|
|
|
|
|
tqDebug("bytes_in_buffer is %d", src->bytes_in_buffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if(skipbytes < src->bytes_in_buffer) {
|
|
|
|
@ -156,8 +156,8 @@ struct JPEGSourceManager : public jpeg_source_mgr {
|
|
|
|
|
cinfo->src->next_input_byte = (JOCTET *) src->jpeg_buffer;
|
|
|
|
|
cinfo->src->bytes_in_buffer = (size_t) src->valid_buffer_length;
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("valid_buffer_length is afterwards %d", src->valid_buffer_length);
|
|
|
|
|
qDebug("skip_input_bytes is now %d", src->skip_input_bytes);
|
|
|
|
|
tqDebug("valid_buffer_length is afterwards %d", src->valid_buffer_length);
|
|
|
|
|
tqDebug("skip_input_bytes is now %d", src->skip_input_bytes);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -218,20 +218,20 @@ JPEGFormat::~JPEGFormat() {
|
|
|
|
|
|
|
|
|
|
int JPEGFormat::decode(TQImage& image, TQImageConsumer* consumer, const uchar* buffer, int length) {
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("JPEGFormat::decode(%p, %p, %p, %d)",
|
|
|
|
|
tqDebug("JPEGFormat::decode(%p, %p, %p, %d)",
|
|
|
|
|
&image, consumer, buffer, length);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if(mSourceManager.at_eof) {
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("at_eof, eating");
|
|
|
|
|
tqDebug("at_eof, eating");
|
|
|
|
|
#endif
|
|
|
|
|
return length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(setjmp(mErrorManager.jmp_buffer)) {
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("jump into state INVALID");
|
|
|
|
|
tqDebug("jump into state INVALID");
|
|
|
|
|
#endif
|
|
|
|
|
if(consumer) consumer->end();
|
|
|
|
|
|
|
|
|
@ -242,7 +242,7 @@ int JPEGFormat::decode(TQImage& image, TQImageConsumer* consumer, const uchar* b
|
|
|
|
|
int consumed = kMin(length, MAX_BUFFER - mSourceManager.valid_buffer_length);
|
|
|
|
|
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("consuming %d bytes", consumed);
|
|
|
|
|
tqDebug("consuming %d bytes", consumed);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// filling buffer with the new data
|
|
|
|
@ -251,9 +251,9 @@ int JPEGFormat::decode(TQImage& image, TQImageConsumer* consumer, const uchar* b
|
|
|
|
|
|
|
|
|
|
if(mSourceManager.skip_input_bytes) {
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("doing skipping");
|
|
|
|
|
qDebug("valid_buffer_length %d", mSourceManager.valid_buffer_length);
|
|
|
|
|
qDebug("skip_input_bytes %d", mSourceManager.skip_input_bytes);
|
|
|
|
|
tqDebug("doing skipping");
|
|
|
|
|
tqDebug("valid_buffer_length %d", mSourceManager.valid_buffer_length);
|
|
|
|
|
tqDebug("skip_input_bytes %d", mSourceManager.skip_input_bytes);
|
|
|
|
|
#endif
|
|
|
|
|
int skipbytes = kMin((size_t) mSourceManager.valid_buffer_length, mSourceManager.skip_input_bytes);
|
|
|
|
|
|
|
|
|
@ -268,7 +268,7 @@ int JPEGFormat::decode(TQImage& image, TQImageConsumer* consumer, const uchar* b
|
|
|
|
|
|
|
|
|
|
// still more bytes to skip
|
|
|
|
|
if(mSourceManager.skip_input_bytes) {
|
|
|
|
|
if(consumed <= 0) qDebug("ERROR!!!");
|
|
|
|
|
if(consumed <= 0) tqDebug("ERROR!!!");
|
|
|
|
|
return consumed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -278,7 +278,7 @@ int JPEGFormat::decode(TQImage& image, TQImageConsumer* consumer, const uchar* b
|
|
|
|
|
mDecompress.src->bytes_in_buffer = (size_t) mSourceManager.valid_buffer_length;
|
|
|
|
|
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("buffer contains %d bytes", mSourceManager.valid_buffer_length);
|
|
|
|
|
tqDebug("buffer contains %d bytes", mSourceManager.valid_buffer_length);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if(mState == INIT) {
|
|
|
|
@ -297,7 +297,7 @@ int JPEGFormat::decode(TQImage& image, TQImageConsumer* consumer, const uchar* b
|
|
|
|
|
mSourceManager.do_progressive = jpeg_has_multiple_scans( &mDecompress );
|
|
|
|
|
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug( "**** DOPROGRESSIVE: %d", mSourceManager.do_progressive );
|
|
|
|
|
tqDebug( "**** DOPROGRESSIVE: %d", mSourceManager.do_progressive );
|
|
|
|
|
#endif
|
|
|
|
|
mDecompress.buffered_image = mSourceManager.do_progressive;
|
|
|
|
|
|
|
|
|
@ -324,11 +324,11 @@ int JPEGFormat::decode(TQImage& image, TQImageConsumer* consumer, const uchar* b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("will create a picture %d/%d in size", mDecompress.output_width, mDecompress.output_height);
|
|
|
|
|
tqDebug("will create a picture %d/%d in size", mDecompress.output_width, mDecompress.output_height);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("ok, going to DECOMPRESS_STARTED");
|
|
|
|
|
tqDebug("ok, going to DECOMPRESS_STARTED");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
mSourceManager.decoder_timestamp.start();
|
|
|
|
@ -368,7 +368,7 @@ again:
|
|
|
|
|
if(mState == DO_OUTPUT_SCAN) {
|
|
|
|
|
if(image.isNull() || mSourceManager.decoding_done) {
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("complete in doOutputscan, eating..");
|
|
|
|
|
tqDebug("complete in doOutputscan, eating..");
|
|
|
|
|
#endif
|
|
|
|
|
return consumed;
|
|
|
|
|
}
|
|
|
|
@ -381,7 +381,7 @@ again:
|
|
|
|
|
|
|
|
|
|
int completed_scanlines = mDecompress.output_scanline - oldoutput_scanline;
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("completed now %d scanlines", completed_scanlines);
|
|
|
|
|
tqDebug("completed now %d scanlines", completed_scanlines);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if ( mDecompress.output_components == 3 ) {
|
|
|
|
@ -400,7 +400,7 @@ again:
|
|
|
|
|
if(consumer && completed_scanlines) {
|
|
|
|
|
TQRect r(0, oldoutput_scanline, mDecompress.output_width, completed_scanlines);
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("changing %d/%d %d/%d", r.x(), r.y(), r.width(), r.height());
|
|
|
|
|
tqDebug("changing %d/%d %d/%d", r.x(), r.y(), r.width(), r.height());
|
|
|
|
|
#endif
|
|
|
|
|
mSourceManager.change_rect |= r;
|
|
|
|
|
|
|
|
|
@ -428,12 +428,12 @@ again:
|
|
|
|
|
mSourceManager.decoding_done = true;
|
|
|
|
|
}
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("one pass is completed, final_pass = %d, dec_done: %d, complete: %d",
|
|
|
|
|
tqDebug("one pass is completed, final_pass = %d, dec_done: %d, complete: %d",
|
|
|
|
|
mSourceManager.final_pass, mSourceManager.decoding_done, jpeg_input_complete(&mDecompress));
|
|
|
|
|
#endif
|
|
|
|
|
if(!mSourceManager.decoding_done) {
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("starting another one, input_scan_number is %d/%d", mDecompress.input_scan_number,
|
|
|
|
|
tqDebug("starting another one, input_scan_number is %d/%d", mDecompress.input_scan_number,
|
|
|
|
|
mDecompress.output_scan_number);
|
|
|
|
|
#endif
|
|
|
|
|
mSourceManager.decoder_timestamp.restart();
|
|
|
|
@ -445,7 +445,7 @@ again:
|
|
|
|
|
|
|
|
|
|
if(mState == DO_OUTPUT_SCAN && mSourceManager.decoding_done) {
|
|
|
|
|
#ifdef JPEG_DEBUG
|
|
|
|
|
qDebug("input is complete, cleaning up, returning..");
|
|
|
|
|
tqDebug("input is complete, cleaning up, returning..");
|
|
|
|
|
#endif
|
|
|
|
|
if ( consumer && !mSourceManager.change_rect.isEmpty() ) {
|
|
|
|
|
consumer->changed( mSourceManager.change_rect );
|
|
|
|
@ -488,9 +488,9 @@ again:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef BUFFER_DEBUG
|
|
|
|
|
qDebug("valid_buffer_length is now %d", mSourceManager.valid_buffer_length);
|
|
|
|
|
qDebug("bytes_in_buffer is now %d", mSourceManager.bytes_in_buffer);
|
|
|
|
|
qDebug("consumed %d bytes", consumed);
|
|
|
|
|
tqDebug("valid_buffer_length is now %d", mSourceManager.valid_buffer_length);
|
|
|
|
|
tqDebug("bytes_in_buffer is now %d", mSourceManager.bytes_in_buffer);
|
|
|
|
|
tqDebug("consumed %d bytes", consumed);
|
|
|
|
|
#endif
|
|
|
|
|
if(mSourceManager.bytes_in_buffer
|
|
|
|
|
&& mSourceManager.jpeg_buffer != mSourceManager.next_input_byte) {
|
|
|
|
|