37#include "Configuration.h"
40#include <wx/zipstrm.h>
41#include <wx/wfstream.h>
42#define NANOSVG_ALL_COLOR_KEYWORDS
43#include "nanosvg_private.h"
44#include "nanosvgrast_private.h"
95 const wxString &wxmxFile,
bool remove =
true);
104 const int &width,
const int &height);
108 m_loadImageTask->Wait();
109 m_configuration = config; }
113 m_loadImageTask->Wait();
118 m_loadImageTask->Wait();
123 void GenerateInvalidBitmap();
125 wxString m_invalidBitmapMessage;
126 bool m_isInvalid =
false;
155 m_loadImageTask->Wait();
156 return m_loadFailureKind;
165 void GnuplotSource(wxString gnuplotFilename, wxString dataFilename,
166 const wxString &wxmxFile = wxEmptyString);
172 const wxString &wxmxFile = wxEmptyString);
197 const wxMemoryBuffer GetCompressedGnuplotSource();
200 const wxMemoryBuffer GetCompressedGnuplotData();
209 m_loadImageTask->Wait();
213 if (m_scaledBitmap.IsOk() &&
214 ((m_scaledBitmap.GetWidth() > 1) || (m_scaledBitmap.GetHeight() > 1)))
215 m_scaledBitmap.Create(1, 1);
223 m_loadImageTask->Wait();
228 m_loadImageTask->Wait();
233 m_loadImageTask->Wait();
239 m_loadImageTask->Wait();
240 m_maxHeight = height;
280 m_loadImageTask->Wait();
281 return m_svgRast !=
nullptr;}
292 WxmxStream(wxInputStream &wxmxFile,
const wxString &fileInWxmx);
295 bool HasGnuplotSource()
const {
return m_gnuplotSource_Compressed.GetDataLen() > 20;}
297 bool m_fromWxFS =
false;
299 wxMemoryBuffer m_gnuplotSource_Compressed;
301 wxMemoryBuffer m_gnuplotData_Compressed;
303 std::size_t m_originalWidth = 640;
305 std::size_t m_originalHeight = 480;
307 wxBitmap m_scaledBitmap;
309 wxString m_extension;
311 wxString m_gnuplotSource;
313 wxString m_gnuplotData;
315 mutable std::shared_ptr<BackgroundTask> m_loadImageTask;
316 void LoadImage_Backgroundtask(
stop_token stopToken,
317 wxString image, wxString wxmxFile,
321 std::shared_ptr<BackgroundTask> m_loadGnuplotSourceTask;
322 void LoadGnuplotSource_Backgroundtask(
324 wxString gnuplotFile, wxString dataFile, wxString wxmxFile);
325 void LoadGnuplotSource(wxInputStream *source);
326 void LoadGnuplotData(wxInputStream *data);
327 void LoadGnuplotSource_Backgroundtask_internal(
328 wxInputStream *source,
329 wxInputStream *data);
332 void LoadCompressedGnuplotSource_Backgroundtask(
stop_token stopToken,
338 void LoadImage(wxString image,
const wxString &wxmxFile,
bool remove =
true);
340 wxMemoryBuffer ReadCompressedImage(
stop_token stopToken, wxInputStream *data);
342 void RecordDataUnavailable(
const wxString &message);
350 void RecordDecodeFailure(
const wxString &message,
bool missingCodec);
355 wxCoord m_maxWidth = -1;
357 wxCoord m_maxHeight = -1;
359 wxString m_imageName;
362 struct free_deleter {
void operator()(
void *p)
const { std::free(p); } };
363 wxm_NSVGimage* m_svgImage = {};
364 std::unique_ptr<struct wxm_NSVGrasterizer, free_deleter> m_svgRast{
nullptr};
A priority work-queue thread pool for offloading work to background threads.
Small compatibility shims for older toolchains and older wxWidgets.
The configuration storage for the current worksheet.
Definition: Configuration.h:98
Manages an auto-scaling image.
Definition: Image.h:71
void SetMaxWidth(double width)
Set the maximum width this image shall be displayed with.
Definition: Image.h:231
double GetHeightList() const
The maximum height this image shall be displayed with.
Definition: Image.h:226
void LoadImage(const wxBitmap &bitmap)
"Loads" an image from a bitmap
Definition: Image.cpp:827
void Recalculate(double scale=1.0)
Can be called to specify a specific scale.
Definition: Image.cpp:1050
int GetPPI() const
Return the image's resolution.
Definition: Image.h:111
wxString GnuplotSource()
Returns the gnuplot source file name of this image.
Definition: Image.cpp:566
const wxMemoryBuffer GetGnuplotSource()
Returns the gnuplot source of this image.
Definition: Image.cpp:456
std::size_t GetOriginalWidth() const
Returns the original width.
Definition: Image.cpp:223
std::size_t GetOriginalHeight() const
Returns the original height.
Definition: Image.cpp:230
static const wxString GetBadImageToolTip()
The tooltip to use wherever an image that's not Ok is shown.
Definition: Image.cpp:1143
long m_height
The height of the scaled image.
Definition: Image.h:261
const wxMemoryBuffer GetGnuplotData()
Returns the gnuplot data of this image.
Definition: Image.cpp:501
long m_width
The width of the scaled image.
Definition: Image.h:259
wxString GetExtension() const
Returns the file name extension of the current image.
Definition: Image.cpp:846
void InvalidBitmap(const wxString &message=wxEmptyString)
Creates a bitmap showing an error message.
Definition: Image.cpp:748
static wxBitmap RGBA2wxBitmap(const unsigned char imgdata[], const int &width, const int &height)
Converts rgba data to a wxBitmap.
Definition: Image.cpp:1153
LoadFailureKind GetLoadFailureKind() const
Blocks until this image's background load task (if any) has finished, then reports why it ended up in...
Definition: Image.h:153
const wxMemoryBuffer GetCompressedImage() const
Returns the original image in its compressed form.
Definition: Image.cpp:217
bool CanExportSVG() const
Can this image be exported in SVG format?
Definition: Image.h:278
LoadFailureKind
Why the most recent load attempt left this image invalid, if it did.
Definition: Image.h:129
@ MissingCodec
Data was read fine, but this wxWidgets build has no decoder registered for the format at all (e....
@ DecodeFailed
Data was read fine and a decoder exists for the format (or it's an SVG, parsed by our own vendored co...
@ DataUnavailable
Raw data could never be obtained at all (file not found, empty wxmx entry, ...). Always a real failur...
static bool IsSafePath(const wxString &path)
Returns true if the path is in a safe (temporary) directory for deletion.
Definition: Image.cpp:1124
void SetPPI(int ppi)
Set the image's resolution.
Definition: Image.h:116
wxMemoryBuffer m_compressedImage
The image in its original compressed form.
Definition: Image.h:275
void SetMaxHeight(double height)
Set the maximum height this image shall be displayed with.
Definition: Image.h:237
wxSize ToImageFile(wxString filename)
Saves the image in its original form, or as .png if it originates in a bitmap.
Definition: Image.cpp:607
double GetMaxWidth() const
The maximum width this image shall be displayed with.
Definition: Image.h:221
wxBitmap GetBitmap(double scale=1.0)
Returns the bitmap being displayed with custom scale.
Definition: Image.cpp:677
wxString GnuplotData()
Returns the gnuplot data file name of this image.
Definition: Image.cpp:531
wxBitmap GetUnscaledBitmap()
Returns the image in its unscaled form.
Definition: Image.cpp:193
void CompressedGnuplotSource(wxString gnuplotFilename, wxString dataFilename, const wxString &wxmxFile=wxEmptyString)
Loads the compressed gnuplot source and data file for this image.
Definition: Image.cpp:295
void ClearCache()
Temporarily forget the scaled image in order to save memory.
Definition: Image.h:206