Skip to content

Fix when with pitch != width*BBP in Image Display - #1719

Merged
ahcorde merged 2 commits into
rollingfrom
ahcorde/rolling/camera_plugin_error
May 26, 2026
Merged

Fix when with pitch != width*BBP in Image Display#1719
ahcorde merged 2 commits into
rollingfrom
ahcorde/rolling/camera_plugin_error

Conversation

@ahcorde

@ahcorde ahcorde commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Description

Related to #512

Did you use Generative AI?

Claude Sonnet 4.6

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@ahcorde
ahcorde requested a review from abaeyens May 25, 2026 16:44

@abaeyens abaeyens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

(btw: 16-bit bayer is still broken, but it doesn't have anything to do with these changes, and it's being addressed in #1749)

@ahcorde

ahcorde commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Pulls: #1719
Gist: https://gist.githubusercontent.com/ahcorde/b5a963871eb270e5d9318580ffe9ccfe/raw/1df0a1537a1b80cb8eadebb6b517b200a37475a4/ros2.repos
BUILD args: --packages-above-and-dependencies rviz_default_plugins
TEST args: --packages-above rviz_default_plugins
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/19367

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde
ahcorde merged commit 9eebc57 into rolling May 26, 2026
2 checks passed
@ahcorde
ahcorde deleted the ahcorde/rolling/camera_plugin_error branch May 26, 2026 08:18
@ahcorde

ahcorde commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

https://github.com/Mergifyio backport lyrical kilted jazzy humble

@mergify

mergify Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

backport lyrical kilted jazzy humble

✅ Backports have been created

Details

Cherry-pick of 9eebc57 has failed:

On branch mergify/bp/humble/pr-1719
Your branch is up to date with 'origin/humble'.

You are currently cherry-picking commit 9eebc57c.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   rviz_default_plugins/src/rviz_default_plugins/displays/image/ros_image_texture.cpp

no changes added to commit (use "git add" and/or "git commit -a")

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

ahcorde added a commit that referenced this pull request May 26, 2026
(cherry picked from commit 9eebc57)

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
Co-authored-by: Alejandro Hernández Cordero <alejandro@openrobotics.org>
ahcorde added a commit that referenced this pull request May 26, 2026
(cherry picked from commit 9eebc57)

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
Co-authored-by: Alejandro Hernández Cordero <alejandro@openrobotics.org>
ahcorde added a commit that referenced this pull request Jun 3, 2026
…1762)

(cherry picked from commit 9eebc57)

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
Co-authored-by: Alejandro Hernández Cordero <alejandro@openrobotics.org>
Co-authored-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
abaeyens added a commit to abaeyens/rviz that referenced this pull request Jul 5, 2026
The previous "Bayer input is linear-light, apply sRGB gamma" rule was
hardcoded. Expose it as a per-display "Linear input" BoolProperty on
ImageDisplay; hidden unless the current message is Bayer; default off.
Toggling on a latched frame re-runs the converter without needing a new
publish (mirrors setSmoothScaling).

Now that PR ros2#1719 (buffer repack in update()) has landed
upstream:
- Replace the inline stride-aware 16-bit min/max scan with a call to
  the shared getMinimalAndMaximalValueToNormalize<uint16_t>.
- Delete unreachable defensive stride/alignment checks and the
  now-obsolete odd_stride_16bit_rejected test.

Also: parameterise linear-passthrough tests over all four Bayer layouts
(8 and 16-bit); add tests for fixed-max above actual, median-frames
tracking, toggle round-trip on a held frame, and initialize-time
propagation of the default. Fix a -Wreorder in the constructor init
list. Name the sRGB piecewise constants (IEC 61966-2-1). Apply
ament_uncrustify to ros_image_texture.cpp.

Signed-off-by: Arne Baeyens <mail@arnebaeyens.com>
abaeyens added a commit to abaeyens/rviz that referenced this pull request Jul 6, 2026
Resolves ros2#887. Bayer encodings (bayer_rggb8 / bayer_bggr8 / bayer_gbrg8 /
bayer_grbg8 and their 16-bit variants) were previously routed to a stub
that handed the raw mosaic to Ogre as PF_BYTE_L, rendering as a visible
checkerboard. They are now bilinearly demosaiced to sRGB-encoded RGB.

The demosaic is hand-rolled to avoid pulling in OpenCV / cv_bridge as a
dependency, matching the policy established in
ros-visualization/rviz#1009 and the existing YUYV / UYVY / NV12
converter pattern in this file. A single templated implementation
(parameterised on the input pixel type and on the (R_DY, R_DX) position
of R within the 2x2 mosaic cell) covers all four layouts at both 8-bit
and 16-bit. The interior loop is bounds-check-free; four separate border
passes handle the 1-pixel edge with clamp-to-edge and a count-of-valid-
neighbours average. Each demosaiced linear value passes through an
sRGB transfer-function LUT (256 entries at 8-bit, 65536 entries / 64 KiB
at 16-bit, built once on first use). The sRGB step is always-on for
Bayer because the bilinear output is linear-light and the texture is
displayed as sRGB; a user-toggleable linear-input property is left for
a follow-up if a real use case appears.

For 16-bit Bayer, the existing Normalize Range / Min Value / Max Value /
Median window properties are reused. Cameras packing 10/12/14-bit data
into 16-bit messages can be displayed correctly by disabling Normalize
Range and setting Max Value to the actual bit-depth maximum
(1023 / 4095 / 16383). Min/max statistics are computed over the input
mosaic (not the 3x-larger demosaiced output) using a stride-aware
row-by-row scan that ignores padding bytes between rows; this scan and
the bayer_16bit_padded_stride regression test become removable once
PR ros2#1719 lands and repacks padded buffers in update() before dispatch
(see in-file comment for cleanup notes in both directions).

Input validation rejects malformed messages upfront with
UnsupportedImageEncoding: zero or oversize dimensions (> 32768),
inconsistent stride (< width * bpp), truncated data (< height * stride),
odd stride for 16-bit, and misaligned data_ptr for 16-bit (the latter
guards against strict-alignment platforms like ARMv7 where the
uint16_t reinterpret_cast would otherwise be undefined behaviour).
Unknown bayer_* encodings now throw rather than being silently rendered
as luminance; a small deliberate user-visible behaviour change.

In ImageDisplay, the private got_float_image_ flag is renamed to
has_normalizable_range_ to reflect that it now also gates the
normalize controls for 16-bit Bayer. Tooltip on Normalize Range is
extended to mention Bayer applicability.

Tests cover: all four 8-bit layouts (pure-red and pure-blue, which are
discriminating across layouts because a layout-swap bug surfaces as
swapped output channels); all four 16-bit layouts with fixed Max Value;
16-bit black-point via Min Value; running-median smoke test for the
auto-normalisation path; padded-stride regression test (verified to
fail under the previous contiguous min/max scan); scale-then-sRGB
ordering; multi-anchor sRGB transfer-function validation across the
linear toe, the knee at 0.0031308, and the upper exponent range;
small-image edge cases (2x2 and 3x3); unknown-encoding rejection; and
oversize / truncated / odd-stride-16-bit rejection.

Signed-off-by: Arne Baeyens <mail@arnebaeyens.com>
abaeyens added a commit to abaeyens/rviz that referenced this pull request Jul 6, 2026
The previous "Bayer input is linear-light, apply sRGB gamma" rule was
hardcoded. Expose it as a per-display "Linear input" BoolProperty on
ImageDisplay; hidden unless the current message is Bayer; default off.
Toggling on a latched frame re-runs the converter without needing a new
publish (mirrors setSmoothScaling).

Now that PR ros2#1719 (buffer repack in update()) has landed
upstream:
- Replace the inline stride-aware 16-bit min/max scan with a call to
  the shared getMinimalAndMaximalValueToNormalize<uint16_t>.
- Delete unreachable defensive stride/alignment checks and the
  now-obsolete odd_stride_16bit_rejected test.

Also: parameterise linear-passthrough tests over all four Bayer layouts
(8 and 16-bit); add tests for fixed-max above actual, median-frames
tracking, toggle round-trip on a held frame, and initialize-time
propagation of the default. Fix a -Wreorder in the constructor init
list. Name the sRGB piecewise constants (IEC 61966-2-1). Apply
ament_uncrustify to ros_image_texture.cpp.

Signed-off-by: Arne Baeyens <mail@arnebaeyens.com>
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.

2 participants