python-codecs: fix pil rgba to jpg. fix image close race condition.

This commit is contained in:
Koushik Dutta
2023-05-27 22:46:55 -07:00
parent 2063e3822a
commit dd98f12f2a
5 changed files with 18 additions and 10 deletions

View File

@@ -144,6 +144,7 @@ class GstImage(scrypted_sdk.Image):
if bands and bands != capsBands:
reformat = format
colored = None
if reformat or crop:
colored = image
image = await image.toImageInternal(
@@ -152,8 +153,6 @@ class GstImage(scrypted_sdk.Image):
"format": reformat,
}
)
asyncio.ensure_future(colored.close(), loop = asyncio.get_event_loop())
try:
return await image.toBuffer(
{
@@ -162,6 +161,8 @@ class GstImage(scrypted_sdk.Image):
)
finally:
await image.close()
if colored:
await colored.close()
finally:
gst_buffer.unmap(info)

View File

@@ -54,7 +54,14 @@ class PILImage(scrypted_sdk.Image):
def save():
bytesArray = io.BytesIO()
pilImage.pilImage.save(bytesArray, format='JPEG')
if pilImage.pilImage.mode == 'RGBA':
rgb = pilImage.pilImage.convert('RGB')
try:
rgb.save(bytesArray, format='JPEG')
finally:
rgb.close()
else:
pilImage.pilImage.save(bytesArray, format='JPEG')
# pilImage.pilImage.save(bytesArray, format=options['format'])
return bytesArray.getvalue()