]> git.sesse.net Git - vlc/blobdiff - src/video_parser/vpar_blocks.c
The motion compensation routines are now modules as well ; choose your
[vlc] / src / video_parser / vpar_blocks.c
index dfc6fc85c90b576be8215e40166869a242e85cd9..12d0bbf9565ef3710d2748563f56bdaf80dfcce3 100644 (file)
@@ -1,41 +1,58 @@
 /*****************************************************************************
  * vpar_blocks.c : blocks parsing
- * (c)1999 VideoLAN
+ *****************************************************************************
+ * Copyright (C) 1999, 2000 VideoLAN
+ * $Id: vpar_blocks.c,v 1.72 2001/01/18 05:13:23 sam Exp $
+ *
+ * Authors: Christophe Massiot <massiot@via.ecp.fr>
+ *          Jean-Marc Dressler <polux@via.ecp.fr>
+ *          Stéphane Borel <stef@via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/uio.h>
+#include "defs.h"
+
+#include <string.h>                                                /* memset */
 
 #include "config.h"
 #include "common.h"
+#include "threads.h"
 #include "mtime.h"
-#include "vlc_thread.h"
+#include "plugins.h"
 
 #include "intf_msg.h"
-#include "debug.h"                    /* ?? temporaire, requis par netlist.h */
 
-#include "input.h"
-#include "input_netlist.h"
-#include "decoder_fifo.h"
+#include "stream_control.h"
+#include "input_ext-dec.h"
+
 #include "video.h"
 #include "video_output.h"
 
-#include "vdec_idct.h"
 #include "video_decoder.h"
 #include "vdec_motion.h"
+#include "../video_decoder/vdec_idct.h"
 
 #include "vpar_blocks.h"
-#include "vpar_headers.h"
-#include "vpar_synchro.h"
-#include "video_parser.h"
-#include "video_fifo.h"
+#include "../video_decoder/vpar_headers.h"
+#include "../video_decoder/vpar_synchro.h"
+#include "../video_decoder/video_parser.h"
+#include "../video_decoder/video_fifo.h"
 
 /*
  * Welcome to vpar_blocks.c ! Here's where the heavy processor-critical parsing
@@ -54,7 +71,7 @@
  */
 
     /* Table for coded_block_pattern resolution */
-static lookup_t     pl_coded_pattern[512] = 
+static lookup_t     pl_coded_pattern[512] =
     { {MB_ERROR, 0}, {0, 9}, {39, 9}, {27, 9}, {59, 9}, {55, 9}, {47, 9}, {31, 9},
     {58, 8}, {58, 8}, {54, 8}, {54, 8}, {46, 8}, {46, 8}, {30, 8}, {30, 8},
     {57, 8}, {57, 8}, {53, 8}, {53, 8}, {45, 8}, {45, 8}, {29, 8}, {29, 8},
@@ -64,67 +81,68 @@ static lookup_t     pl_coded_pattern[512] =
     {41, 8}, {41, 8}, {21, 8}, {21, 8}, {49, 8}, {49, 8}, {13, 8}, {13, 8},
     {35, 8}, {35, 8}, {19, 8}, {19, 8}, {11, 8}, {11, 8}, {7, 8}, {7, 8},
     {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
-    {10, 7}, {10, 7}, {10, 7}, {10, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7}, 
-    {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, 
-    {9, 7}, {9, 7}, {9, 7}, {9, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, 
-    {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, 
-    {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, 
-    {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, 
-    {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, 
+    {10, 7}, {10, 7}, {10, 7}, {10, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7},
+    {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
+    {9, 7}, {9, 7}, {9, 7}, {9, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7},
+    {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6},
+    {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6},
+    {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6},
+    {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6},
     {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
     {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
-    {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, 
-    {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, 
-    {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, 
-    {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, 
-    {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, 
-    {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, 
-    {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, 
-    {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, 
-    {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, 
-    {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, 
-    {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, 
-    {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, 
-    {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, 
-    {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, 
-    {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, 
-    {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, 
-    {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, 
-    {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, 
-    {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, 
-    {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, 
-    {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, 
-    {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, 
-    {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, 
-    {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, 
-    {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, 
-    {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, 
-    {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, 
-    {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, 
-    {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, 
-    {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, 
-    {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, 
-    {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, 
-    {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, 
+    {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5},
+    {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5},
+    {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5},
+    {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5},
+    {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5},
+    {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5},
+    {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5},
+    {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5},
+    {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5},
+    {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5},
+    {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5},
+    {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5},
+    {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5},
+    {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5},
+    {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5},
+    {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5},
+    {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5},
+    {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5},
+    {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5},
+    {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5},
+    {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
+    {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
+    {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
+    {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
+    {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
+    {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
+    {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
+    {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
+    {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
+    {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
+    {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
     {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
+    {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
+    {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
+    {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
+    {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
     {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
-    {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, 
-    {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, 
     {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
-    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
-    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
-    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
-    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
-    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
-    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
-    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
+    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
+    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
+    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
+    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
+    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
+    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
+    {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3} };
 
-    /* Tables for dc DCT coefficients 
+    /* Tables for dc DCT coefficients
      * Tables are cut in two parts to reduce memory occupation
      */
-    
-    /* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */
+
+    /* Table B-12, dct_dc_size_luminance, codes 00XXX ... 11110 */
+
 static lookup_t     pl_dct_dc_lum_init_table_1[32] =
     { {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
       {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
@@ -132,7 +150,20 @@ static lookup_t     pl_dct_dc_lum_init_table_1[32] =
       {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {MB_ERROR, 0}
     };
 
+static lookup_t     ppl_dct_dc_init_table_1[2][32] =
+{    { {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
+      {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
+      {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
+      {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {MB_ERROR, 0}},
+{ {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
+      {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
+      {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
+      {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {MB_ERROR, 0}
+    }
+    };
+
     /* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */
+
 static lookup_t     pl_dct_dc_lum_init_table_2[32] =
     { {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
       {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10,9}, {11,9},
@@ -142,22 +173,37 @@ static lookup_t     pl_dct_dc_lum_init_table_2[32] =
       {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}
     };
 
+static lookup_t     ppl_dct_dc_init_table_2[2][32] =
+{    { {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
+      {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10,9}, {11,9},
+      {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
+      {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
+      {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
+      {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}},
+    { {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
+      {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
+      {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
+      {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10}
+    }
+    };
+
     /* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */
 static lookup_t     pl_dct_dc_chrom_init_table_1[32] =
   { {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
+ { {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
       {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
       {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
       {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {MB_ERROR, 0}
     };
+    
 
-    /* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */
+   /* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */
 static lookup_t     pl_dct_dc_chrom_init_table_2[32] =
     { {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
       {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
       {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
       {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10}
     };
-    
 
     /* Tables for ac DCT coefficients. There are cut in many parts to save space */
     /* Table B-14, DCT coefficients table zero,
@@ -346,6 +392,15 @@ static dct_lookup_t pl_DCT_tab6[16] =
         {30,1,16}, {29,1,16}, {28,1,16}, {27,1,16}
     };
 
+    /* Pointers on tables of dct coefficients */
+static dct_lookup_t * ppl_dct_tab1[2] = { pl_DCT_tab_ac, pl_DCT_tab0a };
+
+static dct_lookup_t * ppl_dct_tab2[2] = { pl_DCT_tab_ac, pl_DCT_tab_dc };
+
+
+    /* Lookup Table for the chromatic component */
+static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
+
 
 /*
  * Initialization of lookup tables
@@ -382,8 +437,8 @@ void vpar_InitCrop( vpar_thread_t * p_vpar )
  *****************************************************************************/
 
 /* Function for filling up the lookup table for mb_addr_inc */
-static void __inline__ FillMbAddrIncTable( vpar_thread_t * p_vpar,
-                                    int i_start, int i_end, int i_step, 
+static void FillMbAddrIncTable( vpar_thread_t * p_vpar,
+                                    int i_start, int i_end, int i_step,
                                     int * pi_value, int i_length )
 {
     int i_pos, i_offset;
@@ -397,13 +452,13 @@ static void __inline__ FillMbAddrIncTable( vpar_thread_t * p_vpar,
         (*pi_value)--;
     }
 }
-    
+
 /* Function that initialize the table using the last one */
 void vpar_InitMbAddrInc( vpar_thread_t * p_vpar )
 {
     int i_dummy;
     int i_value;
-    
+
     for( i_dummy = 0 ; i_dummy < 8 ; i_dummy++ )
     {
         p_vpar->pl_mb_addr_inc[i_dummy].i_value = MB_ERROR;
@@ -413,7 +468,7 @@ void vpar_InitMbAddrInc( vpar_thread_t * p_vpar )
     p_vpar->pl_mb_addr_inc[8].i_value = MB_ADDRINC_ESCAPE;
     p_vpar->pl_mb_addr_inc[8].i_length = 11;
 
-    for( i_dummy = 9 ; i_dummy < 15 ; i_dummy ++ ) 
+    for( i_dummy = 9 ; i_dummy < 15 ; i_dummy ++ )
     {
         p_vpar->pl_mb_addr_inc[i_dummy].i_value =  MB_ERROR;
         p_vpar->pl_mb_addr_inc[i_dummy].i_length = 0;
@@ -422,14 +477,14 @@ void vpar_InitMbAddrInc( vpar_thread_t * p_vpar )
     p_vpar->pl_mb_addr_inc[15].i_value = MB_ADDRINC_STUFFING;
     p_vpar->pl_mb_addr_inc[15].i_length = 11;
 
-    for( i_dummy = 16; i_dummy < 24; i_dummy++ ) 
+    for( i_dummy = 16; i_dummy < 24; i_dummy++ )
     {
         p_vpar->pl_mb_addr_inc[i_dummy].i_value =  MB_ERROR;
         p_vpar->pl_mb_addr_inc[i_dummy].i_length = 0;
     }
-    
+
     i_value = 33;
-    
+
     FillMbAddrIncTable( p_vpar, 24, 36, 1, &i_value, 11 );
     FillMbAddrIncTable( p_vpar, 36, 48, 2, &i_value, 10 );
     FillMbAddrIncTable( p_vpar, 48, 96, 8, &i_value, 8 );
@@ -445,7 +500,7 @@ void vpar_InitMbAddrInc( vpar_thread_t * p_vpar )
  *****************************************************************************/
 
 /* Fonction for filling up the tables */
-static void __inline__ FillMBType( vpar_thread_t * p_vpar,
+static void FillMBType( vpar_thread_t * p_vpar,
                                    int           i_mb_type,
                                    int           i_start,
                                    int           i_end,
@@ -453,7 +508,7 @@ static void __inline__ FillMBType( vpar_thread_t * p_vpar,
                                    int           i_length )
 {
     int i_dummy;
-    
+
     for( i_dummy = i_start ; i_dummy < i_end ; i_dummy++ )
     {
         p_vpar->ppl_mb_type[i_mb_type][i_dummy].i_value = i_value;
@@ -506,7 +561,7 @@ void vpar_InitBMBType( vpar_thread_t * p_vpar )
  *****************************************************************************/
 
 /* First fonction for filling the table */
-static void __inline__ FillDCTTable( dct_lookup_t * p_tab_dest, dct_lookup_t * p_tab_src,
+static void FillDCTTable( dct_lookup_t * p_tab_dest, dct_lookup_t * p_tab_src,
                                      int i_step, int i_nb_elem, int i_offset )
 {
     int i_dummy, i_dummy2;
@@ -524,15 +579,17 @@ static void __inline__ FillDCTTable( dct_lookup_t * p_tab_dest, dct_lookup_t * p
 /* Fonction that actually fills the table or create the pointers */
 void vpar_InitDCTTables( vpar_thread_t * p_vpar )
 {
-    /* Tables are cut in two parts to reduce memory occupation */    
+    /* Tables are cut in two parts to reduce memory occupation */
     p_vpar->pppl_dct_dc_size[0][0] = pl_dct_dc_lum_init_table_1;
     p_vpar->pppl_dct_dc_size[0][1] = pl_dct_dc_lum_init_table_2;
     p_vpar->pppl_dct_dc_size[1][0] = pl_dct_dc_chrom_init_table_1;
     p_vpar->pppl_dct_dc_size[1][1] = pl_dct_dc_chrom_init_table_2;
 
-    memset( p_vpar->ppl_dct_coef[0], MB_ERROR, 16 );
-    memset( p_vpar->ppl_dct_coef[1], MB_ERROR, 16 );
-    
+    /* XXX?? MB_ERROR is replaced by 0 because if we use -1 we
+     * can block in DecodeMPEG2Intra and others */
+    memset( p_vpar->ppl_dct_coef[0], 0, 16 );
+    memset( p_vpar->ppl_dct_coef[1], 0, 16 );
+
     /* For table B14 & B15, we have a pointer to tables */
     /* We fill the table thanks to the fonction defined above */
     FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab0, 256, 60,  4 );
@@ -552,6 +609,26 @@ void vpar_InitDCTTables( vpar_thread_t * p_vpar )
     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab6,    1, 16, 16 );
 }
 
+/*****************************************************************************
+ * vpar_InitScanTable : Initialize scan table
+ *****************************************************************************/
+void vpar_InitScanTable( vpar_thread_t * p_vpar )
+{
+    int     i;
+
+    memcpy( p_vpar->ppi_scan, pi_scan, sizeof(pi_scan) );
+    p_vpar->pf_norm_scan( p_vpar->ppi_scan );
+
+    /* If scan table has changed, we must change the quantization matrices. */
+    for( i = 0; i < 64; i++ )
+    {
+        p_vpar->pi_default_intra_quant[ p_vpar->ppi_scan[0][i] ] =
+            pi_default_intra_quant[ pi_scan[0][i] ];
+        p_vpar->pi_default_nonintra_quant[ p_vpar->ppi_scan[0][i] ] =
+            pi_default_nonintra_quant[ pi_scan[0][i] ];
+    }
+}
+
 
 /*
  * Block parsing
@@ -564,13 +641,111 @@ static __inline__ void DecodeMPEG1NonIntra( vpar_thread_t * p_vpar,
                                             macroblock_t * p_mb, int i_b,
                                             int i_chroma_format )
 {
+    int         i_parse;
+    int         i_nc;
+    int         i_cc;
+    int         i_coef;
+    int         i_code;
+    int         i_length;
+    int         i_pos;
+    int         i_run;
+    int         i_level;
+    boolean_t   b_dc;
+    boolean_t   b_sign;
+    boolean_t   b_chroma;
+
+    /* Give the chromatic component (0, 1, 2) */
+    i_cc = pi_cc_index[i_b];
+
+    /* Determine whether it is luminance or not (chrominance) */
+    b_chroma = ( i_cc + 1 ) >> 1;
 
+    /* There should be no D picture in non-intra blocks */
     if( p_vpar->picture.i_coding_type == D_CODING_TYPE )
+        intf_ErrMsg("vpar error : D-picture in non intra block");
+    
+    /* Decoding of the AC coefficients */
+
+    i_nc = 0;
+    i_coef = 0;
+    b_sign = 0;
+
+    for( i_parse = 0; !p_vpar->p_fifo->b_die; i_parse++ )
     {
-        /* Remove end_of_macroblock (always 1, prevents startcode emulation)
-         * ISO/IEC 11172-2 section 2.4.2.7 and 2.4.3.6 */
-        RemoveBits( &p_vpar->bit_stream, 1 );
+        i_code = ShowBits( &p_vpar->bit_stream, 16 );
+        if( i_code >= 16384 )
+        {
+            b_dc = (i_parse == 0);
+            i_run =     ppl_dct_tab2[b_dc][(i_code>>12)-4].i_run;
+            i_level =   ppl_dct_tab2[b_dc][(i_code>>12)-4].i_level;
+            i_length =  ppl_dct_tab2[b_dc][(i_code>>12)-4].i_length;
+        }
+        else
+        {
+            i_run =     p_vpar->ppl_dct_coef[0][i_code].i_run;
+            i_length =  p_vpar->ppl_dct_coef[0][i_code].i_length;
+            i_level =   p_vpar->ppl_dct_coef[0][i_code].i_level;
+        }
+
+        RemoveBits( &p_vpar->bit_stream, i_length );
+
+        switch( i_run )
+        {
+            case DCT_ESCAPE:
+                i_run = GetBits( &p_vpar->bit_stream, 6 );
+                i_level = GetBits( &p_vpar->bit_stream, 8 );
+                if (i_level == 0)
+                    i_level = GetBits( &p_vpar->bit_stream, 8 );
+                else if (i_level == 128)
+                    i_level = GetBits( &p_vpar->bit_stream, 8 ) - 256;
+                else if (i_level > 128)
+                    i_level -= 256;
+
+                if( (b_sign = i_level < 0) )
+                    i_level = -i_level;
+                
+                break;
+            case DCT_EOB:
+                if( i_nc <= 1 )
+                {
+                    p_mb->pf_idct[i_b] = p_vpar->pf_sparse_idct;
+                    p_mb->pi_sparse_pos[i_b] = i_coef;
+                }
+                else
+                {
+                    p_mb->pf_idct[i_b] = p_vpar->pf_idct;
+                }
+                return;
+
+                break;
+            default:
+                b_sign = GetBits( &p_vpar->bit_stream, 1 );
+        }
+        i_coef = i_parse;
+        i_parse += i_run;
+        i_nc ++;
+
+        if( i_parse >= 64 )
+        {
+            break;
+        }
+
+        i_pos = p_vpar->ppi_scan[p_vpar->picture.b_alternate_scan][i_parse];
+        i_level = ( ((i_level << 1) + 1) * p_vpar->mb.i_quantizer_scale
+                    * p_vpar->sequence.nonintra_quant.pi_matrix[i_pos] ) >> 4;
+
+        /* Mismatch control */
+        if( i_level ) /* Should always be true */
+        {
+            /* Equivalent to : if( (val & 1) == 0 ) val = val - 1; */
+            i_level = (i_level - 1) | 1;
+        }
+
+        p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
     }
+
+    intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds");
+    p_vpar->picture.b_error = 1;
 }
 
 /*****************************************************************************
@@ -580,13 +755,153 @@ static __inline__ void DecodeMPEG1Intra( vpar_thread_t * p_vpar,
                                          macroblock_t * p_mb, int i_b ,
                                          int i_chroma_format )
 {
+    int             i_parse;
+    int             i_nc;
+    int             i_cc;
+    int             i_coef;
+    int             i_code;
+    int             i_length;
+    int             i_pos;
+    int             i_dct_dc_size;
+    int             i_dct_dc_diff;
+    int             i_run;
+    int             i_level;
+    boolean_t       b_sign;
+    boolean_t       b_chroma;
+    
+    /* Give the chromatic component (0, 1, 2) */
+    i_cc = pi_cc_index[i_b];
+
+    /* Determine whether it is luminance or not (chrominance) */
+    b_chroma = ( i_cc + 1 ) >> 1;
+
+    /* decode length */
+    i_code = ShowBits(&p_vpar->bit_stream, 5);
+
+    if (i_code<31)
+    {
+        i_dct_dc_size = ppl_dct_dc_init_table_1[b_chroma][i_code].i_value;
+        i_length = ppl_dct_dc_init_table_1[b_chroma][i_code].i_length;
+        RemoveBits( &p_vpar->bit_stream, i_length);
+    }
+    else
+    {
+        i_code = ShowBits(&p_vpar->bit_stream, (9+b_chroma)) - (0x1f0 * (b_chroma + 1));
+        i_dct_dc_size = ppl_dct_dc_init_table_2[b_chroma][i_code].i_value;
+        i_length = ppl_dct_dc_init_table_2[b_chroma][i_code].i_length;
+        RemoveBits( &p_vpar->bit_stream, i_length);
+    }
+    if (i_dct_dc_size == 0)
+        i_dct_dc_diff = 0;
+    else
+    {
+        i_dct_dc_diff = GetBits( &p_vpar->bit_stream, i_dct_dc_size);
+        if ((i_dct_dc_diff & (1<<(i_dct_dc_size-1))) == 0)
+            i_dct_dc_diff -= (1<<i_dct_dc_size) - 1;
+    }
+
+    /* Read the actual code with the good length */
+    p_vpar->mb.pi_dc_dct_pred[i_cc] += i_dct_dc_diff;
+
+    p_mb->ppi_blocks[i_b][0] = p_vpar->mb.pi_dc_dct_pred[i_cc] << 3;
+
+    i_nc = ( p_vpar->mb.pi_dc_dct_pred[i_cc] != 0 );
+
 
     if( p_vpar->picture.i_coding_type == D_CODING_TYPE )
     {
         /* Remove end_of_macroblock (always 1, prevents startcode emulation)
          * ISO/IEC 11172-2 section 2.4.2.7 and 2.4.3.6 */
         RemoveBits( &p_vpar->bit_stream, 1 );
+        /* D pictures do not have AC coefficients */
+        return;
+    }
+
+    
+    /* Decoding of the AC coefficients */
+    i_coef = 0;
+    b_sign = 0;
+
+    for( i_parse = 1; !p_vpar->p_fifo->b_die/*i_parse < 64*/; i_parse++ )
+    {
+        i_code = ShowBits( &p_vpar->bit_stream, 16 );
+        /* We use 2 main tables for the coefficients */
+        if( i_code >= 16384 )
+        {
+            i_run =     ppl_dct_tab1[0][(i_code>>12)-4].i_run;
+            i_level =   ppl_dct_tab1[0][(i_code>>12)-4].i_level;
+            i_length =  ppl_dct_tab1[0][(i_code>>12)-4].i_length;
+        }
+        else
+        {
+            i_run =     p_vpar->ppl_dct_coef[0][i_code].i_run;
+            i_length =  p_vpar->ppl_dct_coef[0][i_code].i_length;
+            i_level =   p_vpar->ppl_dct_coef[0][i_code].i_level;
+        }
+
+        RemoveBits( &p_vpar->bit_stream, i_length );
+
+        switch( i_run )
+        {
+            case DCT_ESCAPE:
+                i_run = GetBits( &p_vpar->bit_stream, 6 );
+                i_level = GetBits( &p_vpar->bit_stream, 8 );
+                if (i_level == 0)
+                    i_level = GetBits( &p_vpar->bit_stream, 8 );
+                else if (i_level == 128)
+                    i_level = GetBits( &p_vpar->bit_stream, 8 ) - 256;
+                else if (i_level > 128)
+                    i_level -= 256;
+                if( (b_sign = i_level < 0) )
+                    i_level = -i_level;
+                break;
+            case DCT_EOB:
+                if( i_nc <= 1 )
+                {
+                    p_mb->pf_idct[i_b] = p_vpar->pf_sparse_idct;
+                    p_mb->pi_sparse_pos[i_b] = i_coef;
+                }
+                else
+                {
+                    p_mb->pf_idct[i_b] = p_vpar->pf_idct;
+                }
+                return;
+
+                break;
+            default:
+                b_sign = GetBits( &p_vpar->bit_stream, 1 );
+        }
+        
+        /* Prepare the next block */
+        i_coef = i_parse;
+        i_parse += i_run;
+        i_nc ++;
+
+        if( i_parse >= 64 )
+        {
+            /* We have an error in the stream */
+            break;
+        }
+
+        /* Determine the position of the block in the frame */
+        i_pos = p_vpar->ppi_scan[p_vpar->picture.b_alternate_scan][i_parse];
+        i_level = ( i_level *
+                    p_vpar->mb.i_quantizer_scale *
+                    p_vpar->sequence.intra_quant.pi_matrix[i_pos] ) >> 3;
+
+        /* Mismatch control */
+        if( i_level ) /* Should always be true */
+        {
+            /* Equivalent to : if( (val & 1) == 0 ) val = val - 1; */
+            i_level = (i_level - 1) | 1;
+        }
+
+        p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
     }
+
+    intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds");
+    p_vpar->picture.b_error = 1;
 }
 
 /*****************************************************************************
@@ -600,25 +915,24 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
     int         i_nc;
     int         i_cc;
     int         i_coef;
-    int         i_type;
     int         i_code;
     int         i_length;
     int         i_pos;
     int         i_run;
     int         i_level;
+    boolean_t   b_dc;
     boolean_t   b_sign;
-    int *       pi_quant;
-    
-    /* Lookup Table for the chromatic component */
-    static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
+    boolean_t   b_chroma;
+    u8 *        pi_quant;
 
+    /* Give the chromatic component (0, 1, 2) */
     i_cc = pi_cc_index[i_b];
 
     /* Determine whether it is luminance or not (chrominance) */
-    i_type = ( i_cc + 1 ) >> 1;
+    b_chroma = ( i_cc + 1 ) >> 1;
 
     /* Give a pointer to the quantization matrices for intra blocks */
-    if( (i_chroma_format == CHROMA_420) || (!i_type) )
+    if( (i_chroma_format == CHROMA_420) || (!b_chroma) )
     {
         pi_quant = p_vpar->sequence.nonintra_quant.pi_matrix;
     }
@@ -628,32 +942,18 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
     }
 
     /* Decoding of the AC coefficients */
-    
+
     i_nc = 0;
     i_coef = 0;
-    for( i_parse = 0; ; i_parse++ )
+    for( i_parse = 0; !p_vpar->p_fifo->b_die; i_parse++ )
     {
         i_code = ShowBits( &p_vpar->bit_stream, 16 );
         if( i_code >= 16384 )
         {
-            if( i_parse == 0 )
-            {
-                i_run =     pl_DCT_tab_dc[(i_code>>12)-4].i_run;
-                i_level =   pl_DCT_tab_dc[(i_code>>12)-4].i_level;
-                i_length =  pl_DCT_tab_dc[(i_code>>12)-4].i_length;
-            }
-            else
-            {
-                i_run =     pl_DCT_tab_ac[(i_code>>12)-4].i_run;
-                i_level =   pl_DCT_tab_ac[(i_code>>12)-4].i_level;
-                i_length =  pl_DCT_tab_ac[(i_code>>12)-4].i_length;
-             }
-        }
-        else if( i_code >= 1024 )
-        {
-            i_run =     pl_DCT_tab0[(i_code>>8)-4].i_run;
-            i_length =  pl_DCT_tab0[(i_code>>8)-4].i_length;
-            i_level =   pl_DCT_tab0[(i_code>>8)-4].i_level;
+            b_dc = (i_parse == 0);
+            i_run =     ppl_dct_tab2[b_dc][(i_code>>12)-4].i_run;
+            i_level =   ppl_dct_tab2[b_dc][(i_code>>12)-4].i_level;
+            i_length =  ppl_dct_tab2[b_dc][(i_code>>12)-4].i_length;
         }
         else
         {
@@ -662,7 +962,7 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
             i_level =   p_vpar->ppl_dct_coef[0][i_code].i_level;
         }
 
-        
+
         RemoveBits( &p_vpar->bit_stream, i_length );
 
         switch( i_run )
@@ -681,12 +981,12 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
 #endif
                 if( i_nc <= 1 )
                 {
-                    p_mb->pf_idct[i_b] = vdec_SparseIDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_sparse_idct;
                     p_mb->pi_sparse_pos[i_b] = i_coef;
                 }
                 else
                 {
-                    p_mb->pf_idct[i_b] = vdec_IDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_idct;
                 }
                 return;
 
@@ -702,14 +1002,14 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
         {
             break;
         }
-        
-        i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
-        i_level = ( ((i_level << 1) + 1) * p_vpar->mb.i_quantizer_scale 
+
+        i_pos = p_vpar->ppi_scan[p_vpar->picture.b_alternate_scan][i_parse];
+        i_level = ( ((i_level << 1) + 1) * p_vpar->mb.i_quantizer_scale
                     * pi_quant[i_pos] ) >> 5;
         p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
     }
 
-    intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds\n");
+    intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds");
     p_vpar->picture.b_error = 1;
 }
 
@@ -720,31 +1020,30 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
                                          macroblock_t * p_mb, int i_b,
                                          int i_chroma_format )
 {
-    int         i_parse;
-    int         i_nc;
-    int         i_cc;
-    int         i_coef;
-    int         i_type;
-    int         i_code;
-    int         i_length;
-    int         i_pos;
-    int         i_dct_dc_size;
-    int         i_dct_dc_diff;
-    int         i_run;
-    int         i_level;
-    boolean_t   b_vlc_intra;
-    boolean_t   b_sign;
-    int *       pi_quant;
+    int             i_parse;
+    int             i_nc;
+    int             i_cc;
+    int             i_coef;
+    int             i_code;
+    int             i_length;
+    int             i_pos;
+    int             i_dct_dc_size;
+    int             i_dct_dc_diff;
+    int             i_run;
+    int             i_level;
+    boolean_t       b_vlc_intra;
+    boolean_t       b_sign;
+    boolean_t       b_chroma;
+    u8 *            pi_quant;
     
-    /* Lookup Table for the chromatic component */
-    static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
+    /* Give the chromatic component (0, 1, 2) */
     i_cc = pi_cc_index[i_b];
 
     /* Determine whether it is luminance or not (chrominance) */
-    i_type = ( i_cc + 1 ) >> 1;
+    b_chroma = ( i_cc + 1 ) >> 1;
 
     /* Give a pointer to the quantization matrices for intra blocks */
-    if( (i_chroma_format == CHROMA_420) || (!i_type) )
+    if( (i_chroma_format == CHROMA_420) || (!b_chroma) )
     {
         pi_quant = p_vpar->sequence.intra_quant.pi_matrix;
     }
@@ -753,73 +1052,32 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
         pi_quant = p_vpar->sequence.chroma_intra_quant.pi_matrix;
     }
 
-#if 0    
-    /* Decoding of the DC intra coefficient */
-    /* The nb of bits to parse depends on i_type */
-    i_code = ShowBits( &p_vpar->bit_stream, 9 + i_type );
-    
-    /* To reduce memory occupation, there are two lookup tables
-     * See InitDCT above */
-    i_code5 = i_code >> (4+i_type);
-    
-    /* Shall we lookup in the first or in the second table ? */
-    i_select = ( i_code5 == 31 );
-    /* Offset value for looking in the second table */
-    i_offset = 0x1f0 + ( i_type * 0x1f0 );
-    i_pos = ( i_code5 * ( ! i_select ) ) + ( ( i_code - i_offset ) * i_select );
-    i_dct_dc_size = p_vpar->pppl_dct_dc_size[i_type][i_select][i_pos].i_value;
-#endif
-    
-    if( !i_type/*i_b < 4*/ )
+    /* decode length */
+    i_code = ShowBits(&p_vpar->bit_stream, 5);
+
+    if (i_code<31)
     {
-        /* decode length */
-        i_code = ShowBits(&p_vpar->bit_stream, 5);
-        if (i_code<31)
-        {
-            i_dct_dc_size = pl_dct_dc_lum_init_table_1[i_code].i_value;
-            i_length = pl_dct_dc_lum_init_table_1[i_code].i_length;
-            RemoveBits( &p_vpar->bit_stream, i_length);
-        }
-        else
-        {
-            i_code = ShowBits(&p_vpar->bit_stream, 9) - 0x1f0;
-            i_dct_dc_size = pl_dct_dc_lum_init_table_2[i_code].i_value;
-            i_length = pl_dct_dc_lum_init_table_2[i_code].i_length;
-            RemoveBits( &p_vpar->bit_stream, i_length);
-        }
+        i_dct_dc_size = ppl_dct_dc_init_table_1[b_chroma][i_code].i_value;
+        i_length = ppl_dct_dc_init_table_1[b_chroma][i_code].i_length;
+        RemoveBits( &p_vpar->bit_stream, i_length);
     }
     else
     {
-        /* decode length */
-        i_code = ShowBits(&p_vpar->bit_stream, 5);
-
-        if (i_code<31)
-        {
-            i_dct_dc_size = pl_dct_dc_chrom_init_table_1[i_code].i_value;
-            i_length = pl_dct_dc_chrom_init_table_1[i_code].i_length;
-            RemoveBits(&p_vpar->bit_stream, i_length);
-        }
-        else
-        {
-            i_code = ShowBits(&p_vpar->bit_stream, 10) - 0x3e0;
-            i_dct_dc_size = pl_dct_dc_chrom_init_table_2[i_code].i_value;
-            i_length = pl_dct_dc_chrom_init_table_2[i_code].i_length;
-            RemoveBits( &p_vpar->bit_stream, i_length);
-        }
+        i_code = ShowBits(&p_vpar->bit_stream, (9+b_chroma)) - (0x1f0 * (b_chroma + 1));
+        i_dct_dc_size = ppl_dct_dc_init_table_2[b_chroma][i_code].i_value;
+        i_length = ppl_dct_dc_init_table_2[b_chroma][i_code].i_length;
+        RemoveBits( &p_vpar->bit_stream, i_length);
     }
-    if (i_dct_dc_size==0)
+    if (i_dct_dc_size == 0)
         i_dct_dc_diff = 0;
     else
     {
         i_dct_dc_diff = GetBits( &p_vpar->bit_stream, i_dct_dc_size);
-        if ((i_dct_dc_diff & (1<<(i_dct_dc_size-1)))==0)
-            i_dct_dc_diff-= (1<<i_dct_dc_size) - 1;
+        if ((i_dct_dc_diff & (1<<(i_dct_dc_size-1))) == 0)
+            i_dct_dc_diff -= (1<<i_dct_dc_size) - 1;
     }
 
-    /* Dump the variable length code */
-    //RemoveBits( &p_vpar->bit_stream, 
-    //          p_vpar->pppl_dct_dc_size[i_type][i_select][i_pos].i_length );
-    
     /* Read the actual code with the good length */
     p_vpar->mb.pi_dc_dct_pred[i_cc] += i_dct_dc_diff;
 
@@ -828,28 +1086,20 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
 
     i_nc = ( p_vpar->mb.pi_dc_dct_pred[i_cc] != 0 );
 
-    /* Decoding of the AC coefficients */
     
+    /* Decoding of the AC coefficients */
+
     i_coef = 0;
     b_vlc_intra = p_vpar->picture.b_intra_vlc_format;
-    for( i_parse = 1; /*i_parse < 64*/; i_parse++ )
+    for( i_parse = 1; !p_vpar->p_fifo->b_die/*i_parse < 64*/; i_parse++ )
     {
         i_code = ShowBits( &p_vpar->bit_stream, 16 );
+        /* We use 2 main tables for the coefficients */
         if( i_code >= 16384 )
         {
-            if( b_vlc_intra )
-            {
-                i_run =     pl_DCT_tab0a[(i_code>>8)-4].i_run;
-                i_level =   pl_DCT_tab0a[(i_code>>8)-4].i_level;
-                i_length =  pl_DCT_tab0a[(i_code>>8)-4].i_length;
-//fprintf( stderr, "**********> %d, %d, %d *******\n", i_run, i_level, (i_code>>8)-4 );
-            }
-            else
-            {
-                i_run =     pl_DCT_tab_ac[(i_code>>12)-4].i_run;
-                i_level =   pl_DCT_tab_ac[(i_code>>12)-4].i_level;
-                i_length =  pl_DCT_tab_ac[(i_code>>12)-4].i_length;
-             }
+            i_run =     ppl_dct_tab1[b_vlc_intra][(i_code>>(12-(4*b_vlc_intra)))-4].i_run;
+            i_level =   ppl_dct_tab1[b_vlc_intra][(i_code>>(12-(4*b_vlc_intra)))-4].i_level;
+            i_length =  ppl_dct_tab1[b_vlc_intra][(i_code>>(12-(4*b_vlc_intra)))-4].i_length;
         }
         else
         {
@@ -858,54 +1108,6 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
             i_level =   p_vpar->ppl_dct_coef[b_vlc_intra][i_code].i_level;
         }
 
-#if 0
-        {
-            int code = i_code;
-            int intra_vlc_format = b_vlc_intra;
-            dct_lookup_t tab;
-            
-    if (code>=16384 && !intra_vlc_format)
-      tab = pl_DCT_tab_ac[(code>>12)-4];
-    else if (code>=1024)
-    {
-      if (intra_vlc_format)
-        tab = pl_DCT_tab0a[(code>>8)-4];
-      else
-        tab = pl_DCT_tab0[(code>>8)-4];
-    }
-    else if (code>=512)
-    {
-      if (intra_vlc_format)
-        tab = pl_DCT_tab1a[(code>>6)-8];
-      else
-        tab = pl_DCT_tab1[(code>>6)-8];
-    }
-    else if (code>=256)
-      tab = pl_DCT_tab2[(code>>4)-16];
-    else if (code>=128)
-      tab = pl_DCT_tab3[(code>>3)-16];
-    else if (code>=64)
-      tab = pl_DCT_tab4[(code>>2)-16];
-    else if (code>=32)
-      tab = pl_DCT_tab5[(code>>1)-16];
-    else if (code>=16)
-      tab = pl_DCT_tab6[code-16];
-    else
-    {
-       fprintf( stderr, "invalid Huffman code in Decode_MPEG2_Intra_Block()\n");
-    }
-
-    if( (i_run != tab.i_run) || (i_length != tab.i_length) || (i_level != tab.i_level) )
-    {
-        fprintf( stderr, "ET M....... !!!\n" );
-        exit(0);
-    }
-        }
-#endif
-
-
-
-        
         RemoveBits( &p_vpar->bit_stream, i_length );
 
         switch( i_run )
@@ -913,21 +1115,18 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
             case DCT_ESCAPE:
                 i_run = GetBits( &p_vpar->bit_stream, 6 );
                 i_level = GetBits( &p_vpar->bit_stream, 12 );
-                /*p_mb->ppi_blocks[i_b][i_parse] = ( b_sign = ( i_level > 2047 ) ) 
-                                                          ? ( -4096 + i_level )
-                                                          : i_level;*/
                 i_level = (b_sign = ( i_level > 2047 )) ? 4096 - i_level
                                                         : i_level;
                 break;
             case DCT_EOB:
                 if( i_nc <= 1 )
                 {
-                    p_mb->pf_idct[i_b] = vdec_SparseIDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_sparse_idct;
                     p_mb->pi_sparse_pos[i_b] = i_coef;
                 }
                 else
                 {
-                    p_mb->pf_idct[i_b] = vdec_IDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_idct;
                 }
                 return;
 
@@ -935,24 +1134,27 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
             default:
                 b_sign = GetBits( &p_vpar->bit_stream, 1 );
         }
-
+        
+        /* Prepare the next block */
         i_coef = i_parse;
         i_parse += i_run;
         i_nc ++;
+
         if( i_parse >= 64 )
         {
+            /* We have an error in the stream */
             break;
         }
 
-        i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
+        /* Determine the position of the block in the frame */
+        i_pos = p_vpar->ppi_scan[p_vpar->picture.b_alternate_scan][i_parse];
         i_level = ( i_level *
                     p_vpar->mb.i_quantizer_scale *
                     pi_quant[i_pos] ) >> 4;
         p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
     }
 
-    intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds\n");
+    intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds");
     p_vpar->picture.b_error = 1;
 }
 
@@ -967,7 +1169,7 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
 static __inline__ int MotionCode( vpar_thread_t * p_vpar )
 {
     int i_code;
-    static lookup_t pl_mv_tab0[8] = 
+    static lookup_t pl_mv_tab0[8] =
         { {-1,0}, {3,3}, {2,2}, {2,2}, {1,1}, {1,1}, {1,1}, {1,1} };
     /* Table B-10, motion_code, codes 0000011 ... 000011x */
     static lookup_t pl_mv_tab1[8] =
@@ -977,7 +1179,7 @@ static __inline__ int MotionCode( vpar_thread_t * p_vpar )
         {16,9}, {15,9}, {14,9}, {13,9},
         {12,9}, {11,9}, {10,8}, {10,8},
         {9,8},  {9,8},  {8,8},  {8,8} };
-    
+
     if( GetBits( &p_vpar->bit_stream, 1 ) )
     {
         return 0;
@@ -1001,13 +1203,13 @@ static __inline__ int MotionCode( vpar_thread_t * p_vpar )
     if( (i_code -= 12) < 0 )
     {
         p_vpar->picture.b_error = 1;
-        intf_DbgMsg( "vpar debug: Invalid motion_vector code\n" );
+        intf_DbgMsg( "vpar debug: Invalid motion_vector code" );
         return 0;
     }
 
     RemoveBits( &p_vpar->bit_stream, pl_mv_tab2[i_code].i_length );
     return( GetBits( &p_vpar->bit_stream, 1 ) ?
-        -pl_mv_tab2[i_code].i_value : pl_mv_tab2[i_code].i_value );            
+        -pl_mv_tab2[i_code].i_value : pl_mv_tab2[i_code].i_value );
 }
 
 /****************************************************************************
@@ -1042,17 +1244,16 @@ static __inline__ void DecodeMotionVector( int * pi_prediction, int i_r_size,
  ****************************************************************************/
 static __inline__ void MotionVector( vpar_thread_t * p_vpar,
                                      macroblock_t * p_mb, int i_r,
-                                     int i_s, int i_full_pel, int i_structure )
+                                     int i_s, int i_full_pel, int i_structure,
+                                     int i_h_r_size, int i_v_r_size )
 {
     int i_motion_code, i_motion_residual;
-    int i_r_size;
     int pi_dm_vector[2];
-    
-    i_r_size = p_vpar->picture.ppi_f_code[i_s][0] - 1;
+
     i_motion_code = MotionCode( p_vpar );
-    i_motion_residual = (i_r_size != 0 && i_motion_code != 0) ?
-                        GetBits( &p_vpar->bit_stream, i_r_size) : 0;
-    DecodeMotionVector( &p_vpar->mb.pppi_pmv[i_r][i_s][0], i_r_size,
+    i_motion_residual = (i_h_r_size != 0 && i_motion_code != 0) ?
+                        GetBits( &p_vpar->bit_stream, i_h_r_size) : 0;
+    DecodeMotionVector( &p_vpar->mb.pppi_pmv[i_r][i_s][0], i_h_r_size,
                         i_motion_code, i_motion_residual, i_full_pel );
     p_mb->pppi_motion_vectors[i_r][i_s][0] = p_vpar->mb.pppi_pmv[i_r][i_s][0];
 
@@ -1067,26 +1268,25 @@ static __inline__ void MotionVector( vpar_thread_t * p_vpar,
             pi_dm_vector[0] = 0;
         }
     }
-    
-    i_r_size = p_vpar->picture.ppi_f_code[i_s][1]-1;
+
     i_motion_code = MotionCode( p_vpar );
-    i_motion_residual = (i_r_size != 0 && i_motion_code != 0) ?
-                        GetBits( &p_vpar->bit_stream, i_r_size) : 0;
+    i_motion_residual = (i_v_r_size != 0 && i_motion_code != 0) ?
+                        GetBits( &p_vpar->bit_stream, i_v_r_size) : 0;
+
 
-   
     if( (p_vpar->mb.i_mv_format == MOTION_FIELD)
         && (i_structure == FRAME_STRUCTURE) )
     {
          p_vpar->mb.pppi_pmv[i_r][i_s][1] >>= 1;
     }
-    
-    DecodeMotionVector( &p_vpar->mb.pppi_pmv[i_r][i_s][1], i_r_size,
+
+    DecodeMotionVector( &p_vpar->mb.pppi_pmv[i_r][i_s][1], i_v_r_size,
                         i_motion_code, i_motion_residual, i_full_pel );
 
     if( (p_vpar->mb.i_mv_format == MOTION_FIELD)
         && (i_structure == FRAME_STRUCTURE) )
          p_vpar->mb.pppi_pmv[i_r][i_s][1] <<= 1;
-     
+
     p_mb->pppi_motion_vectors[i_r][i_s][1] = p_vpar->mb.pppi_pmv[i_r][i_s][1];
 
     if( p_vpar->mb.b_dmv )
@@ -1149,18 +1349,21 @@ static __inline__ void MotionVector( vpar_thread_t * p_vpar,
 /*****************************************************************************
  * DecodeMVMPEG1 : Parse the next MPEG-1 motion vectors
  *****************************************************************************/
-static __inline__ void DecodeMVMPEG1( vpar_thread_t * p_vpar,
-                            macroblock_t * p_mb, int i_s, int i_structure )
+static void DecodeMVMPEG1( vpar_thread_t * p_vpar,
+                           macroblock_t * p_mb, int i_s, int i_structure )
 {
+    int i_r_size = i_s ? p_vpar->picture.i_backward_f_code - 1 :
+                         p_vpar->picture.i_forward_f_code - 1;
     MotionVector( p_vpar, p_mb, 0, i_s,
-                  p_vpar->picture.pb_full_pel_vector[i_s], i_structure );
+                  p_vpar->picture.pb_full_pel_vector[i_s], FRAME_STRUCTURE,
+                  i_r_size, i_r_size );
 }
 
 /*****************************************************************************
  * DecodeMVMPEG2 : Parse the next MPEG-2 motion_vectors field
  *****************************************************************************/
-static __inline__ void DecodeMVMPEG2( vpar_thread_t * p_vpar,
-                            macroblock_t * p_mb, int i_s, int i_structure )
+static void DecodeMVMPEG2( vpar_thread_t * p_vpar,
+                           macroblock_t * p_mb, int i_s, int i_structure )
 {
     if( p_vpar->mb.i_mv_count == 1 )
     {
@@ -1169,7 +1372,9 @@ static __inline__ void DecodeMVMPEG2( vpar_thread_t * p_vpar,
             p_mb->ppi_field_select[0][i_s] = p_mb->ppi_field_select[1][i_s]
                                             = GetBits( &p_vpar->bit_stream, 1 );
         }
-        MotionVector( p_vpar, p_mb, 0, i_s, 0, i_structure );
+        MotionVector( p_vpar, p_mb, 0, i_s, 0, i_structure,
+                      p_vpar->picture.ppi_f_code[i_s][0] - 1,
+                      p_vpar->picture.ppi_f_code[i_s][1] - 1 );
         p_vpar->mb.pppi_pmv[1][i_s][0] = p_vpar->mb.pppi_pmv[0][i_s][0];
         p_vpar->mb.pppi_pmv[1][i_s][1] = p_vpar->mb.pppi_pmv[0][i_s][1];
         p_mb->pppi_motion_vectors[1][i_s][0] = p_vpar->mb.pppi_pmv[0][i_s][0];
@@ -1178,9 +1383,13 @@ static __inline__ void DecodeMVMPEG2( vpar_thread_t * p_vpar,
     else
     {
         p_mb->ppi_field_select[0][i_s] = GetBits( &p_vpar->bit_stream, 1 );
-        MotionVector( p_vpar, p_mb, 0, i_s, 0, i_structure );
+        MotionVector( p_vpar, p_mb, 0, i_s, 0, i_structure,
+                      p_vpar->picture.ppi_f_code[i_s][0] - 1,
+                      p_vpar->picture.ppi_f_code[i_s][1] - 1 );
         p_mb->ppi_field_select[1][i_s] = GetBits( &p_vpar->bit_stream, 1 );
-        MotionVector( p_vpar, p_mb, 1, i_s, 0, i_structure );
+        MotionVector( p_vpar, p_mb, 1, i_s, 0, i_structure,
+                      p_vpar->picture.ppi_f_code[i_s][0] - 1,
+                      p_vpar->picture.ppi_f_code[i_s][1] - 1 );
     }
 }
 
@@ -1192,12 +1401,12 @@ static __inline__ void DecodeMVMPEG2( vpar_thread_t * p_vpar,
 /*****************************************************************************
  * MacroblockAddressIncrement : Get the macroblock_address_increment field
  *****************************************************************************/
-static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
+static int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
 {
     int i_addr_inc = 0;
     /* Index in the lookup table mb_addr_inc */
     int    i_index = ShowBits( &p_vpar->bit_stream, 11 );
-        
+
     /* Test the presence of the escape character */
     while( i_index == 8 )
     {
@@ -1205,13 +1414,13 @@ static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
         i_addr_inc += 33;
         i_index = ShowBits( &p_vpar->bit_stream, 11 );
     }
-     
+
     /* Affect the value from the lookup table */
     i_addr_inc += p_vpar->pl_mb_addr_inc[i_index].i_value;
-    
+
     /* Dump the good number of bits */
     RemoveBits( &p_vpar->bit_stream, p_vpar->pl_mb_addr_inc[i_index].i_length );
-    
+
     return i_addr_inc;
 }
 
@@ -1222,7 +1431,7 @@ static __inline__ int IMBType( vpar_thread_t * p_vpar )
 {
     /* Take two bits for testing */
     int                 i_type = ShowBits( &p_vpar->bit_stream, 2 );
-    
+
     /* Lookup table for macroblock_type */
     static lookup_t     pl_mb_Itype[4] = { {MB_ERROR, 0},
                                            {MB_QUANT|MB_INTRA, 2},
@@ -1240,7 +1449,7 @@ static __inline__ int PMBType( vpar_thread_t * p_vpar )
 {
     /* Testing on 6 bits */
     int                i_type = ShowBits( &p_vpar->bit_stream, 6 );
-    
+
     /* Dump the good number of bits */
     RemoveBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[0][i_type].i_length );
     /* return the value from the lookup table for P type */
@@ -1254,10 +1463,10 @@ static __inline__ int BMBType( vpar_thread_t * p_vpar )
 {
      /* Testing on 6 bits */
     int                i_type = ShowBits( &p_vpar->bit_stream, 6 );
-    
+
     /* Dump the good number of bits */
     RemoveBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[1][i_type].i_length );
-    
+
     /* return the value from the lookup table for B type */
     return p_vpar->ppl_mb_type[1][i_type].i_value;
 }
@@ -1277,10 +1486,10 @@ static __inline__ int CodedPattern420( vpar_thread_t * p_vpar )
 {
     /* Take the max 9 bits length vlc code for testing */
     int      i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
-    
+
     /* Trash the good number of bits read in the lookup table */
     RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
-    
+
     /* return the value from the vlc table */
     return pl_coded_pattern[i_vlc].i_value;
 }
@@ -1291,9 +1500,9 @@ static __inline__ int CodedPattern420( vpar_thread_t * p_vpar )
 static __inline__ int CodedPattern422( vpar_thread_t * p_vpar )
 {
     int      i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
-    
+
     RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
-    
+
     /* Supplementary 2 bits long code for 4:2:2 format */
     return pl_coded_pattern[i_vlc].i_value |
            (GetBits( &p_vpar->bit_stream, 2 ) << 6);
@@ -1305,9 +1514,9 @@ static __inline__ int CodedPattern422( vpar_thread_t * p_vpar )
 static __inline__ int CodedPattern444( vpar_thread_t * p_vpar )
 {
     int      i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
-    
+
     RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
-    
+
     return pl_coded_pattern[i_vlc].i_value |
            (GetBits( &p_vpar->bit_stream, 6 ) << 6);
 }
@@ -1376,24 +1585,13 @@ static __inline__ void SkippedMacroblock( vpar_thread_t * p_vpar, int i_mb,
 {
     macroblock_t *  p_mb;
 
-    static f_motion_t   pf_motion_skipped[4][4] =
-    {
-        {NULL, NULL, NULL, NULL},
-        {NULL, vdec_MotionFieldField420, vdec_MotionFieldField420,
-            vdec_MotionFrameFrame420},
-        {NULL, vdec_MotionFieldField422, vdec_MotionFieldField422,
-            vdec_MotionFrameFrame422},
-        {NULL, vdec_MotionFieldField444, vdec_MotionFieldField444,
-            vdec_MotionFrameFrame444},
-    };
-
     if( i_coding_type == I_CODING_TYPE )
     {
-        intf_DbgMsg("vpar error: skipped macroblock in I-picture\n");
+        intf_DbgMsg("vpar error: skipped macroblock in I-picture");
         p_vpar->picture.b_error = 1;
         return;
     }
-    
+
     if( (p_mb = vpar_NewMacroblock( &p_vpar->vfifo )) == NULL )
     {
         /* b_die == 1 */
@@ -1405,13 +1603,27 @@ static __inline__ void SkippedMacroblock( vpar_thread_t * p_vpar, int i_mb,
 
     InitMacroblock( p_vpar, p_mb, i_coding_type, i_chroma_format,
                     i_structure, b_second_field );
-   
+
     /* Motion type is picture structure. */
-    p_mb->pf_motion = pf_motion_skipped[i_chroma_format]
-                                       [i_structure];
-    p_mb->i_mb_type = MB_MOTION_FORWARD;
+    p_mb->pf_motion = p_vpar->ppf_motion_skipped[i_chroma_format]
+                                                [i_structure];
     p_mb->i_coded_block_pattern = 0;
-    memset( p_mb->pppi_motion_vectors, 0, 8*sizeof(int) );
+
+    /* Motion direction and motion vectors depend on the coding type. */
+    if( i_coding_type == B_CODING_TYPE )
+    {
+        int i, j, k;
+        p_mb->i_mb_type = p_vpar->mb.i_motion_dir;
+        for( i = 0; i < 2; i++ )
+            for( j = 0; j < 2; j++ )
+                for( k = 0; k < 2; k++ )
+                    p_mb->pppi_motion_vectors[i][j][k] = p_vpar->mb.pppi_pmv[i][j][k];
+    }
+    else if( i_coding_type == P_CODING_TYPE )
+    {
+        p_mb->i_mb_type = MB_MOTION_FORWARD;
+        memset( p_mb->pppi_motion_vectors, 0, 8*sizeof(int) );
+    }
 
     /* Set the field we use for motion compensation */
     p_mb->ppi_field_select[0][0] = p_mb->ppi_field_select[0][1]
@@ -1421,7 +1633,7 @@ static __inline__ void SkippedMacroblock( vpar_thread_t * p_vpar, int i_mb,
 
 #ifndef VDEC_SMP
     /* Decode the macroblock NOW ! */
-    vdec_DecodeMacroblock( p_vpar->pp_vdec[0], p_mb );
+    vpar_DecodeMacroblock ( &p_vpar->vfifo, p_mb );
 #endif
 }
 
@@ -1452,11 +1664,19 @@ static __inline__ void MacroblockModes( vpar_thread_t * p_vpar,
     case D_CODING_TYPE:
         p_mb->i_mb_type = DMBType( p_vpar );
     }
-    
+
+    if( i_coding_type == B_CODING_TYPE )
+    {
+        /* We need to remember the motion direction of the last macroblock
+         * before a skipped macroblock (ISO/IEC 13818-2 7.6.6) */
+        p_vpar->mb.i_motion_dir = p_mb->i_mb_type
+                              & (MB_MOTION_FORWARD | MB_MOTION_BACKWARD);
+    }
+
     /* SCALABILITY : warning, we don't know if spatial_temporal_weight_code
      * has to be dropped, take care if you use scalable streams. */
     /* RemoveBits( &p_vpar->bit_stream, 2 ); */
-    
+
     if( (i_coding_type == P_CODING_TYPE || i_coding_type == B_CODING_TYPE)
         && (p_mb->i_mb_type & (MB_MOTION_FORWARD | MB_MOTION_BACKWARD)) )
     {
@@ -1470,7 +1690,7 @@ static __inline__ void MacroblockModes( vpar_thread_t * p_vpar,
             p_vpar->mb.i_motion_type = MOTION_FRAME;
         }
 
-        /* ???? */
+        /* XXX?? */
         p_vpar->mb.i_mv_count = ppi_mv_count[i_structure == FRAME_STRUCTURE]
                                             [p_vpar->mb.i_motion_type];
         p_vpar->mb.i_mv_format = ppi_mv_format[i_structure == FRAME_STRUCTURE]
@@ -1510,8 +1730,7 @@ if( p_vpar->picture.b_error )                                           \
     (*pi_mb_address)--;                                                 \
     vpar_DestroyMacroblock( &p_vpar->vfifo, p_mb );                     \
     return;                                                             \
-} 
+}
 
 #define PARSEBLOCKS( MPEG1FUNC, MPEG2FUNC )                             \
 {                                                                       \
@@ -1534,7 +1753,7 @@ if( p_vpar->picture.b_error )                                           \
             /* Calculate block coordinates. */                          \
             p_mb->p_data[i_b] = p_data1                                 \
                                 + pi_y[p_vpar->mb.b_dct_type][i_b]      \
-                                * p_vpar->sequence.i_width              \
+                                * p_vpar->picture.i_l_stride            \
                                 + pi_x[i_b];                            \
                                                                         \
             PARSEERROR                                                  \
@@ -1567,7 +1786,7 @@ if( p_vpar->picture.b_error )                                           \
             /* Calculate block coordinates. */                          \
             p_mb->p_data[i_b] = pp_data[i_b & 1]                        \
                                  + pi_y[p_vpar->mb.b_dct_type][i_b]     \
-                                   * p_vpar->sequence.i_chroma_width    \
+                                   * p_vpar->picture.i_c_stride         \
                                  + pi_x[i_b];                           \
                                                                         \
             PARSEERROR                                                  \
@@ -1590,37 +1809,24 @@ static __inline__ void ParseMacroblock(
                            boolean_t b_second_field )     /* second field of a
                                                            * field picture   */
 {
-    static f_motion_t   pppf_motion[4][2][4] =
-      {
-        { {NULL, NULL, NULL, NULL},
-          {NULL, NULL, NULL, NULL}
-        },
-        { {NULL, vdec_MotionFieldField420, vdec_MotionField16x8420,
-            vdec_MotionFieldDMV420},
-          {NULL, vdec_MotionFrameField420, vdec_MotionFrameFrame420,
-            vdec_MotionFrameDMV420}
-        },
-        { {NULL, vdec_MotionFieldField422, vdec_MotionField16x8422,
-            vdec_MotionFieldDMV422},
-          {NULL, vdec_MotionFrameField422, vdec_MotionFrameFrame422,
-            vdec_MotionFrameDMV422}
-        },
-        { {NULL, vdec_MotionFieldField444, vdec_MotionField16x8444,
-            vdec_MotionFieldDMV444},
-          {NULL, vdec_MotionFrameField444, vdec_MotionFrameFrame444,
-            vdec_MotionFrameDMV444}
-        }
-      };
     static int      pi_x[12] = {0,8,0,8,0,0,0,0,8,8,8,8};
     static int      pi_y[2][12] = { {0,0,8,8,0,0,8,8,0,0,8,8},
                                     {0,0,1,1,0,0,1,1,0,0,1,1} };
-
     int             i_mb, i_b, i_mask;
+    int i_inc;
     macroblock_t *  p_mb;
     yuv_data_t *    p_data1;
     yuv_data_t *    p_data2;
 
-    *pi_mb_address += MacroblockAddressIncrement( p_vpar );
+    i_inc = MacroblockAddressIncrement( p_vpar );
+    *pi_mb_address += i_inc;
+
+    if( i_inc < 0 )
+    {
+        intf_ErrMsg( "vpar error: bad address increment (%d)", i_inc );
+        p_vpar->picture.b_error = 1;
+        return;
+    }
 
     if( *pi_mb_address - i_mb_previous - 1 )
     {
@@ -1705,9 +1911,9 @@ static __inline__ void ParseMacroblock(
             = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
 
         /* Motion function pointer. */
-        p_mb->pf_motion = pppf_motion[i_chroma_format]
-                                     [i_structure == FRAME_STRUCTURE]
-                                     [p_vpar->mb.i_motion_type];
+        p_mb->pf_motion = p_vpar->pppf_motion[i_chroma_format]
+                                             [i_structure == FRAME_STRUCTURE]
+                                             [p_vpar->mb.i_motion_type];
 
         if( p_mb->i_mb_type & MB_PATTERN )
         {
@@ -1780,7 +1986,7 @@ static __inline__ void ParseMacroblock(
         UpdateContext( p_vpar, i_structure );
 #ifndef VDEC_SMP
         /* Decode the macroblock NOW ! */
-        vdec_DecodeMacroblock( p_vpar->pp_vdec[0], p_mb );
+        vpar_DecodeMacroblock ( &p_vpar->vfifo, p_mb );
 #endif
     }
     else
@@ -1796,9 +2002,136 @@ static __inline__ void ParseMacroblock(
  * Picture data parsing management
  */
 
+/*****************************************************************************
+ * ParseMacroblockVWXYZ : Parse the next macroblock ; specific functions
+ *****************************************************************************
+ * V = MPEG2 ?
+ * W = coding type ?
+ * X = chroma format ?
+ * Y = structure ?
+ * Z = second field ?
+ *****************************************************************************/
+void ParseMacroblockGENERIC( vpar_thread_t * p_vpar, int * pi_mb_address,
+                             int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     b_mpeg2, i_coding_type, i_chroma_format,
+                     i_structure, b_second_field );
+}
+
+#if (VPAR_OPTIM_LEVEL > 0)
+/* Optimizations for frame pictures */
+void ParseMacroblock2I420F0( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, I_CODING_TYPE, CHROMA_420,
+                     FRAME_STRUCTURE, 0 );
+}
+
+void ParseMacroblock2P420F0( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, P_CODING_TYPE, CHROMA_420,
+                     FRAME_STRUCTURE, 0 );
+}
+
+void ParseMacroblock2B420F0( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, B_CODING_TYPE, CHROMA_420,
+                     FRAME_STRUCTURE, 0 );
+}
+#endif
+
+#if (VPAR_OPTIM_LEVEL > 1)
+/* Optimizations for field pictures */
+void ParseMacroblock2I420TZ( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, I_CODING_TYPE, CHROMA_420,
+                     TOP_FIELD, (p_vpar->picture.i_structure !=
+                                 p_vpar->picture.i_current_structure) );
+}
+
+void ParseMacroblock2P420TZ( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, P_CODING_TYPE, CHROMA_420,
+                     TOP_FIELD, (p_vpar->picture.i_structure !=
+                                 p_vpar->picture.i_current_structure) );
+}
+
+void ParseMacroblock2B420TZ( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, B_CODING_TYPE, CHROMA_420,
+                     TOP_FIELD, (p_vpar->picture.i_structure !=
+                                 p_vpar->picture.i_current_structure) );
+}
+
+void ParseMacroblock2I420BZ( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, I_CODING_TYPE, CHROMA_420,
+                     BOTTOM_FIELD, (p_vpar->picture.i_structure !=
+                                    p_vpar->picture.i_current_structure) );
+}
+
+void ParseMacroblock2P420BZ( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, P_CODING_TYPE, CHROMA_420,
+                     BOTTOM_FIELD, (p_vpar->picture.i_structure !=
+                                    p_vpar->picture.i_current_structure) );
+}
+
+void ParseMacroblock2B420BZ( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                             boolean_t b_mpeg2, int i_coding_type,
+                             int i_chroma_format, int i_structure,
+                             boolean_t b_second_field )
+{
+    ParseMacroblock( p_vpar, pi_mb_address, i_mb_previous, i_mb_base,
+                     1, B_CODING_TYPE, CHROMA_420,
+                     BOTTOM_FIELD, (p_vpar->picture.i_structure !=
+                                    p_vpar->picture.i_current_structure) );
+}
+#endif
+
 /*****************************************************************************
  * SliceHeader : Parse the next slice structure
  *****************************************************************************/
+typedef void    (*f_parse_mb_t)( vpar_thread_t * p_vpar, int * pi_mb_address,                                    int i_mb_previous, int i_mb_base,
+                                 boolean_t b_mpeg2, int i_coding_type,
+                                 int i_chroma_format, int i_structure,
+                                 boolean_t b_second_field );
+
 static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
                                     int * pi_mb_address, int i_mb_base,
                                     u32 i_vert_code, boolean_t b_high,
@@ -1807,6 +2140,43 @@ static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
                                     int i_chroma_format, int i_structure,
                                     boolean_t b_second_field )
 {
+    static f_parse_mb_t ppf_parse_mb[4][4] =
+    {
+        {
+            NULL, NULL, NULL, NULL
+        },
+        {
+            /* TOP_FIELD */
+#if (VPAR_OPTIM_LEVEL > 1)
+            NULL, ParseMacroblock2I420TZ, ParseMacroblock2P420TZ,
+            ParseMacroblock2B420TZ
+#else
+            NULL, ParseMacroblockGENERIC, ParseMacroblockGENERIC,
+            ParseMacroblockGENERIC
+#endif
+        },
+        {
+            /* BOTTOM_FIELD */
+#if (VPAR_OPTIM_LEVEL > 1)
+            NULL, ParseMacroblock2I420BZ, ParseMacroblock2P420BZ,
+            ParseMacroblock2B420BZ
+#else
+            NULL, ParseMacroblockGENERIC, ParseMacroblockGENERIC,
+            ParseMacroblockGENERIC
+#endif
+        },
+        {
+            /* FRAME_PICTURE */
+#if (VPAR_OPTIM_LEVEL > 0)
+            NULL, ParseMacroblock2I420F0, ParseMacroblock2P420F0,
+            ParseMacroblock2B420F0
+#else
+            NULL, ParseMacroblockGENERIC, ParseMacroblockGENERIC,
+            ParseMacroblockGENERIC
+#endif
+        }
+    };
+
     int                     i_mb_address_save = *pi_mb_address;
 
     p_vpar->picture.b_error = 0;
@@ -1835,7 +2205,14 @@ static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
         }
     }
     *pi_mb_address = (i_vert_code - 1)*p_vpar->sequence.i_mb_width;
-    
+
+    if( *pi_mb_address < i_mb_address_save )
+    {
+        intf_ErrMsg( "vpar error: slices do not follow, maybe a PES has been trashed" );
+        p_vpar->picture.b_error = 1;
+        return;
+    }
+
     /* Reset DC coefficients predictors (ISO/IEC 13818-2 7.2.1). */
     p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
         = p_vpar->mb.pi_dc_dct_pred[2]
@@ -1846,58 +2223,97 @@ static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
 
     do
     {
-        ParseMacroblock( p_vpar, pi_mb_address, i_mb_address_save,
+        if( i_mb_address_save >= p_vpar->sequence.i_mb_size )
+        {
+            p_vpar->picture.b_error = 1;
+            return;
+        }
+
+        if( p_vpar->sequence.i_chroma_format != CHROMA_420
+            || !p_vpar->sequence.b_mpeg2 || p_vpar->sequence.i_height > 2800
+            || p_vpar->sequence.i_scalable_mode == SC_DP )
+        {
+            /* Weird stream. Use the slower generic function. */
+            ParseMacroblockGENERIC( p_vpar, pi_mb_address, i_mb_address_save,
                          i_mb_base, b_mpeg2, i_coding_type,
                          i_chroma_format, i_structure,
                          b_second_field );
+        }
+        else
+        {
+            /* Try to find an optimized function. */
+            if( ppf_parse_mb[i_structure]
+                            [p_vpar->picture.i_coding_type] == NULL )
+            {
+                intf_ErrMsg( "vpar error: bad ppf_parse_mb function pointer (struct:%d, coding type:%d)",
+                         i_structure, i_coding_type );
+            }
+            else
+            {
+                ppf_parse_mb[i_structure][i_coding_type]
+                       ( p_vpar, pi_mb_address, i_mb_address_save,
+                         i_mb_base, b_mpeg2, i_coding_type,
+                         i_chroma_format, i_structure,
+                         b_second_field );
+            }
+        }
+
         i_mb_address_save = *pi_mb_address;
+        if( p_vpar->picture.b_error )
+        {
+            return;
+        }
     }
-    while( ShowBits( &p_vpar->bit_stream, 23 ) && !p_vpar->picture.b_error
-            && !p_vpar->b_die );
-    NextStartCode( p_vpar );
+    while( ShowBits( &p_vpar->bit_stream, 23 )
+            && !p_vpar->p_fifo->b_die );
+    NextStartCode( &p_vpar->bit_stream );
 }
 
 /*****************************************************************************
  * PictureData : Parse off all macroblocks (ISO/IEC 13818-2 6.2.3.7)
  *****************************************************************************/
-static __inline__ void PictureData( vpar_thread_t * p_vpar, int i_mb_base,
-                                    boolean_t b_high, boolean_t b_dp_scalable,
-                                    boolean_t b_mpeg2, int i_coding_type,
-                                    int i_chroma_format, int i_structure,
-                                    boolean_t b_second_field )
+void vpar_PictureData( vpar_thread_t * p_vpar, int i_mb_base )
 {
     int         i_mb_address = 0;
     u32         i_dummy;
 
-    NextStartCode( p_vpar );
-    while( ((i_coding_type != I_CODING_TYPE && i_coding_type != D_CODING_TYPE)
+    NextStartCode( &p_vpar->bit_stream );
+    while( ((p_vpar->picture.i_coding_type != I_CODING_TYPE
+                    && p_vpar->picture.i_coding_type != D_CODING_TYPE)
              || !p_vpar->picture.b_error)
-           && i_mb_address+i_mb_base < p_vpar->sequence.i_mb_size
-           && !p_vpar->b_die )
+           && i_mb_address < (p_vpar->sequence.i_mb_size
+                    >> (p_vpar->picture.i_structure != FRAME_STRUCTURE))
+           && !p_vpar->p_fifo->b_die )
     {
         if( ((i_dummy = ShowBits( &p_vpar->bit_stream, 32 ))
                  < SLICE_START_CODE_MIN) ||
             (i_dummy > SLICE_START_CODE_MAX) )
         {
-            intf_DbgMsg("vpar debug: premature end of picture\n");
+            intf_DbgMsg("vpar debug: premature end of picture");
             p_vpar->picture.b_error = 1;
             break;
         }
         RemoveBits32( &p_vpar->bit_stream );
-        
+
         /* Decode slice data. */
         SliceHeader( p_vpar, &i_mb_address, i_mb_base, i_dummy & 255,
-                     b_high, b_dp_scalable, b_mpeg2, i_coding_type,
-                     i_chroma_format, i_structure, b_second_field );
+                     (p_vpar->sequence.i_height > 2800),
+                     (p_vpar->sequence.i_scalable_mode == SC_DP),
+                     p_vpar->sequence.b_mpeg2, p_vpar->picture.i_coding_type,
+                     p_vpar->sequence.i_chroma_format,
+                     p_vpar->picture.i_structure,
+                     (p_vpar->picture.i_structure !=
+                        p_vpar->picture.i_current_structure) );
     }
 
     /* Try to recover from error. If we missed less than half the
      * number of macroblocks of the picture, mark the missed ones
      * as skipped. */
-    if( (i_coding_type == P_CODING_TYPE || i_coding_type == B_CODING_TYPE)
+    if( (p_vpar->picture.i_coding_type == P_CODING_TYPE
+                || p_vpar->picture.i_coding_type == B_CODING_TYPE)
         && p_vpar->picture.b_error &&
         ( (i_mb_address-i_mb_base) > (p_vpar->sequence.i_mb_size >> 1)
-           || (i_structure != FRAME_STRUCTURE
+           || (p_vpar->picture.i_structure != FRAME_STRUCTURE
                && (i_mb_address-i_mb_base) > (p_vpar->sequence.i_mb_size >> 2) ) ) )
     {
         int         i_mb;
@@ -1905,97 +2321,16 @@ static __inline__ void PictureData( vpar_thread_t * p_vpar, int i_mb_base,
         p_vpar->picture.b_error = 0;
         for( i_mb = i_mb_address + 1;
              i_mb < (p_vpar->sequence.i_mb_size
-                     << (i_structure != FRAME_STRUCTURE));
+                     << (p_vpar->picture.i_structure != FRAME_STRUCTURE));
              i_mb++ )
         {
-            SkippedMacroblock( p_vpar, i_mb, i_mb_base, i_coding_type,
-                               i_chroma_format, i_structure, b_second_field );
+            SkippedMacroblock( p_vpar, i_mb, i_mb_base,
+                               p_vpar->picture.i_coding_type,
+                               p_vpar->sequence.i_chroma_format,
+                               p_vpar->picture.i_structure,
+                               (p_vpar->picture.i_structure !=
+                                p_vpar->picture.i_current_structure) );
         }
     }
 }
 
-/*****************************************************************************
- * vpar_PictureDataVWXYZ : Parse the next macroblock ; specific functions
- *****************************************************************************
- * V = MPEG2 ?
- * W = coding type ?
- * X = chroma format ?
- * Y = structure ?
- * Z = second field ?
- *****************************************************************************/
-void vpar_PictureDataGENERIC( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, i_mb_base, (p_vpar->sequence.i_height > 2800),
-                 (p_vpar->sequence.i_scalable_mode == SC_DP),
-                 p_vpar->sequence.b_mpeg2, p_vpar->picture.i_coding_type,
-                 p_vpar->sequence.i_chroma_format,
-                 p_vpar->picture.i_structure,
-                 (p_vpar->picture.i_structure !=
-                    p_vpar->picture.i_current_structure) );
-}
-
-#if (VPAR_OPTIM_LEVEL > 0)
-/* Optimizations for frame pictures */
-void vpar_PictureData2I420F0( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, 0, 0, 0, 1, I_CODING_TYPE, CHROMA_420,
-                 FRAME_STRUCTURE, 0 );
-}
-
-void vpar_PictureData2P420F0( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, 0, 0, 0, 1, P_CODING_TYPE, CHROMA_420,
-                 FRAME_STRUCTURE, 0 );
-}
-
-void vpar_PictureData2B420F0( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, 0, 0, 0, 1, B_CODING_TYPE, CHROMA_420,
-                 FRAME_STRUCTURE, 0 );
-}
-#endif
-
-#if (VPAR_OPTIM_LEVEL > 1)
-/* Optimizations for field pictures */
-void vpar_PictureData2I420TZ( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, i_mb_base, 0, 0, 1, I_CODING_TYPE, CHROMA_420,
-                 TOP_FIELD, (p_vpar->picture.i_structure !=
-                                p_vpar->picture.i_current_structure) );
-}
-
-void vpar_PictureData2P420TZ( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, i_mb_base, 0, 0, 1, P_CODING_TYPE, CHROMA_420,
-                 TOP_FIELD, (p_vpar->picture.i_structure !=
-                                p_vpar->picture.i_current_structure) );
-}
-
-void vpar_PictureData2B420TZ( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, i_mb_base, 0, 0, 1, B_CODING_TYPE, CHROMA_420,
-                 TOP_FIELD, (p_vpar->picture.i_structure !=
-                                p_vpar->picture.i_current_structure) );
-}
-
-void vpar_PictureData2I420BZ( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, i_mb_base, 0, 0, 1, I_CODING_TYPE, CHROMA_420,
-                 BOTTOM_FIELD, (p_vpar->picture.i_structure !=
-                                p_vpar->picture.i_current_structure) );
-}
-
-void vpar_PictureData2P420BZ( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, i_mb_base, 0, 0, 1, P_CODING_TYPE, CHROMA_420,
-                 BOTTOM_FIELD, (p_vpar->picture.i_structure !=
-                                p_vpar->picture.i_current_structure) );
-}
-
-void vpar_PictureData2B420BZ( vpar_thread_t * p_vpar, int i_mb_base )
-{
-    PictureData( p_vpar, i_mb_base, 0, 0, 1, B_CODING_TYPE, CHROMA_420,
-                 BOTTOM_FIELD, (p_vpar->picture.i_structure !=
-                                p_vpar->picture.i_current_structure) );
-}
-#endif