Commit graph

3499 commits

Author SHA1 Message Date
Laurent Pinchart
560ceb1ea8 libcamera: v4l2_subdevice: Silence warning for unknown metadata formats
Commit e297673e76 ("libcamera: v4l2_device: Adjust colorspace based on
pixel format") has introduced a warning when trying to convert a color
space from V4L2 to libcamera if the media bus code is unknown. This was
meant to catch unknown image formats, but turned out to be also
triggered for metadata formats.

Color spaces are not applicable to metadata formats, there should thus
be no warning. Fix it by skipping the color space translation and
returning std::nullopt directly if the kernel reports
V4L2_COLORSPACE_DEFAULT. This doesn't introduce any change in behaviour
other than getting rid of the warning, as the V4L2Device::toColorSpace()
function returns std::nullopt already in that case.

Fixes: e297673e76 ("libcamera: v4l2_device: Adjust colorspace based on pixel format")
Reported-by: Naushir Patuck <naush@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Tested-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
2022-09-08 16:43:32 +03:00
Utkarsh Tiwari
5a9fd9a95c qcam: Fix crash when switching from non existant camera
When switching to different camera we try to release the camera
previously used. But if that camera has been unplugged, then its
instance would have been destroyed. Accessing it leads to seg fault.

Fix by checking camera_ to see if it exists.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=147
Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-08 11:20:53 +03:00
Laurent Pinchart
6225d647b4 pipeline: uvcvideo: Fail match() if the camera has no supported format
A UVC device could expose only formats that are not supported by
libcamera. The pipeline handler doesn't currently consider this as an
error, and happily creates a camera. The camera won't be usable, and
worse, generateConfiguration() and validate() will crash as those
functions assume that at least one format is supported.

Fix this by failing match() if none of the formats exposed by the camera
are supported. Log an error message in that case to notify the user.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=145
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Christian Rauch <Rauch.Christian@gmx.de>
2022-09-07 00:32:10 +03:00
Laurent Pinchart
f98919307e pipeline: uvcvideo: Cache supported formats in UVCCameraData
Populate and cache the list of supported formats in
UVCCameraData::init(), to avoid repeating the operation every time
generateConfiguration() is called. Combine this with the search for
the largest size advertised by the camera to avoid iterating over the
formats twice in init().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Christian Rauch <Rauch.Christian@gmx.de>
2022-09-07 00:32:08 +03:00
Laurent Pinchart
52660f2b13 pipeline: uvcvideo: Move camera ID generation to UVCCameraData class
Move the camera ID generation to UVCCameraData, and cache the ID in that
class. This will be useful to access the ID in multiple locations, such
as when printing error messages.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Christian Rauch <Rauch.Christian@gmx.de>
2022-09-07 00:30:04 +03:00
Kieran Bingham
ad8af50d86 libcamera: v4l2_device: Report device node on failure
When the V4L2Device fails to open, it is not clear what device
caused the failure. The Entity name is presented, but not the device
node.

Provide it.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-05 17:34:49 +01:00
Kieran Bingham
29497a73dd CameraSensor: Don't fail to add camera with faulty lens
If the CameraSensor fails to identify the VCM specified, it could still
be possible to continue to operate the sensor. Autofocus support will be
disabled, but this would be no different to operating a camera with a
fixed focus. While of course the fixed focus position may not be
suitable, it would provide a better user experience to be able to
continue to operate the camera, while still reporting that the lens is
disabled.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=146
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-05 17:34:49 +01:00
Kieran Bingham
1a082a3e95 libcamera: yaml_parser: Report filename on failures
It can be helpful to know 'which' file failed to parse if there is a
failure.

Report it to the user in the error message.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-05 17:34:49 +01:00
Barnabás Pőcze
cec5704d34 libcamera: Override "libcamera" dependency in meson
Overriding the dependency enables libcamera to be used
as a meson subproject more easily.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-05 17:55:45 +03:00
Marco Felsch
5771125bfa qcam: viewfinder_gl: Fix maybe-uninitialized warnings
Commit 251f0534b7 ("qcam: viewfinder_gl: Take color space into account
for YUV rendering") introduced maybe-uninitialized warnings with gcc 11
and 12 when compiling with -O3. Both compilers warn that

../../src/qcam/viewfinder_gl.cpp: In member function ‘void ViewFinderGL::selectColorSpace(const libcamera::ColorSpace&)’:
../../src/qcam/viewfinder_gl.cpp:392:21: error: ‘offset’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  391 |         fragmentShaderDefines_.append(QString("#define YUV2RGB_Y_OFFSET %1")
      |                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  392 |                 .arg(offset, 0, 'f', 1));
      |                 ~~~~^~~~~~~~~~~~~~~~~~~

Additionally, gcc 12 warns that

../../src/qcam/viewfinder_gl.cpp: In member function ‘void ViewFinderGL::selectColorSpace(const libcamera::ColorSpace&)’:
../../src/qcam/viewfinder_gl.cpp:379:36: error: ‘yuv2rgb’ may be used uninitialized [-Werror=maybe-uninitialized]
  379 |                         yuv2rgb[i] *= 255.0 / 219.0;
../../src/qcam/viewfinder_gl.cpp:330:31: note: ‘yuv2rgb’ declared here
  330 |         std::array<double, 9> yuv2rgb;
      |

While this should never happen here, the compiler isn't necessarily
wrong, as C++17 allows initializing a scoped enum from an integer using
direct-list-initialization, even if the integer value doesn't match any
of the enumerators for the scoped enum ([1]). Whether this is valid or
borderline paranoia from gcc may be debatable, but in any case it can't
be classified as blatantly wrong. Fix the warnings by adding default
cases to the switch statements in ViewFinderGL::selectColorSpace().
Which case is selected as the default doesn't matter, as this is not
meant to happen.

[1] https://en.cppreference.com/w/cpp/language/enum#enum_relaxed_init_cpp17

Bug: https://bugs.libcamera.org/show_bug.cgi?id=143
Fixes: 251f0534b7 ("qcam: viewfinder_gl: Take color space into account for YUV rendering")
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Rewrote commit message, added a default case for the encoding switch.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-05 17:55:45 +03:00
Laurent Pinchart
a03ce60cf9 libcamera: v4l2_device: Map YCbCrEncoding::None to V4L2
The ycbcrEncodingToV4l2 map is missing the YCbCrEncoding::None encoding,
which results in a failure of V4L2Device::fromColorSpace() to convert
color spaces from libcamera to V4L2 for RGB formats. Fix it by adding
the missing encoding. As V4L2 has no such encoding, use
V4L2_YCBCR_ENC_DEFAULT as the value doesn't matter.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-05 17:55:45 +03:00
Utkarsh Tiwari
d182a99e7b
qcam: Queue requests only through MainWindow::queueRequest()
Currently to request a frame, we operate the camera directly.
This approach is also scattered in two places,
MainWindow::startCapture() and MainWindow::queueRequest().
This makes it difficult to account for requests.

Centralize all the queuing to a single function queueRequest()

Rename the current queueRequest() to renderComplete().
This makes more sense as this slot is triggered when
the render is complete and we want to queue another
request.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-05 12:19:50 +05:30
Utkarsh Tiwari
d598e77aa5
qcam: CamSelectDialog: Display Location and Model propety of camera
The camera selection dialog currently only displays the camera Id.
Display the camera location and camera model if available.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-05 12:19:00 +05:30
Utkarsh Tiwari
b63519d201
qcam: MainWindow: Replace cameraCombo_ with CameraSelectorDialog
Replace the cameraCombo_ on the toolbar with a QPushButton which
displays the CameraSelectorDialog. This would allow the user to view
information about the camera when switching.

The QPushButton text is set to the camera Id currently in use.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-05 12:14:14 +05:30
Utkarsh Tiwari
923927ae45
qcam: Support Hotplug for Camera Selection Dialog
Currently if there is HotPlug event when the user is on the Camera
selection dialog, the QComboBox doesn't update to reflect the change.

Add support for hotplugging / unplugging cameras.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-05 12:12:02 +05:30
Utkarsh Tiwari
f03da23b56
qcam: Use QDialog for selection of cameras at startup
Currently we use QInputDialog convenience dialogs to allow the user to
select a camera. This doesn't allow adding of more information (such as
camera location, model etc).

Create a QDialog with a QFormLayout that shows a QComboBox with camera
Ids. Use a QDialogButtonBox to provide buttons for accepting and
cancelling the action.

The CameraSelectorDialog is only initialized the first time when the
MainWindow is created.

From this commit we cease to auto select the camera if only a single
camera is available to libcamera. We would always display the selection
dialog with the exception being that being if the camera is supplied on
the command line.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-05 12:04:59 +05:30
Daniel Semkowicz
f1776100f5 cam: capture_script: Check parseFrames() return value for errors
parseFrames() return value was ignored. If there was an error during
frame parsing, parsing was not stopped correctly.

Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-02 12:39:48 +02:00
Daniel Semkowicz
f71c76ceff cam: Add Rectangle type parsing in capture script
This change is required for AfWindows control from capture script.
Parser expects array of arrays of parameters, so it is possible to
specify multiple rectangles.

Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-02 12:39:44 +02:00
Laurent Pinchart
251f0534b7 qcam: viewfinder_gl: Take color space into account for YUV rendering
Update the YUV shaders and the viewfinder_gl to correctly take the
Y'CbCr encoding and the quantization range into account when rendering
YUV formats to RGB. Support for the primaries and transfer function will
be added in a subsequent step.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kunal Agarwal <kunalagarwal1072002@gmail.com>
2022-09-01 22:41:01 +03:00
Laurent Pinchart
ee4681b7e8 qcam: Pass color space to ViewFinder::setFormat()
To prepare for color space support in the viewfinder, pass the color
space to the setFormat() function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-01 22:41:01 +03:00
Laurent Pinchart
6b3f8a7875 pipeline: uvcvideo: Add color space support
Add support for color space to the uvcvideo pipeline handler. UVC
devices have a fixed color space per format, so only the validate()
function needs to be extended to retrieve the color space from the
kernel. There is no need to pass the value back to the driver in
configure().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-01 22:41:01 +03:00
Rishikesh Donadkar
fc9783acc6 gstreamer: Provide colorimetry <> ColorSpace mappings
Provide colorimetry <=> libcamera::ColorSpace mappings via:
- GstVideoColorimetry colorimetry_from_colorspace(colorspace);
- ColorSpace colorspace_from_colorimetry(colorimetry);

Read the colorimetry field from caps into the stream configuration.
After stream validation, the sensor supported colorimetry will
be retrieved and the caps will be updated accordingly.

Colorimetry support for gstlibcamera currently undertakes only one
argument. Multiple colorimetry support shall be introduced in
subsequent commits.

Signed-off-by: Rishikesh Donadkar <rishikeshdonadkar@gmail.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-09-01 16:52:44 +05:30
Umang Jain
4aa71c2cd2 libcamera: color_space: Move color space adjustment to ColorSpace class
The CameraConfiguration::validateColorSpaces() function performs color
space validation on a camera configuration, by validating the color
space of each stream individually, and optionally ensuring that all
streams share the same color space. The individual validation is very
basic, limited to ensuring that raw formats use a raw color space.

Color spaces are more constrained than that:

- The Y'CbCr encoding and quantization range for RGB formats must be
  YcbcrEncoding::None and Range::Full respectively.
- The Y'CbCr encoding for YUV formats must not be YcbcrEncoding::None.

Instead of open-coding these constraints in the validateColorSpaces()
function, create a new ColorSpace::adjust() function to centralize color
space validation and adjustment, and use it in validateColorSpaces().

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-09-01 16:49:59 +05:30
Umang Jain
d09c2bb127 libcamera: colorspace: Rectify the ColorSpace::Srgb preset
Rectify the ColorSpace::Srgb to denote that it does not use
any Y'Cbcr encoding and uses full range.

The kernel on the other hand, recommends to use Rec601 as the encoding
for V4L2_COLORSPACE_SRGB. It is not very explicit but it can be
inferred that the kernel assumes V4L2_COLORSPACE_SRGB is a YUV-encoded
one. However, when the data is in RGB, no encoding is required (and
this is denoted by YcbcrEncoding::None in libcamera).

Hence, to be clear on the libcamera colorspace API, rectify the
ColorSpace::Srgb preset to use YcbcrEncoding::None and full range.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-09-01 16:49:59 +05:30
Umang Jain
e52729e7ec libcamera: v4l2_videodevice: Improve toColorSpace() readability
Wrap V4L2Device::toColorspace() inside a private static member
function in V4L2VideoDevice class. It improves readability in
setting the colorspace for V4L2DeviceFormat.

No functional changes intended.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-09-01 16:49:59 +05:30
Umang Jain
e297673e76 libcamera: v4l2_device: Adjust colorspace based on pixel format
V4L2 has no "none" YCbCr encoding, and thus reports an encoding for all
formats, including RGB and raw formats. This causes the libcamera
ColorSpace to report incorrect encodings for non-YUV formats. Fix it by
overriding the encoding reported by the kernel to YCbCrEncoding::None
for non-YUV pixel formats and media bus formats.

Similarly, override the quantization range of non-YUV formats to full
range, as limited range isn't used for RGB and raw formats.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-09-01 16:49:59 +05:30
Umang Jain
d5ad19bf03 libcamera: v4l2_subdevice: Add color encoding for media bus formats
Store the colour encoding corresponding to a media bus format in the
V4L2SubdeviceFormatInfo structure. This will be used to implement color
space adjustments.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-09-01 16:49:59 +05:30
Umang Jain
5eb7be6a0a libcamera: request: Rename Private::reuse() to Private::reset()
The Request::Private::reuse() is different from Request::reuse().
It resets the members of Request::Private to default values hence,
rename it to a more appropriate Request::Private::reset().

Update the usage and documentation accordingly.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-31 20:51:31 +05:30
Marvin Schmidt
68683d3811 ipa: rkisp1: lsc: Use double instead of float to accumulate vector of doubles
clang-tidy's bugprone-fold-init-type check warns about this:

> ../src/ipa/rkisp1/algorithms/lsc.cpp:61:14: warning: folding type 'double' into type 'float' might result in loss of precision [bugprone-fold-init-type]
>         float sum = std::accumulate(sizes.begin(), sizes.end(), 0.0f);
>                     ^

Fixes: b3e96411d8 ("ipa: rkisp1: Add support of Lens Shading Correction control")
Signed-off-by: Marvin Schmidt <marvin.schmidt1987@gmail.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-30 22:06:20 +03:00
Marvin Schmidt
372621352d ipa: rkisp1: Remove redundant call of std::string::c_str()
The constructor of libcamera::File takes a const reference to a std::string
and clang-tidy's readability-redundant-string-cstr check warns about it:

> ../src/ipa/rkisp1/rkisp1.cpp:147:12: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
>         File file(settings.configurationFile.c_str());
>                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>                   settings.configurationFile

Signed-off-by: Marvin Schmidt <marvin.schmidt1987@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-30 15:26:43 +03:00
Marvin Schmidt
252561e77f ipa: ipu3: Remove redundant call of std::string::c_str()
The constructor of libcamera::File takes a const reference to a std::string
and clang-tidy's readability-redundant-string-cstr check warns about it:

> ../src/ipa/ipu3/ipu3.cpp:330:12: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
>         File file(settings.configurationFile.c_str());
>                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>                   settings.configurationFile

Signed-off-by: Marvin Schmidt <marvin.schmidt1987@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-30 15:26:41 +03:00
Marvin Schmidt
18764a15c7 libcamera: media_device: Fix \sa tags for MediaDevice::link
doxygen didn't create proper links to the overloads of
MediaDevice::link because the signatures didn't match due to an
additional 'const'

While at it remove the unnecessary `MediaDevice::` and wrap the lines

Fixes: b65feafe32 ("libcamera: media_device: Add functions to get a MediaLink")
Signed-off-by: Marvin Schmidt <marvin.schmidt1987@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-30 15:26:04 +03:00
Laurent Pinchart
4267e0bab8 libcamera: pipeline: rkisp1: Implement color space support
Implement color space support in the rkisp1 pipeline handler, in the
configuration generation, configuration validation and camera
configuration. As all the processing related to the color space is
performed in the part of the pipeline shared by all streams, a single
color space must cover all stream configurations. This is enforced
manually when generating the configuration, and with the
validateColorSpaces() helper when validating it.

Only the Y'CbCr encoding and quantization range are currently taken into
account, and they are programmed through the V4L2 color space API. The
primary colors chromaticities and the transfer function need to be
configured in the ISP parameters buffer, and thus conveyed to the IPA,
but the rkisp1 driver does not currently support tone mapping, so this
will be done later.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Florian Sylvestre <fsylvestre@baylibre.com>
2022-08-30 10:26:42 +03:00
Laurent Pinchart
951522c179 cam: Add color space support
Add support for color space to the StreamKeyValueParser, allowing
selection of a color space on the command line.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-26 01:04:27 +03:00
Laurent Pinchart
fbfdaa2d20 libcamera: color_space: Add fromString() function
Add a ColorSpace:fromString() function to parse a string into a color
space. The string can either contain the name of a well-known color
space, or four color space components separate by a '/' character.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-26 01:04:27 +03:00
Laurent Pinchart
994358dab6 libcamera: color_space: Reorder members in the same order as the header
Sort the members of the ColorSpace class in color_space.cpp to match the
color_space.h order. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-26 01:04:27 +03:00
Laurent Pinchart
a17f0eddc6 libcamera: color_space: Rename Jpeg to Sycc
The JPEG color space is badly name, as the JPEG specification (ITU-T
T.81) doesn't define any particular color space:

    The interchange format does not specify a complete coded image
    representation. Application-dependent information, e.g. colour
    space, is outside the scope of this Specification.

The JFIF specification (ITU-T T.871) is clearer as it requires ITU-R
BT.601 YCbCr encoding and a full quantization range:

  The interpretations of Y, CB, and CR are derived from the E'Y, E'Cb,
  and E'Cr signals defined in the 625-line specification of Rec. ITU-R
  BT.601, but these signals are normalized so as to permit the usage of
  the full range of 256 levels of the 8-bit binary encoding of the Y
  component.

It however doesn't specify color primaries or a transfer function
explicitly. It only mentions the latter when describing the conversion
from YCbCr to RGB:

  The inverse relationship for computing full scale 8-bit per colour
  channel gamma pre-corrected RGB values (following Rec. ITU-R BT.601
  gamma pre-correction and colour primary specifications) from YCbCr
  colours (with 256 levels per component) can be computed as follows:
  [...]

Given that ITU-R BT.601-5 (1995) didn't specify color primaries or a
transfer function, and that the later ITU-R BT.601-7 (2011) version
specifies color primaries for the 625-line variant that do not match
sRGB, the JPEG color space in libcamera is badly named. This is
confirmed by ITU-T T.871:

  As this Recommendation | International Standard is based on the prior
  informally-circulated JFIF version 1.02 specification that was
  produced in 1992, which referenced Rec. ITU-R BT.601 (formerly CCIR
  601), it references that specification for definition of the E'Y,
  E'Cb, and E'Cr signals that correspond to the YCBCR values specified
  herein. However, since the development of the prior JFIF version 1.02
  specification, additional industry specifications have been developed,
  Rec. ITU-R BT.601 has been updated, and common industry practice has
  emerged which often follows the sYCC specification in IEC
  61966-2-1/Amd.1. The difference between the use of the colour
  interpretation specification in this Recommendation | International
  Standard and that of the sYCC specification may be considered
  negligible in practice.

Rename the color space to sYCC, as its definition matches the sYCC
standard, and indicate that it is typically used to encode JPEG images.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-25 20:12:54 +03:00
Han-Lin Chen via libcamera-devel
ba72e4202f libcamera: ipu3: Use std::max() instead of expandTo() to get the max resolution
Using Size::expandTo() to find the max resolution might generate a non-existent
resolution. For example, when application request streams for 1920x1080 and
1600x1200, the max resolution will be wrongly 1920x1200 and fails the
configuration.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=139
Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-25 14:04:59 +02:00
Christian Rauch via libcamera-devel
45c198da63 libcamera: Use const reference for range loops
Use a const reference in range-based for loops to avoid copies of the
loop elements.

While at it, change looping over controls in
PipelineHandlerUVC::processControls to use structured bindings.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-25 14:03:22 +02:00
Laurent Pinchart
868ab2287d gstreamer: Add support for additional RGB formats
libcamerasrc only supports three RGB formats. Adding the other RGB
formats supported by libcamera is trivial, do so.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-24 21:18:49 +03:00
Florian Sylvestre
6c6289ee18 ipa: rkisp1: Add support of Denoise Pre-Filter control
The denoise pre-filter algorithm is a bilateral filter which combines a range
filter and a domain filter. The denoise pre-filter is applied before
demosaicing.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-21 21:50:12 +03:00
Florian Sylvestre
6d20a93177 ipa: rkisp1: Add enable field for LSC algorithm in IPA context
Add an enable variable in the lsc struct in IPASessionConfiguration
which indicates if the LSC hardware module is enabled. This will allow
other algorithms to retrieve this information.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-21 21:50:12 +03:00
Florian Sylvestre
ea549c46d3 ipa: rkisp1: Add enable field for AWB algorithm in IPA context
Add an enable variable in the awb struct in IPASessionConfiguration
which indicates if the AWB hardware module is enabled. This will allow
other algorithms to retrieve this information.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-21 21:50:12 +03:00
Laurent Pinchart
acf7213230 libcamera: yaml_parser: De-duplicate common code in YamlObject::get()
The specializations of the YamlObject::get() function template for
integer types duplicate code that doesn't directly depend on the
template type argument. Move it to separate helper functions to reduce
the object size.

While at it, rephrase the comment about unsigned integer parsing.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-21 21:50:10 +03:00
Laurent Pinchart
a69958fcd6 libcamera: yaml_parser: Enable YamlObject::get() for int8_t and uint8_t
The YamlObject::get() function template is implemented for 16-bit and
32-bit integers. Add an 8-bit specialization that will be used in the
rkisp1 IPA module, and extend the unit tests accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-21 21:47:19 +03:00
Laurent Pinchart
dc688f1d88 libcamera: yaml_parser: Fix bounds checking for 16-bit YamlObject::get()
The YamlObject::get() function specializations for 16-bit integers cast
the return value of strto(u)l() to a 16-bit integer, rendering the
bounds checking useless. Fix them.

Fixes: c7d260c03a ("libcamera: yaml_parser: Add get() specializations for 16-bit integers")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-21 21:47:18 +03:00
Christian Rauch
fa388da4f0 libcamera: pipeline: rkisp1: Remove unused assignment
The variable 'ret' is assigned but not read until after the next
assignment.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-21 20:45:29 +03:00
Christian Rauch
90a0df100c libcamera: Remove unused headers
These headers are not used as reported by clangd.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-21 20:45:28 +03:00
Umang Jain
f094c2922a libcamera: v4l2: Set colorspace flags
The colorspace fields are read-only from an application point of view,
both on video devices and on subdevs, unless the
V4L2_PIX_FMT_FLAG_SET_CSC or V4L2_MBUS_FRAMEFMT_SET_CSC flags
(respectively) are set when calling the S_FMT ioctl.

Set the flags accordingly within the V4L2SubDevice and V4L2Device when
a colorspace is being set by the application.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-20 11:35:35 +05:30
Paul Elder
3200bb635c ipa: rkisp1: Add manual color gains
Add support for manually controlling the color gains on the rkisp1 IPA.
To that end, add and plumb the AwbEnable and ColourGains controls. As
per-frame controls aren't supported yet in the rkisp1 IPA, simply apply
and perform checks on the controls immediately.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 18:14:16 +03:00