[dali_1.1.38] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / images / pixel-data-impl.cpp
1 /*
2  * Copyright (c) 2016 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/internal/event/images/pixel-data-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <stdlib.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 PixelData::PixelData( unsigned char* buffer,
31                       unsigned int width,
32                       unsigned int height,
33                       Pixel::Format pixelFormat,
34                       Dali::PixelData::ReleaseFunction releaseFunction )
35 : mBuffer( buffer ),
36   mWidth( width ),
37   mHeight( height ),
38   mPixelFormat( pixelFormat ),
39   mReleaseFunction( releaseFunction )
40 {
41 }
42
43 PixelData::~PixelData()
44 {
45   if( mBuffer )
46   {
47     if( mReleaseFunction == Dali::PixelData::FREE)
48     {
49       free( mBuffer );
50     }
51     else
52     {
53       delete[] mBuffer;
54     }
55   }
56  }
57
58 PixelDataPtr PixelData::New(unsigned char* buffer,
59                             unsigned int width,
60                             unsigned int height,
61                             Pixel::Format pixelFormat,
62                             Dali::PixelData::ReleaseFunction releaseFunction)
63 {
64   return new PixelData( buffer, width, height, pixelFormat, releaseFunction );
65 }
66
67 unsigned int PixelData::GetWidth() const
68 {
69   return mWidth;
70 }
71
72 unsigned int PixelData::GetHeight() const
73 {
74   return mHeight;
75 }
76
77 Pixel::Format PixelData::GetPixelFormat() const
78 {
79   return mPixelFormat;
80 }
81
82 unsigned char* PixelData::GetBuffer() const
83 {
84   return mBuffer;
85 }
86
87 }// namespace Internal
88
89 }// namespace Dali