Suppress libpng errors.

This commit is contained in:
Lymia Aluysia
2017-01-18 09:14:17 -06:00
parent 1d912a6853
commit 76cf6fc0d6
9 changed files with 52 additions and 18 deletions
+2 -1
View File
@@ -14,6 +14,7 @@
#include <data/card.hpp>
#include <gfx/gfx.hpp>
#include <wx/imaglist.h>
#include <gui/util.hpp>
DECLARE_TYPEOF_COLLECTION(FieldP);
@@ -62,7 +63,7 @@ class CardThumbnailRequest : public ThumbnailRequest {
try {
ImageCardList* parent = (ImageCardList*)owner;
Image image;
if (image.LoadFile(*parent->set->openIn(filename))) {
if (image_load_file(image, *parent->set->openIn(filename))) {
// two step anti aliased resampling
image.Rescale(36, 28); // step 1: no anti aliassing
return resample(image, 18, 14); // step 2: with anti aliassing
+2 -1
View File
@@ -11,6 +11,7 @@
#include <util/io/package_manager.hpp>
#include <util/alignment.hpp>
#include <script/profiler.hpp>
#include <gui/util.hpp>
DECLARE_TYPEOF_COLLECTION(PackagedP);
@@ -75,7 +76,7 @@ void PackageList::showData(const String& pattern) {
InputStreamP stream = p->openIconFile();
Image img;
Bitmap bmp;
if (stream && img.LoadFile(*stream)) {
if (stream && image_load_file(img, *stream)) {
bmp = Bitmap(img);
}
// add to list
+25 -8
View File
@@ -126,6 +126,19 @@ void draw_checker(RotatedDC& dc, const RealRect& rect) {
}
}
// ----------------------------------------------------------------------------- : Image related
bool image_load_file(Image& image, wxInputStream &stream) {
wxLogNull noLog;
return image.LoadFile(stream);
}
bool image_load_file(Image& image, const wxString &name) {
wxLogNull noLog;
return image.LoadFile(name);
}
// ----------------------------------------------------------------------------- : Resource related
Image load_resource_image(const String& name) {
@@ -144,22 +157,24 @@ Image load_resource_image(const String& name) {
int len = ::SizeofResource(wxGetInstance(), hResource);
wxMemoryInputStream stream(data, len);
wxLogNull noLog;
return wxImage(stream);
#elif defined(__GNUC__)
static String path = wxStandardPaths::Get().GetDataDir() + _("/resource/");
String file = path + name;
wxImage resource;
if (wxFileExists(file + _(".png"))) resource.LoadFile(file + _(".png"));
else if (wxFileExists(file + _(".bmp"))) resource.LoadFile(file + _(".bmp"));
else if (wxFileExists(file + _(".ico"))) resource.LoadFile(file + _(".ico"));
else if (wxFileExists(file + _(".cur"))) resource.LoadFile(file + _(".cur"));
if (wxFileExists(file + _(".png"))) image_load_file(resource, file + _(".png"));
else if (wxFileExists(file + _(".bmp"))) image_load_file(resource, file + _(".bmp"));
else if (wxFileExists(file + _(".ico"))) image_load_file(resource, file + _(".ico"));
else if (wxFileExists(file + _(".cur"))) image_load_file(resource, file + _(".cur"));
if (resource.Ok()) return resource;
static String local_path = wxStandardPaths::Get().GetUserDataDir() + _("/resource/");
file = local_path + name;
if (wxFileExists(file + _(".png"))) resource.LoadFile(file + _(".png"));
else if (wxFileExists(file + _(".bmp"))) resource.LoadFile(file + _(".bmp"));
else if (wxFileExists(file + _(".ico"))) resource.LoadFile(file + _(".ico"));
else if (wxFileExists(file + _(".cur"))) resource.LoadFile(file + _(".cur"));
if (wxFileExists(file + _(".png"))) image_load_file(resource, file + _(".png"));
else if (wxFileExists(file + _(".bmp"))) image_load_file(resource, file + _(".bmp"));
else if (wxFileExists(file + _(".ico"))) image_load_file(resource, file + _(".ico"));
else if (wxFileExists(file + _(".cur"))) image_load_file(resource, file + _(".cur"));
if (!resource.Ok()) handle_error(InternalError(String(_("Cannot find resource file at ")) + path + name + _(" or ") + file));
return resource;
#else
@@ -169,6 +184,7 @@ Image load_resource_image(const String& name) {
wxCursor load_resource_cursor(const String& name) {
#if defined(__WXMSW__) && !defined(__GNUC__)
wxLogNull noLog;
return wxCursor(_("cursor/") + name, wxBITMAP_TYPE_CUR_RESOURCE);
#else
return wxCursor(load_resource_image(_("cursor/") + name));
@@ -176,6 +192,7 @@ wxCursor load_resource_cursor(const String& name) {
}
wxIcon load_resource_icon(const String& name) {
wxLogNull noLog;
#if defined(__WXMSW__) && !defined(__GNUC__)
return wxIcon(_("icon/") + name);
#else
+8
View File
@@ -40,6 +40,14 @@ void clearDC_black(DC& dc);
/// Draw a checkerboard pattern
void draw_checker(RotatedDC& dc, const RealRect&);
// ----------------------------------------------------------------------------- : Image related
/// Proxy around Image.LoadFile that suppresses errors.
bool image_load_file(Image& image, wxInputStream &stream);
/// Proxy around Image.LoadFile that suppresses errors.
bool image_load_file(Image& image, const wxString &name);
// ----------------------------------------------------------------------------- : Resource related
/// Load an image from a resource
+8 -2
View File
@@ -12,6 +12,7 @@
#include <data/format/clipboard.hpp>
#include <data/action/value.hpp>
#include <wx/clipbrd.h>
#include <gui/util.hpp>
// ----------------------------------------------------------------------------- : ImageValueEditor
@@ -23,7 +24,12 @@ bool ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
wxOPEN, wxGetTopLevelParent(&editor()));
if (!filename.empty()) {
settings.default_image_dir = wxPathOnly(filename);
sliceImage(wxImage(filename));
wxImage image;
{
wxLogNull noLog;
image = wxImage(filename);
}
sliceImage(image);
}
return true;
}
@@ -61,7 +67,7 @@ bool ImageValueEditor::doCopy() {
// load image
InputStreamP image_file = getLocalPackage().openIn(value().filename);
Image image;
if (!image.LoadFile(*image_file)) return false;
if (!image_load_file(image, *image_file)) return false;
// set data
if (!wxTheClipboard->Open()) return false;
bool ok = wxTheClipboard->SetData(new wxBitmapDataObject(image));