Modified the bitmap scaling
authorJongWoo Lee <jongwoo718.lee@samsung.com>
Mon, 24 Jun 2013 04:06:31 +0000 (09:36 +0530)
committerJongWoo Lee <jongwoo718.lee@samsung.com>
Mon, 24 Jun 2013 04:06:31 +0000 (09:36 +0530)
Change-Id: I647f21b2a1cbb284d2c2305bbc0724030bfd8fa4
Signed-off-by: JongWoo Lee <jongwoo718.lee@samsung.com>
src/ui/controls/FUiCtrl_GalleryCanvas.cpp
src/ui/controls/FUiCtrl_GalleryPresenter.cpp
src/ui/controls/FUiCtrl_GalleryViewEventHandler.cpp
src/ui/inc/FUiCtrl_GalleryCanvas.h

index bc28487..160be62 100644 (file)
@@ -252,6 +252,7 @@ _GalleryCanvas::LoadImage(void)
 {
        Canvas* pCanvas = null;
        result r = E_SUCCESS;
+       Bitmap* pScaledImage = null;
 
        if (IsNeedUpdateImage() == true)
        {
@@ -269,12 +270,17 @@ _GalleryCanvas::LoadImage(void)
                        r = pCanvas->Clear();
                        SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-                       r = pCanvas->DrawBitmap(rect, *pImage->GetInternalBitmap());
+                       pScaledImage = ScaledBitmapN(pImage->GetInternalBitmap(), Dimension(rect.width, rect.height));
+                       r = GetLastResult();
+                       SysTryCatch(NID_UI_CTRL, pScaledImage != null, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+                       r = pCanvas->DrawBitmap(Point(0,0), *pScaledImage);
                        SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
                        r = GetImageVisualElement().SetFlushNeeded();
                        SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
+                       delete pScaledImage;
                        delete pCanvas;
                }
                SetNeedUpdateImage(false);
@@ -283,6 +289,7 @@ _GalleryCanvas::LoadImage(void)
        return E_SUCCESS;
 
 CATCH:
+       delete pScaledImage;
        delete pCanvas;
        return r;
 }
@@ -638,6 +645,57 @@ _GalleryCanvas::GetScaledBitmapSize(_GalleryBitmap& galleryBitmap, const FloatDi
        return scaledSize;
 }
 
+Bitmap*
+_GalleryCanvas::ScaledBitmapN(Bitmap* pSourceBitmap, Dimension scaledSize)
+{
+       Bitmap* pScaledBitmap = new (std::nothrow) Bitmap();
+       SysTryReturn(NID_UI_CTRL, pScaledBitmap != null, null, E_OUT_OF_MEMORY,
+                                       "[E_OUT_OF_MEMORY] Failed to allocate the memory for the Bitmap.");
+
+       FloatRectangle rect(0, 0, pSourceBitmap->GetWidthF(), pSourceBitmap->GetHeightF());
+       int share = 1;
+       int widthShare = rect.width / scaledSize.width;
+       int heightShare = rect.height / scaledSize.height;
+       int power = 0;
+       Dimension realScaleSize = scaledSize;
+
+       result r = pScaledBitmap->Construct(*pSourceBitmap, rect);
+       SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+       if (widthShare > heightShare)
+       {
+               share = widthShare;
+       }
+       else
+       {
+               share = heightShare;
+       }
+
+
+       while (share > pow(2, (power + 1)))
+       {
+               power++;
+       }
+
+       r = pScaledBitmap->SetScalingQuality(BITMAP_SCALING_QUALITY_HIGH);
+       SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+       for (; power >= 0; power--)
+       {
+               realScaleSize.width = scaledSize.width * pow(2, power);
+               realScaleSize.height = scaledSize.height * pow(2, power);
+               r = pScaledBitmap->Scale(realScaleSize);
+               SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+       }
+
+       return pScaledBitmap;
+
+CATCH:
+       delete pScaledBitmap;
+
+       return null;
+}
+
 
 // _GalleryRootCanvas
 _GalleryRootCanvas*
index 5b7c42b..38a09f5 100644 (file)
@@ -98,8 +98,13 @@ _GalleryPresenter::~_GalleryPresenter(void)
        delete __pGalleryCoreEvent;
        delete __pEmptyGalleryImage;
        delete[] __pItemToCanvas;
-       delete __pSlideShowTimer;
-       __pSlideShowTimer = null;
+
+       if (__pSlideShowTimer != null)
+       {
+               __pSlideShowTimer->Cancel();
+               delete __pSlideShowTimer;
+               __pSlideShowTimer = null;
+       }
 }
 
 _GalleryPresenter*
@@ -1134,6 +1139,7 @@ _GalleryPresenter::StartSlideShowTimer(int duration)
        result r = E_SUCCESS;
        if (__pSlideShowTimer != null)
        {
+               __pSlideShowTimer->Cancel();
                delete __pSlideShowTimer;
                __pSlideShowTimer = null;
        }
@@ -1150,8 +1156,12 @@ _GalleryPresenter::StartSlideShowTimer(int duration)
        return E_SUCCESS;
 
 CATCH:
-       delete __pSlideShowTimer;
-       __pSlideShowTimer = null;
+       if (__pSlideShowTimer != null)
+       {
+               __pSlideShowTimer->Cancel();
+               delete __pSlideShowTimer;
+               __pSlideShowTimer = null;
+       }
 
        return GetLastResult();
 }
@@ -1159,8 +1169,12 @@ CATCH:
 void
 _GalleryPresenter::StopSlideShowTimer(void)
 {
-       delete __pSlideShowTimer;
-       __pSlideShowTimer = null;
+       if (__pSlideShowTimer != null)
+       {
+               __pSlideShowTimer->Cancel();
+               delete __pSlideShowTimer;
+               __pSlideShowTimer = null;
+       }
 
        __slideShowRepeat = false;
        __slideShowPlayCount = 0;
index 915f0e0..9f58879 100644 (file)
@@ -322,6 +322,8 @@ _GalleryViewEventHandler::OnTouchPinchZoom(_GalleryViewEventInfo& eventInfo)
 bool
 _GalleryViewEventHandler::OnTouchFlicked(_GalleryViewEventInfo& eventInfo)
 {
+       SysTryReturn(NID_UI_CTRL, __pressed == true, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] not pressed state.");
+
        if (__pinchMode == true)
        {
                return true;
index efd4d9c..91337f5 100644 (file)
@@ -121,6 +121,7 @@ private:
        void SetImageVisualElement(Tizen::Ui::Animations::_VisualElement& visualElement);
        void SetFrameVisualElement(Tizen::Ui::Animations::_VisualElement& visualElement);
        void SetAnimation(Tizen::Ui::Animations::VisualElementPropertyAnimation& animation);
+       Tizen::Graphics::Bitmap* ScaledBitmapN(Tizen::Graphics::Bitmap* pSourceBitmap, Tizen::Graphics::Dimension scaledSize);
 
 private:
        Tizen::Ui::Animations::_VisualElement* __pImageVisualElement;