Repository navigation
fix(data): turn a JPEG GeoTIFF's YCbCr into colours when it is read in place #3544
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -365,7 +365,11 @@ fn read_layout(r: Sparse) -> Result<Parse> { | |
| ColorType::Gray(_) => (1, ColorHint::Gray), | ||
| ColorType::GrayA(_) => (2, ColorHint::GrayAlpha), | ||
| ColorType::RGB(_) => (3, ColorHint::Rgb { alpha: false }), | ||
| 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) | ||
| && dec.find_tag_unsigned::<u16>(Tag::PlanarConfiguration).ok().flatten() != Some(2) => | ||
|
Comment on lines
+369
to
+371
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, a hand-built planar file would pin the guard. Left for the release quality pass. |
||
| { | ||
| (3, ColorHint::Rgb { alpha: false }) | ||
| } | ||
| ColorType::RGBA(_) => (4, ColorHint::Rgb { alpha: true }), | ||
|
|
@@ -761,6 +765,10 @@ pub fn decode_tile_counted(header: &Sparse, layout: &Layout, level: usize, index | |
| } | ||
| } | ||
| } | ||
| // Each level by its own header, as the whole-file reader reads the level it picks (#2761). | ||
| if super::geotiff::is_ycbcr_jpeg(&mut dec) { | ||
| super::geotiff::ycbcr_to_rgb(&mut out); | ||
| } | ||
| if let Some(nd) = layout.nodata { | ||
| let nd = nd as f32; | ||
| for band in &mut out { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::plannedwith 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_translaterefuses to write one (PHOTOMETRIC=YCBCR requires INTERLEAVE=PIXEL). No change.