1 /*
2  * Copyright (C) 2024 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 "effect_context.h"
17 #include "effect_log.h"
18 
19 namespace OHOS {
20 namespace Media {
21 namespace Effect {
22 
GetExifMetadataFromPixelmap(PixelMap * pixelMap)23 std::shared_ptr<ExifMetadata> GetExifMetadataFromPixelmap(PixelMap *pixelMap)
24 {
25     CHECK_AND_RETURN_RET_LOG(pixelMap != nullptr, nullptr,
26         "EffectContext::GetExifMetadataFromPixelmap: pixelmap is null");
27 
28     return pixelMap->GetExifMetadata();
29 }
30 
GetExifMetadataFromPicture(Picture * picture)31 std::shared_ptr<ExifMetadata> GetExifMetadataFromPicture(Picture *picture)
32 {
33     CHECK_AND_RETURN_RET_LOG(picture != nullptr, nullptr,
34         "EffectContext::GetExifMetadataFromPicture: picture is null");
35 
36     return picture->GetExifMetadata();
37 }
38 
GetExifMetadata()39 std::shared_ptr<ExifMetadata> EffectContext::GetExifMetadata()
40 {
41     CHECK_AND_RETURN_RET_LOG(renderStrategy_ != nullptr, nullptr,
42         "EffectContext::GetExifMetadata: renderStrategy_ is null");
43 
44     EffectBuffer *src = renderStrategy_->GetInput();
45     CHECK_AND_RETURN_RET_LOG(src != nullptr, nullptr, "EffectContext::GetExifMetadata: src is null");
46 
47     std::shared_ptr<ExtraInfo> &extraInfo = src->extraInfo_;
48     CHECK_AND_RETURN_RET_LOG(extraInfo != nullptr, nullptr, "EffectContext::GetExifMetadata: extraInfo is null");
49 
50     switch (extraInfo->dataType) {
51         case DataType::PIXEL_MAP:
52             return GetExifMetadataFromPixelmap(extraInfo->pixelMap);
53         case DataType::PATH:
54         case DataType::URI:
55             return GetExifMetadataFromPixelmap(extraInfo->innerPixelMap.get());
56         case DataType::PICTURE:
57             return GetExifMetadataFromPicture(extraInfo->picture);
58         default:
59             EFFECT_LOGW("EffectContext::GetExifMetadata: dataType=%{public}d not contain exif!", extraInfo->dataType);
60             return nullptr;
61     }
62 }
63 
64 } // namespace Effect
65 } // namespace Media
66 } // namespace OHOS
67