35template <
typename PixelType>
37 const Image<PixelType> &img, std::size_t tile_offset, std::size_t tile_count, std::size_t tiles_per_row = 16)
42 "image dimensions must be multiples of {}, got {}x{}",
48 std::vector<PixelTile<PixelType>> result;
49 result.reserve(tile_count);
51 for (std::size_t i = 0; i < tile_count; ++i) {
52 const std::size_t tile_idx = tile_offset + i;
53 const std::size_t tile_row = tile_idx / tiles_per_row;
54 const std::size_t tile_col = tile_idx % tiles_per_row;
62 pixel_tile.
set(row, col, img.
at(pixel_y + row, pixel_x + col));
66 result.push_back(std::move(pixel_tile));
89template <
typename PixelType>
95 "image dimensions must be multiples of {}, got {}x{}",
120template <
typename PixelType>
123 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.