Merge "Fix issue that LoadContents of WebView cound not be called with null arguments...
[platform/core/uifw/dali-extension.git] / dali-extension / image-loader / tizen-image-loader.cpp
1 /*
2  * Copyright (c) 2018 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
18 // CLASS HEADER
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"
23
24 // The plugin factories
25 extern "C" DALI_EXPORT_API Dali::ImageLoaderPlugin* CreateImageLoaderPlugin(void)
26 {
27   return new Dali::Plugin::TizenImageLoader;
28 }
29
30 extern "C" DALI_EXPORT_API void DestroyImageLoaderPlugin( Dali::ImageLoaderPlugin* plugin )
31 {
32   if( plugin != NULL )
33   {
34     delete plugin;
35   }
36 }
37
38 namespace Dali
39 {
40 namespace Plugin
41 {
42 namespace
43 {
44   /**
45    * Enum for file formats, has to be in sync with BITMAP_LOADER_LOOKUP_TABLE
46    */
47   enum FileFormats
48   {
49     // Unknown file format
50     FORMAT_UNKNOWN = -1,
51
52     // formats that use magic bytes
53     FORMAT_DUMMY = 0,
54     FORMAT_TOTAL_COUNT
55   };
56
57   /**
58    * A lookup table containing all the bitmap loaders with the appropriate information.
59    * Has to be in sync with enum FileFormats
60    */
61   const Dali::ImageLoader::BitmapLoader BITMAP_LOADER_LOOKUP_TABLE[FORMAT_TOTAL_COUNT] =
62   {
63     { 0x0,                0x0,                LoadBitmapFromImage,  LoadImageHeader,  Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS },
64   };
65
66
67   struct FormatExtension
68   {
69     const std::string extension;
70     FileFormats format;
71   };
72
73   const FormatExtension FORMAT_EXTENSIONS[] =
74   {
75     { ".dummy",  FORMAT_DUMMY  }
76   };
77
78   const unsigned int FORMAT_EXTENSIONS_COUNT = sizeof(FORMAT_EXTENSIONS) / sizeof(FormatExtension);
79
80
81   FileFormats GetFormatHint( const std::string& filename )
82   {
83     FileFormats format = FORMAT_UNKNOWN;
84
85     for ( unsigned int i = 0; i < FORMAT_EXTENSIONS_COUNT; ++i )
86     {
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 ) ) )
90       {
91         format = FORMAT_EXTENSIONS[i].format;
92         break;
93       }
94     }
95     return format;
96   }
97
98 }
99
100 TizenImageLoader::TizenImageLoader()
101 {
102 }
103
104 TizenImageLoader::~TizenImageLoader()
105 {
106 }
107
108 const Dali::ImageLoader::BitmapLoader* TizenImageLoader::BitmapLoaderLookup( const std::string& filename ) const
109 {
110   const Dali::ImageLoader::BitmapLoader *lookupPtr = BITMAP_LOADER_LOOKUP_TABLE;
111   FileFormats format =  GetFormatHint( filename );
112   if ( format != FORMAT_UNKNOWN )
113   {
114     lookupPtr = BITMAP_LOADER_LOOKUP_TABLE + format;
115     return lookupPtr;
116   }
117   else
118   {
119     return NULL;
120   }
121 }
122
123 } // namespace Plugin
124
125 } // namespace Dali
126