Browse Source

pnmimage: fix PixelSpec coercion, add PixelSpec unit test

rdb 7 years ago
parent
commit
c427357db9

+ 0 - 23
panda/src/pnmimage/pnmImageHeader.I

@@ -295,29 +295,6 @@ PixelSpec(const xel &rgb, xelval alpha) :
 {
 {
 }
 }
 
 
-/**
- *
- */
-INLINE PNMImageHeader::PixelSpec::
-PixelSpec(const PixelSpec &copy) :
-  _red(copy._red),
-  _green(copy._green),
-  _blue(copy._blue),
-  _alpha(copy._alpha)
-{
-}
-
-/**
- *
- */
-INLINE void PNMImageHeader::PixelSpec::
-operator = (const PixelSpec &copy) {
-  _red = copy._red;
-  _green = copy._green;
-  _blue = copy._blue;
-  _alpha = copy._alpha;
-}
-
 /**
 /**
  *
  *
  */
  */

+ 3 - 2
panda/src/pnmimage/pnmImageHeader.h

@@ -113,6 +113,9 @@ PUBLISHED:
   // make_histogram().  Note that pixels are stored by integer value, not by
   // make_histogram().  Note that pixels are stored by integer value, not by
   // floating-point scaled value.
   // floating-point scaled value.
   class EXPCL_PANDA_PNMIMAGE PixelSpec {
   class EXPCL_PANDA_PNMIMAGE PixelSpec {
+  public:
+    INLINE PixelSpec() = default;
+
   PUBLISHED:
   PUBLISHED:
     INLINE PixelSpec(xelval gray_value);
     INLINE PixelSpec(xelval gray_value);
     INLINE PixelSpec(xelval gray_value, xelval alpha);
     INLINE PixelSpec(xelval gray_value, xelval alpha);
@@ -120,8 +123,6 @@ PUBLISHED:
     INLINE PixelSpec(xelval red, xelval green, xelval blue, xelval alpha);
     INLINE PixelSpec(xelval red, xelval green, xelval blue, xelval alpha);
     INLINE PixelSpec(const xel &rgb);
     INLINE PixelSpec(const xel &rgb);
     INLINE PixelSpec(const xel &rgb, xelval alpha);
     INLINE PixelSpec(const xel &rgb, xelval alpha);
-    INLINE PixelSpec(const PixelSpec &copy);
-    INLINE void operator = (const PixelSpec &copy);
 
 
     INLINE bool operator < (const PixelSpec &other) const;
     INLINE bool operator < (const PixelSpec &other) const;
     INLINE bool operator == (const PixelSpec &other) const;
     INLINE bool operator == (const PixelSpec &other) const;

+ 21 - 0
tests/pnmimage/test_pnmimage.py

@@ -0,0 +1,21 @@
+from panda3d.core import PNMImage, PNMImageHeader
+
+
+def test_pixelspec_ctor():
+    assert tuple(PNMImage.PixelSpec(1)) == (1, 1, 1, 0)
+    assert tuple(PNMImage.PixelSpec(1, 2)) == (1, 1, 1, 2)
+    assert tuple(PNMImage.PixelSpec(1, 2, 3)) == (1, 2, 3, 0)
+    assert tuple(PNMImage.PixelSpec(1, 2, 3, 4)) == (1, 2, 3, 4)
+
+    assert tuple(PNMImage.PixelSpec((1, 2, 3))) == (1, 2, 3, 0)
+    assert tuple(PNMImage.PixelSpec((1, 2, 3), 4)) == (1, 2, 3, 4)
+
+    # Copy constructor
+    spec = PNMImage.PixelSpec(1, 2, 3, 4)
+    assert tuple(PNMImage.PixelSpec(spec)) == (1, 2, 3, 4)
+
+
+def test_pixelspec_coerce():
+    img = PNMImage(1, 1, 4)
+    img.set_pixel(0, 0, (1, 2, 3, 4))
+    assert img.get_pixel(0, 0) == (1, 2, 3, 4)