HiRISE
 PDS_JP2

JP2_Decoder.hh

Go to the documentation of this file.
00001 /*  JP2_Decoder
00002 
00003 HiROC CVS ID: JP2_Decoder.hh,v 1.14 2007/12/13 05:18:56 castalia 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 
00031 #include    <string>
00032 #include    <iosfwd>
00033 
00034 namespace UA
00035 {
00036 namespace HiRISE
00037 {
00038 //  Forward reference.
00039 class JP2_Decoder_Error;
00040 
00072 class JP2_Decoder
00073 {
00074 public:
00075 /*==============================================================================
00076     Constants:
00077 */
00079 static const char* const
00080     ID;
00081 
00083 static const char* const
00084     UUID_INFO_BOX_NAME;
00086 static const char* const
00087     UUID_BOX_NAME;
00089 #define UUID_SIZE   16
00090 
00091 static const char* const
00092     URL_BOX_NAME;
00093 
00095 static const int
00096     MIN_STRIPE_HEIGHT,
00097     MAX_STRIPE_HEIGHT;
00098 
00100 static const int
00101     DECODER_EXCEPTION;
00102 
00103 /*==============================================================================
00104     Constructors:
00105 */
00114 JP2_Decoder ();
00115 
00116 /*==============================================================================
00117     Accessors:
00118 */
00119 //------------------------------------------------------------------------------
00120 //  Input
00121 
00127 std::string source () const
00128     {return JP2_Pathname;}
00129 
00139 JP2_Decoder& source (const std::string& pathname);
00140 
00150 Size_2D image_size () const
00151     {return Image_Size;}
00152 
00158 unsigned int image_width () const
00159     {return Image_Size.Width;}
00160 
00166 unsigned int image_height () const
00167     {return Image_Size.Height;}
00168 
00174 unsigned int image_bands () const
00175     {return Image_Bands;}
00176 
00189 unsigned int resolution_levels () const
00190     {return Resolution_Levels;}
00191 
00197 unsigned int pixel_bytes () const
00198     {return Pixel_Bytes;}
00199 
00205 unsigned int pixel_bits () const
00206     {return Pixel_Bits;}
00207 
00214 bool signed_data () const
00215     {return Signed_Data;}
00216 
00228 unsigned char* const producer_UUID () const
00229     {return UUID_Info_UUID;}
00230 
00239 std::string URL () const
00240     {return UUID_Info_URL;}
00241 
00242 //------------------------------------------------------------------------------
00243 //  Output
00244 
00250 std::string destination () const
00251     {return Image_Destination;}
00252 
00258 JP2_Decoder& destination (const std::string& pathname)
00259     {Image_Destination = pathname; return *this;}
00260 
00269 Size_2D rendered_size () const;
00270 
00277 unsigned int rendered_width () const;
00278 
00285 unsigned int rendered_height () const;
00286 
00300 Rectangle image_region () const
00301     {return Image_Region;}
00302 
00321 JP2_Decoder& image_region (const Rectangle& region);
00322 
00335 JP2_Decoder& image_region (int x, int y, int width, int height);
00336 
00342 unsigned int resolution_level () const
00343     {return Resolution_Level;}
00344 
00361 JP2_Decoder& resolution_level (unsigned int level);
00362 
00368 bool swap_pixel_bytes () const
00369     {return Swap_Pixel_Bytes;}
00370 
00381 JP2_Decoder& swap_pixel_bytes (bool swap_data)
00382     {Swap_Pixel_Bytes = swap_data; return *this;}
00383 
00389 unsigned long long bytes_written () const
00390     {return Bytes_Written;}
00391 
00392 /*==============================================================================
00393     Decoder
00394 */
00402 bool ready () const;
00403 
00411 std::string reasons () const;
00412 
00423 unsigned long long decode ();
00424 
00447 void open ();
00448 
00454 bool is_open () const;
00455 
00473 unsigned long long write_image_data ();
00474 
00487 void close ();
00488 
00489 JP2_Decoder_Error* decoder_error () const;
00490 
00491 /*============================================================================
00492     Image Data Writers:
00493 */
00494 protected:
00495 
00519 std::streamsize write_stripe
00520     (std::ostream& destination, std::streamoff file_offset,
00521         int band, int line, int lines, kdu_int16* buffer);
00522 
00546 std::streamsize write_stripe
00547     (std::ostream& destination, std::streamoff file_offset,
00548         int band, int line, int lines, kdu_int32* buffer);
00549 
00550 /*============================================================================
00551     Helpers:
00552 */
00553 protected:
00554 
00585 void
00586 set_resolution_and_region
00587     (unsigned int level, const Rectangle& region);
00588 
00589 /*==============================================================================
00590     Data Members:
00591 */
00592 protected:
00593 //------------------------------------------------------------------------------
00594 //  Input:
00595 
00597 std::string
00598     JP2_Pathname;
00599 
00601 unsigned int
00602     Image_Bands;
00603 
00605 Size_2D
00606     Image_Size;
00607 
00609 unsigned int
00610     Pixel_Bytes;
00611 
00613 unsigned int
00614     Pixel_Bits;
00615 
00617 bool
00618     Signed_Data;
00619 
00630 unsigned int
00631     Resolution_Levels;
00632 
00638 unsigned char
00639     *UUID_Info_UUID;
00640 
00642 std::string
00643     UUID_Info_URL;
00644 
00645 //------------------------------------------------------------------------------
00646 //  Output:
00647 
00649 std::string
00650     Image_Destination;
00651 
00653 Size_2D
00654     Rendered_Size;
00655 
00657 Rectangle
00658     Image_Region;
00659 
00665 unsigned int
00666     Resolution_Level;
00667 
00669 bool
00670     Swap_Pixel_Bytes;
00671 
00673 unsigned long long
00674     Bytes_Written;
00675 
00676 private:
00677 //------------------------------------------------------------------------------
00678 //  Kakadu classes used during JP2 file rendering.
00679 
00681 jp2_family_src
00682     *JP2_Stream;
00683 
00685 jp2_source
00686     *JP2_Source;
00687 
00689 kdu_codestream
00690     *JPEG2000_Codestream;
00691 
00692 
00694 JP2_Decoder_Error
00695     *Decoder_Error;
00696 
00697 };  //  Class JP2_Decoder
00698 
00699 
00700 #ifndef DOXYGEN_PROCESSING
00701 /*=*****************************************************************************
00702     JP2_Decoder_Error
00703 */
00704 class JP2_Decoder_Error
00705 :   public kdu_thread_safe_message
00706 {
00707 public:
00708 
00709 void put_text (const char* message);
00710 void flush (bool end_of_message = false);
00711 
00712 std::string
00713     Message;
00714 };
00715 #endif  //  DOXYGEN_PROCESSING
00716 
00717 
00718 }   //  namespace HiRISE
00719 }   //  namespace UA
00720 #endif

Generated on Tue Jul 15 14:22:43 2008 for UA::HiRISE::PDS_JP2 by  doxygen 1.4.6