Usage
Installation
Copy pnm.hpp
to your favorite location. Because pnm is a header-only, you need no build before use it.
example
Pixel types
pnm supports 3 pixel types that correspond binary, grayscale, and RGB color.
binary and grayscale pixel type has a member variable value
. RGB pixel type has 3 member variables named red
, blue
, and green
, respectively.
Image types
pnm::image
is a class that represents image. It requires pixel format as a template parameter.
You can access each pixel by using operator[]
and at()
in the same way as nested vector. Also, you can access to lines composed by pixels by lines()
.
The constructors accepts (width, height)
, (width, height, pixel)
, (width, height, std::vector<pixel>)
, and (std::vector<std::vector<pixel>>)
.
IO
read()
and read_(pbm|pgm|ppm)
functions read a file header and automatically detects the file format. read()
function receives pixel_type
that you want to get(By default, it is rgb_pixel
).
Note that when you pass a pixel_type
that is different from actual one contained in the file, read()
converts the pixel_type
if it is not narrowing-conversion
(for example, conversion from bit_pixel
to rgb_pixel
is allowed. On the other hand, the opposite conversion is not allowed).
write
function writes the image file into a specific file. You can select a format to write out by passing an enum value pnm::format::ascii
or pnm::format::binary
.
Last updated
Was this helpful?