![]() |
PDS_JP2
|
00001 /* JP2_Decoder 00002 00003 HiROC CVS ID: JP2_Decoder.hh,v 1.16 2020/05/14 00:12:14 guym Exp 00004 00005 Copyright (C) 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_Decoder_ 00024 #define _JP2_Decoder_ 00025 00026 #include "Dimensions.hh" 00027 00028 // Kakadu 00029 #include "jp2.h" 00030 using namespace kdu_supp; 00031 00032 #include <string> 00033 #include <ios> 00034 00035 namespace UA 00036 { 00037 namespace HiRISE 00038 { 00039 // Forward reference. 00040 class JP2_Decoder_Error; 00041 00073 class JP2_Decoder 00074 { 00075 public: 00076 /*============================================================================== 00077 Constants: 00078 */ 00080 static const char* const 00081 ID; 00082 00084 static const char* const 00085 UUID_INFO_BOX_NAME; 00087 static const char* const 00088 UUID_BOX_NAME; 00090 #define UUID_SIZE 16 00091 00092 static const char* const 00093 URL_BOX_NAME; 00094 00096 static const int 00097 MIN_STRIPE_HEIGHT, 00098 MAX_STRIPE_HEIGHT; 00099 00101 static const int 00102 DECODER_EXCEPTION; 00103 00104 /*============================================================================== 00105 Constructors: 00106 */ 00115 JP2_Decoder (); 00116 00117 /*============================================================================== 00118 Accessors: 00119 */ 00120 //------------------------------------------------------------------------------ 00121 // Input 00122 00128 std::string source () const 00129 {return JP2_Pathname;} 00130 00140 JP2_Decoder& source (const std::string& pathname); 00141 00151 Size_2D image_size () const 00152 {return Image_Size;} 00153 00159 unsigned int image_width () const 00160 {return Image_Size.Width;} 00161 00167 unsigned int image_height () const 00168 {return Image_Size.Height;} 00169 00175 unsigned int image_bands () const 00176 {return Image_Bands;} 00177 00190 unsigned int resolution_levels () const 00191 {return Resolution_Levels;} 00192 00198 unsigned int pixel_bytes () const 00199 {return Pixel_Bytes;} 00200 00206 unsigned int pixel_bits () const 00207 {return Pixel_Bits;} 00208 00215 bool signed_data () const 00216 {return Signed_Data;} 00217 00229 unsigned char* const producer_UUID () const 00230 {return UUID_Info_UUID;} 00231 00240 std::string URL () const 00241 {return UUID_Info_URL;} 00242 00243 //------------------------------------------------------------------------------ 00244 // Output 00245 00251 std::string destination () const 00252 {return Image_Destination;} 00253 00259 JP2_Decoder& destination (const std::string& pathname) 00260 {Image_Destination = pathname; return *this;} 00261 00270 Size_2D rendered_size () const; 00271 00278 unsigned int rendered_width () const; 00279 00286 unsigned int rendered_height () const; 00287 00301 Rectangle image_region () const 00302 {return Image_Region;} 00303 00322 JP2_Decoder& image_region (const Rectangle& region); 00323 00336 JP2_Decoder& image_region (int x, int y, int width, int height); 00337 00343 unsigned int resolution_level () const 00344 {return Resolution_Level;} 00345 00362 JP2_Decoder& resolution_level (unsigned int level); 00363 00369 bool swap_pixel_bytes () const 00370 {return Swap_Pixel_Bytes;} 00371 00382 JP2_Decoder& swap_pixel_bytes (bool swap_data) 00383 {Swap_Pixel_Bytes = swap_data; return *this;} 00384 00390 unsigned long long bytes_written () const 00391 {return Bytes_Written;} 00392 00393 /*============================================================================== 00394 Decoder 00395 */ 00403 bool ready () const; 00404 00412 std::string reasons () const; 00413 00424 unsigned long long decode (); 00425 00448 void open (); 00449 00455 bool is_open () const; 00456 00474 unsigned long long write_image_data (); 00475 00488 void close (); 00489 00490 JP2_Decoder_Error* decoder_error () const; 00491 00492 /*============================================================================ 00493 Image Data Writers: 00494 */ 00495 protected: 00496 00520 std::streamsize write_stripe 00521 (std::ostream& destination, std::streamoff file_offset, 00522 int band, int line, int lines, kdu_int16* buffer); 00523 00547 std::streamsize write_stripe 00548 (std::ostream& destination, std::streamoff file_offset, 00549 int band, int line, int lines, kdu_int32* buffer); 00550 00551 /*============================================================================ 00552 Helpers: 00553 */ 00554 protected: 00555 00586 void 00587 set_resolution_and_region 00588 (unsigned int level, const Rectangle& region); 00589 00590 /*============================================================================== 00591 Data Members: 00592 */ 00593 protected: 00594 //------------------------------------------------------------------------------ 00595 // Input: 00596 00598 std::string 00599 JP2_Pathname; 00600 00602 unsigned int 00603 Image_Bands; 00604 00606 Size_2D 00607 Image_Size; 00608 00610 unsigned int 00611 Pixel_Bytes; 00612 00614 unsigned int 00615 Pixel_Bits; 00616 00618 bool 00619 Signed_Data; 00620 00631 unsigned int 00632 Resolution_Levels; 00633 00639 unsigned char 00640 *UUID_Info_UUID; 00641 00643 std::string 00644 UUID_Info_URL; 00645 00646 //------------------------------------------------------------------------------ 00647 // Output: 00648 00650 std::string 00651 Image_Destination; 00652 00654 Size_2D 00655 Rendered_Size; 00656 00658 Rectangle 00659 Image_Region; 00660 00666 unsigned int 00667 Resolution_Level; 00668 00670 bool 00671 Swap_Pixel_Bytes; 00672 00674 unsigned long long 00675 Bytes_Written; 00676 00677 private: 00678 //------------------------------------------------------------------------------ 00679 // Kakadu classes used during JP2 file rendering. 00680 00682 jp2_family_src 00683 *JP2_Stream; 00684 00686 jp2_source 00687 *JP2_Source; 00688 00690 kdu_codestream 00691 *JPEG2000_Codestream; 00692 00693 00695 JP2_Decoder_Error 00696 *Decoder_Error; 00697 00698 }; // Class JP2_Decoder 00699 00700 00701 #ifndef DOXYGEN_PROCESSING 00702 /*=***************************************************************************** 00703 JP2_Decoder_Error 00704 */ 00705 class JP2_Decoder_Error 00706 : public kdu_thread_safe_message 00707 { 00708 public: 00709 00710 void put_text (const char* message); 00711 void flush (bool end_of_message = false); 00712 00713 std::string 00714 Message; 00715 }; 00716 #endif // DOXYGEN_PROCESSING 00717 00718 00719 } // namespace HiRISE 00720 } // namespace UA 00721 #endif