Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 23 | #include "fxbarcode/common/BC_CommonBitMatrix.h" |
Tom Sepez | 0804b3f | 2017-05-01 14:06:10 -0700 | [diff] [blame] | 24 | |
Tom Sepez | 1c14ae2 | 2018-07-03 15:57:03 +0000 | [diff] [blame] | 25 | #include <algorithm> |
| 26 | #include <iterator> |
| 27 | |
Tom Sepez | 1c14ae2 | 2018-07-03 15:57:03 +0000 | [diff] [blame] | 28 | #include "third_party/base/stl_util.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 29 | |
Lei Zhang | 1b22880 | 2017-04-05 18:42:22 -0700 | [diff] [blame] | 30 | CBC_CommonBitMatrix::CBC_CommonBitMatrix() {} |
| 31 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 32 | void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) { |
| 33 | m_width = width; |
| 34 | m_height = height; |
Henrique Nakashima | f474442 | 2018-08-21 21:36:55 +0000 | [diff] [blame] | 35 | m_rowSize = (width + 31) >> 5; |
Tom Sepez | 1c14ae2 | 2018-07-03 15:57:03 +0000 | [diff] [blame] | 36 | m_bits = pdfium::Vector2D<int32_t>(m_rowSize, m_height); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 37 | } |
Lei Zhang | 1b22880 | 2017-04-05 18:42:22 -0700 | [diff] [blame] | 38 | |
Tom Sepez | 1c14ae2 | 2018-07-03 15:57:03 +0000 | [diff] [blame] | 39 | CBC_CommonBitMatrix::~CBC_CommonBitMatrix() = default; |
Lei Zhang | 1b22880 | 2017-04-05 18:42:22 -0700 | [diff] [blame] | 40 | |
| 41 | bool CBC_CommonBitMatrix::Get(int32_t x, int32_t y) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 42 | int32_t offset = y * m_rowSize + (x >> 5); |
Lei Zhang | 1b22880 | 2017-04-05 18:42:22 -0700 | [diff] [blame] | 43 | if (offset >= m_rowSize * m_height || offset < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 44 | return false; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 45 | return ((((uint32_t)m_bits[offset]) >> (x & 0x1f)) & 1) != 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 46 | } |
Lei Zhang | 1b22880 | 2017-04-05 18:42:22 -0700 | [diff] [blame] | 47 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 48 | void CBC_CommonBitMatrix::Set(int32_t x, int32_t y) { |
| 49 | int32_t offset = y * m_rowSize + (x >> 5); |
Henrique Nakashima | dc2bb9a | 2018-08-21 19:50:17 +0000 | [diff] [blame] | 50 | ASSERT(offset >= 0); |
| 51 | ASSERT(offset < m_rowSize * m_height); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 52 | m_bits[offset] |= 1 << (x & 0x1f); |
| 53 | } |