Skip to content

fix(raw): fixes cropping when the image is rotated - #5424

Open
antond-weta wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
antond-weta:raw_crop
Open

fix(raw): fixes cropping when the image is rotated#5424
antond-weta wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
antond-weta:raw_crop

Conversation

@antond-weta

Copy link
Copy Markdown
Contributor

Description

This fixes incorrectly positioned crop when the image is rotated.

Tests

I have not added any unit tests specifically for this fix. I'm planning to add some tests later on using generated DNG images, but I doubt that I will get them in time for the v3.2 release. Happy to delay this fix until the tests are ready, if we prefer.

Tested manually with images from several cameras.

Checklist:

  • I have read the guidelines on contributions and code review procedures.
  • I have read the Policy on AI Coding Assistants
    and if I used AI coding assistants, I have an Assisted-by: TOOL / MODEL
    line in the pull request description above.
  • I have updated the documentation if my PR adds features or changes
    behavior.
  • I am sure that this PR's changes are tested in the testsuite.
  • I have run and passed the testsuite in CI before submitting the
    PR, by pushing the changes to my fork and seeing that the automated CI
    passed there. (Exceptions: If most tests pass and you can't figure out why
    the remaining ones fail, it's ok to submit the PR and ask for help. Or if
    any failures seem entirely unrelated to your change; sometimes things break
    on the GitHub runners.)
  • My code follows the prevailing code style of this project and I
    fixed any problems reported by the clang-format CI test.
  • If I added or modified a public C++ API call, I have also amended the
    corresponding Python bindings. If altering ImageBufAlgo functions, I also
    exposed the new functionality as oiiotool options.

@lgritz

lgritz commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

LGTM, though do you have any tests?

@antond-weta

Copy link
Copy Markdown
Contributor Author

I have added image margins and crop info to the DNG generator, seem to be working. Will add some unit tests shortly.

@antond-weta
antond-weta marked this pull request as draft August 26, 2026 02:41
antond-weta and others added 2 commits August 27, 2026 13:17
Co-authored-by: Rémi Achard <remiachard@gmail.com>
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
@antond-weta
antond-weta marked this pull request as ready for review August 27, 2026 03:05
@antond-weta

Copy link
Copy Markdown
Contributor Author

I have added tests

@lgritz

lgritz commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

I'm not sure I understand what happened with the test files. You added crop-36x32.dng, but it also looks like some of the other image test files changed, very slightly, but I'm not sure I understand what changed or why. It doesn't seem like they should be related to the crop fix, or am I misunderstanding?

@antond-weta

Copy link
Copy Markdown
Contributor Author

All test images changed, because I'd added 3 new attributes to the DNG header: DefaultCropOrigin, DefaultCropSize, ActiveArea. By default they match the image resolution, so don't affect any other tests (I had to update one of the existing test's reference output as it mentioned the file size, which had changed).

In crop-36x32.dng I have manually crafted the image margins and crop insets so all numbers are different at all stages of calculation. Tests override the orientation with the raw:user_flip hint to avoid needing storing 4 files.

@lgritz

lgritz commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

testsuite/raw/src/make_malformed_dng.py is a script that creates several specific invalid dng files, to test error handling. A special script is needed because... well, they're malformed, so it's hard to create them any other way.

The script was checked into the repo for reference, to document how those malfomed files were made and I guess be able to make other types of malformed files the future. But the existing malformed files are checked into the repo and I think do not need to be changed, even if you use the script to make new, different files.

But is crop-36x32.dng also malformed? Or is it meant to be a legal file?

Maybe if you are making special purpose valid files and need to do so with a python program, they should have their own script?

@antond-weta

Copy link
Copy Markdown
Contributor Author

crop-36x32.dng is malformed in a way that it doesn't contain all mandatory DNG attributes. It only contains the ones needed for libraw to calculate cropping. Actually I'm not aware of any other ways of generating DNG files. If I were to do that myself, I would have written a script like yours. If you think a separate script would be better, I'm happy to make it, but it would be 90% identical to make_malformed_dng.py

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.

2 participants