|
|
PDS_JP2
|
00001 /* JP2_Encoder 00002 00003 HiROC CVS ID: JP2_Encoder.hh,v 1.24 2009/01/31 04:30:53 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; 00098 00100 static const char* const 00101 UUID_INFO_BOX_NAME; 00103 static const char* const 00104 UUID_BOX_NAME; 00106 static const int 00107 UUID_SIZE; 00109 static const char* const 00110 URL_BOX_NAME; 00111 00113 static const int 00114 MIN_STRIPE_HEIGHT, 00115 MAX_STRIPE_HEIGHT; 00116 00121 static const int 00122 NEEDS_SOURCE, 00123 NEEDS_DESTINATION, 00124 NEEDS_IMAGE; 00125 00127 static const int 00128 ENCODER_EXCEPTION; 00129 00130 /*============================================================================== 00131 Constructors: 00132 */ 00133 JP2_Encoder (); 00134 00135 // Destructor. 00136 ~JP2_Encoder (); 00137 00138 /*============================================================================== 00139 Accessors: 00140 */ 00146 std::string source () const 00147 {return Image_Source;} 00148 00158 JP2_Encoder& source (const std::string& pathname); 00159 00166 std::string destination () const 00167 {return JP2_Pathname;} 00168 00174 JP2_Encoder& destination (const std::string& pathname) 00175 {JP2_Pathname = pathname; return *this;} 00176 00183 std::string PDS_label_pathname () const 00184 {return PDS_Label_Pathname;} 00185 00198 JP2_Encoder& PDS_label_pathname (const std::string& pathname) 00199 {PDS_Label_Pathname = pathname; return *this;} 00200 00207 std::streamoff image_data_location () const 00208 {return Image_Offset;} 00209 00216 JP2_Encoder& image_data_location (std::streamoff file_offset) 00217 {Image_Offset = file_offset; return *this;} 00218 00224 unsigned int image_bands () const 00225 {return Image_Bands;} 00226 00232 JP2_Encoder& image_bands (unsigned int bands) 00233 {Image_Bands = bands; return *this;} 00234 00240 const Size_2D image_size () const 00241 {return Image_Size;} 00242 00251 JP2_Encoder& image_size (const Size_2D& size); 00252 00258 unsigned int pixel_bytes () const 00259 {return Pixel_Bytes;} 00260 00274 JP2_Encoder& pixel_bytes (unsigned int bytes_per_pixel); 00275 00281 unsigned int pixel_bits () const 00282 {return Pixel_Bits;} 00283 00298 JP2_Encoder& pixel_bits (unsigned int bits_per_pixel); 00299 00306 bool signed_data () const 00307 {return Signed_Data;} 00308 00321 JP2_Encoder& signed_data (bool data_is_signed); 00322 00330 bool MSB_data () const; 00331 00344 JP2_Encoder& MSB_data (bool data_is_MSB); 00345 00353 bool swap_pixel_bytes () const 00354 {return Swap_Pixel_Bytes;} 00355 00364 JP2_Encoder& swap_pixel_bytes (bool swap_data) 00365 {Swap_Pixel_Bytes = swap_data; return *this;} 00366 00373 unsigned int line_prefix_bytes () const 00374 {return Line_Prefix_Bytes;} 00375 00382 JP2_Encoder& line_prefix_bytes (unsigned int prefix_bytes) 00383 {Line_Prefix_Bytes = prefix_bytes; return *this;} 00384 00391 unsigned int line_suffix_bytes () const 00392 {return Line_Suffix_Bytes;} 00393 00400 JP2_Encoder& line_suffix_bytes (unsigned int suffix_bytes) 00401 {Line_Suffix_Bytes = suffix_bytes; return *this;} 00402 00409 const Size_2D tile_size () const 00410 {return Tile_Size;} 00411 00421 JP2_Encoder& tile_size (const Size_2D& size) 00422 {Tile_Size = size; return *this;} 00423 00431 unsigned int resolution_levels () const 00432 {return Resolution_Levels;} 00433 00445 JP2_Encoder& resolution_levels (unsigned int resolution_levels); 00446 00452 std::string progression_order () const 00453 {return Progression_Order;} 00454 00475 JP2_Encoder& progression_order (const std::string& progression); 00476 00484 const std::vector<Size_2D> precinct_sizes () const 00485 {return Precinct_Sizes;} 00486 00496 const Size_2D precinct_size 00497 (unsigned int resolution_level = 0) const; 00498 00516 JP2_Encoder& precinct_sizes 00517 (const std::vector<Size_2D>& sizes); 00518 00528 JP2_Encoder& precinct_size 00529 (const Size_2D& size, unsigned int resolution_level = 0); 00530 00536 const Size_2D code_block_size () const 00537 {return Code_Block_Size;} 00538 00546 JP2_Encoder& code_block_size (const Size_2D& size); 00547 00555 JP2_Box::JP2_Box_List& added_boxes () 00556 {return Added_Boxes;} 00557 00567 JP2_Encoder& add_box (JP2_Box* box); 00568 00577 bool remove_box (JP2_Box* box); 00578 00587 const unsigned char* producer_UUID () const 00588 {return Producer_UUID;} 00589 00605 JP2_Encoder& producer_UUID (const unsigned char* id); 00606 00613 bool ready () const; 00614 00621 std::string reasons () const; 00622 00644 int needs () const; 00645 00655 JP2_Encoder_Error* encoder_error () const; 00656 00657 /*============================================================================== 00658 Encoder 00659 */ 00677 long long encode (); 00678 00681 void open (); 00682 00687 long long write_header (); 00688 00699 long long write_user_boxes (); 00700 00704 long long write_codestream (); 00705 00751 JP2_Encoder& incremental_flush_bytes (long long bytes) 00752 {Incremental_Flush_Bytes = ((bytes < 0) ? 0 : bytes); return *this;} 00753 00762 long long incremental_flush_bytes () const 00763 {return Incremental_Flush_Bytes;} 00764 00783 JP2_Encoder& incremental_flush_lines (unsigned int lines); 00784 00803 int incremental_flush_lines () const; 00804 00805 long long close (); 00806 00807 /*============================================================================ 00808 Helpers: 00809 */ 00818 int 00819 invalid_precinct_size (const std::vector<Size_2D>& sizes); 00820 00821 protected: 00822 00838 void read_stripe 00839 (std::istream& source, int band, int line, int lines, kdu_int16* buffer); 00840 00856 void read_stripe 00857 (std::istream& source, int band, int line, int lines, kdu_int32* buffer); 00858 00859 /*============================================================================== 00860 Data Members: 00861 */ 00862 protected: 00863 //------------------------------------------------------------------------------ 00864 // Input: 00865 00867 std::string 00868 Image_Source; 00869 00871 std::string 00872 JP2_Pathname; 00873 00875 std::streamoff 00876 Image_Offset; 00877 00879 unsigned int 00880 Image_Bands; 00881 00882 // Dimensions of the image. 00883 Size_2D 00884 Image_Size; 00885 00891 unsigned int 00892 Line_Prefix_Bytes, 00893 Line_Suffix_Bytes; 00894 00896 unsigned int 00897 Pixel_Bytes; 00898 00900 unsigned int 00901 Pixel_Bits; 00902 00904 bool 00905 Signed_Data; 00906 00907 // JP2 boxes beyond the minimum required. 00908 JP2_Box::JP2_Box_List 00909 Added_Boxes; 00910 00911 //------------------------------------------------------------------------------ 00912 // Output: 00913 00915 std::string 00916 PDS_Label_Pathname; 00917 00919 unsigned char 00920 *Producer_UUID; 00921 00923 bool 00924 Swap_Pixel_Bytes; 00925 00931 unsigned int 00932 Resolution_Levels; 00933 00935 std::string 00936 Progression_Order; 00937 00939 Size_2D 00940 Tile_Size; 00941 00943 std::vector<Size_2D> 00944 Precinct_Sizes; 00945 00947 Size_2D 00948 Code_Block_Size; 00949 00950 long long 00951 Incremental_Flush_Bytes; 00952 00953 private: 00954 //------------------------------------------------------------------------------ 00955 // Kakadu classes used during JP2 file generation. 00956 00958 jp2_family_tgt 00959 *JP2_Stream; 00960 00962 jp2_target 00963 *JP2_Boxes; 00964 00966 kdu_codestream 00967 *JPEG2000_Codestream; 00968 00970 JP2_Encoder_Error 00971 *Encoder_Error; 00972 00973 }; // Class JP2_Encoder 00974 00975 00976 #ifndef DOXYGEN_PROCESSING 00977 /*=***************************************************************************** 00978 JP2_Encoder_Error 00979 */ 00980 class JP2_Encoder_Error 00981 : public kdu_thread_safe_message 00982 { 00983 public: 00984 00985 void put_text (const char* message); 00986 void add_text (const std::string& message); 00987 void flush (bool end_of_message = false); 00988 00989 std::string 00990 Message; 00991 }; 00992 #endif // DOXYGEN_PROCESSING 00993 00994 00995 /*=***************************************************************************** 00996 Functions 00997 */ 01003 bool power_of_2 (unsigned int value); 01004 01005 01006 } // namespace HiRISE 01007 } // namespace UA 01008 #endif
1.5.3