49 p_image.format = PNG_FORMAT_RGB;
52 p_image.format = PNG_FORMAT_RGBA;
75 if(fileName ==
""){
return false;}
77 std::cerr <<
"PImagePng::read : file is not a png '"<<fileName<<
"'" << std::endl;
80 if(png_image_begin_read_from_file(&
p_image, fileName.c_str()) == 0){
81 std::cerr <<
"PImagePng::read : cannot read png image '"<<fileName<<
"'" << std::endl;
88 if(
p_image.format == PNG_FORMAT_RGB){
91 }
else if(
p_image.format == PNG_FORMAT_RGBA){
113 if(fileName ==
"" ||
p_buffer == NULL){
return false;}
114 if(png_image_write_to_file(&
p_image, fileName.c_str(), 0,
p_buffer, 0, NULL) != 0){
137 for(png_uint_32 j(0u); j <
p_image.height; ++j){
138 for(png_uint_32 i(0u); i <
p_image.width; ++i){
153 setColor(idxWidth, idxHeight, red, green , blue, alpha);
183 getColor(idxWidth, idxHeight, red, green , blue, alpha);
240 p_image.version = PNG_IMAGE_VERSION;
unsigned char color_t
Type des of a color.
unsigned int NbColorByte
Number of bytes use in the image color (3 for RGB, 4 for RGBA)
bool check_is_png(const PPath &fileName)
Check if the given filename is a png file.
void initialisationPImagePng()
Initialisation function of the class PImagePng.
bool createImage(size_t width, size_t height, PImagePng::ColorType colorType=PImagePng::RGB)
Create an image.
void setColor(size_t idxWidth, size_t idxHeight, color_t red, color_t green, color_t blue)
Set the color of the pixel at (idxWidth, idxHeight)
void fill(color_t red, color_t green, color_t blue, color_t alpha=255)
Fill the image with the given color.
bool read(const PPath &fileName)
Read the given png image.
NbColorByte getNbBytePerPixel() const
Get the number of bytes per pixel.
png_image p_image
Png image.
void clear()
Clear the image and buffer.
PImagePng()
Default constructor of PImagePng.
void copyPImagePng(const PImagePng &other)
Copy function of PImagePng.
png_byte * p_buffer
Buffer use to store the image data.
PImagePng & operator=(const PImagePng &other)
Definition of equal operator of PImagePng.
const png_byte * getData() const
Get the buffer data of the current PImagePng.
PImagePng::ColorType p_colorType
Type of the color of the current image.
NbColorByte p_nbBytePerPixel
Number of bytes per pixel (3 for RGB, 4 for RGBA)
virtual ~PImagePng()
Destructor of PImagePng.
unsigned int getHeight() const
Get the height of the image.
void getColor(size_t idxWidth, size_t idxHeight, color_t &red, color_t &green, color_t &blue) const
Get the color of the pixel at (idxWidth, idxHeight)
bool write(const PPath &fileName)
Write a png file.
unsigned int getWidth() const
Get the width of the image.