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

pnm-plugin #4253

Merged
merged 12 commits into from May 4, 2024
Merged

pnm-plugin #4253

merged 12 commits into from May 4, 2024

Conversation

ssh4net
Copy link
Contributor

@ssh4net ssh4net commented May 1, 2024

Description

Fixes added:

  • import/export support for 8/16 uint 32-float
  • pnm:bigendian
  • pnm:pfmflip for float pfm files (GIMP flip float PFM files by default, Photoshop do not)
  • update in documentation

Checklist:

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • If I added or modified a C++ API call, I have also amended the
    corresponding Python bindings (and if altering ImageBufAlgo functions, also
    exposed the new functionality as oiiotool options).
  • My code follows the prevailing code style of this project. If I haven't
    already run clang-format before submitting, I definitely will look at the CI
    test that runs clang-format and fix anything that it highlights as being
    nonconforming.

• import/export support for 8/16 uint 32-float
• bigendian
• pfmflip for float pfm files

Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
src/pnm.imageio/pnminput.cpp Outdated Show resolved Hide resolved
return false;
}

m_spec["pnm:pfmflip"] = config.get_int_attribute("pnm:pfmflip", 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

m_spec is for communicating what's in the file to the caller.

config is for the caller to give us instructions about how to read.

So it's unusual to copy something from the config into m_spec. I suspect you are merely trying to communicate that config hint to the later reading functions, but usually what we do in a case like this is just have a bool as a private member of the PNMInput, set it here, and use it as needed in the read_scanline function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think at the very least, we should only set this in m_spec if it really is a pfm file, not for the non-float varieties.

src/doc/builtinplugins.rst Outdated Show resolved Hide resolved
Orthography fix.

Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>

Co-authored-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Vlad (Kuzmin) Erium <shaamaan@gmail.com>
@lgritz
Copy link
Collaborator

lgritz commented May 3, 2024

I'm a little confused, so let me say what I think is going on, and you can confirm or let me know where I'm getting it wrong:

The pbm, pgm, and ppm varieties are stored with scanlines ordered in the file as top-to-bottom (the same as the usual OIIO convention), but the float-based pfm files are conventionally ordered in the file as bottom-to-top. Therefore, by default, reading and writing of the pfm variety will automatically flip the image so that an application calling the OpenImageIO API can, as usual, assume that scanline 0 is the visual "top" (even though it is actually the last scanline stored in the file).

Both the reader and writer accept configuration hints "pnm:pfmflip" (default: 1), which if set to 0 will disable this flipping and ensure that scanline 0 is written as the first in the file (therefore representing what PFM assumes is the visual "bottom" of the image). This hint only affects PFM files and has no effect on the pbm, pgm, or ppm varieties.

@ssh4net
Copy link
Contributor Author

ssh4net commented May 3, 2024

Correct.
pnm:pfmflip is only affecting PFM (float NetPBM) and only because of historical reasons someone from GIMP project decided to have it flipped upside down: https://netpbm.sourceforge.net/doc/pfm.html

If you think it worth to disable flipping to be on the same page with USC ITC (https://pauldebevec.com/Research/HDR/PFM/ ) and Adobe I'm in!

@lgritz
Copy link
Collaborator

lgritz commented May 3, 2024

Is GIMP the only major faction that assumes y=0 is the bottom? Adobe thinks it's the top?

Is there an official "PFM spec" and does it address the issue?

When you encounter pfm files in the wild, do they tend to mostly follow the GIMP convention?

@ssh4net
Copy link
Contributor Author

ssh4net commented May 3, 2024

Gimp, tools from libjxl, NetPBM package... looks like all that use bottom line as y=0.

And there is no official spec for this extension of NetPBM format 🤷‍♂️

Float NetPBM is rarely used, as most of image sources are uint.

@lgritz
Copy link
Collaborator

lgritz commented May 3, 2024

OK, NetPBM seems like the closest to determining what should be the de facto standard, so let's go with flipping by default (for pfm only), with the ability of providing the hint to turn it off if needed.

Could you please add those two paragraphs I wrote above in the introduction to pnm part of the documentation?

Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

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

Code looks fine other than the reporting of the flip attribute upon read for non-pfm files.

I made some suggestions for clarifying the docs regarding flipping.

The rest all looks good to me.

src/doc/builtinplugins.rst Outdated Show resolved Hide resolved
src/doc/builtinplugins.rst Outdated Show resolved Hide resolved
src/doc/builtinplugins.rst Outdated Show resolved Hide resolved
testsuite/pnm/ref/out.txt Outdated Show resolved Hide resolved
return false;
}

m_spec["pnm:pfmflip"] = config.get_int_attribute("pnm:pfmflip", 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think at the very least, we should only set this in m_spec if it really is a pfm file, not for the non-float varieties.

ssh4net and others added 8 commits May 4, 2024 11:41
Co-authored-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Vlad (Kuzmin) Erium <shaamaan@gmail.com>
Co-authored-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Vlad (Kuzmin) Erium <shaamaan@gmail.com>
Co-authored-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Vlad (Kuzmin) Erium <shaamaan@gmail.com>
Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
some text formatting

Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
m_pfm_flip private variable.
Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
revert back
Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
pfm always binary

Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
@ssh4net
Copy link
Contributor Author

ssh4net commented May 4, 2024

@lgritz hope fixed now

src/doc/builtinplugins.rst Outdated Show resolved Hide resolved
Signed-off-by: Larry Gritz <lg@larrygritz.com>
Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

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

I just fixed one last typo myself rather than do another edit cycle for you.

LGTM!

@lgritz lgritz merged commit ed9d8d3 into AcademySoftwareFoundation:master May 4, 2024
24 checks passed
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request May 18, 2024
Fixes added:

- import/export support for 8/16 uint 32-float
- "pnm:bigendian" attribute reports/controls andianness
- "pnm:pfmflip" attribute (when set to 0) can disable the automatic vertical flip of pfm files (GIMP flips float PFM files by default, Photoshop does not)
- update in documentation

---------

Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
Signed-off-by: Vlad (Kuzmin) Erium <shaamaan@gmail.com>
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request May 18, 2024
Fixes added:

- import/export support for 8/16 uint 32-float
- "pnm:bigendian" attribute reports/controls andianness
- "pnm:pfmflip" attribute (when set to 0) can disable the automatic vertical flip of pfm files (GIMP flips float PFM files by default, Photoshop does not)
- update in documentation

---------

Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
Signed-off-by: Vlad (Kuzmin) Erium <shaamaan@gmail.com>
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.

None yet

2 participants