bool ossimGeneralRasterTileSource::fillBuffer(const ossimIpt& origin, const ossimIpt& size)
{

   static const char MODULE[] = "ossimGeneralRasterTileSource::fillBuffer";

   // Note:  InterleaveType enumerations in "constants.h" file.
   bool status = false;
   switch ( m_rasterInfo.interleaveType() )
   {
      case OSSIM_BIP:
      {
         status = fillBIP(origin, size);
         break;
      }
      case OSSIM_BIL:
      {
         status = fillBIL(origin, size);
         break;
      }
      case OSSIM_BSQ:
      {
         status = fillBSQ(origin, size);
         break;
      }
      case OSSIM_BSQ_MULTI_FILE:
      {
         status = fillBsqMultiFile(origin, size);
         break;
      }
      default:
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " ERROR:\n"
            << " Unsupported interleave type:  "
            << ILUT.getEntryString(m_rasterInfo.interleaveType())
            << std::endl;
      }
   }
   
   if (status && m_swapBytesFlag)
   {
      ossimEndian oe;
      oe.swap(m_rasterInfo.getImageMetaData().getScalarType(),
              m_buffer,
              m_bufferSizeInPixels);
   }

   return status;
}
bool ossimGeneralRasterInfo::loadState(const ossimKeywordlist& kwl, const char* prefix)
{
   static const char MODULE[] = "ossimGeneralRasterInfo::loadState";
   if ( traceDebug() )
   {
      CLOG << "DEBUG: entered..."
           << "\nprefix:  " << (prefix ? prefix : "")
           << "\nInput keyword list:\n"
           << kwl
           << std::endl;
   }   

   bool result = false;

   //---
   // Look for required and option keyword.  Break from loop if required
   // keyword is not found.
   //---
   while( 1 )
   {
      // Check for errors in the ossimKeywordlist.
      if(kwl.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR)
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " ERROR:\n"
            << "Detected an error in the keywordlist:  " << kwl
            << std::endl;
         break;
      }

      std::string key;
      ossimString value; // Use for keyword list lookups.
      ossim_int32 lines = 0;
      ossim_int32 samples = 0;

      // Lines (required):
      key = NUMBER_LINES;
      value.string() = kwl.findKey( key );  // Required to have this.
      if ( value.size() )
      {
         lines = value.toInt32();
         if ( !lines )
         {
            if (traceDebug())
            {
               ossimNotify(ossimNotifyLevel_WARN)
                  << " ERROR:\n"
                  << "Required number of lines is 0!" << std::endl;
            }
            break;
         } 
      }
      else
      {
         if (traceDebug())
         {
            ossimNotify(ossimNotifyLevel_WARN)
               << " ERROR:\n"
               << "Required keyword not found:  " << key << std::endl;
         }
         break;
      }

      // Samples (required):
      key = NUMBER_SAMPLES;
      value.string() = kwl.findKey( key );  // Required to have this.
      if ( value.size() )
      {
         samples = value.toInt32();
         if ( !samples )
         {
            if (traceDebug())
            {
               ossimNotify(ossimNotifyLevel_WARN)
                  << " ERROR:\n"
                  << "Required number of samples is 0!" << std::endl;
            }
            break;
         }          
      }
      else
      {
         if (traceDebug())
         {
            ossimNotify(ossimNotifyLevel_WARN)
               << " ERROR:\n"
               << "Required keyword not found:  " << key << std::endl;
         }
         break;
      }
      
      // Bands ossimImageMetaData::loadState checks for required bands:
      if(!theMetaData.loadState(kwl, prefix))
      {
         if (traceDebug())
         {
            ossimNotify(ossimNotifyLevel_WARN)
               << " Error loading meta data!\n" << std::endl;
         }
         break;
      }

      // If we get here assign the rectangles:
      theRawImageRect   = ossimIrect( 0, 0, samples - 1, lines - 1 );
      theValidImageRect = theRawImageRect;
      theImageRect      = theRawImageRect;

      int tmp = INTERLEAVE_TYPE_LUT.getEntryNumber(kwl);
      if (tmp == ossimLookUpTable::NOT_FOUND)
      {
         theInterleaveType = OSSIM_BIL;
      }
      else
      {
         theInterleaveType = static_cast<ossimInterleaveType>(tmp);
      }
      
      // Get the image files.
      if (theInterleaveType != OSSIM_BSQ_MULTI_FILE)
      {
         // Look for "filename" first, then deprecated "image_file".
         key = ossimKeywordNames::FILENAME_KW;
         value.string() = kwl.findKey( key );
         if ( value.empty() )
         {
            // deprecated keyword...
            key = ossimKeywordNames::IMAGE_FILE_KW;
            value.string() = kwl.findKey( key );
         }
         
         if ( value.size() )
         {
            //---
            // omd (ossim metadata) files can have just the base filename, e.g. image.ras,
            // in which case open will fail if not in the image dir.  So only put it in
            // the list if it doesn't exits.
            //---
            ossimFilename f = value;
            if ( f.exists() )
            {
               theImageFileList.clear();
               theImageFileList.push_back(ossimFilename(value));
            }
         }

         if ( theImageFileList.empty() )
         {
            if (traceDebug())
            {
               ossimNotify(ossimNotifyLevel_WARN)
                  << "ERROR:\n"
                  << "Required keyword not found:  "
                  << ossimKeywordNames::FILENAME_KW << std::endl;
            }
            break;
         }
      }
      else
      {
         // multiple file names.
         ossim_int32 count = 0;
         
         // look for image file key word with no number.
         // Required to have this.
         key = ossimKeywordNames::FILENAME_KW;
         value.string() = kwl.findKey( key );
         if ( value.empty() )
         {
            // deprecated keyword...
            key = ossimKeywordNames::IMAGE_FILE_KW;
            value.string() = kwl.findKey( key );
         }
         
         if ( value.size() )
         {
            theImageFileList.push_back(ossimFilename(value));
            ++count;
         }
         
         ossim_int32 i = 0;
         while ( (count < numberOfBands()) && (i < 1000) )
         {
            key = ossimKeywordNames::FILENAME_KW;
            key += ossimString::toString(i).string();
            value.string() = kwl.findKey( key );
            if ( value.empty() )
            {
               // Lookup for deprecated keyword.
               key = ossimKeywordNames::IMAGE_FILE_KW;
               key += ossimString::toString(i).string();
               value.string() = kwl.findKey( key );
            }
            
            if ( value.size() )
            {
               theImageFileList.push_back(ossimFilename(value));
               ++count;
            }
            ++i;
         }
         
         if (count != numberOfBands())  // Error, count should equal bands!
         {
            if (traceDebug())
            {
               ossimNotify(ossimNotifyLevel_WARN)
                  << " ERROR:\n"
                  << "Required keyword not found:  "
                  << ossimKeywordNames::FILENAME_KW
                  << "\nInterleave type is multi file; however,"
                  << " not enough were pick up!"  << std::endl;
            }
            break;
         }
      }

      key = VALID_START_LINE;
      value.string() = kwl.findKey( key ); // Default is zero.
      if ( value.size() )
      {
         theValidImageRect.set_uly( value.toInt32() );
      }

      key = VALID_STOP_LINE;
      value.string() = kwl.findKey( key ); // Default is last line.
      if ( value.size() )
      {
         theValidImageRect.set_lry( value.toInt32() );
      }
      
      if (theValidImageRect.lr().y < theValidImageRect.ul().y)
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << " ERROR:"
            << "\nValid stop line < start line."
            << "\nValid start line:  " << theValidImageRect.ul().y
            << "\nValid stop line:   " << theValidImageRect.lr().y
            << "\nError status has been set.  Returning." << std::endl;
         break;
      }

      key = VALID_START_SAMPLE;
      value.string() = kwl.findKey( key ); // Default is zero.
      if ( value.size() )
      {
         theValidImageRect.set_ulx( value.toInt32() );
      }

      key = VALID_STOP_SAMPLE;
      value.string() = kwl.findKey( key ); // Default is last sample.
      if ( value.size() ) 
      {
         theValidImageRect.set_lrx( value.toInt32() );
      }
      
      if (theValidImageRect.lr().x < theValidImageRect.ul().x)
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << " ERROR:"
            << "\nValid stop samp < start samp."
            << "\nValid start samp:  " << theValidImageRect.ul().x
            << "\nValid stop samp:   " << theValidImageRect.lr().x
            << "\nError status has been set.  Returning." << std::endl;
         break;
      }
      
      theImageRect.set_lry(theValidImageRect.lr().y -
                           theValidImageRect.ul().y);
      theImageRect.set_lrx(theValidImageRect.lr().x -
                           theValidImageRect.ul().x);
      
      key = SUB_IMAGE_OFFSET_LINE;
      value.string() = kwl.findKey( key ); // Default is zero.
      if ( value.size() )
      {
         theSubImageOffset.line = value.toInt32();
      }

      key = SUB_IMAGE_OFFSET_SAMP;
      value.string() = kwl.findKey( key ); // Default is zero.
      if ( value.size() )
      {
         theSubImageOffset.samp = atoi(value);
      }

      key = HEADER_SIZE;
      value.string() = kwl.findKey( key ); // Default is zero.
      if ( value.size() )
      {
         theHeaderSize = value.toInt32();
      }

      key = SET_NULLS;
      value.string() = kwl.findKey( key ); // Default is 2.
      if ( value.size() )
      {
         int tmp;
         tmp = atoi(value);
         if ((tmp < 3) && (tmp > -1))
         {
            theSetNullsMode = (ossimFillMode)tmp;
         }
         else
         {
            theSetNullsMode = ZEROES_TO_NULL_EDGES_ONLY;  // 2
            ossimNotify(ossimNotifyLevel_WARN)
               << " WARNING:"
               << "\nset_fill_to_nulls_mode value out of range."
               << "\nDefaulted to 2" << std::endl;
         }
      }

      key = PIXELS_TO_CHOP;
      value.string() = kwl.findKey( key ); // Default is zero.
      if ( value.size() )
      {
         thePixelsToChop = value.toInt32();
      }
      
      if (bytesPerPixel() > 1)
      {
         // get the byte order of the data.
         key = ossimKeywordNames::BYTE_ORDER_KW;
         value.string() = kwl.findKey( key );
         if ( value.size() )
         {
            ossimString s(value);
            if (s.trim() != "")  // Check for empty string.
            {
               s.downcase();
               if (s.contains("big"))
               {
                  theImageDataByteOrder = OSSIM_BIG_ENDIAN;
               }
               else if(s.contains("little"))
               {
                  theImageDataByteOrder = OSSIM_LITTLE_ENDIAN;
               }
            }
         }
      }

      // End of while forever loop.
      result = true;
      break;

   } // Matches: while (1)

   if ( traceDebug() )
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE  << " Exit status: " << (result?"true":"false") << std::endl;
   }      
   
   return result;
   
} // End: bool ossimGeneralRasterInfo::loadState
bool ossimGeneralRasterInfo::saveState(ossimKeywordlist& kwl,
                                       const char* prefix) const
{
   for (ossim_uint32 i=0; i<theImageFileList.size(); ++i)
   {
      ossimString kw = ossimKeywordNames::FILENAME_KW;
      kw += ossimString::toString(i+1);
      kwl.add(prefix, theImageFileList[i].c_str());
   }

   theMetaData.saveState(kwl, prefix);

   kwl.add(prefix,
           NUMBER_LINES,
           ossimString::toString( rawLines() ), true);
   kwl.add(prefix,
           NUMBER_SAMPLES,
           ossimString::toString( rawSamples() ),
           true);
   kwl.add(prefix,
           HEADER_SIZE,
           ossimString::toString(theHeaderSize),
           true);
   kwl.add(prefix,
           SUB_IMAGE_OFFSET_LINE,
           theSubImageOffset.line,
           true);
   kwl.add(prefix,
           SUB_IMAGE_OFFSET_SAMP,
           theSubImageOffset.samp,
           true);
   kwl.add(prefix,
           VALID_START_LINE,
           theValidImageRect.ul().y,
           true);
   kwl.add(prefix,
           VALID_STOP_LINE,
           theValidImageRect.lr().y,
           true);
   kwl.add(prefix,
           VALID_START_SAMPLE,
           theValidImageRect.ul().x,
           true);
   kwl.add(prefix,
           VALID_STOP_SAMPLE,
           theValidImageRect.ur().x,
           true);
   kwl.add(prefix,
           ossimKeywordNames::INTERLEAVE_TYPE_KW,
           INTERLEAVE_TYPE_LUT.getEntryString(theInterleaveType),
           true);

   kwl.add(prefix,
           PIXELS_TO_CHOP,
           thePixelsToChop,
           true);

   kwl.add(prefix,
           SET_NULLS,
           theSetNullsMode,
           true);


   if (bytesPerPixel() > 1)
   {
      kwl.add(prefix,
              ossimKeywordNames::BYTE_ORDER_KW,
              (theImageDataByteOrder == OSSIM_LITTLE_ENDIAN ? "little_endian" :
               "big_endian"),
              true);
   }

   return true;
}