[Bugfix][Multimodal] Honor RGB PNG transparency when loading images (#61986)

Signed-off-by: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com>
Co-authored-by: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com>
This commit is contained in:
alp
2026-10-16 23:09:12 +00:00
committed by GitHub
co-authored by mottopanikeiku
parent 28e92eeff2
commit 2268d83bd9
6 changed files with 102 additions and 16 deletions
+3 -3
View File
@@ -104,12 +104,12 @@ def convert_image_mode(
to_mode: str,
background_color: tuple[int, int, int] | list[int] = (255, 255, 255),
) -> Image.Image:
if image.mode == to_mode:
return image
if to_mode == "RGB" and _has_transparency(image):
if image.mode != "RGBA":
image = image.convert("RGBA")
return rgba_to_rgb(image, background_color)
if image.mode == to_mode:
return image
return image.convert(to_mode)
+3 -8
View File
@@ -16,7 +16,7 @@ from vllm.utils.sparse_utils import (
safe_to_dense,
)
from ..image import convert_image_mode, normalize_image, open_image, rgba_to_rgb
from ..image import convert_image_mode, normalize_image, open_image
from .base import MediaDecodedBudget, MediaIO, MediaWithBytes
MAGIC_NUMPY_PREFIX = b"\x93NUMPY" # https://numpy.org/devdocs/reference/generated/numpy.lib.format.html#format-version-1-0
@@ -74,14 +74,9 @@ class ImageMediaIO(MediaIO[Image.Image]):
"""Convert image mode with custom background color."""
if isinstance(image, MediaWithBytes):
image = image.media
if self.image_mode is None or image.mode == self.image_mode:
if self.image_mode is None:
return image
elif image.mode == "RGBA" and self.image_mode == "RGB":
return rgba_to_rgb(image, self.rgba_background_color)
else:
return convert_image_mode(
image, self.image_mode, self.rgba_background_color
)
return convert_image_mode(image, self.image_mode, self.rgba_background_color)
def load_bytes(self, data: bytes) -> MediaWithBytes[Image.Image]:
try: