Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zxing-cpp/core/src/Matrix.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 * Copyright 2016 Huy Cuong Nguyen | |
| 3 * Copyright 2016 ZXing authors | |
| 4 */ | |
| 5 // SPDX-License-Identifier: Apache-2.0 | |
| 6 | |
| 7 #pragma once | |
| 8 | |
| 9 #include "Point.h" | |
| 10 #include "ZXAlgorithms.h" | |
| 11 | |
| 12 #include <stdexcept> | |
| 13 #include <algorithm> | |
| 14 #include <cassert> | |
| 15 #include <vector> | |
| 16 | |
| 17 namespace ZXing { | |
| 18 | |
| 19 template <class T> | |
| 20 class Matrix | |
| 21 { | |
| 22 public: | |
| 23 using value_t = T; | |
| 24 | |
| 25 private: | |
| 26 int _width = 0; | |
| 27 int _height = 0; | |
| 28 std::vector<value_t> _data; | |
| 29 | |
| 30 // Nothing wrong to support it, just to make it explicit, instead of by mistake. | |
| 31 // Use copy() below. | |
| 32 Matrix(const Matrix &) = default; | |
| 33 Matrix& operator=(const Matrix &) = delete; | |
| 34 | |
| 35 public: | |
| 36 Matrix() = default; | |
| 37 | |
| 38 #if defined(__llvm__) || (defined(__GNUC__) && (__GNUC__ > 7)) | |
| 39 __attribute__((no_sanitize("signed-integer-overflow"))) | |
| 40 #endif | |
| 41 Matrix(int width, int height, value_t val = {}) : _width(width), _height(height), _data(_width * _height, val) { | |
| 42 if (width != 0 && Size(_data) / width != height) | |
| 43 throw std::invalid_argument("Invalid size: width * height is too big"); | |
| 44 } | |
| 45 | |
| 46 Matrix(Matrix&&) noexcept = default; | |
| 47 Matrix& operator=(Matrix&&) noexcept = default; | |
| 48 | |
| 49 Matrix copy() const { | |
| 50 return *this; | |
| 51 } | |
| 52 | |
| 53 int height() const { | |
| 54 return _height; | |
| 55 } | |
| 56 | |
| 57 int width() const { | |
| 58 return _width; | |
| 59 } | |
| 60 | |
| 61 int size() const { | |
| 62 return Size(_data); | |
| 63 } | |
| 64 | |
| 65 value_t& operator()(int x, int y) | |
| 66 { | |
| 67 assert(x >= 0 && x < _width && y >= 0 && y < _height); | |
| 68 return _data[y * _width + x]; | |
| 69 } | |
| 70 | |
| 71 const T& operator()(int x, int y) const | |
| 72 { | |
| 73 assert(x >= 0 && x < _width && y >= 0 && y < _height); | |
| 74 return _data[y * _width + x]; | |
| 75 } | |
| 76 | |
| 77 const value_t& get(int x, int y) const { | |
| 78 return operator()(x, y); | |
| 79 } | |
| 80 | |
| 81 value_t& set(int x, int y, value_t value) { | |
| 82 return operator()(x, y) = value; | |
| 83 } | |
| 84 | |
| 85 const value_t& get(PointI p) const { | |
| 86 return operator()(p.x, p.y); | |
| 87 } | |
| 88 | |
| 89 value_t& set(PointI p, value_t value) { | |
| 90 return operator()(p.x, p.y) = value; | |
| 91 } | |
| 92 | |
| 93 const value_t* data() const { | |
| 94 return _data.data(); | |
| 95 } | |
| 96 | |
| 97 const value_t* begin() const { | |
| 98 return _data.data(); | |
| 99 } | |
| 100 | |
| 101 const value_t* end() const { | |
| 102 return _data.data() + _width * _height; | |
| 103 } | |
| 104 | |
| 105 value_t* begin() { | |
| 106 return _data.data(); | |
| 107 } | |
| 108 | |
| 109 value_t* end() { | |
| 110 return _data.data() + _width * _height; | |
| 111 } | |
| 112 | |
| 113 void clear(value_t value = {}) { | |
| 114 std::fill(_data.begin(), _data.end(), value); | |
| 115 } | |
| 116 }; | |
| 117 | |
| 118 } // ZXing |
