mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Backout of 76776 - Tp regression.
This commit is contained in:
parent
db6ae294df
commit
7e87165c13
@ -33,8 +33,6 @@
|
||||
#include "nsCRT.h"
|
||||
#include "ImageLogging.h"
|
||||
|
||||
#include "jerror.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsJPEGDecoder, imgIDecoder)
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
@ -212,20 +210,11 @@ NS_IMETHODIMP nsJPEGDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PR
|
||||
}
|
||||
// else no input stream.. Flush() ?
|
||||
|
||||
|
||||
nsresult error_code = NS_ERROR_FAILURE;
|
||||
/* Return here if there is a fatal error. */
|
||||
nsresult error_code;
|
||||
if ((error_code = setjmp(mErr.setjmp_buffer)) != 0) {
|
||||
mState = JPEG_SINK_NON_JPEG_TRAILER;
|
||||
if (error_code == NS_ERROR_FAILURE) {
|
||||
/* Error due to corrupt stream - return NS_OK so that libpr0n
|
||||
doesn't throw away a partial image load */
|
||||
return NS_OK;
|
||||
} else {
|
||||
/* Error due to reasons external to the stream (probably out of
|
||||
memory) - let libpr0n attempt to clean up, even though
|
||||
mozilla is seconds away from falling flat on its face. */
|
||||
return error_code;
|
||||
}
|
||||
return error_code;
|
||||
}
|
||||
|
||||
PR_LOG(gJPEGlog, PR_LOG_DEBUG,
|
||||
@ -359,7 +348,6 @@ NS_IMETHODIMP nsJPEGDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PR
|
||||
|
||||
mState = JPEG_START_DECOMPRESS;
|
||||
}
|
||||
|
||||
case JPEG_START_DECOMPRESS:
|
||||
{
|
||||
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- entering JPEG_START_DECOMPRESS case");
|
||||
@ -384,6 +372,7 @@ NS_IMETHODIMP nsJPEGDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PR
|
||||
} else {
|
||||
mState = JPEG_DECOMPRESS_SEQUENTIAL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case JPEG_DECOMPRESS_SEQUENTIAL:
|
||||
@ -391,54 +380,61 @@ NS_IMETHODIMP nsJPEGDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PR
|
||||
if (mState == JPEG_DECOMPRESS_SEQUENTIAL)
|
||||
{
|
||||
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- JPEG_DECOMPRESS_SEQUENTIAL case");
|
||||
|
||||
if (OutputScanlines() == PR_FALSE)
|
||||
|
||||
if (OutputScanlines(-1) == PR_FALSE)
|
||||
return NS_OK; /* I/O suspension */
|
||||
|
||||
|
||||
/* If we've completed image output ... */
|
||||
NS_ASSERTION(mInfo.output_scanline == mInfo.output_height, "We didn't process all of the data!");
|
||||
mState = JPEG_DONE;
|
||||
mState = JPEG_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
case JPEG_DECOMPRESS_PROGRESSIVE:
|
||||
{
|
||||
if (mState == JPEG_DECOMPRESS_PROGRESSIVE)
|
||||
{
|
||||
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- JPEG_DECOMPRESS_PROGRESSIVE case");
|
||||
|
||||
while (!jpeg_input_complete(&mInfo)) {
|
||||
if (mInfo.output_scanline == mInfo.output_height)
|
||||
{
|
||||
if (!jpeg_finish_output(&mInfo))
|
||||
return NS_OK; /* I/O suspension */
|
||||
|
||||
if (jpeg_input_complete(&mInfo) &&
|
||||
(mInfo.input_scan_number == mInfo.output_scan_number))
|
||||
break;
|
||||
int status;
|
||||
do {
|
||||
status = jpeg_consume_input(&mInfo);
|
||||
} while (!((status == JPEG_SUSPENDED) ||
|
||||
(status == JPEG_REACHED_EOI)));
|
||||
|
||||
mInfo.output_scanline = 0;
|
||||
}
|
||||
switch (status) {
|
||||
case JPEG_REACHED_EOI:
|
||||
// End of image
|
||||
mState = JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT;
|
||||
break;
|
||||
case JPEG_SUSPENDED:
|
||||
PR_LOG(gJPEGlog, PR_LOG_DEBUG,
|
||||
("[this=%p] nsJPEGDecoder::WriteFrom -- suspending\n", this));
|
||||
|
||||
if (mInfo.output_scanline == 0) {
|
||||
jpeg_consume_input(&mInfo);
|
||||
if (!jpeg_start_output(&mInfo, mInfo.input_scan_number))
|
||||
return NS_OK; /* I/O suspension */
|
||||
}
|
||||
|
||||
if (mInfo.output_scanline == 0xffffff)
|
||||
mInfo.output_scanline = 0;
|
||||
|
||||
if (OutputScanlines() == PR_FALSE) {
|
||||
if (mInfo.output_scanline == 0) {
|
||||
/* didn't manage to read any lines - flag so we don't call
|
||||
jpeg_start_output() multiple times for the same scan */
|
||||
mInfo.output_scanline = 0xffffff;
|
||||
}
|
||||
return NS_OK; /* I/O suspension */
|
||||
default:
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("got someo other state!?\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT:
|
||||
{
|
||||
if (mState == JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT)
|
||||
{
|
||||
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- entering JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT case");
|
||||
|
||||
// XXX progressive? ;)
|
||||
// not really progressive according to the state machine... -saari
|
||||
jpeg_start_output(&mInfo, mInfo.input_scan_number);
|
||||
if (OutputScanlines(-1) == PR_FALSE)
|
||||
return NS_OK; /* I/O suspension */
|
||||
jpeg_finish_output(&mInfo);
|
||||
mState = JPEG_DONE;
|
||||
}
|
||||
}
|
||||
@ -475,14 +471,14 @@ NS_IMETHODIMP nsJPEGDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PR
|
||||
|
||||
|
||||
int
|
||||
nsJPEGDecoder::OutputScanlines()
|
||||
nsJPEGDecoder::OutputScanlines(int num_scanlines)
|
||||
{
|
||||
PRUint32 top = mInfo.output_scanline;
|
||||
PRBool rv = PR_TRUE;
|
||||
|
||||
while ((mInfo.output_scanline < mInfo.output_height)) {
|
||||
while ((mInfo.output_scanline < mInfo.output_height) && num_scanlines--) {
|
||||
JSAMPROW samples;
|
||||
|
||||
|
||||
/* Request one scanline. Returns 0 or 1 scanlines. */
|
||||
int ns = jpeg_read_scanlines(&mInfo, mSamples, 1);
|
||||
|
||||
@ -571,23 +567,36 @@ nsJPEGDecoder::OutputScanlines()
|
||||
void PR_CALLBACK
|
||||
my_error_exit (j_common_ptr cinfo)
|
||||
{
|
||||
nsresult error_code;
|
||||
nsresult error_code = NS_ERROR_FAILURE;
|
||||
decoder_error_mgr *err = (decoder_error_mgr *) cinfo->err;
|
||||
|
||||
/* Convert error to a browser error code */
|
||||
switch (cinfo->err->msg_code) {
|
||||
case JERR_OUT_OF_MEMORY:
|
||||
error_code = NS_ERROR_OUT_OF_MEMORY;
|
||||
default:
|
||||
error_code = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#ifdef DEBUG
|
||||
/*ptn fix later */
|
||||
if (il_debug >= 1) {
|
||||
char buffer[JMSG_LENGTH_MAX];
|
||||
|
||||
/* Create the message */
|
||||
(*cinfo->err->format_message) (cinfo, buffer);
|
||||
|
||||
ILTRACE(1,("%s\n", buffer));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert error to a browser error code */
|
||||
if (cinfo->err->msg_code == JERR_OUT_OF_MEMORY)
|
||||
error_code = MK_OUT_OF_MEMORY;
|
||||
else
|
||||
error_code = MK_IMAGE_LOSSAGE;
|
||||
#endif
|
||||
|
||||
char buffer[JMSG_LENGTH_MAX];
|
||||
|
||||
/* Create the message */
|
||||
(*cinfo->err->format_message) (cinfo, buffer);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "JPEG decoding error:\n%s\n", buffer);
|
||||
#endif
|
||||
|
||||
|
@ -60,6 +60,7 @@ typedef enum {
|
||||
JPEG_START_DECOMPRESS,
|
||||
JPEG_DECOMPRESS_PROGRESSIVE, /* Output progressive pixels */
|
||||
JPEG_DECOMPRESS_SEQUENTIAL, /* Output sequential pixels */
|
||||
JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT,
|
||||
JPEG_DONE,
|
||||
JPEG_SINK_NON_JPEG_TRAILER, /* Some image files have a */
|
||||
/* non-JPEG trailer */
|
||||
@ -80,7 +81,7 @@ public:
|
||||
PRUint32 mBytesToSkip;
|
||||
|
||||
protected:
|
||||
int OutputScanlines();
|
||||
int OutputScanlines(int num_scanlines);
|
||||
|
||||
public:
|
||||
nsCOMPtr<imgIContainer> mImage;
|
||||
@ -111,6 +112,9 @@ public:
|
||||
PRUint32 mBackBufferLen; // Offset of end of active backtrack data
|
||||
PRUint32 mBackBufferSize; // size in bytes what mBackBuffer was created with
|
||||
PRUint32 mBackBufferUnreadLen; // amount of data currently in mBackBuffer
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // nsJPEGDecoder_h__
|
||||
|
Loading…
Reference in New Issue
Block a user