mirror of
https://github.com/holub/mame
synced 2025-07-23 02:01:08 +03:00

Added a "brightness boost" feature for the shadow mask that works by making the brightness ratio between bright and dark mask pixels closer to 1 for the brighter parts of the image. Added clamping to zero so that underscanning produces a black border. Added a "raster bloom" effect to crt-geom-deluxe that makes the image grow slightly when the average brightness of the screen is high, mimicking a common defect in CRTs.
34 lines
704 B
Python
34 lines
704 B
Python
"""
|
|
Assumes the input RGB image subpixels are all either 0 or 255.
|
|
Counts the bright subpixels in the whole image. This should be divisible by 3.
|
|
Creates a uniform alpha channel containing 255 minus 1/3 of
|
|
the number of bright subpixels.
|
|
Writes the RGBA image to the output file.
|
|
"""
|
|
import sys
|
|
import numpy
|
|
import PIL
|
|
import PIL.Image
|
|
|
|
if len(sys.argv) != 3:
|
|
print("usage: add_alpha.py in.png out.png")
|
|
sys.exit(1)
|
|
|
|
img = PIL.Image.open(sys.argv[1])
|
|
|
|
arr = numpy.asarray(img)
|
|
count = (arr==255).sum()
|
|
assert count%3 == 0
|
|
count //= 3
|
|
|
|
alpha = arr[:,:,0,None]*0 + (255-count)
|
|
|
|
arr = numpy.concatenate((arr,alpha),axis=2)
|
|
|
|
# DEBUG
|
|
#print(arr)
|
|
|
|
out = PIL.Image.fromarray(arr)
|
|
out.save(sys.argv[2])
|
|
|