Browse Source

fix image -= colour

rdb 15 years ago
parent
commit
44bf0582cf
1 changed files with 22 additions and 1 deletions
  1. 22 1
      panda/src/pnmimage/pnmImage.cxx

+ 22 - 1
panda/src/pnmimage/pnmImage.cxx

@@ -1529,7 +1529,28 @@ operator -= (const PNMImage &other) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void PNMImage::
 void PNMImage::
 operator -= (const Colord &other) {
 operator -= (const Colord &other) {
-  (*this) += (-other);
+  size_t array_size = _x_size * _y_size;
+  xel subxel (to_val(other.get_x()), to_val(other.get_y()), to_val(other.get_z()));
+  xelval subalpha = to_val(other.get_w());
+
+  if (_array != NULL && _alpha != NULL) {
+    for (size_t i = 0; i < array_size; ++i) {
+      _array[i].r = clamp_val(_array[i].r - subxel.r);
+      _array[i].g = clamp_val(_array[i].g - subxel.g);
+      _array[i].b = clamp_val(_array[i].b - subxel.b);
+      _alpha[i] = clamp_val(_alpha[i] + subalpha);
+    }
+  } else if (_array != NULL) {
+    for (size_t i = 0; i < array_size; ++i) {
+      _array[i].r = clamp_val(_array[i].r - subxel.r);
+      _array[i].g = clamp_val(_array[i].g - subxel.g);
+      _array[i].b = clamp_val(_array[i].b - subxel.b);
+    }
+  } else if (_alpha != NULL) {
+    for (size_t i = 0; i < array_size; ++i) {
+      _alpha[i] = clamp_val(_alpha[i] - subalpha);
+    }
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////