From 16e9630b79f0a7a90c6cedb6781175bb8b337dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 29 Apr 2017 12:11:08 +0200 Subject: New upstream version 4.3.0 --- app/wlib/gtklib/pixbuf.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 app/wlib/gtklib/pixbuf.c (limited to 'app/wlib/gtklib/pixbuf.c') diff --git a/app/wlib/gtklib/pixbuf.c b/app/wlib/gtklib/pixbuf.c new file mode 100644 index 0000000..7b8d7d1 --- /dev/null +++ b/app/wlib/gtklib/pixbuf.c @@ -0,0 +1,99 @@ +/** \file pixbuf.c + * Create pixbuf from various bitmap formats + */ + +/* + * + * Copyright 2016 Martin Fischer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +#include +#include + +#define GTK_DISABLE_SINGLE_INCLUDES +#define GDK_DISABLE_DEPRECATED +#define GTK_DISABLE_DEPRECATED +#define GSEAL_ENABLE + +#include +#include + +#include "gtkint.h" + +/** + * Create a pixbuf from a wIcon + * + * \param ip IN widget + * \returns a valid pixbuf + */ + +GdkPixbuf* wlibMakePixbuf( + wIcon_p ip) +{ + GdkPixbuf * pixbuf; + char line0[40]; + char line2[40]; + + assert(ip != NULL); + + if (ip->gtkIconType == gtkIcon_pixmap) { + pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)ip->bits); + } else { + const char * bits; + long rgb; + int row,col,wb; + char ** pixmapData; + + wb = (ip->w+7)/8; + pixmapData = (char**)g_malloc((3+ip->h) * sizeof *pixmapData); + pixmapData[0] = line0; + rgb = wDrawGetRGB(ip->color); + sprintf(line0, " %d %d 2 1", ip->w, ip->h); + sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb>>16)&0xFF, (rgb>>8)&0xFF, + rgb&0xFF); + pixmapData[1] = ". c None s None"; + pixmapData[2] = line2; + bits = ip->bits; + + for (row = 0; rowh; row++) { + pixmapData[row+3] = (char*)g_malloc((ip->w+1) * sizeof **pixmapData); + + for (col = 0; colw; col++) { + if (bits[ row*wb+(col>>3) ] & (1<<(col&07))) { + pixmapData[row+3][col] = '#'; + } else { + pixmapData[row+3][col] = '.'; + } + } + + pixmapData[row+3][ip->w] = 0; + } + + pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)pixmapData); + + for (row = 0; rowh; row++) { + g_free(pixmapData[row+3]); + } + } + + return pixbuf; +} + + -- cgit v1.2.3