ossim_int32 ossimGeneralRasterInfo::getBitsPerPixel( const ossimFilename& imageFile ) const { // Note currently does not consider header size. ossim_int32 result = 0; ossim_int64 fileSize = imageFile.size(); ossimIpt rectSize = theRawImageRect.size(); if ( fileSize && rectSize.x && rectSize.y && numberOfBands() ) { result = ( fileSize / rectSize.x / rectSize.y / numberOfBands() ) * 8; } return result; }
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::initializeFromXml( const ossimFilename& imageFile, const ossimFilename& headerFile ) { bool result = false; ossimFgdcXmlDoc file; if (file.open( headerFile )) { while( 1 ) { //--- // Go through the data members in order. // If a required item is not found break from loop. //-- theMetaData.clear(); // scalar ( default ) - adjusted below : theMetaData.setScalarType( OSSIM_UINT8 ); // Image file name: theImageFileList.clear(); theImageFileList.push_back( imageFile ); // interleave ( defaulted ): theInterleaveType = OSSIM_BIL; // bands ( required ): if ( !file.getNumberOfBands() ) { break; } theMetaData.setNumberOfBands( file.getNumberOfBands() ); ossimIpt size; if ( file.getImageSize(size) ) // Lines, samples not image file size. { // lines, samples ( required ): if ( !size.x || !size.y ) { break; } } else { break; } // Set the rectangles: theRawImageRect = ossimIrect( 0, 0, size.x - 1, size.y - 1 ); theValidImageRect = theRawImageRect; theImageRect = theRawImageRect; // sample start ( not required ): theSubImageOffset.x = 0; // line start ( not required ): theSubImageOffset.y = 0; // header offset ( not required ): theHeaderSize = 0; // null mode: theSetNullsMode = ossimGeneralRasterInfo::NONE; // pixels to chop: thePixelsToChop = 0; // Byte order *** need this ***, defaulting to system for now: theImageDataByteOrder = ossim::byteOrder(); // Adjust scalar if needed, note defaulted to 8 bit above: ossimString eainfo; file.getPath("/metadata/eainfo/detailed/enttyp/enttypd", eainfo); ossim_int32 numBits = 0; ossim_int64 fileSize = imageFile.fileSize(); // Image file size. ossim_int32 numBytes = fileSize / size.x / size.y / numberOfBands(); if( numBytes > 0 && numBytes != 3 ) { numBits = numBytes*8; } if( numBits == 16 ) { theMetaData.setScalarType( OSSIM_UINT16 ); } else if( numBits == 32 ) { if(eainfo.contains("float")) { theMetaData.setScalarType( OSSIM_FLOAT32 ); } else { theMetaData.setScalarType( OSSIM_UINT32 ); } } result = true; break; // Trailing break to get out. } } return result; } // End: ossimGeneralRasterInfo::initializeFromXml
/******************************************************************************* Functionname: UpdateFreqScale ******************************************************************************* Description: Arguments: Return: *******************************************************************************/ int UpdateFreqScale(unsigned char *v_k_master, int *h_num_bands, const int k0, const int k2, const int freqScale, const int alterScale) { int b_p_o = 0; float warp = 0; int dk = 0; /* Internal variables */ int two_regions = 0; int k1 = 0, i; int num_bands0; int num_bands1; int diff_tot[MAX_OCTAVE + MAX_SECOND_REGION]; int *diff0 = diff_tot; int *diff1 = diff_tot+MAX_OCTAVE; int k2_achived; int k2_diff; int incr = 0; /* counting previous operations */ if(freqScale==1) { b_p_o=12; } if(freqScale==2) { b_p_o=10; } if(freqScale==3) { b_p_o=8; } if(freqScale > 0) { if(alterScale==0) { warp=1.0; } else { warp=1.3f; } if(4*k2 >= 9*k0) { two_regions=1; k1=2*k0; num_bands0=numberOfBands(b_p_o, k0, k1, 1.0); num_bands1=numberOfBands(b_p_o, k1, k2, warp); CalcBands(diff0, k0, k1, num_bands0); Shellsort_int( diff0, num_bands0); if (diff0[0] == 0) { return (1); } cumSum(k0, diff0, num_bands0, v_k_master); CalcBands(diff1, k1, k2, num_bands1); Shellsort_int( diff1, num_bands1); if(diff0[num_bands0-1] > diff1[0]) { if(modifyBands(diff0[num_bands0-1],diff1, num_bands1)) { return(1); } } cumSum(k1, diff1, num_bands1, &v_k_master[num_bands0]); *h_num_bands=num_bands0+num_bands1; } else { two_regions=0; k1=k2; num_bands0=numberOfBands(b_p_o, k0, k1, 1.0); CalcBands(diff0, k0, k1, num_bands0); Shellsort_int( diff0, num_bands0); if (diff0[0] == 0) { return (1); } cumSum(k0, diff0, num_bands0, v_k_master); *h_num_bands=num_bands0; } } else { if (alterScale==0) { dk = 1; num_bands0 = 2 * ((k2 - k0)/2); } else { dk = 2; num_bands0 = 2 * (((k2 - k0)/dk +1)/2); } k2_achived = k0 + num_bands0*dk; k2_diff = k2 - k2_achived; for(i=0;i<num_bands0;i++) { diff_tot[i] = dk; } if (k2_diff < 0) { incr = 1; i = 0; } if (k2_diff > 0) { incr = -1; i = num_bands0-1; } /* diff_tot[] */ while (k2_diff != 0) { diff_tot[i] = diff_tot[i] - incr; /* ADD(1): pointer increment */ i = i + incr; k2_diff = k2_diff + incr; } cumSum(k0, diff_tot, num_bands0, v_k_master); *h_num_bands=num_bands0; } if (*h_num_bands < 1) { return(1); } return (0); }/* End UpdateFreqScale */