Optimize draw_rgb565 display write speed by skipping slow synchronous canvas updates during raw video frames
This commit is contained in:
+3
-2
@@ -233,7 +233,7 @@ class ILI9341:
|
|||||||
mono = 1 if lum >= 128 else 0
|
mono = 1 if lum >= 128 else 0
|
||||||
self.canvas.pixel(screen_x, screen_y, mono)
|
self.canvas.pixel(screen_x, screen_y, mono)
|
||||||
|
|
||||||
def draw_rgb565(self, x, y, w, h, data):
|
def draw_rgb565(self, x, y, w, h, data, sync_canvas=True):
|
||||||
"""Draw raw RGB565 pixel data on the screen at specified (x,y) with width and height."""
|
"""Draw raw RGB565 pixel data on the screen at specified (x,y) with width and height."""
|
||||||
# Clip coordinates
|
# Clip coordinates
|
||||||
x_start = max(0, x)
|
x_start = max(0, x)
|
||||||
@@ -265,7 +265,8 @@ class ILI9341:
|
|||||||
self.cs(1)
|
self.cs(1)
|
||||||
|
|
||||||
# Sync the internal 1-bit canvas buffer
|
# Sync the internal 1-bit canvas buffer
|
||||||
self._update_mono_canvas_rgb565(x, y, w, h, data)
|
if sync_canvas:
|
||||||
|
self._update_mono_canvas_rgb565(x, y, w, h, data)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# --- SCREENSHOT ---
|
# --- SCREENSHOT ---
|
||||||
|
|||||||
+3
-2
@@ -233,7 +233,7 @@ class ST7796:
|
|||||||
mono = 1 if lum >= 128 else 0
|
mono = 1 if lum >= 128 else 0
|
||||||
self.canvas.pixel(screen_x, screen_y, mono)
|
self.canvas.pixel(screen_x, screen_y, mono)
|
||||||
|
|
||||||
def draw_rgb565(self, x, y, w, h, data):
|
def draw_rgb565(self, x, y, w, h, data, sync_canvas=True):
|
||||||
"""Draw raw RGB565 pixel data on the screen at specified (x,y) with width and height."""
|
"""Draw raw RGB565 pixel data on the screen at specified (x,y) with width and height."""
|
||||||
# Clip coordinates
|
# Clip coordinates
|
||||||
x_start = max(0, x)
|
x_start = max(0, x)
|
||||||
@@ -265,7 +265,8 @@ class ST7796:
|
|||||||
self.cs(1)
|
self.cs(1)
|
||||||
|
|
||||||
# Sync the internal 1-bit canvas buffer
|
# Sync the internal 1-bit canvas buffer
|
||||||
self._update_mono_canvas_rgb565(x, y, w, h, data)
|
if sync_canvas:
|
||||||
|
self._update_mono_canvas_rgb565(x, y, w, h, data)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# --- SCREENSHOT ---
|
# --- SCREENSHOT ---
|
||||||
|
|||||||
+17
-1
@@ -77,8 +77,11 @@ class MCPServer:
|
|||||||
if self.sock is None:
|
if self.sock is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
t0 = 0
|
||||||
|
t1 = 0
|
||||||
try:
|
try:
|
||||||
client, addr = self.sock.accept()
|
client, addr = self.sock.accept()
|
||||||
|
t0 = time.ticks_ms()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
import errno
|
import errno
|
||||||
err = getattr(e, 'errno', None)
|
err = getattr(e, 'errno', None)
|
||||||
@@ -110,6 +113,7 @@ class MCPServer:
|
|||||||
|
|
||||||
header_text = req_bytes[:header_end].decode('utf-8', 'ignore')
|
header_text = req_bytes[:header_end].decode('utf-8', 'ignore')
|
||||||
lines = header_text.split('\r\n')
|
lines = header_text.split('\r\n')
|
||||||
|
t1 = time.ticks_ms()
|
||||||
if len(lines) == 0 or not lines[0]:
|
if len(lines) == 0 or not lines[0]:
|
||||||
client.close()
|
client.close()
|
||||||
return
|
return
|
||||||
@@ -171,6 +175,7 @@ class MCPServer:
|
|||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
body_bytes.extend(chunk)
|
body_bytes.extend(chunk)
|
||||||
|
t2 = time.ticks_ms()
|
||||||
|
|
||||||
# Parse query parameters from path (e.g. /api/screen/raw?x=0&y=0&w=320&h=240)
|
# Parse query parameters from path (e.g. /api/screen/raw?x=0&y=0&w=320&h=240)
|
||||||
width = getattr(self.display, 'width', 320)
|
width = getattr(self.display, 'width', 320)
|
||||||
@@ -186,10 +191,12 @@ class MCPServer:
|
|||||||
elif k == 'y': y = int(v)
|
elif k == 'y': y = int(v)
|
||||||
elif k == 'w': w = int(v)
|
elif k == 'w': w = int(v)
|
||||||
elif k == 'h': h = int(v)
|
elif k == 'h': h = int(v)
|
||||||
|
t3 = time.ticks_ms()
|
||||||
|
|
||||||
# Draw directly using display raw RGB565 method
|
# Draw directly using display raw RGB565 method
|
||||||
self.override_active = True
|
self.override_active = True
|
||||||
self.display.draw_rgb565(x, y, w, h, body_bytes)
|
self.display.draw_rgb565(x, y, w, h, body_bytes, sync_canvas=False)
|
||||||
|
t4 = time.ticks_ms()
|
||||||
|
|
||||||
resp_body = "OK"
|
resp_body = "OK"
|
||||||
resp = "HTTP/1.1 200 OK\r\n"
|
resp = "HTTP/1.1 200 OK\r\n"
|
||||||
@@ -206,6 +213,15 @@ class MCPServer:
|
|||||||
time.sleep_ms(10)
|
time.sleep_ms(10)
|
||||||
continue
|
continue
|
||||||
total_sent += sent
|
total_sent += sent
|
||||||
|
t5 = time.ticks_ms()
|
||||||
|
print("[RAW API Profile] total={}ms: accept_to_header={}ms, recv_body={}ms, route_n_prep={}ms, draw={}ms, send_resp={}ms".format(
|
||||||
|
time.ticks_diff(t5, t0),
|
||||||
|
time.ticks_diff(t1, t0),
|
||||||
|
time.ticks_diff(t2, t1),
|
||||||
|
time.ticks_diff(t3, t2),
|
||||||
|
time.ticks_diff(t4, t3),
|
||||||
|
time.ticks_diff(t5, t4)
|
||||||
|
))
|
||||||
else:
|
else:
|
||||||
# Return 404
|
# Return 404
|
||||||
resp = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
|
resp = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user