isle-portable/LEGO1/lego/sources/misc/legoimage.h
foxtacles fdbe9a8705
Some checks are pending
CI / clang-format (push) Waiting to run
CI / ${{ matrix.name }} (false, --toolchain $GITHUB_WORKSPACE/CMake/i586-pc-msdosdjgpp.cmake, false, true, false, Ninja, DOS, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, --toolchain /usr/local/vitasdk/share/vita.toolchain.cmake, false, false, Ninja, Vita, ubuntu-latest, true, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.26100.0, false, false, Visual Studio 18 2026, true, Xbox One, windows-latest, amd64, false, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake, false, devkitpro/devkitarm:latest, false, Ninja, true, Nintendo 3DS, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake, false, devkitpro/devkita64:latest, false, Ninja, Nintendo Switch, true, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, emcmake, false, false, true, Ninja, Emscripten, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, false, Ninja, true, MSVC (arm64), windows-latest, amd64_arm64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, true, Ninja, true, MSVC (x86), windows-latest, amd64_x86, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, false, Ninja, true, MSVC (x64), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, true, false, Ninja, true, MSVC (x64 Debug), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, -DCMAKE_SYSTEM_NAME=iOS, false, false, Xcode, true, iOS, macos-15, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, false, false, Ninja, Android, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, true, false, Ninja, macOS, macos-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, false, Ninja, true, mingw-w64-x86_64, mingw64, msys2 mingw64, windows-latest, msys2 {0}, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux (Debug), ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux, ubuntu-latest, true) (push) Waiting to run
CI / FreeBSD (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (aarch64, ubuntu-22.04-arm) (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (x86_64, ubuntu-latest) (push) Waiting to run
CI / C++ (push) Waiting to run
CI / Release (push) Blocked by required conditions
Docker / Publish web port (push) Waiting to run
Rescale save-loaded textures to runtime texture dimensions (#805)
* Rescale save-loaded textures to runtime texture dimensions

`LegoTextureInfo::LoadBits` sized its memcpy from the destination
DirectDraw surface and assumed the source bits matched. They don't
when the save was made under a different renderer than the current
one: HW mode squares non-square assets in `LegoImage::Read` (e.g.
128x32 -> 128x128 via row duplication), SW mode keeps the original
dimensions, and `ReadNamedTexture` always loads with `p_square=0`,
so saved bits keep whatever size they had at save time. SW save
loaded under HW caused an OOB read in `LoadBits`; HW save loaded
under SW silently truncated the source and rendered a distorted
texture.

Add `LegoImage::Resize(width, height)` (nearest-neighbor, handles
both up- and down-scale) and call it in `LoadFromNamedTexture` to
match the runtime `LegoTextureInfo` surface dimensions before
binding. Save format unchanged; `LoadBits` signature unchanged.
Square textures and matching-mode loads short-circuit on the
fast-path.

* ci: bump Android SDL3 download + Xbox One generator for VS 18

- Android: SDL3's `build-release.py` started requiring `download`
  before `android` so it can fetch the new gameinput dependency.
  (build-release.py is technically internal SDL tooling; longer-term
  we may want to invoke a different SDL3 build entry point.)

- Xbox One: windows-latest now ships VS 18, so the
  `Visual Studio 17 2022` generator can no longer find a VS install.
  Bump to `Visual Studio 18 2026`.
2026-05-15 01:45:40 +00:00

63 lines
1.8 KiB
C++

#ifndef __LEGOIMAGE_H
#define __LEGOIMAGE_H
#include "legotypes.h"
#include <SDL3/SDL_surface.h>
class LegoStorage;
// SIZE 0x03
class LegoPaletteEntry {
public:
LegoPaletteEntry();
// LegoPaletteEntry(LegoU8 p_red, LegoU8 p_green, LegoU8 p_blue);
LegoU8 GetRed() const { return m_color.r; }
void SetRed(LegoU8 p_red) { m_color.r = p_red; }
LegoU8 GetGreen() const { return m_color.g; }
void SetGreen(LegoU8 p_green) { m_color.g = p_green; }
LegoU8 GetBlue() const { return m_color.b; }
void SetBlue(LegoU8 p_blue) { m_color.b = p_blue; }
SDL_Color GetColor() const { return m_color; }
void SetColor(SDL_Color p_color) { m_color = p_color; }
LegoResult Read(LegoStorage* p_storage);
LegoResult Write(LegoStorage* p_storage) const;
protected:
SDL_Color m_color;
};
// 0x310
class LegoImage {
public:
LegoImage();
LegoImage(LegoU32 p_width, LegoU32 p_height);
~LegoImage();
LegoU32 GetWidth() const { return m_surface->w; }
LegoU32 GetHeight() const { return m_surface->h; }
LegoU32 GetCount() const { return m_palette ? m_palette->ncolors : 0; }
SDL_Palette* GetPalette() const { return m_palette; }
void SetPalette(SDL_Palette* p_palette)
{
SDL_DestroyPalette(m_palette);
m_palette = p_palette;
}
void SetPaletteEntry(LegoU32 p_i, LegoPaletteEntry& p_paletteEntry)
{
m_palette->colors[p_i] = p_paletteEntry.GetColor();
}
LegoU8* GetBits() const { return (LegoU8*) m_surface->pixels; }
LegoResult Read(LegoStorage* p_storage, LegoU32 p_square);
LegoResult Write(LegoStorage* p_storage);
LegoResult Resize(LegoU32 p_width, LegoU32 p_height);
protected:
SDL_Surface* m_surface;
SDL_Palette* m_palette;
// LegoU32 m_count; // 0x08
// LegoPaletteEntry m_palette[256]; // 0x0c
// LegoU8* m_bits; // 0x30c
};
#endif // __LEGOIMAGE_H