Search in sources :

Example 1 with InvalidVersionException

use of jp.sourceforge.qrcode.exception.InvalidVersionException in project qrcode by yanbe.

the class QRCodeImageReader method getQRCodeSymbol.

public QRCodeSymbol getQRCodeSymbol(int[][] image) throws SymbolNotFoundException {
    int longSide = (image.length < image[0].length) ? image[0].length : image.length;
    QRCodeImageReader.DECIMAL_POINT = 23 - QRCodeUtility.sqrt(longSide / 256);
    bitmap = filterImage(image);
    canvas.println("Drawing matrix.");
    canvas.drawMatrix(bitmap);
    canvas.println("Scanning Finder Pattern.");
    FinderPattern finderPattern = null;
    try {
        finderPattern = FinderPattern.findFinderPattern(bitmap);
    } catch (FinderPatternNotFoundException e) {
        canvas.println("Not found, now retrying...");
        bitmap = applyCrossMaskingMedianFilter(bitmap, 5);
        canvas.drawMatrix(bitmap);
        try {
            finderPattern = FinderPattern.findFinderPattern(bitmap);
        } catch (FinderPatternNotFoundException e2) {
            throw new SymbolNotFoundException(e2.getMessage());
        } catch (VersionInformationException e2) {
            throw new SymbolNotFoundException(e2.getMessage());
        }
    } catch (VersionInformationException e) {
        throw new SymbolNotFoundException(e.getMessage());
    }
    canvas.println("FinderPattern at");
    String finderPatternCoordinates = finderPattern.getCenter(FinderPattern.UL).toString() + finderPattern.getCenter(FinderPattern.UR).toString() + finderPattern.getCenter(FinderPattern.DL).toString();
    canvas.println(finderPatternCoordinates);
    int[] sincos = finderPattern.getAngle();
    canvas.println("Angle*4098: Sin " + Integer.toString(sincos[0]) + "  " + "Cos " + Integer.toString(sincos[1]));
    int version = finderPattern.getVersion();
    canvas.println("Version: " + Integer.toString(version));
    if (version < 1 || version > 40)
        throw new InvalidVersionException("Invalid version: " + version);
    AlignmentPattern alignmentPattern = null;
    try {
        alignmentPattern = AlignmentPattern.findAlignmentPattern(bitmap, finderPattern);
    } catch (AlignmentPatternNotFoundException e) {
        throw new SymbolNotFoundException(e.getMessage());
    }
    int matrixLength = alignmentPattern.getCenter().length;
    canvas.println("AlignmentPatterns at");
    for (int y = 0; y < matrixLength; y++) {
        String alignmentPatternCoordinates = "";
        for (int x = 0; x < matrixLength; x++) {
            alignmentPatternCoordinates += alignmentPattern.getCenter()[x][y].toString();
        }
        canvas.println(alignmentPatternCoordinates);
    }
    //for(int i = 0; i < 500000; i++) System.out.println("");
    canvas.println("Creating sampling grid.");
    //[TODO] need all-purpose method
    //samplingGrid = getSamplingGrid2_6(finderPattern, alignmentPattern);
    samplingGrid = getSamplingGrid(finderPattern, alignmentPattern);
    canvas.println("Reading grid.");
    boolean[][] qRCodeMatrix = null;
    try {
        qRCodeMatrix = getQRCodeMatrix(bitmap, samplingGrid);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new SymbolNotFoundException("Sampling grid exceeded image boundary");
    }
    //canvas.drawMatrix(qRCodeMatrix);
    return new QRCodeSymbol(qRCodeMatrix);
}
Also used : VersionInformationException(jp.sourceforge.qrcode.exception.VersionInformationException) InvalidVersionException(jp.sourceforge.qrcode.exception.InvalidVersionException) FinderPatternNotFoundException(jp.sourceforge.qrcode.exception.FinderPatternNotFoundException) AlignmentPatternNotFoundException(jp.sourceforge.qrcode.exception.AlignmentPatternNotFoundException) SymbolNotFoundException(jp.sourceforge.qrcode.exception.SymbolNotFoundException)

Aggregations

AlignmentPatternNotFoundException (jp.sourceforge.qrcode.exception.AlignmentPatternNotFoundException)1 FinderPatternNotFoundException (jp.sourceforge.qrcode.exception.FinderPatternNotFoundException)1 InvalidVersionException (jp.sourceforge.qrcode.exception.InvalidVersionException)1 SymbolNotFoundException (jp.sourceforge.qrcode.exception.SymbolNotFoundException)1 VersionInformationException (jp.sourceforge.qrcode.exception.VersionInformationException)1