DngCreator
class DngCreator : AutoCloseable
| kotlin.Any | |
| ↳ | android.hardware.camera2.DngCreator |
The DngCreator class provides functions to write raw pixel data as a DNG file.
This class is designed to be used with the android.graphics.ImageFormat#RAW_SENSOR buffers available from android.hardware.camera2.CameraDevice, or with Bayer-type raw pixel data that is otherwise generated by an application. The DNG metadata tags will be generated from a android.hardware.camera2.CaptureResult object or set directly.
The DNG file format is a cross-platform file format that is used to store pixel data from camera sensors with minimal pre-processing applied. DNG files allow for pixel data to be defined in a user-defined colorspace, and have associated metadata that allow for this pixel data to be converted to the standard CIE XYZ colorspace during post-processing.
For more information on the DNG file format and associated metadata, please refer to the Adobe DNG 1.4.0.0 specification.
Summary
| Constants | |
|---|---|
| static Int |
Max width or height dimension for thumbnails. |
| Public constructors | |
|---|---|
DngCreator(characteristics: CameraCharacteristics, metadata: CaptureResult)Create a new DNG object. |
|
| Public methods | |
|---|---|
| Unit |
close() |
| DngCreator |
setDescription(description: String)Set the user description string to write. |
| DngCreator |
setLocation(location: Location)Set image location metadata. |
| DngCreator |
setOrientation(orientation: Int)Set the orientation value to write. |
| DngCreator |
setThumbnail(pixels: Bitmap)Set the thumbnail image. |
| DngCreator |
setThumbnail(pixels: Image)Set the thumbnail image. |
| Unit |
writeByteBuffer(dngOutput: OutputStream, size: Size, pixels: ByteBuffer, offset: Long)Write the |
| Unit |
writeImage(dngOutput: OutputStream, pixels: Image)Write the pixel data to a DNG file with the currently configured metadata. |
| Unit |
writeInputStream(dngOutput: OutputStream, size: Size, pixels: InputStream, offset: Long)Write the |
| Protected methods | |
|---|---|
| Unit |
finalize() |
Constants
MAX_THUMBNAIL_DIMENSION
static val MAX_THUMBNAIL_DIMENSION: Int
Max width or height dimension for thumbnails.
Value: 256Public constructors
DngCreator
DngCreator(
characteristics: CameraCharacteristics,
metadata: CaptureResult)
Create a new DNG object.
It is not necessary to call any set methods to write a well-formatted DNG file.
DNG metadata tags will be generated from the corresponding parameters in the android.hardware.camera2.CaptureResult object.
For best quality DNG files, it is strongly recommended that lens shading map output is enabled if supported. See CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE.
| Parameters | |
|---|---|
characteristics |
CameraCharacteristics: an object containing the static android.hardware.camera2.CameraCharacteristics. This value cannot be null. |
metadata |
CaptureResult: a metadata object to generate tags from. This value cannot be null. |
Public methods
close
fun close(): Unit
| Exceptions | |
|---|---|
java.lang.Exception |
if this resource cannot be closed |
setDescription
fun setDescription(description: String): DngCreator
Set the user description string to write.
This is equivalent to setting the TIFF "ImageDescription" tag (0x010E).
| Parameters | |
|---|---|
description |
String: the user description string. This value cannot be null. |
| Return | |
|---|---|
DngCreator |
this DngCreator object. This value cannot be null. |
setLocation
fun setLocation(location: Location): DngCreator
Set image location metadata.
The given location object must contain at least a valid time, latitude, and longitude (equivalent to the values returned by android.location.Location#getTime(), android.location.Location#getLatitude(), and android.location.Location#getLongitude() methods).
| Parameters | |
|---|---|
location |
Location: an android.location.Location object to set. This value cannot be null. |
| Return | |
|---|---|
DngCreator |
this DngCreator object. This value cannot be null. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if the given location object doesn't contain enough information to set location metadata. |
setOrientation
fun setOrientation(orientation: Int): DngCreator
Set the orientation value to write.
This will be written as the TIFF "Orientation" tag (0x0112). Calling this will override any prior settings for this tag.
| Return | |
|---|---|
DngCreator |
this DngCreator object. This value cannot be null. |
setThumbnail
fun setThumbnail(pixels: Bitmap): DngCreator
Set the thumbnail image.
Pixel data will be converted to a Baseline TIFF RGB image, with 8 bits per color channel. The alpha channel will be discarded. Thumbnail images with a dimension larger than MAX_THUMBNAIL_DIMENSION will be rejected.
| Parameters | |
|---|---|
pixels |
Bitmap: a android.graphics.Bitmap of pixel data. This value cannot be null. |
| Return | |
|---|---|
DngCreator |
this DngCreator object. This value cannot be null. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if the given thumbnail image has a dimension larger than MAX_THUMBNAIL_DIMENSION. |
setThumbnail
fun setThumbnail(pixels: Image): DngCreator
Set the thumbnail image.
Pixel data is interpreted as a android.graphics.ImageFormat#YUV_420_888 image. Thumbnail images with a dimension larger than MAX_THUMBNAIL_DIMENSION will be rejected.
| Parameters | |
|---|---|
pixels |
Image: an android.media.Image object with the format android.graphics.ImageFormat#YUV_420_888. This value cannot be null. |
| Return | |
|---|---|
DngCreator |
this DngCreator object. This value cannot be null. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if the given thumbnail image has a dimension larger than MAX_THUMBNAIL_DIMENSION. |
writeByteBuffer
fun writeByteBuffer(
dngOutput: OutputStream,
size: Size,
pixels: ByteBuffer,
offset: Long
): Unit
Write the android.graphics.ImageFormat#RAW_SENSOR pixel data to a DNG file with the currently configured metadata.
Raw pixel data must have 16 bits per pixel, and the input must contain at least offset + 2 * width * height) bytes. The width and height of the input are taken from the width and height set in the DngCreator metadata tags, and will typically be equal to the width and height of CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE. Prior to API level 23, this was always the same as CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE. The pixel layout in the input is determined from the reported color filter arrangement (CFA) set in CameraCharacteristics.SENSOR_INFO_COLOR_FILTER_ARRANGEMENT. If insufficient metadata is available to write a well-formatted DNG file, an java.lang.IllegalStateException will be thrown.
Any mark or limit set on this ByteBuffer is ignored, and will be cleared by this method.
| Parameters | |
|---|---|
dngOutput |
OutputStream: an java.io.OutputStream to write the DNG file to. This value cannot be null. |
size |
Size: the Size of the image to write, in pixels. This value cannot be null. |
pixels |
ByteBuffer: an java.nio.ByteBuffer of pixel data to write. This value cannot be null. |
offset |
Long: the offset of the raw image in bytes. This indicates how many bytes will be skipped in the input before any pixel data is read. Value is 0 or greater |
| Exceptions | |
|---|---|
java.io.IOException |
if an error was encountered in the input or output stream. |
java.lang.IllegalStateException |
if not enough metadata information has been set to write a well-formatted DNG file. |
writeImage
fun writeImage(
dngOutput: OutputStream,
pixels: Image
): Unit
Write the pixel data to a DNG file with the currently configured metadata.
For this method to succeed, the android.media.Image input must contain android.graphics.ImageFormat#RAW_SENSOR pixel data, otherwise an java.lang.IllegalArgumentException will be thrown.
| Parameters | |
|---|---|
dngOutput |
OutputStream: an java.io.OutputStream to write the DNG file to. This value cannot be null. |
pixels |
Image: an android.media.Image to write. This value cannot be null. |
| Exceptions | |
|---|---|
java.io.IOException |
if an error was encountered in the output stream. |
java.lang.IllegalArgumentException |
if an image with an unsupported format was used. |
java.lang.IllegalStateException |
if not enough metadata information has been set to write a well-formatted DNG file. |
writeInputStream
fun writeInputStream(
dngOutput: OutputStream,
size: Size,
pixels: InputStream,
offset: Long
): Unit
Write the android.graphics.ImageFormat#RAW_SENSOR pixel data to a DNG file with the currently configured metadata.
Raw pixel data must have 16 bits per pixel, and the input must contain at least offset + 2 * width * height) bytes. The width and height of the input are taken from the width and height set in the DngCreator metadata tags, and will typically be equal to the width and height of CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE. Prior to API level 23, this was always the same as CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE. The pixel layout in the input is determined from the reported color filter arrangement (CFA) set in CameraCharacteristics.SENSOR_INFO_COLOR_FILTER_ARRANGEMENT. If insufficient metadata is available to write a well-formatted DNG file, an java.lang.IllegalStateException will be thrown.
| Parameters | |
|---|---|
dngOutput |
OutputStream: an java.io.OutputStream to write the DNG file to. This value cannot be null. |
size |
Size: the Size of the image to write, in pixels. This value cannot be null. |
pixels |
InputStream: an java.io.InputStream of pixel data to write. This value cannot be null. |
offset |
Long: the offset of the raw image in bytes. This indicates how many bytes will be skipped in the input before any pixel data is read. Value is 0 or greater |
| Exceptions | |
|---|---|
java.io.IOException |
if an error was encountered in the input or output stream. |
java.lang.IllegalStateException |
if not enough metadata information has been set to write a well-formatted DNG file. |
java.lang.IllegalArgumentException |
if the size passed in does not match the |
Protected methods
finalize
protected fun finalize(): Unit
| Exceptions | |
|---|---|
java.lang.Throwable |
the Exception raised by this method |