1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include <sys/types.h>
35 #include "gdkprivate.h"
36 #include "gdkprivate-fb.h"
38 static gpointer parent_class = NULL;
40 #define GDK_IMAGE_PRIVATE_DATA(image) ((GdkImagePrivateFB *) GDK_IMAGE (image)->windowing_data)
43 _gdk_windowing_image_init (void)
48 gdk_image_init (GdkImage *image)
50 image->windowing_data = g_new0 (GdkImagePrivateFB, 1);
54 gdk_image_finalize (GObject *object)
56 GdkImage *image = GDK_IMAGE (object);
58 g_free (image->windowing_data);
59 image->windowing_data = NULL;
64 G_OBJECT_CLASS (parent_class)->finalize (object);
68 gdk_image_class_init (GdkImageClass *klass)
70 GObjectClass *object_class = G_OBJECT_CLASS (klass);
72 parent_class = g_type_class_peek_parent (klass);
74 object_class->finalize = gdk_image_finalize;
78 gdk_image_get_type (void)
80 static GType object_type = 0;
84 static const GTypeInfo object_info =
86 sizeof (GdkImageClass),
88 (GBaseFinalizeFunc) NULL,
89 (GClassInitFunc) gdk_image_class_init,
90 NULL, /* class_finalize */
91 NULL, /* class_data */
94 (GInstanceInitFunc) gdk_image_init,
97 object_type = g_type_register_static (G_TYPE_OBJECT,
107 gdk_image_new_bitmap(GdkVisual *visual,
113 GdkImagePrivateFB *private;
115 image = g_object_new (gdk_image_get_type (), NULL);
116 private = GDK_IMAGE_PRIVATE_DATA (image);
118 image->type = GDK_IMAGE_NORMAL;
119 image->visual = visual;
124 image->byte_order = 1 /* MSBFirst */;
126 image->bpl = (w+7)/8;
127 image->mem = g_malloc (image->bpl * h / 8);
133 gdk_image_new (GdkImageType type,
139 GdkImagePrivateFB *private;
141 image = g_object_new (gdk_image_get_type (), NULL);
142 private = GDK_IMAGE_PRIVATE_DATA (image);
145 image->visual = visual;
146 image->width = width;
147 image->height = height;
148 image->depth = visual->depth;
150 image->byte_order = 0;
151 image->bpp = image->depth/8;
152 image->bpl = (width * image->depth + 7) / 8;
153 image->mem = g_malloc (image->bpl * height);
159 _gdk_fb_get_image (GdkDrawable *drawable,
166 GdkImagePrivateFB *private;
167 gint bits_per_pixel = GDK_DRAWABLE_IMPL_FBDATA (gdk_parent_root)->depth;
170 g_return_val_if_fail (drawable != NULL, NULL);
172 image = g_object_new (gdk_image_get_type (), NULL);
173 private = GDK_IMAGE_PRIVATE_DATA (image);
175 image->type = GDK_IMAGE_NORMAL;
176 image->visual = gdk_drawable_get_visual (drawable);
177 image->width = width;
178 image->height = height;
179 image->depth = bits_per_pixel;
181 if (bits_per_pixel <= 8)
183 else if (bits_per_pixel <= 16)
185 else if (bits_per_pixel <= 24)
189 image->byte_order = 1;
191 image->bpl = (image->width * image->depth + 7) / 8; /* Packed pixels */
192 image->mem = g_malloc (image->bpl * image->height);
194 /* Fake its existence as a pixmap */
195 memset (&fbd, 0, sizeof(fbd));
196 fbd.drawable_data.mem = image->mem;
197 fbd.drawable_data.rowstride = image->bpl;
198 fbd.drawable_data.width = fbd.drawable_data.lim_x = image->width;
199 fbd.drawable_data.height = fbd.drawable_data.lim_y = image->height;
200 fbd.drawable_data.depth = image->depth;
201 fbd.drawable_data.window_type = GDK_DRAWABLE_PIXMAP;
203 gdk_fb_draw_drawable_2 ((GdkPixmap *)&fbd,
215 gdk_image_get_pixel (GdkImage *image,
219 GdkImagePrivateFB *private;
221 g_return_val_if_fail (image != NULL, 0);
223 private = GDK_IMAGE_PRIVATE_DATA (image);
225 switch (image->depth)
228 return ((guchar *)image->mem)[x + y * image->bpl];
231 return *((guint16 *)&((guchar *)image->mem)[x*2 + y*image->bpl]);
236 guchar *smem = &(((guchar *)image->mem)[x*image->bpp + y*image->bpl]);
237 return smem[0]|(smem[1]<<8)|(smem[2]<<16);
246 gdk_image_put_pixel (GdkImage *image,
251 guchar *ptr = image->mem;
253 g_return_if_fail (image != NULL);
255 switch (image->depth)
258 ptr[x + y * image->bpl] = pixel;
262 guint16 *p16 = (guint16 *)&ptr[x*2 + y*image->bpl];
268 guchar *smem = &ptr[x*3 + y*image->bpl];
269 smem[0] = (pixel & 0xFF);
270 smem[1] = (pixel & 0xFF00) >> 8;
271 smem[2] = (pixel & 0xFF0000) >> 16;
276 guint32 *smem = (guint32 *)&ptr[x*4 + y*image->bpl];
281 g_assert_not_reached ();