![]() |
Leptonica
1.73
Image processing and image analysis suite
|
#include <string.h>#include <math.h>#include "allheaders.h"Go to the source code of this file.
Macros | |
| #define | L_SMALLBUF 256 |
| #define | L_BIGBUF 2048 /* must be able to hold hex colormap */ |
| #define | DEBUG_MULTIPAGE 0 |
Functions | |
| static L_COMP_DATA * | l_generateJp2kData (const char *fname) |
| static L_COMP_DATA * | pixGenerateFlateData (PIX *pixs, l_int32 ascii85flag) |
| static L_COMP_DATA * | pixGenerateJpegData (PIX *pixs, l_int32 ascii85flag, l_int32 quality) |
| static L_COMP_DATA * | pixGenerateG4Data (PIX *pixs, l_int32 ascii85flag) |
| static l_int32 | l_generatePdf (l_uint8 **pdata, size_t *pnbytes, L_PDF_DATA *lpd) |
| static void | generateFixedStringsPdf (L_PDF_DATA *lpd) |
| static char * | generateEscapeString (const char *str) |
| static void | generateMediaboxPdf (L_PDF_DATA *lpd) |
| static l_int32 | generatePageStringPdf (L_PDF_DATA *lpd) |
| static l_int32 | generateContentStringPdf (L_PDF_DATA *lpd) |
| static l_int32 | generatePreXStringsPdf (L_PDF_DATA *lpd) |
| static l_int32 | generateColormapStringsPdf (L_PDF_DATA *lpd) |
| static void | generateTrailerPdf (L_PDF_DATA *lpd) |
| static char * | makeTrailerStringPdf (L_DNA *daloc) |
| static l_int32 | generateOutputDataPdf (l_uint8 **pdata, size_t *pnbytes, L_PDF_DATA *lpd) |
| static l_int32 | parseTrailerPdf (L_BYTEA *bas, L_DNA **pda) |
| static char * | generatePagesObjStringPdf (NUMA *napage) |
| static L_BYTEA * | substituteObjectNumbers (L_BYTEA *bas, NUMA *na_objs) |
| static L_PDF_DATA * | pdfdataCreate (const char *title) |
| static void | pdfdataDestroy (L_PDF_DATA **plpd) |
| static L_COMP_DATA * | pdfdataGetCid (L_PDF_DATA *lpd, l_int32 index) |
| 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) |
| l_int32 | ptraConcatenatePdfToData (L_PTRA *pa_data, SARRAY *sa, l_uint8 **pdata, size_t *pnbytes) |
| l_int32 | convertTiffMultipageToPdf (const char *filein, const char *fileout) |
| l_int32 | l_generateCIDataForPdf (const char *fname, PIX *pix, l_int32 quality, L_COMP_DATA **pcid) |
| L_COMP_DATA * | l_generateFlateDataPdf (const char *fname, PIX *pixs) |
| L_COMP_DATA * | l_generateJpegData (const char *fname, l_int32 ascii85flag) |
| l_int32 | l_generateCIData (const char *fname, l_int32 type, l_int32 quality, l_int32 ascii85, L_COMP_DATA **pcid) |
| l_int32 | pixGenerateCIData (PIX *pixs, l_int32 type, l_int32 quality, l_int32 ascii85, L_COMP_DATA **pcid) |
| L_COMP_DATA * | l_generateFlateData (const char *fname, l_int32 ascii85flag) |
| L_COMP_DATA * | l_generateG4Data (const char *fname, l_int32 ascii85flag) |
| l_int32 | cidConvertToPdfData (L_COMP_DATA *cid, const char *title, l_uint8 **pdata, size_t *pnbytes) |
| void | l_CIDataDestroy (L_COMP_DATA **pcid) |
| void | l_pdfSetG4ImageMask (l_int32 flag) |
| void | l_pdfSetDateAndVersion (l_int32 flag) |
Variables | |
| static const l_int32 | DEFAULT_INPUT_RES = 300 |
| static l_int32 | var_WRITE_G4_IMAGE_MASK = 1 |
| static l_int32 | var_WRITE_DATE_AND_VERSION = 1 |
Lower-level operations for generating pdf.
Intermediate function for single page, multi-image conversion
l_int32 pixConvertToPdfData() Intermediate function for generating multipage pdf output
l_int32 ptraConcatenatePdfToData() Convert tiff multipage to pdf file
l_int32 convertTiffMultipageToPdf()Low-level CID-based operations
Without transcoding
l_int32 l_generateCIDataForPdf()
L_COMP_DATA *l_generateFlateDataPdf()
L_COMP_DATA *l_generateJpegData()
static L_COMP_DATA *l_generateJp2kData() With transcoding
l_int32 l_generateCIData()
static l_int32 pixGenerateCIData()
L_COMP_DATA *l_generateFlateData()
static L_COMP_DATA *pixGenerateFlateData()
static L_COMP_DATA *pixGenerateJpegData()
static L_COMP_DATA *pixGenerateG4Data()
L_COMP_DATA *l_generateG4Data() Other
l_int32 cidConvertToPdfData()
void l_CIDataDestroy() Helper functions for generating the output pdf string
static l_int32 l_generatePdf()
static void generateFixedStringsPdf()
static char *generateEscapeString()
static void generateMediaboxPdf()
static l_int32 generatePageStringPdf()
static l_int32 generateContentStringPdf()
static l_int32 generatePreXStringsPdf()
static l_int32 generateColormapStringsPdf()
static void generateTrailerPdf()
static l_int32 makeTrailerStringPdf()
static l_int32 generateOutputDataPdf() Helper functions for generating multipage pdf output
static l_int32 parseTrailerPdf()
static char *generatePagesObjStringPdf()
static L_BYTEA *substituteObjectNumbers() Create/destroy/access pdf data
static L_PDF_DATA *pdfdataCreate()
static void pdfdataDestroy()
static L_COMP_DATA *pdfdataGetCid() Set flags for special modes
void l_pdfSetG4ImageMask()
void l_pdfSetDateAndVersion()
Definition in file pdfio2.c.
| l_int32 cidConvertToPdfData | ( | L_COMP_DATA * | cid, |
| const char * | title, | ||
| l_uint8 ** | pdata, | ||
| size_t * | pnbytes | ||
| ) |
| [in] | cid | compressed image data – of jp2k image |
| [in] | title | [optional] pdf title; can be NULL |
| [out] | pdata | output pdf data for image |
| [out] | pnbytes | size of output pdf data |
Notes:
(1) Caller must not destroy the cid. It is absorbed in the
lpd and destroyed by this function.
Definition at line 1401 of file pdfio2.c.
References L_Compressed_Data::res.
| l_int32 convertTiffMultipageToPdf | ( | const char * | filein, |
| const char * | fileout | ||
| ) |
| [in] | filein | (tiff) |
| [in] | fileout | (pdf) |
Notes:
(1) A multipage tiff file can also be converted to PS, using
convertTiffMultipageToPS()
Definition at line 470 of file pdfio2.c.
References fileFormatIsTiff(), fopenReadStream(), pixaConvertToPdf(), pixaDestroy(), and pixaReadMultipageTiff().
|
static |
generateEscapeString()
| [in] | str | input string |
Notes:
(1) If the input string is not ascii, returns null.
(2) This takes an input ascii string and generates a hex
ascii output string with 4 bytes out for each byte in.
The feff code at the beginning tells the pdf interpreter
that the data is to be interpreted as big-endian, 4 bytes
at a time. For ascii, the first two bytes are 0 and the
last two bytes are less than 0x80.
*/
static char *
generateEscapeString(const char *str)
{
char smallbuf[8];
char *buffer;
l_int32 i, nchar, buflen;
PROCNAME("generateEscapeString");
if (!str)
return (char *)ERROR_PTR("str not defined", procName, NULL);
nchar = strlen(str);
for (i = 0; i < nchar; i++) {
if (str[i] < 0)
return (char *)ERROR_PTR("str not all ascii", procName, NULL);
}
buflen = 4 * nchar + 10;
buffer = (char *)LEPT_CALLOC(buflen, sizeof(char));
stringCat(buffer, buflen, "<feff");
for (i = 0; i < nchar; i++) {
snprintf(smallbuf, sizeof(smallbuf), "%04x", str[i]);
stringCat(buffer, buflen, smallbuf);
}
stringCat(buffer, buflen, ">");
return buffer;
}static void
generateMediaboxPdf(L_PDF_DATA *lpd)
{
l_int32 i;
l_float32 xpt, ypt, wpt, hpt, maxx, maxy;
/* First get the full extent of all the images.
This is the mediabox, in pts. */
maxx = maxy = 0;
for (i = 0; i < lpd->n; i++) {
ptaGetPt(lpd->xy, i, &xpt, &ypt);
ptaGetPt(lpd->wh, i, &wpt, &hpt);
maxx = L_MAX(maxx, xpt + wpt);
maxy = L_MAX(maxy, ypt + hpt);
}
lpd->mediabox = boxCreate(0, 0, (l_int32)(maxx + 0.5),
(l_int32)(maxy + 0.5));
/* ypt is in standard image coordinates: the location of
the UL image corner with respect to the UL media box corner.
Rewrite each ypt for PostScript coordinates: the location of
the LL image corner with respect to the LL media box corner. */
for (i = 0; i < lpd->n; i++) {
ptaGetPt(lpd->xy, i, &xpt, &ypt);
ptaGetPt(lpd->wh, i, &wpt, &hpt);
ptaSetPt(lpd->xy, i, xpt, maxy - ypt - hpt);
}
return;
}static l_int32
generatePageStringPdf(L_PDF_DATA *lpd)
{
char *buf;
char *xstr;
l_int32 bufsize, i, wpt, hpt;
SARRAY *sa;
PROCNAME("generatePageStringPdf");
/* Allocate 1000 bytes for the boilerplate text, and
50 bytes for each reference to an image in the
ProcSet array. */
bufsize = 1000 + 50 * lpd->n;
if ((buf = (char *)LEPT_CALLOC(bufsize, sizeof(char))) == NULL)
return ERROR_INT("calloc fail for buf", procName, 1);
boxGetGeometry(lpd->mediabox, NULL, NULL, &wpt, &hpt);
sa = sarrayCreate(lpd->n);
for (i = 0; i < lpd->n; i++) {
snprintf(buf, bufsize, "/Im%d %d 0 R ", i + 1, 6 + i);
sarrayAddString(sa, buf, L_COPY);
}
xstr = sarrayToString(sa, 0);
sarrayDestroy(&sa);
if (!xstr) {
LEPT_FREE(buf);
return ERROR_INT("xstr not made", procName, 1);
}
snprintf(buf, bufsize, "4 0 obj\n"
"<<\n"
"/Type /Page\n"
"/Parent 3 0 R\n"
"/MediaBox [%d %d %d %d]\n"
"/Contents 5 0 R\n"
"/Resources\n"
"<<\n"
"/XObject << %s >>\n"
"/ProcSet [ /ImageB /ImageI /ImageC ]\n"
">>\n"
">>\n"
"endobj\n",
0, 0, wpt, hpt, xstr);
lpd->obj4 = stringNew(buf);
l_dnaAddNumber(lpd->objsize, strlen(lpd->obj4));
sarrayDestroy(&sa);
LEPT_FREE(buf);
LEPT_FREE(xstr);
return 0;
}static l_int32
generateContentStringPdf(L_PDF_DATA *lpd)
{
char *buf;
char *cstr;
l_int32 i, bufsize;
l_float32 xpt, ypt, wpt, hpt;
SARRAY *sa;
PROCNAME("generateContentStringPdf");
bufsize = 1000 + 200 * lpd->n;
if ((buf = (char *)LEPT_CALLOC(bufsize, sizeof(char))) == NULL)
return ERROR_INT("calloc fail for buf", procName, 1);
sa = sarrayCreate(lpd->n);
for (i = 0; i < lpd->n; i++) {
ptaGetPt(lpd->xy, i, &xpt, &ypt);
ptaGetPt(lpd->wh, i, &wpt, &hpt);
snprintf(buf, bufsize,
"q %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d Do Q\n",
wpt, 0.0, 0.0, hpt, xpt, ypt, i + 1);
sarrayAddString(sa, buf, L_COPY);
}
cstr = sarrayToString(sa, 0);
sarrayDestroy(&sa);
if (!cstr) {
LEPT_FREE(buf);
return ERROR_INT("cstr not made", procName, 1);
}
snprintf(buf, bufsize, "5 0 obj\n"
"<< /Length %d >>\n"
"stream\n"
"%s"
"endstream\n"
"endobj\n",
(l_int32)strlen(cstr), cstr);
lpd->obj5 = stringNew(buf);
l_dnaAddNumber(lpd->objsize, strlen(lpd->obj5));
sarrayDestroy(&sa);
LEPT_FREE(buf);
LEPT_FREE(cstr);
return 0;
}static l_int32
generatePreXStringsPdf(L_PDF_DATA *lpd)
{
char buff[256];
char buf[L_BIGBUF];
char *cstr, *bstr, *fstr, *pstr, *xstr;
l_int32 i, cmindex;
L_COMP_DATA *cid;
SARRAY *sa;
PROCNAME("generatePreXStringsPdf");
sa = lpd->saprex;
cmindex = 6 + lpd->n; /* starting value */
for (i = 0; i < lpd->n; i++) {
pstr = cstr = NULL;
if ((cid = pdfdataGetCid(lpd, i)) == NULL)
return ERROR_INT("cid not found", procName, 1);
if (cid->type == L_G4_ENCODE) {
if (var_WRITE_G4_IMAGE_MASK) {
cstr = stringNew("/ImageMask true\n"
"/ColorSpace /DeviceGray");
} else {
cstr = stringNew("/ColorSpace /DeviceGray");
}
bstr = stringNew("/BitsPerComponent 1\n"
"/Interpolate true");
snprintf(buff, sizeof(buff),
"/Filter /CCITTFaxDecode\n"
"/DecodeParms\n"
"<<\n"
"/K -1\n"
"/Columns %d\n"
">>", cid->w);
fstr = stringNew(buff);
} else if (cid->type == L_JPEG_ENCODE) {
if (cid->spp == 1)
cstr = stringNew("/ColorSpace /DeviceGray");
else if (cid->spp == 3)
cstr = stringNew("/ColorSpace /DeviceRGB");
else if (cid->spp == 4) /* pdf supports cmyk */
cstr = stringNew("/ColorSpace /DeviceCMYK");
else
L_ERROR("in jpeg: spp != 1, 3 or 4\n", procName);
bstr = stringNew("/BitsPerComponent 8");
fstr = stringNew("/Filter /DCTDecode");
} else if (cid->type == L_JP2K_ENCODE) {
if (cid->spp == 1)
cstr = stringNew("/ColorSpace /DeviceGray");
else if (cid->spp == 3)
cstr = stringNew("/ColorSpace /DeviceRGB");
else
L_ERROR("in jp2k: spp != 1 && spp != 3\n", procName);
bstr = stringNew("/BitsPerComponent 8");
fstr = stringNew("/Filter /JPXDecode");
} else { /* type == L_FLATE_ENCODE */
if (cid->ncolors > 0) { /* cmapped */
snprintf(buff, sizeof(buff), "/ColorSpace %d 0 R", cmindex++);
cstr = stringNew(buff);
} else {
if (cid->spp == 1 && cid->bps == 1)
cstr = stringNew("/ColorSpace /DeviceGray\n"
"/Decode [1 0]");
else if (cid->spp == 1) /* 8 bpp */
cstr = stringNew("/ColorSpace /DeviceGray");
else if (cid->spp == 3)
cstr = stringNew("/ColorSpace /DeviceRGB");
else
L_ERROR("unknown colorspace: spp = %d\n",
procName, cid->spp);
}
snprintf(buff, sizeof(buff), "/BitsPerComponent %d", cid->bps);
bstr = stringNew(buff);
fstr = stringNew("/Filter /FlateDecode");
if (cid->predictor == TRUE) {
snprintf(buff, sizeof(buff),
"/DecodeParms\n"
"<<\n"
" /Columns %d\n"
" /Predictor 14\n"
" /Colors %d\n"
" /BitsPerComponent %d\n"
">>\n", cid->w, cid->spp, cid->bps);
pstr = stringNew(buff);
}
}
if (!pstr) /* no decode parameters */
pstr = stringNew("");
snprintf(buf, sizeof(buf),
"%d 0 obj\n"
"<<\n"
"/Length %lu\n"
"/Subtype /Image\n"
"%s\n" /* colorspace */
"/Width %d\n"
"/Height %d\n"
"%s\n" /* bits/component */
"%s\n" /* filter */
"%s" /* decode parms; can be empty */
">>\n"
"stream\n",
6 + i, (unsigned long)cid->nbytescomp, cstr,
cid->w, cid->h, bstr, fstr, pstr);
xstr = stringNew(buf);
sarrayAddString(sa, xstr, L_INSERT);
l_dnaAddNumber(lpd->objsize,
strlen(xstr) + cid->nbytescomp + strlen(lpd->poststream));
LEPT_FREE(cstr);
LEPT_FREE(bstr);
LEPT_FREE(fstr);
LEPT_FREE(pstr);
}
return 0;
}static l_int32
generateColormapStringsPdf(L_PDF_DATA *lpd)
{
char buf[L_BIGBUF];
char *cmstr;
l_int32 i, cmindex, ncmap;
L_COMP_DATA *cid;
SARRAY *sa;
PROCNAME("generateColormapStringsPdf");
/* In our canonical format, we have 5 objects, followed
by n XObjects, followed by m colormaps, so the index of
the first colormap object is 6 + n. */
sa = lpd->sacmap;
cmindex = 6 + lpd->n; /* starting value */
ncmap = 0;
for (i = 0; i < lpd->n; i++) {
if ((cid = pdfdataGetCid(lpd, i)) == NULL)
return ERROR_INT("cid not found", procName, 1);
if (cid->ncolors == 0) continue;
ncmap++;
snprintf(buf, sizeof(buf), "%d 0 obj\n"
"[ /Indexed /DeviceRGB\n"
"%d\n"
"%s\n"
"]\n"
"endobj\n",
cmindex, cid->ncolors - 1, cid->cmapdatahex);
cmindex++;
cmstr = stringNew(buf);
l_dnaAddNumber(lpd->objsize, strlen(cmstr));
sarrayAddString(sa, cmstr, L_INSERT);
}
lpd->ncmap = ncmap;
return 0;
}static void
generateTrailerPdf(L_PDF_DATA *lpd)
{
l_int32 i, n, size, linestart;
L_DNA *daloc, *dasize;
/* Let nobj be the number of numbered objects. These numbered
objects are indexed by their pdf number in arrays naloc[]
and nasize[]. The 0th object is the 9 byte header. Then
the number of objects in nasize, which includes the header,
is n = nobj + 1. The array naloc[] has n + 1 elements,
because it includes as the last element the starting
location of xref. The indexing of these objects, their
starting locations and sizes are:
Object number Starting location Size
------------- ----------------- --------------
0 daloc[0] = 0 dasize[0] = 9
1 daloc[1] = 9 dasize[1] = 49
n daloc[n] dasize[n]
xref daloc[n+1]
We first generate daloc.
*/
dasize = lpd->objsize;
daloc = lpd->objloc;
linestart = 0;
l_dnaAddNumber(daloc, linestart); /* header */
n = l_dnaGetCount(dasize);
for (i = 0; i < n; i++) {
l_dnaGetIValue(dasize, i, &size);
linestart += size;
l_dnaAddNumber(daloc, linestart);
}
l_dnaGetIValue(daloc, n, &lpd->xrefloc); /* save it */
/* Now make the actual trailer string */
lpd->trailer = makeTrailerStringPdf(daloc);
}static char *
makeTrailerStringPdf(L_DNA *daloc)
{
char *outstr;
char buf[L_BIGBUF];
l_int32 i, n, linestart, xrefloc;
SARRAY *sa;
PROCNAME("makeTrailerStringPdf");
if (!daloc)
return (char *)ERROR_PTR("daloc not defined", procName, NULL);
n = l_dnaGetCount(daloc) - 1; /* numbered objects + 1 (yes, +1) */
sa = sarrayCreate(0);
snprintf(buf, sizeof(buf), "xref\n"
"0 %d\n"
"0000000000 65535 f \n", n);
sarrayAddString(sa, (char *)buf, L_COPY);
for (i = 1; i < n; i++) {
l_dnaGetIValue(daloc, i, &linestart);
snprintf(buf, sizeof(buf), "%010d 00000 n \n", linestart);
sarrayAddString(sa, (char *)buf, L_COPY);
}
l_dnaGetIValue(daloc, n, &xrefloc);
snprintf(buf, sizeof(buf), "trailer\n"
"<<\n"
"/Size %d\n"
"/Root 1 0 R\n"
"/Info 2 0 R\n"
">>\n"
"startxref\n"
"%d\n"
"%%%%EOF\n", n, xrefloc);
sarrayAddString(sa, (char *)buf, L_COPY);
outstr = sarrayToString(sa, 0);
sarrayDestroy(&sa);
return outstr;
}/*! generateOutputDataPdf()
| [out] | pdata | pdf data array |
| [out] | pnbytes | size of pdf data array |
| [in] | lpd | input data used to make pdf |
Notes:
(1) Only called from l_generatePdf(). On error, no data is returned.
Definition at line 2030 of file pdfio2.c.
References L_Pdf_Data::id, l_dnaGetIArray(), L_Pdf_Data::n, L_Pdf_Data::obj1, L_Pdf_Data::obj2, L_Pdf_Data::obj3, L_Pdf_Data::obj4, L_Pdf_Data::obj5, L_Pdf_Data::objloc, L_Pdf_Data::objsize, L_Pdf_Data::trailer, and L_Pdf_Data::xrefloc.
| void l_CIDataDestroy | ( | L_COMP_DATA ** | pcid | ) |
| [in,out] | pcid | will be set to null before returning |
Definition at line 1450 of file pdfio2.c.
References L_Compressed_Data::cmapdata85, L_Compressed_Data::cmapdatahex, L_Compressed_Data::data85, and L_Compressed_Data::datacomp.
Referenced by convertFlateToPSEmbed(), convertG4ToPSEmbed(), convertG4ToPSString(), convertJpegToPSEmbed(), and l_generateJp2kData().
| l_int32 l_generateCIData | ( | const char * | fname, |
| l_int32 | type, | ||
| l_int32 | quality, | ||
| l_int32 | ascii85, | ||
| L_COMP_DATA ** | pcid | ||
| ) |
| [in] | fname | |
| [in] | type | L_G4_ENCODE, L_JPEG_ENCODE, L_FLATE_ENCODE, L_JP2K_ENCODE |
| [in] | quality | used for jpeg only; 0 for default (75) |
| [in] | ascii85 | 0 for binary; 1 for ascii85-encoded |
| [out] | pcid | compressed data |
Notes:
(1) This can be used for both PostScript and pdf.
(1) Set ascii85:
~ 0 for binary data (not permitted in PostScript)
~ 1 for ascii85 (5 for 4) encoded binary data
(2) This attempts to compress according to the requested type.
If this can't be done, it falls back to ordinary flate encoding.
(3) This differs from l_generateCIDataPdf(), which determines
the format and attempts to generate the CID without transcoding.
Definition at line 917 of file pdfio2.c.
References L_FLATE_ENCODE, L_G4_ENCODE, L_JP2K_ENCODE, L_JPEG_ENCODE, and pixReadHeader().
| l_int32 l_generateCIDataForPdf | ( | const char * | fname, |
| PIX * | pix, | ||
| l_int32 | quality, | ||
| L_COMP_DATA ** | pcid | ||
| ) |
| [in] | fname | [optional]; can be null |
| [in] | pix | [optional]; can be null |
| [in] | quality | for jpeg if transcoded; 75 is standard |
| [out] | pcid | compressed data |
Notes:
(1) You must set either filename or pix.
(2) Given an image file and optionally a pix raster of that data,
this provides a CID that is compatible with PDF, preferably
without transcoding.
(3) The pix is included for efficiency, in case transcoding
is required and the pix is available to the caller.
(4) We don't try to open files named "stdin" or "-" for Tesseract
compatibility reasons. We may remove this restriction
in the future.
Definition at line 519 of file pdfio2.c.
References findFileFormat().
| L_COMP_DATA* l_generateFlateData | ( | const char * | fname, |
| l_int32 | ascii85flag | ||
| ) |
| [in] | fname | |
| [in] | ascii85flag | 0 for gzipped; 1 for ascii85-encoded gzipped |
Notes:
(1) The input image is converted to one of these 4 types:
~ 1 bpp
~ 8 bpp, no colormap
~ 8 bpp, colormap
~ 32 bpp rgb
(2) Set ascii85flag:
~ 0 for binary data (not permitted in PostScript)
~ 1 for ascii85 (5 for 4) encoded binary data
Definition at line 1086 of file pdfio2.c.
References pixDestroy(), pixGenerateFlateData(), and pixRead().
Referenced by convertFlateToPSEmbed(), and convertFlateToPSString().
| L_COMP_DATA* l_generateFlateDataPdf | ( | const char * | fname, |
| PIX * | pixs | ||
| ) |
| [in] | fname | preferably png |
| [in] | pixs | [optional]; can be null |
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.
Definition at line 597 of file pdfio2.c.
References findFileFormat().
| L_COMP_DATA* l_generateG4Data | ( | const char * | fname, |
| l_int32 | ascii85flag | ||
| ) |
| [in] | fname | of g4 compressed file |
| [in] | ascii85flag | 0 for g4 compressed; 1 for ascii85-encoded g4 |
Notes:
(1) Set ascii85flag:
~ 0 for binary data (not permitted in PostScript)
~ 1 for ascii85 (5 for 4) encoded binary data
(not permitted in pdf)
Definition at line 1324 of file pdfio2.c.
References L_Compressed_Data::bps, L_Compressed_Data::data85, L_Compressed_Data::datacomp, extractG4DataFromFile(), fopenReadStream(), getTiffResolution(), L_Compressed_Data::h, L_G4_ENCODE, L_Compressed_Data::minisblack, L_Compressed_Data::nbytes85, L_Compressed_Data::nbytescomp, L_Compressed_Data::res, L_Compressed_Data::spp, L_Compressed_Data::type, and L_Compressed_Data::w.
Referenced by convertG4ToPSEmbed(), and convertG4ToPSString().
|
static |
| [in] | fname | of jp2k file |
Notes:
(1) This is only called after the file is verified to be jp2k.
Definition at line 862 of file pdfio2.c.
References L_Compressed_Data::bps, L_Compressed_Data::datacomp, L_Compressed_Data::h, l_binaryRead(), l_CIDataDestroy(), L_JP2K_ENCODE, L_Compressed_Data::nbytescomp, readHeaderJp2k(), L_Compressed_Data::res, L_Compressed_Data::spp, L_Compressed_Data::type, and L_Compressed_Data::w.
| L_COMP_DATA* l_generateJpegData | ( | const char * | fname, |
| l_int32 | ascii85flag | ||
| ) |
| [in] | fname | of jpeg file |
| [in] | ascii85flag | 0 for jpeg; 1 for ascii85-encoded jpeg |
Notes:
(1) Set ascii85flag:
~ 0 for binary data (not permitted in PostScript)
~ 1 for ascii85 (5 for 4) encoded binary data
(not permitted in pdf)
Definition at line 792 of file pdfio2.c.
References fopenReadStream(), and freadHeaderJpeg().
Referenced by convertJpegToPSEmbed(), and convertJpegToPSString().
|
static |
| [out] | pdata | pdf array |
| [out] | pnbytes | number of bytes in pdf array |
| [in] | lpd | all the required input image data |
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 | ) |
| [in] | flag | 1 for writing date/time and leptonica version; 0 for omitting this from the metadata |
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 | ) |
| [in] | flag | 1 for writing g4 data as fg only through a mask; 0 for writing fg and bg |
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.
| [in] | bas | lba of a pdf file |
| [out] | pda | byte locations of the beginning of each object |
Definition at line 2106 of file pdfio2.c.
References arrayFindSequence(), l_byteaFindEachSequence(), l_byteaGetData(), l_dnaAddNumber(), l_dnaCreate(), l_dnaDestroy(), l_dnaEmpty(), l_dnaGetCount(), l_dnaGetIValue(), l_dnaWriteStream(), L_NOCOPY, sarrayCreateLinesFromString(), sarrayDestroy(), sarrayGetString(), and sarrayWriteStream().
Referenced by ptraConcatenatePdfToData().
| 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 | ||
| ) |
| [in] | pix | all depths; cmap OK |
| [in] | type | L_G4_ENCODE, L_JPEG_ENCODE, L_FLATE_ENCODE |
| [in] | quality | used for JPEG only; 0 for default (75) |
| [out] | pdata | pdf array |
| [out] | pnbytes | number of bytes in pdf array |
| [in] | 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) |
| [in] | res | override the resolution of the input image, in ppi; use 0 to respect the resolution embedded in the input |
| [in] | title | [optional] pdf title |
| [in,out] | plpd | ptr to lpd, which is created on the first invocation and returned until last image is processed |
| [in] | position | in image sequence: L_FIRST_IMAGE, L_NEXT_IMAGE, L_LAST_IMAGE |
Notes:
(1) If res == 0 and the input resolution field is 0,
this will use DEFAULT_INPUT_RES.
(2) This only writes data if it is the last image to be
written on the page.
(3) See comments in convertToPdf().
Definition at line 181 of file pdfio2.c.
References L_Compressed_Data::h, L_FIRST_IMAGE, pixGenerateCIData(), L_Compressed_Data::res, and L_Compressed_Data::w.
Referenced by convertImageDataToPdfData(), convertToPdfData(), pixaConvertToPdfData(), pixConvertToPdf(), and saConvertFilesToPdfData().
| l_int32 pixGenerateCIData | ( | PIX * | pixs, |
| l_int32 | type, | ||
| l_int32 | quality, | ||
| l_int32 | ascii85, | ||
| L_COMP_DATA ** | pcid | ||
| ) |
| [in] | pixs | 8 or 32 bpp, no colormap |
| [in] | type | L_G4_ENCODE, L_JPEG_ENCODE, L_FLATE_ENCODE |
| [in] | quality | used for jpeg only; 0 for default (75) |
| [in] | ascii85 | 0 for binary; 1 for ascii85-encoded |
| [out] | pcid | compressed data |
Notes:
(1) Set ascii85:
~ 0 for binary data (not permitted in PostScript)
~ 1 for ascii85 (5 for 4) encoded binary data
Definition at line 1013 of file pdfio2.c.
References L_FLATE_ENCODE, L_G4_ENCODE, and L_JPEG_ENCODE.
Referenced by pixConvertToPdfData().
|
static |
| [in] | pixs | |
| [in] | ascii85flag | 0 for gzipped; 1 for ascii85-encoded gzipped |
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. Definition at line 1120 of file pdfio2.c.
References pixGetDimensions().
Referenced by l_generateFlateData().
|
static |
| [in] | pixs | 1 bpp |
| [in] | ascii85flag | 0 for gzipped; 1 for ascii85-encoded gzipped |
Notes:
(1) Set ascii85flag:
~ 0 for binary data (not permitted in PostScript)
~ 1 for ascii85 (5 for 4) encoded binary data
|
static |
| [in] | pixs | 8 or 32 bpp, no colormap |
| [in] | ascii85flag | 0 for jpeg; 1 for ascii85-encoded jpeg |
| [in] | quality | 0 for default, which is 75 |
Notes:
(1) Set ascii85flag:
~ 0 for binary data (not permitted in PostScript)
~ 1 for ascii85 (5 for 4) encoded binary data
| l_int32 ptraConcatenatePdfToData | ( | L_PTRA * | pa_data, |
| SARRAY * | sa, | ||
| l_uint8 ** | pdata, | ||
| size_t * | pnbytes | ||
| ) |
| [in] | pa_data | ptra array of pdf strings, each for a single-page pdf file |
| [in] | sa | string array [optional] of pathnames for input pdf files |
| [out] | pdata | concatenated pdf data in memory |
| [out] | pnbytes | number of bytes in pdf data |
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.
Definition at line 306 of file pdfio2.c.
References l_byteaDestroy(), L_CLONE, l_dnaaAddDna(), l_dnaaCreate(), l_dnaaDestroy(), l_dnaaGetDna(), l_dnaDestroy(), l_dnaGetCount(), L_INSERT, L_NO_COMPACTION, L_NOCOPY, numaaAddNuma(), numaaCreate(), numaAddNumber(), numaCreate(), numaMakeConstant(), numaMakeSequence(), numaReplaceNumber(), numaSetValue(), parseTrailerPdf(), ptraCompactArray(), ptraGetActualCount(), ptraGetPtrToItem(), ptraRemove(), and sarrayGetString().
Referenced by convertSegmentedFilesToPdf(), pixaConvertToPdfData(), ptraConcatenatePdf(), saConcatenatePdfToData(), saConvertFilesToPdfData(), and saConvertUnscaledFilesToPdfData().
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.
Definition at line 2257 of file pdfio2.c.
References arrayFindEachSequence(), arrayFindSequence(), l_byteaAppendData(), l_byteaAppendString(), l_byteaCreate(), l_byteaGetData(), l_dnaDestroy(), l_dnaGetCount(), l_dnaGetIArray(), and numaGetIArray().
1.8.14