HiRISE
 PDS_JP2

Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
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]

Public Member Functions

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

Static Public Attributes

static const char *const ID
 Class identification name with source code version and date. More...
 
static const unsigned int DEFAULT_RESOLUTION_LEVELS = 6
 Default number of resolution levels. More...
 
static const unsigned int MAX_RESOLUTION_LEVELS = 32
 Maximum number of resolution levels. More...
 
static const unsigned int MAX_QUALITY_LAYERS = 16384
 Maximum number of quality layers. More...
 
static const char *const UUID_INFO_BOX_NAME = "uinf"
 PDS label reference information UUID Info JP2 container box name. More...
 
static const char *const UUID_BOX_NAME = "ulst"
 Data provider UUID JP2 box name. More...
 
static const int UUID_SIZE = 16
 Size of the UUID data content. More...
 
static const char *const URL_BOX_NAME = "url "
 PDS label relative filename URL JP2 box name. More...
 
static const int MIN_STRIPE_HEIGHT = 256
 Image data stripe minimum and maximum number of lines. More...
 
static const int MAX_STRIPE_HEIGHT = 8192
 
static const int NEEDS_SOURCE = 1 << 0
 What the encoder needs to do its job. More...
 
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. More...
 

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. More...
 
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. More...
 

Protected Attributes

std::string Image_Source
 Image source pathname. More...
 
std::string JP2_Pathname
 Image destination pathname. More...
 
std::streamoff Image_Offset
 Image data location as a byte offset within the source file. More...
 
unsigned int Image_Bands
 Total image bands (components). More...
 
Size_2D Image_Size
 
unsigned int Line_Prefix_Bytes
 The number of bytes preceeding and following each line of pixel bytes. More...
 
unsigned int Line_Suffix_Bytes
 
unsigned int Pixel_Bytes
 Pixel datum size in bytes. More...
 
unsigned int Pixel_Bits
 Pixel precision bits. More...
 
bool Signed_Data
 Whether pixel data is to be treated as signed. More...
 
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. More...
 
unsigned char * Producer_UUID
 The UUID to be placed in a UUID List box inside a UUID Info box. More...
 
std::string Comment
 Comment segment to be added to the codestream. More...
 
bool Swap_Pixel_Bytes
 Whether pixel bytes should be reordered before be encoded. More...
 
unsigned int Resolution_Levels
 The number of resolution levels to encode. More...
 
unsigned int Quality_Layers
 
double Bit_Rate
 
std::string Progression_Order
 The codestream progression order to be used. More...
 
Size_2D Tile_Size
 Tile size for codestream structure organization. More...
 
std::vector< Size_2DPrecinct_Sizes
 Precinct sizes for codestream structure organization within tiles. More...
 
Size_2D Code_Block_Size
 Code block size for codestream packet encoding within precincts. More...
 
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(const std::string&) destination} file and the image data characterization with at least the image { image_size(const Size_2D&) size} and number of { pixel_bytes(unsigned int) pixel bytes} or { pixel_bits(unsigned int) pixel bits}. By default the image data is assumed to be image_data_location(std::streamoff) located} at the beginning the source file, has one { image_bands(unsigned int) band} (i.e. component), is { signed_data(bool) unsigned}, is MSB_data(bool) 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 tile_size(const Size_2D&) untiled}, have #DEFAULT_RESOLUTION_LEVELS resolution_levels(unsigned int) resolution levels}, use Precint-Component-Resolution-Level { progression_order(const std::string&) progression order}, have a 64x64 code_block_size(const Size_2D&) code block size} and use precinct sizes determined by the underlying codestream generation machinery. Once the JP2_Encoder is ready() ready} encode() 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.28

Constructor & Destructor Documentation

◆ JP2_Encoder()

◆ ~JP2_Encoder()

Member Function Documentation

◆ source() [1/2]

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.

Referenced by main(), and JP2_Encoder::read_stripe().

◆ source() [2/2]

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
pathnameThe image data source pathname.
Returns
This JP2_Encoder.

References JP2_Encoder::close(), and JP2_Encoder::Image_Source.

◆ destination() [1/2]

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&)

◆ destination() [2/2]

JP2_Encoder& destination ( const std::string &  pathname)
inline

Set the destination JP2 file pathname.

Parameters
pathnameThe destination file pathname string.
Returns
This JP2_Encoder.

◆ PDS_label_pathname() [1/2]

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&)

◆ PDS_label_pathname() [2/2]

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
pathnameThe 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*)

◆ image_data_location() [1/2]

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)

◆ image_data_location() [2/2]

JP2_Encoder& image_data_location ( std::streamoff  file_offset)
inline

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

Parameters
file_offsetThe byte offset where the image data starts in the source file.
Returns
This JP2_Encoder.

◆ image_bands() [1/2]

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)

◆ image_bands() [2/2]

JP2_Encoder& image_bands ( unsigned int  bands)
inline

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

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

◆ image_size() [1/2]

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&)

◆ image_size() [2/2]

JP2_Encoder & image_size ( const Size_2D size)

Set the size of the source PDS image data.

Parameters
sizeA Size_2D object containing the image width and height.
Returns
This JP2_Encoder.
Exceptions
invalid_argumentIf either the image width or height is zero.

References Size_2D::Height, JP2_Encoder::ID, JP2_Encoder::Image_Size, and Size_2D::Width.

◆ pixel_bytes() [1/2]

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)

Referenced by JP2_Encoder::pixel_bits().

◆ pixel_bytes() [2/2]

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_pixelThe number of bytes per pixel. Only the values 1, 2 and 4 are allowed.
Returns
This JP2_Encoder.
Exceptions
invalid_argumentIf the argument is not 1, 2 or 4.
length_errorIf the number of pixel bytes is less than are needed to hold the pixel bits.

References JP2_Encoder::ID, JP2_Encoder::Pixel_Bits, JP2_Encoder::Pixel_Bytes, and JP2_Encoder::signed_data().

◆ pixel_bits() [1/2]

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)

◆ pixel_bits() [2/2]

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_pixelThe number of bits per pixel. The maximum value is 32.
Returns
This JP2_Encoder.
Exceptions
invalid_argumentIf the argument is greater than 32.

References JP2_Encoder::ID, JP2_Encoder::Pixel_Bits, JP2_Encoder::pixel_bytes(), JP2_Encoder::Pixel_Bytes, and JP2_Encoder::signed_data().

◆ signed_data() [1/2]

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)

Referenced by JP2_Encoder::pixel_bits(), and JP2_Encoder::pixel_bytes().

◆ signed_data() [2/2]

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_signedtrue if the data is to be treated as signed; false otherwise.
Returns
This JP2_Encoder.

References JP2_Encoder::Pixel_Bits, JP2_Encoder::Pixel_Bytes, and JP2_Encoder::Signed_Data.

◆ MSB_data() [1/2]

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.

References high_endian_host(), and JP2_Encoder::Swap_Pixel_Bytes.

◆ MSB_data() [2/2]

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_MSBtrue if the source data is MSB ordered; false if the source data is LSB ordered.
Returns
This JP2_Encoder.

References high_endian_host(), and JP2_Encoder::Swap_Pixel_Bytes.

◆ swap_pixel_bytes() [1/2]

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)

◆ swap_pixel_bytes() [2/2]

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_datatrue if multi-byte pixels are to be reordered; false otherwise.
Returns
This JP2_Encoder.
See also
MSB_data(bool)

◆ line_prefix_bytes() [1/2]

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)

◆ line_prefix_bytes() [2/2]

JP2_Encoder& line_prefix_bytes ( unsigned int  prefix_bytes)
inline

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

Parameters
prefix_bytesThe number of line prefix bytes.
Returns
This JP2_Encoder.

◆ line_suffix_bytes() [1/2]

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)

◆ line_suffix_bytes() [2/2]

JP2_Encoder& line_suffix_bytes ( unsigned int  suffix_bytes)
inline

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

Parameters
suffix_bytesThe number of line suffix bytes.
Returns
This JP2_Encoder.

◆ tile_size() [1/2]

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&)

◆ tile_size() [2/2]

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
sizeA Size_2D object containing the JP2 tiles width and height.
Returns
This JP2_Encoder.

◆ resolution_levels() [1/2]

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.
See also
resolution_levels(unsigned int)

Referenced by JP2_Encoder::resolution_levels().

◆ resolution_levels() [2/2]

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_levelsThe total number of codestream resolution levels.
Returns
This JP2_Encoder.
Exceptions
invalid_argumentIf the specified number of resolution levels is greater than the MAX_RESOLUTION_LEVELS allowed.
See also
resolution_levels()

References JP2_Encoder::ID, JP2_Encoder::MAX_RESOLUTION_LEVELS, JP2_Encoder::Precinct_Sizes, JP2_Encoder::resolution_levels(), and JP2_Encoder::Resolution_Levels.

◆ quality_layers() [1/2]

unsigned int quality_layers ( ) const
inline

Get the number of codestream quality layers.

Returns
The number of codestream quality layers.
See also
quality_layers(unsigned int)

Referenced by JP2_Encoder::quality_layers().

◆ quality_layers() [2/2]

JP2_Encoder & quality_layers ( unsigned int  quality_layers)

Set the number of codestream quality layers.

The default number of quality layers is 1. The maximum number of layers is MAX_QUALITY_LAYERS (16384).

Parameters
quality_layersThe number of codestream quality layers. A value of zero will be set to 1.
Returns
This JP2_Encoder.
Exceptions
invalid_argumentIf the specified number of quality layers is greater than the maximum of the MAX_QUALITY_LAYERS allowed.

References JP2_Encoder::ID, JP2_Encoder::MAX_QUALITY_LAYERS, JP2_Encoder::quality_layers(), and JP2_Encoder::Quality_Layers.

◆ bit_rate() [1/2]

double bit_rate ( ) const
inline

Get the codestream compression bit-rate.

Returns
The codestream compression bit-rate. This will be zero if loss-less, reversible compression is to be used.
See also
bit_rate(double)

◆ bit_rate() [2/2]

JP2_Encoder & bit_rate ( double  rate)

Set the codestream compression bit-rate.

The compression bit-rate is expressed in terms of the ratio between the total number of compressed bits (including headers) and the product of the largest horizontal and vertical image component dimensions. This may also be thought of as the number of bits per pixel used in the compressed codestream.

Parameters
rateThe codestream compression bit-rate. A value of zero means that loss-less, reversible compression is to be used. A value less than zero is set to zero.
Returns
This JP2_Encoder.
See also
bit_rate()

References JP2_Encoder::Bit_Rate.

◆ progression_order() [1/2]

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&)

◆ progression_order() [2/2]

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
progressionA string specifying the progression order.
Returns
This JP2_Encoder.
Exceptions
invalid_argumentIf the progression order string is not four characters containing 'P', 'C', 'R' and 'L' in some order.

References JP2_Encoder::ID, and JP2_Encoder::Progression_Order.

◆ precinct_sizes() [1/2]

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)

◆ precinct_size() [1/2]

const Size_2D precinct_size ( unsigned int  resolution_level = 0) const

Get the precinct size for a given resolution level.

Parameters
resolution_levelThe 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_argumentIf the resolution level is greater than or equal to the number of resolution levels.
See also
resolution_levels(unsigned int)

References JP2_Encoder::ID, and JP2_Encoder::Precinct_Sizes.

◆ precinct_sizes() [2/2]

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
sizesA list (vector<Size_2D>) of precinct sizes in resolution number order.
Returns
This JP2_Encoder.
Exceptions
invalid_argumentIf any precinct size dimension is not a non-zero power of two.
See also
invalid_precinct_size(const std::vector<Size_2D>& sizes)

References JP2_Encoder::ID, JP2_Encoder::invalid_precinct_size(), JP2_Encoder::Precinct_Sizes, and JP2_Encoder::Resolution_Levels.

◆ precinct_size() [2/2]

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

Set the precinct size for a given resolution level.

Parameters
sizeA precinct size (Size_2D) for the resolution level.
resolution_levelThe resoultion level index (0-based) for which the precinct size is to be obtained.
Exceptions
invalid_argumentIf the resolution level is greater than or equal to the number of resolution levels.
See also
resolution_levels(unsigned int)

References Size_2D::Height, JP2_Encoder::ID, UA::HiRISE::power_of_2(), JP2_Encoder::Precinct_Sizes, JP2_Encoder::Resolution_Levels, and Size_2D::Width.

◆ code_block_size() [1/2]

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&)

◆ code_block_size() [2/2]

JP2_Encoder & code_block_size ( const Size_2D size)

Set the code block size.

Parameters
sizeThe size (Size_2D) of the code block.
Returns
This JP2_Encoder.
Exceptions
invalid_argumentIf either dimension is 0 or greater than 64.

References JP2_Encoder::Code_Block_Size, Size_2D::Height, JP2_Encoder::ID, and Size_2D::Width.

◆ added_boxes()

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.

◆ add_box()

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
boxA JP2_Box pointer.
Returns
This JP2_Encoder.

References JP2_Encoder::Added_Boxes.

◆ remove_box()

bool remove_box ( JP2_Box box)

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

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

References JP2_Encoder::Added_Boxes.

◆ producer_UUID() [1/2]

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*)

◆ producer_UUID() [2/2]

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
idAn 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.
Returns
This JP2_Encoder.

References JP2_Encoder::Producer_UUID, and JP2_Encoder::UUID_SIZE.

◆ comment() [1/2]

std::string comment ( ) const
inline

Get the codestream comment.

Returns
The string that will be added as a comment to the codestream. This will be an empty string if no comment is specified.
See also
comment(const std::string& text)

◆ comment() [2/2]

JP2_Encoder& comment ( const std::string &  text)
inline

Set comment text to be added to the codestream.

Parameters
textA string to be added to the codestream as a comment. If the string is empty no comment will be added to the codestream.
Returns
This JP2_Encoder.
See also
comment()

◆ ready()

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

References Size_2D::Height, JP2_Encoder::Image_Bands, JP2_Encoder::Image_Size, JP2_Encoder::Image_Source, JP2_Encoder::JP2_Pathname, JP2_Encoder::Pixel_Bytes, and Size_2D::Width.

Referenced by JP2_Encoder::open().

◆ reasons()

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.

References Size_2D::Height, JP2_Encoder::Image_Bands, JP2_Encoder::Image_Size, JP2_Encoder::Image_Source, JP2_Encoder::JP2_Pathname, JP2_Encoder::Pixel_Bytes, and Size_2D::Width.

Referenced by JP2_Encoder::open().

◆ needs()

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.
@return A bit flag value.

References Size_2D::Height, JP2_Encoder::Image_Bands, JP2_Encoder::Image_Size, JP2_Encoder::Image_Source, JP2_Encoder::JP2_Pathname, JP2_Encoder::NEEDS_DESTINATION, JP2_Encoder::NEEDS_IMAGE, JP2_Encoder::NEEDS_SOURCE, JP2_Encoder::Pixel_Bytes, and Size_2D::Width.

◆ encoder_error()

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.

Referenced by main().

◆ encode()

long long encode ( )

◆ open()

void open ( )

◆ write_header()

long long write_header ( )

◆ write_user_boxes()

long long write_user_boxes ( )

Write user specified boxes to the JP2 file.

If a PDS label filename has been specified a UUID Info box containing a UUID box with producer signature and a URL box with a relative file reference to the PDS label filename is written to the JP2 file.

Returns
The number of bytes written to the JP2 file.

References JP2_Encoder::Added_Boxes, file_name(), JP2_Encoder::PDS_Label_Pathname, JP2_Encoder::Producer_UUID, JP2_Box::type_code(), JP2_Encoder::URL_BOX_NAME, JP2_Encoder::UUID_BOX_NAME, JP2_Encoder::UUID_INFO_BOX_NAME, JP2_Encoder::UUID_SIZE, and JP2_Encoder::write_header().

Referenced by JP2_Encoder::encode().

◆ write_codestream()

long long write_codestream ( )

◆ incremental_flush_bytes() [1/2]

JP2_Encoder& incremental_flush_bytes ( long long  bytes)
inline

Set the rate at which compressed image data will be written to the output JP2 file.

Incremental codestream flushing is when the compressed image data that has accumulated in memory is periodically written to the output JP2 file during the process of codestream generation. Incremental codestream flushing is desirable to avoid retaining the entire codestream in memory when a large image is being processed; the memory requirements to hold the entire codestream may be more than the system can provide. The rate of codestream flushing is controlled by the number of image lines that have been compressed since the last flush or the start of compression. Since the issue of incremental codestream flushing is the amount of system memory that is used this method allows the rate to be expressed in terms of bytes. This should be as large as possible, or zero to disable incremental flushing, to allow for the most efficient compression operations as possible.

However, incremental flushing may not actually occur at the requested rate, or may not occur at all, depending on the progression order and other codestream organization issues. In addition, incremental flushing may generate additional JPEG2000 tile-part segments beyond the initial tile-part segment for each tile, and each of these additional tile-parts will require that additional space be reserved in the tile-part length segments of the main header. Since the actual number of tile-parts generated by incremental flushing depends on the data and thus will not be known until the codestream generation has been completed - at which time the reserved space for the tile-part length segments are overwritten with the actual location information

  • an estimate of the number of tile-parts is necessary. If the actual number of tile-parts is less than what has been reserved empty tile parts will be provided as place holders. N.B.: If the actual number is larger than what has been reserved the generation of the codestream will fail.

The default flush rate is set at compile time by the value of the INCREMENTAL_FLUSH_BYTES symbol.

Parameters
bytesThe requested maximum amount of memory to use in generating the compressed image data codestream before the codestream will be flushed to the output JP2 file. If zero incremental flushing is disabled.
Returns
This JP2_Encoder.
See also
incremental_flush_lines()

◆ incremental_flush_bytes() [2/2]

long long incremental_flush_bytes ( ) const
inline

Get the rate at which compressed image data will be written to the output JP2 file.

Returns
The requested maximum amount of memory to use in generating the compressed image data codestream before the codestream will be flushed to the output JP2 file. If zero incremental flushing is disabled.

Referenced by JP2_Encoder::incremental_flush_lines().

◆ incremental_flush_lines() [1/2]

JP2_Encoder & incremental_flush_lines ( unsigned int  lines)

Set the rate at which compressed image data will be written to the output JP2 file.

The incremental flush rate is set in terms of the number of image lines to compress before flushing the codestream from memory to the JP2 file. This will set the maximum flush bytes.

Warning: Since the determining the maximum flush bytes from a number of image lines depends on the image width and number of pixel bytes if these have not yet been set the maximum flush bytes will be set to zero thus disabling incremental flushing.

Parameters
linesThe number of image lines to compress before flushing the codestream. If zero incremental flushing is disabled.

References JP2_Encoder::Image_Size, JP2_Encoder::incremental_flush_bytes(), JP2_Encoder::Pixel_Bytes, and Size_2D::Width.

◆ incremental_flush_lines() [2/2]

int incremental_flush_lines ( ) const

Get the rate at which compressed image data will be written to the output JP2 file.

The incremental flush rate, in terms of the number of image lines, is determined by the requested maximum flush bytes. If the maximum flush bytes is zero or the size of an image band is greater than or equal to the maximum flush bytes the flush lines will be zero (no incremental flusing will occur). Otherwise the number of flush lines is set to the height of an image tile. If number of bytes in these image lines for a single band is greater than the maximum flush bytes the number of flush lines is reduced by 1024 until the number of bytes in the lines is less than or equal to the maximum flush bytes.

Returns
The rate, in terms of image lines, at which the compressed image data codestream will be requested to be flushed to the output JP2 file. If zero incremental flushing is disabled.

References Size_2D::Height, JP2_Encoder::Image_Size, JP2_Encoder::Incremental_Flush_Bytes, JP2_Encoder::Pixel_Bytes, JP2_Encoder::Tile_Size, and Size_2D::Width.

Referenced by JP2_Encoder::write_codestream(), and JP2_Encoder::write_header().

◆ close()

long long close ( )

◆ invalid_precinct_size()

int invalid_precinct_size ( const std::vector< Size_2D > &  sizes)

Check for valid precinct sizes.

Valid precinct sizes are non-zero powers of 2.

Parameters
sizesA vector of precinct Size_2D values.
Returns
If all sizes are valid, 0. Otherwise the vector entry number (i.e. index + 1) of the first invalid entry encountered.

References UA::HiRISE::power_of_2().

Referenced by JP2_Encoder::precinct_sizes().

◆ read_stripe() [1/2]

void read_stripe ( std::istream &  source,
int  band,
int  line,
int  lines,
kdu_int16 *  buffer 
)
protected

Fill an image data buffer with pixel data from a source stream.

The lines of source image data starting with the specified line of the specified band are read into the buffer as a contiguous sequence of bytes.

Parameters
sourceAn istream that has been opened on the source file.
bandThe index of the image band from which pixel data is to be read.
lineThe starting index of the image line from which pixel data it to be read.
linesThe number of image lines to read.
bufferBuffer storage to hold at least lines * image_width pixels where each pixel is stored as a 16-bit signed integer.

References Size_2D::Height, JP2_Encoder::ID, JP2_Encoder::Image_Offset, JP2_Encoder::Image_Size, JP2_Encoder::Line_Prefix_Bytes, JP2_Encoder::Line_Suffix_Bytes, JP2_Encoder::Pixel_Bits, JP2_Encoder::Pixel_Bytes, JP2_Encoder::Signed_Data, JP2_Encoder::source(), JP2_Encoder::Swap_Pixel_Bytes, and Size_2D::Width.

Referenced by JP2_Encoder::write_codestream().

◆ read_stripe() [2/2]

void read_stripe ( std::istream &  source,
int  band,
int  line,
int  lines,
kdu_int32 *  buffer 
)
protected

Fill an image data buffer with pixel data from a source stream.

The lines of source image data starting with the specified line of the specified band are read into the buffer as a contiguous sequence of bytes.

Parameters
sourceAn istream that has been opened on the source file.
bandThe index of the image band from which pixel data is to be read.
lineThe starting index of the image line from which pixel data it to be read.
linesThe number of image lines to read.
bufferBuffer storage to hold at least lines * image_width pixels where each pixel is stored as a 32-bit signed integer.

References Size_2D::Height, JP2_Encoder::ID, JP2_Encoder::Image_Offset, JP2_Encoder::Image_Size, JP2_Encoder::Line_Prefix_Bytes, JP2_Encoder::Line_Suffix_Bytes, JP2_Encoder::Pixel_Bits, JP2_Encoder::Pixel_Bytes, JP2_Encoder::Signed_Data, JP2_Encoder::source(), swap_bytes(), JP2_Encoder::Swap_Pixel_Bytes, and Size_2D::Width.

Member Data Documentation

◆ ID

const char *const ID
static

◆ DEFAULT_RESOLUTION_LEVELS

const unsigned int DEFAULT_RESOLUTION_LEVELS = 6
static

Default number of resolution levels.

Referenced by JP2_Encoder::write_header().

◆ MAX_RESOLUTION_LEVELS

const unsigned int MAX_RESOLUTION_LEVELS = 32
static

Maximum number of resolution levels.

Referenced by JP2_Encoder::resolution_levels().

◆ MAX_QUALITY_LAYERS

const unsigned int MAX_QUALITY_LAYERS = 16384
static

Maximum number of quality layers.

Referenced by JP2_Encoder::quality_layers().

◆ UUID_INFO_BOX_NAME

const char *const UUID_INFO_BOX_NAME = "uinf"
static

PDS label reference information UUID Info JP2 container box name.

Referenced by JP2_Encoder::write_user_boxes().

◆ UUID_BOX_NAME

const char *const UUID_BOX_NAME = "ulst"
static

Data provider UUID JP2 box name.

Referenced by JP2_Encoder::write_user_boxes().

◆ UUID_SIZE

const int UUID_SIZE = 16
static

Size of the UUID data content.

Referenced by JP2_Encoder::producer_UUID(), and JP2_Encoder::write_user_boxes().

◆ URL_BOX_NAME

const char *const URL_BOX_NAME = "url "
static

PDS label relative filename URL JP2 box name.

Referenced by JP2_Encoder::write_user_boxes().

◆ MIN_STRIPE_HEIGHT

const int MIN_STRIPE_HEIGHT = 256
static

Image data stripe minimum and maximum number of lines.

Referenced by JP2_Encoder::write_codestream().

◆ MAX_STRIPE_HEIGHT

const int MAX_STRIPE_HEIGHT = 8192
static

◆ NEEDS_SOURCE

const int NEEDS_SOURCE = 1 << 0
static

What the encoder needs to do its job.

See also
needs() const

Referenced by JP2_Encoder::needs().

◆ NEEDS_DESTINATION

const int NEEDS_DESTINATION = 1 << 1
static

Referenced by JP2_Encoder::needs().

◆ NEEDS_IMAGE

const int NEEDS_IMAGE = 1 << 2
static

Referenced by JP2_Encoder::needs().

◆ ENCODER_EXCEPTION

const int ENCODER_EXCEPTION = 66
static

JP2_Encoder_Error exception signal value.

Referenced by JP2_Encoder::write_codestream().

◆ Image_Source

std::string Image_Source
protected

◆ JP2_Pathname

std::string JP2_Pathname
protected

Image destination pathname.

Referenced by JP2_Encoder::needs(), JP2_Encoder::open(), JP2_Encoder::ready(), and JP2_Encoder::reasons().

◆ Image_Offset

std::streamoff Image_Offset
protected

Image data location as a byte offset within the source file.

Referenced by JP2_Encoder::read_stripe().

◆ Image_Bands

unsigned int Image_Bands
protected

◆ Image_Size

Size_2D Image_Size
protected

◆ Line_Prefix_Bytes

unsigned int Line_Prefix_Bytes
protected

The number of bytes preceeding and following each line of pixel bytes.

The line prefix and suffix bytes are to be skipped when the image data is being read.

Referenced by JP2_Encoder::read_stripe().

◆ Line_Suffix_Bytes

unsigned int Line_Suffix_Bytes
protected

◆ Pixel_Bytes

unsigned int Pixel_Bytes
protected

◆ Pixel_Bits

unsigned int Pixel_Bits
protected

◆ Signed_Data

bool Signed_Data
protected

Whether pixel data is to be treated as signed.

Referenced by JP2_Encoder::read_stripe(), JP2_Encoder::signed_data(), and JP2_Encoder::write_header().

◆ Added_Boxes

JP2_Box::JP2_Box_List Added_Boxes
protected

◆ PDS_Label_Pathname

std::string PDS_Label_Pathname
protected

PDS label file pathname to be placed in a UUID Info URL box.

Referenced by JP2_Encoder::write_user_boxes().

◆ Producer_UUID

unsigned char* Producer_UUID
protected

The UUID to be placed in a UUID List box inside a UUID Info box.

Referenced by JP2_Encoder::producer_UUID(), JP2_Encoder::write_user_boxes(), and JP2_Encoder::~JP2_Encoder().

◆ Comment

std::string Comment
protected

Comment segment to be added to the codestream.

Referenced by JP2_Encoder::write_header().

◆ Swap_Pixel_Bytes

bool Swap_Pixel_Bytes
protected

Whether pixel bytes should be reordered before be encoded.

Referenced by JP2_Encoder::MSB_data(), and JP2_Encoder::read_stripe().

◆ Resolution_Levels

unsigned int Resolution_Levels
protected

The number of resolution levels to encode.

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

Referenced by JP2_Encoder::precinct_size(), JP2_Encoder::precinct_sizes(), JP2_Encoder::resolution_levels(), and JP2_Encoder::write_header().

◆ Quality_Layers

unsigned int Quality_Layers
protected

◆ Bit_Rate

double Bit_Rate
protected

◆ Progression_Order

std::string Progression_Order
protected

The codestream progression order to be used.

Referenced by JP2_Encoder::progression_order(), and JP2_Encoder::write_header().

◆ Tile_Size

Size_2D Tile_Size
protected

Tile size for codestream structure organization.

Referenced by JP2_Encoder::incremental_flush_lines(), and JP2_Encoder::write_header().

◆ Precinct_Sizes

std::vector<Size_2D> Precinct_Sizes
protected

Precinct sizes for codestream structure organization within tiles.

Referenced by JP2_Encoder::precinct_size(), JP2_Encoder::precinct_sizes(), JP2_Encoder::resolution_levels(), and JP2_Encoder::write_header().

◆ Code_Block_Size

Size_2D Code_Block_Size
protected

Code block size for codestream packet encoding within precincts.

Referenced by JP2_Encoder::code_block_size(), and JP2_Encoder::write_header().

◆ Incremental_Flush_Bytes

long long Incremental_Flush_Bytes
protected

The documentation for this class was generated from the following files: