kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Add class that handles data ownership for full image
rodzic
6ced865d53
commit
e53058e8b0
|
@ -47,6 +47,47 @@
|
|||
|
||||
#include <array>
|
||||
|
||||
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<PixelFormat SrcFormat, PixelFormat DstFormat>
|
||||
void convert_pixel_row_impl2(const std::uint8_t* in_data, std::uint8_t* out_data,
|
||||
std::size_t count)
|
||||
|
|
|
@ -45,6 +45,35 @@
|
|||
#define BACKEND_GENESYS_IMAGE_H
|
||||
|
||||
#include "genesys_image_pixel.h"
|
||||
#include <vector>
|
||||
|
||||
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<std::uint8_t> 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);
|
||||
|
|
Ładowanie…
Reference in New Issue