From 07d3bf60862ddbb29a5e21084cf3467302bf09d2 Mon Sep 17 00:00:00 2001 From: Rupert Date: Sat, 31 May 2025 13:14:23 +0200 Subject: [PATCH] OS/2 icons/pointers: refactor boolean flags one icon flag and and mono flag instead of two color-icon/mono-icon flags --- bmp-common.h | 4 ++-- bmp-read-loadimage.c | 4 ++-- bmp-read.c | 15 ++++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bmp-common.h b/bmp-common.h index cb11722..0543784 100644 --- a/bmp-common.h +++ b/bmp-common.h @@ -119,8 +119,8 @@ struct Bmpread { int width; int height; enum BmpOrient orientation; - bool is_color_icon; - bool is_mono_icon; + bool is_icon; + bool icon_is_mono; bool has_alpha; /* original BMP has alpha channel */ enum BmpUndefined undefined_mode; bool we_allocated_buffer; diff --git a/bmp-read-loadimage.c b/bmp-read-loadimage.c index 6a97a7f..f32acdd 100644 --- a/bmp-read-loadimage.c +++ b/bmp-read-loadimage.c @@ -277,7 +277,7 @@ static void s_read_one_line(BMPREAD_R rp, unsigned char *restrict line) } else { if (rp->ih->compression == BI_OS2_HUFFMAN) { s_read_huffman_line(rp, line); - } else if (rp->is_mono_icon) { + } else if (rp->is_icon && rp->icon_is_mono) { s_read_monoicon_line(rp, line, rp->lbl_y); } else { s_read_indexed_line(rp, line); @@ -298,7 +298,7 @@ static void s_read_one_line(BMPREAD_R rp, unsigned char *restrict line) s_read_rgb_line(rp, line); } - if (rp->is_color_icon || rp->is_mono_icon) { + if (rp->is_icon) { apply_icon_alpha(rp, rp->lbl_y, line); } diff --git a/bmp-read.c b/bmp-read.c index 9e19881..8e6651f 100644 --- a/bmp-read.c +++ b/bmp-read.c @@ -141,10 +141,11 @@ API BMPRESULT bmpread_load_info(BMPHANDLE h) goto abort; } + rp->is_icon = true; if (type == BMPFILE_CI || type == BMPFILE_CP) - rp->is_color_icon = true; + rp->icon_is_mono = false; else - rp->is_mono_icon = true; + rp->icon_is_mono = true; } /* otherwise we read the AND/XOR masks as a normal image */ @@ -184,7 +185,7 @@ API BMPRESULT bmpread_load_info(BMPHANDLE h) /* negative height flips the image vertically */ if (rp->ih->height < 0) { - if (rp->is_color_icon || rp->is_mono_icon) { + if (rp->is_icon) { logerr(rp->c.log, "Top-down orientation incompatible with icons/pointers"); rp->lasterr = BMP_ERR_HEADER; goto abort; @@ -200,7 +201,7 @@ API BMPRESULT bmpread_load_info(BMPHANDLE h) rp->height = rp->ih->height; } - if (rp->is_mono_icon) + if (rp->is_icon && rp->icon_is_mono) rp->height /= 2; if (rp->ih->compression == BI_RLE4 || @@ -248,7 +249,7 @@ API BMPRESULT bmpread_load_info(BMPHANDLE h) if (rp->rle) { rp->result_channels = (rp->undefined_mode == BMP_UNDEFINED_TO_ALPHA) ? 4 : 3; } - if (rp->is_color_icon || rp->is_mono_icon) + if (rp->is_icon) rp->result_channels = 4; if (!br_set_resultbits(rp)) @@ -532,7 +533,7 @@ BMPRESULT br_set_number_format(BMPREAD_R rp, enum BmpFormat format) rp->lasterr = BMP_ERR_FORMAT; return BMP_RESULT_ERROR; } - if (rp->is_color_icon || rp->is_mono_icon) { + if (rp->is_icon) { logerr(rp->c.log, "Cannot load icons/pointers as float or s2.13"); rp->lasterr = BMP_ERR_FORMAT; return BMP_RESULT_ERROR; @@ -795,7 +796,7 @@ static bool s_is_bmptype_supported(BMPREAD_R rp) return false; } - if (rp->is_color_icon || rp->is_mono_icon) { + if (rp->is_icon) { if (rp->ih->compression != BI_RGB) { logerr(rp->c.log, "Unsupported compression %s for icon/pointer", s_compression_name(rp->ih->compression));