<<
OBJECTS = \
+ ..\xpm\$D\attrib.obj \
..\xpm\$D\crbuffri.obj \
..\xpm\$D\crdatfri.obj \
..\xpm\$D\create.obj \
..\xpm\$D\crifrbuf.obj \
..\xpm\$D\crifrdat.obj \
..\xpm\$D\data.obj \
+ ..\xpm\$D\image.obj \
+ ..\xpm\$D\info.obj \
..\xpm\$D\hashtab.obj \
..\xpm\$D\misc.obj \
..\xpm\$D\parse.obj \
..\xpm\$D\scan.obj \
..\xpm\$D\simx.obj \
..\xpm\$D\wrffrdat.obj \
- ..\xpm\$D\wrffrp.obj \
..\xpm\$D\wrffri.obj
all: $(OS2XPMLIB)
--- /dev/null
+/*
+ * Copyright (C) 1989-95 GROUPE BULL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 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
+ * GROUPE BULL 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 GROUPE BULL shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from GROUPE BULL.
+ */
+
+/*****************************************************************************\
+* Attrib.c: *
+* *
+* XPM library *
+* Functions related to the XpmAttributes structure *
+* *
+* Developed by Arnaud Le Hors *
+\*****************************************************************************/
+
+#include "XpmI.h"
+
+/* 3.2 backward compatibility code */
+LFUNC(CreateOldColorTable, int, (XpmColor *ct, int ncolors,
+ XpmColor ***oldct));
+
+LFUNC(FreeOldColorTable, void, (XpmColor **colorTable, int ncolors));
+
+/*
+ * Create a colortable compatible with the old style colortable
+ */
+static int
+CreateOldColorTable(ct, ncolors, oldct)
+ XpmColor *ct;
+ int ncolors;
+ XpmColor ***oldct;
+{
+ XpmColor **colorTable, **color;
+ int a;
+
+ colorTable = (XpmColor **) XpmMalloc(ncolors * sizeof(XpmColor *));
+ if (!colorTable) {
+ *oldct = NULL;
+ return (XpmNoMemory);
+ }
+ for (a = 0, color = colorTable; a < ncolors; a++, color++, ct++)
+ *color = ct;
+ *oldct = colorTable;
+ return (XpmSuccess);
+}
+
+static void
+FreeOldColorTable(colorTable, ncolors)
+ XpmColor **colorTable;
+ int ncolors;
+{
+ int a, b;
+ XpmColor **color;
+ char **sptr;
+
+ if (colorTable) {
+ for (a = 0, color = colorTable; a < ncolors; a++, color++) {
+ for (b = 0, sptr = (char **) *color; b <= NKEYS; b++, sptr++)
+ if (*sptr)
+ XpmFree(*sptr);
+ }
+ XpmFree(*colorTable);
+ XpmFree(colorTable);
+ }
+}
+
+/* end 3.2 bc */
+
+/*
+ * Free the computed color table
+ */
+void
+xpmFreeColorTable(colorTable, ncolors)
+ XpmColor *colorTable;
+ int ncolors;
+{
+ int a, b;
+ XpmColor *color;
+ char **sptr;
+
+ if (colorTable) {
+ for (a = 0, color = colorTable; a < ncolors; a++, color++) {
+ for (b = 0, sptr = (char **) color; b <= NKEYS; b++, sptr++)
+ if (*sptr)
+ XpmFree(*sptr);
+ }
+ XpmFree(colorTable);
+ }
+}
+
+/*
+ * Free array of extensions
+ */
+void
+XpmFreeExtensions(extensions, nextensions)
+ XpmExtension *extensions;
+ int nextensions;
+{
+ unsigned int i, j, nlines;
+ XpmExtension *ext;
+ char **sptr;
+
+ if (extensions) {
+ for (i = 0, ext = extensions; i < nextensions; i++, ext++) {
+ if (ext->name)
+ XpmFree(ext->name);
+ nlines = ext->nlines;
+ for (j = 0, sptr = ext->lines; j < nlines; j++, sptr++)
+ if (*sptr)
+ XpmFree(*sptr);
+ if (ext->lines)
+ XpmFree(ext->lines);
+ }
+ XpmFree(extensions);
+ }
+}
+
+/*
+ * Return the XpmAttributes structure size
+ */
+
+int
+XpmAttributesSize()
+{
+ return sizeof(XpmAttributes);
+}
+
+/*
+ * Init returned data to free safely later on
+ */
+void
+xpmInitAttributes(attributes)
+ XpmAttributes *attributes;
+{
+ if (attributes) {
+ attributes->pixels = NULL;
+ attributes->npixels = 0;
+ attributes->colorTable = NULL;
+ attributes->ncolors = 0;
+/* 3.2 backward compatibility code */
+ attributes->hints_cmt = NULL;
+ attributes->colors_cmt = NULL;
+ attributes->pixels_cmt = NULL;
+/* end 3.2 bc */
+ if (attributes->valuemask & XpmReturnExtensions) {
+ attributes->extensions = NULL;
+ attributes->nextensions = 0;
+ }
+ if (attributes->valuemask & XpmReturnAllocPixels) {
+ attributes->alloc_pixels = NULL;
+ attributes->nalloc_pixels = 0;
+ }
+ }
+}
+
+/*
+ * Fill in the XpmAttributes with the XpmImage and the XpmInfo
+ */
+void
+xpmSetAttributes(attributes, image, info)
+ XpmAttributes *attributes;
+ XpmImage *image;
+ XpmInfo *info;
+{
+ if (attributes->valuemask & XpmReturnColorTable) {
+ attributes->colorTable = image->colorTable;
+ attributes->ncolors = image->ncolors;
+
+ /* avoid deletion of copied data */
+ image->ncolors = 0;
+ image->colorTable = NULL;
+ }
+/* 3.2 backward compatibility code */
+ else if (attributes->valuemask & XpmReturnInfos) {
+ int ErrorStatus;
+
+ ErrorStatus = CreateOldColorTable(image->colorTable, image->ncolors,
+ (XpmColor ***)
+ &attributes->colorTable);
+
+ /* if error just say we can't return requested data */
+ if (ErrorStatus != XpmSuccess) {
+ attributes->valuemask &= ~XpmReturnInfos;
+ if (!(attributes->valuemask & XpmReturnPixels)) {
+ XpmFree(attributes->pixels);
+ attributes->pixels = NULL;
+ attributes->npixels = 0;
+ }
+ attributes->ncolors = 0;
+ } else {
+ attributes->ncolors = image->ncolors;
+ attributes->hints_cmt = info->hints_cmt;
+ attributes->colors_cmt = info->colors_cmt;
+ attributes->pixels_cmt = info->pixels_cmt;
+
+ /* avoid deletion of copied data */
+ image->ncolors = 0;
+ image->colorTable = NULL;
+ info->hints_cmt = NULL;
+ info->colors_cmt = NULL;
+ info->pixels_cmt = NULL;
+ }
+ }
+/* end 3.2 bc */
+ if (attributes->valuemask & XpmReturnExtensions) {
+ attributes->extensions = info->extensions;
+ attributes->nextensions = info->nextensions;
+
+ /* avoid deletion of copied data */
+ info->extensions = NULL;
+ info->nextensions = 0;
+ }
+ if (info->valuemask & XpmHotspot) {
+ attributes->valuemask |= XpmHotspot;
+ attributes->x_hotspot = info->x_hotspot;
+ attributes->y_hotspot = info->y_hotspot;
+ }
+ attributes->valuemask |= XpmCharsPerPixel;
+ attributes->cpp = image->cpp;
+ attributes->valuemask |= XpmSize;
+ attributes->width = image->width;
+ attributes->height = image->height;
+}
+
+/*
+ * Free the XpmAttributes structure members
+ * but the structure itself
+ */
+void
+XpmFreeAttributes(attributes)
+ XpmAttributes *attributes;
+{
+ if (attributes->valuemask & XpmReturnPixels && attributes->npixels) {
+ XpmFree(attributes->pixels);
+ attributes->pixels = NULL;
+ attributes->npixels = 0;
+ }
+ if (attributes->valuemask & XpmReturnColorTable) {
+ xpmFreeColorTable(attributes->colorTable, attributes->ncolors);
+ attributes->colorTable = NULL;
+ attributes->ncolors = 0;
+ }
+/* 3.2 backward compatibility code */
+ else if (attributes->valuemask & XpmInfos) {
+ if (attributes->colorTable) {
+ FreeOldColorTable((XpmColor **) attributes->colorTable,
+ attributes->ncolors);
+ attributes->colorTable = NULL;
+ attributes->ncolors = 0;
+ }
+ if (attributes->hints_cmt) {
+ XpmFree(attributes->hints_cmt);
+ attributes->hints_cmt = NULL;
+ }
+ if (attributes->colors_cmt) {
+ XpmFree(attributes->colors_cmt);
+ attributes->colors_cmt = NULL;
+ }
+ if (attributes->pixels_cmt) {
+ XpmFree(attributes->pixels_cmt);
+ attributes->pixels_cmt = NULL;
+ }
+ if (attributes->pixels) {
+ XpmFree(attributes->pixels);
+ attributes->pixels = NULL;
+ attributes->npixels = 0;
+ }
+ }
+/* end 3.2 bc */
+ if (attributes->valuemask & XpmReturnExtensions
+ && attributes->nextensions) {
+ XpmFreeExtensions(attributes->extensions, attributes->nextensions);
+ attributes->extensions = NULL;
+ attributes->nextensions = 0;
+ }
+ if (attributes->valuemask & XpmReturnAllocPixels
+ && attributes->nalloc_pixels) {
+ XpmFree(attributes->alloc_pixels);
+ attributes->alloc_pixels = NULL;
+ attributes->nalloc_pixels = 0;
+ }
+ attributes->valuemask = 0;
+}
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* *
\**************************************************************************/
+3.4k (98/03/18)
+
+ ENHANCEMENTS:
+ - A new program called cxpm is provided to check on XPM files and help
+ figuring out where the file might be invalid.
+ - The FAQ and README are now in HTML.
+
+ BUGS CORRECTED:
+ - A bug in writing pixmaps out on an 32 bit depth visual and MSBFirst
+ machine.
+ - patch from Uwe Langenkamp <Uwe.Langenkamp@t-online.de>
+ - A severe bug in parsing the pixels section when an unknown character
+ is encountered.
+
+3.4j (96/12/31)
+
+ ENHANCEMENTS:
+ - The XPM library can now be built under Amiga DOS. This entirely comes
+ from: Lorens Younes <d93-hyo@nada.kth.se>
+ See the README.AMIGA file for details.
+ - Changes for MSW: big performance improvement in ParseAndPutPixels(),
+ fixed creation of the mask in SetColor()
+ - patch from Jan Wielemaker <jan@swi.psy.uva.nl>
+ - makefiles are provided for VMS
+ - given by Martin P.J. Zinser m.zinser@gsi.de
+ - Imakefiles reworked to get smoother builds and fixes from:
+ - Paul DuBois dubois@primate.wisc.edu
+ - Larry Schwimmer schwim@cyclone.stanford.edu
+ - thanks to some code rearrangement the library is smaller (the size
+ reduction goes from 4 to 7% depending on the system)
+
+ BUGS CORRECTED:
+ - A severe bug (introduced in 3.4i as part of the sprintf
+ optimization) in code writing XPM extensions to a buffer
+ XpmCreateBufferFromImage/Pixmap.
+ - The XpmAttributes definition in xpm.h was declaring nalloc_colors to
+ be Bool, it's an int.
+
+3.4i (96/09/13)
+
+ NEW FEATURES:
+ - The XPM library now allows the application to pass its own color
+ allocation/free functions. For this matter the following was done:
+ The XpmAttributes structure has three new fields alloc_color,
+ free_color, and color_closure. The following new valuemasks were
+ added XpmAllocColorFunc, XpmFreeColorsFunc, XpmColorClosure. And
+ two new types were defined XpmAllocColorFunc and XpmFreeColorsFunc.
+ See documentation for details.
+
+ ENHANCEMENTS:
+ - Windows NT support. It should compile and run fine based on the X
+ Consortium X11R6 distribution.
+ - The README file contains information to compile on Solaris with gcc.
+ - Part of the code has been optimized by using the value returned by
+ sprintf instead of calling strlen. Add the flag -DVOID_SPRINTF
+ if on your system sprintf returns void.
+ - patch from Thomas Ott thommy@rz.fh-augsburg.de
+
+ BUGS CORRECTED:
+ - XpmFree is now a real function (simply calling free by default).
+
+ CHANGES TO THE DOC:
+ - The documentation describes the new XpmAttributes fields and their
+ use.
+
+3.4h (96/02/01)
+
+ NEW FEATURES:
+ - The XpmAttributes has a new member called 'alloc_close_colors' which
+ lets the caller specify whether close colors should be allocated
+ using XAllocColor or not. This is especially useful when one uses a
+ private colormap full of read/write cells.
+ The xpm.h header file define a new bitmap flag called
+ XpmAllocCloseColors to use along with this new slot.
+ - Dale Pease peased@bigbird.cso.gtegsc.com
+ - The XpmAttributes has a new member called 'bitmap_format' which lets
+ the caller specify the format of 1 bit depth images (XYBitmap or
+ ZPixmap). The xpm.h header file define a new bitmap flag called
+ XpmBitmapFormat to use along with this new field.
+
+ ENHANCEMENTS:
+ - XpmReadFileTo[Image/Pixmap], XpmCreate[Image/Pixmap]FromData,
+ XpmCreateImageFromDataFromBuffer functions do no longer use a
+ temporary XpmImage object, which reduces a lot the amount of memory
+ used. On the other hand it can take a little more time, but given the
+ following figures (based on sxpm) it is a real good trade-off.
+
+ Reading a 22x22 pixmap with 5 colors no time change is detected
+ using time:
+ real 0.3
+ user 0.1
+ sys 0.1
+
+ Reading a 1279x1023 pixmap with 14 colors (quite extreme case for
+ XPM!) the time goes from:
+ real 1.9
+ user 0.8
+ sys 0.8
+
+ to:
+ real 2.2
+ user 1.8
+ sys 0.3
+
+ Reading the 22x22 pixmap with 5 colors the memory usage (under
+ purify) goes from:
+ 255256 code
+ 55496 data/bss
+ 163848 heap (peak use)
+ 4248 stack
+ to:
+ 271240 code
+ 55472 data/bss
+ 159752 heap (peak use)
+ 4224 stack
+
+ And reading the 1279x1023 pixmap with 14 colors it goes from:
+ 255256 code
+ 55496 data/bss
+ 6705160 heap (peak use)
+ 4280 stack
+ to:
+ 271240 code
+ 55472 data/bss
+ 1732616 heap (peak use)
+ 4264 stack
+
+ This clearly shows that while for small pixmaps there is no real
+ difference on both sides, for large pixmaps this makes a huge
+ difference about the amount of memory used and it is not much
+ slower.
+
+ Note that you can still get the old behavior using both
+ XpmReadFileToXpmImage and XpmCreate[Image/Pixmap]FromXpmImage instead
+ of XpmReadFileTo[Image/Pixmap]. Once more XPM gives you the choice!
+
+ BUGS CORRECTED:
+ - when defined locally the global symbols strcasecmp and strdup are
+ now called xpmstrcasecmp and xpmstrdup to avoid any possible
+ conflict.
+ - VMS has a bogus file system which requires a work around in
+ XpmReadFileToBuffer.
+ - patch from Bob.Deen@jpl.nasa.gov
+ - the type of the exactColors attribute has been changed from unsigned
+ int to Bool.
+
+ CHANGES TO THE DOC:
+ - the documentation describes the new XpmAttributes fields
+ alloc_close_colors and bitmap_format.
+
+3.4g (95/10/08)
+
+ ENHANCEMENTS:
+ - The XpmAttributes structure has now two new slots: alloc_pixels and
+ nalloc_pixels in order to provide an easy way to free allocated
+ colors. The new bitmask XpmReturnAllocPixels should be used to
+ request this data through the valuemask. Unless you really know why,
+ you should use this instead of XpmReturnPixels, pixels, and npixels.
+ - the XPM1 format parsing has been improved.
+ - patch from Chuck Thompson <cthomp@cs.uiuc.edu>
+ - compilers defining _STDC_ to something different from 1 are now
+ considered as ANSI compilers.
+ - the README file provides now more info on how to build XPM depending
+ on the system.
+
+ BUGS CORRECTED:
+ - a bug introduced in 3.4f in the XPM1 format parsing function.
+ - fix from Chuck Thompson <cthomp@cs.uiuc.edu>
+ - the hashtable was not free when the color parsing failed.
+ - patch from ackley@cs.unm.edu (David Ackley)
+ - the close color mechanism wasn't used if one of the closeness
+ parameter was null. Now only one needs to be different from 0.
+ Lorens Younes d93-hyo@nada.kth.se
+ - parsing of long comments failed with a segmentation fault.
+
+ CHANGES TO THE DOC:
+ - the documentation describes the new XpmAttributes fields
+ alloc_pixels and nalloc_pixels and how they are used.
+
+3.4f (95/05/29)
+
+ ENHANCEMENTS:
+ - Defines IMAKE_DEFINES in the top Imakefile so one can easily avoid
+ building the shared library.
+ - Add some information about the installation process in the README.
+ - filenames are surrounded with quotes when calling gzip or compress in
+ order to allow spaces within filenames.
+ - William Parn <parn@fgm.com>
+ - the compilation and the shared library building should be smoother
+ on Alpha OSF/1.
+ - patch from Dale Moore <Dale.Moore@CS.cmu.edu>
+
+ BUGS CORRECTED:
+ - a segmentation fault occurring in some weird case.
+
+3.4e (95/03/01)
+
+ ENHANCEMENTS:
+ - The top Imakefile passes CDEBUGFLAGS and DEFINES to subdirs. Thus
+ only this Imakefile should need to be edited by users.
+ - FAQ includes the answer to the question "How can I get a non
+ rectangular icon using XPM ?"
+ - VMS support updated
+ - patch from Martin P.J. Zinser m.zinser@gsi.de
+
+ BUGS CORRECTED:
+ - XpmCreateImageFromXpmImage() called from XpmReadFileToPixmap() could
+ lead to a segmentation fault since free was called on a memory block
+ size variable instead of the block itself. Note: this bug has been
+ introduced in 3.4d.
+
+3.4d (95/01/31)
+
+ ENHANCEMENTS:
+ - sxpm now supports a -version option command.
+
+ BUGS CORRECTED:
+ - the list of pixels returned in XpmAttributes was wrong when two
+ colors were defined as None in the read XPM
+ - Lionel.Mallet@sophia.inria.fr
+ - the parser was skipping whitespace reading extensions strings. This
+ has been fixed so extensions lines are now returned exactly as they
+ are.
+ - some compilation control added for the dec alpha with X11R5 (LONG64)
+ - patch from Fredrik Lundh <Fredrik_Lundh@ivab.se>
+ - when writing an XPM file, '-' characters are replaced with '_'
+ characters in the array name, in order to get a valid C syntax name.
+ - XYPixmap format images were not correctly handled.
+ - XPM1 file with names using multiple '_' characters are now handled
+ correctly.
+ - todd@erda.rl.af.mil (Todd Gleason)
+
+3.4c (94/06/06)
+
+ Yes, this is kind of quick. But this is because no code has been modified,
+ this is just a new packaging to make the whole stuff more suitable to the
+ X development team's requests for inclusion in the R6 contrib.
+
+ ENHANCEMENTS:
+ - Several filenames were too long to fit without any conflict on DOS
+ and CD-ROM filesystems. They have been renamed.
+ - Imakefiles use XCOMM for comments instead of the # character.
+ - the Postscript documentation file doc/xpm.ps is now distributed as
+ doc/xpm.PS.gz and allows browsing with tools such as ghostview.
+ - Besides, parts of lib/misc.c have been moved to several new files,
+ and some functions of data.c have been moved to other files in
+ order to get a better link profile.
+ - I've also added a FAQ hoping this will prevent people from
+ continuously filling my mailbox with the same questions.
+ - sxpm.c includes <X11/xpm.h> instead of "xpm.h" and BUILDINCTOP is
+ used in Makefiles as expected.
+ - Everything can be done simply using "xmkmf -a" and "make".
+
3.4b (94/05/24)
ENHANCEMENTS:
defined.
- The XpmInfo struct has been extended to avoid having to deal with an
XpmAttributes at the lower level. The idea is that all the data
- stored in an Xpm file can be retreive through both an XpmImage and
+ stored in an Xpm file can be retrieve through both an XpmImage and
an XpmInfo struct. See the documentation for details.
- XpmUndefPixel is defined and exported by xpm.h in order to let
- clients providing their own colorTable when writting out an Xpm file.
+ clients providing their own colorTable when writing out an Xpm file.
See the documentation for details.
- in sxpm/sxpm.c, set attribute XtNinput to True on toplevel widget.
Windows that don't "take" input, never get focus, as mandated by
patch from simon@lia.di.epfl.ch (Simon Leinen)
NEW FEATURES:
- - a new funtion and a new define should help client figuring out with
+ - a new function and a new define should help client figuring out with
which Xpm library version they are working. These are
XpmIncludeVersion and XpmLibraryVersion().
BUGS CORRECTED:
- reading some binary file was leading to a bus error.
- patch from Detlef Schmier <detlef@mfr.dec.com>
- - the ? character is no longer used when writting an XPM file in order
+ - the ? character is no longer used when writing an XPM file in order
to avoid possible ANSI trigraphs.
3.3alpha (93/08/13)
- a separate distribution called xpm-contrib is available. This
includes the converters which used to be part of this distribution
plus:
- two new appplications:
+ two new applications:
* nexpm to draw a pixmap in *any* existing window from
Ralph Betza <gnohmon@ssiny.com>
* xpmview to display a list of Xpm files from
- The documentation has been ported from LaTeX to FrameMaker and is
now included in the distribution in its PostScript form (doc/xpm.ps).
Source files are available on request.
- Also the documentation has been reoreganized and includes a table of
+ Also the documentation has been reorganized and includes a table of
contents and an index of the functions (the number of functions
increasing this became a requisite).
BUGS CORRECTED:
- Intrinsic.h is no longer included.
- bzero is defined as memset on SYSV and SVR4.
- - some memory initialisation bug concerning XpmAttributes.
+ - some memory initialization bug concerning XpmAttributes.
3.2d (93/01/27)
- Jason Patterson <jasonp@fitmail.qut.edu.au>
- errors while parsing or allocating colors now revert to other
visual defaults, creating pixmap/image as expected, and returning
- XpmSuccess. The old behaviour of XpmColorError being returned and no
+ XpmSuccess. The old behavior of XpmColorError being returned and no
pixmap/image being created can be retained by setting the
exactColors attribute.
- Jason Patterson <jasonp@fitmail.qut.edu.au>
[-rgb filename] Search color names in the rgb text file
'filename'.
- if no input is specified sxpm reads from stdandard input.
+ if no input is specified sxpm reads from standard input.
- Xpm functions and Ppm converters now deal with multiword colornames.
the XCreatePixmapFromData function later on.
- a new structure: XpmAttributes which replace the XpmInfo structure
and which leads to a much simpler API with less arguments.
- - arguments such as visual, colormap and depth are optionnal, default
+ - arguments such as visual, colormap and depth are optional, default
values are taken if omitted.
- parsing and allocating color failures don't simply break anymore. If
another default color can be found it is used and a PixmapColorError
BUGS CORRECTED:
- I've again improved the memory management.
- the parser is also improved.
- - when writting a pixmap to a file the variable name could be
+ - when writing a pixmap to a file the variable name could be
"plaid.xpm" which is not valid in C. Now the extension name is cut off
to give "plaid" as variable name.
- reading multiple words colornames such as "peach puff" where leading
BUGS CORRECTED:
- the memory management has been much improved in order to avoid
memory leaks.
- - the XImage building algorythm has been changed to support correctly
+ - the XImage building algorithm has been changed to support correctly
different visual depths. There is special code to handle depths 1, 4,
6, 8, 24, and 32 to build the image and send it in one whack, and
other depths are supported by building the image with XPutPixel which
2.5 (90/10/17)
BUGS CORRECTED:
- - XWritePixmapFile was not closing the file while ending normaly.
+ - XWritePixmapFile was not closing the file while ending normally.
2.4 (90/09/06)
2.3 (90/08/30)
BUGS CORRECTED:
- - handle monochrom display correctly,
+ - handle monochrome display correctly,
- comments can be empty.
2.2 (90/08/27)
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* XpmCrBufFrI.c: *
+* CrBufFrI.c: *
* *
* XPM library *
* Scan an image and possibly its mask and create an XPM buffer *
* Developed by Arnaud Le Hors *
\*****************************************************************************/
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:string.h"
-#else
-#if defined(SYSV) || defined(SVR4)
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#endif
+#include "XpmI.h"
LFUNC(WriteColors, int, (char **dataptr, unsigned int *data_size,
unsigned int *used_size, XpmColor *colors,
LFUNC(CommentsSize, int, (XpmInfo *info));
int
-XpmCreateBufferFromImage(Display *display, char **buffer_return, XImage *image,
- XImage *shapeimage, XpmAttributes *attributes)
+XpmCreateBufferFromImage(display, buffer_return, image, shapeimage, attributes)
+ Display *display;
+ char **buffer_return;
+ XImage *image;
+ XImage *shapeimage;
+ XpmAttributes *attributes;
{
XpmImage xpmimage;
XpmInfo info;
#undef RETURN
#define RETURN(status) \
{ \
- if (ptr) \
- XpmFree(ptr); \
- return(status); \
+ ErrorStatus = status; \
+ goto error; \
}
int
-XpmCreateBufferFromXpmImage(char **buffer_return, XpmImage *image, XpmInfo *info)
+XpmCreateBufferFromXpmImage(buffer_return, image, info)
+ char **buffer_return;
+ XpmImage *image;
+ XpmInfo *info;
{
/* calculation variables */
int ErrorStatus;
cmt_size = CommentsSize(info);
/* write the header line */
+#ifndef VOID_SPRINTF
+ used_size =
+#endif
sprintf(buf, "/* XPM */\nstatic char * image_name[] = {\n");
+#ifdef VOID_SPRINTF
used_size = strlen(buf);
+#endif
ptr_size = used_size + ext_size + cmt_size + 1;
ptr = (char *) XpmMalloc(ptr_size);
if (!ptr)
/* write the values line */
if (cmts && info->hints_cmt) {
+#ifndef VOID_SPRINTF
+ used_size +=
+#endif
sprintf(ptr + used_size, "/*%s*/\n", info->hints_cmt);
+#ifdef VOID_SPRINTF
used_size += strlen(info->hints_cmt) + 5;
+#endif
}
+#ifndef VOID_SPRINTF
+ l =
+#endif
sprintf(buf, "\"%d %d %d %d", image->width, image->height,
image->ncolors, image->cpp);
+#ifdef VOID_SPRINTF
l = strlen(buf);
+#endif
if (info && (info->valuemask & XpmHotspot)) {
+#ifndef VOID_SPRINTF
+ l +=
+#endif
sprintf(buf + l, " %d %d", info->x_hotspot, info->y_hotspot);
+#ifdef VOID_SPRINTF
l = strlen(buf);
+#endif
}
if (extensions) {
+#ifndef VOID_SPRINTF
+ l +=
+#endif
sprintf(buf + l, " XPMEXT");
+#ifdef VOID_SPRINTF
l = strlen(buf);
+#endif
}
+#ifndef VOID_SPRINTF
+ l +=
+#endif
sprintf(buf + l, "\",\n");
+#ifdef VOID_SPRINTF
l = strlen(buf);
+#endif
ptr_size += l;
p = (char *) XpmRealloc(ptr, ptr_size);
if (!p)
/* write colors */
if (cmts && info->colors_cmt) {
+#ifndef VOID_SPRINTF
+ used_size +=
+#endif
sprintf(ptr + used_size, "/*%s*/\n", info->colors_cmt);
+#ifdef VOID_SPRINTF
used_size += strlen(info->colors_cmt) + 5;
+#endif
}
ErrorStatus = WriteColors(&ptr, &ptr_size, &used_size,
image->colorTable, image->ncolors, image->cpp);
RETURN(ErrorStatus);
/*
- * now we know the exact size we needed, realloc the data 4 = 1 (for
- * '"') + 3 (for '",\n') 1 = - 2 is because the last line does not end
- * with ',\n' + 3 (for '};\n')
+ * now we know the exact size we need, realloc the data
+ * 4 = 1 (for '"') + 3 (for '",\n')
+ * 1 = - 2 (because the last line does not end with ',\n') + 3 (for '};\n')
*/
ptr_size += image->height * (image->width * image->cpp + 4) + 1;
/* print pixels */
if (cmts && info->pixels_cmt) {
+#ifndef VOID_SPRINTF
+ used_size +=
+#endif
sprintf(ptr + used_size, "/*%s*/\n", info->pixels_cmt);
+#ifdef VOID_SPRINTF
used_size += strlen(info->pixels_cmt) + 5;
+#endif
}
WritePixels(ptr + used_size, &used_size, image->width, image->height,
image->cpp, image->data, image->colorTable);
info->extensions, info->nextensions);
/* close the array */
- sprintf(ptr + used_size, "};\n");
+ strcpy(ptr + used_size, "};\n");
*buffer_return = ptr;
return (XpmSuccess);
+
+/* exit point in case of error, free only locally allocated variables */
+error:
+ if (ptr)
+ XpmFree(ptr);
+ return (ErrorStatus);
}
static int
-WriteColors(char **dataptr, unsigned int *data_size, unsigned int *used_size,
- XpmColor *colors, unsigned int ncolors, unsigned int cpp)
+WriteColors(dataptr, data_size, used_size, colors, ncolors, cpp)
+ char **dataptr;
+ unsigned int *data_size;
+ unsigned int *used_size;
+ XpmColor *colors;
+ unsigned int ncolors;
+ unsigned int cpp;
{
char buf[BUFSIZ];
unsigned int a, key, l;
for (key = 1; key <= NKEYS; key++, defaults++) {
if (s2 = *defaults) {
+#ifndef VOID_SPRINTF
+ s +=
+#endif
sprintf(s, "\t%s %s", xpmColorKeys[key - 1], s2);
+#ifdef VOID_SPRINTF
s += strlen(s);
+#endif
}
}
strcpy(s, "\",\n");
- l = strlen(buf);
+ l = s + 3 - buf;
s = (char *) XpmRealloc(*dataptr, *data_size + l);
if (!s)
return (XpmNoMemory);
}
static void
-WritePixels(char *dataptr, unsigned int *used_size, unsigned int width, unsigned int height,
- unsigned int cpp, unsigned int *pixels, XpmColor *colors)
+WritePixels(dataptr, used_size, width, height, cpp, pixels, colors)
+ char *dataptr;
+ unsigned int *used_size;
+ unsigned int width;
+ unsigned int height;
+ unsigned int cpp;
+ unsigned int *pixels;
+ XpmColor *colors;
{
char *s = dataptr;
unsigned int x, y, h;
}
static int
-ExtensionsSize(XpmExtension *ext, unsigned int num)
+ExtensionsSize(ext, num)
+ XpmExtension *ext;
+ unsigned int num;
{
unsigned int x, y, a, size;
char **line;
}
static void
-WriteExtensions(char *dataptr, unsigned int *used_size, XpmExtension *ext, unsigned int num)
+WriteExtensions(dataptr, used_size, ext, num)
+ char *dataptr;
+ unsigned int *used_size;
+ XpmExtension *ext;
+ unsigned int num;
{
unsigned int x, y, a;
char **line;
char *s = dataptr;
for (x = 0; x < num; x++, ext++) {
+#ifndef VOID_SPRINTF
+ s +=
+#endif
sprintf(s, ",\n\"XPMEXT %s\"", ext->name);
+#ifdef VOID_SPRINTF
s += strlen(ext->name) + 11;
+#endif
a = ext->nlines;
for (y = 0, line = ext->lines; y < a; y++, line++) {
+#ifndef VOID_SPRINTF
+ s +=
+#endif
sprintf(s, ",\n\"%s\"", *line);
+#ifdef VOID_SPRINTF
s += strlen(*line) + 4;
+#endif
}
}
strcpy(s, ",\n\"XPMENDEXT\"");
}
static int
-CommentsSize(XpmInfo *info)
+CommentsSize(info)
+ XpmInfo *info;
{
int size = 0;
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-/*****************************************************************************\
-* XpmCrBufFrP.c: *
-* *
-* XPM library *
-* Scan a pixmap and possibly its mask and create an XPM buffer *
-* *
-* Developed by Arnaud Le Hors *
-\*****************************************************************************/
-
-#ifndef FOR_MSW
-
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:string.h"
-#else
-#if defined(SYSV) || defined(SVR4)
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#endif
-
-int
-XpmCreateBufferFromPixmap(Display *display, char **buffer_return, Pixmap pixmap, Pixmap shapemask,
- XpmAttributes *attributes)
-{
- XImage *ximage = NULL;
- XImage *shapeimage = NULL;
- unsigned int width = 0;
- unsigned int height = 0;
- int ErrorStatus;
-
- /* get geometry */
- if (attributes && attributes->valuemask & XpmSize) {
- width = attributes->width;
- height = attributes->height;
- }
- /* get the ximages */
- if (pixmap)
- xpmCreateImageFromPixmap(display, pixmap, &ximage, &width, &height);
- if (shapemask)
- xpmCreateImageFromPixmap(display, shapemask, &shapeimage,
- &width, &height);
-
- /* create the buffer */
- ErrorStatus = XpmCreateBufferFromImage(display, buffer_return, ximage,
- shapeimage, attributes);
-
- /* destroy the ximages */
- if (ximage)
- XDestroyImage(ximage);
- if (shapeimage)
- XDestroyImage(shapeimage);
-
- return (ErrorStatus);
-}
-#endif
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* XpmCrDataFI.c: *
+* CrDataFI.c: *
* *
* XPM library *
* Scan an image and possibly its mask and create an XPM array *
* Developed by Arnaud Le Hors *
\*****************************************************************************/
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:string.h"
-#else
-#if defined(SYSV) || defined(SVR4)
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#endif
+#include "XpmI.h"
LFUNC(CreateColors, int, (char **dataptr, unsigned int *data_size,
XpmColor *colors, unsigned int ncolors,
unsigned int ext_nlines));
int
-XpmCreateDataFromImage(Display *display, char ***data_return, XImage *image,
- XImage *shapeimage, XpmAttributes *attributes)
+XpmCreateDataFromImage(display, data_return, image, shapeimage, attributes)
+ Display *display;
+ char ***data_return;
+ XImage *image;
+ XImage *shapeimage;
+ XpmAttributes *attributes;
{
XpmImage xpmimage;
XpmInfo info;
#undef RETURN
#define RETURN(status) \
{ \
- if (header) { \
- for (l = 0; l < header_nlines; l++) \
- if (header[l]) \
- XpmFree(header[l]); \
- XpmFree(header); \
- } \
- return(status); \
+ ErrorStatus = status; \
+ goto exit; \
}
int
-XpmCreateDataFromXpmImage(char ***data_return, XpmImage *image, XpmInfo *info)
+XpmCreateDataFromXpmImage(data_return, image, info)
+ char ***data_return;
+ XpmImage *image;
+ XpmInfo *info;
{
/* calculation variables */
int ErrorStatus;
/* print the hints line */
s = buf;
+#ifndef VOID_SPRINTF
+ s +=
+#endif
sprintf(s, "%d %d %d %d", image->width, image->height,
image->ncolors, image->cpp);
+#ifdef VOID_SPRINTF
s += strlen(s);
+#endif
if (info && (info->valuemask & XpmHotspot)) {
+#ifndef VOID_SPRINTF
+ s +=
+#endif
sprintf(s, " %d %d", info->x_hotspot, info->y_hotspot);
+#ifdef VOID_SPRINTF
s += strlen(s);
+#endif
}
- if (extensions)
- sprintf(s, " XPMEXT");
-
- l = strlen(buf) + 1;
+ if (extensions) {
+ strcpy(s, " XPMEXT");
+ s += 7;
+ }
+ l = s - buf + 1;
*header = (char *) XpmMalloc(l);
if (!*header)
RETURN(XpmNoMemory);
ext_nlines);
*data_return = data;
-
- RETURN(XpmSuccess);
+ ErrorStatus = XpmSuccess;
+
+/* exit point, free only locally allocated variables */
+exit:
+ if (header) {
+ for (l = 0; l < header_nlines; l++)
+ if (header[l])
+ XpmFree(header[l]);
+ XpmFree(header);
+ }
+ return(ErrorStatus);
}
static int
-CreateColors(char **dataptr, unsigned int *data_size, XpmColor *colors, unsigned int ncolors, unsigned int cpp)
+CreateColors(dataptr, data_size, colors, ncolors, cpp)
+ char **dataptr;
+ unsigned int *data_size;
+ XpmColor *colors;
+ unsigned int ncolors;
+ unsigned int cpp;
{
char buf[BUFSIZ];
unsigned int a, key, l;
for (key = 1; key <= NKEYS; key++, defaults++) {
if (s2 = *defaults) {
+#ifndef VOID_SPRINTF
+ s +=
+#endif
sprintf(s, "\t%s %s", xpmColorKeys[key - 1], s2);
+#ifdef VOID_SPRINTF
s += strlen(s);
+#endif
}
}
- l = strlen(buf) + 1;
+ l = s - buf + 1;
s = (char *) XpmMalloc(l);
if (!s)
return (XpmNoMemory);
*data_size += l;
- strcpy(s, buf);
- *dataptr = s;
+ *dataptr = strcpy(s, buf);
}
return (XpmSuccess);
}
static void
-CreatePixels(char **dataptr, unsigned int width, unsigned int height, unsigned int cpp,
- unsigned int *pixels, XpmColor *colors)
+CreatePixels(dataptr, width, height, cpp, pixels, colors)
+ char **dataptr;
+ unsigned int width;
+ unsigned int height;
+ unsigned int cpp;
+ unsigned int *pixels;
+ XpmColor *colors;
{
char *s;
unsigned int x, y, h, offset;
}
static void
-CountExtensions(XpmExtension *ext, unsigned int num, unsigned int *ext_size, unsigned int *ext_nlines)
+CountExtensions(ext, num, ext_size, ext_nlines)
+ XpmExtension *ext;
+ unsigned int num;
+ unsigned int *ext_size;
+ unsigned int *ext_nlines;
{
unsigned int x, y, a, size, nlines;
char **line;
}
static void
-CreateExtensions(char **dataptr, unsigned int offset, XpmExtension *ext, unsigned int num, unsigned int ext_nlines)
+CreateExtensions(dataptr, offset, ext, num, ext_nlines)
+ char **dataptr;
+ unsigned int offset;
+ XpmExtension *ext;
+ unsigned int num;
+ unsigned int ext_nlines;
{
unsigned int x, y, a, b;
char **line;
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-/*****************************************************************************\
-* XpmCrDataFP.c: *
-* *
-* XPM library *
-* Scan a pixmap and possibly its mask and create an XPM array *
-* *
-* Developed by Arnaud Le Hors *
-\*****************************************************************************/
-
-#ifndef FOR_MSW
-
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:string.h"
-#else
-#if defined(SYSV) || defined(SVR4)
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#endif
-
-int
-XpmCreateDataFromPixmap(Display *display, char ***data_return, Pixmap pixmap,
- Pixmap shapemask, XpmAttributes *attributes)
-{
- XImage *ximage = NULL;
- XImage *shapeimage = NULL;
- unsigned int width = 0;
- unsigned int height = 0;
- int ErrorStatus;
-
- /* get geometry */
- if (attributes && attributes->valuemask & XpmSize) {
- width = attributes->width;
- height = attributes->height;
- }
- /* get the ximages */
- if (pixmap)
- xpmCreateImageFromPixmap(display, pixmap, &ximage, &width, &height);
- if (shapemask)
- xpmCreateImageFromPixmap(display, shapemask, &shapeimage,
- &width, &height);
-
- /* create the data */
- ErrorStatus = XpmCreateDataFromImage(display, data_return, ximage,
- shapeimage, attributes);
-
- /* destroy the ximages */
- if (ximage)
- XDestroyImage(ximage);
- if (shapeimage)
- XDestroyImage(shapeimage);
-
- return (ErrorStatus);
-}
-
-#endif
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* *
* XPM library *
* Create an X image and possibly its related shape mask *
-* from the given xpmInternAttrib. *
+* from the given XpmImage. *
* *
* Developed by Arnaud Le Hors *
\*****************************************************************************/
* HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
*/
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:ctype.h"
-#else
+/*
+ * The code related to AMIGA has been added by
+ * Lorens Younes (d93-hyo@nada.kth.se) 4/96
+ */
+
+#include "XpmI.h"
#include <ctype.h>
-#endif
LFUNC(xpmVisualType, int, (Visual *visual));
+LFUNC(AllocColor, int, (Display *display, Colormap colormap,
+ char *colorname, XColor *xcolor, void *closure));
+LFUNC(FreeColors, int, (Display *display, Colormap colormap,
+ Pixel *pixels, int n, void *closure));
+
#ifndef FOR_MSW
LFUNC(SetCloseColor, int, (Display *display, Colormap colormap,
Visual *visual, XColor *col,
Pixel *image_pixel, Pixel *mask_pixel,
- Pixel **pixels, unsigned int *npixels,
- XpmAttributes *attributes,
- XColor *cols, int ncols));
+ Pixel *alloc_pixels, unsigned int *nalloc_pixels,
+ XpmAttributes *attributes, XColor *cols, int ncols,
+ XpmAllocColorFunc allocColor, void *closure));
#else
/* let the window system take care of close colors */
#endif
LFUNC(SetColor, int, (Display *display, Colormap colormap, Visual *visual,
char *colorname, unsigned int color_index,
Pixel *image_pixel, Pixel *mask_pixel,
- unsigned int *mask_pixel_index, Pixel **pixels,
- unsigned int *npixels, XpmAttributes *attributes,
- XColor *cols, int ncols));
+ unsigned int *mask_pixel_index,
+ Pixel *alloc_pixels, unsigned int *nalloc_pixels,
+ Pixel *used_pixels, unsigned int *nused_pixels,
+ XpmAttributes *attributes, XColor *cols, int ncols,
+ XpmAllocColorFunc allocColor, void *closure));
LFUNC(CreateXImage, int, (Display *display, Visual *visual,
- unsigned int depth, unsigned int width,
- unsigned int height, XImage **image_return));
+ unsigned int depth, int format, unsigned int width,
+ unsigned int height, XImage **image_return));
LFUNC(CreateColors, int, (Display *display, XpmAttributes *attributes,
- XpmColor *ct, unsigned int ncolors, Pixel *ip,
- Pixel *mp, unsigned int *mask_pixel,
- Pixel **pixels, unsigned int *npixels));
+ XpmColor *colors, unsigned int ncolors,
+ Pixel *image_pixels, Pixel *mask_pixels,
+ unsigned int *mask_pixel_index,
+ Pixel *alloc_pixels, unsigned int *nalloc_pixels,
+ Pixel *used_pixels, unsigned int *nused_pixels));
+
+#ifndef FOR_MSW
+LFUNC(ParseAndPutPixels, int, (xpmData *data, unsigned int width,
+ unsigned int height, unsigned int ncolors,
+ unsigned int cpp, XpmColor *colorTable,
+ xpmHashTable *hashtable,
+ XImage *image, Pixel *image_pixels,
+ XImage *mask, Pixel *mask_pixels));
+#else /* FOR_MSW */
+LFUNC(ParseAndPutPixels, int, (Display *dc, xpmData *data, unsigned int width,
+ unsigned int height, unsigned int ncolors,
+ unsigned int cpp, XpmColor *colorTable,
+ xpmHashTable *hashtable,
+ XImage *image, Pixel *image_pixels,
+ XImage *mask, Pixel *mask_pixels));
+#endif
#ifndef FOR_MSW
+# ifndef AMIGA
/* XImage pixel routines */
-LFUNC(SetImagePixels, void, (XImage *image, unsigned int width,
+LFUNC(PutImagePixels, void, (XImage *image, unsigned int width,
unsigned int height, unsigned int *pixelindex,
Pixel *pixels));
-LFUNC(SetImagePixels32, void, (XImage *image, unsigned int width,
+LFUNC(PutImagePixels32, void, (XImage *image, unsigned int width,
unsigned int height, unsigned int *pixelindex,
Pixel *pixels));
-LFUNC(SetImagePixels16, void, (XImage *image, unsigned int width,
+LFUNC(PutImagePixels16, void, (XImage *image, unsigned int width,
unsigned int height, unsigned int *pixelindex,
Pixel *pixels));
-LFUNC(SetImagePixels8, void, (XImage *image, unsigned int width,
+LFUNC(PutImagePixels8, void, (XImage *image, unsigned int width,
unsigned int height, unsigned int *pixelindex,
Pixel *pixels));
-LFUNC(SetImagePixels1, void, (XImage *image, unsigned int width,
+LFUNC(PutImagePixels1, void, (XImage *image, unsigned int width,
unsigned int height, unsigned int *pixelindex,
Pixel *pixels));
-#else /* ndef FOR_MSW */
+
+LFUNC(PutPixel1, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel32, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel32MSB, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel32LSB, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel16MSB, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel16LSB, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel8, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel1MSB, int, (XImage *ximage, int x, int y, unsigned long pixel));
+LFUNC(PutPixel1LSB, int, (XImage *ximage, int x, int y, unsigned long pixel));
+
+# else /* AMIGA */
+LFUNC(APutImagePixels, void, (XImage *ximage, unsigned int width,
+ unsigned int height, unsigned int *pixelindex,
+ Pixel *pixels));
+# endif/* AMIGA */
+#else /* FOR_MSW */
/* FOR_MSW pixel routine */
-LFUNC(MSWSetImagePixels, void, (Display *dc, XImage *image,
+LFUNC(MSWPutImagePixels, void, (Display *dc, XImage *image,
unsigned int width, unsigned int height,
unsigned int *pixelindex, Pixel *pixels));
-#endif /* ndef FOR_MSW */
+#endif /* FOR_MSW */
#ifdef NEED_STRCASECMP
-FUNC(strcasecmp, int, (char *s1, char *s2));
+FUNC(xpmstrcasecmp, int, (char *s1, char *s2));
/*
* in case strcasecmp is not provided by the system here is one
* which does the trick
*/
int
-strcasecmp(register char *s1, register char *s2)
+xpmstrcasecmp(s1, s2)
+ register char *s1, *s2;
{
register int c1, c2;
* return the default color key related to the given visual
*/
static int
-xpmVisualType(Visual *visual)
+xpmVisualType(visual)
+ Visual *visual;
{
#ifndef FOR_MSW
-/* Xlib.h defines this to be c_class or class, depending
- * on whether we're doing C++ or C
- */
-#if defined(__cplusplus) || defined(c_plusplus)
- switch (visual->c_class)
-#else
- switch (visual->class)
-#endif
- {
+# ifndef AMIGA
+ switch (visual->class) {
case StaticGray:
case GrayScale:
switch (visual->map_entries) {
default:
return (XPM_COLOR);
}
+# else
+ /* set the key explicitly in the XpmAttributes to override this */
+ return (XPM_COLOR);
+# endif
#else
/* there should be a similar switch for MSW */
return (XPM_COLOR);
} CloseColor;
static int
-closeness_cmp(const void *a, const void *b)
+closeness_cmp(a, b)
+ Const void *a, *b;
{
CloseColor *x = (CloseColor *) a, *y = (CloseColor *) b;
return (int) (x->closeness - y->closeness);
}
+
+/* default AllocColor function:
+ * call XParseColor if colorname is given, return negative value if failure
+ * call XAllocColor and return 0 if failure, positive otherwise
+ */
+static int
+AllocColor(display, colormap, colorname, xcolor, closure)
+ Display *display;
+ Colormap colormap;
+ char *colorname;
+ XColor *xcolor;
+ void *closure; /* not used */
+{
+ int status;
+ if (colorname)
+ if (!XParseColor(display, colormap, colorname, xcolor))
+ return -1;
+ status = XAllocColor(display, colormap, xcolor);
+ return status != 0 ? 1 : 0;
+}
+
+
#ifndef FOR_MSW
/*
* set a close color in case the exact one can't be set
*/
static int
-SetCloseColor(Display *display, Colormap colormap, Visual *visual, XColor *col,
- Pixel *image_pixel, Pixel *mask_pixel, Pixel **pixels, unsigned int *npixels, XpmAttributes *attributes,
- XColor *cols, int ncols)
+SetCloseColor(display, colormap, visual, col, image_pixel, mask_pixel,
+ alloc_pixels, nalloc_pixels, attributes, cols, ncols,
+ allocColor, closure)
+ Display *display;
+ Colormap colormap;
+ Visual *visual;
+ XColor *col;
+ Pixel *image_pixel, *mask_pixel;
+ Pixel *alloc_pixels;
+ unsigned int *nalloc_pixels;
+ XpmAttributes *attributes;
+ XColor *cols;
+ int ncols;
+ XpmAllocColorFunc allocColor;
+ void *closure;
{
/*
long int red_closeness, green_closeness, blue_closeness;
int n;
+ Bool alloc_color;
if (attributes && (attributes->valuemask & XpmCloseness))
red_closeness = green_closeness = blue_closeness =
green_closeness = attributes->green_closeness;
blue_closeness = attributes->blue_closeness;
}
-
+ if (attributes && (attributes->valuemask & XpmAllocCloseColors))
+ alloc_color = attributes->alloc_close_colors;
+ else
+ alloc_color = True;
/*
* We sort the colormap by closeness and try to allocate the color
* occurred, so we try the next closest color, and so on, until no more
* colors are within closeness of the target. If we knew that the
* colormap had changed, we could skip this sequence.
- *
+ *
* If _none_ of the colors within closeness of the target can be allocated,
* then we can finally be pretty sure that the colormap has actually
* changed. In this case we try to allocate the original color (again),
* then try the closecolor stuff (again)...
- *
+ *
* In theory it would be possible for an infinite loop to occur if another
* process kept changing the colormap every time we sorted it, so we set
* a maximum on the number of iterations. After this many tries, we use
* XGrabServer() to ensure that the colormap remains unchanged.
- *
+ *
* This approach gives particularly bad worst case performance - as many as
* <MaximumIterations> colormap reads and sorts may be needed, and as
* many as <MaximumIterations> * <ColormapSize> attempted allocations
(long) cols[c].green <= (long) col->green + green_closeness &&
(long) cols[c].blue >= (long) col->blue - blue_closeness &&
(long) cols[c].blue <= (long) col->blue + blue_closeness) {
- if (XAllocColor(display, colormap, &cols[c])) {
+ if (alloc_color) {
+ if ((*allocColor)(display, colormap, NULL, &cols[c], closure)){
+ if (n == ITERATIONS)
+ XUngrabServer(display);
+ XpmFree(closenesses);
+ *image_pixel = cols[c].pixel;
+ *mask_pixel = 1;
+ alloc_pixels[(*nalloc_pixels)++] = cols[c].pixel;
+ return (0);
+ } else {
+ ++i;
+ if (i == ncols)
+ break;
+ c = closenesses[i].cols_index;
+ }
+ } else {
if (n == ITERATIONS)
XUngrabServer(display);
XpmFree(closenesses);
*image_pixel = cols[c].pixel;
*mask_pixel = 1;
- (*pixels)[*npixels] = cols[c].pixel;
- (*npixels)++;
return (0);
- } else {
- ++i;
- if (i == ncols)
- break;
- c = closenesses[i].cols_index;
}
}
if (i == 0 || i == ncols) /* no color close enough or cannot */
return (1); /* alloc any color (full of r/w's) */
- if (XAllocColor(display, colormap, col)) {
+ if ((*allocColor)(display, colormap, NULL, col, closure)) {
*image_pixel = col->pixel;
*mask_pixel = 1;
- (*pixels)[*npixels] = col->pixel;
- (*npixels)++;
+ alloc_pixels[(*nalloc_pixels)++] = col->pixel;
return (0);
} else { /* colormap has probably changed, so
* re-read... */
XGrabServer(display);
#if 0
- if (visual->c_class == DirectColor) {
+ if (visual->class == DirectColor) {
/* TODO */
} else
#endif
#define USE_CLOSECOLOR attributes && \
(((attributes->valuemask & XpmCloseness) && attributes->closeness != 0) \
|| ((attributes->valuemask & XpmRGBCloseness) && \
- attributes->red_closeness != 0 \
- && attributes->green_closeness != 0 \
- && attributes->blue_closeness != 0))
+ (attributes->red_closeness != 0 \
+ || attributes->green_closeness != 0 \
+ || attributes->blue_closeness != 0)))
#else
/* FOR_MSW part */
*/
static int
-SetColor(Display *display, Colormap colormap, Visual *visual, char *colorname, unsigned int color_index,
- Pixel *image_pixel, Pixel *mask_pixel, unsigned int *mask_pixel_index,
- Pixel **pixels, unsigned int *npixels, XpmAttributes *attributes, XColor *cols, int ncols)
+SetColor(display, colormap, visual, colorname, color_index,
+ image_pixel, mask_pixel, mask_pixel_index,
+ alloc_pixels, nalloc_pixels, used_pixels, nused_pixels,
+ attributes, cols, ncols, allocColor, closure)
+ Display *display;
+ Colormap colormap;
+ Visual *visual;
+ char *colorname;
+ unsigned int color_index;
+ Pixel *image_pixel, *mask_pixel;
+ unsigned int *mask_pixel_index;
+ Pixel *alloc_pixels;
+ unsigned int *nalloc_pixels;
+ Pixel *used_pixels;
+ unsigned int *nused_pixels;
+ XpmAttributes *attributes;
+ XColor *cols;
+ int ncols;
+ XpmAllocColorFunc allocColor;
+ void *closure;
{
XColor xcolor;
+ int status;
- if (strcasecmp(colorname, TRANSPARENT_COLOR)) {
-#ifdef wx_msw
- if (!XParseColor(display, (Colormap *)colormap, colorname, &xcolor))
-#else
- if (!XParseColor(display, (Colormap)colormap, colorname, &xcolor))
-#endif
+ if (xpmstrcasecmp(colorname, TRANSPARENT_COLOR)) {
+ status = (*allocColor)(display, colormap, colorname, &xcolor, closure);
+ if (status < 0) /* parse color failed */
return (1);
-#ifdef wx_msw
- if (!XAllocColor(display, (Colormap *)colormap, &xcolor)) {
-#else
- if (!XAllocColor(display, (Colormap)colormap, &xcolor)) {
-#endif
+
+ if (status == 0) {
#ifndef FOR_MSW
if (USE_CLOSECOLOR)
return (SetCloseColor(display, colormap, visual, &xcolor,
- image_pixel, mask_pixel, pixels, npixels,
- attributes, cols, ncols));
+ image_pixel, mask_pixel,
+ alloc_pixels, nalloc_pixels,
+ attributes, cols, ncols,
+ allocColor, closure));
else
#endif /* ndef FOR_MSW */
return (1);
- }
+ } else
+ alloc_pixels[(*nalloc_pixels)++] = xcolor.pixel;
*image_pixel = xcolor.pixel;
+#ifndef FOR_MSW
*mask_pixel = 1;
- (*pixels)[*npixels] = xcolor.pixel;
- (*npixels)++;
+#else
+ *mask_pixel = RGB(0,0,0);
+#endif
+ used_pixels[(*nused_pixels)++] = xcolor.pixel;
} else {
*image_pixel = 0;
+#ifndef FOR_MSW
*mask_pixel = 0;
- *mask_pixel_index = color_index; /* store the color table index */
+#else
+ *mask_pixel = RGB(255,255,255);
+#endif
+ /* store the color table index */
+ *mask_pixel_index = color_index;
}
return (0);
}
static int
-CreateColors(Display *display, XpmAttributes *attributes, XpmColor *ct, unsigned int ncolors,
- Pixel *ip, Pixel *mp, unsigned int *mask_pixel, Pixel **pixels, unsigned int *npixels)
+CreateColors(display, attributes, colors, ncolors, image_pixels, mask_pixels,
+ mask_pixel_index, alloc_pixels, nalloc_pixels,
+ used_pixels, nused_pixels)
+ Display *display;
+ XpmAttributes *attributes;
+ XpmColor *colors;
+ unsigned int ncolors;
+ Pixel *image_pixels;
+ Pixel *mask_pixels;
+ unsigned int *mask_pixel_index;
+ Pixel *alloc_pixels;
+ unsigned int *nalloc_pixels;
+ Pixel *used_pixels;
+ unsigned int *nused_pixels;
{
/* variables stored in the XpmAttributes structure */
Visual *visual;
Colormap colormap;
XpmColorSymbol *colorsymbols;
unsigned int numsymbols;
+ XpmAllocColorFunc allocColor;
+ void *closure;
char *colorname;
- unsigned int a, b, l;
- int pixel_defined;
- unsigned int key;
+ unsigned int color, key;
+ Bool pixel_defined;
XpmColorSymbol *symbol;
char **defaults;
int ErrorStatus = XpmSuccess;
else
visual = XDefaultVisual(display, XDefaultScreen(display));
- if (attributes && attributes->valuemask & XpmColormap)
+ if (attributes && (attributes->valuemask & XpmColormap))
colormap = attributes->colormap;
else
colormap = XDefaultColormap(display, XDefaultScreen(display));
- if (attributes && attributes->valuemask & XpmColorKey)
+ if (attributes && (attributes->valuemask & XpmColorKey))
key = attributes->color_key;
else
key = xpmVisualType(visual);
+ if (attributes && (attributes->valuemask & XpmAllocColor))
+ allocColor = attributes->alloc_color;
+ else
+ allocColor = AllocColor;
+ if (attributes && (attributes->valuemask & XpmColorClosure))
+ closure = attributes->color_closure;
+ else
+ closure = NULL;
+
#ifndef FOR_MSW
if (USE_CLOSECOLOR) {
/* originally from SetCloseColor */
#if 0
- if (visual->c_class == DirectColor) {
+ if (visual->class == DirectColor) {
/*
* TODO: Implement close colors for DirectColor visuals. This is
#endif
int i;
+#ifndef AMIGA
ncols = visual->map_entries;
+#else
+ ncols = colormap->Count;
+#endif
cols = (XColor *) XpmCalloc(ncols, sizeof(XColor));
for (i = 0; i < ncols; ++i)
cols[i].pixel = i;
break;
}
- for (a = 0; a < ncolors; a++, ct++, ip++, mp++) {
+ for (color = 0; color < ncolors; color++, colors++,
+ image_pixels++, mask_pixels++) {
colorname = NULL;
pixel_defined = False;
- defaults = (char **) ct;
+ defaults = (char **) colors;
/*
* look for a defined symbol
*/
if (numsymbols) {
+
+ unsigned int n;
+
s = defaults[1];
- for (l = 0, symbol = colorsymbols; l < numsymbols; l++, symbol++) {
+ for (n = 0, symbol = colorsymbols; n < numsymbols; n++, symbol++) {
if (symbol->name && s && !strcmp(symbol->name, s))
/* override name */
break;
++def_index;
}
if (def_index >= 2 && defaults[def_index] != NULL &&
- !strcasecmp(symbol->value, defaults[def_index]))
+ !xpmstrcasecmp(symbol->value, defaults[def_index]))
break;
}
}
- if (l != numsymbols) {
+ if (n != numsymbols) {
if (symbol->name && symbol->value)
colorname = symbol->value;
else
}
}
if (!pixel_defined) { /* pixel not given as symbol value */
+
+ unsigned int k;
+
if (colorname) { /* colorname given as symbol value */
- if (!SetColor(display, colormap, visual, colorname, a, ip, mp,
- mask_pixel, pixels, npixels, attributes,
- cols, ncols))
+ if (!SetColor(display, colormap, visual, colorname, color,
+ image_pixels, mask_pixels, mask_pixel_index,
+ alloc_pixels, nalloc_pixels, used_pixels,
+ nused_pixels, attributes, cols, ncols,
+ allocColor, closure))
pixel_defined = True;
else
ErrorStatus = XpmColorError;
}
- b = key;
- while (!pixel_defined && b > 1) {
- if (defaults[b]) {
- if (!SetColor(display, colormap, visual, defaults[b],
- a, ip, mp, mask_pixel, pixels, npixels,
- attributes, cols, ncols)) {
+ k = key;
+ while (!pixel_defined && k > 1) {
+ if (defaults[k]) {
+ if (!SetColor(display, colormap, visual, defaults[k],
+ color, image_pixels, mask_pixels,
+ mask_pixel_index, alloc_pixels,
+ nalloc_pixels, used_pixels, nused_pixels,
+ attributes, cols, ncols,
+ allocColor, closure)) {
pixel_defined = True;
break;
} else
ErrorStatus = XpmColorError;
}
- b--;
+ k--;
}
- b = key + 1;
- while (!pixel_defined && b < NKEYS + 1) {
- if (defaults[b]) {
- if (!SetColor(display, colormap, visual, defaults[b],
- a, ip, mp, mask_pixel, pixels, npixels,
- attributes, cols, ncols)) {
+ k = key + 1;
+ while (!pixel_defined && k < NKEYS + 1) {
+ if (defaults[k]) {
+ if (!SetColor(display, colormap, visual, defaults[k],
+ color, image_pixels, mask_pixels,
+ mask_pixel_index, alloc_pixels,
+ nalloc_pixels, used_pixels, nused_pixels,
+ attributes, cols, ncols,
+ allocColor, closure)) {
pixel_defined = True;
break;
} else
ErrorStatus = XpmColorError;
}
- b++;
+ k++;
}
if (!pixel_defined) {
if (cols)
return (XpmColorFailed);
}
} else {
- *ip = colorsymbols[l].pixel;
+ /* simply use the given pixel */
+ *image_pixels = symbol->pixel;
+ /* the following makes the mask to be built even if none
+ is given a particular pixel */
if (symbol->value
- && !strcasecmp(symbol->value, TRANSPARENT_COLOR)) {
- *mp = 0;
- *mask_pixel = 0;
+ && !xpmstrcasecmp(symbol->value, TRANSPARENT_COLOR)) {
+ *mask_pixels = 0;
+ *mask_pixel_index = color;
} else
- *mp = 1;
+ *mask_pixels = 1;
+ used_pixels[(*nused_pixels)++] = *image_pixels;
}
}
if (cols)
}
-/* function call in case of error, frees only locally allocated variables */
+/* default FreeColors function, simply call XFreeColors */
+static int
+FreeColors(display, colormap, pixels, n, closure)
+ Display *display;
+ Colormap colormap;
+ Pixel *pixels;
+ int n;
+ void *closure; /* not used */
+{
+ return XFreeColors(display, colormap, pixels, n, 0);
+}
+
+
+/* function call in case of error */
#undef RETURN
#define RETURN(status) \
{ \
- if (ximage) XDestroyImage(ximage); \
- if (shapeimage) XDestroyImage(shapeimage); \
- if (ximage_pixels) XpmFree(ximage_pixels); \
- if (mask_pixels) XpmFree(mask_pixels); \
- if (npixels) XFreeColors(display, colormap, pixels, npixels, 0); \
- if (pixels) XpmFree(pixels); \
- return (status); \
+ ErrorStatus = status; \
+ goto error; \
}
int
-XpmCreateImageFromXpmImage(Display *display, XpmImage *image,
- XImage **image_return, XImage **shapeimage_return, XpmAttributes *attributes)
+XpmCreateImageFromXpmImage(display, image,
+ image_return, shapeimage_return, attributes)
+ Display *display;
+ XpmImage *image;
+ XImage **image_return;
+ XImage **shapeimage_return;
+ XpmAttributes *attributes;
{
/* variables stored in the XpmAttributes structure */
Visual *visual;
Colormap colormap;
unsigned int depth;
+ int bitmap_format;
+ XpmFreeColorsFunc freeColors;
+ void *closure;
/* variables to return */
XImage *ximage = NULL;
XImage *shapeimage = NULL;
- unsigned int mask_pixel;
+ unsigned int mask_pixel_index = XpmUndefPixel;
int ErrorStatus;
/* calculation variables */
- Pixel *ximage_pixels = NULL;
+ Pixel *image_pixels = NULL;
Pixel *mask_pixels = NULL;
- Pixel *pixels = NULL; /* allocated pixels */
- unsigned int npixels = 0; /* number of allocated pixels */
+ Pixel *alloc_pixels = NULL;
+ Pixel *used_pixels = NULL;
+ unsigned int nalloc_pixels = 0;
+ unsigned int nused_pixels = 0;
/* initialize return values */
if (image_return)
else
depth = XDefaultDepth(display, XDefaultScreen(display));
+ if (attributes && (attributes->valuemask & XpmBitmapFormat))
+ bitmap_format = attributes->bitmap_format;
+ else
+ bitmap_format = ZPixmap;
+
+ if (attributes && (attributes->valuemask & XpmFreeColors))
+ freeColors = attributes->free_colors;
+ else
+ freeColors = FreeColors;
+ if (attributes && (attributes->valuemask & XpmColorClosure))
+ closure = attributes->color_closure;
+ else
+ closure = NULL;
+
ErrorStatus = XpmSuccess;
/* malloc pixels index tables */
- ximage_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);
- if (!ximage_pixels)
+ image_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);
+ if (!image_pixels)
return (XpmNoMemory);
mask_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);
if (!mask_pixels)
RETURN(XpmNoMemory);
- mask_pixel = XpmUndefPixel;
+ /* maximum of allocated pixels will be the number of colors */
+ alloc_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);
+ if (!alloc_pixels)
+ RETURN(XpmNoMemory);
/* maximum of allocated pixels will be the number of colors */
- pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);
- if (!pixels)
+ used_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);
+ if (!used_pixels)
RETURN(XpmNoMemory);
/* get pixel colors, store them in index tables */
ErrorStatus = CreateColors(display, attributes, image->colorTable,
- image->ncolors, ximage_pixels, mask_pixels,
- &mask_pixel, &pixels, &npixels);
+ image->ncolors, image_pixels, mask_pixels,
+ &mask_pixel_index, alloc_pixels, &nalloc_pixels,
+ used_pixels, &nused_pixels);
if (ErrorStatus != XpmSuccess
&& (ErrorStatus < 0 || (attributes
/* create the ximage */
if (image_return) {
ErrorStatus = CreateXImage(display, visual, depth,
+ (depth == 1 ? bitmap_format : ZPixmap),
image->width, image->height, &ximage);
if (ErrorStatus != XpmSuccess)
RETURN(ErrorStatus);
#ifndef FOR_MSW
+# ifndef AMIGA
/*
- * set the ximage data
- *
- * In case depth is 1 or bits_per_pixel is 4, 6, 8, 24 or 32 use
- * optimized functions, otherwise use slower but sure general one.
- *
+ * set the ximage data using optimized functions for ZPixmap
*/
- if (ximage->depth == 1)
- SetImagePixels1(ximage, image->width, image->height,
- image->data, ximage_pixels);
- else if (ximage->bits_per_pixel == 8)
- SetImagePixels8(ximage, image->width, image->height,
- image->data, ximage_pixels);
+ if (ximage->bits_per_pixel == 8)
+ PutImagePixels8(ximage, image->width, image->height,
+ image->data, image_pixels);
+ else if (((ximage->bits_per_pixel | ximage->depth) == 1) &&
+ (ximage->byte_order == ximage->bitmap_bit_order))
+ PutImagePixels1(ximage, image->width, image->height,
+ image->data, image_pixels);
else if (ximage->bits_per_pixel == 16)
- SetImagePixels16(ximage, image->width, image->height,
- image->data, ximage_pixels);
+ PutImagePixels16(ximage, image->width, image->height,
+ image->data, image_pixels);
else if (ximage->bits_per_pixel == 32)
- SetImagePixels32(ximage, image->width, image->height,
- image->data, ximage_pixels);
+ PutImagePixels32(ximage, image->width, image->height,
+ image->data, image_pixels);
else
- SetImagePixels(ximage, image->width, image->height,
- image->data, ximage_pixels);
+ PutImagePixels(ximage, image->width, image->height,
+ image->data, image_pixels);
+# else /* AMIGA */
+ APutImagePixels(ximage, image->width, image->height,
+ image->data, image_pixels);
+# endif
#else /* FOR_MSW */
- MSWSetImagePixels(display, ximage, image->width, image->height,
- image->data, ximage_pixels);
+ MSWPutImagePixels(display, ximage, image->width, image->height,
+ image->data, image_pixels);
#endif
}
/* create the shape mask image */
- if (mask_pixel != XpmUndefPixel && shapeimage_return) {
- ErrorStatus = CreateXImage(display, visual, 1, image->width,
- image->height, &shapeimage);
+ if (mask_pixel_index != XpmUndefPixel && shapeimage_return) {
+ ErrorStatus = CreateXImage(display, visual, 1, bitmap_format,
+ image->width, image->height, &shapeimage);
if (ErrorStatus != XpmSuccess)
RETURN(ErrorStatus);
#ifndef FOR_MSW
- SetImagePixels1(shapeimage, image->width, image->height,
+# ifndef AMIGA
+ PutImagePixels1(shapeimage, image->width, image->height,
image->data, mask_pixels);
-#else
- MSWSetImagePixels(display, shapeimage, image->width, image->height,
+# else /* AMIGA */
+ APutImagePixels(shapeimage, image->width, image->height,
+ image->data, mask_pixels);
+# endif
+#else /* FOR_MSW */
+ MSWPutImagePixels(display, shapeimage, image->width, image->height,
image->data, mask_pixels);
#endif
}
+ XpmFree(image_pixels);
XpmFree(mask_pixels);
- XpmFree(pixels);
- /* if requested store alloc'ed pixels in the XpmAttributes structure */
- if (attributes) {
- if (attributes->valuemask & XpmReturnPixels ||
-/* 3.2 backward compatibility code */
- attributes->valuemask & XpmReturnInfos) {
-/* end 3.2 bc */
- if (mask_pixel != XpmUndefPixel) {
- Pixel *pixels, *p1, *p2;
- unsigned int a;
-
- attributes->npixels = image->ncolors - 1;
- pixels = (Pixel *) XpmMalloc(sizeof(Pixel)
- * attributes->npixels);
- if (pixels) {
- p1 = ximage_pixels;
- p2 = pixels;
- for (a = 0; a < image->ncolors; a++, p1++)
- if (a != mask_pixel)
- *p2++ = *p1;
- attributes->pixels = pixels;
- } else {
- /* if error just say we can't return requested data */
- attributes->valuemask &= ~XpmReturnPixels;
+ /* if requested return used pixels in the XpmAttributes structure */
+ if (attributes && (attributes->valuemask & XpmReturnPixels ||
/* 3.2 backward compatibility code */
- attributes->valuemask &= ~XpmReturnInfos;
+ attributes->valuemask & XpmReturnInfos)) {
/* end 3.2 bc */
- attributes->pixels = NULL;
- attributes->npixels = 0;
- }
- XpmFree(ximage_pixels);
- } else {
- attributes->pixels = ximage_pixels;
- attributes->npixels = image->ncolors;
- }
- attributes->mask_pixel = mask_pixel;
- } else
- XpmFree(ximage_pixels);
+ attributes->pixels = used_pixels;
+ attributes->npixels = nused_pixels;
+ attributes->mask_pixel = mask_pixel_index;
+ } else
+ XpmFree(used_pixels);
+
+ /* if requested return alloc'ed pixels in the XpmAttributes structure */
+ if (attributes && (attributes->valuemask & XpmReturnAllocPixels)) {
+ attributes->alloc_pixels = alloc_pixels;
+ attributes->nalloc_pixels = nalloc_pixels;
} else
- XpmFree(ximage_pixels);
+ XpmFree(alloc_pixels);
/* return created images */
if (image_return)
*shapeimage_return = shapeimage;
return (ErrorStatus);
+
+/* exit point in case of error, free only locally allocated variables */
+error:
+ if (ximage)
+ XDestroyImage(ximage);
+ if (shapeimage)
+ XDestroyImage(shapeimage);
+ if (image_pixels)
+ XpmFree(image_pixels);
+ if (mask_pixels)
+ XpmFree(mask_pixels);
+ if (nalloc_pixels)
+ (*freeColors)(display, colormap, alloc_pixels, nalloc_pixels, NULL);
+ if (alloc_pixels)
+ XpmFree(alloc_pixels);
+ if (used_pixels)
+ XpmFree(used_pixels);
+
+ return (ErrorStatus);
}
/*
- * Create an XImage
+ * Create an XImage with its data
*/
static int
-CreateXImage(Display *display, Visual *visual, unsigned int depth,
- unsigned int width, unsigned int height, XImage **image_return)
+CreateXImage(display, visual, depth, format, width, height, image_return)
+ Display *display;
+ Visual *visual;
+ unsigned int depth;
+ int format;
+ unsigned int width;
+ unsigned int height;
+ XImage **image_return;
{
int bitmap_pad;
bitmap_pad = 8;
/* then create the XImage with data = NULL and bytes_per_line = 0 */
- *image_return = XCreateImage(display, visual, depth, ZPixmap, 0, 0,
+ *image_return = XCreateImage(display, visual, depth, format, 0, 0,
width, height, bitmap_pad, 0);
if (!*image_return)
return (XpmNoMemory);
-#ifndef FOR_MSW
+#if !defined(FOR_MSW) && !defined(AMIGA)
/* now that bytes_per_line must have been set properly alloc data */
(*image_return)->data =
(char *) XpmMalloc((*image_return)->bytes_per_line * height);
return (XpmNoMemory);
}
#else
- /* under FOR_MSW XCreateImage has done it all */
+ /* under FOR_MSW and AMIGA XCreateImage has done it all */
#endif
return (XpmSuccess);
}
#ifndef FOR_MSW
+# ifndef AMIGA
/*
* The functions below are written from X11R5 MIT's code (XImUtil.c)
*
};
static int
-_XReverse_Bytes(register unsigned char *bpt, register int nb)
+_XReverse_Bytes(bpt, nb)
+ register unsigned char *bpt;
+ register int nb;
{
do {
*bpt = _reverse_byte[*bpt];
void
-xpm_xynormalizeimagebits(register unsigned char *bp, register XImage *img)
+xpm_xynormalizeimagebits(bp, img)
+ register unsigned char *bp;
+ register XImage *img;
{
register unsigned char c;
}
void
-xpm_znormalizeimagebits(register unsigned char *bp, register XImage *img)
+xpm_znormalizeimagebits(bp, img)
+ register unsigned char *bp;
+ register XImage *img;
{
register unsigned char c;
0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
static void
-_putbits(register char *src, int dstoffset, register int numbits, register char *dst)
-
-/* register char *src; */ /* address of source bit string */
-/* int dstoffset; */ /* bit offset into destination;
+_putbits(src, dstoffset, numbits, dst)
+ register char *src; /* address of source bit string */
+ int dstoffset; /* bit offset into destination;
* range is 0-31 */
-/* register int numbits; */ /* number of bits to copy to
+ register int numbits; /* number of bits to copy to
* destination */
-/* register char *dst; */ /* address of destination bit string */
+ register char *dst; /* address of destination bit string */
{
register unsigned char chlo, chhi;
int hibits;
*/
static void
-SetImagePixels(XImage *image, unsigned int width, unsigned int height, unsigned int *pixelindex, Pixel *pixels)
+PutImagePixels(image, width, height, pixelindex, pixels)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ unsigned int *pixelindex;
+ Pixel *pixels;
{
register char *src;
register char *dst;
* write pixels into a 32-bits Z image data structure
*/
-#ifndef WORD64
+#if !defined(WORD64) && !defined(LONG64)
/* this item is static but deterministic so let it slide; doesn't
* hurt re-entrancy of this library. Note if it is actually const then would
* be OK under rules of ANSI-C but probably not C++ which may not
* want to allocate space for it.
*/
-static unsigned long /* constant */ RTXpm_byteorderpixel = MSBFirst << 24;
+static unsigned long byteorderpixel = MSBFirst << 24;
#endif
*/
static void
-SetImagePixels32(XImage *image, unsigned int width, unsigned int height, unsigned int *pixelindex, Pixel *pixels)
+PutImagePixels32(image, width, height, pixelindex, pixels)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ unsigned int *pixelindex;
+ Pixel *pixels;
{
unsigned char *data;
unsigned int *iptr;
data = (unsigned char *) image->data;
iptr = pixelindex;
-#ifndef WORD64
- if (*((char *) &RTXpm_byteorderpixel) == image->byte_order) {
+#if !defined(WORD64) && !defined(LONG64)
+ if (*((char *) &byteorderpixel) == image->byte_order) {
for (y = 0; y < height; y++)
for (x = 0; x < width; x++, iptr++) {
addr = &data[ZINDEX32(x, y, image)];
data = (unsigned char *) image->data;
iptr = pixelindex;
-#ifndef WORD64
- if (*((char *) &RTXpm_byteorderpixel) == image->byte_order) {
+#if !defined(WORD64) && !defined(LONG64)
+ if (*((char *) &byteorderpixel) == image->byte_order) {
for (y = 0; y < height; y++) {
data_ptr = data;
max_data = data_ptr + (width << 2);
*/
static void
-SetImagePixels16(XImage *image, unsigned int width, unsigned int height, unsigned int *pixelindex, Pixel *pixels)
+PutImagePixels16(image, width, height, pixelindex, pixels)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ unsigned int *pixelindex;
+ Pixel *pixels;
{
unsigned char *data;
unsigned int *iptr;
*/
static void
-SetImagePixels8(XImage *image, unsigned int width, unsigned int height, unsigned int *pixelindex, Pixel *pixels)
+PutImagePixels8(image, width, height, pixelindex, pixels)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ unsigned int *pixelindex;
+ Pixel *pixels;
{
char *data;
unsigned int *iptr;
*/
static void
-SetImagePixels1(XImage *image, unsigned int width, unsigned int height, unsigned int *pixelindex, Pixel *pixels)
+PutImagePixels1(image, width, height, pixelindex, pixels)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ unsigned int *pixelindex;
+ Pixel *pixels;
{
if (image->byte_order != image->bitmap_bit_order)
- SetImagePixels(image, width, height, pixelindex, pixels);
+ PutImagePixels(image, width, height, pixelindex, pixels);
else {
unsigned int *iptr;
int y;
}
int
-XpmCreatePixmapFromXpmImage(Display *display, Drawable d, XpmImage *image,
- Pixmap *pixmap_return, Pixmap *shapemask_return, XpmAttributes *attributes)
+XpmCreatePixmapFromXpmImage(display, d, image,
+ pixmap_return, shapemask_return, attributes)
+ Display *display;
+ Drawable d;
+ XpmImage *image;
+ Pixmap *pixmap_return;
+ Pixmap *shapemask_return;
+ XpmAttributes *attributes;
{
XImage *ximage, *shapeimage;
int ErrorStatus;
return (ErrorStatus);
}
+# else /* AMIGA */
+
+static void
+APutImagePixels (
+ XImage *image,
+ unsigned int width,
+ unsigned int height,
+ unsigned int *pixelindex,
+ Pixel *pixels)
+{
+ unsigned int *data = pixelindex;
+ unsigned int x, y;
+ unsigned char *array;
+ XImage *tmp_img;
+ BOOL success = FALSE;
+
+ array = XpmMalloc ((((width+15)>>4)<<4)*sizeof (*array));
+ if (array != NULL)
+ {
+ tmp_img = AllocXImage ((((width+15)>>4)<<4), 1,
+ image->rp->BitMap->Depth);
+ if (tmp_img != NULL)
+ {
+ for (y = 0; y < height; ++y)
+ {
+ for (x = 0; x < width; ++x)
+ array[x] = pixels[*(data++)];
+ WritePixelLine8 (image->rp, 0, y, width, array, tmp_img->rp);
+ }
+ FreeXImage (tmp_img);
+ success = TRUE;
+ }
+ XpmFree (array);
+ }
+
+ if (!success)
+ {
+ for (y = 0; y < height; ++y)
+ for (x = 0; x < width; ++x)
+ XPutPixel (image, x, y, pixels[*(data++)]);
+ }
+}
+
+# endif/* AMIGA */
#else /* FOR_MSW part follows */
-#if !defined(__VISAGECPP__)
static void
-MSWSetImagePixels(Display *dc, XImage *image, unsigned int width, unsigned int height,
- unsigned int *pixelindex, Pixel *pixels)
+MSWPutImagePixels(dc, image, width, height, pixelindex, pixels)
+ Display *dc;
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ unsigned int *pixelindex;
+ Pixel *pixels;
{
unsigned int *data = pixelindex;
unsigned int x, y;
+ HBITMAP obm;
- SelectObject(*dc, image->bitmap);
+ obm = SelectObject(*dc, image->bitmap);
for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- SetPixel(*dc, x, y, pixels[*(data++)]); /* data is [x+y*width] */
- }
+ for (x = 0; x < width; x++) {
+ SetPixel(*dc, x, y, pixels[*(data++)]); /* data is [x+y*width] */
+ }
}
+ SelectObject(*dc, obm);
}
-#else
-void MSWSetImagePixels(Display *dc, XImage *image, unsigned int width, unsigned int height,
- unsigned int *pixelindex, Pixel *pixels)
+
+#endif /* FOR_MSW */
+
+
+
+#if !defined(FOR_MSW) && !defined(AMIGA)
+
+static int
+PutPixel1(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
{
- unsigned int *data = pixelindex;
- unsigned int x, y;
-// TODO:
+ register char *src;
+ register char *dst;
+ register int i;
+ register char *data;
+ Pixel px;
+ int nbytes;
+
+ for (i=0, px=pixel; i<sizeof(unsigned long); i++, px>>=8)
+ ((unsigned char *)&pixel)[i] = px;
+ src = &ximage->data[XYINDEX(x, y, ximage)];
+ dst = (char *)&px;
+ px = 0;
+ nbytes = ximage->bitmap_unit >> 3;
+ for (i = nbytes; --i >= 0; ) *dst++ = *src++;
+ XYNORMALIZE(&px, ximage);
+ i = ((x + ximage->xoffset) % ximage->bitmap_unit);
+ _putbits ((char *)&pixel, i, 1, (char *)&px);
+ XYNORMALIZE(&px, ximage);
+ src = (char *) &px;
+ dst = &ximage->data[XYINDEX(x, y, ximage)];
+ for (i = nbytes; --i >= 0; )
+ *dst++ = *src++;
+
+ return 1;
+}
+
+static int
+PutPixel(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ register char *src;
+ register char *dst;
+ register int i;
+ register char *data;
+ Pixel px;
+ int nbytes, ibpp;
+
+ ibpp = ximage->bits_per_pixel;
+ if (ximage->depth == 4)
+ pixel &= 0xf;
+ for (i = 0, px = pixel; i < sizeof(unsigned long); i++, px >>= 8)
+ ((unsigned char *) &pixel)[i] = px;
+ src = &ximage->data[ZINDEX(x, y, ximage)];
+ dst = (char *) &px;
+ px = 0;
+ nbytes = (ibpp + 7) >> 3;
+ for (i = nbytes; --i >= 0;)
+ *dst++ = *src++;
+ ZNORMALIZE(&px, ximage);
+ _putbits((char *) &pixel, (x * ibpp) & 7, ibpp, (char *) &px);
+ ZNORMALIZE(&px, ximage);
+ src = (char *) &px;
+ dst = &ximage->data[ZINDEX(x, y, ximage)];
+ for (i = nbytes; --i >= 0;)
+ *dst++ = *src++;
+
+ return 1;
+}
+
+static int
+PutPixel32(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
+ *((unsigned long *)addr) = pixel;
+ return 1;
+}
+
+static int
+PutPixel32MSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
+ addr[0] = pixel >> 24;
+ addr[1] = pixel >> 16;
+ addr[2] = pixel >> 8;
+ addr[3] = pixel;
+ return 1;
+}
+
+static int
+PutPixel32LSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
+ addr[3] = pixel >> 24;
+ addr[2] = pixel >> 16;
+ addr[1] = pixel >> 8;
+ addr[0] = pixel;
+ return 1;
+}
+
+static int
+PutPixel16MSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX16(x, y, ximage)];
+ addr[0] = pixel >> 8;
+ addr[1] = pixel;
+ return 1;
+}
+
+static int
+PutPixel16LSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX16(x, y, ximage)];
+ addr[1] = pixel >> 8;
+ addr[0] = pixel;
+ return 1;
+}
+
+static int
+PutPixel8(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ ximage->data[ZINDEX8(x, y, ximage)] = pixel;
+ return 1;
+}
+
+static int
+PutPixel1MSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ if (pixel & 1)
+ ximage->data[ZINDEX1(x, y, ximage)] |= 0x80 >> (x & 7);
+ else
+ ximage->data[ZINDEX1(x, y, ximage)] &= ~(0x80 >> (x & 7));
+ return 1;
+}
+
+static int
+PutPixel1LSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ if (pixel & 1)
+ ximage->data[ZINDEX1(x, y, ximage)] |= 1 << (x & 7);
+ else
+ ximage->data[ZINDEX1(x, y, ximage)] &= ~(1 << (x & 7));
+ return 1;
+}
+
+#endif /* not FOR_MSW && not AMIGA */
+
/*
- SelectObject(*dc, image->bitmap);
- if (image->depth == 1)
+ * This function parses an Xpm file or data and directly create an XImage
+ */
+int
+xpmParseDataAndCreate(display, data, image_return, shapeimage_return,
+ image, info, attributes)
+ Display *display;
+ xpmData *data;
+ XImage **image_return;
+ XImage **shapeimage_return;
+ XpmImage *image;
+ XpmInfo *info;
+ XpmAttributes *attributes;
+{
+ /* variables stored in the XpmAttributes structure */
+ Visual *visual;
+ Colormap colormap;
+ unsigned int depth;
+ int bitmap_format;
+ XpmFreeColorsFunc freeColors;
+ void *closure;
+
+ /* variables to return */
+ XImage *ximage = NULL;
+ XImage *shapeimage = NULL;
+ unsigned int mask_pixel_index = XpmUndefPixel;
+
+ /* calculation variables */
+ Pixel *image_pixels = NULL;
+ Pixel *mask_pixels = NULL;
+ Pixel *alloc_pixels = NULL;
+ Pixel *used_pixels = NULL;
+ unsigned int nalloc_pixels = 0;
+ unsigned int nused_pixels = 0;
+ unsigned int width, height, ncolors, cpp;
+ unsigned int x_hotspot, y_hotspot, hotspot = 0, extensions = 0;
+ XpmColor *colorTable = NULL;
+ char *hints_cmt = NULL;
+ char *colors_cmt = NULL;
+ char *pixels_cmt = NULL;
+
+ unsigned int cmts;
+ int ErrorStatus;
+ xpmHashTable hashtable;
+
+
+ /* initialize return values */
+ if (image_return)
+ *image_return = NULL;
+ if (shapeimage_return)
+ *shapeimage_return = NULL;
+
+
+ /* retrieve information from the XpmAttributes */
+ if (attributes && (attributes->valuemask & XpmVisual))
+ visual = attributes->visual;
+ else
+ visual = XDefaultVisual(display, XDefaultScreen(display));
+
+ if (attributes && (attributes->valuemask & XpmColormap))
+ colormap = attributes->colormap;
+ else
+ colormap = XDefaultColormap(display, XDefaultScreen(display));
+
+ if (attributes && (attributes->valuemask & XpmDepth))
+ depth = attributes->depth;
+ else
+ depth = XDefaultDepth(display, XDefaultScreen(display));
+
+ if (attributes && (attributes->valuemask & XpmBitmapFormat))
+ bitmap_format = attributes->bitmap_format;
+ else
+ bitmap_format = ZPixmap;
+
+ if (attributes && (attributes->valuemask & XpmFreeColors))
+ freeColors = attributes->free_colors;
+ else
+ freeColors = FreeColors;
+ if (attributes && (attributes->valuemask & XpmColorClosure))
+ closure = attributes->color_closure;
+ else
+ closure = NULL;
+
+ cmts = info && (info->valuemask & XpmReturnComments);
+
+ /*
+ * parse the header
+ */
+ ErrorStatus = xpmParseHeader(data);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+
+ /*
+ * read values
+ */
+ ErrorStatus = xpmParseValues(data, &width, &height, &ncolors, &cpp,
+ &x_hotspot, &y_hotspot, &hotspot,
+ &extensions);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+
+ /*
+ * store the hints comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &hints_cmt);
+
+ /*
+ * init the hastable
+ */
+ if (USE_HASHTABLE) {
+ ErrorStatus = xpmHashTableInit(&hashtable);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+ }
+
+ /*
+ * read colors
+ */
+ ErrorStatus = xpmParseColors(data, ncolors, cpp, &colorTable, &hashtable);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+
+ /*
+ * store the colors comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &colors_cmt);
+
+ /* malloc pixels index tables */
+ image_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
+ if (!image_pixels)
+ RETURN(XpmNoMemory);
+
+ mask_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
+ if (!mask_pixels)
+ RETURN(XpmNoMemory);
+
+ /* maximum of allocated pixels will be the number of colors */
+ alloc_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
+ if (!alloc_pixels)
+ RETURN(XpmNoMemory);
+
+ /* maximum of allocated pixels will be the number of colors */
+ used_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
+ if (!used_pixels)
+ RETURN(XpmNoMemory);
+
+ /* get pixel colors, store them in index tables */
+ ErrorStatus = CreateColors(display, attributes, colorTable, ncolors,
+ image_pixels, mask_pixels, &mask_pixel_index,
+ alloc_pixels, &nalloc_pixels, used_pixels,
+ &nused_pixels);
+
+ if (ErrorStatus != XpmSuccess
+ && (ErrorStatus < 0 || (attributes
+ && (attributes->valuemask & XpmExactColors)
+ && attributes->exactColors)))
+ RETURN(ErrorStatus);
+
+ /* now create the ximage */
+ if (image_return) {
+ ErrorStatus = CreateXImage(display, visual, depth,
+ (depth == 1 ? bitmap_format : ZPixmap),
+ width, height, &ximage);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+
+#if !defined(FOR_MSW) && !defined(AMIGA)
+
+ /*
+ * set the XImage pointer function, to be used with XPutPixel,
+ * to an internal optimized function
+ */
+
+ if (ximage->bits_per_pixel == 8)
+ ximage->f.put_pixel = PutPixel8;
+ else if (((ximage->bits_per_pixel | ximage->depth) == 1) &&
+ (ximage->byte_order == ximage->bitmap_bit_order))
+ if (ximage->bitmap_bit_order == MSBFirst)
+ ximage->f.put_pixel = PutPixel1MSB;
+ else
+ ximage->f.put_pixel = PutPixel1LSB;
+ else if (ximage->bits_per_pixel == 16)
+ if (ximage->bitmap_bit_order == MSBFirst)
+ ximage->f.put_pixel = PutPixel16MSB;
+ else
+ ximage->f.put_pixel = PutPixel16LSB;
+ else if (ximage->bits_per_pixel == 32)
+#if !defined(WORD64) && !defined(LONG64)
+ if (*((char *)&byteorderpixel) == ximage->byte_order)
+ ximage->f.put_pixel = PutPixel32;
+ else
+#endif
+ if (ximage->bitmap_bit_order == MSBFirst)
+ ximage->f.put_pixel = PutPixel32MSB;
+ else
+ ximage->f.put_pixel = PutPixel32LSB;
+ else if ((ximage->bits_per_pixel | ximage->depth) == 1)
+ ximage->f.put_pixel = PutPixel1;
+ else
+ ximage->f.put_pixel = PutPixel;
+#endif /* not FOR_MSW && not AMIGA */
+ }
+
+ /* create the shape mask image */
+ if (mask_pixel_index != XpmUndefPixel && shapeimage_return) {
+ ErrorStatus = CreateXImage(display, visual, 1, bitmap_format,
+ width, height, &shapeimage);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+
+#if !defined(FOR_MSW) && !defined(AMIGA)
+ if (shapeimage->bitmap_bit_order == MSBFirst)
+ shapeimage->f.put_pixel = PutPixel1MSB;
+ else
+ shapeimage->f.put_pixel = PutPixel1LSB;
+#endif
+ }
+
+ /*
+ * read pixels and put them in the XImage
+ */
+ ErrorStatus = ParseAndPutPixels(
+#ifdef FOR_MSW
+ display,
+#endif
+ data, width, height, ncolors, cpp,
+ colorTable, &hashtable,
+ ximage, image_pixels,
+ shapeimage, mask_pixels);
+ XpmFree(image_pixels);
+ image_pixels = NULL;
+ XpmFree(mask_pixels);
+ mask_pixels = NULL;
+
+ /*
+ * free the hastable
+ */
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus)
+ else if (USE_HASHTABLE)
+ xpmHashTableFree(&hashtable);
+
+ /*
+ * store the pixels comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &pixels_cmt);
+
+ /*
+ * parse extensions
+ */
+ if (info && (info->valuemask & XpmReturnExtensions))
+ if (extensions) {
+ ErrorStatus = xpmParseExtensions(data, &info->extensions,
+ &info->nextensions);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+ } else {
+ info->extensions = NULL;
+ info->nextensions = 0;
+ }
+
+ /*
+ * store found informations in the XpmImage structure
+ */
+ image->width = width;
+ image->height = height;
+ image->cpp = cpp;
+ image->ncolors = ncolors;
+ image->colorTable = colorTable;
+ image->data = NULL;
+
+ if (info) {
+ if (cmts) {
+ info->hints_cmt = hints_cmt;
+ info->colors_cmt = colors_cmt;
+ info->pixels_cmt = pixels_cmt;
+ }
+ if (hotspot) {
+ info->x_hotspot = x_hotspot;
+ info->y_hotspot = y_hotspot;
+ info->valuemask |= XpmHotspot;
+ }
+ }
+ /* if requested return used pixels in the XpmAttributes structure */
+ if (attributes && (attributes->valuemask & XpmReturnPixels ||
+/* 3.2 backward compatibility code */
+ attributes->valuemask & XpmReturnInfos)) {
+/* end 3.2 bc */
+ attributes->pixels = used_pixels;
+ attributes->npixels = nused_pixels;
+ attributes->mask_pixel = mask_pixel_index;
+ } else
+ XpmFree(used_pixels);
+
+ /* if requested return alloc'ed pixels in the XpmAttributes structure */
+ if (attributes && (attributes->valuemask & XpmReturnAllocPixels)) {
+ attributes->alloc_pixels = alloc_pixels;
+ attributes->nalloc_pixels = nalloc_pixels;
+ } else
+ XpmFree(alloc_pixels);
+
+ /* return created images */
+ if (image_return)
+ *image_return = ximage;
+ if (shapeimage_return)
+ *shapeimage_return = shapeimage;
+
+ return (XpmSuccess);
+
+/* exit point in case of error, free only locally allocated variables */
+error:
+ if (USE_HASHTABLE)
+ xpmHashTableFree(&hashtable);
+ if (colorTable)
+ xpmFreeColorTable(colorTable, ncolors);
+ if (hints_cmt)
+ XpmFree(hints_cmt);
+ if (colors_cmt)
+ XpmFree(colors_cmt);
+ if (pixels_cmt)
+ XpmFree(pixels_cmt);
+ if (ximage)
+ XDestroyImage(ximage);
+ if (shapeimage)
+ XDestroyImage(shapeimage);
+ if (image_pixels)
+ XpmFree(image_pixels);
+ if (mask_pixels)
+ XpmFree(mask_pixels);
+ if (nalloc_pixels)
+ (*freeColors)(display, colormap, alloc_pixels, nalloc_pixels, NULL);
+ if (alloc_pixels)
+ XpmFree(alloc_pixels);
+ if (used_pixels)
+ XpmFree(used_pixels);
+
+ return (ErrorStatus);
+}
+
+static int
+ParseAndPutPixels(
+#ifdef FOR_MSW
+ dc,
+#endif
+ data, width, height, ncolors, cpp, colorTable, hashtable,
+ image, image_pixels, shapeimage, shape_pixels)
+#ifdef FOR_MSW
+ Display *dc;
+#endif
+ xpmData *data;
+ unsigned int width;
+ unsigned int height;
+ unsigned int ncolors;
+ unsigned int cpp;
+ XpmColor *colorTable;
+ xpmHashTable *hashtable;
+ XImage *image;
+ Pixel *image_pixels;
+ XImage *shapeimage;
+ Pixel *shape_pixels;
+{
+ unsigned int a, x, y;
+
+ switch (cpp) {
+
+ case (1): /* Optimize for single character
+ * colors */
{
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- SetPixel(*dc, x, y, (pixels[*(data++)] ? RGB(255,255,255) : 0));
+ unsigned short colidx[256];
+#ifdef FOR_MSW
+ HDC shapedc;
+ HBITMAP obm, sobm;
+
+ if ( shapeimage ) {
+ shapedc = CreateCompatibleDC(*dc);
+ sobm = SelectObject(shapedc, shapeimage->bitmap);
+ } else {
+ shapedc = NULL;
+ }
+ obm = SelectObject(*dc, image->bitmap);
+#endif
+
+
+ bzero((char *)colidx, 256 * sizeof(short));
+ for (a = 0; a < ncolors; a++)
+ colidx[(unsigned char)colorTable[a].string[0]] = a + 1;
+
+ for (y = 0; y < height; y++) {
+ xpmNextString(data);
+ for (x = 0; x < width; x++) {
+ int c = xpmGetC(data);
+
+ if (c > 0 && c < 256 && colidx[c] != 0) {
+#ifndef FOR_MSW
+ XPutPixel(image, x, y, image_pixels[colidx[c] - 1]);
+ if (shapeimage)
+ XPutPixel(shapeimage, x, y,
+ shape_pixels[colidx[c] - 1]);
+#else
+ SetPixel(*dc, x, y, image_pixels[colidx[c] - 1]);
+ if (shapedc) {
+ SetPixel(shapedc, x, y, shape_pixels[colidx[c] - 1]);
}
+#endif
+ } else
+ return (XpmFileInvalid);
}
+ }
+#ifdef FOR_MSW
+ if ( shapedc ) {
+ SelectObject(shapedc, sobm);
+ DeleteDC(shapedc);
+ }
+ SelectObject(*dc, obm);
+#endif
}
- else
+ break;
+
+ case (2): /* Optimize for double character
+ * colors */
{
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- SetPixel(*dc, x, y, pixels[*(data++)]);
+
+/* free all allocated pointers at all exits */
+#define FREE_CIDX {int f; for (f = 0; f < 256; f++) \
+if (cidx[f]) XpmFree(cidx[f]);}
+
+ /* array of pointers malloced by need */
+ unsigned short *cidx[256];
+ int char1;
+
+ bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */
+ for (a = 0; a < ncolors; a++) {
+ char1 = colorTable[a].string[0];
+ if (cidx[char1] == NULL) { /* get new memory */
+ cidx[char1] = (unsigned short *)
+ XpmCalloc(256, sizeof(unsigned short));
+ if (cidx[char1] == NULL) { /* new block failed */
+ FREE_CIDX;
+ return (XpmNoMemory);
+ }
+ }
+ cidx[char1][(unsigned char)colorTable[a].string[1]] = a + 1;
+ }
+
+ for (y = 0; y < height; y++) {
+ xpmNextString(data);
+ for (x = 0; x < width; x++) {
+ int cc1 = xpmGetC(data);
+ if (cc1 > 0 && cc1 < 256) {
+ int cc2 = xpmGetC(data);
+ if (cc2 > 0 && cc2 < 256 &&
+ cidx[cc1] && cidx[cc1][cc2] != 0) {
+#ifndef FOR_MSW
+ XPutPixel(image, x, y,
+ image_pixels[cidx[cc1][cc2] - 1]);
+ if (shapeimage)
+ XPutPixel(shapeimage, x, y,
+ shape_pixels[cidx[cc1][cc2] - 1]);
+#else
+ SelectObject(*dc, image->bitmap);
+ SetPixel(*dc, x, y, image_pixels[cidx[cc1][cc2] - 1]);
+ if (shapeimage) {
+ SelectObject(*dc, shapeimage->bitmap);
+ SetPixel(*dc, x, y,
+ shape_pixels[cidx[cc1][cc2] - 1]);
+ }
+#endif
+ } else {
+ FREE_CIDX;
+ return (XpmFileInvalid);
}
+ } else {
+ FREE_CIDX;
+ return (XpmFileInvalid);
+ }
}
+ }
+ FREE_CIDX;
}
-*/
- return;
-}
-#endif // __VISAGECPP__
+ break;
+ default: /* Non-optimized case of long color
+ * names */
+ {
+ char *s;
+ char buf[BUFSIZ];
-#endif /* FOR_MSW */
+ buf[cpp] = '\0';
+ if (USE_HASHTABLE) {
+ xpmHashAtom *slot;
+
+ for (y = 0; y < height; y++) {
+ xpmNextString(data);
+ for (x = 0; x < width; x++) {
+ for (a = 0, s = buf; a < cpp; a++, s++)
+ *s = xpmGetC(data);
+ slot = xpmHashSlot(hashtable, buf);
+ if (!*slot) /* no color matches */
+ return (XpmFileInvalid);
+#ifndef FOR_MSW
+ XPutPixel(image, x, y,
+ image_pixels[HashColorIndex(slot)]);
+ if (shapeimage)
+ XPutPixel(shapeimage, x, y,
+ shape_pixels[HashColorIndex(slot)]);
+#else
+ SelectObject(*dc, image->bitmap);
+ SetPixel(*dc, x, y,
+ image_pixels[HashColorIndex(slot)]);
+ if (shapeimage) {
+ SelectObject(*dc, shapeimage->bitmap);
+ SetPixel(*dc, x, y,
+ shape_pixels[HashColorIndex(slot)]);
+ }
+#endif
+ }
+ }
+ } else {
+ for (y = 0; y < height; y++) {
+ xpmNextString(data);
+ for (x = 0; x < width; x++) {
+ for (a = 0, s = buf; a < cpp; a++, s++)
+ *s = xpmGetC(data);
+ for (a = 0; a < ncolors; a++)
+ if (!strcmp(colorTable[a].string, buf))
+ break;
+ if (a == ncolors) /* no color matches */
+ return (XpmFileInvalid);
+#ifndef FOR_MSW
+ XPutPixel(image, x, y, image_pixels[a]);
+ if (shapeimage)
+ XPutPixel(shapeimage, x, y, shape_pixels[a]);
+#else
+ SelectObject(*dc, image->bitmap);
+ SetPixel(*dc, x, y, image_pixels[a]);
+ if (shapeimage) {
+ SelectObject(*dc, shapeimage->bitmap);
+ SetPixel(*dc, x, y, shape_pixels[a]);
+ }
+#endif
+ }
+ }
+ }
+ }
+ break;
+ }
+ return (XpmSuccess);
+}
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* XpmCrIFrBuf.c: *
+* CrIFrBuf.c: *
* *
* XPM library *
* Parse an Xpm buffer (file in memory) and create the image and possibly its *
* Developed by Arnaud Le Hors *
\*****************************************************************************/
-#include "xpm34p.h"
+#include "XpmI.h"
+
+LFUNC(OpenBuffer, void, (char *buffer, xpmData *mdata));
int
-XpmCreateImageFromBuffer(Display *display, char *buffer, XImage **image_return,
- XImage **shapeimage_return, XpmAttributes *attributes)
+XpmCreateImageFromBuffer(display, buffer, image_return,
+ shapeimage_return, attributes)
+ Display *display;
+ char *buffer;
+ XImage **image_return;
+ XImage **shapeimage_return;
+ XpmAttributes *attributes;
{
XpmImage image;
XpmInfo info;
int ErrorStatus;
+ xpmData mdata;
- /* create an XpmImage from the buffer */
+ xpmInitXpmImage(&image);
+ xpmInitXpmInfo(&info);
+
+ /* open buffer to read */
+ OpenBuffer(buffer, &mdata);
+
+ /* create the XImage from the XpmData */
if (attributes) {
xpmInitAttributes(attributes);
xpmSetInfoMask(&info, attributes);
- ErrorStatus = XpmCreateXpmImageFromBuffer(buffer, &image, &info);
+ ErrorStatus = xpmParseDataAndCreate(display, &mdata,
+ image_return, shapeimage_return,
+ &image, &info, attributes);
} else
- ErrorStatus = XpmCreateXpmImageFromBuffer(buffer, &image, NULL);
-
- if (ErrorStatus != XpmSuccess)
- return (ErrorStatus);
-
- /* create the related ximages */
- ErrorStatus = XpmCreateImageFromXpmImage(display, &image,
- image_return, shapeimage_return,
- attributes);
+ ErrorStatus = xpmParseDataAndCreate(display, &mdata,
+ image_return, shapeimage_return,
+ &image, NULL, attributes);
if (attributes) {
if (ErrorStatus >= 0) /* no fatal error */
xpmSetAttributes(attributes, &image, &info);
XpmFreeXpmInfo(&info);
}
+
/* free the XpmImage */
XpmFreeXpmImage(&image);
}
int
-XpmCreateXpmImageFromBuffer(char *buffer, XpmImage *image, XpmInfo *info)
+XpmCreateXpmImageFromBuffer(buffer, image, info)
+ char *buffer;
+ XpmImage *image;
+ XpmInfo *info;
{
xpmData mdata;
int ErrorStatus;
xpmInitXpmInfo(info);
/* open buffer to read */
- xpmOpenBuffer(buffer, &mdata);
+ OpenBuffer(buffer, &mdata);
/* create the XpmImage from the XpmData */
ErrorStatus = xpmParseData(&mdata, image, info);
- xpmDataClose(&mdata);
-
return (ErrorStatus);
}
+
+/*
+ * open the given buffer to be read or written as an xpmData which is returned
+ */
+static void
+OpenBuffer(buffer, mdata)
+ char *buffer;
+ xpmData *mdata;
+{
+ mdata->type = XPMBUFFER;
+ mdata->cptr = buffer;
+ mdata->CommentLength = 0;
+}
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* XpmCrIFrData.c: *
+* CrIFrData.c: *
* *
* XPM library *
* Parse an Xpm array and create the image and possibly its mask *
* Developed by Arnaud Le Hors *
\*****************************************************************************/
-#include "xpm34p.h"
+#include "XpmI.h"
+
+LFUNC(OpenArray, void, (char **data, xpmData *mdata));
int
-XpmCreateImageFromData(Display *display, char **data, XImage **image_return,
- XImage **shapeimage_return, XpmAttributes *attributes)
+XpmCreateImageFromData(display, data, image_return,
+ shapeimage_return, attributes)
+ Display *display;
+ char **data;
+ XImage **image_return;
+ XImage **shapeimage_return;
+ XpmAttributes *attributes;
{
XpmImage image;
XpmInfo info;
int ErrorStatus;
+ xpmData mdata;
+
+ xpmInitXpmImage(&image);
+ xpmInitXpmInfo(&info);
+
+ /* open data */
+ OpenArray(data, &mdata);
/* create an XpmImage from the file */
if (attributes) {
xpmInitAttributes(attributes);
xpmSetInfoMask(&info, attributes);
- ErrorStatus = XpmCreateXpmImageFromData(data, &image, &info);
+ ErrorStatus = xpmParseDataAndCreate(display, &mdata,
+ image_return, shapeimage_return,
+ &image, &info, attributes);
} else
- ErrorStatus = XpmCreateXpmImageFromData(data, &image, NULL);
-
- if (ErrorStatus != XpmSuccess)
- return (ErrorStatus);
-
- /* create the related ximages */
- ErrorStatus = XpmCreateImageFromXpmImage(display, &image,
- image_return, shapeimage_return,
- attributes);
+ ErrorStatus = xpmParseDataAndCreate(display, &mdata,
+ image_return, shapeimage_return,
+ &image, NULL, attributes);
if (attributes) {
if (ErrorStatus >= 0) /* no fatal error */
xpmSetAttributes(attributes, &image, &info);
XpmFreeXpmInfo(&info);
}
+
+ /* free the XpmImage */
XpmFreeXpmImage(&image);
return (ErrorStatus);
}
int
-XpmCreateXpmImageFromData(char **data, XpmImage *image, XpmInfo *info)
+XpmCreateXpmImageFromData(data, image, info)
+ char **data;
+ XpmImage *image;
+ XpmInfo *info;
{
xpmData mdata;
int ErrorStatus;
xpmInitXpmInfo(info);
/* open data */
- xpmOpenArray(data, &mdata);
+ OpenArray(data, &mdata);
/* create the XpmImage from the XpmData */
ErrorStatus = xpmParseData(&mdata, image, info);
- xpmDataClose(&mdata);
-
return (ErrorStatus);
}
+
+/*
+ * open the given array to be read or written as an xpmData which is returned
+ */
+static void
+OpenArray(data, mdata)
+ char **data;
+ xpmData *mdata;
+{
+ mdata->type = XPMARRAY;
+ mdata->stream.data = data;
+ mdata->cptr = *data;
+ mdata->line = 0;
+ mdata->CommentLength = 0;
+ mdata->Bcmt = mdata->Ecmt = NULL;
+ mdata->Bos = mdata->Eos = '\0';
+ mdata->format = 0; /* this can only be Xpm 2 or 3 */
+}
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-/*****************************************************************************\
-* XpmCrPFrBuf.c: *
-* *
-* XPM library *
-* Parse an Xpm buffer and create the pixmap and possibly its mask *
-* *
-* Developed by Arnaud Le Hors *
-\*****************************************************************************/
-
-#ifndef FOR_MSW
-#include "xpm34p.h"
-
-int
-XpmCreatePixmapFromBuffer(Display *display, Drawable d, char *buffer, Pixmap *pixmap_return,
- Pixmap *shapemask_return, XpmAttributes *attributes)
-{
- XImage *ximage, *shapeimage;
- int ErrorStatus;
-
- /* initialize return values */
- if (pixmap_return)
- *pixmap_return = 0;
- if (shapemask_return)
- *shapemask_return = 0;
-
- /* create the images */
- ErrorStatus = XpmCreateImageFromBuffer(display, buffer,
- (pixmap_return ? &ximage : NULL),
- (shapemask_return ?
- &shapeimage : NULL),
- attributes);
-
- if (ErrorStatus < 0) /* fatal error */
- return (ErrorStatus);
-
- /* create the pixmaps and destroy images */
- if (pixmap_return && ximage) {
- xpmCreatePixmapFromImage(display, d, ximage, pixmap_return);
- XDestroyImage(ximage);
- }
- if (shapemask_return && shapeimage) {
- xpmCreatePixmapFromImage(display, d, shapeimage, shapemask_return);
- XDestroyImage(shapeimage);
- }
- return (ErrorStatus);
-}
-#endif
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-/*****************************************************************************\
-* XpmCrPFrData.c: *
-* *
-* XPM library *
-* Parse an Xpm array and create the pixmap and possibly its mask *
-* *
-* Developed by Arnaud Le Hors *
-\*****************************************************************************/
-
-#include "xpm34p.h"
-
-#ifndef FOR_MSW
-int
-XpmCreatePixmapFromData(Display *display, Drawable d, char **data, Pixmap *pixmap_return,
- Pixmap *shapemask_return, XpmAttributes *attributes)
-{
- XImage *ximage, *shapeimage;
- int ErrorStatus;
-
- /* initialize return values */
- if (pixmap_return)
- *pixmap_return = 0;
- if (shapemask_return)
- *shapemask_return = 0;
-
- /* create the images */
- ErrorStatus = XpmCreateImageFromData(display, data,
- (pixmap_return ? &ximage : NULL),
- (shapemask_return ?
- &shapeimage : NULL),
- attributes);
-
- if (ErrorStatus != XpmSuccess)
- return (ErrorStatus);
-
- if (ErrorStatus < 0) /* fatal error */
- return (ErrorStatus);
-
- /* create the pixmaps and destroy images */
- if (pixmap_return && ximage) {
- xpmCreatePixmapFromImage(display, d, ximage, pixmap_return);
- XDestroyImage(ximage);
- }
- if (shapemask_return && shapeimage) {
- xpmCreatePixmapFromImage(display, d, shapeimage, shapemask_return);
- XDestroyImage(shapeimage);
- }
- return (ErrorStatus);
-}
-#endif
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* Developed by Arnaud Le Hors *
\*****************************************************************************/
+#ifndef CXPMPROG
/* Official version number */
-static char *RCS_Version = "$XpmVersion: 3.4b $";
+static char *RCS_Version = "$XpmVersion: 3.4k $";
/* Internal version number */
static char *RCS_Id = "$Id$";
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:stat.h"
-#include "sys$library:ctype.h"
-#else
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <ctype.h>
+#include "XpmI.h"
#endif
+#include <ctype.h>
-#include <string.h>
-
-LFUNC(ParseComment, int, (xpmData * mdata));
+#ifndef CXPMPROG
+#define Getc(data, file) getc(file)
+#define Ungetc(data, c, file) ungetc(c, file)
+#endif
static int
-ParseComment(xpmData *mdata)
+ParseComment(data)
+ xpmData *data;
{
- if (mdata->type == XPMBUFFER) {
+ if (data->type == XPMBUFFER) {
register char c;
register unsigned int n = 0;
unsigned int notend;
char *s, *s2;
- s = mdata->Comment;
- *s = mdata->Bcmt[0];
+ s = data->Comment;
+ *s = data->Bcmt[0];
/* skip the string beginning comment */
- s2 = mdata->Bcmt;
+ s2 = data->Bcmt;
do {
- c = *mdata->cptr++;
+ c = *data->cptr++;
*++s = c;
n++;
s2++;
- } while (c == *s2 && *s2 != '\0' && c && c != mdata->Bos);
+ } while (c == *s2 && *s2 != '\0' && c);
if (*s2 != '\0') {
/* this wasn't the beginning of a comment */
- mdata->cptr -= n;
+ data->cptr -= n;
return 0;
}
/* store comment */
- mdata->Comment[0] = *s;
- s = mdata->Comment;
+ data->Comment[0] = *s;
+ s = data->Comment;
notend = 1;
n = 0;
while (notend) {
- s2 = mdata->Ecmt;
- while (*s != *s2 && c && c != mdata->Bos) {
- c = *mdata->cptr++;
+ s2 = data->Ecmt;
+ while (*s != *s2 && c) {
+ c = *data->cptr++;
+ if (n == XPMMAXCMTLEN - 1) { /* forget it */
+ s = data->Comment;
+ n = 0;
+ }
*++s = c;
n++;
}
- mdata->CommentLength = n;
+ data->CommentLength = n;
do {
- c = *mdata->cptr++;
- n++;
+ c = *data->cptr++;
+ if (n == XPMMAXCMTLEN - 1) { /* forget it */
+ s = data->Comment;
+ n = 0;
+ }
*++s = c;
+ n++;
s2++;
- } while (c == *s2 && *s2 != '\0' && c && c != mdata->Bos);
+ } while (c == *s2 && *s2 != '\0' && c);
if (*s2 == '\0') {
/* this is the end of the comment */
notend = 0;
- mdata->cptr--;
+ data->cptr--;
}
}
return 0;
} else {
- FILE *file = mdata->stream.file;
+ FILE *file = data->stream.file;
register int c;
register unsigned int n = 0, a;
unsigned int notend;
char *s, *s2;
- s = mdata->Comment;
- *s = mdata->Bcmt[0];
+ s = data->Comment;
+ *s = data->Bcmt[0];
/* skip the string beginning comment */
- s2 = mdata->Bcmt;
+ s2 = data->Bcmt;
do {
- c = getc(file);
+ c = Getc(data, file);
*++s = c;
n++;
s2++;
- } while (c == *s2 && *s2 != '\0'
- && c != EOF && c != mdata->Bos);
+ } while (c == *s2 && *s2 != '\0' && c != EOF);
if (*s2 != '\0') {
/* this wasn't the beginning of a comment */
/* put characters back in the order that we got them */
for (a = n; a > 0; a--, s--)
- ungetc(*s, file);
+ Ungetc(data, *s, file);
return 0;
}
/* store comment */
- mdata->Comment[0] = *s;
- s = mdata->Comment;
+ data->Comment[0] = *s;
+ s = data->Comment;
notend = 1;
n = 0;
while (notend) {
- s2 = mdata->Ecmt;
- while (*s != *s2 && c != EOF && c != mdata->Bos) {
- c = getc(file);
+ s2 = data->Ecmt;
+ while (*s != *s2 && c != EOF) {
+ c = Getc(data, file);
+ if (n == XPMMAXCMTLEN - 1) { /* forget it */
+ s = data->Comment;
+ n = 0;
+ }
*++s = c;
n++;
}
- mdata->CommentLength = n;
+ data->CommentLength = n;
do {
- c = getc(file);
- n++;
+ c = Getc(data, file);
+ if (n == XPMMAXCMTLEN - 1) { /* forget it */
+ s = data->Comment;
+ n = 0;
+ }
*++s = c;
+ n++;
s2++;
- } while (c == *s2 && *s2 != '\0'
- && c != EOF && c != mdata->Bos);
+ } while (c == *s2 && *s2 != '\0' && c != EOF);
if (*s2 == '\0') {
/* this is the end of the comment */
notend = 0;
- ungetc(*s, file);
+ Ungetc(data, *s, file);
}
}
return 0;
* skip to the end of the current string and the beginning of the next one
*/
int
-xpmNextString(xpmData *mdata)
+xpmNextString(data)
+ xpmData *data;
{
- if (!mdata->type)
- mdata->cptr = (mdata->stream.data)[++mdata->line];
- else if (mdata->type == XPMBUFFER) {
+ if (!data->type)
+ data->cptr = (data->stream.data)[++data->line];
+ else if (data->type == XPMBUFFER) {
register char c;
/* get to the end of the current string */
- if (mdata->Eos)
- while ((c = *mdata->cptr++) && c != mdata->Eos);
+ if (data->Eos)
+ while ((c = *data->cptr++) && c != data->Eos);
/*
* then get to the beginning of the next string looking for possible
* comment
*/
- if (mdata->Bos) {
- while ((c = *mdata->cptr++) && c != mdata->Bos)
- if (mdata->Bcmt && c == mdata->Bcmt[0])
- ParseComment(mdata);
- } else if (mdata->Bcmt) { /* XPM2 natural */
- while ((c = *mdata->cptr++) == mdata->Bcmt[0])
- ParseComment(mdata);
- mdata->cptr--;
+ if (data->Bos) {
+ while ((c = *data->cptr++) && c != data->Bos)
+ if (data->Bcmt && c == data->Bcmt[0])
+ ParseComment(data);
+ } else if (data->Bcmt) { /* XPM2 natural */
+ while ((c = *data->cptr++) == data->Bcmt[0])
+ ParseComment(data);
+ data->cptr--;
}
} else {
register int c;
- FILE *file = mdata->stream.file;
+ FILE *file = data->stream.file;
/* get to the end of the current string */
- if (mdata->Eos)
- while ((c = getc(file)) != mdata->Eos && c != EOF);
+ if (data->Eos)
+ while ((c = Getc(data, file)) != data->Eos && c != EOF);
/*
* then get to the beginning of the next string looking for possible
* comment
*/
- if (mdata->Bos) {
- while ((c = getc(file)) != mdata->Bos && c != EOF)
- if (mdata->Bcmt && c == mdata->Bcmt[0])
- ParseComment(mdata);
-
- } else if (mdata->Bcmt) { /* XPM2 natural */
- while ((c = getc(file)) == mdata->Bcmt[0])
- ParseComment(mdata);
- ungetc(c, file);
+ if (data->Bos) {
+ while ((c = Getc(data, file)) != data->Bos && c != EOF)
+ if (data->Bcmt && c == data->Bcmt[0])
+ ParseComment(data);
+
+ } else if (data->Bcmt) { /* XPM2 natural */
+ while ((c = Getc(data, file)) == data->Bcmt[0])
+ ParseComment(data);
+ Ungetc(data, c, file);
}
}
return 0;
}
-/*
- * skip whitespace and compute the following unsigned int,
- * returns 1 if one is found and 0 if not
- */
-int
-xpmNextUI(xpmData *mdata, unsigned int *ui_return)
-{
- char buf[BUFSIZ];
- int l;
-
- l = xpmNextWord(mdata, buf, BUFSIZ);
- return atoui(buf, l, ui_return);
-}
-
/*
* skip whitespace and return the following word
*/
unsigned int
-xpmNextWord(xpmData *mdata, char *buf, unsigned int buflen)
+xpmNextWord(data, buf, buflen)
+ xpmData *data;
+ char *buf;
+ unsigned int buflen;
{
register unsigned int n = 0;
int c;
- if (!mdata->type || mdata->type == XPMBUFFER) {
- while (isspace(c = *mdata->cptr) && c != mdata->Eos)
- mdata->cptr++;
+ if (!data->type || data->type == XPMBUFFER) {
+ while (isspace(c = *data->cptr) && c != data->Eos)
+ data->cptr++;
do {
- c = *mdata->cptr++;
+ c = *data->cptr++;
*buf++ = c;
n++;
- } while (!isspace(c) && c != mdata->Eos && n < buflen);
+ } while (!isspace(c) && c != data->Eos && n < buflen);
n--;
- mdata->cptr--;
+ data->cptr--;
} else {
- FILE *file = mdata->stream.file;
+ FILE *file = data->stream.file;
- while ((c = getc(file)) != EOF && isspace(c) && c != mdata->Eos);
- while (!isspace(c) && c != mdata->Eos && c != EOF && n < buflen) {
+ while ((c = Getc(data, file)) != EOF && isspace(c) && c != data->Eos);
+ while (!isspace(c) && c != data->Eos && c != EOF && n < buflen) {
*buf++ = c;
n++;
- c = getc(file);
+ c = Getc(data, file);
}
- ungetc(c, file);
+ Ungetc(data, c, file);
}
return (n);
}
+/*
+ * skip whitespace and compute the following unsigned int,
+ * returns 1 if one is found and 0 if not
+ */
+int
+xpmNextUI(data, ui_return)
+ xpmData *data;
+ unsigned int *ui_return;
+{
+ char buf[BUFSIZ];
+ int l;
+
+ l = xpmNextWord(data, buf, BUFSIZ);
+ return xpmatoui(buf, l, ui_return);
+}
+
/*
* return end of string - WARNING: malloc!
*/
int
-xpmGetString(xpmData *mdata, char **sptr, unsigned int *l)
+xpmGetString(data, sptr, l)
+ xpmData *data;
+ char **sptr;
+ unsigned int *l;
{
unsigned int i, n = 0;
int c;
- char *p, *q, buf[BUFSIZ];
-
- if (!mdata->type || mdata->type == XPMBUFFER) {
- if (mdata->cptr) {
- char *start;
-
- while (isspace(c = *mdata->cptr) && c != mdata->Eos)
- mdata->cptr++;
- start = mdata->cptr;
- while ((c = *mdata->cptr) && c != mdata->Eos)
- mdata->cptr++;
- n = mdata->cptr - start + 1;
+ char *p = NULL, *q, buf[BUFSIZ];
+
+ if (!data->type || data->type == XPMBUFFER) {
+ if (data->cptr) {
+ char *start = data->cptr;
+ while ((c = *data->cptr) && c != data->Eos)
+ data->cptr++;
+ n = data->cptr - start + 1;
p = (char *) XpmMalloc(n);
if (!p)
return (XpmNoMemory);
strncpy(p, start, n);
- if (mdata->type) /* XPMBUFFER */
+ if (data->type) /* XPMBUFFER */
p[n - 1] = '\0';
}
} else {
- FILE *file = mdata->stream.file;
+ FILE *file = data->stream.file;
- while ((c = getc(file)) != EOF && isspace(c) && c != mdata->Eos);
- if (c == EOF)
+ if ((c = Getc(data, file)) == EOF)
return (XpmFileInvalid);
- p = NULL;
+
i = 0;
q = buf;
p = (char *) XpmMalloc(1);
- while (c != mdata->Eos && c != EOF) {
+ while (c != data->Eos && c != EOF) {
if (i == BUFSIZ) {
/* get to the end of the buffer */
/* malloc needed memory */
}
*q++ = c;
i++;
- c = getc(file);
+ c = Getc(data, file);
}
if (c == EOF) {
XpmFree(p);
*p = '\0';
n = 1;
}
- ungetc(c, file);
+ Ungetc(data, c, file);
}
*sptr = p;
*l = n;
* get the current comment line
*/
int
-xpmGetCmt(xpmData *mdata, char **cmt)
+xpmGetCmt(data, cmt)
+ xpmData *data;
+ char **cmt;
{
- if (!mdata->type)
+ if (!data->type)
*cmt = NULL;
- else if (mdata->CommentLength) {
- *cmt = (char *) XpmMalloc(mdata->CommentLength + 1);
- strncpy(*cmt, mdata->Comment, mdata->CommentLength);
- (*cmt)[mdata->CommentLength] = '\0';
- mdata->CommentLength = 0;
+ else if (data->CommentLength) {
+ *cmt = (char *) XpmMalloc(data->CommentLength + 1);
+ strncpy(*cmt, data->Comment, data->CommentLength);
+ (*cmt)[data->CommentLength] = '\0';
+ data->CommentLength = 0;
} else
*cmt = NULL;
return 0;
}
-/*
- * open the given file to be read as an xpmData which is returned.
- */
-int
-xpmReadFile(char *filename, xpmData *mdata)
-{
-#ifdef ZPIPE
- char *compressfile, buf[BUFSIZ];
- struct stat status;
-
-#endif
-
- if (!filename) {
- mdata->stream.file = (stdin);
- mdata->type = XPMFILE;
- } else {
-#ifdef ZPIPE
- if (((int) strlen(filename) > 2) &&
- !strcmp(".Z", filename + (strlen(filename) - 2))) {
- mdata->type = XPMPIPE;
- sprintf(buf, "uncompress -c %s", filename);
- if (!(mdata->stream.file = popen(buf, "r")))
- return (XpmOpenFailed);
-
- } else if (((int) strlen(filename) > 3) &&
- !strcmp(".gz", filename + (strlen(filename) - 3))) {
- mdata->type = XPMPIPE;
- sprintf(buf, "gunzip -qc %s", filename);
- if (!(mdata->stream.file = popen(buf, "r")))
- return (XpmOpenFailed);
-
- } else {
- if (!(compressfile = (char *) XpmMalloc(strlen(filename) + 4)))
- return (XpmNoMemory);
-
- strcpy(compressfile, filename);
- strcat(compressfile, ".Z");
- if (!stat(compressfile, &status)) {
- sprintf(buf, "uncompress -c %s", compressfile);
- if (!(mdata->stream.file = popen(buf, "r"))) {
- XpmFree(compressfile);
- return (XpmOpenFailed);
- }
- mdata->type = XPMPIPE;
- } else {
- strcpy(compressfile, filename);
- strcat(compressfile, ".gz");
- if (!stat(compressfile, &status)) {
- sprintf(buf, "gunzip -c %s", compressfile);
- if (!(mdata->stream.file = popen(buf, "r"))) {
- XpmFree(compressfile);
- return (XpmOpenFailed);
- }
- mdata->type = XPMPIPE;
- } else {
-#endif
- if (!(mdata->stream.file = fopen(filename, "r"))) {
-#ifdef ZPIPE
- XpmFree(compressfile);
-#endif
- return (XpmOpenFailed);
- }
- mdata->type = XPMFILE;
-#ifdef ZPIPE
- }
- }
- XpmFree(compressfile);
- }
-#endif
- }
- mdata->CommentLength = 0;
- return (XpmSuccess);
-}
-
-/*
- * open the given file to be written as an xpmData which is returned
- */
-int
-xpmWriteFile(char *filename, xpmData *mdata)
-{
-#ifdef ZPIPE
- char buf[BUFSIZ];
-
-#endif
-
- if (!filename) {
- mdata->stream.file = (stdout);
- mdata->type = XPMFILE;
- } else {
-#ifdef ZPIPE
- if ((int) strlen(filename) > 2
- && !strcmp(".Z", filename + (strlen(filename) - 2))) {
- sprintf(buf, "compress > %s", filename);
- if (!(mdata->stream.file = popen(buf, "w")))
- return (XpmOpenFailed);
-
- mdata->type = XPMPIPE;
- } else if ((int) strlen(filename) > 3
- && !strcmp(".gz", filename + (strlen(filename) - 3))) {
- sprintf(buf, "gzip -q > %s", filename);
- if (!(mdata->stream.file = popen(buf, "w")))
- return (XpmOpenFailed);
-
- mdata->type = XPMPIPE;
- } else {
-#endif
- if (!(mdata->stream.file = fopen(filename, "w")))
- return (XpmOpenFailed);
-
- mdata->type = XPMFILE;
-#ifdef ZPIPE
- }
-#endif
- }
- return (XpmSuccess);
-}
-
-/*
- * open the given array to be read or written as an xpmData which is returned
- */
-void
-xpmOpenArray(char **data, xpmData *mdata)
-{
- mdata->type = XPMARRAY;
- mdata->stream.data = data;
- mdata->cptr = *data;
- mdata->line = 0;
- mdata->CommentLength = 0;
- mdata->Bcmt = mdata->Ecmt = NULL;
- mdata->Bos = mdata->Eos = '\0';
- mdata->format = 0; /* this can only be Xpm 2 or 3 */
-}
-
-/*
- * open the given buffer to be read or written as an xpmData which is returned
- */
-void
-xpmOpenBuffer(char *buffer, xpmData *mdata)
-{
- mdata->type = XPMBUFFER;
- mdata->cptr = buffer;
- mdata->CommentLength = 0;
-}
-
-/*
- * close the file related to the xpmData if any
- */
-int
-xpmDataClose(xpmData *mdata)
-{
- switch (mdata->type) {
- case XPMARRAY:
- case XPMBUFFER:
- break;
- case XPMFILE:
- if (mdata->stream.file != (stdout) && mdata->stream.file != (stdin))
- fclose(mdata->stream.file);
- break;
-#ifdef ZPIPE
- case XPMPIPE:
- pclose(mdata->stream.file);
- break;
-#endif
- }
- return 0;
-}
-
xpmDataType xpmDataTypes[] =
{
"", "!", "\n", '\0', '\n', "", "", "", "", /* Natural type */
* parse xpm header
*/
int
-xpmParseHeader(xpmData *mdata)
+xpmParseHeader(data)
+ xpmData *data;
{
char buf[BUFSIZ];
int l, n = 0;
- if (mdata->type) {
- mdata->Bos = '\0';
- mdata->Eos = '\n';
- mdata->Bcmt = mdata->Ecmt = NULL;
- l = xpmNextWord(mdata, buf, BUFSIZ);
+ if (data->type) {
+ data->Bos = '\0';
+ data->Eos = '\n';
+ data->Bcmt = data->Ecmt = NULL;
+ l = xpmNextWord(data, buf, BUFSIZ);
if (l == 7 && !strncmp("#define", buf, 7)) {
/* this maybe an XPM 1 file */
char *ptr;
- l = xpmNextWord(mdata, buf, BUFSIZ);
+ l = xpmNextWord(data, buf, BUFSIZ);
if (!l)
return (XpmFileInvalid);
- ptr = strchr(buf, '_');
+ buf[l] = '\0';
+ ptr = rindex(buf, '_');
if (!ptr || strncmp("_format", ptr, l - (ptr - buf)))
return XpmFileInvalid;
/* this is definitely an XPM 1 file */
- mdata->format = 1;
+ data->format = 1;
n = 1; /* handle XPM1 as mainly XPM2 C */
} else {
* skip the first word, get the second one, and see if this is
* XPM 2 or 3
*/
- l = xpmNextWord(mdata, buf, BUFSIZ);
+ l = xpmNextWord(data, buf, BUFSIZ);
if ((l == 3 && !strncmp("XPM", buf, 3)) ||
(l == 4 && !strncmp("XPM2", buf, 4))) {
if (l == 3)
n = 1; /* handle XPM as XPM2 C */
else {
/* get the type key word */
- l = xpmNextWord(mdata, buf, BUFSIZ);
+ l = xpmNextWord(data, buf, BUFSIZ);
/*
* get infos about this type
&& strncmp(xpmDataTypes[n].type, buf, l))
n++;
}
- mdata->format = 0;
+ data->format = 0;
} else
/* nope this is not an XPM file */
return XpmFileInvalid;
}
if (xpmDataTypes[n].type) {
if (n == 0) { /* natural type */
- mdata->Bcmt = xpmDataTypes[n].Bcmt;
- mdata->Ecmt = xpmDataTypes[n].Ecmt;
- xpmNextString(mdata); /* skip the end of the headerline */
- mdata->Bos = xpmDataTypes[n].Bos;
- mdata->Eos = xpmDataTypes[n].Eos;
+ data->Bcmt = xpmDataTypes[n].Bcmt;
+ data->Ecmt = xpmDataTypes[n].Ecmt;
+ xpmNextString(data); /* skip the end of the headerline */
+ data->Bos = xpmDataTypes[n].Bos;
+ data->Eos = xpmDataTypes[n].Eos;
} else {
- mdata->Bcmt = xpmDataTypes[n].Bcmt;
- mdata->Ecmt = xpmDataTypes[n].Ecmt;
- if (!mdata->format) { /* XPM 2 or 3 */
- mdata->Bos = xpmDataTypes[n].Bos;
- mdata->Eos = '\0';
+ data->Bcmt = xpmDataTypes[n].Bcmt;
+ data->Ecmt = xpmDataTypes[n].Ecmt;
+ if (!data->format) { /* XPM 2 or 3 */
+ data->Bos = xpmDataTypes[n].Bos;
+ data->Eos = '\0';
/* get to the beginning of the first string */
- xpmNextString(mdata);
- mdata->Eos = xpmDataTypes[n].Eos;
+ xpmNextString(data);
+ data->Eos = xpmDataTypes[n].Eos;
} else /* XPM 1 skip end of line */
- xpmNextString(mdata);
+ xpmNextString(data);
}
} else
/* we don't know about that type of XPM file... */
CHANGES
COPYRIGHT
+FAQ.html
FILES
Imakefile
-Makefile.noXtree
-README
+Makefile.noX
+README.html
+README.AMIGA
README.MSW
namecvt
lib
lib/Imakefile
-lib/Makefile.noXtree
-lib/XpmCrBufFrI.c
-lib/XpmCrBufFrP.c
-lib/XpmCrDataFrI.c
-lib/XpmCrDataFrP.c
-lib/XpmCrIFrBuf.c
-lib/XpmCrIFrData.c
-lib/XpmCrPFrBuf.c
-lib/XpmCrPFrData.c
-lib/XpmRdFToData.c
-lib/XpmRdFToI.c
-lib/XpmRdFToP.c
-lib/XpmWrFFrData.c
-lib/XpmWrFFrI.c
-lib/XpmWrFFrP.c
+lib/Makefile.noX
+lib/Makefile.AmigaGCC
+lib/Smakefile
+lib/Attrib.c
+lib/CrBufFrI.c
+lib/CrBufFrP.c
+lib/CrDatFrI.c
+lib/CrDatFrP.c
+lib/CrIFrBuf.c
+lib/CrIFrDat.c
+lib/CrIFrP.c
+lib/CrPFrBuf.c
+lib/CrPFrDat.c
+lib/CrPFrI.c
+lib/Image.c
+lib/Info.c
+lib/RdFToBuf.c
+lib/RdFToDat.c
+lib/RdFToI.c
+lib/RdFToP.c
+lib/WrFFrBuf.c
+lib/WrFFrDat.c
+lib/WrFFrI.c
+lib/WrFFrP.c
+lib/amigax.h
+lib/amigax.c
lib/create.c
lib/data.c
-lib/hashtable.c
+lib/descrip.mms
+lib/hashtab.c
+lib/make.com
lib/misc.c
lib/parse.c
lib/rgb.c
lib/simx.h
lib/simx.c
lib/xpm.h
-lib/xpmP.h
+lib/XpmI.h
+lib/Xpm-def.cpp
doc
-doc/xpm.ps
+doc/xpm.PS
sxpm
sxpm/Imakefile
-sxpm/Makefile.noXtree
+sxpm/Makefile.noX
sxpm/plaid.xpm
sxpm/plaid_ext.xpm
sxpm/plaid_mask.xpm
sxpm/sxpm.c
sxpm/sxpm.man
+cxpm
+cxpm/Imakefile
+cxpm/Makefile.noX
+cxpm/cxpm.c
+cxpm/cxpm.man
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* hashtable.c: *
+* hashtab.c: *
* *
* XPM library *
* *
* *
\*****************************************************************************/
-#include "xpm34p.h"
+#include "XpmI.h"
LFUNC(AtomMake, xpmHashAtom, (char *name, void *data));
LFUNC(HashTableGrows, int, (xpmHashTable * table));
static xpmHashAtom
-AtomMake(char *name, void *data) /* makes an atom */
-/* char *name; */ /* WARNING: is just pointed to */
-/* void *data; */
+AtomMake(name, data) /* makes an atom */
+ char *name; /* WARNING: is just pointed to */
+ void *data;
{
xpmHashAtom object = (xpmHashAtom) XpmMalloc(sizeof(struct _xpmHashAtom));
*/
xpmHashAtom *
-xpmHashSlot(xpmHashTable *table, char *s)
+xpmHashSlot(table, s)
+ xpmHashTable *table;
+ char *s;
{
xpmHashAtom *atomTable = table->atomTable;
unsigned int hash;
}
static int
-HashTableGrows(xpmHashTable *table)
+HashTableGrows(table)
+ xpmHashTable *table;
{
xpmHashAtom *atomTable = table->atomTable;
int size = table->size;
*/
int
-xpmHashIntern(xpmHashTable *table, char *tag, void *data)
+xpmHashIntern(table, tag, data)
+ xpmHashTable *table;
+ char *tag;
+ void *data;
{
xpmHashAtom *slot;
*/
int
-xpmHashTableInit(xpmHashTable *table)
+xpmHashTableInit(table)
+ xpmHashTable *table;
{
xpmHashAtom *p;
xpmHashAtom *atomTable;
*/
void
-xpmHashTableFree(xpmHashTable *table)
+xpmHashTableFree(table)
+ xpmHashTable *table;
{
xpmHashAtom *p;
xpmHashAtom *atomTable = table->atomTable;
+ if (!atomTable)
+ return;
for (p = atomTable + table->size; p > atomTable;)
if (*--p)
XpmFree(*p);
--- /dev/null
+/*
+ * Copyright (C) 1989-95 GROUPE BULL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 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
+ * GROUPE BULL 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 GROUPE BULL shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from GROUPE BULL.
+ */
+
+/*****************************************************************************\
+* Image.c: *
+* *
+* XPM library *
+* Functions to init and free the XpmImage structure. *
+* *
+* Developed by Arnaud Le Hors *
+\*****************************************************************************/
+
+#include "XpmI.h"
+
+/*
+ * Init returned data to free safely later on
+ */
+void
+xpmInitXpmImage(image)
+ XpmImage *image;
+{
+ image->ncolors = 0;
+ image->colorTable = NULL;
+ image->data = NULL;
+}
+
+/*
+ * Free the XpmImage data which have been allocated
+ */
+void
+XpmFreeXpmImage(image)
+ XpmImage *image;
+{
+ if (image->colorTable)
+ xpmFreeColorTable(image->colorTable, image->ncolors);
+ if (image->data)
+ XpmFree(image->data);
+ image->data = NULL;
+}
--- /dev/null
+/*
+ * Copyright (C) 1989-95 GROUPE BULL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 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
+ * GROUPE BULL 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 GROUPE BULL shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from GROUPE BULL.
+ */
+
+/*****************************************************************************\
+* Info.c: *
+* *
+* XPM library *
+* Functions related to the XpmInfo structure. *
+* *
+* Developed by Arnaud Le Hors *
+\*****************************************************************************/
+
+#include "XpmI.h"
+
+/*
+ * Init returned data to free safely later on
+ */
+void
+xpmInitXpmInfo(info)
+ XpmInfo *info;
+{
+ if (info) {
+ info->hints_cmt = NULL;
+ info->colors_cmt = NULL;
+ info->pixels_cmt = NULL;
+ info->extensions = NULL;
+ info->nextensions = 0;
+ }
+}
+
+/*
+ * Free the XpmInfo data which have been allocated
+ */
+void
+XpmFreeXpmInfo(info)
+ XpmInfo *info;
+{
+ if (info) {
+ if (info->valuemask & XpmComments) {
+ if (info->hints_cmt) {
+ XpmFree(info->hints_cmt);
+ info->hints_cmt = NULL;
+ }
+ if (info->colors_cmt) {
+ XpmFree(info->colors_cmt);
+ info->colors_cmt = NULL;
+ }
+ if (info->pixels_cmt) {
+ XpmFree(info->pixels_cmt);
+ info->pixels_cmt = NULL;
+ }
+ }
+ if (info->valuemask & XpmReturnExtensions && info->nextensions) {
+ XpmFreeExtensions(info->extensions, info->nextensions);
+ info->extensions = NULL;
+ info->nextensions = 0;
+ }
+ info->valuemask = 0;
+ }
+}
+
+/*
+ * Set the XpmInfo valuemask to retrieve required info
+ */
+void
+xpmSetInfoMask(info, attributes)
+ XpmInfo *info;
+ XpmAttributes *attributes;
+{
+ info->valuemask = 0;
+ if (attributes->valuemask & XpmReturnInfos)
+ info->valuemask |= XpmReturnComments;
+ if (attributes->valuemask & XpmReturnExtensions)
+ info->valuemask |= XpmReturnExtensions;
+}
+
+/*
+ * Fill in the XpmInfo with the XpmAttributes
+ */
+void
+xpmSetInfo(info, attributes)
+ XpmInfo *info;
+ XpmAttributes *attributes;
+{
+ info->valuemask = 0;
+ if (attributes->valuemask & XpmInfos) {
+ info->valuemask |= XpmComments | XpmColorTable;
+ info->hints_cmt = attributes->hints_cmt;
+ info->colors_cmt = attributes->colors_cmt;
+ info->pixels_cmt = attributes->pixels_cmt;
+ }
+ if (attributes->valuemask & XpmExtensions) {
+ info->valuemask |= XpmExtensions;
+ info->extensions = attributes->extensions;
+ info->nextensions = attributes->nextensions;
+ }
+ if (attributes->valuemask & XpmHotspot) {
+ info->valuemask |= XpmHotspot;
+ info->x_hotspot = attributes->x_hotspot;
+ info->y_hotspot = attributes->y_hotspot;
+ }
+}
LIBTARGET=$(WXDIR)\lib\xpm.lib
-OBJECTS = crbuffri.obj crdatfri.obj create.obj crifrbuf.obj crifrdat.obj\
- data.obj hashtab.obj misc.obj parse.obj rdftodat.obj rdftoi.obj\
- rgb.obj scan.obj simx.obj wrffrdat.obj wrffrp.obj wrffri.obj
+OBJECTS = attrib.obj crbuffri.obj crdatfri.obj create.obj crifrbuf.obj crifrdat.obj\
+ data.obj image.obj info.obj hashtab.obj misc.obj parse.obj\
+ rdftodat.obj rdftoi.obj rgb.obj scan.obj simx.obj wrffrdat.obj wrffri.obj
!include $(WXWIN)\src\makelib.b32
XPMDIR=$(WXDIR)\src\xpm
-OBJECTS = $(XPMDIR)\crbuffri.obj\
+OBJECTS = $(XPMDIR)\attrib.obj\
+ $(XPMDIR)\crbuffri.obj\
$(XPMDIR)\crdatfri.obj\
- $(XPMDIR)\create.obj $(XPMDIR)\crifrbuf.obj\
+ $(XPMDIR)\create.obj\
+ $(XPMDIR)\crifrbuf.obj\
$(XPMDIR)\crifrdat.obj\
$(XPMDIR)\data.obj\
- $(XPMDIR)\hashtab.obj $(XPMDIR)\misc.obj\
- $(XPMDIR)\parse.obj $(XPMDIR)\rdftodat.obj\
+ $(XPMDIR)\image.obj\
+ $(XPMDIR)\info.obj\
+ $(XPMDIR)\hashtab.obj\
+ $(XPMDIR)\misc.obj\
+ $(XPMDIR)\parse.obj\
+ $(XPMDIR)\rdftodat.obj\
$(XPMDIR)\rdftoi.obj\
- $(XPMDIR)\rgb.obj $(XPMDIR)\scan.obj\
- $(XPMDIR)\simx.obj $(XPMDIR)\wrffrdat.obj\
- $(XPMDIR)\wrffrp.obj $(XPMDIR)\wrffri.obj
+ $(XPMDIR)\rgb.obj\
+ $(XPMDIR)\scan.obj\
+ $(XPMDIR)\simx.obj\
+ $(XPMDIR)\wrffrdat.obj\
+ $(XPMDIR)\wrffri.obj
all: $(LIBTARGET)
$(OBJECTS) $(PERIPH_LIBS)
<<
-$(XPMDIR)\crbuffri.obj: $(XPMDIR)\crbuffri.c
+$(XPMDIR)\crbuffri.obj: $(XPMDIR)\attrib.c
cl @<<
$(CPPFLAGS2) /c $*.c /Fo$@
<<
-$(XPMDIR)\crbuffrp.obj: $(XPMDIR)\crbuffrp.c
+$(XPMDIR)\crbuffri.obj: $(XPMDIR)\crbuffri.c
cl @<<
-$(CPPFLAGS2) /c $*.c /Fo$@
+$(CPPFLAGS2) /c $*.c /Fo$@
<<
$(XPMDIR)\crdatfri.obj: $(XPMDIR)\crdatfri.c
$(CPPFLAGS2) /c $*.c /Fo$@
<<
-$(XPMDIR)\crdatfrp.obj: $(XPMDIR)\crdatfrp.c
- cl @<<
-$(CPPFLAGS2) /c $*.c /Fo$@
-<<
-
$(XPMDIR)\create.obj: $(XPMDIR)\create.c
cl @<<
$(CPPFLAGS2) /c $*.c /Fo$@
$(CPPFLAGS2) /c $*.c /Fo$@
<<
-$(XPMDIR)\crpfrbuf.obj: $(XPMDIR)\crpfrbuf.c
+$(XPMDIR)\data.obj: $(XPMDIR)\data.c
cl @<<
$(CPPFLAGS2) /c $*.c /Fo$@
<<
-$(XPMDIR)\crpfrdat.obj: $(XPMDIR)\crpfrdat.c
+$(XPMDIR)\data.obj: $(XPMDIR)\image.c
cl @<<
$(CPPFLAGS2) /c $*.c /Fo$@
<<
-$(XPMDIR)\data.obj: $(XPMDIR)\data.c
+$(XPMDIR)\data.obj: $(XPMDIR)\info.c
cl @<<
$(CPPFLAGS2) /c $*.c /Fo$@
<<
$(CPPFLAGS2) /c $*.c /Fo$@
<<
-$(XPMDIR)\rdftop.obj: $(XPMDIR)\rdftop.c
- cl @<<
-$(CPPFLAGS2) /c $*.c /Fo$@
-<<
-
$(XPMDIR)\rgb.obj: $(XPMDIR)\rgb.c
cl @<<
$(CPPFLAGS2) /c $*.c /Fo$@
$(CPPFLAGS2) /c $*.c /Fo$@
<<
-$(XPMDIR)\wrffrp.obj: $(XPMDIR)\wrffrp.c
- cl @<<
-$(CPPFLAGS2) /c $*.c /Fo$@
-<<
-
clean:
-erase *.obj
-erase $(LIBTARGET)
LIBTARGET = $(WXLIB)\xpm.lib
-OBJECTS = crbuffri.obj &
+OBJECTS = attrib.obj &
+ crbuffri.obj &
crdatfri.obj &
create.obj &
- crifrbuf.obj &
+ crifrbuf.obj &
crifrdat.obj &
data.obj &
+ image.obj &
+ info.obj &
hashtab.obj &
- misc.obj &
+ misc.obj &
parse.obj &
- rdftodat.obj &
+ rdftodat.obj &
rdftoi.obj &
rgb.obj &
- scan.obj &
+ scan.obj &
simx.obj &
- wrffrdat.obj &
- wrffrp.obj &
- wrffri.obj
+ wrffrdat.obj &
+ wrffri.obj
all: $(OBJECTS) $(LIBTARGET)
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* Developed by Arnaud Le Hors *
\*****************************************************************************/
-/*
- * The code related to FOR_MSW has been added by
- * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
- */
-
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:stat.h"
-#include "sys$library:fcntl.h"
-#else
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#ifdef FOR_MSW
-#include <io.h>
-#else
-#include <unistd.h>
-#endif
-#endif
-
-/* 3.2 backward compatibility code */
-LFUNC(CreateOldColorTable, int, (XpmColor *ct, int ncolors,
- XpmColor ***oldct));
-
-LFUNC(FreeOldColorTable, void, (XpmColor **colorTable, int ncolors));
-
-/*
- * Create a colortable compatible with the old style colortable
- */
-static int
-CreateOldColorTable(XpmColor *ct, int ncolors, XpmColor ***oldct)
-{
- XpmColor **colorTable, **color;
- int a;
-
- colorTable = (XpmColor **) XpmMalloc(ncolors * sizeof(XpmColor *));
- if (!colorTable) {
- *oldct = NULL;
- return (XpmNoMemory);
- }
- for (a = 0, color = colorTable; a < ncolors; a++, color++, ct++)
- *color = ct;
- *oldct = colorTable;
- return (XpmSuccess);
-}
-
-static void
-FreeOldColorTable(XpmColor **colorTable, int ncolors)
-{
- int a, b;
- XpmColor **color;
- char **sptr;
-
- if (colorTable) {
- for (a = 0, color = colorTable; a < ncolors; a++, color++) {
- for (b = 0, sptr = (char **) *color; b <= NKEYS; b++, sptr++)
- if (*sptr)
- XpmFree(*sptr);
- }
- XpmFree(*colorTable);
- XpmFree(colorTable);
- }
-}
-
-/* end 3.2 bc */
-
-
-/*
- * Free the computed color table
- */
-void
-xpmFreeColorTable(XpmColor *colorTable, int ncolors)
-{
- int a, b;
- XpmColor *color;
- char **sptr;
-
- if (colorTable) {
- for (a = 0, color = colorTable; a < ncolors; a++, color++) {
- for (b = 0, sptr = (char **) color; b <= NKEYS; b++, sptr++)
- if (*sptr)
- XpmFree(*sptr);
- }
- XpmFree(colorTable);
- }
-}
-
-/*
- * Free array of extensions
- */
-void
-XpmFreeExtensions(XpmExtension *extensions, int nextensions)
-{
- unsigned int i, j, nlines;
- XpmExtension *ext;
- char **sptr;
-
- if (extensions) {
- for (i = 0, ext = extensions; i < (unsigned int)nextensions; i++, ext++) {
- if (ext->name)
- XpmFree(ext->name);
- nlines = ext->nlines;
- for (j = 0, sptr = ext->lines; j < nlines; j++, sptr++)
- if (*sptr)
- XpmFree(*sptr);
- if (ext->lines)
- XpmFree(ext->lines);
- }
- XpmFree(extensions);
- }
-}
-
-
-/*
- * Return the XpmAttributes structure size
- */
-
-int
-XpmAttributesSize()
-{
- return sizeof(XpmAttributes);
-}
-
-/*
- * Init returned data to free safely later on
- */
-void
-xpmInitAttributes(XpmAttributes *attributes)
-{
- if (attributes) {
- attributes->pixels = NULL;
- attributes->npixels = 0;
- attributes->colorTable = NULL;
- attributes->ncolors = 0;
-/* 3.2 backward compatibility code */
- attributes->hints_cmt = NULL;
- attributes->colors_cmt = NULL;
- attributes->pixels_cmt = NULL;
-/* end 3.2 bc */
- attributes->extensions = NULL;
- attributes->nextensions = 0;
- }
-}
-
-/*
- * Fill in the XpmAttributes with the XpmImage and the XpmInfo
- */
-void
-xpmSetAttributes(XpmAttributes *attributes, XpmImage *image, XpmInfo *info)
-{
- if (attributes->valuemask & XpmReturnColorTable) {
- attributes->colorTable = image->colorTable;
- attributes->ncolors = image->ncolors;
-
- /* avoid deletion of copied data */
- image->ncolors = 0;
- image->colorTable = NULL;
- }
-/* 3.2 backward compatibility code */
- else if (attributes->valuemask & XpmReturnInfos) {
- int ErrorStatus;
-
- ErrorStatus = CreateOldColorTable(image->colorTable, image->ncolors,
- (XpmColor ***)
- &attributes->colorTable);
-
- /* if error just say we can't return requested data */
- if (ErrorStatus != XpmSuccess) {
- attributes->valuemask &= ~XpmReturnInfos;
- if (!(attributes->valuemask & XpmReturnPixels)) {
- XpmFree(attributes->pixels);
- attributes->pixels = NULL;
- attributes->npixels = 0;
- }
- attributes->ncolors = 0;
- } else {
- attributes->ncolors = image->ncolors;
- attributes->hints_cmt = info->hints_cmt;
- attributes->colors_cmt = info->colors_cmt;
- attributes->pixels_cmt = info->pixels_cmt;
-
- /* avoid deletion of copied data */
- image->ncolors = 0;
- image->colorTable = NULL;
- info->hints_cmt = NULL;
- info->colors_cmt = NULL;
- info->pixels_cmt = NULL;
- }
- }
-/* end 3.2 bc */
- if (attributes->valuemask & XpmReturnExtensions) {
- attributes->extensions = info->extensions;
- attributes->nextensions = info->nextensions;
-
- /* avoid deletion of copied data */
- info->extensions = NULL;
- info->nextensions = 0;
- }
- if (info->valuemask & XpmHotspot) {
- attributes->valuemask |= XpmHotspot;
- attributes->x_hotspot = info->x_hotspot;
- attributes->y_hotspot = info->y_hotspot;
- }
- attributes->valuemask |= XpmCharsPerPixel;
- attributes->cpp = image->cpp;
- attributes->valuemask |= XpmSize;
- attributes->width = image->width;
- attributes->height = image->height;
-}
-
-/*
- * Free the XpmAttributes structure members
- * but the structure itself
- */
-void
-XpmFreeAttributes(XpmAttributes *attributes)
-{
- if (attributes->valuemask & XpmReturnPixels && attributes->npixels) {
- XpmFree(attributes->pixels);
- attributes->pixels = NULL;
- attributes->npixels = 0;
- }
- if (attributes->valuemask & XpmReturnColorTable) {
- xpmFreeColorTable(attributes->colorTable, attributes->ncolors);
- attributes->colorTable = NULL;
- attributes->ncolors = 0;
- }
-/* 3.2 backward compatibility code */
- else if (attributes->valuemask & XpmInfos) {
- if (attributes->colorTable) {
- FreeOldColorTable((XpmColor **) attributes->colorTable,
- attributes->ncolors);
- attributes->colorTable = NULL;
- attributes->ncolors = 0;
- }
- if (attributes->hints_cmt) {
- XpmFree(attributes->hints_cmt);
- attributes->hints_cmt = NULL;
- }
- if (attributes->colors_cmt) {
- XpmFree(attributes->colors_cmt);
- attributes->colors_cmt = NULL;
- }
- if (attributes->pixels_cmt) {
- XpmFree(attributes->pixels_cmt);
- attributes->pixels_cmt = NULL;
- }
- if (attributes->pixels) {
- XpmFree(attributes->pixels);
- attributes->pixels = NULL;
- attributes->npixels = 0;
- }
- }
-/* end 3.2 bc */
- if (attributes->valuemask & XpmReturnExtensions
- && attributes->nextensions) {
- XpmFreeExtensions(attributes->extensions, attributes->nextensions);
- attributes->extensions = NULL;
- attributes->nextensions = 0;
- }
- attributes->valuemask = 0;
-}
-
-/*
- * Init returned data to free safely later on
- */
-void
-xpmInitXpmImage(XpmImage *image)
-{
- image->ncolors = 0;
- image->colorTable = NULL;
- image->data = NULL;
-}
-
-/*
- * Free the XpmImage data which have been allocated
- */
-void
-XpmFreeXpmImage(XpmImage *image)
-{
- if (image->colorTable)
- xpmFreeColorTable(image->colorTable, image->ncolors);
- XpmFree(image->data);
- image->data = NULL;
-}
-
-/*
- * Init returned data to free safely later on
- */
-void
-xpmInitXpmInfo(XpmInfo *info)
-{
- if (info) {
- info->hints_cmt = NULL;
- info->colors_cmt = NULL;
- info->pixels_cmt = NULL;
- info->extensions = NULL;
- info->nextensions = 0;
- }
-}
-
-/*
- * Free the XpmInfo data which have been allocated
- */
-void
-XpmFreeXpmInfo(XpmInfo *info)
-{
- if (info) {
- if (info->valuemask & XpmComments) {
- if (info->hints_cmt) {
- XpmFree(info->hints_cmt);
- info->hints_cmt = NULL;
- }
- if (info->colors_cmt) {
- XpmFree(info->colors_cmt);
- info->colors_cmt = NULL;
- }
- if (info->pixels_cmt) {
- XpmFree(info->pixels_cmt);
- info->pixels_cmt = NULL;
- }
- }
- if (info->valuemask & XpmReturnExtensions && info->nextensions) {
- XpmFreeExtensions(info->extensions, info->nextensions);
- info->extensions = NULL;
- info->nextensions = 0;
- }
- info->valuemask = 0;
- }
-}
-
-/*
- * Set the XpmInfo valuemask to retrieve required info
- */
-void
-xpmSetInfoMask(XpmInfo *info, XpmAttributes *attributes)
-{
- info->valuemask = 0;
- if (attributes->valuemask & XpmReturnInfos)
- info->valuemask |= XpmReturnComments;
- if (attributes->valuemask & XpmReturnExtensions)
- info->valuemask |= XpmReturnExtensions;
-}
-
-/*
- * Fill in the XpmInfo with the XpmAttributes
- */
-void
-xpmSetInfo(XpmInfo *info, XpmAttributes *attributes)
-{
- info->valuemask = 0;
- if (attributes->valuemask & XpmInfos) {
- info->valuemask |= XpmComments | XpmColorTable;
- info->hints_cmt = attributes->hints_cmt;
- info->colors_cmt = attributes->colors_cmt;
- info->pixels_cmt = attributes->pixels_cmt;
- }
- if (attributes->valuemask & XpmExtensions) {
- info->valuemask |= XpmExtensions;
- info->extensions = attributes->extensions;
- info->nextensions = attributes->nextensions;
- }
- if (attributes->valuemask & XpmHotspot) {
- info->valuemask |= XpmHotspot;
- info->x_hotspot = attributes->x_hotspot;
- info->y_hotspot = attributes->y_hotspot;
- }
-}
-
+#include "XpmI.h"
#ifdef NEED_STRDUP
/*
* which does the trick
*/
char *
-strdup(char *s1)
+xpmstrdup(s1)
+ char *s1;
{
char *s2;
int l = strlen(s1) + 1;
if (s2 = (char *) XpmMalloc(l))
- strncpy(s2, s1, l);
+ strcpy(s2, s1);
return s2;
}
#endif
unsigned int
-atoui(register char *p, unsigned int l, unsigned int *ui_return)
+xpmatoui(p, l, ui_return)
+ register char *p;
+ unsigned int l;
+ unsigned int *ui_return;
{
register unsigned int n, i;
return 0;
}
-
/*
- * File / Buffer utilities
- */
-int
-XpmReadFileToBuffer(char *filename, char **buffer_return)
-{
- int fd, fcheck, len;
- char *ptr;
- struct stat stats;
- FILE *fp;
-
- *buffer_return = NULL;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return XpmOpenFailed;
-
- if (fstat(fd, &stats)) {
- close(fd);
- return XpmOpenFailed;
- }
- fp = fdopen(fd, "r");
- if (!fp) {
- close(fd);
- return XpmOpenFailed;
- }
- len = (int) stats.st_size;
- ptr = (char *) XpmMalloc(len + 1);
- if (!ptr) {
- fclose(fp);
- return XpmNoMemory;
- }
- fcheck = fread(ptr, len, 1, fp);
- fclose(fp);
- if (fcheck != 1) {
- XpmFree(ptr);
- return XpmOpenFailed;
- }
- ptr[len] = '\0';
- *buffer_return = ptr;
- return XpmSuccess;
-}
-
-int
-XpmWriteFileFromBuffer(char *filename, char *buffer)
-{
- int fcheck, len;
- FILE *fp = fopen(filename, "w");
-
- if (!fp)
- return XpmOpenFailed;
-
- len = strlen(buffer);
- fcheck = fwrite(buffer, len, 1, fp);
- fclose(fp);
- if (fcheck != 1)
- return XpmOpenFailed;
-
- return XpmSuccess;
-}
-
-
-/*
- * Small utility function
+ * Function returning a character string related to an error code.
*/
char *
-XpmGetErrorString(int errcode)
+XpmGetErrorString(errcode)
+ int errcode;
{
switch (errcode) {
case XpmColorError:
}
-#ifndef FOR_MSW
-void
-xpmCreatePixmapFromImage(Display *display, Drawable d, XImage *ximage, Pixmap *pixmap_return)
-{
- GC gc;
-
- *pixmap_return = XCreatePixmap(display, d, ximage->width,
- ximage->height, ximage->depth);
- gc = XCreateGC(display, *pixmap_return, 0, NULL);
-
- XPutImage(display, *pixmap_return, gc, ximage, 0, 0, 0, 0,
- ximage->width, ximage->height);
-
- XFreeGC(display, gc);
-}
+/* The following should help people wanting to use their own functions */
+#ifdef XpmFree
+#undef XpmFree
+#endif
void
-xpmCreateImageFromPixmap(Display *display, Pixmap pixmap, XImage **ximage_return, unsigned int *width, unsigned int *height)
+XpmFree(ptr)
+ void *ptr;
{
- unsigned int dum;
- int dummy;
- Window win;
-
- if (*width == 0 && *height == 0)
- XGetGeometry(display, pixmap, &win, &dummy, &dummy,
- width, height, &dum, &dum);
-
- *ximage_return = XGetImage(display, pixmap, 0, 0, *width, *height,
- AllPlanes, ZPixmap);
+ free(ptr);
}
-
-#endif /* FOR_MSW */
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
*/
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:ctype.h"
-#else
+#include "XpmI.h"
#include <ctype.h>
-#endif
-
-#ifdef sun
-#ifdef SVR4
-#define __ORIGINAL_XORG_CODE
-#include <X11/Xfuncs.h> /* bzero, bcopy */
-#endif
-#endif
-
-#include <string.h>
-#ifdef __sgi
-#include <bstring.h>
-#endif
-
-LFUNC(ParseValues, int, (xpmData *data, unsigned int *width,
- unsigned int *height, unsigned int *ncolors,
- unsigned int *cpp, unsigned int *x_hotspot,
- unsigned int *y_hotspot, unsigned int *hotspot,
- unsigned int *extensions));
-
-LFUNC(ParseColors, int, (xpmData *data, unsigned int ncolors, unsigned int cpp,
- XpmColor **colorTablePtr, xpmHashTable *hashtable));
LFUNC(ParsePixels, int, (xpmData *data, unsigned int width,
unsigned int height, unsigned int ncolors,
unsigned int cpp, XpmColor *colorTable,
xpmHashTable *hashtable, unsigned int **pixels));
-LFUNC(ParseExtensions, int, (xpmData *data, XpmExtension **extensions,
- unsigned int *nextensions));
-
char *xpmColorKeys[] = {
"s", /* key #1: symbol */
"m", /* key #2: mono visual */
"c", /* key #5: color visual */
};
-
-/* function call in case of error, frees only locally allocated variables */
-#undef RETURN
-#define RETURN(status) \
-{ \
- if (colorTable) xpmFreeColorTable(colorTable, ncolors); \
- if (pixelindex) XpmFree(pixelindex); \
- if (hints_cmt) XpmFree(hints_cmt); \
- if (colors_cmt) XpmFree(colors_cmt); \
- if (pixels_cmt) XpmFree(pixels_cmt); \
- return(status); \
-}
-
-/*
- * This function parses an Xpm file or data and store the found informations
- * in an an XpmImage structure which is returned.
- */
int
-xpmParseData(xpmData *data, XpmImage *image, XpmInfo *info)
-{
- /* variables to return */
- unsigned int width, height, ncolors, cpp;
- unsigned int x_hotspot, y_hotspot, hotspot = 0, extensions = 0;
- XpmColor *colorTable = NULL;
- unsigned int *pixelindex = NULL;
- char *hints_cmt = NULL;
- char *colors_cmt = NULL;
- char *pixels_cmt = NULL;
-
- unsigned int cmts;
- int ErrorStatus;
- xpmHashTable hashtable;
-
- cmts = info && (info->valuemask & XpmReturnComments);
-
- /*
- * parse the header
- */
- ErrorStatus = xpmParseHeader(data);
- if (ErrorStatus != XpmSuccess)
- return (ErrorStatus);
-
- /*
- * read values
- */
- ErrorStatus = ParseValues(data, &width, &height, &ncolors, &cpp,
- &x_hotspot, &y_hotspot, &hotspot, &extensions);
- if (ErrorStatus != XpmSuccess)
- return (ErrorStatus);
-
- /*
- * store the hints comment line
- */
- if (cmts)
- xpmGetCmt(data, &hints_cmt);
-
- /*
- * init the hastable
- */
- if (USE_HASHTABLE) {
- ErrorStatus = xpmHashTableInit(&hashtable);
- if (ErrorStatus != XpmSuccess)
- return (ErrorStatus);
- }
-
- /*
- * read colors
- */
- ErrorStatus = ParseColors(data, ncolors, cpp, &colorTable, &hashtable);
- if (ErrorStatus != XpmSuccess)
- RETURN(ErrorStatus);
-
- /*
- * store the colors comment line
- */
- if (cmts)
- xpmGetCmt(data, &colors_cmt);
-
- /*
- * read pixels and index them on color number
- */
- ErrorStatus = ParsePixels(data, width, height, ncolors, cpp, colorTable,
- &hashtable, &pixelindex);
-
- /*
- * free the hastable
- */
- if (USE_HASHTABLE)
- xpmHashTableFree(&hashtable);
-
- if (ErrorStatus != XpmSuccess)
- RETURN(ErrorStatus);
-
- /*
- * store the pixels comment line
- */
- if (cmts)
- xpmGetCmt(data, &pixels_cmt);
-
- /*
- * parse extensions
- */
- if (info && (info->valuemask & XpmReturnExtensions))
- if (extensions) {
- ErrorStatus = ParseExtensions(data, &info->extensions,
- &info->nextensions);
- if (ErrorStatus != XpmSuccess)
- RETURN(ErrorStatus);
- } else {
- info->extensions = NULL;
- info->nextensions = 0;
- }
-
- /*
- * store found informations in the XpmImage structure
- */
- image->width = width;
- image->height = height;
- image->cpp = cpp;
- image->ncolors = ncolors;
- image->colorTable = colorTable;
- image->data = pixelindex;
-
- if (info) {
- if (cmts) {
- info->hints_cmt = hints_cmt;
- info->colors_cmt = colors_cmt;
- info->pixels_cmt = pixels_cmt;
- }
- if (hotspot) {
- info->x_hotspot = x_hotspot;
- info->y_hotspot = y_hotspot;
- info->valuemask |= XpmHotspot;
- }
- }
- return (XpmSuccess);
-}
-
-static int
-ParseValues(xpmData *data, unsigned int *width, unsigned int *height, unsigned int *ncolors, unsigned int *cpp,
- unsigned int *x_hotspot, unsigned int *y_hotspot, unsigned int *hotspot, unsigned int *extensions)
+xpmParseValues(data, width, height, ncolors, cpp,
+ x_hotspot, y_hotspot, hotspot, extensions)
+ xpmData *data;
+ unsigned int *width, *height, *ncolors, *cpp;
+ unsigned int *x_hotspot, *y_hotspot, *hotspot;
+ unsigned int *extensions;
{
unsigned int l;
char buf[BUFSIZ];
*hotspot = (xpmNextUI(data, x_hotspot)
&& xpmNextUI(data, y_hotspot));
else {
- *hotspot = (atoui(buf, l, x_hotspot)
+ *hotspot = (xpmatoui(buf, l, x_hotspot)
&& xpmNextUI(data, y_hotspot));
l = xpmNextWord(data, buf, BUFSIZ);
*extensions = (l == 6 && !strncmp("XPMEXT", buf, 6));
*/
int i;
char *ptr;
+ Bool got_one, saw_width = False, saw_height = False;
+ Bool saw_ncolors = False, saw_chars_per_pixel = False;
for (i = 0; i < 4; i++) {
l = xpmNextWord(data, buf, BUFSIZ);
l = xpmNextWord(data, buf, BUFSIZ);
if (!l)
return (XpmFileInvalid);
- ptr = strchr(buf, '_');
- if (!ptr)
- return (XpmFileInvalid);
- switch (l - (ptr - buf)) {
- case 6:
- if (!strncmp("_width", ptr, 6) && !xpmNextUI(data, width))
- return (XpmFileInvalid);
- break;
- case 7:
- if (!strncmp("_height", ptr, 7) && !xpmNextUI(data, height))
+ buf[l] = '\0';
+ ptr = buf;
+ got_one = False;
+ while (!got_one) {
+ ptr = index(ptr, '_');
+ if (!ptr)
return (XpmFileInvalid);
- break;
- case 8:
- if (!strncmp("_ncolors", ptr, 8) && !xpmNextUI(data, ncolors))
- return (XpmFileInvalid);
- break;
- case 16:
- if (!strncmp("_chars_per_pixel", ptr, 16)
- && !xpmNextUI(data, cpp))
- return (XpmFileInvalid);
- break;
- default:
- return (XpmFileInvalid);
+ switch (l - (ptr - buf)) {
+ case 6:
+ if (saw_width || strncmp("_width", ptr, 6)
+ || !xpmNextUI(data, width))
+ return (XpmFileInvalid);
+ else
+ saw_width = True;
+ got_one = True;
+ break;
+ case 7:
+ if (saw_height || strncmp("_height", ptr, 7)
+ || !xpmNextUI(data, height))
+ return (XpmFileInvalid);
+ else
+ saw_height = True;
+ got_one = True;
+ break;
+ case 8:
+ if (saw_ncolors || strncmp("_ncolors", ptr, 8)
+ || !xpmNextUI(data, ncolors))
+ return (XpmFileInvalid);
+ else
+ saw_ncolors = True;
+ got_one = True;
+ break;
+ case 16:
+ if (saw_chars_per_pixel
+ || strncmp("_chars_per_pixel", ptr, 16)
+ || !xpmNextUI(data, cpp))
+ return (XpmFileInvalid);
+ else
+ saw_chars_per_pixel = True;
+ got_one = True;
+ break;
+ default:
+ ptr++;
+ }
}
/* skip the end of line */
xpmNextString(data);
}
+ if (!saw_width || !saw_height || !saw_ncolors || !saw_chars_per_pixel)
+ return (XpmFileInvalid);
+
*hotspot = 0;
*extensions = 0;
}
return (XpmSuccess);
}
-static int
-ParseColors(xpmData *data, unsigned int ncolors, unsigned int cpp, XpmColor **colorTablePtr, xpmHashTable *hashtable)
+int
+xpmParseColors(data, ncolors, cpp, colorTablePtr, hashtable)
+ xpmData *data;
+ unsigned int ncolors;
+ unsigned int cpp;
+ XpmColor **colorTablePtr;
+ xpmHashTable *hashtable;
{
unsigned int key, l, a, b;
unsigned int curkey; /* current color key */
}
static int
-ParsePixels(xpmData *data, unsigned int width, unsigned int height, unsigned int ncolors,
- unsigned int cpp, XpmColor *colorTable, xpmHashTable *hashtable, unsigned int **pixels)
+ParsePixels(data, width, height, ncolors, cpp, colorTable, hashtable, pixels)
+ xpmData *data;
+ unsigned int width;
+ unsigned int height;
+ unsigned int ncolors;
+ unsigned int cpp;
+ XpmColor *colorTable;
+ xpmHashTable *hashtable;
+ unsigned int **pixels;
{
unsigned int *iptr, *iptr2;
unsigned int a, x, y;
bzero((char *)colidx, 256 * sizeof(short));
for (a = 0; a < ncolors; a++)
- colidx[colorTable[a].string[0]] = a + 1;
+ colidx[(unsigned char)colorTable[a].string[0]] = a + 1;
for (y = 0; y < height; y++) {
xpmNextString(data);
for (x = 0; x < width; x++, iptr++) {
- int idx = colidx[xpmGetC(data)];
+ int c = xpmGetC(data);
- if (idx != 0)
- *iptr = idx - 1;
+ if (c > 0 && c < 256 && colidx[c] != 0)
+ *iptr = colidx[c] - 1;
else {
XpmFree(iptr2);
return (XpmFileInvalid);
return (XpmNoMemory);
}
}
- cidx[char1][colorTable[a].string[1]] = a + 1;
+ cidx[char1][(unsigned char)colorTable[a].string[1]] = a + 1;
}
for (y = 0; y < height; y++) {
xpmNextString(data);
for (x = 0; x < width; x++, iptr++) {
int cc1 = xpmGetC(data);
- int idx = cidx[cc1][xpmGetC(data)];
-
- if (idx != 0)
- *iptr = idx - 1;
- else {
+ if (cc1 > 0 && cc1 < 256) {
+ int cc2 = xpmGetC(data);
+ if (cc2 > 0 && cc2 < 256 &&
+ cidx[cc1] && cidx[cc1][cc2] != 0)
+ *iptr = cidx[cc1][cc2] - 1;
+ else {
+ FREE_CIDX;
+ XpmFree(iptr2);
+ return (XpmFileInvalid);
+ }
+ } else {
FREE_CIDX;
XpmFree(iptr2);
return (XpmFileInvalid);
return (XpmSuccess);
}
-static int
-ParseExtensions(xpmData *data, XpmExtension **extensions, unsigned int *nextensions)
+int
+xpmParseExtensions(data, extensions, nextensions)
+ xpmData *data;
+ XpmExtension **extensions;
+ unsigned int *nextensions;
{
XpmExtension *exts = NULL, *ext;
unsigned int num = 0;
*extensions = exts;
return (XpmSuccess);
}
+
+
+/* function call in case of error */
+#undef RETURN
+#define RETURN(status) \
+{ \
+ goto error; \
+}
+
+/*
+ * This function parses an Xpm file or data and store the found informations
+ * in an an XpmImage structure which is returned.
+ */
+int
+xpmParseData(data, image, info)
+ xpmData *data;
+ XpmImage *image;
+ XpmInfo *info;
+{
+ /* variables to return */
+ unsigned int width, height, ncolors, cpp;
+ unsigned int x_hotspot, y_hotspot, hotspot = 0, extensions = 0;
+ XpmColor *colorTable = NULL;
+ unsigned int *pixelindex = NULL;
+ char *hints_cmt = NULL;
+ char *colors_cmt = NULL;
+ char *pixels_cmt = NULL;
+
+ unsigned int cmts;
+ int ErrorStatus;
+ xpmHashTable hashtable;
+
+ cmts = info && (info->valuemask & XpmReturnComments);
+
+ /*
+ * parse the header
+ */
+ ErrorStatus = xpmParseHeader(data);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+
+ /*
+ * read values
+ */
+ ErrorStatus = xpmParseValues(data, &width, &height, &ncolors, &cpp,
+ &x_hotspot, &y_hotspot, &hotspot,
+ &extensions);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+
+ /*
+ * store the hints comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &hints_cmt);
+
+ /*
+ * init the hastable
+ */
+ if (USE_HASHTABLE) {
+ ErrorStatus = xpmHashTableInit(&hashtable);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+ }
+
+ /*
+ * read colors
+ */
+ ErrorStatus = xpmParseColors(data, ncolors, cpp, &colorTable, &hashtable);
+ if (ErrorStatus != XpmSuccess) {
+ if (USE_HASHTABLE)
+ xpmHashTableFree(&hashtable);
+ RETURN(ErrorStatus);
+ }
+
+ /*
+ * store the colors comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &colors_cmt);
+
+ /*
+ * read pixels and index them on color number
+ */
+ ErrorStatus = ParsePixels(data, width, height, ncolors, cpp, colorTable,
+ &hashtable, &pixelindex);
+
+ /*
+ * free the hastable
+ */
+ if (USE_HASHTABLE)
+ xpmHashTableFree(&hashtable);
+
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+
+ /*
+ * store the pixels comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &pixels_cmt);
+
+ /*
+ * parse extensions
+ */
+ if (info && (info->valuemask & XpmReturnExtensions))
+ if (extensions) {
+ ErrorStatus = xpmParseExtensions(data, &info->extensions,
+ &info->nextensions);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+ } else {
+ info->extensions = NULL;
+ info->nextensions = 0;
+ }
+
+ /*
+ * store found informations in the XpmImage structure
+ */
+ image->width = width;
+ image->height = height;
+ image->cpp = cpp;
+ image->ncolors = ncolors;
+ image->colorTable = colorTable;
+ image->data = pixelindex;
+
+ if (info) {
+ if (cmts) {
+ info->hints_cmt = hints_cmt;
+ info->colors_cmt = colors_cmt;
+ info->pixels_cmt = pixels_cmt;
+ }
+ if (hotspot) {
+ info->x_hotspot = x_hotspot;
+ info->y_hotspot = y_hotspot;
+ info->valuemask |= XpmHotspot;
+ }
+ }
+ return (XpmSuccess);
+
+/* exit point in case of error, free only locally allocated variables */
+error:
+ if (colorTable)
+ xpmFreeColorTable(colorTable, ncolors);
+ if (pixelindex)
+ XpmFree(pixelindex);
+ if (hints_cmt)
+ XpmFree(hints_cmt);
+ if (colors_cmt)
+ XpmFree(colors_cmt);
+ if (pixels_cmt)
+ XpmFree(pixels_cmt);
+
+ return(ErrorStatus);
+}
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* XpmRdFToData.c: *
+* RdFToDat.c: *
* *
* XPM library *
* Parse an XPM file and create an array of strings corresponding to it. *
* Developed by Dan Greening dgreen@cs.ucla.edu / dgreen@sti.com *
\*****************************************************************************/
-#include "xpm34p.h"
+#include "XpmI.h"
int
-XpmReadFileToData(char *filename, char ***data_return)
+XpmReadFileToData(filename, data_return)
+ char *filename;
+ char ***data_return;
{
XpmImage image;
XpmInfo info;
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* XpmRdFToI.c: *
+* RdFToI.c: *
* *
* XPM library *
* Parse an XPM file and create the image and possibly its mask *
* Developed by Arnaud Le Hors *
\*****************************************************************************/
-#include "xpm34p.h"
+#include "XpmI.h"
+#include <sys/stat.h>
+#if !defined(NO_ZPIPE) && defined(WIN32)
+# define popen _popen
+# define pclose _pclose
+# if defined(STAT_ZFILE)
+# include <io.h>
+# define stat _stat
+# define fstat _fstat
+# endif
+#endif
+LFUNC(OpenReadFile, int, (char *filename, xpmData *mdata));
+LFUNC(xpmDataClose, void, (xpmData *mdata));
+
+#ifndef CXPMPROG
int
-XpmReadFileToImage(Display *display, char *filename,
- XImage **image_return, XImage **shapeimage_return, XpmAttributes *attributes)
+XpmReadFileToImage(display, filename,
+ image_return, shapeimage_return, attributes)
+ Display *display;
+ char *filename;
+ XImage **image_return;
+ XImage **shapeimage_return;
+ XpmAttributes *attributes;
{
XpmImage image;
XpmInfo info;
int ErrorStatus;
+ xpmData mdata;
- /* create an XpmImage from the file */
+ xpmInitXpmImage(&image);
+ xpmInitXpmInfo(&info);
+
+ /* open file to read */
+ if ((ErrorStatus = OpenReadFile(filename, &mdata)) != XpmSuccess)
+ return (ErrorStatus);
+
+ /* create the XImage from the XpmData */
if (attributes) {
xpmInitAttributes(attributes);
xpmSetInfoMask(&info, attributes);
- ErrorStatus = XpmReadFileToXpmImage(filename, &image, &info);
+ ErrorStatus = xpmParseDataAndCreate(display, &mdata,
+ image_return, shapeimage_return,
+ &image, &info, attributes);
} else
- ErrorStatus = XpmReadFileToXpmImage(filename, &image, NULL);
-
- if (ErrorStatus != XpmSuccess)
- return (ErrorStatus);
-
- /* create the related ximages */
- ErrorStatus = XpmCreateImageFromXpmImage(display, &image,
- image_return, shapeimage_return,
- attributes);
+ ErrorStatus = xpmParseDataAndCreate(display, &mdata,
+ image_return, shapeimage_return,
+ &image, NULL, attributes);
if (attributes) {
if (ErrorStatus >= 0) /* no fatal error */
xpmSetAttributes(attributes, &image, &info);
XpmFreeXpmInfo(&info);
}
+
+ xpmDataClose(&mdata);
/* free the XpmImage */
XpmFreeXpmImage(&image);
}
int
-XpmReadFileToXpmImage(char *filename, XpmImage *image, XpmInfo *info)
+XpmReadFileToXpmImage(filename, image, info)
+ char *filename;
+ XpmImage *image;
+ XpmInfo *info;
{
xpmData mdata;
int ErrorStatus;
xpmInitXpmInfo(info);
/* open file to read */
- if ((ErrorStatus = xpmReadFile(filename, &mdata)) != XpmSuccess)
+ if ((ErrorStatus = OpenReadFile(filename, &mdata)) != XpmSuccess)
return (ErrorStatus);
/* create the XpmImage from the XpmData */
return (ErrorStatus);
}
+#endif /* CXPMPROG */
+
+/*
+ * open the given file to be read as an xpmData which is returned.
+ */
+static int
+OpenReadFile(filename, mdata)
+ char *filename;
+ xpmData *mdata;
+{
+#ifndef NO_ZPIPE
+ char *compressfile, buf[BUFSIZ];
+# ifdef STAT_ZFILE
+ struct stat status;
+# endif
+#endif
+
+ if (!filename) {
+ mdata->stream.file = (stdin);
+ mdata->type = XPMFILE;
+ } else {
+#ifndef NO_ZPIPE
+ int len = strlen(filename);
+ if ((len > 2) && !strcmp(".Z", filename + (len - 2))) {
+ mdata->type = XPMPIPE;
+ sprintf(buf, "uncompress -c \"%s\"", filename);
+ if (!(mdata->stream.file = popen(buf, "r")))
+ return (XpmOpenFailed);
+
+ } else if ((len > 3) && !strcmp(".gz", filename + (len - 3))) {
+ mdata->type = XPMPIPE;
+ sprintf(buf, "gunzip -qc \"%s\"", filename);
+ if (!(mdata->stream.file = popen(buf, "r")))
+ return (XpmOpenFailed);
+
+ } else {
+# ifdef STAT_ZFILE
+ if (!(compressfile = (char *) XpmMalloc(len + 4)))
+ return (XpmNoMemory);
+
+ sprintf(compressfile, "%s.Z", filename);
+ if (!stat(compressfile, &status)) {
+ sprintf(buf, "uncompress -c \"%s\"", compressfile);
+ if (!(mdata->stream.file = popen(buf, "r"))) {
+ XpmFree(compressfile);
+ return (XpmOpenFailed);
+ }
+ mdata->type = XPMPIPE;
+ } else {
+ sprintf(compressfile, "%s.gz", filename);
+ if (!stat(compressfile, &status)) {
+ sprintf(buf, "gunzip -c \"%s\"", compressfile);
+ if (!(mdata->stream.file = popen(buf, "r"))) {
+ XpmFree(compressfile);
+ return (XpmOpenFailed);
+ }
+ mdata->type = XPMPIPE;
+ } else {
+# endif
+#endif
+ if (!(mdata->stream.file = fopen(filename, "r"))) {
+#if !defined(NO_ZPIPE) && defined(STAT_ZFILE)
+ XpmFree(compressfile);
+#endif
+ return (XpmOpenFailed);
+ }
+ mdata->type = XPMFILE;
+#ifndef NO_ZPIPE
+# ifdef STAT_ZFILE
+ }
+ }
+ XpmFree(compressfile);
+# endif
+ }
+#endif
+ }
+ mdata->CommentLength = 0;
+#ifdef CXPMPROG
+ mdata->lineNum = 0;
+ mdata->charNum = 0;
+#endif
+ return (XpmSuccess);
+}
+
+/*
+ * close the file related to the xpmData if any
+ */
+static void
+xpmDataClose(mdata)
+ xpmData *mdata;
+{
+ switch (mdata->type) {
+ case XPMFILE:
+ if (mdata->stream.file != (stdin))
+ fclose(mdata->stream.file);
+ break;
+#ifndef NO_ZPIPE
+ case XPMPIPE:
+ pclose(mdata->stream.file);
+ break;
+#endif
+ }
+}
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-/*****************************************************************************\
-* XpmRdFToP.c: *
-* *
-* XPM library *
-* Parse an XPM file and create the pixmap and possibly its mask *
-* *
-* Developed by Arnaud Le Hors *
-\*****************************************************************************/
-
-#ifndef FOR_MSW
-
-#include "xpm34p.h"
-
-int
-XpmReadFileToPixmap(Display *display, Drawable d, char *filename, Pixmap *pixmap_return,
- Pixmap *shapemask_return, XpmAttributes *attributes)
-{
- XImage *ximage, *shapeimage;
- int ErrorStatus;
-
- /* initialize return values */
- if (pixmap_return)
- *pixmap_return = 0;
- if (shapemask_return)
- *shapemask_return = 0;
-
- /* create the images */
- ErrorStatus = XpmReadFileToImage(display, filename,
- (pixmap_return ? &ximage : NULL),
- (shapemask_return ? &shapeimage : NULL),
- attributes);
-
- if (ErrorStatus < 0) /* fatal error */
- return (ErrorStatus);
-
- /* create the pixmaps and destroy images */
- if (pixmap_return && ximage) {
- xpmCreatePixmapFromImage(display, d, ximage, pixmap_return);
- XDestroyImage(ximage);
- }
- if (shapemask_return && shapeimage) {
- xpmCreatePixmapFromImage(display, d, shapeimage, shapemask_return);
- XDestroyImage(shapeimage);
- }
- return (ErrorStatus);
-}
-#endif
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-
- XPM Version 3
-
-WHAT IS XPM?
-============
-
-XPM (X PixMap) is a format for storing/retrieving X pixmaps to/from files.
-
-Here is provided a library containing a set of four functions, similar to the
-X bitmap functions as defined in the Xlib: XpmCreatePixmapFromData,
-XpmCreateDataFromPixmap, XpmReadFileToPixmap and XpmWriteFileFromPixmap for
-respectively including, storing, reading and writing this format, plus four
-other: XpmCreateImageFromData, XpmCreateDataFromImage, XpmReadFileToImage and
-XpmWriteFileFromImage for working with images instead of pixmaps.
-
-This new version provides a C includable format, defaults for different types
-of display: monochrome/color/grayscale, hotspot coordinates and symbol names
-for colors for overriding default colors when creating the pixmap. It provides
-a mechanism for storing information while reading a file which is re-used
-while writing. This way comments, default colors and symbol names aren't lost.
-It also handles "transparent pixels" by returning a shape mask in addition to
-the created pixmap.
-
-See the XPM Manual for more details.
-
-HOW TO GET XPM?
-===============
-
-New xpm updates are announced on the comp.windows.x newsgroup, and on the
-"xpm-talk" list. All new "official" xpm releases can be found by ftp on:
-
- ftp.x.org (18.112.44.100) contrib (Boston, USA)
- avahi.inria.fr (192.5.60.47) pub (Sophia Antipolis, France)
-
-
-DOCUMENTATION:
-=============
-
-Old users might read the CHANGES file for a history of changes interesting
-the user.
-
-Read the doc. The documentation is in PostScript format (file doc/xpm.ps) and
-has been produced with FrameMaker. The source files are available on request.
-
-
-INSTALLATION:
-============
-
-To obtain the XPM library, first uncompress and untar the compressed tar file
-in an approriate directory.
-
-Then you can either compile xpm via "imake" or in a stand-alone way.
-
-WITH IMAKE:
-
- Imakefiles are provided to build both shared and unshared libraries.
- First have a look at the beginning of the lib/Imakefile and see if you
- need to do some modification to fit with your system.
- You should know how to use imake to build the XPM Makefiles
- by executing "xmkmf", then do:
-
- make Makefiles
- make depend (if you want to)
- make
-
- which will build the XPM library and the sxpm application.
- Then do:
-
- make install
- make install.man
-
- which will install the library and the sxpm pregram and man page.
-
- If it fails, you may edit the Imakefiles to add compilation flags to
- suit your machine.
-
-WITHOUT IMAKE:
-
- To compile xpm, in the xpm directory you just created, do:
-
- make -f Makefile.noXtree
-
- Then to install it, do:
-
- make -f Makefile.noXtree install
-
-SXPM:
-====
-
-In addition to the library the sxpm tool is provided to show XPM file and
-convert them from XPM1 or XPM2 to XPM version 3. If you have previously done
-'make' or 'make all' you should have it yet, otherwise just do:
-
- cd sxpm; make
-
-This application shows you most of the features of XPM and its source can be
-used to quickly see how to use the provided functions.
-
-By executing 'sxpm -help' you will get the usage.
-
-Executing 'sxpm -plaid' will show a demo of the XpmCreatePixmapFromData
-function. The pixmap is created from the static variable plaid defined in the
-sxpm.c file. sxpm will end when you press the key 'q' in the created window.
-
-Executing 'sxpm -plaid -sc lines_in_mix blue' will show the feature of
-overriding color symbols giving a colorname, executing 'sxpm -sp lines_in_mix
-1' will show overriding giving a pixel value, and executing 'sxpm -plaid -cp
-red 0' will show overriding giving a color value.
-
-Then you should try 'sxpm -plaid -o output' to get an output file using the
-XpmWriteFileFromPixmap function.
-
-You can now try 'sxpm -plaid -o - -nod -rgb /usr/lib/X11/rgb.txt' to directly
-get the pixmap printed out on the standard output with colornames instead of
-rgb values.
-
-Then you should try 'sxpm plaid.xpm' to use the XpmReadFileToPixmap function,
-and 'cat plaid_mask.xpm|sxpm' to see how "transparent pixels" are handled.
-
-The XpmCreatePixmapFromData function is on purpose called without any XpmInfos
-flag to show the utility of this one. Indeed, compare the color section of the
-two files foo and bar obtained from 'sxpm -nod -plaid -o foo' and 'sxpm -nod
-plaid.xpm -o bar'. All the default colors and also the comments have been
-restored.
-
-To end look at plaid_ext.xpm and try "sxpm -nod plaid_ext.xpm -v" to see how
-extensions are handled.
-
-Of course, other combinations are allowed and should be tried. Thus, 'sxpm
-plaid.xpm -o output -nod' will show you how to convert a file from XPM1 or XPM2
-to a XPM version 3 using sxpm.
-
-See the manual page for more detail.
-
-OTHER TOOLS:
-===========
-
-Several converters dealing with XPM and a pixmap editor can be found in the
-xpm-contrib distribution. Also I recommend the use of netpbm to do any kind of
-general image operations such as scaling, resizing, dithering, and to convert
-from and to any other image format.
-
-DISCUSSION:
-==========
-
-There is a mailing list to discuss about XPM which is xpm-talk@sophia.inria.fr.
-Any request to subscribe should be sent to xpm-talk-request@sophia.inria.fr.
-
-COPYRIGHT:
-==========
-
- Copyright 1989-94 GROUPE BULL --
- See license conditions in the COPYRIGHT file of the XPM distribution
-
-Please mail any bug reports or modifications done, comments, suggestions,
-requests for updates or patches to port on another machine to:
-
-lehors@sophia.inria.fr (INTERNET)
-
-33 (FRANCE) 93.65.77.71 (VOICE PHONE)
-
-Arnaud Le Hors (SURFACE MAIL)
-Bull c/o Inria BP. 109
-2004, Route des lucioles
-Sophia Antipolis
-06561 Valbonne Cedex
-FRANCE
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html lang="en">
+<HEAD>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<TITLE>XPM README</TITLE>
+</HEAD>
+
+<body>
+<h1 align="center">XPM README</h1>
+
+<h2>Contents</h2>
+
+<ol>
+<li><a href="#sec1">What Is XPM?</a>
+<li><a href="#sec2">Where to get XPM?</a>
+<li><a href="#sec3">Documentation</a>
+<li><a href="#sec4">Installation</a>
+<ol>
+<li><a href="#sec4.1">With imake</a>
+<li><a href="#sec4.2">Without imake</a>
+</ol>
+<li><a href="#sec5">SXPM</a>
+<li><a href="#sec6">CXPM</a>
+<li><a href="#sec7">Other Tools</a>
+<li><a href="#sec8">Discussion</a>
+<li><a href="#copy">Copyright</a>
+</ol>
+
+
+<h2><a name="sec1">1. What Is XPM?</a></h2>
+<p>
+XPM (X PixMap) is a format for storing/retrieving X pixmaps to/from files.
+<p>
+Here is provided a library containing a set of four functions, similar to the
+X bitmap functions as defined in the Xlib: <code>XpmCreatePixmapFromData</code>,
+<code>XpmCreateDataFromPixmap</code>, <code>XpmReadFileToPixmap</code> and <code>XpmWriteFileFromPixmap</code> for
+respectively including, storing, reading and writing this format, plus four
+other: <code>XpmCreateImageFromData</code>, <code>XpmCreateDataFromImage</code>, <code>XpmReadFileToImage</code> and
+<code>XpmWriteFileFromImage</code> for working with images instead of pixmaps.
+<p>
+This new version provides a C includable format, defaults for different types
+of display: monochrome/color/grayscale, hotspot coordinates and symbol names
+for colors for overriding default colors when creating the pixmap. It provides
+a mechanism for storing information while reading a file which is re-used
+while writing. This way comments, default colors and symbol names aren't lost.
+It also handles "transparent pixels" by returning a shape mask in addition to
+the created pixmap.
+<p>
+See the XPM Manual for details.
+
+
+<h2><a name="sec2">2. Where to get XPM?</a></h2>
+<p>
+New XPM updates are announced on the comp.windows.x newsgroup, and on the
+"xpm-talk" list and you can always consult the XPM Home page at <a
+href="http://www.inria.fr/koala/lehors/xpm.html">http://www.inria.fr/koala/lehors/xpm.html</a>
+<p>The latest "official" XPM release can always be found at:
+<br>Boston, USA: <a
+href="ftp://ftp.x.org/contrib">ftp://ftp.x.org/contrib</a>
+<br>Sophia Antipolis, France: <a
+href="ftp://koala.inria.fr/pub/xpm">ftp://koala.inria.fr/pub/xpm</a>
+
+
+<h2><a name="sec3">3. Documentation</a></h2>
+<p>
+Old users might read the <a href="CHANGES">CHANGES</a> file for a history
+of changes interesting the user.
+<p>
+Read the doc. The documentation is in PostScript format (<a
+href="doc/xpm.PS">doc/xpm.PS</a>) and has been produced with
+FrameMaker. The source files are available on request.
+<p>
+A <a href="FAQ.html">FAQ</a> (Frequently Asked Questions) is also provided,
+so if you experience any problem you should have a look at this file.
+
+
+<h2><a name="sec4">4. Installation</a></h2>
+<p>
+To obtain the XPM library, first uncompress and untar the compressed tar file
+in an appropriate directory.
+<p>
+Then you can either compile XPM via "imake" or in a stand-alone way.
+
+<h3><a name="sec4.1">4.1. With imake</a></h3>
+<p>
+ Imakefiles are provided to build both shared and unshared libraries.
+ However, building a shared lib is very OS dependent and often requires
+ specific files which are not available. Also config files are often not
+ set correctly for this task. So if it fails you can avoid trying to
+ build one and simply build the static library instead. In order to do
+ so you should edit the top Imakefile to add -DSharedLibXpm=NO to the
+ definition of IMAKE_DEFINES as described.
+<p>
+ The compilation and installation of the library and the sxpm program
+ should only require you to edit the top Imakefile. But you should do so
+ in order to specify the locations where the various files should be
+ installed and to set the DEFINES variable accordingly to your system.
+<p>
+ On Solaris 2.* the compilation works only in the native svr4
+ environment, avoid the bsd one or it won't compile. Especially you
+ should be using /opt/SUNWspro/bin/cc and not /usr/ucb/cc.
+ Also since the compiler is no longer part of the OS distribution a lot
+ of people use gcc instead. This is fine, but be aware that the imake
+ tool you get as part of the X Window System on a solaris box is
+ configured for cc. Therefore the compilation using the generated
+ Makefiles will not succeed unless you have changed the default
+ configuration. An easy work around is to directly edit the generated
+ lib/Makefile to change '-K pic' to '-fpic'. Fixing your imake
+ configuration would be better though.
+<p>
+ On Linux, if you do not use ELF yet you'd better get the binary
+ distribution available from sunsite. Because it's really a pain to
+ build a shared lib and the current XPM distribution doesn't contain
+ the jump files you would need to do so. On the other hand people have
+ had no problems building it using ELF.
+<p>
+ Then execute the following command:
+<pre>
+ xmkmf -a
+</pre>
+<p>
+ or if this option is not supported by your version of xmkmf:
+<pre>
+ xmkmf
+ make Makefiles
+ make includes
+ make depend (optional)
+</pre>
+<p>
+ Then simply execute:
+<pre>
+ make
+</pre>
+<p>
+ which will build the XPM library and the sxpm application.
+ Then do:
+<pre>
+ make install
+ make install.man
+</pre>
+<p>
+ which will install the library and the sxpm program and man page.
+<p>
+ If it fails, be sure you have set the DEFINES correctly in the top
+ Imakefile to suit your machine.
+
+<h4>NOTE ON USING IMAKE:</h4>
+<p>
+ Building the XPM distribution with imake requires to have imake
+ <strong>correctly installed and configured</strong> on your
+ system. I do my best at tweaking the Imakefiles so they work with
+ as many imake flavors people might have as possible but there is
+ nothing I can do against wrong imake configurations. So if your
+ build fails using imake, don't send me email for advice. Get your
+ imake configuration fixed or forget about it!
+
+
+<h3><a name="sec4.2">4.2. Without imake</a></h3>
+<p>
+ A set of makefiles is provided for those who do not have imake
+ available on their system. However, this is only provided as a
+ convenience and you should be considered as a starting point and not as
+ something ready to use. These makefiles, called Makefile.noX, will most
+ likely require some editing in order be set accordingly to your system.
+<p>
+ Once this setting is done, you should be able to compile XPM, by
+ executing the following command:
+<pre>
+ make -f Makefile.noX
+</pre>
+<p>
+ Then to install it, do:
+<pre>
+ make -f Makefile.noX install
+</pre>
+
+
+<h2><a name="sec5">5. SXPM</a></h2>
+<p>
+In addition to the library the sxpm tool is provided to show XPM file and
+convert them from XPM1 or XPM2 to XPM version 3. If you have previously done
+'make' or 'make all' you should already have it, otherwise just do:
+<pre>
+ cd sxpm; make
+</pre>
+<p>
+This application shows you most of the features of XPM and its source can be
+used to quickly see how to use the provided functions.
+<p>
+By executing 'sxpm -help' you will get the usage.
+<p>
+Executing 'sxpm -plaid' will show a demo of the XpmCreatePixmapFromData
+function. The pixmap is created from the static variable plaid defined in the
+sxpm.c file. sxpm will end when you press the key 'q' in the created window.
+<p>
+Executing 'sxpm -plaid -sc lines_in_mix blue' will show the feature of
+overriding color symbols giving a colorname, executing 'sxpm -plaid -sp
+lines_in_mix 1' will show overriding giving a pixel value, and executing 'sxpm
+-plaid -cp red 0' will show overriding giving a color value.
+<p>
+Then you should try 'sxpm -plaid -o output' to get an output file using the
+XpmWriteFileFromPixmap function.
+<p>
+You can now try 'sxpm -plaid -o - -nod -rgb /usr/lib/X11/rgb.txt' to directly
+get the pixmap printed out on the standard output with colornames instead of
+rgb values.
+<p>
+Then you should try 'sxpm plaid.xpm' to use the XpmReadFileToPixmap function,
+and 'cat plaid_mask.xpm|sxpm' to see how "transparent pixels" are handled.
+<p>
+The XpmCreatePixmapFromData function is on purpose called without any XpmInfos
+flag to show the utility of this one. Indeed, compare the color section of the
+two files foo and bar obtained from 'sxpm -nod -plaid -o foo' and 'sxpm -nod
+plaid.xpm -o bar'. All the default colors and also the comments have been
+restored.
+<p>
+To end look at plaid_ext.xpm and try "sxpm -nod plaid_ext.xpm -v" to see how
+extensions are handled.
+<p>
+Of course, other combinations are allowed and should be tried. Thus, 'sxpm
+plaid.xpm -o output -nod' will show you how to convert a file from XPM1 or XPM2
+to a XPM version 3 using sxpm.
+<p>
+See the manual page for more detail.
+
+
+<h2><a name="sec6">6. CXPM</a></h2>
+<p>
+The cxpm tool is provided to help you figure out whether an XPM file is correct
+or not with regard to its format. If you have previously done 'make' or
+'make all' you should already have it, otherwise just do:
+<pre>
+ cd cxpm; make
+</pre>
+<p>
+The related man page will tell you everything about it but here is a simple
+example of what it does:
+<pre>
+$ ./cxpm bogus_pixmap
+Xpm Error: Invalid XPM file.
+Error found line 3 near character 5
+</pre>
+<p>
+It is pretty limited but at least, unlike sxpm, it gives you some hint on where
+the error occured within the file.
+
+
+<h2><a name="sec7">7. Other Tools</a></h2>
+<p>
+Several converters dealing with XPM and a pixmap editor can be found in the
+xpm-contrib distribution. Also I recommend the use of netpbm to do any kind of
+general image operations such as scaling, resizing, dithering, and to convert
+from and to any other image format.
+
+<h2><a name="sec8">8. Discussion</a></h2>
+<p>
+There is a mailing list to discuss about XPM which is <a
+href="mailto:xpm-talk@sophia.inria.fr">xpm-talk@sophia.inria.fr</a>.
+Any request to subscribe should be sent to <a
+href="mailto:xpm-talk-request@sophia.inria.fr">xpm-talk-request@sophia.inria.fr</a>.
+The archive of the xpm-talk list is available through the web at
+<a
+href="http://zenon.inria.fr/koala/xpm-talk-hypermail">http://zenon.inria.fr/koala/xpm-talk-hypermail</a>
+and through ftp at <a
+href="ftp://koala.inria.fr/pub/xpm/xpm-talk-archive">ftp://koala.inria.fr/pub/xpm/xpm-talk-archive</a>
+<p>
+Please mail any bug reports or modifications done, comments, suggestions,
+requests for updates or patches to port on another machine to:
+
+<p>Email: <a href="lehors@sophia.inria.fr">lehors@sophia.inria.fr</a>
+<br>Phone: +33 (0)4 93 65 78 89
+<br>Surface Mail:<br>
+Arnaud Le Hors<br>
+Inria BP.93<br>
+2004, Route des lucioles<br>
+06902 Sophia Antipolis Cedex<br>
+FRANCE
+
+
+<hr>
+<h2><a name="copy">Copyright (C) 1989-95 GROUPE BULL</a></h2>
+<p>
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+<p>
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+<p>
+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
+GROUPE BULL 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.
+<p>
+Except as contained in this notice, the name of GROUPE BULL shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from GROUPE BULL.
+</body>
Motivated by the wxWindows library, which is a (freely available) toolkit
for developing multi-platform, graphical applications from the same body
-of C++ code,I wanted to have XPM pixmaps for MS-windows. Instead of rewriting
+of C++ code, I wanted to have XPM pixmaps for MS-windows. Instead of rewriting
a XPM-parser I managed to port the XPM-library-code to MS-windows.
-Thanks to Anaud Le Hors this became a part of the official XPM-library.
+Thanks to Anaud Le Hors this became a part of the official XPM-library.
Until now it's only used together with wxWindows. And even there it's more
a kind of beta. But it should be possible to run it as a simple libxpm.a
INSTALLATION:
There is not yet a makefile with it. Simply take all the *.c files
-into your project.
+into your project except the files related to Pixmap operations: *P*.c.
!!!You MUST set FOR_MSW on the preprocessor options!!!
(You might uncomment NEED_STRCASECMP in xpm.h if it's in your lib)
This should compile into libxpm.a. Good luck...
Please contact me if you have suggestions, comments or problems!
+================================================================
+Some fixes and comments by Jan Wielemaker (jan@swi.psy.uva.nl),
+Oct 24, 1996:
+
+ * Please try not to disturb me on this, XPM is not my
+ piece of cake.
+
+ * Hermann Dunkel has appearently moved in virtual space.
+
+Changes:
+
+ * I've used the xpm package under NT 4.0 and MSVC++ 4.2.
+
+ * I've made a big performance improvement in
+ ParseAndPutPixels(), fixed creation of the mask in
+ SetColor() in create.c. I looked into XCreateImage()
+ in simx.c, but commented out my improvement for reasons
+ you'll find there. If you know what is going on, statement
+ (1) does not apply to you.
+
+Comments on installation:
+
+ * Donot include the to/from pixmap files into the project.
+ These are the ones containing a capital P somewhere in their
+ name. You can also first include all, and then remove all
+ the files you get errors on :-)
+
+ * The DC that is requested should be a valid memory DC, thus
+ CreateCompatibleDC(NULL) provides a good generic one, but
+ GetDC(NULL) doesn't! This costed me some time.
+
+ * The real difficulty is using the mask, mostly due to the
+ bad documentation. If 95 or NT is your target, use:
+
+ MaskBlt(context.hdc, // Destination DC
+ x, y, w, h, // Destination area
+ mhdc, // Memory DC with the image selected
+ sx, sy, // Source X,Y
+ msk, // HBITMAP of the mask
+ sx, sy, // Mask X,Y
+ MAKEROP4(SRCPAINT, SRCCOPY)); // The magic op code.
+================================================================
+
+
--
////|\\\\ \\\\\\ Hermann Dunkel
O O ////// IPN Uni Kiel, Germany
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* W. Snitily but has been modified for my special need
*/
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:ctype.h"
-#include "sys$library:string.h"
-#else
+#include "XpmI.h"
#include <ctype.h>
-#if defined(SYSV) || defined(SVR4)
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#endif
#ifndef FOR_MSW /* normal part first, MSW part at
* the end, (huge ifdef!) */
* number of entries stored.
*/
int
-xpmReadRgbNames(char *rgb_fname, xpmRgbName rgbn[])
+xpmReadRgbNames(rgb_fname, rgbn)
+ char *rgb_fname;
+ xpmRgbName rgbn[];
+
{
FILE *rgbf;
- int i, items, red, green, blue;
- char line[512], name[512], *rgbname, *n, *m;
+ int n, items, red, green, blue;
+ char line[512], name[512], *rgbname, *s1, *s2;
xpmRgbName *rgb;
/* Open the rgb text file. Abort if error. */
return 0;
/* Loop reading each line in the file. */
- for (i = 0, rgb = rgbn; fgets(line, sizeof(line), rgbf); i++, rgb++) {
+ n = 0;
+ rgb = rgbn;
+ /* Quit if rgb text file has too many entries. */
+ while (fgets(line, sizeof(line), rgbf) && n < MAX_RGBNAMES) {
- /* Quit if rgb text file is too large. */
- if (i == MAX_RGBNAMES) {
- /* Too many entries in rgb text file, give up here */
- break;
- }
- /* Read the line. Skip silently if bad. */
+ /* Skip silently if line is bad. */
items = sscanf(line, "%d %d %d %[^\n]\n", &red, &green, &blue, name);
- if (items != 4) {
- i--;
+ if (items != 4)
continue;
- }
/*
* Make sure rgb values are within 0->255 range. Skip silently if
*/
if (red < 0 || red > 0xFF ||
green < 0 || green > 0xFF ||
- blue < 0 || blue > 0xFF) {
- i--;
+ blue < 0 || blue > 0xFF)
continue;
- }
+
/* Allocate memory for ascii name. If error give up here. */
if (!(rgbname = (char *) XpmMalloc(strlen(name) + 1)))
break;
/* Copy string to ascii name and lowercase it. */
- for (n = name, m = rgbname; *n; n++)
- *m++ = tolower(*n);
- *m = '\0';
+ for (s1 = name, s2 = rgbname; *s1; s1++)
+ *s2++ = tolower(*s1);
+ *s2 = '\0';
/* Save the rgb values and ascii name in the array. */
rgb->r = red * 257; /* 65535/255 = 257 */
rgb->g = green * 257;
rgb->b = blue * 257;
rgb->name = rgbname;
+ rgb++;
+ n++;
}
fclose(rgbf);
/* Return the number of read rgb names. */
- return i < 0 ? 0 : i;
+ return n < 0 ? 0 : n;
}
/*
* Return the color name corresponding to the given rgb values
*/
char *
-xpmGetRgbName(xpmRgbName rgbn[], int rgbn_max, int red, int green, int blue)
-/* xpmRgbName rgbn[]; */ /* rgb mnemonics from rgb text file */
-/* int rgbn_max; */ /* number of rgb mnemonics in table */
-/* int red, green, blue; */ /* rgb values */
+xpmGetRgbName(rgbn, rgbn_max, red, green, blue)
+ xpmRgbName rgbn[]; /* rgb mnemonics from rgb text file */
+ int rgbn_max; /* number of rgb mnemonics in table */
+ int red, green, blue; /* rgb values */
{
int i;
* Free the strings which have been malloc'ed in xpmReadRgbNames
*/
void
-xpmFreeRgbNames(xpmRgbName rgbn[], int rgbn_max)
+xpmFreeRgbNames(rgbn, rgbn_max)
+ xpmRgbName rgbn[];
+ int rgbn_max;
+
{
int i;
xpmRgbName *rgb;
#include "rgbtab.h" /* hard coded rgb.txt table */
int
-xpmReadRgbNames(char *rgb_fname, xpmRgbName rgbn[])
+xpmReadRgbNames(rgb_fname, rgbn)
+ char *rgb_fname;
+ xpmRgbName rgbn[];
{
/*
* check for consistency???
* which has something like #0303 for one color
*/
char *
-xpmGetRgbName(xpmRgbName rgbn[], int rgbn_max, int red, int green, int blue)
-/* xpmRgbName rgbn[]; */ /* rgb mnemonics from rgb text file
+xpmGetRgbName(rgbn, rgbn_max, red, green, blue)
+ xpmRgbName rgbn[]; /* rgb mnemonics from rgb text file
* not used */
-/* int rgbn_max; */ /* not used */
-/* int red, green, blue; */ /* rgb values */
+ int rgbn_max; /* not used */
+ int red, green, blue; /* rgb values */
{
int i;
i = 0;
while (i < numTheRGBRecords) {
rgbVal = theRGBRecords[i].rgb;
-#if !defined(__VISAGECPP__)
if (GetRValue(rgbVal) == red &&
GetGValue(rgbVal) == green &&
GetBValue(rgbVal) == blue)
return (theRGBRecords[i].name);
-#endif
i++;
}
return (NULL);
/* used in XParseColor in simx.c */
int
-xpmGetRGBfromName(char *inname, int *r, int *g, int *b)
+xpmGetRGBfromName(inname, r, g, b)
+ char *inname;
+ int *r, *g, *b;
{
int left, right, middle;
int cmp;
char *name;
char *grey, *p;
- name = strdup(inname);
+ name = xpmstrdup(inname);
/*
* the table in rgbtab.c has no names with spaces, and no grey, but a
right = numTheRGBRecords - 1;
do {
middle = (left + right) / 2;
- cmp = strcasecmp(name, theRGBRecords[middle].name);
+ cmp = xpmstrcasecmp(name, theRGBRecords[middle].name);
if (cmp == 0) {
rgbVal = theRGBRecords[middle].rgb;
-#if !defined(__VISAGECPP__)
*r = GetRValue(rgbVal);
*g = GetGValue(rgbVal);
*b = GetBValue(rgbVal);
-#endif
free(name);
return (1);
} else if (cmp < 0) {
}
void
-xpmFreeRgbNames(xpmRgbName rgbn[], int rgbn_max)
+xpmFreeRgbNames(rgbn, rgbn_max)
+ xpmRgbName rgbn[];
+ int rgbn_max;
+
{
/* nothing to do */
}
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
#define myRGB(r,g,b) \
((unsigned long)r<<16|(unsigned long)g<<8|(unsigned long)b)
*/
-
-/* Need an RBG conversion confunction here for OS/2 */
-#if defined(__VISAGECPP__)
-/* Bogus stuff to make it compile for now */
-static rgbRecord theRGBRecords[] = { {"AliceBlue", 0L}, {"AntiqueWhite", 1L}, NULL };
-static int numTheRGBRecords = 2;
-#else
#define myRGB(r,g,b) RGB(r,g,b) /* MSW has this macro */
};
static int numTheRGBRecords = 234;
-#endif
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
*/
-#include "xpm34p.h"
+/*
+ * The code related to AMIGA has been added by
+ * Lorens Younes (d93-hyo@nada.kth.se) 4/96
+ */
+
+#include "XpmI.h"
#define MAXPRINTABLE 92 /* number of printable ascii chars
* minus \ and " for string compat
unsigned int *index_return));
#ifndef FOR_MSW
+# ifndef AMIGA
LFUNC(GetImagePixels, int, (XImage *image, unsigned int width,
unsigned int height, PixelsMap *pmap));
LFUNC(GetImagePixels1, int, (XImage *image, unsigned int width,
unsigned int height, PixelsMap *pmap,
- int (*storeFunc) (Pixel,PixelsMap*,
- unsigned int*)));
-
-/*
int (*storeFunc) ()));
-*/
-
+# else /* AMIGA */
+LFUNC(AGetImagePixels, int, (XImage *image, unsigned int width,
+ unsigned int height, PixelsMap *pmap,
+ int (*storeFunc) ()));
+# endif/* AMIGA */
#else /* ndef FOR_MSW */
LFUNC(MSWGetImagePixels, int, (Display *d, XImage *image, unsigned int width,
- unsigned int height, PixelsMap *pmap));
+ unsigned int height, PixelsMap *pmap,
+ int (*storeFunc) ()));
#endif
LFUNC(ScanTransparentColor, int, (XpmColor *color, unsigned int cpp,
XpmAttributes *attributes));
* if not large enough.
*/
static int
-storePixel(Pixel pixel, PixelsMap *pmap, unsigned int *index_return)
+storePixel(pixel, pmap, index_return)
+ Pixel pixel;
+ PixelsMap *pmap;
+ unsigned int *index_return;
{
unsigned int i;
Pixel *p;
}
static int
-storeMaskPixel(Pixel pixel, PixelsMap *pmap, unsigned int *index_return)
+storeMaskPixel(pixel, pmap, index_return)
+ Pixel pixel;
+ PixelsMap *pmap;
+ unsigned int *index_return;
{
if (!pixel) {
if (!pmap->ncolors) {
return 0;
}
-/* function call in case of error, frees only locally allocated variables */
+/* function call in case of error */
#undef RETURN
#define RETURN(status) \
{ \
- if (pmap.pixelindex) XpmFree(pmap.pixelindex); \
- if (pmap.pixels) XpmFree(pmap.pixels); \
- if (colorTable) xpmFreeColorTable(colorTable, pmap.ncolors); \
- return(status); \
+ ErrorStatus = status; \
+ goto error; \
}
/*
* the given XpmImage structure.
*/
int
-XpmCreateXpmImageFromImage(Display *display, XImage *image, XImage *shapeimage,
- XpmImage *xpmimage, XpmAttributes *attributes)
+XpmCreateXpmImageFromImage(display, image, shapeimage,
+ xpmimage, attributes)
+ Display *display;
+ XImage *image;
+ XImage *shapeimage;
+ XpmImage *xpmimage;
+ XpmAttributes *attributes;
{
/* variables stored in the XpmAttributes structure */
unsigned int cpp;
unsigned int height = 0;
unsigned int cppm; /* minimum chars per pixel */
unsigned int c;
- unsigned int offset;
/* initialize pmap */
pmap.pixels = NULL;
*/
if (shapeimage) {
#ifndef FOR_MSW
+# ifndef AMIGA
ErrorStatus = GetImagePixels1(shapeimage, width, height, &pmap,
storeMaskPixel);
+# else
+ ErrorStatus = AGetImagePixels(shapeimage, width, height, &pmap,
+ storeMaskPixel);
+# endif
#else
ErrorStatus = MSWGetImagePixels(display, shapeimage, width, height,
- &pmap);
+ &pmap, storeMaskPixel);
#endif
if (ErrorStatus != XpmSuccess)
RETURN(ErrorStatus);
/*
* scan the image data
- *
+ *
* In case depth is 1 or bits_per_pixel is 4, 6, 8, 24 or 32 use optimized
* functions, otherwise use slower but sure general one.
- *
+ *
*/
if (image) {
#ifndef FOR_MSW
- if (image->depth == 1)
+# ifndef AMIGA
+ if (((image->bits_per_pixel | image->depth) == 1) &&
+ (image->byte_order == image->bitmap_bit_order))
ErrorStatus = GetImagePixels1(image, width, height, &pmap,
storePixel);
- else if (image->bits_per_pixel == 8)
- ErrorStatus = GetImagePixels8(image, width, height, &pmap);
- else if (image->bits_per_pixel == 16)
- ErrorStatus = GetImagePixels16(image, width, height, &pmap);
- else if (image->bits_per_pixel == 32)
- ErrorStatus = GetImagePixels32(image, width, height, &pmap);
- else
+ else if (image->format == ZPixmap) {
+ if (image->bits_per_pixel == 8)
+ ErrorStatus = GetImagePixels8(image, width, height, &pmap);
+ else if (image->bits_per_pixel == 16)
+ ErrorStatus = GetImagePixels16(image, width, height, &pmap);
+ else if (image->bits_per_pixel == 32)
+ ErrorStatus = GetImagePixels32(image, width, height, &pmap);
+ } else
ErrorStatus = GetImagePixels(image, width, height, &pmap);
-#else /* FOR_MSW */
- ErrorStatus = MSWGetImagePixels(display, image, width, height, &pmap);
+# else
+ ErrorStatus = AGetImagePixels(image, width, height, &pmap,
+ storePixel);
+# endif
+#else
+ ErrorStatus = MSWGetImagePixels(display, image, width, height, &pmap,
+ storePixel);
#endif
if (ErrorStatus != XpmSuccess)
RETURN(ErrorStatus);
ErrorStatus = ScanTransparentColor(colorTable, cpp, attributes);
if (ErrorStatus != XpmSuccess)
RETURN(ErrorStatus);
- offset = 1;
- } else
- offset = 0;
+ }
- ErrorStatus = ScanOtherColors(display, colorTable + offset,
- pmap.ncolors - offset, pmap.pixels + offset,
- pmap.mask_pixel, cpp, attributes);
+ ErrorStatus = ScanOtherColors(display, colorTable, pmap.ncolors,
+ pmap.pixels, pmap.mask_pixel, cpp,
+ attributes);
if (ErrorStatus != XpmSuccess)
RETURN(ErrorStatus);
XpmFree(pmap.pixels);
return (XpmSuccess);
+
+/* exit point in case of error, free only locally allocated variables */
+error:
+ if (pmap.pixelindex)
+ XpmFree(pmap.pixelindex);
+ if (pmap.pixels)
+ XpmFree(pmap.pixels);
+ if (colorTable)
+ xpmFreeColorTable(colorTable, pmap.ncolors);
+
+ return (ErrorStatus);
}
static int
-ScanTransparentColor(XpmColor *color, unsigned int cpp, XpmAttributes *attributes)
+ScanTransparentColor(color, cpp, attributes)
+ XpmColor *color;
+ unsigned int cpp;
+ XpmAttributes *attributes;
{
char *s;
unsigned int a, b, c;
*s = '\0';
/* then retreive related info from the attributes if any */
- if (attributes && attributes->mask_pixel != XpmUndefPixel && (
+ if (attributes && (attributes->valuemask & XpmColorTable
/* 3.2 backward compatibility code */
- attributes->valuemask & XpmInfos ||
+ || attributes->valuemask & XpmInfos)
/* end 3.2 bc */
- attributes->valuemask & XpmColorTable)) {
+ && attributes->mask_pixel != XpmUndefPixel) {
unsigned int key;
char **defaults = (char **) color;
char **mask_defaults;
/* 3.2 backward compatibility code */
- if (attributes->valuemask & XpmInfos)
- mask_defaults = (char **)
- ((XpmColor **) attributes->colorTable)[attributes->mask_pixel];
- else
+ if (attributes->valuemask & XpmColorTable)
/* end 3.2 bc */
mask_defaults = (char **) (
attributes->colorTable + attributes->mask_pixel);
+/* 3.2 backward compatibility code */
+ else
+ mask_defaults = (char **)
+ ((XpmColor **) attributes->colorTable)[attributes->mask_pixel];
+/* end 3.2 bc */
for (key = 1; key <= NKEYS; key++) {
if (s = mask_defaults[key]) {
- defaults[key] = (char *) strdup(s);
+ defaults[key] = (char *) xpmstrdup(s);
if (!defaults[key])
return (XpmNoMemory);
}
}
} else {
- color->c_color = (char *) strdup(TRANSPARENT_COLOR);
+ color->c_color = (char *) xpmstrdup(TRANSPARENT_COLOR);
if (!color->c_color)
return (XpmNoMemory);
}
}
static int
-ScanOtherColors(Display *display, XpmColor *colors, int ncolors, Pixel *pixels,
- unsigned int mask, unsigned int cpp, XpmAttributes *attributes)
+ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
+ Display *display;
+ XpmColor *colors;
+ int ncolors;
+ Pixel *pixels;
+ unsigned int mask;
+ unsigned int cpp;
+ XpmAttributes *attributes;
{
/* variables stored in the XpmAttributes structure */
Colormap colormap;
#ifndef FOR_MSW
xpmRgbName rgbn[MAX_RGBNAMES];
#else
- xpmRgbName *rgbn = NULL;
-#endif
+ xpmRgbName *rgbn = NULL;
+#endif
int rgbn_max = 0;
unsigned int i, j, c, i2;
XpmColor *color;
unsigned int ancolors = 0;
Pixel *apixels;
unsigned int mask_pixel;
- int found;
+ Bool found;
/* retrieve information from the XpmAttributes */
if (attributes && (attributes->valuemask & XpmColormap))
else
rgb_fname = NULL;
+ /* start from the right element */
+ if (mask) {
+ colors++;
+ ncolors--;
+ pixels++;
+ }
+
/* first get character strings and rgb values */
xcolors = (XColor *) XpmMalloc(sizeof(XColor) * ncolors);
if (!xcolors)
return (XpmNoMemory);
- for (i = 0, i2 = (mask ? i + 1 : i), color = colors, xcolor = xcolors;
- i < (unsigned int)ncolors; i++, i2++, color++, xcolor++, pixels++) {
+ for (i = 0, i2 = mask, color = colors, xcolor = xcolors;
+ i < ncolors; i++, i2++, color++, xcolor++, pixels++) {
if (!(s = color->string = (char *) XpmMalloc(cpp + 1))) {
XpmFree(xcolors);
xcolor->pixel = *pixels;
}
-#if defined(wx_msw) || defined(wx_pm)
- XQueryColors(display, (Colormap *)colormap, xcolors, ncolors);
-#else
- XQueryColors(display, (Colormap)colormap, xcolors, ncolors);
-#endif
+ XQueryColors(display, colormap, xcolors, ncolors);
#ifndef FOR_MSW
/* read the rgb file if any was specified */
}
/* end 3.2 bc */
- for (i = 0, color = colors, xcolor = xcolors; i < (unsigned int)ncolors;
+ for (i = 0, color = colors, xcolor = xcolors; i < ncolors;
i++, color++, xcolor++) {
/* look for related info from the attributes if any */
found = True;
for (key = 1; key <= NKEYS; key++) {
if (s = adefaults[key])
- defaults[key] = (char *) strdup(s);
+ defaults[key] = (char *) xpmstrdup(s);
}
}
}
colorname = xpmGetRgbName(rgbn, rgbn_max, xcolor->red,
xcolor->green, xcolor->blue);
if (colorname)
- color->c_color = (char *) strdup(colorname);
+ color->c_color = (char *) xpmstrdup(colorname);
else {
/* at last store the rgb value */
char buf[BUFSIZ];
#ifndef FOR_MSW
sprintf(buf, "#%04X%04X%04X",
xcolor->red, xcolor->green, xcolor->blue);
-#else
+#else
sprintf(buf, "#%02x%02x%02x",
xcolor->red, xcolor->green, xcolor->blue);
#endif
- color->c_color = (char *) strdup(buf);
+ color->c_color = (char *) xpmstrdup(buf);
}
if (!color->c_color) {
XpmFree(xcolors);
}
#ifndef FOR_MSW
+# ifndef AMIGA
/*
* The functions below are written from X11R5 MIT's code (XImUtil.c)
*
* The idea is to have faster functions than the standard XGetPixel function
* to scan the image data. Indeed we can speed up things by suppressing tests
* performed for each pixel. We do exactly the same tests but at the image
- * level. Assuming that we use only ZPixmap images.
+ * level.
*/
static unsigned long Const low_bits_table[] = {
};
/*
- * Default method to scan pixels of a Z image data structure.
+ * Default method to scan pixels of an image data structure.
* The algorithm used is:
*
* copy the source bitmap_unit or Zpixel into temp
*/
static int
-GetImagePixels(XImage *image, unsigned int width, unsigned int height, PixelsMap *pmap)
+GetImagePixels(image, width, height, pmap)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ PixelsMap *pmap;
{
char *src;
char *dst;
unsigned int *iptr;
char *data;
int x, y, i;
- int bits, depth, ibu, ibpp;
+ int bits, depth, ibu, ibpp, offset;
unsigned long lbt;
Pixel pixel, px;
depth = image->depth;
lbt = low_bits_table[depth];
ibpp = image->bits_per_pixel;
- if (image->depth == 1) {
+ offset = image->xoffset;
+
+ if ((image->bits_per_pixel | image->depth) == 1) {
ibu = image->bitmap_unit;
for (y = 0; y < height; y++)
for (x = 0; x < width; x++, iptr++) {
for (i = ibu >> 3; --i >= 0;)
*dst++ = *src++;
XYNORMALIZE(&pixel, image);
- bits = x % ibu;
+ bits = (x + offset) % ibu;
pixel = ((((char *) &pixel)[bits >> 3]) >> (bits & 7)) & 1;
if (ibpp != depth)
pixel &= lbt;
if (storePixel(pixel, pmap, iptr))
return (XpmNoMemory);
}
- } else {
+ } else if (image->format == XYPixmap) {
+ int nbytes, bpl, j;
+ long plane = 0;
+ ibu = image->bitmap_unit;
+ nbytes = ibu >> 3;
+ bpl = image->bytes_per_line;
+ for (y = 0; y < height; y++)
+ for (x = 0; x < width; x++, iptr++) {
+ pixel = 0;
+ plane = 0;
+ for (i = depth; --i >= 0;) {
+ src = &data[XYINDEX(x, y, image) + plane];
+ dst = (char *) &px;
+ px = 0;
+ for (j = nbytes; --j >= 0;)
+ *dst++ = *src++;
+ XYNORMALIZE(&px, image);
+ bits = (x + offset) % ibu;
+ pixel = (pixel << 1) |
+ (((((char *) &px)[bits >> 3]) >> (bits & 7)) & 1);
+ plane = plane + (bpl * height);
+ }
+ if (ibpp != depth)
+ pixel &= lbt;
+ if (storePixel(pixel, pmap, iptr))
+ return (XpmNoMemory);
+ }
+ } else if (image->format == ZPixmap) {
for (y = 0; y < height; y++)
for (x = 0; x < width; x++, iptr++) {
src = &data[ZINDEX(x, y, image)];
if (storePixel(pixel, pmap, iptr))
return (XpmNoMemory);
}
- }
+ } else
+ return (XpmColorError); /* actually a bad image */
return (XpmSuccess);
}
* scan pixels of a 32-bits Z image data structure
*/
-#ifndef WORD64
+#if !defined(WORD64) && !defined(LONG64)
static unsigned long byteorderpixel = MSBFirst << 24;
-
#endif
static int
-GetImagePixels32(XImage *image, unsigned int width, unsigned int height, PixelsMap *pmap)
+GetImagePixels32(image, width, height, pmap)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ PixelsMap *pmap;
{
unsigned char *addr;
unsigned char *data;
iptr = pmap->pixelindex;
depth = image->depth;
lbt = low_bits_table[depth];
-#ifndef WORD64
+#if !defined(WORD64) && !defined(LONG64)
if (*((char *) &byteorderpixel) == image->byte_order) {
for (y = 0; y < height; y++)
for (x = 0; x < width; x++, iptr++) {
pixel = ((unsigned long) addr[0] << 24 |
(unsigned long) addr[1] << 16 |
(unsigned long) addr[2] << 8 |
- addr[4]);
+ addr[3]);
if (depth != 32)
pixel &= lbt;
if (storePixel(pixel, pmap, iptr))
*/
static int
-GetImagePixels16(XImage *image, unsigned int width, unsigned int height, PixelsMap *pmap)
+GetImagePixels16(image, width, height, pmap)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ PixelsMap *pmap;
{
unsigned char *addr;
unsigned char *data;
*/
static int
-GetImagePixels8(XImage *image, unsigned int width, unsigned int height, PixelsMap *pmap)
+GetImagePixels8(image, width, height, pmap)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ PixelsMap *pmap;
{
unsigned int *iptr;
unsigned char *data;
*/
static int
-GetImagePixels1(XImage *image, unsigned int width, unsigned int height, PixelsMap *pmap,
-/*
- int (*storeFunc)()
-*/
- int (*storeFunc)(Pixel,PixelsMap*,unsigned int*)
-)
+GetImagePixels1(image, width, height, pmap, storeFunc)
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ PixelsMap *pmap;
+ int (*storeFunc) ();
{
unsigned int *iptr;
int x, y;
char *data;
Pixel pixel;
+ int xoff, yoff, offset, bpl;
- if (image->byte_order != image->bitmap_bit_order)
- return (GetImagePixels(image, width, height, pmap));
- else {
- data = image->data;
- iptr = pmap->pixelindex;
- if (image->bitmap_bit_order == MSBFirst)
- for (y = 0; y < height; y++)
- for (x = 0; x < width; x++, iptr++) {
- pixel = (data[ZINDEX1(x, y, image)] & (0x80 >> (x & 7)))
- ? 1 : 0;
- if ((*storeFunc) (pixel, pmap, iptr))
- return (XpmNoMemory);
- }
- else
- for (y = 0; y < height; y++)
- for (x = 0; x < width; x++, iptr++) {
- pixel = (data[ZINDEX1(x, y, image)] & (1 << (x & 7)))
- ? 1 : 0;
- if ((*storeFunc) (pixel, pmap, iptr))
- return (XpmNoMemory);
- }
- }
+ data = image->data;
+ iptr = pmap->pixelindex;
+ offset = image->xoffset;
+ bpl = image->bytes_per_line;
+
+ if (image->bitmap_bit_order == MSBFirst)
+ for (y = 0; y < height; y++)
+ for (x = 0; x < width; x++, iptr++) {
+ xoff = x + offset;
+ yoff = y * bpl + (xoff >> 3);
+ xoff &= 7;
+ pixel = (data[yoff] & (0x80 >> xoff)) ? 1 : 0;
+ if ((*storeFunc) (pixel, pmap, iptr))
+ return (XpmNoMemory);
+ }
+ else
+ for (y = 0; y < height; y++)
+ for (x = 0; x < width; x++, iptr++) {
+ xoff = x + offset;
+ yoff = y * bpl + (xoff >> 3);
+ xoff &= 7;
+ pixel = (data[yoff] & (1 << xoff)) ? 1 : 0;
+ if ((*storeFunc) (pixel, pmap, iptr))
+ return (XpmNoMemory);
+ }
return (XpmSuccess);
}
+# else /* AMIGA */
+
+#define CLEAN_UP(status) \
+{\
+ if (pixels) XpmFree (pixels);\
+ if (tmp_img) FreeXImage (tmp_img);\
+ return (status);\
+}
+
+static int
+AGetImagePixels (
+ XImage *image,
+ unsigned int width,
+ unsigned int height,
+ PixelsMap *pmap,
+ int (*storeFunc) ())
+{
+ unsigned int *iptr;
+ unsigned int x, y;
+ unsigned char *pixels;
+ XImage *tmp_img;
+
+ pixels = XpmMalloc ((((width+15)>>4)<<4)*sizeof (*pixels));
+ if (pixels == NULL)
+ return XpmNoMemory;
+
+ tmp_img = AllocXImage ((((width+15)>>4)<<4), 1, image->rp->BitMap->Depth);
+ if (tmp_img == NULL)
+ CLEAN_UP (XpmNoMemory)
+
+ iptr = pmap->pixelindex;
+ for (y = 0; y < height; ++y)
+ {
+ ReadPixelLine8 (image->rp, 0, y, width, pixels, tmp_img->rp);
+ for (x = 0; x < width; ++x, ++iptr)
+ {
+ if ((*storeFunc) (pixels[x], pmap, iptr))
+ CLEAN_UP (XpmNoMemory)
+ }
+ }
+
+ CLEAN_UP (XpmSuccess)
+}
+
+#undef CLEAN_UP
+
+# endif/* AMIGA */
#else /* ndef FOR_MSW */
static int
-MSWGetImagePixels(Display *display, XImage *image, unsigned int width, unsigned int height, PixelsMap *pmap)
+MSWGetImagePixels(display, image, width, height, pmap, storeFunc)
+ Display *display;
+ XImage *image;
+ unsigned int width;
+ unsigned int height;
+ PixelsMap *pmap;
+ int (*storeFunc) ();
{
unsigned int *iptr;
unsigned int x, y;
iptr = pmap->pixelindex;
+ SelectObject(*display, image->bitmap);
for (y = 0; y < height; y++) {
-#if !defined(__VISAGECPP__) /* fixme for OS/2 */
for (x = 0; x < width; x++, iptr++) {
- /* bitmap must be selected !!! ??? */
pixel = GetPixel(*display, x, y);
- if (storePixel(pixel, pmap, iptr))
+ if ((*storeFunc) (pixel, pmap, iptr))
return (XpmNoMemory);
}
-#endif
}
return (XpmSuccess);
}
#endif
#ifndef FOR_MSW
+# ifndef AMIGA
int
-XpmCreateXpmImageFromPixmap(Display *display, Pixmap pixmap, Pixmap shapemask,
- XpmImage *xpmimage, XpmAttributes *attributes)
+XpmCreateXpmImageFromPixmap(display, pixmap, shapemask,
+ xpmimage, attributes)
+ Display *display;
+ Pixmap pixmap;
+ Pixmap shapemask;
+ XpmImage *xpmimage;
+ XpmAttributes *attributes;
{
XImage *ximage = NULL;
XImage *shapeimage = NULL;
return (ErrorStatus);
}
+# endif/* not AMIGA */
#endif /* ndef FOR_MSW */
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* Developed by HeDu 3/94 (hedu@cul-ipn.uni-kiel.de) *
\*****************************************************************************/
-#include "xpm34.h"
+/* Moved here so that FOR_MSW gets defined if we are using wxWindows (GRG) */
+#include "xpm.h"
#ifdef FOR_MSW
-#include "xpm34p.h" /* for XpmMalloc */
+#include "xpmi.h" /* for XpmMalloc */
/*
* On DOS size_t is only 2 bytes, thus malloc(size_t s) can only malloc
}
/* I get only 1 plane but 8 bits per pixel,
- so I think BITSPIXEL should be depth
-
- TRS: I assume that all "displays" have the same number of
- planes later in the code, which is based on the assumption
- that the display variable is ignored below. :)
- */
-int
+ so I think BITSPIXEL should be depth */
+int
XDefaultDepth(Display *display, Screen *screen)
{
int d, b;
-#if !defined(__VISAGECPP__) /* fisme for OS/2 */
b = GetDeviceCaps(*display, BITSPIXEL);
d = GetDeviceCaps(*display, PLANES);
-#endif
return (b);
}
/* convert hex color names,
wrong digits (not a-f,A-F,0-9) are treated as zero */
-static int
-hexCharToInt(char c)
+static int
+hexCharToInt(c)
{
int r;
return (r);
}
-static int
+static int
rgbFromHex(char *hex, int *r, int *g, int *b)
{
int len;
}
/* Color related functions */
-int
+int
XParseColor(Display *d, Colormap *cmap, char *name, XColor *color)
{
int r, g, b; /* only 8 bit values used */
}
if (okay) {
-#if !defined(__VISAGECPP__) /* fixme for OS/2 */
color->pixel = RGB(r, g, b);
-#endif
color->red = (BYTE) r;
color->green = (BYTE) g;
color->blue = (BYTE) b;
}
-int
+/* GRG: 2nd arg is Colormap*, not Colormap */
+
+int
XAllocColor(Display *d, Colormap *cmap, XColor *color)
{
/* colormap not used yet so color->pixel is the real COLORREF (RBG) and not an
index in some colormap as in X */
return (1);
}
-void
+void
XQueryColors(Display *display, Colormap *colormap,
XColor *xcolors, int ncolors)
{
XColor *xc = xcolors;
int i;
-#if !defined(__VISAGECPP__) /* fixme for OS/2 */
for (i = 0; i < ncolors; i++, xc++) {
xc->red = GetRValue(xc->pixel);
xc->green = GetGValue(xc->pixel);
xc->blue = GetBValue(xc->pixel);
}
-#endif
return;
}
-int
+int
XFreeColors(Display *d, Colormap cmap,
unsigned long pixels[], int npixels, unsigned long planes)
{
XImage *img = (XImage *) XpmMalloc(sizeof(XImage));
if (img) {
- /* *img = CreateCompatibleBitmap(*d, width, height); */
-
-#if !defined(__VISAGECPP__) /* fixme for OS/2 */
- /* create the bitmap with the same number of planes as the default display
- * (otherwise it wouldn't work for 16 color mode) */
- img->bitmap = CreateBitmap(width, height,
- GetDeviceCaps(*d, PLANES),
- depth /* bits per pixel */ , NULL);
-#endif
+ /*JW: This is what it should be, but the picture comes out
+ just black!? It appears to be doing monochrome reduction,
+ but I've got no clue why. Using CreateBitmap() is supposed
+ to be slower, but otherwise ok
+ if ( depth == GetDeviceCaps(*d, BITSPIXEL) ) {
+ img->bitmap = CreateCompatibleBitmap(*d, width, height);
+ } else*/ {
+ img->bitmap = CreateBitmap(width, height, 1 /* plane */ ,
+ depth /* bits per pixel */ , NULL);
+ }
img->width = width;
img->height = height;
img->depth = depth;
}
-void
+void
XImageFree(XImage *img)
{
if (img) {
XpmFree(img);
}
}
-void
+void
XDestroyImage(XImage *img)
{
if (img) {
-#if !defined(__VISAGECPP__) /* fixme for OS/2 */
DeleteObject(img->bitmap); /* check return ??? */
-#endif
XImageFree(img);
}
}
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
#ifdef FOR_MSW
-#if defined(__OS2__)
-#define INCL_OS2
-#include<os2.h>
-#else
#include "windows.h" /* MS windows GDI types */
-#endif
/*
* minimal portability layer between ansi and KR C
typedef void *Colormap; /* should be COLORPALETTE, not done
* yet */
-#if !defined(__OS2__)
typedef COLORREF Pixel;
-#else
-typedef unsigned long COLORREF;
-typedef unsigned long Pixel;
-#endif
#define PIXEL_ALREADY_TYPEDEFED /* to let xpm.h know about it */
#endif /* cplusplus */
#define ZPixmap 1 /* not really used */
+#define XYBitmap 1 /* not really used */
#ifndef True
#define True 1
#define False 0
#endif
-
-/*
#ifndef Bool
-typedef BOOL Bool;
+typedef BOOL Bool; /* take MSW bool */
#endif
-*/
-
/* make these local here, simx.c gets the same from xpm.h */
#undef LFUNC
#undef FUNC
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* XpmWrFFrData.c: *
+* WrFFrData.c: *
* *
* XPM library *
* Parse an Xpm array and write a file that corresponds to it. *
* Developed by Dan Greening dgreen@cs.ucla.edu / dgreen@sti.com *
\*****************************************************************************/
-#include "xpm34.h"
-#include "xpm34p.h"
+#include "XpmI.h"
int
-XpmWriteFileFromData(char *filename, char **data)
+XpmWriteFileFromData(filename, data)
+ char *filename;
+ char **data;
{
XpmImage image;
XpmInfo info;
/*
- * Copyright (C) 1989-94 GROUPE BULL
+ * Copyright (C) 1989-95 GROUPE BULL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*/
/*****************************************************************************\
-* XpmWrFFrI.c: *
+* WrFFrI.c: *
* *
* XPM library *
* Write an image and possibly its mask to an XPM file *
* Developed by Arnaud Le Hors *
\*****************************************************************************/
-#include "xpm34p.h"
-#ifdef FOR_MSW
-#include "ctype.h"
+/*
+ * The code related to AMIGA has been added by
+ * Lorens Younes (d93-hyo@nada.kth.se) 4/96
+ */
+
+#include "XpmI.h"
+#if !defined(NO_ZPIPE) && defined(WIN32)
+# define popen _popen
+# define pclose _pclose
#endif
-#include <string.h>
+/* MS Windows define a function called WriteFile @#%#&!!! */
+LFUNC(xpmWriteFile, int, (FILE *file, XpmImage *image, char *name,
+ XpmInfo *info));
LFUNC(WriteColors, void, (FILE *file, XpmColor *colors, unsigned int ncolors));
LFUNC(WriteExtensions, void, (FILE *file, XpmExtension *ext,
unsigned int num));
+LFUNC(OpenWriteFile, int, (char *filename, xpmData *mdata));
+LFUNC(xpmDataClose, void, (xpmData *mdata));
+
int
-XpmWriteFileFromImage(Display *display, char *filename, XImage *image, XImage *shapeimage, XpmAttributes *attributes)
+XpmWriteFileFromImage(display, filename, image, shapeimage, attributes)
+ Display *display;
+ char *filename;
+ XImage *image;
+ XImage *shapeimage;
+ XpmAttributes *attributes;
{
XpmImage xpmimage;
XpmInfo info;
}
int
-XpmWriteFileFromXpmImage(char *filename, XpmImage *image, XpmInfo *info)
+XpmWriteFileFromXpmImage(filename, image, info)
+ char *filename;
+ XpmImage *image;
+ XpmInfo *info;
{
xpmData mdata;
char *name, *dot, *s, new_name[BUFSIZ];
int ErrorStatus;
- int len, i;
/* open file to write */
- if ((ErrorStatus = xpmWriteFile(filename, &mdata)) != XpmSuccess)
+ if ((ErrorStatus = OpenWriteFile(filename, &mdata)) != XpmSuccess)
return (ErrorStatus);
/* figure out a name */
#ifdef VMS
name = filename;
#else
-#ifdef FOR_MSW
- if (!(name = strchr(filename, '\\')))
-#else
- if (!(name = strchr(filename, '/')))
+ if (!(name = rindex(filename, '/'))
+#ifdef AMIGA
+ && !(name = rindex(filename, ':'))
#endif
+ )
name = filename;
else
name++;
#endif
- if (dot = strchr(name, '.')) {
+ /* let's try to make a valid C syntax name */
+ if (dot = index(name, '.')) {
strcpy(new_name, name);
-#ifdef FOR_MSW
- // Convert to lower case
- len = strlen(new_name);
- for (i = 0; i < len; i++)
- new_name[i] = tolower(new_name[i]);
-#endif
- /* change '.' to '_' to get a valid C syntax name */
+ /* change '.' to '_' */
name = s = new_name;
- while (dot = strchr(s, '.')) {
+ while (dot = index(s, '.')) {
+ *dot = '_';
+ s = dot;
+ }
+ }
+ if (dot = index(name, '-')) {
+ if (name != new_name) {
+ strcpy(new_name, name);
+ name = new_name;
+ }
+ /* change '-' to '_' */
+ s = name;
+ while (dot = index(s, '-')) {
*dot = '_';
s = dot;
}
/* write the XpmData from the XpmImage */
if (ErrorStatus == XpmSuccess)
- ErrorStatus = xpmWriteData(&mdata, image, name, info);
+ ErrorStatus = xpmWriteFile(mdata.stream.file, image, name, info);
xpmDataClose(&mdata);
return (ErrorStatus);
}
-int
-xpmWriteData(xpmData *mdata, XpmImage *image, char *name, XpmInfo *info)
+static int
+xpmWriteFile(file, image, name, info)
+ FILE *file;
+ XpmImage *image;
+ char *name;
+ XpmInfo *info;
{
/* calculation variables */
unsigned int cmts, extensions;
- FILE *file;
int ErrorStatus;
- /* store this to speed up */
- file = mdata->stream.file;
-
cmts = info && (info->valuemask & XpmComments);
extensions = info && (info->valuemask & XpmExtensions)
&& info->nextensions;
}
static void
-WriteColors(FILE *file, XpmColor *colors, unsigned int ncolors)
+WriteColors(file, colors, ncolors)
+ FILE *file;
+ XpmColor *colors;
+ unsigned int ncolors;
{
unsigned int a, key;
char *s;
static int
-WritePixels(FILE *file, unsigned int width, unsigned int height, unsigned int cpp, unsigned int *pixels, XpmColor *colors)
+WritePixels(file, width, height, cpp, pixels, colors)
+ FILE *file;
+ unsigned int width;
+ unsigned int height;
+ unsigned int cpp;
+ unsigned int *pixels;
+ XpmColor *colors;
{
char *s, *p, *buf;
unsigned int x, y, h;
}
static void
-WriteExtensions(FILE *file, XpmExtension *ext, unsigned int num)
+WriteExtensions(file, ext, num)
+ FILE *file;
+ XpmExtension *ext;
+ unsigned int num;
{
unsigned int x, y, n;
char **line;
}
fprintf(file, ",\n\"XPMENDEXT\"");
}
+
+/*
+ * open the given file to be written as an xpmData which is returned
+ */
+static int
+OpenWriteFile(filename, mdata)
+ char *filename;
+ xpmData *mdata;
+{
+#ifndef NO_ZPIPE
+ char buf[BUFSIZ];
+
+#endif
+
+ if (!filename) {
+ mdata->stream.file = (stdout);
+ mdata->type = XPMFILE;
+ } else {
+#ifndef NO_ZPIPE
+ int len = strlen(filename);
+ if (len > 2 && !strcmp(".Z", filename + (len - 2))) {
+ sprintf(buf, "compress > \"%s\"", filename);
+ if (!(mdata->stream.file = popen(buf, "w")))
+ return (XpmOpenFailed);
+
+ mdata->type = XPMPIPE;
+ } else if (len > 3 && !strcmp(".gz", filename + (len - 3))) {
+ sprintf(buf, "gzip -q > \"%s\"", filename);
+ if (!(mdata->stream.file = popen(buf, "w")))
+ return (XpmOpenFailed);
+
+ mdata->type = XPMPIPE;
+ } else {
+#endif
+ if (!(mdata->stream.file = fopen(filename, "w")))
+ return (XpmOpenFailed);
+
+ mdata->type = XPMFILE;
+#ifndef NO_ZPIPE
+ }
+#endif
+ }
+ return (XpmSuccess);
+}
+
+/*
+ * close the file related to the xpmData if any
+ */
+static void
+xpmDataClose(mdata)
+ xpmData *mdata;
+{
+ switch (mdata->type) {
+ case XPMFILE:
+ if (mdata->stream.file != (stdout))
+ fclose(mdata->stream.file);
+ break;
+#ifndef NO_ZPIPE
+ case XPMPIPE:
+ pclose(mdata->stream.file);
+ break;
+#endif
+ }
+}
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-#include "xpm34.h"
-
-#ifndef FOR_MSW
-
-/*****************************************************************************\
-* XpmWrFFrP.c: *
-* *
-* XPM library *
-* Write a pixmap and possibly its mask to an XPM file *
-* *
-* Developed by Arnaud Le Hors *
-\*****************************************************************************/
-
-#include "xpm34p.h"
-#ifdef VMS
-#include "sys$library:string.h"
-#else
-#if defined(SYSV) || defined(SVR4)
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#endif
-
-int
-XpmWriteFileFromPixmap(Display *display, char *filename, Pixmap pixmap, Pixmap shapemask, XpmAttributes *attributes)
-{
- XImage *ximage = NULL;
- XImage *shapeimage = NULL;
- unsigned int width = 0;
- unsigned int height = 0;
- int ErrorStatus;
-
- /* get geometry */
- if (attributes && attributes->valuemask & XpmSize) {
- width = attributes->width;
- height = attributes->height;
- }
- /* get the ximages */
- if (pixmap)
- xpmCreateImageFromPixmap(display, pixmap, &ximage, &width, &height);
- if (shapemask)
- xpmCreateImageFromPixmap(display, shapemask, &shapeimage,
- &width, &height);
-
- /* write to the file */
- ErrorStatus = XpmWriteFileFromImage(display, filename, ximage, shapeimage,
- attributes);
-
- /* destroy the ximages */
- if (ximage)
- XDestroyImage(ximage);
- if (shapeimage)
- XDestroyImage(shapeimage);
-
- return (ErrorStatus);
-}
-#endif
--- /dev/null
+/*
+ * Copyright (C) 1989-95 GROUPE BULL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 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
+ * GROUPE BULL 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 GROUPE BULL shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from GROUPE BULL.
+ */
+
+/*****************************************************************************\
+* xpm.h: *
+* *
+* XPM library *
+* Include file *
+* *
+* Developed by Arnaud Le Hors *
+\*****************************************************************************/
+
+/*
+ * The code related to FOR_MSW has been added by
+ * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
+ */
+
+/*
+ * The code related to AMIGA has been added by
+ * Lorens Younes (d93-hyo@nada.kth.se) 4/96
+ */
+
+#ifndef XPM_h
+#define XPM_h
+
+#if (defined(_WINDOWS) || defined(__WXMSW__) || defined(WIN32)) && !defined(FOR_MSW)
+#define FOR_MSW
+#endif
+/* Piggyback on MSW for now */
+#if (defined(__OS2__) || defined(__WXPM__) || defined(OS232)) && !defined(FOR_MSW)
+#define FOR_MSW
+#endif
+
+/*
+ * first some identification numbers:
+ * the version and revision numbers are determined with the following rule:
+ * SO Major number = LIB minor version number.
+ * SO Minor number = LIB sub-minor version number.
+ * e.g: Xpm version 3.2f
+ * we forget the 3 which is the format number, 2 gives 2, and f gives 6.
+ * thus we have XpmVersion = 2 and XpmRevision = 6
+ * which gives SOXPMLIBREV = 2.6
+ *
+ * Then the XpmIncludeVersion number is built from these numbers.
+ */
+#define XpmFormat 3
+#define XpmVersion 4
+#define XpmRevision 11
+#define XpmIncludeVersion ((XpmFormat * 100 + XpmVersion) * 100 + XpmRevision)
+
+#ifndef XPM_NUMBERS
+
+#ifdef FOR_MSW
+# define SYSV /* uses memcpy string.h etc. */
+# include <malloc.h>
+# include "simx.h" /* defines some X stuff using MSW types */
+#define NEED_STRCASECMP /* at least for MSVC++ */
+#else /* FOR_MSW */
+# ifdef AMIGA
+# include "amigax.h"
+# else /* not AMIGA */
+# include <X11/Xlib.h>
+# include <X11/Xutil.h>
+# endif /* not AMIGA */
+#endif /* FOR_MSW */
+
+/* let's define Pixel if it is not done yet */
+#if ! defined(_XtIntrinsic_h) && ! defined(PIXEL_ALREADY_TYPEDEFED)
+typedef unsigned long Pixel; /* Index into colormap */
+# define PIXEL_ALREADY_TYPEDEFED
+#endif
+
+/* make sure we know whether function prototypes are needed or not */
+#ifndef NeedFunctionPrototypes
+# if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
+# define NeedFunctionPrototypes 1
+# else
+# define NeedFunctionPrototypes 0
+# endif
+#endif
+
+
+/* Return ErrorStatus codes:
+ * null if full success
+ * positive if partial success
+ * negative if failure
+ */
+
+#define XpmColorError 1
+#define XpmSuccess 0
+#define XpmOpenFailed -1
+#define XpmFileInvalid -2
+#define XpmNoMemory -3
+#define XpmColorFailed -4
+
+typedef struct {
+ char *name; /* Symbolic color name */
+ char *value; /* Color value */
+ Pixel pixel; /* Color pixel */
+} XpmColorSymbol;
+
+typedef struct {
+ char *name; /* name of the extension */
+ unsigned int nlines; /* number of lines in this extension */
+ char **lines; /* pointer to the extension array of strings */
+} XpmExtension;
+
+typedef struct {
+ char *string; /* characters string */
+ char *symbolic; /* symbolic name */
+ char *m_color; /* monochrom default */
+ char *g4_color; /* 4 level grayscale default */
+ char *g_color; /* other level grayscale default */
+ char *c_color; /* color default */
+} XpmColor;
+
+typedef struct {
+ unsigned int width; /* image width */
+ unsigned int height; /* image height */
+ unsigned int cpp; /* number of characters per pixel */
+ unsigned int ncolors; /* number of colors */
+ XpmColor *colorTable; /* list of related colors */
+ unsigned int *data; /* image data */
+} XpmImage;
+
+typedef struct {
+ unsigned long valuemask; /* Specifies which attributes are defined */
+ char *hints_cmt; /* Comment of the hints section */
+ char *colors_cmt; /* Comment of the colors section */
+ char *pixels_cmt; /* Comment of the pixels section */
+ unsigned int x_hotspot; /* Returns the x hotspot's coordinate */
+ unsigned int y_hotspot; /* Returns the y hotspot's coordinate */
+ unsigned int nextensions; /* number of extensions */
+ XpmExtension *extensions; /* pointer to array of extensions */
+} XpmInfo;
+
+typedef int (*XpmAllocColorFunc)(
+#if NeedFunctionPrototypes
+ Display* /* display */,
+ Colormap /* colormap */,
+ char* /* colorname */,
+ XColor* /* xcolor */,
+ void* /* closure */
+#endif
+);
+
+typedef int (*XpmFreeColorsFunc)(
+#if NeedFunctionPrototypes
+ Display* /* display */,
+ Colormap /* colormap */,
+ Pixel* /* pixels */,
+ int /* npixels */,
+ void* /* closure */
+#endif
+);
+
+typedef struct {
+ unsigned long valuemask; /* Specifies which attributes are
+ defined */
+
+ Visual *visual; /* Specifies the visual to use */
+ Colormap colormap; /* Specifies the colormap to use */
+ unsigned int depth; /* Specifies the depth */
+ unsigned int width; /* Returns the width of the created
+ pixmap */
+ unsigned int height; /* Returns the height of the created
+ pixmap */
+ unsigned int x_hotspot; /* Returns the x hotspot's
+ coordinate */
+ unsigned int y_hotspot; /* Returns the y hotspot's
+ coordinate */
+ unsigned int cpp; /* Specifies the number of char per
+ pixel */
+ Pixel *pixels; /* List of used color pixels */
+ unsigned int npixels; /* Number of used pixels */
+ XpmColorSymbol *colorsymbols; /* List of color symbols to override */
+ unsigned int numsymbols; /* Number of symbols */
+ char *rgb_fname; /* RGB text file name */
+ unsigned int nextensions; /* Number of extensions */
+ XpmExtension *extensions; /* List of extensions */
+
+ unsigned int ncolors; /* Number of colors */
+ XpmColor *colorTable; /* List of colors */
+/* 3.2 backward compatibility code */
+ char *hints_cmt; /* Comment of the hints section */
+ char *colors_cmt; /* Comment of the colors section */
+ char *pixels_cmt; /* Comment of the pixels section */
+/* end 3.2 bc */
+ unsigned int mask_pixel; /* Color table index of transparent
+ color */
+
+ /* Color Allocation Directives */
+ Bool exactColors; /* Only use exact colors for visual */
+ unsigned int closeness; /* Allowable RGB deviation */
+ unsigned int red_closeness; /* Allowable red deviation */
+ unsigned int green_closeness; /* Allowable green deviation */
+ unsigned int blue_closeness; /* Allowable blue deviation */
+ int color_key; /* Use colors from this color set */
+
+ Pixel *alloc_pixels; /* Returns the list of alloc'ed color
+ pixels */
+ int nalloc_pixels; /* Returns the number of alloc'ed
+ color pixels */
+
+ Bool alloc_close_colors; /* Specify whether close colors should
+ be allocated using XAllocColor
+ or not */
+ int bitmap_format; /* Specify the format of 1bit depth
+ images: ZPixmap or XYBitmap */
+
+ /* Color functions */
+ XpmAllocColorFunc alloc_color; /* Application color allocator */
+ XpmFreeColorsFunc free_colors; /* Application color de-allocator */
+ void *color_closure; /* Application private data to pass to
+ alloc_color and free_colors */
+
+} XpmAttributes;
+
+/* XpmAttributes value masks bits */
+#define XpmVisual (1L<<0)
+#define XpmColormap (1L<<1)
+#define XpmDepth (1L<<2)
+#define XpmSize (1L<<3) /* width & height */
+#define XpmHotspot (1L<<4) /* x_hotspot & y_hotspot */
+#define XpmCharsPerPixel (1L<<5)
+#define XpmColorSymbols (1L<<6)
+#define XpmRgbFilename (1L<<7)
+/* 3.2 backward compatibility code */
+#define XpmInfos (1L<<8)
+#define XpmReturnInfos XpmInfos
+/* end 3.2 bc */
+#define XpmReturnPixels (1L<<9)
+#define XpmExtensions (1L<<10)
+#define XpmReturnExtensions XpmExtensions
+
+#define XpmExactColors (1L<<11)
+#define XpmCloseness (1L<<12)
+#define XpmRGBCloseness (1L<<13)
+#define XpmColorKey (1L<<14)
+
+#define XpmColorTable (1L<<15)
+#define XpmReturnColorTable XpmColorTable
+
+#define XpmReturnAllocPixels (1L<<16)
+#define XpmAllocCloseColors (1L<<17)
+#define XpmBitmapFormat (1L<<18)
+
+#define XpmAllocColor (1L<<19)
+#define XpmFreeColors (1L<<20)
+#define XpmColorClosure (1L<<21)
+
+
+/* XpmInfo value masks bits */
+#define XpmComments XpmInfos
+#define XpmReturnComments XpmComments
+
+/* XpmAttributes mask_pixel value when there is no mask */
+#ifndef FOR_MSW
+#define XpmUndefPixel 0x80000000
+#else
+/* int is only 16 bit for MSW */
+#define XpmUndefPixel 0x8000
+#endif
+
+/*
+ * color keys for visual type, they must fit along with the number key of
+ * each related element in xpmColorKeys[] defined in XpmI.h
+ */
+#define XPM_MONO 2
+#define XPM_GREY4 3
+#define XPM_GRAY4 3
+#define XPM_GREY 4
+#define XPM_GRAY 4
+#define XPM_COLOR 5
+
+
+/* macros for forward declarations of functions with prototypes */
+#if NeedFunctionPrototypes
+#define FUNC(f, t, p) extern t f p
+#define LFUNC(f, t, p) static t f p
+#else
+#define FUNC(f, t, p) extern t f()
+#define LFUNC(f, t, p) static t f()
+#endif
+
+
+/*
+ * functions declarations
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* FOR_MSW, all ..Pixmap.. are excluded, only the ..XImage.. are used */
+/* Same for Amiga! */
+
+#if !defined(FOR_MSW) && !defined(AMIGA)
+ FUNC(XpmCreatePixmapFromData, int, (Display *display,
+ Drawable d,
+ char **data,
+ Pixmap *pixmap_return,
+ Pixmap *shapemask_return,
+ XpmAttributes *attributes));
+
+ FUNC(XpmCreateDataFromPixmap, int, (Display *display,
+ char ***data_return,
+ Pixmap pixmap,
+ Pixmap shapemask,
+ XpmAttributes *attributes));
+
+ FUNC(XpmReadFileToPixmap, int, (Display *display,
+ Drawable d,
+ char *filename,
+ Pixmap *pixmap_return,
+ Pixmap *shapemask_return,
+ XpmAttributes *attributes));
+
+ FUNC(XpmWriteFileFromPixmap, int, (Display *display,
+ char *filename,
+ Pixmap pixmap,
+ Pixmap shapemask,
+ XpmAttributes *attributes));
+#endif
+
+ FUNC(XpmCreateImageFromData, int, (Display *display,
+ char **data,
+ XImage **image_return,
+ XImage **shapemask_return,
+ XpmAttributes *attributes));
+
+ FUNC(XpmCreateDataFromImage, int, (Display *display,
+ char ***data_return,
+ XImage *image,
+ XImage *shapeimage,
+ XpmAttributes *attributes));
+
+ FUNC(XpmReadFileToImage, int, (Display *display,
+ char *filename,
+ XImage **image_return,
+ XImage **shapeimage_return,
+ XpmAttributes *attributes));
+
+ FUNC(XpmWriteFileFromImage, int, (Display *display,
+ char *filename,
+ XImage *image,
+ XImage *shapeimage,
+ XpmAttributes *attributes));
+
+ FUNC(XpmCreateImageFromBuffer, int, (Display *display,
+ char *buffer,
+ XImage **image_return,
+ XImage **shapemask_return,
+ XpmAttributes *attributes));
+#if !defined(FOR_MSW) && !defined(AMIGA)
+ FUNC(XpmCreatePixmapFromBuffer, int, (Display *display,
+ Drawable d,
+ char *buffer,
+ Pixmap *pixmap_return,
+ Pixmap *shapemask_return,
+ XpmAttributes *attributes));
+
+ FUNC(XpmCreateBufferFromImage, int, (Display *display,
+ char **buffer_return,
+ XImage *image,
+ XImage *shapeimage,
+ XpmAttributes *attributes));
+
+ FUNC(XpmCreateBufferFromPixmap, int, (Display *display,
+ char **buffer_return,
+ Pixmap pixmap,
+ Pixmap shapemask,
+ XpmAttributes *attributes));
+#endif
+ FUNC(XpmReadFileToBuffer, int, (char *filename, char **buffer_return));
+ FUNC(XpmWriteFileFromBuffer, int, (char *filename, char *buffer));
+
+ FUNC(XpmReadFileToData, int, (char *filename, char ***data_return));
+ FUNC(XpmWriteFileFromData, int, (char *filename, char **data));
+
+ FUNC(XpmAttributesSize, int, ());
+ FUNC(XpmFreeAttributes, void, (XpmAttributes *attributes));
+ FUNC(XpmFreeExtensions, void, (XpmExtension *extensions,
+ int nextensions));
+
+ FUNC(XpmFreeXpmImage, void, (XpmImage *image));
+ FUNC(XpmFreeXpmInfo, void, (XpmInfo *info));
+ FUNC(XpmGetErrorString, char *, (int errcode));
+ FUNC(XpmLibraryVersion, int, ());
+
+ /* XpmImage functions */
+ FUNC(XpmReadFileToXpmImage, int, (char *filename,
+ XpmImage *image,
+ XpmInfo *info));
+
+ FUNC(XpmWriteFileFromXpmImage, int, (char *filename,
+ XpmImage *image,
+ XpmInfo *info));
+#if !defined(FOR_MSW) && !defined(AMIGA)
+ FUNC(XpmCreatePixmapFromXpmImage, int, (Display *display,
+ Drawable d,
+ XpmImage *image,
+ Pixmap *pixmap_return,
+ Pixmap *shapemask_return,
+ XpmAttributes *attributes));
+#endif
+ FUNC(XpmCreateImageFromXpmImage, int, (Display *display,
+ XpmImage *image,
+ XImage **image_return,
+ XImage **shapeimage_return,
+ XpmAttributes *attributes));
+
+ FUNC(XpmCreateXpmImageFromImage, int, (Display *display,
+ XImage *image,
+ XImage *shapeimage,
+ XpmImage *xpmimage,
+ XpmAttributes *attributes));
+#if !defined(FOR_MSW) && !defined(AMIGA)
+ FUNC(XpmCreateXpmImageFromPixmap, int, (Display *display,
+ Pixmap pixmap,
+ Pixmap shapemask,
+ XpmImage *xpmimage,
+ XpmAttributes *attributes));
+#endif
+ FUNC(XpmCreateDataFromXpmImage, int, (char ***data_return,
+ XpmImage *image,
+ XpmInfo *info));
+
+ FUNC(XpmCreateXpmImageFromData, int, (char **data,
+ XpmImage *image,
+ XpmInfo *info));
+
+ FUNC(XpmCreateXpmImageFromBuffer, int, (char *buffer,
+ XpmImage *image,
+ XpmInfo *info));
+
+ FUNC(XpmCreateBufferFromXpmImage, int, (char **buffer_return,
+ XpmImage *image,
+ XpmInfo *info));
+
+ FUNC(XpmGetParseError, int, (char *filename,
+ int *linenum_return,
+ int *charnum_return));
+
+ FUNC(XpmFree, void, (void *ptr));
+
+#ifdef __cplusplus
+} /* for C++ V2.0 */
+#endif
+
+
+/* backward compatibility */
+
+/* for version 3.0c */
+#define XpmPixmapColorError XpmColorError
+#define XpmPixmapSuccess XpmSuccess
+#define XpmPixmapOpenFailed XpmOpenFailed
+#define XpmPixmapFileInvalid XpmFileInvalid
+#define XpmPixmapNoMemory XpmNoMemory
+#define XpmPixmapColorFailed XpmColorFailed
+
+#define XpmReadPixmapFile(dpy, d, file, pix, mask, att) \
+ XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
+#define XpmWritePixmapFile(dpy, file, pix, mask, att) \
+ XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
+
+/* for version 3.0b */
+#define PixmapColorError XpmColorError
+#define PixmapSuccess XpmSuccess
+#define PixmapOpenFailed XpmOpenFailed
+#define PixmapFileInvalid XpmFileInvalid
+#define PixmapNoMemory XpmNoMemory
+#define PixmapColorFailed XpmColorFailed
+
+#define ColorSymbol XpmColorSymbol
+
+#define XReadPixmapFile(dpy, d, file, pix, mask, att) \
+ XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
+#define XWritePixmapFile(dpy, file, pix, mask, att) \
+ XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
+#define XCreatePixmapFromData(dpy, d, data, pix, mask, att) \
+ XpmCreatePixmapFromData(dpy, d, data, pix, mask, att)
+#define XCreateDataFromPixmap(dpy, data, pix, mask, att) \
+ XpmCreateDataFromPixmap(dpy, data, pix, mask, att)
+
+#endif /* XPM_NUMBERS */
+#endif
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-/*****************************************************************************\
-* xpm.h: *
-* *
-* XPM library *
-* Include file *
-* *
-* Developed by Arnaud Le Hors *
-\*****************************************************************************/
-
-/*
- * The code related to FOR_MSW has been added by
- * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
- */
-
-#ifndef XPM_h
-#define XPM_h
-
-#if (defined(_WINDOWS) || defined(__WXMSW__) || defined(WIN32)) && !defined(FOR_MSW)
-#define FOR_MSW
-#endif
-/* Piggyback on MSW for now */
-#if (defined(__OS2__) || defined(__WXPM__) || defined(OS232)) && !defined(FOR_MSW)
-#define FOR_MSW
-#endif
-
-/*
- * first some identification numbers:
- * the following revision numbers is determined with the following rule:
- * SO Major number = LIB minor version number.
- * SO Minor number = LIB sub-minor version number.
- * e.g: Xpm version 3.2f
- * we forget the 3 which is the format number, 2 gives 2, and f gives 6.
- * thus we have XpmVersion = 2 and XpmRevision = 6
- * which gives SOXPMLIBREV = 2.6
- *
- * Then the XpmIncludeVersion number is built with the following rule:
- * (XpmFormat*100 + XpmVersion)*100 + XpmRevision
- */
-#define XpmFormat 3
-#define XpmVersion 4
-#define XpmRevision 2
-
-#define XpmIncludeVersion 30402
-
-#ifndef XPM_NUMBERS
-
-#ifdef VMS
-#include "decw$include:Xlib.h"
-#include "decw$include:Xutil.h"
-#else /* VMS */
-#ifdef FOR_MSW
-#define SYSV /* uses memcpy string.h etc. */
-#include <malloc.h>
-#include "simx.h" /* defines some X stuff using MSW types */
-#ifndef __GNUWIN32__
-#define NEED_STRCASECMP /* at least for MSVC++ */
-#endif
-#else /* FOR_MSW */
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <stdlib.h> /* HEDU */
-#endif /* FOR_MSW */
-#endif /* VMS */
-
-/* let's define Pixel if it is not done yet */
-#if ! defined(_XtIntrinsic_h) && ! defined(PIXEL_ALREADY_TYPEDEFED)
-typedef unsigned long Pixel; /* Index into colormap */
-#define PIXEL_ALREADY_TYPEDEFED
-#endif
-
-/* Return ErrorStatus codes:
- * null if full success
- * positive if partial success
- * negative if failure
- */
-
-#define XpmColorError 1
-#define XpmSuccess 0
-#define XpmOpenFailed -1
-#define XpmFileInvalid -2
-#define XpmNoMemory -3
-#define XpmColorFailed -4
-
-/* the following should help people wanting to use their own functions */
-#define XpmFree(ptr) free(ptr)
-
-typedef struct {
- char *name; /* Symbolic color name */
- char *value; /* Color value */
- Pixel pixel; /* Color pixel */
-} XpmColorSymbol;
-
-typedef struct {
- char *name; /* name of the extension */
- unsigned int nlines; /* number of lines in this extension */
- char **lines; /* pointer to the extension array of strings */
-} XpmExtension;
-
-typedef struct {
- char *string; /* characters string */
- char *symbolic; /* symbolic name */
- char *m_color; /* monochrom default */
- char *g4_color; /* 4 level grayscale default */
- char *g_color; /* other level grayscale default */
- char *c_color; /* color default */
-} XpmColor;
-
-typedef struct {
- unsigned int width; /* image width */
- unsigned int height; /* image height */
- unsigned int cpp; /* number of characters per pixel */
- unsigned int ncolors; /* number of colors */
- XpmColor *colorTable; /* list of related colors */
- unsigned int *data; /* image data */
-} XpmImage;
-
-typedef struct {
- unsigned long valuemask; /* Specifies which attributes are defined */
- char *hints_cmt; /* Comment of the hints section */
- char *colors_cmt; /* Comment of the colors section */
- char *pixels_cmt; /* Comment of the pixels section */
- unsigned int x_hotspot; /* Returns the x hotspot's coordinate */
- unsigned int y_hotspot; /* Returns the y hotspot's coordinate */
- unsigned int nextensions; /* number of extensions */
- XpmExtension *extensions; /* pointer to array of extensions */
-} XpmInfo;
-
-typedef struct {
- unsigned long valuemask; /* Specifies which attributes are
- * defined */
-
- Visual *visual; /* Specifies the visual to use */
- Colormap colormap; /* Specifies the colormap to use */
- unsigned int depth; /* Specifies the depth */
- unsigned int width; /* Returns the width of the created
- * pixmap */
- unsigned int height; /* Returns the height of the created
- * pixmap */
- unsigned int x_hotspot; /* Returns the x hotspot's
- * coordinate */
- unsigned int y_hotspot; /* Returns the y hotspot's
- * coordinate */
- unsigned int cpp; /* Specifies the number of char per
- * pixel */
- Pixel *pixels; /* List of used color pixels */
- unsigned int npixels; /* Number of pixels */
- XpmColorSymbol *colorsymbols; /* Array of color symbols to
- * override */
- unsigned int numsymbols; /* Number of symbols */
- char *rgb_fname; /* RGB text file name */
- unsigned int nextensions; /* number of extensions */
- XpmExtension *extensions; /* pointer to array of extensions */
-
- unsigned int ncolors; /* Number of colors */
- XpmColor *colorTable; /* Color table pointer */
-/* 3.2 backward compatibility code */
- char *hints_cmt; /* Comment of the hints section */
- char *colors_cmt; /* Comment of the colors section */
- char *pixels_cmt; /* Comment of the pixels section */
-/* end 3.2 bc */
- unsigned int mask_pixel; /* Transparent pixel's color table
- * index */
-
- /* Color Allocation Directives */
- unsigned int exactColors; /* Only use exact colors for visual */
- unsigned int closeness; /* Allowable RGB deviation */
- unsigned int red_closeness; /* Allowable red deviation */
- unsigned int green_closeness; /* Allowable green deviation */
- unsigned int blue_closeness; /* Allowable blue deviation */
- int color_key; /* Use colors from this color set */
-
-} XpmAttributes;
-
-/* XpmAttributes value masks bits */
-#define XpmVisual (1L<<0)
-#define XpmColormap (1L<<1)
-#define XpmDepth (1L<<2)
-#define XpmSize (1L<<3) /* width & height */
-#define XpmHotspot (1L<<4) /* x_hotspot & y_hotspot */
-#define XpmCharsPerPixel (1L<<5)
-#define XpmColorSymbols (1L<<6)
-#define XpmRgbFilename (1L<<7)
-/* 3.2 backward compatibility code */
-#define XpmInfos (1L<<8)
-#define XpmReturnInfos XpmInfos
-/* end 3.2 bc */
-#define XpmReturnPixels (1L<<9)
-#define XpmExtensions (1L<<10)
-#define XpmReturnExtensions XpmExtensions
-
-#define XpmExactColors (1L<<11)
-#define XpmCloseness (1L<<12)
-#define XpmRGBCloseness (1L<<13)
-#define XpmColorKey (1L<<14)
-
-#define XpmColorTable (1L<<15)
-#define XpmReturnColorTable XpmColorTable
-
-/* XpmInfo value masks bits */
-#define XpmComments XpmInfos
-#define XpmReturnComments XpmComments
-
-/* XpmAttributes mask_pixel value when there is no mask */
-#ifndef FOR_MSW
-#define XpmUndefPixel 0x80000000
-#else
-/* int is only 16 bit for MSW */
-#define XpmUndefPixel 0x8000
-#endif
-
-/*
- * color keys for visual type, they must fit along with the number key of
- * each related element in xpmColorKeys[] defined in xpmP.h
- */
-#define XPM_MONO 2
-#define XPM_GREY4 3
-#define XPM_GRAY4 3
-#define XPM_GREY 4
-#define XPM_GRAY 4
-#define XPM_COLOR 5
-
-
-/*
- * minimal portability layer between ansi and KR C
- */
-
-/* forward declaration of functions with prototypes */
-
-#if __STDC__ || defined(__cplusplus) || defined(c_plusplus)
- /* ANSI || C++ */
-#define FUNC(f, t, p) extern t f p
-#define LFUNC(f, t, p) static t f p
-/* #define LFUNC(f, t, p) t f p */
-#else /* K&R */
-#define FUNC(f, t, p) extern t f()
-#define LFUNC(f, t, p) static t f()
-/* #define LFUNC(f, t, p) t f() */
-#endif /* end of K&R */
-
-
-/*
- * functions declarations
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* For Microsoft C++ at any rate, the FUNC macro just doesn't work: it causes
- * arguments to be corrupted espec. in XpmWriteFileFromXpmImage.
- * So, define all prototypes explicitly.
- */
-#if defined(_MSC_VER) || defined(__OS2__)
-
-/* FOR_MSW, all ..Pixmap.. are excluded, only the ..XImage.. are used */
-
- int XpmCreateImageFromData(Display *display,
- char **data,
- XImage **image_return,
- XImage **shapemask_return,
- XpmAttributes *attributes);
-
- int XpmCreateDataFromImage(Display *display,
- char ***data_return,
- XImage *image,
- XImage *shapeimage,
- XpmAttributes *attributes);
-
- int XpmReadFileToImage(Display *display,
- char *filename,
- XImage **image_return,
- XImage **shapeimage_return,
- XpmAttributes *attributes);
-
- int XpmWriteFileFromImage(Display *display,
- char *filename,
- XImage *image,
- XImage *shapeimage,
- XpmAttributes *attributes);
-
- int XpmCreateImageFromBuffer(Display *display,
- char *buffer,
- XImage **image_return,
- XImage **shapemask_return,
- XpmAttributes *attributes);
-
- int XpmReadFileToBuffer(char *filename, char **buffer_return);
- int XpmWriteFileFromBuffer(char *filename, char *buffer);
-
- int XpmReadFileToData(char *filename, char ***data_return);
- int XpmWriteFileFromData(char *filename, char **data);
-
- int XpmAttributesSize();
- void XpmFreeAttributes(XpmAttributes *attributes);
- void XpmFreeExtensions(XpmExtension *extensions,
- int nextensions);
-
- void XpmFreeXpmImage(XpmImage *image);
- void XpmFreeXpmInfo(XpmInfo *info);
- char *XpmGetErrorString(int errcode);
- int XpmLibraryVersion();
-
- /* XpmImage functions */
- int XpmReadFileToXpmImage(char *filename,
- XpmImage *image,
- XpmInfo *info);
-
- int XpmWriteFileFromXpmImage(char *filename,
- XpmImage *image,
- XpmInfo *info);
-
- int XpmWriteFileFromXpmImage(char *filename, XpmImage *image, XpmInfo *info);
-
- int XpmCreateImageFromXpmImage(Display *display,
- XpmImage *image,
- XImage **image_return,
- XImage **shapeimage_return,
- XpmAttributes *attributes);
-
- int XpmCreateXpmImageFromImage(Display *display,
- XImage *image,
- XImage *shapeimage,
- XpmImage *xpmimage,
- XpmAttributes *attributes);
- int XpmCreateDataFromXpmImage(char ***data_return,
- XpmImage *image,
- XpmInfo *info);
-
- int XpmCreateXpmImageFromData(char **data,
- XpmImage *image,
- XpmInfo *info);
-
- int XpmCreateXpmImageFromBuffer(char *buffer,
- XpmImage *image,
- XpmInfo *info);
-
- int XpmCreateBufferFromXpmImage(char **buffer_return,
- XpmImage *image,
- XpmInfo *info);
-
-#else // _MSC_VER
-
-/* FOR_MSW, all ..Pixmap.. are excluded, only the ..XImage.. are used */
-
-#ifndef FOR_MSW
- FUNC(XpmCreatePixmapFromData, int, (Display *display,
- Drawable d,
- char **data,
- Pixmap *pixmap_return,
- Pixmap *shapemask_return,
- XpmAttributes *attributes));
-
- FUNC(XpmCreateDataFromPixmap, int, (Display *display,
- char ***data_return,
- Pixmap pixmap,
- Pixmap shapemask,
- XpmAttributes *attributes));
-
- FUNC(XpmReadFileToPixmap, int, (Display *display,
- Drawable d,
- char *filename,
- Pixmap *pixmap_return,
- Pixmap *shapemask_return,
- XpmAttributes *attributes));
-
- FUNC(XpmWriteFileFromPixmap, int, (Display *display,
- char *filename,
- Pixmap pixmap,
- Pixmap shapemask,
- XpmAttributes *attributes));
-#endif /* ndef FOR_MSW */
-
- FUNC(XpmCreateImageFromData, int, (Display *display,
- char **data,
- XImage **image_return,
- XImage **shapemask_return,
- XpmAttributes *attributes));
-
- FUNC(XpmCreateDataFromImage, int, (Display *display,
- char ***data_return,
- XImage *image,
- XImage *shapeimage,
- XpmAttributes *attributes));
-
- FUNC(XpmReadFileToImage, int, (Display *display,
- char *filename,
- XImage **image_return,
- XImage **shapeimage_return,
- XpmAttributes *attributes));
-
- FUNC(XpmWriteFileFromImage, int, (Display *display,
- char *filename,
- XImage *image,
- XImage *shapeimage,
- XpmAttributes *attributes));
-
- FUNC(XpmCreateImageFromBuffer, int, (Display *display,
- char *buffer,
- XImage **image_return,
- XImage **shapemask_return,
- XpmAttributes *attributes));
-#ifndef FOR_MSW
- FUNC(XpmCreatePixmapFromBuffer, int, (Display *display,
- Drawable d,
- char *buffer,
- Pixmap *pixmap_return,
- Pixmap *shapemask_return,
- XpmAttributes *attributes));
-
- FUNC(XpmCreateBufferFromImage, int, (Display *display,
- char **buffer_return,
- XImage *image,
- XImage *shapeimage,
- XpmAttributes *attributes));
-
- FUNC(XpmCreateBufferFromPixmap, int, (Display *display,
- char **buffer_return,
- Pixmap pixmap,
- Pixmap shapemask,
- XpmAttributes *attributes));
-#endif /* ndef FOR_MSW */
- FUNC(XpmReadFileToBuffer, int, (char *filename, char **buffer_return));
- FUNC(XpmWriteFileFromBuffer, int, (char *filename, char *buffer));
-
- FUNC(XpmReadFileToData, int, (char *filename, char ***data_return));
- FUNC(XpmWriteFileFromData, int, (char *filename, char **data));
-
- FUNC(XpmAttributesSize, int, ());
- FUNC(XpmFreeAttributes, void, (XpmAttributes *attributes));
- FUNC(XpmFreeExtensions, void, (XpmExtension *extensions,
- int nextensions));
-
- FUNC(XpmFreeXpmImage, void, (XpmImage *image));
- FUNC(XpmFreeXpmInfo, void, (XpmInfo *info));
- FUNC(XpmGetErrorString, char *, (int errcode));
- FUNC(XpmLibraryVersion, int, ());
-
- /* XpmImage functions */
- FUNC(XpmReadFileToXpmImage, int, (char *filename,
- XpmImage *image,
- XpmInfo *info));
-
- FUNC(XpmWriteFileFromXpmImage, int, (char *filename,
- XpmImage *image,
- XpmInfo *info));
-
- FUNC(XpmWriteFileFromXpmImage, int, (char *filename, XpmImage *image, XpmInfo *info));
-/* extern int XpmWriteFileFromXpmImage(char *filename, XpmImage *image, XpmInfo *info); */
-
-#ifndef FOR_MSW
- FUNC(XpmCreatePixmapFromXpmImage, int, (Display *display,
- Drawable d,
- XpmImage *image,
- Pixmap *pixmap_return,
- Pixmap *shapemask_return,
- XpmAttributes *attributes));
-#endif
- FUNC(XpmCreateImageFromXpmImage, int, (Display *display,
- XpmImage *image,
- XImage **image_return,
- XImage **shapeimage_return,
- XpmAttributes *attributes));
-
- FUNC(XpmCreateXpmImageFromImage, int, (Display *display,
- XImage *image,
- XImage *shapeimage,
- XpmImage *xpmimage,
- XpmAttributes *attributes));
-#ifndef FOR_MSW
- FUNC(XpmCreateXpmImageFromPixmap, int, (Display *display,
- Pixmap pixmap,
- Pixmap shapemask,
- XpmImage *xpmimage,
- XpmAttributes *attributes));
-#endif
- FUNC(XpmCreateDataFromXpmImage, int, (char ***data_return,
- XpmImage *image,
- XpmInfo *info));
-
- FUNC(XpmCreateXpmImageFromData, int, (char **data,
- XpmImage *image,
- XpmInfo *info));
-
- FUNC(XpmCreateXpmImageFromBuffer, int, (char *buffer,
- XpmImage *image,
- XpmInfo *info));
-
- FUNC(XpmCreateBufferFromXpmImage, int, (char **buffer_return,
- XpmImage *image,
- XpmInfo *info));
-
-#endif // _MSC_VER
-
-#ifdef __cplusplus
-} /* for C++ V2.0 */
-#endif
-
-
-/* backward compatibility */
-
-/* for version 3.0c */
-#define XpmPixmapColorError XpmColorError
-#define XpmPixmapSuccess XpmSuccess
-#define XpmPixmapOpenFailed XpmOpenFailed
-#define XpmPixmapFileInvalid XpmFileInvalid
-#define XpmPixmapNoMemory XpmNoMemory
-#define XpmPixmapColorFailed XpmColorFailed
-
-#define XpmReadPixmapFile(dpy, d, file, pix, mask, att) \
- XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
-#define XpmWritePixmapFile(dpy, file, pix, mask, att) \
- XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
-
-/* for version 3.0b */
-#define PixmapColorError XpmColorError
-#define PixmapSuccess XpmSuccess
-#define PixmapOpenFailed XpmOpenFailed
-#define PixmapFileInvalid XpmFileInvalid
-#define PixmapNoMemory XpmNoMemory
-#define PixmapColorFailed XpmColorFailed
-
-#define ColorSymbol XpmColorSymbol
-
-#define XReadPixmapFile(dpy, d, file, pix, mask, att) \
- XpmReadFileToPixmap(dpy, d, file, pix, mask, att)
-#define XWritePixmapFile(dpy, file, pix, mask, att) \
- XpmWriteFileFromPixmap(dpy, file, pix, mask, att)
-#define XCreatePixmapFromData(dpy, d, data, pix, mask, att) \
- XpmCreatePixmapFromData(dpy, d, data, pix, mask, att)
-#define XCreateDataFromPixmap(dpy, data, pix, mask, att) \
- XpmCreateDataFromPixmap(dpy, data, pix, mask, att)
-
-#endif /* XPM_NUMBERS */
-#endif
+++ /dev/null
-/*
- * Copyright (C) 1989-94 GROUPE BULL
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * 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
- * GROUPE BULL 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 GROUPE BULL shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from GROUPE BULL.
- */
-
-/*****************************************************************************\
-* xpmP.h: *
-* *
-* XPM library *
-* Private Include file *
-* *
-* Developed by Arnaud Le Hors *
-\*****************************************************************************/
-
-/*
- * The code related to FOR_MSW has been added by
- * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
- */
-
-#ifndef XPMP_h
-#define XPMP_h
-
-#include "xpm34.h"
-
-/*
- * lets try to solve include files
- */
-#ifdef VMS
-
-#include "sys$library:stdio.h"
-#include "sys$library:string.h"
-
-#else /* VMS */
-
-#include <stdio.h>
-/* stdio.h doesn't declare popen on a Sequent DYNIX OS */
-#ifdef sequent
-extern FILE *popen();
-#endif
-
-#if defined(SYSV) || defined(SVR4)
-#include <string.h>
-
-#ifndef index
-#define index strchr
-#endif
-
-#ifndef rindex
-#define rindex strrchr
-#endif
-
-#else /* defined(SYSV) || defined(SVR4) */
-#include <strings.h>
-#endif
-
-#endif /* VMS */
-
-
-#if (defined(SYSV) || defined(SVR4) || defined(VMS)) && !defined(__sgi)
-#define bcopy(source, dest, count) memcpy(dest, source, count)
-#define bzero(b, len) memset(b, 0, len)
-#endif
-
-
-/* the following should help people wanting to use their own functions */
-#ifndef FOR_MSW
-#define XpmMalloc(size) malloc((size))
-#define XpmRealloc(ptr, size) realloc((ptr), (size))
-#define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
-#else
-/* checks for mallocs bigger than 64K */
-#define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */
-#define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size))
-#define XpmCalloc(nelem, elsize) \
- boundCheckingCalloc((long)(nelem),(long) (elsize))
-#endif
-
-
-typedef struct {
- unsigned int type;
- union {
- FILE *file;
- char **data;
- } stream;
- char *cptr;
- unsigned int line;
- int CommentLength;
- char Comment[BUFSIZ];
- char *Bcmt, *Ecmt, Bos, Eos;
- int format; /* 1 if XPM1, 0 otherwise */
-} xpmData;
-
-#define XPMARRAY 0
-#define XPMFILE 1
-#define XPMPIPE 2
-#define XPMBUFFER 3
-
-#define EOL '\n'
-#define TAB '\t'
-#define SPC ' '
-
-typedef struct {
- char *type; /* key word */
- char *Bcmt; /* string beginning comments */
- char *Ecmt; /* string ending comments */
- char Bos; /* character beginning strings */
- char Eos; /* character ending strings */
- char *Strs; /* strings separator */
- char *Dec; /* data declaration string */
- char *Boa; /* string beginning assignment */
- char *Eoa; /* string ending assignment */
-} xpmDataType;
-
-extern xpmDataType xpmDataTypes[];
-
-/*
- * rgb values and ascii names (from rgb text file) rgb values,
- * range of 0 -> 65535 color mnemonic of rgb value
- */
-typedef struct {
- int r, g, b;
- char *name;
-} xpmRgbName;
-
-/* Maximum number of rgb mnemonics allowed in rgb text file. */
-#define MAX_RGBNAMES 1024
-
-extern char *xpmColorKeys[];
-
-#define TRANSPARENT_COLOR "None" /* this must be a string! */
-
-/* number of xpmColorKeys */
-#define NKEYS 5
-
-/* XPM private routines */
-
-FUNC(xpmWriteData, int, (xpmData *mdata, XpmImage *image, char *name,
- XpmInfo *info));
-
-FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
-
-FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
-
-FUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
-
-FUNC(xpmInitXpmImage, void, (XpmImage *image));
-
-FUNC(xpmInitXpmInfo, void, (XpmInfo *info));
-
-FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
-FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
-FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
- XpmInfo *info));
-
-#ifndef FOR_MSW
-FUNC(xpmCreatePixmapFromImage, void, (Display *display, Drawable d,
- XImage *ximage, Pixmap *pixmap_return));
-
-FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
- XImage **ximage_return,
- unsigned int *width,
- unsigned int *height));
-#endif
-
-/* I/O utility */
-
-FUNC(xpmNextString, int, (xpmData *mdata));
-FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
-FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
-
-#define xpmGetC(mdata) \
- ((!mdata->type || mdata->type == XPMBUFFER) ? \
- (*mdata->cptr++) : (getc(mdata->stream.file)))
-
-FUNC(xpmNextWord, unsigned int,
- (xpmData *mdata, char *buf, unsigned int buflen));
-FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
-FUNC(xpmReadFile, int, (char *filename, xpmData *mdata));
-FUNC(xpmWriteFile, int, (char *filename, xpmData *mdata));
-FUNC(xpmOpenArray, void, (char **data, xpmData *mdata));
-FUNC(xpmDataClose, int, (xpmData *mdata));
-FUNC(xpmParseHeader, int, (xpmData *mdata));
-FUNC(xpmOpenBuffer, void, (char *buffer, xpmData *mdata));
-
-/* RGB utility */
-
-FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn));
-FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
- int red, int green, int blue));
-FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
-#ifdef FOR_MSW
-FUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
-#endif
-
-FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
- register XImage *img));
-FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
- register XImage *img));
-
-/*
- * Macros
- *
- * The XYNORMALIZE macro determines whether XY format data requires
- * normalization and calls a routine to do so if needed. The logic in
- * this module is designed for LSBFirst byte and bit order, so
- * normalization is done as required to present the data in this order.
- *
- * The ZNORMALIZE macro performs byte and nibble order normalization if
- * required for Z format data.
- *
- * The XYINDEX macro computes the index to the starting byte (char) boundary
- * for a bitmap_unit containing a pixel with coordinates x and y for image
- * data in XY format.
- *
- * The ZINDEX* macros compute the index to the starting byte (char) boundary
- * for a pixel with coordinates x and y for image data in ZPixmap format.
- *
- */
-
-#define XYNORMALIZE(bp, img) \
- if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
- xpm_xynormalizeimagebits((unsigned char *)(bp), img)
-
-#define ZNORMALIZE(bp, img) \
- if (img->byte_order == MSBFirst) \
- xpm_znormalizeimagebits((unsigned char *)(bp), img)
-
-#define XYINDEX(x, y, img) \
- ((y) * img->bytes_per_line) + \
- (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
-
-#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
- (((x) * img->bits_per_pixel) >> 3)
-
-#define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
-
-#define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
-
-#define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
-
-#define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
-
-#if __STDC__
-#define Const const
-#else
-#define Const /**/
-#endif
-
-/*
- * there are structures and functions related to hastable code
- */
-
-typedef struct _xpmHashAtom {
- char *name;
- void *data;
-} *xpmHashAtom;
-
-typedef struct {
- int size;
- int limit;
- int used;
- xpmHashAtom *atomTable;
-} xpmHashTable;
-
-FUNC(xpmHashTableInit, int, (xpmHashTable *table));
-FUNC(xpmHashTableFree, void, (xpmHashTable *table));
-FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
-FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
-
-#define HashAtomData(i) ((void *)i)
-#define HashColorIndex(slot) ((unsigned int)(unsigned long)((*slot)->data))
-#define USE_HASHTABLE (cpp > 2 && ncolors > 4)
-
-#ifdef NEED_STRDUP
-FUNC(strdup, char *, (char *s1));
-#endif
-
-#ifdef NEED_STRCASECMP
-FUNC(strcasecmp, int, (char *s1, char *s2));
-#endif
-
-FUNC(atoui, unsigned int, (char *p, unsigned int l, unsigned int *ui_return));
-
-#endif
--- /dev/null
+/*
+ * Copyright (C) 1989-95 GROUPE BULL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 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
+ * GROUPE BULL 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 GROUPE BULL shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from GROUPE BULL.
+ */
+
+/*****************************************************************************\
+* XpmI.h: *
+* *
+* XPM library *
+* Internal Include file *
+* *
+* ** Everything defined here is subject to changes any time. ** *
+* *
+* Developed by Arnaud Le Hors *
+\*****************************************************************************/
+
+/*
+ * The code related to FOR_MSW has been added by
+ * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
+ */
+
+#ifndef XPMI_h
+#define XPMI_h
+
+#include "xpm.h"
+
+/*
+ * lets try to solve include files
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+/* stdio.h doesn't declare popen on a Sequent DYNIX OS */
+#ifdef sequent
+extern FILE *popen();
+#endif
+
+#if defined(SYSV) || defined(SVR4) || defined(VMS) || defined(WIN32)
+#include <string.h>
+
+#ifndef index
+#define index strchr
+#endif
+
+#ifndef rindex
+#define rindex strrchr
+#endif
+
+#else /* defined(SYSV) || defined(SVR4) || defined(VMS) */
+#include <strings.h>
+#endif
+
+
+
+#if defined(SYSV) || defined(SVR4) || defined(VMS) || defined(WIN32)
+#ifndef bcopy
+#define bcopy(source, dest, count) memcpy(dest, source, count)
+#endif
+#ifndef bzero
+#define bzero(b, len) memset(b, 0, len)
+#endif
+#endif
+
+/* the following is defined in X11R6 but not in previous versions */
+#ifdef __alpha
+#ifndef LONG64
+#define LONG64
+#endif
+#endif
+
+#ifdef VMS
+#include <unixio.h>
+#include <file.h>
+#endif
+
+/* The following should help people wanting to use their own memory allocation
+ * functions. To avoid the overhead of a function call when the standard
+ * functions are used these are all macros, even the XpmFree function which
+ * needs to be a real function for the outside world though.
+ * So if change these be sure to change the XpmFree function in misc.c
+ * accordingly.
+ */
+#define XpmFree(ptr) free(ptr)
+
+#ifndef FOR_MSW
+#define XpmMalloc(size) malloc((size))
+#define XpmRealloc(ptr, size) realloc((ptr), (size))
+#define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
+#else
+/* checks for mallocs bigger than 64K */
+#define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */
+#define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size))
+#define XpmCalloc(nelem, elsize) \
+ boundCheckingCalloc((long)(nelem),(long) (elsize))
+#endif
+
+#define XPMMAXCMTLEN BUFSIZ
+typedef struct {
+ unsigned int type;
+ union {
+ FILE *file;
+ char **data;
+ } stream;
+ char *cptr;
+ unsigned int line;
+ int CommentLength;
+ char Comment[XPMMAXCMTLEN];
+ char *Bcmt, *Ecmt, Bos, Eos;
+ int format; /* 1 if XPM1, 0 otherwise */
+#ifdef CXPMPROG
+ int lineNum;
+ int charNum;
+#endif
+} xpmData;
+
+#define XPMARRAY 0
+#define XPMFILE 1
+#define XPMPIPE 2
+#define XPMBUFFER 3
+
+#define EOL '\n'
+#define TAB '\t'
+#define SPC ' '
+
+typedef struct {
+ char *type; /* key word */
+ char *Bcmt; /* string beginning comments */
+ char *Ecmt; /* string ending comments */
+ char Bos; /* character beginning strings */
+ char Eos; /* character ending strings */
+ char *Strs; /* strings separator */
+ char *Dec; /* data declaration string */
+ char *Boa; /* string beginning assignment */
+ char *Eoa; /* string ending assignment */
+} xpmDataType;
+
+extern xpmDataType xpmDataTypes[];
+
+/*
+ * rgb values and ascii names (from rgb text file) rgb values,
+ * range of 0 -> 65535 color mnemonic of rgb value
+ */
+typedef struct {
+ int r, g, b;
+ char *name;
+} xpmRgbName;
+
+/* Maximum number of rgb mnemonics allowed in rgb text file. */
+#define MAX_RGBNAMES 1024
+
+extern char *xpmColorKeys[];
+
+#define TRANSPARENT_COLOR "None" /* this must be a string! */
+
+/* number of xpmColorKeys */
+#define NKEYS 5
+
+/* XPM internal routines */
+
+FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
+FUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data,
+ XImage **image_return,
+ XImage **shapeimage_return,
+ XpmImage *image, XpmInfo *info,
+ XpmAttributes *attributes));
+
+FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
+
+FUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
+
+FUNC(xpmInitXpmImage, void, (XpmImage *image));
+
+FUNC(xpmInitXpmInfo, void, (XpmInfo *info));
+
+FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
+FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
+FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
+ XpmInfo *info));
+
+#if !defined(FOR_MSW) && !defined(AMIGA)
+FUNC(xpmCreatePixmapFromImage, void, (Display *display, Drawable d,
+ XImage *ximage, Pixmap *pixmap_return));
+
+FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
+ XImage **ximage_return,
+ unsigned int *width,
+ unsigned int *height));
+#endif
+
+/* structures and functions related to hastable code */
+
+typedef struct _xpmHashAtom {
+ char *name;
+ void *data;
+} *xpmHashAtom;
+
+typedef struct {
+ int size;
+ int limit;
+ int used;
+ xpmHashAtom *atomTable;
+} xpmHashTable;
+
+FUNC(xpmHashTableInit, int, (xpmHashTable *table));
+FUNC(xpmHashTableFree, void, (xpmHashTable *table));
+FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
+FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
+
+#define HashAtomData(i) ((void *)i)
+#define HashColorIndex(slot) ((unsigned int)((*slot)->data))
+#define USE_HASHTABLE (cpp > 2 && ncolors > 4)
+
+/* I/O utility */
+
+FUNC(xpmNextString, int, (xpmData *mdata));
+FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
+FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
+
+#define xpmGetC(mdata) \
+ ((!mdata->type || mdata->type == XPMBUFFER) ? \
+ (*mdata->cptr++) : (getc(mdata->stream.file)))
+
+FUNC(xpmNextWord, unsigned int,
+ (xpmData *mdata, char *buf, unsigned int buflen));
+FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
+FUNC(xpmParseHeader, int, (xpmData *mdata));
+FUNC(xpmParseValues, int, (xpmData *data, unsigned int *width,
+ unsigned int *height, unsigned int *ncolors,
+ unsigned int *cpp, unsigned int *x_hotspot,
+ unsigned int *y_hotspot, unsigned int *hotspot,
+ unsigned int *extensions));
+
+FUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors,
+ unsigned int cpp, XpmColor **colorTablePtr,
+ xpmHashTable *hashtable));
+
+FUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions,
+ unsigned int *nextensions));
+
+/* RGB utility */
+
+FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn));
+FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
+ int red, int green, int blue));
+FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
+#ifdef FOR_MSW
+FUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
+#endif
+
+#ifndef AMIGA
+FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
+ register XImage *img));
+FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
+ register XImage *img));
+
+/*
+ * Macros
+ *
+ * The XYNORMALIZE macro determines whether XY format data requires
+ * normalization and calls a routine to do so if needed. The logic in
+ * this module is designed for LSBFirst byte and bit order, so
+ * normalization is done as required to present the data in this order.
+ *
+ * The ZNORMALIZE macro performs byte and nibble order normalization if
+ * required for Z format data.
+ *
+ * The XYINDEX macro computes the index to the starting byte (char) boundary
+ * for a bitmap_unit containing a pixel with coordinates x and y for image
+ * data in XY format.
+ *
+ * The ZINDEX* macros compute the index to the starting byte (char) boundary
+ * for a pixel with coordinates x and y for image data in ZPixmap format.
+ *
+ */
+
+#define XYNORMALIZE(bp, img) \
+ if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
+ xpm_xynormalizeimagebits((unsigned char *)(bp), img)
+
+#define ZNORMALIZE(bp, img) \
+ if (img->byte_order == MSBFirst) \
+ xpm_znormalizeimagebits((unsigned char *)(bp), img)
+
+#define XYINDEX(x, y, img) \
+ ((y) * img->bytes_per_line) + \
+ (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
+
+#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
+ (((x) * img->bits_per_pixel) >> 3)
+
+#define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
+
+#define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
+
+#define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
+
+#define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
+#endif /* not AMIGA */
+
+#ifdef __STDC__
+#define Const const
+#else
+#define Const /**/
+#endif
+
+#ifdef NEED_STRDUP
+FUNC(xpmstrdup, char *, (char *s1));
+#else
+#undef xpmstrdup
+#define xpmstrdup strdup
+#endif
+
+#ifdef NEED_STRCASECMP
+FUNC(xpmstrcasecmp, int, (char *s1, char *s2));
+#else
+#undef xpmstrcasecmp
+#define xpmstrcasecmp strcasecmp
+#endif
+
+FUNC(xpmatoui, unsigned int,
+ (char *p, unsigned int l, unsigned int *ui_return));
+
+#endif