Commit Graph

266 Commits

Author SHA1 Message Date
Isaac Connor
83ed47abf4 fix: scan-line polygon fill incorrectly filled non-convex polygon gaps
Image::Fill(Polygon) implements scan-line polygon fill but iterated
through active edges one at a time instead of in pairs. For convex
polygons (always exactly 2 active edges per scan line) this happened
to work, but for non-convex polygons it would fill the gaps between
concave sections.

A banana-shaped zone, for example, would have its inner concave area
incorrectly marked as inside the zone, causing motion detection to
trigger on the area the user explicitly drew the zone to avoid.

Fix by stepping the iterator by 2 to fill between pairs of edges
following the standard parity rule for scan-line polygon fill.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 09:33:52 -04:00
Isaac Connor
4d40ca4edf fix: add www-data to video group and font path fallback refs #4642
Add www-data to video and dialout groups in Debian/Ubuntu postinst
scripts so zmc can access /dev/video* devices on fresh installs.
RedHat packaging already handled this via gpasswd in %post.

Add compile-time ZM_FONTDIR to zm_config_data.h.in and use it as a
fallback in zm_image.cpp when the configured font_file_location is not
found, fixing font loading failures caused by stale DB config values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:19:20 -05:00
Isaac Connor
03c42d4816 fix: use original colour format for DeColourise() dispatch
colours and subpixelorder were set to GRAY8/NONE before the
format detection logic, so RGB32 SSSE3/fast paths were never
reached and subpixel order switches always hit the default case.
Save originals before overwriting and set output values after
conversion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 22:39:28 -05:00
Isaac Connor
701d477ea8 perf: reuse persistent blend buffer in Image::Blend()
Replace per-frame AllocBuffer/free cycle with a persistent
blend_buffer_ member that is allocated once and reused across
calls. For non-holdbuffer images, swap buffer pointers instead
of freeing and reallocating. Eliminates ~8MB alloc+free per
frame for 1080p RGBA.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 22:32:56 -05:00
Isaac Connor
4a4b6b25c5 fix: correct broken pointer logic in Image::Merge() and Image::Highlight()
Merge() reset pdest and psrc to buffer base on every pixel iteration,
so only buffer[0] was ever written. Move pdest outside the loop and
use direct array indexing for source buffers.

Highlight() had the same pointer reset bug plus iterated over size
(total bytes) instead of pixels, and the unsigned diff calculation
wrapped around instead of computing absolute difference. Fix pointer
management, loop bound, and diff comparison.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 22:32:56 -05:00
Isaac Connor
ecb0ed4122 fix: return error when av_buffer_create fails in Image::PopulateFrame
Previously, when av_buffer_create() failed and returned nullptr, the code
only issued a Warning and continued, assigning the null pointer to the
frame buffer and returning success. Now properly returns -1 on failure.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 11:48:03 -05:00
Isaac Connor
bef2ea5b9e Allocate the temp frame inside Assign, instead of keeping it around. 2026-01-22 20:54:00 -05:00
Isaac Connor
32a842e81e Return instead of panic in Delta and Blend 2026-01-19 14:40:28 -06:00
Isaac Connor
9ee497f708 Add toString 2026-01-16 15:44:30 -05:00
Isaac Connor
17a633087c Create a constructor that takes an allocation parameter so that we can give a larger allocation than buffer size 2026-01-16 15:37:10 -05:00
Isaac Connor
ec913cfc50 When overlaying a greyscale onto rgb32, only set the red field so we don't get white. 2026-01-16 15:29:39 -05:00
Isaac Connor
82554e0f20 Fix compiler complain 2025-12-28 13:09:37 -05:00
Isaac Connor
027fcdaf58 Add debugging to figure out cause of crash 2025-10-23 12:37:08 -04:00
Isaac Connor
643fe97b25 Deprecate zm_av_frame_alloc 2025-09-18 14:48:52 -04:00
Isaac Connor
eaf34434e3 Add constructor and assign direct for avframe 2025-09-18 09:59:39 -04:00
Isaac Connor
e1898c483b Adjust debug level add AVPixelFormat Image::AVPixFormat(AVPixelFormat new_pixelformat) 2025-09-18 09:42:03 -04:00
Isaac Connor
4757d711ef Change various cases of int img_buffer_size to size_t 2025-07-19 14:18:32 -04:00
Isaac Connor
69e3694854 Must use struct here as there is a name collision with flock() 2025-04-08 20:06:16 -04:00
Isaac Connor
220d7beb46 Individually set flock options, to simplifybsd support. 2025-04-08 10:21:38 -04:00
Isaac Connor
a993ddb584 POpulateFrame can be const 2024-07-09 08:13:16 -04:00
Aaron Kling
c4683d90a9 Format code using astyle google format
Commands used:
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.cpp
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.h
2024-03-26 13:43:58 -05:00
Isaac Connor
31091d0fd3 Handle out of bounds access to global_edges if it is empty 2024-01-29 13:12:30 -05:00
Isaac Connor
27cfd11d95 Increase debug log leve 2023-12-19 10:54:35 -05:00
Isaac Connor
ffb8d68c74 When reading a jpeg, and the dimensions don't match, update the image dimension values so that the image at least looks right. 2023-10-01 10:28:36 -04:00
Alejandro Criado-Pérez
543683aa4c Corrections on cpp and h files 2023-08-13 01:27:19 +02:00
Isaac Connor
c510745317 Allow specifying width and height so that we can scale to alower res 2023-08-02 13:56:06 -04:00
Isaac Connor
4b20109b69 Use the same open semantics regardless of blocking or non so that we always have an fd to lock. Fixes logging of unable to lock jpeg in streaming with buffering 2023-07-25 16:35:28 -04:00
Isaac Connor
15d9ec32de Add advisory locking around image writing. So that someone can potentially wait for the image to be fully written to. Hopefully will resolve issues with zmes and incomplete images 2023-07-13 14:25:56 -04:00
Isaac Connor
2b34fa67db Add jpeg writing from YUV subpixelformat 2023-06-09 16:42:33 -04:00
Isaac Connor
1d51f1b146 Fix missing c_str() 2023-02-02 12:16:43 -05:00
Isaac Connor
9a999d1465 replace const char * with std::string and save filename in the object when created by filename. Long term, we may represent an image by filename and load the image on demand. For potential use with sendfile. 2023-02-01 14:31:59 -05:00
Isaac Connor
ae66782ddb Use 32byte aligned buffer size when allocating an image buffer to make ffmpeg happy. Fixes a crash when width = 1080. When linesizes are different, copy line by line instead of the whole buffer all at once. 2022-11-30 13:18:13 -05:00
Isaac Connor
658ca44c32 Don't panic if no font file found. Perhaps we can continue with diminished function 2022-10-14 14:04:06 -04:00
Isaac Connor
8558ade8f1 Merge branch 'master' into misc_fixes 2022-08-25 18:33:06 -04:00
Doug Nazar
74f8e43b12 Cast operand to larger destination size to avoid possible overflow issues. 2022-07-31 00:48:27 -04:00
Doug Nazar
f4dd897ef4 Convert AVFrame* to custom unique_ptr (av_frame_ptr).
Switch all owning AVFrame* variables to av_frame_ptr for
automatic cleanup.

Use AVBufferRef to store frame data in AVFrame where appropriate
so that it can be freed automatically with it's AVFrame.

Handle allocation errors.
2022-07-30 13:21:11 -04:00
Doug Nazar
3b21153757 Fix various printf formats for 32bit, 32bit w/_FILE_OFFSET_BITS=64 and 64-bit 2022-07-16 03:18:18 -04:00
Isaac Connor
e6de9c3e01 A polygon must have 3 vertices at minimum 2022-07-14 10:06:26 -04:00
Isaac Connor
59577133ef parenthesis 2022-06-08 23:28:54 -04:00
Isaac Connor
0fcc237fd5 Only call update_function_pointers if size might have changed 2022-06-07 17:19:54 -04:00
Isaac Connor
678abad57c remove debug 2022-06-07 11:58:32 -04:00
Isaac Connor
02cca8e57b Handle no vertices in Fill. Prevents crash when a zone is entirely outside the image 2022-05-17 15:05:08 -04:00
Isaac Connor
0cdb926e9e Remove unused variable 2022-05-10 09:30:13 -04:00
Isaac Connor
442dff3f8a Implement a Scale(new_width, new_height) using sw_scale. 2022-05-06 11:43:35 -04:00
Isaac Connor
db2854a7ac Improve error message when sws_scale fails 2022-05-04 10:00:40 -04:00
Isaac Connor
cc1368ba2c Move code for AVPixFormat to .cpp instead .h. Add const's so we can use it on cost Image * vars 2022-03-26 20:31:33 -04:00
Isaac Connor
fc541ac57d fix potential double lock of jpeg mutex 2022-02-18 17:11:18 -05:00
Isaac Connor
28f3cb18e4 Make std function warning into a debug. Warning will happen if they are actually used 2022-02-18 15:59:00 -05:00
Isaac Connor
91b536b868 Change the test for slow functions to mod4. The unrolled and SSE function work on 4 pixels at a time or 16 or 12 bytes depending on colours.This will improve cpu use on resolutions like 1280x800 2022-02-14 09:43:48 -05:00
Isaac Connor
6e7e6d9e8e small code cleanup, add Warnings when using slow blend functions. 2022-02-11 18:06:43 -05:00