}
#endif // wxUSE_STREAMS
-wxImage::wxImage( const wxImage& image )
- : wxObject()
-{
- Ref(image);
-}
-
-wxImage::wxImage( const wxImage* image )
-{
- if (image) Ref(*image);
-}
-
wxImage::wxImage( const char** xpmData )
{
Create(xpmData);
image.SetMask( M_IMGDATA->m_hasMask );
memcpy( data, GetData(), M_IMGDATA->m_width*M_IMGDATA->m_height*3 );
-
- // also copy the image options
+
wxImageRefData *imgData = (wxImageRefData *)image.m_refData;
+
+ // also copy the alpha channel
+ if (HasAlpha())
+ {
+ image.SetAlpha();
+ unsigned char* alpha = image.GetAlpha();
+ memcpy( alpha, GetAlpha(), M_IMGDATA->m_width*M_IMGDATA->m_height );
+ }
+
+ // also copy the image options
imgData->m_optionNames = M_IMGDATA->m_optionNames;
imgData->m_optionValues = M_IMGDATA->m_optionValues;
}
}
+wxImage wxImage::ConvertToGreyscale( double lr, double lg, double lb ) const
+{
+ wxImage image;
+
+ 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 )
+ {
+ // don't modify the mask
+ if ( hasMask && src[0] == maskRed && src[1] == maskGreen && src[2] == maskBlue )
+ {
+ memcpy(dest, src, 3);
+ }
+ else
+ {
+ // calculate the luma
+ double luma = (src[0] * lr + src[1] * lg + src[2] * lb) + 0.5;
+ dest[0] = dest[1] = dest[2] = wx_static_cast(unsigned char, luma);
+ }
+ }
+
+ return image;
+}
+
wxImage wxImage::ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const
{
wxImage image;
return false;
}
- if (!handler->CanRead(stream))
+ if (stream.IsSeekable() && !handler->CanRead(stream))
{
wxLogError(_("Image file is not of type %d."), type);
return false;
return false;
}
- if (!handler->CanRead(stream))
+ if (stream.IsSeekable() && !handler->CanRead(stream))
{
wxLogError(_("Image file is not of type %s."), (const wxChar*) mimetype);
return false;