Skip to content

Commit

Permalink
optimize RGBA to BGRA conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
qbnu committed Sep 3, 2023
1 parent a49c7a7 commit d386db8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
15 changes: 5 additions & 10 deletions src/JPEGView/HEIFWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,16 @@ void * HeifReader::ReadImage(int &width,
}
std::vector<uint8_t> iccp = image.get_raw_color_profile();
void* transform = ICCProfileTransform::CreateTransform(iccp.data(), iccp.size(), ICCProfileTransform::FORMAT_RGBA);
uint8_t* p;
size_t i, j;
if (!ICCProfileTransform::DoTransform(transform, data, pPixelData, width, height, stride=stride)) {
memcpy(pPixelData, data, size);
unsigned char* o = pPixelData;
unsigned int* o = (unsigned int*)pPixelData;
for (i = 0; i < height; i++) {
p = data + i * stride;
unsigned int* p = (unsigned int*)(data + i * stride);
for (j = 0; j < width; j++) {
// RGBA -> BGRA conversion
o[0] = p[2];
o[1] = p[1];
o[2] = p[0];
o[3] = p[3];
p += nchannels;
o += nchannels;
*o = _rotr(*p & 0x00FF00FF, 16) | (*p & 0xFF00FF00);
p++;
o++;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/JPEGView/JXLWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ void* JxlReader::ReadImage(int& width,
if (cache.transform == NULL)
cache.transform = ICCProfileTransform::CreateTransform(icc_profile.data(), icc_profile.size(), ICCProfileTransform::FORMAT_RGBA);
if (!ICCProfileTransform::DoTransform(cache.transform, pixels.data(), pPixelData, width, height)) {
memcpy(pPixelData, pixels.data(), size);
// RGBA -> BGRA conversion (with little-endian integers)
for (uint32_t* i = (uint32_t*)pPixelData; (uint8_t*)i < pPixelData + size; i++)
*i = ((*i & 0x00FF0000) >> 16) | ((*i & 0x0000FF00)) | ((*i & 0x000000FF) << 16) | ((*i & 0xFF000000));
for (int i = 0; i * sizeof(uint32_t) < size; i++) {
uint32_t pixel = ((uint32_t*)pixels.data())[i];
((uint32_t*)pPixelData)[i] = _rotr(pixel & 0x00FF00FF, 16) | (pixel & 0xFF00FF00);
}
}

// Copy Exif data into the format understood by CEXIFReader
Expand Down

0 comments on commit d386db8

Please sign in to comment.