X-Git-Url: http://git.ieval.ro/?p=xfishtank.git;a=blobdiff_plain;f=src%2Fixpm.c;fp=src%2Fixpm.c;h=f885c5a62fbbd9094eb20fa3adb748cc149975ad;hp=0000000000000000000000000000000000000000;hb=da1c4a843de05b6ee70dc60fa1fcb4b5ec2d606e;hpb=46b872af07138bfc36763f380b876098af4a6b5d diff --git a/src/ixpm.c b/src/ixpm.c new file mode 100644 index 0000000..f885c5a --- /dev/null +++ b/src/ixpm.c @@ -0,0 +1,385 @@ +/* -copyright- +#-# Copyright © 2021 Eric Bina, Dave Black, TJ Phan, +#-# Vincent Renardias, Willem Vermin +#-# +#-# 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 THE AUTHORS OR COPYRIGHT +#-# HOLDERS 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. +#-# +*/ +#include +#include +#include +#include +#include "ixpm.h" +#include "debug.h" +#include "utils.h" +// from the xpm package: +static void xpmCreatePixmapFromImage( + Display *display, + Drawable d, + XImage *ximage, + Pixmap *pixmap_return) +{ + GC gc; + XGCValues values; + + *pixmap_return = XCreatePixmap(display, d, ximage->width, + ximage->height, ximage->depth); + /* set fg and bg in case we have an XYBitmap */ + values.foreground = 1; + values.background = 0; + gc = XCreateGC(display, *pixmap_return, + GCForeground | GCBackground, &values); + + XPutImage(display, *pixmap_return, gc, ximage, 0, 0, 0, 0, + ximage->width, ximage->height); + + XFreeGC(display, gc); +} + +void paintit(XImage *img, long int color) +{ + int x,y; + for (y=0; yheight; y++) + for (x=0; xwidth; x++) + { + XPutPixel(img, x,y,color); + } +} + + +// reverse characters in string, characters taken in chunks of l +// if you know what I mean +static void strrevert(char*s, size_t l) +{ + assert(l>0); + size_t n = strlen(s)/l; + size_t i; + char *c = (char *)malloc(l*sizeof(*c)); + char *a = s; + char *b = s+strlen(s)-l; + for (i=0; i0); + idata = (char **)malloc(lines*sizeof(*idata)); + for (i=0; i (size_t)cpp + 6) + { + sscanf(xpm[i]+cpp,"%*s %100s",s); + if(!strcasecmp(s,"none")) + { + free(code); + code = strndup(xpm[i],cpp); + break; + } + } + } + int y; + unsigned char c = 0; + int j = 0; + if (is_little_endian()) + for (y=0; y>= 1; + if (cpp*x + cpp <= l) + { + if (strncmp(s+cpp*x,code,cpp)) + c |= 0x80; + } + k++; + if (k == 8) + { + bits[j++] = c; + k = 0; + } + } + if (k) + bits[j++] = c>>(8-k); + } + else + for (y=0; y0); + *out = (char**)malloc(sizeof(char *)*(n+3)); + char **x = *out; + int j; + for (j=0; j<2; j++) + x[j] = strdup(data[j]); + x[2] = (char *)malloc(5+strlen(color)); + x[2][0] = '\0'; + strcat(x[2],". c "); + strcat(x[2],color); + P("c: [%s]\n",x[2]); + + for (j=3; j