### JSON Configuration Export/Import in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This example shows how to save and restore ISP pipeline configurations using JSON serialization in libpisp. It depends on libpisp backend headers and standard file I/O streams. The code exports current config to a JSON string and file, then loads it back to apply to a new backend instance, with inputs being existing configs and outputs being serialized JSON, limited to valid JSON formats. ```cpp #include #include // Export current configuration to JSON pisp_be_tiles_config tiles_config; be.Prepare(&tiles_config); std::string json_config = be.GetJsonConfig(&tiles_config); // Save to file std::ofstream out("isp_config.json"); out << json_config; out.close(); std::cout << "Configuration exported to isp_config.json\n"; // Later: Load configuration from JSON std::ifstream in("isp_config.json"); std::string loaded_config((std::istreambuf_iterator(in)), std::istreambuf_iterator()); in.close(); // Create new Backend and apply loaded configuration libpisp::BackEnd be2(config, variant); be2.SetJsonConfig(loaded_config); pisp_be_tiles_config restored_config; be2.Prepare(&restored_config); std::cout << "Configuration restored: " << restored_config.num_tiles << " tiles\n"; ``` -------------------------------- ### Hardware Device Access with V4L2 in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This code demonstrates simplified hardware access and buffer management using the BackendDevice helper from libpisp. It requires libpisp libraries including helpers for media and backend devices. The snippet opens a media device, finds the backend device, sets up buffers, runs processing, and handles inputs/outputs for image data, with limitations in error handling for missing devices. ```cpp #include #include // Open media device libpisp::MediaDevice media("/dev/media0"); std::vector devices = media.EnumerateEntities(); // Find Backend device std::string be_dev; for (const auto &dev : devices) { if (dev.find("pisp-be") != std::string::npos) { be_dev = dev; break; } } if (be_dev.empty()) { std::cerr << "Backend device not found\n"; return -1; } // Open Backend device libpisp::BackendDevice backend(media, be_dev); // Setup with configuration (allocate 3 buffers) pisp_be_tiles_config tiles_config; be.Prepare(&tiles_config); backend.Setup(tiles_config, 3); // Acquire buffers auto buffers = backend.AcquireBuffers(); // Map input/output memory void *input_ptr = buffers["input"].planes[0].mem; void *output_ptr = buffers["output0"].planes[0].mem; // Fill input buffer (from file, camera, etc.) // ... copy data to input_ptr ... // Run processing int result = backend.Run(buffers); if (result < 0) { std::cerr << "Backend processing failed: " << result << "\n"; return -1; } // Output is now in output_ptr std::cout << "Processing complete, output size: " << buffers["output0"].planes[0].length << " bytes\n"; // Release buffers backend.ReleaseBuffers(buffers); ``` -------------------------------- ### Initialize Raspberry Pi PiSP Backend Pipeline Source: https://context7.com/raspberrypi/libpisp/llms.txt Configures the Backend ISP processing pipeline by detecting the hardware variant and applying default settings. It enables global processing flags, sets the input image format, and initializes the Bayer pattern configuration. This snippet is essential for setting up the initial state of the image processing pipeline. ```cpp #include #include // Detect hardware variant const auto &variants = libpisp::get_variants(); const libpisp::PiSPVariant &variant = libpisp::get_variant(0x00114666, 0x02252701); // Initialize Backend with defaults // max_stripe_height=0, max_tile_width=0 for auto-calculation // flags=0 for standard operation libpisp::BackEnd::Config config(0, 0, 0, "/usr/share/libpisp/backend_default_config.json"); libpisp::BackEnd be(config, variant); // Enable global processing flags pisp_be_global_config global; be.GetGlobal(global); global.bayer_enables = PISP_BE_BAYER_ENABLE_INPUT | PISP_BE_BAYER_ENABLE_DPC | PISP_BE_BAYER_ENABLE_DEMOSAIC | PISP_BE_BAYER_ENABLE_LSC; global.rgb_enables = PISP_BE_RGB_ENABLE_CCM | PISP_BE_RGB_ENABLE_GAMMA | PISP_BE_RGB_ENABLE_OUTPUT0; be.SetGlobal(global); // Configure input format (Bayer RGGB 10-bit) pisp_image_format_config input_fmt = { .width = 2592, .height = 1944, .format = PISP_IMAGE_FORMAT_BPS_10 | PISP_IMAGE_FORMAT_PLANARITY_INTERLEAVED | PISP_IMAGE_FORMAT_SAMPLING_444 | PISP_IMAGE_FORMAT_ORDER_NORMAL, .stride = 0, .stride2 = 0 }; libpisp::compute_optimal_stride(input_fmt); be.SetInputFormat(input_fmt); be.SetBayer(PISP_BAYER_ORDER_RGGB, 0); // Bayer pattern, no flips std::cout << "Backend initialized for " << variant.Name() << " with " << variant.BackEndDownscalers() << " downscalers\n"; ``` -------------------------------- ### Set Up Dual Outputs with Scaling in libpisp Backend Source: https://context7.com/raspberrypi/libpisp/llms.txt This code configures two independent output streams in the libpisp backend: one full-resolution RGB and one scaled YUV420 thumbnail, with downscaling applied to the second. It uses output format configs for dimensions, formats, and strides, plus a downscale config for reduction factors. Inputs are resolution specs; outputs are dual streams; limitations include hardware-specific formats and need for global enables. ```cpp #include // Output 0: Full resolution RGB pisp_be_output_format_config output0 = {}; output0.image.width = 1920; output0.image.height = 1080; output0.image.format = PISP_IMAGE_FORMAT_BPS_8 | PISP_IMAGE_FORMAT_THREE_CHANNEL; libpisp::compute_optimal_stride(output0.image); be.SetOutputFormat(0, output0); // Output 1: Thumbnail YUV420 pisp_be_output_format_config output1 = {}; output1.image.width = 320; output1.image.height = 240; output1.image.format = PISP_IMAGE_FORMAT_BPS_8 | PISP_IMAGE_FORMAT_SAMPLING_420 | PISP_IMAGE_FORMAT_PLANARITY_PLANAR; libpisp::compute_optimal_stride(output1.image); be.SetOutputFormat(1, output1); // Configure downscale for output 1 (6x reduction) pisp_be_downscale_config downscale1 = {}; downscale1.xin = 1920; downscale1.yin = 1080; downscale1.xout = 320; downscale1.yout = 240; downscale1.h_enable = 1; downscale1.v_enable = 1; be.SetDownscale(1, downscale1); // Enable both outputs pisp_be_global_config global; be.GetGlobal(global); global.rgb_enables |= PISP_BE_RGB_ENABLE_OUTPUT0 | PISP_BE_RGB_ENABLE_OUTPUT1; global.rgb_enables |= PISP_BE_RGB_ENABLE_DOWNSCALE1; be.SetGlobal(global); std::cout << "Dual output: 1920x1080 RGB + 320x240 YUV420\n"; ``` -------------------------------- ### Advanced Tiling Configuration in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This snippet controls image tiling for large images in libpisp, handling hardware constraints. It requires libpisp backend headers and assumes a variant configuration. Inputs include image formats and tiling constraints, outputs are prepared tile configs with grid details, limited to supported image sizes and formats. ```cpp #include // Backend config with tiling constraints unsigned int max_stripe_height = 128; // Max tile height in pixels unsigned int max_tile_width = 2592; // Max tile width unsigned int flags = 0; // Reserved for future use libpisp::BackEnd::Config config(max_stripe_height, max_tile_width, flags, "backend_default_config.json"); libpisp::BackEnd be(config, variant); // Configure for 8K image (will be automatically tiled) pisp_image_format_config input = { .width = 7680, .height = 4320, .format = PISP_IMAGE_FORMAT_BPS_10 | PISP_IMAGE_FORMAT_PLANARITY_INTERLEAVED }; libpisp::compute_optimal_stride(input); be.SetInputFormat(input); pisp_be_output_format_config output = {}; output.image.width = 7680; output.image.height = 4320; output.image.format = PISP_IMAGE_FORMAT_BPS_8 | PISP_IMAGE_FORMAT_THREE_CHANNEL; libpisp::compute_optimal_stride(output.image); be.SetOutputFormat(0, output); // Prepare - tiling engine automatically splits image pisp_be_tiles_config tiles_config; be.Prepare(&tiles_config); std::cout << "8K image split into " << tiles_config.num_tiles << " tiles\n"; std::cout << "Tile grid: " << tiles_config.config.num_tiles_x << "x" << tiles_config.config.num_tiles_y << "\n"; // Each tile can be processed independently for (int i = 0; i < tiles_config.num_tiles; i++) { pisp_tile *tile = &tiles_config.tiles[i]; std::cout << "Tile " << i << ": input=" << tile->input_addr_offset << " output=" << tile->output_addr_offset << " size=" << tile->tile_width << "x" << tile->tile_height << "\n"; } ``` -------------------------------- ### Configure Frontend Statistics for AGC, AWB, CDAF in libpisp Source: https://context7.com/raspberrypi/libpisp/llms.txt This snippet sets up the libpisp frontend for generating camera statistics in streaming mode, including AGC (auto gain control) with 256 zones, AWB (auto white balance) with 1024 zones, and CDAF (contrast detection autofocus) with 64 zones. It requires frontend initialization with sensor input config like Bayer order and resolution. Outputs statistics grids; limitations involve zone grid alignments and buffer alignment requirements. ```cpp #include // Initialize Frontend for streaming mode bool streaming = true; unsigned int alignment = 16; // Buffer alignment libpisp::FrontEnd fe(streaming, variant, alignment); // Configure input from sensor pisp_fe_input_config input = { .streaming = 1, .format = { .width = 2592, .height = 1944, .format = PISP_IMAGE_FORMAT_BPS_10 | PISP_IMAGE_FORMAT_PLANARITY_INTERLEAVED, .stride = 0 }, .bayer_order = PISP_BAYER_ORDER_RGGB }; libpisp::compute_optimal_stride(input.format); fe.SetInput(input); // AGC Statistics: 256 zones (16x16 grid) pisp_fe_agc_stats_config agc = {}; agc.offset_x = 0; agc.offset_y = 0; agc.size_x = 2592 / 16; agc.size_y = 1944 / 16; agc.num = 16; // 16x16 = 256 zones agc.shift = 0; // No bit shifting fe.SetAgcStats(agc); // AWB Statistics: 1024 zones (32x32 grid) pisp_fe_awb_stats_config awb = {}; awb.offset_x = 0; awb.offset_y = 0; awb.size_x = 2592 / 32; awb.size_y = 1944 / 32; awb.num = 32; awb.shift = 0; fe.SetAwbStats(awb); // CDAF Statistics: 64 focus zones (8x8 grid) pisp_fe_cdaf_stats_config cdaf = {}; cdaf.offset_x = 2592 / 4; cdaf.offset_y = 1944 / 4; cdaf.size_x = 2592 / 16; cdaf.size_y = 1944 / 16; cdaf.num = 8; fe.SetCdafStats(cdaf); // Prepare configuration pisp_fe_config config; fe.Prepare(&config); std::cout << "Frontend statistics: AGC 256 zones, AWB 1024 zones, CDAF 64 zones\n"; ``` -------------------------------- ### Configure HDR Stitching for 2-Exposure Images in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This code configures the Stitch block for creating HDR images from two exposures. It sets exposure thresholds, a motion detection sensitivity, the exposure ratio, and enables output compression. It also configures the input buffer and enables the stitch block globally. Dependencies include the libpisp/backend/backend.hpp header. ```cpp #include // Configure stitch for 2-exposure HDR pisp_be_stitch_config stitch = {}; // Exposure thresholds for blending stitch.threshold_lo = 4096; // 10-bit: switch from short to long exposure stitch.threshold_hi = 8192; // Upper blending threshold stitch.motion_threshold = 128; // Motion detection sensitivity // Exposure ratio (long/short) stitch.exposure_ratio = 8; // 8x ratio between exposures // Compression mode for HDR output stitch.compress_en = 1; // Enable output compression stitch.compress_mode = 2; // Mode 2: companding be.SetStitch(stitch); // Configure for HDR input (2 planes) pisp_be_stitch_input_buffer_config stitch_input = { .addr = {0x0, 0x0} // DMA addresses for short/long exposure frames }; be.SetStitchInputBuffer(stitch_input); // Enable stitch block pisp_be_global_config global; be.GetGlobal(global); global.bayer_enables |= PISP_BE_BAYER_ENABLE_STITCH; be.SetGlobal(global); std::cout << "HDR stitching: " << stitch.exposure_ratio << "x ratio, thresholds [" << stitch.threshold_lo << ", " << stitch.threshold_hi << "]\n"; ``` -------------------------------- ### Enable Hardware Image Compression in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This code configures hardware compression for image output to reduce memory bandwidth. It sets up decompression for input if needed and configures the output format with a specified compression mode. It also calculates the optimal stride for the compressed image. Dependencies include libpisp/backend/backend.hpp and a utility function for stride computation. ```cpp #include // Configure input decompression (if input is compressed) pisp_be_decompress_config decompress = {}; decompress.mode = 2; // Mode 2: companding be.SetDecompress(decompress); // Configure output compression pisp_be_output_format_config output = {}; output.image.width = 1920; output.image.height = 1080; output.image.format = PISP_IMAGE_FORMAT_BPS_10 | PISP_IMAGE_FORMAT_COMPRESSION_MODE_2; libpisp::compute_optimal_stride(output.image); // Compression reduces stride significantly output.compress.mode = 2; // Companding mode output.compress.offset = 0; // No offset be.SetOutputFormat(0, output); std::cout << "Compression enabled: mode " << output.compress.mode << ", stride reduced from " << (1920 * 10 / 8) << " to " << output.image.stride << " bytes\n"; ``` -------------------------------- ### Adjust Color Saturation with Strength and Shift in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This code configures the saturation control block to adjust the vividness of colors in the image. It allows setting a saturation level (ranging from grayscale to vivid) and a bit shift for dynamic range adjustment. It also enables the saturation control globally. Dependencies include libpisp/backend/backend.hpp. ```cpp #include pisp_be_sat_control_config sat = {}; // Saturation adjustment sat.saturation = 128; // 0=grayscale, 128=normal, 255=vivid sat.shift = 0; // Bit shift for dynamic range be.SetSatControl(sat); // Enable saturation control pisp_be_global_config global; be.GetGlobal(global); global.rgb_enables |= PISP_BE_RGB_ENABLE_SAT_CONTROL; be.SetGlobal(global); std::cout << "Saturation: " << (sat.saturation / 128.0) << "x\n"; ``` -------------------------------- ### Perform Raspberry Pi PiSP Bayer to RGB Conversion and Scaling Source: https://context7.com/raspberrypi/libpisp/llms.txt Performs hardware-accelerated format conversion from Bayer to RGB, including automatic scaling to a specified output resolution. It configures the input and output image formats, applies smart resizing to maintain aspect ratio, and sets demosaic parameters for optimal conversion. This snippet is crucial for preparing image data for display or further processing. ```cpp #include #include libpisp::BackEnd be(config, variant); // Input: Bayer RGGB 2592x1944 pisp_image_format_config input = { .width = 2592, .height = 1944, .format = PISP_IMAGE_FORMAT_BPS_10 | PISP_IMAGE_FORMAT_PLANARITY_INTERLEAVED }; libpisp::compute_optimal_stride(input); be.SetInputFormat(input); // Output: RGB888 1920x1080 pisp_be_output_format_config output = {}; output.image.width = 1920; output.image.height = 1080; output.image.format = PISP_IMAGE_FORMAT_BPS_8 | PISP_IMAGE_FORMAT_THREE_CHANNEL;libpisp::compute_optimal_stride(output.image); be.SetOutputFormat(0, output); // Smart resize automatically calculates optimal crop and scale parameterslibpisp::SmartResize smart = { .width = 1920, .height = 1080, .preserve_ar = true, // Maintain aspect ratio .bounds_flags = libpisp::SMART_RESIZE_BOUNDS_NONE }; be.SetSmartResize(0, smart); // Configure demosaic for RGB conversion pisp_be_demosaic_config demosaic = {}; be.GetDemosaic(demosaic); demosaic.sharper = 8; // Sharpness level demosaic.fc_mode = 1; // False color suppression be.SetDemosaic(demosaic); // Generate tiled configuration pisp_be_tiles_config tiles_config; be.Prepare(&tiles_config); std::cout << "Processing " << tiles_config.num_tiles << " tiles\n"; std::cout << "Output stride: " << output.image.stride << " bytes\n"; ``` -------------------------------- ### Configure Defective Pixel Correction using Gradient Analysis in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This code configures the Defective Pixel Detection (DPC) block, which uses local gradient analysis to identify and correct flawed sensor pixels. It sets the gradient threshold for detection, reserved flags, and defines black and white levels for flat region analysis. Dependencies include libpisp/backend/backend.hpp. ```cpp #include pisp_be_dpc_config dpc = {}; // Detection thresholds dpc.threshold = 256; // Gradient threshold (0-4095) dpc.flags = 0; // Reserved // Flat region detection dpc.black_level = 64; // Black level in 10-bit dpc.white_level = 1023; // White level in 10-bit be.SetDpc(dpc); // Enable DPC in Bayer processing pisp_be_global_config global; be.GetGlobal(global); global.bayer_enables |= PISP_BE_BAYER_ENABLE_DPC; be.SetGlobal(global); std::cout << "DPC: threshold=" << dpc.threshold << " range=[" << dpc.black_level << ", " << dpc.white_level << "]\n"; ``` -------------------------------- ### Configure Chromatic Aberration Correction with Per-Color Offset in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This code configures the Chromatic Aberration Correction (CAC) block using per-pixel offset correction based on radial distance. It defines a grid configuration and populates a lookup table (LUT) with radial offset multipliers for red and blue channels. The offsets increase with radial distance from the center. Dependencies include libpisp/backend/backend.hpp and for sqrt. ```cpp #include #include // CAC uses per-pixel offset correction based on radial distance pisp_be_cac_config cac = {}; // Grid configuration (16x12 grid like LSC) cac.grid_step_x = 4096; cac.grid_step_y = 4096; // LUT: radial offset multipliers for R and B channels // Values in s4.8 fixed point (multiply by 256) for (int i = 0; i < PISP_BE_CAC_GRID_SIZE; i++) { int row = i / 16; int col = i % 16; // Calculate radial distance from center float dx = (col - 8.0f) / 8.0f; float dy = (row - 6.0f) / 6.0f; float r = sqrt(dx*dx + dy*dy); // Correction increases with distance int16_t offset_r = (int16_t)(r * 32); // Red shifts outward int16_t offset_b = (int16_t)(r * -32); // Blue shifts inward cac.lut_r[i] = offset_r; cac.lut_b[i] = offset_b; } be.SetCac(cac); // Enable CAC pisp_be_global_config global; be.GetGlobal(global); global.bayer_enables |= PISP_BE_BAYER_ENABLE_CAC; be.SetGlobal(global); std::cout << "CAC configured with radial correction\n"; ``` -------------------------------- ### Configure Edge-Preserving Sharpening in libpisp Backend Source: https://context7.com/raspberrypi/libpisp/llms.txt This snippet configures an edge-preserving sharpening filter in the libpisp backend, allowing adjustable strength, threshold, and response curves to enhance image details while protecting edges. It requires the libpisp backend header and sets parameters like threshold (0-255 for edge detection), limit (max amplitude), and strength (0-255). Outputs include updated backend configuration; limitations include fixed-point response curves and dependency on global RGB enables. ```cpp #include pisp_be_sharpen_config sharpen = {}; // Sharpening strength (0-255) sharpen.threshold = 32; // Edge detection threshold sharpen.limit = 255; // Maximum sharpening amplitude sharpen.strength = 128; // Sharpening strength (0=off, 255=max) // Response curve: defines sharpening vs. edge strength // Format: 5-point PWL curve in u0.10 fixed point sharpen.response = {0, 256, 512, 768, 1024}; sharpen.response_x = {0, 256, 512, 768, 1024}; // Positive/negative sharpening behavior sharpen.positive_pre_limit = 255; sharpen.negative_pre_limit = 255; sharpen.positive_strength = 128; sharpen.negative_strength = 128; be.SetSharpen(sharpen); // Enable sharpening in global config pisp_be_global_config global; be.GetGlobal(global); global.rgb_enables |= PISP_BE_RGB_ENABLE_SHARPEN; be.SetGlobal(global); std::cout << "Sharpening: strength=" << (int)sharpen.strength << " threshold=" << (int)sharpen.threshold << "\n"; ``` -------------------------------- ### Suppress False Color in C++ Source: https://context7.com/raspberrypi/libpisp/llms.txt This code snippet demonstrates how to suppress false color artifacts in high-frequency areas using the libpisp C++ API. It configures the false color suppression parameters (threshold and strength) and enables the feature in the global configuration. ```cpp #include pisp_be_false_colour_config fc = {}; // False color suppression parameters fc.threshold = 128; // Detection threshold fc.strength = 64; // Suppression strength be.SetFalseColour(fc); // Enable false color suppression pisp_be_global_config global; be.GetGlobal(global); global.rgb_enables |= PISP_BE_RGB_ENABLE_FALSE_COLOUR; be.SetGlobal(global); std::cout << "False color suppression: threshold=" << (int)fc.threshold << " strength=" << (int)fc.strength << "\n"; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.