diff options
-rw-r--r-- | indra/llimage/llimage.cpp | 37 | ||||
-rw-r--r-- | indra/llimage/llimage.h | 4 | ||||
-rw-r--r-- | indra/newview/lltinygltfhelper.cpp | 1 |
3 files changed, 42 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 diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h index 9e50fd502b..8f9e1b3c54 100644 --- a/indra/llimage/llimage.h +++ b/indra/llimage/llimage.h @@ -208,6 +208,10 @@ public: void clear(U8 r=0, U8 g=0, U8 b=0, U8 a=255); void verticalFlip(); + + // if the alpha channel is all 100% opaque, delete it + // returns true if alpha channel was deleted + bool optimizeAwayAlpha(); static S32 biasedDimToPowerOfTwo(S32 curr_dim, S32 max_dim = MAX_IMAGE_SIZE); static S32 expandDimToPowerOfTwo(S32 curr_dim, S32 max_dim = MAX_IMAGE_SIZE); diff --git a/indra/newview/lltinygltfhelper.cpp b/indra/newview/lltinygltfhelper.cpp index 838524e910..611911014a 100644 --- a/indra/newview/lltinygltfhelper.cpp +++ b/indra/newview/lltinygltfhelper.cpp @@ -160,6 +160,7 @@ LLImageRaw * LLTinyGLTFHelper::getTexture(const std::string & folder, const tiny name = image->name; rawImage = new LLImageRaw(&image->image[0], image->width, image->height, image->component); rawImage->verticalFlip(); + rawImage->optimizeAwayAlpha(); } return rawImage; |