mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 13:48:30 +09:00
[Feat] (MG_Util/PixelStoreProcessor): properly handle BGRA to RGBA
swizzle
This commit is contained in:
@@ -42,6 +42,40 @@ namespace MobileGL::MG_Util::PixelStoreProcessor {
|
|||||||
bytes += rowBytes;
|
bytes += rowBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Uint8 GetSwizzledChannelValue(Uint8* pixel, TextureSwizzleParam param) {
|
||||||
|
switch (param) {
|
||||||
|
case TextureSwizzleParam::Red:
|
||||||
|
return pixel[0];
|
||||||
|
case TextureSwizzleParam::Green:
|
||||||
|
return pixel[1];
|
||||||
|
case TextureSwizzleParam::Blue:
|
||||||
|
return pixel[2];
|
||||||
|
case TextureSwizzleParam::Alpha:
|
||||||
|
return pixel[3];
|
||||||
|
case TextureSwizzleParam::Zero:
|
||||||
|
return 0;
|
||||||
|
case TextureSwizzleParam::One:
|
||||||
|
return 0xFF;
|
||||||
|
default:
|
||||||
|
return 0xBD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// assume 8 bit per channel
|
||||||
|
// swizzle.size() == channel count
|
||||||
|
static void ProcessColorSwizzle(void* data, SizeT pixelCount, const Vector<TextureSwizzleParam>& swizzle) {
|
||||||
|
const auto bpp = swizzle.size();
|
||||||
|
Uint8* bytes = static_cast<Uint8*>(data);
|
||||||
|
static Uint8 pixelScratch[4];
|
||||||
|
for (SizeT i = 0; i < pixelCount; ++i) {
|
||||||
|
Uint8* pixel = bytes + i * bpp;
|
||||||
|
for (SizeT ch = 0; ch < bpp; ++ch) {
|
||||||
|
pixelScratch[ch] = GetSwizzledChannelValue(pixel, swizzle[ch]);
|
||||||
|
}
|
||||||
|
Memcpy(pixel, pixelScratch, bpp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void* ProcessTexturePixelsDataUnpack(const void* inputPixels, const PixelStoreParameters& params,
|
void* ProcessTexturePixelsDataUnpack(const void* inputPixels, const PixelStoreParameters& params,
|
||||||
TextureInternalFormat targetInternalFormat, TextureInputFormat textureInputFormat, TexturePixelDataType inputDataType,
|
TextureInternalFormat targetInternalFormat, TextureInputFormat textureInputFormat, TexturePixelDataType inputDataType,
|
||||||
@@ -90,14 +124,29 @@ namespace MobileGL::MG_Util::PixelStoreProcessor {
|
|||||||
|
|
||||||
for (Int y = 0; y < copyHeight; ++y) {
|
for (Int y = 0; y < copyHeight; ++y) {
|
||||||
Memcpy(layerDst, layerSrc, static_cast<SizeT>(copyWidth) * pixelSize);
|
Memcpy(layerDst, layerSrc, static_cast<SizeT>(copyWidth) * pixelSize);
|
||||||
|
|
||||||
if (params.SwapBytes && pixelSize > 1) {
|
if (params.SwapBytes && pixelSize > 1) {
|
||||||
|
MGLOG_D("%s: SwapBytes", __func__);
|
||||||
SwapBytes(layerDst, pixelSize, static_cast<SizeT>(copyWidth));
|
SwapBytes(layerDst, pixelSize, static_cast<SizeT>(copyWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.LSBFirst && isBitmap) {
|
if (params.LSBFirst && isBitmap) {
|
||||||
|
MGLOG_D("%s: LSBFirst", __func__);
|
||||||
ProcessLSBFirst(layerDst, static_cast<SizeT>(copyWidth), 1);
|
ProcessLSBFirst(layerDst, static_cast<SizeT>(copyWidth), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (textureInputFormat == TextureInputFormat::BGRA && targetInternalFormat == TextureInternalFormat::RGBA8) {
|
||||||
|
MGLOG_D("%s: Swizzle (BGRA)", __func__);
|
||||||
|
MGLOG_D("%s: pixel0 before = %x", __func__, *((Uint32*)layerDst));
|
||||||
|
ProcessColorSwizzle(layerDst, static_cast<SizeT>(copyWidth), {
|
||||||
|
TextureSwizzleParam::Green,
|
||||||
|
TextureSwizzleParam::Blue,
|
||||||
|
TextureSwizzleParam::Alpha,
|
||||||
|
TextureSwizzleParam::Red
|
||||||
|
});
|
||||||
|
MGLOG_D("%s: pixel0 after = %x", __func__, *((Uint32*)layerDst));
|
||||||
|
} else
|
||||||
|
MGLOG_D("%s: pixel0 = %x", __func__, *((Uint32*)layerDst));
|
||||||
|
|
||||||
layerSrc += inputStride;
|
layerSrc += inputStride;
|
||||||
layerDst += static_cast<SizeT>(copyWidth) * pixelSize;
|
layerDst += static_cast<SizeT>(copyWidth) * pixelSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user