gtk2/gdk/win32/gdkimage-win32.c
Owen Taylor aeaaae04ac Changes multihead reorganizing code for win32 support, mostly from a patch
Wed Jun  5 18:34:47 2002  Owen Taylor  <otaylor@redhat.com>

	Changes multihead reorganizing code for win32 support,
	mostly from a patch by Hans Breuer.

	* gdk/gdkcolor.c gdk/x11/gdkcolor-x11.c gdk/gdkcursor.c
	  gdk/x11/gdkcursor-x11.c gdk/gdkevents.c gdk/x11/gdkevents-x11.c
	  gdk/gdkfont.c gdk/x11/gdkfont-x11.c gdk/gdkkeys.c
	  gdk/x11/gdkkeys-x11.c gdk/gdkimage.c gdk/x11/gdkimage-x11.c
	  gdk/gdkscreen.c gdk/x11/gdkmain-x11.c
	  gdk/gdkdisplay.c gdk/gdkevents-x11.c gdk/gdkpango.c
	  gdk/x11/gdkpango-x11.c gdk/gdkselection.c
	  gdk/x11/gdkselection-x11.c gdk/gdkwindow.c
	  gdk/x11/gdkwindow-x11.c gdk/gdkvisual.c gdk/x11/gdkvisual-x11.c:
	  Move port-independent singlehead wrapper functions into
	  port-independent part of GDK. (#80009)

	* gdk/win32/gdkcolor-win32.c gdk/win32/gdkcursor-win32.c
	  gdk/win32/gdkevents-win32.c gdk/win32/gdkfont-win32.c
	  gdk/win32/gdkimage-win32.c gdk/win32/gdkkeys-win32.c
	  gdk/win32/gdkmain-win32.c gdk/win32/gdkproperty-win32.c
	  gdk/win32/gdkselection-win32.c gdk/win32/gkwindow-win32.c:
	Turn singlehead functions into "multihead" functions that ignore
	their GdkDisplay or GdkScreen arguments.

	* gdk/win32/gdkdrawable-win32.c gdk/win32/gdkevents-win32.c
	gdk/win32/gdkinput-win32.c gdk/win32/gdkprivate-win32.h:
	Misc multihead-compatibility changes.

	* gtk/gtk.def gdk/gdk.def: Update for multihead functions.

	* gdk/gdkcolormap.h gdk/gdkvisual.h gdk/x11/gdkcolormap-x11.c
	gdk/x11/gdkvisual-x11.c: Remove the screen fields
	from the public parts of the colormap/visual structures, add accessors
	instead.

	* gdk/gdkpixbuf-render.c gdk/gdkpixmap.c gdk/gdkrgb.c
	  gdk/x11/gdkcolormap-x11.c gdk/x11/gdkimage-x11.c
	  gdk/x11/gdkimage-x11.c gdk/x11/gdkprivate-x11.h gtk/gtkgc.c
	  gtk/gtkstyle.c gtk/gtkwidget.c: Use accessors to get the screen
	for colormaps, visuals; move the fields into the private
	structures for the x11 backend.

	* gdk/gdkdisplay.[ch] gdk/x11/gdkdisplay-x11.[ch]
	  gdk/gdkscreen.[ch] gdk/x11/gdkscreen-x11.c:
	Remove virtualization of screen and display functions.
	(#79990, patch from Erwann Chenede)

	* gdk/win32/gdkdisplay-x11.c gdk/win32/gdkscreen-win32.c
	gdk/win32/{Makefile.am, makefile.msc, makefile.mingw}:
	New files containing stub implementations of Display,
	Screen functions.

	* gdk/x11/gdkscreen-x11.[ch] gdk/x11/gdkdisplay-x11.[ch]
	gdk/x11/gdkx.h: Clean up function exports and what
	headers they are in. (#79954)

	* gdk/x11/gdkx.h: Fix macro that was referring to a non-existant
	screen->screen_num. (In the patch for #79972, Erwann Chenede)

	* gdk/gdkscreen.c gdk/gdkwindow.c gdk/x11/gdkinternals.h
	 gdk/x11/gdkscreen-x11.c: Fix gdk_screen_get_window_at_pointer()
	to use window hooks. (#79972, patch partly from Erwann Chenede)

	* gdk/x11/gdkdisplay-x11.c gdk/x11/gdkevents-x11.c: Fix
	some warnings.
2002-06-06 00:26:42 +00:00

416 lines
9.6 KiB
C

/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright (C) 1998-2002 Tor Lillqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "gdkimage.h"
#include "gdkpixmap.h"
#include "gdkscreen.h" /* gdk_get_default_screen() */
#include "gdkprivate-win32.h"
static GList *image_list = NULL;
static gpointer parent_class = NULL;
static void gdk_win32_image_destroy (GdkImage *image);
static void gdk_image_init (GdkImage *image);
static void gdk_image_class_init (GdkImageClass *klass);
static void gdk_image_finalize (GObject *object);
GType
gdk_image_get_type (void)
{
static GType object_type = 0;
if (!object_type)
{
static const GTypeInfo object_info =
{
sizeof (GdkImageClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gdk_image_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GdkImage),
0, /* n_preallocs */
(GInstanceInitFunc) gdk_image_init,
};
object_type = g_type_register_static (G_TYPE_OBJECT,
"GdkImage",
&object_info, 0);
}
return object_type;
}
static void
gdk_image_init (GdkImage *image)
{
image->windowing_data = NULL;
}
static void
gdk_image_class_init (GdkImageClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gdk_image_finalize;
}
static void
gdk_image_finalize (GObject *object)
{
GdkImage *image = GDK_IMAGE (object);
gdk_win32_image_destroy (image);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
void
_gdk_image_exit (void)
{
GdkImage *image;
while (image_list)
{
image = image_list->data;
gdk_win32_image_destroy (image);
}
}
GdkImage *
_gdk_win32_setup_pixmap_image (GdkPixmap *pixmap,
GdkWindow *window,
gint width,
gint height,
gint depth,
guchar *bits)
{
GdkImage *image;
image = g_object_new (gdk_image_get_type (), NULL);
image->windowing_data = pixmap;
image->type = GDK_IMAGE_SHARED;
image->visual = gdk_drawable_get_visual (window);
image->byte_order = GDK_LSB_FIRST;
image->width = width;
image->height = height;
image->depth = depth;
switch (depth)
{
case 1:
case 4:
case 5:
case 6:
case 7:
case 8:
image->bpp = 1;
break;
case 15:
case 16:
image->bpp = 2;
break;
case 24:
image->bpp = 3;
break;
case 32:
image->bpp = 4;
break;
default:
g_warning ("_gdk_win32_setup_pixmap_image: depth=%d", image->depth);
g_assert_not_reached ();
}
if (depth == 1)
image->bpl = ((width - 1)/32 + 1)*4;
else if (depth == 4)
image->bpl = ((width - 1)/8 + 1)*4;
else
image->bpl = ((width*image->bpp - 1)/4 + 1)*4;
image->bits_per_pixel = image->depth;
image->mem = bits;
return image;
}
GdkImage *
gdk_image_new_bitmap (GdkVisual *visual,
gpointer data,
gint w,
gint h)
{
GdkPixmap *pixmap;
GdkImage *image;
gint data_bpl = (w-1)/8 + 1;
gint i;
pixmap = gdk_pixmap_new (NULL, w, h, 1);
if (pixmap == NULL)
return NULL;
image = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->image;
GDK_NOTE (IMAGE, g_print ("gdk_image_new_bitmap: %dx%d=%p\n",
w, h, GDK_PIXMAP_HBITMAP (pixmap)));
if (data_bpl != image->bpl)
{
for (i = 0; i < h; i++)
memmove ((guchar *) image->mem + i*image->bpl, ((guchar *) data) + i*data_bpl, data_bpl);
}
else
memmove (image->mem, data, data_bpl*h);
return image;
}
void
_gdk_windowing_image_init (void)
{
/* Nothing needed AFAIK */
}
GdkImage*
_gdk_image_new_for_depth (GdkScreen *screen,
GdkImageType type,
GdkVisual *visual,
gint width,
gint height,
gint depth)
{
GdkPixmap *pixmap;
g_return_val_if_fail (!visual || GDK_IS_VISUAL (visual), NULL);
g_return_val_if_fail (visual || depth != -1, NULL);
g_return_val_if_fail (screen == gdk_get_default_screen (), NULL);
if (visual)
depth = visual->depth;
pixmap = gdk_pixmap_new (NULL, width, height, depth);
if (pixmap == NULL)
return NULL;
GDK_NOTE (IMAGE, g_print ("_gdk_image_new_for_depth: %dx%dx%d=%p\n",
width, height, depth, GDK_PIXMAP_HBITMAP (pixmap)));
return GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->image;
}
GdkImage*
_gdk_win32_copy_to_image (GdkDrawable *drawable,
GdkImage *image,
gint src_x,
gint src_y,
gint dest_x,
gint dest_y,
gint width,
gint height)
{
GdkGC *gc;
GdkScreen *screen = gdk_drawable_get_screen (drawable);
g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable), NULL);
g_return_val_if_fail (image != NULL || (dest_x == 0 && dest_y == 0), NULL);
GDK_NOTE (IMAGE, g_print ("_gdk_win32_copy_to_image: %p\n",
GDK_DRAWABLE_HANDLE (drawable)));
if (!image)
image = _gdk_image_new_for_depth (screen, GDK_IMAGE_FASTEST, NULL, width, height,
gdk_drawable_get_depth (drawable));
gc = gdk_gc_new ((GdkDrawable *) image->windowing_data);
_gdk_win32_blit
(FALSE,
GDK_DRAWABLE_IMPL_WIN32 (GDK_PIXMAP_OBJECT (image->windowing_data)->impl),
gc, drawable, src_x, src_y, dest_x, dest_y, width, height);
gdk_gc_unref (gc);
return image;
}
guint32
gdk_image_get_pixel (GdkImage *image,
gint x,
gint y)
{
guchar *pixelp;
g_return_val_if_fail (GDK_IS_IMAGE (image), 0);
if (!(x >= 0 && x < image->width && y >= 0 && y < image->height))
return 0;
if (image->depth == 1)
return (((guchar *) image->mem)[y * image->bpl + (x >> 3)] & (1 << (7 - (x & 0x7)))) != 0;
if (image->depth == 4)
{
pixelp = (guchar *) image->mem + y * image->bpl + (x >> 1);
if (x&1)
return (*pixelp) & 0x0F;
return (*pixelp) >> 4;
}
pixelp = (guchar *) image->mem + y * image->bpl + x * image->bpp;
switch (image->bpp)
{
case 1:
return *pixelp;
/* Windows is always LSB, no need to check image->byte_order. */
case 2:
return pixelp[0] | (pixelp[1] << 8);
case 3:
return pixelp[0] | (pixelp[1] << 8) | (pixelp[2] << 16);
case 4:
return pixelp[0] | (pixelp[1] << 8) | (pixelp[2] << 16);
}
g_assert_not_reached ();
return 0;
}
void
gdk_image_put_pixel (GdkImage *image,
gint x,
gint y,
guint32 pixel)
{
guchar *pixelp;
g_return_if_fail (image != NULL);
if (!(x >= 0 && x < image->width && y >= 0 && y < image->height))
return;
GdiFlush ();
if (image->depth == 1)
if (pixel & 1)
((guchar *) image->mem)[y * image->bpl + (x >> 3)] |= (1 << (7 - (x & 0x7)));
else
((guchar *) image->mem)[y * image->bpl + (x >> 3)] &= ~(1 << (7 - (x & 0x7)));
else if (image->depth == 4)
{
pixelp = (guchar *) image->mem + y * image->bpl + (x >> 1);
if (x&1)
{
*pixelp &= 0xF0;
*pixelp |= (pixel & 0x0F);
}
else
{
*pixelp &= 0x0F;
*pixelp |= (pixel << 4);
}
}
else
{
pixelp = (guchar *) image->mem + y * image->bpl + x * image->bpp;
/* Windows is always LSB, no need to check image->byte_order. */
switch (image->bpp)
{
case 4:
pixelp[3] = 0;
case 3:
pixelp[2] = ((pixel >> 16) & 0xFF);
case 2:
pixelp[1] = ((pixel >> 8) & 0xFF);
case 1:
pixelp[0] = (pixel & 0xFF);
}
}
}
static void
gdk_win32_image_destroy (GdkImage *image)
{
GdkPixmap *pixmap;
g_return_if_fail (GDK_IS_IMAGE (image));
pixmap = image->windowing_data;
if (pixmap == NULL) /* This means that _gdk_image_exit()
* destroyed the image already, and
* now we're called a second time from
* _finalize()
*/
return;
GDK_NOTE (IMAGE, g_print ("gdk_win32_image_destroy: %p\n",
GDK_PIXMAP_HBITMAP (pixmap)));
gdk_pixmap_unref (pixmap);
image->windowing_data = NULL;
}
gint
_gdk_windowing_get_bits_for_depth (GdkDisplay *display,
gint depth)
{
g_return_val_if_fail (display == gdk_get_default_display (), 0);
switch (depth)
{
case 1:
return 1;
case 2:
case 3:
case 4:
return 4;
case 5:
case 6:
case 7:
case 8:
return 8;
case 15:
case 16:
return 16;
case 24:
return 24;
case 32:
return 32;
}
g_assert_not_reached ();
return 0;
}