Skip to content

Commit c427357

Browse files
committed
pnmimage: fix PixelSpec coercion, add PixelSpec unit test
1 parent 272f130 commit c427357

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

panda/src/pnmimage/pnmImageHeader.I

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -295,29 +295,6 @@ PixelSpec(const xel &rgb, xelval alpha) :
295295
{
296296
}
297297

298-
/**
299-
*
300-
*/
301-
INLINE PNMImageHeader::PixelSpec::
302-
PixelSpec(const PixelSpec &copy) :
303-
_red(copy._red),
304-
_green(copy._green),
305-
_blue(copy._blue),
306-
_alpha(copy._alpha)
307-
{
308-
}
309-
310-
/**
311-
*
312-
*/
313-
INLINE void PNMImageHeader::PixelSpec::
314-
operator = (const PixelSpec &copy) {
315-
_red = copy._red;
316-
_green = copy._green;
317-
_blue = copy._blue;
318-
_alpha = copy._alpha;
319-
}
320-
321298
/**
322299
*
323300
*/

panda/src/pnmimage/pnmImageHeader.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,16 @@ class EXPCL_PANDA_PNMIMAGE PNMImageHeader {
113113
// make_histogram(). Note that pixels are stored by integer value, not by
114114
// floating-point scaled value.
115115
class EXPCL_PANDA_PNMIMAGE PixelSpec {
116+
public:
117+
INLINE PixelSpec() = default;
118+
116119
PUBLISHED:
117120
INLINE PixelSpec(xelval gray_value);
118121
INLINE PixelSpec(xelval gray_value, xelval alpha);
119122
INLINE PixelSpec(xelval red, xelval green, xelval blue);
120123
INLINE PixelSpec(xelval red, xelval green, xelval blue, xelval alpha);
121124
INLINE PixelSpec(const xel &rgb);
122125
INLINE PixelSpec(const xel &rgb, xelval alpha);
123-
INLINE PixelSpec(const PixelSpec &copy);
124-
INLINE void operator = (const PixelSpec &copy);
125126

126127
INLINE bool operator < (const PixelSpec &other) const;
127128
INLINE bool operator == (const PixelSpec &other) const;

tests/pnmimage/test_pnmimage.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from panda3d.core import PNMImage, PNMImageHeader
2+
3+
4+
def test_pixelspec_ctor():
5+
assert tuple(PNMImage.PixelSpec(1)) == (1, 1, 1, 0)
6+
assert tuple(PNMImage.PixelSpec(1, 2)) == (1, 1, 1, 2)
7+
assert tuple(PNMImage.PixelSpec(1, 2, 3)) == (1, 2, 3, 0)
8+
assert tuple(PNMImage.PixelSpec(1, 2, 3, 4)) == (1, 2, 3, 4)
9+
10+
assert tuple(PNMImage.PixelSpec((1, 2, 3))) == (1, 2, 3, 0)
11+
assert tuple(PNMImage.PixelSpec((1, 2, 3), 4)) == (1, 2, 3, 4)
12+
13+
# Copy constructor
14+
spec = PNMImage.PixelSpec(1, 2, 3, 4)
15+
assert tuple(PNMImage.PixelSpec(spec)) == (1, 2, 3, 4)
16+
17+
18+
def test_pixelspec_coerce():
19+
img = PNMImage(1, 1, 4)
20+
img.set_pixel(0, 0, (1, 2, 3, 4))
21+
assert img.get_pixel(0, 0) == (1, 2, 3, 4)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy