/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/imaging/common/pixel-buffer-impl.h>
// EXTERNAL INCLUDES
+#include <dali/integration-api/pixel-data-integ.h>
#include <stdlib.h>
#include <cstring>
// INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
#include <dali/internal/imaging/common/alpha-mask.h>
#include <dali/internal/imaging/common/gaussian-blur.h>
#include <dali/internal/imaging/common/image-operations.h>
{
namespace
{
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gPixelBufferFilter = Debug::Filter::New(Debug::NoLogging, false, "DALI_LOG_PIXEL_BUFFER_SIZE");
+#endif
+
const float TWO_PI = 2.f * Math::PI; ///< 360 degrees in radians
// based on W3C Recommendations (https://www.w3.org/TR/AERT/#color-contrast)
constexpr uint32_t BRIGHTNESS_CONSTANT_R = 299;
constexpr uint32_t BRIGHTNESS_CONSTANT_B = 114;
} // namespace
+#if defined(DEBUG_ENABLED)
+uint32_t PixelBuffer::gPixelBufferAllocationTotal{0};
+#endif
+
PixelBuffer::PixelBuffer(uint8_t* buffer,
uint32_t bufferSize,
uint32_t width,
if(bufferSize > 0)
{
buffer = static_cast<uint8_t*>(malloc(bufferSize));
+#if defined(DEBUG_ENABLED)
+ gPixelBufferAllocationTotal += bufferSize;
+#endif
}
+ DALI_LOG_INFO(gPixelBufferFilter, Debug::Concise, "Allocated PixelBuffer of size %u\n", bufferSize);
+
return new PixelBuffer(buffer, bufferSize, width, height, width, pixelFormat);
}
return new PixelBuffer(buffer, bufferSize, width, height, stride, pixelFormat);
}
-Dali::PixelData PixelBuffer::Convert(PixelBuffer& pixelBuffer)
-{
- Dali::PixelData pixelData = Dali::PixelData::New(pixelBuffer.mBuffer,
- pixelBuffer.mBufferSize,
- pixelBuffer.mWidth,
- pixelBuffer.mHeight,
- pixelBuffer.mStride,
- pixelBuffer.mPixelFormat,
- Dali::PixelData::FREE);
- pixelBuffer.mBuffer = NULL;
- pixelBuffer.mWidth = 0;
- pixelBuffer.mHeight = 0;
- pixelBuffer.mBufferSize = 0;
- pixelBuffer.mStride = 0;
+Dali::PixelData PixelBuffer::Convert(PixelBuffer& pixelBuffer, bool releaseAfterUpload)
+{
+#if defined(DEBUG_ENABLED)
+ gPixelBufferAllocationTotal -= pixelBuffer.mBufferSize;
+#endif
+ Dali::PixelData pixelData;
+ if(releaseAfterUpload)
+ {
+ pixelData = Dali::Integration::NewPixelDataWithReleaseAfterUpload(pixelBuffer.mBuffer,
+ pixelBuffer.mBufferSize,
+ pixelBuffer.mWidth,
+ pixelBuffer.mHeight,
+ pixelBuffer.mStride,
+ pixelBuffer.mPixelFormat,
+ Dali::PixelData::FREE);
+ }
+ else
+ {
+ pixelData = Dali::PixelData::New(pixelBuffer.mBuffer,
+ pixelBuffer.mBufferSize,
+ pixelBuffer.mWidth,
+ pixelBuffer.mHeight,
+ pixelBuffer.mStride,
+ pixelBuffer.mPixelFormat,
+ Dali::PixelData::FREE);
+ }
+ pixelBuffer.mBuffer = NULL;
+ pixelBuffer.mWidth = 0;
+ pixelBuffer.mHeight = 0;
+ pixelBuffer.mBufferSize = 0;
+ pixelBuffer.mStride = 0;
return pixelData;
}
{
if(mBuffer)
{
+#if defined(DEBUG_ENABLED)
+ gPixelBufferAllocationTotal -= mBufferSize;
+#endif
free(mBuffer);
+ mBuffer = nullptr;
}
}
ReleaseBuffer();
mBuffer = reinterpret_cast<unsigned char*>(malloc(size));
mBufferSize = size;
+#if defined(DEBUG_ENABLED)
+ gPixelBufferAllocationTotal += size;
+#endif
}
bool PixelBuffer::Rotate(Degree angle)
pixelsOut = nullptr;
mBufferSize = mWidth * mHeight * pixelSize;
mStride = mWidth; // The buffer is tightly packed.
+
+#if defined(DEBUG_ENABLED)
+ gPixelBufferAllocationTotal += mBufferSize;
+#endif
}
return success;
void PixelBuffer::MultiplyColorByAlpha()
{
- auto bytesPerPixel = Pixel::GetBytesPerPixel(mPixelFormat);
-
// Compressed textures have unknown size of the pixel. Alpha premultiplication
// must be skipped in such case
- if(Pixel::GetBytesPerPixel(mPixelFormat) && Pixel::HasAlpha(mPixelFormat))
+ if(!Pixel::IsCompressed(mPixelFormat) && Pixel::HasAlpha(mPixelFormat))
{
+ auto bytesPerPixel = Pixel::GetBytesPerPixel(mPixelFormat);
+
uint8_t* pixel = mBuffer;
const uint32_t strideBytes = mStride * bytesPerPixel;
const uint32_t widthBytes = mWidth * bytesPerPixel;