Use std::vector<wxImage> instead of wxImageArray
Preserve the old dynamic array name but just define it as a thin class deriving from std::vector and accept just vector in SaveAnimation().
This commit is contained in:
parent
4917d458b8
commit
338751756f
6 changed files with 26 additions and 23 deletions
|
|
@ -18,12 +18,15 @@
|
|||
#include "wx/animdecod.h"
|
||||
#include "wx/dynarray.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
class /*WXDLLIMPEXP_CORE*/ wxANIFrameInfo; // private implementation detail
|
||||
|
||||
WX_DECLARE_EXPORTED_OBJARRAY(wxImage, wxImageArray);
|
||||
// For compatibility purposes, provide wxImageArray class mimicking the legacy
|
||||
// dynamic array which used to be required by wxGIFHandler::SaveAnimation():
|
||||
// now we just take a vector of images there, but we want to keep the existing
|
||||
// code using wxImageArray working (and keep it declared here because this is
|
||||
// where it used to be, even if this doesn't make much sense).
|
||||
using wxImageArray = wxBaseArray<wxImage>;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxANIDecoder class
|
||||
|
|
@ -63,7 +66,7 @@ private:
|
|||
// frames stored as wxImage(s): ANI files are meant to be used mostly for animated
|
||||
// cursors and thus they do not use any optimization to encode differences between
|
||||
// two frames: they are just a list of images to display sequentially.
|
||||
wxImageArray m_images;
|
||||
std::vector<wxImage> m_images;
|
||||
|
||||
// the info about each image stored in m_images.
|
||||
// NB: m_info.GetCount() may differ from m_images.GetCount()!
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include "wx/image.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxGIFHandler
|
||||
|
|
@ -26,7 +28,6 @@
|
|||
|
||||
struct wxRGB;
|
||||
struct GifHashTableType;
|
||||
class WXDLLIMPEXP_FWD_CORE wxImageArray; // anidecod.h
|
||||
|
||||
class WXDLLIMPEXP_CORE wxGIFHandler : public wxImageHandler
|
||||
{
|
||||
|
|
@ -47,7 +48,7 @@ public:
|
|||
bool verbose=true) override;
|
||||
|
||||
// Save animated gif
|
||||
bool SaveAnimation(const wxImageArray& images, wxOutputStream *stream,
|
||||
bool SaveAnimation(const std::vector<wxImage>& images, wxOutputStream *stream,
|
||||
bool verbose = true, int delayMilliSecs = 1000);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public:
|
|||
Save the animated gif.
|
||||
|
||||
@param images
|
||||
The image array object which is to be affected by this operation.
|
||||
The images making up the animation.
|
||||
@param stream
|
||||
Opened output stream for writing the data.
|
||||
@param verbose
|
||||
|
|
@ -45,11 +45,11 @@ public:
|
|||
@return @true if the operation succeeded, @false otherwise.
|
||||
|
||||
*/
|
||||
bool SaveAnimation(const wxImageArray& images, wxOutputStream *stream,
|
||||
bool SaveAnimation(const std::vector<wxImage>& images, wxOutputStream *stream,
|
||||
bool verbose = true, int delayMilliSecs = 1000);
|
||||
|
||||
protected:
|
||||
// allow parent class documentation to overwrite.
|
||||
virtual int DoGetImageCount(wxInputStream& stream);
|
||||
virtual bool DoCanRead(wxInputStream& stream);
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ bool wxANIDecoder::Load( wxInputStream& stream )
|
|||
m_nFrames = 0;
|
||||
m_szAnimation = wxDefaultSize;
|
||||
|
||||
m_images.Clear();
|
||||
m_images.clear();
|
||||
m_info.clear();
|
||||
|
||||
// we have a riff file:
|
||||
|
|
@ -271,7 +271,7 @@ bool wxANIDecoder::Load( wxInputStream& stream )
|
|||
|
||||
globaldelay = header.JifRate * 1000 / 60;
|
||||
|
||||
m_images.Alloc(header.cFrames);
|
||||
m_images.reserve(header.cFrames);
|
||||
m_info.resize(m_nFrames);
|
||||
}
|
||||
else if ( FCC1 == rate32 )
|
||||
|
|
@ -310,7 +310,7 @@ bool wxANIDecoder::Load( wxInputStream& stream )
|
|||
return false;
|
||||
|
||||
image.SetType(wxBITMAP_TYPE_ANI);
|
||||
m_images.Add(image);
|
||||
m_images.push_back(image);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -331,7 +331,7 @@ bool wxANIDecoder::Load( wxInputStream& stream )
|
|||
if (m_nFrames==0)
|
||||
return false;
|
||||
|
||||
if (m_nFrames==m_images.GetCount())
|
||||
if (m_nFrames==m_images.size())
|
||||
{
|
||||
// if no SEQ chunk is available, display the frames in the order
|
||||
// they were loaded
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#include "wx/imaggif.h"
|
||||
#include "wx/gifdecod.h"
|
||||
#include "wx/stream.h"
|
||||
#include "wx/anidecod.h" // wxImageArray
|
||||
#include "wx/scopedarray.h"
|
||||
|
||||
#define GIF89_HDR "GIF89a"
|
||||
|
|
@ -275,7 +274,7 @@ bool wxGIFHandler::DoSaveFile(const wxImage& image, wxOutputStream *stream,
|
|||
return ok;
|
||||
}
|
||||
|
||||
bool wxGIFHandler::SaveAnimation(const wxImageArray& images,
|
||||
bool wxGIFHandler::SaveAnimation(const std::vector<wxImage>& images,
|
||||
wxOutputStream *stream, bool verbose, int delayMilliSecs)
|
||||
{
|
||||
#if wxUSE_PALETTE
|
||||
|
|
@ -283,9 +282,9 @@ bool wxGIFHandler::SaveAnimation(const wxImageArray& images,
|
|||
size_t i;
|
||||
|
||||
wxSize size(0,0);
|
||||
for (i = 0; (i < images.GetCount()) && ok; i++)
|
||||
for (i = 0; (i < images.size()) && ok; i++)
|
||||
{
|
||||
const wxImage& image = images.Item(i);
|
||||
const wxImage& image = images[i];
|
||||
wxSize temp(image.GetWidth(), image.GetHeight());
|
||||
ok = ok && image.HasPalette();
|
||||
if (i)
|
||||
|
|
@ -298,9 +297,9 @@ bool wxGIFHandler::SaveAnimation(const wxImageArray& images,
|
|||
}
|
||||
}
|
||||
|
||||
for (i = 0; (i < images.GetCount()) && ok; i++)
|
||||
for (i = 0; (i < images.size()) && ok; i++)
|
||||
{
|
||||
const wxImage& image = images.Item(i);
|
||||
const wxImage& image = images[i];
|
||||
|
||||
wxRGB pal[256];
|
||||
int palCount;
|
||||
|
|
|
|||
|
|
@ -1190,10 +1190,10 @@ void ImageTestCase::SaveAnimatedGIF()
|
|||
REQUIRE( image.IsOk() );
|
||||
|
||||
wxImageArray images;
|
||||
images.Add(image);
|
||||
images.push_back(image);
|
||||
for (int i = 0; i < 4-1; ++i)
|
||||
{
|
||||
images.Add( images[i].Rotate90() );
|
||||
images.push_back( images[i].Rotate90() );
|
||||
|
||||
images[i+1].SetPalette(images[0].GetPalette());
|
||||
}
|
||||
|
|
@ -1261,12 +1261,12 @@ void ImageTestCase::GIFComment()
|
|||
{
|
||||
if (i)
|
||||
{
|
||||
images.Add( images[i-1].Rotate90() );
|
||||
images.push_back( images[i-1].Rotate90() );
|
||||
images[i].SetPalette(images[0].GetPalette());
|
||||
}
|
||||
else
|
||||
{
|
||||
images.Add(image);
|
||||
images.push_back(image);
|
||||
}
|
||||
|
||||
images[i].SetOption(wxIMAGE_OPTION_GIF_COMMENT,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue