HiRISE
 PDS_JP2

JP2_Encoder.hh
Go to the documentation of this file.
1 /* JP2_Encoder
2 
3 HiROC CVS ID: JP2_Encoder.hh,v 1.28 2019/03/26 20:51:11 guym Exp
4 
5 Copyright (C) 2006-2007 Arizona Board of Regents on behalf of the
6 Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
7 the University of Arizona.
8 
9 This library is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License, version 2.1,
11 as published by the Free Software Foundation.
12 
13 This library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with this library; if not, write to the Free Software Foundation,
20 Inc., 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"
31 using namespace kdu_supp;
32 
33 #include <string>
34 #include <iosfwd>
35 #include <vector>
36 
37 namespace UA
38 {
39 namespace HiRISE
40 {
41 // Forward reference.
42 class JP2_Encoder_Error;
43 
84 {
85 public:
86 /*==============================================================================
87  Constants:
88 */
90 static const char* const
91  ID;
92 
94 static const unsigned int
97 static const unsigned int
100 static const unsigned int
102 
104 static const char* const
107 static const char* const
110 static const int
113 static const char* const
115 
117 static const int
120 
125 static const int
129 
131 static const int
133 
134 /*==============================================================================
135  Constructors:
136 */
137 JP2_Encoder ();
138 
139 // Destructor.
140 ~JP2_Encoder ();
141 
142 /*==============================================================================
143  Accessors:
144 */
150 std::string source () const
151  {return Image_Source;}
152 
162 JP2_Encoder& source (const std::string& pathname);
163 
170 std::string destination () const
171  {return JP2_Pathname;}
172 
178 JP2_Encoder& destination (const std::string& pathname)
179  {JP2_Pathname = pathname; return *this;}
180 
187 std::string PDS_label_pathname () const
188  {return PDS_Label_Pathname;}
189 
202 JP2_Encoder& PDS_label_pathname (const std::string& pathname)
203  {PDS_Label_Pathname = pathname; return *this;}
204 
211 std::streamoff image_data_location () const
212  {return Image_Offset;}
213 
220 JP2_Encoder& image_data_location (std::streamoff file_offset)
221  {Image_Offset = file_offset; return *this;}
222 
228 unsigned int image_bands () const
229  {return Image_Bands;}
230 
236 JP2_Encoder& image_bands (unsigned int bands)
237  {Image_Bands = bands; return *this;}
238 
244 const Size_2D image_size () const
245  {return Image_Size;}
246 
255 JP2_Encoder& image_size (const Size_2D& size);
256 
262 unsigned int pixel_bytes () const
263  {return Pixel_Bytes;}
264 
278 JP2_Encoder& pixel_bytes (unsigned int bytes_per_pixel);
279 
285 unsigned int pixel_bits () const
286  {return Pixel_Bits;}
287 
302 JP2_Encoder& pixel_bits (unsigned int bits_per_pixel);
303 
310 bool signed_data () const
311  {return Signed_Data;}
312 
325 JP2_Encoder& signed_data (bool data_is_signed);
326 
334 bool MSB_data () const;
335 
348 JP2_Encoder& MSB_data (bool data_is_MSB);
349 
357 bool swap_pixel_bytes () const
358  {return Swap_Pixel_Bytes;}
359 
368 JP2_Encoder& swap_pixel_bytes (bool swap_data)
369  {Swap_Pixel_Bytes = swap_data; return *this;}
370 
377 unsigned int line_prefix_bytes () const
378  {return Line_Prefix_Bytes;}
379 
386 JP2_Encoder& line_prefix_bytes (unsigned int prefix_bytes)
387  {Line_Prefix_Bytes = prefix_bytes; return *this;}
388 
395 unsigned int line_suffix_bytes () const
396  {return Line_Suffix_Bytes;}
397 
404 JP2_Encoder& line_suffix_bytes (unsigned int suffix_bytes)
405  {Line_Suffix_Bytes = suffix_bytes; return *this;}
406 
413 const Size_2D tile_size () const
414  {return Tile_Size;}
415 
426  {Tile_Size = size; return *this;}
427 
436 unsigned int resolution_levels () const
437  {return Resolution_Levels;}
438 
451 JP2_Encoder& resolution_levels (unsigned int resolution_levels);
452 
458 unsigned int quality_layers () const
459  {return Quality_Layers;}
460 
472 JP2_Encoder& quality_layers (unsigned int quality_layers);
473 
480 double bit_rate () const
481  {return Bit_Rate;}
482 
497 JP2_Encoder& bit_rate (double rate);
498 
504 std::string progression_order () const
505  {return Progression_Order;}
506 
527 JP2_Encoder& progression_order (const std::string& progression);
528 
536 const std::vector<Size_2D> precinct_sizes () const
537 {return Precinct_Sizes;}
538 
548 const Size_2D precinct_size
549  (unsigned int resolution_level = 0) const;
550 
568 JP2_Encoder& precinct_sizes
569  (const std::vector<Size_2D>& sizes);
570 
580 JP2_Encoder& precinct_size
581  (const Size_2D& size, unsigned int resolution_level = 0);
582 
588 const Size_2D code_block_size () const
589  {return Code_Block_Size;}
590 
598 JP2_Encoder& code_block_size (const Size_2D& size);
599 
608  {return Added_Boxes;}
609 
619 JP2_Encoder& add_box (JP2_Box* box);
620 
629 bool remove_box (JP2_Box* box);
630 
639 const unsigned char* producer_UUID () const
640  {return Producer_UUID;}
641 
658 JP2_Encoder& producer_UUID (const unsigned char* id);
659 
666 std::string comment () const
667  {return Comment;}
668 
676 JP2_Encoder& comment (const std::string& text)
677  {Comment = text; return *this;}
678 
685 bool ready () const;
686 
693 std::string reasons () const;
694 
716 int needs () const;
717 
727 JP2_Encoder_Error* encoder_error () const;
728 
729 /*==============================================================================
730  Encoder
731 */
749 long long encode ();
750 
753 void open ();
754 
759 long long write_header ();
760 
771 long long write_user_boxes ();
772 
776 long long write_codestream ();
777 
824  {Incremental_Flush_Bytes = ((bytes < 0) ? 0 : bytes); return *this;}
825 
834 long long incremental_flush_bytes () const
835  {return Incremental_Flush_Bytes;}
836 
855 JP2_Encoder& incremental_flush_lines (unsigned int lines);
856 
875 int incremental_flush_lines () const;
876 
877 long long close ();
878 
879 /*============================================================================
880  Helpers:
881 */
890 int
891 invalid_precinct_size (const std::vector<Size_2D>& sizes);
892 
893 protected:
894 
910 void read_stripe
911  (std::istream& source, int band, int line, int lines, kdu_int16* buffer);
912 
928 void read_stripe
929  (std::istream& source, int band, int line, int lines, kdu_int32* buffer);
930 
931 /*==============================================================================
932  Data Members:
933 */
934 protected:
935 //------------------------------------------------------------------------------
936 // Input:
937 
939 std::string
941 
943 std::string
945 
947 std::streamoff
949 
951 unsigned int
953 
954 // Dimensions of the image.
955 Size_2D
957 
963 unsigned int
966 
968 unsigned int
970 
972 unsigned int
974 
976 bool
978 
979 // JP2 boxes beyond the minimum required.
982 
983 //------------------------------------------------------------------------------
984 // Output:
985 
987 std::string
989 
991 unsigned char
993 
995 std::string
997 
999 bool
1001 
1007 unsigned int
1009 
1010 unsigned int
1012 
1013 double
1015 
1017 std::string
1019 
1021 Size_2D
1023 
1025 std::vector<Size_2D>
1027 
1029 Size_2D
1031 
1032 long long
1034 
1035 private:
1036 //------------------------------------------------------------------------------
1037 // Kakadu classes used during JP2 file generation.
1038 
1040 jp2_family_tgt
1041  *JP2_Stream;
1042 
1044 jp2_target
1045  *JP2_Boxes;
1046 
1048 kdu_codestream
1049  *JPEG2000_Codestream;
1050 
1052 JP2_Encoder_Error
1053  *Encoder_Error;
1054 
1055 }; // Class JP2_Encoder
1056 
1057 
1058 #ifndef DOXYGEN_PROCESSING
1059 /*=*****************************************************************************
1060  JP2_Encoder_Error
1061 */
1062 class JP2_Encoder_Error
1063 : public kdu_thread_safe_message
1064 {
1065 public:
1066 
1067 void put_text (const char* message);
1068 void add_text (const std::string& message);
1069 void flush (bool end_of_message = false);
1070 
1071 std::string
1072  Message;
1073 };
1074 #endif // DOXYGEN_PROCESSING
1075 
1076 
1077 /*=*****************************************************************************
1078  Functions
1079 */
1085 bool power_of_2 (unsigned int value);
1086 
1087 
1088 } // namespace HiRISE
1089 } // namespace UA
1090 #endif
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
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
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
unsigned char * Producer_UUID
The UUID to be placed in a UUID List box inside a UUID Info box.
Definition: JP2_Encoder.hh:992
unsigned int Line_Prefix_Bytes
The number of bytes preceeding and following each line of pixel bytes.
Definition: JP2_Encoder.hh:964
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
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
unsigned int Line_Suffix_Bytes
Definition: JP2_Encoder.hh:965
unsigned int Pixel_Bytes
Pixel datum size in bytes.
Definition: JP2_Encoder.hh:969
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
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
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
static const unsigned int MAX_QUALITY_LAYERS
Maximum number of quality layers.
Definition: JP2_Encoder.hh:101
JP2_Encoder & destination(const std::string &pathname)
Set the destination JP2 file pathname.
Definition: JP2_Encoder.hh:178
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
static const unsigned int DEFAULT_RESOLUTION_LEVELS
Default number of resolution levels.
Definition: JP2_Encoder.hh:95
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
JP2_Encoder & comment(const std::string &text)
Set comment text to be added to the codestream.
Definition: JP2_Encoder.hh:676
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
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
JP2_Encoder & image_bands(unsigned int bands)
Set the number of bands (components) in the PDS image.
Definition: JP2_Encoder.hh:236
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
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
const std::vector< Size_2D > precinct_sizes() const
Get the precinct sizes for each resolution level.
Definition: JP2_Encoder.hh:536
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
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
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
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
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
bool Swap_Pixel_Bytes
Whether pixel bytes should be reordered before be encoded.
Definition: JP2_Encoder.hh:1000
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
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
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_prefix_bytes(unsigned int prefix_bytes)
Set the number of bytes preceeding each line of image pixel data.
Definition: JP2_Encoder.hh:386
JP2_Encoder & PDS_label_pathname(const std::string &pathname)
Set the PDS/JP2 label file pathname.
Definition: JP2_Encoder.hh:202
JP2_Encoder & tile_size(const Size_2D &size)
Set the size of the JP2 image tiles.
Definition: JP2_Encoder.hh:425
static const char *const UUID_BOX_NAME
Data provider UUID JP2 box name.
Definition: JP2_Encoder.hh:108
const unsigned char * producer_UUID() const
Get the product producer signature UUID value.
Definition: JP2_Encoder.hh:639
static const char *const ID
Class identification name with source code version and date.
Definition: JP2_Encoder.hh:91
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
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