blob: 4cf07ed7d921e762d052c2e4acdae69c3ecc8f0e [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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
Dan Sinclaire7786682017-03-29 15:18:41 -040023#include "fxbarcode/common/BC_CommonBitMatrix.h"
Tom Sepez0804b3f2017-05-01 14:06:10 -070024
Tom Sepez1c14ae22018-07-03 15:57:03 +000025#include <algorithm>
26#include <iterator>
27
Tom Sepez1c14ae22018-07-03 15:57:03 +000028#include "third_party/base/stl_util.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040029
Lei Zhang1b228802017-04-05 18:42:22 -070030CBC_CommonBitMatrix::CBC_CommonBitMatrix() {}
31
Dan Sinclair1770c022016-03-14 14:14:16 -040032void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
33 m_width = width;
34 m_height = height;
Henrique Nakashimaf4744422018-08-21 21:36:55 +000035 m_rowSize = (width + 31) >> 5;
Tom Sepez1c14ae22018-07-03 15:57:03 +000036 m_bits = pdfium::Vector2D<int32_t>(m_rowSize, m_height);
Dan Sinclair1770c022016-03-14 14:14:16 -040037}
Lei Zhang1b228802017-04-05 18:42:22 -070038
Tom Sepez1c14ae22018-07-03 15:57:03 +000039CBC_CommonBitMatrix::~CBC_CommonBitMatrix() = default;
Lei Zhang1b228802017-04-05 18:42:22 -070040
41bool CBC_CommonBitMatrix::Get(int32_t x, int32_t y) const {
Dan Sinclair1770c022016-03-14 14:14:16 -040042 int32_t offset = y * m_rowSize + (x >> 5);
Lei Zhang1b228802017-04-05 18:42:22 -070043 if (offset >= m_rowSize * m_height || offset < 0)
Dan Sinclair1770c022016-03-14 14:14:16 -040044 return false;
tsepez736f28a2016-03-25 14:19:51 -070045 return ((((uint32_t)m_bits[offset]) >> (x & 0x1f)) & 1) != 0;
Dan Sinclair1770c022016-03-14 14:14:16 -040046}
Lei Zhang1b228802017-04-05 18:42:22 -070047
Dan Sinclair1770c022016-03-14 14:14:16 -040048void CBC_CommonBitMatrix::Set(int32_t x, int32_t y) {
49 int32_t offset = y * m_rowSize + (x >> 5);
Henrique Nakashimadc2bb9a2018-08-21 19:50:17 +000050 ASSERT(offset >= 0);
51 ASSERT(offset < m_rowSize * m_height);
Dan Sinclair1770c022016-03-14 14:14:16 -040052 m_bits[offset] |= 1 << (x & 0x1f);
53}