114 lines
2.8 KiB
C++
114 lines
2.8 KiB
C++
#include "PngInfo.h"
|
|
|
|
std::string PngInfo::toString(ColorType colorType) const
|
|
{
|
|
switch(colorType)
|
|
{
|
|
case ColorType::GREYSCALE:
|
|
return "GREYSCALE";
|
|
case ColorType::RGB:
|
|
return "RGB";
|
|
case ColorType::PALETTE:
|
|
return "PALETTE";
|
|
case ColorType::GREYSCALE_ALPHA:
|
|
return "GREYSCALE_ALPHA";
|
|
case ColorType::RGB_ALPHA:
|
|
return "RGB_ALPHA";
|
|
default:
|
|
return "UNKNOWN";
|
|
}
|
|
}
|
|
|
|
unsigned PngInfo::getNumChannels() const
|
|
{
|
|
switch(mColorType)
|
|
{
|
|
case ColorType::GREYSCALE:
|
|
return 1;
|
|
case ColorType::RGB:
|
|
return 3;
|
|
case ColorType::PALETTE:
|
|
return 1;
|
|
case ColorType::GREYSCALE_ALPHA:
|
|
return 2;
|
|
case ColorType::RGB_ALPHA:
|
|
return 4;
|
|
default:
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
std::string PngInfo::toString(CompressionMethod method) const
|
|
{
|
|
switch(method)
|
|
{
|
|
case CompressionMethod::DEFLATE:
|
|
return "DEFLATE";
|
|
default:
|
|
return "UNKNOWN";
|
|
}
|
|
}
|
|
|
|
std::string PngInfo::toString(FilterMethod method) const
|
|
{
|
|
switch(method)
|
|
{
|
|
case FilterMethod::ADAPTIVE:
|
|
return "ADAPTIVE";
|
|
default:
|
|
return "UNKNOWN";
|
|
}
|
|
}
|
|
|
|
std::string PngInfo::toString(InterlaceMethod method) const
|
|
{
|
|
switch(method)
|
|
{
|
|
case InterlaceMethod::NONE:
|
|
return "NONE";
|
|
case InterlaceMethod::ADAM7:
|
|
return "ADAM7";
|
|
default:
|
|
return "UNKNOWN";
|
|
}
|
|
}
|
|
|
|
bool PngInfo::bitDepthIsValid(ColorType colorType, unsigned char bitDepth) const
|
|
{
|
|
switch(colorType)
|
|
{
|
|
case ColorType::GREYSCALE:
|
|
return (bitDepth == 1) || (bitDepth == 2) || (bitDepth == 4) || (bitDepth == 8) || (bitDepth == 16) ;
|
|
case ColorType::RGB:
|
|
return (bitDepth == 8) || (bitDepth == 16);
|
|
case ColorType::PALETTE:
|
|
return (bitDepth == 1) || (bitDepth == 2) || (bitDepth == 4) || (bitDepth == 8);
|
|
case ColorType::GREYSCALE_ALPHA:
|
|
return (bitDepth == 8) || (bitDepth == 16);
|
|
case ColorType::RGB_ALPHA:
|
|
return (bitDepth == 8) || (bitDepth == 16);
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool PngInfo::compressionMethodIsValid(unsigned char method)
|
|
{
|
|
return method == 0;
|
|
}
|
|
|
|
bool PngInfo::filterMethodIsValid(unsigned char method)
|
|
{
|
|
return method == 0;
|
|
}
|
|
|
|
std::string PngInfo::toString() const
|
|
{
|
|
std::stringstream sstr;
|
|
sstr << "PngInfo" << "\n";
|
|
sstr << "colorType: " << toString(mColorType) << "\n";
|
|
sstr << "compressionMethod: " << toString(mCompressionMethod) << "\n";
|
|
sstr << "filterMethod: " << toString(mFilterMethod) << "\n";
|
|
sstr << "interlaceMethod: " << toString(mInterlaceMethod) << "\n";
|
|
return sstr.str();
|
|
}
|