36 _alpha_file_channel = 0;
52 bool any_changed =
false;
54 if (_properties._color_type != pal->_shadow_color_type ||
55 _properties._alpha_type != pal->_shadow_alpha_type) {
57 _properties._color_type = pal->_shadow_color_type;
58 _properties._alpha_type = pal->_shadow_alpha_type;
155 pi = pal->_map_dirname.begin();
156 while (pi != pal->_map_dirname.end()) {
165 if (group !=
nullptr) {
188set_filename(
const string &dirname,
const string &basename) {
190 Filename orig_alpha_filename = _alpha_filename;
192 _filename =
Filename(dirname, basename);
204 if (_properties._color_type !=
nullptr) {
209 if (_properties._alpha_type !=
nullptr) {
217 return (_filename != orig_filename ||
218 _alpha_filename != orig_alpha_filename);
236 return _alpha_filename;
247 return _alpha_file_channel;
257 if (!_filename.
exists()) {
260 if (_properties._alpha_type !=
nullptr &&
262 !_alpha_filename.empty()) {
263 if (!_alpha_filename.
exists()) {
278 nassertr(!_filename.empty(),
false);
280 image.
set_type(_properties._color_type);
282 if (!image.
read(_filename)) {
283 nout <<
"Unable to read.\n";
287 if (!_alpha_filename.empty() && _alpha_filename.
exists()) {
290 alpha_image.
set_type(_properties._alpha_type);
292 if (!alpha_image.
read(_alpha_filename)) {
293 nout <<
"Unable to read.\n";
303 if (_alpha_file_channel == 4 ||
306 for (
int x = 0; x < image.
get_x_size(); x++) {
307 for (
int y = 0; y < image.
get_y_size(); y++) {
312 }
else if (_alpha_file_channel >= 1 && _alpha_file_channel <= 3 &&
315 for (
int x = 0; x < image.
get_x_size(); x++) {
316 for (
int y = 0; y < image.
get_y_size(); y++) {
323 for (
int x = 0; x < image.
get_x_size(); x++) {
324 for (
int y = 0; y < image.
get_y_size(); y++) {
340 nassertr(!_filename.empty(),
false);
343 _properties._alpha_type ==
nullptr) {
344 if (!_alpha_filename.empty() && _alpha_filename.
exists()) {
350 if (!image.
write(_filename, _properties._color_type)) {
351 nout <<
"Unable to write.\n";
360 for (
int y = 0; y < image.
get_y_size(); y++) {
361 for (
int x = 0; x < image.
get_x_size(); x++) {
370 if (!image_copy.
write(_filename, _properties._color_type)) {
371 nout <<
"Unable to write.\n";
377 if (!alpha_image.
write(_alpha_filename, _properties._alpha_type)) {
378 nout <<
"Unable to write.\n";
389 if (!_filename.empty() && _filename.
exists()) {
393 if (!_alpha_filename.empty() && _alpha_filename.
exists()) {
404 nassertv(egg_tex !=
nullptr);
409 !_alpha_filename.empty()) {
413 egg_tex->clear_alpha_filename();
426 if (_properties.
uses_alpha() && !_alpha_filename.empty()) {
469 _properties.
fillin(scan, manager);
472 if (Palettizer::_read_pi_version >= 10) {
475 _alpha_file_channel = 0;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
A class to retrieve the individual data elements previously stored in a Datagram.
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
bool get_bool()
Extracts a boolean value.
std::string get_string()
Extracts a variable-length string.
int32_t get_int32()
Extracts a signed 32-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
void add_bool(bool value)
Adds a boolean value to the datagram.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
Defines a texture map that may be applied to geometry.
set_alpha_file_channel
If a separate alpha-file is specified, this indicates which channel number should be extracted from t...
clear_alpha_file_channel
Removes the specification of a particular channel to use from the alpha- file image.
set_alpha_filename
Specifies a separate file that will be loaded in with the 1- or 3-component texture and applied as th...
static Filename get_bam_filename(Filename filename)
Returns an absolute pathname based on the given relative pathname, presumably read from the bam file ...
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...
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...
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.
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
void standardize()
Converts the filename to standard form by replacing consecutive slashes with a single slash,...
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
void set_extension(const std::string &s)
Replaces the file extension.
bool exists() const
Returns true if the filename exists on the physical disk, false otherwise.
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.
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.
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.
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.
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()...
get_suggested_extension
Returns a suitable filename extension (without a leading dot) to suggest for files of this type,...
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
xelval get_channel_val(int x, int y, int channel) const
Returns the nth component color at the indicated pixel.
float get_alpha(int x, int y) const
Returns the alpha component color at the indicated pixel.
float get_gray(int x, int y) const
Returns the gray component color at the indicated pixel.
void remove_alpha()
Removes the image's alpha channel, if it exists.
void set_gray_val(int x, int y, xelval gray)
Sets the gray component color at the indicated pixel.
xelval get_alpha_val(int x, int y) const
Returns the alpha component color at the indicated pixel.
bool read(const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true)
Reads the indicated image filename.
void set_alpha(int x, int y, float a)
Sets the alpha component color only at the indicated pixel.
void add_alpha()
Adds an alpha channel to the image, if it does not already have one.
bool write(const Filename &filename, PNMFileType *type=nullptr) const
Writes the image to the indicated filename.
This is the highest level of grouping for TextureImages.
const std::string & get_dirname() const
Returns the directory name associated with the palette group.
This is the set of characteristics of a texture that, if different from another texture,...
void update_egg_tex(EggTexture *egg_tex) const
Adjusts the texture properties of the indicated egg reference to match these properties.
int get_num_channels() const
Returns the number of channels (1 through 4) associated with the image.
void clear_basic()
Resets only the properties that might be changed by update_properties() to a neutral state.
void update_properties(const TextureProperties &other)
If the indicate TextureProperties structure is more specific than this one, updates this one.
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...
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
bool has_num_channels() const
Returns true if the number of channels is known.
bool uses_alpha() const
Returns true if the texture uses an alpha channel, false otherwise.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
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...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.