pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/graphics/xv



Module Name:    pkgsrc
Committed By:   tsutsui
Date:           Wed Aug 16 17:02:20 UTC 2023

Modified Files:
        pkgsrc/graphics/xv: Makefile distinfo
        pkgsrc/graphics/xv/patches: patch-Imakefile patch-xvwebp.c

Log Message:
xv: improve webp support, in a pkgsrc patch by me.

- minimum support for loading animation webp (decode only the first frame)
- handle RGBA images properly (libwebp APIs don't convert RGBA to RGB)
  https://bugs.chromium.org/p/webp/issues/detail?id=616
- plug several resouce leaks
- use snprintf(3) rather than sprintf(3)

Bump PKGREVISION.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 pkgsrc/graphics/xv/Makefile
cvs rdiff -u -r1.26 -r1.27 pkgsrc/graphics/xv/distinfo
cvs rdiff -u -r1.2 -r1.3 pkgsrc/graphics/xv/patches/patch-Imakefile
cvs rdiff -u -r1.1 -r1.2 pkgsrc/graphics/xv/patches/patch-xvwebp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/graphics/xv/Makefile
diff -u pkgsrc/graphics/xv/Makefile:1.98 pkgsrc/graphics/xv/Makefile:1.99
--- pkgsrc/graphics/xv/Makefile:1.98    Sun Jul 30 16:30:17 2023
+++ pkgsrc/graphics/xv/Makefile Wed Aug 16 17:02:19 2023
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.98 2023/07/30 16:30:17 tsutsui Exp $
+# $NetBSD: Makefile,v 1.99 2023/08/16 17:02:19 tsutsui Exp $
 
 DISTNAME=      xv-3.10a
-PKGREVISION=   27
+PKGREVISION=   28
 CATEGORIES=    graphics x11
 MASTER_SITES=  ftp://ftp.cis.upenn.edu/pub/xv/
 DISTFILES=     ${DEFAULT_DISTFILES} ${JUMBO_PATCHES}

Index: pkgsrc/graphics/xv/distinfo
diff -u pkgsrc/graphics/xv/distinfo:1.26 pkgsrc/graphics/xv/distinfo:1.27
--- pkgsrc/graphics/xv/distinfo:1.26    Sun Jul 30 07:55:44 2023
+++ pkgsrc/graphics/xv/distinfo Wed Aug 16 17:02:19 2023
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.26 2023/07/30 07:55:44 tsutsui Exp $
+$NetBSD: distinfo,v 1.27 2023/08/16 17:02:19 tsutsui Exp $
 
 BLAKE2s (xv-3.10a-enhancements.20070520-20081216.diff) = 1333e3066444f6adf64e83c33a129a46143678d4b2c805f3740baae1320d3449
 SHA512 (xv-3.10a-enhancements.20070520-20081216.diff) = d7152799f6ec65404496b8d83a93681122fe1280741ffe4d20d7dc1b3791873081c778b3d9806f1217b9d45f5b5bfce6fdbfb655c26ed5e87388a6f517c4f2f7
@@ -9,7 +9,7 @@ Size (xv-3.10a-jumbo-patches-20070520.ta
 BLAKE2s (xv-3.10a.tar.gz) = 1a48a6b641074c1fc1c51a01d6516024489ed0fab550abdd708f7d12aef8d292
 SHA512 (xv-3.10a.tar.gz) = 5b8c5890503e2796638921cabae8967e458c73e332acea8561b1025ed13c771bc44c0e309b4592852e33726eeaa9784f933d1312073b0ba2e0b8c0cedabcaa3f
 Size (xv-3.10a.tar.gz) = 2259124 bytes
-SHA1 (patch-Imakefile) = ea44bbda2a848a81fceac78d2f581269a053fb7f
+SHA1 (patch-Imakefile) = 908a3c30d1a1c08f91cf96362b3292f3ff795e13
 SHA1 (patch-bits_br__webp) = 47f2495f0e8d443e0e20b718593de331cf319dea
 SHA1 (patch-config.h) = fd0ef6bbf774a57dd0bb94676927dcc6eeef1014
 SHA1 (patch-vdcomp.c) = 4c603cdc2c01925fed283b2aa6030d1933cdaddc
@@ -22,4 +22,4 @@ SHA1 (patch-xvinfo.c) = 33b2392de259f138
 SHA1 (patch-xvmisc.c) = ad326175632736e2d6dd257972d8cba5b24635a3
 SHA1 (patch-xvpcd.c) = 1825015f441b9af91916f9a62e8d1dee6ddfdef9
 SHA1 (patch-xvpng.c) = 2bda08bae67fcf127c49b9ed780b7a247579c088
-SHA1 (patch-xvwebp.c) = ad2a1a87176ab099c8d3f51bf5d20e2bbe2faf2a
+SHA1 (patch-xvwebp.c) = 9bffcb775d641f50d778ad026cb66880b74e7462

Index: pkgsrc/graphics/xv/patches/patch-Imakefile
diff -u pkgsrc/graphics/xv/patches/patch-Imakefile:1.2 pkgsrc/graphics/xv/patches/patch-Imakefile:1.3
--- pkgsrc/graphics/xv/patches/patch-Imakefile:1.2      Sun Jul 30 07:55:45 2023
+++ pkgsrc/graphics/xv/patches/patch-Imakefile  Wed Aug 16 17:02:20 2023
@@ -1,4 +1,4 @@
-$NetBSD: patch-Imakefile,v 1.2 2023/07/30 07:55:45 tsutsui Exp $
+$NetBSD: patch-Imakefile,v 1.3 2023/08/16 17:02:20 tsutsui Exp $
 
 - use jpeg, png, tiff, and zlib from pkgsrc
 - make ghostscript support optional
@@ -6,7 +6,7 @@ $NetBSD: patch-Imakefile,v 1.2 2023/07/3
   https://gitlab.com/DavidGriffith/xv/-/commit/5682a07e
   and use libwebp from pkgsrc
 
---- Imakefile.orig     2023-07-30 04:38:19.657014071 +0000
+--- Imakefile.orig     2023-08-16 16:51:48.939703880 +0000
 +++ Imakefile
 @@ -6,13 +6,20 @@
  /* if, for whatever reason, you're unable to get the JPEG library to compile
@@ -49,7 +49,7 @@ $NetBSD: patch-Imakefile,v 1.2 2023/07/3
 +#ifdef HaveWEBP
 +WEBP = -DDOWEBP
 +WEBPDIR = /usr
-+LIBWEBP = $(WEBPDIR)/lib/libwebp.so
++LIBWEBP = $(WEBPDIR)/lib/libwebp.so $(WEBPDIR)/lib/libwebpdemux.so
 +DEPLIBWEBP = $(LIBWEBP)
 +WEBPINCLUDE = -I$(WEBPDIR)/include
 +#endif
@@ -58,7 +58,7 @@ $NetBSD: patch-Imakefile,v 1.2 2023/07/3
 -
 +#ifdef UseInstalledWEBP
 +WEBP = -DDOWEBP
-+LIBWEBP = $(LDFLAGS) -L$(PREFIX)/lib -Wl,-R$(PREFIX)/lib -lwebp
++LIBWEBP = $(LDFLAGS) -L$(PREFIX)/lib -Wl,-R$(PREFIX)/lib -lwebp -lwebpdemux
 +WEBPINCLUDE = -I$(PREFIX)/include
 +#endif
  

Index: pkgsrc/graphics/xv/patches/patch-xvwebp.c
diff -u pkgsrc/graphics/xv/patches/patch-xvwebp.c:1.1 pkgsrc/graphics/xv/patches/patch-xvwebp.c:1.2
--- pkgsrc/graphics/xv/patches/patch-xvwebp.c:1.1       Sun Jul 30 07:55:45 2023
+++ pkgsrc/graphics/xv/patches/patch-xvwebp.c   Wed Aug 16 17:02:20 2023
@@ -1,14 +1,19 @@
-$NetBSD: patch-xvwebp.c,v 1.1 2023/07/30 07:55:45 tsutsui Exp $
+$NetBSD: patch-xvwebp.c,v 1.2 2023/08/16 17:02:20 tsutsui Exp $
 
 - add webp support from forked upstream
   https://gitlab.com/DavidGriffith/xv/-/commit/5682a07e
  - the default quality value is changed to 75 as the original libwebp
  - the default "page" of quality qDial is changed to 5.0 as jpeg
  - fix a bug of wrong quality value (almost 0) passed to WebPEncodeRGB()
+ - minimum support for loading animation webp (decode only the first frame)
+ - handle RGBA images properly (libwebp APIs don't convert RGBA to RGB)
+   https://bugs.chromium.org/p/webp/issues/detail?id=616
+ - plug several resouce leaks
+ - use snprintf(3) rather than sprintf(3)
 
---- xvwebp.c.orig      2023-07-30 06:56:45.683695531 +0000
+--- xvwebp.c.orig      2023-08-16 16:22:28.293425514 +0000
 +++ xvwebp.c
-@@ -0,0 +1,420 @@
+@@ -0,0 +1,525 @@
 +/*
 + * xvwebp.c - load routine for 'webp' format pictures
 + *
@@ -27,6 +32,7 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +#include <webp/types.h>
 +#include <webp/encode.h>
 +#include <webp/decode.h>
++#include <webp/demux.h>
 +
 +static char *filename;
 +static const char *bname;
@@ -34,6 +40,8 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +static void drawWEBPD   PARM((int, int, int, int));
 +static void clickWEBPD  PARM((int, int));
 +static void doCmd       PARM((int));
++static void convertRGBA PARM((const byte * const, byte * const,
++                                    int, int, int, int));
 +static void writeWEBP   PARM((void));
 +static int  WriteWEBP   PARM((FILE *, byte *, int, int, int,
 +                                    byte *, byte *, byte *));
@@ -45,6 +53,10 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +
 +#define QUALITY   75     /* default quality */
 +
++#define RGBATORGB(rgb, bg, alpha) \
++      (((rgb) * (alpha) / 255) + ((bg) * (255 - (alpha)) / 255))
++#define TRANSBG   0xE1   /* default background color to convert alpha channel */
++
 +#define DWIDE    86
 +#define DHIGH    104
 +
@@ -201,7 +213,7 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +
 +  DrawString(webpW,       15,  6+ASCENT,                          title);
 +
-+  sprintf(ctitle1, "Default = %d", QUALITY);
++  snprintf(ctitle1, 20, "Default = %d", QUALITY);
 +  DrawString(webpW,      110,  6+qDial.y+ASCENT,            ctitle1);
 +  DrawString(webpW,      110,  6+qDial.y+ASCENT+LINEHIGH,   ctitle2);
 +  DrawString(webpW,      110,  6+qDial.y+ASCENT+2*LINEHIGH, ctitle3);
@@ -277,6 +289,32 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +}
 +
 +/*******************************************/
++static void convertRGBA(rgba, rgb, width, height, stride, bgcolor)
++     const byte * const rgba; /* input loaded RGBA buffer */
++     byte * const rgb;  /* output xv pic RGB buffer */
++     int width;         /* image width */
++     int height;        /* image height */
++     int stride;        /* input image stride */
++     int bgcolor;       /* background color for alpha channel conversion */
++{
++  const byte *rgbap;
++  byte *rgbp;
++  int x, y;
++
++  rgbp = rgb;
++  for (y = 0; y < height; y++) {
++    rgbap = rgba + y * stride;
++    for (x = 0; x < width; x++) {
++      int alpha = rgbap[3];
++      *rgbp++ = RGBATORGB(rgbap[0], bgcolor, alpha); /* convert R */
++      *rgbp++ = RGBATORGB(rgbap[1], bgcolor, alpha); /* convert G */
++      *rgbp++ = RGBATORGB(rgbap[2], bgcolor, alpha); /* convert B */
++      rgbap += 4; /* skip A */
++    }
++  }
++}
++
++/*******************************************/
 +int LoadWEBP(fname, pinfo)
 +     char    *fname;
 +     PICINFO *pinfo;
@@ -285,9 +323,11 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +  /* returns '1' on success */
 +
 +  FILE  *fp;
-+  int   c, w, h;
-+  size_t filesize;
++  int   c, w, h, stride;
++  size_t filesize, picsize;
 +  byte  *filebuf, *pic24;
++  WebPDecoderConfig config;
++  VP8StatusCode status;
 +
 +  bname = BaseName(fname);
 +
@@ -316,16 +356,84 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +  filebuf = (byte *) calloc((size_t) filesize, (size_t) 1);
 +  if (!filebuf) FatalError("couldn't malloc 'file buffer'");
 +  c = fread(filebuf, (size_t) 1, (size_t) filesize, fp);
++  fclose(fp);
 +  if (c != filesize) {
 +    SetISTR(ISTR_WARNING,"%s:  %s", bname, "file read error");
++    free(filebuf);
++    return 0;
 +  }
-+  fclose(fp);
-+  pic24 = WebPDecodeRGB(filebuf, (size_t)filesize, &w, &h);
-+  free(filebuf);
-+  if (pic24 == NULL) {
-+     SetISTR(ISTR_WARNING,"%s:  %s", bname, "WebP decode failed");
-+     return 0;
++
++  WebPInitDecoderConfig(&config);
++  if (WebPGetFeatures(filebuf, filesize, &config.input) != VP8_STATUS_OK) {
++    SetISTR(ISTR_WARNING,"%s:  %s", bname, "WebP get features failed");
++    free(filebuf);
++    return 0;
++  }
++  w = config.input.width;
++  h = config.input.height;
++  stride = w * 3;
++  picsize = stride * h;
++  pic24 = calloc((size_t)picsize, (size_t)1);
++  if (!pic24) FatalError("couldn't malloc 'image buffer'");
++
++  if (config.input.has_animation != 0) {
++    /* decode the first frame of animation webp */
++    WebPAnimDecoderOptions opts;
++    WebPData webpdata;
++    WebPAnimDecoder* dec;
++    WebPAnimInfo ainfo;
++    int timestamp, x, y, astride;
++    byte *rgbabuf;
++
++    WebPAnimDecoderOptionsInit(&opts);
++    opts.color_mode = MODE_RGBA;
++    webpdata.bytes = filebuf;
++    webpdata.size = filesize;
++    dec = WebPAnimDecoderNew(&webpdata, &opts);
++    if (dec == NULL) {
++      SetISTR(ISTR_WARNING,"%s:  %s", bname, "WebPAnimDecoderNew failed");
++      free(pic24);
++      free(filebuf);
++      return 0;
++    }
++    if (WebPAnimDecoderGetInfo(dec, &ainfo) &&
++        WebPAnimDecoderHasMoreFrames(dec) &&
++        WebPAnimDecoderGetNext(dec, &rgbabuf, &timestamp)) {
++      astride = w * 4;
++      convertRGBA(rgbabuf, pic24, w, h, astride, TRANSBG);
++    } else {
++      SetISTR(ISTR_WARNING,"%s:  %s", bname, "WebPAnimDecoder failed");
++      WebPAnimDecoderDelete(dec);
++      free(pic24);
++      free(filebuf);
++      return 0;
++    }
++    WebPAnimDecoderDelete(dec);
++  } else {
++    /* decode RGBA image and convert it to RGB with TRANSBG background */
++    int x, y, rgbasize, astride;
++    byte *rgbabuf;
++    astride = w * 4;
++    rgbasize = astride * h;
++    rgbabuf = calloc((size_t)rgbasize, (size_t)1);
++    config.output.colorspace = MODE_RGBA;
++    config.output.is_external_memory = 1;
++    config.output.u.RGBA.rgba = rgbabuf;
++    config.output.u.RGBA.size = rgbasize;
++    config.output.u.RGBA.stride = astride;
++    status = WebPDecode(filebuf, (size_t)filesize, &config);
++    if (status != VP8_STATUS_OK) {
++      SetISTR(ISTR_WARNING,"%s:  %s", bname, "WebPDecode failed");
++      free(pic24);
++      free(rgbabuf);
++      free(filebuf);
++      return 0;
++    }
++    convertRGBA(rgbabuf, pic24, w, h, astride, TRANSBG);
++    free(rgbabuf);
++    WebPFreeDecBuffer(&config.output);
 +  }
++  free(filebuf);
 +
 +  pinfo->pic     = pic24;
 +  pinfo->type    = PIC24;
@@ -333,8 +441,10 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +  pinfo->h       = h;
 +  pinfo->normw = pinfo->w;   pinfo->normh = pinfo->h;
 +  pinfo->frmType = F_WEBP;
-+  sprintf(pinfo->fullInfo,"WEBP, RGB. (%ld bytes)", filesize);
-+  sprintf(pinfo->shrtInfo,"%dx%d WEBP.", w,h);
++  snprintf(pinfo->fullInfo, 128, "WEBP%s, RGB%s. (%ld bytes)",
++    config.input.has_animation != 0 ? " (with animation)" : "",
++    config.input.has_alpha != 0 ? "A" : "", filesize);
++  snprintf(pinfo->shrtInfo, 128, "%dx%d WEBP.", w,h);
 +  pinfo->colType = F_FULLCOLOR;
 +
 +  return 1;
@@ -408,12 +518,12 @@ $NetBSD: patch-xvwebp.c,v 1.1 2023/07/30
 +  }
 +  if (pfree == 1) { free(pic); }
 +  if (outsize <= 0) {
-+    free(xpic);
++    WebPFree(xpic);
 +    return -1;
 +  }
 +  fwrite(xpic, outsize, 1, fp);
 +  SetCursors(-1);
-+  free(xpic);
++  WebPFree(xpic);
 +  if (ferror(fp)) return -1;
 +  return 0;
 +}



Home | Main Index | Thread Index | Old Index