Revert "dvdspu: render to ARGB overlay instead of AYUV"
authorJan Schmidt <jan@centricular.com>
Sat, 26 Sep 2015 14:24:23 +0000 (00:24 +1000)
committerJan Schmidt <jan@centricular.com>
Sat, 26 Sep 2015 14:26:07 +0000 (00:26 +1000)
This reverts commit dd3e9deb2aa695a391b58f24d86a3c00bbc1258a.

gst/dvdspu/gstdvdspu.c
gst/dvdspu/gstspu-common.h
gst/dvdspu/gstspu-pgs.c
gst/dvdspu/gstspu-vobsub-render.c

index 2bf5a91..83cb521 100644 (file)
@@ -716,7 +716,7 @@ gstspu_render_composition (GstDVDSpu * dvdspu)
   gint spu_w, spu_h;
   gsize size;
 
-  format = GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB;
+  format = GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV;
 
   switch (dvdspu->spu_input_type) {
     case SPU_INPUT_TYPE_PGS:
index 1618384..3107f29 100644 (file)
@@ -39,12 +39,19 @@ struct SpuRect {
   gint16 bottom;
 };
 
-/* Store a pre-multiplied ARGB colour value */
+/* Store a pre-multiplied YUV colour value */
 struct SpuColour {
-  guint8 B;
-  guint8 G;
-  guint8 R;
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
   guint8 A;
+  guint8 Y;
+  guint8 U;
+  guint8 V;
+#else
+  guint8 V;
+  guint8 U;
+  guint8 Y;
+  guint8 A;
+#endif
 };
 
 G_END_DECLS
index bf76a11..f35fe93 100644 (file)
@@ -319,9 +319,9 @@ pgs_composition_object_render (PgsCompositionObject * obj, SpuState * state,
           memcpy (pix, colour, sizeof (*pix));
         } else {
           pix->A = colour->A;
-          pix->R = colour->R + pix->R * inv_A / 255;
-          pix->G = colour->G + pix->G * inv_A / 255;
-          pix->B = colour->B + pix->B * inv_A / 255;
+          pix->Y = colour->Y + pix->Y * inv_A / 255;
+          pix->U = colour->U + pix->U * inv_A / 255;
+          pix->V = colour->V + pix->V * inv_A / 255;
         }
       }
     } else {
@@ -511,7 +511,6 @@ parse_set_palette (GstDVDSpu * dvdspu, guint8 type, guint8 * payload,
     state->pgs.palette[i].A = 0;
   for (i = 0; i < n_entries; i++) {
     guint8 n, Y, U, V, A;
-    gint R, G, B;
     n = payload[0];
     Y = payload[1];
     V = payload[2];
@@ -520,26 +519,15 @@ parse_set_palette (GstDVDSpu * dvdspu, guint8 type, guint8 * payload,
 
 #if DUMP_FULL_PALETTE
     PGS_DUMP ("Entry %3d: Y %3d U %3d V %3d A %3d  ", n, Y, U, V, A);
-#endif
-
-    /* Convert to ARGB */
-    R = (298 * Y + 459 * V - 63514) >> 8;
-    G = (298 * Y - 55 * U - 136 * V + 19681) >> 8;
-    B = (298 * Y + 541 * U - 73988) >> 8;
-
-    R = CLAMP (R, 0, 255);
-    G = CLAMP (G, 0, 255);
-    B = CLAMP (B, 0, 255);
-
-#if DUMP_FULL_PALETTE
-    PGS_DUMP ("Entry %3d: A %3d R %3d G %3d B %3d\n", n, A, R, G, B);
+    if (((i + 1) % 2) == 0)
+      PGS_DUMP ("\n");
 #endif
 
     /* Premultiply the palette entries by the alpha */
     state->pgs.palette[n].A = A;
-    state->pgs.palette[n].R = R * A / 255;
-    state->pgs.palette[n].G = G * A / 255;
-    state->pgs.palette[n].B = B * A / 255;
+    state->pgs.palette[n].Y = Y * A / 255;
+    state->pgs.palette[n].U = U * A / 255;
+    state->pgs.palette[n].V = V * A / 255;
 
     payload += PGS_PALETTE_ENTRY_SIZE;
   }
index 583fd32..45dcabb 100644 (file)
@@ -40,42 +40,29 @@ gstspu_vobsub_recalc_palette (GstDVDSpu * dvdspu,
   if (state->vobsub.current_clut[idx[0]] != 0) {
     for (i = 0; i < 4; i++, dest++) {
       guint32 col = state->vobsub.current_clut[idx[i]];
-      gint A, Y, U, V;
-      gint R, G, B;
 
       /* Convert incoming 4-bit alpha to 8 bit for blending */
-      A = (alpha[i] << 4) | alpha[i];
-      Y = ((col >> 16) & 0xff);
+      dest->A = (alpha[i] << 4) | alpha[i];
+      dest->Y = ((col >> 16) & 0xff) * dest->A / 255;
       /* U/V are stored as V/U in the clut words, so switch them */
-      V = ((col >> 8) & 0xff);
-      U = (col & 0xff);
-
-      R = (298 * Y + 459 * V - 63514) >> 8;
-      G = (298 * Y - 55 * U - 136 * V + 19681) >> 8;
-      B = (298 * Y + 541 * U - 73988) >> 8;
-
-      R = CLAMP (R, 0, 255);
-      G = CLAMP (G, 0, 255);
-      B = CLAMP (B, 0, 255);
-
-      dest->A = A;
-      dest->R = R * A / 255;
-      dest->G = G * A / 255;
-      dest->B = B * A / 255;
+      dest->V = ((col >> 8) & 0xff) * dest->A / 255;
+      dest->U = (col & 0xff) * dest->A / 255;
     }
   } else {
-    int c = 255;
+    int y = 240;
 
     /* The CLUT presumably hasn't been set, so we'll just guess some
      * values for the non-transparent colors (white, grey, black) */
     for (i = 0; i < 4; i++, dest++) {
       dest->A = (alpha[i] << 4) | alpha[i];
       if (alpha[i] != 0) {
-        dest->R = dest->G = dest->B = c * dest->A / 255;
-        c -= 128;
-        if (c < 0)
-          c = 0;
+        dest[0].Y = y * dest[0].A / 255;
+        y -= 112;
+        if (y < 0)
+          y = 0;
       }
+      dest[0].U = 128 * dest[0].A / 255;
+      dest[0].V = 128 * dest[0].A / 255;
     }
   }
 }
@@ -186,7 +173,7 @@ gstspu_vobsub_draw_rle_run (SpuState * state, GstVideoFrame * frame,
     gint16 x, gint16 end, SpuColour * colour)
 {
   GST_TRACE ("Y: %d x: %d end %d %d %d %d %d",
-      state->vobsub.cur_Y, x, end, colour->R, colour->G, colour->B, colour->A);
+      state->vobsub.cur_Y, x, end, colour->Y, colour->U, colour->V, colour->A);
 
   if (colour->A > 0) {
     gint i;
@@ -207,9 +194,9 @@ gstspu_vobsub_draw_rle_run (SpuState * state, GstVideoFrame * frame,
         memcpy (pix, colour, sizeof (*pix));
       } else {
         pix->A = colour->A;
-        pix->R = colour->R + pix->R * inv_A / 255;
-        pix->G = colour->G + pix->G * inv_A / 255;
-        pix->B = colour->B + pix->B * inv_A / 255;
+        pix->Y = colour->Y + pix->Y * inv_A / 255;
+        pix->U = colour->U + pix->U * inv_A / 255;
+        pix->V = colour->V + pix->V * inv_A / 255;
       }
     }