com.google.zxing.PlanarYUVLuminanceSource Java Examples

The following examples show how to use com.google.zxing.PlanarYUVLuminanceSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CameraManager.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data A preview frame.
 * @param width The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
  Rect rect = getFramingRectInPreview();
  if (rect == null) {
    return null;
  }
  
  //this if saves the app from crashing when switching orientation........
  //finally debugged the biggest problem ...yippee
  if (rect.left + rect.width() > width || rect.top + rect.height() > height)
  	return new PlanarYUVLuminanceSource(data, height, width, rect.left, rect.top,
              rect.width(), rect.height(), false);
  
  // Go ahead and assume it's YUV rather than die.
  return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                                      rect.width(), rect.height(), false);
}
 
Example #2
Source File: CameraManager.java    From reacteu-app with MIT License 6 votes vote down vote up
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
  byte[] rotatedData = new byte[data.length];
  int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;
  if (rotation == Configuration.ORIENTATION_PORTRAIT) {
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        rotatedData[x * height + height - y - 1] = data[x + y * width];
      }
    }
    int tmp = width;
    width = height;
    height = tmp;
  } else {
    rotatedData = null;
  }

  Rect rect = getFramingRectInPreview();
  if (rect == null) {
    return null;
  }
  // Go ahead and assume it's YUV rather than die.
  return new PlanarYUVLuminanceSource(rotation == Configuration.ORIENTATION_PORTRAIT ? rotatedData : data, width, height, rect.left, rect.top,
      rect.width(), rect.height(), false);
}
 
Example #3
Source File: AbsCodec.java    From StarBarcode with Apache License 2.0 6 votes vote down vote up
/**
 * 使用YUV解析bitmap
 *
 * @param data
 * @param width
 * @param height
 * @param hintTypeMap
 * @return
 */
private Result decodeFromYUV(int[] data, int width, int height, Map<DecodeHintType, ?> hintTypeMap) {
    Result result = null;
    byte[] yuv = convertRGBToYuv(data, new byte[width * height], width, height);
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(yuv, width, height, 0, 0, width, height, false);
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
    try {
        result = new MultiFormatReader().decode(binaryBitmap, hintTypeMap);
    } catch (NotFoundException e) {
        //使用GlobalHistogramBinarizer算法进行解析
        try {
            result = new MultiFormatReader().decode(new BinaryBitmap(new GlobalHistogramBinarizer(source)), hintTypeMap);
        } catch (NotFoundException e1) {
            e1.printStackTrace();
        }
    }
    return result;
}
 
Example #4
Source File: ScanActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
private void decode(final byte[] data) {
    final PlanarYUVLuminanceSource source = cameraManager.buildLuminanceSource(data);
    final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    try {
        hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, (ResultPointCallback) dot -> runOnUiThread(() -> scannerView.addDot(dot)));
        final Result scanResult = reader.decode(bitmap, hints);

        runOnUiThread(() -> handleResult(scanResult));
    } catch (final ReaderException x) {
        // retry
        cameraHandler.post(fetchAndDecodeRunnable);
    } finally {
        reader.reset();
    }
}
 
Example #5
Source File: DecodeTask.java    From code-scanner with MIT License 6 votes vote down vote up
@Nullable
@SuppressWarnings("SuspiciousNameCombination")
public Result decode(@NonNull final MultiFormatReader reader) throws ReaderException {
    int imageWidth = mImageSize.getX();
    int imageHeight = mImageSize.getY();
    final int orientation = mOrientation;
    final byte[] image = Utils.rotateYuv(mImage, imageWidth, imageHeight, orientation);
    if (orientation == 90 || orientation == 270) {
        final int width = imageWidth;
        imageWidth = imageHeight;
        imageHeight = width;
    }
    final Rect frameRect =
            Utils.getImageFrameRect(imageWidth, imageHeight, mViewFrameRect, mPreviewSize,
                    mViewSize);
    final int frameWidth = frameRect.getWidth();
    final int frameHeight = frameRect.getHeight();
    if (frameWidth < 1 || frameHeight < 1) {
        return null;
    }
    return Utils.decodeLuminanceSource(reader,
            new PlanarYUVLuminanceSource(image, imageWidth, imageHeight, frameRect.getLeft(),
                    frameRect.getTop(), frameWidth, frameHeight, mReverseHorizontal));
}
 
Example #6
Source File: CameraManager.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data A preview frame.
 * @param width The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
  byte[] rotatedData = new byte[data.length];
  int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;
  if (rotation == Configuration.ORIENTATION_PORTRAIT) {
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        rotatedData[x * height + height - y - 1] = data[x + y * width];
      }
    }
    int tmp = width;
    //noinspection SuspiciousNameCombination
    width = height;
    height = tmp;
  } else {
    rotatedData = null;
  }

  Rect rect = getFramingRectInPreview();
  if (rect == null) {
    return null;
  }
  // Go ahead and assume it's YUV rather than die.
  return new PlanarYUVLuminanceSource(rotation == Configuration.ORIENTATION_PORTRAIT ? rotatedData : data, width, height, rect.left, rect.top,
      rect.width(), rect.height(), false);
}
 
Example #7
Source File: CameraManager.java    From ZxingSupport with Apache License 2.0 6 votes vote down vote up
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] rotatedData, int width, int height, boolean horizontal) {
    Rect rect = getFramingRectInPreview(horizontal);
    int previewFormat = mCameraConfig.getPreviewFormat();
    String previewFormatString = mCameraConfig.getPreviewFormatString();
    switch (previewFormat) {
        // This is the standard Android format which all devices are REQUIRED to support.
        // In theory, it's the only one we should ever care about.
        case PixelFormat.YCbCr_420_SP:
            // This format has never been seen in the wild, but is compatible as we only care
            // about the Y channel, so allow it.
        case PixelFormat.YCbCr_422_SP:
            return new PlanarYUVLuminanceSource(rotatedData, width, height, rect.left, rect.top,
                    rect.width(), rect.height(), horizontal);
        default:
            // The Samsung Moment incorrectly uses this variant instead of the 'sp' version.
            // Fortunately, it too has all the Y data up front, so we can read it.
            if ("yuv420p".equals(previewFormatString)) {
                return new PlanarYUVLuminanceSource(rotatedData, width, height, rect.left, rect.top,
                        rect.width(), rect.height(), horizontal);
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);

}
 
Example #8
Source File: CameraManager.java    From zxing with MIT License 6 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on
 * the format of the preview buffers, as described by Camera.Parameters.
 *
 * @param data   A preview frame.
 * @param width  The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data,
                                                     int width, int height) {
    Rect rect = getFramingRectInPreview();
    if (rect == null) {
        return null;
    }
    // Go ahead and assume it's YUV rather than die.


    if (config == null) {
        config = new ZxingConfig();
    }

    if (config.isFullScreenScan()) {
        return new PlanarYUVLuminanceSource(data, width, height, 0,
                0, width, height, false);
    } else {
        int actionbarHeight = context.getResources().getDimensionPixelSize(R.dimen.toolBarHeight);
        return new PlanarYUVLuminanceSource(data, width, height, rect.left,
                rect.top + actionbarHeight, rect.width(), rect.height(), false);
    }


}
 
Example #9
Source File: BarcodeUtils.java    From code-scanner with MIT License 6 votes vote down vote up
/**
 * Decode barcode from YUV pixels array
 *
 * @param pixels            YUV image data
 * @param width             Image width
 * @param height            Image height
 * @param rotation          Degrees to rotate image before decoding (only 0, 90, 180 or 270 are allowed)
 * @param reverseHorizontal Reverse image horizontally before decoding
 * @param hints             Decoder hints
 * @return Decode result, if barcode was decoded successfully, {@code null} otherwise
 * @see DecodeHintType
 */
@Nullable
@SuppressWarnings("SuspiciousNameCombination")
public static Result decodeYuv(@NonNull final byte[] pixels, final int width, final int height,
        @Rotation final int rotation, final boolean reverseHorizontal,
        @Nullable final Map<DecodeHintType, ?> hints) {
    Objects.requireNonNull(pixels);
    final byte[] rotatedPixels = Utils.rotateYuv(pixels, width, height, rotation);
    final int rotatedWidth;
    final int rotatedHeight;
    if (rotation == ROTATION_90 || rotation == ROTATION_270) {
        rotatedWidth = height;
        rotatedHeight = width;
    } else {
        rotatedWidth = width;
        rotatedHeight = height;
    }
    final MultiFormatReader reader = createReader(hints);
    try {
        return Utils.decodeLuminanceSource(reader,
                new PlanarYUVLuminanceSource(rotatedPixels, rotatedWidth, rotatedHeight, 0, 0,
                        rotatedWidth, rotatedHeight, reverseHorizontal));
    } catch (final ReaderException e) {
        return null;
    }
}
 
Example #10
Source File: QrUtils.java    From Mobike with Apache License 2.0 6 votes vote down vote up
public static Result decodeImage(final String path) {
        Bitmap bitmap = QrUtils.decodeSampledBitmapFromFile(path, 256, 256);
        // Google Photo 相册中选取云照片是会出现 Bitmap == null
        if (bitmap == null) return null;
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
//                RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        PlanarYUVLuminanceSource source1 = new PlanarYUVLuminanceSource(getYUV420sp(width, height, bitmap), width, height, 0, 0, width, height, false);
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source1));
//                BinaryBitmap binaryBitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source1));
        HashMap<DecodeHintType, Object> hints = new HashMap<>();

        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");

        try {
            return new MultiFormatReader().decode(binaryBitmap, hints);
        } catch (NotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
 
Example #11
Source File: DecodeUtils.java    From SimplifyReader with Apache License 2.0 6 votes vote down vote up
public String decodeWithZxing(byte[] data, int width, int height, Rect crop) {
    MultiFormatReader multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(changeZXingDecodeDataMode());

    Result rawResult = null;
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height,
            crop.left, crop.top, crop.width(), crop.height(), false);

    if (source != null) {
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(bitmap);
        } catch (ReaderException re) {
            // continue
        } finally {
            multiFormatReader.reset();
        }
    }

    return rawResult != null ? rawResult.getText() : null;
}
 
Example #12
Source File: QRCodeCameraDecode.java    From ZxingSupport with Apache License 2.0 5 votes vote down vote up
/**
     * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency,
     * reuse the same reader objects from one decode to the next.
     *
     * @param data   The YUV preview frame.
     */
    public CameraDecodeResult decode(byte[] data,boolean horizontal) {
        int width = mCameraManger.getCameraConfig().getCameraResolution().x;
        int height = mCameraManger.getCameraConfig().getCameraResolution().y;
        Result rawResult = null;

        if (!horizontal){
            // 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据
            byte[] rotatedData = new byte[data.length];
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++)
                    rotatedData[x * height + height - y - 1] = data[x + y * width];
            }
            int tmp = width; // Here we are swapping, that's the difference to #11
            width = height;
            height = tmp;
            data= rotatedData;
        }


        PlanarYUVLuminanceSource source = mCameraManger.buildLuminanceSource(data, width, height,horizontal);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(bitmap);
        } catch (ReaderException re) {
            // continue
        } finally {
            multiFormatReader.reset();
        }
        Log.e(TAG, "decode:" + rawResult);
        CameraDecodeResult cameraDecodeResult = new CameraDecodeResult();
        cameraDecodeResult.setDecodeResult(rawResult);

        if (rawResult != null){
            // TODO: 2016/11/5
//            cameraDecodeResult.setDecodeByte(bundleThumbnail(source));
        }
        cameraDecodeResult.setDecodeByte(bundleThumbnail(source));
        return cameraDecodeResult;
    }
 
Example #13
Source File: DecodeHandler.java    From weex with Apache License 2.0 5 votes vote down vote up
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
  int[] pixels = source.renderThumbnail();
  int width = source.getThumbnailWidth();
  int height = source.getThumbnailHeight();
  Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
  ByteArrayOutputStream out = new ByteArrayOutputStream();    
  bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
  bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
  bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
}
 
Example #14
Source File: QRCodeCameraDecode.java    From ZxingSupport with Apache License 2.0 5 votes vote down vote up
private static byte[] bundleThumbnail(PlanarYUVLuminanceSource source) {
    int[] pixels = source.renderThumbnail();
    int width = source.getThumbnailWidth();
    int height = source.getThumbnailHeight();
    Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
    return  out.toByteArray();
}
 
Example #15
Source File: DecodeHandler.java    From Gizwits-SmartBuld_Android with MIT License 5 votes vote down vote up
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
	int[] pixels = source.renderThumbnail();
	int width = source.getThumbnailWidth();
	int height = source.getThumbnailHeight();
	Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
	bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
}
 
Example #16
Source File: ScannerManager.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
private String decode(byte[] data, int width, int height) {
    ScannerManager manager = mManager.get();
    if (manager == null) {
        return null;
    }
    Rect rect = manager.getFramingRectInPreview();
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data,
            width, height, rect.left, rect.top, rect.right, rect.bottom, false);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    try {
        Result result = reader.decode(bitmap, mHints);
        return result.getText();
    } catch (ReaderException e) {
        // Ignore as we will repeatedly decode the preview frame
        return null;
    }
}
 
Example #17
Source File: DecodeHandler.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
  int[] pixels = source.renderThumbnail();
  int width = source.getThumbnailWidth();
  int height = source.getThumbnailHeight();
  Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
  ByteArrayOutputStream out = new ByteArrayOutputStream();    
  bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
  bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
  bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
}
 
Example #18
Source File: DecodeHandler.java    From Gizwits-SmartSocket_Android with MIT License 5 votes vote down vote up
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
	int[] pixels = source.renderThumbnail();
	int width = source.getThumbnailWidth();
	int height = source.getThumbnailHeight();
	Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
	bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
}
 
Example #19
Source File: CameraManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data   A preview frame.
 * @param width  The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = getFramingRectInPreview();
    if (rect == null) {
        return null;
    }
    // Go ahead and assume it's YUV rather than die.
    return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
            rect.width(), rect.height(), false);
}
 
Example #20
Source File: DecodeHandler.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
/**
 * create thumbnail
 *
 * @param source
 * @param bundle
 */

private void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
    int[] pixels = source.renderThumbnail();
    int width = source.getThumbnailWidth();
    int height = source.getThumbnailHeight();
    Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
    bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
}
 
Example #21
Source File: CameraManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data A preview frame.
 * @param width The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
  Rect rect = getFramingRectInPreview();
  if (rect == null) {
    return null;
  }
  // Go ahead and assume it's YUV rather than die.
  return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                                      rect.width(), rect.height(), false);
}
 
Example #22
Source File: DecodeHandler.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
	int[] pixels = source.renderThumbnail();
	int width = source.getThumbnailWidth();
	int height = source.getThumbnailHeight();
	Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
	bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
}
 
Example #23
Source File: DecodeUtil.java    From react-native-smart-barcode with MIT License 5 votes vote down vote up
public static String getStringFromQRCode(String path) {
        String httpString = null;

        Bitmap bmp = convertToBitmap(path);
        byte[] data = getYUV420sp(bmp.getWidth(), bmp.getHeight(), bmp);
        // 处理
        try {
            Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
//            hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
            hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
            hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
            PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data,
                    bmp.getWidth(),
                    bmp.getHeight(),
                    0, 0,
                    bmp.getWidth(),
                    bmp.getHeight(),
                    false);
            BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
            QRCodeReader reader2= new QRCodeReader();
            Result result = reader2.decode(bitmap1, hints);

            httpString = result.getText();
        } catch (Exception e) {
            e.printStackTrace();
        }

        bmp.recycle();
        bmp = null;

        return httpString;
    }
 
Example #24
Source File: CameraManager.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data   A preview frame.
 * @param width  The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = getFramingRectInPreview();
    if (rect == null) {
        return null;
    }
    // Go ahead and assume it's YUV rather than die.
    return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
            rect.width(), rect.height(), false);
}
 
Example #25
Source File: CameraManager.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data A preview frame.
 * @param width The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
  Rect rect = getFramingRectInPreview();
  if (rect == null) {
    return null;
  }
  // Go ahead and assume it's YUV rather than die.
  return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                                      rect.width(), rect.height(), false);
}
 
Example #26
Source File: SourceData.java    From Viewer with Apache License 2.0 5 votes vote down vote up
public PlanarYUVLuminanceSource createSource() {
    byte[] rotated = rotateCameraPreview(rotation, data, dataWidth, dataHeight);
    // TODO: handle mirrored (front) camera. Probably only the ResultPoints should be mirrored,
    // not the preview for decoding.
    if (isRotated()) {
        //noinspection SuspiciousNameCombination
        return new PlanarYUVLuminanceSource(rotated, dataHeight, dataWidth, cropRect.left, cropRect.top, cropRect.width(), cropRect.height(), false);
    } else {
        return new PlanarYUVLuminanceSource(rotated, dataWidth, dataHeight, cropRect.left, cropRect.top, cropRect.width(), cropRect.height(), false);
    }
}
 
Example #27
Source File: DecodeHandler.java    From myapplication with Apache License 2.0 5 votes vote down vote up
/**
 * A factory method to build the appropriate LuminanceSource object based on
 * the format of the preview buffers, as described by Camera.Parameters.
 *
 * @param data   A preview frame.
 * @param width  The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = activity.getCropRect();
    if (rect == null) {
        return null;
    }
    // Go ahead and assume it's YUV rather than die.
    return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect
            .height(), false);
}
 
Example #28
Source File: DecodeHandler.java    From myapplication with Apache License 2.0 5 votes vote down vote up
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
    int[] pixels = source.renderThumbnail();
    int width = source.getThumbnailWidth();
    int height = source.getThumbnailHeight();
    Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
    bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
}
 
Example #29
Source File: DecodeHandler.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
  int[] pixels = source.renderThumbnail();
  int width = source.getThumbnailWidth();
  int height = source.getThumbnailHeight();
  Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
  ByteArrayOutputStream out = new ByteArrayOutputStream();    
  bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
  bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
  bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
}
 
Example #30
Source File: DecodeHandler.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
  int[] pixels = source.renderThumbnail();
  int width = source.getThumbnailWidth();
  int height = source.getThumbnailHeight();
  Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
  ByteArrayOutputStream out = new ByteArrayOutputStream();    
  bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
  bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
  bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
}