Revert "[SRUK] Bitmap core patch 2 of 4 - Replace all uses of the Bitmap class with...
[platform/core/uifw/dali-core.git] / dali / integration-api / image-data.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // CLASS HEADER
18 #include <dali/integration-api/image-data.h>
19
20 // INTERNAL INCLUDES
21
22 // EXTERNAL INCLUDES
23
24 namespace Dali
25 {
26
27 namespace Integration
28 {
29
30 ImageData::ImageData( const size_t numBytes, const unsigned imageWidth, const unsigned imageHeight, const Pixel::Format pixelFormat ) :
31   mData( new uint8_t[numBytes] ),
32   dataSize( numBytes ),
33   imageWidth( imageWidth ),
34   imageHeight( imageHeight ),
35   pixelFormat( pixelFormat ),
36   mAlphaChannelUsed( ALPHA_USAGE_UNDETERMINED )
37 {
38   DALI_ASSERT_DEBUG( numBytes > 0U && imageWidth > 0U && imageHeight > 0U );
39 }
40
41 ImageData::ImageData( uint8_t * const imageBuffer, const size_t numBytes, const unsigned imageWidth, const unsigned imageHeight, const Pixel::Format pixelFormat ) :
42   mData( imageBuffer ),
43   dataSize( numBytes ),
44   imageWidth( imageWidth ),
45   imageHeight( imageHeight ),
46   pixelFormat( pixelFormat ),
47   mAlphaChannelUsed( ALPHA_USAGE_UNDETERMINED )
48 {
49   DALI_ASSERT_DEBUG( imageBuffer != 0 && numBytes > 0U && imageWidth > 0U && imageHeight > 0U );
50 }
51
52 ImageData::~ImageData()
53 {
54   delete[] mData;
55 }
56
57 ImageDataPtr ImageData::New(  const BufferSize numBytes, unsigned imageWidth, unsigned imageHeight, Pixel::Format pixelFormat )
58 {
59   DALI_ASSERT_DEBUG( numBytes.bufferSize > 0 && "Zero allocations are pointless if also harmless."  );
60   DALI_ASSERT_DEBUG( imageWidth > 0 && imageHeight > 0 && "Zero dimensioned images are pointless if also harmless." );
61   return ImageDataPtr( new ImageData( numBytes, imageWidth, imageHeight, pixelFormat ) );
62 }
63
64 ImageDataPtr ImageData::New( uint8_t * const imageBuffer, const BufferSize numBytes, unsigned imageWidth, unsigned imageHeight, Pixel::Format pixelFormat )
65 {
66   DALI_ASSERT_DEBUG( numBytes.bufferSize > 0 && "Zero-length buffers are pointless if also harmless."  );
67   DALI_ASSERT_DEBUG( imageWidth > 0 && imageHeight > 0 && "Zero dimensioned images are pointless if also harmless." );
68   return ImageDataPtr( new ImageData( imageBuffer, numBytes, imageWidth, imageHeight, pixelFormat ) );
69 }
70
71 ImageDataPtr NewBitmapImageData( unsigned imageWidth, unsigned imageHeight, Pixel::Format pixelFormat )
72 {
73   DALI_ASSERT_DEBUG( pixelFormat <= Pixel::BGRA8888 && "Pixel format must be an addressable one." );
74   const size_t numBytes = imageWidth * imageHeight * Pixel::GetBytesPerPixel( pixelFormat );
75
76   return ImageData::New( BufferSize(numBytes), imageWidth, imageHeight, pixelFormat );
77 }
78
79 } //namespace Integration
80
81 } //namespace Dali
82