HiRISE
 PDS_JP2

JP2_Decoder.hh
Go to the documentation of this file.
1 /* JP2_Decoder
2 
3 HiROC CVS ID: JP2_Decoder.hh,v 1.16 2020/05/14 00:12:14 guym Exp
4 
5 Copyright (C) 2007 Arizona Board of Regents on behalf of the
6 Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
7 the University of Arizona.
8 
9 This library is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License, version 2.1,
11 as published by the Free Software Foundation.
12 
13 This library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with this library; if not, write to the Free Software Foundation,
20 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 */
22 
23 #ifndef _JP2_Decoder_
24 #define _JP2_Decoder_
25 
26 #include "Dimensions.hh"
27 
28 // Kakadu
29 #include "jp2.h"
30 using namespace kdu_supp;
31 
32 #include <string>
33 #include <ios>
34 
35 namespace UA
36 {
37 namespace HiRISE
38 {
39 // Forward reference.
40 class JP2_Decoder_Error;
41 
74 {
75 public:
76 /*==============================================================================
77  Constants:
78 */
80 static const char* const
81  ID;
82 
84 static const char* const
87 static const char* const
90 #define UUID_SIZE 16
92 static const char* const
94 
96 static const int
99 
101 static const int
103 
104 /*==============================================================================
105  Constructors:
106 */
115 JP2_Decoder ();
116 
117 /*==============================================================================
118  Accessors:
119 */
120 //------------------------------------------------------------------------------
121 // Input
122 
128 std::string source () const
129  {return JP2_Pathname;}
130 
140 JP2_Decoder& source (const std::string& pathname);
141 
152  {return Image_Size;}
153 
159 unsigned int image_width () const
160  {return Image_Size.Width;}
161 
167 unsigned int image_height () const
168  {return Image_Size.Height;}
169 
175 unsigned int image_bands () const
176  {return Image_Bands;}
177 
190 unsigned int resolution_levels () const
191  {return Resolution_Levels;}
192 
198 unsigned int pixel_bytes () const
199  {return Pixel_Bytes;}
200 
206 unsigned int pixel_bits () const
207  {return Pixel_Bits;}
208 
215 bool signed_data () const
216  {return Signed_Data;}
217 
229 unsigned char* const producer_UUID () const
230  {return UUID_Info_UUID;}
231 
240 std::string URL () const
241  {return UUID_Info_URL;}
242 
243 //------------------------------------------------------------------------------
244 // Output
245 
251 std::string destination () const
252  {return Image_Destination;}
253 
259 JP2_Decoder& destination (const std::string& pathname)
260  {Image_Destination = pathname; return *this;}
261 
270 Size_2D rendered_size () const;
271 
278 unsigned int rendered_width () const;
279 
286 unsigned int rendered_height () const;
287 
302  {return Image_Region;}
303 
322 JP2_Decoder& image_region (const Rectangle& region);
323 
336 JP2_Decoder& image_region (int x, int y, int width, int height);
337 
343 unsigned int resolution_level () const
344  {return Resolution_Level;}
345 
362 JP2_Decoder& resolution_level (unsigned int level);
363 
369 bool swap_pixel_bytes () const
370  {return Swap_Pixel_Bytes;}
371 
382 JP2_Decoder& swap_pixel_bytes (bool swap_data)
383  {Swap_Pixel_Bytes = swap_data; return *this;}
384 
390 unsigned long long bytes_written () const
391  {return Bytes_Written;}
392 
393 /*==============================================================================
394  Decoder
395 */
403 bool ready () const;
404 
412 std::string reasons () const;
413 
424 unsigned long long decode ();
425 
448 void open ();
449 
455 bool is_open () const;
456 
474 unsigned long long write_image_data ();
475 
488 void close ();
489 
490 JP2_Decoder_Error* decoder_error () const;
491 
492 /*============================================================================
493  Image Data Writers:
494 */
495 protected:
496 
520 std::streamsize write_stripe
521  (std::ostream& destination, std::streamoff file_offset,
522  int band, int line, int lines, kdu_int16* buffer);
523 
547 std::streamsize write_stripe
548  (std::ostream& destination, std::streamoff file_offset,
549  int band, int line, int lines, kdu_int32* buffer);
550 
551 /*============================================================================
552  Helpers:
553 */
554 protected:
555 
586 void
587 set_resolution_and_region
588  (unsigned int level, const Rectangle& region);
589 
590 /*==============================================================================
591  Data Members:
592 */
593 protected:
594 //------------------------------------------------------------------------------
595 // Input:
596 
598 std::string
600 
602 unsigned int
604 
606 Size_2D
608 
610 unsigned int
612 
614 unsigned int
616 
618 bool
620 
631 unsigned int
633 
639 unsigned char
641 
643 std::string
645 
646 //------------------------------------------------------------------------------
647 // Output:
648 
650 std::string
652 
654 Size_2D
656 
658 Rectangle
660 
666 unsigned int
668 
670 bool
672 
674 unsigned long long
676 
677 private:
678 //------------------------------------------------------------------------------
679 // Kakadu classes used during JP2 file rendering.
680 
682 jp2_family_src
683  *JP2_Stream;
684 
686 jp2_source
687  *JP2_Source;
688 
690 kdu_codestream
691  *JPEG2000_Codestream;
692 
693 
695 JP2_Decoder_Error
696  *Decoder_Error;
697 
698 }; // Class JP2_Decoder
699 
700 
701 #ifndef DOXYGEN_PROCESSING
702 /*=*****************************************************************************
703  JP2_Decoder_Error
704 */
705 class JP2_Decoder_Error
706 : public kdu_thread_safe_message
707 {
708 public:
709 
710 void put_text (const char* message);
711 void flush (bool end_of_message = false);
712 
713 std::string
714  Message;
715 };
716 #endif // DOXYGEN_PROCESSING
717 
718 
719 } // namespace HiRISE
720 } // namespace UA
721 #endif
A JP2_Decoder decodes image pixel data from a JPEG2000 JP2 image file.
Definition: JP2_Decoder.hh:74
Rectangle Image_Region
Image region to be rendered.
Definition: JP2_Decoder.hh:659
std::string destination() const
Get the destination file pathname for the rendered image data.
Definition: JP2_Decoder.hh:251
bool signed_data() const
Get the signedness of the pixel data.
Definition: JP2_Decoder.hh:215
bool Signed_Data
Whether pixel data is signed.
Definition: JP2_Decoder.hh:619
unsigned char * UUID_Info_UUID
First UUID value found in a UUID List box of a UUID Info super box.
Definition: JP2_Decoder.hh:640
unsigned int pixel_bytes() const
Get the number of bytes per pixel.
Definition: JP2_Decoder.hh:198
unsigned int image_height() const
Get the height of the JP2 source image.
Definition: JP2_Decoder.hh:167
unsigned int image_width() const
Get the width of the JP2 source image.
Definition: JP2_Decoder.hh:159
unsigned int resolution_levels() const
Get the total number of codestream resolution levels.
Definition: JP2_Decoder.hh:190
static const char *const UUID_INFO_BOX_NAME
PDS label reference information UUID Info JP2 container box name.
Definition: JP2_Decoder.hh:85
JP2_Decoder & destination(const std::string &pathname)
Set the destination file pathname for the rendered image data.
Definition: JP2_Decoder.hh:259
unsigned int Pixel_Bytes
Pixel datum size in bytes.
Definition: JP2_Decoder.hh:611
unsigned int Image_Bands
Total image bands (components).
Definition: JP2_Decoder.hh:603
unsigned long long bytes_written() const
Get the number of image data bytes written.
Definition: JP2_Decoder.hh:390
unsigned int resolution_level() const
Get the resolution level at which the codestream will be rendered.
Definition: JP2_Decoder.hh:343
Rectangle image_region() const
Get the image region that will be rendered from the JP2 source.
Definition: JP2_Decoder.hh:301
std::string JP2_Pathname
JP2 source pathname.
Definition: JP2_Decoder.hh:599
std::string source() const
Get the JP2 source pathname.
Definition: JP2_Decoder.hh:128
static const int MIN_STRIPE_HEIGHT
Image data stripe minimum and maximum number of lines.
Definition: JP2_Decoder.hh:97
static const char *const URL_BOX_NAME
PDS label relative filename URL JP2 box name.
Definition: JP2_Decoder.hh:93
std::string Image_Destination
Image data destination pathname.
Definition: JP2_Decoder.hh:651
unsigned int image_bands() const
Get the number of bands (components) in the JP2 image.
Definition: JP2_Decoder.hh:175
Size_2D image_size() const
Get the size of the JP2 source image.
Definition: JP2_Decoder.hh:151
unsigned int Resolution_Level
Resolution level to render.
Definition: JP2_Decoder.hh:667
Size_2D Rendered_Size
Rendered image size.
Definition: JP2_Decoder.hh:655
unsigned long long Bytes_Written
Total number of pixel bytes written.
Definition: JP2_Decoder.hh:675
unsigned int Resolution_Levels
Resolution levels available.
Definition: JP2_Decoder.hh:632
Size_2D Image_Size
Dimensions of the source image.
Definition: JP2_Decoder.hh:607
JP2_Decoder & swap_pixel_bytes(bool swap_data)
Sets whether multi-byte pixels will be reordered before being written.
Definition: JP2_Decoder.hh:382
std::string URL() const
Get the URL found in the JP2 source.
Definition: JP2_Decoder.hh:240
unsigned int Pixel_Bits
Pixel precision bits.
Definition: JP2_Decoder.hh:615
unsigned char *const producer_UUID() const
Get the UUID found in the JP2 source.
Definition: JP2_Decoder.hh:229
unsigned int pixel_bits() const
Get the pixel precision.
Definition: JP2_Decoder.hh:206
bool Swap_Pixel_Bytes
Whether pixel bytes should be reordered when written.
Definition: JP2_Decoder.hh:671
bool swap_pixel_bytes() const
Tests if multi-byte pixels will be reordered before being written.
Definition: JP2_Decoder.hh:369
std::string UUID_Info_URL
First URL value found in a URL box of a UUID Info super box.
Definition: JP2_Decoder.hh:644
static const int MAX_STRIPE_HEIGHT
Definition: JP2_Decoder.hh:98
static const int DECODER_EXCEPTION
JP2_Decoder_Error exception signal value.
Definition: JP2_Decoder.hh:102
static const char *const UUID_BOX_NAME
Data provider UUID JP2 box name.
Definition: JP2_Decoder.hh:88
static const char *const ID
Class identification name with source code version and date.
Definition: JP2_Decoder.hh:81
Definition: Dimensions.cc:30
A Rectangle is a position with a size.
Definition: Dimensions.hh:223
A Size_2D holds 2-dimensional size information.
Definition: Dimensions.hh:119