Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
image.h File Reference
#include <png.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  JPG_IMAGE_INFO
struct  png_image_struct
struct  pdf_image_struct
struct  image_entry
union  image_entry.image_struct

Defines

#define JPG_UINT16   unsigned int
#define JPG_UINT32   unsigned long
#define JPG_UINT8   unsigned char
#define IMAGE_TYPE_NONE   0
#define IMAGE_TYPE_PDF   1
#define IMAGE_TYPE_PNG   2
#define IMAGE_TYPE_JPG   3
#define IMAGE_TYPE_TIF   4
#define IMAGE_COLOR_B   1
#define IMAGE_COLOR_C   2
#define IMAGE_COLOR_I   4
#define img_ptr(N)   (image_array + (N))
#define img_name(N)   (img_ptr(N)->image_name)
#define img_type(N)   (img_ptr(N)->image_type)
#define img_color(N)   (img_ptr(N)->color_type)
#define img_colorspace_ref(N)   (img_ptr(N)->colorspace_ref)
#define img_pages(N)   (img_ptr(N)->num_pages)
#define img_width(N)   (img_ptr(N)->width)
#define img_height(N)   (img_ptr(N)->height)
#define img_xres(N)   (img_ptr(N)->x_res)
#define img_yres(N)   (img_ptr(N)->y_res)
#define png_ptr(N)   (img_ptr(N)->image_struct.png.png_ptr)
#define png_info(N)   (img_ptr(N)->image_struct.png.info_ptr)
#define pdf_ptr(N)   (img_ptr(N)->image_struct.pdf)
#define jpg_ptr(N)   (img_ptr(N)->image_struct.jpg)
#define tif_ptr(N)   (img_ptr(N)->image_struct.tif)

Functions

integer read_pdf_info (char *, char *, integer, integer, integer, integer)
void write_epdf (void)
void epdf_delete (void)
void read_png_info (integer)
void write_png (integer)
void read_jpg_info (integer)
void write_jpg (integer)

Variables

image_entryimage_ptr
image_entryimage_array
integer image_max

Class Documentation

struct JPG_IMAGE_INFO

Definition at line 31 of file image.h.

Class Members
JPG_UINT8 bits_per_component
int color_space
FILE * file
JPG_UINT32 length
struct png_image_struct

Definition at line 38 of file image.h.

Collaboration diagram for png_image_struct:
Class Members
png_infop info_ptr
png_structp png_ptr
struct pdf_image_struct

Definition at line 43 of file image.h.

Class Members
integer always_use_pdfpagebox
void * doc
integer orig_x
integer orig_y
integer page_box
integer selected_page
struct image_entry

Definition at line 52 of file image.h.

Class Members
int color_type
integer colorspace_ref
integer height
char * image_name
union image_entry image_struct
int image_type
integer num_pages
integer width
integer x_res
integer y_res
union image_entry.image_struct

Definition at line 62 of file image.h.

Class Members
JPG_IMAGE_INFO * jpg
pdf_image_struct * pdf
png_image_struct png

Define Documentation

#define IMAGE_COLOR_B   1

Definition at line 78 of file image.h.

#define IMAGE_COLOR_C   2

Definition at line 79 of file image.h.

#define IMAGE_COLOR_I   4

Definition at line 80 of file image.h.

#define IMAGE_TYPE_JPG   3

Definition at line 75 of file image.h.

#define IMAGE_TYPE_NONE   0

Definition at line 72 of file image.h.

#define IMAGE_TYPE_PDF   1

Definition at line 73 of file image.h.

#define IMAGE_TYPE_PNG   2

Definition at line 74 of file image.h.

#define IMAGE_TYPE_TIF   4

Definition at line 76 of file image.h.

#define img_color (   N)    (img_ptr(N)->color_type)

Definition at line 85 of file image.h.

#define img_colorspace_ref (   N)    (img_ptr(N)->colorspace_ref)

Definition at line 86 of file image.h.

#define img_height (   N)    (img_ptr(N)->height)

Definition at line 89 of file image.h.

#define img_name (   N)    (img_ptr(N)->image_name)

Definition at line 83 of file image.h.

#define img_pages (   N)    (img_ptr(N)->num_pages)

Definition at line 87 of file image.h.

#define img_ptr (   N)    (image_array + (N))

Definition at line 82 of file image.h.

#define img_type (   N)    (img_ptr(N)->image_type)

Definition at line 84 of file image.h.

#define img_width (   N)    (img_ptr(N)->width)

Definition at line 88 of file image.h.

#define img_xres (   N)    (img_ptr(N)->x_res)

Definition at line 90 of file image.h.

#define img_yres (   N)    (img_ptr(N)->y_res)

Definition at line 91 of file image.h.

#define jpg_ptr (   N)    (img_ptr(N)->image_struct.jpg)

Definition at line 95 of file image.h.

#define JPG_UINT16   unsigned int

Definition at line 27 of file image.h.

#define JPG_UINT32   unsigned long

Definition at line 28 of file image.h.

#define JPG_UINT8   unsigned char

Definition at line 29 of file image.h.

#define pdf_ptr (   N)    (img_ptr(N)->image_struct.pdf)

Definition at line 94 of file image.h.

#define png_info (   N)    (img_ptr(N)->image_struct.png.info_ptr)

Definition at line 93 of file image.h.

#define png_ptr (   N)    (img_ptr(N)->image_struct.png.png_ptr)

Definition at line 92 of file image.h.

#define tif_ptr (   N)    (img_ptr(N)->image_struct.tif)

Definition at line 96 of file image.h.


Function Documentation

Definition at line 1047 of file pdftoepdf.cc.

{
    PdfDocument *pdf_doc = (PdfDocument *) epdf_doc;
    xref = pdf_doc->xref;
    if (pdf_doc->occurences < 0) {
#ifdef DEBUG
        fprintf(stderr, "\nDeleting %s\n", pdf_doc->file_name);
#endif
        delete_document(pdf_doc);
    }
}

Here is the call graph for this function:

Definition at line 103 of file writejpg.c.

{
    int i;
    char jpg_id[]="JFIF";
    int units=0;
    img_xres(img)=img_yres(img)=0;
    jpg_ptr(img)->file = xfopen(img_name(img), FOPEN_RBIN_MODE);
    xfseek(jpg_ptr(img)->file,0,SEEK_END,cur_file_name);
    jpg_ptr(img)->length=xftell(jpg_ptr(img)->file,cur_file_name);
    xfseek(jpg_ptr(img)->file,0,SEEK_SET,cur_file_name);
    if(read2bytes(jpg_ptr(img)->file)!=0xFFD8)
        pdftex_fail("reading JPEG image failed");

    if(read2bytes(jpg_ptr(img)->file)==0xFFE0) { /* JFIF APP0 */
      (void)read2bytes(jpg_ptr(img)->file);
      for(i=0;i<5;i++) if(xgetc(jpg_ptr(img)->file)!=jpg_id[i])
        pdftex_fail("reading JPEG image failed");
      (void)read2bytes(jpg_ptr(img)->file);
      units=xgetc(jpg_ptr(img)->file);
      img_xres(img)=read2bytes(jpg_ptr(img)->file);
      img_yres(img)=read2bytes(jpg_ptr(img)->file);
      switch(units) {
          case 1: break; /* pixels per inch */
          case 2: img_xres(img)*=2.54; img_yres(img)*=2.54;
                  break; /* pixels per cm */
          default:img_xres(img)=img_yres(img)=0; break;
      }
    }

    xfseek(jpg_ptr(img)->file,0,SEEK_SET,cur_file_name);
    while(1) {
        if(feof(jpg_ptr(img)->file) || fgetc(jpg_ptr(img)->file)!=0xFF)
            pdftex_fail("reading JPEG image failed");
        switch(xgetc(jpg_ptr(img)->file)) {
        case M_SOF5:
        case M_SOF6:
        case M_SOF7:
        case M_SOF9:
        case M_SOF10:
        case M_SOF11:
        case M_SOF13:
        case M_SOF14:
        case M_SOF15:
            pdftex_fail("unsupported type of compression");
        case M_SOF2:
         if (getintpar(cfgpdfminorversioncode) <= 2)
                 pdftex_fail("cannot use progressive DCT with PDF-1.2");
        case M_SOF0:
        case M_SOF1:
        case M_SOF3:
             (void)read2bytes(jpg_ptr(img)->file);    /* read segment length  */
             jpg_ptr(img)->bits_per_component = xgetc(jpg_ptr(img)->file);
             img_height(img)       = read2bytes(jpg_ptr(img)->file);
             img_width(img)        = read2bytes(jpg_ptr(img)->file);
             jpg_ptr(img)->color_space  = xgetc(jpg_ptr(img)->file);
             xfseek(jpg_ptr(img)->file,0,SEEK_SET,cur_file_name); 
             switch (jpg_ptr(img)->color_space) {
                 case JPG_GRAY:
                     img_color(img) = IMAGE_COLOR_B;
                     break;
                 case JPG_RGB:
                     img_color(img) = IMAGE_COLOR_C;
                     break;
                 case JPG_CMYK:
                     img_color(img) = IMAGE_COLOR_C;
                     break;
                 default:
                     pdftex_fail("Unsupported color space %i", 
                             (int)jpg_ptr(img)->color_space);
             }
             return;
        case M_SOI:             /* ignore markers without parameters */
        case M_EOI:
        case M_TEM:
        case M_RST0:
        case M_RST1:
        case M_RST2:
        case M_RST3:
        case M_RST4:
        case M_RST5:
        case M_RST6:
        case M_RST7:
            break;
        default:                        /* skip variable length markers */
            xfseek(jpg_ptr(img)->file,read2bytes(jpg_ptr(img)->file)-2,SEEK_CUR,cur_file_name);
            break;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

integer read_pdf_info ( char *  ,
char *  ,
integer  ,
integer  ,
integer  ,
integer   
)

Definition at line 678 of file pdftoepdf.cc.

{
    PdfDocument *pdf_doc;
    Page *page;
    int rotate;
    PDFRectangle *pagebox;
    float pdf_version_found, pdf_version_wanted;
    // initialize
    if (!isInit) {
        globalParams = new GlobalParams();
        globalParams->setErrQuiet(gFalse);
        isInit = gTrue;
    }
    // open PDF file
    pdf_doc = find_add_document(image_name);
    epdf_doc = (void *) pdf_doc;
#ifdef DEBUG
    fprintf(stderr, "\nReading information on %s\n", pdf_doc->file_name);
#endif
    // check pdf version
    // this works only for pdf 1.x -- but since any versions of pdf newer
    // than 1.x will not be backwards compatible to pdf 1.x, pdfTeX will
    // then have to changed drastically anyway.
    pdf_version_found = pdf_doc->doc->getPDFVersion();
    pdf_version_wanted = 1 + (minor_pdf_version_wanted * 0.1);
    if (pdf_version_found > pdf_version_wanted) {
        char msg[] = "pdf inclusion: found pdf version <%.1f>, but at most version <%.1f> allowed";
        if (pdf_inclusion_errorlevel > 0) {
            pdftex_fail(msg, pdf_version_found, pdf_version_wanted);
        } else {
            pdftex_warn(msg, pdf_version_found, pdf_version_wanted);
        }
    }
    epdf_num_pages = pdf_doc->doc->getCatalog()->getNumPages();
    if (page_name) {
        // get page by name
        GString name(page_name);
        LinkDest *link = pdf_doc->doc->findDest(&name);
        if (link == 0 || !link->isOk())
            pdftex_fail("pdf inclusion: invalid destination <%s>",
                page_name);
        Ref ref = link->getPageRef();
        page_num = pdf_doc->doc->getCatalog()->findPage(ref.num, ref.gen);
        if (page_num == 0)
            pdftex_fail("pdf inclusion: destination is not a page <%s>",
                page_name);
        delete link;
    } else {
        // get page by number
        if (page_num <= 0 || page_num > epdf_num_pages)
        pdftex_fail("pdf inclusion: required page does not exist <%i>", 
            epdf_num_pages);
    }
    // get the required page
    page = pdf_doc->doc->getCatalog()->getPage(page_num);

    // get the pagebox (media, crop...) to use.
    // always_use_pdf_pagebox can set in the config file to override the
    // setting through pdfximage.
    if (always_use_pdf_pagebox < 1) {
        switch (pdflastpdfboxspec) {
        case pdfpdfboxspeccrop:
            pagebox = page->getCropBox();
            break;
        
        case pdfpdfboxspecbleed:
            pagebox = page->getBleedBox();
            break;
        
        case pdfpdfboxspectrim:
            pagebox = page->getTrimBox();
            break;
        
        case pdfpdfboxspecart:
            pagebox = page->getArtBox();
            break;

        default:
            pagebox = page->getMediaBox();
            }
        }
    else {
        switch (always_use_pdf_pagebox) {
        case 1 : 
            pagebox = page->getMediaBox();
            break;
        case 2 : 
            pagebox = page->getCropBox();
            break;
        case 3 : 
            pagebox = page->getBleedBox();
            break;
        case 4 : 
            pagebox = page->getTrimBox();
            break;
        default : // 5 and larger
            pagebox = page->getArtBox();
            }
        }
#ifdef DEBUG
    fprintf(stderr, 
            "\npagebox->x1: %.8f, pagebox->x2: %.8f, pagebox->y1: %.8f, pagebox->y2: %.8f\n", 
            pagebox->x1, pagebox->x2, pagebox->y1, pagebox->y2);
#endif
    epdf_width = pagebox->x2 - pagebox->x1;
    epdf_height = pagebox->y2 - pagebox->y1;
    epdf_orig_x = pagebox->x1;
    epdf_orig_y = pagebox->y1;
    
    rotate = page->getRotate();
    // handle page rotation and adjust dimens as needed
    if (rotate != 0) {
        if (rotate % 90 == 0) {
            // handle only the simple case: multiple of 90s.
            // these are the only values allowed according to the
            // reference (v1.3, p.78).
            // 180 needs no special treatment here
            register float f;
            switch (rotate) {
                case  90: f = epdf_height; epdf_height = epdf_width; epdf_width = f;  break;
                case 270: f = epdf_height; epdf_height = epdf_width; epdf_width = f;  break;
                }
            }
        }
    pdf_doc->xref = pdf_doc->doc->getXRef();
    return page_num;
}

Here is the call graph for this function:

Definition at line 29 of file writepng.c.

{
    FILE *png_file = xfopen(img_name(img), FOPEN_RBIN_MODE);
    if ((png_ptr(img) = png_create_read_struct(PNG_LIBPNG_VER_STRING, 
        NULL, NULL, NULL)) == NULL)
        pdftex_fail("libpng: png_create_read_struct() failed");
    if ((png_info(img) = png_create_info_struct(png_ptr(img))) == NULL)
        pdftex_fail("libpng: png_create_info_struct() failed");
    if (setjmp(png_ptr(img)->jmpbuf))
        pdftex_fail("libpng: internal error");
    png_init_io(png_ptr(img), png_file);
    png_read_info(png_ptr(img), png_info(img));
    if (png_info(img)->color_type & PNG_COLOR_MASK_ALPHA)
        png_set_strip_alpha(png_ptr(img));
    if (png_info(img)->bit_depth == 16)
        png_set_strip_16(png_ptr(img));
    png_read_update_info(png_ptr(img), png_info(img));
    img_width(img) =  png_info(img)->width;
    img_height(img) =  png_info(img)->height;
    if (png_info(img)->valid & PNG_INFO_pHYs) {
        img_xres(img) = 
            round(0.0254*png_get_x_pixels_per_meter(png_ptr(img), png_info(img)));
        img_yres(img) =
            round(0.0254*png_get_y_pixels_per_meter(png_ptr(img), png_info(img)));
    }
    switch (png_info(img)->color_type) {
    case PNG_COLOR_TYPE_PALETTE:
        img_color(img) = IMAGE_COLOR_C | IMAGE_COLOR_I;
        break;
    case PNG_COLOR_TYPE_GRAY:
    case PNG_COLOR_TYPE_GRAY_ALPHA:
        img_color(img) = IMAGE_COLOR_B;
        break;
    case PNG_COLOR_TYPE_RGB:
    case PNG_COLOR_TYPE_RGB_ALPHA:
        img_color(img) = IMAGE_COLOR_C;
        break;
    default:
        pdftex_fail("unsupported type of color_type <%i>", png_info(img)->color_type);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 813 of file pdftoepdf.cc.

{
    Page *page;
    PdfObject contents, obj1, obj2;
    PdfObject group, metadata, pieceinfo, separationInfo;
    Object info;
    char *key;
    int i, l;
    int rotate;
    double scale[6] = {0, 0, 0, 0, 0, 0};
    PdfDocument *pdf_doc = (PdfDocument *) epdf_doc;
    (pdf_doc->occurences)--;
#ifdef DEBUG
    fprintf(stderr, "\nDecrementing %s (%d)\n", pdf_doc->file_name, pdf_doc->occurences);
#endif
    xref = pdf_doc->xref;
    inObjList = pdf_doc->inObjList;
    encodingList = 0;
    page = pdf_doc->doc->getCatalog()->getPage(epdf_selected_page);
    rotate = page->getRotate();
    PDFRectangle *pagebox;
    // write the Page header
    pdf_puts("/Type /XObject\n");
    pdf_puts("/Subtype /Form\n");
    pdf_puts("/FormType 1\n");

    // write additional information
    pdf_printf("/%s.FileName (%s)\n", pdfkeyprefix, 
               convertStringToPDFString(pdf_doc->file_name));
    pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, epdf_selected_page);
    pdf_doc->doc->getDocInfoNF(&info);
    if (info.isRef()) {
        // the info dict must be indirect (pdf ref p.61)
        pdf_printf("/%s.InfoDict ", pdfkeyprefix);
        pdf_printf("%d 0 R \n", addOther(info.getRef()));
        }
  
    // get the pagebox (media, crop...) to use.
    // epdf_always_use_pdf_pagebox is a copy of always_use_pdf_pagebox which
    // can set in the config file to override the setting through pdfximage.
    if (epdf_always_use_pdf_pagebox < 1) {
        switch (epdf_page_box) {
        case pdfpdfboxspeccrop:
            pagebox = page->getCropBox();
            break;
      
        case pdfpdfboxspecbleed:
            pagebox = page->getBleedBox();
            break;
        
        case pdfpdfboxspectrim:
            pagebox = page->getTrimBox();
            break;
        
        case pdfpdfboxspecart:
            pagebox = page->getArtBox();
            break;
       
        default:
            pagebox = page->getMediaBox();
            }
        }
    else {
        switch (epdf_always_use_pdf_pagebox) {
        case 1 : 
            pagebox = page->getMediaBox();
            break;
        case 2 : 
            pagebox = page->getCropBox();
            break;
        case 3 : 
            pagebox = page->getBleedBox();
            break;
        case 4 : 
            pagebox = page->getTrimBox();
            break;
        default : // 5 and larger
            pagebox = page->getArtBox();
            }
        }
#ifdef DEBUG
    fprintf(stderr, 
            "\npagebox->x1: %.8f, pagebox->x2: %.8f, pagebox->y1: %.8f, pagebox->y2: %.8f\n", 
            pagebox->x1, pagebox->x2, pagebox->y1, pagebox->y2);
#endif

    // handle page rotation
    if (rotate != 0) {
        if (rotate % 90 == 0) {
            // this handles only the simple case: multiple of 90s but these
            // are the only values allowed according to the reference
            // (v1.3, p.78).
            // the image is rotated around its center.
            // the /Rotate key is clockwise while the matrix is
            // counterclockwise :-%
            tex_printf (", page is rotated %d degrees", rotate);
            switch (rotate) {
                case  90: scale[1] = -1; scale[2] = 1; scale[4] = pagebox->x1 - pagebox->y1; scale[5] = pagebox->y1 + pagebox->x2; break;
                case 180: scale[0] = scale[3] = -1;    scale[4] = pagebox->x1 + pagebox->x2; scale[5] = pagebox->y1 + pagebox->y2; break; // width and height are exchanged
                case 270: scale[1] = 1; scale[2] = -1; scale[4] = pagebox->x1 + pagebox->y2; scale[5] = pagebox->y1 - pagebox->x1; break;
                }
            }
        }
    else {
        scale[0] = scale[3] = 1;
        }

    pdf_printf("/Matrix [%.8f %.8f %.8f %.8f %.8f %.8f]\n",
        scale[0],
        scale[1],
        scale[2],
        scale[3],
        scale[4],
        scale[5]);

    pdf_printf("/BBox [%.8f %.8f %.8f %.8f]\n",
               pagebox->x1,
               pagebox->y1,
               pagebox->x2,
               pagebox->y2);

    // write the page Group if it's there
    if (page->getGroup() != NULL) {
#if PDFTEX_COPY_PAGEGROUP
#   if PDFTEX_COPY_PAGEGROUP_NOFAIL
        // FIXME: This will most likely produce incorrect PDFs :-(
        initDictFromDict(group, page->getGroup());
        if (group->dictGetLength() > 0) {
            pdf_puts("/Group ");
            copyObject (&group);
            pdf_puts("\n");
        }
#   else
        // FIXME: currently we don't know how to handle Page Groups so we abort gracefully :-(
        pdftex_fail("pdf inclusion: Page Group detected which pdfTeX can't handle. Sorry.");
#   endif
#else
        // FIXME: currently we don't know how to handle Page Groups so we at least give a warning :-(
        pdftex_warn("pdf inclusion: Page Group detected which pdfTeX can't handle. Ignoring it.");
#endif
    }
    
    // write the page Metadata if it's there
    if (page->getMetadata() != NULL) {
        metadata->initStream(page->getMetadata());
        pdf_puts("/Metadata ");
        copyObject (&metadata);
        pdf_puts("\n");
    }
    
    // write the page PieceInfo if it's there
    if (page->getPieceInfo() != NULL) {
        initDictFromDict (pieceinfo, page->getPieceInfo());
        if (pieceinfo->dictGetLength() > 0) {
            pdf_puts("/PieceInfo ");
            copyObject (&pieceinfo);
            pdf_puts("\n");
        }
    }
    
    // write the page SeparationInfo if it's there
    if (page->getSeparationInfo() != NULL) {
        initDictFromDict (separationInfo, page->getSeparationInfo());
        if (separationInfo->dictGetLength() > 0) {
            pdf_puts("/SeparationInfo ");
            copyObject (&separationInfo);
            pdf_puts("\n");
        }
    }
    
    // write the Resources dictionary
    if (page->getResourceDict() == NULL) {
        // Resources can be missing (files without them have been spotted
        // in the wild). This violates the pdf spec, which claims they are
        // required, but all RIPs accept them.  
        // We "replace" them with empty Resources.
        pdftex_warn("pdf inclusion: no /Resources detected. Replacing with empty /Resources.");
        pdf_puts("/Resources <<>>\n");
        }
    else {
        initDictFromDict (obj1, page->getResourceDict());
        page->getResourceDict()->incRef();
        if (!obj1->isDict())
            pdftex_fail("pdf inclusion: invalid resources dict type <%s>", 
                        obj1->getTypeName());
        pdf_puts("/Resources <<\n");
        for (i = 0, l = obj1->dictGetLength(); i < l; ++i) {
            obj1->dictGetVal(i, &obj2);
            key = obj1->dictGetKey(i);
            if (strcmp("Font", key) == 0)
                copyFontResources(&obj2);
            else if (strcmp("ProcSet", key) == 0)
                copyProcSet(&obj2);
            else
                copyOtherResources(&obj2, key);
            }
        pdf_puts(">>\n");
    }
    // write the page contents
    page->getContents(&contents);
    if (contents->isStream()) {
        initDictFromDict (obj1, contents->streamGetDict());
        contents->streamGetDict()->incRef();
        copyDict(&obj1);
        pdf_puts(">>\nstream\n");
        copyStream(contents->getStream()->getBaseStream());
        pdf_puts("endstream\n");
        pdfendobj();
    }
    else if (contents->isArray()) {
        pdfbeginstream();
        for (i = 0, l = contents->arrayGetLength(); i < l; ++i) {
        Object contentsobj;
            copyStream((contents->arrayGet(i, &contentsobj))->getStream());
        contentsobj.free();
        }
        pdfendstream();
    }
    else {// the contents are optional, but we need to include an empty stream
        pdfbeginstream();
        pdfendstream();
    }
    // write out all indirect objects
    writeRefs();
    // write out all used encodings (and delete list)
    writeEncodings();
    // save object list, xref
    pdf_doc->inObjList = inObjList;
    pdf_doc->xref = xref;
}

Definition at line 193 of file writejpg.c.

{
    long unsigned l;
    FILE *f;
    pdf_puts("/Type /XObject\n/Subtype /Image\n");
    pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n/Length %i\n",
               img_width(img),
               img_height(img),
               (int)jpg_ptr(img)->bits_per_component,
               (int)jpg_ptr(img)->length);
    pdf_puts("/ColorSpace ");
    if (img_colorspace_ref(img) != 0) {
        pdf_printf("%i 0 R\n", (int)img_colorspace_ref(img));
    }
    else {
        switch (jpg_ptr(img)->color_space) {
        case JPG_GRAY:
            pdf_puts("/DeviceGray\n");
            break;
        case JPG_RGB:
            pdf_puts("/DeviceRGB\n");
            break;
        case JPG_CMYK:
            pdf_puts("/DeviceCMYK\n/Decode [1 0 1 0 1 0 1 0]\n");
            break;
        default:
            pdftex_fail("Unsupported color space %i", 
                 (int)jpg_ptr(img)->color_space);
        }
    }
    pdf_puts("/Filter /DCTDecode\n>>\nstream\n");
    for (l = jpg_ptr(img)->length, f = jpg_ptr(img)->file; l > 0; l--)
        pdfout(xgetc(f));
    pdf_puts("endstream\nendobj\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 71 of file writepng.c.

{
    int i, j, k, l;
    integer palette_objnum = 0;
    png_bytep row, r, *rows;
    pdf_puts("/Type /XObject\n/Subtype /Image\n");
    pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
               (int)png_info(img)->width,
               (int)png_info(img)->height,
               (int)png_info(img)->bit_depth);
    pdf_puts("/ColorSpace ");
    if (img_colorspace_ref(img) != 0) {
        pdf_printf("%i 0 R\n", (int)img_colorspace_ref(img));
    }
    else {
        switch (png_info(img)->color_type) {
            case PNG_COLOR_TYPE_PALETTE:
                pdfcreateobj(0, 0);
                palette_objnum = objptr;
                pdf_printf("[/Indexed /DeviceRGB %i %i 0 R]\n",
                        (int)(png_info(img)->num_palette - 1),
                        (int)palette_objnum);
                break;
            case PNG_COLOR_TYPE_GRAY:
            case PNG_COLOR_TYPE_GRAY_ALPHA:
                pdf_puts("/DeviceGray\n");
                break;
            case PNG_COLOR_TYPE_RGB:
            case PNG_COLOR_TYPE_RGB_ALPHA:
                pdf_puts("/DeviceRGB\n");
                break;
            default:
                pdftex_fail("unsupported type of color_type <%i>", png_info(img)->color_type);
        }
    }
    pdfbeginstream();
    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
        row = xtalloc(png_info(img)->rowbytes, png_byte);
        for (i = 0; i < (int)png_info(img)->height; i++) {
            png_read_row(png_ptr(img), row, NULL);
           r = row;
           k = png_info(img)->rowbytes;
           while(k > 0) {
              l = (k > pdfbufsize)? pdfbufsize : k;
              pdfroom(l);
              for (j = 0; j < l; j++)
                  pdfbuf[pdfptr++] = *r++;
              k -= l;
           }
        }
        xfree(row);
    }
    else {
        if (png_info(img)->height*png_info(img)->rowbytes >= 10240000L)
            pdftex_warn("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
        rows = xtalloc(png_info(img)->height, png_bytep);
        for (i = 0; i < png_info(img)->height; i++)
            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
        png_read_image(png_ptr(img), rows);
        for (i = 0; i < (int)png_info(img)->height; i++) {
            row = rows[i];
           k = png_info(img)->rowbytes;
           while(k > 0) {
              l = (k > pdfbufsize)? pdfbufsize : k;
              pdfroom(l);
              for (j = 0; j < l; j++)
                  pdfbuf[pdfptr++] = *row++;
              k -= l;
           }
            xfree(rows[i]);
        }
        xfree(rows);
    }
    pdfendstream();
    if (palette_objnum > 0) {
        pdfbegindict(palette_objnum);
        pdfbeginstream();
        for (i = 0; i < png_info(img)->num_palette; i++) {
            pdfroom(3);
            pdfbuf[pdfptr++] = png_info(img)->palette[i].red;
            pdfbuf[pdfptr++] = png_info(img)->palette[i].green;
            pdfbuf[pdfptr++] = png_info(img)->palette[i].blue;
        }
        pdfendstream();
    }
    pdfflush();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation