From f4092abdf94af6a99aff944d6264bc1284e8bdd4 Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Mon, 10 Oct 2011 17:43:39 +0200 Subject: Imported nx-X11-3.1.0-1.tar.gz Summary: Imported nx-X11-3.1.0-1.tar.gz Keywords: Imported nx-X11-3.1.0-1.tar.gz into Git repository --- nx-X11/lib/lbxutil/Imakefile | 31 ++ nx-X11/lib/lbxutil/delta/Imakefile | 17 + nx-X11/lib/lbxutil/delta/lbxdelta.c | 255 ++++++++++ nx-X11/lib/lbxutil/image/Imakefile | 45 ++ nx-X11/lib/lbxutil/image/dfaxg42d.c | 420 +++++++++++++++++ nx-X11/lib/lbxutil/image/dpackbits.c | 100 ++++ nx-X11/lib/lbxutil/image/efaxg42d.c | 328 +++++++++++++ nx-X11/lib/lbxutil/image/epackbits.c | 202 ++++++++ nx-X11/lib/lbxutil/image/lbxbwcodes.h | 269 +++++++++++ nx-X11/lib/lbxutil/image/lbxfax.h | 60 +++ nx-X11/lib/lbxutil/image/misc.c | 213 +++++++++ nx-X11/lib/lbxutil/image/mkg3states.c | 761 ++++++++++++++++++++++++++++++ nx-X11/lib/lbxutil/lbx_zlib/Imakefile | 22 + nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.c | 543 +++++++++++++++++++++ nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.h | 136 ++++++ nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib_io.c | 275 +++++++++++ nx-X11/lib/lbxutil/lbx_zlib/reqstats.c | 503 ++++++++++++++++++++ nx-X11/lib/lbxutil/lbx_zlib/reqstats.h | 43 ++ 18 files changed, 4223 insertions(+) create mode 100644 nx-X11/lib/lbxutil/Imakefile create mode 100644 nx-X11/lib/lbxutil/delta/Imakefile create mode 100644 nx-X11/lib/lbxutil/delta/lbxdelta.c create mode 100644 nx-X11/lib/lbxutil/image/Imakefile create mode 100644 nx-X11/lib/lbxutil/image/dfaxg42d.c create mode 100644 nx-X11/lib/lbxutil/image/dpackbits.c create mode 100644 nx-X11/lib/lbxutil/image/efaxg42d.c create mode 100644 nx-X11/lib/lbxutil/image/epackbits.c create mode 100644 nx-X11/lib/lbxutil/image/lbxbwcodes.h create mode 100644 nx-X11/lib/lbxutil/image/lbxfax.h create mode 100644 nx-X11/lib/lbxutil/image/misc.c create mode 100644 nx-X11/lib/lbxutil/image/mkg3states.c create mode 100644 nx-X11/lib/lbxutil/lbx_zlib/Imakefile create mode 100644 nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.c create mode 100644 nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.h create mode 100644 nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib_io.c create mode 100644 nx-X11/lib/lbxutil/lbx_zlib/reqstats.c create mode 100644 nx-X11/lib/lbxutil/lbx_zlib/reqstats.h (limited to 'nx-X11/lib/lbxutil') diff --git a/nx-X11/lib/lbxutil/Imakefile b/nx-X11/lib/lbxutil/Imakefile new file mode 100644 index 000000000..d4f74e787 --- /dev/null +++ b/nx-X11/lib/lbxutil/Imakefile @@ -0,0 +1,31 @@ +XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:46:40 cpqbld Exp $ + + + + + +XCOMM $XFree86: xc/lib/lbxutil/Imakefile,v 1.7 1999/04/17 09:08:13 dawes Exp $ + +#include + +#define IHaveSubdirs + +SUBDIRS = lbx_zlib delta image + +OBJS = lbx_zlib/?*.o delta/?*.o image/?*.o + +DONES = lbx_zlib/DONE delta/DONE image/DONE + +lbx_zlib/DONE: lbx_zlib +delta/DONE: delta +image/DONE: image + +#undef _LinkBuildLibrary +#define _LinkBuildLibrary(lib) LinkBuildLibrary(lib) + +NormalDepLibraryTarget(lbxutil,$(SUBDIRS) $(DONES),$(OBJS)) + +ForceSubdirs($(SUBDIRS)) + +DependSubdirs($(SUBDIRS)) + diff --git a/nx-X11/lib/lbxutil/delta/Imakefile b/nx-X11/lib/lbxutil/delta/Imakefile new file mode 100644 index 000000000..cb94c8906 --- /dev/null +++ b/nx-X11/lib/lbxutil/delta/Imakefile @@ -0,0 +1,17 @@ +XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:46:40 cpqbld Exp $ + +#define IncSubdir X11 +#include + +SRCS = lbxdelta.c + +OBJS = lbxdelta.o + +INCLUDES = -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/include -I../../../include/extensions + +SubdirLibraryRule($(OBJS)) +NormalLibraryObjectRule() +NormalLintTarget($(SRCS)) + +DependTarget() + diff --git a/nx-X11/lib/lbxutil/delta/lbxdelta.c b/nx-X11/lib/lbxutil/delta/lbxdelta.c new file mode 100644 index 000000000..5925a6a1b --- /dev/null +++ b/nx-X11/lib/lbxutil/delta/lbxdelta.c @@ -0,0 +1,255 @@ +/* + * $NCDXorg: @(#)lbxdelta.c,v 1.2 1994/01/22 02:23:40 dct Exp $ + * $Xorg: lbxdelta.c,v 1.5 2000/08/17 19:46:40 cpqbld Exp $ + * $XdotOrg: xc/lib/lbxutil/delta/lbxdelta.c,v 1.7 2005/07/30 21:07:25 alanc Exp $ + * + * Copyright 1993 Network Computing Devices + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of NCD. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. NCD. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD. + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Dale Tonogai, Network Computing Devices + */ +/* $XFree86: xc/lib/lbxutil/delta/lbxdelta.c,v 1.7 2001/07/25 15:04:57 dawes Exp $ */ + +#include +#include +#define _XLBX_SERVER_ +#include +#include + +#include +#include + +#ifdef LBXREQSTATS +#include "../lbx_zlib/reqstats.h" +extern int LbxWhoAmI; +extern struct ReqStats CoreRequestStats[128]; +extern struct ReqStats LbxRequestStats[LbxNumberReqs]; + +#define LBX_CODE 136 /* XXX - this should not be hardcoded - on todo list */ +#endif + +/* Copied from xc/programs/Xserver/include/xorg/os.h */ +#ifndef _HAVE_XALLOC_DECLS +#define _HAVE_XALLOC_DECLS +#include + +extern pointer Xalloc(unsigned long /*amount*/); +extern pointer Xcalloc(unsigned long /*amount*/); +extern pointer Xrealloc(pointer /*ptr*/, unsigned long /*amount*/); +extern void Xfree(pointer /*ptr*/); +#endif + +/* + * Allocate data structures needed for doing Delta compaction + */ +int +LBXInitDeltaCache(LBXDeltasPtr pcache, + int nDeltas, + int maxDeltasize) +{ + int i; + unsigned char *mem; + + if ((pcache->nDeltas = nDeltas)) { + pcache->maxDeltasize = maxDeltasize; + if ((pcache->deltas = (LBXDeltaElemPtr) + Xalloc(pcache->nDeltas * sizeof(LBXDeltaElemRec) + + pcache->nDeltas * pcache->maxDeltasize)) == NULL) { + return -1; + } + + mem = (unsigned char *) (pcache->deltas + pcache->nDeltas); + for (i = 0; i < pcache->nDeltas; i++) { + pcache->deltas[i].buf = mem; + mem += pcache->maxDeltasize; + } + } + else + pcache->maxDeltasize = 0; + + pcache->nextDelta = 0; + pcache->activeDeltas = 0; + return 0; +} + +/* + * Free data structures used for doing Delta compaction + */ +void +LBXFreeDeltaCache(LBXDeltasPtr pcache) +{ + if (pcache->nDeltas && pcache->deltas) + Xfree(pcache->deltas); +} + +static int +BytesDiff(unsigned char *ptr1, unsigned char *ptr2, + int n, + int maxn) +{ + int result = 0; + + while (n--) + if (*(ptr1++) != *(ptr2++)) + if (++result >= maxn) + break; + return (result); +} + +/* + * Find the message in the outgoing delta cache with the least number of + * differing bytes and return the number of differences. If all + * messages have greater than maxdiff differences, return -1. + */ +int +LBXDeltaMinDiffs(LBXDeltasPtr pcache, + unsigned char *inmsg, + int inmsglen, + int maxdiff, + int *pindex) +{ + int i, j, k = 0, l = maxdiff + 1; + int m; + LBXDeltaElemPtr dm; + + for (m = pcache->nextDelta-1, dm = &pcache->deltas[m], i = 0; + i < pcache->activeDeltas; + i++, m--, dm-- + ) { + if (m < 0) { + m = pcache->nDeltas - 1; + dm = &pcache->deltas[m]; + } + if (dm->length == inmsglen) { + j = BytesDiff(inmsg, dm->buf, inmsglen, l); + if (j < l) { + k = m; + l = j; + } + } + } + + if (l > maxdiff) + return -1; + else { + *pindex = k; + return l; + } +} + +/* + * Delta compact a given message + */ +void +LBXEncodeDelta(LBXDeltasPtr pcache, + unsigned char *inmsg, + int ndiff, + int index, + unsigned char *buf) +{ + int i, off, diff; + xLbxDiffItem *deltas = (xLbxDiffItem *)buf; + + for (off = i = 0; i < ndiff; off++) { + if ((diff = inmsg[off] - pcache->deltas[index].buf[off])) { + deltas[i].offset = off; + deltas[i++].diff = diff; + } + } +} + +/* + * Uncompact a message + */ +int +LBXDecodeDelta(LBXDeltasPtr pcache, + xLbxDiffItem *deltas, + int ndiff, + int index, + unsigned char **buf) +{ + int i; + int newindex = pcache->nextDelta; + int len = pcache->deltas[index].length; + unsigned char *p = pcache->deltas[newindex].buf; +#ifdef LBXREQSTATS + xReq *req; +#endif + + pcache->nextDelta = (pcache->nextDelta + 1) % pcache->nDeltas; + if (index != newindex) { + memcpy(p, pcache->deltas[index].buf, len); + pcache->deltas[newindex].length = len; + } + for (i = 0; i < ndiff; i++) + p[deltas[i].offset] += deltas[i].diff; + *buf = p; + +#ifdef LBXREQSTATS + req = (xReq *) p; + + if (LbxWhoAmI == 1) /* server */ + { + struct ReqStats *reqStat = NULL; + + if (req->reqType == LBX_CODE) + reqStat = &LbxRequestStats[req->data]; + else if (req->reqType < 128) + reqStat = &CoreRequestStats[req->reqType]; + + if (reqStat) + { + reqStat->delta_count++; + reqStat->pre_delta_bytes += (req->length << 2); + reqStat->post_delta_bytes += + (((sz_xLbxDeltaReq + sz_xLbxDiffItem * ndiff + 3) >> 2) << 2); + } + } +#endif + + return len; +} + +/* + * Add a message to the outgoing delta cache + */ +void +LBXAddDeltaOut(LBXDeltasPtr pcache, + unsigned char *inmsg, + int inmsglen) +{ + memcpy(pcache->deltas[pcache->nextDelta].buf, inmsg, inmsglen); + pcache->deltas[pcache->nextDelta].length = inmsglen; + pcache->nextDelta = (pcache->nextDelta + 1) % pcache->nDeltas; + if (pcache->activeDeltas < pcache->nDeltas) + pcache->activeDeltas++; +} + +/* + * Add a message to the incoming delta cache + */ +void +LBXAddDeltaIn(LBXDeltasPtr pcache, + unsigned char *inmsg, + int inmsglen) +{ + memcpy(pcache->deltas[pcache->nextDelta].buf, inmsg, inmsglen); + pcache->deltas[pcache->nextDelta].length = inmsglen; + pcache->nextDelta = (pcache->nextDelta + 1) % pcache->nDeltas; +} diff --git a/nx-X11/lib/lbxutil/image/Imakefile b/nx-X11/lib/lbxutil/image/Imakefile new file mode 100644 index 000000000..fa7421615 --- /dev/null +++ b/nx-X11/lib/lbxutil/image/Imakefile @@ -0,0 +1,45 @@ +XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:46:40 cpqbld Exp $ + + + + +XCOMM $XFree86: xc/lib/lbxutil/image/Imakefile,v 1.3 2001/01/17 19:43:35 dawes Exp $ + +#define IncSubdir X11 +#include + +SRCS = dfaxg42d.c dpackbits.c efaxg42d.c epackbits.c misc.c + +OBJS = dfaxg42d.o dpackbits.o efaxg42d.o epackbits.o misc.o + +INCLUDES = -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/include -I../../../include/extensions + +SubdirLibraryRule($(OBJS)) +NormalLibraryObjectRule() +NormalLintTarget($(SRCS)) + +MKG3STATES = ./mkg3states + +#if CrossCompiling +HOST_CFLAGS=$(TOP_INCLUDES) $(INCLUDES) $(BOOTSTRAPCFLAGS) \ + $(CROSSCOMPILEDEFINES) $(CROSSCOMPILEBOOTSTRAPDEFINES) +#else +HOST_CFLAGS=$(CFLAGS) +#endif + +g3states.h : mkg3states.c + RemoveFiles($@ HostProgramTargetName(mkg3states)) + -HostLinkRule(HostProgramTargetName(mkg3states), $(HOST_CFLAGS),mkg3states.c,$(LDLIBS)) + RunProgram(MKG3STATES,> g3_states_h) + $(MV) g3_states_h $@ + RemoveFiles(HostProgramTargetName(mkg3states) g3_states_h) + +includes:: g3states.h + +depend:: g3states.h + +clean:: + RemoveFiles(g3_states_h g3states.h HostProgramTargetName(mkg3states)) + +DependTarget() + diff --git a/nx-X11/lib/lbxutil/image/dfaxg42d.c b/nx-X11/lib/lbxutil/image/dfaxg42d.c new file mode 100644 index 000000000..609992d62 --- /dev/null +++ b/nx-X11/lib/lbxutil/image/dfaxg42d.c @@ -0,0 +1,420 @@ +/* $Xorg: dfaxg42d.c,v 1.3 2000/08/17 19:46:40 cpqbld Exp $ */ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler + * Copyright (c) 1991, 1992 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +/* $XFree86: xc/lib/lbxutil/image/dfaxg42d.c,v 1.5 2001/01/17 19:43:35 dawes Exp $ */ + +#include +#include +#include +#include +#include "g3states.h" +#include "lbxfax.h" +#include + +/* + * ------------------------------------------------------------------------- + * FAX G42D decoding for 1 bit images + * ------------------------------------------------------------------------- + */ + +static short sp_data, sp_bit; + + +/* + * Fetch a byte from the input stream + */ + +static unsigned char +fetchByte (unsigned char **inbuf) + +{ + unsigned char byte = **inbuf; + (*inbuf)++; + return (byte); +} + + +/* + * Decode a run of white. + */ + +static int +decode_white_run (unsigned char **inbuf) + +{ + short state = sp_bit; + short action; + int runlen = 0; + + for (;;) + { + if (sp_bit == 0) + { + nextbyte: + sp_data = fetchByte (inbuf); + } + + action = TIFFFax1DAction[state][sp_data]; + state = TIFFFax1DNextState[state][sp_data]; + if (action == ACT_INCOMP) + goto nextbyte; + if (action == ACT_INVALID) + return (G3CODE_INVALID); + if (action == ACT_EOL) + return (G3CODE_EOL); + sp_bit = state; + action = RUNLENGTH(action - ACT_WRUNT); + runlen += action; + if (action < 64) + return (runlen); + } +} + + +/* + * Decode a run of black. + */ + +static int +decode_black_run (unsigned char **inbuf) + +{ + short state = sp_bit + 8; + short action; + int runlen = 0; + + for (;;) + { + if (sp_bit == 0) + { + nextbyte: + sp_data = fetchByte (inbuf); + } + + action = TIFFFax1DAction[state][sp_data]; + state = TIFFFax1DNextState[state][sp_data]; + if (action == ACT_INCOMP) + goto nextbyte; + if (action == ACT_INVALID) + return (G3CODE_INVALID); + if (action == ACT_EOL) + return (G3CODE_EOL); + sp_bit = state; + action = RUNLENGTH(action - ACT_BRUNT); + runlen += action; + if (action < 64) + return (runlen); + state += 8; + } +} + + +/* + * Return the next uncompressed mode code word. + */ + +static int +decode_uncomp_code (unsigned char **inbuf) + +{ + short code; + + do { + if (sp_bit == 0 || sp_bit > 7) + sp_data = fetchByte (inbuf); + + code = TIFFFaxUncompAction[sp_bit][sp_data]; + sp_bit = TIFFFaxUncompNextState[sp_bit][sp_data]; + } while (code == ACT_INCOMP); + + return (code); +} + + +/* + * Fill a span with ones. + */ + +static void +fillspan (char *cp, + int x, int count) + +{ + static unsigned char masks[] = + { 0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; + + if (count <= 0) + return; + + cp += x>>3; + + if (x &= 7) + { + /* align to byte boundary */ + + if (count < 8 - x) { + *cp++ |= masks[count] >> x; + return; + } + + *cp++ |= 0xff >> x; + count -= 8 - x; + } + + while (count >= 8) + { + *cp++ = (char)0xff; + count -= 8; + } + + *cp |= masks[count]; +} + + +/* + * Return the next bit in the input stream. This is + * used to extract 2D tag values and the color tag + * at the end of a terminating uncompressed data code. + */ + +static int +nextbit (unsigned char **inbuf) + +{ + static unsigned char bitMask[8] = + { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; + int bit; + + if (sp_bit == 0) + sp_data = fetchByte (inbuf); + + bit = sp_data & bitMask[sp_bit]; + + if (++(sp_bit) > 7) + sp_bit = 0; + + return (bit); +} + + +static int +DecodeFaxG42D (unsigned char **inbuf, + unsigned char *refline, + int pixels_per_line, + unsigned char *outbuf) + +{ + int a0 = -1; + int b1, b2; + int run1, run2; /* for horizontal mode */ + short mode; + short color = 1; + + do { + if (sp_bit == 0 || sp_bit > 7) + sp_data = fetchByte (inbuf); + + mode = TIFFFax2DMode[sp_bit][sp_data]; + sp_bit = TIFFFax2DNextState[sp_bit][sp_data]; + + switch (mode) + { + case MODE_NULL: + break; + + case MODE_PASS: + b2 = LbxImageFindDiff (refline, a0, pixels_per_line, !color); + b1 = LbxImageFindDiff (refline, b2, pixels_per_line, color); + b2 = LbxImageFindDiff (refline, b1, pixels_per_line, !color); + + if (color) + { + if (a0 < 0) + a0 = 0; + fillspan ((char *) outbuf, a0, b2 - a0); + } + + a0 = b2; + break; + + case MODE_HORIZ: + if (color == 1) + { + run1 = decode_white_run (inbuf); + run2 = decode_black_run (inbuf); + } + else + { + run1 = decode_black_run (inbuf); + run2 = decode_white_run (inbuf); + } + + /* + * Do the appropriate fill. Note that we exit this logic with + * the same color that we enter with since we do 2 fills. This + * explains the somewhat obscure logic below. + */ + + if (a0 < 0) + a0 = 0; + if (a0 + run1 > pixels_per_line) + run1 = pixels_per_line - a0; + if (color) + fillspan ((char *) outbuf, a0, run1); + a0 += run1; + if (a0 + run2 > pixels_per_line) + run2 = pixels_per_line - a0; + if (!color) + fillspan ((char *) outbuf, a0, run2); + a0 += run2; + break; + + case MODE_VERT_V0: + case MODE_VERT_VR1: + case MODE_VERT_VR2: + case MODE_VERT_VR3: + case MODE_VERT_VL1: + case MODE_VERT_VL2: + case MODE_VERT_VL3: + b2 = LbxImageFindDiff (refline, a0, pixels_per_line, !color); + b1 = LbxImageFindDiff (refline, b2, pixels_per_line, color); + b1 += mode - MODE_VERT_V0; + + if (color) + { + if (a0 < 0) + a0 = 0; + fillspan ((char *) outbuf, a0, b1 - a0); + } + + color = !color; + a0 = b1; + break; + + case MODE_UNCOMP: + /* + * Uncompressed mode: select from the special set of code words. + */ + + if (a0 < 0) + a0 = 0; + do + { + mode = decode_uncomp_code (inbuf); + switch (mode) + { + case UNCOMP_RUN1: + case UNCOMP_RUN2: + case UNCOMP_RUN3: + case UNCOMP_RUN4: + case UNCOMP_RUN5: + run1 = mode - UNCOMP_RUN0; + fillspan ((char *) outbuf, a0+run1-1, 1); + a0 += run1; + break; + + case UNCOMP_RUN6: + a0 += 5; + break; + + case UNCOMP_TRUN0: + case UNCOMP_TRUN1: + case UNCOMP_TRUN2: + case UNCOMP_TRUN3: + case UNCOMP_TRUN4: + + run1 = mode - UNCOMP_TRUN0; + a0 += run1; + color = nextbit (inbuf) ? 0 : 1; + break; + + case UNCOMP_INVALID: + goto bad; + + case UNCOMP_EOF: + return (0); + } + } while (mode < UNCOMP_EXIT); + break; + + case MODE_ERROR_1: + /* fall thru... */ + case MODE_ERROR: + goto bad; + + default: + return (0); + } + + } while (a0 < pixels_per_line); + +bad: + return (a0 >= pixels_per_line); +} + + +int +LbxImageDecodeFaxG42D (unsigned char *inbuf, + unsigned char *outbuf, + int image_bytes, + int pixels_per_line, + int padded_bytes_per_scanline, + int reverse_bits) + +{ + int bytes_per_scanline = ROUNDUP8 (pixels_per_line); + unsigned char *refline, *refptr; + unsigned char *outbuf_start = outbuf; + int bytes_left = image_bytes; + int i; + + refline = (unsigned char *) malloc (bytes_per_scanline + 1); + refptr = refline + 1; + + for (i = 0; i < bytes_per_scanline + 1; i++) + refline[i] = 0xff; + + bzero (outbuf, image_bytes); + + sp_bit = 0; + sp_data = 0; + + while (bytes_left > 0) + { + if (!DecodeFaxG42D (&inbuf, refptr, pixels_per_line, outbuf)) + return (0); + + memcpy (refptr, outbuf, bytes_per_scanline); + + outbuf += padded_bytes_per_scanline; + bytes_left -= padded_bytes_per_scanline; + } + + free ((char *) refline); + + if (reverse_bits) + LbxReverseBits (outbuf_start, image_bytes); + + return (outbuf - outbuf_start); +} diff --git a/nx-X11/lib/lbxutil/image/dpackbits.c b/nx-X11/lib/lbxutil/image/dpackbits.c new file mode 100644 index 000000000..f0f2058d0 --- /dev/null +++ b/nx-X11/lib/lbxutil/image/dpackbits.c @@ -0,0 +1,100 @@ +/* $Xorg: dpackbits.c,v 1.4 2000/08/17 19:46:40 cpqbld Exp $ */ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler + * Copyright (c) 1991, 1992 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +/* $XFree86: xc/lib/lbxutil/image/dpackbits.c,v 1.3 2000/05/18 23:46:16 dawes Exp $ */ + +#include +#include +#include + +/* + * ------------------------------------------------------------------------- + * PackBits decoding for 8 bit color images + * ------------------------------------------------------------------------- + */ + +static void +DecodePackBits (char **inbuf, + int numPixels, + char *outbuf) + +{ + register char *inptr = *inbuf; + register int n, b; + + while (numPixels > 0) + { + n = (int) *inptr++; + + /* Watch out for compilers that don't sign extend chars... */ + + if (n >= 128) + n -= 256; + + if (n < 0) + { + /* replicate next byte -n+1 times */ + + if (n == -128) /* nop */ + continue; + + n = -n + 1; + numPixels -= n; + for (b = *inptr++; n-- > 0;) + *outbuf++ = b; + } + else + { + /* copy next n+1 bytes literally */ + + memcpy (outbuf, inptr, ++n); + outbuf += n; numPixels -= n; + inptr += n; + } + } + + *inbuf = inptr; +} + + +int +LbxImageDecodePackBits (char *inbuf, + char *outbuf, + int num_scan_lines, + int scan_line_size) + +{ + char *outbuf_start = outbuf; + int padded_scan_line_size = (scan_line_size % 4) ? + scan_line_size + (4 - scan_line_size % 4) : scan_line_size; + + while (num_scan_lines > 0) + { + DecodePackBits (&inbuf, scan_line_size, outbuf); + outbuf += padded_scan_line_size; + num_scan_lines--; + } + + return (outbuf - outbuf_start); +} diff --git a/nx-X11/lib/lbxutil/image/efaxg42d.c b/nx-X11/lib/lbxutil/image/efaxg42d.c new file mode 100644 index 000000000..a89b5e0d2 --- /dev/null +++ b/nx-X11/lib/lbxutil/image/efaxg42d.c @@ -0,0 +1,328 @@ +/* $Xorg: efaxg42d.c,v 1.3 2000/08/17 19:46:41 cpqbld Exp $ */ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler + * Copyright (c) 1991, 1992 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +/* $XFree86: xc/lib/lbxutil/image/efaxg42d.c,v 1.4 2001/01/17 19:43:35 dawes Exp $ */ + +#include +#include +#include +#include "lbxfax.h" +#include +#include "lbxbwcodes.h" + +/* + * ------------------------------------------------------------------------- + * FAX G42D encoding for 1 bit images + * ------------------------------------------------------------------------- + */ + +static short sp_data, sp_bit; + +static tableentry horizcode = + { 3, 0x1 }; /* 001 */ + +static tableentry passcode = + { 4, 0x1 }; /* 0001 */ + +static tableentry vcodes[7] = { + { 7, 0x03 }, /* 0000 011 */ + { 6, 0x03 }, /* 0000 11 */ + { 3, 0x03 }, /* 011 */ + { 1, 0x1 }, /* 1 */ + { 3, 0x2 }, /* 010 */ + { 6, 0x02 }, /* 0000 10 */ + { 7, 0x02 } /* 0000 010 */ +}; + +typedef struct { + unsigned char *bufStart; + unsigned char *bufPtr; + int bufSize; + int bytesLeft; +} Buffer; + + + +/* + * Flush bits to output buffer. + */ + +static int +flushbits (Buffer *outbuf) + +{ + if (outbuf->bytesLeft > 0) + { + *(outbuf->bufPtr++) = sp_data; + outbuf->bytesLeft--; + + sp_data = 0; + sp_bit = 8; + + return (1); + } + else + return (0); +} + + +/* + * Write a variable-length bit-value to the output stream. Values are + * assumed to be at most 16 bits. + */ + +static int +putbits (unsigned int bits, + unsigned int length, + Buffer *outbuf) + +{ + static int mask[9] = + {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; + + while (length > sp_bit) + { + sp_data |= bits >> (length - sp_bit); + length -= sp_bit; + if (!flushbits (outbuf)) + return (0); + } + + sp_data |= (bits & mask[length]) << (sp_bit - length); + sp_bit -= length; + + if (sp_bit == 0) + { + if (!flushbits (outbuf)) + return (0); + } + + return (1); +} + + +/* + * Write a code to the output stream. + */ + +static int +putcode (tableentry *te, + Buffer *outbuf) + +{ + return (putbits (te->code, te->length, outbuf)); +} + + +/* + * Write the sequence of codes that describes the specified span of + * zero's or one's. The appropriate table that holds the make-up and + * terminating codes is supplied. + */ + +static int +putspan (int span, + tableentry *tab, + Buffer *outbuf) + +{ + while (span >= 2624) + { + tableentry *te = &tab[63 + (2560 >> 6)]; + if (!putcode (te, outbuf)) + return (0); + span -= te->runlen; + } + + if (span >= 64) + { + tableentry *te = &tab[63 + (span >> 6)]; + if (!putcode (te, outbuf)) + return (0); + span -= te->runlen; + } + + if (!putcode (&tab[span], outbuf)) + return (0); + + return (1); +} + + + +#define PIXEL(buf,ix) ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1) + +static int +EncodeFaxG42D (unsigned char *inbuf, + unsigned char *refline, + int bits, + Buffer *outbuf) + +{ + short white = 1; + int a0 = 0; + int a1 = (PIXEL (inbuf, 0) != white ? + 0 : LbxImageFindDiff (inbuf, 0, bits, white)); + int b1 = (PIXEL (refline, 0) != white ? + 0 : LbxImageFindDiff (refline, 0, bits, white)); + int a2, b2; + + for (;;) + { + b2 = LbxImageFindDiff (refline, b1, bits, PIXEL (refline, b1)); + if (b2 >= a1) + { + int d = b1 - a1; + if (!(-3 <= d && d <= 3)) + { + /* horizontal mode */ + + a2 = LbxImageFindDiff (inbuf, a1, bits, PIXEL (inbuf, a1)); + if (!putcode (&horizcode, outbuf)) + return (0); + + if (a0 + a1 == 0 || PIXEL (inbuf, a0) == white) + { + if (!putspan(a1 - a0, TIFFFaxWhiteCodes, outbuf)) + return (0); + if (!putspan(a2 - a1, TIFFFaxBlackCodes, outbuf)) + return (0); + } + else + { + if (!putspan (a1 - a0, TIFFFaxBlackCodes, outbuf)) + return (0); + if (!putspan (a2 - a1, TIFFFaxWhiteCodes, outbuf)) + return (0); + } + + a0 = a2; + } + else + { + /* vertical mode */ + + if (!putcode (&vcodes[d+3], outbuf)) + return (0); + a0 = a1; + } + } + else + { + /* pass mode */ + + if (!putcode (&passcode, outbuf)) + return (0); + a0 = b2; + } + + if (a0 >= bits) + break; + + a1 = LbxImageFindDiff (inbuf, a0, bits, PIXEL (inbuf, a0)); + b1 = LbxImageFindDiff (refline, a0, bits, !PIXEL (inbuf, a0)); + b1 = LbxImageFindDiff (refline, b1, bits, PIXEL (inbuf, a0)); + } + + return (1); +} + + +int +LbxImageEncodeFaxG42D (unsigned char *inbuf, + unsigned char *outbuf, + int outbufSize, + int image_bytes, + int pixels_per_line, + int padded_bytes_per_scanline, + int reverse_bits, + int *bytesCompressed) + +{ + int bytes_per_scanline = ROUNDUP8 (pixels_per_line); + unsigned char *refline, *refptr; + unsigned char *save_inbuf = inbuf; + int bytes_left = image_bytes; + Buffer OutBuf; + int status, i; + + OutBuf.bufStart = OutBuf.bufPtr = outbuf; + OutBuf.bufSize = OutBuf.bytesLeft = outbufSize; + + if (!(refline = (unsigned char *) malloc (bytes_per_scanline + 1))) + return (LBX_IMAGE_COMPRESS_BAD_MALLOC); + + refptr = refline + 1; + + for (i = 0; i < bytes_per_scanline + 1; i++) + refline[i] = 0xff; + + if (reverse_bits) + LbxReverseBits (inbuf, image_bytes); + + sp_bit = 8; + sp_data = 0; + + while (bytes_left > 0) + { + if (!(status = EncodeFaxG42D (inbuf, refptr, + pixels_per_line, &OutBuf))) + { + goto bad; + } + + memcpy (refptr, inbuf, bytes_per_scanline); + + inbuf += padded_bytes_per_scanline; + bytes_left -= padded_bytes_per_scanline; + } + + status = putbits (EOL, 12, &OutBuf); + if (status) + status = putbits (EOL, 12, &OutBuf); + if (status && sp_bit != 8) + { + status = flushbits (&OutBuf); + } + + bad: + + free ((char *) refline); + + /* put the bits back the way they were */ + if (reverse_bits) + LbxReverseBits (save_inbuf, image_bytes); + + if (status) + { + *bytesCompressed = OutBuf.bufPtr - OutBuf.bufStart; + + if (OutBuf.bytesLeft > 0) + return (LBX_IMAGE_COMPRESS_SUCCESS); + else + return (LBX_IMAGE_COMPRESS_NOT_WORTH_IT); + } + else + return (LBX_IMAGE_COMPRESS_NOT_WORTH_IT); +} diff --git a/nx-X11/lib/lbxutil/image/epackbits.c b/nx-X11/lib/lbxutil/image/epackbits.c new file mode 100644 index 000000000..816fee57a --- /dev/null +++ b/nx-X11/lib/lbxutil/image/epackbits.c @@ -0,0 +1,202 @@ +/* $Xorg: epackbits.c,v 1.4 2000/08/17 19:46:41 cpqbld Exp $ */ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler + * Copyright (c) 1991, 1992 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include + +/* + * ------------------------------------------------------------------------- + * PackBits encoding for 8 bit color images + * ------------------------------------------------------------------------- + */ + +#define PutByte(byte,bufptr,bytesLeft) \ +{ \ + if (*bytesLeft < 1) {\ + *outbuf = outptr; \ + return (0); \ + } \ + *bufptr++ = byte; \ + (*bytesLeft)--; \ +} + + +static int +EncodePackBits (char *inbuf, + int numPixels, + char **outbuf, + int *bytesLeft) + +{ + register int pixelsLeft = numPixels; + register char *outptr = *outbuf; + register char *lastliteral; + register int n, b; + enum { BASE, LITERAL, RUN, LITERAL_RUN } state; + + state = BASE; + lastliteral = 0; + + while (pixelsLeft > 0) + { + /* + * Find the longest string of identical bytes. + */ + + b = *inbuf++, pixelsLeft--, n = 1; + for (; pixelsLeft > 0 && b == *inbuf; pixelsLeft--, inbuf++) + n++; + + again: + + switch (state) + { + case BASE: /* initial state, set run/literal */ + if (n > 1) + { + state = RUN; + + if (n > 128) + { + PutByte (-127, outptr, bytesLeft); + PutByte (b, outptr, bytesLeft); + n -= 128; + goto again; + } + + PutByte (-(n-1), outptr, bytesLeft); + PutByte (b, outptr, bytesLeft); + } + else + { + lastliteral = outptr; + PutByte (0, outptr, bytesLeft); + PutByte (b, outptr, bytesLeft); + state = LITERAL; + } + + break; + + case LITERAL: /* last object was literal string */ + if (n > 1) + { + state = LITERAL_RUN; + + if (n > 128) + { + PutByte (-127, outptr, bytesLeft); + PutByte (b, outptr, bytesLeft); + n -= 128; + goto again; + } + + PutByte (-(n-1), outptr, bytesLeft); /* encode run */ + PutByte (b, outptr, bytesLeft); + } + else + { /* extend literal */ + if (++(*lastliteral) == 127) + state = BASE; + PutByte (b, outptr, bytesLeft); + } + + break; + + case RUN: /* last object was run */ + if (n > 1) + { + if (n > 128) + { + PutByte (-127, outptr, bytesLeft); + PutByte (b, outptr, bytesLeft); + n -= 128; + goto again; + } + PutByte (-(n-1), outptr, bytesLeft); + PutByte (b, outptr, bytesLeft); + } + else + { + lastliteral = outptr; + PutByte (0, outptr, bytesLeft); + PutByte (b, outptr, bytesLeft); + state = LITERAL; + } + + break; + + case LITERAL_RUN: /* literal followed by a run */ + /* + * Check to see if previous run should + * be converted to a literal, in which + * case we convert literal-run-literal + * to a single literal. + */ + + if (n == 1 && outptr[-2] == (char)-1 && *lastliteral < 126) + { + state = (((*lastliteral) += 2) == 127 ? BASE : LITERAL); + outptr[-2] = outptr[-1]; /* replicate */ + } + else + state = RUN; + goto again; + } + } + + *outbuf = outptr; + + return (1); +} + + +int +LbxImageEncodePackBits (char *inbuf, + char *outbuf, + int outbufSize, + int format, + int depth, + int num_scan_lines, + int scan_line_size, + int *bytesCompressed) + +{ + char *outbuf_start = outbuf; + int padded_scan_line_size = (scan_line_size % 4) ? + scan_line_size + (4 - scan_line_size % 4) : scan_line_size; + int bytesLeft = outbufSize; + + while (num_scan_lines > 0) + { + if (!EncodePackBits (inbuf, scan_line_size, &outbuf, &bytesLeft)) + return (LBX_IMAGE_COMPRESS_NOT_WORTH_IT); + + inbuf += padded_scan_line_size; + num_scan_lines--; + } + + *bytesCompressed = outbuf - outbuf_start; + return (LBX_IMAGE_COMPRESS_SUCCESS); +} diff --git a/nx-X11/lib/lbxutil/image/lbxbwcodes.h b/nx-X11/lib/lbxutil/image/lbxbwcodes.h new file mode 100644 index 000000000..e26e2864c --- /dev/null +++ b/nx-X11/lib/lbxutil/image/lbxbwcodes.h @@ -0,0 +1,269 @@ +/* $Xorg: lbxbwcodes.h,v 1.3 2000/08/17 19:46:41 cpqbld Exp $ */ + +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler + * Copyright (c) 1991, 1992 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Note that these tables are ordered such that the + * index into the table is known to be either the + * run length, or (run length / 64) + a fixed offset. + * + * NB: The G3CODE_INVALID entries are only used + * during state generation (see mkg3states.c). + */ + +#ifdef __DARWIN__ +#ifndef TIFFaxWhiteCodes +#define TIFFFaxWhiteCodes Darwin_X_TIFFFaxWhiteCodes +#endif +#endif +tableentry TIFFFaxWhiteCodes[] = { + { 8, 0x35, 0 }, /* 0011 0101 */ + { 6, 0x7, 1 }, /* 0001 11 */ + { 4, 0x7, 2 }, /* 0111 */ + { 4, 0x8, 3 }, /* 1000 */ + { 4, 0xB, 4 }, /* 1011 */ + { 4, 0xC, 5 }, /* 1100 */ + { 4, 0xE, 6 }, /* 1110 */ + { 4, 0xF, 7 }, /* 1111 */ + { 5, 0x13, 8 }, /* 1001 1 */ + { 5, 0x14, 9 }, /* 1010 0 */ + { 5, 0x7, 10 }, /* 0011 1 */ + { 5, 0x8, 11 }, /* 0100 0 */ + { 6, 0x8, 12 }, /* 0010 00 */ + { 6, 0x3, 13 }, /* 0000 11 */ + { 6, 0x34, 14 }, /* 1101 00 */ + { 6, 0x35, 15 }, /* 1101 01 */ + { 6, 0x2A, 16 }, /* 1010 10 */ + { 6, 0x2B, 17 }, /* 1010 11 */ + { 7, 0x27, 18 }, /* 0100 111 */ + { 7, 0xC, 19 }, /* 0001 100 */ + { 7, 0x8, 20 }, /* 0001 000 */ + { 7, 0x17, 21 }, /* 0010 111 */ + { 7, 0x3, 22 }, /* 0000 011 */ + { 7, 0x4, 23 }, /* 0000 100 */ + { 7, 0x28, 24 }, /* 0101 000 */ + { 7, 0x2B, 25 }, /* 0101 011 */ + { 7, 0x13, 26 }, /* 0010 011 */ + { 7, 0x24, 27 }, /* 0100 100 */ + { 7, 0x18, 28 }, /* 0011 000 */ + { 8, 0x2, 29 }, /* 0000 0010 */ + { 8, 0x3, 30 }, /* 0000 0011 */ + { 8, 0x1A, 31 }, /* 0001 1010 */ + { 8, 0x1B, 32 }, /* 0001 1011 */ + { 8, 0x12, 33 }, /* 0001 0010 */ + { 8, 0x13, 34 }, /* 0001 0011 */ + { 8, 0x14, 35 }, /* 0001 0100 */ + { 8, 0x15, 36 }, /* 0001 0101 */ + { 8, 0x16, 37 }, /* 0001 0110 */ + { 8, 0x17, 38 }, /* 0001 0111 */ + { 8, 0x28, 39 }, /* 0010 1000 */ + { 8, 0x29, 40 }, /* 0010 1001 */ + { 8, 0x2A, 41 }, /* 0010 1010 */ + { 8, 0x2B, 42 }, /* 0010 1011 */ + { 8, 0x2C, 43 }, /* 0010 1100 */ + { 8, 0x2D, 44 }, /* 0010 1101 */ + { 8, 0x4, 45 }, /* 0000 0100 */ + { 8, 0x5, 46 }, /* 0000 0101 */ + { 8, 0xA, 47 }, /* 0000 1010 */ + { 8, 0xB, 48 }, /* 0000 1011 */ + { 8, 0x52, 49 }, /* 0101 0010 */ + { 8, 0x53, 50 }, /* 0101 0011 */ + { 8, 0x54, 51 }, /* 0101 0100 */ + { 8, 0x55, 52 }, /* 0101 0101 */ + { 8, 0x24, 53 }, /* 0010 0100 */ + { 8, 0x25, 54 }, /* 0010 0101 */ + { 8, 0x58, 55 }, /* 0101 1000 */ + { 8, 0x59, 56 }, /* 0101 1001 */ + { 8, 0x5A, 57 }, /* 0101 1010 */ + { 8, 0x5B, 58 }, /* 0101 1011 */ + { 8, 0x4A, 59 }, /* 0100 1010 */ + { 8, 0x4B, 60 }, /* 0100 1011 */ + { 8, 0x32, 61 }, /* 0011 0010 */ + { 8, 0x33, 62 }, /* 0011 0011 */ + { 8, 0x34, 63 }, /* 0011 0100 */ + { 5, 0x1B, 64 }, /* 1101 1 */ + { 5, 0x12, 128 }, /* 1001 0 */ + { 6, 0x17, 192 }, /* 0101 11 */ + { 7, 0x37, 256 }, /* 0110 111 */ + { 8, 0x36, 320 }, /* 0011 0110 */ + { 8, 0x37, 384 }, /* 0011 0111 */ + { 8, 0x64, 448 }, /* 0110 0100 */ + { 8, 0x65, 512 }, /* 0110 0101 */ + { 8, 0x68, 576 }, /* 0110 1000 */ + { 8, 0x67, 640 }, /* 0110 0111 */ + { 9, 0xCC, 704 }, /* 0110 0110 0 */ + { 9, 0xCD, 768 }, /* 0110 0110 1 */ + { 9, 0xD2, 832 }, /* 0110 1001 0 */ + { 9, 0xD3, 896 }, /* 0110 1001 1 */ + { 9, 0xD4, 960 }, /* 0110 1010 0 */ + { 9, 0xD5, 1024 }, /* 0110 1010 1 */ + { 9, 0xD6, 1088 }, /* 0110 1011 0 */ + { 9, 0xD7, 1152 }, /* 0110 1011 1 */ + { 9, 0xD8, 1216 }, /* 0110 1100 0 */ + { 9, 0xD9, 1280 }, /* 0110 1100 1 */ + { 9, 0xDA, 1344 }, /* 0110 1101 0 */ + { 9, 0xDB, 1408 }, /* 0110 1101 1 */ + { 9, 0x98, 1472 }, /* 0100 1100 0 */ + { 9, 0x99, 1536 }, /* 0100 1100 1 */ + { 9, 0x9A, 1600 }, /* 0100 1101 0 */ + { 6, 0x18, 1664 }, /* 0110 00 */ + { 9, 0x9B, 1728 }, /* 0100 1101 1 */ + { 11, 0x8, 1792 }, /* 0000 0001 000 */ + { 11, 0xC, 1856 }, /* 0000 0001 100 */ + { 11, 0xD, 1920 }, /* 0000 0001 101 */ + { 12, 0x12, 1984 }, /* 0000 0001 0010 */ + { 12, 0x13, 2048 }, /* 0000 0001 0011 */ + { 12, 0x14, 2112 }, /* 0000 0001 0100 */ + { 12, 0x15, 2176 }, /* 0000 0001 0101 */ + { 12, 0x16, 2240 }, /* 0000 0001 0110 */ + { 12, 0x17, 2304 }, /* 0000 0001 0111 */ + { 12, 0x1C, 2368 }, /* 0000 0001 1100 */ + { 12, 0x1D, 2432 }, /* 0000 0001 1101 */ + { 12, 0x1E, 2496 }, /* 0000 0001 1110 */ + { 12, 0x1F, 2560 }, /* 0000 0001 1111 */ + { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */ + { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */ + { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */ + { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */ + { 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */ +}; + +#ifdef __DARWIN__ +#ifndef TIFFaxBlackCodes +#define TIFFFaxBlackCodes Darwin_X_TIFFFaxBlackCodes +#endif +#endif +tableentry TIFFFaxBlackCodes[] = { + { 10, 0x37, 0 }, /* 0000 1101 11 */ + { 3, 0x2, 1 }, /* 010 */ + { 2, 0x3, 2 }, /* 11 */ + { 2, 0x2, 3 }, /* 10 */ + { 3, 0x3, 4 }, /* 011 */ + { 4, 0x3, 5 }, /* 0011 */ + { 4, 0x2, 6 }, /* 0010 */ + { 5, 0x3, 7 }, /* 0001 1 */ + { 6, 0x5, 8 }, /* 0001 01 */ + { 6, 0x4, 9 }, /* 0001 00 */ + { 7, 0x4, 10 }, /* 0000 100 */ + { 7, 0x5, 11 }, /* 0000 101 */ + { 7, 0x7, 12 }, /* 0000 111 */ + { 8, 0x4, 13 }, /* 0000 0100 */ + { 8, 0x7, 14 }, /* 0000 0111 */ + { 9, 0x18, 15 }, /* 0000 1100 0 */ + { 10, 0x17, 16 }, /* 0000 0101 11 */ + { 10, 0x18, 17 }, /* 0000 0110 00 */ + { 10, 0x8, 18 }, /* 0000 0010 00 */ + { 11, 0x67, 19 }, /* 0000 1100 111 */ + { 11, 0x68, 20 }, /* 0000 1101 000 */ + { 11, 0x6C, 21 }, /* 0000 1101 100 */ + { 11, 0x37, 22 }, /* 0000 0110 111 */ + { 11, 0x28, 23 }, /* 0000 0101 000 */ + { 11, 0x17, 24 }, /* 0000 0010 111 */ + { 11, 0x18, 25 }, /* 0000 0011 000 */ + { 12, 0xCA, 26 }, /* 0000 1100 1010 */ + { 12, 0xCB, 27 }, /* 0000 1100 1011 */ + { 12, 0xCC, 28 }, /* 0000 1100 1100 */ + { 12, 0xCD, 29 }, /* 0000 1100 1101 */ + { 12, 0x68, 30 }, /* 0000 0110 1000 */ + { 12, 0x69, 31 }, /* 0000 0110 1001 */ + { 12, 0x6A, 32 }, /* 0000 0110 1010 */ + { 12, 0x6B, 33 }, /* 0000 0110 1011 */ + { 12, 0xD2, 34 }, /* 0000 1101 0010 */ + { 12, 0xD3, 35 }, /* 0000 1101 0011 */ + { 12, 0xD4, 36 }, /* 0000 1101 0100 */ + { 12, 0xD5, 37 }, /* 0000 1101 0101 */ + { 12, 0xD6, 38 }, /* 0000 1101 0110 */ + { 12, 0xD7, 39 }, /* 0000 1101 0111 */ + { 12, 0x6C, 40 }, /* 0000 0110 1100 */ + { 12, 0x6D, 41 }, /* 0000 0110 1101 */ + { 12, 0xDA, 42 }, /* 0000 1101 1010 */ + { 12, 0xDB, 43 }, /* 0000 1101 1011 */ + { 12, 0x54, 44 }, /* 0000 0101 0100 */ + { 12, 0x55, 45 }, /* 0000 0101 0101 */ + { 12, 0x56, 46 }, /* 0000 0101 0110 */ + { 12, 0x57, 47 }, /* 0000 0101 0111 */ + { 12, 0x64, 48 }, /* 0000 0110 0100 */ + { 12, 0x65, 49 }, /* 0000 0110 0101 */ + { 12, 0x52, 50 }, /* 0000 0101 0010 */ + { 12, 0x53, 51 }, /* 0000 0101 0011 */ + { 12, 0x24, 52 }, /* 0000 0010 0100 */ + { 12, 0x37, 53 }, /* 0000 0011 0111 */ + { 12, 0x38, 54 }, /* 0000 0011 1000 */ + { 12, 0x27, 55 }, /* 0000 0010 0111 */ + { 12, 0x28, 56 }, /* 0000 0010 1000 */ + { 12, 0x58, 57 }, /* 0000 0101 1000 */ + { 12, 0x59, 58 }, /* 0000 0101 1001 */ + { 12, 0x2B, 59 }, /* 0000 0010 1011 */ + { 12, 0x2C, 60 }, /* 0000 0010 1100 */ + { 12, 0x5A, 61 }, /* 0000 0101 1010 */ + { 12, 0x66, 62 }, /* 0000 0110 0110 */ + { 12, 0x67, 63 }, /* 0000 0110 0111 */ + { 10, 0xF, 64 }, /* 0000 0011 11 */ + { 12, 0xC8, 128 }, /* 0000 1100 1000 */ + { 12, 0xC9, 192 }, /* 0000 1100 1001 */ + { 12, 0x5B, 256 }, /* 0000 0101 1011 */ + { 12, 0x33, 320 }, /* 0000 0011 0011 */ + { 12, 0x34, 384 }, /* 0000 0011 0100 */ + { 12, 0x35, 448 }, /* 0000 0011 0101 */ + { 13, 0x6C, 512 }, /* 0000 0011 0110 0 */ + { 13, 0x6D, 576 }, /* 0000 0011 0110 1 */ + { 13, 0x4A, 640 }, /* 0000 0010 0101 0 */ + { 13, 0x4B, 704 }, /* 0000 0010 0101 1 */ + { 13, 0x4C, 768 }, /* 0000 0010 0110 0 */ + { 13, 0x4D, 832 }, /* 0000 0010 0110 1 */ + { 13, 0x72, 896 }, /* 0000 0011 1001 0 */ + { 13, 0x73, 960 }, /* 0000 0011 1001 1 */ + { 13, 0x74, 1024 }, /* 0000 0011 1010 0 */ + { 13, 0x75, 1088 }, /* 0000 0011 1010 1 */ + { 13, 0x76, 1152 }, /* 0000 0011 1011 0 */ + { 13, 0x77, 1216 }, /* 0000 0011 1011 1 */ + { 13, 0x52, 1280 }, /* 0000 0010 1001 0 */ + { 13, 0x53, 1344 }, /* 0000 0010 1001 1 */ + { 13, 0x54, 1408 }, /* 0000 0010 1010 0 */ + { 13, 0x55, 1472 }, /* 0000 0010 1010 1 */ + { 13, 0x5A, 1536 }, /* 0000 0010 1101 0 */ + { 13, 0x5B, 1600 }, /* 0000 0010 1101 1 */ + { 13, 0x64, 1664 }, /* 0000 0011 0010 0 */ + { 13, 0x65, 1728 }, /* 0000 0011 0010 1 */ + { 11, 0x8, 1792 }, /* 0000 0001 000 */ + { 11, 0xC, 1856 }, /* 0000 0001 100 */ + { 11, 0xD, 1920 }, /* 0000 0001 101 */ + { 12, 0x12, 1984 }, /* 0000 0001 0010 */ + { 12, 0x13, 2048 }, /* 0000 0001 0011 */ + { 12, 0x14, 2112 }, /* 0000 0001 0100 */ + { 12, 0x15, 2176 }, /* 0000 0001 0101 */ + { 12, 0x16, 2240 }, /* 0000 0001 0110 */ + { 12, 0x17, 2304 }, /* 0000 0001 0111 */ + { 12, 0x1C, 2368 }, /* 0000 0001 1100 */ + { 12, 0x1D, 2432 }, /* 0000 0001 1101 */ + { 12, 0x1E, 2496 }, /* 0000 0001 1110 */ + { 12, 0x1F, 2560 }, /* 0000 0001 1111 */ + { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */ + { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */ + { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */ + { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */ + { 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */ +}; diff --git a/nx-X11/lib/lbxutil/image/lbxfax.h b/nx-X11/lib/lbxutil/image/lbxfax.h new file mode 100644 index 000000000..beac228b7 --- /dev/null +++ b/nx-X11/lib/lbxutil/image/lbxfax.h @@ -0,0 +1,60 @@ +/* $Xorg: lbxfax.h,v 1.3 2000/08/17 19:46:41 cpqbld Exp $ */ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler + * Copyright (c) 1991, 1992 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +/* $XFree86$ */ + +/* + * This header file contains various constants and tables needed + * for FAX G42D compression. + */ + +typedef struct tableentry { + unsigned short length; /* bit length of g3 code */ + unsigned short code; /* g3 code */ + short runlen; /* run length in bits */ +} tableentry; + +#define EOL 0x001 /* EOL code value - 0000 0000 0000 1 */ + +/* status values returned instead of a run length */ + +#define G3CODE_INVALID -1 +#define G3CODE_INCOMP -2 +#define G3CODE_EOL -3 +#define G3CODE_EOF -4 + +#define ROUNDUP8(x) ((x + 7) >> 3) + +#ifdef __DARWIN__ +#ifndef TIFFaxWhiteCodes +#define TIFFFaxWhiteCodes Darwin_X_TIFFFaxWhiteCodes +#define TIFFFaxBlackCodes Darwin_X_TIFFFaxBlackCodes +#endif +#endif +extern tableentry TIFFFaxWhiteCodes[]; +extern tableentry TIFFFaxBlackCodes[]; + +/* misc.c */ +extern int LbxImageFindDiff ( unsigned char *cp, int bs, int be, int color ); +extern void LbxReverseBits ( unsigned char *cp, int n ); diff --git a/nx-X11/lib/lbxutil/image/misc.c b/nx-X11/lib/lbxutil/image/misc.c new file mode 100644 index 000000000..fd228624e --- /dev/null +++ b/nx-X11/lib/lbxutil/image/misc.c @@ -0,0 +1,213 @@ +/* $Xorg: misc.c,v 1.3 2000/08/17 19:46:41 cpqbld Exp $ */ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler + * Copyright (c) 1991, 1992 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * This module contains utilities for image compression used + * by the LBX server and proxy. + */ + +#include "lbxfax.h" + +static unsigned char zeroruns[256] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, /* 0x00 - 0x0f */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0x10 - 0x1f */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x20 - 0x2f */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x30 - 0x3f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 - 0x5f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x70 - 0x7f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 - 0xaf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 - 0xbf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 - 0xcf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 - 0xdf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 - 0xef */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xf0 - 0xff */ +}; + +static unsigned char oneruns[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 - 0x0f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x2f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x4f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x80 - 0x8f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x90 - 0x9f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xa0 - 0xaf */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xb0 - 0xbf */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xc0 - 0xcf */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xd0 - 0xdf */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xe0 - 0xef */ + 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, /* 0xf0 - 0xff */ +}; + + +static unsigned char BitRevTable[256] = { + 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, + 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, + 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, + 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, + 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, + 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, + 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, + 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, + 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, + 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, + 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, + 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, + 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, + 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, + 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, + 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, + 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, + 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, + 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, + 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, + 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, + 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, + 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, + 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, + 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, + 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, + 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, + 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, + 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, + 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, + 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, + 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff +}; + + +/* + * Find a span of ones or zeros using the supplied table. The byte-aligned + * start of the bit string is supplied along with the start+end bit indices. + * The table gives the number of consecutive ones or zeros starting from the + * msb and is indexed by byte value. + */ + +static int +findspan (unsigned char **bpp, + int bs, int be, + unsigned char *tab) + +{ + unsigned char *bp = *bpp; + int bits = be - bs; + int n, span; + + /* + * Check partial byte on lhs. + */ + + if (bits > 0 && (n = (bs & 7))) + { + span = tab[(*bp << n) & 0xff]; + + if (span > 8 - n) /* table value too generous */ + span = 8 - n; + if (span > bits) /* constrain span to bit range */ + span = bits; + if (n+span < 8) /* doesn't extend to edge of byte */ + goto done; + + bits -= span; + bp++; + } + else + span = 0; + + /* + * Scan full bytes for all 1's or all 0's. + */ + + while (bits >= 8) + { + n = tab[*bp]; + span += n; + bits -= n; + if (n < 8) /* end of run */ + goto done; + bp++; + } + + /* + * Check partial byte on rhs. + */ + + if (bits > 0) + { + n = tab[*bp]; + span += (n > bits ? bits : n); + } + +done: + + *bpp = bp; + return (span); +} + +/* + * Return the offset of the next bit in the range [bs..be] that is different + * from the specified color. The end, be, is returned if no such bit exists. + */ + +int +LbxImageFindDiff (unsigned char *cp, + int bs, int be, int color) + +{ + cp += bs >> 3; /* adjust byte offset */ + return (bs + findspan (&cp, bs, be, color ? oneruns : zeroruns)); +} + + + + +void +LbxReverseBits (unsigned char *cp, + int n) + +{ + for (; n > 8; n -= 8) + { + cp[0] = BitRevTable[cp[0]]; + cp[1] = BitRevTable[cp[1]]; + cp[2] = BitRevTable[cp[2]]; + cp[3] = BitRevTable[cp[3]]; + cp[4] = BitRevTable[cp[4]]; + cp[5] = BitRevTable[cp[5]]; + cp[6] = BitRevTable[cp[6]]; + cp[7] = BitRevTable[cp[7]]; + cp += 8; + } + + while (n-- > 0) + *cp = BitRevTable[*cp], cp++; +} diff --git a/nx-X11/lib/lbxutil/image/mkg3states.c b/nx-X11/lib/lbxutil/image/mkg3states.c new file mode 100644 index 000000000..0e8fe3613 --- /dev/null +++ b/nx-X11/lib/lbxutil/image/mkg3states.c @@ -0,0 +1,761 @@ +/* $Xorg: mkg3states.c,v 1.3 2000/08/17 19:46:41 cpqbld Exp $ */ +/* + * Copyright (c) 1991, 1992 Sam Leffler + * Copyright (c) 1991, 1992 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +/* $XFree86: xc/lib/lbxutil/image/mkg3states.c,v 1.3 1999/02/01 11:55:49 dawes Exp $ */ + +/* + * Program to construct Group 3 & Group 4 decoding tables. + * + * This code is derived from code by Michael P. Marking. In + * particular, the algorithms to generate the null_mode and + * horiz_mode state tables are his. See the comments below + * for more information. + * + * BEGIN (from the original source) + LEGAL + * Copyright 1989, 1990 Michael P. Marking, Post Office Box 8039, + * Scottsdale, Arizona 85252-8039. All rights reserved. + * + * License is granted by the copyright holder to distribute and use this + * code without payment of royalties or the necessity of notification as + * long as this notice (all the text under "LEGAL") is included. + * + * This program is offered without any warranty of any kind. It includes + * no warranty of merchantability or fitness for any purpose. Testing and + * suitability for any use are the sole responsibility of the user. + * + INFORMATION + * Although there is no support offered with this program, the author will + * endeavor to correct errors. Updates will also be made available from + * time to time. + * + * Contact: Michael P. Marking, Post Office Box 8039, Scottsdale, Arizona + * 85252-8039 USA. Replies are not guaranteed to be swift. Beginning + * July 1990, e-mail may be sent to uunet!ipel!marking. + * + * Also beginning in July 1990, this code will be archived at the + * ipel!phoenix BBS in file g3g4.zoo. The 24-hour telephone number + * for 300/1200/2400 is (602)274-0462. When logging in, specify user + * "public", system "bbs", and password "public". + * + * This code is also available from the C Users Group in volume 317. + * + * END (from the original source) + */ +#include +#include +#include + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +#define WHITE 0 +#define BLACK 1 + +/* + * G3 2D and G4 decoding modes. Note that + * the vertical modes are ordered so that + * (mode - MODE_VERT_V0) gives the vertical + * adjustment for the b1 parameter. + */ +#define MODE_NULL 0 +#define MODE_PASS 1 +#define MODE_HORIZ 2 +#define MODE_VERT_VL3 3 +#define MODE_VERT_VL2 4 +#define MODE_VERT_VL1 5 +#define MODE_VERT_V0 6 +#define MODE_VERT_VR1 7 +#define MODE_VERT_VR2 8 +#define MODE_VERT_VR3 9 +#define MODE_UNCOMP 10 +#define MODE_ERROR 11 +#define MODE_ERROR_1 12 + +unsigned long append_0 ( unsigned long prefix ); +unsigned long append_1 ( unsigned long prefix ); + +unsigned long append_0 (unsigned long prefix) +{ + return (prefix + (1L<<16)); +} + +unsigned long append_1 (unsigned long prefix) +{ + static unsigned short prefix_bit[16] = { + 0x8000, 0x4000, 0x2000, 0x1000, + 0x0800, 0x0400, 0x0200, 0x0100, + 0x0080, 0x0040, 0x0020, 0x0010, + 0x0008, 0x0004, 0x0002, 0x0001 + }; + unsigned char len = (prefix >> 16) & 0xf; + return (append_0(prefix) + prefix_bit[len]); +} + +#define G3CODES +#include "lbxfax.h" +#include "lbxbwcodes.h" + +short search_table ( unsigned long prefix, tableentry *tab, int n ); +short white_run_length ( unsigned long prefix ); +short black_run_length ( unsigned long prefix ); +short horiz_mode_code_black ( short runlen ); +short horiz_mode_code_white ( short runlen ); +void write_define ( FILE *fd, char *name, int value, char *comment ); +void write_preamble ( FILE *fd ); +void extern_table ( FILE *fd, char *name ); +void write_tables ( FILE *fd ); +short find_null_mode_prefix ( long prefix ); +short find_horiz_mode_prefix ( long prefix, int color ); +short find_uncomp_mode_prefix ( long prefix ); +short null_mode_type ( long prefix ); +short uncomp_mode_type ( long prefix ); +void build_null_mode_tables ( void ); +void build_horiz_mode_tables ( void ); +void build_uncomp_mode_tables ( void ); + +short search_table (unsigned long prefix, tableentry *tab, int n) +{ + unsigned short len = (prefix >> 16) & 0xf; + unsigned short code = (prefix & 0xffff) >> (16 - len); + + while (n-- > 0) { + if (tab->length == len && tab->code == code) + return ((short) tab->runlen); + tab++; + } + return (G3CODE_INCOMP); +} + +#define NCODES(a) (sizeof (a) / sizeof (a[0])) +short white_run_length (unsigned long prefix) +{ + return (search_table(prefix, TIFFFaxWhiteCodes, NCODES(TIFFFaxWhiteCodes))); +} + +short black_run_length (unsigned long prefix) +{ + return (search_table(prefix, TIFFFaxBlackCodes, NCODES(TIFFFaxBlackCodes))); +} +#undef NCODES + +#define MAX_NULLPREFIX 200 /* max # of null-mode prefixes */ +typedef unsigned char NullModeTable[MAX_NULLPREFIX][256]; +#define MAX_HORIZPREFIX 250 /* max # of incomplete 1-D prefixes */ +typedef unsigned char HorizModeTable[MAX_HORIZPREFIX][256]; + + /* the bit string corresponding to this row of the decoding table */ +long null_mode_prefix[MAX_NULLPREFIX]; +NullModeTable null_mode; /* MODE_*, indexed by bit and byte */ +NullModeTable null_mode_next_state; /* next row of decoding tables to use */ + /* number of prefixes or rows in the G4 decoding tables */ +short null_mode_prefix_count = 0; + +void write_null_mode_table ( FILE *fd, NullModeTable table, char *name ); +void write_horiz_mode_table ( FILE *fd, HorizModeTable table, char *name ); + +/* + * 2D uncompressed mode codes. Note + * that two groups of codes are arranged + * so that the decoder can caluclate the + * length of the run by subtracting the + * code from a known base value. + */ +#define UNCOMP_INCOMP 0 +/* runs of [0]*1 */ +#define UNCOMP_RUN0 1 +#define UNCOMP_RUN1 2 +#define UNCOMP_RUN2 3 +#define UNCOMP_RUN3 4 +#define UNCOMP_RUN4 5 +#define UNCOMP_RUN5 6 +#define UNCOMP_RUN6 7 +/* runs of [0]* w/ terminating color */ +#define UNCOMP_TRUN0 8 +#define UNCOMP_TRUN1 9 +#define UNCOMP_TRUN2 10 +#define UNCOMP_TRUN3 11 +#define UNCOMP_TRUN4 12 +/* special code for unexpected EOF */ +#define UNCOMP_EOF 13 +/* invalid code encountered */ +#define UNCOMP_INVALID 14 + +long uncomp_mode_prefix[MAX_NULLPREFIX]; +NullModeTable uncomp_mode; +NullModeTable uncomp_mode_next_state; +short uncomp_mode_prefix_count = 0; + +/* + * Decoding action values for horiz_mode. + */ +#define ACT_INCOMP 0 /* incompletely decoded code */ +#define ACT_INVALID 1 /* invalide code */ +#define ACT_WRUNT 2 /* terminating white run code */ +#define ACT_WRUN 65 /* non-terminating white run code */ +#define ACT_BRUNT 106 /* terminating black run code */ +#define ACT_BRUN 169 /* non-terminating black run code */ +#define ACT_EOL 210 /* end-of-line code */ +HorizModeTable horiz_mode; + +short horiz_mode_code_black (short runlen) +{ + return (runlen < 64 ? runlen + ACT_BRUNT : (runlen / 64) + ACT_BRUN); +} + +short horiz_mode_code_white (short runlen) +{ + return (runlen < 64 ? runlen + ACT_WRUNT : (runlen / 64) + ACT_WRUN); +} + +/* + * If the corresponding horiz_mode entry is ACT_INCOMP + * this entry is a row number for decoding the next byte; + * otherwise, it is the bit number with which to continue + * decoding the next codeword. + */ +HorizModeTable horiz_mode_next_state; + /* prefixes corresponding to the rows of the decoding table */ +long horiz_mode_prefix[MAX_HORIZPREFIX]; + /* color of next run, BLACK or WHITE */ +char horiz_mode_color[MAX_HORIZPREFIX]; +short horiz_mode_prefix_count = 0; + +static unsigned char bit_mask[8] = + { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; + + +int verbose = FALSE; +char *storage_class = ""; + +int +main (int argc, char *argv[]) +{ + while (argc > 1 && argv[1][0] == '-') { + if (strcmp(argv[1], "-v") == 0) { + verbose = TRUE; + argc--, argv++; + } else if (strcmp(argv[1], "-c") == 0) { + storage_class = "const "; + argc--, argv++; + } + } + build_null_mode_tables(); /* null mode decoding tables */ + if (verbose) { + fprintf(stderr, "%d null mode prefixes defined\n", + (int) null_mode_prefix_count); + fprintf(stderr, "building uncompressed mode scripts...\n"); + } + build_uncomp_mode_tables(); /* uncompressed mode decoding tables */ + if (verbose) { + fprintf(stderr, "%d uncompressed mode prefixes defined\n", + (int) uncomp_mode_prefix_count); + fprintf(stderr, "building 1D scripts...\n"); + } + build_horiz_mode_tables(); /* 1D decoding tables */ + if (verbose) + fprintf(stderr, "%d incomplete prefixes defined\n", + (int) horiz_mode_prefix_count); + write_tables(stdout); + exit(0); +} + +void write_null_mode_table (fd, table, name) +FILE *fd; +NullModeTable table; +char *name; +{ + int i, j; + char* outersep; + char* sep; + + fprintf(fd, "%sunsigned char\t%s[%d][256] = {", storage_class, + name, (int) null_mode_prefix_count); + outersep = ""; + for (i = 0; i < null_mode_prefix_count; i++) { + fprintf(fd, "%s\n/* prefix %d */ {\n", outersep, i); + sep = " "; + for (j = 0; j < 256; j++) { + fprintf(fd, "%s%2d", sep, (int) table[i][j]); + if (((j+1) % 16) == 0) { + fprintf(fd, ", /* %3d-%3d */\n", j-15, j); + sep = " "; + } else + sep = ","; + } + fprintf(fd, "}"); + outersep = ","; + } + fprintf(fd, "\n};\n"); +} + +void +write_horiz_mode_table (FILE *fd, HorizModeTable table, char *name) +{ + int i, j; + char* outersep; + char* sep; + + fprintf(fd, "%s unsigned char\t%s[%d][256] = {", storage_class, + name, (int) horiz_mode_prefix_count); + outersep = ""; + for (i = 0; i < horiz_mode_prefix_count; i++) { + fprintf(fd, "%s\n/* prefix %d */ {\n", outersep, i); + sep = " "; + for (j = 0; j < 256; j++) { + fprintf(fd, "%s%3d", sep, (int) table[i][j]); + if (((j+1) % 14) == 0) { + fprintf(fd, ", /* %3d-%3d */\n", j-13, j); + sep = " "; + } else + sep = ","; + } + fprintf(fd, "\n}"); + outersep = ","; + } + fprintf(fd, "\n};\n"); +} + +void +write_define(FILE *fd, char *name, int value, char *comment) +{ + fprintf(fd, "#define\t%s\t%d", name, value); + if (comment) + fprintf(fd, "\t/* %s */", comment); + fprintf(fd, "\n"); +} + +void +write_preamble(FILE *fd) +{ + fprintf(fd, "%s\n", +"/* DO NOT EDIT THIS FILE, IT WAS AUTOMATICALLY CREATED BY mkg3state */"); + write_define(fd, "ACT_INCOMP", ACT_INCOMP, "incompletely decoded code"); + write_define(fd, "ACT_INVALID", ACT_INVALID, "invalide code"); + write_define(fd, "ACT_WRUNT", ACT_WRUNT, "terminating white run code"); + write_define(fd, "ACT_WRUN", ACT_WRUN, "non-terminating white run code"); + write_define(fd, "ACT_BRUNT", ACT_BRUNT, "terminating black run code"); + write_define(fd, "ACT_BRUN", ACT_BRUN, "non-terminating black run code"); + write_define(fd, "ACT_EOL", ACT_EOL, "end-of-line code"); + fprintf(fd, "\n"); + fprintf(fd, "/* modes that the decoder can be in */\n"); + write_define(fd, "MODE_NULL", MODE_NULL, NULL); + write_define(fd, "MODE_PASS", MODE_PASS, NULL); + write_define(fd, "MODE_HORIZ", MODE_HORIZ, NULL); + write_define(fd, "MODE_VERT_V0", MODE_VERT_V0, NULL); + write_define(fd, "MODE_VERT_VR1", MODE_VERT_VR1, NULL); + write_define(fd, "MODE_VERT_VR2", MODE_VERT_VR2, NULL); + write_define(fd, "MODE_VERT_VR3", MODE_VERT_VR3, NULL); + write_define(fd, "MODE_VERT_VL1", MODE_VERT_VL1, NULL); + write_define(fd, "MODE_VERT_VL2", MODE_VERT_VL2, NULL); + write_define(fd, "MODE_VERT_VL3", MODE_VERT_VL3, NULL); + write_define(fd, "MODE_UNCOMP", MODE_UNCOMP, NULL); + write_define(fd, "MODE_ERROR", MODE_ERROR, NULL); + write_define(fd, "MODE_ERROR_1", MODE_ERROR_1, NULL); + fprintf(fd, "\n"); + fprintf(fd, "#define\tRUNLENGTH(ix) (TIFFFaxWhiteCodes[ix].runlen)\n"); + fprintf(fd, "\n"); + write_define(fd, "UNCOMP_INCOMP", UNCOMP_INCOMP, NULL); + fprintf(fd, "/* runs of [0]*1 */\n"); + write_define(fd, "UNCOMP_RUN0", UNCOMP_RUN0, NULL); + write_define(fd, "UNCOMP_RUN1", UNCOMP_RUN1, NULL); + write_define(fd, "UNCOMP_RUN2", UNCOMP_RUN2, NULL); + write_define(fd, "UNCOMP_RUN3", UNCOMP_RUN3, NULL); + write_define(fd, "UNCOMP_RUN4", UNCOMP_RUN4, NULL); + write_define(fd, "UNCOMP_RUN5", UNCOMP_RUN5, NULL); + write_define(fd, "UNCOMP_RUN6", UNCOMP_RUN6, NULL); + fprintf(fd, "/* runs of [0]* w/ terminating color */\n"); + write_define(fd, "UNCOMP_TRUN0", UNCOMP_TRUN0, NULL); + write_define(fd, "UNCOMP_TRUN1", UNCOMP_TRUN1, NULL); + write_define(fd, "UNCOMP_TRUN2", UNCOMP_TRUN2, NULL); + write_define(fd, "UNCOMP_TRUN3", UNCOMP_TRUN3, NULL); + write_define(fd, "UNCOMP_TRUN4", UNCOMP_TRUN4, NULL); + fprintf(fd, "/* special code for unexpected EOF */\n"); + write_define(fd, "UNCOMP_EOF", UNCOMP_EOF, NULL); + fprintf(fd, "/* invalid code encountered */\n"); + write_define(fd, "UNCOMP_INVALID", UNCOMP_INVALID, NULL); + fprintf(fd, "/* codes >= terminate uncompress mode */\n"); + fprintf(fd, "#define\tUNCOMP_EXIT UNCOMP_TRUN0\n"); + fprintf(fd, "\n"); +} + +void +extern_table(FILE *fd, char *name) +{ + fprintf(fd, "extern\t%sunsigned char %s[][256];\n", storage_class, name); +} + +void +write_tables(FILE *fd) +{ + write_preamble(fd); + write_null_mode_table(fd, null_mode, "TIFFFax2DMode"); + write_null_mode_table(fd, null_mode_next_state, "TIFFFax2DNextState"); + write_null_mode_table(fd, uncomp_mode, "TIFFFaxUncompAction"); + write_null_mode_table(fd, uncomp_mode_next_state, "TIFFFaxUncompNextState"); + write_horiz_mode_table(fd, horiz_mode, "TIFFFax1DAction"); + write_horiz_mode_table(fd, horiz_mode_next_state, "TIFFFax1DNextState"); +} + +short +find_null_mode_prefix (long prefix) +{ + short j1; + + if (prefix == 0L) + return (0); + for (j1 = 8; j1 < null_mode_prefix_count; j1++) + if (prefix == null_mode_prefix[j1]) + return (j1); + if (null_mode_prefix_count == MAX_NULLPREFIX) { + fprintf(stderr, "ERROR: null mode prefix table overflow\n"); + exit(1); + } + if (verbose) + fprintf(stderr, "adding null mode prefix[%d] 0x%lx\n", + (int) null_mode_prefix_count, prefix); + null_mode_prefix[null_mode_prefix_count++] = prefix; + return (null_mode_prefix_count-1); +} + +short +find_horiz_mode_prefix (long prefix, int color) +{ + short j1; + + for (j1 = 0; j1 < horiz_mode_prefix_count; j1++) + if (prefix == horiz_mode_prefix[j1] && horiz_mode_color[j1] == color) + return (j1); + /* + * It wasn't found, so add it to the tables, but first, is there room? + */ + if (horiz_mode_prefix_count == MAX_HORIZPREFIX) { + fprintf(stderr, "ERROR: 1D prefix table overflow\n"); + exit(1); + } + /* OK, there's room... */ + if (verbose) + fprintf(stderr, "\nhoriz mode prefix %d, color %c = 0x%lx ", + (int) horiz_mode_prefix_count, "WB"[color], prefix); + horiz_mode_prefix[horiz_mode_prefix_count] = prefix; + horiz_mode_color[horiz_mode_prefix_count] = color; + horiz_mode_prefix_count++; + return (horiz_mode_prefix_count - 1); +} + +short +find_uncomp_mode_prefix (long prefix) +{ + short j1; + + if (prefix == 0L) + return (0); + for (j1 = 8; j1 < uncomp_mode_prefix_count; j1++) + if (prefix == uncomp_mode_prefix[j1]) + return (j1); + if (uncomp_mode_prefix_count == MAX_NULLPREFIX) { + fprintf(stderr, "ERROR: uncomp mode prefix table overflow\n"); + exit(1); + } + if (verbose) + fprintf(stderr, "adding uncomp mode prefix[%d] 0x%lx\n", + (int) uncomp_mode_prefix_count, prefix); + uncomp_mode_prefix[uncomp_mode_prefix_count++] = prefix; + return (uncomp_mode_prefix_count-1); +} + +short +null_mode_type (long prefix) +{ + switch (prefix) { + case 0x18000L: return (MODE_VERT_V0); /* 1 */ + case 0x36000L: return (MODE_VERT_VR1); /* 011 */ + case 0x34000L: return (MODE_VERT_VL1); /* 010 */ + case 0x32000L: return (MODE_HORIZ); /* 001 */ + case 0x41000L: return (MODE_PASS); /* 0001 */ + case 0x60C00L: return (MODE_VERT_VR2); /* 0000 11 */ + case 0x60800L: return (MODE_VERT_VL2); /* 0000 10 */ + case 0x70600L: return (MODE_VERT_VR3); /* 0000 011 */ + case 0x70400L: return (MODE_VERT_VL3); /* 0000 010 */ + case 0x80200L: return (MODE_ERROR); /* 0000 0010 */ + case 0x90300L: return (MODE_ERROR); /* 0000 0011 0 */ + case 0xA0380L: return (MODE_ERROR); /* 0000 0011 10 */ + case 0xA03C0L: return (MODE_UNCOMP); /* 0000 0011 11 */ + /* + * Under the assumption that there are no + * errors in the file, then this bit string + * can only be the beginning of an EOL code. + */ + case 0x70000L: return (MODE_ERROR_1); /* 0000 000 */ + } + return (-1); +} + +short +uncomp_mode_type (long prefix) +{ + short code; + short len; + switch (prefix) { + case 0x18000L: return (UNCOMP_RUN1); /* 1 */ + case 0x24000L: return (UNCOMP_RUN2); /* 01 */ + case 0x32000L: return (UNCOMP_RUN3); /* 001 */ + case 0x41000L: return (UNCOMP_RUN4); /* 0001 */ + case 0x50800L: return (UNCOMP_RUN5); /* 0000 1 */ + case 0x60400L: return (UNCOMP_RUN6); /* 0000 01 */ + case 0x70200L: return (UNCOMP_TRUN0); /* 0000 001 */ + case 0x80100L: return (UNCOMP_TRUN1); /* 0000 0001 */ + case 0x90080L: return (UNCOMP_TRUN2); /* 0000 0000 1 */ + case 0xA0040L: return (UNCOMP_TRUN3); /* 0000 0000 01 */ + case 0xB0020L: return (UNCOMP_TRUN4); /* 0000 0000 001 */ + } + code = prefix & 0xffffL; + len = (prefix >> 16) & 0xf; + return ((code || len > 10) ? UNCOMP_INVALID : -1); +} + +#define BASESTATE(b) ((unsigned char) ((b) & 0x7)) + +void +build_null_mode_tables(void) +{ + short prefix; + + /* + * Note: the first eight entries correspond to + * a null prefix and starting bit numbers 0-7. + */ + null_mode_prefix_count = 8; + for (prefix = 0; prefix < null_mode_prefix_count; prefix++) { + short byte; + for (byte = 0; byte < 256; byte++) { + short firstbit; + short bit; + long curprefix; + char found_code = FALSE; + + if (prefix < 8) { + curprefix = 0L; + firstbit = prefix; + } else { + curprefix = null_mode_prefix[prefix]; + firstbit = 0; + } + for (bit = firstbit; bit < 8 && !found_code; bit++) { + short mode; + + if (bit_mask[bit] & byte) + curprefix = append_1(curprefix); + else + curprefix = append_0(curprefix); + switch (mode = null_mode_type(curprefix)) { + case MODE_PASS: + case MODE_HORIZ: + case MODE_VERT_V0: + case MODE_VERT_VR1: + case MODE_VERT_VR2: + case MODE_VERT_VR3: + case MODE_VERT_VL1: + case MODE_VERT_VL2: + case MODE_VERT_VL3: + case MODE_UNCOMP: + case MODE_ERROR: + case MODE_ERROR_1: + /* + * NOTE: if the bit number is 8, then the table + * entry will be zero, which indicates a new byte + * is to be fetched during the decoding process + */ + found_code = TRUE; + null_mode[prefix][byte] = (unsigned char) mode; + null_mode_next_state[prefix][byte] = BASESTATE(bit+1); + break; + } + } + if (!found_code) { + null_mode_next_state[prefix][byte] = (unsigned char) + find_null_mode_prefix(curprefix); + /* + * This indicates to the decoder that + * no valid code has yet been identified. + */ + null_mode[prefix][byte] = MODE_NULL; + } + } + } +} + +void +build_horiz_mode_tables(void) +{ + unsigned short byte; + short prefix; + + /* + * The first 8 are for white, + * the second 8 are for black, + * beginning with bits 0-7. + */ + horiz_mode_prefix_count = 16; + for (prefix = 0; prefix < horiz_mode_prefix_count; prefix++) + for (byte = 0; byte < 256; byte++) { + short bits_digested = 0; + short bit; + short firstbit; + char color; + unsigned long curprefix; + + if (prefix < 8) { + color = WHITE; + curprefix = 0L; + firstbit = prefix; + } else if (prefix < 16) { + color = BLACK; + curprefix = 0L; + firstbit = prefix - 8; + } else { + color = horiz_mode_color[prefix]; + curprefix = horiz_mode_prefix[prefix]; + firstbit = 0; + } + for (bit = firstbit; bit < 8 && !bits_digested; bit++) { + if (bit_mask[bit] & byte) + curprefix = append_1(curprefix); + else + curprefix = append_0(curprefix); + /* + * The following conversion allows for arbitrary strings of + * zeroes to precede the end-of-line code 0000 0000 0001. + * It assumes no errors in the data, and is based on + * the assumption that the code replaced (12 consecutive + * zeroes) can only be "legally" encountered before the + * end-of-line code. This assumption is valid only for + * a Group 3 image; the combination will never occur + * in horizontal mode in a proper Group 4 image. + */ + if (curprefix == 0xC0000L) + curprefix = 0xB0000L; + if (color == WHITE) { + short runlength = white_run_length(curprefix); + + if (runlength == G3CODE_INVALID) { + horiz_mode[prefix][byte] = (unsigned char) ACT_INVALID; + horiz_mode_next_state[prefix][byte] = (unsigned char) bit; + bits_digested = bit + 1; + } else if (runlength == G3CODE_EOL) { /* Group 3 only */ + horiz_mode[prefix][byte] = (unsigned char) ACT_EOL; + horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1); + bits_digested = bit + 1; + } else if (runlength != G3CODE_INCOMP) { + horiz_mode[prefix][byte] = (unsigned char) + horiz_mode_code_white(runlength); + horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1); + bits_digested = bit + 1; + } + } else { /* color == BLACK */ + short runlength = black_run_length(curprefix); + + if (runlength == G3CODE_INVALID) { + horiz_mode[prefix][byte] = (unsigned char) ACT_INVALID; + horiz_mode_next_state[prefix][byte] = (unsigned char) (bit+8); + bits_digested = bit + 1; + } else if (runlength == G3CODE_EOL) { /* Group 3 only */ + horiz_mode[prefix][byte] = (unsigned char) ACT_EOL; + horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1); + bits_digested = bit + 1; + } else if (runlength != G3CODE_INCOMP) { + horiz_mode[prefix][byte] = (unsigned char) + horiz_mode_code_black(runlength); + horiz_mode_next_state[prefix][byte] = BASESTATE(bit+1); + bits_digested = bit + 1; + } + } + } + if (!bits_digested) { /* no codewords after examining byte */ + horiz_mode[prefix][byte] = (unsigned char) ACT_INCOMP; + horiz_mode_next_state[prefix][byte] = (unsigned char) + find_horiz_mode_prefix(curprefix, color); + } + } +} + +void +build_uncomp_mode_tables(void) +{ + short prefix; + + /* + * Note: the first eight entries correspond to + * a null prefix and starting bit numbers 0-7. + */ + uncomp_mode_prefix_count = 8; + for (prefix = 0; prefix < uncomp_mode_prefix_count; prefix++) { + short byte; + for (byte = 0; byte < 256; byte++) { + short firstbit; + short bit; + long curprefix; + char found_code = FALSE; + + if (prefix < 8) { + curprefix = 0L; + firstbit = prefix; + } else { + curprefix = uncomp_mode_prefix[prefix]; + firstbit = 0; + } + for (bit = firstbit; bit < 8 && !found_code; bit++) { + short mode; + + if (bit_mask[bit] & byte) + curprefix = append_1(curprefix); + else + curprefix = append_0(curprefix); + mode = uncomp_mode_type(curprefix); + if (mode != -1) { + /* + * NOTE: if the bit number is 8, then the table + * entry will be zero, which indicates a new byte + * is to be fetched during the decoding process + */ + found_code = TRUE; + uncomp_mode[prefix][byte] = (unsigned char) mode; + uncomp_mode_next_state[prefix][byte] = BASESTATE(bit+1); + break; + } + } + if (!found_code) { + uncomp_mode_next_state[prefix][byte] = (unsigned char) + find_uncomp_mode_prefix(curprefix); + /* + * This indicates to the decoder that + * no valid code has yet been identified. + */ + uncomp_mode[prefix][byte] = UNCOMP_INCOMP; + } + } + } +} diff --git a/nx-X11/lib/lbxutil/lbx_zlib/Imakefile b/nx-X11/lib/lbxutil/lbx_zlib/Imakefile new file mode 100644 index 000000000..ddcecc6fd --- /dev/null +++ b/nx-X11/lib/lbxutil/lbx_zlib/Imakefile @@ -0,0 +1,22 @@ +XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:46:41 cpqbld Exp $ +XCOMM $XdotOrg: xc/lib/lbxutil/lbx_zlib/Imakefile,v 1.3 2004/10/10 17:13:11 herrb Exp $ + +#include + +SRCS = lbx_zlib.c lbx_zlib_io.c reqstats.c + +OBJS = lbx_zlib.o lbx_zlib_io.o reqstats.o + +#if !HasZlib +ZLIB_INCLUDES= -I../../zlib +#endif + +INCLUDES = -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/include \ + -I../../../include/extensions $(ZLIB_INCLUDES) + +SubdirLibraryRule($(OBJS)) +NormalLibraryObjectRule() +NormalLintTarget($(SRCS)) + +DependTarget() + diff --git a/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.c b/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.c new file mode 100644 index 000000000..e7105a0c7 --- /dev/null +++ b/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.c @@ -0,0 +1,543 @@ +/* $Xorg: lbx_zlib.c,v 1.6 2001/02/09 02:04:05 xorgcvs Exp $ */ + +/* + +Copyright 1995, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ + +/* + * Copyright 1988, 1989, 1990, 1994 Network Computing Devices, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name Network Computing Devices, Inc. not be + * used in advertising or publicity pertaining to distribution of this + * software without specific, written prior permission. + * + * THIS SOFTWARE IS PROVIDED `AS-IS'. NETWORK COMPUTING DEVICES, INC., + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT + * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK + * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING + * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA, + * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF + * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* $XFree86: xc/lib/lbxutil/lbx_zlib/lbx_zlib.c,v 1.9 2001/08/27 19:01:07 dawes Exp $ */ + +#ifdef WIN32 +#define _WILLWINSOCK_ +#endif +#define _BSD_SOURCE +#include +#include +#include +#include +#include +#if !defined(WIN32) && !defined(Lynx) +#include +#endif +#include +#include "lbx_zlib.h" +#include + +unsigned long stream_out_compressed; +unsigned long stream_out_uncompressed; +unsigned long stream_out_plain; +unsigned long stream_in_compressed; +unsigned long stream_in_uncompressed; +unsigned long stream_in_plain; +#ifdef LBXREQSTATS +unsigned long stream_in_packet_header_bytes = 0; +extern int LbxWhoAmI; +#endif + +struct ZlibInfo { + struct compress_private compress_state; + struct compress_private decompress_state; + int fd; + int compress_off; + ZlibBuffer inbuf; + ZlibBuffer outbuf; + unsigned char header[ZLIB_PACKET_HDRLEN]; + struct iovec iovbuf[2]; +}; + +static int +init_compress(struct compress_private *priv,/* local pointer to private data */ + int level) /* compression level */ +{ + priv->cp_outputcount = 0; + + priv->cp_in_count = 0; /* length of input */ + priv->cp_bytes_out = 0; /* length of compressed output */ + priv->cp_inputbuf = priv->cp_inputbufend = NULL; + priv->cp_packet = NULL; + + priv->stream.zalloc = (alloc_func) 0; + priv->stream.zfree = (free_func) 0; + priv->stream.next_in = NULL; + priv->stream.next_out = NULL; + priv->stream.avail_in = priv->stream.avail_out = 0; + + priv->z_err = deflateInit (&(priv->stream), level); + + return (priv->compress_inited = (priv->z_err == Z_OK) ? 1 : 0); +} + +static int +init_decompress(struct compress_private *priv)/* local pointer to private data */ +{ + priv->cp_outputcount = 0; + + priv->cp_in_count = 0; /* length of input */ + priv->cp_bytes_out = 0; /* length of compressed output */ + priv->cp_inputbuf = priv->cp_inputbufend = NULL; + priv->cp_packet = NULL; + + priv->stream.zalloc = (alloc_func) 0; + priv->stream.zfree = (free_func) 0; + priv->stream.next_in = NULL; + priv->stream.next_out = NULL; + priv->stream.avail_in = priv->stream.avail_out = 0; + + priv->need_flush_decompress = 0; + + priv->z_err = inflateInit (&(priv->stream)); + +#ifdef LBXREQSTATS + priv->req_length = -1; + priv->req_compbytes_read = 0; + priv->req_uncompbytes_read = 0; + priv->x_header_bytes_read = 0; +#endif + + return (priv->decompress_inited = (priv->z_err == Z_OK) ? 1 : 0); +} + + +static void +do_compress (struct compress_private *priv, + int flush) + +{ + priv->stream.next_in = priv->cp_inputbuf; + priv->stream.avail_in = priv->cp_inputbufend - priv->cp_inputbuf; + + priv->stream.next_out = priv->cp_outputbuf; + priv->stream.avail_out = priv->cp_outputbufend - priv->cp_outputbuf; + + priv->z_err = deflate (&(priv->stream), flush); + + priv->cp_inputbuf = priv->stream.next_in; + priv->cp_outputbuf = priv->stream.next_out; +} + + +static void +do_decompress (struct compress_private *priv) + +{ + priv->stream.next_in = priv->cp_inputbuf; + priv->stream.avail_in = priv->cp_inputbufend - priv->cp_inputbuf; + + priv->stream.next_out = priv->cp_outputbuf; + priv->stream.avail_out = priv->cp_outputbufend - priv->cp_outputbuf; + + priv->z_err = inflate (&(priv->stream), Z_PARTIAL_FLUSH); + + priv->need_flush_decompress = (priv->stream.avail_out == 0); + + priv->cp_inputbuf = priv->stream.next_in; + priv->cp_outputbuf = priv->stream.next_out; +} + +static int +GetNewPacket(struct ZlibInfo *comp) +{ + register struct compress_private *priv = &comp->decompress_state; + int len; + int result; + + if (priv->cp_packet) { + /* Free up previous packet in input buffer */ + FreeInput(&comp->inbuf, priv->cp_inputbufend - priv->cp_packet); + priv->cp_packet = NULL; + } + + if ((result = GetInputPtr(comp->fd, + &comp->inbuf, + ZLIB_PACKET_HDRLEN, + &priv->cp_packet)) <= 0) + return result; + len = ZLIB_GET_DATALEN(priv->cp_packet); + if ((result = GetInputPtr(comp->fd, + &comp->inbuf, + len + ZLIB_PACKET_HDRLEN, + &priv->cp_packet)) <= 0) { + priv->cp_packet = NULL; + return result; + } + + return len; +} + +static int +NewPacketAvail(struct ZlibInfo *comp) +{ + register struct compress_private *priv = &comp->decompress_state; + char *pkt; + int len; + + if (priv->cp_packet) { + /* Free up previous packet in input buffer */ + FreeInput(&comp->inbuf, priv->cp_inputbufend - priv->cp_packet); + priv->cp_packet = NULL; + } + + if ((pkt = BYTES_AVAIL(&comp->inbuf, ZLIB_PACKET_HDRLEN))) { + len = ZLIB_GET_DATALEN(pkt); + if (BYTES_AVAIL(&comp->inbuf, len + ZLIB_PACKET_HDRLEN)) + return TRUE; + } + + return FALSE; +} + +static int +PlainWrite(struct ZlibInfo *comp, + unsigned char *buffer, + int buflen) +{ + int retval; + int lenleft = buflen; + + if ((retval = ZlibFlush(comp->fd)) == 0) { + register struct iovec *iov = comp->iovbuf; + while (lenleft) { + int outlen, written; + if ((outlen = iov[1].iov_len)) { + iov[1].iov_base = (caddr_t) buffer; + } + else { + outlen = MIN(lenleft, ZLIB_MAX_DATALEN); + ZLIB_PUT_PKTHDR(comp->header, outlen, FALSE); + iov[0].iov_base = (caddr_t) comp->header; + iov[0].iov_len = ZLIB_PACKET_HDRLEN; + iov[1].iov_base = (caddr_t) buffer; + iov[1].iov_len = outlen; + stream_out_uncompressed += ZLIB_PACKET_HDRLEN; + } + if ((retval = FlushIovBuf(comp->fd, iov)) < 0) + break; + written = outlen - retval; + lenleft -= written; + buffer += written; + stream_out_plain += written; + stream_out_uncompressed += written; + if (retval) + break; + } + if (lenleft == buflen) + return retval; + else + return buflen - lenleft; + } + + else if (retval > 0) { + retval = -1; + errno = EWOULDBLOCK; + } + + return retval; +} + +#define MAX_FDS 256 + +static struct ZlibInfo *per_fd[MAX_FDS]; + +/* + * Initialize ZLIB compressor + */ +void * +ZlibInit(int fd, + int level) /* compression level */ +{ + struct ZlibInfo *comp; + int ret1, ret2; + + if ((comp = (struct ZlibInfo *)Xalloc(sizeof(struct ZlibInfo))) == NULL) + return NULL; + + ret1 = InitZlibBuffer(&comp->inbuf, INBUFFER_SIZE); + ret2 = InitZlibBuffer(&comp->outbuf, OUTBUFFER_SIZE); + if (ret1 < 0 || ret2 < 0) { + ZlibFree(comp); + return NULL; + } + comp->compress_off = FALSE; + comp->iovbuf[1].iov_len = 0; + comp->fd = fd; + + if (!init_compress(&comp->compress_state, level) || + !init_decompress(&comp->decompress_state)) { + ZlibFree(comp); + return NULL; + } + + per_fd[fd] = comp; + +#ifdef LBXREQSTATS + InitLbxReqStats (); +#endif + + return (void *)comp; +} + +void +ZlibFree(struct ZlibInfo *comp) +{ + if (!comp) + return; + per_fd[comp->fd] = 0; + FreeZlibBuffer(&comp->inbuf); + FreeZlibBuffer(&comp->outbuf); + + if (comp->compress_state.compress_inited) + deflateEnd (&(comp->compress_state.stream)); + else if (comp->decompress_state.decompress_inited) + inflateEnd (&(comp->compress_state.stream)); + + Xfree(comp); +} + +int +ZlibFlush(int fd) +{ + struct ZlibInfo *comp = per_fd[fd]; + struct compress_private *priv = &comp->compress_state; + + if (priv->cp_in_count) { + int len; + do_compress (priv, Z_PARTIAL_FLUSH); + len = priv->cp_outputbuf - (priv->cp_packet + ZLIB_PACKET_HDRLEN); + ZLIB_PUT_PKTHDR(priv->cp_packet, len, TRUE); + stream_out_compressed += (len + ZLIB_PACKET_HDRLEN); + + CommitOutBuf(&comp->outbuf, len + ZLIB_PACKET_HDRLEN); + priv->cp_in_count = 0; + } + + return FlushOutBuf(comp->fd, &comp->outbuf); +} + +int +ZlibStuffInput(int fd, + unsigned char *buffer, + int buflen) +{ + struct ZlibInfo *comp = per_fd[fd]; + + if (StuffInput (&comp->inbuf, buffer, buflen) != buflen) + return 0; + return 1; +} + +void +ZlibCompressOn(int fd) +{ + per_fd[fd]->compress_off = FALSE; +} + +void +ZlibCompressOff(int fd) +{ + per_fd[fd]->compress_off = TRUE; +} + +int +ZlibWriteV(int fd, + struct iovec *iov, + int iovcnt) +{ + int i; + int total = 0; + int this_time; + + for (i = 0; i < iovcnt; i++) + { + this_time = ZlibWrite(fd, (unsigned char *)iov[i].iov_base, + iov[i].iov_len); + if (this_time > 0) + total += this_time; + if (this_time != iov[i].iov_len) + { + if (total) + return total; + return this_time; + } + } + return total; +} + +int +ZlibWrite(int fd, + unsigned char *buffer, + int buflen) +{ + struct ZlibInfo *comp = per_fd[fd]; + struct compress_private *priv = &comp->compress_state; + int len; + int lenleft = buflen; + unsigned char *p = buffer; + + if (comp->compress_off) { + return PlainWrite(comp, buffer, buflen); + } + + while (lenleft) { + if (priv->cp_in_count == 0) { + priv->cp_packet = (unsigned char *) ReserveOutBuf(&comp->outbuf, + ZLIB_PACKET_HDRLEN + ZLIB_MAX_OUTLEN); + if (!priv->cp_packet) { + errno = EWOULDBLOCK; + return -1; + } + priv->cp_outputbuf = priv->cp_packet + ZLIB_PACKET_HDRLEN; + priv->cp_outputbufend = priv->cp_outputbuf + ZLIB_MAX_OUTLEN; + } + + len = MIN(ZLIB_MAX_PLAIN - priv->cp_in_count, lenleft); + stream_out_plain += len; + + priv->cp_inputbuf = p; + priv->cp_inputbufend = p + len; + do_compress(priv, Z_NO_FLUSH); + + p += len; + lenleft -= len; + if ((priv->cp_in_count += len) == ZLIB_MAX_PLAIN) { + if (ZlibFlush(fd) < 0) { + if (lenleft == buflen) + return -1; + return buflen - lenleft; + } + } + } + + return buflen; +} + +int +ZlibRead(int fd, + unsigned char *buffer, + int buflen) +{ + struct ZlibInfo *comp = per_fd[fd]; + struct compress_private *priv = &comp->decompress_state; + unsigned char *p = buffer; + int lenleft = buflen; + int len; + int retval = -1; + + /* + * First check if there is any data Zlib decompressed already but + * didn't have output buffer space to store it in. + */ + + if (priv->need_flush_decompress) + { + priv->cp_outputbuf = p; + priv->cp_outputbufend = p + lenleft; + + do_decompress (priv); + + lenleft -= (priv->cp_outputbuf - p); + p = priv->cp_outputbuf; + } + + + /* + * Need to decompress some more data + */ + + priv->cp_outputbuf = p; + priv->cp_outputbufend = p + lenleft; + while (priv->cp_outputbuf != priv->cp_outputbufend) { + if (priv->cp_inputbuf == priv->cp_inputbufend) { + if ((retval = GetNewPacket(comp)) <= 0) + break; + priv->cp_inputbuf = priv->cp_packet + ZLIB_PACKET_HDRLEN; + priv->cp_inputbufend = priv->cp_inputbuf + retval; + if (ZLIB_COMPRESSED(priv->cp_packet)) + stream_in_compressed += (retval + ZLIB_PACKET_HDRLEN); + else + stream_in_uncompressed += (retval + ZLIB_PACKET_HDRLEN); +#ifdef LBXREQSTATS + stream_in_packet_header_bytes += ZLIB_PACKET_HDRLEN; +#endif + } + + if (ZLIB_COMPRESSED(priv->cp_packet)) +#ifdef LBXREQSTATS + if (LbxWhoAmI == 1) /* only support request stats for now */ + do_decompress_with_stats(priv); + else +#endif + do_decompress(priv); + + else { + len = MIN(priv->cp_inputbufend - priv->cp_inputbuf, + priv->cp_outputbufend - priv->cp_outputbuf); + memmove(priv->cp_outputbuf, priv->cp_inputbuf, len); + priv->cp_inputbuf += len; + priv->cp_outputbuf += len; + } + } + + if ((len = priv->cp_outputbuf - buffer) == 0) + return retval; + else { + stream_in_plain += len; + return len; + } +} + +int +ZlibInputAvail(int fd) +{ + struct ZlibInfo *comp = per_fd[fd]; + struct compress_private *priv = &comp->decompress_state; + + return ( + priv->need_flush_decompress || + priv->cp_inputbuf != priv->cp_inputbufend || + NewPacketAvail(comp) > 0); +} diff --git a/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.h b/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.h new file mode 100644 index 000000000..68b94f807 --- /dev/null +++ b/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib.h @@ -0,0 +1,136 @@ +/* $Xorg: lbx_zlib.h,v 1.4 2001/02/09 02:04:05 xorgcvs Exp $ */ + +/* + +Copyright 1996 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ + +/* + * Copyright 1988, 1989, 1990, 1994 Network Computing Devices, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name Network Computing Devices, Inc. not be + * used in advertising or publicity pertaining to distribution of this + * software without specific, written prior permission. + * + * THIS SOFTWARE IS PROVIDED `AS-IS'. NETWORK COMPUTING DEVICES, INC., + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT + * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK + * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING + * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA, + * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF + * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* $XFree86: xc/lib/lbxutil/lbx_zlib/lbx_zlib.h,v 1.9 2001/08/27 19:01:07 dawes Exp $ */ + +#include "zlib.h" +#include + +struct compress_private { + z_stream stream; + char compress_inited; + char decompress_inited; + int z_err; /* error code for last stream operation */ + unsigned char *cp_inputbuf; + unsigned char *cp_inputbufend; + unsigned char *cp_outputbuf; + unsigned char *cp_outputbufend; + unsigned char *cp_packet; + int cp_outputcount; + long int cp_in_count; /* length of input */ + long int cp_bytes_out; /* length of compressed output */ + int need_flush_decompress; +#ifdef LBXREQSTATS + int x_req_code; + int lbx_req_code; + int x_header_bytes_read; + char x_header_buf[4]; + int req_length; + int req_compbytes_read; + int req_uncompbytes_read; +#endif +}; + +#ifndef MIN +#define MIN(_a, _b) ( ((_a) < (_b)) ? (_a) : (_b)) +#endif + + +/* + * The following is taken from the xtrans code, it would be nice to share it + */ +#if defined(WIN32) || (defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__)) + +struct iovec { + caddr_t iov_base; + int iov_len; +}; + +#else +#ifndef Lynx +#include +#else +#include +#endif +#endif + +#ifdef WIN32 +#define BOOL wBOOL +#undef Status +#define Status wStatus +#include +#undef Status +#define Status int +#undef BOOL +#define EWOULDBLOCK WSAEWOULDBLOCK +#endif + + +/* lbx_zlib_io.c */ +extern int GetInputPtr ( int fd, ZlibBufferPtr inbuf, int reqlen, + unsigned char **ppkt ); +extern int StuffInput ( ZlibBufferPtr inbuf, unsigned char *pkt, int reqlen ); +extern void FreeInput ( ZlibBufferPtr inbuf, int len ); +extern void CommitOutBuf ( ZlibBufferPtr outbuf, int outlen ); +extern int FlushOutBuf ( int fd, ZlibBufferPtr outbuf ); +extern int FlushIovBuf ( int fd, struct iovec *iovbuf ); + +/* Copied from xc/programs/Xserver/include/xorg/os.h */ +#ifndef _HAVE_XALLOC_DECLS +#define _HAVE_XALLOC_DECLS +#include + +extern pointer Xalloc(unsigned long /*amount*/); +extern pointer Xcalloc(unsigned long /*amount*/); +extern pointer Xrealloc(pointer /*ptr*/, unsigned long /*amount*/); +extern void Xfree(pointer /*ptr*/); +#endif diff --git a/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib_io.c b/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib_io.c new file mode 100644 index 000000000..12b29a310 --- /dev/null +++ b/nx-X11/lib/lbxutil/lbx_zlib/lbx_zlib_io.c @@ -0,0 +1,275 @@ +/* $Xorg: lbx_zlib_io.c,v 1.3 2000/08/17 19:46:41 cpqbld Exp $ */ + +/* + * Copyright 1993 Network Computing Devices + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of NCD. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. NCD. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD. + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Dale Tonogai, Network Computing Devices + */ +/* $XFree86: xc/lib/lbxutil/lbx_zlib/lbx_zlib_io.c,v 1.11 2001/01/17 19:43:36 dawes Exp $ */ + +#ifdef WIN32 +#define _WILLWINSOCK_ +#endif +#include +#include +#include +#if !defined(WIN32) && !defined(Lynx) +#include +#endif +#include +#include "lbx_zlib.h" + +#include + + +/* + * The following is taken from the xtrans code, almost as is, + * it would be nice to share it... + */ +#if defined(WIN32) || defined(__sxg__) +static int +writev(int fildes, const struct iovec *iov, int iovcnt) +{ + int i, len, total; + char *base; + + ESET(0); + for (i = 0, total = 0; i < iovcnt; i++, iov++) { + len = iov->iov_len; + base = iov->iov_base; + while (len > 0) { + register int nbytes; + nbytes = write(fildes, base, len); + if (nbytes < 0 && total == 0) return -1; + if (nbytes <= 0) return total; + ESET(0); + len -= nbytes; + total += nbytes; + base += nbytes; + } + } + return total; +} +#endif + +int +InitZlibBuffer(b, size) + ZlibBufferPtr b; + int size; +{ + if ((b->bufbase = (char *)Xalloc(size)) == NULL) + return -1; + b->bufend = b->bufbase + size; + b->bufptr = b->bufbase; + b->bufcnt = 0; + return 0; +} + +void +FreeZlibBuffer(b) + ZlibBufferPtr b; +{ + if (b->bufbase) { + Xfree(b->bufbase); + b->bufbase = NULL; + } +} + +/* + * Returns: + * 1 if desired amount of data available in input buffer + * 0 if eof + * -1 if error + */ +int +GetInputPtr(fd, inbuf, reqlen, ppkt) + int fd; + ZlibBufferPtr inbuf; + int reqlen; + unsigned char **ppkt; +{ + int readbytes; + int gotbytes; + + if (inbuf->bufcnt == 0) + inbuf->bufptr = inbuf->bufbase; + + if (reqlen <= inbuf->bufcnt) { + *ppkt = (unsigned char *)inbuf->bufptr; + return 1; + } + + if (reqlen > inbuf->bufend - inbuf->bufptr) { + memmove(inbuf->bufbase, inbuf->bufptr, inbuf->bufcnt); + inbuf->bufptr = inbuf->bufbase; + } + readbytes = (inbuf->bufend - inbuf->bufptr) - inbuf->bufcnt; + gotbytes = read(fd, inbuf->bufptr + inbuf->bufcnt, readbytes); + if (gotbytes > 0) { + if (reqlen <= (inbuf->bufcnt += gotbytes)) { + *ppkt = (unsigned char *)inbuf->bufptr; + return 1; + } + } + else + return gotbytes; + + errno = EWOULDBLOCK; + return -1; +} + +/* + * When ZLIB is started, we may well have read some data off of the + * wire somewhere. This sticks those bytes ahead of anything we might + * read in the future + */ + +int +StuffInput(inbuf, pkt, reqlen) + ZlibBufferPtr inbuf; + unsigned char *pkt; + int reqlen; +{ + int readbytes; + char *last; + + last = inbuf->bufptr + inbuf->bufcnt; + if (reqlen > inbuf->bufend - last) + { + memmove(inbuf->bufbase, inbuf->bufptr, inbuf->bufcnt); + inbuf->bufptr = inbuf->bufbase; + last = inbuf->bufptr + inbuf->bufcnt; + } + readbytes = MIN(reqlen, inbuf->bufend - last); + memmove(last, pkt, readbytes); + inbuf->bufcnt += readbytes; + return readbytes; +} + +void +FreeInput(inbuf, len) + ZlibBufferPtr inbuf; + int len; +{ + inbuf->bufptr += len; + if ((inbuf->bufcnt -= len) == 0) + inbuf->bufptr = inbuf->bufbase; +} + +/* + * Reserve outlen bytes in the output buffer. + */ +char * +ReserveOutBuf(outbuf, outlen) + ZlibBufferPtr outbuf; + int outlen; +{ + int left; + + left = (outbuf->bufend - outbuf->bufptr) - outbuf->bufcnt; + if (left < outlen) + return NULL; + else + return outbuf->bufptr + outbuf->bufcnt; +} + +/* + * Commit previously reserved space as real output + */ +void +CommitOutBuf(outbuf, outlen) + ZlibBufferPtr outbuf; + int outlen; +{ + outbuf->bufcnt += outlen; +} + +/* + * Write out as much as possible from the output buffer. + * Returns: >= 0 - amount left in buffer + * < 0 - write error + */ +int +FlushOutBuf(fd, outbuf) + int fd; + ZlibBufferPtr outbuf; +{ + int bytes; + + if (outbuf->bufcnt == 0) + return 0; + bytes = write(fd, outbuf->bufptr, outbuf->bufcnt); + if (bytes > 0) { + outbuf->bufptr += bytes; + if ((outbuf->bufcnt -= bytes) == 0) + outbuf->bufptr = outbuf->bufbase; + return outbuf->bufcnt; + } + else if (bytes == 0) { + errno = EWOULDBLOCK; + bytes = -1; + } + return bytes; +} + +/* + * Write out as much as possible from the iovec array (no more than + * two entries allowed). + * Returns: >= 0 - amount left in iovec[1] + * < 0 - write error + */ +int +FlushIovBuf(fd, iovbuf) + int fd; + struct iovec *iovbuf; +{ + int bytes; + int niov = 2; + struct iovec *iov = iovbuf; + + if (iov[0].iov_len == 0) { + ++iov; + --niov; + } + bytes = writev(fd, iov, niov); + if (bytes > 0) { + int i; + int len; + for (i = 0; i < niov; i++) { + len = MIN(bytes, iov[i].iov_len); + iov[i].iov_len -= len; + /* + * An explicit cast is necessary because silly SGI changed + * iov_base from a caddr_t to a void* in IRIX 6.x, and strictly + * speaking ANSI/ISO C doesn't allow the use of a cast in an + * lvalue, i.e. such as: '((char*)(iov[i].iov_base)) += len;' + */ + iov[i].iov_base = ((char*)(iov[i].iov_base)) + len; + if ((bytes -= len) == 0) + break; + } + return iovbuf[1].iov_len; + } + else if (bytes == 0) { + errno = EWOULDBLOCK; + bytes = -1; + } + return bytes; +} diff --git a/nx-X11/lib/lbxutil/lbx_zlib/reqstats.c b/nx-X11/lib/lbxutil/lbx_zlib/reqstats.c new file mode 100644 index 000000000..50545b8f6 --- /dev/null +++ b/nx-X11/lib/lbxutil/lbx_zlib/reqstats.c @@ -0,0 +1,503 @@ +/* $Xorg: reqstats.c,v 1.4 2001/02/09 02:04:05 xorgcvs Exp $ */ + +/* + +Copyright 1996 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ +/* $XFree86: xc/lib/lbxutil/lbx_zlib/reqstats.c,v 1.5 2001/08/27 19:01:07 dawes Exp $ */ + +#include "reqstats.h" + +#ifdef LBXREQSTATS + +#include +#include +#define _XLBX_SERVER_ +#include "XLbx.h" +#include "lbx_zlib.h" +#include +#include + +#define LBX_CODE 136 /* XXX - this should not be hardcoded - on todo list */ + +extern unsigned long stream_in_compressed; +extern unsigned long stream_in_plain; +extern unsigned long stream_in_packet_header_bytes; +extern unsigned long stream_in_uncompressed_bytes; + +unsigned long check_sum_in_compressed; +unsigned long check_sum_in_plain; +int unknown_extension_bytes = 0; + +struct ReqStats CoreRequestStats[128]; +struct ReqStats LbxRequestStats[LbxNumberReqs]; + +static void LbxPrintReqStats (int); + +char *X_ReqNames[128] = { + 0, /* 0 */ + "CreateWindow", /* 1 */ + "ChangeWindowAttributes", /* 2 */ + "GetWindowAttributes", /* 3 */ + "DestroyWindow", /* 4 */ + "DestroySubwindows", /* 5 */ + "ChangeSaveSet", /* 6 */ + "ReparentWindow", /* 7 */ + "MapWindow", /* 8 */ + "MapSubwindows", /* 9 */ + "UnmapWindow", /* 10 */ + "UnmapSubwindows", /* 11 */ + "ConfigureWindow", /* 12 */ + "CirculateWindow", /* 13 */ + "GetGeometry", /* 14 */ + "QueryTree", /* 15 */ + "InternAtom", /* 16 */ + "GetAtomName", /* 17 */ + "ChangeProperty", /* 18 */ + "DeleteProperty", /* 19 */ + "GetProperty", /* 20 */ + "ListProperties", /* 21 */ + "SetSelectionOwner", /* 22 */ + "GetSelectionOwner", /* 23 */ + "ConvertSelection", /* 24 */ + "SendEvent", /* 25 */ + "GrabPointer", /* 26 */ + "UngrabPointer", /* 27 */ + "GrabButton", /* 28 */ + "UngrabButton", /* 29 */ + "ChangeActivePointerGrab", /* 30 */ + "GrabKeyboard", /* 31 */ + "UngrabKeyboard", /* 32 */ + "GrabKey", /* 33 */ + "UngrabKey", /* 34 */ + "AllowEvents", /* 35 */ + "GrabServer", /* 36 */ + "UngrabServer", /* 37 */ + "QueryPointer", /* 38 */ + "GetMotionEvents", /* 39 */ + "TranslateCoords", /* 40 */ + "WarpPointer", /* 41 */ + "SetInputFocus", /* 42 */ + "GetInputFocus", /* 43 */ + "QueryKeymap", /* 44 */ + "OpenFont", /* 45 */ + "CloseFont", /* 46 */ + "QueryFont", /* 47 */ + "QueryTextExtents", /* 48 */ + "ListFonts", /* 49 */ + "ListFontsWithInfo", /* 50 */ + "SetFontPath", /* 51 */ + "GetFontPath", /* 52 */ + "CreatePixmap", /* 53 */ + "FreePixmap", /* 54 */ + "CreateGC", /* 55 */ + "ChangeGC", /* 56 */ + "CopyGC", /* 57 */ + "SetDashes", /* 58 */ + "SetClipRectangles", /* 59 */ + "FreeGC", /* 60 */ + "ClearArea", /* 61 */ + "CopyArea", /* 62 */ + "CopyPlane", /* 63 */ + "PolyPoint", /* 64 */ + "PolyLine", /* 65 */ + "PolySegment", /* 66 */ + "PolyRectangle", /* 67 */ + "PolyArc", /* 68 */ + "FillPoly", /* 69 */ + "PolyFillRectangle", /* 70 */ + "PolyFillArc", /* 71 */ + "PutImage", /* 72 */ + "GetImage", /* 73 */ + "PolyText8", /* 74 */ + "PolyText16", /* 75 */ + "ImageText8", /* 76 */ + "ImageText16", /* 77 */ + "CreateColormap", /* 78 */ + "FreeColormap", /* 79 */ + "CopyColormapAndFree", /* 80 */ + "InstallColormap", /* 81 */ + "UninstallColormap", /* 82 */ + "ListInstalledColormaps", /* 83 */ + "AllocColor", /* 84 */ + "AllocNamedColor", /* 85 */ + "AllocColorCells", /* 86 */ + "AllocColorPlanes", /* 87 */ + "FreeColors", /* 88 */ + "StoreColors", /* 89 */ + "StoreNamedColor", /* 90 */ + "QueryColors", /* 91 */ + "LookupColor", /* 92 */ + "CreateCursor", /* 93 */ + "CreateGlyphCursor", /* 94 */ + "FreeCursor", /* 95 */ + "RecolorCursor", /* 96 */ + "QueryBestSize", /* 97 */ + "QueryExtension", /* 98 */ + "ListExtensions", /* 99 */ + "ChangeKeyboardMapping", /* 100 */ + "GetKeyboardMapping", /* 101 */ + "ChangeKeyboardControl", /* 102 */ + "GetKeyboardControl", /* 103 */ + "Bell", /* 104 */ + "ChangePointerControl", /* 105 */ + "GetPointerControl", /* 106 */ + "SetScreenSaver", /* 107 */ + "GetScreenSaver", /* 108 */ + "ChangeHosts", /* 109 */ + "ListHosts", /* 110 */ + "SetAccessControl", /* 111 */ + "SetCloseDownMode", /* 112 */ + "KillClient", /* 113 */ + "RotateProperties", /* 114 */ + "ForceScreenSaver", /* 115 */ + "SetPointerMapping", /* 116 */ + "GetPointerMapping", /* 117 */ + "SetModifierMapping", /* 118 */ + "GetModifierMapping", /* 119 */ + 0, /* 120 */ + 0, /* 121 */ + 0, /* 122 */ + 0, /* 123 */ + 0, /* 124 */ + 0, /* 125 */ + 0, /* 126 */ + "NoOperation" /* 127 */ +}; + + +char *LBX_ReqNames[LbxNumberReqs] = { + + "LbxQueryVersion", /* 0 */ + "LbxStartProxy", /* 1 */ + "LbxStopProxy", /* 2 */ + "LbxSwitch", /* 3 */ + "LbxNewClient", /* 4 */ + "LbxCloseClient", /* 5 */ + "LbxModifySequence", /* 6 */ + "LbxAllowMotion", /* 7 */ + "LbxIncrementPixel", /* 8 */ + "LbxDelta", /* 9 */ + "LbxGetModifierMapping", /* 10 */ + "LbxQueryTag", /* 11 */ + "LbxInvalidateTag", /* 12 */ + "LbxPolyPoint", /* 13 */ + "LbxPolyLine", /* 14 */ + "LbxPolySegment", /* 15 */ + "LbxPolyRectangle", /* 16 */ + "LbxPolyArc", /* 17 */ + "LbxFillPoly", /* 18 */ + "LbxPolyFillRectangle", /* 19 */ + "LbxPolyFillArc", /* 20 */ + "LbxGetKeyboardMapping", /* 21 */ + "LbxQueryFont", /* 22 */ + "LbxChangeProperty", /* 23 */ + "LbxGetProperty", /* 24 */ + "LbxTagData", /* 25 */ + "LbxCopyArea", /* 26 */ + "LbxCopyPlane", /* 27 */ + "LbxPolyText8", /* 28 */ + "LbxPolyText16", /* 29 */ + "LbxImageText8", /* 30 */ + "LbxImageText16", /* 31 */ + "LbxQueryExtension", /* 32 */ + "LbxPutImage", /* 33 */ + "LbxGetImage", /* 34 */ + "LbxBeginLargeRequest", /* 35 */ + "LbxLargeRequestData", /* 36 */ + "LbxEndLargeRequest" /* 37 */ +}; + + + +void +InitLbxReqStats (void) + +{ + bzero (CoreRequestStats, 128 * sizeof (struct ReqStats)); + bzero (LbxRequestStats, LbxNumberReqs * sizeof (struct ReqStats)); + + signal (SIGUSR1, LbxPrintReqStats); +} + + +static void +PrintStatsTable (struct ReqStats *table, + int count, + char **reqNames) + +{ + int i; + + fprintf (stderr, "U = uncompressed bytes\n"); + fprintf (stderr, "C = compressed bytes\n"); + fprintf (stderr, "%%C = percent compression\n"); + fprintf (stderr, "%%T = percent of total bytes in stream\n"); + fprintf (stderr, "\n"); + fprintf (stderr, "%-25s\tCount\tU\tC\t%%C\t\t%%T\n", "Request"); + fprintf (stderr, "-------------------------------------------------------------------------------\n"); + + for (i = 0; i < count; i++) + { + float compRatio, percentTot; + + if (table[i].uncomp_bytes == 0) + compRatio = 0.0; + else + compRatio = 100.0 * (1.0 - ((float) table[i].comp_bytes / + (float) table[i].uncomp_bytes)); + + if (stream_in_compressed - stream_in_packet_header_bytes == 0) + percentTot = 0.0; + else + percentTot = 100.0 * (float) table[i].comp_bytes / + (float) (stream_in_compressed - + stream_in_packet_header_bytes); + + if (reqNames[i]) + fprintf (stderr, "%-25s\t%d\t%d\t%d\t%.3f\t\t%.3f\n", + reqNames[i], + table[i].count, + table[i].uncomp_bytes, + table[i].comp_bytes, + compRatio, + percentTot); + + check_sum_in_plain += table[i].uncomp_bytes; + check_sum_in_compressed += table[i].comp_bytes; + } +} + +static void +PrintDeltaStats (struct ReqStats *table, + int count, + char **reqNames) + +{ + int i; + + for (i = 0; i < count; i++) + { + if (table[i].delta_count && reqNames[i]) + fprintf (stderr, "%-25s\t%d\t%d\t%d\n", + reqNames[i], + table[i].delta_count, + table[i].pre_delta_bytes, + table[i].post_delta_bytes); + } +} + + +static void +LbxPrintReqStats (int dummy) + +{ + unsigned long total; + + check_sum_in_plain = 0; + check_sum_in_compressed = 0; + + fprintf (stderr, "\n\n"); + fprintf (stderr, "Core X requests\n\n"); + PrintStatsTable (CoreRequestStats, 128, X_ReqNames); + + fprintf (stderr, "\n\n"); + fprintf (stderr, "LBX requests\n\n"); + PrintStatsTable (LbxRequestStats, LbxNumberReqs, LBX_ReqNames); + + fprintf (stderr, "\n\n\n"); + + fprintf (stderr, "The following requests were delta compressed:\n"); + fprintf (stderr, "\n"); + fprintf (stderr, "Pre = pre delta bytes\n"); + fprintf (stderr, "Post = post delta bytes\n"); + fprintf (stderr, "\n"); + fprintf (stderr, "%-25s\tCount\tPre\tPost\n", "Request"); + fprintf (stderr, "-------------------------------------------------------------------------------\n"); + PrintDeltaStats (CoreRequestStats, 128, X_ReqNames); + PrintDeltaStats (LbxRequestStats, LbxNumberReqs, LBX_ReqNames); + + fprintf (stderr, "\n\n\n"); + + fprintf (stderr, "overall stream compression = %f %%\n", + (check_sum_in_plain == 0) ? 0.0 : + (100.0 * (1.0 - ((float) check_sum_in_compressed / + (float) check_sum_in_plain)))); + + fprintf (stderr, "\n\n\n"); + + total = check_sum_in_plain + unknown_extension_bytes + + stream_in_uncompressed_bytes; + + if (total == stream_in_plain) + fprintf (stderr, "Internal checksum succeeded!!!\n"); + else + { + fprintf (stderr, "Internal checksum failed!!!\n"); + fprintf (stderr, "actual checksum = %d\n", stream_in_plain); + fprintf (stderr, "computed checksum = %d\n", total); + } + + fprintf (stderr, "\n\n"); +} + + +void +do_decompress_with_stats (struct compress_private *priv) + +{ + int incount = priv->cp_inputbufend - priv->cp_inputbuf; + + priv->stream.next_in = priv->cp_inputbuf; + priv->stream.next_out = priv->cp_outputbuf; + priv->stream.avail_out = priv->cp_outputbufend - priv->cp_outputbuf; + + while (incount > 0) + { + char *save_out = (char *) priv->stream.next_out; + int outcount, outconsumed; + + priv->stream.avail_in = 1; + priv->z_err = inflate (&(priv->stream), Z_NO_FLUSH); + + priv->need_flush_decompress = (priv->stream.avail_out == 0 ); + + priv->req_compbytes_read++; + + outcount = (char *) priv->stream.next_out - save_out; + + priv->req_uncompbytes_read += outcount; + + while (outcount > 0) + { + if (priv->req_length == -1 && priv->x_header_bytes_read < 4) + { + int have = MIN (outcount, (4 - priv->x_header_bytes_read)); + memcpy (priv->x_header_buf + priv->x_header_bytes_read, + save_out, have); + priv->x_header_bytes_read += have; + + if (priv->x_header_bytes_read < 4 && ((outcount - have) == 0)) + break; + } + + if (priv->req_length == -1 && priv->x_header_bytes_read == 4) + { + xReq *req = (xReq *) priv->x_header_buf; + + priv->req_length = req->length << 2; + priv->x_req_code = req->reqType; + + if (priv->x_req_code == LBX_CODE) + priv->lbx_req_code = req->data; + } + + if (priv->req_length != -1) + { + if (priv->req_uncompbytes_read < priv->req_length) + break; + else + { + if (priv->x_req_code == LBX_CODE) + { + struct ReqStats *reqStat = + &LbxRequestStats[priv->lbx_req_code]; + + reqStat->count++; + reqStat->comp_bytes += priv->req_compbytes_read; + reqStat->uncomp_bytes += priv->req_length; + +#ifdef LBXREQLOG + fprintf (stderr, + "LBX opcode = %d, real len = %d, comp len = %d\n", + priv->lbx_req_code, priv->req_length, + priv->req_compbytes_read); +#endif + } + else if (priv->x_req_code < 128) + { + struct ReqStats *reqStat = + &CoreRequestStats[priv->x_req_code]; + + reqStat->count++; + reqStat->comp_bytes += priv->req_compbytes_read; + reqStat->uncomp_bytes += priv->req_length; + +#ifdef LBXREQLOG + fprintf (stderr, + "X opcode = %d, real len = %d, comp len = %d\n", + priv->x_req_code, priv->req_length, + priv->req_compbytes_read); +#endif + } + else + { +#ifdef LBXREQLOG + fprintf (stderr, + "Unknown opcode = %d, real len = %d, comp len = %d\n", + priv->x_req_code, priv->req_length, + priv->req_compbytes_read); +#endif + unknown_extension_bytes += priv->req_length; + } + + priv->req_uncompbytes_read -= priv->req_length; + + if (priv->req_uncompbytes_read > 0) + { + priv->req_compbytes_read = 1; + save_out += (outcount - priv->req_uncompbytes_read); + outcount = priv->req_uncompbytes_read; + } + else + { + priv->req_compbytes_read = 0; + outcount = 0; + } + + priv->req_length = -1; + priv->x_header_bytes_read = 0; + } + } + } + + incount--; + + if (priv->stream.avail_out == 0) + break; + } + + priv->cp_inputbuf = priv->stream.next_in; + priv->cp_outputbuf = priv->stream.next_out; +} + +#else + +void +InitLbxReqStats() +{} + +#endif /* LBXREQSTATS */ diff --git a/nx-X11/lib/lbxutil/lbx_zlib/reqstats.h b/nx-X11/lib/lbxutil/lbx_zlib/reqstats.h new file mode 100644 index 000000000..eab64e94e --- /dev/null +++ b/nx-X11/lib/lbxutil/lbx_zlib/reqstats.h @@ -0,0 +1,43 @@ +/* $Xorg: reqstats.h,v 1.4 2001/02/09 02:04:05 xorgcvs Exp $ */ + +/* + +Copyright 1996 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ +/* $XFree86: xc/lib/lbxutil/lbx_zlib/reqstats.h,v 1.2 2001/08/27 19:01:07 dawes Exp $ */ + +#ifdef LBXREQSTATS +struct ReqStats { + int count; + unsigned long comp_bytes; + unsigned long uncomp_bytes; + int delta_count; + unsigned long pre_delta_bytes; + unsigned long post_delta_bytes; +}; +#endif + +extern void InitLbxReqStats(void); -- cgit v1.2.3