MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_setalpha

Function test_setalpha

tests/test_pixmap.py:88–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86
87
88def test_setalpha():
89 # pixmap from JPEG file, then add an alpha channel
90 # with 30% transparency
91 pix1 = pymupdf.Pixmap(imgfile)
92 opa = int(255 * 0.3) # corresponding to 30% transparency
93 alphas = [opa] * (pix1.width * pix1.height)
94 alphas = bytearray(alphas)
95 pix2 = pymupdf.Pixmap(pix1, 1) # add alpha channel
96 pix2.set_alpha(alphas) # make image 30% transparent
97 samples = pix2.samples # copy of samples
98 # confirm correct the alpha bytes
99 t = bytearray([samples[i] for i in range(3, len(samples), 4)])
100 assert t == alphas
101
102def test_color_count():
103 '''

Callers

nothing calls this directly

Calls 1

set_alphaMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…