- wxCHECK_MSG( Ok(), image, wxT("invalid image") );
-
- image.Create(M_IMGDATA->m_width, M_IMGDATA->m_height, false);
-
- unsigned char *dest = image.GetData();
-
- wxCHECK_MSG( dest, image, wxT("unable to create image") );
-
- unsigned char *src = M_IMGDATA->m_data;
- bool hasMask = M_IMGDATA->m_hasMask;
- unsigned char maskRed = M_IMGDATA->m_maskRed;
- unsigned char maskGreen = M_IMGDATA->m_maskGreen;
- unsigned char maskBlue = M_IMGDATA->m_maskBlue;
-
- if ( hasMask )
- image.SetMaskColour(maskRed, maskGreen, maskBlue);
-
- const long size = M_IMGDATA->m_width * M_IMGDATA->m_height;
- for ( long i = 0; i < size; i++, src += 3, dest += 3 )
- {
- memcpy(dest, src, 3);
- // don't modify the mask
- if ( hasMask && src[0] == maskRed && src[1] == maskGreen && src[2] == maskBlue )
- {
- }
- else
- {
- wxColour::MakeGrey(dest + 0, dest + 1, dest + 2, weight_r, weight_g, weight_b);
- }
- }
-
- // copy the alpha channel, if any
- if (HasAlpha())
+ const int w = M_IMGDATA->m_width;
+ const int h = M_IMGDATA->m_height;
+ size_t size = size_t(w) * h;
+ image.Create(w, h, false);
+ const unsigned char* alpha = M_IMGDATA->m_alpha;
+ if (alpha)