PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.18
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.18
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / vendor_prefixed / chillerlan / php-qrcode / src / Common / LuminanceSourceAbstract.php

LuminanceSourceAbstract.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.18, at vendor_prefixed/chillerlan/php-qrcode/src/Common/LuminanceSourceAbstract.php

94 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LuminanceSourceAbstract
5 *
6 * @created 24.01.2021
7 * @author ZXing Authors
8 * @author Ashot Khanamiryan
9 * @author Smiley <smiley@chillerlan.net>
10 * @copyright 2021 Smiley
11 * @license Apache-2.0
12 */
13 namespace WCPOS\Vendor\chillerlan\QRCode\Common;
14
15 use WCPOS\Vendor\chillerlan\QRCode\Decoder\QRCodeDecoderException;
16 use WCPOS\Vendor\chillerlan\QRCode\QROptions;
17 use WCPOS\Vendor\chillerlan\Settings\SettingsContainerInterface;
18 use function array_slice, array_splice, file_exists, is_file, is_readable, realpath;
19 /**
20 * The purpose of this class hierarchy is to abstract different bitmap implementations across
21 * platforms into a standard interface for requesting greyscale luminance values.
22 *
23 * @author dswitkin@google.com (Daniel Switkin)
24 */
25 abstract class LuminanceSourceAbstract implements LuminanceSourceInterface
26 {
27 /** @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface */
28 protected SettingsContainerInterface $options;
29 protected array $luminances;
30 protected int $width;
31 protected int $height;
32 /**
33 *
34 */
35 public function __construct(int $width, int $height, ?SettingsContainerInterface $options = null)
36 {
37 $this->width = $width;
38 $this->height = $height;
39 $this->options = $options ?? new QROptions();
40 $this->luminances = [];
41 }
42 /** @inheritDoc */
43 public function getLuminances() : array
44 {
45 return $this->luminances;
46 }
47 /** @inheritDoc */
48 public function getWidth() : int
49 {
50 return $this->width;
51 }
52 /** @inheritDoc */
53 public function getHeight() : int
54 {
55 return $this->height;
56 }
57 /**
58 * @inheritDoc
59 * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
60 */
61 public function getRow(int $y) : array
62 {
63 if ($y < 0 || $y >= $this->getHeight()) {
64 throw new QRCodeDecoderException('Requested row is outside the image: ' . $y);
65 }
66 $arr = [];
67 array_splice($arr, 0, $this->width, array_slice($this->luminances, $y * $this->width, $this->width));
68 return $arr;
69 }
70 /**
71 *
72 */
73 protected function setLuminancePixel(int $r, int $g, int $b) : void
74 {
75 $this->luminances[] = $r === $g && $g === $b ? $r : ($r + 2 * $g + $b) / 4;
76 // (((($r + 2 * $g + $b) / 4) + 128) % 256) - 128;
77 }
78 /**
79 * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
80 */
81 protected static function checkFile(string $path) : string
82 {
83 $path = \trim($path);
84 if (!file_exists($path) || !is_file($path) || !is_readable($path)) {
85 throw new QRCodeDecoderException('invalid file: ' . $path);
86 }
87 $realpath = realpath($path);
88 if ($realpath === \false) {
89 throw new QRCodeDecoderException('unable to resolve path: ' . $path);
90 }
91 return $realpath;
92 }
93 }
94