36 using namespace kdu_core;
    37 using namespace kdu_supp;
    48   JP2Decoder::JP2Decoder(
const QString &jp2file) {
    52     p_resolutionLevel = 1;
    57     kdu_customize_errors(Kakadu_Error);
    59     std::string msg = 
"JPEG2000 has not been enabled with this build of ISIS3";
    68   void JP2Decoder::OpenFile() {
    71     if(JP2_Source == NULL) {
    74       JP2_Stream = 
new jp2_family_src();
    75       JP2_Stream->open(p_jp2File.toLatin1().data());
    78       JP2_Source = 
new jp2_source();
    79       if(!JP2_Source->open(JP2_Stream)) {
    80         QString msg = 
"Unable to open the decoder because the source file ";
    81         msg += 
"does not have valid JP2 format content [" + p_jp2File + 
"]";
    86       JP2_Source->read_header();
    89       JPEG2000_Codestream = 
new kdu_codestream();
    90       JPEG2000_Codestream->create(JP2_Source);
    94       p_numBands = JPEG2000_Codestream->get_num_components(
true);
    98       JPEG2000_Codestream->get_dims(0, p_imageDims, 
true); 
   101       p_pixelBits = JPEG2000_Codestream->get_bit_depth(0, 
true);
   102       p_pixelBytes = (p_pixelBits >> 3) + ((p_pixelBits % 8) ? 1 : 0);
   103       if(p_pixelBytes == 3) p_pixelBytes = 4;
   104       if(p_pixelBits > 16 || p_pixelBytes > 2) {
   105         QString msg = 
"The source file has unsupported pixel type ";
   106         msg += 
"[" + p_jp2File + 
"]";
   109       p_signedData = JPEG2000_Codestream->get_signed(0, 
true);
   114       unsigned int pixel_bits;
   116       for(
unsigned int band = 1; band < p_numBands; ++band) {
   117         JPEG2000_Codestream->get_dims(band, dims, 
true);
   118         pixel_bits = JPEG2000_Codestream->get_bit_depth(band, 
true);
   119         signed_data = JPEG2000_Codestream->get_signed(band, 
true);
   120         if(dims.size.x != p_imageDims.size.x || dims.size.y != p_imageDims.size.y ||
   121             dims.pos.x != p_imageDims.pos.x || dims.pos.y != p_imageDims.pos.y ||
   122             pixel_bits != p_pixelBits || signed_data != p_signedData) {
   123           std::string msg = 
"The source file does not have bands with matching ";
   124           msg += 
"characteristics";
   131       p_highestResLevel = JPEG2000_Codestream->get_min_dwt_levels() + 1;
   132       SetResolutionAndRegion();
   136       p_decompressor.start(*JPEG2000_Codestream);
   141       p_stripeHeights = 
new int[p_numBands];
   142       p_maxStripeHeights = 
new int[p_numBands];
   143       p_precisions = 
new int[p_numBands];
   144       p_isSigned = 
new bool[p_numBands];
   145       p_decompressor.get_recommended_stripe_heights(MIN_STRIPE_HEIGHT,
   146           MAX_STRIPE_HEIGHT, p_stripeHeights, p_maxStripeHeights);
   147       for(
unsigned int i = 0; i < p_numBands; i++) {
   148         p_precisions[i] = p_pixelBits;
   149         p_stripeHeights[i] = 1;
   150         p_isSigned[i] = p_signedData;
   161   void JP2Decoder::SetResolutionAndRegion() {
   165     JPEG2000_Codestream->apply_input_restrictions(0, 0, p_resolutionLevel - 1, 0, NULL,
   166         KDU_WANT_OUTPUT_COMPONENTS);
   168     JPEG2000_Codestream->get_dims(0, p_imageDims, 
true);
   169     p_numSamples = p_imageDims.size.x;
   170     p_numLines = p_imageDims.size.y;
   184   void JP2Decoder::Read(
unsigned char **inbuf) {
   186     p_readStripes = p_decompressor.pull_stripe(inbuf, p_stripeHeights, NULL, NULL,
   201   void JP2Decoder::Read(
short int **inbuf) {
   203     p_readStripes = p_decompressor.pull_stripe(inbuf, p_stripeHeights, NULL, NULL,
   204                     p_precisions, p_isSigned);
   212   JP2Decoder::~JP2Decoder() {
   218     p_decompressor.finish();
   219     if(JPEG2000_Codestream) {
   220       JPEG2000_Codestream->destroy();
   222     JPEG2000_Codestream = NULL;
   236     delete [] p_stripeHeights;
   237     delete [] p_maxStripeHeights;
   238     delete [] p_precisions;
   239     delete [] p_isSigned;
   244   bool JP2Decoder::IsJP2(QString filename) {
   246     jp2_family_src *stream = 
new jp2_family_src();
   247     stream->open(filename.toLatin1().data());
   248     jp2_source *source = 
new jp2_source();
   250     bool result = source->open(stream);
 
Namespace for the standard library. 
 
Kakadu error messaging class. 
 
#define _FILEINFO_
Macro for the filename and line number. 
 
Namespace for ISIS/Bullet specific routines.