handle transparent images when importing symbols

This commit is contained in:
GenevensiS
2026-02-06 03:17:46 +01:00
parent 857bfb6c9c
commit d2dce6617d
16 changed files with 57 additions and 5 deletions
+2
View File
@@ -1094,6 +1094,8 @@ error:
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
#TODO: Localize #TODO: Localize
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
#TODO: Localize
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
#TODO: Localize #TODO: Localize
+2
View File
@@ -1092,6 +1092,8 @@ error:
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
#TODO: Localize #TODO: Localize
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
#TODO: Localize
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
#TODO: Localize #TODO: Localize
+2
View File
@@ -1119,6 +1119,8 @@ error:
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
#TODO: Localize #TODO: Localize
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
#TODO: Localize
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
#TODO: Localize Section #TODO: Localize Section
+1
View File
@@ -1021,6 +1021,7 @@ error:
negative image width: Bild mit Breite Null oder negativer Breite, erstellt in der Funktion '%s' negative image width: Bild mit Breite Null oder negativer Breite, erstellt in der Funktion '%s'
negative image height: Bild mit Höhe Null oder negativer Höhe, erstellt in der Funktion '%s' negative image height: Bild mit Höhe Null oder negativer Höhe, erstellt in der Funktion '%s'
can't load image: Bild konnte nicht geladen werden. Stelle sicher, dass das tatsächliche Format des Bildes mit der gespeicherten Dateiendung übereinstimmt. can't load image: Bild konnte nicht geladen werden. Stelle sicher, dass das tatsächliche Format des Bildes mit der gespeicherten Dateiendung übereinstimmt.
symbol image has alpha: Für optimale Ergebnisse sollte das Bild schwarzweiß und ohne Transparenz sein.
# error from files # error from files
no card fields: Das Spiel '%s' hat keine Kartenfelder. Definieren Sie mindestens ein Kartenfeld. no card fields: Das Spiel '%s' hat keine Kartenfelder. Definieren Sie mindestens ein Kartenfeld.
+1
View File
@@ -1023,6 +1023,7 @@ error:
negative image width: Image with zero or negative width created in function '%s' negative image width: Image with zero or negative width created in function '%s'
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
no card fields: Game '%s' does not have any card fields. Define at least one card field. no card fields: Game '%s' does not have any card fields. Define at least one card field.
+2
View File
@@ -1095,6 +1095,8 @@ error:
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
#TODO: Localize #TODO: Localize
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
#TODO: Localize
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
#TODO: Localize #TODO: Localize
+1
View File
@@ -1022,6 +1022,7 @@ error:
negative image width: Image de largeur nulle ou négative créée par la fonction '%s' negative image width: Image de largeur nulle ou négative créée par la fonction '%s'
negative image height: Image de hauteur nulle ou négative créée par la fonction '%s' negative image height: Image de hauteur nulle ou négative créée par la fonction '%s'
can't load image: Échec du chargement de l'image. Assurez-vous que le format réel de l'image corresponde à son extension enregistrée. can't load image: Échec du chargement de l'image. Assurez-vous que le format réel de l'image corresponde à son extension enregistrée.
symbol image has alpha: Pour un résultat optimal, l'image doit être en noir et blanc sans transparence.
# error from files # error from files
no card fields: Le jeu '%s' ne contient aucun champ de carte. Définissez au moins un champ de carte. no card fields: Le jeu '%s' ne contient aucun champ de carte. Définissez au moins un champ de carte.
+1
View File
@@ -1022,6 +1022,7 @@ error:
negative image width: Immagine con larghezza zero o negativa creata nella funzione '%s' negative image width: Immagine con larghezza zero o negativa creata nella funzione '%s'
negative image height: Immagine con altezza zero o negativa creata nella funzione '%s' negative image height: Immagine con altezza zero o negativa creata nella funzione '%s'
can't load image: Impossibile caricare l'immagine. Assicurarsi che il formato effettivo dell'immagine corrisponda all'estensione salvata. can't load image: Impossibile caricare l'immagine. Assicurarsi che il formato effettivo dell'immagine corrisponda all'estensione salvata.
symbol image has alpha: Per ottenere risultati ottimali, l'immagine dovrebbe essere in bianco e nero, senza trasparenza.
# error from files # error from files
no card fields: Il gioco '%s' non ha campi carta. Definisci almeno un campo carta. no card fields: Il gioco '%s' non ha campi carta. Definisci almeno un campo carta.
+2
View File
@@ -1095,6 +1095,8 @@ error:
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
#TODO: Localize #TODO: Localize
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
#TODO: Localize
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
#TODO: Localize #TODO: Localize
+2
View File
@@ -1101,6 +1101,8 @@ error:
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
#TODO: Localize #TODO: Localize
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
#TODO: Localize
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
#TODO: Localize #TODO: Localize
+2
View File
@@ -1151,6 +1151,8 @@ error:
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
#TODO: Localize #TODO: Localize
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
#TODO: Localize
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
#TODO: Localize #TODO: Localize
+1
View File
@@ -1023,6 +1023,7 @@ error:
negative image width: Imagem com largura zero ou negativa criada na função '%s' negative image width: Imagem com largura zero ou negativa criada na função '%s'
negative image height: Imagem com altura zero ou negativa criada na função '%s' negative image height: Imagem com altura zero ou negativa criada na função '%s'
can't load image: Falha ao carregar a imagem. Verifique se o formato real da imagem corresponde à extensão salva. can't load image: Falha ao carregar a imagem. Verifique se o formato real da imagem corresponde à extensão salva.
symbol image has alpha: Para obter melhores resultados, a imagem deve ser em preto e branco, sem transparência.
# error from files # error from files
no card fields: O jogo '%s' não possui campos de Card. Defina pelo menos um campo de Card. no card fields: O jogo '%s' não possui campos de Card. Defina pelo menos um campo de Card.
+2
View File
@@ -1147,6 +1147,8 @@ error:
negative image height: Image with zero or negative height created in function '%s' negative image height: Image with zero or negative height created in function '%s'
#TODO: Localize #TODO: Localize
can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. can't load image: Failed to load image. Ensure the image's actual format matches its saved extension.
#TODO: Localize
symbol image has alpha: For best results, image should be black and white with no transparency.
# error from files # error from files
#TODO: Localize Section #TODO: Localize Section
+3 -2
View File
@@ -194,10 +194,11 @@ String compute_new_variable_value(const String& str, const String& tag, size_t s
} }
while (end_i < str.size() && while (end_i < str.size() &&
is_formatting_tag(str, end_i)) { is_formatting_tag(str, end_i)) {
end_i = str.find_first_of(">", end_i) + 1; end_i = str.find_first_of(">", end_i);
if (end_i != String::npos) end_i++;
} }
String prefix(substr(str, 0, start_i)); String prefix(substr(str, 0, start_i));
String suffix(substr(str, end_i)); String suffix = end_i == String::npos ? String() : substr(str, end_i);
String selection(substr(str, start_i, end_i - start_i)); String selection(substr(str, start_i, end_i - start_i));
// tally open tags that are variants of this tag // tally open tags that are variants of this tag
+29 -2
View File
@@ -15,6 +15,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <data/format/image_to_symbol.hpp> #include <data/format/image_to_symbol.hpp>
#include <gfx/gfx.hpp>
#include <gfx/bezier.hpp> #include <gfx/bezier.hpp>
#include <util/error.hpp> #include <util/error.hpp>
#include <util/platform.hpp> #include <util/platform.hpp>
@@ -206,10 +207,12 @@ SymbolShapeP read_symbol_shape(const ImageData& data) {
SymbolP image_to_symbol(Image& img) { SymbolP image_to_symbol(Image& img) {
int w = img.GetWidth(), h = img.GetHeight(); int w = img.GetWidth(), h = img.GetHeight();
// 1. threshold the image // get rid of alpha channel
fill_alpha(img, w, h);
// threshold the image
greyscale(img); greyscale(img);
threshold(img.GetData(), w, h); threshold(img.GetData(), w, h);
// 2. read as many symbol shapes as we can // read as many symbol shapes as we can
ImageData data = {w,h,img.GetData()}; ImageData data = {w,h,img.GetData()};
SymbolP symbol(new Symbol); SymbolP symbol(new Symbol);
while (true) { while (true) {
@@ -221,6 +224,30 @@ SymbolP image_to_symbol(Image& img) {
return symbol; return symbol;
} }
void fill_alpha(Image& img, int w, int h) {
if (!img.HasAlpha() || w <= 0 || h <= 0) return;
Byte* alpha = img.GetAlpha();
for (int i = 0; i < w*h ; ++i) {
if (alpha[i] < 255) {
Byte* pixels = img.GetData();
Byte first_pixel = pixels[0];
for (int j = 1; j < 3 * w * h; ++j) {
if (pixels[j] != first_pixel) {
wxMessageDialog dial = wxMessageDialog(nullptr, _ERROR_("symbol image has alpha"));
dial.ShowModal();
break;
}
}
Image copy = img.Copy();
memset(copy.GetData(), 255, 3 * w * h);
memset(pixels, 0, 3 * w * h);
memset(alpha, 255, w * h);
img.Paste(copy, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE);
return;
}
}
}
SymbolP import_symbol(Image& img) { SymbolP import_symbol(Image& img) {
SymbolP symbol; SymbolP symbol;
if (is_mse1_symbol(img)) { if (is_mse1_symbol(img)) {
+3
View File
@@ -24,6 +24,9 @@ bool is_mse1_symbol(const Image& img);
/// Convert an image to a symbol, destroys the image in the process /// Convert an image to a symbol, destroys the image in the process
SymbolP image_to_symbol(Image& img); SymbolP image_to_symbol(Image& img);
/// If an image has alpha, try to save it if it has only one color
void fill_alpha(Image& img, int w, int h);
// ----------------------------------------------------------------------------- : Simplify symbol // ----------------------------------------------------------------------------- : Simplify symbol
/// Simplify a symbol /// Simplify a symbol