[libcamera-devel] [PATCH 3/5] libcamera: Rename ImageFormats
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Sat Jun 6 01:20:13 CEST 2020
Hi Jacopo,
Thank you for the patch.
On Fri, May 29, 2020 at 01:03:33PM +0200, Jacopo Mondi wrote:
> The ImageFormats class is actually a map. Convey that in the class name.
It's a hybrid of a map with extra random features. That's partly why I
don't like it. I don't see much value in a rename.
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
> ---
> include/libcamera/internal/camera_sensor.h | 2 +-
> include/libcamera/internal/formats.h | 2 +-
> include/libcamera/internal/v4l2_subdevice.h | 2 +-
> include/libcamera/internal/v4l2_videodevice.h | 2 +-
> src/libcamera/formats.cpp | 32 +++++++++----------
> .../pipeline/raspberrypi/raspberrypi.cpp | 10 +++---
> src/libcamera/pipeline/simple/simple.cpp | 2 +-
> src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 2 +-
> src/libcamera/v4l2_subdevice.cpp | 4 +--
> src/libcamera/v4l2_videodevice.cpp | 4 +--
> test/v4l2_subdevice/list_formats.cpp | 2 +-
> 11 files changed, 32 insertions(+), 32 deletions(-)
>
> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> index 5c1d5789fe79..52eedb9ef880 100644
> --- a/include/libcamera/internal/camera_sensor.h
> +++ b/include/libcamera/internal/camera_sensor.h
> @@ -75,7 +75,7 @@ private:
>
> std::string model_;
>
> - ImageFormats<uint32_t> formats_;
> + ImageFormatsMap<uint32_t> formats_;
> Size resolution_;
> std::vector<unsigned int> mbusCodes_;
> std::vector<Size> sizes_;
> diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h
> index e20c031e857f..cc56e256f54c 100644
> --- a/include/libcamera/internal/formats.h
> +++ b/include/libcamera/internal/formats.h
> @@ -19,7 +19,7 @@
> namespace libcamera {
>
> template<typename T>
> -class ImageFormats
> +class ImageFormatsMap
> {
> public:
> using iterator = typename std::map<T, std::vector<SizeRange>>::iterator;
> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
> index 0ce6da48f58a..c9aa3428f93c 100644
> --- a/include/libcamera/internal/v4l2_subdevice.h
> +++ b/include/libcamera/internal/v4l2_subdevice.h
> @@ -51,7 +51,7 @@ public:
> int setSelection(unsigned int pad, unsigned int target,
> Rectangle *rect);
>
> - ImageFormats<uint32_t> formats(unsigned int pad);
> + ImageFormatsMap<uint32_t> formats(unsigned int pad);
>
> int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
> Whence whence = ActiveFormat);
> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
> index de4745982e94..02d101db0b2b 100644
> --- a/include/libcamera/internal/v4l2_videodevice.h
> +++ b/include/libcamera/internal/v4l2_videodevice.h
> @@ -187,7 +187,7 @@ public:
>
> int getFormat(V4L2DeviceFormat *format);
> int setFormat(V4L2DeviceFormat *format);
> - ImageFormats<V4L2PixelFormat> formats(uint32_t code = 0);
> + ImageFormatsMap<V4L2PixelFormat> formats(uint32_t code = 0);
>
> int setSelection(unsigned int target, Rectangle *rect);
>
> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> index a7922077d9c5..3acb6fe6284e 100644
> --- a/src/libcamera/formats.cpp
> +++ b/src/libcamera/formats.cpp
> @@ -21,7 +21,7 @@ namespace libcamera {
> LOG_DEFINE_CATEGORY(Formats)
>
> /**
> - * \class ImageFormats
> + * \class ImageFormatsMap
> * \brief Describe V4L2Device and V4L2SubDevice image formats and associated
> * image resolutions
> *
> @@ -36,62 +36,62 @@ LOG_DEFINE_CATEGORY(Formats)
> */
>
> /**
> - * \typedef ImageFormats::iterator
> + * \typedef ImageFormatsMap::iterator
> * \brief Iterator for the formats map
> */
>
> /**
> - * \typedef ImageFormats::const_iterator
> + * \typedef ImageFormatsMap::const_iterator
> * \brief Const iterator for the formats map
> */
>
> /**
> - * \typedef ImageFormats::value_type
> + * \typedef ImageFormatsMap::value_type
> * \brief Value type of the entries in the formats map
> */
>
> /**
> - * \fn iterator ImageFormats<T>::begin()
> + * \fn iterator ImageFormatsMap<T>::begin()
> * \brief Retrieve an iterator to the first element in the formats map
> * \return An iterator to the first format map
> */
>
> /**
> - * \fn const_iterator ImageFormats<T>::begin() const
> + * \fn const_iterator ImageFormatsMap<T>::begin() const
> * \brief Retrieve an const iterator to the first element in the formats map
> * \return A const iterator to the first format map
> */
>
> /**
> - * \fn iterator ImageFormats<T>::end()
> + * \fn iterator ImageFormatsMap<T>::end()
> * \brief Retrieve an iterator pointing to the past-the-end element in the
> * formats map
> * \return An iterator to the element following the last format
> */
>
> /**
> - * \fn const_iterator ImageFormats<T>::end() const
> + * \fn const_iterator ImageFormatsMap<T>::end() const
> * \brief Retrieve a const iterator pointing to the past-the-end element in the
> * formats map
> * \return A const iterator to the element following the last format
> */
>
> /**
> - * \fn iterator ImageFormats::find(const T format)
> + * \fn iterator ImageFormatsMap::find(const T format)
> * \brief Find an element with key equal to \a format
> * \param[in] format The format to search for
> * \return An iterator to the vector of sizes associated with \a format
> */
>
> /**
> - * \fn const_iterator ImageFormats::find(const T format) const
> + * \fn const_iterator ImageFormatsMap::find(const T format) const
> * \brief Find a const element with key equal to \a format
> * \param[in] format The format to search for
> * \return An const iterator to the vector of sizes associated with \a format
> */
>
> /**
> - * \fn std::pair<iterator, bool> ImageFormats::emplace(Args&&... args)
> + * \fn std::pair<iterator, bool> ImageFormatsMap::emplace(Args&&... args)
> * \brief Insert a new element in the formats map constructed in place with the
> * given \a args
> * \param[in] args The argument pack used to construct the new entry in place
> @@ -100,7 +100,7 @@ LOG_DEFINE_CATEGORY(Formats)
> */
>
> /**
> - * \fn ImageFormats<T>::addFormat(T format, const std::vector<SizeRange> &sizes)
> + * \fn ImageFormatsMap<T>::addFormat(T format, const std::vector<SizeRange> &sizes)
> * \brief Add a format and corresponding sizes to the description
> * \param[in] format Pixel format or media bus code to describe
> * \param[in] sizes List of supported size ranges for the format
> @@ -110,19 +110,19 @@ LOG_DEFINE_CATEGORY(Formats)
> */
>
> /**
> - * \fn ImageFormats<T>::isEmpty() const
> + * \fn ImageFormatsMap<T>::isEmpty() const
> * \brief Check if the list of devices supported formats is empty
> * \return True if the list of supported formats is empty
> */
>
> /**
> - * \fn ImageFormats<T>::formats() const
> + * \fn ImageFormatsMap<T>::formats() const
> * \brief Retrieve a list of all supported image formats
> * \return List of pixel formats or media bus codes
> */
>
> /**
> - * \fn ImageFormats<T>::sizes(T format) const
> + * \fn ImageFormatsMap<T>::sizes(T format) const
> * \brief Retrieve all sizes for a specific format
> * \param[in] format The pixel format or mbus code
> *
> @@ -134,7 +134,7 @@ LOG_DEFINE_CATEGORY(Formats)
> */
>
> /**
> - * \fn ImageFormats<T>::data() const
> + * \fn ImageFormatsMap<T>::data() const
> * \brief Retrieve the map that associates formats to image sizes
> * \return The map that associates formats to image sizes
> */
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index 64364afb3f7e..e0132113b072 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -65,7 +65,7 @@ double scoreFormat(double desired, double actual)
> return score;
> }
>
> -V4L2DeviceFormat findBestMode(ImageFormats<V4L2PixelFormat> &formatsMap, const Size &req)
> +V4L2DeviceFormat findBestMode(ImageFormatsMap<V4L2PixelFormat> &formatsMap, const Size &req)
> {
> double bestScore = 9e9, score;
> V4L2DeviceFormat bestMode = {};
> @@ -424,7 +424,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()
> * Calculate the best sensor mode we can use based on
> * the user request.
> */
> - ImageFormats<V4L2PixelFormat> fmts = data_->unicam_[Unicam::Image].dev()->formats();
> + ImageFormatsMap<V4L2PixelFormat> fmts = data_->unicam_[Unicam::Image].dev()->formats();
> V4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size);
> PixelFormat sensorPixFormat = sensorFormat.fourcc.toPixelFormat();
> if (cfg.size != sensorFormat.size ||
> @@ -478,7 +478,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()
> *
> */
> PixelFormat &cfgPixFmt = config_.at(outSize[i].first).pixelFormat;
> - ImageFormats<V4L2PixelFormat> fmts;
> + ImageFormatsMap<V4L2PixelFormat> fmts;
>
> if (i == maxIndex)
> fmts = data_->isp_[Isp::Output0].dev()->formats();
> @@ -515,7 +515,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
> RPiCameraData *data = cameraData(camera);
> CameraConfiguration *config = new RPiCameraConfiguration(data);
> V4L2DeviceFormat sensorFormat;
> - ImageFormats<V4L2PixelFormat> fmts;
> + ImageFormatsMap<V4L2PixelFormat> fmts;
>
> if (roles.empty())
> return config;
> @@ -602,7 +602,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)
> }
>
> /* First calculate the best sensor mode we can use based on the user request. */
> - ImageFormats<V4L2PixelFormat> fmts = data->unicam_[Unicam::Image].dev()->formats();
> + ImageFormatsMap<V4L2PixelFormat> fmts = data->unicam_[Unicam::Image].dev()->formats();
> V4L2DeviceFormat sensorFormat = findBestMode(fmts, rawStream ? sensorSize : maxSize);
>
> /*
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index f3e03ba60196..62906b560d6a 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -275,7 +275,7 @@ int SimpleCameraData::init()
> return ret;
> }
>
> - ImageFormats<V4L2PixelFormat> videoFormats = video_->formats(format.mbus_code);
> + ImageFormatsMap<V4L2PixelFormat> videoFormats = video_->formats(format.mbus_code);
>
> LOG(SimplePipeline, Debug)
> << "Adding configuration for " << format.size.toString()
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index dbd835f5c5ef..e1b1ae32b821 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -159,7 +159,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera,
> if (roles.empty())
> return config;
>
> - ImageFormats<V4L2PixelFormat> v4l2Formats = data->video_->formats();
> + ImageFormatsMap<V4L2PixelFormat> v4l2Formats = data->video_->formats();
> std::map<PixelFormat, std::vector<SizeRange>> deviceFormats;
> std::transform(v4l2Formats.begin(), v4l2Formats.end(),
> std::inserter(deviceFormats, deviceFormats.begin()),
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 9fa20e84a904..80db4cda82bb 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -320,9 +320,9 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
> *
> * \return A list of the supported device formats
> */
> -ImageFormats<uint32_t> V4L2Subdevice::formats(unsigned int pad)
> +ImageFormatsMap<uint32_t> V4L2Subdevice::formats(unsigned int pad)
> {
> - ImageFormats<uint32_t> formats;
> + ImageFormatsMap<uint32_t> formats;
>
> if (pad >= entity_->pads().size()) {
> LOG(V4L2, Error) << "Invalid pad: " << pad;
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index ea952444e0ad..b264915cb73a 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -925,9 +925,9 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)
> *
> * \return A list of the supported video device formats
> */
> -ImageFormats<V4L2PixelFormat> V4L2VideoDevice::formats(uint32_t code)
> +ImageFormatsMap<V4L2PixelFormat> V4L2VideoDevice::formats(uint32_t code)
> {
> - ImageFormats<V4L2PixelFormat> formats;
> + ImageFormatsMap<V4L2PixelFormat> formats;
>
> for (V4L2PixelFormat pixelFormat : enumPixelformats(code)) {
> std::vector<SizeRange> sizes = enumSizes(pixelFormat);
> diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp
> index f66bb633fb00..adcf5606c961 100644
> --- a/test/v4l2_subdevice/list_formats.cpp
> +++ b/test/v4l2_subdevice/list_formats.cpp
> @@ -48,7 +48,7 @@ void ListFormatsTest::printFormats(unsigned int pad,
> int ListFormatsTest::run()
> {
> /* List all formats available on existing "Scaler" pads. */
> - ImageFormats<uint32_t> formats;
> + ImageFormatsMap<uint32_t> formats;
>
> formats = scaler_->formats(0);
> if (formats.isEmpty()) {
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list