Back to index

tetex-bin  3.0
Defines | Functions | Variables
writeimg.c File Reference
#include "ptexlib.h"
#include "image.h"
#include <kpathsea/c-auto.h>
#include <kpathsea/c-memstr.h>

Go to the source code of this file.

Defines

#define bp2int(p)   round(p*(onehundredbp/100.0))
#define HEADER_JPG   "\xFF\xD8"
#define HEADER_PNG   "\x89PNG\r\n\x1A\n"
#define HEADER_PDF   "%PDF-1."
#define MAX_HEADER   (sizeof(HEADER_PNG)-1)

Functions

 define_array (image)
static integer new_image_entry (void)
integer imagecolor (integer img)
integer imagewidth (integer img)
integer imageheight (integer img)
integer imagexres (integer img)
integer imageyres (integer img)
boolean ispdfimage (integer img)
boolean checkimageb (integer procset)
boolean checkimagec (integer procset)
boolean checkimagei (integer procset)
void updateimageprocset (integer img)
integer epdforigx (integer img)
integer epdforigy (integer img)
integer imagepages (integer img)
integer imagecolordepth (integer img)
static void checktypebyheader (integer img)
static void checktypebyextension (integer img)
integer readimage (strnumber s, integer page_num, strnumber page_name, integer colorspace, integer pdfversion, integer pdfoptionalwaysusepdfpagebox, integer pdf_option_pdf_inclusion_errorlevel)
void writeimage (integer img)
void deleteimage (integer img)
void img_free ()

Variables

static const char perforce_id [] = "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeimg.c#15 $"
float epdf_width
float epdf_height
float epdf_orig_x
float epdf_orig_y
integer epdf_selected_page
integer epdf_num_pages
integer epdf_page_box
integer epdf_always_use_pdf_pagebox
voidepdf_doc

Define Documentation

#define bp2int (   p)    round(p*(onehundredbp/100.0))

Definition at line 31 of file writeimg.c.

#define HEADER_JPG   "\xFF\xD8"

Definition at line 201 of file writeimg.c.

#define HEADER_PDF   "%PDF-1."

Definition at line 203 of file writeimg.c.

#define HEADER_PNG   "\x89PNG\r\n\x1A\n"

Definition at line 202 of file writeimg.c.

#define MAX_HEADER   (sizeof(HEADER_PNG)-1)

Definition at line 204 of file writeimg.c.


Function Documentation

boolean checkimageb ( integer  procset)

Definition at line 90 of file writeimg.c.

{
    return procset & IMAGE_COLOR_B;
}
boolean checkimagec ( integer  procset)

Definition at line 95 of file writeimg.c.

{
    return procset & IMAGE_COLOR_C;
}
boolean checkimagei ( integer  procset)

Definition at line 100 of file writeimg.c.

{
    return procset & IMAGE_COLOR_I;
}
static void checktypebyextension ( integer  img) [static]

Definition at line 232 of file writeimg.c.

{
    char *image_suffix;

    if (img_type(img) != IMAGE_TYPE_NONE) /* nothing to do */
        return;
    /* tests */
    if ((image_suffix = strrchr(cur_file_name, '.')) == 0)
        img_type(img) = IMAGE_TYPE_NONE;
    else if (strcasecmp(image_suffix, ".pdf") == 0)
        img_type(img) = IMAGE_TYPE_PDF;
    else if (strcasecmp(image_suffix, ".png") == 0)
        img_type(img) = IMAGE_TYPE_PNG;
    else if (strcasecmp(image_suffix, ".jpg") == 0 ||
             strcasecmp(image_suffix, ".jpeg") == 0)
        img_type(img) = IMAGE_TYPE_JPG;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void checktypebyheader ( integer  img) [static]

Definition at line 205 of file writeimg.c.

{
    int i;
    FILE *file = NULL;
    char header[MAX_HEADER];

    if (img_type(img) != IMAGE_TYPE_NONE) /* nothing to do */
        return;

    /* read the header */
    file = xfopen(img_name(img), FOPEN_RBIN_MODE);
    for (i=0; i<MAX_HEADER; i++) {
        header[i] = xgetc(file);
        if (feof(file))
            pdftex_fail("reading image file failed");
    }
    xfclose(file, img_name(img));

    /* tests */
    if (strncmp(header, HEADER_JPG, sizeof(HEADER_JPG)-1) == 0)
        img_type(img) = IMAGE_TYPE_JPG;
    else if (strncmp(header, HEADER_PNG, sizeof(HEADER_PNG)-1) == 0)
        img_type(img) = IMAGE_TYPE_PNG;
    else if (strncmp(header, HEADER_PDF, sizeof(HEADER_PDF)-1) == 0)
        img_type(img) = IMAGE_TYPE_PDF;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 341 of file writeimg.c.

{
    switch (img_type(img)) {
    case IMAGE_TYPE_PDF:
        epdf_doc = pdf_ptr(img)->doc;
        epdf_delete();
        break;
    case IMAGE_TYPE_PNG:
        xfclose(png_ptr(img)->io_ptr, cur_file_name);
        png_destroy_read_struct(&(png_ptr(img)), &(png_info(img)), NULL);
        break;
    case IMAGE_TYPE_JPG:
        xfclose(jpg_ptr(img)->file, cur_file_name);
        break;
    default:
        pdftex_fail("unknown type of image");
    }
    xfree(img_name(img));
    return;
}

Here is the call graph for this function:

Definition at line 110 of file writeimg.c.

{
    return pdf_ptr(img)->orig_x;
}

Definition at line 115 of file writeimg.c.

{
    return pdf_ptr(img)->orig_y;
}

Definition at line 60 of file writeimg.c.

{
    return img_color(img);
}

Definition at line 125 of file writeimg.c.

{
    switch (img_type(img)) {
    case IMAGE_TYPE_PNG:
        return png_info(img)->bit_depth;
    case IMAGE_TYPE_JPG:
        return jpg_ptr(img)->bits_per_component;
    case IMAGE_TYPE_PDF:
        return 0;
    default:
        pdftex_fail("unknown type of image");
    }
}

Definition at line 70 of file writeimg.c.

{
    return img_height(img);
}

Definition at line 120 of file writeimg.c.

{
    return img_pages(img);
}

Definition at line 65 of file writeimg.c.

{
    return img_width(img);
}

Definition at line 75 of file writeimg.c.

{
    return img_xres(img);
}

Definition at line 80 of file writeimg.c.

{
    return img_yres(img);
}

Definition at line 362 of file writeimg.c.

{
    xfree(image_array);
}

Here is the caller graph for this function:

Definition at line 85 of file writeimg.c.

{
    return img_type(img) == IMAGE_TYPE_PDF;
}
static integer new_image_entry ( void  ) [static]

Definition at line 46 of file writeimg.c.

Here is the caller graph for this function:

integer readimage ( strnumber  s,
integer  page_num,
strnumber  page_name,
integer  colorspace,
integer  pdfversion,
integer  pdfoptionalwaysusepdfpagebox,
integer  pdf_option_pdf_inclusion_errorlevel 
)

Definition at line 250 of file writeimg.c.

{
    char *dest = NULL;
    integer img = new_image_entry();
    img_colorspace_ref(img) = colorspace;

    /* need to allocate new string as makecstring's buffer is 
       already used by cur_file_name */
    if (page_name != 0)
      dest = xstrdup(makecstring(page_name));
    cur_file_name = makecstring(s);
#ifdef WIN32
    /* unquote file name */
    if (*cur_file_name == '"') {
      char *p = cur_file_name;
      char *q = cur_file_name;
      while (p && *p) {
    *q = (*p == '"' ? *(++p) : *p);
    p++, q++;
      }
      *q = '\0';
    }
    fprintf(stderr, " %s\n", cur_file_name);
#endif
    img_name(img) = kpse_find_file(cur_file_name, kpse_tex_format, true);
    if (img_name(img) == NULL)
        pdftex_fail("cannot find image file");
    /* type checks */
    checktypebyheader(img);
    checktypebyextension(img);
    /* read image */
    switch (img_type(img)) {
    case IMAGE_TYPE_PDF:
        pdf_ptr(img) = xtalloc(1, pdf_image_struct);
        pdf_ptr(img)->page_box = pdflastpdfboxspec;
        pdf_ptr(img)->always_use_pdfpagebox = pdfoptionalwaysusepdfpagebox;
        page_num = read_pdf_info(img_name(img), dest, page_num, 
                                     pdfversion, pdfoptionalwaysusepdfpagebox,
                                     pdf_option_pdf_inclusion_errorlevel);
        img_width(img) = bp2int(epdf_width);
        img_height(img) = bp2int(epdf_height);
        img_pages(img) = epdf_num_pages;
        pdf_ptr(img)->orig_x = bp2int(epdf_orig_x);
        pdf_ptr(img)->orig_y = bp2int(epdf_orig_y);
        pdf_ptr(img)->selected_page = page_num;
        pdf_ptr(img)->doc = epdf_doc;
        break;
    case IMAGE_TYPE_PNG:
        img_pages(img) = 1;
        read_png_info(img);
        break;
    case IMAGE_TYPE_JPG:
        jpg_ptr(img) = xtalloc(1, JPG_IMAGE_INFO);
        img_pages(img) = 1;
        read_jpg_info(img);
        break;
    default:
        pdftex_fail("unknown type of image");
    }
    xfree(dest);
    cur_file_name = NULL;
    return img;
}

Here is the call graph for this function:

Definition at line 105 of file writeimg.c.

{
    pdfimageprocset |= img_color(img);
}

Definition at line 316 of file writeimg.c.

{
    cur_file_name = img_name(img);
    tex_printf(" <%s", img_name(img));
    switch (img_type(img)) {
    case IMAGE_TYPE_PNG:
        write_png(img);
        break;
    case IMAGE_TYPE_JPG:
        write_jpg(img);
        break;
    case IMAGE_TYPE_PDF:
        epdf_doc = pdf_ptr(img)->doc;
        epdf_selected_page = pdf_ptr(img)->selected_page;
        epdf_page_box = pdf_ptr(img)->page_box;
        epdf_always_use_pdf_pagebox = pdf_ptr(img)->always_use_pdfpagebox;
        write_epdf();
        break;
    default:
        pdftex_fail("unknown type of image");
    }
    tex_printf(">");
    cur_file_name = NULL;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 43 of file writeimg.c.

Definition at line 44 of file writeimg.c.

float epdf_height

Definition at line 37 of file writeimg.c.

Definition at line 41 of file writeimg.c.

float epdf_orig_x

Definition at line 38 of file writeimg.c.

float epdf_orig_y

Definition at line 39 of file writeimg.c.

Definition at line 42 of file writeimg.c.

Definition at line 40 of file writeimg.c.

float epdf_width

Definition at line 36 of file writeimg.c.

const char perforce_id[] = "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeimg.c#15 $" [static]

Definition at line 28 of file writeimg.c.