Procházet zdrojové kódy

:octocat: move luminance source selection back to QRCode

smiley před 3 roky
rodič
revize
8c79c82bda
2 změnil soubory, kde provedl 17 přidání a 16 odebrání
  1. 17 3
      src/QRCode.php
  2. 0 13
      src/QROptionsTrait.php

+ 17 - 3
src/QRCode.php

@@ -12,7 +12,7 @@ namespace chillerlan\QRCode;
 
 
 use chillerlan\QRCode\Common\{EccLevel, ECICharset, MaskPattern, Mode, Version};
 use chillerlan\QRCode\Common\{EccLevel, ECICharset, MaskPattern, Mode, Version};
 use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Kanji, Number, QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
 use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Kanji, Number, QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
-use chillerlan\QRCode\Decoder\{Decoder, DecoderResult, LuminanceSourceInterface};
+use chillerlan\QRCode\Decoder\{Decoder, DecoderResult, GDLuminanceSource, IMagickLuminanceSource, LuminanceSourceInterface};
 use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
 use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
 use chillerlan\Settings\SettingsContainerInterface;
 use chillerlan\Settings\SettingsContainerInterface;
 use function class_exists, class_implements, in_array, mb_convert_encoding, mb_detect_encoding;
 use function class_exists, class_implements, in_array, mb_convert_encoding, mb_detect_encoding;
@@ -170,6 +170,11 @@ class QRCode{
 	 */
 	 */
 	protected array $dataSegments = [];
 	protected array $dataSegments = [];
 
 
+	/**
+	 * The luminance source for the reader
+	 */
+	protected string $luminanceSourceFQN = GDLuminanceSource::class;
+
 	/**
 	/**
 	 * QRCode constructor.
 	 * QRCode constructor.
 	 *
 	 *
@@ -177,6 +182,11 @@ class QRCode{
 	 */
 	 */
 	public function __construct(SettingsContainerInterface $options = null){
 	public function __construct(SettingsContainerInterface $options = null){
 		$this->options = $options ?? new QROptions;
 		$this->options = $options ?? new QROptions;
+
+		// i hate this less
+		if($this->options->readerUseImagickIfAvailable){
+			$this->luminanceSourceFQN = IMagickLuminanceSource::class;
+		}
 	}
 	}
 
 
 	/**
 	/**
@@ -420,16 +430,20 @@ class QRCode{
 
 
 	/**
 	/**
 	 * Reads a QR Code from a given file
 	 * Reads a QR Code from a given file
+	 *
+	 * @noinspection PhpUndefinedMethodInspection
 	 */
 	 */
 	public function readFromFile(string $path):DecoderResult{
 	public function readFromFile(string $path):DecoderResult{
-		return $this->readFromSource($this->options->getLuminanceSourceFQCN()::fromFile($path, $this->options));
+		return $this->readFromSource($this->luminanceSourceFQN::fromFile($path, $this->options));
 	}
 	}
 
 
 	/**
 	/**
 	 * Reads a QR Code from the given data blob
 	 * Reads a QR Code from the given data blob
+	 *
+	 *  @noinspection PhpUndefinedMethodInspection
 	 */
 	 */
 	public function readFromBlob(string $blob):DecoderResult{
 	public function readFromBlob(string $blob):DecoderResult{
-		return $this->readFromSource($this->options->getLuminanceSourceFQCN()::fromBlob($blob, $this->options));
+		return $this->readFromSource($this->luminanceSourceFQN::fromBlob($blob, $this->options));
 	}
 	}
 
 
 	/**
 	/**

+ 0 - 13
src/QROptionsTrait.php

@@ -14,7 +14,6 @@ namespace chillerlan\QRCode;
 
 
 use chillerlan\QRCode\Output\QROutputInterface;
 use chillerlan\QRCode\Output\QROutputInterface;
 use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version};
 use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version};
-use chillerlan\QRCode\Decoder\{GDLuminanceSource, IMagickLuminanceSource};
 use function array_values, count, extension_loaded, in_array, is_numeric, max, min, sprintf, strtolower;
 use function array_values, count, extension_loaded, in_array, is_numeric, max, min, sprintf, strtolower;
 
 
 /**
 /**
@@ -460,18 +459,6 @@ trait QROptionsTrait{
 		$this->readerUseImagickIfAvailable = $useImagickIfAvailable && extension_loaded('imagick');
 		$this->readerUseImagickIfAvailable = $useImagickIfAvailable && extension_loaded('imagick');
 	}
 	}
 
 
-	/**
-	 * returns the FQCN of the luminance source class to use in the reader (GD or Imagick)
-	 *
-	 * @see \chillerlan\QRCode\Decoder\LuminanceSourceInterface
-	 */
-	public function getLuminanceSourceFQCN():string{
-		// i still hate this
-		return $this->readerUseImagickIfAvailable
-			? IMagickLuminanceSource::class
-			: GDLuminanceSource::class;
-	}
-
 	/**
 	/**
 	 * clamp the logo space values between 0 and maximum length (177 modules at version 40)
 	 * clamp the logo space values between 0 and maximum length (177 modules at version 40)
 	 */
 	 */