Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
jdatasrc.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
#include "jerror.h"

Go to the source code of this file.

Classes

struct  my_source_mgr

Defines

#define INPUT_BUF_SIZE   4096 /* choose an efficiently fread'able size */

Typedefs

typedef my_source_mgrmy_src_ptr

Functions

 init_source (j_decompress_ptr cinfo)
 fill_input_buffer (j_decompress_ptr cinfo)
 skip_input_data (j_decompress_ptr cinfo, long num_bytes)
 term_source (j_decompress_ptr cinfo)
 jpeg_stdio_src (j_decompress_ptr cinfo, FILE *infile)

Class Documentation

struct my_source_mgr

Definition at line 25 of file jdatasrc.c.

Class Members
JOCTET * buffer
FILE * infile
boolean start_of_file

Define Documentation

#define INPUT_BUF_SIZE   4096 /* choose an efficiently fread'able size */

Definition at line 35 of file jdatasrc.c.


Typedef Documentation

Definition at line 33 of file jdatasrc.c.


Function Documentation

Definition at line 90 of file jdatasrc.c.

{
  my_src_ptr src = (my_src_ptr) cinfo->src;
  size_t nbytes;

  nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);

  if (nbytes <= 0) {
    if (src->start_of_file) /* Treat empty input file as fatal error */
      ERREXIT(cinfo, JERR_INPUT_EMPTY);
    WARNMS(cinfo, JWRN_JPEG_EOF);
    /* Insert a fake EOI marker */
    src->buffer[0] = (JOCTET) 0xFF;
    src->buffer[1] = (JOCTET) JPEG_EOI;
    nbytes = 2;
  }

  src->pub.next_input_byte = src->buffer;
  src->pub.bytes_in_buffer = nbytes;
  src->start_of_file = FALSE;

  return TRUE;
}

Here is the caller graph for this function:

Definition at line 44 of file jdatasrc.c.

{
  my_src_ptr src = (my_src_ptr) cinfo->src;

  /* We reset the empty-input-file flag for each image,
   * but we don't clear the input buffer.
   * This is correct behavior for reading a series of images from one source.
   */
  src->start_of_file = TRUE;
}

Here is the caller graph for this function:

jpeg_stdio_src ( j_decompress_ptr  cinfo,
FILE infile 
)

Definition at line 182 of file jdatasrc.c.

{
  my_src_ptr src;

  /* The source object and input buffer are made permanent so that a series
   * of JPEG images can be read from the same file by calling jpeg_stdio_src
   * only before the first one.  (If we discarded the buffer at the end of
   * one image, we'd likely lose the start of the next one.)
   * This makes it unsafe to use this manager and a different source
   * manager serially with the same JPEG object.  Caveat programmer.
   */
  if (cinfo->src == NULL) { /* first time for this JPEG object? */
    cinfo->src = (struct jpeg_source_mgr *)
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
                              SIZEOF(my_source_mgr));
    src = (my_src_ptr) cinfo->src;
    src->buffer = (JOCTET *)
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
                              INPUT_BUF_SIZE * SIZEOF(JOCTET));
  }

  src = (my_src_ptr) cinfo->src;
  src->pub.init_source = init_source;
  src->pub.fill_input_buffer = fill_input_buffer;
  src->pub.skip_input_data = skip_input_data;
  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  src->pub.term_source = term_source;
  src->infile = infile;
  src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  src->pub.next_input_byte = NULL; /* until buffer loaded */
}

Here is the call graph for this function:

Here is the caller graph for this function:

skip_input_data ( j_decompress_ptr  cinfo,
long  num_bytes 
)

Definition at line 128 of file jdatasrc.c.

{
  my_src_ptr src = (my_src_ptr) cinfo->src;

  /* Just a dumb implementation for now.  Could use fseek() except
   * it doesn't work on pipes.  Not clear that being smart is worth
   * any trouble anyway --- large skips are infrequent.
   */
  if (num_bytes > 0) {
    while (num_bytes > (long) src->pub.bytes_in_buffer) {
      num_bytes -= (long) src->pub.bytes_in_buffer;
      (void) fill_input_buffer(cinfo);
      /* note we assume that fill_input_buffer will never return FALSE,
       * so suspension need not be handled.
       */
    }
    src->pub.next_input_byte += (size_t) num_bytes;
    src->pub.bytes_in_buffer -= (size_t) num_bytes;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 169 of file jdatasrc.c.

{
  /* no work necessary here */
}

Here is the caller graph for this function: