2 * Copyright (c) 2022 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.
18 #include <dali/devel-api/adaptor-framework/image-loading.h>
21 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
22 #include <dali/internal/imaging/common/file-download.h>
23 #include <dali/internal/imaging/common/image-loader.h>
24 #include <dali/internal/system/common/file-reader.h>
25 #include <dali/public-api/object/property-map.h>
31 // limit maximum image down load size to 50 MB
32 const size_t MAXIMUM_DOWNLOAD_IMAGE_SIZE = 50 * 1024 * 1024;
36 Devel::PixelBuffer LoadImageFromFile(const std::string& url, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection)
38 Integration::BitmapResourceType resourceType(size, fittingMode, samplingMode, orientationCorrection);
40 Internal::Platform::FileReader fileReader(url);
41 FILE* const fp = fileReader.GetFile();
44 Dali::Devel::PixelBuffer bitmap;
45 bool success = TizenPlatform::ImageLoader::ConvertStreamToBitmap(resourceType, url, fp, bitmap);
51 return Dali::Devel::PixelBuffer();
54 void LoadImagePlanesFromFile(const std::string& url, std::vector<Devel::PixelBuffer>& buffers, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection)
56 Integration::BitmapResourceType resourceType(size, fittingMode, samplingMode, orientationCorrection);
58 Internal::Platform::FileReader fileReader(url);
59 FILE* const fp = fileReader.GetFile();
62 TizenPlatform::ImageLoader::ConvertStreamToPlanes(resourceType, url, fp, buffers);
66 Devel::PixelBuffer LoadImageFromBuffer(const Dali::Vector<uint8_t>& buffer, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection)
70 DALI_LOG_ERROR("buffer is empty!\n");
71 return Dali::Devel::PixelBuffer();
73 Integration::BitmapResourceType resourceType(size, fittingMode, samplingMode, orientationCorrection);
75 Internal::Platform::FileReader fileReader(buffer);
76 FILE* const fp = fileReader.GetFile();
79 Dali::Devel::PixelBuffer bitmap;
80 // Make path as empty string. Path information just for file format hint.
81 bool success = TizenPlatform::ImageLoader::ConvertStreamToBitmap(resourceType, std::string(""), fp, bitmap);
87 return Dali::Devel::PixelBuffer();
90 ImageDimensions GetClosestImageSize(const std::string& filename,
92 FittingMode::Type fittingMode,
93 SamplingMode::Type samplingMode,
94 bool orientationCorrection)
96 ImageDimensions dimension = TizenPlatform::ImageLoader::GetClosestImageSize(filename, size, fittingMode, samplingMode, orientationCorrection);
98 dimension.SetWidth(std::min(dimension.GetWidth(), static_cast<uint16_t>(GetMaxTextureSize())));
99 dimension.SetHeight(std::min(dimension.GetHeight(), static_cast<uint16_t>(GetMaxTextureSize())));
104 ImageDimensions GetOriginalImageSize(const std::string& filename, bool orientationCorrection)
106 return TizenPlatform::ImageLoader::GetClosestImageSize(filename, ImageDimensions(0, 0), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, orientationCorrection);
109 Devel::PixelBuffer DownloadImageSynchronously(const std::string& url, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection)
111 Integration::BitmapResourceType resourceType(size, fittingMode, samplingMode, orientationCorrection);
114 Dali::Vector<uint8_t> dataBuffer;
117 succeeded = TizenPlatform::Network::DownloadRemoteFileIntoMemory(url, dataBuffer, dataSize, MAXIMUM_DOWNLOAD_IMAGE_SIZE);
120 size_t blobSize = dataBuffer.Size();
122 DALI_ASSERT_DEBUG(blobSize > 0U);
126 // Open a file handle on the memory buffer:
127 Dali::Internal::Platform::FileReader fileReader(dataBuffer, blobSize);
128 FILE* const fp = fileReader.GetFile();
131 Dali::Devel::PixelBuffer bitmap;
132 bool result = TizenPlatform::ImageLoader::ConvertStreamToBitmap(
144 DALI_LOG_WARNING("Unable to decode bitmap supplied as in-memory blob.\n");
149 return Dali::Devel::PixelBuffer();
152 unsigned int GetMaxTextureSize()
154 return TizenPlatform::ImageLoader::GetMaxTextureSize();