Commit a2b3027f authored by twanvl's avatar twanvl

Added image to symbol conversion

parent 57d5ead3
...@@ -99,6 +99,7 @@ magicseteditor_SOURCES += ./src/data/format/mws.cpp ...@@ -99,6 +99,7 @@ magicseteditor_SOURCES += ./src/data/format/mws.cpp
magicseteditor_SOURCES += ./src/data/format/mse1.cpp magicseteditor_SOURCES += ./src/data/format/mse1.cpp
magicseteditor_SOURCES += ./src/data/format/mse2.cpp magicseteditor_SOURCES += ./src/data/format/mse2.cpp
magicseteditor_SOURCES += ./src/data/format/clipboard.cpp magicseteditor_SOURCES += ./src/data/format/clipboard.cpp
magicseteditor_SOURCES += ./src/data/format/image_to_symbol.cpp
magicseteditor_SOURCES += ./src/data/statistics.cpp magicseteditor_SOURCES += ./src/data/statistics.cpp
magicseteditor_SOURCES += ./src/data/settings.cpp magicseteditor_SOURCES += ./src/data/settings.cpp
magicseteditor_SOURCES += ./src/data/keyword.cpp magicseteditor_SOURCES += ./src/data/keyword.cpp
......
This diff is collapsed.
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_FORMAT_IMAGE_TO_SYMBOL
#define HEADER_DATA_FORMAT_IMAGE_TO_SYMBOL
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/symbol.hpp>
// ----------------------------------------------------------------------------- : Image to symbol
/// Import an image as a symbol.
/** Handles MSE1 symbols by cutting out the symbol rectangle */
SymbolP import_symbol(Image& img);
/// Does the image represent a MSE1 symbol file?
/** Does some heuristic checks */
bool is_mse1_symbol(const Image& img);
/// Convert an image to a symbol, destroys the image in the process
SymbolP image_to_symbol(Image& img);
// ----------------------------------------------------------------------------- : Simplify symbol
/// Simplify a symbol
void simplify_symbol(Symbol&);
/// Simplify a symbol parts, i.e. use bezier curves instead of lots of lines
void simplify_symbol_part(SymbolPart&);
// ----------------------------------------------------------------------------- : EOF
#endif
...@@ -114,6 +114,12 @@ enum SymbolPartCombine ...@@ -114,6 +114,12 @@ enum SymbolPartCombine
, PART_BORDER , PART_BORDER
}; };
/// A sane mod function, always returns a result in the range [0..size)
inline size_t mod(int a, size_t size) {
int m = a % (int)size;
return m >= 0 ? m : m + size;
}
/// A single part (polygon/bezier-gon) in a Symbol /// A single part (polygon/bezier-gon) in a Symbol
class SymbolPart { class SymbolPart {
public: public:
...@@ -136,7 +142,7 @@ class SymbolPart { ...@@ -136,7 +142,7 @@ class SymbolPart {
/// Get a control point, wraps around /// Get a control point, wraps around
inline ControlPointP getPoint(int id) const { inline ControlPointP getPoint(int id) const {
return points[id >= 0 ? id % points.size() : id + points.size()]; return points[mod(id, points.size())];
} }
/// Enforce lock constraints /// Enforce lock constraints
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <gui/util.hpp> #include <gui/util.hpp>
#include <data/set.hpp> #include <data/set.hpp>
#include <data/field/symbol.hpp> #include <data/field/symbol.hpp>
#include <data/format/image_to_symbol.hpp>
#include <data/action/value.hpp> #include <data/action/value.hpp>
#include <util/window_id.hpp> #include <util/window_id.hpp>
#include <util/io/reader.hpp> #include <util/io/reader.hpp>
...@@ -143,16 +144,18 @@ void SymbolWindow::onFileNew(wxCommandEvent& ev) { ...@@ -143,16 +144,18 @@ void SymbolWindow::onFileNew(wxCommandEvent& ev) {
} }
void SymbolWindow::onFileOpen(wxCommandEvent& ev) { void SymbolWindow::onFileOpen(wxCommandEvent& ev) {
String name = wxFileSelector(_("Open symbol"),_(""),_(""),_(""),_("Symbol files|*.mse-symbol;*.bmp|MSE2 symbol files (*.mse-symbol)|*.mse-symbol|MSE1 symbol files (*.bmp)|*.bmp"),wxOPEN|wxFILE_MUST_EXIST, this); String name = wxFileSelector(_("Open symbol"),_(""),_(""),_(""),_("Symbol files|*.mse-symbol;*.bmp|MSE2 symbol files (*.mse-symbol)|*.mse-symbol|Images/MSE1 symbol files|*.bmp;*.png;*.jpg;*.gif"),wxOPEN|wxFILE_MUST_EXIST, this);
if (!name.empty()) { if (!name.empty()) {
wxFileName n(name); wxFileName n(name);
String ext = n.GetExt(); String ext = n.GetExt();
SymbolP symbol; SymbolP symbol;
if (ext.Lower() == _("bmp")) { if (ext.Lower() == _("mse-symbol")) {
//% symbol = importSymbol(wxImage(name));
} else {
Reader reader(new_shared1<wxFileInputStream>(name), name); Reader reader(new_shared1<wxFileInputStream>(name), name);
reader.handle_greedy(symbol); reader.handle_greedy(symbol);
} else {
Image image(name);
if (!image.Ok()) return;
symbol = import_symbol(image);
} }
// show... // show...
parts->setSymbol(symbol); parts->setSymbol(symbol);
......
...@@ -1440,6 +1440,12 @@ ...@@ -1440,6 +1440,12 @@
ObjectFile="$(IntDir)/$(InputName)4.obj"/> ObjectFile="$(IntDir)/$(InputName)4.obj"/>
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\data\format\image_to_symbol.cpp">
</File>
<File
RelativePath=".\data\format\image_to_symbol.hpp">
</File>
<File <File
RelativePath=".\data\format\mse1.cpp"> RelativePath=".\data\format\mse1.cpp">
</File> </File>
......
...@@ -123,7 +123,7 @@ class Vector2D { ...@@ -123,7 +123,7 @@ class Vector2D {
}; };
/// Piecewise minimum /// Piecewise minimum
inline Vector2D piecewise_min(Vector2D a, Vector2D b) { inline Vector2D piecewise_min(const Vector2D& a, const Vector2D& b) {
return Vector2D( return Vector2D(
a.x < b.x ? a.x : b.x, a.x < b.x ? a.x : b.x,
a.y < b.y ? a.y : b.y a.y < b.y ? a.y : b.y
...@@ -131,13 +131,15 @@ inline Vector2D piecewise_min(Vector2D a, Vector2D b) { ...@@ -131,13 +131,15 @@ inline Vector2D piecewise_min(Vector2D a, Vector2D b) {
} }
/// Piecewise maximum /// Piecewise maximum
inline Vector2D piecewise_max(Vector2D a, Vector2D b) { inline Vector2D piecewise_max(const Vector2D& a, const Vector2D& b) {
return Vector2D( return Vector2D(
a.x < b.x ? b.x : a.x, a.x < b.x ? b.x : a.x,
a.y < b.y ? b.y : a.y a.y < b.y ? b.y : a.y
); );
} }
inline Vector2D operator * (double a, const Vector2D& b) { return b * a; }
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment