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>
This commit is contained in:
@@ -317,17 +317,6 @@ std::size_t CameraConfiguration::size() const
|
||||
return config_.size();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool isRaw(const PixelFormat &pixFmt)
|
||||
{
|
||||
const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
|
||||
return info.isValid() &&
|
||||
info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/**
|
||||
* \enum CameraConfiguration::ColorSpaceFlag
|
||||
* \brief Specify the behaviour of validateColorSpaces
|
||||
@@ -368,29 +357,31 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF
|
||||
Status status = Valid;
|
||||
|
||||
/*
|
||||
* Set all raw streams to the Raw color space, and make a note of the largest
|
||||
* non-raw stream with a defined color space (if there is one).
|
||||
* Set all raw streams to the Raw color space, and make a note of the
|
||||
* largest non-raw stream with a defined color space (if there is one).
|
||||
*/
|
||||
int index = -1;
|
||||
std::optional<ColorSpace> colorSpace;
|
||||
|
||||
for (auto [i, cfg] : utils::enumerate(config_)) {
|
||||
if (isRaw(cfg.pixelFormat)) {
|
||||
if (cfg.colorSpace != ColorSpace::Raw) {
|
||||
cfg.colorSpace = ColorSpace::Raw;
|
||||
status = Adjusted;
|
||||
}
|
||||
} else if (cfg.colorSpace && (index == -1 || cfg.size > config_[i].size)) {
|
||||
index = i;
|
||||
}
|
||||
if (!cfg.colorSpace)
|
||||
continue;
|
||||
|
||||
if (cfg.colorSpace->adjust(cfg.pixelFormat))
|
||||
status = Adjusted;
|
||||
|
||||
if (cfg.colorSpace != ColorSpace::Raw &&
|
||||
(!colorSpace || cfg.size > config_[i].size))
|
||||
colorSpace = cfg.colorSpace;
|
||||
}
|
||||
|
||||
if (index < 0 || !(flags & ColorSpaceFlag::StreamsShareColorSpace))
|
||||
if (!colorSpace || !(flags & ColorSpaceFlag::StreamsShareColorSpace))
|
||||
return status;
|
||||
|
||||
/* Make all output color spaces the same, if requested. */
|
||||
for (auto &cfg : config_) {
|
||||
if (!isRaw(cfg.pixelFormat) &&
|
||||
cfg.colorSpace != config_[index].colorSpace) {
|
||||
cfg.colorSpace = config_[index].colorSpace;
|
||||
if (cfg.colorSpace != ColorSpace::Raw &&
|
||||
cfg.colorSpace != colorSpace) {
|
||||
cfg.colorSpace = colorSpace;
|
||||
status = Adjusted;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user