From fc1757d8d1f31f7a2b99c73c21d5b719959a17ce Mon Sep 17 00:00:00 2001 From: Sunghyun Kim Date: Fri, 29 Jan 2021 10:47:22 +0900 Subject: [PATCH] [Tizen] Add GetOriginalImageSize() considering rotation Change-Id: I4459c44e15a06ca1d585b8493ad569741db5f055 --- .../adaptor-framework/image-loader-input.h | 6 ++-- dali/devel-api/adaptor-framework/image-loading.cpp | 5 +++ dali/devel-api/adaptor-framework/image-loading.h | 11 +++++- dali/internal/imaging/common/image-loader.cpp | 41 +++++++++++++++++++++- dali/internal/imaging/common/image-loader.h | 6 ++++ dali/internal/imaging/common/loader-jpeg-turbo.cpp | 28 +++++++++++++++ 6 files changed, 93 insertions(+), 4 deletions(-) diff --git a/dali/devel-api/adaptor-framework/image-loader-input.h b/dali/devel-api/adaptor-framework/image-loader-input.h index 830b33c..99265f9 100644 --- a/dali/devel-api/adaptor-framework/image-loader-input.h +++ b/dali/devel-api/adaptor-framework/image-loader-input.h @@ -51,15 +51,17 @@ public: */ struct Input { - Input(FILE* file, ScalingParameters scalingParameters = ScalingParameters(), bool reorientationRequested = true) + Input(FILE* file, ScalingParameters scalingParameters = ScalingParameters(), bool reorientationRequested = true, bool rotatedSizeRequested = false ) : file(file), scalingParameters(scalingParameters), - reorientationRequested(reorientationRequested) + reorientationRequested(reorientationRequested), + rotatedSizeRequested(rotatedSizeRequested) { } FILE* file; ScalingParameters scalingParameters; bool reorientationRequested; + bool rotatedSizeRequested; }; using LoadBitmapFunction = bool (*)(const Dali::ImageLoader::Input& input, Dali::Devel::PixelBuffer& pixelData); diff --git a/dali/devel-api/adaptor-framework/image-loading.cpp b/dali/devel-api/adaptor-framework/image-loading.cpp index eac5e61..5972bde 100644 --- a/dali/devel-api/adaptor-framework/image-loading.cpp +++ b/dali/devel-api/adaptor-framework/image-loading.cpp @@ -70,6 +70,11 @@ ImageDimensions GetOriginalImageSize(const std::string& filename) return TizenPlatform::ImageLoader::GetClosestImageSize(filename, ImageDimensions(0, 0), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, true); } +ImageDimensions GetOriginalImageSize(const std::string& filename, bool orientationCorrection) +{ + return TizenPlatform::ImageLoader::GetRotatedImageSize(filename, ImageDimensions(0, 0), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, true); +} + Devel::PixelBuffer DownloadImageSynchronously(const std::string& url, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection) { Integration::BitmapResourceType resourceType(size, fittingMode, samplingMode, orientationCorrection); diff --git a/dali/devel-api/adaptor-framework/image-loading.h b/dali/devel-api/adaptor-framework/image-loading.h index b00cd28..9786848 100644 --- a/dali/devel-api/adaptor-framework/image-loading.h +++ b/dali/devel-api/adaptor-framework/image-loading.h @@ -70,7 +70,7 @@ DALI_ADAPTOR_API ImageDimensions GetClosestImageSize( bool orientationCorrection = true); /** - * @brief Get the size of an original image + * @brief Get the size of an original image. this method will not respect any rotation of image. * @param[in] filename name of the image. * * @return dimensions to original image @@ -79,6 +79,15 @@ DALI_ADAPTOR_API ImageDimensions GetOriginalImageSize( const std::string& filename); /** + * @brief Get the size of an original image. this method will respect any rotation of image. + * @param[in] filename name of the image. + * + * @return dimensions to original image + */ +DALI_ADAPTOR_API ImageDimensions GetOriginalImageSize( + const std::string& filename, bool orientationCorrection); + +/** * @brief Load an image synchronously from a remote resource. * * @param [in] url The URL of the image file to load. diff --git a/dali/internal/imaging/common/image-loader.cpp b/dali/internal/imaging/common/image-loader.cpp index 5980796..b5dcf4b 100755 --- a/dali/internal/imaging/common/image-loader.cpp +++ b/dali/internal/imaging/common/image-loader.cpp @@ -355,7 +355,7 @@ ImageDimensions GetClosestImageSize( const std::string& filename, profile, filename ) ) { - const Dali::ImageLoader::Input input( fp, Dali::ImageLoader::ScalingParameters( size, fittingMode, samplingMode ), orientationCorrection ); + const Dali::ImageLoader::Input input( fp, Dali::ImageLoader::ScalingParameters( size, fittingMode, samplingMode ), orientationCorrection , false ); const bool read_res = headerFunction( input, width, height ); if(!read_res) @@ -417,6 +417,45 @@ ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer return ImageDimensions( width, height ); } +ImageDimensions GetRotatedImageSize( const std::string& filename, + ImageDimensions size, + FittingMode::Type fittingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection ) +{ + unsigned int width = 0; + unsigned int height = 0; + + Internal::Platform::FileReader fileReader( filename ); + FILE *fp = fileReader.GetFile(); + if (fp != NULL) + { + Dali::ImageLoader::LoadBitmapFunction loaderFunction; + Dali::ImageLoader::LoadBitmapHeaderFunction headerFunction; + Bitmap::Profile profile; + + if ( GetBitmapLoaderFunctions( fp, + GetFormatHint(filename), + loaderFunction, + headerFunction, + profile, + filename ) ) + { + const Dali::ImageLoader::Input input( fp, Dali::ImageLoader::ScalingParameters( size, fittingMode, samplingMode ), orientationCorrection , true ); + + const bool read_res = headerFunction( input, width, height ); + if(!read_res) + { + DALI_LOG_WARNING("Image Decoder failed to read header for %s\n", filename.c_str()); + } + } + else + { + DALI_LOG_WARNING("Image Decoder for %s unavailable\n", filename.c_str()); + } + } + return ImageDimensions( width, height ); +} void SetMaxTextureSize( unsigned int size ) { gMaxTextureSize = size; diff --git a/dali/internal/imaging/common/image-loader.h b/dali/internal/imaging/common/image-loader.h index a7c42a0..8168299 100644 --- a/dali/internal/imaging/common/image-loader.h +++ b/dali/internal/imaging/common/image-loader.h @@ -81,6 +81,12 @@ ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer SamplingMode::Type samplingMode, bool orientationCorrection ); +ImageDimensions GetRotatedImageSize( const std::string& filename, + ImageDimensions size, + FittingMode::Type fittingMode, + SamplingMode::Type samplingMode, + bool orientationCorrection ); + /** * @brief Set the maximum texture size. Then size can be kwown by GL_MAX_TEXTURE_SIZE. * diff --git a/dali/internal/imaging/common/loader-jpeg-turbo.cpp b/dali/internal/imaging/common/loader-jpeg-turbo.cpp index 1848a1c..f321f03 100755 --- a/dali/internal/imaging/common/loader-jpeg-turbo.cpp +++ b/dali/internal/imaging/common/loader-jpeg-turbo.cpp @@ -1121,6 +1121,34 @@ bool LoadJpegHeader( const Dali::ImageLoader::Input& input, unsigned int& width, FILE* const fp = input.file; bool success = false; + + // If rotatedSizeRequested is true, just get size + if( input.rotatedSizeRequested ) + { + unsigned int headerWidth; + unsigned int headerHeight; + if( LoadJpegHeader( fp, headerWidth, headerHeight ) ) + { + auto transform = JpegTransform::NONE; + if( input.reorientationRequested ) + { + auto exifData = LoadExifData( fp ); + if( exifData ) + { + transform = ConvertExifOrientation(exifData.get()); + } + if( transform == JpegTransform::ROTATE_90 || transform == JpegTransform::ROTATE_270 || transform == JpegTransform::TRANSPOSE || transform == JpegTransform::TRANSVERSE) + { + std::swap( headerWidth, headerHeight ); + } + } + success = true; + width = headerWidth; + height = headerHeight; + } + return success; + } + if( requiredWidth == 0 && requiredHeight == 0 ) { success = LoadJpegHeader( fp, width, height ); -- 2.7.4