Skip to content

Commit 9c86e57

Browse files
committed
foreign: replace coding table with flag enum
1 parent d09cdf2 commit 9c86e57

File tree

7 files changed

+51
-36
lines changed

7 files changed

+51
-36
lines changed

libvips/foreign/dzsave.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,17 +2047,12 @@ vips_foreign_save_dz_build(VipsObject *object)
20472047
*/
20482048
if (dz->direct) {
20492049
VipsImage *z;
2050-
gboolean coding[VIPS_CODING_LAST];
2051-
2052-
for (int i = 0; i < VIPS_CODING_LAST; i++)
2053-
coding[i] = FALSE;
2054-
coding[VIPS_CODING_NONE] = TRUE;
20552050

20562051
if (vips__foreign_convert_saveable(save->ready, &z,
20572052
VIPS_FOREIGN_SAVEABLE_MONO |
20582053
VIPS_FOREIGN_SAVEABLE_RGB |
20592054
VIPS_FOREIGN_SAVEABLE_CMYK,
2060-
bandfmt_dzsave, coding, save->background))
2055+
bandfmt_dzsave, VIPS_FOREIGN_CODING_NONE, save->background))
20612056
return -1;
20622057

20632058
VIPS_UNREF(save->ready);
@@ -2325,7 +2320,7 @@ vips_foreign_save_dz_class_init(VipsForeignSaveDzClass *class)
23252320

23262321
save_class->saveable = VIPS_FOREIGN_SAVEABLE_ANY;
23272322
save_class->format_table = bandfmt_dz;
2328-
save_class->coding[VIPS_CODING_LABQ] = TRUE;
2323+
save_class->coding |= VIPS_FOREIGN_CODING_LABQ;
23292324

23302325
VIPS_ARG_STRING(class, "imagename", 2,
23312326
_("Image name"),

libvips/foreign/foreign.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ vips_foreign_apply_saveable(VipsImage *in, VipsImage **ready,
15261526
*/
15271527
int
15281528
vips__foreign_convert_saveable(VipsImage *in, VipsImage **ready,
1529-
VipsForeignSaveable saveable, VipsBandFormat *format, VipsCoding *coding,
1529+
VipsForeignSaveable saveable, VipsBandFormat *format, VipsForeignCoding coding,
15301530
VipsArrayDouble *background)
15311531
{
15321532
VipsImage *out;
@@ -1536,13 +1536,14 @@ vips__foreign_convert_saveable(VipsImage *in, VipsImage **ready,
15361536
g_object_ref(in);
15371537

15381538
g_assert(format);
1539-
g_assert(coding);
15401539

15411540
/* For coded images, can this class save the coding we are in now?
15421541
* Nothing to do.
15431542
*/
1544-
if (in->Coding != VIPS_CODING_NONE &&
1545-
coding[in->Coding]) {
1543+
if ((in->Coding == VIPS_CODING_LABQ &&
1544+
(coding & VIPS_FOREIGN_CODING_LABQ)) ||
1545+
(in->Coding == VIPS_CODING_RAD &&
1546+
(coding & VIPS_FOREIGN_CODING_RAD))) {
15461547
*ready = in;
15471548
return 0;
15481549
}
@@ -1650,30 +1651,34 @@ vips__foreign_convert_saveable(VipsImage *in, VipsImage **ready,
16501651
in = out;
16511652
}
16521653

1653-
/* Does this class want a coded image? Search the coding table for the
1654-
* first one.
1654+
/* Does this class want a coded image?
16551655
*/
1656-
if (coding[in->Coding]) {
1656+
if ((in->Coding == VIPS_CODING_NONE &&
1657+
(coding & VIPS_FOREIGN_CODING_NONE)) ||
1658+
(in->Coding == VIPS_CODING_LABQ &&
1659+
(coding & VIPS_FOREIGN_CODING_LABQ)) ||
1660+
(in->Coding == VIPS_CODING_RAD &&
1661+
(coding & VIPS_FOREIGN_CODING_RAD))) {
16571662
/* Already there, nothing to do.
16581663
*/
16591664
}
1660-
else if (coding[VIPS_CODING_LABQ]) {
1665+
else if (coding & VIPS_FOREIGN_CODING_LABQ) {
16611666
if (vips_Lab2LabQ(in, &out, NULL)) {
16621667
g_object_unref(in);
16631668
return -1;
16641669
}
16651670
g_object_unref(in);
16661671
in = out;
16671672
}
1668-
else if (coding[VIPS_CODING_RAD]) {
1673+
else if (coding & VIPS_FOREIGN_CODING_RAD) {
16691674
if (vips_float2rad(in, &out, NULL)) {
16701675
g_object_unref(in);
16711676
return -1;
16721677
}
16731678
g_object_unref(in);
16741679
in = out;
16751680
}
1676-
else if (coding[VIPS_CODING_NONE]) {
1681+
else if (coding & VIPS_FOREIGN_CODING_NONE) {
16771682
if (vips_image_decode(in, &out)) {
16781683
g_object_unref(in);
16791684
return -1;
@@ -1832,8 +1837,6 @@ vips_foreign_save_class_init(VipsForeignSaveClass *class)
18321837
VipsObjectClass *object_class = (VipsObjectClass *) class;
18331838
VipsOperationClass *operation_class = (VipsOperationClass *) class;
18341839

1835-
int i;
1836-
18371840
gobject_class->dispose = vips_foreign_save_dispose;
18381841
gobject_class->set_property = vips_object_set_property;
18391842
gobject_class->get_property = vips_object_get_property;
@@ -1856,9 +1859,7 @@ vips_foreign_save_class_init(VipsForeignSaveClass *class)
18561859

18571860
/* Default to no coding allowed.
18581861
*/
1859-
for (i = 0; i < VIPS_CODING_LAST; i++)
1860-
class->coding[i] = FALSE;
1861-
class->coding[VIPS_CODING_NONE] = TRUE;
1862+
class->coding = VIPS_FOREIGN_CODING_NONE;
18621863

18631864
/* Default to no cast on save.
18641865
*/

libvips/foreign/radsave.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ vips_foreign_save_rad_class_init(VipsForeignSaveRadClass *class)
9696
save_class->saveable =
9797
VIPS_FOREIGN_SAVEABLE_MONO | VIPS_FOREIGN_SAVEABLE_RGB;
9898
save_class->format_table = vips_foreign_save_rad_format_table;
99-
save_class->coding[VIPS_CODING_NONE] = FALSE;
100-
save_class->coding[VIPS_CODING_RAD] = TRUE;
99+
save_class->coding = VIPS_FOREIGN_CODING_RAD;
101100
}
102101

103102
static void

libvips/foreign/tiffsave.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ vips_foreign_save_tiff_class_init(VipsForeignSaveTiffClass *class)
254254
foreign_class->suffs = vips__foreign_tiff_suffs;
255255

256256
save_class->saveable = VIPS_FOREIGN_SAVEABLE_ANY;
257-
save_class->coding[VIPS_CODING_LABQ] = TRUE;
257+
save_class->coding |= VIPS_FOREIGN_CODING_LABQ;
258258

259259
VIPS_ARG_ENUM(class, "compression", 6,
260260
_("Compression"),

libvips/foreign/vipssave.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ extern const char *vips__suffs[];
128128
static void
129129
vips_foreign_save_vips_class_init(VipsForeignSaveVipsClass *class)
130130
{
131-
int i;
132-
133131
GObjectClass *gobject_class = G_OBJECT_CLASS(class);
134132
VipsObjectClass *object_class = (VipsObjectClass *) class;
135133
VipsForeignClass *foreign_class = (VipsForeignClass *) class;
@@ -144,8 +142,7 @@ vips_foreign_save_vips_class_init(VipsForeignSaveVipsClass *class)
144142
foreign_class->suffs = vips__suffs;
145143

146144
save_class->saveable = VIPS_FOREIGN_SAVEABLE_ANY;
147-
for (i = 0; i < VIPS_CODING_LAST; i++)
148-
save_class->coding[i] = TRUE;
145+
save_class->coding = VIPS_FOREIGN_CODING_ALL;
149146
}
150147

151148
static void

libvips/include/vips/foreign.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,28 @@ typedef enum /*< flags >*/ {
333333
VIPS_FOREIGN_SAVEABLE_ALPHA)
334334
} VipsForeignSaveable;
335335

336+
/**
337+
* VipsForeignCoding:
338+
* @VIPS_FOREIGN_CODING_NONE: saver supports [enum@Vips.Coding.NONE]
339+
* @VIPS_FOREIGN_CODING_LABQ: saver supports [enum@Vips.Coding.LABQ]
340+
* @VIPS_FOREIGN_CODING_RAD: saver supports [enum@Vips.Coding.RAD]
341+
* @VIPS_FOREIGN_CODING_ALL: saver supports all coding types
342+
*
343+
* The set of coding types supported by a saver.
344+
*
345+
* ::: seealso
346+
* [enum@Coding].
347+
*/
348+
typedef enum /*< flags >*/ {
349+
VIPS_FOREIGN_CODING_NONE = 1 << 0,
350+
VIPS_FOREIGN_CODING_LABQ = 1 << 1,
351+
VIPS_FOREIGN_CODING_RAD = 1 << 2,
352+
353+
VIPS_FOREIGN_CODING_ALL = (VIPS_FOREIGN_CODING_NONE |
354+
VIPS_FOREIGN_CODING_LABQ |
355+
VIPS_FOREIGN_CODING_RAD)
356+
} VipsForeignCoding;
357+
336358
/**
337359
* VipsForeignKeep:
338360
* @VIPS_FOREIGN_KEEP_NONE: don't attach metadata
@@ -357,7 +379,7 @@ typedef enum /*< flags >*/ {
357379
VIPS_FOREIGN_KEEP_XMP |
358380
VIPS_FOREIGN_KEEP_IPTC |
359381
VIPS_FOREIGN_KEEP_ICC |
360-
VIPS_FOREIGN_KEEP_OTHER),
382+
VIPS_FOREIGN_KEEP_OTHER)
361383
} VipsForeignKeep;
362384

363385
typedef struct _VipsForeignSave {
@@ -408,7 +430,7 @@ typedef struct _VipsForeignSaveClass {
408430
*
409431
* @saveable describes the image types that your saver can handle. For
410432
* example, PPM images can have 1 or 3 bands (mono or RGB), so it
411-
* uses VIPS_SAVEABLE_FLAGS_MONO | VIPS_SAVEABLE_FLAGS_RGB.
433+
* uses [flags@Vips.ForeignSaveable.MONO] | [flags@Vips.ForeignSaveable.RGB].
412434
*/
413435
VipsForeignSaveable saveable;
414436

@@ -420,12 +442,13 @@ typedef struct _VipsForeignSaveClass {
420442
*/
421443
VipsBandFormat *format_table;
422444

423-
/* The set of coding types this format can save. For example, jpeg can
424-
* only save NONE, so has NONE TRUE and RAD and LABQ FALSE.
445+
/* The set of coding types this format can save. For example,
446+
* [method@Image.vipssave] can save all coding types, so it
447+
* uses [flags@Vips.ForeignCoding.ALL]
425448
*
426-
* Default NONE TRUE, RAD and LABQ FALSE.
449+
* Default to [flags@Vips.ForeignCoding.NONE].
427450
*/
428-
gboolean coding[VIPS_CODING_LAST];
451+
VipsForeignCoding coding;
429452
} VipsForeignSaveClass;
430453

431454
VIPS_API

libvips/include/vips/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ typedef struct _VipsImagePixels {
342342
} VipsImagePixels;
343343

344344
int vips__foreign_convert_saveable(VipsImage *in, VipsImage **ready,
345-
VipsForeignSaveable saveable, VipsBandFormat *format, VipsCoding *coding,
345+
VipsForeignSaveable saveable, VipsBandFormat *format, VipsForeignCoding coding,
346346
VipsArrayDouble *background);
347347

348348
int vips_foreign_load(const char *filename, VipsImage **out, ...)

0 commit comments

Comments
 (0)