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
16 #include "scan_parameters.h"
17 #include "scan_log.h"
18
19 namespace OHOS::Scan {
ScanParameters()20 ScanParameters::ScanParameters() : format_(SCAN_FRAME_GRAY),
21 lastFrame_(false), bytesPerLine_(0), pixelsPerLine_(0), lines_(0), depth_(0)
22 {}
23
ScanParameters(const ScanParameters & right)24 ScanParameters::ScanParameters(const ScanParameters &right)
25 {
26 format_ = right.format_;
27 lastFrame_ = right.lastFrame_;
28 bytesPerLine_ = right.bytesPerLine_;
29 pixelsPerLine_ = right.pixelsPerLine_;
30 lines_ = right.lines_;
31 depth_ = right.depth_;
32 }
33
operator =(const ScanParameters & right)34 ScanParameters &ScanParameters::operator=(const ScanParameters &right)
35 {
36 if (this != &right) {
37 format_ = right.format_;
38 lastFrame_ = right.lastFrame_;
39 bytesPerLine_ = right.bytesPerLine_;
40 pixelsPerLine_ = right.pixelsPerLine_;
41 lines_ = right.lines_;
42 depth_ = right.depth_;
43 }
44 return *this;
45 }
46
~ScanParameters()47 ScanParameters::~ScanParameters()
48 {}
49
Reset()50 void ScanParameters::Reset()
51 {
52 format_ = SCAN_FRAME_GRAY;
53 lastFrame_ = false;
54 bytesPerLine_ = 0;
55 pixelsPerLine_ = 0;
56 lines_ = 0;
57 depth_ = 0;
58 }
59
SetFormat(const ScanFrame & format)60 void ScanParameters::SetFormat(const ScanFrame &format)
61 {
62 format_ = format;
63 }
64
SetLastFrame(const bool & lastFrame)65 void ScanParameters::SetLastFrame(const bool &lastFrame)
66 {
67 lastFrame_ = lastFrame;
68 }
69
SetBytesPerLine(const int32_t & bytesPerLine)70 void ScanParameters::SetBytesPerLine(const int32_t &bytesPerLine)
71 {
72 bytesPerLine_ = bytesPerLine;
73 }
74
SetPixelsPerLine(const int32_t & pixelsPerLine)75 void ScanParameters::SetPixelsPerLine(const int32_t &pixelsPerLine)
76 {
77 pixelsPerLine_ = pixelsPerLine;
78 }
79
SetLines(const int32_t & lines)80 void ScanParameters::SetLines(const int32_t &lines)
81 {
82 lines_ = lines;
83 }
84
SetDepth(const int32_t & depth)85 void ScanParameters::SetDepth(const int32_t &depth)
86 {
87 depth_ = depth;
88 }
89
GetFormat() const90 ScanFrame ScanParameters::GetFormat() const
91 {
92 return format_;
93 }
94
GetLastFrame() const95 bool ScanParameters::GetLastFrame() const
96 {
97 return lastFrame_;
98 }
99
GetBytesPerLine() const100 int32_t ScanParameters::GetBytesPerLine() const
101 {
102 return bytesPerLine_;
103 }
104
GetPixelsPerLine() const105 int32_t ScanParameters::GetPixelsPerLine() const
106 {
107 return pixelsPerLine_;
108 }
109
GetLines() const110 int32_t ScanParameters::GetLines() const
111 {
112 return lines_;
113 }
114
GetDepth() const115 int32_t ScanParameters::GetDepth() const
116 {
117 return depth_;
118 }
119
120
ReadFromParcel(Parcel & parcel)121 void ScanParameters::ReadFromParcel(Parcel &parcel)
122 {
123 SetFormat((ScanFrame)parcel.ReadUint32());
124 SetLastFrame(parcel.ReadBool());
125 SetBytesPerLine(parcel.ReadInt32());
126 SetPixelsPerLine(parcel.ReadInt32());
127 SetLines(parcel.ReadInt32());
128 SetDepth(parcel.ReadInt32());
129 }
130
Marshalling(Parcel & parcel) const131 bool ScanParameters::Marshalling(Parcel &parcel) const
132 {
133 parcel.WriteUint32((uint32_t)format_);
134 parcel.WriteBool(lastFrame_);
135 parcel.WriteInt32(bytesPerLine_);
136 parcel.WriteInt32(pixelsPerLine_);
137 parcel.WriteInt32(lines_);
138 parcel.WriteInt32(depth_);
139 return true;
140 }
141
Unmarshalling(Parcel & parcel)142 std::shared_ptr<ScanParameters> ScanParameters::Unmarshalling(Parcel &parcel)
143 {
144 auto nativeObj = std::make_shared<ScanParameters>();
145 nativeObj->ReadFromParcel(parcel);
146 return nativeObj;
147 }
148
Dump()149 void ScanParameters::Dump()
150 {
151 SCAN_HILOGI("Format = %{public}u", format_);
152 SCAN_HILOGI("LastFrame = %{public}d", lastFrame_);
153 SCAN_HILOGI("BytesPerLine = %{public}d", bytesPerLine_);
154 SCAN_HILOGI("PixelsPerLine = %{public}d", pixelsPerLine_);
155 SCAN_HILOGI("Lines = %{public}d", lines_);
156 SCAN_HILOGI("Depth = %{public}d", depth_);
157 }
158 } // namespace OHOS::Scan
159