Skip to content

iOS fractional crop coordinates cause an incorrect byte offset#97

Open
dodokw wants to merge 1 commit into
mrousavy:mainfrom
dodokw:codex/fix-ios-fractional-crop-offset
Open

iOS fractional crop coordinates cause an incorrect byte offset#97
dodokw wants to merge 1 commit into
mrousavy:mainfrom
dodokw:codex/fix-ios-fractional-crop-offset

Conversation

@dodokw

@dodokw dodokw commented Jul 23, 2026

Copy link
Copy Markdown

@mrousavy

Summary

Fix incorrect iOS cropping when the calculated crop rectangle contains fractional values.

  • Convert crop origins and dimensions to integral pixel values before pointer arithmetic.
  • Prevent a fractional cropY from becoming an unintended in-row byte offset.
  • Keep the source pointer aligned to whole-pixel coordinates.

Fixes #

Root cause

When no explicit crop is provided, the automatic center-crop calculation can produce fractional coordinates.

For example, resizing a 640x480 frame to 576x320 calculates approximately:

  • cropHeight = 355.555
  • cropY = 62.222

Previously, iOS kept these values as CGFloat and converted only the final byte-offset expression to size_t:

cropY * rowBytes + cropX * bytesPerPixel

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.

1 participant