1919_expected_raw_size = EXPECTED_WIDTH * EXPECTED_HEIGHT * 3
2020
2121
22- def _is_raw_brg_expected_size (data : bytes ) -> bool :
23- """Detect if data is already a raw BRG array of expected size."""
22+ def _is_raw_bgr_expected_size (data : bytes ) -> bool :
23+ """Detect if data is already a raw BGR array of expected size."""
2424 return len (data ) == _expected_raw_size
2525
2626
@@ -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_brg_expected_size (image_data .data ):
40+ if _is_raw_bgr_expected_size (image_data .data ):
4141 return image_data .data , False # No transformation needed
4242
4343 # Try to load the image data directly
@@ -57,15 +57,15 @@ def process_image() -> tuple[bytes, bool]:
5757
5858 rgb_bytes = resized_image .tobytes ()
5959
60- # Convert RGB to BRG by swapping channels
61- brg_bytes = bytearray (len (rgb_bytes ))
60+ # Convert RGB to BGR by swapping channels
61+ bgr_bytes = bytearray (len (rgb_bytes ))
6262
6363 for i in range (0 , len (rgb_bytes ), 3 ):
64- brg_bytes [i ] = rgb_bytes [i + 2 ]
65- brg_bytes [i + 1 ] = rgb_bytes [i ]
66- brg_bytes [i + 2 ] = rgb_bytes [i + 1 ]
64+ bgr_bytes [i ] = rgb_bytes [i + 2 ]
65+ bgr_bytes [i + 1 ] = rgb_bytes [i + 1 ]
66+ bgr_bytes [i + 2 ] = rgb_bytes [i ]
6767
68- return bytes (brg_bytes ), True # Data was transformed
68+ return bytes (bgr_bytes ), True # Data was transformed
6969
7070 # Use thread pool for CPU-intensive processing
7171 resized_bytes , was_transformed = await asyncio .to_thread (process_image )
0 commit comments