[GTK+ on Mac OS X] Implementation of _gdk_quartz_copy_to_image



I dont know if I can cvs it, but this is my code for _gdk_quartz_copy_to_image :

GdkImage *
_gdk_quartz_copy_to_image (GdkDrawable *drawable,
			   GdkImage    *image,
			   gint         src_x,
			   gint         src_y,
			   gint         dest_x,
			   gint         dest_y,
			   gint         width,
			   gint         height)
{
	GdkPixbuf *pixbuf;

	pixbuf = NULL;

	image = g_object_new (gdk_image_get_type (), NULL);

	image->type = GDK_TYPE_IMAGE;

	image->width = width;
	image->height = height;

image->byte_order = (G_BYTE_ORDER == G_LITTLE_ENDIAN) ? GDK_LSB_FIRST : GDK_MSB_FIRST;

	image->bpp = 4;
	image->bpl = image->width * image->bpp;
	image->bits_per_pixel = image->bpp * 8;

	//

	image->colormap = gdk_drawable_get_colormap (drawable);

	if(image->colormap != NULL)
	{
		image->visual = gdk_colormap_get_visual (image->colormap);

		//

		if (image->visual)
		{
			void *data;
			int x, y;
			guint32 *pix, *pixels;

			image->depth = image->visual->depth;

			//

			image->mem = g_malloc (image->bpl * image->height);
			memset (image->mem, 0x00, image->bpl * image->height);

			data = GDK_PIXMAP_IMPL_QUARTZ (drawable)->data;

			pixels = (guint32 *)data;

			for (y = 0; y < image->height; y++)
			{
				pix = pixels+((image->height - 1 - y)*width);

				for (x = 0; x<image->width; x++)
				{
					char *b;

					guint32 pixtab;

					b = (char *)g_malloc(sizeof(char)*4);

					b[3] = (*pix >> 24) & 0xff;

					b[2] = (*pix >> 16) & 0xff;

					b[1] = (*pix >> 8) & 0xff;

					b[0] = (*pix >> 0) & 0xff;

pixtab = ((*(b+0) & 0xff) << 24) | ((*(b+1) & 0xff) << 0) | ((*(b+2) & 0xff) << 8) | ((*(b+3) & 0xff) << 16);

					gdk_image_put_pixel (image, x, y, pixtab);

					g_free(b);

					pix++;
				}
			}

			image->windowing_data = NULL;

			return image;
		}
	}

	g_free(image);

	image = NULL;

	return NULL;
}


it works but maybe this code is incomplete...





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]