YCbCr_422_SP ( )源码实例Demo

android.graphics.PixelFormat#YCbCr_422_SP ( )源码实例Demo

下面列出了android.graphics.PixelFormat#YCbCr_422_SP ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: QrCodeLib   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, 0, 0, width, height);
        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(data, width, height, 0, 0, width, height);
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码2 项目: vmqApk   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, 0, 0, width, height);
        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(data, width, height, 0, 0, width, height);
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码3 项目: DoraemonKit   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        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(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码4 项目: QrCodeDemo4   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, 0, 0, width, height);
        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(data, width, height, 0, 0, width, height);
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码5 项目: RxTools-master   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        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(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码6 项目: Mobike   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        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(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码7 项目: smart-farmer-android   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        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(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码8 项目: vinci   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        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(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码9 项目: mobile-manager-tool   文件: CameraManager.java
/**
 * 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();
  int previewFormat = configManager.getPreviewFormat();
  String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
          rect.width(), rect.height());
    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(data, width, height, rect.left, rect.top,
          rect.width(), rect.height());
      }
  }
  throw new IllegalArgumentException("Unsupported picture format: " +
      previewFormat + '/' + previewFormatString);
}
 
源代码10 项目: MaterialHome   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        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(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码11 项目: QrScan   文件: CameraManager.java
/**
 * 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();
  int previewFormat = configManager.getPreviewFormat();
  String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
          rect.width(), rect.height());
    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(data, width, height, rect.left, rect.top,
          rect.width(), rect.height());
      }
  }
  throw new IllegalArgumentException("Unsupported picture format: " +
      previewFormat + '/' + previewFormatString);
}
 
源代码12 项目: lunzi   文件: CameraManager.java
/**
 * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        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(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
 
源代码13 项目: KSYMediaPlayer_Android   文件: CameraManager.java
/**
 * 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();
  int previewFormat = configManager.getPreviewFormat();
  String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
          rect.width(), rect.height());
    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(data, width, height, rect.left, rect.top,
          rect.width(), rect.height());
      }
  }
  throw new IllegalArgumentException("Unsupported picture format: " +
      previewFormat + '/' + previewFormatString);
}
 
源代码14 项目: KSYMediaPlayer_Android   文件: CameraManager.java
/**
 * 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();
  int previewFormat = configManager.getPreviewFormat();
  String previewFormatString = configManager.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(data, width, height, rect.left, rect.top,
          rect.width(), rect.height());
    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(data, width, height, rect.left, rect.top,
          rect.width(), rect.height());
      }
  }
  throw new IllegalArgumentException("Unsupported picture format: " +
      previewFormat + '/' + previewFormatString);
}
 
源代码15 项目: ZxingSupport   文件: CameraManager.java
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);

}
 
源代码16 项目: o2oa   文件: CameraManager.java
/**
	 * 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();
		int previewFormat = configManager.getPreviewFormat();
		String previewFormatString = configManager.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(data, width, height, rect.left,
//					rect.top, rect.width(), rect.height());
			//fancyLou 使用全屏扫码 不仅仅是方框内的图像 ,这样用户错觉上看起来扫秒效率会高了
			return new PlanarYUVLuminanceSource(data, width, height, 0,
					0, width, height);
		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(data, width, height,
//						rect.left, rect.top, rect.width(), rect.height());
				return new PlanarYUVLuminanceSource(data, width, height, 0,
						0, width, height);
			}
		}
		throw new IllegalArgumentException("Unsupported picture format: "
				+ previewFormat + '/' + previewFormatString);
	}
 
源代码17 项目: react-native-smart-barcode   文件: CameraManager.java
/**
   * 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();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.getPreviewFormatString();


//    Log.i("Test","PlanarYUVLuminanceSource_width:"+width+",height:"+height+",Rect_left:"+rect.left+"Rect_top:"+rect.top+
//            "Rect_width:"+rect.width()+ "Rect_height:"+rect.height()
//    );

    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(data, width, height, rect.left, rect.top,
            rect.width(), rect.height());
      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(data, width, height, rect.left, rect.top,
            rect.width(), rect.height());
        }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
        previewFormat + '/' + previewFormatString);
  }
 
源代码18 项目: iscanner_android   文件: CameraManager.java
/**
 * 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();
	int previewFormat = configManager.getPreviewFormat();
	String previewFormatString = configManager.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(data, width, height, rect.left,
				rect.top, rect.width(), rect.height());
	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(data, width, height,
					rect.left, rect.top, rect.width(), rect.height());
		}
	}
	throw new IllegalArgumentException("Unsupported picture format: "
			+ previewFormat + '/' + previewFormatString);
}