35 static const char COMPRESSION_LEVEL_KW[] =
"compression_level";
36 static const char ADD_ALPHA_CHANNEL_KW[] =
"add_alpha_channel";
42 static ossimTrace traceDebug(
"ossimPngWriter:debug");
49 static const char OSSIM_ID[] =
"$Id: ossimPngWriter.cpp 22466 2013-10-24 18:23:51Z dburken $";
55 theOwnsStreamFlag(false),
56 theCompressionLevel(Z_BEST_COMPRESSION),
57 theInterlaceSupport(PNG_INTERLACE_NONE),
58 theCompressionStratagy(Z_FILTERED),
59 thePngFilter(PNG_FILTER_NONE),
63 theAlphaChannelFlag(false),
64 theBackgroundFlag(false),
66 theBackgroundGreen(0),
69 theTransparentFlag(false),
71 theTransparentGreen(0),
72 theTransparentBlue(0),
79 <<
"ossimPngWriter::ossimPngWriter entered" << std::endl;
139 static const char MODULE[] =
"ossimPngWriter::write";
146 << MODULE <<
" DEBUG:\ntheInputConnection is NULL!" << endl;
160 << MODULE <<
" ERROR:" 161 <<
"\nNULL output stream!" 162 <<
"\nReturning from method." << std::endl;
184 << MODULE <<
" ERROR: Area of interest has nans!" 185 <<
"Area of interest: " 187 <<
"\nReturning..." << endl;
195 if (bands != 1 && bands != 3)
198 << MODULE <<
" Range Error:" 199 <<
"\nInvalid number of input bands! Must be one or three." 200 <<
"\nInput bands = " << bands
201 <<
"\nReturning from method." << endl;
221 <<
"\nData is being scaled to 8 bit!" 222 <<
"\nOriginal scalar type: " 224 getEntryString(inputScalar).c_str()
244 bool swapFlag =
doSwap(outputScalar);
252 ossim_int32 bytesPerRow = bands*imageWidth*bytesPerPixel;
270 bytesPerRow += imageWidth*bytesPerPixel;
285 png_structp pp = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
286 png_infop info = png_create_info_struct (pp);
288 if ( setjmp( png_jmpbuf(pp) ) )
300 png_set_write_fn( pp,
313 png_set_filter(pp, PNG_FILTER_TYPE_BASE, PNG_FILTER_NONE);
314 png_set_compression_strategy(pp, Z_DEFAULT_STRATEGY);
319 png_set_compression_strategy(pp, Z_FILTERED);
325 << MODULE <<
" DEBUG: " 326 <<
"\nInput scalar: " 328 getEntryString(inputScalar).c_str()
329 <<
"\nOutput scalar: " 331 getEntryString(outputScalar).c_str()
333 <<
"\nSwap flag: " << swapFlag
334 <<
"\nbytesPerRow: " << bytesPerRow
335 <<
"\nimageWidth: " << imageWidth
336 <<
"\nimageHeight: " << imageHeight
338 <<
"\ngetColorType(bands): " << colorType
349 PNG_COMPRESSION_TYPE_DEFAULT,
350 PNG_FILTER_TYPE_DEFAULT);
355 png_write_info(pp, info);
364 <<
"Interlace support not implemented yet!" 385 buf_rect.
set_lry(buf_rect.
ul().
y + tileHeight - 1);
388 void* bipBuf = bipTile->
getBuf();
407 min( (buf_rect.
lr().
y-buf_rect.
ul().
y+1),
414 <<
"buf_rect: " << buf_rect
415 <<
"lines_to_copy: " << lines_to_copy << endl;
424 imageWidth*lines_to_copy*bands);
429 for (
ossim_int32 line=0; line<lines_to_copy; ++line)
431 png_bytep rowp = (png_bytep)&buf[buf_offset];
432 png_write_row(pp, rowp);
433 buf_offset += bytesPerRow;
438 double dPercentComplete = (100.0*(i+1)) / maxY;
447 png_write_end(pp, 0);
448 png_destroy_write_struct(&pp, &info);
477 fp->write((
char*)data, length);
487 const char* prefix)
const 490 ADD_ALPHA_CHANNEL_KW,
502 value = kwl.
find(prefix, ADD_ALPHA_CHANNEL_KW);
574 if ( (imageType ==
"ossim_png") || (imageType ==
"image/png") )
589 if (property->
getName() == COMPRESSION_LEVEL_KW)
594 if (property->
getName() == ADD_ALPHA_CHANNEL_KW)
606 if (name == COMPRESSION_LEVEL_KW)
618 else if (name == ADD_ALPHA_CHANNEL_KW)
628 propertyNames.push_back(
ossimString(COMPRESSION_LEVEL_KW));
629 propertyNames.push_back(
ossimString(ADD_ALPHA_CHANNEL_KW));
769 png_color_16 transparent;
774 png_set_tRNS( pp, info, NULL, 0, &transparent );
782 png_color_16 background;
787 png_set_bKGD( pp, info, &background );
807 png_convert_from_time_t(&modtime, t);
808 png_set_tIME(pp, info, &modtime);
836 while ( (s != 0x0001) && (s >= max16) )
844 png_color_8* sig_bit =
new png_color_8;
846 sig_bit->green = bits;
847 sig_bit->blue = bits;
848 sig_bit->gray = bits;
849 sig_bit->alpha = bits;
850 png_set_sBIT(pp, info, sig_bit);
890 colorType = PNG_COLOR_TYPE_GRAY_ALPHA;
894 colorType = PNG_COLOR_TYPE_RGB_ALPHA;
901 colorType = PNG_COLOR_TYPE_GRAY;
936 case Z_NO_COMPRESSION:
944 case Z_BEST_COMPRESSION:
961 if(s ==
"z_no_compression")
965 else if(s ==
"z_best_speed")
969 else if(s ==
"z_best_compression")
973 else if(s ==
"z_default_compression")
986 <<
"\nossimPngWriter::setCompressionLevel DEBUG" 987 <<
"passed in level: " << level.
c_str()
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
ossim_uint16 theTransparentGreen
void set_uly(ossim_int32 y)
virtual void valueToString(ossimString &valueResult) const =0
virtual void slaveProcessTiles()
RTTI_DEF1(ossimPngWriter, "ossimPngWriter", ossimImageFileWriter) static const char COMPRESSION_LEVEL_KW[]
ossim_uint16 theBackgroundBlue
bool theScaleToEightBitFlag
void writeTransparentColorChunk(png_structp pp, png_infop info)
Write transparent color chunk (tRNS) Location: Multiple:
void writePhysicalScale(png_structp pp, png_infop info)
Write physical scale (sCAL) Location: before first IDAT Multiple: no.
bool theTimeFlag
Time support, either on or off.
void writeLatinTextChunk(png_structp pp, png_infop info)
Write any text (tEXt, zTXt).
virtual void computeAlphaChannel()
Computes the alpha channel.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual void setImageRectangle(const ossimIrect &rect)
virtual ossimString getLongName() const
ossimString theOutputImageType
bool needsAborting() const
virtual bool isMaster() const
Represents serializable keyword/value map.
ossim_int32 theInterlaceSupport
Interlace support: PNG_INTERLACE_ADAM7 PNG_INTERLACE_NONE.
virtual void setToStartOfSequence()
virtual ossimString getClassName() const
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Will set the property whose name matches the argument "property->getName()".
static const ossimErrorCode OSSIM_OK
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
void writeBackgroundColorChunk(png_structp pp, png_infop info)
Write background color chunk (bKGD) Location: After PLTE, before first IDAT.
const char * find(const char *key) const
bool theBackgroundFlag
For background support.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimIrect theAreaOfInterest
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saves the state of the object.
static ossimString toString(bool aValue)
Numeric to string methods.
void setAlphaChannelFlag(bool flag)
Set the writer to add an alpha channel to the output png image.
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
void getImageTypeList(std::vector<ossimString>& imageTypeList)const
void writeImageOffset(png_structp pp, png_infop info)
Write image offset (oFFs) Location: before first IDAT Multiple: no.
const ossimIpt & ul() const
OSSIM_DLL ossimByteOrder byteOrder()
virtual bool writeStream()
Method to write the image to a stream.
ossim_uint16 theTransparentGray
void addConstraint(const ossimString &value)
void writeFractalParameters(png_structp pp, png_infop info)
Write fractal parameters (fRAc) Location: anywhere Multiple: yes.
Pure virtual base class for image file writers.
unsigned short ossim_uint16
virtual ossimString getExtension() const
Returns a 3-letter extension from the image type descriptor (theOutputImageType) that can be used for...
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void setProcessStatus(ossimProcessStatus processStatus)
bool setCompressionLevel(const ossimString &level)
Set the png compression level from a string.
ossim_uint16 theBackgroundGray
virtual void initialize()
Initialize the data buffer.
static void pngFlush(png_structp png_ptr)
Callback method for a flush.
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
std::ostream * theOutputStream
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Pushes this's names onto the list of property names.
virtual void setAreaOfInterest(const ossimIrect &areaOfInterest)
void writeInternationalTextChunk(png_structp pp, png_infop info)
Write any text (iTXt).
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
void writeSuggestedPalette(png_structp pp, png_infop info)
Write suggested palette (sPLT) Location: before first IDAT Multiple: yes.
ossimRefPtr< ossimImageSourceSequencer > theInputConnection
ossim_uint16 theBackgroundRed
ossimString getCompressionLevel() const
Get the png compression level as a string.
virtual bool isOpen() const
ossimFilename theFilename
ossim_int32 theCompressionLevel
Compression level from zlib.h: Z_NO_COMPRESSION 0 Z_BEST_SPEED 1 Z_BEST_COMPRESSION 9 Z_DEFAULT_COMPR...
bool isLutEnabled() const
unsigned int ossim_uint32
OSSIM_DLL ossim_uint32 scalarSizeInBytes(ossimScalarType scalarType)
const ossimIpt & lr() const
static ossimString downcase(const ossimString &aString)
void writePixelCalibration(png_structp pp, png_infop info)
Write pixel calibration (pCAL) Location: after PLTE, before first IDAT Multiple: no.
virtual void unloadTileToBipAlpha(void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
virtual void unloadTile(void *dest, const ossimIrect &dest_rect, ossimInterleaveType il_type) const
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual void initialize()
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
bool theAlphaChannelFlag
For alpha channel support.
virtual bool writeFile()
Writes the file to disk or a stream.
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
16 bit unsigned integer (11 bits used)
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
bool getAlphaChannelFlag(void) const
Retrieve the writer's setting for whether or not to add an alpha channel to the output png image...
bool hasImageType(const ossimString &imageType) const
bool hasImageType(const ossimString& imageType) const
bool theGammaFlag
For gamma support.
void writeHistogram(png_structp pp, png_infop info)
Write histogram (hIST) Location: after PLTE, before first IDAT Multiple: no.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
void set_lry(ossim_int32 y)
virtual ossimErrorCode getErrorStatus() const
ossim_int32 getColorType(ossim_int32 bands) const
Get the png color type.
virtual void setWriteExternalGeometryFlag(bool flag)
void writeGammaChunk(png_structp pp, png_infop info)
Write gamm chunk (gAMMA) Location: Before PLTE, before first IDAT.
virtual const void * getBuf() const
bool theTransparentFlag
For transparent color support.
virtual ~ossimPngWriter()
virtual ossimString getShortName() const
void writeOptionalChunks(png_structp pp, png_infop info)
writes optionial chunks.
void writeTimeStampChunk(png_structp pp, png_infop info)
Write time stamp chunk (tIME).
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
ossim_uint16 theTransparentBlue
const ossimIrect & getAreaOfInterest() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
std::basic_ofstream< char > ofstream
Class for char output file streams.
ossim_uint16 theBackgroundGreen
virtual void setPercentComplete(double percentComplete)
void writeSignificantBits(png_structp pp, png_infop info)
Write significant bits (sBIT) Location: before PLTE and first IDAT Multiple: no.
ossim_uint16 theTransparentRed
void writePhysicalPixelDimensions(png_structp pp, png_infop info)
Write physical pixel dimensions (pHYs) Location: before first IDAT Multiple: no.
ossim_int32 getBitDepth(ossimScalarType outputScalar) const
unsigned char ossim_uint8
virtual bool setOutputStream(std::ostream &stream)
Sets the output stream to write to.
bool doSwap(ossimScalarType outputScalar) const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
ossim_int64 getNumberOfTilesVertical() const
std::basic_ostream< char > ostream
Base class for char output streams.
const ossimString & getName() const
static void pngWriteData(png_structp png_ptr, png_bytep data, png_size_t length)
Callback method for writing to stream.