28 static const std::string ALIGN_TILES_KW =
"align_tiles";
29 static const std::string BLOCK_SIZE_KW =
"block_size";
30 static const std::string FLUSH_TILES_KW =
"flush_tiles";
31 static const std::string INCLUDE_BLANK_TILES_KW =
"include_blank_tiles";
32 static const std::string TILE_SIZE_KW =
"tile_size";
33 static const std::string TRUE_KW =
"true";
35 static const ossimTrace traceDebug(
"ossimWriter:debug");
40 m_ownsStreamFlag(false),
105 imageTypeList.push_back(
ossimString(
"ossim_ttbs"));
110 return (
m_str ?
true :
false );
142 if ( (imageType ==
"ossim_ttbs") || (imageType ==
"image/tif") )
219 std::vector<ossim_uint64> tile_offsets;
220 std::vector<ossim_uint64> tile_byte_counts;
226 std::vector<ossim_float64> minBands(0);
227 std::vector<ossim_float64> maxBands(0);
230 tile_offsets, tile_byte_counts, minBands, maxBands ) ==
true )
254 m_str->write( s.c_str(), 2 );
258 m_str->write( (
const char*)&us16, 2 );
262 m_str->write( (
const char*)&us16, 2 );
266 m_str->write( (
const char*)&us16, 2 );
270 m_str->write( (
const char*)&ul64, 8 );
272 return m_str->good();
276 const std::vector<ossim_uint64>& tile_byte_counts,
277 const std::vector<ossim_float64>& minBands,
278 const std::vector<ossim_float64>& maxBands )
291 m_str->seekp( 16, std::ios_base::beg );
295 m_str->write( (
const char*)&tagCount, 8 );
302 std::streamoff arrayWritePos = 512;
318 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
324 writeTiffTag<ossim_uint32>( tag, type, count, &value_ui32, arrayWritePos );
335 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
341 writeTiffTag<ossim_uint32>( tag, type, count, &value_ui32, arrayWritePos );
352 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
356 std::vector<ossim_uint16> v(count, value_ui16);
357 writeTiffTag<ossim_uint16>( tag, type, count, &v.front(), arrayWritePos );
366 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
381 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
389 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
403 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
415 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
421 writeTiffTag<ossim_uint32>( tag, type, count, &value_ui32, arrayWritePos );
432 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
438 writeTiffTag<ossim_uint32>( tag, type, count, &value_ui32, arrayWritePos );
445 count = tile_offsets.size();
447 writeTiffTag<ossim_uint64>( tag, type, count, &tile_offsets.front(), arrayWritePos );
452 count = tile_byte_counts.size();
454 writeTiffTag<ossim_uint64>( tag, type, count, &tile_byte_counts.front(), arrayWritePos );
464 writeTiffTag<ossim_uint16>( tag, type, count, &value_ui16, arrayWritePos );
468 std::vector<ossim_uint16> v(count, value_ui16);
469 writeTiffTag<ossim_uint16>( tag, type, count, &v.front(), arrayWritePos );
480 if ( mapProj.
valid() )
482 std::vector<ossim_float64> vf;
508 writeTiffTag<ossim_float64>( tag, type, count, &vf.front(), arrayWritePos );
522 writeTiffTag<ossim_float64>( tag, type, count, &vf.front(), arrayWritePos );
529 std::vector<ossim_uint16> vs(0);
604 vs[3] = (count / 4) - 1;
605 writeTiffTag<ossim_uint16>( tag, type, count, &vs.front(), arrayWritePos );
615 writeTiffTag<ossim_float64>( tag, type, count, &vf.front(), arrayWritePos );
621 m_str->write( (
const char*)&offsetToNextIfd, 8 );
624 m_str->seekp( 16, std::ios_base::beg );
625 m_str->write( (
const char*)&tagCount, 8 );
684 1, &minValue, arrayWritePos );
687 1, &maxValue, arrayWritePos );
694 const vector<ossim_float64>& maxBands,
695 std::streamoff& arrayWritePos )
699 if(minBands.size() && maxBands.size())
701 ossim_float64 minValue = *std::min_element(minBands.begin(), minBands.end());
702 ossim_float64 maxValue = *std::max_element(maxBands.begin(), maxBands.end());
716 1, &v, arrayWritePos );
720 1, &v, arrayWritePos );
736 const T* value, std::streamoff& arrayWritePos )
738 m_str->write( (
const char*)&tag, 2 );
739 m_str->write( (
const char*)&type, 2 );
740 m_str->write( (
const char*)&count, 8 );
746 m_str->write( (
const char*)value, bytes );
751 m_str->write( (
const char*)&c, (8-bytes) );
757 m_str->write( (
const char*)&arrayWritePos, 8 );
760 std::streamoff currentPos =
m_str->tellp();
763 m_str->seekp( arrayWritePos, std::ios_base::beg );
766 m_str->write( (
const char*)value, bytes );
769 arrayWritePos =
m_str->tellp();
772 m_str->seekp( currentPos, std::ios_base::beg );
777 std::vector<ossim_uint64>& tile_byte_counts,
778 std::vector<ossim_float64>& minBands,
779 std::vector<ossim_float64>& maxBands )
781 static const char*
const MODULE =
"ossimWriter::writeToTilesBandSeparate";
782 if ( traceDebug() )
CLOG <<
" Entered...\n";
803 <<
"align tiles flag: " << alignTiles
804 <<
"\nflush tiles flag: " << flushTiles
805 <<
"\nwrite blanks flag: " << writeBlanks
806 <<
"\ncompute min max flag: " << computeMinMax
807 <<
"\nwrite block size: " << BLOCK_SIZE
808 <<
"\nBANDS: " << BANDS
809 <<
"\nTILES_WIDE: " << TILES_WIDE
810 <<
"\nTILES_TOTAL: " << TILES_TOTAL <<
"\n";
813 tile_offsets.resize( TILES_TOTAL*BANDS );
814 tile_byte_counts.resize( TILES_TOTAL*BANDS );
831 std::streamsize startPos = 512 + 16 * TILES_TOTAL * BANDS + 256;
833 while ( ossimTileIndex < TILES_TOTAL )
839 << MODULE <<
" ERROR:" 840 <<
"Error returned writing tiff tile: " << ossimTileIndex
841 <<
"\nNULL Tile from input encountered" 846 tileStatus =
id->getDataObjectStatus();
848 if ( ossimTileIndex == 0 )
851 bandOffsetInBytes = tileSizeInBytes * TILES_TOTAL;
859 id->computeMinMaxPix(minBands, maxBands);
866 tiffTileIndex = ossimTileIndex + band * TILES_TOTAL;
871 const char* data = (
const char*)id->
getBuf(band);
883 std::streampos pos = startPos + ossimTileIndex * tileSizeInBytes +
884 band * bandOffsetInBytes;
889 std::streampos overflow = pos % BLOCK_SIZE;
892 pos += BLOCK_SIZE - overflow;
901 tile_byte_counts[ tiffTileIndex ] = (
ossim_uint64)tileSizeInBytes;
904 m_str->write( data, (std::streamsize)tileSizeInBytes);
915 << MODULE <<
" ERROR:\nWrite error on tiff tile: " << ossimTileIndex
923 << MODULE <<
" ERROR:\nStream has gone bad!" << std::endl;
931 << MODULE <<
" ERROR:\nNull input tile: " << ossimTileIndex
945 <<
"sparse blank tile[" << tiffTileIndex <<
"]: " << tiffTileIndex <<
"\n";
947 tile_offsets[ tiffTileIndex ] = 0;
948 tile_byte_counts[ tiffTileIndex ] = 0;
960 else if ( ossimTileIndex % TILES_WIDE )
963 double tileNum = ossimTileIndex;
964 double numTiles = TILES_TOTAL;
970 if ( traceDebug() )
CLOG <<
" Exited...\n";
972 return m_str->good();
988 if ( (tileSize.
x % 16) || (tileSize.
y % 16) )
993 <<
"ossimWriter::setTileSize ERROR:" 994 <<
"\nTile size must be a multiple of 16!" 1022 bool result =
false;
1029 std::string pfx = prefix?prefix:
"";
1032 value = kwl.
findKey( pfx, ALIGN_TILES_KW );
1038 value = kwl.
findKey( pfx, BLOCK_SIZE_KW );
1044 value = kwl.
findKey( pfx, FLUSH_TILES_KW );
1050 value = kwl.
findKey( pfx, INCLUDE_BLANK_TILES_KW );
1056 value = kwl.
findKey( pfx, TILE_SIZE_KW );
1070 if( property.
valid() )
1073 std::string key =
property->getName().string();
1078 property->valueToString(value);
1081 <<
"ossimWriter::setProperty DEBUG:" 1083 <<
"\nvalue: " << value <<
"\n";
1086 if ( ( key == ALIGN_TILES_KW ) ||
1087 ( key == BLOCK_SIZE_KW ) ||
1088 ( key == FLUSH_TILES_KW ) ||
1089 ( key == INCLUDE_BLANK_TILES_KW ) )
1092 property->valueToString(value);
1095 else if ( key == TILE_SIZE_KW )
1099 property->valueToString(value);
1117 if ( name.
string() == ALIGN_TILES_KW )
1122 prop = boolProp.
get();
1124 else if( name == BLOCK_SIZE_KW )
1130 prop = stringProp.
get();
1132 else if ( name.
string() == FLUSH_TILES_KW )
1137 prop = boolProp.
get();
1139 else if ( name.
string() == INCLUDE_BLANK_TILES_KW )
1141 std::string value =
m_kwl->
findKey( INCLUDE_BLANK_TILES_KW );
1144 prop = boolProp.
get();
1146 else if( name == TILE_SIZE_KW )
1161 prop = stringProp.
get();
1172 propertyNames.push_back(
ossimString(ALIGN_TILES_KW));
1173 propertyNames.push_back(
ossimString(BLOCK_SIZE_KW));
1174 propertyNames.push_back(
ossimString(FLUSH_TILES_KW));
1175 propertyNames.push_back(
ossimString(INCLUDE_BLANK_TILES_KW));
1176 propertyNames.push_back(
ossimString(TILE_SIZE_KW));
1239 if ( result % 1024 )
1243 <<
"ossimWriter::getBlockSize ERROR:" 1244 <<
"\nBlock size MUST be a multiple of 1024!" 1245 <<
"\nBlock size remains: " << result
1266 std::string value =
m_kwl->
findKey( INCLUDE_BLANK_TILES_KW );
1276 bool result =
false;
ossimString toString() const
16 bit unsigned integer (15 bits used)
virtual ossimString getShortName() const
#define OSSIM_DEFAULT_MAX_PIX_UINT16
virtual const ossimDpt & getDecimalDegreesPerPixel() const
Returns decimal degrees per pixel as an ossimDpt with "x" representing longitude and "y" representing...
bool hasImageType(const ossimString &imageType) const
bool hasImageType(const ossimString& imageType) const
virtual void close()
close Flushes and deletes stream if we own it.
ossim_uint16 getTiffSampleFormat() const
Gets the tiff sample format based on scalar type.
ossim_uint32 getEpsgCode() const
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
ossimString theOutputImageType
bool needsAborting() const
virtual bool isMaster() const
virtual void setTileSize(const ossimIpt &tileSize)
Sets the output tile size for tiled formats.
bool writeTiffHdr()
Writes tiff header to stream.
Represents serializable keyword/value map.
virtual ossimString getExtension() const
Returns a 3-letter extension from the image type descriptor (theOutputImageType) that can be used for...
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
virtual void setToStartOfSequence()
static const ossimErrorCode OSSIM_OK
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual ossim_uint32 getPcsCode() const
Returns the EPSG PCS code or 32767 if the projection is a custom (non-EPSG) projection.
virtual ossim_uint32 epsgCode() const
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
getImageTypeList method.
ossim_int64 getNumberOfTiles() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossim_uint32 height() const
bool writeTiffTags(const std::vector< ossim_uint64 > &tile_offsets, const std::vector< ossim_uint64 > &tile_byte_counts, const std::vector< ossim_float64 > &minBands, const std::vector< ossim_float64 > &maxBands)
Writes tags to image file directory(IFD).
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimIrect theAreaOfInterest
static ossimString toString(bool aValue)
Numeric to string methods.
void setChangeType(int type, bool on=true)
virtual bool isGeographic() const
OSSIM_DLL void defaultTileSize(ossimIpt &tileSize)
const ossimIpt & ul() const
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
OSSIM_DLL ossimByteOrder byteOrder()
16 bit unsigned integer (14 bits used)
bool getFlushTilesFlag() const
16 bit unsigned integer (13 bits used)
virtual ossimString getClassName() const
virtual bool setOutputStream(std::ostream &str)
Sets the output stream to write to.
virtual void setReadOnlyFlag(bool flag)
void addConstraint(const ossimString &value)
Pure virtual base class for image file writers.
unsigned short ossim_uint16
virtual ~ossimWriter()
virtual destructor
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
bool writeSMinSMaxTiffTags(const std::vector< ossim_float64 > &minBands, const std::vector< ossim_float64 > &maxBands, std::streamoff &arrayWritePos)
Writes tags TIFFTAG_SMINSAMPLEVALUE(340) and TIFFTAG_SMAXSAMPLEVALUE(341).
#define OSSIM_DEFAULT_TILE_WIDTH
virtual ossim_uint32 getSizePerBandInBytes() const
Returns the number of bytes in single band of the tile.
bool writeMinMaxTiffTags(std::streamoff &arrayWritePos)
Writes tags TIFFTAG_MINSAMPLEVALUE(280) and TIFFTAG_MAXSAMPLEVALUE(281).
ossim_int32 toInt32() const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
ossimRefPtr< ossimKeywordlist > m_kwl
Hold all options.
virtual ossimGpt lineSampleToWorld(const ossimDpt &projectedPoint) const
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual const ossimDatum * getDatum() const
virtual void lineSampleToEastingNorthing(const ossimDpt &liineSample, ossimDpt &eastingNorthing) const
std::string::size_type size() const
ossimRefPtr< ossimImageSourceSequencer > theInputConnection
ossimFilename theFilename
bool toBool() const
String to numeric methods.
ossim_int64 getBlockSize() const
unsigned long long ossim_uint64
unsigned int ossim_uint32
32 bit normalized floating point
virtual const ossimEllipsoid * ellipsoid() const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Pushes this's names onto the list of property names.
ossimIpt m_outputTileSize
bool writeTiffTilesBandSeparate(std::vector< ossim_uint64 > &tile_offsets, std::vector< ossim_uint64 > &tile_byte_counts, std::vector< ossim_float64 > &minBands, std::vector< ossim_float64 > &maxBands)
Writes image data to stream.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
ossim_uint32 width() const
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Will set the property whose name matches the argument "property->getName()".
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
void toPoint(const std::string &s)
Initializes this point from string.
OSSIM_DLL ossim_uint32 getBitsPerPixel(ossimScalarType scalarType)
Get bits per pixel for a given scalar type.
virtual const ossimIpt & getOutputTileSize() const
Gets the tile size.
bool getWriteBlanksFlag() const
64 bit normalized floating point
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
16 bit unsigned integer (11 bits used)
ossim_int64 getNumberOfTilesHorizontal() const
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
virtual bool writeFile()
Write out the file.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual ossimErrorCode getErrorStatus() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Saves the state of the object.
virtual const void * getBuf() const
virtual bool writeStream()
Method to write the image to a stream.
#define OSSIM_DEFAULT_TILE_HEIGHT
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
ossim_int64 toInt64() const
std::basic_ofstream< char > ofstream
Class for char output file streams.
bool getAlignTilesFlag() const
virtual ossimString getLongName() const
void writeTiffTag(ossim_uint16 tag, ossim_uint16 type, ossim_uint64 count, const T *value, std::streamoff &arrayWritePos)
Writes tiff tag to image file directory(IFD).
ossimDataObjectStatus
Definitions for data object status.
virtual void setPercentComplete(double percentComplete)
ossimWriter()
default constructor
virtual ossimDpt getMetersPerPixel() const
virtual bool isOpen() const
isOpen
virtual void setTileSize(const ossimIpt &tileSize)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
bool writeStreamTtbs()
Writes a tiled tiff band separate to stream.
std::basic_ostream< char > ostream
Base class for char output streams.
const std::string & string() const
16 bit unsigned integer (12 bits used)