21
21
from adafruit_pycamera import imageprocessing
22
22
from adafruit_pycamera import PyCameraBase
23
23
24
+
25
+ blend_50_50 = bitmapfilter .blend_precompute (imageprocessing .alphablend_maker (0.5 ))
26
+ screen = bitmapfilter .blend_precompute (imageprocessing .screen_func )
27
+ overlay = bitmapfilter .blend_precompute (imageprocessing .overlay_func )
28
+ hard_light = bitmapfilter .blend_precompute (imageprocessing .hard_light_func )
29
+ soft_light = bitmapfilter .blend_precompute (imageprocessing .soft_light_func )
30
+ color_dodge = bitmapfilter .blend_precompute (imageprocessing .color_dodge_func )
31
+ # linear_dodge = bitmapfilter.blend_precompute(imageprocessing.linear_dodge_func)
32
+ # divide = bitmapfilter.blend_precompute(imageprocessing.divide_func)
33
+ multiply = bitmapfilter .blend_precompute (imageprocessing .multiply_func )
34
+ # subtract = bitmapfilter.blend_precompute(imageprocessing.subtract_func)
35
+ # color_burn = bitmapfilter.blend_precompute(imageprocessing.color_burn_func)
36
+ # linear_burn = bitmapfilter.blend_precompute(imageprocessing.linear_burn_func)
37
+ # darken_only = bitmapfilter.blend_precompute(min)
38
+ # lighten_only = bitmapfilter.blend_precompute(max)
39
+
40
+
41
+ def blender (f ):
42
+ def inner (b ):
43
+ return bitmapfilter .blend (b , b , testpattern , f )
44
+
45
+ return inner
46
+
47
+
48
+ def reverse_blender (f ):
49
+ def inner (b ):
50
+ return bitmapfilter .blend (b , testpattern , b , f )
51
+
52
+ return inner
53
+
54
+
55
+ inverse_greyscale_weights = bitmapfilter .ChannelMixer (
56
+ 1 - 0.299 ,
57
+ 1 - 0.587 ,
58
+ 1 - 0.114 ,
59
+ 1 - 0.299 ,
60
+ 1 - 0.587 ,
61
+ 1 - 0.114 ,
62
+ 1 - 0.299 ,
63
+ 1 - 0.587 ,
64
+ 1 - 0.114 ,
65
+ )
66
+
67
+ blur_more = [
68
+ 4 ,
69
+ 15 ,
70
+ 24 ,
71
+ 15 ,
72
+ 4 ,
73
+ 15 ,
74
+ 61 ,
75
+ 97 ,
76
+ 61 ,
77
+ 15 ,
78
+ 24 ,
79
+ 97 ,
80
+ 154 ,
81
+ 97 ,
82
+ 24 ,
83
+ 15 ,
84
+ 61 ,
85
+ 97 ,
86
+ 61 ,
87
+ 15 ,
88
+ 4 ,
89
+ 15 ,
90
+ 24 ,
91
+ 15 ,
92
+ 4 ,
93
+ ]
94
+
95
+
96
+ # "Sketch" filter based on
97
+ # https://www.freecodecamp.org/news/sketchify-turn-any-image-into-a-pencil-sketch-with-10-lines-of-code-cf67fa4f68ce/
98
+ def sketch (b ):
99
+ bitmapfilter .mix (b , inverse_greyscale_weights )
100
+ memoryview (auxbuffer )[:] = memoryview (b )
101
+ bitmapfilter .morph (auxbuffer , blur_more )
102
+ bitmapfilter .blend (b , auxbuffer , b , color_dodge )
103
+ bitmapfilter .mix (b , inverse_greyscale_weights ) # get rid of magenta halos
104
+ return b
105
+
106
+
24
107
effects = [
108
+ ("sketch" , sketch ),
109
+ ("50/50" , blender (blend_50_50 )),
110
+ ("multiply" , blender (multiply )),
111
+ ("soft light" , blender (soft_light )),
112
+ ("hard_light" , blender (hard_light )),
25
113
("blue cast" , imageprocessing .blue_cast ),
26
114
("blur" , imageprocessing .blur ),
27
115
("bright" , lambda b : bitmapfilter .mix (b , bitmapfilter .ChannelScale (2.0 , 2.0 , 2.0 ))),
@@ -65,6 +153,9 @@ def cycle(seq):
65
153
pycam = PyCameraBase ()
66
154
pycam .init_display ()
67
155
156
+ testpattern = displayio .Bitmap (208 , 208 , 65535 )
157
+ auxbuffer = displayio .Bitmap (208 , 208 , 65535 )
158
+
68
159
69
160
def main ():
70
161
filename = "/cornell_box_208x208.jpg"
@@ -74,6 +165,9 @@ def main():
74
165
decoder .open (filename )
75
166
decoder .decode (bitmap0 )
76
167
168
+ decoder .open ("/testpattern_208x208.jpg" )
169
+ decoder .decode (testpattern )
170
+
77
171
label = Label (font = FONT , x = 0 , y = 8 )
78
172
pycam .display .root_group = label
79
173
pycam .display .refresh ()
0 commit comments