From: Igor Nazarov Date: Thu, 30 Mar 2017 12:16:21 +0000 (+0300) Subject: TizenRefApp-8274 [Gallery] Add resolution information into MediaItem X-Git-Tag: submit/tizen/20170531.142232~44 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dbede4c1a29c01ad6ebb79ecbffb36ab36c8312e;p=profile%2Fwearable%2Fapps%2Fnative%2Fgallery.git TizenRefApp-8274 [Gallery] Add resolution information into MediaItem - Added MediaItem::getResolution() method; - Added ImageGrid::ItemParams::aspectX/Y members. Change-Id: I0d9cbc8a6fd36b7858d89adc00c8aee1f69e13c5 --- diff --git a/inc/model/MediaItem.h b/inc/model/MediaItem.h index eab79d9..0e8ff46 100644 --- a/inc/model/MediaItem.h +++ b/inc/model/MediaItem.h @@ -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 m_thumbCbProxy; diff --git a/inc/presentation/ImageGrid.h b/inc/presentation/ImageGrid.h index fd1f3c7..baea32d 100644 --- a/inc/presentation/ImageGrid.h +++ b/inc/presentation/ImageGrid.h @@ -50,6 +50,8 @@ namespace gallery { struct ItemParams { int flags; + int aspectX; + int aspectY; std::string imagePath; std::string bgImagePath; }; diff --git a/src/model/MediaItem.cpp b/src/model/MediaItem.cpp index 92bdaf1..7a492f5 100644 --- a/src/model/MediaItem.cpp +++ b/src/model/MediaItem.cpp @@ -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; diff --git a/src/model/helpers.cpp b/src/model/helpers.cpp index c605e6a..fe340d0 100644 --- a/src/model/helpers.cpp +++ b/src/model/helpers.cpp @@ -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; + } +} diff --git a/src/model/helpers.h b/src/model/helpers.h index 47f9724..dc41e68 100644 --- a/src/model/helpers.h +++ b/src/model/helpers.h @@ -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" diff --git a/src/presentation/ImageGrid.cpp b/src/presentation/ImageGrid.cpp index 25b247b..99cf0f5 100644 --- a/src/presentation/ImageGrid.cpp +++ b/src/presentation/ImageGrid.cpp @@ -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);