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 "pixelmap_native_impl.h"
16
17 #include "pixel_map.h"
18
19 using namespace OHOS::Media;
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
OH_PixelmapNative(std::shared_ptr<PixelMap> pixelmap)24 OH_PixelmapNative::OH_PixelmapNative(std::shared_ptr<PixelMap> pixelmap)
25 {
26 if (pixelmap == nullptr) {
27 pixelmap_ = nullptr;
28 return;
29 }
30 pixelmap_ = pixelmap;
31 }
32
OH_PixelmapNative(const uint32_t * colors,uint32_t colorLength,const InitializationOptions & opts)33 OH_PixelmapNative::OH_PixelmapNative(const uint32_t *colors, uint32_t colorLength, const InitializationOptions &opts)
34 {
35 if (opts.pixelFormat == PixelFormat::RGBA_1010102 ||
36 opts.pixelFormat == PixelFormat::YCBCR_P010 ||
37 opts.pixelFormat == PixelFormat::YCRCB_P010) {
38 pixelmap_ = nullptr;
39 } else {
40 auto tmpPixelmap = PixelMap::Create(colors, colorLength, opts);
41 pixelmap_ = std::move(tmpPixelmap);
42 }
43 }
44
OH_PixelmapNative(const InitializationOptions & opts)45 OH_PixelmapNative::OH_PixelmapNative(const InitializationOptions &opts)
46 {
47 if (opts.pixelFormat == PixelFormat::RGBA_1010102 ||
48 opts.pixelFormat == PixelFormat::YCBCR_P010 ||
49 opts.pixelFormat == PixelFormat::YCRCB_P010) {
50 pixelmap_ = nullptr;
51 } else {
52 auto tmpPixelmap = PixelMap::Create(opts);
53 pixelmap_ = std::move(tmpPixelmap);
54 }
55 }
56
OH_PixelmapNative(OH_PixelmapNative * OH_PixelmapNative,const InitializationOptions & opts)57 OH_PixelmapNative::OH_PixelmapNative(OH_PixelmapNative *OH_PixelmapNative, const InitializationOptions &opts)
58 {
59 if (OH_PixelmapNative == nullptr) {
60 pixelmap_ = nullptr;
61 return;
62 }
63 auto pixelmapPtr = OH_PixelmapNative->GetInnerPixelmap().get();
64 auto tmpPixelmap = PixelMap::Create(*pixelmapPtr, opts);
65 pixelmap_ = std::move(tmpPixelmap);
66 }
67
GetInnerPixelmap()68 std::shared_ptr<OHOS::Media::PixelMap> OH_PixelmapNative::GetInnerPixelmap()
69 {
70 return pixelmap_;
71 }
72
~OH_PixelmapNative()73 OH_PixelmapNative::~OH_PixelmapNative()
74 {
75 if (pixelmap_) {
76 pixelmap_ = nullptr;
77 }
78 }
79
80 #ifdef __cplusplus
81 };
82 #endif
83
84 // }
85 // }