Le 2014-05-19 03:34, Anton Khirnov a écrit :
+double av_display_rotation_get(const int32_t matrix[9])
+{
+    double rotationf, scale[2];
+
+    scale[0] = sqrt(CONV_FP(matrix[0]) * CONV_FP(matrix[0]) +
+                    CONV_FP(matrix[3]) * CONV_FP(matrix[3]));
+    scale[1] = sqrt(CONV_FP(matrix[1]) * CONV_FP(matrix[1]) +
+                    CONV_FP(matrix[4]) * CONV_FP(matrix[4]));
+
+    rotationf = atan2(CONV_FP(matrix[1]) / scale[1],
+                      CONV_FP(matrix[0]) / scale[0]) * 180 / M_PI;

Does libav assume that floating point divisions by zero are safe?

+
+    return (int) floor(rotationf);

I think rounding to nearest makes more sense here.

+}
+
+void av_display_rotation_set(int32_t matrix[9], double angle)
+{
+    double radians = angle * M_PI / 180.0f;
+
+    memset(matrix, 0, 9 * sizeof(int32_t));
+
+    matrix[0] = CONV_DB(cos(radians));
+    matrix[1] = CONV_DB(-sin(radians));
+    matrix[3] = CONV_DB(sin(radians));
+    matrix[4] = CONV_DB(cos(radians));

I am not sure the compiler is able to optimize this properly. I would cache the cosine and sine value in intermediate variables.

+    matrix[8] = 1 << 30;
+}

--
Rémi Denis-Courmont
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to