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::_BitmapCoordinateHolder*
41 _GetBitmapCoordinateHolder(const Tizen::Graphics::_BitmapImpl& bitmap)
44 : public Tizen::Graphics::_BitmapImpl
47 inline Tizen::Graphics::_BitmapCoordinateHolder* GetBitmapCoordinateHolder(void)
49 return this->_sharedItem->coordHolder.get();
53 return ((BitmapHacked*) &bitmap)->GetBitmapCoordinateHolder();
58 namespace Tizen { namespace Graphics
62 _NonScale::CreateBitmapN(const Tizen::Base::ByteBuffer& buffer, const Dimension& rqDim, BitmapPixelFormat pixelFormat)
64 FloatDimension pcDimF(static_cast<float>(rqDim.width), static_cast<float>(rqDim.height));
65 FloatDimension vcDimF = _ResUtil::ConvertToVirCoord(pcDimF);
67 return _NonScale::CreateBitmapN(buffer, rqDim, pixelFormat, vcDimF);
71 _NonScale::CreateBitmapN(const Tizen::Base::ByteBuffer& buffer, const Dimension& rqDim, BitmapPixelFormat pixelFormat,
72 const FloatDimension& logicalSizeF)
77 , rqDim.width > 0 && rqDim.height > 0
80 , "[E_INVALID_ARG] The reqired size(%d, %d) is invalid.", rqDim.width, rqDim.height);
83 , BITMAP_PIXEL_FORMAT_MIN < pixelFormat && pixelFormat < BITMAP_PIXEL_FORMAT_MAX
86 , "[E_INVALID_ARG] The given pixel format(%d) is invalid.", pixelFormat);
93 case Tizen::Graphics::BITMAP_PIXEL_FORMAT_RGB565:
96 case Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888:
97 case Tizen::Graphics::BITMAP_PIXEL_FORMAT_R8G8B8A8:
101 SysLogException(NID_GRP, E_INVALID_ARG, "The given pixel format(%d) is not supported.", pixelFormat);
108 , E_UNSUPPORTED_FORMAT
109 , "[E_UNSUPPORTED_FORMAT] The given bytes-per-pixel(%d) is not supported.", bytePerPixel);
111 int numOfBytes = buffer.GetLimit();
112 int expectedBufferSize = rqDim.width * rqDim.height * bytePerPixel;
115 , expectedBufferSize <= numOfBytes
118 , "[E_INVALID_ARG] The buffer size is too small. (expected: %d, actual: %d)", expectedBufferSize, numOfBytes);
121 std::auto_ptr <_BitmapImpl> bitmap(new (std::nothrow) _BitmapImpl);
127 , "[E_OUT_OF_MEMORY] _BitmapImpl is not allocated.");
129 _Bitmap* pBitmapEx = _GetBitmapEx(*bitmap.get());
135 , "[E_OUT_OF_MEMORY] _Bitmap is not allocated.");
137 r = pBitmapEx->Construct(buffer, rqDim, pixelFormat);
143 , "[%s] _Bitmap::Construct() failed.", GetErrorMessage(r));
145 _BitmapCoordinateHolder* pBitmapCoordinateHolder = _GetBitmapCoordinateHolder(*bitmap.get());
147 if (pBitmapCoordinateHolder)
149 _Util::Dimension<float> vcDimF = { logicalSizeF.width, logicalSizeF.height };
150 _Util::Dimension<int> vcDim = { _FloatToIntForSize(vcDimF.w), _FloatToIntForSize(vcDimF.h) };
151 _Util::Dimension<int> pcDim = { rqDim.width, rqDim.height };
153 pBitmapCoordinateHolder->ResetFromPc(pcDim, vcDim, vcDimF);
156 return bitmap.release();
160 _NonScale::CreateBitmapN(const Dimension& rq_dim, BitmapPixelFormat pixelFormat)
162 std::auto_ptr <_BitmapImpl> bitmap(new (std::nothrow) _BitmapImpl);
168 , "[E_OUT_OF_MEMORY] _BitmapImpl::Construct() failed.");
170 Dimension pc_dim = rq_dim;
171 Dimension vc_dim = _ResUtil::ConvertToVirCoord(pc_dim);
173 result r = bitmap->Construct(vc_dim, pixelFormat);
179 , "[%s] _Bitmap::Construct() failed.", GetErrorMessage(r));
181 return bitmap.release();
184 }} // Tizen::Graphics