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 ImageFormat.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 |
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 |
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 | |
---|---|
Constants
MAX_THUMBNAIL_DIMENSION
public static final int MAX_THUMBNAIL_DIMENSION
Max width or height dimension for thumbnails.
Constant Value: 256 (0x00000100)
Public constructors
DngCreator
public 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 CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE
.
Parameters | |
---|---|
characteristics |
CameraCharacteristics : an object containing the static
CameraCharacteristics .
This value cannot be null . |
metadata |
CaptureResult : a metadata object to generate tags from.
This value cannot be null . |
Public methods
close
public void close ()
Closes this resource, relinquishing any underlying resources.
This method is invoked automatically on objects managed by the
try
-with-resources statement.
setDescription
public 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.
This value cannot be null . |
Returns | |
---|---|
DngCreator |
this DngCreator(CameraCharacteristics, CaptureResult) object.
This value cannot be null . |
setLocation
public 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 Location.getTime()
,
Location.getLatitude()
, and
Location.getLongitude()
methods).
Parameters | |
---|---|
location |
Location : an Location object to set.
This value cannot be null . |
Returns | |
---|---|
DngCreator |
this DngCreator(CameraCharacteristics, CaptureResult) object.
This value cannot be null . |
Throws | |
---|---|
IllegalArgumentException |
if the given location object doesn't contain enough information to set location metadata. |
setOrientation
public 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.
This value cannot be null . |
setThumbnail
public DngCreator setThumbnail (Image pixels)
Set the thumbnail image.
Pixel data is interpreted as a ImageFormat.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
ImageFormat.YUV_420_888 .
This value cannot be null . |
Returns | |
---|---|
DngCreator |
this DngCreator(CameraCharacteristics, CaptureResult) object.
This value cannot be null . |
Throws | |
---|---|
IllegalArgumentException |
if the given thumbnail image has a dimension
larger than MAX_THUMBNAIL_DIMENSION . |
setThumbnail
public 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.
This value cannot be null . |
Returns | |
---|---|
DngCreator |
this DngCreator(CameraCharacteristics, CaptureResult) object.
This value cannot be null . |
Throws | |
---|---|
IllegalArgumentException |
if the given thumbnail image has a dimension
larger than MAX_THUMBNAIL_DIMENSION . |
writeByteBuffer
public void writeByteBuffer (OutputStream dngOutput, Size size, ByteBuffer pixels, long offset)
Write the 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
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.
This value cannot be null . |
size |
Size : the Size of the image to write, in pixels.
This value cannot be null . |
pixels |
ByteBuffer : an 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 |
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
public 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
ImageFormat.RAW_SENSOR
pixel data, otherwise an
IllegalArgumentException
will be thrown.
Parameters | |
---|---|
dngOutput |
OutputStream : an OutputStream to write the DNG file to.
This value cannot be null . |
pixels |
Image : an Image to write.
This value cannot be null . |
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
public void writeInputStream (OutputStream dngOutput, Size size, InputStream pixels, long offset)
Write the 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
IllegalStateException
will be thrown.
Parameters | |
---|---|
dngOutput |
OutputStream : an 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 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 |
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
protected 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 Java 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 |