Modify DrawBitmap with flip For AlphaConstant and CompositeMode
authorhoonik.lee <hoonik.lee@samsung.com>
Tue, 9 Apr 2013 13:13:26 +0000 (22:13 +0900)
committerhoonik.lee <hoonik.lee@samsung.com>
Tue, 9 Apr 2013 13:42:54 +0000 (22:42 +0900)
Change-Id: Id15a2bd87187f99ba7c421bd3bfc5325d486a3fe
Signed-off-by: hoonik.lee <hoonik.lee@samsung.com>
src/graphics/FGrp_Canvas.cpp
src/graphics/FGrp_Canvas.h
src/graphics/FGrp_CanvasImpl.cpp
src/graphics/FGrp_CanvasPixman.cpp
src/graphics/FGrp_CanvasPixman.h

index 2bfebd8..3608461 100755 (executable)
@@ -1954,7 +1954,7 @@ _Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap
 }
 
 result
-_Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir)
+_Canvas::DrawBitmap(const _Util::Point<double>& pointD, const _Bitmap& bitmap, FlipDirection dir)
 {
        SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
 
@@ -1965,6 +1965,12 @@ _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir
        this->__GetClipBounds(clipRect);
 
        {
+               _Util::Point<int> point =
+               {
+                       _DoubleToIntForPos(pointD.x),
+                       _DoubleToIntForPos(pointD.y)
+               };
+
                _Util::Pixmap* pFlippedImage = 0;
 
                {
@@ -1991,7 +1997,7 @@ _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir
                {
                        bool pass = false;
 
-                       if (!this->__useStableRenderer && alphaConstant >= 255 && !bitmap.__hasMaskingColor)
+                       if (!this->__useStableRenderer && pFlippedImage->depth == 32)
                        {
                                _Util::LockManager dstLock(*this);
                                SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.");
@@ -2002,7 +2008,20 @@ _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir
                                        _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
                                        _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
 
-                                       pass = _Pixman::FlipPixmap(dstImage, *pFlippedImage, GetDrawingQuality(), GetCompositeMode(), point.x - clipRect.x, point.y - clipRect.y);
+                                       if  (alphaConstant < 255)
+                                       {
+                                               std::unique_ptr<_Util::Pixmap> modifiedSrcImage(pFlippedImage->GetAlphaAttenuatedPixmap(alphaConstant));
+
+                                               if (modifiedSrcImage != null)
+                                               {
+                                                       pass = _Pixman::CopyPixmap(dstImage, *modifiedSrcImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
+                                               }
+                                       }
+
+                                       if (!pass)
+                                       {
+                                               pass = _Pixman::CopyPixmap(dstImage, *pFlippedImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
+                                       }
                                }
                        }
 
index b94c628..712ebc2 100644 (file)
@@ -156,7 +156,7 @@ public:
        result DrawBitmap(const _Util::Rectangle<double>& rect, const _Bitmap& bitmap);
        result DrawBitmap(const _Util::Rectangle<double>& destRect, const _Bitmap& srcBitmap, const _Util::Rectangle<double>& srcRect);
        result DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect, bool copyOnly = false);
-       result DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir);
+       result DrawBitmap(const _Util::Point<double>& point, const _Bitmap& bitmap, FlipDirection dir);
        result DrawBitmap(const _Util::Point<double>& point, const _Bitmap& bitmap, const _Util::Point<double>& pivot, double degree);
        result DrawNinePatchedBitmap(const Rectangle& rect, const _Bitmap& bitmap);
        result DrawNineTiledBitmap(const Rectangle& rect, const _Bitmap& bitmap);
index 3fcef9a..e9420a2 100755 (executable)
@@ -1245,43 +1245,7 @@ _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap, FlipDir
 {
        SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
 
-       SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
-
-       switch (dir)
-       {
-       case FLIP_DIRECTION_HORIZONTAL:
-       case FLIP_DIRECTION_VERTICAL:
-               break;
-       default:
-               SysTryReturnResult(NID_GRP, 0, E_INVALID_ARG, "FlipStyle(%d) is invalid.", dir);
-               break;
-       }
-
-       EXTRACT_BITMAPEX(pBitmapEx, bitmap);
-
-       if (_ResUtil::NeedToConvertCoord())
-       {
-               Tizen::Graphics::Dimension virSize;
-               Tizen::Graphics::Dimension phySize;
-               bool lazyScaling = Tizen::Graphics::_IsLazyScalingBitmap(bitmap, virSize, phySize);
-
-               Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
-
-               if (lazyScaling)
-               {
-                       EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
-
-                       return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx, dir);
-               }
-               else
-               {
-                       return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx, dir);
-               }
-       }
-       else
-       {
-               return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx, dir);
-       }
+       return this->DrawBitmap(FloatPoint(float(vcPoint.x), float(vcPoint.y)), bitmap, dir);
 }
 
 result
@@ -1311,24 +1275,24 @@ _CanvasImpl::DrawBitmap(const FloatPoint& vcPointF, const _BitmapImpl& bitmap, F
 
                FloatPoint pcPointF = _ResUtil::ConvertToPhyCoord(vcPointF);
 
-               Point pcPoint(_FloatToIntForPos(pcPointF.x), _FloatToIntForPos(pcPointF.y));
+               _Util::Point<double> pcPointD = _Util::Convert<FloatPoint, _Util::Point<double> >(pcPointF);
 
                if (lazyScaling)
                {
                        EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
 
-                       return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx, dir);
+                       return this->_pNativeCanvas->DrawBitmap(pcPointD, *pScaledBitmapEx, dir);
                }
                else
                {
-                       return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx, dir);
+                       return this->_pNativeCanvas->DrawBitmap(pcPointD, *pBitmapEx, dir);
                }
        }
        else
        {
-               Point vcPoint(_FloatToIntForPos(vcPointF.x), _FloatToIntForPos(vcPointF.y));
+               _Util::Point<double> vcPointD = _Util::Convert<FloatPoint, _Util::Point<double> >(vcPointF);
 
-               return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx, dir);
+               return this->_pNativeCanvas->DrawBitmap(vcPointD, *pBitmapEx, dir);
        }
 }
 
index c53f543..8612dca 100644 (file)
@@ -308,80 +308,6 @@ bool CompositePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Grap
        return false;
 }
 
-bool ClipPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, pixman_op_t rop, pixman_filter_t filter, pixman_repeat_t repeatMethod, int xDest, int yDest)
-{
-       Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanDst;
-
-       switch (dstImage.depth)
-       {
-       case 16:
-               pPixmanDst.Bind(pixman_image_create_bits(PIXMAN_r5g6b5, dstImage.width, dstImage.height, (uint32_t*)dstImage.pBitmap, dstImage.bytesPerLine));
-               break;
-       case 32:
-               pPixmanDst.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, dstImage.width, dstImage.height, (uint32_t*)dstImage.pBitmap, dstImage.bytesPerLine));
-               break;
-       default:
-               return false;
-       }
-
-       if (pPixmanDst)
-       {
-               std::auto_ptr<Tizen::Graphics::_Util::Pixmap> premultipliedSrcImage;
-               Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanSrc;
-               Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanMsk;
-
-               switch (srcImage.depth)
-               {
-               case 16:
-                       pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_r5g6b5, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
-                       break;
-               case 32:
-                       if (srcImage.isPremultiplied || rop == PIXMAN_OP_COPY)
-                       {
-                               pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
-                       }
-                       else
-                       {
-                               premultipliedSrcImage.reset(srcImage.GetPremultipliedPixmap());
-
-                               if (premultipliedSrcImage.get())
-                               {
-                                       pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, premultipliedSrcImage->width, premultipliedSrcImage->height, (uint32_t*)premultipliedSrcImage->pBitmap, premultipliedSrcImage->bytesPerLine));
-                               }
-                               else
-                               {
-                                       // slow but it does not create additional buffer
-                                       pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_x8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
-                                       pPixmanMsk.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
-
-                                       if (pPixmanMsk == null)
-                                       {
-                                               return false;
-                                       }
-                               }
-                       }
-                       break;
-               default:
-                       return false;
-               }
-
-               if (pPixmanSrc)
-               {
-                       if (rop == PIXMAN_OP_COPY)
-                       {
-                               rop = PIXMAN_OP_SRC;
-                       }
-
-                       pixman_image_set_repeat(pPixmanSrc, PIXMAN_REPEAT_NORMAL);
-                       pixman_image_composite32(rop, pPixmanSrc, pPixmanMsk, pPixmanDst, 0, 0, 0, 0, xDest, yDest, srcImage.width, srcImage.height);
-
-                       return true;
-               }
-       }
-
-       return false;
-}
-
 bool ResizePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapScalingQuality scalingQuality)
 {
        if (dstImage.width <= 0 || dstImage.height <= 0)
@@ -484,19 +410,6 @@ bool RotatePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphic
        return CompositePixmap(dstImage, srcImage, rop, filter, transform, PIXMAN_REPEAT_NONE);
 }
 
-bool FlipPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode, int xDest, int yDest)
-{
-       if (dstImage.width <= 0 || dstImage.height <= 0)
-       {
-               return true;
-       }
-
-       pixman_op_t rop = Tizen::Graphics::_Pixman::GetRop(compositeMode);
-       pixman_filter_t filter = Tizen::Graphics::_Pixman::GetFilter(drawingQuality);
-
-       return ClipPixmap(dstImage, srcImage, rop, filter, PIXMAN_REPEAT_REFLECT, xDest, yDest);
-}
-
 } // _Pixman
 
 }} // Tizen::Graphics
index 1bf1dbc..b1ab7a7 100644 (file)
@@ -59,9 +59,6 @@ ResizePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_U
 bool
 RotatePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode, double xDest, double yDest, double degree, double xPivot, double yPivot);
 
-bool
-FlipPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode, int xDest, int yDest);
-
 } // Tizen::Graphics::_Pixman
 
 }} // Tizen::Graphics