123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- namespace Zxing\Common;
- use Zxing\NotFoundException;
- abstract class GridSampler
- {
- private static $gridSampler;
-
- public static function setGridSampler($newGridSampler)
- {
- self::$gridSampler = $newGridSampler;
- }
-
- public static function getInstance()
- {
- if (!self::$gridSampler) {
- self::$gridSampler = new DefaultGridSampler();
- }
- return self::$gridSampler;
- }
-
- protected static function checkAndNudgePoints(
- $image,
- $points
- ) {
- $width = $image->getWidth();
- $height = $image->getHeight();
- $nudged = true;
- for ($offset = 0; $offset < count($points) && $nudged; $offset += 2) {
- $x = (int)$points[$offset];
- $y = (int)$points[$offset + 1];
- if ($x < -1 || $x > $width || $y < -1 || $y > $height) {
- throw NotFoundException::getNotFoundInstance();
- }
- $nudged = false;
- if ($x == -1) {
- $points[$offset] = 0.0;
- $nudged = true;
- } else if ($x == $width) {
- $points[$offset] = $width - 1;
- $nudged = true;
- }
- if ($y == -1) {
- $points[$offset + 1] = 0.0;
- $nudged = true;
- } else if ($y == $height) {
- $points[$offset + 1] = $height - 1;
- $nudged = true;
- }
- }
- $nudged = true;
- for ($offset = count($points) - 2; $offset >= 0 && $nudged; $offset -= 2) {
- $x = (int)$points[$offset];
- $y = (int)$points[$offset + 1];
- if ($x < -1 || $x > $width || $y < -1 || $y > $height) {
- throw NotFoundException::getNotFoundInstance();
- }
- $nudged = false;
- if ($x == -1) {
- $points[$offset] = 0.0;
- $nudged = true;
- } else if ($x == $width) {
- $points[$offset] = $width - 1;
- $nudged = true;
- }
- if ($y == -1) {
- $points[$offset + 1] = 0.0;
- $nudged = true;
- } else if ($y == $height) {
- $points[$offset + 1] = $height - 1;
- $nudged = true;
- }
- }
- }
-
- public abstract function sampleGrid(
- $image,
- $dimensionX,
- $dimensionY,
- $p1ToX, $p1ToY,
- $p2ToX, $p2ToY,
- $p3ToX, $p3ToY,
- $p4ToX, $p4ToY,
- $p1FromX, $p1FromY,
- $p2FromX, $p2FromY,
- $p3FromX, $p3FromY,
- $p4FromX, $p4FromY
- );
- public abstract function sampleGrid_(
- $image,
- $dimensionX,
- $dimensionY,
- $transform
- );
- }
|