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