yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
color_id_permutation.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_COLOR_ID_PERMUTATION_H_
2#define YAZE_APP_EDITOR_GRAPHICS_COLOR_ID_PERMUTATION_H_
3
4#include <array>
5#include <cstddef>
6#include <cstdint>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
11#include "absl/types/span.h"
12
13namespace yaze::editor {
14
15// Whole-selection color-ID map for one SNES planar depth (2, 3 or 4 bpp).
16// ids[i] is the new ID of original ID i. Entries at or past 2^bpp must stay
17// identity so a permutation can never name an ID its backing cannot store.
19 int bpp = 3;
20 std::array<uint8_t, 16> ids{0, 1, 2, 3, 4, 5, 6, 7,
21 8, 9, 10, 11, 12, 13, 14, 15};
22
23 int colors() const { return 1 << bpp; }
24};
25
26ColorIdPermutation IdentityColorIdPermutation(int bpp);
27
28// Bijection on 0..2^bpp-1 that keeps ID 0 fixed. Changing transparency is a
29// separate explicit replacement and is always refused here.
30absl::Status ValidateColorIdPermutation(const ColorIdPermutation& permutation);
31
32// As above, and the permutation depth must equal the backing's depth.
34 const ColorIdPermutation& permutation, int backing_bpp);
35
36// Swaps two nonzero IDs inside the depth.
37absl::StatusOr<ColorIdPermutation> MakeColorIdSwap(int bpp, int from, int to);
38
39// Maps a mask over a displayed (possibly flipped) 8x8 tile to the physical,
40// unflipped tile. Bit y * 8 + x selects a pixel.
41uint64_t PhysicalPixelMask(uint64_t displayed_mask, bool hflip, bool vflip);
42
43// One row-major 128x32 indexed page and its declared planar depth.
45 uint32_t range = 0;
46 int bpp = 3;
47 absl::Span<const uint8_t> pixels;
48};
49
51 uint32_t range = 0;
52 uint16_t tile_index = 0;
53 uint64_t pixel_mask = ~uint64_t{0};
54 bool hflip = false;
55 bool vflip = false;
56};
57
59 uint32_t range = 0;
60 std::vector<uint16_t> offsets;
61 std::vector<uint8_t> before;
62 std::vector<uint8_t> after;
63};
64
65// Targets are canonical physical masks (H/V false), one per physical tile.
66// ranges lists only ranges whose pixels change.
69 std::vector<ColorIdTarget> targets;
70 std::vector<ColorIdRangeEdit> ranges;
71 size_t physical_tiles = 0;
72 size_t selected_pixels = 0;
73};
74
75// Pure planning across any number of backings. Every backing must match the
76// permutation depth and hold only IDs below 2^bpp. Aliases of one physical
77// tile are unioned first, so each original pixel is mapped exactly once.
78absl::StatusOr<ColorIdEditPlan> PlanColorIdEdit(
79 const std::vector<ColorIdBacking>& backings,
80 const std::vector<ColorIdTarget>& targets,
81 const ColorIdPermutation& permutation);
82
83// Writes one range edit (forward = after) into a copy of its page. Refuses
84// when any affected pixel differs from the expected prior value.
85absl::Status ApplyColorIdRangeEdit(const ColorIdRangeEdit& edit, int bpp,
86 bool forward, std::vector<uint8_t>& pixels);
87
88} // namespace yaze::editor
89
90#endif // YAZE_APP_EDITOR_GRAPHICS_COLOR_ID_PERMUTATION_H_
Editors are the view controllers for the application.
absl::Status ValidateColorIdPermutation(const ColorIdPermutation &permutation)
absl::StatusOr< ColorIdPermutation > MakeColorIdSwap(int bpp, int from, int to)
absl::StatusOr< ColorIdEditPlan > PlanColorIdEdit(const std::vector< ColorIdBacking > &backings, const std::vector< ColorIdTarget > &targets, const ColorIdPermutation &permutation)
ColorIdPermutation IdentityColorIdPermutation(int bpp)
absl::Status ValidateColorIdPermutationForBacking(const ColorIdPermutation &permutation, int backing_bpp)
uint64_t PhysicalPixelMask(uint64_t displayed_mask, bool hflip, bool vflip)
absl::Status ApplyColorIdRangeEdit(const ColorIdRangeEdit &edit, int bpp, bool forward, std::vector< uint8_t > &pixels)
absl::Span< const uint8_t > pixels
std::vector< ColorIdRangeEdit > ranges
std::vector< ColorIdTarget > targets