From d5ea1db60fe0c215fcb8201a1ee1a3fe8986917b Mon Sep 17 00:00:00 2001 From: danblooomberg Date: Sat, 11 Jan 2025 20:28:45 -0800 Subject: [PATCH] Use lossy dct encoding in convertToPSEmbed() for input webp compressed file * Previously it defaulted to lossless flate encoding --- src/psio1.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/psio1.c b/src/psio1.c index 8cfb0d9e8..83a77a4e8 100644 --- a/src/psio1.c +++ b/src/psio1.c @@ -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 @@ -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; @@ -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);