summaryrefslogtreecommitdiffstats
path: root/src/trace/imagemap-gdk.cpp
diff options
context:
space:
mode:
authorBob Jamison <ishmalius@gmail.com>2006-03-25 05:57:21 +0000
committerishmal <ishmal@users.sourceforge.net>2006-03-25 05:57:21 +0000
commit72c233de4b889debcc509186be8114abbb06f6aa (patch)
tree8dd159b66503e9ae24d4bd9665591d5fae6fb9a8 /src/trace/imagemap-gdk.cpp
parentinitial hookup of siox into Tracer. much work still to be done, and testing too (diff)
downloadinkscape-72c233de4b889debcc509186be8114abbb06f6aa.tar.gz
inkscape-72c233de4b889debcc509186be8114abbb06f6aa.zip
Add PackedPixelMap to make pixbuf->pixel array conversion much cleaner. Also make certain that packed pixels are unsigned long.
(bzr r294)
Diffstat (limited to 'src/trace/imagemap-gdk.cpp')
-rw-r--r--src/trace/imagemap-gdk.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/trace/imagemap-gdk.cpp b/src/trace/imagemap-gdk.cpp
index 93a1d05aa..e217dd619 100644
--- a/src/trace/imagemap-gdk.cpp
+++ b/src/trace/imagemap-gdk.cpp
@@ -81,6 +81,87 @@ GdkPixbuf *grayMapToGdkPixbuf(GrayMap *grayMap)
/*#########################################################################
+## P A C K E D P I X E L M A P
+#########################################################################*/
+
+PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf)
+{
+ if (!buf)
+ return NULL;
+
+ int width = gdk_pixbuf_get_width(buf);
+ int height = gdk_pixbuf_get_height(buf);
+ guchar *pixdata = gdk_pixbuf_get_pixels(buf);
+ int rowstride = gdk_pixbuf_get_rowstride(buf);
+ int n_channels = gdk_pixbuf_get_n_channels(buf);
+
+ PackedPixelMap *ppMap = PackedPixelMapCreate(width, height);
+ if (!ppMap)
+ return NULL;
+
+ //### Fill in the cells with RGB values
+ int x,y;
+ int row = 0;
+ for (y=0 ; y<height ; y++)
+ {
+ guchar *p = pixdata + row;
+ for (x=0 ; x<width ; x++)
+ {
+ int alpha = (int)p[3];
+ int white = 255 - alpha;
+ int r = (int)p[0]; r = r * alpha / 256 + white;
+ int g = (int)p[1]; g = g * alpha / 256 + white;
+ int b = (int)p[2]; b = b * alpha / 256 + white;
+
+ ppMap->setPixel(ppMap, x, y, r, g, b);
+ p += n_channels;
+ }
+ row += rowstride;
+ }
+
+ return ppMap;
+}
+
+GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap)
+{
+ if (!ppMap)
+ return NULL;
+
+ guchar *pixdata = (guchar *)
+ malloc(sizeof(guchar) * ppMap->width * ppMap->height * 3);
+ if (!pixdata)
+ return NULL;
+
+ int n_channels = 3;
+ int rowstride = ppMap->width * 3;
+
+ GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB,
+ 0, 8, ppMap->width, ppMap->height,
+ rowstride, NULL, NULL);
+
+ //### Fill in the cells with RGB values
+ int x,y;
+ int row = 0;
+ for (y=0 ; y<ppMap->height ; y++)
+ {
+ guchar *p = pixdata + row;
+ for (x=0 ; x<ppMap->width ; x++)
+ {
+ unsigned long rgb = ppMap->getPixel(ppMap, x, y);
+ p[0] = (rgb >> 16) & 0xff;
+ p[1] = (rgb >> 8) & 0xff;
+ p[2] = (rgb ) & 0xff;
+ p += n_channels;
+ }
+ row += rowstride;
+ }
+
+ return buf;
+}
+
+
+
+/*#########################################################################
## R G B M A P
#########################################################################*/