Repository navigation
fix(data): an RGBA GeoTIFF with a NaN colour under an opaque alpha is written as floats, not opaque 0 (#2665) #2701
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
234d7e5
4237d19
77404e3
dd4d33b
de1c4f9
256a1ca
4800445
d7701a2
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 |
|---|---|---|
|
|
@@ -34,6 +34,9 @@ | |
| //! | ||
| //! The untiled GeoTIFF ([`super::geotiff::write`]) is written here too, by [`write_strips`]: one | ||
| //! image in strips of rows, with the same predictors, Deflate effort and threads, and no overviews. | ||
| //! | ||
| //! Alpha: a float file's alpha is opaque at 1, so the alpha of an integer raster written as floats | ||
| //! is divided by its opaque value (255 for bytes), as the untiled writer does. | ||
|
|
||
| use std::io::{Seek, SeekFrom, Write}; | ||
| use std::ops::Range; | ||
|
|
@@ -137,10 +140,11 @@ fn fits_shorts(r: &Raster, b: usize) -> bool { | |
| r.data_type == "UInt16" && nodata_ok && ((s.min >= 0.0 && s.max <= 65_535.0) || s.count == 0) | ||
| } | ||
|
|
||
| /// Chooses the file's samples like [`super::geotiff::write`] does: a colour raster's colour bands | ||
| /// (as bytes when they are bytes, alpha kept), otherwise `band` alone. 16-bit rasters stay 16-bit, | ||
| /// and a grey byte raster is written as bytes when no pixel needs a no-data value the bytes can't | ||
| /// hold. Grey with alpha keeps both bands; a palette raster keeps its colour table. | ||
| /// Chooses the file's samples like [`super::geotiff::write`] does, except for a colour cell with | ||
| /// no value under an opaque alpha: it is written see-through here (its alpha 0), not as floats | ||
| /// there. A colour raster's colour bands are written (as bytes when they are bytes, alpha kept), | ||
| /// otherwise `band` alone. 16-bit rasters stay 16-bit, and a grey byte raster is written as bytes | ||
| /// when no pixel needs a no-data value the bytes can't hold. Grey with alpha keeps both bands; a palette raster keeps its colour table. | ||
| fn plan(r: &Raster, band: usize) -> Result<Plan> { | ||
| let int_nodata = |max: f64| r.nodata.filter(|d| (0.0..=max).contains(d) && d.fract() == 0.0).map(|d| d as u16); | ||
| // The type of a set of bands: bytes, else 16-bit when that is what they are, else floats. | ||
|
|
@@ -325,6 +329,7 @@ fn tile_samples(r: &Raster, plan: &Plan, lv: &Level, tx: u32, ty: u32) -> Vec<u8 | |
| let mut raw = Vec::with_capacity(t * t * spp * bps); | ||
| let float_pad = r.nodata.map_or(f32::NAN, |d| d as f32); | ||
| let int_pad = plan.nodata_int.unwrap_or(0); | ||
| let opaque = super::alpha_max(&r.data_type); | ||
| let mut px = vec![f32::NAN; spp]; | ||
| for y in 0..t { | ||
| let oy = ty as usize * t + y; | ||
|
|
@@ -342,6 +347,13 @@ fn tile_samples(r: &Raster, plan: &Plan, lv: &Level, tx: u32, ty: u32) -> Vec<u8 | |
| { | ||
| *alpha = 0.0; | ||
| } | ||
| // A float file's alpha is opaque at 1: an integer raster's is divided by its opaque value. | ||
| // (No no-data tag goes with an alpha band, so none of its cells is a no-data one.) | ||
|
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 comment says no cell of the alpha band is a no-data one, but the source raster can still have a no-data value that equals an alpha value (for example an Int16 RGBA with no-data 32767 and alpha 32767). The COG file has no nodata tag, so after the division that cell is 1.0, an opaque pixel. The map draws the source cell see-through, because Category: bug |
||
| if plan.sample == Sample::Float | ||
| && let Some(alpha) = plan.alpha.and_then(|a| px.get_mut(a)) | ||
| { | ||
| *alpha /= opaque; | ||
| } | ||
| for v in &px { | ||
| match plan.sample { | ||
| Sample::Byte => raw.push(if v.is_nan() { int_pad as u8 } else { v.round().clamp(0.0, 255.0) as u8 }), | ||
|
|
||
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.
The cloud-optimised writer now makes a NaN colour cell under an opaque alpha see-through (alpha 0) without any notice, where the GeoTIFF writers in the same PR report nothing either. The cell's opacity changes from 255 to 0 in the file. AGENTS.md's "Never silent" rule asks a writer that approximates data to say what, how much and where, and the docs paragraph is not a notice through
Session::notifyorToolResult::messages. The see-through result may well be the right representation of a cell with no value, but it needs a count-based notice, or an explicit reason in the doc comment that the rule is met another way.Category: agents-md