Modify DrawBitmap code when alphaConstant is less than 255
authorhoonik.lee <hoonik.lee@samsung.com>
Mon, 8 Apr 2013 07:00:21 +0000 (16:00 +0900)
committerhoonik.lee <hoonik.lee@samsung.com>
Mon, 8 Apr 2013 10:14:44 +0000 (19:14 +0900)
Change-Id: I3132873222d29de0c52b3886a322049b90a9b4ce
Signed-off-by: hoonik.lee <hoonik.lee@samsung.com>
src/graphics/FGrp_Canvas.cpp
src/graphics/FGrp_Canvas.h
src/graphics/FGrp_CanvasPixman.cpp
src/graphics/FGrp_CanvasPixman.h
src/graphics/util/FGrp_UtilPixmap.cpp

index f3a0144..6c1777d 100755 (executable)
@@ -1498,7 +1498,7 @@ _Canvas::DrawBitmap(const _Util::Point<double>& pointD, const _Bitmap& bitmap)
                                }
                        }
                        {
-                               bool isPixmanSupported = (!this->__useStableRenderer) && (alphaConstant >= 255);
+                               bool isPixmanSupported = (!this->__useStableRenderer);
 
                                if (isPixmanSupported)
                                {
@@ -1509,13 +1509,26 @@ _Canvas::DrawBitmap(const _Util::Point<double>& pointD, const _Bitmap& bitmap)
 
                                if (isPixmanSupported)
                                {
-                                               _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
-                                               _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
+                                       _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
+                                       _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
+
+                                       _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);
 
-                                               _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);
+                                       if  (alphaConstant < 255)
+                                       {
+                                               std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
 
+                                               if (modifiedSrcImage != null)
+                                               {
+                                                       pass = _Pixman::CopyPixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
+                                               }
+                                       }
+
+                                       if (!pass)
+                                       {
                                                pass = _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
+                                       }
                                }
 
                                if (!pass)
@@ -1716,7 +1729,7 @@ _Canvas::DrawBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const R
 }
 
 result
-_Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect)
+_Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect, bool copyOnly)
 {
        SysTryReturnResult(NID_GRP, &srcBitmap && srcBitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
 
@@ -1782,7 +1795,14 @@ _Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap
                                _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
                                _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
 
-                               pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode());
+                               if (copyOnly)
+                               {
+                                       pass = _Pixman::ScalePixmapOpCopy(dstImage, srcImage, GetDrawingQuality());
+                               }
+                               else
+                               {
+                                       pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode());
+                               }
                        }
 
                        if (!pass)
@@ -1795,7 +1815,14 @@ _Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap
                                _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 = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
+                               if (copyOnly)
+                               {
+                                       pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
+                               }
+                               else
+                               {
+                                       pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
+                               }
                        }
 
                }
@@ -2125,7 +2152,7 @@ _Canvas::DrawNinePatchedBitmap(const Rectangle& rect, const _Bitmap& bitmap)
                                        Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
                                        Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
 
-                                       expandedCanvas.DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
+                                       expandedCanvas.DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect, true);
 
                                        ++iter;
                                }
index 08123b8..a4928e6 100644 (file)
@@ -155,7 +155,7 @@ public:
        result DrawBitmap(const _Util::Point<double>& point, const _Bitmap& bitmap);
        result DrawBitmap(const _Util::Rectangle<double>& rect, const _Bitmap& bitmap);
        result DrawBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect);
-       result DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& 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, const _Util::Point<double>& pivot, double degree);
        result DrawNinePatchedBitmap(const Rectangle& rect, const _Bitmap& bitmap);
index 3ff8b0e..c53f543 100644 (file)
@@ -223,7 +223,7 @@ bool ResizePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphic
        return false;
 }
 
-bool CompositePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, pixman_op_t rop, pixman_filter_t filter, pixman_transform_t transform, pixman_repeat_t repeatMethod)
+bool CompositePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, int rop, pixman_filter_t filter, pixman_transform_t transform, pixman_repeat_t repeatMethod)
 {
        Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanDst;
 
@@ -253,7 +253,7 @@ bool CompositePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Grap
                        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_SRC)
+                       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));
                        }
@@ -294,7 +294,12 @@ bool CompositePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Grap
                        pixman_image_set_filter(pPixmanSrc, filter, NULL, 0);
                        pixman_image_set_repeat(pPixmanSrc, repeatMethod);
 
-                       pixman_image_composite32(rop, pPixmanSrc, pPixmanMsk, pPixmanDst, 0, 0, 0, 0, 0, 0, dstImage.width, dstImage.height);
+                       if (rop == PIXMAN_OP_COPY)
+                       {
+                               rop = PIXMAN_OP_SRC;
+                       }
+
+                       pixman_image_composite32(pixman_op_t(rop), pPixmanSrc, pPixmanMsk, pPixmanDst, 0, 0, 0, 0, 0, 0, dstImage.width, dstImage.height);
 
                        return true;
                }
@@ -331,7 +336,7 @@ bool ClipPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics:
                        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_SRC)
+                       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));
                        }
@@ -362,6 +367,11 @@ bool ClipPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics:
 
                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);
 
@@ -433,6 +443,19 @@ bool ScalePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics
        return CompositePixmap(dstImage, srcImage, rop, filter, transform, PIXMAN_REPEAT_NORMAL);
 }
 
+bool ScalePixmapOpCopy(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality)
+{
+       if (dstImage.width <= 0 || dstImage.height <= 0)
+       {
+               return true;
+       }
+
+       pixman_filter_t filter = Tizen::Graphics::_Pixman::GetFilter(drawingQuality);
+       pixman_transform_t transform = Tizen::Graphics::_Pixman::GetTransform(srcImage.width, srcImage.height, dstImage.width, dstImage.height);
+
+       return CompositePixmap(dstImage, srcImage, PIXMAN_OP_COPY, filter, transform, PIXMAN_REPEAT_NORMAL);
+}
+
 bool ScalePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode, double xDest, double yDest, double wDest, double hDest)
 {
        if (dstImage.width <= 0 || dstImage.height <= 0)
index a9e73cd..1bf1dbc 100644 (file)
@@ -30,6 +30,7 @@
 #include "FGrpBitmapCommon.h"
 #include "util/FGrp_UtilPixmap.h"
 
+#define PIXMAN_OP_COPY pixman_op_t(PIXMAN_OP_CLEAR - 1)
 
 namespace Tizen { namespace Graphics
 {
@@ -47,6 +48,9 @@ bool
 ScalePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode = COMPOSITE_MODE_SRC_OVER);
 
 bool
+ScalePixmapOpCopy(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality);
+
+bool
 ScalePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::CompositeMode compositeMode, double xDest, double yDest, double wDest, double hDest);
 
 bool
index 2bcfd58..37d0f38 100755 (executable)
@@ -393,7 +393,9 @@ _CreateAlphaAttenuatedBuffer(const _Util::Pixmap& srcImage, int alphaConstant)
                                        DestPixel alpha = ((*p) & 0xFF000000) >> 8;
                                        alpha *= attenuation;
 
-                                       *p++ = (alpha & 0xFF000000) | ((*p) & 0x00FFFFFF);
+                                       *p = (alpha & 0xFF000000) | ((*p) & 0x00FFFFFF);
+
+                                       ++p;
                                }
 
                                p += padding;