Skip to content
/ PNGImg Public

Simple low level C++ library to load/save PNG images, with some support for text metadata.

License

Notifications You must be signed in to change notification settings

Arnache/PNGImg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PNGImg

Description

PNGImg is a simple C++ class for saving/loading png images, with support of textual comments in the metadata.

Its interface basically has function members load() and a save() and settings are set via variable members.

There is no image transformation/filtering or whatsoever. The PNG image is decoded to/encoded from a memory buffer* which is in raw format. It is the user's task to interpret this raw format according to the PNG specification. For convenience, we include a description of the raw format in the manual.
*: in this implementation, a C++ vector
It is also the user's responsibility to send valid settings and data to PNGImg.

Disclaimer

PNGImg is provided "as is" with absolutely no guarrantee of any sort. In now way the author can be liable for any damage it may induce.

Example

Computer generate an image and save it in a linear color space (gamma=1) together with a textual comment.

#include "PNGImg.cpp"

int main() {

  int width=300;
  int height=200;

  PNGImg img(width,height,8,PNG_COLOR_TYPE_RGB);

  // assign one text comment
  PNGImg::pngText t1;
  t1.type = PNG_TEXT_COMPRESSION_zTXt;
  t1.key="Comment";
  t1.text="Coucou ;)";
  img.text.push_back(t1);

  // the size of img.data is not set by img's constructor, so we set it here
  img.data.resize(width*height*3);

  // fill img.data with computer generated values
  int k;
  for(int li=0; li<height; li++) {
    for(int co=0; co<width; co++) {
      k=3*(width*li+co);
      img.data[k+0] = li; // red
      img.data[k+1] = co; // green
      img.data[k+2] = li+co; // blue
    }
  }

  // by default, images are encoded in sRGB; below we modify this to a linear color space
  img.has_sRGB = false;
  img.has_gamma = true;
  img.decoding_gamma = 1.0 ;

  img.saveImage("test.png");
}

About

Simple low level C++ library to load/save PNG images, with some support for text metadata.

Resources

License

Stars

Watchers

Forks

Packages

No packages published