Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/libcamera/src/apps/qcam/assets
repos/libcamera/src/apps/qcam/assets/shader/YUV_2_planes.frag
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Linaro * * YUV_2_planes.frag - Fragment shader code for NV12, NV16 and NV24 formats */ #ifdef GL_ES precision mediump float; #endif varying vec2 textureOut; uniform sampler2D tex_y; uniform sampler2D tex_u; const mat3 yuv2rgb_matrix = mat3( YUV2RGB_MATRIX ); const vec3 yuv2rgb_offset = vec3( YUV2RGB_Y_OFFSET / 255.0, 128.0 / 255.0, 128.0 / 255.0 ); void main(void) { vec3 yuv; yuv.x = texture2D(tex_y, textureOut).r; #if defined(YUV_PATTERN_UV) yuv.y = texture2D(tex_u, textureOut).r; yuv.z = texture2D(tex_u, textureOut).a; #elif defined(YUV_PATTERN_VU) yuv.y = texture2D(tex_u, textureOut).a; yuv.z = texture2D(tex_u, textureOut).r; #else #error Invalid pattern #endif vec3 rgb = yuv2rgb_matrix * (yuv - yuv2rgb_offset); gl_FragColor = vec4(rgb, 1.0); }
0
repos/libcamera/src/apps/qcam/assets
repos/libcamera/src/apps/qcam/assets/shader/YUV_3_planes.frag
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Linaro * * YUV_3_planes_UV.frag - Fragment shader code for YUV420 format */ #ifdef GL_ES precision mediump float; #endif varying vec2 textureOut; uniform sampler2D tex_y; uniform sampler2D tex_u; uniform sampler2D tex_v; const mat3 yuv2rgb_matrix = mat3( YUV2RGB_MATRIX ); const vec3 yuv2rgb_offset = vec3( YUV2RGB_Y_OFFSET / 255.0, 128.0 / 255.0, 128.0 / 255.0 ); void main(void) { vec3 yuv; yuv.x = texture2D(tex_y, textureOut).r; yuv.y = texture2D(tex_u, textureOut).r; yuv.z = texture2D(tex_v, textureOut).r; vec3 rgb = yuv2rgb_matrix * (yuv - yuv2rgb_offset); gl_FragColor = vec4(rgb, 1.0); }
0
repos/libcamera/src/apps/qcam/assets
repos/libcamera/src/apps/qcam/assets/shader/identity.vert
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Linaro * * identity.vert - Identity vertex shader for pixel format conversion */ attribute vec4 vertexIn; attribute vec2 textureIn; varying vec2 textureOut; uniform float stride_factor; void main(void) { gl_Position = vertexIn; textureOut = vec2(textureIn.x * stride_factor, textureIn.y); }
0
repos/libcamera/src/apps/qcam/assets
repos/libcamera/src/apps/qcam/assets/shader/bayer_8.vert
/* SPDX-License-Identifier: BSD-2-Clause */ /* From http://jgt.akpeters.com/papers/McGuire08/ Efficient, High-Quality Bayer Demosaic Filtering on GPUs Morgan McGuire This paper appears in issue Volume 13, Number 4. --------------------------------------------------------- Copyright (c) 2008, Morgan McGuire. All rights reserved. Modified by Linaro Ltd to integrate it into libcamera. Copyright (C) 2021, Linaro */ //Vertex Shader attribute vec4 vertexIn; attribute vec2 textureIn; uniform vec2 tex_size; /* The texture size in pixels */ uniform vec2 tex_step; /** Pixel position of the first red pixel in the */ /** Bayer pattern. [{0,1}, {0, 1}]*/ uniform vec2 tex_bayer_first_red; /** .xy = Pixel being sampled in the fragment shader on the range [0, 1] .zw = ...on the range [0, sourceSize], offset by firstRed */ varying vec4 center; /** center.x + (-2/w, -1/w, 1/w, 2/w); These are the x-positions */ /** of the adjacent pixels.*/ varying vec4 xCoord; /** center.y + (-2/h, -1/h, 1/h, 2/h); These are the y-positions */ /** of the adjacent pixels.*/ varying vec4 yCoord; void main(void) { center.xy = textureIn; center.zw = textureIn * tex_size + tex_bayer_first_red; xCoord = center.x + vec4(-2.0 * tex_step.x, -tex_step.x, tex_step.x, 2.0 * tex_step.x); yCoord = center.y + vec4(-2.0 * tex_step.y, -tex_step.y, tex_step.y, 2.0 * tex_step.y); gl_Position = vertexIn; }
0
repos/libcamera/src/apps/qcam/assets
repos/libcamera/src/apps/qcam/assets/shader/YUV_packed.frag
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Laurent Pinchart <[email protected]> * * YUV_packed.frag - Fragment shader code for YUYV packed formats */ #ifdef GL_ES precision mediump float; #endif varying vec2 textureOut; uniform sampler2D tex_y; uniform vec2 tex_step; const mat3 yuv2rgb_matrix = mat3( YUV2RGB_MATRIX ); const vec3 yuv2rgb_offset = vec3( YUV2RGB_Y_OFFSET / 255.0, 128.0 / 255.0, 128.0 / 255.0 ); void main(void) { /* * The sampler won't interpolate the texture correctly along the X axis, * as each RGBA pixel effectively stores two pixels. We thus need to * interpolate manually. * * In integer texture coordinates, the Y values are layed out in the * texture memory as follows: * * ...| Y U Y V | Y U Y V | Y U Y V |... * ...| R G B A | R G B A | R G B A |... * ^ ^ ^ ^ ^ ^ * | | | | | | * n-1 n-0.5 n n+0.5 n+1 n+1.5 * * For a texture location x in the interval [n, n+1[, sample the left * and right pixels at n and n+1, and interpolate them with * * left.r * (1 - a) + left.b * a if fract(x) < 0.5 * left.b * (1 - a) + right.r * a if fract(x) >= 0.5 * * with a = fract(x * 2) which can also be written * * a = fract(x) * 2 if fract(x) < 0.5 * a = fract(x) * 2 - 1 if fract(x) >= 0.5 */ vec2 pos = textureOut; float f_x = fract(pos.x / tex_step.x); vec4 left = texture2D(tex_y, vec2(pos.x - f_x * tex_step.x, pos.y)); vec4 right = texture2D(tex_y, vec2(pos.x + (1.0 - f_x) * tex_step.x , pos.y)); #if defined(YUV_PATTERN_UYVY) float y_left = mix(left.g, left.a, f_x * 2.0); float y_right = mix(left.a, right.g, f_x * 2.0 - 1.0); vec2 uv = mix(left.rb, right.rb, f_x); #elif defined(YUV_PATTERN_VYUY) float y_left = mix(left.g, left.a, f_x * 2.0); float y_right = mix(left.a, right.g, f_x * 2.0 - 1.0); vec2 uv = mix(left.br, right.br, f_x); #elif defined(YUV_PATTERN_YUYV) float y_left = mix(left.r, left.b, f_x * 2.0); float y_right = mix(left.b, right.r, f_x * 2.0 - 1.0); vec2 uv = mix(left.ga, right.ga, f_x); #elif defined(YUV_PATTERN_YVYU) float y_left = mix(left.r, left.b, f_x * 2.0); float y_right = mix(left.b, right.r, f_x * 2.0 - 1.0); vec2 uv = mix(left.ag, right.ag, f_x); #else #error Invalid pattern #endif float y = mix(y_left, y_right, step(0.5, f_x)); vec3 rgb = yuv2rgb_matrix * (vec3(y, uv) - yuv2rgb_offset); gl_FragColor = vec4(rgb, 1.0); }
0
repos/libcamera/src/apps/qcam/assets
repos/libcamera/src/apps/qcam/assets/shader/bayer_1x_packed.frag
/* SPDX-License-Identifier: BSD-2-Clause */ /* * Based on the code from http://jgt.akpeters.com/papers/McGuire08/ * * Efficient, High-Quality Bayer Demosaic Filtering on GPUs * * Morgan McGuire * * This paper appears in issue Volume 13, Number 4. * --------------------------------------------------------- * Copyright (c) 2008, Morgan McGuire. All rights reserved. * * * Modified by Linaro Ltd for 10/12-bit packed vs 8-bit raw Bayer format, * and for simpler demosaic algorithm. * Copyright (C) 2020, Linaro * * bayer_1x_packed.frag - Fragment shader code for raw Bayer 10-bit and 12-bit * packed formats */ #ifdef GL_ES precision mediump float; #endif /* * These constants are used to select the bytes containing the HS part of * the pixel value: * BPP - bytes per pixel, * THRESHOLD_L = fract(BPP) * 0.5 + 0.02 * THRESHOLD_H = 1.0 - fract(BPP) * 1.5 + 0.02 * Let X is the x coordinate in the texture measured in bytes (so that the * range is from 0 to (stride_-1)) aligned on the nearest pixel. * E.g. for RAW10P: * -------------+-------------------+-------------------+-- * pixel No | 0 1 2 3 | 4 5 6 7 | ... * -------------+-------------------+-------------------+-- * byte offset | 0 1 2 3 4 | 5 6 7 8 9 | ... * -------------+-------------------+-------------------+-- * X | 0.0 1.25 2.5 3.75 | 5.0 6.25 7.5 8.75 | ... * -------------+-------------------+-------------------+-- * If fract(X) < THRESHOLD_L then the previous byte contains the LS * bits of the pixel values and needs to be skipped. * If fract(X) > THRESHOLD_H then the next byte contains the LS bits * of the pixel values and needs to be skipped. */ #if defined(RAW10P) #define BPP 1.25 #define THRESHOLD_L 0.14 #define THRESHOLD_H 0.64 #elif defined(RAW12P) #define BPP 1.5 #define THRESHOLD_L 0.27 #define THRESHOLD_H 0.27 #else #error Invalid raw format #endif varying vec2 textureOut; /* the texture size in pixels */ uniform vec2 tex_size; uniform vec2 tex_step; uniform vec2 tex_bayer_first_red; uniform sampler2D tex_y; void main(void) { vec3 rgb; /* * center_bytes holds the coordinates of the MS byte of the pixel * being sampled on the [0, stride-1/height-1] range. * center_pixel holds the coordinates of the pixel being sampled * on the [0, width/height-1] range. */ vec2 center_bytes; vec2 center_pixel; /* * x- and y-positions of the adjacent pixels on the [0, 1] range. */ vec2 xcoords; vec2 ycoords; /* * The coordinates passed to the shader in textureOut may point * to a place in between the pixels if the texture format doesn't * match the image format. In particular, MIPI packed raw Bayer * formats don't have a matching texture format. * In this case align the coordinates to the left nearest pixel * by hand. */ center_pixel = floor(textureOut * tex_size); center_bytes.y = center_pixel.y; /* * Add a small number (a few mantissa's LSBs) to avoid float * representation issues. Maybe paranoic. */ center_bytes.x = BPP * center_pixel.x + 0.02; float fract_x = fract(center_bytes.x); /* * The below floor() call ensures that center_bytes.x points * at one of the bytes representing the 8 higher bits of * the pixel value, not at the byte containing the LS bits * of the group of the pixels. */ center_bytes.x = floor(center_bytes.x); center_bytes *= tex_step; xcoords = center_bytes.x + vec2(-tex_step.x, tex_step.x); ycoords = center_bytes.y + vec2(-tex_step.y, tex_step.y); /* * If xcoords[0] points at the byte containing the LS bits * of the previous group of the pixels, move xcoords[0] one * byte back. */ xcoords[0] += (fract_x < THRESHOLD_L) ? -tex_step.x : 0.0; /* * If xcoords[1] points at the byte containing the LS bits * of the current group of the pixels, move xcoords[1] one * byte forward. */ xcoords[1] += (fract_x > THRESHOLD_H) ? tex_step.x : 0.0; vec2 alternate = mod(center_pixel.xy + tex_bayer_first_red, 2.0); bool even_col = alternate.x < 1.0; bool even_row = alternate.y < 1.0; /* * We need to sample the central pixel and the ones with offset * of -1 to +1 pixel in both X and Y directions. Let's name these * pixels as below, where C is the central pixel: * * +----+----+----+----+ * | \ x| | | | * |y \ | -1 | 0 | +1 | * +----+----+----+----+ * | +1 | D2 | A1 | D3 | * +----+----+----+----+ * | 0 | B0 | C | B1 | * +----+----+----+----+ * | -1 | D0 | A0 | D1 | * +----+----+----+----+ * * In the below equations (0,-1).r means "r component of the texel * shifted by -tex_step.y from the center_bytes one" etc. * * In the even row / even column (EE) case the colour values are: * R = C = (0,0).r, * G = (A0 + A1 + B0 + B1) / 4.0 = * ( (0,-1).r + (0,1).r + (-1,0).r + (1,0).r ) / 4.0, * B = (D0 + D1 + D2 + D3) / 4.0 = * ( (-1,-1).r + (1,-1).r + (-1,1).r + (1,1).r ) / 4.0 * * For even row / odd column (EO): * R = (B0 + B1) / 2.0 = ( (-1,0).r + (1,0).r ) / 2.0, * G = C = (0,0).r, * B = (A0 + A1) / 2.0 = ( (0,-1).r + (0,1).r ) / 2.0 * * For odd row / even column (OE): * R = (A0 + A1) / 2.0 = ( (0,-1).r + (0,1).r ) / 2.0, * G = C = (0,0).r, * B = (B0 + B1) / 2.0 = ( (-1,0).r + (1,0).r ) / 2.0 * * For odd row / odd column (OO): * R = (D0 + D1 + D2 + D3) / 4.0 = * ( (-1,-1).r + (1,-1).r + (-1,1).r + (1,1).r ) / 4.0, * G = (A0 + A1 + B0 + B1) / 4.0 = * ( (0,-1).r + (0,1).r + (-1,0).r + (1,0).r ) / 4.0, * B = C = (0,0).r */ /* * Fetch the values and precalculate the terms: * patterns.x = (A0 + A1) / 2.0 * patterns.y = (B0 + B1) / 2.0 * patterns.z = (A0 + A1 + B0 + B1) / 4.0 * patterns.w = (D0 + D1 + D2 + D3) / 4.0 */ #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r float C = texture2D(tex_y, center_bytes).r; vec4 patterns = vec4( fetch(center_bytes.x, ycoords[0]), /* A0: (0,-1) */ fetch(xcoords[0], center_bytes.y), /* B0: (-1,0) */ fetch(xcoords[0], ycoords[0]), /* D0: (-1,-1) */ fetch(xcoords[1], ycoords[0])); /* D1: (1,-1) */ vec4 temp = vec4( fetch(center_bytes.x, ycoords[1]), /* A1: (0,1) */ fetch(xcoords[1], center_bytes.y), /* B1: (1,0) */ fetch(xcoords[1], ycoords[1]), /* D3: (1,1) */ fetch(xcoords[0], ycoords[1])); /* D2: (-1,1) */ patterns = (patterns + temp) * 0.5; /* .x = (A0 + A1) / 2.0, .y = (B0 + B1) / 2.0 */ /* .z = (D0 + D3) / 2.0, .w = (D1 + D2) / 2.0 */ patterns.w = (patterns.z + patterns.w) * 0.5; patterns.z = (patterns.x + patterns.y) * 0.5; rgb = even_col ? (even_row ? vec3(C, patterns.zw) : vec3(patterns.x, C, patterns.y)) : (even_row ? vec3(patterns.y, C, patterns.x) : vec3(patterns.wz, C)); gl_FragColor = vec4(rgb, 1.0); }
0
repos/libcamera/src/apps/qcam/assets
repos/libcamera/src/apps/qcam/assets/shader/RGB.frag
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Laurent Pinchart * * RGB.frag - Fragment shader code for RGB formats */ #ifdef GL_ES precision mediump float; #endif varying vec2 textureOut; uniform sampler2D tex_y; void main(void) { vec3 rgb; rgb = texture2D(tex_y, textureOut).RGB_PATTERN; gl_FragColor = vec4(rgb, 1.0); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/lc-compliance/environment.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2021, Collabora Ltd. * * Common environment for tests */ #pragma once #include <libcamera/libcamera.h> class Environment { public: static Environment *get(); void setup(libcamera::CameraManager *cm, std::string cameraId); const std::string &cameraId() const { return cameraId_; } libcamera::CameraManager *cm() const { return cm_; } private: Environment() = default; std::string cameraId_; libcamera::CameraManager *cm_; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/lc-compliance/environment.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2021, Collabora Ltd. * * Common environment for tests */ #include "environment.h" using namespace libcamera; Environment *Environment::get() { static Environment instance; return &instance; } void Environment::setup(CameraManager *cm, std::string cameraId) { cm_ = cm; cameraId_ = cameraId; }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/lc-compliance/main.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2020, Google Inc. * Copyright (C) 2021, Collabora Ltd. * * lc-compliance - The libcamera compliance tool */ #include <iomanip> #include <iostream> #include <string.h> #include <gtest/gtest.h> #include <libcamera/libcamera.h> #include "../common/options.h" #include "environment.h" using namespace libcamera; enum { OptCamera = 'c', OptList = 'l', OptFilter = 'f', OptHelp = 'h', }; /* * Make asserts act like exceptions, otherwise they only fail (or skip) the * current function. From gtest documentation: * https://google.github.io/googletest/advanced.html#asserting-on-subroutines-with-an-exception */ class ThrowListener : public testing::EmptyTestEventListener { void OnTestPartResult(const testing::TestPartResult &result) override { if (result.type() == testing::TestPartResult::kFatalFailure || result.type() == testing::TestPartResult::kSkip) throw testing::AssertionException(result); } }; static void listCameras(CameraManager *cm) { for (const std::shared_ptr<Camera> &cam : cm->cameras()) std::cout << "- " << cam.get()->id() << std::endl; } static int initCamera(CameraManager *cm, OptionsParser::Options options) { std::shared_ptr<Camera> camera; int ret = cm->start(); if (ret) { std::cout << "Failed to start camera manager: " << strerror(-ret) << std::endl; return ret; } if (!options.isSet(OptCamera)) { std::cout << "No camera specified, available cameras:" << std::endl; listCameras(cm); return -ENODEV; } const std::string &cameraId = options[OptCamera]; camera = cm->get(cameraId); if (!camera) { std::cout << "Camera " << cameraId << " not found, available cameras:" << std::endl; listCameras(cm); return -ENODEV; } Environment::get()->setup(cm, cameraId); std::cout << "Using camera " << cameraId << std::endl; return 0; } static int initGtestParameters(char *arg0, OptionsParser::Options options) { const std::map<std::string, std::string> gtestFlags = { { "list", "--gtest_list_tests" }, { "filter", "--gtest_filter" } }; int argc = 0; std::string filterParam; /* * +2 to have space for both the 0th argument that is needed but not * used and the null at the end. */ char **argv = new char *[(gtestFlags.size() + 2)]; if (!argv) return -ENOMEM; argv[0] = arg0; argc++; if (options.isSet(OptList)) { argv[argc] = const_cast<char *>(gtestFlags.at("list").c_str()); argc++; } if (options.isSet(OptFilter)) { /* * The filter flag needs to be passed as a single parameter, in * the format --gtest_filter=filterStr */ filterParam = gtestFlags.at("filter") + "=" + static_cast<const std::string &>(options[OptFilter]); argv[argc] = const_cast<char *>(filterParam.c_str()); argc++; } argv[argc] = nullptr; ::testing::InitGoogleTest(&argc, argv); delete[] argv; return 0; } static int initGtest(char *arg0, OptionsParser::Options options) { int ret = initGtestParameters(arg0, options); if (ret) return ret; testing::UnitTest::GetInstance()->listeners().Append(new ThrowListener); return 0; } static int parseOptions(int argc, char **argv, OptionsParser::Options *options) { OptionsParser parser; parser.addOption(OptCamera, OptionString, "Specify which camera to operate on, by id", "camera", ArgumentRequired, "camera"); parser.addOption(OptList, OptionNone, "List all tests and exit", "list"); parser.addOption(OptFilter, OptionString, "Specify which tests to run", "filter", ArgumentRequired, "filter"); parser.addOption(OptHelp, OptionNone, "Display this help message", "help"); *options = parser.parse(argc, argv); if (!options->valid()) return -EINVAL; if (options->isSet(OptHelp)) { parser.usage(); std::cerr << "Further options from Googletest can be passed as environment variables" << std::endl; return -EINTR; } return 0; } int main(int argc, char **argv) { OptionsParser::Options options; int ret = parseOptions(argc, argv, &options); if (ret == -EINTR) return EXIT_SUCCESS; if (ret < 0) return EXIT_FAILURE; std::unique_ptr<CameraManager> cm = std::make_unique<CameraManager>(); /* No need to initialize the camera if we'll just list tests */ if (!options.isSet(OptList)) { ret = initCamera(cm.get(), options); if (ret) return ret; } ret = initGtest(argv[0], options); if (ret) return ret; ret = RUN_ALL_TESTS(); if (!options.isSet(OptList)) cm->stop(); return ret; }
0
repos/libcamera/src/apps/lc-compliance
repos/libcamera/src/apps/lc-compliance/tests/capture_test.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2020, Google Inc. * Copyright (C) 2021, Collabora Ltd. * * Test camera capture */ #include "capture.h" #include <iostream> #include <gtest/gtest.h> #include "environment.h" using namespace libcamera; const std::vector<int> NUMREQUESTS = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 }; const std::vector<StreamRole> ROLES = { StreamRole::Raw, StreamRole::StillCapture, StreamRole::VideoRecording, StreamRole::Viewfinder }; class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>> { public: static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info); protected: void SetUp() override; void TearDown() override; std::shared_ptr<Camera> camera_; }; /* * We use gtest's SetUp() and TearDown() instead of constructor and destructor * in order to be able to assert on them. */ void SingleStream::SetUp() { Environment *env = Environment::get(); camera_ = env->cm()->get(env->cameraId()); ASSERT_EQ(camera_->acquire(), 0); } void SingleStream::TearDown() { if (!camera_) return; camera_->release(); camera_.reset(); } std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info) { std::map<StreamRole, std::string> rolesMap = { { StreamRole::Raw, "Raw" }, { StreamRole::StillCapture, "StillCapture" }, { StreamRole::VideoRecording, "VideoRecording" }, { StreamRole::Viewfinder, "Viewfinder" } }; std::string roleName = rolesMap[std::get<0>(info.param)]; std::string numRequestsName = std::to_string(std::get<1>(info.param)); return roleName + "_" + numRequestsName; } /* * Test single capture cycles * * Makes sure the camera completes the exact number of requests queued. Example * failure is a camera that completes less requests than the number of requests * queued. */ TEST_P(SingleStream, Capture) { auto [role, numRequests] = GetParam(); CaptureBalanced capture(camera_); capture.configure(role); capture.capture(numRequests); } /* * Test multiple start/stop cycles * * Makes sure the camera supports multiple start/stop cycles. Example failure is * a camera that does not clean up correctly in its error path but is only * tested by single-capture applications. */ TEST_P(SingleStream, CaptureStartStop) { auto [role, numRequests] = GetParam(); unsigned int numRepeats = 3; CaptureBalanced capture(camera_); capture.configure(role); for (unsigned int starts = 0; starts < numRepeats; starts++) capture.capture(numRequests); } /* * Test unbalanced stop * * Makes sure the camera supports a stop with requests queued. Example failure * is a camera that does not handle cancelation of buffers coming back from the * video device while stopping. */ TEST_P(SingleStream, UnbalancedStop) { auto [role, numRequests] = GetParam(); CaptureUnbalanced capture(camera_); capture.configure(role); capture.capture(numRequests); } INSTANTIATE_TEST_SUITE_P(CaptureTests, SingleStream, testing::Combine(testing::ValuesIn(ROLES), testing::ValuesIn(NUMREQUESTS)), SingleStream::nameParameters);
0
repos/libcamera/src/apps/lc-compliance
repos/libcamera/src/apps/lc-compliance/helpers/capture.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2020-2021, Google Inc. * * Simple capture helper */ #pragma once #include <memory> #include <libcamera/libcamera.h> #include "../common/event_loop.h" class Capture { public: void configure(libcamera::StreamRole role); protected: Capture(std::shared_ptr<libcamera::Camera> camera); virtual ~Capture(); void start(); void stop(); virtual void requestComplete(libcamera::Request *request) = 0; EventLoop *loop_; std::shared_ptr<libcamera::Camera> camera_; std::unique_ptr<libcamera::FrameBufferAllocator> allocator_; std::unique_ptr<libcamera::CameraConfiguration> config_; std::vector<std::unique_ptr<libcamera::Request>> requests_; }; class CaptureBalanced : public Capture { public: CaptureBalanced(std::shared_ptr<libcamera::Camera> camera); void capture(unsigned int numRequests); private: int queueRequest(libcamera::Request *request); void requestComplete(libcamera::Request *request) override; unsigned int queueCount_; unsigned int captureCount_; unsigned int captureLimit_; }; class CaptureUnbalanced : public Capture { public: CaptureUnbalanced(std::shared_ptr<libcamera::Camera> camera); void capture(unsigned int numRequests); private: void requestComplete(libcamera::Request *request) override; unsigned int captureCount_; unsigned int captureLimit_; };
0
repos/libcamera/src/apps/lc-compliance
repos/libcamera/src/apps/lc-compliance/helpers/capture.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2020-2021, Google Inc. * * Simple capture helper */ #include "capture.h" #include <gtest/gtest.h> using namespace libcamera; Capture::Capture(std::shared_ptr<Camera> camera) : loop_(nullptr), camera_(camera), allocator_(std::make_unique<FrameBufferAllocator>(camera)) { } Capture::~Capture() { stop(); } void Capture::configure(StreamRole role) { config_ = camera_->generateConfiguration({ role }); if (!config_) { std::cout << "Role not supported by camera" << std::endl; GTEST_SKIP(); } if (config_->validate() != CameraConfiguration::Valid) { config_.reset(); FAIL() << "Configuration not valid"; } if (camera_->configure(config_.get())) { config_.reset(); FAIL() << "Failed to configure camera"; } } void Capture::start() { Stream *stream = config_->at(0).stream(); int count = allocator_->allocate(stream); ASSERT_GE(count, 0) << "Failed to allocate buffers"; EXPECT_EQ(count, config_->at(0).bufferCount) << "Allocated less buffers than expected"; camera_->requestCompleted.connect(this, &Capture::requestComplete); ASSERT_EQ(camera_->start(), 0) << "Failed to start camera"; } void Capture::stop() { if (!config_ || !allocator_->allocated()) return; camera_->stop(); camera_->requestCompleted.disconnect(this); Stream *stream = config_->at(0).stream(); requests_.clear(); allocator_->free(stream); } /* CaptureBalanced */ CaptureBalanced::CaptureBalanced(std::shared_ptr<Camera> camera) : Capture(camera) { } void CaptureBalanced::capture(unsigned int numRequests) { start(); Stream *stream = config_->at(0).stream(); const std::vector<std::unique_ptr<FrameBuffer>> &buffers = allocator_->buffers(stream); /* No point in testing less requests then the camera depth. */ if (buffers.size() > numRequests) { std::cout << "Camera needs " + std::to_string(buffers.size()) + " requests, can't test only " + std::to_string(numRequests) << std::endl; GTEST_SKIP(); } queueCount_ = 0; captureCount_ = 0; captureLimit_ = numRequests; /* Queue the recommended number of requests. */ for (const std::unique_ptr<FrameBuffer> &buffer : buffers) { std::unique_ptr<Request> request = camera_->createRequest(); ASSERT_TRUE(request) << "Can't create request"; ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; ASSERT_EQ(queueRequest(request.get()), 0) << "Failed to queue request"; requests_.push_back(std::move(request)); } /* Run capture session. */ loop_ = new EventLoop(); loop_->exec(); stop(); delete loop_; ASSERT_EQ(captureCount_, captureLimit_); } int CaptureBalanced::queueRequest(Request *request) { queueCount_++; if (queueCount_ > captureLimit_) return 0; return camera_->queueRequest(request); } void CaptureBalanced::requestComplete(Request *request) { EXPECT_EQ(request->status(), Request::Status::RequestComplete) << "Request didn't complete successfully"; captureCount_++; if (captureCount_ >= captureLimit_) { loop_->exit(0); return; } request->reuse(Request::ReuseBuffers); if (queueRequest(request)) loop_->exit(-EINVAL); } /* CaptureUnbalanced */ CaptureUnbalanced::CaptureUnbalanced(std::shared_ptr<Camera> camera) : Capture(camera) { } void CaptureUnbalanced::capture(unsigned int numRequests) { start(); Stream *stream = config_->at(0).stream(); const std::vector<std::unique_ptr<FrameBuffer>> &buffers = allocator_->buffers(stream); captureCount_ = 0; captureLimit_ = numRequests; /* Queue the recommended number of requests. */ for (const std::unique_ptr<FrameBuffer> &buffer : buffers) { std::unique_ptr<Request> request = camera_->createRequest(); ASSERT_TRUE(request) << "Can't create request"; ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; ASSERT_EQ(camera_->queueRequest(request.get()), 0) << "Failed to queue request"; requests_.push_back(std::move(request)); } /* Run capture session. */ loop_ = new EventLoop(); int status = loop_->exec(); stop(); delete loop_; ASSERT_EQ(status, 0); } void CaptureUnbalanced::requestComplete(Request *request) { captureCount_++; if (captureCount_ >= captureLimit_) { loop_->exit(0); return; } EXPECT_EQ(request->status(), Request::Status::RequestComplete) << "Request didn't complete successfully"; request->reuse(Request::ReuseBuffers); if (camera_->queueRequest(request)) loop_->exit(-EINVAL); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/image.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas on Board Oy * * Multi-planar image with access to pixel data */ #include "image.h" #include <assert.h> #include <errno.h> #include <iostream> #include <map> #include <string.h> #include <sys/mman.h> #include <unistd.h> using namespace libcamera; std::unique_ptr<Image> Image::fromFrameBuffer(const FrameBuffer *buffer, MapMode mode) { std::unique_ptr<Image> image{ new Image() }; assert(!buffer->planes().empty()); int mmapFlags = 0; if (mode & MapMode::ReadOnly) mmapFlags |= PROT_READ; if (mode & MapMode::WriteOnly) mmapFlags |= PROT_WRITE; struct MappedBufferInfo { uint8_t *address = nullptr; size_t mapLength = 0; size_t dmabufLength = 0; }; std::map<int, MappedBufferInfo> mappedBuffers; for (const FrameBuffer::Plane &plane : buffer->planes()) { const int fd = plane.fd.get(); if (mappedBuffers.find(fd) == mappedBuffers.end()) { const size_t length = lseek(fd, 0, SEEK_END); mappedBuffers[fd] = MappedBufferInfo{ nullptr, 0, length }; } const size_t length = mappedBuffers[fd].dmabufLength; if (plane.offset > length || plane.offset + plane.length > length) { std::cerr << "plane is out of buffer: buffer length=" << length << ", plane offset=" << plane.offset << ", plane length=" << plane.length << std::endl; return nullptr; } size_t &mapLength = mappedBuffers[fd].mapLength; mapLength = std::max(mapLength, static_cast<size_t>(plane.offset + plane.length)); } for (const FrameBuffer::Plane &plane : buffer->planes()) { const int fd = plane.fd.get(); auto &info = mappedBuffers[fd]; if (!info.address) { void *address = mmap(nullptr, info.mapLength, mmapFlags, MAP_SHARED, fd, 0); if (address == MAP_FAILED) { int error = -errno; std::cerr << "Failed to mmap plane: " << strerror(-error) << std::endl; return nullptr; } info.address = static_cast<uint8_t *>(address); image->maps_.emplace_back(info.address, info.mapLength); } image->planes_.emplace_back(info.address + plane.offset, plane.length); } return image; } Image::Image() = default; Image::~Image() { for (Span<uint8_t> &map : maps_) munmap(map.data(), map.size()); } unsigned int Image::numPlanes() const { return planes_.size(); } Span<uint8_t> Image::data(unsigned int plane) { assert(plane <= planes_.size()); return planes_[plane]; } Span<const uint8_t> Image::data(unsigned int plane) const { assert(plane <= planes_.size()); return planes_[plane]; }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/stream_options.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2020, Raspberry Pi Ltd * * Helper to parse options for streams */ #include "stream_options.h" #include <iostream> #include <libcamera/color_space.h> using namespace libcamera; StreamKeyValueParser::StreamKeyValueParser() { addOption("role", OptionString, "Role for the stream (viewfinder, video, still, raw)", ArgumentRequired); addOption("width", OptionInteger, "Width in pixels", ArgumentRequired); addOption("height", OptionInteger, "Height in pixels", ArgumentRequired); addOption("pixelformat", OptionString, "Pixel format name", ArgumentRequired); addOption("colorspace", OptionString, "Color space", ArgumentRequired); } KeyValueParser::Options StreamKeyValueParser::parse(const char *arguments) { KeyValueParser::Options options = KeyValueParser::parse(arguments); if (options.valid() && options.isSet("role") && !parseRole(options)) { std::cerr << "Unknown stream role " << options["role"].toString() << std::endl; options.invalidate(); } return options; } std::vector<StreamRole> StreamKeyValueParser::roles(const OptionValue &values) { /* If no configuration values to examine default to viewfinder. */ if (values.empty()) return { StreamRole::Viewfinder }; const std::vector<OptionValue> &streamParameters = values.toArray(); std::vector<StreamRole> roles; for (auto const &value : streamParameters) { /* If a role is invalid default it to viewfinder. */ roles.push_back(parseRole(value.toKeyValues()).value_or(StreamRole::Viewfinder)); } return roles; } int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config, const OptionValue &values) { if (!config) { std::cerr << "No configuration provided" << std::endl; return -EINVAL; } /* If no configuration values nothing to do. */ if (values.empty()) return 0; const std::vector<OptionValue> &streamParameters = values.toArray(); if (config->size() != streamParameters.size()) { std::cerr << "Number of streams in configuration " << config->size() << " does not match number of streams parsed " << streamParameters.size() << std::endl; return -EINVAL; } unsigned int i = 0; for (auto const &value : streamParameters) { KeyValueParser::Options opts = value.toKeyValues(); StreamConfiguration &cfg = config->at(i++); if (opts.isSet("width") && opts.isSet("height")) { cfg.size.width = opts["width"]; cfg.size.height = opts["height"]; } if (opts.isSet("pixelformat")) cfg.pixelFormat = PixelFormat::fromString(opts["pixelformat"].toString()); if (opts.isSet("colorspace")) cfg.colorSpace = ColorSpace::fromString(opts["colorspace"].toString()); } return 0; } std::optional<libcamera::StreamRole> StreamKeyValueParser::parseRole(const KeyValueParser::Options &options) { if (!options.isSet("role")) return {}; std::string name = options["role"].toString(); if (name == "viewfinder") return StreamRole::Viewfinder; else if (name == "video") return StreamRole::VideoRecording; else if (name == "still") return StreamRole::StillCapture; else if (name == "raw") return StreamRole::Raw; return {}; }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/stream_options.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2020, Raspberry Pi Ltd * * Helper to parse options for streams */ #pragma once #include <optional> #include <libcamera/camera.h> #include "options.h" class StreamKeyValueParser : public KeyValueParser { public: StreamKeyValueParser(); KeyValueParser::Options parse(const char *arguments) override; static std::vector<libcamera::StreamRole> roles(const OptionValue &values); static int updateConfiguration(libcamera::CameraConfiguration *config, const OptionValue &values); private: static std::optional<libcamera::StreamRole> parseRole(const KeyValueParser::Options &options); };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/image.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas on Board Oy * * Multi-planar image with access to pixel data */ #pragma once #include <memory> #include <stdint.h> #include <vector> #include <libcamera/base/class.h> #include <libcamera/base/flags.h> #include <libcamera/base/span.h> #include <libcamera/framebuffer.h> class Image { public: enum class MapMode { ReadOnly = 1 << 0, WriteOnly = 1 << 1, ReadWrite = ReadOnly | WriteOnly, }; static std::unique_ptr<Image> fromFrameBuffer(const libcamera::FrameBuffer *buffer, MapMode mode); ~Image(); unsigned int numPlanes() const; libcamera::Span<uint8_t> data(unsigned int plane); libcamera::Span<const uint8_t> data(unsigned int plane) const; private: LIBCAMERA_DISABLE_COPY(Image) Image(); std::vector<libcamera::Span<uint8_t>> maps_; std::vector<libcamera::Span<uint8_t>> planes_; }; namespace libcamera { LIBCAMERA_FLAGS_ENABLE_OPERATORS(Image::MapMode) }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/options.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * cam - Options parsing */ #include <assert.h> #include <getopt.h> #include <iomanip> #include <iostream> #include <string.h> #include "options.h" /** * \enum OptionArgument * \brief Indicate if an option takes an argument * * \var OptionArgument::ArgumentNone * \brief The option doesn't accept any argument * * \var OptionArgument::ArgumentRequired * \brief The option requires an argument * * \var OptionArgument::ArgumentOptional * \brief The option accepts an optional argument */ /** * \enum OptionType * \brief The type of argument for an option * * \var OptionType::OptionNone * \brief No argument type, used for options that take no argument * * \var OptionType::OptionInteger * \brief Integer argument type, with an optional base prefix (`0` for base 8, * `0x` for base 16, none for base 10) * * \var OptionType::OptionString * \brief String argument * * \var OptionType::OptionKeyValue * \brief key=value list argument */ /* ----------------------------------------------------------------------------- * Option */ /** * \struct Option * \brief Store metadata about an option * * \var Option::opt * \brief The option identifier * * \var Option::type * \brief The type of the option argument * * \var Option::name * \brief The option name * * \var Option::argument * \brief Whether the option accepts an optional argument, a mandatory * argument, or no argument at all * * \var Option::argumentName * \brief The argument name used in the help text * * \var Option::help * \brief The help text (may be a multi-line string) * * \var Option::keyValueParser * \brief For options of type OptionType::OptionKeyValue, the key-value parser * to parse the argument * * \var Option::isArray * \brief Whether the option can appear once or multiple times * * \var Option::parent * \brief The parent option * * \var Option::children * \brief List of child options, storing all options whose parent is this option * * \fn Option::hasShortOption() * \brief Tell if the option has a short option specifier (e.g. `-f`) * \return True if the option has a short option specifier, false otherwise * * \fn Option::hasLongOption() * \brief Tell if the option has a long option specifier (e.g. `--foo`) * \return True if the option has a long option specifier, false otherwise */ struct Option { int opt; OptionType type; const char *name; OptionArgument argument; const char *argumentName; const char *help; KeyValueParser *keyValueParser; bool isArray; Option *parent; std::list<Option> children; bool hasShortOption() const { return isalnum(opt); } bool hasLongOption() const { return name != nullptr; } const char *typeName() const; std::string optionName() const; }; /** * \brief Retrieve a string describing the option type * \return A string describing the option type */ const char *Option::typeName() const { switch (type) { case OptionNone: return "none"; case OptionInteger: return "integer"; case OptionString: return "string"; case OptionKeyValue: return "key=value"; } return "unknown"; } /** * \brief Retrieve a string describing the option name, with leading dashes * \return A string describing the option name, as a long option identifier * (double dash) if the option has a name, or a short option identifier (single * dash) otherwise */ std::string Option::optionName() const { if (name) return "--" + std::string(name); else return "-" + std::string(1, opt); } /* ----------------------------------------------------------------------------- * OptionBase<T> */ /** * \class template<typename T> OptionBase * \brief Container to store the values of parsed options * \tparam T The type through which options are identified * * The OptionsBase class is generated by a parser (either OptionsParser or * KeyValueParser) when parsing options. It stores values for all the options * found, and exposes accessor functions to retrieve them. The options are * accessed through an identifier to type \a T, which is an int referencing an * Option::opt for OptionsParser, or a std::string referencing an Option::name * for KeyValueParser. */ /** * \fn OptionsBase::OptionsBase() * \brief Construct an OptionsBase instance * * The constructed instance is initially invalid, and will be populated by the * options parser. */ /** * \brief Tell if the stored options list is empty * \return True if the container is empty, false otherwise */ template<typename T> bool OptionsBase<T>::empty() const { return values_.empty(); } /** * \brief Tell if the options parsing completed successfully * \return True if the container is returned after successfully parsing * options, false if it is returned after an error was detected during parsing */ template<typename T> bool OptionsBase<T>::valid() const { return valid_; } /** * \brief Tell if the option \a opt is specified * \param[in] opt The option to search for * \return True if the \a opt option is set, false otherwise */ template<typename T> bool OptionsBase<T>::isSet(const T &opt) const { return values_.find(opt) != values_.end(); } /** * \brief Retrieve the value of option \a opt * \param[in] opt The option to retrieve * \return The value of option \a opt if found, an empty OptionValue otherwise */ template<typename T> const OptionValue &OptionsBase<T>::operator[](const T &opt) const { static const OptionValue empty; auto it = values_.find(opt); if (it != values_.end()) return it->second; return empty; } /** * \brief Mark the container as invalid * * This function can be used in a key-value parser's override of the * KeyValueParser::parse() function to mark the returned options as invalid if * a validation error occurs. */ template<typename T> void OptionsBase<T>::invalidate() { valid_ = false; } template<typename T> bool OptionsBase<T>::parseValue(const T &opt, const Option &option, const char *arg) { OptionValue value; switch (option.type) { case OptionNone: break; case OptionInteger: unsigned int integer; if (arg) { char *endptr; integer = strtoul(arg, &endptr, 0); if (*endptr != '\0') return false; } else { integer = 0; } value = OptionValue(integer); break; case OptionString: value = OptionValue(arg ? arg : ""); break; case OptionKeyValue: KeyValueParser *kvParser = option.keyValueParser; KeyValueParser::Options keyValues = kvParser->parse(arg); if (!keyValues.valid()) return false; value = OptionValue(keyValues); break; } if (option.isArray) values_[opt].addValue(value); else values_[opt] = value; return true; } template class OptionsBase<int>; template class OptionsBase<std::string>; /* ----------------------------------------------------------------------------- * KeyValueParser */ /** * \class KeyValueParser * \brief A specialized parser for list of key-value pairs * * The KeyValueParser is an options parser for comma-separated lists of * `key=value` pairs. The supported keys are added to the parser with * addOption(). A given key can only appear once in the parsed list. * * Instances of this class can be passed to the OptionsParser::addOption() * function to create options that take key-value pairs as an option argument. * Specialized versions of the key-value parser can be created by inheriting * from this class, to pre-build the options list in the constructor, and to add * custom validation by overriding the parse() function. */ /** * \class KeyValueParser::Options * \brief An option list generated by the key-value parser * * This is a specialization of OptionsBase with the option reference type set to * std::string. */ KeyValueParser::KeyValueParser() = default; KeyValueParser::~KeyValueParser() = default; /** * \brief Add a supported option to the parser * \param[in] name The option name, corresponding to the key name in the * key=value pair. The name shall be unique. * \param[in] type The type of the value in the key=value pair * \param[in] help The help text * \param[in] argument Whether the value is optional, mandatory or not allowed. * Shall be ArgumentNone if \a type is OptionNone. * * \sa OptionsParser * * \return True if the option was added successfully, false if an error * occurred. */ bool KeyValueParser::addOption(const char *name, OptionType type, const char *help, OptionArgument argument) { if (!name) return false; if (!help || help[0] == '\0') return false; if (argument != ArgumentNone && type == OptionNone) return false; /* Reject duplicate options. */ if (optionsMap_.find(name) != optionsMap_.end()) return false; optionsMap_[name] = Option({ 0, type, name, argument, nullptr, help, nullptr, false, nullptr, {} }); return true; } /** * \brief Parse a string containing a list of key-value pairs * \param[in] arguments The key-value pairs string to parse * * If a parsing error occurs, the parsing stops and the function returns an * invalid container. The container is populated with the options successfully * parsed so far. * * \return A valid container with the list of parsed options on success, or an * invalid container otherwise */ KeyValueParser::Options KeyValueParser::parse(const char *arguments) { Options options; for (const char *pair = arguments; *arguments != '\0'; pair = arguments) { const char *comma = strchrnul(arguments, ','); size_t len = comma - pair; /* Skip over the comma. */ arguments = *comma == ',' ? comma + 1 : comma; /* Skip to the next pair if the pair is empty. */ if (!len) continue; std::string key; std::string value; const char *separator = static_cast<const char *>(memchr(pair, '=', len)); if (!separator) { key = std::string(pair, len); value = ""; } else { key = std::string(pair, separator - pair); value = std::string(separator + 1, comma - separator - 1); } /* The key is mandatory, the value might be optional. */ if (key.empty()) continue; if (optionsMap_.find(key) == optionsMap_.end()) { std::cerr << "Invalid option " << key << std::endl; return options; } OptionArgument arg = optionsMap_[key].argument; if (value.empty() && arg == ArgumentRequired) { std::cerr << "Option " << key << " requires an argument" << std::endl; return options; } else if (!value.empty() && arg == ArgumentNone) { std::cerr << "Option " << key << " takes no argument" << std::endl; return options; } const Option &option = optionsMap_[key]; if (!options.parseValue(key, option, value.c_str())) { std::cerr << "Failed to parse '" << value << "' as " << option.typeName() << " for option " << key << std::endl; return options; } } options.valid_ = true; return options; } unsigned int KeyValueParser::maxOptionLength() const { unsigned int maxLength = 0; for (auto const &iter : optionsMap_) { const Option &option = iter.second; unsigned int length = 10 + strlen(option.name); if (option.argument != ArgumentNone) length += 1 + strlen(option.typeName()); if (option.argument == ArgumentOptional) length += 2; if (length > maxLength) maxLength = length; } return maxLength; } void KeyValueParser::usage(int indent) { for (auto const &iter : optionsMap_) { const Option &option = iter.second; std::string argument = std::string(" ") + option.name; if (option.argument != ArgumentNone) { if (option.argument == ArgumentOptional) argument += "[="; else argument += "="; argument += option.typeName(); if (option.argument == ArgumentOptional) argument += "]"; } std::cerr << std::setw(indent) << argument; for (const char *help = option.help, *end = help; end;) { end = strchr(help, '\n'); if (end) { std::cerr << std::string(help, end - help + 1); std::cerr << std::setw(indent) << " "; help = end + 1; } else { std::cerr << help << std::endl; } } } } /* ----------------------------------------------------------------------------- * OptionValue */ /** * \class OptionValue * \brief Container to store the value of an option * * The OptionValue class is a variant-type container to store the value of an * option. It supports empty values, integers, strings, key-value lists, as well * as arrays of those types. For array values, all array elements shall have the * same type. * * OptionValue instances are organized in a tree-based structure that matches * the parent-child relationship of the options added to the parser. Children * are retrieved with the children() function, and are stored as an * OptionsBase<int>. */ /** * \enum OptionValue::ValueType * \brief The option value type * * \var OptionValue::ValueType::ValueNone * \brief Empty value * * \var OptionValue::ValueType::ValueInteger * \brief Integer value (int) * * \var OptionValue::ValueType::ValueString * \brief String value (std::string) * * \var OptionValue::ValueType::ValueKeyValue * \brief Key-value list value (KeyValueParser::Options) * * \var OptionValue::ValueType::ValueArray * \brief Array value */ /** * \brief Construct an empty OptionValue instance * * The value type is set to ValueType::ValueNone. */ OptionValue::OptionValue() : type_(ValueNone), integer_(0) { } /** * \brief Construct an integer OptionValue instance * \param[in] value The integer value * * The value type is set to ValueType::ValueInteger. */ OptionValue::OptionValue(int value) : type_(ValueInteger), integer_(value) { } /** * \brief Construct a string OptionValue instance * \param[in] value The string value * * The value type is set to ValueType::ValueString. */ OptionValue::OptionValue(const char *value) : type_(ValueString), integer_(0), string_(value) { } /** * \brief Construct a string OptionValue instance * \param[in] value The string value * * The value type is set to ValueType::ValueString. */ OptionValue::OptionValue(const std::string &value) : type_(ValueString), integer_(0), string_(value) { } /** * \brief Construct a key-value OptionValue instance * \param[in] value The key-value list * * The value type is set to ValueType::ValueKeyValue. */ OptionValue::OptionValue(const KeyValueParser::Options &value) : type_(ValueKeyValue), integer_(0), keyValues_(value) { } /** * \brief Add an entry to an array value * \param[in] value The entry value * * This function can only be called if the OptionValue type is * ValueType::ValueNone or ValueType::ValueArray. Upon return, the type will be * set to ValueType::ValueArray. */ void OptionValue::addValue(const OptionValue &value) { assert(type_ == ValueNone || type_ == ValueArray); type_ = ValueArray; array_.push_back(value); } /** * \fn OptionValue::type() * \brief Retrieve the value type * \return The value type */ /** * \fn OptionValue::empty() * \brief Check if the value is empty * \return True if the value is empty (type set to ValueType::ValueNone), or * false otherwise */ /** * \brief Cast the value to an int * \return The option value as an int, or 0 if the value type isn't * ValueType::ValueInteger */ OptionValue::operator int() const { return toInteger(); } /** * \brief Cast the value to a std::string * \return The option value as an std::string, or an empty string if the value * type isn't ValueType::ValueString */ OptionValue::operator std::string() const { return toString(); } /** * \brief Retrieve the value as an int * \return The option value as an int, or 0 if the value type isn't * ValueType::ValueInteger */ int OptionValue::toInteger() const { if (type_ != ValueInteger) return 0; return integer_; } /** * \brief Retrieve the value as a std::string * \return The option value as a std::string, or an empty string if the value * type isn't ValueType::ValueString */ std::string OptionValue::toString() const { if (type_ != ValueString) return std::string(); return string_; } /** * \brief Retrieve the value as a key-value list * * The behaviour is undefined if the value type isn't ValueType::ValueKeyValue. * * \return The option value as a KeyValueParser::Options */ const KeyValueParser::Options &OptionValue::toKeyValues() const { assert(type_ == ValueKeyValue); return keyValues_; } /** * \brief Retrieve the value as an array * * The behaviour is undefined if the value type isn't ValueType::ValueArray. * * \return The option value as a std::vector of OptionValue */ const std::vector<OptionValue> &OptionValue::toArray() const { assert(type_ == ValueArray); return array_; } /** * \brief Retrieve the list of child values * \return The list of child values */ const OptionsParser::Options &OptionValue::children() const { return children_; } /* ----------------------------------------------------------------------------- * OptionsParser */ /** * \class OptionsParser * \brief A command line options parser * * The OptionsParser class is an easy to use options parser for POSIX-style * command line options. Supports short (e.g. `-f`) and long (e.g. `--foo`) * options, optional and mandatory arguments, automatic parsing arguments for * integer types and comma-separated list of key=value pairs, and multi-value * arguments. It handles help text generation automatically. * * An OptionsParser instance is initialized by adding supported options with * addOption(). Options are specified by an identifier and a name. If the * identifier is an alphanumeric character, it will be used by the parser as a * short option identifier (e.g. `-f`). The name, if specified, will be used as * a long option identifier (e.g. `--foo`). It should not include the double * dashes. The name is optional if the option identifier is an alphanumeric * character and mandatory otherwise. * * An option has a mandatory help text, which is used to print the full options * list with the usage() function. The help text may be a multi-line string. * Correct indentation of the help text is handled automatically. * * Options accept arguments when created with OptionArgument::ArgumentRequired * or OptionArgument::ArgumentOptional. If the argument is required, it can be * specified as a positional argument after the option (e.g. `-f bar`, * `--foo bar`), collated with the short option (e.g. `-fbar`) or separated from * the long option by an equal sign (e.g. `--foo=bar`'). When the argument is * optional, it must be collated with the short option or separated from the * long option by an equal sign. * * If an option has a required or optional argument, an argument name must be * set when adding the option. The argument name is used in the help text as a * place holder for an argument value. For instance, a `--write` option that * takes a file name as an argument could set the argument name to `filename`, * and the help text would display `--write filename`. This is only used to * clarify the help text and has no effect on option parsing. * * The option type tells the parser how to process the argument. Arguments for * string options (OptionType::OptionString) are stored as-is without any * processing. Arguments for integer options (OptionType::OptionInteger) are * converted to an integer value, using an optional base prefix (`0` for base 8, * `0x` for base 16, none for base 10). Arguments for key-value options are * parsed by a KeyValueParser given to addOption(). * * By default, a given option can appear once only in the parsed command line. * If the option is created as an array option, the parser will accept multiple * instances of the option. The order in which identical options are specified * is preserved in the values of an array option. * * After preparing the parser, it can be used any number of times to parse * command line options with the parse() function. The function returns an * Options instance that stores the values for the parsed options. The * Options::isSet() function can be used to test if an option has been found, * and is the only way to access options that take no argument (specified by * OptionType::OptionNone and OptionArgument::ArgumentNone). For options that * accept an argument, the option value can be access by Options::operator[]() * using the option identifier as the key. The order in which different options * are specified on the command line isn't preserved. * * Options can be created with parent-child relationships to organize them as a * tree instead of a flat list. When parsing a command line, the child options * are considered related to the parent option that precedes them. This is * useful when the parent is an array option. The Options values list generated * by the parser then turns into a tree, which each parent value storing the * values of child options that follow that instance of the parent option. * For instance, with a `capture` option specified as a child of a `camera` * array option, parsing the command line * * `--camera 1 --capture=10 --camera 2 --capture=20` * * will return an Options instance containing a single OptionValue instance of * array type, for the `camera` option. The OptionValue will contain two * entries, with the first entry containing the integer value 1 and the second * entry the integer value 2. Each of those entries will in turn store an * Options instance that contains the respective children. The first entry will * store in its children a `capture` option of value 10, and the second entry a * `capture` option of value 20. * * The command line * * `--capture=10 --camera 1` * * would result in a parsing error, as the `capture` option has no preceding * `camera` option on the command line. */ /** * \class OptionsParser::Options * \brief An option list generated by the options parser * * This is a specialization of OptionsBase with the option reference type set to * int. */ OptionsParser::OptionsParser() = default; OptionsParser::~OptionsParser() = default; /** * \brief Add an option to the parser * \param[in] opt The option identifier * \param[in] type The type of the option argument * \param[in] help The help text (may be a multi-line string) * \param[in] name The option name * \param[in] argument Whether the option accepts an optional argument, a * mandatory argument, or no argument at all * \param[in] argumentName The argument name used in the help text * \param[in] array Whether the option can appear once or multiple times * \param[in] parent The identifier of the parent option (optional) * * \return True if the option was added successfully, false if an error * occurred. */ bool OptionsParser::addOption(int opt, OptionType type, const char *help, const char *name, OptionArgument argument, const char *argumentName, bool array, int parent) { /* * Options must have at least a short or long name, and a text message. * If an argument is accepted, it must be described by argumentName. */ if (!isalnum(opt) && !name) return false; if (!help || help[0] == '\0') return false; if (argument != ArgumentNone && !argumentName) return false; /* Reject duplicate options. */ if (optionsMap_.find(opt) != optionsMap_.end()) return false; /* * If a parent is specified, create the option as a child of its parent. * Otherwise, create it in the parser's options list. */ Option *option; if (parent) { auto iter = optionsMap_.find(parent); if (iter == optionsMap_.end()) return false; Option *parentOpt = iter->second; parentOpt->children.push_back({ opt, type, name, argument, argumentName, help, nullptr, array, parentOpt, {} }); option = &parentOpt->children.back(); } else { options_.push_back({ opt, type, name, argument, argumentName, help, nullptr, array, nullptr, {} }); option = &options_.back(); } optionsMap_[opt] = option; return true; } /** * \brief Add a key-value pair option to the parser * \param[in] opt The option identifier * \param[in] parser The KeyValueParser for the option value * \param[in] help The help text (may be a multi-line string) * \param[in] name The option name * \param[in] array Whether the option can appear once or multiple times * * \sa Option * * \return True if the option was added successfully, false if an error * occurred. */ bool OptionsParser::addOption(int opt, KeyValueParser *parser, const char *help, const char *name, bool array, int parent) { if (!addOption(opt, OptionKeyValue, help, name, ArgumentRequired, "key=value[,key=value,...]", array, parent)) return false; optionsMap_[opt]->keyValueParser = parser; return true; } /** * \brief Parse command line arguments * \param[in] argc The number of arguments in the \a argv array * \param[in] argv The array of arguments * * If a parsing error occurs, the parsing stops, the function prints an error * message that identifies the invalid argument, prints usage information with * usage(), and returns an invalid container. The container is populated with * the options successfully parsed so far. * * \return A valid container with the list of parsed options on success, or an * invalid container otherwise */ OptionsParser::Options OptionsParser::parse(int argc, char **argv) { OptionsParser::Options options; /* * Allocate short and long options arrays large enough to contain all * options. */ char shortOptions[optionsMap_.size() * 3 + 2]; struct option longOptions[optionsMap_.size() + 1]; unsigned int ids = 0; unsigned int idl = 0; shortOptions[ids++] = ':'; for (const auto [opt, option] : optionsMap_) { if (option->hasShortOption()) { shortOptions[ids++] = opt; if (option->argument != ArgumentNone) shortOptions[ids++] = ':'; if (option->argument == ArgumentOptional) shortOptions[ids++] = ':'; } if (option->hasLongOption()) { longOptions[idl].name = option->name; switch (option->argument) { case ArgumentNone: longOptions[idl].has_arg = no_argument; break; case ArgumentRequired: longOptions[idl].has_arg = required_argument; break; case ArgumentOptional: longOptions[idl].has_arg = optional_argument; break; } longOptions[idl].flag = 0; longOptions[idl].val = option->opt; idl++; } } shortOptions[ids] = '\0'; memset(&longOptions[idl], 0, sizeof(longOptions[idl])); opterr = 0; while (true) { int c = getopt_long(argc, argv, shortOptions, longOptions, nullptr); if (c == -1) break; if (c == '?' || c == ':') { if (c == '?') std::cerr << "Invalid option "; else std::cerr << "Missing argument for option "; std::cerr << argv[optind - 1] << std::endl; usage(); return options; } const Option &option = *optionsMap_[c]; if (!parseValue(option, optarg, &options)) { usage(); return options; } } if (optind < argc) { std::cerr << "Invalid non-option argument '" << argv[optind] << "'" << std::endl; usage(); return options; } options.valid_ = true; return options; } /** * \brief Print usage text to std::cerr * * The usage text list all the supported option with their arguments. It is * generated automatically from the options added to the parser. Caller of this * function may print additional usage information for the application before * the list of options. */ void OptionsParser::usage() { unsigned int indent = 0; for (const auto &opt : optionsMap_) { const Option *option = opt.second; unsigned int length = 14; if (option->hasLongOption()) length += 2 + strlen(option->name); if (option->argument != ArgumentNone) length += 1 + strlen(option->argumentName); if (option->argument == ArgumentOptional) length += 2; if (option->isArray) length += 4; if (length > indent) indent = length; if (option->keyValueParser) { length = option->keyValueParser->maxOptionLength(); if (length > indent) indent = length; } } indent = (indent + 7) / 8 * 8; std::cerr << "Options:" << std::endl; std::ios_base::fmtflags f(std::cerr.flags()); std::cerr << std::left; usageOptions(options_, indent); std::cerr.flags(f); } void OptionsParser::usageOptions(const std::list<Option> &options, unsigned int indent) { std::vector<const Option *> parentOptions; for (const Option &option : options) { std::string argument; if (option.hasShortOption()) argument = std::string(" -") + static_cast<char>(option.opt); else argument = " "; if (option.hasLongOption()) { if (option.hasShortOption()) argument += ", "; else argument += " "; argument += std::string("--") + option.name; } if (option.argument != ArgumentNone) { if (option.argument == ArgumentOptional) argument += "[="; else argument += " "; argument += option.argumentName; if (option.argument == ArgumentOptional) argument += "]"; } if (option.isArray) argument += " ..."; std::cerr << std::setw(indent) << argument; for (const char *help = option.help, *end = help; end; ) { end = strchr(help, '\n'); if (end) { std::cerr << std::string(help, end - help + 1); std::cerr << std::setw(indent) << " "; help = end + 1; } else { std::cerr << help << std::endl; } } if (option.keyValueParser) option.keyValueParser->usage(indent); if (!option.children.empty()) parentOptions.push_back(&option); } if (parentOptions.empty()) return; for (const Option *option : parentOptions) { std::cerr << std::endl << "Options valid in the context of " << option->optionName() << ":" << std::endl; usageOptions(option->children, indent); } } std::tuple<OptionsParser::Options *, const Option *> OptionsParser::childOption(const Option *parent, Options *options) { /* * The parent argument points to the parent of the leaf node Option, * and the options argument to the root node of the Options tree. Use * recursive calls to traverse the Option tree up to the root node while * traversing the Options tree down to the leaf node: */ /* * - If we have no parent, we've reached the root node of the Option * tree, the options argument is what we need. */ if (!parent) return { options, nullptr }; /* * - If the parent has a parent, use recursion to move one level up the * Option tree. This returns the Options corresponding to parent, or * nullptr if a suitable Options child isn't found. */ if (parent->parent) { const Option *error; std::tie(options, error) = childOption(parent->parent, options); /* Propagate the error all the way back up the call stack. */ if (!error) return { options, error }; } /* * - The parent has no parent, we're now one level down the root. * Return the Options child corresponding to the parent. The child may * not exist if options are specified in an incorrect order. */ if (!options->isSet(parent->opt)) return { nullptr, parent }; /* * If the child value is of array type, children are not stored in the * value .children() list, but in the .children() of the value's array * elements. Use the last array element in that case, as a child option * relates to the last instance of its parent option. */ const OptionValue *value = &(*options)[parent->opt]; if (value->type() == OptionValue::ValueArray) value = &value->toArray().back(); return { const_cast<Options *>(&value->children()), nullptr }; } bool OptionsParser::parseValue(const Option &option, const char *arg, Options *options) { const Option *error; std::tie(options, error) = childOption(option.parent, options); if (error) { std::cerr << "Option " << option.optionName() << " requires a " << error->optionName() << " context" << std::endl; return false; } if (!options->parseValue(option.opt, option, arg)) { std::cerr << "Can't parse " << option.typeName() << " argument for option " << option.optionName() << std::endl; return false; } return true; }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/options.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * cam - Options parsing */ #pragma once #include <ctype.h> #include <list> #include <map> #include <tuple> #include <vector> class KeyValueParser; class OptionValue; struct Option; enum OptionArgument { ArgumentNone, ArgumentRequired, ArgumentOptional, }; enum OptionType { OptionNone, OptionInteger, OptionString, OptionKeyValue, }; template<typename T> class OptionsBase { public: OptionsBase() : valid_(false) {} bool empty() const; bool valid() const; bool isSet(const T &opt) const; const OptionValue &operator[](const T &opt) const; void invalidate(); private: friend class KeyValueParser; friend class OptionsParser; bool parseValue(const T &opt, const Option &option, const char *value); std::map<T, OptionValue> values_; bool valid_; }; class KeyValueParser { public: class Options : public OptionsBase<std::string> { }; KeyValueParser(); virtual ~KeyValueParser(); bool addOption(const char *name, OptionType type, const char *help, OptionArgument argument = ArgumentNone); virtual Options parse(const char *arguments); private: KeyValueParser(const KeyValueParser &) = delete; KeyValueParser &operator=(const KeyValueParser &) = delete; friend class OptionsParser; unsigned int maxOptionLength() const; void usage(int indent); std::map<std::string, Option> optionsMap_; }; class OptionsParser { public: class Options : public OptionsBase<int> { }; OptionsParser(); ~OptionsParser(); bool addOption(int opt, OptionType type, const char *help, const char *name = nullptr, OptionArgument argument = ArgumentNone, const char *argumentName = nullptr, bool array = false, int parent = 0); bool addOption(int opt, KeyValueParser *parser, const char *help, const char *name = nullptr, bool array = false, int parent = 0); Options parse(int argc, char *argv[]); void usage(); private: OptionsParser(const OptionsParser &) = delete; OptionsParser &operator=(const OptionsParser &) = delete; void usageOptions(const std::list<Option> &options, unsigned int indent); std::tuple<OptionsParser::Options *, const Option *> childOption(const Option *parent, Options *options); bool parseValue(const Option &option, const char *arg, Options *options); std::list<Option> options_; std::map<unsigned int, Option *> optionsMap_; }; class OptionValue { public: enum ValueType { ValueNone, ValueInteger, ValueString, ValueKeyValue, ValueArray, }; OptionValue(); OptionValue(int value); OptionValue(const char *value); OptionValue(const std::string &value); OptionValue(const KeyValueParser::Options &value); void addValue(const OptionValue &value); ValueType type() const { return type_; } bool empty() const { return type_ == ValueType::ValueNone; } operator int() const; operator std::string() const; int toInteger() const; std::string toString() const; const KeyValueParser::Options &toKeyValues() const; const std::vector<OptionValue> &toArray() const; const OptionsParser::Options &children() const; private: ValueType type_; int integer_; std::string string_; KeyValueParser::Options keyValues_; std::vector<OptionValue> array_; OptionsParser::Options children_; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/event_loop.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * cam - Event loop */ #include "event_loop.h" #include <assert.h> #include <event2/event.h> #include <event2/thread.h> #include <iostream> EventLoop *EventLoop::instance_ = nullptr; EventLoop::EventLoop() { assert(!instance_); evthread_use_pthreads(); base_ = event_base_new(); instance_ = this; } EventLoop::~EventLoop() { instance_ = nullptr; events_.clear(); event_base_free(base_); libevent_global_shutdown(); } EventLoop *EventLoop::instance() { return instance_; } int EventLoop::exec() { exitCode_ = -1; event_base_loop(base_, EVLOOP_NO_EXIT_ON_EMPTY); return exitCode_; } void EventLoop::exit(int code) { exitCode_ = code; event_base_loopbreak(base_); } void EventLoop::callLater(const std::function<void()> &func) { { std::unique_lock<std::mutex> locker(lock_); calls_.push_back(func); } event_base_once(base_, -1, EV_TIMEOUT, dispatchCallback, this, nullptr); } void EventLoop::addFdEvent(int fd, EventType type, const std::function<void()> &callback) { std::unique_ptr<Event> event = std::make_unique<Event>(callback); short events = (type & Read ? EV_READ : 0) | (type & Write ? EV_WRITE : 0) | EV_PERSIST; event->event_ = event_new(base_, fd, events, &EventLoop::Event::dispatch, event.get()); if (!event->event_) { std::cerr << "Failed to create event for fd " << fd << std::endl; return; } int ret = event_add(event->event_, nullptr); if (ret < 0) { std::cerr << "Failed to add event for fd " << fd << std::endl; return; } events_.push_back(std::move(event)); } void EventLoop::addTimerEvent(const std::chrono::microseconds period, const std::function<void()> &callback) { std::unique_ptr<Event> event = std::make_unique<Event>(callback); event->event_ = event_new(base_, -1, EV_PERSIST, &EventLoop::Event::dispatch, event.get()); if (!event->event_) { std::cerr << "Failed to create timer event" << std::endl; return; } struct timeval tv; tv.tv_sec = period.count() / 1000000ULL; tv.tv_usec = period.count() % 1000000ULL; int ret = event_add(event->event_, &tv); if (ret < 0) { std::cerr << "Failed to add timer event" << std::endl; return; } events_.push_back(std::move(event)); } void EventLoop::dispatchCallback([[maybe_unused]] evutil_socket_t fd, [[maybe_unused]] short flags, void *param) { EventLoop *loop = static_cast<EventLoop *>(param); loop->dispatchCall(); } void EventLoop::dispatchCall() { std::function<void()> call; { std::unique_lock<std::mutex> locker(lock_); if (calls_.empty()) return; call = calls_.front(); calls_.pop_front(); } call(); } EventLoop::Event::Event(const std::function<void()> &callback) : callback_(callback), event_(nullptr) { } EventLoop::Event::~Event() { event_del(event_); event_free(event_); } void EventLoop::Event::dispatch([[maybe_unused]] int fd, [[maybe_unused]] short events, void *arg) { Event *event = static_cast<Event *>(arg); event->callback_(); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/dng_writer.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Raspberry Pi Ltd * * DNG writer */ #pragma once #ifdef HAVE_TIFF #define HAVE_DNG #include <libcamera/camera.h> #include <libcamera/controls.h> #include <libcamera/framebuffer.h> #include <libcamera/stream.h> class DNGWriter { public: static int write(const char *filename, const libcamera::Camera *camera, const libcamera::StreamConfiguration &config, const libcamera::ControlList &metadata, const libcamera::FrameBuffer *buffer, const void *data); }; #endif /* HAVE_TIFF */
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/ppm_writer.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Red Hat, Inc. * * PPM writer */ #pragma once #include <libcamera/base/span.h> #include <libcamera/stream.h> class PPMWriter { public: static int write(const char *filename, const libcamera::StreamConfiguration &config, const libcamera::Span<uint8_t> &data); };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/ppm_writer.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024 Red Hat, Inc. * * PPM writer */ #include "ppm_writer.h" #include <fstream> #include <iostream> #include <libcamera/formats.h> #include <libcamera/pixel_format.h> using namespace libcamera; int PPMWriter::write(const char *filename, const StreamConfiguration &config, const Span<uint8_t> &data) { if (config.pixelFormat != formats::BGR888) { std::cerr << "Only BGR888 output pixel format is supported (" << config.pixelFormat << " requested)" << std::endl; return -EINVAL; } std::ofstream output(filename, std::ios::binary); if (!output) { std::cerr << "Failed to open ppm file: " << filename << std::endl; return -EINVAL; } output << "P6" << std::endl << config.size.width << " " << config.size.height << std::endl << "255" << std::endl; if (!output) { std::cerr << "Failed to write the file header" << std::endl; return -EINVAL; } const unsigned int rowLength = config.size.width * 3; const char *row = reinterpret_cast<const char *>(data.data()); for (unsigned int y = 0; y < config.size.height; y++, row += config.stride) { output.write(row, rowLength); if (!output) { std::cerr << "Failed to write image data at row " << y << std::endl; return -EINVAL; } } return 0; }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/event_loop.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * cam - Event loop */ #pragma once #include <chrono> #include <functional> #include <list> #include <memory> #include <mutex> #include <event2/util.h> struct event_base; class EventLoop { public: enum EventType { Read = 1, Write = 2, }; EventLoop(); ~EventLoop(); static EventLoop *instance(); int exec(); void exit(int code = 0); void callLater(const std::function<void()> &func); void addFdEvent(int fd, EventType type, const std::function<void()> &handler); using duration = std::chrono::steady_clock::duration; void addTimerEvent(const std::chrono::microseconds period, const std::function<void()> &handler); private: struct Event { Event(const std::function<void()> &callback); ~Event(); static void dispatch(int fd, short events, void *arg); std::function<void()> callback_; struct event *event_; }; static EventLoop *instance_; struct event_base *base_; int exitCode_; std::list<std::function<void()>> calls_; std::list<std::unique_ptr<Event>> events_; std::mutex lock_; static void dispatchCallback(evutil_socket_t fd, short flags, void *param); void dispatchCall(); };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/common/dng_writer.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Raspberry Pi Ltd * * DNG writer */ #include "dng_writer.h" #include <algorithm> #include <iostream> #include <map> #include <tiffio.h> #include <libcamera/control_ids.h> #include <libcamera/formats.h> #include <libcamera/property_ids.h> using namespace libcamera; enum CFAPatternColour : uint8_t { CFAPatternRed = 0, CFAPatternGreen = 1, CFAPatternBlue = 2, }; struct FormatInfo { uint8_t bitsPerSample; CFAPatternColour pattern[4]; void (*packScanline)(void *output, const void *input, unsigned int width); void (*thumbScanline)(const FormatInfo &info, void *output, const void *input, unsigned int width, unsigned int stride); }; struct Matrix3d { Matrix3d() { } Matrix3d(float m0, float m1, float m2, float m3, float m4, float m5, float m6, float m7, float m8) { m[0] = m0, m[1] = m1, m[2] = m2; m[3] = m3, m[4] = m4, m[5] = m5; m[6] = m6, m[7] = m7, m[8] = m8; } Matrix3d(const Span<const float> &span) : Matrix3d(span[0], span[1], span[2], span[3], span[4], span[5], span[6], span[7], span[8]) { } static Matrix3d diag(float diag0, float diag1, float diag2) { return Matrix3d(diag0, 0, 0, 0, diag1, 0, 0, 0, diag2); } static Matrix3d identity() { return Matrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1); } Matrix3d transpose() const { return { m[0], m[3], m[6], m[1], m[4], m[7], m[2], m[5], m[8] }; } Matrix3d cofactors() const { return { m[4] * m[8] - m[5] * m[7], -(m[3] * m[8] - m[5] * m[6]), m[3] * m[7] - m[4] * m[6], -(m[1] * m[8] - m[2] * m[7]), m[0] * m[8] - m[2] * m[6], -(m[0] * m[7] - m[1] * m[6]), m[1] * m[5] - m[2] * m[4], -(m[0] * m[5] - m[2] * m[3]), m[0] * m[4] - m[1] * m[3] }; } Matrix3d adjugate() const { return cofactors().transpose(); } float determinant() const { return m[0] * (m[4] * m[8] - m[5] * m[7]) - m[1] * (m[3] * m[8] - m[5] * m[6]) + m[2] * (m[3] * m[7] - m[4] * m[6]); } Matrix3d inverse() const { return adjugate() * (1.0 / determinant()); } Matrix3d operator*(const Matrix3d &other) const { Matrix3d result; for (unsigned int i = 0; i < 3; i++) { for (unsigned int j = 0; j < 3; j++) { result.m[i * 3 + j] = m[i * 3 + 0] * other.m[0 + j] + m[i * 3 + 1] * other.m[3 + j] + m[i * 3 + 2] * other.m[6 + j]; } } return result; } Matrix3d operator*(float f) const { Matrix3d result; for (unsigned int i = 0; i < 9; i++) result.m[i] = m[i] * f; return result; } float m[9]; }; void packScanlineSBGGR8(void *output, const void *input, unsigned int width) { const uint8_t *in = static_cast<const uint8_t *>(input); uint8_t *out = static_cast<uint8_t *>(output); std::copy(in, in + width, out); } void packScanlineSBGGR10P(void *output, const void *input, unsigned int width) { const uint8_t *in = static_cast<const uint8_t *>(input); uint8_t *out = static_cast<uint8_t *>(output); /* \todo Can this be made more efficient? */ for (unsigned int x = 0; x < width; x += 4) { *out++ = in[0]; *out++ = (in[4] & 0x03) << 6 | in[1] >> 2; *out++ = (in[1] & 0x03) << 6 | (in[4] & 0x0c) << 2 | in[2] >> 4; *out++ = (in[2] & 0x0f) << 4 | (in[4] & 0x30) >> 2 | in[3] >> 6; *out++ = (in[3] & 0x3f) << 2 | (in[4] & 0xc0) >> 6; in += 5; } } void packScanlineSBGGR12P(void *output, const void *input, unsigned int width) { const uint8_t *in = static_cast<const uint8_t *>(input); uint8_t *out = static_cast<uint8_t *>(output); /* \todo Can this be made more efficient? */ for (unsigned int i = 0; i < width; i += 2) { *out++ = in[0]; *out++ = (in[2] & 0x0f) << 4 | in[1] >> 4; *out++ = (in[1] & 0x0f) << 4 | in[2] >> 4; in += 3; } } void thumbScanlineSBGGRxxP(const FormatInfo &info, void *output, const void *input, unsigned int width, unsigned int stride) { const uint8_t *in = static_cast<const uint8_t *>(input); uint8_t *out = static_cast<uint8_t *>(output); /* Number of bytes corresponding to 16 pixels. */ unsigned int skip = info.bitsPerSample * 16 / 8; for (unsigned int x = 0; x < width; x++) { uint8_t value = (in[0] + in[1] + in[stride] + in[stride + 1]) >> 2; *out++ = value; *out++ = value; *out++ = value; in += skip; } } void packScanlineIPU3(void *output, const void *input, unsigned int width) { const uint8_t *in = static_cast<const uint8_t *>(input); uint16_t *out = static_cast<uint16_t *>(output); /* * Upscale the 10-bit format to 16-bit as it's not trivial to pack it * as 10-bit without gaps. * * \todo Improve packing to keep the 10-bit sample size. */ unsigned int x = 0; while (true) { for (unsigned int i = 0; i < 6; i++) { *out++ = (in[1] & 0x03) << 14 | (in[0] & 0xff) << 6; if (++x >= width) return; *out++ = (in[2] & 0x0f) << 12 | (in[1] & 0xfc) << 4; if (++x >= width) return; *out++ = (in[3] & 0x3f) << 10 | (in[2] & 0xf0) << 2; if (++x >= width) return; *out++ = (in[4] & 0xff) << 8 | (in[3] & 0xc0) << 0; if (++x >= width) return; in += 5; } *out++ = (in[1] & 0x03) << 14 | (in[0] & 0xff) << 6; if (++x >= width) return; in += 2; } } void thumbScanlineIPU3([[maybe_unused]] const FormatInfo &info, void *output, const void *input, unsigned int width, unsigned int stride) { uint8_t *out = static_cast<uint8_t *>(output); for (unsigned int x = 0; x < width; x++) { unsigned int pixel = x * 16; unsigned int block = pixel / 25; unsigned int pixelInBlock = pixel - block * 25; /* * If the pixel is the last in the block cheat a little and * move one pixel backward to avoid reading between two blocks * and having to deal with the padding bits. */ if (pixelInBlock == 24) pixelInBlock--; const uint8_t *in = static_cast<const uint8_t *>(input) + block * 32 + (pixelInBlock / 4) * 5; uint16_t val1, val2, val3, val4; switch (pixelInBlock % 4) { default: case 0: val1 = (in[1] & 0x03) << 14 | (in[0] & 0xff) << 6; val2 = (in[2] & 0x0f) << 12 | (in[1] & 0xfc) << 4; val3 = (in[stride + 1] & 0x03) << 14 | (in[stride + 0] & 0xff) << 6; val4 = (in[stride + 2] & 0x0f) << 12 | (in[stride + 1] & 0xfc) << 4; break; case 1: val1 = (in[2] & 0x0f) << 12 | (in[1] & 0xfc) << 4; val2 = (in[3] & 0x3f) << 10 | (in[2] & 0xf0) << 2; val3 = (in[stride + 2] & 0x0f) << 12 | (in[stride + 1] & 0xfc) << 4; val4 = (in[stride + 3] & 0x3f) << 10 | (in[stride + 2] & 0xf0) << 2; break; case 2: val1 = (in[3] & 0x3f) << 10 | (in[2] & 0xf0) << 2; val2 = (in[4] & 0xff) << 8 | (in[3] & 0xc0) << 0; val3 = (in[stride + 3] & 0x3f) << 10 | (in[stride + 2] & 0xf0) << 2; val4 = (in[stride + 4] & 0xff) << 8 | (in[stride + 3] & 0xc0) << 0; break; case 3: val1 = (in[4] & 0xff) << 8 | (in[3] & 0xc0) << 0; val2 = (in[6] & 0x03) << 14 | (in[5] & 0xff) << 6; val3 = (in[stride + 4] & 0xff) << 8 | (in[stride + 3] & 0xc0) << 0; val4 = (in[stride + 6] & 0x03) << 14 | (in[stride + 5] & 0xff) << 6; break; } uint8_t value = (val1 + val2 + val3 + val4) >> 10; *out++ = value; *out++ = value; *out++ = value; } } static const std::map<PixelFormat, FormatInfo> formatInfo = { { formats::SBGGR8, { .bitsPerSample = 8, .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed }, .packScanline = packScanlineSBGGR8, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SGBRG8, { .bitsPerSample = 8, .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen }, .packScanline = packScanlineSBGGR8, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SGRBG8, { .bitsPerSample = 8, .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen }, .packScanline = packScanlineSBGGR8, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SRGGB8, { .bitsPerSample = 8, .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue }, .packScanline = packScanlineSBGGR8, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SBGGR10_CSI2P, { .bitsPerSample = 10, .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed }, .packScanline = packScanlineSBGGR10P, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SGBRG10_CSI2P, { .bitsPerSample = 10, .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen }, .packScanline = packScanlineSBGGR10P, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SGRBG10_CSI2P, { .bitsPerSample = 10, .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen }, .packScanline = packScanlineSBGGR10P, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SRGGB10_CSI2P, { .bitsPerSample = 10, .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue }, .packScanline = packScanlineSBGGR10P, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SBGGR12_CSI2P, { .bitsPerSample = 12, .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed }, .packScanline = packScanlineSBGGR12P, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SGBRG12_CSI2P, { .bitsPerSample = 12, .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen }, .packScanline = packScanlineSBGGR12P, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SGRBG12_CSI2P, { .bitsPerSample = 12, .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen }, .packScanline = packScanlineSBGGR12P, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SRGGB12_CSI2P, { .bitsPerSample = 12, .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue }, .packScanline = packScanlineSBGGR12P, .thumbScanline = thumbScanlineSBGGRxxP, } }, { formats::SBGGR10_IPU3, { .bitsPerSample = 16, .pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed }, .packScanline = packScanlineIPU3, .thumbScanline = thumbScanlineIPU3, } }, { formats::SGBRG10_IPU3, { .bitsPerSample = 16, .pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen }, .packScanline = packScanlineIPU3, .thumbScanline = thumbScanlineIPU3, } }, { formats::SGRBG10_IPU3, { .bitsPerSample = 16, .pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen }, .packScanline = packScanlineIPU3, .thumbScanline = thumbScanlineIPU3, } }, { formats::SRGGB10_IPU3, { .bitsPerSample = 16, .pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue }, .packScanline = packScanlineIPU3, .thumbScanline = thumbScanlineIPU3, } }, }; int DNGWriter::write(const char *filename, const Camera *camera, const StreamConfiguration &config, const ControlList &metadata, [[maybe_unused]] const FrameBuffer *buffer, const void *data) { const ControlList &cameraProperties = camera->properties(); const auto it = formatInfo.find(config.pixelFormat); if (it == formatInfo.cend()) { std::cerr << "Unsupported pixel format" << std::endl; return -EINVAL; } const FormatInfo *info = &it->second; TIFF *tif = TIFFOpen(filename, "w"); if (!tif) { std::cerr << "Failed to open tiff file" << std::endl; return -EINVAL; } /* * Scanline buffer, has to be large enough to store both a RAW scanline * or a thumbnail scanline. The latter will always be much smaller than * the former as we downscale by 16 in both directions. */ uint8_t scanline[(config.size.width * info->bitsPerSample + 7) / 8]; toff_t rawIFDOffset = 0; toff_t exifIFDOffset = 0; /* * Start with a thumbnail in IFD 0 for compatibility with TIFF baseline * readers, as required by the TIFF/EP specification. Tags that apply to * the whole file are stored here. */ const uint8_t version[] = { 1, 2, 0, 0 }; TIFFSetField(tif, TIFFTAG_DNGVERSION, version); TIFFSetField(tif, TIFFTAG_DNGBACKWARDVERSION, version); TIFFSetField(tif, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB); TIFFSetField(tif, TIFFTAG_MAKE, "libcamera"); const auto &model = cameraProperties.get(properties::Model); if (model) { TIFFSetField(tif, TIFFTAG_MODEL, model->c_str()); /* \todo set TIFFTAG_UNIQUECAMERAMODEL. */ } TIFFSetField(tif, TIFFTAG_SOFTWARE, "qcam"); TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); /* * Thumbnail-specific tags. The thumbnail is stored as an RGB image * with 1/16 of the raw image resolution. Greyscale would save space, * but doesn't seem well supported by RawTherapee. */ TIFFSetField(tif, TIFFTAG_SUBFILETYPE, FILETYPE_REDUCEDIMAGE); TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, config.size.width / 16); TIFFSetField(tif, TIFFTAG_IMAGELENGTH, config.size.height / 16); TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3); TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); /* * Fill in some reasonable colour information in the DNG. We supply * the "neutral" colour values which determine the white balance, and the * "ColorMatrix1" which converts XYZ to (un-white-balanced) camera RGB. * Note that this is not a "proper" colour calibration for the DNG, * nonetheless, many tools should be able to render the colours better. */ float neutral[3] = { 1, 1, 1 }; Matrix3d wbGain = Matrix3d::identity(); /* From http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */ const Matrix3d rgb2xyz(0.4124564, 0.3575761, 0.1804375, 0.2126729, 0.7151522, 0.0721750, 0.0193339, 0.1191920, 0.9503041); Matrix3d ccm = Matrix3d::identity(); /* * Pick a reasonable number eps to protect against singularities. It * should be comfortably larger than the point at which we run into * numerical trouble, yet smaller than any plausible gain that we might * apply to a colour, either explicitly or as part of the colour matrix. */ const double eps = 1e-2; const auto &colourGains = metadata.get(controls::ColourGains); if (colourGains) { if ((*colourGains)[0] > eps && (*colourGains)[1] > eps) { wbGain = Matrix3d::diag((*colourGains)[0], 1, (*colourGains)[1]); neutral[0] = 1.0 / (*colourGains)[0]; /* red */ neutral[2] = 1.0 / (*colourGains)[1]; /* blue */ } } const auto &ccmControl = metadata.get(controls::ColourCorrectionMatrix); if (ccmControl) { Matrix3d ccmSupplied(*ccmControl); if (ccmSupplied.determinant() > eps) ccm = ccmSupplied; } /* * rgb2xyz is known to be invertible, and we've ensured above that both * the ccm and wbGain matrices are non-singular, so the product of all * three is guaranteed to be invertible too. */ Matrix3d colorMatrix1 = (rgb2xyz * ccm * wbGain).inverse(); TIFFSetField(tif, TIFFTAG_COLORMATRIX1, 9, colorMatrix1.m); TIFFSetField(tif, TIFFTAG_ASSHOTNEUTRAL, 3, neutral); /* * Reserve space for the SubIFD and ExifIFD tags, pointing to the IFD * for the raw image and EXIF data respectively. The real offsets will * be set later. */ TIFFSetField(tif, TIFFTAG_SUBIFD, 1, &rawIFDOffset); TIFFSetField(tif, TIFFTAG_EXIFIFD, exifIFDOffset); /* Write the thumbnail. */ const uint8_t *row = static_cast<const uint8_t *>(data); for (unsigned int y = 0; y < config.size.height / 16; y++) { info->thumbScanline(*info, &scanline, row, config.size.width / 16, config.stride); if (TIFFWriteScanline(tif, &scanline, y, 0) != 1) { std::cerr << "Failed to write thumbnail scanline" << std::endl; TIFFClose(tif); return -EINVAL; } row += config.stride * 16; } TIFFWriteDirectory(tif); /* Create a new IFD for the RAW image. */ const uint16_t cfaRepeatPatternDim[] = { 2, 2 }; const uint8_t cfaPlaneColor[] = { CFAPatternRed, CFAPatternGreen, CFAPatternBlue }; TIFFSetField(tif, TIFFTAG_SUBFILETYPE, 0); TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, config.size.width); TIFFSetField(tif, TIFFTAG_IMAGELENGTH, config.size.height); TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, info->bitsPerSample); TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA); TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1); TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); TIFFSetField(tif, TIFFTAG_CFAREPEATPATTERNDIM, cfaRepeatPatternDim); if (TIFFLIB_VERSION < 20201219) TIFFSetField(tif, TIFFTAG_CFAPATTERN, info->pattern); else TIFFSetField(tif, TIFFTAG_CFAPATTERN, 4, info->pattern); TIFFSetField(tif, TIFFTAG_CFAPLANECOLOR, 3, cfaPlaneColor); TIFFSetField(tif, TIFFTAG_CFALAYOUT, 1); const uint16_t blackLevelRepeatDim[] = { 2, 2 }; float blackLevel[] = { 0.0f, 0.0f, 0.0f, 0.0f }; uint32_t whiteLevel = (1 << info->bitsPerSample) - 1; const auto &blackLevels = metadata.get(controls::SensorBlackLevels); if (blackLevels) { Span<const int32_t, 4> levels = *blackLevels; /* * The black levels control is specified in R, Gr, Gb, B order. * Map it to the TIFF tag that is specified in CFA pattern * order. */ unsigned int green = (info->pattern[0] == CFAPatternRed || info->pattern[1] == CFAPatternRed) ? 0 : 1; for (unsigned int i = 0; i < 4; ++i) { unsigned int level; switch (info->pattern[i]) { case CFAPatternRed: level = levels[0]; break; case CFAPatternGreen: level = levels[green + 1]; green = (green + 1) % 2; break; case CFAPatternBlue: default: level = levels[3]; break; } /* Map the 16-bit value to the bits per sample range. */ blackLevel[i] = level >> (16 - info->bitsPerSample); } } TIFFSetField(tif, TIFFTAG_BLACKLEVELREPEATDIM, &blackLevelRepeatDim); TIFFSetField(tif, TIFFTAG_BLACKLEVEL, 4, &blackLevel); TIFFSetField(tif, TIFFTAG_WHITELEVEL, 1, &whiteLevel); /* Write RAW content. */ row = static_cast<const uint8_t *>(data); for (unsigned int y = 0; y < config.size.height; y++) { info->packScanline(&scanline, row, config.size.width); if (TIFFWriteScanline(tif, &scanline, y, 0) != 1) { std::cerr << "Failed to write RAW scanline" << std::endl; TIFFClose(tif); return -EINVAL; } row += config.stride; } /* Checkpoint the IFD to retrieve its offset, and write it out. */ TIFFCheckpointDirectory(tif); rawIFDOffset = TIFFCurrentDirOffset(tif); TIFFWriteDirectory(tif); /* Create a new IFD for the EXIF data and fill it. */ TIFFCreateEXIFDirectory(tif); /* Store creation time. */ time_t rawtime; struct tm *timeinfo; char strTime[20]; time(&rawtime); timeinfo = localtime(&rawtime); strftime(strTime, 20, "%Y:%m:%d %H:%M:%S", timeinfo); /* * \todo Handle timezone information by setting OffsetTimeOriginal and * OffsetTimeDigitized once libtiff catches up to the specification and * has EXIFTAG_ defines to handle them. */ TIFFSetField(tif, EXIFTAG_DATETIMEORIGINAL, strTime); TIFFSetField(tif, EXIFTAG_DATETIMEDIGITIZED, strTime); const auto &analogGain = metadata.get(controls::AnalogueGain); if (analogGain) { uint16_t iso = std::min(std::max(*analogGain * 100, 0.0f), 65535.0f); TIFFSetField(tif, EXIFTAG_ISOSPEEDRATINGS, 1, &iso); } const auto &exposureTime = metadata.get(controls::ExposureTime); if (exposureTime) TIFFSetField(tif, EXIFTAG_EXPOSURETIME, *exposureTime / 1e6); TIFFWriteCustomDirectory(tif, &exifIFDOffset); /* Update the IFD offsets and close the file. */ TIFFSetDirectory(tif, 0); TIFFSetField(tif, TIFFTAG_SUBIFD, 1, &rawIFDOffset); TIFFSetField(tif, TIFFTAG_EXIFIFD, exifIFDOffset); TIFFWriteDirectory(tif); TIFFClose(tif); return 0; }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/capture_script.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * Capture session configuration script */ #include "capture_script.h" #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace libcamera; CaptureScript::CaptureScript(std::shared_ptr<Camera> camera, const std::string &fileName) : camera_(camera), loop_(0), valid_(false) { FILE *fh = fopen(fileName.c_str(), "r"); if (!fh) { int ret = -errno; std::cerr << "Failed to open capture script " << fileName << ": " << strerror(-ret) << std::endl; return; } /* * Map the camera's controls to their name so that they can be * easily identified when parsing the script file. */ for (const auto &[control, info] : camera_->controls()) controls_[control->name()] = control; int ret = parseScript(fh); fclose(fh); if (ret) return; valid_ = true; } /* Retrieve the control list associated with a frame number. */ const ControlList &CaptureScript::frameControls(unsigned int frame) { static ControlList controls{}; unsigned int idx = frame; /* If we loop, repeat the controls every 'loop_' frames. */ if (loop_) idx = frame % loop_; auto it = frameControls_.find(idx); if (it == frameControls_.end()) return controls; return it->second; } CaptureScript::EventPtr CaptureScript::nextEvent(yaml_event_type_t expectedType) { EventPtr event(new yaml_event_t); if (!yaml_parser_parse(&parser_, event.get())) return nullptr; if (expectedType != YAML_NO_EVENT && !checkEvent(event, expectedType)) return nullptr; return event; } bool CaptureScript::checkEvent(const EventPtr &event, yaml_event_type_t expectedType) const { if (event->type != expectedType) { std::cerr << "Capture script error on line " << event->start_mark.line << " column " << event->start_mark.column << ": " << "Expected " << eventTypeName(expectedType) << " event, got " << eventTypeName(event->type) << std::endl; return false; } return true; } std::string CaptureScript::eventScalarValue(const EventPtr &event) { return std::string(reinterpret_cast<char *>(event->data.scalar.value), event->data.scalar.length); } std::string CaptureScript::eventTypeName(yaml_event_type_t type) { static const std::map<yaml_event_type_t, std::string> typeNames = { { YAML_STREAM_START_EVENT, "stream-start" }, { YAML_STREAM_END_EVENT, "stream-end" }, { YAML_DOCUMENT_START_EVENT, "document-start" }, { YAML_DOCUMENT_END_EVENT, "document-end" }, { YAML_ALIAS_EVENT, "alias" }, { YAML_SCALAR_EVENT, "scalar" }, { YAML_SEQUENCE_START_EVENT, "sequence-start" }, { YAML_SEQUENCE_END_EVENT, "sequence-end" }, { YAML_MAPPING_START_EVENT, "mapping-start" }, { YAML_MAPPING_END_EVENT, "mapping-end" }, }; auto it = typeNames.find(type); if (it == typeNames.end()) return "[type " + std::to_string(type) + "]"; return it->second; } int CaptureScript::parseScript(FILE *script) { int ret = yaml_parser_initialize(&parser_); if (!ret) { std::cerr << "Failed to initialize yaml parser" << std::endl; return ret; } /* Delete the parser upon function exit. */ struct ParserDeleter { ParserDeleter(yaml_parser_t *parser) : parser_(parser) { } ~ParserDeleter() { yaml_parser_delete(parser_); } yaml_parser_t *parser_; } deleter(&parser_); yaml_parser_set_input_file(&parser_, script); EventPtr event = nextEvent(YAML_STREAM_START_EVENT); if (!event) return -EINVAL; event = nextEvent(YAML_DOCUMENT_START_EVENT); if (!event) return -EINVAL; event = nextEvent(YAML_MAPPING_START_EVENT); if (!event) return -EINVAL; while (1) { event = nextEvent(); if (!event) return -EINVAL; if (event->type == YAML_MAPPING_END_EVENT) return 0; if (!checkEvent(event, YAML_SCALAR_EVENT)) return -EINVAL; std::string section = eventScalarValue(event); if (section == "properties") { ret = parseProperties(); if (ret) return ret; } else if (section == "frames") { ret = parseFrames(); if (ret) return ret; } else { std::cerr << "Unsupported section '" << section << "'" << std::endl; return -EINVAL; } } } int CaptureScript::parseProperty() { EventPtr event = nextEvent(YAML_MAPPING_START_EVENT); if (!event) return -EINVAL; std::string prop = parseScalar(); if (prop.empty()) return -EINVAL; if (prop == "loop") { event = nextEvent(); if (!event) return -EINVAL; std::string value = eventScalarValue(event); if (value.empty()) return -EINVAL; loop_ = atoi(value.c_str()); if (!loop_) { std::cerr << "Invalid loop limit '" << loop_ << "'" << std::endl; return -EINVAL; } } else { std::cerr << "Unsupported property '" << prop << "'" << std::endl; return -EINVAL; } event = nextEvent(YAML_MAPPING_END_EVENT); if (!event) return -EINVAL; return 0; } int CaptureScript::parseProperties() { EventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT); if (!event) return -EINVAL; while (1) { if (event->type == YAML_SEQUENCE_END_EVENT) return 0; int ret = parseProperty(); if (ret) return ret; event = nextEvent(); if (!event) return -EINVAL; } return 0; } int CaptureScript::parseFrames() { EventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT); if (!event) return -EINVAL; while (1) { event = nextEvent(); if (!event) return -EINVAL; if (event->type == YAML_SEQUENCE_END_EVENT) return 0; int ret = parseFrame(std::move(event)); if (ret) return ret; } } int CaptureScript::parseFrame(EventPtr event) { if (!checkEvent(event, YAML_MAPPING_START_EVENT)) return -EINVAL; std::string key = parseScalar(); if (key.empty()) return -EINVAL; unsigned int frameId = atoi(key.c_str()); if (loop_ && frameId >= loop_) { std::cerr << "Frame id (" << frameId << ") shall be smaller than" << "loop limit (" << loop_ << ")" << std::endl; return -EINVAL; } event = nextEvent(YAML_MAPPING_START_EVENT); if (!event) return -EINVAL; ControlList controls{}; while (1) { event = nextEvent(); if (!event) return -EINVAL; if (event->type == YAML_MAPPING_END_EVENT) break; int ret = parseControl(std::move(event), controls); if (ret) return ret; } frameControls_[frameId] = std::move(controls); event = nextEvent(YAML_MAPPING_END_EVENT); if (!event) return -EINVAL; return 0; } int CaptureScript::parseControl(EventPtr event, ControlList &controls) { /* We expect a value after a key. */ std::string name = eventScalarValue(event); if (name.empty()) return -EINVAL; /* If the camera does not support the control just ignore it. */ auto it = controls_.find(name); if (it == controls_.end()) { std::cerr << "Unsupported control '" << name << "'" << std::endl; return -EINVAL; } const ControlId *controlId = it->second; ControlValue val = unpackControl(controlId); if (val.isNone()) { std::cerr << "Error unpacking control '" << name << "'" << std::endl; return -EINVAL; } controls.set(controlId->id(), val); return 0; } std::string CaptureScript::parseScalar() { EventPtr event = nextEvent(YAML_SCALAR_EVENT); if (!event) return ""; return eventScalarValue(event); } ControlValue CaptureScript::parseRectangles() { std::vector<libcamera::Rectangle> rectangles; std::vector<std::vector<std::string>> arrays = parseArrays(); if (arrays.empty()) return {}; for (const std::vector<std::string> &values : arrays) { if (values.size() != 4) { std::cerr << "Error parsing Rectangle: expected " << "array with 4 parameters" << std::endl; return {}; } Rectangle rect = unpackRectangle(values); rectangles.push_back(rect); } ControlValue controlValue; if (rectangles.size() == 1) controlValue.set(rectangles.at(0)); else controlValue.set(Span<const Rectangle>(rectangles)); return controlValue; } std::vector<std::vector<std::string>> CaptureScript::parseArrays() { EventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT); if (!event) return {}; event = nextEvent(); if (!event) return {}; std::vector<std::vector<std::string>> valueArrays; /* Parse single array. */ if (event->type == YAML_SCALAR_EVENT) { std::string firstValue = eventScalarValue(event); if (firstValue.empty()) return {}; std::vector<std::string> remaining = parseSingleArray(); std::vector<std::string> values = { firstValue }; values.insert(std::end(values), std::begin(remaining), std::end(remaining)); valueArrays.push_back(values); return valueArrays; } /* Parse array of arrays. */ while (1) { switch (event->type) { case YAML_SEQUENCE_START_EVENT: { std::vector<std::string> values = parseSingleArray(); valueArrays.push_back(values); break; } case YAML_SEQUENCE_END_EVENT: return valueArrays; default: return {}; } event = nextEvent(); if (!event) return {}; } } std::vector<std::string> CaptureScript::parseSingleArray() { std::vector<std::string> values; while (1) { EventPtr event = nextEvent(); if (!event) return {}; switch (event->type) { case YAML_SCALAR_EVENT: { std::string value = eventScalarValue(event); if (value.empty()) return {}; values.push_back(value); break; } case YAML_SEQUENCE_END_EVENT: return values; default: return {}; } } } void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr) { static const std::map<unsigned int, const char *> typeNames = { { ControlTypeNone, "none" }, { ControlTypeBool, "bool" }, { ControlTypeByte, "byte" }, { ControlTypeInteger32, "int32" }, { ControlTypeInteger64, "int64" }, { ControlTypeFloat, "float" }, { ControlTypeString, "string" }, { ControlTypeRectangle, "Rectangle" }, { ControlTypeSize, "Size" }, }; const char *typeName; auto it = typeNames.find(id->type()); if (it != typeNames.end()) typeName = it->second; else typeName = "unknown"; std::cerr << "Unsupported control '" << repr << "' for " << typeName << " control " << id->name() << std::endl; } ControlValue CaptureScript::parseScalarControl(const ControlId *id, const std::string repr) { ControlValue value{}; switch (id->type()) { case ControlTypeNone: break; case ControlTypeBool: { bool val; if (repr == "true") { val = true; } else if (repr == "false") { val = false; } else { unpackFailure(id, repr); return value; } value.set<bool>(val); break; } case ControlTypeByte: { uint8_t val = strtol(repr.c_str(), NULL, 10); value.set<uint8_t>(val); break; } case ControlTypeInteger32: { int32_t val = strtol(repr.c_str(), NULL, 10); value.set<int32_t>(val); break; } case ControlTypeInteger64: { int64_t val = strtoll(repr.c_str(), NULL, 10); value.set<int64_t>(val); break; } case ControlTypeFloat: { float val = strtof(repr.c_str(), NULL); value.set<float>(val); break; } case ControlTypeString: { value.set<std::string>(repr); break; } default: std::cerr << "Unsupported control type" << std::endl; break; } return value; } ControlValue CaptureScript::parseArrayControl(const ControlId *id, const std::vector<std::string> &repr) { ControlValue value{}; switch (id->type()) { case ControlTypeNone: break; case ControlTypeBool: { /* * This is unpleasant, but we cannot use an std::vector<> as its * boolean type overload does not allow to access the raw data, * as boolean values are stored in a bitmask for efficiency. * * As we need a contiguous memory region to wrap in a Span<>, * use an array instead but be strict about not overflowing it * by limiting the number of controls we can store. * * Be loud but do not fail, as the issue would present at * runtime and it's not fatal. */ static constexpr unsigned int kMaxNumBooleanControls = 1024; std::array<bool, kMaxNumBooleanControls> values; unsigned int idx = 0; for (const std::string &s : repr) { bool val; if (s == "true") { val = true; } else if (s == "false") { val = false; } else { unpackFailure(id, s); return value; } if (idx == kMaxNumBooleanControls) { std::cerr << "Cannot parse more than " << kMaxNumBooleanControls << " boolean controls" << std::endl; break; } values[idx++] = val; } value = Span<bool>(values.data(), idx); break; } case ControlTypeByte: { std::vector<uint8_t> values; for (const std::string &s : repr) { uint8_t val = strtoll(s.c_str(), NULL, 10); values.push_back(val); } value = Span<const uint8_t>(values.data(), values.size()); break; } case ControlTypeInteger32: { std::vector<int32_t> values; for (const std::string &s : repr) { int32_t val = strtoll(s.c_str(), NULL, 10); values.push_back(val); } value = Span<const int32_t>(values.data(), values.size()); break; } case ControlTypeInteger64: { std::vector<int64_t> values; for (const std::string &s : repr) { int64_t val = strtoll(s.c_str(), NULL, 10); values.push_back(val); } value = Span<const int64_t>(values.data(), values.size()); break; } case ControlTypeFloat: { std::vector<float> values; for (const std::string &s : repr) values.push_back(strtof(s.c_str(), NULL)); value = Span<const float>(values.data(), values.size()); break; } case ControlTypeString: { value = Span<const std::string>(repr.data(), repr.size()); break; } default: std::cerr << "Unsupported control type" << std::endl; break; } return value; } ControlValue CaptureScript::unpackControl(const ControlId *id) { /* Parse complex types. */ switch (id->type()) { case ControlTypeRectangle: return parseRectangles(); case ControlTypeSize: /* \todo Parse Sizes. */ return {}; default: break; } /* Check if the control has a single scalar value or is an array. */ EventPtr event = nextEvent(); if (!event) return {}; switch (event->type) { case YAML_SCALAR_EVENT: { const std::string repr = eventScalarValue(event); if (repr.empty()) return {}; return parseScalarControl(id, repr); } case YAML_SEQUENCE_START_EVENT: { std::vector<std::string> array = parseSingleArray(); if (array.empty()) return {}; return parseArrayControl(id, array); } default: std::cerr << "Unexpected event type: " << event->type << std::endl; return {}; } } libcamera::Rectangle CaptureScript::unpackRectangle(const std::vector<std::string> &strVec) { int x = strtol(strVec[0].c_str(), NULL, 10); int y = strtol(strVec[1].c_str(), NULL, 10); unsigned int width = strtoul(strVec[2].c_str(), NULL, 10); unsigned int height = strtoul(strVec[3].c_str(), NULL, 10); return Rectangle(x, y, width, height); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/camera_session.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * Camera capture session */ #include <iomanip> #include <iostream> #include <limits.h> #include <sstream> #include <libcamera/control_ids.h> #include <libcamera/property_ids.h> #include "../common/event_loop.h" #include "../common/stream_options.h" #include "camera_session.h" #include "capture_script.h" #include "file_sink.h" #ifdef HAVE_KMS #include "kms_sink.h" #endif #include "main.h" #ifdef HAVE_SDL #include "sdl_sink.h" #endif using namespace libcamera; CameraSession::CameraSession(CameraManager *cm, const std::string &cameraId, unsigned int cameraIndex, const OptionsParser::Options &options) : options_(options), cameraIndex_(cameraIndex), last_(0), queueCount_(0), captureCount_(0), captureLimit_(0), printMetadata_(false) { char *endptr; unsigned long index = strtoul(cameraId.c_str(), &endptr, 10); if (*endptr == '\0' && index > 0) { auto cameras = cm->cameras(); if (index <= cameras.size()) camera_ = cameras[index - 1]; } if (!camera_) camera_ = cm->get(cameraId); if (!camera_) { std::cerr << "Camera " << cameraId << " not found" << std::endl; return; } if (camera_->acquire()) { std::cerr << "Failed to acquire camera " << cameraId << std::endl; return; } std::vector<StreamRole> roles = StreamKeyValueParser::roles(options_[OptStream]); std::unique_ptr<CameraConfiguration> config = camera_->generateConfiguration(roles); if (!config || config->size() != roles.size()) { std::cerr << "Failed to get default stream configuration" << std::endl; return; } if (options_.isSet(OptOrientation)) { std::string orientOpt = options_[OptOrientation].toString(); static const std::map<std::string, libcamera::Orientation> orientations{ { "rot0", libcamera::Orientation::Rotate0 }, { "rot180", libcamera::Orientation::Rotate180 }, { "mirror", libcamera::Orientation::Rotate0Mirror }, { "flip", libcamera::Orientation::Rotate180Mirror }, }; auto orientation = orientations.find(orientOpt); if (orientation == orientations.end()) { std::cerr << "Invalid orientation " << orientOpt << std::endl; return; } config->orientation = orientation->second; } /* Apply configuration if explicitly requested. */ if (StreamKeyValueParser::updateConfiguration(config.get(), options_[OptStream])) { std::cerr << "Failed to update configuration" << std::endl; return; } bool strictFormats = options_.isSet(OptStrictFormats); #ifdef HAVE_KMS if (options_.isSet(OptDisplay)) { if (options_.isSet(OptFile)) { std::cerr << "--display and --file options are mutually exclusive" << std::endl; return; } if (roles.size() != 1) { std::cerr << "Display doesn't support multiple streams" << std::endl; return; } if (roles[0] != StreamRole::Viewfinder) { std::cerr << "Display requires a viewfinder stream" << std::endl; return; } } #endif if (options_.isSet(OptCaptureScript)) { std::string scriptName = options_[OptCaptureScript].toString(); script_ = std::make_unique<CaptureScript>(camera_, scriptName); if (!script_->valid()) { std::cerr << "Invalid capture script '" << scriptName << "'" << std::endl; return; } } switch (config->validate()) { case CameraConfiguration::Valid: break; case CameraConfiguration::Adjusted: if (strictFormats) { std::cout << "Adjusting camera configuration disallowed by --strict-formats argument" << std::endl; return; } std::cout << "Camera configuration adjusted" << std::endl; break; case CameraConfiguration::Invalid: std::cout << "Camera configuration invalid" << std::endl; return; } config_ = std::move(config); } CameraSession::~CameraSession() { if (camera_) camera_->release(); } void CameraSession::listControls() const { for (const auto &[id, info] : camera_->controls()) { std::cout << "Control: " << id->name() << ": " << info.toString() << std::endl; } } void CameraSession::listProperties() const { for (const auto &[key, value] : camera_->properties()) { const ControlId *id = properties::properties.at(key); std::cout << "Property: " << id->name() << " = " << value.toString() << std::endl; } } void CameraSession::infoConfiguration() const { unsigned int index = 0; for (const StreamConfiguration &cfg : *config_) { std::cout << index << ": " << cfg.toString() << std::endl; const StreamFormats &formats = cfg.formats(); for (PixelFormat pixelformat : formats.pixelformats()) { std::cout << " * Pixelformat: " << pixelformat << " " << formats.range(pixelformat).toString() << std::endl; for (const Size &size : formats.sizes(pixelformat)) std::cout << " - " << size << std::endl; } index++; } } int CameraSession::start() { int ret; queueCount_ = 0; captureCount_ = 0; captureLimit_ = options_[OptCapture].toInteger(); printMetadata_ = options_.isSet(OptMetadata); ret = camera_->configure(config_.get()); if (ret < 0) { std::cout << "Failed to configure camera" << std::endl; return ret; } streamNames_.clear(); for (unsigned int index = 0; index < config_->size(); ++index) { StreamConfiguration &cfg = config_->at(index); streamNames_[cfg.stream()] = "cam" + std::to_string(cameraIndex_) + "-stream" + std::to_string(index); } camera_->requestCompleted.connect(this, &CameraSession::requestComplete); #ifdef HAVE_KMS if (options_.isSet(OptDisplay)) sink_ = std::make_unique<KMSSink>(options_[OptDisplay].toString()); #endif #ifdef HAVE_SDL if (options_.isSet(OptSDL)) sink_ = std::make_unique<SDLSink>(); #endif if (options_.isSet(OptFile)) { if (!options_[OptFile].toString().empty()) sink_ = std::make_unique<FileSink>(camera_.get(), streamNames_, options_[OptFile]); else sink_ = std::make_unique<FileSink>(camera_.get(), streamNames_); } if (sink_) { ret = sink_->configure(*config_); if (ret < 0) { std::cout << "Failed to configure frame sink" << std::endl; return ret; } sink_->requestProcessed.connect(this, &CameraSession::sinkRelease); } allocator_ = std::make_unique<FrameBufferAllocator>(camera_); return startCapture(); } void CameraSession::stop() { int ret = camera_->stop(); if (ret) std::cout << "Failed to stop capture" << std::endl; if (sink_) { ret = sink_->stop(); if (ret) std::cout << "Failed to stop frame sink" << std::endl; } sink_.reset(); requests_.clear(); allocator_.reset(); } int CameraSession::startCapture() { int ret; /* Identify the stream with the least number of buffers. */ unsigned int nbuffers = UINT_MAX; for (StreamConfiguration &cfg : *config_) { ret = allocator_->allocate(cfg.stream()); if (ret < 0) { std::cerr << "Can't allocate buffers" << std::endl; return -ENOMEM; } unsigned int allocated = allocator_->buffers(cfg.stream()).size(); nbuffers = std::min(nbuffers, allocated); } /* * TODO: make cam tool smarter to support still capture by for * example pushing a button. For now run all streams all the time. */ for (unsigned int i = 0; i < nbuffers; i++) { std::unique_ptr<Request> request = camera_->createRequest(); if (!request) { std::cerr << "Can't create request" << std::endl; return -ENOMEM; } for (StreamConfiguration &cfg : *config_) { Stream *stream = cfg.stream(); const std::vector<std::unique_ptr<FrameBuffer>> &buffers = allocator_->buffers(stream); const std::unique_ptr<FrameBuffer> &buffer = buffers[i]; ret = request->addBuffer(stream, buffer.get()); if (ret < 0) { std::cerr << "Can't set buffer for request" << std::endl; return ret; } if (sink_) sink_->mapBuffer(buffer.get()); } requests_.push_back(std::move(request)); } if (sink_) { ret = sink_->start(); if (ret) { std::cout << "Failed to start frame sink" << std::endl; return ret; } } ret = camera_->start(); if (ret) { std::cout << "Failed to start capture" << std::endl; if (sink_) sink_->stop(); return ret; } for (std::unique_ptr<Request> &request : requests_) { ret = queueRequest(request.get()); if (ret < 0) { std::cerr << "Can't queue request" << std::endl; camera_->stop(); if (sink_) sink_->stop(); return ret; } } if (captureLimit_) std::cout << "cam" << cameraIndex_ << ": Capture " << captureLimit_ << " frames" << std::endl; else std::cout << "cam" << cameraIndex_ << ": Capture until user interrupts by SIGINT" << std::endl; return 0; } int CameraSession::queueRequest(Request *request) { if (captureLimit_ && queueCount_ >= captureLimit_) return 0; if (script_) request->controls() = script_->frameControls(queueCount_); queueCount_++; return camera_->queueRequest(request); } void CameraSession::requestComplete(Request *request) { if (request->status() == Request::RequestCancelled) return; /* * Defer processing of the completed request to the event loop, to avoid * blocking the camera manager thread. */ EventLoop::instance()->callLater([this, request]() { processRequest(request); }); } void CameraSession::processRequest(Request *request) { /* * If we've reached the capture limit, we're done. This doesn't * duplicate the check below that emits the captureDone signal, as this * function will be called for each request still in flight after the * capture limit is reached and we don't want to emit the signal every * single time. */ if (captureLimit_ && captureCount_ >= captureLimit_) return; const Request::BufferMap &buffers = request->buffers(); /* * Compute the frame rate. The timestamp is arbitrarily retrieved from * the first buffer, as all buffers should have matching timestamps. */ uint64_t ts = buffers.begin()->second->metadata().timestamp; double fps = ts - last_; fps = last_ != 0 && fps ? 1000000000.0 / fps : 0.0; last_ = ts; bool requeue = true; std::stringstream info; info << ts / 1000000000 << "." << std::setw(6) << std::setfill('0') << ts / 1000 % 1000000 << " (" << std::fixed << std::setprecision(2) << fps << " fps)"; for (const auto &[stream, buffer] : buffers) { const FrameMetadata &metadata = buffer->metadata(); info << " " << streamNames_[stream] << " seq: " << std::setw(6) << std::setfill('0') << metadata.sequence << " bytesused: "; unsigned int nplane = 0; for (const FrameMetadata::Plane &plane : metadata.planes()) { info << plane.bytesused; if (++nplane < metadata.planes().size()) info << "/"; } } if (sink_) { if (!sink_->processRequest(request)) requeue = false; } std::cout << info.str() << std::endl; if (printMetadata_) { const ControlList &requestMetadata = request->metadata(); for (const auto &[key, value] : requestMetadata) { const ControlId *id = controls::controls.at(key); std::cout << "\t" << id->name() << " = " << value.toString() << std::endl; } } /* * Notify the user that capture is complete if the limit has just been * reached. */ captureCount_++; if (captureLimit_ && captureCount_ >= captureLimit_) { captureDone.emit(); return; } /* * If the frame sink holds on the request, we'll requeue it later in the * complete handler. */ if (!requeue) return; request->reuse(Request::ReuseBuffers); queueRequest(request); } void CameraSession::sinkRelease(Request *request) { request->reuse(Request::ReuseBuffers); queueRequest(request); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/kms_sink.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2021, Ideas on Board Oy * * KMS Sink */ #include "kms_sink.h" #include <array> #include <algorithm> #include <assert.h> #include <iostream> #include <limits.h> #include <memory> #include <stdint.h> #include <string.h> #include <libcamera/camera.h> #include <libcamera/formats.h> #include <libcamera/framebuffer.h> #include <libcamera/stream.h> #include "drm.h" KMSSink::KMSSink(const std::string &connectorName) : connector_(nullptr), crtc_(nullptr), plane_(nullptr), mode_(nullptr) { int ret = dev_.init(); if (ret < 0) return; /* * Find the requested connector. If no specific connector is requested, * pick the first connected connector or, if no connector is connected, * the first connector with unknown status. */ for (const DRM::Connector &conn : dev_.connectors()) { if (!connectorName.empty()) { if (conn.name() != connectorName) continue; connector_ = &conn; break; } if (conn.status() == DRM::Connector::Connected) { connector_ = &conn; break; } if (!connector_ && conn.status() == DRM::Connector::Unknown) connector_ = &conn; } if (!connector_) { if (!connectorName.empty()) std::cerr << "Connector " << connectorName << " not found" << std::endl; else std::cerr << "No connected connector found" << std::endl; return; } dev_.requestComplete.connect(this, &KMSSink::requestComplete); } void KMSSink::mapBuffer(libcamera::FrameBuffer *buffer) { std::array<uint32_t, 4> strides = {}; /* \todo Should libcamera report per-plane strides ? */ unsigned int uvStrideMultiplier; switch (format_) { case libcamera::formats::NV24: case libcamera::formats::NV42: uvStrideMultiplier = 4; break; case libcamera::formats::YUV420: case libcamera::formats::YVU420: case libcamera::formats::YUV422: uvStrideMultiplier = 1; break; default: uvStrideMultiplier = 2; break; } strides[0] = stride_; for (unsigned int i = 1; i < buffer->planes().size(); ++i) strides[i] = stride_ * uvStrideMultiplier / 2; std::unique_ptr<DRM::FrameBuffer> drmBuffer = dev_.createFrameBuffer(*buffer, format_, size_, strides); if (!drmBuffer) return; buffers_.emplace(std::piecewise_construct, std::forward_as_tuple(buffer), std::forward_as_tuple(std::move(drmBuffer))); } int KMSSink::configure(const libcamera::CameraConfiguration &config) { if (!connector_) return -EINVAL; crtc_ = nullptr; plane_ = nullptr; mode_ = nullptr; const libcamera::StreamConfiguration &cfg = config.at(0); /* Find the best mode for the stream size. */ const std::vector<DRM::Mode> &modes = connector_->modes(); unsigned int cfgArea = cfg.size.width * cfg.size.height; unsigned int bestDistance = UINT_MAX; for (const DRM::Mode &mode : modes) { unsigned int modeArea = mode.hdisplay * mode.vdisplay; unsigned int distance = modeArea > cfgArea ? modeArea - cfgArea : cfgArea - modeArea; if (distance < bestDistance) { mode_ = &mode; bestDistance = distance; /* * If the sizes match exactly, there will be no better * match. */ if (distance == 0) break; } } if (!mode_) { std::cerr << "No modes\n"; return -EINVAL; } int ret = configurePipeline(cfg.pixelFormat); if (ret < 0) return ret; size_ = cfg.size; stride_ = cfg.stride; /* Configure color space. */ colorEncoding_ = std::nullopt; colorRange_ = std::nullopt; if (cfg.colorSpace->ycbcrEncoding == libcamera::ColorSpace::YcbcrEncoding::None) return 0; /* * The encoding and range enums are defined in the kernel but not * exposed in public headers. */ enum drm_color_encoding { DRM_COLOR_YCBCR_BT601, DRM_COLOR_YCBCR_BT709, DRM_COLOR_YCBCR_BT2020, }; enum drm_color_range { DRM_COLOR_YCBCR_LIMITED_RANGE, DRM_COLOR_YCBCR_FULL_RANGE, }; const DRM::Property *colorEncoding = plane_->property("COLOR_ENCODING"); const DRM::Property *colorRange = plane_->property("COLOR_RANGE"); if (colorEncoding) { drm_color_encoding encoding; switch (cfg.colorSpace->ycbcrEncoding) { case libcamera::ColorSpace::YcbcrEncoding::Rec601: default: encoding = DRM_COLOR_YCBCR_BT601; break; case libcamera::ColorSpace::YcbcrEncoding::Rec709: encoding = DRM_COLOR_YCBCR_BT709; break; case libcamera::ColorSpace::YcbcrEncoding::Rec2020: encoding = DRM_COLOR_YCBCR_BT2020; break; } for (const auto &[id, name] : colorEncoding->enums()) { if (id == encoding) { colorEncoding_ = encoding; break; } } } if (colorRange) { drm_color_range range; switch (cfg.colorSpace->range) { case libcamera::ColorSpace::Range::Limited: default: range = DRM_COLOR_YCBCR_LIMITED_RANGE; break; case libcamera::ColorSpace::Range::Full: range = DRM_COLOR_YCBCR_FULL_RANGE; break; } for (const auto &[id, name] : colorRange->enums()) { if (id == range) { colorRange_ = range; break; } } } if (!colorEncoding_ || !colorRange_) std::cerr << "Color space " << cfg.colorSpace->toString() << " not supported by the display device." << " Colors may be wrong." << std::endl; return 0; } int KMSSink::selectPipeline(const libcamera::PixelFormat &format) { /* * If the requested format has an alpha channel, also consider the X * variant. */ libcamera::PixelFormat xFormat; switch (format) { case libcamera::formats::ABGR8888: xFormat = libcamera::formats::XBGR8888; break; case libcamera::formats::ARGB8888: xFormat = libcamera::formats::XRGB8888; break; case libcamera::formats::BGRA8888: xFormat = libcamera::formats::BGRX8888; break; case libcamera::formats::RGBA8888: xFormat = libcamera::formats::RGBX8888; break; } /* * Find a CRTC and plane suitable for the request format and the * connector at the end of the pipeline. Restrict the search to primary * planes for now. */ for (const DRM::Encoder *encoder : connector_->encoders()) { for (const DRM::Crtc *crtc : encoder->possibleCrtcs()) { for (const DRM::Plane *plane : crtc->planes()) { if (plane->type() != DRM::Plane::TypePrimary) continue; if (plane->supportsFormat(format)) { crtc_ = crtc; plane_ = plane; format_ = format; return 0; } if (plane->supportsFormat(xFormat)) { crtc_ = crtc; plane_ = plane; format_ = xFormat; return 0; } } } } return -EPIPE; } int KMSSink::configurePipeline(const libcamera::PixelFormat &format) { const int ret = selectPipeline(format); if (ret) { std::cerr << "Unable to find display pipeline for format " << format << std::endl; return ret; } std::cout << "Using KMS plane " << plane_->id() << ", CRTC " << crtc_->id() << ", connector " << connector_->name() << " (" << connector_->id() << "), mode " << mode_->hdisplay << "x" << mode_->vdisplay << "@" << mode_->vrefresh << std::endl; return 0; } int KMSSink::start() { int ret = FrameSink::start(); if (ret < 0) return ret; /* Disable all CRTCs and planes to start from a known valid state. */ DRM::AtomicRequest request(&dev_); for (const DRM::Crtc &crtc : dev_.crtcs()) request.addProperty(&crtc, "ACTIVE", 0); for (const DRM::Plane &plane : dev_.planes()) { request.addProperty(&plane, "CRTC_ID", 0); request.addProperty(&plane, "FB_ID", 0); } ret = request.commit(DRM::AtomicRequest::FlagAllowModeset); if (ret < 0) { std::cerr << "Failed to disable CRTCs and planes: " << strerror(-ret) << std::endl; return ret; } return 0; } int KMSSink::stop() { /* Display pipeline. */ DRM::AtomicRequest request(&dev_); request.addProperty(connector_, "CRTC_ID", 0); request.addProperty(crtc_, "ACTIVE", 0); request.addProperty(crtc_, "MODE_ID", 0); request.addProperty(plane_, "CRTC_ID", 0); request.addProperty(plane_, "FB_ID", 0); int ret = request.commit(DRM::AtomicRequest::FlagAllowModeset); if (ret < 0) { std::cerr << "Failed to stop display pipeline: " << strerror(-ret) << std::endl; return ret; } /* Free all buffers. */ pending_.reset(); queued_.reset(); active_.reset(); buffers_.clear(); return FrameSink::stop(); } bool KMSSink::testModeSet(DRM::FrameBuffer *drmBuffer, const libcamera::Rectangle &src, const libcamera::Rectangle &dst) { DRM::AtomicRequest drmRequest{ &dev_ }; drmRequest.addProperty(connector_, "CRTC_ID", crtc_->id()); drmRequest.addProperty(crtc_, "ACTIVE", 1); drmRequest.addProperty(crtc_, "MODE_ID", mode_->toBlob(&dev_)); drmRequest.addProperty(plane_, "CRTC_ID", crtc_->id()); drmRequest.addProperty(plane_, "FB_ID", drmBuffer->id()); drmRequest.addProperty(plane_, "SRC_X", src.x << 16); drmRequest.addProperty(plane_, "SRC_Y", src.y << 16); drmRequest.addProperty(plane_, "SRC_W", src.width << 16); drmRequest.addProperty(plane_, "SRC_H", src.height << 16); drmRequest.addProperty(plane_, "CRTC_X", dst.x); drmRequest.addProperty(plane_, "CRTC_Y", dst.y); drmRequest.addProperty(plane_, "CRTC_W", dst.width); drmRequest.addProperty(plane_, "CRTC_H", dst.height); return !drmRequest.commit(DRM::AtomicRequest::FlagAllowModeset | DRM::AtomicRequest::FlagTestOnly); } bool KMSSink::setupComposition(DRM::FrameBuffer *drmBuffer) { /* * Test composition options, from most to least desirable, to select the * best one. */ const libcamera::Rectangle framebuffer{ size_ }; const libcamera::Rectangle display{ 0, 0, mode_->hdisplay, mode_->vdisplay }; /* 1. Scale the frame buffer to full screen, preserving aspect ratio. */ libcamera::Rectangle src = framebuffer; libcamera::Rectangle dst = display.size().boundedToAspectRatio(framebuffer.size()) .centeredTo(display.center()); if (testModeSet(drmBuffer, src, dst)) { std::cout << "KMS: full-screen scaled output, square pixels" << std::endl; src_ = src; dst_ = dst; return true; } /* * 2. Scale the frame buffer to full screen, without preserving aspect * ratio. */ src = framebuffer; dst = display; if (testModeSet(drmBuffer, src, dst)) { std::cout << "KMS: full-screen scaled output, non-square pixels" << std::endl; src_ = src; dst_ = dst; return true; } /* 3. Center the frame buffer on the display. */ src = display.size().centeredTo(framebuffer.center()).boundedTo(framebuffer); dst = framebuffer.size().centeredTo(display.center()).boundedTo(display); if (testModeSet(drmBuffer, src, dst)) { std::cout << "KMS: centered output" << std::endl; src_ = src; dst_ = dst; return true; } /* 4. Align the frame buffer on the top-left of the display. */ src = framebuffer.boundedTo(display); dst = display.boundedTo(framebuffer); if (testModeSet(drmBuffer, src, dst)) { std::cout << "KMS: top-left aligned output" << std::endl; src_ = src; dst_ = dst; return true; } return false; } bool KMSSink::processRequest(libcamera::Request *camRequest) { /* * Perform a very crude rate adaptation by simply dropping the request * if the display queue is full. */ if (pending_) return true; libcamera::FrameBuffer *buffer = camRequest->buffers().begin()->second; auto iter = buffers_.find(buffer); if (iter == buffers_.end()) return true; DRM::FrameBuffer *drmBuffer = iter->second.get(); unsigned int flags = DRM::AtomicRequest::FlagAsync; std::unique_ptr<DRM::AtomicRequest> drmRequest = std::make_unique<DRM::AtomicRequest>(&dev_); drmRequest->addProperty(plane_, "FB_ID", drmBuffer->id()); if (!active_ && !queued_) { /* Enable the display pipeline on the first frame. */ if (!setupComposition(drmBuffer)) { std::cerr << "Failed to setup composition" << std::endl; return true; } drmRequest->addProperty(connector_, "CRTC_ID", crtc_->id()); drmRequest->addProperty(crtc_, "ACTIVE", 1); drmRequest->addProperty(crtc_, "MODE_ID", mode_->toBlob(&dev_)); drmRequest->addProperty(plane_, "CRTC_ID", crtc_->id()); drmRequest->addProperty(plane_, "SRC_X", src_.x << 16); drmRequest->addProperty(plane_, "SRC_Y", src_.y << 16); drmRequest->addProperty(plane_, "SRC_W", src_.width << 16); drmRequest->addProperty(plane_, "SRC_H", src_.height << 16); drmRequest->addProperty(plane_, "CRTC_X", dst_.x); drmRequest->addProperty(plane_, "CRTC_Y", dst_.y); drmRequest->addProperty(plane_, "CRTC_W", dst_.width); drmRequest->addProperty(plane_, "CRTC_H", dst_.height); if (colorEncoding_) drmRequest->addProperty(plane_, "COLOR_ENCODING", *colorEncoding_); if (colorRange_) drmRequest->addProperty(plane_, "COLOR_RANGE", *colorRange_); flags |= DRM::AtomicRequest::FlagAllowModeset; } pending_ = std::make_unique<Request>(std::move(drmRequest), camRequest); std::lock_guard<std::mutex> lock(lock_); if (!queued_) { int ret = pending_->drmRequest_->commit(flags); if (ret < 0) { std::cerr << "Failed to commit atomic request: " << strerror(-ret) << std::endl; /* \todo Implement error handling */ } queued_ = std::move(pending_); } return false; } void KMSSink::requestComplete([[maybe_unused]] DRM::AtomicRequest *request) { std::lock_guard<std::mutex> lock(lock_); assert(queued_ && queued_->drmRequest_.get() == request); /* Complete the active request, if any. */ if (active_) requestProcessed.emit(active_->camRequest_); /* The queued request becomes active. */ active_ = std::move(queued_); /* Queue the pending request, if any. */ if (pending_) { pending_->drmRequest_->commit(DRM::AtomicRequest::FlagAsync); queued_ = std::move(pending_); } }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/sdl_sink.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * SDL Sink */ #pragma once #include <map> #include <memory> #include <libcamera/stream.h> #include <SDL2/SDL.h> #include "frame_sink.h" class Image; class SDLTexture; class SDLSink : public FrameSink { public: SDLSink(); ~SDLSink(); int configure(const libcamera::CameraConfiguration &config) override; int start() override; int stop() override; void mapBuffer(libcamera::FrameBuffer *buffer) override; bool processRequest(libcamera::Request *request) override; private: void renderBuffer(libcamera::FrameBuffer *buffer); void processSDLEvents(); std::map<libcamera::FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_; std::unique_ptr<SDLTexture> texture_; SDL_Window *window_; SDL_Renderer *renderer_; SDL_Rect rect_; bool init_; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/drm.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2021, Ideas on Board Oy * * DRM/KMS Helpers */ #pragma once #include <array> #include <list> #include <map> #include <memory> #include <stdint.h> #include <string> #include <vector> #include <libcamera/base/signal.h> #include <libcamera/base/span.h> #include <libdrm/drm.h> #include <xf86drm.h> #include <xf86drmMode.h> namespace libcamera { class FrameBuffer; class PixelFormat; class Size; } /* namespace libcamera */ namespace DRM { class Device; class Plane; class Property; class PropertyValue; class Object { public: enum Type { TypeCrtc = DRM_MODE_OBJECT_CRTC, TypeConnector = DRM_MODE_OBJECT_CONNECTOR, TypeEncoder = DRM_MODE_OBJECT_ENCODER, TypeMode = DRM_MODE_OBJECT_MODE, TypeProperty = DRM_MODE_OBJECT_PROPERTY, TypeFb = DRM_MODE_OBJECT_FB, TypeBlob = DRM_MODE_OBJECT_BLOB, TypePlane = DRM_MODE_OBJECT_PLANE, TypeAny = DRM_MODE_OBJECT_ANY, }; Object(Device *dev, uint32_t id, Type type); virtual ~Object(); Device *device() const { return dev_; } uint32_t id() const { return id_; } Type type() const { return type_; } const Property *property(const std::string &name) const; const PropertyValue *propertyValue(const std::string &name) const; const std::vector<PropertyValue> &properties() const { return properties_; } protected: virtual int setup() { return 0; } uint32_t id_; private: friend Device; Device *dev_; Type type_; std::vector<PropertyValue> properties_; }; class Property : public Object { public: enum Type { TypeUnknown = 0, TypeRange, TypeEnum, TypeBlob, TypeBitmask, TypeObject, TypeSignedRange, }; Property(Device *dev, drmModePropertyRes *property); Type type() const { return type_; } const std::string &name() const { return name_; } bool isImmutable() const { return flags_ & DRM_MODE_PROP_IMMUTABLE; } const std::vector<uint64_t> values() const { return values_; } const std::map<uint32_t, std::string> &enums() const { return enums_; } const std::vector<uint32_t> blobs() const { return blobs_; } private: Type type_; std::string name_; uint32_t flags_; std::vector<uint64_t> values_; std::map<uint32_t, std::string> enums_; std::vector<uint32_t> blobs_; }; class PropertyValue { public: PropertyValue(uint32_t id, uint64_t value) : id_(id), value_(value) { } uint32_t id() const { return id_; } uint32_t value() const { return value_; } private: uint32_t id_; uint64_t value_; }; class Blob : public Object { public: Blob(Device *dev, const libcamera::Span<const uint8_t> &data); ~Blob(); bool isValid() const { return id() != 0; } }; class Mode : public drmModeModeInfo { public: Mode(const drmModeModeInfo &mode); std::unique_ptr<Blob> toBlob(Device *dev) const; }; class Crtc : public Object { public: Crtc(Device *dev, const drmModeCrtc *crtc, unsigned int index); unsigned int index() const { return index_; } const std::vector<const Plane *> &planes() const { return planes_; } private: friend Device; unsigned int index_; std::vector<const Plane *> planes_; }; class Encoder : public Object { public: Encoder(Device *dev, const drmModeEncoder *encoder); uint32_t type() const { return type_; } const std::vector<const Crtc *> &possibleCrtcs() const { return possibleCrtcs_; } private: uint32_t type_; std::vector<const Crtc *> possibleCrtcs_; }; class Connector : public Object { public: enum Status { Connected, Disconnected, Unknown, }; Connector(Device *dev, const drmModeConnector *connector); uint32_t type() const { return type_; } const std::string &name() const { return name_; } Status status() const { return status_; } const std::vector<const Encoder *> &encoders() const { return encoders_; } const std::vector<Mode> &modes() const { return modes_; } private: uint32_t type_; std::string name_; Status status_; std::vector<const Encoder *> encoders_; std::vector<Mode> modes_; }; class Plane : public Object { public: enum Type { TypeOverlay, TypePrimary, TypeCursor, }; Plane(Device *dev, const drmModePlane *plane); Type type() const { return type_; } const std::vector<uint32_t> &formats() const { return formats_; } const std::vector<const Crtc *> &possibleCrtcs() const { return possibleCrtcs_; } bool supportsFormat(const libcamera::PixelFormat &format) const; protected: int setup() override; private: friend class Device; Type type_; std::vector<uint32_t> formats_; std::vector<const Crtc *> possibleCrtcs_; uint32_t possibleCrtcsMask_; }; class FrameBuffer : public Object { public: struct Plane { uint32_t handle; }; ~FrameBuffer(); private: friend class Device; FrameBuffer(Device *dev); std::map<int, Plane> planes_; }; class AtomicRequest { public: enum Flags { FlagAllowModeset = (1 << 0), FlagAsync = (1 << 1), FlagTestOnly = (1 << 2), }; AtomicRequest(Device *dev); ~AtomicRequest(); Device *device() const { return dev_; } bool isValid() const { return valid_; } int addProperty(const Object *object, const std::string &property, uint64_t value); int addProperty(const Object *object, const std::string &property, std::unique_ptr<Blob> blob); int commit(unsigned int flags = 0); private: AtomicRequest(const AtomicRequest &) = delete; AtomicRequest(const AtomicRequest &&) = delete; AtomicRequest &operator=(const AtomicRequest &) = delete; AtomicRequest &operator=(const AtomicRequest &&) = delete; int addProperty(uint32_t object, uint32_t property, uint64_t value); Device *dev_; bool valid_; drmModeAtomicReq *request_; std::list<std::unique_ptr<Blob>> blobs_; }; class Device { public: Device(); ~Device(); int init(); int fd() const { return fd_; } const std::list<Crtc> &crtcs() const { return crtcs_; } const std::list<Encoder> &encoders() const { return encoders_; } const std::list<Connector> &connectors() const { return connectors_; } const std::list<Plane> &planes() const { return planes_; } const std::list<Property> &properties() const { return properties_; } const Object *object(uint32_t id); std::unique_ptr<FrameBuffer> createFrameBuffer( const libcamera::FrameBuffer &buffer, const libcamera::PixelFormat &format, const libcamera::Size &size, const std::array<uint32_t, 4> &strides); libcamera::Signal<AtomicRequest *> requestComplete; private: Device(const Device &) = delete; Device(const Device &&) = delete; Device &operator=(const Device &) = delete; Device &operator=(const Device &&) = delete; int openCard(); int getResources(); void drmEvent(); static void pageFlipComplete(int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data); int fd_; std::list<Crtc> crtcs_; std::list<Encoder> encoders_; std::list<Connector> connectors_; std::list<Plane> planes_; std::list<Property> properties_; std::map<uint32_t, Object *> objects_; }; } /* namespace DRM */
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/frame_sink.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2021, Ideas on Board Oy * * Base Frame Sink Class */ #pragma once #include <libcamera/base/signal.h> namespace libcamera { class CameraConfiguration; class FrameBuffer; class Request; } /* namespace libcamera */ class FrameSink { public: virtual ~FrameSink(); virtual int configure(const libcamera::CameraConfiguration &config); virtual void mapBuffer(libcamera::FrameBuffer *buffer); virtual int start(); virtual int stop(); virtual bool processRequest(libcamera::Request *request) = 0; libcamera::Signal<libcamera::Request *> requestProcessed; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/sdl_texture_yuv.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * SDL YUV Textures */ #include "sdl_texture_yuv.h" using namespace libcamera; #if SDL_VERSION_ATLEAST(2, 0, 16) SDLTextureNV12::SDLTextureNV12(const SDL_Rect &rect, unsigned int stride) : SDLTexture(rect, SDL_PIXELFORMAT_NV12, stride) { } void SDLTextureNV12::update(const std::vector<libcamera::Span<const uint8_t>> &data) { SDL_UpdateNVTexture(ptr_, &rect_, data[0].data(), stride_, data[1].data(), stride_); } #endif SDLTextureYUYV::SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride) : SDLTexture(rect, SDL_PIXELFORMAT_YUY2, stride) { } void SDLTextureYUYV::update(const std::vector<libcamera::Span<const uint8_t>> &data) { SDL_UpdateTexture(ptr_, &rect_, data[0].data(), stride_); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/capture_script.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * Capture session configuration script */ #pragma once #include <map> #include <memory> #include <string> #include <libcamera/camera.h> #include <libcamera/controls.h> #include <yaml.h> class CaptureScript { public: CaptureScript(std::shared_ptr<libcamera::Camera> camera, const std::string &fileName); bool valid() const { return valid_; } const libcamera::ControlList &frameControls(unsigned int frame); private: struct EventDeleter { void operator()(yaml_event_t *event) const { yaml_event_delete(event); delete event; } }; using EventPtr = std::unique_ptr<yaml_event_t, EventDeleter>; std::map<std::string, const libcamera::ControlId *> controls_; std::map<unsigned int, libcamera::ControlList> frameControls_; std::shared_ptr<libcamera::Camera> camera_; yaml_parser_t parser_; unsigned int loop_; bool valid_; EventPtr nextEvent(yaml_event_type_t expectedType = YAML_NO_EVENT); bool checkEvent(const EventPtr &event, yaml_event_type_t expectedType) const; static std::string eventScalarValue(const EventPtr &event); static std::string eventTypeName(yaml_event_type_t type); int parseScript(FILE *script); int parseProperties(); int parseProperty(); int parseFrames(); int parseFrame(EventPtr event); int parseControl(EventPtr event, libcamera::ControlList &controls); libcamera::ControlValue parseScalarControl(const libcamera::ControlId *id, const std::string repr); libcamera::ControlValue parseArrayControl(const libcamera::ControlId *id, const std::vector<std::string> &repr); std::string parseScalar(); libcamera::ControlValue parseRectangles(); std::vector<std::vector<std::string>> parseArrays(); std::vector<std::string> parseSingleArray(); void unpackFailure(const libcamera::ControlId *id, const std::string &repr); libcamera::ControlValue unpackControl(const libcamera::ControlId *id); libcamera::Rectangle unpackRectangle(const std::vector<std::string> &strVec); };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/capture-script.yaml
# SPDX-License-Identifier: CC0-1.0 # Capture script example # # A capture script allows to associate a list of controls and their values # to frame numbers. # # The script allows defining a list of frames associated with controls # and an optional list of properties that can control the script behaviour. # properties: # # Repeat the controls every 'idx' frames. # - loop: idx # # # List of frame number with associated a list of controls to be applied # frames: # - frame-number: # Control1: value1 # Control2: value2 # \todo Formally define the capture script structure with a schema # Notes: # - Controls have to be specified by name, as defined in the # libcamera::controls:: enumeration # - Controls not supported by the camera currently operated are ignored # - Frame numbers shall be monotonically incrementing, gaps are allowed # - If a loop limit is specified, frame numbers in the 'frames' list shall be # less than the loop control # Example: Turn brightness up and down every 460 frames properties: - loop: 460 frames: - 0: Brightness: 0.0 - 40: Brightness: 0.2 - 80: Brightness: 0.4 - 120: Brightness: 0.8 - 160: Brightness: 0.4 - 200: Brightness: 0.2 - 240: Brightness: 0.0 - 280: Brightness: -0.2 - 300: Brightness: -0.4 - 340: Brightness: -0.8 - 380: Brightness: -0.4 - 420: Brightness: -0.2
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/file_sink.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * File Sink */ #include <assert.h> #include <fcntl.h> #include <iomanip> #include <iostream> #include <sstream> #include <string.h> #include <unistd.h> #include <libcamera/camera.h> #include "../common/dng_writer.h" #include "../common/image.h" #include "../common/ppm_writer.h" #include "file_sink.h" using namespace libcamera; FileSink::FileSink([[maybe_unused]] const libcamera::Camera *camera, const std::map<const libcamera::Stream *, std::string> &streamNames, const std::string &pattern) : #ifdef HAVE_TIFF camera_(camera), #endif streamNames_(streamNames), pattern_(pattern) { } FileSink::~FileSink() { } int FileSink::configure(const libcamera::CameraConfiguration &config) { int ret = FrameSink::configure(config); if (ret < 0) return ret; return 0; } void FileSink::mapBuffer(FrameBuffer *buffer) { std::unique_ptr<Image> image = Image::fromFrameBuffer(buffer, Image::MapMode::ReadOnly); assert(image != nullptr); mappedBuffers_[buffer] = std::move(image); } bool FileSink::processRequest(Request *request) { for (auto [stream, buffer] : request->buffers()) writeBuffer(stream, buffer, request->metadata()); return true; } void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer, [[maybe_unused]] const ControlList &metadata) { std::string filename; size_t pos; int fd, ret = 0; if (!pattern_.empty()) filename = pattern_; #ifdef HAVE_TIFF bool dng = filename.find(".dng", filename.size() - 4) != std::string::npos; #endif /* HAVE_TIFF */ bool ppm = filename.find(".ppm", filename.size() - 4) != std::string::npos; if (filename.empty() || filename.back() == '/') filename += "frame-#.bin"; pos = filename.find_first_of('#'); if (pos != std::string::npos) { std::stringstream ss; ss << streamNames_[stream] << "-" << std::setw(6) << std::setfill('0') << buffer->metadata().sequence; filename.replace(pos, 1, ss.str()); } Image *image = mappedBuffers_[buffer].get(); #ifdef HAVE_TIFF if (dng) { ret = DNGWriter::write(filename.c_str(), camera_, stream->configuration(), metadata, buffer, image->data(0).data()); if (ret < 0) std::cerr << "failed to write DNG file `" << filename << "'" << std::endl; return; } #endif /* HAVE_TIFF */ if (ppm) { ret = PPMWriter::write(filename.c_str(), stream->configuration(), image->data(0)); if (ret < 0) std::cerr << "failed to write PPM file `" << filename << "'" << std::endl; return; } fd = open(filename.c_str(), O_CREAT | O_WRONLY | (pos == std::string::npos ? O_APPEND : O_TRUNC), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd == -1) { ret = -errno; std::cerr << "failed to open file " << filename << ": " << strerror(-ret) << std::endl; return; } for (unsigned int i = 0; i < buffer->planes().size(); ++i) { /* * This was formerly a local "const FrameMetadata::Plane &" * however this causes a false positive warning for dangling * references on gcc 13. */ const unsigned int bytesused = buffer->metadata().planes()[i].bytesused; Span<uint8_t> data = image->data(i); const unsigned int length = std::min<unsigned int>(bytesused, data.size()); if (bytesused > data.size()) std::cerr << "payload size " << bytesused << " larger than plane size " << data.size() << std::endl; ret = ::write(fd, data.data(), length); if (ret < 0) { ret = -errno; std::cerr << "write error: " << strerror(-ret) << std::endl; break; } else if (ret != (int)length) { std::cerr << "write error: only " << ret << " bytes written instead of " << length << std::endl; break; } } close(fd); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/camera_session.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * Camera capture session */ #pragma once #include <memory> #include <stdint.h> #include <string> #include <vector> #include <libcamera/base/signal.h> #include <libcamera/camera.h> #include <libcamera/camera_manager.h> #include <libcamera/framebuffer.h> #include <libcamera/framebuffer_allocator.h> #include <libcamera/request.h> #include <libcamera/stream.h> #include "../common/options.h" class CaptureScript; class FrameSink; class CameraSession { public: CameraSession(libcamera::CameraManager *cm, const std::string &cameraId, unsigned int cameraIndex, const OptionsParser::Options &options); ~CameraSession(); bool isValid() const { return config_ != nullptr; } const OptionsParser::Options &options() { return options_; } libcamera::Camera *camera() { return camera_.get(); } libcamera::CameraConfiguration *config() { return config_.get(); } void listControls() const; void listProperties() const; void infoConfiguration() const; int start(); void stop(); libcamera::Signal<> captureDone; private: int startCapture(); int queueRequest(libcamera::Request *request); void requestComplete(libcamera::Request *request); void processRequest(libcamera::Request *request); void sinkRelease(libcamera::Request *request); const OptionsParser::Options &options_; std::shared_ptr<libcamera::Camera> camera_; std::unique_ptr<libcamera::CameraConfiguration> config_; std::unique_ptr<CaptureScript> script_; std::map<const libcamera::Stream *, std::string> streamNames_; std::unique_ptr<FrameSink> sink_; unsigned int cameraIndex_; uint64_t last_; unsigned int queueCount_; unsigned int captureCount_; unsigned int captureLimit_; bool printMetadata_; std::unique_ptr<libcamera::FrameBufferAllocator> allocator_; std::vector<std::unique_ptr<libcamera::Request>> requests_; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/sdl_sink.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * SDL Sink */ #include "sdl_sink.h" #include <assert.h> #include <fcntl.h> #include <iomanip> #include <iostream> #include <signal.h> #include <sstream> #include <string.h> #include <unistd.h> #include <libcamera/camera.h> #include <libcamera/formats.h> #include "../common/event_loop.h" #include "../common/image.h" #ifdef HAVE_LIBJPEG #include "sdl_texture_mjpg.h" #endif #include "sdl_texture_yuv.h" using namespace libcamera; using namespace std::chrono_literals; SDLSink::SDLSink() : window_(nullptr), renderer_(nullptr), rect_({}), init_(false) { } SDLSink::~SDLSink() { stop(); } int SDLSink::configure(const libcamera::CameraConfiguration &config) { int ret = FrameSink::configure(config); if (ret < 0) return ret; if (config.size() > 1) { std::cerr << "SDL sink only supports one camera stream at present, streaming first camera stream" << std::endl; } else if (config.empty()) { std::cerr << "Require at least one camera stream to process" << std::endl; return -EINVAL; } const libcamera::StreamConfiguration &cfg = config.at(0); rect_.w = cfg.size.width; rect_.h = cfg.size.height; switch (cfg.pixelFormat) { #ifdef HAVE_LIBJPEG case libcamera::formats::MJPEG: texture_ = std::make_unique<SDLTextureMJPG>(rect_); break; #endif #if SDL_VERSION_ATLEAST(2, 0, 16) case libcamera::formats::NV12: texture_ = std::make_unique<SDLTextureNV12>(rect_, cfg.stride); break; #endif case libcamera::formats::YUYV: texture_ = std::make_unique<SDLTextureYUYV>(rect_, cfg.stride); break; default: std::cerr << "Unsupported pixel format " << cfg.pixelFormat.toString() << std::endl; return -EINVAL; }; return 0; } int SDLSink::start() { int ret = SDL_Init(SDL_INIT_VIDEO); if (ret) { std::cerr << "Failed to initialize SDL: " << SDL_GetError() << std::endl; return ret; } init_ = true; window_ = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, rect_.w, rect_.h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if (!window_) { std::cerr << "Failed to create SDL window: " << SDL_GetError() << std::endl; return -EINVAL; } renderer_ = SDL_CreateRenderer(window_, -1, 0); if (!renderer_) { std::cerr << "Failed to create SDL renderer: " << SDL_GetError() << std::endl; return -EINVAL; } /* * Set for scaling purposes, not critical, don't return in case of * error. */ ret = SDL_RenderSetLogicalSize(renderer_, rect_.w, rect_.h); if (ret) std::cerr << "Failed to set SDL render logical size: " << SDL_GetError() << std::endl; ret = texture_->create(renderer_); if (ret) { return ret; } /* \todo Make the event cancellable to support stop/start cycles. */ EventLoop::instance()->addTimerEvent( 10ms, std::bind(&SDLSink::processSDLEvents, this)); return 0; } int SDLSink::stop() { texture_.reset(); if (renderer_) { SDL_DestroyRenderer(renderer_); renderer_ = nullptr; } if (window_) { SDL_DestroyWindow(window_); window_ = nullptr; } if (init_) { SDL_Quit(); init_ = false; } return FrameSink::stop(); } void SDLSink::mapBuffer(FrameBuffer *buffer) { std::unique_ptr<Image> image = Image::fromFrameBuffer(buffer, Image::MapMode::ReadOnly); assert(image != nullptr); mappedBuffers_[buffer] = std::move(image); } bool SDLSink::processRequest(Request *request) { for (auto [stream, buffer] : request->buffers()) { renderBuffer(buffer); break; /* to be expanded to launch SDL window per buffer */ } return true; } /* * Process SDL events, required for things like window resize and quit button */ void SDLSink::processSDLEvents() { for (SDL_Event e; SDL_PollEvent(&e);) { if (e.type == SDL_QUIT) { /* Click close icon then quit */ EventLoop::instance()->exit(0); } } } void SDLSink::renderBuffer(FrameBuffer *buffer) { Image *image = mappedBuffers_[buffer].get(); std::vector<Span<const uint8_t>> planes; unsigned int i = 0; planes.reserve(buffer->metadata().planes().size()); for (const FrameMetadata::Plane &meta : buffer->metadata().planes()) { Span<uint8_t> data = image->data(i); if (meta.bytesused > data.size()) std::cerr << "payload size " << meta.bytesused << " larger than plane size " << data.size() << std::endl; planes.push_back(data); i++; } texture_->update(planes); SDL_RenderClear(renderer_); SDL_RenderCopy(renderer_, texture_->get(), nullptr, nullptr); SDL_RenderPresent(renderer_); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/sdl_texture_mjpg.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * SDL Texture MJPG */ #include "sdl_texture_mjpg.h" #include <iostream> #include <setjmp.h> #include <stdio.h> #include <jpeglib.h> using namespace libcamera; struct JpegErrorManager : public jpeg_error_mgr { JpegErrorManager() { jpeg_std_error(this); error_exit = errorExit; output_message = outputMessage; } static void errorExit(j_common_ptr cinfo) { JpegErrorManager *self = static_cast<JpegErrorManager *>(cinfo->err); longjmp(self->escape_, 1); } static void outputMessage([[maybe_unused]] j_common_ptr cinfo) { } jmp_buf escape_; }; SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &rect) : SDLTexture(rect, SDL_PIXELFORMAT_RGB24, rect.w * 3), rgb_(std::make_unique<unsigned char[]>(stride_ * rect.h)) { } int SDLTextureMJPG::decompress(Span<const uint8_t> data) { struct jpeg_decompress_struct cinfo; JpegErrorManager errorManager; if (setjmp(errorManager.escape_)) { /* libjpeg found an error */ jpeg_destroy_decompress(&cinfo); std::cerr << "JPEG decompression error" << std::endl; return -EINVAL; } cinfo.err = &errorManager; jpeg_create_decompress(&cinfo); jpeg_mem_src(&cinfo, data.data(), data.size()); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); for (int i = 0; cinfo.output_scanline < cinfo.output_height; ++i) { JSAMPROW rowptr = rgb_.get() + i * stride_; jpeg_read_scanlines(&cinfo, &rowptr, 1); } jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); return 0; } void SDLTextureMJPG::update(const std::vector<libcamera::Span<const uint8_t>> &data) { decompress(data[0]); SDL_UpdateTexture(ptr_, nullptr, rgb_.get(), stride_); }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/frame_sink.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2021, Ideas on Board Oy * * Base Frame Sink Class */ #include "frame_sink.h" /** * \class FrameSink * \brief Abstract class to model a consumer of frames * * The FrameSink class models the consumer that processes frames after a request * completes. It receives requests through processRequest(), and processes them * synchronously or asynchronously. This allows frame sinks to hold onto frames * for an extended period of time, for instance to display them until a new * frame arrives. * * A frame sink processes whole requests, and is solely responsible for deciding * how to handle different frame buffers in case multiple streams are captured. */ FrameSink::~FrameSink() { } int FrameSink::configure([[maybe_unused]] const libcamera::CameraConfiguration &config) { return 0; } void FrameSink::mapBuffer([[maybe_unused]] libcamera::FrameBuffer *buffer) { } int FrameSink::start() { return 0; } int FrameSink::stop() { return 0; } /** * \fn FrameSink::processRequest() * \param[in] request The request * * This function is called to instruct the sink to process a request. The sink * may process the request synchronously or queue it for asynchronous * processing. * * When the request is processed synchronously, this function shall return true. * The \a request shall not be accessed by the FrameSink after the function * returns. * * When the request is processed asynchronously, the FrameSink temporarily takes * ownership of the \a request. The function shall return false, and the * FrameSink shall emit the requestProcessed signal when the request processing * completes. If the stop() function is called before the request processing * completes, it shall release the request synchronously. * * \return True if the request has been processed synchronously, false if * processing has been queued */
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/kms_sink.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2021, Ideas on Board Oy * * KMS Sink */ #pragma once #include <list> #include <memory> #include <mutex> #include <optional> #include <string> #include <utility> #include <libcamera/base/signal.h> #include <libcamera/geometry.h> #include <libcamera/pixel_format.h> #include "drm.h" #include "frame_sink.h" class KMSSink : public FrameSink { public: KMSSink(const std::string &connectorName); void mapBuffer(libcamera::FrameBuffer *buffer) override; int configure(const libcamera::CameraConfiguration &config) override; int start() override; int stop() override; bool processRequest(libcamera::Request *request) override; private: class Request { public: Request(std::unique_ptr<DRM::AtomicRequest> drmRequest, libcamera::Request *camRequest) : drmRequest_(std::move(drmRequest)), camRequest_(camRequest) { } std::unique_ptr<DRM::AtomicRequest> drmRequest_; libcamera::Request *camRequest_; }; int selectPipeline(const libcamera::PixelFormat &format); int configurePipeline(const libcamera::PixelFormat &format); bool testModeSet(DRM::FrameBuffer *drmBuffer, const libcamera::Rectangle &src, const libcamera::Rectangle &dst); bool setupComposition(DRM::FrameBuffer *drmBuffer); void requestComplete(DRM::AtomicRequest *request); DRM::Device dev_; const DRM::Connector *connector_; const DRM::Crtc *crtc_; const DRM::Plane *plane_; const DRM::Mode *mode_; libcamera::PixelFormat format_; libcamera::Size size_; unsigned int stride_; std::optional<unsigned int> colorEncoding_; std::optional<unsigned int> colorRange_; libcamera::Rectangle src_; libcamera::Rectangle dst_; std::map<libcamera::FrameBuffer *, std::unique_ptr<DRM::FrameBuffer>> buffers_; std::mutex lock_; std::unique_ptr<Request> pending_; std::unique_ptr<Request> queued_; std::unique_ptr<Request> active_; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/sdl_texture_yuv.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * SDL YUV Textures */ #pragma once #include "sdl_texture.h" #if SDL_VERSION_ATLEAST(2, 0, 16) class SDLTextureNV12 : public SDLTexture { public: SDLTextureNV12(const SDL_Rect &rect, unsigned int stride); void update(const std::vector<libcamera::Span<const uint8_t>> &data) override; }; #endif class SDLTextureYUYV : public SDLTexture { public: SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride); void update(const std::vector<libcamera::Span<const uint8_t>> &data) override; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/sdl_texture_mjpg.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * SDL Texture MJPG */ #pragma once #include "sdl_texture.h" class SDLTextureMJPG : public SDLTexture { public: SDLTextureMJPG(const SDL_Rect &rect); void update(const std::vector<libcamera::Span<const uint8_t>> &data) override; private: int decompress(libcamera::Span<const uint8_t> data); std::unique_ptr<unsigned char[]> rgb_; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/sdl_texture.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * SDL Texture */ #include "sdl_texture.h" #include <iostream> SDLTexture::SDLTexture(const SDL_Rect &rect, uint32_t pixelFormat, const int stride) : ptr_(nullptr), rect_(rect), pixelFormat_(pixelFormat), stride_(stride) { } SDLTexture::~SDLTexture() { if (ptr_) SDL_DestroyTexture(ptr_); } int SDLTexture::create(SDL_Renderer *renderer) { ptr_ = SDL_CreateTexture(renderer, pixelFormat_, SDL_TEXTUREACCESS_STREAMING, rect_.w, rect_.h); if (!ptr_) { std::cerr << "Failed to create SDL texture: " << SDL_GetError() << std::endl; return -ENOMEM; } return 0; }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/main.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * cam - The libcamera swiss army knife */ #include <atomic> #include <iomanip> #include <iostream> #include <signal.h> #include <string.h> #include <libcamera/libcamera.h> #include <libcamera/property_ids.h> #include "../common/event_loop.h" #include "../common/options.h" #include "../common/stream_options.h" #include "camera_session.h" #include "main.h" using namespace libcamera; class CamApp { public: CamApp(); static CamApp *instance(); int init(int argc, char **argv); void cleanup(); int exec(); void quit(); private: void cameraAdded(std::shared_ptr<Camera> cam); void cameraRemoved(std::shared_ptr<Camera> cam); void captureDone(); int parseOptions(int argc, char *argv[]); int run(); static std::string cameraName(const Camera *camera); static CamApp *app_; OptionsParser::Options options_; std::unique_ptr<CameraManager> cm_; std::atomic_uint loopUsers_; EventLoop loop_; }; CamApp *CamApp::app_ = nullptr; CamApp::CamApp() : loopUsers_(0) { CamApp::app_ = this; } CamApp *CamApp::instance() { return CamApp::app_; } int CamApp::init(int argc, char **argv) { int ret; ret = parseOptions(argc, argv); if (ret < 0) return ret; cm_ = std::make_unique<CameraManager>(); ret = cm_->start(); if (ret) { std::cout << "Failed to start camera manager: " << strerror(-ret) << std::endl; return ret; } return 0; } void CamApp::cleanup() { cm_->stop(); } int CamApp::exec() { int ret; ret = run(); cleanup(); return ret; } void CamApp::quit() { loop_.exit(); } int CamApp::parseOptions(int argc, char *argv[]) { StreamKeyValueParser streamKeyValue; OptionsParser parser; parser.addOption(OptCamera, OptionString, "Specify which camera to operate on, by id or by index", "camera", ArgumentRequired, "camera", true); parser.addOption(OptHelp, OptionNone, "Display this help message", "help"); parser.addOption(OptInfo, OptionNone, "Display information about stream(s)", "info"); parser.addOption(OptList, OptionNone, "List all cameras", "list"); parser.addOption(OptListControls, OptionNone, "List cameras controls", "list-controls"); parser.addOption(OptListProperties, OptionNone, "List cameras properties", "list-properties"); parser.addOption(OptMonitor, OptionNone, "Monitor for hotplug and unplug camera events", "monitor"); /* Sub-options of OptCamera: */ parser.addOption(OptCapture, OptionInteger, "Capture until interrupted by user or until <count> frames captured", "capture", ArgumentOptional, "count", false, OptCamera); parser.addOption(OptOrientation, OptionString, "Desired image orientation (rot0, rot180, mirror, flip)", "orientation", ArgumentRequired, "orientation", false, OptCamera); #ifdef HAVE_KMS parser.addOption(OptDisplay, OptionString, "Display viewfinder through DRM/KMS on specified connector", "display", ArgumentOptional, "connector", false, OptCamera); #endif parser.addOption(OptFile, OptionString, "Write captured frames to disk\n" "If the file name ends with a '/', it sets the directory in which\n" "to write files, using the default file name. Otherwise it sets the\n" "full file path and name. The first '#' character in the file name\n" "is expanded to the camera index, stream name and frame sequence number.\n" #ifdef HAVE_TIFF "If the file name ends with '.dng', then the frame will be written to\n" "the output file(s) in DNG format.\n" #endif "If the file name ends with '.ppm', then the frame will be written to\n" "the output file(s) in PPM format.\n" "The default file name is 'frame-#.bin'.", "file", ArgumentOptional, "filename", false, OptCamera); #ifdef HAVE_SDL parser.addOption(OptSDL, OptionNone, "Display viewfinder through SDL", "sdl", ArgumentNone, "", false, OptCamera); #endif parser.addOption(OptStream, &streamKeyValue, "Set configuration of a camera stream", "stream", true, OptCamera); parser.addOption(OptStrictFormats, OptionNone, "Do not allow requested stream format(s) to be adjusted", "strict-formats", ArgumentNone, nullptr, false, OptCamera); parser.addOption(OptMetadata, OptionNone, "Print the metadata for completed requests", "metadata", ArgumentNone, nullptr, false, OptCamera); parser.addOption(OptCaptureScript, OptionString, "Load a capture session configuration script from a file", "script", ArgumentRequired, "script", false, OptCamera); options_ = parser.parse(argc, argv); if (!options_.valid()) return -EINVAL; if (options_.empty() || options_.isSet(OptHelp)) { parser.usage(); return options_.empty() ? -EINVAL : -EINTR; } return 0; } void CamApp::cameraAdded(std::shared_ptr<Camera> cam) { std::cout << "Camera Added: " << cam->id() << std::endl; } void CamApp::cameraRemoved(std::shared_ptr<Camera> cam) { std::cout << "Camera Removed: " << cam->id() << std::endl; } void CamApp::captureDone() { if (--loopUsers_ == 0) EventLoop::instance()->exit(0); } int CamApp::run() { int ret; /* 1. List all cameras. */ if (options_.isSet(OptList)) { std::cout << "Available cameras:" << std::endl; unsigned int index = 1; for (const std::shared_ptr<Camera> &cam : cm_->cameras()) { std::cout << index << ": " << cameraName(cam.get()) << std::endl; index++; } } /* 2. Create the camera sessions. */ std::vector<std::unique_ptr<CameraSession>> sessions; if (options_.isSet(OptCamera)) { unsigned int index = 0; for (const OptionValue &camera : options_[OptCamera].toArray()) { std::unique_ptr<CameraSession> session = std::make_unique<CameraSession>(cm_.get(), camera.toString(), index, camera.children()); if (!session->isValid()) { std::cout << "Failed to create camera session" << std::endl; return -EINVAL; } std::cout << "Using camera " << session->camera()->id() << " as cam" << index << std::endl; session->captureDone.connect(this, &CamApp::captureDone); sessions.push_back(std::move(session)); index++; } } /* 3. Print camera information. */ if (options_.isSet(OptListControls) || options_.isSet(OptListProperties) || options_.isSet(OptInfo)) { for (const auto &session : sessions) { if (options_.isSet(OptListControls)) session->listControls(); if (options_.isSet(OptListProperties)) session->listProperties(); if (options_.isSet(OptInfo)) session->infoConfiguration(); } } /* 4. Start capture. */ for (const auto &session : sessions) { if (!session->options().isSet(OptCapture)) continue; ret = session->start(); if (ret) { std::cout << "Failed to start camera session" << std::endl; return ret; } loopUsers_++; } /* 5. Enable hotplug monitoring. */ if (options_.isSet(OptMonitor)) { std::cout << "Monitoring new hotplug and unplug events" << std::endl; std::cout << "Press Ctrl-C to interrupt" << std::endl; cm_->cameraAdded.connect(this, &CamApp::cameraAdded); cm_->cameraRemoved.connect(this, &CamApp::cameraRemoved); loopUsers_++; } if (loopUsers_) loop_.exec(); /* 6. Stop capture. */ for (const auto &session : sessions) { if (!session->options().isSet(OptCapture)) continue; session->stop(); } return 0; } std::string CamApp::cameraName(const Camera *camera) { const ControlList &props = camera->properties(); bool addModel = true; std::string name; /* * Construct the name from the camera location, model and ID. The model * is only used if the location isn't present or is set to External. */ const auto &location = props.get(properties::Location); if (location) { switch (*location) { case properties::CameraLocationFront: addModel = false; name = "Internal front camera "; break; case properties::CameraLocationBack: addModel = false; name = "Internal back camera "; break; case properties::CameraLocationExternal: name = "External camera "; break; } } if (addModel) { /* * If the camera location is not availble use the camera model * to build the camera name. */ const auto &model = props.get(properties::Model); if (model) name = "'" + *model + "' "; } name += "(" + camera->id() + ")"; return name; } void signalHandler([[maybe_unused]] int signal) { std::cout << "Exiting" << std::endl; CamApp::instance()->quit(); } int main(int argc, char **argv) { CamApp app; int ret; ret = app.init(argc, argv); if (ret) return ret == -EINTR ? 0 : EXIT_FAILURE; struct sigaction sa = {}; sa.sa_handler = &signalHandler; sigaction(SIGINT, &sa, nullptr); if (app.exec()) return EXIT_FAILURE; return 0; }
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/sdl_texture.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2022, Ideas on Board Oy * * SDL Texture */ #pragma once #include <vector> #include <SDL2/SDL.h> #include "../common/image.h" class SDLTexture { public: SDLTexture(const SDL_Rect &rect, uint32_t pixelFormat, const int stride); virtual ~SDLTexture(); int create(SDL_Renderer *renderer); virtual void update(const std::vector<libcamera::Span<const uint8_t>> &data) = 0; SDL_Texture *get() const { return ptr_; } protected: SDL_Texture *ptr_; const SDL_Rect rect_; const uint32_t pixelFormat_; const int stride_; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/file_sink.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * File Sink */ #pragma once #include <map> #include <memory> #include <string> #include <libcamera/stream.h> #include "frame_sink.h" class Image; class FileSink : public FrameSink { public: FileSink(const libcamera::Camera *camera, const std::map<const libcamera::Stream *, std::string> &streamNames, const std::string &pattern = ""); ~FileSink(); int configure(const libcamera::CameraConfiguration &config) override; void mapBuffer(libcamera::FrameBuffer *buffer) override; bool processRequest(libcamera::Request *request) override; private: void writeBuffer(const libcamera::Stream *stream, libcamera::FrameBuffer *buffer, const libcamera::ControlList &metadata); #ifdef HAVE_TIFF const libcamera::Camera *camera_; #endif std::map<const libcamera::Stream *, std::string> streamNames_; std::string pattern_; std::map<libcamera::FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_; };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/main.h
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * Cam application */ #pragma once enum { OptCamera = 'c', OptCapture = 'C', OptDisplay = 'D', OptFile = 'F', OptHelp = 'h', OptInfo = 'I', OptList = 'l', OptListProperties = 'p', OptMonitor = 'm', OptOrientation = 'o', OptSDL = 'S', OptStream = 's', OptListControls = 256, OptStrictFormats = 257, OptMetadata = 258, OptCaptureScript = 259, };
0
repos/libcamera/src/apps
repos/libcamera/src/apps/cam/drm.cpp
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2021, Ideas on Board Oy * * DRM/KMS Helpers */ #include "drm.h" #include <algorithm> #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <iostream> #include <set> #include <string.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/types.h> #include <libcamera/framebuffer.h> #include <libcamera/geometry.h> #include <libcamera/pixel_format.h> #include <libdrm/drm_mode.h> #include "../common/event_loop.h" namespace DRM { Object::Object(Device *dev, uint32_t id, Type type) : id_(id), dev_(dev), type_(type) { /* Retrieve properties from the objects that support them. */ if (type != TypeConnector && type != TypeCrtc && type != TypeEncoder && type != TypePlane) return; /* * We can't distinguish between failures due to the object having no * property and failures due to other conditions. Assume we use the API * correctly and consider the object has no property. */ drmModeObjectProperties *properties = drmModeObjectGetProperties(dev->fd(), id, type); if (!properties) return; properties_.reserve(properties->count_props); for (uint32_t i = 0; i < properties->count_props; ++i) properties_.emplace_back(properties->props[i], properties->prop_values[i]); drmModeFreeObjectProperties(properties); } Object::~Object() { } const Property *Object::property(const std::string &name) const { for (const PropertyValue &pv : properties_) { const Property *property = static_cast<const Property *>(dev_->object(pv.id())); if (property && property->name() == name) return property; } return nullptr; } const PropertyValue *Object::propertyValue(const std::string &name) const { for (const PropertyValue &pv : properties_) { const Property *property = static_cast<const Property *>(dev_->object(pv.id())); if (property && property->name() == name) return &pv; } return nullptr; } Property::Property(Device *dev, drmModePropertyRes *property) : Object(dev, property->prop_id, TypeProperty), name_(property->name), flags_(property->flags), values_(property->values, property->values + property->count_values), blobs_(property->blob_ids, property->blob_ids + property->count_blobs) { if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) type_ = TypeRange; else if (drm_property_type_is(property, DRM_MODE_PROP_ENUM)) type_ = TypeEnum; else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) type_ = TypeBlob; else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) type_ = TypeBitmask; else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) type_ = TypeObject; else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) type_ = TypeSignedRange; else type_ = TypeUnknown; for (int i = 0; i < property->count_enums; ++i) enums_[property->enums[i].value] = property->enums[i].name; } Blob::Blob(Device *dev, const libcamera::Span<const uint8_t> &data) : Object(dev, 0, Object::TypeBlob) { drmModeCreatePropertyBlob(dev->fd(), data.data(), data.size(), &id_); } Blob::~Blob() { if (isValid()) drmModeDestroyPropertyBlob(device()->fd(), id()); } Mode::Mode(const drmModeModeInfo &mode) : drmModeModeInfo(mode) { } std::unique_ptr<Blob> Mode::toBlob(Device *dev) const { libcamera::Span<const uint8_t> data{ reinterpret_cast<const uint8_t *>(this), sizeof(*this) }; return std::make_unique<Blob>(dev, data); } Crtc::Crtc(Device *dev, const drmModeCrtc *crtc, unsigned int index) : Object(dev, crtc->crtc_id, Object::TypeCrtc), index_(index) { } Encoder::Encoder(Device *dev, const drmModeEncoder *encoder) : Object(dev, encoder->encoder_id, Object::TypeEncoder), type_(encoder->encoder_type) { const std::list<Crtc> &crtcs = dev->crtcs(); possibleCrtcs_.reserve(crtcs.size()); for (const Crtc &crtc : crtcs) { if (encoder->possible_crtcs & (1 << crtc.index())) possibleCrtcs_.push_back(&crtc); } possibleCrtcs_.shrink_to_fit(); } namespace { const std::map<uint32_t, const char *> connectorTypeNames{ { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, { DRM_MODE_CONNECTOR_VGA, "VGA" }, { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, { DRM_MODE_CONNECTOR_Composite, "Composite" }, { DRM_MODE_CONNECTOR_SVIDEO, "S-Video" }, { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, { DRM_MODE_CONNECTOR_Component, "Component" }, { DRM_MODE_CONNECTOR_9PinDIN, "9-Pin-DIN" }, { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, { DRM_MODE_CONNECTOR_TV, "TV" }, { DRM_MODE_CONNECTOR_eDP, "eDP" }, { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, { DRM_MODE_CONNECTOR_DSI, "DSI" }, { DRM_MODE_CONNECTOR_DPI, "DPI" }, }; } /* namespace */ Connector::Connector(Device *dev, const drmModeConnector *connector) : Object(dev, connector->connector_id, Object::TypeConnector), type_(connector->connector_type) { auto typeName = connectorTypeNames.find(connector->connector_type); if (typeName == connectorTypeNames.end()) { std::cerr << "Invalid connector type " << connector->connector_type << std::endl; typeName = connectorTypeNames.find(DRM_MODE_CONNECTOR_Unknown); } name_ = std::string(typeName->second) + "-" + std::to_string(connector->connector_type_id); switch (connector->connection) { case DRM_MODE_CONNECTED: status_ = Status::Connected; break; case DRM_MODE_DISCONNECTED: status_ = Status::Disconnected; break; case DRM_MODE_UNKNOWNCONNECTION: default: status_ = Status::Unknown; break; } const std::list<Encoder> &encoders = dev->encoders(); encoders_.reserve(connector->count_encoders); for (int i = 0; i < connector->count_encoders; ++i) { uint32_t encoderId = connector->encoders[i]; auto encoder = std::find_if(encoders.begin(), encoders.end(), [=](const Encoder &e) { return e.id() == encoderId; }); if (encoder == encoders.end()) { std::cerr << "Encoder " << encoderId << " not found" << std::endl; continue; } encoders_.push_back(&*encoder); } encoders_.shrink_to_fit(); modes_ = { connector->modes, connector->modes + connector->count_modes }; } Plane::Plane(Device *dev, const drmModePlane *plane) : Object(dev, plane->plane_id, Object::TypePlane), possibleCrtcsMask_(plane->possible_crtcs) { formats_ = { plane->formats, plane->formats + plane->count_formats }; const std::list<Crtc> &crtcs = dev->crtcs(); possibleCrtcs_.reserve(crtcs.size()); for (const Crtc &crtc : crtcs) { if (plane->possible_crtcs & (1 << crtc.index())) possibleCrtcs_.push_back(&crtc); } possibleCrtcs_.shrink_to_fit(); } bool Plane::supportsFormat(const libcamera::PixelFormat &format) const { return std::find(formats_.begin(), formats_.end(), format.fourcc()) != formats_.end(); } int Plane::setup() { const PropertyValue *pv = propertyValue("type"); if (!pv) return -EINVAL; switch (pv->value()) { case DRM_PLANE_TYPE_OVERLAY: type_ = TypeOverlay; break; case DRM_PLANE_TYPE_PRIMARY: type_ = TypePrimary; break; case DRM_PLANE_TYPE_CURSOR: type_ = TypeCursor; break; default: return -EINVAL; } return 0; } FrameBuffer::FrameBuffer(Device *dev) : Object(dev, 0, Object::TypeFb) { } FrameBuffer::~FrameBuffer() { for (const auto &plane : planes_) { struct drm_gem_close gem_close = { .handle = plane.second.handle, .pad = 0, }; int ret; do { ret = ioctl(device()->fd(), DRM_IOCTL_GEM_CLOSE, &gem_close); } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); if (ret == -1) { ret = -errno; std::cerr << "Failed to close GEM object: " << strerror(-ret) << std::endl; } } drmModeRmFB(device()->fd(), id()); } AtomicRequest::AtomicRequest(Device *dev) : dev_(dev), valid_(true) { request_ = drmModeAtomicAlloc(); if (!request_) valid_ = false; } AtomicRequest::~AtomicRequest() { if (request_) drmModeAtomicFree(request_); } int AtomicRequest::addProperty(const Object *object, const std::string &property, uint64_t value) { if (!valid_) return -EINVAL; const Property *prop = object->property(property); if (!prop) { valid_ = false; return -EINVAL; } return addProperty(object->id(), prop->id(), value); } int AtomicRequest::addProperty(const Object *object, const std::string &property, std::unique_ptr<Blob> blob) { if (!valid_) return -EINVAL; const Property *prop = object->property(property); if (!prop) { valid_ = false; return -EINVAL; } int ret = addProperty(object->id(), prop->id(), blob->id()); if (ret < 0) return ret; blobs_.emplace_back(std::move(blob)); return 0; } int AtomicRequest::addProperty(uint32_t object, uint32_t property, uint64_t value) { int ret = drmModeAtomicAddProperty(request_, object, property, value); if (ret < 0) { valid_ = false; return ret; } return 0; } int AtomicRequest::commit(unsigned int flags) { if (!valid_) return -EINVAL; uint32_t drmFlags = 0; if (flags & FlagAllowModeset) drmFlags |= DRM_MODE_ATOMIC_ALLOW_MODESET; if (flags & FlagAsync) drmFlags |= DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK; if (flags & FlagTestOnly) drmFlags |= DRM_MODE_ATOMIC_TEST_ONLY; return drmModeAtomicCommit(dev_->fd(), request_, drmFlags, this); } Device::Device() : fd_(-1) { } Device::~Device() { if (fd_ != -1) drmClose(fd_); } int Device::init() { int ret = openCard(); if (ret < 0) { std::cerr << "Failed to open any DRM/KMS device: " << strerror(-ret) << std::endl; return ret; } /* * Enable the atomic APIs. This also automatically enables the * universal planes API. */ ret = drmSetClientCap(fd_, DRM_CLIENT_CAP_ATOMIC, 1); if (ret < 0) { ret = -errno; std::cerr << "Failed to enable atomic capability: " << strerror(-ret) << std::endl; return ret; } /* List all the resources. */ ret = getResources(); if (ret < 0) return ret; EventLoop::instance()->addFdEvent(fd_, EventLoop::Read, std::bind(&Device::drmEvent, this)); return 0; } int Device::openCard() { const std::string dirName = "/dev/dri/"; bool found = false; int ret; /* * Open the first DRM/KMS device beginning with /dev/dri/card. The * libdrm drmOpen*() functions require either a module name or a bus ID, * which we don't have, so bypass them. The automatic module loading and * device node creation from drmOpen() is of no practical use as any * modern system will handle that through udev or an equivalent * component. */ DIR *folder = opendir(dirName.c_str()); if (!folder) { ret = -errno; std::cerr << "Failed to open " << dirName << " directory: " << strerror(-ret) << std::endl; return ret; } for (struct dirent *res; (res = readdir(folder));) { uint64_t cap; if (strncmp(res->d_name, "card", 4)) continue; const std::string devName = dirName + res->d_name; fd_ = open(devName.c_str(), O_RDWR | O_CLOEXEC); if (fd_ < 0) { ret = -errno; std::cerr << "Failed to open DRM/KMS device " << devName << ": " << strerror(-ret) << std::endl; continue; } /* * Skip devices that don't support the modeset API, to avoid * selecting a DRM device corresponding to a GPU. There is no * modeset capability, but the kernel returns an error for most * caps if mode setting isn't support by the driver. The * DRM_CAP_DUMB_BUFFER capability is one of those, other would * do as well. The capability value itself isn't relevant. */ ret = drmGetCap(fd_, DRM_CAP_DUMB_BUFFER, &cap); if (ret < 0) { drmClose(fd_); fd_ = -1; continue; } found = true; break; } closedir(folder); return found ? 0 : -ENOENT; } int Device::getResources() { int ret; std::unique_ptr<drmModeRes, decltype(&drmModeFreeResources)> resources{ drmModeGetResources(fd_), &drmModeFreeResources }; if (!resources) { ret = -errno; std::cerr << "Failed to get DRM/KMS resources: " << strerror(-ret) << std::endl; return ret; } for (int i = 0; i < resources->count_crtcs; ++i) { drmModeCrtc *crtc = drmModeGetCrtc(fd_, resources->crtcs[i]); if (!crtc) { ret = -errno; std::cerr << "Failed to get CRTC: " << strerror(-ret) << std::endl; return ret; } crtcs_.emplace_back(this, crtc, i); drmModeFreeCrtc(crtc); Crtc &obj = crtcs_.back(); objects_[obj.id()] = &obj; } for (int i = 0; i < resources->count_encoders; ++i) { drmModeEncoder *encoder = drmModeGetEncoder(fd_, resources->encoders[i]); if (!encoder) { ret = -errno; std::cerr << "Failed to get encoder: " << strerror(-ret) << std::endl; return ret; } encoders_.emplace_back(this, encoder); drmModeFreeEncoder(encoder); Encoder &obj = encoders_.back(); objects_[obj.id()] = &obj; } for (int i = 0; i < resources->count_connectors; ++i) { drmModeConnector *connector = drmModeGetConnector(fd_, resources->connectors[i]); if (!connector) { ret = -errno; std::cerr << "Failed to get connector: " << strerror(-ret) << std::endl; return ret; } connectors_.emplace_back(this, connector); drmModeFreeConnector(connector); Connector &obj = connectors_.back(); objects_[obj.id()] = &obj; } std::unique_ptr<drmModePlaneRes, decltype(&drmModeFreePlaneResources)> planes{ drmModeGetPlaneResources(fd_), &drmModeFreePlaneResources }; if (!planes) { ret = -errno; std::cerr << "Failed to get DRM/KMS planes: " << strerror(-ret) << std::endl; return ret; } for (uint32_t i = 0; i < planes->count_planes; ++i) { drmModePlane *plane = drmModeGetPlane(fd_, planes->planes[i]); if (!plane) { ret = -errno; std::cerr << "Failed to get plane: " << strerror(-ret) << std::endl; return ret; } planes_.emplace_back(this, plane); drmModeFreePlane(plane); Plane &obj = planes_.back(); objects_[obj.id()] = &obj; } /* Set the possible planes for each CRTC. */ for (Crtc &crtc : crtcs_) { for (const Plane &plane : planes_) { if (plane.possibleCrtcsMask_ & (1 << crtc.index())) crtc.planes_.push_back(&plane); } } /* Collect all property IDs and create Property instances. */ std::set<uint32_t> properties; for (const auto &object : objects_) { for (const PropertyValue &value : object.second->properties()) properties.insert(value.id()); } for (uint32_t id : properties) { drmModePropertyRes *property = drmModeGetProperty(fd_, id); if (!property) { ret = -errno; std::cerr << "Failed to get property: " << strerror(-ret) << std::endl; continue; } properties_.emplace_back(this, property); drmModeFreeProperty(property); Property &obj = properties_.back(); objects_[obj.id()] = &obj; } /* Finally, perform all delayed setup of mode objects. */ for (auto &object : objects_) { ret = object.second->setup(); if (ret < 0) { std::cerr << "Failed to setup object " << object.second->id() << ": " << strerror(-ret) << std::endl; return ret; } } return 0; } const Object *Device::object(uint32_t id) { const auto iter = objects_.find(id); if (iter == objects_.end()) return nullptr; return iter->second; } std::unique_ptr<FrameBuffer> Device::createFrameBuffer( const libcamera::FrameBuffer &buffer, const libcamera::PixelFormat &format, const libcamera::Size &size, const std::array<uint32_t, 4> &strides) { std::unique_ptr<FrameBuffer> fb{ new FrameBuffer(this) }; uint32_t handles[4] = {}; uint32_t offsets[4] = {}; int ret; const std::vector<libcamera::FrameBuffer::Plane> &planes = buffer.planes(); unsigned int i = 0; for (const libcamera::FrameBuffer::Plane &plane : planes) { int fd = plane.fd.get(); uint32_t handle; auto iter = fb->planes_.find(fd); if (iter == fb->planes_.end()) { ret = drmPrimeFDToHandle(fd_, plane.fd.get(), &handle); if (ret < 0) { ret = -errno; std::cerr << "Unable to import framebuffer dmabuf: " << strerror(-ret) << std::endl; return nullptr; } fb->planes_[fd] = { handle }; } else { handle = iter->second.handle; } handles[i] = handle; offsets[i] = plane.offset; ++i; } ret = drmModeAddFB2(fd_, size.width, size.height, format.fourcc(), handles, strides.data(), offsets, &fb->id_, 0); if (ret < 0) { ret = -errno; std::cerr << "Failed to add framebuffer: " << strerror(-ret) << std::endl; return nullptr; } return fb; } void Device::drmEvent() { drmEventContext ctx{}; ctx.version = DRM_EVENT_CONTEXT_VERSION; ctx.page_flip_handler = &Device::pageFlipComplete; drmHandleEvent(fd_, &ctx); } void Device::pageFlipComplete([[maybe_unused]] int fd, [[maybe_unused]] unsigned int sequence, [[maybe_unused]] unsigned int tv_sec, [[maybe_unused]] unsigned int tv_usec, void *user_data) { AtomicRequest *request = static_cast<AtomicRequest *>(user_data); request->device()->requestComplete.emit(request); } } /* namespace DRM */
0
repos/libcamera/src
repos/libcamera/src/ipa/ipa-sign-install.sh
#!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2020, Google Inc. # # Author: Laurent Pinchart <[email protected]> # # Regenerate IPA module signatures when installing key=$1 shift modules=$* ipa_sign=$(dirname "$0")/ipa-sign.sh echo "Regenerating IPA modules signatures" for module in ${modules} ; do module="${MESON_INSTALL_DESTDIR_PREFIX}/${module}" if [ -f "${module}" ] ; then "${ipa_sign}" "${key}" "${module}" "${module}.sign" fi done
0
repos/libcamera/src
repos/libcamera/src/ipa/ipa-sign.sh
#!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2020, Google Inc. # # Author: Laurent Pinchart <[email protected]> # # Generate a signature for an IPA module key="$1" input="$2" output="$3" openssl dgst -sha256 -sign "${key}" -out "${output}" "${input}"
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/ipu3/ipa_context.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google Inc. * * IPU3 IPA Context * */ #pragma once #include <linux/intel-ipu3.h> #include <libcamera/base/utils.h> #include <libcamera/controls.h> #include <libcamera/geometry.h> #include <libipa/fc_queue.h> namespace libcamera { namespace ipa::ipu3 { struct IPASessionConfiguration { struct { ipu3_uapi_grid_config bdsGrid; Size bdsOutputSize; uint32_t stride; } grid; struct { ipu3_uapi_grid_config afGrid; } af; struct { utils::Duration minShutterSpeed; utils::Duration maxShutterSpeed; double minAnalogueGain; double maxAnalogueGain; } agc; struct { int32_t defVBlank; utils::Duration lineDuration; Size size; } sensor; }; struct IPAActiveState { struct { uint32_t focus; double maxVariance; bool stable; } af; struct { uint32_t exposure; double gain; uint32_t constraintMode; uint32_t exposureMode; } agc; struct { struct { double red; double green; double blue; } gains; double temperatureK; } awb; struct { double gamma; struct ipu3_uapi_gamma_corr_lut gammaCorrection; } toneMapping; }; struct IPAFrameContext : public FrameContext { struct { uint32_t exposure; double gain; } sensor; }; struct IPAContext { IPASessionConfiguration configuration; IPAActiveState activeState; FCQueue<IPAFrameContext> frameContexts; ControlInfoMap::Map ctrlMap; }; } /* namespace ipa::ipu3 */ } /* namespace libcamera*/
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/ipu3/module.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2022, Ideas On Board * * IPU3 IPA Module */ #pragma once #include <linux/intel-ipu3.h> #include <libcamera/ipa/ipu3_ipa_interface.h> #include <libipa/module.h> #include "ipa_context.h" namespace libcamera { namespace ipa::ipu3 { using Module = ipa::Module<IPAContext, IPAFrameContext, IPAConfigInfo, ipu3_uapi_params, ipu3_uapi_stats_3a>; } /* namespace ipa::ipu3 */ } /* namespace libcamera*/
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/ipu3/ipa_context.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google Inc. * * IPU3 IPA Context */ #include "ipa_context.h" /** * \file ipa_context.h * \brief Context and state information shared between the algorithms */ namespace libcamera::ipa::ipu3 { /** * \struct IPASessionConfiguration * \brief Session configuration for the IPA module * * The session configuration contains all IPA configuration parameters that * remain constant during the capture session, from IPA module start to stop. * It is typically set during the configure() operation of the IPA module, but * may also be updated in the start() operation. */ /** * \struct IPAActiveState * \brief The active state of the IPA algorithms * * The IPA is fed with the statistics generated from the latest frame captured * by the hardware. The statistics are then processed by the IPA algorithms to * compute ISP parameters required for the next frame capture. The current state * of the algorithms is reflected through the IPAActiveState to store the values * most recently computed by the IPA algorithms. */ /** * \struct IPAContext * \brief Global IPA context data shared between all algorithms * * \var IPAContext::configuration * \brief The IPA session configuration, immutable during the session * * \var IPAContext::frameContexts * \brief Ring buffer of the IPAFrameContext(s) * * \var IPAContext::activeState * \brief The current state of IPA algorithms * * \var IPAContext::ctrlMap * \brief A ControlInfoMap::Map of controls populated by the algorithms */ /** * \var IPASessionConfiguration::grid * \brief Grid configuration of the IPA * * \var IPASessionConfiguration::grid.bdsGrid * \brief Bayer Down Scaler grid plane config used by the kernel * * \var IPASessionConfiguration::grid.bdsOutputSize * \brief BDS output size configured by the pipeline handler * * \var IPASessionConfiguration::grid.stride * \brief Number of cells on one line including the ImgU padding */ /** * \var IPASessionConfiguration::af * \brief AF grid configuration of the IPA * * \var IPASessionConfiguration::af.afGrid * \brief AF scene grid configuration */ /** * \var IPAActiveState::af * \brief Context for the Automatic Focus algorithm * * \var IPAActiveState::af.focus * \brief Current position of the lens * * \var IPAActiveState::af.maxVariance * \brief The maximum variance of the current image * * \var IPAActiveState::af.stable * \brief It is set to true, if the best focus is found */ /** * \var IPASessionConfiguration::agc * \brief AGC parameters configuration of the IPA * * \var IPASessionConfiguration::agc.minShutterSpeed * \brief Minimum shutter speed supported with the configured sensor * * \var IPASessionConfiguration::agc.maxShutterSpeed * \brief Maximum shutter speed supported with the configured sensor * * \var IPASessionConfiguration::agc.minAnalogueGain * \brief Minimum analogue gain supported with the configured sensor * * \var IPASessionConfiguration::agc.maxAnalogueGain * \brief Maximum analogue gain supported with the configured sensor */ /** * \var IPASessionConfiguration::sensor * \brief Sensor-specific configuration of the IPA * * \var IPASessionConfiguration::sensor.lineDuration * \brief Line duration in microseconds * * \var IPASessionConfiguration::sensor.defVBlank * \brief The default vblank value of the sensor * * \var IPASessionConfiguration::sensor.size * \brief Sensor output resolution */ /** * \var IPAActiveState::agc * \brief Context for the Automatic Gain Control algorithm * * The exposure and gain determined are expected to be applied to the sensor * at the earliest opportunity. * * \var IPAActiveState::agc.exposure * \brief Exposure time expressed as a number of lines * * \var IPAActiveState::agc.gain * \brief Analogue gain multiplier * * The gain should be adapted to the sensor specific gain code before applying. */ /** * \var IPAActiveState::awb * \brief Context for the Automatic White Balance algorithm * * \var IPAActiveState::awb.gains * \brief White balance gains * * \var IPAActiveState::awb.gains.red * \brief White balance gain for R channel * * \var IPAActiveState::awb.gains.green * \brief White balance gain for G channel * * \var IPAActiveState::awb.gains.blue * \brief White balance gain for B channel * * \var IPAActiveState::awb.temperatureK * \brief Estimated color temperature */ /** * \var IPAActiveState::toneMapping * \brief Context for ToneMapping and Gamma control * * \var IPAActiveState::toneMapping.gamma * \brief Gamma value for the LUT * * \var IPAActiveState::toneMapping.gammaCorrection * \brief Per-pixel tone mapping implemented as a LUT * * The LUT structure is defined by the IPU3 kernel interface. See * <linux/intel-ipu3.h> struct ipu3_uapi_gamma_corr_lut for further details. */ /** * \struct IPAFrameContext * \brief IPU3-specific FrameContext * * \var IPAFrameContext::sensor * \brief Effective sensor values that were applied for the frame * * \var IPAFrameContext::sensor.exposure * \brief Exposure time expressed as a number of lines * * \var IPAFrameContext::sensor.gain * \brief Analogue gain multiplier */ } /* namespace libcamera::ipa::ipu3 */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/ipu3/ipu3.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Google Inc. * * IPU3 Image Processing Algorithms */ #include <algorithm> #include <array> #include <cmath> #include <limits> #include <map> #include <memory> #include <stdint.h> #include <utility> #include <vector> #include <linux/intel-ipu3.h> #include <linux/v4l2-controls.h> #include <libcamera/base/file.h> #include <libcamera/base/log.h> #include <libcamera/base/utils.h> #include <libcamera/control_ids.h> #include <libcamera/framebuffer.h> #include <libcamera/ipa/ipa_interface.h> #include <libcamera/ipa/ipa_module_info.h> #include <libcamera/ipa/ipu3_ipa_interface.h> #include <libcamera/request.h> #include "libcamera/internal/mapped_framebuffer.h" #include "libcamera/internal/yaml_parser.h" #include "algorithms/af.h" #include "algorithms/agc.h" #include "algorithms/algorithm.h" #include "algorithms/awb.h" #include "algorithms/blc.h" #include "algorithms/tone_mapping.h" #include "libipa/camera_sensor_helper.h" #include "ipa_context.h" /* Minimum grid width, expressed as a number of cells */ static constexpr uint32_t kMinGridWidth = 16; /* Maximum grid width, expressed as a number of cells */ static constexpr uint32_t kMaxGridWidth = 80; /* Minimum grid height, expressed as a number of cells */ static constexpr uint32_t kMinGridHeight = 16; /* Maximum grid height, expressed as a number of cells */ static constexpr uint32_t kMaxGridHeight = 60; /* log2 of the minimum grid cell width and height, in pixels */ static constexpr uint32_t kMinCellSizeLog2 = 3; /* log2 of the maximum grid cell width and height, in pixels */ static constexpr uint32_t kMaxCellSizeLog2 = 6; /* Maximum number of frame contexts to be held */ static constexpr uint32_t kMaxFrameContexts = 16; namespace libcamera { LOG_DEFINE_CATEGORY(IPAIPU3) using namespace std::literals::chrono_literals; namespace ipa::ipu3 { /** * \brief The IPU3 IPA implementation * * The IPU3 Pipeline defines an IPU3-specific interface for communication * between the PipelineHandler and the IPA module. * * We extend the IPAIPU3Interface to implement our algorithms and handle * calls from the IPU3 PipelineHandler to satisfy requests from the * application. * * At initialisation time, a CameraSensorHelper is instantiated to support * camera-specific calculations, while the default controls are computed, and * the algorithms are instantiated from the tuning data file. * * The IPU3 ImgU operates with a grid layout to divide the overall frame into * rectangular cells of pixels. When the IPA is configured, we determine the * best grid for the statistics based on the pipeline handler Bayer Down Scaler * output size. * * Two main events are then handled to operate the IPU3 ImgU by populating its * parameter buffer, and adapting the settings of the sensor attached to the * IPU3 CIO2 through sensor-specific V4L2 controls. * * In fillParamsBuffer(), we populate the ImgU parameter buffer with * settings to configure the device in preparation for handling the frame * queued in the Request. * * When the frame has completed processing, the ImgU will generate a statistics * buffer which is given to the IPA with processStatsBuffer(). In this we run the * algorithms to parse the statistics and cache any results for the next * fillParamsBuffer() call. * * The individual algorithms are split into modular components that are called * iteratively to allow them to process statistics from the ImgU in the order * defined in the tuning data file. * * The current implementation supports five core algorithms: * * - Auto focus (AF) * - Automatic gain and exposure control (AGC) * - Automatic white balance (AWB) * - Black level correction (BLC) * - Tone mapping (Gamma) * * AWB is implemented using a Greyworld algorithm, and calculates the red and * blue gains to apply to generate a neutral grey frame overall. * * AGC is handled by calculating a histogram of the green channel to estimate an * analogue gain and shutter time which will provide a well exposed frame. A * low-pass IIR filter is used to smooth the changes to the sensor to reduce * perceivable steps. * * The tone mapping algorithm provides a gamma correction table to improve the * contrast of the scene. * * The black level compensation algorithm subtracts a hardcoded black level from * all pixels. * * The IPU3 ImgU has further processing blocks to support image quality * improvements through bayer and temporal noise reductions, however those are * not supported in the current implementation, and will use default settings as * provided by the kernel driver. * * Demosaicing is operating with the default parameters and could be further * optimised to provide improved sharpening coefficients, checker artifact * removal, and false color correction. * * Additional image enhancements can be made by providing lens and * sensor-specific tuning to adapt for Black Level compensation (BLC), Lens * shading correction (SHD) and Color correction (CCM). */ class IPAIPU3 : public IPAIPU3Interface, public Module { public: IPAIPU3(); int init(const IPASettings &settings, const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls) override; int start() override; void stop() override; int configure(const IPAConfigInfo &configInfo, ControlInfoMap *ipaControls) override; void mapBuffers(const std::vector<IPABuffer> &buffers) override; void unmapBuffers(const std::vector<unsigned int> &ids) override; void queueRequest(const uint32_t frame, const ControlList &controls) override; void fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) override; void processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, const uint32_t bufferId, const ControlList &sensorControls) override; protected: std::string logPrefix() const override; private: void updateControls(const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls); void updateSessionConfiguration(const ControlInfoMap &sensorControls); void setControls(unsigned int frame); void calculateBdsGrid(const Size &bdsOutputSize); std::map<unsigned int, MappedFrameBuffer> buffers_; ControlInfoMap sensorCtrls_; ControlInfoMap lensCtrls_; IPACameraSensorInfo sensorInfo_; /* Interface to the Camera Helper */ std::unique_ptr<CameraSensorHelper> camHelper_; /* Local parameter storage */ struct IPAContext context_; }; IPAIPU3::IPAIPU3() : context_({ {}, {}, { kMaxFrameContexts }, {} }) { } std::string IPAIPU3::logPrefix() const { return "ipu3"; } /** * \brief Compute IPASessionConfiguration using the sensor information and the * sensor V4L2 controls */ void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls) { const ControlInfo vBlank = sensorControls.find(V4L2_CID_VBLANK)->second; context_.configuration.sensor.defVBlank = vBlank.def().get<int32_t>(); const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second; int32_t minExposure = v4l2Exposure.min().get<int32_t>(); int32_t maxExposure = v4l2Exposure.max().get<int32_t>(); const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second; int32_t minGain = v4l2Gain.min().get<int32_t>(); int32_t maxGain = v4l2Gain.max().get<int32_t>(); /* * When the AGC computes the new exposure values for a frame, it needs * to know the limits for shutter speed and analogue gain. * As it depends on the sensor, update it with the controls. * * \todo take VBLANK into account for maximum shutter speed */ context_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration; context_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration; context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain); context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain); } /** * \brief Compute camera controls using the sensor information and the sensor * V4L2 controls * * Some of the camera controls are computed by the pipeline handler, some others * by the IPA module which is in charge of handling, for example, the exposure * time and the frame duration. * * This function computes: * - controls::ExposureTime * - controls::FrameDurationLimits */ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls) { ControlInfoMap::Map controls{}; double lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>(); /* * Compute exposure time limits by using line length and pixel rate * converted to microseconds. Use the V4L2_CID_EXPOSURE control to get * exposure min, max and default and convert it from lines to * microseconds. */ const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second; int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration; int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration; int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration; controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure, defExposure); /* * Compute the frame duration limits. * * The frame length is computed assuming a fixed line length combined * with the vertical frame sizes. */ const ControlInfo &v4l2HBlank = sensorControls.find(V4L2_CID_HBLANK)->second; uint32_t hblank = v4l2HBlank.def().get<int32_t>(); uint32_t lineLength = sensorInfo.outputSize.width + hblank; const ControlInfo &v4l2VBlank = sensorControls.find(V4L2_CID_VBLANK)->second; std::array<uint32_t, 3> frameHeights{ v4l2VBlank.min().get<int32_t>() + sensorInfo.outputSize.height, v4l2VBlank.max().get<int32_t>() + sensorInfo.outputSize.height, v4l2VBlank.def().get<int32_t>() + sensorInfo.outputSize.height, }; std::array<int64_t, 3> frameDurations; for (unsigned int i = 0; i < frameHeights.size(); ++i) { uint64_t frameSize = lineLength * frameHeights[i]; frameDurations[i] = frameSize / (sensorInfo.pixelRate / 1000000U); } controls[&controls::FrameDurationLimits] = ControlInfo(frameDurations[0], frameDurations[1], frameDurations[2]); controls.merge(context_.ctrlMap); *ipaControls = ControlInfoMap(std::move(controls), controls::controls); } /** * \brief Initialize the IPA module and its controls * * This function receives the camera sensor information from the pipeline * handler, computes the limits of the controls it handles and returns * them in the \a ipaControls output parameter. */ int IPAIPU3::init(const IPASettings &settings, const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls) { camHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel); if (camHelper_ == nullptr) { LOG(IPAIPU3, Error) << "Failed to create camera sensor helper for " << settings.sensorModel; return -ENODEV; } /* Clean context */ context_.configuration = {}; context_.configuration.sensor.lineDuration = sensorInfo.minLineLength * 1.0s / sensorInfo.pixelRate; /* Load the tuning data file. */ File file(settings.configurationFile); if (!file.open(File::OpenModeFlag::ReadOnly)) { int ret = file.error(); LOG(IPAIPU3, Error) << "Failed to open configuration file " << settings.configurationFile << ": " << strerror(-ret); return ret; } std::unique_ptr<libcamera::YamlObject> data = YamlParser::parse(file); if (!data) return -EINVAL; unsigned int version = (*data)["version"].get<uint32_t>(0); if (version != 1) { LOG(IPAIPU3, Error) << "Invalid tuning file version " << version; return -EINVAL; } if (!data->contains("algorithms")) { LOG(IPAIPU3, Error) << "Tuning file doesn't contain any algorithm"; return -EINVAL; } int ret = createAlgorithms(context_, (*data)["algorithms"]); if (ret) return ret; /* Initialize controls. */ updateControls(sensorInfo, sensorControls, ipaControls); return 0; } /** * \brief Perform any processing required before the first frame */ int IPAIPU3::start() { /* * Set the sensors V4L2 controls before the first frame to ensure that * we have an expected and known configuration from the start. */ setControls(0); return 0; } /** * \brief Ensure that all processing has completed */ void IPAIPU3::stop() { context_.frameContexts.clear(); } /** * \brief Calculate a grid for the AWB statistics * * This function calculates a grid for the AWB algorithm in the IPU3 firmware. * Its input is the BDS output size calculated in the ImgU. * It is limited for now to the simplest method: find the lesser error * with the width/height and respective log2 width/height of the cells. * * \todo The frame is divided into cells which can be 8x8 => 64x64. * As a smaller cell improves the algorithm precision, adapting the * x_start and y_start parameters of the grid would provoke a loss of * some pixels but would also result in more accurate algorithms. */ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize) { Size best; Size bestLog2; /* Set the BDS output size in the IPAConfiguration structure */ context_.configuration.grid.bdsOutputSize = bdsOutputSize; uint32_t minError = std::numeric_limits<uint32_t>::max(); for (uint32_t shift = kMinCellSizeLog2; shift <= kMaxCellSizeLog2; ++shift) { uint32_t width = std::clamp(bdsOutputSize.width >> shift, kMinGridWidth, kMaxGridWidth); width = width << shift; uint32_t error = utils::abs_diff(width, bdsOutputSize.width); if (error >= minError) continue; minError = error; best.width = width; bestLog2.width = shift; } minError = std::numeric_limits<uint32_t>::max(); for (uint32_t shift = kMinCellSizeLog2; shift <= kMaxCellSizeLog2; ++shift) { uint32_t height = std::clamp(bdsOutputSize.height >> shift, kMinGridHeight, kMaxGridHeight); height = height << shift; uint32_t error = utils::abs_diff(height, bdsOutputSize.height); if (error >= minError) continue; minError = error; best.height = height; bestLog2.height = shift; } struct ipu3_uapi_grid_config &bdsGrid = context_.configuration.grid.bdsGrid; bdsGrid.x_start = 0; bdsGrid.y_start = 0; bdsGrid.width = best.width >> bestLog2.width; bdsGrid.block_width_log2 = bestLog2.width; bdsGrid.height = best.height >> bestLog2.height; bdsGrid.block_height_log2 = bestLog2.height; /* The ImgU pads the lines to a multiple of 4 cells. */ context_.configuration.grid.stride = utils::alignUp(bdsGrid.width, 4); LOG(IPAIPU3, Debug) << "Best grid found is: (" << (int)bdsGrid.width << " << " << (int)bdsGrid.block_width_log2 << ") x (" << (int)bdsGrid.height << " << " << (int)bdsGrid.block_height_log2 << ")"; } /** * \brief Configure the IPU3 IPA * \param[in] configInfo The IPA configuration data, received from the pipeline * handler * \param[in] ipaControls The IPA controls to update * * Calculate the best grid for the statistics based on the pipeline handler BDS * output, and parse the minimum and maximum exposure and analogue gain control * values. * * \todo Document what the BDS is, ideally in a block diagram of the ImgU. * * All algorithm modules are called to allow them to prepare the * \a IPASessionConfiguration structure for the \a IPAContext. */ int IPAIPU3::configure(const IPAConfigInfo &configInfo, ControlInfoMap *ipaControls) { if (configInfo.sensorControls.empty()) { LOG(IPAIPU3, Error) << "No sensor controls provided"; return -ENODATA; } sensorInfo_ = configInfo.sensorInfo; lensCtrls_ = configInfo.lensControls; /* Clear the IPA context for the new streaming session. */ context_.activeState = {}; context_.configuration = {}; context_.frameContexts.clear(); /* Initialise the sensor configuration. */ context_.configuration.sensor.lineDuration = sensorInfo_.minLineLength * 1.0s / sensorInfo_.pixelRate; context_.configuration.sensor.size = sensorInfo_.outputSize; /* * Compute the sensor V4L2 controls to be used by the algorithms and * to be set on the sensor. */ sensorCtrls_ = configInfo.sensorControls; calculateBdsGrid(configInfo.bdsOutputSize); /* Update the camera controls using the new sensor settings. */ updateControls(sensorInfo_, sensorCtrls_, ipaControls); /* Update the IPASessionConfiguration using the sensor settings. */ updateSessionConfiguration(sensorCtrls_); for (auto const &algo : algorithms()) { int ret = algo->configure(context_, configInfo); if (ret) return ret; } return 0; } /** * \brief Map the parameters and stats buffers allocated in the pipeline handler * \param[in] buffers The buffers to map */ void IPAIPU3::mapBuffers(const std::vector<IPABuffer> &buffers) { for (const IPABuffer &buffer : buffers) { const FrameBuffer fb(buffer.planes); buffers_.emplace(buffer.id, MappedFrameBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite)); } } /** * \brief Unmap the parameters and stats buffers * \param[in] ids The IDs of the buffers to unmap */ void IPAIPU3::unmapBuffers(const std::vector<unsigned int> &ids) { for (unsigned int id : ids) { auto it = buffers_.find(id); if (it == buffers_.end()) continue; buffers_.erase(it); } } /** * \brief Fill and return a buffer with ISP processing parameters for a frame * \param[in] frame The frame number * \param[in] bufferId ID of the parameter buffer to fill * * Algorithms are expected to fill the IPU3 parameter buffer for the next * frame given their most recent processing of the ImgU statistics. */ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) { auto it = buffers_.find(bufferId); if (it == buffers_.end()) { LOG(IPAIPU3, Error) << "Could not find param buffer!"; return; } Span<uint8_t> mem = it->second.planes()[0]; ipu3_uapi_params *params = reinterpret_cast<ipu3_uapi_params *>(mem.data()); /* * The incoming params buffer may contain uninitialised data, or the * parameters of previously queued frames. Clearing the entire buffer * may be an expensive operation, and the kernel will only read from * structures which have their associated use-flag set. * * It is the responsibility of the algorithms to set the use flags * accordingly for any data structure they update during prepare(). */ params->use = {}; IPAFrameContext &frameContext = context_.frameContexts.get(frame); for (auto const &algo : algorithms()) algo->prepare(context_, frame, frameContext, params); paramsBufferReady.emit(frame); } /** * \brief Process the statistics generated by the ImgU * \param[in] frame The frame number * \param[in] frameTimestamp Timestamp of the frame * \param[in] bufferId ID of the statistics buffer * \param[in] sensorControls Sensor controls * * Parse the most recently processed image statistics from the ImgU. The * statistics are passed to each algorithm module to run their calculations and * update their state accordingly. */ void IPAIPU3::processStatsBuffer(const uint32_t frame, [[maybe_unused]] const int64_t frameTimestamp, const uint32_t bufferId, const ControlList &sensorControls) { auto it = buffers_.find(bufferId); if (it == buffers_.end()) { LOG(IPAIPU3, Error) << "Could not find stats buffer!"; return; } Span<uint8_t> mem = it->second.planes()[0]; const ipu3_uapi_stats_3a *stats = reinterpret_cast<ipu3_uapi_stats_3a *>(mem.data()); IPAFrameContext &frameContext = context_.frameContexts.get(frame); frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>(); frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>()); ControlList metadata(controls::controls); for (auto const &algo : algorithms()) algo->process(context_, frame, frameContext, stats, metadata); setControls(frame); /* * \todo The Metadata provides a path to getting extended data * out to the application. Further data such as a simplifed Histogram * might have value to be exposed, however such data may be * difficult to report in a generically parsable way and we * likely want to avoid putting platform specific metadata in. */ metadataReady.emit(frame, metadata); } /** * \brief Queue a request and process the control list from the application * \param[in] frame The number of the frame which will be processed next * \param[in] controls The controls for the \a frame * * Parse the request to handle any IPA-managed controls that were set from the * application such as manual sensor settings. */ void IPAIPU3::queueRequest(const uint32_t frame, const ControlList &controls) { IPAFrameContext &frameContext = context_.frameContexts.alloc(frame); for (auto const &algo : algorithms()) algo->queueRequest(context_, frame, frameContext, controls); } /** * \brief Handle sensor controls for a given \a frame number * \param[in] frame The frame on which the sensor controls should be set * * Send the desired sensor control values to the pipeline handler to request * that they are applied on the camera sensor. */ void IPAIPU3::setControls(unsigned int frame) { int32_t exposure = context_.activeState.agc.exposure; int32_t gain = camHelper_->gainCode(context_.activeState.agc.gain); ControlList ctrls(sensorCtrls_); ctrls.set(V4L2_CID_EXPOSURE, exposure); ctrls.set(V4L2_CID_ANALOGUE_GAIN, gain); ControlList lensCtrls(lensCtrls_); lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast<int32_t>(context_.activeState.af.focus)); setSensorControls.emit(frame, ctrls, lensCtrls); } } /* namespace ipa::ipu3 */ /** * \brief External IPA module interface * * The IPAModuleInfo is required to match an IPA module construction against the * intented pipeline handler with the module. The API and pipeline handler * versions must match the corresponding IPA interface and pipeline handler. * * \sa struct IPAModuleInfo */ extern "C" { const struct IPAModuleInfo ipaModuleInfo = { IPA_MODULE_API_VERSION, 1, "ipu3", "ipu3", }; /** * \brief Create an instance of the IPA interface * * This function is the entry point of the IPA module. It is called by the IPA * manager to create an instance of the IPA interface for each camera. When * matched against with a pipeline handler, the IPAManager will construct an IPA * instance for each associated Camera. */ IPAInterface *ipaCreate() { return new ipa::ipu3::IPAIPU3(); } } } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/data/uncalibrated.yaml
# SPDX-License-Identifier: CC0-1.0 %YAML 1.1 --- version: 1 algorithms: - Af: - Agc: - Awb: - BlackLevelCorrection: - ToneMapping: ...
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/af.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Red Hat * * IPU3 auto focus algorithm */ #include "af.h" #include <algorithm> #include <chrono> #include <cmath> #include <fcntl.h> #include <numeric> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <linux/videodev2.h> #include <libcamera/base/log.h> #include <libcamera/ipa/core_ipa_interface.h> #include "libipa/histogram.h" /** * \file af.h */ /* * Static variables from ChromiumOS Intel Camera HAL and ia_imaging library: * - https://chromium.googlesource.com/chromiumos/platform/arc-camera/+/master/hal/intel/psl/ipu3/statsConverter/ipu3-stats.h * - https://chromium.googlesource.com/chromiumos/platform/camera/+/refs/heads/main/hal/intel/ipu3/include/ia_imaging/af_public.h */ /** The minimum horizontal grid dimension. */ static constexpr uint8_t kAfMinGridWidth = 16; /** The minimum vertical grid dimension. */ static constexpr uint8_t kAfMinGridHeight = 16; /** The maximum horizontal grid dimension. */ static constexpr uint8_t kAfMaxGridWidth = 32; /** The maximum vertical grid dimension. */ static constexpr uint8_t kAfMaxGridHeight = 24; /** The minimum value of Log2 of the width of the grid cell. */ static constexpr uint16_t kAfMinGridBlockWidth = 4; /** The minimum value of Log2 of the height of the grid cell. */ static constexpr uint16_t kAfMinGridBlockHeight = 3; /** The maximum value of Log2 of the width of the grid cell. */ static constexpr uint16_t kAfMaxGridBlockWidth = 6; /** The maximum value of Log2 of the height of the grid cell. */ static constexpr uint16_t kAfMaxGridBlockHeight = 6; /** The number of blocks in vertical axis per slice. */ static constexpr uint16_t kAfDefaultHeightPerSlice = 2; namespace libcamera { using namespace std::literals::chrono_literals; namespace ipa::ipu3::algorithms { LOG_DEFINE_CATEGORY(IPU3Af) /** * Maximum focus steps of the VCM control * \todo should be obtained from the VCM driver */ static constexpr uint32_t kMaxFocusSteps = 1023; /* Minimum focus step for searching appropriate focus */ static constexpr uint32_t kCoarseSearchStep = 30; static constexpr uint32_t kFineSearchStep = 1; /* Max ratio of variance change, 0.0 < kMaxChange < 1.0 */ static constexpr double kMaxChange = 0.5; /* The numbers of frame to be ignored, before performing focus scan. */ static constexpr uint32_t kIgnoreFrame = 10; /* Fine scan range 0 < kFineRange < 1 */ static constexpr double kFineRange = 0.05; /* Settings for IPU3 AF filter */ static struct ipu3_uapi_af_filter_config afFilterConfigDefault = { .y1_coeff_0 = { 0, 1, 3, 7 }, .y1_coeff_1 = { 11, 13, 1, 2 }, .y1_coeff_2 = { 8, 19, 34, 242 }, .y1_sign_vec = 0x7fdffbfe, .y2_coeff_0 = { 0, 1, 6, 6 }, .y2_coeff_1 = { 13, 25, 3, 0 }, .y2_coeff_2 = { 25, 3, 177, 254 }, .y2_sign_vec = 0x4e53ca72, .y_calc = { 8, 8, 8, 8 }, .nf = { 0, 9, 0, 9, 0 }, }; /** * \class Af * \brief An auto-focus algorithm based on IPU3 statistics * * This algorithm is used to determine the position of the lens to make a * focused image. The IPU3 AF processing block computes the statistics that * are composed by two types of filtered value and stores in a AF buffer. * Typically, for a clear image, it has a relatively higher contrast than a * blurred one. Therefore, if an image with the highest contrast can be * found through the scan, the position of the len indicates to a clearest * image. */ Af::Af() : focus_(0), bestFocus_(0), currentVariance_(0.0), previousVariance_(0.0), coarseCompleted_(false), fineCompleted_(false) { } /** * \brief Configure the Af given a configInfo * \param[in] context The shared IPA context * \param[in] configInfo The IPA configuration data * \return 0 on success, a negative error code otherwise */ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo) { struct ipu3_uapi_grid_config &grid = context.configuration.af.afGrid; grid.width = kAfMinGridWidth; grid.height = kAfMinGridHeight; grid.block_width_log2 = kAfMinGridBlockWidth; grid.block_height_log2 = kAfMinGridBlockHeight; /* * \todo - while this clamping code is effectively a no-op, it satisfies * the compiler that the constant definitions of the hardware limits * are used, and paves the way to support dynamic grid sizing in the * future. While the block_{width,height}_log2 remain assigned to the * minimum, this code should be optimized out by the compiler. */ grid.width = std::clamp(grid.width, kAfMinGridWidth, kAfMaxGridWidth); grid.height = std::clamp(grid.height, kAfMinGridHeight, kAfMaxGridHeight); grid.block_width_log2 = std::clamp(grid.block_width_log2, kAfMinGridBlockWidth, kAfMaxGridBlockWidth); grid.block_height_log2 = std::clamp(grid.block_height_log2, kAfMinGridBlockHeight, kAfMaxGridBlockHeight); grid.height_per_slice = kAfDefaultHeightPerSlice; /* Position the AF grid in the center of the BDS output. */ Rectangle bds(configInfo.bdsOutputSize); Size gridSize(grid.width << grid.block_width_log2, grid.height << grid.block_height_log2); /* * \todo - Support request metadata * - Set the ROI based on any input controls in the request * - Return the AF ROI as metadata in the Request */ Rectangle roi = gridSize.centeredTo(bds.center()); Point start = roi.topLeft(); /* x_start and y_start should be even */ grid.x_start = utils::alignDown(start.x, 2); grid.y_start = utils::alignDown(start.y, 2); grid.y_start |= IPU3_UAPI_GRID_Y_START_EN; /* Initial max focus step */ maxStep_ = kMaxFocusSteps; /* Initial frame ignore counter */ afIgnoreFrameReset(); /* Initial focus value */ context.activeState.af.focus = 0; /* Maximum variance of the AF statistics */ context.activeState.af.maxVariance = 0; /* The stable AF value flag. if it is true, the AF should be in a stable state. */ context.activeState.af.stable = false; return 0; } /** * \copydoc libcamera::ipa::Algorithm::prepare */ void Af::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] IPAFrameContext &frameContext, ipu3_uapi_params *params) { const struct ipu3_uapi_grid_config &grid = context.configuration.af.afGrid; params->acc_param.af.grid_cfg = grid; params->acc_param.af.filter_config = afFilterConfigDefault; /* Enable AF processing block */ params->use.acc_af = 1; } /** * \brief AF coarse scan * \param[in] context The shared IPA context * * Find a near focused image using a coarse step. The step is determined by * kCoarseSearchStep. */ void Af::afCoarseScan(IPAContext &context) { if (coarseCompleted_) return; if (afNeedIgnoreFrame()) return; if (afScan(context, kCoarseSearchStep)) { coarseCompleted_ = true; context.activeState.af.maxVariance = 0; focus_ = context.activeState.af.focus - (context.activeState.af.focus * kFineRange); context.activeState.af.focus = focus_; previousVariance_ = 0; maxStep_ = std::clamp(focus_ + static_cast<uint32_t>((focus_ * kFineRange)), 0U, kMaxFocusSteps); } } /** * \brief AF fine scan * \param[in] context The shared IPA context * * Find an optimum lens position with moving 1 step for each search. */ void Af::afFineScan(IPAContext &context) { if (!coarseCompleted_) return; if (afNeedIgnoreFrame()) return; if (afScan(context, kFineSearchStep)) { context.activeState.af.stable = true; fineCompleted_ = true; } } /** * \brief AF reset * \param[in] context The shared IPA context * * Reset all the parameters to start over the AF process. */ void Af::afReset(IPAContext &context) { if (afNeedIgnoreFrame()) return; context.activeState.af.maxVariance = 0; context.activeState.af.focus = 0; focus_ = 0; context.activeState.af.stable = false; ignoreCounter_ = kIgnoreFrame; previousVariance_ = 0.0; coarseCompleted_ = false; fineCompleted_ = false; maxStep_ = kMaxFocusSteps; } /** * \brief AF variance comparison * \param[in] context The IPA context * \param[in] min_step The VCM movement step * * We always pick the largest variance to replace the previous one. The image * with a larger variance also indicates it is a clearer image than previous * one. If we find a negative derivative, we return immediately. * * \return True, if it finds a AF value. */ bool Af::afScan(IPAContext &context, int min_step) { if (focus_ > maxStep_) { /* If reach the max step, move lens to the position. */ context.activeState.af.focus = bestFocus_; return true; } else { /* * Find the maximum of the variance by estimating its * derivative. If the direction changes, it means we have * passed a maximum one step before. */ if ((currentVariance_ - context.activeState.af.maxVariance) >= -(context.activeState.af.maxVariance * 0.1)) { /* * Positive and zero derivative: * The variance is still increasing. The focus could be * increased for the next comparison. Also, the max variance * and previous focus value are updated. */ bestFocus_ = focus_; focus_ += min_step; context.activeState.af.focus = focus_; context.activeState.af.maxVariance = currentVariance_; } else { /* * Negative derivative: * The variance starts to decrease which means the maximum * variance is found. Set focus step to previous good one * then return immediately. */ context.activeState.af.focus = bestFocus_; return true; } } previousVariance_ = currentVariance_; LOG(IPU3Af, Debug) << " Previous step is " << bestFocus_ << " Current step is " << focus_; return false; } /** * \brief Determine the frame to be ignored * \return Return True if the frame should be ignored, false otherwise */ bool Af::afNeedIgnoreFrame() { if (ignoreCounter_ == 0) return false; else ignoreCounter_--; return true; } /** * \brief Reset frame ignore counter */ void Af::afIgnoreFrameReset() { ignoreCounter_ = kIgnoreFrame; } /** * \brief Estimate variance * \param[in] y_items The AF filter data set from the IPU3 statistics buffer * \param[in] isY1 Selects between filter Y1 or Y2 to calculate the variance * * Calculate the mean of the data set provided by \a y_item, and then calculate * the variance of that data set from the mean. * * The operation can work on one of two sets of values contained within the * y_item data set supplied by the IPU3. The two data sets are the results of * both the Y1 and Y2 filters which are used to support coarse (Y1) and fine * (Y2) calculations of the contrast. * * \return The variance of the values in the data set \a y_item selected by \a isY1 */ double Af::afEstimateVariance(Span<const y_table_item_t> y_items, bool isY1) { uint32_t total = 0; double mean; double var_sum = 0; for (auto y : y_items) total += isY1 ? y.y1_avg : y.y2_avg; mean = total / y_items.size(); for (auto y : y_items) { double avg = isY1 ? y.y1_avg : y.y2_avg; var_sum += pow(avg - mean, 2); } return var_sum / y_items.size(); } /** * \brief Determine out-of-focus situation * \param[in] context The IPA context * * Out-of-focus means that the variance change rate for a focused and a new * variance is greater than a threshold. * * \return True if the variance threshold is crossed indicating lost focus, * false otherwise */ bool Af::afIsOutOfFocus(IPAContext &context) { const uint32_t diff_var = std::abs(currentVariance_ - context.activeState.af.maxVariance); const double var_ratio = diff_var / context.activeState.af.maxVariance; LOG(IPU3Af, Debug) << "Variance change rate: " << var_ratio << " Current VCM step: " << context.activeState.af.focus; if (var_ratio > kMaxChange) return true; else return false; } /** * \brief Determine the max contrast image and lens position * \param[in] context The IPA context * \param[in] frame The frame context sequence number * \param[in] frameContext The current frame context * \param[in] stats The statistics buffer of IPU3 * \param[out] metadata Metadata for the frame, to be filled by the algorithm * * Ideally, a clear image also has a relatively higher contrast. So, every * image for each focus step should be tested to find an optimal focus step. * * The Hill Climbing Algorithm[1] is used to find the maximum variance of the * AF statistics which is the AF output of IPU3. The focus step is increased * then the variance of the AF statistics are estimated. If it finds the * negative derivative we have just passed the peak, and we infer that the best * focus is found. * * [1] Hill Climbing Algorithm, https://en.wikipedia.org/wiki/Hill_climbing */ void Af::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, [[maybe_unused]] ControlList &metadata) { /* Evaluate the AF buffer length */ uint32_t afRawBufferLen = context.configuration.af.afGrid.width * context.configuration.af.afGrid.height; ASSERT(afRawBufferLen < IPU3_UAPI_AF_Y_TABLE_MAX_SIZE); Span<const y_table_item_t> y_items(reinterpret_cast<const y_table_item_t *>(&stats->af_raw_buffer.y_table), afRawBufferLen); /* * Calculate the mean and the variance of AF statistics for a given grid. * For coarse: y1 are used. * For fine: y2 results are used. */ currentVariance_ = afEstimateVariance(y_items, !coarseCompleted_); if (!context.activeState.af.stable) { afCoarseScan(context); afFineScan(context); } else { if (afIsOutOfFocus(context)) afReset(context); else afIgnoreFrameReset(); } } REGISTER_IPA_ALGORITHM(Af, "Af") } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/tone_mapping.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google inc. * * IPU3 ToneMapping and Gamma control */ #pragma once #include "algorithm.h" namespace libcamera { namespace ipa::ipu3::algorithms { class ToneMapping : public Algorithm { public: ToneMapping(); int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override; void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, ControlList &metadata) override; private: double gamma_; }; } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/awb.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas On Board * * AWB control algorithm */ #include "awb.h" #include <algorithm> #include <cmath> #include <libcamera/base/log.h> #include <libcamera/control_ids.h> /** * \file awb.h */ namespace libcamera { namespace ipa::ipu3::algorithms { LOG_DEFINE_CATEGORY(IPU3Awb) /* * When zones are used for the grey world algorithm, they are only considered if * their average green value is at least 16/255 (after black level subtraction) * to exclude zones that are too dark and don't provide relevant colour * information (on the opposite side of the spectrum, saturated regions are * excluded by the ImgU statistics engine). */ static constexpr uint32_t kMinGreenLevelInZone = 16; /* * Minimum proportion of non-saturated cells in a zone for the zone to be used * by the AWB algorithm. */ static constexpr double kMaxCellSaturationRatio = 0.8; /* * Maximum ratio of saturated pixels in a cell for the cell to be considered * non-saturated and counted by the AWB algorithm. */ static constexpr uint32_t kMinCellsPerZoneRatio = 255 * 90 / 100; /** * \struct Accumulator * \brief RGB statistics for a given zone * * Accumulate red, green and blue values for each non-saturated item over a * zone. Items can for instance be pixels, but also the average of groups of * pixels, depending on who uses the accumulator. * \todo move this description and structure into a common header * * Zones which are saturated beyond the threshold defined in * ipu3_uapi_awb_config_s are not included in the average. * * \var Accumulator::counted * \brief Number of unsaturated cells used to calculate the sums * * \var Accumulator::sum * \brief A structure containing the average red, green and blue sums * * \var Accumulator::sum.red * \brief Sum of the average red values of each unsaturated cell in the zone * * \var Accumulator::sum.green * \brief Sum of the average green values of each unsaturated cell in the zone * * \var Accumulator::sum.blue * \brief Sum of the average blue values of each unsaturated cell in the zone */ /** * \struct Awb::AwbStatus * \brief AWB parameters calculated * * The AwbStatus structure is intended to store the AWB * parameters calculated by the algorithm * * \var AwbStatus::temperatureK * \brief Color temperature calculated * * \var AwbStatus::redGain * \brief Gain calculated for the red channel * * \var AwbStatus::greenGain * \brief Gain calculated for the green channel * * \var AwbStatus::blueGain * \brief Gain calculated for the blue channel */ /* Default settings for Bayer noise reduction replicated from the Kernel */ static const struct ipu3_uapi_bnr_static_config imguCssBnrDefaults = { .wb_gains = { 16, 16, 16, 16 }, .wb_gains_thr = { 255, 255, 255, 255 }, .thr_coeffs = { 1700, 0, 31, 31, 0, 16 }, .thr_ctrl_shd = { 26, 26, 26, 26 }, .opt_center = { -648, 0, -366, 0 }, .lut = { { 17, 23, 28, 32, 36, 39, 42, 45, 48, 51, 53, 55, 58, 60, 62, 64, 66, 68, 70, 72, 73, 75, 77, 78, 80, 82, 83, 85, 86, 88, 89, 90 } }, .bp_ctrl = { 20, 0, 1, 40, 0, 6, 0, 6, 0 }, .dn_detect_ctrl = { 9, 3, 4, 0, 8, 0, 1, 1, 1, 1, 0 }, .column_size = 1296, .opt_center_sqr = { 419904, 133956 }, }; /* Default color correction matrix defined as an identity matrix */ static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = { 8191, 0, 0, 0, 0, 8191, 0, 0, 0, 0, 8191, 0 }; /** * \class Awb * \brief A Grey world white balance correction algorithm * * The Grey World algorithm assumes that the scene, in average, is neutral grey. * Reference: Lam, Edmund & Fung, George. (2008). Automatic White Balancing in * Digital Photography. 10.1201/9781420054538.ch10. * * The IPU3 generates statistics from the Bayer Down Scaler output into a grid * defined in the ipu3_uapi_awb_config_s structure. * * - Cells are defined in Pixels * - Zones are defined in Cells * * 80 cells * /───────────── 1280 pixels ───────────\ * 16 zones * 16 * ┌────┬────┬────┬────┬────┬─ ──────┬────┐ \ * │Cell│ │ │ │ │ | │ │ │ * 16 │ px │ │ │ │ │ | │ │ │ * ├────┼────┼────┼────┼────┼─ ──────┼────┤ │ * │ │ │ │ │ │ | │ │ * │ │ │ │ │ │ | │ │ 7 * │ ── │ ── │ ── │ ── │ ── │ ── ── ─┤ ── │ 1 2 4 * │ │ │ │ │ │ | │ │ 2 0 5 * * │ │ │ │ │ │ | │ │ z p c * ├────┼────┼────┼────┼────┼─ ──────┼────┤ o i e * │ │ │ │ │ │ | │ │ n x l * │ │ | │ │ e e l * ├─── ───┼─ ──────┼────┤ s l s * │ │ | │ │ s * │ │ | │ │ * ├─── Zone of Cells ───┼─ ──────┼────┤ │ * │ (5 x 4) │ | │ │ │ * │ │ | │ │ │ * ├── ───┼─ ──────┼────┤ │ * │ │ │ | │ │ │ * │ │ │ │ │ │ | │ │ │ * └────┴────┴────┴────┴────┴─ ──────┴────┘ / * * * In each cell, the ImgU computes for each colour component the average of all * unsaturated pixels (below a programmable threshold). It also provides the * ratio of saturated pixels in the cell. * * The AWB algorithm operates on a coarser grid, made by grouping cells from the * hardware grid into zones. The number of zones is fixed to \a kAwbStatsSizeX x * \a kAwbStatsSizeY. For example, a frame of 1280x720 is divided into 80x45 * cells of [16x16] pixels and 16x12 zones of [5x4] cells each * (\a kAwbStatsSizeX=16 and \a kAwbStatsSizeY=12). If the number of cells isn't * an exact multiple of the number of zones, the right-most and bottom-most * cells are ignored. The grid configuration is computed by * IPAIPU3::calculateBdsGrid(). * * Before calculating the gains, the algorithm aggregates the cell averages for * each zone in generateAwbStats(). Cells that have a too high ratio of * saturated pixels are ignored, and only zones that contain enough * non-saturated cells are then used by the algorithm. * * The Grey World algorithm will then estimate the red and blue gains to apply, and * store the results in the metadata. The green gain is always set to 1. */ Awb::Awb() : Algorithm() { asyncResults_.blueGain = 1.0; asyncResults_.greenGain = 1.0; asyncResults_.redGain = 1.0; asyncResults_.temperatureK = 4500; zones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY); } Awb::~Awb() = default; /** * \copydoc libcamera::ipa::Algorithm::configure */ int Awb::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { const ipu3_uapi_grid_config &grid = context.configuration.grid.bdsGrid; stride_ = context.configuration.grid.stride; cellsPerZoneX_ = std::round(grid.width / static_cast<double>(kAwbStatsSizeX)); cellsPerZoneY_ = std::round(grid.height / static_cast<double>(kAwbStatsSizeY)); /* * Configure the minimum proportion of cells counted within a zone * for it to be relevant for the grey world algorithm. * \todo This proportion could be configured. */ cellsPerZoneThreshold_ = cellsPerZoneX_ * cellsPerZoneY_ * kMaxCellSaturationRatio; LOG(IPU3Awb, Debug) << "Threshold for AWB is set to " << cellsPerZoneThreshold_; return 0; } constexpr uint16_t Awb::threshold(float value) { /* AWB thresholds are in the range [0, 8191] */ return value * 8191; } constexpr uint16_t Awb::gainValue(double gain) { /* * The colour gains applied by the BNR for the four channels (Gr, R, B * and Gb) are expressed in the parameters structure as 16-bit integers * that store a fixed-point U3.13 value in the range [0, 8[. * * The real gain value is equal to the gain parameter plus one, i.e. * * Pout = Pin * (1 + gain / 8192) * * where 'Pin' is the input pixel value, 'Pout' the output pixel value, * and 'gain' the gain in the parameters structure as a 16-bit integer. */ return std::clamp((gain - 1.0) * 8192, 0.0, 65535.0); } /** * \copydoc libcamera::ipa::Algorithm::prepare */ void Awb::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] IPAFrameContext &frameContext, ipu3_uapi_params *params) { /* * Green saturation thresholds are reduced because we are using the * green channel only in the exposure computation. */ params->acc_param.awb.config.rgbs_thr_r = threshold(1.0); params->acc_param.awb.config.rgbs_thr_gr = threshold(0.9); params->acc_param.awb.config.rgbs_thr_gb = threshold(0.9); params->acc_param.awb.config.rgbs_thr_b = threshold(1.0); /* * Enable saturation inclusion on thr_b for ImgU to update the * ipu3_uapi_awb_set_item->sat_ratio field. */ params->acc_param.awb.config.rgbs_thr_b |= IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT | IPU3_UAPI_AWB_RGBS_THR_B_EN; const ipu3_uapi_grid_config &grid = context.configuration.grid.bdsGrid; params->acc_param.awb.config.grid = context.configuration.grid.bdsGrid; /* * Optical center is column start (respectively row start) of the * cell of interest minus its X center (respectively Y center). * * For the moment use BDS as a first approximation, but it should * be calculated based on Shading (SHD) parameters. */ params->acc_param.bnr = imguCssBnrDefaults; Size &bdsOutputSize = context.configuration.grid.bdsOutputSize; params->acc_param.bnr.column_size = bdsOutputSize.width; params->acc_param.bnr.opt_center.x_reset = grid.x_start - (bdsOutputSize.width / 2); params->acc_param.bnr.opt_center.y_reset = grid.y_start - (bdsOutputSize.height / 2); params->acc_param.bnr.opt_center_sqr.x_sqr_reset = params->acc_param.bnr.opt_center.x_reset * params->acc_param.bnr.opt_center.x_reset; params->acc_param.bnr.opt_center_sqr.y_sqr_reset = params->acc_param.bnr.opt_center.y_reset * params->acc_param.bnr.opt_center.y_reset; params->acc_param.bnr.wb_gains.gr = gainValue(context.activeState.awb.gains.green); params->acc_param.bnr.wb_gains.r = gainValue(context.activeState.awb.gains.red); params->acc_param.bnr.wb_gains.b = gainValue(context.activeState.awb.gains.blue); params->acc_param.bnr.wb_gains.gb = gainValue(context.activeState.awb.gains.green); LOG(IPU3Awb, Debug) << "Color temperature estimated: " << asyncResults_.temperatureK; /* The CCM matrix may change when color temperature will be used */ params->acc_param.ccm = imguCssCcmDefault; params->use.acc_awb = 1; params->use.acc_bnr = 1; params->use.acc_ccm = 1; } /** * The function estimates the correlated color temperature using * from RGB color space input. * In physics and color science, the Planckian locus or black body locus is * the path or locus that the color of an incandescent black body would take * in a particular chromaticity space as the blackbody temperature changes. * * If a narrow range of color temperatures is considered (those encapsulating * daylight being the most practical case) one can approximate the Planckian * locus in order to calculate the CCT in terms of chromaticity coordinates. * * More detailed information can be found in: * https://en.wikipedia.org/wiki/Color_temperature#Approximation */ uint32_t Awb::estimateCCT(double red, double green, double blue) { /* Convert the RGB values to CIE tristimulus values (XYZ) */ double X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue); double Y = (-0.32466) * (red) + (1.57837) * (green) + (-0.73191) * (blue); double Z = (-0.68202) * (red) + (0.77073) * (green) + (0.56332) * (blue); /* Calculate the normalized chromaticity values */ double x = X / (X + Y + Z); double y = Y / (X + Y + Z); /* Calculate CCT */ double n = (x - 0.3320) / (0.1858 - y); return 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33; } /* Generate an RGB vector with the average values for each zone */ void Awb::generateZones() { zones_.clear(); for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) { RGB zone; double counted = awbStats_[i].counted; if (counted >= cellsPerZoneThreshold_) { zone.G = awbStats_[i].sum.green / counted; if (zone.G >= kMinGreenLevelInZone) { zone.R = awbStats_[i].sum.red / counted; zone.B = awbStats_[i].sum.blue / counted; zones_.push_back(zone); } } } } /* Translate the IPU3 statistics into the default statistics zone array */ void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats) { /* * Generate a (kAwbStatsSizeX x kAwbStatsSizeY) array from the IPU3 grid which is * (grid.width x grid.height). */ for (unsigned int cellY = 0; cellY < kAwbStatsSizeY * cellsPerZoneY_; cellY++) { for (unsigned int cellX = 0; cellX < kAwbStatsSizeX * cellsPerZoneX_; cellX++) { uint32_t cellPosition = cellY * stride_ + cellX; uint32_t zoneX = cellX / cellsPerZoneX_; uint32_t zoneY = cellY / cellsPerZoneY_; uint32_t awbZonePosition = zoneY * kAwbStatsSizeX + zoneX; /* Cast the initial IPU3 structure to simplify the reading */ const ipu3_uapi_awb_set_item *currentCell = reinterpret_cast<const ipu3_uapi_awb_set_item *>( &stats->awb_raw_buffer.meta_data[cellPosition] ); /* * Use cells which have less than 90% * saturation as an initial means to include * otherwise bright cells which are not fully * saturated. * * \todo The 90% saturation rate may require * further empirical measurements and * optimisation during camera tuning phases. */ if (currentCell->sat_ratio <= kMinCellsPerZoneRatio) { /* The cell is not saturated, use the current cell */ awbStats_[awbZonePosition].counted++; uint32_t greenValue = currentCell->Gr_avg + currentCell->Gb_avg; awbStats_[awbZonePosition].sum.green += greenValue / 2; awbStats_[awbZonePosition].sum.red += currentCell->R_avg; awbStats_[awbZonePosition].sum.blue += currentCell->B_avg; } } } } void Awb::clearAwbStats() { for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) { awbStats_[i].sum.blue = 0; awbStats_[i].sum.red = 0; awbStats_[i].sum.green = 0; awbStats_[i].counted = 0; } } void Awb::awbGreyWorld() { LOG(IPU3Awb, Debug) << "Grey world AWB"; /* * Make a separate list of the derivatives for each of red and blue, so * that we can sort them to exclude the extreme gains. We could * consider some variations, such as normalising all the zones first, or * doing an L2 average etc. */ std::vector<RGB> &redDerivative(zones_); std::vector<RGB> blueDerivative(redDerivative); std::sort(redDerivative.begin(), redDerivative.end(), [](RGB const &a, RGB const &b) { return a.G * b.R < b.G * a.R; }); std::sort(blueDerivative.begin(), blueDerivative.end(), [](RGB const &a, RGB const &b) { return a.G * b.B < b.G * a.B; }); /* Average the middle half of the values. */ int discard = redDerivative.size() / 4; RGB sumRed(0, 0, 0); RGB sumBlue(0, 0, 0); for (auto ri = redDerivative.begin() + discard, bi = blueDerivative.begin() + discard; ri != redDerivative.end() - discard; ri++, bi++) sumRed += *ri, sumBlue += *bi; double redGain = sumRed.G / (sumRed.R + 1), blueGain = sumBlue.G / (sumBlue.B + 1); /* Color temperature is not relevant in Grey world but still useful to estimate it :-) */ asyncResults_.temperatureK = estimateCCT(sumRed.R, sumRed.G, sumBlue.B); /* * Gain values are unsigned integer value ranging [0, 8) with 13 bit * fractional part. */ redGain = std::clamp(redGain, 0.0, 65535.0 / 8192); blueGain = std::clamp(blueGain, 0.0, 65535.0 / 8192); asyncResults_.redGain = redGain; /* Hardcode the green gain to 1.0. */ asyncResults_.greenGain = 1.0; asyncResults_.blueGain = blueGain; } void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats) { ASSERT(stats->stats_3a_status.awb_en); clearAwbStats(); generateAwbStats(stats); generateZones(); LOG(IPU3Awb, Debug) << "Valid zones: " << zones_.size(); if (zones_.size() > 10) { awbGreyWorld(); LOG(IPU3Awb, Debug) << "Gain found for red: " << asyncResults_.redGain << " and for blue: " << asyncResults_.blueGain; } } /** * \copydoc libcamera::ipa::Algorithm::process */ void Awb::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, [[maybe_unused]] ControlList &metadata) { calculateWBGains(stats); /* * Gains are only recalculated if enough zones were detected. * The results are cached, so if no results were calculated, we set the * cached values from asyncResults_ here. */ context.activeState.awb.gains.blue = asyncResults_.blueGain; context.activeState.awb.gains.green = asyncResults_.greenGain; context.activeState.awb.gains.red = asyncResults_.redGain; context.activeState.awb.temperatureK = asyncResults_.temperatureK; metadata.set(controls::AwbEnable, true); metadata.set(controls::ColourGains, { static_cast<float>(context.activeState.awb.gains.red), static_cast<float>(context.activeState.awb.gains.blue) }); metadata.set(controls::ColourTemperature, context.activeState.awb.temperatureK); } REGISTER_IPA_ALGORITHM(Awb, "Awb") } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/af.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Red Hat * * IPU3 Af algorithm */ #pragma once #include <linux/intel-ipu3.h> #include <libcamera/base/utils.h> #include <libcamera/geometry.h> #include "algorithm.h" namespace libcamera { namespace ipa::ipu3::algorithms { class Af : public Algorithm { /* The format of y_table. From ipu3-ipa repo */ typedef struct __attribute__((packed)) y_table_item { uint16_t y1_avg; uint16_t y2_avg; } y_table_item_t; public: Af(); ~Af() = default; int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override; void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, ControlList &metadata) override; private: void afCoarseScan(IPAContext &context); void afFineScan(IPAContext &context); bool afScan(IPAContext &context, int min_step); void afReset(IPAContext &context); bool afNeedIgnoreFrame(); void afIgnoreFrameReset(); double afEstimateVariance(Span<const y_table_item_t> y_items, bool isY1); bool afIsOutOfFocus(IPAContext &context); /* VCM step configuration. It is the current setting of the VCM step. */ uint32_t focus_; /* The best VCM step. It is a local optimum VCM step during scanning. */ uint32_t bestFocus_; /* Current AF statistic variance. */ double currentVariance_; /* The frames are ignore before starting measuring. */ uint32_t ignoreCounter_; /* It is used to determine the derivative during scanning */ double previousVariance_; /* The designated maximum range of focus scanning. */ uint32_t maxStep_; /* If the coarse scan completes, it is set to true. */ bool coarseCompleted_; /* If the fine scan completes, it is set to true. */ bool fineCompleted_; }; } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/tone_mapping.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google inc. * * IPU3 ToneMapping and Gamma control */ #include "tone_mapping.h" #include <cmath> #include <string.h> /** * \file tone_mapping.h */ namespace libcamera { namespace ipa::ipu3::algorithms { /** * \class ToneMapping * \brief A class to handle tone mapping based on gamma * * This algorithm improves the image dynamic using a look-up table which is * generated based on a gamma parameter. */ ToneMapping::ToneMapping() : gamma_(1.0) { } /** * \brief Configure the tone mapping given a configInfo * \param[in] context The shared IPA context * \param[in] configInfo The IPA configuration data * * \return 0 */ int ToneMapping::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { /* Initialise tone mapping gamma value. */ context.activeState.toneMapping.gamma = 0.0; return 0; } /** * \brief Fill in the parameter structure, and enable gamma control * \param[in] context The shared IPA context * \param[in] frame The frame context sequence number * \param[in] frameContext The FrameContext for this frame * \param[out] params The IPU3 parameters * * Populate the IPU3 parameter structure with our tone mapping look up table and * enable the gamma control module in the processing blocks. */ void ToneMapping::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] IPAFrameContext &frameContext, ipu3_uapi_params *params) { /* Copy the calculated LUT into the parameters buffer. */ memcpy(params->acc_param.gamma.gc_lut.lut, context.activeState.toneMapping.gammaCorrection.lut, IPU3_UAPI_GAMMA_CORR_LUT_ENTRIES * sizeof(params->acc_param.gamma.gc_lut.lut[0])); /* Enable the custom gamma table. */ params->use.acc_gamma = 1; params->acc_param.gamma.gc_ctrl.enable = 1; } /** * \brief Calculate the tone mapping look up table * \param[in] context The shared IPA context * \param[in] frame The current frame sequence number * \param[in] frameContext The current frame context * \param[in] stats The IPU3 statistics and ISP results * \param[out] metadata Metadata for the frame, to be filled by the algorithm * * The tone mapping look up table is generated as an inverse power curve from * our gamma setting. */ void ToneMapping::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] IPAFrameContext &frameContext, [[maybe_unused]] const ipu3_uapi_stats_3a *stats, [[maybe_unused]] ControlList &metadata) { /* * Hardcode gamma to 1.1 as a default for now. * * \todo Expose gamma control setting through the libcamera control API */ gamma_ = 1.1; if (context.activeState.toneMapping.gamma == gamma_) return; struct ipu3_uapi_gamma_corr_lut &lut = context.activeState.toneMapping.gammaCorrection; for (uint32_t i = 0; i < std::size(lut.lut); i++) { double j = static_cast<double>(i) / (std::size(lut.lut) - 1); double gamma = std::pow(j, 1.0 / gamma_); /* The output value is expressed on 13 bits. */ lut.lut[i] = gamma * 8191; } context.activeState.toneMapping.gamma = gamma_; } REGISTER_IPA_ALGORITHM(ToneMapping, "ToneMapping") } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/blc.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google inc. * * IPU3 Black Level Correction control */ #include "blc.h" #include <string.h> /** * \file blc.h * \brief IPU3 Black Level Correction control */ namespace libcamera { namespace ipa::ipu3::algorithms { /** * \class BlackLevelCorrection * \brief A class to handle black level correction * * The pixels output by the camera normally include a black level, because * sensors do not always report a signal level of '0' for black. Pixels at or * below this level should be considered black. To achieve that, the ImgU BLC * algorithm subtracts a configurable offset from all pixels. * * The black level can be measured at runtime from an optical dark region of the * camera sensor, or measured during the camera tuning process. The first option * isn't currently supported. */ BlackLevelCorrection::BlackLevelCorrection() { } /** * \brief Fill in the parameter structure, and enable black level correction * \param[in] context The shared IPA context * \param[in] frame The frame context sequence number * \param[in] frameContext The FrameContext for this frame * \param[out] params The IPU3 parameters * * Populate the IPU3 parameter structure with the correction values for each * channel and enable the corresponding ImgU block processing. */ void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] IPAFrameContext &frameContext, ipu3_uapi_params *params) { /* * The Optical Black Level correction values * \todo The correction values should come from sensor specific * tuning processes. This is a first rough approximation. */ params->obgrid_param.gr = 64; params->obgrid_param.r = 64; params->obgrid_param.b = 64; params->obgrid_param.gb = 64; /* Enable the custom black level correction processing */ params->use.obgrid = 1; params->use.obgrid_param = 1; } REGISTER_IPA_ALGORITHM(BlackLevelCorrection, "BlackLevelCorrection") } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/blc.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google inc. * * IPU3 Black Level Correction control */ #pragma once #include "algorithm.h" namespace libcamera { namespace ipa::ipu3::algorithms { class BlackLevelCorrection : public Algorithm { public: BlackLevelCorrection(); void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override; }; } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/algorithm.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas On Board * * IPU3 control algorithm interface */ #pragma once #include <libipa/algorithm.h> #include "module.h" namespace libcamera { namespace ipa::ipu3 { using Algorithm = libcamera::ipa::Algorithm<Module>; } /* namespace ipa::ipu3 */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/awb.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas On Board * * IPU3 AWB control algorithm */ #pragma once #include <vector> #include <linux/intel-ipu3.h> #include <libcamera/geometry.h> #include "algorithm.h" namespace libcamera { namespace ipa::ipu3::algorithms { /* Region size for the statistics generation algorithm */ static constexpr uint32_t kAwbStatsSizeX = 16; static constexpr uint32_t kAwbStatsSizeY = 12; struct Accumulator { unsigned int counted; struct { uint64_t red; uint64_t green; uint64_t blue; } sum; }; class Awb : public Algorithm { public: Awb(); ~Awb(); int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override; void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, ControlList &metadata) override; private: /* \todo Make these structs available to all the ISPs ? */ struct RGB { RGB(double _R = 0, double _G = 0, double _B = 0) : R(_R), G(_G), B(_B) { } double R, G, B; RGB &operator+=(RGB const &other) { R += other.R, G += other.G, B += other.B; return *this; } }; struct AwbStatus { double temperatureK; double redGain; double greenGain; double blueGain; }; private: void calculateWBGains(const ipu3_uapi_stats_3a *stats); void generateZones(); void generateAwbStats(const ipu3_uapi_stats_3a *stats); void clearAwbStats(); void awbGreyWorld(); uint32_t estimateCCT(double red, double green, double blue); static constexpr uint16_t threshold(float value); static constexpr uint16_t gainValue(double gain); std::vector<RGB> zones_; Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY]; AwbStatus asyncResults_; uint32_t stride_; uint32_t cellsPerZoneX_; uint32_t cellsPerZoneY_; uint32_t cellsPerZoneThreshold_; }; } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera*/
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/agc.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas On Board * * IPU3 AGC/AEC mean-based control algorithm */ #pragma once #include <linux/intel-ipu3.h> #include <libcamera/base/utils.h> #include <libcamera/geometry.h> #include "libipa/agc_mean_luminance.h" #include "libipa/histogram.h" #include "algorithm.h" namespace libcamera { struct IPACameraSensorInfo; namespace ipa::ipu3::algorithms { class Agc : public Algorithm, public AgcMeanLuminance { public: Agc(); ~Agc() = default; int init(IPAContext &context, const YamlObject &tuningData) override; int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, ControlList &metadata) override; private: double estimateLuminance(double gain) const override; Histogram parseStatistics(const ipu3_uapi_stats_3a *stats, const ipu3_uapi_grid_config &grid); utils::Duration minShutterSpeed_; utils::Duration maxShutterSpeed_; double minAnalogueGain_; double maxAnalogueGain_; uint32_t stride_; double rGain_; double gGain_; double bGain_; ipu3_uapi_grid_config bdsGrid_; std::vector<std::tuple<uint8_t, uint8_t, uint8_t>> rgbTriples_; }; } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa/ipu3
repos/libcamera/src/ipa/ipu3/algorithms/agc.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas On Board * * AGC/AEC mean-based control algorithm */ #include "agc.h" #include <algorithm> #include <chrono> #include <cmath> #include <libcamera/base/log.h> #include <libcamera/base/utils.h> #include <libcamera/control_ids.h> #include <libcamera/ipa/core_ipa_interface.h> #include "libipa/histogram.h" /** * \file agc.h */ namespace libcamera { using namespace std::literals::chrono_literals; namespace ipa::ipu3::algorithms { /** * \class Agc * \brief A mean-based auto-exposure algorithm * * This algorithm calculates a shutter time and an analogue gain so that the * average value of the green channel of the brightest 2% of pixels approaches * 0.5. The AWB gains are not used here, and all cells in the grid have the same * weight, like an average-metering case. In this metering mode, the camera uses * light information from the entire scene and creates an average for the final * exposure setting, giving no weighting to any particular portion of the * metered area. * * Reference: Battiato, Messina & Castorina. (2008). Exposure * Correction for Imaging Devices: An Overview. 10.1201/9781420054538.ch12. */ LOG_DEFINE_CATEGORY(IPU3Agc) /* Minimum limit for analogue gain value */ static constexpr double kMinAnalogueGain = 1.0; /* \todo Honour the FrameDurationLimits control instead of hardcoding a limit */ static constexpr utils::Duration kMaxShutterSpeed = 60ms; /* Histogram constants */ static constexpr uint32_t knumHistogramBins = 256; Agc::Agc() : minShutterSpeed_(0s), maxShutterSpeed_(0s) { } /** * \brief Initialise the AGC algorithm from tuning files * \param[in] context The shared IPA context * \param[in] tuningData The YamlObject containing Agc tuning data * * This function calls the base class' tuningData parsers to discover which * control values are supported. * * \return 0 on success or errors from the base class */ int Agc::init(IPAContext &context, const YamlObject &tuningData) { int ret; ret = parseTuningData(tuningData); if (ret) return ret; context.ctrlMap.merge(controls()); return 0; } /** * \brief Configure the AGC given a configInfo * \param[in] context The shared IPA context * \param[in] configInfo The IPA configuration data * * \return 0 */ int Agc::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { const IPASessionConfiguration &configuration = context.configuration; IPAActiveState &activeState = context.activeState; stride_ = configuration.grid.stride; bdsGrid_ = configuration.grid.bdsGrid; minShutterSpeed_ = configuration.agc.minShutterSpeed; maxShutterSpeed_ = std::min(configuration.agc.maxShutterSpeed, kMaxShutterSpeed); minAnalogueGain_ = std::max(configuration.agc.minAnalogueGain, kMinAnalogueGain); maxAnalogueGain_ = configuration.agc.maxAnalogueGain; /* Configure the default exposure and gain. */ activeState.agc.gain = minAnalogueGain_; activeState.agc.exposure = 10ms / configuration.sensor.lineDuration; context.activeState.agc.constraintMode = constraintModes().begin()->first; context.activeState.agc.exposureMode = exposureModeHelpers().begin()->first; /* \todo Run this again when FrameDurationLimits is passed in */ setLimits(minShutterSpeed_, maxShutterSpeed_, minAnalogueGain_, maxAnalogueGain_); resetFrameCount(); return 0; } Histogram Agc::parseStatistics(const ipu3_uapi_stats_3a *stats, const ipu3_uapi_grid_config &grid) { uint32_t hist[knumHistogramBins] = { 0 }; rgbTriples_.clear(); for (unsigned int cellY = 0; cellY < grid.height; cellY++) { for (unsigned int cellX = 0; cellX < grid.width; cellX++) { uint32_t cellPosition = cellY * stride_ + cellX; const ipu3_uapi_awb_set_item *cell = reinterpret_cast<const ipu3_uapi_awb_set_item *>( &stats->awb_raw_buffer.meta_data[cellPosition]); rgbTriples_.push_back({ cell->R_avg, (cell->Gr_avg + cell->Gb_avg) / 2, cell->B_avg }); /* * Store the average green value to estimate the * brightness. Even the overexposed pixels are * taken into account. */ hist[(cell->Gr_avg + cell->Gb_avg) / 2]++; } } return Histogram(Span<uint32_t>(hist)); } /** * \brief Estimate the relative luminance of the frame with a given gain * \param[in] gain The gain to apply in estimating luminance * * The estimation is based on the AWB statistics for the current frame. Red, * green and blue averages for all cells are first multiplied by the gain, and * then saturated to approximate the sensor behaviour at high brightness * values. The approximation is quite rough, as it doesn't take into account * non-linearities when approaching saturation. * * The relative luminance (Y) is computed from the linear RGB components using * the Rec. 601 formula. The values are normalized to the [0.0, 1.0] range, * where 1.0 corresponds to a theoretical perfect reflector of 100% reference * white. * * More detailed information can be found in: * https://en.wikipedia.org/wiki/Relative_luminance * * \return The relative luminance of the frame */ double Agc::estimateLuminance(double gain) const { double redSum = 0, greenSum = 0, blueSum = 0; for (unsigned int i = 0; i < rgbTriples_.size(); i++) { redSum += std::min(std::get<0>(rgbTriples_[i]) * gain, 255.0); greenSum += std::min(std::get<1>(rgbTriples_[i]) * gain, 255.0); blueSum += std::min(std::get<2>(rgbTriples_[i]) * gain, 255.0); } double ySum = redSum * rGain_ * 0.299 + greenSum * gGain_ * 0.587 + blueSum * bGain_ * 0.114; return ySum / (bdsGrid_.height * bdsGrid_.width) / 255; } /** * \brief Process IPU3 statistics, and run AGC operations * \param[in] context The shared IPA context * \param[in] frame The current frame sequence number * \param[in] frameContext The current frame context * \param[in] stats The IPU3 statistics and ISP results * \param[out] metadata Metadata for the frame, to be filled by the algorithm * * Identify the current image brightness, and use that to estimate the optimal * new exposure and gain for the scene. */ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, ControlList &metadata) { Histogram hist = parseStatistics(stats, context.configuration.grid.bdsGrid); rGain_ = context.activeState.awb.gains.red; gGain_ = context.activeState.awb.gains.blue; bGain_ = context.activeState.awb.gains.green; /* * The Agc algorithm needs to know the effective exposure value that was * applied to the sensor when the statistics were collected. */ utils::Duration exposureTime = context.configuration.sensor.lineDuration * frameContext.sensor.exposure; double analogueGain = frameContext.sensor.gain; utils::Duration effectiveExposureValue = exposureTime * analogueGain; utils::Duration shutterTime; double aGain, dGain; std::tie(shutterTime, aGain, dGain) = calculateNewEv(context.activeState.agc.constraintMode, context.activeState.agc.exposureMode, hist, effectiveExposureValue); LOG(IPU3Agc, Debug) << "Divided up shutter, analogue gain and digital gain are " << shutterTime << ", " << aGain << " and " << dGain; IPAActiveState &activeState = context.activeState; /* Update the estimated exposure and gain. */ activeState.agc.exposure = shutterTime / context.configuration.sensor.lineDuration; activeState.agc.gain = aGain; metadata.set(controls::AnalogueGain, frameContext.sensor.gain); metadata.set(controls::ExposureTime, exposureTime.get<std::micro>()); /* \todo Use VBlank value calculated from each frame exposure. */ uint32_t vTotal = context.configuration.sensor.size.height + context.configuration.sensor.defVBlank; utils::Duration frameDuration = context.configuration.sensor.lineDuration * vTotal; metadata.set(controls::FrameDuration, frameDuration.get<std::micro>()); } REGISTER_IPA_ALGORITHM(Agc, "Agc") } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/exposure_mode_helper.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Helper class that performs computations relating to exposure */ #pragma once #include <tuple> #include <utility> #include <vector> #include <libcamera/base/span.h> #include <libcamera/base/utils.h> namespace libcamera { namespace ipa { class ExposureModeHelper { public: ExposureModeHelper(const Span<std::pair<utils::Duration, double>> stages); ~ExposureModeHelper() = default; void setLimits(utils::Duration minShutter, utils::Duration maxShutter, double minGain, double maxGain); std::tuple<utils::Duration, double, double> splitExposure(utils::Duration exposure) const; utils::Duration minShutter() const { return minShutter_; } utils::Duration maxShutter() const { return maxShutter_; } double minGain() const { return minGain_; } double maxGain() const { return maxGain_; } private: utils::Duration clampShutter(utils::Duration shutter) const; double clampGain(double gain) const; std::vector<utils::Duration> shutters_; std::vector<double> gains_; utils::Duration minShutter_; utils::Duration maxShutter_; double minGain_; double maxGain_; }; } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/agc_mean_luminance.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024 Ideas on Board Oy * agc_mean_luminance.h - Base class for mean luminance AGC algorithms */ #pragma once #include <map> #include <memory> #include <tuple> #include <vector> #include <libcamera/base/utils.h> #include <libcamera/controls.h> #include "libcamera/internal/yaml_parser.h" #include "exposure_mode_helper.h" #include "histogram.h" namespace libcamera { namespace ipa { class AgcMeanLuminance { public: AgcMeanLuminance(); virtual ~AgcMeanLuminance(); struct AgcConstraint { enum class Bound { Lower = 0, Upper = 1 }; Bound bound; double qLo; double qHi; double yTarget; }; int parseTuningData(const YamlObject &tuningData); void setLimits(utils::Duration minShutter, utils::Duration maxShutter, double minGain, double maxGain); std::map<int32_t, std::vector<AgcConstraint>> constraintModes() { return constraintModes_; } std::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers() { return exposureModeHelpers_; } ControlInfoMap::Map controls() { return controls_; } std::tuple<utils::Duration, double, double> calculateNewEv(uint32_t constraintModeIndex, uint32_t exposureModeIndex, const Histogram &yHist, utils::Duration effectiveExposureValue); void resetFrameCount() { frameCount_ = 0; } private: virtual double estimateLuminance(const double gain) const = 0; void parseRelativeLuminanceTarget(const YamlObject &tuningData); void parseConstraint(const YamlObject &modeDict, int32_t id); int parseConstraintModes(const YamlObject &tuningData); int parseExposureModes(const YamlObject &tuningData); double estimateInitialGain() const; double constraintClampGain(uint32_t constraintModeIndex, const Histogram &hist, double gain); utils::Duration filterExposure(utils::Duration exposureValue); uint64_t frameCount_; utils::Duration filteredExposure_; double relativeLuminanceTarget_; std::map<int32_t, std::vector<AgcConstraint>> constraintModes_; std::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers_; ControlInfoMap::Map controls_; }; } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/matrix_interpolator.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Helper class for interpolating maps of matrices */ #pragma once #include <algorithm> #include <map> #include <string> #include <tuple> #include <libcamera/base/log.h> #include "libcamera/internal/yaml_parser.h" #include "matrix.h" namespace libcamera { LOG_DECLARE_CATEGORY(MatrixInterpolator) namespace ipa { #ifndef __DOXYGEN__ template<typename T, unsigned int R, unsigned int C, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr> #else template<typename T, unsigned int R, unsigned int C> #endif /* __DOXYGEN__ */ class MatrixInterpolator { public: MatrixInterpolator() { reset(); } MatrixInterpolator(const std::map<unsigned int, Matrix<T, R, C>> &matrices) { for (const auto &pair : matrices) matrices_[pair.first] = pair.second; } ~MatrixInterpolator() {} void reset() { matrices_.clear(); matrices_[0] = Matrix<T, R, C>::identity(); } int readYaml(const libcamera::YamlObject &yaml, const std::string &key_name, const std::string &matrix_name) { matrices_.clear(); if (!yaml.isList()) { LOG(MatrixInterpolator, Error) << "yaml object must be a list"; return -EINVAL; } for (const auto &value : yaml.asList()) { unsigned int ct = std::stoul(value[key_name].get<std::string>("")); std::optional<Matrix<T, R, C>> matrix = value[matrix_name].get<Matrix<T, R, C>>(); if (!matrix) { LOG(MatrixInterpolator, Error) << "Failed to read matrix"; return -EINVAL; } matrices_[ct] = *matrix; LOG(MatrixInterpolator, Debug) << "Read matrix '" << matrix_name << "' for key '" << key_name << "' " << ct << ": " << matrices_[ct].toString(); } if (matrices_.size() < 1) { LOG(MatrixInterpolator, Error) << "Need at least one matrix"; return -EINVAL; } return 0; } Matrix<T, R, C> get(unsigned int ct) { ASSERT(matrices_.size() > 0); if (matrices_.size() == 1 || ct <= matrices_.begin()->first) return matrices_.begin()->second; if (ct >= matrices_.rbegin()->first) return matrices_.rbegin()->second; if (matrices_.find(ct) != matrices_.end()) return matrices_[ct]; /* The above four guarantee that this will succeed */ auto iter = matrices_.upper_bound(ct); unsigned int ctUpper = iter->first; unsigned int ctLower = (--iter)->first; double lambda = (ct - ctLower) / static_cast<double>(ctUpper - ctLower); Matrix<T, R, C> ret = lambda * matrices_[ctUpper] + (1.0 - lambda) * matrices_[ctLower]; return ret; } private: std::map<unsigned int, Matrix<T, R, C>> matrices_; }; } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/matrix_interpolator.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Helper class for interpolating maps of matrices */ #include "matrix_interpolator.h" #include <algorithm> #include <string> #include <libcamera/base/log.h> #include "libcamera/internal/yaml_parser.h" #include "matrix.h" /** * \file matrix_interpolator.h * \brief Helper class for interpolating maps of matrices */ namespace libcamera { LOG_DEFINE_CATEGORY(MatrixInterpolator) namespace ipa { /** * \class MatrixInterpolator * \brief Class for storing, retrieving, and interpolating matrices * \tparam T Type of numerical values to be stored in the matrices * \tparam R Number of rows in the matrices * \tparam C Number of columns in the matrices * * The main use case is to pass a map from color temperatures to corresponding * matrices (eg. color correction), and then requesting a matrix for a specific * color temperature. This class will abstract away the interpolation portion. */ /** * \fn MatrixInterpolator::MatrixInterpolator(const std::map<unsigned int, Matrix<T, R, C>> &matrices) * \brief Construct a matrix interpolator from a map of matrices * \param matrices Map from which to construct the matrix interpolator */ /** * \fn MatrixInterpolator::reset() * \brief Reset the matrix interpolator content to a single identity matrix */ /** * \fn int MatrixInterpolator<T, R, C>::readYaml() * \brief Initialize an MatrixInterpolator instance from yaml * \tparam T Type of data stored in the matrices * \tparam R Number of rows of the matrices * \tparam C Number of columns of the matrices * \param[in] yaml The yaml object that contains the map of unsigned integers to matrices * \param[in] key_name The name of the key in the yaml object * \param[in] matrix_name The name of the matrix in the yaml object * * The yaml object is expected to be a list of maps. Each map has two or more * pairs: one of \a key_name to the key value (usually color temperature), and * one or more of \a matrix_name to the matrix. This is a bit difficult to * explain, so here is an example (in python, as it is easier to parse than * yaml): * [ * { * 'ct': 2860, * 'ccm': [ 2.12089, -0.52461, -0.59629, * -0.85342, 2.80445, -0.95103, * -0.26897, -1.14788, 2.41685 ], * 'offsets': [ 0, 0, 0 ] * }, * * { * 'ct': 2960, * 'ccm': [ 2.26962, -0.54174, -0.72789, * -0.77008, 2.60271, -0.83262, * -0.26036, -1.51254, 2.77289 ], * 'offsets': [ 0, 0, 0 ] * }, * * { * 'ct': 3603, * 'ccm': [ 2.18644, -0.66148, -0.52496, * -0.77828, 2.69474, -0.91645, * -0.25239, -0.83059, 2.08298 ], * 'offsets': [ 0, 0, 0 ] * }, * ] * * In this case, \a key_name would be 'ct', and \a matrix_name can be either * 'ccm' or 'offsets'. This way multiple matrix interpolators can be defined in * one set of color temperature ranges in the tuning file, and they can be * retrieved separately with the \a matrix_name parameter. * * \return Zero on success, negative error code otherwise */ /** * \fn Matrix<T, R, C> MatrixInterpolator<T, R, C>::get(unsigned int key) * \brief Retrieve a matrix from the list of matrices, interpolating if necessary * \param[in] key The unsigned integer key of the matrix to retrieve * \return The matrix corresponding to the color temperature */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/exposure_mode_helper.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Helper class that performs computations relating to exposure */ #include "exposure_mode_helper.h" #include <algorithm> #include <libcamera/base/log.h> /** * \file exposure_mode_helper.h * \brief Helper class that performs computations relating to exposure * * AEGC algorithms have a need to split exposure between shutter time, analogue * and digital gain. Multiple implementations do so based on paired stages of * shutter time and gain limits; provide a helper to avoid duplicating the code. */ namespace libcamera { using namespace std::literals::chrono_literals; LOG_DEFINE_CATEGORY(ExposureModeHelper) namespace ipa { /** * \class ExposureModeHelper * \brief Class for splitting exposure into shutter time and total gain * * The ExposureModeHelper class provides a standard interface through which an * AEGC algorithm can divide exposure between shutter time and gain. It is * configured with a set of shutter time and gain pairs and works by initially * fixing gain at 1.0 and increasing shutter time up to the shutter time value * from the first pair in the set in an attempt to meet the required exposure * value. * * If the required exposure is not achievable by the first shutter time value * alone it ramps gain up to the value from the first pair in the set. If the * required exposure is still not met it then allows shutter time to ramp up to * the shutter time value from the second pair in the set, and continues in this * vein until either the required exposure time is met, or else the hardware's * shutter time or gain limits are reached. * * This method allows users to strike a balance between a well-exposed image and * an acceptable frame-rate, as opposed to simply maximising shutter time * followed by gain. The same helpers can be used to perform the latter * operation if needed by passing an empty set of pairs to the initialisation * function. * * The gain values may exceed a camera sensor's analogue gain limits if either * it or the IPA is also capable of digital gain. The configure() function must * be called with the hardware's limits to inform the helper of those * constraints. Any gain that is needed will be applied as analogue gain first * until the hardware's limit is reached, following which digital gain will be * used. */ /** * \brief Construct an ExposureModeHelper instance * \param[in] stages The vector of paired shutter time and gain limits * * The input stages are shutter time and _total_ gain pairs; the gain * encompasses both analogue and digital gain. * * The vector of stages may be empty. In that case, the helper will simply use * the runtime limits set through setShutterGainLimits() instead. */ ExposureModeHelper::ExposureModeHelper(const Span<std::pair<utils::Duration, double>> stages) { minShutter_ = 0us; maxShutter_ = 0us; minGain_ = 0; maxGain_ = 0; for (const auto &[s, g] : stages) { shutters_.push_back(s); gains_.push_back(g); } } /** * \brief Set the shutter time and gain limits * \param[in] minShutter The minimum shutter time supported * \param[in] maxShutter The maximum shutter time supported * \param[in] minGain The minimum analogue gain supported * \param[in] maxGain The maximum analogue gain supported * * This function configures the shutter time and analogue gain limits that need * to be adhered to as the helper divides up exposure. Note that this function * *must* be called whenever those limits change and before splitExposure() is * used. * * If the algorithm using the helpers needs to indicate that either shutter time * or analogue gain or both should be fixed it can do so by setting both the * minima and maxima to the same value. */ void ExposureModeHelper::setLimits(utils::Duration minShutter, utils::Duration maxShutter, double minGain, double maxGain) { minShutter_ = minShutter; maxShutter_ = maxShutter; minGain_ = minGain; maxGain_ = maxGain; } utils::Duration ExposureModeHelper::clampShutter(utils::Duration shutter) const { return std::clamp(shutter, minShutter_, maxShutter_); } double ExposureModeHelper::clampGain(double gain) const { return std::clamp(gain, minGain_, maxGain_); } /** * \brief Split exposure time into shutter time and gain * \param[in] exposure Exposure time * * This function divides a given exposure time into shutter time, analogue and * digital gain by iterating through stages of shutter time and gain limits. At * each stage the current stage's shutter time limit is multiplied by the * previous stage's gain limit (or 1.0 initially) to see if the combination of * the two can meet the required exposure time. If they cannot then the current * stage's shutter time limit is multiplied by the same stage's gain limit to * see if that combination can meet the required exposure time. If they cannot * then the function moves to consider the next stage. * * When a combination of shutter time and gain _stage_ limits are found that are * sufficient to meet the required exposure time, the function attempts to * reduce shutter time as much as possible whilst fixing gain and still meeting * the exposure time. If a _runtime_ limit prevents shutter time from being * lowered enough to meet the exposure time with gain fixed at the stage limit, * gain is also lowered to compensate. * * Once the shutter time and gain values are ascertained, gain is assigned as * analogue gain as much as possible, with digital gain only in use if the * maximum analogue gain runtime limit is unable to accommodate the exposure * value. * * If no combination of shutter time and gain limits is found that meets the * required exposure time, the helper falls-back to simply maximising the * shutter time first, followed by analogue gain, followed by digital gain. * * \return Tuple of shutter time, analogue gain, and digital gain */ std::tuple<utils::Duration, double, double> ExposureModeHelper::splitExposure(utils::Duration exposure) const { ASSERT(maxShutter_); ASSERT(maxGain_); bool gainFixed = minGain_ == maxGain_; bool shutterFixed = minShutter_ == maxShutter_; /* * There's no point entering the loop if we cannot change either gain * nor shutter anyway. */ if (shutterFixed && gainFixed) return { minShutter_, minGain_, exposure / (minShutter_ * minGain_) }; utils::Duration shutter; double stageGain; double gain; for (unsigned int stage = 0; stage < gains_.size(); stage++) { double lastStageGain = stage == 0 ? 1.0 : clampGain(gains_[stage - 1]); utils::Duration stageShutter = clampShutter(shutters_[stage]); stageGain = clampGain(gains_[stage]); /* * We perform the clamping on both shutter and gain in case the * helper has had limits set that prevent those values being * lowered beyond a certain minimum...this can happen at runtime * for various reasons and so would not be known when the stage * limits are initialised. */ if (stageShutter * lastStageGain >= exposure) { shutter = clampShutter(exposure / clampGain(lastStageGain)); gain = clampGain(exposure / shutter); return { shutter, gain, exposure / (shutter * gain) }; } if (stageShutter * stageGain >= exposure) { shutter = clampShutter(exposure / clampGain(stageGain)); gain = clampGain(exposure / shutter); return { shutter, gain, exposure / (shutter * gain) }; } } /* * From here on all we can do is max out the shutter time, followed by * the analogue gain. If we still haven't achieved the target we send * the rest of the exposure time to digital gain. If we were given no * stages to use then set stageGain to 1.0 so that shutter time is maxed * before gain touched at all. */ if (gains_.empty()) stageGain = 1.0; shutter = clampShutter(exposure / clampGain(stageGain)); gain = clampGain(exposure / shutter); return { shutter, gain, exposure / (shutter * gain) }; } /** * \fn ExposureModeHelper::minShutter() * \brief Retrieve the configured minimum shutter time limit set through * setShutterGainLimits() * \return The minShutter_ value */ /** * \fn ExposureModeHelper::maxShutter() * \brief Retrieve the configured maximum shutter time set through * setShutterGainLimits() * \return The maxShutter_ value */ /** * \fn ExposureModeHelper::minGain() * \brief Retrieve the configured minimum gain set through * setShutterGainLimits() * \return The minGain_ value */ /** * \fn ExposureModeHelper::maxGain() * \brief Retrieve the configured maximum gain set through * setShutterGainLimits() * \return The maxGain_ value */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/vector.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Vector and related operations */ #include "vector.h" #include <libcamera/base/log.h> /** * \file vector.h * \brief Vector class */ namespace libcamera { LOG_DEFINE_CATEGORY(Vector) namespace ipa { /** * \class Vector * \brief Vector class * \tparam T Type of numerical values to be stored in the vector * \tparam Rows Number of dimension of the vector (= number of elements) */ /** * \fn Vector::Vector() * \brief Construct a zero vector */ /** * \fn Vector::Vector(const std::array<T, Rows> &data) * \brief Construct vector from supplied data * \param data Data from which to construct a vector * * The size of \a data must be equal to the dimension size Rows of the vector. */ /** * \fn T Vector::operator[](size_t i) const * \brief Index to an element in the vector * \param i Index of element to retrieve * \return Element at index \a i from the vector */ /** * \fn T &Vector::operator[](size_t i) * \copydoc Vector::operator[](size_t i) const */ /** * \fn Vector::x() * \brief Convenience function to access the first element of the vector * \return The first element of the vector */ /** * \fn Vector::y() * \brief Convenience function to access the second element of the vector * \return The second element of the vector */ /** * \fn Vector::z() * \brief Convenience function to access the third element of the vector * \return The third element of the vector */ /** * \fn Vector::operator-() const * \brief Negate a Vector by negating both all of its coordinates * \return The negated vector */ /** * \fn Vector::operator-(Vector const &other) const * \brief Subtract one vector from another * \param[in] other The other vector * \return The difference of \a other from this vector */ /** * \fn Vector::operator+() * \brief Add two vectors together * \param[in] other The other vector * \return The sum of the two vectors */ /** * \fn Vector::operator*(const Vector<T, Rows> &other) const * \brief Compute the dot product * \param[in] other The other vector * \return The dot product of the two vectors */ /** * \fn Vector::operator*(T factor) const * \brief Multiply the vector by a scalar * \param[in] factor The factor * \return The vector multiplied by \a factor */ /** * \fn Vector::operator/() * \brief Divide the vector by a scalar * \param[in] factor The factor * \return The vector divided by \a factor */ /** * \fn Vector::length2() * \brief Get the squared length of the vector * \return The squared length of the vector */ /** * \fn Vector::length() * \brief Get the length of the vector * \return The length of the vector */ /** * \fn Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols> &v) * \brief Multiply a matrix by a vector * \tparam T Numerical type of the contents of the matrix and vector * \tparam Rows The number of rows in the matrix * \tparam Cols The number of columns in the matrix (= rows in the vector) * \param m The matrix * \param v The vector * \return Product of matrix \a m and vector \a v */ /** * \fn bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) * \brief Compare vectors for equality * \return True if the two vectors are equal, false otherwise */ /** * \fn bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) * \brief Compare vectors for inequality * \return True if the two vectors are not equal, false otherwise */ #ifndef __DOXYGEN__ bool vectorValidateYaml(const YamlObject &obj, unsigned int size) { if (!obj.isList()) return false; if (obj.size() != size) { LOG(Vector, Error) << "Wrong number of values in YAML vector: expected " << size << ", got " << obj.size(); return false; } return true; } #endif /* __DOXYGEN__ */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/histogram.h
/* SPDX-License-Identifier: BSD-2-Clause */ /* * Copyright (C) 2019, Raspberry Pi Ltd * * histogram calculation interface */ #pragma once #include <assert.h> #include <limits.h> #include <stdint.h> #include <type_traits> #include <vector> #include <libcamera/base/span.h> #include <libcamera/base/utils.h> namespace libcamera { namespace ipa { class Histogram { public: Histogram() { cumulative_.push_back(0); } Histogram(Span<const uint32_t> data); template<typename Transform, std::enable_if_t<std::is_invocable_v<Transform, uint32_t>> * = nullptr> Histogram(Span<const uint32_t> data, Transform transform) { cumulative_.resize(data.size() + 1); cumulative_[0] = 0; for (const auto &[i, value] : utils::enumerate(data)) cumulative_[i + 1] = cumulative_[i] + transform(value); } size_t bins() const { return cumulative_.size() - 1; } uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } uint64_t cumulativeFrequency(double bin) const; double quantile(double q, uint32_t first = 0, uint32_t last = UINT_MAX) const; double interQuantileMean(double lowQuantile, double hiQuantile) const; private: std::vector<uint64_t> cumulative_; }; } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/histogram.cpp
/* SPDX-License-Identifier: BSD-2-Clause */ /* * Copyright (C) 2019, Raspberry Pi Ltd * * histogram calculations */ #include "histogram.h" #include <cmath> #include <libcamera/base/log.h> /** * \file histogram.h * \brief Class to represent Histograms and manipulate them */ namespace libcamera { namespace ipa { /** * \class Histogram * \brief The base class for creating histograms * * This class stores a cumulative frequency histogram, which is a mapping that * counts the cumulative number of observations in all of the bins up to the * specified bin. It can be used to find quantiles and averages between quantiles. */ /** * \fn Histogram::Histogram() * \brief Construct an empty Histogram * * This empty constructor exists largely to allow Histograms to be embedded in * other classes which may be created before the contents of the Histogram are * known. */ /** * \brief Create a cumulative histogram * \param[in] data A (non-cumulative) histogram */ Histogram::Histogram(Span<const uint32_t> data) { cumulative_.resize(data.size() + 1); cumulative_[0] = 0; for (const auto &[i, value] : utils::enumerate(data)) cumulative_[i + 1] = cumulative_[i] + value; } /** * \fn Histogram::Histogram(Span<const uint32_t> data, Transform transform) * \brief Create a cumulative histogram * \param[in] data A (non-cumulative) histogram * \param[in] transform The transformation function to apply to every bin */ /** * \fn Histogram::bins() * \brief Retrieve the number of bins currently used by the Histogram * \return Number of bins */ /** * \fn Histogram::total() * \brief Retrieve the total number of values in the data set * \return Number of values */ /** * \brief Cumulative frequency up to a (fractional) point in a bin * \param[in] bin The bin up to which to cumulate * * With F(p) the cumulative frequency of the histogram, the value is 0 at * the bottom of the histogram, and the maximum is the number of bins. * The pixels are spread evenly throughout the “bin” in which they lie, so that * F(p) is a continuous (monotonically increasing) function. * * \return The cumulative frequency from 0 up to the specified bin */ uint64_t Histogram::cumulativeFrequency(double bin) const { if (bin <= 0) return 0; else if (bin >= bins()) return total(); int b = static_cast<int32_t>(bin); return cumulative_[b] + (bin - b) * (cumulative_[b + 1] - cumulative_[b]); } /** * \brief Return the (fractional) bin of the point through the histogram * \param[in] q the desired point (0 <= q <= 1) * \param[in] first low limit (default is 0) * \param[in] last high limit (default is UINT_MAX) * * A quantile gives us the point p = Q(q) in the range such that a proportion * q of the pixels lie below p. A familiar quantile is Q(0.5) which is the median * of a distribution. * * \return The fractional bin of the point */ double Histogram::quantile(double q, uint32_t first, uint32_t last) const { if (last == UINT_MAX) last = cumulative_.size() - 2; ASSERT(first <= last); uint64_t item = q * total(); /* Binary search to find the right bin */ while (first < last) { int middle = (first + last) / 2; /* Is it between first and middle ? */ if (cumulative_[middle + 1] > item) last = middle; else first = middle + 1; } ASSERT(item >= cumulative_[first] && item <= cumulative_[last + 1]); double frac; if (cumulative_[first + 1] == cumulative_[first]) frac = 0; else frac = (item - cumulative_[first]) / (cumulative_[first + 1] - cumulative_[first]); return first + frac; } /** * \brief Calculate the mean between two quantiles * \param[in] lowQuantile low Quantile * \param[in] highQuantile high Quantile * * Quantiles are not ideal for metering as they suffer several limitations. * Instead, a concept is introduced here: inter-quantile mean. * It returns the mean of all pixels between lowQuantile and highQuantile. * * \return The mean histogram bin value between the two quantiles */ double Histogram::interQuantileMean(double lowQuantile, double highQuantile) const { ASSERT(highQuantile > lowQuantile); /* Proportion of pixels which lies below lowQuantile */ double lowPoint = quantile(lowQuantile); /* Proportion of pixels which lies below highQuantile */ double highPoint = quantile(highQuantile, static_cast<uint32_t>(lowPoint)); double sumBinFreq = 0, cumulFreq = 0; for (double p_next = floor(lowPoint) + 1.0; p_next <= ceil(highPoint); lowPoint = p_next, p_next += 1.0) { int bin = floor(lowPoint); double freq = (cumulative_[bin + 1] - cumulative_[bin]) * (std::min(p_next, highPoint) - lowPoint); /* Accumulate weighted bin */ sumBinFreq += bin * freq; /* Accumulate weights */ cumulFreq += freq; } /* add 0.5 to give an average for bin mid-points */ return sumBinFreq / cumulFreq + 0.5; } } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/fc_queue.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2022, Google Inc. * * IPA Frame context queue */ #pragma once #include <stdint.h> #include <vector> #include <libcamera/base/log.h> namespace libcamera { LOG_DECLARE_CATEGORY(FCQueue) namespace ipa { template<typename FrameContext> class FCQueue; struct FrameContext { private: template<typename T> friend class FCQueue; uint32_t frame; }; template<typename FrameContext> class FCQueue { public: FCQueue(unsigned int size) : contexts_(size) { } void clear() { for (FrameContext &ctx : contexts_) ctx.frame = 0; } FrameContext &alloc(const uint32_t frame) { FrameContext &frameContext = contexts_[frame % contexts_.size()]; /* * Do not re-initialise if a get() call has already fetched this * frame context to preseve the context. * * \todo If the the sequence number of the context to initialise * is smaller than the sequence number of the queue slot to use, * it means that we had a serious request underrun and more * frames than the queue size has been produced since the last * time the application has queued a request. Does this deserve * an error condition ? */ if (frame != 0 && frame <= frameContext.frame) LOG(FCQueue, Warning) << "Frame " << frame << " already initialised"; else init(frameContext, frame); return frameContext; } FrameContext &get(uint32_t frame) { FrameContext &frameContext = contexts_[frame % contexts_.size()]; /* * If the IPA algorithms try to access a frame context slot which * has been already overwritten by a newer context, it means the * frame context queue has overflowed and the desired context * has been forever lost. The pipeline handler shall avoid * queueing more requests to the IPA than the frame context * queue size. */ if (frame < frameContext.frame) LOG(FCQueue, Fatal) << "Frame context for " << frame << " has been overwritten by " << frameContext.frame; if (frame == frameContext.frame) return frameContext; /* * The frame context has been retrieved before it was * initialised through the initialise() call. This indicates an * algorithm attempted to access a Frame context before it was * queued to the IPA. Controls applied for this request may be * left unhandled. * * \todo Set an error flag for per-frame control errors. */ LOG(FCQueue, Warning) << "Obtained an uninitialised FrameContext for " << frame; init(frameContext, frame); return frameContext; } private: void init(FrameContext &frameContext, const uint32_t frame) { frameContext = {}; frameContext.frame = frame; } std::vector<FrameContext> contexts_; }; } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/module.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2022, Ideas On Board * * IPA Module */ #include "module.h" /** * \file module.h * \brief IPA Module common interface */ namespace libcamera { LOG_DEFINE_CATEGORY(IPAModuleAlgo) /** * \brief The IPA (Image Processing Algorithm) namespace * * The IPA namespace groups all types specific to IPA modules. It serves as the * top-level namespace for the IPA library libipa, and also contains * module-specific namespaces for IPA modules. */ namespace ipa { /** * \class Module * \brief The base class for all IPA modules * \tparam Context The type of the shared IPA context * \tparam FrameContext The type of the frame context * \tparam Config The type of the IPA configuration data * \tparam Params The type of the ISP specific parameters * \tparam Stats The type of the IPA statistics and ISP results * * The Module class template defines a standard internal interface between IPA * modules and libipa. * * While IPA modules are platform-specific, many of their internal functions are * conceptually similar, even if they take different types of platform-specifc * parameters. For instance, IPA modules could share code that instantiates, * initializes and run algorithms if it wasn't for the fact that the the format * of ISP parameters or statistics passed to the related functions is * device-dependent. * * To enable a shared implementation of those common tasks in libipa, the Module * class template defines a standard internal interface between IPA modules and * libipa. The template parameters specify the types of module-dependent data. * IPA modules shall create a specialization of the Module class template in * their namespace, and use it to specialize other classes of libipa, such as * the Algorithm class. */ /** * \typedef Module::Context * \brief The type of the shared IPA context */ /** * \typedef Module::FrameContext * \brief The type of the frame context */ /** * \typedef Module::Config * \brief The type of the IPA configuration data */ /** * \typedef Module::Params * \brief The type of the ISP specific parameters */ /** * \typedef Module::Stats * \brief The type of the IPA statistics and ISP results */ /** * \fn Module::algorithms() * \brief Retrieve the list of instantiated algorithms * \return The list of instantiated algorithms */ /** * \fn Module::createAlgorithms() * \brief Create algorithms from YAML configuration data * \param[in] context The IPA context * \param[in] algorithms Algorithms configuration data as a parsed YamlObject * * This function iterates over the list of \a algorithms parsed from the YAML * configuration file, and instantiates and initializes the corresponding * algorithms. The configuration data is expected to be correct, any error * causes the function to fail and return immediately. * * \return 0 on success, or a negative error code on failure */ /** * \fn Module::registerAlgorithm() * \brief Add an algorithm factory class to the list of available algorithms * \param[in] factory Factory to use to construct the algorithm * * This function registers an algorithm factory. It is meant to be called by the * AlgorithmFactory constructor only. */ /** * \fn Module::createAlgorithm(const std::string &name) * \brief Create an instance of an Algorithm by name * \param[in] name The algorithm name * * This function is the entry point to algorithm instantiation for the IPA * module. It creates and returns an instance of an algorithm identified by its * \a name. If no such algorithm exists, the function returns nullptr. * * To make an algorithm available to the IPA module, it shall be registered with * the REGISTER_IPA_ALGORITHM() macro. * * \return A new instance of the Algorithm subclass corresponding to the \a name */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/module.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2022, Ideas On Board * * IPA module */ #pragma once #include <list> #include <memory> #include <string> #include <vector> #include <libcamera/base/log.h> #include <libcamera/base/utils.h> #include "libcamera/internal/yaml_parser.h" #include "algorithm.h" namespace libcamera { LOG_DECLARE_CATEGORY(IPAModuleAlgo) namespace ipa { template<typename _Context, typename _FrameContext, typename _Config, typename _Params, typename _Stats> class Module : public Loggable { public: using Context = _Context; using FrameContext = _FrameContext; using Config = _Config; using Params = _Params; using Stats = _Stats; virtual ~Module() {} const std::list<std::unique_ptr<Algorithm<Module>>> &algorithms() const { return algorithms_; } int createAlgorithms(Context &context, const YamlObject &algorithms) { const auto &list = algorithms.asList(); for (const auto &[i, algo] : utils::enumerate(list)) { if (!algo.isDictionary()) { LOG(IPAModuleAlgo, Error) << "Invalid YAML syntax for algorithm " << i; algorithms_.clear(); return -EINVAL; } int ret = createAlgorithm(context, algo); if (ret) { algorithms_.clear(); return ret; } } return 0; } static void registerAlgorithm(AlgorithmFactoryBase<Module> *factory) { factories().push_back(factory); } private: int createAlgorithm(Context &context, const YamlObject &data) { const auto &[name, algoData] = *data.asDict().begin(); std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name); if (!algo) { LOG(IPAModuleAlgo, Error) << "Algorithm '" << name << "' not found"; return -EINVAL; } int ret = algo->init(context, algoData); if (ret) { LOG(IPAModuleAlgo, Error) << "Algorithm '" << name << "' failed to initialize"; return ret; } LOG(IPAModuleAlgo, Debug) << "Instantiated algorithm '" << name << "'"; algorithms_.push_back(std::move(algo)); return 0; } static std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name) { for (const AlgorithmFactoryBase<Module> *factory : factories()) { if (factory->name() == name) return factory->create(); } return nullptr; } static std::vector<AlgorithmFactoryBase<Module> *> &factories() { /* * The static factories map is defined inside the function to ensure * it gets initialized on first use, without any dependency on * link order. */ static std::vector<AlgorithmFactoryBase<Module> *> factories; return factories; } std::list<std::unique_ptr<Algorithm<Module>>> algorithms_; }; } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/algorithm.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas On Board * * ISP control algorithm interface */ #pragma once #include <memory> #include <stdint.h> #include <string> #include <libcamera/controls.h> namespace libcamera { class YamlObject; namespace ipa { template<typename _Module> class Algorithm { public: using Module = _Module; virtual ~Algorithm() {} virtual int init([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const YamlObject &tuningData) { return 0; } virtual int configure([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const typename Module::Config &configInfo) { return 0; } virtual void queueRequest([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] typename Module::FrameContext &frameContext, [[maybe_unused]] const ControlList &controls) { } virtual void prepare([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] typename Module::FrameContext &frameContext, [[maybe_unused]] typename Module::Params *params) { } virtual void process([[maybe_unused]] typename Module::Context &context, [[maybe_unused]] const uint32_t frame, [[maybe_unused]] typename Module::FrameContext &frameContext, [[maybe_unused]] const typename Module::Stats *stats, [[maybe_unused]] ControlList &metadata) { } }; template<typename _Module> class AlgorithmFactoryBase { public: AlgorithmFactoryBase(const char *name) : name_(name) { _Module::registerAlgorithm(this); } virtual ~AlgorithmFactoryBase() = default; const std::string &name() const { return name_; } virtual std::unique_ptr<Algorithm<_Module>> create() const = 0; private: std::string name_; }; template<typename _Algorithm> class AlgorithmFactory : public AlgorithmFactoryBase<typename _Algorithm::Module> { public: AlgorithmFactory(const char *name) : AlgorithmFactoryBase<typename _Algorithm::Module>(name) { } ~AlgorithmFactory() = default; std::unique_ptr<Algorithm<typename _Algorithm::Module>> create() const override { return std::make_unique<_Algorithm>(); } }; #define REGISTER_IPA_ALGORITHM(algorithm, name) \ static AlgorithmFactory<algorithm> global_##algorithm##Factory(name); } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/agc_mean_luminance.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024 Ideas on Board Oy * * Base class for mean luminance AGC algorithms */ #include "agc_mean_luminance.h" #include <cmath> #include <libcamera/base/log.h> #include <libcamera/control_ids.h> #include "exposure_mode_helper.h" using namespace libcamera::controls; /** * \file agc_mean_luminance.h * \brief Base class implementing mean luminance AEGC */ namespace libcamera { using namespace std::literals::chrono_literals; LOG_DEFINE_CATEGORY(AgcMeanLuminance) namespace ipa { /* * Number of frames for which to run the algorithm at full speed, before slowing * down to prevent large and jarring changes in exposure from frame to frame. */ static constexpr uint32_t kNumStartupFrames = 10; /* * Default relative luminance target * * This value should be chosen so that when the camera points at a grey target, * the resulting image brightness looks "right". Custom values can be passed * as the relativeLuminanceTarget value in sensor tuning files. */ static constexpr double kDefaultRelativeLuminanceTarget = 0.16; /** * \struct AgcMeanLuminance::AgcConstraint * \brief The boundaries and target for an AeConstraintMode constraint * * This structure describes an AeConstraintMode constraint for the purposes of * this algorithm. These constraints are expressed as a pair of quantile * boundaries for a histogram, along with a luminance target and a bounds-type. * The algorithm uses the constraints by ensuring that the defined portion of a * luminance histogram (I.E. lying between the two quantiles) is above or below * the given luminance value. */ /** * \enum AgcMeanLuminance::AgcConstraint::Bound * \brief Specify whether the constraint defines a lower or upper bound * \var AgcMeanLuminance::AgcConstraint::Lower * \brief The constraint defines a lower bound * \var AgcMeanLuminance::AgcConstraint::Upper * \brief The constraint defines an upper bound */ /** * \var AgcMeanLuminance::AgcConstraint::bound * \brief The type of constraint bound */ /** * \var AgcMeanLuminance::AgcConstraint::qLo * \brief The lower quantile to use for the constraint */ /** * \var AgcMeanLuminance::AgcConstraint::qHi * \brief The upper quantile to use for the constraint */ /** * \var AgcMeanLuminance::AgcConstraint::yTarget * \brief The luminance target for the constraint */ /** * \class AgcMeanLuminance * \brief A mean-based auto-exposure algorithm * * This algorithm calculates a shutter time, analogue and digital gain such that * the normalised mean luminance value of an image is driven towards a target, * which itself is discovered from tuning data. The algorithm is a two-stage * process. * * In the first stage, an initial gain value is derived by iteratively comparing * the gain-adjusted mean luminance across the entire image against a target, * and selecting a value which pushes it as closely as possible towards the * target. * * In the second stage we calculate the gain required to drive the average of a * section of a histogram to a target value, where the target and the boundaries * of the section of the histogram used in the calculation are taken from the * values defined for the currently configured AeConstraintMode within the * tuning data. This class provides a helper function to parse those tuning data * to discover the constraints, and so requires a specific format for those * data which is described in \ref parseTuningData(). The gain from the first * stage is then clamped to the gain from this stage. * * The final gain is used to adjust the effective exposure value of the image, * and that new exposure value is divided into shutter time, analogue gain and * digital gain according to the selected AeExposureMode. This class uses the * \ref ExposureModeHelper class to assist in that division, and expects the * data needed to initialise that class to be present in tuning data in a * format described in \ref parseTuningData(). * * In order to be able to use this algorithm an IPA module needs to be able to * do the following: * * 1. Provide a luminance estimation across an entire image. * 2. Provide a luminance Histogram for the image to use in calculating * constraint compliance. The precision of the Histogram that is available * will determine the supportable precision of the constraints. * * IPA modules that want to use this class to implement their AEGC algorithm * should derive it and provide an overriding estimateLuminance() function for * this class to use. They must call parseTuningData() in init(), and must also * call setLimits() and resetFrameCounter() in configure(). They may then use * calculateNewEv() in process(). If the limits passed to setLimits() change for * any reason (for example, in response to a FrameDurationLimit control being * passed in queueRequest()) then setLimits() must be called again with the new * values. */ AgcMeanLuminance::AgcMeanLuminance() : frameCount_(0), filteredExposure_(0s), relativeLuminanceTarget_(0) { } AgcMeanLuminance::~AgcMeanLuminance() = default; void AgcMeanLuminance::parseRelativeLuminanceTarget(const YamlObject &tuningData) { relativeLuminanceTarget_ = tuningData["relativeLuminanceTarget"].get<double>(kDefaultRelativeLuminanceTarget); } void AgcMeanLuminance::parseConstraint(const YamlObject &modeDict, int32_t id) { for (const auto &[boundName, content] : modeDict.asDict()) { if (boundName != "upper" && boundName != "lower") { LOG(AgcMeanLuminance, Warning) << "Ignoring unknown constraint bound '" << boundName << "'"; continue; } unsigned int idx = static_cast<unsigned int>(boundName == "upper"); AgcConstraint::Bound bound = static_cast<AgcConstraint::Bound>(idx); double qLo = content["qLo"].get<double>().value_or(0.98); double qHi = content["qHi"].get<double>().value_or(1.0); double yTarget = content["yTarget"].getList<double>().value_or(std::vector<double>{ 0.5 }).at(0); AgcConstraint constraint = { bound, qLo, qHi, yTarget }; if (!constraintModes_.count(id)) constraintModes_[id] = {}; if (idx) constraintModes_[id].push_back(constraint); else constraintModes_[id].insert(constraintModes_[id].begin(), constraint); } } int AgcMeanLuminance::parseConstraintModes(const YamlObject &tuningData) { std::vector<ControlValue> availableConstraintModes; const YamlObject &yamlConstraintModes = tuningData[controls::AeConstraintMode.name()]; if (yamlConstraintModes.isDictionary()) { for (const auto &[modeName, modeDict] : yamlConstraintModes.asDict()) { if (AeConstraintModeNameValueMap.find(modeName) == AeConstraintModeNameValueMap.end()) { LOG(AgcMeanLuminance, Warning) << "Skipping unknown constraint mode '" << modeName << "'"; continue; } if (!modeDict.isDictionary()) { LOG(AgcMeanLuminance, Error) << "Invalid constraint mode '" << modeName << "'"; return -EINVAL; } parseConstraint(modeDict, AeConstraintModeNameValueMap.at(modeName)); availableConstraintModes.push_back( AeConstraintModeNameValueMap.at(modeName)); } } /* * If the tuning data file contains no constraints then we use the * default constraint that the IPU3/RkISP1 Agc algorithms were adhering * to anyway before centralisation; this constraint forces the top 2% of * the histogram to be at least 0.5. */ if (constraintModes_.empty()) { AgcConstraint constraint = { AgcConstraint::Bound::Lower, 0.98, 1.0, 0.5 }; constraintModes_[controls::ConstraintNormal].insert( constraintModes_[controls::ConstraintNormal].begin(), constraint); availableConstraintModes.push_back( AeConstraintModeNameValueMap.at("ConstraintNormal")); } controls_[&controls::AeConstraintMode] = ControlInfo(availableConstraintModes); return 0; } int AgcMeanLuminance::parseExposureModes(const YamlObject &tuningData) { std::vector<ControlValue> availableExposureModes; const YamlObject &yamlExposureModes = tuningData[controls::AeExposureMode.name()]; if (yamlExposureModes.isDictionary()) { for (const auto &[modeName, modeValues] : yamlExposureModes.asDict()) { if (AeExposureModeNameValueMap.find(modeName) == AeExposureModeNameValueMap.end()) { LOG(AgcMeanLuminance, Warning) << "Skipping unknown exposure mode '" << modeName << "'"; continue; } if (!modeValues.isDictionary()) { LOG(AgcMeanLuminance, Error) << "Invalid exposure mode '" << modeName << "'"; return -EINVAL; } std::vector<uint32_t> shutters = modeValues["shutter"].getList<uint32_t>().value_or(std::vector<uint32_t>{}); std::vector<double> gains = modeValues["gain"].getList<double>().value_or(std::vector<double>{}); if (shutters.size() != gains.size()) { LOG(AgcMeanLuminance, Error) << "Shutter and gain array sizes unequal"; return -EINVAL; } if (shutters.empty()) { LOG(AgcMeanLuminance, Error) << "Shutter and gain arrays are empty"; return -EINVAL; } std::vector<std::pair<utils::Duration, double>> stages; for (unsigned int i = 0; i < shutters.size(); i++) { stages.push_back({ std::chrono::microseconds(shutters[i]), gains[i] }); } std::shared_ptr<ExposureModeHelper> helper = std::make_shared<ExposureModeHelper>(stages); exposureModeHelpers_[AeExposureModeNameValueMap.at(modeName)] = helper; availableExposureModes.push_back(AeExposureModeNameValueMap.at(modeName)); } } /* * If we don't have any exposure modes in the tuning data we create an * ExposureModeHelper using an empty vector of stages. This will result * in the ExposureModeHelper simply driving the shutter as high as * possible before touching gain. */ if (availableExposureModes.empty()) { int32_t exposureModeId = AeExposureModeNameValueMap.at("ExposureNormal"); std::vector<std::pair<utils::Duration, double>> stages = { }; std::shared_ptr<ExposureModeHelper> helper = std::make_shared<ExposureModeHelper>(stages); exposureModeHelpers_[exposureModeId] = helper; availableExposureModes.push_back(exposureModeId); } controls_[&controls::AeExposureMode] = ControlInfo(availableExposureModes); return 0; } /** * \brief Parse tuning data for AeConstraintMode and AeExposureMode controls * \param[in] tuningData the YamlObject representing the tuning data * * This function parses tuning data to build the list of allowed values for the * AeConstraintMode and AeExposureMode controls. Those tuning data must provide * the data in a specific format; the Agc algorithm's tuning data should contain * a dictionary called AeConstraintMode containing per-mode setting dictionaries * with the key being a value from \ref controls::AeConstraintModeNameValueMap. * Each mode dict may contain either a "lower" or "upper" key or both, for * example: * * \code{.unparsed} * algorithms: * - Agc: * AeConstraintMode: * ConstraintNormal: * lower: * qLo: 0.98 * qHi: 1.0 * yTarget: 0.5 * ConstraintHighlight: * lower: * qLo: 0.98 * qHi: 1.0 * yTarget: 0.5 * upper: * qLo: 0.98 * qHi: 1.0 * yTarget: 0.8 * * \endcode * * For the AeExposureMode control the data should contain a dictionary called * AeExposureMode containing per-mode setting dictionaries with the key being a * value from \ref controls::AeExposureModeNameValueMap. Each mode dict should * contain an array of shutter times with the key "shutter" and an array of gain * values with the key "gain", in this format: * * \code{.unparsed} * algorithms: * - Agc: * AeExposureMode: * ExposureNormal: * shutter: [ 100, 10000, 30000, 60000, 120000 ] * gain: [ 2.0, 4.0, 6.0, 8.0, 10.0 ] * ExposureShort: * shutter: [ 100, 10000, 30000, 60000, 120000 ] * gain: [ 2.0, 4.0, 6.0, 8.0, 10.0 ] * * \endcode * * \return 0 on success or a negative error code */ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData) { int ret; parseRelativeLuminanceTarget(tuningData); ret = parseConstraintModes(tuningData); if (ret) return ret; return parseExposureModes(tuningData); } /** * \brief Set the ExposureModeHelper limits for this class * \param[in] minShutter Minimum shutter time to allow * \param[in] maxShutter Maximum shutter time to allow * \param[in] minGain Minimum gain to allow * \param[in] maxGain Maximum gain to allow * * This function calls \ref ExposureModeHelper::setLimits() for each * ExposureModeHelper that has been created for this class. */ void AgcMeanLuminance::setLimits(utils::Duration minShutter, utils::Duration maxShutter, double minGain, double maxGain) { for (auto &[id, helper] : exposureModeHelpers_) helper->setLimits(minShutter, maxShutter, minGain, maxGain); } /** * \fn AgcMeanLuminance::constraintModes() * \brief Get the constraint modes that have been parsed from tuning data */ /** * \fn AgcMeanLuminance::exposureModeHelpers() * \brief Get the ExposureModeHelpers that have been parsed from tuning data */ /** * \fn AgcMeanLuminance::controls() * \brief Get the controls that have been generated after parsing tuning data */ /** * \fn AgcMeanLuminance::estimateLuminance(const double gain) * \brief Estimate the luminance of an image, adjusted by a given gain * \param[in] gain The gain with which to adjust the luminance estimate * * This function estimates the average relative luminance of the frame that * would be output by the sensor if an additional \a gain was applied. It is a * pure virtual function because estimation of luminance is a hardware-specific * operation, which depends wholly on the format of the stats that are delivered * to libcamera from the ISP. Derived classes must override this function with * one that calculates the normalised mean luminance value across the entire * image. * * \return The normalised relative luminance of the image */ /** * \brief Estimate the initial gain needed to achieve a relative luminance * target * \return The calculated initial gain */ double AgcMeanLuminance::estimateInitialGain() const { double yTarget = relativeLuminanceTarget_; double yGain = 1.0; /* * To account for non-linearity caused by saturation, the value needs to * be estimated in an iterative process, as multiplying by a gain will * not increase the relative luminance by the same factor if some image * regions are saturated. */ for (unsigned int i = 0; i < 8; i++) { double yValue = estimateLuminance(yGain); double extra_gain = std::min(10.0, yTarget / (yValue + .001)); yGain *= extra_gain; LOG(AgcMeanLuminance, Debug) << "Y value: " << yValue << ", Y target: " << yTarget << ", gives gain " << yGain; if (utils::abs_diff(extra_gain, 1.0) < 0.01) break; } return yGain; } /** * \brief Clamp gain within the bounds of a defined constraint * \param[in] constraintModeIndex The index of the constraint to adhere to * \param[in] hist A histogram over which to calculate inter-quantile means * \param[in] gain The gain to clamp * * \return The gain clamped within the constraint bounds */ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex, const Histogram &hist, double gain) { std::vector<AgcConstraint> &constraints = constraintModes_[constraintModeIndex]; for (const AgcConstraint &constraint : constraints) { double newGain = constraint.yTarget * hist.bins() / hist.interQuantileMean(constraint.qLo, constraint.qHi); if (constraint.bound == AgcConstraint::Bound::Lower && newGain > gain) gain = newGain; if (constraint.bound == AgcConstraint::Bound::Upper && newGain < gain) gain = newGain; } return gain; } /** * \brief Apply a filter on the exposure value to limit the speed of changes * \param[in] exposureValue The target exposure from the AGC algorithm * * The speed of the filter is adaptive, and will produce the target quicker * during startup, or when the target exposure is within 20% of the most recent * filter output. * * \return The filtered exposure */ utils::Duration AgcMeanLuminance::filterExposure(utils::Duration exposureValue) { double speed = 0.2; /* Adapt instantly if we are in startup phase. */ if (frameCount_ < kNumStartupFrames) speed = 1.0; /* * If we are close to the desired result, go faster to avoid making * multiple micro-adjustments. * \todo Make this customisable? */ if (filteredExposure_ < 1.2 * exposureValue && filteredExposure_ > 0.8 * exposureValue) speed = sqrt(speed); filteredExposure_ = speed * exposureValue + filteredExposure_ * (1.0 - speed); return filteredExposure_; } /** * \brief Calculate the new exposure value and splut it between shutter time and gain * \param[in] constraintModeIndex The index of the current constraint mode * \param[in] exposureModeIndex The index of the current exposure mode * \param[in] yHist A Histogram from the ISP statistics to use in constraining * the calculated gain * \param[in] effectiveExposureValue The EV applied to the frame from which the * statistics in use derive * * Calculate a new exposure value to try to obtain the target. The calculated * exposure value is filtered to prevent rapid changes from frame to frame, and * divided into shutter time, analogue and digital gain. * * \return Tuple of shutter time, analogue gain, and digital gain */ std::tuple<utils::Duration, double, double> AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex, uint32_t exposureModeIndex, const Histogram &yHist, utils::Duration effectiveExposureValue) { /* * The pipeline handler should validate that we have received an allowed * value for AeExposureMode. */ std::shared_ptr<ExposureModeHelper> exposureModeHelper = exposureModeHelpers_.at(exposureModeIndex); double gain = estimateInitialGain(); gain = constraintClampGain(constraintModeIndex, yHist, gain); /* * We don't check whether we're already close to the target, because * even if the effective exposure value is the same as the last frame's * we could have switched to an exposure mode that would require a new * pass through the splitExposure() function. */ utils::Duration newExposureValue = effectiveExposureValue * gain; /* * We filter the exposure value to make sure changes are not too jarring * from frame to frame. */ newExposureValue = filterExposure(newExposureValue); frameCount_++; return exposureModeHelper->splitExposure(newExposureValue); } /** * \fn AgcMeanLuminance::resetFrameCount() * \brief Reset the frame counter * * This function resets the internal frame counter, which exists to help the * algorithm decide whether it should respond instantly or not. The expectation * is for derived classes to call this function before each camera start call in * their configure() function. */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/pwl.cpp
/* SPDX-License-Identifier: BSD-2-Clause */ /* * Copyright (C) 2019, Raspberry Pi Ltd * Copyright (C) 2024, Ideas on Board Oy * * Piecewise linear functions */ #include "pwl.h" #include <assert.h> #include <cmath> #include <sstream> #include <stdexcept> /** * \file pwl.h * \brief Piecewise linear functions */ namespace libcamera { namespace ipa { /** * \class Pwl * \brief Describe a univariate piecewise linear function in two-dimensional * real space * * A piecewise linear function is a univariate function that maps reals to * reals, and it is composed of multiple straight-line segments. * * While a mathematical piecewise linear function would usually be defined by * a list of linear functions and for which values of the domain they apply, * this Pwl class is instead defined by a list of points at which these line * segments intersect. These intersecting points are known as knots. * * https://en.wikipedia.org/wiki/Piecewise_linear_function * * A consequence of the Pwl class being defined by knots instead of linear * functions is that the values of the piecewise linear function past the ends * of the function are constants as opposed to linear functions. In a * mathematical piecewise linear function that is defined by multiple linear * functions, the ends of the function are also linear functions and hence grow * to infinity (or negative infinity). However, since this Pwl class is defined * by knots, the y-value of the leftmost and rightmost knots will hold for all * x values to negative infinity and positive infinity, respectively. */ /** * \typedef Pwl::Point * \brief Describe a point in two-dimensional real space */ /** * \class Pwl::Interval * \brief Describe an interval in one-dimensional real space */ /** * \fn Pwl::Interval::Interval(double _start, double _end) * \brief Construct an interval * \param[in] _start Start of the interval * \param[in] _end End of the interval */ /** * \fn Pwl::Interval::contains * \brief Check if a given value falls within the interval * \param[in] value Value to check * \return True if the value falls within the interval, including its bounds, * or false otherwise */ /** * \fn Pwl::Interval::clamp * \brief Clamp a value such that it is within the interval * \param[in] value Value to clamp * \return The clamped value */ /** * \fn Pwl::Interval::length * \brief Compute the length of the interval * \return The length of the interval */ /** * \var Pwl::Interval::start * \brief Start of the interval */ /** * \var Pwl::Interval::end * \brief End of the interval */ /** * \brief Construct an empty piecewise linear function */ Pwl::Pwl() { } /** * \brief Construct a piecewise linear function from a list of 2D points * \param[in] points Vector of points from which to construct the piecewise * linear function * * \a points must be in ascending order of x-value. */ Pwl::Pwl(const std::vector<Point> &points) : points_(points) { } /** * \copydoc Pwl::Pwl(const std::vector<Point> &points) * * The contents of the \a points vector is moved to the newly constructed Pwl * instance. */ Pwl::Pwl(std::vector<Point> &&points) : points_(std::move(points)) { } /** * \brief Append a point to the end of the piecewise linear function * \param[in] x x-coordinate of the point to add to the piecewise linear function * \param[in] y y-coordinate of the point to add to the piecewise linear function * \param[in] eps Epsilon for the minimum x distance between points (optional) * * The point's x-coordinate must be greater than the x-coordinate of the last * (= greatest) point already in the piecewise linear function. */ void Pwl::append(double x, double y, const double eps) { if (points_.empty() || points_.back().x() + eps < x) points_.push_back(Point({ x, y })); } /** * \brief Prepend a point to the beginning of the piecewise linear function * \param[in] x x-coordinate of the point to add to the piecewise linear function * \param[in] y y-coordinate of the point to add to the piecewise linear function * \param[in] eps Epsilon for the minimum x distance between points (optional) * * The point's x-coordinate must be less than the x-coordinate of the first * (= smallest) point already in the piecewise linear function. */ void Pwl::prepend(double x, double y, const double eps) { if (points_.empty() || points_.front().x() - eps > x) points_.insert(points_.begin(), Point({ x, y })); } /** * \fn Pwl::empty() const * \brief Check if the piecewise linear function is empty * \return True if there are no points in the function, false otherwise */ /** * \fn Pwl::size() const * \brief Retrieve the number of points in the piecewise linear function * \return The number of points in the piecewise linear function */ /** * \brief Get the domain of the piecewise linear function * \return An interval representing the domain */ Pwl::Interval Pwl::domain() const { return Interval(points_[0].x(), points_[points_.size() - 1].x()); } /** * \brief Get the range of the piecewise linear function * \return An interval representing the range */ Pwl::Interval Pwl::range() const { double lo = points_[0].y(), hi = lo; for (auto &p : points_) lo = std::min(lo, p.y()), hi = std::max(hi, p.y()); return Interval(lo, hi); } /** * \brief Evaluate the piecewise linear function * \param[in] x The x value to input into the function * \param[inout] span Initial guess for span * \param[in] updateSpan Set to true to update span * * Evaluate Pwl, optionally supplying an initial guess for the * "span". The "span" may be optionally be updated. If you want to know * the "span" value but don't have an initial guess you can set it to * -1. * * \return The result of evaluating the piecewise linear function at position \a x */ double Pwl::eval(double x, int *span, bool updateSpan) const { int index = findSpan(x, span && *span != -1 ? *span : points_.size() / 2 - 1); if (span && updateSpan) *span = index; return points_[index].y() + (x - points_[index].x()) * (points_[index + 1].y() - points_[index].y()) / (points_[index + 1].x() - points_[index].x()); } int Pwl::findSpan(double x, int span) const { /* * Pwls are generally small, so linear search may well be faster than * binary, though could review this if large Pwls start turning up. */ int lastSpan = points_.size() - 2; /* * some algorithms may call us with span pointing directly at the last * control point */ span = std::max(0, std::min(lastSpan, span)); while (span < lastSpan && x >= points_[span + 1].x()) span++; while (span && x < points_[span].x()) span--; return span; } /** * \brief Compute the inverse function * \param[in] eps Epsilon for the minimum x distance between points (optional) * * The output includes whether the resulting inverse function is a proper * (true) inverse, or only a best effort (e.g. input was non-monotonic). * * \return A pair of the inverse piecewise linear function, and whether or not * the result is a proper/true inverse */ std::pair<Pwl, bool> Pwl::inverse(const double eps) const { bool appended = false, prepended = false, neither = false; Pwl inverse; for (Point const &p : points_) { if (inverse.empty()) { inverse.append(p.y(), p.x(), eps); } else if (std::abs(inverse.points_.back().x() - p.y()) <= eps || std::abs(inverse.points_.front().x() - p.y()) <= eps) { /* do nothing */; } else if (p.y() > inverse.points_.back().x()) { inverse.append(p.y(), p.x(), eps); appended = true; } else if (p.y() < inverse.points_.front().x()) { inverse.prepend(p.y(), p.x(), eps); prepended = true; } else { neither = true; } } /* * This is not a proper inverse if we found ourselves putting points * onto both ends of the inverse, or if there were points that couldn't * go on either. */ bool trueInverse = !(neither || (appended && prepended)); return { inverse, trueInverse }; } /** * \brief Compose two piecewise linear functions together * \param[in] other The "other" piecewise linear function * \param[in] eps Epsilon for the minimum x distance between points (optional) * * The "this" function is done first, and "other" after. * * \return The composed piecewise linear function */ Pwl Pwl::compose(Pwl const &other, const double eps) const { double thisX = points_[0].x(), thisY = points_[0].y(); int thisSpan = 0, otherSpan = other.findSpan(thisY, 0); Pwl result({ Point({ thisX, other.eval(thisY, &otherSpan, false) }) }); while (thisSpan != (int)points_.size() - 1) { double dx = points_[thisSpan + 1].x() - points_[thisSpan].x(), dy = points_[thisSpan + 1].y() - points_[thisSpan].y(); if (std::abs(dy) > eps && otherSpan + 1 < (int)other.points_.size() && points_[thisSpan + 1].y() >= other.points_[otherSpan + 1].x() + eps) { /* * next control point in result will be where this * function's y reaches the next span in other */ thisX = points_[thisSpan].x() + (other.points_[otherSpan + 1].x() - points_[thisSpan].y()) * dx / dy; thisY = other.points_[++otherSpan].x(); } else if (std::abs(dy) > eps && otherSpan > 0 && points_[thisSpan + 1].y() <= other.points_[otherSpan - 1].x() - eps) { /* * next control point in result will be where this * function's y reaches the previous span in other */ thisX = points_[thisSpan].x() + (other.points_[otherSpan + 1].x() - points_[thisSpan].y()) * dx / dy; thisY = other.points_[--otherSpan].x(); } else { /* we stay in the same span in other */ thisSpan++; thisX = points_[thisSpan].x(), thisY = points_[thisSpan].y(); } result.append(thisX, other.eval(thisY, &otherSpan, false), eps); } return result; } /** * \brief Apply function to (x, y) values at every control point * \param[in] f Function to be applied */ void Pwl::map(std::function<void(double x, double y)> f) const { for (auto &pt : points_) f(pt.x(), pt.y()); } /** * \brief Apply function to (x, y0, y1) values wherever either Pwl has a * control point. * \param[in] pwl0 First piecewise linear function * \param[in] pwl1 Second piecewise linear function * \param[in] f Function to be applied * * This applies the function \a f to every parameter (x, y0, y1), where x is * the combined list of x-values from \a pwl0 and \a pwl1, y0 is the y-value * for the given x in \a pwl0, and y1 is the y-value for the same x in \a pwl1. */ void Pwl::map2(Pwl const &pwl0, Pwl const &pwl1, std::function<void(double x, double y0, double y1)> f) { int span0 = 0, span1 = 0; double x = std::min(pwl0.points_[0].x(), pwl1.points_[0].x()); f(x, pwl0.eval(x, &span0, false), pwl1.eval(x, &span1, false)); while (span0 < (int)pwl0.points_.size() - 1 || span1 < (int)pwl1.points_.size() - 1) { if (span0 == (int)pwl0.points_.size() - 1) x = pwl1.points_[++span1].x(); else if (span1 == (int)pwl1.points_.size() - 1) x = pwl0.points_[++span0].x(); else if (pwl0.points_[span0 + 1].x() > pwl1.points_[span1 + 1].x()) x = pwl1.points_[++span1].x(); else x = pwl0.points_[++span0].x(); f(x, pwl0.eval(x, &span0, false), pwl1.eval(x, &span1, false)); } } /** * \brief Combine two Pwls * \param[in] pwl0 First piecewise linear function * \param[in] pwl1 Second piecewise linear function * \param[in] f Function to be applied * \param[in] eps Epsilon for the minimum x distance between points (optional) * * Create a new Pwl where the y values are given by running \a f wherever * either pwl has a knot. * * \return The combined pwl */ Pwl Pwl::combine(Pwl const &pwl0, Pwl const &pwl1, std::function<double(double x, double y0, double y1)> f, const double eps) { Pwl result; map2(pwl0, pwl1, [&](double x, double y0, double y1) { result.append(x, f(x, y0, y1), eps); }); return result; } /** * \brief Multiply the piecewise linear function * \param[in] d Scalar multiplier to multiply the function by * \return This function, after it has been multiplied by \a d */ Pwl &Pwl::operator*=(double d) { for (auto &pt : points_) pt[1] *= d; return *this; } /** * \brief Assemble and return a string describing the piecewise linear function * \return A string describing the piecewise linear function */ std::string Pwl::toString() const { std::stringstream ss; ss << "Pwl { "; for (auto &p : points_) ss << "(" << p.x() << ", " << p.y() << ") "; ss << "}"; return ss.str(); } } /* namespace ipa */ #ifndef __DOXYGEN__ /* * The YAML data shall be a list of numerical values with an even number of * elements. They are parsed in pairs into x and y points in the piecewise * linear function, and added in order. x must be monotonically increasing. */ template<> std::optional<ipa::Pwl> YamlObject::Getter<ipa::Pwl>::get(const YamlObject &obj) const { if (!obj.size() || obj.size() % 2) return std::nullopt; ipa::Pwl pwl; const auto &list = obj.asList(); for (auto it = list.begin(); it != list.end(); it++) { auto x = it->get<double>(); if (!x) return std::nullopt; auto y = (++it)->get<double>(); if (!y) return std::nullopt; pwl.append(*x, *y); } if (pwl.size() != obj.size() / 2) return std::nullopt; return pwl; } #endif /* __DOXYGEN__ */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/algorithm.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Ideas On Board * * IPA control algorithm interface */ #include "algorithm.h" /** * \file algorithm.h * \brief Algorithm common interface */ namespace libcamera { namespace ipa { /** * \class Algorithm * \brief The base class for all IPA algorithms * \tparam Module The IPA module type for this class of algorithms * * The Algorithm class defines a standard interface for IPA algorithms * compatible with the \a Module. By abstracting algorithms, it makes possible * the implementation of generic code to manage algorithms regardless of their * specific type. * * To specialize the Algorithm class template, an IPA module shall specialize * the Module class template with module-specific context and configuration * types, and pass the specialized Module class as the \a Module template * argument. */ /** * \typedef Algorithm::Module * \brief The IPA module type for this class of algorithms */ /** * \fn Algorithm::init() * \brief Initialize the Algorithm with tuning data * \param[in] context The shared IPA context * \param[in] tuningData The tuning data for the algorithm * * This function is called once, when the IPA module is initialized, to * initialize the algorithm. The \a tuningData YamlObject contains the tuning * data for algorithm. * * \return 0 if successful, an error code otherwise */ /** * \fn Algorithm::configure() * \brief Configure the Algorithm given an IPAConfigInfo * \param[in] context The shared IPA context * \param[in] configInfo The IPA configuration data, received from the pipeline * handler * * Algorithms may implement a configure operation to pre-calculate * parameters prior to commencing streaming. * * Configuration state may be stored in the IPASessionConfiguration structure of * the IPAContext. * * \return 0 if successful, an error code otherwise */ /** * \fn Algorithm::queueRequest() * \brief Provide control values to the algorithm * \param[in] context The shared IPA context * \param[in] frame The frame number to apply the control values * \param[in] frameContext The current frame's context * \param[in] controls The list of user controls * * This function is called for each request queued to the camera. It provides * the controls stored in the request to the algorithm. The \a frame number * is the Request sequence number and identifies the desired corresponding * frame to target for the controls to take effect. * * Algorithms shall read the applicable controls and store their value for later * use during frame processing. */ /** * \fn Algorithm::prepare() * \brief Fill the \a params buffer with ISP processing parameters for a frame * \param[in] context The shared IPA context * \param[in] frame The frame context sequence number * \param[in] frameContext The FrameContext for this frame * \param[out] params The ISP specific parameters * * This function is called for every frame when the camera is running before it * is processed by the ISP to prepare the ISP processing parameters for that * frame. * * Algorithms shall fill in the parameter structure fields appropriately to * configure the ISP processing blocks that they are responsible for. This * includes setting fields and flags that enable those processing blocks. */ /** * \fn Algorithm::process() * \brief Process ISP statistics, and run algorithm operations * \param[in] context The shared IPA context * \param[in] frame The frame context sequence number * \param[in] frameContext The current frame's context * \param[in] stats The IPA statistics and ISP results * \param[out] metadata Metadata for the frame, to be filled by the algorithm * * This function is called while camera is running for every frame processed by * the ISP, to process statistics generated from that frame by the ISP. * Algorithms shall use this data to run calculations, update their state * accordingly, and fill the frame metadata. * * Processing shall not take an undue amount of time, and any extended or * computationally expensive calculations or operations must be handled * asynchronously in a separate thread. * * Algorithms can store state in their respective IPAFrameContext structures, * and reference state from the IPAFrameContext of other algorithms. * * \todo Historical data may be required as part of the processing. * Either the previous frame, or the IPAFrameContext state of the frame * that generated the statistics for this operation may be required for * some advanced algorithms to prevent oscillations or support control * loops correctly. Only a single IPAFrameContext is available currently, * and so any data stored may represent the results of the previously * completed operations. * * Care shall be taken to ensure the ordering of access to the information * such that the algorithms use up to date state as required. */ /** * \class AlgorithmFactory * \brief Registration of Algorithm classes and creation of instances * \tparam _Algorithm The algorithm class type for this factory * * To facilitate instantiation of Algorithm classes, the AlgorithmFactory class * implements auto-registration of algorithms with the IPA Module class. Each * Algorithm subclass shall register itself using the REGISTER_IPA_ALGORITHM() * macro, which will create a corresponding instance of an AlgorithmFactory and * register it with the IPA Module. */ /** * \fn AlgorithmFactory::AlgorithmFactory() * \brief Construct an algorithm factory * \param[in] name Name of the algorithm class * * Creating an instance of the factory automatically registers is with the IPA * Module class, enabling creation of algorithm instances through * Module::createAlgorithm(). * * The factory \a name identifies the algorithm and shall be unique. */ /** * \fn AlgorithmFactory::create() * \brief Create an instance of the Algorithm corresponding to the factory * \return A pointer to a newly constructed instance of the Algorithm subclass * corresponding to the factory */ /** * \def REGISTER_IPA_ALGORITHM * \brief Register an algorithm with the IPA module * \param[in] algorithm Class name of Algorithm derived class to register * \param[in] name Name of the algorithm * * Register an Algorithm subclass with the IPA module to make it available for * instantiation through Module::createAlgorithm(). The \a name identifies the * algorithm and must be unique across all algorithms registered for the IPA * module. */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/matrix.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Matrix and related operations */ #pragma once #include <algorithm> #include <cmath> #include <sstream> #include <vector> #include <libcamera/base/log.h> #include <libcamera/base/span.h> #include "libcamera/internal/yaml_parser.h" namespace libcamera { LOG_DECLARE_CATEGORY(Matrix) namespace ipa { #ifndef __DOXYGEN__ template<typename T, unsigned int Rows, unsigned int Cols, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr> #else template<typename T, unsigned int Rows, unsigned int Cols> #endif /* __DOXYGEN__ */ class Matrix { public: Matrix() { data_.fill(static_cast<T>(0)); } Matrix(const std::vector<T> &data) { std::copy(data.begin(), data.end(), data_.begin()); } static Matrix identity() { Matrix ret; for (size_t i = 0; i < std::min(Rows, Cols); i++) ret[i][i] = static_cast<T>(1); return ret; } ~Matrix() = default; const std::string toString() const { std::stringstream out; out << "Matrix { "; for (unsigned int i = 0; i < Rows; i++) { out << "[ "; for (unsigned int j = 0; j < Cols; j++) { out << (*this)[i][j]; out << ((j + 1 < Cols) ? ", " : " "); } out << ((i + 1 < Rows) ? "], " : "]"); } out << " }"; return out.str(); } Span<const T, Cols> operator[](size_t i) const { return Span<const T, Cols>{ &data_.data()[i * Cols], Cols }; } Span<T, Cols> operator[](size_t i) { return Span<T, Cols>{ &data_.data()[i * Cols], Cols }; } #ifndef __DOXYGEN__ template<typename U, std::enable_if_t<std::is_arithmetic_v<U>>> #else template<typename U> #endif /* __DOXYGEN__ */ Matrix<T, Rows, Cols> &operator*=(U d) { for (unsigned int i = 0; i < Rows * Cols; i++) data_[i] *= d; return *this; } private: std::array<T, Rows * Cols> data_; }; #ifndef __DOXYGEN__ template<typename T, typename U, unsigned int Rows, unsigned int Cols, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr> #else template<typename T, typename U, unsigned int Rows, unsigned int Cols> #endif /* __DOXYGEN__ */ Matrix<U, Rows, Cols> operator*(T d, const Matrix<U, Rows, Cols> &m) { Matrix<U, Rows, Cols> result; for (unsigned int i = 0; i < Rows; i++) { for (unsigned int j = 0; j < Cols; j++) result[i][j] = d * m[i][j]; } return result; } #ifndef __DOXYGEN__ template<typename T, typename U, unsigned int Rows, unsigned int Cols, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr> #else template<typename T, typename U, unsigned int Rows, unsigned int Cols> #endif /* __DOXYGEN__ */ Matrix<U, Rows, Cols> operator*(const Matrix<U, Rows, Cols> &m, T d) { return d * m; } #ifndef __DOXYGEN__ template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned int C2, std::enable_if_t<C1 == R2> * = nullptr> #else template<typename T, unsigned int R1, unsigned int C1, unsigned int R2, unsigned in C2> #endif /* __DOXYGEN__ */ Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2) { Matrix<T, R1, C2> result; for (unsigned int i = 0; i < R1; i++) { for (unsigned int j = 0; j < C2; j++) { T sum = 0; for (unsigned int k = 0; k < C1; k++) sum += m1[i][k] * m2[k][j]; result[i][j] = sum; } } return result; } template<typename T, unsigned int Rows, unsigned int Cols> Matrix<T, Rows, Cols> operator+(const Matrix<T, Rows, Cols> &m1, const Matrix<T, Rows, Cols> &m2) { Matrix<T, Rows, Cols> result; for (unsigned int i = 0; i < Rows; i++) { for (unsigned int j = 0; j < Cols; j++) result[i][j] = m1[i][j] + m2[i][j]; } return result; } #ifndef __DOXYGEN__ bool matrixValidateYaml(const YamlObject &obj, unsigned int size); #endif /* __DOXYGEN__ */ } /* namespace ipa */ #ifndef __DOXYGEN__ template<typename T, unsigned int Rows, unsigned int Cols> std::ostream &operator<<(std::ostream &out, const ipa::Matrix<T, Rows, Cols> &m) { out << m.toString(); return out; } template<typename T, unsigned int Rows, unsigned int Cols> struct YamlObject::Getter<ipa::Matrix<T, Rows, Cols>> { std::optional<ipa::Matrix<T, Rows, Cols>> get(const YamlObject &obj) const { if (!ipa::matrixValidateYaml(obj, Rows * Cols)) return std::nullopt; ipa::Matrix<T, Rows, Cols> matrix; T *data = &matrix[0][0]; unsigned int i = 0; for (const YamlObject &entry : obj.asList()) { const auto value = entry.get<T>(); if (!value) return std::nullopt; data[i++] = *value; } return matrix; } }; #endif /* __DOXYGEN__ */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/matrix.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Matrix and related operations */ #include "matrix.h" #include <libcamera/base/log.h> /** * \file matrix.h * \brief Matrix class */ namespace libcamera { LOG_DEFINE_CATEGORY(Matrix) namespace ipa { /** * \class Matrix * \brief Matrix class * \tparam T Type of numerical values to be stored in the matrix * \tparam Rows Number of rows in the matrix * \tparam Cols Number of columns in the matrix */ /** * \fn Matrix::Matrix() * \brief Construct a zero matrix */ /** * \fn Matrix::Matrix(const std::vector<T> &data) * \brief Construct a matrix from supplied data * \param[in] data Data from which to construct a matrix * * \a data is a one-dimensional vector and will be turned into a matrix in * row-major order. The size of \a data must be equal to the product of the * number of rows and columns of the matrix (Rows x Cols). */ /** * \fn Matrix::identity() * \brief Construct an identity matrix */ /** * \fn Matrix::toString() * \brief Assemble and return a string describing the matrix * \return A string describing the matrix */ /** * \fn Span<const T, Cols> Matrix::operator[](size_t i) const * \brief Index to a row in the matrix * \param[in] i Index of row to retrieve * * This operator[] returns a Span, which can then be indexed into again with * another operator[], allowing a convenient m[i][j] to access elements of the * matrix. Note that the lifetime of the Span returned by this first-level * operator[] is bound to that of the Matrix itself, so it is not recommended * to save the Span that is the result of this operator[]. * * \return Row \a i from the matrix, as a Span */ /** * \fn Matrix::operator[](size_t i) * \copydoc Matrix::operator[](size_t i) const */ /** * \fn Matrix<T, Rows, Cols> &Matrix::operator*=(U d) * \brief Multiply the matrix by a scalar in-place * \tparam U Type of the numerical scalar value * \param d The scalar multiplier * \return Product of this matrix and scalar \a d */ /** * \fn Matrix::Matrix<U, Rows, Cols> operator*(T d, const Matrix<U, Rows, Cols> &m) * \brief Multiply the matrix by a scalar * \tparam T Type of the numerical scalar value * \tparam U Type of numerical values in the matrix * \tparam Rows Number of rows in the matrix * \tparam Cols Number of columns in the matrix * \param d The scalar multiplier * \param m The matrix * \return Product of scalar \a d and matrix \a m */ /** * \fn Matrix::Matrix<U, Rows, Cols> operator*(const Matrix<U, Rows, Cols> &m, T d) * \copydoc operator*(T d, const Matrix<U, Rows, Cols> &m) */ /** * \fn Matrix<T, R1, C2> operator*(const Matrix<T, R1, C1> &m1, const Matrix<T, R2, C2> &m2) * \brief Matrix multiplication * \tparam T Type of numerical values in the matrices * \tparam R1 Number of rows in the first matrix * \tparam C1 Number of columns in the first matrix * \tparam R2 Number of rows in the second matrix * \tparam C2 Number of columns in the second matrix * \param m1 Multiplicand matrix * \param m2 Multiplier matrix * \return Matrix product of matrices \a m1 and \a m2 */ /** * \fn Matrix<T, Rows, Cols> operator+(const Matrix<T, Rows, Cols> &m1, const Matrix<T, Rows, Cols> &m2) * \brief Matrix addition * \tparam T Type of numerical values in the matrices * \tparam Rows Number of rows in the matrices * \tparam Cols Number of columns in the matrices * \param m1 Summand matrix * \param m2 Summand matrix * \return Matrix sum of matrices \a m1 and \a m2 */ #ifndef __DOXYGEN__ /* * The YAML data shall be a list of numerical values. Its size shall be equal * to the product of the number of rows and columns of the matrix (Rows x * Cols). The values shall be stored in row-major order. */ bool matrixValidateYaml(const YamlObject &obj, unsigned int size) { if (!obj.isList()) return false; if (obj.size() != size) { LOG(Matrix, Error) << "Wrong number of values in matrix: expected " << size << ", got " << obj.size(); return false; } return true; } #endif /* __DOXYGEN__ */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/fc_queue.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2022, Google Inc. * * IPA Frame context queue */ #include "fc_queue.h" #include <libcamera/base/log.h> namespace libcamera { LOG_DEFINE_CATEGORY(FCQueue) namespace ipa { /** * \file fc_queue.h * \brief Queue of per-frame contexts */ /** * \struct FrameContext * \brief Context for a frame * * The frame context stores data specific to a single frame processed by the * IPA module. Each frame processed by the IPA module has a context associated * with it, accessible through the Frame Context Queue. * * Fields in the frame context should reflect values and controls associated * with the specific frame as requested by the application, and as configured by * the hardware. Fields can be read by algorithms to determine if they should * update any specific action for this frame, and finally to update the metadata * control lists when the frame is fully completed. * * \var FrameContext::frame * \brief The frame number */ /** * \class FCQueue * \brief A support class for managing FrameContext instances in IPA modules * \tparam FrameContext The IPA module-specific FrameContext derived class type * * Along with the Module and Algorithm classes, the frame context queue is a * core component of the libipa infrastructure. It stores per-frame contexts * used by the Algorithm operations. By centralizing the lifetime management of * the contexts and implementing safeguards against underflows and overflows, it * simplifies IPA modules and improves their reliability. * * The queue references frame contexts by a monotonically increasing sequence * number. The FCQueue design assumes that this number matches both the sequence * number of the corresponding frame, as generated by the camera sensor, and the * sequence number of the request. This allows IPA modules to obtain the frame * context from any location where a request or a frame is available. * * A frame context normally begins its lifetime when the corresponding request * is queued, way before the frame is captured by the camera sensor. IPA modules * allocate the context from the queue at that point, calling alloc() using the * request number. The queue initializes the context, and the IPA module then * populates it with data from the request. The context can be later retrieved * with a call to get(), typically when the IPA module is requested to provide * sensor or ISP parameters or receives statistics for a frame. The frame number * is used at that point to identify the context. * * If an application fails to queue requests to the camera fast enough, frames * may be produced by the camera sensor and processed by the IPA module without * a corresponding request having been queued to the IPA module. This creates an * underrun condition, where the IPA module will try to get a frame context that * hasn't been allocated. In this case, the get() function will allocate and * initialize a context for the frame, and log a message. Algorithms will not * apply the controls associated with the late request, but should otherwise * behave correctly. * * \todo Mark the frame context with a per-frame control error flag in case of * underrun, and research how algorithms should handle this. * * At its core, the queue uses a circular buffer to avoid dynamic memory * allocation at runtime. The buffer is pre-allocated with a maximum number of * entries when the FCQueue instance is constructed. Entries are initialized on * first use by alloc() or, in underrun conditions, get(). The queue is not * allowed to overflow, which must be ensured by pipeline handlers never * queuing more in-flight requests to the IPA module than the queue size. If an * overflow condition is detected, the queue will log a fatal error. * * IPA module-specific frame context implementations shall inherit from the * FrameContext base class to support the minimum required features for a * FrameContext. */ /** * \fn FCQueue::FCQueue(unsigned int size) * \brief Construct a frame contexts queue of a specified size * \param[in] size The number of contexts in the queue */ /** * \fn FCQueue::clear() * \brief Clear the contexts queue * * IPA modules must clear the frame context queue at the beginning of a new * streaming session, in IPAModule::start(). * * \todo Fix any issue this may cause with requests queued before the camera is * started. */ /** * \fn FCQueue::alloc(uint32_t frame) * \brief Allocate and return a FrameContext for the \a frame * \param[in] frame The frame context sequence number * * The first call to obtain a FrameContext from the FCQueue should be handled * through this function. The FrameContext will be initialised, if not * initialised already, and returned to the caller. * * If the FrameContext was already initialized for this \a frame, a warning will * be reported and the previously initialized FrameContext is returned. * * Frame contexts are expected to be initialised when a Request is first passed * to the IPA module in IPAModule::queueRequest(). * * \return A reference to the FrameContext for sequence \a frame */ /** * \fn FCQueue::get(uint32_t frame) * \brief Obtain the FrameContext for the \a frame * \param[in] frame The frame context sequence number * * If the FrameContext is not correctly initialised for the \a frame, it will be * initialised. * * \return A reference to the FrameContext for sequence \a frame */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/pwl.h
/* SPDX-License-Identifier: BSD-2-Clause */ /* * Copyright (C) 2019, Raspberry Pi Ltd * * Piecewise linear functions interface */ #pragma once #include <algorithm> #include <cmath> #include <functional> #include <string> #include <utility> #include <vector> #include "libcamera/internal/yaml_parser.h" #include "vector.h" namespace libcamera { namespace ipa { class Pwl { public: using Point = Vector<double, 2>; struct Interval { Interval(double _start, double _end) : start(_start), end(_end) {} bool contains(double value) { return value >= start && value <= end; } double clamp(double value) { return std::clamp(value, start, end); } double length() const { return end - start; } double start, end; }; Pwl(); Pwl(const std::vector<Point> &points); Pwl(std::vector<Point> &&points); void append(double x, double y, double eps = 1e-6); bool empty() const { return points_.empty(); } size_t size() const { return points_.size(); } Interval domain() const; Interval range() const; double eval(double x, int *span = nullptr, bool updateSpan = true) const; std::pair<Pwl, bool> inverse(double eps = 1e-6) const; Pwl compose(const Pwl &other, double eps = 1e-6) const; void map(std::function<void(double x, double y)> f) const; static Pwl combine(const Pwl &pwl0, const Pwl &pwl1, std::function<double(double x, double y0, double y1)> f, double eps = 1e-6); Pwl &operator*=(double d); std::string toString() const; private: static void map2(const Pwl &pwl0, const Pwl &pwl1, std::function<void(double x, double y0, double y1)> f); void prepend(double x, double y, double eps = 1e-6); int findSpan(double x, int span) const; std::vector<Point> points_; }; } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/camera_sensor_helper.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google Inc. * * Helper class that performs sensor-specific * parameter computations */ #include "camera_sensor_helper.h" #include <cmath> #include <libcamera/base/log.h> /** * \file camera_sensor_helper.h * \brief Helper class that performs sensor-specific parameter computations * * Computation of sensor configuration parameters is a sensor specific * operation. Each CameraHelper derived class computes the value of * configuration parameters, for example the analogue gain value, using * sensor-specific functions and constants. * * Every subclass of CameraSensorHelper shall be registered with libipa using * the REGISTER_CAMERA_SENSOR_HELPER() macro. */ namespace libcamera { LOG_DEFINE_CATEGORY(CameraSensorHelper) namespace ipa { /** * \class CameraSensorHelper * \brief Base class for computing sensor tuning parameters using * sensor-specific constants * * Instances derived from CameraSensorHelper class are sensor-specific. * Each supported sensor will have an associated base class defined. */ /** * \brief Construct a CameraSensorHelper instance * * CameraSensorHelper derived class instances shall never be constructed * manually but always through the CameraSensorHelperFactoryBase::create() * function. */ /** * \brief Compute gain code from the analogue gain absolute value * \param[in] gain The real gain to pass * * This function aims to abstract the calculation of the gain letting the IPA * use the real gain for its estimations. * * \return The gain code to pass to V4L2 */ uint32_t CameraSensorHelper::gainCode(double gain) const { const AnalogueGainConstants &k = gainConstants_; switch (gainType_) { case AnalogueGainLinear: ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); return (k.linear.c0 - k.linear.c1 * gain) / (k.linear.m1 * gain - k.linear.m0); case AnalogueGainExponential: ASSERT(k.exp.a != 0 && k.exp.m != 0); return std::log2(gain / k.exp.a) / k.exp.m; default: ASSERT(false); return 0; } } /** * \brief Compute the real gain from the V4L2 subdev control gain code * \param[in] gainCode The V4L2 subdev control gain * * This function aims to abstract the calculation of the gain letting the IPA * use the real gain for its estimations. It is the counterpart of the function * CameraSensorHelper::gainCode. * * \return The real gain */ double CameraSensorHelper::gain(uint32_t gainCode) const { const AnalogueGainConstants &k = gainConstants_; double gain = static_cast<double>(gainCode); switch (gainType_) { case AnalogueGainLinear: ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); return (k.linear.m0 * gain + k.linear.c0) / (k.linear.m1 * gain + k.linear.c1); case AnalogueGainExponential: ASSERT(k.exp.a != 0 && k.exp.m != 0); return k.exp.a * std::exp2(k.exp.m * gain); default: ASSERT(false); return 0.0; } } /** * \enum CameraSensorHelper::AnalogueGainType * \brief The gain calculation modes as defined by the MIPI CCS * * Describes the image sensor analogue gain capabilities. * Two modes are possible, depending on the sensor: Linear and Exponential. */ /** * \var CameraSensorHelper::AnalogueGainLinear * \brief Gain is computed using linear gain estimation * * The relationship between the integer gain parameter and the resulting gain * multiplier is given by the following equation: * * \f$gain=\frac{m0x+c0}{m1x+c1}\f$ * * Where 'x' is the gain control parameter, and m0, m1, c0 and c1 are * image-sensor-specific constants of the sensor. * These constants are static parameters, and for any given image sensor either * m0 or m1 shall be zero. * * The full Gain equation therefore reduces to either: * * \f$gain=\frac{c0}{m1x+c1}\f$ or \f$\frac{m0x+c0}{c1}\f$ */ /** * \var CameraSensorHelper::AnalogueGainExponential * \brief Gain is expressed using an exponential model * * The relationship between the integer gain parameter and the resulting gain * multiplier is given by the following equation: * * \f$gain = a \cdot 2^{m \cdot x}\f$ * * Where 'x' is the gain control parameter, and 'a' and 'm' are image * sensor-specific constants. * * This is a subset of the MIPI CCS exponential gain model with the linear * factor 'a' being a constant, but with the exponent being configurable * through the 'm' coefficient. * * When the gain is expressed in dB, 'a' is equal to 1 and 'm' to * \f$log_{2}{10^{\frac{1}{20}}}\f$. */ /** * \struct CameraSensorHelper::AnalogueGainLinearConstants * \brief Analogue gain constants for the linear gain model * * \var CameraSensorHelper::AnalogueGainLinearConstants::m0 * \brief Constant used in the linear gain coding/decoding * * \note Either m0 or m1 shall be zero. * * \var CameraSensorHelper::AnalogueGainLinearConstants::c0 * \brief Constant used in the linear gain coding/decoding * * \var CameraSensorHelper::AnalogueGainLinearConstants::m1 * \brief Constant used in the linear gain coding/decoding * * \note Either m0 or m1 shall be zero. * * \var CameraSensorHelper::AnalogueGainLinearConstants::c1 * \brief Constant used in the linear gain coding/decoding */ /** * \struct CameraSensorHelper::AnalogueGainExpConstants * \brief Analogue gain constants for the exponential gain model * * \var CameraSensorHelper::AnalogueGainExpConstants::a * \brief Constant used in the exponential gain coding/decoding * * \var CameraSensorHelper::AnalogueGainExpConstants::m * \brief Constant used in the exponential gain coding/decoding */ /** * \struct CameraSensorHelper::AnalogueGainConstants * \brief Analogue gain model constants * * This union stores the constants used to calculate the analogue gain. The * CameraSensorHelper::gainType_ variable selects which union member is valid. * * \var CameraSensorHelper::AnalogueGainConstants::linear * \brief Constants for the linear gain model * * \var CameraSensorHelper::AnalogueGainConstants::exp * \brief Constants for the exponential gain model */ /** * \var CameraSensorHelper::gainType_ * \brief The analogue gain model type */ /** * \var CameraSensorHelper::gainConstants_ * \brief The analogue gain parameters used for calculation * * The analogue gain is calculated through a formula, and its parameters are * sensor specific. Use this variable to store the values at init time. */ /** * \class CameraSensorHelperFactoryBase * \brief Base class for camera sensor helper factories * * The CameraSensorHelperFactoryBase class is the base of all specializations of * the CameraSensorHelperFactory class template. It implements the factory * registration, maintains a registry of factories, and provides access to the * registered factories. */ /** * \brief Construct a camera sensor helper factory base * \param[in] name Name of the camera sensor helper class * * Creating an instance of the factory base registers it with the global list of * factories, accessible through the factories() function. * * The factory \a name is used to look up factories and shall be unique. */ CameraSensorHelperFactoryBase::CameraSensorHelperFactoryBase(const std::string name) : name_(name) { registerType(this); } /** * \brief Create an instance of the CameraSensorHelper corresponding to * a named factory * \param[in] name Name of the factory * * \return A unique pointer to a new instance of the CameraSensorHelper subclass * corresponding to the named factory or a null pointer if no such factory * exists */ std::unique_ptr<CameraSensorHelper> CameraSensorHelperFactoryBase::create(const std::string &name) { const std::vector<CameraSensorHelperFactoryBase *> &factories = CameraSensorHelperFactoryBase::factories(); for (const CameraSensorHelperFactoryBase *factory : factories) { if (name != factory->name_) continue; return factory->createInstance(); } return nullptr; } /** * \brief Add a camera sensor helper class to the registry * \param[in] factory Factory to use to construct the camera sensor helper * * The caller is responsible to guarantee the uniqueness of the camera sensor * helper name. */ void CameraSensorHelperFactoryBase::registerType(CameraSensorHelperFactoryBase *factory) { std::vector<CameraSensorHelperFactoryBase *> &factories = CameraSensorHelperFactoryBase::factories(); factories.push_back(factory); } /** * \brief Retrieve the list of all camera sensor helper factories * \return The list of camera sensor helper factories */ std::vector<CameraSensorHelperFactoryBase *> &CameraSensorHelperFactoryBase::factories() { /* * The static factories map is defined inside the function to ensure * it gets initialized on first use, without any dependency on link * order. */ static std::vector<CameraSensorHelperFactoryBase *> factories; return factories; } /** * \class CameraSensorHelperFactory * \brief Registration of CameraSensorHelperFactory classes and creation of instances * \tparam _Helper The camera sensor helper class type for this factory * * To facilitate discovery and instantiation of CameraSensorHelper classes, the * CameraSensorHelperFactory class implements auto-registration of camera sensor * helpers. Each CameraSensorHelper subclass shall register itself using the * REGISTER_CAMERA_SENSOR_HELPER() macro, which will create a corresponding * instance of a CameraSensorHelperFactory subclass and register it with the * static list of factories. */ /** * \fn CameraSensorHelperFactory::CameraSensorHelperFactory(const char *name) * \brief Construct a camera sensor helper factory * \param[in] name Name of the camera sensor helper class * * Creating an instance of the factory registers it with the global list of * factories, accessible through the CameraSensorHelperFactoryBase::factories() * function. * * The factory \a name is used to look up factories and shall be unique. */ /** * \fn CameraSensorHelperFactory::createInstance() const * \brief Create an instance of the CameraSensorHelper corresponding to the * factory * * \return A unique pointer to a newly constructed instance of the * CameraSensorHelper subclass corresponding to the factory */ /** * \def REGISTER_CAMERA_SENSOR_HELPER * \brief Register a camera sensor helper with the camera sensor helper factory * \param[in] name Sensor model name used to register the class * \param[in] helper Class name of CameraSensorHelper derived class to register * * Register a CameraSensorHelper subclass with the factory and make it available * to try and match sensors. */ /* ----------------------------------------------------------------------------- * Sensor-specific subclasses */ #ifndef __DOXYGEN__ /* * Helper function to compute the m parameter of the exponential gain model * when the gain code is expressed in dB. */ static constexpr double expGainDb(double step) { constexpr double log2_10 = 3.321928094887362; /* * The gain code is expressed in step * dB (e.g. in 0.1 dB steps): * * G_code = G_dB/step = 20/step*log10(G_linear) * * Inverting the formula, we get * * G_linear = 10^(step/20*G_code) = 2^(log2(10)*step/20*G_code) */ return log2_10 * step / 20; } class CameraSensorHelperAr0521 : public CameraSensorHelper { public: uint32_t gainCode(double gain) const override { gain = std::clamp(gain, 1.0, 15.5); unsigned int coarse = std::log2(gain); unsigned int fine = (gain / (1 << coarse) - 1) * kStep_; return (coarse << 4) | (fine & 0xf); } double gain(uint32_t gainCode) const override { unsigned int coarse = gainCode >> 4; unsigned int fine = gainCode & 0xf; return (1 << coarse) * (1 + fine / kStep_); } private: static constexpr double kStep_ = 16; }; REGISTER_CAMERA_SENSOR_HELPER("ar0521", CameraSensorHelperAr0521) class CameraSensorHelperImx219 : public CameraSensorHelper { public: CameraSensorHelperImx219() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 0, 256, -1, 256 }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx219", CameraSensorHelperImx219) class CameraSensorHelperImx258 : public CameraSensorHelper { public: CameraSensorHelperImx258() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 0, 512, -1, 512 }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx258", CameraSensorHelperImx258) class CameraSensorHelperImx283 : public CameraSensorHelper { public: CameraSensorHelperImx283() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 0, 2048, -1, 2048 }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx283", CameraSensorHelperImx283) class CameraSensorHelperImx290 : public CameraSensorHelper { public: CameraSensorHelperImx290() { gainType_ = AnalogueGainExponential; gainConstants_.exp = { 1.0, expGainDb(0.3) }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx290", CameraSensorHelperImx290) class CameraSensorHelperImx296 : public CameraSensorHelper { public: CameraSensorHelperImx296() { gainType_ = AnalogueGainExponential; gainConstants_.exp = { 1.0, expGainDb(0.1) }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx296", CameraSensorHelperImx296) class CameraSensorHelperImx327 : public CameraSensorHelperImx290 { }; REGISTER_CAMERA_SENSOR_HELPER("imx327", CameraSensorHelperImx327) class CameraSensorHelperImx335 : public CameraSensorHelper { public: CameraSensorHelperImx335() { gainType_ = AnalogueGainExponential; gainConstants_.exp = { 1.0, expGainDb(0.3) }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx335", CameraSensorHelperImx335) class CameraSensorHelperImx415 : public CameraSensorHelper { public: CameraSensorHelperImx415() { gainType_ = AnalogueGainExponential; gainConstants_.exp = { 1.0, expGainDb(0.3) }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx415", CameraSensorHelperImx415) class CameraSensorHelperImx477 : public CameraSensorHelper { public: CameraSensorHelperImx477() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 0, 1024, -1, 1024 }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx477", CameraSensorHelperImx477) class CameraSensorHelperOv2685 : public CameraSensorHelper { public: CameraSensorHelperOv2685() { /* * The Sensor Manual doesn't appear to document the gain model. * This has been validated with some empirical testing only. */ gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov2685", CameraSensorHelperOv2685) class CameraSensorHelperOv2740 : public CameraSensorHelper { public: CameraSensorHelperOv2740() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov2740", CameraSensorHelperOv2740) class CameraSensorHelperOv4689 : public CameraSensorHelper { public: CameraSensorHelperOv4689() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov4689", CameraSensorHelperOv4689) class CameraSensorHelperOv5640 : public CameraSensorHelper { public: CameraSensorHelperOv5640() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 16 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov5640", CameraSensorHelperOv5640) class CameraSensorHelperOv5647 : public CameraSensorHelper { public: CameraSensorHelperOv5647() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 16 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov5647", CameraSensorHelperOv5647) class CameraSensorHelperOv5670 : public CameraSensorHelper { public: CameraSensorHelperOv5670() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov5670", CameraSensorHelperOv5670) class CameraSensorHelperOv5675 : public CameraSensorHelper { public: CameraSensorHelperOv5675() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov5675", CameraSensorHelperOv5675) class CameraSensorHelperOv5693 : public CameraSensorHelper { public: CameraSensorHelperOv5693() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 16 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) class CameraSensorHelperOv64a40 : public CameraSensorHelper { public: CameraSensorHelperOv64a40() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov64a40", CameraSensorHelperOv64a40) class CameraSensorHelperOv8858 : public CameraSensorHelper { public: CameraSensorHelperOv8858() { gainType_ = AnalogueGainLinear; /* * \todo Validate the selected 1/128 step value as it differs * from what the sensor manual describes. * * See: https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/#142267 */ gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov8858", CameraSensorHelperOv8858) class CameraSensorHelperOv8865 : public CameraSensorHelper { public: CameraSensorHelperOv8865() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov8865", CameraSensorHelperOv8865) class CameraSensorHelperOv13858 : public CameraSensorHelper { public: CameraSensorHelperOv13858() { gainType_ = AnalogueGainLinear; gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov13858", CameraSensorHelperOv13858) #endif /* __DOXYGEN__ */ } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/camera_sensor_helper.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google Inc. * * Helper class that performs sensor-specific parameter computations */ #pragma once #include <stdint.h> #include <memory> #include <string> #include <vector> #include <libcamera/base/class.h> namespace libcamera { namespace ipa { class CameraSensorHelper { public: CameraSensorHelper() = default; virtual ~CameraSensorHelper() = default; virtual uint32_t gainCode(double gain) const; virtual double gain(uint32_t gainCode) const; protected: enum AnalogueGainType { AnalogueGainLinear, AnalogueGainExponential, }; struct AnalogueGainLinearConstants { int16_t m0; int16_t c0; int16_t m1; int16_t c1; }; struct AnalogueGainExpConstants { double a; double m; }; union AnalogueGainConstants { AnalogueGainLinearConstants linear; AnalogueGainExpConstants exp; }; AnalogueGainType gainType_; AnalogueGainConstants gainConstants_; private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper) }; class CameraSensorHelperFactoryBase { public: CameraSensorHelperFactoryBase(const std::string name); virtual ~CameraSensorHelperFactoryBase() = default; static std::unique_ptr<CameraSensorHelper> create(const std::string &name); static std::vector<CameraSensorHelperFactoryBase *> &factories(); private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactoryBase) static void registerType(CameraSensorHelperFactoryBase *factory); virtual std::unique_ptr<CameraSensorHelper> createInstance() const = 0; std::string name_; }; template<typename _Helper> class CameraSensorHelperFactory final : public CameraSensorHelperFactoryBase { public: CameraSensorHelperFactory(const char *name) : CameraSensorHelperFactoryBase(name) { } private: std::unique_ptr<CameraSensorHelper> createInstance() const override { return std::make_unique<_Helper>(); } }; #define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \ static CameraSensorHelperFactory<helper> global_##helper##Factory(name); } /* namespace ipa */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/libipa/vector.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Vector and related operations */ #pragma once #include <algorithm> #include <array> #include <cmath> #include <sstream> #include <libcamera/base/log.h> #include <libcamera/base/span.h> #include "libcamera/internal/yaml_parser.h" #include "matrix.h" namespace libcamera { LOG_DECLARE_CATEGORY(Vector) namespace ipa { #ifndef __DOXYGEN__ template<typename T, unsigned int Rows, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr> #else template<typename T, unsigned int Rows> #endif /* __DOXYGEN__ */ class Vector { public: constexpr Vector() = default; constexpr Vector(const std::array<T, Rows> &data) { for (unsigned int i = 0; i < Rows; i++) data_[i] = data[i]; } const T &operator[](size_t i) const { ASSERT(i < data_.size()); return data_[i]; } T &operator[](size_t i) { ASSERT(i < data_.size()); return data_[i]; } #ifndef __DOXYGEN__ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>> #endif /* __DOXYGEN__ */ constexpr T x() const { return data_[0]; } #ifndef __DOXYGEN__ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 2>> #endif /* __DOXYGEN__ */ constexpr T y() const { return data_[1]; } #ifndef __DOXYGEN__ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 3>> #endif /* __DOXYGEN__ */ constexpr T z() const { return data_[2]; } constexpr Vector<T, Rows> operator-() const { Vector<T, Rows> ret; for (unsigned int i = 0; i < Rows; i++) ret[i] = -data_[i]; return ret; } constexpr Vector<T, Rows> operator-(const Vector<T, Rows> &other) const { Vector<T, Rows> ret; for (unsigned int i = 0; i < Rows; i++) ret[i] = data_[i] - other[i]; return ret; } constexpr Vector<T, Rows> operator+(const Vector<T, Rows> &other) const { Vector<T, Rows> ret; for (unsigned int i = 0; i < Rows; i++) ret[i] = data_[i] + other[i]; return ret; } constexpr T operator*(const Vector<T, Rows> &other) const { T ret = 0; for (unsigned int i = 0; i < Rows; i++) ret += data_[i] * other[i]; return ret; } constexpr Vector<T, Rows> operator*(T factor) const { Vector<T, Rows> ret; for (unsigned int i = 0; i < Rows; i++) ret[i] = data_[i] * factor; return ret; } constexpr Vector<T, Rows> operator/(T factor) const { Vector<T, Rows> ret; for (unsigned int i = 0; i < Rows; i++) ret[i] = data_[i] / factor; return ret; } constexpr double length2() const { double ret = 0; for (unsigned int i = 0; i < Rows; i++) ret += data_[i] * data_[i]; return ret; } constexpr double length() const { return std::sqrt(length2()); } private: std::array<T, Rows> data_; }; template<typename T, unsigned int Rows, unsigned int Cols> Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols> &v) { Vector<T, Rows> result; for (unsigned int i = 0; i < Rows; i++) { T sum = 0; for (unsigned int j = 0; j < Cols; j++) sum += m[i][j] * v[j]; result[i] = sum; } return result; } template<typename T, unsigned int Rows> bool operator==(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) { for (unsigned int i = 0; i < Rows; i++) { if (lhs[i] != rhs[i]) return false; } return true; } template<typename T, unsigned int Rows> bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs) { return !(lhs == rhs); } #ifndef __DOXYGEN__ bool vectorValidateYaml(const YamlObject &obj, unsigned int size); #endif /* __DOXYGEN__ */ } /* namespace ipa */ #ifndef __DOXYGEN__ template<typename T, unsigned int Rows> std::ostream &operator<<(std::ostream &out, const ipa::Vector<T, Rows> &v) { out << "Vector { "; for (unsigned int i = 0; i < Rows; i++) { out << v[i]; out << ((i + 1 < Rows) ? ", " : " "); } out << " }"; return out; } template<typename T, unsigned int Rows> struct YamlObject::Getter<ipa::Vector<T, Rows>> { std::optional<ipa::Vector<T, Rows>> get(const YamlObject &obj) const { if (!ipa::vectorValidateYaml(obj, Rows)) return std::nullopt; ipa::Vector<T, Rows> vector; unsigned int i = 0; for (const YamlObject &entry : obj.asList()) { const auto value = entry.get<T>(); if (!value) return std::nullopt; vector[i++] = *value; } return vector; } }; #endif /* __DOXYGEN__ */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/rkisp1/ipa_context.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021-2022, Ideas On Board * * RkISP1 IPA Context * */ #pragma once #include <linux/rkisp1-config.h> #include <libcamera/base/utils.h> #include <libcamera/control_ids.h> #include <libcamera/controls.h> #include <libcamera/geometry.h> #include <libipa/fc_queue.h> #include <libipa/matrix.h> namespace libcamera { namespace ipa::rkisp1 { struct IPAHwSettings { unsigned int numAeCells; unsigned int numHistogramBins; unsigned int numHistogramWeights; unsigned int numGammaOutSamples; }; struct IPASessionConfiguration { struct { struct rkisp1_cif_isp_window measureWindow; } agc; struct { struct rkisp1_cif_isp_window measureWindow; bool enabled; } awb; struct { bool enabled; } lsc; struct { utils::Duration minShutterSpeed; utils::Duration maxShutterSpeed; double minAnalogueGain; double maxAnalogueGain; int32_t defVBlank; utils::Duration lineDuration; Size size; } sensor; bool raw; }; struct IPAActiveState { struct { struct { uint32_t exposure; double gain; } manual; struct { uint32_t exposure; double gain; } automatic; bool autoEnabled; controls::AeConstraintModeEnum constraintMode; controls::AeExposureModeEnum exposureMode; controls::AeMeteringModeEnum meteringMode; utils::Duration maxFrameDuration; } agc; struct { struct { struct { double red; double green; double blue; } manual; struct { double red; double green; double blue; } automatic; } gains; unsigned int temperatureK; bool autoEnabled; } awb; struct { int8_t brightness; uint8_t contrast; uint8_t saturation; } cproc; struct { bool denoise; } dpf; struct { uint8_t denoise; uint8_t sharpness; } filter; struct { double gamma; } goc; }; struct IPAFrameContext : public FrameContext { struct { uint32_t exposure; double gain; bool autoEnabled; controls::AeConstraintModeEnum constraintMode; controls::AeExposureModeEnum exposureMode; controls::AeMeteringModeEnum meteringMode; utils::Duration maxFrameDuration; bool updateMetering; } agc; struct { struct { double red; double green; double blue; } gains; unsigned int temperatureK; bool autoEnabled; } awb; struct { int8_t brightness; uint8_t contrast; uint8_t saturation; bool update; } cproc; struct { bool denoise; bool update; } dpf; struct { uint8_t denoise; uint8_t sharpness; bool update; } filter; struct { double gamma; bool update; } goc; struct { uint32_t exposure; double gain; } sensor; struct { Matrix<float, 3, 3> ccm; } ccm; }; struct IPAContext { const IPAHwSettings *hw; IPASessionConfiguration configuration; IPAActiveState activeState; FCQueue<IPAFrameContext> frameContexts; ControlInfoMap::Map ctrlMap; }; } /* namespace ipa::rkisp1 */ } /* namespace libcamera*/
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/rkisp1/utils.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Miscellaneous utility functions specific to rkisp1 */ #include "utils.h" /** * \file utils.h */ namespace libcamera { namespace ipa::rkisp1::utils { /** * \fn R floatingToFixedPoint(T number) * \brief Convert a floating point number to a fixed-point representation * \tparam I Bit width of the integer part of the fixed-point * \tparam F Bit width of the fractional part of the fixed-point * \tparam R Return type of the fixed-point representation * \tparam T Input type of the floating point representation * \param number The floating point number to convert to fixed point * \return The converted value */ /** * \fn R fixedToFloatingPoint(T number) * \brief Convert a fixed-point number to a floating point representation * \tparam I Bit width of the integer part of the fixed-point * \tparam F Bit width of the fractional part of the fixed-point * \tparam R Return type of the floating point representation * \tparam T Input type of the fixed-point representation * \param number The fixed point number to convert to floating point * \return The converted value */ } /* namespace ipa::rkisp1::utils */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/rkisp1/utils.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2024, Paul Elder <[email protected]> * * Miscellaneous utility functions specific to rkisp1 */ #pragma once #include <cmath> #include <limits> #include <type_traits> namespace libcamera { namespace ipa::rkisp1::utils { #ifndef __DOXYGEN__ template<unsigned int I, unsigned int F, typename R, typename T, std::enable_if_t<std::is_integral_v<R> && std::is_floating_point_v<T>> * = nullptr> #else template<unsigned int I, unsigned int F, typename R, typename T> #endif constexpr R floatingToFixedPoint(T number) { static_assert(sizeof(int) >= sizeof(R)); static_assert(I + F <= sizeof(R) * 8); /* * The intermediate cast to int is needed on arm platforms to properly * cast negative values. See * https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/ */ R mask = (1 << (F + I)) - 1; R frac = static_cast<R>(static_cast<int>(std::round(number * (1 << F)))) & mask; return frac; } #ifndef __DOXYGEN__ template<unsigned int I, unsigned int F, typename R, typename T, std::enable_if_t<std::is_floating_point_v<R> && std::is_integral_v<T>> * = nullptr> #else template<unsigned int I, unsigned int F, typename R, typename T> #endif constexpr R fixedToFloatingPoint(T number) { static_assert(sizeof(int) >= sizeof(T)); static_assert(I + F <= sizeof(T) * 8); /* * Recreate the upper bits in case of a negative number by shifting the sign * bit from the fixed point to the first bit of the unsigned and then right shifting * by the same amount which keeps the sign bit in place. * This can be optimized by the compiler quite well. */ int remaining_bits = sizeof(int) * 8 - (I + F); int t = static_cast<int>(static_cast<unsigned>(number) << remaining_bits) >> remaining_bits; return static_cast<R>(t) / static_cast<R>(1 << F); } } /* namespace ipa::rkisp1::utils */ } /* namespace libcamera */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/rkisp1/module.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2022, Ideas On Board * * RkISP1 IPA Module */ #pragma once #include <linux/rkisp1-config.h> #include <libcamera/ipa/rkisp1_ipa_interface.h> #include <libipa/module.h> #include "ipa_context.h" namespace libcamera { namespace ipa::rkisp1 { using Module = ipa::Module<IPAContext, IPAFrameContext, IPACameraSensorInfo, rkisp1_params_cfg, rkisp1_stat_buffer>; } /* namespace ipa::rkisp1 */ } /* namespace libcamera*/
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/rkisp1/ipa_context.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021-2022, Ideas On Board * * RkISP1 IPA Context */ #include "ipa_context.h" /** * \file ipa_context.h * \brief Context and state information shared between the algorithms */ namespace libcamera::ipa::rkisp1 { /** * \struct IPAHwSettings * \brief RkISP1 version-specific hardware parameters */ /** * \var IPAHwSettings::numAeCells * \brief Number of cells in the AE exposure means grid * * \var IPAHwSettings::numHistogramBins * \brief Number of bins in the histogram * * \var IPAHwSettings::numHistogramWeights * \brief Number of weights in the histogram grid * * \var IPAHwSettings::numGammaOutSamples * \brief Number of samples in the gamma out table */ /** * \struct IPASessionConfiguration * \brief Session configuration for the IPA module * * The session configuration contains all IPA configuration parameters that * remain constant during the capture session, from IPA module start to stop. * It is typically set during the configure() operation of the IPA module, but * may also be updated in the start() operation. */ /** * \var IPASessionConfiguration::agc * \brief AGC parameters configuration of the IPA * * \var IPASessionConfiguration::agc.measureWindow * \brief AGC measure window */ /** * \var IPASessionConfiguration::awb * \brief AWB parameters configuration of the IPA * * \var IPASessionConfiguration::awb.measureWindow * \brief AWB measure window * * \var IPASessionConfiguration::awb.enabled * \brief Indicates if the AWB hardware is enabled and applies colour gains * * The AWB module of the ISP applies colour gains and computes statistics. It is * enabled when the AWB algorithm is loaded, regardless of whether the algorithm * operates in manual or automatic mode. */ /** * \var IPASessionConfiguration::lsc * \brief Lens Shading Correction configuration of the IPA * * \var IPASessionConfiguration::lsc.enabled * \brief Indicates if the LSC hardware is enabled */ /** * \var IPASessionConfiguration::sensor * \brief Sensor-specific configuration of the IPA * * \var IPASessionConfiguration::sensor.minShutterSpeed * \brief Minimum shutter speed supported with the sensor * * \var IPASessionConfiguration::sensor.maxShutterSpeed * \brief Maximum shutter speed supported with the sensor * * \var IPASessionConfiguration::sensor.minAnalogueGain * \brief Minimum analogue gain supported with the sensor * * \var IPASessionConfiguration::sensor.maxAnalogueGain * \brief Maximum analogue gain supported with the sensor * * \var IPASessionConfiguration::sensor.defVBlank * \brief The default vblank value of the sensor * * \var IPASessionConfiguration::sensor.lineDuration * \brief Line duration in microseconds * * \var IPASessionConfiguration::sensor.size * \brief Sensor output resolution */ /** * \var IPASessionConfiguration::raw * \brief Indicates if the camera is configured to capture raw frames */ /** * \struct IPAActiveState * \brief Active state for algorithms * * The active state contains all algorithm-specific data that needs to be * maintained by algorithms across frames. Unlike the session configuration, * the active state is mutable and constantly updated by algorithms. The active * state is accessible through the IPAContext structure. * * The active state stores two distinct categories of information: * * - The consolidated value of all algorithm controls. Requests passed to * the queueRequest() function store values for controls that the * application wants to modify for that particular frame, and the * queueRequest() function updates the active state with those values. * The active state thus contains a consolidated view of the value of all * controls handled by the algorithm. * * - The value of parameters computed by the algorithm when running in auto * mode. Algorithms running in auto mode compute new parameters every * time statistics buffers are received (either synchronously, or * possibly in a background thread). The latest computed value of those * parameters is stored in the active state in the process() function. * * Each of the members in the active state belongs to a specific algorithm. A * member may be read by any algorithm, but shall only be written by its owner. */ /** * \var IPAActiveState::agc * \brief State for the Automatic Gain Control algorithm * * The \a automatic variables track the latest values computed by algorithm * based on the latest processed statistics. All other variables track the * consolidated controls requested in queued requests. * * \struct IPAActiveState::agc.manual * \brief Manual exposure time and analog gain (set through requests) * * \var IPAActiveState::agc.manual.exposure * \brief Manual exposure time expressed as a number of lines as set by the * ExposureTime control * * \var IPAActiveState::agc.manual.gain * \brief Manual analogue gain as set by the AnalogueGain control * * \struct IPAActiveState::agc.automatic * \brief Automatic exposure time and analog gain (computed by the algorithm) * * \var IPAActiveState::agc.automatic.exposure * \brief Automatic exposure time expressed as a number of lines * * \var IPAActiveState::agc.automatic.gain * \brief Automatic analogue gain multiplier * * \var IPAActiveState::agc.autoEnabled * \brief Manual/automatic AGC state as set by the AeEnable control * * \var IPAActiveState::agc.constraintMode * \brief Constraint mode as set by the AeConstraintMode control * * \var IPAActiveState::agc.exposureMode * \brief Exposure mode as set by the AeExposureMode control * * \var IPAActiveState::agc.meteringMode * \brief Metering mode as set by the AeMeteringMode control * * \var IPAActiveState::agc.maxFrameDuration * \brief Maximum frame duration as set by the FrameDurationLimits control */ /** * \var IPAActiveState::awb * \brief State for the Automatic White Balance algorithm * * \struct IPAActiveState::awb.gains * \brief White balance gains * * \struct IPAActiveState::awb.gains.manual * \brief Manual white balance gains (set through requests) * * \var IPAActiveState::awb.gains.manual.red * \brief Manual white balance gain for R channel * * \var IPAActiveState::awb.gains.manual.green * \brief Manual white balance gain for G channel * * \var IPAActiveState::awb.gains.manual.blue * \brief Manual white balance gain for B channel * * \struct IPAActiveState::awb.gains.automatic * \brief Automatic white balance gains (computed by the algorithm) * * \var IPAActiveState::awb.gains.automatic.red * \brief Automatic white balance gain for R channel * * \var IPAActiveState::awb.gains.automatic.green * \brief Automatic white balance gain for G channel * * \var IPAActiveState::awb.gains.automatic.blue * \brief Automatic white balance gain for B channel * * \var IPAActiveState::awb.temperatureK * \brief Estimated color temperature * * \var IPAActiveState::awb.autoEnabled * \brief Whether the Auto White Balance algorithm is enabled */ /** * \var IPAActiveState::cproc * \brief State for the Color Processing algorithm * * \struct IPAActiveState::cproc.brightness * \brief Brightness level * * \var IPAActiveState::cproc.contrast * \brief Contrast level * * \var IPAActiveState::cproc.saturation * \brief Saturation level */ /** * \var IPAActiveState::dpf * \brief State for the Denoise Pre-Filter algorithm * * \var IPAActiveState::dpf.denoise * \brief Indicates if denoise is activated */ /** * \var IPAActiveState::filter * \brief State for the Filter algorithm * * \struct IPAActiveState::filter.denoise * \brief Denoising level * * \var IPAActiveState::filter.sharpness * \brief Sharpness level */ /** * \var IPAActiveState::goc * \brief State for the goc algorithm * * \var IPAActiveState::goc.gamma * \brief Gamma value applied as 1.0/gamma */ /** * \struct IPAFrameContext * \brief Per-frame context for algorithms * * The frame context stores two distinct categories of information: * * - The value of the controls to be applied to the frame. These values are * typically set in the queueRequest() function, from the consolidated * control values stored in the active state. The frame context thus stores * values for all controls related to the algorithm, not limited to the * controls specified in the corresponding request, but consolidated from all * requests that have been queued so far. * * For controls that can be set manually or computed by an algorithm * (depending on the algorithm operation mode), such as for instance the * colour gains for the AWB algorithm, the control value will be stored in * the frame context in the queueRequest() function only when operating in * manual mode. When operating in auto mode, the values are computed by the * algorithm in process(), stored in the active state, and copied to the * frame context in prepare(), just before being stored in the ISP parameters * buffer. * * The queueRequest() function can also store ancillary data in the frame * context, such as flags to indicate if (and what) control values have * changed compared to the previous request. * * - Status information computed by the algorithm for a frame. For instance, * the colour temperature estimated by the AWB algorithm from ISP statistics * calculated on a frame is stored in the frame context for that frame in * the process() function. */ /** * \var IPAFrameContext::agc * \brief Automatic Gain Control parameters for this frame * * The exposure and gain are provided by the AGC algorithm, and are to be * applied to the sensor in order to take effect for this frame. * * \var IPAFrameContext::agc.exposure * \brief Exposure time expressed as a number of lines computed by the algorithm * * \var IPAFrameContext::agc.gain * \brief Analogue gain multiplier computed by the algorithm * * The gain should be adapted to the sensor specific gain code before applying. * * \var IPAFrameContext::agc.autoEnabled * \brief Manual/automatic AGC state as set by the AeEnable control * * \var IPAFrameContext::agc.constraintMode * \brief Constraint mode as set by the AeConstraintMode control * * \var IPAFrameContext::agc.exposureMode * \brief Exposure mode as set by the AeExposureMode control * * \var IPAFrameContext::agc.meteringMode * \brief Metering mode as set by the AeMeteringMode control * * \var IPAFrameContext::agc.maxFrameDuration * \brief Maximum frame duration as set by the FrameDurationLimits control * * \var IPAFrameContext::agc.updateMetering * \brief Indicate if new ISP AGC metering parameters need to be applied */ /** * \var IPAFrameContext::awb * \brief Automatic White Balance parameters for this frame * * \struct IPAFrameContext::awb.gains * \brief White balance gains * * \var IPAFrameContext::awb.gains.red * \brief White balance gain for R channel * * \var IPAFrameContext::awb.gains.green * \brief White balance gain for G channel * * \var IPAFrameContext::awb.gains.blue * \brief White balance gain for B channel * * \var IPAFrameContext::awb.temperatureK * \brief Estimated color temperature * * \var IPAFrameContext::awb.autoEnabled * \brief Whether the Auto White Balance algorithm is enabled */ /** * \var IPAFrameContext::cproc * \brief Color Processing parameters for this frame * * \struct IPAFrameContext::cproc.brightness * \brief Brightness level * * \var IPAFrameContext::cproc.contrast * \brief Contrast level * * \var IPAFrameContext::cproc.saturation * \brief Saturation level * * \var IPAFrameContext::cproc.update * \brief Indicates if the color processing parameters have been updated * compared to the previous frame */ /** * \var IPAFrameContext::dpf * \brief Denoise Pre-Filter parameters for this frame * * \var IPAFrameContext::dpf.denoise * \brief Indicates if denoise is activated * * \var IPAFrameContext::dpf.update * \brief Indicates if the denoise pre-filter parameters have been updated * compared to the previous frame */ /** * \var IPAFrameContext::filter * \brief Filter parameters for this frame * * \struct IPAFrameContext::filter.denoise * \brief Denoising level * * \var IPAFrameContext::filter.sharpness * \brief Sharpness level * * \var IPAFrameContext::filter.updateParams * \brief Indicates if the filter parameters have been updated compared to the * previous frame */ /** * \var IPAFrameContext::goc * \brief Gamma out correction parameters for this frame * * \var IPAFrameContext::goc.gamma * \brief Gamma value applied as 1.0/gamma * * \var IPAFrameContext::goc.update * \brief Indicates if the goc parameters have been updated compared to the * previous frame */ /** * \var IPAFrameContext::sensor * \brief Sensor configuration that used been used for this frame * * \var IPAFrameContext::sensor.exposure * \brief Exposure time expressed as a number of lines * * \var IPAFrameContext::sensor.gain * \brief Analogue gain multiplier */ /** * \struct IPAContext * \brief Global IPA context data shared between all algorithms * * \var IPAContext::hw * \brief RkISP1 version-specific hardware parameters * * \var IPAContext::configuration * \brief The IPA session configuration, immutable during the session * * \var IPAContext::activeState * \brief The IPA active state, storing the latest state for all algorithms * * \var IPAContext::frameContexts * \brief Ring buffer of per-frame contexts */ } /* namespace libcamera::ipa::rkisp1 */
0
repos/libcamera/src/ipa
repos/libcamera/src/ipa/rkisp1/rkisp1.cpp
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2019, Google Inc. * * RkISP1 Image Processing Algorithms */ #include <algorithm> #include <math.h> #include <queue> #include <stdint.h> #include <string.h> #include <linux/rkisp1-config.h> #include <linux/v4l2-controls.h> #include <libcamera/base/file.h> #include <libcamera/base/log.h> #include <libcamera/control_ids.h> #include <libcamera/framebuffer.h> #include <libcamera/ipa/ipa_interface.h> #include <libcamera/ipa/ipa_module_info.h> #include <libcamera/ipa/rkisp1_ipa_interface.h> #include <libcamera/request.h> #include "libcamera/internal/formats.h" #include "libcamera/internal/mapped_framebuffer.h" #include "libcamera/internal/yaml_parser.h" #include "algorithms/algorithm.h" #include "libipa/camera_sensor_helper.h" #include "ipa_context.h" namespace libcamera { LOG_DEFINE_CATEGORY(IPARkISP1) using namespace std::literals::chrono_literals; namespace ipa::rkisp1 { /* Maximum number of frame contexts to be held */ static constexpr uint32_t kMaxFrameContexts = 16; class IPARkISP1 : public IPARkISP1Interface, public Module { public: IPARkISP1(); int init(const IPASettings &settings, unsigned int hwRevision, const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls) override; int start() override; void stop() override; int configure(const IPAConfigInfo &ipaConfig, const std::map<uint32_t, IPAStream> &streamConfig, ControlInfoMap *ipaControls) override; void mapBuffers(const std::vector<IPABuffer> &buffers) override; void unmapBuffers(const std::vector<unsigned int> &ids) override; void queueRequest(const uint32_t frame, const ControlList &controls) override; void fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) override; void processStatsBuffer(const uint32_t frame, const uint32_t bufferId, const ControlList &sensorControls) override; protected: std::string logPrefix() const override; private: void updateControls(const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls); void setControls(unsigned int frame); std::map<unsigned int, FrameBuffer> buffers_; std::map<unsigned int, MappedFrameBuffer> mappedBuffers_; ControlInfoMap sensorControls_; /* Interface to the Camera Helper */ std::unique_ptr<CameraSensorHelper> camHelper_; /* Local parameter storage */ struct IPAContext context_; }; namespace { const IPAHwSettings ipaHwSettingsV10{ RKISP1_CIF_ISP_AE_MEAN_MAX_V10, RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10, RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10, RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10, }; const IPAHwSettings ipaHwSettingsV12{ RKISP1_CIF_ISP_AE_MEAN_MAX_V12, RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12, RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12, RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12, }; /* List of controls handled by the RkISP1 IPA */ const ControlInfoMap::Map rkisp1Controls{ { &controls::AwbEnable, ControlInfo(false, true) }, { &controls::ColourGains, ControlInfo(0.0f, 3.996f, 1.0f) }, { &controls::Sharpness, ControlInfo(0.0f, 10.0f, 1.0f) }, { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }, }; } /* namespace */ IPARkISP1::IPARkISP1() : context_({ {}, {}, {}, { kMaxFrameContexts }, {} }) { } std::string IPARkISP1::logPrefix() const { return "rkisp1"; } int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision, const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls) { /* \todo Add support for other revisions */ switch (hwRevision) { case RKISP1_V10: case RKISP1_V_IMX8MP: context_.hw = &ipaHwSettingsV10; break; case RKISP1_V12: context_.hw = &ipaHwSettingsV12; break; default: LOG(IPARkISP1, Error) << "Hardware revision " << hwRevision << " is currently not supported"; return -ENODEV; } LOG(IPARkISP1, Debug) << "Hardware revision is " << hwRevision; camHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel); if (!camHelper_) { LOG(IPARkISP1, Error) << "Failed to create camera sensor helper for " << settings.sensorModel; return -ENODEV; } context_.configuration.sensor.lineDuration = sensorInfo.minLineLength * 1.0s / sensorInfo.pixelRate; /* Load the tuning data file. */ File file(settings.configurationFile); if (!file.open(File::OpenModeFlag::ReadOnly)) { int ret = file.error(); LOG(IPARkISP1, Error) << "Failed to open configuration file " << settings.configurationFile << ": " << strerror(-ret); return ret; } std::unique_ptr<libcamera::YamlObject> data = YamlParser::parse(file); if (!data) return -EINVAL; unsigned int version = (*data)["version"].get<uint32_t>(0); if (version != 1) { LOG(IPARkISP1, Error) << "Invalid tuning file version " << version; return -EINVAL; } if (!data->contains("algorithms")) { LOG(IPARkISP1, Error) << "Tuning file doesn't contain any algorithm"; return -EINVAL; } int ret = createAlgorithms(context_, (*data)["algorithms"]); if (ret) return ret; /* Initialize controls. */ updateControls(sensorInfo, sensorControls, ipaControls); return 0; } int IPARkISP1::start() { setControls(0); return 0; } void IPARkISP1::stop() { context_.frameContexts.clear(); } int IPARkISP1::configure(const IPAConfigInfo &ipaConfig, const std::map<uint32_t, IPAStream> &streamConfig, ControlInfoMap *ipaControls) { sensorControls_ = ipaConfig.sensorControls; const auto itExp = sensorControls_.find(V4L2_CID_EXPOSURE); int32_t minExposure = itExp->second.min().get<int32_t>(); int32_t maxExposure = itExp->second.max().get<int32_t>(); const auto itGain = sensorControls_.find(V4L2_CID_ANALOGUE_GAIN); int32_t minGain = itGain->second.min().get<int32_t>(); int32_t maxGain = itGain->second.max().get<int32_t>(); LOG(IPARkISP1, Debug) << "Exposure: [" << minExposure << ", " << maxExposure << "], gain: [" << minGain << ", " << maxGain << "]"; /* Clear the IPA context before the streaming session. */ context_.configuration = {}; context_.activeState = {}; context_.frameContexts.clear(); const IPACameraSensorInfo &info = ipaConfig.sensorInfo; const ControlInfo vBlank = sensorControls_.find(V4L2_CID_VBLANK)->second; context_.configuration.sensor.defVBlank = vBlank.def().get<int32_t>(); context_.configuration.sensor.size = info.outputSize; context_.configuration.sensor.lineDuration = info.minLineLength * 1.0s / info.pixelRate; /* Update the camera controls using the new sensor settings. */ updateControls(info, sensorControls_, ipaControls); /* * When the AGC computes the new exposure values for a frame, it needs * to know the limits for shutter speed and analogue gain. * As it depends on the sensor, update it with the controls. * * \todo take VBLANK into account for maximum shutter speed */ context_.configuration.sensor.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration; context_.configuration.sensor.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration; context_.configuration.sensor.minAnalogueGain = camHelper_->gain(minGain); context_.configuration.sensor.maxAnalogueGain = camHelper_->gain(maxGain); context_.configuration.raw = std::any_of(streamConfig.begin(), streamConfig.end(), [](auto &cfg) -> bool { PixelFormat pixelFormat{ cfg.second.pixelFormat }; const PixelFormatInfo &format = PixelFormatInfo::info(pixelFormat); return format.colourEncoding == PixelFormatInfo::ColourEncodingRAW; }); for (auto const &a : algorithms()) { Algorithm *algo = static_cast<Algorithm *>(a.get()); /* Disable algorithms that don't support raw formats. */ algo->disabled_ = context_.configuration.raw && !algo->supportsRaw_; if (algo->disabled_) continue; int ret = algo->configure(context_, info); if (ret) return ret; } return 0; } void IPARkISP1::mapBuffers(const std::vector<IPABuffer> &buffers) { for (const IPABuffer &buffer : buffers) { auto elem = buffers_.emplace(std::piecewise_construct, std::forward_as_tuple(buffer.id), std::forward_as_tuple(buffer.planes)); const FrameBuffer &fb = elem.first->second; MappedFrameBuffer mappedBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite); if (!mappedBuffer.isValid()) { LOG(IPARkISP1, Fatal) << "Failed to mmap buffer: " << strerror(mappedBuffer.error()); } mappedBuffers_.emplace(buffer.id, std::move(mappedBuffer)); } } void IPARkISP1::unmapBuffers(const std::vector<unsigned int> &ids) { for (unsigned int id : ids) { const auto fb = buffers_.find(id); if (fb == buffers_.end()) continue; mappedBuffers_.erase(id); buffers_.erase(id); } } void IPARkISP1::queueRequest(const uint32_t frame, const ControlList &controls) { IPAFrameContext &frameContext = context_.frameContexts.alloc(frame); for (auto const &a : algorithms()) { Algorithm *algo = static_cast<Algorithm *>(a.get()); if (algo->disabled_) continue; algo->queueRequest(context_, frame, frameContext, controls); } } void IPARkISP1::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) { IPAFrameContext &frameContext = context_.frameContexts.get(frame); rkisp1_params_cfg *params = reinterpret_cast<rkisp1_params_cfg *>( mappedBuffers_.at(bufferId).planes()[0].data()); /* Prepare parameters buffer. */ memset(params, 0, sizeof(*params)); for (auto const &algo : algorithms()) algo->prepare(context_, frame, frameContext, params); paramsBufferReady.emit(frame); } void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId, const ControlList &sensorControls) { IPAFrameContext &frameContext = context_.frameContexts.get(frame); /* * In raw capture mode, the ISP is bypassed and no statistics buffer is * provided. */ const rkisp1_stat_buffer *stats = nullptr; if (!context_.configuration.raw) stats = reinterpret_cast<rkisp1_stat_buffer *>( mappedBuffers_.at(bufferId).planes()[0].data()); frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>(); frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>()); ControlList metadata(controls::controls); for (auto const &a : algorithms()) { Algorithm *algo = static_cast<Algorithm *>(a.get()); if (algo->disabled_) continue; algo->process(context_, frame, frameContext, stats, metadata); } setControls(frame); metadataReady.emit(frame, metadata); } void IPARkISP1::updateControls(const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls) { ControlInfoMap::Map ctrlMap = rkisp1Controls; /* * Compute exposure time limits from the V4L2_CID_EXPOSURE control * limits and the line duration. */ double lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>(); const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second; int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration; int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration; int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration; ctrlMap.emplace(std::piecewise_construct, std::forward_as_tuple(&controls::ExposureTime), std::forward_as_tuple(minExposure, maxExposure, defExposure)); /* Compute the analogue gain limits. */ const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second; float minGain = camHelper_->gain(v4l2Gain.min().get<int32_t>()); float maxGain = camHelper_->gain(v4l2Gain.max().get<int32_t>()); float defGain = camHelper_->gain(v4l2Gain.def().get<int32_t>()); ctrlMap.emplace(std::piecewise_construct, std::forward_as_tuple(&controls::AnalogueGain), std::forward_as_tuple(minGain, maxGain, defGain)); /* * Compute the frame duration limits. * * The frame length is computed assuming a fixed line length combined * with the vertical frame sizes. */ const ControlInfo &v4l2HBlank = sensorControls.find(V4L2_CID_HBLANK)->second; uint32_t hblank = v4l2HBlank.def().get<int32_t>(); uint32_t lineLength = sensorInfo.outputSize.width + hblank; const ControlInfo &v4l2VBlank = sensorControls.find(V4L2_CID_VBLANK)->second; std::array<uint32_t, 3> frameHeights{ v4l2VBlank.min().get<int32_t>() + sensorInfo.outputSize.height, v4l2VBlank.max().get<int32_t>() + sensorInfo.outputSize.height, v4l2VBlank.def().get<int32_t>() + sensorInfo.outputSize.height, }; std::array<int64_t, 3> frameDurations; for (unsigned int i = 0; i < frameHeights.size(); ++i) { uint64_t frameSize = lineLength * frameHeights[i]; frameDurations[i] = frameSize / (sensorInfo.pixelRate / 1000000U); } ctrlMap[&controls::FrameDurationLimits] = ControlInfo(frameDurations[0], frameDurations[1], frameDurations[2]); ctrlMap.insert(context_.ctrlMap.begin(), context_.ctrlMap.end()); *ipaControls = ControlInfoMap(std::move(ctrlMap), controls::controls); } void IPARkISP1::setControls(unsigned int frame) { /* * \todo The frame number is most likely wrong here, we need to take * internal sensor delays and other timing parameters into account. */ IPAFrameContext &frameContext = context_.frameContexts.get(frame); uint32_t exposure = frameContext.agc.exposure; uint32_t gain = camHelper_->gainCode(frameContext.agc.gain); ControlList ctrls(sensorControls_); ctrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure)); ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast<int32_t>(gain)); setSensorControls.emit(frame, ctrls); } } /* namespace ipa::rkisp1 */ /* * External IPA module interface */ extern "C" { const struct IPAModuleInfo ipaModuleInfo = { IPA_MODULE_API_VERSION, 1, "rkisp1", "rkisp1", }; IPAInterface *ipaCreate() { return new ipa::rkisp1::IPARkISP1(); } } } /* namespace libcamera */
0
repos/libcamera/src/ipa/rkisp1
repos/libcamera/src/ipa/rkisp1/data/ov8858.yaml
# SPDX-License-Identifier: CC0-1.0 %YAML 1.1 --- version: 1 algorithms: - Agc: - Awb: - LensShadingCorrection: x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] sets: #3264x2448_A_70 - A - ct: 2856 resolution: 3264x2448 r: [4095, 3932, 3584, 3324, 3113, 2934, 2747, 2619, 2566, 2579, 2671, 2816, 3009, 3217, 3444, 3843, 4095, 4095, 3658, 3343, 3088, 2867, 2620, 2404, 2271, 2207, 2229, 2315, 2485, 2727, 2965, 3232, 3500, 4057, 3926, 3482, 3187, 2914, 2612, 2330, 2112, 1976, 1917, 1931, 2028, 2198, 2456, 2762, 3042, 3335, 3770, 3739, 3331, 3029, 2720, 2364, 2070, 1852, 1718, 1655, 1669, 1765, 1940, 2207, 2538, 2878, 3183, 3565, 3590, 3209, 2910, 2524, 2156, 1860, 1642, 1493, 1431, 1446, 1551, 1734, 1986, 2338, 2721, 3075, 3405, 3484, 3116, 2778, 2373, 1997, 1698, 1466, 1315, 1254, 1272, 1374, 1562, 1825, 2169, 2587, 2946, 3317, 3415, 3044, 2682, 2252, 1873, 1574, 1336, 1192, 1126, 1146, 1249, 1437, 1712, 2050, 2462, 2877, 3238, 3355, 3002, 2619, 2171, 1800, 1490, 1259, 1112, 1051, 1073, 1173, 1359, 1635, 1977, 2388, 2813, 3182, 3348, 2969, 2587, 2138, 1768, 1457, 1228, 1085, 1024, 1043, 1144, 1326, 1603, 1950, 2364, 2783, 3170, 3344, 2984, 2594, 2152, 1776, 1468, 1239, 1098, 1041, 1061, 1161, 1342, 1617, 1962, 2373, 2798, 3177, 3388, 3011, 2637, 2207, 1829, 1528, 1298, 1158, 1100, 1120, 1217, 1408, 1677, 2018, 2429, 2841, 3192, 3442, 3064, 2718, 2301, 1929, 1633, 1405, 1263, 1205, 1224, 1326, 1513, 1777, 2119, 2525, 2903, 3274, 3557, 3138, 2822, 2435, 2066, 1775, 1558, 1414, 1355, 1378, 1478, 1663, 1927, 2255, 2657, 2987, 3369, 3682, 3256, 2940, 2604, 2252, 1958, 1748, 1609, 1557, 1576, 1677, 1857, 2106, 2445, 2793, 3096, 3526, 3874, 3380, 3075, 2783, 2472, 2189, 1974, 1846, 1790, 1811, 1909, 2086, 2342, 2643, 2934, 3247, 3743, 4095, 3583, 3218, 2950, 2708, 2456, 2257, 2114, 2064, 2083, 2185, 2364, 2598, 2856, 3111, 3444, 4045, 4095, 3842, 3474, 3155, 2950, 2731, 2575, 2440, 2388, 2413, 2499, 2659, 2846, 3056, 3334, 3796, 4095, ] gr: [3246, 2753, 2547, 2359, 2249, 2148, 2052, 1977, 1938, 1947, 1995, 2082, 2183, 2277, 2411, 2655, 2957, 2906, 2568, 2361, 2223, 2092, 1964, 1850, 1767, 1735, 1740, 1790, 1881, 2002, 2124, 2265, 2437, 2751, 2740, 2449, 2261, 2106, 1950, 1798, 1681, 1604, 1570, 1577, 1626, 1714, 1846, 2012, 2149, 2322, 2581, 2628, 2348, 2169, 2000, 1808, 1654, 1539, 1460, 1419, 1429, 1483, 1576, 1710, 1881, 2062, 2231, 2443, 2541, 2279, 2102, 1891, 1687, 1536, 1420, 1330, 1289, 1298, 1362, 1459, 1589, 1773, 1967, 2168, 2352, 2459, 2226, 2027, 1797, 1599, 1442, 1313, 1221, 1179, 1190, 1253, 1359, 1497, 1675, 1898, 2100, 2286, 2406, 2180, 1976, 1732, 1531, 1369, 1231, 1140, 1096, 1109, 1174, 1284, 1431, 1608, 1824, 2055, 2245, 2374, 2148, 1928, 1684, 1484, 1317, 1178, 1084, 1043, 1058, 1122, 1234, 1387, 1562, 1785, 2020, 2218, 2363, 2140, 1910, 1663, 1464, 1292, 1156, 1063, 1024, 1036, 1102, 1214, 1363, 1547, 1762, 2004, 2194, 2366, 2136, 1917, 1670, 1469, 1302, 1163, 1073, 1032, 1047, 1111, 1223, 1373, 1552, 1775, 2009, 2206, 2383, 2158, 1940, 1703, 1506, 1339, 1201, 1112, 1072, 1087, 1150, 1265, 1408, 1584, 1805, 2030, 2228, 2434, 2189, 1994, 1757, 1557, 1400, 1270, 1181, 1142, 1154, 1218, 1328, 1468, 1640, 1860, 2068, 2267, 2497, 2235, 2043, 1837, 1630, 1477, 1360, 1273, 1238, 1249, 1310, 1412, 1544, 1725, 1924, 2124, 2329, 2592, 2305, 2109, 1925, 1731, 1576, 1460, 1384, 1350, 1364, 1422, 1513, 1648, 1818, 2009, 2174, 2427, 2699, 2379, 2188, 2022, 1860, 1696, 1588, 1510, 1480, 1489, 1543, 1637, 1771, 1937, 2072, 2269, 2546, 2862, 2514, 2276, 2120, 1983, 1850, 1737, 1664, 1628, 1642, 1695, 1787, 1914, 2043, 2182, 2390, 2734, 3175, 2661, 2434, 2232, 2119, 2004, 1921, 1849, 1813, 1816, 1874, 1959, 2049, 2159, 2317, 2604, 2891, ] gb: [3248, 2762, 2549, 2352, 2241, 2135, 2024, 1949, 1910, 1923, 1970, 2058, 2167, 2278, 2427, 2679, 3003, 2939, 2581, 2369, 2212, 2084, 1945, 1829, 1743, 1710, 1713, 1773, 1861, 1999, 2127, 2278, 2456, 2799, 2766, 2468, 2268, 2114, 1949, 1788, 1666, 1587, 1550, 1557, 1612, 1711, 1849, 2022, 2168, 2354, 2627, 2659, 2372, 2185, 2003, 1808, 1646, 1531, 1447, 1404, 1415, 1474, 1573, 1711, 1896, 2082, 2269, 2494, 2572, 2297, 2122, 1903, 1694, 1534, 1411, 1322, 1278, 1294, 1356, 1459, 1599, 1796, 2003, 2204, 2415, 2494, 2259, 2053, 1813, 1609, 1442, 1310, 1216, 1174, 1186, 1254, 1368, 1512, 1699, 1934, 2147, 2352, 2450, 2219, 2006, 1751, 1543, 1372, 1233, 1134, 1096, 1108, 1175, 1292, 1449, 1639, 1865, 2103, 2311, 2424, 2182, 1960, 1705, 1498, 1324, 1181, 1086, 1041, 1059, 1127, 1245, 1404, 1594, 1828, 2078, 2281, 2405, 2182, 1937, 1687, 1480, 1301, 1161, 1062, 1024, 1038, 1107, 1224, 1384, 1581, 1812, 2057, 2272, 2417, 2181, 1951, 1695, 1487, 1312, 1167, 1074, 1032, 1050, 1118, 1235, 1397, 1586, 1820, 2069, 2278, 2450, 2196, 1974, 1724, 1522, 1348, 1205, 1113, 1075, 1089, 1153, 1276, 1430, 1619, 1849, 2095, 2291, 2483, 2229, 2022, 1779, 1573, 1408, 1272, 1181, 1142, 1156, 1223, 1339, 1488, 1673, 1905, 2123, 2343, 2541, 2277, 2079, 1856, 1643, 1485, 1361, 1270, 1235, 1248, 1313, 1421, 1566, 1751, 1971, 2173, 2399, 2635, 2339, 2138, 1944, 1745, 1580, 1458, 1380, 1344, 1359, 1418, 1519, 1661, 1849, 2048, 2222, 2487, 2743, 2413, 2216, 2037, 1864, 1702, 1579, 1500, 1467, 1479, 1537, 1642, 1777, 1958, 2108, 2315, 2617, 2890, 2544, 2293, 2131, 1988, 1842, 1726, 1651, 1612, 1628, 1684, 1783, 1920, 2060, 2213, 2432, 2804, 3189, 2693, 2445, 2245, 2116, 2000, 1902, 1826, 1789, 1798, 1857, 1950, 2045, 2170, 2337, 2642, 2952, ] b: [3058, 2592, 2385, 2213, 2113, 2016, 1936, 1869, 1845, 1844, 1887, 1965, 2056, 2162, 2288, 2535, 2815, 2739, 2411, 2208, 2067, 1959, 1848, 1747, 1681, 1655, 1659, 1709, 1788, 1909, 2024, 2149, 2317, 2640, 2595, 2298, 2119, 1981, 1836, 1704, 1608, 1543, 1517, 1519, 1561, 1646, 1774, 1925, 2042, 2217, 2463, 2469, 2218, 2033, 1880, 1710, 1575, 1479, 1419, 1384, 1398, 1439, 1527, 1647, 1810, 1968, 2125, 2330, 2404, 2138, 1979, 1785, 1611, 1474, 1374, 1303, 1271, 1280, 1336, 1421, 1545, 1706, 1895, 2058, 2261, 2341, 2104, 1920, 1713, 1535, 1397, 1284, 1203, 1168, 1181, 1237, 1339, 1462, 1631, 1822, 2012, 2194, 2293, 2063, 1882, 1662, 1480, 1336, 1206, 1128, 1092, 1106, 1165, 1270, 1407, 1565, 1767, 1965, 2158, 2262, 2048, 1845, 1625, 1450, 1289, 1165, 1079, 1041, 1057, 1122, 1223, 1370, 1534, 1725, 1940, 2129, 2258, 2046, 1834, 1605, 1433, 1273, 1147, 1058, 1024, 1037, 1102, 1209, 1352, 1519, 1711, 1928, 2110, 2261, 2041, 1847, 1615, 1442, 1282, 1151, 1069, 1028, 1048, 1109, 1218, 1359, 1523, 1716, 1927, 2124, 2282, 2064, 1864, 1645, 1461, 1316, 1184, 1103, 1070, 1083, 1143, 1249, 1389, 1552, 1745, 1948, 2141, 2326, 2090, 1907, 1695, 1505, 1362, 1247, 1164, 1133, 1144, 1202, 1307, 1436, 1597, 1794, 1985, 2182, 2380, 2132, 1952, 1758, 1569, 1429, 1323, 1247, 1215, 1229, 1283, 1379, 1506, 1669, 1851, 2025, 2222, 2458, 2187, 2000, 1835, 1653, 1511, 1407, 1344, 1314, 1326, 1374, 1461, 1583, 1749, 1916, 2069, 2319, 2559, 2255, 2066, 1910, 1757, 1616, 1512, 1450, 1427, 1431, 1481, 1565, 1688, 1850, 1970, 2151, 2432, 2700, 2384, 2151, 1995, 1874, 1747, 1637, 1577, 1552, 1563, 1610, 1689, 1817, 1934, 2064, 2254, 2607, 3019, 2498, 2301, 2107, 1991, 1888, 1808, 1742, 1716, 1716, 1775, 1847, 1930, 2044, 2200, 2494, 2763, ] #3264x2448_D50_70 - D50 - ct: 5003 resolution: 3264x2448 r: [4095, 3613, 3287, 3049, 2867, 2696, 2545, 2427, 2374, 2387, 2473, 2592, 2779, 2948, 3156, 3544, 3984, 3842, 3341, 3076, 2850, 2650, 2438, 2245, 2123, 2065, 2085, 2164, 2316, 2531, 2745, 2979, 3232, 3738, 3605, 3194, 2924, 2694, 2430, 2182, 1986, 1867, 1814, 1824, 1909, 2060, 2301, 2567, 2807, 3088, 3473, 3432, 3048, 2806, 2516, 2208, 1953, 1758, 1638, 1581, 1596, 1679, 1836, 2061, 2367, 2669, 2928, 3285, 3275, 2940, 2676, 2354, 2027, 1763, 1572, 1443, 1385, 1398, 1496, 1648, 1878, 2184, 2527, 2813, 3150, 3181, 2855, 2566, 2201, 1877, 1622, 1413, 1284, 1226, 1243, 1333, 1502, 1732, 2033, 2391, 2731, 3021, 3116, 2786, 2474, 2100, 1773, 1510, 1304, 1171, 1114, 1131, 1224, 1389, 1630, 1925, 2296, 2638, 2973, 3060, 2752, 2410, 2024, 1710, 1437, 1231, 1101, 1044, 1063, 1152, 1318, 1559, 1865, 2228, 2600, 2919, 3044, 2730, 2388, 2001, 1677, 1403, 1204, 1073, 1024, 1036, 1128, 1289, 1534, 1839, 2198, 2569, 2903, 3039, 2734, 2392, 2004, 1684, 1417, 1210, 1086, 1031, 1050, 1138, 1306, 1544, 1845, 2204, 2576, 2916, 3099, 2751, 2432, 2050, 1732, 1469, 1264, 1136, 1085, 1101, 1194, 1358, 1596, 1891, 2264, 2612, 2929, 3131, 2808, 2499, 2142, 1811, 1556, 1354, 1230, 1178, 1195, 1286, 1451, 1683, 1986, 2341, 2678, 2991, 3235, 2875, 2592, 2258, 1936, 1679, 1491, 1363, 1310, 1332, 1421, 1582, 1813, 2113, 2455, 2737, 3096, 3357, 2965, 2692, 2412, 2094, 1840, 1650, 1533, 1485, 1501, 1591, 1747, 1979, 2275, 2582, 2840, 3239, 3543, 3094, 2808, 2555, 2298, 2043, 1851, 1737, 1685, 1703, 1791, 1955, 2178, 2459, 2700, 2992, 3425, 3749, 3286, 2950, 2712, 2495, 2282, 2093, 1972, 1919, 1950, 2033, 2186, 2412, 2625, 2856, 3165, 3713, 4095, 3514, 3156, 2880, 2701, 2511, 2370, 2249, 2203, 2222, 2309, 2454, 2607, 2813, 3060, 3476, 3973, ] gr: [3126, 2654, 2449, 2277, 2167, 2065, 1967, 1898, 1859, 1866, 1917, 2000, 2085, 2198, 2323, 2565, 2866, 2805, 2487, 2288, 2151, 2020, 1894, 1781, 1706, 1672, 1681, 1731, 1812, 1937, 2057, 2191, 2358, 2670, 2662, 2378, 2191, 2044, 1889, 1739, 1629, 1554, 1520, 1528, 1576, 1662, 1791, 1947, 2083, 2253, 2496, 2545, 2278, 2108, 1939, 1753, 1606, 1498, 1421, 1385, 1393, 1444, 1533, 1656, 1830, 2001, 2166, 2370, 2460, 2205, 2037, 1834, 1644, 1494, 1384, 1301, 1264, 1275, 1328, 1422, 1547, 1723, 1914, 2100, 2284, 2377, 2164, 1972, 1748, 1557, 1410, 1287, 1200, 1162, 1174, 1231, 1334, 1463, 1632, 1846, 2043, 2218, 2335, 2117, 1922, 1686, 1494, 1339, 1213, 1125, 1090, 1100, 1157, 1263, 1401, 1569, 1778, 1995, 2176, 2311, 2081, 1879, 1641, 1452, 1292, 1163, 1078, 1038, 1055, 1111, 1217, 1356, 1527, 1740, 1960, 2152, 2296, 2074, 1861, 1621, 1434, 1273, 1142, 1058, 1024, 1032, 1093, 1197, 1338, 1508, 1718, 1949, 2134, 2292, 2079, 1863, 1628, 1441, 1280, 1149, 1065, 1029, 1042, 1100, 1207, 1347, 1519, 1728, 1951, 2144, 2319, 2089, 1890, 1658, 1470, 1312, 1185, 1101, 1065, 1077, 1138, 1242, 1378, 1549, 1757, 1976, 2157, 2353, 2128, 1936, 1706, 1519, 1366, 1249, 1162, 1129, 1142, 1198, 1303, 1434, 1600, 1808, 2011, 2202, 2417, 2165, 1985, 1785, 1586, 1443, 1327, 1249, 1217, 1226, 1283, 1378, 1506, 1675, 1874, 2060, 2255, 2508, 2231, 2044, 1867, 1681, 1530, 1425, 1348, 1320, 1331, 1386, 1476, 1601, 1770, 1955, 2110, 2345, 2616, 2306, 2124, 1958, 1799, 1648, 1536, 1466, 1437, 1448, 1497, 1589, 1716, 1880, 2017, 2199, 2467, 2754, 2434, 2202, 2053, 1920, 1788, 1681, 1608, 1574, 1588, 1641, 1726, 1853, 1980, 2112, 2304, 2656, 3054, 2562, 2347, 2155, 2038, 1931, 1843, 1778, 1742, 1748, 1803, 1887, 1976, 2089, 2229, 2513, 2806, ] gb: [3110, 2650, 2442, 2268, 2159, 2061, 1963, 1887, 1855, 1860, 1910, 1995, 2091, 2202, 2330, 2589, 2876, 2817, 2480, 2285, 2141, 2019, 1890, 1777, 1697, 1664, 1670, 1725, 1811, 1936, 2060, 2200, 2370, 2701, 2645, 2378, 2188, 2041, 1882, 1735, 1623, 1548, 1513, 1524, 1567, 1660, 1798, 1959, 2096, 2272, 2534, 2550, 2276, 2104, 1935, 1753, 1601, 1494, 1417, 1377, 1388, 1441, 1533, 1660, 1839, 2014, 2181, 2402, 2452, 2209, 2036, 1834, 1641, 1493, 1377, 1298, 1257, 1272, 1328, 1426, 1554, 1732, 1932, 2122, 2315, 2387, 2165, 1969, 1749, 1559, 1407, 1285, 1197, 1159, 1171, 1233, 1337, 1472, 1649, 1862, 2070, 2256, 2336, 2119, 1926, 1684, 1495, 1340, 1210, 1124, 1087, 1100, 1159, 1269, 1411, 1582, 1801, 2019, 2219, 2312, 2092, 1885, 1644, 1453, 1295, 1164, 1077, 1036, 1054, 1115, 1221, 1370, 1544, 1763, 1995, 2189, 2297, 2086, 1862, 1629, 1435, 1275, 1145, 1058, 1024, 1036, 1097, 1205, 1352, 1529, 1746, 1980, 2180, 2305, 2091, 1869, 1634, 1444, 1283, 1151, 1066, 1030, 1045, 1106, 1215, 1360, 1538, 1754, 1987, 2182, 2329, 2104, 1896, 1662, 1476, 1315, 1187, 1101, 1066, 1081, 1142, 1249, 1395, 1566, 1785, 2007, 2205, 2369, 2133, 1942, 1715, 1523, 1370, 1247, 1163, 1128, 1141, 1203, 1309, 1447, 1618, 1834, 2043, 2240, 2430, 2181, 1995, 1785, 1588, 1444, 1330, 1247, 1216, 1227, 1287, 1387, 1520, 1694, 1902, 2086, 2299, 2513, 2244, 2058, 1879, 1688, 1534, 1424, 1350, 1317, 1331, 1388, 1478, 1613, 1786, 1975, 2139, 2392, 2625, 2320, 2129, 1965, 1806, 1649, 1539, 1465, 1435, 1446, 1500, 1596, 1728, 1895, 2039, 2230, 2517, 2757, 2450, 2210, 2061, 1924, 1795, 1680, 1608, 1572, 1587, 1638, 1732, 1863, 1994, 2136, 2337, 2692, 3076, 2574, 2347, 2163, 2039, 1933, 1842, 1764, 1738, 1749, 1804, 1883, 1981, 2095, 2253, 2542, 2845, ] b: [2915, 2480, 2280, 2121, 2025, 1929, 1854, 1793, 1773, 1769, 1815, 1879, 1970, 2069, 2185, 2406, 2670, 2610, 2321, 2132, 1997, 1889, 1781, 1681, 1616, 1587, 1598, 1642, 1721, 1831, 1945, 2068, 2221, 2492, 2485, 2222, 2043, 1913, 1775, 1639, 1541, 1485, 1457, 1466, 1500, 1579, 1705, 1855, 1972, 2122, 2360, 2380, 2127, 1969, 1815, 1647, 1516, 1427, 1367, 1342, 1342, 1390, 1463, 1577, 1739, 1901, 2041, 2243, 2297, 2061, 1914, 1722, 1549, 1418, 1325, 1261, 1233, 1241, 1287, 1369, 1483, 1638, 1820, 1994, 2158, 2233, 2025, 1852, 1646, 1474, 1347, 1242, 1171, 1142, 1152, 1203, 1293, 1409, 1559, 1758, 1931, 2104, 2198, 1987, 1808, 1594, 1424, 1290, 1178, 1104, 1079, 1088, 1139, 1232, 1358, 1505, 1700, 1893, 2077, 2165, 1972, 1772, 1561, 1393, 1250, 1139, 1065, 1035, 1051, 1101, 1196, 1323, 1473, 1656, 1867, 2046, 2166, 1960, 1769, 1542, 1381, 1234, 1121, 1048, 1024, 1034, 1084, 1178, 1308, 1462, 1651, 1855, 2036, 2166, 1961, 1774, 1548, 1380, 1240, 1126, 1054, 1025, 1041, 1092, 1186, 1315, 1464, 1654, 1862, 2041, 2184, 1975, 1794, 1576, 1408, 1268, 1155, 1082, 1056, 1066, 1118, 1211, 1338, 1492, 1678, 1877, 2063, 2222, 1999, 1826, 1623, 1441, 1314, 1208, 1137, 1109, 1120, 1171, 1261, 1383, 1533, 1724, 1912, 2071, 2265, 2043, 1871, 1684, 1507, 1372, 1276, 1211, 1183, 1193, 1242, 1327, 1447, 1600, 1781, 1941, 2132, 2351, 2095, 1928, 1760, 1588, 1454, 1357, 1297, 1271, 1282, 1326, 1406, 1523, 1684, 1849, 1988, 2215, 2439, 2167, 1992, 1847, 1695, 1551, 1455, 1397, 1372, 1381, 1422, 1507, 1622, 1785, 1897, 2068, 2323, 2564, 2289, 2068, 1923, 1803, 1684, 1581, 1520, 1495, 1504, 1546, 1623, 1752, 1866, 1990, 2170, 2488, 2838, 2390, 2201, 2026, 1908, 1814, 1736, 1669, 1643, 1654, 1700, 1774, 1862, 1964, 2101, 2363, 2613, ] #3264x2448_D65_70 - D65 - ct: 6504 resolution: 3264x2448 r: [4095, 3609, 3293, 3044, 2858, 2708, 2555, 2426, 2383, 2390, 2485, 2610, 2769, 2948, 3150, 3554, 4002, 3858, 3341, 3067, 2851, 2656, 2436, 2251, 2136, 2083, 2092, 2169, 2327, 2531, 2747, 2983, 3227, 3713, 3579, 3194, 2920, 2704, 2441, 2187, 2002, 1873, 1824, 1838, 1920, 2070, 2308, 2573, 2812, 3074, 3487, 3428, 3039, 2791, 2525, 2213, 1962, 1775, 1650, 1593, 1609, 1691, 1852, 2077, 2379, 2680, 2932, 3261, 3283, 2933, 2685, 2353, 2038, 1779, 1582, 1449, 1395, 1407, 1501, 1661, 1893, 2189, 2527, 2825, 3136, 3179, 2846, 2572, 2206, 1894, 1626, 1426, 1292, 1234, 1250, 1343, 1513, 1744, 2046, 2404, 2725, 3037, 3115, 2787, 2479, 2109, 1786, 1520, 1312, 1180, 1120, 1136, 1229, 1399, 1641, 1938, 2296, 2645, 2956, 3052, 2747, 2419, 2039, 1716, 1448, 1238, 1106, 1047, 1068, 1160, 1326, 1572, 1876, 2228, 2597, 2913, 3044, 2732, 2389, 2006, 1687, 1415, 1208, 1079, 1024, 1040, 1132, 1296, 1542, 1843, 2206, 2571, 2901, 3049, 2721, 2397, 2016, 1694, 1426, 1215, 1091, 1035, 1055, 1145, 1312, 1550, 1859, 2211, 2575, 2919, 3078, 2759, 2434, 2063, 1737, 1478, 1271, 1141, 1088, 1106, 1199, 1367, 1603, 1905, 2267, 2616, 2927, 3143, 2793, 2505, 2140, 1828, 1564, 1364, 1237, 1183, 1202, 1290, 1461, 1695, 1996, 2340, 2676, 2993, 3228, 2867, 2595, 2268, 1942, 1689, 1499, 1370, 1316, 1340, 1431, 1593, 1823, 2117, 2461, 2756, 3077, 3371, 2972, 2696, 2408, 2104, 1852, 1661, 1541, 1491, 1505, 1599, 1758, 1987, 2276, 2582, 2849, 3235, 3523, 3088, 2811, 2565, 2302, 2046, 1860, 1745, 1694, 1716, 1800, 1961, 2188, 2460, 2699, 2987, 3420, 3757, 3276, 2947, 2706, 2497, 2283, 2099, 1979, 1929, 1947, 2032, 2199, 2409, 2626, 2852, 3158, 3715, 4095, 3473, 3168, 2886, 2708, 2514, 2365, 2251, 2203, 2229, 2315, 2440, 2623, 2806, 3061, 3472, 3935, ] gr: [3109, 2638, 2434, 2267, 2147, 2051, 1954, 1871, 1847, 1848, 1903, 1981, 2080, 2184, 2312, 2555, 2821, 2799, 2481, 2275, 2132, 2010, 1885, 1775, 1698, 1665, 1670, 1719, 1802, 1926, 2045, 2182, 2346, 2660, 2643, 2361, 2180, 2032, 1880, 1730, 1618, 1547, 1513, 1520, 1566, 1652, 1785, 1940, 2074, 2238, 2491, 2534, 2272, 2096, 1934, 1743, 1597, 1491, 1416, 1379, 1389, 1437, 1526, 1653, 1822, 1991, 2156, 2356, 2445, 2203, 2031, 1828, 1639, 1492, 1376, 1298, 1261, 1270, 1325, 1418, 1540, 1717, 1908, 2093, 2270, 2374, 2153, 1965, 1746, 1552, 1404, 1282, 1198, 1160, 1173, 1228, 1331, 1459, 1629, 1836, 2038, 2206, 2328, 2111, 1916, 1679, 1490, 1336, 1208, 1123, 1087, 1097, 1156, 1260, 1398, 1564, 1772, 1985, 2174, 2292, 2087, 1871, 1639, 1448, 1292, 1161, 1077, 1038, 1051, 1111, 1214, 1355, 1521, 1732, 1955, 2142, 2290, 2067, 1852, 1619, 1430, 1271, 1141, 1055, 1024, 1033, 1091, 1194, 1335, 1507, 1715, 1939, 2133, 2285, 2073, 1861, 1623, 1436, 1278, 1147, 1065, 1028, 1042, 1099, 1204, 1345, 1514, 1723, 1945, 2131, 2312, 2082, 1884, 1653, 1467, 1308, 1181, 1100, 1065, 1076, 1133, 1240, 1377, 1543, 1754, 1968, 2151, 2350, 2114, 1928, 1703, 1515, 1364, 1244, 1161, 1126, 1138, 1197, 1300, 1429, 1595, 1803, 2003, 2192, 2404, 2166, 1977, 1775, 1581, 1435, 1322, 1245, 1213, 1223, 1278, 1375, 1504, 1671, 1872, 2048, 2255, 2499, 2220, 2040, 1859, 1678, 1526, 1416, 1345, 1314, 1327, 1380, 1468, 1596, 1763, 1948, 2105, 2337, 2607, 2299, 2116, 1951, 1792, 1638, 1534, 1458, 1431, 1443, 1492, 1583, 1709, 1873, 2004, 2191, 2463, 2733, 2429, 2197, 2044, 1912, 1782, 1670, 1601, 1568, 1581, 1630, 1719, 1847, 1973, 2107, 2304, 2637, 3045, 2548, 2338, 2143, 2029, 1920, 1832, 1762, 1736, 1737, 1795, 1871, 1961, 2070, 2227, 2493, 2794, ] gb: [3118, 2634, 2434, 2259, 2154, 2052, 1949, 1888, 1844, 1853, 1900, 1987, 2084, 2192, 2325, 2571, 2855, 2786, 2469, 2271, 2125, 2010, 1882, 1775, 1690, 1662, 1669, 1719, 1805, 1928, 2050, 2192, 2362, 2674, 2635, 2358, 2173, 2030, 1872, 1729, 1620, 1547, 1508, 1516, 1565, 1654, 1790, 1947, 2082, 2257, 2516, 2527, 2260, 2094, 1923, 1744, 1598, 1486, 1411, 1374, 1388, 1438, 1525, 1657, 1830, 2001, 2169, 2382, 2431, 2196, 2021, 1824, 1634, 1486, 1376, 1296, 1254, 1269, 1325, 1422, 1547, 1722, 1922, 2106, 2297, 2367, 2146, 1960, 1736, 1550, 1402, 1281, 1196, 1157, 1169, 1230, 1333, 1466, 1640, 1848, 2055, 2232, 2320, 2105, 1909, 1675, 1489, 1335, 1208, 1120, 1083, 1099, 1158, 1265, 1405, 1575, 1794, 2006, 2206, 2295, 2075, 1873, 1634, 1447, 1292, 1162, 1076, 1037, 1052, 1113, 1220, 1363, 1541, 1748, 1982, 2173, 2278, 2071, 1850, 1619, 1430, 1271, 1144, 1056, 1024, 1035, 1096, 1202, 1348, 1521, 1736, 1966, 2162, 2290, 2073, 1856, 1626, 1439, 1279, 1150, 1065, 1029, 1043, 1104, 1211, 1355, 1532, 1744, 1973, 2166, 2302, 2090, 1883, 1651, 1466, 1313, 1184, 1100, 1065, 1078, 1139, 1246, 1388, 1557, 1771, 1995, 2185, 2344, 2122, 1927, 1706, 1513, 1368, 1245, 1163, 1126, 1140, 1200, 1305, 1441, 1612, 1823, 2030, 2225, 2411, 2166, 1983, 1776, 1584, 1439, 1324, 1245, 1213, 1225, 1283, 1383, 1513, 1688, 1887, 2074, 2281, 2493, 2226, 2042, 1867, 1679, 1535, 1418, 1349, 1317, 1329, 1382, 1476, 1607, 1780, 1968, 2128, 2376, 2613, 2305, 2120, 1955, 1797, 1642, 1536, 1460, 1430, 1446, 1496, 1591, 1722, 1887, 2029, 2217, 2500, 2745, 2434, 2202, 2052, 1917, 1784, 1676, 1603, 1572, 1584, 1634, 1731, 1857, 1986, 2128, 2326, 2675, 3059, 2546, 2342, 2153, 2041, 1930, 1833, 1767, 1731, 1739, 1795, 1880, 1970, 2091, 2242, 2528, 2816, ] b: [2873, 2460, 2268, 2104, 2011, 1921, 1837, 1775, 1753, 1759, 1798, 1871, 1956, 2059, 2172, 2375, 2631, 2606, 2309, 2117, 1990, 1879, 1768, 1673, 1606, 1582, 1588, 1633, 1705, 1820, 1931, 2051, 2202, 2475, 2458, 2204, 2033, 1901, 1760, 1630, 1533, 1475, 1452, 1455, 1495, 1572, 1694, 1839, 1962, 2110, 2332, 2361, 2122, 1964, 1800, 1640, 1506, 1417, 1362, 1332, 1340, 1378, 1452, 1573, 1727, 1887, 2031, 2222, 2280, 2053, 1893, 1713, 1542, 1414, 1321, 1257, 1229, 1235, 1282, 1365, 1470, 1633, 1804, 1974, 2144, 2220, 2010, 1846, 1638, 1472, 1340, 1238, 1168, 1141, 1149, 1201, 1288, 1403, 1551, 1742, 1923, 2094, 2180, 1986, 1797, 1591, 1416, 1287, 1176, 1105, 1077, 1088, 1137, 1230, 1350, 1502, 1688, 1885, 2062, 2161, 1955, 1767, 1554, 1387, 1249, 1135, 1064, 1035, 1050, 1097, 1191, 1317, 1471, 1654, 1863, 2027, 2145, 1955, 1757, 1539, 1375, 1233, 1121, 1047, 1024, 1033, 1086, 1175, 1303, 1454, 1640, 1848, 2020, 2154, 1953, 1760, 1542, 1379, 1237, 1124, 1053, 1027, 1038, 1089, 1182, 1310, 1463, 1645, 1848, 2028, 2167, 1965, 1781, 1567, 1400, 1266, 1152, 1083, 1054, 1066, 1117, 1209, 1334, 1483, 1674, 1867, 2043, 2207, 1995, 1816, 1613, 1440, 1311, 1204, 1137, 1109, 1118, 1169, 1258, 1378, 1527, 1713, 1899, 2067, 2247, 2035, 1862, 1676, 1500, 1369, 1274, 1208, 1182, 1190, 1237, 1324, 1439, 1592, 1770, 1930, 2126, 2337, 2085, 1919, 1752, 1585, 1447, 1353, 1294, 1270, 1278, 1325, 1401, 1517, 1672, 1842, 1979, 2199, 2421, 2154, 1984, 1835, 1686, 1549, 1450, 1393, 1369, 1381, 1418, 1500, 1617, 1769, 1886, 2055, 2310, 2539, 2273, 2056, 1921, 1791, 1680, 1576, 1515, 1490, 1499, 1544, 1624, 1737, 1860, 1983, 2162, 2458, 2817, 2386, 2185, 2018, 1904, 1802, 1724, 1668, 1638, 1646, 1685, 1765, 1851, 1953, 2089, 2342, 2607, ] #3264x2448_D75_70 - D75 - ct: 7504 resolution: 3264x2448 r: [4095, 3519, 3218, 2985, 2815, 2645, 2509, 2389, 2327, 2355, 2435, 2555, 2710, 2908, 3107, 3455, 3909, 3739, 3284, 3001, 2795, 2603, 2392, 2213, 2093, 2049, 2058, 2135, 2281, 2493, 2685, 2920, 3163, 3650, 3536, 3113, 2865, 2641, 2393, 2149, 1967, 1852, 1802, 1811, 1894, 2037, 2267, 2525, 2747, 3014, 3388, 3358, 2983, 2730, 2466, 2185, 1933, 1755, 1634, 1579, 1590, 1678, 1826, 2049, 2329, 2621, 2864, 3207, 3196, 2870, 2628, 2311, 2001, 1757, 1569, 1439, 1382, 1396, 1488, 1645, 1865, 2163, 2477, 2773, 3063, 3115, 2785, 2512, 2175, 1859, 1619, 1412, 1285, 1228, 1243, 1335, 1502, 1726, 2015, 2362, 2666, 2951, 3027, 2733, 2430, 2073, 1761, 1507, 1303, 1172, 1116, 1132, 1223, 1388, 1622, 1913, 2253, 2591, 2908, 2995, 2683, 2368, 2007, 1696, 1435, 1234, 1104, 1045, 1068, 1154, 1317, 1561, 1846, 2189, 2547, 2845, 2960, 2670, 2344, 1972, 1667, 1403, 1205, 1074, 1024, 1038, 1128, 1290, 1526, 1816, 2166, 2519, 2841, 2985, 2665, 2355, 1980, 1675, 1416, 1210, 1087, 1032, 1052, 1141, 1300, 1537, 1836, 2171, 2530, 2837, 3017, 2686, 2380, 2030, 1721, 1465, 1264, 1140, 1086, 1104, 1190, 1358, 1586, 1879, 2221, 2556, 2871, 3062, 2738, 2456, 2107, 1796, 1549, 1356, 1232, 1175, 1192, 1285, 1446, 1672, 1961, 2298, 2626, 2926, 3172, 2807, 2533, 2227, 1916, 1670, 1485, 1356, 1308, 1325, 1415, 1577, 1801, 2085, 2411, 2676, 3033, 3272, 2904, 2640, 2360, 2069, 1821, 1639, 1525, 1476, 1492, 1580, 1735, 1951, 2232, 2536, 2784, 3143, 3481, 3014, 2752, 2511, 2256, 2018, 1835, 1719, 1672, 1687, 1777, 1931, 2151, 2414, 2647, 2922, 3369, 3652, 3193, 2877, 2650, 2441, 2239, 2058, 1946, 1895, 1918, 1999, 2153, 2365, 2572, 2794, 3086, 3594, 4095, 3408, 3097, 2824, 2643, 2469, 2323, 2215, 2158, 2187, 2264, 2412, 2554, 2742, 2991, 3425, 3869, ] gr: [3118, 2636, 2433, 2254, 2141, 2035, 1950, 1873, 1840, 1849, 1893, 1975, 2079, 2175, 2303, 2544, 2821, 2787, 2475, 2277, 2131, 2003, 1880, 1767, 1691, 1656, 1665, 1715, 1794, 1921, 2037, 2179, 2343, 2648, 2644, 2359, 2180, 2024, 1877, 1724, 1615, 1543, 1508, 1516, 1561, 1650, 1780, 1935, 2071, 2236, 2483, 2533, 2271, 2094, 1926, 1742, 1593, 1487, 1413, 1377, 1385, 1434, 1520, 1647, 1819, 1984, 2150, 2358, 2451, 2197, 2027, 1823, 1635, 1491, 1375, 1296, 1258, 1268, 1324, 1417, 1538, 1712, 1905, 2087, 2270, 2374, 2145, 1961, 1741, 1549, 1402, 1281, 1196, 1159, 1169, 1227, 1325, 1458, 1624, 1834, 2028, 2212, 2324, 2109, 1912, 1678, 1487, 1335, 1208, 1123, 1087, 1096, 1155, 1260, 1394, 1560, 1769, 1981, 2168, 2302, 2071, 1872, 1633, 1447, 1290, 1159, 1076, 1038, 1052, 1109, 1211, 1356, 1521, 1728, 1954, 2134, 2285, 2065, 1850, 1617, 1427, 1269, 1142, 1054, 1024, 1033, 1090, 1194, 1333, 1502, 1714, 1936, 2128, 2281, 2075, 1855, 1621, 1435, 1277, 1146, 1064, 1030, 1042, 1100, 1203, 1341, 1513, 1721, 1948, 2122, 2312, 2076, 1880, 1647, 1463, 1308, 1180, 1099, 1064, 1075, 1132, 1237, 1375, 1539, 1746, 1961, 2151, 2345, 2115, 1924, 1700, 1514, 1361, 1244, 1160, 1126, 1137, 1194, 1298, 1427, 1592, 1802, 2001, 2181, 2409, 2156, 1978, 1774, 1578, 1435, 1320, 1242, 1211, 1221, 1276, 1372, 1498, 1668, 1864, 2047, 2237, 2494, 2218, 2033, 1858, 1672, 1520, 1415, 1343, 1311, 1324, 1376, 1462, 1590, 1758, 1940, 2097, 2340, 2607, 2290, 2110, 1945, 1786, 1638, 1526, 1455, 1425, 1437, 1485, 1578, 1705, 1868, 1998, 2185, 2460, 2727, 2419, 2192, 2039, 1906, 1775, 1666, 1593, 1565, 1576, 1627, 1711, 1838, 1963, 2101, 2299, 2626, 3040, 2538, 2330, 2138, 2021, 1918, 1827, 1755, 1724, 1732, 1784, 1866, 1954, 2068, 2214, 2496, 2760, ] gb: [3103, 2631, 2429, 2258, 2149, 2044, 1949, 1878, 1843, 1853, 1904, 1985, 2081, 2188, 2320, 2563, 2842, 2787, 2459, 2271, 2124, 2008, 1878, 1772, 1689, 1663, 1666, 1715, 1801, 1924, 2045, 2190, 2357, 2679, 2626, 2355, 2170, 2027, 1869, 1724, 1617, 1543, 1507, 1517, 1566, 1653, 1785, 1945, 2080, 2250, 2509, 2516, 2256, 2083, 1920, 1737, 1595, 1485, 1413, 1376, 1385, 1438, 1526, 1654, 1826, 1997, 2161, 2383, 2426, 2190, 2013, 1820, 1629, 1486, 1374, 1294, 1255, 1266, 1325, 1419, 1543, 1721, 1918, 2103, 2291, 2358, 2142, 1954, 1731, 1545, 1400, 1280, 1194, 1157, 1171, 1227, 1334, 1465, 1633, 1848, 2045, 2227, 2319, 2095, 1902, 1672, 1488, 1334, 1207, 1123, 1085, 1096, 1157, 1261, 1401, 1572, 1784, 2003, 2191, 2286, 2071, 1863, 1631, 1445, 1289, 1160, 1075, 1038, 1053, 1113, 1221, 1363, 1534, 1743, 1971, 2167, 2278, 2059, 1844, 1613, 1427, 1271, 1143, 1057, 1024, 1035, 1096, 1199, 1346, 1518, 1731, 1960, 2153, 2280, 2065, 1853, 1619, 1438, 1278, 1149, 1066, 1029, 1044, 1105, 1210, 1354, 1528, 1735, 1970, 2160, 2302, 2080, 1875, 1649, 1465, 1309, 1183, 1100, 1065, 1079, 1136, 1246, 1384, 1556, 1767, 1987, 2178, 2346, 2109, 1923, 1697, 1514, 1365, 1245, 1160, 1127, 1141, 1199, 1303, 1438, 1608, 1818, 2027, 2215, 2410, 2158, 1976, 1774, 1578, 1437, 1325, 1245, 1212, 1225, 1284, 1379, 1514, 1680, 1883, 2068, 2272, 2489, 2219, 2041, 1862, 1677, 1529, 1417, 1345, 1314, 1327, 1381, 1474, 1600, 1780, 1961, 2120, 2371, 2601, 2306, 2111, 1953, 1795, 1642, 1534, 1459, 1431, 1443, 1496, 1587, 1717, 1881, 2024, 2213, 2482, 2733, 2436, 2194, 2049, 1910, 1784, 1674, 1600, 1567, 1581, 1632, 1728, 1855, 1985, 2122, 2321, 2675, 3032, 2542, 2344, 2151, 2037, 1930, 1834, 1767, 1732, 1747, 1791, 1879, 1968, 2083, 2239, 2522, 2807, ] b: [2879, 2455, 2264, 2106, 2006, 1922, 1836, 1777, 1750, 1753, 1802, 1870, 1949, 2055, 2160, 2385, 2620, 2609, 2309, 2119, 1990, 1882, 1764, 1668, 1603, 1583, 1586, 1625, 1704, 1818, 1933, 2054, 2201, 2478, 2465, 2208, 2038, 1897, 1760, 1627, 1531, 1477, 1450, 1453, 1492, 1569, 1686, 1838, 1960, 2103, 2342, 2362, 2116, 1967, 1802, 1637, 1506, 1416, 1359, 1332, 1340, 1379, 1453, 1574, 1722, 1888, 2030, 2214, 2284, 2053, 1896, 1715, 1540, 1412, 1320, 1257, 1227, 1236, 1282, 1363, 1468, 1629, 1806, 1969, 2149, 2217, 2010, 1841, 1638, 1470, 1340, 1237, 1168, 1140, 1146, 1199, 1286, 1401, 1552, 1740, 1932, 2082, 2182, 1981, 1791, 1589, 1418, 1287, 1175, 1104, 1076, 1087, 1137, 1227, 1352, 1497, 1690, 1883, 2059, 2158, 1964, 1767, 1551, 1387, 1247, 1135, 1065, 1036, 1048, 1100, 1190, 1318, 1466, 1651, 1858, 2037, 2149, 1951, 1756, 1539, 1373, 1233, 1121, 1047, 1024, 1035, 1085, 1174, 1302, 1457, 1637, 1845, 2021, 2153, 1952, 1760, 1542, 1378, 1236, 1126, 1054, 1026, 1040, 1090, 1181, 1308, 1458, 1645, 1852, 2025, 2172, 1964, 1780, 1565, 1398, 1266, 1151, 1085, 1055, 1066, 1116, 1209, 1333, 1484, 1667, 1864, 2036, 2200, 1989, 1822, 1612, 1435, 1311, 1202, 1135, 1108, 1117, 1169, 1259, 1374, 1526, 1714, 1895, 2075, 2259, 2034, 1860, 1674, 1500, 1363, 1275, 1208, 1180, 1192, 1237, 1319, 1437, 1591, 1767, 1932, 2119, 2327, 2081, 1914, 1750, 1580, 1445, 1350, 1292, 1269, 1279, 1320, 1400, 1515, 1671, 1835, 1975, 2198, 2428, 2152, 1983, 1838, 1684, 1546, 1448, 1394, 1367, 1377, 1417, 1501, 1615, 1768, 1890, 2056, 2310, 2536, 2273, 2059, 1919, 1794, 1676, 1576, 1512, 1487, 1499, 1543, 1621, 1741, 1856, 1980, 2155, 2463, 2820, 2387, 2189, 2014, 1906, 1806, 1722, 1672, 1639, 1645, 1687, 1758, 1846, 1950, 2094, 2345, 2609, ] #3264x2448_F11_TL84_70 - F11_TL84 - ct: 4000 resolution: 3264x2448 r: [4002, 3309, 3035, 2794, 2634, 2461, 2319, 2207, 2157, 2168, 2244, 2370, 2537, 2712, 2917, 3269, 3672, 3551, 3103, 2825, 2625, 2420, 2214, 2037, 1922, 1874, 1882, 1956, 2100, 2302, 2511, 2738, 2969, 3444, 3298, 2949, 2692, 2463, 2213, 1969, 1792, 1686, 1640, 1646, 1721, 1857, 2074, 2333, 2576, 2831, 3187, 3157, 2805, 2562, 2298, 1998, 1762, 1596, 1491, 1444, 1454, 1521, 1655, 1863, 2142, 2432, 2691, 3014, 3030, 2709, 2454, 2128, 1831, 1597, 1435, 1335, 1291, 1302, 1366, 1495, 1686, 1971, 2291, 2593, 2883, 2940, 2627, 2345, 1995, 1701, 1475, 1311, 1216, 1176, 1186, 1246, 1372, 1564, 1831, 2173, 2490, 2788, 2868, 2575, 2259, 1900, 1604, 1387, 1231, 1136, 1095, 1105, 1167, 1286, 1475, 1735, 2074, 2418, 2721, 2826, 2533, 2203, 1835, 1548, 1332, 1177, 1084, 1042, 1056, 1116, 1233, 1422, 1676, 2015, 2370, 2679, 2812, 2511, 2176, 1810, 1521, 1303, 1157, 1063, 1024, 1034, 1095, 1216, 1398, 1657, 1989, 2342, 2677, 2816, 2517, 2185, 1816, 1530, 1312, 1161, 1070, 1031, 1041, 1109, 1224, 1410, 1665, 1999, 2359, 2664, 2839, 2531, 2218, 1856, 1571, 1350, 1197, 1106, 1065, 1080, 1142, 1263, 1451, 1708, 2046, 2389, 2703, 2896, 2578, 2281, 1935, 1636, 1421, 1265, 1171, 1135, 1147, 1209, 1335, 1527, 1788, 2123, 2454, 2753, 2994, 2638, 2366, 2046, 1749, 1522, 1365, 1268, 1231, 1245, 1310, 1442, 1638, 1912, 2230, 2518, 2840, 3101, 2741, 2467, 2183, 1895, 1664, 1502, 1402, 1363, 1376, 1451, 1582, 1789, 2057, 2362, 2609, 2977, 3260, 2841, 2581, 2342, 2083, 1842, 1676, 1575, 1534, 1553, 1625, 1769, 1977, 2240, 2474, 2752, 3175, 3489, 3019, 2716, 2496, 2274, 2077, 1899, 1789, 1751, 1769, 1847, 1991, 2189, 2409, 2631, 2927, 3411, 3949, 3229, 2910, 2647, 2477, 2296, 2156, 2049, 2010, 2022, 2104, 2237, 2398, 2579, 2812, 3226, 3666, ] gr: [3132, 2654, 2457, 2283, 2168, 2064, 1974, 1892, 1855, 1864, 1922, 1997, 2100, 2202, 2331, 2576, 2861, 2822, 2487, 2297, 2143, 2021, 1891, 1780, 1697, 1664, 1669, 1720, 1809, 1934, 2058, 2197, 2364, 2674, 2652, 2374, 2189, 2039, 1882, 1732, 1618, 1541, 1502, 1512, 1561, 1654, 1788, 1943, 2081, 2250, 2503, 2542, 2272, 2100, 1925, 1743, 1592, 1482, 1408, 1367, 1378, 1429, 1517, 1644, 1816, 1993, 2163, 2364, 2454, 2203, 2028, 1824, 1624, 1481, 1366, 1286, 1249, 1256, 1312, 1409, 1527, 1709, 1905, 2097, 2279, 2368, 2158, 1956, 1731, 1540, 1390, 1275, 1189, 1153, 1165, 1219, 1318, 1446, 1615, 1833, 2032, 2220, 2332, 2110, 1908, 1667, 1473, 1322, 1200, 1119, 1085, 1095, 1149, 1249, 1383, 1550, 1760, 1983, 2175, 2300, 2074, 1859, 1619, 1428, 1273, 1154, 1072, 1038, 1052, 1105, 1203, 1339, 1506, 1722, 1951, 2146, 2289, 2061, 1844, 1602, 1410, 1256, 1134, 1053, 1024, 1031, 1089, 1183, 1320, 1490, 1702, 1938, 2137, 2282, 2067, 1845, 1605, 1418, 1260, 1141, 1061, 1027, 1041, 1095, 1194, 1328, 1497, 1713, 1942, 2139, 2318, 2083, 1870, 1634, 1448, 1296, 1173, 1096, 1062, 1073, 1129, 1226, 1363, 1528, 1741, 1967, 2157, 2345, 2113, 1918, 1691, 1495, 1351, 1233, 1154, 1119, 1132, 1189, 1286, 1418, 1583, 1795, 2001, 2190, 2416, 2159, 1976, 1767, 1568, 1424, 1311, 1232, 1202, 1211, 1268, 1363, 1490, 1661, 1868, 2047, 2256, 2502, 2222, 2037, 1855, 1670, 1518, 1407, 1333, 1302, 1313, 1369, 1457, 1591, 1756, 1941, 2106, 2352, 2619, 2304, 2118, 1948, 1789, 1638, 1523, 1449, 1418, 1432, 1483, 1578, 1706, 1875, 2011, 2197, 2473, 2758, 2433, 2198, 2052, 1915, 1783, 1674, 1593, 1566, 1576, 1629, 1721, 1852, 1976, 2115, 2312, 2657, 3071, 2569, 2344, 2154, 2039, 1930, 1841, 1773, 1734, 1748, 1795, 1881, 1974, 2089, 2231, 2521, 2802, ] gb: [3133, 2656, 2457, 2275, 2154, 2053, 1951, 1877, 1838, 1848, 1901, 1985, 2088, 2205, 2345, 2598, 2891, 2824, 2492, 2292, 2135, 2015, 1879, 1765, 1681, 1647, 1653, 1708, 1800, 1928, 2056, 2208, 2384, 2708, 2667, 2381, 2198, 2039, 1879, 1723, 1610, 1527, 1492, 1502, 1553, 1645, 1781, 1953, 2093, 2277, 2545, 2558, 2287, 2108, 1931, 1743, 1586, 1472, 1400, 1359, 1367, 1424, 1513, 1652, 1830, 2012, 2188, 2417, 2474, 2212, 2042, 1831, 1630, 1477, 1365, 1283, 1242, 1255, 1313, 1408, 1538, 1723, 1930, 2127, 2323, 2395, 2169, 1970, 1738, 1548, 1392, 1272, 1187, 1151, 1161, 1222, 1322, 1459, 1633, 1861, 2066, 2263, 2356, 2130, 1922, 1679, 1479, 1325, 1200, 1118, 1082, 1094, 1151, 1254, 1396, 1573, 1792, 2024, 2227, 2337, 2095, 1883, 1627, 1438, 1279, 1156, 1074, 1038, 1054, 1110, 1211, 1352, 1530, 1752, 1997, 2195, 2306, 2095, 1861, 1616, 1421, 1258, 1139, 1055, 1024, 1035, 1094, 1193, 1335, 1513, 1741, 1986, 2182, 2315, 2094, 1867, 1622, 1427, 1266, 1143, 1064, 1029, 1044, 1100, 1202, 1344, 1523, 1746, 1989, 2193, 2342, 2108, 1890, 1648, 1458, 1299, 1176, 1096, 1061, 1075, 1132, 1236, 1376, 1557, 1773, 2010, 2203, 2377, 2140, 1939, 1704, 1508, 1353, 1232, 1154, 1120, 1131, 1193, 1292, 1432, 1608, 1828, 2044, 2251, 2443, 2185, 1992, 1782, 1577, 1428, 1315, 1233, 1199, 1214, 1271, 1370, 1504, 1685, 1895, 2093, 2305, 2519, 2249, 2058, 1869, 1675, 1519, 1406, 1331, 1298, 1313, 1371, 1462, 1599, 1781, 1976, 2139, 2405, 2637, 2326, 2130, 1962, 1792, 1637, 1521, 1445, 1412, 1428, 1481, 1578, 1713, 1888, 2035, 2238, 2529, 2777, 2458, 2215, 2053, 1917, 1776, 1662, 1588, 1554, 1568, 1624, 1722, 1851, 1992, 2136, 2351, 2708, 3076, 2575, 2354, 2161, 2036, 1925, 1834, 1757, 1723, 1732, 1779, 1874, 1972, 2093, 2258, 2546, 2857, ] b: [2906, 2483, 2290, 2108, 2020, 1921, 1851, 1778, 1756, 1759, 1799, 1880, 1969, 2074, 2183, 2435, 2664, 2618, 2324, 2122, 1992, 1883, 1772, 1666, 1601, 1578, 1586, 1627, 1712, 1827, 1934, 2072, 2225, 2524, 2483, 2211, 2037, 1900, 1761, 1625, 1532, 1472, 1447, 1449, 1486, 1571, 1692, 1847, 1968, 2118, 2360, 2370, 2126, 1961, 1803, 1638, 1509, 1411, 1355, 1324, 1335, 1376, 1449, 1572, 1729, 1884, 2042, 2233, 2286, 2051, 1902, 1710, 1537, 1407, 1314, 1249, 1222, 1228, 1276, 1356, 1472, 1629, 1815, 1975, 2159, 2238, 2012, 1839, 1636, 1463, 1333, 1232, 1165, 1137, 1144, 1192, 1280, 1394, 1549, 1743, 1922, 2094, 2184, 1979, 1797, 1586, 1413, 1279, 1170, 1102, 1074, 1086, 1134, 1219, 1345, 1492, 1684, 1888, 2067, 2160, 1958, 1765, 1546, 1378, 1240, 1132, 1062, 1035, 1050, 1095, 1184, 1307, 1459, 1646, 1858, 2036, 2151, 1954, 1752, 1531, 1366, 1224, 1115, 1046, 1026, 1033, 1081, 1170, 1293, 1450, 1635, 1845, 2032, 2155, 1948, 1754, 1535, 1373, 1228, 1118, 1053, 1024, 1038, 1088, 1175, 1299, 1452, 1638, 1849, 2027, 2179, 1970, 1780, 1565, 1391, 1259, 1147, 1079, 1053, 1063, 1113, 1203, 1324, 1474, 1668, 1869, 2037, 2214, 1989, 1816, 1610, 1433, 1297, 1194, 1130, 1105, 1112, 1161, 1249, 1367, 1522, 1710, 1892, 2074, 2264, 2034, 1863, 1673, 1491, 1360, 1264, 1199, 1176, 1185, 1230, 1312, 1434, 1590, 1770, 1936, 2127, 2348, 2084, 1916, 1751, 1581, 1437, 1343, 1284, 1254, 1268, 1312, 1395, 1516, 1673, 1837, 1986, 2216, 2445, 2159, 1975, 1832, 1684, 1544, 1441, 1381, 1358, 1367, 1413, 1494, 1612, 1773, 1894, 2067, 2330, 2573, 2285, 2061, 1914, 1791, 1672, 1568, 1507, 1480, 1492, 1529, 1619, 1743, 1862, 1987, 2168, 2475, 2853, 2395, 2197, 2003, 1909, 1798, 1726, 1652, 1638, 1640, 1687, 1762, 1852, 1956, 2101, 2365, 2643, ] #3264x2448_F2_CWF_70 - F2_CWF - ct: 4230 resolution: 3264x2448 r: [3695, 3077, 2822, 2622, 2472, 2342, 2200, 2111, 2075, 2079, 2145, 2258, 2393, 2547, 2713, 3030, 3396, 3294, 2882, 2641, 2461, 2294, 2117, 1965, 1868, 1822, 1827, 1898, 2020, 2200, 2366, 2557, 2763, 3190, 3081, 2755, 2527, 2334, 2120, 1915, 1760, 1667, 1625, 1635, 1702, 1820, 2002, 2225, 2422, 2641, 2979, 2935, 2624, 2415, 2192, 1939, 1732, 1587, 1496, 1452, 1461, 1526, 1643, 1825, 2064, 2314, 2518, 2804, 2832, 2532, 2323, 2050, 1792, 1591, 1448, 1348, 1301, 1315, 1382, 1504, 1675, 1916, 2190, 2435, 2700, 2735, 2464, 2229, 1935, 1680, 1485, 1327, 1227, 1183, 1194, 1265, 1392, 1567, 1799, 2091, 2351, 2611, 2673, 2415, 2150, 1853, 1597, 1397, 1244, 1144, 1096, 1111, 1182, 1308, 1489, 1715, 2000, 2291, 2552, 2638, 2381, 2104, 1797, 1546, 1342, 1189, 1086, 1042, 1058, 1126, 1255, 1435, 1666, 1950, 2257, 2514, 2621, 2361, 2083, 1766, 1525, 1319, 1164, 1064, 1024, 1037, 1106, 1231, 1415, 1644, 1929, 2233, 2506, 2638, 2364, 2088, 1777, 1528, 1326, 1168, 1073, 1029, 1046, 1115, 1240, 1422, 1654, 1941, 2237, 2511, 2655, 2388, 2121, 1813, 1563, 1366, 1210, 1114, 1070, 1084, 1155, 1283, 1459, 1693, 1981, 2269, 2530, 2712, 2427, 2182, 1884, 1628, 1428, 1281, 1183, 1143, 1158, 1226, 1352, 1531, 1764, 2046, 2317, 2579, 2790, 2485, 2250, 1983, 1722, 1523, 1379, 1284, 1242, 1258, 1327, 1454, 1628, 1862, 2139, 2376, 2667, 2895, 2571, 2344, 2103, 1851, 1644, 1506, 1409, 1371, 1388, 1457, 1578, 1756, 1996, 2250, 2457, 2782, 3048, 2672, 2441, 2229, 2007, 1806, 1658, 1567, 1526, 1541, 1611, 1739, 1916, 2148, 2340, 2583, 2953, 3225, 2827, 2544, 2353, 2172, 1998, 1846, 1755, 1708, 1732, 1794, 1928, 2102, 2282, 2468, 2726, 3175, 3641, 3010, 2734, 2492, 2341, 2192, 2069, 1968, 1937, 1948, 2023, 2139, 2270, 2437, 2634, 2994, 3392, ] gr: [3050, 2599, 2407, 2232, 2134, 2044, 1950, 1879, 1843, 1845, 1897, 1973, 2069, 2164, 2285, 2518, 2788, 2763, 2436, 2247, 2112, 1994, 1867, 1764, 1688, 1655, 1661, 1710, 1788, 1907, 2024, 2157, 2320, 2612, 2604, 2323, 2155, 2009, 1858, 1715, 1606, 1543, 1504, 1512, 1556, 1640, 1766, 1917, 2047, 2211, 2450, 2492, 2232, 2067, 1906, 1727, 1584, 1480, 1411, 1371, 1381, 1428, 1512, 1632, 1799, 1962, 2124, 2327, 2400, 2164, 1999, 1801, 1617, 1475, 1369, 1292, 1252, 1264, 1317, 1408, 1525, 1691, 1879, 2063, 2240, 2326, 2120, 1935, 1721, 1533, 1392, 1278, 1194, 1156, 1167, 1225, 1319, 1443, 1606, 1809, 2003, 2170, 2291, 2075, 1883, 1653, 1470, 1323, 1204, 1122, 1086, 1096, 1153, 1252, 1381, 1540, 1746, 1951, 2139, 2256, 2043, 1839, 1609, 1430, 1278, 1158, 1076, 1038, 1052, 1108, 1206, 1341, 1500, 1702, 1929, 2103, 2242, 2036, 1820, 1596, 1411, 1260, 1138, 1053, 1024, 1032, 1091, 1186, 1322, 1484, 1690, 1909, 2098, 2251, 2034, 1826, 1598, 1416, 1267, 1143, 1065, 1027, 1043, 1097, 1198, 1328, 1493, 1694, 1913, 2096, 2263, 2048, 1852, 1626, 1447, 1298, 1177, 1096, 1063, 1075, 1131, 1230, 1360, 1521, 1723, 1934, 2117, 2316, 2078, 1897, 1680, 1494, 1351, 1238, 1159, 1123, 1135, 1193, 1290, 1416, 1572, 1776, 1974, 2152, 2362, 2122, 1947, 1746, 1562, 1424, 1313, 1238, 1207, 1218, 1272, 1361, 1484, 1647, 1838, 2014, 2215, 2461, 2182, 2007, 1835, 1653, 1510, 1408, 1336, 1305, 1317, 1368, 1456, 1576, 1736, 1919, 2068, 2306, 2560, 2260, 2080, 1920, 1771, 1626, 1516, 1450, 1420, 1432, 1480, 1566, 1687, 1844, 1975, 2157, 2418, 2703, 2387, 2160, 2012, 1888, 1763, 1660, 1588, 1558, 1566, 1617, 1702, 1827, 1943, 2075, 2267, 2603, 2992, 2511, 2296, 2118, 2001, 1898, 1817, 1749, 1719, 1730, 1779, 1859, 1938, 2050, 2187, 2457, 2741, ] gb: [3060, 2612, 2398, 2229, 2123, 2030, 1932, 1857, 1822, 1830, 1874, 1957, 2069, 2163, 2291, 2542, 2825, 2776, 2432, 2251, 2106, 1988, 1856, 1748, 1668, 1636, 1641, 1695, 1784, 1902, 2026, 2170, 2338, 2654, 2609, 2336, 2151, 2005, 1853, 1710, 1597, 1527, 1487, 1500, 1546, 1634, 1768, 1926, 2063, 2235, 2497, 2514, 2248, 2075, 1908, 1727, 1578, 1471, 1396, 1360, 1371, 1422, 1509, 1639, 1810, 1981, 2151, 2365, 2415, 2182, 2010, 1807, 1619, 1474, 1366, 1284, 1247, 1257, 1316, 1409, 1532, 1710, 1906, 2098, 2282, 2358, 2140, 1949, 1725, 1539, 1393, 1276, 1191, 1153, 1166, 1224, 1325, 1455, 1628, 1840, 2045, 2226, 2308, 2101, 1903, 1666, 1479, 1329, 1204, 1121, 1083, 1098, 1154, 1260, 1395, 1565, 1775, 2000, 2191, 2296, 2069, 1863, 1625, 1437, 1285, 1160, 1074, 1038, 1053, 1112, 1214, 1355, 1527, 1746, 1970, 2167, 2280, 2060, 1844, 1609, 1422, 1262, 1140, 1055, 1024, 1034, 1095, 1198, 1337, 1516, 1724, 1962, 2155, 2284, 2063, 1850, 1618, 1429, 1273, 1147, 1064, 1030, 1043, 1104, 1207, 1351, 1519, 1738, 1965, 2159, 2303, 2083, 1878, 1640, 1460, 1304, 1182, 1099, 1065, 1078, 1136, 1244, 1379, 1552, 1764, 1986, 2181, 2341, 2110, 1916, 1698, 1504, 1359, 1238, 1159, 1125, 1136, 1197, 1297, 1431, 1599, 1809, 2018, 2208, 2403, 2156, 1967, 1764, 1570, 1427, 1315, 1237, 1205, 1217, 1274, 1369, 1502, 1673, 1875, 2061, 2278, 2488, 2208, 2025, 1848, 1662, 1513, 1405, 1333, 1304, 1314, 1372, 1460, 1588, 1760, 1946, 2108, 2355, 2596, 2289, 2101, 1934, 1775, 1624, 1516, 1442, 1412, 1425, 1476, 1571, 1700, 1865, 2005, 2195, 2486, 2720, 2411, 2169, 2025, 1895, 1760, 1650, 1578, 1548, 1559, 1612, 1702, 1834, 1960, 2101, 2302, 2647, 3035, 2523, 2314, 2125, 2002, 1897, 1806, 1738, 1705, 1716, 1766, 1855, 1944, 2061, 2204, 2497, 2792, ] b: [2861, 2421, 2239, 2078, 1980, 1893, 1811, 1762, 1723, 1742, 1779, 1851, 1933, 2034, 2151, 2359, 2635, 2562, 2279, 2088, 1949, 1859, 1748, 1650, 1585, 1562, 1570, 1607, 1691, 1798, 1909, 2028, 2181, 2467, 2428, 2166, 2009, 1873, 1736, 1613, 1518, 1461, 1436, 1441, 1480, 1557, 1676, 1814, 1932, 2087, 2311, 2326, 2088, 1923, 1779, 1621, 1492, 1404, 1351, 1322, 1329, 1368, 1445, 1557, 1708, 1863, 2004, 2200, 2250, 2013, 1869, 1687, 1522, 1398, 1309, 1250, 1218, 1231, 1273, 1354, 1457, 1615, 1779, 1941, 2113, 2187, 1979, 1812, 1617, 1454, 1331, 1231, 1163, 1137, 1145, 1195, 1277, 1392, 1537, 1720, 1899, 2061, 2161, 1947, 1769, 1567, 1405, 1273, 1171, 1101, 1078, 1087, 1132, 1222, 1336, 1483, 1665, 1849, 2018, 2122, 1923, 1740, 1530, 1369, 1239, 1131, 1064, 1037, 1049, 1096, 1182, 1306, 1452, 1625, 1829, 1999, 2115, 1919, 1730, 1520, 1360, 1222, 1117, 1046, 1024, 1033, 1086, 1169, 1288, 1439, 1617, 1815, 1991, 2121, 1918, 1736, 1524, 1359, 1227, 1119, 1053, 1025, 1040, 1088, 1173, 1295, 1442, 1624, 1817, 1995, 2136, 1934, 1750, 1546, 1384, 1254, 1147, 1079, 1053, 1063, 1114, 1203, 1321, 1464, 1649, 1837, 2004, 2179, 1955, 1795, 1587, 1423, 1294, 1195, 1131, 1105, 1112, 1161, 1247, 1362, 1506, 1688, 1872, 2037, 2228, 1999, 1833, 1656, 1480, 1353, 1263, 1197, 1172, 1182, 1228, 1311, 1423, 1574, 1751, 1903, 2078, 2309, 2047, 1889, 1724, 1558, 1425, 1336, 1277, 1252, 1263, 1308, 1382, 1500, 1654, 1806, 1954, 2164, 2390, 2114, 1949, 1802, 1660, 1524, 1429, 1373, 1352, 1360, 1401, 1482, 1597, 1748, 1863, 2031, 2287, 2520, 2231, 2019, 1882, 1760, 1651, 1549, 1494, 1466, 1478, 1519, 1597, 1715, 1827, 1947, 2124, 2444, 2788, 2355, 2157, 1974, 1878, 1770, 1701, 1637, 1615, 1612, 1661, 1743, 1824, 1925, 2064, 2315, 2599, ]
0
repos/libcamera/src/ipa/rkisp1
repos/libcamera/src/ipa/rkisp1/data/imx219.yaml
# SPDX-License-Identifier: CC0-1.0 %YAML 1.1 --- version: 1 algorithms: - Agc: - Awb: - BlackLevelCorrection: R: 256 Gr: 256 Gb: 256 B: 256 - LensShadingCorrection: x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] sets: - ct: 5800 r: [ 1501, 1480, 1478, 1362, 1179, 1056, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1030, 1053, 1134, 1185, 1520, 1480, 1463, 1179, 1056, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1027, 1046, 1134, 1533, 1471, 1179, 1056, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1039, 1471, 1314, 1068, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1314, 1150, 1028, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1150, 1050, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1076, 1026, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1052, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1050, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1050, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1050, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1086, 1037, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1057, 1182, 1071, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1057, 1161, 1345, 1146, 1027, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1036, 1161, 1298, 1612, 1328, 1089, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1036, 1161, 1324, 1463, 1884, 1651, 1339, 1103, 1032, 1025, 1024, 1024, 1024, 1024, 1025, 1038, 1101, 1204, 1324, 1463, 1497, 1933, 1884, 1587, 1275, 1079, 1052, 1046, 1046, 1046, 1046, 1055, 1101, 1204, 1336, 1487, 1493, 1476, ] gr: [ 1262, 1250, 1094, 1027, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1250, 1095, 1028, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1095, 1030, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1030, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1041, 1051, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1051, 1165, 1088, 1051, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1051, 1165, 1261, ] gb: [ 1259, 1248, 1092, 1027, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1248, 1092, 1027, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1092, 1029, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1029, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1041, 1051, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1052, 1166, 1090, 1051, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1052, 1166, 1266, ] b: [ 1380, 1378, 1377, 1247, 1080, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1030, 1406, 1378, 1284, 1092, 1027, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1406, 1338, 1129, 1029, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1338, 1205, 1043, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1205, 1094, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1116, 1039, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1070, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1052, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1052, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1052, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1052, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1070, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1109, 1036, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1057, 1175, 1082, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1057, 1176, 1293, 1172, 1036, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1054, 1185, 1334, 1438, 1294, 1099, 1025, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1054, 1185, 1334, 1334, 1462, 1438, 1226, 1059, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1025, 1054, 1185, 1326, 1334, 1334, ] ...
0
repos/libcamera/src/ipa/rkisp1
repos/libcamera/src/ipa/rkisp1/data/ov5640.yaml
# SPDX-License-Identifier: CC0-1.0 %YAML 1.1 --- version: 1 algorithms: - Agc: - Awb: - BlackLevelCorrection: R: 256 Gr: 256 Gb: 256 B: 256 - ColorProcessing: - GammaSensorLinearization: x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] y: red: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] blue: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ] - LensShadingCorrection: x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] sets: - ct: 3000 r: [ 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, ] gr: [ 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, ] gb: [ 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, ] b: [ 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, ] - ct: 7000 r: [ 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, ] gr: [ 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, ] gb: [ 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, ] b: [ 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, ] - DefectPixelClusterCorrection: fixed-set: false sets: # PG, LC, RO, RND, RG - line-threshold: green: 8 red-blue: 8 line-mad-factor: green: 4 red-blue: 4 pg-factor: green: 8 red-blue: 8 rnd-threshold: green: 10 red-blue: 10 rg-factor: green: 32 red-blue: 32 ro-limits: green: 1 red-blue: 1 rnd-offsets: green: 2 red-blue: 2 # PG, LC, RO - line-threshold: green: 24 red-blue: 32 line-mad-factor: green: 16 red-blue: 24 pg-factor: green: 6 red-blue: 8 ro-limits: green: 2 red-blue: 2 # PG, LC, RO, RND, RG - line-threshold: green: 32 red-blue: 32 line-mad-factor: green: 4 red-blue: 4 pg-factor: green: 10 red-blue: 10 rnd-threshold: green: 6 red-blue: 8 rg-factor: green: 4 red-blue: 4 ro-limits: green: 1 red-blue: 2 rnd-offsets: green: 2 red-blue: 2 - Dpf: DomainFilter: g: [ 16, 16, 16, 16, 16, 16 ] rb: [ 16, 16, 16, 16, 16, 16 ] NoiseLevelFunction: coeff: [ 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023 ] scale-mode: "linear" FilterStrength: r: 64 g: 64 b: 64 - Filter: ...
0
repos/libcamera/src/ipa/rkisp1
repos/libcamera/src/ipa/rkisp1/data/ov2685.yaml
# SPDX-License-Identifier: CC0-1.0 %YAML 1.1 --- version: 1 algorithms: - Agc: - Awb: - LensShadingCorrection: x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] sets: #800x600_A_70 - A - ct: 2856 resolution: 800x600 r: [2451, 2258, 2111, 2039, 1982, 1925, 1860, 1818, 1802, 1815, 1859, 1936, 1997, 2056, 2129, 2298, 2486, 2351, 2157, 2066, 1991, 1912, 1809, 1720, 1677, 1653, 1671, 1739, 1843, 1932, 2009, 2071, 2182, 2392, 2253, 2105, 2018, 1929, 1802, 1670, 1566, 1503, 1475, 1508, 1590, 1705, 1848, 1947, 2026, 2118, 2281, 2174, 2065, 1975, 1854, 1687, 1529, 1412, 1345, 1327, 1358, 1445, 1572, 1733, 1870, 1992, 2075, 2202, 2125, 2033, 1929, 1765, 1574, 1407, 1286, 1220, 1204, 1237, 1318, 1447, 1632, 1801, 1951, 2048, 2142, 2092, 2010, 1877, 1688, 1471, 1304, 1187, 1127, 1118, 1149, 1221, 1348, 1533, 1738, 1918, 2021, 2105, 2088, 1982, 1836, 1628, 1398, 1239, 1128, 1073, 1060, 1086, 1163, 1280, 1466, 1688, 1886, 2001, 2092, 2067, 1965, 1809, 1584, 1358, 1200, 1094, 1044, 1030, 1056, 1123, 1240, 1424, 1649, 1860, 1989, 2082, 2057, 1960, 1795, 1569, 1345, 1187, 1083, 1034, 1024, 1046, 1111, 1229, 1408, 1637, 1850, 1989, 2085, 2053, 1967, 1802, 1578, 1358, 1199, 1095, 1046, 1031, 1058, 1122, 1245, 1423, 1651, 1867, 1989, 2084, 2059, 1970, 1823, 1615, 1399, 1235, 1129, 1074, 1061, 1090, 1161, 1281, 1461, 1689, 1878, 2006, 2096, 2086, 1989, 1866, 1670, 1471, 1302, 1188, 1134, 1117, 1150, 1223, 1352, 1537, 1745, 1909, 2028, 2114, 2101, 2006, 1916, 1749, 1567, 1399, 1278, 1218, 1206, 1237, 1317, 1456, 1633, 1813, 1954, 2053, 2142, 2171, 2023, 1954, 1843, 1680, 1526, 1403, 1339, 1323, 1357, 1440, 1575, 1733, 1885, 1996, 2069, 2212, 2231, 2074, 1990, 1916, 1792, 1656, 1554, 1489, 1473, 1513, 1588, 1702, 1840, 1946, 2011, 2124, 2283, 2343, 2146, 2036, 1973, 1890, 1789, 1700, 1653, 1645, 1678, 1733, 1828, 1922, 1978, 2065, 2181, 2405, 2420, 2246, 2092, 2015, 1954, 1885, 1816, 1776, 1777, 1791, 1847, 1904, 1941, 2016, 2105, 2284, 2463, ] gr: [1790, 1645, 1522, 1469, 1433, 1419, 1390, 1381, 1374, 1381, 1401, 1428, 1460, 1494, 1552, 1693, 1839, 1687, 1555, 1471, 1433, 1408, 1362, 1335, 1319, 1308, 1318, 1344, 1393, 1430, 1456, 1497, 1591, 1752, 1612, 1503, 1447, 1417, 1365, 1315, 1276, 1248, 1237, 1252, 1290, 1339, 1404, 1435, 1469, 1539, 1661, 1547, 1470, 1424, 1389, 1321, 1260, 1205, 1173, 1165, 1181, 1221, 1286, 1358, 1409, 1452, 1503, 1603, 1504, 1451, 1411, 1358, 1276, 1198, 1148, 1114, 1110, 1124, 1164, 1228, 1320, 1388, 1435, 1479, 1552, 1475, 1437, 1392, 1325, 1231, 1153, 1094, 1069, 1068, 1084, 1119, 1182, 1278, 1365, 1429, 1469, 1529, 1464, 1430, 1375, 1301, 1196, 1118, 1067, 1043, 1039, 1051, 1089, 1150, 1245, 1342, 1417, 1453, 1512, 1461, 1418, 1369, 1281, 1177, 1099, 1051, 1028, 1029, 1037, 1069, 1129, 1224, 1328, 1404, 1449, 1503, 1455, 1422, 1366, 1276, 1170, 1094, 1046, 1026, 1024, 1033, 1063, 1125, 1216, 1322, 1400, 1448, 1508, 1459, 1426, 1368, 1280, 1179, 1102, 1051, 1030, 1029, 1039, 1071, 1132, 1222, 1327, 1406, 1448, 1502, 1473, 1433, 1380, 1302, 1201, 1125, 1069, 1046, 1043, 1055, 1091, 1153, 1245, 1343, 1412, 1461, 1523, 1488, 1445, 1397, 1328, 1242, 1157, 1104, 1079, 1073, 1088, 1127, 1193, 1284, 1373, 1424, 1473, 1543, 1521, 1461, 1424, 1361, 1289, 1210, 1152, 1124, 1118, 1134, 1174, 1242, 1330, 1396, 1439, 1494, 1572, 1573, 1475, 1434, 1397, 1336, 1270, 1213, 1182, 1176, 1194, 1239, 1301, 1366, 1420, 1464, 1510, 1624, 1628, 1510, 1449, 1424, 1378, 1326, 1281, 1252, 1243, 1264, 1304, 1352, 1406, 1443, 1456, 1554, 1692, 1727, 1578, 1482, 1448, 1415, 1374, 1337, 1318, 1317, 1338, 1356, 1398, 1429, 1443, 1501, 1603, 1783, 1776, 1643, 1510, 1448, 1415, 1387, 1353, 1344, 1343, 1348, 1368, 1396, 1407, 1442, 1515, 1674, 1832, ] gb: [1805, 1650, 1529, 1468, 1430, 1412, 1378, 1371, 1363, 1371, 1393, 1430, 1465, 1501, 1567, 1713, 1864, 1700, 1564, 1476, 1434, 1404, 1359, 1323, 1306, 1294, 1306, 1338, 1388, 1432, 1462, 1509, 1605, 1780, 1627, 1520, 1457, 1423, 1370, 1311, 1267, 1238, 1226, 1245, 1286, 1344, 1414, 1448, 1489, 1563, 1697, 1568, 1487, 1436, 1398, 1325, 1257, 1200, 1163, 1156, 1175, 1221, 1291, 1372, 1427, 1476, 1528, 1636, 1527, 1474, 1431, 1371, 1285, 1201, 1144, 1109, 1104, 1121, 1165, 1239, 1335, 1411, 1461, 1509, 1588, 1498, 1463, 1413, 1343, 1242, 1159, 1094, 1066, 1064, 1083, 1124, 1195, 1299, 1391, 1455, 1499, 1561, 1492, 1454, 1401, 1319, 1209, 1124, 1068, 1042, 1039, 1053, 1096, 1164, 1268, 1370, 1446, 1486, 1547, 1486, 1446, 1392, 1302, 1190, 1108, 1053, 1028, 1029, 1040, 1078, 1146, 1245, 1355, 1437, 1600, 1546, 1600, 1449, 1389, 1294, 1184, 1101, 1047, 1024, 1024, 1035, 1073, 1136, 1240, 1348, 1431, 1483, 1537, 1485, 1450, 1390, 1298, 1188, 1109, 1051, 1030, 1026, 1038, 1077, 1143, 1243, 1354, 1436, 1482, 1547, 1494, 1454, 1400, 1317, 1211, 1125, 1067, 1041, 1038, 1053, 1094, 1165, 1264, 1368, 1440, 1489, 1557, 1513, 1464, 1414, 1340, 1245, 1156, 1097, 1071, 1063, 1081, 1126, 1197, 1298, 1394, 1446, 1502, 1573, 1541, 1477, 1438, 1370, 1292, 1204, 1142, 1111, 1106, 1121, 1169, 1245, 1338, 1411, 1462, 1519, 1599, 1590, 1485, 1447, 1403, 1334, 1263, 1199, 1164, 1158, 1179, 1230, 1299, 1373, 1433, 1477, 1528, 1649, 1643, 1520, 1454, 1426, 1375, 1315, 1266, 1235, 1224, 1247, 1291, 1345, 1408, 1449, 1468, 1572, 1711, 1738, 1579, 1482, 1443, 1406, 1359, 1318, 1294, 1294, 1312, 1338, 1385, 1427, 1441, 1507, 1614, 1799, 1786, 1653, 1516, 1452, 1414, 1383, 1348, 1331, 1328, 1336, 1362, 1391, 1408, 1448, 1529, 1684, 1858, ] b: [1807, 1633, 1496, 1427, 1395, 1372, 1357, 1340, 1339, 1335, 1356, 1382, 1410, 1454, 1541, 1690, 1860, 1657, 1503, 1411, 1364, 1342, 1312, 1286, 1274, 1262, 1270, 1287, 1326, 1355, 1387, 1447, 1550, 1726, 1556, 1438, 1374, 1340, 1305, 1267, 1236, 1213, 1199, 1211, 1246, 1280, 1324, 1355, 1397, 1475, 1620, 1473, 1407, 1350, 1317, 1270, 1223, 1173, 1144, 1135, 1151, 1185, 1237, 1292, 1326, 1368, 1422, 1544, 1430, 1375, 1331, 1293, 1238, 1166, 1120, 1096, 1091, 1104, 1133, 1188, 1261, 1310, 1351, 1388, 1487, 1383, 1362, 1316, 1269, 1194, 1128, 1076, 1054, 1057, 1070, 1101, 1146, 1229, 1294, 1329, 1368, 1459, 1368, 1347, 1301, 1250, 1162, 1099, 1057, 1039, 1035, 1041, 1076, 1119, 1199, 1271, 1321, 1349, 1440, 1360, 1338, 1299, 1234, 1145, 1086, 1042, 1029, 1026, 1034, 1059, 1104, 1176, 1260, 1307, 1344, 1439, 1347, 1342, 1293, 1226, 1139, 1077, 1040, 1024, 1025, 1030, 1051, 1099, 1170, 1249, 1301, 1335, 1432, 1346, 1342, 1295, 1227, 1145, 1083, 1040, 1025, 1024, 1031, 1059, 1096, 1170, 1247, 1297, 1338, 1436, 1362, 1344, 1299, 1245, 1161, 1095, 1055, 1034, 1031, 1041, 1069, 1115, 1185, 1252, 1299, 1347, 1453, 1378, 1353, 1311, 1261, 1191, 1117, 1077, 1058, 1045, 1063, 1092, 1141, 1210, 1274, 1302, 1358, 1461, 1405, 1364, 1329, 1281, 1229, 1159, 1106, 1084, 1080, 1093, 1124, 1180, 1244, 1285, 1317, 1380, 1496, 1467, 1379, 1343, 1304, 1260, 1208, 1154, 1127, 1117, 1138, 1172, 1225, 1266, 1297, 1340, 1397, 1556, 1532, 1428, 1354, 1325, 1290, 1248, 1211, 1181, 1178, 1197, 1227, 1261, 1293, 1321, 1342, 1450, 1624, 1634, 1502, 1394, 1347, 1316, 1283, 1251, 1239, 1241, 1254, 1266, 1297, 1312, 1328, 1396, 1509, 1739, 1685, 1572, 1426, 1351, 1313, 1285, 1257, 1254, 1249, 1259, 1266, 1287, 1292, 1336, 1429, 1593, 1816, ] #800x600_D65_70 - D65 - ct: 6504 resolution: 800x600 r: [2310, 2164, 1991, 1936, 1850, 1817, 1755, 1703, 1707, 1707, 1757, 1836, 1862, 1962, 2029, 2221, 2360, 2246, 2047, 1960, 1865, 1809, 1707, 1633, 1600, 1571, 1595, 1646, 1733, 1829, 1886, 1973, 2107, 2297, 2150, 1988, 1897, 1818, 1703, 1592, 1504, 1453, 1424, 1452, 1527, 1625, 1753, 1828, 1929, 2014, 2213, 2056, 1960, 1846, 1757, 1608, 1475, 1376, 1315, 1297, 1330, 1399, 1512, 1645, 1782, 1879, 1981, 2117, 2007, 1925, 1817, 1678, 1513, 1371, 1268, 1205, 1188, 1221, 800, 1406, 1563, 1712, 1840, 1954, 2039, 1988, 1883, 1780, 1612, 1425, 1282, 1180, 1125, 1111, 1140, 1208, 1324, 1484, 1660, 1821, 1914, 2015, 1973, 1864, 1740, 1553, 1366, 1220, 1124, 1069, 1057, 1083, 1154, 1264, 1423, 1615, 1794, 1891, 2000, 1955, 1842, 1717, 1524, 1332, 1187, 1094, 1042, 1028, 1053, 1117, 1229, 1387, 1582, 1767, 1877, 1991, 1942, 1849, 1704, 1509, 1320, 1177, 1081, 1031, 1024, 1042, 1108, 1216, 1376, 1569, 1767, 1877, 1998, 1946, 1853, 1710, 1515, 1335, 1186, 1092, 1041, 1030, 1055, 1118, 1233, 1390, 1584, 1773, 1885, 1985, 1958, 1852, 1737, 1550, 1370, 1224, 1125, 1073, 1058, 1089, 1155, 1265, 1419, 1614, 1788, 1894, 2007, 1973, 1875, 1768, 1604, 1426, 1282, 1181, 1128, 1112, 1145, 1214, 1330, 1491, 1667, 1810, 1926, 2015, 1995, 1902, 1815, 1667, 1513, 1371, 1262, 1207, 1194, 1224, 1299, 1418, 1569, 1723, 1848, 1961, 2038, 2051, 1925, 1837, 1758, 1606, 1473, 1373, 1313, 1302, 1335, 1405, 1521, 1650, 1793, 1893, 1977, 2116, 2136, 1971, 1882, 1815, 1703, 1587, 1492, 1445, 1432, 1461, 1529, 1624, 1754, 1841, 1907, 2032, 2215, 2244, 2038, 1200, 1860, 1800, 1696, 1625, 1583, 1577, 1610, 1653, 1734, 1822, 1865, 1980, 2109, 2298, 2286, 2159, 1971, 1909, 1828, 1794, 1703, 1686, 1686, 1689, 1740, 1810, 1830, 1925, 1999, 2201, 2357, ] gr: [1785, 1800, 1516, 1458, 1422, 1403, 1374, 1363, 1359, 1363, 1385, 1417, 1447, 1486, 1547, 1693, 1834, 1675, 1547, 1462, 1418, 1393, 1346, 1319, 1304, 1289, 1302, 1330, 1382, 1417, 1451, 1492, 1592, 1743, 1607, 1498, 1437, 1404, 1353, 1301, 1264, 1238, 1226, 1240, 1281, 1325, 1398, 1426, 1468, 1541, 1668, 1547, 1466, 1413, 1382, 1311, 1251, 1202, 1168, 1161, 1176, 1218, 1275, 1351, 1408, 1449, 1498, 1606, 1499, 1447, 1404, 1349, 1269, 1199, 1147, 1113, 1106, 1123, 1163, 1225, 1313, 1384, 1435, 1485, 1551, 1467, 1437, 1388, 1318, 1228, 1154, 1099, 1070, 1066, 1081, 1120, 1185, 1278, 1362, 1430, 1468, 1530, 1460, 1422, 1370, 1293, 1199, 1121, 1068, 1044, 1035, 1052, 1090, 1155, 1244, 1344, 1420, 1457, 1507, 1460, 1416, 1363, 1278, 1179, 1105, 1054, 1028, 1028, 1036, 1073, 1134, 1230, 1323, 1413, 1452, 1509, 1454, 1421, 1361, 1272, 1174, 1097, 1046, 1025, 1024, 1033, 1068, 1130, 1222, 1320, 1408, 1450, 1503, 1456, 1423, 1366, 1275, 1184, 1105, 1053, 1030, 1027, 1040, 1073, 1136, 1228, 1324, 1411, 1457, 1508, 1472, 1429, 1376, 1294, 1205, 1126, 1072, 1046, 1044, 1058, 1095, 1159, 1246, 1345, 1419, 1464, 1530, 1481, 1443, 1396, 1322, 1239, 1161, 1104, 1078, 1070, 1088, 1128, 1196, 1283, 1371, 1428, 1600, 1551, 1521, 1457, 1421, 1355, 1282, 1209, 1152, 1125, 1116, 1134, 1176, 1243, 1324, 1398, 1446, 1497, 1581, 1571, 1471, 1430, 1392, 1328, 1262, 1210, 1179, 1172, 1191, 1236, 1295, 1363, 1424, 1465, 1511, 1636, 1636, 1509, 1448, 1415, 1368, 1316, 1271, 1243, 1234, 1258, 800, 1340, 1407, 1439, 1459, 1561, 1699, 1720, 1577, 1479, 1444, 1408, 1362, 1325, 1304, 1305, 1325, 1348, 1394, 1426, 1439, 1503, 1609, 1788, 1770, 1642, 1502, 1444, 1400, 1384, 1338, 1334, 1329, 1339, 1357, 1389, 1396, 1443, 1514, 1670, 1822, ] gb: [1791, 1649, 1516, 1459, 1422, 1404, 1373, 1360, 1353, 1358, 1386, 1424, 1451, 1492, 1563, 1710, 1854, 1687, 1553, 1463, 1420, 1393, 1347, 1313, 800, 1284, 1295, 1324, 1376, 1417, 1455, 1493, 1609, 1768, 1617, 1511, 1444, 1409, 1359, 1299, 1260, 1234, 1219, 1237, 1276, 1328, 1403, 1431, 1479, 1557, 1696, 1555, 1477, 1422, 1388, 1311, 1250, 1200, 1165, 1158, 1174, 1217, 1281, 1358, 1416, 1463, 1520, 1629, 1520, 1458, 1415, 1355, 1272, 1203, 1144, 1111, 1105, 1122, 1165, 1231, 1322, 1394, 1447, 1497, 1577, 1481, 1452, 1399, 1330, 1234, 1160, 1101, 1070, 1065, 1082, 1124, 1192, 1288, 1373, 1443, 1485, 1556, 1476, 1437, 1384, 1304, 1207, 1124, 1070, 1045, 1039, 1055, 1092, 1163, 1256, 1357, 1429, 1475, 1539, 1470, 1430, 1373, 1288, 1186, 1108, 1056, 1029, 1027, 1040, 1078, 1142, 1240, 1336, 1424, 1469, 1529, 1465, 1433, 1370, 1281, 1179, 1102, 1049, 1025, 1024, 1035, 1070, 1134, 1230, 1332, 1420, 1464, 1536, 1469, 1434, 1372, 1283, 1186, 1108, 1055, 1029, 1027, 1037, 1076, 1145, 1236, 1337, 1421, 1468, 1535, 1478, 1438, 1382, 1303, 1210, 1128, 1070, 1044, 1040, 1056, 1096, 1164, 1255, 1355, 1427, 1478, 1551, 1489, 1454, 1401, 1329, 1239, 1160, 1102, 1075, 1067, 1084, 1128, 1196, 1288, 1380, 1435, 1492, 1573, 1528, 1464, 1426, 1358, 1283, 1206, 1146, 1116, 1110, 1129, 1172, 1242, 1327, 1402, 1451, 1508, 1597, 1574, 1476, 1433, 1395, 1326, 1254, 1202, 1170, 1165, 1182, 1230, 1292, 1361, 1425, 1471, 1526, 1657, 1638, 1512, 1449, 1418, 1366, 1308, 1259, 1230, 1223, 1246, 1285, 1334, 1402, 1439, 1465, 1574, 1712, 1723, 1575, 1474, 1440, 1400, 1353, 1312, 1289, 1287, 1305, 1332, 1381, 1417, 1440, 1504, 1616, 1806, 1780, 1652, 1506, 1448, 1403, 1380, 1340, 1327, 1325, 1335, 1350, 1390, 1402, 1448, 1532, 1693, 1848, ] b: [1834, 1686, 1532, 1462, 1420, 1404, 1369, 1360, 1354, 1357, 1375, 1415, 1442, 1496, 1568, 1741, 1872, 1706, 1543, 1441, 1391, 1366, 1321, 1295, 1281, 1270, 1276, 1305, 1345, 1389, 1418, 1477, 1588, 1752, 1594, 1473, 1400, 1363, 1317, 1269, 1238, 1216, 1206, 1214, 1250, 800, 1353, 1389, 1434, 1503, 1664, 1514, 1437, 1372, 1334, 1278, 1228, 1180, 1151, 1143, 1159, 1196, 1246, 1313, 1359, 1405, 1453, 1587, 1465, 1401, 1351, 1308, 1236, 1177, 1127, 1101, 1093, 1109, 1141, 1200, 1274, 1335, 1384, 1427, 1522, 1423, 1386, 1335, 1275, 1199, 1133, 1087, 1063, 1059, 1069, 1104, 1159, 1240, 1316, 1369, 1402, 1493, 1407, 1375, 1318, 1256, 1172, 1107, 1060, 1041, 1035, 1048, 1077, 1135, 1211, 1291, 1354, 1391, 1478, 1390, 1365, 1313, 1239, 1153, 1089, 1047, 1029, 1028, 1033, 1065, 1116, 1193, 1278, 1342, 1382, 1475, 1384, 1364, 1308, 1231, 1146, 1082, 1040, 1025, 1024, 1030, 1057, 1110, 1183, 1269, 1337, 1379, 1475, 1384, 1372, 1309, 1233, 1152, 1086, 1046, 1024, 1024, 1032, 1061, 1113, 1187, 1268, 1337, 1379, 1479, 1395, 1370, 1317, 1249, 1171, 1102, 1058, 1035, 1029, 1047, 1073, 1130, 1200, 1278, 1341, 1388, 1491, 1420, 1383, 1336, 1265, 1195, 1129, 1078, 1059, 1053, 1065, 1102, 1155, 1227, 1301, 1348, 1405, 1505, 1452, 1396, 1356, 1295, 1234, 1166, 1116, 1092, 1084, 1103, 1139, 1195, 1262, 1321, 1364, 1420, 1547, 1517, 1414, 1375, 1324, 1269, 1214, 1165, 1138, 1132, 1148, 1188, 1239, 1291, 1336, 1387, 1446, 1604, 1587, 1471, 1383, 1354, 1309, 1257, 1216, 1192, 1187, 1209, 1241, 1277, 1330, 1366, 1384, 1498, 1682, 1689, 1543, 1427, 1381, 1344, 1303, 1265, 1250, 1251, 1266, 1284, 1326, 1353, 1369, 1447, 1566, 1790, 1754, 1632, 1469, 1391, 1353, 1317, 1292, 1282, 1278, 1294, 1306, 1321, 1347, 1382, 1477, 1650, 1854, ] #800x600_F2_CWF_70 - F2_CWF - ct: 4230 resolution: 800x600 r: [2065, 1886, 1745, 1661, 1619, 1574, 1532, 1504, 1498, 1499, 1533, 1586, 1628, 1689, 1770, 1942, 2140, 1978, 1796, 1688, 1627, 1565, 1501, 1446, 1424, 1407, 1419, 1460, 1525, 1583, 1642, 1712, 1829, 2032, 1880, 1732, 1643, 1579, 1499, 1418, 1356, 1319, 1300, 1320, 1372, 1443, 1536, 1598, 1661, 1763, 1923, 1812, 1689, 1608, 1535, 1429, 1335, 1267, 1223, 1210, 1234, 1284, 1362, 1461, 1547, 1634, 1715, 1848, 1755, 1664, 1579, 1600, 1362, 1262, 1188, 1145, 1132, 1156, 1211, 1289, 1403, 1504, 1604, 1688, 1791, 1726, 1635, 1548, 1433, 1298, 1199, 1126, 1084, 1080, 1101, 1147, 1226, 1340, 1468, 1586, 1659, 1752, 1707, 1624, 1522, 1393, 1256, 1155, 1085, 1054, 1043, 1059, 1111, 1187, 1302, 1435, 1566, 1645, 1732, 1695, 1605, 1508, 1367, 1230, 1132, 1066, 1034, 1028, 1042, 1084, 1160, 1275, 1418, 1549, 1634, 1722, 1681, 1604, 1498, 1360, 1222, 1121, 1058, 1027, 1024, 1034, 1075, 1151, 1264, 1407, 1543, 1633, 1723, 1691, 1609, 1498, 1361, 1231, 1130, 1064, 1037, 1027, 1043, 1083, 1162, 1275, 1413, 1545, 1638, 1714, 1692, 1612, 1515, 1385, 1258, 1153, 1087, 1051, 1045, 1064, 1109, 1185, 1295, 1437, 1560, 1645, 1741, 1712, 1627, 1538, 1417, 1298, 1199, 1124, 1087, 1075, 1101, 1146, 1231, 1342, 1472, 1574, 1665, 1754, 1743, 1637, 1572, 1466, 1357, 1253, 1181, 1142, 1131, 1154, 1207, 1295, 1401, 1515, 1601, 1687, 1789, 1807, 1661, 1597, 1525, 1425, 1328, 1257, 1215, 1208, 1230, 1282, 1363, 1459, 1555, 1800, 1714, 1857, 1871, 1711, 1631, 1573, 1491, 1407, 1343, 1307, 1298, 1323, 1368, 1440, 1528, 1601, 1649, 1767, 1932, 1982, 1788, 1675, 1617, 1559, 1489, 1433, 1406, 1405, 1425, 1457, 1516, 1581, 1623, 1713, 1836, 2044, 2041, 1885, 1730, 1646, 1589, 1547, 1498, 1476, 1474, 1488, 1518, 1569, 1594, 1656, 1757, 1921, 2111, ] gr: [1765, 1633, 1502, 1441, 1411, 1389, 1365, 1356, 1350, 1358, 1375, 1408, 1434, 1476, 1534, 1678, 1820, 1671, 1535, 1450, 1410, 1381, 1341, 1311, 1297, 1288, 1295, 1323, 1368, 1407, 1437, 1600, 1580, 1736, 1595, 1488, 1424, 1388, 1342, 1293, 1255, 1230, 1219, 1235, 1270, 1319, 1384, 1413, 1452, 1524, 1657, 1534, 1452, 1399, 1367, 1300, 1238, 1194, 1162, 1155, 1171, 1209, 1267, 1336, 1393, 1435, 1486, 1591, 1491, 1429, 1389, 1335, 1255, 1189, 1139, 1108, 1104, 1118, 1156, 1218, 1302, 1369, 1422, 1470, 1540, 1456, 1416, 1370, 1305, 1216, 1146, 1093, 1068, 1064, 1078, 1116, 1176, 1268, 1345, 1415, 1451, 1510, 1445, 1409, 1352, 1280, 1185, 1113, 1065, 1041, 1039, 1051, 1085, 1147, 1235, 1330, 1402, 1440, 1499, 1444, 1399, 1349, 1261, 1171, 1096, 1050, 1029, 1030, 1037, 1070, 1127, 1217, 1314, 1395, 1437, 1490, 1437, 1401, 1346, 1256, 1161, 1091, 1043, 1026, 1024, 1034, 1064, 1123, 1210, 1308, 1390, 1436, 1490, 1441, 1409, 1346, 1262, 1170, 1097, 1049, 1030, 1029, 1040, 1069, 1129, 1216, 1315, 1393, 1439, 1490, 1458, 1413, 1357, 1280, 1194, 1118, 1065, 1044, 1043, 1055, 1088, 1151, 1235, 1331, 1404, 1448, 1513, 1475, 1426, 1378, 1304, 1225, 1149, 1098, 1074, 1067, 1083, 1122, 1187, 1268, 1356, 1411, 1465, 1530, 1505, 1439, 1402, 1339, 1268, 1197, 1144, 1119, 1110, 1129, 1167, 1232, 1313, 1383, 1428, 1481, 1563, 1564, 1455, 1415, 1373, 1313, 1249, 1203, 1173, 1167, 1184, 1227, 1284, 1349, 1404, 1449, 1499, 1617, 1620, 1493, 1428, 1402, 1354, 1303, 1261, 1236, 1228, 1250, 1285, 1333, 1389, 1428, 1444, 1544, 1684, 1710, 1568, 1462, 1428, 1394, 1354, 1315, 800, 1298, 1317, 1337, 1381, 1411, 1428, 1491, 1594, 1774, 1755, 1632, 1496, 1430, 1395, 1370, 1330, 1328, 1322, 1331, 1348, 1378, 1392, 1426, 1503, 1657, 1810, ] gb: [1773, 1627, 1500, 1438, 1403, 1382, 1352, 1341, 1336, 1344, 1365, 1404, 1435, 1476, 1545, 1692, 1839, 1672, 1540, 1450, 1406, 1376, 1332, 1298, 1282, 1274, 1284, 1312, 1363, 1405, 1440, 1483, 1594, 1751, 1608, 1494, 1426, 1391, 1341, 1284, 1247, 1219, 1207, 1224, 1263, 1318, 1388, 1423, 1460, 1542, 1678, 1545, 1463, 1407, 1368, 1298, 1235, 1188, 1153, 1148, 1163, 1207, 1268, 1345, 1402, 1450, 1506, 1613, 1499, 1442, 1399, 1342, 1259, 1187, 1135, 1103, 1096, 1116, 1157, 1222, 1310, 1382, 1436, 1489, 1564, 1475, 1434, 1382, 1315, 1221, 1145, 1093, 1065, 1061, 1076, 1115, 1182, 1278, 1364, 1431, 1474, 1541, 1461, 1425, 1368, 1290, 1193, 1118, 1064, 1041, 1037, 1050, 1090, 1154, 1246, 1346, 1420, 1466, 1525, 1463, 1416, 1363, 1273, 1178, 1097, 1051, 1030, 1029, 1039, 1073, 1136, 1232, 1332, 1414, 1460, 1519, 1452, 1420, 1357, 1268, 1172, 1094, 1045, 1026, 1024, 1034, 1067, 1131, 1223, 1324, 1409, 1458, 1521, 1460, 1420, 1359, 1271, 1175, 1099, 1048, 1029, 1027, 1038, 1072, 1136, 1227, 1330, 1412, 1458, 1524, 1467, 1424, 1368, 1289, 1197, 1117, 1063, 1040, 1038, 1053, 1089, 1156, 1246, 1345, 1415, 1470, 1538, 1486, 1437, 1384, 1309, 1224, 1146, 1091, 1067, 1063, 1077, 1118, 1187, 1278, 1367, 1425, 1600, 1553, 1519, 1445, 1408, 1342, 1266, 1192, 1136, 1106, 1102, 1119, 1161, 1230, 1316, 1389, 1438, 1495, 1583, 1567, 1460, 1420, 1374, 1310, 1241, 1189, 1158, 1152, 1173, 1214, 1278, 1348, 1410, 1456, 1511, 1634, 1624, 1498, 1427, 1400, 1346, 1294, 1244, 1219, 1210, 1232, 1271, 1321, 1384, 1430, 1448, 1557, 1697, 1719, 1560, 1458, 1421, 1381, 1338, 1298, 1274, 1275, 1292, 1318, 1365, 1404, 1424, 1489, 1601, 1785, 1751, 1637, 1497, 1429, 1389, 1361, 1323, 1311, 1309, 1318, 1339, 1374, 1388, 1429, 1513, 1674, 1829, ] b: [1800, 1643, 1486, 1416, 1376, 1354, 1329, 1318, 1309, 1310, 1331, 1359, 1390, 1444, 1533, 1708, 1846, 1664, 1510, 1400, 1351, 1324, 1286, 1260, 1246, 1235, 1244, 1266, 1306, 1341, 1373, 1441, 1556, 1734, 1557, 1441, 1360, 1322, 1282, 1242, 1211, 1188, 1180, 1186, 1220, 1258, 1309, 1346, 1391, 1475, 1626, 1484, 1400, 1331, 1300, 1247, 1202, 1163, 1135, 1127, 1143, 1170, 1215, 1274, 1315, 1365, 1417, 1555, 1422, 1368, 1316, 1270, 1209, 1158, 1117, 1088, 1084, 1094, 1130, 1174, 1240, 800, 1343, 1389, 1497, 1383, 1351, 1299, 1247, 1177, 1122, 1081, 1057, 1051, 1067, 1094, 1142, 1209, 1274, 1329, 1362, 1461, 1367, 1333, 1284, 1224, 1153, 1098, 1056, 1040, 1035, 1042, 1070, 1118, 1186, 1255, 1314, 1349, 1441, 1355, 1327, 1275, 1209, 1137, 1082, 1044, 1029, 1026, 1034, 1056, 1100, 1166, 1241, 1302, 1341, 1439, 1343, 1325, 1270, 1201, 1130, 1075, 1037, 1024, 1026, 1030, 1050, 1094, 1160, 1231, 1295, 1334, 1434, 1347, 1330, 1274, 1203, 1135, 1079, 1040, 1026, 1024, 1031, 1054, 1097, 1161, 1231, 1292, 1338, 1433, 1358, 1330, 1280, 1219, 1152, 1093, 1051, 1032, 1030, 1043, 1067, 1115, 1173, 1237, 1298, 1348, 1447, 1382, 1342, 1298, 1236, 1174, 1115, 1071, 1051, 1044, 1060, 1088, 1138, 1197, 1259, 1301, 1365, 1464, 1410, 1360, 1314, 1259, 1205, 1149, 1104, 1079, 1075, 1090, 1123, 1171, 1227, 1277, 1315, 1387, 1508, 1476, 1376, 1330, 1287, 1238, 1188, 1144, 1122, 1115, 1132, 1165, 1206, 1249, 1294, 1344, 1402, 1567, 1548, 1431, 1348, 1314, 1271, 1224, 1190, 1168, 1163, 1182, 1210, 1246, 1286, 1318, 1344, 1462, 1650, 1658, 1510, 1386, 1342, 1305, 1268, 1232, 1220, 1221, 1236, 1250, 1283, 1311, 1328, 1406, 1530, 1755, 1698, 1587, 1431, 1350, 1304, 1274, 1244, 1238, 1239, 1245, 1262, 1283, 1293, 1339, 1439, 1608, 1825, ] #800x600_D50_70 - D50 - ct: 5003 resolution: 800x600 r: [2543, 2578, 2509, 2438, 2318, 2233, 2133, 2085, 2088, 2130, 2245, 2390, 2533, 2674, 2811, 2910, 2790, 2536, 2518, 2407, 2309, 2153, 2048, 1910, 1861, 1865, 1921, 2013, 2160, 2340, 2523, 2664, 2836, 2882, 2501, 2408, 2276, 2127, 1951, 1804, 1701, 1655, 1635, 1674, 1771, 1939, 2141, 2356, 2565, 2701, 2839, 2403, 2314, 2154, 1963, 1779, 1618, 1511, 1447, 1433, 1470, 1554, 1714, 1920, 2196, 2430, 2589, 2694, 2352, 2232, 2049, 1828, 1635, 1472, 1357, 1295, 1274, 1317, 1399, 1543, 1785, 2021, 2302, 2494, 2688, 2254, 2143, 1936, 1720, 1509, 1345, 1237, 1168, 1158, 1188, 1271, 1420, 1614, 1894, 2190, 2443, 2592, 2210, 2085, 1870, 1630, 1432, 1264, 1161, 1090, 1079, 1102, 1184, 1329, 1525, 1797, 2112, 2377, 2587, 2224, 2063, 1822, 1598, 1381, 1217, 1121, 1045, 1031, 1063, 1129, 1270, 1481, 1749, 2059, 2344, 2559, 2234, 2083, 1812, 1592, 1381, 1215, 1102, 1046, 1024, 1053, 1122, 1257, 1466, 1734, 2045, 2338, 2530, 2224, 2063, 1856, 1610, 1407, 1237, 1126, 1063, 1044, 1072, 1145, 1288, 1485, 1764, 2059, 2344, 2539, 2273, 2135, 1906, 1675, 1470, 1299, 1187, 1112, 1094, 1120, 1208, 1348, 1546, 1828, 2124, 2377, 2566, 2321, 2197, 1986, 1779, 1563, 1402, 1271, 1209, 1192, 1221, 1313, 1461, 1664, 1929, 2203, 2460, 2659, 2371, 2292, 2119, 1906, 1700, 1538, 1407, 1335, 1321, 1366, 1447, 1593, 1800, 2062, 2331, 2570, 2737, 2485, 2382, 2262, 2078, 1876, 1721, 1587, 1525, 1504, 1545, 1633, 1785, 1985, 2246, 2464, 2631, 2799, 2621, 2465, 2387, 2243, 2063, 1912, 1801, 1734, 1705, 1755, 1848, 2005, 2213, 2417, 2584, 2773, 2900, 2757, 2632, 2519, 2419, 2283, 2160, 2044, 1976, 1979, 2024, 2107, 2272, 2430, 2578, 2731, 2921, 2984, 2724, 2762, 2663, 2570, 2413, 2331, 2245, 2227, 2242, 2278, 2369, 2486, 2647, 2763, 2864, 3041, 2860, ] gr: [2123, 2151, 2065, 2008, 1917, 1836, 1766, 1738, 1740, 1752, 1817, 1882, 1943, 2023, 2110, 2206, 2123, 2143, 2093, 2006, 1915, 1810, 1724, 1632, 1597, 1588, 1608, 1665, 1733, 1827, 1928, 2014, 2122, 2189, 2104, 2052, 1936, 1805, 1686, 1575, 1502, 1464, 1446, 1461, 1512, 1597, 1705, 1827, 1949, 2027, 2124, 2066, 1962, 1856, 1704, 1563, 1450, 1376, 1323, 1310, 1323, 1371, 1466, 1570, 1714, 1868, 1954, 2066, 1997, 1917, 1771, 1622, 1466, 1351, 1258, 1217, 1199, 1211, 1265, 1351, 1469, 1622, 1781, 1891, 1989, 1958, 1863, 1700, 1537, 1382, 1265, 1182, 1133, 1118, 1128, 1178, 1254, 1385, 1537, 1695, 1838, 1943, 1935, 1829, 1642, 1480, 1319, 1202, 1122, 1078, 1061, 1073, 1114, 1196, 1316, 1477, 1655, 1806, 1913, 1953, 1794, 1639, 1442, 1288, 1171, 1089, 1047, 1031, 1044, 1083, 1153, 1279, 1436, 1623, 1783, 1924, 1940, 1807, 1621, 1442, 1283, 1166, 1083, 1041, 1024, 1034, 1073, 1147, 1270, 1436, 1608, 1768, 1897, 1968, 1828, 1639, 1470, 1297, 1182, 1096, 1055, 1038, 1050, 1090, 1168, 1290, 1442, 1627, 1783, 1917, 1942, 1841, 1682, 1510, 1349, 1222, 1132, 1088, 1067, 1081, 1127, 1206, 1326, 1486, 1651, 1811, 1942, 2005, 1901, 1743, 1578, 1422, 1303, 1209, 1152, 1135, 1148, 1191, 1280, 1399, 1548, 1719, 1845, 1974, 2057, 1952, 1830, 1685, 1512, 1393, 1305, 1245, 1221, 1233, 1289, 1372, 1489, 1634, 1776, 1904, 2031, 2113, 2007, 1918, 1777, 1640, 1511, 1423, 1360, 1344, 1360, 1400, 1494, 1608, 1742, 1862, 1976, 2123, 2199, 2104, 2006, 1879, 1756, 1649, 1553, 1502, 1480, 1495, 1546, 1633, 1732, 1839, 1956, 2052, 2210, 2300, 2191, 2104, 2010, 1907, 1802, 1717, 1669, 1655, 1673, 1717, 1792, 1878, 1955, 2054, 2222, 2274, 2310, 2336, 2195, 2103, 2012, 1925, 1861, 1823, 1814, 1844, 1889, 1931, 2004, 2079, 2166, 2287, 2213, ] gb: [2166, 2183, 2106, 2056, 1961, 1889, 1800, 1772, 1760, 1791, 1821, 1907, 1948, 2040, 2115, 2205, 2191, 2197, 2125, 2062, 1973, 1862, 1758, 1680, 1620, 1612, 1636, 1693, 1758, 1851, 1953, 2031, 2125, 2174, 2125, 2067, 1974, 1852, 1719, 1621, 1532, 1477, 1465, 1480, 1535, 1605, 1724, 1852, 1967, 2050, 2156, 2107, 2015, 1893, 1738, 1608, 1485, 1406, 1337, 1319, 1337, 1382, 1476, 1589, 1733, 1869, 1985, 2070, 2037, 1948, 1806, 1641, 1501, 1377, 1287, 1227, 1215, 1227, 1274, 1364, 1485, 1645, 1806, 1928, 2028, 1981, 1887, 1728, 1564, 1409, 1285, 1199, 1145, 1125, 1135, 1183, 1270, 1395, 1560, 1733, 1868, 1974, 1965, 1841, 1670, 1509, 1349, 1221, 1138, 1084, 1065, 1073, 1121, 1208, 1332, 1496, 1670, 1835, 1958, 1948, 1818, 1642, 1467, 1315, 1185, 1099, 1052, 1035, 1042, 1084, 1163, 1292, 1458, 1638, 1812, 1948, 1942, 1809, 1635, 1467, 1296, 1178, 1094, 1039, 1024, 1038, 1073, 1157, 1285, 1451, 1640, 1803, 1935, 1948, 1812, 1646, 1483, 1317, 1196, 1107, 1057, 1043, 1053, 1090, 1183, 1296, 1464, 1650, 1818, 1941, 1965, 1841, 1687, 1519, 1362, 1243, 1145, 1094, 1075, 1088, 1137, 1225, 1339, 1512, 1692, 1835, 1988, 1981, 1893, 1738, 1586, 1435, 1314, 1218, 1160, 1143, 1158, 1212, 1294, 1418, 1578, 1742, 1887, 2005, 2037, 1948, 1838, 1674, 1527, 1398, 1309, 1251, 1236, 1253, 1305, 1385, 1514, 1674, 1816, 1934, 2062, 2098, 2015, 1899, 1791, 1656, 1530, 1430, 1379, 1360, 1379, 1428, 1517, 1639, 1781, 1893, 2015, 2117, 2199, 2075, 1988, 1910, 1776, 1664, 1583, 1518, 1502, 1525, 1576, 1668, 1776, 1898, 1981, 2084, 2221, 2269, 2204, 2103, 2021, 1921, 1827, 1751, 1676, 1671, 1693, 1755, 1843, 1927, 2007, 2095, 2224, 2294, 2285, 2285, 2190, 2112, 2009, 1956, 1909, 1853, 1845, 1864, 1921, 1995, 2058, 2137, 2199, 2308, 2231, ] b: [2007, 2014, 1951, 1922, 1856, 1794, 1746, 1720, 1718, 1747, 1818, 1865, 1956, 2026, 2146, 2219, 2251, 2020, 1954, 1914, 1840, 1745, 1673, 1626, 1592, 1586, 1613, 1674, 1732, 1851, 1938, 2030, 2131, 2207, 1927, 1878, 1807, 1732, 1628, 1548, 1486, 1461, 1440, 1465, 1519, 1601, 1715, 1846, 1943, 2018, 2141, 1863, 1826, 1730, 1633, 1515, 1436, 1369, 1326, 1318, 1337, 1399, 1479, 1598, 1729, 1865, 1962, 2051, 1840, 1751, 1653, 1541, 1426, 1333, 1265, 1217, 1214, 1223, 1281, 1373, 1493, 1641, 1794, 1908, 2015, 1803, 1695, 1587, 1462, 1347, 1245, 1173, 1139, 1122, 1139, 1197, 1288, 1404, 1555, 1712, 1845, 1987, 1781, 1659, 1544, 1402, 1284, 1186, 1117, 1075, 1065, 1088, 1131, 1214, 1342, 1504, 1667, 1808, 1945, 1753, 1639, 1509, 1376, 1253, 1152, 1083, 1045, 1040, 1051, 1094, 1177, 1307, 1464, 1630, 1782, 1939, 1752, 1626, 1510, 1370, 1248, 1141, 1076, 1037, 1024, 1043, 1087, 1163, 1299, 1452, 1631, 1789, 1927, 1761, 1639, 1509, 1384, 1259, 1157, 1088, 1049, 1036, 1061, 1103, 1190, 1321, 1469, 1648, 1806, 1939, 1772, 1673, 1550, 1423, 1304, 1194, 1124, 1088, 1073, 1094, 1143, 1231, 1353, 1508, 1673, 1816, 1955, 1794, 1709, 1599, 1495, 1373, 1269, 1191, 1149, 1129, 1159, 1210, 1298, 1429, 1571, 1726, 1854, 2010, 1840, 1759, 1679, 1567, 1448, 1358, 1284, 1234, 1228, 1249, 1306, 1392, 1507, 1647, 1794, 1917, 2076, 1929, 1835, 1760, 1670, 1565, 1470, 1388, 1351, 1335, 1362, 1423, 1511, 1609, 1743, 1865, 1983, 2145, 2028, 1898, 1841, 1761, 1670, 1590, 1519, 1483, 1475, 1505, 1563, 1640, 1749, 1862, 1943, 2078, 2218, 2109, 2014, 1944, 1883, 1812, 1745, 1674, 1630, 1635, 1665, 1717, 1801, 1884, 1967, 2064, 2188, 2295, 2157, 2126, 2020, 1952, 1891, 1833, 1781, 1761, 1773, 1803, 1857, 1943, 2005, 2026, 2159, 2268, 2251, ] ...
0
repos/libcamera/src/ipa/rkisp1
repos/libcamera/src/ipa/rkisp1/data/ov5695.yaml
# SPDX-License-Identifier: CC0-1.0 %YAML 1.1 --- version: 1 algorithms: - Agc: - Awb: - LensShadingCorrection: x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ] sets: #2592x1944_A_70 - A - ct: 2856 resolution: 2592x1944 r: [2312, 2874, 2965, 2789, 2603, 2424, 2288, 2176, 2151, 2176, 2240, 2345, 2520, 2736, 2856, 2825, 2272, 2675, 3026, 2925, 2693, 2443, 2247, 2074, 1992, 1947, 1972, 2066, 2211, 2386, 2618, 2847, 2953, 2698, 2927, 3008, 2846, 2541, 2272, 2037, 1867, 1782, 1740, 1762, 1855, 1981, 2198, 2454, 2711, 2963, 2927, 2974, 2920, 2664, 2337, 2061, 1822, 1648, 1550, 1503, 1550, 1648, 1794, 1982, 2257, 2565, 2805, 2880, 2933, 2799, 2472, 2161, 1880, 1631, 1457, 1361, 1328, 1364, 1448, 1602, 1817, 2087, 2390, 2698, 2911, 2947, 2734, 2404, 2061, 1759, 1525, 1340, 1244, 1209, 1240, 1343, 1473, 1701, 1975, 2278, 2641, 2823, 2948, 2680, 2342, 1979, 1667, 1425, 1259, 1159, 1125, 1159, 1238, 1407, 1633, 1914, 2235, 2592, 2866, 2936, 2661, 2276, 1908, 1624, 1368, 1190, 1097, 1058, 1086, 1178, 1341, 1556, 1848, 2175, 2509, 2763, 2873, 2603, 2230, 1868, 1578, 1320, 1157, 1058, 1024, 1053, 1142, 1302, 1521, 1789, 2125, 2471, 2760, 2896, 2661, 2276, 1914, 1591, 1349, 1176, 1083, 1044, 1080, 1166, 1327, 1544, 1814, 2141, 2509, 2763, 2969, 2710, 2342, 1985, 1676, 1431, 1250, 1146, 1105, 1140, 1234, 1392, 1616, 1895, 2235, 2578, 2847, 3060, 2800, 2426, 2076, 1764, 1518, 1335, 1227, 1197, 1227, 1314, 1486, 1696, 1989, 2298, 2641, 2863, 2978, 2853, 2496, 2169, 1880, 1631, 1457, 1345, 1304, 1334, 1429, 1586, 1811, 2064, 2378, 2698, 2867, 3024, 2960, 2664, 2327, 2054, 1811, 1626, 1517, 1490, 1514, 1597, 1763, 1962, 2229, 2538, 2768, 2926, 3032, 3077, 2864, 2554, 2272, 2052, 1861, 1747, 1716, 1742, 1816, 1995, 2190, 2454, 2727, 2920, 2927, 2849, 3155, 3008, 2772, 2490, 2276, 2121, 2006, 1954, 1978, 2066, 2202, 2408, 2648, 2847, 2977, 2797, 2440, 3116, 3132, 2900, 2738, 2509, 2329, 2239, 2194, 2230, 2298, 2436, 2617, 2825, 2965, 2899, 2312, ] gr: [1557, 1922, 2004, 1947, 1841, 1757, 1689, 1651, 1631, 1647, 1680, 1737, 1835, 1911, 1995, 1941, 1613, 1820, 2038, 1996, 1900, 1779, 1692, 1617, 1565, 1549, 1554, 1594, 1670, 1753, 1875, 1957, 2029, 1848, 2009, 2064, 1956, 1834, 1715, 1601, 1518, 1474, 1446, 1459, 1505, 1582, 1666, 1796, 1935, 2029, 2009, 2013, 2006, 1874, 1731, 1602, 1493, 1409, 1346, 1332, 1348, 1395, 1474, 1576, 1689, 1843, 1944, 2003, 1982, 1931, 1783, 1637, 1496, 1386, 1297, 1238, 1219, 1239, 1284, 1370, 1474, 1601, 1747, 1897, 2000, 1998, 1920, 1755, 1587, 1455, 1325, 1228, 1171, 1159, 1176, 1223, 1311, 1418, 1565, 1707, 1855, 1990, 2007, 1897, 1733, 1574, 1423, 1296, 1183, 1121, 1101, 1132, 1182, 1277, 1396, 1539, 1696, 1866, 1990, 2000, 1870, 1692, 1529, 1377, 1239, 1141, 1077, 1057, 1079, 1141, 1230, 1350, 1493, 1640, 1810, 1961, 1957, 1849, 1669, 1496, 1356, 1212, 1112, 1053, 1024, 1049, 1106, 1203, 1322, 1465, 1615, 1780, 1919, 1969, 1870, 1675, 1515, 1365, 1232, 1128, 1063, 1042, 1068, 1123, 1220, 1345, 1483, 1628, 1788, 1945, 2007, 1917, 1728, 1574, 1420, 1285, 1173, 1115, 1088, 1109, 1170, 1268, 1388, 1532, 1678, 1835, 1999, 2033, 1927, 1760, 1613, 1461, 1334, 1234, 1175, 1145, 1168, 1225, 1311, 1423, 1557, 1726, 1874, 2015, 2000, 1960, 1810, 1641, 1515, 1391, 1292, 1228, 1212, 1232, 1275, 1358, 1462, 1601, 1737, 1883, 1974, 2032, 2006, 1874, 1712, 1594, 1477, 1395, 1329, 1316, 1327, 1375, 1453, 1547, 1671, 1808, 1937, 1994, 2039, 2064, 1971, 1829, 1701, 1608, 1521, 1465, 1441, 1462, 1498, 1571, 1666, 1785, 1921, 2003, 2039, 1886, 2087, 2062, 1926, 1817, 1706, 1637, 1572, 1560, 1572, 1613, 1688, 1774, 1868, 1973, 2029, 1886, 1692, 2020, 2067, 2008, 1897, 1822, 1741, 1704, 1683, 1695, 1727, 1783, 1872, 1977, 2022, 1989, 1639, ] gb: [1553, 1926, 1992, 1930, 1852, 1746, 1675, 1630, 1611, 1622, 1671, 1726, 1804, 1915, 1992, 1955, 1584, 1852, 2043, 2001, 1879, 1773, 1674, 1602, 1548, 1532, 1541, 1583, 1661, 1752, 1867, 1986, 2034, 1881, 1993, 2060, 1976, 1811, 1697, 1590, 1505, 1459, 1439, 1453, 1496, 1579, 1674, 1795, 1940, 2051, 2034, 2018, 2003, 1866, 1735, 1594, 1478, 1396, 1339, 1326, 1339, 1388, 1463, 1579, 1707, 1842, 1980, 2037, 2014, 1950, 1793, 1641, 1509, 1384, 1291, 1229, 1209, 1231, 1283, 1369, 1481, 1625, 1751, 1901, 2023, 2029, 1925, 1750, 1602, 1458, 1330, 1228, 1162, 1144, 1166, 1218, 1308, 1433, 1572, 1730, 1872, 2029, 2020, 1934, 1752, 1578, 1429, 1288, 1181, 1116, 1102, 1130, 1184, 1278, 1400, 1546, 1700, 1870, 2020, 2030, 1899, 1706, 1536, 1388, 1239, 1137, 1074, 1053, 1078, 1134, 1235, 1358, 1509, 1661, 1838, 1989, 1985, 1853, 1682, 1522, 1356, 1209, 1114, 1050, 1024, 1046, 1106, 1206, 1335, 1478, 1623, 1801, 1954, 2005, 1887, 1706, 1536, 1383, 1235, 1131, 1063, 1045, 1059, 1120, 1225, 1356, 1493, 1666, 1815, 1981, 2063, 1948, 1767, 1589, 1438, 1293, 1183, 1116, 1093, 1115, 1174, 1272, 1400, 1546, 1695, 1877, 2012, 2055, 1952, 1795, 1633, 1476, 1347, 1235, 1167, 1146, 1160, 1230, 1323, 1435, 1579, 1730, 1898, 2046, 2059, 1972, 1843, 1666, 1519, 1402, 1291, 1231, 1209, 1233, 1283, 1366, 1481, 1613, 1767, 1922, 2023, 2066, 2036, 1903, 1740, 1609, 1484, 1399, 1337, 1317, 1330, 1378, 1451, 1572, 1689, 1830, 1964, 2037, 2034, 2097, 2005, 1856, 1724, 1608, 1521, 1471, 1450, 1456, 1505, 1593, 1688, 1805, 1940, 2051, 2045, 1974, 2123, 2067, 1958, 1827, 1719, 1633, 1580, 1563, 1576, 1609, 1688, 1783, 1892, 2009, 2053, 1911, 1652, 2078, 2101, 2021, 1915, 1837, 1731, 1682, 1661, 1686, 1717, 1782, 1864, 1982, 2036, 2005, 1669, ] b: [1439, 1756, 1796, 1808, 1716, 1631, 1568, 1537, 1530, 1546, 1578, 1608, 1676, 1744, 1796, 1756, 1456, 1685, 1858, 1830, 1764, 1687, 1603, 1529, 1486, 1489, 1486, 1493, 1552, 1628, 1721, 1812, 1858, 1727, 1837, 1888, 1825, 1726, 1628, 1548, 1478, 1449, 1423, 1434, 1462, 1521, 1566, 1688, 1809, 1888, 1837, 1889, 1857, 1775, 1680, 1576, 1467, 1403, 1336, 1309, 1329, 1369, 1429, 1529, 1623, 1733, 1822, 1868, 1852, 1828, 1704, 1585, 1486, 1377, 1285, 1237, 1216, 1232, 1268, 1344, 1438, 1536, 1667, 1764, 1813, 1853, 1815, 1675, 1576, 1436, 1333, 1226, 1158, 1145, 1158, 1216, 1298, 1407, 1503, 1640, 1754, 1816, 1908, 1800, 1691, 1536, 1422, 1296, 1188, 1114, 1095, 1114, 1174, 1268, 1388, 1485, 1623, 1742, 1851, 1865, 1783, 1646, 1513, 1378, 1236, 1124, 1071, 1050, 1074, 1132, 1211, 1333, 1463, 1603, 1713, 1829, 1822, 1736, 1621, 1486, 1358, 1211, 1109, 1040, 1024, 1037, 1101, 1197, 1314, 1423, 1559, 1683, 1788, 1829, 1769, 1635, 1513, 1371, 1231, 1128, 1057, 1033, 1057, 1112, 1202, 1327, 1455, 1572, 1700, 1794, 1870, 1831, 1679, 1554, 1430, 1290, 1170, 1103, 1091, 1107, 1165, 1263, 1374, 1501, 1623, 1742, 1833, 1911, 1863, 1724, 1586, 1459, 1352, 1236, 1171, 1153, 1171, 1221, 1315, 1414, 1520, 1663, 1799, 1872, 1913, 1861, 1730, 1626, 1511, 1397, 1296, 1242, 1221, 1227, 1279, 1350, 1446, 1555, 1691, 1779, 1852, 1934, 1893, 1804, 1703, 1576, 1475, 1396, 1329, 1309, 1336, 1363, 1437, 1538, 1634, 1747, 1839, 1868, 1955, 1991, 1910, 1808, 1696, 1596, 1537, 1472, 1445, 1457, 1494, 1539, 1617, 1739, 1825, 1928, 1860, 1818, 2015, 1981, 1906, 1778, 1680, 1627, 1585, 1551, 1566, 1596, 1646, 1725, 1824, 1902, 1945, 1794, 1571, 1937, 1977, 1932, 1866, 1784, 1714, 1674, 1642, 1662, 1678, 1730, 1788, 1859, 1913, 1912, 1592, ] #2592x1944_D65_70 - D65 - ct: 6504 resolution: 2592x1944 r: [2457, 2985, 2981, 2763, 2587, 2383, 2222, 2123, 2089, 2123, 2167, 2270, 2466, 2638, 2823, 2805, 2457, 2770, 3097, 2893, 2640, 2410, 2169, 2039, 1933, 1908, 1914, 1973, 2117, 2295, 2514, 2728, 2953, 2735, 3009, 2991, 2771, 2467, 2201, 1985, 1825, 1726, 1679, 1703, 1791, 1924, 2085, 2345, 2583, 2806, 2898, 3015, 2906, 2586, 2267, 2005, 1790, 1629, 1527, 1488, 1505, 1597, 1734, 1923, 2169, 2447, 2714, 2876, 2953, 2756, 2435, 2120, 1832, 1617, 1462, 1359, 1326, 1351, 1423, 1573, 1774, 2014, 2285, 2612, 2857, 2963, 2676, 2324, 2016, 1735, 1499, 1334, 1234, 1201, 1227, 1313, 1452, 1649, 1893, 2177, 2503, 2754, 2883, 2582, 2252, 1912, 1634, 1401, 1236, 1144, 1106, 1135, 1215, 1365, 1570, 1804, 2091, 2443, 2715, 2839, 2555, 2196, 1860, 1576, 1346, 1180, 1084, 1046, 1077, 1161, 1305, 1501, 1767, 2056, 2384, 2678, 2797, 2546, 2165, 1832, 1546, 1314, 1150, 1060, 1024, 1046, 1133, 1275, 1474, 1726, 2030, 2378, 2667, 2811, 2555, 2169, 1843, 1564, 1321, 1161, 1069, 1032, 1057, 1146, 1289, 1496, 1751, 2021, 2350, 2653, 2883, 2603, 2195, 1884, 1614, 1388, 1219, 1116, 1077, 1107, 1196, 1335, 1529, 1787, 2079, 2406, 2689, 2900, 2630, 2293, 1963, 1677, 1462, 1294, 1194, 1157, 1181, 1274, 1403, 1622, 1847, 2163, 2464, 2727, 2920, 2731, 2400, 2071, 1798, 1567, 1404, 1301, 1264, 1293, 1376, 1514, 1711, 1949, 2224, 2568, 2767, 3015, 2820, 2545, 2196, 1933, 1719, 1554, 1452, 1422, 1442, 1525, 1661, 1847, 2078, 2358, 2639, 2780, 2971, 2927, 2674, 2396, 2110, 1904, 1767, 1654, 1611, 1627, 1720, 1848, 2026, 2250, 2540, 2722, 2863, 2842, 3023, 2864, 2576, 2311, 2105, 1952, 1857, 1808, 1830, 1912, 2033, 2205, 2417, 2652, 2822, 2667, 2489, 3024, 2981, 2737, 2546, 2317, 2180, 2086, 2041, 2050, 2140, 2255, 2391, 2615, 2735, 2840, 2366, ] gr: [1766, 2092, 2109, 2006, 1875, 1775, 1707, 1659, 1633, 1646, 1679, 1754, 1844, 1954, 2045, 2041, 1740, 1981, 2142, 2048, 1911, 1779, 1678, 1597, 1549, 1529, 1539, 1570, 1630, 1728, 1848, 1970, 2064, 1971, 2109, 2107, 1982, 1820, 1673, 1563, 1494, 1442, 1423, 1433, 1472, 1538, 1630, 1751, 1899, 2019, 2058, 2121, 2066, 1892, 1719, 1584, 1472, 1386, 1331, 1311, 1326, 1370, 1441, 1533, 1673, 1820, 1956, 2062, 2080, 1982, 1807, 1636, 1493, 1379, 1293, 1236, 1213, 1230, 1280, 1353, 1458, 1580, 1729, 1885, 2017, 2074, 1934, 1756, 1584, 1435, 1318, 1220, 1163, 1142, 1154, 1207, 1280, 1393, 1522, 1666, 1844, 1990, 2041, 1886, 1711, 1535, 1392, 1269, 1165, 1106, 1086, 1103, 1151, 1240, 1356, 1479, 1635, 1802, 1969, 2006, 1856, 1673, 1506, 1359, 1220, 1131, 1067, 1041, 1056, 1113, 1201, 1312, 1446, 1594, 1771, 1937, 2000, 1841, 1654, 1489, 1334, 1201, 1105, 1046, 1024, 1038, 1096, 1183, 1299, 1428, 1577, 1746, 1925, 2006, 1850, 1656, 1490, 1339, 1210, 1112, 1054, 1028, 1044, 1098, 1188, 1296, 1431, 1574, 1754, 1923, 2033, 1868, 1692, 1518, 1366, 1242, 1143, 1085, 1060, 1074, 1133, 1214, 1329, 1460, 1602, 1780, 1938, 2040, 1900, 1722, 1547, 1409, 1291, 1192, 1131, 1107, 1125, 1174, 1258, 1363, 1488, 1644, 1813, 1958, 2052, 1939, 1770, 1592, 1461, 1346, 1254, 1192, 1174, 1186, 1236, 1312, 1410, 1535, 1690, 1846, 1975, 2071, 1986, 1843, 1664, 1533, 1424, 1338, 1280, 1256, 1269, 1309, 1387, 1475, 1596, 1753, 1898, 2006, 2058, 2045, 1906, 1756, 1622, 1517, 1432, 1380, 1363, 1372, 1412, 1480, 1566, 1691, 1835, 1955, 2008, 1971, 2083, 2008, 1842, 1718, 1606, 1530, 1488, 1463, 1468, 1506, 1574, 1675, 1772, 1904, 1992, 1922, 1748, 2103, 2063, 1961, 1838, 1724, 1648, 1600, 1596, 1592, 1627, 1690, 1780, 1890, 1969, 1992, 1713, ] gb: [1749, 2093, 2072, 1983, 1869, 1765, 1684, 1638, 1621, 1629, 1666, 1734, 1838, 1925, 2019, 2021, 1722, 1981, 2142, 2048, 1904, 1774, 1660, 1582, 1535, 1512, 1528, 1563, 1626, 1728, 1854, 1970, 2064, 1961, 2088, 2107, 1975, 1809, 1668, 1556, 1481, 1424, 1406, 1421, 1456, 1528, 1626, 1761, 1886, 2028, 2068, 2111, 2049, 1873, 1715, 1569, 1465, 1376, 1323, 1300, 1321, 1363, 1432, 1536, 1660, 1808, 1956, 2062, 2089, 1975, 1797, 1632, 1493, 1374, 1284, 1228, 1205, 1226, 1273, 1351, 1449, 1577, 1729, 1898, 2035, 2083, 1934, 1751, 1584, 1441, 1307, 1214, 1156, 1134, 1153, 1203, 1280, 1393, 1526, 1675, 1844, 1998, 2049, 1905, 1702, 1535, 1390, 1265, 1160, 1103, 1078, 1100, 1150, 1238, 1351, 1485, 1631, 1814, 1984, 2014, 1868, 1678, 1506, 1356, 1218, 1123, 1065, 1039, 1055, 1112, 1201, 1317, 1446, 1602, 1782, 1952, 2008, 1853, 1658, 1496, 1344, 1203, 1110, 1046, 1024, 1037, 1091, 1179, 1292, 1428, 1588, 1757, 1947, 2030, 1856, 1660, 1493, 1346, 1212, 1116, 1049, 1024, 1040, 1093, 1190, 1303, 1440, 1590, 1760, 1937, 2041, 1886, 1688, 1522, 1376, 1240, 1146, 1083, 1057, 1074, 1131, 1218, 1331, 1466, 1614, 1785, 1953, 2066, 1920, 1737, 1558, 1415, 1289, 1186, 1130, 1110, 1123, 1172, 1254, 1368, 1492, 1644, 1814, 1974, 2080, 1953, 1775, 1612, 1461, 1343, 1254, 1194, 1174, 1186, 1236, 1309, 1413, 1528, 1695, 1852, 1983, 2081, 2009, 1837, 1678, 1543, 1424, 1338, 1278, 1254, 1273, 1306, 1390, 1485, 1604, 1758, 1905, 2016, 2078, 2062, 1926, 1777, 1626, 1517, 1441, 1388, 1363, 1367, 1412, 1487, 1574, 1686, 1835, 1962, 2018, 1981, 2112, 2016, 1848, 1733, 1614, 1541, 1488, 1469, 1468, 1520, 1570, 1666, 1789, 1911, 1992, 1913, 1776, 2082, 2072, 1968, 1856, 1739, 1657, 1600, 1577, 1592, 1627, 1695, 1786, 1883, 1977, 2002, 1722, ] b: [1681, 1945, 1998, 1882, 1777, 1699, 1617, 1588, 1571, 1554, 1581, 1644, 1729, 1797, 1905, 1919, 1646, 1868, 2012, 1964, 1828, 1711, 1617, 1535, 1492, 1479, 1478, 1509, 1559, 1636, 1737, 1860, 1925, 1830, 1961, 2001, 1890, 1754, 1638, 1529, 1463, 1407, 1389, 1407, 1432, 1485, 1574, 1668, 1790, 1898, 1922, 1995, 1962, 1813, 1680, 1557, 1453, 1378, 1319, 1297, 1302, 1348, 1418, 1505, 1605, 1726, 1868, 1944, 2004, 1901, 1765, 1611, 1482, 1375, 1287, 1230, 1207, 1224, 1259, 1338, 1420, 1528, 1664, 1807, 1921, 1969, 1858, 1708, 1557, 1434, 1317, 1217, 1161, 1142, 1156, 1206, 1275, 1369, 1481, 1598, 1764, 1880, 1973, 1821, 1664, 1516, 1392, 1270, 1165, 1106, 1085, 1095, 1152, 1231, 1336, 1445, 1567, 1725, 1856, 1947, 1804, 1647, 1495, 1359, 1230, 1136, 1067, 1043, 1060, 1115, 1197, 1299, 1419, 1548, 1695, 1834, 1924, 1787, 1623, 1478, 1346, 1212, 1114, 1052, 1024, 1044, 1094, 1172, 1287, 1408, 1532, 1681, 1853, 1925, 1804, 1641, 1481, 1351, 1225, 1124, 1056, 1032, 1046, 1099, 1181, 1296, 1410, 1531, 1688, 1806, 1951, 1821, 1664, 1516, 1377, 1255, 1150, 1089, 1066, 1082, 1128, 1214, 1315, 1432, 1562, 1709, 1856, 1957, 1840, 1688, 1546, 1413, 1297, 1190, 1139, 1116, 1130, 1179, 1259, 1347, 1462, 1592, 1740, 1859, 1968, 1881, 1728, 1588, 1460, 1345, 1265, 1199, 1180, 1191, 1241, 1307, 1391, 1498, 1644, 1773, 1876, 2008, 1940, 1789, 1654, 1531, 1427, 1341, 1286, 1265, 1273, 1316, 1370, 1471, 1569, 1696, 1830, 1896, 2002, 1977, 1871, 1732, 1620, 1519, 1432, 1387, 1362, 1364, 1402, 1466, 1535, 1654, 1782, 1877, 1896, 1895, 2025, 1975, 1828, 1704, 1599, 1540, 1478, 1456, 1459, 1499, 1548, 1636, 1737, 1841, 1925, 1830, 1705, 2013, 2036, 1912, 1785, 1720, 1636, 1588, 1565, 1576, 1599, 1664, 1722, 1815, 1905, 1945, 1681, ] #2592x1944_F2_CWF_70 - F2_CWF - ct: 4230 resolution: 2592x1944 r: [2512, 2860, 2753, 2554, 2376, 2198, 2033, 1949, 1924, 1921, 2012, 2100, 2257, 2461, 2682, 2775, 2436, 2753, 2915, 2713, 2415, 2193, 2004, 1869, 1790, 1755, 1774, 1844, 1945, 2108, 2306, 2547, 2755, 2697, 2849, 2810, 2526, 2247, 2018, 1821, 1692, 1608, 1577, 1591, 1653, 1775, 1921, 2132, 2371, 2625, 2765, 2881, 2679, 2376, 2077, 1853, 1677, 1542, 1449, 1412, 1430, 1511, 1615, 1781, 1983, 2258, 2517, 2722, 2832, 2589, 2237, 1977, 1718, 1527, 1403, 1319, 1290, 1307, 1370, 1491, 1658, 1850, 2112, 2408, 2708, 2718, 2474, 2154, 1861, 1616, 1439, 1293, 1211, 1176, 1205, 1275, 1390, 1553, 1773, 2008, 2313, 2607, 2661, 2388, 2066, 1781, 1535, 1359, 1207, 1130, 1098, 1117, 1192, 1313, 1474, 1688, 1934, 2240, 2537, 2672, 2353, 2024, 1733, 1494, 1296, 1162, 1075, 1045, 1064, 1146, 1261, 1422, 1640, 1889, 2197, 2528, 2599, 2332, 1991, 1718, 1484, 1276, 1139, 1051, 1024, 1051, 1117, 1245, 1409, 1620, 1861, 2179, 2481, 2651, 2338, 2004, 1719, 1479, 1289, 1146, 1066, 1034, 1055, 1127, 1248, 1413, 1633, 1872, 2184, 2471, 2640, 2372, 2045, 1751, 1514, 1324, 1189, 1107, 1064, 1097, 1163, 1280, 1455, 1661, 1915, 2226, 2498, 2672, 2457, 2107, 1820, 1587, 1390, 1248, 1170, 1132, 1155, 1235, 1353, 1510, 1729, 1967, 2268, 2544, 2781, 2532, 2198, 1920, 1678, 1486, 1349, 1251, 1225, 1251, 1326, 1438, 1602, 1800, 2043, 2343, 2616, 2826, 2637, 2330, 2024, 1796, 1609, 1480, 1391, 1365, 1370, 1442, 1556, 1714, 1915, 2190, 2461, 2673, 2820, 2738, 2472, 2182, 1949, 1760, 1640, 1545, 1517, 1524, 1591, 1716, 1867, 2073, 2308, 2561, 2686, 2782, 2806, 2648, 2352, 2132, 1926, 1819, 1716, 1678, 1702, 1757, 1872, 2029, 2234, 2434, 2611, 2617, 2538, 2919, 2777, 2554, 2345, 2148, 2012, 1940, 1896, 1930, 1961, 2065, 2243, 2426, 2592, 2669, 2461, ] gr: [2065, 2350, 2320, 2148, 2002, 1877, 1794, 1730, 1709, 1712, 1754, 1837, 1948, 2082, 2217, 2291, 2054, 2263, 2359, 2204, 2022, 1860, 1735, 1639, 1583, 1560, 1576, 1619, 1694, 1805, 1967, 2126, 2281, 2228, 2353, 2294, 2112, 1897, 1724, 1615, 1525, 1460, 1441, 1448, 1499, 1581, 1684, 1829, 2000, 2187, 2305, 2354, 2194, 1994, 1785, 1626, 1493, 1406, 1349, 1323, 1342, 1384, 1468, 1576, 1722, 1909, 2100, 2265, 2281, 2126, 1894, 1708, 1539, 1409, 1310, 1253, 1225, 1240, 1291, 1377, 1486, 1639, 1821, 2019, 2220, 2257, 2059, 1819, 1622, 1464, 1337, 1233, 1168, 1144, 1161, 1219, 1302, 1420, 1576, 1733, 1934, 2180, 2189, 1991, 1759, 1578, 1407, 1280, 1164, 1107, 1085, 1100, 1157, 1242, 1359, 1514, 1685, 1894, 2110, 2153, 1954, 1726, 1537, 1365, 1229, 1129, 1066, 1039, 1057, 1114, 1202, 1327, 1471, 1638, 1850, 2094, 2153, 1948, 1718, 1522, 1352, 1217, 1114, 1047, 1024, 1038, 1100, 1187, 1310, 1467, 1627, 1851, 2078, 2162, 1947, 1716, 1527, 1367, 1225, 1125, 1054, 1031, 1045, 1106, 1198, 1320, 1465, 1638, 1861, 2094, 2180, 1964, 1731, 1545, 1383, 1252, 1145, 1085, 1057, 1070, 1131, 1223, 1341, 1488, 1658, 1852, 2077, 2199, 2002, 1787, 1584, 1429, 1297, 1194, 1131, 1109, 1124, 1181, 1266, 1384, 1523, 1695, 1908, 2118, 2260, 2071, 1843, 1651, 1502, 1364, 1265, 1203, 1181, 1197, 1244, 1331, 1451, 1579, 1763, 1969, 2153, 2276, 2150, 1922, 1736, 1573, 1453, 1355, 1296, 1275, 1285, 1335, 1417, 1526, 1663, 1849, 2052, 2203, 2294, 2205, 2029, 1834, 1666, 1548, 1461, 1399, 1372, 1390, 1431, 1513, 1620, 1760, 1931, 2115, 2237, 2228, 2271, 2126, 1934, 1784, 1650, 1577, 1512, 1485, 1506, 1547, 1625, 1729, 1872, 2029, 2189, 2160, 2033, 2326, 2227, 2106, 1935, 1815, 1721, 1671, 1627, 1654, 1688, 1768, 1885, 2021, 2160, 2245, 2022, ] gb: [2062, 2335, 2286, 2148, 1975, 1850, 1776, 1709, 1688, 1709, 1761, 1822, 1943, 2082, 2226, 2300, 2062, 2272, 2345, 2186, 2016, 1856, 1728, 1637, 1579, 1556, 1564, 1610, 1691, 1807, 1961, 2126, 2280, 2237, 2338, 2293, 2081, 1893, 1731, 1594, 1501, 1444, 1424, 1441, 1485, 1572, 1677, 1830, 2022, 2195, 2303, 2352, 2212, 1988, 1782, 1625, 1499, 1400, 1342, 1318, 1335, 1379, 1468, 1579, 1728, 1898, 2116, 2274, 2311, 2127, 1896, 1701, 1538, 1404, 1308, 1249, 1218, 1243, 1290, 1382, 1491, 1641, 1828, 2041, 2249, 2256, 2060, 1820, 1637, 1476, 1335, 1234, 1166, 1147, 1159, 1220, 1302, 1428, 1586, 1754, 1968, 2198, 2225, 2013, 1781, 1584, 1421, 1281, 1166, 1101, 1082, 1105, 1158, 1246, 1372, 1524, 1696, 1914, 2144, 2179, 1961, 1742, 1546, 1378, 1232, 1136, 1064, 1042, 1061, 1118, 1208, 1335, 1489, 1661, 1875, 2110, 2179, 1962, 1734, 1538, 1367, 1224, 1117, 1051, 1024, 1046, 1106, 1195, 1322, 1479, 1658, 1876, 2094, 2179, 1988, 1742, 1543, 1375, 1232, 1128, 1060, 1030, 1050, 1110, 1208, 1330, 1486, 1652, 1881, 2127, 2197, 2006, 1761, 1562, 1396, 1255, 1152, 1086, 1063, 1077, 1137, 1232, 1354, 1504, 1682, 1902, 2135, 2236, 2031, 1810, 1605, 1449, 1311, 1200, 1137, 1110, 1130, 1185, 1275, 1389, 1539, 1720, 1922, 2161, 2290, 2103, 1873, 1675, 1504, 1379, 1276, 1211, 1184, 1202, 1251, 1339, 1460, 1593, 1785, 1983, 2180, 2329, 2176, 1961, 1752, 1598, 1471, 1366, 1308, 1279, 1292, 1348, 1432, 1535, 1682, 1874, 2068, 2222, 2338, 2253, 2059, 1852, 1686, 1565, 1473, 1410, 1385, 1393, 1445, 1522, 1639, 1782, 1959, 2132, 2257, 2272, 2312, 2160, 1961, 1802, 1674, 1587, 1525, 1497, 1508, 1557, 1644, 1741, 1897, 2045, 2197, 2202, 2095, 2335, 2276, 2098, 1969, 1828, 1732, 1669, 1641, 1656, 1699, 1785, 1886, 2036, 2188, 2254, 2030, ] b: [1957, 2184, 2113, 2000, 1876, 1757, 1686, 1620, 1614, 1596, 1649, 1687, 1805, 1914, 2027, 2082, 1880, 2101, 2170, 2056, 1894, 1763, 1659, 1571, 1527, 1501, 1506, 1541, 1608, 1694, 1809, 1964, 2094, 2040, 2156, 2121, 1964, 1796, 1654, 1563, 1485, 1419, 1399, 1407, 1447, 1499, 1587, 1724, 1859, 2019, 2076, 2184, 2063, 1888, 1705, 1586, 1470, 1383, 1330, 1299, 1315, 1352, 1421, 1513, 1633, 1794, 1956, 2125, 2153, 2012, 1821, 1660, 1511, 1395, 1302, 1241, 1219, 1232, 1275, 1352, 1453, 1570, 1726, 1914, 2080, 2106, 1953, 1751, 1601, 1462, 1333, 1235, 1171, 1142, 1156, 1207, 1285, 1403, 1520, 1656, 1838, 2038, 2081, 1885, 1704, 1553, 1398, 1266, 1166, 1101, 1079, 1097, 1151, 1240, 1340, 1471, 1616, 1780, 1970, 2041, 1882, 1686, 1513, 1364, 1235, 1125, 1065, 1037, 1054, 1108, 1196, 1299, 1429, 1576, 1756, 1935, 2049, 1853, 1665, 1504, 1363, 1227, 1118, 1049, 1024, 1035, 1099, 1188, 1298, 1434, 1582, 1752, 1929, 2073, 1870, 1677, 1520, 1364, 1240, 1131, 1057, 1037, 1048, 1102, 1188, 1308, 1442, 1600, 1756, 1921, 2048, 1885, 1695, 1525, 1387, 1248, 1148, 1085, 1064, 1076, 1131, 1215, 1325, 1458, 1591, 1780, 1926, 2089, 1926, 1731, 1563, 1432, 1304, 1191, 1132, 1112, 1129, 1172, 1258, 1359, 1492, 1647, 1814, 1975, 2115, 1983, 1799, 1626, 1491, 1368, 1270, 1212, 1188, 1204, 1249, 1322, 1416, 1548, 1697, 1874, 2045, 2164, 2047, 1888, 1705, 1571, 1451, 1357, 1296, 1276, 1291, 1336, 1404, 1499, 1616, 1772, 1956, 2069, 2177, 2139, 1964, 1785, 1654, 1549, 1459, 1402, 1376, 1385, 1423, 1493, 1587, 1704, 1847, 2003, 2057, 2144, 2190, 2056, 1906, 1753, 1642, 1556, 1506, 1488, 1485, 1534, 1592, 1684, 1809, 1935, 2076, 2081, 1997, 2228, 2150, 2030, 1888, 1799, 1704, 1637, 1631, 1629, 1667, 1716, 1816, 1914, 2043, 2122, 1917, ] #2592x1944_D50_70 - D50 - ct: 5003 resolution: 2592x1944 r: [2445, 2929, 2967, 2734, 2576, 2380, 2211, 2113, 2074, 2072, 2166, 2255, 2383, 2626, 2861, 2812, 2411, 2795, 3067, 2915, 2660, 2369, 2162, 2038, 1940, 1900, 1919, 1978, 2106, 2281, 2519, 2702, 2875, 2718, 2953, 3006, 2761, 2452, 2197, 1964, 1815, 1720, 1676, 1712, 1769, 1899, 2070, 2268, 2581, 2739, 2798, 3022, 2895, 2570, 2275, 2011, 1793, 1619, 1512, 1486, 1506, 1577, 1740, 1898, 2123, 2420, 2659, 2869, 2939, 2776, 2457, 2132, 1863, 1619, 1479, 1366, 1332, 1356, 1435, 1571, 1769, 1978, 2272, 2543, 2736, 2905, 2703, 2360, 2023, 1747, 1516, 1355, 1247, 1214, 1243, 1332, 1457, 1651, 1898, 2194, 2488, 2714, 2945, 2615, 2257, 1937, 1653, 1419, 1242, 1151, 1117, 1138, 1219, 1374, 1575, 1795, 2080, 2417, 2695, 2795, 2558, 2207, 1875, 1586, 1350, 1182, 1089, 1046, 1084, 1158, 1305, 1497, 1736, 2027, 2351, 2624, 2840, 2547, 2201, 1863, 1566, 1323, 1172, 1068, 1024, 1057, 1142, 1288, 1484, 1725, 2010, 2343, 2584, 2857, 2580, 2222, 1875, 1573, 1355, 1182, 1086, 1046, 1072, 1151, 1301, 1509, 1762, 2052, 2371, 2707, 2912, 2615, 2257, 1904, 1631, 1389, 1227, 1129, 1090, 1122, 1197, 1331, 1529, 1777, 2040, 2397, 2639, 2905, 2628, 2290, 1987, 1698, 1457, 1296, 1202, 1154, 1181, 1259, 1398, 1607, 1826, 2119, 2466, 2684, 2939, 2748, 2399, 2078, 1796, 1584, 1424, 1310, 1276, 1297, 1377, 1519, 1708, 1943, 2222, 2543, 2736, 2982, 2863, 2570, 2243, 1964, 1740, 1570, 1470, 1435, 1448, 1537, 1683, 1856, 2094, 2342, 2632, 2798, 3037, 2970, 2681, 2413, 2111, 1920, 1769, 1672, 1616, 1634, 1709, 1847, 2019, 2234, 2488, 2709, 2835, 2836, 3026, 2851, 2611, 2315, 2106, 1932, 1836, 1801, 1807, 1899, 2027, 2199, 2392, 2620, 2805, 2644, 2515, 3013, 2967, 2792, 2553, 2343, 2181, 2046, 2035, 2033, 2108, 2239, 2444, 2575, 2731, 2812, 2411, ] gr: [1764, 2120, 2133, 2015, 1886, 1783, 1704, 1644, 1626, 1631, 1666, 1739, 1792, 1938, 2020, 2014, 1727, 1988, 2163, 2079, 1945, 1797, 1681, 1595, 1551, 1526, 1533, 1567, 1619, 1707, 1833, 1963, 2052, 1936, 2115, 2119, 1964, 1824, 1676, 1555, 1486, 1428, 1406, 1425, 1447, 1526, 1623, 1720, 1866, 2001, 2030, 2142, 2062, 1902, 1716, 1580, 1465, 1376, 1321, 1301, 1314, 1355, 1428, 1513, 1645, 1791, 1941, 2022, 2104, 1988, 1816, 1663, 1515, 1388, 1294, 1235, 1215, 1225, 1271, 1350, 1449, 1571, 1719, 1880, 2028, 2113, 1963, 1766, 1588, 1445, 1325, 1231, 1168, 1142, 1155, 1213, 1284, 1392, 1517, 1662, 1835, 1980, 2065, 1897, 1712, 1544, 1394, 1268, 1163, 1105, 1080, 1097, 1147, 1225, 1348, 1464, 1603, 1780, 1948, 2044, 1877, 1672, 1512, 1355, 1223, 1127, 1057, 1038, 1052, 1107, 1193, 1312, 1437, 1593, 1741, 1931, 2004, 1873, 1674, 1501, 1350, 1211, 1113, 1048, 1024, 1038, 1095, 1180, 1301, 1424, 1571, 1738, 1895, 2027, 1871, 1681, 1506, 1361, 1227, 1123, 1064, 1035, 1057, 1104, 1189, 1310, 1440, 1573, 1758, 1916, 2048, 1884, 1707, 1526, 1374, 1248, 1154, 1087, 1069, 1073, 1128, 1205, 1317, 1455, 1590, 1757, 1925, 2031, 1907, 1720, 1557, 1406, 1289, 1193, 1129, 1104, 1116, 1170, 1244, 1348, 1478, 1621, 1792, 1947, 2075, 1973, 1777, 1615, 1465, 1355, 1269, 1195, 1176, 1184, 1234, 1302, 1412, 1532, 1669, 1826, 1975, 2100, 2028, 1870, 1687, 1542, 1443, 1352, 1294, 1264, 1278, 1324, 1393, 1492, 1602, 1757, 1911, 2031, 2093, 2054, 1935, 1763, 1631, 1529, 1441, 1393, 1361, 1371, 1419, 1480, 1569, 1690, 1827, 1960, 2020, 1957, 2091, 1979, 1864, 1722, 1619, 1529, 1484, 1458, 1471, 1497, 1557, 1654, 1761, 1918, 2005, 1907, 1783, 2076, 2094, 1938, 1829, 1729, 1657, 1592, 1571, 1572, 1616, 1664, 1769, 1880, 1968, 1994, 1718, ] gb: [1771, 2117, 2122, 1999, 1887, 1768, 1691, 1633, 1619, 1633, 1668, 1736, 1836, 1923, 2010, 2002, 1734, 2040, 2161, 2070, 1925, 1777, 1678, 1601, 1532, 1528, 1518, 1562, 1625, 1724, 1840, 1956, 2079, 1954, 2091, 2109, 1965, 1826, 1669, 1561, 1472, 1419, 1400, 1422, 1450, 1521, 1608, 1732, 1867, 2001, 2028, 2151, 2053, 1877, 1718, 1579, 1465, 1379, 1319, 1296, 1309, 1350, 1428, 1530, 1647, 1792, 1934, 2030, 2112, 2003, 1824, 1656, 1511, 1388, 1296, 1240, 1206, 1228, 1271, 1347, 1458, 1577, 1725, 1894, 2018, 2112, 1978, 1778, 1602, 1451, 1325, 1231, 1165, 1141, 1154, 1207, 1292, 1397, 1530, 1687, 1849, 2030, 2056, 1911, 1723, 1554, 1396, 1271, 1165, 1103, 1077, 1100, 1148, 1236, 1343, 1477, 1626, 1798, 1972, 2027, 1885, 1692, 1522, 1358, 1225, 1126, 1068, 1038, 1055, 1105, 1194, 1313, 1443, 1583, 1771, 1931, 2037, 1868, 1690, 1514, 1355, 1216, 1116, 1053, 1024, 1046, 1096, 1191, 1306, 1433, 1586, 1762, 1925, 2061, 1891, 1688, 1522, 1363, 1236, 1128, 1067, 1037, 1059, 1110, 1196, 1318, 1439, 1596, 1765, 1977, 2056, 1898, 1709, 1535, 1391, 1264, 1157, 1089, 1069, 1076, 1131, 1216, 1335, 1467, 1596, 1775, 1948, 2048, 1929, 1737, 1567, 1427, 1294, 1198, 1130, 1106, 1120, 1168, 1260, 1353, 1491, 1641, 1811, 1963, 2112, 1988, 1795, 1626, 1484, 1374, 1274, 1198, 1174, 1190, 1237, 1317, 1427, 1538, 1695, 1840, 2000, 2140, 2045, 1877, 1708, 1567, 1443, 1360, 1304, 1267, 1288, 1337, 1398, 1491, 1621, 1781, 1919, 2039, 2112, 2109, 1936, 1792, 1633, 1539, 1450, 1396, 1377, 1376, 1422, 1496, 1579, 1697, 1835, 1976, 2028, 2029, 2089, 2028, 1884, 1734, 1638, 1543, 1490, 1460, 1466, 1514, 1579, 1670, 1774, 1910, 2013, 1904, 1790, 2117, 2065, 1961, 1854, 1752, 1672, 1616, 1590, 1599, 1623, 1700, 1782, 1867, 1984, 2022, 1698, ] b: [1676, 1930, 1956, 1924, 1811, 1685, 1640, 1571, 1556, 1544, 1569, 1639, 1710, 1802, 1890, 1881, 1642, 1930, 2013, 1952, 1827, 1711, 1616, 1538, 1488, 1472, 1470, 1494, 1560, 1632, 1724, 1825, 1906, 1803, 1985, 2007, 1894, 1759, 1625, 1524, 1440, 1401, 1380, 1385, 1411, 1463, 1537, 1649, 1765, 1876, 1884, 1996, 1961, 1831, 1676, 1555, 1444, 1367, 1301, 1282, 1295, 1328, 1383, 1468, 1580, 1708, 1833, 1900, 2020, 1914, 1777, 1618, 1508, 1382, 1284, 1227, 1197, 1216, 1251, 1325, 1408, 1511, 1639, 1796, 1915, 1998, 1901, 1716, 1581, 1447, 1327, 1226, 1169, 1134, 1155, 1199, 1269, 1368, 1486, 1608, 1741, 1879, 1959, 1838, 1674, 1531, 1387, 1269, 1158, 1094, 1072, 1082, 1132, 1217, 1323, 1431, 1568, 1706, 1847, 1956, 1806, 1645, 1497, 1352, 1222, 1124, 1059, 1031, 1049, 1093, 1177, 1292, 1398, 1528, 1686, 1800, 1945, 1806, 1634, 1494, 1357, 1211, 1110, 1049, 1024, 1034, 1080, 1174, 1277, 1388, 1519, 1673, 1809, 1989, 1822, 1664, 1497, 1366, 1239, 1115, 1065, 1033, 1049, 1095, 1183, 1295, 1406, 1544, 1679, 1855, 1981, 1838, 1674, 1512, 1384, 1260, 1151, 1086, 1062, 1069, 1121, 1198, 1303, 1423, 1540, 1691, 1847, 1964, 1856, 1683, 1550, 1422, 1294, 1189, 1122, 1103, 1113, 1164, 1237, 1332, 1446, 1574, 1741, 1859, 2008, 1885, 1755, 1606, 1471, 1371, 1263, 1197, 1169, 1182, 1228, 1298, 1392, 1501, 1620, 1763, 1883, 2034, 1950, 1823, 1676, 1540, 1439, 1353, 1298, 1269, 1276, 1325, 1383, 1468, 1575, 1700, 1833, 1923, 2012, 1995, 1894, 1744, 1625, 1519, 1440, 1389, 1361, 1370, 1403, 1467, 1558, 1642, 1773, 1876, 1908, 1903, 2038, 1942, 1844, 1704, 1599, 1528, 1484, 1445, 1457, 1494, 1544, 1602, 1724, 1843, 1906, 1827, 1724, 2051, 2027, 1914, 1827, 1698, 1640, 1577, 1566, 1588, 1604, 1633, 1717, 1811, 1901, 1930, 1665, ] ...
0
repos/libcamera/src/ipa/rkisp1
repos/libcamera/src/ipa/rkisp1/data/ov4689.yaml
# SPDX-License-Identifier: CC0-1.0 %YAML 1.1 --- version: 1 algorithms: - Agc: - Awb: - BlackLevelCorrection: R: 66 Gr: 66 Gb: 66 B: 66 ...