X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fimaging%2Fcommon%2Fpixel-buffer-impl.cpp;h=e69f2c8dc2f70bbbafed36b540adc7299368649c;hb=794911bc29c5ddf7a1629b4872a4bd8c663c0005;hp=1b7498865ecb18dc3b3ffc90814c6c6d7c05f329;hpb=d0a8e24ca48e45e8a6b883b5e7c6520e38483376;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/imaging/common/pixel-buffer-impl.cpp b/dali/internal/imaging/common/pixel-buffer-impl.cpp index 1b74988..e69f2c8 100644 --- a/dali/internal/imaging/common/pixel-buffer-impl.cpp +++ b/dali/internal/imaging/common/pixel-buffer-impl.cpp @@ -37,6 +37,10 @@ namespace Adaptor namespace { const float TWO_PI = 2.f * Math::PI; ///< 360 degrees in radians +// based on W3C Recommendations (https://www.w3.org/TR/AERT/#color-contrast) +constexpr uint32_t BRIGHTNESS_CONSTANT_R = 299; +constexpr uint32_t BRIGHTNESS_CONSTANT_G = 587; +constexpr uint32_t BRIGHTNESS_CONSTANT_B = 114; } // namespace PixelBuffer::PixelBuffer(unsigned char* buffer, @@ -466,6 +470,33 @@ bool PixelBuffer::IsAlphaPreMultiplied() const return mPreMultiplied; } +uint32_t PixelBuffer::GetBrightness() const +{ + uint32_t brightness = 0; + + uint32_t bytesPerPixel = Pixel::GetBytesPerPixel(mPixelFormat); + if(bytesPerPixel) + { + unsigned char* pixel = mBuffer; + const uint32_t bufferSize = mWidth * mHeight; + uint64_t red = 0; + uint64_t green = 0; + uint64_t blue = 0; + + for(uint32_t i = 0; i < bufferSize; ++i) + { + red += ReadChannel(pixel, mPixelFormat, Adaptor::RED); + green += ReadChannel(pixel, mPixelFormat, Adaptor::GREEN); + blue += ReadChannel(pixel, mPixelFormat, Adaptor::BLUE); + pixel += bytesPerPixel; + } + // http://www.w3.org/TR/AERT#color-contrast + brightness = (red * BRIGHTNESS_CONSTANT_R + green * BRIGHTNESS_CONSTANT_G + blue * BRIGHTNESS_CONSTANT_B) / (1000uLL * bufferSize); + } + + return brightness; +} + } // namespace Adaptor } // namespace Internal } // namespace Dali