Back to index

texmacs  1.0.7.15
Classes | Defines | Enumerations | Functions
jpegimage.c File Reference
#include "system.h"
#include "error.h"
#include "mem.h"
#include "mfileio.h"
#include "numbers.h"
#include "dvipdfmx.h"
#include "pdfobj.h"
#include "jpegimage.h"
#include "pdfcolor.h"
#include "pdfximage.h"

Go to the source code of this file.

Classes

struct  JPEG_APPn_JFIF
struct  JPEG_APPn_ICC
struct  JPEG_APPn_Adobe
struct  JPEG_ext
struct  JPEG_info

Defines

#define JPEG_DEBUG_STR   "JPEG"
#define JPEG_DEBUG   3
#define MAX_COUNT   1024
#define HAVE_APPn_JFIF   (1 << 0)
#define HAVE_APPn_ADOBE   (1 << 1)
#define HAVE_APPn_ICC   (1 << 2)
#define IS_ADOBE_CMYK(j)   (((j).flags & HAVE_APPn_ADOBE) && (j).num_components == 4)
#define IS_JFIF(j)   ((j)->flags & HAVE_APPn_JFIF)

Enumerations

enum  JPEG_marker {
  JM_SOF0 = 0xc0, JM_SOF1 = 0xc1, JM_SOF2 = 0xc2, JM_SOF3 = 0xc3,
  JM_SOF5 = 0xc5, JM_DHT = 0xc4, JM_SOF6 = 0xc6, JM_SOF7 = 0xc7,
  JM_SOF9 = 0xc9, JM_SOF10 = 0xca, JM_SOF11 = 0xcb, JM_DAC = 0xcc,
  JM_SOF13 = 0xcd, JM_SOF14 = 0xce, JM_SOF15 = 0xcf, JM_RST0 = 0xd0,
  JM_RST1 = 0xd1, JM_RST2 = 0xd2, JM_RST3 = 0xd3, JM_RST4 = 0xd4,
  JM_RST5 = 0xd5, JM_RST6 = 0xd6, JM_RST7 = 0xd7, JM_SOI = 0xd8,
  JM_EOI = 0xd9, JM_SOS = 0xda, JM_DQT = 0xdb, JM_DNL = 0xdc,
  JM_DRI = 0xdd, JM_DHP = 0xde, JM_EXP = 0xdf, JM_APP0 = 0xe0,
  JM_APP2 = 0xe2, JM_APP14 = 0xee, JM_APP15 = 0xef, JM_COM = 0xfe
}
enum  JPEG_APPn_sig { JS_APPn_JFIF, JS_APPn_ADOBE, JS_APPn_ICC }

Functions

static int JPEG_scan_file (struct JPEG_info *j_info, FILE *fp)
static int JPEG_copy_stream (struct JPEG_info *j_info, pdf_obj *stream, FILE *fp, int flags)
static void JPEG_info_init (struct JPEG_info *j_info)
static void JPEG_info_clear (struct JPEG_info *j_info)
static pdf_objJPEG_get_iccp (struct JPEG_info *j_info)
static void jpeg_get_density (struct JPEG_info *j_info, double *xdensity, double *ydensity)
int check_for_jpeg (FILE *fp)
int jpeg_include_image (pdf_ximage *ximage, FILE *fp)
static void JPEG_release_APPn_data (JPEG_marker marker, JPEG_APPn_sig app_sig, void *app_data)
static JPEG_marker JPEG_get_marker (FILE *fp)
static int add_APPn_marker (struct JPEG_info *j_info, JPEG_marker marker, int app_sig, void *app_data)
static unsigned short read_APP14_Adobe (struct JPEG_info *j_info, FILE *fp, unsigned short length)
static unsigned short read_APP0_JFIF (struct JPEG_info *j_info, FILE *fp, unsigned short length)
static unsigned short read_APP0_JFXX (struct JPEG_info *j_info, FILE *fp, unsigned short length)
static unsigned short read_APP2_ICC (struct JPEG_info *j_info, FILE *fp, unsigned short length)
int jpeg_get_bbox (FILE *fp, long *width, long *height, double *xdensity, double *ydensity)

Class Documentation

struct JPEG_APPn_JFIF

Definition at line 131 of file jpegimage.c.

Class Members
unsigned char * thumbnail
unsigned char units
unsigned short version
unsigned short Xdensity
unsigned char Xthumbnail
unsigned short Ydensity
unsigned char Ythumbnail
struct JPEG_APPn_ICC

Definition at line 145 of file jpegimage.c.

Class Members
unsigned char * chunk
unsigned short length
unsigned char num_chunks
unsigned char seq_id
struct JPEG_APPn_Adobe

Definition at line 155 of file jpegimage.c.

Class Members
unsigned short flag0
unsigned short flag1
unsigned char transform
unsigned short version
struct JPEG_ext

Definition at line 163 of file jpegimage.c.

Class Members
void * app_data
JPEG_APPn_sig app_sig
JPEG_marker marker
struct JPEG_info

Definition at line 171 of file jpegimage.c.

Collaboration diagram for JPEG_info:
Class Members
struct JPEG_ext * appn
unsigned char bits_per_component
int flags
unsigned short height
int max_appn
int num_appn
unsigned char num_components
char skipbits
unsigned short width

Define Documentation

#define HAVE_APPn_ADOBE   (1 << 1)

Definition at line 189 of file jpegimage.c.

#define HAVE_APPn_ICC   (1 << 2)

Definition at line 190 of file jpegimage.c.

#define HAVE_APPn_JFIF   (1 << 0)

Definition at line 188 of file jpegimage.c.

#define IS_ADOBE_CMYK (   j)    (((j).flags & HAVE_APPn_ADOBE) && (j).num_components == 4)
#define IS_JFIF (   j)    ((j)->flags & HAVE_APPn_JFIF)

Definition at line 346 of file jpegimage.c.

#define JPEG_DEBUG   3

Definition at line 75 of file jpegimage.c.

#define JPEG_DEBUG_STR   "JPEG"

Definition at line 74 of file jpegimage.c.

#define MAX_COUNT   1024

Definition at line 170 of file jpegimage.c.


Enumeration Type Documentation

Enumerator:
JS_APPn_JFIF 
JS_APPn_ADOBE 
JS_APPn_ICC 

Definition at line 125 of file jpegimage.c.

Enumerator:
JM_SOF0 
JM_SOF1 
JM_SOF2 
JM_SOF3 
JM_SOF5 
JM_DHT 
JM_SOF6 
JM_SOF7 
JM_SOF9 
JM_SOF10 
JM_SOF11 
JM_DAC 
JM_SOF13 
JM_SOF14 
JM_SOF15 
JM_RST0 
JM_RST1 
JM_RST2 
JM_RST3 
JM_RST4 
JM_RST5 
JM_RST6 
JM_RST7 
JM_SOI 
JM_EOI 
JM_SOS 
JM_DQT 
JM_DNL 
JM_DRI 
JM_DHP 
JM_EXP 
JM_APP0 
JM_APP2 
JM_APP14 
JM_APP15 
JM_COM 

Definition at line 82 of file jpegimage.c.

             {
  JM_SOF0  = 0xc0,
  JM_SOF1  = 0xc1,
  JM_SOF2  = 0xc2,
  JM_SOF3  = 0xc3,
  JM_SOF5  = 0xc5,
  JM_DHT   = 0xc4,
  JM_SOF6  = 0xc6,
  JM_SOF7  = 0xc7,
  JM_SOF9  = 0xc9,
  JM_SOF10 = 0xca,
  JM_SOF11 = 0xcb,
  JM_DAC   = 0xcc,
  JM_SOF13 = 0xcd,
  JM_SOF14 = 0xce,
  JM_SOF15 = 0xcf,

  JM_RST0  = 0xd0,
  JM_RST1  = 0xd1,
  JM_RST2  = 0xd2,
  JM_RST3  = 0xd3,
  JM_RST4  = 0xd4,
  JM_RST5  = 0xd5,
  JM_RST6  = 0xd6,
  JM_RST7  = 0xd7,

  JM_SOI   = 0xd8,
  JM_EOI   = 0xd9,
  JM_SOS   = 0xda,
  JM_DQT   = 0xdb,
  JM_DNL   = 0xdc,
  JM_DRI   = 0xdd,
  JM_DHP   = 0xde,
  JM_EXP   = 0xdf,

  JM_APP0  = 0xe0,
  JM_APP2  = 0xe2,
  JM_APP14 = 0xee,
  JM_APP15 = 0xef,

  JM_COM   = 0xfe
} JPEG_marker;

Function Documentation

static int add_APPn_marker ( struct JPEG_info j_info,
JPEG_marker  marker,
int  app_sig,
void *  app_data 
) [static]

Definition at line 507 of file jpegimage.c.

{
  int n;

  if (j_info->num_appn >= j_info->max_appn) {
    j_info->max_appn += 16;
    j_info->appn = RENEW(j_info->appn, j_info->max_appn, struct JPEG_ext);
  }
  n = j_info->num_appn;

  j_info->appn[n].marker   = marker;
  j_info->appn[n].app_sig  = app_sig;
  j_info->appn[n].app_data = app_data;

  j_info->num_appn += 1;

  return n;
}

Here is the caller graph for this function:

int check_for_jpeg ( FILE *  fp)

Definition at line 203 of file jpegimage.c.

{
  unsigned char jpeg_sig[2];

  rewind(fp);
  if (fread(jpeg_sig, sizeof(unsigned char), 2, fp) != 2)
    return 0;
  else if (jpeg_sig[0] != 0xff || jpeg_sig[1] != JM_SOI)
    return 0;

  return 1;
}

Here is the caller graph for this function:

static int JPEG_copy_stream ( struct JPEG_info j_info,
pdf_obj stream,
FILE *  fp,
int  flags 
) [static]

Definition at line 606 of file jpegimage.c.

{
  JPEG_marker marker;
  long length, nb_read;
  int  found_SOFn, count;

  rewind(fp);
  count      = 0;
  found_SOFn = 0;
  while (!found_SOFn &&
        count < MAX_COUNT &&
        (marker = JPEG_get_marker(fp)) >= 0) {
    if (marker == JM_SOI  ||
       (marker >= JM_RST0 && marker <= JM_RST7)) {
      work_buffer[0] = (char) 0xff;
      work_buffer[1] = (char) marker;
      pdf_add_stream(stream, work_buffer, 2);
      count++;
      continue;
    }
    length = get_unsigned_pair(fp) - 2;
    switch (marker) {
    case JM_SOF0:  case JM_SOF1:  case JM_SOF2:  case JM_SOF3:
    case JM_SOF5:  case JM_SOF6:  case JM_SOF7:  case JM_SOF9:
    case JM_SOF10: case JM_SOF11: case JM_SOF13: case JM_SOF14:
    case JM_SOF15:
      work_buffer[0] = (char) 0xff;
      work_buffer[1] = (char) marker;
      work_buffer[2] = ((length + 2) >> 8) & 0xff;
      work_buffer[3] =  (length + 2) & 0xff;
      pdf_add_stream(stream, work_buffer, 4);
      while (length > 0) {
       nb_read = fread(work_buffer, sizeof(char),
                     MIN(length, WORK_BUFFER_SIZE), fp);
       if (nb_read > 0)
         pdf_add_stream(stream, work_buffer, nb_read);
       length -= nb_read;
      }
      found_SOFn = 1;
      break;
    default:
      if (j_info->skipbits[count / 8] & (1 << (7 - (count % 8)))) {
       /* skip */
       while (length > 0) {
         nb_read = fread(work_buffer, sizeof(char),
                       MIN(length, WORK_BUFFER_SIZE), fp);
         length -= nb_read;
       }
      } else {
       work_buffer[0] = (char) 0xff;
       work_buffer[1] = (char) marker;
       work_buffer[2] = ((length + 2) >> 8) & 0xff;
       work_buffer[3] =  (length + 2) & 0xff;
       pdf_add_stream(stream, work_buffer, 4);
       while (length > 0) {
         nb_read = fread(work_buffer, sizeof(char),
                       MIN(length, WORK_BUFFER_SIZE), fp);
         if (nb_read > 0)
           pdf_add_stream(stream, work_buffer, nb_read);
         length -= nb_read;
       }
      }
    }
    count++;
  }

  while ((length = fread(work_buffer,
                      sizeof(char), WORK_BUFFER_SIZE, fp)) > 0) {
    pdf_add_stream(stream, work_buffer, length);
  }

  return (found_SOFn ? 0 : -1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int jpeg_get_bbox ( FILE *  fp,
long *  width,
long *  height,
double *  xdensity,
double *  ydensity 
)

Definition at line 773 of file jpegimage.c.

{
  struct JPEG_info j_info;

  JPEG_info_init(&j_info);

  if (JPEG_scan_file(&j_info, fp) < 0) {
    WARN("%s: Not a JPEG file?", JPEG_DEBUG_STR);
    JPEG_info_clear(&j_info);
    return -1;
  }

  *width  = j_info.width;
  *height = j_info.height;

  jpeg_get_density(&j_info, xdensity, ydensity);

  JPEG_info_clear(&j_info);

  return 0;
}

Here is the call graph for this function:

static void jpeg_get_density ( struct JPEG_info j_info,
double *  xdensity,
double *  ydensity 
) [static]

Definition at line 349 of file jpegimage.c.

{
  if (compat_mode) {
    *xdensity = *ydensity = 72.0 / 100.0;
    return;
  }

  *xdensity = *ydensity = 1.0;

  if (IS_JFIF(j_info)) {
    struct JPEG_APPn_JFIF *app_data;
    int i;
    for (i = 0; i < j_info->num_appn; i++) {
      if (j_info->appn[i].marker  == JM_APP0 ||
         j_info->appn[i].app_sig == JS_APPn_JFIF)
        break;
    }
    if (i < j_info->num_appn) {
      app_data = (struct JPEG_APPn_JFIF *)j_info->appn[i].app_data;
      switch (app_data->units) {
      case 1: /* pixels per inch */
        *xdensity = 72.0 / app_data->Xdensity;
        *ydensity = 72.0 / app_data->Ydensity;
        break;
      case 2: /* pixels per centimeter */
        *xdensity = 72.0 / 2.54 / app_data->Xdensity;
        *ydensity = 72.0 / 2.54 / app_data->Ydensity;
        break;
      default:
        break;
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static pdf_obj * JPEG_get_iccp ( struct JPEG_info j_info) [static]

Definition at line 453 of file jpegimage.c.

{
  pdf_obj *icc_stream;
  struct JPEG_APPn_ICC *icc;
  int i, prev_id = 0, num_icc_seg = -1;

  icc_stream = pdf_new_stream(STREAM_COMPRESS);
  for (i = 0; i < j_info->num_appn; i++) {
    if (j_info->appn[i].marker  != JM_APP2 ||
       j_info->appn[i].app_sig != JS_APPn_ICC)
      continue;
    icc = (struct JPEG_APPn_ICC *) j_info->appn[i].app_data;
    if (num_icc_seg < 0 && prev_id == 0) {
      num_icc_seg = icc->num_chunks;
      /* ICC chunks are sorted? */
    } else if (icc->seq_id != prev_id + 1 ||
              num_icc_seg != icc->num_chunks ||
              icc->seq_id  > icc->num_chunks) {
      WARN("Invalid JPEG ICC chunk: %d (p:%d, n:%d)",
          icc->seq_id, prev_id, icc->num_chunks);
      pdf_release_obj(icc_stream);
      icc_stream = NULL;
      break;
    }
    pdf_add_stream(icc_stream, icc->chunk, icc->length);
    prev_id = icc->seq_id;
    num_icc_seg = icc->num_chunks;
  }

  return icc_stream;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JPEG_marker JPEG_get_marker ( FILE *  fp) [static]

Definition at line 486 of file jpegimage.c.

{
  int c;

  c = fgetc(fp);
  if (c != 255)
    return -1;

  for (;;) {
    c = fgetc(fp);
    if (c < 0)
      return -1;
    else if (c > 0 && c < 255) {
      return c;
    }
  }

  return -1;
}

Here is the caller graph for this function:

int jpeg_include_image ( pdf_ximage *  ximage,
FILE *  fp 
)

Definition at line 217 of file jpegimage.c.

{
  pdf_obj    *stream;
  pdf_obj    *stream_dict;
  pdf_obj    *colorspace;
  int         colortype;
  ximage_info info;
  struct JPEG_info j_info;

  if (!check_for_jpeg(fp)) {
    WARN("%s: Not a JPEG file?", JPEG_DEBUG_STR);
    rewind(fp);
    return -1;
  }
  /* File position is 2 here... */

  pdf_ximage_init_image_info(&info);

  JPEG_info_init(&j_info);

  if (JPEG_scan_file(&j_info, fp) < 0) {
    WARN("%s: Not a JPEG file?", JPEG_DEBUG_STR);
    JPEG_info_clear(&j_info);
    return -1;
  }

  switch (j_info.num_components) {
  case 1:
    colortype = PDF_COLORSPACE_TYPE_GRAY;
    break;
  case 3:
    colortype = PDF_COLORSPACE_TYPE_RGB;
    break;
  case 4:
    colortype = PDF_COLORSPACE_TYPE_CMYK;
    break;
  default:
    WARN("%s: Unknown color space (num components: %d)",
        JPEG_DEBUG_STR, info.num_components);
    JPEG_info_clear(&j_info);
    return -1;
  }

  /* JPEG image use DCTDecode. */
  stream      = pdf_new_stream (0);
  stream_dict = pdf_stream_dict(stream);
  pdf_add_dict(stream_dict,
              pdf_new_name("Filter"), pdf_new_name("DCTDecode"));

  colorspace  = NULL;
  if (j_info.flags & HAVE_APPn_ICC) {
    pdf_obj *icc_stream, *intent;

    icc_stream = JPEG_get_iccp(&j_info);

    if (!icc_stream)
      colorspace = NULL;
    else {
      int   cspc_id;

      if (iccp_check_colorspace(colortype,
                            pdf_stream_dataptr(icc_stream),
                            pdf_stream_length (icc_stream)) < 0)
       colorspace = NULL;
      else {
       cspc_id = iccp_load_profile(NULL, /* noname */
                                pdf_stream_dataptr(icc_stream),
                                pdf_stream_length (icc_stream));
       if (cspc_id < 0)
         colorspace = NULL;
       else {
         colorspace = pdf_get_colorspace_reference(cspc_id);
         intent     = iccp_get_rendering_intent(pdf_stream_dataptr(icc_stream),
                                           pdf_stream_length (icc_stream));
         if (intent)
           pdf_add_dict(stream_dict, pdf_new_name("Intent"), intent);
       }
      }
      pdf_release_obj(icc_stream);
    }
  }

  /* No ICC or invalid ICC profile. */
  if (!colorspace) {
    switch (colortype) {
    case PDF_COLORSPACE_TYPE_GRAY:
      colorspace = pdf_new_name("DeviceGray");
      break;
    case PDF_COLORSPACE_TYPE_RGB:
      colorspace = pdf_new_name("DeviceRGB");
      break;
    case PDF_COLORSPACE_TYPE_CMYK:
      colorspace = pdf_new_name("DeviceCMYK");
      break;
    }
  }
  pdf_add_dict(stream_dict, pdf_new_name("ColorSpace"), colorspace);

#define IS_ADOBE_CMYK(j) (((j).flags & HAVE_APPn_ADOBE) && (j).num_components == 4)

  if (IS_ADOBE_CMYK(j_info)) {
    pdf_obj *decode;
    int      i;

    WARN("Adobe CMYK JPEG: Inverted color assumed.");
    decode = pdf_new_array();
    for (i = 0; i < j_info.num_components; i++) {
      pdf_add_array(decode, pdf_new_number(1.0));
      pdf_add_array(decode, pdf_new_number(0.0));
    }
    pdf_add_dict(stream_dict, pdf_new_name("Decode"), decode);
  }

  /* Copy file */
  JPEG_copy_stream(&j_info, stream, fp, 0);

  info.width              = j_info.width;
  info.height             = j_info.height;
  info.bits_per_component = j_info.bits_per_component;
  info.num_components     = j_info.num_components;

  jpeg_get_density(&j_info, &info.xdensity, &info.ydensity);

  pdf_ximage_set_image(ximage, &info, stream);
  JPEG_info_clear(&j_info);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void JPEG_info_clear ( struct JPEG_info j_info) [static]

Definition at line 435 of file jpegimage.c.

{
  if (j_info->num_appn > 0 &&
      j_info->appn    != NULL) {
    int i;

    for (i = 0; i < j_info->num_appn; i++)
      JPEG_release_APPn_data(j_info->appn[i].marker,
                          j_info->appn[i].app_sig, j_info->appn[i].app_data);
    RELEASE(j_info->appn);
  }
  j_info->appn     = NULL;
  j_info->num_appn = 0;
  j_info->max_appn = 0;
  j_info->flags    = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void JPEG_info_init ( struct JPEG_info j_info) [static]

Definition at line 386 of file jpegimage.c.

{
  j_info->width  = 0;
  j_info->height = 0;
  j_info->bits_per_component = 0;
  j_info->num_components = 0;

  j_info->flags    = 0;
  j_info->num_appn = 0;
  j_info->max_appn = 0;
  j_info->appn     = NULL;

  memset(j_info->skipbits, 0, MAX_COUNT / 8 + 1);
}

Here is the caller graph for this function:

static void JPEG_release_APPn_data ( JPEG_marker  marker,
JPEG_APPn_sig  app_sig,
void *  app_data 
) [static]

Definition at line 402 of file jpegimage.c.

{
  if (marker  == JM_APP0 &&
      app_sig == JS_APPn_JFIF) {
    struct JPEG_APPn_JFIF *data;

    data = (struct JPEG_APPn_JFIF *) app_data;
    if (data->thumbnail)
      RELEASE(data->thumbnail);
    data->thumbnail = NULL;

    RELEASE(data);
  } else if (marker  == JM_APP2 &&
            app_sig == JS_APPn_ICC) {
    struct JPEG_APPn_ICC *data;

    data = (struct JPEG_APPn_ICC *) app_data;
    if (data->chunk)
      RELEASE(data->chunk);
    data->chunk = NULL;

    RELEASE(data);
  } else if (marker  == JM_APP14 &&
            app_sig == JS_APPn_ADOBE) {
    struct JPEG_APPn_Adobe *data;

    data = (struct JPEG_APPn_Adobe *) app_data;

    RELEASE(data);
  }
}

Here is the caller graph for this function:

static int JPEG_scan_file ( struct JPEG_info j_info,
FILE *  fp 
) [static]

Definition at line 682 of file jpegimage.c.

{
  JPEG_marker marker;
  unsigned short length;
  int  found_SOFn, count;
  char app_sig[128];

  rewind(fp);
  count      = 0;
  found_SOFn = 0;
  while (!found_SOFn &&
        (marker = JPEG_get_marker(fp)) >= 0) {
    if (marker == JM_SOI  ||
       (marker >= JM_RST0 && marker <= JM_RST7)) {
      count++;
      continue;
    }
    length = get_unsigned_pair(fp) - 2;
    switch (marker) {
    case JM_SOF0:  case JM_SOF1:  case JM_SOF2:  case JM_SOF3:
    case JM_SOF5:  case JM_SOF6:  case JM_SOF7:  case JM_SOF9:
    case JM_SOF10: case JM_SOF11: case JM_SOF13: case JM_SOF14:
    case JM_SOF15:
      j_info->bits_per_component = get_unsigned_byte(fp);
      j_info->height = get_unsigned_pair(fp);
      j_info->width  = get_unsigned_pair(fp);
      j_info->num_components = get_unsigned_byte(fp);
      found_SOFn = 1;
      break;
    case JM_APP0:
      if (length > 5) {
       if (fread(app_sig, sizeof(char), 5, fp) != 5)
         return -1;
       length -= 5;
       if (!memcmp(app_sig, "JFIF\000", 5)) {
         j_info->flags |= HAVE_APPn_JFIF;
         length -= read_APP0_JFIF(j_info, fp, length);
       } else if (!memcmp(app_sig, "JFXX", 5)) {
         length -= read_APP0_JFXX(j_info, fp, length);
       }
      }
      seek_relative(fp, length);
      break;
    case JM_APP2:
      if (length >= 14) {
       if (fread(app_sig, sizeof(char), 12, fp) != 12)
         return -1;
       length -= 12;
       if (!memcmp(app_sig, "ICC_PROFILE\000", 12)) {
         j_info->flags |= HAVE_APPn_ICC;
         length -= read_APP2_ICC(j_info, fp, length);
         if (count < MAX_COUNT) {
           j_info->skipbits[count / 8] |= (1 << (7 - (count % 8)));
         }
       }
      }
      seek_relative(fp, length);
      break;
    case JM_APP14:
      if (length > 5) {
       if (fread(app_sig, sizeof(char), 5, fp) != 5)
         return -1;
       length -= 5;
       if (!memcmp(app_sig, "Adobe", 5)) {
         j_info->flags |= HAVE_APPn_ADOBE;
         length -= read_APP14_Adobe(j_info, fp, length);
       } else {
         if (count < MAX_COUNT) {
           j_info->skipbits[count/8] |= (1 << (7 - (count % 8)));
         }
       }
      }
      seek_relative(fp, length);
      break;
    default:
      seek_relative(fp, length);
      if (marker >= JM_APP0 &&
         marker <= JM_APP15) {
       if (count < MAX_COUNT) {
         j_info->skipbits[count / 8] |= (1 << (7 - (count % 8)));
       }
      }
      break;
    }
    count++;
  }

  return (found_SOFn ? 0 : -1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned short read_APP0_JFIF ( struct JPEG_info j_info,
FILE *  fp,
unsigned short  length 
) [static]

Definition at line 544 of file jpegimage.c.

{
  struct JPEG_APPn_JFIF *app_data;
  unsigned short thumb_data_len;

  app_data = NEW(1, struct JPEG_APPn_JFIF);
  app_data->version  = get_unsigned_pair(fp);
  app_data->units    = get_unsigned_byte(fp);
  app_data->Xdensity = get_unsigned_pair(fp);
  app_data->Ydensity = get_unsigned_pair(fp);
  app_data->Xthumbnail = get_unsigned_byte(fp);
  app_data->Ythumbnail = get_unsigned_byte(fp);
  thumb_data_len = 3 * app_data->Xthumbnail * app_data->Ythumbnail;
  if (thumb_data_len > 0) {
    app_data->thumbnail = NEW(thumb_data_len, unsigned char);
    fread(app_data->thumbnail, 1, thumb_data_len, fp);
  } else {
    app_data->thumbnail = NULL;
  }

  add_APPn_marker(j_info, JM_APP0, JS_APPn_JFIF, app_data);

  return (9 + thumb_data_len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned short read_APP0_JFXX ( struct JPEG_info j_info,
FILE *  fp,
unsigned short  length 
) [static]

Definition at line 570 of file jpegimage.c.

{
  unsigned char extension_code;

  extension_code = get_unsigned_byte(fp);
  /* Extension Code:
   *
   * 0x10: Thumbnail coded using JPEG
   * 0x11: Thumbnail stored using 1 byte/pixel
   * 0x13: Thumbnail stored using 3 bytes/pixel
   */
  seek_relative(fp, length-1); /* Thunbnail image */

  /* Ignore */

  return length;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned short read_APP14_Adobe ( struct JPEG_info j_info,
FILE *  fp,
unsigned short  length 
) [static]

Definition at line 528 of file jpegimage.c.

{
  struct JPEG_APPn_Adobe *app_data;

  app_data = NEW(1, struct JPEG_APPn_Adobe);
  app_data->version   = get_unsigned_pair(fp);
  app_data->flag0     = get_unsigned_pair(fp);
  app_data->flag1     = get_unsigned_pair(fp);
  app_data->transform = get_unsigned_byte(fp);

  add_APPn_marker(j_info, JM_APP14, JS_APPn_ADOBE, app_data);

  return 7;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned short read_APP2_ICC ( struct JPEG_info j_info,
FILE *  fp,
unsigned short  length 
) [static]

Definition at line 589 of file jpegimage.c.

{
  struct JPEG_APPn_ICC *app_data;

  app_data = NEW(1, struct JPEG_APPn_ICC);
  app_data->seq_id      = get_unsigned_byte(fp); /* Starting at 1 */
  app_data->num_chunks  = get_unsigned_byte(fp);
  app_data->length = length - 2;
  app_data->chunk  = NEW(app_data->length, unsigned char);
  fread(app_data->chunk, 1, app_data->length, fp);

  add_APPn_marker(j_info, JM_APP2, JS_APPn_ICC, app_data);

  return length;
}

Here is the call graph for this function:

Here is the caller graph for this function: