15 #include "imageFile.h" 16 #include "palettizer.h" 17 #include "filenameUnifier.h" 18 #include "paletteGroup.h" 21 #include "pnmFileType.h" 22 #include "eggTexture.h" 24 #include "datagramIterator.h" 25 #include "bamReader.h" 26 #include "bamWriter.h" 37 _alpha_file_channel = 0;
57 bool any_changed =
false;
59 if (_properties._color_type != pal->_shadow_color_type ||
60 _properties._alpha_type != pal->_shadow_alpha_type) {
62 _properties._color_type = pal->_shadow_color_type;
63 _properties._alpha_type = pal->_shadow_alpha_type;
186 pi = pal->_map_dirname.begin();
187 while (pi != pal->_map_dirname.end()) {
225 Filename orig_alpha_filename = _alpha_filename;
227 _filename =
Filename(dirname, basename);
240 if (_properties._color_type != (
PNMFileType *)NULL) {
245 if (_properties._alpha_type != (
PNMFileType *)NULL) {
253 return (_filename != orig_filename ||
254 _alpha_filename != orig_alpha_filename);
277 return _alpha_filename;
292 return _alpha_file_channel;
304 if (!_filename.
exists()) {
307 if (_properties._alpha_type != (
PNMFileType *)NULL &&
309 !_alpha_filename.empty()) {
310 if (!_alpha_filename.
exists()) {
327 nassertr(!_filename.empty(),
false);
329 image.
set_type(_properties._color_type);
331 if (!image.
read(_filename)) {
332 nout <<
"Unable to read.\n";
336 if (!_alpha_filename.empty() && _alpha_filename.
exists()) {
339 alpha_image.
set_type(_properties._alpha_type);
341 if (!alpha_image.
read(_alpha_filename)) {
342 nout <<
"Unable to read.\n";
352 if (_alpha_file_channel == 4 ||
355 for (
int x = 0; x < image.
get_x_size(); x++) {
356 for (
int y = 0; y < image.
get_y_size(); y++) {
361 }
else if (_alpha_file_channel >= 1 && _alpha_file_channel <= 3 &&
364 for (
int x = 0; x < image.
get_x_size(); x++) {
365 for (
int y = 0; y < image.
get_y_size(); y++) {
372 for (
int x = 0; x < image.
get_x_size(); x++) {
373 for (
int y = 0; y < image.
get_y_size(); y++) {
392 nassertr(!_filename.empty(),
false);
396 if (!_alpha_filename.empty() && _alpha_filename.
exists()) {
402 if (!image.
write(_filename, _properties._color_type)) {
403 nout <<
"Unable to write.\n";
412 for (
int y = 0; y < image.
get_y_size(); y++) {
413 for (
int x = 0; x < image.
get_x_size(); x++) {
422 if (!image_copy.
write(_filename, _properties._color_type)) {
423 nout <<
"Unable to write.\n";
429 if (!alpha_image.write(_alpha_filename, _properties._alpha_type)) {
430 nout <<
"Unable to write.\n";
443 if (!_filename.empty() && _filename.
exists()) {
447 if (!_alpha_filename.empty() && _alpha_filename.
exists()) {
465 !_alpha_filename.empty()) {
469 egg_tex->clear_alpha_filename();
485 if (_properties.
uses_alpha() && !_alpha_filename.empty()) {
537 _properties.
fillin(scan, manager);
540 if (Palettizer::_read_pi_version >= 10) {
543 _alpha_file_channel = 0;
void set_gray_val(int x, int y, xelval gray)
Sets the gray component color at the indicated pixel.
bool write(const PNMImage &image) const
Writes out the image in the indicated PNMImage to the _filename and/or _alpha_filename.
static Filename make_bam_filename(Filename filename)
Returns a new filename that's made relative to the bam file itself, suitable for writing to the bam f...
void set_extension(const string &s)
Replaces the file extension.
bool read(PNMImage &image) const
Reads in the image (or images, if the alpha_filename is separate) and stores it in the indicated PNMI...
void add_uint8(PN_uint8 value)
Adds an unsigned 8-bit integer to the datagram.
int get_num_channels() const
Returns the number of channels (1 through 4) associated with the image.
void update_egg_tex(EggTexture *egg_tex) const
Sets the indicated EggTexture to refer to this file.
xelval get_channel_val(int x, int y, int channel) const
Returns the nth component color at the indicated pixel.
bool get_bool()
Extracts a boolean value.
void add_string(const string &str)
Adds a variable-length string to the datagram.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
bool exists() const
Returns true if the file or files named by the image file exist, false otherwise. ...
void set_alpha_file_channel(int alpha_file_channel)
If a separate alpha-file is specified, this indicates which channel number should be extracted from t...
int get_alpha_file_channel() const
Returns the particular channel number of the alpha image file from which the alpha channel should be ...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
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 set_filename(PaletteGroup *group, const string &basename)
Sets the filename, and if applicable, the alpha_filename, from the indicated basename.
float get_gray(int x, int y) const
Returns the gray component color at the indicated pixel.
Defines a texture map that may be applied to geometry.
bool read(const Filename &filename, PNMFileType *type=NULL, bool report_unknown_type=true)
Reads the indicated image filename.
int get_y_size() const
Returns the size of the image file in pixels in the Y direction.
Base class for objects that can be written to and read from Bam files.
This is the highest level of grouping for TextureImages.
This is the base class of a family of classes that represent particular image file types that PNMImag...
void output_filename(ostream &out) const
Writes the filename (or pair of filenames) to the indicated output stream.
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...
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
bool make_shadow_image(const string &basename)
Sets up the ImageFile as a "shadow image" of a particular PaletteImage.
PN_int32 get_int32()
Extracts a signed 32-bit integer.
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
void remove_alpha()
Removes the image's alpha channel, if it exists.
string get_string()
Extracts a variable-length string.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
void standardize()
Converts the filename to standard form by replacing consecutive slashes with a single slash...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void update_egg_tex(EggTexture *egg_tex) const
Adjusts the texture properties of the indicated egg reference to match these properties.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
void set_alpha_filename(const Filename &filename)
Specifies a separate file that will be loaded in with the 1- or 3-component texture and applied as th...
void add_bool(bool value)
Adds a boolean value to the datagram.
static Filename make_user_filename(Filename filename)
Returns a new filename that's made relative to the current directory, suitable for reporting to the u...
bool is_size_known() const
Returns true if the size of the image file is known, false otherwise.
static Filename make_egg_filename(Filename filename)
Returns a new filename that's made relative to the rel_directory, suitable for writing out within egg...
The name of a file, such as a texture file or an Egg file.
int get_x_size() const
Returns the size of the image file in pixels in the X direction.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
static Filename get_bam_filename(Filename filename)
Returns an absolute pathname based on the given relative pathname, presumably read from the bam file ...
const string & get_dirname() const
Returns the directory name associated with the palette group.
int get_num_channels() const
Returns the number of channels of the image.
void clear_basic_properties()
Resets the properties to a neutral state, for instance in preparation for calling update_properties()...
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
bool uses_alpha() const
Returns true if the texture uses an alpha channel, false otherwise.
bool write(const Filename &filename, PNMFileType *type=NULL) const
Writes the image to the indicated filename.
bool has_num_channels() const
Returns true if the number of channels is known.
void clear_alpha_file_channel()
Removes the specification of a particular channel to use from the alpha-file image.
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
const Filename & get_alpha_filename() const
Returns the alpha filename of the image file.
void add_alpha()
Adds an alpha channel to the image, if it does not already have one.
void unlink()
Deletes the image file or files.
void set_alpha(int x, int y, float a)
Sets the alpha component color only at the indicated pixel.
bool has_num_channels() const
Returns true if the number of channels in the image is known, false otherwise.
void clear_basic()
Resets only the properties that might be changed by update_properties() to a neutral state...
void update_properties(const TextureProperties &properties)
If the indicate TextureProperties structure is more specific than this one, updates this one...
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
A class to retrieve the individual data elements previously stored in a Datagram. ...
xelval get_alpha_val(int x, int y) const
Returns the alpha component color at the indicated pixel.
void update_properties(const TextureProperties &other)
If the indicate TextureProperties structure is more specific than this one, updates this one...
string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
TypeHandle is the identifier used to differentiate C++ class types.
const Filename & get_filename() const
Returns the primary filename of the image file.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
virtual string get_suggested_extension() const
Returns a suitable filename extension (without a leading dot) to suggest for files of this type...
float get_alpha(int x, int y) const
Returns the alpha component color at the indicated pixel.
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.