X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=platform-abstractions%2Fportable%2Fimage-operations.cpp;h=f759d39a187059c27d09438cbcf692c98a43489a;hb=316892a6d5196a469bfda0bd56bca85dfce8271b;hp=c301fcc0db8ac027b4931887318f2da3f437167d;hpb=35f2e773c065808dff9959413a7fb550c2f7df0a;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/platform-abstractions/portable/image-operations.cpp b/platform-abstractions/portable/image-operations.cpp index c301fcc..f759d39 100644 --- a/platform-abstractions/portable/image-operations.cpp +++ b/platform-abstractions/portable/image-operations.cpp @@ -26,6 +26,7 @@ #include #include #include +#include // INTERNAL INCLUDES @@ -49,7 +50,7 @@ const unsigned int MAXIMUM_TARGET_BITMAP_SIZE( ( 1u << 16 ) - 1 ); // Constants used by the ImageResampler. const float DEFAULT_SOURCE_GAMMA = 1.75f; ///< Default source gamma value used in the Resampler() function. Partial gamma correction looks better on mips. Set to 1.0 to disable gamma correction. const float FILTER_SCALE = 1.f; ///< Default filter scale value used in the Resampler() function. Filter scale - values < 1.0 cause aliasing, but create sharper looking mips. -const char* const FILTER_TYPE = "lanczos4"; ///< Default filter used in the Resampler() function. Possible Lanczos filters are: lanczos3, lanczos4, lanczos6, lanczos12 +const Resampler::Filter FILTER_TYPE = Resampler::LANCZOS4; ///< Default filter used in the Resampler() function. Possible Lanczos filters are: lanczos3, lanczos4, lanczos6, lanczos12 using Integration::Bitmap; using Integration::BitmapPtr; @@ -449,24 +450,29 @@ BitmapPtr MakeBitmap( const uint8_t * const pixels, Pixel::Format pixelFormat, u */ ImageDimensions CalculateDesiredDimensions( unsigned int bitmapWidth, unsigned int bitmapHeight, unsigned int requestedWidth, unsigned int requestedHeight ) { + unsigned int maxSize = Dali::GetMaxTextureSize(); + // If no dimensions have been requested, default to the source ones: if( requestedWidth == 0 && requestedHeight == 0 ) { - return ImageDimensions( bitmapWidth, bitmapHeight ); + return ImageDimensions( std::min( bitmapWidth, maxSize ), std::min( bitmapHeight, maxSize ) ); } // If both dimensions have values requested, use them both: if( requestedWidth != 0 && requestedHeight != 0 ) { - return ImageDimensions( requestedWidth, requestedHeight ); + return ImageDimensions( std::min( requestedWidth, maxSize ), std::min( requestedHeight, maxSize ) ); } // Only one of the dimensions has been requested. Calculate the other from // the requested one and the source image aspect ratio: if( requestedWidth != 0 ) { + requestedWidth = std::min( requestedWidth, maxSize ); return ImageDimensions( requestedWidth, bitmapHeight / float(bitmapWidth) * requestedWidth + 0.5f ); } + + requestedHeight = std::min( requestedHeight, maxSize ); return ImageDimensions( bitmapWidth / float(bitmapHeight) * requestedHeight + 0.5f, requestedHeight ); } @@ -1517,45 +1523,51 @@ void LinearSample4BPP( const unsigned char * __restrict__ inPixels, LinearSampleGeneric( inPixels, inputDimensions, outPixels, desiredDimensions ); } -void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, - ImageDimensions inputDimensions, - unsigned char * __restrict__ outPixels, - ImageDimensions desiredDimensions ) +void LanczosSample( const unsigned char * __restrict__ inPixels, + ImageDimensions inputDimensions, + unsigned char * __restrict__ outPixels, + ImageDimensions desiredDimensions, + int numChannels, bool hasAlpha ) { // Got from the test.cpp of the ImageResampler lib. const float ONE_DIV_255 = 1.0f / 255.0f; const int MAX_UNSIGNED_CHAR = std::numeric_limits::max(); const int LINEAR_TO_SRGB_TABLE_SIZE = 4096; - const int ALPHA_CHANNEL = 3; - const int NUMBER_OF_CHANNELS = 4; + const int ALPHA_CHANNEL = hasAlpha ? (numChannels-1) : 0; - float srgbToLinear[MAX_UNSIGNED_CHAR + 1]; - for( int i = 0; i <= MAX_UNSIGNED_CHAR; ++i ) - { - srgbToLinear[i] = pow( static_cast( i ) * ONE_DIV_255, DEFAULT_SOURCE_GAMMA ); - } + static bool loadColorSpaces = true; + static float srgbToLinear[MAX_UNSIGNED_CHAR + 1]; + static unsigned char linearToSrgb[LINEAR_TO_SRGB_TABLE_SIZE]; - unsigned char linearToSrgb[LINEAR_TO_SRGB_TABLE_SIZE]; - - const float invLinearToSrgbTableSize = 1.0f / static_cast( LINEAR_TO_SRGB_TABLE_SIZE ); - const float invSourceGamma = 1.0f / DEFAULT_SOURCE_GAMMA; - - for( int i = 0; i < LINEAR_TO_SRGB_TABLE_SIZE; ++i ) + if( loadColorSpaces ) // Only create the color space conversions on the first execution { - int k = static_cast( 255.0f * pow( static_cast( i ) * invLinearToSrgbTableSize, invSourceGamma ) + 0.5f ); - if( k < 0 ) + loadColorSpaces = false; + + for( int i = 0; i <= MAX_UNSIGNED_CHAR; ++i ) { - k = 0; + srgbToLinear[i] = pow( static_cast( i ) * ONE_DIV_255, DEFAULT_SOURCE_GAMMA ); } - else if( k > MAX_UNSIGNED_CHAR ) + + const float invLinearToSrgbTableSize = 1.0f / static_cast( LINEAR_TO_SRGB_TABLE_SIZE ); + const float invSourceGamma = 1.0f / DEFAULT_SOURCE_GAMMA; + + for( int i = 0; i < LINEAR_TO_SRGB_TABLE_SIZE; ++i ) { - k = MAX_UNSIGNED_CHAR; + int k = static_cast( 255.0f * pow( static_cast( i ) * invLinearToSrgbTableSize, invSourceGamma ) + 0.5f ); + if( k < 0 ) + { + k = 0; + } + else if( k > MAX_UNSIGNED_CHAR ) + { + k = MAX_UNSIGNED_CHAR; + } + linearToSrgb[i] = static_cast( k ); } - linearToSrgb[i] = static_cast( k ); } - Resampler* resamplers[NUMBER_OF_CHANNELS] = { 0 }; - Vector samples[NUMBER_OF_CHANNELS]; + Resampler* resamplers[numChannels]; + Vector samples[numChannels]; const int srcWidth = inputDimensions.GetWidth(); const int srcHeight = inputDimensions.GetHeight(); @@ -1577,7 +1589,7 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, FILTER_SCALE, // src_x_ofs, FILTER_SCALE ); // src_y_ofs. Offset input image by specified amount (fractional values okay). samples[0].Resize( srcWidth ); - for( int i = 1; i < NUMBER_OF_CHANNELS; ++i ) + for( int i = 1; i < numChannels; ++i ) { resamplers[i] = new Resampler( srcWidth, srcHeight, @@ -1594,8 +1606,8 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, samples[i].Resize( srcWidth ); } - const int srcPitch = srcWidth * NUMBER_OF_CHANNELS; - const int dstPitch = dstWidth * NUMBER_OF_CHANNELS; + const int srcPitch = srcWidth * numChannels; + const int dstPitch = dstWidth * numChannels; int dstY = 0; for( int srcY = 0; srcY < srcHeight; ++srcY ) @@ -1604,9 +1616,9 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, for( int x = 0; x < srcWidth; ++x ) { - for( int c = 0; c < NUMBER_OF_CHANNELS; ++c ) + for( int c = 0; c < numChannels; ++c ) { - if( c == ALPHA_CHANNEL ) + if( c == ALPHA_CHANNEL && hasAlpha ) { samples[c][x] = *pSrc++ * ONE_DIV_255; } @@ -1617,7 +1629,7 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, } } - for( int c = 0; c < NUMBER_OF_CHANNELS; ++c ) + for( int c = 0; c < numChannels; ++c ) { if( !resamplers[c]->put_line( &samples[c][0] ) ) { @@ -1628,7 +1640,7 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, for(;;) { int compIndex; - for( compIndex = 0; compIndex < NUMBER_OF_CHANNELS; ++compIndex ) + for( compIndex = 0; compIndex < numChannels; ++compIndex ) { const float* pOutputSamples = resamplers[compIndex]->get_line(); if( !pOutputSamples ) @@ -1636,7 +1648,7 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, break; } - const bool isAlphaChannel = ( compIndex == ALPHA_CHANNEL ); + const bool isAlphaChannel = ( compIndex == ALPHA_CHANNEL && hasAlpha ); DALI_ASSERT_DEBUG( dstY < dstHeight ); unsigned char* pDst = &outPixels[dstY * dstPitch + compIndex]; @@ -1669,10 +1681,10 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, *pDst = linearToSrgb[j]; } - pDst += NUMBER_OF_CHANNELS; + pDst += numChannels; } } - if( compIndex < NUMBER_OF_CHANNELS ) + if( compIndex < numChannels ) { break; } @@ -1682,12 +1694,29 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, } // Delete the resamplers. - for( int i = 0; i < NUMBER_OF_CHANNELS; ++i ) + for( int i = 0; i < numChannels; ++i ) { delete resamplers[i]; } } +void LanczosSample4BPP( const unsigned char * __restrict__ inPixels, + ImageDimensions inputDimensions, + unsigned char * __restrict__ outPixels, + ImageDimensions desiredDimensions ) +{ + LanczosSample( inPixels, inputDimensions, outPixels, desiredDimensions, 4, true ); +} + +void LanczosSample1BPP( const unsigned char * __restrict__ inPixels, + ImageDimensions inputDimensions, + unsigned char * __restrict__ outPixels, + ImageDimensions desiredDimensions ) +{ + // For L8 images + LanczosSample( inPixels, inputDimensions, outPixels, desiredDimensions, 1, false ); +} + // Dispatch to a format-appropriate linear sampling function: void LinearSample( const unsigned char * __restrict__ inPixels, ImageDimensions inDimensions,