X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..2db0bbdecd8b979c00eef0276075d1e314b35d93:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index 666a09736a..903defa811 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -57,6 +57,9 @@ public: unsigned char m_maskRed,m_maskGreen,m_maskBlue; bool m_ok; bool m_static; + wxPalette m_palette; + wxArrayString m_optionNames; + wxArrayString m_optionValues; }; wxImageRefData::wxImageRefData() @@ -84,7 +87,7 @@ wxList wxImage::sm_handlers; #define M_IMGDATA ((wxImageRefData *)m_refData) - IMPLEMENT_DYNAMIC_CLASS(wxImage, wxObject) +IMPLEMENT_DYNAMIC_CLASS(wxImage, wxObject) wxImage::wxImage() { @@ -314,7 +317,7 @@ wxImage wxImage::Mirror( bool horizontally ) const for (long i = 0; i < height; i++) { target_data = data + 3*width*(height-1-i); - memcpy( target_data, source_data, 3*width ); + memcpy( target_data, source_data, (size_t)3*width ); source_data += 3*width; } } @@ -406,9 +409,36 @@ void wxImage::Paste( const wxImage &image, int x, int y ) source_data += source_step; target_data += target_step; } + return; } - else + + if (!HasMask() && image.HasMask()) { + unsigned char r = image.GetMaskRed(); + unsigned char g = image.GetMaskGreen(); + unsigned char b = image.GetMaskBlue(); + + width *= 3; + unsigned char* source_data = image.GetData() + xx*3 + yy*3*image.GetWidth(); + int source_step = image.GetWidth()*3; + + unsigned char* target_data = GetData() + (x+xx)*3 + (y+yy)*3*M_IMGDATA->m_width; + int target_step = M_IMGDATA->m_width*3; + + for (int j = 0; j < height; j++) + { + for (int i = 0; i < width; i+=3) + { + if ((source_data[i] != r) && + (source_data[i+1] != g) && + (source_data[i+2] != b)) + { + memcpy( target_data+i, source_data+i, 3 ); + } + } + source_data += source_step; + target_data += target_step; + } } } @@ -612,6 +642,80 @@ int wxImage::GetHeight() const return M_IMGDATA->m_height; } +// Palette functions + +bool wxImage::HasPalette() const +{ + if (!Ok()) + return FALSE; + + return M_IMGDATA->m_palette.Ok(); +} + +const wxPalette& wxImage::GetPalette() const +{ + wxCHECK_MSG( Ok(), wxNullPalette, wxT("invalid image") ); + + return M_IMGDATA->m_palette; +} + +void wxImage::SetPalette(const wxPalette& palette) +{ + wxCHECK_RET( Ok(), wxT("invalid image") ); + + M_IMGDATA->m_palette = palette; +} + +// Option functions (arbitrary name/value mapping) +void wxImage::SetOption(const wxString& name, const wxString& value) +{ + wxCHECK_RET( Ok(), wxT("invalid image") ); + + int idx = M_IMGDATA->m_optionNames.Index(name, FALSE); + if (idx == wxNOT_FOUND) + { + M_IMGDATA->m_optionNames.Add(name); + M_IMGDATA->m_optionValues.Add(value); + } + else + { + M_IMGDATA->m_optionNames[idx] = name; + M_IMGDATA->m_optionValues[idx] = value; + } +} + +void wxImage::SetOption(const wxString& name, int value) +{ + wxString valStr; + valStr.Printf(wxT("%d"), value); + SetOption(name, valStr); +} + +wxString wxImage::GetOption(const wxString& name) const +{ + wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid image") ); + + int idx = M_IMGDATA->m_optionNames.Index(name, FALSE); + if (idx == wxNOT_FOUND) + return wxEmptyString; + else + return M_IMGDATA->m_optionValues[idx]; +} + +int wxImage::GetOptionInt(const wxString& name) const +{ + wxCHECK_MSG( Ok(), 0, wxT("invalid image") ); + + return wxAtoi(GetOption(name)); +} + +bool wxImage::HasOption(const wxString& name) const +{ + wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") ); + + return (M_IMGDATA->m_optionNames.Index(name, FALSE) != wxNOT_FOUND); +} + bool wxImage::LoadFile( const wxString& filename, long type ) { #if wxUSE_STREAMS @@ -662,9 +766,9 @@ bool wxImage::SaveFile( const wxString& filename, int type ) wxBufferedOutputStream bstream( stream ); return SaveFile(bstream, type); } - else #endif // wxUSE_STREAMS - return FALSE; + + return FALSE; } bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) @@ -677,9 +781,9 @@ bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) wxBufferedOutputStream bstream( stream ); return SaveFile(bstream, mimetype); } - else #endif // wxUSE_STREAMS - return FALSE; + + return FALSE; } bool wxImage::CanRead( const wxString &name ) @@ -1020,6 +1124,13 @@ wxBitmap wxImage::ConvertToBitmap() const hbitmap = ::CreateCompatibleBitmap( hdc, width, bmpHeight ); ::SelectObject( memdc, hbitmap); + HPALETTE hOldPalette = 0; + if (GetPalette().Ok()) + { + hOldPalette = ::SelectPalette(memdc, (HPALETTE) GetPalette().GetHPALETTE(), FALSE); + ::RealizePalette(memdc); + } + // copy image data into DIB data and then into DDB (in a loop) unsigned char *data = GetData(); int i, j, n; @@ -1069,6 +1180,9 @@ wxBitmap wxImage::ConvertToBitmap() const } bitmap.SetHBITMAP( (WXHBITMAP) hbitmap ); + if (hOldPalette) + SelectPalette(memdc, hOldPalette, FALSE); + // similarly, created an mono-bitmap for the possible mask if( HasMask() ) {