Conversation
9cbd749 to
9a6d2bc
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthrough
ChangesST_MapAlgebra / ST_Grayscale NODATA Preservation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cbd74989f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
raster/rt_pg/rtpostgis.sql.in (1)
4503-4518:⚠️ Potential issue | 🟠 Major | ⚡ Quick winReserve sentinel 255 using a global RGB decision, not per-band.
reservenodatais computed from each band’s ownnodata, so in mixed cases (only one RGB band has NODATA) the other 8BUI bands can keep value255. The grayscale formula can still round to255, which then collides with the output NODATA sentinel once Line 4544 sets band NODATA to255.Use a pre-scan/global flag (any input band has NODATA OR non-INTERSECTION extent) and apply the
0..254reclass to all three bands when reservation is needed.Suggested patch sketch
- hasnodata boolean DEFAULT FALSE; - reservenodata boolean; + hasnodata boolean DEFAULT FALSE; + reservenodata boolean DEFAULT FALSE; + _extenttype text; @@ + _extenttype := upper(coalesce(extenttype, 'INTERSECTION')); + + -- First pass: detect whether any source band has NODATA + FOR idx IN 1.._NBANDS LOOP + rast := _set[idx].rast; + nband := _set[idx].nband; + nodata := `@extschema`@.ST_BandNoDataValue(rast, nband); + IF nodata IS NOT NULL THEN + hasnodata := TRUE; + EXIT; + END IF; + END LOOP; + + reservenodata := hasnodata OR _extenttype != 'INTERSECTION'; + + -- Second pass: normalize/reclass each band FOR idx IN 1.._NBANDS LOOP @@ - reservenodata := nodata IS NOT NULL OR upper(extenttype) != 'INTERSECTION'; - IF `@extschema`@.ST_BandPixelType(rast, nband) != _PIXTYPE OR reservenodata THEN @@ - IF hasnodata OR upper(extenttype) != 'INTERSECTION' THEN + IF reservenodata THEN grayscale := `@extschema`@.ST_SetBandNoDataValue(grayscale, 1, _NODATA); END IF;Also applies to: 4544-4544
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@raster/rt_pg/rtpostgis.sql.in` around lines 4503 - 4518, The `reservenodata` flag is currently computed per-band based on each individual band's nodata value, which causes a collision when different RGB bands have different nodata settings and the grayscale formula rounds to 255. Create a global pre-scan flag that checks if ANY input band has NODATA OR the extent type is not INTERSECTION, before the per-band loop. Use this global flag to apply the 0..254 reclass (the reclassexpr logic) consistently to all three bands when reservation is needed, rather than making per-band decisions. This ensures that when reservation is triggered for any reason, all bands get the same restrictive 0..254 range to prevent collisions with the sentinel value 255 set at line 4544.
🧹 Nitpick comments (1)
raster/rt_pg/rtpg_mapalgebra.c (1)
940-949: ⚡ Quick winRun clang-format on these new loop hunks.
The added
forloops use a standalone brace style that doesn’t match the surrounding C style and likely won’t survive clang-format unchanged. As per coding guidelines, “Format C and C++ code using clang-format, running it only on relevant hunks before submitting patches to avoid unrelated churn.”Suggested formatting-only adjustment
- for (i = 0; i < arg->numraster && !arg->hasnodata; i++) - { + for (i = 0; i < arg->numraster && !arg->hasnodata; i++) { rt_band bandi;- for (i = 0; i < numraster && !arg->bandarg->hasnodata; i++) - { + for (i = 0; i < numraster && !arg->bandarg->hasnodata; i++) { rt_band bandi;Also applies to: 1655-1664
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@raster/rt_pg/rtpg_mapalgebra.c` around lines 940 - 949, The for loop starting with `for (i = 0; i < arg->numraster && !arg->hasnodata; i++)` and the related loop at lines 1655-1664 use a brace style that doesn't match the project's C coding style guidelines. Run clang-format on these specific loop hunks to ensure the formatting aligns with the project's standards and coding conventions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@raster/rt_pg/rtpostgis.sql.in`:
- Around line 4503-4518: The `reservenodata` flag is currently computed per-band
based on each individual band's nodata value, which causes a collision when
different RGB bands have different nodata settings and the grayscale formula
rounds to 255. Create a global pre-scan flag that checks if ANY input band has
NODATA OR the extent type is not INTERSECTION, before the per-band loop. Use
this global flag to apply the 0..254 reclass (the reclassexpr logic)
consistently to all three bands when reservation is needed, rather than making
per-band decisions. This ensures that when reservation is triggered for any
reason, all bands get the same restrictive 0..254 range to prevent collisions
with the sentinel value 255 set at line 4544.
---
Nitpick comments:
In `@raster/rt_pg/rtpg_mapalgebra.c`:
- Around line 940-949: The for loop starting with `for (i = 0; i <
arg->numraster && !arg->hasnodata; i++)` and the related loop at lines 1655-1664
use a brace style that doesn't match the project's C coding style guidelines.
Run clang-format on these specific loop hunks to ensure the formatting aligns
with the project's standards and coding conventions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1d2f8947-df90-4f2b-8ed4-804f47783db6
📒 Files selected for processing (4)
raster/rt_pg/rtpg_mapalgebra.craster/rt_pg/rtpostgis.sql.inraster/test/regress/rt_grayscale.sqlraster/test/regress/rt_grayscale_expected
2da5cdd to
00ffea3
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
raster/rt_pg/rtpostgis.sql.in (1)
4527-4538:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAvoid stats-stretching native 8BUI bands when reserving 255.
Line 4527 now reclassifies already-8BUI bands whenever
reservenodatais true, but lines 4533-4538 mapstats.min..stats.maxinto0..254. For native RGB input, that changes valid color values whenever the data range is narrower than0..255; reserve the sentinel over the full 8BUI domain instead, and keep stats-based normalization for non-8BUI inputs.🐛 Proposed fix
nodata double precision; nodataval integer; + pixtype text; reclassexpr text; hasnodata boolean DEFAULT FALSE; @@ - IF `@extschema`@.ST_BandPixelType(rast, nband) != _PIXTYPE OR reservenodata THEN - stats := `@extschema`@.ST_SummaryStats(rast, nband); + pixtype := `@extschema`@.ST_BandPixelType(rast, nband); + IF pixtype != _PIXTYPE OR reservenodata THEN + IF pixtype = _PIXTYPE THEN + stats.min := 0; + stats.max := _NODATA; + ELSE + stats := `@extschema`@.ST_SummaryStats(rast, nband); + END IF; IF nodata IS NOT NULL THEN nodataval := _NODATA;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@raster/rt_pg/rtpostgis.sql.in` around lines 4527 - 4538, The condition at line 4527 incorrectly applies stats-based remapping whenever reservenodata is true, even for native 8BUI bands, which changes valid color values when the data range is narrower than 0..255. Modify the condition to only apply stats-based normalization for non-8BUI inputs by adding an additional check to determine if the band is a native 8BUI type. When the band is already 8BUI and reservenodata is true, skip the stats calculation and reclassification in lines 4533-4538 and instead simply set nodataval to _NODATA without remapping the data, preserving the original color values while reserving 255 as the sentinel.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@raster/rt_pg/rtpostgis.sql.in`:
- Around line 4527-4538: The condition at line 4527 incorrectly applies
stats-based remapping whenever reservenodata is true, even for native 8BUI
bands, which changes valid color values when the data range is narrower than
0..255. Modify the condition to only apply stats-based normalization for
non-8BUI inputs by adding an additional check to determine if the band is a
native 8BUI type. When the band is already 8BUI and reservenodata is true, skip
the stats calculation and reclassification in lines 4533-4538 and instead simply
set nodataval to _NODATA without remapping the data, preserving the original
color values while reserving 255 as the sentinel.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 115c8019-da1a-402c-be7e-d0303d2de9ca
📒 Files selected for processing (4)
raster/rt_pg/rtpg_mapalgebra.craster/rt_pg/rtpostgis.sql.inraster/test/regress/rt_grayscale.sqlraster/test/regress/rt_grayscale_expected
🚧 Files skipped from review as they are similar to previous changes (2)
- raster/test/regress/rt_grayscale.sql
- raster/rt_pg/rtpg_mapalgebra.c
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00ffea3a13
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Closes #2807 Closes postgis#1100
00ffea3 to
44ccf5b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 44ccf5bca1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
44ccf5b to
4ebfc54
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ebfc54069
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@raster/rt_pg/rtpg_mapalgebra.c`:
- Around line 1116-1122: The current code at line 1117 initializes
arg->hasnodata based only on the selected reference band using
rt_band_get_hasnodata_flag(band), which fails to account for NODATA metadata on
other participating bands in the map algebra operation. Before finalizing
arg->callback.hasnodata, scan through all participating bands (accessible via
arg->raster and arg->hasband) and check if any of them have NODATA flags set
using rt_band_get_hasnodata_flag. If any participating band has NODATA metadata,
ensure arg->hasnodata is set to 1 to properly indicate that the callback output
may produce NULL values from those sources.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6a9537bf-e034-4e05-be8c-fbf42d8ecccb
📒 Files selected for processing (6)
raster/rt_pg/rtpg_mapalgebra.craster/rt_pg/rtpostgis.sql.inraster/test/regress/rt_grayscale.sqlraster/test/regress/rt_grayscale_expectedraster/test/regress/rt_mapalgebra.sqlraster/test/regress/rt_mapalgebra_expected
✅ Files skipped from review due to trivial changes (1)
- raster/test/regress/rt_grayscale_expected
🚧 Files skipped from review as they are similar to previous changes (2)
- raster/rt_pg/rtpostgis.sql.in
- raster/test/regress/rt_grayscale.sql
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
4ebfc54 to
75a13b6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 75a13b621c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
75a13b6 to
799af10
Compare
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
799af10 to
7cccf2a
Compare
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
7cccf2a to
03c0968
Compare
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
03c0968 to
452c0dd
Compare
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
452c0dd to
13c8b3b
Compare
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
13c8b3b to
78dac12
Compare
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
78dac12 to
35c1574
Compare
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
35c1574 to
cdfa181
Compare
Keep map algebra outputs from reserving a NODATA value when source NODATA values are handled by the expression or callback path, while still reserving NODATA for synthesized extent gaps or unhandled source NODATA. Closes #2807 Closes postgis#1100
cdfa181 to
cf5f99b
Compare
Summary
nodata1expr,nodata2expr, andnodatanodataval, so handled extent gaps can return valid minimum-valued pixels without reserving them as NODATAFIRST,SECOND,LAST, and custom-style selected extents, while keepingUNIONgap detection tied to actual source coverageFIRSTextents and coextensiveUNIONwhite pixels remain valid 255 valuesFIRSTextents, handled extent gaps, handled source NODATA, 8BUI white-pixel collisions, and grayscale extent gaps for https://trac.osgeo.org/postgis/ticket/2807Current State
postgis/postgis@4e470f1534795ae4a4c52ad5ad35b8744af9d7087cccf2a1faf2f4a636cd8001f94972540e510f8aValidation
make -C raster/rt_pg -j32make -C extensions/postgis_raster all -j1sudo -n make -C extensions/postgis installsudo -n make -C extensions/postgis_raster installsudo -n make -C raster/rt_pg installPGPASSWORD=postgres PGHOST=127.0.0.1 PGPORT=5432 PGUSER=kom PGDATABASE=postgres make -C raster/test check RUNTESTFLAGS='--extension --verbose' TESTS="$(pwd)/raster/test/regress/rt_mapalgebra $(pwd)/raster/test/regress/rt_grayscale"./utils/check_news.sh .git diff --check upstream/master..HEADgit clang-format --diff upstream/master -- raster/rt_pg/rtpg_mapalgebra.cCloses https://trac.osgeo.org/postgis/ticket/2807
Supersedes closed PR #1056.