Returns the Pixel::Format of a BitmapImage's Bitmap
[platform/core/uifw/dali-core.git] / dali / public-api / images / bitmap-image.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/public-api/images/bitmap-image.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/internal/event/images/bitmap-image-impl.h>
25
26 namespace Dali
27 {
28
29 BitmapImage::BitmapImage()
30 {
31 }
32
33 BitmapImage::BitmapImage(Internal::BitmapImage* internal)
34   : Image(internal)
35 {
36 }
37
38 BitmapImage BitmapImage::DownCast( BaseHandle handle )
39 {
40   return BitmapImage( dynamic_cast<Dali::Internal::BitmapImage*>(handle.GetObjectPtr()) );
41 }
42
43 BitmapImage::~BitmapImage()
44 {
45 }
46
47 BitmapImage::BitmapImage(const BitmapImage& handle)
48 : Image(handle)
49 {
50 }
51
52 BitmapImage& BitmapImage::operator=(const BitmapImage& rhs)
53 {
54   BaseHandle::operator=(rhs);
55   return *this;
56 }
57
58 const BitmapImage BitmapImage::WHITE()
59 {
60   Internal::BitmapImage* internal = new Internal::BitmapImage(1,1,Pixel::RGBA8888, Immediate, Never);
61   PixelBuffer* pBuf = internal->GetBuffer();
62   pBuf[0] = pBuf[1] = pBuf[2] = pBuf[3] = 0xFF;
63   return BitmapImage(internal);
64 }
65
66 BitmapImage BitmapImage::New(unsigned int width, unsigned int height, Pixel::Format pixelformat)
67 {
68   DALI_ASSERT_ALWAYS( 0u != width  && "Invalid BitmapImage width requested" );
69   DALI_ASSERT_ALWAYS( 0u != height && "Invalid BitmapImage height requested" );
70
71   Internal::BitmapImagePtr internal = Internal::BitmapImage::New(width, height, pixelformat);
72   return BitmapImage(internal.Get());
73 }
74
75 BitmapImage BitmapImage::New(unsigned int width, unsigned int height, Pixel::Format pixelformat, LoadPolicy loadPol, ReleasePolicy releasePol)
76 {
77   DALI_ASSERT_ALWAYS( 0u != width  && "Invalid BitmapImage width requested" );
78   DALI_ASSERT_ALWAYS( 0u != height && "Invalid BitmapImage height requested" );
79
80   Internal::BitmapImagePtr internal = Internal::BitmapImage::New(width, height, pixelformat, loadPol, releasePol);
81   return BitmapImage(internal.Get());
82 }
83
84 BitmapImage BitmapImage::New(PixelBuffer* pixBuf, unsigned int width, unsigned int height, Pixel::Format pixelformat, unsigned int stride)
85 {
86   DALI_ASSERT_ALWAYS( 0u != width  && "Invalid BitmapImage width requested" );
87   DALI_ASSERT_ALWAYS( 0u != height && "Invalid BitmapImage height requested" );
88
89   Internal::BitmapImagePtr internal = Internal::BitmapImage::New(pixBuf, width, height, pixelformat, stride);
90   return BitmapImage(internal.Get());
91 }
92
93 BitmapImage BitmapImage::New(PixelBuffer* pixBuf, unsigned int width, unsigned int height, Pixel::Format pixelformat, unsigned int stride, ReleasePolicy releasePol)
94 {
95   DALI_ASSERT_ALWAYS( 0u != width  && "Invalid BitmapImage width requested" );
96   DALI_ASSERT_ALWAYS( 0u != height && "Invalid BitmapImage height requested" );
97   Internal::BitmapImagePtr internal = Internal::BitmapImage::New(pixBuf, width, height, pixelformat, stride, releasePol);
98   return BitmapImage(internal.Get());
99 }
100
101 PixelBuffer* BitmapImage::GetBuffer()
102 {
103   return GetImplementation(*this).GetBuffer();
104 }
105
106 unsigned int BitmapImage::GetBufferSize() const
107 {
108   return GetImplementation(*this).GetBufferSize();
109 }
110
111 unsigned int BitmapImage::GetBufferStride() const
112 {
113   return GetImplementation(*this).GetBufferStride();
114 }
115
116 Pixel::Format BitmapImage::GetPixelFormat() const
117 {
118   return GetImplementation(*this).GetPixelFormat();
119 }
120
121 void BitmapImage::Update ()
122 {
123   RectArea area;
124   GetImplementation(*this).Update(area);
125 }
126
127 void BitmapImage::Update (RectArea updateArea)
128 {
129   GetImplementation(*this).Update(updateArea);
130 }
131
132 bool BitmapImage::IsDataExternal() const
133 {
134   return GetImplementation(*this).IsDataExternal();
135 }
136
137 } // namespace Dali