OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimKakaduCommon.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Description: Common code for this plugin.
8 //
9 //----------------------------------------------------------------------------
10 // $Id: ossimKakaduCommon.cpp 23121 2015-01-30 01:24:56Z dburken $
11 
12 #include "ossimKakaduCommon.h"
14 
16 #include <ossim/base/ossimIrect.h>
18 #include <ossim/base/ossimTrace.h>
22 
23 #include <jp2.h>
24 #include <kdu_region_decompressor.h>
25 #include <kdu_compressed.h>
26 #include <kdu_threads.h>
27 
28 #include <ostream>
29 #include <sstream>
30 
31 static const ossimTrace traceDebug( ossimString("ossimKakaduCommon:debug") );
32 
33 void ossim::getDims(const ossimIrect& rect, kdu_core::kdu_dims& dims)
34 {
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());
39 }
40 
41 void ossim::getRect(const kdu_core::kdu_dims& dims, ossimIrect& rect)
42 {
43  rect = ossimIrect(dims.pos.x,
44  dims.pos.y,
45  dims.pos.x + dims.size.x - 1,
46  dims.pos.y + dims.size.y - 1);
47 }
48 
49 bool ossim::clipRegionToImage(kdu_core::kdu_codestream& codestream,
50  kdu_core::kdu_dims& region,
51  int discard_levels,
52  kdu_core::kdu_dims& clipRegion)
53 {
54  // Clip the region to the image dimensions.
55 
56  bool result = false;
57 
58  if ( codestream.exists() )
59  {
60  codestream.apply_input_restrictions(
61  0, 0, discard_levels, 0, NULL, kdu_core::KDU_WANT_OUTPUT_COMPONENTS);
62 
63  kdu_core::kdu_dims dims;
64  codestream.get_dims(0, dims);
65  if ( region.intersects(dims) )
66  {
67  clipRegion = region.intersection(dims);
68  result = true;
69  }
70  }
71 
72  return result;
73 }
74 
75 bool ossim::getCodestreamDimensions(kdu_core::kdu_codestream& codestream,
76  std::vector<ossimIrect>& imageDims,
77  std::vector<ossimIrect>& tileDims)
78 {
79  bool result = true;
80 
81  imageDims.clear();
82  tileDims.clear();
83 
84  if ( codestream.exists() )
85  {
86  kdu_core::kdu_coords tileIdx(0, 0);
87 
88  ossim_uint32 levels = codestream.get_min_dwt_levels();
89 
90  for (ossim_uint32 level=0; level <= levels; ++level)
91  {
92  // Get the image dimensions.
93 
94  codestream.apply_input_restrictions(
95  0, // first_component
96  0, // max_components (0 = all remaining will appear)
97  level, // highest resolution level
98  0, // max_layers (0 = all layers retained)
99  NULL, // expanded out to block boundary.
100  kdu_core::KDU_WANT_OUTPUT_COMPONENTS);
101 
102  kdu_core::kdu_dims dims;
103  codestream.get_dims(0, dims);
104 
105  // Make the imageRect upper left relative to any sub image offset.
106  ossimIrect imageRect;
107  getRect(dims, imageRect);
108 
109  imageDims.push_back(imageRect);
110 
111  // Get the tile dimensions.
112 
113  kdu_core::kdu_dims mappedRegion;
114  codestream.map_region(0, dims, mappedRegion, true);
115 
116  kdu_core::kdu_tile tile = codestream.open_tile(tileIdx);
117  if ( tile.exists() )
118  {
119  codestream.get_tile_dims( tile.get_tile_idx(), 0, dims );
120 
121  // Make the tile rect zero based.
122  ossimIrect tileRect(0,
123  0,
124  dims.size.x-1,
125  dims.size.y-1);
126 
127  tileDims.push_back(tileRect);
128 
129  // Every open has a close.
130  tile.close();
131  }
132  else
133  {
134  result = false;
135  }
136 
137  } // matches: for (ossim_uint32 level=0; level <= levels; ++level)
138 
139  // Set things back to level 0.
140  codestream.apply_input_restrictions(
141  0, // first_component
142  0, // max_components (0 = all remaining will appear)
143  0, // highest resolution level
144  0, // max_layers (0 = all layers retained)
145  NULL, // expanded out to block boundary.
146  kdu_core::KDU_WANT_OUTPUT_COMPONENTS);
147 
148  // Should be the same sizes as levels.
149  if ( (imageDims.size() != tileDims.size()) ||
150  (tileDims.size() != levels+1) )
151  {
152  result = false;
153  }
154  }
155  else // codestream.exists() == false
156  {
157  result = false;
158  }
159 
160  return result;
161 }
162 
163 // Takes a channel map and decompresses all bands at once.
164 bool ossim::copyRegionToTile(kdu_supp::kdu_channel_mapping* channelMapping,
165  kdu_core::kdu_codestream& codestream,
166  int discard_levels,
167  kdu_core::kdu_thread_env* threadEnv,
168  kdu_core::kdu_thread_queue* threadQueue,
169  ossimImageData* destTile)
170 {
171  bool result = true;
172 
173  if ( channelMapping && destTile && codestream.exists())// && threadEnv && threadQueue )
174  {
175  try // Kakadu throws exceptions...
176  {
177  kdu_core::kdu_dims region;
178  getDims(destTile->getImageRectangle(), region);
179 
180  kdu_core::kdu_dims clipRegion;
181  if ( clipRegionToImage(codestream,
182  region,
183  discard_levels,
184  clipRegion) )
185  {
186  if (region != clipRegion)
187  {
188  // Not filling whole tile.
189  destTile->makeBlank();
190  }
191 
192  const ossim_uint32 BANDS = destTile->getNumberOfBands();
193  const ossimScalarType SCALAR = destTile->getScalarType();
194 
195  int max_layers = INT_MAX;
196  kdu_core::kdu_coords expand_numerator(1,1);
197  kdu_core::kdu_coords expand_denominator(1,1);
198  bool precise = true;
199  kdu_core::kdu_component_access_mode access_mode =
200  kdu_core::KDU_WANT_OUTPUT_COMPONENTS;
201  bool fastest = false;
202 
203  // Start the kdu_region_decompressor.
204  kdu_supp::kdu_region_decompressor krd;
205  if ( krd.start( codestream,
206  channelMapping,
207  -1,
208  discard_levels,
209  max_layers,
210  clipRegion,
211  expand_numerator,
212  expand_denominator,
213  precise,
214  access_mode,
215  fastest,
216  threadEnv,
217  threadQueue )
218  == false)
219  {
220  std::string e = "kdu_region_decompressor::start error!";
221  throw(ossimException(e));
222  }
223 
224  bool expand_monochrome = false;
225  int pixel_gap = 1;
226  kdu_core::kdu_coords buffer_origin;
227  buffer_origin.x = destTile->getImageRectangle().ul().x;
228  buffer_origin.y = destTile->getImageRectangle().ul().y;
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;
235 
236  // For signed int set precision bit to 0 for kakadu.
237  int precision_bits = (SCALAR != OSSIM_SINT16) ? codestream.get_bit_depth(0, true) : 0;
238 
239  switch (SCALAR)
240  {
241  case OSSIM_UINT8:
242  {
243  // Get pointers to the tile buffers.
244  std::vector<kdu_core::kdu_byte*> channel_bufs(BANDS);
245  for ( ossim_uint32 band = 0; band < BANDS; ++band )
246  {
247  channel_bufs[band] = destTile->getUcharBuf(band);
248  }
249 
250  while ( !incomplete_region.is_empty() )
251  {
252  if ( krd.process( &channel_bufs.front(),
253  expand_monochrome,
254  pixel_gap,
255  buffer_origin,
256  row_gap,
257  suggested_increment,
258  max_region_pixels,
259  incomplete_region,
260  new_region,
261  precision_bits,
262  measure_row_gap_in_pixels ) == false )
263  {
264  break;
265  }
266  }
267 
268  // Wait for things to finish.
269  if( threadEnv && threadQueue )
270  {
271  //---
272  // Wait for all queues descended from `root_queue' to identify themselves
273  // as "finished" via the `kdu_thread_queue::all_done' function.
274  //---
275  threadEnv->join(threadQueue, true);
276  }
277 
278  // Validate the tile.
279  destTile->validate();
280 
281  break;
282  }
283  case OSSIM_UINT11:
284  case OSSIM_UINT12:
285  case OSSIM_UINT13:
286  case OSSIM_UINT14:
287  case OSSIM_UINT15:
288  case OSSIM_UINT16:
289  case OSSIM_SINT16:
290  {
291  // Get pointers to the tile buffers.
292  std::vector<kdu_core::kdu_uint16*> channel_bufs(BANDS);
293  for ( ossim_uint32 band = 0; band < BANDS; ++band )
294  {
295  channel_bufs[band] = static_cast<kdu_core::kdu_uint16*>(
296  destTile->getBuf(band));
297  }
298 
299  while ( !incomplete_region.is_empty() )
300  {
301  //---
302  // Note: precision_bits set to 0 to indicate "signed" data
303  // for the region decompressor.
304  //---
305  if ( krd.process( &channel_bufs.front(),
306  expand_monochrome,
307  pixel_gap,
308  buffer_origin,
309  row_gap,
310  suggested_increment,
311  max_region_pixels,
312  incomplete_region,
313  new_region,
314  precision_bits,
315  measure_row_gap_in_pixels ) == false )
316  {
317  break;
318  }
319  }
320 
321  // Wait for things to finish.
322  if( threadEnv && threadQueue )
323  {
324  //---
325  // Wait for all queues descended from `root_queue' to identify themselves
326  // as "finished" via the `kdu_thread_queue::all_done' function.
327  //---
328  threadEnv->join(threadQueue, true);
329  }
330 
331  // Validate the tile.
332  destTile->validate();
333 
334  break;
335  }
336  case OSSIM_SINT32:
337  case OSSIM_FLOAT32:
338  {
339  //---
340  // NOTES:
341  // 1) Signed 32 bit integer data gets normalized when compressed
342  // so use the same code path as float data.
343  // 2) Cannot call "ossimImageData::getFloatBuf" as it will return a
344  // null pointer if the destination tile is OSSIM_SINT32 scalar type.
345  //---
346 
347  // Get pointers to the tile buffers.
348  std::vector<ossim_float32*> channel_bufs(BANDS);
349  for ( ossim_uint32 band = 0; band < BANDS; ++band )
350  {
351  channel_bufs[band] = static_cast<ossim_float32*>(destTile->getBuf(band));
352  }
353 
354  while ( !incomplete_region.is_empty() )
355  {
356  //---
357  // Note: precision_bits set to 0 to indicate "signed" data
358  // for the region decompressor.
359  //---
360  if ( krd.process( &channel_bufs.front(),
361  expand_monochrome,
362  pixel_gap,
363  buffer_origin,
364  row_gap,
365  suggested_increment,
366  max_region_pixels,
367  incomplete_region,
368  new_region,
369  true, // normalize
370  measure_row_gap_in_pixels ) )
371  {
372  break;
373  }
374  }
375 
376  if( threadEnv && threadQueue )
377  {
378  //---
379  // Wait for all queues descended from `root_queue' to identify themselves
380  // as "finished" via the `kdu_thread_queue::all_done' function.
381  //---
382  threadEnv->join(threadQueue, true);
383  }
384 
385  // Un-normalize.
386  ossim::unNormalizeTile(destTile);
387 
388  // Validate the tile.
389  destTile->validate();
390 
391  break;
392  }
393  default:
394  {
396  << __FILE__ << " " << __LINE__ << " Unhandle scalar: "
397  << destTile->getScalarType() << "\n";
398  result = false;
399  break;
400  }
401 
402  } // End of: switch (theScalarType)
403 
404  // Every call to kdu_region_decompressor::start has a finish.
405  if ( krd.finish() == false )
406  {
408  << __FILE__ << " " << __LINE__
409  << "kdu_region_decompressor::proces error!\n";
410  }
411  }
412  else // No region intersect with image.
413  {
414  destTile->makeBlank();
415  }
416 
417  } // Matches: try{ ...
418 
419  // Catch and rethrow exceptions.
420  catch( const ossimException& /* e */ )
421  {
422  throw;
423  }
424  catch ( kdu_core::kdu_exception exc )
425  {
426  // kdu_exception is an int typedef.
427  if ( threadEnv != 0 )
428  {
429  threadEnv->handle_exception(exc);
430  }
431  ostringstream e;
432  e << "Caught exception from kdu_region_decompressor: " << exc << "\n";
433  throw ossimException( e.str() );
434  }
435  catch ( std::bad_alloc& )
436  {
437  if ( threadEnv != 0 )
438  {
439  threadEnv->handle_exception(KDU_MEMORY_EXCEPTION);
440  }
441  std::string e =
442  "Caught exception from kdu_region_decompressor: std::bad_alloc";
443  throw ossimException( e );
444  }
445  catch( ... )
446  {
447  std::string e =
448  "Caught unhandled exception from kdu_region_decompressor";
449  throw ossimException( e );
450  }
451  }
452  else // no codestream
453  {
454  result = false;
455  }
456 
457 #if 0 /* Please leave for serious debug. (drb) */
458  if (destTile)
459  {
460  static int tileNumber = 0;
461  if (destTile)
462  {
463  ossimFilename f = "tile-dump";
465  f += ".ras";
466  if (destTile->write(f))
467  {
469  << "wrote: " << f << std::endl;
470  ++tileNumber;
471  }
472  }
473  }
474 #endif
475 
476  return result;
477 
478 } // End: ossim::copyRegionToTile
479 
480 // Takes a codestream and decompresses band at a time.
481 bool ossim::copyRegionToTile(kdu_core::kdu_codestream& codestream,
482  int discard_levels,
483  kdu_core::kdu_thread_env* threadEnv,
484  kdu_core::kdu_thread_queue* threadQueue,
485  ossimImageData* destTile)
486 {
487  bool result = true;
488 
489  if ( destTile && codestream.exists())// && threadEnv && threadQueue )
490  {
491  try // Kakadu throws exceptions...
492  {
493  kdu_core::kdu_dims region;
494  getDims(destTile->getImageRectangle(), region);
495 
496  kdu_core::kdu_dims clipRegion;
497  if ( clipRegionToImage(codestream,
498  region,
499  discard_levels,
500  clipRegion) )
501  {
502  if (region != clipRegion)
503  {
504  // Not filling whole tile.
505  destTile->makeBlank();
506  }
507 
508  const ossimScalarType SCALAR = destTile->getScalarType();
509  const ossim_uint32 BANDS = destTile->getNumberOfBands();
510 
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);
515  bool precise = true;
516  kdu_core::kdu_component_access_mode access_mode =
517  kdu_core::KDU_WANT_OUTPUT_COMPONENTS;
518  bool fastest = false;
519 
520  //---
521  // band loop:
522  // Note: At some point we may want to be a band selector;
523  // in which case, we would loop through the band list.
524  // For now just go through all bands and let the ossimBandSelector
525  // weed them out.
526  //---
527  for (ossim_uint32 band = 0; band < BANDS; ++band)
528  {
529  int single_component = band;
530 
531  // Start the kdu_region_decompressor.
532  kdu_supp::kdu_region_decompressor krd;
533 
534  if ( krd.start( codestream,
535  mapping,
536  single_component,
537  discard_levels,
538  max_layers,
539  clipRegion,
540  expand_numerator,
541  expand_denominator,
542  precise,
543  access_mode,
544  fastest,
545  threadEnv,
546  threadQueue )
547  == false)
548  {
549  std::string e = "kdu_region_decompressor::start error!";
550  throw(ossimException(e));
551  }
552 
553  vector<int> channel_offsets(1);
554  channel_offsets[0] = 0;
555  int pixel_gap = 1;
556  kdu_core::kdu_coords buffer_origin;
557  buffer_origin.x = destTile->getImageRectangle().ul().x;
558  buffer_origin.y = destTile->getImageRectangle().ul().y;
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;
565 
566  // For signed int set precision bit to 0 for kakadu.
567  int precision_bits = (SCALAR != OSSIM_SINT16) ? codestream.get_bit_depth(0, true) : 0;
568 
569  switch (SCALAR)
570  {
571  case OSSIM_UINT8:
572  {
573  // Get pointer to the tile buffer.
574  kdu_core::kdu_byte* buffer = destTile->getUcharBuf(band);
575 
576  while ( !incomplete_region.is_empty() )
577  {
578  if ( krd.process( buffer,
579  &channel_offsets.front(),
580  pixel_gap,
581  buffer_origin,
582  row_gap,
583  suggested_increment,
584  max_region_pixels,
585  incomplete_region,
586  new_region,
587  precision_bits,
588  measure_row_gap_in_pixels ) )
589  {
590  break;
591  }
592  }
593 
594  if( threadEnv && threadQueue)
595  {
596  //---
597  // Wait for all queues descended from `root_queue' to identify themselves
598  // as "finished" via the `kdu_thread_queue::all_done' function.
599  //---
600  threadEnv->join(threadQueue, true);
601  }
602 
603  // Validate the tile.
604  destTile->validate();
605 
606  break;
607  }
608  case OSSIM_UINT11:
609  case OSSIM_UINT12:
610  case OSSIM_UINT13:
611  case OSSIM_UINT14:
612  case OSSIM_UINT15:
613  case OSSIM_UINT16:
614  case OSSIM_SINT16:
615  {
616  // Get pointer to the tile buffer.
617  kdu_core::kdu_uint16* buffer =
618  static_cast<kdu_core::kdu_uint16*>(destTile->getBuf(band));
619 
620  while ( !incomplete_region.is_empty() )
621  {
622  //---
623  // Note: precision_bits set to 0 to indicate "signed" data
624  // for the region decompressor.
625  //---
626  if ( krd.process( buffer,
627  &channel_offsets.front(),
628  pixel_gap,
629  buffer_origin,
630  row_gap,
631  suggested_increment,
632  max_region_pixels,
633  incomplete_region,
634  new_region,
635  precision_bits,
636  measure_row_gap_in_pixels ) == false )
637  {
638  break;
639  }
640  }
641 
642  //---
643  // Wait for all queues descended from `root_queue' to identify themselves
644  // as "finished" via the `kdu_thread_queue::all_done' function.
645  //---
646  if( threadEnv && threadQueue)
647  {
648  threadEnv->join(threadQueue, true);
649  }
650 
651  // Validate the tile.
652  destTile->validate();
653 
654  break;
655  }
656  case OSSIM_SINT32:
657  case OSSIM_FLOAT32:
658  {
659  //---
660  // NOTES:
661  // 1) Signed 32 bit integer data gets normalized when compressed
662  // so use the same code path as float data.
663  // 2) Cannot call "ossimImageData::getFloatBuf" as it will return a
664  // null pointer if the destination tile is OSSIM_SINT32 scalar type.
665  //---
666 
667  // Get pointer to the tile buffer.
668  ossim_float32* buffer = static_cast<ossim_float32*>(destTile->getBuf(band));
669 
670  while ( !incomplete_region.is_empty() )
671  {
672  //---
673  // Note: precision_bits set to 0 to indicate "signed" data
674  // for the region decompressor.
675  //---
676  if ( krd.process( buffer,
677  &channel_offsets.front(),
678  pixel_gap,
679  buffer_origin,
680  row_gap,
681  suggested_increment,
682  max_region_pixels,
683  incomplete_region,
684  new_region,
685  true, // normalize
686  measure_row_gap_in_pixels ) == false )
687  {
688  break;
689  }
690  }
691 
692  if( threadEnv && threadQueue)
693  {
694  //---
695  // Wait for all queues descended from `root_queue' to identify themselves
696  // as "finished" via the `kdu_thread_queue::all_done' function.
697  //---
698  threadEnv->join(threadQueue, true);
699  }
700 
701  // Un-normalize.
702  ossim::unNormalizeTile(destTile);
703 
704  // Validate the tile.
705  destTile->validate();
706 
707  break;
708  }
709 
710  default:
711  {
713  << __FILE__ << " " << __LINE__ << " Unhandle scalar: "
714  << destTile->getScalarType() << "\n";
715  result = false;
716  break;
717  }
718 
719  } // End of: switch (theScalarType)
720 
721  // Every call to kdu_region_decompressor::start has a finish.
722  if ( krd.finish() == false )
723  {
724  result = false;
726  << __FILE__ << " " << __LINE__
727  << " kdu_region_decompressor::proces error!" << std::endl;
728  }
729 
730 
731  } // End of band loop.
732  }
733  else // No region intersect with image.
734  {
735  destTile->makeBlank();
736  }
737 
738  } // Matches: try{ ...
739 
740  // Catch and rethrow exceptions.
741  catch( const ossimException& /* e */ )
742  {
743  throw;
744  }
745  catch ( kdu_core::kdu_exception exc )
746  {
747  // kdu_exception is an int typedef.
748  if ( threadEnv != 0 )
749  {
750  threadEnv->handle_exception(exc);
751  }
752  ostringstream e;
753  e << "Caught exception from kdu_region_decompressor: " << exc << "\n";
754  throw ossimException( e.str() );
755 
756  }
757  catch ( std::bad_alloc& )
758  {
759  if ( threadEnv != 0 )
760  {
761  threadEnv->handle_exception(KDU_MEMORY_EXCEPTION);
762  }
763  std::string e =
764  "Caught exception from kdu_region_decompressor: std::bad_alloc";
765  throw ossimException( e );
766  }
767  catch( ... )
768  {
769  std::string e =
770  "Caught unhandled exception from kdu_region_decompressor";
771  throw ossimException(e);
772  }
773  }
774  else // no codestream
775  {
776  result = false;
777  }
778 
779 #if 0 /* Please leave for serious debug. (drb) */
780  if (destTile)
781  {
782  static int tileNumber = 0;
783  if (destTile)
784  {
785  ossimFilename f = "tile-dump";
787  f += ".ras";
788  if (destTile->write(f))
789  {
791  << "wrote: " << f << std::endl;
792  ++tileNumber;
793  }
794  }
795  }
796 #endif
797 
798  return result;
799 
800 } // End: ossim::copyRegionToTile
801 
803 {
804  if (result)
805  {
806  const ossim_uint32 SIZE = result->getSize();
807  const ossim_float64 MINP = result->getMinPix(0);
808  const ossim_float64 MAXP = result->getMaxPix(0);
809  const ossim_float64 RANGE = MAXP - MINP;
810 
811  if ( result->getScalarType() == OSSIM_FLOAT32 )
812  {
813  const ossim_float32 NULLP = static_cast<ossim_float32>(result->getNullPix(0));
814  ossim_float32* buf = result->getFloatBuf();
815  for(ossim_uint32 idx = 0; idx < SIZE; ++idx)
816  {
817  ossim_float64 p = buf[idx];
818  if(p > 0.0)
819  {
820  p = MINP + RANGE * p;
821  p = (p < MAXP ? (p > MINP ? p : MINP) : MAXP);
822  buf[idx] = static_cast<ossim_float32>(p);
823  }
824  else
825  {
826  buf[idx] = NULLP;
827  }
828  }
829  }
830  else if ( result->getScalarType() == OSSIM_SINT32 )
831  {
832  const ossim_sint32 NULLP = static_cast<ossim_sint32>(result->getNullPix(0));
833  ossim_float32* inBuf = static_cast<ossim_float32*>(result->getBuf());
834  ossim_sint32* outBuf = static_cast<ossim_sint32*>(result->getBuf());
835  for(ossim_uint32 idx = 0; idx < SIZE; ++idx)
836  {
837  ossim_float64 p = inBuf[idx];
838  if(p > 0.0)
839  {
840  p = MINP + RANGE * p;
841  p = (p < MAXP ? (p > MINP ? p : MINP) : MAXP);
842  outBuf[idx] = static_cast<ossim_sint32>(p);
843  }
844  else
845  {
846  outBuf[idx] = NULLP;
847  }
848  }
849  }
850  else
851  {
853  << __FILE__ << " " << __LINE__ << " Unhandle scalar: "
854  << result->getScalarType() << "\n";
855  }
856  }
857 
858 } // End: ossim::unNormalizeTile
859 
860 std::ostream& ossim::print(std::ostream& out, kdu_core::kdu_codestream& cs)
861 {
862  out << "codestream debug:"
863  << "exists: " << (cs.exists()?"true":"false");
864  if (cs.exists())
865  {
866  const int BANDS = cs.get_num_components(true);
867  out << "\ncomponents: " << BANDS;
868  for (int i = 0; i < BANDS; ++i)
869  {
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 << "]: ";
875  ossim::print(out, dims);
876  }
877  out << "\nlevels: " << cs.get_min_dwt_levels();
878  }
879  return out;
880 }
881 
882 std::ostream& ossim::print(std::ostream& out, const kdu_core::kdu_dims& dims)
883 {
884  out << "pos: ";
885  print(out, dims.pos);
886  out << ", size: ";
887  print(out, dims.size);
888  out << "\n";
889  return out;
890 }
891 
892 std::ostream& ossim::print(std::ostream& out, const kdu_core::kdu_coords& coords)
893 {
894  out << "(" << coords.x << ", " << coords.y << ")";
895  return out;
896 }
virtual const ossim_float64 * getMaxPix() const
16 bit unsigned integer (12 bits used)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual ossim_uint32 getNumberOfBands() const
16 bit unsigned integer
ossim_uint32 tileNumber
virtual const ossim_uint8 * getUcharBuf() const
16 bit unsigned integer (14 bits used)
float ossim_float32
ossim_uint32 height() const
Definition: ossimIrect.h:487
static ossimString toString(bool aValue)
Numeric to string methods.
16 bit signed integer
const ossimIpt & ul() const
Definition: ossimIrect.h:274
16 bit unsigned integer (13 bits used)
std::ostream & print(H5::H5File *file, std::ostream &out)
Print method.
Definition: ossimH5Util.cpp:41
32 bit floating point
virtual bool write(const ossimFilename &f) const
Writes tile to stream.
double ossim_float64
virtual ossimDataObjectStatus validate() const
32 bit signed integer
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
signed int ossim_sint32
virtual ossimIrect getImageRectangle() const
ossim_uint32 width() const
Definition: ossimIrect.h:500
void unNormalizeTile(ossimImageData *result)
Un-normalizes float tile from kdu_region_decompressor::process method.
ossimScalarType
virtual const ossim_float32 * getFloatBuf() const
virtual const ossim_float64 * getMinPix() const
bool clipRegionToImage(kdu_core::kdu_codestream &codestream, kdu_core::kdu_dims &region, 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.
ossim_int32 y
Definition: ossimIpt.h:142
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.
ossim_int32 x
Definition: ossimIpt.h:141
8 bit unsigned integer
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.
Definition: ossimIosFwd.h:23