HiRISE
 PDS_JP2

JP2_Encoder Class Reference

A JP2_Encoder encodes image pixel data into a JPEG2000 JP2 file. More...

#include <JP2_Encoder.hh>

Collaboration diagram for JP2_Encoder:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 JP2_Encoder ()
 ~JP2_Encoder ()
std::string source () const
 Get the PDS image data source pathname.
JP2_Encodersource (const std::string &pathname)
 Set the pathname to the PDS image data source.
std::string destination () const
 Get the destination JP2 file pathname.
JP2_Encoderdestination (const std::string &pathname)
 Set the destination JP2 file pathname.
std::string PDS_label_pathname () const
 Get the PDS/JP2 label file pathname.
JP2_EncoderPDS_label_pathname (const std::string &pathname)
 Set the PDS/JP2 label file pathname.
std::streamoff image_data_location () const
 Get the location of the image data in the source file.
JP2_Encoderimage_data_location (std::streamoff file_offset)
 Set the location of the image data in the source file.
unsigned int image_bands () const
 Get the number of bands (components) in the PDS image.
JP2_Encoderimage_bands (unsigned int bands)
 Set the number of bands (components) in the PDS image.
const Size_2D image_size () const
 Get the size of the source PDS image data.
JP2_Encoderimage_size (const Size_2D &size)
 Set the size of the source PDS image data.
unsigned int pixel_bytes () const
 Get the number of bytes per pixel.
JP2_Encoderpixel_bytes (unsigned int bytes_per_pixel)
 Set the number of bytes per pixel.
unsigned int pixel_bits () const
 Get the pixel precision.
JP2_Encoderpixel_bits (unsigned int bits_per_pixel)
 Set the number of bits per pixel.
bool signed_data () const
 Get the signedness of the pixel data.
JP2_Encodersigned_data (bool data_is_signed)
 Set the signedness of the data.
bool MSB_data () const
 Test if the source data will be treated as MSB ordered.
JP2_EncoderMSB_data (bool data_is_MSB)
 Set the source data byte ordering.
bool swap_pixel_bytes () const
 Test if multi-byte pixels will be reordered before being sent to the JPEG2000 codestream generation machinery.
JP2_Encoderswap_pixel_bytes (bool swap_data)
 Set if multi-byte pixels will be reordered before being sent to the JPEG2000 codestream generation machinery.
unsigned int line_prefix_bytes () const
 Get the number of bytes preceeding each line of image pixel data.
JP2_Encoderline_prefix_bytes (unsigned int prefix_bytes)
 Set the number of bytes preceeding each line of image pixel data.
unsigned int line_suffix_bytes () const
 Get the number of bytes following each line of image pixel data.
JP2_Encoderline_suffix_bytes (unsigned int suffix_bytes)
 Set the number of bytes following each line of image pixel data.
const Size_2D tile_size () const
 Get the size of the JP2 image tiles.
JP2_Encodertile_size (const Size_2D &size)
 Set the size of the JP2 image tiles.
unsigned int resolution_levels () const
 Get the total number of codestream resolution levels.
JP2_Encoderresolution_levels (unsigned int resolution_levels)
 Set the total number of codestream resolution levels.
std::string progression_order () const
 Get the codestream progression order descriptor.
JP2_Encoderprogression_order (const std::string &progression)
 Set the codestream progression order.
const std::vector< Size_2Dprecinct_sizes () const
 Get the precinct sizes for each resolution level.
const Size_2D precinct_size (unsigned int resolution_level=0) const
 Get the precinct size for a given resolution level.
JP2_Encoderprecinct_sizes (const std::vector< Size_2D > &sizes)
 Set the precinct sizes for each resolution level.
JP2_Encoderprecinct_size (const Size_2D &size, unsigned int resolution_level=0)
 Set the precinct size for a given resolution level.
const Size_2D code_block_size () const
 Get the code block size.
JP2_Encodercode_block_size (const Size_2D &size)
 Set the code block size.
JP2_Box::JP2_Box_Listadded_boxes ()
 Get the list of user specified data boxes added to the JP2 file.
JP2_Encoderadd_box (JP2_Box *box)
 Add a data box to the JP2 file.
bool remove_box (JP2_Box *box)
 Remove a data box from the list of user specified boxes.
const unsigned char * producer_UUID () const
 Get the product producer signature UUID value.
JP2_Encoderproducer_UUID (const unsigned char *id)
 Set the product producer signature UUID value.
bool ready () const
 Test if the encoder is ready to compress the image data.
std::string reasons () const
 Get a description of the reasons that the encoder is not ready.
int needs () const
 Indicates what the encoder needs to do its job.
JP2_Encoder_Error * encoder_error () const
 Get the JP2_Encoder_Error describing the last encoder error that occurred.
long long encode ()
 Encode the image source to a JPEG2000 JP2 destination.
void open ()
 Open the source JP2 file.
long long write_header ()
 Write the required metadata boxes to the JP2 file.
long long write_user_boxes ()
 Write user specified boxes to the JP2 file.
long long write_codestream ()
 Generate the compressed image data JPEG2000 codestream and write it to the JP2 file.
JP2_Encoderincremental_flush_bytes (long long bytes)
 Set the rate at which compressed image data will be written to the output JP2 file.
long long incremental_flush_bytes () const
 Get the rate at which compressed image data will be written to the output JP2 file.
JP2_Encoderincremental_flush_lines (unsigned int lines)
 Set the rate at which compressed image data will be written to the output JP2 file.
int incremental_flush_lines () const
 Get the rate at which compressed image data will be written to the output JP2 file.
long long close ()
int invalid_precinct_size (const std::vector< Size_2D > &sizes)
 Check for valid precinct sizes.

Static Public Attributes

static const char *const ID
 Class identification name with source code version and date.
static const unsigned int DEFAULT_RESOLUTION_LEVELS = 6
 Default number of resolution levels.
static const unsigned int MAX_RESOLUTION_LEVELS = 32
 Maximum number of resolution levels.
static const char *const UUID_INFO_BOX_NAME = "uinf"
 PDS label reference information UUID Info JP2 container box name.
static const char *const UUID_BOX_NAME = "ulst"
 Data provider UUID JP2 box name.
static const int UUID_SIZE = 16
 Size of the UUID data content.
static const char *const URL_BOX_NAME = "url "
 PDS label relative filename URL JP2 box name.
static const int MIN_STRIPE_HEIGHT = 256
 Image data stripe minimum and maximum number of lines.
static const int MAX_STRIPE_HEIGHT = 8192
static const int NEEDS_SOURCE = 1 << 0
 What the encoder needs to do its job.
static const int NEEDS_DESTINATION = 1 << 1
static const int NEEDS_IMAGE = 1 << 2
static const int ENCODER_EXCEPTION = 66
 JP2_Encoder_Error exception signal value.

Protected Member Functions

void read_stripe (std::istream &source, int band, int line, int lines, kdu_int16 *buffer)
 Fill an image data buffer with pixel data from a source stream.
void read_stripe (std::istream &source, int band, int line, int lines, kdu_int32 *buffer)
 Fill an image data buffer with pixel data from a source stream.

Protected Attributes

std::string Image_Source
 Image source pathname.
std::string JP2_Pathname
 Image destination pathname.
std::streamoff Image_Offset
 Image data location as a byte offset within the source file.
unsigned int Image_Bands
 Total image bands (components).
Size_2D Image_Size
unsigned int Line_Prefix_Bytes
 The number of bytes preceeding and following each line of pixel bytes.
unsigned int Line_Suffix_Bytes
unsigned int Pixel_Bytes
 Pixel datum size in bytes.
unsigned int Pixel_Bits
 Pixel precision bits.
bool Signed_Data
 Whether pixel data is to be treated as signed.
JP2_Box::JP2_Box_List Added_Boxes
std::string PDS_Label_Pathname
 PDS label file pathname to be placed in a UUID Info URL box.
unsigned char * Producer_UUID
 The UUID to be placed in a UUID List box inside a UUID Info box.
bool Swap_Pixel_Bytes
 Whether pixel bytes should be reordered before be encoded.
unsigned int Resolution_Levels
 The number of resolution levels to encode.
std::string Progression_Order
 The codestream progression order to be used.
Size_2D Tile_Size
 Tile size for codestream structure organization.
std::vector< Size_2DPrecinct_Sizes
 Precinct sizes for codestream structure organization within tiles.
Size_2D Code_Block_Size
 Code block size for codestream packet encoding within precincts.
long long Incremental_Flush_Bytes

Detailed Description

A JP2_Encoder encodes image pixel data into a JPEG2000 JP2 file.

After a JP2_Encoder is constructed it must be configured. The encoder must be configured with at least an input image data source file, an output JP2 destination file and the image data characterization with at least the image size and number of pixel bytes or pixel bits. By default the image data is assumed to be located at the beginning the source file, has one band (i.e. component), is unsigned, is MSB ordered (if multi-byte) and has no line prefix or suffix bytes.

The JP2_Encoder can also be configured with various JPEG2000 codestream organization information. By default the codestream will be untiled, have DEFAULT_RESOLUTION_LEVELS resolution levels, use Precint-Component-Resolution-Level progression order, have a 64x64 code block size and use precinct sizes determined by the underlying codestream generation machinery.

Once the JP2_Encoder is ready encoding can be started to generate the JP2 file from the image data source. Lossless image data compression will be used to generate the JPEG2000 codestream. A JP2_Encoder may be reused with or without reconfiguration between uses.

This implementation employs the Kakadu Software libraries.

Author:
Bradford Castalia, Drew Davidson and Ben Pearson, UA/HiROC
Version:
1.23


Constructor & Destructor Documentation

JP2_Encoder  ) 
 

~JP2_Encoder  ) 
 


Member Function Documentation

std::string source  )  const [inline]
 

Get the PDS image data source pathname.

Returns:
The pathname string for the PDS source. This will be the empty string if no source has been bound to this JP2_Encoder.

JP2_Encoder & source const std::string &  pathname  ) 
 

Set the pathname to the PDS image data source.

N.B.: If the source has already been opened and the pathname is different than the previous pathname, the source is closed.

Parameters:
pathname The image data source pathname.
Returns:
This JP2_Encoder.

std::string destination  )  const [inline]
 

Get the destination JP2 file pathname.

Returns:
The destination file pathname string. This will be empty if no destination has been bound to this JP2_Encoder.
See also:
destination(const std::string&)

JP2_Encoder& destination const std::string &  pathname  )  [inline]
 

Set the destination JP2 file pathname.

Parameters:
pathname The destination file pathname string.
Returns:
This JP2_Encoder.

std::string PDS_label_pathname  )  const [inline]
 

Get the PDS/JP2 label file pathname.

Returns:
The PDS/JP2 label file pathname string. This will be empty if no PDS/JP2 label file has been bound to this JP2_Encoder.
See also:
PDS_label_pathname(const std::string&)

JP2_Encoder& PDS_label_pathname const std::string &  pathname  )  [inline]
 

Set the PDS/JP2 label file pathname.

Only the filename portion of the pathname is used for the relative filename URL reference when the user boxes are written to the JP2 file.

Parameters:
pathname The PDS/JP2 label file pathname string. If NULL no label filename reference URL box or producer signature UUUID box will be included in the JP2 file.
Returns:
This JP2_Encoder.
See also:
producer_UUID(const unsigned char*)

std::streamoff image_data_location  )  const [inline]
 

Get the location of the image data in the source file.

Returns:
The byte offset where the image data starts in the source file.
See also:
image_data_location(std::ios::off_type)

JP2_Encoder& image_data_location std::streamoff  file_offset  )  [inline]
 

Set the location of the image data in the source file.

Parameters:
file_offset The byte offset where the image data starts in the source file.
Returns:
This JP2_Encoder.

unsigned int image_bands  )  const [inline]
 

Get the number of bands (components) in the PDS image.

Returns:
The number of bands in the PDS image.
See also:
image_bands(unsigned int)

JP2_Encoder& image_bands unsigned int  bands  )  [inline]
 

Set the number of bands (components) in the PDS image.

Parameters:
bands The number of bands in the PDS image.
Returns:
This JP2_Encoder.

const Size_2D image_size  )  const [inline]
 

Get the size of the source PDS image data.

Returns:
A Size_2D object containing the image width and height.
See also:
image_size(const Size_2D&)

JP2_Encoder & image_size const Size_2D size  ) 
 

Set the size of the source PDS image data.

Parameters:
size A Size_2D object containing the image width and height.
Returns:
This JP2_Encoder.
Exceptions:
invalid_argument If either the image width or height is zero.

unsigned int pixel_bytes  )  const [inline]
 

Get the number of bytes per pixel.

Returns:
The number of storage bytes used by each pixel.
See also:
pixel_bytes(unsigned int)

JP2_Encoder & pixel_bytes unsigned int  bytes_per_pixel  ) 
 

Set the number of bytes per pixel.

N.B.: If the number of pixel bytes is 1 the data will be set to unsigned.

Parameters:
bytes_per_pixel The number of bytes per pixel. Only the values 1, 2 and 4 are allowed.
Returns:
This JP2_Encoder.
Exceptions:
invalid_argument If the argument is not 1, 2 or 4.
length_error If the number of pixel bytes is less than are needed to hold the pixel bits.

unsigned int pixel_bits  )  const [inline]
 

Get the pixel precision.

Returns:
The number of valid bits used by each pixel.
See also:
pixel_bits(unsigned int)

JP2_Encoder & pixel_bits unsigned int  bits_per_pixel  ) 
 

Set the number of bits per pixel.

The number of pixel bytes is enlarged, if necessary, to accommodate all the pixel bits.

N.B.: If the number of pixel bits is less than the number of bits in the pixel bytes the data will be set to unsigned.

Parameters:
bits_per_pixel The number of bits per pixel. The maximum value is 32.
Returns:
This JP2_Encoder.
Exceptions:
invalid_argument If the argument is greater than 32.

bool signed_data  )  const [inline]
 

Get the signedness of the pixel data.

Returns:
true if the pixel data is treated as signed; false otherwise.
See also:
signed_data(bool)

JP2_Encoder & signed_data bool  data_is_signed  ) 
 

Set the signedness of the data.

N.B.: If the number of pixel bytes is 1, or the number of pixel bits is less than the number of bits in the pixel bytes, then the data is unsigned by definition. In such cases the argument will be forced to false.

Parameters:
data_is_signed true if the data is to be treated as signed; false otherwise.
Returns:
This JP2_Encoder.

bool MSB_data  )  const
 

Test if the source data will be treated as MSB ordered.

Returns:
true if the host system is not high endian and pixel byte swapping has been enabled, or the host system is high endian and pixel byte swapping has not been enabled; false otherwise.

JP2_Encoder & MSB_data bool  data_is_MSB  ) 
 

Set the source data byte ordering.

N.B.: The pixel byte swapping state is set by this method: If the host system is not high endian and the source data is MSB ordered, or the host system is high endian and the source data is LSB ordered, pixel byte swapping will be enabled; otherwise pixel byte swapping will be disabled.

Parameters:
data_is_MSB true if the source data is MSB ordered; false if the source data is LSB ordered.
Returns:
This JP2_Encoder.

bool swap_pixel_bytes  )  const [inline]
 

Test if multi-byte pixels will be reordered before being sent to the JPEG2000 codestream generation machinery.

Returns:
true if multi-byte pixels are to be reordered; false otherwise.
See also:
swap_pixel_bytes(bool)

JP2_Encoder& swap_pixel_bytes bool  swap_data  )  [inline]
 

Set if multi-byte pixels will be reordered before being sent to the JPEG2000 codestream generation machinery.

Parameters:
swap_data true if multi-byte pixels are to be reordered; false otherwise.
Returns:
This JP2_Encoder.
See also:
MSB_data(bool)

unsigned int line_prefix_bytes  )  const [inline]
 

Get the number of bytes preceeding each line of image pixel data.

Returns:
The number of line prefix bytes.
See also:
line_prefix_bytes(unsigned int)

JP2_Encoder& line_prefix_bytes unsigned int  prefix_bytes  )  [inline]
 

Set the number of bytes preceeding each line of image pixel data.

Parameters:
prefix_bytes The number of line prefix bytes.
Returns:
This JP2_Encoder.

unsigned int line_suffix_bytes  )  const [inline]
 

Get the number of bytes following each line of image pixel data.

Returns:
The number of line suffix bytes.
See also:
line_suffix_bytes(unsigned int)

JP2_Encoder& line_suffix_bytes unsigned int  suffix_bytes  )  [inline]
 

Set the number of bytes following each line of image pixel data.

Parameters:
suffix_bytes The number of line suffix bytes.
Returns:
This JP2_Encoder.

const Size_2D tile_size  )  const [inline]
 

Get the size of the JP2 image tiles.

Returns:
A Size_2D object containing the JP2 image tiles width and height.
See also:
tile_size(const Size_2D&)

JP2_Encoder& tile_size const Size_2D size  )  [inline]
 

Set the size of the JP2 image tiles.

If the tile width is zero the width of the image will be use. If the tile height is zero height of the image will be used.

Parameters:
size A Size_2D object containing the JP2 tiles width and height.
Returns:
This JP2_Encoder.

unsigned int resolution_levels  )  const [inline]
 

Get the total number of codestream resolution levels.

N.B.: The number of resolution levels is one more than the number of JPEG2000 decomposition levels.

Returns:
The total number of codestream resolution levels.

JP2_Encoder & resolution_levels unsigned int  resolution_levels  ) 
 

Set the total number of codestream resolution levels.

N.B.: The number of resolution levels is one more than the number of JPEG2000 decomposition levels.

Parameters:
resolution_levels The total number of codestream resolution levels.
Returns:
This JP2_Encoder.
Exceptions:
invalid_argument If the sepecified number of resolution levels is greater than the MAX_RESOLUTION_LEVELS allowed.

std::string progression_order  )  const [inline]
 

Get the codestream progression order descriptor.

Returns:
The progression order descriptor string.
See also:
progression_order(const std::string&)

JP2_Encoder & progression_order const std::string &  progression  ) 
 

Set the codestream progression order.

The progression order is described by a string which specifies the order in which the JPEG2000 codestream is written. A JPEG2000 codestream has Position (image area), Component (image band), Resolution and Layer (quality) dimensions. The codestream progression order is specified as the first letters of each dimension in the order in which they are to be written; the first dimension specified varies the most slowly while the last dimension specified varies the most quickly.

The default progression order is set at compile time by the value of the DEFAULT_PROGRESSION_ORDER symbol.

Parameters:
progression A string specifying the progression order.
Returns:
This JP2_Encoder.
Exceptions:
invalid_argument If the progression order string is not four characters containing 'P', 'C', 'R' and 'L' in some order.

const std::vector<Size_2D> precinct_sizes  )  const [inline]
 

Get the precinct sizes for each resolution level.

Returns:
The list of precinct sizes as a const std::vector<Size_2D>) with one entry for each resolution level.
See also:
precinct_sizes(const std::vector<Size_2D>& sizes)

resolution_levels(unsigned int)

const Size_2D precinct_size unsigned int  resolution_level = 0  )  const
 

Get the precinct size for a given resolution level.

Parameters:
resolution_level The resoultion level index (0-based) for which the precinct size is to be obtained.
Returns:
The precinct size (Size_2D) for the resolution level.
Exceptions:
invalid_argument If the resolution level is greater than or equal to the number of resolution levels.
See also:
resolution_levels(unsigned int)

JP2_Encoder & precinct_sizes const std::vector< Size_2D > &  sizes  ) 
 

Set the precinct sizes for each resolution level.

Each precinct size dimension must be a non-zero power of two.

If the number of precinct sizes is greater than the number of resolution levels the excess size values will be ignored. If the number of precinct sizes is less than the number of resolution levels the last size will be used for the sizes of all remaining resolution levels.

Parameters:
sizes A list (vector<Size_2D>) of precinct sizes in resolution number order.
Returns:
This JP2_Encoder.
Exceptions:
invalid_argument If any precinct size dimension is not a non-zero power of two.
See also:
invalid_precinct_size(const std::vector<Size_2D>& sizes)

JP2_Encoder & precinct_size const Size_2D size,
unsigned int  resolution_level = 0
 

Set the precinct size for a given resolution level.

Parameters:
size A precinct size (Size_2D) for the resolution level.
resolution_level The resoultion level index (0-based) for which the precinct size is to be obtained.
Exceptions:
invalid_argument If the resolution level is greater than or equal to the number of resolution levels.
See also:
resolution_levels(unsigned int)

const Size_2D code_block_size  )  const [inline]
 

Get the code block size.

Returns:
The size (Size_2D) of the code block.
See also:
code_block_size(const Size_2D&)

JP2_Encoder & code_block_size const Size_2D size  ) 
 

Set the code block size.

Parameters:
size The size (Size_2D) of the code block.
Returns:
This JP2_Encoder.
Exceptions:
invalid_argument If either dimension is 0 or greater than 64.

JP2_Box::JP2_Box_List& added_boxes  )  [inline]
 

Get the list of user specified data boxes added to the JP2 file.

Returns:
A reference to a JP2_Box::JP2_Box_List, a vector of JP2_Box objects that will be added to the JP2 file, or that were added if the file has already been written.

JP2_Encoder & add_box JP2_Box box  ) 
 

Add a data box to the JP2 file.

The box is placed on the list of user specified boxes that will be added to included in the JP2 file when it is written.

Parameters:
box A JP2_Box pointer.
Returns:
This JP2_Encoder.

bool remove_box JP2_Box box  ) 
 

Remove a data box from the list of user specified boxes.

Parameters:
box A JP2_Box pointer.
Returns:
true if the specified box was found in the list of user specifed boxes; false otherwise.
See also:
added_boxes()

const unsigned char* producer_UUID  )  const [inline]
 

Get the product producer signature UUID value.

Returns:
An array of UUID_SIZE (16) characters (N.B.: This is not a null-terminated character string) containing the product producer UUID value. This will be NULL if a product producer signature of all zeros is to be used.
See also:
producer_UUID(const unsigned char*)

JP2_Encoder & producer_UUID const unsigned char *  id  ) 
 

Set the product producer signature UUID value.

The producer signature UUID value is intended to provide a unique identifier for the product. The UUID will be placed in a UUID List box inside a UUID Info box.

N.B.: A producer signature will only be included in the JP2 file if a PDS label pathname has been specified.

Parameters:
id An array of UUID_SIZE (16) characters (N.B.: This is not a null-terminated character string) containing the product producer UUID value. If NULL no product producer signature is to be used.

bool ready  )  const
 

Test if the encoder is ready to compress the image data.

Returns:
true if the encoder is ready; false otherwise.
See also:
needs() const

reasons() const

string reasons  )  const
 

Get a description of the reasons that the encoder is not ready.

Returns:
A string describing what the encoder needs. This will be the empty string if the encoder is ready to compress image data.

int needs  )  const
 

Indicates what the encoder needs to do its job.

The returned bit flag value will be zero if the encoder has all the required user-supplied information. Otherwise it will have one or more of the following bits set:

NEEDS_SOURCE (0)
A source PDS file pathname has not been specified.
NEEDS_DESTINATION (1)
A destination PDS/JP2 file pathname has not been specified.
NEEDS_IMAGE
The source image structure - image size, number of bands and bytes per pixel - has not been completely defined.

Returns:
A bit flag value.

JP2_Encoder_Error * encoder_error  )  const
 

Get the JP2_Encoder_Error describing the last encoder error that occurred.

The JP2_Encoder_Error contains a Message string data member describing the last error. This will be the empty string if no error has occurred.

Returns:
A pointer to a JP2_Encoder_Error object.

long long encode  ) 
 

Encode the image source to a JPEG2000 JP2 destination.

This function is the main workhorse of the class. It is responsible for doing the actual work of generating a JP2 file.

The destination JP2 file is opened. The JP2 metadata boxes are written to the file, including the required header boxes and any user boxes that have been added and the box to contain a producer signature UUID and PDS label filename URL if this has been specified. The source pixel data is written to a codestream box. The completed JP2 file is then closed.

Returns:
The number of bytes written to the JP2 file.

void open  ) 
 

Open the source JP2 file.

long long write_header  ) 
 

Write the required metadata boxes to the JP2 file.

Returns:
The number of bytes written to the JP2 file.

long long write_user_boxes  )