mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
refactor image/crop encoding
This commit is contained in:
+8
-65
@@ -13,7 +13,7 @@
|
||||
#include <util/error.hpp>
|
||||
#include <util/file_utils.hpp>
|
||||
#include <util/vcs.hpp>
|
||||
#include <data/format/file_to_text.h>
|
||||
#include <data/format/image_encoding.hpp>
|
||||
|
||||
class Package;
|
||||
class wxFileInputStream;
|
||||
@@ -54,71 +54,14 @@ public:
|
||||
|
||||
inline String const& toStringForKey() const { return fn; }
|
||||
|
||||
/// Retreive a rect from a filename
|
||||
inline static void getExternalRect(const String& filename, wxRect& rect_out, int& degrees_out) {
|
||||
size_t first = filename.find(_("<mse-crop-data>"));
|
||||
if (first == String::npos) return;
|
||||
size_t last = filename.find(_("</mse-crop-data>"), first + 15);
|
||||
if (last == String::npos) return;
|
||||
String string = filename.substr(first + 15, last - (first + 15));
|
||||
if (string.empty()) return;
|
||||
|
||||
size_t divider = string.find(_("-"));
|
||||
if (divider == String::npos) return;
|
||||
if (divider == 0) return;
|
||||
int x;
|
||||
if(!string.substr(0, divider).ToInt(&x)) return;
|
||||
string = string.substr(divider + 1);
|
||||
|
||||
divider = string.find(_("-"));
|
||||
if (divider == String::npos) return;
|
||||
if (divider == 0) return;
|
||||
int y;
|
||||
if(!string.substr(0, divider).ToInt(&y)) return;
|
||||
string = string.substr(divider + 1);
|
||||
|
||||
divider = string.find(_("-"));
|
||||
if (divider == String::npos) return;
|
||||
if (divider == 0) return;
|
||||
int width;
|
||||
if(!string.substr(0, divider).ToInt(&width)) return;
|
||||
string = string.substr(divider + 1);
|
||||
|
||||
divider = string.find(_("-"));
|
||||
if (divider == String::npos) return;
|
||||
if (divider == 0) return;
|
||||
int height;
|
||||
if(!string.substr(0, divider).ToInt(&height)) return;
|
||||
string = string.substr(divider + 1);
|
||||
|
||||
if(!string.ToInt(°rees_out)) return;
|
||||
|
||||
rect_out = wxRect(x, y, width, height);
|
||||
}
|
||||
/// Retreive a rect from a filename
|
||||
inline void getExternalRect(wxRect& rect_out, int& degrees_out) {
|
||||
getExternalRect(fn, rect_out, degrees_out);
|
||||
}
|
||||
|
||||
/// Retreive an image from a filename
|
||||
inline static Image getExternalImage(const String& filename) {
|
||||
Image img;
|
||||
size_t first = filename.find(_("<mse-image-data>"));
|
||||
if (first == String::npos) return img;
|
||||
size_t last = filename.find(_("</mse-image-data>"), first + 16);
|
||||
if (last == String::npos) return img;
|
||||
std::string s = filename.substr(first + 16, last - (first + 16)).ToStdString();
|
||||
if (s.empty()) return img;
|
||||
|
||||
const std::string& temppath = (wxFileName::CreateTempFileName(_("mse")) + _(".png")).ToStdString();
|
||||
UTF8ToFile(temppath, s);
|
||||
img.LoadFile(temppath, wxBITMAP_TYPE_PNG);
|
||||
wxRemoveFile(temppath);
|
||||
wxRemoveFile(temppath.substr(0, temppath.size() - 4));
|
||||
return img;
|
||||
}
|
||||
inline Image getExternalImage() {
|
||||
return getExternalImage(fn);
|
||||
}
|
||||
decodeRectFromString(fn, rect_out, degrees_out);
|
||||
}
|
||||
/// Retreive an image from a filename
|
||||
inline Image getExternalImage() {
|
||||
return decodeImageFromString(fn);
|
||||
}
|
||||
|
||||
private:
|
||||
LocalFileName(const wxString& fn) : fn(fn) {}
|
||||
|
||||
Reference in New Issue
Block a user