/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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 <cstdlib>
#include <dali-test-suite-utils.h>
-
-#include <dali/public-api/images/pixel.h>
-#include <dali/public-api/images/pixel-data.h>
#include <dali/public-api/common/dali-vector.h>
+#include <dali/public-api/images/pixel-data.h>
+#include <dali/public-api/images/pixel.h>
+
+#include <dali/integration-api/pixel-data-integ.h>
+
+#include <cstdlib>
using namespace Dali;
{
TestApplication application;
- unsigned int width = 10u;
- unsigned int height = 10u;
- unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
+ unsigned int width = 10u;
+ unsigned int height = 10u;
+ unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
- unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
- PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
+ unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
- DALI_TEST_CHECK( pixelData );
- DALI_TEST_CHECK( pixelData.GetWidth() == width );
- DALI_TEST_CHECK( pixelData.GetHeight() == height );
- DALI_TEST_CHECK( pixelData.GetPixelFormat() == Pixel::RGB888 );
+ DALI_TEST_CHECK(pixelData);
+ DALI_TEST_CHECK(pixelData.GetWidth() == width);
+ DALI_TEST_CHECK(pixelData.GetHeight() == height);
+ DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
END_TEST;
}
{
TestApplication application;
- unsigned int width = 10u;
- unsigned int height = 10u;
- unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
- unsigned char* buffer = new unsigned char [ bufferSize ];
- buffer[0] = 'a';
+ unsigned int width = 10u;
+ unsigned int height = 10u;
+ unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+ unsigned char* buffer = new unsigned char[bufferSize];
+ buffer[0] = 'a';
+
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
+
+ DALI_TEST_CHECK(pixelData);
+ DALI_TEST_CHECK(pixelData.GetWidth() == width);
+ DALI_TEST_CHECK(pixelData.GetHeight() == height);
+ DALI_TEST_CHECK(pixelData.GetStride() == 0);
+ DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
+
+ END_TEST;
+}
+
+int UtcDaliPixelData03(void)
+{
+ TestApplication application;
+
+ uint32_t width = 10u;
+ uint32_t height = 10u;
+ uint32_t stride = 12u;
+ uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
+
+ uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::RGB888, PixelData::FREE);
+
+ DALI_TEST_CHECK(pixelData);
+ DALI_TEST_CHECK(pixelData.GetWidth() == width);
+ DALI_TEST_CHECK(pixelData.GetHeight() == height);
+ DALI_TEST_CHECK(pixelData.GetStride() == stride);
+ DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888);
+
+ END_TEST;
+}
+
+int UtcDaliPixelData04(void)
+{
+ TestApplication application;
+
+ uint32_t width = 10u;
+ uint32_t height = 10u;
+ uint32_t stride = 12u;
+ uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
+ uint8_t* buffer = new uint8_t[bufferSize];
+ buffer[0] = 'a';
- PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
- DALI_TEST_CHECK( pixelData);
- DALI_TEST_CHECK( pixelData.GetWidth() == width );
- DALI_TEST_CHECK( pixelData.GetHeight() == height );
- DALI_TEST_CHECK( pixelData.GetPixelFormat() == Pixel::L8 );
+ DALI_TEST_CHECK(pixelData);
+ DALI_TEST_CHECK(pixelData.GetWidth() == width);
+ DALI_TEST_CHECK(pixelData.GetHeight() == height);
+ DALI_TEST_CHECK(pixelData.GetStride() == stride);
+ DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
END_TEST;
}
{
TestApplication application;
- unsigned int width = 10u;
- unsigned int height = 10u;
- unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
- unsigned char* buffer = new unsigned char [ bufferSize ];
- PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+ unsigned int width = 10u;
+ unsigned int height = 10u;
+ unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+ unsigned char* buffer = new unsigned char[bufferSize];
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
PixelData pixelDataCopy(pixelData);
- DALI_TEST_EQUALS( (bool)pixelDataCopy, true, TEST_LOCATION );
+ DALI_TEST_EQUALS((bool)pixelDataCopy, true, TEST_LOCATION);
END_TEST;
}
{
TestApplication application;
- unsigned int width = 10u;
- unsigned int height = 10u;
- unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
- unsigned char* buffer = new unsigned char [ bufferSize ];
- PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+ unsigned int width = 10u;
+ unsigned int height = 10u;
+ unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+ unsigned char* buffer = new unsigned char[bufferSize];
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
PixelData pixelData2;
- DALI_TEST_EQUALS( (bool)pixelData2, false, TEST_LOCATION );
+ DALI_TEST_EQUALS((bool)pixelData2, false, TEST_LOCATION);
pixelData2 = pixelData;
- DALI_TEST_EQUALS( (bool)pixelData2, true, TEST_LOCATION );
+ DALI_TEST_EQUALS((bool)pixelData2, true, TEST_LOCATION);
END_TEST;
}
{
TestApplication application;
- unsigned int width = 10u;
- unsigned int height = 10u;
- unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
- unsigned char* buffer = new unsigned char [ bufferSize ];
+ unsigned int width = 10u;
+ unsigned int height = 10u;
+ unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+ unsigned char* buffer = new unsigned char[bufferSize];
- PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
- DALI_TEST_CHECK( pixelData );
- DALI_TEST_EQUALS( width, pixelData.GetWidth(), TEST_LOCATION );
- DALI_TEST_EQUALS( height, pixelData.GetHeight(), TEST_LOCATION );
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
+ DALI_TEST_CHECK(pixelData);
+ DALI_TEST_EQUALS(width, pixelData.GetWidth(), TEST_LOCATION);
+ DALI_TEST_EQUALS(height, pixelData.GetHeight(), TEST_LOCATION);
- PixelData moved = std::move( pixelData);
- DALI_TEST_CHECK( moved );
- DALI_TEST_EQUALS( width, moved.GetWidth(), TEST_LOCATION );
- DALI_TEST_EQUALS( height, moved.GetHeight(), TEST_LOCATION );
- DALI_TEST_CHECK( !pixelData );
+ PixelData moved = std::move(pixelData);
+ DALI_TEST_CHECK(moved);
+ DALI_TEST_EQUALS(width, moved.GetWidth(), TEST_LOCATION);
+ DALI_TEST_EQUALS(height, moved.GetHeight(), TEST_LOCATION);
+ DALI_TEST_CHECK(!pixelData);
END_TEST;
}
{
TestApplication application;
- unsigned int width = 10u;
- unsigned int height = 10u;
- unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
- unsigned char* buffer = new unsigned char [ bufferSize ];
+ unsigned int width = 10u;
+ unsigned int height = 10u;
+ unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::L8);
+ unsigned char* buffer = new unsigned char[bufferSize];
- PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
- DALI_TEST_CHECK( pixelData );
- DALI_TEST_EQUALS( width, pixelData.GetWidth(), TEST_LOCATION );
- DALI_TEST_EQUALS( height, pixelData.GetHeight(), TEST_LOCATION );
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY);
+ DALI_TEST_CHECK(pixelData);
+ DALI_TEST_EQUALS(width, pixelData.GetWidth(), TEST_LOCATION);
+ DALI_TEST_EQUALS(height, pixelData.GetHeight(), TEST_LOCATION);
PixelData moved;
- moved = std::move( pixelData);
- DALI_TEST_CHECK( moved );
- DALI_TEST_EQUALS( width, moved.GetWidth(), TEST_LOCATION );
- DALI_TEST_EQUALS( height, moved.GetHeight(), TEST_LOCATION );
- DALI_TEST_CHECK( !pixelData );
+ moved = std::move(pixelData);
+ DALI_TEST_CHECK(moved);
+ DALI_TEST_EQUALS(width, moved.GetWidth(), TEST_LOCATION);
+ DALI_TEST_EQUALS(height, moved.GetHeight(), TEST_LOCATION);
+ DALI_TEST_CHECK(!pixelData);
END_TEST;
}
}
END_TEST;
}
+
+int UtcDaliPixelDataReleasePixelDataBuffer(void)
+{
+ TestApplication application;
+
+ uint32_t width = 10u;
+ uint32_t height = 10u;
+ uint32_t stride = 12u;
+ uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
+ uint8_t* buffer = new uint8_t[bufferSize];
+ buffer[0] = 'a';
+
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
+
+ DALI_TEST_CHECK(pixelData);
+ DALI_TEST_CHECK(pixelData.GetWidth() == width);
+ DALI_TEST_CHECK(pixelData.GetHeight() == height);
+ DALI_TEST_CHECK(pixelData.GetStride() == stride);
+ DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
+
+ Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::ReleasePixelDataBuffer(pixelData);
+
+ DALI_TEST_CHECK(!pixelData);
+
+ DALI_TEST_EQUALS(pixelDataBuffer.bufferSize, bufferSize, TEST_LOCATION);
+ DALI_TEST_EQUALS(pixelDataBuffer.buffer[0], static_cast<uint8_t>('a'), TEST_LOCATION);
+
+ // Release memory by our self.
+ delete[] pixelDataBuffer.buffer;
+
+ END_TEST;
+}
+
+int UtcDaliPixelDataGetPixelDataBuffer(void)
+{
+ TestApplication application;
+
+ uint32_t width = 10u;
+ uint32_t height = 10u;
+ uint32_t stride = 12u;
+ uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8);
+ uint8_t* buffer = new uint8_t[bufferSize];
+ buffer[0] = 'a';
+
+ PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY);
+
+ DALI_TEST_CHECK(pixelData);
+ DALI_TEST_CHECK(pixelData.GetWidth() == width);
+ DALI_TEST_CHECK(pixelData.GetHeight() == height);
+ DALI_TEST_CHECK(pixelData.GetStride() == stride);
+ DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8);
+
+ Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
+
+ DALI_TEST_CHECK(pixelData);
+
+ DALI_TEST_EQUALS(pixelDataBuffer.bufferSize, bufferSize, TEST_LOCATION);
+ DALI_TEST_EQUALS(pixelDataBuffer.buffer[0], static_cast<uint8_t>('a'), TEST_LOCATION);
+
+ END_TEST;
+}