bool ossimNitfFileHeaderV2_1::setDefaults(const ossimKeywordlist& /* kwl */, const char* /* prefix */) { #if 0 const char* complexityLevel = kwl.find(prefix, CLEVEL_KW); const char* systemType = kwl.find(prefix, STYPE_KW); const char* originatingStationId = kwl.find(prefix, OSTAID_KW); const char* dateTime = kwl.find(prefix, FDT_KW); const char* title = kwl.find(prefix, FTITLE_KW); const char* securityClassification = kwl.find(prefix, FSCLAS_KW); const char* securityClassificationSys = kwl.find(prefix, FSCLASY_KW); const char* codeWords = kwl.find(prefix, FSCODE_KW); const char* controlAndHandling = kwl.find(prefix, FSCTLH_KW); const char* releasingInstructions = kwl.find(prefix, FSREL_KW); const char* declassificationType = kwl.find(prefix, FSDCTP_KW); const char* declassificationDate = kwl.find(prefix, FSDCDT_KW); const char* declassificationExemption = kwl.find(prefix, FSDCXM_KW); const char* downgrade = kwl.find(prefix, FSDG_KW); const char* downgradingDate = kwl.find(prefix, FSDGDT_KW); const char* classificationText = kwl.find(prefix, FSCLTX_KW); const char* classificationAuthorityType = kwl.find(prefix, FSCATP_KW); const char* classificationAuthority = kwl.find(prefix, FSCAUT_KW); const char* classificationReason = kwl.find(prefix, FSCRSN_KW); const char* securitySourceDate = kwl.find(prefix, FSSRDT_KW); const char* securityControlNumber = kwl.find(prefix, FSCTLN_KW); const char* copyNumber = kwl.find(prefix, FSCOP_KW); const char* numberOfCopies = kwl.find(prefix, FSCPYS_KW); const char* encryption = kwl.find(prefix, ENCRYP_KW); const char* fileBackgroundColor = kwl.find(prefix, FBKGC_KW); const char* originatorsName = kwl.find(prefix, ONAME_KW); const char* originatorsPhone = kwl.find(prefix, OPHONE_KW); if(complexityLevel) { setComplexityLevel(complexityLevel); } #endif return true; }
bool ossimKakaduNitfWriter::writeStream() { static const char MODULE[] = "ossimKakaduNitfWriter::writeStream"; if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered..." << endl; } if ( !theInputConnection || !m_outputStream || !theInputConnection->isMaster() ) { return false; } const ossim_uint32 TILES = theInputConnection->getNumberOfTiles(); const ossim_uint32 BANDS = theInputConnection->getNumberOfOutputBands(); const ossimScalarType SCALAR = theInputConnection->getOutputScalarType(); if (m_compressor->getAlphaChannelFlag()) { //--- // Someone can set this through the generic setProperty interface. // Unset, currently only supported in jp2 writer. // Could be used here but I think we would have to update the // nitf tags. //--- m_compressor->setAlphaChannelFlag(false); } // Create the compressor. Can through an exception. try { m_compressor->create(m_outputStream, SCALAR, BANDS, theInputConnection->getAreaOfInterest(), DEFAULT_TILE_SIZE, TILES, false); } catch (const ossimException& e) { ossimNotify(ossimNotifyLevel_WARN) << e.what() << std::endl; return false; } std::streampos endOfFileHdrPos; std::streampos endOfImgHdrPos; std::streampos endOfFilePos; // Container record withing NITF file header. ossimNitfImageInfoRecordV2_1 imageInfoRecord; // NITF file header. ossimRefPtr<ossimNitfFileHeaderV2_1> fHdr = new ossimNitfFileHeaderV2_1(); // Note the sub header length and image length will be set later. fHdr->addImageInfoRecord(imageInfoRecord); fHdr->setDate(ossimDate()); fHdr->setTitle(ossimString("")); // ??? // Write to stream capturing the stream position for later. fHdr->writeStream(*m_outputStream); endOfFileHdrPos = m_outputStream->tellp(); // NITF image header. ossimRefPtr<ossimNitfImageHeaderV2_1> iHdr = new ossimNitfImageHeaderV2_1(); // Set the compression type: iHdr->setCompression(ossimString("C8")); // Set the Image Magnification (IMAG) field. iHdr->setImageMagnification(ossimString("1.0")); // Set the pixel type (PVTYPE) field. iHdr->setPixelType(ossimNitfCommon::getNitfPixelType(SCALAR)); // Set the actual bits per pixel (ABPP) field. ossim_uint32 abpp = ossim::getActualBitsPerPixel(SCALAR); iHdr->setActualBitsPerPixel( abpp ); // Set the bits per pixel (NBPP) field. iHdr->setBitsPerPixel(ossim::getBitsPerPixel(SCALAR)); iHdr->setNumberOfBands(BANDS); iHdr->setImageMode('B'); // IMODE field to blocked. if( (BANDS == 3) && (SCALAR == OSSIM_UCHAR) ) { iHdr->setRepresentation("RGB"); iHdr->setCategory("VIS"); } else if(BANDS == 1) { iHdr->setRepresentation("MONO"); iHdr->setCategory("MS"); } else { iHdr->setRepresentation("MULTI"); iHdr->setCategory("MS"); } ossimNitfImageBandV2_1 bandInfo; for(ossim_uint32 band = 0; band < BANDS; ++band) { std::ostringstream out; out << std::setfill('0') << std::setw(2) << band; bandInfo.setBandRepresentation(out.str().c_str()); iHdr->setBandInfo(band, bandInfo); } ossim_uint32 outputTilesWide = theInputConnection->getNumberOfTilesHorizontal(); ossim_uint32 outputTilesHigh = theInputConnection->getNumberOfTilesVertical(); iHdr->setBlocksPerRow(outputTilesWide); iHdr->setBlocksPerCol(outputTilesHigh); iHdr->setNumberOfPixelsPerBlockRow(DEFAULT_TILE_SIZE.y); iHdr->setNumberOfPixelsPerBlockCol(DEFAULT_TILE_SIZE.x); iHdr->setNumberOfRows(theInputConnection->getAreaOfInterest().height()); iHdr->setNumberOfCols(theInputConnection->getAreaOfInterest().width()); // Write the geometry info to the image header. writeGeometry(iHdr.get(), theInputConnection.get()); // Add the J2KLRA TRE: ossimRefPtr<ossimNitfJ2klraTag> j2klraTag = new ossimNitfJ2klraTag(); m_compressor->initialize( j2klraTag.get(), abpp ); j2klraTag->setBandsO( BANDS ); ossimRefPtr<ossimNitfRegisteredTag> tag = j2klraTag.get(); ossimNitfTagInformation tagInfo( tag ); iHdr->addTag( tagInfo ); // Write the image header to stream capturing the stream position. iHdr->writeStream(*m_outputStream); endOfImgHdrPos = m_outputStream->tellp(); if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG:" << "\noutputTilesWide: " << outputTilesWide << "\noutputTilesHigh: " << outputTilesHigh << "\nnumberOfTiles: " << TILES << "\nimageRect: " << theInputConnection->getAreaOfInterest() << std::endl; } // Tile loop in the line direction. ossim_uint32 tileNumber = 0; bool result = true; for(ossim_uint32 y = 0; y < outputTilesHigh; ++y) { // Tile loop in the sample (width) direction. for(ossim_uint32 x = 0; x < outputTilesWide; ++x) { // Grab the resampled tile. ossimRefPtr<ossimImageData> t = theInputConnection->getNextTile(); if (t.valid() && ( t->getDataObjectStatus() != OSSIM_NULL ) ) { if ( ! m_compressor->writeTile( *(t.get()) ) ) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " ERROR:" << "Error returned writing tile: " << tileNumber << std::endl; result = false; } } else { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " ERROR:" << "Error returned writing tile: " << tileNumber << std::endl; result = false; } if ( !result ) { // This will bust out of both loops. x = outputTilesWide; y = outputTilesHigh; } // Increment tile number for percent complete. ++tileNumber; } // End of tile loop in the sample (width) direction. if (needsAborting()) { setPercentComplete(100.0); break; } else { ossim_float64 tile = tileNumber; ossim_float64 numTiles = TILES; setPercentComplete(tile / numTiles * 100.0); } } // End of tile loop in the line (height) direction. m_compressor->finish(); // Get the file length. endOfFilePos = m_outputStream->tellp(); //--- // Seek back to set some things that were not know until now and // rewrite the nitf file and image header. //--- m_outputStream->seekp(0, std::ios_base::beg); // Set the file length. std::streamoff length = endOfFilePos; fHdr->setFileLength(static_cast<ossim_uint64>(length)); // Set the file header length. length = endOfFileHdrPos; fHdr->setHeaderLength(static_cast<ossim_uint64>(length)); // Set the image sub header length. length = endOfImgHdrPos - endOfFileHdrPos; imageInfoRecord.setSubheaderLength(static_cast<ossim_uint64>(length)); // Set the image length. length = endOfFilePos - endOfImgHdrPos; imageInfoRecord.setImageLength(static_cast<ossim_uint64>(length)); fHdr->replaceImageInfoRecord(0, imageInfoRecord); setComplexityLevel(length, fHdr.get()); // Rewrite the header. fHdr->writeStream(*m_outputStream); // Set the compression rate now that the image size is known. ossimString comrat = ossimNitfCommon::getCompressionRate( theInputConnection->getAreaOfInterest(), BANDS, SCALAR, static_cast<ossim_uint64>(length)); iHdr->setCompressionRateCode(comrat); // Rewrite the image header. iHdr->writeStream(*m_outputStream); close(); if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status = " << (result?"true":"false\n") << std::endl; } return result; }