package com.journeyapps.barcodescanner;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.ResultPointCallback;
import com.google.zxing.common.HybridBinarizer;

import java.util.ArrayList;
import java.util.List;

/**
 * A class for decoding images.
 *
 * A decoder contains all the configuration required for the binarization and decoding process.
 *
 * The actual decoding should happen on a dedicated thread.
 */
public class Decoder implements ResultPointCallback {
    private Reader reader;

    /**
     * Create a new Decoder with the specified Reader.
     *
     * It is recommended to use an instance of MultiFormatReader in most cases.
     *
     * @param reader the reader
     */
    public Decoder(Reader reader) {
        this.reader = reader;
    }

    protected Reader getReader() {
        return reader;
    }

    /**
     * Given an image source, attempt to decode the barcode.
     *
     * Must not raise an exception.
     *
     * @param source the image source
     * @return a Result or null
     */
    public Result decode(LuminanceSource source) {
        return decode(toBitmap(source));
    }

    /**
     * Given an image source, convert to a binary bitmap.
     *
     * Override this to use a custom binarizer.
     *
     * @param source the image source
     * @return a BinaryBitmap
     */
    protected BinaryBitmap toBitmap(LuminanceSource source) {
        return new BinaryBitmap(new HybridBinarizer(source));
    }

    /**
     * Decode a binary bitmap.
     *
     * @param bitmap the binary bitmap
     * @return a Result or null
     */
    protected Result decode(BinaryBitmap bitmap) {
        possibleResultPoints.clear();
        try {
            if (reader instanceof MultiFormatReader) {
                // Optimization - MultiFormatReader's normal decode() method is slow.
                return ((MultiFormatReader) reader).decodeWithState(bitmap);
            } else {
                return reader.decode(bitmap);
            }
        } catch (Exception e) {
            // Decode error, try again next frame
            return null;
        } finally {
            reader.reset();
        }
    }

    private List<ResultPoint> possibleResultPoints = new ArrayList<>();

    /**
     * Call immediately after decode(), from the same thread.
     *
     * The result is undefined while decode() is running.
     *
     * @return possible ResultPoints from the last decode.
     */
    public List<ResultPoint> getPossibleResultPoints() {
        return new ArrayList<>(possibleResultPoints);
    }

    @Override
    public void foundPossibleResultPoint(ResultPoint point) {
        possibleResultPoints.add(point);
    }
}

@@ -59,27 +59,106 @@
 .zxing.B
-inaryBitmap
+arcodeFormat;%0Aimport com.google.zxing.BinaryBitmap;%0Aimport com.google.zxing.DecodeHintType
 ;%0Aimport
@@ -433,58 +433,165 @@
 er;%0A
-%0Aimport java.util.ArrayList;%0Aimport java.util.List
+import com.journeyapps.barcodescanner.camera.TOCodeReader;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0A/
@@ -2079,16 +2079,262 @@
         
+Result have = null;%0A%0A            if (true) %7B%0A                Map%3CDecodeHintType, Object%3E hints = new HashMap%3CDecodeHintType, Object%3E();;%0A                have = new TOCodeReader().decode(bitmap,%0A                        hints);%0A%0A            %7D else 
 if (read
@@ -2470,22 +2470,22 @@
         
-return
+have =
  ((Multi
@@ -2564,30 +2564,30 @@
             
-return
+have =
  reader.deco
@@ -2590,32 +2590,33 @@
 decode(bitmap);%0A
+%0A
             %7D%0A  
@@ -2609,24 +2609,312 @@
           %7D%0A
+            if (have == null)%7B%0A%0A%0A                ResultPoint l = new ResultPoint(196,104);%0A                ResultPoint r = new ResultPoint(196,104);%0A%0A                have = new Result(%22hi%22,null, new ResultPoint%5B%5D%7Bl,r%7D, BarcodeFormat.UPC_E,56135);%0A            %7D%0A%0A            return have;%0A%0A
         %7D ca

Bump to v002 open source release