summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-11-04 16:25:00 +0100
committerKim Woelders <kim@woelders.dk>2021-11-05 17:22:01 +0100
commit543323230864ed8e00754b746f4f2ee2418ba0c4 (patch)
tree33a84f8e8aef80368c2a7deda3575d1dcd1d37d1
parent55a27d01f8e96a6c448cc3059c17e67453303461 (diff)
Introduce UPDATE_FLAG()
Somewhat simpler.
-rw-r--r--src/lib/api.c42
-rw-r--r--src/lib/image.h2
-rw-r--r--src/modules/loaders/loader_argb.c5
-rw-r--r--src/modules/loaders/loader_bmp.c6
-rw-r--r--src/modules/loaders/loader_gif.c5
-rw-r--r--src/modules/loaders/loader_lbm.c5
-rw-r--r--src/modules/loaders/loader_png.c5
-rw-r--r--src/modules/loaders/loader_pnm.c5
-rw-r--r--src/modules/loaders/loader_tga.c5
-rw-r--r--src/modules/loaders/loader_tiff.c6
-rw-r--r--src/modules/loaders/loader_webp.c5
-rw-r--r--src/modules/loaders/loader_xpm.c5
12 files changed, 20 insertions, 76 deletions
diff --git a/src/lib/api.c b/src/lib/api.c
index 3f65bba..13b42bb 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -1754,14 +1754,7 @@ imlib_image_set_irrelevant_format(char irrelevant)
1754 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_format", "image", 1754 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_format", "image",
1755 ctx->image); 1755 ctx->image);
1756 CAST_IMAGE(im, ctx->image); 1756 CAST_IMAGE(im, ctx->image);
1757 if (irrelevant) 1757 UPDATE_FLAG(im->flags, F_FORMAT_IRRELEVANT, irrelevant);
1758 {
1759 SET_FLAG(im->flags, F_FORMAT_IRRELEVANT);
1760 }
1761 else
1762 {
1763 UNSET_FLAG(im->flags, F_FORMAT_IRRELEVANT);
1764 }
1765} 1758}
1766 1759
1767/** 1760/**
@@ -1780,14 +1773,7 @@ imlib_image_set_irrelevant_border(char irrelevant)
1780 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_border", "image", 1773 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_border", "image",
1781 ctx->image); 1774 ctx->image);
1782 CAST_IMAGE(im, ctx->image); 1775 CAST_IMAGE(im, ctx->image);
1783 if (irrelevant) 1776 UPDATE_FLAG(im->flags, F_BORDER_IRRELEVANT, irrelevant);
1784 {
1785 SET_FLAG(im->flags, F_BORDER_IRRELEVANT);
1786 }
1787 else
1788 {
1789 UNSET_FLAG(im->flags, F_BORDER_IRRELEVANT);
1790 }
1791} 1777}
1792 1778
1793/** 1779/**
@@ -1806,14 +1792,7 @@ imlib_image_set_irrelevant_alpha(char irrelevant)
1806 CHECK_CONTEXT(ctx); 1792 CHECK_CONTEXT(ctx);
1807 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_alpha", "image", ctx->image); 1793 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_alpha", "image", ctx->image);
1808 CAST_IMAGE(im, ctx->image); 1794 CAST_IMAGE(im, ctx->image);
1809 if (irrelevant) 1795 UPDATE_FLAG(im->flags, F_ALPHA_IRRELEVANT, irrelevant);
1810 {
1811 SET_FLAG(im->flags, F_ALPHA_IRRELEVANT);
1812 }
1813 else
1814 {
1815 UNSET_FLAG(im->flags, F_ALPHA_IRRELEVANT);
1816 }
1817} 1796}
1818 1797
1819/** 1798/**
@@ -1847,10 +1826,7 @@ imlib_image_set_has_alpha(char has_alpha)
1847 CHECK_CONTEXT(ctx); 1826 CHECK_CONTEXT(ctx);
1848 CHECK_PARAM_POINTER("imlib_image_set_has_alpha", "image", ctx->image); 1827 CHECK_PARAM_POINTER("imlib_image_set_has_alpha", "image", ctx->image);
1849 CAST_IMAGE(im, ctx->image); 1828 CAST_IMAGE(im, ctx->image);
1850 if (has_alpha) 1829 UPDATE_FLAG(im->flags, F_HAS_ALPHA, has_alpha);
1851 SET_FLAG(im->flags, F_HAS_ALPHA);
1852 else
1853 UNSET_FLAG(im->flags, F_HAS_ALPHA);
1854} 1830}
1855 1831
1856#ifdef BUILD_X11 1832#ifdef BUILD_X11
@@ -2265,10 +2241,7 @@ imlib_create_image_from_drawable(Pixmap mask, int x, int y, int width,
2265 ctx->colormap, ctx->depth, x, y, width, 2241 ctx->colormap, ctx->depth, x, y, width,
2266 height, &domask, need_to_grab_x)) 2242 height, &domask, need_to_grab_x))
2267 { 2243 {
2268 if (domask) 2244 UPDATE_FLAG(im->flags, F_HAS_ALPHA, domask);
2269 SET_FLAG(im->flags, F_HAS_ALPHA);
2270 else
2271 UNSET_FLAG(im->flags, F_HAS_ALPHA);
2272 } 2245 }
2273 else 2246 else
2274 { 2247 {
@@ -2450,10 +2423,7 @@ imlib_create_scaled_image_from_drawable(Pixmap mask, int source_x,
2450 ctx->visual, ctx->colormap, ctx->depth, 0, 0, 2423 ctx->visual, ctx->colormap, ctx->depth, 0, 0,
2451 destination_width, destination_height, &domask, 2424 destination_width, destination_height, &domask,
2452 need_to_grab_x); 2425 need_to_grab_x);
2453 if (domask) 2426 UPDATE_FLAG(im->flags, F_HAS_ALPHA, domask);
2454 SET_FLAG(im->flags, F_HAS_ALPHA);
2455 else
2456 UNSET_FLAG(im->flags, F_HAS_ALPHA);
2457 2427
2458 if (mgc) 2428 if (mgc)
2459 XFreeGC(ctx->display, mgc); 2429 XFreeGC(ctx->display, mgc);
diff --git a/src/lib/image.h b/src/lib/image.h
index dd1ed8c..c473365 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -171,6 +171,8 @@ int __imlib_CurrentCacheSize(void);
171 171
172#define SET_FLAG(flags, f) ((flags) |= (f)) 172#define SET_FLAG(flags, f) ((flags) |= (f))
173#define UNSET_FLAG(flags, f) ((flags) &= (~f)) 173#define UNSET_FLAG(flags, f) ((flags) &= (~f))
174#define UPDATE_FLAG(flags, f, set) \
175 do { if (set) SET_FLAG(flags, f); else UNSET_FLAG(flags, f); } while(0)
174 176
175#define LOAD_FAIL 0 177#define LOAD_FAIL 0
176#define LOAD_SUCCESS 1 178#define LOAD_SUCCESS 1
diff --git a/src/modules/loaders/loader_argb.c b/src/modules/loaders/loader_argb.c
index 913ce83..fb326d9 100644
--- a/src/modules/loaders/loader_argb.c
+++ b/src/modules/loaders/loader_argb.c
@@ -70,10 +70,7 @@ load2(ImlibImage * im, int load_data)
70 if (!IMAGE_DIMENSIONS_OK(im->w, im->h)) 70 if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
71 goto quit; 71 goto quit;
72 72
73 if (alpha) 73 UPDATE_FLAG(im->flags, F_HAS_ALPHA, alpha);
74 SET_FLAG(im->flags, F_HAS_ALPHA);
75 else
76 UNSET_FLAG(im->flags, F_HAS_ALPHA);
77 74
78 if (!load_data) 75 if (!load_data)
79 { 76 {
diff --git a/src/modules/loaders/loader_bmp.c b/src/modules/loaders/loader_bmp.c
index 14a3a7d..8f6f2ee 100644
--- a/src/modules/loaders/loader_bmp.c
+++ b/src/modules/loaders/loader_bmp.c
@@ -220,8 +220,6 @@ load2(ImlibImage * im, int load_data)
220 ashift1 = rshift1 = gshift1 = bshift1 = 0; 220 ashift1 = rshift1 = gshift1 = bshift1 = 0;
221 ashift2 = rshift2 = gshift2 = bshift2 = 1; 221 ashift2 = rshift2 = gshift2 = bshift2 = 1;
222 222
223 UNSET_FLAG(im->flags, F_HAS_ALPHA);
224
225 if (bih.header_size == 12) 223 if (bih.header_size == 12)
226 { 224 {
227 w = SWAP_LE_16(bih.bch.width); 225 w = SWAP_LE_16(bih.bch.width);
@@ -251,8 +249,6 @@ load2(ImlibImage * im, int load_data)
251 gmask = SWAP_LE_32(bih.bih.mask_g); 249 gmask = SWAP_LE_32(bih.bih.mask_g);
252 bmask = SWAP_LE_32(bih.bih.mask_b); 250 bmask = SWAP_LE_32(bih.bih.mask_b);
253 amask = SWAP_LE_32(bih.bih.mask_a); 251 amask = SWAP_LE_32(bih.bih.mask_a);
254 if (amask)
255 SET_FLAG(im->flags, F_HAS_ALPHA);
256 } 252 }
257 } 253 }
258 else 254 else
@@ -260,6 +256,8 @@ load2(ImlibImage * im, int load_data)
260 goto quit; 256 goto quit;
261 } 257 }
262 258
259 UPDATE_FLAG(im->flags, F_HAS_ALPHA, amask);
260
263 imgsize = size - bfh_offset; 261 imgsize = size - bfh_offset;
264 D("w=%3d h=%3d bitcount=%d comp=%d imgsize=%d\n", 262 D("w=%3d h=%3d bitcount=%d comp=%d imgsize=%d\n",
265 w, h, bitcount, comp, imgsize); 263 w, h, bitcount, comp, imgsize);
diff --git a/src/modules/loaders/loader_gif.c b/src/modules/loaders/loader_gif.c
index cc8baa7..7002417 100644
--- a/src/modules/loaders/loader_gif.c
+++ b/src/modules/loaders/loader_gif.c
@@ -104,10 +104,7 @@ load2(ImlibImage * im, int load_data)
104 } 104 }
105 while (rec != TERMINATE_RECORD_TYPE); 105 while (rec != TERMINATE_RECORD_TYPE);
106 106
107 if (transp >= 0) 107 UPDATE_FLAG(im->flags, F_HAS_ALPHA, transp >= 0);
108 SET_FLAG(im->flags, F_HAS_ALPHA);
109 else
110 UNSET_FLAG(im->flags, F_HAS_ALPHA);
111 108
112 if (!rows) 109 if (!rows)
113 goto quit; 110 goto quit;
diff --git a/src/modules/loaders/loader_lbm.c b/src/modules/loaders/loader_lbm.c
index 752b344..ae96d38 100644
--- a/src/modules/loaders/loader_lbm.c
+++ b/src/modules/loaders/loader_lbm.c
@@ -486,10 +486,7 @@ load2(ImlibImage * im, int load_data)
486 486
487 ilbm.mask = ilbm.bmhd.data[9]; 487 ilbm.mask = ilbm.bmhd.data[9];
488 488
489 if (ilbm.mask || ilbm.depth == 32) 489 UPDATE_FLAG(im->flags, F_HAS_ALPHA, ilbm.mask || ilbm.depth == 32);
490 SET_FLAG(im->flags, F_HAS_ALPHA);
491 else
492 UNSET_FLAG(im->flags, F_HAS_ALPHA);
493 490
494 env = getenv("IMLIB2_LBM_NOMASK"); 491 env = getenv("IMLIB2_LBM_NOMASK");
495 if (env 492 if (env
diff --git a/src/modules/loaders/loader_png.c b/src/modules/loaders/loader_png.c
index d8fd3a4..de9d103 100644
--- a/src/modules/loaders/loader_png.c
+++ b/src/modules/loaders/loader_png.c
@@ -82,10 +82,7 @@ load2(ImlibImage * im, int load_data)
82 hasa = 1; 82 hasa = 1;
83 if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 83 if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
84 hasa = 1; 84 hasa = 1;
85 if (hasa) 85 UPDATE_FLAG(im->flags, F_HAS_ALPHA, hasa);
86 SET_FLAG(im->flags, F_HAS_ALPHA);
87 else
88 UNSET_FLAG(im->flags, F_HAS_ALPHA);
89 86
90 if (!load_data) 87 if (!load_data)
91 { 88 {
diff --git a/src/modules/loaders/loader_pnm.c b/src/modules/loaders/loader_pnm.c
index b78228a..8dab889 100644
--- a/src/modules/loaders/loader_pnm.c
+++ b/src/modules/loaders/loader_pnm.c
@@ -168,10 +168,7 @@ load2(ImlibImage * im, int load_data)
168 if (!IMAGE_DIMENSIONS_OK(w, h)) 168 if (!IMAGE_DIMENSIONS_OK(w, h))
169 goto quit; 169 goto quit;
170 170
171 if (p == '8') 171 UPDATE_FLAG(im->flags, F_HAS_ALPHA, p == '8');
172 SET_FLAG(im->flags, F_HAS_ALPHA);
173 else
174 UNSET_FLAG(im->flags, F_HAS_ALPHA);
175 172
176 if (!load_data) 173 if (!load_data)
177 { 174 {
diff --git a/src/modules/loaders/loader_tga.c b/src/modules/loaders/loader_tga.c
index 6780598..c74d17f 100644
--- a/src/modules/loaders/loader_tga.c
+++ b/src/modules/loaders/loader_tga.c
@@ -284,10 +284,7 @@ load2(ImlibImage * im, int load_data)
284 if (!IMAGE_DIMENSIONS_OK(im->w, im->h)) 284 if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
285 goto quit; 285 goto quit;
286 286
287 if (hasa) 287 UPDATE_FLAG(im->flags, F_HAS_ALPHA, hasa);
288 SET_FLAG(im->flags, F_HAS_ALPHA);
289 else
290 UNSET_FLAG(im->flags, F_HAS_ALPHA);
291 288
292 if (!load_data) 289 if (!load_data)
293 { 290 {
diff --git a/src/modules/loaders/loader_tiff.c b/src/modules/loaders/loader_tiff.c
index fa0e745..0b25ca0 100644
--- a/src/modules/loaders/loader_tiff.c
+++ b/src/modules/loaders/loader_tiff.c
@@ -311,10 +311,8 @@ load2(ImlibImage * im, int load_data)
311 if (!IMAGE_DIMENSIONS_OK(im->w, im->h)) 311 if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
312 goto quit; 312 goto quit;
313 313
314 if (rgba_image.rgba.alpha != EXTRASAMPLE_UNSPECIFIED) 314 UPDATE_FLAG(im->flags, F_HAS_ALPHA,
315 SET_FLAG(im->flags, F_HAS_ALPHA); 315 rgba_image.rgba.alpha != EXTRASAMPLE_UNSPECIFIED);
316 else
317 UNSET_FLAG(im->flags, F_HAS_ALPHA);
318 316
319 if (!load_data) 317 if (!load_data)
320 { 318 {
diff --git a/src/modules/loaders/loader_webp.c b/src/modules/loaders/loader_webp.c
index 12986dc..d8a0b30 100644
--- a/src/modules/loaders/loader_webp.c
+++ b/src/modules/loaders/loader_webp.c
@@ -59,10 +59,7 @@ load2(ImlibImage * im, int load_data)
59 if (!IMAGE_DIMENSIONS_OK(im->w, im->h)) 59 if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
60 goto quit; 60 goto quit;
61 61
62 if (features.has_alpha == 0) 62 UPDATE_FLAG(im->flags, F_HAS_ALPHA, features.has_alpha);
63 UNSET_FLAG(im->flags, F_HAS_ALPHA);
64 else
65 SET_FLAG(im->flags, F_HAS_ALPHA);
66 63
67 if (!load_data) 64 if (!load_data)
68 { 65 {
diff --git a/src/modules/loaders/loader_xpm.c b/src/modules/loaders/loader_xpm.c
index d58de83..ccadf7b 100644
--- a/src/modules/loaders/loader_xpm.c
+++ b/src/modules/loaders/loader_xpm.c
@@ -360,10 +360,7 @@ load2(ImlibImage * im, int load_data)
360 qsort(cmap, ncolors, sizeof(cmap_t), xpm_cmap_sort); 360 qsort(cmap, ncolors, sizeof(cmap_t), xpm_cmap_sort);
361 context++; 361 context++;
362 362
363 if (transp >= 0) 363 UPDATE_FLAG(im->flags, F_HAS_ALPHA, transp >= 0);
364 SET_FLAG(im->flags, F_HAS_ALPHA);
365 else
366 UNSET_FLAG(im->flags, F_HAS_ALPHA);
367 364
368 if (!load_data) 365 if (!load_data)
369 { 366 {