Skip to content

Commit

Permalink
Use lossy dct encoding in convertToPSEmbed() for input webp compresse…
Browse files Browse the repository at this point in the history
…d file

* Previously it defaulted to lossless flate encoding
  • Loading branch information
DanBloomberg committed Jan 12, 2025
1 parent efb42ed commit d5ea1db
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/psio1.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ l_int32 resb, resc, endpage, maskop, ret;
* a bounding box, from any input image file.
* (2) Do the best job of compression given the specified level.
* %level=3 does flate compression on anything that is not
* tiffg4 (1 bpp) or jpeg (8 bpp or rgb).
* tiffg4 (1 bpp), jpeg (8 bpp or rgb), or webp.
* (3) If %level=2 and the file is not tiffg4 or jpeg, it will
* first be written to file as jpeg with quality = 75.
* This will remove the colormap and cause some degradation
Expand All @@ -813,7 +813,7 @@ convertToPSEmbed(const char *filein,
const char *fileout,
l_int32 level)
{
char *tname;
char *tname, *tmpfile, *basename;
l_int32 d, format;
PIX *pix, *pixs;

Expand Down Expand Up @@ -844,6 +844,21 @@ PIX *pix, *pixs;
return 1;
}

/* If level 3 and in webp format, convert to jpeg
* and use dct encoding */
if (level == 3 && format == IFF_WEBP) {
pix = pixRead(filein);
splitPathAtExtension(filein, &basename, NULL);
tmpfile = stringJoin(basename, ".tmpjpg");
pixWrite(tmpfile, pix, IFF_JFIF_JPEG);
convertJpegToPSEmbed(tmpfile, fileout);
pixDestroy(&pix);
lept_rmfile(tmpfile);
LEPT_FREE(tmpfile);
LEPT_FREE(basename);
return 0;
}

/* If level 3, flate encode. */
if (level == 3) {
convertFlateToPSEmbed(filein, fileout);
Expand Down

0 comments on commit d5ea1db

Please sign in to comment.