[Tizen] Add GetOriginalImageSize() considering rotation 92/252492/7 accepted/tizen/6.0/unified/20210129.124047 submit/tizen_6.0/20210129.175201
authorSunghyun Kim <scholb.kim@samsung.com>
Fri, 29 Jan 2021 01:47:22 +0000 (10:47 +0900)
committerSunghyun Kim <scholb.kim@samsung.com>
Fri, 29 Jan 2021 08:06:56 +0000 (17:06 +0900)
Change-Id: I4459c44e15a06ca1d585b8493ad569741db5f055

dali/devel-api/adaptor-framework/image-loader-input.h
dali/devel-api/adaptor-framework/image-loading.cpp
dali/devel-api/adaptor-framework/image-loading.h
dali/internal/imaging/common/image-loader.cpp
dali/internal/imaging/common/image-loader.h
dali/internal/imaging/common/loader-jpeg-turbo.cpp

index 830b33c..99265f9 100644 (file)
@@ -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);
index eac5e61..5972bde 100644 (file)
@@ -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);
index b00cd28..9786848 100644 (file)
@@ -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.
index 5980796..b5dcf4b 100755 (executable)
@@ -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;
index a7c42a0..8168299 100644 (file)
@@ -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.
  *
index 1848a1c..f321f03 100755 (executable)
@@ -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 );