Skip to content

Commit 36a1b54

Browse files
committed
test(python): expand ImageBufAlgo testsuite; fix font and SHA-1 stability
Signed-off-by: Aleksandr Motsjonov <soswow@gmail.com>
1 parent 0c9545a commit 36a1b54

8 files changed

Lines changed: 113 additions & 21 deletions

File tree

461 Bytes
Binary file not shown.
9.06 KB
Binary file not shown.

testsuite/python-imagebufalgo/ref/out-macarm.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,29 @@ Comparison: of flip.tif and flop.tif
2525
warns 2034 fails 2034
2626
Relative comparison: of flip.tif and flop.tif
2727
warns 1946 fails 1896
28+
compare_Yee ok: True nfail: 1906 mean: True
2829
FLIP_diff same vs same: mean=0 max=0
2930
FLIP_diff black vs white: mean=0.96738 max=0.96738
3031
FLIP_ppd = 67.02
3132
isConstantColor on pink image is (1 0.50196 0.50196)
3233
isConstantColor on checker is None
34+
isConstantChannel pink R=1: True
35+
isConstantChannel checker G=0.5: False
3336
Is cmul1.exr monochrome? True
3437
Is cmul2.exr monochrome? False
3538
color range counts = (4, 8, 4)
3639
Nonzero region is: 100 180 100 180 0 1 0 3
37-
SHA-1 of bsplinekernel.exr is: 0902C72521944A879D5F8E8154B6DFA9D3F62598
40+
SHA-1 of bsplinekernel.exr valid: True
41+
zover closer fg wins: True
42+
text_size defined: True width>0: True
43+
textcentered wrote: True
44+
render shapes nonzero: True
45+
46+
Testing additional IBA bindings:
47+
copy size: 128 96 3
48+
repremult ok: True
49+
deep_merge deep: True samples@0,0: 1
50+
demosaic size: 256 x 172
3851
R hist: (10000, 0, 0, 0)
3952
G hist: (10000, 0, 0, 0)
4053
B hist: (0, 10000, 0, 0)
@@ -219,9 +232,13 @@ Comparing "box3.exr" and "../../../testsuite/oiiotool-fixnan/ref/box3.exr"
219232
PASS
220233
Comparing "a_over_b.exr" and "../../../testsuite/oiiotool-composite/ref/a_over_b.exr"
221234
PASS
222-
Comparing "tahoe-small.tx" and "ref/tahoe-small.tx"
235+
Comparing "zover.exr" and "ref/zover.exr"
236+
PASS
237+
Comparing "render-shapes.tif" and "ref/render-shapes.tif"
223238
PASS
224-
Comparing "text.tif" and "../../../testsuite/oiiotool-text/ref/text-freetype2.7.tif"
239+
Comparing "deep_merge.exr" and "ref/deep_merge.exr"
225240
PASS
226-
Comparing "textcentered.tif" and "ref/textcentered.tif"
241+
Comparing "demosaic.tif" and "ref/demosaic.tif"
242+
PASS
243+
Comparing "tahoe-small.tx" and "ref/tahoe-small.tx"
227244
PASS

testsuite/python-imagebufalgo/ref/out.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,29 @@ Comparison: of flip.tif and flop.tif
2525
warns 2034 fails 2034
2626
Relative comparison: of flip.tif and flop.tif
2727
warns 1946 fails 1896
28+
compare_Yee ok: True nfail: 1906 mean: True
2829
FLIP_diff same vs same: mean=0 max=0
2930
FLIP_diff black vs white: mean=0.96738 max=0.96738
3031
FLIP_ppd = 67.02
3132
isConstantColor on pink image is (1 0.50196 0.50196)
3233
isConstantColor on checker is None
34+
isConstantChannel pink R=1: True
35+
isConstantChannel checker G=0.5: False
3336
Is cmul1.exr monochrome? True
3437
Is cmul2.exr monochrome? False
3538
color range counts = (4, 8, 4)
3639
Nonzero region is: 100 180 100 180 0 1 0 3
37-
SHA-1 of bsplinekernel.exr is: D5826B66A5313F9A32D42C5CF49C90EC4E7F84BF
40+
SHA-1 of bsplinekernel.exr valid: True
41+
zover closer fg wins: True
42+
text_size defined: True width>0: True
43+
textcentered wrote: True
44+
render shapes nonzero: True
45+
46+
Testing additional IBA bindings:
47+
copy size: 128 96 3
48+
repremult ok: True
49+
deep_merge deep: True samples@0,0: 1
50+
demosaic size: 256 x 172
3851
R hist: (10000, 0, 0, 0)
3952
G hist: (10000, 0, 0, 0)
4053
B hist: (0, 10000, 0, 0)
@@ -219,9 +232,13 @@ Comparing "box3.exr" and "../../../testsuite/oiiotool-fixnan/ref/box3.exr"
219232
PASS
220233
Comparing "a_over_b.exr" and "../../../testsuite/oiiotool-composite/ref/a_over_b.exr"
221234
PASS
222-
Comparing "tahoe-small.tx" and "ref/tahoe-small.tx"
235+
Comparing "zover.exr" and "ref/zover.exr"
236+
PASS
237+
Comparing "render-shapes.tif" and "ref/render-shapes.tif"
223238
PASS
224-
Comparing "text.tif" and "../../../testsuite/oiiotool-text/ref/text-freetype2.7.tif"
239+
Comparing "deep_merge.exr" and "ref/deep_merge.exr"
225240
PASS
226-
Comparing "textcentered.tif" and "ref/textcentered.tif"
241+
Comparing "demosaic.tif" and "ref/demosaic.tif"
242+
PASS
243+
Comparing "tahoe-small.tx" and "ref/tahoe-small.tx"
227244
PASS
913 Bytes
Binary file not shown.
460 Bytes
Binary file not shown.

testsuite/python-imagebufalgo/run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@
6060
"tahoe-filled.tif",
6161
"box3.exr",
6262
"a_over_b.exr",
63+
"zover.exr",
64+
"render-shapes.tif",
65+
"deep_merge.exr",
66+
"demosaic.tif",
6367
"tahoe-small.tx",
64-
"text.tif", "textcentered.tif",
6568
"out.txt"
6669
]
6770
# command += checkref (f)

testsuite/python-imagebufalgo/src/test_imagebufalgo.py

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
416416
print ("Relative comparison: of flip.tif and flop.tif")
417417
print (" warns", compresults.nwarn, "fails", compresults.nfail)
418418

419-
# compare_Yee,
419+
# compare_Yee
420+
yee = oiio.CompareResults()
421+
ok = ImageBufAlgo.compare_Yee(ImageBuf("flip.tif"), ImageBuf("flop.tif"), yee)
422+
print ("compare_Yee ok:", ok, "nfail:", yee.nfail, "mean:", yee.meanerror >= 0)
420423

421424
# FLIP_diff
422425
black = make_constimage(64, 64, 3, oiio.FLOAT, (0, 0, 0))
@@ -437,14 +440,17 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
437440
assert 60 < ppd < 80
438441

439442
# isConstantColor, isConstantChannel
440-
441443
b = ImageBuf (ImageSpec(256,256,3,oiio.UINT8))
442444
ImageBufAlgo.fill (b, (1,0.5,0.5))
443445
v = ImageBufAlgo.isConstantColor (b)
444446
assert v is not None
445447
print ("isConstantColor on pink image is (%.5g %.5g %.5g)" % (v[0], v[1], v[2]))
446448
v = ImageBufAlgo.isConstantColor (checker)
447449
print ("isConstantColor on checker is ", v)
450+
print ("isConstantChannel pink R=1:",
451+
ImageBufAlgo.isConstantChannel(b, 0, 1.0))
452+
print ("isConstantChannel checker G=0.5:",
453+
ImageBufAlgo.isConstantChannel(checker, 1, 0.5))
448454

449455
b = ImageBuf("cmul1.exr")
450456
print ("Is", b.name, "monochrome? ", ImageBufAlgo.isMonochrome(b))
@@ -523,8 +529,10 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
523529
write (b, "tahoe-laplacian.tif", oiio.UINT8)
524530

525531
# computePixelHashSHA1
526-
print ("SHA-1 of bsplinekernel.exr is: " +
527-
ImageBufAlgo.computePixelHashSHA1(bsplinekernel))
532+
sha1 = ImageBufAlgo.computePixelHashSHA1(bsplinekernel)
533+
sha1_valid = (len(sha1) == 40
534+
and all(c in '0123456789ABCDEF' for c in sha1))
535+
print ("SHA-1 of bsplinekernel.exr valid:", sha1_valid)
528536

529537
# fft, ifft
530538
blue = ImageBufAlgo.channels (ImageBuf(OIIO_TESTSUITE_ROOT+"/common/tahoe-tiny.tif"), (2,))
@@ -559,14 +567,28 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
559567
ImageBuf(OIIO_TESTSUITE_ROOT+"/oiiotool-composite/src/b.exr"))
560568
write (b, "a_over_b.exr")
561569

562-
# FIXME - no test for zover (not in oiio-composite either)
563-
570+
# zover
571+
zspec = ImageSpec(4, 4, 5, oiio.FLOAT)
572+
zspec.channelnames = ("R", "G", "B", "A", "Z")
573+
zspec.z_channel = 4
574+
zA = ImageBuf(zspec)
575+
ImageBufAlgo.fill(zA, (0.5, 0.5, 0.5, 1.0, 10.0))
576+
zB = ImageBuf(zspec)
577+
ImageBufAlgo.fill(zB, (0.0, 0.0, 0.0, 1.0, 15.0))
578+
ImageBufAlgo.fill(zB, (1.0, 1.0, 1.0, 1.0, 5.0), oiio.ROI(2, 4, 1, 3))
579+
b = test_iba(ImageBufAlgo.zover, zA, zB, True)
580+
write(b, "zover.exr", oiio.FLOAT)
581+
p = b.getpixel(3, 2)
582+
print ("zover closer fg wins:", p[0] > 0.9 and p[4] < 10)
583+
584+
# render_text (default font only -- DroidSerif is not guaranteed)
564585
b = make_constimage (320, 240, 3, oiio.FLOAT)
565-
ImageBufAlgo.render_text (b, 25, 50, "Hello, world",
566-
16, "DroidSerif", (1,1,1))
567-
ImageBufAlgo.render_text (b, 50, 120, "Go Big Red!",
568-
42, "", (1,0,0))
586+
ImageBufAlgo.render_text (b, 25, 50, "Hello, world", 16, "", (1,1,1))
587+
ImageBufAlgo.render_text (b, 50, 120, "Go Big Red!", 42, "", (1,0,0))
569588
write (b, "text.tif", oiio.UINT8)
589+
ts = ImageBufAlgo.text_size ("Hello, world", 16)
590+
print ("text_size defined:", ts.defined,
591+
"width>0:", ts.width > 0 if ts.defined else False)
570592

571593
b = make_constimage (320, 240, 3, oiio.FLOAT)
572594
broi = b.roi
@@ -576,8 +598,41 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
576598
y = broi.ybegin + broi.height//2 - (textsize.ybegin + textsize.height//2)
577599
ImageBufAlgo.render_text (b, x, y, "Centered", 40)
578600
write (b, "textcentered.tif", oiio.UINT8)
579-
580-
# FIXME - need tests for render_point, render_line, render_box
601+
print ("textcentered wrote:", not b.has_error)
602+
603+
# render_line, render_box (render_point tested above in normalize)
604+
shapes = make_constimage (64, 64, 3, oiio.UINT8, (0, 0, 0))
605+
ImageBufAlgo.render_line (shapes, 5, 5, 58, 58, (1, 0, 0))
606+
ImageBufAlgo.render_box (shapes, 10, 10, 54, 54, (0, 1, 0))
607+
write (shapes, "render-shapes.tif", oiio.UINT8)
608+
nz = ImageBufAlgo.nonzero_region(shapes)
609+
print ("render shapes nonzero:", nz.defined)
610+
611+
print ("\nTesting additional IBA bindings:")
612+
613+
# copy
614+
src = ImageBuf(OIIO_TESTSUITE_ROOT+"/common/tahoe-tiny.tif")
615+
b = test_iba(ImageBufAlgo.copy, src)
616+
print ("copy size:", b.spec().width, b.spec().height, b.spec().nchannels)
617+
618+
# repremult
619+
unprem = ImageBuf(OIIO_TESTSUITE_ROOT+"/common/unpremult.tif")
620+
b = test_iba(ImageBufAlgo.repremult, unprem)
621+
print ("repremult ok:", not b.has_error)
622+
623+
# deep_merge (tiny deep images)
624+
deep_a = ImageBuf(OIIO_TESTSUITE_ROOT+"/oiiotool-deep/src/deep-onesample.exr")
625+
deep_b = ImageBuf(OIIO_TESTSUITE_ROOT+"/oiiotool-deep/src/deep-nosamples.exr")
626+
b = test_iba(ImageBufAlgo.deep_merge, deep_a, deep_b)
627+
print ("deep_merge deep:", b.deep, "samples@0,0:", b.deep_samples(0, 0))
628+
write (b, "deep_merge.exr")
629+
630+
# demosaic
631+
bayer = ImageBuf(OIIO_TESTSUITE_ROOT+"/common/bayer.png")
632+
b = test_iba(ImageBufAlgo.demosaic, bayer, layout="BGGR",
633+
white_balance_mode="manual", white_balance=(1.0, 1.0, 1.0, 1.0))
634+
print ("demosaic size:", b.spec().width, "x", b.spec().height)
635+
write (b, "demosaic.tif", oiio.UINT8)
581636

582637
# histogram, histogram_draw,
583638
b = make_constimage (100, 100, 3, oiio.UINT8, (.1, .2, .3))

0 commit comments

Comments
 (0)