// Author: Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Author: Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
static pixel_format_t gs_pixel_format_15 =
//-----------------------------------------------------------------------------
static pixel_format_t gs_pixel_format_15 =
- {0x1F,0x0A,3, 0x1F,0x05,3, 0x1F,0x00,3, 0x01,0x0F,7}; // 555 15bpp
-
+ {0x1F,0x0A,3, 0x1F,0x05,3, 0x1F,0x00,3, 0x01,0x0F,7}; // 555 15bpp
+
- {0x1F,0x0B,3, 0x3F,0x05,2, 0x1F,0x00,3, 0x00,0x00,0}; // 565 16bpp
+ {0x1F,0x0B,3, 0x3F,0x05,2, 0x1F,0x00,3, 0x00,0x00,0}; // 565 16bpp
- {0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0, 0x00,0x00,0}; // RGB 24bpp
+ {0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0, 0x00,0x00,0}; // RGB 24bpp
- {0xFF,0x18,0, 0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0}; // RGBA 32bpp
+ {0xFF,0x18,0, 0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0}; // RGBA 32bpp
- {0xFF,0x00,0, 0xFF,0x08,0, 0xFF,0x10,0, 0x00,0x00,0}; // RGB 24bpp for wxImage
+ {0xFF,0x00,0, 0xFF,0x08,0, 0xFF,0x10,0, 0x00,0x00,0}; // RGB 24bpp for wxImage
static wxColour wxQuantizeColour(const wxColour& clr, const wxBitmap& bmp)
{
pixel_format_t *pf = bmp.GetMGLbitmap_t()->pf;
static wxColour wxQuantizeColour(const wxColour& clr, const wxBitmap& bmp)
{
pixel_format_t *pf = bmp.GetMGLbitmap_t()->pf;
- return wxColour((clr.Red() >> pf->redAdjust) << pf->redAdjust,
- (clr.Green() >> pf->greenAdjust) << pf->greenAdjust,
- (clr.Blue() >> pf->blueAdjust) << pf->blueAdjust);
+ return wxColour((unsigned char)((clr.Red() >> pf->redAdjust) << pf->redAdjust),
+ (unsigned char)((clr.Green() >> pf->greenAdjust) << pf->greenAdjust),
+ (unsigned char)((clr.Blue() >> pf->blueAdjust) << pf->blueAdjust));
wxColour clr(wxQuantizeColour(colour, bitmap));
wxImage imgSrc(bitmap.ConvertToImage());
wxColour clr(wxQuantizeColour(colour, bitmap));
wxImage imgSrc(bitmap.ConvertToImage());
pal->GetRGB(paletteIndex, &r, &g, &b);
return Create(bitmap, wxColour(r, g, b));
pal->GetRGB(paletteIndex, &r, &g, &b);
return Create(bitmap, wxColour(r, g, b));
- wxCHECK_MSG( bitmap.Ok(), FALSE, wxT("Invalid bitmap") );
- wxCHECK_MSG( bitmap.GetDepth() == 1, FALSE, wxT("Cannot create mask from colour bitmap") );
+ wxCHECK_MSG( bitmap.Ok(), false, wxT("Invalid bitmap") );
+ wxCHECK_MSG( bitmap.GetDepth() == 1, false, wxT("Cannot create mask from colour bitmap") );
int bpp, pixel_format_t *pf)
{
MGLMemoryDC mdc(width, height, bpp, pf);
int bpp, pixel_format_t *pf)
{
MGLMemoryDC mdc(width, height, bpp, pf);
- wxCHECK_MSG( (width > 0) && (height > 0), FALSE, wxT("invalid bitmap size") )
-
- pixel_format_t pf_dummy, *pf;
+ wxCHECK_MSG( (width > 0) && (height > 0), false, wxT("invalid bitmap size") );
+
+ pixel_format_t pf_dummy;
+ pixel_format_t *pf;
wxASSERT_MSG( g_displayDC, wxT("MGL display DC not created yet.") );
g_displayDC->getPixelFormat(pf_dummy);
wxASSERT_MSG( g_displayDC, wxT("MGL display DC not created yet.") );
g_displayDC->getPixelFormat(pf_dummy);
{
// MGL does not support mono DCs, so we have to emulate them with
// 8bpp ones. We do that by using a special palette with color 0
{
// MGL does not support mono DCs, so we have to emulate them with
// 8bpp ones. We do that by using a special palette with color 0
M_BMPDATA->m_bitmap = MyMGL_createBitmap(width, height, 8, pf);
SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
M_BMPDATA->m_bitmap = MyMGL_createBitmap(width, height, 8, pf);
SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
width = image.GetWidth();
height = image.GetHeight();
if ( !Create(width, height, depth) ) return;
width = image.GetWidth();
height = image.GetHeight();
if ( !Create(width, height, depth) ) return;
MGLMemoryDC idc(width, height, 24, &gs_pixel_format_wxImage,
width * 3, (void*)image.GetData(), NULL);
wxASSERT_MSG( idc.isValid(), wxT("cannot create custom MGLDC") );
MGLMemoryDC idc(width, height, 24, &gs_pixel_format_wxImage,
width * 3, (void*)image.GetData(), NULL);
wxASSERT_MSG( idc.isValid(), wxT("cannot create custom MGLDC") );
bdc->bitBlt(idc, 0, 0, width, height, 0, 0, MGL_REPLACE_MODE);
delete bdc;
bdc->bitBlt(idc, 0, 0, width, height, 0, 0, MGL_REPLACE_MODE);
delete bdc;
wxBitmap mask_bmp(mask_image, 1);
SetMask(new wxMask(mask_bmp));
}
wxBitmap mask_bmp(mask_image, 1);
SetMask(new wxMask(mask_bmp));
}
wxImage image(width, height);
wxASSERT_MSG( image.Ok(), wxT("cannot create image") );
wxImage image(width, height);
wxASSERT_MSG( image.Ok(), wxT("cannot create image") );
MGLMemoryDC idc(width, height, 24, &gs_pixel_format_wxImage,
width * 3, (void*)image.GetData(), NULL);
wxASSERT_MSG( idc.isValid(), wxT("cannot create custom MGLDC") );
if ( M_BMPDATA->m_palette )
image.SetPalette(*(M_BMPDATA->m_palette));
MGLMemoryDC idc(width, height, 24, &gs_pixel_format_wxImage,
width * 3, (void*)image.GetData(), NULL);
wxASSERT_MSG( idc.isValid(), wxT("cannot create custom MGLDC") );
if ( M_BMPDATA->m_palette )
image.SetPalette(*(M_BMPDATA->m_palette));
// bg colour set to black and fg colour to <16,16,16>
image.SetMaskColour(16, 16, 16);
// bg colour set to black and fg colour to <16,16,16>
image.SetMaskColour(16, 16, 16);
tmpDC.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID));
tmpDC.Clear();
tmpDC.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID));
tmpDC.Clear();
- tmpDC.DrawBitmap(*this, 0, 0, TRUE);
+ tmpDC.DrawBitmap(*this, 0, 0, true);
idc.putBitmap(0, 0, M_BMPDATA->m_bitmap, MGL_REPLACE_MODE);
}
return image;
}
idc.putBitmap(0, 0, M_BMPDATA->m_bitmap, MGL_REPLACE_MODE);
}
return image;
}
wxBitmap::wxBitmap(const wxString &filename, wxBitmapType type)
{
LoadFile(filename, type);
wxBitmap::wxBitmap(const wxString &filename, wxBitmapType type)
{
LoadFile(filename, type);
rect.x + rect.width, rect.y + rect.height,
0, 0, M_BMPDATA->m_bitmap, MGL_REPLACE_MODE);
delete tdc;
rect.x + rect.width, rect.y + rect.height,
0, 0, M_BMPDATA->m_bitmap, MGL_REPLACE_MODE);
delete tdc;
M_BMPDATA->m_bitmap->bitsPerPixel,
M_BMPDATA->m_bitmap->pf,
M_BMPDATA->m_bitmap->bytesPerLine,
M_BMPDATA->m_bitmap->bitsPerPixel,
M_BMPDATA->m_bitmap->pf,
M_BMPDATA->m_bitmap->bytesPerLine,
NULL);
wxCHECK_MSG( tdc->isValid(), NULL, wxT("cannot create temporary MGLDC") );
if ( M_BMPDATA->m_bitmap->pal != NULL )
{
int cnt;
NULL);
wxCHECK_MSG( tdc->isValid(), NULL, wxT("cannot create temporary MGLDC") );
if ( M_BMPDATA->m_bitmap->pal != NULL )
{
int cnt;
tdc->setPalette(M_BMPDATA->m_bitmap->pal, cnt, 0);
tdc->realizePalette(cnt, 0, FALSE);
}
tdc->setPalette(M_BMPDATA->m_bitmap->pal, cnt, 0);
tdc->realizePalette(cnt, 0, FALSE);
}
type == wxBITMAP_TYPE_PCX || type == wxBITMAP_TYPE_JPEG )
{
// prevent accidental loading of bitmap from $MGL_ROOT:
if ( !wxFileExists(name) )
{
wxLogError(_("File %s does not exist."), name.c_str());
type == wxBITMAP_TYPE_PCX || type == wxBITMAP_TYPE_JPEG )
{
// prevent accidental loading of bitmap from $MGL_ROOT:
if ( !wxFileExists(name) )
{
wxLogError(_("File %s does not exist."), name.c_str());
bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
{
bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
{
wxMGLBitmapHandler(wxBitmapType type,
const wxString& extension, const wxString& name);
wxMGLBitmapHandler(wxBitmapType type,
const wxString& extension, const wxString& name);
- virtual bool Create(wxBitmap *bitmap, void *data, long flags,
- int width, int height, int depth = 1)
- { return FALSE; }
+ virtual bool Create(wxBitmap *WXUNUSED(bitmap),
+ void *WXUNUSED(data),
+ long WXUNUSED(flags),
+ int WXUNUSED(width),
+ int WXUNUSED(height),
+ int WXUNUSED(depth) = 1)
+ { return false; }
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth, int desiredHeight);
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth, int desiredHeight);
-bool wxMGLBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
- long flags,
- int WXUNUSED(desiredWidth),
+bool wxMGLBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
+ long flags,
+ int WXUNUSED(desiredWidth),
switch (flags)
{
case wxBITMAP_TYPE_BMP:
case wxBITMAP_TYPE_BMP_RESOURCE:
if ( !MGL_getBitmapSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
switch (flags)
{
case wxBITMAP_TYPE_BMP:
case wxBITMAP_TYPE_BMP_RESOURCE:
if ( !MGL_getBitmapSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadBitmapIntoDC(fullname.mb_str(), 0, 0, TRUE) )
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadBitmapIntoDC(fullname.mb_str(), 0, 0, TRUE) )
break;
case wxBITMAP_TYPE_JPEG:
case wxBITMAP_TYPE_JPEG_RESOURCE:
if ( !MGL_getJPEGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
break;
case wxBITMAP_TYPE_JPEG:
case wxBITMAP_TYPE_JPEG_RESOURCE:
if ( !MGL_getJPEGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadJPEGIntoDC(fullname.mb_str(), 0, 0, TRUE) )
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadJPEGIntoDC(fullname.mb_str(), 0, 0, TRUE) )
break;
case wxBITMAP_TYPE_PNG:
case wxBITMAP_TYPE_PNG_RESOURCE:
if ( !MGL_getPNGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
break;
case wxBITMAP_TYPE_PNG:
case wxBITMAP_TYPE_PNG_RESOURCE:
if ( !MGL_getPNGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadPNGIntoDC(fullname.mb_str(), 0, 0, TRUE) )
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadPNGIntoDC(fullname.mb_str(), 0, 0, TRUE) )
break;
case wxBITMAP_TYPE_PCX:
case wxBITMAP_TYPE_PCX_RESOURCE:
if ( !MGL_getPCXSize(fullname.mb_str(), &width, &height, &bpp) )
break;
case wxBITMAP_TYPE_PCX:
case wxBITMAP_TYPE_PCX_RESOURCE:
if ( !MGL_getPCXSize(fullname.mb_str(), &width, &height, &bpp) )
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadPCXIntoDC(fullname.mb_str(), 0, 0, TRUE) )
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadPCXIntoDC(fullname.mb_str(), 0, 0, TRUE) )
- return tdc->saveBitmapFromDC(name.mb_str(), 0, 0, w, h);
- break;
+ return (bool)tdc->saveBitmapFromDC(name.mb_str(), 0, 0, w, h);
- return tdc->saveJPEGFromDC(name.mb_str(), 0, 0, w, h, 75);
- break;
+ return (bool)tdc->saveJPEGFromDC(name.mb_str(), 0, 0, w, h, 75);
- return tdc->savePNGFromDC(name.mb_str(), 0, 0, w, h);
- break;
+ return (bool)tdc->savePNGFromDC(name.mb_str(), 0, 0, w, h);
- return tdc->savePCXFromDC(name.mb_str(), 0, 0, w, h);
- break;
- default:
- return FALSE;
- break;
+ return (bool)tdc->savePCXFromDC(name.mb_str(), 0, 0, w, h);
fullname = name;
if ( !MGL_getPNGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
fullname = name;
if ( !MGL_getPNGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
if ( bpp != 32 )
{
// We can load ordinary PNGs faster with 'normal' MGL handler.
// Only RGBA PNGs need to be processed in special way because
// we have to convert alpha channel to mask
if ( bpp != 32 )
{
// We can load ordinary PNGs faster with 'normal' MGL handler.
// Only RGBA PNGs need to be processed in special way because
// we have to convert alpha channel to mask
- return wxMGLBitmapHandler::LoadFile(bitmap, name, flags,
+ return wxMGLBitmapHandler::LoadFile(bitmap, name, flags,
// convert bmp to display's depth and write it to *bitmap:
wxMemoryDC dc;
dc.SelectObject(*bitmap);
dc.GetMGLDC()->putBitmap(0, 0, bmp, MGL_REPLACE_MODE);
dc.SelectObject(wxNullBitmap);
// convert bmp to display's depth and write it to *bitmap:
wxMemoryDC dc;
dc.SelectObject(*bitmap);
dc.GetMGLDC()->putBitmap(0, 0, bmp, MGL_REPLACE_MODE);
dc.SelectObject(wxNullBitmap);
// create mask, if bmp contains alpha channel (ARGB format):
if ( bmp->bitsPerPixel == 32 )
{
// create mask, if bmp contains alpha channel (ARGB format):
if ( bmp->bitsPerPixel == 32 )
{
s = ((wxUint32*)bmp->surface) + y * bmp->bytesPerLine/4;
for (x = 0; x < bmp->width; x++, s ++)
{
s = ((wxUint32*)bmp->surface) + y * bmp->bytesPerLine/4;
for (x = 0; x < bmp->width; x++, s ++)
{
public:
wxICOBitmapHandler(wxBitmapType type,
const wxString& extension, const wxString& name);
public:
wxICOBitmapHandler(wxBitmapType type,
const wxString& extension, const wxString& name);
-
- virtual bool Create(wxBitmap *bitmap, void *data, long flags,
- int width, int height, int depth = 1)
- { return FALSE; }
-
+
+ virtual bool Create(wxBitmap *WXUNUSED(bitmap),
+ void *WXUNUSED(data),
+ long WXUNUSED(flags),
+ int WXUNUSED(width),
+ int WXUNUSED(height),
+ int WXUNUSED(depth) = 1)
+ { return false; }
+
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth, int desiredHeight);
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth, int desiredHeight);
-bool wxICOBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
- long flags,
- int WXUNUSED(desiredWidth),
+bool wxICOBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
+ long flags,
+ int WXUNUSED(desiredWidth),
if ( flags == wxBITMAP_TYPE_ICO_RESOURCE )
icon = MGL_loadIcon(wxString(name + wxT(".ico")).mb_str(), TRUE);
if ( flags == wxBITMAP_TYPE_ICO_RESOURCE )
icon = MGL_loadIcon(wxString(name + wxT(".ico")).mb_str(), TRUE);
dc->clearDevice();
dc->putMonoImage(0, 0, icon->xorMask.width, icon->byteWidth,
icon->xorMask.height, (void*)icon->andMask);
dc->clearDevice();
dc->putMonoImage(0, 0, icon->xorMask.width, icon->byteWidth,
icon->xorMask.height, (void*)icon->andMask);
-bool wxICOBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name,
- int type, const wxPalette * WXUNUSED(palette))
+bool wxICOBitmapHandler::SaveFile(const wxBitmap *WXUNUSED(bitmap),
+ const wxString& WXUNUSED(name),
+ int WXUNUSED(type),
+ const wxPalette * WXUNUSED(palette))