1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "plugin_export.h"
17 #include "bmp_decoder.h"
18 #include "bmp_format_agent.h"
19 #include "gif_encoder.h"
20 #include "gif_format_agent.h"
21 #include "image_log.h"
22 #include "iosfwd"
23 #include "jpeg_decoder.h"
24 #include "jpeg_encoder.h"
25 #include "jpeg_format_agent.h"
26 #include "map"
27 #include "plugin_class_base.h"
28 #include "plugin_utils.h"
29 #include "png_decoder.h"
30 #include "png_format_agent.h"
31 #include "raw_decoder.h"
32 #include "raw_format_agent.h"
33 #include "string"
34 #include "svg_decoder.h"
35 #include "svg_format_agent.h"
36 #include "utility"
37 #include "wbmp_format_agent.h"
38 #include "webp_decoder.h"
39 #include "webp_encoder.h"
40 #include "webp_format_agent.h"
41 #include "ext_decoder.h"
42 #include "ext_encoder.h"
43 #undef LOG_DOMAIN
44 #define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
45 #undef LOG_TAG
46 #define LOG_TAG "BmpFormatAgent"
47
48 namespace {
49 const std::string PACKAGE_NAME = ("LibImagePluginsExport");
50 }
51
52 // register implement classes of this plugin.
53 PLUGIN_EXPORT_REGISTER_CLASS_BEGIN
54 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::BmpDecoder)
55 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::BmpFormatAgent)
56 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::JpegDecoder)
57 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::JpegEncoder)
58 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::JpegFormatAgent)
59 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::PngDecoder)
60 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::PngFormatAgent)
61 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::GifEncoder)
62 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::GifFormatAgent)
63 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WebpDecoder)
64 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WebpEncoder)
65 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WebpFormatAgent)
66 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WbmpFormatAgent)
67 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::RawDecoder)
68 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::RawFormatAgent)
69 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::SvgDecoder)
70 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::SvgFormatAgent)
71 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::ExtDecoder)
72 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::ExtEncoder)
73 PLUGIN_EXPORT_REGISTER_CLASS_END
74
75 using std::string;
76
77 // define the external interface of this plugin.
78 PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()79 PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
80 OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
81 {
82 IMAGE_LOGD("LibImagePluginsExport: create object for package: %{public}s, class: %{public}s.",
83 PACKAGE_NAME.c_str(), className.c_str());
84
85 auto iter = implClassMap.find(className);
86 if (iter == implClassMap.end()) {
87 IMAGE_LOGE("LibImagePluginsExport: failed to find class: %{public}s, in package: %{public}s.",
88 className.c_str(), PACKAGE_NAME.c_str());
89 return nullptr;
90 }
91
92 auto creator = iter->second;
93 if (creator == nullptr) {
94 IMAGE_LOGE("LibImagePluginsExport: null creator for class: %{public}s, in package: %{public}s.",
95 className.c_str(), PACKAGE_NAME.c_str());
96 return nullptr;
97 }
98
99 return creator();
100 }