2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali/devel-api/adaptor-framework/image-loading.h>
21 #include <dali/public-api/object/property-map.h>
22 #include <dali/internal/imaging/common/image-loader.h>
23 #include <dali/internal/imaging/common/file-download.h>
24 #include <dali/internal/system/common/file-reader.h>
25 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
33 // limit maximum image down load size to 50 MB
34 const size_t MAXIMUM_DOWNLOAD_IMAGE_SIZE = 50 * 1024 * 1024 ;
36 static unsigned int gMaxTextureSize = 4096;
40 Devel::PixelBuffer LoadImageFromFile( const std::string& url, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection )
42 Integration::BitmapResourceType resourceType( size, fittingMode, samplingMode, orientationCorrection );
44 Internal::Platform::FileReader fileReader( url );
45 FILE * const fp = fileReader.GetFile();
48 Dali::Devel::PixelBuffer bitmap;
49 bool success = TizenPlatform::ImageLoader::ConvertStreamToBitmap( resourceType, url, fp, bitmap );
50 if( success && bitmap )
55 return Dali::Devel::PixelBuffer();
58 ImageDimensions GetClosestImageSize( const std::string& filename,
60 FittingMode::Type fittingMode,
61 SamplingMode::Type samplingMode,
62 bool orientationCorrection )
64 ImageDimensions dimension = TizenPlatform::ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
66 dimension.SetWidth( std::min( dimension.GetWidth(), static_cast< uint16_t >( GetMaxTextureSize() ) ) );
67 dimension.SetHeight( std::min( dimension.GetHeight(), static_cast< uint16_t >( GetMaxTextureSize() ) ) );
73 Devel::PixelBuffer DownloadImageSynchronously( const std::string& url, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection )
75 Integration::BitmapResourceType resourceType( size, fittingMode, samplingMode, orientationCorrection );
78 Dali::Vector<uint8_t> dataBuffer;
81 succeeded = TizenPlatform::Network::DownloadRemoteFileIntoMemory( url, dataBuffer, dataSize,
82 MAXIMUM_DOWNLOAD_IMAGE_SIZE );
85 size_t blobSize = dataBuffer.Size();
87 DALI_ASSERT_DEBUG( blobSize > 0U );
91 // Open a file handle on the memory buffer:
92 Dali::Internal::Platform::FileReader fileReader( dataBuffer, blobSize );
93 FILE * const fp = fileReader.GetFile();
96 Dali::Devel::PixelBuffer bitmap;
97 bool result = TizenPlatform::ImageLoader::ConvertStreamToBitmap(
103 if ( result && bitmap )
109 DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
114 return Dali::Devel::PixelBuffer();
117 void SetMaxTextureSize( unsigned int size )
119 gMaxTextureSize = size;
122 unsigned int GetMaxTextureSize()
124 return gMaxTextureSize;