git: c2069505c562 - main - graphics/xv: update to 4.2.0
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 26 Nov 2023 15:04:30 UTC
The branch main has been updated by dinoex:
URL: https://cgit.FreeBSD.org/ports/commit/?id=c2069505c56276c241be5551055b82d82067c5b7
commit c2069505c56276c241be5551055b82d82067c5b7
Author: Dirk Meyer <dinoex@FreeBSD.org>
AuthorDate: 2023-11-26 15:04:03 +0000
Commit: Dirk Meyer <dinoex@FreeBSD.org>
CommitDate: 2023-11-26 15:04:03 +0000
graphics/xv: update to 4.2.0
---
graphics/xv/Makefile | 58 +-
graphics/xv/distinfo | 9 +-
graphics/xv/files/patch-Imakefile | 126 --
graphics/xv/files/patch-config.h | 63 +-
graphics/xv/files/patch-xv.h | 10 +-
graphics/xv/files/patch-xvevent.c | 6 +-
graphics/xv/files/patch-xvgif.c | 12 +-
graphics/xv/files/patch-xvinfo.c | 11 -
graphics/xv/files/patch-xvjp2k.c | 2377 -------------------------------------
graphics/xv/files/patch-xvjpeg.c | 9 +-
graphics/xv/files/patch-xvmisc.c | 9 +-
graphics/xv/files/patch-xvpng.c | 509 --------
graphics/xv/files/patch-xvtext.c | 6 +-
graphics/xv/files/patch-xvvd.c | 14 +-
graphics/xv/pkg-descr | 2 -
graphics/xv/pkg-plist | 290 ++++-
16 files changed, 334 insertions(+), 3177 deletions(-)
diff --git a/graphics/xv/Makefile b/graphics/xv/Makefile
index eacddcdec1cb..ead1b403f35f 100644
--- a/graphics/xv/Makefile
+++ b/graphics/xv/Makefile
@@ -1,27 +1,24 @@
PORTNAME= xv
-PORTVERSION= 3.10a
-PORTREVISION= 22
+PORTVERSION= 4.2.0
+DISTVERSIONPREFIX= v
+PORTREVISION= 0
CATEGORIES+= graphics
-MASTER_SITES= ftp://ftp.cis.upenn.edu/pub/xv/:base \
- SF/png-mng/XV%20jumbo%20patches/20070520
-
-DISTFILES= ${DISTNAME}${EXTRACT_SUFX}:base \
- ${DISTNAME}-jumbo-patches-20070520.tar.gz
DIST_SUBDIR= ${PORTNAME}
-PATCH_SITES= http://www.gregroelofs.com/code/
-PATCHFILES= xv-3.10a-enhancements.20070520-20081216.diff
-
MAINTAINER?= dinoex@FreeBSD.org
COMMENT?= X11 program that displays images of various formats
WWW= http://www.trilon.com/xv/
LIB_DEPENDS= libtiff.so:graphics/tiff \
libpng.so:graphics/png \
- libjasper.so:graphics/jasper
+ libjasper.so:graphics/jasper \
+ libwebp.so:graphics/webp
+
+USES= cpe localbase cmake jpeg xorg
+USE_XORG= xext x11 xt ice sm
-USES= cpe imake jpeg xorg
-USE_XORG= xext x11 xt
+USE_GITHUB= yes
+GH_ACCOUNT= jasper-software
CPE_VENDOR= xv_project
@@ -30,43 +27,22 @@ M17N_DESC= build with Multilingualization support
.include <bsd.port.options.mk>
-.if defined(CC) && ${CC:T:Mclang}
-# Optimizer crashes with
-# Assertion failed: (isPtrIV == IndVar->getType()->isPointerTy() && "IndVar type must match IVInit type")
-CFLAGS:= ${CFLAGS:S/-O2//g}
-.endif
-
.if ${PORT_OPTIONS:MM17N}
-MAKE_ENV= LOCALE_EXTENSION=-DTV_MULTILINGUAL
+CFLAGS+= -DTV_MULTILINGUAL
DESCR= ${FILESDIR}/pkg-descr
CONFLICTS_INSTALL= xv
.else
CONFLICTS_INSTALL= xv-m17n
.endif
-pre-patch:
- ${PATCH} -d ${PATCH_WRKSRC} ${PATCH_ARGS} -p1 < ${WRKDIR}/xv-3.10a-jumbo-fix-enh-patch-20070520.txt
+XV_DOCS= README.md src/docs/help
-post-patch:
- ${REINPLACE_CMD} -e "s@%%LOCALBASE%%@${LOCALBASE}@" \
- ${WRKSRC}/config.h
-.for i in bggen.1 vdcomp.1 xcmap.1 xv.1 xvp2p.1
- ${CP} ${WRKSRC}/docs/${i:R}.man ${WRKSRC}
+do-install-DOCS-on:
+.for i in ${XV_DOCS}
+ ${INSTALL_DATA} ${WRKSRC}/${i} ${STAGEDIR}${DOCSDIR}/
.endfor
-post-install:
-.if ${PORT_OPTIONS:MDOCS}
- ${MKDIR} ${STAGEDIR}${DOCSDIR}
- ${INSTALL_DATA} ${WRKSRC}/README ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/README.jumbo ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/README.pcd ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/docs/epsf.ps ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/docs/xpm.ps ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/docs/xvdocs.ps ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/docs/xvtitle.ps ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/docs/help ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/docs/bmp.doc ${STAGEDIR}${DOCSDIR}/
- ${INSTALL_DATA} ${WRKSRC}/docs/gif* ${STAGEDIR}${DOCSDIR}/
-.endif
+do-install-DOCS-off:
+ ${RM} -fr ${STAGEDIR}${DOCSDIR}/
.include <bsd.port.mk>
diff --git a/graphics/xv/distinfo b/graphics/xv/distinfo
index b592830be19a..c11f79e98b2d 100644
--- a/graphics/xv/distinfo
+++ b/graphics/xv/distinfo
@@ -1,6 +1,3 @@
-SHA256 (xv/xv-3.10a.tar.gz) = 03eb26b1e8f315c3093f4ae794862ba46637d16c055e8efbe5e3beb5d40fc451
-SIZE (xv/xv-3.10a.tar.gz) = 2259124
-SHA256 (xv/xv-3.10a-jumbo-patches-20070520.tar.gz) = 221ec89fdf0772bd09c845cbb337aecf411a1aee215140b676717f49e9e65c80
-SIZE (xv/xv-3.10a-jumbo-patches-20070520.tar.gz) = 1363802
-SHA256 (xv/xv-3.10a-enhancements.20070520-20081216.diff) = c47aa52b7dbf2e09896d3eba6411d78a56162a4b966197e40115c14d88c2e1eb
-SIZE (xv/xv-3.10a-enhancements.20070520-20081216.diff) = 8847
+TIMESTAMP = 1700942420
+SHA256 (xv/jasper-software-xv-v4.2.0_GH0.tar.gz) = 2871338c517a7444fc9d6a3d146bc2c5c7bd98b50c83369b24d24ad49fa0ab87
+SIZE (xv/jasper-software-xv-v4.2.0_GH0.tar.gz) = 5381969
diff --git a/graphics/xv/files/patch-Imakefile b/graphics/xv/files/patch-Imakefile
deleted file mode 100644
index dfdd490eb661..000000000000
--- a/graphics/xv/files/patch-Imakefile
+++ /dev/null
@@ -1,126 +0,0 @@
---- Imakefile.orig 2009-05-17 15:02:50.000000000 +0200
-+++ Imakefile 2009-05-17 15:05:52.000000000 +0200
-@@ -6,13 +6,15 @@
- /* if, for whatever reason, you're unable to get the JPEG library to compile
- * on your machine, *COMMENT OUT* the following line
- */
--#define HaveJpeg
-+/* #define HaveJpeg */
-+#define UseInstalledJpeg
-
-
- /* if, for whatever reason, you're unable to get the TIFF library to compile
- * on your machine, *COMMENT OUT* the following line
- */
--#define HaveTiff
-+/* #define HaveTiff */
-+#define UseInstalledTiff
-
-
- /* if, for whatever reason, you're unable to get the PDS/VICAR support
-@@ -124,20 +126,48 @@
- JPEG = -DDOJPEG
- JPEGDIR = jpeg
- LIBJPEG = $(JPEGDIR)/libjpeg.a
-+DEPLIBJPEG = $(LIBJPEG)
- JPEGINCLUDE = -I$(JPEGDIR)
- #endif
-
-+#ifdef UseInstalledJpeg
-+JPEG = -DDOJPEG
-+LIBJPEG = -L${LOCALBASE}/lib -ljpeg
-+JPEGINCLUDE = -I${LOCALBASE}/include
-+#endif
-+
- #ifdef HaveTiff
- TIFF = -DDOTIFF
- TIFFDIR = tiff
- LIBTIFF = $(TIFFDIR)/libtiff.a
-+DEPLIBTIFF = $(LIBTIFF)
- TIFFINCLUDE = -I$(TIFFDIR)
- #endif
-
-+#ifdef UseInstalledTiff
-+TIFF = -DDOTIFF -DUSE_TILED_TIFF_BOTLEFT_FIX -DOG3
-+LIBTIFF = -L${LOCALBASE}/lib -ltiff
-+TIFFINCLUDE = -I${LOCALBASE}/include
-+#endif
-+
- #ifdef HavePDS
- PDS = -DDOPDS
- #endif
-
-+PNG = -DDOPNG
-+PNGINC = -I${LOCALBASE}/include
-+PNGLIB = -L${LOCALBASE}/lib -lpng
-+
-+JP2K = -DDOJP2K
-+JP2KINC = -I${LOCALBASE}/include
-+JP2KLIB = -L${LOCALBASE}/lib -ljasper
-+
-+ZLIBDIR = /usr
-+ZLIBINC = -I$(ZLIBDIR)/include
-+ZLIBLIB = -L$(ZLIBDIR)/lib -lz
-+
-+DOCDIR = -L${PREFIX}/share/doc/xv
-+SYSCONFDIR = ${PREFIX}/etc/
-
- #if defined(SCOArchitecture)
- SCO= -Dsco -DPOSIX -DNO_RANDOM
-@@ -149,14 +179,17 @@
- #endif
-
-
--DEPLIBS = $(LIBJPEG) $(LIBTIFF)
--LOCAL_LIBRARIES = $(XLIB) $(DEPLIBS)
-+DEPLIBS = $(DEPLIBJPEG) $(DEPLIBTIFF)
-+LOCAL_LIBRARIES = $(XLIB) $(LIBJPEG) $(LIBTIFF) ${PNGLIB} ${JP2KLIB} ${ZLIBLIB}
-
- DEFINES= $(SCO) $(UNIX) $(NODIRENT) $(VPRINTF) $(TIMERS) \
- $(HPUX7) $(JPEG) $(TIFF) $(PDS) $(DXWM) $(RAND) \
-- $(BACKING_STORE) $(BSDTYPES) $(SGI) $(MGCSFX)
-+ ${PNG} ${JP2K} $(TVL10N) \
-+ -DDOCDIR=\"$(DOCDIR)\" \
-+ -DSYSCONFDIR=\"$(SYSCONFDIR)\" \
-+ $(BACKING_STORE) $(BSDTYPES) $(SGI) $(MGCSFX) $(LOCALE_EXTENSION)
-
--INCLUDES = $(JPEGINCLUDE) $(TIFFINCLUDE)
-+INCLUDES = $(JPEGINCLUDE) $(TIFFINCLUDE) ${PNGINC} ${JP2KINC} ${ZLIBINC}
-
- SRCS1 = xv.c xvevent.c xvroot.c xvmisc.c xvimage.c xvcolor.c xvsmooth.c \
- xv24to8.c xvgif.c xvpm.c xvinfo.c xvctrl.c xvscrl.c xvalg.c \
-@@ -166,7 +199,7 @@
- xvbrowse.c xvtext.c xvpcx.c xviff.c xvtarga.c xvxpm.c xvcut.c \
- xvxwd.c xvfits.c xvpng.c xvzx.c xvwbmp.c xvpcd.c \
- xvmag.c xvpic.c xvmaki.c xvpi.c xvpic2.c xvvd.c xvmgcsfx.c \
-- xvml.c
-+ xvml.c xvjp2k.c xvhips.c
-
- OBJS1 = xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
- xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvscrl.o xvalg.o \
-@@ -176,7 +209,7 @@
- xvbrowse.o xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcut.o \
- xvxwd.o xvfits.o xvpng.o xvzx.o xvwbmp.o xvpcd.o \
- xvmag.o xvpic.o xvmaki.o xvpi.o xvpic2.o xvvd.o xvmgcsfx.o \
-- xvml.o
-+ xvml.o xvjp2k.o xvhips.o
-
- SRCS2= bggen.c
- OBJS2= bggen.o
-@@ -271,11 +304,11 @@
- #endif
-
-
--InstallManPageLong(docs/xv,$(MANDIR),xv)
--InstallManPageLong(docs/bggen,$(MANDIR),bggen)
--InstallManPageLong(docs/xcmap,$(MANDIR),xcmap)
--InstallManPageLong(docs/xvp2p,$(MANDIR),xvpictoppm)
--InstallManPageLong(docs/vdcomp,$(MANDIR),vdcomp)
-+InstallManPage(xv,$(MANDIR))
-+InstallManPage(bggen,$(MANDIR))
-+InstallManPage(xcmap,$(MANDIR))
-+InstallManPage(xvp2p,$(MANDIR))
-+InstallManPage(vdcomp,$(MANDIR))
-
- InstallNonExecFile(xv_mgcsfx.sample,$(MGCSFXDIR))
-
diff --git a/graphics/xv/files/patch-config.h b/graphics/xv/files/patch-config.h
index 5d36a12b5046..c53959ab6589 100644
--- a/graphics/xv/files/patch-config.h
+++ b/graphics/xv/files/patch-config.h
@@ -1,20 +1,6 @@
---- config.h.orig Thu Aug 27 04:50:47 1998
-+++ config.h Thu Aug 27 04:51:05 1998
-@@ -103,10 +103,9 @@
- * should not need to be changed
- */
-
--/* #define GS_PATH "/usr/local/bin/gs" */
--#define GS_PATH "gs"
--/* #define GS_LIB "." */
--/* #define GS_DEV "ppmraw" */
-+#define GS_PATH "%%LOCALBASE%%/bin/gs"
-+#define GS_LIB "%%LOCALBASE%%/lib/ghostscript"
-+#define GS_DEV "ppmraw"
-
-
- /***************************************************************************
-@@ -159,7 +159,7 @@
+--- src/config.h.orig 2023-07-17 01:25:42 UTC
++++ src/config.h
+@@ -191,7 +191,7 @@
* in the following line.
*/
@@ -23,7 +9,7 @@
/***************************************************************************
-@@ -175,8 +175,8 @@
+@@ -207,8 +207,8 @@
* is read-only), change 'undef' to 'define' the VIRTUAL_TD line.
*/
@@ -32,27 +18,9 @@
+#define AUTO_EXPAND
+#define VIRTUAL_TD
- #if !defined(AUTO_EXPAND) && defined(VIRTUAL_TD)
+ #if defined(VIRTUAL_TD) && !defined(AUTO_EXPAND)
# undef VIRTUAL_TD
-@@ -190,7 +190,7 @@
- * Shunauzer, change 'undef' to 'define' in the following line.
- */
-
--#undef VS_ADJUST
-+#define VS_ADJUST
-
-
- /***************************************************************************
-@@ -216,7 +216,7 @@
- * 'undef' to 'define' in the following line.
- */
-
--#undef TV_L10N
-+/* #undef TV_L10N */
-
- #ifdef TV_L10N
- /*
-@@ -259,7 +259,7 @@
+@@ -291,7 +291,7 @@
* magic number or suffix in "~/.xv_mgcsfx" .
* To enable this feature, change 'undef' to 'define' in the following line.
*/
@@ -61,24 +29,7 @@
#ifdef HAVE_MGCSFX
/*
-@@ -285,14 +285,14 @@
- * WARNING : If you decide to use preprocessor, you must not write
- * '# <comment>' style comment in startup file. Because,
- * preprocessor can't recognize. */
--# undef USE_MGCSFX_PREPROCESSOR
-+# define USE_MGCSFX_PREPROCESSOR
-
- # ifdef USE_MGCSFX_PREPROCESSOR
- /*
- * This is used like "system("MGCSFX_PREPROCESSOR MGCSFX_RC > tmp_name");",
- * and read tmp_name instead of MGCSFX_RC.
- */
--# define MGCSFX_PREPROCESSOR "/usr/lib/cpp"
-+# define MGCSFX_PREPROCESSOR "/usr/bin/cpp"
- /* # define MGCSFX_PREPROCESSOR "cc -E" */
-
- # endif /* USE_MGCSFX_PREPROCESSOR */
-@@ -325,7 +325,7 @@
+@@ -352,7 +352,7 @@
* 'undef' to 'define' in the following line.
*/
diff --git a/graphics/xv/files/patch-xv.h b/graphics/xv/files/patch-xv.h
index 631f2cc5515e..8795af429413 100644
--- a/graphics/xv/files/patch-xv.h
+++ b/graphics/xv/files/patch-xv.h
@@ -1,11 +1,11 @@
---- xv.h.orig 2009-05-17 12:01:21.000000000 +0200
-+++ xv.h 2009-05-17 12:02:58.000000000 +0200
-@@ -158,7 +159,7 @@
+--- src/xv.h.orig 2023-07-17 01:25:42 UTC
++++ src/xv.h
+@@ -183,7 +183,7 @@
#ifndef VMS
# include <errno.h>
-# ifndef __NetBSD__
+# if !defined(__NetBSD__) && !defined(__FreeBSD__)
- # if !(defined __GLIBC__ && __GLIBC__ >= 2)
+ # if !(defined(__GLIBC__) && __GLIBC__ >= 2) && !defined(__OpenBSD__)
extern int errno; /* SHOULD be in errno.h, but often isn't */
- extern char *sys_errlist[]; /* this too... */
+ # ifndef XV_HAVE_SYSERRLISTDECL
diff --git a/graphics/xv/files/patch-xvevent.c b/graphics/xv/files/patch-xvevent.c
index 5ce5d4faeec8..8245b11534ba 100644
--- a/graphics/xv/files/patch-xvevent.c
+++ b/graphics/xv/files/patch-xvevent.c
@@ -1,6 +1,6 @@
---- xvevent.c.orig 2009-05-22 07:21:18.000000000 +0200
-+++ xvevent.c 2009-05-22 07:21:48.000000000 +0200
-@@ -814,7 +814,7 @@
+--- src/xvevent.c.orig 2023-07-17 01:25:42 UTC
++++ src/xvevent.c
+@@ -828,7 +828,7 @@ int HandleEvent(event, donep)
debkludge_offy = eHIGH-xwa.height+p_offy;
}
diff --git a/graphics/xv/files/patch-xvgif.c b/graphics/xv/files/patch-xvgif.c
index 9c769565196c..e9d6c25122be 100644
--- a/graphics/xv/files/patch-xvgif.c
+++ b/graphics/xv/files/patch-xvgif.c
@@ -1,7 +1,7 @@
---- xvgif.c.orig 2009-05-17 08:25:07.000000000 +0200
-+++ xvgif.c 2009-05-17 09:37:28.000000000 +0200
-@@ -169,8 +169,12 @@
-
+--- src/xvgif.c.orig 2023-07-17 01:25:42 UTC
++++ src/xvgif.c
+@@ -186,8 +186,12 @@ int LoadGIF(fname, pinfo)
+
aspect = NEXTBYTE;
if (aspect) {
+#if 0
@@ -11,5 +11,5 @@
+ normaspect = (float) (aspect + 15) / 64.0; /* gif89 aspect ratio */
+#endif
if (DEBUG) fprintf(stderr,"GIF89 aspect = %f\n", normaspect);
- }
-
+ /* FIXME: apparently this _should_ apply to all frames in a multi-image
+ * GIF (i.e., PgUp/PgDn), but it doesn't */
diff --git a/graphics/xv/files/patch-xvinfo.c b/graphics/xv/files/patch-xvinfo.c
deleted file mode 100644
index 05547a174ff0..000000000000
--- a/graphics/xv/files/patch-xvinfo.c
+++ /dev/null
@@ -1,11 +0,0 @@
---- xvinfo.c.orig 1994-12-22 22:34:41 UTC
-+++ xvinfo.c
-@@ -26,7 +26,7 @@
- #define INFOHIGH 270
-
- /* max length of an Info String */
--#define ISTRLEN 80
-+#define ISTRLEN 256
-
- /* baseline of top line of text */
- #define TOPBASE (36 + penn_height/2 + 4 + 8 + ASCENT)
diff --git a/graphics/xv/files/patch-xvjp2k.c b/graphics/xv/files/patch-xvjp2k.c
deleted file mode 100644
index 2f84d53a8c16..000000000000
--- a/graphics/xv/files/patch-xvjp2k.c
+++ /dev/null
@@ -1,2377 +0,0 @@
-diff -ur ./xvjp2k.c /home/src/master/GIT/xv/src/xvjp2k.c
---- ./xvjp2k.c 2022-02-20 20:18:25.590840000 +0100
-+++ /home/src/master/GIT/xv/src/xvjp2k.c 2022-02-20 20:39:26.277883000 +0100
-@@ -2,20 +2,20 @@
- * xvjp2k.c - I/O subroutines for JPEG 2000 format pictures
- *
- * This module is a "shim" between XV and a JPEG 2000 CODEC in the open-source
-- * JasPer Library created by Michael D. Adams; for more information, see the URL
-- * "http://www.ece.uvic.ca/~mdadams/jasper". We don't use most of the other
-- * facilities in this library, so it's better to link XV with a UNIX "archive"
-- * representation of it, not a DLL.
-+ * JasPer Library created by Michael D. Adams; for more information, see the
-+ * URL "http://www.ece.uvic.ca/~mdadams/jasper". We don't use most of the
-+ * other facilities in this library, so it's better to link XV with a UNIX
-+ * "archive" representation of it, not a DLL.
- *
- * JPEG 2000 files can be represented in either of two general ways: The
- * simplest representation is a "code stream", which often has a ".jpc" file
- * name suffix and is organized much like a classical JPEG file, except that
- * unfortunately, JPEG 2000 code streams indicate the no. of colors in an image
- * but no longer give any clues about its color space (e.g., RGB or YCbCr).
-- * Instead, there is now a semantically higher-level representation, which often
-- * has a ".jp2" file name suffix and encapsulates a "code stream" with (possibly
-- * a lot of) color-space information, optionally including things like ICC
-- * correction tables.
-+ * Instead, there is now a semantically higher-level representation, which
-+ * often has a ".jp2" file name suffix and encapsulates a "code stream" with
-+ * (possibly a lot of) color-space information, optionally including things
-+ * like ICC correction tables.
- *
- * Compared to the IJG JPEG Library used in file "xvjpeg.c", one must solve
- * several problems for color images when marrying JasPer to XV.
-@@ -25,9 +25,9 @@
- * normal "X Windows" display, so we must carefully check a decoded image's
- * parameters in order to reject anything that we can't handle gracefully.
- *
-- * 2. JasPer prefers to decode/encode images using color-plane "slices", instead
-- * of interleaved pixels needed by "X Windows", so we must (de)interleave
-- * copies of the image buffer here.
-+ * 2. JasPer prefers to decode/encode images using color-plane "slices",
-+ * instead of interleaved pixels needed by "X Windows", so we must
-+ * (de)interleave copies of the image buffer here.
- *
- * XXX Things to do:
- *
-@@ -42,599 +42,419 @@
- *
- * --Scott Marovich <marovich@hpl.hp.com>, Hewlett-Packard Laboratories,
- * January 2005.
-+ *
-+ * Michael Aadams <mdadams@ece.uvic.ca>, University of Victoria, January 2022.
-+ * The original code needed to be almost entirely rewritten due to its
-+ * insistence on bypassing the JasPer library API and violating many
-+ * preconditions in the usage of the API (which, of course, caused
-+ * many problems as the JasPer library evolved over time).
-+ *
- */
- #include "copyright.h"
-
--#define NEEDSARGS
-+#define NEEDSARGS
- #include "xv.h"
-
- #ifdef HAVE_JP2K
-
- #include <jasper/jasper.h>
--/* missing prototype in 1.701.0, sigh: */
--jas_stream_t *jas_stream_freopen PARM((const char *, const char *, FILE *));
-
--static const char *fbasename, /* File's base name, for error/warning msgs */
-- bad_samp[] = "%s: can't read %d-plane %s file!",
-- fmode[] = "rb",
-- full_msg[] = "%s %s. (%ld bytes)",
-- jp2_kind[] = "JP2",
-- jpc_kind[] = "JPEG 2000",
-- load_msg[] = "Loading %dx%d %s %s (%ld bytes)...",
-- no_mem[] = "%s: can't read %s file - out of memory",
-- pixel_size[] = "%s: can't display %d-bit pixels!",
-- shrt_msg[] = "%dx%d %s %s. ",
-- truncated[] = "%s: Unexpected end of %s file",
-- read_err[] = "%s: I/O error reading %s file",
-- bad_dims[] = "%s: error in JPEG-2000 header (bad image size)";
-+#define GIBI (1024ULL * 1024ULL * 1024ULL)
-
--/* We only want to override the JasPer Library's "jas_eprintf()" subroutine in
-- order to make it a "wrapper" around XV's own error-reporting subroutine, but
-- because of the way the former is currently packaged in JasPer Library Version
-- 1.701, we must override everything else packaged in the "jas_debug.o" module
-- with it, otherwise we get "duplicate definition" messages from the linker.
--*/
--int jas_getdbglevel(void) {return 0;}
--int jas_setdbglevel(int n) {return 0;}
--int jas_memdump(FILE *fp,void *data,size_t len) {return 0;}
-+static const char *fbasename, /* File's base name, for error/warning msgs */
-+ bad_samp[] = "%s: can't read %d-plane %s file!", fmode[] = "rb",
-+ full_msg[] = "%s %s. (%ld bytes)", jp2_kind[] = "JP2",
-+ jpc_kind[] = "JPEG 2000", load_msg[] = "Loading %dx%d %s %s (%ld bytes)...",
-+ no_mem[] = "%s: can't read %s file - out of memory",
-+ pixel_size[] = "%s: can't display %d-bit pixels!",
-+ shrt_msg[] = "%dx%d %s %s. ",
-+ truncated[] = "%s: Unexpected end of %s file",
-+ read_err[] = "%s: I/O error reading %s file",
-+ bad_dims[] = "%s: error in JPEG-2000 header (bad image size)";
-
--int jas_eprintf(const char *fmt,...) /* Handle JasPer Library message */
-+static int get_debug_level(void)
- {
-- static char error[] = "error: ", warning[]= "warning: ";
-- va_list ap;
-- int kind = ISTR_WARNING;
-- char buffer[512];
-- register char *p;
--
-- /* Unlike the IJG JPEG Library, the JasPer Library current has no graceful way
-- for an application (= us!) to intercept its diagnostic messages and output
-- them using our own subroutines, so this ugly replacement for its output
-- subroutine will have to suffice. At Version 1.701, lthough the library's
-- own "jas_eprintf()" is a varargs subroutine, all calls currently pass just
-- 1 string with a Line Feed at the end and no "printf(3C)" arguments. Most
-- strings begin with "error: " or "warning: ", although a few have neither.
-- We try to translate these into the format preferred by XV, trimming any
-- trailing Line Feed character (ugh!).
-- */
-- va_start(ap, fmt);
-- vsnprintf(p = buffer,512,fmt,ap);
-- va_end(ap);
-- while (*p++);
-- if (p[-2] == '\n') p[-2] = '\0';
-- p = buffer;
-- if (strncmp(p,error,sizeof error) == 0) /* "error: ... " */
-- {
-- kind = ISTR_WARNING;
-- p += sizeof error;
-- }
-- else /* "warning: ... " */
-- if (strncmp(p,warning,sizeof warning) == 0)
-- {
-- kind = ISTR_INFO;
-- p += sizeof warning;
-- };
-- SetISTR(kind,"%s: %s",fbasename,p);
-- return strlen(fmt);
-+ int debug_level = 0;
-+ const char *cp;
-+ if ((cp = getenv("XV_JASPER_DEBUG_LEVEL"))) {
-+ debug_level = atoi(cp);
-+ }
-+ return debug_level;
- }
-
--static char *SetBuf(FILE *f)
--{
-- char *buf;
-- register char *p;
-+#if (JAS_VERSION_MAJOR >= 3)
-+static int print_log(jas_logtype_t type, const char *format, va_list ap) {
-+ const int buffer_size = 512;
-+ char buffer[buffer_size];
-+ int count;
-
-- /* JPEG 2000 image files are apt to be large, but the buffer size allocated by
-- most implementations of the "C" Standard I/O Library is still ridiculously
-- small, typically 1 KB. We want to allocate a much larger buffer for higher
-- I/O efficiency, but the details are unfortunately a bit platform-specific.
-- Under UNIX systems with virtual memory, we want to encourage its internal
-- "physio()" subroutine by making the buffer an integral number of pages,
-- aligned on a page-multiple memory address boundary. Under HP-UX 11.1+ and
-- perhaps other operating-systems, a Standard I/O buffer is preceded by a
-- header whose size must also be taken into account.
-- */
--# ifndef IOBUFSIZ
--# define IOBUFSIZ 65536
--# endif /* IOBUFSIZ */
--# ifdef __hpux
--# define OVERHEAD sizeof(mbstate_t)
--# endif /* __hpux */
--# ifndef OVERHEAD
--# define OVERHEAD 0
--# endif /* OVERHEAD */
-+ int log_class = jas_logtype_getclass(type);
-+ int kind;
-+ switch (log_class) {
-+ case JAS_LOGTYPE_CLASS_INFO:
-+ kind = ISTR_INFO;
-+ break;
-+ case JAS_LOGTYPE_CLASS_WARN:
-+ case JAS_LOGTYPE_CLASS_ERROR:
-+ default:
-+ kind = ISTR_WARNING;
-+ break;
-+ }
-
--# ifdef NBPG
-- if (!(buf = p = malloc(NBPG+OVERHEAD+IOBUFSIZ))) return 0;
-- p = (char *)((unsigned long)p+NBPG-1 & ~(NBPG-1));
-- p -= OVERHEAD;
--# else /* not NBPG */
-- if (!(buf = p = malloc(OVERHEAD+IOBUFSIZ))) return 0;
-- p += OVERHEAD;
--# endif /* NBPG */
-- setvbuf(f,p,_IOFBF,OVERHEAD+IOBUFSIZ);
-- return buf;
--# undef OVERHEAD
--# undef IOBUFSIZ
-+ count = vsnprintf(buffer, buffer_size, format, ap);
-+
-+ if (log_class == JAS_LOGTYPE_CLASS_WARN ||
-+ log_class == JAS_LOGTYPE_CLASS_ERROR) {
-+ if (get_debug_level() >= 1) {
-+ jas_eprintf("%s", buffer);
-+ } else {
-+ int i;
-+ for (i = 0; i < count; ++i) {
-+ if (buffer[i] == '\n') {
-+ buffer[i] = ' ';
-+ }
-+ }
-+ SetISTR(kind, "%s: %s", fbasename, buffer);
-+ }
-+ } else {
-+ jas_eprintf("%s", buffer);
-+ }
-+ return count;
- }
-+#endif
-
--int LoadJPC(char *fname,register PICINFO *pinfo,int quick)
--{
-- jas_image_t *img;
-- jas_stream_t *str;
-- FILE *fp;
-- char *iobuf;
-- const char *s;
-- unsigned long filesize;
-- long w, h, npixels, bufsize;
-- int ok = 0, vstride;
-- register int i;
-+static int LoadJP2K(char *fname, register PICINFO *pinfo, int quick,
-+ bool jpc_format) {
-+ jas_image_t *img = 0;
-+ jas_stream_t *str = 0;
-+ FILE *fp;
-+ const char *s;
-+ unsigned long filesize;
-+ long w, h, npixels, bufsize;
-+ int vstride;
-+ register int i;
-+ jas_matrix_t *data = 0;
-
-- /* Load a JPEG 2000 "code stream" image file into a pixel buffer for XV.
-- Unlike classical JPEG files, they have no clue about the image's color
-- space, so we check for 8-bit data samples but make no effort to check or
-- convert color spaces, and "what you see is what you get". For now, ignore
-- the "quick" option to return a reduced-resolution or -size image. Return 1
-- on success, or 0 on failure.
-- */
-- if (!(fp = xv_fopen(fname,fmode))) return 0;
-- fbasename = BaseName(fname); /* Input file's base name, for message(s) */
-- if (!(iobuf = SetBuf(fp)))
-- {
-- (void)fclose(fp);
-- SetISTR(ISTR_WARNING,no_mem,fbasename,jpc_kind);
-- goto L3;
-- }
-+ int ret = 1;
-
-- /* Before telling the JasPer Library about this file, get its size for display
-- purposes. Non-UNIX systems don't necessarily simulate "stat(2)", so do it
-- crudely but portably by seeking to the end, then back to the beginning.
-- */
-- fseek(fp,0L,2);
-- filesize = ftell(fp);
-- fseek(fp,0L,0);
-+ int debug_level = get_debug_level();
-+#if (JAS_VERSION_MAJOR >= 3)
-+ size_t max_mem = jas_get_total_mem_size();
-+ if (!max_mem) {
-+ max_mem = GIBI;
-+ }
-+ jas_conf_clear();
-+ jas_conf_set_max_mem_usage(max_mem);
-+ jas_init_library();
-+ jas_init_thread();
-+ jas_set_vlogmsgf(print_log);
-+#else
-+ jas_init();
-+#endif
-+#if (JAS_VERSION_MAJOR >= 3)
-+ jas_set_debug_level(debug_level);
-+#else
-+ jas_setdbglevel(debug_level);
-+#endif
-
-- /* "jas_stream_close()" will eventually close the input file, so only do it
-- explicitly if no stream can be created:
-- */
-- if (!(str = jas_stream_freopen(fname,fmode,fp))) /* nice if prototype... */
-- {
-- (void)fclose(fp);
-- goto L3;
-- }
-+ if (!(fp = xv_fopen(fname, fmode))) {
-+ return 0;
-+ }
-+ /* Input file's base name, for message(s) */
-+ fbasename = BaseName(fname);
-
-- /* It's not clear to me whether the following represents a JasPer Library "bug"
-- but it sure looks goofy: Unless a stream buffer is marked "read only",
-- which only happens when the stream's "fillbuf" method is called, even though
-- our buffers are always "read only", the library will try to flush out buffer
-- contents when the stream is destroyed, which makes it die a horrible death.
-- So, mark the stream buffer proactively:
-- */
-- str->bufmode_ |= JAS_STREAM_RDBUF; /* We will only read the stream buffer */
-- if (!(img = jpc_decode(str,0))) goto L2;
-- if ((vstride = jas_image_numcmpts(img))) /* num. color planes */
-- {
-+ /* Compute file size is portable way. */
-+ fseek(fp, 0L, 2);
-+ filesize = ftell(fp);
-+ fseek(fp, 0L, 0);
-
-- /* After the image-component streams created, they are left in a "write"
-- state with the streams' cursors positioned at their ends, so "seek" in
-- order to "read" each stream from its beginning.
-- */
-- i = vstride;
-- while (--i >= 0)
-- if (jas_stream_seek(img->cmpts_[i]->stream_,0L,0))
-- {
-- SetISTR(ISTR_WARNING,read_err,fbasename,jpc_kind);
-- goto L1;
-- }
-- }
-- w = jas_image_width(img);
-- h = jas_image_height(img);
-+#if (JAS_VERSION_MAJOR >= 3)
-+ /*
-+ This approach will not work in JasPer prior to 3.0.0 due to a bug in
-+ the stream code.
-+ */
-+ if (!(str = jas_stream_freopen(fname,fmode,fp))) {
-+ fclose(fp);
-+ ret = 0;
-+ goto done;
-+ }
-
-- /* avoid buffer overflow */
-- npixels = w * h;
-- bufsize = vstride * npixels;
-- if (w <= 0 || h <= 0 || npixels/w != h || bufsize/vstride != npixels)
-- {
-- (void)fclose(fp);
-- SetISTR(ISTR_WARNING,bad_dims,fbasename);
-- goto L1;
-- }
-- pinfo->normw = pinfo->w = w;
-- pinfo->normh = pinfo->h = h;
-+ /* It's not clear to me whether the following represents a JasPer Library
-+ "bug" but it sure looks goofy: Unless a stream buffer is marked "read
-+ only", which only happens when the stream's "fillbuf" method is called,
-+ even though our buffers are always "read only", the library will try to
-+ flush out buffer contents when the stream is destroyed, which makes it
-+ die a horrible death. So, mark the stream buffer proactively:
-+ */
-+ str->bufmode_ |= JAS_STREAM_RDBUF; /* We will only read the stream buffer */
-+#else
-+ {
-+ if (!(str = jas_stream_memopen(0, 0))) {
-+ ret = 0;
-+ goto done;
-+ }
-+ const size_t buffer_size = 1024;
-+ char buffer[buffer_size];
-+ for (;;) {
-+ size_t count;
-+ count = fread(buffer, 1, buffer_size, fp);
-+ if (!count) {
-+ if (!feof(fp)) {
-+ ret = 0;
-+ goto done;
-+ }
-+ break;
-+ }
-+ if (jas_stream_write(str, buffer, count) != count) {
-+ ret = 0;
-+ goto done;
-+ }
-+ }
-+ jas_stream_rewind(str);
-+ }
-+#endif
-
-- /* Sanity-check the image's color space and no. of colors. For now, accept
-- only "generic" color spaces, not files needing image-specific color
-- correction, but fix that someday...
-- */
-- switch (vstride)
-- {
-- default:
-- SetISTR(ISTR_WARNING,bad_samp,fbasename,vstride,jpc_kind);
-- goto L1;
-- case 1:
-- if ((i = jas_image_cmptprec(img,0)) != 8) /* not 8-bit pixels */
-- {
-- SetISTR(ISTR_WARNING,pixel_size,fbasename,i);
-- goto L1;
-- }
-- s = "Greyscale";
-- pinfo->type = PIC8;
-- pinfo->colType = F_GREYSCALE;
-- i = 256; /* Return fake indexed-color "map" */
-- while (--i >= 0) pinfo->r[i] = pinfo->g[i] = pinfo->b[i] = i;
-- break;
-- case 3:
-+ const jas_image_fmtinfo_t *fmtinfo = jas_image_lookupfmtbyname(
-+ jpc_format ? "jpc" : "jp2");
-+ assert(fmtinfo);
-+ if (!(img = jas_image_decode(str, fmtinfo->id, 0))) {
-+ ret = 0;
-+ goto done;
-+ }
-
-- /* BEWARE OF KLUDGE: If the image's color space is RGB, assume that the
-- data-sample precision for all color planes is the
-- same. If the color space is YCbCr, assume the luminance (Y = 0th)
-- component has the greatest precision, although the chrominance
-- (Cr = 1st, Cb = 2nd) components are usually sub-sampled.
-- */
-- if ((i = jas_image_cmptprec(img,0)) != 8) /* not 24-bit pixels */
-- {
-- SetISTR(ISTR_WARNING,pixel_size,fbasename,i*3);
-- goto L1;
-- }
-- s = "Color";
-- pinfo->type = PIC24;
-- pinfo->colType = F_FULLCOLOR;
-+ w = jas_image_width(img);
-+ h = jas_image_height(img);
-+ vstride = jas_image_numcmpts(img);
-
-- /* XXX Unlike the IJG JPEG Library, the JasPer Library is apparently
-- unable to quantize colors or tell us whether the image's colors
-- were quantized by its creator, so it seems that we can't return a
-- color map for XV to potentially use 8-bit indexed color. If there
-- *is* an easy way to do it that escapes me, put the code here someday.
-- */
-- }
-- if (!(pinfo->pic = (byte *)malloc(bufsize))) /* image buffer for XV */
-- {
-- SetISTR(ISTR_WARNING,no_mem,fbasename,jpc_kind);
-- goto L1;
-- }
-- pinfo->frmType = F_JPC;
-- sprintf(pinfo->fullInfo,full_msg,s,jpc_kind,filesize);
-- sprintf(pinfo->shrtInfo,shrt_msg,pinfo->w,pinfo->h,s,jpc_kind);
-- SetISTR(ISTR_INFO,load_msg,pinfo->normw,pinfo->normh,s,jpc_kind,filesize);
-- if (vstride == 1) /* gray-scale image */
-- { register jas_stream_t *c = img->cmpts_[0]->stream_;
-- register byte *p = pinfo->pic;
-+ /* avoid buffer overflow */
-+ npixels = w * h;
-+ bufsize = vstride * npixels;
-+ if (w <= 0 || h <= 0 || npixels / w != h || bufsize / vstride != npixels) {
-+ (void)fclose(fp);
-+ SetISTR(ISTR_WARNING, bad_dims, fbasename);
-+ ret = 0;
-+ goto done;
-+ }
-+ pinfo->normw = pinfo->w = w;
-+ pinfo->normh = pinfo->h = h;
-
-- /* Since this is a 1-plane image, avoid a lot of errant nonsense in the
-- JasPer Library by sequentially reading all of the data into our buffer
-- directly.
-- */
-- do if ((i = (*c->ops_->read_)(c->obj_,(char *)p,bufsize)) <= 0)
-- {
-- SetISTR(ISTR_WARNING,i < 0 ? read_err : truncated,fbasename,
-- jpc_kind);
-- goto L1;
-- }
-- while ((p += i),(bufsize -= i) > 0);
-- }
-- else /* RGB color image */
-- {
-+ /* Sanity-check the image's color space and no. of colors. For now, accept
-+ only "generic" color spaces, not files needing image-specific color
-+ correction, but fix that someday...
-+ */
-+ switch (vstride) {
-+ static char color_space[] = {"%s: invalid color space!"};
-
-- /* Reading color images is inefficient because JPEG 2000 wants to partition
-- file data into separate image planes (colors), while XV wants data
-- samples from each plane to be interleaved as 3-byte pixels. Apparently
-- the fastest method consists of 3 passes through the XV image buffer,
-- into which we insert the bytes of each component.
-- */
-- i = 0;
-- do /* each color component */
-- { long npix = npixels;
-- register jas_stream_t *c = img->cmpts_[i]->stream_;
-- register byte *p = pinfo->pic + i;
-+ default:
-+ SetISTR(ISTR_WARNING, bad_samp, fbasename, vstride, jp2_kind);
-+ ret = 0;
-+ goto done;
-+ case 1:
-+ if (!jas_clrspc_isunknown(i = jas_image_clrspc(img)) &&
-+ jas_clrspc_fam(i) != JAS_CLRSPC_FAM_GRAY) {
-+ SetISTR(ISTR_WARNING, color_space, fbasename);
-+ ret = 0;
-+ goto done;
-+ }
-+ if ((i = jas_image_cmptprec(img, 0)) != 8) /* not 8-bit pixels */
-+ {
-+ SetISTR(ISTR_WARNING, pixel_size, fbasename, i);
-+ ret = 0;
-+ goto done;
-+ }
-+ s = "Greyscale";
-+ pinfo->type = PIC8;
-+ pinfo->colType = F_GREYSCALE;
-+ i = 256; /* Return fake indexed-color "map" */
-+ while (--i >= 0)
-+ pinfo->r[i] = pinfo->g[i] = pinfo->b[i] = i;
-+ break;
-+ case 3:
-+ if (jas_clrspc_isunknown(i = jas_image_clrspc(img))) {
-+ SetISTR(ISTR_WARNING, color_space, fbasename);
-+ ret = 0;
-+ goto done;
-+ }
-+ if (jas_clrspc_fam(i) != JAS_CLRSPC_FAM_RGB) {
-+ jas_image_t *oimg;
-+ jas_cmprof_t *profile;
-
-- do /* each pixel */
-- { register int b;
-+ /* Here's where the JasPer Library really shines. The only color
-+ space that XV handles is RGB, so if that's not what our image
*** 2756 LINES SKIPPED ***