OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageData.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: MIT
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 //*************************************************************************
10 // $Id$
11 
14 //#include <ossim/base/ossimErrorContext.h>
17 //#include <ossim/base/ossimIrect.h>
20 #include <ossim/base/ossimNotify.h>
21 #include <ossim/base/ossimRtti.h>
23 //#include <ossim/base/ossimSource.h>
24 #include <ossim/base/ossimString.h>
26 #include <algorithm>
27 #include <cstring>
28 #include <fstream>
29 #include <iostream>
30 #include <iterator>
31 //#include <ostream>
32 
33 
35 
38  0, // owner
39  1, // bands
40  OSSIM_UINT8), // scalar
41  m_nullPixelValue(0),
42  m_minPixelValue(0),
43  m_maxPixelValue(0),
44  m_alpha(0),
45  m_origin(0, 0),
46  m_indexedFlag(false),
47  m_histogram(NULL)
48 {
49  ossimIpt tileSize;
50  ossim::defaultTileSize(tileSize);
51  m_spatialExtents[0] = tileSize.x;
52  m_spatialExtents[1] = tileSize.y;
53  initializeDefaults();
54 }
55 
57  ossimScalarType scalar,
58  ossim_uint32 bands)
60  owner,
61  bands,
62  scalar),
63  m_nullPixelValue(0),
64  m_minPixelValue(0),
65  m_maxPixelValue(0),
66  m_alpha(0),
67  m_origin(0, 0),
68  m_indexedFlag(false),
69  m_histogram(NULL)
70 {
71  ossimIpt tileSize;
72  ossim::defaultTileSize(tileSize);
73  m_spatialExtents[0] = tileSize.x;
74  m_spatialExtents[1] = tileSize.y;
76 }
77 
79  ossimScalarType scalar,
80  ossim_uint32 bands,
81  ossim_uint32 width,
82  ossim_uint32 height)
84  bands,
85  width, // 2-D array
86  height,
87  scalar),
88  m_nullPixelValue(0),
89  m_minPixelValue(0),
90  m_maxPixelValue(0),
91  m_alpha(0),
92  m_origin(0, 0),
93  m_indexedFlag(false),
94  m_histogram(NULL),
95  m_percentFull(0)
96 {
97  m_spatialExtents[0] = width;
98  m_spatialExtents[1] = height;
100 }
101 
104  m_nullPixelValue(rhs.m_nullPixelValue),
105  m_minPixelValue(rhs.m_minPixelValue),
106  m_maxPixelValue(rhs.m_maxPixelValue),
107  m_alpha(rhs.m_alpha),
108  m_origin(rhs.m_origin),
109  m_indexedFlag(rhs.m_indexedFlag),
110  m_percentFull(0)
111 {
112 }
113 
115 {
116  if (this != &rhs)
117  {
118  // ossimRectilinearDataObject initialization:
120 
121  // ossimImageData (this) members:
125  m_alpha = rhs.m_alpha;
126  m_origin = rhs.m_origin;
128  }
129  return *this;
130 }
131 
133 {
134 }
135 
137 {
138  return (band<getNumberOfDataComponents());
139 }
140 
142 {
144 }
145 
147 {
148  return (getHeight() * getWidth());
149 }
150 
152 {
154 }
155 
157 {
158  return (getHeight() * getWidth() * getScalarSizeInBytes());
159 }
160 
162 {
163  if (m_alpha.size() > 0)
164  {
165  return &m_alpha.front();
166  }
167  return 0;
168 }
169 
171 {
172  if (m_alpha.size() > 0)
173  {
174  return &m_alpha.front();
175  }
176  return 0;
177 }
178 
179 const void* ossimImageData::getBuf() const
180 {
181  if (m_dataBuffer.size() > 0)
182  {
183  return static_cast<const void*>(&m_dataBuffer.front());
184  }
185  return 0;
186 }
187 
189 {
190  if (m_dataBuffer.size() > 0)
191  {
192  return static_cast<void*>(&m_dataBuffer.front());
193  }
194  return 0;
195 }
196 
197 const void* ossimImageData::getBuf(ossim_uint32 band) const
198 {
199  const ossim_uint8* b = static_cast<const ossim_uint8*>(getBuf());
200 
201  if (isValidBand(band) && b != 0)
202  {
203  b += (band * getSizePerBandInBytes());
204  return static_cast<const void*>(b);
205  }
206  return 0;
207 }
208 
210 {
211  ossim_uint8* b = static_cast<ossim_uint8*>(getBuf());
212 
213  if (isValidBand(band) && b != 0)
214  {
215  b += (band * getSizePerBandInBytes());
216  return static_cast<void*>(b);
217  }
218  return 0;
219 }
220 
222 {
223  if (m_scalarType == OSSIM_UINT8)
224  {
225  return static_cast<const ossim_uint8*>(getBuf());
226  }
227  return 0;
228 }
229 
231 {
232  if (m_scalarType == OSSIM_UINT16 ||
238  {
239  return static_cast<const ossim_uint16*>(getBuf());
240  }
241  return 0;
242 }
243 
245 {
246  if (m_scalarType == OSSIM_SINT16)
247  {
248  return static_cast<const ossim_sint16*>(getBuf());
249  }
250  return 0;
251 }
252 
254 {
255  if (m_scalarType == OSSIM_FLOAT32 ||
257  {
258  return static_cast<const ossim_float32*>(getBuf());
259  }
260  return 0;
261 }
262 
264 {
265  if (m_scalarType == OSSIM_FLOAT64 ||
267  {
268  return static_cast<const ossim_float64*>(getBuf());
269  }
270  return 0;
271 }
272 
274 {
275  if (m_scalarType == OSSIM_UINT8)
276  {
277  return static_cast<ossim_uint8*>(getBuf());
278  }
279  return 0;
280 }
281 
283 {
284  if (m_scalarType == OSSIM_UINT16 ||
290  {
291  return static_cast<ossim_uint16*>(getBuf());
292  }
293  return 0;
294 }
295 
297 {
298  if (m_scalarType == OSSIM_SINT16)
299  {
300  return static_cast<ossim_sint16*>(getBuf());
301  }
302  return 0;
303 }
304 
306 {
307  if (m_scalarType == OSSIM_FLOAT32 ||
309  {
310  return static_cast<ossim_float32*>(getBuf());
311  }
312  return 0;
313 }
314 
316 {
317  if (m_scalarType == OSSIM_FLOAT64 ||
319  {
320  return static_cast<ossim_float64*>(getBuf());
321  }
322  return 0;
323 }
324 
326 {
327  if (m_scalarType == OSSIM_UINT8)
328  {
329  return static_cast<const ossim_uint8*>(getBuf(band));
330  }
331  return 0;
332 }
333 
335 {
336  if (m_scalarType == OSSIM_UINT16 ||
342  {
343  return static_cast<const ossim_uint16*>(getBuf(band));
344  }
345  return 0;
346 }
347 
349 {
350  if (m_scalarType == OSSIM_SINT16)
351  {
352  return static_cast<const ossim_sint16*>(getBuf(band));
353  }
354  return 0;
355 }
356 
358 {
359  if (m_scalarType == OSSIM_FLOAT32 ||
361  {
362  return static_cast<const ossim_float32*>(getBuf(band));
363  }
364  return 0;
365 }
366 
368 {
369  if (m_scalarType == OSSIM_FLOAT64 ||
371  {
372  return static_cast<const ossim_float64*>(getBuf(band));
373  }
374  return 0;
375 }
376 
378 {
379  if (m_scalarType == OSSIM_UINT8)
380  {
381  return static_cast<ossim_uint8*>(getBuf(band));
382  }
383  return 0;
384 }
385 
387 {
388  if (m_scalarType == OSSIM_UINT16 ||
394  {
395  return static_cast<ossim_uint16*>(getBuf(band));
396  }
397  return 0;
398 }
399 
401 {
402  if (m_scalarType == OSSIM_SINT16)
403  {
404  return static_cast<ossim_sint16*>(getBuf(band));
405  }
406  return 0;
407 }
408 
410 {
411  if (m_scalarType == OSSIM_FLOAT32 ||
413  {
414  return static_cast<ossim_float32*>(getBuf(band));
415  }
416  return 0;
417 }
418 
420 {
421  if (m_scalarType == OSSIM_FLOAT64 ||
423  {
424  return static_cast<ossim_float64*>(getBuf(band));
425  }
426  return 0;
427 }
428 
430  ossim_uint32 bandNumber,
431  ossim_float32& result)const
432 {
433  // Make sure that the types and width and height are good.
434  if( (getDataObjectStatus() != OSSIM_NULL) && (bandNumber < getNumberOfDataComponents()) )
435  {
436  ossim_float32 p = 0.0;
437 
438  switch (getScalarType())
439  {
440  case OSSIM_UINT8:
441  {
442  const unsigned char* sourceBuf = getUcharBuf(bandNumber);
443  p = sourceBuf[offset];
444  break;
445  }
446  case OSSIM_SINT8:
447  {
448  const ossim_sint8* sourceBuf = static_cast<const ossim_sint8*>(getBuf(bandNumber));
449  p = sourceBuf[offset];
450  break;
451  }
452  case OSSIM_USHORT11:
453  case OSSIM_USHORT12:
454  case OSSIM_USHORT13:
455  case OSSIM_USHORT14:
456  case OSSIM_USHORT15:
457  case OSSIM_UINT16:
458  {
459  const ossim_uint16* sourceBuf = getUshortBuf(bandNumber);
460  p = sourceBuf[offset];
461  break;
462  }
463  case OSSIM_SINT16:
464  {
465  const ossim_sint16* sourceBuf = getSshortBuf(bandNumber);
466  p = sourceBuf[offset];
467  break;
468  }
469  case OSSIM_UINT32:
470  {
471  const ossim_uint32* sourceBuf =
472  static_cast<const ossim_uint32*>(getBuf(bandNumber));
473  p = sourceBuf[offset];
474  break;
475  }
476  case OSSIM_SINT32:
477  {
478  const ossim_sint32* sourceBuf = static_cast<const ossim_sint32*>(getBuf(bandNumber));
479  p = sourceBuf[offset];
480  break;
481  }
483  case OSSIM_FLOAT32:
484  {
485  const ossim_float32* sourceBuf = getFloatBuf(bandNumber);
486  p = sourceBuf[offset];
487  break;
488  }
489  case OSSIM_FLOAT64:
491  {
492  const ossim_float64* sourceBuf = getDoubleBuf(bandNumber);
493  p = sourceBuf[offset];
494  break;
495  }
497  default:
498  {
499  // Shouldn't hit this.
501  << "ossimImageData::setNormalizedFloat Unsupported scalar type!"
502  << std::endl;
503  }
504 
505  } // Matches: switch (getScalarType())
506 
507  if ( p != m_nullPixelValue[bandNumber] )
508  {
509  const ossim_float32 DELTA = m_maxPixelValue[bandNumber] - m_minPixelValue[bandNumber] - 1;
510  const ossim_float32 OFFSET_TO_ONE = 1 - m_minPixelValue[bandNumber];
511 
512  result = ( p <= m_maxPixelValue[bandNumber] ) ?
513  ( ( p >= m_minPixelValue[bandNumber] ) ? ( p + OFFSET_TO_ONE ) / DELTA : 0.0 ) : 1.0;
514  }
515  else
516  {
517  result = 0.0;
518  }
519 
520  } // Matches: if( (getDataObjectStatus() ...
521 
522 } // End: ossimImageData::getNormalizedFloat
523 
525  ossim_uint32 bandNumber,
526  ossim_float32 inputValue)
527 {
528  // Make sure that the types and width and height are good.
529  if( (getDataObjectStatus() != OSSIM_NULL) && (bandNumber < getNumberOfDataComponents()) )
530  {
531 
532  ossim_float32 p = 0.0;
533 
534  if ( inputValue )
535  {
536  const ossim_float32 DELTA = m_maxPixelValue[bandNumber] - m_minPixelValue[bandNumber] - 1;
537  const ossim_float32 OFFSET_TO_MIN = m_minPixelValue[bandNumber] - 1;
538  p = inputValue * DELTA + OFFSET_TO_MIN + 0.5;
539  if ( p > m_maxPixelValue[bandNumber] )
540  {
541  p = m_maxPixelValue[bandNumber];
542  }
543  }
544  else
545  {
546  p = m_nullPixelValue[bandNumber];
547  }
548 
549  switch (getScalarType())
550  {
551  case OSSIM_UINT8:
552  {
553  unsigned char* sourceBuf = getUcharBuf(bandNumber);
554  sourceBuf[offset] = static_cast<ossim_uint8>( p );
555  break;
556  }
557  case OSSIM_SINT8:
558  {
559  ossim_sint8* sourceBuf = static_cast<ossim_sint8*>(getBuf(bandNumber));
560  sourceBuf[offset] = static_cast<ossim_sint8>( p );
561  break;
562  }
563  case OSSIM_USHORT11:
564  case OSSIM_USHORT12:
565  case OSSIM_USHORT13:
566  case OSSIM_USHORT14:
567  case OSSIM_USHORT15:
568  case OSSIM_UINT16:
569  {
570  ossim_uint16* sourceBuf = getUshortBuf(bandNumber);
571  sourceBuf[offset] = static_cast<ossim_uint16>( p );
572  break;
573  }
574  case OSSIM_SINT16:
575  {
576  ossim_sint16* sourceBuf = getSshortBuf(bandNumber);
577  sourceBuf[offset] = static_cast<ossim_sint16>( p );
578  break;
579  }
580  case OSSIM_UINT32:
581  {
582  ossim_uint32* sourceBuf = static_cast<ossim_uint32*>(getBuf(bandNumber));
583  sourceBuf[offset] = static_cast<ossim_uint32>( p );
584  break;
585  }
586  case OSSIM_SINT32:
587  {
588  ossim_sint32* sourceBuf = static_cast<ossim_sint32*>(getBuf(bandNumber));
589  sourceBuf[offset] = static_cast<ossim_sint32>( p );
590  break;
591  }
593  case OSSIM_FLOAT32:
594  {
595  ossim_float32* sourceBuf = getFloatBuf(bandNumber);
596  sourceBuf[offset] = p;
597  break;
598  }
599  case OSSIM_FLOAT64:
601  {
602  ossim_float64* sourceBuf = getDoubleBuf(bandNumber);
603  sourceBuf[offset] = p;
604  break;
605  }
607  default:
608  // Shouldn't hit this.
610  << "ossimImageData::setNormalizedFloat Unsupported scalar type!"
611  << std::endl;
612 
613  } // Matches: switch (getScalarType())
614 
615  } // Matches: if( (getDataObjectStatus() ...
616 
617 } // End: ossimImageData::setNormalizedFloat
618 
620 {
621  if(!result)
622  {
623  return;
624  }
625  // make sure that the types and width and height are
626  // good.
627  if( (result->getScalarType() != OSSIM_NORMALIZED_FLOAT) ||
628  (result->getNumberOfBands() != this->getNumberOfBands())||
629  (result->getWidth() != this->getWidth()) ||
630  (result->getHeight() != this->getHeight())||
631  (result->getDataObjectStatus() == OSSIM_NULL) ||
633  {
634  return;
635  }
636 
639 }
640 
642 {
644  new ossimImageData(0,
646  this->getNumberOfBands(),
647  this->getWidth(),
648  this->getHeight());
649 
650  result->initialize();
651 
652  convertToNormalizedFloat(result.get());
653 
654  return result;
655 }
656 
658 {
659  if(!result)
660  {
661  return;
662  }
663  // make sure that the types and width and height are
664  // good.
665  if( (result->getScalarType() != OSSIM_NORMALIZED_DOUBLE) ||
666  (result->getNumberOfBands() != this->getNumberOfBands())||
667  (result->getWidth() != this->getWidth()) ||
668  (result->getHeight() != this->getHeight())||
669  (result->getDataObjectStatus() == OSSIM_NULL) ||
671  {
672  return;
673  }
674 
677 }
678 
680 {
681  ossimImageData* result = new ossimImageData(0,
683  this->getNumberOfBands(),
684  this->getWidth(),
685  this->getHeight());
686  result->initialize();
687 
689 
690  return result;
691 }
692 
693 
695 {
696  if((normalizedInput->getScalarType() != OSSIM_NORMALIZED_FLOAT) &&
697  (normalizedInput->getScalarType() != OSSIM_NORMALIZED_DOUBLE) )
698  {
699  //ERROR
700  return;
701  }
702 
703  if(normalizedInput->getScalarType() == OSSIM_NORMALIZED_DOUBLE)
704  {
705  copyNormalizedBufferToTile((ossim_float64*)normalizedInput->getBuf());
706  }
707  else
708  {
709  copyNormalizedBufferToTile((ossim_float32*)normalizedInput->getBuf());
710  }
711 }
712 
714  ossim_float64 meanValue,
715  ossim_uint32 bandNumber) const
716 {
717  ossim_float64 result = -1; // invalid MSE
718 
719  switch (getScalarType())
720  {
721  case OSSIM_UINT8:
722  {
724  meanValue,
725  bandNumber);
726  break;
727  }
728  case OSSIM_SINT8:
729  {
731  meanValue,
732  bandNumber);
733  break;
734  }
735  case OSSIM_UINT16:
736  case OSSIM_USHORT11:
737  case OSSIM_USHORT12:
738  case OSSIM_USHORT13:
739  case OSSIM_USHORT14:
740  case OSSIM_USHORT15:
741  {
743  meanValue,
744  bandNumber);
745  break;
746  }
747  case OSSIM_SINT16:
748  {
750  meanValue,
751  bandNumber);
752  break;
753  }
754  case OSSIM_UINT32:
755  {
757  meanValue,
758  bandNumber);
759  break;
760  }
761  case OSSIM_SINT32:
762  {
764  meanValue,
765  bandNumber);
766  break;
767  }
768  case OSSIM_FLOAT32:
770  {
772  meanValue,
773  bandNumber);
774  break;
775  }
777  case OSSIM_FLOAT64:
778  {
780  meanValue,
781  bandNumber);
782  break;
783  }
785  default:
786  {
790  "ossimImageData::computeMeanSquaredError File %s line %d\n\
791 Invalid scalar type: %d",
792 __FILE__,
793 __LINE__,
794 getScalarType());
795  break;
796  }
797  }
798 
799  return result;
800 }
801 
803  T, /* dummyTemplate */
804  ossim_float64 meanValue,
805  ossim_uint32 bandNumber) const
806 {
807  ossim_float64 result = -1.0; // invalid MSE
808 
809  if ( (getDataObjectStatus() == OSSIM_NULL) ||
811  {
812  return result;
813  }
814 
815  ossim_uint32 index = 0;
816  ossim_float64 delta = 0.0;
817  ossim_uint32 validPixelCount = 0;
818 
819  const T* BUFFER = static_cast<const T*>(getBuf(bandNumber));
820  if(BUFFER)
821  {
822  const ossim_uint32 BOUNDS = getSizePerBand();
823  for(index = 0; index < BOUNDS; ++index)
824  {
825  if(!isNull(index))
826  {
827  delta = BUFFER[index] - meanValue;
828  result += (delta*delta);
829  ++validPixelCount;
830  }
831  }
832  if(validPixelCount > 0)
833  {
834  result /= validPixelCount;
835  }
836  }
837 
838  return result;
839 }
840 
841 
842 //******************************************************************
843 //
844 // NOTE: I was checking for null and not adding it to the histogram.
845 // this was messing up the equalization algorithms since the
846 // accumulation histogram did not represent the area of the
847 // image. For now I will leave out the check for "is null" and
848 // add this to the count so that the total accumulation is the
849 // area of the image.
850 //
851 //******************************************************************
853 {
854  ossim_uint32 numberOfBands = getNumberOfBands();
855 
856  if( (getDataObjectStatus() == OSSIM_NULL) ||
858  (!histo))
859  {
860  return;
861  }
862  switch(getScalarType())
863  {
864  case OSSIM_UINT8:
865  {
866  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
867  {
868  ossimRefPtr<ossimHistogram> currentHisto = histo->getHistogram(band);
869  if(currentHisto.valid())
870  {
871  ossim_uint8 nullpix = (ossim_uint8)getNullPix(band);
872  float* histoBins = currentHisto->GetCounts();
873  int binCount = currentHisto->GetRes();
874  ossim_uint8* buffer = (ossim_uint8*)getBuf(band);
875  ossim_uint32 upperBound = getWidth()*getHeight();
876  if ( binCount == 256 )
877  {
878  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
879  {
880  if (buffer[offset] != nullpix)
881  ++histoBins[ buffer[offset] ];
882  }
883  }
884  else
885  {
886  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
887  {
888  if (buffer[offset] != nullpix)
889  currentHisto->UpCount((float)buffer[offset]);
890  }
891  }
892  }
893  }
894  break;
895  }
896  case OSSIM_UINT16:
897  case OSSIM_USHORT11:
898  case OSSIM_USHORT12:
899  case OSSIM_USHORT13:
900  case OSSIM_USHORT14:
901  case OSSIM_USHORT15:
902  {
903  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
904  {
905  ossimRefPtr<ossimHistogram> currentHisto = histo->getHistogram(band);
906  if(currentHisto.valid())
907  {
908  ossim_uint16 nullpix = (ossim_uint16)getNullPix(band);
909  ossim_uint16* buffer = (ossim_uint16*)getBuf(band);
910  ossim_uint32 upperBound = getWidth()*getHeight();
911  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
912  {
913  if (buffer[offset] != nullpix)
914  currentHisto->UpCount((float)buffer[offset]);
915  }
916  }
917  }
918  break;
919  }
920  case OSSIM_SINT16:
921  {
922  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
923  {
924  ossimRefPtr<ossimHistogram> currentHisto = histo->getHistogram(band);
925  if(currentHisto.valid())
926  {
927  ossim_sint16 nullpix = (ossim_sint16)getNullPix(band);
928  ossim_sint16* buffer = (ossim_sint16*)getBuf(band);
929  ossim_uint32 upperBound = getWidth()*getHeight();
930  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
931  {
932  if (buffer[offset] != nullpix)
933  currentHisto->UpCount((float)buffer[offset]);
934  }
935  }
936  }
937  break;
938  }
939  case OSSIM_SINT32:
940  {
941  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
942  {
943  ossimRefPtr<ossimHistogram> currentHisto = histo->getHistogram(band);
944  if(currentHisto.valid())
945  {
946  ossim_sint32 nullpix = (ossim_sint32)getNullPix(band);
947  ossim_sint32* buffer = (ossim_sint32*)getBuf(band);
948  ossim_uint32 upperBound = getWidth()*getHeight();
949  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
950  {
951  if (buffer[offset] != nullpix)
952  currentHisto->UpCount((float)buffer[offset]);
953  }
954  }
955  }
956  break;
957  }
958  case OSSIM_UINT32:
959  {
960  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
961  {
962  ossimRefPtr<ossimHistogram> currentHisto = histo->getHistogram(band);
963  if(currentHisto.valid())
964  {
965  ossim_uint32 nullpix = (ossim_uint32)getNullPix(band);
966  ossim_uint32* buffer = (ossim_uint32*)getBuf(band);
967  ossim_uint32 upperBound = getWidth()*getHeight();
968  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
969  {
970  if (buffer[offset] != nullpix)
971  currentHisto->UpCount((float)buffer[offset]);
972  }
973  }
974  }
975  break;
976  }
978  case OSSIM_FLOAT64:
979  {
980  ossim_float64 epsilon = 2*DBL_EPSILON;
981  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
982  {
983  ossimRefPtr<ossimHistogram> currentHisto = histo->getHistogram(band);
984  if(currentHisto.valid())
985  {
986  ossim_float64 nullpix = (ossim_float64)getNullPix(band);
987  if (nullpix == 0.0)
988  epsilon = 0;
989  ossim_float64* buffer = (ossim_float64*)getBuf(band);
990  ossim_uint32 upperBound = getWidth()*getHeight();
991  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
992  {
993  if (!ossim::almostEqual<ossim_float64>(buffer[offset], nullpix, epsilon))
994  currentHisto->UpCount((float)buffer[offset]);
995  }
996  }
997  }
998  break;
999  }
1001  case OSSIM_FLOAT32:
1002  {
1003  ossim_float32 epsilon = 2*FLT_EPSILON;
1004  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
1005  {
1006  ossimRefPtr<ossimHistogram> currentHisto = histo->getHistogram(band);
1007  if(currentHisto.valid())
1008  {
1009  ossim_float32 nullpix = (ossim_float32)getNullPix(band);
1010  if (nullpix == 0.0)
1011  epsilon = 0;
1012  ossim_float32* buffer = (ossim_float32*)getBuf(band);
1013  ossim_uint32 upperBound = getWidth()*getHeight();
1014  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
1015  {
1016  if (!ossim::almostEqual<ossim_float32>(buffer[offset], nullpix, epsilon))
1017  currentHisto->UpCount((float)buffer[offset]);
1018  }
1019  }
1020  }
1021  break;
1022  }
1023  case OSSIM_SCALAR_UNKNOWN:
1024  default:
1025  {
1026  //ERROR
1028  << "ossimImageData::populateHistogram\n"
1029  << "Unknown scalar type." << std::endl;
1030  }
1031  } // end of switch
1032 }
1033 
1035 {
1036  ossim_float64 result = 0.0;
1037 
1038  switch (getScalarType())
1039  {
1040  case OSSIM_UINT8:
1041  {
1043  bandNumber);
1044  break;
1045  }
1046  case OSSIM_SINT8:
1047  {
1049  bandNumber);
1050  break;
1051  }
1052  case OSSIM_UINT16:
1053  case OSSIM_USHORT11:
1054  case OSSIM_USHORT12:
1055  case OSSIM_USHORT13:
1056  case OSSIM_USHORT14:
1057  case OSSIM_USHORT15:
1058  {
1060  bandNumber);
1061  break;
1062  }
1063  case OSSIM_SINT16:
1064  {
1066  bandNumber);
1067  break;
1068  }
1069  case OSSIM_UINT32:
1070  {
1072  bandNumber);
1073  break;
1074  }
1075  case OSSIM_SINT32:
1076  {
1078  bandNumber);
1079  break;
1080  }
1081  case OSSIM_FLOAT32:
1083  {
1084  result = computeAverageBandValue(ossim_float32(0.0),
1085  bandNumber);
1086  break;
1087  }
1089  case OSSIM_FLOAT64:
1090  {
1091  result = computeAverageBandValue(ossim_float64(0.0),
1092  bandNumber);
1093  break;
1094  }
1095  case OSSIM_SCALAR_UNKNOWN:
1096  default:
1097  {
1101  "ossimImageData::computeAverageBandValue File %s line %d\n\
1102 Invalid scalar type: %d",
1103 __FILE__,
1104 __LINE__,
1105 getScalarType());
1106  break;
1107  }
1108  }
1109 
1110  return result;
1111 }
1112 
1114  T, /* dummy */
1115  ossim_uint32 bandNumber) const
1116 {
1117  ossim_float64 result = 0.0;
1118 
1119  if ( (getDataObjectStatus() == OSSIM_NULL) ||
1121  {
1122  return result;
1123  }
1124 
1125  ossim_uint32 index = 0;
1126  ossim_uint32 validPixelCount = 0;
1127 
1128  const T* BUFFER = static_cast<const T*>(getBuf(bandNumber));
1129  if(BUFFER)
1130  {
1131  const ossim_uint32 BOUNDS = getSizePerBand();
1132  for(index = 0; index < BOUNDS; ++index)
1133  {
1134  if(!isNull(index))
1135  {
1136  result += BUFFER[index];
1137  ++validPixelCount;
1138  }
1139  }
1140  if(validPixelCount > 0)
1141  {
1142  result /= validPixelCount;
1143  }
1144  }
1145 
1146  return result;
1147 }
1148 
1150 {
1151  switch (getScalarType())
1152  {
1153  case OSSIM_UINT8:
1154  {
1155  return validate(ossim_uint8(0));
1156  }
1157  case OSSIM_SINT8:
1158  {
1159  return validate(ossim_sint8(0));
1160  }
1161 
1162  case OSSIM_UINT16:
1163  case OSSIM_USHORT11:
1164  case OSSIM_USHORT12:
1165  case OSSIM_USHORT13:
1166  case OSSIM_USHORT14:
1167  case OSSIM_USHORT15:
1168  {
1169  return validate(ossim_uint16(0));
1170  }
1171  case OSSIM_SINT16:
1172  {
1173  return validate(ossim_sint16(0));
1174  }
1175 
1176  case OSSIM_UINT32:
1177  {
1178  return validate(ossim_uint32(0));
1179  }
1180  case OSSIM_SINT32:
1181  {
1182  return validate(ossim_sint32(0));
1183  }
1184  case OSSIM_FLOAT32:
1186  {
1187  return validate(ossim_float32(0.0));
1188  }
1189 
1191  case OSSIM_FLOAT64:
1192  {
1193  return validate(ossim_float64(0.0));
1194  }
1195  case OSSIM_SCALAR_UNKNOWN:
1196  default:
1197  {
1199  break;
1200  }
1201  }
1202 
1203  return OSSIM_STATUS_UNKNOWN;
1204 }
1205 
1206 template <class T>
1208 {
1209  if (m_dataBuffer.size() == 0)
1210  {
1212  m_percentFull = 0;
1213  return OSSIM_NULL;
1214  }
1215 
1216  ossim_uint32 count = 0;
1217  const ossim_uint32 SIZE = getSize();
1218  const ossim_uint32 BOUNDS = getSizePerBand();
1219  const ossim_uint32 NUMBER_OF_BANDS = getNumberOfBands();
1220 
1221  for(ossim_uint32 band = 0; band < NUMBER_OF_BANDS; ++band)
1222  {
1223  const T NP = static_cast<T>(m_nullPixelValue[band]);
1224  const T* p = static_cast<const T*>(getBuf(band));
1225 
1226  for (ossim_uint32 i = 0; i < BOUNDS; ++i)
1227  {
1228  // check if the band is null
1229  if (p[i] != NP) ++count;
1230  }
1231  }
1232 
1233  if (!count)
1234  {
1236  m_percentFull = 0;
1237  }
1238  else if (count == SIZE)
1239  {
1241  m_percentFull = 100;
1242  }
1243  else
1244  {
1246  m_percentFull = 100.0 * count / SIZE;
1247  }
1248  return getDataObjectStatus();
1249 }
1250 
1252 {
1253  if ( (m_dataBuffer.size() == 0) || (getDataObjectStatus() == OSSIM_EMPTY) )
1254  {
1255  return; // nothing to do...
1256  }
1257 
1258  switch (getScalarType())
1259  {
1260  case OSSIM_UINT8:
1261  {
1262  makeBlank(ossim_uint8(0));
1263  return;
1264  }
1265  case OSSIM_SINT8:
1266  {
1267  makeBlank(ossim_sint8(0));
1268  return;
1269  }
1270  case OSSIM_UINT16:
1271  case OSSIM_USHORT11:
1272  case OSSIM_USHORT12:
1273  case OSSIM_USHORT13:
1274  case OSSIM_USHORT14:
1275  case OSSIM_USHORT15:
1276  {
1277  makeBlank(ossim_uint16(0));
1278  return;
1279  }
1280  case OSSIM_SINT16:
1281  {
1282  makeBlank(ossim_sint16(0));
1283  return;
1284  }
1285  case OSSIM_UINT32:
1286  {
1287  makeBlank(ossim_uint32(0));
1288  return;
1289  }
1290  case OSSIM_SINT32:
1291  {
1292  makeBlank(ossim_sint32(0));
1293  return;
1294  }
1295  case OSSIM_FLOAT32:
1297  {
1298  makeBlank(ossim_float32(0.0));
1299  return;
1300  }
1302  case OSSIM_FLOAT64:
1303  {
1304  makeBlank(ossim_float64(0.0));
1305  return;
1306  }
1307  case OSSIM_SCALAR_UNKNOWN:
1308  default:
1309  {
1313  "ossimImageData::makeBlank File %s line %d\n\
1314 Invalid scalar type: %d",
1315 __FILE__,
1316 __LINE__,
1317 getScalarType());
1318  break;
1319  }
1320  }
1321 }
1322 
1323 template <class T> void ossimImageData::makeBlank(T /* dummyTemplate */ )
1324 {
1325  // Note: Empty buffer or already OSSIM_EMPTY checked in public method.
1326 
1327  const ossim_uint32 BANDS = getNumberOfBands();
1328  const ossim_uint32 SPB = getSizePerBand();
1329  ossim_uint32 sizePerBandInBytes = getSizePerBandInBytes();
1330  for(ossim_uint32 band = 0; band < BANDS; ++band)
1331  {
1332  const T NP = static_cast<T>(m_nullPixelValue[band]);
1333  if(NP == 0.0)
1334  {
1335  // do an optimize byte fill
1336  memset(getBuf(band), '\0', sizePerBandInBytes);
1337  }
1338  else
1339  {
1340  // slower assign call
1341  T* p = static_cast<T*>(getBuf(band));
1342  for (ossim_uint32 i = 0; i < SPB; ++i)
1343  {
1344  p[i] = NP;
1345  }
1346  }
1347  }
1348 
1350 }
1351 
1353 {
1354  // let the base class allocate a buffer
1356 
1357  if (m_dataBuffer.size() > 0)
1358  {
1359  makeBlank(); // Make blank will set the status.
1360  }
1361 }
1362 
1363 // Write the tile out to disk with a general raster header file.
1365 {
1366  bool result = false;
1367 
1368  std::ofstream os;
1369  os.open(f.c_str(), ios::out | ios::binary);
1370  if (os.good())
1371  {
1372  // Write the tile out.
1373  os.write(static_cast<const char*>(getBuf()),
1374  static_cast<std::streamsize>(getSizeInBytes()));
1375 
1376  result = os.good();
1377  if (result)
1378  {
1379  // Write a header file that we can use to read the tile.
1380  os.close();
1381  ossimFilename hdrFile = f;
1382  hdrFile.setExtension("hdr");
1383  os.open(hdrFile.c_str(), ios::out);
1384  result = os.good();
1385  if (result)
1386  {
1387  os << "filename: " << f.c_str()
1388  << "\nimage_type: general_raster_bsq"
1389  << "\nindexed: " << m_indexedFlag
1390  << "\ninterleave_type: bsq"
1391  << "\norigin: " << m_origin
1392  << "\nnumber_bands: " << ossimString::toString(getNumberOfBands())
1393  << "\nnumber_lines: " << ossimString::toString(getHeight())
1394  << "\nnumber_samples: " << ossimString::toString(getWidth())
1395  << "\nscalar_type: "
1397  << "\n";
1398  for(ossim_uint32 band=0; band < getNumberOfBands(); ++band)
1399  {
1400  ossimString bs = "band";
1401  bs += ossimString::toString(band+1);
1402  os << bs.c_str() << ".min_value: " << m_minPixelValue[band] << "\n"
1403  << bs.c_str() << ".max_value: " << m_maxPixelValue[band] << "\n"
1404  << bs.c_str() << ".null_value: " << m_nullPixelValue[band]
1405  << std::endl;
1406  }
1407  }
1408  }
1409  }
1410  os.close();
1411 
1412  return result;
1413 }
1414 
1416 {
1417  return ((x >= m_origin.x) &&
1418  (x < m_origin.x + static_cast<ossim_int32>(m_spatialExtents[0])) &&
1419  (y >= m_origin.y) &&
1420  (y < m_origin.y + static_cast<ossim_int32>(m_spatialExtents[1])));
1421 
1422 }
1423 
1425 {
1426  if(m_dataBuffer.size() > 0 && isWithin(x, y))
1427  {
1428  ossim_uint32 band=0;
1429 
1430  //***
1431  // Compute the offset into the buffer for (x,y). This should always
1432  // come out positive.
1433  //***
1434  ossim_uint32 ux = static_cast<ossim_uint32>(x - m_origin.x);
1435  ossim_uint32 uy = static_cast<ossim_uint32>(y - m_origin.y);
1436 
1437  ossim_uint32 offset = uy * m_spatialExtents[0] + ux;
1438 
1439  switch (getScalarType())
1440  {
1441  case OSSIM_UINT8:
1442  {
1443  for(band = 0; band < m_numberOfDataComponents; band++)
1444  {
1445  unsigned char* buf = static_cast<unsigned char*>(getBuf(band))+
1446  offset;
1447  *buf = (unsigned char)color;
1448  }
1449  break;
1450  }
1451  case OSSIM_SINT8:
1452  {
1453  for(band = 0; band < m_numberOfDataComponents; band++)
1454  {
1455  ossim_sint8* buf = static_cast<ossim_sint8*>(getBuf(band))+
1456  offset;
1457  *buf = (ossim_sint8)color;
1458  }
1459  break;
1460  }
1461  case OSSIM_UINT16:
1462  case OSSIM_USHORT11:
1463  case OSSIM_USHORT12:
1464  case OSSIM_USHORT13:
1465  case OSSIM_USHORT14:
1466  case OSSIM_USHORT15:
1467  {
1468  for(band = 0; band < m_numberOfDataComponents; band++)
1469  {
1470  ossim_uint16* buf = static_cast<ossim_uint16*>(getBuf(band))+
1471  offset;
1472  *buf = (ossim_uint16)color;
1473  }
1474  break;
1475  }
1476  case OSSIM_SINT16:
1477  {
1478  for(band = 0; band < m_numberOfDataComponents; band++)
1479  {
1480  signed short* buf = static_cast<signed short*>(getBuf(band))+
1481  offset;
1482  *buf = (signed short)color;
1483  }
1484  break;
1485  }
1486  case OSSIM_UINT32:
1487  {
1488  for(band = 0; band < m_numberOfDataComponents; band++)
1489  {
1490  ossim_uint32* buf = static_cast<ossim_uint32*>(getBuf(band))+
1491  offset;
1492  *buf = (ossim_uint32)color;
1493  }
1494  break;
1495  }
1496  case OSSIM_SINT32:
1497  {
1498  for(band = 0; band < m_numberOfDataComponents; band++)
1499  {
1500  ossim_sint32* buf = static_cast<ossim_sint32*>(getBuf(band))+
1501  offset;
1502  *buf = (ossim_sint32)color;
1503  }
1504  break;
1505  }
1507  case OSSIM_FLOAT32:
1508  {
1509  for(band = 0; band < m_numberOfDataComponents; band++)
1510  {
1511  ossim_float32* buf = static_cast<ossim_float32*>(getBuf(band))+offset;
1512  *buf = (ossim_float32)color;
1513  }
1514  break;
1515  }
1516  case OSSIM_FLOAT64:
1518  {
1519  for(band = 0; band < m_numberOfDataComponents; band++)
1520  {
1521  ossim_float64* buf = static_cast<ossim_float64*>(getBuf(band))+offset;
1522  *buf = color;
1523  }
1524  break;
1525  }
1526  case OSSIM_SCALAR_UNKNOWN:
1527  default:
1528  {
1529  //ERROR
1531  << "ossimImageData::setValue Unsupported scalar type!"
1532  << std::endl;
1533 
1534  }
1535 
1536  } // End of: switch (getScalarType())
1537  }
1538 }
1539 
1541 {
1545 }
1546 
1548 {
1550  {
1551  return;
1552  }
1553 
1555 
1557 
1558  for(ossim_uint32 band = 0; band < m_numberOfDataComponents; ++band)
1559  {
1560  m_minPixelValue[band] = value;
1561  }
1562 }
1563 
1565 {
1567  {
1568  return;
1569  }
1570 
1572 
1574 
1575  for(ossim_uint32 band = 0; band < m_numberOfDataComponents; ++band)
1576  {
1577  m_maxPixelValue[band] = value;
1578  }
1579 }
1580 
1582 {
1584  {
1585  return;
1586  }
1587 
1589 
1591 
1592  for(ossim_uint32 band = 0; band < m_numberOfDataComponents; ++band)
1593  {
1594  m_nullPixelValue[band] = value;
1595  }
1596 }
1597 
1599  bool deepTest)const
1600 {
1601  const ossimImageData* rhsPtr = dynamic_cast<const ossimImageData*>(&rhs);
1602  if(!rhsPtr) return false;
1603  bool result = ( (m_scalarType == rhsPtr->m_scalarType)&&
1605  (m_origin == rhsPtr->m_origin)&&
1606  (getWidth() == rhsPtr->getWidth())&&
1607  (getHeight() == rhsPtr->getHeight()));
1608 
1609  if(result)
1610  {
1611  bool test=true;
1612  for(ossim_uint32 index = 0; index < m_numberOfDataComponents; ++index)
1613  {
1614  if(m_minPixelValue[index] != rhsPtr->m_minPixelValue[index])
1615  {
1616  test = false;
1617  break;
1618  }
1619  if(m_maxPixelValue[index] != rhsPtr->m_maxPixelValue[index])
1620  {
1621  test = false;
1622  break;
1623  }
1624  if(m_nullPixelValue[index] != rhsPtr->m_nullPixelValue[index])
1625  {
1626  test = false;
1627  break;
1628  }
1629  }
1630  result = test;
1631  }
1632  if(deepTest&&result)
1633  {
1634  if(getBuf() != 0 && rhsPtr->getBuf() != 0)
1635  {
1636  if(memcmp(getBuf(), rhsPtr->getBuf(), getSizeInBytes()) != 0)
1637  {
1638  result = false;
1639  }
1640  }
1641  else if(getBuf() == 0 && rhsPtr->getBuf() == 0)
1642  {
1643  // nothing both are null so don't change the result.
1644  }
1645  else // one is null so not equal.
1646  {
1647  result = false;
1648  }
1649  }
1650 
1651  return result;
1652 }
1653 
1655 {
1657 }
1658 
1660 {
1661  return getNumberOfDataComponents();
1662 }
1663 
1665  ossim_uint32 band) const
1666 {
1667  ossimIpt relative( position.x - m_origin.x,
1668  position.y - m_origin.y);
1669  if((relative.x < 0) || (relative.x >= (ossim_int32)m_spatialExtents[0])) return 0.0;
1670  if((relative.y < 0) || (relative.y >= (ossim_int32)m_spatialExtents[1])) return 0.0;
1671  return getPix((m_spatialExtents[0])*relative.y + relative.x, band);
1672 }
1673 
1675 {
1676  switch(m_scalarType)
1677  {
1678  case OSSIM_UINT8:
1679  {
1680  const ossim_uint8* buf = getUcharBuf(band);
1681  if(buf)
1682  {
1683  return (ossim_float64)buf[offset];
1684  }
1685  break;
1686  }
1687  case OSSIM_SINT8:
1688  {
1689  const ossim_sint8* buf = static_cast<const ossim_sint8*>(getBuf(band));
1690  if(buf)
1691  {
1692  return (ossim_float64)buf[offset];
1693  }
1694  break;
1695  }
1696  case OSSIM_USHORT11:
1697  case OSSIM_USHORT12:
1698  case OSSIM_USHORT13:
1699  case OSSIM_USHORT14:
1700  case OSSIM_USHORT15:
1701  case OSSIM_UINT16:
1702  {
1703  const ossim_uint16* buf = getUshortBuf(band);
1704  if(buf)
1705  {
1706  return (ossim_float64)buf[offset];
1707  }
1708  break;
1709  }
1710  case OSSIM_SINT16:
1711  {
1712  const ossim_sint16* buf = getSshortBuf(band);
1713  if(buf)
1714  {
1715  return (ossim_float64)buf[offset];
1716  }
1717  break;
1718  }
1719  case OSSIM_SINT32:
1720  {
1721  const ossim_sint32* buf = static_cast<const ossim_sint32*>(getBuf(band));
1722  if(buf)
1723  {
1724  return (ossim_float64)buf[offset];
1725  }
1726  break;
1727  }
1728  case OSSIM_UINT32:
1729  {
1730  const ossim_uint32* buf = static_cast<const ossim_uint32*>(getBuf(band));
1731  if(buf)
1732  {
1733  return (ossim_float64)buf[offset];
1734  }
1735  break;
1736  }
1738  case OSSIM_FLOAT64:
1739  {
1740  const ossim_float64* buf = getDoubleBuf(band);
1741  if(buf)
1742  {
1743  return (ossim_float64)buf[offset];
1744  }
1745  break;
1746  }
1748  case OSSIM_FLOAT32:
1749  {
1750  const ossim_float32* buf = getFloatBuf(band);
1751  if(buf)
1752  {
1753  return (ossim_float64)buf[offset];
1754  }
1755  break;
1756  }
1757  case OSSIM_SCALAR_UNKNOWN:
1758  default:
1759  // Shouldn't hit this.
1761  << "ossimImageData::fill Unsupported scalar type!"
1762  << std::endl;
1763  }
1764 
1765  return 0.0;
1766 }
1767 
1769 {
1770  void* s = getBuf(band);
1771 
1772  if (s == 0) return; // nothing to do...
1773 
1774  ossim_uint32 size_in_pixels = getWidth()*getHeight();
1775 
1776  switch (getScalarType())
1777  {
1778  case OSSIM_UINT8:
1779  {
1780  ossim_uint8* p = getUcharBuf(band);
1781  ossim_uint8 np = static_cast<ossim_uint8>(value);
1782  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = np;
1783 
1784  break;
1785  }
1786  case OSSIM_SINT8:
1787  {
1788  ossim_sint8* p = static_cast<ossim_sint8*>(getBuf(band));
1789  ossim_sint8 np = static_cast<ossim_sint8>(value);
1790  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = np;
1791 
1792  break;
1793  }
1794  case OSSIM_UINT16:
1795  case OSSIM_USHORT11:
1796  case OSSIM_USHORT12:
1797  case OSSIM_USHORT13:
1798  case OSSIM_USHORT14:
1799  case OSSIM_USHORT15:
1800  {
1801  ossim_uint16* p = getUshortBuf(band);
1802  ossim_uint16 np = static_cast<ossim_uint16>(value);
1803  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = np;
1804 
1805  break;
1806  }
1807  case OSSIM_SINT16:
1808  {
1809  ossim_sint16* p = getSshortBuf(band);
1810  ossim_sint16 np = static_cast<ossim_sint16>(value);
1811  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = np;
1812 
1813  break;
1814  }
1815  case OSSIM_UINT32:
1816  {
1817  ossim_uint32* p = static_cast<ossim_uint32*>(getBuf(band));
1818  ossim_uint32 np = static_cast<ossim_uint32>(value);
1819  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = np;
1820 
1821  break;
1822  }
1823  case OSSIM_SINT32:
1824  {
1825  ossim_sint32* p = static_cast<ossim_sint32*>(getBuf(band));
1826  ossim_sint32 np = static_cast<ossim_sint32>(value);
1827  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = np;
1828 
1829  break;
1830  }
1832  case OSSIM_FLOAT32:
1833  {
1834  ossim_float32* p = getFloatBuf(band);
1835  ossim_float32 np = static_cast<ossim_float32>(value);
1836  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = np;
1837 
1838  break;
1839  }
1841  case OSSIM_FLOAT64:
1842  {
1843  ossim_float64* p = getDoubleBuf(band);
1844  ossim_float64 np = static_cast<ossim_float64>(value);
1845  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = np;
1846 
1847  break;
1848  }
1849  case OSSIM_SCALAR_UNKNOWN:
1850  default:
1853  "ossimImageData::makeBlank File %s line %d\n\
1854 Invalid scalar type: %d",
1855 __FILE__,
1856 __LINE__,
1857 getScalarType());
1858  return;
1859  }
1860 
1862 
1863 }
1864 
1866 {
1867  ossim_uint32 valueNullCount= 0;
1868  for(ossim_uint32 band=0; band < getNumberOfBands(); ++band)
1869  {
1870  if (value == m_nullPixelValue[band])
1871  {
1872  ++valueNullCount;
1873  }
1874 
1875  fill(band, value);
1876  }
1877 
1878  if (valueNullCount==0)
1879  {
1881  }
1882  else if(valueNullCount==getNumberOfBands())
1883  {
1885  }
1886  else
1887  {
1889  }
1890 }
1891 
1892 
1894 {
1895  // Check the status and allocate memory if needed.
1897  {
1898  initialize();
1899  }
1900 
1901  if ( getDataObjectStatus() != OSSIM_NULL )
1902  {
1903  switch (getScalarType())
1904  {
1905  case OSSIM_UINT8:
1906  {
1908  break;
1909  }
1910  case OSSIM_SINT8:
1911  {
1913  break;
1914  }
1915  case OSSIM_UINT16:
1916  case OSSIM_USHORT11:
1917  case OSSIM_USHORT12:
1918  case OSSIM_USHORT13:
1919  case OSSIM_USHORT14:
1920  case OSSIM_USHORT15:
1921  {
1923  break;
1924  }
1925  case OSSIM_SINT16:
1926  {
1928  break;
1929  }
1930  case OSSIM_UINT32:
1931  {
1933  break;
1934  }
1935  case OSSIM_SINT32:
1936  {
1938  break;
1939  }
1940  case OSSIM_FLOAT32:
1942  {
1944  break;
1945  }
1947  case OSSIM_FLOAT64:
1948  {
1950  break;
1951  }
1952  case OSSIM_SCALAR_UNKNOWN:
1953  default:
1956  "ossimImageData::createTestTile File %s line %d\nInvalid or unhandled scalar type: %d",
1957  __FILE__,
1958  __LINE__,
1959  getScalarType());
1960  }
1961  }
1962  else
1963  {
1966  "ossimImageData::createTestTile File %s line %d\nTile must be initialed!",
1967  __FILE__,
1968  __LINE__,
1969  getScalarType());
1970  }
1971 
1972 } // End: ossimImageData::createTestTile()
1973 
1974 
1975 template <class T> void ossimImageData::createTestTile(T)
1976 {
1978  {
1979  const ossim_uint32 BANDS = getNumberOfBands();
1980  const ossim_uint32 LINES = getHeight();
1981  const ossim_uint32 SAMPS = getWidth();
1982  const ossim_float64 NP = getNullPix(0);
1983  const ossim_float64 MAX_PIX = getMaxPix(0);
1984 
1985  const T STEP = static_cast<T>( (MAX_PIX-NP) / (LINES-1) );
1986 
1987  for(ossim_uint32 band = 0; band < BANDS; ++band)
1988  {
1989  T* s = (T*)getBuf(band);
1990  T p = (T)NP;
1991 
1992  for ( ossim_uint32 line = 0; line < LINES; ++line )
1993  {
1994  for ( ossim_uint32 samp = 0; samp < SAMPS; ++samp )
1995  {
1996  s[samp] = p;
1997  }
1998  p += STEP;
1999  s += SAMPS;
2000 
2001  }
2002  }
2003 
2004  validate();
2005  }
2006 
2007 } // End: ossimImageData::createTestTile() template implementation.
2008 
2010 {
2011  ossim_uint32 numberOfBands = getNumberOfBands();
2012  ossim_uint32 band=0;
2013  if(!getBuf())
2014  {
2015  return true;
2016  }
2017 
2018  switch(getScalarType())
2019  {
2020  case OSSIM_UINT8:
2021  {
2022  for(band = 0; band < numberOfBands; ++band)
2023  {
2024  const ossim_uint8* buf = static_cast<const ossim_uint8*>(getBuf(band))+offset;
2025  if((*buf) != (ossim_uint8)getNullPix(band))
2026  {
2027  return false;
2028  }
2029  }
2030  break;
2031  }
2032  case OSSIM_SINT8:
2033  {
2034  for(band = 0; band < numberOfBands; ++band)
2035  {
2036  const ossim_sint8* buf = static_cast<const ossim_sint8*>(getBuf(band))+offset;
2037  if((*buf) != (ossim_uint8)getNullPix(band))
2038  {
2039  return false;
2040  }
2041  }
2042  break;
2043  }
2044  case OSSIM_UINT16:
2045  case OSSIM_USHORT11:
2046  case OSSIM_USHORT12:
2047  case OSSIM_USHORT13:
2048  case OSSIM_USHORT14:
2049  case OSSIM_USHORT15:
2050  {
2051  for(band = 0; band < numberOfBands; band++)
2052  {
2053  const ossim_uint16* buf = static_cast<const ossim_uint16*>(getBuf(band))+offset;
2054  if((*buf) != (ossim_uint16)getNullPix(band))
2055  {
2056  return false;
2057  }
2058  }
2059  break;
2060  }
2061  case OSSIM_SINT16:
2062  {
2063  for(band = 0; band < numberOfBands; band++)
2064  {
2065  const ossim_sint16* buf = static_cast<const ossim_sint16*>(getBuf(band))+offset;
2066  if((*buf) != (ossim_sint16)getNullPix(band))
2067  {
2068  return false;
2069  }
2070  }
2071  break;
2072  }
2073  case OSSIM_UINT32:
2074  {
2075  for(band = 0; band < numberOfBands; band++)
2076  {
2077  const ossim_uint32* buf = static_cast<const ossim_uint32*>(getBuf(band))+offset;
2078  if((*buf) != (ossim_uint32)getNullPix(band))
2079  {
2080  return false;
2081  }
2082  }
2083  break;
2084  }
2085  case OSSIM_SINT32:
2086  {
2087  for(band = 0; band < numberOfBands; band++)
2088  {
2089  const ossim_sint32* buf = static_cast<const ossim_sint32*>(getBuf(band))+offset;
2090  if((*buf) != (ossim_sint32)getNullPix(band))
2091  {
2092  return false;
2093  }
2094  }
2095  break;
2096  }
2098  {
2099  for(band = 0; band < numberOfBands; band++)
2100  {
2101  const ossim_float32* buf = static_cast<const ossim_float32*>(getBuf(band))+offset;
2102  if((*buf) != 0.0)
2103  {
2104  return false;
2105  }
2106  }
2107  break;
2108  }
2109  case OSSIM_FLOAT32:
2110  {
2111  for(band = 0; band < numberOfBands; band++)
2112  {
2113  const ossim_float32* buf = static_cast<const ossim_float32*>(getBuf(band))+offset;
2114  if((*buf) != (ossim_float32)getNullPix(band))
2115  {
2116  return false;
2117  }
2118  }
2119  break;
2120  }
2122  {
2123  for(band = 0; band < numberOfBands; band++)
2124  {
2125  const ossim_float64* buf = static_cast<const ossim_float64*>(getBuf(band))+offset;
2126  if((*buf) != 0.0)
2127  {
2128  return false;
2129  }
2130  }
2131  break;
2132  }
2133  case OSSIM_FLOAT64:
2134  {
2135  for(band = 0; band < numberOfBands; band++)
2136  {
2137  const ossim_float64* buf = static_cast<const ossim_float64*>(getBuf(band))+offset;
2138  if((*buf) != getNullPix(band))
2139  {
2140  return false;
2141  }
2142  }
2143  break;
2144  }
2145  case OSSIM_SCALAR_UNKNOWN:
2146  default:
2147  {
2148  //ERROR
2150  << "ossimImageData::isNull Unsupported scalar type!"
2151  << std::endl;
2152  }
2153  }
2154  return true;
2155 }
2156 
2158 {
2159  switch(getScalarType())
2160  {
2161  case OSSIM_UINT8:
2162  {
2163  const ossim_uint8* buf =
2164  static_cast<const ossim_uint8*>(getBuf(band))+offset;
2165 
2166  if((*buf) != (ossim_uint8)getNullPix(band))
2167  {
2168  return false;
2169  }
2170  break;
2171  }
2172  case OSSIM_SINT8:
2173  {
2174  const ossim_sint8* buf =
2175  static_cast<const ossim_sint8*>(getBuf(band))+offset;
2176 
2177  if((*buf) != (ossim_sint8)getNullPix(band))
2178  {
2179  return false;
2180  }
2181  break;
2182  }
2183  case OSSIM_UINT16:
2184  case OSSIM_USHORT11:
2185  case OSSIM_USHORT12:
2186  case OSSIM_USHORT13:
2187  case OSSIM_USHORT14:
2188  case OSSIM_USHORT15:
2189  {
2190  const ossim_uint16* buf =
2191  static_cast<const ossim_uint16*>(getBuf(band))+offset;
2192  if((*buf) != (ossim_uint16)getNullPix(band))
2193  {
2194  return false;
2195  }
2196  break;
2197  }
2198  case OSSIM_SINT16:
2199  {
2200  const ossim_sint16* buf =
2201  static_cast<const ossim_sint16*>(getBuf(band))+offset;
2202  if((*buf) != (ossim_sint16)getNullPix(band))
2203  {
2204  return false;
2205  }
2206  break;
2207  }
2208  case OSSIM_UINT32:
2209  {
2210  const ossim_uint32* buf =
2211  static_cast<const ossim_uint32*>(getBuf(band))+offset;
2212  if((*buf) != (ossim_uint32)getNullPix(band))
2213  {
2214  return false;
2215  }
2216  break;
2217  }
2218  case OSSIM_SINT32:
2219  {
2220  const ossim_sint32* buf =
2221  static_cast<const ossim_sint32*>(getBuf(band))+offset;
2222  if((*buf) != (ossim_sint32)getNullPix(band))
2223  {
2224  return false;
2225  }
2226  break;
2227  }
2229  case OSSIM_FLOAT32:
2230  {
2231  const ossim_float32* buf = static_cast<const ossim_float32*>(getBuf(band))+offset;
2232  if((*buf) != (ossim_float32)getNullPix(band))
2233  {
2234  return false;
2235  }
2236  break;
2237  }
2238  case OSSIM_FLOAT64:
2240  {
2241  const ossim_float64* buf = static_cast<const ossim_float64*>(getBuf(band))+offset;
2242  if((*buf) != getNullPix(band))
2243  {
2244  return false;
2245  }
2246  break;
2247  }
2248  case OSSIM_SCALAR_UNKNOWN:
2249  default:
2250  {
2251  //ERROR
2253  << "ossimImageData::isNull Unsupported scalar type!"
2254  << std::endl;
2255  }
2256  }
2257  return true;
2258 }
2259 
2260 bool ossimImageData::isNull(const ossimIpt& pt)const
2261 {
2262  ossim_int32 xNew = (pt.x - m_origin.x);
2263  ossim_int32 yNew = (pt.y - m_origin.y);
2264  if(xNew < 0 || xNew >= static_cast<ossim_int32>(m_spatialExtents[0]) ||
2265  yNew < 0 || yNew >= static_cast<ossim_int32>(m_spatialExtents[1]) )
2266  {
2267  return true;
2268  }
2269  ossim_uint32 offset = getWidth()*yNew + xNew;
2270 
2271  return isNull(offset);
2272 }
2273 
2275 {
2276  ossim_int32 xNew = (pt.x - m_origin.x);
2277  ossim_int32 yNew = (pt.y - m_origin.y);
2278  if(xNew < 0 || xNew >= static_cast<ossim_int32>(m_spatialExtents[0]) ||
2279  yNew < 0 || yNew >= static_cast<ossim_int32>(m_spatialExtents[1]) )
2280  {
2281  return true;
2282  }
2283  ossim_uint32 offset = getWidth()*yNew + xNew;
2284 
2285  return isNull(offset, band);
2286 }
2287 
2289 {
2290  ossim_uint32 numberOfBands = getNumberOfBands();
2291  ossim_uint32 band=0;
2292  switch(getScalarType())
2293  {
2294  case OSSIM_UINT8:
2295  {
2296  for(band = 0; band < numberOfBands; ++band)
2297  {
2298  ossim_uint8* buf = static_cast<ossim_uint8*>(getBuf(band))+offset;
2299  *buf = (ossim_uint8)getNullPix(band);
2300  }
2301  break;
2302  }
2303  case OSSIM_SINT8:
2304  {
2305  for(band = 0; band < numberOfBands; ++band)
2306  {
2307  ossim_sint8* buf = static_cast<ossim_sint8*>(getBuf(band))+offset;
2308  *buf = (ossim_sint8)getNullPix(band);
2309  }
2310  break;
2311  }
2312  case OSSIM_UINT16:
2313  case OSSIM_USHORT11:
2314  case OSSIM_USHORT12:
2315  case OSSIM_USHORT13:
2316  case OSSIM_USHORT14:
2317  case OSSIM_USHORT15:
2318  {
2319  for(band = 0; band < numberOfBands; band++)
2320  {
2321  ossim_uint16* buf = static_cast<ossim_uint16*>(getBuf(band))+
2322  offset;
2323  *buf = (ossim_uint16)getNullPix(band);
2324  }
2325  break;
2326  }
2327  case OSSIM_SINT16:
2328  {
2329  for(band = 0; band < numberOfBands; band++)
2330  {
2331  ossim_sint16* buf = static_cast<ossim_sint16*>(getBuf(band))+
2332  offset;
2333  *buf = (ossim_sint16)getNullPix(band);
2334  }
2335  break;
2336  }
2337  case OSSIM_UINT32:
2338  {
2339  for(band = 0; band < numberOfBands; band++)
2340  {
2341  ossim_uint32* buf = static_cast<ossim_uint32*>(getBuf(band))+
2342  offset;
2343  *buf = (ossim_uint32)getNullPix(band);
2344  }
2345  break;
2346  }
2347  case OSSIM_SINT32:
2348  {
2349  for(band = 0; band < numberOfBands; band++)
2350  {
2351  ossim_sint32* buf = static_cast<ossim_sint32*>(getBuf(band))+
2352  offset;
2353  *buf = (ossim_sint32)getNullPix(band);
2354  }
2355  break;
2356  }
2358  case OSSIM_FLOAT32:
2359  {
2360  for(band = 0; band < numberOfBands; band++)
2361  {
2362  ossim_float32* buf = static_cast<ossim_float32*>(getBuf(band))+offset;
2363  *buf = (ossim_float32)getNullPix(band);
2364  }
2365  break;
2366  }
2367  case OSSIM_FLOAT64:
2369  {
2370  for(band = 0; band < numberOfBands; band++)
2371  {
2372  ossim_float64* buf = static_cast<ossim_float64*>(getBuf(band))+offset;
2373  *buf = getNullPix(band);
2374  }
2375  break;
2376  }
2377  case OSSIM_SCALAR_UNKNOWN:
2378  default:
2379  {
2380  //ERROR
2382  << "ossimImageData::isNull Unsupported scalar type!"
2383  << std::endl;
2384  }
2385  }
2386 }
2387 
2389 {
2390  switch(getScalarType())
2391  {
2392  case OSSIM_UINT8:
2393  {
2394  ossim_uint8* buf = static_cast<ossim_uint8*>(getBuf(band))+offset;
2395  *buf = (ossim_uint8)getNullPix(band);
2396  break;
2397  }
2398  case OSSIM_SINT8:
2399  {
2400  ossim_sint8* buf = static_cast<ossim_sint8*>(getBuf(band))+offset;
2401  *buf = (ossim_sint8)getNullPix(band);
2402  break;
2403  }
2404  case OSSIM_UINT16:
2405  case OSSIM_USHORT11:
2406  case OSSIM_USHORT12:
2407  case OSSIM_USHORT13:
2408  case OSSIM_USHORT14:
2409  case OSSIM_USHORT15:
2410  {
2411  ossim_uint16* buf = static_cast<ossim_uint16*>(getBuf(band))+offset;
2412  *buf = (ossim_uint16)getNullPix(band);
2413  break;
2414  }
2415  case OSSIM_SINT16:
2416  {
2417  ossim_sint16* buf = static_cast<ossim_sint16*>(getBuf(band))+offset;
2418  *buf = (ossim_sint16)getNullPix(band);
2419  break;
2420  }
2421  case OSSIM_UINT32:
2422  {
2423  ossim_uint32* buf = static_cast<ossim_uint32*>(getBuf(band))+offset;
2424  *buf = (ossim_uint32)getNullPix(band);
2425  break;
2426  }
2427  case OSSIM_SINT32:
2428  {
2429  ossim_sint32* buf = static_cast<ossim_sint32*>(getBuf(band))+offset;
2430  *buf = (ossim_sint32)getNullPix(band);
2431  break;
2432  }
2434  case OSSIM_FLOAT32:
2435  {
2436  ossim_float32* buf = static_cast<ossim_float32*>(getBuf(band))+offset;
2437  *buf = (ossim_float32)getNullPix(band);
2438  break;
2439  }
2440  case OSSIM_FLOAT64:
2442  {
2443  ossim_float64* buf = static_cast<ossim_float64*>(getBuf(band))+offset;
2444  *buf = getNullPix(band);
2445  break;
2446  }
2447  case OSSIM_SCALAR_UNKNOWN:
2448  default:
2449  {
2450  //ERROR
2452  << "ossimImageData::isNull Unsupported scalar type!"
2453  << std::endl;
2454  }
2455  }
2456 }
2457 
2459 {
2460  ossim_int32 xNew = (pt.x - m_origin.x);
2461  ossim_int32 yNew = (pt.y - m_origin.y);
2462 
2463  if(xNew < 0 || xNew >= (int)m_spatialExtents[0] ||
2464  yNew < 0 || yNew >= (int)m_spatialExtents[1])
2465  {
2466  return;
2467  }
2468  ossim_uint32 offset = ((int)getWidth())*yNew + xNew;
2469 
2470  setNull(offset);
2471 }
2472 
2474 {
2475  ossim_int32 xNew = (pt.x - m_origin.x);
2476  ossim_int32 yNew = (pt.y - m_origin.y);
2477 
2478  if(xNew < 0 || xNew >= (int)m_spatialExtents[0] ||
2479  yNew < 0 || yNew >= (int)m_spatialExtents[1])
2480  {
2481  return;
2482  }
2483  ossim_uint32 offset = ((int)getWidth())*yNew + xNew;
2484 
2485  setNull(offset, band);
2486 }
2487 
2489 {
2491  {
2492  return;
2493  }
2495  for(ossim_uint32 band = 0; band < m_numberOfDataComponents; ++band)
2496  {
2497  m_nullPixelValue[band] = null_pix;
2498  }
2499 }
2500 
2502 {
2504  {
2505  return;
2506  }
2508  {
2510  }
2511  m_nullPixelValue[band] = null_pix;
2512 }
2513 
2515  ossim_uint32 numberOfValues)
2516 {
2517  if(!nullPixArray || !m_numberOfDataComponents)
2518  {
2519  return;
2520  }
2521 
2523  {
2525  }
2526 
2527  for(ossim_uint32 band = 0;
2528  (band < numberOfValues) && (band < m_numberOfDataComponents);
2529  ++band)
2530  {
2531  m_nullPixelValue[band] = nullPixArray[band];
2532  }
2533 }
2534 
2536 {
2538  {
2539  return;
2540  }
2542  for(ossim_uint32 band = 0; band < m_minPixelValue.size(); ++band)
2543  {
2544  m_minPixelValue[band] = min_pix;
2545  }
2546 }
2547 
2549 {
2551  {
2552  return;
2553  }
2555  {
2557  }
2558  m_minPixelValue[band] = min_pix;
2559 }
2560 
2562  ossim_uint32 numberOfValues)
2563 {
2564  if( !minPixArray || !m_numberOfDataComponents )
2565  {
2566  return;
2567  }
2568 
2570  {
2572  }
2573 
2574  for(ossim_uint32 band = 0;
2575  (band < numberOfValues) && (band < m_numberOfDataComponents);
2576  ++band)
2577  {
2578  m_minPixelValue[band] = minPixArray[band];
2579  }
2580 }
2581 
2583 {
2585  {
2586  return;
2587  }
2589  for(ossim_uint32 band = 0; band < m_numberOfDataComponents; ++band)
2590  {
2591  m_maxPixelValue[band] = max_pix;
2592  }
2593 }
2594 
2596 {
2598  {
2599  return;
2600  }
2602  {
2604  }
2605  m_maxPixelValue[band] = max_pix;
2606 }
2607 
2609  ossim_uint32 /* numberOfValues */)
2610 {
2611  if(!maxPixArray || !m_numberOfDataComponents )
2612  {
2613  return;
2614  }
2615 
2617  {
2619  }
2620 
2621  for(ossim_uint32 band = 0;
2622  (band < m_numberOfDataComponents) &&
2623  (band < m_numberOfDataComponents);
2624  ++band)
2625  {
2626  m_maxPixelValue[band] = maxPixArray[band];
2627  }
2628 }
2629 
2631  bool reallocate)
2632 {
2634  if(bands && (b != bands))
2635  {
2637  if(reallocate)
2638  {
2640  }
2641 
2642  ossim_uint32 minBands = ossim::min(b, bands);
2643 
2644 
2645  vector<ossim_float64> newNull(bands);
2646  vector<ossim_float64> newMin(bands);
2647  vector<ossim_float64> newMax(bands);
2648 
2649  ossim_uint32 i = 0;
2650  while (i < minBands)
2651  {
2652  newNull[i] = m_nullPixelValue[i];
2653  newMin[i] = m_minPixelValue[i];
2654  newMax[i] = m_maxPixelValue[i];
2655  ++i;
2656  }
2657 
2658  if(b)
2659  {
2660  while (i < bands)
2661  {
2662  newNull[i] = m_nullPixelValue[b-1];
2663  newMin[i] = m_minPixelValue[b-1];
2664  newMax[i] = m_maxPixelValue[b-1];
2665  ++i;
2666  }
2667  }
2668 
2669  m_nullPixelValue = newNull;
2670  m_minPixelValue = newMin;
2671  m_maxPixelValue = newMax;
2672  }
2673 }
2674 
2676  ossim_uint32 numberOfBands)
2677 {
2678  if(rect.hasNans())
2679  {
2680  return;
2681  }
2682 
2683  ossim_uint32 bands = getNumberOfBands();
2684  ossim_uint32 w = getWidth();
2685  ossim_uint32 h = getHeight();
2686  ossim_uint32 nw = rect.width();
2687  ossim_uint32 nh = rect.height();
2688 
2689  setOrigin(rect.ul());
2690  setWidthHeight(nw, nh);
2691  setNumberOfBands(numberOfBands, false);
2692 
2693  // we will try to be non destructive on the resize of the number of bands
2694  if( ( (w*h != nw*nh) || ( bands != numberOfBands) ) &&
2696  {
2697  initialize();
2698  }
2699 }
2700 
2702 {
2703  if(rect.hasNans())
2704  {
2705  return;
2706  }
2707 
2708  ossim_uint32 w = getWidth();
2709  ossim_uint32 h = getHeight();
2710  ossim_uint32 nw = rect.width();
2711  ossim_uint32 nh = rect.height();
2712 
2713  setOrigin(rect.ul());
2714  setWidthHeight(nw, nh);
2715 
2716  // we will try to be non destructive on the resize of the number of bands
2717  if ( (w*h != nw*nh) && (theDataObjectStatus != OSSIM_NULL) )
2718  {
2719  initialize();
2720  }
2721 }
2722 
2724 {
2725  if(data)
2726  {
2727  const ossimImageData* d = dynamic_cast<const ossimImageData*>(data);
2728  if(d)
2729  {
2730  assign(d);
2731  }
2732  }
2733 }
2734 
2736 {
2737  ossimSource* tmp_owner = getOwner();
2738 
2740 
2741  //***
2742  // The data member "theSource" will be overwritten so capture it and then
2743  // set it back.
2744  //***
2745  setOwner(tmp_owner);
2746 
2747  if(this != data)
2748  {
2749  ossim_uint32 numberOfBands = getNumberOfBands();
2750  if(!numberOfBands)
2751  {
2753  << "ossimImageData::assign\n"
2754  << "Number of components is 0, can't assign" << std::endl;
2755  return;
2756  }
2757  m_origin = data->m_origin;
2758 
2762 
2763  if (m_minPixelValue.size() == 0 ||
2764  m_maxPixelValue.size() == 0 ||
2765  m_nullPixelValue.size() == 0)
2766  {
2768  }
2769 
2770  ossim_uint32 source_size = data->getSizeInBytes();
2771  const void* s = data->getBuf();
2772  void* d = getBuf();
2773  if (s && d)
2774  memcpy(d, s, source_size);
2775 
2776  }
2777 }
2778 
2780  ossim_uint32 source_band,
2781  ossim_uint32 output_band)
2782 {
2783  //***
2784  // This method requires this image data to be initialized to the same
2785  // size as the source data being copied.
2786  //***
2787 
2788  // Some basic error checking...
2789  if ( !data->isValidBand(source_band) )
2790  {
2792  << "ossimImageData::assignBand ERROR:"
2793  << "\nInvalid source band!" << std::endl;
2794  return;
2795  }
2796  if ( !isValidBand(output_band) )
2797  {
2799  << "ossimImageData::assignBand ERROR:"
2800  << "\nInvalid output band!" << std::endl;
2801  return;
2802  }
2803  if (data->getDataObjectStatus() == OSSIM_NULL)
2804  {
2806  << "ossimImageData::assignBand ERROR:"
2807  << "\nSource data status is null!" << std::endl;
2808  return;
2809  }
2811  {
2813  << "ossimImageData::assignBand ERROR:"
2814  << "\nThis status is null!" << std::endl;
2815  return;
2816  }
2817 
2818  //***
2819  // Make sure this buffer is the same size; if not, return.
2820  //***
2821  ossim_uint32 source_size = data->getSizePerBandInBytes();
2822 
2823  if ( source_size != getSizePerBandInBytes() )
2824  {
2825  return;
2826  }
2827 
2828  // Get the pointers to the bands.
2829  const void* s = data->getBuf(source_band);
2830  void* d = getBuf(output_band);
2831 
2832  // One last check.
2833  if (s == 0 || d == 0)
2834  {
2835  return;
2836  }
2837 
2838  // Ok copy the image data...
2839  memcpy(d, s, source_size);
2840 }
2841 
2842 void ossimImageData::loadBand(const void* src,
2843  const ossimIrect& src_rect,
2844  ossim_uint32 band)
2845 {
2846  // Call the appropriate load method.
2847  switch (getScalarType())
2848  {
2849  case OSSIM_UINT8:
2850  loadBandTemplate(ossim_uint8(0), src, src_rect, band);
2851  return;
2852 
2853  case OSSIM_SINT8:
2854  loadBandTemplate(ossim_sint8(0), src, src_rect, band);
2855  return;
2856 
2857  case OSSIM_UINT16:
2858  case OSSIM_USHORT11:
2859  case OSSIM_USHORT12:
2860  case OSSIM_USHORT13:
2861  case OSSIM_USHORT14:
2862  case OSSIM_USHORT15:
2863  loadBandTemplate(ossim_uint16(0), src, src_rect, band);
2864  return;
2865 
2866  case OSSIM_SINT16:
2867  loadBandTemplate(ossim_sint16(0), src, src_rect, band);
2868  return;
2869 
2870  case OSSIM_UINT32:
2871  loadBandTemplate(ossim_uint32(0), src, src_rect, band);
2872  return;
2873 
2874  case OSSIM_SINT32:
2875  loadBandTemplate(ossim_sint32(0), src, src_rect, band);
2876  return;
2877 
2878  case OSSIM_FLOAT32:
2880  loadBandTemplate(ossim_float32(0), src, src_rect, band);
2881  return;
2882 
2884  case OSSIM_FLOAT64:
2885  loadBandTemplate(ossim_float64(0), src, src_rect, band);
2886  return;
2887 
2888  case OSSIM_SCALAR_UNKNOWN:
2889  default:
2892  "ossimImageData::loadBand\n\
2893 File %s line %d\nUnknown scalar type!",
2894 __FILE__,
2895 __LINE__);
2896  return;
2897  }
2898 }
2899 
2900 void ossimImageData::loadBand(const void* src,
2901  const ossimIrect& src_rect,
2902  const ossimIrect& clip_rect,
2903  ossim_uint32 band)
2904 {
2905  // Call the appropriate load method.
2906  switch (getScalarType())
2907  {
2908  case OSSIM_UINT8:
2909  loadBandTemplate(ossim_uint8(0), src, src_rect, clip_rect, band);
2910  return;
2911 
2912  case OSSIM_SINT8:
2913  loadBandTemplate(ossim_sint8(0), src, src_rect, clip_rect, band);
2914  return;
2915 
2916  case OSSIM_UINT16:
2917  case OSSIM_USHORT11:
2918  case OSSIM_USHORT12:
2919  case OSSIM_USHORT13:
2920  case OSSIM_USHORT14:
2921  case OSSIM_USHORT15:
2922  loadBandTemplate(ossim_uint16(0), src, src_rect, clip_rect, band);
2923  return;
2924 
2925  case OSSIM_SINT16:
2926  loadBandTemplate(ossim_sint16(0), src, src_rect, clip_rect, band);
2927  return;
2928 
2929  case OSSIM_UINT32:
2930  loadBandTemplate(ossim_uint32(0), src, src_rect, clip_rect, band);
2931  return;
2932 
2933  case OSSIM_SINT32:
2934  loadBandTemplate(ossim_sint32(0), src, src_rect, clip_rect, band);
2935  return;
2936 
2937  case OSSIM_FLOAT32:
2939  loadBandTemplate(ossim_float32(0), src, src_rect, clip_rect, band);
2940  return;
2941 
2943  case OSSIM_FLOAT64:
2944  loadBandTemplate(ossim_float64(0), src, src_rect, clip_rect, band);
2945  return;
2946 
2947  case OSSIM_SCALAR_UNKNOWN:
2948  default:
2951  "ossimImageData::loadBand\n\
2952 File %s line %d\nUnknown scalar type!",
2953 __FILE__,
2954 __LINE__);
2955  return;
2956  }
2957 }
2958 
2959 template <class T> void ossimImageData::loadBandTemplate(T, // dummy template variable
2960  const void* src,
2961  const ossimIrect& src_rect,
2962  ossim_uint32 band)
2963 {
2964  const ossimIrect img_rect = getImageRectangle();
2965 
2966  // Get the clip rect.
2967  const ossimIrect clip_rect = img_rect.clipToRect(src_rect);
2968 
2969 
2970  loadBandTemplate(T(0), src, src_rect, clip_rect, band);
2971 }
2972 
2973 template <class T> void ossimImageData::loadBandTemplate(T, // dummy template variable
2974  const void* src,
2975  const ossimIrect& src_rect,
2976  const ossimIrect& clip_rect,
2977  ossim_uint32 band)
2978 {
2979  static const char MODULE[] = "ossimImageData::loadBand";
2980 
2981  // Check the pointer.
2982  if (!src)
2983  {
2984  // Set the error...
2987  "%s File %s line %d\nNULL pointer passed to method!",
2988  MODULE,
2989  __FILE__,
2990  __LINE__);
2991  return;
2992  }
2993 
2994  // Check the band.
2995  if (!isValidBand(band))
2996  {
2997  // Set the error...
3000  "%s File %s line %d\nInvalid band: %d",
3001  MODULE,
3002  __FILE__,
3003  __LINE__,
3004  band);
3005  return;
3006  }
3007 
3008  const ossimIrect img_rect = getImageRectangle();
3009 
3010  // Check for intersect.
3011  if ( ! img_rect.intersects(src_rect) )
3012  {
3013  return; // Nothing to do here.
3014  }
3015 
3016  // Check the clip rect.
3017  if (!clip_rect.completely_within(img_rect))
3018  {
3019  return;
3020  }
3021 
3022  // Check the status and allocate memory if needed.
3024 
3025  // Get the width of the buffers.
3026  ossim_uint32 s_width = src_rect.width();
3027  ossim_uint32 d_width = getWidth();
3028 
3029  const T* s = static_cast<const T*>(src);
3030  T* d = static_cast<T*>(getBuf(band));
3031 
3032  // Move the pointers to the first valid pixel.
3033  s += (clip_rect.ul().y - src_rect.ul().y) * s_width +
3034  clip_rect.ul().x - src_rect.ul().x;
3035 
3036  d += (clip_rect.ul().y - img_rect.ul().y) * d_width +
3037  clip_rect.ul().x - img_rect.ul().x;
3038 
3039  // Copy the data.
3040  ossim_uint32 clipHeight = clip_rect.height();
3041  ossim_uint32 clipWidth = clip_rect.width();
3042 
3043  for (ossim_uint32 line = 0; line < clipHeight; ++line)
3044  {
3045  for (ossim_uint32 sample = 0; sample < clipWidth; ++sample)
3046  {
3047  d[sample] = s[sample];
3048  }
3049 
3050  s += s_width;
3051  d += d_width;
3052  }
3053 }
3054 
3056 {
3057  if (!src)
3058  {
3060  << "ossimImageData::loadTile ERROR:"
3061  << "Null tile passed to method!" << std::endl;
3062  return;
3063  }
3064 
3065  if (!src->getBuf())
3066  {
3068  << "ossimImageData::loadTile ERROR:"
3069  << "Source tile buff is null!" << std::endl;
3070  return;
3071  }
3072 
3073  if (!this->getBuf())
3074  {
3076  << "ossimImageData::loadTile ERROR:"
3077  << "This tile not initialized!" << std::endl;
3078  return;
3079  }
3080 
3081  if (src->getNumberOfBands() != this->getNumberOfBands())
3082  {
3084  << "ossimImageData::loadTile ERROR:"
3085  << "Tiles do not have same number of bands!" << std::endl;
3086  return;
3087  }
3088 
3089  //***
3090  // Set the status of this tile to the status of the source tile.
3091  // Do this in place of validate.
3092  //***
3094 
3095  if(getScalarType() == src->getScalarType())
3096  {
3097  loadTile((void*)(src->getBuf()),
3098  src->getImageRectangle(),
3099  OSSIM_BSQ);
3100  setNullPix(src->getNullPix(), src->getNumberOfBands());
3101  }
3102  else // do a slow generic normalize to unnormalize copy
3103  {
3104  // Check the pointer.
3105  ossimIrect src_rect = src->getImageRectangle();
3106  const ossimIrect img_rect = getImageRectangle();
3107 
3108  // Check for intersect.
3109  if ( !img_rect.intersects(src_rect) )
3110  {
3111  return; // Nothing to do here.
3112  }
3113 
3114  // Get the clip rect.
3115  const ossimIrect clip_rect = img_rect.clipToRect(src_rect);
3116 
3117  // Check the status and allocate memory if needed.
3119 
3120  // Get the width of the buffers.
3121  ossim_uint32 num_bands = getNumberOfBands();
3122  ossim_uint32 s_width = src_rect.width();
3123  ossim_uint32 d_width = getWidth();
3124 
3125  ossim_uint32 band;
3126 
3127  ossim_uint32 sourceOffset = (clip_rect.ul().y - src_rect.ul().y) *
3128  s_width + (clip_rect.ul().x - src_rect.ul().x);
3129 
3130  ossim_uint32 destinationOffset = (clip_rect.ul().y - img_rect.ul().y) *
3131  d_width + (clip_rect.ul().x - img_rect.ul().x);
3132 
3133  ossim_uint32 clipHeight = clip_rect.height();
3134  ossim_uint32 clipWidth = clip_rect.width();
3135 
3136  // Copy the data.
3137  for (band=0; band<num_bands; ++band)
3138  {
3139  ossim_uint32 sourceIndex = sourceOffset;
3140  ossim_uint32 destinationIndex = destinationOffset;
3141  ossim_float32 tempResult = 0.0;
3142 
3143  for (ossim_uint32 line = 0; line < clipHeight; ++line)
3144  {
3145  for (ossim_uint32 sample = 0; sample < clipWidth; ++sample)
3146  {
3147  src->getNormalizedFloat(sourceIndex + sample,
3148  band,
3149  tempResult);
3150 
3151  this->setNormalizedFloat(destinationIndex + sample,
3152  band,
3153  tempResult);
3154  }
3155  sourceIndex += s_width;
3156  destinationIndex += d_width;
3157  }
3158  }
3159  }
3160 }
3161 
3162 void ossimImageData::loadTile(const void* src,
3163  const ossimIrect& src_rect,
3164  ossimInterleaveType il_type)
3165 {
3166  switch (il_type)
3167  {
3168  case OSSIM_BIP:
3169  loadTileFromBip(src, src_rect);
3170  return;
3171  case OSSIM_BIL:
3172  loadTileFromBil(src, src_rect);
3173  return;
3174  case OSSIM_BSQ:
3175  loadTileFromBsq(src, src_rect);
3176  return;
3177  default:
3179  << "ossimImageData::loadTile ERROR: unsupported interleave type!"
3180  << std::endl;
3183  "ossimImageData::loadTile\n\
3184 File %s line %d\nUnknown interleave type!",
3185 __FILE__,
3186 __LINE__);
3187  return;
3188  } // End of "switch (type)"
3189 }
3190 
3192  const ossimIrect& src_rect,
3193  ossimInterleaveType il_type)
3194 {
3195  switch (il_type)
3196  {
3197  case OSSIM_BIP:
3198  loadTileFromBipAlpha(src, src_rect);
3199  return;
3200  /* case OSSIM_BIL:
3201  loadTileFromBil(src, src_rect);
3202  return;
3203  case OSSIM_BSQ:
3204  loadTileFromBsq(src, src_rect);
3205  return;
3206  */
3207  default:
3209  << "ossimImageData::loadTileWithAlpha ERROR: unsupported interleave type!"
3210  << std::endl;
3213  "ossimImageData::loadTile\n\
3214 File %s line %d\nUnknown interleave type!",
3215 __FILE__,
3216 __LINE__);
3217  return;
3218  } // End of "switch (type)"
3219 }
3220 
3221 void ossimImageData::loadTile(const void* src,
3222  const ossimIrect& src_rect,
3223  const ossimIrect& clip_rect,
3224  ossimInterleaveType il_type)
3225 {
3226  switch (il_type)
3227  {
3228  case OSSIM_BIP:
3229  loadTileFromBip(src, src_rect, clip_rect);
3230  return;
3231  case OSSIM_BIL:
3232  loadTileFromBil(src, src_rect, clip_rect);
3233  return;
3234  case OSSIM_BSQ:
3235  loadTileFromBsq(src, src_rect, clip_rect);
3236  return;
3237  default:
3239  << "ossimImageData::loadTile ERROR: unsupported interleave type!"
3240  << std::endl;
3243  "ossimImageData::loadTile\n\
3244 File %s line %d\nUnknown interleave type!",
3245 __FILE__,
3246 __LINE__);
3247  return;
3248  } // End of "switch (type)"
3249 }
3250 
3251 
3253  const ossimIrect& src_rect,
3254  bool multiplyAlphaFlag)
3255 {
3256  const ossimIrect img_rect = getImageRectangle();
3257 
3258  // Get the clip rect.
3259  const ossimIrect clip_rect = img_rect.clipToRect(src_rect);
3260 
3261  nullTileAlpha(src, src_rect, clip_rect, multiplyAlphaFlag);
3262 }
3263 
3265  const ossimIrect& src_rect,
3266  const ossimIrect& clip_rect,
3267  bool multiplyAlphaFlag)
3268 {
3269  switch (getScalarType())
3270  {
3271  case OSSIM_UINT8:
3272  nullTileAlphaTemplate(ossim_uint8(0), src, src_rect, clip_rect, multiplyAlphaFlag);
3273  return;
3274 
3275  case OSSIM_SINT8:
3276  nullTileAlphaTemplate(ossim_sint8(0), src, src_rect, clip_rect, multiplyAlphaFlag);
3277  return;
3278 
3279  case OSSIM_UINT16:
3280  case OSSIM_USHORT11:
3281  case OSSIM_USHORT12:
3282  case OSSIM_USHORT13:
3283  case OSSIM_USHORT14:
3284  case OSSIM_USHORT15:
3285  nullTileAlphaTemplate(ossim_uint16(0), src, src_rect, clip_rect, multiplyAlphaFlag);
3286  return;
3287 
3288  case OSSIM_SINT16:
3289  nullTileAlphaTemplate(ossim_sint16(0), src, src_rect, clip_rect, multiplyAlphaFlag);
3290  return;
3291 
3292  case OSSIM_UINT32:
3293  nullTileAlphaTemplate(ossim_uint32(0), src, src_rect, clip_rect, multiplyAlphaFlag);
3294  return;
3295 
3296  case OSSIM_SINT32:
3297  nullTileAlphaTemplate(ossim_sint32(0), src, src_rect, clip_rect, multiplyAlphaFlag);
3298  return;
3299 
3301  case OSSIM_FLOAT32:
3302  nullTileAlphaTemplate(ossim_float32(0), src, src_rect, clip_rect, multiplyAlphaFlag);
3303  return;
3304 
3306  case OSSIM_FLOAT64:
3307  nullTileAlphaTemplate(ossim_float64(0), src, src_rect, clip_rect, multiplyAlphaFlag);
3308  return;
3309 
3310  case OSSIM_SCALAR_UNKNOWN:
3311  default:
3314  "ossimImageData::nullTileAlpha\n\
3315 File %s line %d\nUnsupported scalar type for method!",
3316 __FILE__,
3317 __LINE__);
3318  return;
3319  }
3320 
3321 }
3322 
3323 void ossimImageData::loadTileFromBip(const void* src,
3324  const ossimIrect& src_rect)
3325 {
3326  switch (getScalarType())
3327  {
3328  case OSSIM_UINT8:
3329  loadTileFromBipTemplate(ossim_uint8(0), src, src_rect);
3330  return;
3331 
3332  case OSSIM_SINT8:
3333  loadTileFromBipTemplate(ossim_sint8(0), src, src_rect);
3334  return;
3335 
3336  case OSSIM_UINT16:
3337  case OSSIM_USHORT11:
3338  case OSSIM_USHORT12:
3339  case OSSIM_USHORT13:
3340  case OSSIM_USHORT14:
3341  case OSSIM_USHORT15:
3342  loadTileFromBipTemplate(ossim_uint16(0), src, src_rect);
3343  return;
3344 
3345  case OSSIM_SINT16:
3346  loadTileFromBipTemplate(ossim_sint16(0), src, src_rect);
3347  return;
3348 
3349  case OSSIM_UINT32:
3350  loadTileFromBipTemplate(ossim_uint32(0), src, src_rect);
3351  return;
3352 
3353  case OSSIM_SINT32:
3354  loadTileFromBipTemplate(ossim_sint32(0), src, src_rect);
3355  return;
3356 
3358  case OSSIM_FLOAT32:
3359  loadTileFromBipTemplate(ossim_float32(0), src, src_rect);
3360  return;
3361 
3363  case OSSIM_FLOAT64:
3364  loadTileFromBipTemplate(ossim_float64(0), src, src_rect);
3365  return;
3366 
3367  case OSSIM_SCALAR_UNKNOWN:
3368  default:
3371  "ossimImageData::loadTileFromBip\n\
3372 File %s line %d\nUnsupported scalar type for method!",
3373 __FILE__,
3374 __LINE__);
3375  return;
3376  }
3377 }
3378 
3380  const ossimIrect& src_rect)
3381 {
3382  switch (getScalarType())
3383  {
3384  case OSSIM_UINT8:
3385  loadTileFromBipAlphaTemplate(ossim_uint8(0), src, src_rect);
3386  return;
3387 
3388  case OSSIM_SINT8:
3389  loadTileFromBipAlphaTemplate(ossim_sint8(0), src, src_rect);
3390  return;
3391 
3392  case OSSIM_UINT16:
3393  case OSSIM_USHORT11:
3394  case OSSIM_USHORT12:
3395  case OSSIM_USHORT13:
3396  case OSSIM_USHORT14:
3397  case OSSIM_USHORT15:
3398  loadTileFromBipAlphaTemplate(ossim_uint16(0), src, src_rect);
3399  return;
3400 
3401  case OSSIM_SINT16:
3402  loadTileFromBipAlphaTemplate(ossim_sint16(0), src, src_rect);
3403  return;
3404 
3405  case OSSIM_UINT32:
3406  loadTileFromBipAlphaTemplate(ossim_uint32(0), src, src_rect);
3407  return;
3408 
3409  case OSSIM_SINT32:
3410  loadTileFromBipAlphaTemplate(ossim_sint32(0), src, src_rect);
3411  return;
3412 
3414  case OSSIM_FLOAT32:
3415  loadTileFromBipAlphaTemplate(ossim_float32(0), src, src_rect);
3416  return;
3417 
3419  case OSSIM_FLOAT64:
3420  loadTileFromBipAlphaTemplate(ossim_float64(0), src, src_rect);
3421  return;
3422 
3423  case OSSIM_SCALAR_UNKNOWN:
3424  default:
3427  "ossimImageData::loadTileFromBip\n\
3428 File %s line %d\nUnsupported scalar type for method!",
3429 __FILE__,
3430 __LINE__);
3431  return;
3432  }
3433 }
3434 
3435 void ossimImageData::loadTileFromBip(const void* src,
3436  const ossimIrect& src_rect,
3437  const ossimIrect& clip_rect)
3438 {
3439  switch (getScalarType())
3440  {
3441  case OSSIM_UINT8:
3442  loadTileFromBipTemplate(ossim_uint8(0), src, src_rect, clip_rect);
3443  return;
3444 
3445  case OSSIM_SINT8:
3446  loadTileFromBipTemplate(ossim_sint8(0), src, src_rect, clip_rect);
3447  return;
3448 
3449  case OSSIM_UINT16:
3450  case OSSIM_USHORT11:
3451  case OSSIM_USHORT12:
3452  case OSSIM_USHORT13:
3453  case OSSIM_USHORT14:
3454  case OSSIM_USHORT15:
3455  loadTileFromBipTemplate(ossim_uint16(0), src, src_rect, clip_rect);
3456  return;
3457 
3458  case OSSIM_SINT16:
3459  loadTileFromBipTemplate(ossim_sint16(0), src, src_rect, clip_rect);
3460  return;
3461 
3462  case OSSIM_UINT32:
3463  loadTileFromBipTemplate(ossim_uint32(0), src, src_rect, clip_rect);
3464  return;
3465 
3466  case OSSIM_SINT32:
3467  loadTileFromBipTemplate(ossim_sint32(0), src, src_rect, clip_rect);
3468  return;
3469 
3471  case OSSIM_FLOAT32:
3472  loadTileFromBipTemplate(ossim_float32(0), src, src_rect, clip_rect);
3473  return;
3474 
3476  case OSSIM_FLOAT64:
3477  loadTileFromBipTemplate(ossim_float64(0), src, src_rect, clip_rect);
3478  return;
3479 
3480  case OSSIM_SCALAR_UNKNOWN:
3481  default:
3484  "ossimImageData::loadTileFromBip\n\
3485 File %s line %d\nUnsupported scalar type for method!",
3486 __FILE__,
3487 __LINE__);
3488  return;
3489  }
3490 }
3491 
3492 void ossimImageData::loadTileFromBil(const void* src,
3493  const ossimIrect& src_rect)
3494 {
3495  switch (getScalarType())
3496  {
3497  case OSSIM_UINT8:
3498  loadTileFromBilTemplate(ossim_uint8(0), src, src_rect);
3499  return;
3500 
3501  case OSSIM_SINT8:
3502  loadTileFromBilTemplate(ossim_sint8(0), src, src_rect);
3503  return;
3504 
3505  case OSSIM_UINT16:
3506  case OSSIM_USHORT11:
3507  case OSSIM_USHORT12:
3508  case OSSIM_USHORT13:
3509  case OSSIM_USHORT14:
3510  case OSSIM_USHORT15:
3511  loadTileFromBilTemplate(ossim_uint16(0), src, src_rect);
3512  return;
3513 
3514  case OSSIM_SINT16:
3515  loadTileFromBilTemplate(ossim_sint16(0), src, src_rect);
3516  return;
3517 
3518  case OSSIM_UINT32:
3519  loadTileFromBilTemplate(ossim_uint32(0), src, src_rect);
3520  return;
3521 
3522  case OSSIM_SINT32:
3523  loadTileFromBilTemplate(ossim_sint32(0), src, src_rect);
3524  return;
3525 
3527  case OSSIM_FLOAT32:
3528  loadTileFromBilTemplate(ossim_float32(0), src, src_rect);
3529  return;
3530 
3532  case OSSIM_FLOAT64:
3533  loadTileFromBilTemplate(ossim_float64(0), src, src_rect);
3534  return;
3535 
3536  case OSSIM_SCALAR_UNKNOWN:
3537  default:
3540  "ossimImageData::loadTileFromBil\n\
3541 File %s line %d\nUnsupported scalar type for method!",
3542 __FILE__,
3543 __LINE__);
3544  return;
3545  }
3546 }
3547 
3548 void ossimImageData::loadTileFromBil(const void* src,
3549  const ossimIrect& src_rect,
3550  const ossimIrect& clip_rect)
3551 {
3552  switch (getScalarType())
3553  {
3554  case OSSIM_UINT8:
3555  loadTileFromBilTemplate(ossim_uint8(0), src, src_rect, clip_rect);
3556  return;
3557 
3558  case OSSIM_SINT8:
3559  loadTileFromBilTemplate(ossim_sint8(0), src, src_rect, clip_rect);
3560  return;
3561 
3562  case OSSIM_UINT16:
3563  case OSSIM_USHORT11:
3564  case OSSIM_USHORT12:
3565  case OSSIM_USHORT13:
3566  case OSSIM_USHORT14:
3567  case OSSIM_USHORT15:
3568  loadTileFromBilTemplate(ossim_uint16(0), src, src_rect, clip_rect);
3569  return;
3570 
3571  case OSSIM_SINT16:
3572  loadTileFromBilTemplate(ossim_sint16(0), src, src_rect, clip_rect);
3573  return;
3574 
3575  case OSSIM_UINT32:
3576  loadTileFromBilTemplate(ossim_uint32(0), src, src_rect, clip_rect);
3577  return;
3578 
3579  case OSSIM_SINT32:
3580  loadTileFromBilTemplate(ossim_sint32(0), src, src_rect, clip_rect);
3581  return;
3582 
3584  case OSSIM_FLOAT32:
3585  loadTileFromBilTemplate(ossim_float32(0), src, src_rect, clip_rect);
3586  return;
3587 
3589  case OSSIM_FLOAT64:
3590  loadTileFromBilTemplate(ossim_float64(0), src, src_rect, clip_rect);
3591  return;
3592 
3593  case OSSIM_SCALAR_UNKNOWN:
3594  default:
3597  "ossimImageData::loadTileFromBil\n\
3598 File %s line %d\nUnsupported scalar type for method!",
3599 __FILE__,
3600 __LINE__);
3601  return;
3602  }
3603 }
3604 
3605 void ossimImageData::loadTileFromBsq(const void* src,
3606  const ossimIrect& src_rect)
3607 {
3608  switch (getScalarType())
3609  {
3610  case OSSIM_UINT8:
3611  loadTileFromBsqTemplate(ossim_uint8(0), src, src_rect);
3612  return;
3613 
3614  case OSSIM_SINT8:
3615  loadTileFromBsqTemplate(ossim_sint8(0), src, src_rect);
3616  return;
3617 
3618  case OSSIM_UINT16:
3619  case OSSIM_USHORT11:
3620  case OSSIM_USHORT12:
3621  case OSSIM_USHORT13:
3622  case OSSIM_USHORT14:
3623  case OSSIM_USHORT15:
3624  loadTileFromBsqTemplate(ossim_uint16(0), src, src_rect);
3625  return;
3626 
3627  case OSSIM_SINT16:
3628  loadTileFromBsqTemplate(ossim_sint16(0), src, src_rect);
3629  return;
3630 
3631  case OSSIM_UINT32:
3632  loadTileFromBsqTemplate(ossim_uint32(0), src, src_rect);
3633  return;
3634 
3635  case OSSIM_SINT32:
3636  loadTileFromBsqTemplate(ossim_sint32(0), src, src_rect);
3637  return;
3638 
3640  case OSSIM_FLOAT32:
3641  loadTileFromBsqTemplate(ossim_float32(0), src, src_rect);
3642  return;
3643 
3645  case OSSIM_FLOAT64:
3646  loadTileFromBsqTemplate(ossim_float64(0), src, src_rect);
3647  return;
3648 
3649  case OSSIM_SCALAR_UNKNOWN:
3650  default:
3653  "ossimImageData::loadTileFromBsq\n\
3654 File %s line %d\nUnsupported scalar type for method!",
3655 __FILE__,
3656 __LINE__);
3657  return;
3658  }
3659 }
3660 
3661 void ossimImageData::loadTileFromBsq(const void* src,
3662  const ossimIrect& src_rect,
3663  const ossimIrect& clip_rect)
3664 {
3665  switch (getScalarType())
3666  {
3667  case OSSIM_UINT8:
3668  loadTileFromBsqTemplate(ossim_uint8(0), src, src_rect, clip_rect);
3669  return;
3670 
3671  case OSSIM_SINT8:
3672  loadTileFromBsqTemplate(ossim_sint8(0), src, src_rect, clip_rect);
3673  return;
3674 
3675  case OSSIM_UINT16:
3676  case OSSIM_USHORT11:
3677  case OSSIM_USHORT12:
3678  case OSSIM_USHORT13:
3679  case OSSIM_USHORT14:
3680  case OSSIM_USHORT15:
3681  loadTileFromBsqTemplate(ossim_uint16(0), src, src_rect, clip_rect);
3682  return;
3683 
3684  case OSSIM_SINT16:
3685  loadTileFromBsqTemplate(ossim_sint16(0), src, src_rect, clip_rect);
3686  return;
3687 
3688  case OSSIM_UINT32:
3689  loadTileFromBsqTemplate(ossim_uint32(0), src, src_rect, clip_rect);
3690  return;
3691 
3692  case OSSIM_SINT32:
3693  loadTileFromBsqTemplate(ossim_sint32(0), src, src_rect, clip_rect);
3694  return;
3695 
3697  case OSSIM_FLOAT32:
3698  loadTileFromBsqTemplate(ossim_float32(0), src, src_rect, clip_rect);
3699  return;
3700 
3702  case OSSIM_FLOAT64:
3703  loadTileFromBsqTemplate(ossim_float64(0), src, src_rect, clip_rect);
3704  return;
3705 
3706  case OSSIM_SCALAR_UNKNOWN:
3707  default:
3710  "ossimImageData::loadTileFromBsq\n\
3711 File %s line %d\nUnsupported scalar type for method!",
3712 __FILE__,
3713 __LINE__);
3714  return;
3715  }
3716 }
3717 
3718 void ossimImageData::computeMinMaxPix(vector<ossim_float64>& minBands,
3719  vector<ossim_float64>& maxBands) const
3720 {
3721  if ( (getDataObjectStatus() == OSSIM_NULL) ||
3723  {
3724  return;
3725  }
3726 
3727  switch(m_scalarType)
3728  {
3729  case OSSIM_UINT8:
3730  {
3732  minBands,
3733  maxBands);
3734  break;
3735  }
3736  case OSSIM_SINT8:
3737  {
3739  minBands,
3740  maxBands);
3741  break;
3742 
3743  }
3744  case OSSIM_USHORT11:
3745  case OSSIM_USHORT12:
3746  case OSSIM_USHORT13:
3747  case OSSIM_USHORT14:
3748  case OSSIM_USHORT15:
3749  case OSSIM_UINT16:
3750  {
3752  minBands,
3753  maxBands);
3754  break;
3755  }
3756  case OSSIM_SINT16:
3757  {
3759  minBands,
3760  maxBands);
3761  break;
3762  }
3763  case OSSIM_UINT32:
3764  {
3766  minBands,
3767  maxBands);
3768  break;
3769  }
3770  case OSSIM_SINT32:
3771  {
3773  minBands,
3774  maxBands);
3775  break;
3776  }
3778  case OSSIM_FLOAT32:
3779  {
3781  minBands,
3782  maxBands);
3783  break;
3784  }
3786  case OSSIM_FLOAT64:
3787  {
3789  minBands,
3790  maxBands);
3791  break;
3792  }
3793  case OSSIM_SCALAR_UNKNOWN:
3794  default:
3795  {
3796  // Shouldn't hit this.
3798  << "ossimImageData::computeMinPix Unsupported scalar type!"
3799  << std::endl;
3800  break;
3801  }
3802  }
3803 }
3804 
3805 template <class T>
3806 void ossimImageData::computeMinMaxPix(T /* dummyValue */,
3807  vector<ossim_float64>& minBands,
3808  vector<ossim_float64>& maxBands) const
3809 {
3810  const ossim_uint32 BANDS = getNumberOfBands();
3811  const ossim_uint32 SPB = getSizePerBand();
3812 
3813  if( minBands.size() != BANDS ||
3814  maxBands.size() != BANDS )
3815  {
3816  minBands.resize(BANDS);
3817  maxBands.resize(BANDS);
3818  for (ossim_uint32 band = 0; band < BANDS; ++band)
3819  {
3820  // Set min to max and max to min for starters.
3821  minBands[band] = getMaxPix(band);
3822  maxBands[band] = getMinPix(band);
3823  }
3824  }
3825 
3826  for(ossim_uint32 band = 0; band < BANDS; ++band)
3827  {
3828  const T* bandBuffer = (const T*)getBuf(band);
3829  if(bandBuffer)
3830  {
3831  const T NP = static_cast<T>(getNullPix(band));
3832  ossim_float64 currentMin = minBands[band];
3833  ossim_float64 currentMax = maxBands[band];
3834  for(ossim_uint32 offset = 0; offset < SPB; ++offset)
3835  {
3836  T p = bandBuffer[offset];
3837  if(p != NP)
3838  {
3839  if(p < currentMin)
3840  {
3841  currentMin = p;
3842  }
3843  else if(p > currentMax)
3844  {
3845  currentMax = p;
3846  }
3847  }
3848  }
3849  minBands[band] = currentMin;
3850  maxBands[band] = currentMax;
3851  }
3852  }
3853 }
3854 
3855 void ossimImageData::computeMinMaxNulPix(vector<ossim_float64>& minBands,
3856  vector<ossim_float64>& maxBands,
3857  vector<ossim_float64>& nulBands) const
3858 {
3859  if ( getDataObjectStatus() == OSSIM_NULL )
3860  {
3861  return;
3862  }
3863 
3864  switch(m_scalarType)
3865  {
3866  case OSSIM_UINT8:
3867  {
3869  minBands,
3870  maxBands,
3871  nulBands);
3872  break;
3873  }
3874  case OSSIM_SINT8:
3875  {
3877  minBands,
3878  maxBands,
3879  nulBands);
3880  break;
3881  }
3882  case OSSIM_USHORT11:
3883  case OSSIM_USHORT12:
3884  case OSSIM_USHORT13:
3885  case OSSIM_USHORT14:
3886  case OSSIM_USHORT15:
3887  case OSSIM_UINT16:
3888  {
3890  minBands,
3891  maxBands,
3892  nulBands);
3893  break;
3894  }
3895  case OSSIM_SINT16:
3896  {
3898  minBands,
3899  maxBands,
3900  nulBands);
3901  break;
3902  }
3903  case OSSIM_UINT32:
3904  {
3906  minBands,
3907  maxBands,
3908  nulBands);
3909  break;
3910  }
3911  case OSSIM_SINT32:
3912  {
3914  minBands,
3915  maxBands,
3916  nulBands);
3917  break;
3918  }
3920  case OSSIM_FLOAT32:
3921  {
3923  minBands,
3924  maxBands,
3925  nulBands);
3926  break;
3927  }
3929  case OSSIM_FLOAT64:
3930  {
3932  minBands,
3933  maxBands,
3934  nulBands);
3935  break;
3936  }
3937  case OSSIM_SCALAR_UNKNOWN:
3938  default:
3939  {
3940  // Shouldn't hit this.
3942  << "ossimImageData::computeMinNulPix Unsupported scalar type!"
3943  << std::endl;
3944  break;
3945  }
3946  }
3947 }
3948 
3949 template <class T>
3950 void ossimImageData::computeMinMaxNulPix(T /* dummyValue */,
3951  vector<ossim_float64>& minBands,
3952  vector<ossim_float64>& maxBands,
3953  vector<ossim_float64>& nulBands) const
3954 {
3955  const ossim_uint32 BANDS = getNumberOfBands();
3956  const ossim_uint32 SPB = getSizePerBand();
3957  T DEFAULT_NULL = static_cast<T>(ossim::defaultNull(getScalarType()));
3958 
3959  if( minBands.size() != BANDS ||
3960  maxBands.size() != BANDS ||
3961  nulBands.size() != BANDS )
3962  {
3963  // First time through.
3964  minBands.resize(BANDS);
3965  maxBands.resize(BANDS);
3966  nulBands.resize(BANDS);
3967  for (ossim_uint32 band = 0; band < BANDS; ++band)
3968  {
3969  // Set min to max and max to min for starters.
3970  minBands[band] = getMaxPix(band);
3971  maxBands[band] = getMinPix(band);
3972  nulBands[band] = getMaxPix(band);
3973  }
3974  }
3975 
3976  for(ossim_uint32 band = 0; band < BANDS; ++band)
3977  {
3978  const T* bandBuffer = (const T*)getBuf(band);
3979  if(bandBuffer)
3980  {
3981  ossim_float64 currentMin = minBands[band];
3982  ossim_float64 currentMax = maxBands[band];
3983  ossim_float64 currentNul = nulBands[band];
3984  for(ossim_uint32 offset = 0; offset < SPB; ++offset)
3985  {
3986  T p = bandBuffer[offset];
3987 
3988  // Since we are scanning for nulls this is making an assumption that the default
3989  // null is incorrect and should be ignored in this scan as it could have been
3990  // introduced by a make blank on a partial tile so ignore it.
3991  // NOTE (OLK 03/2015): It is a bad idea to ignore pixels with default nulls, as it may
3992  // be the actual null value being used. By ignoring it, a new null will be latched
3993  // corresponding to actual, non-null, minimum value. Unfortunately, when tiles are
3994  // initialized, they are filled with default nulls since (with float-data), the
3995  // null (if any exists) is not yet known -- effectively creating two null pixel values.
3996  // The recommendation (if you're looking at this code, then you're probably having the
3997  // problem that your nulls aren't being recognized), is to turn off the flag in your
3998  // ossim prefs file with: overview_builder.scan_for_min_max_null_if_float: false
3999  // (or just delete that line)
4000  if ( p != DEFAULT_NULL )
4001  {
4002  // Must do null first as min depends on null.
4003  if ( p < currentNul )
4004  {
4005  currentNul = p;
4006  }
4007  if( ( p < currentMin ) && ( p > currentNul ) )
4008  {
4009  currentMin = p;
4010  }
4011  else if( p > currentMax )
4012  {
4013  currentMax = p;
4014  }
4015  }
4016  }
4017  minBands[band] = currentMin;
4018  maxBands[band] = currentMax;
4019  nulBands[band] = currentNul;
4020  }
4021  }
4022 }
4023 
4024 template <class T>
4025 void ossimImageData::loadTileFromBipTemplate(T, // dummy template variable
4026  const void* src,
4027  const ossimIrect& src_rect)
4028 {
4029  const ossimIrect img_rect = getImageRectangle();
4030 
4031  // Get the clip rect.
4032  const ossimIrect clip_rect = img_rect.clipToRect(src_rect);
4033 
4034  loadTileFromBipTemplate(T(0), src, src_rect, clip_rect);
4035 }
4036 template <class T>
4037 void ossimImageData::loadTileFromBipAlphaTemplate(T, // dummy template variable
4038  const void* src,
4039  const ossimIrect& src_rect)
4040 {
4041  const ossimIrect img_rect = getImageRectangle();
4042 
4043  // Get the clip rect.
4044  const ossimIrect clip_rect = img_rect.clipToRect(src_rect);
4045 
4046  loadTileFromBipAlphaTemplate(T(0), src, src_rect, clip_rect);
4047 }
4048 
4049 template <class T>
4050 void ossimImageData::loadTileFromBipTemplate(T, // dummy template variable
4051  const void* src,
4052  const ossimIrect& src_rect,
4053  const ossimIrect& clip_rect)
4054 {
4055  static const char MODULE[] = "ossimImageData::loadTileFromBip";
4056 
4057  // Check the pointer.
4058  if (!src)
4059  {
4060  // Set the error...
4063  "%s File %s line %d\nNULL pointer passed to method!",
4064  MODULE,
4065  __FILE__,
4066  __LINE__);
4067  return;
4068  }
4069 
4070  const ossimIrect img_rect = getImageRectangle();
4071 
4072  // Check for intersect.
4073  if ( ! img_rect.intersects(src_rect) )
4074  {
4075  return; // Nothing to do here.
4076  }
4077 
4078  // Check the clip rect.
4079  if (!clip_rect.completely_within(img_rect))
4080  {
4081  return;
4082  }
4083 
4084  // Check the status and allocate memory if needed.
4086 
4087  // Get the width of the buffers.
4088  ossim_uint32 num_bands = getNumberOfBands();
4089  ossim_uint32 s_width = (src_rect.width()) * num_bands;
4090  ossim_uint32 d_width = getWidth();
4091  ossim_uint32 band = 0;
4092  const T* s = static_cast<const T*>(src);
4093  T** d = new T*[num_bands];
4094 
4095  // Make destination pointers to each one.
4096  for (band=0; band<num_bands; band++)
4097  {
4098  d[band] = static_cast<T*>(getBuf(band));
4099 
4100  // Move the pointers to the first valid pixel.
4101  d[band] += (clip_rect.ul().y - img_rect.ul().y) * d_width +
4102  clip_rect.ul().x - img_rect.ul().x;
4103  }
4104 
4105  // Move the source pointer to the first valid pixel.
4106  s += (clip_rect.ul().y - src_rect.ul().y) * s_width +
4107  (clip_rect.ul().x - src_rect.ul().x) * num_bands;
4108 
4109  // Copy the data.
4110  ossim_uint32 clipHeight = clip_rect.height();
4111  ossim_uint32 clipWidth = clip_rect.width();
4112 
4113  for (ossim_uint32 line = 0; line < clipHeight; ++line)
4114  {
4115  ossim_uint32 j = 0;
4116  for (ossim_uint32 sample = 0; sample < clipWidth; ++sample)
4117  {
4118  for (band=0; band<num_bands; band++)
4119  {
4120  d[band][sample] = s[j+band];
4121  }
4122  j += num_bands;
4123  }
4124 
4125  s += s_width;
4126  for (band=0; band<num_bands; band++)
4127  {
4128  d[band] += d_width;
4129  }
4130  }
4131 
4132  delete [] d;
4133 }
4134 
4135 template <class T>
4136 void ossimImageData::loadTileFromBipAlphaTemplate(T, // dummy template variable
4137  const void* src,
4138  const ossimIrect& src_rect,
4139  const ossimIrect& clip_rect)
4140 {
4141  static const char MODULE[] = "ossimImageData::loadTileFromBip";
4142 
4143  // Check the pointer.
4144  if (!src)
4145  {
4146  // Set the error...
4149  "%s File %s line %d\nNULL pointer passed to method!",
4150  MODULE,
4151  __FILE__,
4152  __LINE__);
4153  return;
4154  }
4155 
4156  const ossimIrect img_rect = getImageRectangle();
4157 
4158  // Check for intersect.
4159  if ( ! img_rect.intersects(src_rect) )
4160  {
4161  return; // Nothing to do here.
4162  }
4163 
4164  // Check the clip rect.
4165  if (!clip_rect.completely_within(img_rect))
4166  {
4167  return;
4168  }
4169 
4170  // Check the status and allocate memory if needed.
4172 
4173  // Get the width of the buffers.
4174  ossim_uint32 num_bands = getNumberOfBands();
4175  ossim_uint32 s_width = (src_rect.width()) * (num_bands+1);
4176  ossim_uint32 d_width = getWidth();
4177  ossim_uint32 band = 0;
4178  const T* s = static_cast<const T*>(src);
4179  T** d = new T*[num_bands];
4180 
4181  // Make destination pointers to each one.
4182  for (band=0; band<num_bands; band++)
4183  {
4184  d[band] = static_cast<T*>(getBuf(band));
4185 
4186  // Move the pointers to the first valid pixel.
4187  d[band] += (clip_rect.ul().y - img_rect.ul().y) * d_width +
4188  clip_rect.ul().x - img_rect.ul().x;
4189  }
4190 
4191  // Move the source pointer to the first valid pixel.
4192  s += (clip_rect.ul().y - src_rect.ul().y) * s_width +
4193  (clip_rect.ul().x - src_rect.ul().x) * (num_bands+1); // +1 for the alpha
4194 
4195  // Copy the data.
4196  ossim_uint32 clipHeight = clip_rect.height();
4197  ossim_uint32 clipWidth = clip_rect.width();
4198 
4199  for (ossim_uint32 line = 0; line < clipHeight; ++line)
4200  {
4201  ossim_uint32 j = 0;
4202  for (ossim_uint32 sample = 0; sample < clipWidth; ++sample)
4203  {
4204  for (band=0; band<num_bands; band++)
4205  {
4206  d[band][sample] = s[j+band];
4207  }
4208  j += (num_bands+1); // need to offset by the alpha channel
4209  }
4210 
4211  s += s_width;
4212  for (band=0; band<num_bands; band++)
4213  {
4214  d[band] += d_width;
4215  }
4216  }
4217 
4218  delete [] d;
4219 }
4220 
4221 template <class T>
4222 void ossimImageData::loadTileFromBilTemplate(T, // dummy template variable
4223  const void* src,
4224  const ossimIrect& src_rect)
4225 {
4226  const ossimIrect img_rect = getImageRectangle();
4227 
4228  // Get the clip rect.
4229  const ossimIrect clip_rect = img_rect.clipToRect(src_rect);
4230 
4231  loadTileFromBilTemplate(T(0), src, src_rect, clip_rect);
4232 }
4233 
4234 template <class T>
4235 void ossimImageData::loadTileFromBilTemplate(T, // dummy template variable
4236  const void* src,
4237  const ossimIrect& src_rect,
4238  const ossimIrect& clip_rect)
4239 {
4240  static const char MODULE[] = "ossimImageData::loadTileFromBil";
4241 
4242  // Check the pointer.
4243  if (!src)
4244  {
4245  // Set the error...
4248  "%s File %s line %d\nNULL pointer passed to method!",
4249  MODULE,
4250  __FILE__,
4251  __LINE__);
4252  return;
4253  }
4254 
4255  const ossimIrect img_rect = getImageRectangle();
4256 
4257  // Check for intersect.
4258  if ( ! img_rect.intersects(src_rect) )
4259  {
4260  return; // Nothing to do here.
4261  }
4262 
4263  // Check the clip rect.
4264  if (!clip_rect.completely_within(img_rect))
4265  {
4266  return;
4267  }
4268 
4269  // Check the status and allocate memory if needed.
4271 
4272  // Get the width of the buffers.
4273  ossim_uint32 num_bands = getNumberOfBands();
4274  ossim_uint32 s_width = (src_rect.lr().x - src_rect.ul().x + 1);
4275  ossim_uint32 d_width = getWidth();
4276  ossim_uint32 band = 0;
4277  ossim_uint32 d_offset = (clip_rect.ul().y - img_rect.ul().y) * d_width +
4278  clip_rect.ul().x - img_rect.ul().x;
4279 
4280  const T* s = static_cast<const T*>(src);
4281 
4282  // Get the number of bands and make destination pointers to each one.
4283  T** d = new T*[num_bands];
4284 
4285  for (band=0; band<num_bands; band++)
4286  {
4287  d[band] = static_cast<T*>(getBuf(band));
4288 
4289  // Move the pointers to the first valid pixel.
4290  d[band] += d_offset;
4291  }
4292 
4293  // Move the source pointer to the first valid pixel.
4294  s += (clip_rect.ul().y - src_rect.ul().y) * s_width * num_bands +
4295  clip_rect.ul().x - src_rect.ul().x;
4296 
4297  // Copy the data.
4298  ossim_uint32 clipHeight = clip_rect.height();
4299  ossim_uint32 clipWidth = clip_rect.width();
4300 
4301  for (ossim_uint32 line = 0; line < clipHeight; ++line)
4302  {
4303  for (band = 0; band < num_bands; ++band)
4304  {
4305  for (ossim_uint32 sample = 0; sample < clipWidth; ++sample)
4306  {
4307  d[band][sample] = s[sample];
4308  }
4309  s += s_width;
4310  d[band] += d_width;
4311  }
4312  }
4313 
4314  delete [] d;
4315 }
4316 
4317 template <class T>
4318 void ossimImageData::loadTileFromBsqTemplate(T, // dummy template variable
4319  const void* src,
4320  const ossimIrect& src_rect)
4321 {
4322  const ossimIrect img_rect = getImageRectangle();
4323 
4324  // Get the clip rect.
4325  const ossimIrect clip_rect = img_rect.clipToRect(src_rect);
4326 
4327  loadTileFromBsqTemplate(T(0), src, src_rect, clip_rect);
4328 }
4329 
4330 template <class T>
4331 void ossimImageData::loadTileFromBsqTemplate(T, // dummy template variable
4332  const void* src,
4333  const ossimIrect& src_rect,
4334  const ossimIrect& clip_rect)
4335 {
4336  static const char MODULE[] = "ossimImageData::loadTileFromBsq";
4337 
4338  // Check the pointer.
4339  if (!src)
4340  {
4341  // Set the error...
4344  "%s File %s line %d\nNULL pointer passed to method!",
4345  MODULE,
4346  __FILE__,
4347  __LINE__);
4348  return;
4349  }
4350 
4351  const ossimIrect img_rect = getImageRectangle();
4352 
4353  // Check for intersect.
4354  if ( ! img_rect.intersects(src_rect) )
4355  {
4356  return; // Nothing to do here.
4357  }
4358 
4359  // Check the clip rect.
4360  if (!clip_rect.completely_within(img_rect))
4361  {
4362  return;
4363  }
4364 
4365  // Check the status and allocate memory if needed.
4367 
4368  // Get the width of the buffers.
4369  ossim_uint32 num_bands = getNumberOfBands();
4370  ossim_uint32 s_width = src_rect.width();
4371  ossim_uint32 d_width = getWidth();
4372  ossim_uint32 s_band_offset = s_width * src_rect.height();
4373 
4374  const T* s = static_cast<const T*>(src);
4375 
4376  ossim_uint32 band;
4377  ossim_uint32 destinationOffset = (clip_rect.ul().y - img_rect.ul().y) * d_width +
4378  (clip_rect.ul().x - img_rect.ul().x);
4379  ossim_uint32 destinationIndex = destinationOffset;
4380  ossim_uint32 sourceOffset = (clip_rect.ul().y - src_rect.ul().y) * s_width +
4381  (clip_rect.ul().x - src_rect.ul().x);
4382  ossim_uint32 sourceIndex = sourceOffset;
4383  ossim_uint32 clipHeight = clip_rect.height();
4384  ossim_uint32 clipWidth = clip_rect.width();
4385 
4386  // Copy the data.
4387  for (band=0; band<num_bands; band++)
4388  {
4389  T* destinationBand = static_cast<T*>(getBuf(band));
4390  destinationIndex = destinationOffset;
4391  sourceIndex = sourceOffset + s_band_offset*band;
4392 
4393  for (ossim_uint32 line = 0; line < clipHeight; ++line)
4394  {
4395  for (ossim_uint32 sample = 0; sample < clipWidth; ++sample)
4396  {
4397  destinationBand[destinationIndex + sample]
4398  = s[sourceIndex+sample];
4399  }
4400  sourceIndex += s_width;
4401  destinationIndex += d_width;
4402  }
4403  }
4404 }
4405 
4407  const ossimIrect& src_rect)
4408 {
4409  ossim_uint32 bands = getNumberOfBands();
4410  for(ossim_uint32 band = 0; band < bands; ++band)
4411  {
4412  loadBand(src, src_rect, band);
4413  }
4414 }
4415 
4417 {
4418  if(!src) return;
4419  loadTileFrom1Band((const void*)src->getBuf(),
4420  src->getImageRectangle());
4421 }
4422 
4423 void ossimImageData::loadShortBand(const void* src,
4424  const ossimIrect& src_rect,
4425  ossim_uint32 band,
4426  bool swap_bytes)
4427 {
4428  static const char MODULE[] = "ossimImageData::loadShortBand";
4429 
4430  // Check the pointer.
4431  if (!src)
4432  {
4433  // Set the error...
4436  "%s File %s line %d\nNULL pointer passed to method!",
4437  MODULE,
4438  __FILE__,
4439  __LINE__);
4440  return;
4441  }
4442 
4443  // Check the band.
4444  if (!isValidBand(band))
4445  {
4446  // Set the error...
4449  "%s File %s line %d\nInvalid band: %d",
4450  MODULE,
4451  __FILE__,
4452  __LINE__,
4453  band);
4454  return;
4455  }
4456 
4457  const ossimIrect img_rect = getImageRectangle();
4458 
4459  // Check for intersect.
4460  if ( ! img_rect.intersects(src_rect) )
4461  {
4462  return; // Nothing to do here.
4463  }
4464 
4465  // Get the clip rect.
4466  const ossimIrect clip_rect = img_rect.clipToRect(src_rect);
4467 
4468  // Check the status and allocate memory if needed.
4470 
4471  // Get the width of the buffers.
4472  ossim_uint32 s_width = src_rect.width();
4473  ossim_uint32 d_width = getWidth();
4474 
4475  const ossim_uint16* s = static_cast<const ossim_uint16*>(src);
4476  ossim_uint16* d = getUshortBuf(band);
4477 
4478  // Move the pointers to the first valid pixel.
4479  s += (clip_rect.ul().y - src_rect.ul().y) * s_width +
4480  clip_rect.ul().x - src_rect.ul().x;
4481 
4482  d += (clip_rect.ul().y - img_rect.ul().y) * d_width +
4483  clip_rect.ul().x - img_rect.ul().x;
4484 
4485  // Copy the data.
4486  for (ossim_int32 line=clip_rect.ul().y; line<=clip_rect.lr().y; line++)
4487  {
4488  ossim_uint32 i = 0;
4489  for (ossim_int32 sample=clip_rect.ul().x; sample<=clip_rect.lr().x; sample++)
4490  {
4491  d[i] = (swap_bytes ? ( (s[i] << 8) | (s[i] >> 8) ) :
4492  s[i]);
4493  ++i;
4494  }
4495 
4496  s += s_width;
4497  d += d_width;
4498  }
4499 
4500  validate();
4501 }
4502 
4504 {
4505  return ((point.x >= m_origin.x)&&
4506  (point.y >= m_origin.y)&&
4507  ((point.x - m_origin.x)<static_cast<ossim_int32>(m_spatialExtents[0]))&&
4508  ((point.y - m_origin.y)<static_cast<ossim_int32>(m_spatialExtents[1])));
4509 }
4510 
4512 {
4513  return ((x >= m_origin.x)&&
4514  (y >= m_origin.y)&&
4515  ((x - m_origin.x) < static_cast<ossim_int32>(m_spatialExtents[0]))&&
4516  ((y - m_origin.y) < static_cast<ossim_int32>(m_spatialExtents[1])));
4517 }
4518 
4520  const ossimIrect& dest_rect,
4521  ossimInterleaveType type) const
4522 {
4523  unloadTile(dest, dest_rect, getImageRectangle(), type);
4524 }
4525 
4527  const ossimIrect& dest_rect,
4528  const ossimIrect& clip_rect,
4529  ossimInterleaveType type) const
4530 {
4531  switch (type)
4532  {
4533  case OSSIM_BIP:
4534  unloadTileToBip(dest, dest_rect, clip_rect);
4535  return;
4536  case OSSIM_BIL:
4537  unloadTileToBil(dest, dest_rect, clip_rect);
4538  return;
4539  case OSSIM_BSQ:
4540  unloadTileToBsq(dest, dest_rect, clip_rect);
4541  return;
4542  default:
4545  "ossimImageData::unloadTile\n\
4546 File %s line %d\nUnknown scalar type!",
4547 __FILE__,
4548 __LINE__);
4549  return;
4550  }
4551 }
4552 
4554  const ossimIrect& dest_rect,
4555  const ossimIrect& clip_rect) const
4556 {
4557  switch (getScalarType())
4558  {
4559  case OSSIM_UINT8:
4560  unloadTileToBipTemplate(ossim_uint8(0), dest, dest_rect, clip_rect);
4561  return;
4562 
4563  case OSSIM_SINT8:
4564  unloadTileToBipTemplate(ossim_sint8(0), dest, dest_rect, clip_rect);
4565  return;
4566 
4567  case OSSIM_UINT16:
4568  case OSSIM_USHORT11:
4569  case OSSIM_USHORT12:
4570  case OSSIM_USHORT13:
4571  case OSSIM_USHORT14:
4572  case OSSIM_USHORT15:
4573  unloadTileToBipTemplate(ossim_uint16(0), dest, dest_rect, clip_rect);
4574  return;
4575 
4576  case OSSIM_SINT16:
4577  unloadTileToBipTemplate(ossim_sint16(0), dest, dest_rect, clip_rect);
4578  return;
4579 
4580  case OSSIM_UINT32:
4581  unloadTileToBipTemplate(ossim_uint32(0), dest, dest_rect, clip_rect);
4582  return;
4583 
4584  case OSSIM_SINT32:
4585  unloadTileToBipTemplate(ossim_sint32(0), dest, dest_rect, clip_rect);
4586  return;
4587 
4589  case OSSIM_FLOAT32:
4590  unloadTileToBipTemplate(ossim_float32(0), dest, dest_rect, clip_rect);
4591  return;
4592 
4594  case OSSIM_FLOAT64:
4595  unloadTileToBipTemplate(ossim_float64(0), dest, dest_rect, clip_rect);
4596  return;
4597 
4598  case OSSIM_SCALAR_UNKNOWN:
4599  default:
4602  "ossimImageData::unloadTileToBip\n\
4603 File %s line %d\nUnsupported scalar type for method!",
4604 __FILE__,
4605 __LINE__);
4606  return;
4607  }
4608 }
4609 
4611  const ossimIrect& dest_rect,
4612  const ossimIrect& clip_rect) const
4613 {
4614  switch (getScalarType())
4615  {
4616  case OSSIM_UINT8:
4617  unloadTileToBipAlphaTemplate(ossim_uint8(0), dest, dest_rect, clip_rect);
4618  return;
4619 
4620  case OSSIM_SINT8:
4621  unloadTileToBipAlphaTemplate(ossim_sint8(0), dest, dest_rect, clip_rect);
4622  return;
4623 
4624  case OSSIM_UINT16:
4625  case OSSIM_USHORT11:
4626  case OSSIM_USHORT12:
4627  case OSSIM_USHORT13:
4628  case OSSIM_USHORT14:
4629  case OSSIM_USHORT15:
4630  unloadTileToBipAlphaTemplate(ossim_uint16(0), dest, dest_rect, clip_rect);
4631  return;
4632 
4633  case OSSIM_SINT16:
4634  unloadTileToBipAlphaTemplate(ossim_sint16(0), dest, dest_rect, clip_rect);
4635  return;
4636 
4637  case OSSIM_UINT32:
4638  unloadTileToBipAlphaTemplate(ossim_uint32(0), dest, dest_rect, clip_rect);
4639  return;
4640 
4641  case OSSIM_SINT32:
4642  unloadTileToBipAlphaTemplate(ossim_sint32(0), dest, dest_rect, clip_rect);
4643  return;
4644 
4646  case OSSIM_FLOAT32:
4647  unloadTileToBipAlphaTemplate(ossim_float32(0), dest, dest_rect, clip_rect);
4648  return;
4649 
4651  case OSSIM_FLOAT64:
4652  unloadTileToBipAlphaTemplate(ossim_float64(0), dest, dest_rect, clip_rect);
4653  return;
4654 
4655  case OSSIM_SCALAR_UNKNOWN:
4656  default:
4659  "ossimImageData::unloadTileToBipAlpha\n\
4660 File %s line %d\nUnsupported scalar type for method!",
4661 __FILE__,
4662 __LINE__);
4663  return;
4664  }
4665 }
4666 
4668  const ossimIrect& dest_rect,
4669  const ossimIrect& clip_rect) const
4670 {
4671  switch (getScalarType())
4672  {
4673  case OSSIM_UINT8:
4674  unloadTileToBilTemplate(ossim_uint8(0), dest, dest_rect, clip_rect);
4675  return;
4676 
4677  case OSSIM_SINT8:
4678  unloadTileToBilTemplate(ossim_sint8(0), dest, dest_rect, clip_rect);
4679  return;
4680 
4681  case OSSIM_UINT16:
4682  case OSSIM_USHORT11:
4683  case OSSIM_USHORT12:
4684  case OSSIM_USHORT13:
4685  case OSSIM_USHORT14:
4686  case OSSIM_USHORT15:
4687  unloadTileToBilTemplate(ossim_uint16(0), dest, dest_rect, clip_rect);
4688  return;
4689 
4690  case OSSIM_SINT16:
4691  unloadTileToBilTemplate(ossim_sint16(0), dest, dest_rect, clip_rect);
4692  return;
4693 
4694  case OSSIM_UINT32:
4695  unloadTileToBilTemplate(ossim_uint32(0), dest, dest_rect, clip_rect);
4696  return;
4697 
4698  case OSSIM_SINT32:
4699  unloadTileToBilTemplate(ossim_sint32(0), dest, dest_rect, clip_rect);
4700  return;
4701 
4703  case OSSIM_FLOAT32:
4704  unloadTileToBilTemplate(ossim_float32(0), dest, dest_rect, clip_rect);
4705  return;
4706 
4708  case OSSIM_FLOAT64:
4709  unloadTileToBilTemplate(ossim_float64(0), dest, dest_rect, clip_rect);
4710  return;
4711 
4712  case OSSIM_SCALAR_UNKNOWN:
4713  default:
4716  "ossimImageData::unloadTileToBil\n\
4717 File %s line %d\nUnsupported scalar type for method!",
4718 __FILE__,
4719 __LINE__);
4720  return;
4721  }
4722 }
4723 
4725  const ossimIrect& dest_rect,
4726  const ossimIrect& clip_rect) const
4727 {
4728  switch (getScalarType())
4729  {
4730  case OSSIM_UINT8:
4731  unloadTileToBsqTemplate(ossim_uint8(0), dest, dest_rect, clip_rect);
4732  return;
4733 
4734  case OSSIM_SINT8:
4735  unloadTileToBsqTemplate(ossim_sint8(0), dest, dest_rect, clip_rect);
4736  return;
4737 
4738  case OSSIM_UINT16:
4739  case OSSIM_USHORT11:
4740  case OSSIM_USHORT12:
4741  case OSSIM_USHORT13:
4742  case OSSIM_USHORT14:
4743  case OSSIM_USHORT15:
4744  unloadTileToBsqTemplate(ossim_uint16(0), dest, dest_rect, clip_rect);
4745  return;
4746 
4747  case OSSIM_SINT16:
4748  unloadTileToBsqTemplate(ossim_sint16(0), dest, dest_rect, clip_rect);
4749  return;
4750 
4751  case OSSIM_UINT32:
4752  unloadTileToBsqTemplate(ossim_uint32(0), dest, dest_rect, clip_rect);
4753  return;
4754 
4755  case OSSIM_SINT32:
4756  unloadTileToBsqTemplate(ossim_sint32(0), dest, dest_rect, clip_rect);
4757  return;
4758 
4760  case OSSIM_FLOAT32:
4761  unloadTileToBsqTemplate(ossim_float32(0), dest, dest_rect, clip_rect);
4762  return;
4763 
4765  case OSSIM_FLOAT64:
4766  unloadTileToBsqTemplate(ossim_float64(0), dest, dest_rect, clip_rect);
4767  return;
4768 
4769  case OSSIM_SCALAR_UNKNOWN:
4770  default:
4773  "ossimImageData::unloadTileToBsq\n\
4774 File %s line %d\nUnsupported scalar type for method!",
4775 __FILE__,
4776 __LINE__);
4777  return;
4778  }
4779 }
4780 
4782  const ossimIrect& dest_rect,
4783  ossim_uint32 band) const
4784 {
4785  unloadBand(dest, dest_rect, getImageRectangle(), band);
4786 }
4787 
4789  const ossimIrect& dest_rect,
4790  const ossimIrect& clip_rect,
4791  ossim_uint32 band) const
4792 {
4793  // Call the appropriate load method.
4794  switch (getScalarType())
4795  {
4796  case OSSIM_UINT8:
4797  unloadBandTemplate(ossim_uint8(0), dest, dest_rect, clip_rect, band);
4798  return;
4799 
4800  case OSSIM_SINT8:
4801  unloadBandTemplate(ossim_sint8(0), dest, dest_rect, clip_rect, band);
4802  return;
4803 
4804  case OSSIM_UINT16:
4805  case OSSIM_USHORT11:
4806  case OSSIM_USHORT12:
4807  case OSSIM_USHORT13:
4808  case OSSIM_USHORT14:
4809  case OSSIM_USHORT15:
4810  unloadBandTemplate(ossim_uint16(0), dest, dest_rect, clip_rect, band);
4811  return;
4812 
4813  case OSSIM_SINT16:
4814  unloadBandTemplate(ossim_sint16(0), dest, dest_rect, clip_rect, band);
4815  return;
4816 
4817  case OSSIM_UINT32:
4818  unloadBandTemplate(ossim_uint32(0), dest, dest_rect, clip_rect, band);
4819  return;
4820 
4821  case OSSIM_SINT32:
4822  unloadBandTemplate(ossim_sint32(0), dest, dest_rect, clip_rect, band);
4823  return;
4824 
4826  case OSSIM_FLOAT32:
4827  unloadBandTemplate(ossim_float32(0), dest, dest_rect, clip_rect, band);
4828  return;
4829 
4831  case OSSIM_FLOAT64:
4832  unloadBandTemplate(ossim_float64(0), dest, dest_rect, clip_rect, band);
4833  return;
4834 
4835  case OSSIM_SCALAR_UNKNOWN:
4836  default:
4839  "ossimImageData::unloadBand\n\
4840 File %s line %d\nUnsupported scalar type for method!",
4841 __FILE__,
4842 __LINE__);
4843  return;
4844  }
4845 }
4846 
4848  ossim_uint32 src_band,
4849  ossim_uint32 dest_band,
4850  const ossimIrect& dest_rect,
4851  ossimInterleaveType il_type,
4852  OverwriteBandRule ow_type ) const
4853 {
4854  unloadBand( dest, src_band, dest_band, dest_rect, getImageRectangle(), il_type, ow_type );
4855 }
4856 
4858  ossim_uint32 src_band,
4859  ossim_uint32 dest_band,
4860  const ossimIrect& dest_rect,
4861  const ossimIrect& clip_rect,
4862  ossimInterleaveType il_type,
4863  OverwriteBandRule ow_type ) const
4864 {
4865  static const char MODULE[] = "ossimImageData::unloadBand";
4866 
4867  if ( il_type == OSSIM_BSQ )
4868  {
4869  unloadBandToBsq( dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4870  }
4871  else
4872  {
4874  << MODULE << " NOTICE:"
4875  << "\nUnsupported interleave type: " << il_type << " Returning..."
4876  << std::endl;
4877  }
4878 }
4879 
4881  ossim_uint32 src_band,
4882  ossim_uint32 dest_band,
4883  const ossimIrect& dest_rect,
4884  const ossimIrect& clip_rect,
4885  OverwriteBandRule ow_type ) const
4886 {
4887  switch (getScalarType())
4888  {
4889  case OSSIM_UINT8:
4890  unloadBandToBsqTemplate(ossim_uint8(0), dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4891  return;
4892 
4893  case OSSIM_SINT8:
4894  unloadBandToBsqTemplate(ossim_sint8(0), dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4895  return;
4896 
4897  case OSSIM_UINT16:
4898  case OSSIM_USHORT11:
4899  case OSSIM_USHORT12:
4900  case OSSIM_USHORT13:
4901  case OSSIM_USHORT14:
4902  case OSSIM_USHORT15:
4903  unloadBandToBsqTemplate(ossim_uint16(0), dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4904  return;
4905 
4906  case OSSIM_SINT16:
4907  unloadBandToBsqTemplate(ossim_sint16(0), dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4908  return;
4909 
4910  case OSSIM_UINT32:
4911  unloadBandToBsqTemplate(ossim_uint32(0), dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4912  return;
4913 
4914  case OSSIM_SINT32:
4915  unloadBandToBsqTemplate(ossim_sint32(0), dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4916  return;
4917 
4919  case OSSIM_FLOAT32:
4920  unloadBandToBsqTemplate(ossim_float32(0), dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4921  return;
4922 
4924  case OSSIM_FLOAT64:
4925  unloadBandToBsqTemplate(ossim_float64(0), dest, src_band, dest_band, dest_rect, clip_rect, ow_type );
4926  return;
4927 
4928  case OSSIM_SCALAR_UNKNOWN:
4929  default:
4932  "ossimImageData::unloadBandToBsq\n\
4933  File %s line %d\nUnsupported scalar type for method!",
4934  __FILE__,
4935  __LINE__);
4936  return;
4937  }
4938 }
4939 
4940 template <class T>
4941 void ossimImageData::unloadBandTemplate(T, // dummy template variable
4942  void* dest,
4943  const ossimIrect& dest_rect,
4944  const ossimIrect& clip_rect,
4945  ossim_uint32 band) const
4946 {
4947  static const char MODULE[] = "ossimImageData::unloadBand";
4948 
4949  // Check the pointers.
4950  if (!dest)
4951  {
4953  << MODULE << " ERROR:"
4954  << "\nNULL pointer passed to method! Returning..." << std::endl;
4955  return;
4956  }
4957 
4959  {
4961  << MODULE << " ERROR:"
4962  << "\nThis object is null! Returning..." << std::endl;
4963  return;
4964  }
4965 
4966  ossimIrect img_rect = getImageRectangle();
4967 
4968  // Clip the clip_rect to the tile rect.
4969  ossimIrect output_clip_rect = clip_rect.clipToRect(img_rect);
4970 
4971  // Clip it again to the destination rect.
4972  output_clip_rect = dest_rect.clipToRect(output_clip_rect);
4973 
4974  // Check the output clip rect for intersection.
4975  if (!output_clip_rect.intersects(img_rect))
4976  {
4977  return;
4978  }
4979  if ( !(output_clip_rect.intersects(dest_rect)) )
4980  {
4981  return;
4982  }
4983 
4984  // Check for valid band.
4985  if (!isValidBand(band))
4986  {
4988  << MODULE << " NOTICE:"
4989  << "\nInvalid band: " << band << " Returning..."
4990  << std::endl;
4991  return;
4992  }
4993 
4994  ossim_uint32 buf_width = dest_rect.lr().x - dest_rect.ul().x + 1;
4995 
4996  // Get a pointer to the source band buffer.
4997  const T* s = reinterpret_cast<const T*>(getBuf(band));
4998 
4999  // Get the offset for each source band.
5000  ossim_uint32 src_offset = (output_clip_rect.ul().y - img_rect.ul().y) *
5001  getWidth() + output_clip_rect.ul().x - img_rect.ul().x;
5002 
5003  // Move the pointers to the start.
5004  T* d = reinterpret_cast<T*>(dest);
5005 
5006  ossim_uint32 dest_offset = (output_clip_rect.ul().y - dest_rect.ul().y) *
5007  buf_width + output_clip_rect.ul().x - dest_rect.ul().x;
5008 
5009  d += dest_offset;
5010  s += src_offset;
5011 
5012  for (ossim_int32 line=output_clip_rect.ul().y;
5013  line<=output_clip_rect.lr().y; ++line)
5014  {
5015  ossim_uint32 i=0;
5016  for (ossim_int32 samp=clip_rect.ul().x;
5017  samp<=output_clip_rect.lr().x; ++samp)
5018  {
5019  d[i] = s[i];
5020  ++i;
5021  }
5022  d += buf_width;
5023  s += getWidth();
5024  }
5025 }
5026 
5027 template <class T> void
5028 ossimImageData::unloadTileToBipTemplate(T, // dummy template variable
5029  void* dest,
5030  const ossimIrect& dest_rect,
5031  const ossimIrect& clip_rect) const
5032 {
5033  static const char MODULE[] = "ossimImageData::unloadTileToBip";
5034 
5035  // Check the pointer.
5036  if (!dest)
5037  {
5039  << MODULE << " ERROR:"
5040  << "\nNULL pointer passed to method! Returning..." << std::endl;
5041  return;
5042  }
5043 
5044  bool dataIsNull = false;
5046  {
5047  dataIsNull = true;
5048  }
5049 
5050  ossimIrect img_rect = getImageRectangle();
5051 
5052  // Clip the clip_rect to the tile rect.
5053  ossimIrect output_clip_rect = clip_rect.clipToRect(img_rect);
5054 
5055  // Clip it again to the destination rect.
5056  output_clip_rect = dest_rect.clipToRect(output_clip_rect);
5057 
5058  // Check the output clip rect for intersection.
5059  if (output_clip_rect.hasNans())
5060  {
5061  return;
5062  }
5063  if ( !(output_clip_rect.intersects(dest_rect)) )
5064  {
5065  return;
5066  }
5067 
5068  ossim_int32 num_bands = getNumberOfBands();
5069 
5070  ossim_int32 buf_width = dest_rect.width() * num_bands;
5071 
5072  if(!dataIsNull)
5073  {
5074  // Get the number of bands and grab a pointers to each one.
5075  const T** s = new const T*[num_bands];
5076 
5077  ossim_int32 band;
5078  ossim_int32 s_width = getWidth();
5079 
5080  for (band=0; band<num_bands; band++)
5081  {
5082  s[band] = reinterpret_cast<const T*>(getBuf(band));
5083  }
5084 
5085  // Move the pointers to the start.
5086  T* d = reinterpret_cast<T*>(dest);
5087 
5088  d += (output_clip_rect.ul().y - dest_rect.ul().y) * buf_width +
5089  (output_clip_rect.ul().x - dest_rect.ul().x) * num_bands;
5090 
5091  // Get the offset for each source band.
5092  ossim_int32 src_offset = (output_clip_rect.ul().y - img_rect.ul().y) *
5093  s_width + (output_clip_rect.ul().x - img_rect.ul().x);
5094 
5095  ossim_int32 output_clip_width = output_clip_rect.width();
5096  ossim_int32 output_clip_height = output_clip_rect.height();
5097 
5098  for (band=0; band<(ossim_int32)getNumberOfBands(); band++)
5099  {
5100  s[band] += src_offset;
5101  }
5102 
5103  ossim_int32 j;
5104  for (ossim_int32 line=0; line<output_clip_height; ++line)
5105  {
5106  j = 0;
5107  for (ossim_int32 samp=0; samp<output_clip_width; ++samp, j+=num_bands)
5108  {
5109  for (band=0; band<num_bands; ++band)
5110  {
5111  d[j+band] = s[band][samp];
5112  }
5113  }
5114 
5115  // increment to next line...
5116  d += buf_width;
5117  for (band=0; band<num_bands; ++band)
5118  {
5119  s[band] += s_width;
5120  }
5121 
5122  }
5123  delete [] s;
5124  }
5125  else
5126  {
5127  ossim_int32 band = 0;
5128  T* nulls = new T[num_bands];
5129  for(band = 0; band < num_bands; ++band)
5130  {
5131  nulls[band] = static_cast<T>(m_nullPixelValue[band]);
5132  }
5133  // Move the pointers to the start.
5134  T* d = reinterpret_cast<T*>(dest);
5135 
5136  d += (output_clip_rect.ul().y - dest_rect.ul().y) * buf_width +
5137  (output_clip_rect.ul().x - dest_rect.ul().x) * num_bands;
5138 
5139  for (ossim_int32 line=output_clip_rect.ul().y;
5140  line<=output_clip_rect.lr().y; ++line)
5141  {
5142  ossim_int32 i=0;
5143  ossim_int32 j=0;
5144  for (ossim_int32 samp=output_clip_rect.ul().x;
5145  samp<=output_clip_rect.lr().x; ++samp)
5146  {
5147  for (band=0; band<num_bands; ++band)
5148  {
5149  d[j+band] = nulls[band];
5150  }
5151  ++i; // increment to next pixel...
5152  j+= num_bands;
5153  }
5154 
5155  // increment to next line...
5156  d += buf_width;
5157  }
5158  delete [] nulls;
5159  nulls = 0;
5160  }
5161 }
5162 
5163 template <class T> void
5165  void* dest,
5166  const ossimIrect& dest_rect,
5167  const ossimIrect& clip_rect) const
5168 {
5169  static const char M[] = "ossimImageData::unloadTileToBipAlphaTemplate";
5170 
5171  // Sanity checks:
5172 
5173  // Are we null:
5175  {
5177  << M << " ERROR:"
5178  << "\nAttempting to copy null tile! Returning..." << std::endl;
5179  return;
5180  }
5181 
5182  // Check the pointer.
5183  if (!dest)
5184  {
5186  << M << " ERROR:"
5187  << "\nNULL pointer passed to method! Returning..." << std::endl;
5188  return;
5189  }
5190 
5191  if ( !hasAlpha() )
5192  {
5194  << M << " ERROR:"
5195  << "\nTile has no alpha! Returning..." << std::endl;
5196  return;
5197  }
5198 
5199  ossimIrect img_rect = getImageRectangle();
5200 
5201  // Clip the clip_rect to the tile rect.
5202  ossimIrect output_clip_rect = clip_rect.clipToRect(img_rect);
5203 
5204  // Clip it again to the destination rect.
5205  output_clip_rect = dest_rect.clipToRect(output_clip_rect);
5206 
5207  // Check the output clip rect for intersection.
5208  if (output_clip_rect.hasNans())
5209  {
5210  return;
5211  }
5212  if ( !(output_clip_rect.intersects(dest_rect)) )
5213  {
5214  return;
5215  }
5216 
5217  const ossim_int32 NUM_DATA_BANDS = getNumberOfBands();
5218  const ossim_int32 BANDS = NUM_DATA_BANDS + 1; // Has data plus alpha.
5219  const ossim_float64 MAX_PIX = static_cast<T>(getMaxPix(0));
5220  const ossim_float64 ALPHA_MAX_PIX = 255.00;
5221  const ossim_int32 S_WIDTH = getWidth();
5222  const ossim_int32 D_WIDTH = dest_rect.width() * BANDS;
5223  const ossim_int32 OUTPUT_CLIP_WIDTH = output_clip_rect.width();
5224  const ossim_int32 OUTPUT_CLIP_HEIGHT = output_clip_rect.height();
5225 
5226  bool uint8Flag = ( getScalarType() == OSSIM_UINT8 );
5227 
5228  // Get the offset for each source band relative to start of clip rect.
5229  const ossim_int32 SRC_OFFSET = (output_clip_rect.ul().y - img_rect.ul().y) *
5230  S_WIDTH + (output_clip_rect.ul().x - img_rect.ul().x);
5231 
5232  // Get pointers to each one band of image data.
5233  std::vector<const T*> s(NUM_DATA_BANDS);
5234  ossim_int32 band;
5235  for (band = 0; band < NUM_DATA_BANDS; ++band)
5236  {
5237  s[band] = reinterpret_cast<const T*>(getBuf(band));
5238 
5239  // Move to start of clip rect.
5240  s[band] += SRC_OFFSET;
5241  }
5242 
5243  // Get pointer to the alpha channel:
5244  const ossim_uint8* a = getAlphaBuf();
5245 
5246  // Move to start of clip rect.
5247  a += SRC_OFFSET;
5248 
5249  // Pointer to the destination buffer.
5250  T* d = reinterpret_cast<T*>(dest);
5251 
5252  // Move to start of clip rect.
5253  d += (output_clip_rect.ul().y - dest_rect.ul().y) * D_WIDTH +
5254  (output_clip_rect.ul().x - dest_rect.ul().x) * BANDS;
5255 
5256 
5257  // Loop to copy data:
5258  for (ossim_int32 line = 0; line < OUTPUT_CLIP_HEIGHT; ++line)
5259  {
5260  ossim_int32 j = 0;
5261  ossim_int32 alphaIdx = 0;
5262  for (ossim_int32 samp = 0; samp < OUTPUT_CLIP_WIDTH; ++samp, j +=BANDS)
5263  {
5264  // Copy the pixels:
5265  for (band = 0; band < NUM_DATA_BANDS; ++band)
5266  {
5267  d[j+band] = s[band][samp];
5268  }
5269 
5270  // Copy alpha channel converting to scalar type.
5271  if ( uint8Flag )
5272  {
5273  d[j+NUM_DATA_BANDS] = a[alphaIdx++];
5274  }
5275  else
5276  {
5277  d[j+NUM_DATA_BANDS] =
5278  static_cast<T>( (a[alphaIdx++]/ALPHA_MAX_PIX) * MAX_PIX );
5279  }
5280  }
5281 
5282  // Increment pointers to next line...
5283  d += D_WIDTH;
5284  for (band = 0; band < NUM_DATA_BANDS; ++band)
5285  {
5286  s[band] += S_WIDTH;
5287  }
5288  a += S_WIDTH;
5289  }
5290 }
5291 
5292 template <class T> void
5293 ossimImageData::unloadTileToBilTemplate(T, // dummy template arg...
5294  void* dest,
5295  const ossimIrect& dest_rect,
5296  const ossimIrect& clip_rect) const
5297 {
5298  static const char MODULE[] = "ossimImageData::unloadTileToBil";
5299 
5300  // Check the pointers.
5301  if (!dest)
5302  {
5304  << MODULE << " ERROR:"
5305  << "\nNULL pointer passed to method! Returning..." << std::endl;
5306  return;
5307  }
5308  bool dataIsNull = false;
5310  {
5311  dataIsNull = true;
5312  }
5313 
5314  ossimIrect img_rect = getImageRectangle();
5315 
5316  // Clip the clip_rect to the tile rect.
5317  ossimIrect output_clip_rect = clip_rect.clipToRect(img_rect);
5318 
5319  // Clip it again to the destination rect.
5320  output_clip_rect = dest_rect.clipToRect(output_clip_rect);
5321 
5322  // Check the output clip rect for intersection.
5323  if (output_clip_rect.hasNans())
5324  {
5325  return;
5326  }
5327  if ( !(output_clip_rect.intersects(dest_rect)) )
5328  {
5329  return;
5330  }
5331 
5332  ossim_uint32 num_bands = getNumberOfBands();
5333 
5334  ossim_uint32 buf_width = dest_rect.width();
5335 
5336  if(!dataIsNull)
5337  {
5338  // Get the number of bands and grab a pointers to each one.
5339  const T** s = new const T*[num_bands];
5340 
5341  ossim_uint32 band;
5342 
5343  for (band=0; band<num_bands; band++)
5344  {
5345  s[band] = reinterpret_cast<const T*>(getBuf(band));
5346  }
5347 
5348  // Get the offset for each source band.
5349  ossim_uint32 src_offset = (output_clip_rect.ul().y - img_rect.ul().y) *
5350  getWidth() + (output_clip_rect.ul().x - img_rect.ul().x);
5351 
5352  // Move the pointers to the start.
5353  T* d = reinterpret_cast<T*>(dest);
5354 
5355  d += (output_clip_rect.ul().y - dest_rect.ul().y) *
5356  buf_width * num_bands +
5357  (output_clip_rect.ul().x-dest_rect.ul().x);
5358 
5359  for (band=0; band<num_bands; ++band)
5360  {
5361  s[band] += src_offset;
5362  }
5363 
5364  for (ossim_int32 line=output_clip_rect.ul().y;
5365  line<=output_clip_rect.lr().y; ++line)
5366  {
5367  for (band=0; band<num_bands; ++band)
5368  {
5369  ossim_uint32 i=0;
5370  for (ossim_int32 samp=output_clip_rect.ul().x;
5371  samp<=output_clip_rect.lr().x; ++samp)
5372  {
5373  d[i] = s[band][i];
5374  ++i;
5375  }
5376  d += buf_width;
5377  s[band] += getWidth();
5378  }
5379  }
5380  // Free up memory allocated for pointers.
5381  delete [] s;
5382  }
5383  else
5384  {
5385  ossim_uint32 band = 0;
5386  T* nulls = new T[num_bands];
5387  for(band = 0; band < num_bands; ++band)
5388  {
5389  nulls[band] = static_cast<T>(m_nullPixelValue[band]);
5390  }
5391 
5392  // Move the pointers to the start.
5393  T* d = reinterpret_cast<T*>(dest);
5394 
5395  d += (output_clip_rect.ul().y - dest_rect.ul().y) *
5396  buf_width * num_bands + (output_clip_rect.ul().x - dest_rect.ul().x);
5397 
5398  for (ossim_int32 line=output_clip_rect.ul().y;
5399  line<=output_clip_rect.lr().y; ++line)
5400  {
5401  for (band=0; band<num_bands; ++band)
5402  {
5403  ossim_uint32 i=0;
5404  for (ossim_int32 samp=output_clip_rect.ul().x;
5405  samp<=output_clip_rect.lr().x; ++samp)
5406  {
5407  d[i] = nulls[band];
5408  ++i;
5409  }
5410  d += buf_width;
5411  }
5412  }
5413  delete [] nulls;
5414  }
5415 }
5416 
5418  T,
5419  const ossim_uint8* src,
5420  const ossimIrect& src_rect,
5421  const ossimIrect& clip_rect,
5422  bool multiplyAlphaFlag)
5423 {
5424  static const char MODULE[] = "ossimImageData::nullTileAlphaTemplate";
5425 
5426  // Check the pointer.
5427  if (!src)
5428  {
5429  // Set the error...
5432  "%s File %s line %d\nNULL pointer passed to method!",
5433  MODULE,
5434  __FILE__,
5435  __LINE__);
5436  return;
5437  }
5438 
5439  const ossimIrect img_rect = getImageRectangle();
5440 
5441  // Check for intersect.
5442  if ( ! img_rect.intersects(src_rect) )
5443  {
5444  return; // Nothing to do here.
5445  }
5446 
5447  // Check the clip rect.
5448  if (!clip_rect.completely_within(img_rect))
5449  {
5450  return;
5451  }
5452 
5453  // Check the status and allocate memory if needed.
5455 
5456  // Get the width of the buffers.
5457  ossim_uint32 num_bands = getNumberOfBands();
5458  ossim_uint32 s_width = src_rect.width();
5459  ossim_uint32 d_width = getWidth();
5460  ossim_uint32 band;
5461  ossim_uint32 destinationOffset = (clip_rect.ul().y - img_rect.ul().y) * d_width +
5462  (clip_rect.ul().x - img_rect.ul().x);
5463  ossim_uint32 destinationIndex = destinationOffset;
5464  ossim_uint32 sourceOffset = (clip_rect.ul().y - src_rect.ul().y) * s_width +
5465  (clip_rect.ul().x - src_rect.ul().x);
5466  ossim_uint32 sourceIndex = sourceOffset;
5467  ossim_uint32 clipHeight = clip_rect.height();
5468  ossim_uint32 clipWidth = clip_rect.width();
5469 
5470  if(!multiplyAlphaFlag)
5471  {
5472  // Copy the data.
5473  for (band=0; band<num_bands; band++)
5474  {
5475  T* destinationBand = static_cast<T*>(getBuf(band));
5476  destinationIndex = destinationOffset;
5477  sourceIndex = sourceOffset;
5478  T nullPix = (T)getNullPix(band);
5479  T minPix = (T)getMinPix(band);
5480  for (ossim_uint32 line = 0; line < clipHeight; ++line)
5481  {
5482  for (ossim_uint32 sample = 0; sample < clipWidth; ++sample)
5483  {
5484  if(src[sourceIndex+sample] == 0)
5485  {
5486  destinationBand[destinationIndex + sample] = nullPix;
5487  }
5488  else if(destinationBand[destinationIndex + sample] == nullPix)
5489  {
5490  destinationBand[destinationIndex + sample] = minPix;
5491  }
5492  }
5493  sourceIndex += s_width;
5494  destinationIndex += d_width;
5495  }
5496  }
5497  }
5498  else
5499  {
5500  ossim_float64 normalizer = 1.0/255.0;
5501  // Copy the data.
5502  for (band=0; band<num_bands; band++)
5503  {
5504  T* destinationBand = static_cast<T*>(getBuf(band));
5505  destinationIndex = destinationOffset;
5506  sourceIndex = sourceOffset;
5507  T nullPix = (T)getNullPix(band);
5508  T minPix = (T)getMinPix(band);
5509  for (ossim_uint32 line = 0; line < clipHeight; ++line)
5510  {
5511  for (ossim_uint32 sample = 0; sample < clipWidth; ++sample)
5512  {
5513  if(src[sourceIndex+sample] != 255)
5514  {
5515  if(src[sourceIndex+sample] != 0)
5516  {
5517  destinationBand[destinationIndex + sample] = (T)(destinationBand[destinationIndex + sample]*
5518  (src[sourceIndex+sample]*normalizer));
5519  if(destinationBand[destinationIndex + sample] == nullPix)
5520  {
5521  destinationBand[destinationIndex + sample] = minPix;
5522  }
5523  }
5524  else
5525  {
5526  destinationBand[destinationIndex + sample] = nullPix;
5527  }
5528  }
5529  else if(destinationBand[destinationIndex + sample] == nullPix)
5530  {
5531  destinationBand[destinationIndex + sample] = minPix;
5532  }
5533  }
5534  sourceIndex += s_width;
5535  destinationIndex += d_width;
5536  }
5537  }
5538 
5539  }
5540 }
5541 
5542 template <class T> void
5543 ossimImageData::unloadTileToBsqTemplate(T, // dummy template arg...
5544  void* dest,
5545  const ossimIrect& dest_rect,
5546  const ossimIrect& clip_rect) const
5547 {
5548  static const char MODULE[] = "ossimImageData::unloadTileToBsq";
5549 
5550  // Check the pointers.
5551  if (!dest)
5552  {
5554  << MODULE << " ERROR:"
5555  << "\nNULL pointer passed to method! Returning..." << std::endl;
5556  return;
5557  }
5558 
5559  bool dataIsNull = false;
5561  {
5562  dataIsNull = true;
5563  }
5564 
5565  ossimIrect img_rect = getImageRectangle();
5566 
5567  // Clip the clip_rect to the tile rect.
5568  ossimIrect output_clip_rect = clip_rect.clipToRect(img_rect);
5569 
5570  // Clip it again to the destination rect.
5571  output_clip_rect = dest_rect.clipToRect(output_clip_rect);
5572 
5573  // Check the output clip rect for intersection.
5574  if (output_clip_rect.hasNans())
5575  {
5576  return;
5577  }
5578  if ( !(output_clip_rect.intersects(dest_rect)) )
5579  {
5580  return;
5581  }
5582 
5583  ossim_uint32 num_bands = getNumberOfBands();
5584  ossim_uint32 band = 0;
5585  if(!dataIsNull)
5586  {
5587  ossim_uint32 d_width = dest_rect.lr().x - dest_rect.ul().x + 1;
5588  ossim_uint32 d_band_offset = d_width * (dest_rect.lr().y-dest_rect.ul().y+1);
5589  ossim_uint32 s_width = getWidth();
5590  ossim_uint32 s_offset = (output_clip_rect.ul().y - img_rect.ul().y) *
5591  s_width + (output_clip_rect.ul().x - img_rect.ul().x);
5592 
5593  T* d = static_cast<T*>(dest);
5594  const T** s = new const T*[num_bands];
5595 
5596  // Grab a pointers to each one.
5597  for (band=0; band<num_bands; ++band)
5598  {
5599  s[band] = reinterpret_cast<const T*>(getBuf(band));
5600 
5601  // Move to first valid pixel.
5602  s[band] += s_offset;
5603  }
5604 
5605  // Move to first valid pixel.
5606  d += (output_clip_rect.ul().y - dest_rect.ul().y) * d_width +
5607  (output_clip_rect.ul().x - dest_rect.ul().x);
5608 
5609  for (band=0; band<num_bands; ++band)
5610  {
5611  ossim_uint32 d_buf_offset = 0;
5612 
5613  for (ossim_int32 line=output_clip_rect.ul().y;
5614  line<=output_clip_rect.lr().y; ++line)
5615  {
5616  ossim_int32 i=0;
5617  for (ossim_int32 samp=output_clip_rect.ul().x;
5618  samp<=output_clip_rect.lr().x; ++samp)
5619  {
5620  d[d_buf_offset+i] = s[band][i];
5621  ++i;
5622  }
5623 
5624  d_buf_offset += d_width;
5625  s[band] += s_width;
5626  }
5627  d += d_band_offset;
5628  }
5629 
5630  // Free up memory allocated for pointers.
5631  delete [] s;
5632  }
5633  else
5634  {
5635  ossim_uint32 d_width = dest_rect.lr().x - dest_rect.ul().x + 1;
5636  ossim_uint32 d_band_offset = d_width * (dest_rect.lr().y-dest_rect.ul().y+1);
5637 
5638  ossim_uint8* d = static_cast<ossim_uint8*>(dest);
5639 
5640  // Move to first valid pixel.
5641  d += (output_clip_rect.ul().y - dest_rect.ul().y) * d_width +
5642  (output_clip_rect.ul().x - dest_rect.ul().x);
5643 
5644  for (band=0; band<num_bands; ++band)
5645  {
5646  ossim_uint8 np = static_cast<ossim_uint8>(m_nullPixelValue[band]);
5647  ossim_uint32 d_buf_offset = 0;
5648 
5649  for (ossim_int32 line=output_clip_rect.ul().y;
5650  line<=output_clip_rect.lr().y; ++line)
5651  {
5652  ossim_int32 i=0;
5653  for (ossim_int32 samp=output_clip_rect.ul().x;
5654  samp<=output_clip_rect.lr().x; ++samp)
5655  {
5656  d[d_buf_offset+i] = np;
5657  ++i;
5658  }
5659 
5660  d_buf_offset += d_width;
5661  }
5662  d += d_band_offset;
5663  }
5664  }
5665 }
5666 
5667 template <class T> void
5668 ossimImageData::unloadBandToBsqTemplate(T, // dummy template arg...
5669  void* dest,
5670  ossim_uint32 src_band,
5671  ossim_uint32 dest_band,
5672  const ossimIrect& dest_rect,
5673  const ossimIrect& clip_rect,
5674  OverwriteBandRule ow_type) const
5675 {
5676  static const char MODULE[] = "ossimImageData::unloadBandToBsq";
5677 
5678  // Check the pointers.
5679  if (!dest)
5680  {
5682  << MODULE << " ERROR:"
5683  << "\nNULL pointer passed to method! Returning..." << std::endl;
5684  return;
5685  }
5686 
5687  bool dataIsNull = false;
5689  {
5690  dataIsNull = true;
5691  }
5692 
5693  ossimIrect img_rect = getImageRectangle();
5694 
5695  // Clip the clip_rect to the tile rect.
5696  ossimIrect output_clip_rect = clip_rect.clipToRect(img_rect);
5697 
5698  // Clip it again to the destination rect.
5699  output_clip_rect = dest_rect.clipToRect(output_clip_rect);
5700 
5701  // Check the output clip rect for intersection.
5702  if (output_clip_rect.hasNans())
5703  {
5704  return;
5705  }
5706  if ( !(output_clip_rect.intersects(dest_rect)) )
5707  {
5708  return;
5709  }
5710 
5711  ossim_uint32 num_bands = getNumberOfBands();
5712  ossim_uint32 band = 0;
5713  if(!dataIsNull)
5714  {
5715  ossim_uint32 d_width = dest_rect.lr().x - dest_rect.ul().x + 1;
5716  ossim_uint32 d_band_offset = d_width * (dest_rect.lr().y-dest_rect.ul().y+1);
5717  ossim_uint32 s_width = getWidth();
5718  ossim_uint32 s_offset = (output_clip_rect.ul().y - img_rect.ul().y) *
5719  s_width + (output_clip_rect.ul().x - img_rect.ul().x);
5720 
5721  T* d = static_cast<T*>(dest);
5722  const T** s = new const T*[num_bands];
5723 
5724  // Grab a pointers to each one.
5725  for (band=0; band<num_bands; ++band)
5726  {
5727  s[band] = reinterpret_cast<const T*>(getBuf(band));
5728 
5729  // Move to first valid pixel.
5730  s[band] += s_offset;
5731  }
5732 
5733  // Move to first valid pixel.
5734  d += (output_clip_rect.ul().y - dest_rect.ul().y) * d_width +
5735  (output_clip_rect.ul().x - dest_rect.ul().x);
5736 
5737  ossim_uint32 d_dest_band_offset = dest_band * d_band_offset;
5738  ossim_uint32 d_buf_offset = 0;
5739 
5740  for (ossim_int32 line=output_clip_rect.ul().y;
5741  line<=output_clip_rect.lr().y; ++line)
5742  {
5743  ossim_int32 i=0;
5744  for (ossim_int32 samp=output_clip_rect.ul().x;
5745  samp<=output_clip_rect.lr().x; ++samp)
5746  {
5747  ossim_uint32 d_pixel_offset = d_buf_offset+i;
5748  ossim_uint32 d_dest_band_pixel_offset = d_pixel_offset + d_dest_band_offset;
5749 
5750  switch( ow_type )
5751  {
5752  case COLOR_DISCREPANCY:
5754  {
5755  T d_dest_band = d[d_dest_band_pixel_offset];
5756 
5757  for ( band=0; band<num_bands && band!=dest_band; ++band )
5758  {
5759  T d_other_band = d[d_pixel_offset + (band * d_band_offset)];
5760 
5761  // test for color discrepancy
5762  if ( d_other_band != d_dest_band )
5763  {
5764  d[d_dest_band_pixel_offset] = s[src_band][i];
5765  break;
5766  }
5767  }
5768  }
5769  break;
5770 
5772  {
5773  T d_dest_band = d[d_dest_band_pixel_offset];
5774 
5775  bool bFoundSameValue = false;
5776  for ( band=0; band<num_bands && band!=dest_band; ++band )
5777  {
5778  T d_other_band = d[d_pixel_offset + (band * d_band_offset)];
5779 
5780  // test for color sameness
5781  if ( d_other_band == d_dest_band )
5782  {
5783  bFoundSameValue = true;
5784  break;
5785  }
5786  }
5787  if ( bFoundSameValue == false )
5788  {
5789  d[d_dest_band_pixel_offset] = s[src_band][i];
5790  }
5791  }
5792  break;
5793 
5795  {
5796  T d_src_band = s[src_band][i];
5797 
5798  for ( band=0; band<num_bands && band!=dest_band; ++band )
5799  {
5800  T d_other_band = d[d_pixel_offset + (band * d_band_offset)];
5801 
5802  // test for color discrepancy
5803  if ( d_other_band == d_src_band )
5804  {
5805  d[d_dest_band_pixel_offset] = s[src_band][i];
5806  break;
5807  }
5808  }
5809  }
5810  break;
5811 
5813  {
5814  T d_src_band = s[src_band][i];
5815 
5816  bool bFoundDifferentValue = false;
5817  for ( band=0; band<num_bands && band!=dest_band; ++band )
5818  {
5819  T d_other_band = d[d_pixel_offset + (band * d_band_offset)];
5820 
5821  // test for color discrepancy
5822  if ( d_other_band != d_src_band )
5823  {
5824  bFoundDifferentValue = true;
5825  break;
5826  }
5827  }
5828  if ( bFoundDifferentValue == false )
5829  {
5830  d[d_dest_band_pixel_offset] = s[src_band][i];
5831  }
5832  }
5833  break;
5834 
5835  case NULL_RULE:
5836  default:
5837  {
5838  d[d_dest_band_pixel_offset] = s[src_band][i];
5839  }
5840  break;
5841  }
5842 
5843  ++i;
5844  }
5845 
5846  d_buf_offset += d_width;
5847  s[src_band] += s_width;
5848  }
5849 
5850  // Free up memory allocated for pointers.
5851  delete [] s;
5852  }
5853  else
5854  {
5855  ossim_uint32 d_width = dest_rect.lr().x - dest_rect.ul().x + 1;
5856  ossim_uint32 d_band_offset = d_width * (dest_rect.lr().y-dest_rect.ul().y+1);
5857 
5858  ossim_uint8* d = static_cast<ossim_uint8*>(dest);
5859 
5860  // Move to first valid pixel.
5861  d += (output_clip_rect.ul().y - dest_rect.ul().y) * d_width +
5862  (output_clip_rect.ul().x - dest_rect.ul().x);
5863 
5864  for (band=0; band<num_bands; ++band)
5865  {
5866  ossim_uint8 np = static_cast<ossim_uint8>(m_nullPixelValue[band]);
5867  ossim_uint32 d_buf_offset = 0;
5868 
5869  for (ossim_int32 line=output_clip_rect.ul().y;
5870  line<=output_clip_rect.lr().y; ++line)
5871  {
5872  ossim_int32 i=0;
5873  for (ossim_int32 samp=output_clip_rect.ul().x;
5874  samp<=output_clip_rect.lr().x; ++samp)
5875  {
5876  d[d_buf_offset+i] = np;
5877  ++i;
5878  }
5879 
5880  d_buf_offset += d_width;
5881  }
5882  d += d_band_offset;
5883  }
5884  }
5885 }
5886 
5888 {
5889  return new ossimImageData(*this);
5890 }
5891 
5893 {
5894  if (!buf)
5895  {
5897  << "ossimImageData::copyTileToNormalizedBuffer ERROR:"
5898  << "\nNull buffer passed to method! Returning..." << std::endl;
5899  return;
5900  }
5901 
5903  {
5905  << "ossimImageData::copyTileToNormalizedBuffer ERROR:"
5906  << "\nThis object is null! Returning..." << std::endl;
5907  return;
5908  }
5909 
5910  switch(getScalarType())
5911  {
5913  {
5914  memmove(buf, getBuf(), getDataSizeInBytes());
5915  break;
5916  }
5918  {
5919  ossim_uint32 upperBound = getWidth()*getHeight()*getNumberOfBands();
5920  const ossim_float32* inputBuf = static_cast<const ossim_float32*>(getBuf());
5921  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
5922  {
5923  buf[offset] = inputBuf[offset];
5924  }
5925  break;
5926  }
5927  case OSSIM_FLOAT32:
5928  {
5930  break;
5931  }
5932  case OSSIM_FLOAT64:
5933  {
5935  break;
5936  }
5937  case OSSIM_UINT8:
5938  {
5940  break;
5941 
5942  }
5943  case OSSIM_SINT8:
5944  {
5946  break;
5947 
5948  }
5949  case OSSIM_USHORT11:
5950  case OSSIM_USHORT12:
5951  case OSSIM_USHORT13:
5952  case OSSIM_USHORT14:
5953  case OSSIM_USHORT15:
5954  case OSSIM_UINT16:
5955  {
5957  break;
5958  }
5959  case OSSIM_SINT16:
5960  {
5962  break;
5963  }
5964  case OSSIM_UINT32:
5965  {
5967  break;
5968  }
5969  case OSSIM_SINT32:
5970  {
5972  break;
5973  }
5974  case OSSIM_SCALAR_UNKNOWN:
5975  default:
5976  {
5978  << "NOTICE: copyTileToNormalizedBuffer not implemented yet"
5979  << std::endl;
5980  }
5981 
5982  } // End of "switch(getScalarType())"
5983 }
5984 
5985 template <class T>
5987  ossim_float64* buf) const
5988 {
5989  const ossim_uint32 SIZE = getSizePerBand();
5990  const ossim_uint32 BANDS = getNumberOfBands();
5991 
5992  for(ossim_uint32 band = 0; band < BANDS; ++band)
5993  {
5994  const ossim_float64 MIN_PIX = getMinPix(band);
5995  const ossim_float64 MAX_PIX = getMaxPix(band);
5996  const ossim_float64 RANGE = (MAX_PIX-MIN_PIX);
5997  const ossim_float64 NP = getNullPix(band);
5998 
5999  const T* s = (T*)getBuf(band); // source
6000  ossim_float64* d = (ossim_float64*)(buf + (band*SIZE)); // destination
6001 
6002  for(ossim_uint32 offset = 0; offset < SIZE; ++offset)
6003  {
6004  ossim_float64 p = s[offset];
6005  if(p != NP)
6006  {
6007  if( p == MIN_PIX)
6008  {
6010  }
6011  else
6012  {
6013  d[offset] = (p-MIN_PIX)/RANGE;
6014  }
6015  }
6016  else
6017  {
6018  d[offset] = 0.0;
6019  }
6020  }
6021  }
6022 }
6023 
6024 template <class T>
6026  ossim_float32* buf) const
6027 {
6028  const ossim_uint32 SIZE = getSizePerBand();
6029  const ossim_uint32 BANDS = getNumberOfBands();
6030 
6031  for(ossim_uint32 band = 0; band < BANDS; ++band)
6032  {
6033  const ossim_float64 MIN_PIX = getMinPix(band);
6034  const ossim_float64 MAX_PIX = getMaxPix(band);
6035  const ossim_float64 RANGE = (MAX_PIX-MIN_PIX);
6036  const ossim_float64 NP = getNullPix(band);
6037 
6038  const T* s = (T*)getBuf(band); // source
6039  ossim_float32* d = (ossim_float32*)(buf + (band*SIZE)); // destination
6040 
6041  for(ossim_uint32 offset = 0; offset < SIZE; ++offset)
6042  {
6043  ossim_float64 p = s[offset];
6044  if(p != NP)
6045  {
6046  if( p == MIN_PIX)
6047  {
6049  }
6050  else
6051  {
6052  d[offset] = (p-MIN_PIX)/RANGE;
6053  }
6054  }
6055  else
6056  {
6057  d[offset] = 0.0;
6058  }
6059  }
6060  }
6061 }
6062 
6063 template <class T>
6065  ossim_uint32 band,
6066  ossim_float64* buf) const
6067 {
6068  const ossim_uint32 SIZE = getSizePerBand();
6069  const ossim_float64 MIN_PIX = getMinPix(band);
6070  const ossim_float64 MAX_PIX = getMaxPix(band);
6071  const ossim_float64 RANGE = (MAX_PIX-MIN_PIX);
6072  const ossim_float64 NP = getNullPix(band);
6073 
6074  const T* s = (T*)getBuf(band); // source
6075  ossim_float64* d = (ossim_float64*)(buf); // destination
6076 
6077  for(ossim_uint32 offset = 0; offset < SIZE; ++offset)
6078  {
6079  ossim_float64 p = s[offset];
6080  if(p != NP)
6081  {
6082  if( p == MIN_PIX)
6083  {
6085  }
6086  else
6087  {
6088  d[offset] = (p-MIN_PIX)/RANGE;
6089  }
6090  }
6091  else
6092  {
6093  d[offset] = 0.0;
6094  }
6095  }
6096 }
6097 
6098 template <class T>
6100  ossim_uint32 band,
6101  ossim_float32* buf) const
6102 {
6103  const ossim_uint32 SIZE = getSizePerBand();
6104  const ossim_float64 MIN_PIX = getMinPix(band);
6105  const ossim_float64 MAX_PIX = getMaxPix(band);
6106  const ossim_float64 RANGE = (MAX_PIX-MIN_PIX);
6107  const ossim_float64 NP = getNullPix(band);
6108 
6109  const T* s = (T*)getBuf(band); // source
6110  ossim_float32* d = (ossim_float32*)(buf); // destination
6111 
6112  for(ossim_uint32 offset = 0; offset < SIZE; ++offset)
6113  {
6114  ossim_float64 p = s[offset];
6115  if(p != NP)
6116  {
6117  if( p == MIN_PIX)
6118  {
6120  }
6121  else
6122  {
6123  d[offset] = (p-MIN_PIX)/RANGE;
6124  }
6125  }
6126  else
6127  {
6128  d[offset] = 0.0;
6129  }
6130  }
6131 }
6132 
6133 template <class T>
6135  ossim_float64* buf)
6136 {
6137  const ossim_uint32 SIZE = getSizePerBand();
6138  const ossim_uint32 BANDS = getNumberOfBands();
6139 
6140  for(ossim_uint32 band = 0; band < BANDS; ++band)
6141  {
6142  const ossim_float64 MIN_PIX = getMinPix(band);
6143  const ossim_float64 MAX_PIX = getMaxPix(band);
6144  const ossim_float64 RANGE = (MAX_PIX-MIN_PIX);
6145  const T NP = (T)getNullPix(band);
6146 
6147  ossim_float64* s = buf + (band*SIZE); // source
6148  T* d = (T*)getBuf(band); // destination
6149 
6150  for(ossim_uint32 offset = 0; offset < SIZE; ++offset)
6151  {
6152  const ossim_float64 P = s[offset];
6153  if(P != 0.0)
6154  {
6155  d[offset] = (T)(MIN_PIX + RANGE*P);
6156  }
6157  else
6158  {
6159  d[offset] = NP;
6160  }
6161  }
6162  }
6163 }
6164 
6165 template <class T>
6167  ossim_float32* buf)
6168 {
6169  const ossim_uint32 SIZE = getSizePerBand();
6170  const ossim_uint32 BANDS = getNumberOfBands();
6171 
6172  for(ossim_uint32 band = 0; band < BANDS; ++band)
6173  {
6174  const ossim_float64 MIN_PIX = getMinPix(band);
6175  const ossim_float64 MAX_PIX = getMaxPix(band);
6176  const ossim_float64 RANGE = (MAX_PIX-MIN_PIX);
6177  const T NP = (T)getNullPix(band);
6178 
6179  ossim_float32* s = buf + (band*SIZE); // source
6180  T* d = (T*)getBuf(band); // destination
6181 
6182  for(ossim_uint32 offset = 0; offset < SIZE; ++offset)
6183  {
6184  const ossim_float64 P = s[offset];
6185  if(P != 0.0)
6186  {
6187  ossim_float64 test = MIN_PIX + RANGE*P;
6188  if(test > MAX_PIX) test = MAX_PIX;
6189  d[offset] = (T)test;
6190  }
6191  else
6192  {
6193  d[offset] = NP;
6194  }
6195  }
6196  }
6197 }
6198 
6199 template <class T>
6201  ossim_uint32 band,
6202  ossim_float64* buf)
6203 {
6204  const ossim_uint32 SIZE = getSizePerBand();
6205  const ossim_float64 MIN_PIX = getMinPix(band);
6206  const ossim_float64 MAX_PIX = getMaxPix(band);
6207  const ossim_float64 RANGE = (MAX_PIX-MIN_PIX);
6208  const T NP = (T)getNullPix(band);
6209 
6210  ossim_float64* s = buf; // source
6211  T* d = (T*)getBuf(band); // destination
6212 
6213  for(ossim_uint32 offset = 0; offset < SIZE; ++offset)
6214  {
6215  const ossim_float64 P = s[offset];
6216  if(P != 0.0)
6217  {
6218  ossim_float64 test = MIN_PIX + RANGE*P;
6219  if(test > MAX_PIX) test = MAX_PIX;
6220  d[offset] = (T)test;
6221  }
6222  else
6223  {
6224  d[offset] = NP;
6225  }
6226  }
6227 }
6228 
6229 template <class T>
6231  ossim_uint32 band,
6232  ossim_float32* buf)
6233 {
6234  const ossim_uint32 SIZE = getSizePerBand();
6235  const ossim_float64 MIN_PIX = getMinPix(band);
6236  const ossim_float64 MAX_PIX = getMaxPix(band);
6237  const ossim_float64 RANGE = (MAX_PIX-MIN_PIX);
6238  const T NP = (T)getNullPix(band);
6239 
6240  ossim_float32* s = buf; // source
6241  T* d = (T*)getBuf(band); // destination
6242 
6243  for(ossim_uint32 offset = 0; offset < SIZE; ++offset)
6244  {
6245  const ossim_float64 P = s[offset];
6246  if(P != 0.0)
6247  {
6248  ossim_float64 test = MIN_PIX + RANGE*P;
6249  if(test > MAX_PIX) test = MAX_PIX;
6250  d[offset] = (T)test;
6251  }
6252  else
6253  {
6254  d[offset] = NP;
6255  }
6256  }
6257 }
6258 
6260  ossim_float64* buf) const
6261 {
6262  if (!buf)
6263  {
6265  << "ossimImageData::copyTileBandToNormalizedBuffer ERROR:"
6266  << "\nNull buffer passed to method! Returning..." << std::endl;
6267  return;
6268  }
6269 
6271  {
6273  << "ossimImageData::copyTileBandToNormalizedBuffer ERROR:"
6274  << "\nThis object is null! Returning..." << std::endl;
6275  return;
6276  }
6277 
6278  if(!getBuf(band)) return;
6279 
6280  switch(getScalarType())
6281  {
6283  {
6284  memmove(buf, getBuf(band), getDataSizeInBytes());
6285  break;
6286  }
6288  {
6289  ossim_uint32 upperBound = getWidth()*getHeight();
6290  const ossim_float32* inputBuf = static_cast<const ossim_float32*>(getBuf(band));
6291  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
6292  {
6293  buf[offset] = inputBuf[offset];
6294  }
6295  break;
6296  }
6297  case OSSIM_FLOAT32:
6298  {
6300  break;
6301  }
6302  case OSSIM_FLOAT64:
6303  {
6305  break;
6306  }
6307  case OSSIM_UINT8:
6308  {
6309  copyTileToNormalizedBuffer((ossim_uint8)0, band, buf);
6310  break;
6311 
6312  }
6313  case OSSIM_SINT8:
6314  {
6315  copyTileToNormalizedBuffer((ossim_sint8)0, band, buf);
6316  break;
6317 
6318  }
6319  case OSSIM_USHORT11:
6320  case OSSIM_USHORT12:
6321  case OSSIM_USHORT13:
6322  case OSSIM_USHORT14:
6323  case OSSIM_USHORT15:
6324  case OSSIM_UINT16:
6325  {
6327  break;
6328  }
6329  case OSSIM_SINT16:
6330  {
6332  break;
6333  }
6334  case OSSIM_UINT32:
6335  {
6337  break;
6338  }
6339  case OSSIM_SINT32:
6340  {
6342  break;
6343  }
6344  case OSSIM_SCALAR_UNKNOWN:
6345  default:
6346  {
6348  << "ossimImageData::copyTileBandToNormalizedBuffer ERROR:"
6349  << " Unknown scalar type!"
6350  << std::endl;
6351  }
6352 
6353  } // End of "switch(getScalarType())"
6354 
6355 }
6356 
6358 {
6359 
6360  if (!buf)
6361  {
6363  << "ossimImageData::copyTileToNormalizedBuffer ERROR:"
6364  << "\nNull buffer passed to method! Returning..." << std::endl;
6365  return;
6366  }
6367 
6369  {
6371  << "ossimImageData::copyTileToNormalizedBuffer ERROR:"
6372  << "\nThis object is null! Returning..." << std::endl;
6373  return;
6374  }
6375 
6376  switch(getScalarType())
6377  {
6379  {
6380  ossim_uint32 upperBound = getWidth()*getHeight()*getNumberOfBands();
6381  const ossim_float32* inputBuf = static_cast<const ossim_float32*>(getBuf());
6382  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
6383  {
6384  buf[offset] = inputBuf[offset];
6385  }
6386  break;
6387  }
6389  {
6390  memmove(buf, getBuf(), getDataSizeInBytes());
6391  break;
6392  }
6393  case OSSIM_FLOAT32:
6394  {
6396  break;
6397  }
6398  case OSSIM_FLOAT64:
6399  {
6401  break;
6402  }
6403  case OSSIM_UINT8:
6404  {
6406  break;
6407 
6408  }
6409  case OSSIM_SINT8:
6410  {
6412  break;
6413 
6414  }
6415  case OSSIM_USHORT11:
6416  case OSSIM_USHORT12:
6417  case OSSIM_USHORT13:
6418  case OSSIM_USHORT14:
6419  case OSSIM_USHORT15:
6420  case OSSIM_UINT16:
6421  {
6423  break;
6424  }
6425  case OSSIM_SINT16:
6426  {
6428  break;
6429  }
6430  case OSSIM_UINT32:
6431  {
6433  break;
6434  }
6435  case OSSIM_SINT32:
6436  {
6438  break;
6439  }
6440  case OSSIM_SCALAR_UNKNOWN:
6441  default:
6442  {
6444  << "NOTICE: copyTileToNormalizedBuffer not implemented yet"
6445  << std::endl;
6446  }
6447 
6448  } // End of "switch(getScalarType())"
6449 }
6450 
6452  ossim_float32* buf)const
6453 {
6454  if (!buf)
6455  {
6457  << "ossimImageData::copyTileBandToNormalizedBuffer ERROR:"
6458  << "\nNull buffer passed to method! Returning..." << std::endl;
6459  return;
6460  }
6461 
6463  {
6465  << "ossimImageData::copyTileBandToNormalizedBuffer ERROR:"
6466  << "\nThis object is null! Returning..." << std::endl;
6467  return;
6468  }
6469 
6470  switch(getScalarType())
6471  {
6473  {
6474  ossim_uint32 upperBound = getWidth()*getHeight();
6475  const ossim_float32* inputBuf = static_cast<const ossim_float32*>(getBuf(band));
6476  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
6477  {
6478  buf[offset] = inputBuf[offset];
6479  }
6480  break;
6481  }
6483  {
6484  memmove(buf, getBuf(band), getSizePerBandInBytes());
6485  break;
6486  }
6487  case OSSIM_FLOAT32:
6488  {
6490  break;
6491  }
6492  case OSSIM_FLOAT64:
6493  {
6495  break;
6496  }
6497  case OSSIM_UINT8:
6498  {
6499  copyTileToNormalizedBuffer((ossim_uint8)0, band, buf);
6500  break;
6501 
6502  }
6503  case OSSIM_SINT8:
6504  {
6505  copyTileToNormalizedBuffer((ossim_sint8)0, band, buf);
6506  break;
6507 
6508  }
6509  case OSSIM_USHORT11:
6510  case OSSIM_USHORT12:
6511  case OSSIM_USHORT13:
6512  case OSSIM_USHORT14:
6513  case OSSIM_USHORT15:
6514  case OSSIM_UINT16:
6515  {
6517  break;
6518  }
6519  case OSSIM_SINT16:
6520  {
6522  break;
6523  }
6524  case OSSIM_UINT32:
6525  {
6527  break;
6528  }
6529  case OSSIM_SINT32:
6530  {
6532  break;
6533  }
6534  case OSSIM_SCALAR_UNKNOWN:
6535  default:
6536  {
6538  << "ossimImageData::copyTileBandToNormalizedBuffer ERROR:"
6539  << " Unknown scalar type"
6540  << std::endl;
6541  }
6542 
6543  } // End of "switch(getScalarType())"
6544 }
6545 
6546 
6548 {
6549  if (!buf)
6550  {
6552  << "ossimImageData::copyNormalizedBufferToTile ERROR:"
6553  << "\nNull buffer passed to method! Returning..." << std::endl;
6554  return;
6555  }
6556 
6558  {
6560  << "ossimImageData::copyNormalizedBufferToTile ERROR:"
6561  << "\nThis object is null! Returning..." << std::endl;
6562  return;
6563  }
6564 
6565  switch(getScalarType())
6566  {
6568  {
6569  memmove(getBuf(), buf, getDataSizeInBytes());
6570  break;
6571  }
6573  {
6574  ossim_uint32 upperBound = getWidth()*getHeight()*getNumberOfBands();
6575  ossim_float32* inputBuf = static_cast<ossim_float32*>(getBuf());
6576  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
6577  {
6578  inputBuf[offset] = static_cast<ossim_float32>(buf[offset]);
6579  }
6580  break;
6581  }
6582  case OSSIM_FLOAT32:
6583  {
6585  break;
6586  }
6587  case OSSIM_FLOAT64:
6588  {
6590  break;
6591  }
6592  case OSSIM_UINT8:
6593  {
6595  break;
6596 
6597  }
6598  case OSSIM_SINT8:
6599  {
6601  break;
6602 
6603  }
6604  case OSSIM_USHORT11:
6605  case OSSIM_USHORT12:
6606  case OSSIM_USHORT13:
6607  case OSSIM_USHORT14:
6608  case OSSIM_USHORT15:
6609  case OSSIM_UINT16:
6610  {
6612  break;
6613  }
6614  case OSSIM_SINT16:
6615  {
6617  break;
6618  }
6619  case OSSIM_UINT32:
6620  {
6622  break;
6623  }
6624  case OSSIM_SINT32:
6625  {
6627  break;
6628  }
6629  case OSSIM_SCALAR_UNKNOWN:
6630  default:
6631  {
6633  << "ossimImageData::copyNormalizedBufferToTile\n"
6634  << "Unknown scalar type!" << std::endl;
6635  }
6636 
6637  } // End of "switch(getScalarType())".
6638 }
6639 
6641  ossim_float64* buf)
6642 {
6643  if (!buf)
6644  {
6646  << "ossimImageData::copyNormalizedBufferToTile ERROR:"
6647  << "\nNull buffer passed to method! Returning..." << std::endl;
6648  return;
6649  }
6650 
6652  {
6654  << "ossimImageData::copyNormalizedBufferToTile ERROR:"
6655  << "\nThis object is null! Returning..." << std::endl;
6656  return;
6657  }
6658 
6659  if(band < getNumberOfBands())
6660  {
6661  switch(getScalarType())
6662  {
6664  {
6665  memmove(getBuf(band), buf, getSizePerBandInBytes());
6666  break;
6667  }
6669  {
6670  ossim_uint32 upperBound = getWidth()*getHeight();
6671  ossim_float32* inputBuf = static_cast<ossim_float32*>(getBuf(band));
6672  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
6673  {
6674  inputBuf[offset] = static_cast<ossim_float32>(buf[offset]);
6675  }
6676  break;
6677  }
6678  case OSSIM_FLOAT32:
6679  {
6681  break;
6682  }
6683  case OSSIM_FLOAT64:
6684  {
6686  break;
6687  }
6688  case OSSIM_UINT8:
6689  {
6690  copyNormalizedBufferToTile((ossim_uint8)0, band, buf);
6691  break;
6692 
6693  }
6694  case OSSIM_SINT8:
6695  {
6696  copyNormalizedBufferToTile((ossim_sint8)0, band, buf);
6697  break;
6698 
6699  }
6700  case OSSIM_USHORT11:
6701  case OSSIM_USHORT12:
6702  case OSSIM_USHORT13:
6703  case OSSIM_USHORT14:
6704  case OSSIM_USHORT15:
6705  case OSSIM_UINT16:
6706  {
6708  break;
6709  }
6710  case OSSIM_SINT16:
6711  {
6713  break;
6714  }
6715  case OSSIM_UINT32:
6716  {
6718  break;
6719  }
6720  case OSSIM_SINT32:
6721  {
6723  break;
6724  }
6725  case OSSIM_SCALAR_UNKNOWN:
6726  default:
6727  {
6729  << "ossimImageData::copyNormalizedBufferToTile\n"
6730  << "Unknown scalar type." << std::endl;
6731  }
6732 
6733  } // End of "switch(getScalarType())".
6734  }
6735 }
6736 
6738 {
6739  if (!buf)
6740  {
6742  << "ossimImageData::copyNormalizedBufferToTile ERROR:"
6743  << "\nNull buffer passed to method! Returning..." << std::endl;
6744  return;
6745  }
6746 
6748  {
6750  << "ossimImageData::copyNormalizedBufferToTile ERROR:"
6751  << "\nThis object is null! Returning..." << std::endl;
6752  return;
6753  }
6754 
6755  switch(getScalarType())
6756  {
6758  {
6759  ossim_uint32 upperBound = getWidth()*getHeight()*getNumberOfBands();
6760  ossim_float64* inputBuf = static_cast<ossim_float64*>(getBuf());
6761  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
6762  {
6763  inputBuf[offset] = buf[offset];
6764  }
6765  break;
6766  }
6768  {
6769  memmove(getBuf(), buf, getDataSizeInBytes());
6770  break;
6771  }
6772  case OSSIM_FLOAT32:
6773  {
6775  break;
6776  }
6777  case OSSIM_FLOAT64:
6778  {
6780  break;
6781  }
6782  case OSSIM_UINT8:
6783  {
6785  break;
6786 
6787  }
6788  case OSSIM_SINT8:
6789  {
6791  break;
6792 
6793  }
6794  case OSSIM_USHORT11:
6795  case OSSIM_USHORT12:
6796  case OSSIM_USHORT13:
6797  case OSSIM_USHORT14:
6798  case OSSIM_USHORT15:
6799  case OSSIM_UINT16:
6800  {
6802  break;
6803  }
6804  case OSSIM_SINT16:
6805  {
6807  break;
6808  }
6809  case OSSIM_UINT32:
6810  {
6812  break;
6813  }
6814  case OSSIM_SINT32:
6815  {
6817  break;
6818  }
6819  case OSSIM_SCALAR_UNKNOWN:
6820  default:
6821  {
6823  << "ossimImageDatacopyNormalizedBufferToTile\n"
6824  << "Unknown scalar type!" << std::endl;
6825  }
6826 
6827  } // End of "switch(getScalarType())".
6828 }
6829 
6831  ossim_float32* buf)
6832 {
6833  if (!buf)
6834  {
6836  << "ossimImageData::copyNormalizedBufferToTile ERROR:"
6837  << "\nNull buffer passed to method! Returning..." << std::endl;
6838  return;
6839  }
6840 
6842  {
6844  << "ossimImageData::copyNormalizedBufferToTile ERROR:"
6845  << "\nThis object is null! Returning..." << std::endl;
6846  return;
6847  }
6848 
6849  switch(getScalarType())
6850  {
6852  {
6853  ossim_uint32 upperBound = getWidth()*getHeight();
6854  ossim_float64* inputBuf = static_cast<ossim_float64*>(getBuf(band));
6855  for(ossim_uint32 offset = 0; offset < upperBound; ++offset)
6856  {
6857  inputBuf[offset] = buf[offset];
6858  }
6859  break;
6860  }
6862  {
6863  memmove(getBuf(band), buf, getSizePerBandInBytes());
6864  break;
6865  }
6866  case OSSIM_FLOAT32:
6867  {
6869  break;
6870  }
6871  case OSSIM_FLOAT64:
6872  {
6874  break;
6875  }
6876  case OSSIM_UINT8:
6877  {
6878  copyNormalizedBufferToTile((ossim_uint8)0, band, buf);
6879  break;
6880 
6881  }
6882  case OSSIM_SINT8:
6883  {
6884  copyNormalizedBufferToTile((ossim_sint8)0, band, buf);
6885  break;
6886 
6887  }
6888  case OSSIM_USHORT11:
6889  case OSSIM_USHORT12:
6890  case OSSIM_USHORT13:
6891  case OSSIM_USHORT14:
6892  case OSSIM_USHORT15:
6893  case OSSIM_UINT16:
6894  {
6896  break;
6897  }
6898  case OSSIM_SINT16:
6899  {
6901  break;
6902  }
6903  case OSSIM_UINT32:
6904  {
6906  break;
6907  }
6908  case OSSIM_SINT32:
6909  {
6911  break;
6912  }
6913  case OSSIM_SCALAR_UNKNOWN:
6914  default:
6915  {
6917  << "ossimImageData::copyNormalizedBufferToTile\n"
6918  << "Unknown scalar type!" << std::endl;
6919  }
6920 
6921  } // End of "switch(getScalarType())".
6922 }
6923 
6925 {
6928  {
6929  return m_minPixelValue[0]; // Already normalized.
6930  }
6931  return (1.0 / (m_maxPixelValue[0] - m_minPixelValue[0] + 1.0));
6932 }
6933 
6935 {
6936  out << getClassName() << "::print:"
6937  << "\nm_origin: " << m_origin << "\n";
6938  if(m_nullPixelValue.size())
6939  {
6940  out << "Null values: ";
6941 
6942  copy(m_nullPixelValue.begin(),
6943  m_nullPixelValue.begin() + getNumberOfBands(),
6944  std::ostream_iterator<ossim_float64>(out, " "));
6945  out << "\n";
6946  }
6947  if(m_minPixelValue.size())
6948  {
6949  out << "Min values: ";
6950 
6951  copy(m_minPixelValue.begin(),
6952  m_minPixelValue.begin() + getNumberOfBands(),
6953  std::ostream_iterator<ossim_float64>(out, " "));
6954  out << "\n";
6955  }
6956  if(m_maxPixelValue.size())
6957  {
6958  out << "Max values: ";
6959 
6960  copy(m_maxPixelValue.begin(),
6961  m_maxPixelValue.begin() + getNumberOfBands(),
6962  std::ostream_iterator<ossim_float64>(out, " "));
6963  out << "\n";
6964  }
6965  out << "width: " << getWidth()
6966  << "\nheight: " << getHeight()
6967  << "\nimage rectangle: " << getImageRectangle()
6968  << "\nindexed: " << m_indexedFlag
6969  << "\nalpha size: " << m_alpha.size()
6970  << std::endl;
6971 
6973 }
6974 
6976 {
6977  if ( (getDataObjectStatus() != OSSIM_NULL) &&
6979  {
6980  switch (getScalarType())
6981  {
6982  case OSSIM_UINT8:
6983  {
6985  return;
6986  }
6987  case OSSIM_SINT8:
6988  {
6990  return;
6991  }
6992  case OSSIM_UINT16:
6993  case OSSIM_USHORT11:
6994  case OSSIM_USHORT12:
6995  case OSSIM_USHORT13:
6996  case OSSIM_USHORT14:
6997  case OSSIM_USHORT15:
6998  {
7000  return;
7001  }
7002  case OSSIM_SINT16:
7003  {
7005  return;
7006  }
7007  case OSSIM_UINT32:
7008  {
7010  return;
7011  }
7012  case OSSIM_SINT32:
7013  {
7015  return;
7016  }
7017  case OSSIM_FLOAT32:
7019  {
7021  return;
7022  }
7024  case OSSIM_FLOAT64:
7025  {
7027  return;
7028  }
7029  case OSSIM_SCALAR_UNKNOWN:
7030  default:
7031  {
7035  "ossimImageData::stretchMinMax File %s line %d\n\
7036 Invalid scalar type: %d",
7037 __FILE__,
7038 __LINE__,
7039 getScalarType());
7040  break;
7041  }
7042  }
7043  }
7044 }
7045 
7046 template <class T> void ossimImageData::stretchMinMax(T /* dummyTemplate */)
7047 {
7048  const ossim_uint32 BANDS = getNumberOfBands();
7049  const ossim_uint32 SPB = getSizePerBand();
7050 
7051  // scalar min
7053 
7054  // scalar max
7056 
7057  // scalar null
7059 
7060  // scalar range
7061  const ossim_float64 S_RNG = S_MAX-S_MIN+1.0;
7062 
7063  for(ossim_uint32 band = 0; band < BANDS; ++band)
7064  {
7065  T* s = static_cast<T*>(getBuf(band));
7066 
7067  if (s)
7068  {
7069  const ossim_float64 T_NUL = m_nullPixelValue[band]; // tile null
7070  const ossim_float64 T_MIN = m_minPixelValue[band]; // tile min
7071  const ossim_float64 T_MAX = m_maxPixelValue[band]; // tile max
7072  const ossim_float64 T_RNG = (T_MAX-T_MIN)+1; // tile range
7073  const ossim_float64 SPP = S_RNG / T_RNG; // stretch per pixel
7074 
7075  for(ossim_uint32 i = 0; i < SPB; ++i)
7076  {
7077  ossim_float64 p = s[i];
7078  if ( p == T_NUL )
7079  {
7080  p = S_NUL;
7081  }
7082  else if (p <= T_MIN)
7083  {
7084  p = S_MIN;
7085  }
7086  else if (p >= T_MAX)
7087  {
7088  p = S_MAX;
7089  }
7090  else
7091  {
7092  // Stretch...
7093  p = (p - T_MIN + 1.0) * SPP + S_MIN - 1.0;
7094  }
7095  s[i] = ossim::round<T>(p);
7096  }
7097 
7098  // Set the min, max, null:
7099  m_minPixelValue[band] = S_MIN;
7100  m_maxPixelValue[band] = S_MAX;
7101  m_nullPixelValue[band] = S_NUL;
7102 
7103  }
7104  }
7105 }
7106 
7108 {
7109  if ( getDataObjectStatus() != OSSIM_NULL )
7110  {
7111  switch (getScalarType())
7112  {
7113  case OSSIM_UINT8:
7114  {
7116  return;
7117  }
7118  case OSSIM_SINT8:
7119  {
7121  return;
7122  }
7123  case OSSIM_UINT16:
7124  case OSSIM_USHORT11:
7125  case OSSIM_USHORT12:
7126  case OSSIM_USHORT13:
7127  case OSSIM_USHORT14:
7128  case OSSIM_USHORT15:
7129  {
7131  return;
7132  }
7133  case OSSIM_SINT16:
7134  {
7136  return;
7137  }
7138  case OSSIM_UINT32:
7139  {
7141  return;
7142  }
7143  case OSSIM_SINT32:
7144  {
7146  return;
7147  }
7148  case OSSIM_FLOAT32:
7150  {
7152  return;
7153  }
7155  case OSSIM_FLOAT64:
7156  {
7158  return;
7159  }
7160  case OSSIM_SCALAR_UNKNOWN:
7161  default:
7162  {
7166  "ossimImageData::computeAlphaChannel File %s line %d\n\
7167 Invalid scalar type: %d",
7168 __FILE__,
7169 __LINE__,
7170 getScalarType());
7171  break;
7172  }
7173  }
7174  }
7175 }
7176 
7177 template <class T> void ossimImageData::computeAlphaChannel(T /* dummyTemplate */)
7178 {
7179  const ossim_uint32 SPB = getSizePerBand();
7180  const ossim_uint8 ANP = 0; // Alpha Null Pixel
7181  const ossim_uint8 AVP = 255; // Alpha Valid Pixel
7182 
7183  // Allocate the alpha channel if not already.
7184  if (m_alpha.size() != SPB)
7185  {
7186  m_alpha.resize(SPB);
7187  }
7188 
7190  {
7191  memset( static_cast<void*>(&m_alpha.front()),
7192  static_cast<int>(AVP),
7193  static_cast<int>(SPB) );
7194  }
7195  else if (getDataObjectStatus() == OSSIM_EMPTY)
7196  {
7197  // Start with alpha being set to 0.
7198  memset( static_cast<void*>(&m_alpha.front()),
7199  static_cast<int>(ANP),
7200  static_cast<int>(SPB) );
7201  }
7202  else // Partial must check each pixel.
7203  {
7204  const ossim_uint32 BANDS = getNumberOfBands();
7205 
7206  std::vector<T> null_pix(BANDS);
7207  std::vector<const T*> buf(BANDS); // Pointer to pixel data.
7208  ossim_uint32 band;
7209  for(band = 0; band < BANDS; ++band)
7210  {
7211  buf[band] = static_cast<const T*>(getBuf(band));
7212  null_pix[band] = static_cast<T>(m_nullPixelValue[band]);
7213  }
7214 
7215  for(ossim_uint32 i = 0; i < SPB; ++i)
7216  {
7217  //---
7218  // Start with alpha being set to 0. If any band has a valid pixel set
7219  // to 255 and break from band loop.
7220  //---
7221  m_alpha[i] = ANP;
7222  for(band = 0; band < BANDS; ++band)
7223  {
7224  if (buf[band][i] != null_pix[band])
7225  {
7226  m_alpha[i] = AVP;
7227  break;
7228  }
7229  }
7230  }
7231  }
7232 
7233 } // End: template <class T> void ossimImageData::computeAlphaChannel
7234 
7236 {
7237  return m_spatialExtents[0];
7238 }
7239 
7241 {
7242  return m_spatialExtents[1];
7243 }
7244 
7246 {
7247  w = m_spatialExtents[0];
7248  h = m_spatialExtents[1];
7249 }
7250 
7252 {
7253  m_spatialExtents[0] = width;
7254 }
7255 
7257 {
7258  m_spatialExtents[1] = height;
7259 }
7260 
7262 {
7263  m_spatialExtents[0] = w;
7264  m_spatialExtents[1] = h;
7265 }
7266 
7268 {
7269  m_origin = origin;
7270 }
7271 
7273 {
7274  return getSizeInBytes();
7275 }
7276 
7277 void ossimImageData::copyLine(const void* src,
7278  ossim_int32 lineNumber,
7279  ossim_int32 lineStartSample,
7280  ossim_int32 lineStopSample,
7281  ossimInterleaveType lineInterleave)
7282 {
7283  switch(m_scalarType)
7284  {
7285  case OSSIM_UINT8:
7286  {
7287  copyLineTemplate((ossim_uint8)0, src, lineNumber, lineStartSample,
7288  lineStopSample, lineInterleave);
7289  break;
7290  }
7291  case OSSIM_SINT8:
7292  {
7293  copyLineTemplate((ossim_sint8)0, src, lineNumber, lineStartSample,
7294  lineStopSample, lineInterleave);
7295  break;
7296 
7297  }
7298  case OSSIM_USHORT11:
7299  case OSSIM_USHORT12:
7300  case OSSIM_USHORT13:
7301  case OSSIM_USHORT14:
7302  case OSSIM_USHORT15:
7303  case OSSIM_UINT16:
7304  {
7305  copyLineTemplate((ossim_uint16)0, src, lineNumber, lineStartSample,
7306  lineStopSample, lineInterleave);
7307  break;
7308  }
7309  case OSSIM_SINT16:
7310  {
7311  copyLineTemplate((ossim_sint16)0, src, lineNumber, lineStartSample,
7312  lineStopSample, lineInterleave);
7313  break;
7314  }
7315  case OSSIM_UINT32:
7316  {
7317  copyLineTemplate((ossim_uint32)0, src, lineNumber, lineStartSample,
7318  lineStopSample, lineInterleave);
7319  break;
7320  }
7321  case OSSIM_SINT32:
7322  {
7323  copyLineTemplate((ossim_sint32)0, src, lineNumber, lineStartSample,
7324  lineStopSample, lineInterleave);
7325  break;
7326  }
7328  case OSSIM_FLOAT32:
7329  {
7330  copyLineTemplate((ossim_float32)0.0, src, lineNumber, lineStartSample,
7331  lineStopSample, lineInterleave);
7332  break;
7333  }
7335  case OSSIM_FLOAT64:
7336  {
7337  copyLineTemplate((ossim_float64)0.0, src, lineNumber, lineStartSample,
7338  lineStopSample, lineInterleave);
7339  break;
7340  }
7341  case OSSIM_SCALAR_UNKNOWN:
7342  default:
7343  {
7344  // Shouldn't hit this.
7346  << "ossimImageData::copyLine Unsupported scalar type!"
7347  << std::endl;
7348  break;
7349  }
7350  }
7351 
7352 } // End: void ossimImageData::copyLine
7353 
7354 template <class T>
7355 void ossimImageData::copyLineTemplate(T /* dummyTemplate */,
7356  const void* src,
7357  ossim_int32 lineNumber,
7358  ossim_int32 lineStartSample,
7359  ossim_int32 lineStopSample,
7360  ossimInterleaveType lineInterleave)
7361 {
7362  if (src)
7363  {
7364  const ossimIrect RECT = getImageRectangle();
7365 
7366  // Check for intersect:
7367  if ( ( lineNumber >= RECT.ul().y) &&
7368  ( lineNumber <= RECT.lr().y) &&
7369  ( lineStartSample < lineStopSample) &&
7370  ( lineStartSample <= RECT.lr().x) &&
7371  ( lineStopSample >= RECT.ul().x) )
7372  {
7373  const ossim_int32 BANDS = static_cast<ossim_int32>(m_numberOfDataComponents);
7374  const ossim_int32 START_SAMP =
7375  (lineStartSample > RECT.ul().x)?lineStartSample:RECT.ul().x;
7376  const ossim_int32 STOP_SAMP =
7377  (lineStopSample < RECT.lr().x)?lineStopSample:RECT.lr().x;
7378  const ossim_int32 SAMPS = STOP_SAMP - START_SAMP + 1;
7379 
7380  std::vector<T*> d(BANDS);
7381 
7382  ossim_int32 band;
7383  for (band = 0; band < BANDS; ++band)
7384  {
7385  d[band] = static_cast<T*>(getBuf(band));
7386 
7387  // Position at start sample.
7388  d[band] += (lineNumber - RECT.ul().y) * RECT.width() + (START_SAMP - RECT.ul().x);
7389  }
7390 
7391  if (lineInterleave == OSSIM_BIP)
7392  {
7393  const T* S = static_cast<const T*>(src); // Source buffer:
7394 
7395  // Position at start sample.
7396  S += (START_SAMP - lineStartSample) * BANDS;
7397 
7398  ossim_int32 srcOffset = 0;
7399  for (ossim_int32 samp = 0; samp < SAMPS; ++samp)
7400  {
7401  for (band = 0; band < BANDS; ++band)
7402  {
7403  d[band][samp] = S[srcOffset++];
7404  }
7405  }
7406  }
7407  else
7408  {
7409  const ossim_int32 W = lineStopSample - lineStartSample + 1;
7410  std::vector<const T*> S(BANDS);
7411  for (band = 0; band < BANDS; ++band)
7412  {
7413  S[band] = static_cast<const T*>(src) + (START_SAMP - lineStartSample);
7414  if (band)
7415  {
7416  S[band] += band * W; // Move to line.
7417  }
7418  }
7419 
7420  for (band = 0; band < BANDS; ++band)
7421  {
7422  for (ossim_int32 samp = 0; samp < SAMPS; ++samp)
7423  {
7424  d[band][samp] = S[band][samp];
7425  }
7426  }
7427  }
7428 
7429  } // intersect check
7430 
7431  } // if (src)
7432 
7433 } // End: template <class T> void ossimImageData::copyLineTemplate
7434 
7436 {
7437  m_indexedFlag = flag;
7438 }
7439 
7441 {
7442  return m_indexedFlag;
7443 }
7444 
7445 bool ossimImageData::saveState(ossimKeywordlist& kwl, const char* prefix)const
7446 {
7447  bool result = ossimRectilinearDataObject::saveState(kwl, prefix);
7448  ossimString null_pixels;
7449  ossimString min_pixels;
7450  ossimString max_pixels;
7454 
7455  kwl.add(prefix, "null_pixels", null_pixels, true);
7456  kwl.add(prefix, "min_pixels", min_pixels, true);
7457  kwl.add(prefix, "max_pixels", max_pixels, true);
7458 
7459  ossimString alpha;
7461  kwl.add(prefix, "alpha", alpha, true);
7462  kwl.add(prefix, "indexed", m_indexedFlag, true);
7463  kwl.add(prefix, "origin", m_origin.toString(), true);
7464  return result;
7465 
7466 }
7467 
7468 bool ossimImageData::loadState(const ossimKeywordlist& kwl, const char* prefix)
7469 {
7470  bool result = ossimRectilinearDataObject::loadState(kwl, prefix);
7471  m_spatialExtents.resize(2);
7472  if(result)
7473  {
7474  const char* null_pixels = kwl.find(prefix, "null_pixels");
7475  const char* min_pixels = kwl.find(prefix, "min_pixels");
7476  const char* max_pixels = kwl.find(prefix, "max_pixels");
7477  const char* alpha = kwl.find(prefix, "alpha");
7478  const char* origin = kwl.find(prefix, "origin");
7479  const char* indexed = kwl.find(prefix, "indexed");
7480  ossimString rectString = kwl.find(prefix, "rect");
7481  const char* numberOfBands = kwl.find(prefix, "number_bands");
7482  m_nullPixelValue.clear();
7483  m_minPixelValue.clear();
7484  m_maxPixelValue.clear();
7485  m_alpha.clear();
7486  if(null_pixels)
7487  {
7489  {
7490  return false;
7491  }
7492  }
7493  if(min_pixels)
7494  {
7496  {
7497  return false;
7498  }
7499  }
7500  if(max_pixels)
7501  {
7503  {
7504  return false;
7505  }
7506  }
7507  if(alpha)
7508  {
7510  {
7511  return false;
7512  }
7513  }
7514  if(origin)
7515  {
7516  m_origin.toPoint(origin);
7517  }
7518  m_indexedFlag = false;
7519  if(indexed)
7520  {
7521  m_indexedFlag = ossimString(indexed).toBool();
7522  }
7523  if(!rectString.empty())
7524  {
7525  ossimIrect rect;
7526 
7527  if(rect.toRect(rectString))
7528  {
7529  setImageRectangle(rect);
7530  }
7531  }
7532  if(numberOfBands)
7533  {
7534  ossim_uint32 nBands = ossimString(numberOfBands).toUInt32();
7535  setNumberOfDataComponents(nBands);
7536  if(m_nullPixelValue.empty()||
7537  m_minPixelValue.empty()||
7538  m_maxPixelValue.empty())
7539  {
7541  }
7542  }
7543  }
7544 
7545  return result;
7546 }
7547 
7549 {
7550  m_histogram = histo;
7551 }
7552 
7554 {
7555  return m_histogram;
7556 }
OSSIMDLLEXPORT void ossimSetError(const char *className, ossim_int32 error, const char *fmtString=0,...)
ossimString toString() const
Definition: ossimIpt.cpp:139
16 bit unsigned integer (15 bits used)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void loadBand(const void *src, const ossimIrect &src_rect, ossim_uint32 band)
8 bit signed integer
virtual ossim_uint32 getWidth() const
ossim_uint32 x
void fill(ossim_uint32 band, ossim_float64 value)
will fill the entire band with the value.
virtual void setValue(ossim_int32 x, ossim_int32 y, ossim_float64 color)
virtual const ossim_float64 * getMaxPix() const
ossimRefPtr< ossimMultiResLevelHistogram > getHistogram()
virtual ossimRefPtr< ossimImageData > newNormalizedFloat() const
Will take this tile and normalize it to a newly allocated floating point tile.
virtual void setNumberOfBands(ossim_uint32 bands, bool reallocate=false)
virtual void setOwner(ossimSource *aSource)
Sets the owner of this Data object.
virtual ossim_uint32 getNumberOfBands() const
64 bit floating point
virtual void computeAlphaChannel()
Computes the alpha channel.
virtual void setImageRectangle(const ossimIrect &rect)
virtual const ossim_uint16 * getUshortBuf() const
16 bit unsigned integer
virtual ossim_float64 getMinNormalizedPix() const
returns normalized minimum pixel value of band zero.
void loadTileFromBil(const void *src, const ossimIrect &src_rect)
virtual void populateHistogram(ossimRefPtr< ossimMultiBandHistogram > histo)
virtual const ossim_uint8 * getUcharBuf() const
virtual void setWidthHeight(ossim_uint32 w, ossim_uint32 h)
Represents serializable keyword/value map.
virtual void computeMinMaxPix(std::vector< ossim_float64 > &minBands, std::vector< ossim_float64 > &maxBands) const
If the minBands and maxBands are empty or not equal to the imageData&#39;s current number of bands it wil...
ossim_uint32 y
void unloadTileToBsq(void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
bool valid() const
Definition: ossimRefPtr.h:75
virtual void getNormalizedFloat(ossim_uint32 offset, ossim_uint32 bandNumber, ossim_float32 &result) const
will go to the band and offset and compute the normalized float and return it back to the caller thro...
virtual std::ostream & print(std::ostream &out) const
Generic print method.
const char * find(const char *key) const
std::vector< ossim_uint8 > m_alpha
Alpha channel.
float ossim_float32
virtual ossimString getEntryString(ossim_int32 entry_number) const
virtual void unloadBandToBsq(void *dest, ossim_uint32 src_band, ossim_uint32 dest_band, const ossimIrect &dest_rect, const ossimIrect &clip_rect, OverwriteBandRule ow_type=NULL_RULE) const
Called from public unloadBand() routines that have an OverwriteBandRule interface.
virtual ossimImageData * newNormalizedDouble() const
Will take this tile and normalize it to a newly allocated double point tile.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void copyTileBandToNormalizedBuffer(ossim_uint32 band, ossim_float64 *buf) const
Will copy this tiles specified band number to the normalized buffer.
virtual bool hasAlpha() const
ossim_uint32 height() const
Definition: ossimIrect.h:487
static ossimString toString(bool aValue)
Numeric to string methods.
#define STEP(bseg)
Definition: polygrf.h:238
OSSIM_DLL void defaultTileSize(ossimIpt &tileSize)
16 bit signed integer
void toSimpleStringList(ossimString &result, const std::vector< T > &valuesList)
This will output a vector of values inst a string.
Definition: ossimCommon.h:484
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual void getWidthHeight(ossim_uint32 &w, ossim_uint32 &h)
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
static const ossimErrorCode OSSIM_ERROR
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
signed char ossim_sint8
ossim_uint32 toUInt32() const
16 bit unsigned integer (13 bits used)
virtual void assign(const ossimRectilinearDataObject *data)
virtual ossim_float64 getPix(const ossimIpt &position, ossim_uint32 band=0) const
Will return the pixel at location position.
32 bit floating point
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
unsigned short ossim_uint16
virtual const ossim_sint16 * getSshortBuf() const
virtual void initializeNullDefault()
initializeNullDefault() Resizes theNullPixelValue array to number of bands and initializes to the def...
virtual ~ossimImageData()
virtual destructor
32 bit unsigned integer
void unloadTileToBip(void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
virtual void initialize()
Initialize the data buffer.
void unloadTileToBil(void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
virtual bool write(const ossimFilename &f) const
Writes tile to stream.
virtual ossimObject * dup() const
virtual void computeMinMaxNulPix(std::vector< ossim_float64 > &minBands, std::vector< ossim_float64 > &maxBands, std::vector< ossim_float64 > &nulBands) const
Scans tile for min, max, nulls.
virtual void assign(const ossimDataObject *data)
virtual ossim_uint32 getSizePerBandInBytes() const
Returns the number of bytes in single band of the tile.
bool toSimpleVector(std::vector< T > &result, const ossimString &stringOfPoints)
Definition: ossimCommon.h:537
void unloadBandTemplate(T, void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect, ossim_uint32 band) const
virtual void unloadBand(void *dest, ossim_uint32 src_band, ossim_uint32 dest_band, const ossimIrect &dest_rect, ossimInterleaveType il_type=OSSIM_BSQ, OverwriteBandRule ow_type=NULL_RULE) const
This routine is designed for overwriting a selected band of the destination buffer &#39;dest&#39; by an indep...
bool completely_within(const ossimIrect &rect) const
Definition: ossimIrect.cpp:425
bool isNull(ossim_uint32 offset) const
void unloadTileToBilTemplate(T, void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
double ossim_float64
virtual void assignBand(const ossimImageData *data, ossim_uint32 source_band, ossim_uint32 output_band)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
virtual void setHeight(ossim_uint32 height)
int GetRes() const
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
virtual void setNullPix(ossim_float64 null_pix)
OSSIM_DLL double defaultMin(ossimScalarType scalarType)
Definition: ossimCommon.cpp:73
std::vector< ossim_uint8 > m_dataBuffer
virtual void setNumberOfDataComponents(ossim_uint32 n)
How many components make up this data object.
ossimRefPtr< ossimMultiResLevelHistogram > m_histogram
virtual ossim_uint32 getSizeInBytes() const
Returns the total number of bytes for all bands.
virtual ossimDataObjectStatus validate() const
signed short ossim_sint16
virtual void setImageRectangleAndBands(const ossimIrect &rect, ossim_uint32 numberOfBands)
virtual bool isEqualTo(const ossimDataObject &rhs, bool deepTest=false) const
virtual void initializeMaxDefault()
initializeMaxDefault() Resizes theMaxPixelValue array to number of bands and initializes to the defau...
#define FLT_EPSILON
void createTestTile()
Creates a step wedge for testing only.
32 bit signed integer
bool toBool() const
String to numeric methods.
OSSIM_DLL double defaultNull(ossimScalarType scalarType)
virtual void nullTileAlpha(const ossim_uint8 *src, const ossimIrect &src_rect, bool mutliplyAlphaFlag=false)
void loadTileFromBip(const void *src, const ossimIrect &src_rect)
virtual ossim_uint32 getSizePerBand() const
Returns the number of pixels in a single band in a tile.
virtual void loadTileWithAlpha(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
std::vector< ossim_float64 > m_maxPixelValue
Max pixel value for each band.
void loadTileFromBipAlphaTemplate(T, const void *src, const ossimIrect &src_rect)
void loadTileFromBsqTemplate(T, const void *src, const ossimIrect &src_rect)
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
32 bit normalized floating point
OverwriteBandRule
Definitions for the unloadBand routines.
virtual void unnormalizeInput(ossimImageData *normalizedInput)
Will take the normalized input and convert it to this tile&#39;s data type.
ossimRefPtr< ossimHistogram > getHistogram(ossim_int32 band)
void loadTileFromBipAlpha(const void *src, const ossimIrect &src_rect)
signed int ossim_sint32
virtual ossimString getScalarTypeAsString() const
void loadTileFromBilTemplate(T, const void *src, const ossimIrect &src_rect)
virtual void setWidth(ossim_uint32 width)
virtual ossimIrect getImageRectangle() const
virtual ossim_float64 computeMeanSquaredError(ossim_float64 meanValue, ossim_uint32 bandNumber=0) const
This will call the compute average band value and then use that in the calculation of: ...
void nullTileAlphaTemplate(T, const ossim_uint8 *src, const ossimIrect &src_rect, const ossimIrect &clip_rect, bool multiplyAlphaFlag=false)
std::vector< ossim_uint32 > m_spatialExtents
virtual void copyTileToNormalizedBuffer(ossim_float64 *buf) const
Copies entire tile to buf passed in.
virtual bool isWithin(ossim_int32 x, ossim_int32 y)
std::vector< ossim_float64 > m_minPixelValue
Min pixel value for each band.
virtual ossim_float64 computeAverageBandValue(ossim_uint32 bandNumber=0) const
This will compute the average value for the band.
const ossimIpt & lr() const
Definition: ossimIrect.h:276
void UpCount(float newval, float occurences=1)
virtual void copyNormalizedBufferToTile(ossim_float64 *buf)
Copies buf passed in to tile.
ossimInterleaveType
virtual void unloadTileToBipAlpha(void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
virtual void unloadTile(void *dest, const ossimIrect &dest_rect, ossimInterleaveType il_type) const
T min(T a, T b)
Definition: ossimCommon.h:203
#define DBL_EPSILON
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossim_float64 m_percentFull
percentage (0-100) of image tile that has valid (non-null) pixel values.
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
void copyLineTemplate(T dummyTemplate, const void *src, ossim_int32 lineNumber, ossim_int32 lineStartSample, ossim_int32 lineStopSample, ossimInterleaveType lineInterleave)
Templated copy line method.
void toPoint(const std::string &s)
Initializes this point from string.
Definition: ossimIpt.cpp:170
void setNull(ossim_uint32 offset)
virtual const ossimImageData & operator=(const ossimImageData &rhs)
assignment operator=
void setIndexedFlag(bool flag)
Sets the indexed flag.
virtual bool isValidBand(ossim_uint32 band) const
ossimScalarType
virtual void setOrigin(const ossimIpt &origin)
virtual ossim_uint32 getScalarSizeInBytes() const
virtual const ossim_float32 * getFloatBuf() const
virtual const ossim_float64 * getMinPix() const
virtual void initialize()
Initializes m_dataBuffer to current spatial extents.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
virtual void setNormalizedFloat(ossim_uint32 offset, ossim_uint32 bandNumber, ossim_float32 input)
This will assign to this object a normalized value by unnormalizing to its native type...
#define OSSIM_DEFAULT_MIN_PIX_NORM_DOUBLE
OSSIM_DLL double defaultMax(ossimScalarType scalarType)
virtual void loadShortBand(const void *src, const ossimIrect &src_rect, ossim_uint32 band, bool swap_bytes=false)
Specialized to load a tile from a short (16 bit scalar type) buffer.
virtual void setMaxPix(ossim_float64 max_pix)
void unloadBandToBsqTemplate(T, void *dest, ossim_uint32 src_band, ossim_uint32 dest_band, const ossimIrect &dest_rect, const ossimIrect &clip_rect, OverwriteBandRule ow_type=NULL_RULE) const
virtual bool isPointWithin(const ossimIpt &point) const
std::vector< ossim_float64 > m_nullPixelValue
Null pixel value for each band.
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
float * GetCounts()
virtual void convertToNormalizedDouble(ossimImageData *result) const
Will use the memory that you pass in to normalize this data object.
bool m_indexedFlag
Indicates data contains palette indexes.
virtual void loadTileFrom1Band(const ossimImageData *data)
#define OSSIM_DEFAULT_MIN_PIX_NORM_FLOAT
bool getIndexedFlag() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
bool toRect(const ossimString &rectString)
expected Format: form 1: ( 30, -90, 512, 512, [LH|RH] ) -x- -y- -w- -h- -Right or left handed- ...
Definition: ossimIrect.cpp:359
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
virtual ossim_uint32 getDataSizeInBytes() const
virtual ossimSource * getOwner()
bool hasNans() const
Definition: ossimIrect.h:337
virtual const ossimRectilinearDataObject & operator=(const ossimRectilinearDataObject &rhs)
assignment operator=
void unloadTileToBsqTemplate(T, void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
ossim_int32 x
Definition: ossimIpt.h:141
virtual void initializeMinDefault()
initializeMinDefault() Resizes theMinPixelValue array to number of bands and initializes to the defau...
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
virtual ossim_uint32 getNumberOfDataComponents() const
8 bit unsigned integer
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual void copyLine(const void *src, ossim_int32 lineNumber, ossim_int32 lineStartSample, ossim_int32 lineStopSample, ossimInterleaveType lineInterleave)
Method to copy a single line to the tile.
ossimDataObjectStatus
Definitions for data object status.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual const ossim_uint8 * getAlphaBuf() const
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
void unloadTileToBipAlphaTemplate(T, void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
virtual void convertToNormalizedFloat(ossimImageData *result) const
Will use the memory that you pass in to normalize this data object.
ossimDataObjectStatus theDataObjectStatus
void loadTileFromBsq(const void *src, const ossimIrect &src_rect)
virtual void setMinPix(ossim_float64 min_pix)
void loadTileFromBipTemplate(T, const void *src, const ossimIrect &src_rect)
void unloadTileToBipTemplate(T, void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
unsigned char ossim_uint8
virtual std::ostream & print(std::ostream &out) const
Generic print method.
virtual void stretchMinMax()
Performs linear stretch on tile data from min/max to limits of scalar type.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual void initializeDefaults()
initializeDefaults() Resizes and sets min/max/null arrays to number of bands and some default value f...
int ossim_int32
16 bit unsigned integer (12 bits used)
void loadBandTemplate(T, const void *src, const ossimIrect &src_rect, ossim_uint32 band)
virtual const ossim_float64 * getDoubleBuf() const
virtual void setHistogram(ossimRefPtr< ossimMultiResLevelHistogram > histo)