36 static const std::string USE_ALPHA_KW =
"use_alpha";
40 #ifdef OSSIM_ID_ENABLED 41 static const char OSSIM_ID[] =
"$Id: ossimPngReader.cpp 23355 2015-06-01 23:55:15Z dburken $";
44 static ossimTrace traceDebug(
"ossimPngReader:degug");
52 m_lineBufferSizeInBytes(0),
54 m_bufferRect(0, 0, 0, 0),
55 m_imageRect(0, 0, 0, 0),
56 m_numberOfInputBands(0),
57 m_numberOfOutputBands(0),
58 m_bytePerPixelPerBand(1),
63 m_pngColorType(PNG_COLOR_TYPE_GRAY),
68 m_readMode(ossimPngReadUnknown),
71 m_useAlphaChannelFlag(false)
76 <<
"ossimPngReader::ossimPngReader entered..." << std::endl;
78 #ifdef OSSIM_ID_ENABLED 80 <<
"OSSIM_ID: " << OSSIM_ID << endl;
155 <<
"ossimPngReader::allocate DEBUG:" 260 if (!tile || !
m_str)
return;
273 <<
"tiles high: " << number_of_cache_tiles
280 for (
int tileIdx = 0; tileIdx < number_of_cache_tiles; ++tileIdx)
286 if (tempTile.
valid())
395 const char* prefix)
const 397 std::string p = ( prefix ? prefix :
"" );
399 kwl.
addPair( p, USE_ALPHA_KW, v,
true );
426 if ( property.
valid() )
431 property->valueToString(s);
444 if ( name.
string() == USE_ALPHA_KW )
457 propertyNames.push_back(
ossimString(USE_ALPHA_KW) );
463 static const char MODULE[] =
"ossimPngReader::open()";
488 result =
open( str );
495 <<
"ossimPngReader::open() exit status: " << (result?
"true":
"false") <<
"\n";
502 const std::string& connectionString )
504 bool result =
open( str );
523 str->seekg( 0, std::ios_base::beg );
549 <<
"ossimPngReader::open NOTICE:\n" 550 <<
"Could not open stream!\n";
570 if (reduced_res_level == 0)
584 if (reduced_res_level == 0)
671 m_pngReadPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
680 <<
"Error while reading. File corrupted? " 688 m_str->seekg( 0, std::ios_base::beg );
696 (png_voidp)
m_str.get(),
710 bool expandFlag =
false;
729 bool packingFlag =
false;
777 str.read( (
char*)sig, 8);
780 if ( png_sig_cmp(sig, 0, 8) == 0 )
822 m_pngReadPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
839 (png_voidp)
m_str.get(),
917 bool expandFlag =
false;
936 bool packingFlag =
false;
977 case PNG_COLOR_TYPE_RGB:
983 case PNG_COLOR_TYPE_RGB_ALPHA:
996 case PNG_COLOR_TYPE_GRAY:
1002 case PNG_COLOR_TYPE_GRAY_ALPHA:
1015 case PNG_COLOR_TYPE_PALETTE:
1046 <<
"ossimPngReader::initReader DEBUG:" 1049 <<
"\nm_pngColorType: " 1056 <<
"\npalette expansion: " 1057 << (expandFlag?
"on":
"off")
1058 <<
"\npacking (1,2,4 bit to one byte): " 1059 << (packingFlag?
"on":
"off")
1080 <<
"ossimPngReader::readPngVersionInfo\nCompiled with:" 1081 <<
"\nlibpng " << PNG_LIBPNG_VER_STRING
1082 <<
" using libpng " << PNG_LIBPNG_VER
1083 <<
"\nzlib " << ZLIB_VERSION
" using zlib " 1084 << zlib_version << std::endl;
1125 png_color_8p sig_bit;
1130 <<
"ossimPngReader::setMaxPixelValue DEBUG:" 1131 <<
"\nsig_bit->red: " << int(sig_bit->red)
1132 <<
"\nsig_bit->green: " << int(sig_bit->green)
1133 <<
"\nsig_bit->blue: " << int(sig_bit->blue)
1134 <<
"\nsig_bit->gray: " << int(sig_bit->gray)
1135 <<
"\nsig_bit->alpa: " << int(sig_bit->alpha)
1140 case PNG_COLOR_TYPE_RGB:
1145 case PNG_COLOR_TYPE_RGB_ALPHA:
1151 case PNG_COLOR_TYPE_GRAY:
1154 case PNG_COLOR_TYPE_GRAY_ALPHA:
1158 case PNG_COLOR_TYPE_PALETTE:
1218 for (
ossim_uint32 sample = 0; sample < SAMPLES; ++sample)
1222 dst[band][bufIdx] = src[index];
1281 for (
ossim_uint32 sample = 0; sample < SAMPLES; ++sample)
1286 p[band] = src[srcIdx++];
1290 alpha = src[srcIdx++];
1291 alpha = alpha / denominator;
1297 dst[band][dstIdx] = p[band];
1300 else if (alpha == 0.0)
1304 dst[band][dstIdx] =
static_cast<T
>(NULL_PIX);
1316 static_cast<T
>( (f>=MIN_PIX) ?
1317 ( (f<=MAX_PIX) ? f : MAX_PIX ) :
1322 dst[band][dstIdx] =
static_cast<T
>(NULL_PIX);
1339 str->read( (
char*)data, length );
virtual void deleteCache(ossimAppFixedCacheId cacheId)
virtual ossim_uint32 getWidth() const
virtual ossim_uint32 getImageTileWidth() const
Returns the tile width of the image or 0 if the image is not tiled.
virtual bool isSourceEnabled() const
void fillTile(const ossimIrect &clip_rect, ossimImageData *tile)
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
Get propterty method.
ossimRefPtr< ossimImageGeometry > theGeometry
virtual const ossim_float64 * getMaxPix() const
void destroy()
Free tile and buffer memory.
bool isOpen() const
Derived classes must implement this method to be concrete.
virtual ossim_uint32 getNumberOfBands() const
ossimFilename theImageFile
virtual void setImageRectangle(const ossimIrect &rect)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
Returns a pointer to a tile given an origin representing the upper left corner of the tile to grab fr...
std::shared_ptr< ossim::istream > m_str
void allocate()
Initializes tiles and buffers.
void copyLines(T dummy, ossim_uint32 stopLine)
Represents serializable keyword/value map.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
virtual ossimIrect getImageRectangle(ossim_uint32 reduced_res_level=0) const
Returns the zero based image rectangle for the reduced resolution data set (rrds) passed in...
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Get propterty names.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel=0) const =0
Pure virtual, derived classes must implement.
ossimAppFixedTileCache::ossimAppFixedCacheId m_cacheId
ossim_uint32 height() const
ossim_uint8 * m_lineBuffer
bool initReader()
Initializes this reader from libpng m_pngPtr and infoPtr.
static ossimString toString(bool aValue)
Numeric to string methods.
OSSIM_DLL void defaultTileSize(ossimIpt &tileSize)
const ossimIpt & ul() const
bool checkSignature(std::istream &str)
std::vector< ossim_float64 > m_maxPixelValue
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
OSSIM_DLL ossimByteOrder byteOrder()
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Set propterty method.
static StreamFactoryRegistry * instance()
ossimRefPtr< ossimImageData > m_cacheTile
unsigned short ossim_uint16
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
ossim_uint32 m_lineBufferSizeInBytes
virtual ossim_uint32 getNumberOfLines(ossim_uint32 reduced_res_level=0) const
Returns the number of lines in the image.
void ref() const
increment the reference count by one, indicating that this object has another pointer which is refere...
virtual void initialize()
Initialize the data buffer.
ossimString getPngColorTypeString() const
static ossimAppFixedTileCache * instance(ossim_uint32 maxSize=0)
virtual ossimObject * dup() const
virtual bool isValidRLevel(ossim_uint32 resLevel) const
Determines if the passed in reslution level is valid.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool completely_within(const ossimIrect &rect) const
ossimPngReader()
default constructor
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
ossimPngReadMode m_readMode
virtual bool getOverviewTile(ossim_uint32 resLevel, ossimImageData *result)
Method to get an overview tile.
static ossimImageDataFactory * instance()
virtual ossimDataObjectStatus validate() const
std::string::size_type size() const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Gets the image geometry.
bool toBool() const
String to numeric methods.
ossim_uint32 m_numberOfInputBands
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
virtual ossim_uint32 getTileHeight() const
Returns the height of the output tile.
virtual ossimIrect getImageRectangle() const
void copyLinesWithAlpha(T, ossim_uint32 stopLine)
bool m_useAlphaChannelFlag
virtual ossimScalarType getOutputScalarType() const
Returns the output pixel type of the tile source.
virtual void close()
Deletes the overview and clears the valid image vertices.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossim_uint32 width() const
void initImageParameters(ossimImageGeometry *geom) const
Convenience method to set things needed in the image geometry from the image handler.
ossimIrect clipToRect(const ossimIrect &rect) const
ossim_int8 m_pngColorType
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
void unref() const
decrement the reference count by one, indicating that a pointer to this object is referencing it...
virtual ossimString getShortName() const
virtual ~ossimPngReader()
virtual destructor
void setMaxPixelValue()
the max pixel value.
virtual const ossim_float64 * getMinPix() const
virtual ossimString getLongName() const
virtual ossimRefPtr< ossimImageGeometry > getExternalImageGeometry() const
Returns the image geometry object associated with this tile source or NULL if non defined...
void set_lrx(ossim_int32 x)
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual ossimString getClassName() const
virtual void makeBlank()
Initializes data to null pixel values.
virtual void completeOpen()
Will complete the opening process.
16 bit unsigned integer (11 bits used)
std::basic_istream< char > istream
Base class for char input streams.
ossim_uint32 m_bytePerPixelPerBand
ossimRefPtr< ossimImageHandler > theOverview
ossim_uint32 m_numberOfOutputBands
This class defines an abstract Handler which all image handlers(loaders) should derive from...
virtual ossim_uint32 getImageTileHeight() const
Returns the tile width of the image or 0 if the image is not tiled.
ossimRefPtr< ossimImageData > m_tile
virtual const void * getBuf() const
virtual void close()
Close method.
void restart()
Method to restart reading from the beginning (for backing up).
virtual ossim_uint32 getTileWidth() const
Returns the width of the output tile.
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
virtual bool open()
open method.
virtual ossim_uint32 getNumberOfInputBands() const
Returns the number of bands in the image.
void stretchToTileBoundary(const ossimIpt &tileWidthHeight)
ossim_int32 m_interlacePasses
ossim_uint32 m_currentRow
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const =0
Pure virtual, derived classes must implement.
static void pngReadData(png_structp png_ptr, png_bytep data, png_size_t length)
Callback method for reading from a stream.
#define RTTI_DEF1(cls, name, b1)
virtual void setScalarType(ossimScalarType type)
See ossimScalarType in ossimConstants for a full list.
int completely_within(extent_type extent1, extent_type extent2)
void readPngVersionInfo()
unsigned char ossim_uint8
png_infop m_pngReadInfoPtr
ossimRefPtr< ossimImageData > addTile(ossimAppFixedCacheId cacheId, ossimRefPtr< ossimImageData > data, bool duplicateData=true)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossimScalarType m_outputScalarType
const ossimString & getName() const
void set_ulx(ossim_int32 x)
const std::string & string() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 reduced_res_level=0) const
Returns the number of samples in the image.
bool readPngInit()
Performs signature check and initializes png_structp and png_infop.