1 /*
2 * Copyright (C) 2022 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 #include "image_source_native_impl.h"
16
17 using namespace OHOS;
18 using namespace Media;
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
~OH_ImageSourceNative()23 OH_ImageSourceNative::~OH_ImageSourceNative()
24 {
25 if (innerImageSource_) {
26 innerImageSource_ = nullptr;
27 }
28 }
29
GetInnerImageSource()30 std::shared_ptr<ImageSource> OH_ImageSourceNative::GetInnerImageSource()
31 {
32 return innerImageSource_;
33 }
34
OH_ImageSourceNative(std::shared_ptr<ImageSource> imageSource)35 OH_ImageSourceNative::OH_ImageSourceNative(std::shared_ptr<ImageSource> imageSource)
36 {
37 innerImageSource_ = imageSource;
38 }
39
OH_ImageSourceNative(char * uri,size_t size,SourceOptions opts)40 OH_ImageSourceNative::OH_ImageSourceNative(char *uri, size_t size, SourceOptions opts)
41 {
42 std::string strUri = std::string(uri, size);
43 std::string path = UrlToPath(strUri);
44 uint32_t errorCode = IMAGE_BAD_PARAMETER;
45 std::unique_ptr<ImageSource> nativeImageSource = ImageSource::CreateImageSource(path, opts, errorCode);
46 if (nativeImageSource == nullptr) {
47 innerImageSource_ = nullptr;
48 return;
49 }
50 innerImageSource_ = std::move(nativeImageSource);
51 }
52
OH_ImageSourceNative(int32_t fd,SourceOptions opts)53 OH_ImageSourceNative::OH_ImageSourceNative(int32_t fd, SourceOptions opts)
54 {
55 uint32_t errorCode = IMAGE_BAD_PARAMETER;
56 std::unique_ptr<ImageSource> nativeImageSource = ImageSource::CreateImageSource(fd, opts, errorCode);
57 if (nativeImageSource == nullptr) {
58 innerImageSource_ = nullptr;
59 return;
60 }
61 innerImageSource_ = std::move(nativeImageSource);
62 }
63
OH_ImageSourceNative(uint8_t * data,size_t dataSize,SourceOptions opts)64 OH_ImageSourceNative::OH_ImageSourceNative(uint8_t *data, size_t dataSize, SourceOptions opts)
65 {
66 uint32_t errorCode = IMAGE_BAD_PARAMETER;
67 std::unique_ptr<ImageSource> nativeImageSource = ImageSource::CreateImageSource(
68 data, dataSize, opts, errorCode);
69 if (nativeImageSource == nullptr) {
70 innerImageSource_ = nullptr;
71 return;
72 }
73 innerImageSource_ = std::move(nativeImageSource);
74 }
75
OH_ImageSourceNative(RawFileDescriptor rawFile,SourceOptions opts)76 OH_ImageSourceNative::OH_ImageSourceNative(RawFileDescriptor rawFile, SourceOptions opts)
77 {
78 uint32_t errorCode = IMAGE_BAD_PARAMETER;
79 int32_t rawFileLength = rawFile.start + rawFile.length;
80 std::unique_ptr<ImageSource> nativeImageSource = ImageSource::CreateImageSource(
81 rawFile.fd, rawFile.start, rawFileLength, opts, errorCode);
82 if (nativeImageSource == nullptr) {
83 innerImageSource_ = nullptr;
84 return;
85 }
86 innerImageSource_ = std::move(nativeImageSource);
87 }
88
OH_DecodingOptionsForPicture(std::shared_ptr<OHOS::Media::DecodingOptionsForPicture> decodingOptionsForPicture)89 OH_DecodingOptionsForPicture::OH_DecodingOptionsForPicture(
90 std::shared_ptr<OHOS::Media::DecodingOptionsForPicture> decodingOptionsForPicture)
91 {
92 decodingOptionsForPicture_ = decodingOptionsForPicture;
93 }
94
~OH_DecodingOptionsForPicture()95 OH_DecodingOptionsForPicture::~OH_DecodingOptionsForPicture() {}
96
GetInnerDecodingOptForPicture()97 std::shared_ptr<OHOS::Media::DecodingOptionsForPicture> OH_DecodingOptionsForPicture::GetInnerDecodingOptForPicture()
98 {
99 return decodingOptionsForPicture_;
100 }
101
102 #ifdef __cplusplus
103 };
104 #endif