下面列出了android.graphics.ImageFormat#PRIVATE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Add a surface to this OutputConfiguration.
*
* <p> This function can be called before or after {@link
* CameraDevice#createCaptureSessionByOutputConfigurations}. If it's called after,
* the application must finalize the capture session with
* {@link CameraCaptureSession#finalizeOutputConfigurations}. It is possible to call this method
* after the output configurations have been finalized only in cases of enabled surface sharing
* see {@link #enableSurfaceSharing}. The modified output configuration must be updated with
* {@link CameraCaptureSession#updateOutputConfiguration}.</p>
*
* <p> If the OutputConfiguration was constructed with a deferred surface by {@link
* OutputConfiguration#OutputConfiguration(Size, Class)}, the added surface must be obtained
* from {@link android.view.SurfaceView} by calling {@link android.view.SurfaceHolder#getSurface},
* or from {@link android.graphics.SurfaceTexture} via
* {@link android.view.Surface#Surface(android.graphics.SurfaceTexture)}).</p>
*
* <p> If the OutputConfiguration was constructed by other constructors, the added
* surface must be compatible with the existing surface. See {@link #enableSurfaceSharing} for
* details of compatible surfaces.</p>
*
* <p> If the OutputConfiguration already contains a Surface, {@link #enableSurfaceSharing} must
* be called before calling this function to add a new Surface.</p>
*
* @param surface The surface to be added.
* @throws IllegalArgumentException if the Surface is invalid, the Surface's
* dataspace/format doesn't match, or adding the Surface would exceed number of
* shared surfaces supported.
* @throws IllegalStateException if the Surface was already added to this OutputConfiguration,
* or if the OutputConfiguration is not shared and it already has a surface associated
* with it.
*/
public void addSurface(@NonNull Surface surface) {
checkNotNull(surface, "Surface must not be null");
if (mSurfaces.contains(surface)) {
throw new IllegalStateException("Surface is already added!");
}
if (mSurfaces.size() == 1 && !mIsShared) {
throw new IllegalStateException("Cannot have 2 surfaces for a non-sharing configuration");
}
if (mSurfaces.size() + 1 > MAX_SURFACES_COUNT) {
throw new IllegalArgumentException("Exceeds maximum number of surfaces");
}
// This will throw IAE is the surface was abandoned.
Size surfaceSize = SurfaceUtils.getSurfaceSize(surface);
if (!surfaceSize.equals(mConfiguredSize)) {
Log.w(TAG, "Added surface size " + surfaceSize +
" is different than pre-configured size " + mConfiguredSize +
", the pre-configured size will be used.");
}
if (mConfiguredFormat != SurfaceUtils.getSurfaceFormat(surface)) {
throw new IllegalArgumentException("The format of added surface format doesn't match");
}
// If the surface format is PRIVATE, do not enforce dataSpace because camera device may
// override it.
if (mConfiguredFormat != ImageFormat.PRIVATE &&
mConfiguredDataspace != SurfaceUtils.getSurfaceDataspace(surface)) {
throw new IllegalArgumentException("The dataspace of added surface doesn't match");
}
mSurfaces.add(surface);
}
/**
* Query the surface for its currently configured format
*/
public static int detectSurfaceType(Surface surface) throws BufferQueueAbandonedException {
checkNotNull(surface);
int surfaceType = nativeDetectSurfaceType(surface);
// TODO: remove this override since the default format should be
// ImageFormat.PRIVATE. b/9487482
if ((surfaceType >= LegacyMetadataMapper.HAL_PIXEL_FORMAT_RGBA_8888 &&
surfaceType <= LegacyMetadataMapper.HAL_PIXEL_FORMAT_BGRA_8888)) {
surfaceType = ImageFormat.PRIVATE;
}
return LegacyExceptionUtils.throwOnError(surfaceType);
}
/**
* A high speed output surface can only be preview or hardware encoder surface.
*
* @param surface The high speed output surface to be checked.
*/
private static void checkHighSpeedSurfaceFormat(Surface surface) {
int surfaceFormat = SurfaceUtils.getSurfaceFormat(surface);
if (surfaceFormat != ImageFormat.PRIVATE) {
throw new IllegalArgumentException("Surface format(" + surfaceFormat + ") is not"
+ " for preview or hardware video encoding!");
}
}
/**
* 対応する映像フォーマットをlogCatへ出力する
* @param params
*/
public static void dumpSupportedPictureFormats(@NonNull final Camera.Parameters params) {
final List<Integer> formats = params.getSupportedPictureFormats();
for (final int format: formats) {
switch (format) {
case ImageFormat.DEPTH16: Log.i(TAG, "supported: DEPTH16"); break;
case ImageFormat.DEPTH_POINT_CLOUD: Log.i(TAG, "supported: DEPTH_POINT_CLOUD"); break;
case ImageFormat.FLEX_RGBA_8888: Log.i(TAG, "supported: FLEX_RGBA_8888"); break;
case ImageFormat.FLEX_RGB_888: Log.i(TAG, "supported: FLEX_RGB_888"); break;
case ImageFormat.JPEG: Log.i(TAG, "supported: JPEG"); break;
case ImageFormat.NV16: Log.i(TAG, "supported: NV16"); break;
case ImageFormat.NV21: Log.i(TAG, "supported: NV21"); break;
case ImageFormat.PRIVATE: Log.i(TAG, "supported: PRIVATE"); break;
case ImageFormat.RAW10: Log.i(TAG, "supported: RAW10"); break;
case ImageFormat.RAW12: Log.i(TAG, "supported: RAW12"); break;
case ImageFormat.RAW_PRIVATE: Log.i(TAG, "supported: RAW_PRIVATE"); break;
case ImageFormat.RAW_SENSOR: Log.i(TAG, "supported: RAW_SENSOR"); break;
case ImageFormat.RGB_565: Log.i(TAG, "supported: RGB_565"); break;
case ImageFormat.UNKNOWN: Log.i(TAG, "supported: UNKNOWN"); break;
case ImageFormat.YUV_420_888: Log.i(TAG, "supported: YUV_420_888"); break;
case ImageFormat.YUV_422_888: Log.i(TAG, "supported: YUV_422_888"); break;
case ImageFormat.YUV_444_888: Log.i(TAG, "supported: YUV_444_888"); break;
case ImageFormat.YUY2: Log.i(TAG, "supported: YUY2"); break;
case ImageFormat.YV12: Log.i(TAG, "supported: YV12"); break;
default:
Log.i(TAG, String.format("supported: unknown, %08x", format));
break;
}
}
}
private String formatToString(int format) {
switch (format) {
case ImageFormat.YV12:
return "YV12";
case ImageFormat.YUV_420_888:
return "YUV_420_888";
case ImageFormat.NV21:
return "NV21";
case ImageFormat.NV16:
return "NV16";
case PixelFormat.RGB_565:
return "RGB_565";
case PixelFormat.RGBA_8888:
return "RGBA_8888";
case PixelFormat.RGBX_8888:
return "RGBX_8888";
case PixelFormat.RGB_888:
return "RGB_888";
case ImageFormat.JPEG:
return "JPEG";
case ImageFormat.YUY2:
return "YUY2";
case ImageFormat.Y8:
return "Y8";
case ImageFormat.Y16:
return "Y16";
case ImageFormat.RAW_SENSOR:
return "RAW_SENSOR";
case ImageFormat.RAW_PRIVATE:
return "RAW_PRIVATE";
case ImageFormat.RAW10:
return "RAW10";
case ImageFormat.DEPTH16:
return "DEPTH16";
case ImageFormat.DEPTH_POINT_CLOUD:
return "DEPTH_POINT_CLOUD";
case ImageFormat.RAW_DEPTH:
return "RAW_DEPTH";
case ImageFormat.PRIVATE:
return "PRIVATE";
default:
return "UNKNOWN";
}
}
private static String getFormat(int format) {
switch (format) {
case ImageFormat.DEPTH16:
return "DEPTH16";
case ImageFormat.DEPTH_POINT_CLOUD:
return "DEPTH_POINT_CLOUD";
case ImageFormat.FLEX_RGBA_8888:
return "FLEX_RGBA_8888";
case ImageFormat.FLEX_RGB_888:
return "FLEX_RGB_888";
case ImageFormat.JPEG:
return "JPEG";
case ImageFormat.NV16:
return "NV16";
case ImageFormat.NV21:
return "NV21";
case ImageFormat.PRIVATE:
return "PRIVATE";
case ImageFormat.RAW10:
return "RAW10";
case ImageFormat.RAW12:
return "RAW12";
case ImageFormat.RAW_PRIVATE:
return "RAW_PRIVATE";
case ImageFormat.RAW_SENSOR:
return "RAW_SENSOR";
case ImageFormat.RGB_565:
return "RGB_565";
case ImageFormat.YUV_420_888:
return "YUV_420_888";
case ImageFormat.YUV_422_888:
return "YUV_422_888";
case ImageFormat.YUV_444_888:
return "YUV_444_888";
case ImageFormat.YUY2:
return "YUY2";
case ImageFormat.YV12:
return "YV12";
default:
return UNKNOWN + "-" + format;
}
}