Allow to use premultiplied external texture
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Image.cpp
1 /*
2  * Copyright (c) 2023 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 #include <stdlib.h>
18 #include <iostream>
19
20 #include <dali-toolkit-test-suite-utils.h>
21
22 #include <dali-toolkit/public-api/image-loader/image-url.h>
23 #include <dali-toolkit/public-api/image-loader/image.h>
24 #include <dali/public-api/adaptor-framework/native-image-source.h>
25 #include <dali/public-api/images/pixel-data.h>
26 #include <dali/public-api/rendering/frame-buffer.h>
27 #include <dali/public-api/rendering/texture.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 namespace
33 {
34 } // namespace
35
36 void dali_image_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void dali_image_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46 int UtcDaliImageConvertFrameBufferToUrl1(void)
47 {
48   ToolkitTestApplication application;
49   tet_infoline("UtcDaliImageConvertFrameBufferToUrl1");
50
51   unsigned int width(64);
52   unsigned int height(64);
53   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
54
55   DALI_TEST_CHECK(frameBuffer);
56   ImageUrl url = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
57
58   DALI_TEST_CHECK(url.GetUrl().size() > 0u);
59
60   END_TEST;
61 }
62
63 int UtcDaliImageConvertFrameBufferToUrl2(void)
64 {
65   ToolkitTestApplication application;
66   tet_infoline("UtcDaliImageConvertFrameBufferToUrl2");
67
68   unsigned int width(64);
69   unsigned int height(64);
70   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
71
72   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
73   frameBuffer.AttachColorTexture(texture);
74
75   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(frameBuffer, 0).GetUrl().size() > 0u);
76
77   END_TEST;
78 }
79
80 int UtcDaliImageConvertPixelDataToUrl01(void)
81 {
82   ToolkitTestApplication application;
83   tet_infoline("UtcDaliImageConvertPixelDataToUrl01");
84
85   unsigned int width(64);
86   unsigned int height(64);
87   unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGB888);
88
89   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
90   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
91
92   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(pixelData).GetUrl().size() > 0u);
93
94   END_TEST;
95 }
96
97 int UtcDaliImageConvertPixelDataToUrl02(void)
98 {
99   ToolkitTestApplication application;
100   tet_infoline("UtcDaliImageConvertPixelDataToUrl02");
101
102   unsigned int width(64);
103   unsigned int height(64);
104   unsigned int bufferSize = width * height * Pixel::GetBytesPerPixel(Pixel::RGBA8888);
105
106   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
107   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
108
109   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(pixelData, true).GetUrl().size() > 0u);
110
111   END_TEST;
112 }
113
114 int UtcDaliImageConvertNativeImageSourceToUrl01(void)
115 {
116   ToolkitTestApplication application;
117   tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl01");
118
119   unsigned int width(64);
120   unsigned int height(64);
121   try
122   {
123     NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT);
124
125     DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageSource).GetUrl().size() > 0u);
126   }
127   catch(Dali::DaliException& e)
128   {
129     DALI_TEST_PRINT_ASSERT(e);
130     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
131   }
132   catch(...)
133   {
134     tet_printf("Assertion test failed - wrong Exception\n");
135     tet_result(TET_FAIL);
136   }
137
138   END_TEST;
139 }
140
141 int UtcDaliImageConvertNativeImageSourceToUrl02(void)
142 {
143   ToolkitTestApplication application;
144   tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl02");
145
146   unsigned int width(64);
147   unsigned int height(64);
148   try
149   {
150     NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT);
151
152     DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageSource, true).GetUrl().size() > 0u);
153   }
154   catch(Dali::DaliException& e)
155   {
156     DALI_TEST_PRINT_ASSERT(e);
157     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
158   }
159   catch(...)
160   {
161     tet_printf("Assertion test failed - wrong Exception\n");
162     tet_result(TET_FAIL);
163   }
164
165   END_TEST;
166 }
167
168 int UtcDaliImageConvertEncodedImageBufferToUrl(void)
169 {
170   ToolkitTestApplication application;
171   tet_infoline("UtcDaliImageConvertEncodedImageBufferToUrl");
172
173   Dali::Vector<uint8_t> buffer;
174   buffer.PushBack(0x11);
175   buffer.PushBack(0x22);
176   buffer.PushBack(0x33);
177
178   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(EncodedImageBuffer::New(buffer)).GetUrl().size() > 0u);
179
180   END_TEST;
181 }