• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sane_parameters.h"
17 #include "scan_log.h"
18 #include "message_parcel.h"
19 
20 namespace OHOS::Scan {
SaneParameters()21 SaneParameters::SaneParameters() : format_(SANE_FRAME_GRAY), lastFrame_(0),
22     bytesPerLine_(0), pixelsPerLine_(0), lines_(0), depth_(0) {}
Marshalling(Parcel & parcel) const23 bool SaneParameters::Marshalling(Parcel &parcel) const
24 {
25     bool status = true;
26     status &= parcel.WriteInt32(static_cast<int32_t>(format_));
27     status &= parcel.WriteInt32(static_cast<int32_t>(lastFrame_));
28     status &= parcel.WriteInt32(bytesPerLine_);
29     status &= parcel.WriteInt32(pixelsPerLine_);
30     status &= parcel.WriteInt32(lines_);
31     status &= parcel.WriteInt32(depth_);
32     return status;
33 }
34 
Unmarshalling(Parcel & parcel)35 SaneParameters* SaneParameters::Unmarshalling(Parcel &parcel)
36 {
37     SaneParameters* obj = new (std::nothrow) SaneParameters();
38     if (obj == nullptr) {
39         SCAN_HILOGE("obj is a nullptr.");
40         return nullptr;
41     }
42     obj->format_ = static_cast<SaneFrame>(parcel.ReadInt32());
43     obj->lastFrame_ = parcel.ReadInt32();
44     obj->bytesPerLine_ = parcel.ReadInt32();
45     obj->pixelsPerLine_ = parcel.ReadInt32();
46     obj->lines_ = parcel.ReadInt32();
47     obj->depth_ = parcel.ReadInt32();
48     return obj;
49 }
50 }   // namespace OHOS::Scan