|
16 | 16 | # You should have received a copy of the GNU General Public License |
17 | 17 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | 18 |
|
19 | | -import struct |
20 | 19 | from enum import Enum |
21 | 20 |
|
22 | 21 | from serial.tools.list_ports import comports |
23 | 22 |
|
24 | 23 | from library.lcd.lcd_comm import * |
| 24 | +from library.lcd.serialize import image_to_RGB565, chunked |
25 | 25 | from library.log import logger |
26 | 26 |
|
27 | 27 |
|
@@ -175,31 +175,12 @@ def DisplayPILImage( |
175 | 175 | # Prepare bitmap data transmission |
176 | 176 | self.SendCommand(Command.INTOPICMODE) |
177 | 177 |
|
178 | | - pix = image.load() |
179 | | - line = bytes([80]) |
| 178 | + rgb565be = image_to_RGB565(image, "big") |
180 | 179 |
|
181 | 180 | # Lock queue mutex then queue all the requests for the image data |
182 | 181 | with self.update_queue_mutex: |
183 | | - for h in range(image_height): |
184 | | - for w in range(image_width): |
185 | | - R = pix[w, h][0] >> 3 |
186 | | - G = pix[w, h][1] >> 2 |
187 | | - B = pix[w, h][2] >> 3 |
188 | | - |
189 | | - # Color information is 0bRRRRRGGGGGGBBBBB |
190 | | - # Revision A: Encode in Little-Endian (native x86/ARM encoding) |
191 | | - # Revition B: Encode in Big-Endian |
192 | | - rgb = (R << 11) | (G << 5) | B |
193 | | - line += struct.pack('>H', rgb) |
194 | | - |
195 | | - # Send image data by multiple of 64 bytes + 1 command byte |
196 | | - if len(line) >= 65: |
197 | | - self.SendLine(line[0:64]) |
198 | | - line = bytes([80]) + line[64:] |
199 | | - |
200 | | - # Write last line if needed |
201 | | - if len(line) > 0: |
202 | | - self.SendLine(line) |
| 182 | + for chunk in chunked(rgb565be, 63): |
| 183 | + self.SendLine(b"\x50" + chunk) |
203 | 184 |
|
204 | 185 | # Indicate the complete bitmap has been transmitted |
205 | 186 | self.SendCommand(Command.OUTPICMODE) |
0 commit comments