Back to index

texmacs  1.0.7.15
Functions
jpegimage.h File Reference
#include "mfileio.h"
#include "pdfximage.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int check_for_jpeg (FILE *fp)
int jpeg_include_image (pdf_ximage *ximage, FILE *fp)
int jpeg_get_bbox (FILE *fp, long *width, long *height, double *xdensity, double *ydensity)

Function Documentation

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:

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:

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: