From: Joogab Yun Date: Mon, 19 Mar 2018 10:42:56 +0000 (+0900) Subject: supports remote URL gif image X-Git-Tag: accepted/tizen/4.0/unified/20180327.144913~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git;a=commitdiff_plain;h=3ddda734307cb4a3bdd66cabcf7513002d22d108 supports remote URL gif image Change-Id: If1b47536ef57fa45bd07e334c0545d8f2dbfd7d8 --- diff --git a/adaptors/devel-api/adaptor-framework/gif-loading.cpp b/adaptors/devel-api/adaptor-framework/gif-loading.cpp index d6504e9..8f75463 100755 --- a/adaptors/devel-api/adaptor-framework/gif-loading.cpp +++ b/adaptors/devel-api/adaptor-framework/gif-loading.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #define IMG_TOO_BIG( w, h ) \ ( ( static_cast(w) * static_cast(h) ) >= \ @@ -51,6 +53,7 @@ Debug::Filter *gGifLoadingLogFilter = Debug::Filter::New( Debug::NoLogging, fals #endif const int IMG_MAX_SIZE = 65000; +constexpr size_t MAXIMUM_DOWNLOAD_IMAGE_SIZE = 50 * 1024 * 1024; #if GIFLIB_MAJOR < 5 const int DISPOSE_BACKGROUND = 2; /* Set area too background color */ @@ -130,7 +133,8 @@ struct LoaderInfo : fileName( nullptr ), globalMap ( nullptr ), length( 0 ), - fileDescriptor( -1 ) + fileDescriptor( -1 ), + isLocalResource( true ) { } @@ -138,6 +142,7 @@ struct LoaderInfo unsigned char *globalMap ; /**< A pointer to the entire contents of the file that have been mapped with mmap(2). */ long long length; /**< The length of the file in bytes. */ int fileDescriptor; /**< The file descriptor. */ + bool isLocalResource; /**< The flag whether the file is a local resource */ }; struct FileInfo @@ -631,32 +636,63 @@ bool ReadHeader( LoaderInfo &loaderInfo, prop.w = 0; prop.h = 0; - fileData.fileDescriptor = open( fileData.fileName, O_RDONLY ); - - if( fileData.fileDescriptor == -1 ) + if( fileData.isLocalResource ) { - return false; - } + // local file + fileData.fileDescriptor = open( fileData.fileName, O_RDONLY ); - fileData.length = lseek( fileData.fileDescriptor, 0, SEEK_END ); - if( fileData.length <= -1 ) - { - close( fileData.fileDescriptor ); - return false; - } + if( fileData.fileDescriptor == -1 ) + { + return false; + } - if( lseek( fileData.fileDescriptor, 0, SEEK_SET ) == -1 ) - { - close( fileData.fileDescriptor ); - return false; - } + fileData.length = lseek( fileData.fileDescriptor, 0, SEEK_END ); + if( fileData.length <= -1 ) + { + close( fileData.fileDescriptor ); + return false; + } - // map the file and store/track info - fileData.globalMap = reinterpret_cast( mmap(NULL, fileData.length, PROT_READ, MAP_SHARED, fileData.fileDescriptor, 0 )); - fileInfo.map = fileData.globalMap ; + if( lseek( fileData.fileDescriptor, 0, SEEK_SET ) == -1 ) + { + close( fileData.fileDescriptor ); + return false; + } - close(fileData.fileDescriptor); - fileData.fileDescriptor = -1; + // map the file and store/track info + fileData.globalMap = reinterpret_cast( mmap(NULL, fileData.length, PROT_READ, MAP_SHARED, fileData.fileDescriptor, 0 )); + fileInfo.map = fileData.globalMap ; + + close(fileData.fileDescriptor); + fileData.fileDescriptor = -1; + } + else + { + // remote file + bool succeeded; + Dali::Vector dataBuffer; + size_t dataSize; + + succeeded = TizenPlatform::Network::DownloadRemoteFileIntoMemory( fileData.fileName, dataBuffer, dataSize, + MAXIMUM_DOWNLOAD_IMAGE_SIZE ); + if( succeeded ) + { + size_t blobSize = dataBuffer.Size(); + if( blobSize > 0U ) + { + // Open a file handle on the memory buffer: + Dali::Internal::Platform::FileReader fileReader( dataBuffer, blobSize ); + FILE * const fp = fileReader.GetFile(); + if ( NULL != fp ) + { + fseek( fp, 0, SEEK_SET ); + fileData.globalMap = reinterpret_cast( malloc(sizeof( GifByteType ) * blobSize ) ); + fileData.length = fread( fileData.globalMap, sizeof( GifByteType ), blobSize, fp); + fileInfo.map = fileData.globalMap; + } + } + } + } if( !fileInfo.map ) { @@ -1135,12 +1171,13 @@ on_error: // jump here on any errors to clean up struct GifLoading::Impl { public: - Impl( const std::string& url) + Impl( const std::string& url, bool isLocalResource ) : mUrl( url ) { loaderInfo.gif = nullptr; int error; loaderInfo.fileData.fileName = mUrl.c_str(); + loaderInfo.fileData.isLocalResource = isLocalResource; ReadHeader( loaderInfo, imageProperties, &error ); } @@ -1149,7 +1186,14 @@ public: { if( loaderInfo.fileData.globalMap ) { - munmap( loaderInfo.fileData.globalMap , loaderInfo.fileData.length ); + if( loaderInfo.fileData.isLocalResource ) + { + munmap( loaderInfo.fileData.globalMap , loaderInfo.fileData.length ); + } + else + { + free( loaderInfo.fileData.globalMap ); + } loaderInfo.fileData.globalMap = nullptr; } } @@ -1159,16 +1203,17 @@ public: ImageProperties imageProperties; }; -std::unique_ptr GifLoading::New( const std::string &url ) +std::unique_ptr GifLoading::New( const std::string &url, bool isLocalResource ) { - return std::unique_ptr( new GifLoading( url ) ); + return std::unique_ptr( new GifLoading( url, isLocalResource ) ); } -GifLoading::GifLoading( const std::string &url ) -: mImpl( new GifLoading::Impl( url ) ) +GifLoading::GifLoading( const std::string &url, bool isLocalResource ) +: mImpl( new GifLoading::Impl( url, isLocalResource ) ) { } + GifLoading::~GifLoading() { delete mImpl; diff --git a/adaptors/devel-api/adaptor-framework/gif-loading.h b/adaptors/devel-api/adaptor-framework/gif-loading.h old mode 100644 new mode 100755 index dd0a94e..0b8deec --- a/adaptors/devel-api/adaptor-framework/gif-loading.h +++ b/adaptors/devel-api/adaptor-framework/gif-loading.h @@ -41,15 +41,22 @@ class DALI_IMPORT_API GifLoading { public: - static std::unique_ptr New( const std::string& url ); + /** + * Create a GifLoading with the given url and resourceType. + * @param[in] url The url of the gif image to load + * @param[in] isLocalResource The true or false whether this is a local resource. + * @return A newly created GifLoading. + */ + static std::unique_ptr New( const std::string& url, bool isLocalResource ); /** * @brief Constructor * * Construct a Loader with the given URL * @param[in] url The url of the gif image to load + * @param[in] isLocalResource The true or false whether this is a local resource. */ - GifLoading( const std::string& url ); + GifLoading( const std::string& url, bool isLocalResource ); // Moveable but not copyable diff --git a/automated-tests/src/dali-adaptor/utc-Dali-GifLoading.cpp b/automated-tests/src/dali-adaptor/utc-Dali-GifLoading.cpp old mode 100644 new mode 100755 index 5bd3698..6a4fa87 --- a/automated-tests/src/dali-adaptor/utc-Dali-GifLoading.cpp +++ b/automated-tests/src/dali-adaptor/utc-Dali-GifLoading.cpp @@ -65,7 +65,7 @@ int UtcDaliGifLoadingP(void) std::vector pixelDataList; Dali::Vector frameDelayList; - std::unique_ptr gifLoading = GifLoading::New( gGif_100_None ); + std::unique_ptr gifLoading = GifLoading::New( gGif_100_None, true ); bool succeed = gifLoading->LoadAllFrames( pixelDataList, frameDelayList ); // Check that the loading succeed @@ -73,14 +73,14 @@ int UtcDaliGifLoadingP(void) VerifyLoad( pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u ); pixelDataList.clear(); - gifLoading = GifLoading::New( gGif_100_Prev ); + gifLoading = GifLoading::New( gGif_100_Prev, true ); succeed = gifLoading->LoadAllFrames( pixelDataList, frameDelayList ); // Check that the loading succeed DALI_TEST_CHECK( succeed ); VerifyLoad( pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u ); pixelDataList.clear(); - gifLoading = GifLoading::New( gGif_100_Bgnd ); + gifLoading = GifLoading::New( gGif_100_Bgnd, true ); succeed = gifLoading->LoadAllFrames( pixelDataList, frameDelayList ); // Check that the loading succeed @@ -95,7 +95,7 @@ int UtcDaliGifLoadingN(void) std::vector pixelDataList; Dali::Vector frameDelayList; - std::unique_ptr gifLoading = GifLoading::New( gGifNonExist ); + std::unique_ptr gifLoading = GifLoading::New( gGifNonExist, true ); bool succeed = gifLoading->LoadAllFrames( pixelDataList, frameDelayList ); // Check that the loading failed @@ -110,7 +110,7 @@ int UtcDaliGifLoadingN(void) int UtcDaliGifLoadingGetImageSizeP(void) { - std::unique_ptr gifLoading = GifLoading::New( gGif_100_None ); + std::unique_ptr gifLoading = GifLoading::New( gGif_100_None, true ); ImageDimensions imageSize = gifLoading->GetImageSize(); // Check that the image size is [100, 100] @@ -122,7 +122,7 @@ int UtcDaliGifLoadingGetImageSizeP(void) int UtcDaliGifLoadingGetImageSizeN(void) { - std::unique_ptr gifLoading = GifLoading::New( gGifNonExist ); + std::unique_ptr gifLoading = GifLoading::New( gGifNonExist, true ); ImageDimensions imageSize = gifLoading->GetImageSize(); // Check that it returns zero size when the gif is not valid