33template <
typename PixelType>
35 const Image<PixelType> &img, std::size_t tile_offset, std::size_t tile_count, std::size_t tiles_per_row = 16)
40 "image dimensions must be multiples of {}, got {}x{}",
46 std::vector<PixelTile<PixelType>> result;
47 result.reserve(tile_count);
49 for (std::size_t i = 0; i < tile_count; ++i) {
50 const std::size_t tile_idx = tile_offset + i;
51 const std::size_t tile_row = tile_idx / tiles_per_row;
52 const std::size_t tile_col = tile_idx % tiles_per_row;
60 pixel_tile.
set(row, col, img.
at(pixel_y + row, pixel_x + col));
64 result.push_back(std::move(pixel_tile));
85template <
typename PixelType>
91 "image dimensions must be multiples of {}, got {}x{}",
114template <
typename PixelType>
117 std::size_t tile_idx,
A template for two-dimensional images with arbitrarily typed pixel values.
std::size_t size_in_tiles() const
Gets the number of 8x8 tile regions in this image.
std::size_t width() const
std::size_t height() const
PixelType at(std::size_t i) const
Fetches the pixel value at a given one-dimensional pixel index.
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.
PixelType at(std::size_t i) const
void set(std::size_t i, const PixelType &p)
constexpr std::size_t side_length_pix
PixelTile< PixelType > extract_single_tile(const Image< PixelType > &img, std::size_t tile_idx, std::size_t tiles_per_row=metatile::metatiles_per_row *metatile::tiles_per_side)
Extracts a single tile from an image at a given tile index.
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
std::vector< PixelTile< PixelType > > extract_tiles_from_image(const Image< PixelType > &img, std::size_t tile_offset, std::size_t tile_count, std::size_t tiles_per_row=16)
Extracts a subset of 8x8 tiles from a tileset image at a specific offset.