• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows:
7 /*
8  * Copyright 2007 ZXing authors
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "fxbarcode/common/BC_CommonBitMatrix.h"
24 
25 #include <algorithm>
26 #include <iterator>
27 
28 #include "third_party/base/stl_util.h"
29 
CBC_CommonBitMatrix()30 CBC_CommonBitMatrix::CBC_CommonBitMatrix() {}
31 
Init(int32_t width,int32_t height)32 void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
33   m_width = width;
34   m_height = height;
35   m_rowSize = (width + 31) >> 5;
36   m_bits = pdfium::Vector2D<int32_t>(m_rowSize, m_height);
37 }
38 
39 CBC_CommonBitMatrix::~CBC_CommonBitMatrix() = default;
40 
Get(int32_t x,int32_t y) const41 bool CBC_CommonBitMatrix::Get(int32_t x, int32_t y) const {
42   int32_t offset = y * m_rowSize + (x >> 5);
43   if (offset >= m_rowSize * m_height || offset < 0)
44     return false;
45   return ((((uint32_t)m_bits[offset]) >> (x & 0x1f)) & 1) != 0;
46 }
47 
Set(int32_t x,int32_t y)48 void CBC_CommonBitMatrix::Set(int32_t x, int32_t y) {
49   int32_t offset = y * m_rowSize + (x >> 5);
50   ASSERT(offset >= 0);
51   ASSERT(offset < m_rowSize * m_height);
52   m_bits[offset] |= 1 << (x & 0x1f);
53 }
54