TizenRefApp-8274 [Gallery] Add resolution information into MediaItem 91/122191/1
authorIgor Nazarov <i.nazarov@samsung.com>
Thu, 30 Mar 2017 12:16:21 +0000 (15:16 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Thu, 30 Mar 2017 12:16:50 +0000 (15:16 +0300)
- Added MediaItem::getResolution() method;
- Added ImageGrid::ItemParams::aspectX/Y members.

Change-Id: I0d9cbc8a6fd36b7858d89adc00c8aee1f69e13c5

inc/model/MediaItem.h
inc/presentation/ImageGrid.h
src/model/MediaItem.cpp
src/model/helpers.cpp
src/model/helpers.h
src/presentation/ImageGrid.cpp

index eab79d9a3e5b29ffbad966243a905b6b5715729f..0e8ff4645efc28c868a2e7987a47a61dc61ab7ce 100644 (file)
@@ -33,6 +33,8 @@ namespace gallery {
                bool isValid() const;
                MediaType getType() const;
 
+               void getResolution(int &x, int &y) const;
+
                const std::string &getFilePath() const;
 
                ucl::Result getThumbnailPath(ThumbnailPathGetCb cb) const;
@@ -44,6 +46,7 @@ namespace gallery {
                MediaItem(MediaType type);
 
                ucl::Result prepare(media_info_h media);
+               ucl::Result prepareImage(image_meta_h imageMeta);
 
        private:
                ucl::Result initThumbPath(media_info_h media) const;
@@ -63,6 +66,8 @@ namespace gallery {
                const MediaType m_type;
                std::string m_mediaId;
                std::string m_filePath;
+               int m_resolutionX;
+               int m_resolutionY;
                mutable media_info_h m_media;
                mutable std::string m_thumbPath;
                mutable std::unique_ptr<ThumbCbProxy> m_thumbCbProxy;
index fd1f3c79419c65d66dc5c4079303cea3651eb854..baea32da069829b12b1f6efbae5f09fd2e170de2 100644 (file)
@@ -50,6 +50,8 @@ namespace gallery {
 
                struct ItemParams {
                        int flags;
+                       int aspectX;
+                       int aspectY;
                        std::string imagePath;
                        std::string bgImagePath;
                };
index 92bdaf159a25b0753375ed68642c385a4880665d..7a492f5eee446d44b016ab3880c1419c973ddf3a 100644 (file)
@@ -25,6 +25,8 @@ namespace gallery {
        MediaItem::MediaItem(const MediaType type) :
                m_type(type),
                m_media(nullptr),
+               m_resolutionX(0),
+               m_resolutionY(0),
                m_isValid(false)
        {
        }
@@ -72,12 +74,36 @@ namespace gallery {
                        LOG_RETURN(RES_FAIL, "getProperty(file_path) failed!");
                }
 
+               if (m_type == MediaType::IMAGE) {
+                       image_meta_h imageMeta = nullptr;
+                       const int ret = media_info_get_image(media, &imageMeta);
+                       if ((ret != 0) || !imageMeta) {
+                               LOG_RETURN(RES_FAIL, "media_info_get_image() failed: %d", ret);
+                       }
+                       const Result result = prepareImage(imageMeta);
+                       image_meta_destroy(imageMeta);
+                       FAIL_RETURN(result, "prepareImage() failed!");
+               }
+
                m_isValid = true;
 
                return RES_OK;
        }
 
-       Result MediaItem::initThumbPath(media_info_h media) const
+       Result MediaItem::prepareImage(const image_meta_h imageMeta)
+       {
+               if (!getProperty(imageMeta, image_meta_get_width, m_resolutionX)) {
+                       LOG_RETURN(RES_FAIL, "getProperty(image_width) failed!");
+               }
+
+               if (!getProperty(imageMeta, image_meta_get_height, m_resolutionY)) {
+                       LOG_RETURN(RES_FAIL, "getProperty(image_width) failed!");
+               }
+
+               return RES_OK;
+       }
+
+       Result MediaItem::initThumbPath(const media_info_h media) const
        {
                if (!getProperty(media, media_info_get_thumbnail_path,
                                m_thumbPath, true)) {
@@ -107,6 +133,12 @@ namespace gallery {
                return m_type;
        }
 
+       void MediaItem::getResolution(int &x, int &y) const
+       {
+               x = m_resolutionX;
+               y = m_resolutionY;
+       }
+
        const std::string &MediaItem::getFilePath() const
        {
                return m_filePath;
index c605e6a8004758913d9642c8889112cff3aeabed..fe340d0a8548194a4bcbadbb3e952263be327482 100644 (file)
@@ -40,5 +40,16 @@ namespace gallery {
 
                return true;
        }
-}
 
+       bool getProperty(image_meta_h imageMeta,
+                       int (*get)(image_meta_h imageMeta, int *value),
+                       int &result, bool mayBeZero)
+       {
+               const int ret = get(imageMeta, &result);
+               if ((ret != 0) || (!mayBeZero && !result)) {
+                       ELOG("get() failed: %d", ret);
+                       return false;
+               }
+               return true;
+       }
+}
index 47f9724e11b5dd8c67311739bd2648dcae4402d3..dc41e6870cc83d78f551b7e0e629ee503787ad95 100644 (file)
@@ -26,6 +26,10 @@ namespace gallery {
        bool getProperty(media_info_h media,
                        int (*get)(media_info_h media, char **value),
                        std::string &result, bool optional = false);
+
+       bool getProperty(image_meta_h imageMeta,
+                       int (*get)(image_meta_h imageMeta, int *value),
+                       int &result, bool mayBeZero = false);
 }
 
 #include "helpers.hpp"
index 25b247b488a36670b6b2c063594d20785e8cf931..99cf0f5f995b9302116cd13ab117c999e048296a 100644 (file)
@@ -314,8 +314,11 @@ namespace gallery {
                                evas_object_image_file_set(*m_bgImage,
                                                params.bgImagePath.c_str(), NULL);
 
-                               int w, h;
-                               evas_object_image_size_get(*m_bgImage, &w, &h);
+                               int w = params.aspectX;
+                               int h = params.aspectY;
+                               if ((w == 0) || (h == 0)) {
+                                       evas_object_image_size_get(*m_bgImage, &w, &h);
+                               }
                                m_bgImage->setARHint(WidgetARHint::NEITHER, w, h);
 
                                makeWhite(*m_bgImage);