/* read image parameters and fill JPEG struct*/
if (!AnalyzeJPEG(JPEG)) {
fprintf(stderr, "Error: '%s' is not a proper JPEG file!\n", JPEG->filename);
return;
}
if (!quiet)
fprintf(stderr, "Note on file '%s': %dx%d pixel, %d color component%s\n",
JPEG->filename, JPEG->width, JPEG->height, JPEG->components,
(JPEG->components == 1 ? "" : "s"));
/* "Use resolution from file" was requested, but we couldn't find any */
if (JPEG->dpi == DPI_USE_FILE && !quiet) {
fprintf(stderr,
"Note: no resolution values found in JPEG file - using standard scaling.\n");
JPEG->dpi = DPI_IGNORE;
}
if (JPEG->dpi == DPI_IGNORE) {
if (JPEG->width > JPEG->height && autorotate) { /* switch to landscape if needed */
JPEG->landscape = TRUE;
if (!quiet)
fprintf(stderr,
"Note: image width exceeds height - producing landscape output!\n");
}
if (!JPEG->landscape) { /* calculate scaling factors */
sx = (float) (PageWidth - 2*Margin) / JPEG->width;
sy = (float) (PageHeight - 2*Margin) / JPEG->height;
}else {
sx = (float) (PageHeight - 2*Margin) / JPEG->width;
sy = (float) (PageWidth - 2*Margin) / JPEG->height;
}
scale = min(sx, sy); /* We use at least one edge of the page */
} else {
if (!quiet)
fprintf(stderr, "Note: Using resolution %d dpi.\n", (int) JPEG->dpi);
scale = 72 / JPEG->dpi; /* use given image resolution */
}
/* workaround for color-inverted CMYK files produced by Adobe Photoshop:
* compensate for the color inversion in the PostScript code
*/
if (JPEG->adobe && JPEG->components == 4) {
if (!quiet)
fprintf(stderr, "Note: Adobe-conforming CMYK file - applying workaround for color inversion.\n");
fprintf(PSfile, " /Decode [1 0 1 0 1 0 1 0]\n");
}else {
fprintf(PSfile, " /Decode [0 1");
for (i = 1; i < JPEG->components; i++)
fprintf(PSfile," 0 1");
fprintf(PSfile, "]\n");
}
/* seek to start position of JPEG data */
fseek(JPEG->fp, JPEG->startpos, SEEK_SET);
switch (JPEG->mode) {
case BINARY:
/* important: ONE blank and NO newline */
fprintf(PSfile, " ");
#ifdef DOS
fflush(PSfile); /* up to now we have CR/NL mapping */
setmode(fileno(PSfile), O_BINARY); /* continue in binary mode */
#endif
/* copy data without change */
while ((n = fread(buffer, 1, sizeof(buffer), JPEG->fp)) != 0)
fwrite(buffer, 1, n, PSfile);
#ifdef DOS
fflush(PSfile); /* binary yet */
setmode(fileno(PSfile), O_TEXT); /* text mode */
#endif
break;
case ASCII85:
fprintf(PSfile, "\n");
/* ASCII85 representation of image data */
if (ASCII85Encode(JPEG->fp, PSfile)) {
fprintf(stderr, "Error: internal problems with ASCII85Encode!\n");
exit(1);
}
break;
case ASCIIHEX:
/* hex representation of image data (useful for buggy dvips) */
ASCIIHexEncode(JPEG->fp, PSfile);
break;
}
fprintf(PSfile, "\n%%%%EOF\n");
}
static
void usage P0(void) {
fprintf(stderr, "jpeg2ps %s: convert JPEG files to PostScript Level 2.\n",
VERSION);
fprintf(stderr, "(C) Thomas Merz 1994-1999\n\n");
fprintf(stderr, "usage: jpeg2ps [options] jpegfile > epsfile\n");
fprintf(stderr, "-a auto rotate: produce landscape output if width > height\n");
fprintf(stderr, "-b binary mode: output 8 bit data (default: 7 bit with ASCII85)\n");
fprintf(stderr, "-h hex mode: output 7 bit data in ASCIIHex encoding\n");
fprintf(stderr, "-o <name> output file name\n");
fprintf(stderr, "-p <size> page size name. Known names are:\n");
fprintf(stderr, " a0, a1, a2, a3, a4, a5, a6, b5, letter, legal, ledger, p11x17\n");
fprintf(stderr, "-q quiet mode: suppress all informational messages\n");
fprintf(stderr, "-r <dpi> resolution value (dots per inch)\n");
fprintf(stderr, " 0 means use value given in file, if any (disables autorotate)\n");
exit(1);
}
int
main P2(int, argc, char **, argv) {
imagedata image;
FILE *outfile;
#ifdef MAC
int i, bufLength;
char *cp, outfilename[512];
#else
int opt, pagesizeindex = -1;
#endif