#include "wx/module.h"
#include "wx/hash.h"
#include "wx/utils.h"
+#include "wx/math.h"
// For memcpy
#include <string.h>
-#include <math.h>
#ifdef __SALFORDC__
#undef FAR
wxImageRefData::~wxImageRefData()
{
- if ( !m_static )
+ if (!m_static)
+ {
free( m_data );
-
- free(m_alpha);
+ free( m_alpha );
+ }
}
wxList wxImage::sm_handlers;
Create( width, height, data, static_data );
}
+wxImage::wxImage( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data )
+{
+ Create( width, height, data, alpha, static_data );
+}
+
wxImage::wxImage( const wxString& name, long type, int index )
{
LoadFile( name, type, index );
return true;
}
+bool wxImage::Create( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data )
+{
+ UnRef();
+
+ wxCHECK_MSG( data, false, _T("NULL data in wxImage::Create") );
+
+ m_refData = new wxImageRefData();
+
+ M_IMGDATA->m_data = data;
+ M_IMGDATA->m_alpha = alpha;
+ M_IMGDATA->m_width = width;
+ M_IMGDATA->m_height = height;
+ M_IMGDATA->m_ok = true;
+ M_IMGDATA->m_static = static_data;
+
+ return true;
+}
+
void wxImage::Destroy()
{
UnRef();
bool wxImage::ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned char b )
{
SetAlpha( NULL );
-
+
int w = M_IMGDATA->m_width,
h = M_IMGDATA->m_height;
-
+
unsigned char *alpha = GetAlpha();
unsigned char *data = GetData();
-
+
int x,y;
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
int i;
angle = -angle; // screen coordinates are a mirror image of "real" coordinates
-
+
bool has_alpha = HasAlpha();
// Create pointer-based array to accelerate access to wxImage's data
for (i = 1; i < GetHeight(); i++)
data[i] = data[i - 1] + (3 * GetWidth());
- // Same for alpha channel
+ // Same for alpha channel
unsigned char ** alpha = NULL;
if (has_alpha)
{
// array here (and in fact it would be slower).
//
unsigned char * dst = rotated.GetData();
-
+
unsigned char * alpha_dst = NULL;
if (has_alpha)
alpha_dst = rotated.GetAlpha();
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[y1] + x1;
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[y1] + x2;
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[y2] + x2;
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[y2] + x1;
( (w1 * *v1 + w2 * *v2 +
w3 * *v3 + w4 * *v4) /
(w1 + w2 + w3 + w4) );
-
+
if (has_alpha)
{
unsigned char *v1 = alpha[y1] + (x1);
*(dst++) = blank_r;
*(dst++) = blank_g;
*(dst++) = blank_b;
-
+
if (has_alpha)
*(alpha_dst++) = 0;
}
*(dst++) = *(p++);
*(dst++) = *(p++);
*(dst++) = *p;
-
+
if (has_alpha)
{
unsigned char *p = alpha[ys] + (xs);
*(dst++) = blank_r;
*(dst++) = blank_g;
*(dst++) = blank_b;
-
+
if (has_alpha)
*(alpha_dst++) = 255;
}
}
delete [] data;
-
+
if (has_alpha)
delete [] alpha;