Most visited

Recently visited

Added in API level 21

DngCreator

public final class DngCreator
extends Object implements AutoCloseable

java.lang.Object
   ↳ 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 RAW_SENSOR buffers available from CameraDevice, or with Bayer-type raw pixel data that is otherwise generated by an application. The DNG metadata tags will be generated from a 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

int MAX_THUMBNAIL_DIMENSION

Max width or height dimension for thumbnails.

Public constructors

DngCreator(CameraCharacteristics characteristics, CaptureResult metadata)

Create a new DNG object.

Public methods

void close()

Closes this resource, relinquishing any underlying resources.

DngCreator setDescription(String description)

Set the user description string to write.

DngCreator setLocation(Location location)

Set image location metadata.

DngCreator setOrientation(int orientation)

Set the orientation value to write.

DngCreator setThumbnail(Image pixels)

Set the thumbnail image.

DngCreator setThumbnail(Bitmap pixels)

Set the thumbnail image.

void writeByteBuffer(OutputStream dngOutput, Size size, ByteBuffer pixels, long offset)

Write the RAW_SENSOR pixel data to a DNG file with the currently configured metadata.

void writeImage(OutputStream dngOutput, Image pixels)

Write the pixel data to a DNG file with the currently configured metadata.

void writeInputStream(OutputStream dngOutput, Size size, InputStream pixels, long offset)

Write the RAW_SENSOR pixel data to a DNG file with the currently configured metadata.

Protected methods

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Inherited methods

From class java.lang.Object
From interface java.lang.AutoCloseable

Constants

MAX_THUMBNAIL_DIMENSION

Added in API level 21
int MAX_THUMBNAIL_DIMENSION

Max width or height dimension for thumbnails.

Constant Value: 256 (0x00000100)

Public constructors

DngCreator

Added in API level 21
DngCreator (CameraCharacteristics characteristics, 
                CaptureResult metadata)

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 CaptureResult object.

For best quality DNG files, it is strongly recommended that lens shading map output is enabled if supported. See STATISTICS_LENS_SHADING_MAP_MODE.

Parameters
characteristics CameraCharacteristics: an object containing the static CameraCharacteristics.
metadata CaptureResult: a metadata object to generate tags from.

Public methods

close

Added in API level 21
void close ()

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

While this interface method is declared to throw Exception, implementers are strongly encouraged to declare concrete implementations of the close method to throw more specific exceptions, or to throw no exception at all if the close operation cannot fail.

Implementers of this interface are also strongly advised to not have the close method throw InterruptedException. This exception interacts with a thread's interrupted status, and runtime misbehavior is likely to occur if an InterruptedException is suppressed. More generally, if it would cause problems for an exception to be suppressed, the AutoCloseable.close method should not throw it.

Note that unlike the close method of Closeable, this close method is not required to be idempotent. In other words, calling this close method more than once may have some visible side effect, unlike Closeable.close which is required to have no effect if called more than once. However, implementers of this interface are strongly encouraged to make their close methods idempotent.

setDescription

Added in API level 21
DngCreator setDescription (String description)

Set the user description string to write.

This is equivalent to setting the TIFF "ImageDescription" tag (0x010E).

Parameters
description String: the user description string.
Returns
DngCreator this DngCreator(CameraCharacteristics, CaptureResult) object.

setLocation

Added in API level 21
DngCreator setLocation (Location location)

Set image location metadata.

The given location object must contain at least a valid time, latitude, and longitude (equivalent to the values returned by getTime(), getLatitude(), and getLongitude() methods).

Parameters
location Location: an Location object to set.
Returns
DngCreator this DngCreator(CameraCharacteristics, CaptureResult) object.
Throws
IllegalArgumentException if the given location object doesn't contain enough information to set location metadata.

setOrientation

Added in API level 21
DngCreator setOrientation (int orientation)

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.

Parameters
orientation int: the orientation value to set, one of:
Returns
DngCreator this DngCreator(CameraCharacteristics, CaptureResult) object.

setThumbnail

Added in API level 21
DngCreator setThumbnail (Image pixels)

Set the thumbnail image.

Pixel data is interpreted as a YUV_420_888 image. Thumbnail images with a dimension larger than MAX_THUMBNAIL_DIMENSION will be rejected.

Parameters
pixels Image: an Image object with the format YUV_420_888.
Returns
DngCreator this DngCreator(CameraCharacteristics, CaptureResult) object.
Throws
IllegalArgumentException if the given thumbnail image has a dimension larger than MAX_THUMBNAIL_DIMENSION.

setThumbnail

Added in API level 21
DngCreator setThumbnail (Bitmap pixels)

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 Bitmap of pixel data.
Returns
DngCreator this DngCreator(CameraCharacteristics, CaptureResult) object.
Throws
IllegalArgumentException if the given thumbnail image has a dimension larger than MAX_THUMBNAIL_DIMENSION.

writeByteBuffer

Added in API level 21
void writeByteBuffer (OutputStream dngOutput, 
                Size size, 
                ByteBuffer pixels, 
                long offset)

Write the 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 SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE. Prior to API level 23, this was always the same as SENSOR_INFO_ACTIVE_ARRAY_SIZE. The pixel layout in the input is determined from the reported color filter arrangement (CFA) set in SENSOR_INFO_COLOR_FILTER_ARRANGEMENT. If insufficient metadata is available to write a well-formatted DNG file, an 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 OutputStream to write the DNG file to.
size Size: the Size of the image to write, in pixels.
pixels ByteBuffer: an ByteBuffer of pixel data to write.
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.
Throws
IOException if an error was encountered in the input or output stream.
IllegalStateException if not enough metadata information has been set to write a well-formatted DNG file.

writeImage

Added in API level 21
void writeImage (OutputStream dngOutput, 
                Image pixels)

Write the pixel data to a DNG file with the currently configured metadata.

For this method to succeed, the Image input must contain RAW_SENSOR pixel data, otherwise an IllegalArgumentException will be thrown.

Parameters
dngOutput OutputStream: an OutputStream to write the DNG file to.
pixels Image: an Image to write.
Throws
IOException if an error was encountered in the output stream.
IllegalArgumentException if an image with an unsupported format was used.
IllegalStateException if not enough metadata information has been set to write a well-formatted DNG file.

writeInputStream

Added in API level 21
void writeInputStream (OutputStream dngOutput, 
                Size size, 
                InputStream pixels, 
                long offset)

Write the 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 SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE. Prior to API level 23, this was always the same as SENSOR_INFO_ACTIVE_ARRAY_SIZE. The pixel layout in the input is determined from the reported color filter arrangement (CFA) set in SENSOR_INFO_COLOR_FILTER_ARRANGEMENT. If insufficient metadata is available to write a well-formatted DNG file, an IllegalStateException will be thrown.

Parameters
dngOutput OutputStream: an OutputStream to write the DNG file to.
size Size: the Size of the image to write, in pixels.
pixels InputStream: an InputStream of pixel data to write.
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.
Throws
IOException if an error was encountered in the input or output stream.
IllegalStateException if not enough metadata information has been set to write a well-formatted DNG file.
IllegalArgumentException if the size passed in does not match the

Protected methods

finalize

Added in API level 21
void finalize ()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Throws
Throwable

Hooray!