2 * Copyright (c) 2014 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>
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/internal/common/core-impl.h>
24 #include <dali/integration-api/debug.h>
31 using namespace Dali::Pixel;
34 BitmapPackedPixel::BitmapPackedPixel( ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf )
35 : Bitmap( discardable, pixBuf ),
42 // use power of two bufferWidth and bufferHeight for better performance
43 Dali::Integration::PixelBuffer* BitmapPackedPixel::ReserveBuffer(Pixel::Format pixelFormat,
46 unsigned int bufferWidth,
47 unsigned int bufferHeight)
49 // delete existing buffer
52 Initialize(pixelFormat, width, height, bufferWidth, bufferHeight);
55 unsigned int bufSize = mBufferWidth * mBufferHeight * mBytesPerPixel;
57 mData = new Dali::Integration::PixelBuffer[bufSize];
62 void BitmapPackedPixel::AssignBuffer(Pixel::Format pixelFormat,
63 Dali::Integration::PixelBuffer* buffer,
64 std::size_t bufferSize,
67 unsigned int bufferWidth,
68 unsigned int bufferHeight)
70 DALI_ASSERT_DEBUG( buffer );
72 // delete existing buffer
75 Initialize( pixelFormat, width, height, bufferWidth, bufferHeight );
77 // make sure the buffer size matches what is being passed in
78 DALI_ASSERT_DEBUG( bufferSize == (mBufferWidth * mBufferHeight * mBytesPerPixel))
83 void BitmapPackedPixel::TestForTransparency()
85 DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
87 mAlphaChannelUsed = false;
91 unsigned char* pixelBuffer=GetBuffer();
92 if(pixelBuffer != NULL)
94 unsigned char* row = pixelBuffer;
97 Pixel::GetAlphaOffsetAndMask(mPixelFormat, byte, bits);
99 int stride = mBufferWidth * mBytesPerPixel;
100 int pixelsPerRow = mImageWidth;
102 for(size_t j=0; j<mImageHeight; j++)
104 unsigned char* pixels = row;
105 for(int i=0; i<pixelsPerRow; i++)
107 if((pixels[byte] & bits) != bits)
109 mAlphaChannelUsed = true;
110 j=mImageHeight; // break out of outer loop
113 pixels+=mBytesPerPixel;
121 BitmapPackedPixel::~BitmapPackedPixel()
123 DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
126 void BitmapPackedPixel::Initialize( Pixel::Format pixelFormat,
129 unsigned int bufferWidth,
130 unsigned int bufferHeight)
132 Dali::Integration::Bitmap::Initialize(pixelFormat, width, height);
133 mBufferWidth = (bufferWidth != 0) ? bufferWidth : width;
134 mBufferHeight = (bufferHeight != 0) ? bufferHeight : height;
135 mBytesPerPixel = Pixel::GetBytesPerPixel(pixelFormat);
136 DALI_ASSERT_DEBUG(mBufferWidth >= mImageWidth && mBufferHeight >= mImageHeight);
139 unsigned int BitmapPackedPixel::GetBufferStride() const
141 return mBufferWidth*mBytesPerPixel;
146 } //namespace Integration