|
|
PDS_JP2
|
00001 /* JP2_Encoder 00002 00003 HiROC CVS ID: JP2_Encoder.hh,v 1.27 2010/04/30 08:01:47 castalia 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 00032 #include <string> 00033 #include <iosfwd> 00034 #include <vector> 00035 00036 namespace UA 00037 { 00038 namespace HiRISE 00039 { 00040 // Forward reference. 00041 class JP2_Encoder_Error; 00042 00082 class JP2_Encoder 00083 { 00084 public: 00085 /*============================================================================== 00086 Constants: 00087 */ 00089 static const char* const 00090 ID; 00091 00093 static const unsigned int 00094 DEFAULT_RESOLUTION_LEVELS; 00096 static const unsigned int 00097 MAX_RESOLUTION_LEVELS; 00099 static const unsigned int 00100 MAX_QUALITY_LAYERS; 00101 00103 static const char* const 00104 UUID_INFO_BOX_NAME; 00106 static const char* const 00107 UUID_BOX_NAME; 00109 static const int 00110 UUID_SIZE; 00112 static const char* const 00113 URL_BOX_NAME; 00114 00116 static const int 00117 MIN_STRIPE_HEIGHT, 00118 MAX_STRIPE_HEIGHT; 00119 00124 static const int 00125 NEEDS_SOURCE, 00126 NEEDS_DESTINATION, 00127 NEEDS_IMAGE; 00128 00130 static const int 00131 ENCODER_EXCEPTION; 00132 00133 /*============================================================================== 00134 Constructors: 00135 */ 00136 JP2_Encoder (); 00137 00138 // Destructor. 00139 ~JP2_Encoder (); 00140 00141 /*============================================================================== 00142 Accessors: 00143 */ 00149 std::string source () const 00150 {return Image_Source;} 00151 00161 JP2_Encoder& source (const std::string& pathname); 00162 00169 std::string destination () const 00170 {return JP2_Pathname;} 00171 00177 JP2_Encoder& destination (const std::string& pathname) 00178 {JP2_Pathname = pathname; return *this;} 00179 00186 std::string PDS_label_pathname () const 00187 {return PDS_Label_Pathname;} 00188 00201 JP2_Encoder& PDS_label_pathname (const std::string& pathname) 00202 {PDS_Label_Pathname = pathname; return *this;} 00203 00210 std::streamoff image_data_location () const 00211 {return Image_Offset;} 00212 00219 JP2_Encoder& image_data_location (std::streamoff file_offset) 00220 {Image_Offset = file_offset; return *this;} 00221 00227 unsigned int image_bands () const 00228 {return Image_Bands;} 00229 00235 JP2_Encoder& image_bands (unsigned int bands) 00236 {Image_Bands = bands; return *this;} 00237 00243 const Size_2D image_size () const 00244 {return Image_Size;} 00245 00254 JP2_Encoder& image_size (const Size_2D& size); 00255 00261 unsigned int pixel_bytes () const 00262 {return Pixel_Bytes;} 00263 00277 JP2_Encoder& pixel_bytes (unsigned int bytes_per_pixel); 00278 00284 unsigned int pixel_bits () const 00285 {return Pixel_Bits;} 00286 00301 JP2_Encoder& pixel_bits (unsigned int bits_per_pixel); 00302 00309 bool signed_data () const 00310 {return Signed_Data;} 00311 00324 JP2_Encoder& signed_data (bool data_is_signed); 00325 00333 bool MSB_data () const; 00334 00347 JP2_Encoder& MSB_data (bool data_is_MSB); 00348 00356 bool swap_pixel_bytes () const 00357 {return Swap_Pixel_Bytes;} 00358 00367 JP2_Encoder& swap_pixel_bytes (bool swap_data) 00368 {Swap_Pixel_Bytes = swap_data; return *this;} 00369 00376 unsigned int line_prefix_bytes () const 00377 {return Line_Prefix_Bytes;} 00378 00385 JP2_Encoder& line_prefix_bytes (unsigned int prefix_bytes) 00386 {Line_Prefix_Bytes = prefix_bytes; return *this;} 00387 00394 unsigned int line_suffix_bytes () const 00395 {return Line_Suffix_Bytes;} 00396 00403 JP2_Encoder& line_suffix_bytes (unsigned int suffix_bytes) 00404 {Line_Suffix_Bytes = suffix_bytes; return *this;} 00405 00412 const Size_2D tile_size () const 00413 {return Tile_Size;} 00414 00424 JP2_Encoder& tile_size (const Size_2D& size) 00425 {Tile_Size = size; return *this;} 00426 00435 unsigned int resolution_levels () const 00436 {return Resolution_Levels;} 00437 00450 JP2_Encoder& resolution_levels (unsigned int resolution_levels); 00451 00457 unsigned int quality_layers () const 00458 {return Quality_Layers;} 00459 00471 JP2_Encoder& quality_layers (unsigned int quality_layers); 00472 00479 double bit_rate () const 00480 {return Bit_Rate;} 00481 00496 JP2_Encoder& bit_rate (double rate); 00497 00503 std::string progression_order () const 00504 {return Progression_Order;} 00505 00526 JP2_Encoder& progression_order (const std::string& progression); 00527 00535 const std::vector<Size_2D> precinct_sizes () const 00536 {return Precinct_Sizes;} 00537 00547 const Size_2D precinct_size 00548 (unsigned int resolution_level = 0) const; 00549 00567 JP2_Encoder& precinct_sizes 00568 (const std::vector<Size_2D>& sizes); 00569 00579 JP2_Encoder& precinct_size 00580 (const Size_2D& size, unsigned int resolution_level = 0); 00581 00587 const Size_2D code_block_size () const 00588 {return Code_Block_Size;} 00589 00597 JP2_Encoder& code_block_size (const Size_2D& size); 00598 00606 JP2_Box::JP2_Box_List& added_boxes () 00607 {return Added_Boxes;} 00608 00618 JP2_Encoder& add_box (JP2_Box* box); 00619 00628 bool remove_box (JP2_Box* box); 00629 00638 const unsigned char* producer_UUID () const 00639 {return Producer_UUID;} 00640 00657 JP2_Encoder& producer_UUID (const unsigned char* id); 00658 00665 std::string comment () const 00666 {return Comment;} 00667 00675 JP2_Encoder& comment (const std::string& text) 00676 {Comment = text; return *this;} 00677 00684 bool ready () const; 00685 00692 std::string reasons () const; 00693 00715 int needs () const; 00716 00726 JP2_Encoder_Error* encoder_error () const; 00727 00728 /*============================================================================== 00729 Encoder 00730 */ 00748 long long encode (); 00749 00752 void open (); 00753 00758 long long write_header (); 00759 00770 long long write_user_boxes (); 00771 00775 long long write_codestream (); 00776 00822 JP2_Encoder& incremental_flush_bytes (long long bytes) 00823 {Incremental_Flush_Bytes = ((bytes < 0) ? 0 : bytes); return *this;} 00824 00833 long long incremental_flush_bytes () const 00834 {return Incremental_Flush_Bytes;} 00835 00854 JP2_Encoder& incremental_flush_lines (unsigned int lines); 00855 00874 int incremental_flush_lines () const; 00875 00876 long long close (); 00877 00878 /*============================================================================ 00879 Helpers: 00880 */ 00889 int 00890 invalid_precinct_size (const std::vector<Size_2D>& sizes); 00891 00892 protected: 00893 00909 void read_stripe 00910 (std::istream& source, int band, int line, int lines, kdu_int16* buffer); 00911 00927 void read_stripe 00928 (std::istream& source, int band, int line, int lines, kdu_int32* buffer); 00929 00930 /*============================================================================== 00931 Data Members: 00932 */ 00933 protected: 00934 //------------------------------------------------------------------------------ 00935 // Input: 00936 00938 std::string 00939 Image_Source; 00940 00942 std::string 00943 JP2_Pathname; 00944 00946 std::streamoff 00947 Image_Offset; 00948 00950 unsigned int 00951 Image_Bands; 00952 00953 // Dimensions of the image. 00954 Size_2D 00955 Image_Size; 00956 00962 unsigned int 00963 Line_Prefix_Bytes, 00964 Line_Suffix_Bytes; 00965 00967 unsigned int 00968 Pixel_Bytes; 00969 00971 unsigned int 00972 Pixel_Bits; 00973 00975 bool 00976 Signed_Data; 00977 00978 // JP2 boxes beyond the minimum required. 00979 JP2_Box::JP2_Box_List 00980 Added_Boxes; 00981 00982 //------------------------------------------------------------------------------ 00983 // Output: 00984 00986 std::string 00987 PDS_Label_Pathname; 00988 00990 unsigned char 00991 *Producer_UUID; 00992 00994 std::string 00995 Comment; 00996 00998 bool 00999 Swap_Pixel_Bytes; 01000 01006 unsigned int 01007 Resolution_Levels; 01008 01009 unsigned int 01010 Quality_Layers; 01011 01012 double 01013 Bit_Rate; 01014 01016 std::string 01017 Progression_Order; 01018 01020 Size_2D 01021 Tile_Size; 01022 01024 std::vector<Size_2D> 01025 Precinct_Sizes; 01026 01028 Size_2D 01029 Code_Block_Size; 01030 01031 long long 01032 Incremental_Flush_Bytes; 01033 01034 private: 01035 //------------------------------------------------------------------------------ 01036 // Kakadu classes used during JP2 file generation. 01037 01039 jp2_family_tgt 01040 *JP2_Stream; 01041 01043 jp2_target 01044 *JP2_Boxes; 01045 01047 kdu_codestream 01048 *JPEG2000_Codestream; 01049 01051 JP2_Encoder_Error 01052 *Encoder_Error; 01053 01054 }; // Class JP2_Encoder 01055 01056 01057 #ifndef DOXYGEN_PROCESSING 01058 /*=***************************************************************************** 01059 JP2_Encoder_Error 01060 */ 01061 class JP2_Encoder_Error 01062 : public kdu_thread_safe_message 01063 { 01064 public: 01065 01066 void put_text (const char* message); 01067 void add_text (const std::string& message); 01068 void flush (bool end_of_message = false); 01069 01070 std::string 01071 Message; 01072 }; 01073 #endif // DOXYGEN_PROCESSING 01074 01075 01076 /*=***************************************************************************** 01077 Functions 01078 */ 01084 bool power_of_2 (unsigned int value); 01085 01086 01087 } // namespace HiRISE 01088 } // namespace UA 01089 #endif
1.7.2