X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cfbe03c9c3ffecd6363dcc63e6fc27b8c6ed70aa..8290d43d0d43369d007f1c47abf98a45da461a30:/src/xpm/crbuffri.c?ds=sidebyside diff --git a/src/xpm/crbuffri.c b/src/xpm/crbuffri.c index ed83271ff4..f728fe48f7 100644 --- a/src/xpm/crbuffri.c +++ b/src/xpm/crbuffri.c @@ -1,5 +1,5 @@ /* - * 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 @@ -24,7 +24,7 @@ */ /*****************************************************************************\ -* XpmCrBufFrI.c: * +* CrBufFrI.c: * * * * XPM library * * Scan an image and possibly its mask and create an XPM buffer * @@ -32,16 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpm34p.h" -#ifdef VMS -#include "sys$library:string.h" -#else -#if defined(SYSV) || defined(SVR4) -#include -#else -#include -#endif -#endif +#include "XpmI.h" LFUNC(WriteColors, int, (char **dataptr, unsigned int *data_size, unsigned int *used_size, XpmColor *colors, @@ -58,9 +49,24 @@ LFUNC(WriteExtensions, void, (char *dataptr, unsigned int *used_size, LFUNC(ExtensionsSize, int, (XpmExtension *ext, unsigned int num)); LFUNC(CommentsSize, int, (XpmInfo *info)); +#ifdef __OS2__ +/* Visual Age cannot deal with old, non-ansi, code */ +int XpmCreateBufferFromImage( + Display* display +, char** buffer_return +, XImage* image +, XImage* shapeimage +, XpmAttributes* attributes +) +#else 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; +#endif { XpmImage xpmimage; XpmInfo info; @@ -95,13 +101,20 @@ XpmCreateBufferFromImage(Display *display, char **buffer_return, XImage *image, #undef RETURN #define RETURN(status) \ { \ - if (ptr) \ - XpmFree(ptr); \ - return(status); \ + ErrorStatus = status; \ + goto error; \ } +#ifdef __OS2__ +/* Visual Age cannot deal with old, non-ansi, code */ +int XpmCreateBufferFromXpmImage(char** buffer_return, XpmImage* image, XpmInfo* info) +#else int -XpmCreateBufferFromXpmImage(char **buffer_return, XpmImage *image, XpmInfo *info) +XpmCreateBufferFromXpmImage(buffer_return, image, info) + char **buffer_return; + XpmImage *image; + XpmInfo *info; +#endif { /* calculation variables */ int ErrorStatus; @@ -124,8 +137,13 @@ XpmCreateBufferFromXpmImage(char **buffer_return, XpmImage *image, XpmInfo *info 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) @@ -134,23 +152,48 @@ XpmCreateBufferFromXpmImage(char **buffer_return, XpmImage *image, XpmInfo *info /* 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) @@ -161,19 +204,24 @@ XpmCreateBufferFromXpmImage(char **buffer_return, XpmImage *image, XpmInfo *info /* 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); - + if (ErrorStatus != XpmSuccess) 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; @@ -184,8 +232,13 @@ XpmCreateBufferFromXpmImage(char **buffer_return, XpmImage *image, XpmInfo *info /* 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); @@ -196,16 +249,39 @@ XpmCreateBufferFromXpmImage(char **buffer_return, XpmImage *image, XpmInfo *info 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); } +#ifdef __OS2__ +/* Visual Age cannot deal with old, non-ansi, code */ +static int WriteColors( + char** dataptr +, unsigned int* data_size +, unsigned int* used_size +, XpmColor* colors +, unsigned int ncolors +, unsigned int cpp +) +#else 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; +#endif { char buf[BUFSIZ]; unsigned int a, key, l; @@ -222,12 +298,17 @@ WriteColors(char **dataptr, unsigned int *data_size, unsigned int *used_size, 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); @@ -239,9 +320,28 @@ WriteColors(char **dataptr, unsigned int *data_size, unsigned int *used_size, return (XpmSuccess); } +#ifdef __OS2__ +/* Visual Age cannot deal with old, non-ansi, code */ +static void WritePixels( + char* dataptr +, unsigned int* used_size +, unsigned int width +, unsigned int height +, unsigned int cpp +, unsigned int* pixels +, XpmColor* colors +) +#else 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; +#endif { char *s = dataptr; unsigned int x, y, h; @@ -266,8 +366,16 @@ WritePixels(char *dataptr, unsigned int *used_size, unsigned int width, unsigned *used_size += s - dataptr; } +#ifdef __OS2__ +/* Visual Age cannot deal with old, non-ansi, code */ static int -ExtensionsSize(XpmExtension *ext, unsigned int num) +ExtensionsSize(XpmExtension* ext, unsigned int num) +#else +static int +ExtensionsSize(ext, num) + XpmExtension *ext; + unsigned int num; +#endif { unsigned int x, y, a, size; char **line; @@ -285,28 +393,57 @@ ExtensionsSize(XpmExtension *ext, unsigned int num) return size + 13; } +#ifdef __OS2__ +/* Visual Age cannot deal with old, non-ansi, code */ +static void WriteExtensions( + char* dataptr +, unsigned int* used_size +, XpmExtension* ext +, unsigned int num +) +#else 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; +#endif { 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\""); *used_size += s - dataptr + 13; } -static int -CommentsSize(XpmInfo *info) +#ifdef __OS2__ +/* Visual Age cannot deal with old, non-ansi, code */ +static int CommentsSize(XpmInfo* info) +#else +static int CommentsSize(info) + XpmInfo *info; +#endif { int size = 0;