1#ifndef YAZE_APP_EDITOR_OVERWORLD_PAINTING_TILE_BRUSH_PREVIEW_H_
2#define YAZE_APP_EDITOR_OVERWORLD_PAINTING_TILE_BRUSH_PREVIEW_H_
24 int anchor_x,
int anchor_y,
26 std::span<const uint8_t> atlas,
27 int atlas_width = 128) {
29 if (!brush.
valid() || atlas_width < 16 || atlas_width % 16 != 0)
31 const int left = std::max(anchor_x, map_x * 32);
32 const int top = std::max(anchor_y, map_y * 32);
33 const int right = std::min(anchor_x + brush.
width, (map_x + 1) * 32);
34 const int bottom = std::min(anchor_y + brush.
height, (map_y + 1) * 32);
35 if (right <= left || bottom <= top)
39 result.
width = (right - left) * 16;
40 result.
height = (bottom - top) * 16;
42 const int columns = atlas_width / 16;
43 for (
int y = top; y < bottom; ++y) {
44 for (
int x = left; x < right; ++x) {
45 const int id = brush.
at(x - anchor_x, y - anchor_y);
47 (
id / columns * 16) * atlas_width + (
id % columns * 16);
48 if (source + 15 * atlas_width + 16 > atlas.size())
50 for (
int row = 0; row < 16; ++row) {
51 std::copy_n(atlas.begin() + source + row * atlas_width, 16,
53 ((y - top) * 16 + row) * result.
width +
67 constexpr int kTextureExtent = 32 * 16;
69 piece.
height > kTextureExtent ||
73 std::vector<uint8_t> pixels(kTextureExtent * kTextureExtent, 0);
74 for (
int y = 0; y < piece.
height; ++y) {
76 pixels.begin() + y * kTextureExtent);
78 const bool pixels_changed =
80 const bool palette_changed = !(preview.
palette() == palette);
82 preview.
Create(kTextureExtent, kTextureExtent, 8, pixels);
84 if (pixels_changed || palette_changed)
88 else if (pixels_changed || palette_changed)
95 std::span<const uint8_t> atlas,
int tile_id,
int atlas_width = 128) {
96 if (tile_id < 0 || atlas_width < 16 || atlas_width % 16 != 0)
98 const int columns = atlas_width / 16;
100 static_cast<size_t>(tile_id / columns * 16) * atlas_width +
101 (tile_id % columns * 16);
102 if (source + 15 *
static_cast<size_t>(atlas_width) + 16 > atlas.size())
104 std::vector<uint8_t> pixels(16 * 16);
105 for (
int row = 0; row < 16; ++row) {
106 std::copy_n(atlas.begin() + source + row * atlas_width, 16,
107 pixels.begin() + row * 16);
Represents a bitmap image optimized for SNES ROM hacking.
const SnesPalette & palette() const
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.
TextureHandle texture() const
const std::vector< uint8_t > & vector() const
void CreateTexture()
Creates the underlying SDL_Texture to be displayed.
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap using SNES palette format.
void UpdateTexture()
Updates the underlying SDL_Texture when it already exists.
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Editors are the view controllers for the application.
MapBrushPreview BuildMapBrushPreview(const TileBrush &brush, int anchor_x, int anchor_y, int map_x, int map_y, std::span< const uint8_t > atlas, int atlas_width=128)
void SyncMapBrushPreview(const MapBrushPreview &piece, const gfx::SnesPalette &palette, gfx::Bitmap &preview)
std::vector< uint8_t > Tile16PixelsFromBlockset(std::span< const uint8_t > atlas, int tile_id, int atlas_width=128)
std::vector< uint8_t > pixels
int at(int x, int y) const