ossim_int32 ossimNitfImageHeaderV2_1::getNumberOfPixelsPerBlockVert()const { // return ossimString(theNumberOfPixelsPerBlockVert).toInt32(); ossim_int32 rval = ossimString(theNumberOfPixelsPerBlockVert).toInt32(); if ((rval == 0) && (getNumberOfBlocksPerRow() == 1)) { rval = getNumberOfRows(); } return rval; }
bool ossimNitfImageHeader::isSameAs(const ossimNitfImageHeader* hdr) const { if (!hdr) return false; return ( (isCompressed() == hdr->isCompressed()) && (getNumberOfRows() == hdr->getNumberOfRows()) && (getNumberOfBands() == hdr->getNumberOfBands()) && (getNumberOfCols() == hdr->getNumberOfCols()) && (getNumberOfBlocksPerRow() == hdr->getNumberOfBlocksPerRow()) && (getNumberOfBlocksPerCol() == hdr->getNumberOfBlocksPerCol()) && (getNumberOfPixelsPerBlockHoriz() == hdr->getNumberOfPixelsPerBlockHoriz()) && (getNumberOfPixelsPerBlockVert() == hdr->getNumberOfPixelsPerBlockVert()) && (getBitsPerPixelPerBand() == hdr->getBitsPerPixelPerBand()) && (getImageRect() == hdr->getImageRect()) && (getIMode() == hdr->getIMode()) && (getCoordinateSystem() == hdr->getCoordinateSystem()) && (getGeographicLocation() == hdr->getGeographicLocation()) ); }
ossim_uint32 ossimNitfImageHeaderV2_0::getPadPixelMaskRecordOffset(ossim_uint32 blockNumber, ossim_uint32 bandNumber)const { ossim_uint32 maxBlock = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol(); ossim_uint32 result = 0xffffffff; if((hasPadPixelMaskRecords())&& (blockNumber < maxBlock)) { if(theImageMode[0] == 'S') { if(bandNumber < (ossim_uint32)getNumberOfBands()) { result = thePadPixelMaskRecords[bandNumber*maxBlock + blockNumber]; } } else { result = thePadPixelMaskRecords[blockNumber]; } } return result; }
void ossimNitfImageHeaderV2_0::parseStream(std::istream &in) { clearFields(); theImageBands.clear(); in.read(theType, 2); if(ossimString(theType) != "IM") { // error } in.read(theImageId, 10); in.read(theDateTime, 14); in.read(theTargetId, 17); in.read(theTitle, 80); in.read(theSecurityClassification, 1); in.read(theCodewords, 40); in.read(theControlAndHandling, 40); in.read(theReleasingInstructions, 40); in.read(theClassificationAuthority, 20); in.read(theSecurityControlNumber, 20); in.read(theSecurityDowngrade, 6); if(ossimString(theSecurityDowngrade) == "999998") { in.read(theDowngradingEvent, 40); } in.read(theEncryption, 1); in.read(theImageSource, 42); in.read(theSignificantRows, 8); in.read(theSignificantCols, 8); in.read(thePixelValueType, 3); in.read(theRepresentation, 8); in.read(theCategory, 8); in.read(theActualBitsPerPixelPerBand, 2); in.read(theJustification, 1); in.read(theCoordinateSystem, 1); if(theCoordinateSystem[0] != 'N') { in.read(theGeographicLocation, 60); } in.read(theNumberOfComments, 1); ossim_uint32 numberOfComments = ossimString(theNumberOfComments).toInt32(); if(numberOfComments > 0) { // for now let's ignore the comments about the image in.ignore(numberOfComments*80); } in.read(theCompression, 2); // check to see if there is compression ossimString temp = theCompression; if((temp != "NC") && (temp != "NM")) { // get the rate if compression exists. in.read(theCompressionRateCode, 4); } in.read(theNumberOfBands, 1); ossim_uint32 numberOfBands = ossimString(theNumberOfBands).toUInt32(); theImageBands.resize(numberOfBands); ossim_uint32 idx = 0; while(idx < numberOfBands) { theImageBands[idx] = new ossimNitfImageBandV2_0; theImageBands[idx]->parseStream(in); ++idx; } in.read(theImageSyncCode, 1); in.read(theImageMode, 1); in.read(theNumberOfBlocksPerRow, 4); in.read(theNumberOfBlocksPerCol, 4); in.read(theNumberOfPixelsPerBlockHoriz, 4); in.read(theNumberOfPixelsPerBlockVert, 4); in.read(theNumberOfBitsPerPixelPerBand, 2); in.read(theDisplayLevel, 3); in.read(theAttachmentLevel, 3); in.read(theImageLocation, 10); in.read(theImageMagnification, 4); in.read(theUserDefinedImageDataLength, 5); std::streampos userDefinedDataLen = (std::streampos)ossimString(theUserDefinedImageDataLength).toUInt32(); theTagList.clear(); ossimNitfTagInformation headerTag; std::streampos start = in.tellg(); std::streampos current = in.tellg(); if(userDefinedDataLen > 0) { in.read(theUserDefinedOverflow, 3); while((current - start) < userDefinedDataLen) { headerTag.parseStream(in); theTagList.push_back(headerTag); // in.ignore(headerTag.getTagLength()); // headerTag.clearFields(); current = in.tellg(); } } in.read(theExtendedSubheaderDataLen, 5); std::streampos extSubHeadLen = (std::streampos)ossimString(theExtendedSubheaderDataLen).toUInt32(); start = in.tellg(); current = in.tellg(); if(extSubHeadLen > 0) { in.read(theExtendedSubheaderOverflow, 3); // ossim_uint32 test = 0; while((current - start) < extSubHeadLen) { headerTag.parseStream(in); theTagList.push_back(headerTag); // test = headerTag.getTagLength()+in.tellg(); // in.ignore(headerTag.getTagLength()); // headerTag.clearFields(); current = in.tellg(); } } ossimString compressionType = theCompression; compressionType = compressionType.trim().upcase(); ossimEndian endian; ossim_uint64 locationBefore = in.tellg(); //--- // Note: "C4" added to skip over the image data mask subheader. // See MIL-STD-2500A paragraph 5.5.1.5 // // Seems like CIB data does not have. Could not find a hard and fast // rule in the specs. Need a better was to detect if this needs to be // read. (drb - 20100317) //--- if( (compressionType == "NM") || (compressionType == "M0") || (compressionType == "M3") || (compressionType == "M4") || ( (compressionType == "C4") && ( !getImageId().contains("CIB")) ) ) { in.read((char*)(&theBlockedImageDataOffset), 4); in.read((char*)(&theBlockMaskRecordLength),2); in.read((char*)(&thePadPixelMaskRecordLength), 2); in.read((char*)(&theTransparentOutputPixelCodeLength), 2); if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN) { endian.swap(theBlockedImageDataOffset); endian.swap(theBlockMaskRecordLength); endian.swap(thePadPixelMaskRecordLength); endian.swap(theTransparentOutputPixelCodeLength); } if(theTransparentOutputPixelCodeLength <9) { if(theTransparentOutputPixelCodeLength != 0) { ossim_uint8 padOutputPixelCode; in.read((char*)(&padOutputPixelCode), 1); thePadOutputPixelCode = padOutputPixelCode; } } else { in.read((char*)(&thePadOutputPixelCode), 2); if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN) { endian.swap(thePadOutputPixelCode); } // I need to add code here to check for justification when its 2 bytes // but the code length is less than 16 bits. // } if(theBlockMaskRecordLength>0) { ossim_uint32 totalNumber = 0; if((theImageMode[0] == 'S')) { totalNumber = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol()*getNumberOfBands(); } else { totalNumber = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol(); } ossim_uint32 *blockRead = new ossim_uint32[totalNumber]; ossim_uint32 idx = 0; theBlockMaskRecords.resize(totalNumber); in.read((char*)(blockRead), totalNumber*4); for(idx = 0; idx < totalNumber; ++idx) { if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN) { endian.swap(blockRead[idx]); } theBlockMaskRecords[idx] = blockRead[idx]; } delete [] blockRead; } if((thePadPixelMaskRecordLength > 0)|| (( (getCompressionCode().upcase() == "M3"))&& (thePadPixelMaskRecordLength == 0))) { ossim_uint32 totalNumber = 0; if((theImageMode[0] == 'S')) { totalNumber = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol()*getNumberOfBands(); } else { totalNumber = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol(); } ossim_uint32 *blockRead = new ossim_uint32[totalNumber]; ossim_uint32 idx = 0; thePadPixelMaskRecords.resize(totalNumber); in.read((char*)(blockRead), totalNumber*4); for(idx = 0; idx < totalNumber; ++idx) { if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN) { endian.swap(blockRead[idx]); } thePadPixelMaskRecords[idx] = blockRead[idx]; } delete [] blockRead; } } theCompressionHeader = 0; if((getCompressionCode() == "C4")|| (getCompressionCode() == "M4")) { ossimRefPtr<ossimNitfVqCompressionHeader> compressionHeader = new ossimNitfVqCompressionHeader; compressionHeader->parseStream(in); // do a check to see if the compression header is good // if( compressionHeader->getCompressionAlgorithmId()!= 1 ) { compressionHeader = 0; } theCompressionHeader = compressionHeader.get(); } ossim_uint64 delta = (ossim_uint64)in.tellg() - locationBefore; if(delta < theBlockedImageDataOffset) { in.ignore(theBlockedImageDataOffset-delta); } // // The stream should now be at the start of the data location so capture // it. // theDataLocation = in.tellg(); }
void ossimNitfImageHeaderV2_1::parseStream(std::istream &in) { if (!in) { return; } clearFields(); theTagList.clear(); in.read(theType, 2); in.read(theImageId, 10); in.read(theDateTime,14); in.read(theTargetId, 17); in.read(theTitle, 80); in.read(theSecurityClassification, 1); in.read(theSecurityClassificationSys, 2); in.read(theCodewords, 11); in.read(theControlAndHandling, 2); in.read(theReleasingInstructions, 20); in.read(theDeclassificationType, 2); in.read(theDeclassificationDate, 8); in.read(theDeclassificationExempt, 4); in.read(theDowngrade, 1); in.read(theDowngradeDate, 8); in.read(theClassificationText, 43); in.read(theClassificationAuthType, 1); in.read(theClassificationAuthority, 40); in.read(theClassificationReason, 1); in.read(theSecuritySourceDate, 8); in.read(theSecurityControlNumber, 15); in.read(theEncryption, 1); in.read(theImageSource, 42); in.read(theSignificantRows, 8); in.read(theSignificantCols, 8); in.read(thePixelValueType, 3); in.read(theRepresentation, 8); in.read(theCategory, 8); in.read(theActualBitsPerPixelPerBand, 2); in.read(theJustification, 1); in.read(theCoordinateSystem, 1); // if it's not blank then read coordinates if(theCoordinateSystem[0] != ' ') { in.read(theGeographicLocation, 60); } in.read(theNumberOfComments, 1); ossim_int32 numberOfComments = ossimString(theNumberOfComments).toInt32(); // for now just ignore the comments if(numberOfComments > 0) { in.ignore(numberOfComments*80); } in.read(theCompression, 2); // only need the Rate code if its not // NC (No compression) ossimString temp = theCompression; if((temp != "NC") && (temp != "NM")) { in.read(theCompressionRateCode, 4); } in.read(theNumberOfBands, 1); // check to see if multi spectral bands // exceed 9. A value of 0 indicates this ossim_int32 numberOfBands = ossimString(theNumberOfBands).toInt32(); if (numberOfBands == 0) { in.read(theNumberOfMultispectralBands, 5); numberOfBands = ossimString(theNumberOfMultispectralBands).toInt32(); } theImageBands.clear(); theImageBands.resize(numberOfBands); for (ossim_int32 band = 0; band < numberOfBands; ++band) { theImageBands[band] = new ossimNitfImageBandV2_1; theImageBands[band]->parseStream(in); } in.read(theImageSyncCode, 1); in.read(theImageMode, 1); in.read(theNumberOfBlocksPerRow, 4); in.read(theNumberOfBlocksPerCol, 4); in.read(theNumberOfPixelsPerBlockHoriz, 4); in.read(theNumberOfPixelsPerBlockVert, 4); in.read(theNumberOfBitsPerPixelPerBand, 2); in.read(theDisplayLevel, 3); in.read(theAttachmentLevel, 3); in.read(theImageLocation, 10); in.read(theImageMagnification, 4); in.read(theUserDefinedImageDataLength, 5); ossimNitfTagInformation headerTag; std::streampos start = in.tellg(); std::streampos current = in.tellg(); std::streampos userDefinedDataLen = ossimString(theUserDefinedImageDataLength).toInt32(); if(userDefinedDataLen > 0) { in.read(theUserDefinedOverflow, 3); while((current - start) < userDefinedDataLen) { headerTag.parseStream(in); theTagList.push_back(headerTag); // in.ignore(headerTag.getTagLength()); // headerTag.clearFields(); current = in.tellg(); } in.seekg(start + userDefinedDataLen); } in.read(theExtendedSubheaderDataLen, 5); std::streampos extSubHeadLen = ossimString(theExtendedSubheaderDataLen).toInt32(); start = in.tellg(); current = in.tellg(); if(extSubHeadLen > 0) { in.read(theExtendedSubheaderOverflow, 3); while((current - start) < extSubHeadLen) { headerTag.parseStream(in); theTagList.push_back(headerTag); // in.ignore(headerTag.getTagLength()); // headerTag.clearFields(); current = in.tellg(); } in.seekg(start + extSubHeadLen); } ossimString compressionType = theCompression; compressionType = compressionType.trim().upcase(); ossimEndian endian; //--- // Note: "C4" added to skip over the image data mask subheader. // See MIL-STD-2500C paragraph 5.4.3.2 //--- if((compressionType == "NM")|| (compressionType == "M1")|| (compressionType == "M3")|| (compressionType == "M4")|| (compressionType == "M5")|| (compressionType == "C4")) { ossim_uint64 locationBefore = in.tellg(); in.read((char*)(&theBlockedImageDataOffset), 4); in.read((char*)(&theBlockMaskRecordLength),2); in.read((char*)(&thePadPixelMaskRecordLength), 2); in.read((char*)(&theTransparentOutputPixelCodeLength), 2); if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN) { endian.swap(theBlockedImageDataOffset); endian.swap(theBlockMaskRecordLength); endian.swap(thePadPixelMaskRecordLength); endian.swap(theTransparentOutputPixelCodeLength); } if(theTransparentOutputPixelCodeLength <9) { if(theTransparentOutputPixelCodeLength != 0) { ossim_uint8 padOutputPixelCode; in.read((char*)(&padOutputPixelCode), 1); thePadOutputPixelCode = padOutputPixelCode; } } else { in.read((char*)(&thePadOutputPixelCode), 2); if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN) { endian.swap(thePadOutputPixelCode); } // I need to add code here to check for justification when its 2 bytes // but the code length is less than 16 bits. // } if(theBlockMaskRecordLength>0) { ossim_uint32 totalNumber = 0; if((theImageMode[0] == 'S')) { totalNumber = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol()*getNumberOfBands(); } else { totalNumber = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol(); } ossim_uint32 *blockRead = new ossim_uint32[totalNumber]; ossim_uint32 idx = 0; theBlockMaskRecords.resize(totalNumber); in.read((char*)(blockRead), totalNumber*4); for(idx = 0; idx < totalNumber; ++idx) { if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN) { endian.swap(blockRead[idx]); } theBlockMaskRecords[idx] = blockRead[idx]; } delete [] blockRead; } if((thePadPixelMaskRecordLength > 0)|| (( (getCompressionCode().upcase() == "M3"))&& (thePadPixelMaskRecordLength == 0))) { ossim_uint32 totalNumber = 0; if((theImageMode[0] == 'S')) { totalNumber = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol()*getNumberOfBands(); } else { totalNumber = getNumberOfBlocksPerRow()*getNumberOfBlocksPerCol(); } ossim_uint32 *blockRead = new ossim_uint32[totalNumber]; ossim_uint32 idx = 0; thePadPixelMaskRecords.resize(totalNumber); in.read((char*)(blockRead), totalNumber*4); for(idx = 0; idx < totalNumber; ++idx) { if(endian.getSystemEndianType() == OSSIM_LITTLE_ENDIAN) { endian.swap(blockRead[idx]); } thePadPixelMaskRecords[idx] = blockRead[idx]; } delete [] blockRead; } theCompressionHeader = 0; if((getCompressionCode() == "C4")|| (getCompressionCode() == "M4")) { ossimRefPtr<ossimNitfVqCompressionHeader> compressionHeader = new ossimNitfVqCompressionHeader; compressionHeader->parseStream(in); // do a check to see if the compression header is good // if(compressionHeader->getCompressionAlgorithmId()!= 1) { compressionHeader = 0; } theCompressionHeader = compressionHeader.get(); } ossim_uint64 delta = (ossim_uint64)in.tellg() - locationBefore; if(delta < theBlockedImageDataOffset) { in.ignore(theBlockedImageDataOffset-delta); } } //*** // The stream should now be at the start of the data location so capture // it. //*** theDataLocation = in.tellg(); }