2 * Copyright (c) 2018 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.
19 #include <tizen-image-loader.h>
20 #include <dali/integration-api/debug.h>
21 #include <dali/integration-api/bitmap.h>
22 #include "loader-dummy.h"
24 // The plugin factories
25 extern "C" DALI_EXPORT_API Dali::ImageLoaderPlugin* CreateImageLoaderPlugin(void)
27 return new Dali::Plugin::TizenImageLoader;
30 extern "C" DALI_EXPORT_API void DestroyImageLoaderPlugin( Dali::ImageLoaderPlugin* plugin )
45 * Enum for file formats, has to be in sync with BITMAP_LOADER_LOOKUP_TABLE
49 // Unknown file format
52 // formats that use magic bytes
58 * A lookup table containing all the bitmap loaders with the appropriate information.
59 * Has to be in sync with enum FileFormats
61 const Dali::ImageLoader::BitmapLoader BITMAP_LOADER_LOOKUP_TABLE[FORMAT_TOTAL_COUNT] =
63 { 0x0, 0x0, LoadBitmapFromImage, LoadImageHeader, Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS },
67 struct FormatExtension
69 const std::string extension;
73 const FormatExtension FORMAT_EXTENSIONS[] =
75 { ".dummy", FORMAT_DUMMY }
78 const unsigned int FORMAT_EXTENSIONS_COUNT = sizeof(FORMAT_EXTENSIONS) / sizeof(FormatExtension);
81 FileFormats GetFormatHint( const std::string& filename )
83 FileFormats format = FORMAT_UNKNOWN;
85 for ( unsigned int i = 0; i < FORMAT_EXTENSIONS_COUNT; ++i )
87 unsigned int length = FORMAT_EXTENSIONS[i].extension.size();
88 if ( ( filename.size() > length ) &&
89 ( 0 == filename.compare( filename.size() - length, length, FORMAT_EXTENSIONS[i].extension ) ) )
91 format = FORMAT_EXTENSIONS[i].format;
100 TizenImageLoader::TizenImageLoader()
104 TizenImageLoader::~TizenImageLoader()
108 const Dali::ImageLoader::BitmapLoader* TizenImageLoader::BitmapLoaderLookup( const std::string& filename ) const
110 const Dali::ImageLoader::BitmapLoader *lookupPtr = BITMAP_LOADER_LOOKUP_TABLE;
111 FileFormats format = GetFormatHint( filename );
112 if ( format != FORMAT_UNKNOWN )
114 lookupPtr = BITMAP_LOADER_LOOKUP_TABLE + format;
123 } // namespace Plugin