Skip to content

JP2Grok: let Grok handle jp2 box read/write#14268

Merged
rouault merged 1 commit intoOSGeo:masterfrom
boxerab:jp2_boxes
Apr 6, 2026
Merged

JP2Grok: let Grok handle jp2 box read/write#14268
rouault merged 1 commit intoOSGeo:masterfrom
boxerab:jp2_boxes

Conversation

@boxerab
Copy link
Copy Markdown
Contributor

@boxerab boxerab commented Mar 31, 2026

What does this PR do?

The current JP2Grok driver handles read, write and rewrite of JP2 boxes. This PR allows Grok to handle read
and write (not re-write), as it is more efficient to let the codec itself manage the boxes.

No new unit tests have been added as the existing ones will test these changes.

AI tool usage

  • AI (Copilot or something similar) supported my development of this PR. See our policy about AI tool use. Use of AI tools must be indicated.

Tasklist

  • Make sure code is correctly formatted (cf pre-commit configuration)
  • Add test case(s)
  • Add documentation
  • Updated Python API documentation (swig/include/python/docs/)
  • Review
  • Adjust for comments
  • All CI builds and checks have passed

@rouault
Copy link
Copy Markdown
Member

rouault commented Mar 31, 2026

I'm skeptical about the added benefit vs maintenance overhead. Would you have done this PR without AI assistance? They are pretty good at cluttering code bases...

@aaron-boxer
Copy link
Copy Markdown

I'm skeptical about the added benefit vs maintenance overhead. Would you have done this PR without AI assistance? They are pretty good at cluttering code bases...

I hear your point, I appreciate your rapid code reviews, and don't want to flood the project with PRs. My plan, which is now easier with AI help, is to shift as much functionality as possible away from the driver and into the codec. Since Grok is already parsing the metadata, it isn't efficient to have the driver duplicate this effort with a second parse.

After this PR, and a second one to shift Box rewrite to the library, there won't be any more significant code churn on the driver. Just bug fixes as they show themselves.

@rouault
Copy link
Copy Markdown
Member

rouault commented Apr 1, 2026

My plan, which is now easier with AI help, is to shift as much functionality as possible away from the driver and into the codec

yes but that actually turns into more code being written... I'm a bit skeptical about the performance impact of doing the JP2 boxes analysis twice. Is that significant compared to actual JPEG2000 decompression... ?

@boxerab
Copy link
Copy Markdown
Contributor Author

boxerab commented Apr 1, 2026

My plan, which is now easier with AI help, is to shift as much functionality as possible away from the driver and into the codec

yes but that actually turns into more code being written... I'm a bit skeptical about the performance impact of doing the JP2 boxes analysis twice. Is that significant compared to actual JPEG2000 decompression... ?

You're right, there is more code. The way I see it is:

  1. this is a micro-optimization : it's not a significant perf hit to parse twice, but when combined with other micro optimizations, it begins to add up.

  2. we get more separation of concerns: the driver is mainly passing metadata and pixels back and forth, and letting the Grok library worry about the details of the codec implementation.

  3. we can support transcoding: with box rewriting, we can add support for Grok transcoding: the library can, among other things, add PLT, TLM and SOP/EPH markers, or change progression. No new GDAL API is needed as the driver can simply detect when input and output are both JP2 and do the transcoding.

  4. the code is already written, tested and will be maintained by me

And, as I said, there only a few more iterations needed on the code and then it will enter maintenance mode.

@boxerab boxerab force-pushed the jp2_boxes branch 2 times, most recently from 8be9856 to 7589a1f Compare April 4, 2026 15:18
@boxerab
Copy link
Copy Markdown
Contributor Author

boxerab commented Apr 4, 2026

@rouault I have reworked the PR to minimize code changes - it still avoids reading the JP2 header twice in the JP2Grok driver.

Comment thread frmts/grok/grkdatasetbase.h Outdated
Comment thread frmts/grok/grkdatasetbase.h Outdated
Comment thread frmts/opjlike/jp2opjlikedataset.cpp Outdated
Comment thread frmts/opjlike/jp2opjlikedataset.cpp Outdated
@rouault rouault merged commit b436f3f into OSGeo:master Apr 6, 2026
1 check passed
@boxerab boxerab deleted the jp2_boxes branch April 6, 2026 10:25
@aaron-boxer
Copy link
Copy Markdown

Thanks for the reviews and merge!

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.

3 participants