[libcamera-devel] [PATCH v6 0/12] libcamera: Replace CameraConfiguration::transform
Barnabás Pőcze
pobrn at protonmail.com
Fri Nov 3 20:41:44 CET 2023
Hi
2023. október 23., hétfő 0:56 keltezéssel, Laurent Pinchart via libcamera-devel <libcamera-devel at lists.libcamera.org> írta:
> [...]
> I wanted to replace the
>
> Orientation operator*(const Orientation &o, const Transform &t);
>
> with a
>
> Orientation Transform::operator()(const Orientation &o);
>
> in order to be able to write
>
> Transform t = ...;
> Orientation o1 = ...,
> Orientation o2 = t(o1);
>
> or also
>
> Orientation o1 = ...,
> Orientation o2 = Transform::HFlip(o1);
>
> which I think would be a nicer syntax. However, I couldn't find a way to
> nicely do so :-( Transform is currently an enum class, which is not a
> class, and thus can't have member operators. The call operator having no
> non-member (outside of the class definition) variant, I had to try and
> turn Transform into a class. I got stuck at the point where HFlip had to
> be a static constexpr member of the Transform class (to be able to write
> `Transform::HFlip`), but also an instance of the Transform class (to be
> able to write `Transform::HFlip(o)`). The compiler rightfully complained
> that I was trying to use a type that hasn't been fully defined yet. I
> gave up for now (but would be very interested into hearing from a C++
> enthousiast on how something similar could be achieved). If we keep the
> multiplication operator as-is, then your patch 06/12 that inverts the
> order of the operands to the multiplication operator between two
> Transform instances is needed.
> [...]
I believe something like the following can work: https://gcc.godbolt.org/z/ecqoGTGGs
It's a lot of code compared to the enum...
On a slightly related note, I think using a pipe is also not bad: "o1 | t1 | t2 | t3 ...".
Regards,
Barnabás Pőcze
More information about the libcamera-devel
mailing list