mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 20:53:50 -04:00
My shader system operates on many types of maps: color(RGB), alpha,
bump, lumma, specular, nomral(UVW), damage, team color ... That are all stored in different formats of packed and unpacked ways. Not all objects have all of the maps. If an object has color and spec map i can easy pack it into red,green,blue,spec texture. If a object has color,lumma,specular,normal map again i can pack it most effective in 2 textures (rgbl + suvw). I needed a way to repack them easily. At first i coded the function in python and it was pretty slow. So I rewrote it in c++.
This commit is contained in:
parent
b36dc682a3
commit
fcc8ee33b6
@ -110,6 +110,39 @@ copy_from(const PNMImage ©) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PNMImage::copy_channel
|
||||||
|
// Access: Published
|
||||||
|
// Description: Copies a channel from one image into another.
|
||||||
|
// Images must be the same size
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void PNMImage::
|
||||||
|
copy_channel(const PNMImage ©, int src_channel, int dest_channel) {
|
||||||
|
// Make sure the channels are in range
|
||||||
|
nassertv(src_channel >= 0 && src_channel <= 3);
|
||||||
|
nassertv(dest_channel >= 0 && dest_channel <= 3);
|
||||||
|
// Make sure that images are valid
|
||||||
|
if (!copy.is_valid() || !is_valid()) {
|
||||||
|
pnmimage_cat.error() << "One of the images is invalid!\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Make sure the images are the same size
|
||||||
|
if (_x_size != copy.get_x_size() || _y_size != copy.get_y_size()){
|
||||||
|
pnmimage_cat.error() << "Image size doesn't match!\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Do the actual copying
|
||||||
|
for (int x = 0; x < _x_size; x++) {
|
||||||
|
for (int y = 0; y < _y_size; y++) {
|
||||||
|
LVecBase4d t = get_xel_a(x, y);
|
||||||
|
LVecBase4d o = copy.get_xel_a(x, y);
|
||||||
|
t.set_cell(dest_channel,o.get_cell(src_channel));
|
||||||
|
set_xel_a(x, y, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PNMImage::copy_header_from
|
// Function: PNMImage::copy_header_from
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -73,6 +73,7 @@ PUBLISHED:
|
|||||||
xelval maxval = 255, PNMFileType *type = NULL);
|
xelval maxval = 255, PNMFileType *type = NULL);
|
||||||
|
|
||||||
void copy_from(const PNMImage ©);
|
void copy_from(const PNMImage ©);
|
||||||
|
void copy_channel(const PNMImage ©, int src_channel, int dest_channel);
|
||||||
void copy_header_from(const PNMImageHeader &header);
|
void copy_header_from(const PNMImageHeader &header);
|
||||||
void take_from(PNMImage &orig);
|
void take_from(PNMImage &orig);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user