From 217406ec420b694b0b7ac6eeb077643292320bcb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 15 Apr 2025 02:07:38 +0000 Subject: [PATCH] Cleanup: move IMB_convert_rgba_to_abgr to a static function This is a fairly specific function and was only used by the IRIS format. --- source/blender/imbuf/IMB_imbuf.hh | 8 ----- source/blender/imbuf/intern/format_iris.cc | 38 +++++++++++++++++++-- source/blender/imbuf/intern/imageprocess.cc | 35 ------------------- 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/source/blender/imbuf/IMB_imbuf.hh b/source/blender/imbuf/IMB_imbuf.hh index c2b66144ef3..ec62c2f88e8 100644 --- a/source/blender/imbuf/IMB_imbuf.hh +++ b/source/blender/imbuf/IMB_imbuf.hh @@ -457,14 +457,6 @@ void IMB_buffer_byte_from_byte(unsigned char *rect_to, int stride_to, int stride_from); -/** - * Change the ordering of the color bytes pointed to by rect from - * RGBA to ABGR. size * 4 color bytes are reordered. - * - * Only this one is used liberally here, and in imbuf. - */ -void IMB_convert_rgba_to_abgr(ImBuf *ibuf); - void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3]); void IMB_alpha_under_color_byte(unsigned char *rect, int x, int y, const float backcol[3]); diff --git a/source/blender/imbuf/intern/format_iris.cc b/source/blender/imbuf/intern/format_iris.cc index f55d474f916..a3b3cf6b397 100644 --- a/source/blender/imbuf/intern/format_iris.cc +++ b/source/blender/imbuf/intern/format_iris.cc @@ -121,6 +121,38 @@ static void interleaverow2(float *lptr, const uchar *cptr, int z, int n); static int compressrow(const uchar *lbuf, uchar *rlebuf, int z, int row_len); static void lumrow(const uchar *rgbptr, uchar *lumptr, int n); +/* -------------------------------------------------------------------- */ +/** \name Internal Image API + * \{ */ + +/** + * Change the ordering of the color bytes pointed to by rect from + * RGBA to ABGR. size * 4 color bytes are reordered. + * + * Only this one is used liberally here, and in imbuf. + */ +static void imbuf_rgba_to_abgr(ImBuf *ibuf) +{ + size_t size; + uchar rt, *cp = ibuf->byte_buffer.data; + + if (ibuf->byte_buffer.data) { + size = IMB_get_pixel_count(ibuf); + + while (size-- > 0) { + rt = cp[0]; + cp[0] = cp[3]; + cp[3] = rt; + rt = cp[1]; + cp[1] = cp[2]; + cp[2] = rt; + cp += 4; + } + } +} + +/** \} */ + /* * byte order independent read/write of shorts and ints. */ @@ -555,7 +587,7 @@ ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, ImFileColorSpace & ibuf->ftype = IMB_FTYPE_IRIS; if (ibuf->byte_buffer.data) { - IMB_convert_rgba_to_abgr(ibuf); + imbuf_rgba_to_abgr(ibuf); } return ibuf; @@ -945,13 +977,13 @@ bool imb_saveiris(ImBuf *ibuf, const char *filepath, int /*flags*/) const short zsize = (ibuf->planes + 7) >> 3; - IMB_convert_rgba_to_abgr(ibuf); + imbuf_rgba_to_abgr(ibuf); const bool ok = output_iris( filepath, (uint *)ibuf->byte_buffer.data, nullptr, ibuf->x, ibuf->y, zsize); /* restore! Quite clumsy, 2 times a switch... maybe better a malloc ? */ - IMB_convert_rgba_to_abgr(ibuf); + imbuf_rgba_to_abgr(ibuf); return ok; } diff --git a/source/blender/imbuf/intern/imageprocess.cc b/source/blender/imbuf/intern/imageprocess.cc index 029daeb23d3..874d617c1b7 100644 --- a/source/blender/imbuf/intern/imageprocess.cc +++ b/source/blender/imbuf/intern/imageprocess.cc @@ -13,41 +13,6 @@ #include "IMB_imbuf.hh" #include "IMB_imbuf_types.hh" -void IMB_convert_rgba_to_abgr(ImBuf *ibuf) -{ - size_t size; - uchar rt, *cp = ibuf->byte_buffer.data; - float rtf, *cpf = ibuf->float_buffer.data; - - if (ibuf->byte_buffer.data) { - size = IMB_get_pixel_count(ibuf); - - while (size-- > 0) { - rt = cp[0]; - cp[0] = cp[3]; - cp[3] = rt; - rt = cp[1]; - cp[1] = cp[2]; - cp[2] = rt; - cp += 4; - } - } - - if (ibuf->float_buffer.data) { - size = IMB_get_pixel_count(ibuf); - - while (size-- > 0) { - rtf = cpf[0]; - cpf[0] = cpf[3]; - cpf[3] = rtf; - rtf = cpf[1]; - cpf[1] = cpf[2]; - cpf[2] = rtf; - cpf += 4; - } - } -} - /* -------------------------------------------------------------------- */ /** \name Alpha-under * \{ */