19 #include <wx/wfstream.h>
27 #if defined(__WXPALMOS__)
28 #elif defined(__WXMSW__)
29 #include "wx/msw/dib.h"
30 #elif defined(__WXMOTIF__)
31 #elif defined(__WXGTK20__)
33 #elif defined(__WXGTK__)
35 #elif defined(__WXX11__)
36 #elif defined(__WXMGL__)
37 #elif defined(__WXDFB__)
38 #elif defined(__WXMAC__)
39 #elif defined(__WXCOCOA__)
40 #elif defined(__WXPM__)
43 a2dImageRGBA::a2dImageRGBA(
int width,
int height )
47 m_glimage = (
unsigned char* ) malloc( width * height * 4 );
48 memset( m_glimage, 0, width * height * 4 );
49 #if defined(__WXMSW__)
57 a2dImageRGBA::a2dImageRGBA(
const wxImage& image,
unsigned char alpha )
59 #if defined(__WXMSW__)
65 m_height = image.GetHeight();
66 m_width = image.GetWidth();
67 m_glimage = (
unsigned char* ) malloc( image.GetWidth() * image.GetHeight() * 4 );
70 unsigned char* data = (
unsigned char* ) m_glimage;
71 for ( i = m_height - 1; i >= 0 ; i-- )
74 for ( j = 0; j < m_width ; j++ )
78 *data++ = image.GetRed( j, i );
79 *data++ = image.GetGreen( j, i );
80 *data++ = image.GetBlue( j, i );
81 if ( image.HasAlpha() )
82 * data++ = ( image.GetAlpha( j, i ) * alpha ) / 255;
83 else if ( image.HasMask() )
85 if ( image.IsTransparent( i, j ) )
86 * data++ = (
unsigned char ) 0;
91 *data++ = (
unsigned char ) alpha;
95 *data++ = image.GetBlue( j, i );
96 *data++ = image.GetGreen( j, i );
97 *data++ = image.GetRed( j, i );
98 if ( image.HasAlpha() )
99 *data++ = ( image.GetAlpha( j, i ) * alpha ) / 255;
100 else if ( image.HasMask() )
102 if ( image.IsTransparent( j, i ) )
103 * data++ = (
unsigned char ) 0;
108 *data++ = (
unsigned char ) alpha;
115 a2dImageRGBA::~a2dImageRGBA()
127 m_glimage = (
unsigned char* )malloc( other.m_width * other.m_height * 4 );
128 memcpy( m_glimage, other.m_glimage, other.m_width * other.m_height * 4 );
129 m_height = other.m_height;
130 m_width = other.m_width;
131 m_rgbOrder = other.m_rgbOrder;
135 void a2dImageRGBA::SetAlpha(
unsigned char alpha )
139 data = (
unsigned char* ) m_glimage;
141 for ( j = 0; j < m_height * m_width; j++ )
148 void a2dImageRGBA::SetAlpha(
unsigned char* alphadata )
152 data = (
unsigned char* ) m_glimage;
154 for ( j = 0; j < m_height * m_width; j++ )
162 wxImage a2dImageRGBA::GetImage()
const
164 wxImage image = wxImage( m_width, m_height );
166 unsigned char* imageData = image.GetData();
169 unsigned char* data = (
unsigned char* ) m_glimage;
170 for ( i = m_height - 1; i >= 0 ; i-- )
173 for ( j = 0; j < m_width ; j++ )
177 *imageData++ = *data++;
178 *imageData++ = *data++;
179 *imageData++ = *data++;
180 image.SetAlpha( j, i, *data++ );
184 *imageData++ = data[2];
185 *imageData++ = data[1];
186 *imageData++ = data[0];
187 image.SetAlpha( j, i, data[3] );
195 a2dImageRGBA* a2dImageRGBA::GetSubImage(
const wxRect& rect )
const
197 const int subwidth = rect.GetWidth();
198 const int subheight = rect.GetHeight();
202 wxCHECK_MSG( ( rect.GetLeft() >= 0 ) && ( rect.GetTop() >= 0 ) &&
203 ( rect.GetRight() <= GetWidth() ) && ( rect.GetBottom() <= GetHeight() ),
204 image, wxT(
"invalid subimage size" ) );
206 const unsigned char* src_data = GetData();
207 unsigned char* subdata = image->GetData();
209 wxCHECK_MSG( subdata, image, wxT(
"unable to create image" ) );
211 const int width = GetWidth();
212 const int pixsoff = rect.GetLeft() + width * rect.GetTop();
214 src_data += 4 * pixsoff;
216 for (
long j = 0; j < subheight; ++j )
218 memcpy( subdata, src_data, 4 * subwidth );
219 subdata += 4 * subwidth;
220 src_data += 4 * width;
226 wxBitmap a2dImageRGBA::CreateBitmap()
228 #if defined(__WXMSW__)
230 bool m_hasAlpha =
true;
231 wxImage image = GetImage();
232 const int bpp = m_hasAlpha ? 32 : 24;
233 return wxBitmap( image, bpp );
323 wxBitmap bitm( m_width, m_height, 32 );
325 GdkPixbuf* pixbuf = bitm.GetPixbuf();
330 const unsigned char* src = GetData();
331 unsigned char* dst = gdk_pixbuf_get_pixels( pixbuf );
333 int rowpad = gdk_pixbuf_get_rowstride( pixbuf ) - 4 * m_width;
337 memcpy( dst, src, m_width * m_height * 4 );
341 for (
int y = 0; y < m_height; y++ )
343 for (
int x = 0; x < m_width; x++ )
347 const unsigned char a = src[3];
348 *dst++ = (
unsigned char )( ( src[0] * a + 127 ) / 255 );
349 *dst++ = (
unsigned char )( ( src[1] * a + 127 ) / 255 );
350 *dst++ = (
unsigned char )( ( src[2] * a + 127 ) / 255 );
351 *dst++ = (
unsigned char )( src[3] );
Contains image with RGBA per pixel.