pnmimage: fix PixelSpec coercion, add PixelSpec unit test

This commit is contained in:
rdb
2018-11-27 17:09:22 +01:00
parent 272f13023e
commit c427357db9
3 changed files with 24 additions and 25 deletions
-23
View File
@@ -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
View File
@@ -113,6 +113,9 @@ PUBLISHED:
// make_histogram(). Note that pixels are stored by integer value, not by
// floating-point scaled value.
class EXPCL_PANDA_PNMIMAGE PixelSpec {
public:
INLINE PixelSpec() = default;
PUBLISHED:
INLINE PixelSpec(xelval gray_value);
INLINE PixelSpec(xelval gray_value, xelval alpha);
@@ -120,8 +123,6 @@ PUBLISHED:
INLINE PixelSpec(xelval red, xelval green, xelval blue, xelval alpha);
INLINE PixelSpec(const xel &rgb);
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;
+21
View File
@@ -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)