Panda3D
Loading...
Searching...
No Matches
imageFile.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file imageFile.h
10 * @author drose
11 * @date 2000-11-28
12 */
13
14#ifndef IMAGEFILE_H
15#define IMAGEFILE_H
16
17#include "pandatoolbase.h"
18
19#include "textureProperties.h"
20
21#include "filename.h"
22#include "typedWritable.h"
23
24class PNMImage;
25class EggTexture;
26class PaletteGroup;
27
28/**
29 * This is the base class of both TextureImage and PaletteImage. It
30 * encapsulates all the information specific to an image file that can be
31 * assigned as a texture image to egg geometry.
32 */
33class ImageFile : public TypedWritable {
34public:
35 ImageFile();
36
37 bool make_shadow_image(const std::string &basename);
38
39 bool is_size_known() const;
40 int get_x_size() const;
41 int get_y_size() const;
42 bool has_num_channels() const;
43 int get_num_channels() const;
44
45 const TextureProperties &get_properties() const;
47 void update_properties(const TextureProperties &properties);
48
49 bool set_filename(PaletteGroup *group, const std::string &basename);
50 bool set_filename(const std::string &dirname, const std::string &basename);
51 const Filename &get_filename() const;
52 const Filename &get_alpha_filename() const;
53 int get_alpha_file_channel() const;
54 bool exists() const;
55
56 bool read(PNMImage &image) const;
57 bool write(const PNMImage &image) const;
58 void unlink();
59
60 void update_egg_tex(EggTexture *egg_tex) const;
61
62 void output_filename(std::ostream &out) const;
63
64protected:
65 TextureProperties _properties;
66 Filename _filename;
67 Filename _alpha_filename;
68 int _alpha_file_channel;
69
70 bool _size_known;
71 int _x_size, _y_size;
72
73 // The TypedWritable interface follows.
74public:
75 virtual void write_datagram(BamWriter *writer, Datagram &datagram);
76 virtual int complete_pointers(TypedWritable **p_list,
77 BamReader *manager);
78
79protected:
80 void fillin(DatagramIterator &scan, BamReader *manager);
81
82public:
83 static TypeHandle get_class_type() {
84 return _type_handle;
85 }
86 static void init_type() {
87 TypedWritable::init_type();
88 register_type(_type_handle, "ImageFile",
89 TypedWritable::get_class_type());
90 }
91 virtual TypeHandle get_type() const {
92 return get_class_type();
93 }
94
95private:
96 static TypeHandle _type_handle;
97
98};
99
100#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
Defines a texture map that may be applied to geometry.
Definition eggTexture.h:30
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
This is the base class of both TextureImage and PaletteImage.
Definition imageFile.h:33
void update_egg_tex(EggTexture *egg_tex) const
Sets the indicated EggTexture to refer to this file.
int get_num_channels() const
Returns the number of channels of the image.
bool write(const PNMImage &image) const
Writes out the image in the indicated PNMImage to the _filename and/or _alpha_filename.
bool set_filename(PaletteGroup *group, const std::string &basename)
Sets the filename, and if applicable, the alpha_filename, from the indicated basename.
void unlink()
Deletes the image file or files.
int get_x_size() const
Returns the size of the image file in pixels in the X direction.
Definition imageFile.cxx:82
void output_filename(std::ostream &out) const
Writes the filename (or pair of filenames) to the indicated output stream.
bool exists() const
Returns true if the file or files named by the image file exist, false otherwise.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
bool make_shadow_image(const std::string &basename)
Sets up the ImageFile as a "shadow image" of a particular PaletteImage.
Definition imageFile.cxx:51
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
const Filename & get_filename() const
Returns the primary filename of the image file.
bool read(PNMImage &image) const
Reads in the image (or images, if the alpha_filename is separate) and stores it in the indicated PNMI...
const Filename & get_alpha_filename() const
Returns the alpha filename of the image file.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
bool is_size_known() const
Returns true if the size of the image file is known, false otherwise.
Definition imageFile.cxx:73
void update_properties(const TextureProperties &properties)
If the indicate TextureProperties structure is more specific than this one, updates this one.
int get_y_size() const
Returns the size of the image file in pixels in the Y direction.
Definition imageFile.cxx:92
int get_alpha_file_channel() const
Returns the particular channel number of the alpha image file from which the alpha channel should be ...
bool has_num_channels() const
Returns true if the number of channels in the image is known, false otherwise.
void clear_basic_properties()
Resets the properties to a neutral state, for instance in preparation for calling update_properties()...
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition pnmImage.h:58
This is the highest level of grouping for TextureImages.
This is the set of characteristics of a texture that, if different from another texture,...
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.