Skip to content

Commit fc65829

Browse files
feat: pack uint8 BGR non-planar format images
1 parent 06c1c80 commit fc65829

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ wheels/
88

99
# Virtual environments
1010
.venv
11-
.env
11+
.env*
1212

1313
docs/_build/
1414

src/resolver_athena_client/client/transformers/core.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_expected_raw_size = EXPECTED_WIDTH * EXPECTED_HEIGHT * 3
2020

2121

22-
def _is_raw_rgb_expected_size(data: bytes) -> bool:
22+
def _is_raw_brg_expected_size(data: bytes) -> bool:
2323
"""Detect if data is already a raw RGB array of expected size."""
2424
return len(data) == _expected_raw_size
2525

@@ -37,7 +37,7 @@ async def resize_image(image_data: ImageData) -> ImageData:
3737

3838
def process_image() -> tuple[bytes, bool]:
3939
# Fast path for raw RGB arrays of correct size
40-
if _is_raw_rgb_expected_size(image_data.data):
40+
if _is_raw_brg_expected_size(image_data.data):
4141
return image_data.data, False # No transformation needed
4242

4343
# Try to load the image data directly
@@ -55,8 +55,17 @@ def process_image() -> tuple[bytes, bool]:
5555
else:
5656
resized_image = rgb_image
5757

58-
# Convert to raw RGB bytes (C-order: height x width x channels)
59-
return resized_image.tobytes(), True # Data was transformed
58+
rgb_bytes = resized_image.tobytes()
59+
60+
# Convert RGB to BGR by swapping channels
61+
brg_bytes = bytearray(len(rgb_bytes))
62+
brg_bytes[:] = rgb_bytes # Initialize with RGB data
63+
64+
for i in range(0, len(rgb_bytes), 3):
65+
brg_bytes[i] = rgb_bytes[i + 2] # B
66+
brg_bytes[i + 2] = rgb_bytes[i] # R
67+
68+
return bytes(brg_bytes), True # Data was transformed
6069

6170
# Use thread pool for CPU-intensive processing
6271
resized_bytes, was_transformed = await asyncio.to_thread(process_image)

0 commit comments

Comments
 (0)