1 /*
2 * Copyright (c) 2025 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 "picture_impl.h"
17
18 #include "image_common.h"
19 #include "image_log.h"
20
21 namespace OHOS {
22 namespace Media {
PictureImpl(std::shared_ptr<Picture> picture)23 PictureImpl::PictureImpl(std::shared_ptr<Picture> picture)
24 {
25 static std::atomic<uint32_t> currentId = 0;
26 uniqueId_ = currentId.fetch_add(1, std::memory_order_relaxed);
27 nativePicture_ = picture;
28 }
29
~PictureImpl()30 PictureImpl::~PictureImpl()
31 {
32 release();
33 }
34
release()35 void PictureImpl::release()
36 {
37 if (!isRelease) {
38 if (nativePicture_ != nullptr) {
39 nativePicture_ = nullptr;
40 }
41 isRelease = true;
42 }
43 }
44
GetPicture()45 std::shared_ptr<Picture> PictureImpl::GetPicture()
46 {
47 return nativePicture_;
48 }
49
SetMetadata(MetadataType metadataType,std::shared_ptr<ImageMetadata> imageMetadata)50 uint32_t PictureImpl::SetMetadata(MetadataType metadataType, std::shared_ptr<ImageMetadata> imageMetadata)
51 {
52 IMAGE_LOGD("SetMetadata IN");
53 if (nativePicture_ == nullptr) {
54 IMAGE_LOGE("Empty native picture");
55 return IMAGE_BAD_PARAMETER;
56 }
57 if (metadataType != MetadataType::EXIF) {
58 IMAGE_LOGE("Unsupport MetadataType");
59 return IMAGE_UNSUPPORTED_METADATA;
60 }
61 return nativePicture_->SetExifMetadata(std::reinterpret_pointer_cast<ExifMetadata>(imageMetadata));
62 }
63
GetMetadata(MetadataType metadataType,uint32_t * errCode)64 std::shared_ptr<ImageMetadata> PictureImpl::GetMetadata(MetadataType metadataType, uint32_t* errCode)
65 {
66 IMAGE_LOGD("GetMetadata IN");
67 if (nativePicture_ == nullptr) {
68 IMAGE_LOGE("Empty native picture");
69 return nullptr;
70 }
71 if (metadataType != MetadataType::EXIF) {
72 *errCode = IMAGE_UNSUPPORTED_METADATA;
73 IMAGE_LOGE("Unsupport MetadataType");
74 return nullptr;
75 }
76 return std::reinterpret_pointer_cast<ImageMetadata>(nativePicture_->GetExifMetadata());
77 }
78 } // namespace Media
79 } // namespace OHOS