Bounded native lens and exposure correction for USHER JPEGs. More...
#include <stddef.h>#include <stdio.h>#include <jpeglib.h>#include "jpeg_marker_guard.h"#include "exifite.h"#include "image_exif.h"#include "sha256fst.h"#include <opencv2/core/persistence.hpp>#include <opencv2/calib3d.hpp>#include <opencv2/imgproc.hpp>#include <fcntl.h>#include <sys/file.h>#include <sys/stat.h>#include <unistd.h>#include <algorithm>#include <array>#include <atomic>#include <chrono>#include <cmath>#include <csetjmp>#include <cstdio>#include <cstdlib>#include <fstream>#include <iostream>#include <list>#include <map>#include <memory>#include <sstream>#include <stdexcept>#include <string>#include <vector>#include "version.h"#include "opencv_json.hpp"#include "opencv_parallel.hpp"
Go to the source code of this file.
Data Structures | |
| struct | camera_lens_detail::FileCloser |
| struct | camera_lens_detail::JpegError |
| struct | camera_lens_detail::Decoder |
| Own decoder state across libjpeg's nonlocal error return. More... | |
| struct | camera_lens_detail::JpegHeader |
| Encoder facts of a decoded JPEG, used to calibrate profiles. More... | |
| struct | camera_lens_detail::Encoder |
| Own encoder state independently of the output stream. More... | |
| struct | camera_lens_detail::TemporaryOutput |
| Own an unpublished derivative and its temporary sibling path. More... | |
| struct | camera_lens_detail::Resources |
| struct | camera_lens_detail::Bounds |
| class | camera_lens_detail::TileCache |
| struct | camera_lens_detail::TileCache::Entry |
| struct | camera_lens_detail::Lens |
| class | camera_lens_detail::RayField |
| struct | camera_lens_detail::Pose |
| struct | camera_lens_detail::Rendered |
| struct | camera_lens_detail::TemporalSampling |
| struct | camera_lens_detail::Development |
| struct | camera_lens_detail::RowSamplePose |
| struct | camera_lens_detail::SourcePinhole |
Namespaces | |
| namespace | camera_lens_detail |
Macros | |
| #define | CAMERA_LENS_SIMD |
Typedefs | |
| using | camera_lens_detail::Json = usher_cv_json::Value |
| using | camera_lens_detail::File = std::unique_ptr<FILE, FileCloser> |
Functions | |
| void | camera_lens_detail::require (bool valid, const char *message) |
| Route a failed precondition to the CLI's diagnostic handler. | |
| void | camera_lens_detail::require (bool valid, const std::string &message) |
| Route a failed precondition to the CLI's diagnostic handler. | |
| double | camera_lens_detail::number (const Json &value, const std::string &name, double minimum, double maximum) |
| File | camera_lens_detail::open_regular (const std::string &path, size_t maximum) |
| Json | camera_lens_detail::read_profile (const char *path) |
| void | camera_lens_detail::jpeg_failure (j_common_ptr state) |
| Return a fatal libjpeg error to the active codec recovery point. | |
| void | camera_lens_detail::jpeg_message (j_common_ptr state, int level) |
| Enforce JPEG marker bounds before normal message handling. | |
| cv::Mat | camera_lens_detail::read_jpeg (const std::string &path, bool tile, size_t budget, JpegHeader *header=nullptr, bool decode_pixels=true) |
| void | camera_lens_detail::write_jpeg (const std::string &output, const cv::Mat &image, int quality, const exif_document *metadata) |
| std::string | camera_lens_detail::tag_text (const exif_document *metadata, exif_directory ifd, uint16_t tag) |
| unsigned char * | camera_lens_detail::replace_tag (exif_document *metadata, exif_directory ifd, uint16_t tag, exif_format format, size_t components) |
| void | camera_lens_detail::set_text (exif_document *metadata, exif_directory ifd, uint16_t tag, const std::string &text, bool undefined=false) |
| void | camera_lens_detail::set_rational (exif_document *metadata, uint16_t tag, double value, unsigned denominator, bool signed_value=false) |
| Json | camera_lens_detail::read_shot (const exif_document *metadata, Json &geometry) |
| const std::array< float, 256 > & | camera_lens_detail::srgb_decoding () |
| 8-bit sRGB to linear-light lookup, built once. | |
| TemporalSampling | camera_lens_detail::temporal_sampling (const RayField &field, const Pose &pose, int width, int height, int maximum) |
| Choose the fewest odd exposure samples that resolve motion blur. | |
| const std::array< unsigned char, 65536 > & | camera_lens_detail::srgb_encoding () |
| Linear-light to 8-bit sRGB lookup, built once. | |
| int | camera_lens_detail::reflect_101 (int index, int size) |
| Reflect-101 index clamp matching OpenCV's BORDER_REFLECT_101. | |
| CAMERA_LENS_SIMD void | camera_lens_detail::blur_linear_rgb (cv::Mat &frame, double sigma) |
| Parallel separable Gaussian blur on a contiguous CV_32FC3 frame. | |
| float | camera_lens_detail::stateless_normal (uint64_t row_seed, int index) |
| Stateless zero-mean, unit-variance Irwin-Hall normal sample. | |
| CAMERA_LENS_SIMD void | camera_lens_detail::encode_sensor_rows (const cv::Mat &linear, cv::Mat &output, int start_row, int end_row, float well, float read_variance, uint64_t seed, const unsigned char *encode) |
| Parallel shot/read noise + sRGB encoding for a row range. | |
| CAMERA_LENS_SIMD void | camera_lens_detail::sharpen_luma_rgb (cv::Mat &output, double sharpen) |
| Parallel luma-only unsharp mask (sigma = 1 px) preserving chroma. | |
| float | camera_lens_detail::sample_tile_channel (const float *const *tile_ptrs, int grid_width, int max_x, int max_y, float map_x, float map_y, int channel) |
| Bilinearly sample one channel from a 2D pointer grid of 256x256 linear float32 RGB tiles without assembling a strip mosaic. | |
| void | camera_lens_detail::sample_tile_rgb (const float *const *tile_ptrs, int grid_width, int max_x, int max_y, float map_x, float map_y, float &red, float &green, float &blue) |
| Bilinearly sample all 3 RGB channels at identical coordinates from a 2D pointer grid of 256x256 linear float32 tiles. | |
| float | camera_lens_detail::sample_pinhole_channel (const cv::Mat &source, float map_x, float map_y, int channel) |
| Bilinearly sample a linear CV_32FC3 pinhole source image matching OpenCV INTER_LINEAR + BORDER_CONSTANT(0). | |
| CAMERA_LENS_SIMD void | camera_lens_detail::compute_strip_bounds_rows (const std::vector< std::unique_ptr< RayField > > &fields, int channels, const RowSamplePose *poses, int samples, int first, int start_row, int end_row, double *min_e, double *max_e, double *min_n, double *max_n, std::atomic< bool > &horizon, std::atomic< bool > &non_finite) |
| SIMD-friendly strip ground-bounds and horizon check. | |
| CAMERA_LENS_SIMD void | camera_lens_detail::sample_cache_rows (const std::vector< std::unique_ptr< RayField > > &fields, int channels, const RowSamplePose *poses, int samples, int first, int start_row, int end_row, int width, float inv_map_scale, float base_offset_x, float base_offset_y, const float *const *tile_ptrs, int grid_width, int grid_height, float gain, float vignette_scale, cv::Mat &linear) |
| Fused parallel strip kernel for map-cache rendering. | |
| Rendered | camera_lens_detail::render (const cv::Mat &input, const Json &shot, const Json &geometry, const Json &profile, const std::string &cache_path, const Resources &resources, cv::Size source_size={}) |
| Json | camera_lens_detail::emulate (const std::string &input, const std::string &output, const Json &profile, const std::string &cache) |
| std::pair< int, double > | ijg_quality (const std::array< unsigned, 64 > &quant) |
| Estimate the IJG quality whose scaled luma table best matches. | |
| Json | measure (const std::string &path) |
| Measure image statistics that a lens profile should reproduce. | |
| Json | measure_all (const std::vector< std::string > &paths) |
| Measure files and append per-key medians of numeric results. | |
| int | main (int argc, char **argv) |
| Validate a lens profile or generate a simulated camera derivative. | |
Variables | |
| constexpr double | camera_lens_detail::pi = 3.14159265358979323846 |
| constexpr size_t | camera_lens_detail::mib = 1024 * 1024 |
| constexpr size_t | camera_lens_detail::maximum_exif_payload_bytes = 65533 |
| constexpr unsigned int | camera_lens_detail::maximum_image_dimension = 4096 |
| constexpr uint64_t | camera_lens_detail::maximum_mock_pixels = 8388608 |
| constexpr size_t | camera_lens_detail::tile_cache_entries = 48 |
| constexpr double | camera_lens_detail::maximum_reprojection_error_pixels = 0.1 |
| constexpr int | camera_lens_detail::lens_inverse_iterations = 30 |
| constexpr int | camera_lens_detail::lens_polish_passes = 8 |
| constexpr double | camera_lens_detail::lens_polish_tolerance_px = 0.001 |
| constexpr int | camera_lens_detail::ray_grid_initial_step = 16 |
| constexpr double | camera_lens_detail::ray_interpolation_tolerance_px = 0.02 |
| constexpr double | camera_lens_detail::temporal_sample_spacing_px = 0.5 |
Detailed Description
Bounded native lens and exposure correction for USHER JPEGs.
Validates a versioned profile, reads the clean source JPEG and flight EXIF, renders in memory-bounded strips, and atomically publishes a derivative with provenance. Default profiles are illustrative, not measured calibration.
Definition in file camera_lens.cpp.
Macro Definition Documentation
◆ CAMERA_LENS_SIMD
| #define CAMERA_LENS_SIMD |
Definition at line 73 of file camera_lens.cpp.
Function Documentation
◆ ijg_quality()
| std::pair< int, double > ijg_quality | ( | const std::array< unsigned, 64 > & | quant | ) |
Estimate the IJG quality whose scaled luma table best matches.
- Parameters
-
quant Natural-order luma quantization table.
- Returns
- {quality, mean absolute table error}; error 0 is an exact IJG table, larger values mean a vendor table and an approximate quality.
Definition at line 2345 of file camera_lens.cpp.
◆ main()
| int main | ( | int | argc, |
| char ** | argv ) |
Validate a lens profile or generate a simulated camera derivative.
- Parameters
-
argc Argument count including the program name. argv Command-line argument vector.
- Returns
- Zero for success, or one after reporting an exception.
Version and validation requests bypass rendering. Render jobs take a nonblocking executable lock so separate jobs cannot multiply the working set managed by the per-job memory budget.
Definition at line 2480 of file camera_lens.cpp.
◆ measure()
| Json measure | ( | const std::string & | path | ) |
Measure image statistics that a lens profile should reproduce.
- Parameters
-
path JPEG saved by a real or simulated camera.
- Returns
- Encoder, exposure, noise, sharpness, shading and colour facts.
Compare medians of real flight photos with medians of simulated photos of similar terrain; single-image values are scene dependent.
Definition at line 2369 of file camera_lens.cpp.
◆ measure_all()
| Json measure_all | ( | const std::vector< std::string > & | paths | ) |
Measure files and append per-key medians of numeric results.
Definition at line 2449 of file camera_lens.cpp.