mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 21:47:00 -04:00
BlankImage and ImageValueToImage
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@425 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -19,6 +19,19 @@
|
|||||||
ScriptType GeneratedImage::type() const { return SCRIPT_IMAGE; }
|
ScriptType GeneratedImage::type() const { return SCRIPT_IMAGE; }
|
||||||
String GeneratedImage::typeName() const { return _TYPE_("image"); }
|
String GeneratedImage::typeName() const { return _TYPE_("image"); }
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : BlankImage
|
||||||
|
|
||||||
|
Image BlankImage::generate(const Options& opt) const {
|
||||||
|
Image img(opt.width, opt.height);
|
||||||
|
img.InitAlpha();
|
||||||
|
memset(img.GetAlpha(), 0, opt.width * opt.height);
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
bool BlankImage::operator == (const GeneratedImage& that) const {
|
||||||
|
const BlankImage* that2 = dynamic_cast<const BlankImage*>(&that);
|
||||||
|
return that2;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : LinearBlendImage
|
// ----------------------------------------------------------------------------- : LinearBlendImage
|
||||||
|
|
||||||
Image LinearBlendImage::generate(const Options& opt) const {
|
Image LinearBlendImage::generate(const Options& opt) const {
|
||||||
@@ -145,12 +158,12 @@ SymbolToImage::~SymbolToImage() {}
|
|||||||
|
|
||||||
Image SymbolToImage::generate(const Options& opt) const {
|
Image SymbolToImage::generate(const Options& opt) const {
|
||||||
// TODO : use opt.width and opt.height?
|
// TODO : use opt.width and opt.height?
|
||||||
if (!opt.symbol_package) throw ScriptError(_("Can only load images in a context where an image is expected"));
|
if (!opt.local_package) throw ScriptError(_("Can only load images in a context where an image is expected"));
|
||||||
SymbolP the_symbol;
|
SymbolP the_symbol;
|
||||||
if (filename.empty()) {
|
if (filename.empty()) {
|
||||||
the_symbol = default_symbol();
|
the_symbol = default_symbol();
|
||||||
} else {
|
} else {
|
||||||
the_symbol = opt.symbol_package->readFile<SymbolP>(filename);
|
the_symbol = opt.local_package->readFile<SymbolP>(filename);
|
||||||
}
|
}
|
||||||
return render_symbol(the_symbol, *variation->filter, variation->border_radius);
|
return render_symbol(the_symbol, *variation->filter, variation->border_radius);
|
||||||
}
|
}
|
||||||
@@ -160,3 +173,29 @@ bool SymbolToImage::operator == (const GeneratedImage& that) const {
|
|||||||
&& age == that2->age
|
&& age == that2->age
|
||||||
&& variation == that2->variation;
|
&& variation == that2->variation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ImageValueToImage
|
||||||
|
|
||||||
|
ImageValueToImage::ImageValueToImage(const String& filename, Age age)
|
||||||
|
: filename(filename), age(age)
|
||||||
|
{}
|
||||||
|
ImageValueToImage::~ImageValueToImage() {}
|
||||||
|
|
||||||
|
Image ImageValueToImage::generate(const Options& opt) const {
|
||||||
|
// TODO : use opt.width and opt.height?
|
||||||
|
if (!opt.local_package) throw ScriptError(_("Can only load images in a context where an image is expected"));
|
||||||
|
Image image;
|
||||||
|
if (!filename.empty()) {
|
||||||
|
InputStreamP image_file = opt.local_package->openIn(filename);
|
||||||
|
image.LoadFile(*image_file);
|
||||||
|
}
|
||||||
|
if (!image.Ok()) {
|
||||||
|
image = Image(opt.width, opt.height);
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
bool ImageValueToImage::operator == (const GeneratedImage& that) const {
|
||||||
|
const ImageValueToImage* that2 = dynamic_cast<const ImageValueToImage*>(&that);
|
||||||
|
return that2 && filename == that2->filename
|
||||||
|
&& age == that2->age;
|
||||||
|
}
|
||||||
|
|||||||
+29
-21
@@ -27,15 +27,15 @@ class GeneratedImage : public ScriptValue {
|
|||||||
public:
|
public:
|
||||||
/// Options for generating the image
|
/// Options for generating the image
|
||||||
struct Options {
|
struct Options {
|
||||||
Options(int width = 0, int height = 0, Package* package = nullptr, Package* symbol_package = nullptr, PreserveAspect preserve_aspect = ASPECT_STRETCH, bool saturate = false)
|
Options(int width = 0, int height = 0, Package* package = nullptr, Package* local_package = nullptr, PreserveAspect preserve_aspect = ASPECT_STRETCH, bool saturate = false)
|
||||||
: width(width), height(height), preserve_aspect(preserve_aspect), saturate(saturate), package(package), symbol_package(symbol_package)
|
: width(width), height(height), preserve_aspect(preserve_aspect), saturate(saturate), package(package), local_package(local_package)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
int width, height; ///< Width to force the image to, or 0 to keep the width of the input
|
int width, height; ///< Width to force the image to, or 0 to keep the width of the input
|
||||||
PreserveAspect preserve_aspect;
|
PreserveAspect preserve_aspect;
|
||||||
bool saturate;
|
bool saturate;
|
||||||
Package* package; ///< Package to load images from
|
Package* package; ///< Package to load images from
|
||||||
Package* symbol_package; ///< Package to load symbols from
|
Package* local_package; ///< Package to load symbols and ImageValue images from
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Generate the image
|
/// Generate the image
|
||||||
@@ -47,12 +47,21 @@ class GeneratedImage : public ScriptValue {
|
|||||||
inline bool operator != (const GeneratedImage& that) const { return !(*this == that); }
|
inline bool operator != (const GeneratedImage& that) const { return !(*this == that); }
|
||||||
|
|
||||||
/// Can this image be generated safely from another thread?
|
/// Can this image be generated safely from another thread?
|
||||||
virtual bool threadSafe() const = 0;
|
virtual bool threadSafe() const { return true; };
|
||||||
|
|
||||||
virtual ScriptType type() const;
|
virtual ScriptType type() const;
|
||||||
virtual String typeName() const;
|
virtual String typeName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : BlankImage
|
||||||
|
|
||||||
|
/// An image generator that returns a blank image
|
||||||
|
class BlankImage : public GeneratedImage {
|
||||||
|
public:
|
||||||
|
virtual Image generate(const Options&) const;
|
||||||
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : LinearBlendImage
|
// ----------------------------------------------------------------------------- : LinearBlendImage
|
||||||
|
|
||||||
/// An image generator that linearly blends two other images
|
/// An image generator that linearly blends two other images
|
||||||
@@ -64,8 +73,6 @@ class LinearBlendImage : public GeneratedImage {
|
|||||||
virtual Image generate(const Options& opt) const;
|
virtual Image generate(const Options& opt) const;
|
||||||
virtual ImageCombine combine() const;
|
virtual ImageCombine combine() const;
|
||||||
virtual bool operator == (const GeneratedImage& that) const;
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
|
||||||
virtual bool threadSafe() const { return true; }
|
|
||||||
private:
|
private:
|
||||||
GeneratedImageP image1, image2;
|
GeneratedImageP image1, image2;
|
||||||
double x1, y1, x2, y2;
|
double x1, y1, x2, y2;
|
||||||
@@ -82,8 +89,6 @@ class MaskedBlendImage : public GeneratedImage {
|
|||||||
virtual Image generate(const Options& opt) const;
|
virtual Image generate(const Options& opt) const;
|
||||||
virtual ImageCombine combine() const;
|
virtual ImageCombine combine() const;
|
||||||
virtual bool operator == (const GeneratedImage& that) const;
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
|
||||||
virtual bool threadSafe() const { return true; }
|
|
||||||
private:
|
private:
|
||||||
GeneratedImageP light, dark, mask;
|
GeneratedImageP light, dark, mask;
|
||||||
};
|
};
|
||||||
@@ -99,8 +104,6 @@ class CombineBlendImage : public GeneratedImage {
|
|||||||
virtual Image generate(const Options& opt) const;
|
virtual Image generate(const Options& opt) const;
|
||||||
virtual ImageCombine combine() const;
|
virtual ImageCombine combine() const;
|
||||||
virtual bool operator == (const GeneratedImage& that) const;
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
|
||||||
virtual bool threadSafe() const { return true; }
|
|
||||||
private:
|
private:
|
||||||
GeneratedImageP image1, image2;
|
GeneratedImageP image1, image2;
|
||||||
ImageCombine image_combine;
|
ImageCombine image_combine;
|
||||||
@@ -117,8 +120,6 @@ class SetMaskImage : public GeneratedImage {
|
|||||||
virtual Image generate(const Options& opt) const;
|
virtual Image generate(const Options& opt) const;
|
||||||
virtual ImageCombine combine() const;
|
virtual ImageCombine combine() const;
|
||||||
virtual bool operator == (const GeneratedImage& that) const;
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
|
||||||
virtual bool threadSafe() const { return true; }
|
|
||||||
private:
|
private:
|
||||||
GeneratedImageP image, mask;
|
GeneratedImageP image, mask;
|
||||||
};
|
};
|
||||||
@@ -134,8 +135,6 @@ class SetCombineImage : public GeneratedImage {
|
|||||||
virtual Image generate(const Options& opt) const;
|
virtual Image generate(const Options& opt) const;
|
||||||
virtual ImageCombine combine() const;
|
virtual ImageCombine combine() const;
|
||||||
virtual bool operator == (const GeneratedImage& that) const;
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
|
||||||
virtual bool threadSafe() const {return true;}
|
|
||||||
private:
|
private:
|
||||||
GeneratedImageP image;
|
GeneratedImageP image;
|
||||||
ImageCombine image_combine;
|
ImageCombine image_combine;
|
||||||
@@ -151,8 +150,6 @@ class PackagedImage : public GeneratedImage {
|
|||||||
{}
|
{}
|
||||||
virtual Image generate(const Options& opt) const;
|
virtual Image generate(const Options& opt) const;
|
||||||
virtual bool operator == (const GeneratedImage& that) const;
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
|
||||||
virtual bool threadSafe() const { return true; }
|
|
||||||
private:
|
private:
|
||||||
String filename;
|
String filename;
|
||||||
};
|
};
|
||||||
@@ -167,8 +164,6 @@ class BuiltInImage : public GeneratedImage {
|
|||||||
{}
|
{}
|
||||||
virtual Image generate(const Options& opt) const;
|
virtual Image generate(const Options& opt) const;
|
||||||
virtual bool operator == (const GeneratedImage& that) const;
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
|
||||||
virtual bool threadSafe() const { return true; }
|
|
||||||
private:
|
private:
|
||||||
String name;
|
String name;
|
||||||
};
|
};
|
||||||
@@ -185,8 +180,6 @@ class SymbolToImage : public GeneratedImage {
|
|||||||
|
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
virtual bool threadSafe() const { return false; }
|
virtual bool threadSafe() const { return false; }
|
||||||
#else
|
|
||||||
virtual bool threadSafe() const { return true; }
|
|
||||||
#endif
|
#endif
|
||||||
private:
|
private:
|
||||||
SymbolToImage(const SymbolToImage&); // copy ctor
|
SymbolToImage(const SymbolToImage&); // copy ctor
|
||||||
@@ -195,5 +188,20 @@ class SymbolToImage : public GeneratedImage {
|
|||||||
SymbolVariationP variation;
|
SymbolVariationP variation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ImageValueToImage
|
||||||
|
|
||||||
|
/// Use an image from an ImageValue as an image
|
||||||
|
class ImageValueToImage : public GeneratedImage {
|
||||||
|
public:
|
||||||
|
ImageValueToImage(const String& filename, Age age);
|
||||||
|
~ImageValueToImage();
|
||||||
|
virtual Image generate(const Options& opt) const;
|
||||||
|
virtual bool operator == (const GeneratedImage& that) const;
|
||||||
|
private:
|
||||||
|
ImageValueToImage(const ImageValueToImage&); // copy ctor
|
||||||
|
String filename;
|
||||||
|
Age age; ///< Age the symbol was last updated
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : EOF
|
// ----------------------------------------------------------------------------- : EOF
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user