HiRISE
 PDS_JP2

Macros | Functions | Variables
JP2_to_PDS.cc File Reference
#include "Dimensions.hh"
#include "PDS_Converters.hh"
#include "JP2_Decoder.hh"
#include "Files.hh"
#include "endian.hh"
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <cctype>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <stdexcept>
Include dependency graph for JP2_to_PDS.cc:

Macros

#define _VERSION_   " "
 
#define FILESYSTEM_PATHNAME_DELIMITER   '/'
 

Functions

void usage (int exit_status=BAD_SYNTAX, bool list_descriptions=false)
 JP2_to_PDS command line syntax and usage. More...
 
int main (int argument_count, char **arguments)
 JP2_to_PDS application. More...
 

Variables

const char *const JP2_EXTENSION = ".JP2"
 The default filename extension for the JPEG2000 JP2 file. More...
 
const char *const LABEL_EXTENSION = ".LBL"
 The default filename extension for the PDS/JP2 label file. More...
 
const char *const PDS_IMAGE_EXTENSION = ".IMG"
 The default filename extension for the PDS file. More...
 
const int DEFAULT_DATA_ORDER = 1
 The default data order if it can't be determined from the source. More...
 
const int SUCCESS = 0
 Exit status values. More...
 
const int BAD_SYNTAX = 1
 
const int INVALID_ARGUMENT = 11
 
const int PDS_LABEL_ERROR = 12
 
const int NO_IMAGE_DATA = 13
 
const int LABEL_INCONSISTENCY = 14
 
const int LOGIC_ERROR = 19
 
const int NO_INPUT_FILE = 20
 
const int EXISTING_OUTPUT_FILE = 21
 
const int IO_FAILURE = 29
 
const int PVL_ERROR = 30
 
const int DECODER_ERROR = JP2_Decoder::DECODER_EXCEPTION
 
const int UNKNOWN_ERROR = -1
 
const char * ID
 Application identification name with source code version and date. More...
 
const char * SOFTWARE_NAME_PARAMETER = "SOFTWARE_NAME"
 The label parameter to have its value set to the ID. More...
 
char * Program_Name
 The runtime command name. More...
 
const char PATHNAME_DELIMITER = FILESYSTEM_PATHNAME_DELIMITER
 Host filesystem pathname delimiter. More...
 
const int LABEL_WIDTH = 24
 Listing format widths. More...
 
const int VALUE_WIDTH = 9
 

Macro Definition Documentation

◆ _VERSION_

#define _VERSION_   " "

◆ FILESYSTEM_PATHNAME_DELIMITER

#define FILESYSTEM_PATHNAME_DELIMITER   '/'

Function Documentation

◆ usage()

void usage ( int  exit_status = BAD_SYNTAX,
bool  list_descriptions = false 
)

JP2_to_PDS command line syntax and usage.

Command line syntax:

JP2_to_PDS [Options] [-Input | -Jp2] <pathname>

Command line options:

-Input | -Jp2 <pathname>

The pathname of the input JP2 file.

Default: The PDS label file pathname with a JP2_EXTENSION.

-LAbel <pathname>

The pathname of the input PDS label file.

Default: The JP2 source PDS label URL if present or the input JP2 pathname with a LABEL_EXTENSION.

-Output | -Pds <pathname>

The pathname of the output PDS file.

Default: The input JP2 file pathname with a PDS_IMAGE_EXTENSION.

-No_output

No ouput file will be written. The input files will be examined and prepared for conversion with all the reports listed. This is a convenient way to see the source file structure and check that the expected output will be produced without having to process the files.

Default: Output is produced.

-Force

If the output file already exists, it will be overwritten.

Default: Do not overwrite an existing file.

-Area <origin_x>,<origin_y>,<extent_x>,<extent_y>

An area of the image to be selected for decompression. The area is specified relative to the image at full resolution, before any resolution level selection size reduction is applied. If the area selected extends beyond the width (x) or height (y) of the image size the area is clipped to corresponding limit. If the origin of the area falls outside the image boundaries no output will be generated; an empty image will not be produced.

Default: The entire image.

-Resolution <level>

The JPEG2000 codestream may provide access to the image at multiple resolution levels. The image is always available at full resolution; level 1. The next level is half resolution, then half of that, etc.; i.e. the effective image size at resolution level L is the full resolution size divided by 2**(L-1). If the selected resolution level is greater than the number of resolution levels available in the JP2 source codestream the image will be rendered at the smallest size.

Default: Full resolution level 1.

-Lsb | -Msb

Normally the image data values are treated as MSB or LSB ordered based on information from the source PDS label file: If the SAMPLE_TYPE parameter is present and its value contains the "MSB" string, the image data is treated as MSB ordered; if the value contains the "LSB" string the data is treated as LSB ordered. This option determines the effective byte order of multi-byte image data values regardless of the PDS label parameter value.

Default: Pixel data of unknown data order is MSB.

-Help

Prints this usage description.

Parameters
exit_statusThis method always result in program exit. If the exit status value is not specified the BAD_SYNTAX value will be used.
list_descriptionsIf true, long option descriptions will be listed; otherwise only the brief option syntax is listed.
See also
main(int, char**)

References DEFAULT_DATA_ORDER, JP2_EXTENSION, LABEL_EXTENSION, PDS_IMAGE_EXTENSION, and Program_Name.

Referenced by main().

◆ main()

int main ( int  argument_count,
char **  arguments 
)

JP2_to_PDS application.

Converts a JP2 image data file with a detached PDS label file to a PDS image file having a label attached to uncompressed image data.

Files:

An input JP2 file and associated PDS label file are required. If only a -Label pathname is provided it is used to determine the JP2 file pathname by replacing the extension, if any, with the JP2_EXTENSION. If the -Label pathname is not specified it is determined from the JP2 PDS label URL. If no URL is found the label file pathname is determined by replacing the JP2 file pathname extension, if any, with the LABEL_EXTENSION. If no -Output pathname for the PDS file is specified it is determined by replacing the JP2 pathname extension, if any, with the PDS_IMAGE_EXTENSION. If a file at the output pathname exists and the -Force option has not been specified the program will exit (with EXISTING_OUTPUT_FILE status); a warning will be provided in this case if the -Force option has been specified.

A report listing the input and output files, the image data specifications, the JP2 data producer signature if present, the selected image area and rendering resolution and resultant output image size will be written to stdout before the input files are processed to generate the output file.

JP2 -

A JP2_Decoder object is instantiated and opened on the input JP2 file. The JPEG2000 codestream is checked by the decoder to be sure it meets the requirment that all image data components (bands) are have the same size, pixel bits and data signedness; if they are not the same the program will exit with a LOGIC_ERROR status. The decoder is configured with the rendering -Resolution level and image -Area selection. This will result in the resolution level being limited to the maximum number of resolution levels present in the JP2 source, and the selected image area clipped to the image extent. If the selected image area is entirely outside the image boundaries the program will exit with a LOGIC_ERROR status.

PDS label -

A PDS_Converter object instantiated on the PDS label file is used to convert the input file PDS label to the new attached label. The selection of the appropriate PDS label converter is done by each registered PDS label converter examining the file's contents and deciding if it is suitable for handling the conversion; the first one to indicate that it is appropriate for the input file is used. Product specific converters are queried first until finally the {Generic_PDS_Converter} is tried. If the label converter is unable to locate a group of parameters in the label that describes the IMAGE data block the program will exit with a #PDS_LABEL_ERROR status. The JP2 decoder is then configured to reorder multi-byte pixels if it is found from the user specified order, the label converter or the default that the source image data order is not the same as the host system native data order. If the number of image bands and pixel bits obtained from the label converter does not match the values obtained from the JP2 decoder the program will exit with a #LABEL_INCONSISTENCY status. Inconsitency of image size will be reported with a warning, but the output PDS label will have the correct values set, which are set appropriately if an image region or less than full resolution rendering is selected in any case. A warning is also provided if the image data signedness from the PDS label does not match that from the JP2 file, but this has no effect on the output PDS label. Before the output file is generated a check is made that the host filesystem is capable of storing a file of the size to be produced. If it appears that it can not handle very large files the program will exit with an #IO_FAILURE status. Note: Before the PDS label converter is requested to write the new label file the SOFTWARE_NAME parameter in the label, if it exists, is updated with the application identification. The PDS label converter is informed of the selected image area and resolution and requested to write the converted label to the output file. Then the JP2 decoder is requested to appended the rendered image pixel data to this file. Exit status values:

SUCCESS
The application completed successfully.
BAD_SYNTAX
There was a syntax problem in the command line. A description of the problem followed by a brief command line syntax summary will be written to stdout.
INVALID_ARGUMENT
An invalid software function argument exception was encountered. A description of the error will be written to stdout. This error may indicate a bug in the software so the complete error description should be reported to the application software development contact.
PDS_LABEL_ERROR
There was a problem with the PDS label. A description of the problem will be written to stdout. This problem is typically the result of specifying an input file for processing that is not, or is not associated with, a valid PDS label file.
NO_IMAGE_DATA
The PDS label indicates that the file does not contain any image data; in this case check the label for a complete set of valid IMAGE parameters. Or an -Area was specified that is empty or is outside the image boundaries; in this case the error message will describe the problem.
LABEL_INCONSISTENCY
The image data characterization from the PDS label does not match the image data characterization from the JP2 file. Check that the correct files are being used together.
LOGIC_ERROR
A logic error was detected in the software. A description of the error will be written to stdout. This error may indicate that the JP2 decoder detected a problem with the file format, which will be reported to stdout. If, however, a software but is suspected the complete error description should be reported to the application software development contact.
NO_INPUT_FILE
No input file was specified on the command line or the PDL label or JP2 file could not be accessed from the filesystem. Check that the input files exists at the specified pathname and that their permissions allow read access to the user.
EXISTING_OUTPUT_FILE
A PDS image file at the intended output pathname already exists. Use the -Force option an existing file is to be overwritten.
IO_FAILURE
A filesystem I/O failure has occurred. A likely cause of the failure is insufficient user permissions to write the output file or running out of space on the storage volume. This exit status will also occur if the program detects that the host system is not capable of storing a file of the expected size, including the PDS label and decompressed image data.
PVL_ERROR
An exception occurred while managing the Parameter Value Language of a PDS label. A description of the error will be written to stdout. This may be due to an invalid PDS label that can not be parsed. If the input file label is valid then the complete error description should be reported to the application software development contact.
DECODER_ERROR
An exception occurred while decoding the JPEG2000 codestream to the output image data. This may be due to the exhaustion of system resources, such as available memory or storage capacity.
UNKNOWN_ERROR
An unanticipated exception occurred. This error may indicate a bug in the software so the complete error description should be reported to the application software development contact.
Parameters
argument_countThe number of command line arguments.
argumentsThe array of command line arguments.
See also
usage(int, bool)
Author
Bradford Castalia, UA/HiROC
Version
1.21

References Size_2D::area(), UA::HiRISE::converter_for(), JP2_Decoder::decode(), JP2_Decoder::decoder_error(), DECODER_ERROR, DEFAULT_DATA_ORDER, JP2_Decoder::destination(), EXISTING_OUTPUT_FILE, PIRL::file_basename(), PIRL::file_directory(), PIRL::file_exists(), PIRL::file_is_directory(), PIRL::file_is_readable(), PIRL::file_name(), PIRL::file_pathname(), PIRL::file_size(), Size_2D::Height, PIRL::high_endian_host(), PIRL::hostname(), ID, Image_Data_Block::image_bands(), JP2_Decoder::image_bands(), PDS_Converter::image_data(), PDS_Data::IMAGE_DATA_BLOCK_NAME, Image_Data_Block::image_height(), JP2_Decoder::image_height(), JP2_Decoder::image_region(), Image_Data_Block::image_width(), JP2_Decoder::image_width(), INVALID_ARGUMENT, IO_FAILURE, JP2_EXTENSION, LABEL_EXTENSION, LABEL_INCONSISTENCY, PDS_Converter::label_size(), LABEL_WIDTH, LOGIC_ERROR, Image_Data_Block::MSB_data(), NO_IMAGE_DATA, NO_INPUT_FILE, JP2_Decoder::open(), PDS_Data::parameter_value(), PDS_IMAGE_EXTENSION, PDS_LABEL_ERROR, Image_Data_Block::pixel_bits(), JP2_Decoder::pixel_bits(), Image_Data_Block::pixel_bytes(), JP2_Decoder::pixel_bytes(), JP2_Decoder::producer_UUID(), PDS_Converter::product_names(), Program_Name, PVL_ERROR, JP2_Decoder::rendered_height(), JP2_Decoder::rendered_width(), JP2_Decoder::resolution_level(), JP2_Decoder::resolution_levels(), Image_Data_Block::signed_data(), JP2_Decoder::signed_data(), SOFTWARE_NAME_PARAMETER, JP2_Decoder::source(), SUCCESS, PIRL::swap_bytes(), JP2_Decoder::swap_pixel_bytes(), UNKNOWN_ERROR, JP2_Decoder::URL(), usage(), UUID_SIZE, VALUE_WIDTH, Size_2D::Width, PDS_Converter::write_PDS_label(), Point_2D::X, and Point_2D::Y.

Variable Documentation

◆ JP2_EXTENSION

const char* const JP2_EXTENSION = ".JP2"

The default filename extension for the JPEG2000 JP2 file.

Referenced by main(), and usage().

◆ LABEL_EXTENSION

const char* const LABEL_EXTENSION = ".LBL"

The default filename extension for the PDS/JP2 label file.

Referenced by main(), and usage().

◆ PDS_IMAGE_EXTENSION

const char* const PDS_IMAGE_EXTENSION = ".IMG"

The default filename extension for the PDS file.

Referenced by main(), and usage().

◆ DEFAULT_DATA_ORDER

const int DEFAULT_DATA_ORDER = 1

The default data order if it can't be determined from the source.

Positive is MSB; negative is LSB.

Referenced by main(), and usage().

◆ SUCCESS

const int SUCCESS = 0

Exit status values.

Referenced by main().

◆ BAD_SYNTAX

const int BAD_SYNTAX = 1

◆ INVALID_ARGUMENT

const int INVALID_ARGUMENT = 11

Referenced by main().

◆ PDS_LABEL_ERROR

const int PDS_LABEL_ERROR = 12

Referenced by main().

◆ NO_IMAGE_DATA

const int NO_IMAGE_DATA = 13

Referenced by main().

◆ LABEL_INCONSISTENCY

const int LABEL_INCONSISTENCY = 14

Referenced by main().

◆ LOGIC_ERROR

const int LOGIC_ERROR = 19

Referenced by main().

◆ NO_INPUT_FILE

const int NO_INPUT_FILE = 20

Referenced by main().

◆ EXISTING_OUTPUT_FILE

const int EXISTING_OUTPUT_FILE = 21

Referenced by main().

◆ IO_FAILURE

const int IO_FAILURE = 29

Referenced by main().

◆ PVL_ERROR

const int PVL_ERROR = 30

Referenced by main().

◆ DECODER_ERROR

const int DECODER_ERROR = JP2_Decoder::DECODER_EXCEPTION

Referenced by main().

◆ UNKNOWN_ERROR

const int UNKNOWN_ERROR = -1

Referenced by main().

◆ ID

const char* ID
Initial value:
=
"JP2_to_PDS"
"(1.21 2013/01/29 19:06:32)"
#define _VERSION_
Definition: JP2_to_PDS.cc:107

Application identification name with source code version and date.

Referenced by main().

◆ SOFTWARE_NAME_PARAMETER

const char* SOFTWARE_NAME_PARAMETER = "SOFTWARE_NAME"

The label parameter to have its value set to the ID.

Referenced by main().

◆ Program_Name

char* Program_Name

The runtime command name.

Referenced by main(), and usage().

◆ PATHNAME_DELIMITER

const char PATHNAME_DELIMITER = FILESYSTEM_PATHNAME_DELIMITER

Host filesystem pathname delimiter.

◆ LABEL_WIDTH

const int LABEL_WIDTH = 24

Listing format widths.

Referenced by main().

◆ VALUE_WIDTH

const int VALUE_WIDTH = 9

Referenced by main().