Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Add support for .webp image format.
Browse files Browse the repository at this point in the history
This is from xv-20150913-rainer-m-canavan--xrandr-support--webp-support.dif
See https://developers.google.com/speed/webp/ and
https://en.wikipedia.org/wiki/WebP for info on this format.
  • Loading branch information
DavidGriffith committed May 3, 2017
1 parent a84406c commit 5682a07
Show file tree
Hide file tree
Showing 10 changed files with 589 additions and 13 deletions.
19 changes: 13 additions & 6 deletions Imakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*/
#define HaveJpeg

/* if, for whatever reason, you're unable to get the WEBP library to compile
* on your machine, *COMMENT OUT* the following line
*/
#define HaveWEBP

/* if, for whatever reason, you're unable to get the TIFF library to compile
* on your machine, *COMMENT OUT* the following line
Expand Down Expand Up @@ -116,9 +120,12 @@ MGCSFX = -DMGCSFXDIR=\"$(MGCSFXDIR)\"

/* This marks the end of the configuration parameters */




#ifdef HaveWEBP
WEBP = -DDOWEBP
WEBPDIR = /usr/
LIBWEBP = $(WEBPDIR)/lib/libwebp.so
WEBPINCLUDE = -I$(WEBPDIR)/include
#endif

#ifdef HaveJpeg
JPEG = -DDOJPEG
Expand Down Expand Up @@ -156,7 +163,7 @@ DEFINES= $(SCO) $(UNIX) $(NODIRENT) $(VPRINTF) $(TIMERS) \
$(HPUX7) $(JPEG) $(TIFF) $(PDS) $(DXWM) $(RAND) \
$(BACKING_STORE) $(BSDTYPES) $(SGI) $(MGCSFX)

INCLUDES = $(JPEGINCLUDE) $(TIFFINCLUDE)
INCLUDES = $(JPEGINCLUDE) $(TIFFINCLUDE) $(WEBPINCLUDE)

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 \
Expand All @@ -166,7 +173,7 @@ SRCS1 = xv.c xvevent.c xvroot.c xvmisc.c xvimage.c xvcolor.c xvsmooth.c \
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 xvwebp.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 \
Expand All @@ -176,7 +183,7 @@ OBJS1 = xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
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 xvwebp.o

SRCS2= bggen.c
OBJS2= bggen.o
Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ TIFFLIB = -L$(TIFFDIR)/lib -ltiff
# ( cd $(TIFFDIR) ; make CC='$(CC)' COPTS='$(CCOPTS) $(MCHN)' )


#ifdef HaveWEBP
WEBP = -DDOWEBP
WEBPDIR = /usr/
WEBPLIB = -L$(WEBPDIR)/lib -lwebp
WEBPINC = -I$(WEBPDIR)/include
#endif


###
### if, for whatever reason, you're unable to get the JPEG library to compile
### on your machine, *COMMENT OUT* the following lines
Expand Down Expand Up @@ -339,14 +347,14 @@ XRANDRLIB = -lXrandr



CFLAGS = $(CCOPTS) $(PNG) $(PNGINC) $(ZLIBINC) $(JPEG) $(JPEGINC) \
CFLAGS = $(CCOPTS) $(PNG) $(PNGINC) $(ZLIBINC) $(JPEG) $(JPEGINC) $(WEBP) $(WEBPINC) \
$(TIFF) $(TIFFINC) $(PDS) $(JP2K) $(JP2KINC) $(TVL10N) $(MGCSFX) \
$(UNIX) $(BSDTYPES) $(RAND) $(MALLOC) $(DXWM) $(MCHN) $(NODIRENT) \
$(VPRINTF) $(TIMERS) $(XRANDR) -DDOCDIR=\"$(DOCDIR)\" \
-DSYSCONFDIR=\"$(SYSCONFDIR)\" -DXVEXECPATH=\"$(LIBDIR)\"

### remove -lm for BeOS:
LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) $(XRANDRLIB) -L/usr/X11R6/lib -lX11 -lXt -lm
LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) $(XRANDRLIB) $(WEBPLIB) -L/usr/X11R6/lib -lX11 -lXt -lm
#LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -lX11 -lXt

OBJS = xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
Expand All @@ -357,7 +365,7 @@ OBJS = xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
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 xvhips.o \
xvmag.o xvpic.o xvmaki.o xvpi.o xvpic2.o xvvd.o xvmgcsfx.o \
xvml.o xvjp2k.o
xvml.o xvjp2k.o xvwebp.o

MISC = README INSTALL CHANGELOG IDEAS

Expand Down
23 changes: 23 additions & 0 deletions bits/br_webp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#define br_webp_width 48
#define br_webp_height 48
static char br_webp_bits[] = {
0xe0,0xff,0xff,0xff,0x01,0x00,0x20,0x00,0x00,0x00,0x03,0x00,0x20,0x00,0x00,
0x00,0x05,0x00,0x20,0x00,0x00,0x00,0x09,0x00,0x20,0x00,0x00,0x00,0x11,0x00,
0x20,0x00,0x00,0x00,0x21,0x00,0x20,0x00,0x00,0x00,0x41,0x00,0x20,0x00,0x00,
0x00,0x81,0x00,0x20,0x00,0x00,0x00,0x01,0x01,0x20,0x00,0x00,0x00,0xff,0x03,
0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,
0x00,0x00,0x02,0x20,0xff,0xff,0xff,0x7f,0x02,0x20,0x00,0x00,0x00,0x00,0x02,
0x20,0xff,0xff,0xff,0x7f,0x02,0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x83,0x7d,
0x3f,0x3f,0x02,0x20,0x83,0x7d,0x7f,0x7f,0x02,0x20,0x83,0x0d,0x63,0x63,0x02,
0x20,0x93,0x0d,0x63,0x63,0x02,0x20,0x93,0x0d,0x63,0x63,0x02,0x20,0xbb,0x7d,
0x7f,0x73,0x02,0x20,0xbb,0x7d,0x3f,0x3f,0x02,0x20,0xef,0x0d,0x63,0x1f,0x02,
0x20,0xef,0x0d,0x63,0x03,0x02,0x20,0xc7,0x0d,0x63,0x03,0x02,0x20,0xc7,0x0d,
0x63,0x03,0x02,0x20,0x83,0x7d,0x7f,0x03,0x02,0x20,0x83,0x7d,0x3f,0x03,0x02,
0x20,0x00,0x00,0x00,0x00,0x02,0x20,0xff,0xff,0xff,0x7f,0x02,0x20,0x00,0x00,
0x00,0x00,0x02,0x20,0xff,0xff,0xff,0x7f,0x02,0x20,0x00,0x00,0x00,0x00,0x02,
0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,
0x00,0x00,0x02,0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,0x00,0x00,0x02,
0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,
0x00,0x00,0x02,0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,0x00,0x00,0x02,
0x20,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x00,0x00,0x00,0x02,0xe0,0xff,0xff,
0xff,0xff,0x03};
25 changes: 25 additions & 0 deletions xv.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ int main(argc, argv)
pngW = (Window) NULL; pngUp = 0;
#endif

#ifdef HAVE_WEBP
webpW = (Window) NULL; webpUp = 0;
#endif

pcdW = (Window) NULL; pcdUp = 0;

#ifdef HAVE_PIC2
Expand Down Expand Up @@ -993,6 +997,11 @@ int main(argc, argv)
XSetTransientForHint(theDisp, pngW, dirW);
#endif

#ifdef HAVE_WEBP
CreateWEBPW();
XSetTransientForHint(theDisp, webpW, dirW);
#endif

#ifdef HAVE_PCD
CreatePCDW();
XSetTransientForHint(theDisp, pcdW, dirW);
Expand Down Expand Up @@ -1898,6 +1907,9 @@ static void cmdSyntax(i)
#endif
#ifdef HAVE_PNG
VersionInfoPNG();
#endif
#ifdef HAVE_WEBP
VersionInfoWEBP();
#endif
/* pbm/pgm/ppm support is native, not via pbmplus/netpbm libraries */
fprintf(stderr, "\n");
Expand Down Expand Up @@ -3153,6 +3165,15 @@ int ReadFileType(fname)
magicno[2]=='N' && magicno[3]=='G') rv = RFT_PNG;
#endif

#ifdef HAVE_WEBP
else if (magicno[0]==0x52 && magicno[1]==0x49 &&
magicno[2]==0x46 && magicno[3]==0x46 &&
magicno[8]==0x57 && magicno[9]==0x45 &&
magicno[10]==0x42 && magicno[11]==0x50 &&
magicno[12]==0x56 && magicno[13]==0x50 &&
magicno[14]==0x38) rv = RFT_WEBP;
#endif

#ifdef HAVE_PDS
else if (strncmp((char *) magicno, "NJPL1I00", (size_t) 8)==0 ||
strncmp((char *) magicno+2,"NJPL1I", (size_t) 6)==0 ||
Expand Down Expand Up @@ -3290,6 +3311,10 @@ int ReadPicFile(fname, ftype, pinfo, quick)
case RFT_PNG: rv = LoadPNG (fname, pinfo); break;
#endif

#ifdef HAVE_WEBP
case RFT_WEBP: rv = LoadWEBP (fname, pinfo); break;
#endif

#ifdef HAVE_PDS
case RFT_PDSVICAR: rv = LoadPDS (fname, pinfo); break;
#endif
Expand Down
26 changes: 25 additions & 1 deletion xv.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@
/* END OF CONFIGURATION INFO */
/*****************************/

#ifdef DOWEBP
# define HAVE_WEBP
#endif

#ifdef DOJPEG
# define HAVE_JPEG
Expand Down Expand Up @@ -573,6 +576,12 @@
# define F_TIFINC 0
#endif

#ifdef HAVE_WEBP
# define F_WEBPINC 1
#else
# define F_WEBPINC 0
#endif

#ifdef HAVE_PNG
# define F_PNGINC 1
#else
Expand Down Expand Up @@ -626,7 +635,8 @@
#define F_JPC ( 0 + F_PNGINC + F_JPGINC)
#define F_JP2 ( 0 + F_PNGINC + F_JPGINC + F_JP2INC)
#define F_GIF ( 0 + F_PNGINC + F_JPGINC + F_JP2INC + F_JP2INC) /* always avail; index varies */
#define F_TIFF ( 0 + F_PNGINC + F_JPGINC + F_JP2INC + F_JP2INC + F_TIFINC)
#define F_WEBP ( 0 + F_PNGINC + F_JPGINC + F_JP2INC + F_JP2INC + F_WEBPINC)
#define F_TIFF ( 0 + F_PNGINC + F_JPGINC + F_JP2INC + F_JP2INC + F_WEBPINC + F_TIFINC)
#define F_PS ( 1 + F_TIFF)
#define F_PBMRAW ( 2 + F_TIFF)
#define F_PBMASCII ( 3 + F_TIFF)
Expand Down Expand Up @@ -696,6 +706,7 @@
#define RFT_PI (JP_EXT_RFT + 4)
#define RFT_PIC2 (JP_EXT_RFT + 5)
#define RFT_MGCSFX (JP_EXT_RFT + 6)
#define RFT_WEBP (JP_EXT_RFT + 7)

/* definitions for page up/down, arrow up/down list control */
#define LS_PAGEUP 0
Expand Down Expand Up @@ -1409,6 +1420,11 @@ WHERE Window pngW;
WHERE int pngUp; /* is pngW mapped, or what? */
#endif

#ifdef HAVE_WEBP
/* stuff used for 'webp' box */
WHERE Window webpW;
WHERE int webpUp; /* is webpW mapped, or what? */
#endif

#ifdef ENABLE_FIXPIX_SMOOTH
WHERE int do_fixpix_smooth; /* GRR 19980607: runtime FS dithering */
Expand Down Expand Up @@ -2095,6 +2111,14 @@ int LoadSunRas PARM((char *, PICINFO *));
int WriteSunRas PARM((FILE *, byte *, int, int, int, byte *,
byte *, byte*, int, int, int));

/**************************** XVWEBP.C ***************************/
int LoadWEBP PARM((char *, PICINFO *));
void CreateWEBPW PARM((void));
void WEBPDialog PARM((int));
int WEBPCheckEvent PARM((XEvent *));
void WEBPSaveParams PARM((char *));
void VersionInfoWEBP PARM((void));

/**************************** XVTARGA.C ***************************/
int LoadTarga PARM((char *, PICINFO *));
int WriteTarga PARM((FILE *, byte *, int, int, int, byte *,
Expand Down
7 changes: 6 additions & 1 deletion xvbrowse.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef unsigned int mode_t; /* file mode bits */
#include "bits/br_targa"
#include "bits/br_tiff"
#include "bits/br_utah"
#include "bits/br_webp"
#include "bits/br_xbm"
#include "bits/br_xpm"
#include "bits/br_xwd"
Expand Down Expand Up @@ -117,7 +118,8 @@ typedef unsigned int mode_t; /* file mode bits */
#define BF_PCD 30
#define BF_BZIP2 31
#define BF_JP2 32
#define BF_JPC 33
#define BF_WEBP 33
#define BF_JPC 34
#define JP_EXT_BF (BF_JPC)
#define BF_MAG (JP_EXT_BF + 1)
#define BF_MAKI (JP_EXT_BF + 2)
Expand Down Expand Up @@ -605,6 +607,7 @@ void CreateBrowse(geom, fgstr, bgstr, histr, lostr)
bfIcons[BF_PS] =MakePix1(br->win,br_ps_bits, br_ps_width, br_ps_height);
bfIcons[BF_TGA] =MakePix1(br->win,br_tga_bits, br_tga_width, br_tga_height);
bfIcons[BF_TIFF]=MakePix1(br->win,br_tiff_bits,br_tiff_width,br_tiff_height);
bfIcons[BF_WEBP]=MakePix1(br->win,br_webp_bits,br_webp_width,br_webp_height);
bfIcons[BF_XBM] =MakePix1(br->win,br_xbm_bits, br_xbm_width, br_xbm_height);
bfIcons[BF_XPM] =MakePix1(br->win,br_xpm_bits, br_xpm_width, br_xpm_height);
bfIcons[BF_XWD] =MakePix1(br->win,br_xwd_bits, br_xwd_width, br_xwd_height);
Expand Down Expand Up @@ -3351,6 +3354,7 @@ static void scanFile(br, bf, name)
case RFT_PI: bf->ftype = BF_PI; break;
case RFT_PIC2: bf->ftype = BF_PIC2; break;
case RFT_MGCSFX: bf->ftype = BF_MGCSFX; break;
case RFT_WEBP: bf->ftype = BF_WEBP; break;
}
}
}
Expand Down Expand Up @@ -3975,6 +3979,7 @@ static void genIcon(br, bf)
case RFT_PI: strcat(str,"PI file"); break;
case RFT_PIC2: strcat(str,"PIC2 file"); break;
case RFT_MGCSFX: strcat(str,"Magic Suffix file"); break;
case RFT_WEBP: strcat(str,"WEBP file"); break;
default: strcat(str,"file of unknown type"); break;
}

Expand Down
31 changes: 29 additions & 2 deletions xvdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ static const char *saveFormats[] = {
#ifdef HAVE_JP2K
"JPEG 2000",
"JP2",
#endif
#endif
"GIF",
#ifdef HAVE_WEBP
"WEBP",
#endif
#ifdef HAVE_TIFF
"TIFF",
#endif
Expand Down Expand Up @@ -1235,6 +1238,15 @@ int DoSave()
}
#endif

#ifdef HAVE_WEBP
else if (fmt == F_WEBP) { /* WEBP */
WEBPSaveParams(fullname);
WEBPDialog(1); /* open WEBP Dialog box */
dbut[S_BOK].lit = 0; BTRedraw(&dbut[S_BOK]);
return 0; /* always 'succeeds' */
}
#endif

#ifdef HAVE_PIC2
else if (fmt == F_PIC2) { /* PIC2 */
if (PIC2SaveParams(fullname, col) < 0)
Expand Down Expand Up @@ -1488,7 +1500,15 @@ void SetDirSaveMode(group, bnum)
colMB.dim[F_REDUCED] = 1;
MBSelect(&colMB, F_BWDITHER);
}

#ifdef HAVE_WEBP
else if (MBWhich(&fmtMB) == F_WEBP) { /* turn off all but FULLCOLOR */
colMB.dim[F_FULLCOLOR] = 0;
colMB.dim[F_GREYSCALE] = 1;
colMB.dim[F_BWDITHER] = 1;
colMB.dim[F_REDUCED] = 1;
MBSelect(&colMB, F_FULLCOLOR);
}
#endif
else if (MBWhich(&fmtMB) == F_FITS) { /* turn off 'color' modes */
colMB.dim[F_FULLCOLOR] = 1;
colMB.dim[F_GREYSCALE] = 0;
Expand Down Expand Up @@ -1577,6 +1597,9 @@ static void changeSuffix()
#endif
#ifdef HAVE_PNG
(strcmp(lowsuf,"png" )==0) ||
#endif
#ifdef HAVE_WEBP
(strcmp(lowsuf,"webp")==0) ||
#endif
(strcmp(lowsuf,"wbmp")==0) ||
(strcmp(lowsuf,"xpm" )==0) ||
Expand Down Expand Up @@ -1645,6 +1668,10 @@ static void changeSuffix()
case F_MAKI: strcpy(lowsuf,"mki"); break;
#endif

#ifdef HAVE_WEBP
case F_WEBP: strcpy(lowsuf,"webp"); break;
#endif

#ifdef HAVE_PI
case F_PI: strcpy(lowsuf,"pi"); break;
#endif
Expand Down
Loading

0 comments on commit 5682a07

Please sign in to comment.