Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Image flip Raw data vertically #2369

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions core/platform/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,30 @@ bool Image::initWithRawData(const uint8_t* data,
return ret;
}

void Image::flipRawData()
{
// only RGBA8888 supported

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check pixel format

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)
Expand Down
3 changes: 3 additions & 0 deletions core/platform/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down