Monitor::Decode scales the Y-channel image when the camera's resolution
differs from the monitor's. That image is get_y_image()'s zero-copy wrap of
the decoder's Y plane, whose stride is the decoder's linesize[0], not the
FFALIGN(width,32) that Scale assumed when it handed the buffer to
SWScale::Convert at align 32. Each row was read from the wrong offset, so
the scaled analysis image, and the alarm pixels drawn from it, came out
sheared.
Set up the source and destination frames in Scale, override plane 0's
stride with the Image's linesize as Rotate and Flip already do, and convert
through SWScale::Convert(AVFrame*, AVFrame*). The output layout is
unchanged (align 32).
tests/zm_image_linesize.cpp: scale a 40 wide GRAY8 plane with a 48 byte
stride and check that every output row is still flat.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
get_y_image() wraps the decoder Y plane zero-copy but recorded
FFALIGN(width,32) as the Image stride instead of the frame's real
linesize[0]. For widths that are not a multiple of 32 the decoder packs
the plane tighter than FFALIGN, so:
- Image::Rotate/Flip re-derived the source stride via
av_image_fill_arrays(...,32) and read past the end of the borrowed
plane (and skewed Y-channel motion analysis, which reads the same
buffer).
- Image::Flip sized its destination from this->size, which is tight for a
borrowed plane and smaller than the 32-aligned layout the planes are
written at, overrunning the destination.
Record the frame's real linesize in get_y_image(); use the Image's own
linesize for the source plane-0 stride in Rotate/Flip; size Flip's
destination from av_image_get_buffer_size(...,32). All are no-ops for
self-consistent ZM-allocated (32-aligned) images.
tests/zm_image_linesize.cpp: Rotate 90/180/270 and Flip H/V over a tight,
non-32-aligned GRAY8 source verifying correct output.
refs #4788
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>