mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-21 14:02:57 +02:00
Image manipulation functions return smart pointers
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user