+/* zigzags are transposed with respect to the tables in the standard */
+static const uint8_t x264_zigzag_scan4[2][16] =
+{{ // frame
+ 0, 4, 1, 2, 5, 8, 12, 9, 6, 3, 7, 10, 13, 14, 11, 15
+},
+{ // field
+ 0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+}};
+static const uint8_t x264_zigzag_scan8[2][64] =
+{{
+ 0, 8, 1, 2, 9, 16, 24, 17, 10, 3, 4, 11, 18, 25, 32, 40,
+ 33, 26, 19, 12, 5, 6, 13, 20, 27, 34, 41, 48, 56, 49, 42, 35,
+ 28, 21, 14, 7, 15, 22, 29, 36, 43, 50, 57, 58, 51, 44, 37, 30,
+ 23, 31, 38, 45, 52, 59, 60, 53, 46, 39, 47, 54, 61, 62, 55, 63
+},
+{
+ 0, 1, 2, 8, 9, 3, 4, 10, 16, 11, 5, 6, 7, 12, 17, 24,
+ 18, 13, 14, 15, 19, 25, 32, 26, 20, 21, 22, 23, 27, 33, 40, 34,
+ 28, 29, 30, 31, 35, 41, 48, 42, 36, 37, 38, 39, 43, 49, 50, 44,
+ 45, 46, 47, 51, 56, 57, 52, 53, 54, 55, 58, 59, 60, 61, 62, 63
+}};
+
+static const uint8_t block_idx_x[16] =
+{
+ 0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3
+};
+static const uint8_t block_idx_y[16] =
+{
+ 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3
+};
+static const uint8_t block_idx_xy[4][4] =
+{
+ { 0, 2, 8, 10 },
+ { 1, 3, 9, 11 },
+ { 4, 6, 12, 14 },
+ { 5, 7, 13, 15 }
+};
+static const uint8_t block_idx_xy_1d[16] =
+{
+ 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15
+};
+static const uint8_t block_idx_yx_1d[16] =
+{
+ 0, 4, 1, 5, 8, 12, 9, 13, 2, 6, 3, 7, 10, 14, 11, 15
+};
+static const uint8_t block_idx_xy_fenc[16] =
+{
+ 0*4 + 0*4*FENC_STRIDE, 1*4 + 0*4*FENC_STRIDE,
+ 0*4 + 1*4*FENC_STRIDE, 1*4 + 1*4*FENC_STRIDE,
+ 2*4 + 0*4*FENC_STRIDE, 3*4 + 0*4*FENC_STRIDE,
+ 2*4 + 1*4*FENC_STRIDE, 3*4 + 1*4*FENC_STRIDE,
+ 0*4 + 2*4*FENC_STRIDE, 1*4 + 2*4*FENC_STRIDE,
+ 0*4 + 3*4*FENC_STRIDE, 1*4 + 3*4*FENC_STRIDE,
+ 2*4 + 2*4*FENC_STRIDE, 3*4 + 2*4*FENC_STRIDE,
+ 2*4 + 3*4*FENC_STRIDE, 3*4 + 3*4*FENC_STRIDE
+};
+static const uint16_t block_idx_xy_fdec[16] =
+{
+ 0*4 + 0*4*FDEC_STRIDE, 1*4 + 0*4*FDEC_STRIDE,
+ 0*4 + 1*4*FDEC_STRIDE, 1*4 + 1*4*FDEC_STRIDE,
+ 2*4 + 0*4*FDEC_STRIDE, 3*4 + 0*4*FDEC_STRIDE,
+ 2*4 + 1*4*FDEC_STRIDE, 3*4 + 1*4*FDEC_STRIDE,
+ 0*4 + 2*4*FDEC_STRIDE, 1*4 + 2*4*FDEC_STRIDE,
+ 0*4 + 3*4*FDEC_STRIDE, 1*4 + 3*4*FDEC_STRIDE,
+ 2*4 + 2*4*FDEC_STRIDE, 3*4 + 2*4*FDEC_STRIDE,
+ 2*4 + 3*4*FDEC_STRIDE, 3*4 + 3*4*FDEC_STRIDE
+};
+
+static const uint8_t i_chroma_qp_table[52+12*2] =
+{
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 29, 30, 31, 32, 32, 33, 34, 34, 35, 35,
+ 36, 36, 37, 37, 37, 38, 38, 38, 39, 39,
+ 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+};
+
+enum cabac_ctx_block_cat_e
+{
+ DCT_LUMA_DC = 0,
+ DCT_LUMA_AC = 1,
+ DCT_LUMA_4x4 = 2,
+ DCT_CHROMA_DC = 3,
+ DCT_CHROMA_AC = 4,
+ DCT_LUMA_8x8 = 5,
+};
+
+
+int x264_macroblock_cache_init( x264_t *h );
+void x264_macroblock_slice_init( x264_t *h );
+void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y );