Re: GTK+ >> Cocoa Native Port



This is my first version of _gdk_quartz_copy_to_image. The only problem is that I didnt succeed in getting the color map from "drawable"... so the image is displayed without its original colors

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;

	//printf("_gdk_quartz_copy_to_image : To Implement\n");

	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 = (GdkColormap *)g_malloc(sizeof(GdkColormap));

memcpy(image->colormap, GDK_DRAWABLE_IMPL_QUARTZ (&(GDK_PIXMAP_IMPL_QUARTZ (drawable)->parent_instance))->colormap, sizeof(GdkColormap));

	if(image->colormap != NULL)
	{
		image->visual = (GdkVisual *)g_malloc(sizeof(GdkVisual));

memcpy(image->visual, gdk_colormap_get_visual (image->colormap), sizeof(GdkVisual));

		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++)
				{
					gdk_image_put_pixel (image, x, y, *pix);

					pix++;
				}
			}

			return image;
		}
	}

	g_free(image);

	image = NULL;

	return NULL;
}





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