2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/images/bitmap-packed-pixel.h>
25 #include <dali/public-api/object/ref-object.h>
26 #include <dali/internal/common/core-impl.h>
27 #include <dali/integration-api/debug.h>
34 using namespace Dali::Pixel;
37 BitmapPackedPixel::BitmapPackedPixel( ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf )
38 : Bitmap( discardable, pixBuf ),
45 // use power of two bufferWidth and bufferHeight for better performance
46 Dali::Integration::PixelBuffer* BitmapPackedPixel::ReserveBuffer( Pixel::Format pixelFormat,
50 uint32_t bufferHeight )
52 // delete existing buffer
55 Initialize(pixelFormat, width, height, bufferWidth, bufferHeight);
58 uint32_t bufSize = mBufferWidth * mBufferHeight * mBytesPerPixel;
60 mData = reinterpret_cast< Dali::Integration::PixelBuffer* >( malloc( bufSize) );
65 void BitmapPackedPixel::AssignBuffer( Pixel::Format pixelFormat,
66 Dali::Integration::PixelBuffer* buffer,
71 uint32_t bufferHeight)
73 DALI_ASSERT_DEBUG( buffer );
75 // delete existing buffer
78 Initialize( pixelFormat, width, height, bufferWidth, bufferHeight );
80 // make sure the buffer size matches what is being passed in
81 DALI_ASSERT_DEBUG( bufferSize == (mBufferWidth * mBufferHeight * mBytesPerPixel))
86 void BitmapPackedPixel::TestForTransparency()
88 DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
90 mAlphaChannelUsed = false;
94 uint8_t* pixelBuffer=GetBuffer();
95 if(pixelBuffer != NULL)
97 uint8_t* row = pixelBuffer;
99 int32_t byte; int32_t bits;
100 Pixel::GetAlphaOffsetAndMask(mPixelFormat, byte, bits);
102 int32_t stride = mBufferWidth * mBytesPerPixel;
103 int32_t pixelsPerRow = mImageWidth;
105 for(uint32_t j=0; j<mImageHeight; j++)
107 uint8_t* pixels = row;
108 for(int32_t i=0; i<pixelsPerRow; i++)
110 if((pixels[byte] & bits) != bits)
112 mAlphaChannelUsed = true;
113 j=mImageHeight; // break out of outer loop
116 pixels+=mBytesPerPixel;
124 BitmapPackedPixel::~BitmapPackedPixel()
126 DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
129 void BitmapPackedPixel::Initialize( Pixel::Format pixelFormat,
132 uint32_t bufferWidth,
133 uint32_t bufferHeight)
135 Dali::Integration::Bitmap::Initialize(pixelFormat, width, height);
136 mBufferWidth = (bufferWidth != 0) ? bufferWidth : width;
137 mBufferHeight = (bufferHeight != 0) ? bufferHeight : height;
138 mBytesPerPixel = Pixel::GetBytesPerPixel(pixelFormat);
139 DALI_ASSERT_DEBUG(mBufferWidth >= mImageWidth && mBufferHeight >= mImageHeight);
142 uint32_t BitmapPackedPixel::GetBufferStride() const
144 return mBufferWidth*mBytesPerPixel;
149 } //namespace Integration