@@ -21,6 +21,26 @@ struct plum_rectangle * get_frame_boundaries (struct context * context, bool anc
21
21
22
22
void adjust_frame_boundaries (const struct plum_image * image , struct plum_rectangle * restrict boundaries ) {
23
23
uint64_t empty_color = get_empty_color (image );
24
+ #define checkframe (type ) do \
25
+ for (uint_fast32_t frame = 0; frame < image -> frames; frame ++) { \
26
+ for (size_t remaining = (size_t) boundaries[frame].top * image -> width; remaining; remaining --) \
27
+ if (notempty(type)) goto done ## type; \
28
+ if (boundaries[frame].left || boundaries[frame].width != image -> width) \
29
+ for (uint_fast32_t row = 0; row < boundaries[frame].height; row ++) { \
30
+ for (uint_fast32_t col = 0; col < boundaries[frame].left; col ++) if (notempty(type)) goto done ## type; \
31
+ index += boundaries[frame].width; \
32
+ for (uint_fast32_t col = boundaries[frame].left + boundaries[frame].width; col < image -> width; col ++) \
33
+ if (notempty(type)) goto done ## type; \
34
+ } \
35
+ else \
36
+ index += (size_t) boundaries[frame].height * image -> width; \
37
+ for (size_t remaining = (size_t) (image -> height - boundaries[frame].top - boundaries[frame].height) * image -> width; remaining; remaining --) \
38
+ if (notempty(type)) goto done ## type; \
39
+ continue; \
40
+ done ## type: \
41
+ boundaries[frame] = (struct plum_rectangle) {.left = 0, .top = 0, .width = image -> width, .height = image -> height}; \
42
+ } \
43
+ while (false)
24
44
if (image -> palette ) {
25
45
bool empty [256 ];
26
46
switch (image -> color_format & PLUM_COLOR_MASK ) {
@@ -34,55 +54,20 @@ void adjust_frame_boundaries (const struct plum_image * image, struct plum_recta
34
54
for (size_t p = 0 ; p <= image -> max_palette_index ; p ++ ) empty [p ] = image -> palette32 [p ] == empty_color ;
35
55
}
36
56
size_t index = 0 ;
37
- for (uint_fast32_t frame = 0 ; frame < image -> frames ; frame ++ ) {
38
- bool adjust = true;
39
- for (size_t remaining = (size_t ) boundaries [frame ].top * image -> width ; remaining ; remaining -- )
40
- if (!empty [image -> data8 [index ++ ]]) goto paldone ;
41
- if (boundaries [frame ].left || boundaries [frame ].width != image -> width )
42
- for (uint_fast32_t row = 0 ; row < boundaries [frame ].height ; row ++ ) {
43
- for (uint_fast32_t col = 0 ; col < boundaries [frame ].left ; col ++ ) if (!empty [image -> data8 [index ++ ]]) goto paldone ;
44
- index += boundaries [frame ].width ;
45
- for (uint_fast32_t col = boundaries [frame ].left + boundaries [frame ].width ; col < image -> width ; col ++ )
46
- if (!empty [image -> data8 [index ++ ]]) goto paldone ;
47
- }
48
- else
49
- index += (size_t ) boundaries [frame ].height * image -> width ;
50
- for (size_t remaining = (size_t ) (image -> height - boundaries [frame ].top - boundaries [frame ].height ) * image -> width ; remaining ; remaining -- )
51
- if (!empty [image -> data8 [index ++ ]]) goto paldone ;
52
- adjust = false;
53
- paldone :
54
- if (adjust ) boundaries [frame ] = (struct plum_rectangle ) {.left = 0 , .top = 0 , .width = image -> width , .height = image -> height };
55
- }
57
+ #define notempty (...) (!empty[image -> data8[index ++]])
58
+ checkframe (pal );
56
59
} else {
57
60
size_t index = 0 ;
58
- #define checkframe (bits ) do \
59
- for (uint_fast32_t frame = 0; frame < image -> frames; frame ++) { \
60
- bool adjust = true; \
61
- for (size_t remaining = (size_t) boundaries[frame].top * image -> width; remaining; remaining --) \
62
- if (image -> data ## bits[index ++] != empty_color) goto done ## bits; \
63
- if (boundaries[frame].left || boundaries[frame].width != image -> width) \
64
- for (uint_fast32_t row = 0; row < boundaries[frame].height; row ++) { \
65
- for (uint_fast32_t col = 0; col < boundaries[frame].left; col ++) if (image -> data ## bits[index ++] != empty_color) goto done ## bits; \
66
- index += boundaries[frame].width; \
67
- for (uint_fast32_t col = boundaries[frame].left + boundaries[frame].width; col < image -> width; col ++) \
68
- if (image -> data ## bits[index ++] != empty_color) goto done ## bits; \
69
- } \
70
- else \
71
- index += (size_t) boundaries[frame].height * image -> width; \
72
- for (size_t remaining = (size_t) (image -> height - boundaries[frame].top - boundaries[frame].height) * image -> width; remaining; remaining --) \
73
- if (image -> data ## bits[index ++] != empty_color) goto done ## bits; \
74
- adjust = false; \
75
- done ## bits: \
76
- if (adjust) boundaries[frame] = (struct plum_rectangle) {.left = 0, .top = 0, .width = image -> width, .height = image -> height}; \
77
- } \
78
- while (false)
61
+ #undef notempty
62
+ #define notempty (bits ) (image -> data ## bits[index ++] != empty_color)
79
63
switch (image -> color_format & PLUM_COLOR_MASK ) {
80
64
case PLUM_COLOR_16 : checkframe (16 ); break ;
81
65
case PLUM_COLOR_64 : checkframe (64 ); break ;
82
66
default : checkframe (32 );
83
67
}
84
- #undef checkframe
85
68
}
69
+ #undef notempty
70
+ #undef checkframe
86
71
}
87
72
88
73
bool image_rectangles_have_transparency (const struct plum_image * image , const struct plum_rectangle * rectangles ) {
0 commit comments