Decompile fn_01905 (DeviceOwnerDX7::CalibrateTextureCoordinates)

Batch #15595 by Yommy: 0 byte-identical, 1 confirmed by peer review.

- fn_01905 DeviceOwnerDX7::CalibrateTextureCoordinates: logic confirmed by peer review

Peer-reviewed-by: eAthena, bgamez23
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
This commit is contained in:
ragnarok-clanker 2026-11-10 12:12:16 +00:00
commit a91ee384ce

View file

@ -30,7 +30,7 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() {
const unsigned columns = this->width >> 2;
const unsigned capacity = columns * (this->height >> 2);
int bestScore = -1024;
unsigned best = 32896;
int best = 32896;
unsigned first = 0;
do {
@ -40,10 +40,14 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() {
return false;
}
for (unsigned index = 0; index < capacity && first + index <= 65535; ++index) {
const unsigned candidate = first + index;
const float x = static_cast<float>(4 * (index % columns));
const float y = static_cast<float>(4 * (index / columns));
for (unsigned index = 0; index < capacity; ++index) {
const int candidate = first + index;
if (candidate > 65535) {
break;
}
const int left = 4 * (index % columns);
const int top = 4 * (index / columns);
const float offsetX = static_cast<float>(candidate % 256) * (1.0f / 256.0f);
const float offsetY = static_cast<float>(candidate / 256) * (1.0f / 256.0f);
const float u0 = (offsetX + 0.0f) / static_cast<float>(texture.TextureWidth());
@ -53,10 +57,10 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() {
constexpr float z = 0.00001f;
constexpr float rhw = 0.99999f;
RenderVertex vertices[4] = {
{x, y, z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u0, v0},
{x, y + 4, z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u0, v1},
{x + 4, y, z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u1, v0},
{x + 4, y + 4, z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u1, v1}
{static_cast<float>(left), static_cast<float>(top), z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u0, v0},
{static_cast<float>(left), static_cast<float>(top + 4), z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u0, v1},
{static_cast<float>(left + 4), static_cast<float>(top), z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u1, v0},
{static_cast<float>(left + 4), static_cast<float>(top + 4), z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u1, v1}
};
this->device->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, vertices, 4, 0);
}
@ -72,13 +76,18 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() {
const unsigned pixelBytes = locked.ddpfPixelFormat.dwRGBBitCount >> 3;
for (unsigned index = 0; index < capacity && first + index <= 65535; ++index) {
for (unsigned index = 0; index < capacity; ++index) {
const int candidate = first + index;
if (candidate > 65535) {
break;
}
const unsigned x = 4 * (index % columns);
const unsigned y = 4 * (index / columns);
unsigned dark = 0;
unsigned bright = 0;
int dark = 0;
int bright = 0;
for (unsigned sample = 0; sample < 16; ++sample) {
for (int sample = 0; sample < 16; ++sample) {
const auto* source = static_cast<const unsigned char*>(locked.lpSurface) + (y + sample / 4) * locked.lPitch + (x + sample % 4) * pixelBytes;
unsigned pixel;
@ -91,7 +100,7 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() {
}
pixel = static_cast<std::uint16_t>(pixel);
const unsigned value =
const int value =
Component(pixel, this->greenMask, this->green) + Component(pixel, this->blueMask, this->blue) + Component(pixel, this->redMask, this->red);
if (pattern[sample] == 0) {
@ -101,13 +110,9 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() {
}
}
const int lightScore = std::bit_cast<int>(bright);
const int darkScore = std::bit_cast<int>(dark);
const int difference = std::bit_cast<int>(bright - dark);
if (lightScore >= 5760 && darkScore <= 384 && difference > bestScore) {
bestScore = difference;
best = first + index;
if (bright >= 5760 && dark <= 384 && bright - dark > bestScore) {
bestScore = bright - dark;
best = candidate;
}
}