Browse Source

use alpha channel if alpha image has it

David Rose 23 years ago
parent
commit
b6eefd9e23
2 changed files with 22 additions and 6 deletions
  1. 11 3
      panda/src/gobj/texture.cxx
  2. 11 3
      pandatool/src/egg-palettize/imageFile.cxx

+ 11 - 3
panda/src/gobj/texture.cxx

@@ -246,9 +246,17 @@ read(const Filename &fullpath, const Filename &alpha_fullpath) {
 
   // Make the original image a 4-component image
   image.add_alpha();
-  for (int x = 0; x < image.get_x_size(); x++) {
-    for (int y = 0; y < image.get_y_size(); y++) {
-      image.set_alpha(x, y, alpha_image.get_gray(x, y));
+  if (alpha_image.has_alpha()) {
+    for (int x = 0; x < image.get_x_size(); x++) {
+      for (int y = 0; y < image.get_y_size(); y++) {
+        image.set_alpha(x, y, alpha_image.get_alpha(x, y));
+      }
+    }
+  } else {
+    for (int x = 0; x < image.get_x_size(); x++) {
+      for (int y = 0; y < image.get_y_size(); y++) {
+        image.set_alpha(x, y, alpha_image.get_gray(x, y));
+      }
     }
   }
 

+ 11 - 3
pandatool/src/egg-palettize/imageFile.cxx

@@ -293,9 +293,17 @@ read(PNMImage &image) const {
     }
 
     image.add_alpha();
-    for (int y = 0; y < image.get_y_size(); y++) {
-      for (int x = 0; x < image.get_x_size(); x++) {
-        image.set_alpha(x, y, alpha_image.get_gray(x, y));
+    if (alpha_image.has_alpha()) {
+      for (int y = 0; y < image.get_y_size(); y++) {
+        for (int x = 0; x < image.get_x_size(); x++) {
+          image.set_alpha(x, y, alpha_image.get_alpha(x, y));
+        }
+      }
+    } else {
+      for (int y = 0; y < image.get_y_size(); y++) {
+        for (int x = 0; x < image.get_x_size(); x++) {
+          image.set_alpha(x, y, alpha_image.get_gray(x, y));
+        }
       }
     }
   }