HiRISE
 PDS_JP2

JP2_Encoder.hh
Go to the documentation of this file.
1/* JP2_Encoder
2
3HiROC CVS ID: JP2_Encoder.hh,v 1.28 2019/03/26 20:51:11 guym Exp
4
5Copyright (C) 2006-2007 Arizona Board of Regents on behalf of the
6Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
7the University of Arizona.
8
9This library is free software; you can redistribute it and/or modify it
10under the terms of the GNU Lesser General Public License, version 2.1,
11as published by the Free Software Foundation.
12
13This library is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License
19along with this library; if not, write to the Free Software Foundation,
20Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21*/
22
23#ifndef _JP2_Encoder_
24#define _JP2_Encoder_
25
26#include "Dimensions.hh"
27#include "JP2_Box.hh"
28
29// Kakadu
30#include "jp2.h"
31using namespace kdu_supp;
32
33#include <string>
34#include <iosfwd>
35#include <vector>
36
37namespace UA
38{
39namespace HiRISE
40{
41// Forward reference.
42class JP2_Encoder_Error;
43
84{
85public:
86/*==============================================================================
87 Constants:
88*/
90static const char* const
92
94static const unsigned int
97static const unsigned int
100static const unsigned int
102
104static const char* const
107static const char* const
110static const int
113static const char* const
115
117static const int
120
125static const int
129
131static const int
133
134/*==============================================================================
135 Constructors:
136*/
137JP2_Encoder ();
138
139// Destructor.
140~JP2_Encoder ();
141
142/*==============================================================================
143 Accessors:
144*/
150std::string source () const
151 {return Image_Source;}
152
162JP2_Encoder& source (const std::string& pathname);
163
170std::string destination () const
171 {return JP2_Pathname;}
172
178JP2_Encoder& destination (const std::string& pathname)
179 {JP2_Pathname = pathname; return *this;}
180
187std::string PDS_label_pathname () const
188 {return PDS_Label_Pathname;}
189
202JP2_Encoder& PDS_label_pathname (const std::string& pathname)
203 {PDS_Label_Pathname = pathname; return *this;}
204
211std::streamoff image_data_location () const
212 {return Image_Offset;}
213
220JP2_Encoder& image_data_location (std::streamoff file_offset)
221 {Image_Offset = file_offset; return *this;}
222
228unsigned int image_bands () const
229 {return Image_Bands;}
230
236JP2_Encoder& image_bands (unsigned int bands)
237 {Image_Bands = bands; return *this;}
238
244const Size_2D image_size () const
245 {return Image_Size;}
246
255JP2_Encoder& image_size (const Size_2D& size);
256
262unsigned int pixel_bytes () const
263 {return Pixel_Bytes;}
264
278JP2_Encoder& pixel_bytes (unsigned int bytes_per_pixel);
279
285unsigned int pixel_bits () const
286 {return Pixel_Bits;}
287
302JP2_Encoder& pixel_bits (unsigned int bits_per_pixel);
303
310bool signed_data () const
311 {return Signed_Data;}
312
325JP2_Encoder& signed_data (bool data_is_signed);
326
334bool MSB_data () const;
335
348JP2_Encoder& MSB_data (bool data_is_MSB);
349
357bool swap_pixel_bytes () const
358 {return Swap_Pixel_Bytes;}
359
369 {Swap_Pixel_Bytes = swap_data; return *this;}
370
377unsigned int line_prefix_bytes () const
378 {return Line_Prefix_Bytes;}
379
386JP2_Encoder& line_prefix_bytes (unsigned int prefix_bytes)
387 {Line_Prefix_Bytes = prefix_bytes; return *this;}
388
395unsigned int line_suffix_bytes () const
396 {return Line_Suffix_Bytes;}
397
404JP2_Encoder& line_suffix_bytes (unsigned int suffix_bytes)
405 {Line_Suffix_Bytes = suffix_bytes; return *this;}
406
413const Size_2D tile_size () const
414 {return Tile_Size;}
415
426 {Tile_Size = size; return *this;}
427
436unsigned int resolution_levels () const
437 {return Resolution_Levels;}
438
452
458unsigned int quality_layers () const
459 {return Quality_Layers;}
460
473
480double bit_rate () const
481 {return Bit_Rate;}
482
497JP2_Encoder& bit_rate (double rate);
498
504std::string progression_order () const
505 {return Progression_Order;}
506
527JP2_Encoder& progression_order (const std::string& progression);
528
536const std::vector<Size_2D> precinct_sizes () const
537{return Precinct_Sizes;}
538
549 (unsigned int resolution_level = 0) const;
550
569 (const std::vector<Size_2D>& sizes);
570
581 (const Size_2D& size, unsigned int resolution_level = 0);
582
589 {return Code_Block_Size;}
590
598JP2_Encoder& code_block_size (const Size_2D& size);
599
609
620
629bool remove_box (JP2_Box* box);
630
639const unsigned char* producer_UUID () const
640 {return Producer_UUID;}
641
658JP2_Encoder& producer_UUID (const unsigned char* id);
659
666std::string comment () const
667 {return Comment;}
668
676JP2_Encoder& comment (const std::string& text)
677 {Comment = text; return *this;}
678
685bool ready () const;
686
693std::string reasons () const;
694
716int needs () const;
717
727JP2_Encoder_Error* encoder_error () const;
728
729/*==============================================================================
730 Encoder
731*/
749long long encode ();
750
753void open ();
754
759long long write_header ();
760
771long long write_user_boxes ();
772
776long long write_codestream ();
777
824 {Incremental_Flush_Bytes = ((bytes < 0) ? 0 : bytes); return *this;}
825
834long long incremental_flush_bytes () const
836
855JP2_Encoder& incremental_flush_lines (unsigned int lines);
856
875int incremental_flush_lines () const;
876
877long long close ();
878
879/*============================================================================
880 Helpers:
881*/
890int
891invalid_precinct_size (const std::vector<Size_2D>& sizes);
892
893protected:
894
910void read_stripe
911 (std::istream& source, int band, int line, int lines, kdu_int16* buffer);
912
928void read_stripe
929 (std::istream& source, int band, int line, int lines, kdu_int32* buffer);
930
931/*==============================================================================
932 Data Members:
933*/
934protected:
935//------------------------------------------------------------------------------
936// Input:
937
939std::string
941
943std::string
945
947std::streamoff
949
951unsigned int
953
954// Dimensions of the image.
957
963unsigned int
966
968unsigned int
970
972unsigned int
974
976bool
978
979// JP2 boxes beyond the minimum required.
982
983//------------------------------------------------------------------------------
984// Output:
985
987std::string
989
991unsigned char
993
995std::string
997
999bool
1001
1007unsigned int
1009
1010unsigned int
1012
1013double
1015
1017std::string
1019
1021Size_2D
1023
1025std::vector<Size_2D>
1027
1029Size_2D
1031
1032long long
1034
1035private:
1036//------------------------------------------------------------------------------
1037// Kakadu classes used during JP2 file generation.
1038
1040jp2_family_tgt
1041 *JP2_Stream;
1042
1044jp2_target
1045 *JP2_Boxes;
1046
1048kdu_codestream
1049 *JPEG2000_Codestream;
1050
1052JP2_Encoder_Error
1053 *Encoder_Error;
1054
1055}; // Class JP2_Encoder
1056
1057
1058#ifndef DOXYGEN_PROCESSING
1059/*=*****************************************************************************
1060 JP2_Encoder_Error
1061*/
1062class JP2_Encoder_Error
1063: public kdu_thread_safe_message
1064{
1065public:
1066
1067void put_text (const char* message);
1068void add_text (const std::string& message);
1069void flush (bool end_of_message = false);
1070
1071std::string
1072 Message;
1073};
1074#endif // DOXYGEN_PROCESSING
1075
1076
1077/*=*****************************************************************************
1078 Functions
1079*/
1085bool power_of_2 (unsigned int value);
1086
1087
1088} // namespace HiRISE
1089} // namespace UA
1090#endif
JP2_Encoder()
Definition JP2_Encoder.cc:136
A JP2_Box contains JP2 file format box data.
Definition JP2_Box.hh:40
std::vector< JP2_Box * > JP2_Box_List
List of JP2 boxes.
Definition JP2_Box.hh:46
A JP2_Encoder encodes image pixel data into a JPEG2000 JP2 file.
Definition JP2_Encoder.hh:84
long long close()
Definition JP2_Encoder.cc:1501
std::string destination() const
Get the destination JP2 file pathname.
Definition JP2_Encoder.hh:170
unsigned int line_prefix_bytes() const
Get the number of bytes preceeding each line of image pixel data.
Definition JP2_Encoder.hh:377
static const int NEEDS_DESTINATION
Definition JP2_Encoder.hh:127
double bit_rate() const
Get the codestream compression bit-rate.
Definition JP2_Encoder.hh:480
std::string comment() const
Get the codestream comment.
Definition JP2_Encoder.hh:666
static const unsigned int MAX_RESOLUTION_LEVELS
Maximum number of resolution levels.
Definition JP2_Encoder.hh:98
JP2_Encoder & comment(const std::string &text)
Set comment text to be added to the codestream.
Definition JP2_Encoder.hh:676
std::streamoff Image_Offset
Image data location as a byte offset within the source file.
Definition JP2_Encoder.hh:948
bool signed_data() const
Get the signedness of the pixel data.
Definition JP2_Encoder.hh:310
bool Signed_Data
Whether pixel data is to be treated as signed.
Definition JP2_Encoder.hh:977
const Size_2D image_size() const
Get the size of the source PDS image data.
Definition JP2_Encoder.hh:244
unsigned int pixel_bytes() const
Get the number of bytes per pixel.
Definition JP2_Encoder.hh:262
JP2_Encoder & swap_pixel_bytes(bool swap_data)
Set if multi-byte pixels will be reordered before being sent to the JPEG2000 codestream generation ma...
Definition JP2_Encoder.hh:368
JP2_Encoder_Error * encoder_error() const
Get the JP2_Encoder_Error describing the last encoder error that occurred.
Definition JP2_Encoder.cc:1579
unsigned char * Producer_UUID
The UUID to be placed in a UUID List box inside a UUID Info box.
Definition JP2_Encoder.hh:992
const std::vector< Size_2D > precinct_sizes() const
Get the precinct sizes for each resolution level.
Definition JP2_Encoder.hh:536
unsigned int Line_Prefix_Bytes
The number of bytes preceeding and following each line of pixel bytes.
Definition JP2_Encoder.hh:964
std::string reasons() const
Get a description of the reasons that the encoder is not ready.
Definition JP2_Encoder.cc:1553
std::string Image_Source
Image source pathname.
Definition JP2_Encoder.hh:940
unsigned int resolution_levels() const
Get the total number of codestream resolution levels.
Definition JP2_Encoder.hh:436
JP2_Encoder & image_data_location(std::streamoff file_offset)
Set the location of the image data in the source file.
Definition JP2_Encoder.hh:220
std::string PDS_Label_Pathname
PDS label file pathname to be placed in a UUID Info URL box.
Definition JP2_Encoder.hh:988
static const char *const UUID_INFO_BOX_NAME
PDS label reference information UUID Info JP2 container box name.
Definition JP2_Encoder.hh:105
std::string Comment
Comment segment to be added to the codestream.
Definition JP2_Encoder.hh:996
JP2_Encoder & image_bands(unsigned int bands)
Set the number of bands (components) in the PDS image.
Definition JP2_Encoder.hh:236
unsigned int Line_Suffix_Bytes
Definition JP2_Encoder.hh:965
unsigned int Pixel_Bytes
Pixel datum size in bytes.
Definition JP2_Encoder.hh:969
const Size_2D code_block_size() const
Get the code block size.
Definition JP2_Encoder.hh:588
unsigned int Image_Bands
Total image bands (components).
Definition JP2_Encoder.hh:952
static const unsigned int MAX_QUALITY_LAYERS
Maximum number of quality layers.
Definition JP2_Encoder.hh:101
bool MSB_data() const
Test if the source data will be treated as MSB ordered.
Definition JP2_Encoder.cc:361
std::string progression_order() const
Get the codestream progression order descriptor.
Definition JP2_Encoder.hh:504
static const int NEEDS_SOURCE
What the encoder needs to do its job.
Definition JP2_Encoder.hh:126
JP2_Box::JP2_Box_List Added_Boxes
Definition JP2_Encoder.hh:981
unsigned int quality_layers() const
Get the number of codestream quality layers.
Definition JP2_Encoder.hh:458
JP2_Encoder & PDS_label_pathname(const std::string &pathname)
Set the PDS/JP2 label file pathname.
Definition JP2_Encoder.hh:202
JP2_Box::JP2_Box_List & added_boxes()
Get the list of user specified data boxes added to the JP2 file.
Definition JP2_Encoder.hh:607
static const unsigned int DEFAULT_RESOLUTION_LEVELS
Default number of resolution levels.
Definition JP2_Encoder.hh:95
JP2_Encoder()
Definition JP2_Encoder.cc:136
JP2_Encoder & incremental_flush_bytes(long long bytes)
Set the rate at which compressed image data will be written to the output JP2 file.
Definition JP2_Encoder.hh:823
std::vector< Size_2D > Precinct_Sizes
Precinct sizes for codestream structure organization within tiles.
Definition JP2_Encoder.hh:1026
std::string JP2_Pathname
Image destination pathname.
Definition JP2_Encoder.hh:944
long long incremental_flush_bytes() const
Get the rate at which compressed image data will be written to the output JP2 file.
Definition JP2_Encoder.hh:834
std::string source() const
Get the PDS image data source pathname.
Definition JP2_Encoder.hh:150
int needs() const
Indicates what the encoder needs to do its job.
Definition JP2_Encoder.cc:1535
static const int UUID_SIZE
Size of the UUID data content.
Definition JP2_Encoder.hh:111
static const int MIN_STRIPE_HEIGHT
Image data stripe minimum and maximum number of lines.
Definition JP2_Encoder.hh:118
static const char *const URL_BOX_NAME
PDS label relative filename URL JP2 box name.
Definition JP2_Encoder.hh:114
const unsigned char * producer_UUID() const
Get the product producer signature UUID value.
Definition JP2_Encoder.hh:639
unsigned int image_bands() const
Get the number of bands (components) in the PDS image.
Definition JP2_Encoder.hh:228
std::string PDS_label_pathname() const
Get the PDS/JP2 label file pathname.
Definition JP2_Encoder.hh:187
long long Incremental_Flush_Bytes
Definition JP2_Encoder.hh:1033
long long write_user_boxes()
Write user specified boxes to the JP2 file.
Definition JP2_Encoder.cc:1165
void open()
Open the source JP2 file.
Definition JP2_Encoder.cc:880
static const int NEEDS_IMAGE
Definition JP2_Encoder.hh:128
std::streamoff image_data_location() const
Get the location of the image data in the source file.
Definition JP2_Encoder.hh:211
double Bit_Rate
Definition JP2_Encoder.hh:1014
unsigned int Resolution_Levels
The number of resolution levels to encode.
Definition JP2_Encoder.hh:1008
JP2_Encoder & add_box(JP2_Box *box)
Add a data box to the JP2 file.
Definition JP2_Encoder.cc:204
std::string Progression_Order
The codestream progression order to be used.
Definition JP2_Encoder.hh:1018
Size_2D Image_Size
Definition JP2_Encoder.hh:956
long long write_codestream()
Generate the compressed image data JPEG2000 codestream and write it to the JP2 file.
Definition JP2_Encoder.cc:1230
const Size_2D precinct_size(unsigned int resolution_level=0) const
Get the precinct size for a given resolution level.
Definition JP2_Encoder.cc:510
~JP2_Encoder()
Definition JP2_Encoder.cc:172
Size_2D Code_Block_Size
Code block size for codestream packet encoding within precincts.
Definition JP2_Encoder.hh:1030
unsigned int Pixel_Bits
Pixel precision bits.
Definition JP2_Encoder.hh:973
bool remove_box(JP2_Box *box)
Remove a data box from the list of user specified boxes.
Definition JP2_Encoder.cc:219
const Size_2D tile_size() const
Get the size of the JP2 image tiles.
Definition JP2_Encoder.hh:413
unsigned int pixel_bits() const
Get the pixel precision.
Definition JP2_Encoder.hh:285
Size_2D Tile_Size
Tile size for codestream structure organization.
Definition JP2_Encoder.hh:1022
long long encode()
Encode the image source to a JPEG2000 JP2 destination.
Definition JP2_Encoder.cc:852
bool Swap_Pixel_Bytes
Whether pixel bytes should be reordered before be encoded.
Definition JP2_Encoder.hh:1000
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.
Definition JP2_Encoder.cc:1667
bool swap_pixel_bytes() const
Test if multi-byte pixels will be reordered before being sent to the JPEG2000 codestream generation m...
Definition JP2_Encoder.hh:357
long long write_header()
Write the required metadata boxes to the JP2 file.
Definition JP2_Encoder.cc:917
JP2_Encoder & destination(const std::string &pathname)
Set the destination JP2 file pathname.
Definition JP2_Encoder.hh:178
unsigned int line_suffix_bytes() const
Get the number of bytes following each line of image pixel data.
Definition JP2_Encoder.hh:395
static const int MAX_STRIPE_HEIGHT
Definition JP2_Encoder.hh:119
int incremental_flush_lines() const
Get the rate at which compressed image data will be written to the output JP2 file.
Definition JP2_Encoder.cc:1460
static const int ENCODER_EXCEPTION
JP2_Encoder_Error exception signal value.
Definition JP2_Encoder.hh:132
unsigned int Quality_Layers
Definition JP2_Encoder.hh:1011
JP2_Encoder & line_suffix_bytes(unsigned int suffix_bytes)
Set the number of bytes following each line of image pixel data.
Definition JP2_Encoder.hh:404
JP2_Encoder & tile_size(const Size_2D &size)
Set the size of the JP2 image tiles.
Definition JP2_Encoder.hh:425
bool ready() const
Test if the encoder is ready to compress the image data.
Definition JP2_Encoder.cc:1521
int invalid_precinct_size(const std::vector< Size_2D > &sizes)
Check for valid precinct sizes.
Definition JP2_Encoder.cc:553
static const char *const UUID_BOX_NAME
Data provider UUID JP2 box name.
Definition JP2_Encoder.hh:108
static const char *const ID
Class identification name with source code version and date.
Definition JP2_Encoder.hh:91
JP2_Encoder & line_prefix_bytes(unsigned int prefix_bytes)
Set the number of bytes preceeding each line of image pixel data.
Definition JP2_Encoder.hh:386
Definition Dimensions.cc:32
bool power_of_2(unsigned int value)
Test if a value is a power of 2.
Definition JP2_Encoder.cc:530
Definition Dimensions.cc:30
A Size_2D holds 2-dimensional size information.
Definition Dimensions.hh:119