2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrp_CanvasPixman.cpp
20 * @brief This is the implementation file for the pixman solution.
26 #include "FGrp_CanvasPixman.h"
27 #include "util/FGrp_UtilTemplate.h"
30 namespace Tizen { namespace Graphics
37 AutoDeletor<pixman_image_t>::~AutoDeletor(void)
41 pixman_image_unref(__pPtr);
50 pixman_op_t GetRop(Tizen::Graphics::BlendingMode blendingMode)
54 case BLENDING_MODE_CLEAR:
55 return PIXMAN_OP_CLEAR;
56 case BLENDING_MODE_SRC:
58 case BLENDING_MODE_DST:
60 case BLENDING_MODE_SRC_OVER:
61 return PIXMAN_OP_OVER;
62 case BLENDING_MODE_DST_OVER:
63 return PIXMAN_OP_OVER_REVERSE;
64 case BLENDING_MODE_SRC_IN:
66 case BLENDING_MODE_DST_IN:
67 return PIXMAN_OP_IN_REVERSE;
68 case BLENDING_MODE_SRC_OUT:
70 case BLENDING_MODE_DST_OUT:
71 return PIXMAN_OP_OUT_REVERSE;
72 case BLENDING_MODE_SRC_ATOP:
73 return PIXMAN_OP_ATOP;
74 case BLENDING_MODE_DST_ATOP:
75 return PIXMAN_OP_ATOP_REVERSE;
76 case BLENDING_MODE_DST_XOR:
78 case BLENDING_MODE_ADD:
80 case BLENDING_MODE_SATURATE:
81 return PIXMAN_OP_SATURATE;
82 case BLENDING_MODE_MULTIPLY:
83 return PIXMAN_OP_MULTIPLY;
84 case BLENDING_MODE_SCREEN:
85 return PIXMAN_OP_SCREEN;
86 case BLENDING_MODE_OVERLAY:
87 return PIXMAN_OP_OVERLAY;
88 case BLENDING_MODE_DARKEN:
89 return PIXMAN_OP_DARKEN;
90 case BLENDING_MODE_LIGHTEN:
91 return PIXMAN_OP_LIGHTEN;
92 case BLENDING_MODE_COLOR_DODGE:
93 return PIXMAN_OP_COLOR_DODGE;
94 case BLENDING_MODE_COLOR_BURN:
95 return PIXMAN_OP_COLOR_BURN;
96 case BLENDING_MODE_HARD_LIGHT:
97 return PIXMAN_OP_HARD_LIGHT;
98 case BLENDING_MODE_SOFT_LIGHT:
99 return PIXMAN_OP_SOFT_LIGHT;
100 case BLENDING_MODE_DIFFERENCE:
101 return PIXMAN_OP_DIFFERENCE;
102 case BLENDING_MODE_EXCLUSION:
103 return PIXMAN_OP_EXCLUSION;
105 return PIXMAN_OP_SRC;
109 pixman_filter_t GetFilter(BitmapDrawingQuality drawingQuality)
111 switch (drawingQuality)
113 case Tizen::Graphics::BITMAP_DRAWING_QUALITY_HIGH:
114 return PIXMAN_FILTER_BEST;
115 case Tizen::Graphics::BITMAP_DRAWING_QUALITY_MID:
116 return PIXMAN_FILTER_GOOD;
118 return PIXMAN_FILTER_FAST;
122 pixman_filter_t GetFilter(BitmapScalingQuality scalingQuality)
124 switch (scalingQuality)
126 case Tizen::Graphics::BITMAP_SCALING_QUALITY_HIGH:
127 return PIXMAN_FILTER_BEST;
128 case Tizen::Graphics::BITMAP_SCALING_QUALITY_MID:
129 return PIXMAN_FILTER_GOOD;
131 return PIXMAN_FILTER_FAST;
135 pixman_transform_t GetTransform(int xDest, int yDest, double degree, int xPivot, int yPivot)
137 pixman_transform_t transform;
139 double c = cos(degree * 3.141592 / 180.0);
140 double s = sin(degree * 3.141592 / 180.0);
142 pixman_transform_init_identity(&transform);
144 pixman_transform_translate(&transform, NULL, pixman_int_to_fixed(-xDest), pixman_int_to_fixed(-yDest));
145 pixman_transform_rotate(&transform, NULL, pixman_double_to_fixed(c), pixman_double_to_fixed(s));
146 pixman_transform_translate(&transform, NULL, pixman_int_to_fixed(xPivot), pixman_int_to_fixed(yPivot));
151 pixman_transform_t GetTransform(int srcWidth, int srcHeight, int dstWidth, int dstHeight)
153 pixman_transform_t transform;
155 pixman_transform_init_scale(&transform, 65536 * srcWidth / dstWidth, 65536 * srcHeight / dstHeight);
160 bool ResizePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, pixman_filter_t filter)
162 Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanDst;
164 switch (dstImage.depth)
167 pPixmanDst.Bind(pixman_image_create_bits(PIXMAN_r5g6b5, dstImage.width, dstImage.height, (uint32_t*)dstImage.pBitmap, dstImage.bytesPerLine));
170 pPixmanDst.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, dstImage.width, dstImage.height, (uint32_t*)dstImage.pBitmap, dstImage.bytesPerLine));
178 Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanSrc;
180 switch (srcImage.depth)
183 // color key is not supporting
184 pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_r5g6b5, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
187 pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
195 pixman_transform_t transform = Tizen::Graphics::_Pixman::GetTransform(srcImage.width, srcImage.height, dstImage.width, dstImage.height);
197 pixman_image_set_transform(pPixmanSrc, &transform);
199 pixman_image_set_filter(pPixmanSrc, filter, NULL, 0);
201 pixman_image_composite32(PIXMAN_OP_SRC, pPixmanSrc, 0, pPixmanDst, 0, 0, 0, 0, 0, 0, dstImage.width, dstImage.height);
210 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)
212 Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanDst;
214 switch (dstImage.depth)
217 pPixmanDst.Bind(pixman_image_create_bits(PIXMAN_r5g6b5, dstImage.width, dstImage.height, (uint32_t*)dstImage.pBitmap, dstImage.bytesPerLine));
220 pPixmanDst.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, dstImage.width, dstImage.height, (uint32_t*)dstImage.pBitmap, dstImage.bytesPerLine));
228 std::auto_ptr<Tizen::Graphics::_Util::Pixmap> premultipliedSrcImage;
230 Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanMsk;
231 Tizen::Graphics::_Util::AutoDeletor<pixman_image_t> pPixmanSrc;
233 switch (srcImage.depth)
236 // color key is not supporting
237 pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_r5g6b5, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
240 if (srcImage.isPremultiplied || rop == PIXMAN_OP_SRC)
242 pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
246 premultipliedSrcImage.reset(srcImage.GetPremultipliedPixmap());
248 if (premultipliedSrcImage.get())
250 pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, premultipliedSrcImage->width, premultipliedSrcImage->height, (uint32_t*)premultipliedSrcImage->pBitmap, premultipliedSrcImage->bytesPerLine));
254 // slow but it does not create additional buffer
255 pPixmanSrc.Bind(pixman_image_create_bits(PIXMAN_x8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
256 pPixmanMsk.Bind(pixman_image_create_bits(PIXMAN_a8r8g8b8, srcImage.width, srcImage.height, (uint32_t*)srcImage.pBitmap, srcImage.bytesPerLine));
258 if (pPixmanMsk == null)
271 pixman_image_set_transform(pPixmanSrc, &transform);
275 pixman_image_set_transform(pPixmanMsk, &transform);
278 pixman_image_set_filter(pPixmanSrc, filter, NULL, 0);
279 pixman_image_set_repeat(pPixmanSrc, repeatMethod);
281 pixman_image_composite32(rop, pPixmanSrc, pPixmanMsk, pPixmanDst, 0, 0, 0, 0, 0, 0, dstImage.width, dstImage.height);
290 bool ResizePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapScalingQuality scalingQuality)
292 if (dstImage.width <= 0 || dstImage.height <= 0)
297 pixman_filter_t filter = Tizen::Graphics::_Pixman::GetFilter(scalingQuality);
299 return ResizePixmap(dstImage, srcImage, filter);
302 bool CopyPixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::BlendingMode blendingMode)
304 if (dstImage.width <= 0 || dstImage.height <= 0)
309 pixman_op_t rop = Tizen::Graphics::_Pixman::GetRop(blendingMode);
311 pixman_filter_t filter = Tizen::Graphics::_Pixman::GetFilter(drawingQuality);
313 pixman_transform_t transform;
314 pixman_transform_init_identity(&transform);
316 return CompositePixmap(dstImage, srcImage, rop, filter, transform, PIXMAN_REPEAT_NONE);
319 bool ScalePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, Tizen::Graphics::BlendingMode blendingMode)
321 if (dstImage.width <= 0 || dstImage.height <= 0)
326 pixman_op_t rop = Tizen::Graphics::_Pixman::GetRop(blendingMode);
327 pixman_filter_t filter = Tizen::Graphics::_Pixman::GetFilter(drawingQuality);
328 pixman_transform_t transform = Tizen::Graphics::_Pixman::GetTransform(srcImage.width, srcImage.height, dstImage.width, dstImage.height);
330 return CompositePixmap(dstImage, srcImage, rop, filter, transform, PIXMAN_REPEAT_NORMAL);
333 bool RotatePixmap(Tizen::Graphics::_Util::Pixmap& dstImage, const Tizen::Graphics::_Util::Pixmap& srcImage, Tizen::Graphics::BitmapDrawingQuality drawingQuality, int xDest, int yDest, double degree, int xPivot, int yPivot)
335 if (dstImage.width <= 0 || dstImage.height <= 0)
340 pixman_filter_t filter = Tizen::Graphics::_Pixman::GetFilter(drawingQuality);
341 pixman_transform_t transform = Tizen::Graphics::_Pixman::GetTransform(xDest, yDest, degree, xPivot, yPivot);
343 return CompositePixmap(dstImage, srcImage, PIXMAN_OP_OVER, filter, transform, PIXMAN_REPEAT_NONE);
348 }} // Tizen::Graphics