[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / image-loader / 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 // CLASS HEADER
18 #include <dali-toolkit/public-api/image-loader/image.h>
19
20 // INTERNAL INCLUDES
21 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
22 #include <dali-toolkit/public-api/image-loader/image-url.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/devel-api/rendering/frame-buffer-devel.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace Image
32 {
33 Dali::Toolkit::ImageUrl GenerateUrl(Dali::FrameBuffer frameBuffer, Pixel::Format pixelFormat, uint32_t width, uint32_t height)
34 {
35   Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelFormat, width, height);
36   frameBuffer.AttachColorTexture(texture, 0u, 0u);
37   // TODO : Need to check frameBuffer result use preMultiplied color or not. By default, we use premultiplied
38   Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, true);
39   return imageUrl;
40 }
41
42 Dali::Toolkit::ImageUrl GenerateUrl(const Dali::FrameBuffer frameBuffer, uint8_t index)
43 {
44   Texture texture = Dali::DevelFrameBuffer::GetColorTexture(frameBuffer, index);
45   // TODO : Need to check frameBuffer result use preMultiplied color or not. By default, we use premultiplied
46   Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, true);
47   return imageUrl;
48 }
49
50 Dali::Toolkit::ImageUrl GenerateUrl(const Dali::PixelData pixelData, bool preMultiplied)
51 {
52   Texture texture = Texture::New(TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
53   texture.Upload(pixelData);
54   Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, preMultiplied);
55   return imageUrl;
56 }
57
58 Dali::Toolkit::ImageUrl GenerateUrl(const Dali::NativeImageInterfacePtr nativeImageInterface, bool preMultiplied)
59 {
60   Texture texture = Dali::Texture::New(*nativeImageInterface);
61   Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, preMultiplied);
62   return imageUrl;
63 }
64
65 Dali::Toolkit::ImageUrl GenerateUrl(const Dali::EncodedImageBuffer encodedImageBuffer)
66 {
67   return Dali::Toolkit::ImageUrl::New(encodedImageBuffer);
68 }
69
70 Dali::Toolkit::ImageUrl GenerateDepthUrl(const Dali::FrameBuffer frameBuffer)
71 {
72   Texture texture = Dali::DevelFrameBuffer::GetDepthTexture(frameBuffer);
73   Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::ImageUrl::New(texture, false);
74   return imageUrl;
75 }
76
77 } // namespace Image
78
79 } // namespace Toolkit
80
81 } // namespace Dali