Implement unique IDs and card linking

This commit is contained in:
GenevensiS
2025-08-11 16:17:13 +02:00
committed by GitHub
parent 13406b946c
commit 3bf9de18b1
100 changed files with 2432 additions and 1219 deletions
+3 -3
View File
@@ -55,9 +55,9 @@ void linear_blend(Image& img1, const Image& img2, double x1,double y1, double x2
data1 += 3;
data2 += 3;
}
}
// Blend Alpha for the two images.
}
// Blend Alpha for the two images.
if (img1.HasAlpha() && img2.HasAlpha()) {
Byte *alpha1 = img1.GetAlpha(), *alpha2 = img2.GetAlpha();
for (int y = 0; y < height; ++y) {
+5 -5
View File
@@ -91,7 +91,7 @@ IMPLEMENT_REFLECTION_ENUM(ImageCombine) {
VALUE_N("greater than 235", COMBINE_GREATER_THAN_235);
VALUE_N("greater than 240", COMBINE_GREATER_THAN_240);
VALUE_N("greater than 245", COMBINE_GREATER_THAN_245);
VALUE_N("greater than 250", COMBINE_GREATER_THAN_250);
VALUE_N("greater than 250", COMBINE_GREATER_THAN_250);
VALUE_N("smaller than 5", COMBINE_SMALLER_THAN_5);
VALUE_N("smaller than 10", COMBINE_SMALLER_THAN_10);
VALUE_N("smaller than 15", COMBINE_SMALLER_THAN_15);
@@ -237,7 +237,7 @@ COMBINE_FUN(COMBINE_GREATER_THAN_230, a > 230 ? b : a)
COMBINE_FUN(COMBINE_GREATER_THAN_235, a > 235 ? b : a)
COMBINE_FUN(COMBINE_GREATER_THAN_240, a > 240 ? b : a)
COMBINE_FUN(COMBINE_GREATER_THAN_245, a > 245 ? b : a)
COMBINE_FUN(COMBINE_GREATER_THAN_250, a > 250 ? b : a)
COMBINE_FUN(COMBINE_GREATER_THAN_250, a > 250 ? b : a)
COMBINE_FUN(COMBINE_SMALLER_THAN_5, a < 5 ? b : a)
COMBINE_FUN(COMBINE_SMALLER_THAN_10, a < 10 ? b : a)
COMBINE_FUN(COMBINE_SMALLER_THAN_15, a < 15 ? b : a)
@@ -287,7 +287,7 @@ COMBINE_FUN(COMBINE_SMALLER_THAN_230, a < 230 ? b : a)
COMBINE_FUN(COMBINE_SMALLER_THAN_235, a < 235 ? b : a)
COMBINE_FUN(COMBINE_SMALLER_THAN_240, a < 240 ? b : a)
COMBINE_FUN(COMBINE_SMALLER_THAN_245, a < 245 ? b : a)
COMBINE_FUN(COMBINE_SMALLER_THAN_250, a < 250 ? b : a)
COMBINE_FUN(COMBINE_SMALLER_THAN_250, a < 250 ? b : a)
// ----------------------------------------------------------------------------- : Combining
@@ -306,7 +306,7 @@ void combine_image_do(Image& a, Image b) {
void combine_image(Image& a, const Image& b, ImageCombine combine) {
// Images must have same size
if (a.GetWidth() != b.GetWidth() || a.GetHeight() != b.GetHeight()) {
throw Error(_ERROR_("images used for combine blending must have the same size"));
throw Error(_ERROR_("images used for combine blending must have the same size"));
}
// Copy alpha channel?
if (b.HasAlpha()) {
@@ -392,7 +392,7 @@ void combine_image(Image& a, const Image& b, ImageCombine combine) {
DISPATCH(COMBINE_GREATER_THAN_235);
DISPATCH(COMBINE_GREATER_THAN_240);
DISPATCH(COMBINE_GREATER_THAN_245);
DISPATCH(COMBINE_GREATER_THAN_250);
DISPATCH(COMBINE_GREATER_THAN_250);
DISPATCH(COMBINE_SMALLER_THAN_5);
DISPATCH(COMBINE_SMALLER_THAN_10);
DISPATCH(COMBINE_SMALLER_THAN_15);
+133 -133
View File
@@ -14,7 +14,7 @@
#include <data/field/symbol.hpp>
#include <render/symbol/filter.hpp>
#include <gui/util.hpp> // load_resource_image
#include <wx/wfstream.h>
#include <wx/wfstream.h>
// ----------------------------------------------------------------------------- : GeneratedImage
@@ -308,7 +308,7 @@ bool EnlargeImage::operator == (const GeneratedImage& that) const {
// ----------------------------------------------------------------------------- : ResizeImage
Image ResizeImage::generate(const Options& opt) const {
Image img = image->generate(opt);
Image img = image->generate(opt);
return resample(img, width, height);
}
bool ResizeImage::operator == (const GeneratedImage& that) const {
@@ -321,16 +321,16 @@ bool ResizeImage::operator == (const GeneratedImage& that) const {
// ----------------------------------------------------------------------------- : BleedEdgedImage
Image BleedEdgedImage::generate(const Options& opt) const {
// create enlarged image
// create enlarged image
Image base_img = base_image->generate(opt);
int w = base_img.GetWidth(), h = base_img.GetHeight();
int w = base_img.GetWidth(), h = base_img.GetHeight();
if (w <= 0 || h <= 0) {
queue_message(MESSAGE_ERROR, _("Cannot add bleed edge to empty image"));
queue_message(MESSAGE_ERROR, _("Cannot add bleed edge to empty image"));
return base_img;
}
bool is_landscape = w > h;
int dw = int(w * (horizontal_size > 0.0 ? horizontal_size : is_landscape ? 0.037 : 0.048));
int dh = int(h * (vertical_size > 0.0 ? vertical_size : is_landscape ? 0.048 : 0.037));
}
bool is_landscape = w > h;
int dw = int(w * (horizontal_size > 0.0 ? horizontal_size : is_landscape ? 0.037 : 0.048));
int dh = int(h * (vertical_size > 0.0 ? vertical_size : is_landscape ? 0.048 : 0.037));
if (dw <= 0 && dh <= 0) {
return base_img;
}
@@ -339,119 +339,119 @@ Image BleedEdgedImage::generate(const Options& opt) const {
Image img = wxImage(width, height, false);
img.InitAlpha();
Byte* data = img.GetData();
Byte* alpha = img.GetAlpha();
// fill with background color
Byte* alpha = img.GetAlpha();
// fill with background color
for (UInt i = 0; i < size; ++i) {
data[3 * i + 0] = background_color.Red();
data[3 * i + 1] = background_color.Green();
data[3 * i + 2] = background_color.Blue();
alpha[i] = background_color.Alpha();
}
// paste original image
img.Paste(base_img, dw, dh, wxIMAGE_ALPHA_BLEND_COMPOSE);
// fill top left corner
// paste original image
img.Paste(base_img, dw, dh, wxIMAGE_ALPHA_BLEND_COMPOSE);
// fill top left corner
int pixel;
int x_start = 0;
int y_start = 0;
int ref = dw + dh * width;
int x_start = 0;
int y_start = 0;
int ref = dw + dh * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill top right corner
x_start = width - dw;
y_start = 0;
ref = x_start - 1 + dh * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill bottom left corner
x_start = 0;
y_start = height - dh;
ref = dw + (y_start - 1) * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
alpha[pixel] = alpha[ref];
}
}
// fill bottom right corner
x_start = width - dw;
y_start = height - dh;
// fill top right corner
x_start = width - dw;
y_start = 0;
ref = x_start - 1 + dh * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill bottom left corner
x_start = 0;
y_start = height - dh;
ref = dw + (y_start - 1) * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill bottom right corner
x_start = width - dw;
y_start = height - dh;
ref = (x_start - 1) + (y_start - 1) * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
alpha[pixel] = alpha[ref];
}
}
// fill left border
x_start = 0;
y_start = dh;
for (int y = 0; y < height - dh - dh; ++y) {
}
// fill left border
x_start = 0;
y_start = dh;
for (int y = 0; y < height - dh - dh; ++y) {
ref = dw + (y_start + y) * width;
for (int x = 0; x < dw; ++x) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
alpha[pixel] = alpha[ref];
}
}
// fill top border
x_start = dw;
y_start = 0;
}
// fill top border
x_start = dw;
y_start = 0;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < width - dw - dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
for (int x = 0; x < width - dw - dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
ref = x_start + x + dh * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
alpha[pixel] = alpha[ref];
}
}
// fill right border
x_start = width - dw;
y_start = dh;
for (int y = 0; y < height - dh - dh; ++y) {
}
// fill right border
x_start = width - dw;
y_start = dh;
for (int y = 0; y < height - dh - dh; ++y) {
ref = width - dw - 1 + (y_start + y) * width;
for (int x = 0; x < dw; ++x) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
alpha[pixel] = alpha[ref];
}
}
// fill bottom border
x_start = dw;
y_start = height - dh;
}
// fill bottom border
x_start = dw;
y_start = height - dh;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < width - dw - dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
for (int x = 0; x < width - dw - dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
ref = x_start + x + (height - dh - 1) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
alpha[pixel] = alpha[ref];
}
}
// done
@@ -621,7 +621,7 @@ Image PackagedImage::generate(const Options& opt) const {
if (img.HasMask()) img.InitAlpha(); // we can't handle masks
return img;
} else {
throw ScriptError(_("Unable to load image '") + filename + _("' from '" + opt.package->name() + _("'")));
throw ScriptError(_("Unable to load image '") + filename + _("' from '") + opt.package->name() + _("'"));
}
}
bool PackagedImage::operator == (const GeneratedImage& that) const {
@@ -642,17 +642,17 @@ Image BuiltInImage::generate(const Options& opt) const {
bool BuiltInImage::operator == (const GeneratedImage& that) const {
const BuiltInImage* that2 = dynamic_cast<const BuiltInImage*>(&that);
return that2 && name == that2->name;
}
// ----------------------------------------------------------------------------- : ArbitraryImage
Image ArbitraryImage::generate(const Options& opt) const {
return image;
}
bool ArbitraryImage::operator == (const GeneratedImage& that) const {
const ArbitraryImage* that2 = dynamic_cast<const ArbitraryImage*>(&that);
return that2 && image.IsSameAs(that2->image);
}
}
// ----------------------------------------------------------------------------- : ArbitraryImage
Image ArbitraryImage::generate(const Options& opt) const {
return image;
}
bool ArbitraryImage::operator == (const GeneratedImage& that) const {
const ArbitraryImage* that2 = dynamic_cast<const ArbitraryImage*>(&that);
return that2 && image.IsSameAs(that2->image);
}
// ----------------------------------------------------------------------------- : SymbolToImage
@@ -716,48 +716,48 @@ bool ImageValueToImage::operator == (const GeneratedImage& that) const {
return that2 && filename == that2->filename
&& age == that2->age;
}
// ----------------------------------------------------------------------------- : ExternalImage
Image ExternalImage::generate(const Options& opt) const {
wxFileName fname(filepath, wxPATH_UNIX);
String filePathString = fname.GetAbsolutePath();
// ----------------------------------------------------------------------------- : ExternalImage
Image ExternalImage::generate(const Options& opt) const {
wxFileName fname(filepath, wxPATH_UNIX);
String filePathString = fname.GetAbsolutePath();
// has a pre-existing .mse-set file been loaded?
if (opt.local_package->needSaveAs()) throw ScriptError(_ERROR_1_("can't import image without set", filePathString));
// does the file pointed to by filepath exist?
if (!fname.FileExists()) throw ScriptError(_ERROR_1_("import not found", filePathString));
String fileExt = fname.GetExt();
wxBitmapType bitmapType;
if (fileExt == _("png")) bitmapType = wxBITMAP_TYPE_PNG;
else if (fileExt == _("jpg") || fileExt == _("jpeg")) bitmapType = wxBITMAP_TYPE_JPEG;
else bitmapType = wxBITMAP_TYPE_BMP;
// does the file exist in the package?
String fileNameNoExtension = fname.GetName();
if (!opt.local_package->existsIn(fileNameNoExtension)) {
auto outStream = opt.local_package->openOut(fileNameNoExtension);
wxFileInputStream inStream = wxFileInputStream(filepath.ToStdString());
if (!inStream.IsOk()) throw ScriptError(_ERROR_1_("can't create file stream", filePathString));
outStream->Write(inStream);
if (!outStream->IsOk()) throw ScriptError(_ERROR_1_("can't write image to set", filePathString));
outStream->Close();
}
// save the package with the new image
opt.local_package->save(false);
auto imageInputStream = opt.local_package->openIn(fileNameNoExtension);
Image img(*imageInputStream.get(), bitmapType);
if (!img.IsOk()) throw ScriptError(_ERROR_1_("can't import image", filePathString));
return img;
}
bool ExternalImage::operator == (const GeneratedImage& that) const {
const ExternalImage* that2 = dynamic_cast<const ExternalImage*>(&that);
return that2 && that2->filepath == filepath;
}
if (opt.local_package->needSaveAs()) throw ScriptError(_ERROR_1_("can't import image without set", filePathString));
// does the file pointed to by filepath exist?
if (!fname.FileExists()) throw ScriptError(_ERROR_1_("import not found", filePathString));
String fileExt = fname.GetExt();
wxBitmapType bitmapType;
if (fileExt == _("png")) bitmapType = wxBITMAP_TYPE_PNG;
else if (fileExt == _("jpg") || fileExt == _("jpeg")) bitmapType = wxBITMAP_TYPE_JPEG;
else bitmapType = wxBITMAP_TYPE_BMP;
// does the file exist in the package?
String fileNameNoExtension = fname.GetName();
if (!opt.local_package->existsIn(fileNameNoExtension)) {
auto outStream = opt.local_package->openOut(fileNameNoExtension);
wxFileInputStream inStream = wxFileInputStream(filepath.ToStdString());
if (!inStream.IsOk()) throw ScriptError(_ERROR_1_("can't create file stream", filePathString));
outStream->Write(inStream);
if (!outStream->IsOk()) throw ScriptError(_ERROR_1_("can't write image to set", filePathString));
outStream->Close();
}
// save the package with the new image
opt.local_package->save(false);
auto imageInputStream = opt.local_package->openIn(fileNameNoExtension);
Image img(*imageInputStream.get(), bitmapType);
if (!img.IsOk()) throw ScriptError(_ERROR_1_("can't import image", filePathString));
return img;
}
bool ExternalImage::operator == (const GeneratedImage& that) const {
const ExternalImage* that2 = dynamic_cast<const ExternalImage*>(&that);
return that2 && that2->filepath == filepath;
}
+27 -27
View File
@@ -327,9 +327,9 @@ public:
{}
Image generate(const Options& opt) const override;
bool operator == (const GeneratedImage& that) const override;
private:
private:
GeneratedImageP base_image;
double horizontal_size, vertical_size;
double horizontal_size, vertical_size;
Color background_color;
};
@@ -395,18 +395,18 @@ public:
bool operator == (const GeneratedImage& that) const override;
private:
String name;
};
// ----------------------------------------------------------------------------- : Arbitrary
};
// ----------------------------------------------------------------------------- : Arbitrary
class ArbitraryImage : public GeneratedImage {
public:
inline ArbitraryImage(const Image image)
: image(image)
{}
Image generate(const Options& opt) const override;
bool operator == (const GeneratedImage& that) const override;
private:
public:
inline ArbitraryImage(const Image image)
: image(image)
{}
Image generate(const Options& opt) const override;
bool operator == (const GeneratedImage& that) const override;
private:
Image image;
};
@@ -447,17 +447,17 @@ private:
LocalFileName filename;
Age age; ///< Age the image was last updated
};
// ----------------------------------------------------------------------------- : ExternalImage
/// Load an image from the filesystem
class ExternalImage : public GeneratedImage {
public:
ExternalImage(const String& filepath) : filepath(filepath) {};
Image generate(const Options&) const override;
bool operator == (const GeneratedImage& that) const override;
inline String toString() { return filepath; }
inline String toCode() const override { return _("<image>"); }
private:
String filepath;
};
// ----------------------------------------------------------------------------- : ExternalImage
/// Load an image from the filesystem
class ExternalImage : public GeneratedImage {
public:
ExternalImage(const String& filepath) : filepath(filepath) {};
Image generate(const Options&) const override;
bool operator == (const GeneratedImage& that) const override;
inline String toString() { return filepath; }
inline String toCode() const override { return _("<image>"); }
private:
String filepath;
};
+1 -1
View File
@@ -172,7 +172,7 @@ enum ImageCombine
, COMBINE_GREATER_THAN_235
, COMBINE_GREATER_THAN_240
, COMBINE_GREATER_THAN_245
, COMBINE_GREATER_THAN_250
, COMBINE_GREATER_THAN_250
, COMBINE_SMALLER_THAN_5
, COMBINE_SMALLER_THAN_10
, COMBINE_SMALLER_THAN_15