PDS_JP2
|
00001 /* JP2_Encoder 00002 00003 HiROC CVS ID: JP2_Encoder.hh,v 1.28 2019/03/26 20:51:11 guym Exp 00004 00005 Copyright (C) 2006-2007 Arizona Board of Regents on behalf of the 00006 Planetary Image Research Laboratory, Lunar and Planetary Laboratory at 00007 the University of Arizona. 00008 00009 This library is free software; you can redistribute it and/or modify it 00010 under the terms of the GNU Lesser General Public License, version 2.1, 00011 as published by the Free Software Foundation. 00012 00013 This library is distributed in the hope that it will be useful, but 00014 WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public License 00019 along with this library; if not, write to the Free Software Foundation, 00020 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00021 */ 00022 00023 #ifndef _JP2_Encoder_ 00024 #define _JP2_Encoder_ 00025 00026 #include "Dimensions.hh" 00027 #include "JP2_Box.hh" 00028 00029 // Kakadu 00030 #include "jp2.h" 00031 using namespace kdu_supp; 00032 00033 #include <string> 00034 #include <iosfwd> 00035 #include <vector> 00036 00037 namespace UA 00038 { 00039 namespace HiRISE 00040 { 00041 // Forward reference. 00042 class JP2_Encoder_Error; 00043 00083 class JP2_Encoder 00084 { 00085 public: 00086 /*============================================================================== 00087 Constants: 00088 */ 00090 static const char* const 00091 ID; 00092 00094 static const unsigned int 00095 DEFAULT_RESOLUTION_LEVELS; 00097 static const unsigned int 00098 MAX_RESOLUTION_LEVELS; 00100 static const unsigned int 00101 MAX_QUALITY_LAYERS; 00102 00104 static const char* const 00105 UUID_INFO_BOX_NAME; 00107 static const char* const 00108 UUID_BOX_NAME; 00110 static const int 00111 UUID_SIZE; 00113 static const char* const 00114 URL_BOX_NAME; 00115 00117 static const int 00118 MIN_STRIPE_HEIGHT, 00119 MAX_STRIPE_HEIGHT; 00120 00125 static const int 00126 NEEDS_SOURCE, 00127 NEEDS_DESTINATION, 00128 NEEDS_IMAGE; 00129 00131 static const int 00132 ENCODER_EXCEPTION; 00133 00134 /*============================================================================== 00135 Constructors: 00136 */ 00137 JP2_Encoder (); 00138 00139 // Destructor. 00140 ~JP2_Encoder (); 00141 00142 /*============================================================================== 00143 Accessors: 00144 */ 00150 std::string source () const 00151 {return Image_Source;} 00152 00162 JP2_Encoder& source (const std::string& pathname); 00163 00170 std::string destination () const 00171 {return JP2_Pathname;} 00172 00178 JP2_Encoder& destination (const std::string& pathname) 00179 {JP2_Pathname = pathname; return *this;} 00180 00187 std::string PDS_label_pathname () const 00188 {return PDS_Label_Pathname;} 00189 00202 JP2_Encoder& PDS_label_pathname (const std::string& pathname) 00203 {PDS_Label_Pathname = pathname; return *this;} 00204 00211 std::streamoff image_data_location () const 00212 {return Image_Offset;} 00213 00220 JP2_Encoder& image_data_location (std::streamoff file_offset) 00221 {Image_Offset = file_offset; return *this;} 00222 00228 unsigned int image_bands () const 00229 {return Image_Bands;} 00230 00236 JP2_Encoder& image_bands (unsigned int bands) 00237 {Image_Bands = bands; return *this;} 00238 00244 const Size_2D image_size () const 00245 {return Image_Size;} 00246 00255 JP2_Encoder& image_size (const Size_2D& size); 00256 00262 unsigned int pixel_bytes () const 00263 {return Pixel_Bytes;} 00264 00278 JP2_Encoder& pixel_bytes (unsigned int bytes_per_pixel); 00279 00285 unsigned int pixel_bits () const 00286 {return Pixel_Bits;} 00287 00302 JP2_Encoder& pixel_bits (unsigned int bits_per_pixel); 00303 00310 bool signed_data () const 00311 {return Signed_Data;} 00312 00325 JP2_Encoder& signed_data (bool data_is_signed); 00326 00334 bool MSB_data () const; 00335 00348 JP2_Encoder& MSB_data (bool data_is_MSB); 00349 00357 bool swap_pixel_bytes () const 00358 {return Swap_Pixel_Bytes;} 00359 00368 JP2_Encoder& swap_pixel_bytes (bool swap_data) 00369 {Swap_Pixel_Bytes = swap_data; return *this;} 00370 00377 unsigned int line_prefix_bytes () const 00378 {return Line_Prefix_Bytes;} 00379 00386 JP2_Encoder& line_prefix_bytes (unsigned int prefix_bytes) 00387 {Line_Prefix_Bytes = prefix_bytes; return *this;} 00388 00395 unsigned int line_suffix_bytes () const 00396 {return Line_Suffix_Bytes;} 00397 00404 JP2_Encoder& line_suffix_bytes (unsigned int suffix_bytes) 00405 {Line_Suffix_Bytes = suffix_bytes; return *this;} 00406 00413 const Size_2D tile_size () const 00414 {return Tile_Size;} 00415 00425 JP2_Encoder& tile_size (const Size_2D& size) 00426 {Tile_Size = size; return *this;} 00427 00436 unsigned int resolution_levels () const 00437 {return Resolution_Levels;} 00438 00451 JP2_Encoder& resolution_levels (unsigned int resolution_levels); 00452 00458 unsigned int quality_layers () const 00459 {return Quality_Layers;} 00460 00472 JP2_Encoder& quality_layers (unsigned int quality_layers); 00473 00480 double bit_rate () const 00481 {return Bit_Rate;} 00482 00497 JP2_Encoder& bit_rate (double rate); 00498 00504 std::string progression_order () const 00505 {return Progression_Order;} 00506 00527 JP2_Encoder& progression_order (const std::string& progression); 00528 00536 const std::vector<Size_2D> precinct_sizes () const 00537 {return Precinct_Sizes;} 00538 00548 const Size_2D precinct_size 00549 (unsigned int resolution_level = 0) const; 00550 00568 JP2_Encoder& precinct_sizes 00569 (const std::vector<Size_2D>& sizes); 00570 00580 JP2_Encoder& precinct_size 00581 (const Size_2D& size, unsigned int resolution_level = 0); 00582 00588 const Size_2D code_block_size () const 00589 {return Code_Block_Size;} 00590 00598 JP2_Encoder& code_block_size (const Size_2D& size); 00599 00607 JP2_Box::JP2_Box_List& added_boxes () 00608 {return Added_Boxes;} 00609 00619 JP2_Encoder& add_box (JP2_Box* box); 00620 00629 bool remove_box (JP2_Box* box); 00630 00639 const unsigned char* producer_UUID () const 00640 {return Producer_UUID;} 00641 00658 JP2_Encoder& producer_UUID (const unsigned char* id); 00659 00666 std::string comment () const 00667 {return Comment;} 00668 00676 JP2_Encoder& comment (const std::string& text) 00677 {Comment = text; return *this;} 00678 00685 bool ready () const; 00686 00693 std::string reasons () const; 00694 00716 int needs () const; 00717 00727 JP2_Encoder_Error* encoder_error () const; 00728 00729 /*============================================================================== 00730 Encoder 00731 */ 00749 long long encode (); 00750 00753 void open (); 00754 00759 long long write_header (); 00760 00771 long long write_user_boxes (); 00772 00776 long long write_codestream (); 00777 00823 JP2_Encoder& incremental_flush_bytes (long long bytes) 00824 {Incremental_Flush_Bytes = ((bytes < 0) ? 0 : bytes); return *this;} 00825 00834 long long incremental_flush_bytes () const 00835 {return Incremental_Flush_Bytes;} 00836 00855 JP2_Encoder& incremental_flush_lines (unsigned int lines); 00856 00875 int incremental_flush_lines () const; 00876 00877 long long close (); 00878 00879 /*============================================================================ 00880 Helpers: 00881 */ 00890 int 00891 invalid_precinct_size (const std::vector<Size_2D>& sizes); 00892 00893 protected: 00894 00910 void read_stripe 00911 (std::istream& source, int band, int line, int lines, kdu_int16* buffer); 00912 00928 void read_stripe 00929 (std::istream& source, int band, int line, int lines, kdu_int32* buffer); 00930 00931 /*============================================================================== 00932 Data Members: 00933 */ 00934 protected: 00935 //------------------------------------------------------------------------------ 00936 // Input: 00937 00939 std::string 00940 Image_Source; 00941 00943 std::string 00944 JP2_Pathname; 00945 00947 std::streamoff 00948 Image_Offset; 00949 00951 unsigned int 00952 Image_Bands; 00953 00954 // Dimensions of the image. 00955 Size_2D 00956 Image_Size; 00957 00963 unsigned int 00964 Line_Prefix_Bytes, 00965 Line_Suffix_Bytes; 00966 00968 unsigned int 00969 Pixel_Bytes; 00970 00972 unsigned int 00973 Pixel_Bits; 00974 00976 bool 00977 Signed_Data; 00978 00979 // JP2 boxes beyond the minimum required. 00980 JP2_Box::JP2_Box_List 00981 Added_Boxes; 00982 00983 //------------------------------------------------------------------------------ 00984 // Output: 00985 00987 std::string 00988 PDS_Label_Pathname; 00989 00991 unsigned char 00992 *Producer_UUID; 00993 00995 std::string 00996 Comment; 00997 00999 bool 01000 Swap_Pixel_Bytes; 01001 01007 unsigned int 01008 Resolution_Levels; 01009 01010 unsigned int 01011 Quality_Layers; 01012 01013 double 01014 Bit_Rate; 01015 01017 std::string 01018 Progression_Order; 01019 01021 Size_2D 01022 Tile_Size; 01023 01025 std::vector<Size_2D> 01026 Precinct_Sizes; 01027 01029 Size_2D 01030 Code_Block_Size; 01031 01032 long long 01033 Incremental_Flush_Bytes; 01034 01035 private: 01036 //------------------------------------------------------------------------------ 01037 // Kakadu classes used during JP2 file generation. 01038 01040 jp2_family_tgt 01041 *JP2_Stream; 01042 01044 jp2_target 01045 *JP2_Boxes; 01046 01048 kdu_codestream 01049 *JPEG2000_Codestream; 01050 01052 JP2_Encoder_Error 01053 *Encoder_Error; 01054 01055 }; // Class JP2_Encoder 01056 01057 01058 #ifndef DOXYGEN_PROCESSING 01059 /*=***************************************************************************** 01060 JP2_Encoder_Error 01061 */ 01062 class JP2_Encoder_Error 01063 : public kdu_thread_safe_message 01064 { 01065 public: 01066 01067 void put_text (const char* message); 01068 void add_text (const std::string& message); 01069 void flush (bool end_of_message = false); 01070 01071 std::string 01072 Message; 01073 }; 01074 #endif // DOXYGEN_PROCESSING 01075 01076 01077 /*=***************************************************************************** 01078 Functions 01079 */ 01085 bool power_of_2 (unsigned int value); 01086 01087 01088 } // namespace HiRISE 01089 } // namespace UA 01090 #endif