Mercurial > louis > kiibohd-controller
annotate Scan/STLcd/bitmap2Struct.py @ 332:2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sat, 18 Apr 2015 11:24:15 -0700 |
parents | |
children | 63b1d003fd50 cba3cefc6e56 |
rev | line source |
---|---|
332
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 # Copyright (C) 2015 by Jacob Alexander |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
4 # |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 # This file is free software: you can redistribute it and/or modify |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 # it under the terms of the GNU General Public License as published by |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 # the Free Software Foundation, either version 3 of the License, or |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 # (at your option) any later version. |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 # |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 # This file is distributed in the hope that it will be useful, |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 # GNU General Public License for more details. |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 # |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 # You should have received a copy of the GNU General Public License |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 # along with this file. If not, see <http://www.gnu.org/licenses/>. |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 # Imports |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 import sys |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
21 from array import * |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
22 from PIL import Image |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
23 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
24 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
25 # Convenience class to deal with converting images to a C array |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
26 class STLcdGraphic: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
27 # Some constants for the LCD Driver |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
28 page_width = 8 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
29 page_max_length = 132 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
30 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
31 array('B') |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
32 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
33 def __init__( self, height, width ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
34 self.height = height |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
35 self.width = width |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
36 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
37 # Calculate number of pages |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
38 self.page_count = int( self.height / self.page_width ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
39 self.page_length = self.width |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
40 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
41 # Initialize pages to 0's |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
42 self.page_data = [] |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
43 for page in range( 0, self.page_count ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
44 self.page_data.append( array( 'B', [0] * self.page_length ) ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
45 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
46 def setpixel( self, x, y ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
47 # Calculate which page |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
48 page = int( ( self.height - y ) / self.page_width ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
49 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
50 if page == 4: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
51 print("YAR", (x,y)) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
52 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
53 # Calculate which byte |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 byte = x |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
55 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 # Calculate which bit |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
57 bit = int( ( self.height - y ) % self.page_width ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
58 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
59 # Set pixel bit |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
60 self.page_data[ page ][ byte ] |= (1 << bit) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
62 def getpage( self, page ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
63 return self.page_data[ page ] |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
64 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
65 def getarray( self ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
66 struct = "{\n" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
67 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
68 for page in range( 0, self.page_count ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
69 for elem in self.page_data[ page ]: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 struct += "0x{0:02x}, ".format( elem ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
71 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
72 if page != self.page_count - 1: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
73 struct += "\n" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
74 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 struct += "\n}" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
76 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
77 return struct |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
78 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
79 # Prints out what the image will look like on the display |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
80 def preview( self ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
81 # Top border first |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
82 display = "+" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
83 for pixel in range( 0, self.width ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
84 display += "-" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
85 display += "+\n" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
86 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
87 # Each Page |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
88 for page in range( self.page_count - 1, -1, -1 ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
89 # Each Bit (Line) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
90 for line in range( 7, -1, -1 ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
91 # Border |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
92 display += "|" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
93 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
94 # Each Byte (Column/Pixel) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
95 for byte in range( 0, self.width ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
96 if self.page_data[ page ][ byte ] & (1 << line): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
97 display += "*" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
98 else: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
99 display += " " |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
100 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
101 # Border |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
102 display += "|\n" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
103 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
104 # Bottom border |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
105 display += "+" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
106 for pixel in range( 0, self.width ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
107 display += "-" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
108 display += "+\n" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
109 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
110 return display |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
111 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
112 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
113 filename = "ic_logo_lcd.bmp" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
114 max_height = 32 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
115 max_width = 128 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
116 x_offset = 0 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
117 y_offset = 0 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
118 output_image = STLcdGraphic( max_height, max_width ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
119 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
120 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
121 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
122 # Load the input filename and convert to black & white |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
123 try: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
124 input_image = Image.open( filename ).convert('1') |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
125 except: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
126 print( "Unable to load image '{0}'".format( filename ) ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
127 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
128 # Check the image size to see if within the bounds of the display |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
129 if input_image.size[0] > max_width or input_image.size[1] > max_height: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
130 print( "ERROR: '{0}:{1}' is too large, must be no larger than {2}x{3}".format( |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
131 filename, |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
132 ( input_image.format, input_image.size, input_image.mode ), |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
133 max_width, |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
134 max_height ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
135 ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
136 sys.exit( 1 ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
137 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
138 # Center the image |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
139 height_start = int( ( max_height - input_image.size[1] ) / 2 ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
140 height_end = int( height_start + input_image.size[1] ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
141 width_start = int( ( max_width - input_image.size[0] ) / 2 ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
142 width_end = int( width_start + input_image.size[0] ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
143 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
144 #print( height_start ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
145 #print( height_end ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
146 #print( width_start ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
147 #print( width_end ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
148 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
149 # Iterate over all of the pixels |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
150 # Also prepare the debug view of the image (disp_test) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
151 disp_test = "+" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
152 for pixel in range( 0, max_width ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
153 disp_test += "-" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
154 disp_test += "+\n" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
155 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
156 for y in range( 0, max_height ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
157 disp_test += "|" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
158 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
159 # Check if within height range |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
160 if not ( y >= height_start and y < height_end ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
161 disp_test += " " * max_width + "|\n|" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
162 continue |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
163 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
164 for x in range( 0, max_width ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
165 # Check if within width range |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
166 if not ( x >= width_start and x < width_end ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
167 disp_test += " " |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
168 continue |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
169 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
170 # Use image value to determine pixel |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
171 try: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
172 if input_image.getpixel( (x - width_start, y - height_start) ) == 0: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
173 disp_test += "*" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
174 output_image.setpixel( x, y + 1 ) # +1 is due to page boundary |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
175 else: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
176 disp_test += " " |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
177 except IndexError: |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
178 print( (x - width_start,y - height_start) ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
179 pass |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
180 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
181 disp_test += "|\n" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
182 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
183 disp_test += "+" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
184 for pixel in range( 0, max_width ): |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
185 disp_test += "-" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
186 disp_test += "+\n" |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
187 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
188 # BMP Conversion preview |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
189 print( disp_test ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
190 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
191 |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
192 print ( output_image.preview() ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
193 #print () |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
194 print( "uint8_t array[] = {0};".format( output_image.getarray() ) ) |
2e0074f75855
Adding example logo to the lcdtest and bmp conversion script.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
195 |