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_NonScale.cpp
20 * @brief This is the header file for internal util class.
27 #include <FBaseByteBuffer.h>
29 #include "FGrp_NonScale.h"
30 #include "FGrp_BitmapImpl.h"
31 #include "FGrp_BitmapCoordHolder.h"
32 #include "FGrp_BitmapUtil.h"
33 #include "FGrp_Bitmap.h"
34 #include "util/FGrp_UtilTemplate.h"
40 Tizen::Graphics::_BitmapCoordHolder*
41 _GetBitmapCoordHolder(const Tizen::Graphics::_BitmapImpl& bitmap)
44 : public Tizen::Graphics::_BitmapImpl
47 inline Tizen::Graphics::_BitmapCoordHolder* GetBitmapCoordHolder(void)
49 return this->_sharedItem->coordHolder.get();
53 return ((BitmapHacked*) &bitmap)->GetBitmapCoordHolder();
58 namespace Tizen { namespace Graphics
62 _NonScale::CreateBitmapN(const Tizen::Base::ByteBuffer& buffer, const Dimension& rq_dim, BitmapPixelFormat pixelFormat)
64 Dimension vc_dim = _ResUtil::ConvertToVirCoord(rq_dim);
66 return _NonScale::CreateBitmapN(buffer, rq_dim, pixelFormat, vc_dim);
70 _NonScale::CreateBitmapN(const Tizen::Base::ByteBuffer& buffer, const Dimension& rq_dim, BitmapPixelFormat pixelFormat,
71 const Dimension& logicalSize)
76 , rq_dim.width > 0 && rq_dim.height > 0
79 , "[E_INVALID_ARG] The reqired size(%d, %d) is invalid.", rq_dim.width, rq_dim.height);
82 , BITMAP_PIXEL_FORMAT_MIN < pixelFormat && pixelFormat < BITMAP_PIXEL_FORMAT_MAX
85 , "[E_INVALID_ARG] The given pixel format(%d) is invalid.", pixelFormat);
92 case Tizen::Graphics::BITMAP_PIXEL_FORMAT_RGB565:
95 case Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888:
96 case Tizen::Graphics::BITMAP_PIXEL_FORMAT_R8G8B8A8:
100 SysLogException(NID_GRP, E_INVALID_ARG, "The given pixel format(%d) is not supported.", pixelFormat);
107 , E_UNSUPPORTED_FORMAT
108 , "[E_UNSUPPORTED_FORMAT] The given bytes-per-pixel(%d) is not supported.", bytePerPixel);
110 int numOfBytes = buffer.GetLimit();
111 int expectedBufferSize = rq_dim.width * rq_dim.height * bytePerPixel;
114 , expectedBufferSize <= numOfBytes
117 , "[E_INVALID_ARG] The buffer size is too small. (expected: %d, actual: %d)", expectedBufferSize, numOfBytes);
120 std::auto_ptr <_BitmapImpl> bitmap(new (std::nothrow) _BitmapImpl);
126 , "[E_OUT_OF_MEMORY] _BitmapImpl is not allocated.");
128 _Bitmap* pBitmapEx = GetBitmapEx(*bitmap.get());
134 , "[E_OUT_OF_MEMORY] _Bitmap is not allocated.");
136 if (_ResUtil::NeedToConvertCoord())
138 r = pBitmapEx->Construct(buffer, rq_dim, pixelFormat);
144 , "[%s] _Bitmap::Construct() failed.", GetErrorMessage(r));
146 Dimension pc_dim = rq_dim;
147 Dimension vc_dim = logicalSize;
149 _ResUtil::Rect vc_rect(0, 0, vc_dim.width, vc_dim.height);
150 _ResUtil::Rect pc_rect(0, 0, pc_dim.width, pc_dim.height);
152 _BitmapCoordHolder* pBitmapCoordHolder = _GetBitmapCoordHolder(*bitmap.get());
154 if (pBitmapCoordHolder)
156 pBitmapCoordHolder->bitmapSize.required = vc_rect;
157 pBitmapCoordHolder->bitmapSize.phyCoord = pc_rect;
158 pBitmapCoordHolder->bitmapSize.virCoord = vc_rect;
163 r = pBitmapEx->Construct(buffer, rq_dim, pixelFormat);
169 , "[%s] _Bitmap::Construct() failed.", GetErrorMessage(r));
172 return bitmap.release();
176 _NonScale::CreateBitmapN(const Dimension& rq_dim, BitmapPixelFormat pixelFormat)
178 std::auto_ptr <_BitmapImpl> bitmap(new (std::nothrow) _BitmapImpl);
184 , "[E_OUT_OF_MEMORY] _BitmapImpl::Construct() failed.");
186 Dimension pc_dim = rq_dim;
187 Dimension vc_dim = _ResUtil::ConvertToVirCoord(pc_dim);
189 result r = bitmap->Construct(vc_dim, pixelFormat);
195 , "[%s] _Bitmap::Construct() failed.", GetErrorMessage(r));
197 return bitmap.release();
200 }} // Tizen::Graphics