rodecomp/Source/Render/DeviceContext/DCBitmap.cpp
ragnarok-clanker 25b5e75513 Decompile 10 functions in Source/Render/Textures/BitmapPixels.cpp, Source/Render/Textures/BitmapPixels.h, ...
Batch #16419 by Yommy: 4 byte-identical, 6 confirmed by peer review.

- fn_01847 CDCBitmap::UploadTexture: logic confirmed by peer review
- fn_01850 CDCBitmap::Grow: byte-identical
- fn_01848 CDCBitmap::GetDC: byte-identical
- fn_01849 CDCBitmap::ReleaseDC: byte-identical
- fn_01841 CDCBitmap::Fill: byte-identical
- fn_01852 CDCBitmap::Copy: logic confirmed by peer review
- fn_01843 CDCBitmap::CopyFrom: logic confirmed by peer review
- fn_01844 CDCBitmap::BlendFrom: logic confirmed by peer review
- fn_01857 CDCBitmap::Brighten: logic confirmed by peer review
- fn_01851 CDCBitmap::ScaleCopy: logic confirmed by peer review

Peer-reviewed-by: youko, kyoshi, gordaoprogramas, cremane, codeplay, Tanke
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-10 19:12:14 +00:00

52 lines
1.9 KiB
C++

#include "Render/DeviceContext/DCBitmap.h"
// OFFSET: 0x00545790
// FUNCTION: fn_01832
CDCBitmap::CDCBitmap(int width, int height) : m_bitmap(width, height) {
}
CDCBitmap::~CDCBitmap() = default;
// OFFSET: 0x00569E90
// FUNCTION: fn_02273
CDCBitmap* CreateBitmapDC(int width, int height, bool fill) {
CDCBitmap* bitmap = new CDCBitmap(width, height);
if (fill) {
bitmap->Fill(nullptr, 0xFFFF00FFu);
}
return bitmap;
}
// OFFSET: 0x005482D0
// FUNCTION: fn_01853
void CDCBitmap::SetAlpha(unsigned char maxLuminance) {
for (std::uint32_t y = 0; y < this->m_bitmap.height; ++y) {
for (std::uint32_t x = 0; x < this->m_bitmap.width; ++x) {
const std::uint32_t index = y * this->m_bitmap.width + x;
std::uint32_t pixel = this->m_bitmap.pixels[index];
const unsigned char r = pixel & 0xFF;
const unsigned char g = (pixel >> 8) & 0xFF;
const unsigned char b = (pixel >> 16) & 0xFF;
const unsigned char avg = static_cast<unsigned char>((r + g + b) / 3);
const unsigned char alpha = static_cast<unsigned char>((static_cast<float>(avg) / static_cast<float>(maxLuminance)) * 255.0f);
reinterpret_cast<unsigned char*>(&pixel)[3] = alpha;
this->m_bitmap.pixels[index] = pixel;
}
}
}
void CDCBitmap::CopyRegion(
int x, int y, int sourceLeft, int sourceTop, int sourceRight, int sourceBottom, const std::uint32_t* source, int sourceWidth, int sourceHeight,
bool transparent, bool alpha
) {
this->m_bitmap.CopyRegion(x, y, sourceLeft, sourceTop, sourceRight, sourceBottom, source, sourceWidth, sourceHeight, transparent, alpha);
}
void CDCBitmap::Draw(CRenderSystemBase& system, int x, int y, int width, int height, std::uint32_t color) {
this->m_cache.Draw(this->m_bitmap, system, x, y, width, height, color);
}
void CDCBitmap::Dim(int x, int y, int width, int height, int percent) {
this->m_bitmap.Dim(x, y, width, height, percent);
}