1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-20 22:30:05 +02:00

Image manipulation functions return smart pointers

This commit is contained in:
Paul Licameli 2016-03-31 13:41:42 -04:00
parent 99cb50d6db
commit c78e91f6c1
3 changed files with 29 additions and 29 deletions

View File

@ -30,7 +30,7 @@ channel. This collection of functions fills that gap.
/// the entire image by the vector difference between that /// the entire image by the vector difference between that
/// pixel and the dstColour. For better control, use /// pixel and the dstColour. For better control, use
/// ChangeImageColour(wxImage, wxColour*, wxColour*) below /// 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(); unsigned char *src = srcImage->GetData();
wxColour c; wxColour c;
@ -40,7 +40,7 @@ wxImage *ChangeImageColour(wxImage * srcImage, wxColour & dstColour)
///This will explicitly shift the image color from ///This will explicitly shift the image color from
///srcColour to dstColour. ///srcColour to dstColour.
wxImage *ChangeImageColour(wxImage * srcImage, std::unique_ptr<wxImage> ChangeImageColour(wxImage * srcImage,
wxColour & srcColour, wxColour & srcColour,
wxColour & dstColour) wxColour & dstColour)
{ {
@ -56,7 +56,7 @@ wxImage *ChangeImageColour(wxImage * srcImage,
int width = srcImage->GetWidth(); int width = srcImage->GetWidth();
int height = srcImage->GetHeight(); int height = srcImage->GetHeight();
wxImage * dstImage = new wxImage(width, height); auto dstImage = std::make_unique<wxImage>(width, height);
unsigned char *dst = dstImage->GetData(); unsigned char *dst = dstImage->GetData();
@ -90,7 +90,7 @@ wxImage *ChangeImageColour(wxImage * srcImage,
c = (c + 1) % 3; c = (c + 1) % 3;
} }
return dstImage; return std::move(dstImage);
} }
/// Takes a background image, foreground image, and mask /// 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 /// returns an NEW image where the foreground has been
/// overlaid onto the background using alpha-blending, /// overlaid onto the background using alpha-blending,
/// at location (xoff, yoff). /// 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) wxImage * mask, int xoff, int yoff)
{ {
unsigned char *bg = background->GetData(); unsigned char *bg = background->GetData();
@ -130,7 +130,7 @@ wxImage *OverlayImage(wxImage * background, wxImage * foreground,
//Make a NEW image the size of the background //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(); unsigned char *dst = dstImage->GetData();
memcpy(dst, bg, bgWidth * bgHeight * 3); memcpy(dst, bg, bgWidth * bgHeight * 3);
@ -156,7 +156,7 @@ wxImage *OverlayImage(wxImage * background, wxImage * foreground,
(fg[3 * (y * fgWidth + x) + c] * value)) / 255; (fg[3 * (y * fgWidth + x) + c] * value)) / 255;
} }
} }
return dstImage; return std::move(dstImage);
} }
/// Takes a background image, foreground image, and mask /// 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 /// returns an NEW image where the foreground has been
/// overlaid onto the background using alpha-blending, /// overlaid onto the background using alpha-blending,
/// at location (xoff, yoff). /// at location (xoff, yoff).
wxImage *OverlayImage(teBmps eBack, teBmps eForeground, std::unique_ptr<wxImage> OverlayImage(teBmps eBack, teBmps eForeground,
int xoff, int yoff) int xoff, int yoff)
{ {
wxImage imgBack(theTheme.Image( eBack )); 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 // TMP: dmazzoni - just so the code runs even though not all of
// our images have transparency... // our images have transparency...
if (!imgFore.HasAlpha()) if (!imgFore.HasAlpha())
return new wxImage(imgBack); return std::make_unique<wxImage>(imgBack);
wxASSERT( imgFore.HasAlpha() ); wxASSERT( imgFore.HasAlpha() );
@ -205,7 +205,7 @@ wxImage *OverlayImage(teBmps eBack, teBmps eForeground,
hCutoff = (bgHeight - yoff > hCutoff) ? hCutoff : bgHeight - yoff; hCutoff = (bgHeight - yoff > hCutoff) ? hCutoff : bgHeight - yoff;
//Make a NEW image the size of the background //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(); unsigned char *dst = dstImage->GetData();
memcpy(dst, bg, bgWidth * bgHeight * 3); memcpy(dst, bg, bgWidth * bgHeight * 3);
@ -234,9 +234,9 @@ wxImage *OverlayImage(teBmps eBack, teBmps eForeground,
} }
// Creates an image with a solid background color // 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; unsigned char *ip;
int srcVal[3]; int srcVal[3];
int x; int x;
@ -252,14 +252,14 @@ wxImage *CreateBackground(int width, int height, wxColour colour)
*ip++ = srcVal[2]; *ip++ = srcVal[2];
} }
return i; return std::move(i);
} }
// Creates an image with the Mac OS X Aqua stripes, to be used // Creates an image with the Mac OS X Aqua stripes, to be used
// as a background // 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 *ip = image->GetData();
unsigned char val[4] = {231, 239, 255, 239}; unsigned char val[4] = {231, 239, 255, 239};
unsigned char v; unsigned char v;
@ -271,13 +271,14 @@ wxImage *CreateAquaBackground(int width, int height, int offset)
*ip++ = v; *ip++ = v;
} }
return image; return std::move(image);
} }
std::unique_ptr<wxImage> CreateSysBackground
#ifdef USE_AQUA_THEME #ifdef USE_AQUA_THEME
wxImage *CreateSysBackground(int width, int height, int offset, wxColour colour) (int width, int height, int offset, wxColour colour)
#else #else
wxImage *CreateSysBackground(int width, int height, int WXUNUSED(offset), wxColour colour) (int width, int height, int WXUNUSED(offset), wxColour colour)
#endif #endif
{ {
#ifdef USE_AQUA_THEME #ifdef USE_AQUA_THEME

View File

@ -8,6 +8,7 @@
**********************************************************************/ **********************************************************************/
#include "MemoryX.h"
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/colour.h> #include <wx/colour.h>
#include "Theme.h" #include "Theme.h"
@ -18,7 +19,7 @@ class wxImage;
// the entire image by the vector difference between that // the entire image by the vector difference between that
// pixel and the dstColour. For better control, use // pixel and the dstColour. For better control, use
// ChangeImageColour(wxImage, wxColour*, wxColour*) below // 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 // This function takes a source image, which it assumes to
// be grayscale, and smoothly changes the overall color // 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 // Audacity uses this routines to make the buttons
// (skip-start, play, stop, record, skip-end) adapt to // (skip-start, play, stop, record, skip-end) adapt to
// the color scheme of the user. // the color scheme of the user.
wxImage *ChangeImageColour(wxImage * srcImage, std::unique_ptr<wxImage> ChangeImageColour(wxImage * srcImage,
wxColour & srcColour, wxColour & srcColour,
wxColour & dstColour); wxColour & dstColour);
@ -36,25 +37,25 @@ wxImage *ChangeImageColour(wxImage * srcImage,
// returns an NEW image where the foreground has been // returns an NEW image where the foreground has been
// overlaid onto the background using alpha-blending, // overlaid onto the background using alpha-blending,
// at location (xoff, yoff). // 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); wxImage * mask, int xoff, int yoff);
// Same idea, but this time the mask is an alpha channel in // Same idea, but this time the mask is an alpha channel in
// the foreground bitmap, and it's all retrieved from Themes. // 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); int xoff, int yoff);
// Creates an image with a solid background color // 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 // Creates an image with the Mac OS X Aqua stripes, to be used
// as a background // 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 // 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); wxColour colour);
// Pastes one image into another at specified location. // Pastes one image into another at specified location.

View File

@ -635,7 +635,6 @@ void ToolBar::MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn )
void ToolBar::MakeRecoloredImage( teBmps eBmpOut, teBmps eBmpIn ) void ToolBar::MakeRecoloredImage( teBmps eBmpOut, teBmps eBmpIn )
{ {
wxImage * pPattern;
wxImage * pSrc = &theTheme.Image( eBmpIn ); wxImage * pSrc = &theTheme.Image( eBmpIn );
#if defined( __WXGTK__ ) #if defined( __WXGTK__ )
wxColour newColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ); wxColour newColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
@ -644,10 +643,9 @@ void ToolBar::MakeRecoloredImage( teBmps eBmpOut, teBmps eBmpIn )
#endif #endif
wxColour baseColour = wxColour( 204, 204, 204 ); wxColour baseColour = wxColour( 204, 204, 204 );
pPattern = ChangeImageColour( pSrc, baseColour, newColour ); auto pPattern = ChangeImageColour( pSrc, baseColour, newColour );
theTheme.ReplaceImage( eBmpOut, pPattern); theTheme.ReplaceImage( eBmpOut, pPattern.get());
delete pPattern;
} }
void ToolBar:: MakeButtonBackgroundsLarge() void ToolBar:: MakeButtonBackgroundsLarge()