Skip to content

Commit 982f3ea

Browse files
committed
Import memory and color modules with 'rv_' prefix
1 parent 59b6497 commit 982f3ea

File tree

8 files changed

+46
-46
lines changed

8 files changed

+46
-46
lines changed

red_vision/cameras/dvp_rp2_pio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import array
1919
from machine import Pin, PWM
2020
from uctypes import addressof
21-
from ..utils import memory
21+
from ..utils import memory as rv_memory
2222

2323
class DVP_RP2_PIO():
2424
"""
@@ -247,7 +247,7 @@ def _setup_dmas(self):
247247
self._dma_executer = rp2.DMA()
248248

249249
# Check if the display buffer is in PSRAM.
250-
self._buffer_is_in_psram = memory.is_in_external_ram(self._buffer)
250+
self._buffer_is_in_psram = rv_memory.is_in_external_ram(self._buffer)
251251

252252
# If the buffer is in PSRAM, create the streamer DMA channel and row
253253
# buffer in SRAM.
@@ -261,7 +261,7 @@ def _setup_dmas(self):
261261

262262
# Verify row buffer is in SRAM. If not, we'll still have the same
263263
# latency problem.
264-
if memory.is_in_external_ram(self._row_buffer):
264+
if rv_memory.is_in_external_ram(self._row_buffer):
265265
raise MemoryError("not enough space in SRAM for row buffer")
266266

267267
# Create DMA control register values.

red_vision/cameras/hm01b0.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from .dvp_camera import DVP_Camera
1717
from time import sleep_us
18-
from ..utils import colors
18+
from ..utils import colors as rv_colors
1919

2020
class HM01B0(DVP_Camera):
2121
"""
@@ -300,7 +300,7 @@ def color_mode_default(self):
300300
Returns:
301301
int: Color mode constant
302302
"""
303-
return colors.COLOR_MODE_BAYER_RG
303+
return rv_colors.COLOR_MODE_BAYER_RG
304304

305305
def color_mode_is_supported(self, color_mode):
306306
"""
@@ -311,7 +311,7 @@ def color_mode_is_supported(self, color_mode):
311311
Returns:
312312
bool: True if the color mode is supported, otherwise False
313313
"""
314-
return color_mode == colors.COLOR_MODE_BAYER_RG
314+
return color_mode == rv_colors.COLOR_MODE_BAYER_RG
315315

316316
def open(self):
317317
"""

red_vision/cameras/ov5640.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from .dvp_camera import DVP_Camera
1717
from time import sleep_us
18-
from ..utils import colors
18+
from ..utils import colors as rv_colors
1919

2020
class OV5640(DVP_Camera):
2121
"""
@@ -960,7 +960,7 @@ def color_mode_default(self):
960960
Returns:
961961
int: Color mode constant
962962
"""
963-
return colors.COLOR_MODE_BGR565
963+
return rv_colors.COLOR_MODE_BGR565
964964

965965
def color_mode_is_supported(self, color_mode):
966966
"""
@@ -971,7 +971,7 @@ def color_mode_is_supported(self, color_mode):
971971
Returns:
972972
bool: True if the color mode is supported, otherwise False
973973
"""
974-
return color_mode == colors.COLOR_MODE_BGR565
974+
return color_mode == rv_colors.COLOR_MODE_BGR565
975975

976976
def open(self):
977977
"""

red_vision/cameras/video_capture.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#-------------------------------------------------------------------------------
1111

1212
import cv2
13-
from ..utils import colors
13+
from ..utils import colors as rv_colors
1414

1515
class VideoCapture():
1616
"""
@@ -61,9 +61,9 @@ def retrieve(self, image = None):
6161
"""
6262
color_mode = self._driver.color_mode()
6363
buffer = self._driver.buffer()
64-
if (color_mode == colors.COLOR_MODE_BGR888 or
65-
color_mode == colors.COLOR_MODE_GRAY8 or
66-
color_mode == colors.COLOR_MODE_BGR233): # No conversion available
64+
if (color_mode == rv_colors.COLOR_MODE_BGR888 or
65+
color_mode == rv_colors.COLOR_MODE_GRAY8 or
66+
color_mode == rv_colors.COLOR_MODE_BGR233): # No conversion available
6767
# These color modes are copied directly with no conversion.
6868
if image is not None:
6969
# Copy buffer to provided image.
@@ -72,17 +72,17 @@ def retrieve(self, image = None):
7272
else:
7373
# Return a copy of the buffer.
7474
return (True, buffer.copy())
75-
elif color_mode == colors.COLOR_MODE_BAYER_BG:
75+
elif color_mode == rv_colors.COLOR_MODE_BAYER_BG:
7676
return (True, cv2.cvtColor(buffer, cv2.COLOR_BayerBG2BGR, image))
77-
elif color_mode == colors.COLOR_MODE_BAYER_GB:
77+
elif color_mode == rv_colors.COLOR_MODE_BAYER_GB:
7878
return (True, cv2.cvtColor(buffer, cv2.COLOR_BayerGB2BGR, image))
79-
elif color_mode == colors.COLOR_MODE_BAYER_RG:
79+
elif color_mode == rv_colors.COLOR_MODE_BAYER_RG:
8080
return (True, cv2.cvtColor(buffer, cv2.COLOR_BayerRG2BGR, image))
81-
elif color_mode == colors.COLOR_MODE_BAYER_GR:
81+
elif color_mode == rv_colors.COLOR_MODE_BAYER_GR:
8282
return (True, cv2.cvtColor(buffer, cv2.COLOR_BayerGR2BGR, image))
83-
elif color_mode == colors.COLOR_MODE_BGR565:
83+
elif color_mode == rv_colors.COLOR_MODE_BGR565:
8484
return (True, cv2.cvtColor(buffer, cv2.COLOR_BGR5652BGR, image))
85-
elif color_mode == colors.COLOR_MODE_BGRA8888:
85+
elif color_mode == rv_colors.COLOR_MODE_BGRA8888:
8686
return (True, cv2.cvtColor(buffer, cv2.COLOR_BGRA2BGR, image))
8787
else:
8888
NotImplementedError("Unsupported color mode")

red_vision/displays/dvi_rp2_hstx.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import array
2121
from uctypes import addressof
2222
from ulab import numpy as np
23-
from ..utils import colors
24-
from ..utils import memory
23+
from ..utils import colors as rv_colors
24+
from ..utils import memory as rv_memory
2525

2626
class DVI_RP2_HSTX():
2727
"""
@@ -200,7 +200,7 @@ def color_mode_default(self):
200200
"""
201201
Returns the default color mode for the display.
202202
"""
203-
return colors.COLOR_MODE_BGR565
203+
return rv_colors.COLOR_MODE_BGR565
204204

205205
def color_mode_is_supported(self, color_mode):
206206
"""
@@ -211,7 +211,7 @@ def color_mode_is_supported(self, color_mode):
211211
Returns:
212212
bool: True if the color mode is supported, otherwise False
213213
"""
214-
return color_mode == colors.COLOR_MODE_BGR565
214+
return color_mode == rv_colors.COLOR_MODE_BGR565
215215

216216
def _configure_hstx(self):
217217
"""
@@ -261,7 +261,7 @@ def _configure_hstx(self):
261261
# With BGR color modes, B is the least significant bits, and R is the
262262
# most significant bits. This means the bits are in RGB order, which is
263263
# opposite of what one might expect.
264-
if self._color_mode == colors.COLOR_MODE_BGR233:
264+
if self._color_mode == rv_colors.COLOR_MODE_BGR233:
265265
# BGR233 (00000000 00000000 00000000 RRRGGGBB)
266266
expand_tmds = self._hstx.pack_expand_tmds(
267267
l2_nbits = 2, # 3 bits (red)
@@ -271,7 +271,7 @@ def _configure_hstx(self):
271271
l0_nbits = 1, # 2 bits (blue)
272272
l0_rot = 26, # Shift right 26 bits to align MSB (left 6 bits)
273273
)
274-
elif self._color_mode == colors.COLOR_MODE_GRAY8:
274+
elif self._color_mode == rv_colors.COLOR_MODE_GRAY8:
275275
# GRAY8 (00000000 00000000 00000000 GGGGGGGG)
276276
expand_tmds = self._hstx.pack_expand_tmds(
277277
l2_nbits = 7, # 8 bits (red)
@@ -281,7 +281,7 @@ def _configure_hstx(self):
281281
l0_nbits = 7, # 8 bits (blue)
282282
l0_rot = 0, # Shift right 0 bits to align MSB
283283
)
284-
elif self._color_mode == colors.COLOR_MODE_BGR565:
284+
elif self._color_mode == rv_colors.COLOR_MODE_BGR565:
285285
# BGR565 (00000000 00000000 RRRRRGGG GGGBBBBB)
286286
expand_tmds = self._hstx.pack_expand_tmds(
287287
l2_nbits = 4, # 5 bits (red)
@@ -291,7 +291,7 @@ def _configure_hstx(self):
291291
l0_nbits = 4, # 5 bits (blue)
292292
l0_rot = 29, # Shift right 29 bits to align MSB (left 3 bits)
293293
)
294-
elif self._color_mode == colors.COLOR_MODE_BGRA8888:
294+
elif self._color_mode == rv_colors.COLOR_MODE_BGRA8888:
295295
# BGRA8888 (AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB) alpha is ignored
296296
expand_tmds = self._hstx.pack_expand_tmds(
297297
l2_nbits = 7, # 8 bits (red)
@@ -526,7 +526,7 @@ def _configure_dmas(self):
526526
self._dma_executer = rp2.DMA()
527527

528528
# Check if the display buffer is in PSRAM.
529-
self._buffer_is_in_psram = memory.is_in_external_ram(self._buffer)
529+
self._buffer_is_in_psram = rv_memory.is_in_external_ram(self._buffer)
530530

531531
# If the buffer is in PSRAM, create the streamer DMA channel and row
532532
# buffer in SRAM.
@@ -544,7 +544,7 @@ def _configure_dmas(self):
544544
# BGR233 or GRAY8). Larger color modes (2 or 4 bytes per pixel) can
545545
# only be used with scaling.
546546
hstx_pixels_per_second = machine.freq() / 5
547-
psram_bytes_per_second = memory.external_ram_max_bytes_per_second()
547+
psram_bytes_per_second = rv_memory.external_ram_max_bytes_per_second()
548548
psram_pixels_per_second = psram_bytes_per_second * self._width_scale / self._bytes_per_pixel
549549
if psram_pixels_per_second < hstx_pixels_per_second:
550550
raise ValueError("PSRAM transfer speed too low for specified resolution and color mode")
@@ -555,7 +555,7 @@ def _configure_dmas(self):
555555

556556
# Verify row buffer is in SRAM. If not, we'll still have the same
557557
# latency problem.
558-
if memory.is_in_external_ram(self._row_buffer):
558+
if rv_memory.is_in_external_ram(self._row_buffer):
559559
raise MemoryError("not enough space in SRAM for row buffer")
560560

561561
# We'll use a DMA to trigger the XIP stream. However the RP2350's
@@ -725,7 +725,7 @@ def _create_control_blocks(self):
725725

726726
# The control block array must be in SRAM, otherwise we run into the
727727
# same latency problem with DMA transfers from PSRAM.
728-
if memory.is_in_external_ram(self._control_blocks):
728+
if rv_memory.is_in_external_ram(self._control_blocks):
729729
raise MemoryError("not enough space in SRAM for control block array")
730730

731731
# Create the HSTX command sequences so the control blocks can reference

red_vision/displays/st7789.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from time import sleep_ms
2020
import struct
21-
from ..utils import colors
21+
from ..utils import colors as rv_colors
2222
from .video_display_driver import VideoDisplayDriver
2323

2424
class ST7789(VideoDisplayDriver):
@@ -208,7 +208,7 @@ def color_mode_default(self):
208208
"""
209209
Returns the default color mode for the display.
210210
"""
211-
return colors.COLOR_MODE_BGR565
211+
return rv_colors.COLOR_MODE_BGR565
212212

213213
def color_mode_is_supported(self, color_mode):
214214
"""
@@ -219,7 +219,7 @@ def color_mode_is_supported(self, color_mode):
219219
Returns:
220220
bool: True if the color mode is supported, otherwise False
221221
"""
222-
return color_mode == colors.COLOR_MODE_BGR565
222+
return color_mode == rv_colors.COLOR_MODE_BGR565
223223

224224
def show(self):
225225
"""

red_vision/displays/video_display.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import cv2 as cv
1313
from ulab import numpy as np
14-
from ..utils import colors
14+
from ..utils import colors as rv_colors
1515

1616
class VideoDisplay():
1717
"""
@@ -46,19 +46,19 @@ def imshow(self, image):
4646

4747
# Convert the image to current format and write it to the buffer.
4848
color_mode = self._driver.color_mode()
49-
if (color_mode == colors.COLOR_MODE_GRAY8 or
49+
if (color_mode == rv_colors.COLOR_MODE_GRAY8 or
5050
# No conversion available for the modes below, treat as GRAY8
51-
color_mode == colors.COLOR_MODE_BAYER_BG or
52-
color_mode == colors.COLOR_MODE_BAYER_GB or
53-
color_mode == colors.COLOR_MODE_BAYER_RG or
54-
color_mode == colors.COLOR_MODE_BAYER_GR or
55-
color_mode == colors.COLOR_MODE_BGR233):
51+
color_mode == rv_colors.COLOR_MODE_BAYER_BG or
52+
color_mode == rv_colors.COLOR_MODE_BAYER_GB or
53+
color_mode == rv_colors.COLOR_MODE_BAYER_RG or
54+
color_mode == rv_colors.COLOR_MODE_BAYER_GR or
55+
color_mode == rv_colors.COLOR_MODE_BGR233):
5656
self._convert_to_gray8(image_roi, buffer_roi)
57-
elif color_mode == colors.COLOR_MODE_BGR565:
57+
elif color_mode == rv_colors.COLOR_MODE_BGR565:
5858
self._convert_to_bgr565(image_roi, buffer_roi)
59-
elif color_mode == colors.COLOR_MODE_BGR888:
59+
elif color_mode == rv_colors.COLOR_MODE_BGR888:
6060
self._convert_to_bgr888(image_roi, buffer_roi)
61-
elif color_mode == colors.COLOR_MODE_BGRA8888:
61+
elif color_mode == rv_colors.COLOR_MODE_BGRA8888:
6262
self._convert_to_bgra8888(image_roi, buffer_roi)
6363
else:
6464
raise ValueError("Unsupported color mode")

red_vision/utils/video_driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#-------------------------------------------------------------------------------
1010

1111
from ulab import numpy as np
12-
from . import colors
12+
from . import colors as rv_colors
1313

1414
class VideoDriver():
1515
"""
@@ -51,7 +51,7 @@ def __init__(
5151
self._color_mode = color_mode
5252

5353
# Create or store the image buffer.
54-
self._bytes_per_pixel = colors.bytes_per_pixel(self._color_mode)
54+
self._bytes_per_pixel = rv_colors.bytes_per_pixel(self._color_mode)
5555
buffer_shape = (self._height, self._width, self._bytes_per_pixel)
5656
if buffer is None:
5757
# No buffer provided, create a new one.

0 commit comments

Comments
 (0)