forked from adafruit/circuitpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmapfilter_mix.py
More file actions
54 lines (42 loc) · 1.29 KB
/
bitmapfilter_mix.py
File metadata and controls
54 lines (42 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from displayio import Bitmap
import bitmapfilter
import ulab
from dump_bitmap import dump_bitmap_rgb_swapped
from blinka_image import decode_resource
def test_pattern():
return decode_resource("testpattern", 2)
def make_quadrant_bitmap():
b = Bitmap(17, 17, 1)
for i in range(b.height):
for j in range(b.width):
b[i, j] = (i < 8) ^ (j < 8)
return b
q = make_quadrant_bitmap()
b = test_pattern()
dump_bitmap_rgb_swapped(b)
sepia_weights = bitmapfilter.ChannelMixer(
0.393, 0.769, 0.189, 0.349, 0.686, 0.168, 0.272, 0.534, 0.131
)
print("sepia")
bitmapfilter.mix(b, sepia_weights)
dump_bitmap_rgb_swapped(b)
# Red channel only
print("red channel only (note: masked)")
b = test_pattern()
bitmapfilter.mix(b, bitmapfilter.ChannelScale(1, 0, 0), mask=q)
dump_bitmap_rgb_swapped(b)
# Scale green channel
print("scale green channel (note: masked)")
b = test_pattern()
bitmapfilter.mix(b, bitmapfilter.ChannelScale(1, 2, 0), mask=q)
dump_bitmap_rgb_swapped(b)
# Swap R & G channels
print("swap R&G")
b = test_pattern()
bitmapfilter.mix(b, bitmapfilter.ChannelMixerOffset(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0))
dump_bitmap_rgb_swapped(b)
# invert B
print("invert B")
b = test_pattern()
bitmapfilter.mix(b, bitmapfilter.ChannelScaleOffset(1, 0, 1, 0, -1, 1))
dump_bitmap_rgb_swapped(b)