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_UtilScratchpad.h
20 * @brief This is the header file for internal ScratchPad class.
24 #ifndef _FGRP_INTERNAL_UTIL_SCRATCHPAD_H_
25 #define _FGRP_INTERNAL_UTIL_SCRATCHPAD_H_
28 namespace Tizen { namespace Graphics
41 explicit ColorKey(unsigned long _colorKey)
47 explicit ColorKey(unsigned long _a, unsigned long _r, unsigned long _g, unsigned long _b)
70 colorKey = (_a << 24) | (_r << 16) | (_g << 8) | (_b << 0);
74 unsigned long colorKey;
77 // external buffer manipulation tool
78 template<typename Pixel>
87 typedef void (*FillRectFunc)(Pixel* pDest32, int w, int h, int pitch, unsigned long color, unsigned long opacity);
88 typedef void (*BitBltFunc)(Pixel* pDest32, int w, int h, int pitch, Pixel* pSour32, int imagePitch, unsigned long opacity,
91 ScratchPad(Pixel* pBuffer, int width, int height, int pitch, ColorKey colorKey = ColorKey())
95 , __xPitch(sizeof(Pixel))
97 , __colorKey(colorKey)
98 , __fnFillRect(__FillRect)
99 , __fnBitBlt(__BitBlt)
101 __depth = sizeof(Pixel) * 8;
102 __bytesPerLine = pitch * sizeof(Pixel);
105 void DrawPoint(int x, int y, Pixel color)
107 if (!__IsInRegion(x, y))
112 *__GetAddress(x, y) = color;
115 void FillRect(int x, int y, int w, int h, Pixel color, unsigned long opacity = 255)
117 if (!__FitToRegion(x, y, w, h))
122 __fnFillRect(__GetAddress(x, y), w, h, __yPitch, color, opacity);
125 void BitBlt(int xDest, int yDest, ScratchPad* pImage, int xSour, int ySour, int wSour, int hSour, unsigned long opacity = 255)
136 if (!pImage->__FitToRegion(xSour, ySour, wSour, hSour))
141 xDest += (xSour - x);
142 yDest += (ySour - y);
149 if (!__FitToRegion(xDest, yDest, wSour, hSour))
154 xSour += (xDest - x);
155 ySour += (yDest - y);
158 int srcPitch = pImage->__bytesPerLine / (pImage->__depth / 8);
160 __fnBitBlt(__GetAddress(xDest, yDest), wSour, hSour, __yPitch, pImage->__GetAddress(xSour,
161 ySour), srcPitch, opacity,
165 int GetWidth(void) const
170 int GetHeight(void) const
175 void RegisterFillRect(FillRectFunc fnFillRect)
177 __fnFillRect = (fnFillRect) ? fnFillRect : __FillRect;
180 void RegisterBitBlt(BitBltFunc fnBitBlt)
182 __fnBitBlt = (fnBitBlt) ? fnBitBlt : __BitBlt;
185 // for internal purposes
186 void GetBuffer(Pixel*& pAddr, int& pitch) const
192 // for internal purposes
193 ColorKey GetColorKey(void) const
198 // for internal purposes
199 void SetColorKey(ColorKey colorKey)
201 __colorKey = colorKey;
204 // for internal purposes
205 void SetPitch(int depth, int bytesPerLine)
208 __xPitch = depth / 8;
209 __bytesPerLine = bytesPerLine;
213 bool __IsInRegion(int x, int y)
215 return (x >= 0 && x < __width && y >= 0 && y < __height);
218 bool __FitToRegion(int& x1, int& y1, int& w, int& h)
223 x1 = (x1 < 0) ? 0 : x1;
224 y1 = (y1 < 0) ? 0 : y1;
225 x2 = (x2 > __width) ? __width : x2;
226 y2 = (y2 > __height) ? __height : y2;
231 return (w >= 0) && (h >= 0);
234 Pixel* __GetAddress(int x, int y)
236 unsigned char* pBuffer = (unsigned char*) (__pBuffer) + y * __bytesPerLine;
237 return (Pixel*) (pBuffer + (x * __xPitch));
240 static void __FillRect(Pixel* pDest, int w, int h, int pitch, unsigned long color, unsigned long opacity);
241 static void __BitBlt(Pixel* pDest, int w, int h, int pitch, Pixel* pSour, int imagePitch, unsigned long opacity, ColorKey srcColorKey);
253 FillRectFunc __fnFillRect;
254 BitBltFunc __fnBitBlt;
257 } // Tizen::Graphics::_Util
259 }} // Tizen::Graphics
261 #endif // #ifndef _FGRP_INTERNAL_UTIL_SCRATCHPAD_H_