Skip to content

Commit 2314cae

Browse files
authored
Merge pull request #772 from adafruit/TheKitty-patch-98
Add files via upload
2 parents c6f50d0 + 1345a73 commit 2314cae

6 files changed

Lines changed: 727 additions & 0 deletions

File tree

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
### Adafruit logo
2+
3+
"""Adafruit logo created from bitmap,
4+
vectorised and flattened to straight lines by Inkscape
5+
then points extracte from SVG data.
6+
(Other route is to ask Adafruit for vector version!)
7+
"""
8+
9+
### pylint: disable=invalid-name
10+
offset_x = -10
11+
offset_y = 9
12+
13+
data = [
14+
# Removing the box outline
15+
# Group 1
16+
# (2.9962184, 251.49811),
17+
# (2.9962184, 1.4981075),
18+
# (252.99622, 1.4981075),
19+
# (502.99622, 1.4981075),
20+
# (502.99622, 251.49811),
21+
# (502.99622, 501.49811),
22+
# (252.99622, 501.49811),
23+
# (2.9962184, 501.49811),
24+
# (2.9962184, 251.49811),
25+
26+
# Outline of the flower followed by the five
27+
# Group 2
28+
[(342.49622, 454.21659),
29+
(346.959242969, 451.054080156),
30+
(349.16935125, 444.29346125),
31+
(349.74007, 396.99811),
32+
(349.42067, 348.99811),
33+
(346.15117, 331.03534),
34+
(341.803838594, 322.622872031),
35+
(336.10557625, 315.17921375),
36+
(320.50984, 301.96305),
37+
(315.24595, 297.9209),
38+
(322.89745, 300.16203),
39+
(338.78867125, 303.15162),
40+
(354.51274, 302.19987),
41+
(370.1502025, 297.314415),
42+
(383.99038, 290.42349),
43+
(425.3782575, 261.03182375),
44+
(455.62553, 237.51598),
45+
(457.673981406, 232.384370781),
46+
(457.63498125, 226.75574125),
47+
(455.656955469, 221.435746094),
48+
(451.88833, 217.23004),
49+
(411.03035375, 203.142875),
50+
(364.28838, 189.00345),
51+
(346.28838, 187.51289),
52+
(334.345396094, 188.212601406),
53+
(324.08682875, 190.43598375),
54+
(314.755874531, 194.422959219),
55+
(305.59573, 200.41345),
56+
(298.69523, 205.64576),
57+
(302.36566, 200.82194),
58+
(309.1910175, 190.60812125),
59+
(313.73687, 180.22634),
60+
(316.80698125, 162.25769875),
61+
(315.61122, 142.49811),
62+
(302.2062, 97.30761225),
63+
(287.72529, 54.616095),
64+
(281.9467975, 48.27558525),
65+
(273.17468, 46.774785),
66+
(268.19440125, 47.74447575),
67+
(264.37486, 50.652804),
68+
(236.2211725, 88.324987),
69+
(209.53225, 127.99811),
70+
(202.6606625, 146.3071125),
71+
(201.25938, 164.93584),
72+
(203.77534, 181.49811),
73+
(206.51089, 188.99811),
74+
(205.9051675, 188.794985),
75+
(203.43769, 185.49811),
76+
(196.64267375, 177.104034375),
77+
(188.75523, 169.97381),
78+
(179.92702375, 164.224298125),
79+
(170.30972, 159.97236),
80+
(160.326935313, 157.051098125),
81+
(148.6087275, 155.3990125),
82+
(102.61522, 154.49966),
83+
(60.16592325, 155.3425225),
84+
(53.6551856875, 157.376749063),
85+
(50.290496, 161.35986),
86+
(47.372345, 168.60014),
87+
(48.89669, 175.71523),
88+
(74.532052, 211.99811),
89+
(94.1360167813, 237.819985),
90+
(108.59780025, 254.2254825),
91+
(120.832361594, 264.08215625),
92+
(133.75466, 270.25756),
93+
(141.60613, 272.36428),
94+
(152.49621, 273.38038),
95+
(164.49621, 273.99811),
96+
(158.0089, 275.81829),
97+
(145.07552625, 280.9514125),
98+
(133.8165275, 288.7022225),
99+
(124.0311775, 299.24521125),
100+
(115.51875, 312.75487),
101+
(98.843153625, 358.473565),
102+
(85.295136, 403.16722),
103+
(85.26685925, 408.01758375),
104+
(86.915068, 411.86681),
105+
(92.4915405, 417.39844125),
106+
(99.473822, 419.49811),
107+
(143.00896275, 406.315715),
108+
(190.36777, 389.38911),
109+
(202.01838, 382.636295),
110+
(212.26301, 373.79104),
111+
(221.50430875, 362.505715),
112+
(227.61924, 348.61117),
113+
(230.74226, 339.12239),
114+
(231.21585, 351.56025),
115+
(232.0963625, 362.919155),
116+
(234.30307, 370.76155),
117+
(242.12680375, 385.41184875),
118+
(253.38592, 399.00254),
119+
(289.43734875, 427.02384125),
120+
(327.49622, 454.1789),
121+
(334.9740875, 456.36105375),
122+
#(342.49622, 454.2166),
123+
#(342.49622, 454.21659),
124+
],
125+
# Group 3
126+
[(269.38148, 328.24811),
127+
(260.235962344, 318.54971125),
128+
(252.98225875, 304.9253925),
129+
(249.221025781, 291.33056),
130+
(249.150290957, 285.780265547),
131+
(250.55292, 281.72062),
132+
(254.134922402, 279.408903848),
133+
(258.744026719, 280.396155156),
134+
(263.916454863, 284.085617324),
135+
(269.18842875, 289.88053375),
136+
(278.175901406, 305.399702969),
137+
(280.963844004, 313.930442559),
138+
(281.99622, 322.17961),
139+
(281.55819875, 326.77132),
140+
(279.99622, 329.49811),
141+
(275.74986, 331.3257375),
142+
#(269.38148, 328.24811),
143+
#(269.38148, 328.24811),
144+
],
145+
# Group 4
146+
[(189.27613, 317.48919),
147+
(186.689292012, 315.017226172),
148+
(186.253231719, 310.95217),
149+
(190.75285125, 299.8028675),
150+
(200.613802656, 287.56145625),
151+
(213.6749, 277.74811),
152+
(220.431676309, 274.964493711),
153+
(225.392900469, 274.551332812),
154+
(228.531887832, 276.197175508),
155+
(229.82195375, 279.59057),
156+
(229.236413574, 284.420064492),
157+
(226.748582656, 290.374207187),
158+
(215.95931, 304.41063),
159+
(208.563450625, 310.792326562),
160+
(201.1146375, 315.3621975),
161+
(194.417365625, 317.725924687),
162+
#(189.27613, 317.48919),
163+
#(189.27613, 317.48919),
164+
],
165+
# Group 5
166+
[(270.49622, 263.99178),
167+
(266.275620215, 261.866190078),
168+
(264.014989219, 259.301005),
169+
(263.608503301, 256.443141797),
170+
(264.95033875, 253.4395175),
171+
(272.455678906, 247.58265375),
172+
(285.68442, 242.90575),
173+
(302.642775, 241.59651875),
174+
(316.00365, 244.06329),
175+
(319.7235275, 248.4713),
176+
(318.6949, 253.83523),
177+
(310.640874688, 259.620080625),
178+
(297.3441375, 263.7845675),
179+
(282.673111563, 265.513523125),
180+
#(270.49622, 263.99178),
181+
#(270.49622, 263.99178),
182+
],
183+
# Group 6
184+
[(202.04337, 252.52942),
185+
(191.235123437, 247.592305),
186+
(181.9467875, 241.23868),
187+
(175.444952812, 234.5173375),
188+
(172.99621, 228.47707),
189+
(174.24765832, 224.997173086),
190+
(177.684219687, 223.036961563),
191+
(189.20598, 223.281585),
192+
(203.748087812, 228.422920938),
193+
(217.49714, 237.67295),
194+
(224.516762344, 246.891496563),
195+
(224.975280254, 250.442414727),
196+
(223.57588375, 253.118295),
197+
(220.450783652, 254.792036523),
198+
(215.732190781, 255.336538437),
199+
#(202.04337, 252.52942),
200+
#(202.04337, 252.52942),
201+
],
202+
# Group 7
203+
[(243.14004, 239.17141),
204+
(240.444360469, 233.682861094),
205+
(238.94700375, 225.78207875),
206+
(239.96685, 206.99811),
207+
(245.63492375, 191.82701),
208+
(249.349385156, 186.715313438),
209+
(252.99622, 184.38871),
210+
(256.799735, 184.899581563),
211+
(259.7174025, 187.9743),
212+
(262.71503, 201.49811),
213+
(261.901079688, 215.476273438),
214+
(258.45465, 228.0064775),
215+
(253.205227813, 237.032497812),
216+
(250.16360918, 239.588868945),
217+
(246.9823, 240.49811),
218+
#(243.14004, 239.17141),
219+
#(243.14004, 239.17141),
220+
]
221+
] ### pylint has a strange opinion on indentation here

CPX_DAC_Guide/dacanim.wav

156 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

CPX_DAC_Guide/python/pngtowav.py

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/python3
2+
3+
### pngtowav v1.0
4+
"""Convert a list of png images to pseudo composite video in wav file form.
5+
6+
This is Python code not intended for running on a microcontroller board.
7+
"""
8+
9+
### MIT License
10+
11+
### Copyright (c) 2019 Kevin J. Walters
12+
13+
### Permission is hereby granted, free of charge, to any person obtaining a copy
14+
### of this software and associated documentation files (the "Software"), to deal
15+
### in the Software without restriction, including without limitation the rights
16+
### to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17+
### copies of the Software, and to permit persons to whom the Software is
18+
### furnished to do so, subject to the following conditions:
19+
20+
### The above copyright notice and this permission notice shall be included in all
21+
### copies or substantial portions of the Software.
22+
23+
### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
### IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
### FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
### AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
### LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
### OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29+
### SOFTWARE.
30+
31+
import getopt
32+
import sys
33+
import array
34+
import wave
35+
36+
import imageio
37+
38+
39+
### globals
40+
### pylint: disable=invalid-name
41+
### start_offset of 1 can help if triggering on oscilloscope
42+
### is missing alternate lines
43+
debug = 0
44+
verbose = False
45+
movie_file = False
46+
output_filename = "dacanim.wav"
47+
fps = 50
48+
threshold = 128 ### pixel level
49+
replaceforsync = False
50+
start_offset = 1
51+
52+
max_dac_v = 3.3
53+
### 16 bit wav files always use signed representation for data
54+
dac_offtop = 2**15-1 ### 3.30V
55+
dac_sync = -2**15 ### 0.00V
56+
### image from 3.00V to 0.30V
57+
dac_top = round(3.00 / max_dac_v * (2**16-1)) - 2**15
58+
dac_bottom = round(0.30 / max_dac_v * (2**16-1)) - 2**15
59+
60+
61+
def usage(exit_code): ### pylint: disable=missing-docstring
62+
print("pngtowav: "
63+
+ "[-d] [-f fps] [-h] [-m] [-o outputfilename] [-r] [-s lineoffset] [-t threshold] [-v]",
64+
file=sys.stderr)
65+
if exit_code is not None:
66+
sys.exit(exit_code)
67+
68+
69+
def image_to_dac(img, row_offset, first_pix, dac_y_range):
70+
"""Convert a single image to DAC output."""
71+
dac_out = array.array("h", [])
72+
73+
img_height, img_width = img.shape
74+
if verbose:
75+
print("W,H", img_width, img_height)
76+
77+
for row_o in range(img_height):
78+
row = (row_o + row_offset) % img_height
79+
### Currently using 0 to (n-1)/n range
80+
y_pos = round(dac_top - row / (img_height - 1) * dac_y_range)
81+
if verbose:
82+
print("Adding row", row, "at y_pos", y_pos)
83+
dac_out.extend(array.array("h",
84+
[dac_sync]
85+
+ [y_pos if x >= threshold else dac_offtop
86+
for x in img[row, first_pix:]]))
87+
return dac_out, img_width, img_height
88+
89+
90+
def write_wav(filename, data, framerate):
91+
"""Create one channel 16bit wav file."""
92+
wav_file = wave.open(filename, "w")
93+
nchannels = 1
94+
sampwidth = 2
95+
nframes = len(data)
96+
comptype = "NONE"
97+
compname = "not compressed"
98+
if verbose:
99+
print("Writing wav file", filename, "at rate", framerate,
100+
"with", nframes, "samples")
101+
wav_file.setparams((nchannels, sampwidth, framerate, nframes,
102+
comptype, compname))
103+
wav_file.writeframes(data)
104+
wav_file.close()
105+
106+
107+
def main(cmdlineargs): ### pylint: disable=too-many-branches
108+
"""main(args)"""
109+
global debug, fps, movie_file, output_filename, replaceforsync ### pylint: disable=global-statement
110+
global threshold, start_offset, verbose ### pylint: disable=global-statement
111+
112+
try:
113+
opts, args = getopt.getopt(cmdlineargs,
114+
"f:hmo:rs:t:v", ["help", "output="])
115+
except getopt.GetoptError as err:
116+
print(err,
117+
file=sys.stderr)
118+
usage(2)
119+
for opt, arg in opts:
120+
if opt == "-d": ### pylint counts these towards too-many-branches :(
121+
debug = 1
122+
elif opt == "-f":
123+
fps = int(arg)
124+
elif opt in ("-h", "--help"):
125+
usage(0)
126+
elif opt == "-m":
127+
movie_file = True
128+
elif opt in ("-o", "--output"):
129+
output_filename = arg
130+
elif opt == "-r":
131+
replaceforsync = True
132+
elif opt == "-s":
133+
start_offset = int(arg)
134+
elif opt == "-t":
135+
threshold = int(arg)
136+
elif opt == "-v":
137+
verbose = True
138+
else:
139+
print("Internal error: unhandled option",
140+
file=sys.stderr)
141+
sys.exit(3)
142+
143+
dac_samples = array.array("h", [])
144+
145+
### Decide whether to replace first column with sync pulse
146+
### or add it as an additional column
147+
first_pix = 1 if replaceforsync else 0
148+
149+
### Read each frame, either
150+
### many single image filenames in args or
151+
### one or more video (animated gifs) (needs -m on command line)
152+
dac_y_range = dac_top - dac_bottom
153+
row_offset = 0
154+
for arg in args:
155+
if verbose:
156+
print("PROCESSING", arg)
157+
if movie_file:
158+
images = imageio.mimread(arg)
159+
else:
160+
images = [imageio.imread(arg)]
161+
162+
for img in images:
163+
img_output, width, height = image_to_dac(img, row_offset,
164+
first_pix, dac_y_range)
165+
dac_samples.extend(img_output)
166+
row_offset += start_offset
167+
168+
write_wav(output_filename, dac_samples,
169+
(width + (1 - first_pix)) * height * fps)
170+
171+
172+
if __name__ == "__main__":
173+
main(sys.argv[1:])

0 commit comments

Comments
 (0)