Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Enumerations | Functions | Variables
nsJPEGDecoder.cpp File Reference
#include "nsJPEGDecoder.h"
#include "imgIContainerObserver.h"
#include "nsIComponentManager.h"
#include "nsIInputStream.h"
#include "nspr.h"
#include "nsCRT.h"
#include "ImageLogging.h"
#include "jerror.h"

Go to the source code of this file.

Classes

struct  decoder_source_mgr

Defines

#define gJPEGlog
#define MAX_JPEG_MARKER_LENGTH   (((PRUint32)1 << 16) - 1)

Enumerations

enum  data_source_state { READING_BACK = 0, READING_NEW }

Functions

 METHODDEF (void) init_source(j_decompress_ptr jd)
 METHODDEF (boolean) fill_input_buffer(j_decompress_ptr jd)
 my_error_exit (j_common_ptr cinfo)
 init_source (j_decompress_ptr jd)
 skip_input_data (j_decompress_ptr jd, long num_bytes)
 fill_input_buffer (j_decompress_ptr jd)
 term_source (j_decompress_ptr jd)

Variables

long num_bytes

Class Documentation

struct decoder_source_mgr

Definition at line 81 of file nsJPEGDecoder.cpp.

Collaboration diagram for decoder_source_mgr:
Class Members
nsJPEGDecoder * decoder

Define Documentation

Definition at line 58 of file nsJPEGDecoder.cpp.

#define MAX_JPEG_MARKER_LENGTH   (((PRUint32)1 << 16) - 1)

Definition at line 69 of file nsJPEGDecoder.cpp.


Enumeration Type Documentation

Enumerator:
READING_BACK 
READING_NEW 

Definition at line 73 of file nsJPEGDecoder.cpp.

                       {
    READING_BACK = 0, /* Must be zero for init purposes */
    READING_NEW
};

Function Documentation

Definition at line 697 of file nsJPEGDecoder.cpp.

{
  decoder_source_mgr *src = (decoder_source_mgr *)jd->src;

  unsigned char *new_buffer = (unsigned char *)src->decoder->mBuffer;
  PRUint32 new_buflen = src->decoder->mBufferLen;
  PRUint32 bytesToSkip = src->decoder->mBytesToSkip;

  switch(src->decoder->mFillState) {
  case READING_BACK:
    {
      if (!new_buffer || new_buflen == 0)
        return PR_FALSE; /* suspend */

      src->decoder->mBufferLen = 0;

      if (bytesToSkip != 0) {
        if (bytesToSkip < new_buflen) {
          /* All done skipping bytes; Return what's left. */
          new_buffer += bytesToSkip;
          new_buflen -= bytesToSkip;
          src->decoder->mBytesToSkip = 0;
        } else {
          /* Still need to skip some more data in the future */
          src->decoder->mBytesToSkip -= (size_t)new_buflen;
          return PR_FALSE; /* suspend */
        }
      }

      src->decoder->mBackBufferUnreadLen = src->pub.bytes_in_buffer;

      src->pub.next_input_byte = new_buffer;
      src->pub.bytes_in_buffer = (size_t)new_buflen;
      src->decoder->mFillState = READING_NEW;

      return PR_TRUE;
    }
    break;

  case READING_NEW:
    {
      if (src->pub.next_input_byte != src->decoder->mBuffer) {
        /* Backtrack data has been permanently consumed. */
        src->decoder->mBackBufferUnreadLen = 0;
        src->decoder->mBackBufferLen = 0;
      }

      /* Save remainder of netlib buffer in backtrack buffer */
      PRUint32 new_backtrack_buflen = src->pub.bytes_in_buffer + src->decoder->mBackBufferLen;


      /* Make sure backtrack buffer is big enough to hold new data. */
      if (src->decoder->mBackBufferSize < new_backtrack_buflen) {

        /* Round up to multiple of 16 bytes. */
        PRUint32 roundup_buflen = ((new_backtrack_buflen + 15) >> 4) << 4;
        if (src->decoder->mBackBufferSize) {
            src->decoder->mBackBuffer =
          (JOCTET *)PR_REALLOC(src->decoder->mBackBuffer, roundup_buflen);
        } else {
          src->decoder->mBackBuffer = (JOCTET*)PR_MALLOC(roundup_buflen);
        }

        /* Check for OOM */
        if (!src->decoder->mBackBuffer) {
#if 0
          j_common_ptr cinfo = (j_common_ptr)(&src->js->jd);
          cinfo->err->msg_code = JERR_OUT_OF_MEMORY;
          my_error_exit(cinfo);
#endif
        }
          
        src->decoder->mBackBufferSize = (size_t)roundup_buflen;

        /* Check for malformed MARKER segment lengths. */
        if (new_backtrack_buflen > MAX_JPEG_MARKER_LENGTH) {
          my_error_exit((j_common_ptr)(&src->decoder->mInfo));
        }
      }


      /* Copy remainder of netlib buffer into backtrack buffer. */
      memmove(src->decoder->mBackBuffer + src->decoder->mBackBufferLen,
              src->pub.next_input_byte,
              src->pub.bytes_in_buffer);


      /* Point to start of data to be rescanned. */
      src->pub.next_input_byte = src->decoder->mBackBuffer + src->decoder->mBackBufferLen - src->decoder->mBackBufferUnreadLen;
      src->pub.bytes_in_buffer += src->decoder->mBackBufferUnreadLen;
      src->decoder->mBackBufferLen = (size_t)new_backtrack_buflen;
    
      src->decoder->mFillState = READING_BACK;

      return PR_FALSE;
    }
    break;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Definition at line 645 of file nsJPEGDecoder.cpp.

{
}
METHODDEF ( void  )

Definition at line 61 of file jccoefct.c.

{
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;

  /* In an interleaved scan, an MCU row is the same as an iMCU row.
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
   * But at the bottom of the image, process only what's left.
   */
  if (cinfo->comps_in_scan > 1) {
    coef->MCU_rows_per_iMCU_row = 1;
  } else {
    if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
    else
      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  }

  coef->mcu_ctr = 0;
  coef->MCU_vert_offset = 0;
}

Here is the call graph for this function:

Definition at line 576 of file nsJPEGDecoder.cpp.

{
  nsresult error_code;
  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;
  }

#ifdef DEBUG
  char buffer[JMSG_LENGTH_MAX];

  /* Create the message */
  (*cinfo->err->format_message) (cinfo, buffer);

  fprintf(stderr, "JPEG decoding error:\n%s\n", buffer);
#endif

  /* Return control to the setjmp point. */
  longjmp(err->setjmp_buffer, error_code);
}

Here is the call graph for this function:

skip_input_data ( j_decompress_ptr  jd,
long  num_bytes 
)

Definition at line 661 of file nsJPEGDecoder.cpp.

{
  decoder_source_mgr *src = (decoder_source_mgr *)jd->src;

  if (num_bytes > (long)src->pub.bytes_in_buffer) {
    /*
     * Can't skip it all right now until we get more data from
     * network stream. Set things up so that fill_input_buffer
     * will skip remaining amount.
     */
    src->decoder->mBytesToSkip = (size_t)num_bytes - src->pub.bytes_in_buffer;
    src->pub.next_input_byte += src->pub.bytes_in_buffer;
    src->pub.bytes_in_buffer = 0;

  } else {
    /* Simple case. Just advance buffer pointer */

    src->pub.bytes_in_buffer -= (size_t)num_bytes;
    src->pub.next_input_byte += num_bytes;
  }
}

Here is the call graph for this function:

Definition at line 807 of file nsJPEGDecoder.cpp.

{
  decoder_source_mgr *src = (decoder_source_mgr *)jd->src;

  if (src->decoder->mObserver) {
    src->decoder->mObserver->OnStopFrame(nsnull, src->decoder->mFrame);
    src->decoder->mObserver->OnStopContainer(nsnull, src->decoder->mImage);
    src->decoder->mObserver->OnStopDecode(nsnull, NS_OK, nsnull);
  }

  PRBool isMutable = PR_FALSE;
  if (src->decoder->mImageLoad) 
      src->decoder->mImageLoad->GetIsMultiPartChannel(&isMutable);
  src->decoder->mFrame->SetMutable(isMutable);
}

Here is the call graph for this function:


Variable Documentation

Definition at line 64 of file nsJPEGDecoder.cpp.