Cleaning up and optimizing scene-graph-material and scene-graph-renderer
[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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
18 // CLASS HEADER
19 #include <dali/integration-api/image-data.h>
20
21 // INTERNAL INCLUDES
22
23 // EXTERNAL INCLUDES
24
25 namespace Dali
26 {
27
28 namespace Integration
29 {
30
31 ImageData::ImageData( const size_t numBytes, const unsigned imageWidth, const unsigned imageHeight, const Pixel::Format pixelFormat ) :
32   mData( new uint8_t[numBytes] ),
33   dataSize( numBytes ),
34   imageWidth( imageWidth ),
35   imageHeight( imageHeight ),
36   pixelFormat( pixelFormat ),
37   mAlphaChannelUsed( ALPHA_USAGE_UNDETERMINED )
38 {
39   DALI_ASSERT_DEBUG( numBytes > 0U && imageWidth > 0U && imageHeight > 0U );
40 }
41
42 ImageData::ImageData( uint8_t * const imageBuffer, const size_t numBytes, const unsigned imageWidth, const unsigned imageHeight, const Pixel::Format pixelFormat ) :
43   mData( imageBuffer ),
44   dataSize( numBytes ),
45   imageWidth( imageWidth ),
46   imageHeight( imageHeight ),
47   pixelFormat( pixelFormat ),
48   mAlphaChannelUsed( ALPHA_USAGE_UNDETERMINED )
49 {
50   DALI_ASSERT_DEBUG( imageBuffer != 0 && numBytes > 0U && imageWidth > 0U && imageHeight > 0U );
51 }
52
53 ImageData::~ImageData()
54 {
55   delete[] mData;
56 }
57
58 ImageDataPtr ImageData::New(  const BufferSize numBytes, unsigned imageWidth, unsigned imageHeight, Pixel::Format pixelFormat )
59 {
60   DALI_ASSERT_DEBUG( numBytes.bufferSize > 0 && "Zero allocations are pointless if also harmless."  );
61   DALI_ASSERT_DEBUG( imageWidth > 0 && imageHeight > 0 && "Zero dimensioned images are pointless if also harmless." );
62   return ImageDataPtr( new ImageData( numBytes, imageWidth, imageHeight, pixelFormat ) );
63 }
64
65 ImageDataPtr ImageData::New( uint8_t * const imageBuffer, const BufferSize numBytes, unsigned imageWidth, unsigned imageHeight, Pixel::Format pixelFormat )
66 {
67   DALI_ASSERT_DEBUG( numBytes.bufferSize > 0 && "Zero-length buffers are pointless if also harmless."  );
68   DALI_ASSERT_DEBUG( imageWidth > 0 && imageHeight > 0 && "Zero dimensioned images are pointless if also harmless." );
69   return ImageDataPtr( new ImageData( imageBuffer, numBytes, imageWidth, imageHeight, pixelFormat ) );
70 }
71
72 ImageDataPtr NewBitmapImageData( unsigned imageWidth, unsigned imageHeight, Pixel::Format pixelFormat )
73 {
74   DALI_ASSERT_DEBUG( pixelFormat <= Pixel::BGRA8888 && "Pixel format must be an addressable one." );
75   const size_t numBytes = imageWidth * imageHeight * Pixel::GetBytesPerPixel( pixelFormat );
76
77   return ImageData::New( BufferSize(numBytes), imageWidth, imageHeight, pixelFormat );
78 }
79
80 } //namespace Integration
81
82 } //namespace Dali
83