From 4ddd7f1c6f2be5d8cf2fd2db1368ec1b627a266a Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Tue, 10 Nov 2026 11:21:05 +0000 Subject: [PATCH] Decompile fn_07871 (BitmapImage::DecodeJpeg) Batch #15786 by Yommy: 0 byte-identical, 1 confirmed by peer review. - fn_07871 BitmapImage::DecodeJpeg: logic confirmed by peer review Peer-reviewed-by: eAthena, Tanke Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Resource/Bitmap/BitmapImageJpeg.cpp | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Source/Resource/Bitmap/BitmapImageJpeg.cpp b/Source/Resource/Bitmap/BitmapImageJpeg.cpp index af608df5c..882aaa17b 100644 --- a/Source/Resource/Bitmap/BitmapImageJpeg.cpp +++ b/Source/Resource/Bitmap/BitmapImageJpeg.cpp @@ -11,16 +11,15 @@ bool BitmapImage::DecodeJpeg(const void* data, int bytes) { return false; } - properties.jpegBytes = const_cast(static_cast(data)); properties.jpegSize = bytes; + properties.jpegBytes = const_cast(static_cast(data)); unsigned char* source; if (ijlRead(&properties, 1) == 0) { this->width = properties.jpegWidth; this->height = properties.jpegHeight; - const std::uint32_t count = static_cast(this->width) * static_cast(this->height); - source = static_cast(std::malloc(count * 3u)); - this->pixels = static_cast(std::malloc(count > 0x3FFFFFFFu ? 0xFFFFFFFFu : count * 4u)); + source = new unsigned char[properties.jpegHeight * properties.jpegWidth * 3]; + this->pixels = new std::uint32_t[this->height * this->width]; properties.dibWidth = this->width; properties.dibHeight = this->height; properties.dibBytes = source; @@ -29,8 +28,8 @@ bool BitmapImage::DecodeJpeg(const void* data, int bytes) { properties.dibPadding = 0; if (ijlRead(&properties, 3) != 0) { - std::free(source); - std::free(this->pixels); + delete[] source; + delete[] this->pixels; this->pixels = nullptr; return false; @@ -42,19 +41,22 @@ bool BitmapImage::DecodeJpeg(const void* data, int bytes) { ijlFree(&properties); for (int y = 0; y < this->height; ++y) { - const unsigned char* input = source + 3u * (static_cast(y) * this->width); + std::uint32_t* out = &this->pixels[this->width * y]; + const unsigned char* input = &source[3 * this->width * y]; if (!input) { return false; } - for (int x = 0; x < this->width; ++x, input += 3) { - const unsigned blue = input[0], green = input[1], red = input[2]; - this->pixels[static_cast(y) * this->width + x] = - red >= 254 && green <= 3 && blue >= 254 ? 0x000A0A0Au : blue | (green << 8) | (red << 16) | 0xFF000000u; + for (int x = 0; x < this->width; ++x) { + const unsigned red = input[2]; + const unsigned blue = input[0]; + const unsigned green = input[1]; + *out++ = red >= 254 && green <= 3 && blue >= 254 ? 0x000A0A0Au : (((((0xFFu << 8) + red) << 8) + green) << 8) + blue; + input += 3; } } - std::free(source); + delete[] source; this->alpha = 0; return true; }