diff --git a/core/platform/Image.cpp b/core/platform/Image.cpp index a6fcb36c09a..86c68c5ca8f 100644 --- a/core/platform/Image.cpp +++ b/core/platform/Image.cpp @@ -748,6 +748,35 @@ bool Image::initWithRawData(const uint8_t* data, return ret; } +void Image::flipRawData() +{ + AXASSERT(_pixelFormat == backend::PixelFormat::RGBA8, "only RGBA8888 can be flipped"); + if (_pixelFormat != backend::PixelFormat::RGBA8) + { + AXLOGE("Cannot flip image. Unsupported pixel format."); + return; + } + + uint8_t temp; + int idx1, idx2; + + for (int w = 0; w < _width; w++) + { + for (int h = 0; h < _height / 2; h++) + { + idx1 = (h * _width + w) * 4; + idx2 = ((_height - h - 1) * _width + w) * 4; + + for (int c = 0; c < 4; c++) + { + temp = _data[idx1 + c]; + _data[idx1 + c] = _data[idx2 + c]; + _data[idx2 + c] = temp; + } + } + } +} + bool Image::isPng(const uint8_t* data, ssize_t dataLen) { if (dataLen <= 8) diff --git a/core/platform/Image.h b/core/platform/Image.h index 0c3796ea7a3..120ae449f1a 100644 --- a/core/platform/Image.h +++ b/core/platform/Image.h @@ -167,6 +167,9 @@ class AX_DLL Image : public Object int bitsPerComponent, bool preMulti = false); + // only RGBA8888 supported + void flipRawData(); + // Getters uint8_t* getData() { return _data + _offset; } ssize_t getDataLen() { return _dataLen - _offset; }