77 std::size_t size = w *
h;
81 if (format == Color::Format::ABGR) {
85 for (uint
i = 0;
i <
h;
i++) {
86 for (uint
j = 0;
j < w;
j++) {
88 mImg(
i,
j) = c.abgr();
99 bool isNull()
const {
return mImg.empty(); }
101 int height()
const {
return mImg.rows(); }
103 int width()
const {
return mImg.cols(); }
105 std::size_t sizeInBytes()
const {
return mImg.rows() * mImg.cols() * 4; }
107 Color pixel(uint i, uint j)
const
112 const unsigned char* data()
const
114 return reinterpret_cast<const unsigned char*
>(mImg.data());
117 bool load(
const std::string& filename)
122 std::shared_ptr<unsigned char> tmp = loadImageData(filename, w, h);
124 std::size_t size = w * h * 4;
130 reinterpret_cast<unsigned char*
>(mImg.data()));
138 void save(
const std::string& filename, uint quality = 90)
const
140 auto* data =
reinterpret_cast<const unsigned char*
>(mImg.data());
141 saveImageData(filename, mImg.cols(), mImg.rows(), data, quality);
144 void mirror(
bool horizontal =
false,
bool vertical =
true)
147 for (uint i = 0; i < mImg.rows(); i++) {
148 std::reverse(mImg.data(i), mImg.data(i) + mImg.cols());
152 for (uint i = 0; i < mImg.rows() / 2; i++) {
153 uint mir = mImg.rows() - i - 1;
155 mImg.data(i), mImg.data(i) + mImg.cols(), mImg.data(mir));
160 void serialize(std::ostream& os)
const { mImg.serialize(os); }
162 void deserialize(std::istream& is) { mImg.deserialize(is); }
Image(const void *data, uint w, uint h, bool yFlip=false, Color::Format format=Color::Format::ABGR)
Construct an Image from a raw buffer, which is assumed to be in the given format (default: ABGR).
Definition image.h:68