@@ -0,0 +1,3081 @@
+// Copyright 2019 Google LLC%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     https://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.sps;%0A%0Aimport com.google.auto.value.AutoValue;%0A%0A// Import the ZXing barcode image processing library.%0Aimport com.google.zxing.BinaryBitmap;%0Aimport com.google.zxing.ChecksumException;%0Aimport com.google.zxing.FormatException;%0Aimport com.google.zxing.MultiFormatReader;%0Aimport com.google.zxing.NotFoundException;%0Aimport com.google.zxing.Reader;%0Aimport com.google.zxing.Result;%0Aimport com.google.zxing.client.j2se.BufferedImageLuminanceSource;%0Aimport com.google.zxing.common.HybridBinarizer;%0A%0Aimport javax.imageio.ImageIO;%0A%0Aimport java.awt.image.BufferedImage;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0A%0A/**%0A *%0A */%0Apublic class BarcodeImageDetector %7B%0A  %0A  /** */%0A  public String detect(InputStream inputStream) throws PhotoDetectionException %7B%0A    %0A    BufferedImage bufferedImage;%0A    try %7B%0A      bufferedImage = ImageIO.read(inputStream);%0A    %7D catch (IOException e) %7B%0A      throw new PhotoDetectionException(%22Failed to convert InputStream to BufferedImage.%22, e);%0A    %7D%0A%0A    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(%0A        new BufferedImageLuminanceSource(bufferedImage)));%0A    %0A%0A    if (bitmap.getWidth() %3C bitmap.getHeight()) %7B%0A      if (bitmap.isRotateSupported()) %7B%0A        bitmap = bitmap.rotateCounterClockwise();%0A      %7D%0A    %7D%0A    return decode(bitmap).getText();%0A  %7D%0A  %0A  /** */%0A  private BarcodeInfo decode(BinaryBitmap bitmap) throws PhotoDetectionException %7B%0A    Reader reader = new MultiFormatReader();%0A    Result result;%0A    try %7B%0A      result = reader.decode(bitmap);%0A    %7D catch (NotFoundException e) %7B%0A      // No potential barcode is found.%0A      throw new PhotoDetectionException(%22No potential barcode found.%22, e);%0A    %7D catch (ChecksumException e) %7B%0A      // A potential barcode is found but does not pass its checksum.%0A      throw new PhotoDetectionException(%22Potential barcode does not pass its checksum.%22, e);%0A    %7D catch (FormatException e) %7B%0A      // A potential barcode is found but format is invalid.%0A      throw new PhotoDetectionException(%22Invalid format for potential barcode.%22, e);%0A    %7D%0A      %0A    return BarcodeInfo.create(result.getText(), result.getBarcodeFormat().toString());%0A  %7D%0A  %0A  /**%0A   * Nested class%0A   */%0A  @AutoValue%0A  public static abstract class BarcodeInfo %7B%0A%0A    public static BarcodeInfo create(String text, String format) %7B%0A      return new AutoValue_BarcodeImageDetector_BarcodeInfo(text, format);%0A    %7D%0A%0A    public abstract String getText();%0A    public abstract String getFormat();%0A  %7D%0A%7D%0A

Add BarcodeImageDetector class