Skip to content

Commit 5d26fdc

Browse files
Multiple watermarks (#219), DDS import (#235)
1 parent 24d33a1 commit 5d26fdc

File tree

5 files changed

+97
-58
lines changed

5 files changed

+97
-58
lines changed

src/bimp-gui.c

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ static void add_input_folder_r(char* folder, gboolean with_subdirs)
332332
g_ascii_strcasecmp(file_extension, ".webp") == 0 ||
333333
g_ascii_strcasecmp(file_extension, ".xpm") == 0 ||
334334
g_ascii_strcasecmp(file_extension, ".exr") == 0 ||
335+
g_ascii_strcasecmp(file_extension, ".dds") == 0 ||
335336
g_ascii_strcasecmp(file_extension, ".xcf") == 0) &&
336337
g_slist_find_custom(bimp_input_filenames, filename, (GCompareFunc)strcmp) == NULL)
337338
{
@@ -592,7 +593,7 @@ static void open_file_chooser(GtkWidget *widget, gpointer data)
592593
{
593594
GSList *selection;
594595

595-
GtkFileFilter *filter_all, *supported[14];
596+
GtkFileFilter *filter_all, *supported[15];
596597

597598
GtkWidget* file_chooser = gtk_file_chooser_dialog_new(
598599
_("Select images"),
@@ -611,82 +612,87 @@ static void open_file_chooser(GtkWidget *widget, gpointer data)
611612
gtk_file_filter_set_name(supported[0], "Bitmap (*.bmp)");
612613
gtk_file_filter_add_pattern (supported[0], "*.[bB][mM][pP]");
613614
gtk_file_filter_add_pattern (filter_all, "*.[bB][mM][pP]");
614-
615+
615616
supported[1] = gtk_file_filter_new();
616-
gtk_file_filter_set_name(supported[1], "JPEG (*.jpg, *.jpeg, *jpe)");
617-
gtk_file_filter_add_pattern (supported[1], "*.[jJ][pP][gG]");
618-
gtk_file_filter_add_pattern (supported[1], "*.[jJ][pP][eE][gG]");
619-
gtk_file_filter_add_pattern (supported[1], "*.[jJ][pP][eE]");
617+
gtk_file_filter_set_name(supported[1], "DDS (*.dds)");
618+
gtk_file_filter_add_pattern (supported[1], "*.[dD][dD][sS]");
619+
gtk_file_filter_add_pattern (filter_all, "*.[dD][dD][sS]");
620+
621+
supported[2] = gtk_file_filter_new();
622+
gtk_file_filter_set_name(supported[2], "JPEG (*.jpg, *.jpeg, *jpe)");
623+
gtk_file_filter_add_pattern (supported[2], "*.[jJ][pP][gG]");
624+
gtk_file_filter_add_pattern (supported[2], "*.[jJ][pP][eE][gG]");
625+
gtk_file_filter_add_pattern (supported[2], "*.[jJ][pP][eE]");
620626
gtk_file_filter_add_pattern (filter_all, "*.[jJ][pP][gG]");
621627
gtk_file_filter_add_pattern (filter_all, "*.[jJ][pP][eE][gG]");
622628
gtk_file_filter_add_pattern (filter_all, "*.[jJ][pP][eE]");
623629

624-
supported[2] = gtk_file_filter_new();
625-
gtk_file_filter_set_name(supported[2], "JPEG2000 (*.jp2)");
626-
gtk_file_filter_add_pattern (supported[2], "*.[jJ][pP][2]");
627-
628630
supported[3] = gtk_file_filter_new();
629-
gtk_file_filter_set_name(supported[3], "GIF (*.gif)");
630-
gtk_file_filter_add_pattern (supported[3], "*.[gG][iI][fF]");
631+
gtk_file_filter_set_name(supported[3], "JPEG2000 (*.jp2)");
632+
gtk_file_filter_add_pattern (supported[3], "*.[jJ][pP][2]");
633+
634+
supported[4] = gtk_file_filter_new();
635+
gtk_file_filter_set_name(supported[4], "GIF (*.gif)");
636+
gtk_file_filter_add_pattern (supported[4], "*.[gG][iI][fF]");
631637
gtk_file_filter_add_pattern (filter_all, "*.[gG][iI][fF]");
632638

633-
supported[4] = gtk_file_filter_new();
634-
gtk_file_filter_set_name(supported[4], "PNG (*.png)");
635-
gtk_file_filter_add_pattern (supported[4], "*.[pP][nN][gG]");
639+
supported[5] = gtk_file_filter_new();
640+
gtk_file_filter_set_name(supported[5], "PNG (*.png)");
641+
gtk_file_filter_add_pattern (supported[5], "*.[pP][nN][gG]");
636642
gtk_file_filter_add_pattern (filter_all, "*.[pP][nN][gG]");
637643

638-
supported[5] = gtk_file_filter_new();
639-
gtk_file_filter_set_name(supported[5], "HEIF/HEIC (*.heif, *.heic)");
640-
gtk_file_filter_add_pattern (supported[5], "*.[hH][eE][iI][fF]");
641-
gtk_file_filter_add_pattern (supported[5], "*.[hH][eE][iI][cC]");
644+
supported[6] = gtk_file_filter_new();
645+
gtk_file_filter_set_name(supported[6], "HEIF/HEIC (*.heif, *.heic)");
646+
gtk_file_filter_add_pattern (supported[6], "*.[hH][eE][iI][fF]");
647+
gtk_file_filter_add_pattern (supported[6], "*.[hH][eE][iI][cC]");
642648
gtk_file_filter_add_pattern (filter_all, "*.[hH][eE][iI][fF]");
643649
gtk_file_filter_add_pattern (filter_all, "*.[hH][eE][iI][cC]");
644650

645-
supported[6] = gtk_file_filter_new();
646-
gtk_file_filter_set_name(supported[6], "Icon (*.ico)");
647-
gtk_file_filter_add_pattern (supported[6], "*.[iI][cC][oO]");
651+
supported[7] = gtk_file_filter_new();
652+
gtk_file_filter_set_name(supported[7], "Icon (*.ico)");
653+
gtk_file_filter_add_pattern (supported[7], "*.[iI][cC][oO]");
648654
gtk_file_filter_add_pattern (filter_all, "*.[iI][cC][oO]");
649655

650-
supported[7] = gtk_file_filter_new();
651-
gtk_file_filter_set_name(supported[7], "Scalable Vector Graphics (*.svg)");
652-
gtk_file_filter_add_pattern (supported[7], "*.[sS][vV][gG]");
656+
supported[8] = gtk_file_filter_new();
657+
gtk_file_filter_set_name(supported[8], "Scalable Vector Graphics (*.svg)");
658+
gtk_file_filter_add_pattern (supported[8], "*.[sS][vV][gG]");
653659
gtk_file_filter_add_pattern (filter_all, "*.[sS][vV][gG]");
654660

655-
supported[8] = gtk_file_filter_new();
656-
gtk_file_filter_set_name(supported[8], "TIFF (*tif, *.tiff)");
657-
gtk_file_filter_add_pattern (supported[8], "*.[tT][iI][fF][fF]");
658-
gtk_file_filter_add_pattern (supported[8], "*.[tT][iI][fF]");
661+
supported[9] = gtk_file_filter_new();
662+
gtk_file_filter_set_name(supported[9], "TIFF (*tif, *.tiff)");
663+
gtk_file_filter_add_pattern (supported[9], "*.[tT][iI][fF][fF]");
664+
gtk_file_filter_add_pattern (supported[9], "*.[tT][iI][fF]");
659665
gtk_file_filter_add_pattern (filter_all, "*.[tT][iI][fF][fF]");
660666
gtk_file_filter_add_pattern (filter_all, "*.[tT][iI][fF]");
661667

662-
supported[9] = gtk_file_filter_new();
663-
gtk_file_filter_set_name(supported[9], "Targa (*.tga)");
664-
gtk_file_filter_add_pattern (supported[9], "*.[tT][gG][aA]");
668+
supported[10] = gtk_file_filter_new();
669+
gtk_file_filter_set_name(supported[10], "Targa (*.tga)");
670+
gtk_file_filter_add_pattern (supported[10], "*.[tT][gG][aA]");
665671
gtk_file_filter_add_pattern (filter_all, "*.[tT][gG][aA]");
666672

667-
supported[10] = gtk_file_filter_new();
668-
gtk_file_filter_set_name(supported[10], "WebP (*.webp)");
669-
gtk_file_filter_add_pattern (supported[10], "*.[wW][eE][bB][pP]");
673+
supported[11] = gtk_file_filter_new();
674+
gtk_file_filter_set_name(supported[11], "WebP (*.webp)");
675+
gtk_file_filter_add_pattern (supported[11], "*.[wW][eE][bB][pP]");
670676
gtk_file_filter_add_pattern (filter_all, "*.[wW][eE][bB][pP]");
671677

672-
supported[11] = gtk_file_filter_new();
673-
gtk_file_filter_set_name(supported[11], "XPM (*.xpm)");
674-
gtk_file_filter_add_pattern (supported[11], "*.[xX][pP][mM]");
678+
supported[12] = gtk_file_filter_new();
679+
gtk_file_filter_set_name(supported[12], "XPM (*.xpm)");
680+
gtk_file_filter_add_pattern (supported[12], "*.[xX][pP][mM]");
675681
gtk_file_filter_add_pattern (filter_all, "*.[xX][pP][mM]");
676682

677-
supported[12] = gtk_file_filter_new();
678-
gtk_file_filter_set_name(supported[12], "OpenEXR (*.exr)");
679-
gtk_file_filter_add_pattern (supported[12], "*.[eE][xX][rR]");
683+
supported[13] = gtk_file_filter_new();
684+
gtk_file_filter_set_name(supported[13], "OpenEXR (*.exr)");
685+
gtk_file_filter_add_pattern (supported[13], "*.[eE][xX][rR]");
680686
gtk_file_filter_add_pattern (filter_all, "*.[eE][xX][rR]");
681687

682-
supported[13] = gtk_file_filter_new();
683-
gtk_file_filter_set_name(supported[13], "GIMP XCF (*.xcf)");
684-
gtk_file_filter_add_pattern (supported[13], "*.[xX][cC][fF]");
688+
supported[14] = gtk_file_filter_new();
689+
gtk_file_filter_set_name(supported[14], "GIMP XCF (*.xcf)");
690+
gtk_file_filter_add_pattern (supported[14], "*.[xX][cC][fF]");
685691
gtk_file_filter_add_pattern (filter_all, "*.[xX][cC][fF]");
686692

687693
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), filter_all);
688694
size_t i;
689-
for(i = 0; i < 14; i++) {
695+
for(i = 0; i < 15; i++) {
690696
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_chooser), supported[i]);
691697
}
692698

src/bimp-manipulations.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ manipulation bimp_append_manipulation(manipulation_type type)
1616
{
1717
manipulation newman = NULL; /* newman, paul newman. */
1818

19-
if (type != MANIP_USERDEF && bimp_list_contains_manip(type)) {
19+
if (type != MANIP_WATERMARK && type != MANIP_USERDEF && bimp_list_contains_manip(type)) {
2020
return NULL;
2121
}
2222
else {
@@ -116,6 +116,20 @@ manipulation bimp_list_get_manip(manipulation_type search)
116116
return found_man;
117117
}
118118

119+
GSList* bimp_list_get_manip_all(manipulation_type search)
120+
{
121+
GSList *result = NULL;
122+
GSList *iterator = NULL;
123+
124+
for (iterator = bimp_selected_manipulations; iterator; iterator = iterator->next) {
125+
manipulation found_man = (manipulation)(iterator->data);
126+
if (found_man->type == search) result = g_slist_append (result, iterator->data);
127+
}
128+
129+
return result;
130+
}
131+
132+
119133
/* set of constructors for each type of manipulation (with default values) */
120134

121135
manipulation manipulation_resize_new()

src/bimp-manipulations.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ void bimp_remove_manipulation(manipulation);
266266
gboolean bimp_list_contains_manip(manipulation_type);
267267
gboolean bimp_list_contains_savingplugin(void);
268268
manipulation bimp_list_get_manip(manipulation_type);
269+
GSList* bimp_list_get_manip_all(manipulation_type);
269270
char* bimp_manip_get_string(manipulation_type);
270271

271272
manipulation manipulation_sharpblur_new(void);

src/bimp-operate.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,14 @@ void bimp_apply_drawable_manipulations(image_output imageout, gchar* orig_filena
364364

365365
// watermark at last
366366
if(list_contains_watermark) {
367-
g_print("Applying WATERMARK...\n");
368-
apply_watermark((watermark_settings)(bimp_list_get_manip(MANIP_WATERMARK))->settings, imageout);
367+
GSList* watermarks = bimp_list_get_manip_all(MANIP_WATERMARK);
368+
GSList *iterator = NULL;
369+
for (iterator = watermarks; iterator; iterator = iterator->next) {
370+
g_print("Applying WATERMARK...\n");
371+
apply_watermark((watermark_settings)(((manipulation)(iterator->data))->settings), imageout);
372+
}
373+
374+
369375
}
370376

371377
// re-enable undo

src/bimp-serialize.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ static void write_color(color_settings, GKeyFile*);
2727
static manipulation read_color(GKeyFile*, int);
2828
static void write_sharpblur(sharpblur_settings, GKeyFile*);
2929
static manipulation read_sharpblur(GKeyFile*);
30-
static void write_watermark(watermark_settings, GKeyFile*);
31-
static manipulation read_watermark(GKeyFile*);
30+
static void write_watermark(watermark_settings, GKeyFile*, int);
31+
static manipulation read_watermark(GKeyFile*, int);
3232
static void write_changeformat(changeformat_settings, GKeyFile*);
3333
static manipulation read_changeformat(GKeyFile*);
3434
static void write_rename(rename_settings, GKeyFile*);
3535
static manipulation read_rename(GKeyFile*);
3636
static void write_userdef(userdef_settings, GKeyFile*, int);
3737
static manipulation read_userdef(GKeyFile*, int);
3838

39-
static int userdef_count;
39+
static int watermark_count, userdef_count;
4040
static int loaded_build;
4141

4242
gboolean bimp_serialize_to_file(gchar* filename)
@@ -48,6 +48,7 @@ gboolean bimp_serialize_to_file(gchar* filename)
4848

4949
g_key_file_set_comment (output_file, NULL, NULL, g_strdup_printf("BIMP %s\nMANIPULATION SET DEFINITION", PLUG_IN_VERSION), NULL);
5050

51+
watermark_count = 0;
5152
userdef_count = 0;
5253
g_slist_foreach(bimp_selected_manipulations, (GFunc)append_manipulation_details, output_file);
5354

@@ -123,7 +124,8 @@ static void append_manipulation_details(manipulation man, GKeyFile* output_file)
123124
write_sharpblur((sharpblur_settings)man->settings, output_file);
124125
}
125126
else if (man->type == MANIP_WATERMARK) {
126-
write_watermark((watermark_settings)man->settings, output_file);
127+
write_watermark((watermark_settings)man->settings, output_file, watermark_count);
128+
watermark_count++;
127129
}
128130
else if (man->type == MANIP_CHANGEFORMAT) {
129131
write_changeformat((changeformat_settings)man->settings, output_file);
@@ -163,8 +165,16 @@ static GSList* parse_manipulations(GKeyFile* file, int version)
163165
else if (strcmp(groups[i], "SHARPBLUR") == 0) {
164166
newman = read_sharpblur(file);
165167
}
166-
else if (strcmp(groups[i], "WATERMARK") == 0) {
167-
newman = read_watermark(file);
168+
else if (strncmp(groups[i], "WATERMARK", strlen("WATERMARK")) == 0) {
169+
if (strcmp(groups[i], "WATERMARK") == 0) {
170+
newman = read_watermark(file, -1);
171+
}
172+
else {
173+
int watermark_id;
174+
if (sscanf(groups[i], "WATERMARK%d", &watermark_id) == 1) {
175+
newman = read_watermark(file, watermark_id);
176+
}
177+
}
168178
}
169179
else if (strcmp(groups[i], "CHANGEFORMAT") == 0) {
170180
newman = read_changeformat(file);
@@ -593,9 +603,9 @@ static manipulation read_sharpblur(GKeyFile* file)
593603
return man;
594604
}
595605

596-
static void write_watermark(watermark_settings settings, GKeyFile* file)
606+
static void write_watermark(watermark_settings settings, GKeyFile* file, int id)
597607
{
598-
gchar* group_name = "WATERMARK";
608+
gchar* group_name = g_strdup_printf("WATERMARK%d", id);
599609

600610
g_key_file_set_boolean(file, group_name, "mode", settings->mode);
601611
g_key_file_set_string(file, group_name, "text", settings->text);
@@ -609,9 +619,11 @@ static void write_watermark(watermark_settings settings, GKeyFile* file)
609619
g_key_file_set_integer(file, group_name, "position", settings->position);
610620
}
611621

612-
static manipulation read_watermark(GKeyFile* file)
622+
static manipulation read_watermark(GKeyFile* file, int id)
613623
{
614-
gchar* group_name = "WATERMARK";
624+
gchar* group_name;
625+
if (id == -1) group_name = "WATERMARK";
626+
else group_name = g_strdup_printf("WATERMARK%d", id);
615627
manipulation man = NULL;
616628

617629
if (g_key_file_has_group(file, group_name)) {

0 commit comments

Comments
 (0)