24 #include <kdu_region_decompressor.h> 25 #include <kdu_compressed.h> 26 #include <kdu_threads.h> 35 dims.pos.x = rect.
ul().
x;
36 dims.pos.y = rect.
ul().
y;
37 dims.size.x =
static_cast<int>(rect.
width());
38 dims.size.y =
static_cast<int>(rect.
height());
45 dims.pos.x + dims.size.x - 1,
46 dims.pos.y + dims.size.y - 1);
50 kdu_core::kdu_dims& region,
52 kdu_core::kdu_dims& clipRegion)
58 if ( codestream.exists() )
60 codestream.apply_input_restrictions(
61 0, 0, discard_levels, 0, NULL, kdu_core::KDU_WANT_OUTPUT_COMPONENTS);
63 kdu_core::kdu_dims dims;
64 codestream.get_dims(0, dims);
65 if ( region.intersects(dims) )
67 clipRegion = region.intersection(dims);
76 std::vector<ossimIrect>& imageDims,
77 std::vector<ossimIrect>& tileDims)
84 if ( codestream.exists() )
86 kdu_core::kdu_coords tileIdx(0, 0);
94 codestream.apply_input_restrictions(
100 kdu_core::KDU_WANT_OUTPUT_COMPONENTS);
102 kdu_core::kdu_dims dims;
103 codestream.get_dims(0, dims);
109 imageDims.push_back(imageRect);
113 kdu_core::kdu_dims mappedRegion;
114 codestream.map_region(0, dims, mappedRegion,
true);
116 kdu_core::kdu_tile tile = codestream.open_tile(tileIdx);
119 codestream.get_tile_dims( tile.get_tile_idx(), 0, dims );
127 tileDims.push_back(tileRect);
140 codestream.apply_input_restrictions(
146 kdu_core::KDU_WANT_OUTPUT_COMPONENTS);
149 if ( (imageDims.size() != tileDims.size()) ||
150 (tileDims.size() != levels+1) )
165 kdu_core::kdu_codestream& codestream,
167 kdu_core::kdu_thread_env* threadEnv,
168 kdu_core::kdu_thread_queue* threadQueue,
173 if ( channelMapping && destTile && codestream.exists())
177 kdu_core::kdu_dims region;
180 kdu_core::kdu_dims clipRegion;
186 if (region != clipRegion)
195 int max_layers = INT_MAX;
196 kdu_core::kdu_coords expand_numerator(1,1);
197 kdu_core::kdu_coords expand_denominator(1,1);
199 kdu_core::kdu_component_access_mode access_mode =
200 kdu_core::KDU_WANT_OUTPUT_COMPONENTS;
201 bool fastest =
false;
204 kdu_supp::kdu_region_decompressor krd;
205 if ( krd.start( codestream,
220 std::string e =
"kdu_region_decompressor::start error!";
224 bool expand_monochrome =
false;
226 kdu_core::kdu_coords buffer_origin;
229 int row_gap = region.size.x;
230 int suggested_increment =
static_cast<int>(destTile->
getSize());
231 int max_region_pixels = suggested_increment;
232 kdu_core::kdu_dims incomplete_region = clipRegion;
233 kdu_core::kdu_dims new_region;
234 bool measure_row_gap_in_pixels =
true;
237 int precision_bits = (SCALAR !=
OSSIM_SINT16) ? codestream.get_bit_depth(0,
true) : 0;
244 std::vector<kdu_core::kdu_byte*> channel_bufs(BANDS);
250 while ( !incomplete_region.is_empty() )
252 if ( krd.process( &channel_bufs.front(),
262 measure_row_gap_in_pixels ) ==
false )
269 if( threadEnv && threadQueue )
275 threadEnv->join(threadQueue,
true);
292 std::vector<kdu_core::kdu_uint16*> channel_bufs(BANDS);
295 channel_bufs[band] =
static_cast<kdu_core::kdu_uint16*
>(
299 while ( !incomplete_region.is_empty() )
305 if ( krd.process( &channel_bufs.front(),
315 measure_row_gap_in_pixels ) ==
false )
322 if( threadEnv && threadQueue )
328 threadEnv->join(threadQueue,
true);
348 std::vector<ossim_float32*> channel_bufs(BANDS);
354 while ( !incomplete_region.is_empty() )
360 if ( krd.process( &channel_bufs.front(),
370 measure_row_gap_in_pixels ) )
376 if( threadEnv && threadQueue )
382 threadEnv->join(threadQueue,
true);
396 << __FILE__ <<
" " << __LINE__ <<
" Unhandle scalar: " 405 if ( krd.finish() == false )
408 << __FILE__ <<
" " << __LINE__
409 <<
"kdu_region_decompressor::proces error!\n";
424 catch ( kdu_core::kdu_exception exc )
427 if ( threadEnv != 0 )
429 threadEnv->handle_exception(exc);
432 e <<
"Caught exception from kdu_region_decompressor: " << exc <<
"\n";
435 catch ( std::bad_alloc& )
437 if ( threadEnv != 0 )
439 threadEnv->handle_exception(KDU_MEMORY_EXCEPTION);
442 "Caught exception from kdu_region_decompressor: std::bad_alloc";
448 "Caught unhandled exception from kdu_region_decompressor";
466 if (destTile->
write(f))
469 <<
"wrote: " << f << std::endl;
483 kdu_core::kdu_thread_env* threadEnv,
484 kdu_core::kdu_thread_queue* threadQueue,
489 if ( destTile && codestream.exists())
493 kdu_core::kdu_dims region;
496 kdu_core::kdu_dims clipRegion;
502 if (region != clipRegion)
511 kdu_supp::kdu_channel_mapping* mapping = 0;
512 int max_layers = INT_MAX;
513 kdu_core::kdu_coords expand_numerator(1,1);
514 kdu_core::kdu_coords expand_denominator(1,1);
516 kdu_core::kdu_component_access_mode access_mode =
517 kdu_core::KDU_WANT_OUTPUT_COMPONENTS;
518 bool fastest =
false;
529 int single_component = band;
532 kdu_supp::kdu_region_decompressor krd;
534 if ( krd.start( codestream,
549 std::string e =
"kdu_region_decompressor::start error!";
553 vector<int> channel_offsets(1);
554 channel_offsets[0] = 0;
556 kdu_core::kdu_coords buffer_origin;
559 int row_gap = region.size.x;
560 int suggested_increment =
static_cast<int>(destTile->
getSize());
561 int max_region_pixels = suggested_increment;
562 kdu_core::kdu_dims incomplete_region = clipRegion;
563 kdu_core::kdu_dims new_region;
564 bool measure_row_gap_in_pixels =
true;
567 int precision_bits = (SCALAR !=
OSSIM_SINT16) ? codestream.get_bit_depth(0,
true) : 0;
574 kdu_core::kdu_byte* buffer = destTile->
getUcharBuf(band);
576 while ( !incomplete_region.is_empty() )
578 if ( krd.process( buffer,
579 &channel_offsets.front(),
588 measure_row_gap_in_pixels ) )
594 if( threadEnv && threadQueue)
600 threadEnv->join(threadQueue,
true);
617 kdu_core::kdu_uint16* buffer =
618 static_cast<kdu_core::kdu_uint16*
>(destTile->
getBuf(band));
620 while ( !incomplete_region.is_empty() )
626 if ( krd.process( buffer,
627 &channel_offsets.front(),
636 measure_row_gap_in_pixels ) ==
false )
646 if( threadEnv && threadQueue)
648 threadEnv->join(threadQueue,
true);
670 while ( !incomplete_region.is_empty() )
676 if ( krd.process( buffer,
677 &channel_offsets.front(),
686 measure_row_gap_in_pixels ) ==
false )
692 if( threadEnv && threadQueue)
698 threadEnv->join(threadQueue,
true);
713 << __FILE__ <<
" " << __LINE__ <<
" Unhandle scalar: " 722 if ( krd.finish() == false )
726 << __FILE__ <<
" " << __LINE__
727 <<
" kdu_region_decompressor::proces error!" << std::endl;
745 catch ( kdu_core::kdu_exception exc )
748 if ( threadEnv != 0 )
750 threadEnv->handle_exception(exc);
753 e <<
"Caught exception from kdu_region_decompressor: " << exc <<
"\n";
757 catch ( std::bad_alloc& )
759 if ( threadEnv != 0 )
761 threadEnv->handle_exception(KDU_MEMORY_EXCEPTION);
764 "Caught exception from kdu_region_decompressor: std::bad_alloc";
770 "Caught unhandled exception from kdu_region_decompressor";
788 if (destTile->
write(f))
791 <<
"wrote: " << f << std::endl;
820 p = MINP + RANGE * p;
821 p = (p < MAXP ? (p > MINP ? p : MINP) : MAXP);
840 p = MINP + RANGE * p;
841 p = (p < MAXP ? (p > MINP ? p : MINP) : MAXP);
853 << __FILE__ <<
" " << __LINE__ <<
" Unhandle scalar: " 862 out <<
"codestream debug:" 863 <<
"exists: " << (cs.exists()?
"true":
"false");
866 const int BANDS = cs.get_num_components(
true);
867 out <<
"\ncomponents: " << BANDS;
868 for (
int i = 0; i < BANDS; ++i)
870 kdu_core::kdu_dims dims;
871 cs.get_dims(i, dims,
true);
872 out <<
"\nbit_depth[" << i <<
"]: " << cs.get_bit_depth(i,
true)
873 <<
"\nsigned[" << i <<
"]: " << cs.get_signed(i,
true)
874 <<
"\ndims[" << i <<
"]: ";
877 out <<
"\nlevels: " << cs.get_min_dwt_levels();
885 print(out, dims.pos);
887 print(out, dims.size);
894 out <<
"(" << coords.x <<
", " << coords.y <<
")";
virtual const ossim_float64 * getMaxPix() const
16 bit unsigned integer (12 bits used)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
virtual ossim_uint32 getNumberOfBands() const
virtual const ossim_uint8 * getUcharBuf() const
16 bit unsigned integer (14 bits used)
ossim_uint32 height() const
static ossimString toString(bool aValue)
Numeric to string methods.
const ossimIpt & ul() const
16 bit unsigned integer (13 bits used)
std::ostream & print(H5::H5File *file, std::ostream &out)
Print method.
virtual bool write(const ossimFilename &f) const
Writes tile to stream.
virtual ossimDataObjectStatus validate() const
std::ostream & print(std::ostream &out, kdu_core::kdu_codestream &cs)
Convenience print method for kdu_codestream.
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
virtual ossimIrect getImageRectangle() const
ossim_uint32 width() const
void unNormalizeTile(ossimImageData *result)
Un-normalizes float tile from kdu_region_decompressor::process method.
virtual const ossim_float32 * getFloatBuf() const
virtual const ossim_float64 * getMinPix() const
bool clipRegionToImage(kdu_core::kdu_codestream &codestream, kdu_core::kdu_dims ®ion, int discard_levels, kdu_core::kdu_dims &clipRegion)
Sets clipRegion from region, and image dimensions for level.
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
16 bit unsigned integer (15 bits used)
void getDims(const ossimIrect &rect, kdu_core::kdu_dims &dims)
Convenience method to convert ossimIrect to kdu_dims.
bool copyRegionToTile(kdu_supp::kdu_channel_mapping *channelMapping, kdu_core::kdu_codestream &codestream, int discard_levels, kdu_core::kdu_thread_env *threadEnv, kdu_core::kdu_thread_queue *threadQueue, ossimImageData *destTile)
Copies region from codestream to tile at a given rlevel.
virtual ossim_uint32 getSize() const
Returns the total number of pixels in a tile for all bands.
virtual const void * getBuf() const
void getRect(const kdu_core::kdu_dims &dims, ossimIrect &rect)
Convenience method to convert kdu_core::kdu_dims to ossimIrect.
16 bit unsigned integer (11 bits used)
bool getCodestreamDimensions(kdu_core::kdu_codestream &codestream, std::vector< ossimIrect > &imageDims, std::vector< ossimIrect > &tileDims)
Gets image and tile dimensions from codestream for each resolution level (rlevel).
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.