public final class

ImageCaptureConfig

extends java.lang.Object

implements UseCaseConfig<ImageCapture>, ImageOutputConfig, IoConfig

 java.lang.Object

↳androidx.camera.core.impl.ImageCaptureConfig

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-core', version: '1.5.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-core
  • version: 1.5.0-alpha01

Artifact androidx.camera:camera-core:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Configuration for an image capture use case.

Summary

Fields
public static final Config.Option<java.lang.Integer>OPTION_BUFFER_FORMAT

public static final Config.Option<CaptureBundle>OPTION_CAPTURE_BUNDLE

public static final Config.Option<java.lang.Integer>OPTION_FLASH_MODE

public static final Config.Option<java.lang.Integer>OPTION_FLASH_TYPE

public static final Config.Option<java.lang.Integer>OPTION_IMAGE_CAPTURE_MODE

public static final Config.Option<ImageReaderProxyProvider>OPTION_IMAGE_READER_PROXY_PROVIDER

public static final Config.Option<java.lang.Integer>OPTION_JPEG_COMPRESSION_QUALITY

public static final Config.Option<java.lang.Integer>OPTION_MAX_CAPTURE_STAGES

public static final Config.Option<java.lang.Integer>OPTION_OUTPUT_FORMAT

public static final Config.Option<java.lang.Boolean>OPTION_POSTVIEW_ENABLED

public static final Config.Option<ResolutionSelector>OPTION_POSTVIEW_RESOLUTION_SELECTOR

public static final Config.Option<ImageCapture.ScreenFlash>OPTION_SCREEN_FLASH

public static final Config.Option<java.lang.Boolean>OPTION_USE_SOFTWARE_JPEG_ENCODER

Constructors
publicImageCaptureConfig(OptionsBundle config)

Creates a new configuration instance.

Methods
public java.lang.IntegergetBufferFormat()

Returns the of the capture in memory.

public java.lang.IntegergetBufferFormat(java.lang.Integer valueIfMissing)

Returns the of the capture in memory.

public CaptureBundlegetCaptureBundle()

Returns the CaptureBundle.

public CaptureBundlegetCaptureBundle(CaptureBundle valueIfMissing)

Returns the CaptureBundle.

public intgetCaptureMode()

Returns the ImageCapture.CaptureMode.

public ConfiggetConfig()

public intgetFlashMode()

Returns the .

public intgetFlashMode(int valueIfMissing)

Returns the .

public intgetFlashType()

Returns the .

public intgetFlashType(int valueIfMissing)

Returns the .

public ImageReaderProxyProvidergetImageReaderProxyProvider()

Gets the caller provided ImageReaderProxy.

public intgetInputFormat()

Retrieves the format of the image that is fed as input.

public java.util.concurrent.ExecutorgetIoExecutor()

Returns the executor that will be used for IO tasks.

public java.util.concurrent.ExecutorgetIoExecutor(java.util.concurrent.Executor valueIfMissing)

Returns the executor that will be used for IO tasks.

public intgetJpegQuality()

Returns the JPEG compression quality setting.

public intgetJpegQuality(int valueIfMissing)

Returns the JPEG compression quality setting.

public intgetMaxCaptureStages()

Returns the max number of CaptureStage.

public intgetMaxCaptureStages(int valueIfMissing)

Returns the max number of CaptureStage.

public ResolutionSelectorgetPostviewResolutionSelector()

public ImageCapture.ScreenFlashgetScreenFlash()

Gets the caller provided instance.

public booleanhasCaptureMode()

Returns whether a ImageCapture.CaptureMode option has been set in this configuration.

public booleanisPostviewEnabled()

public booleanisSoftwareJpegEncoderRequested()

Returns whether ImageCapture should use a software JPEG encoder, if available.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final Config.Option<java.lang.Integer> OPTION_IMAGE_CAPTURE_MODE

public static final Config.Option<java.lang.Integer> OPTION_FLASH_MODE

public static final Config.Option<CaptureBundle> OPTION_CAPTURE_BUNDLE

public static final Config.Option<java.lang.Integer> OPTION_BUFFER_FORMAT

public static final Config.Option<java.lang.Integer> OPTION_OUTPUT_FORMAT

public static final Config.Option<java.lang.Integer> OPTION_MAX_CAPTURE_STAGES

public static final Config.Option<ImageReaderProxyProvider> OPTION_IMAGE_READER_PROXY_PROVIDER

public static final Config.Option<java.lang.Boolean> OPTION_USE_SOFTWARE_JPEG_ENCODER

public static final Config.Option<java.lang.Integer> OPTION_FLASH_TYPE

public static final Config.Option<java.lang.Integer> OPTION_JPEG_COMPRESSION_QUALITY

public static final Config.Option<ImageCapture.ScreenFlash> OPTION_SCREEN_FLASH

public static final Config.Option<ResolutionSelector> OPTION_POSTVIEW_RESOLUTION_SELECTOR

public static final Config.Option<java.lang.Boolean> OPTION_POSTVIEW_ENABLED

Constructors

public ImageCaptureConfig(OptionsBundle config)

Creates a new configuration instance.

Methods

public Config getConfig()

public boolean hasCaptureMode()

Returns whether a ImageCapture.CaptureMode option has been set in this configuration.

Returns:

true if a ImageCapture.CaptureMode option has been set in this configuration, false otherwise.

public int getCaptureMode()

Returns the ImageCapture.CaptureMode.

Returns:

The stored value, if it exists in this configuration.

public int getFlashMode(int valueIfMissing)

Returns the .

Parameters:

valueIfMissing: The value to return if this configuration option has not been set.

Returns:

The stored value, if it exists in this configuration.

public int getFlashMode()

Returns the .

Returns:

The stored value, if it exists in this configuration.

public CaptureBundle getCaptureBundle(CaptureBundle valueIfMissing)

Returns the CaptureBundle.

Parameters:

valueIfMissing: The value to return if this configuration option has not been set.

Returns:

The stored value or valueIfMissing if the value does not exist in this configuration.

public CaptureBundle getCaptureBundle()

Returns the CaptureBundle.

Returns:

The stored value, if it exists in this configuration.

public java.lang.Integer getBufferFormat(java.lang.Integer valueIfMissing)

Returns the of the capture in memory.

Parameters:

valueIfMissing: The value to return if this configuration option has not been set.

Returns:

The stored value or ValueIfMissing if the value does not exist in this configuration.

public java.lang.Integer getBufferFormat()

Returns the of the capture in memory.

Returns:

The stored value, if it exists in the configuration.

public int getInputFormat()

Retrieves the format of the image that is fed as input.

This should be YUV_420_888, when processing is run on the image. Otherwise it is JPEG.

public int getMaxCaptureStages(int valueIfMissing)

Returns the max number of CaptureStage.

Parameters:

valueIfMissing: The value to return if this configuration option has not been set.

Returns:

The stored value or valueIfMissing if the value does not exist in this configuration.

public int getMaxCaptureStages()

Returns the max number of CaptureStage.

Returns:

The stored value, if it exists in this configuration.

public ImageReaderProxyProvider getImageReaderProxyProvider()

Gets the caller provided ImageReaderProxy.

public boolean isSoftwareJpegEncoderRequested()

Returns whether ImageCapture should use a software JPEG encoder, if available.

public int getFlashType(int valueIfMissing)

Returns the .

Parameters:

valueIfMissing: The value to return if this configuration option has not been set.

Returns:

The stored value, if it exists in this configuration.

public int getFlashType()

Returns the .

Returns:

The stored value, if it exists in this configuration.

public int getJpegQuality(int valueIfMissing)

Returns the JPEG compression quality setting.

Parameters:

valueIfMissing: The value to return if this configuration option has not been set.

Returns:

The stored value or valueIfMissing if the value does not exist in this configuration.

public int getJpegQuality()

Returns the JPEG compression quality setting.

Returns:

The stored value, if it exists in this configuration.

public ImageCapture.ScreenFlash getScreenFlash()

Gets the caller provided instance.

public ResolutionSelector getPostviewResolutionSelector()

Returns:

the ResolutionSelector used to determine the size of the postview.

public boolean isPostviewEnabled()

Returns:

if postview is enabled.

public java.util.concurrent.Executor getIoExecutor(java.util.concurrent.Executor valueIfMissing)

Returns the executor that will be used for IO tasks.

This executor will be used for any IO tasks specifically for ImageCapture, such as ImageCapture.takePicture(ImageCapture.OutputFileOptions, Executor, ImageCapture.OnImageSavedCallback). If no executor is set, then a default Executor specifically for IO will be used instead.

Parameters:

valueIfMissing: The value to return if this configuration option has not been set.

Returns:

The stored value or valueIfMissing if the value does not exist in this configuration.

public java.util.concurrent.Executor getIoExecutor()

Returns the executor that will be used for IO tasks.

This executor will be used for any IO tasks specifically for ImageCapture, such as ImageCapture.takePicture(ImageCapture.OutputFileOptions, Executor, ImageCapture.OnImageSavedCallback). If no executor is set, then a default Executor specifically for IO will be used instead.

Returns:

The stored value, if it exists in this configuration.

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.core.impl;

import android.graphics.ImageFormat;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.camera.core.ImageCapture;
import androidx.camera.core.ImageCapture.CaptureMode;
import androidx.camera.core.ImageReaderProxyProvider;
import androidx.camera.core.internal.IoConfig;
import androidx.camera.core.resolutionselector.ResolutionSelector;

import java.util.concurrent.Executor;

/**
 * Configuration for an image capture use case.
 */
public final class ImageCaptureConfig implements UseCaseConfig<ImageCapture>, ImageOutputConfig,
        IoConfig {

    // Option Declarations:
    // *********************************************************************************************

    public static final Option<Integer> OPTION_IMAGE_CAPTURE_MODE =
            Option.create("camerax.core.imageCapture.captureMode", int.class);
    public static final Option<Integer> OPTION_FLASH_MODE =
            Option.create("camerax.core.imageCapture.flashMode", int.class);
    public static final Option<CaptureBundle> OPTION_CAPTURE_BUNDLE =
            Option.create("camerax.core.imageCapture.captureBundle", CaptureBundle.class);
    public static final Option<Integer> OPTION_BUFFER_FORMAT =
            Option.create("camerax.core.imageCapture.bufferFormat", Integer.class);
    public static final Option<Integer> OPTION_OUTPUT_FORMAT =
            Option.create("camerax.core.imageCapture.outputFormat", Integer.class);
    public static final Option<Integer> OPTION_MAX_CAPTURE_STAGES =
            Option.create("camerax.core.imageCapture.maxCaptureStages", Integer.class);
    public static final Option<ImageReaderProxyProvider> OPTION_IMAGE_READER_PROXY_PROVIDER =
            Option.create("camerax.core.imageCapture.imageReaderProxyProvider",
                    ImageReaderProxyProvider.class);
    public static final Option<Boolean> OPTION_USE_SOFTWARE_JPEG_ENCODER =
            Option.create("camerax.core.imageCapture.useSoftwareJpegEncoder", boolean.class);
    public static final Option<Integer> OPTION_FLASH_TYPE =
            Option.create("camerax.core.imageCapture.flashType", int.class);
    public static final Option<Integer> OPTION_JPEG_COMPRESSION_QUALITY =
            Option.create("camerax.core.imageCapture.jpegCompressionQuality", int.class);
    public static final Option<ImageCapture.ScreenFlash> OPTION_SCREEN_FLASH =
            Option.create("camerax.core.imageCapture.screenFlash", ImageCapture.ScreenFlash.class);
    public static final Option<ResolutionSelector> OPTION_POSTVIEW_RESOLUTION_SELECTOR =
            Option.create("camerax.core.useCase.postviewResolutionSelector",
                    ResolutionSelector.class);

    public static final Option<Boolean> OPTION_POSTVIEW_ENABLED =
            Option.create("camerax.core.useCase.isPostviewEnabled",
                    Boolean.class);

    // *********************************************************************************************

    private final OptionsBundle mConfig;

    /** Creates a new configuration instance. */
    public ImageCaptureConfig(@NonNull OptionsBundle config) {
        mConfig = config;
    }

    @NonNull
    @Override
    public Config getConfig() {
        return mConfig;
    }

    /**
     * Returns whether a {@link CaptureMode} option has been set in this configuration.
     *
     * @return true if a {@link CaptureMode} option has been set in this configuration, false
     * otherwise.
     */
    public boolean hasCaptureMode() {
        return containsOption(OPTION_IMAGE_CAPTURE_MODE);
    }

    /**
     * Returns the {@link CaptureMode}.
     *
     * @return The stored value, if it exists in this configuration.
     * @throws IllegalArgumentException if the option does not exist in this configuration.
     */
    @CaptureMode
    public int getCaptureMode() {
        return retrieveOption(OPTION_IMAGE_CAPTURE_MODE);
    }

    /**
     * Returns the {@link ImageCapture.FlashMode}.
     *
     * @param valueIfMissing The value to return if this configuration option has not been set.
     * @return The stored value, if it exists in this configuration.
     */
    @ImageCapture.FlashMode
    public int getFlashMode(@ImageCapture.FlashMode int valueIfMissing) {
        return retrieveOption(OPTION_FLASH_MODE, valueIfMissing);
    }

    /**
     * Returns the {@link ImageCapture.FlashMode}.
     *
     * @return The stored value, if it exists in this configuration.
     * @throws IllegalArgumentException if the option does not exist in this configuration.
     */
    @ImageCapture.FlashMode
    public int getFlashMode() {
        return retrieveOption(OPTION_FLASH_MODE);
    }

    /**
     * Returns the {@link CaptureBundle}.
     *
     * @param valueIfMissing The value to return if this configuration option has not been set.
     * @return The stored value or <code>valueIfMissing</code> if the value does not exist in this
     * configuration.
     */
    @Nullable
    public CaptureBundle getCaptureBundle(@Nullable CaptureBundle valueIfMissing) {
        return retrieveOption(OPTION_CAPTURE_BUNDLE, valueIfMissing);
    }

    /**
     * Returns the {@link CaptureBundle}.
     *
     * @return The stored value, if it exists in this configuration.
     * @throws IllegalArgumentException if the option does not exist in this configuration.
     */
    @NonNull
    public CaptureBundle getCaptureBundle() {
        return retrieveOption(OPTION_CAPTURE_BUNDLE);
    }

    /**
     * Returns the {@link ImageFormat} of the capture in memory.
     *
     * @param valueIfMissing The value to return if this configuration option has not been set.
     * @return The stored value or <code>ValueIfMissing</code> if the value does not exist in this
     * configuration.
     */
    @Nullable
    public Integer getBufferFormat(@Nullable Integer valueIfMissing) {
        return retrieveOption(OPTION_BUFFER_FORMAT, valueIfMissing);
    }

    /**
     * Returns the {@link ImageFormat} of the capture in memory.
     *
     * @return The stored value, if it exists in the configuration.
     * @throws IllegalArgumentException if the option does not exist in this configuration.
     */
    @NonNull
    public Integer getBufferFormat() {
        return retrieveOption(OPTION_BUFFER_FORMAT);
    }

    /**
     * Retrieves the format of the image that is fed as input.
     *
     * <p>This should be YUV_420_888, when processing is run on the image. Otherwise it is JPEG.
     */
    @Override
    public int getInputFormat() {
        return retrieveOption(OPTION_INPUT_FORMAT);
    }

    /**
     * Returns the max number of {@link CaptureStage}.
     *
     * @param valueIfMissing The value to return if this configuration option has not been set.
     * @return The stored value or <code>valueIfMissing</code> if the value does not exist in
     * this configuration.
     */
    public int getMaxCaptureStages(int valueIfMissing) {
        return retrieveOption(OPTION_MAX_CAPTURE_STAGES, valueIfMissing);
    }

    /**
     * Returns the max number of {@link CaptureStage}.
     *
     * @return The stored value, if it exists in this configuration.
     * @throws IllegalArgumentException if the option does not exist in this configuration.
     */
    public int getMaxCaptureStages() {
        return retrieveOption(OPTION_MAX_CAPTURE_STAGES);
    }

    /**
     * Gets the caller provided {@link ImageReaderProxy}.
     *
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    @Nullable
    public ImageReaderProxyProvider getImageReaderProxyProvider() {
        return retrieveOption(OPTION_IMAGE_READER_PROXY_PROVIDER, null);
    }

    /**
     * Returns whether ImageCapture should use a software JPEG encoder, if available.
     *
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    public boolean isSoftwareJpegEncoderRequested() {
        return retrieveOption(OPTION_USE_SOFTWARE_JPEG_ENCODER, false);
    }

    /**
     * Returns the {@link ImageCapture.FlashType}.
     *
     * @param valueIfMissing The value to return if this configuration option has not been set.
     * @return The stored value, if it exists in this configuration.
     */
    @ImageCapture.FlashType
    public int getFlashType(@ImageCapture.FlashType int valueIfMissing) {
        return retrieveOption(OPTION_FLASH_TYPE, valueIfMissing);
    }

    /**
     * Returns the {@link ImageCapture.FlashType}.
     *
     * @return The stored value, if it exists in this configuration.
     * @throws IllegalArgumentException if the option does not exist in this configuration.
     */
    @ImageCapture.FlashType
    public int getFlashType() {
        return retrieveOption(OPTION_FLASH_TYPE);
    }

    /**
     * Returns the JPEG compression quality setting.
     *
     * @param valueIfMissing The value to return if this configuration option has not been set.
     * @return The stored value or <code>valueIfMissing</code> if the value does not exist in this
     * configuration.
     */
    @IntRange(from = 1, to = 100)
    public int getJpegQuality(@IntRange(from = 1, to = 100) int valueIfMissing) {
        return retrieveOption(OPTION_JPEG_COMPRESSION_QUALITY, valueIfMissing);
    }


    /**
     * Returns the JPEG compression quality setting.
     *
     * @return The stored value, if it exists in this configuration.
     * @throws IllegalArgumentException if the option does not exist in this configuration.
     */
    @IntRange(from = 1, to = 100)
    public int getJpegQuality() {
        return retrieveOption(OPTION_JPEG_COMPRESSION_QUALITY);
    }

    /**
     * Gets the caller provided {@link ImageCapture.ScreenFlash} instance.
     */
    @Nullable
    public ImageCapture.ScreenFlash getScreenFlash() {
        return retrieveOption(OPTION_SCREEN_FLASH, null);
    }

    /**
     * @return the {@link ResolutionSelector} used to determine the size of the postview.
     */
    @Nullable
    public ResolutionSelector getPostviewResolutionSelector() {
        return retrieveOption(OPTION_POSTVIEW_RESOLUTION_SELECTOR, null);
    }

    /**
     * @return if postview is enabled.
     */
    public boolean isPostviewEnabled() {
        return retrieveOption(OPTION_POSTVIEW_ENABLED, false);
    }

    // Implementations of IO default methods

    /**
     * Returns the executor that will be used for IO tasks.
     *
     * <p> This executor will be used for any IO tasks specifically for ImageCapture, such as
     * {@link ImageCapture#takePicture(ImageCapture.OutputFileOptions, Executor,
     * ImageCapture.OnImageSavedCallback)}. If no executor is set, then a default Executor
     * specifically for IO will be used instead.
     *
     * @param valueIfMissing The value to return if this configuration option has not been set.
     * @return The stored value or <code>valueIfMissing</code> if the value does not exist in this
     * configuration.
     */
    @Nullable
    @Override
    public Executor getIoExecutor(@Nullable Executor valueIfMissing) {
        return retrieveOption(OPTION_IO_EXECUTOR, valueIfMissing);
    }

    /**
     * Returns the executor that will be used for IO tasks.
     *
     * <p> This executor will be used for any IO tasks specifically for ImageCapture, such as
     * {@link ImageCapture#takePicture(ImageCapture.OutputFileOptions, Executor,
     * ImageCapture.OnImageSavedCallback)}. If no executor is set, then a default Executor
     * specifically for IO will be used instead.
     *
     * @return The stored value, if it exists in this configuration.
     * @throws IllegalArgumentException if the option does not exist in this configuration.
     */
    @NonNull
    @Override
    public Executor getIoExecutor() {
        return retrieveOption(OPTION_IO_EXECUTOR);
    }
}