Panda3D

Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
PNMImageHeader Class Reference

This is the base class of PNMImage, PNMReader, and PNMWriter. More...

`#include "pnmImageHeader.h"`

Inheritance diagram for PNMImageHeader:

## Classes
class | Histogram
class | PixelSpec
class | PixelSpecCount

## Public Types
enum | ColorType { CT_invalid = 0 , CT_grayscale = 1 , CT_two_channel = 2 , CT_color = 3 , CT_four_channel = 4 }
typedef pmap< PixelSpec, int > | HistMap
typedef pvector< PixelSpec > | Palette
typedef pvector< PixelSpecCount > | PixelCount

## Public Member Functions
| PNMImageHeader (const PNMImageHeader &copy)
ColorSpace | get_color_space () const
ColorType | get_color_type () const
| Returns the image type of the image, as an enumerated value.
std::string | get_comment () const
xelval | get_maxval () const
int | get_num_channels () const
LVecBase2i | get_size () const
PNMFileType * | get_type () const
int | get_x_size () const
| Returns the number of pixels in the X direction.
int | get_y_size () const
| Returns the number of pixels in the Y direction.
bool | has_alpha () const
| Returns true if the image includes an alpha channel, false otherwise.
bool | has_type () const
bool | is_grayscale () const
| Returns false if the image is a full-color image, and has red, green, and blue components; true if it is a grayscale image and has only a gray component.
PNMReader * | make_reader (const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true) const
| Returns a newly-allocated PNMReader of the suitable type for reading from the indicated image filename, or NULL if the filename cannot be read for some reason.
PNMReader * | make_reader (std::istream *file, bool owns_file=true, const Filename &filename=Filename(), std::string magic_number=std::string(), PNMFileType *type=nullptr, bool report_unknown_type=true) const
| Returns a newly-allocated PNMReader of the suitable type for reading from the already-opened image file, or NULL if the file cannot be read for some reason.
PNMWriter * | make_writer (const Filename &filename, PNMFileType *type=nullptr) const
| Returns a newly-allocated PNMWriter of the suitable type for writing an image to the indicated filename, or NULL if the filename cannot be written for some reason.
PNMWriter * | make_writer (std::ostream *file, bool owns_file=true, const Filename &filename=Filename(), PNMFileType *type=nullptr) const
| Returns a newly-allocated PNMWriter of the suitable type for writing to the already-opened image file, or NULL if the file cannot be written for some reason.
void | operator= (const PNMImageHeader &copy)
void | output (std::ostream &out) const
bool | read_header (const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true)
| Opens up the image file and tries to read its header information to determine its size, number of channels, etc.
bool | read_header (std::istream &data, const std::string &filename=std::string(), PNMFileType *type=nullptr, bool report_unknown_type=true)
| Reads the image header information only from the indicated stream.
void | set_comment (const std::string &comment)
void | set_type (PNMFileType *type)
| Sets the file type of this PNMImage.

## Static Public Member Functions
static bool | has_alpha (ColorType color_type)
| This static variant of has_alpha() returns true if the indicated image type includes an alpha channel, false otherwise.
static bool | is_grayscale (ColorType color_type)
| This static variant of is_grayscale() returns true if the indicated image type represents a grayscale image, false otherwise.
static bool | read_magic_number (std::istream *file, std::string &magic_number, int num_bytes)
| Ensures that the first n bytes of the file are read into magic_number.

## Public Attributes
| get_color_space
| Returns the color space that the image is encoded in, or CS_unspecified if unknown.
| get_comment
| Gets the user comment from the file.
| get_maxval
| Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image.
| get_num_channels
| Returns the number of channels in the image.
| get_size
| Returns the number of pixels in each direction.
| get_type
| If the file type is known (e.g.
| has_type
| Returns true if the PNMImageHeader knows what type it is, false otherwise.
| set_comment
| Writes a user comment string to the image (header).

## Detailed Description

This is the base class of PNMImage, PNMReader, and PNMWriter.

It encapsulates all the information associated with an image that describes its size, number of channels, etc; that is, all the information about the image except the image data itself. It's the sort of information you typically read from the image file's header.

Definition at line 40 of file pnmImageHeader.h.

## Member Typedef Documentation

## ◆ HistMap

typedef pmap<PixelSpec, int> PNMImageHeader::HistMap

Definition at line 162 of file pnmImageHeader.h.

## ◆ Palette

typedef pvector<PixelSpec> PNMImageHeader::Palette

Definition at line 164 of file pnmImageHeader.h.

## ◆ PixelCount

typedef pvector<PixelSpecCount> PNMImageHeader::PixelCount

Definition at line 163 of file pnmImageHeader.h.

## Member Enumeration Documentation

## ◆ ColorType

enum PNMImageHeader::ColorType

Definition at line 50 of file pnmImageHeader.h.

## Constructor & Destructor Documentation

## ◆ PNMImageHeader() [1/2]

PNMImageHeader::PNMImageHeader | ( |  | ) |
| inline

Definition at line 17 of file pnmImageHeader.I.

## ◆ PNMImageHeader() [2/2]

PNMImageHeader::PNMImageHeader | ( | const PNMImageHeader & | copy | ) |
| inline

Definition at line 30 of file pnmImageHeader.I.

## ◆ ~PNMImageHeader()

PNMImageHeader::~PNMImageHeader | ( |  | ) |
| inline

Definition at line 58 of file pnmImageHeader.I.

## Member Function Documentation

## ◆ get_color_type()

PNMImageHeader::ColorType PNMImageHeader::get_color_type | ( |  | ) | const
| inline

Returns the image type of the image, as an enumerated value.

This is really just the number of channels cast to the enumerated type.

Definition at line 66 of file pnmImageHeader.I.

Referenced by osxGraphicsPipe::create_cg_image(), has_alpha(), is_grayscale(), and PNMImage::set_color_type().

## ◆ get_x_size()

int PNMImageHeader::get_x_size | ( |  | ) | const
| inline

Returns the number of pixels in the X direction.

This is one more than the largest allowable X coordinate.

Definition at line 143 of file pnmImageHeader.I.

Referenced by BulletHeightfieldShape::BulletHeightfieldShape(), PNMImage::alpha_fill_val(), Texture::consider_rescale(), PNMImage::copy_channel(), PNMImage::copy_channel_bits(), osxGraphicsPipe::create_cg_image(), PNMImage::do_fill_distance(), PNMImage::expand_border(), PNMImage::fill_distance_inside(), PNMImage::fill_distance_outside(), PNMImage::fill_val(), PfmFile::forward_distort(), PNMImage::get_read_x_size(), PfmFile::indirect_1d_lookup(), PNMImage::indirect_1d_lookup(), PfmFile::load(), PNMImage::make_grayscale(), PNMTextGlyph::place(), PNMTextGlyph::place(), PNMImage::premultiply_alpha(), PfmTrans::process_pfm(), PT(), PfmFile::quick_filter_from(), PNMImage::quick_filter_from(), ImageFile::read(), PNMImage::remix_channels(), PNMImage::rescale(), PfmFile::reverse_distort(), PfmVizzer::set_aux_pfm(), PNMImage::set_color_type(), SourceTextureImage::set_header(), GeoMipTerrain::set_heightfield(), GeoMipTerrain::set_heightfield(), PNMImage::set_maxval(), PfmFile::store(), PfmFile::store_mask(), PfmFile::store_mask(), PNMImage::threshold(), PNMImage::unfiltered_stretch_from(), PNMImage::unpremultiply_alpha(), ImageFile::write(), PNMImage::write(), and PNMFileTypePfm::Writer::write_pfm().

## ◆ get_y_size()

int PNMImageHeader::get_y_size | ( |  | ) | const
| inline

Returns the number of pixels in the Y direction.

This is one more than the largest allowable Y coordinate.

Definition at line 152 of file pnmImageHeader.I.

Referenced by BulletHeightfieldShape::BulletHeightfieldShape(), PNMImage::alpha_fill_val(), Texture::consider_rescale(), PNMImage::copy_channel(), PNMImage::copy_channel_bits(), osxGraphicsPipe::create_cg_image(), PNMImage::do_fill_distance(), PNMImage::expand_border(), PNMImage::fill_distance_inside(), PNMImage::fill_distance_outside(), PNMImage::fill_val(), PfmFile::forward_distort(), PNMImage::get_read_y_size(), PfmFile::indirect_1d_lookup(), PNMImage::indirect_1d_lookup(), PfmFile::load(), PNMImage::make_grayscale(), PNMTextGlyph::place(), PNMTextGlyph::place(), PNMImage::premultiply_alpha(), PfmTrans::process_pfm(), PT(), PfmFile::quick_filter_from(), PNMImage::quick_filter_from(), ImageFile::read(), PNMImage::remix_channels(), PNMImage::rescale(), PfmFile::reverse_distort(), PfmVizzer::set_aux_pfm(), PNMImage::set_color_type(), SourceTextureImage::set_header(), GeoMipTerrain::set_heightfield(), GeoMipTerrain::set_heightfield(), PNMImage::set_maxval(), PfmFile::store(), PfmFile::store_mask(), PfmFile::store_mask(), PNMImage::threshold(), PNMImage::unfiltered_stretch_from(), PNMImage::unpremultiply_alpha(), ImageFile::write(), PNMImage::write(), and PNMFileTypePfm::Writer::write_pfm().

## ◆ has_alpha() [1/2]

bool PNMImageHeader::has_alpha | ( |  | ) | const
| inline

Returns true if the image includes an alpha channel, false otherwise.

Unlike is_grayscale(), if this returns false it is an error to call any of the functions accessing the alpha channel.

Definition at line 115 of file pnmImageHeader.I.

References get_color_type(), and has_alpha().

Referenced by PNMImage::add_sub_image(), PNMImage::alpha_fill_val(), PNMImage::apply_exponent(), PNMImage::blend(), PNMImage::clear(), PNMImage::copy_from(), PNMImage::copy_header_from(), PNMImage::copy_sub_image(), PNMImage::darken_sub_image(), PNMImage::expand_border(), has_alpha(), PNMImage::indirect_1d_lookup(), PNMImage::lighten_sub_image(), PNMImage::make_grayscale(), PNMImage::make_rgb(), PNMImage::mult_sub_image(), PNMImage::premultiply_alpha(), PNMImage::quantize(), PNMReader::read_data(), PNMImage::set_color_type(), PNMImage::set_maxval(), PNMImage::take_from(), PNMImage::threshold(), PNMImage::unfiltered_stretch_from(), and PNMImage::unpremultiply_alpha().

## ◆ has_alpha() [2/2]

bool PNMImageHeader::has_alpha | ( | PNMImageHeader::ColorType | color_type | ) |
| inline static

This static variant of has_alpha() returns true if the indicated image type includes an alpha channel, false otherwise.

Definition at line 105 of file pnmImageHeader.I.

Referenced by PNMImage::add_sub_image(), PNMImage::blend_sub_image(), DestTextureImage::copy(), PNMImage::copy_sub_image(), PNMImage::darken_sub_image(), TexturePlacement::fill_image(), TexturePlacement::fill_swapped_image(), TexturePlacement::flag_error_image(), Texture::generate_simple_ram_image(), PNMImage::lighten_sub_image(), PNMImage::mult_sub_image(), PNMImage::threshold(), PNMImage::unfiltered_stretch_from(), and ImageFile::write().

## ◆ is_grayscale() [1/2]

bool PNMImageHeader::is_grayscale | ( |  | ) | const
| inline

Returns false if the image is a full-color image, and has red, green, and blue components; true if it is a grayscale image and has only a gray component.

(The gray color is actually stored in the blue channel, and the red and green channels are ignored.)

Definition at line 96 of file pnmImageHeader.I.

References get_color_type(), and is_grayscale().

Referenced by PNMImage::add_alpha(), is_grayscale(), PNMImage::make_grayscale(), PNMImage::remove_alpha(), PNMImage::set_color_type(), PNMImage::set_maxval(), and PNMImage::write().

## ◆ is_grayscale() [2/2]

bool PNMImageHeader::is_grayscale | ( | PNMImageHeader::ColorType | color_type | ) |
| inline static

This static variant of is_grayscale() returns true if the indicated image type represents a grayscale image, false otherwise.

Definition at line 85 of file pnmImageHeader.I.

## ◆ make_reader() [1/2]

PNMReader * PNMImageHeader::make_reader | ( | const Filename & | filename,
|  | PNMFileType * | type = nullptr,
|  | bool | report_unknown_type = true ) const

Returns a newly-allocated PNMReader of the suitable type for reading from the indicated image filename, or NULL if the filename cannot be read for some reason.

The filename "-" always stands for standard input. If type is specified, it is a suggestion for the file type to use.

The PNMReader should be deleted when it is no longer needed.

Definition at line 79 of file pnmImageHeader.cxx.

References VirtualFileSystem::get_global_ptr(), and make_reader().

Referenced by make_reader(), PfmFile::read(), PNMImage::read(), PNMImage::read(), read_header(), and read_header().

## ◆ make_reader() [2/2]

PNMReader * PNMImageHeader::make_reader | ( | std::istream * | file,
|  | bool | owns_file = true,
|  | const Filename & | filename = Filename(),
|  | std::string | magic_number = std::string(),
|  | PNMFileType * | type = nullptr,
|  | bool | report_unknown_type = true ) const

Returns a newly-allocated PNMReader of the suitable type for reading from the already-opened image file, or NULL if the file cannot be read for some reason.

owns_file should be set true if the PNMReader is to be considered the owner of the stream pointer (in which case the stream will be deleted on completion, whether successful or not), or false if it should not delete it.

The filename parameter is optional here, since the file has already been opened; it is only used to examine the extension and attempt to guess the file type.

If magic_number is nonempty, it is assumed to represent the first few bytes that have already been read from the file. Some file types may have difficulty if this is more than two bytes.

If type is non-NULL, it is a suggestion for the file type to use.

The PNMReader should be deleted when it is no longer needed.

Definition at line 138 of file pnmImageHeader.cxx.

References Filename::get_extension(), PNMFileTypeRegistry::get_global_ptr(), VirtualFileSystem::get_global_ptr(), PNMFileTypeRegistry::get_type_from_extension(), PNMReader::is_valid(), PNMFileType::make_reader(), and read_magic_number().

## ◆ make_writer() [1/2]

PNMWriter * PNMImageHeader::make_writer | ( | const Filename & | filename,
|  | PNMFileType * | type = nullptr ) const

Returns a newly-allocated PNMWriter of the suitable type for writing an image to the indicated filename, or NULL if the filename cannot be written for some reason.

The filename "-" always stands for standard output. If type is specified, it is a suggestion for the file type to use.

The PNMWriter should be deleted when it is no longer needed.

Definition at line 247 of file pnmImageHeader.cxx.

References VirtualFileSystem::get_global_ptr(), and make_writer().

Referenced by make_writer(), PfmFile::write(), PNMImage::write(), and PNMImage::write().

## ◆ make_writer() [2/2]

PNMWriter * PNMImageHeader::make_writer | ( | std::ostream * | file,
|  | bool | owns_file = true,
|  | const Filename & | filename = Filename(),
|  | PNMFileType * | type = nullptr ) const

Returns a newly-allocated PNMWriter of the suitable type for writing to the already-opened image file, or NULL if the file cannot be written for some reason.

owns_file should be set true if the PNMWriter is to be considered the owner of the stream pointer (in which case the stream will be deleted on completion, whether successful or not), or false if it should not delete it.

The filename parameter is optional here, since the file has already been opened; it is only used to examine the extension and attempt to guess the intended file type.

If type is non-NULL, it is a suggestion for the file type to use.

The PNMWriter should be deleted when it is no longer needed.

Definition at line 303 of file pnmImageHeader.cxx.

References PNMFileTypeRegistry::get_global_ptr(), PNMFileTypeRegistry::get_type_from_extension(), PNMWriter::is_valid(), and PNMFileType::make_writer().

## ◆ operator=()

void PNMImageHeader::operator= | ( | const PNMImageHeader & | copy | ) |
| inline

Definition at line 44 of file pnmImageHeader.I.

## ◆ output()

void PNMImageHeader::output | ( | std::ostream & | out | ) | const

Definition at line 380 of file pnmImageHeader.cxx.

## ◆ read_header() [1/2]

bool PNMImageHeader::read_header | ( | const Filename & | filename,
|  | PNMFileType * | type = nullptr,
|  | bool | report_unknown_type = true )

Opens up the image file and tries to read its header information to determine its size, number of channels, etc.

If successful, updates the header information and returns true; otherwise, returns false.

Definition at line 32 of file pnmImageHeader.cxx.

References make_reader().

Referenced by SourceTextureImage::read_header(), and GeoMipTerrain::set_heightfield().

## ◆ read_header() [2/2]

bool PNMImageHeader::read_header | ( | std::istream & | data,
|  | const std::string & | filename = std::string(),
|  | PNMFileType * | type = nullptr,
|  | bool | report_unknown_type = true )

Reads the image header information only from the indicated stream.

The filename is advisory only, and may be used to suggest a type if it has a known extension.

If type is non-NULL, it is a suggestion for the type of file it is (and a non-NULL type will override any magic number test or filename extension lookup).

Returns true if successful, false on error.

Definition at line 57 of file pnmImageHeader.cxx.

References make_reader().

## ◆ read_magic_number()

bool PNMImageHeader::read_magic_number | ( | std::istream * | file,
|  | std::string & | magic_number,
|  | int | num_bytes )
| static

Ensures that the first n bytes of the file are read into magic_number.

If magic_number is initially nonempty, assumes these represent the first few bytes already extracted. Returns true if successful, false if an end of file or error occurred before num_bytes could be read.

Definition at line 364 of file pnmImageHeader.cxx.

Referenced by make_reader().

## ◆ set_type()

void PNMImageHeader::set_type | ( | PNMFileType * | type | ) |
| inline

Sets the file type of this PNMImage.

This will be the default type used when an image is read, if the type cannot be determined by magic number or inferred by extension, or the type used when the image is written, if the type cannot be inferred from the filename extension.

Definition at line 205 of file pnmImageHeader.I.

Referenced by ImageFile::read().

## Member Data Documentation

## ◆ get_color_space

ColorSpace PNMImageHeader::get_color_space
| inline

Returns the color space that the image is encoded in, or CS_unspecified if unknown.

Definition at line 71 of file pnmImageHeader.h.

Referenced by GeoMipTerrain::set_heightfield().

## ◆ get_comment

std::string PNMImageHeader::get_comment
| inline

Gets the user comment from the file.

Definition at line 80 of file pnmImageHeader.h.

## ◆ get_maxval

xelval PNMImageHeader::get_maxval
| inline

Returns the maximum channel value allowable for any pixel in this image; for instance, 255 for a typical 8-bit-per-channel image.

A pixel with this value is full on.

Definition at line 70 of file pnmImageHeader.h.

Referenced by PNMImage::clamp_val(), Texture::consider_rescale(), DestTextureImage::copy(), PNMImage::copy_channel(), PNMImage::copy_sub_image(), PNMImage::darken_sub_image(), PNMImage::expand_border(), TexturePlacement::fill_image(), TexturePlacement::fill_swapped_image(), PNMImage::indirect_1d_lookup(), PNMImage::lighten_sub_image(), PNMImage::operator+=(), PNMImage::operator+=(), PNMImage::operator-=(), PT(), PNMImage::read(), PNMImage::set_xel_a(), PNMImage::threshold(), PNMImage::to_alpha_val(), PNMImage::to_val(), PNMImage::to_val(), and ImageFile::write().

## ◆ get_num_channels

int PNMImageHeader::get_num_channels
| inline

Returns the number of channels in the image.

Definition at line 60 of file pnmImageHeader.h.

Referenced by Texture::consider_rescale(), PfmFile::copy_channel(), PfmFile::copy_channel_masked(), osxGraphicsPipe::create_cg_image(), PNMImage::expand_border(), TexturePlacement::fill_image(), TexturePlacement::fill_swapped_image(), Texture::generate_simple_ram_image(), PNMImage::get_channel(), PNMImage::get_channel_val(), PfmFile::indirect_1d_lookup(), PNMImage::indirect_1d_lookup(), PfmFile::load(), PfmTrans::process_pfm(), ImageFile::read(), PNMImage::read(), PNMImage::remix_channels(), SourceTextureImage::set_header(), PfmFile::store(), PNMImage::threshold(), PNMFileTypePfm::Writer::write_pfm(), and PfmFile::xform().

## ◆ get_size

LVecBase2i PNMImageHeader::get_size
| inline

Returns the number of pixels in each direction.

This is one more than the largest allowable coordinates.

Definition at line 76 of file pnmImageHeader.h.

## ◆ get_type

PNMFileType * PNMImageHeader::get_type
| inline

If the file type is known (e.g.

has_type() returns true), returns its PNMFileType pointer; otherwise, returns NULL.

Definition at line 85 of file pnmImageHeader.h.

Referenced by Texture::consider_rescale(), PNMImage::expand_border(), and PNMImage::read().

## ◆ has_type

bool PNMImageHeader::has_type
| inline

Returns true if the PNMImageHeader knows what type it is, false otherwise.

Definition at line 85 of file pnmImageHeader.h.

## ◆ set_comment

void PNMImageHeader::set_comment
| inline

Writes a user comment string to the image (header).

Definition at line 80 of file pnmImageHeader.h.

Referenced by DisplayRegion::save_screenshot().

The documentation for this class was generated from the following files:

- panda/src/pnmimage/pnmImageHeader.h
- panda/src/pnmimage/pnmImageHeader.cxx
- panda/src/pnmimage/pnmImageHeader.I