Repository navigation
fix(data): turn a JPEG GeoTIFF's YCbCr into colours when it is read in place - #3544
Conversation
…n place The whole-file reader turned JPEG-compressed YCbCr bands into red, green and blue (opengeos#692); reading a tile at a time kept them as they are, so an orthophoto read in place, or from its web address, drew in wrong colours and Identify gave luma and chroma as its values. Each level is now converted by its own header, before no-data is matched. Part of opengeos#2761.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| ColorType::YCbCr(_) | ||
| if super::geotiff::is_ycbcr_jpeg(&mut dec) | ||
| && dec.find_tag_unsigned::<u16>(Tag::PlanarConfiguration).ok().flatten() != Some(2) => |
There was a problem hiding this comment.
The new PlanarConfiguration != 2 guard changes what a planar YCbCr JPEG does: before, it was read in place (and drawn with wrong colours, since each chunk holds one band and ycbcr_to_rgb skips a single band). Now it falls through to NotTiled. That fix is right, but no test covers the planar branch, so nothing checks that a planar YCbCr JPEG is read whole and converted, rather than read in place. A small case in geotiff.rs's tests (planar, compression 7, YCbCr photometric) asserting Parse::NotTiled in cog::layout, and the whole-file read shown in colour, would pin it.
Category: quality
There was a problem hiding this comment.
Agreed, a hand-built planar file would pin the guard. Left for the release quality pass.
| ColorType::YCbCr(_) if dec.find_tag_unsigned::<u16>(Tag::Compression).ok().flatten() == Some(7) => { | ||
| // A chunk's three bands are turned into colours together, so they are read together. | ||
| ColorType::YCbCr(_) | ||
| if super::geotiff::is_ycbcr_jpeg(&mut dec) |
There was a problem hiding this comment.
Consequence to check: a large planar YCbCr JPEG GeoTIFF (for example, a big orthophoto written with separate bands) used to open in place, so a window or tile read stayed cheap. With this guard it is read whole, so its memory and time now scale with the whole file, and the in-place path that the PR's title describes doesn't apply to it. The PR says it "isn't read in place" but doesn't say what that costs or how big a file it covers. Please give its size as a multiple of the layer (AGENTS.md, Size for real data), and confirm that the whole read is refused past memory::planned with a notice, not left to run out of memory.
Confidence: medium-low (I did not trace the whole-read limit for this path).
Category: performance
There was a problem hiding this comment.
Checked. The whole-file read is bounded: past max_samples() it reads an overview, or every k-th pixel where there is none, and says so, so memory doesn't grow with the file. Such a file should be rare: gdal_translate refuses to write one (PHOTOMETRIC=YCBCR requires INTERLEAVE=PIXEL). No change.
Code reviewTwo commits' worth of change, 2 files, ~55 lines added. The core fix looks right: the YCbCr conversion now runs per level in BugsNone found. Checked: the conversion order against no-data, SecurityNone found. Performance
Quality
AGENTS.mdNone found. The change adds no command, asset, wasm branch, or stored data. The "Size for real data" point is covered in the performance item above. Twins checked
Prior reviewsNo earlier threads on this PR, so no concerns were left out as already raised. Change sizeCompared with main (merge base def6c67 to PR head 5651419).
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
Summary
A JPEG-compressed GeoTIFF usually stores its colours as YCbCr. The whole-file reader turns them into red, green and blue (#692), but reading a tile at a time didn't. A large JPEG orthophoto read in place, from this computer or a web address, drew in wrong colours, and Identify gave luma and chroma as its values. v0.9.0 reads a large local file in place, so it's reached there without doing anything special.
Not in this PR: Identify still gives the overview's pixel for a layer read in place (a later step of #2761). A stretch or range a project saved for the wrong colours isn't changed.
Surfaces: the decoder is shared by the desktop, browser (web addresses), command line, Python and phone. No command, parameter or saved format changes, and no new memory: the bands are converted in place.
Testing
ycbcr_jpeg_is_shown_as_rgb_read_in_place: two levels, and no-data equal to a decoded colour and to a stored luma. It fails without the conversion (81 for 200), and with the conversion moved after no-data.UI evidence
A synthetic 20000 × 20000 JPEG GeoTIFF with red, green, blue, yellow, white and black boxes, opened from this computer:
Related issue
Part of #2761.
Summary by CodeRabbit