Data Structures | |
| struct | ObjectDetection |
| struct | CropBox |
| struct | DecodedImage |
| struct | JpegErrorContext |
Functions | |
| void | jpeg_error_exit (j_common_ptr jpeg_info) |
| void | jpeg_message (j_common_ptr state, int level) |
| Check JPEG marker bounds before forwarding a codec diagnostic. | |
| bool | parse_object_summary (const std::string &comment_text, ObjectDetection *out) |
| Parse an already-decoded EXIF_TAG_USER_COMMENT payload for an AICAM_OBJECTS_V1 hit. Kept separate from the EXIF/file I/O in read_object_detection() so the parsing logic is unit-testable against synthetic buffers without needing a real JPEG on disk. | |
| bool | read_object_detection (const char *image_path, ObjectDetection *out) |
| Read the AICAM_OBJECTS_V1 record usher's image_exif_write_object_detections() writes into EXIF_TAG_USER_COMMENT, if present and reporting count >= 1. | |
| bool | sibling_directory (const char *image_path, const char *name, std::string *out) |
| std::string | basename_of (const char *image_path) |
| bool | copy_file_bytes (const char *source_path, const char *dest_path) |
| CropBox | compute_crop_box (int box_x, int box_y, int box_w, int box_h, unsigned img_w, unsigned img_h, double margin) |
| bool | decode_jpeg_rgb (const char *path, DecodedImage *image) |
| void | draw_box_outline (DecodedImage *image, int box_x, int box_y, int box_w, int box_h, int thickness) |
| bool | encode_cropped_jpeg (const char *path, const DecodedImage &image, const CropBox &box) |
| bool | write_all_atomic (int fd, const std::string &data) |
| std::string | csv_field (const std::string &value) |
| bool | append_detection_csv (const std::string &csv_path, const std::string &image_basename, const ObjectDetection &detection) |
Variables | |
| constexpr size_t | kAsciiCommentPrefixSize = 8 |
| constexpr char | kObjectDetectionMarker [] = "\nAICAM_OBJECTS_V1\n" |
| constexpr size_t | kObjectLabelCapacity = 64 |
| constexpr double | kCropMargin = 0.18 |
| constexpr int | kBoxOutlineThickness = 4 |
| constexpr size_t | kCopyChunkBytes = 65536 |
| constexpr size_t | kCsvRowCapacity = 512 |
| constexpr int | kCropJpegQuality = 95 |
Detailed Description
Parsing, drawing, and file-writing helpers used by the public SODA entry point.
Function Documentation
◆ append_detection_csv()
| bool soda_object_postprocess_detail::append_detection_csv | ( | const std::string & | csv_path, |
| const std::string & | image_basename, | ||
| const ObjectDetection & | detection ) |
Append one CSV row for detection to csv_path, safe against concurrent SODA processes racing on the same file (usher can run multiple worker threads' finish_image() close together, each spawning its own SODA child).
Header-or-not is decided with O_CREAT|O_EXCL: whichever process wins that race writes header+row together in a single write(); every loser falls back to a plain O_APPEND open and writes only its own row. Each row (and the header+row for the winner) goes out as exactly one write() call, which POSIX guarantees is atomic against other O_APPEND writers on the same file as long as it stays under PIPE_BUF – comfortably true for these rows.
- Parameters
-
csv_path Shared CSV path. image_basename Source JPEG basename. detection EXIF-derived hit summary.
- Returns
- True when exactly one complete row/header+row is written.
Definition at line 538 of file soda_object_postprocess.cpp.
◆ basename_of()
| std::string soda_object_postprocess_detail::basename_of | ( | const char * | image_path | ) |
Return the final path component for display and CSV output.
- Parameters
-
image_path Source photo path.
- Returns
- Basename without directory components.
Definition at line 208 of file soda_object_postprocess.cpp.
◆ compute_crop_box()
| CropBox soda_object_postprocess_detail::compute_crop_box | ( | int | box_x, |
| int | box_y, | ||
| int | box_w, | ||
| int | box_h, | ||
| unsigned | img_w, | ||
| unsigned | img_h, | ||
| double | margin ) |
Add margin times the box size on each side, then clamp to the image bounds, guarding a degenerate zero-area result so it's always safely croppable.
- Parameters
-
box_x Detection left pixel. box_y Detection top pixel. box_w Detection width. box_h Detection height. img_w Source-image width. img_h Source-image height. margin Fraction of box size added on every side.
- Returns
- Clamped half-open crop with nonzero area.
Definition at line 280 of file soda_object_postprocess.cpp.
◆ copy_file_bytes()
| bool soda_object_postprocess_detail::copy_file_bytes | ( | const char * | source_path, |
| const char * | dest_path ) |
Copy every byte of source_path into a newly created/truncated dest_path.
- Parameters
-
source_path Source JPEG. dest_path Destination copy.
- Returns
- True only for a complete copy; removes partial output on failure.
A standalone copy loop, deliberately not shared with spotter_cam_pipe.c's own copy_file() – that function is file-local there, and linking spotter_cam_pipe.o into soda would couple this build to usher's object graph for ~20 lines of code.
Definition at line 223 of file soda_object_postprocess.cpp.
◆ csv_field()
| std::string soda_object_postprocess_detail::csv_field | ( | const std::string & | value | ) |
Escape one bounded model label as a CSV field.
Definition at line 514 of file soda_object_postprocess.cpp.
◆ decode_jpeg_rgb()
| bool soda_object_postprocess_detail::decode_jpeg_rgb | ( | const char * | path, |
| DecodedImage * | image ) |
Decode a JPEG to a contiguous row-major RGB buffer.
- Parameters
-
path Input image path. [out] image Decoded pixels and image dimensions.
- Returns
- True only for a complete valid JPEG decode.
Same libjpeg pattern as image_mock_transform.c's decode_jpeg(), duplicated rather than shared since that file's decode/encode helpers are file-local (static) and out of scope to refactor for this change.
Definition at line 302 of file soda_object_postprocess.cpp.
◆ draw_box_outline()
| void soda_object_postprocess_detail::draw_box_outline | ( | DecodedImage * | image, |
| int | box_x, | ||
| int | box_y, | ||
| int | box_w, | ||
| int | box_h, | ||
| int | thickness ) |
Draw a green rectangle outline in place on a decoded RGB buffer.
- Parameters
-
image Mutable decoded image. box_x Box left coordinate. box_y Box top coordinate. box_w Box width. box_h Box height. thickness Outline width in pixels.
The native capture and metadata stages never draw on the frame saved to the configured photo directory; that file stays a clean flight-record image. SODA is the only place that burns a box in, onto its own copies (objects_captured/ and the crop), using the box this process already read back from EXIF. This draws only the outline, not the "label 0.NN" confidence text – replicating PIL's text rendering in raw C++ would need a font-rendering dependency for a label that's already in the console log and the CSV row.
Definition at line 395 of file soda_object_postprocess.cpp.
◆ encode_cropped_jpeg()
| bool soda_object_postprocess_detail::encode_cropped_jpeg | ( | const char * | path, |
| const DecodedImage & | image, | ||
| const CropBox & | box ) |
Encode the selected region of an already-decoded frame to a new JPEG file.
- Parameters
-
path Destination JPEG path. image Full-frame RGB source. box Half-open source rectangle; rows are referenced directly without a crop copy.
- Returns
- True when all rows encode and the output closes successfully.
No separate crop buffer is allocated: since the decoded buffer is row-major RGB at the full image's stride, each output scanline's row pointer can point directly into it at the crop's left/top offset – the encoder only reads crop_w*3 bytes from wherever that pointer starts. Quality 95, matching image_mock_transform.c's encode_jpeg().
Definition at line 438 of file soda_object_postprocess.cpp.
◆ jpeg_error_exit()
| void soda_object_postprocess_detail::jpeg_error_exit | ( | j_common_ptr | jpeg_info | ) |
Redirect libjpeg fatal errors to the caller's setjmp cleanup path.
- Parameters
-
jpeg_info Active libjpeg common state.
Definition at line 112 of file soda_object_postprocess.cpp.
◆ jpeg_message()
| void soda_object_postprocess_detail::jpeg_message | ( | j_common_ptr | state, |
| int | level ) |
Check JPEG marker bounds before forwarding a codec diagnostic.
- Parameters
-
state Codec state carrying the installed JpegErrorContext. level libjpeg diagnostic level.
Retain libjpeg's normal warning accounting for accepted input.
Definition at line 121 of file soda_object_postprocess.cpp.
◆ parse_object_summary()
| bool soda_object_postprocess_detail::parse_object_summary | ( | const std::string & | comment_text, |
| ObjectDetection * | out ) |
Parse an already-decoded EXIF_TAG_USER_COMMENT payload for an AICAM_OBJECTS_V1 hit. Kept separate from the EXIF/file I/O in read_object_detection() so the parsing logic is unit-testable against synthetic buffers without needing a real JPEG on disk.
- Parameters
-
comment_text Complete EXIF UserComment payload after charset prefix. [out] out Parsed detection fields on success.
- Returns
- true only for a genuine hit; false when the marker is absent (every non-spottercam image) or the summary after it is "status=ok; count=0" / "status=analysis_failed; ...", both of which fail to match the count>=1 pattern below.
Definition at line 136 of file soda_object_postprocess.cpp.
◆ read_object_detection()
| bool soda_object_postprocess_detail::read_object_detection | ( | const char * | image_path, |
| ObjectDetection * | out ) |
Read the AICAM_OBJECTS_V1 record usher's image_exif_write_object_detections() writes into EXIF_TAG_USER_COMMENT, if present and reporting count >= 1.
- Returns
- true only for a genuine hit; false for a read/parse failure, a shot without the marker (every non-spottercam image), or a "status=ok; count=0"/"analysis_failed" shot.
Definition at line 173 of file soda_object_postprocess.cpp.
◆ sibling_directory()
| bool soda_object_postprocess_detail::sibling_directory | ( | const char * | image_path, |
| const char * | name, | ||
| std::string * | out ) |
Resolve a sibling output directory and ensure it is writable.
- Parameters
-
image_path Source photo path. name Sibling directory name. [out] out Resolved directory path.
- Returns
- True when the directory exists and is usable.
Definition at line 195 of file soda_object_postprocess.cpp.
◆ write_all_atomic()
| bool soda_object_postprocess_detail::write_all_atomic | ( | int | fd, |
| const std::string & | data ) |
Write one complete buffer in a single syscall, retrying only an EINTR that transferred nothing. Callers rely on the single-syscall property for O_APPEND atomicity – see append_detection_csv().
- Parameters
-
fd Open output descriptor. data Complete row or header-plus-row payload.
- Returns
- True only if the syscall wrote the entire buffer.
Definition at line 505 of file soda_object_postprocess.cpp.
Variable Documentation
◆ kAsciiCommentPrefixSize
|
constexpr |
Matches image_exif.c's write_tagged_comment(): an 8-byte ASCII-charset prefix precedes the text payload in EXIF_TAG_USER_COMMENT, and the tagged record itself is introduced by "\n<TAG>\n". The entry is zero-filled before being written and sized one byte past the visible text (image_exif.c's replace_tag()/write_tagged_comment()), so a trailing NUL is present in practice, but entry->size (not strlen()) is used regardless, to stay correct even if that trailing byte is ever not zero.
Definition at line 63 of file soda_object_postprocess.cpp.
◆ kBoxOutlineThickness
|
constexpr |
Matches the outline width the now-removed Python draw_hits() used (PIL's ImageDraw.rectangle(..., width=4)). There is no text label here – see draw_box_outline()'s comment for why.
Definition at line 72 of file soda_object_postprocess.cpp.
◆ kCopyChunkBytes
|
constexpr |
Fixed copy buffer avoids allocating a second full-resolution JPEG-sized block.
Definition at line 75 of file soda_object_postprocess.cpp.
◆ kCropJpegQuality
|
constexpr |
Keep crop output quality consistent with the previous SODA crop path.
Definition at line 80 of file soda_object_postprocess.cpp.
◆ kCropMargin
|
constexpr |
Same default as the now-removed Python cropper, kept identical so a ported call site produces the same crop given the same box.
Definition at line 68 of file soda_object_postprocess.cpp.
◆ kCsvRowCapacity
|
constexpr |
Bounded detection row; rows stay comfortably below append atomicity limits.
Definition at line 78 of file soda_object_postprocess.cpp.
◆ kObjectDetectionMarker
|
constexpr |
Definition at line 64 of file soda_object_postprocess.cpp.
◆ kObjectLabelCapacity
|
constexpr |
Definition at line 65 of file soda_object_postprocess.cpp.