File: gtk.patch

package info (click to toggle)
waili 19990723-22.2
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 2,564 kB
  • sloc: cpp: 9,964; ansic: 273; makefile: 208; sh: 74
file content (73 lines) | stat: -rw-r--r-- 1,859 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Description: code to convert from waili to GDK images and back
Author: mennucc1@debian.org

--- /dev/null
+++ waili-19990723/include/waili/gtk.h
@@ -0,0 +1,67 @@
+
+#ifndef __WAILI_GTK_H__
+#define __WAILI_GTK_H__
+
+#include <waili/Image.h>
+
+#ifndef GDK_PIXBUF_MAJOR
+#error you need to install gtk 2.0 or gdk-pixbuf, and include <gdk-pixbuf/gdk-pixbuf.h> to use this header
+#endif
+
+Image *gdk_to_waili(GdkPixbuf *src)
+{
+  gchar * data = gdk_pixbuf_get_pixels(src);
+  int ch,channels=gdk_pixbuf_get_n_channels(src),
+    stride=gdk_pixbuf_get_rowstride(src),
+    w= gdk_pixbuf_get_width(src), h=gdk_pixbuf_get_height(src), c ,r ;
+
+  Image * dst = new Image(w,h,ch); 
+  for (r = 0; r < h; r++)
+    for (c = 0; c < w; c++)
+      for (ch = 0; ch < channels; ch++) {
+	  (*dst)(c, r, ch) = (PixType)
+	    ( data[ch+ c*channels + stride*r]-128);
+      }
+  return dst;
+}
+GdkPixbuf  *waili_to_gdk(Image *src)
+{
+  int ch,channels=src->GetChannels(), 
+    w=src->GetCols(),  h=src->GetRows(),   c ,r ;
+  GdkPixbuf  *dst=gdk_pixbuf_new
+    (GDK_COLORSPACE_RGB,//GdkColorspace colorspace,
+     (channels==4?1:0),//gboolean has_alpha,
+     8,//int bits_per_sample,
+     w,//int width,
+     h);//int height);
+  gchar * data = gdk_pixbuf_get_pixels(dst);
+
+  int    stride=gdk_pixbuf_get_rowstride(src);
+
+    switch(channels) {
+    case 1:
+  for (r = 0; r < h; r++)
+    for (c = 0; c < w; c++)      {
+	data[ c + stride*r]= 
+	data[ c + stride*r+1]= 
+	data[ c + stride*r+2]= 
+	  CLAMP((*src)(c, r, 0) +128,0,255);
+      }
+  break;
+    case 3:
+    case 4:
+
+  for (r = 0; r < h; r++)
+    for (c = 0; c < w; c++)
+      for (ch = 0; ch < channels; ch++) {
+	data[ch+ c*channels + stride*r]= 
+	  CLAMP((*src)(c, r, ch) +128,0,255);
+
+      }
+  break;
+    default: abort(); 
+    }
+  return dst;
+}
+
+#endif // __WAILI_GTK_H__