diff --git a/backend/genesys_image.cc b/backend/genesys_image.cc index 36d1cc1fe..c55f4b56a 100644 --- a/backend/genesys_image.cc +++ b/backend/genesys_image.cc @@ -47,6 +47,47 @@ #include +Image::Image() = default; + +Image::Image(std::size_t width, std::size_t height, PixelFormat format) : + width_{width}, + height_{height}, + format_{format}, + row_bytes_{get_pixel_row_bytes(format_, width_)} +{ + data_.resize(get_row_bytes() * height); +} + +std::uint8_t* Image::get_row_ptr(std::size_t y) +{ + return data_.data() + row_bytes_ * y; +} + +const std::uint8_t* Image::get_row_ptr(std::size_t y) const +{ + return data_.data() + row_bytes_ * y; +} + +Pixel Image::get_pixel(std::size_t x, std::size_t y) const +{ + return get_pixel_from_row(get_row_ptr(y), x, format_); +} + +void Image::set_pixel(std::size_t x, std::size_t y, const Pixel& pixel) +{ + set_pixel_to_row(get_row_ptr(y), x, pixel, format_); +} + +RawPixel Image::get_raw_pixel(std::size_t x, std::size_t y) const +{ + return get_raw_pixel_from_row(get_row_ptr(y), x, format_); +} + +void Image::set_raw_pixel(std::size_t x, std::size_t y, const RawPixel& pixel) +{ + set_raw_pixel_to_row(get_row_ptr(y), x, pixel, format_); +} + template void convert_pixel_row_impl2(const std::uint8_t* in_data, std::uint8_t* out_data, std::size_t count) diff --git a/backend/genesys_image.h b/backend/genesys_image.h index 3c48580da..388b13acd 100644 --- a/backend/genesys_image.h +++ b/backend/genesys_image.h @@ -45,6 +45,35 @@ #define BACKEND_GENESYS_IMAGE_H #include "genesys_image_pixel.h" +#include + +class Image +{ +public: + Image(); + Image(std::size_t width, std::size_t height, PixelFormat format); + + std::size_t get_width() const { return width_; } + std::size_t get_height() const { return height_; } + PixelFormat get_format() const { return format_; } + std::size_t get_row_bytes() const { return row_bytes_; } + + std::uint8_t* get_row_ptr(std::size_t y); + const std::uint8_t* get_row_ptr(std::size_t y) const; + + Pixel get_pixel(std::size_t x, std::size_t y) const; + void set_pixel(std::size_t x, std::size_t y, const Pixel& pixel); + + RawPixel get_raw_pixel(std::size_t x, std::size_t y) const; + void set_raw_pixel(std::size_t x, std::size_t y, const RawPixel& pixel); + +private: + std::size_t width_ = 0; + std::size_t height_ = 0; + PixelFormat format_ = PixelFormat::UNKNOWN; + std::size_t row_bytes_ = 0; + std::vector data_; +}; void convert_pixel_row_format(const std::uint8_t* in_data, PixelFormat in_format, std::uint8_t* out_data, PixelFormat out_format, std::size_t count);