mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
parent
f2e67169bc
commit
80ab6a28c4
@ -1176,7 +1176,7 @@ add_sub_image(const PNMImage ©, int xto, int yto,
|
||||
if (has_alpha() && copy.has_alpha()) {
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
set_alpha(x, y, get_alpha(x, y) + copy.get_alpha(x, y) * pixel_scale);
|
||||
set_alpha(x, y, get_alpha(x, y) + copy.get_alpha(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1184,7 +1184,7 @@ add_sub_image(const PNMImage ©, int xto, int yto,
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
LRGBColorf rgb1 = get_xel(x, y);
|
||||
LRGBColorf rgb2 = copy.get_xel(x, y);
|
||||
LRGBColorf rgb2 = copy.get_xel(x - xmin + xfrom, y - ymin + yfrom);
|
||||
set_xel(x, y,
|
||||
rgb1[0] + rgb2[0] * pixel_scale,
|
||||
rgb1[1] + rgb2[1] * pixel_scale,
|
||||
@ -1210,7 +1210,7 @@ mult_sub_image(const PNMImage ©, int xto, int yto,
|
||||
if (has_alpha() && copy.has_alpha()) {
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
set_alpha(x, y, get_alpha(x, y) * copy.get_alpha(x, y) * pixel_scale);
|
||||
set_alpha(x, y, get_alpha(x, y) * copy.get_alpha(x - xmin + xfrom, y - ymin + yfrom) * pixel_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1218,7 +1218,7 @@ mult_sub_image(const PNMImage ©, int xto, int yto,
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
LRGBColorf rgb1 = get_xel(x, y);
|
||||
LRGBColorf rgb2 = copy.get_xel(x, y);
|
||||
LRGBColorf rgb2 = copy.get_xel(x - xmin + xfrom, y - ymin + yfrom);
|
||||
set_xel(x, y,
|
||||
rgb1[0] * rgb2[0] * pixel_scale,
|
||||
rgb1[1] * rgb2[1] * pixel_scale,
|
||||
|
@ -70,3 +70,40 @@ def test_pnmimage_quantize():
|
||||
assert col.b in (0, 1)
|
||||
|
||||
assert max_dist < 0.1 ** 2
|
||||
|
||||
def test_pnmimage_add_sub_image():
|
||||
dst = PNMImage(2, 2)
|
||||
dst.fill(0.5, 0, 0) #adding color to dst
|
||||
#dst_color will store rgb values at each pixel of dst
|
||||
dst_color = ((dst.get_xel(0, 0), dst.get_xel(0, 1)), (dst.get_xel(1, 0), dst.get_xel(1, 1)))
|
||||
|
||||
src = PNMImage(1, 1)
|
||||
src.fill(0, 0.7, 0) #adding color to src
|
||||
#src_color will store rgb values at each pixel of src
|
||||
src_color = src.get_xel(0, 0)
|
||||
|
||||
dst.add_sub_image(src, 1, 1, 0, 0, 1, 1)
|
||||
final_color = ((dst.get_xel(0, 0), dst.get_xel(0, 1)), (dst.get_xel(1, 0), dst.get_xel(1, 1)))
|
||||
assert final_color[0][0] == dst_color[0][0]
|
||||
assert final_color[0][1] == dst_color[0][1]
|
||||
assert final_color[1][0] == dst_color[1][0]
|
||||
assert final_color[1][1] == dst_color[1][1] + src_color
|
||||
|
||||
|
||||
def test_pnmimage_mult_sub_image():
|
||||
dst = PNMImage(2, 2)
|
||||
dst.fill(0.5, 0, 0) #adding color to dst
|
||||
#dst_color will store rgb values at each pixel of dst
|
||||
dst_color = ((dst.get_xel(0, 0), dst.get_xel(0, 1)), (dst.get_xel(1, 0), dst.get_xel(1, 1)))
|
||||
|
||||
src = PNMImage(1, 1)
|
||||
src.fill(0, 0.7, 0) #adding color to src
|
||||
#src_color will store rgb values at each pixel of src
|
||||
src_color = src.get_xel(0, 0)
|
||||
|
||||
dst.mult_sub_image(src, 1, 1, 0, 0, 1, 1)
|
||||
final_color = ((dst.get_xel(0, 0), dst.get_xel(0, 1)), (dst.get_xel(1, 0), dst.get_xel(1, 1)))
|
||||
assert final_color[0][0] == dst_color[0][0]
|
||||
assert final_color[0][1] == dst_color[0][1]
|
||||
assert final_color[1][0] == dst_color[1][0]
|
||||
assert final_color[1][1][0] == dst_color[1][1][0] * src_color[0] and final_color[1][1][1] == dst_color[1][1][1] * src_color[1] and final_color[1][1][2] == dst_color[1][1][2] * src_color[2]
|
||||
|
Loading…
x
Reference in New Issue
Block a user