From fee0429537fdf467d7cbe99c60657c9ba2a436dc Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 29 Oct 1998 22:57:46 +0000 Subject: [PATCH] 24-bit rendering from wxImage into wxBitmap I think requiring GTK 1.0.4 is enough (not 1.0.6) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@935 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- configure.in | 4 ++-- docs/gtk/todo.txt | 3 --- src/gtk.inc | 4 ++-- src/gtk/bitmap.cpp | 52 ++++++++++++++++++++++++++++++++++----------- src/gtk1/bitmap.cpp | 52 ++++++++++++++++++++++++++++++++++----------- 5 files changed, 84 insertions(+), 31 deletions(-) diff --git a/configure.in b/configure.in index 21ba45a90e..5146813a4e 100644 --- a/configure.in +++ b/configure.in @@ -1000,10 +1000,10 @@ GUI_TK_LINK= MAKEINCLUDE= if test "$wxUSE_GTK" = 1; then - AM_PATH_GTK(1.0.6, [ + AM_PATH_GTK(1.0.4, [ GUI_TK_INCLUDE="$GTK_CFLAGS" GUI_TK_LIBRARY="$GTK_LIBS" - ], AC_MSG_ERROR(Is gtk-config in path and GTK+ is version 1.0.6?)) + ], AC_MSG_ERROR(Is gtk-config in path and GTK+ is version 1.0.4?)) TOOLKIT=GTK TOOLKIT_DEF=__WXGTK__ MAKEINCLUDE=../gtk.inc diff --git a/docs/gtk/todo.txt b/docs/gtk/todo.txt index 998a2c254e..4065f62bc2 100644 --- a/docs/gtk/todo.txt +++ b/docs/gtk/todo.txt @@ -15,9 +15,6 @@ wxHelpController Fix printing of bitmaps -> No idea. - -wxImage - -> 24-bit support -------------------- Low priority --------------------- diff --git a/src/gtk.inc b/src/gtk.inc index 9aa61d874d..194ced95cd 100644 --- a/src/gtk.inc +++ b/src/gtk.inc @@ -129,8 +129,8 @@ LIB_CPP_SRC=\ generic/splitter.cpp \ generic/statusbr.cpp \ generic/tabg.cpp \ - generic/textdlgg.cpp - + generic/textdlgg.cpp + LIB_C_SRC=\ common/extended.c \ \ diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 4706c2e7d7..acd2e490fa 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -101,25 +101,32 @@ wxBitmap::wxBitmap(void) wxBitmap::wxBitmap( int width, int height, int depth ) { + wxCHECK_RET( (width > 0) && (height > 0), "invalid bitmap size" ) + wxCHECK_RET( (depth > 0) || (depth == -1), "invalid bitmap depth" ) + m_refData = new wxBitmapRefData(); + + GdkWindow *parent = (GdkWindow*) &gdk_root_parent; + M_BMPDATA->m_mask = (wxMask *) NULL; - M_BMPDATA->m_pixmap = - gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, width, height, depth ); + M_BMPDATA->m_pixmap = gdk_pixmap_new( parent, width, height, depth ); M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; - M_BMPDATA->m_bpp = depth; + M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } wxBitmap::wxBitmap( char **bits ) { + wxCHECK_RET( bits != NULL, "invalid bitmap data" ) + m_refData = new wxBitmapRefData(); - GdkBitmap *mask = NULL; + GdkBitmap *mask = (GdkBitmap*) NULL; + GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - M_BMPDATA->m_pixmap = - gdk_pixmap_create_from_xpm_d( (GdkWindow*) &gdk_root_parent, &mask, NULL, (gchar **) bits ); + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( parent, &mask, NULL, (gchar **) bits ); if (mask) { @@ -129,7 +136,7 @@ wxBitmap::wxBitmap( char **bits ) gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - M_BMPDATA->m_bpp = 24; // ? + M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ? if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } @@ -374,6 +381,20 @@ wxBitmap::wxBitmap( const wxImage &image ) if (M_BMPDATA->m_bpp > 8) render_depth = M_BMPDATA->m_bpp; // Render + + enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR }; + byte_order b_o; + + if (render_depth >= 24) + { + GdkVisual *visual = gdk_visual_get_system(); + if ((visual->red_mask > visual->green_mask) && (visual->green_mask > visual->blue_mask)) b_o = RGB; + else if ((visual->red_mask > visual->blue_mask) && (visual->blue_mask > visual->green_mask)) b_o = RGB; + else if ((visual->blue_mask > visual->red_mask) && (visual->red_mask > visual->green_mask)) b_o = BRG; + else if ((visual->blue_mask > visual->green_mask) && (visual->green_mask > visual->red_mask)) b_o = BGR; + else if ((visual->green_mask > visual->red_mask) && (visual->red_mask > visual->blue_mask)) b_o = GRB; + else if ((visual->green_mask > visual->blue_mask) && (visual->blue_mask > visual->red_mask)) b_o = GBR; + } int r_mask = image.GetMaskRed(); int g_mask = image.GetMaskGreen(); @@ -434,13 +455,20 @@ wxBitmap::wxBitmap( const wxImage &image ) gdk_image_put_pixel( data_image, x, y, pixel ); break; } - case 24: - { - break; - } case 32: + case 24: { - break; + guint32 pixel = 0; + switch (b_o) + { + case RGB: pixel = (r << 16) | (g << 8) | b; break; + case RBG: pixel = (r << 16) | (b << 8) | g; break; + case BRG: pixel = (b << 16) | (r << 8) | g; break; + case BGR: pixel = (b << 16) | (g << 8) | r; break; + case GRB: pixel = (g << 16) | (r << 8) | b; break; + case GBR: pixel = (g << 16) | (b << 8) | r; break; + } + gdk_image_put_pixel( data_image, x, y, pixel ); } default: break; } diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 4706c2e7d7..acd2e490fa 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -101,25 +101,32 @@ wxBitmap::wxBitmap(void) wxBitmap::wxBitmap( int width, int height, int depth ) { + wxCHECK_RET( (width > 0) && (height > 0), "invalid bitmap size" ) + wxCHECK_RET( (depth > 0) || (depth == -1), "invalid bitmap depth" ) + m_refData = new wxBitmapRefData(); + + GdkWindow *parent = (GdkWindow*) &gdk_root_parent; + M_BMPDATA->m_mask = (wxMask *) NULL; - M_BMPDATA->m_pixmap = - gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, width, height, depth ); + M_BMPDATA->m_pixmap = gdk_pixmap_new( parent, width, height, depth ); M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; - M_BMPDATA->m_bpp = depth; + M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } wxBitmap::wxBitmap( char **bits ) { + wxCHECK_RET( bits != NULL, "invalid bitmap data" ) + m_refData = new wxBitmapRefData(); - GdkBitmap *mask = NULL; + GdkBitmap *mask = (GdkBitmap*) NULL; + GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - M_BMPDATA->m_pixmap = - gdk_pixmap_create_from_xpm_d( (GdkWindow*) &gdk_root_parent, &mask, NULL, (gchar **) bits ); + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( parent, &mask, NULL, (gchar **) bits ); if (mask) { @@ -129,7 +136,7 @@ wxBitmap::wxBitmap( char **bits ) gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - M_BMPDATA->m_bpp = 24; // ? + M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ? if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } @@ -374,6 +381,20 @@ wxBitmap::wxBitmap( const wxImage &image ) if (M_BMPDATA->m_bpp > 8) render_depth = M_BMPDATA->m_bpp; // Render + + enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR }; + byte_order b_o; + + if (render_depth >= 24) + { + GdkVisual *visual = gdk_visual_get_system(); + if ((visual->red_mask > visual->green_mask) && (visual->green_mask > visual->blue_mask)) b_o = RGB; + else if ((visual->red_mask > visual->blue_mask) && (visual->blue_mask > visual->green_mask)) b_o = RGB; + else if ((visual->blue_mask > visual->red_mask) && (visual->red_mask > visual->green_mask)) b_o = BRG; + else if ((visual->blue_mask > visual->green_mask) && (visual->green_mask > visual->red_mask)) b_o = BGR; + else if ((visual->green_mask > visual->red_mask) && (visual->red_mask > visual->blue_mask)) b_o = GRB; + else if ((visual->green_mask > visual->blue_mask) && (visual->blue_mask > visual->red_mask)) b_o = GBR; + } int r_mask = image.GetMaskRed(); int g_mask = image.GetMaskGreen(); @@ -434,13 +455,20 @@ wxBitmap::wxBitmap( const wxImage &image ) gdk_image_put_pixel( data_image, x, y, pixel ); break; } - case 24: - { - break; - } case 32: + case 24: { - break; + guint32 pixel = 0; + switch (b_o) + { + case RGB: pixel = (r << 16) | (g << 8) | b; break; + case RBG: pixel = (r << 16) | (b << 8) | g; break; + case BRG: pixel = (b << 16) | (r << 8) | g; break; + case BGR: pixel = (b << 16) | (g << 8) | r; break; + case GRB: pixel = (g << 16) | (r << 8) | b; break; + case GBR: pixel = (g << 16) | (b << 8) | r; break; + } + gdk_image_put_pixel( data_image, x, y, pixel ); } default: break; } -- 2.45.2