yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
terrain_graphics.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_OVERWORLD_TERRAIN_GRAPHICS_H_
2#define YAZE_ZELDA3_OVERWORLD_TERRAIN_GRAPHICS_H_
3
4#include <array>
5#include <cstdint>
6#include <vector>
7
8#include "absl/status/statusor.h"
9
10namespace yaze::zelda3 {
11
12// Read decoded source pixels before ProcessGraphicsBuffer's palette remapping.
13// A preview index of 8 alone cannot distinguish source zero from opaque color 8.
14inline absl::StatusOr<std::array<uint8_t, 64>> Tile8SourceTransparency(
15 const std::vector<uint8_t>& decoded, int sheet, int tile_id, bool flip_x,
16 bool flip_y) {
17 if (sheet <= 0 || tile_id < 0 || tile_id >= 1024 ||
18 static_cast<size_t>(sheet + 1) * 4096 > decoded.size()) {
19 return absl::FailedPreconditionError("Tile8 source graphics unavailable");
20 }
21 std::array<uint8_t, 64> mask{};
22 const int local_tile = tile_id % 64;
23 for (int y = 0; y < 8; ++y) {
24 for (int x = 0; x < 8; ++x) {
25 const int sx = flip_x ? 7 - x : x;
26 const int sy = flip_y ? 7 - y : y;
27 const size_t source = sheet * 4096 + (local_tile / 16) * 1024 +
28 (local_tile % 16) * 8 + sy * 128 + sx;
29 if (decoded[source] > 15) {
30 return absl::DataLossError("Tile8 source contains undecoded pixels");
31 }
32 mask[y * 8 + x] = decoded[source] == 0;
33 }
34 }
35 return mask;
36}
37
38} // namespace yaze::zelda3
39#endif
Zelda 3 specific classes and functions.
absl::StatusOr< std::array< uint8_t, 64 > > Tile8SourceTransparency(const std::vector< uint8_t > &decoded, int sheet, int tile_id, bool flip_x, bool flip_y)