Android Open Source - qrcode-android R G B Luminance Source






From Project

Back to project page qrcode-android.

License

The source code is released under:

MIT License

If you think the Android project qrcode-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.google.zxing.extra;
//from www  .  j  a  va  2s .co m
/**
 * Created by IntelliJ IDEA.
 * User: dlivotov
 * Date: 27.10.11
 * Time: 5:26
 * To change this template use File | Settings | File Templates.
 */

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.google.zxing.LuminanceSource;

import java.io.FileNotFoundException;

/**
 * This class is used to help decode images from files which arrive as RGB data from
 * Android bitmaps. It does not support cropping or rotation.
 *
 * @author dswitkin@google.com (Daniel Switkin)
 */
public final class RGBLuminanceSource extends LuminanceSource
{

    private final byte[] luminances;

    public RGBLuminanceSource(String path) throws FileNotFoundException
    {
        this(loadBitmap(path));
    }

    public RGBLuminanceSource(Bitmap bitmap)
    {
        super(bitmap.getWidth(), bitmap.getHeight());

        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

        // In order to measure pure decoding speed, we convert the entire image to a greyscale array
        // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
        luminances = new byte[width * height];
        for (int y = 0; y < height; y++)
        {
            int offset = y * width;
            for (int x = 0; x < width; x++)
            {
                int pixel = pixels[offset + x];
                int r = (pixel >> 16) & 0xff;
                int g = (pixel >> 8) & 0xff;
                int b = pixel & 0xff;
                if (r == g && g == b)
                {
                    // Image is already greyscale, so pick any channel.
                    luminances[offset + x] = (byte) r;
                } else
                {
                    // Calculate luminance cheaply, favoring green.
                    luminances[offset + x] = (byte) ((r + g + g + b) >> 2);
                }
            }
        }
    }

    public byte[] getRow(int y, byte[] row)
    {
        if (y < 0 || y >= getHeight())
        {
            throw new IllegalArgumentException("Requested row is outside the image: " + y);
        }
        int width = getWidth();
        if (row == null || row.length < width)
        {
            row = new byte[width];
        }

        System.arraycopy(luminances, y * width, row, 0, width);
        return row;
    }

    // Since this class does not support cropping, the underlying byte array already contains
    // exactly what the caller is asking for, so give it to them without a copy.
    public byte[] getMatrix()
    {
        return luminances;
    }

    private static Bitmap loadBitmap(String path) throws FileNotFoundException
    {
        Bitmap bitmap = BitmapFactory.decodeFile(path);
        if (bitmap == null)
        {
            throw new FileNotFoundException("Couldn't open " + path);
        }
        return bitmap;
    }

}




Java Source Code List

com.google.zxing.client.android.BeepManager.java
com.google.zxing.client.android.CaptureActivityHandler.java
com.google.zxing.client.android.CaptureActivity.java
com.google.zxing.client.android.Contents.java
com.google.zxing.client.android.DecodeFormatManager.java
com.google.zxing.client.android.DecodeHandler.java
com.google.zxing.client.android.DecodeHintManager.java
com.google.zxing.client.android.DecodeThread.java
com.google.zxing.client.android.FinishListener.java
com.google.zxing.client.android.InactivityTimer.java
com.google.zxing.client.android.IntentSource.java
com.google.zxing.client.android.Intents.java
com.google.zxing.client.android.LocaleManager.java
com.google.zxing.client.android.ViewfinderResultPointCallback.java
com.google.zxing.client.android.ViewfinderView.java
com.google.zxing.client.android.camera.AutoFocusManager.java
com.google.zxing.client.android.camera.CameraConfigurationManager.java
com.google.zxing.client.android.camera.CameraManager.java
com.google.zxing.client.android.camera.FrontLightMode.java
com.google.zxing.client.android.camera.PreviewCallback.java
com.google.zxing.client.android.camera.exposure.DefaultExposureInterface.java
com.google.zxing.client.android.camera.exposure.ExposureInterface.java
com.google.zxing.client.android.camera.exposure.ExposureManager.java
com.google.zxing.client.android.camera.exposure.FroyoExposureInterface.java
com.google.zxing.client.android.camera.open.DefaultOpenCameraInterface.java
com.google.zxing.client.android.camera.open.GingerbreadOpenCameraInterface.java
com.google.zxing.client.android.camera.open.OpenCameraInterface.java
com.google.zxing.client.android.camera.open.OpenCameraManager.java
com.google.zxing.client.android.common.PlatformSupportManager.java
com.google.zxing.client.android.common.executor.AsyncTaskExecInterface.java
com.google.zxing.client.android.common.executor.AsyncTaskExecManager.java
com.google.zxing.client.android.common.executor.DefaultAsyncTaskExecInterface.java
com.google.zxing.client.android.common.executor.HoneycombAsyncTaskExecInterface.java
com.google.zxing.extra.RGBLuminanceSource.java
eu.livotov.zxscan.AutofocusMode.java
eu.livotov.zxscan.ZXScanHelper.java
eu.livotov.zxscan.ZXUserCallback.java
tw.soleil.constant.Constants.java
tw.soleil.qrcodereadertest.QRCodeReaderTestActivity.java
tw.soleil.service.InvoiceService.java
tw.soleil.to.InvoiceDtl.java
tw.soleil.to.Invoice.java
tw.soleil.util.DateUtil.java
tw.soleil.util.Utils.java