mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 00:32:57 -04:00
*** empty log message ***
This commit is contained in:
parent
e3c9d317b1
commit
40226e0e47
@ -85,6 +85,82 @@ bool Texture::read(const string& name)
|
|||||||
return load(pnmimage);
|
return load(pnmimage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: read
|
||||||
|
// Access:
|
||||||
|
// Description: Combine a 3-component image with a grayscale image
|
||||||
|
// to get a 4-component image
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool Texture::read(const string &name, const string &gray) {
|
||||||
|
PNMImage pnmimage;
|
||||||
|
if (!pnmimage.read(name)) {
|
||||||
|
gobj_cat.error()
|
||||||
|
<< "Texture::read() - couldn't read: " << name << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PNMImage grayimage;
|
||||||
|
if (!grayimage.read(gray)) {
|
||||||
|
gobj_cat.error()
|
||||||
|
<< "Texture::read() - couldn't read: " << gray << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int new_xsize, new_ysize;
|
||||||
|
int new_gxsize, new_gysize;
|
||||||
|
if (max_texture_dimension > 0 &&
|
||||||
|
(pnmimage.get_x_size() > max_texture_dimension ||
|
||||||
|
pnmimage.get_y_size() > max_texture_dimension)) {
|
||||||
|
new_xsize = min(pnmimage.get_x_size(), max_texture_dimension);
|
||||||
|
new_ysize = min(pnmimage.get_y_size(), max_texture_dimension);
|
||||||
|
gobj_cat.info()
|
||||||
|
<< "Automatically rescaling " << name << " from "
|
||||||
|
<< pnmimage.get_x_size() << " by " << pnmimage.get_y_size() << " to "
|
||||||
|
<< new_xsize << " by " << new_ysize << "\n";
|
||||||
|
|
||||||
|
PNMImage scaled(new_xsize, new_ysize, pnmimage.get_num_channels(),
|
||||||
|
pnmimage.get_maxval(), pnmimage.get_type());
|
||||||
|
scaled.gaussian_filter_from(0.5, pnmimage);
|
||||||
|
pnmimage = scaled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now do the same for the grayscale image
|
||||||
|
if (max_texture_dimension > 0 &&
|
||||||
|
(grayimage.get_x_size() > max_texture_dimension ||
|
||||||
|
grayimage.get_y_size() > max_texture_dimension)) {
|
||||||
|
new_gxsize = min(grayimage.get_x_size(), max_texture_dimension);
|
||||||
|
new_gysize = min(grayimage.get_y_size(), max_texture_dimension);
|
||||||
|
gobj_cat.info()
|
||||||
|
<< "Automatically rescaling " << gray << " from "
|
||||||
|
<< grayimage.get_x_size() << " by " << grayimage.get_y_size() << " to "
|
||||||
|
<< new_xsize << " by " << new_ysize << "\n";
|
||||||
|
|
||||||
|
PNMImage scaled(new_xsize, new_ysize, pnmimage.get_num_channels(),
|
||||||
|
pnmimage.get_maxval(), pnmimage.get_type());
|
||||||
|
scaled.gaussian_filter_from(0.5, pnmimage);
|
||||||
|
pnmimage = scaled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the 2 images are the same size
|
||||||
|
if ((new_xsize != new_gxsize) || (new_ysize != new_gysize)) {
|
||||||
|
gobj_cat.error()
|
||||||
|
<< "Texture::read() - grayscale image not the same size as original"
|
||||||
|
<< endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the original image a 4-component image
|
||||||
|
pnmimage.add_alpha();
|
||||||
|
for (int x = 0; x < new_xsize; x++) {
|
||||||
|
for (int y = 0; y < new_ysize; y++) {
|
||||||
|
pnmimage.set_alpha(x, y, grayimage.get_gray(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set_name(name);
|
||||||
|
return load(pnmimage);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: write
|
// Function: write
|
||||||
// Access:
|
// Access:
|
||||||
|
@ -48,8 +48,9 @@ public:
|
|||||||
Texture();
|
Texture();
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
virtual bool read( const string& name );
|
virtual bool read(const string& name);
|
||||||
virtual bool write( const string& name = "" ) const;
|
virtual bool read(const string &name, const string &gray);
|
||||||
|
virtual bool write(const string& name = "") const;
|
||||||
|
|
||||||
bool load( const PNMImage& pnmimage );
|
bool load( const PNMImage& pnmimage );
|
||||||
bool store( PNMImage& pnmimage ) const;
|
bool store( PNMImage& pnmimage ) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user