Leptonica
1.54
|
#define DEBUG_MULTIPAGE 0 |
#define L_BIGBUF 2048 /* must be able to hold hex colormap */ |
#define L_SMALLBUF 256 |
l_int32 cidConvertToPdfData | ( | L_COMP_DATA * | cid, |
const char * | title, | ||
l_uint8 ** | pdata, | ||
size_t * | pnbytes | ||
) |
Input: cid (compressed image data -- of jp2k image) title (<optional> pdf title; can be NULL) &data (<return> output pdf data for image) &nbytes (<return> size of output pdf data) Return: 0 if OK, 1 on error
Notes: (1) Caller must not destroy the cid. It is absorbed in the lpd and destroyed by this function.
static l_int32 generateColormapStringsPdf | ( | L_PDF_DATA * | lpd | ) | [static] |
static l_int32 generateContentStringPdf | ( | L_PDF_DATA * | lpd | ) | [static] |
static void generateFixedStringsPdf | ( | L_PDF_DATA * | lpd | ) | [static] |
static void generateMediaboxPdf | ( | L_PDF_DATA * | lpd | ) | [static] |
static l_int32 generateOutputDataPdf | ( | l_uint8 ** | pdata, |
size_t * | pnbytes, | ||
L_PDF_DATA * | lpd | ||
) | [static] |
Input: &data (<return> pdf data array) &nbytes (<return> size of pdf data array) lpd (input data used to make pdf) Return: 0 if OK, 1 on error
Notes: (1) Only called from l_generatePdf(). On error, no data is returned.
static char * generatePagesObjStringPdf | ( | NUMA * | napage | ) | [static] |
static l_int32 generatePageStringPdf | ( | L_PDF_DATA * | lpd | ) | [static] |
static l_int32 generatePreXStringsPdf | ( | L_PDF_DATA * | lpd | ) | [static] |
static void generateTrailerPdf | ( | L_PDF_DATA * | lpd | ) | [static] |
void l_CIDataDestroy | ( | L_COMP_DATA ** | pcid | ) |
Input: &cid (<will be="" set="" to="" null="" before="" returning>="">) Return: void
l_int32 l_generateCIData | ( | const char * | fname, |
l_int32 | type, | ||
l_int32 | quality, | ||
l_int32 | ascii85, | ||
L_COMP_DATA ** | pcid | ||
) |
Input: fname type (L_G4_ENCODE, L_JPEG_ENCODE, L_FLATE_ENCODE, L_JP2K_ENCODE) quality (used for jpeg only; 0 for default (75)) ascii85 (0 for binary; 1 for ascii85-encoded) &cid (<return> compressed data) Return: 0 if OK, 1 on error
Notes: (1) This can be used for both PostScript and pdf. (1) Set ascii85:
l_int32 l_generateCIDataForPdf | ( | const char * | fname, |
PIX * | pix, | ||
l_int32 | quality, | ||
L_COMP_DATA ** | pcid | ||
) |
Input: fname pix (<optional>; can be null) quality (for jpeg if transcoded; 75 is standard) &cid (<return> compressed data) Return: 0 if OK, 1 on error
Notes: (1) Given an image file and optionally a pix raster of that data, this provides a CID that is compatible with PDF, preferably without transcoding. (2) The pix is included for efficiency, in case transcoding is required and the pix is available to the caller.
L_COMP_DATA* l_generateFlateData | ( | const char * | fname, |
l_int32 | ascii85flag | ||
) |
Input: fname ascii85flag (0 for gzipped; 1 for ascii85-encoded gzipped) Return: cid (flate compressed image data), or null on error
Notes: (1) The input image is converted to one of these 4 types:
L_COMP_DATA* l_generateFlateDataPdf | ( | const char * | fname, |
PIX * | pixs | ||
) |
Input: fname (preferably png) pix (<optional>; can be null) Return: cid (containing png data), or null on error
Notes: (1) If you hand this a png file, you are going to get png predictors embedded in the flate data. So it has come to this. http://xkcd.com/1022/ (2) Exception: if the png is interlaced or if it is RGBA, it will be transcoded. (3) If transcoding is required, this will not have to read from file if you also input a pix.
L_COMP_DATA* l_generateG4Data | ( | const char * | fname, |
l_int32 | ascii85flag | ||
) |
Input: fname (of g4 compressed file) ascii85flag (0 for g4 compressed; 1 for ascii85-encoded g4) Return: cid (g4 compressed image data), or null on error
Notes: (1) Set ascii85flag:
static L_COMP_DATA * l_generateJp2kData | ( | const char * | fname | ) | [static] |
Input: fname (of jp2k file) Return: cid (containing jp2k data), or null on error
Notes: (1) This is only called after the file is verified to be jp2k.
L_COMP_DATA* l_generateJpegData | ( | const char * | fname, |
l_int32 | ascii85flag | ||
) |
Input: fname (of jpeg file) ascii85flag (0 for jpeg; 1 for ascii85-encoded jpeg) Return: cid (containing jpeg data), or null on error
Notes: (1) Set ascii85flag:
static l_int32 l_generatePdf | ( | l_uint8 ** | pdata, |
size_t * | pnbytes, | ||
L_PDF_DATA * | lpd | ||
) | [static] |
Input: &data (<return> pdf array) &nbytes (<return> number of bytes in pdf array) lpd (all the required input image data) Return: 0 if OK, 1 on error
Notes: (1) On error, no data is returned. (2) The objects are: 1: Catalog 2: Info 3: Pages 4: Page 5: Contents (rendering command) 6 to 6+n-1: n XObjects 6+n to 6+n+m-1: m colormaps
void l_pdfSetDateAndVersion | ( | l_int32 | flag | ) |
Input: flag (1 for writing date/time and leptonica version; 0 for omitting this from the metadata) Return: void
Notes: (1) The default is for writing this data. For regression tests that compare output against golden files, it is useful to omit.
void l_pdfSetG4ImageMask | ( | l_int32 | flag | ) |
Input: flag (1 for writing g4 data as fg only through a mask; 0 for writing fg and bg) Return: void
Notes: (1) The default is for writing only the fg (through the mask). That way when you write a 1 bpp image, the bg is transparent, so any previously written image remains visible behind it.
static char * makeTrailerStringPdf | ( | L_DNA * | daloc | ) | [static] |
static l_int32 parseTrailerPdf | ( | L_BYTEA * | bas, |
L_DNA ** | pda | ||
) | [static] |
Input: bas (lba of a pdf file) da (<return> byte locations of the beginning of each object) Return: 0 if OK, 1 on error
static L_PDF_DATA * pdfdataCreate | ( | const char * | title | ) | [static] |
static void pdfdataDestroy | ( | L_PDF_DATA ** | plpd | ) | [static] |
static L_COMP_DATA * pdfdataGetCid | ( | L_PDF_DATA * | lpd, |
l_int32 | index | ||
) | [static] |
l_int32 pixConvertToPdfData | ( | PIX * | pix, |
l_int32 | type, | ||
l_int32 | quality, | ||
l_uint8 ** | pdata, | ||
size_t * | pnbytes, | ||
l_int32 | x, | ||
l_int32 | y, | ||
l_int32 | res, | ||
const char * | title, | ||
L_PDF_DATA ** | plpd, | ||
l_int32 | position | ||
) |
Input: pix (all depths; cmap OK) type (L_G4_ENCODE, L_JPEG_ENCODE, L_FLATE_ENCODE) quality (used for JPEG only; 0 for default (75)) &data (<return> pdf array) &nbytes (<return> number of bytes in pdf array) x, y (location of lower-left corner of image, in pixels, relative to the PostScript origin (0,0) at the lower-left corner of the page) res (override the resolution of the input image, in ppi; use 0 to respect the resolution embedded in the input) title (<optional> pdf title) &lpd (ptr to lpd, which is created on the first invocation and returned until last image is processed) position (in image sequence: L_FIRST_IMAGE, L_NEXT_IMAGE, L_LAST_IMAGE) Return: 0 if OK, 1 on error
Notes: (1) If == 0 and the input resolution field is 0, this will use DEFAULT_INPUT_RES. (2) This only writes if it is the last image to be written on the page. (3) See comments in convertToPdf().
l_int32 pixGenerateCIData | ( | PIX * | pixs, |
l_int32 | type, | ||
l_int32 | quality, | ||
l_int32 | ascii85, | ||
L_COMP_DATA ** | pcid | ||
) |
Input: pixs (8 or 32 bpp, no colormap) type (L_G4_ENCODE, L_JPEG_ENCODE, L_FLATE_ENCODE) quality (used for jpeg only; 0 for default (75)) ascii85 (0 for binary; 1 for ascii85-encoded) &cid (<return> compressed data) Return: 0 if OK, 1 on error
Notes: (1) Set ascii85:
static L_COMP_DATA * pixGenerateFlateData | ( | PIX * | pixs, |
l_int32 | ascii85flag | ||
) | [static] |
Input: pixs ascii85flag (0 for gzipped; 1 for ascii85-encoded gzipped) Return: cid (flate compressed image data), or null on error
Notes: (1) This should not be called with an RGBA pix (spp == 4); it will ignore the alpha channel. Likewise, if called with a colormapped pix, the alpha component in the colormap will be ignored (as it is for all leptonica operations on colormapped pix).
static L_COMP_DATA * pixGenerateG4Data | ( | PIX * | pixs, |
l_int32 | ascii85flag | ||
) | [static] |
Input: pixs (1 bpp) ascii85flag (0 for gzipped; 1 for ascii85-encoded gzipped) Return: cid (g4 compressed image data), or null on error
Notes: (1) Set ascii85flag:
static L_COMP_DATA * pixGenerateJpegData | ( | PIX * | pixs, |
l_int32 | ascii85flag, | ||
l_int32 | quality | ||
) | [static] |
Input: pixs (8 or 32 bpp, no colormap) ascii85flag (0 for jpeg; 1 for ascii85-encoded jpeg) quality (0 for default, which is 75) Return: cid (jpeg compressed data), or null on error
Notes: (1) Set ascii85flag:
l_int32 ptraConcatenatePdfToData | ( | L_PTRA * | pa_data, |
SARRAY * | sa, | ||
l_uint8 ** | pdata, | ||
size_t * | pnbytes | ||
) |
Input: ptra (array of pdf strings, each for a single-page pdf file) sarray (<optional> of pathnames for input pdf files) &data (<return> concatenated pdf data in memory) &nbytes (<return> number of bytes in pdf data) Return: 0 if OK, 1 on error
Notes: (1) This only works with leptonica-formatted single-page pdf files. pdf files generated by other programs will have unpredictable (and usually bad) results. The requirements for each pdf file: (a) The Catalog and Info objects are the first two. (b) Object 3 is Pages (c) Object 4 is Page (d) The remaining objects are Contents, XObjects, and ColorSpace (2) We remove trailers from each page, and append the full trailer for all pages at the end. (3) For all but the first file, remove the ID and the first 3 objects (catalog, info, pages), so that each subsequent file has only objects of these classes: Page, Contents, XObject, ColorSpace (Indexed RGB). For those objects, we substitute these refs to objects in the local file: Page: Parent(object 3), Contents, XObject(typically multiple) XObject: [ColorSpace if indexed] The Pages object on the first page (object 3) has a Kids array of references to all the Page objects, with a Count equal to the number of pages. Each Page object refers back to this parent.
static L_BYTEA * substituteObjectNumbers | ( | L_BYTEA * | bas, |
NUMA * | na_objs | ||
) | [static] |
Input: bas (lba of a pdf object) na_objs (object number mapping array) Return: bad (lba of rewritten pdf for the object)
Notes: (1) Interpret the first set of bytes as the object number, map to the new number, and write it out. (2) Find all occurrences of this 4-byte sequence: " 0 R" (3) Find the location and value of the integer preceding this, and map it to the new value. (4) Rewrite the object with new object numbers.
const l_int32 DEFAULT_INPUT_RES = 300 [static] |
l_int32 var_WRITE_DATE_AND_VERSION = 1 [static] |
l_int32 var_WRITE_G4_IMAGE_MASK = 1 [static] |