Loading...
Searching...
No Matches
inference_jpeg.c
Go to the documentation of this file.
46/** @brief Convert libjpeg's fatal callback into a failed input instead of terminating the CAM worker. */
65/** @brief Fill a bound input tensor; ignore partial tensor/transform contents after any failure. */
82 if (!jpeg_start_decompress(&reader->codec) || reader->codec.output_components != 3) return false;
85 (spec->type != ONNX_FLOAT32 && spec->type != ONNX_UINT8 && spec->type != ONNX_INT8)) return false;
133 /* Consume every source row to validate the JPEG, but retain only rows selected by nearest resize. */
139 const unsigned selected = (unsigned)(((uint64_t)target_row * 2 + 1) * transform->source_height /
143 .lengths = {(size_t)transform->source_width * 3}, .strides = {(size_t)transform->source_width * 3},
147 /* Reuse the live-image conversion so color order and normalization cannot drift between sources. */
148 if (!inference_image_prepare(&image, &row_spec, reader->prepared.bytes, row_bytes, &unused, error, sizeof(error))) return false;
152 const unsigned final_row = target_row + transform->top, final_column = column + transform->left;
157 ((unsigned char *)context->model.inputs[0].data)[output + byte] = reader->prepared.bytes[input + byte];
187 context->model.inputs[0].bytes != (size_t)spec->width * spec->height * spec->channels * element ||
193 if (!isfinite(spec->scale[channel]) || !spec->scale[channel] || !isfinite(spec->mean[channel])) {
199 if (stat(filename, &status) || !S_ISREG(status.st_mode) || status.st_size <= 0 || status.st_size > 128 * 1024 * 1024) {
static bool decode_jpeg(struct jpeg_reader *reader, struct inference_context *context)
Fill a bound input tensor; ignore partial tensor/transform contents after any failure.
Definition inference_jpeg.c:66
bool inference_jpeg_prepare(struct inference_context *context, const char *filename, char *error, size_t capacity)
Stream a JPEG into an open context's single declared image input.
Definition inference_jpeg.c:167
static void jpeg_failure(j_common_ptr codec)
Convert libjpeg's fatal callback into a failed input instead of terminating the CAM worker.
Definition inference_jpeg.c:47
static void jpeg_message(j_common_ptr codec, int level)
Check JPEG marker bounds ahead of normal codec diagnostics.
Definition inference_jpeg.c:58
Bounded JPEG-to-tensor preparation without running the graph or modifying the input file.
Reject invalid Huffman selectors before the bundled codec indexes its tables.
static void usher_jpeg_validate_marker(j_common_ptr state)
Validate marker parameters from an error manager's emit_message callback.
Definition jpeg_marker_guard.h:29
Independent, noncopyable model owner; mapped tensor buffers and session are reused between jobs.
Definition inference_model.h:43
struct inference_image_transform transform
Definition inference_model.h:46
Model-owned preprocessing; normalized samples are (sample - mean) * scale.
Definition inference_image.h:45
Exact resized content rectangle, including rounded letterbox offsets.
Definition inference_image.h:55
Definition ear_heatmap_overlay.c:149
Caller-owned codec/error state that remains valid across decoder longjmp exits.
Definition inference_jpeg.c:35
union jpeg_reader::@046352252025233214237353161003055245043271123215 prepared