Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ImageBitmap => ImageData on the main thread in all browsers #36

Merged
merged 1 commit into from Jun 4, 2022

Conversation

robertknight
Copy link
Owner

Chrome has a bug where image orientation metadata in JPEG images is lost
when an ImageBitmap is cloned via a structured clone [1]. Therefore we have
to do ImageBitmap => ImageData conversion on the main thread to ensure
that the OCR engine receives decoded image data which respects the image
orientation.

Prior to this fix the rendered image orientation and the OCR output did
not match up in Chrome if the input image was rotated.

Since neither Firefox nor Safari support OffscreenCanvas, this means
that all browsers are now doing ImageBitmap => ImageData conversion on
the main thread.

Fixes #35

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=1332947

Chrome has a bug where image orientation metadata in JPEG images is lost
when an ImageBitmap is cloned via a structured clone [1]. Therefore we have
to do ImageBitmap => ImageData conversion on the main thread to ensure
that the OCR engine receives decoded image data which respects the image
orientation.

Prior to this fix the rendered image orientation and the OCR output did
not match up in Chrome if the input image was rotated.

Since neither Firefox nor Safari support OffscreenCanvas, this means
that all browsers are now doing ImageBitmap => ImageData conversion on
the main thread.

Fixes #35

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=1332947
@robertknight robertknight merged commit 42d7cc2 into main Jun 4, 2022
@robertknight robertknight deleted the chrome-image-clone-workaround branch June 4, 2022 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Work around Chrome bug with JPEG rotation information being lost after image is cloned
1 participant