HiRISE
 PDS_JP2

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