[PATCH 1/2] qcam: rotate the viewfinder output as per camera properties

Joel Selvaraj joelselvaraj.oss at gmail.com
Fri Jun 21 14:04:46 CEST 2024


Hi Jacopo Mondi,

On 6/21/24 03:27, Jacopo Mondi wrote:
>> diff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp
>> index 47fd6a32..7afb37a8 100644
>> --- a/src/libcamera/orientation.cpp
>> +++ b/src/libcamera/orientation.cpp
>> @@ -92,6 +92,40 @@ Orientation orientationFromRotation(int angle, bool *success)
>>   	return Orientation::Rotate0;
>>   }
>>
>> +/**
>> + * \brief Return the rotation angle for a given orientation
> 
> I'm a bit unconfortable about having this in the API, as it might
> result in something more complex than what it actually looks like.
> 
> All the 2d plane transforms expressed by Orientation include
> an optional horizontal flip, something that cannot be expressed with
> an angular rotation only.
> 
> Look at the example images we have in the Orientation class
> documentation. If you only report the rotation angle (*)
> you won't be able to identify if an image has been flipped or not, and
> the result might not be what you expect.
> 
> (*) Also expressing the rotation angle only is less trivial than what
> one might expect. First of all, if you want to return a rotation
> angle, you have to specify what the rotation describes:
> 
> 1) The image rotation in the memory buffers
> 2) The correction to be applied to display the image in its natural
> orientation
> 
> The Orientation class describes the image rotation in memory buffers,
> so I presume that's what you're expressing here, but it has to be made
> explicit in the documentation of the function. The direction of the
> rotation has to be specified as well. All of this is documented in the
> Orientation class, but if this function is made part of the API, it
> has to be specified here as well.
> 
> I would suggest to infer the rotation angle from Orientation in the
> application and explicitly say that mirroring is not corrected there. 

Right... I was a bit hesitant when I worked on this API. I will remove 
this and infer the angle in the application directly in v2.

Regards,
Joel Selvaraj
>    j
> 
>> + * \param[in] orientation The orientation to convert to a rotation angle
>> + * \param[out] success Set to `true` if the given orientation is valid,
>> + * otherwise `false`
>> + * \return The rotation angle corresponding to the given orientation
>> + * if \a success was set to `true`, otherwise 0.
>> + */
>> +int rotationFromOrientation(const Orientation &orientation, bool *success)
>> +{
>> +	if (success != nullptr)
>> +		*success = true;
>> +
>> +	switch (orientation) {
>> +	case Orientation::Rotate0:
>> +	case Orientation::Rotate0Mirror:
>> +		return 0;
>> +	case Orientation::Rotate90:
>> +	case Orientation::Rotate90Mirror:
>> +		return 90;
>> +	case Orientation::Rotate180:
>> +	case Orientation::Rotate180Mirror:
>> +		return 180;
>> +	case Orientation::Rotate270:
>> +	case Orientation::Rotate270Mirror:
>> +		return 270;
>> +	}
>> +
>> +	if (success != nullptr)
>> +		*success = false;
>> +
>> +	return 0;
>> +}
>> +
>>   /**
>>    * \brief Prints human-friendly names for Orientation items
>>    * \param[in] out The output stream
>> --
>> 2.45.2
>>



More information about the libcamera-devel mailing list