Example #1
0
wxBitmap BlendBitmaps(const wxBitmap& background, const wxBitmap& overlay, const int /*dim*/)
{
	wxImage back = background.ConvertToImage();
	wxImage front = overlay.ConvertToImage();
	wxImage ret = BlendImage(front, back);
	return wxBitmap(ret);
}
Example #2
0
wxBitmap ConvertTo24Bit( wxColor bgColor, wxBitmap front ) {
    if( front.GetDepth() == 24 ) return front;

    wxBitmap result( front.GetWidth(), front.GetHeight(), 24 );
    front.UseAlpha();

    wxImage im_front = front.ConvertToImage();
    wxImage im_result = result.ConvertToImage();

    unsigned char *presult = im_result.GetData();
    unsigned char *pfront = im_front.GetData();

    unsigned char *afront = NULL;
    if( im_front.HasAlpha() )
        afront = im_front.GetAlpha();

    for( int i = 0; i < result.GetWidth(); i++ ) {
        for( int j = 0; j < result.GetHeight(); j++ ) {

            double alphaF = (double) ( *afront++ ) / 256.0;
            unsigned char r = *pfront++ * alphaF + bgColor.Red() * ( 1.0 - alphaF );
            *presult++ = r;
            unsigned char g = *pfront++ * alphaF + bgColor.Green() * ( 1.0 - alphaF );
            *presult++ = g;
            unsigned char b = *pfront++ * alphaF + bgColor.Blue() * ( 1.0 - alphaF );
            *presult++ = b;
        }
    }

    result = wxBitmap( im_result );
    return result;
}
Example #3
0
wxImage ReplaceChannelStatusColour( wxBitmap img, const wxColour& colour )
{
  wxImage ret = img.ConvertToImage();
  wxImage::HSVValue origcolour = wxImage::RGBtoHSV( wxImage::RGBValue( colour.Red(), colour.Green(), colour.Blue() ) );

  double bright = origcolour.value - 0.1*origcolour.value;
  bright = LSL::Util::Clamp( bright, 0.0, 1.0 );
  wxImage::HSVValue hsvdarker1( origcolour.hue, origcolour.saturation, bright );
  bright = origcolour.value - 0.5*origcolour.value;
  bright = LSL::Util::Clamp( bright, 0.0, 1.0 );
  wxImage::HSVValue hsvdarker2( origcolour.hue, origcolour.saturation, bright );

  wxImage::RGBValue rgbdarker1 = wxImage::HSVtoRGB( hsvdarker1 );
  wxImage::RGBValue rgbdarker2 = wxImage::HSVtoRGB( hsvdarker2 );


  ret.Replace( 164, 147, 0, rgbdarker2.red, rgbdarker2.green, rgbdarker2.blue );

  ret.Replace( 255, 228, 0, rgbdarker1.red, rgbdarker1.green, rgbdarker1.blue );

  ret.Replace( 255, 253, 234, colour.Red(), colour.Green(), colour.Blue() );

  return ret;

}
Example #4
0
wxBitmap wxCustomButton::CreateBitmapDisabled(const wxBitmap &bitmap) const
{
    wxCHECK_MSG(bitmap.Ok(), wxNullBitmap, wxT("invalid bitmap"));

    unsigned char br = GetBackgroundColour().Red();
    unsigned char bg = GetBackgroundColour().Green();
    unsigned char bb = GetBackgroundColour().Blue();

    wxImage image = bitmap.ConvertToImage();
    int pos, width = image.GetWidth(), height = image.GetHeight();
    unsigned char *img_data = image.GetData();

    for (int j=0; j<height; j++)
    {
        for (int i=j%2; i<width; i+=2)
        {
            pos = (j*width+i)*3;
            img_data[pos  ] = br;
            img_data[pos+1] = bg;
            img_data[pos+2] = bb;
        }
    }

    return wxBitmap(image);
}
Example #5
0
// Adds a bitmap, using the specified colour to create the mask bitmap
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap'.
int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour)
{
    HBITMAP hbmp;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // See the comment in overloaded Add() above.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        hbmp = wxDIB(bitmap.ConvertToImage(),
                     wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
        hbmp = GetHbitmapOf(bitmap);

    int index = ImageList_AddMasked(GetHImageList(),
                                    hbmp,
                                    wxColourToRGB(maskColour));
    if ( index == -1 )
    {
        wxLogError(_("Couldn't add an image to the image list."));
    }

    return index;
}
Example #6
0
// Adds a bitmap, and optionally a mask bitmap.
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap' and 'mask'.
int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
{
    HBITMAP hbmp;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // wxBitmap normally stores alpha in pre-multiplied format but
    // ImageList_Draw() does pre-multiplication internally so we need to undo
    // the pre-multiplication here. Converting back and forth like this is, of
    // course, very inefficient but it's better than wrong appearance so we do
    // this for now until a better way can be found.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        hbmp = wxDIB(bitmap.ConvertToImage(),
                     wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
        hbmp = GetHbitmapOf(bitmap);

    // Use mask only if we don't have alpha, the bitmap isn't drawn correctly
    // if we use both.
    AutoHBITMAP hbmpMask;
    if ( !bitmap.HasAlpha() )
        hbmpMask.Init(GetMaskForImage(bitmap, mask));

    int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
    if ( index == -1 )
    {
        wxLogError(_("Couldn't add an image to the image list."));
    }

    return index;
}
Example #7
0
int wxImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
{
    wxImage img = bitmap.ConvertToImage();
    img.SetMaskColour( maskColour.Red(), maskColour.Green(), maskColour.Blue() );

    return Add( wxBitmap( img ) );
}
Example #8
0
static void OverlaySymlink(wxBitmap& bmp)
{
	// This is ugly, but apparently needed so that the data is _really_ in the right internal format
	bmp = bmp.ConvertToImage();
	wxBitmap symlink = wxArtProvider::GetBitmap(_T("ART_SYMLINK"),  wxART_OTHER, wxSize(bmp.GetWidth(), bmp.GetHeight())).ConvertToImage();

	wxAlphaPixelData target(bmp);
	wxAlphaPixelData source(symlink);

	int sx = bmp.GetWidth();
	if (symlink.GetWidth() < sx)
		sx = symlink.GetWidth();		
	int sy = bmp.GetHeight();
	if (symlink.GetHeight() < sy)
		sy = symlink.GetHeight();		

	// Do some rudimentary alpha copying
	wxAlphaPixelData::Iterator t(target);
	wxAlphaPixelData::Iterator s(source);
	for (int y = 0; y < sy; y++)
	{
		s.MoveTo(source, 0, y);
		t.MoveTo(target, 0, y);
		for (int x = 0; x < sx; x++, s++, t++)
			AlphaComposite_Over_Inplace(t, s);
	}
}
Example #9
0
// Replaces a bitmap, optionally passing a mask bitmap.
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap' and 'mask'.
bool wxImageList::Replace(int index,
                          const wxBitmap& bitmap,
                          const wxBitmap& mask)
{
    HBITMAP hbmp;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // See the comment in Add() above.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        hbmp = wxDIB(bitmap.ConvertToImage(),
                     wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
        hbmp = GetHbitmapOf(bitmap);

    AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask));

    if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
    {
        wxLogLastError(wxT("ImageList_Replace()"));
        return false;
    }

    return true;
}
Example #10
0
    void setImage(wxString path)
    {
        m_image_path = path;

        if(path.EndsWith(wxT(".icns"))) {
            wxExecute(wxT("sips -s format png '") + path + wxT("' --out /tmp/tmpicon.png"), wxEXEC_SYNC);
            path = wxT("/tmp/tmpicon.png");
        }

        m_image.LoadFile(path, wxBITMAP_TYPE_ANY);

        if(m_image.IsOk()) {
            if(m_image.GetWidth() > 50 or m_image.GetHeight() > 50) {
                wxImage tmp = m_image.ConvertToImage();
                tmp.Rescale(50, 50, wxIMAGE_QUALITY_HIGH);
                m_image = wxBitmap(tmp);
            }

            const int w = m_image.GetWidth();
            const int h = m_image.GetHeight();
            SetMinSize(wxSize(w + 20, h + 20));
            SetMaxSize(wxSize(w + 20, h + 20));
            Refresh(); // repaint needed to see change
        } else {
            wxMessageBox(_("Failed to load image"));
        }
    }
void wxSpeedButton::MakeTransparent(wxBitmap &inBitmap) {
int         h;
int         r,g,b;
wxImage     img;
wxBitmap    *bmp;

// not a good image?

    if (! inBitmap.IsOk()) return;

// already have a mask?

    img = inBitmap.ConvertToImage();
    if (img.HasMask()) return;

// get the colors of the lower-left corner of the image

    h = img.GetHeight();
    r = img.GetRed(0, h-1);
    b = img.GetBlue(0, h-1);
    g = img.GetGreen(0, h-1);

// make a mask from those colors

    img.SetMaskColour(r, g, b);

// store it back in the bitmap

    bmp = new wxBitmap(img);
    inBitmap = *bmp;
}
Example #12
0
/*static*/ void
wxMemoryFSHandler::AddFile(const wxString& filename,
                           const wxBitmap& bitmap,
                           wxBitmapType type)
{
    wxImage img = bitmap.ConvertToImage();
    AddFile(filename, img, type);
}
Example #13
0
wxBitmap wxCustomButton::CreateBitmapDisabled(const wxBitmap &bitmap) const
{
    wxCHECK_MSG(bitmap.Ok(), wxNullBitmap, wxT("invalid bitmap"));

    unsigned char br = GetBackgroundColour().Red();
    unsigned char bg = GetBackgroundColour().Green();
    unsigned char bb = GetBackgroundColour().Blue();

    wxImage image = bitmap.ConvertToImage();
    int pos, width = image.GetWidth(), height = image.GetHeight();
    unsigned char *img_data = image.GetData();

    for (int j=0; j<height; j++)
    {
        for (int i=j%2; i<width; i+=2)
        {
            pos = (j*width+i)*3;
            img_data[pos  ] = br;
            img_data[pos+1] = bg;
            img_data[pos+2] = bb;
        }
    }

    return wxBitmap(image);

/*      // FIXME why bother creating focused wxCustomButton's bitmap
        wxImage imgFoc = bitmap.ConvertToImage();

        bool mask = false;
        unsigned char mr=0, mg=0, mb=0;
        if (img.HasMask())
        {
            mask = true;
            mr = imgDis.GetMaskRed();
            mg = imgDis.GetMaskGreen();
            mb = imgDis.GetMaskBlue();
        }
        unsigned char *r, *g, *b;
        unsigned char *focData = imgFoc.GetData();
        r = imgFoc.GetData();
        g = imgFoc.GetData() + 1;
        b = imgFoc.GetData() + 2;
        for (int j=0; j<h; j++)
        {
            for (int i=0; i<w; i++)
            {
                if ((!mask || ((*r!=mr)&&(*b!=mb)&&(*g!=mg))) &&
                    ((*r<236)&&(*b<236)&&(*g<236)))
                {
                    *r += 20; *g += 20; *b += 20;
                }
                r += 3; g += 3; b += 3;
            }
        }
        m_bmpFocus = wxBitmap(imgFoc);
*/

}
Example #14
0
void DrawGLUtils::CreateOrUpdateTexture(const wxBitmap &bmp48,
                                        const wxBitmap &bmp32,
                                        const wxBitmap &bmp16,
                                        GLuint* texture)
{
    int level = 0;
    glGenTextures(1,texture);
    glBindTexture(GL_TEXTURE_2D, *texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    addMipMap(texture, bmp48.ConvertToImage().Rescale(64, 64, wxIMAGE_QUALITY_HIGH), level);
    addMipMap(texture, bmp32.ConvertToImage(), level);
    addMipMap(texture, bmp16.ConvertToImage(), level);
    addMipMap(texture, bmp16.ConvertToImage().Rescale(8, 8, wxIMAGE_QUALITY_HIGH), level);
    addMipMap(texture, bmp16.ConvertToImage().Rescale(4, 4, wxIMAGE_QUALITY_HIGH), level);
    addMipMap(texture, bmp16.ConvertToImage().Rescale(2, 2, wxIMAGE_QUALITY_HIGH), level);
    addMipMap(texture, bmp16.ConvertToImage().Rescale(1, 1, wxIMAGE_QUALITY_HIGH), level);
}
Example #15
0
// See also: wxButton::DoSetBitmap and wxBitmapButton::DoSetBitmap
void DynamicBitmap::SetBitmap( const wxBitmap& bitmap, wxButtonBase::State state )
{
    if ( bitmap.IsOk() )
    {
        DoSetBitmap( bitmap, state );

        switch ( state )
        {
            default:
                // nothing special to do but include the default clause to
                // suppress gcc warnings
                //HELIUM_ASSERT();
                break;

            case wxButtonBase::State_Normal:
                m_WasStateSetByUser[wxButtonBase::State_Normal] = true;
#if wxUSE_IMAGE
                if ( !m_WasStateSetByUser[wxButtonBase::State_Disabled] )
                {
                    wxImage disabledImage( bitmap.ConvertToImage().ConvertToGreyscale() );
                    DoSetBitmap( disabledImage, wxButtonBase::State_Disabled );
                }
#endif // wxUSE_IMAGE
                break;

            case wxButtonBase::State_Current:
                m_WasStateSetByUser[wxButtonBase::State_Current] = true;
                break;

            case wxButtonBase::State_Pressed:
                m_WasStateSetByUser[wxButtonBase::State_Pressed] = true;
                break;

            case wxButtonBase::State_Disabled:
                m_WasStateSetByUser[wxButtonBase::State_Disabled] = true;
                break;

            case wxButtonBase::State_Focused:
                m_WasStateSetByUser[wxButtonBase::State_Focused] = true;

                // if the focus bitmap is specified but current one isn't, use
                // the focus bitmap for hovering as well if this is consistent
                // with the current Windows version look and feel
                //
                // rationale: this is compatible with the old wxGTK behaviour
                // and also makes it much easier to do "the right thing" for
                // all platforms (some of them, such as Windows XP, have "hot"
                // buttons while others don't)
                if ( !m_WasStateSetByUser[wxButtonBase::State_Current] )
                {
                    DoSetBitmap( bitmap, wxButtonBase::State_Current );
                }
                break;
        }
    }
}
Example #16
0
// ----------------------------------------------------------------------------
void BitmapWidget::OnPaint(wxPaintEvent &event)
{
    wxAutoBufferedPaintDC dc(this);

    dc.SetBackground(*wxBLACK_BRUSH);
    dc.Clear();

    wxImage img(m_bmp->ConvertToImage());
    dc.DrawBitmap(wxBitmap(img.Scale(m_w, m_h)), m_x, m_y, false);
}
Example #17
0
bool wxRegion::Union(const wxBitmap& bmp,
                     const wxColour& transColour,
                     int   tolerance)
{
    wxImage image = bmp.ConvertToImage();
    return DoRegionUnion(*this, image,
                         transColour.Red(),
                         transColour.Green(),
                         transColour.Blue(),
                         tolerance);
}
Example #18
0
wxBitmap RescaleBitmap(const wxBitmap& bitmap, const wxSize& size, bool hq)
{
    wxASSERT(bitmap.IsOk());

    if (!bitmap.IsOk())
        return wxNullBitmap;

    wxImage image = bitmap.ConvertToImage();
    image.Rescale(size.x, size.y, hq ? wxIMAGE_QUALITY_HIGH : wxIMAGE_QUALITY_NORMAL);

    return image;
}
Example #19
0
wxBitmap AdjustBitmapSize(const wxBitmap& bitmap, const wxSize& size, const wxPoint& origin)
{
    wxASSERT(bitmap.IsOk());

    if (!bitmap.IsOk())
        return wxNullBitmap;

    wxImage image=bitmap.ConvertToImage();
    image.Resize(size, origin);

    return image;
}
Example #20
0
static wxBitmap CreateDisabledBitmap(const wxBitmap& bmp)
{
    wxImage img = bmp.ConvertToImage();
    img = img.ConvertToGreyscale();
    wxBitmap greyBmp(img);
    if(DrawingUtils::IsThemeDark()) {
        return greyBmp.ConvertToDisabled(70);

    } else {
        return greyBmp.ConvertToDisabled(150);
    }
}
Example #21
0
// Adds a bitmap, and optionally a mask bitmap.
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap' and 'mask'.
int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
{
    HBITMAP hbmp;
    bool useMask;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // wxBitmap normally stores alpha in pre-multiplied format but
    // ImageList_Draw() does pre-multiplication internally so we need to undo
    // the pre-multiplication here. Converting back and forth like this is, of
    // course, very inefficient but it's better than wrong appearance so we do
    // this for now until a better way can be found.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        wxImage img = bitmap.ConvertToImage();

        // For comctl32.dll < 6 remove alpha channel from image
        // to prevent possible interferences with the mask.
        if ( wxApp::GetComCtl32Version() < 600 )
        {
            img.ClearAlpha();
            useMask = true;
        }
        else
        {
            useMask = false;
        }

        hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
    {
        hbmp = GetHbitmapOf(bitmap);
        useMask = true;
    }

    // Use mask only if we don't have alpha, the bitmap isn't drawn correctly
    // if we use both.
    AutoHBITMAP hbmpMask;
    if ( useMask )
        hbmpMask.Init(GetMaskForImage(bitmap, mask));

    int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
    if ( index == -1 )
    {
        wxLogError(_("Couldn't add an image to the image list."));
    }

    return index;
}
Example #22
0
static wxBitmap wxMakeStdSizeBitmap(const wxBitmap& bitmap)
{
    // in Mac OS X the icon controls (which are used for borderless bitmap
    // buttons) can have only one of the few standard sizes and if they
    // don't, the OS rescales them automatically resulting in really ugly
    // images, so centre the image in a square of standard size instead

    // the supported sizes, sorted in decreasng order
    static const int stdSizes[] = { 128, 48, 32, 16, 0 };

    const int width = bitmap.GetWidth();
    const int height = bitmap.GetHeight();

    wxBitmap newBmp(bitmap);
    
    int n;
    for ( n = 0; n < (int)WXSIZEOF(stdSizes); n++ )
    {
        const int sizeStd = stdSizes[n];
        if ( width > sizeStd || height > sizeStd )
        {
            // it will become -1 if the bitmap is larger than the biggest
            // supported size, this is intentional
            n--;

            break;
        }
    }

    if ( n != -1 )
    {
        const int sizeStd = stdSizes[n];
        if ( width != sizeStd || height != sizeStd )
        {
            wxASSERT_MSG( width <= sizeStd && height <= sizeStd,
                          _T("bitmap shouldn't be cropped") );

            wxImage square_image = bitmap.ConvertToImage();
            newBmp = square_image.Size
                     (
                         wxSize(sizeStd, sizeStd),
                         wxPoint((sizeStd - width)/2, (sizeStd-height)/2)
                     );
        }
    }
    //else: let the system rescale the bitmap

    return newBmp;
}
Example #23
0
void wxBitmapButton::DoSetBitmap(const wxBitmap& bitmap, State which)
{
    if ( bitmap.IsOk() )
    {
        switch ( which )
        {
#if wxUSE_IMAGE
            case State_Normal:
                if ( !HasFlag(wxBU_AUTODRAW) && !m_disabledSetByUser )
                {
                    wxImage img(bitmap.ConvertToImage().ConvertToGreyscale());
                    wxBitmapButtonBase::DoSetBitmap(img, State_Disabled);
                }
                break;
#endif // wxUSE_IMAGE

            case State_Focused:
                // if the focus bitmap is specified but current one isn't, use
                // the focus bitmap for hovering as well if this is consistent
                // with the current Windows version look and feel
                //
                // rationale: this is compatible with the old wxGTK behaviour
                // and also makes it much easier to do "the right thing" for
                // all platforms (some of them, such as Windows XP, have "hot"
                // buttons while others don't)
                if ( !m_hoverSetByUser )
                    wxBitmapButtonBase::DoSetBitmap(bitmap, State_Current);
                break;

            case State_Current:
                // don't overwrite it with the focused bitmap
                m_hoverSetByUser = true;
                break;

            case State_Disabled:
                // don't overwrite it with the version automatically created
                // from the normal one
                m_disabledSetByUser = true;
                break;

            default:
                // nothing special to do but include the default clause to
                // suppress gcc warnings
                ;
        }
    }

    wxBitmapButtonBase::DoSetBitmap(bitmap, which);
}
Example #24
0
bool wxRegion::Union(const wxBitmap& bmp,
                     const wxColour& transColour,
                     int   tolerance)
{
#if (!defined(__WXMSW__) || wxUSE_WXDIB)
    wxImage image = bmp.ConvertToImage();
    return DoRegionUnion(*this, image,
                         transColour.Red(),
                         transColour.Green(),
                         transColour.Blue(),
                         tolerance);
#else
    return false;
#endif                         
}
Example #25
0
static wxBitmap ConvertToDisabled(const wxBitmap& bmp)
{
#if wxVERSION_NUMBER >= 3100 && !defined(__WXMSW__)
    // Convert the image to disabled
    // It seems that m_bitmap.ConvertToDisabled() looses the scale
    // factor, so use this kind of conversion
    wxImage img = bmp.ConvertToImage();
    img = img.ConvertToDisabled();
    // Keep the original m_bitmap scale factor
    wxBitmap disabledBmp = wxBitmap(img, -1, bmp.GetScaleFactor());
    return disabledBmp;
#else
    return bmp.ConvertToDisabled();
#endif
}
Example #26
0
void Image::LoadImage(const wxBitmap &bitmap)
{
  // Convert the bitmap to a png image we can use as m_compressedImage
  wxImage image = bitmap.ConvertToImage();
  wxMemoryOutputStream stream;
  image.SaveFile(stream,wxBITMAP_TYPE_PNG);
  m_compressedImage.AppendData(stream.GetOutputStreamBuffer()->GetBufferStart(),
			       stream.GetOutputStreamBuffer()->GetBufferSize());

  // Set the info about the image.
  m_extension = wxT("png");
  m_originalWidth  = image.GetWidth();
  m_originalHeight = image.GetHeight();
  m_scaledBitmap.Create (1,1);
}
Example #27
0
// Replaces a bitmap, optionally passing a mask bitmap.
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap' and 'mask'.
bool wxImageList::Replace(int index,
                          const wxBitmap& bitmap,
                          const wxBitmap& mask)
{
    HBITMAP hbmp;
    bool useMask;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // See the comment in Add() above.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        wxImage img = bitmap.ConvertToImage();

        if ( wxApp::GetComCtl32Version() < 600 )
        {
            img.ClearAlpha();
            useMask = true;
        }
        else
        {
            useMask = false;
        }

        hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
    {
        hbmp = GetHbitmapOf(bitmap);
        useMask = true;
    }

    AutoHBITMAP hbmpMask;
    if ( useMask )
        hbmpMask.Init(GetMaskForImage(bitmap, mask));

    if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
    {
        wxLogLastError(wxT("ImageList_Replace()"));
        return false;
    }

    return true;
}
Example #28
0
wxBitmap KiScaledBitmap( const wxBitmap& aBitmap, EDA_BASE_FRAME* aWindow )
{
    const int scale = get_scale_factor( aWindow );

    if( scale == 4)
    {
        return wxBitmap( aBitmap );
    }
    else
    {
        wxImage image = aBitmap.ConvertToImage();
        image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
            wxIMAGE_QUALITY_BILINEAR );

        return wxBitmap( image );
    }
}
Example #29
0
bool wxRegion::Union(const wxBitmap& bmp)
{
    if (bmp.GetMask())
    {
        wxImage image = bmp.ConvertToImage();
        wxASSERT_MSG( image.HasMask(), _T("wxBitmap::ConvertToImage doesn't preserve mask?") );
        return DoRegionUnion(*this, image,
                             image.GetMaskRed(),
                             image.GetMaskGreen(),
                             image.GetMaskBlue(),
                             0);
    }
    else
    {
        return Union(0, 0, bmp.GetWidth(), bmp.GetHeight());
    }
}
Example #30
0
bool
wxSVGBitmapEmbedHandler::ProcessBitmap(const wxBitmap& bmp,
                                       wxCoord x, wxCoord y,
                                       wxOutputStream& stream) const
{
    static int sub_images = 0;

    if ( wxImage::FindHandler(wxBITMAP_TYPE_PNG) == NULL )
        wxImage::AddHandler(new wxPNGHandler);

    // write the bitmap as a PNG to a memory stream and Base64 encode
    wxMemoryOutputStream mem;
    bmp.ConvertToImage().SaveFile(mem, wxBITMAP_TYPE_PNG);
    wxString data = wxBase64Encode(mem.GetOutputStreamBuffer()->GetBufferStart(),
                                   mem.GetSize());

    // write image meta information
    wxString s;
    s += wxString::Format(" <image x=\"%d\" y=\"%d\" "
                          "width=\"%dpx\" height=\"%dpx\" "
                          "title=\"Image from wxSVG\"\n",
                          x, y, bmp.GetWidth(), bmp.GetHeight());
    s += wxString::Format(" id=\"image%d\" "
                          "xlink:href=\"data:image/png;base64,\n",
                          sub_images++);

    // Wrap Base64 encoded data on 76 columns boundary (same as Inkscape).
    const unsigned WRAP = 76;
    for ( size_t i = 0; i < data.size(); i += WRAP )
    {
        if (i < data.size() - WRAP)
            s += data.Mid(i, WRAP) + "\n";
        else
            s += data.Mid(i, s.size() - i) + "\"\n/>"; // last line
    }

    // write to the SVG file
    const wxCharBuffer buf = s.utf8_str();
    stream.Write(buf, strlen((const char *)buf));

    return stream.IsOk();
}