Making DALi core internals typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / internal / event / images / bitmap-compressed.cpp
1 /*
2  * Copyright (c) 2018 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/bitmap-compressed.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstdlib>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/common/core-impl.h>
26 #include <dali/integration-api/debug.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33 using namespace Dali::Pixel;
34
35 BitmapCompressed::BitmapCompressed( const ResourcePolicy::Discardable discardable )
36 : Bitmap( discardable ),
37   mBufferSize(0)
38 {
39 }
40
41 BitmapCompressed::~BitmapCompressed()
42 {
43   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
44 }
45
46 void BitmapCompressed::Initialize( Pixel::Format pixelFormat,
47                                    const uint32_t width,
48                                    const uint32_t height,
49                                    const uint32_t bufferSize )
50 {
51   Dali::Integration::Bitmap::Initialize( pixelFormat, width, height );
52   mBufferSize  = bufferSize;
53   mAlphaChannelUsed = false; // Default to not using Alpha as we cannot scan the pixels to look for transparent pixels. A follow-up work-item and patch will add an "assume alpha present" flag to ImageAttributes.
54 }
55
56 Dali::Integration::PixelBuffer* BitmapCompressed::ReserveBufferOfSize( Pixel::Format pixelFormat,
57                                                                        const uint32_t  width,
58                                                                        const uint32_t  height,
59                                                                        const uint32_t  bufferSize )
60 {
61   // Sanity check that a not-outrageous amount of data is being passed in (indicating a client error):
62   DALI_ASSERT_DEBUG(bufferSize < (1U << 27U) && "That is far too much compressed data."); // 128MB of compressed data == unreasonable.
63   // delete existing buffer
64   DeletePixelBuffer();
65
66   Initialize(pixelFormat, width, height, bufferSize);
67
68   mData = reinterpret_cast< Dali::Integration::PixelBuffer* >( malloc( bufferSize ) );
69
70   return mData;
71 }
72
73 } //namespace Integration
74
75 } //namespace Dali