Modified the bitmap scaling
authorJongwooLee <jongwoo718.lee@samsung.com>
Fri, 14 Jun 2013 08:18:52 +0000 (17:18 +0900)
committerJongwooLee <jongwoo718.lee@samsung.com>
Fri, 14 Jun 2013 09:46:33 +0000 (18:46 +0900)
Change-Id: I976c4b5d55c3b7e81aec1d8d297d24d8d85dcdd0
Signed-off-by: JongwooLee <jongwoo718.lee@samsung.com>
src/ui/controls/FUiCtrl_GalleryCanvas.cpp
src/ui/inc/FUiCtrl_GalleryCanvas.h

index bc28487..a92fee9 100644 (file)
@@ -269,12 +269,15 @@ _GalleryCanvas::LoadImage(void)
                        r = pCanvas->Clear();
                        SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-                       r = pCanvas->DrawBitmap(rect, *pImage->GetInternalBitmap());
+                       Bitmap* pScaledImage = ScaledBitmapN(pImage->GetInternalBitmap(), Dimension(rect.width, rect.height));
+
+                       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 +286,7 @@ _GalleryCanvas::LoadImage(void)
        return E_SUCCESS;
 
 CATCH:
+       delete pScaledImage;
        delete pCanvas;
        return r;
 }
@@ -638,6 +642,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 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;