Skip to content

fix: place offset GIF frames on the full logical screen - #22

Open
parth-garg01 wants to merge 1 commit into
appwrite:mainfrom
parth-garg01:fix/gif-frame-offset
Open

parth-garg01 wants to merge 1 commit into
appwrite:mainfrom
parth-garg01:fix/gif-frame-offset

Conversation

@parth-garg01

Copy link
Copy Markdown

What does this PR do?

A GIF's first frame can cover only part of the GIF's logical screen. image/gif returns that frame with its own bounds (for example (800,0)-(1600,450) on a 1600×450 screen). The rest of the pipeline therefore computed gravity and FocalNet crops relative to the frame, not the whole image.

imageutil.Decode now draws a GIF frame onto a transparent NRGBA canvas the size of the logical screen when the frame's bounds differ from it. The screen size is already checked against MaxPixels, so the canvas stays within the existing limit. GIFs whose first frame fills the screen, which is the common case, are returned unchanged.

Before (main @ 35b155f, 1600×450 GIF with the 800×450 generated-face-left.jpg frame at x=800):

$ curl -s -H 'Content-Type: image/gif' --data-binary @face-left-offset.gif 127.0.0.1:18080/analyze
{"gravity":{"x":0.26323946937918663,"y":0.23157380289501617},"confidence":0.9248611985862869,"source":"face"}

After:

$ curl -s -H 'Content-Type: image/gif' --data-binary @face-left-offset.gif 127.0.0.1:18347/analyze
{"gravity":{"x":0.631202907860279,"y":0.23365748723347984},"confidence":0.9117835906633392,"source":"face"}

For reference, the source JPEG on its own gives x = 0.2625, and (800 + 0.2625 × 800) / 1600 = 0.631.

Test Plan

  • Added TestDecodeGIFPlacesOffsetFrameOnCanvas. It fails on main (decoded bounds = (2,0)-(4,2), want the 4x2 logical screen) and passes with this change.
  • test -z "$(gofmt -l cmd internal tools)", go vet ./..., go test -race ./..., go build ./cmd/autogravity: all pass.
  • go test -race -tags=integration ./... with ONNXRUNTIME_LIB pointing to ONNX Runtime 1.30.0 (macOS arm64) and the checked-in INT8 and YuNet models: all pass.
  • Ran the built server (default backend) on macOS arm64 and sent the offset GIF above, rose.gif, and malformed GIFs. The output is shown above. Malformed GIFs still return 400 invalid image.

Related PRs and Issues

Fixes #21

Have you read the Contributing Guidelines on issues?

Yes.


(Everything below is for the main session only.)

A GIF's first frame may cover only part of its logical screen. image/gif
returns that frame with its own bounds, so gravity and crops were computed
relative to the frame instead of the whole image. Draw the frame onto a
canvas the size of the logical screen before analysis.
@appwrite

appwrite Bot commented Oct 22, 2026

Copy link
Copy Markdown

Autogravity

Project ID: 6a9e5d640016fa6fb653

Sites (1)
Site Status Logs Preview QR
 Docs
autogravity-docs
Queued Queued Authorize Preview URL QR Code

Tip

HTTPS and SSL certificates are handled automatically for all your Sites

@hansi-codes

hansi-codes Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new compositing path addresses the reported coordinate mismatch and the regression test verifies its observable result.

imageutil.Decode now places offset GIF first frames on a transparent canvas matching the GIF's logical screen, while leaving full-screen frames unchanged. A regression test checks the output bounds and pixels both inside and outside the frame.

Verdict New comments Fixed Still open
💬 Commented 0 0 0

Note

@parth-garg01 does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.

📂 Walkthrough · 2
File Change
internal/imageutil/image.go Adds logical-screen canvas compositing for GIFs whose first-frame bounds differ.
internal/imageutil/image_test.go Adds a regression test for an offset GIF frame.

Reviewed 2f9c343 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

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.

🐛 Bug Report: focal point is wrong for GIFs whose first frame does not start at (0, 0)

1 participant