summaryrefslogtreecommitdiff
path: root/src/video_out/yuv2rgb_mmx.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_out/yuv2rgb_mmx.c')
-rw-r--r--src/video_out/yuv2rgb_mmx.c154
1 files changed, 80 insertions, 74 deletions
diff --git a/src/video_out/yuv2rgb_mmx.c b/src/video_out/yuv2rgb_mmx.c
index 46db48179..da6114a52 100644
--- a/src/video_out/yuv2rgb_mmx.c
+++ b/src/video_out/yuv2rgb_mmx.c
@@ -31,8 +31,15 @@
#include <string.h>
#include <inttypes.h>
+#ifdef HAVE_FFMPEG_AVUTIL_H
+# include <mem.h>
+#else
+# include <libavutil/mem.h>
+#endif
+
#include "yuv2rgb.h"
-#include "xineutils.h"
+#include <xine/xineutils.h>
+#include "xine_mmx.h"
#define CPU_MMXEXT 0
#define CPU_MMX 1
@@ -50,7 +57,8 @@ do { \
typedef struct mmx_csc_s mmx_csc_t;
struct mmx_csc_s {
- mmx_t subYw;
+ mmx_t x00ffw;
+ mmx_t x0080w;
mmx_t addYw;
mmx_t U_green;
mmx_t U_blue;
@@ -62,42 +70,52 @@ struct mmx_csc_s {
extern const int32_t Inverse_Table_6_9[8][4];
void mmx_yuv2rgb_set_csc_levels(yuv2rgb_factory_t *this,
- int brightness, int contrast, int saturation)
+ int brightness, int contrast, int saturation, int colormatrix)
{
- int a,s,i;
- int crv, cbu, cgu, cgv, cty;
+ int i, cty;
+
+ int yoffset = -16;
+ int ygain = ((1 << 16) * 255) / 219;
+
+ int cm = (colormatrix >> 1) & 7;
+ int crv = Inverse_Table_6_9[cm][0];
+ int cbu = Inverse_Table_6_9[cm][1];
+ int cgu = Inverse_Table_6_9[cm][2];
+ int cgv = Inverse_Table_6_9[cm][3];
+
mmx_csc_t *csc;
/* 'table_mmx' is 64bit aligned for better performance */
if (this->table_mmx == NULL) {
- this->table_mmx = xine_xmalloc_aligned (8, sizeof(mmx_csc_t), &this->table_mmx_base);
+ this->table_mmx = av_mallocz(sizeof(mmx_csc_t));
}
- if( brightness <= 16 ) {
- a = 0;
- s = 16 - brightness;
- } else {
- a = brightness - 16;
- s = 0;
+ /* full range mode */
+ if (colormatrix & 1) {
+ yoffset = 0;
+ ygain = (1 << 16);
+
+ crv = (crv * 112 + 63) / 127;
+ cbu = (cbu * 112 + 63) / 127;
+ cgu = (cgu * 112 + 63) / 127;
+ cgv = (cgv * 112 + 63) / 127;
}
- csc = (mmx_csc_t *) this->table_mmx;
+ yoffset += brightness;
+ /* TV set behaviour: contrast affects color difference as well */
+ saturation = (contrast * saturation + 64) >> 7;
- for( i = 0; i < 8; i++ ) {
- csc->subYw.ub[i] = s;
- csc->addYw.ub[i] = a;
- }
+ csc = (mmx_csc_t *) this->table_mmx;
- crv = Inverse_Table_6_9[this->matrix_coefficients][0];
crv = (crv * saturation + 512) / 1024;
- cbu = Inverse_Table_6_9[this->matrix_coefficients][1];
cbu = (cbu * saturation + 512) / 1024;
cbu = (cbu > 32767) ? 32767 : cbu;
- cgu = Inverse_Table_6_9[this->matrix_coefficients][2];
cgu = (cgu * saturation + 512) / 1024;
- cgv = Inverse_Table_6_9[this->matrix_coefficients][3];
cgv = (cgv * saturation + 512) / 1024;
- cty = (76309 * contrast + 512) / 1024;
+ cty = (ygain * contrast + 512) / 1024;
+
+ /* the 8 is "+0,5" for later rounding */
+ yoffset = ((cty * (yoffset << 7)) >> 16) + 8;
for (i=0; i < 4; i++) {
csc->U_green.w[i] = -cgu;
@@ -105,106 +123,94 @@ void mmx_yuv2rgb_set_csc_levels(yuv2rgb_factory_t *this,
csc->V_red.w[i] = crv;
csc->V_green.w[i] = -cgv;
csc->Y_coeff.w[i] = cty;
+
+ csc->addYw.w[i] = yoffset;
+
+ csc->x0080w.w[i] = 128;
+ csc->x00ffw.w[i] = 0xff;
}
}
static inline void mmx_yuv2rgb (uint8_t * py, uint8_t * pu, uint8_t * pv, mmx_csc_t *csc)
{
- static mmx_t mmx_80w = {0x0080008000800080ULL};
- static mmx_t mmx_00ffw = {0x00ff00ff00ff00ffULL};
+
+ /* OK what we're doing here is
+ y = ((cty * (y << 7)) >> 16) + yoffset;
+ u = (u - 128) << 7;
+ v = (v - 128) << 7;
+ r = (y + ((crv * v) >> 16)) >> 4;
+ g = (y + ((cgu * u) >> 16) + ((cgv * v) >> 16)) >> 4;
+ b = (y + ((cbu * u) >> 16)) >> 4; */
movq_m2r (*py, mm6); // mm6 = Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
pxor_r2r (mm4, mm4); // mm4 = 0
-
- psubusb_m2r (csc->subYw, mm6); // Y -= 16
- paddusb_m2r (csc->addYw, mm6);
-
movd_m2r (*pu, mm0); // mm0 = 00 00 00 00 u3 u2 u1 u0
+
movq_r2r (mm6, mm7); // mm7 = Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
+ pand_m2r (csc->x00ffw, mm6); // mm6 = Y6 Y4 Y2 Y0
- pand_m2r (mmx_00ffw, mm6); // mm6 = Y6 Y4 Y2 Y0
psrlw_i2r (8, mm7); // mm7 = Y7 Y5 Y3 Y1
-
+ psllw_i2r (7, mm6); // promote precision
movd_m2r (*pv, mm1); // mm1 = 00 00 00 00 v3 v2 v1 v0
- psllw_i2r (3, mm6); // promote precision
pmulhw_m2r (csc->Y_coeff, mm6); // mm6 = luma_rgb even
- psllw_i2r (3, mm7); // promote precision
-
+ psllw_i2r (7, mm7); // promote precision
punpcklbw_r2r (mm4, mm0); // mm0 = u3 u2 u1 u0
- psubsw_m2r (mmx_80w, mm0); // u -= 128
+ paddsw_m2r (csc->addYw, mm6); // += yoffset
+ psubsw_m2r (csc->x0080w, mm0); // u -= 128
punpcklbw_r2r (mm4, mm1); // mm1 = v3 v2 v1 v0
-
pmulhw_m2r (csc->Y_coeff, mm7); // mm7 = luma_rgb odd
- psllw_i2r (3, mm0); // promote precision
- psubsw_m2r (mmx_80w, mm1); // v -= 128
- movq_r2r (mm0, mm2); // mm2 = u3 u2 u1 u0
+ psllw_i2r (7, mm0); // promote precision
+ psubsw_m2r (csc->x0080w, mm1); // v -= 128
- psllw_i2r (3, mm1); // promote precision
+ movq_r2r (mm0, mm2); // mm2 = u3 u2 u1 u0
+ psllw_i2r (7, mm1); // promote precision
movq_r2r (mm1, mm4); // mm4 = v3 v2 v1 v0
- pmulhw_m2r (csc->U_blue, mm0); // mm0 = chroma_b
-
-
- // slot
-
-
- // slot
-
-
+ paddsw_m2r (csc->addYw, mm7); // += yoffset
+ pmulhw_m2r (csc->U_blue, mm0); // mm0 = chroma_b
pmulhw_m2r (csc->V_red, mm1); // mm1 = chroma_r
+
movq_r2r (mm0, mm3); // mm3 = chroma_b
paddsw_r2r (mm6, mm0); // mm0 = B6 B4 B2 B0
paddsw_r2r (mm7, mm3); // mm3 = B7 B5 B3 B1
- packuswb_r2r (mm0, mm0); // saturate to 0-255
-
-
+ psraw_i2r (4, mm0); // div round
pmulhw_m2r (csc->U_green, mm2); // mm2 = u * u_green
+ psraw_i2r (4, mm3); // div round
-
+ packuswb_r2r (mm0, mm0); // saturate to 0-255
packuswb_r2r (mm3, mm3); // saturate to 0-255
-
-
- punpcklbw_r2r (mm3, mm0); // mm0 = B7 B6 B5 B4 B3 B2 B1 B0
-
-
pmulhw_m2r (csc->V_green, mm4); // mm4 = v * v_green
-
- // slot
-
-
- // slot
-
-
+ punpcklbw_r2r (mm3, mm0); // mm0 = B7 B6 B5 B4 B3 B2 B1 B0
paddsw_r2r (mm4, mm2); // mm2 = chroma_g
- movq_r2r (mm2, mm5); // mm5 = chroma_g
+ movq_r2r (mm1, mm4); // mm4 = chroma_r
+ movq_r2r (mm2, mm5); // mm5 = chroma_g
- movq_r2r (mm1, mm4); // mm4 = chroma_r
paddsw_r2r (mm6, mm2); // mm2 = G6 G4 G2 G0
-
- packuswb_r2r (mm2, mm2); // saturate to 0-255
+ psraw_i2r (4, mm2); // div round
paddsw_r2r (mm6, mm1); // mm1 = R6 R4 R2 R0
- packuswb_r2r (mm1, mm1); // saturate to 0-255
+ packuswb_r2r (mm2, mm2); // saturate to 0-255
+ psraw_i2r (4, mm1); // div round
paddsw_r2r (mm7, mm4); // mm4 = R7 R5 R3 R1
- packuswb_r2r (mm4, mm4); // saturate to 0-255
+ packuswb_r2r (mm1, mm1); // saturate to 0-255
+ psraw_i2r (4, mm4); // div round
paddsw_r2r (mm7, mm5); // mm5 = G7 G5 G3 G1
-
- packuswb_r2r (mm5, mm5); // saturate to 0-255
-
+ packuswb_r2r (mm4, mm4); // saturate to 0-255
+ psraw_i2r (4, mm5); // div round
punpcklbw_r2r (mm4, mm1); // mm1 = R7 R6 R5 R4 R3 R2 R1 R0
-
+ packuswb_r2r (mm5, mm5); // saturate to 0-255
punpcklbw_r2r (mm5, mm2); // mm2 = G7 G6 G5 G4 G3 G2 G1 G0
}