• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_decoder.h"
20 #include "gif_format_agent.h"
21 #include "hilog/log.h"
22 #include "hilog/log_c.h"
23 #include "hilog/log_cpp.h"
24 #include "iosfwd"
25 #include "jpeg_decoder.h"
26 #include "jpeg_encoder.h"
27 #include "jpeg_format_agent.h"
28 #include "log_tags.h"
29 #include "map"
30 #include "plugin_class_base.h"
31 #include "plugin_utils.h"
32 #include "png_decoder.h"
33 #include "png_format_agent.h"
34 #include "raw_decoder.h"
35 #include "raw_format_agent.h"
36 #include "string"
37 #include "svg_decoder.h"
38 #include "svg_format_agent.h"
39 #include "utility"
40 #include "wbmp_format_agent.h"
41 #include "webp_decoder.h"
42 #include "webp_encoder.h"
43 #include "webp_format_agent.h"
44 
45 namespace {
46     const std::string PACKAGE_NAME = ("LibImagePluginsExport");
47 }
48 
49 // register implement classes of this plugin.
50 PLUGIN_EXPORT_REGISTER_CLASS_BEGIN
51 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::BmpDecoder)
52 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::BmpFormatAgent)
53 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::JpegDecoder)
54 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::JpegEncoder)
55 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::JpegFormatAgent)
56 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::PngDecoder)
57 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::PngFormatAgent)
58 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::GifDecoder)
59 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::GifFormatAgent)
60 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WebpDecoder)
61 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WebpEncoder)
62 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WebpFormatAgent)
63 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WbmpFormatAgent)
64 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::RawDecoder)
65 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::RawFormatAgent)
66 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::SvgDecoder)
67 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::SvgFormatAgent)
68 PLUGIN_EXPORT_REGISTER_CLASS_END
69 
70 using std::string;
71 using namespace OHOS::HiviewDFX;
72 
73 static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibImagePluginsExport" };
74 
75 #define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__)
76 #define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__)
77 
78 // define the external interface of this plugin.
79 PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()80 PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
81 OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
82 {
83     HiLog::Debug(LABEL, "LibImagePluginsExport: create object for package: %{public}s, class: %{public}s.",
84                  PACKAGE_NAME.c_str(), className.c_str());
85 
86     auto iter = implClassMap.find(className);
87     if (iter == implClassMap.end()) {
88         HiLog::Error(LABEL, "LibImagePluginsExport: failed to find class: %{public}s, in package: %{public}s.",
89                      className.c_str(), PACKAGE_NAME.c_str());
90         return nullptr;
91     }
92 
93     auto creator = iter->second;
94     if (creator == nullptr) {
95         HiLog::Error(LABEL, "LibImagePluginsExport: null creator for class: %{public}s, in package: %{public}s.",
96                      className.c_str(), PACKAGE_NAME.c_str());
97         return nullptr;
98     }
99 
100     return creator();
101 }