/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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/loader-ktx.h>
#include <dali/internal/imaging/common/loader-png.h>
#include <dali/internal/imaging/common/loader-wbmp.h>
+#include <dali/internal/imaging/common/loader-webp.h>
#include <dali/internal/system/common/file-reader.h>
using namespace Dali::Integration;
FORMAT_JPEG,
FORMAT_BMP,
FORMAT_GIF,
+ FORMAT_WEBP,
FORMAT_KTX,
FORMAT_ASTC,
FORMAT_ICO,
// clang-format off
const Dali::ImageLoader::BitmapLoader BITMAP_LOADER_LOOKUP_TABLE[FORMAT_TOTAL_COUNT] =
{
- {Png::MAGIC_BYTE_1, Png::MAGIC_BYTE_2, LoadBitmapFromPng, LoadPngHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
- {Jpeg::MAGIC_BYTE_1, Jpeg::MAGIC_BYTE_2, LoadBitmapFromJpeg, LoadJpegHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
- {Bmp::MAGIC_BYTE_1, Bmp::MAGIC_BYTE_2, LoadBitmapFromBmp, LoadBmpHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
- {Gif::MAGIC_BYTE_1, Gif::MAGIC_BYTE_2, LoadBitmapFromGif, LoadGifHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
- {Ktx::MAGIC_BYTE_1, Ktx::MAGIC_BYTE_2, LoadBitmapFromKtx, LoadKtxHeader, Bitmap::BITMAP_COMPRESSED },
- {Astc::MAGIC_BYTE_1, Astc::MAGIC_BYTE_2, LoadBitmapFromAstc, LoadAstcHeader, Bitmap::BITMAP_COMPRESSED },
- {Ico::MAGIC_BYTE_1, Ico::MAGIC_BYTE_2, LoadBitmapFromIco, LoadIcoHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
- {0x0, 0x0, LoadBitmapFromWbmp, LoadWbmpHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
+ {Png::MAGIC_BYTE_1, Png::MAGIC_BYTE_2, LoadBitmapFromPng, nullptr, LoadPngHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
+ {Jpeg::MAGIC_BYTE_1, Jpeg::MAGIC_BYTE_2, LoadBitmapFromJpeg, LoadPlanesFromJpeg, LoadJpegHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
+ {Bmp::MAGIC_BYTE_1, Bmp::MAGIC_BYTE_2, LoadBitmapFromBmp, nullptr, LoadBmpHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
+ {Gif::MAGIC_BYTE_1, Gif::MAGIC_BYTE_2, LoadBitmapFromGif, nullptr, LoadGifHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
+ {Webp::MAGIC_BYTE_1, Webp::MAGIC_BYTE_2, LoadBitmapFromWebp, nullptr, LoadWebpHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
+ {Ktx::MAGIC_BYTE_1, Ktx::MAGIC_BYTE_2, LoadBitmapFromKtx, nullptr, LoadKtxHeader, Bitmap::BITMAP_COMPRESSED },
+ {Astc::MAGIC_BYTE_1, Astc::MAGIC_BYTE_2, LoadBitmapFromAstc, nullptr, LoadAstcHeader, Bitmap::BITMAP_COMPRESSED },
+ {Ico::MAGIC_BYTE_1, Ico::MAGIC_BYTE_2, LoadBitmapFromIco, nullptr, LoadIcoHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
+ {0x0, 0x0, LoadBitmapFromWbmp, nullptr, LoadWbmpHeader, Bitmap::BITMAP_2D_PACKED_PIXELS},
};
// clang-format on
{".jpg", FORMAT_JPEG},
{".bmp", FORMAT_BMP },
{".gif", FORMAT_GIF },
+ {".webp", FORMAT_WEBP },
{".ktx", FORMAT_KTX },
{".astc", FORMAT_ASTC},
{".ico", FORMAT_ICO },
bool GetBitmapLoaderFunctions(FILE* fp,
FileFormats format,
Dali::ImageLoader::LoadBitmapFunction& loader,
+ Dali::ImageLoader::LoadPlanesFunction& planeLoader,
Dali::ImageLoader::LoadBitmapHeaderFunction& header,
Bitmap::Profile& profile,
const std::string& filename)
// if a loader was found set the outputs
if(loaderFound)
{
- loader = lookupPtr->loader;
- header = lookupPtr->header;
- profile = lookupPtr->profile;
+ loader = lookupPtr->loader;
+ planeLoader = lookupPtr->planeLoader;
+ header = lookupPtr->header;
+ profile = lookupPtr->profile;
}
// Reset to the start of the file.
if(fp != NULL)
{
Dali::ImageLoader::LoadBitmapFunction function;
+ Dali::ImageLoader::LoadPlanesFunction planeLoader;
Dali::ImageLoader::LoadBitmapHeaderFunction header;
Bitmap::Profile profile;
if(GetBitmapLoaderFunctions(fp,
GetFormatHint(path),
function,
+ planeLoader,
header,
profile,
path))
if(!result)
{
- DALI_LOG_WARNING("Unable to convert %s\n", path.c_str());
+ DALI_LOG_ERROR("Unable to convert %s\n", path.c_str());
pixelBuffer.Reset();
}
}
else
{
- DALI_LOG_WARNING("Image Decoder for %s unavailable\n", path.c_str());
+ DALI_LOG_ERROR("Image Decoder for %s unavailable\n", path.c_str());
+ }
+ }
+
+ return result;
+}
+
+bool ConvertStreamToPlanes(const Integration::BitmapResourceType& resource, std::string path, FILE* const fp, std::vector<Dali::Devel::PixelBuffer>& pixelBuffers)
+{
+ DALI_LOG_TRACE_METHOD(gLogFilter);
+
+ bool result = false;
+
+ if(fp != NULL)
+ {
+ Dali::ImageLoader::LoadBitmapFunction loader;
+ Dali::ImageLoader::LoadPlanesFunction planeLoader;
+ Dali::ImageLoader::LoadBitmapHeaderFunction header;
+
+ Bitmap::Profile profile;
+
+ if(GetBitmapLoaderFunctions(fp,
+ GetFormatHint(path),
+ loader,
+ planeLoader,
+ header,
+ profile,
+ path))
+ {
+ const Dali::ImageLoader::ScalingParameters scalingParameters(resource.size, resource.scalingMode, resource.samplingMode);
+ const Dali::ImageLoader::Input input(fp, scalingParameters, resource.orientationCorrection);
+
+ // Run the image type decoder:
+ if(planeLoader)
+ {
+ result = planeLoader(input, pixelBuffers);
+ }
+ else
+ {
+ Dali::Devel::PixelBuffer pixelBuffer;
+ result = loader(input, pixelBuffer);
+ if(!result)
+ {
+ DALI_LOG_ERROR("Unable to convert %s\n", path.c_str());
+ }
+
+ pixelBuffer = Internal::Platform::ApplyAttributesToBitmap(pixelBuffer, resource.size, resource.scalingMode, resource.samplingMode);
+
+ pixelBuffers.push_back(pixelBuffer);
+ }
+ }
+ else
+ {
+ DALI_LOG_ERROR("Image Decoder for %s unavailable\n", path.c_str());
}
}
if(fp != NULL)
{
Dali::ImageLoader::LoadBitmapFunction loaderFunction;
+ Dali::ImageLoader::LoadPlanesFunction planeLoader;
Dali::ImageLoader::LoadBitmapHeaderFunction headerFunction;
Bitmap::Profile profile;
if(GetBitmapLoaderFunctions(fp,
GetFormatHint(filename),
loaderFunction,
+ planeLoader,
headerFunction,
profile,
filename))
const bool read_res = headerFunction(input, width, height);
if(!read_res)
{
- DALI_LOG_WARNING("Image Decoder failed to read header for %s\n", filename.c_str());
+ DALI_LOG_ERROR("Image Decoder failed to read header for %s\n", filename.c_str());
}
}
else
{
- DALI_LOG_WARNING("Image Decoder for %s unavailable\n", filename.c_str());
+ DALI_LOG_ERROR("Image Decoder for %s unavailable\n", filename.c_str());
}
}
return ImageDimensions(width, height);
if(fp != NULL)
{
Dali::ImageLoader::LoadBitmapFunction loaderFunction;
+ Dali::ImageLoader::LoadPlanesFunction planeLoader;
Dali::ImageLoader::LoadBitmapHeaderFunction headerFunction;
Bitmap::Profile profile;
if(GetBitmapLoaderFunctions(fp,
FORMAT_UNKNOWN,
loaderFunction,
+ planeLoader,
headerFunction,
profile,
""))
const bool read_res = headerFunction(input, width, height);
if(!read_res)
{
- DALI_LOG_WARNING("Image Decoder failed to read header for resourceBuffer\n");
+ DALI_LOG_ERROR("Image Decoder failed to read header for resourceBuffer\n");
}
}
}