Commit fd8b1414 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

es_format: fix warnings and simplify

parent 6ce87411
...@@ -178,7 +178,7 @@ typedef enum video_orientation_t ...@@ -178,7 +178,7 @@ typedef enum video_orientation_t
typedef enum video_transform_t typedef enum video_transform_t
{ {
TRANSFORM_IDENTIY = ORIENT_NORMAL, TRANSFORM_IDENTITY = ORIENT_NORMAL,
TRANSFORM_HFLIP = ORIENT_HFLIPPED, TRANSFORM_HFLIP = ORIENT_HFLIPPED,
TRANSFORM_VFLIP = ORIENT_VFLIPPED, TRANSFORM_VFLIP = ORIENT_VFLIPPED,
TRANSFORM_R180 = ORIENT_ROTATED_180, TRANSFORM_R180 = ORIENT_ROTATED_180,
......
...@@ -245,45 +245,37 @@ void video_format_ScaleCropAr( video_format_t *p_dst, const video_format_t *p_sr ...@@ -245,45 +245,37 @@ void video_format_ScaleCropAr( video_format_t *p_dst, const video_format_t *p_sr
} }
//Simplify transforms to have something more managable. Order: angle, hflip. //Simplify transforms to have something more managable. Order: angle, hflip.
void transform_GetBasicOps( video_transform_t transform, int *angle, int *hflip ) { static void transform_GetBasicOps( video_transform_t transform,
unsigned *restrict angle,
*angle = 0; bool *restrict hflip )
*hflip = 0; {
*hflip = ORIENT_IS_MIRROR(transform);
switch ( transform ) {
switch ( transform )
{
case TRANSFORM_R90: case TRANSFORM_R90:
case TRANSFORM_TRANSPOSE:
*angle = 90; *angle = 90;
break; break;
case TRANSFORM_R180: case TRANSFORM_R180:
case TRANSFORM_VFLIP:
*angle = 180; *angle = 180;
break; break;
case TRANSFORM_R270: case TRANSFORM_R270:
case TRANSFORM_ANTI_TRANSPOSE:
*angle = 270; *angle = 270;
break; break;
case TRANSFORM_HFLIP: case TRANSFORM_HFLIP:
*hflip = 1; case TRANSFORM_IDENTITY:
break; *angle = 0;
case TRANSFORM_VFLIP:
*angle = 180;
*hflip = 1;
break;
case TRANSFORM_TRANSPOSE:
*angle = 90;
*hflip = 1;
break;
case TRANSFORM_ANTI_TRANSPOSE:
*angle = 270;
*hflip = 1;
break; break;
} }
} }
video_transform_t transform_FromBasicOps( int angle, int hflip ) static video_transform_t transform_FromBasicOps( unsigned angle, bool hflip )
{ {
switch ( angle ) { switch ( angle )
case 0: {
return hflip ? TRANSFORM_HFLIP : TRANSFORM_IDENTIY;
case 90: case 90:
return hflip ? TRANSFORM_TRANSPOSE : TRANSFORM_R90; return hflip ? TRANSFORM_TRANSPOSE : TRANSFORM_R90;
case 180: case 180:
...@@ -291,24 +283,22 @@ video_transform_t transform_FromBasicOps( int angle, int hflip ) ...@@ -291,24 +283,22 @@ video_transform_t transform_FromBasicOps( int angle, int hflip )
case 270: case 270:
return hflip ? TRANSFORM_ANTI_TRANSPOSE : TRANSFORM_R270; return hflip ? TRANSFORM_ANTI_TRANSPOSE : TRANSFORM_R270;
default: default:
return TRANSFORM_IDENTIY; return hflip ? TRANSFORM_HFLIP : TRANSFORM_IDENTITY;
} }
} }
video_transform_t video_format_GetTransform( video_orientation_t src, video_orientation_t dst ) video_transform_t video_format_GetTransform( video_orientation_t src,
video_orientation_t dst )
{ {
int angle1 = 0; unsigned angle1, angle2;
int hflip1 = 0; bool hflip1, hflip2;
transform_GetBasicOps( (video_transform_t)src, &angle1, &hflip1 ); transform_GetBasicOps( (video_transform_t)src, &angle1, &hflip1 );
transform_GetBasicOps( transform_Inverse( (video_transform_t)dst ),
int angle2 = 0; &angle2, &hflip2 );
int hflip2 = 0;
transform_GetBasicOps( transform_Inverse( (video_transform_t)dst ), &angle2, &hflip2 );
int angle = (angle1 + angle2) % 360; int angle = (angle1 + angle2) % 360;
int hflip = (hflip1 + hflip2) % 2; bool hflip = hflip1 ^ hflip2;
return transform_FromBasicOps(angle, hflip); return transform_FromBasicOps(angle, hflip);
} }
...@@ -323,19 +313,14 @@ void video_format_TransformTo( video_format_t *fmt, video_orientation_t dst_orie ...@@ -323,19 +313,14 @@ void video_format_TransformTo( video_format_t *fmt, video_orientation_t dst_orie
void video_format_TransformBy( video_format_t *fmt, video_transform_t transform ) void video_format_TransformBy( video_format_t *fmt, video_transform_t transform )
{ {
/* Get destination orientation */ /* Get destination orientation */
unsigned angle1, angle2;
int angle1 = 0; bool hflip1, hflip2;
int hflip1 = 0;
transform_GetBasicOps( transform, &angle1, &hflip1 ); transform_GetBasicOps( transform, &angle1, &hflip1 );
transform_GetBasicOps( (video_transform_t)fmt->orientation, &angle2, &hflip2 );
int angle2 = 0; unsigned angle = (angle2 - angle1 + 360) % 360;
int hflip2 = 0; bool hflip = hflip2 ^ hflip1;
transform_GetBasicOps( (video_transform_t)( fmt->orientation ), &angle2, &hflip2 );
int angle = (angle2 - angle1 + 360) % 360;
int hflip = (hflip2 - hflip1 + 2) % 2;
video_orientation_t dst_orient = ORIENT_NORMAL; video_orientation_t dst_orient = ORIENT_NORMAL;
...@@ -379,6 +364,8 @@ void video_format_TransformBy( video_format_t *fmt, video_transform_t transform ...@@ -379,6 +364,8 @@ void video_format_TransformBy( video_format_t *fmt, video_transform_t transform
switch ( transform ) switch ( transform )
{ {
case TRANSFORM_IDENTITY:
break;
case TRANSFORM_R90: case TRANSFORM_R90:
fmt->i_x_offset = delta_y; fmt->i_x_offset = delta_y;
fmt->i_y_offset = scratch.i_x_offset; fmt->i_y_offset = scratch.i_x_offset;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment