X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fimages%2Fencoded-buffer-image-impl.cpp;h=6666656d06dfa0476e0df206af6c565973935eb4;hb=091424324901c46a18959bfc0dd52f7ce8a0a811;hp=42cfa521fe45b96f067a2d7157e96904457c9812;hpb=315d672889a73bbca5ca4e9e952c01e4c1f410ae;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/images/encoded-buffer-image-impl.cpp b/dali/internal/event/images/encoded-buffer-image-impl.cpp index 42cfa52..6666656 100644 --- a/dali/internal/event/images/encoded-buffer-image-impl.cpp +++ b/dali/internal/event/images/encoded-buffer-image-impl.cpp @@ -1,25 +1,30 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // CLASS HEADER #include +// EXTERNAL INCLUDES +#include // for memcpy + // INTERNAL INCLUDES +#include +#include #include -#include #include namespace Dali @@ -27,10 +32,22 @@ namespace Dali namespace Internal { -Dali::EncodedBufferImage EncodedBufferImage::New( const uint8_t * const encodedImage, - const std::size_t encodedImageByteCount, - const ImageAttributes& attributes, - const ReleasePolicy releasePol ) +namespace +{ + +TypeRegistration mType( typeid( Dali::EncodedBufferImage ), typeid( Dali::Image ), NULL ); + +/** Raw bytes of a resource laid out exactly as it would be in a file, but in memory. */ +typedef Dali::RefCountedVector RequestBuffer; +/** Counting smart pointer for managing a buffer of raw bytes. */ +typedef IntrusivePtr RequestBufferPtr; + +} // unnamed namespace + +EncodedBufferImagePtr EncodedBufferImage::New( const uint8_t * const encodedImage, + std::size_t encodedImageByteCount, + ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, + bool orientationCorrection ) { DALI_ASSERT_DEBUG( encodedImage && "Null image pointer passed-in for decoding from memory." ); DALI_ASSERT_DEBUG( encodedImageByteCount > 0U && "Zero size passed for image resource in memory buffer." ); @@ -39,12 +56,10 @@ Dali::EncodedBufferImage EncodedBufferImage::New( const uint8_t * const encodedI // input buffer by reading both ends of it: DALI_ASSERT_ALWAYS( static_cast( encodedImage[0] + encodedImage[encodedImageByteCount-1] ) != -1 ); - EncodedBufferImage* const image = new EncodedBufferImage( releasePol ); - // Make sure that this image object cannot leak if we throw: - Dali::EncodedBufferImage publicImage(image); + EncodedBufferImagePtr image( new EncodedBufferImage() ); + image->Initialize(); // Second stage initialization - // Replicate the functionality of ImageFactory::load() without the filesystem caching: - Dali::Integration::BitmapResourceType resourceType( attributes ); + Dali::Integration::BitmapResourceType resourceType( size, fittingMode, samplingMode, orientationCorrection ); RequestBufferPtr buffer( new RequestBuffer ); buffer->GetVector().Resize( encodedImageByteCount ); // Resize() won't throw on failure, so avoid a SEGV if the allocation failed: @@ -53,23 +68,48 @@ Dali::EncodedBufferImage EncodedBufferImage::New( const uint8_t * const encodedI memcpy( &(buffer->GetVector()[0]), encodedImage, encodedImageByteCount ); // Get image size from buffer - Vector2 size; - Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( buffer, attributes, size ); - image->mWidth = (unsigned int) size.width; - image->mHeight = (unsigned int) size.height; - - ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient(); - ResourceTicketPtr ticket = resourceClient.DecodeResource( resourceType, buffer ); - if( ticket ) + Dali::Integration::PlatformAbstraction& platformAbstraction = Internal::ThreadLocalStorage::Get().GetPlatformAbstraction(); + const ImageDimensions expectedSize = platformAbstraction.GetClosestImageSize( buffer, size, fittingMode, samplingMode, orientationCorrection ); + image->mWidth = static_cast( expectedSize.GetWidth() ); + image->mHeight = static_cast( expectedSize.GetHeight() ); + + // Load the image synchronously + Integration::BitmapPtr bitmap = platformAbstraction.DecodeBuffer( resourceType, &(buffer->GetVector()[0]), encodedImageByteCount ); + + if( bitmap ) { - DALI_ASSERT_DEBUG( dynamic_cast( ticket.Get() ) && "Resource ticket returned for image resource has to be an ImageTicket subclass.\n" ); - ImageTicket * const imageTicket = static_cast( ticket.Get() ); + unsigned width = bitmap->GetImageWidth(); + unsigned height = bitmap->GetImageHeight(); + + //Create texture + Pixel::Format format = bitmap->GetPixelFormat(); + image->mTexture = Texture::New( Dali::TextureType::TEXTURE_2D, format, width, height ); + + //Upload data to the texture + size_t bufferSize = bitmap->GetBufferSize(); + PixelDataPtr pixelData = PixelData::New( bitmap->GetBufferOwnership(), bufferSize, width, height, format, + static_cast< Dali::PixelData::ReleaseFunction >( bitmap->GetReleaseFunction() ) ); + image->mTexture->Upload( pixelData ); - image->mTicket = imageTicket; - imageTicket->AddObserver( *image ); + image->mWidth = size.GetWidth(); + if( image->mWidth == 0 ) + { + image->mWidth = width; + } + + image->mHeight = size.GetHeight(); + if( image->mHeight == 0 ) + { + image->mHeight = height; + } + } + else + { + image->mTexture = Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888, 0u, 0u ); + image->mWidth = image->mHeight = 0u; } - return publicImage; + return image; } } // namespace Internal