• 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 "fusion_image_framework_internal.h"
17 
18 #include "c_parcel_internal.h"
19 
20 #include "devicestatus_define.h"
21 #include "fi_log.h"
22 
23 namespace {
24 constexpr ::OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, ::OHOS::Msdp::MSDP_DOMAIN_ID, "fusion_image_framework" };
25 static const int32_t MAX_PIXEL_MAP_WIDTH { 600 };
26 static const int32_t MAX_PIXEL_MAP_HEIGHT { 600 };
27 
CPixelMapFrom(std::shared_ptr<::OHOS::Media::PixelMap> pixelMap)28 CPixelMap* CPixelMapFrom(std::shared_ptr<::OHOS::Media::PixelMap> pixelMap)
29 {
30     auto cImg = new (std::nothrow) CPixelMap;
31     CHKPP(cImg);
32     cImg->refCnt = 1;
33     cImg->pixelMap = pixelMap;
34     return cImg;
35 }
36 
CPixelMapRef(struct CPixelMap * pixelMap)37 struct CPixelMap* CPixelMapRef(struct CPixelMap *pixelMap)
38 {
39     CHKPP(pixelMap);
40     pixelMap->refCnt++;
41     return pixelMap;
42 }
43 
CPixelMapUnref(struct CPixelMap * pixelMap)44 struct CPixelMap* CPixelMapUnref(struct CPixelMap *pixelMap)
45 {
46     CHKPP(pixelMap);
47     if (pixelMap->refCnt > 0) {
48         pixelMap->refCnt--;
49     }
50     if (pixelMap->refCnt > 0) {
51         return pixelMap;
52     }
53     delete pixelMap;
54     return nullptr;
55 }
56 
CPixelMapSerialize(const struct CPixelMap * pixelMap,CParcel * parcel)57 int32_t CPixelMapSerialize(const struct CPixelMap *pixelMap, CParcel *parcel)
58 {
59     CALL_DEBUG_ENTER;
60     CHKPR(parcel, RET_ERR);
61     CHKPR(parcel->parcel_, RET_ERR);
62     CHKPR(pixelMap, RET_ERR);
63     CHKPR(pixelMap->pixelMap, RET_ERR);
64     if (!pixelMap->pixelMap->Marshalling(*parcel->parcel_)) {
65         return RET_ERR;
66     }
67     return RET_OK;
68 }
69 
CPixelMapDeserialize(const CParcel * parcel)70 struct CPixelMap* CPixelMapDeserialize(const CParcel *parcel)
71 {
72     CALL_DEBUG_ENTER;
73     CHKPP(parcel);
74     CHKPP(parcel->parcel_);
75 
76     auto pixelMap = ::OHOS::Media::PixelMap::Unmarshalling(*parcel->parcel_);
77     CHKPP(pixelMap);
78     std::shared_ptr<::OHOS::Media::PixelMap> sPixelMap(pixelMap);
79 
80     if (sPixelMap->GetWidth() > MAX_PIXEL_MAP_WIDTH || sPixelMap->GetHeight() > MAX_PIXEL_MAP_HEIGHT) {
81         FI_HILOGE("Pixelmap is oversize, width:%{public}d, height:%{public}d",
82             sPixelMap->GetWidth(), sPixelMap->GetHeight());
83         return nullptr;
84     }
85     return CPixelMapFrom(sPixelMap);
86 }
87 } // namespace