mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 09:39:42 +02:00
Image manipulation functions return smart pointers
This commit is contained in:
parent
99cb50d6db
commit
c78e91f6c1
@ -30,7 +30,7 @@ channel. This collection of functions fills that gap.
|
||||
/// the entire image by the vector difference between that
|
||||
/// pixel and the dstColour. For better control, use
|
||||
/// ChangeImageColour(wxImage, wxColour*, wxColour*) below
|
||||
wxImage *ChangeImageColour(wxImage * srcImage, wxColour & dstColour)
|
||||
std::unique_ptr<wxImage> ChangeImageColour(wxImage * srcImage, wxColour & dstColour)
|
||||
{
|
||||
unsigned char *src = srcImage->GetData();
|
||||
wxColour c;
|
||||
@ -40,7 +40,7 @@ wxImage *ChangeImageColour(wxImage * srcImage, wxColour & dstColour)
|
||||
|
||||
///This will explicitly shift the image color from
|
||||
///srcColour to dstColour.
|
||||
wxImage *ChangeImageColour(wxImage * srcImage,
|
||||
std::unique_ptr<wxImage> ChangeImageColour(wxImage * srcImage,
|
||||
wxColour & srcColour,
|
||||
wxColour & dstColour)
|
||||
{
|
||||
@ -56,7 +56,7 @@ wxImage *ChangeImageColour(wxImage * srcImage,
|
||||
int width = srcImage->GetWidth();
|
||||
int height = srcImage->GetHeight();
|
||||
|
||||
wxImage * dstImage = new wxImage(width, height);
|
||||
auto dstImage = std::make_unique<wxImage>(width, height);
|
||||
unsigned char *dst = dstImage->GetData();
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ wxImage *ChangeImageColour(wxImage * srcImage,
|
||||
c = (c + 1) % 3;
|
||||
}
|
||||
|
||||
return dstImage;
|
||||
return std::move(dstImage);
|
||||
}
|
||||
|
||||
/// Takes a background image, foreground image, and mask
|
||||
@ -98,7 +98,7 @@ wxImage *ChangeImageColour(wxImage * srcImage,
|
||||
/// returns an NEW image where the foreground has been
|
||||
/// overlaid onto the background using alpha-blending,
|
||||
/// at location (xoff, yoff).
|
||||
wxImage *OverlayImage(wxImage * background, wxImage * foreground,
|
||||
std::unique_ptr<wxImage> OverlayImage(wxImage * background, wxImage * foreground,
|
||||
wxImage * mask, int xoff, int yoff)
|
||||
{
|
||||
unsigned char *bg = background->GetData();
|
||||
@ -130,7 +130,7 @@ wxImage *OverlayImage(wxImage * background, wxImage * foreground,
|
||||
|
||||
|
||||
//Make a NEW image the size of the background
|
||||
wxImage * dstImage = new wxImage(bgWidth, bgHeight);
|
||||
auto dstImage = std::make_unique<wxImage>(bgWidth, bgHeight);
|
||||
unsigned char *dst = dstImage->GetData();
|
||||
memcpy(dst, bg, bgWidth * bgHeight * 3);
|
||||
|
||||
@ -156,7 +156,7 @@ wxImage *OverlayImage(wxImage * background, wxImage * foreground,
|
||||
(fg[3 * (y * fgWidth + x) + c] * value)) / 255;
|
||||
}
|
||||
}
|
||||
return dstImage;
|
||||
return std::move(dstImage);
|
||||
}
|
||||
|
||||
/// Takes a background image, foreground image, and mask
|
||||
@ -164,7 +164,7 @@ wxImage *OverlayImage(wxImage * background, wxImage * foreground,
|
||||
/// returns an NEW image where the foreground has been
|
||||
/// overlaid onto the background using alpha-blending,
|
||||
/// at location (xoff, yoff).
|
||||
wxImage *OverlayImage(teBmps eBack, teBmps eForeground,
|
||||
std::unique_ptr<wxImage> OverlayImage(teBmps eBack, teBmps eForeground,
|
||||
int xoff, int yoff)
|
||||
{
|
||||
wxImage imgBack(theTheme.Image( eBack ));
|
||||
@ -174,7 +174,7 @@ wxImage *OverlayImage(teBmps eBack, teBmps eForeground,
|
||||
// TMP: dmazzoni - just so the code runs even though not all of
|
||||
// our images have transparency...
|
||||
if (!imgFore.HasAlpha())
|
||||
return new wxImage(imgBack);
|
||||
return std::make_unique<wxImage>(imgBack);
|
||||
|
||||
|
||||
wxASSERT( imgFore.HasAlpha() );
|
||||
@ -205,7 +205,7 @@ wxImage *OverlayImage(teBmps eBack, teBmps eForeground,
|
||||
hCutoff = (bgHeight - yoff > hCutoff) ? hCutoff : bgHeight - yoff;
|
||||
|
||||
//Make a NEW image the size of the background
|
||||
wxImage * dstImage = new wxImage(bgWidth, bgHeight);
|
||||
auto dstImage = std::make_unique<wxImage>(bgWidth, bgHeight);
|
||||
unsigned char *dst = dstImage->GetData();
|
||||
memcpy(dst, bg, bgWidth * bgHeight * 3);
|
||||
|
||||
@ -234,9 +234,9 @@ wxImage *OverlayImage(teBmps eBack, teBmps eForeground,
|
||||
}
|
||||
|
||||
// Creates an image with a solid background color
|
||||
wxImage *CreateBackground(int width, int height, wxColour colour)
|
||||
std::unique_ptr<wxImage> CreateBackground(int width, int height, wxColour colour)
|
||||
{
|
||||
wxImage *i = new wxImage(width, height);
|
||||
auto i = std::make_unique<wxImage>(width, height);
|
||||
unsigned char *ip;
|
||||
int srcVal[3];
|
||||
int x;
|
||||
@ -252,14 +252,14 @@ wxImage *CreateBackground(int width, int height, wxColour colour)
|
||||
*ip++ = srcVal[2];
|
||||
}
|
||||
|
||||
return i;
|
||||
return std::move(i);
|
||||
}
|
||||
|
||||
// Creates an image with the Mac OS X Aqua stripes, to be used
|
||||
// as a background
|
||||
wxImage *CreateAquaBackground(int width, int height, int offset)
|
||||
std::unique_ptr<wxImage> CreateAquaBackground(int width, int height, int offset)
|
||||
{
|
||||
wxImage *image = new wxImage(width, height);
|
||||
auto image = std::make_unique<wxImage>(width, height);
|
||||
unsigned char *ip = image->GetData();
|
||||
unsigned char val[4] = {231, 239, 255, 239};
|
||||
unsigned char v;
|
||||
@ -271,13 +271,14 @@ wxImage *CreateAquaBackground(int width, int height, int offset)
|
||||
*ip++ = v;
|
||||
}
|
||||
|
||||
return image;
|
||||
return std::move(image);
|
||||
}
|
||||
|
||||
std::unique_ptr<wxImage> CreateSysBackground
|
||||
#ifdef USE_AQUA_THEME
|
||||
wxImage *CreateSysBackground(int width, int height, int offset, wxColour colour)
|
||||
(int width, int height, int offset, wxColour colour)
|
||||
#else
|
||||
wxImage *CreateSysBackground(int width, int height, int WXUNUSED(offset), wxColour colour)
|
||||
(int width, int height, int WXUNUSED(offset), wxColour colour)
|
||||
#endif
|
||||
{
|
||||
#ifdef USE_AQUA_THEME
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#include "MemoryX.h"
|
||||
#include <wx/defs.h>
|
||||
#include <wx/colour.h>
|
||||
#include "Theme.h"
|
||||
@ -18,7 +19,7 @@ class wxImage;
|
||||
// the entire image by the vector difference between that
|
||||
// pixel and the dstColour. For better control, use
|
||||
// ChangeImageColour(wxImage, wxColour*, wxColour*) below
|
||||
wxImage *ChangeImageColour(wxImage * srcImage, wxColour & dstColour);
|
||||
std::unique_ptr<wxImage> ChangeImageColour(wxImage * srcImage, wxColour & dstColour);
|
||||
|
||||
// This function takes a source image, which it assumes to
|
||||
// be grayscale, and smoothly changes the overall color
|
||||
@ -27,7 +28,7 @@ wxImage *ChangeImageColour(wxImage * srcImage, wxColour & dstColour);
|
||||
// Audacity uses this routines to make the buttons
|
||||
// (skip-start, play, stop, record, skip-end) adapt to
|
||||
// the color scheme of the user.
|
||||
wxImage *ChangeImageColour(wxImage * srcImage,
|
||||
std::unique_ptr<wxImage> ChangeImageColour(wxImage * srcImage,
|
||||
wxColour & srcColour,
|
||||
wxColour & dstColour);
|
||||
|
||||
@ -36,25 +37,25 @@ wxImage *ChangeImageColour(wxImage * srcImage,
|
||||
// returns an NEW image where the foreground has been
|
||||
// overlaid onto the background using alpha-blending,
|
||||
// at location (xoff, yoff).
|
||||
wxImage *OverlayImage(wxImage * background, wxImage * foreground,
|
||||
std::unique_ptr<wxImage> OverlayImage(wxImage * background, wxImage * foreground,
|
||||
wxImage * mask, int xoff, int yoff);
|
||||
|
||||
|
||||
// Same idea, but this time the mask is an alpha channel in
|
||||
// the foreground bitmap, and it's all retrieved from Themes.
|
||||
wxImage *OverlayImage(teBmps eBack, teBmps eForeground,
|
||||
std::unique_ptr<wxImage> OverlayImage(teBmps eBack, teBmps eForeground,
|
||||
int xoff, int yoff);
|
||||
|
||||
|
||||
// Creates an image with a solid background color
|
||||
wxImage *CreateBackground(int width, int height, wxColour colour);
|
||||
std::unique_ptr<wxImage> CreateBackground(int width, int height, wxColour colour);
|
||||
|
||||
// Creates an image with the Mac OS X Aqua stripes, to be used
|
||||
// as a background
|
||||
wxImage *CreateAquaBackground(int width, int height, int offset);
|
||||
std::unique_ptr<wxImage> CreateAquaBackground(int width, int height, int offset);
|
||||
|
||||
// Uses color on all OS except Mac, uses Aqua
|
||||
wxImage *CreateSysBackground(int width, int height, int offset,
|
||||
std::unique_ptr<wxImage> CreateSysBackground(int width, int height, int offset,
|
||||
wxColour colour);
|
||||
|
||||
// Pastes one image into another at specified location.
|
||||
|
@ -635,7 +635,6 @@ void ToolBar::MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn )
|
||||
|
||||
void ToolBar::MakeRecoloredImage( teBmps eBmpOut, teBmps eBmpIn )
|
||||
{
|
||||
wxImage * pPattern;
|
||||
wxImage * pSrc = &theTheme.Image( eBmpIn );
|
||||
#if defined( __WXGTK__ )
|
||||
wxColour newColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
|
||||
@ -644,10 +643,9 @@ void ToolBar::MakeRecoloredImage( teBmps eBmpOut, teBmps eBmpIn )
|
||||
#endif
|
||||
wxColour baseColour = wxColour( 204, 204, 204 );
|
||||
|
||||
pPattern = ChangeImageColour( pSrc, baseColour, newColour );
|
||||
auto pPattern = ChangeImageColour( pSrc, baseColour, newColour );
|
||||
|
||||
theTheme.ReplaceImage( eBmpOut, pPattern);
|
||||
delete pPattern;
|
||||
theTheme.ReplaceImage( eBmpOut, pPattern.get());
|
||||
}
|
||||
|
||||
void ToolBar:: MakeButtonBackgroundsLarge()
|
||||
|
Loading…
x
Reference in New Issue
Block a user