diff options
| author | Dave Parks <davep@lindenlab.com> | 2022-12-16 12:22:23 -0600 |
|---|---|---|
| committer | Dave Parks <davep@lindenlab.com> | 2022-12-16 12:22:23 -0600 |
| commit | dbc641ce52264d0b5a8e584a726f2df457f26f79 (patch) | |
| tree | 0a048d600ec9c98fea45ad9bcc02cc2d2b5eee9e /indra/llimage/llimage.cpp | |
| parent | d27d23ab269f6d22483c4b4dc1db1664cf3e441e (diff) | |
SL-18861 Optimize away alpha channel on GLTF material imports.
Diffstat (limited to 'indra/llimage/llimage.cpp')
| -rw-r--r-- | indra/llimage/llimage.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 186b01d60c..031471d1fe 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -989,6 +989,43 @@ void LLImageRaw::verticalFlip() } +bool LLImageRaw::optimizeAwayAlpha() +{ + if (getComponents() == 4) + { + U8* data = getData(); + U32 pixels = getWidth() * getHeight(); + + // check alpha channel for all 255 + for (U32 i = 0; i < pixels; ++i) + { + if (data[i * 4 + 3] != 255) + { + return false; + } + } + + // alpha channel is all 255, make a new copy of data without alpha channel + U8* new_data = (U8*) ll_aligned_malloc_16(getWidth() * getHeight() * 3); + + for (U32 i = 0; i < pixels; ++i) + { + U32 di = i * 3; + U32 si = i * 4; + for (U32 j = 0; j < 3; ++j) + { + new_data[di+j] = data[si+j]; + } + } + + setDataAndSize(new_data, getWidth(), getHeight(), 3); + + return true; + } + + return false; +} + void LLImageRaw::expandToPowerOfTwo(S32 max_dim, bool scale_image) { // Find new sizes |
