[xiph-commits] r12750 - in experimental/j/theora-mashup/lib: . dec

j at svn.xiph.org j at svn.xiph.org
Tue Mar 13 07:34:26 PDT 2007


Author: j
Date: 2007-03-13 07:34:17 -0700 (Tue, 13 Mar 2007)
New Revision: 12750

Removed:
   experimental/j/theora-mashup/lib/dec/bitrate.c
   experimental/j/theora-mashup/lib/dec/encinfo.c
   experimental/j/theora-mashup/lib/dec/encint.h
   experimental/j/theora-mashup/lib/dec/encmsc.c
   experimental/j/theora-mashup/lib/dec/encode.c
   experimental/j/theora-mashup/lib/dec/encvbr.c
   experimental/j/theora-mashup/lib/dec/encvbr.h
   experimental/j/theora-mashup/lib/dec/enquant.c
   experimental/j/theora-mashup/lib/dec/fdct.c
   experimental/j/theora-mashup/lib/dec/fdct.h
   experimental/j/theora-mashup/lib/dec/huffenc.c
   experimental/j/theora-mashup/lib/dec/huffenc.h
   experimental/j/theora-mashup/lib/dec/impmap.c
   experimental/j/theora-mashup/lib/dec/mcenc.c
   experimental/j/theora-mashup/lib/dec/psych.c
   experimental/j/theora-mashup/lib/dec/psych.h
Modified:
   experimental/j/theora-mashup/lib/Makefile.am
Log:
remove theora-exp encoder

Modified: experimental/j/theora-mashup/lib/Makefile.am
===================================================================
--- experimental/j/theora-mashup/lib/Makefile.am	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/Makefile.am	2007-03-13 14:34:17 UTC (rev 12750)
@@ -115,16 +115,11 @@
 	dec/dct.h \
 	dec/decint.h \
 	dec/dequant.h \
-	dec/encint.h \
 	dec/enquant.h \
-	dec/encvbr.h \
-	dec/fdct.h \
 	dec/huffdec.h \
-	dec/huffenc.h \
 	dec/huffman.h \
 	dec/idct.h \
 	dec/ocintrin.h \
-	dec/psych.h \
 	dec/quant.h \
 	dec/x86/x86int.h
 	

Deleted: experimental/j/theora-mashup/lib/dec/bitrate.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/bitrate.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/bitrate.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,8580 +0,0 @@
-#include <string.h>
-#include <ogg/ogg.h>
-#include "encint.h"
-
-ogg_uint16_t OC_RES_BITRATES[64][3][OC_NMODES][16]={
-  {
-    {
-      /*Y'  qi=0  OC_MODE_INTRA*/
-      {
-          476,  632, 1372, 2027, 2619, 3272, 3956, 4620,
-         5300, 5974, 6626, 7245, 7836, 8474, 9056,12823
-      },
-      /*Y'  qi=0  OC_MODE_INTER_NOMV*/
-      {
-           74,   95,  127,  263,  592, 1010, 1582, 2359,
-         3295, 4275, 5286, 6236, 6988, 7777, 8725,13318
-      },
-      /*Y'  qi=0  OC_MODE_INTER_MV*/
-      {
-          223,  258,  305,  459,  824, 1461, 2273, 3168,
-         4062, 4967, 5893, 6785, 7694, 8470, 9289,12589
-      },
-      /*Y'  qi=0  OC_MDOE_INTER_MV_LAST*/
-      {
-          199,  229,  266,  420,  776, 1350, 2121, 2987,
-         3909, 4868, 5841, 6780, 7688, 8529, 9327,12668
-      },
-      /*Y'  qi=0  OC_MODE_INTER_MV_LAST2*/
-      {
-          221,  261,  295,  436,  793, 1375, 2144, 3011,
-         3936, 4895, 5882, 6839, 7776, 8639, 9398,12826
-      },
-      /*Y'  qi=0  OC_MODE_INTER_MV_FOUR*/
-      {
-          252,  289,  324,  477,  844, 1463, 2274, 3173,
-         4100, 5046, 5982, 6909, 7780, 8588, 9358,12248
-      },
-      /*Y'  qi=0  OC_MODE_GOLDEN_NOMV*/
-      {
-          265,  297,  408,  739, 1444, 1989, 2404, 3139,
-         3879, 4394, 5131, 5967, 6262, 6833, 7631,13096
-      },
-      /*Y'  qi=0  OC_MODE_GOLDEN_MV*/
-      {
-          316,  348,  381,  625, 1158, 1661, 2342, 3151,
-         4094, 5062, 6045, 6988, 7862, 8665, 9420,12760
-      }
-    },
-    {
-      /*Cb  qi=0  OC_MODE_INTRA*/
-      {
-          457, 1182, 2197, 3154, 4159, 5256, 6252, 7084,
-         7945, 8846, 9524,10479,11039,11905,12674,16114
-      },
-      /*Cb  qi=0  OC_MODE_INTER_NOMV*/
-      {
-           55,   90,  260,  679, 1505, 3029, 4482, 5749,
-         6616, 7001, 7349, 7457, 7671, 7492, 7782, 8001
-      },
-      /*Cb  qi=0  OC_MODE_INTER_MV*/
-      {
-           35,  173,  510, 1346, 2519, 3995, 5144, 6672,
-         7823, 8681, 9591,10611,10955,12535,12121,14330
-      },
-      /*Cb  qi=0  OC_MDOE_INTER_MV_LAST*/
-      {
-           34,  156,  476, 1130, 2159, 3629, 5215, 6754,
-         8110, 9218,10134,10300,10982,10395,10888,10719
-      },
-      /*Cb  qi=0  OC_MODE_INTER_MV_LAST2*/
-      {
-           33,  166,  497, 1140, 2157, 3630, 5234, 6730,
-         8149, 9295,10312,10488,10568,10645,10943,11595
-      },
-      /*Cb  qi=0  OC_MODE_INTER_MV_FOUR*/
-      {
-           20,  178,  526, 1239, 2328, 3699, 5120, 6558,
-         7873, 8890, 9785,10528,11189,11793,12165,14903
-      },
-      /*Cb  qi=0  OC_MODE_GOLDEN_NOMV*/
-      {
-          112,  220,  500, 1066, 1908, 3199, 3770, 4392,
-         4592, 5275, 5284, 5458, 6029, 6134, 6305, 8462
-      },
-      /*Cb  qi=0  OC_MODE_GOLDEN_MV*/
-      {
-           23,  204,  572, 1248, 2271, 3523, 4832, 5771,
-         6389, 6313, 6357, 6756, 6406, 6533, 6549, 8494
-      }
-    },
-    {
-      /*Cr  qi=0  OC_MODE_INTRA*/
-      {
-          354,  976, 1749, 2553, 3277, 3998, 4656, 5295,
-         5948, 6531, 7173, 7740, 8309, 9125, 9439,11887
-      },
-      /*Cr  qi=0  OC_MODE_INTER_NOMV*/
-      {
-           47,   64,  105,  209,  447,  916, 2069, 2923,
-         3616, 3837, 4237, 4515, 4435, 4719, 4754, 4264
-      },
-      /*Cr  qi=0  OC_MODE_INTER_MV*/
-      {
-           32,  112,  258,  636, 1207, 1919, 2837, 3772,
-         4447, 5092, 5832, 6519, 6945, 6537, 7111, 8700
-      },
-      /*Cr  qi=0  OC_MDOE_INTER_MV_LAST*/
-      {
-           33,  115,  236,  607, 1107, 1681, 2592, 3621,
-         4588, 5507, 6271, 6687, 7354, 7199, 6916, 5722
-      },
-      /*Cr  qi=0  OC_MODE_INTER_MV_LAST2*/
-      {
-           31,  120,  236,  589, 1125, 1655, 2550, 3525,
-         4290, 5056, 5672, 6112, 6678, 6058, 5292, 5296
-      },
-      /*Cr  qi=0  OC_MODE_INTER_MV_FOUR*/
-      {
-           20,  120,  261,  663, 1245, 1871, 2711, 3641,
-         4597, 5351, 6091, 6884, 7369, 7670, 8045, 9350
-      },
-      /*Cr  qi=0  OC_MODE_GOLDEN_NOMV*/
-      {
-           93,  116,  202,  456,  960, 1495, 2274, 2914,
-         3091, 3475, 3958, 4175, 4293, 4415, 4675, 4808
-      },
-      /*Cr  qi=0  OC_MODE_GOLDEN_MV*/
-      {
-           24,  135,  267,  655, 1226, 1777, 2537, 3357,
-         3704, 3986, 4465, 4350, 4359, 4758, 4889, 4295
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=1  OC_MODE_INTRA*/
-      {
-          485,  652, 1438, 2134, 2764, 3465, 4192, 4881,
-         5591, 6285, 6958, 7579, 8191, 8840, 9430,13291
-      },
-      /*Y'  qi=1  OC_MODE_INTER_NOMV*/
-      {
-           78,   99,  138,  311,  688, 1153, 1817, 2695,
-         3700, 4744, 5813, 6771, 7547, 8466, 9413,13919
-      },
-      /*Y'  qi=1  OC_MODE_INTER_MV*/
-      {
-          239,  270,  317,  502,  969, 1700, 2600, 3515,
-         4434, 5331, 6241, 7209, 8081, 8896, 9762,13081
-      },
-      /*Y'  qi=1  OC_MDOE_INTER_MV_LAST*/
-      {
-          192,  229,  273,  460,  877, 1539, 2384, 3307,
-         4282, 5283, 6288, 7256, 8170, 9040, 9821,13176
-      },
-      /*Y'  qi=1  OC_MODE_INTER_MV_LAST2*/
-      {
-          225,  268,  304,  476,  898, 1566, 2412, 3333,
-         4307, 5316, 6341, 7331, 8245, 9114, 9900,13359
-      },
-      /*Y'  qi=1  OC_MODE_INTER_MV_FOUR*/
-      {
-          253,  292,  333,  521,  951, 1655, 2540, 3485,
-         4458, 5447, 6428, 7393, 8270, 9107, 9851,12755
-      },
-      /*Y'  qi=1  OC_MODE_GOLDEN_NOMV*/
-      {
-          285,  309,  441,  905, 1635, 2025, 2594, 3251,
-         4036, 4655, 5471, 6248, 6556, 7138, 7876,13739
-      },
-      /*Y'  qi=1  OC_MODE_GOLDEN_MV*/
-      {
-          339,  348,  387,  689, 1234, 1797, 2566, 3441,
-         4454, 5463, 6521, 7493, 8402, 9187, 9947,13286
-      }
-    },
-    {
-      /*Cb  qi=1  OC_MODE_INTRA*/
-      {
-          469, 1231, 2305, 3310, 4341, 5465, 6471, 7341,
-         8227, 9150, 9872,10820,11414,12362,13075,16640
-      },
-      /*Cb  qi=1  OC_MODE_INTER_NOMV*/
-      {
-           57,   99,  304,  797, 1727, 3370, 4809, 6067,
-         6910, 7450, 7468, 7969, 7648, 7747, 7930, 8330
-      },
-      /*Cb  qi=1  OC_MODE_INTER_MV*/
-      {
-           27,  192,  571, 1432, 2674, 4147, 5662, 7246,
-         8536, 9590,10045,11387,12736,14068,12607,14603
-      },
-      /*Cb  qi=1  OC_MDOE_INTER_MV_LAST*/
-      {
-           35,  170,  539, 1268, 2364, 3963, 5607, 7175,
-         8543, 9659,10420,10704,11477,10757,11486,11450
-      },
-      /*Cb  qi=1  OC_MODE_INTER_MV_LAST2*/
-      {
-           33,  184,  563, 1277, 2368, 3963, 5674, 7210,
-         8568, 9673,10362,10549,10951,11780,11816,12030
-      },
-      /*Cb  qi=1  OC_MODE_INTER_MV_FOUR*/
-      {
-           20,  196,  594, 1369, 2524, 3983, 5469, 6954,
-         8218, 9281,10111,10831,11632,12277,13257,15247
-      },
-      /*Cb  qi=1  OC_MODE_GOLDEN_NOMV*/
-      {
-          116,  216,  592, 1122, 1905, 3353, 4044, 4836,
-         4835, 5581, 5451, 5961, 6350, 6610, 6457, 8852
-      },
-      /*Cb  qi=1  OC_MODE_GOLDEN_MV*/
-      {
-           24,  208,  634, 1382, 2483, 3824, 5133, 6049,
-         6686, 6738, 6955, 7293, 6615, 7244, 7503, 8992
-      }
-    },
-    {
-      /*Cr  qi=1  OC_MODE_INTRA*/
-      {
-          363, 1030, 1850, 2693, 3453, 4200, 4866, 5526,
-         6253, 6844, 7498, 8073, 8633, 9539, 9893,12400
-      },
-      /*Cr  qi=1  OC_MODE_INTER_NOMV*/
-      {
-           49,   67,  117,  247,  551, 1115, 2247, 3264,
-         3829, 4189, 4330, 4677, 4879, 4746, 5399, 4432
-      },
-      /*Cr  qi=1  OC_MODE_INTER_MV*/
-      {
-           24,  118,  295,  719, 1275, 1932, 2956, 3993,
-         4952, 5669, 6508, 7293, 7309, 7100, 7450, 8738
-      },
-      /*Cr  qi=1  OC_MDOE_INTER_MV_LAST*/
-      {
-           34,  121,  262,  680, 1231, 1894, 2879, 3976,
-         4980, 5929, 6596, 7111, 7546, 7237, 7229, 6053
-      },
-      /*Cr  qi=1  OC_MODE_INTER_MV_LAST2*/
-      {
-           31,  126,  261,  676, 1270, 1874, 2856, 3851,
-         4701, 5384, 6003, 6573, 6988, 6267, 6763, 5411
-      },
-      /*Cr  qi=1  OC_MODE_INTER_MV_FOUR*/
-      {
-           21,  127,  288,  758, 1402, 2100, 3002, 4008,
-         4936, 5739, 6483, 7048, 7770, 8247, 8413, 9825
-      },
-      /*Cr  qi=1  OC_MODE_GOLDEN_NOMV*/
-      {
-           96,  120,  249,  574,  865, 1688, 2528, 3322,
-         3226, 3537, 4023, 4444, 4583, 4656, 4877, 4962
-      },
-      /*Cr  qi=1  OC_MODE_GOLDEN_MV*/
-      {
-           25,  138,  289,  740, 1370, 1991, 2803, 3677,
-         4205, 4319, 4979, 4651, 4860, 5132, 5524, 4751
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=2  OC_MODE_INTRA*/
-      {
-          496,  675, 1519, 2272, 2949, 3692, 4456, 5186,
-         5929, 6637, 7334, 7968, 8594, 9252, 9861,13843
-      },
-      /*Y'  qi=2  OC_MODE_INTER_NOMV*/
-      {
-           82,  103,  151,  371,  801, 1327, 2118, 3113,
-         4204, 5312, 6412, 7346, 8173, 9147,10260,14547
-      },
-      /*Y'  qi=2  OC_MODE_INTER_MV*/
-      {
-          236,  280,  336,  568, 1108, 1952, 2937, 3917,
-         4856, 5829, 6789, 7761, 8652, 9519,10375,13705
-      },
-      /*Y'  qi=2  OC_MDOE_INTER_MV_LAST*/
-      {
-          199,  233,  282,  513, 1012, 1775, 2705, 3698,
-         4729, 5789, 6830, 7825, 8754, 9653,10445,13772
-      },
-      /*Y'  qi=2  OC_MODE_INTER_MV_LAST2*/
-      {
-          226,  270,  305,  523, 1031, 1797, 2733, 3715,
-         4762, 5823, 6879, 7917, 8872, 9710,10517,13980
-      },
-      /*Y'  qi=2  OC_MODE_INTER_MV_FOUR*/
-      {
-          260,  297,  348,  581, 1095, 1904, 2870, 3881,
-         4912, 5950, 6980, 7968, 8860, 9697,10464,13338
-      },
-      /*Y'  qi=2  OC_MODE_GOLDEN_NOMV*/
-      {
-          279,  306,  476,  957, 1725, 2297, 2839, 3633,
-         4444, 5124, 6036, 6529, 6922, 7776, 7979,14329
-      },
-      /*Y'  qi=2  OC_MODE_GOLDEN_MV*/
-      {
-          308,  353,  394,  776, 1383, 2030, 2871, 3845,
-         4925, 6026, 7099, 8106, 8994, 9831,10572,13876
-      }
-    },
-    {
-      /*Cb  qi=2  OC_MODE_INTRA*/
-      {
-          485, 1291, 2447, 3500, 4570, 5739, 6737, 7641,
-         8558, 9482,10212,11223,11788,12802,13591,17150
-      },
-      /*Cb  qi=2  OC_MODE_INTER_NOMV*/
-      {
-           61,  110,  358,  940, 1968, 3694, 5260, 6435,
-         7182, 7927, 7849, 8157, 8033, 7860, 8125, 8433
-      },
-      /*Cb  qi=2  OC_MODE_INTER_MV*/
-      {
-           28,  209,  645, 1570, 2916, 4580, 6179, 7715,
-         8988, 9990,10472,11590,12642,13135,13104,14829
-      },
-      /*Cb  qi=2  OC_MDOE_INTER_MV_LAST*/
-      {
-           37,  188,  619, 1436, 2615, 4315, 6093, 7691,
-         9098,10234,11175,11294,11304,11712,11862,11917
-      },
-      /*Cb  qi=2  OC_MODE_INTER_MV_LAST2*/
-      {
-           35,  204,  644, 1442, 2594, 4292, 6149, 7725,
-         9140,10176,10551,11524,11779,11536,12599,12935
-      },
-      /*Cb  qi=2  OC_MODE_INTER_MV_FOUR*/
-      {
-           21,  214,  673, 1535, 2772, 4314, 5874, 7395,
-         8652, 9640,10566,11408,12140,12526,13187,15633
-      },
-      /*Cb  qi=2  OC_MODE_GOLDEN_NOMV*/
-      {
-          125,  261,  613, 1204, 2159, 3435, 4405, 5125,
-         5145, 5595, 5789, 6160, 6574, 6878, 6799, 8953
-      },
-      /*Cb  qi=2  OC_MODE_GOLDEN_MV*/
-      {
-           26,  229,  720, 1534, 2729, 4083, 5394, 6314,
-         6714, 6961, 6843, 6942, 6645, 7057, 7525, 9052
-      }
-    },
-    {
-      /*Cr  qi=2  OC_MODE_INTRA*/
-      {
-          373, 1086, 1967, 2863, 3653, 4449, 5158, 5834,
-         6643, 7204, 7893, 8529, 9091, 9986,10418,12982
-      },
-      /*Cr  qi=2  OC_MODE_INTER_NOMV*/
-      {
-           51,   72,  135,  303,  678, 1508, 2543, 3703,
-         4121, 4334, 4711, 4893, 5119, 4983, 5223, 4521
-      },
-      /*Cr  qi=2  OC_MODE_INTER_MV*/
-      {
-           25,  129,  331,  818, 1441, 2224, 3309, 4478,
-         5354, 6231, 6735, 7665, 8357, 7694, 8091, 9234
-      },
-      /*Cr  qi=2  OC_MDOE_INTER_MV_LAST*/
-      {
-           34,  131,  298,  786, 1399, 2180, 3303, 4462,
-         5452, 6530, 7106, 7346, 8099, 7448, 7438, 5942
-      },
-      /*Cr  qi=2  OC_MODE_INTER_MV_LAST2*/
-      {
-           34,  138,  298,  772, 1438, 2170, 3303, 4244,
-         5075, 5879, 6437, 6807, 7101, 6423, 6783, 5220
-      },
-      /*Cr  qi=2  OC_MODE_INTER_MV_FOUR*/
-      {
-           22,  136,  331,  873, 1595, 2382, 3392, 4427,
-         5382, 6184, 6957, 7928, 8173, 8378, 9142,10498
-      },
-      /*Cr  qi=2  OC_MODE_GOLDEN_NOMV*/
-      {
-          107,  140,  314,  662,  874, 1914, 2905, 3181,
-         3303, 3796, 4349, 4571, 4694, 5076, 5092, 5231
-      },
-      /*Cr  qi=2  OC_MODE_GOLDEN_MV*/
-      {
-           27,  146,  330,  845, 1531, 2264, 3100, 3930,
-         4173, 4362, 5105, 4699, 4814, 5492, 5364, 4739
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=3  OC_MODE_INTRA*/
-      {
-          502,  686, 1550, 2333, 3044, 3812, 4592, 5334,
-         6087, 6806, 7513, 8156, 8783, 9448,10058,14101
-      },
-      /*Y'  qi=3  OC_MODE_INTER_NOMV*/
-      {
-           83,  105,  157,  404,  857, 1425, 2272, 3316,
-         4426, 5553, 6654, 7600, 8366, 9286,10513,14877
-      },
-      /*Y'  qi=3  OC_MODE_INTER_MV*/
-      {
-          240,  285,  343,  607, 1194, 2087, 3079, 4078,
-         5034, 6016, 6990, 7961, 8916, 9788,10614,14008
-      },
-      /*Y'  qi=3  OC_MDOE_INTER_MV_LAST*/
-      {
-          199,  235,  286,  538, 1081, 1900, 2867, 3884,
-         4940, 6018, 7075, 8085, 9014, 9879,10700,14015
-      },
-      /*Y'  qi=3  OC_MODE_INTER_MV_LAST2*/
-      {
-          232,  273,  328,  581, 1145, 1980, 2949, 3937,
-         4975, 6048, 7111, 8110, 9070, 9956,10742,14274
-      },
-      /*Y'  qi=3  OC_MODE_INTER_MV_FOUR*/
-      {
-          259,  302,  356,  617, 1178, 2040, 3036, 4068,
-         5121, 6174, 7203, 8188, 9101, 9925,10700,13631
-      },
-      /*Y'  qi=3  OC_MODE_GOLDEN_NOMV*/
-      {
-          286,  286,  486, 1041, 1755, 2478, 2971, 3789,
-         4618, 5382, 6175, 6709, 7280, 7663, 8416,14660
-      },
-      /*Y'  qi=3  OC_MODE_GOLDEN_MV*/
-      {
-          341,  349,  402,  819, 1426, 2126, 3015, 4022,
-         5122, 6239, 7303, 8345, 9264,10073,10875,14167
-      }
-    },
-    {
-      /*Cb  qi=3  OC_MODE_INTRA*/
-      {
-          499, 1338, 2562, 3673, 4784, 5986, 7007, 7928,
-         8910, 9862,10621,11696,12350,13266,14028,17697
-      },
-      /*Cb  qi=3  OC_MODE_INTER_NOMV*/
-      {
-           64,  119,  403, 1089, 2258, 4109, 5682, 6749,
-         7626, 8187, 8077, 8623, 8370, 8243, 8621, 8922
-      },
-      /*Cb  qi=3  OC_MODE_INTER_MV*/
-      {
-           30,  222,  721, 1754, 3195, 4772, 6536, 8204,
-         9477,10372,11172,12128,12479,14549,14228,15843
-      },
-      /*Cb  qi=3  OC_MDOE_INTER_MV_LAST*/
-      {
-           38,  202,  690, 1594, 2863, 4685, 6544, 8157,
-         9476,10583,11737,12361,13068,13616,13986,15475
-      },
-      /*Cb  qi=3  OC_MODE_INTER_MV_LAST2*/
-      {
-           35,  215,  716, 1623, 2912, 4780, 6558, 8216,
-         9613,10463,11078,11309,11113,11356,12284,11630
-      },
-      /*Cb  qi=3  OC_MODE_INTER_MV_FOUR*/
-      {
-           23,  229,  742, 1695, 3015, 4670, 6321, 7863,
-         9128,10303,11028,12045,12465,13034,13877,16260
-      },
-      /*Cb  qi=3  OC_MODE_GOLDEN_NOMV*/
-      {
-          122,  314,  647, 1391, 2469, 3857, 4946, 5212,
-         5371, 5936, 6156, 6596, 6811, 7079, 7233, 9525
-      },
-      /*Cb  qi=3  OC_MODE_GOLDEN_MV*/
-      {
-           29,  254,  777, 1690, 2963, 4444, 5823, 6719,
-         7044, 7279, 7391, 7463, 7255, 7705, 8388, 9719
-      }
-    },
-    {
-      /*Cr  qi=3  OC_MODE_INTRA*/
-      {
-          382, 1111, 1999, 2899, 3696, 4496, 5219, 5914,
-         6724, 7315, 7991, 8649, 9266,10080,10536,13102
-      },
-      /*Cr  qi=3  OC_MODE_INTER_NOMV*/
-      {
-           52,   75,  142,  313,  696, 1575, 2627, 3713,
-         4281, 4402, 4756, 4905, 5121, 5463, 5283, 4892
-      },
-      /*Cr  qi=3  OC_MODE_INTER_MV*/
-      {
-           26,  131,  356,  853, 1535, 2380, 3435, 4513,
-         5580, 6278, 6876, 7860, 7934, 8073, 8429, 9093
-      },
-      /*Cr  qi=3  OC_MDOE_INTER_MV_LAST*/
-      {
-           36,  136,  312,  807, 1454, 2266, 3410, 4564,
-         5749, 6650, 7202, 7999, 8513, 7783, 8245, 8183
-      },
-      /*Cr  qi=3  OC_MODE_INTER_MV_LAST2*/
-      {
-           32,  141,  323,  833, 1435, 2182, 3357, 4485,
-         5322, 6165, 6620, 7250, 7385, 6943, 6487, 5132
-      },
-      /*Cr  qi=3  OC_MODE_INTER_MV_FOUR*/
-      {
-           23,  141,  348,  905, 1622, 2435, 3505, 4601,
-         5540, 6360, 7200, 7930, 8305, 8722, 9172,10336
-      },
-      /*Cr  qi=3  OC_MODE_GOLDEN_NOMV*/
-      {
-          114,  153,  326,  646, 1003, 1983, 2982, 3309,
-         3355, 3728, 4404, 4711, 4799, 5294, 5145, 5354
-      },
-      /*Cr  qi=3  OC_MODE_GOLDEN_MV*/
-      {
-           27,  153,  338,  873, 1539, 2352, 3258, 4224,
-         4401, 4705, 4910, 4573, 5208, 5224, 5967, 5637
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=4  OC_MODE_INTRA*/
-      {
-          511,  703, 1587, 2424, 3173, 3989, 4808, 5576,
-         6361, 7098, 7829, 8475, 9120, 9804,10422,14518
-      },
-      /*Y'  qi=4  OC_MODE_INTER_NOMV*/
-      {
-           87,  111,  175,  467,  968, 1611, 2571, 3690,
-         4869, 6045, 7206, 8163, 8984, 9922,11129,15347
-      },
-      /*Y'  qi=4  OC_MODE_INTER_MV*/
-      {
-          246,  292,  364,  672, 1347, 2331, 3388, 4417,
-         5426, 6440, 7458, 8448, 9402,10269,11146,14476
-      },
-      /*Y'  qi=4  OC_MDOE_INTER_MV_LAST*/
-      {
-          204,  238,  298,  592, 1211, 2124, 3154, 4224,
-         5338, 6453, 7539, 8564, 9494,10406,11220,14512
-      },
-      /*Y'  qi=4  OC_MODE_INTER_MV_LAST2*/
-      {
-          236,  276,  320,  608, 1242, 2167, 3198, 4254,
-         5376, 6498, 7602, 8658, 9584,10446,11312,14719
-      },
-      /*Y'  qi=4  OC_MODE_INTER_MV_FOUR*/
-      {
-          268,  309,  372,  672, 1308, 2261, 3325, 4413,
-         5508, 6611, 7687, 8692, 9596,10438,11212,14062
-      },
-      /*Y'  qi=4  OC_MODE_GOLDEN_NOMV*/
-      {
-          272,  294,  548, 1152, 1956, 2593, 3259, 4076,
-         4980, 5882, 6433, 7054, 7451, 8481, 8794,15068
-      },
-      /*Y'  qi=4  OC_MODE_GOLDEN_MV*/
-      {
-          331,  350,  424,  887, 1552, 2335, 3271, 4398,
-         5547, 6708, 7840, 8861, 9834,10574,11312,14608
-      }
-    },
-    {
-      /*Cb  qi=4  OC_MODE_INTRA*/
-      {
-          520, 1397, 2685, 3843, 4991, 6209, 7247, 8176,
-         9180,10156,10968,11996,12606,13564,14262,17938
-      },
-      /*Cb  qi=4  OC_MODE_INTER_NOMV*/
-      {
-           68,  133,  463, 1233, 2487, 4478, 5937, 6962,
-         7729, 8181, 8416, 8688, 8225, 8525, 8918, 9004
-      },
-      /*Cb  qi=4  OC_MODE_INTER_MV*/
-      {
-           29,  250,  800, 1906, 3430, 5178, 6996, 8650,
-         9908,11034,11578,12568,13131,14065,14728,16652
-      },
-      /*Cb  qi=4  OC_MDOE_INTER_MV_LAST*/
-      {
-           42,  225,  775, 1753, 3075, 5003, 6918, 8521,
-         9899,11004,11951,12080,12037,13284,12832,12956
-      },
-      /*Cb  qi=4  OC_MODE_INTER_MV_LAST2*/
-      {
-           41,  244,  822, 1758, 3048, 5015, 6929, 8652,
-         9785,11063,11494,12384,12552,13532,14308,14735
-      },
-      /*Cb  qi=4  OC_MODE_INTER_MV_FOUR*/
-      {
-           25,  257,  829, 1847, 3226, 4942, 6621, 8169,
-         9457,10524,11416,12245,12874,13489,15075,16289
-      },
-      /*Cb  qi=4  OC_MODE_GOLDEN_NOMV*/
-      {
-          141,  338,  680, 1514, 2484, 3988, 5141, 5361,
-         5513, 6150, 6366, 6593, 6988, 7292, 7310, 9675
-      },
-      /*Cb  qi=4  OC_MODE_GOLDEN_MV*/
-      {
-           31,  275,  874, 1831, 3117, 4730, 6004, 6752,
-         7395, 7243, 7468, 7403, 7112, 7901, 8036, 9963
-      }
-    },
-    {
-      /*Cr  qi=4  OC_MODE_INTRA*/
-      {
-          396, 1163, 2080, 3011, 3826, 4652, 5397, 6117,
-         6947, 7556, 8181, 8926, 9527,10356,10821,13399
-      },
-      /*Cr  qi=4  OC_MODE_INTER_NOMV*/
-      {
-           55,   82,  163,  366,  803, 1739, 2867, 3973,
-         4345, 4699, 4970, 5063, 5176, 5286, 5835, 4720
-      },
-      /*Cr  qi=4  OC_MODE_INTER_MV*/
-      {
-           26,  143,  393,  909, 1581, 2419, 3622, 4808,
-         5690, 6499, 7464, 8205, 8752, 7905, 9340,10595
-      },
-      /*Cr  qi=4  OC_MDOE_INTER_MV_LAST*/
-      {
-           38,  148,  351,  885, 1561, 2442, 3682, 4848,
-         5969, 6948, 7431, 7702, 8547, 7014, 7022, 6058
-      },
-      /*Cr  qi=4  OC_MODE_INTER_MV_LAST2*/
-      {
-           37,  158,  354,  887, 1607, 2411, 3641, 4780,
-         5507, 6312, 6739, 7383, 7391, 7145, 6150, 6136
-      },
-      /*Cr  qi=4  OC_MODE_INTER_MV_FOUR*/
-      {
-           24,  156,  390,  983, 1760, 2647, 3746, 4811,
-         5751, 6662, 7414, 7934, 8548, 8762,10129,10869
-      },
-      /*Cr  qi=4  OC_MODE_GOLDEN_NOMV*/
-      {
-          122,  162,  326,  645, 1132, 2252, 3216, 3506,
-         3623, 3932, 4555, 4787, 4785, 5169, 5323, 5431
-      },
-      /*Cr  qi=4  OC_MODE_GOLDEN_MV*/
-      {
-           31,  167,  376,  934, 1656, 2468, 3440, 4376,
-         4490, 4649, 5167, 4780, 5140, 5584, 6055, 4984
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=5  OC_MODE_INTRA*/
-      {
-          521,  726, 1660, 2572, 3362, 4218, 5074, 5868,
-         6673, 7435, 8173, 8831, 9495,10186,10820,15020
-      },
-      /*Y'  qi=5  OC_MODE_INTER_NOMV*/
-      {
-           89,  114,  192,  542, 1087, 1829, 2902, 4122,
-         5364, 6602, 7790, 8764, 9549,10598,11823,15917
-      },
-      /*Y'  qi=5  OC_MODE_INTER_MV*/
-      {
-          255,  299,  381,  762, 1534, 2611, 3704, 4780,
-         5817, 6881, 7933, 8951, 9925,10797,11647,14990
-      },
-      /*Y'  qi=5  OC_MDOE_INTER_MV_LAST*/
-      {
-          207,  242,  318,  670, 1379, 2381, 3473, 4604,
-         5769, 6920, 8033, 9069,10026,10918,11737,15085
-      },
-      /*Y'  qi=5  OC_MODE_INTER_MV_LAST2*/
-      {
-          242,  271,  323,  672, 1403, 2409, 3499, 4634,
-         5802, 6980, 8096, 9145,10126,11014,11823,15271
-      },
-      /*Y'  qi=5  OC_MODE_INTER_MV_FOUR*/
-      {
-          277,  313,  392,  757, 1490, 2526, 3646, 4789,
-         5940, 7083, 8178, 9196,10124,10971,11739,14598
-      },
-      /*Y'  qi=5  OC_MODE_GOLDEN_NOMV*/
-      {
-          282,  282,  531, 1319, 2107, 2752, 3535, 4413,
-         5409, 6239, 6767, 7398, 7934, 8521, 9940,15622
-      },
-      /*Y'  qi=5  OC_MODE_GOLDEN_MV*/
-      {
-          339,  355,  453,  966, 1691, 2566, 3605, 4762,
-         5986, 7209, 8370, 9399,10370,11207,11933,15161
-      }
-    },
-    {
-      /*Cb  qi=5  OC_MODE_INTRA*/
-      {
-          530, 1447, 2810, 4029, 5212, 6457, 7496, 8481,
-         9501,10539,11376,12444,12994,13939,14711,18424
-      },
-      /*Cb  qi=5  OC_MODE_INTER_NOMV*/
-      {
-           70,  141,  509, 1407, 2806, 4909, 6182, 7359,
-         8041, 8497, 8715, 9058, 8768, 8760, 9306, 9412
-      },
-      /*Cb  qi=5  OC_MODE_INTER_MV*/
-      {
-           30,  270,  877, 2089, 3678, 5607, 7503, 9107,
-        10491,11593,11881,12986,13949,14005,15208,16496
-      },
-      /*Cb  qi=5  OC_MDOE_INTER_MV_LAST*/
-      {
-           42,  238,  857, 1938, 3348, 5424, 7381, 9053,
-        10373,11424,12375,12399,12894,13643,13428,13986
-      },
-      /*Cb  qi=5  OC_MODE_INTER_MV_LAST2*/
-      {
-           48,  262,  913, 1927, 3279, 5379, 7313, 9021,
-        10364,11507,11959,12239,14029,14040,13656,14941
-      },
-      /*Cb  qi=5  OC_MODE_INTER_MV_FOUR*/
-      {
-           27,  270,  912, 2027, 3481, 5270, 7028, 8623,
-         9827,10943,11917,12546,13483,14146,15172,17260
-      },
-      /*Cb  qi=5  OC_MODE_GOLDEN_NOMV*/
-      {
-          130,  329,  743, 1652, 2760, 4507, 5842, 5433,
-         5817, 6214, 6544, 6805, 7373, 7523, 7645,10070
-      },
-      /*Cb  qi=5  OC_MODE_GOLDEN_MV*/
-      {
-           33,  286,  958, 2017, 3417, 5085, 6378, 7122,
-         7562, 7943, 7607, 7800, 7972, 8534, 8719,10247
-      }
-    },
-    {
-      /*Cr  qi=5  OC_MODE_INTRA*/
-      {
-          406, 1213, 2167, 3138, 3991, 4851, 5631, 6398,
-         7206, 7854, 8484, 9343, 9987,10727,11196,13787
-      },
-      /*Cr  qi=5  OC_MODE_INTER_NOMV*/
-      {
-           57,   88,  180,  418,  922, 1953, 3157, 4270,
-         4563, 4909, 5131, 5338, 5594, 5782, 5498, 5065
-      },
-      /*Cr  qi=5  OC_MODE_INTER_MV*/
-      {
-           26,  152,  425, 1015, 1735, 2624, 4000, 5120,
-         6182, 7023, 7566, 8433, 9700, 8864, 8038,10979
-      },
-      /*Cr  qi=5  OC_MDOE_INTER_MV_LAST*/
-      {
-           38,  157,  381,  968, 1702, 2695, 4016, 5258,
-         6391, 7322, 7793, 7627, 8547, 7629, 7197, 5952
-      },
-      /*Cr  qi=5  OC_MODE_INTER_MV_LAST2*/
-      {
-           43,  170,  385,  964, 1790, 2678, 3903, 5002,
-         5877, 6687, 7070, 7039, 7370, 6540, 6556, 6066
-      },
-      /*Cr  qi=5  OC_MODE_INTER_MV_FOUR*/
-      {
-           25,  165,  423, 1079, 1932, 2909, 4047, 5148,
-         6175, 6990, 7633, 8490, 8885, 9437,10259,11937
-      },
-      /*Cr  qi=5  OC_MODE_GOLDEN_NOMV*/
-      {
-          116,  171,  342,  720, 1286, 2628, 3147, 3489,
-         3562, 4119, 4759, 4903, 4999, 5375, 5385, 5611
-      },
-      /*Cr  qi=5  OC_MODE_GOLDEN_MV*/
-      {
-           33,  179,  418, 1029, 1846, 2735, 3633, 4652,
-         4846, 5103, 5372, 4823, 5249, 5928, 5880, 5795
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=6  OC_MODE_INTRA*/
-      {
-          535,  748, 1714, 2666, 3494, 4385, 5271, 6085,
-         6920, 7699, 8456, 9118, 9789,10494,11132,15403
-      },
-      /*Y'  qi=6  OC_MODE_INTER_NOMV*/
-      {
-           93,  119,  212,  607, 1198, 2036, 3197, 4504,
-         5785, 7061, 8267, 9279,10198,11251,12276,16375
-      },
-      /*Y'  qi=6  OC_MODE_INTER_MV*/
-      {
-          270,  309,  407,  841, 1693, 2828, 3962, 5058,
-         6140, 7252, 8316, 9372,10302,11226,12078,15373
-      },
-      /*Y'  qi=6  OC_MDOE_INTER_MV_LAST*/
-      {
-          204,  244,  333,  729, 1519, 2597, 3739, 4917,
-         6124, 7308, 8434, 9481,10412,11353,12183,15482
-      },
-      /*Y'  qi=6  OC_MODE_INTER_MV_LAST2*/
-      {
-          241,  272,  337,  732, 1549, 2637, 3781, 4957,
-         6151, 7349, 8508, 9584,10498,11397,12239,15652
-      },
-      /*Y'  qi=6  OC_MODE_INTER_MV_FOUR*/
-      {
-          275,  317,  410,  824, 1638, 2751, 3921, 5113,
-         6301, 7472, 8592, 9615,10536,11379,12145,15016
-      },
-      /*Y'  qi=6  OC_MODE_GOLDEN_NOMV*/
-      {
-          298,  297,  619, 1363, 2259, 2927, 3776, 4648,
-         5719, 6519, 7073, 7709, 8174, 9022,10459,16031
-      },
-      /*Y'  qi=6  OC_MODE_GOLDEN_MV*/
-      {
-          340,  367,  473, 1038, 1821, 2773, 3876, 5111,
-         6376, 7624, 8761, 9829,10743,11555,12252,15572
-      }
-    },
-    {
-      /*Cb  qi=6  OC_MODE_INTRA*/
-      {
-          551, 1510, 2948, 4223, 5435, 6697, 7743, 8740,
-         9803,10874,11745,12851,13355,14281,15140,18896
-      },
-      /*Cb  qi=6  OC_MODE_INTER_NOMV*/
-      {
-           76,  164,  594, 1601, 3088, 5189, 6627, 7604,
-         8215, 8836, 9117, 9226, 8773, 9243, 9313, 9515
-      },
-      /*Cb  qi=6  OC_MODE_INTER_MV*/
-      {
-           31,  303,  980, 2269, 3973, 5950, 7900, 9489,
-        10875,11994,12666,13647,15488,14763,16044,17567
-      },
-      /*Cb  qi=6  OC_MDOE_INTER_MV_LAST*/
-      {
-           46,  270,  956, 2101, 3592, 5793, 7815, 9485,
-        10846,11871,12698,13022,13268,13535,13990,14401
-      },
-      /*Cb  qi=6  OC_MODE_INTER_MV_LAST2*/
-      {
-           52,  299, 1017, 2093, 3533, 5682, 7745, 9505,
-        10744,11983,12747,12484,14471,14406,15294,16275
-      },
-      /*Cb  qi=6  OC_MODE_INTER_MV_FOUR*/
-      {
-           29,  306, 1013, 2205, 3727, 5623, 7409, 9009,
-        10268,11393,12208,13012,13864,14694,14930,17693
-      },
-      /*Cb  qi=6  OC_MODE_GOLDEN_NOMV*/
-      {
-          133,  376,  812, 1766, 2963, 4821, 6427, 5958,
-         6140, 6554, 6890, 7219, 7574, 7779, 7946,10397
-      },
-      /*Cb  qi=6  OC_MODE_GOLDEN_MV*/
-      {
-           34,  324, 1057, 2178, 3630, 5426, 6819, 7534,
-         7855, 8144, 7953, 8086, 7928, 8224, 8204,10424
-      }
-    },
-    {
-      /*Cr  qi=6  OC_MODE_INTRA*/
-      {
-          417, 1276, 2300, 3320, 4209, 5104, 5910, 6742,
-         7569, 8255, 8861, 9717,10445,11219,11628,14270
-      },
-      /*Cr  qi=6  OC_MODE_INTER_NOMV*/
-      {
-           61,   96,  214,  518, 1149, 2246, 3808, 4540,
-         4940, 5097, 5320, 5498, 5799, 5941, 6036, 5180
-      },
-      /*Cr  qi=6  OC_MODE_INTER_MV*/
-      {
-           27,  168,  480, 1151, 1935, 3005, 4432, 5527,
-         6598, 7581, 8547, 8203, 8871, 9541, 8910,12025
-      },
-      /*Cr  qi=6  OC_MDOE_INTER_MV_LAST*/
-      {
-           40,  172,  431, 1094, 1935, 3063, 4454, 5709,
-         6916, 7693, 8313, 8147, 8063, 7824, 7565, 6179
-      },
-      /*Cr  qi=6  OC_MODE_INTER_MV_LAST2*/
-      {
-           46,  185,  435, 1099, 2038, 2998, 4460, 5545,
-         6368, 7124, 7701, 7687, 7638, 7109, 7179, 6673
-      },
-      /*Cr  qi=6  OC_MODE_INTER_MV_FOUR*/
-      {
-           27,  180,  485, 1229, 2155, 3223, 4475, 5568,
-         6580, 7479, 8226, 8901, 9630,10508,10550,12095
-      },
-      /*Cr  qi=6  OC_MODE_GOLDEN_NOMV*/
-      {
-          114,  182,  384,  846, 1418, 2587, 3213, 3860,
-         3780, 4407, 5062, 5140, 5318, 5710, 5593, 5837
-      },
-      /*Cr  qi=6  OC_MODE_GOLDEN_MV*/
-      {
-           33,  190,  475, 1168, 2043, 3001, 3985, 4935,
-         5063, 5163, 5699, 5507, 5451, 6608, 5813, 5751
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=7  OC_MODE_INTRA*/
-      {
-          548,  765, 1782, 2795, 3670, 4591, 5511, 6362,
-         7215, 8006, 8779, 9452,10131,10847,11482,15825
-      },
-      /*Y'  qi=7  OC_MODE_INTER_NOMV*/
-      {
-           95,  121,  229,  679, 1322, 2286, 3559, 4942,
-         6270, 7579, 8796, 9799,10792,11898,12802,16828
-      },
-      /*Y'  qi=7  OC_MODE_INTER_MV*/
-      {
-          259,  312,  427,  934, 1917, 3113, 4288, 5416,
-         6525, 7663, 8753, 9815,10741,11651,12473,15830
-      },
-      /*Y'  qi=7  OC_MDOE_INTER_MV_LAST*/
-      {
-          214,  248,  353,  813, 1704, 2861, 4054, 5278,
-         6526, 7738, 8875, 9933,10893,11806,12635,15935
-      },
-      /*Y'  qi=7  OC_MODE_INTER_MV_LAST2*/
-      {
-          243,  278,  365,  817, 1735, 2907, 4098, 5327,
-         6569, 7785, 8962,10002,10957,11891,12657,16149
-      },
-      /*Y'  qi=7  OC_MODE_INTER_MV_FOUR*/
-      {
-          277,  319,  432,  915, 1833, 3026, 4247, 5484,
-         6704, 7891, 9037,10079,10986,11853,12605,15434
-      },
-      /*Y'  qi=7  OC_MODE_GOLDEN_NOMV*/
-      {
-          284,  297,  689, 1487, 2308, 3063, 4067, 4975,
-         6095, 6931, 7424, 8022, 8395, 9433,11190,16480
-      },
-      /*Y'  qi=7  OC_MODE_GOLDEN_MV*/
-      {
-          347,  356,  510, 1127, 1977, 3023, 4199, 5477,
-         6778, 8045, 9226,10298,11104,11995,12715,15999
-      }
-    },
-    {
-      /*Cb  qi=7  OC_MODE_INTRA*/
-      {
-          578, 1575, 3050, 4366, 5618, 6898, 7971, 9005,
-        10062,11237,12115,13169,13758,14578,15545,19337
-      },
-      /*Cb  qi=7  OC_MODE_INTER_NOMV*/
-      {
-           78,  178,  646, 1746, 3412, 5452, 6861, 7915,
-         8721, 9082, 9014, 9508, 9311, 9216, 9590, 9709
-      },
-      /*Cb  qi=7  OC_MODE_INTER_MV*/
-      {
-           32,  328, 1052, 2423, 4211, 6392, 8329,10020,
-        11320,12335,13187,13673,14507,15569,15613,17477
-      },
-      /*Cb  qi=7  OC_MDOE_INTER_MV_LAST*/
-      {
-           48,  293, 1028, 2245, 3815, 6137, 8174, 9877,
-        11138,12262,12871,13341,13603,14971,14591,14952
-      },
-      /*Cb  qi=7  OC_MODE_INTER_MV_LAST2*/
-      {
-           56,  321, 1095, 2231, 3726, 6046, 8057, 9855,
-        11066,12240,13138,12724,14364,15267,15743,16337
-      },
-      /*Cb  qi=7  OC_MODE_INTER_MV_FOUR*/
-      {
-           33,  333, 1088, 2342, 3949, 5906, 7760, 9331,
-        10671,11771,12918,13478,14038,14750,15301,17891
-      },
-      /*Cb  qi=7  OC_MODE_GOLDEN_NOMV*/
-      {
-          132,  403,  848, 1854, 3147, 5245, 6528, 5879,
-         6302, 6808, 7233, 7617, 7733, 8331, 8001,10520
-      },
-      /*Cb  qi=7  OC_MODE_GOLDEN_MV*/
-      {
-           39,  343, 1133, 2343, 3857, 5663, 6881, 7622,
-         8006, 8245, 7893, 8273, 7969, 8364, 8803,10610
-      }
-    },
-    {
-      /*Cr  qi=7  OC_MODE_INTRA*/
-      {
-          435, 1319, 2374, 3426, 4349, 5261, 6080, 6933,
-         7785, 8498, 9065, 9934,10697,11441,11879,14561
-      },
-      /*Cr  qi=7  OC_MODE_INTER_NOMV*/
-      {
-           62,  100,  229,  561, 1287, 2464, 4093, 4719,
-         4999, 5342, 5618, 5631, 6062, 5827, 6099, 5207
-      },
-      /*Cr  qi=7  OC_MODE_INTER_MV*/
-      {
-           27,  176,  517, 1225, 2088, 3157, 4633, 5865,
-         6870, 7862, 8407, 8405, 9364, 9164,10974,10981
-      },
-      /*Cr  qi=7  OC_MDOE_INTER_MV_LAST*/
-      {
-           42,  183,  461, 1171, 2074, 3287, 4725, 6016,
-         7165, 8073, 8222, 8227, 8760, 7649, 7481, 6486
-      },
-      /*Cr  qi=7  OC_MODE_INTER_MV_LAST2*/
-      {
-           48,  196,  468, 1177, 2131, 3289, 4672, 5678,
-         6620, 7506, 7733, 7743, 7971, 7608, 8029, 6429
-      },
-      /*Cr  qi=7  OC_MODE_INTER_MV_FOUR*/
-      {
-           29,  191,  520, 1314, 2304, 3427, 4743, 5874,
-         6876, 7810, 8591, 9553, 9902,10356,11418,12678
-      },
-      /*Cr  qi=7  OC_MODE_GOLDEN_NOMV*/
-      {
-          116,  195,  422,  915, 1502, 2431, 3299, 3742,
-         3971, 4774, 4878, 5258, 5430, 5410, 6139, 5936
-      },
-      /*Cr  qi=7  OC_MODE_GOLDEN_MV*/
-      {
-           36,  196,  500, 1227, 2192, 3194, 4268, 5204,
-         5219, 5398, 5565, 5405, 5769, 6391, 6147, 5729
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=8  OC_MODE_INTRA*/
-      {
-          562,  790, 1842, 2922, 3842, 4793, 5749, 6624,
-         7506, 8313, 9097, 9774,10459,11206,11844,16218
-      },
-      /*Y'  qi=8  OC_MODE_INTER_NOMV*/
-      {
-          101,  131,  264,  784, 1491, 2573, 3953, 5391,
-         6735, 8069, 9312,10306,11378,12442,13626,17294
-      },
-      /*Y'  qi=8  OC_MODE_INTER_MV*/
-      {
-          266,  326,  471, 1054, 2147, 3392, 4597, 5729,
-         6881, 8022, 9166,10225,11196,12115,12948,16248
-      },
-      /*Y'  qi=8  OC_MDOE_INTER_MV_LAST*/
-      {
-          221,  254,  375,  897, 1897, 3130, 4383, 5669,
-         6966, 8227, 9390,10453,11417,12312,13149,16452
-      },
-      /*Y'  qi=8  OC_MODE_INTER_MV_LAST2*/
-      {
-          251,  294,  424,  956, 1976, 3215, 4441, 5713,
-         6972, 8184, 9332,10382,11327,12242,13047,16509
-      },
-      /*Y'  qi=8  OC_MODE_INTER_MV_FOUR*/
-      {
-          285,  329,  465, 1015, 2036, 3300, 4581, 5868,
-         7126, 8344, 9498,10530,11456,12292,13037,15817
-      },
-      /*Y'  qi=8  OC_MODE_GOLDEN_NOMV*/
-      {
-          304,  307,  727, 1606, 2471, 3276, 4359, 5375,
-         6545, 7275, 7754, 8512, 8945, 9537,12077,16894
-      },
-      /*Y'  qi=8  OC_MODE_GOLDEN_MV*/
-      {
-          373,  372,  570, 1270, 2166, 3295, 4532, 5890,
-         7245, 8530, 9737,10784,11665,12491,13186,16377
-      }
-    },
-    {
-      /*Cb  qi=8  OC_MODE_INTRA*/
-      {
-          612, 1696, 3272, 4668, 5982, 7274, 8378, 9437,
-        10479,11750,12631,13640,14329,15060,16043,19886
-      },
-      /*Cb  qi=8  OC_MODE_INTER_NOMV*/
-      {
-           83,  203,  763, 2035, 3871, 5784, 7451, 8681,
-        10213,12002,11900,11320,11930,12408,10549, 7446
-      },
-      /*Cb  qi=8  OC_MODE_INTER_MV*/
-      {
-           33,  377, 1214, 2713, 4582, 6847, 8871,10571,
-        11871,13066,14081,14684,15172,16096,15613,17972
-      },
-      /*Cb  qi=8  OC_MDOE_INTER_MV_LAST*/
-      {
-           58,  344, 1214, 2529, 4200, 6689, 8759,10335,
-        11390,11881,11823,11981,11073,10764,10918,10280
-      },
-      /*Cb  qi=8  OC_MODE_INTER_MV_LAST2*/
-      {
-           55,  366, 1264, 2567, 4252, 6698, 8706,10572,
-        11852,12920,13168,13724,14546,15601,16427,16842
-      },
-      /*Cb  qi=8  OC_MODE_INTER_MV_FOUR*/
-      {
-           38,  388, 1267, 2640, 4316, 6393, 8236, 9822,
-        11113,12171,13105,13822,14769,15540,16011,18461
-      },
-      /*Cb  qi=8  OC_MODE_GOLDEN_NOMV*/
-      {
-          131,  460,  965, 2172, 3563, 5959, 6333, 6291,
-         6630, 7185, 7626, 8132, 8148, 8435, 8372,10536
-      },
-      /*Cb  qi=8  OC_MODE_GOLDEN_MV*/
-      {
-           42,  405, 1317, 2640, 4224, 6195, 7213, 8034,
-         8064, 8514, 8060, 8441, 8294, 8444, 8803,10454
-      }
-    },
-    {
-      /*Cr  qi=8  OC_MODE_INTRA*/
-      {
-          451, 1387, 2495, 3583, 4536, 5479, 6313, 7188,
-         8055, 8769, 9363,10252,11061,11738,12235,14983
-      },
-      /*Cr  qi=8  OC_MODE_INTER_NOMV*/
-      {
-           66,  109,  260,  633, 1405, 2679, 4375, 4885,
-         5414, 5939, 6845, 7824, 7937, 6923, 8967, 6027
-      },
-      /*Cr  qi=8  OC_MODE_INTER_MV*/
-      {
-           27,  193,  575, 1344, 2255, 3487, 5071, 6218,
-         7239, 8243, 8876, 9292, 9720, 8756,10391,11109
-      },
-      /*Cr  qi=8  OC_MDOE_INTER_MV_LAST*/
-      {
-           49,  203,  510, 1281, 2271, 3544, 5005, 6187,
-         7031, 7422, 7296, 6922, 6715, 6833, 6994, 5814
-      },
-      /*Cr  qi=8  OC_MODE_INTER_MV_LAST2*/
-      {
-           45,  209,  527, 1321, 2290, 3516, 4972, 6072,
-         6901, 7350, 7296, 7321, 8406, 6898, 6931, 7460
-      },
-      /*Cr  qi=8  OC_MODE_INTER_MV_FOUR*/
-      {
-           31,  211,  577, 1439, 2511, 3717, 5050, 6167,
-         7085, 7967, 8704, 9383,10441,10688,11291,12481
-      },
-      /*Cr  qi=8  OC_MODE_GOLDEN_NOMV*/
-      {
-          112,  209,  491, 1044, 1675, 2875, 3332, 4103,
-         4262, 5162, 5069, 5549, 5605, 5795, 5852, 6134
-      },
-      /*Cr  qi=8  OC_MODE_GOLDEN_MV*/
-      {
-           40,  223,  556, 1362, 2360, 3437, 4598, 5022,
-         5211, 5574, 5272, 5393, 5741, 5726, 5955, 5582
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=9  OC_MODE_INTRA*/
-      {
-          583,  823, 1954, 3146, 4114, 5110, 6098, 7001,
-         7902, 8716, 9516,10191,10894,11647,12297,16748
-      },
-      /*Y'  qi=9  OC_MODE_INTER_NOMV*/
-      {
-          102,  134,  304,  897, 1708, 2955, 4448, 5946,
-         7317, 8681, 9869,10884,11713,12906,14232,17956
-      },
-      /*Y'  qi=9  OC_MODE_INTER_MV*/
-      {
-          267,  329,  521, 1239, 2421, 3782, 4998, 6195,
-         7407, 8594, 9701,10739,11722,12651,13557,16726
-      },
-      /*Y'  qi=9  OC_MDOE_INTER_MV_LAST*/
-      {
-          225,  262,  423, 1053, 2183, 3498, 4805, 6137,
-         7470, 8750, 9918,11007,11946,12870,13657,16992
-      },
-      /*Y'  qi=9  OC_MODE_INTER_MV_LAST2*/
-      {
-          243,  300,  474, 1119, 2276, 3591, 4879, 6176,
-         7479, 8725, 9905,10942,11908,12829,13592,17087
-      },
-      /*Y'  qi=9  OC_MODE_INTER_MV_FOUR*/
-      {
-          292,  336,  522, 1192, 2342, 3676, 5014, 6348,
-         7643, 8874,10045,11083,11986,12831,13590,16379
-      },
-      /*Y'  qi=9  OC_MODE_GOLDEN_NOMV*/
-      {
-          291,  333,  823, 1778, 2652, 3561, 4717, 5839,
-         6951, 7717, 8308, 8669, 9684,10657,12384,17450
-      },
-      /*Y'  qi=9  OC_MODE_GOLDEN_MV*/
-      {
-          362,  378,  616, 1398, 2427, 3650, 4961, 6373,
-         7779, 9115,10267,11337,12205,13010,13669,16908
-      }
-    },
-    {
-      /*Cb  qi=9  OC_MODE_INTRA*/
-      {
-          631, 1766, 3404, 4886, 6261, 7559, 8690, 9749,
-        10829,12169,13059,14081,14709,15468,16505,20330
-      },
-      /*Cb  qi=9  OC_MODE_INTER_NOMV*/
-      {
-           86,  217,  844, 2284, 4217, 6245, 7901, 9038,
-        11119,12379,12070,11851,12745,12266,11269, 7327
-      },
-      /*Cb  qi=9  OC_MODE_INTER_MV*/
-      {
-           38,  413, 1345, 2961, 4938, 7331, 9416,11071,
-        12432,13264,13984,15158,15082,17712,17441,18168
-      },
-      /*Cb  qi=9  OC_MDOE_INTER_MV_LAST*/
-      {
-           59,  370, 1338, 2772, 4538, 7174, 9279,10844,
-        11850,12375,12193,12246,11251,11034,11021,10726
-      },
-      /*Cb  qi=9  OC_MODE_INTER_MV_LAST2*/
-      {
-           60,  395, 1392, 2817, 4626, 7159, 9320,11050,
-        12307,13338,14330,14130,15615,17268,15844,16476
-      },
-      /*Cb  qi=9  OC_MODE_INTER_MV_FOUR*/
-      {
-           41,  415, 1388, 2880, 4654, 6823, 8766,10387,
-        11649,12827,13823,14349,14962,15954,16932,19138
-      },
-      /*Cb  qi=9  OC_MODE_GOLDEN_NOMV*/
-      {
-          144,  479, 1057, 2382, 4162, 5999, 6231, 6296,
-         6958, 7236, 8314, 8275, 8586, 8687, 8694,10895
-      },
-      /*Cb  qi=9  OC_MODE_GOLDEN_MV*/
-      {
-           45,  460, 1453, 2878, 4553, 6534, 7715, 8300,
-         8421, 8778, 8562, 8913, 8670, 8944, 9391,10824
-      }
-    },
-    {
-      /*Cr  qi=9  OC_MODE_INTRA*/
-      {
-          467, 1460, 2618, 3746, 4739, 5704, 6588, 7470,
-         8361, 9072, 9659,10533,11398,11958,12557,15329
-      },
-      /*Cr  qi=9  OC_MODE_INTER_NOMV*/
-      {
-           67,  118,  290,  723, 1600, 3145, 4706, 5334,
-         5873, 6266, 7165, 7962, 7729, 8448, 8588, 5948
-      },
-      /*Cr  qi=9  OC_MODE_INTER_MV*/
-      {
-           30,  212,  627, 1492, 2508, 3831, 5434, 6536,
-         7643, 8910, 8868, 9374, 9772, 9712,11167,11630
-      },
-      /*Cr  qi=9  OC_MDOE_INTER_MV_LAST*/
-      {
-           51,  215,  560, 1419, 2481, 3866, 5364, 6551,
-         7349, 7692, 7274, 7120, 6874, 6655, 7142, 6065
-      },
-      /*Cr  qi=9  OC_MODE_INTER_MV_LAST2*/
-      {
-           49,  223,  587, 1452, 2495, 3803, 5270, 6409,
-         7096, 7424, 7607, 7800, 7361, 7250, 7654, 7824
-      },
-      /*Cr  qi=9  OC_MODE_INTER_MV_FOUR*/
-      {
-           34,  227,  633, 1584, 2706, 3993, 5345, 6491,
-         7505, 8370, 9124, 9898,10980,10596,12049,13587
-      },
-      /*Cr  qi=9  OC_MODE_GOLDEN_NOMV*/
-      {
-          120,  237,  549, 1206, 1914, 2950, 3680, 4144,
-         4524, 4906, 5409, 5483, 5581, 6060, 5839, 6292
-      },
-      /*Cr  qi=9  OC_MODE_GOLDEN_MV*/
-      {
-           45,  245,  616, 1495, 2593, 3703, 4877, 5221,
-         5443, 5546, 5474, 5663, 5779, 6191, 5957, 5800
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=10  OC_MODE_INTRA*/
-      {
-          592,  846, 1981, 3196, 4189, 5213, 6215, 7133,
-         8041, 8869, 9676,10362,11063,11820,12489,17017
-      },
-      /*Y'  qi=10  OC_MODE_INTER_NOMV*/
-      {
-          106,  140,  333,  967, 1819, 3120, 4664, 6178,
-         7568, 8937,10127,11138,11992,13342,14563,18285
-      },
-      /*Y'  qi=10  OC_MODE_INTER_MV*/
-      {
-          287,  343,  546, 1306, 2574, 3931, 5198, 6413,
-         7629, 8825, 9963,11000,11964,12913,13737,17069
-      },
-      /*Y'  qi=10  OC_MDOE_INTER_MV_LAST*/
-      {
-          221,  268,  442, 1112, 2296, 3648, 4987, 6345,
-         7699, 8983,10161,11248,12195,13123,13927,17311
-      },
-      /*Y'  qi=10  OC_MODE_INTER_MV_LAST2*/
-      {
-          261,  306,  492, 1180, 2392, 3740, 5065, 6380,
-         7701, 8968,10161,11225,12122,13081,13829,17412
-      },
-      /*Y'  qi=10  OC_MODE_INTER_MV_FOUR*/
-      {
-          302,  343,  541, 1246, 2450, 3825, 5192, 6549,
-         7863, 9112,10295,11313,12240,13075,13830,16660
-      },
-      /*Y'  qi=10  OC_MODE_GOLDEN_NOMV*/
-      {
-          310,  341,  817, 1834, 2694, 3712, 4879, 6058,
-         7196, 7960, 8486, 8868, 9703,10837,12813,17824
-      },
-      /*Y'  qi=10  OC_MODE_GOLDEN_MV*/
-      {
-          353,  379,  641, 1465, 2535, 3782, 5137, 6586,
-         7995, 9353,10543,11643,12573,13469,14156,17511
-      }
-    },
-    {
-      /*Cb  qi=10  OC_MODE_INTRA*/
-      {
-          644, 1789, 3424, 4917, 6289, 7592, 8731, 9791,
-        10880,12194,13104,14107,14789,15539,16546,20340
-      },
-      /*Cb  qi=10  OC_MODE_INTER_NOMV*/
-      {
-           88,  227,  869, 2320, 4281, 6210, 7953, 9428,
-        10073,12490,12040,12486,12938,12168,12805, 7137
-      },
-      /*Cb  qi=10  OC_MODE_INTER_MV*/
-      {
-           36,  421, 1375, 2999, 5010, 7425, 9547,11201,
-        12589,14006,14252,14613,15709,17649,17098,18775
-      },
-      /*Cb  qi=10  OC_MDOE_INTER_MV_LAST*/
-      {
-           62,  380, 1366, 2809, 4576, 7215, 9306,10903,
-        11943,12417,12474,12645,11730,11248,11707,11106
-      },
-      /*Cb  qi=10  OC_MODE_INTER_MV_LAST2*/
-      {
-           63,  401, 1424, 2848, 4655, 7209, 9333,11107,
-        12430,13447,15432,15722,16103,15374,17623,17061
-      },
-      /*Cb  qi=10  OC_MODE_INTER_MV_FOUR*/
-      {
-           42,  425, 1409, 2910, 4686, 6867, 8823,10475,
-        11677,12806,13956,14556,14898,16552,17390,19429
-      },
-      /*Cb  qi=10  OC_MODE_GOLDEN_NOMV*/
-      {
-          163,  489, 1088, 2440, 4169, 5996, 6240, 6662,
-         7167, 7603, 8353, 8363, 8532, 9065, 8831,11131
-      },
-      /*Cb  qi=10  OC_MODE_GOLDEN_MV*/
-      {
-           48,  464, 1472, 2914, 4590, 6862, 8706, 9723,
-        10641,10117,10307,10250, 9007,12307,10550, 9113
-      }
-    },
-    {
-      /*Cr  qi=10  OC_MODE_INTRA*/
-      {
-          476, 1501, 2682, 3823, 4837, 5830, 6724, 7628,
-         8566, 9257, 9869,10750,11666,12213,12857,15631
-      },
-      /*Cr  qi=10  OC_MODE_INTER_NOMV*/
-      {
-           70,  128,  322,  795, 1743, 3412, 4841, 5507,
-         6072, 6585, 6805, 7446, 7868, 9084, 8101, 6417
-      },
-      /*Cr  qi=10  OC_MODE_INTER_MV*/
-      {
-           29,  230,  670, 1545, 2609, 4029, 5639, 6750,
-         7896, 8425, 9102, 9378, 9319,10298,10303,13429
-      },
-      /*Cr  qi=10  OC_MDOE_INTER_MV_LAST*/
-      {
-           55,  229,  597, 1502, 2650, 4075, 5584, 6835,
-         7613, 7863, 7482, 7200, 6998, 7480, 7393, 6369
-      },
-      /*Cr  qi=10  OC_MODE_INTER_MV_LAST2*/
-      {
-           54,  240,  630, 1560, 2701, 4035, 5560, 6553,
-         7327, 7937, 7506, 8733, 8040, 6384, 7895, 8749
-      },
-      /*Cr  qi=10  OC_MODE_INTER_MV_FOUR*/
-      {
-           36,  243,  675, 1674, 2847, 4202, 5562, 6713,
-         7737, 8651, 9498,10123,10973,11042,12613,14092
-      },
-      /*Cr  qi=10  OC_MODE_GOLDEN_NOMV*/
-      {
-          126,  244,  587, 1253, 2109, 3204, 4063, 4400,
-         4792, 4870, 5738, 5760, 5861, 6402, 6490, 6733
-      },
-      /*Cr  qi=10  OC_MODE_GOLDEN_MV*/
-      {
-           48,  255,  642, 1602, 2798, 4018, 5571, 6216,
-         7695, 6689, 7023, 7240, 7011, 9217, 8570, 8429
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=11  OC_MODE_INTRA*/
-      {
-          609,  871, 2061, 3353, 4392, 5457, 6498, 7447,
-         8373, 9212,10038,10734,11446,12223,12862,17460
-      },
-      /*Y'  qi=11  OC_MODE_INTER_NOMV*/
-      {
-          108,  142,  376, 1072, 2038, 3503, 5142, 6680,
-         8103, 9464,10705,11756,12711,13997,15048,18940
-      },
-      /*Y'  qi=11  OC_MODE_INTER_MV*/
-      {
-          301,  351,  596, 1471, 2818, 4245, 5546, 6791,
-         8025, 9257,10441,11496,12474,13421,14257,17510
-      },
-      /*Y'  qi=11  OC_MDOE_INTER_MV_LAST*/
-      {
-          232,  272,  482, 1253, 2565, 3993, 5389, 6802,
-         8185, 9484,10683,11741,12715,13624,14395,17747
-      },
-      /*Y'  qi=11  OC_MODE_INTER_MV_LAST2*/
-      {
-          265,  311,  532, 1321, 2654, 4087, 5457, 6821,
-         8150, 9417,10613,11647,12574,13487,14274,17831
-      },
-      /*Y'  qi=11  OC_MODE_INTER_MV_FOUR*/
-      {
-          310,  347,  593, 1406, 2729, 4175, 5607, 7005,
-         8349, 9600,10797,11826,12748,13552,14316,17104
-      },
-      /*Y'  qi=11  OC_MODE_GOLDEN_NOMV*/
-      {
-          303,  332,  921, 2022, 2900, 4068, 5358, 6562,
-         7605, 8480, 8884, 9320, 9835,11589,13177,18244
-      },
-      /*Y'  qi=11  OC_MODE_GOLDEN_MV*/
-      {
-          394,  397,  723, 1627, 2790, 4139, 5543, 7042,
-         8507, 9849,11042,12106,13034,13822,14519,17647
-      }
-    },
-    {
-      /*Cb  qi=11  OC_MODE_INTRA*/
-      {
-          693, 1940, 3661, 5256, 6684, 8019, 9166,10216,
-        11394,12742,13706,14690,15430,16118,17135,21064
-      },
-      /*Cb  qi=11  OC_MODE_INTER_NOMV*/
-      {
-           96,  266, 1021, 2689, 4805, 6688, 8445, 9490,
-        10985,13177,12478,13909,12860,13041,11786, 7035
-      },
-      /*Cb  qi=11  OC_MODE_INTER_MV*/
-      {
-           39,  475, 1548, 3354, 5461, 8089,10157,11911,
-        13192,14418,14652,15775,17096,17397,19344,20330
-      },
-      /*Cb  qi=11  OC_MDOE_INTER_MV_LAST*/
-      {
-           70,  437, 1596, 3164, 5028, 7826, 9929,11482,
-        12453,12953,12791,12958,11968,11597,11851,11435
-      },
-      /*Cb  qi=11  OC_MODE_INTER_MV_LAST2*/
-      {
-           71,  465, 1656, 3186, 5104, 7777, 9953,11895,
-        12876,14244,16218,15200,16101,16815,19361,19582
-      },
-      /*Cb  qi=11  OC_MODE_INTER_MV_FOUR*/
-      {
-           48,  487, 1624, 3271, 5154, 7429, 9419,11158,
-        12392,13468,14557,15151,15595,16701,18737,20143
-      },
-      /*Cb  qi=11  OC_MODE_GOLDEN_NOMV*/
-      {
-          163,  542, 1237, 2823, 4347, 6147, 6403, 6720,
-         7445, 8089, 8652, 8883, 9220, 9450, 9159,11573
-      },
-      /*Cb  qi=11  OC_MODE_GOLDEN_MV*/
-      {
-           54,  538, 1707, 3264, 5039, 7180, 8390, 8974,
-         8873, 9230, 9298, 9573, 9185, 9615,10330,11284
-      }
-    },
-    {
-      /*Cr  qi=11  OC_MODE_INTRA*/
-      {
-          497, 1589, 2837, 4019, 5073, 6100, 7036, 7965,
-         8896, 9606,10314,11131,12062,12583,13221,16195
-      },
-      /*Cr  qi=11  OC_MODE_INTER_NOMV*/
-      {
-           72,  140,  366,  918, 2024, 3802, 5152, 5530,
-         6154, 6525, 7951, 7934, 8668, 7936, 9412, 6516
-      },
-      /*Cr  qi=11  OC_MODE_INTER_MV*/
-      {
-           31,  246,  731, 1706, 2858, 4487, 6039, 7345,
-         8205, 9376, 9989, 9855,10542,11663,10961,12939
-      },
-      /*Cr  qi=11  OC_MDOE_INTER_MV_LAST*/
-      {
-           59,  247,  660, 1693, 2959, 4503, 6065, 7247,
-         7959, 8239, 7841, 7423, 7232, 7390, 7523, 6570
-      },
-      /*Cr  qi=11  OC_MODE_INTER_MV_LAST2*/
-      {
-           58,  259,  699, 1749, 3020, 4428, 5974, 7179,
-         7875, 8188, 7727, 8509, 7490, 8309, 8743, 9875
-      },
-      /*Cr  qi=11  OC_MODE_INTER_MV_FOUR*/
-      {
-           40,  264,  758, 1857, 3119, 4558, 5985, 7178,
-         8235, 9133,10110,10709,11655,12467,13190,14572
-      },
-      /*Cr  qi=11  OC_MODE_GOLDEN_NOMV*/
-      {
-          136,  275,  638, 1272, 2450, 3388, 4233, 4688,
-         4623, 5392, 5578, 5633, 6320, 6368, 6640, 6784
-      },
-      /*Cr  qi=11  OC_MODE_GOLDEN_MV*/
-      {
-           51,  279,  707, 1770, 2996, 4290, 5388, 5724,
-         5922, 5936, 6155, 6146, 6570, 6840, 7133, 7304
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=12  OC_MODE_INTRA*/
-      {
-          639,  929, 2209, 3638, 4750, 5865, 6943, 7921,
-         8870, 9737,10574,11281,12011,12796,13447,18159
-      },
-      /*Y'  qi=12  OC_MODE_INTER_NOMV*/
-      {
-          115,  158,  484, 1296, 2430, 4093, 5840, 7416,
-         8877,10230,11423,12631,13617,14874,15771,20116
-      },
-      /*Y'  qi=12  OC_MODE_INTER_MV*/
-      {
-          304,  368,  709, 1785, 3304, 4743, 6119, 7432,
-         8701, 9950,11131,12181,13147,14099,14928,18197
-      },
-      /*Y'  qi=12  OC_MDOE_INTER_MV_LAST*/
-      {
-          239,  286,  579, 1522, 2999, 4507, 5978, 7434,
-         8851,10169,11377,12426,13380,14289,15085,18421
-      },
-      /*Y'  qi=12  OC_MODE_INTER_MV_LAST2*/
-      {
-          265,  324,  633, 1599, 3082, 4600, 6044, 7449,
-         8808,10114,11271,12351,13274,14190,14984,18488
-      },
-      /*Y'  qi=12  OC_MODE_INTER_MV_FOUR*/
-      {
-          315,  365,  696, 1669, 3146, 4685, 6195, 7642,
-         9014,10313,11507,12514,13437,14268,15009,17771
-      },
-      /*Y'  qi=12  OC_MODE_GOLDEN_NOMV*/
-      {
-          324,  383, 1107, 2232, 3243, 4588, 5911, 7087,
-         8248, 9059, 9377, 9871,10916,12179,13513,18885
-      },
-      /*Y'  qi=12  OC_MODE_GOLDEN_MV*/
-      {
-          368,  419,  863, 1881, 3189, 4650, 6184, 7747,
-         9250,10620,11711,12801,13683,14462,15036,18301
-      }
-    },
-    {
-      /*Cb  qi=12  OC_MODE_INTRA*/
-      {
-          731, 2045, 3839, 5541, 7015, 8373, 9516,10570,
-        11796,13154,14124,15270,15980,16650,17728,21647
-      },
-      /*Cb  qi=12  OC_MODE_INTER_NOMV*/
-      {
-          109,  325, 1182, 2978, 5199, 7122, 8660,10054,
-        11083,14580,12600,13009,12892,12674,12186, 6210
-      },
-      /*Cb  qi=12  OC_MODE_INTER_MV*/
-      {
-           39,  547, 1729, 3675, 5946, 8682,10819,12640,
-        14064,14963,15087,15897,16347,18103,19644,20596
-      },
-      /*Cb  qi=12  OC_MDOE_INTER_MV_LAST*/
-      {
-           76,  504, 1783, 3477, 5479, 8369,10488,12015,
-        12987,13180,13226,13230,12260,12063,12157,11790
-      },
-      /*Cb  qi=12  OC_MODE_INTER_MV_LAST2*/
-      {
-           79,  533, 1857, 3497, 5550, 8317,10570,12371,
-        13621,14433,14818,14233,14476,18431,17887,16163
-      },
-      /*Cb  qi=12  OC_MODE_INTER_MV_FOUR*/
-      {
-           54,  554, 1811, 3544, 5489, 7910, 9927,11577,
-        12816,13795,15363,15520,16332,18049,18804,20224
-      },
-      /*Cb  qi=12  OC_MODE_GOLDEN_NOMV*/
-      {
-          171,  610, 1383, 2946, 4822, 6475, 6610, 7061,
-         7561, 8587, 8755, 9427, 9492, 9711, 9637,11734
-      },
-      /*Cb  qi=12  OC_MODE_GOLDEN_MV*/
-      {
-           56,  609, 1911, 3568, 5487, 7692, 8683, 9269,
-         9399, 9972, 9441, 9745, 9579, 9723,10227,11619
-      }
-    },
-    {
-      /*Cr  qi=12  OC_MODE_INTRA*/
-      {
-          525, 1688, 2993, 4214, 5301, 6380, 7354, 8309,
-         9237, 9931,10648,11575,12404,12958,13602,16716
-      },
-      /*Cr  qi=12  OC_MODE_INTER_NOMV*/
-      {
-           80,  166,  438, 1073, 2322, 4198, 5594, 5765,
-         5867, 6561, 7579, 7954, 9573, 8488, 8417, 6513
-      },
-      /*Cr  qi=12  OC_MODE_INTER_MV*/
-      {
-           33,  288,  826, 1872, 3136, 4829, 6471, 7702,
-         8412, 9640,10252,10588,11416,11416,11996,14060
-      },
-      /*Cr  qi=12  OC_MDOE_INTER_MV_LAST*/
-      {
-           65,  284,  747, 1885, 3268, 4907, 6492, 7637,
-         8333, 8485, 7889, 7514, 7409, 7549, 7443, 6548
-      },
-      /*Cr  qi=12  OC_MODE_INTER_MV_LAST2*/
-      {
-           64,  295,  794, 1931, 3266, 4821, 6442, 7481,
-         8139, 8441, 7925, 7504, 7445, 7529, 7249, 6060
-      },
-      /*Cr  qi=12  OC_MODE_INTER_MV_FOUR*/
-      {
-           46,  303,  845, 2057, 3422, 4968, 6400, 7585,
-         8693, 9470,10382,11354,11930,12255,13511,14946
-      },
-      /*Cr  qi=12  OC_MODE_GOLDEN_NOMV*/
-      {
-          144,  312,  775, 1364, 2823, 3992, 4396, 4874,
-         4744, 5534, 5779, 6006, 6358, 6475, 6920, 6974
-      },
-      /*Cr  qi=12  OC_MODE_GOLDEN_MV*/
-      {
-           55,  324,  810, 1955, 3306, 4686, 5572, 6063,
-         6126, 6314, 6418, 6359, 6581, 6856, 6891, 6586
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=13  OC_MODE_INTRA*/
-      {
-          658,  965, 2286, 3824, 4982, 6128, 7236, 8238,
-         9200,10080,10937,11647,12392,13183,13862,18635
-      },
-      /*Y'  qi=13  OC_MODE_INTER_NOMV*/
-      {
-          118,  164,  545, 1435, 2710, 4513, 6324, 7931,
-         9388,10719,11901,13114,14223,15447,16266,20612
-      },
-      /*Y'  qi=13  OC_MODE_INTER_MV*/
-      {
-          309,  380,  801, 2022, 3582, 5065, 6448, 7798,
-         9105,10376,11596,12648,13626,14562,15400,18647
-      },
-      /*Y'  qi=13  OC_MDOE_INTER_MV_LAST*/
-      {
-          247,  292,  641, 1718, 3303, 4868, 6380, 7884,
-         9323,10637,11855,12876,13876,14780,15565,18913
-      },
-      /*Y'  qi=13  OC_MODE_INTER_MV_LAST2*/
-      {
-          269,  335,  703, 1804, 3389, 4969, 6483, 7915,
-         9290,10578,11734,12775,13690,14583,15326,18867
-      },
-      /*Y'  qi=13  OC_MODE_INTER_MV_FOUR*/
-      {
-          317,  372,  767, 1866, 3447, 5050, 6616, 8094,
-         9499,10796,12002,13018,13919,14753,15519,18240
-      },
-      /*Y'  qi=13  OC_MODE_GOLDEN_NOMV*/
-      {
-          314,  388, 1240, 2536, 3502, 4963, 6334, 7515,
-         8781, 9343, 9864,10403,11026,12739,14132,19367
-      },
-      /*Y'  qi=13  OC_MODE_GOLDEN_MV*/
-      {
-          384,  417,  946, 2061, 3472, 5017, 6607, 8193,
-         9742,11070,12208,13246,14105,14894,15500,18763
-      }
-    },
-    {
-      /*Cb  qi=13  OC_MODE_INTRA*/
-      {
-          786, 2214, 4095, 5897, 7425, 8799, 9966,11023,
-        12297,13640,14695,15914,16556,17248,18420,22432
-      },
-      /*Cb  qi=13  OC_MODE_INTER_NOMV*/
-      {
-          120,  384, 1361, 3384, 5719, 7569, 9061,10623,
-        12296,14908,13198,14142,13391,14737,12933, 6557
-      },
-      /*Cb  qi=13  OC_MODE_INTER_MV*/
-      {
-           45,  618, 1942, 4096, 6410, 9330,11490,13258,
-        14751,15154,16673,17335,16730,20006,19651,21592
-      },
-      /*Cb  qi=13  OC_MDOE_INTER_MV_LAST*/
-      {
-           87,  578, 2055, 3865, 5987, 9014,11167,12630,
-        13573,13811,13693,13817,12973,12666,12497,12303
-      },
-      /*Cb  qi=13  OC_MODE_INTER_MV_LAST2*/
-      {
-           84,  613, 2129, 3891, 6181, 9131,11325,13367,
-        14479,15053,15737,15517,15957,18428,19719,16527
-      },
-      /*Cb  qi=13  OC_MODE_INTER_MV_FOUR*/
-      {
-           64,  632, 2057, 3919, 5988, 8481,10538,12280,
-        13544,14659,15741,16540,16843,18360,19647,21182
-      },
-      /*Cb  qi=13  OC_MODE_GOLDEN_NOMV*/
-      {
-          185,  675, 1563, 3257, 5030, 7012, 7185, 7539,
-         8068, 8797, 9317,10040, 9848,10218,10088,12294
-      },
-      /*Cb  qi=13  OC_MODE_GOLDEN_MV*/
-      {
-           69,  707, 2174, 3974, 5972, 8181, 9146, 9649,
-         9996,10059,10047,10171,10065,10347,10496,12237
-      }
-    },
-    {
-      /*Cr  qi=13  OC_MODE_INTRA*/
-      {
-          548, 1760, 3107, 4371, 5498, 6612, 7597, 8560,
-         9533,10214,10891,11832,12810,13295,13989,17158
-      },
-      /*Cr  qi=13  OC_MODE_INTER_NOMV*/
-      {
-           81,  178,  474, 1175, 2592, 4568, 5920, 6152,
-         6498, 7279, 7474, 8499, 9825, 8632, 7819, 7414
-      },
-      /*Cr  qi=13  OC_MODE_INTER_MV*/
-      {
-           36,  302,  877, 2024, 3402, 5231, 6934, 8192,
-         9049, 9975,10349,10683,10506,12455,12046,14688
-      },
-      /*Cr  qi=13  OC_MDOE_INTER_MV_LAST*/
-      {
-           72,  304,  805, 2071, 3578, 5296, 6858, 8031,
-         8610, 8648, 8080, 7655, 7926, 7493, 7781, 6750
-      },
-      /*Cr  qi=13  OC_MODE_INTER_MV_LAST2*/
-      {
-           67,  317,  858, 2114, 3453, 5140, 6805, 8078,
-         8720, 8826, 8271, 7999, 8461, 7057, 7802, 7046
-      },
-      /*Cr  qi=13  OC_MODE_INTER_MV_FOUR*/
-      {
-           51,  324,  908, 2226, 3696, 5287, 6729, 7942,
-         8941, 9924,11031,11903,12186,12886,14435,15105
-      },
-      /*Cr  qi=13  OC_MODE_GOLDEN_NOMV*/
-      {
-          140,  356,  841, 1491, 3000, 4251, 4547, 4992,
-         4873, 5683, 5870, 6295, 6204, 6743, 6798, 7308
-      },
-      /*Cr  qi=13  OC_MODE_GOLDEN_MV*/
-      {
-           63,  342,  876, 2112, 3528, 4999, 5826, 6275,
-         6229, 6613, 6460, 6686, 6867, 7195, 7202, 6850
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=14  OC_MODE_INTRA*/
-      {
-          679,  999, 2391, 4022, 5238, 6416, 7548, 8573,
-         9554,10468,11334,12043,12801,13610,14264,19184
-      },
-      /*Y'  qi=14  OC_MODE_INTER_NOMV*/
-      {
-          120,  173,  623, 1603, 3054, 5007, 6859, 8533,
-         9957,11292,12442,13731,14869,15985,16758,21428
-      },
-      /*Y'  qi=14  OC_MODE_INTER_MV*/
-      {
-          318,  391,  898, 2256, 3906, 5457, 6890, 8247,
-         9579,10879,12083,13125,14113,15070,15887,19180
-      },
-      /*Y'  qi=14  OC_MDOE_INTER_MV_LAST*/
-      {
-          254,  300,  723, 1939, 3634, 5257, 6809, 8326,
-         9783,11122,12340,13413,14368,15286,16052,19468
-      },
-      /*Y'  qi=14  OC_MODE_INTER_MV_LAST2*/
-      {
-          275,  345,  788, 2026, 3710, 5350, 6892, 8357,
-         9762,11084,12267,13331,14212,15061,15813,19320
-      },
-      /*Y'  qi=14  OC_MODE_INTER_MV_FOUR*/
-      {
-          323,  387,  862, 2101, 3782, 5454, 7059, 8555,
-         9973,11292,12464,13500,14408,15265,15999,18782
-      },
-      /*Y'  qi=14  OC_MODE_GOLDEN_NOMV*/
-      {
-          325,  426, 1297, 2591, 3805, 5292, 6805, 8023,
-         9204, 9683,10418,10891,11236,13195,14517,20007
-      },
-      /*Y'  qi=14  OC_MODE_GOLDEN_MV*/
-      {
-          378,  434, 1038, 2268, 3795, 5406, 7079, 8694,
-        10217,11592,12705,13715,14649,15285,15937,19341
-      }
-    },
-    {
-      /*Cb  qi=14  OC_MODE_INTRA*/
-      {
-          798, 2291, 4194, 6058, 7620, 9009,10198,11297,
-        12573,13977,15070,16332,16986,17651,18784,22905
-      },
-      /*Cb  qi=14  OC_MODE_INTER_NOMV*/
-      {
-          120,  397, 1444, 3606, 5928, 7655, 9462,10997,
-        12957,14257,13521,14736,14102,12819,15748, 6509
-      },
-      /*Cb  qi=14  OC_MODE_INTER_MV*/
-      {
-           46,  648, 2064, 4316, 6834, 9771,12006,13750,
-        15050,15892,16677,17526,20421,20352,20188,22002
-      },
-      /*Cb  qi=14  OC_MDOE_INTER_MV_LAST*/
-      {
-           89,  594, 2171, 4075, 6298, 9413,11588,13032,
-        13981,14263,14108,14096,13177,12857,12948,12791
-      },
-      /*Cb  qi=14  OC_MODE_INTER_MV_LAST2*/
-      {
-           95,  637, 2245, 4064, 6368, 9201,11389,13523,
-        14693,15668,16657,16987,17432,19451,18513,22443
-      },
-      /*Cb  qi=14  OC_MODE_INTER_MV_FOUR*/
-      {
-           68,  660, 2168, 4125, 6260, 8837,10931,12651,
-        14016,15114,16203,17097,17632,19932,19673,21908
-      },
-      /*Cb  qi=14  OC_MODE_GOLDEN_NOMV*/
-      {
-          193,  712, 1648, 3495, 5310, 7116, 7151, 7851,
-         8264, 9030, 9709,10201, 9960,10480,10406,12576
-      },
-      /*Cb  qi=14  OC_MODE_GOLDEN_MV*/
-      {
-           71,  729, 2309, 4184, 6264, 8479, 9524,10037,
-        10242,10419,10538,10403,10367,10745,10854,12763
-      }
-    },
-    {
-      /*Cr  qi=14  OC_MODE_INTRA*/
-      {
-          557, 1848, 3253, 4565, 5731, 6873, 7893, 8916,
-         9873,10559,11286,12203,13131,13648,14432,17707
-      },
-      /*Cr  qi=14  OC_MODE_INTER_NOMV*/
-      {
-           81,  188,  517, 1317, 3031, 4965, 5974, 6398,
-         6756, 8015, 7918,10043, 9928,10240, 9176, 7346
-      },
-      /*Cr  qi=14  OC_MODE_INTER_MV*/
-      {
-           38,  325,  974, 2227, 3724, 5641, 7262, 8614,
-         9465, 9981,11118,12323,12248,13367,12617,15090
-      },
-      /*Cr  qi=14  OC_MDOE_INTER_MV_LAST*/
-      {
-           73,  321,  877, 2285, 3879, 5694, 7240, 8450,
-         8917, 8990, 8296, 8043, 7723, 8083, 8074, 6930
-      },
-      /*Cr  qi=14  OC_MODE_INTER_MV_LAST2*/
-      {
-           75,  336,  943, 2364, 3808, 5499, 7055, 8316,
-         8876, 9258, 8802, 9769, 9488, 8801,10330,11839
-      },
-      /*Cr  qi=14  OC_MODE_INTER_MV_FOUR*/
-      {
-           55,  345, 1003, 2442, 4002, 5647, 7139, 8403,
-         9491,10247,11462,12301,12751,13977,14594,15385
-      },
-      /*Cr  qi=14  OC_MODE_GOLDEN_NOMV*/
-      {
-          146,  368,  894, 1753, 3288, 4511, 4978, 5029,
-         5261, 5892, 6285, 6428, 6496, 6907, 7152, 7412
-      },
-      /*Cr  qi=14  OC_MODE_GOLDEN_MV*/
-      {
-           66,  371,  954, 2349, 3856, 5289, 6158, 6456,
-         6404, 6912, 6574, 6947, 6641, 7822, 7124, 7003
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=15  OC_MODE_INTRA*/
-      {
-          710, 1055, 2510, 4247, 5522, 6740, 7904, 8951,
-         9950,10885,11773,12480,13259,14094,14730,19742
-      },
-      /*Y'  qi=15  OC_MODE_INTER_NOMV*/
-      {
-          125,  196,  754, 1840, 3471, 5550, 7450, 9148,
-        10571,11876,13097,14317,15585,16562,17085,23143
-      },
-      /*Y'  qi=15  OC_MODE_INTER_MV*/
-      {
-          331,  418, 1021, 2520, 4238, 5821, 7296, 8702,
-        10096,11419,12603,13633,14653,15595,16390,19727
-      },
-      /*Y'  qi=15  OC_MDOE_INTER_MV_LAST*/
-      {
-          259,  314,  830, 2210, 4012, 5696, 7296, 8862,
-        10344,11663,12861,13886,14870,15794,16550,20009
-      },
-      /*Y'  qi=15  OC_MODE_INTER_MV_LAST2*/
-      {
-          281,  368,  912, 2309, 4091, 5796, 7394, 8879,
-        10313,11616,12764,13780,14703,15535,16216,19778
-      },
-      /*Y'  qi=15  OC_MODE_INTER_MV_FOUR*/
-      {
-          333,  413,  980, 2366, 4155, 5899, 7556, 9099,
-        10524,11850,13015,14043,14951,15803,16520,19304
-      },
-      /*Y'  qi=15  OC_MODE_GOLDEN_NOMV*/
-      {
-          356,  482, 1401, 2777, 4193, 5707, 7247, 8533,
-         9513,10151,11018,11310,11914,14019,14827,20528
-      },
-      /*Y'  qi=15  OC_MODE_GOLDEN_MV*/
-      {
-          387,  461, 1171, 2544, 4175, 5846, 7571, 9239,
-        10800,12127,13286,14240,15097,15857,16453,19863
-      }
-    },
-    {
-      /*Cb  qi=15  OC_MODE_INTRA*/
-      {
-          847, 2475, 4442, 6407, 8007, 9410,10601,11729,
-        13043,14430,15566,16847,17562,18239,19470,23623
-      },
-      /*Cb  qi=15  OC_MODE_INTER_NOMV*/
-      {
-          132,  470, 1675, 4020, 6239, 7976, 9724,10533,
-        12365,14549,13173,14194,14417,14276,10166, 5841
-      },
-      /*Cb  qi=15  OC_MODE_INTER_MV*/
-      {
-           53,  741, 2298, 4730, 7293,10409,12556,14281,
-        15677,16745,17527,18924,18867,19749,21406,23108
-      },
-      /*Cb  qi=15  OC_MDOE_INTER_MV_LAST*/
-      {
-          103,  684, 2467, 4462, 6812, 9983,12104,13667,
-        14508,14733,14538,14771,13831,13150,13695,13269
-      },
-      /*Cb  qi=15  OC_MODE_INTER_MV_LAST2*/
-      {
-           96,  737, 2543, 4496, 7047,10172,12579,14406,
-        15461,16296,16982,17751,16705,18372,21377,18999
-      },
-      /*Cb  qi=15  OC_MODE_INTER_MV_FOUR*/
-      {
-           77,  754, 2439, 4504, 6722, 9367,11492,13285,
-        14507,15617,16864,17986,18453,18464,21086,22951
-      },
-      /*Cb  qi=15  OC_MODE_GOLDEN_NOMV*/
-      {
-          214,  798, 1884, 3787, 5863, 7487, 7686, 8149,
-         8789, 9533,10134,10777,10569,10862,10887,13090
-      },
-      /*Cb  qi=15  OC_MODE_GOLDEN_MV*/
-      {
-           85,  824, 2590, 4585, 6755, 9062, 9941,10311,
-        10600,11011,10713,11235,10589,11282,11257,13063
-      }
-    },
-    {
-      /*Cr  qi=15  OC_MODE_INTRA*/
-      {
-          580, 1957, 3431, 4793, 6003, 7165, 8212, 9278,
-        10270,10982,11701,12575,13644,14276,14887,18160
-      },
-      /*Cr  qi=15  OC_MODE_INTER_NOMV*/
-      {
-           87,  213,  592, 1510, 3380, 5327, 6194, 6477,
-         6389, 7235, 7633, 8675,10056,10345, 8704, 6301
-      },
-      /*Cr  qi=15  OC_MODE_INTER_MV*/
-      {
-           43,  358, 1068, 2440, 4080, 6048, 7794, 9019,
-         9825,10515,11770,11892,12805,14299,13933,15160
-      },
-      /*Cr  qi=15  OC_MDOE_INTER_MV_LAST*/
-      {
-           83,  351,  981, 2534, 4281, 6103, 7700, 8836,
-         9304, 9262, 8518, 8251, 7941, 8193, 8017, 7174
-      },
-      /*Cr  qi=15  OC_MODE_INTER_MV_LAST2*/
-      {
-           75,  370, 1053, 2554, 4040, 5926, 7569, 8789,
-         9360, 9358, 9223, 9139, 8817, 8369, 8116, 7704
-      },
-      /*Cr  qi=15  OC_MODE_INTER_MV_FOUR*/
-      {
-           61,  380, 1118, 2694, 4352, 6041, 7538, 8721,
-         9832,10791,11819,12768,13337,14262,15590,16166
-      },
-      /*Cr  qi=15  OC_MODE_GOLDEN_NOMV*/
-      {
-          148,  405,  978, 1821, 3639, 4852, 5152, 5242,
-         5464, 5680, 6473, 6644, 6554, 7214, 7435, 7635
-      },
-      /*Cr  qi=15  OC_MODE_GOLDEN_MV*/
-      {
-           76,  407, 1060, 2559, 4181, 5684, 6442, 6995,
-         6700, 7133, 6902, 7294, 7095, 7739, 7234, 7414
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=16  OC_MODE_INTRA*/
-      {
-          717, 1070, 2530, 4299, 5597, 6833, 8010, 9067,
-        10079,11025,11922,12625,13411,14250,14907,19948
-      },
-      /*Y'  qi=16  OC_MODE_INTER_NOMV*/
-      {
-          123,  195,  769, 1899, 3616, 5747, 7664, 9413,
-        10816,12119,13351,14565,15893,16743,17276,22994
-      },
-      /*Y'  qi=16  OC_MODE_INTER_MV*/
-      {
-          335,  425, 1059, 2613, 4361, 5970, 7466, 8884,
-        10295,11613,12812,13832,14871,15799,16574,19935
-      },
-      /*Y'  qi=16  OC_MDOE_INTER_MV_LAST*/
-      {
-          260,  317,  860, 2299, 4142, 5849, 7475, 9060,
-        10539,11871,13065,14094,15109,15992,16769,20226
-      },
-      /*Y'  qi=16  OC_MODE_INTER_MV_LAST2*/
-      {
-          279,  371,  939, 2392, 4205, 5936, 7551, 9079,
-        10509,11832,12978,13954,14939,15758,16421,20074
-      },
-      /*Y'  qi=16  OC_MODE_INTER_MV_FOUR*/
-      {
-          335,  417, 1009, 2445, 4272, 6052, 7725, 9275,
-        10700,12040,13207,14221,15151,15996,16739,19515
-      },
-      /*Y'  qi=16  OC_MODE_GOLDEN_NOMV*/
-      {
-          369,  509, 1470, 2868, 4294, 5851, 7416, 8652,
-         9643,10306,11206,11425,12120,14461,14998,20780
-      },
-      /*Y'  qi=16  OC_MODE_GOLDEN_MV*/
-      {
-          413,  474, 1210, 2630, 4296, 6008, 7758, 9432,
-        11002,12337,13457,14434,15356,15996,16667,20098
-      }
-    },
-    {
-      /*Cb  qi=16  OC_MODE_INTRA*/
-      {
-          875, 2528, 4520, 6502, 8120, 9536,10725,11865,
-        13162,14575,15729,17008,17782,18371,19646,23808
-      },
-      /*Cb  qi=16  OC_MODE_INTER_NOMV*/
-      {
-          134,  483, 1727, 4125, 6355, 8177, 9924,11407,
-        13572,14106,14639,13963,14121,14066,13880, 6350
-      },
-      /*Cb  qi=16  OC_MODE_INTER_MV*/
-      {
-           56,  764, 2369, 4836, 7427,10571,12697,14474,
-        15801,16876,17915,18829,18341,20368,21015,23192
-      },
-      /*Cb  qi=16  OC_MDOE_INTER_MV_LAST*/
-      {
-          110,  704, 2542, 4567, 6940,10114,12243,13756,
-        14603,14954,14730,14733,13657,13578,13545,13446
-      },
-      /*Cb  qi=16  OC_MODE_INTER_MV_LAST2*/
-      {
-          107,  757, 2619, 4570, 7139,10251,12679,14467,
-        15701,16753,16784,16102,18243,18707,21886,18943
-      },
-      /*Cb  qi=16  OC_MODE_INTER_MV_FOUR*/
-      {
-           83,  774, 2504, 4592, 6848, 9492,11666,13416,
-        14695,15768,16947,17894,18229,19603,20537,23049
-      },
-      /*Cb  qi=16  OC_MODE_GOLDEN_NOMV*/
-      {
-          232,  822, 1926, 3871, 6139, 7591, 7702, 8197,
-         8788, 9433,10331,10842,10530,10839,11016,13217
-      },
-      /*Cb  qi=16  OC_MODE_GOLDEN_MV*/
-      {
-           91,  849, 2664, 4694, 6893, 9229, 9997,10739,
-        10798,10796,11009,11383,10994,11296,11514,13301
-      }
-    },
-    {
-      /*Cr  qi=16  OC_MODE_INTRA*/
-      {
-          595, 1992, 3476, 4852, 6072, 7251, 8314, 9409,
-        10394,11081,11856,12726,13890,14453,15082,18367
-      },
-      /*Cr  qi=16  OC_MODE_INTER_NOMV*/
-      {
-           87,  218,  606, 1564, 3582, 5326, 6247, 6646,
-         7038, 7546, 9337, 8391,10629,11032, 8824, 6677
-      },
-      /*Cr  qi=16  OC_MODE_INTER_MV*/
-      {
-           44,  371, 1093, 2505, 4216, 6277, 7899, 9243,
-         9757,10923,11967,12371,12669,13293,13961,14683
-      },
-      /*Cr  qi=16  OC_MDOE_INTER_MV_LAST*/
-      {
-           85,  360, 1003, 2608, 4405, 6309, 7863, 9077,
-         9402, 9295, 8493, 8323, 8339, 8195, 8296, 7245
-      },
-      /*Cr  qi=16  OC_MODE_INTER_MV_LAST2*/
-      {
-           82,  384, 1092, 2632, 4182, 6206, 7781, 9056,
-         9383, 9619, 9200, 9006, 9125, 8290, 8526, 7320
-      },
-      /*Cr  qi=16  OC_MODE_INTER_MV_FOUR*/
-      {
-           64,  391, 1142, 2768, 4458, 6208, 7666, 8984,
-        10079,10905,12010,13222,13500,14437,15386,17279
-      },
-      /*Cr  qi=16  OC_MODE_GOLDEN_NOMV*/
-      {
-          158,  429, 1002, 1891, 3677, 4972, 5244, 5315,
-         5351, 5821, 6507, 6635, 6974, 6935, 7783, 7730
-      },
-      /*Cr  qi=16  OC_MODE_GOLDEN_MV*/
-      {
-           79,  417, 1087, 2639, 4252, 5618, 6622, 6732,
-         6983, 6883, 7093, 7084, 7326, 7586, 7831, 7416
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=17  OC_MODE_INTRA*/
-      {
-          742, 1117, 2656, 4534, 5900, 7175, 8383, 9454,
-        10492,11469,12390,13101,13902,14774,15382,20585
-      },
-      /*Y'  qi=17  OC_MODE_INTER_NOMV*/
-      {
-          125,  212,  879, 2147, 4096, 6339, 8325,10070,
-        11489,12742,14042,15246,16490,17348,17997,23592
-      },
-      /*Y'  qi=17  OC_MODE_INTER_MV*/
-      {
-          334,  454, 1190, 2916, 4766, 6446, 8016, 9478,
-        10884,12212,13394,14407,15458,16369,17156,20524
-      },
-      /*Y'  qi=17  OC_MDOE_INTER_MV_LAST*/
-      {
-          259,  334,  984, 2611, 4554, 6327, 7993, 9601,
-        11098,12460,13662,14709,15708,16590,17336,20925
-      },
-      /*Y'  qi=17  OC_MODE_INTER_MV_LAST2*/
-      {
-          284,  390, 1067, 2679, 4607, 6391, 8039, 9596,
-        11077,12399,13598,14627,15591,16464,17044,21039
-      },
-      /*Y'  qi=17  OC_MODE_INTER_MV_FOUR*/
-      {
-          340,  439, 1150, 2753, 4685, 6534, 8244, 9820,
-        11260,12619,13781,14802,15725,16561,17313,20161
-      },
-      /*Y'  qi=17  OC_MODE_GOLDEN_NOMV*/
-      {
-          377,  521, 1654, 3135, 4678, 6278, 7909, 9148,
-        10021,10863,11580,11828,12700,15108,15525,21453
-      },
-      /*Y'  qi=17  OC_MODE_GOLDEN_MV*/
-      {
-          402,  509, 1361, 2895, 4666, 6493, 8300,10008,
-        11558,12925,14046,15021,15906,16645,17277,20762
-      }
-    },
-    {
-      /*Cb  qi=17  OC_MODE_INTRA*/
-      {
-          925, 2734, 4812, 6913, 8585, 9994,11221,12377,
-        13693,15135,16302,17725,18425,19092,20425,24706
-      },
-      /*Cb  qi=17  OC_MODE_INTER_NOMV*/
-      {
-          143,  552, 1999, 4638, 6743, 8494,10488,12018,
-        14234,16214,14142,16149,14899,16360,15904, 6799
-      },
-      /*Cb  qi=17  OC_MODE_INTER_MV*/
-      {
-           62,  888, 2727, 5305, 8195,11399,13582,15420,
-        16709,17622,18465,18930,19995,21688,23192,24403
-      },
-      /*Cb  qi=17  OC_MDOE_INTER_MV_LAST*/
-      {
-          118,  788, 2864, 5014, 7545,10804,12907,14407,
-        15359,15558,15315,15238,14602,13862,14315,14106
-      },
-      /*Cb  qi=17  OC_MODE_INTER_MV_LAST2*/
-      {
-          133,  844, 2936, 4981, 7618,10776,12993,14846,
-        16218,16991,18190,17384,17444,22165,20686,21170
-      },
-      /*Cb  qi=17  OC_MODE_INTER_MV_FOUR*/
-      {
-           92,  869, 2820, 5035, 7412,10155,12368,14232,
-        15579,16694,17608,18446,19286,21298,22477,24178
-      },
-      /*Cb  qi=17  OC_MODE_GOLDEN_NOMV*/
-      {
-          245,  896, 2158, 4236, 6576, 7995, 8424, 8691,
-         9195,10064,10986,11355,11092,11771,11520,13798
-      },
-      /*Cb  qi=17  OC_MODE_GOLDEN_MV*/
-      {
-          100,  969, 3004, 5144, 7457, 9672,10670,11082,
-        11369,11583,11595,11847,11667,12096,11976,14029
-      }
-    },
-    {
-      /*Cr  qi=17  OC_MODE_INTRA*/
-      {
-          620, 2102, 3663, 5092, 6360, 7580, 8677, 9806,
-        10830,11490,12287,13209,14357,15068,15626,18989
-      },
-      /*Cr  qi=17  OC_MODE_INTER_NOMV*/
-      {
-           91,  243,  689, 1799, 4049, 5731, 6511, 7106,
-         6803, 7079, 8480, 9885,11454, 9849, 8769, 6980
-      },
-      /*Cr  qi=17  OC_MODE_INTER_MV*/
-      {
-           47,  413, 1229, 2805, 4577, 6696, 8452, 9688,
-        10283,11290,12283,13442,13295,12898,15390,16827
-      },
-      /*Cr  qi=17  OC_MDOE_INTER_MV_LAST*/
-      {
-           91,  392, 1112, 2885, 4791, 6804, 8387, 9538,
-         9818, 9571, 8794, 8467, 8485, 8255, 8678, 7523
-      },
-      /*Cr  qi=17  OC_MODE_INTER_MV_LAST2*/
-      {
-           98,  416, 1198, 2934, 4668, 6659, 8171, 9453,
-         9725, 9818, 9365, 9009, 8796, 8933, 8440, 8254
-      },
-      /*Cr  qi=17  OC_MODE_INTER_MV_FOUR*/
-      {
-           70,  426, 1275, 3053, 4852, 6667, 8136, 9450,
-        10568,11478,12610,13594,13959,14950,16534,16416
-      },
-      /*Cr  qi=17  OC_MODE_GOLDEN_NOMV*/
-      {
-          169,  457, 1109, 2151, 3895, 5170, 5608, 5546,
-         5662, 6023, 6786, 6965, 7165, 7243, 8080, 8040
-      },
-      /*Cr  qi=17  OC_MODE_GOLDEN_MV*/
-      {
-           88,  459, 1220, 2931, 4650, 6000, 6899, 6993,
-         7364, 7281, 7299, 7577, 7721, 7775, 7810, 7663
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=18  OC_MODE_INTRA*/
-      {
-          772, 1193, 2810, 4799, 6235, 7554, 8794, 9888,
-        10959,11963,12899,13617,14447,15340,15966,21266
-      },
-      /*Y'  qi=18  OC_MODE_INTER_NOMV*/
-      {
-          133,  248, 1048, 2471, 4636, 6986, 9022,10741,
-        12226,13360,14819,16008,17158,17828,18539,24557
-      },
-      /*Y'  qi=18  OC_MODE_INTER_MV*/
-      {
-          343,  484, 1369, 3230, 5159, 6914, 8525,10050,
-        11495,12804,14008,15067,16108,17014,17814,21335
-      },
-      /*Y'  qi=18  OC_MDOE_INTER_MV_LAST*/
-      {
-          259,  362, 1140, 2964, 5013, 6863, 8607,10263,
-        11748,13075,14270,15346,16368,17289,18034,21701
-      },
-      /*Y'  qi=18  OC_MODE_INTER_MV_LAST2*/
-      {
-          294,  425, 1247, 3030, 5068, 6957, 8677,10270,
-        11719,13006,14152,15169,16106,16850,17429,21113
-      },
-      /*Y'  qi=18  OC_MODE_INTER_MV_FOUR*/
-      {
-          351,  479, 1335, 3104, 5149, 7074, 8848,10457,
-        11916,13264,14441,15428,16401,17226,17980,20874
-      },
-      /*Y'  qi=18  OC_MODE_GOLDEN_NOMV*/
-      {
-          367,  665, 1821, 3441, 5122, 6868, 8499, 9691,
-        10485,11488,12251,12197,13766,15765,16066,22187
-      },
-      /*Y'  qi=18  OC_MODE_GOLDEN_MV*/
-      {
-          421,  574, 1544, 3210, 5143, 7042, 8907,10693,
-        12175,13589,14695,15653,16559,17256,17924,21485
-      }
-    },
-    {
-      /*Cb  qi=18  OC_MODE_INTRA*/
-      {
-         1005, 2959, 5117, 7328, 9066,10451,11682,12894,
-        14171,15681,16901,18286,19060,19770,21085,25523
-      },
-      /*Cb  qi=18  OC_MODE_INTER_NOMV*/
-      {
-          159,  647, 2306, 5141, 7102, 8799,11278,12618,
-        14572,14373,16939,14955,15770,15861,13793, 7075
-      },
-      /*Cb  qi=18  OC_MODE_INTER_MV*/
-      {
-           78,  979, 3024, 5767, 8668,11925,14191,15919,
-        17279,18558,19049,19697,20399,22552,23150,24172
-      },
-      /*Cb  qi=18  OC_MDOE_INTER_MV_LAST*/
-      {
-          143,  893, 3216, 5455, 8100,11394,13546,14990,
-        15881,16226,16048,16005,15262,14789,15026,14703
-      },
-      /*Cb  qi=18  OC_MODE_INTER_MV_LAST2*/
-      {
-          128,  976, 3280, 5493, 8330,11519,14006,15895,
-        17152,17680,18247,19808,18124,20903,20931,22658
-      },
-      /*Cb  qi=18  OC_MODE_INTER_MV_FOUR*/
-      {
-          110,  982, 3153, 5472, 7953,10805,12986,14862,
-        16243,17349,18710,18967,20385,21888,22696,24390
-      },
-      /*Cb  qi=18  OC_MODE_GOLDEN_NOMV*/
-      {
-          266, 1017, 2460, 4699, 7208, 8482, 9001, 9071,
-         9800,10872,11509,11920,11528,12183,11963,14327
-      },
-      /*Cb  qi=18  OC_MODE_GOLDEN_MV*/
-      {
-          122, 1094, 3340, 5597, 7982,10310,11093,11528,
-        11894,12162,11956,12213,12090,12363,12660,14505
-      }
-    },
-    {
-      /*Cr  qi=18  OC_MODE_INTRA*/
-      {
-          664, 2259, 3913, 5403, 6711, 7980, 9113,10262,
-        11334,12021,12836,13683,14841,15560,16297,19630
-      },
-      /*Cr  qi=18  OC_MODE_INTER_NOMV*/
-      {
-          103,  308,  841, 2110, 4545, 6204, 6939, 7915,
-         7808, 7902, 8305, 9168,10009,10383, 9237, 6932
-      },
-      /*Cr  qi=18  OC_MODE_INTER_MV*/
-      {
-           57,  486, 1391, 3145, 5169, 7333, 9084,10345,
-        11085,12560,13286,13442,13997,15635,15570,15470
-      },
-      /*Cr  qi=18  OC_MDOE_INTER_MV_LAST*/
-      {
-          106,  465, 1280, 3281, 5327, 7369, 8950,10072,
-        10233, 9995, 9242, 8878, 8871, 8616, 8840, 7744
-      },
-      /*Cr  qi=18  OC_MODE_INTER_MV_LAST2*/
-      {
-           95,  492, 1399, 3219, 5030, 7040, 8873,10163,
-        10271,10438, 9828, 9743,10424, 9601, 9739, 9941
-      },
-      /*Cr  qi=18  OC_MODE_INTER_MV_FOUR*/
-      {
-           79,  506, 1472, 3409, 5323, 7205, 8687,10032,
-        11039,12092,13571,13967,14509,15819,16888,18279
-      },
-      /*Cr  qi=18  OC_MODE_GOLDEN_NOMV*/
-      {
-          176,  571, 1288, 2442, 4260, 5285, 5676, 6107,
-         5896, 6465, 7050, 7262, 7544, 7776, 7894, 8370
-      },
-      /*Cr  qi=18  OC_MODE_GOLDEN_MV*/
-      {
-           96,  548, 1389, 3274, 5089, 6523, 7490, 7451,
-         7783, 7650, 7809, 7628, 8102, 8137, 8386, 8189
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=19  OC_MODE_INTRA*/
-      {
-          799, 1239, 2938, 5018, 6495, 7842, 9093,10198,
-        11285,12308,13255,13985,14814,15722,16368,21723
-      },
-      /*Y'  qi=19  OC_MODE_INTER_NOMV*/
-      {
-          136,  272, 1163, 2723, 5014, 7416, 9459,11126,
-        12573,13830,15203,16532,17485,18365,19143,25375
-      },
-      /*Y'  qi=19  OC_MODE_INTER_MV*/
-      {
-          344,  518, 1515, 3480, 5481, 7290, 8934,10434,
-        11895,13226,14411,15493,16522,17399,18207,21741
-      },
-      /*Y'  qi=19  OC_MDOE_INTER_MV_LAST*/
-      {
-          256,  388, 1283, 3256, 5352, 7224, 8985,10631,
-        12127,13469,14648,15691,16696,17556,18296,22092
-      },
-      /*Y'  qi=19  OC_MODE_INTER_MV_LAST2*/
-      {
-          290,  444, 1383, 3285, 5368, 7290, 9058,10624,
-        12045,13399,14572,15650,16656,17500,18258,22248
-      },
-      /*Y'  qi=19  OC_MODE_INTER_MV_FOUR*/
-      {
-          354,  506, 1490, 3376, 5479, 7430, 9223,10835,
-        12289,13652,14816,15844,16793,17622,18392,21334
-      },
-      /*Y'  qi=19  OC_MODE_GOLDEN_NOMV*/
-      {
-          365,  700, 1982, 3662, 5489, 7241, 8809,10035,
-        10919,11842,12502,12749,14079,15935,16438,22700
-      },
-      /*Y'  qi=19  OC_MODE_GOLDEN_MV*/
-      {
-          413,  587, 1667, 3425, 5464, 7406, 9264,11049,
-        12604,13963,15069,16007,16974,17656,18308,21937
-      }
-    },
-    {
-      /*Cb  qi=19  OC_MODE_INTRA*/
-      {
-         1045, 3108, 5323, 7593, 9379,10776,12008,13255,
-        14528,16024,17347,18789,19505,20317,21580,26079
-      },
-      /*Cb  qi=19  OC_MODE_INTER_NOMV*/
-      {
-          164,  695, 2524, 5487, 7512, 9148,11860,12498,
-        14334,16490,16915,16530,15549,15473,18212, 7299
-      },
-      /*Cb  qi=19  OC_MODE_INTER_MV*/
-      {
-           87, 1080, 3288, 6080, 9101,12495,14712,16503,
-        18006,18892,19851,19911,21216,23036,24689,25364
-      },
-      /*Cb  qi=19  OC_MDOE_INTER_MV_LAST*/
-      {
-          148,  960, 3436, 5790, 8543,11943,14075,15433,
-        16360,16550,16470,16186,15556,15556,15339,15257
-      },
-      /*Cb  qi=19  OC_MODE_INTER_MV_LAST2*/
-      {
-          174, 1032, 3552, 5719, 8426,11685,13998,15881,
-        17229,18490,18602,19140,20472,22679,22656,22874
-      },
-      /*Cb  qi=19  OC_MODE_INTER_MV_FOUR*/
-      {
-          122, 1055, 3382, 5777, 8345,11237,13387,15356,
-        16743,18120,19070,19687,21104,20928,23889,25790
-      },
-      /*Cb  qi=19  OC_MODE_GOLDEN_NOMV*/
-      {
-          290, 1063, 2652, 4925, 7788, 8856, 9257, 9329,
-        10151,11008,11707,12502,11870,12696,12132,14837
-      },
-      /*Cb  qi=19  OC_MODE_GOLDEN_MV*/
-      {
-          138, 1185, 3582, 5912, 8319,10886,11561,11806,
-        12146,12280,12261,12853,12514,12874,13293,15010
-      }
-    },
-    {
-      /*Cr  qi=19  OC_MODE_INTRA*/
-      {
-          680, 2298, 3972, 5486, 6829, 8133, 9296,10466,
-        11562,12216,13133,13938,15155,15832,16649,19960
-      },
-      /*Cr  qi=19  OC_MODE_INTER_NOMV*/
-      {
-          105,  320,  873, 2246, 4844, 6236, 6912, 8208,
-         8753, 8095, 9184, 9290, 9678, 9636,10059, 7456
-      },
-      /*Cr  qi=19  OC_MODE_INTER_MV*/
-      {
-           59,  515, 1478, 3311, 5359, 7585, 9280,10831,
-        11177,12145,13187,14162,14665,14573,14488,16463
-      },
-      /*Cr  qi=19  OC_MDOE_INTER_MV_LAST*/
-      {
-          107,  485, 1333, 3412, 5540, 7630, 9239,10340,
-        10455,10141, 9226, 9060, 8838, 8535, 8953, 7796
-      },
-      /*Cr  qi=19  OC_MODE_INTER_MV_LAST2*/
-      {
-          122,  512, 1438, 3507, 5478, 7504, 9104,10224,
-        10585,10307,10410, 9792,11089, 9178, 9127, 9354
-      },
-      /*Cr  qi=19  OC_MODE_INTER_MV_FOUR*/
-      {
-           85,  524, 1525, 3539, 5516, 7437, 8957,10279,
-        11392,12395,13425,14407,14863,15464,16745,17950
-      },
-      /*Cr  qi=19  OC_MODE_GOLDEN_NOMV*/
-      {
-          186,  587, 1304, 2666, 4610, 5534, 5808, 6283,
-         6114, 6642, 7135, 7329, 7798, 7944, 8162, 8639
-      },
-      /*Cr  qi=19  OC_MODE_GOLDEN_MV*/
-      {
-          108,  562, 1452, 3417, 5292, 6807, 7551, 7755,
-         7665, 7629, 7959, 7952, 8381, 8206, 8443, 8282
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=20  OC_MODE_INTRA*/
-      {
-          826, 1346, 3202, 5420, 6999, 8403, 9686,10820,
-        11946,13020,14000,14709,15574,16498,17109,22597
-      },
-      /*Y'  qi=20  OC_MODE_INTER_NOMV*/
-      {
-          139,  315, 1394, 3260, 5840, 8342,10353,12036,
-        13481,14869,16152,17377,18284,19235,19774,26401
-      },
-      /*Y'  qi=20  OC_MODE_INTER_MV*/
-      {
-          341,  572, 1827, 4010, 6131, 8022, 9707,11266,
-        12733,14079,15285,16367,17406,18331,19135,22815
-      },
-      /*Y'  qi=20  OC_MDOE_INTER_MV_LAST*/
-      {
-          260,  436, 1560, 3799, 6037, 8003, 9837,11502,
-        12994,14305,15482,16521,17510,18418,19160,23095
-      },
-      /*Y'  qi=20  OC_MODE_INTER_MV_LAST2*/
-      {
-          290,  485, 1673, 3788, 6032, 8089, 9910,11492,
-        12937,14227,15400,16530,17428,18356,19116,23324
-      },
-      /*Y'  qi=20  OC_MODE_INTER_MV_FOUR*/
-      {
-          354,  555, 1794, 3920, 6156, 8200,10036,11674,
-        13131,14499,15673,16725,17658,18496,19316,22275
-      },
-      /*Y'  qi=20  OC_MODE_GOLDEN_NOMV*/
-      {
-          381,  771, 2174, 4151, 6180, 7969, 9561,10671,
-        11778,12492,13199,13785,15426,16631,17062,23729
-      },
-      /*Y'  qi=20  OC_MODE_GOLDEN_MV*/
-      {
-          430,  676, 1936, 3922, 6133, 8178,10118,11913,
-        13455,14787,15948,16873,17837,18502,19169,22970
-      }
-    },
-    {
-      /*Cb  qi=20  OC_MODE_INTRA*/
-      {
-         1108, 3364, 5668, 8042, 9884,11295,12524,13814,
-        15120,16706,18004,19584,20253,21106,22346,26882
-      },
-      /*Cb  qi=20  OC_MODE_INTER_NOMV*/
-      {
-          179,  782, 2884, 5975, 7851, 9764,12258,12994,
-        17568,17087,17227,18018,16906,18271,17465, 7901
-      },
-      /*Cb  qi=20  OC_MODE_INTER_MV*/
-      {
-          103, 1203, 3663, 6635, 9767,13231,15478,17189,
-        18942,19555,20448,21608,22302,25504,25078,28354
-      },
-      /*Cb  qi=20  OC_MDOE_INTER_MV_LAST*/
-      {
-          165, 1072, 3825, 6305, 9221,12685,14834,16130,
-        16953,17275,17083,17106,16541,16178,16318,15943
-      },
-      /*Cb  qi=20  OC_MODE_INTER_MV_LAST2*/
-      {
-          206, 1150, 3944, 6198, 8991,12361,14807,16393,
-        18131,19005,19929,20150,21400,22741,22966,25862
-      },
-      /*Cb  qi=20  OC_MODE_INTER_MV_FOUR*/
-      {
-          144, 1164, 3745, 6277, 8930,11906,14150,16126,
-        17420,19042,20377,20595,21414,21968,26449,27536
-      },
-      /*Cb  qi=20  OC_MODE_GOLDEN_NOMV*/
-      {
-          312, 1194, 2968, 5589, 8357, 9200, 9873, 9927,
-        10805,11739,12315,13057,12634,13418,13007,15498
-      },
-      /*Cb  qi=20  OC_MODE_GOLDEN_MV*/
-      {
-          160, 1315, 3981, 6395, 8954,11242,12337,12489,
-        12909,12635,12800,13435,13003,13306,13824,15739
-      }
-    },
-    {
-      /*Cr  qi=20  OC_MODE_INTRA*/
-      {
-          714, 2480, 4270, 5851, 7233, 8567, 9777,10995,
-        12181,12866,13814,14694,15902,16581,17353,20735
-      },
-      /*Cr  qi=20  OC_MODE_INTER_NOMV*/
-      {
-          113,  379, 1054, 2633, 5368, 6552, 7323, 7835,
-         8494, 7871, 8718, 9999,11632,11207, 9371, 7624
-      },
-      /*Cr  qi=20  OC_MODE_INTER_MV*/
-      {
-           68,  586, 1685, 3735, 6009, 8241, 9926,11125,
-        11917,12597,13342,15116,15179,14870,16640,17964
-      },
-      /*Cr  qi=20  OC_MDOE_INTER_MV_LAST*/
-      {
-          117,  552, 1531, 3891, 6147, 8293, 9881,11028,
-        10985,10454, 9773, 9362, 9009, 9020, 9930, 8243
-      },
-      /*Cr  qi=20  OC_MODE_INTER_MV_LAST2*/
-      {
-          141,  583, 1653, 3969, 6006, 8159, 9632,10788,
-        11220,11200,11487,10835,11115,10424, 9968,10827
-      },
-      /*Cr  qi=20  OC_MODE_INTER_MV_FOUR*/
-      {
-           98,  598, 1761, 3977, 6090, 8053, 9633,10977,
-        12178,13027,14302,15075,16159,16777,17447,18884
-      },
-      /*Cr  qi=20  OC_MODE_GOLDEN_NOMV*/
-      {
-          190,  650, 1484, 3039, 5110, 5818, 6203, 6557,
-         6340, 6814, 7346, 7722, 7812, 8330, 8373, 9043
-      },
-      /*Cr  qi=20  OC_MODE_GOLDEN_MV*/
-      {
-          117,  650, 1667, 3854, 5819, 7230, 8097, 8109,
-         8180, 8190, 8193, 8440, 8470, 8717, 8920, 8775
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=21  OC_MODE_INTRA*/
-      {
-          832, 1352, 3212, 5467, 7066, 8491, 9788,10935,
-        12073,13153,14137,14860,15733,16655,17295,22807
-      },
-      /*Y'  qi=21  OC_MODE_INTER_NOMV*/
-      {
-          138,  318, 1421, 3378, 6027, 8551,10554,12241,
-        13714,15092,16320,17491,18394,19221,19905,27152
-      },
-      /*Y'  qi=21  OC_MODE_INTER_MV*/
-      {
-          339,  565, 1848, 4073, 6244, 8172, 9869,11439,
-        12913,14275,15463,16560,17602,18526,19342,23039
-      },
-      /*Y'  qi=21  OC_MDOE_INTER_MV_LAST*/
-      {
-          255,  437, 1605, 3905, 6179, 8165,10025,11692,
-        13173,14477,15638,16712,17674,18558,19310,23276
-      },
-      /*Y'  qi=21  OC_MODE_INTER_MV_LAST2*/
-      {
-          293,  493, 1677, 3850, 6174, 8322,10141,11685,
-        13102,14390,15571,16707,17682,18506,19335,23498
-      },
-      /*Y'  qi=21  OC_MODE_INTER_MV_FOUR*/
-      {
-          359,  565, 1834, 4016, 6300, 8377,10225,11881,
-        13320,14699,15859,16922,17866,18722,19507,22496
-      },
-      /*Y'  qi=21  OC_MODE_GOLDEN_NOMV*/
-      {
-          380,  783, 2183, 4215, 6315, 8150, 9656,10770,
-        11952,12853,13487,14032,15813,16917,17169,23932
-      },
-      /*Y'  qi=21  OC_MODE_GOLDEN_MV*/
-      {
-          427,  671, 1984, 4034, 6273, 8356,10302,12113,
-        13652,15012,16190,17054,18026,18711,19410,23171
-      }
-    },
-    {
-      /*Cb  qi=21  OC_MODE_INTRA*/
-      {
-         1164, 3538, 5889, 8311,10184,11578,12804,14085,
-        15424,17023,18349,19934,20615,21422,22725,27372
-      },
-      /*Cb  qi=21  OC_MODE_INTER_NOMV*/
-      {
-          190,  845, 3117, 6245, 8009, 9871,12618,13100,
-        16486,15773,17227,17207,18807,18512,17662, 7697
-      },
-      /*Cb  qi=21  OC_MODE_INTER_MV*/
-      {
-          125, 1267, 3897, 6899,10069,13502,15804,17667,
-        19452,19588,21005,21682,22662,25876,25580,28092
-      },
-      /*Cb  qi=21  OC_MDOE_INTER_MV_LAST*/
-      {
-          180, 1144, 4048, 6606, 9616,13044,15236,16536,
-        17486,17507,17489,17646,16933,16085,16219,16378
-      },
-      /*Cb  qi=21  OC_MODE_INTER_MV_LAST2*/
-      {
-          227, 1250, 4204, 6474, 9213,12598,14882,16576,
-        18393,19014,20203,19765,22140,25783,28198,24604
-      },
-      /*Cb  qi=21  OC_MODE_INTER_MV_FOUR*/
-      {
-          158, 1259, 3988, 6566, 9297,12283,14603,16415,
-        18031,19362,20417,21004,22355,22932,26220,27668
-      },
-      /*Cb  qi=21  OC_MODE_GOLDEN_NOMV*/
-      {
-          355, 1280, 3186, 6071, 8709, 9582,10224,10327,
-        10969,12058,12722,13485,12920,13410,13461,15949
-      },
-      /*Cb  qi=21  OC_MODE_GOLDEN_MV*/
-      {
-          181, 1422, 4220, 6691, 9324,11687,12680,12862,
-        12970,13060,13112,13294,13426,13649,14103,16128
-      }
-    },
-    {
-      /*Cr  qi=21  OC_MODE_INTRA*/
-      {
-          737, 2583, 4460, 6094, 7495, 8849,10084,11321,
-        12560,13226,14145,15042,16251,17044,17744,21268
-      },
-      /*Cr  qi=21  OC_MODE_INTER_NOMV*/
-      {
-          116,  407, 1166, 2895, 5596, 6950, 7739, 8365,
-         8667, 8380, 9345, 8799,12540, 9575,10352, 7498
-      },
-      /*Cr  qi=21  OC_MODE_INTER_MV*/
-      {
-           78,  621, 1844, 4052, 6436, 8659,10403,11580,
-        12287,13136,13809,14659,15957,14770,16590,17305
-      },
-      /*Cr  qi=21  OC_MDOE_INTER_MV_LAST*/
-      {
-          120,  591, 1675, 4188, 6498, 8684,10282,11364,
-        11284,10917,10061, 9486, 9571, 9562,10272, 8597
-      },
-      /*Cr  qi=21  OC_MODE_INTER_MV_LAST2*/
-      {
-          157,  635, 1765, 4264, 6452, 8518,10176,11436,
-        11647,11231,11627,10450,11507, 8604,11349,11265
-      },
-      /*Cr  qi=21  OC_MODE_INTER_MV_FOUR*/
-      {
-          103,  645, 1924, 4271, 6432, 8401,10006,11278,
-        12568,13539,14772,15868,16788,16866,18425,19876
-      },
-      /*Cr  qi=21  OC_MODE_GOLDEN_NOMV*/
-      {
-          198,  698, 1637, 3273, 5324, 5959, 6395, 6702,
-         6527, 7012, 7510, 7811, 8124, 8601, 8741, 9262
-      },
-      /*Cr  qi=21  OC_MODE_GOLDEN_MV*/
-      {
-          125,  698, 1813, 4149, 6106, 7736, 8392, 8460,
-         8361, 8209, 8369, 8606, 8859, 8988, 8844, 9002
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=22  OC_MODE_INTRA*/
-      {
-          879, 1494, 3451, 5782, 7442, 8895,10208,11362,
-        12523,13621,14625,15361,16229,17182,17820,23388
-      },
-      /*Y'  qi=22  OC_MODE_INTER_NOMV*/
-      {
-          152,  402, 1659, 3785, 6576, 9111,11091,12846,
-        14284,15623,16834,17994,18970,19671,20461,27884
-      },
-      /*Y'  qi=22  OC_MODE_INTER_MV*/
-      {
-          359,  649, 2125, 4462, 6685, 8659,10355,11955,
-        13451,14785,15978,17117,18141,19065,19916,23682
-      },
-      /*Y'  qi=22  OC_MDOE_INTER_MV_LAST*/
-      {
-          270,  505, 1844, 4284, 6634, 8675,10543,12201,
-        13679,14996,16166,17255,18215,19124,19905,24001
-      },
-      /*Y'  qi=22  OC_MODE_INTER_MV_LAST2*/
-      {
-          301,  562, 1951, 4238, 6639, 8825,10643,12197,
-        13605,14959,16101,17250,18218,19190,19928,24240
-      },
-      /*Y'  qi=22  OC_MODE_INTER_MV_FOUR*/
-      {
-          378,  645, 2097, 4408, 6763, 8872,10723,12389,
-        13843,15216,16407,17461,18386,19270,20075,23104
-      },
-      /*Y'  qi=22  OC_MODE_GOLDEN_NOMV*/
-      {
-          391,  813, 2436, 4607, 6808, 8750,10176,11165,
-        12658,13421,14145,14785,15999,17211,17884,24609
-      },
-      /*Y'  qi=22  OC_MODE_GOLDEN_MV*/
-      {
-          449,  750, 2227, 4398, 6728, 8834,10808,12609,
-        14158,15501,16697,17639,18545,19265,19916,23855
-      }
-    },
-    {
-      /*Cb  qi=22  OC_MODE_INTRA*/
-      {
-         1192, 3642, 6050, 8517,10419,11804,13039,14330,
-        15702,17298,18668,20161,20985,21790,23130,27772
-      },
-      /*Cb  qi=22  OC_MODE_INTER_NOMV*/
-      {
-          198,  893, 3297, 6476, 8195,10297,12639,14214,
-        19547,19351,17234,18259,18475,20676,18444, 8103
-      },
-      /*Cb  qi=22  OC_MODE_INTER_MV*/
-      {
-          131, 1339, 4085, 7190,10474,13967,16297,18132,
-        19774,21165,21454,22011,22598,22784,25913,27175
-      },
-      /*Cb  qi=22  OC_MDOE_INTER_MV_LAST*/
-      {
-          195, 1196, 4244, 6861, 9923,13403,15606,16933,
-        17711,17907,17889,18071,16911,16679,16630,16722
-      },
-      /*Cb  qi=22  OC_MODE_INTER_MV_LAST2*/
-      {
-          240, 1278, 4379, 6741, 9575,12974,15457,16924,
-        18510,19687,20166,20711,21671,23384,22366,25799
-      },
-      /*Cb  qi=22  OC_MODE_INTER_MV_FOUR*/
-      {
-          171, 1305, 4153, 6818, 9582,12602,14939,16851,
-        18290,19514,21363,21404,23235,23273,27653,26386
-      },
-      /*Cb  qi=22  OC_MODE_GOLDEN_NOMV*/
-      {
-          353, 1344, 3388, 6224, 8683, 9618,10458,10357,
-        11402,12384,13127,13573,13146,13838,13685,16122
-      },
-      /*Cb  qi=22  OC_MODE_GOLDEN_MV*/
-      {
-          191, 1479, 4408, 6967, 9599,12187,12777,13247,
-        13127,13516,13808,13602,13882,14017,14375,16386
-      }
-    },
-    {
-      /*Cr  qi=22  OC_MODE_INTRA*/
-      {
-          781, 2648, 4544, 6197, 7617, 8998,10242,11508,
-        12771,13430,14370,15273,16517,17266,17933,21537
-      },
-      /*Cr  qi=22  OC_MODE_INTER_NOMV*/
-      {
-          128,  453, 1243, 3018, 5728, 6983, 8065, 8250,
-         8429, 8298, 8600, 9075,11365,11568,11285, 7813
-      },
-      /*Cr  qi=22  OC_MODE_INTER_MV*/
-      {
-           82,  670, 1906, 4177, 6601, 8861,10600,11635,
-        12620,13660,14745,14921,16260,16197,16452,17853
-      },
-      /*Cr  qi=22  OC_MDOE_INTER_MV_LAST*/
-      {
-          134,  635, 1726, 4340, 6710, 8894,10460,11577,
-        11468,10978,10121, 9709, 9342, 9614,10556, 8437
-      },
-      /*Cr  qi=22  OC_MODE_INTER_MV_LAST2*/
-      {
-          166,  676, 1864, 4380, 6562, 8572,10323,11366,
-        11760,11585,12162,11313,11545, 9542,11669,11550
-      },
-      /*Cr  qi=22  OC_MODE_INTER_MV_FOUR*/
-      {
-          113,  693, 2007, 4400, 6614, 8623,10244,11560,
-        12736,13873,15137,16377,17386,18283,18726,20161
-      },
-      /*Cr  qi=22  OC_MODE_GOLDEN_NOMV*/
-      {
-          205,  764, 1703, 3465, 5259, 6170, 6653, 6770,
-         6883, 7260, 7984, 8018, 8342, 8634, 8831, 9526
-      },
-      /*Cr  qi=22  OC_MODE_GOLDEN_MV*/
-      {
-          130,  739, 1885, 4288, 6224, 7811, 8611, 8314,
-         8624, 8439, 8476, 8857, 9171, 8775, 8959, 9175
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=23  OC_MODE_INTRA*/
-      {
-          916, 1648, 3771, 6208, 7945, 9436,10786,11943,
-        13144,14287,15301,16031,16941,17907,18606,24258
-      },
-      /*Y'  qi=23  OC_MODE_INTER_NOMV*/
-      {
-          156,  482, 1973, 4425, 7428, 9952,11912,13603,
-        15139,16469,17523,18863,19816,20530,21395,28515
-      },
-      /*Y'  qi=23  OC_MODE_INTER_MV*/
-      {
-          365,  777, 2523, 5037, 7370, 9387,11109,12715,
-        14250,15594,16799,17939,18988,19920,20793,24676
-      },
-      /*Y'  qi=23  OC_MDOE_INTER_MV_LAST*/
-      {
-          267,  575, 2215, 4868, 7331, 9445,11325,12981,
-        14458,15783,16962,18050,19050,19960,20783,24966
-      },
-      /*Y'  qi=23  OC_MODE_INTER_MV_LAST2*/
-      {
-          300,  646, 2307, 4813, 7362, 9598,11415,12948,
-        14373,15722,16877,18009,18920,19892,20659,25139
-      },
-      /*Y'  qi=23  OC_MODE_INTER_MV_FOUR*/
-      {
-          382,  728, 2461, 4970, 7427, 9604,11469,13120,
-        14577,15920,17163,18225,19175,20089,20917,24003
-      },
-      /*Y'  qi=23  OC_MODE_GOLDEN_NOMV*/
-      {
-          383,  871, 2719, 5163, 7490, 9481,10691,11940,
-        13266,14098,15082,16227,16927,17832,18481,25523
-      },
-      /*Y'  qi=23  OC_MODE_GOLDEN_MV*/
-      {
-          435,  842, 2530, 4941, 7415, 9582,11593,13414,
-        14988,16302,17449,18458,19425,20089,20819,24768
-      }
-    },
-    {
-      /*Cb  qi=23  OC_MODE_INTRA*/
-      {
-         1262, 3995, 6517, 9074,11067,12444,13690,15008,
-        16470,18016,19385,21086,21768,22822,23951,28726
-      },
-      /*Cb  qi=23  OC_MODE_INTER_NOMV*/
-      {
-          227, 1022, 3792, 7082, 8790,10912,13470,15105,
-        17338,17380,19046,17676,21909,20672,20108, 9649
-      },
-      /*Cb  qi=23  OC_MODE_INTER_MV*/
-      {
-          158, 1526, 4633, 7872,11187,14697,17084,19001,
-        20547,22010,22425,23034,24591,25610,26706,30113
-      },
-      /*Cb  qi=23  OC_MDOE_INTER_MV_LAST*/
-      {
-          222, 1350, 4763, 7548,10780,14328,16428,17701,
-        18490,18462,18727,18797,17682,17413,17587,17564
-      },
-      /*Cb  qi=23  OC_MODE_INTER_MV_LAST2*/
-      {
-          273, 1450, 4909, 7407,10384,13693,16444,18130,
-        19888,21095,21715,21966,25170,25525,26252,26123
-      },
-      /*Cb  qi=23  OC_MODE_INTER_MV_FOUR*/
-      {
-          207, 1465, 4649, 7461,10353,13448,15802,17914,
-        19215,20849,21876,22297,24443,24801,26495,28669
-      },
-      /*Cb  qi=23  OC_MODE_GOLDEN_NOMV*/
-      {
-          393, 1508, 3891, 6634, 9473,10147,11021,11105,
-        11994,13226,13810,14393,14232,14684,14309,17107
-      },
-      /*Cb  qi=23  OC_MODE_GOLDEN_MV*/
-      {
-          226, 1661, 4931, 7602,10373,12826,13392,14015,
-        14186,14099,14257,14465,14639,14933,15201,17335
-      }
-    },
-    {
-      /*Cr  qi=23  OC_MODE_INTRA*/
-      {
-          807, 2826, 4840, 6563, 8036, 9452,10785,12081,
-        13396,14085,14966,15870,17087,18011,18676,22323
-      },
-      /*Cr  qi=23  OC_MODE_INTER_NOMV*/
-      {
-          137,  510, 1451, 3583, 6310, 7660, 8871, 9369,
-         9292, 8871, 9858, 9930,12408,10753,12069, 9619
-      },
-      /*Cr  qi=23  OC_MODE_INTER_MV*/
-      {
-           87,  756, 2203, 4726, 7327, 9551,11211,12390,
-        12862,13551,14920,14994,18269,17077,16480,18466
-      },
-      /*Cr  qi=23  OC_MDOE_INTER_MV_LAST*/
-      {
-          141,  711, 1960, 4855, 7411, 9632,11160,12191,
-        11937,11445,10672, 9870,10044,10075,10088, 8973
-      },
-      /*Cr  qi=23  OC_MODE_INTER_MV_LAST2*/
-      {
-          180,  765, 2112, 4839, 7272, 9485,11108,12166,
-        12354,11972,12321,10789,11730,11851,12477,12672
-      },
-      /*Cr  qi=23  OC_MODE_INTER_MV_FOUR*/
-      {
-          130,  771, 2271, 4878, 7227, 9287,10940,12285,
-        13489,14558,15968,16519,17502,19044,19067,20788
-      },
-      /*Cr  qi=23  OC_MODE_GOLDEN_NOMV*/
-      {
-          211,  854, 1878, 3762, 5715, 6439, 6939, 7272,
-         7256, 7595, 8396, 8547, 8793, 8929, 9660, 9849
-      },
-      /*Cr  qi=23  OC_MODE_GOLDEN_MV*/
-      {
-          138,  829, 2146, 4797, 6788, 8388, 8961, 9034,
-         8928, 9049, 9055, 9338, 9400, 9302, 9253, 9584
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=24  OC_MODE_INTRA*/
-      {
-          925, 1659, 3781, 6234, 7979, 9478,10827,11984,
-        13196,14345,15358,16088,16990,17953,18682,24311
-      },
-      /*Y'  qi=24  OC_MODE_INTER_NOMV*/
-      {
-          154,  481, 1989, 4482, 7498,10016,11962,13685,
-        15232,16509,17649,18887,19723,20618,21484,28686
-      },
-      /*Y'  qi=24  OC_MODE_INTER_MV*/
-      {
-          369,  779, 2565, 5096, 7415, 9414,11160,12793,
-        14313,15654,16877,18000,19024,19968,20825,24748
-      },
-      /*Y'  qi=24  OC_MDOE_INTER_MV_LAST*/
-      {
-          266,  600, 2245, 4918, 7392, 9509,11388,13042,
-        14529,15853,17055,18129,19108,20053,20872,25036
-      },
-      /*Y'  qi=24  OC_MODE_INTER_MV_LAST2*/
-      {
-          300,  649, 2331, 4868, 7422, 9658,11453,12987,
-        14433,15754,16952,18069,19005,19776,20672,25197
-      },
-      /*Y'  qi=24  OC_MODE_INTER_MV_FOUR*/
-      {
-          383,  736, 2485, 5014, 7482, 9665,11520,13165,
-        14624,15965,17212,18267,19234,20137,20956,24079
-      },
-      /*Y'  qi=24  OC_MODE_GOLDEN_NOMV*/
-      {
-          388,  900, 2740, 5208, 7544, 9524,10697,12006,
-        13240,14289,15212,16465,17042,17835,18463,25589
-      },
-      /*Y'  qi=24  OC_MODE_GOLDEN_MV*/
-      {
-          441,  856, 2564, 4999, 7463, 9661,11681,13489,
-        15010,16407,17514,18524,19423,20160,20852,24829
-      }
-    },
-    {
-      /*Cb  qi=24  OC_MODE_INTRA*/
-      {
-         1326, 4124, 6699, 9285,11285,12642,13877,15209,
-        16703,18225,19650,21316,22089,23092,24251,29098
-      },
-      /*Cb  qi=24  OC_MODE_INTER_NOMV*/
-      {
-          238, 1085, 3985, 7297, 9037,11027,13527,14819,
-        18605,20637,21479,17006,19967,22144,20165, 9407
-      },
-      /*Cb  qi=24  OC_MODE_INTER_MV*/
-      {
-          175, 1599, 4875, 8104,11378,14879,17227,19181,
-        20975,22072,22521,23249,25771,24770,27741,31130
-      },
-      /*Cb  qi=24  OC_MDOE_INTER_MV_LAST*/
-      {
-          239, 1440, 4958, 7781,11033,14588,16710,17782,
-        18971,18729,19192,19136,18264,17614,17965,17907
-      },
-      /*Cb  qi=24  OC_MODE_INTER_MV_LAST2*/
-      {
-          297, 1545, 5102, 7624,10595,14003,16491,18495,
-        20200,21250,21195,22919,24174,24981,27546,26388
-      },
-      /*Cb  qi=24  OC_MODE_INTER_MV_FOUR*/
-      {
-          225, 1548, 4841, 7678,10602,13740,16169,18097,
-        19555,21049,22294,23345,24447,24158,28239,29073
-      },
-      /*Cb  qi=24  OC_MODE_GOLDEN_NOMV*/
-      {
-          412, 1574, 4056, 6817, 9862,10542,11442,11190,
-        12430,13298,13998,14689,14259,14915,14706,17386
-      },
-      /*Cb  qi=24  OC_MODE_GOLDEN_MV*/
-      {
-          249, 1765, 5120, 7805,10509,12978,13750,14139,
-        14218,14561,14343,14854,14945,15137,15465,17690
-      }
-    },
-    {
-      /*Cr  qi=24  OC_MODE_INTRA*/
-      {
-          854, 2906, 4937, 6669, 8151, 9573,10896,12205,
-        13504,14218,15067,16026,17218,18125,18839,22443
-      },
-      /*Cr  qi=24  OC_MODE_INTER_NOMV*/
-      {
-          140,  529, 1505, 3686, 6360, 7687, 8769, 8678,
-         8934, 8156, 9306,10385,10890,10996,12755, 8948
-      },
-      /*Cr  qi=24  OC_MODE_INTER_MV*/
-      {
-           97,  787, 2299, 4871, 7455, 9713,11277,12289,
-        13022,14286,14557,15484,17137,18756,17715,20175
-      },
-      /*Cr  qi=24  OC_MDOE_INTER_MV_LAST*/
-      {
-          153,  740, 2039, 4942, 7534, 9762,11345,12192,
-        12106,11510,10813, 9636,10196,10190,10228, 9195
-      },
-      /*Cr  qi=24  OC_MODE_INTER_MV_LAST2*/
-      {
-          194,  804, 2184, 4946, 7377, 9579,11451,12293,
-        12252,12295,12048,12679,12847,12288,13791,12703
-      },
-      /*Cr  qi=24  OC_MODE_INTER_MV_FOUR*/
-      {
-          142,  806, 2360, 4983, 7365, 9400,11112,12422,
-        13547,14752,16200,16996,18016,18588,18964,22103
-      },
-      /*Cr  qi=24  OC_MODE_GOLDEN_NOMV*/
-      {
-          224,  895, 1957, 3830, 5807, 6593, 7090, 7207,
-         7424, 7696, 8421, 8509, 8817, 9023, 9359, 9893
-      },
-      /*Cr  qi=24  OC_MODE_GOLDEN_MV*/
-      {
-          154,  878, 2240, 4903, 6815, 8412, 9279, 8888,
-         9040, 8955, 9227, 9033, 9233, 9253, 9232, 9567
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=25  OC_MODE_INTRA*/
-      {
-          963, 1877, 4170, 6710, 8531,10066,11444,12602,
-        13856,15046,16073,16795,17731,18715,19470,25206
-      },
-      /*Y'  qi=25  OC_MODE_INTER_NOMV*/
-      {
-          158,  581, 2377, 5216, 8377,10847,12780,14487,
-        15977,17336,18528,19672,20734,21509,22403,29163
-      },
-      /*Y'  qi=25  OC_MODE_INTER_MV*/
-      {
-          354,  906, 2832, 5486, 8125,10286,12074,13632,
-        15098,16460,17750,18893,19838,20827,21788,25948
-      },
-      /*Y'  qi=25  OC_MDOE_INTER_MV_LAST*/
-      {
-          261,  707, 2692, 5569, 8145,10279,12146,13825,
-        15310,16649,17906,19010,20016,20982,21859,26007
-      },
-      /*Y'  qi=25  OC_MODE_INTER_MV_LAST2*/
-      {
-          292,  775, 2783, 5542, 8169,10357,12179,13772,
-        15241,16616,17857,18942,19987,20865,21769,26111
-      },
-      /*Y'  qi=25  OC_MODE_INTER_MV_FOUR*/
-      {
-          383,  842, 2926, 5670, 8207,10383,12241,13859,
-        15346,16690,17928,19018,20024,20952,21851,25087
-      },
-      /*Y'  qi=25  OC_MODE_GOLDEN_NOMV*/
-      {
-          394, 1061, 3165, 5849, 8243,10121,11349,12649,
-        13877,14927,15973,17191,17802,18348,19377,26510
-      },
-      /*Y'  qi=25  OC_MODE_GOLDEN_MV*/
-      {
-          448,  976, 2952, 5609, 8205,10448,12492,14276,
-        15808,17181,18331,19326,20282,21036,21793,25809
-      }
-    },
-    {
-      /*Cb  qi=25  OC_MODE_INTRA*/
-      {
-         1404, 4461, 7141, 9818,11908,13289,14525,15921,
-        17497,19096,20487,22219,23012,24140,25167,30177
-      },
-      /*Cb  qi=25  OC_MODE_INTER_NOMV*/
-      {
-          253, 1210, 4481, 7896, 9722,11954,14933,15636,
-        22272,19058,20018,19333,21440,24549,19414,11606
-      },
-      /*Cb  qi=25  OC_MODE_INTER_MV*/
-      {
-          308, 2183, 5637, 8349,11556,14800,17119,18967,
-        21053,21802,22667,23629,26332,24444,27675,30190
-      },
-      /*Cb  qi=25  OC_MDOE_INTER_MV_LAST*/
-      {
-          252, 1624, 5548, 8487,11823,15401,17400,18457,
-        19541,19530,19639,19357,18990,18223,18480,18672
-      },
-      /*Cb  qi=25  OC_MODE_INTER_MV_LAST2*/
-      {
-          294, 1689, 5596, 8409,11721,15153,17718,19706,
-        20954,22461,25656,24975,25295,28032,26898,29577
-      },
-      /*Cb  qi=25  OC_MODE_INTER_MV_FOUR*/
-      {
-          243, 1686, 5306, 8410,11481,14762,17160,19127,
-        20504,22072,23403,23936,25231,26217,30722,31060
-      },
-      /*Cb  qi=25  OC_MODE_GOLDEN_NOMV*/
-      {
-          459, 1728, 4508, 7295,10509,11326,12027,11945,
-        13262,13950,14535,15670,15156,15757,15342,18241
-      },
-      /*Cb  qi=25  OC_MODE_GOLDEN_MV*/
-      {
-          267, 1957, 5658, 8501,11297,13659,14578,14653,
-        14902,15207,14974,16046,15557,16177,16364,18469
-      }
-    },
-    {
-      /*Cr  qi=25  OC_MODE_INTRA*/
-      {
-          911, 3115, 5286, 7089, 8634,10086,11490,12849,
-        14184,14936,15764,16826,18108,18958,19641,23323
-      },
-      /*Cr  qi=25  OC_MODE_INTER_NOMV*/
-      {
-          144,  593, 1805, 4359, 7002, 8352, 9370,10684,
-        10398, 8849, 9175,11421,11651,12592,12223, 9732
-      },
-      /*Cr  qi=25  OC_MODE_INTER_MV*/
-      {
-          185,  941, 2737, 5594, 8094,10219,11868,12926,
-        13854,14567,15303,16914,18354,19943,19749,22938
-      },
-      /*Cr  qi=25  OC_MDOE_INTER_MV_LAST*/
-      {
-          161,  852, 2398, 5561, 8349,10562,12105,12841,
-        12707,11883,11274,10426,10302,10611,11157, 9541
-      },
-      /*Cr  qi=25  OC_MODE_INTER_MV_LAST2*/
-      {
-          186,  886, 2521, 5575, 8200,10427,11912,12857,
-        13256,12301,12533,13018,12412,13235,13423,13367
-      },
-      /*Cr  qi=25  OC_MODE_INTER_MV_FOUR*/
-      {
-          152,  917, 2741, 5556, 8071,10155,11775,13176,
-        14585,15677,17045,17651,18442,20112,20461,21667
-      },
-      /*Cr  qi=25  OC_MODE_GOLDEN_NOMV*/
-      {
-          251,  979, 2175, 4587, 6224, 6993, 7590, 7465,
-         7957, 8166, 8830, 8961, 9365, 9431, 9871,10171
-      },
-      /*Cr  qi=25  OC_MODE_GOLDEN_MV*/
-      {
-          175, 1006, 2593, 5447, 7460, 9017, 9737, 9342,
-         9620, 9282, 9642, 9586, 9850, 9845, 9759,10073
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=26  OC_MODE_INTRA*/
-      {
-          969, 1886, 4210, 6763, 8608,10162,11549,12721,
-        13989,15197,16233,16967,17906,18902,19676,25632
-      },
-      /*Y'  qi=26  OC_MODE_INTER_NOMV*/
-      {
-          168,  646, 2460, 5394, 8602,11051,12999,14790,
-        16265,17533,18729,19753,20568,21243,22033,27751
-      },
-      /*Y'  qi=26  OC_MODE_INTER_MV*/
-      {
-          385,  948, 2934, 5689, 8287,10454,12210,13787,
-        15286,16643,17898,19047,20071,21051,21986,26224
-      },
-      /*Y'  qi=26  OC_MDOE_INTER_MV_LAST*/
-      {
-          226,  697, 2721, 5704, 8330,10480,12356,14027,
-        15529,16891,18118,19190,20203,21144,22029,25814
-      },
-      /*Y'  qi=26  OC_MODE_INTER_MV_LAST2*/
-      {
-          272,  796, 2829, 5626, 8333,10619,12487,14021,
-        15432,16772,18058,19204,20244,21305,22120,26780
-      },
-      /*Y'  qi=26  OC_MODE_INTER_MV_FOUR*/
-      {
-          394,  879, 2999, 5802, 8394,10603,12506,14146,
-        15619,17004,18238,19330,20346,21284,22170,25523
-      },
-      /*Y'  qi=26  OC_MODE_GOLDEN_NOMV*/
-      {
-          403, 1071, 3131, 5987, 8393,10293,11504,12911,
-        14126,15106,15976,17316,17912,18499,19403,27092
-      },
-      /*Y'  qi=26  OC_MODE_GOLDEN_MV*/
-      {
-          449, 1005, 3017, 5721, 8372,10660,12714,14497,
-        16058,17422,18586,19545,20482,21323,22053,26411
-      }
-    },
-    {
-      /*Cb  qi=26  OC_MODE_INTRA*/
-      {
-         1485, 4776, 7553,10293,12424,13818,15031,16479,
-        18080,19719,21109,22942,23798,24886,25968,30987
-      },
-      /*Cb  qi=26  OC_MODE_INTER_NOMV*/
-      {
-          295, 1367, 4939, 8508,10598,13501,15519,15755,
-        16825,17198,17562,17930,18107,18120,18221,18816
-      },
-      /*Cb  qi=26  OC_MODE_INTER_MV*/
-      {
-          282, 2128, 5945, 9132,12780,16230,18561,20345,
-        21906,23145,24325,25481,26333,28054,29258,31492
-      },
-      /*Cb  qi=26  OC_MDOE_INTER_MV_LAST*/
-      {
-          290, 1759, 6016, 8969,12225,15835,18144,19800,
-        21353,22582,23857,24489,23848,28160,24989,26860
-      },
-      /*Cb  qi=26  OC_MODE_INTER_MV_LAST2*/
-      {
-          371, 1874, 6050, 8804,12255,15613,17976,19944,
-        21569,23069,23534,23337,26953,27461,27673,31600
-      },
-      /*Cb  qi=26  OC_MODE_INTER_MV_FOUR*/
-      {
-          290, 1865, 5753, 8901,12015,15156,17585,19632,
-        21189,22967,23970,24890,26253,28234,28848,31823
-      },
-      /*Cb  qi=26  OC_MODE_GOLDEN_NOMV*/
-      {
-          519, 1892, 4943, 7711,10604,11778,12020,12339,
-        13679,14720,14883,16549,15926,16604,16341,19894
-      },
-      /*Cb  qi=26  OC_MODE_GOLDEN_MV*/
-      {
-          311, 2162, 6131, 9040,11797,14170,15245,15303,
-        15392,15879,16206,16490,16477,17025,17448,20547
-      }
-    },
-    {
-      /*Cr  qi=26  OC_MODE_INTRA*/
-      {
-          937, 3290, 5580, 7453, 9066,10557,11999,13380,
-        14774,15523,16355,17535,18710,19556,20328,24080
-      },
-      /*Cr  qi=26  OC_MODE_INTER_NOMV*/
-      {
-          153,  656, 2115, 5167, 7962, 9355,10456,10810,
-        10818,10354,10738,10540,10776,11372,11489, 9252
-      },
-      /*Cr  qi=26  OC_MODE_INTER_MV*/
-      {
-          155, 1007, 3017, 6181, 8911,11210,12944,14503,
-        15055,15060,17437,17701,18167,19569,20056,21443
-      },
-      /*Cr  qi=26  OC_MDOE_INTER_MV_LAST*/
-      {
-          172,  930, 2717, 6070, 9038,11365,13249,14778,
-        15521,15619,17974,17221,19531,18452,17394,16846
-      },
-      /*Cr  qi=26  OC_MODE_INTER_MV_LAST2*/
-      {
-          220,  974, 2850, 6201, 8866,10983,12805,14361,
-        14833,14566,15278,16277,14890,12779,14562,15468
-      },
-      /*Cr  qi=26  OC_MODE_INTER_MV_FOUR*/
-      {
-          174, 1004, 3053, 6108, 8677,10757,12470,13917,
-        15284,16482,17742,18557,19280,20322,21645,23491
-      },
-      /*Cr  qi=26  OC_MODE_GOLDEN_NOMV*/
-      {
-          267, 1048, 2388, 5109, 6283, 6973, 7712, 7843,
-         8320, 8688, 9410, 9565, 9976,10254,10624,10795
-      },
-      /*Cr  qi=26  OC_MODE_GOLDEN_MV*/
-      {
-          199, 1103, 2913, 5992, 8039, 9507,10358,10100,
-        10241,10130,10242,10273,10704,10745,10889,10981
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=27  OC_MODE_INTRA*/
-      {
-         1020, 2098, 4577, 7168, 9052,10626,12030,13207,
-        14504,15736,16772,17504,18449,19448,20250,26046
-      },
-      /*Y'  qi=27  OC_MODE_INTER_NOMV*/
-      {
-          174,  754, 2797, 5947, 9197,11608,13542,15316,
-        16737,17992,19356,20503,21450,22288,23312,29974
-      },
-      /*Y'  qi=27  OC_MODE_INTER_MV*/
-      {
-          372, 1070, 3323, 6161, 8854,10963,12774,14332,
-        15835,17282,18535,19658,20738,21775,22526,26787
-      },
-      /*Y'  qi=27  OC_MDOE_INTER_MV_LAST*/
-      {
-          238,  814, 3115, 6203, 8863,11032,12907,14587,
-        16076,17427,18696,19792,20844,21847,22768,26945
-      },
-      /*Y'  qi=27  OC_MODE_INTER_MV_LAST2*/
-      {
-          277,  918, 3154, 6129, 8925,11209,13043,14624,
-        16047,17357,18576,19668,20710,21677,22449,27088
-      },
-      /*Y'  qi=27  OC_MODE_INTER_MV_FOUR*/
-      {
-          403, 1013, 3288, 6231, 8868,11065,12927,14566,
-        16061,17455,18712,19820,20837,21810,22707,25986
-      },
-      /*Y'  qi=27  OC_MODE_GOLDEN_NOMV*/
-      {
-          398, 1193, 3482, 6519, 8972,10805,11952,13519,
-        14632,15520,16569,17931,18645,19115,19967,27435
-      },
-      /*Y'  qi=27  OC_MODE_GOLDEN_MV*/
-      {
-          452, 1142, 3393, 6249, 8919,11218,13237,15041,
-        16562,17903,19095,20082,20999,21815,22604,26700
-      }
-    },
-    {
-      /*Cb  qi=27  OC_MODE_INTRA*/
-      {
-         1531, 4845, 7638,10380,12498,13859,15098,16497,
-        18117,19763,21206,23004,23844,24935,25995,31061
-      },
-      /*Cb  qi=27  OC_MODE_INTER_NOMV*/
-      {
-          333, 1420, 4973, 8466,10346,13347,15560,16385,
-        20482,18920,21658,20564,25754,24832,23293,13981
-      },
-      /*Cb  qi=27  OC_MODE_INTER_MV*/
-      {
-          457, 2665, 6262, 9122,12326,15427,17955,18876,
-        20483,22388,23419,24784,25889,29127,28575,32410
-      },
-      /*Cb  qi=27  OC_MDOE_INTER_MV_LAST*/
-      {
-          322, 1814, 6094, 9099,12546,16072,18008,19005,
-        19933,19937,20396,19881,19445,18912,18652,19393
-      },
-      /*Cb  qi=27  OC_MODE_INTER_MV_LAST2*/
-      {
-          399, 1968, 6186, 8929,12112,15470,18015,20032,
-        21422,22571,24770,23473,24685,27733,27232,34169
-      },
-      /*Cb  qi=27  OC_MODE_INTER_MV_FOUR*/
-      {
-          311, 1919, 5848, 8987,12153,15375,17792,19737,
-        21334,22588,23883,24384,26867,26786,28608,32011
-      },
-      /*Cb  qi=27  OC_MODE_GOLDEN_NOMV*/
-      {
-          540, 1932, 4949, 7754,10972,12093,12133,12526,
-        13899,14916,15294,16280,15920,16353,16070,18965
-      },
-      /*Cb  qi=27  OC_MODE_GOLDEN_MV*/
-      {
-          332, 2220, 6185, 9125,11957,14223,14942,15282,
-        15707,15488,15790,16400,16491,16934,17050,19286
-      }
-    },
-    {
-      /*Cr  qi=27  OC_MODE_INTRA*/
-      {
-          958, 3379, 5687, 7571, 9181,10651,12110,13503,
-        14861,15617,16391,17605,18835,19575,20431,24317
-      },
-      /*Cr  qi=27  OC_MODE_INTER_NOMV*/
-      {
-          157,  678, 2169, 5181, 7777, 9190,10304,10721,
-        10689,10281,10385,12240,13456,10660,12808,13854
-      },
-      /*Cr  qi=27  OC_MODE_INTER_MV*/
-      {
-          240, 1175, 3271, 6293, 8795,10955,12607,13526,
-        14100,14892,17274,17813,19522,21703,21436,21320
-      },
-      /*Cr  qi=27  OC_MDOE_INTER_MV_LAST*/
-      {
-          180,  963, 2831, 6263, 9146,11331,12844,13587,
-        13273,12281,12097,11023,10551,10445,12008, 9881
-      },
-      /*Cr  qi=27  OC_MODE_INTER_MV_LAST2*/
-      {
-          226, 1039, 2909, 6251, 8803,11138,12670,13876,
-        13693,13459,14366,13240,13581,13784,14346,16056
-      },
-      /*Cr  qi=27  OC_MODE_INTER_MV_FOUR*/
-      {
-          179, 1034, 3125, 6187, 8780,10900,12571,13843,
-        15093,16435,17770,18728,19501,20419,20649,23958
-      },
-      /*Cr  qi=27  OC_MODE_GOLDEN_NOMV*/
-      {
-          265, 1093, 2517, 5167, 6637, 7338, 8004, 8001,
-         8402, 8463, 9176, 9434, 9728, 9775,10366,10585
-      },
-      /*Cr  qi=27  OC_MODE_GOLDEN_MV*/
-      {
-          203, 1158, 2985, 6088, 8128, 9618,10292,10021,
-         9965,10006,10056,10140,10660,10552,10112,10397
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=28  OC_MODE_INTRA*/
-      {
-         1042, 2249, 4805, 7405, 9335,10930,12355,13553,
-        14884,16129,17186,17926,18885,19884,20739,26640
-      },
-      /*Y'  qi=28  OC_MODE_INTER_NOMV*/
-      {
-          192,  846, 3061, 6419, 9713,12033,14045,15854,
-        17123,18494,19755,20895,21847,22842,23664,30681
-      },
-      /*Y'  qi=28  OC_MODE_INTER_MV*/
-      {
-          388, 1160, 3488, 6472, 9261,11452,13250,14845,
-        16323,17699,19009,20122,21217,22213,23140,27498
-      },
-      /*Y'  qi=28  OC_MDOE_INTER_MV_LAST*/
-      {
-          217,  896, 3363, 6612, 9318,11442,13305,14998,
-        16485,17886,19146,20288,21335,22355,23296,27635
-      },
-      /*Y'  qi=28  OC_MODE_INTER_MV_LAST2*/
-      {
-          297, 1013, 3398, 6520, 9440,11717,13520,15084,
-        16471,17812,19061,20201,21240,22269,23078,27667
-      },
-      /*Y'  qi=28  OC_MODE_INTER_MV_FOUR*/
-      {
-          406, 1103, 3544, 6624, 9317,11563,13436,15096,
-        16595,17990,19240,20355,21401,22397,23325,26638
-      },
-      /*Y'  qi=28  OC_MODE_GOLDEN_NOMV*/
-      {
-          203,  986, 3529, 6793, 9381,11151,12377,14017,
-        15022,15919,17154,18454,19059,19608,20615,28195
-      },
-      /*Y'  qi=28  OC_MODE_GOLDEN_MV*/
-      {
-          436, 1220, 3596, 6603, 9371,11695,13671,15485,
-        17013,18375,19641,20698,21749,22524,23555,27726
-      }
-    },
-    {
-      /*Cb  qi=28  OC_MODE_INTRA*/
-      {
-         1651, 5231, 8127,10919,13108,14460,15726,17122,
-        18843,20512,22012,23782,24723,25814,26804,31978
-      },
-      /*Cb  qi=28  OC_MODE_INTER_NOMV*/
-      {
-          417, 1632, 5536, 9246,11008,14183,17042,18551,
-        21603,19461,21416,24172,27648,26262,23048,16867
-      },
-      /*Cb  qi=28  OC_MODE_INTER_MV*/
-      {
-          431, 2803, 6751, 9600,12899,16300,18618,20152,
-        23610,23184,24281,25502,26150,27452,31287,31986
-      },
-      /*Cb  qi=28  OC_MDOE_INTER_MV_LAST*/
-      {
-          362, 1994, 6620, 9713,13199,16648,18609,19706,
-        20673,21006,21167,20902,19965,20178,20011,20435
-      },
-      /*Cb  qi=28  OC_MODE_INTER_MV_LAST2*/
-      {
-          448, 2229, 6750, 9542,12812,16344,18623,20713,
-        21818,22677,22964,27255,27352,27520,29541,32815
-      },
-      /*Cb  qi=28  OC_MODE_INTER_MV_FOUR*/
-      {
-          363, 2121, 6326, 9583,12789,15985,18501,20354,
-        22037,23511,24685,25800,26672,27421,31166,32497
-      },
-      /*Cb  qi=28  OC_MODE_GOLDEN_NOMV*/
-      {
-          471, 2029, 5308, 7884,11137,12228,12984,13465,
-        14671,15644,16133,17691,17299,17773,17539,19972
-      },
-      /*Cb  qi=28  OC_MODE_GOLDEN_MV*/
-      {
-          377, 2428, 6753, 9681,12548,15546,17468,17725,
-        18450,17646,19289,17644,17634,17975,18580,19051
-      }
-    },
-    {
-      /*Cr  qi=28  OC_MODE_INTRA*/
-      {
-         1002, 3557, 6014, 7984, 9658,11150,12650,14092,
-        15527,16291,17075,18343,19575,20297,21240,25136
-      },
-      /*Cr  qi=28  OC_MODE_INTER_NOMV*/
-      {
-          186,  768, 2528, 5851, 8515,10021,11106,12151,
-        12600,10581, 9604,10801,11600,12494,12542,12766
-      },
-      /*Cr  qi=28  OC_MODE_INTER_MV*/
-      {
-          237, 1192, 3516, 6913, 9556,11669,13357,14421,
-        14805,15981,16973,17495,20224,22253,21081,22640
-      },
-      /*Cr  qi=28  OC_MDOE_INTER_MV_LAST*/
-      {
-          190, 1046, 3221, 6893, 9852,12007,13537,14135,
-        13734,13016,12537,11439,11078,11840,12385,10495
-      },
-      /*Cr  qi=28  OC_MODE_INTER_MV_LAST2*/
-      {
-          250, 1169, 3197, 6856, 9463,11751,13449,14288,
-        14132,14789,14380,13871,14268,14874,17894,18031
-      },
-      /*Cr  qi=28  OC_MODE_INTER_MV_FOUR*/
-      {
-          202, 1141, 3522, 6770, 9434,11568,13166,14701,
-        15934,17390,18713,18951,20733,21810,21587,24700
-      },
-      /*Cr  qi=28  OC_MODE_GOLDEN_NOMV*/
-      {
-          219, 1128, 2763, 5656, 6883, 7583, 8403, 8453,
-         8509, 9003, 9713, 9922,10571,10736,10899,11418
-      },
-      /*Cr  qi=28  OC_MODE_GOLDEN_MV*/
-      {
-          228, 1276, 3351, 6889, 9183,11072,12095,12312,
-        11545,10391,10239,10620,11128,11131,10927,11872
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=29  OC_MODE_INTRA*/
-      {
-         1114, 2616, 5385, 7984, 9968,11594,13073,14294,
-        15643,16905,17955,18689,19657,20658,21513,27544
-      },
-      /*Y'  qi=29  OC_MODE_INTER_NOMV*/
-      {
-          215, 1069, 3638, 7274,10566,12827,14936,16663,
-        17934,19256,20504,21636,22741,23416,24266,31396
-      },
-      /*Y'  qi=29  OC_MODE_INTER_MV*/
-      {
-          437, 1396, 4049, 7209,10044,12216,14010,15600,
-        17087,18508,19827,20996,22082,23183,24110,28506
-      },
-      /*Y'  qi=29  OC_MDOE_INTER_MV_LAST*/
-      {
-          284, 1157, 3954, 7377,10111,12238,14090,15783,
-        17292,18716,19981,21174,22308,23297,24242,28633
-      },
-      /*Y'  qi=29  OC_MODE_INTER_MV_LAST2*/
-      {
-          306, 1243, 3941, 7369,10348,12520,14284,15813,
-        17218,18577,19872,20995,22083,23048,24008,28520
-      },
-      /*Y'  qi=29  OC_MODE_INTER_MV_FOUR*/
-      {
-          402, 1333, 4078, 7336,10091,12331,14202,15877,
-        17387,18807,20061,21228,22309,23311,24280,27603
-      },
-      /*Y'  qi=29  OC_MODE_GOLDEN_NOMV*/
-      {
-          211, 1003, 3967, 7553,10088,11840,13136,14676,
-        15583,16671,18242,19337,19900,20553,21345,29165
-      },
-      /*Y'  qi=29  OC_MODE_GOLDEN_MV*/
-      {
-          430, 1444, 4112, 7294,10170,12490,14493,16265,
-        17801,19196,20461,21617,22654,23388,24698,28665
-      }
-    },
-    {
-      /*Cb  qi=29  OC_MODE_INTRA*/
-      {
-         1794, 5650, 8640,11437,13654,15046,16334,17734,
-        19548,21238,22753,24553,25536,26646,27595,32691
-      },
-      /*Cb  qi=29  OC_MODE_INTER_NOMV*/
-      {
-          505, 1858, 6151, 9951,11910,15248,19305,18491,
-        24640,22562,23381,23224,24763,28297,32424,20931
-      },
-      /*Cb  qi=29  OC_MODE_INTER_MV*/
-      {
-          545, 3113, 7315,10202,13589,16916,19401,21229,
-        22755,24450,24629,28367,27982,27559,32036,32032
-      },
-      /*Cb  qi=29  OC_MDOE_INTER_MV_LAST*/
-      {
-          427, 2318, 7205,10369,13976,17415,19386,20450,
-        21413,21867,22013,21928,21301,20584,21113,21281
-      },
-      /*Cb  qi=29  OC_MODE_INTER_MV_LAST2*/
-      {
-          527, 2548, 7355,10162,13537,16847,19922,21576,
-        23044,24158,25447,26211,27020,28227,30794,30722
-      },
-      /*Cb  qi=29  OC_MODE_INTER_MV_FOUR*/
-      {
-          438, 2373, 6852,10192,13454,16682,19141,21214,
-        22757,24379,25482,26481,27630,28485,31612,32604
-      },
-      /*Cb  qi=29  OC_MODE_GOLDEN_NOMV*/
-      {
-          554, 2197, 5762, 7968,11559,12994,13747,13883,
-        15396,16474,17354,18656,17894,18520,18518,21054
-      },
-      /*Cb  qi=29  OC_MODE_GOLDEN_MV*/
-      {
-          470, 2688, 7325,10336,13225,16148,18086,19287,
-        19057,19858,21301,19523,19518,20009,20248,21213
-      }
-    },
-    {
-      /*Cr  qi=29  OC_MODE_INTRA*/
-      {
-         1060, 3774, 6296, 8297,10008,11536,13080,14574,
-        16016,16878,17629,18970,20088,20777,21745,25700
-      },
-      /*Cr  qi=29  OC_MODE_INTER_NOMV*/
-      {
-          214,  842, 2779, 6378, 8921,10553,11727,16171,
-        12743,10157, 8325,10563,10328,13563,13407, 8771
-      },
-      /*Cr  qi=29  OC_MODE_INTER_MV*/
-      {
-          290, 1286, 3754, 7316,10022,12196,13845,14601,
-        15515,16184,17469,18897,20356,21606,20251,23554
-      },
-      /*Cr  qi=29  OC_MDOE_INTER_MV_LAST*/
-      {
-          217, 1149, 3550, 7328,10311,12416,13956,14650,
-        14434,13210,12966,12585,11438,12211,12543,11006
-      },
-      /*Cr  qi=29  OC_MODE_INTER_MV_LAST2*/
-      {
-          283, 1288, 3457, 7157, 9873,12399,13891,14973,
-        15029,15012,14168,15137,14448,15683,14652,17462
-      },
-      /*Cr  qi=29  OC_MODE_INTER_MV_FOUR*/
-      {
-          229, 1246, 3816, 7168, 9849,11986,13655,15128,
-        16546,17595,19446,19931,20844,21307,22983,24773
-      },
-      /*Cr  qi=29  OC_MODE_GOLDEN_NOMV*/
-      {
-          229, 1234, 2957, 5960, 7197, 7875, 9019, 8840,
-         9056, 9244,10003,10644,10461,10919,11686,11941
-      },
-      /*Cr  qi=29  OC_MODE_GOLDEN_MV*/
-      {
-          259, 1374, 3622, 7259, 9640,11681,12737,13179,
-        13476,11427,11785,11877,12185,13778,12968,12052
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=30  OC_MODE_INTRA*/
-      {
-         1132, 2723, 5519, 8106,10104,11743,13211,14470,
-        15832,17098,18153,18890,19861,20873,21744,27706
-      },
-      /*Y'  qi=30  OC_MODE_INTER_NOMV*/
-      {
-          222, 1122, 3790, 7527,10836,13065,15217,16909,
-        18161,19530,20796,21963,23000,23926,25061,31555
-      },
-      /*Y'  qi=30  OC_MODE_INTER_MV*/
-      {
-          496, 1454, 4238, 7453,10420,12537,14228,15782,
-        17295,18745,20124,21354,22385,23478,24399,28806
-      },
-      /*Y'  qi=30  OC_MDOE_INTER_MV_LAST*/
-      {
-          284, 1208, 4100, 7595,10356,12479,14346,16043,
-        17547,18966,20256,21438,22581,23617,24632,28815
-      },
-      /*Y'  qi=30  OC_MODE_INTER_MV_LAST2*/
-      {
-          300, 1298, 4092, 7602,10577,12746,14493,16035,
-        17456,18828,20092,21252,22273,23338,24105,28707
-      },
-      /*Y'  qi=30  OC_MODE_INTER_MV_FOUR*/
-      {
-          401, 1378, 4190, 7526,10309,12548,14431,16103,
-        17619,19038,20319,21486,22578,23609,24533,27829
-      },
-      /*Y'  qi=30  OC_MODE_GOLDEN_NOMV*/
-      {
-          211, 1048, 4127, 7773,10317,12096,13330,14860,
-        15808,16898,18656,19453,20176,20792,21615,29208
-      },
-      /*Y'  qi=30  OC_MODE_GOLDEN_MV*/
-      {
-          435, 1486, 4267, 7550,10427,12771,14773,16554,
-        18070,19485,20670,21754,22819,23508,24459,28527
-      }
-    },
-    {
-      /*Cb  qi=30  OC_MODE_INTRA*/
-      {
-         1875, 5900, 8960,11778,14007,15393,16701,18106,
-        19979,21699,23236,25061,26079,27177,28285,33412
-      },
-      /*Cb  qi=30  OC_MODE_INTER_NOMV*/
-      {
-          557, 1986, 6483,10306,12135,16136,32988,21821,
-        23333,22089,23451,24653,28243,32688,28240,23215
-      },
-      /*Cb  qi=30  OC_MODE_INTER_MV*/
-      {
-          645, 3366, 7725,10619,13966,17514,19951,21444,
-        23806,24633,25194,29184,28718,29210,30854,32944
-      },
-      /*Cb  qi=30  OC_MDOE_INTER_MV_LAST*/
-      {
-          475, 2473, 7607,10819,14437,17852,19815,20921,
-        21850,22072,22565,21979,20784,20904,21176,21410
-      },
-      /*Cb  qi=30  OC_MODE_INTER_MV_LAST2*/
-      {
-          580, 2795, 7752,10634,14032,17572,20408,22168,
-        23712,24526,26111,26087,28970,28566,30662,31528
-      },
-      /*Cb  qi=30  OC_MODE_INTER_MV_FOUR*/
-      {
-          484, 2514, 7215,10615,13922,17169,19651,21835,
-        23170,25084,26498,26860,28712,28207,31329,33709
-      },
-      /*Cb  qi=30  OC_MODE_GOLDEN_NOMV*/
-      {
-          608, 2316, 6004, 8323,11589,13344,14031,14545,
-        15436,16840,17752,18961,17891,18535,18606,21236
-      },
-      /*Cb  qi=30  OC_MODE_GOLDEN_MV*/
-      {
-          512, 2862, 7721,10818,13688,16105,16682,17215,
-        17233,17756,17844,18549,18122,18909,19031,21435
-      }
-    },
-    {
-      /*Cr  qi=30  OC_MODE_INTRA*/
-      {
-         1095, 3927, 6553, 8584,10317,11852,13401,14938,
-        16400,17287,18037,19461,20571,21382,22353,26214
-      },
-      /*Cr  qi=30  OC_MODE_INTER_NOMV*/
-      {
-          226,  920, 3064, 6757, 9301,10698,11669,19968,
-        14040,10730, 8926, 9147,10583,11143,11759, 8836
-      },
-      /*Cr  qi=30  OC_MODE_INTER_MV*/
-      {
-          341, 1428, 4038, 7764,10495,12740,14320,15464,
-        15996,16937,19705,19040,21586,22355,20191,23474
-      },
-      /*Cr  qi=30  OC_MDOE_INTER_MV_LAST*/
-      {
-          234, 1259, 3880, 7787,10786,12873,14416,15053,
-        14695,13660,13010,12199,11427,12217,12174,11093
-      },
-      /*Cr  qi=30  OC_MODE_INTER_MV_LAST2*/
-      {
-          301, 1414, 3779, 7466,10314,12679,14361,15549,
-        15252,14721,14280,15947,18164,16521,18211,17054
-      },
-      /*Cr  qi=30  OC_MODE_INTER_MV_FOUR*/
-      {
-          249, 1349, 4130, 7567,10283,12414,14076,15597,
-        17205,18145,19724,20572,21321,22567,22814,25543
-      },
-      /*Cr  qi=30  OC_MODE_GOLDEN_NOMV*/
-      {
-          252, 1321, 3165, 6196, 7406, 8135, 9230, 9195,
-         9241, 9570,10080,10504,10432,10746,11208,11700
-      },
-      /*Cr  qi=30  OC_MODE_GOLDEN_MV*/
-      {
-          278, 1507, 3957, 7497, 9389,10908,11524,11374,
-        11336,11022,10925,10980,11143,11534,11127,11510
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=31  OC_MODE_INTRA*/
-      {
-         1243, 3194, 6173, 8714,10746,12418,13880,15098,
-        16507,17856,18942,19676,20668,21695,22573,28604
-      },
-      /*Y'  qi=31  OC_MODE_INTER_NOMV*/
-      {
-          259, 1441, 4459, 8389,11662,13859,16072,17688,
-        18961,20294,21580,22864,23931,24790,25928,33176
-      },
-      /*Y'  qi=31  OC_MODE_INTER_MV*/
-      {
-          710, 1839, 4916, 8249,11183,13277,14981,16538,
-        18052,19536,20875,22064,23189,24323,25227,29847
-      },
-      /*Y'  qi=31  OC_MDOE_INTER_MV_LAST*/
-      {
-          334, 1580, 4791, 8420,11163,13255,15111,16786,
-        18298,19741,21046,22287,23453,24506,25493,29822
-      },
-      /*Y'  qi=31  OC_MODE_INTER_MV_LAST2*/
-      {
-          340, 1660, 4796, 8411,11386,13521,15231,16788,
-        18213,19605,20912,22095,23183,24277,25073,29773
-      },
-      /*Y'  qi=31  OC_MODE_INTER_MV_FOUR*/
-      {
-          398, 1711, 4839, 8308,11100,13325,15206,16867,
-        18415,19860,21183,22375,23479,24548,25532,28945
-      },
-      /*Y'  qi=31  OC_MODE_GOLDEN_NOMV*/
-      {
-          250, 1331, 4688, 8559,11084,12753,14151,15533,
-        16273,17617,19452,20392,20937,21704,22372,30217
-      },
-      /*Y'  qi=31  OC_MODE_GOLDEN_MV*/
-      {
-          462, 1818, 4899, 8330,11244,13556,15492,17306,
-        18834,20273,21493,22590,23733,24462,25371,29530
-      }
-    },
-    {
-      /*Cb  qi=31  OC_MODE_INTRA*/
-      {
-         1969, 6266, 9420,12254,14526,15913,17272,18728,
-        20625,22400,23982,25849,26832,27869,29084,34270
-      },
-      /*Cb  qi=31  OC_MODE_INTER_NOMV*/
-      {
-          602, 2192, 6990,10801,12770,16604,35344,19558,
-        27291,23126,24691,25060,26278,35277,25919,28248
-      },
-      /*Cb  qi=31  OC_MODE_INTER_MV*/
-      {
-          716, 3627, 8237,11193,14656,18188,20843,22277,
-        23979,25632,26623,27331,28221,30677,33286,34856
-      },
-      /*Cb  qi=31  OC_MDOE_INTER_MV_LAST*/
-      {
-          508, 2731, 8162,11409,15073,18614,20576,21665,
-        22523,23016,23205,22822,21761,21927,21581,22295
-      },
-      /*Cb  qi=31  OC_MODE_INTER_MV_LAST2*/
-      {
-          660, 3137, 8289,11192,14635,18103,21061,22876,
-        24301,24757,27361,27336,31414,30016,30911,32270
-      },
-      /*Cb  qi=31  OC_MODE_INTER_MV_FOUR*/
-      {
-          539, 2731, 7697,11175,14555,17841,20452,22510,
-        24147,25889,26820,28375,29408,29754,33360,33947
-      },
-      /*Cb  qi=31  OC_MODE_GOLDEN_NOMV*/
-      {
-          663, 2476, 6402, 8876,11968,13731,15010,14956,
-        16059,17666,18408,19343,18603,19280,19207,22022
-      },
-      /*Cb  qi=31  OC_MODE_GOLDEN_MV*/
-      {
-          573, 3111, 8240,11368,14296,16861,17216,17749,
-        18049,18399,18607,19040,18882,19688,19846,22212
-      }
-    },
-    {
-      /*Cr  qi=31  OC_MODE_INTRA*/
-      {
-         1108, 4103, 6800, 8879,10678,12264,13846,15439,
-        16977,17857,18614,20067,21196,21983,23088,27038
-      },
-      /*Cr  qi=31  OC_MODE_INTER_NOMV*/
-      {
-          243, 1003, 3375, 7242, 9869,11357,12106,14703,
-        13969,20480, 8767, 7802, 9165,11152,10780, 6695
-      },
-      /*Cr  qi=31  OC_MODE_INTER_MV*/
-      {
-          352, 1530, 4451, 8153,10953,13177,14946,16189,
-        16547,18487,19933,19120,21227,24127,18871,23373
-      },
-      /*Cr  qi=31  OC_MDOE_INTER_MV_LAST*/
-      {
-          249, 1375, 4295, 8365,11355,13442,15091,15530,
-        15322,14050,13455,12627,12100,12248,12862,11273
-      },
-      /*Cr  qi=31  OC_MODE_INTER_MV_LAST2*/
-      {
-          327, 1527, 4108, 7880,10890,13359,15189,15926,
-        15917,14872,14336,16691,16635,17637,18716,21662
-      },
-      /*Cr  qi=31  OC_MODE_INTER_MV_FOUR*/
-      {
-          269, 1456, 4455, 8067,10825,13034,14693,16347,
-        17604,19051,20466,21353,21585,23218,20589,26015
-      },
-      /*Cr  qi=31  OC_MODE_GOLDEN_NOMV*/
-      {
-          269, 1423, 3466, 6634, 7720, 8445, 9583, 9507,
-         9585, 9909,10494,10916,10905,11299,11459,12268
-      },
-      /*Cr  qi=31  OC_MODE_GOLDEN_MV*/
-      {
-          301, 1616, 4294, 7896, 9823,11306,11791,11780,
-        11534,11432,11176,11540,11405,12087,11509,11815
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=32  OC_MODE_INTRA*/
-      {
-         1271, 3298, 6329, 8850,10899,12559,14026,15256,
-        16702,18088,19164,19920,20920,21979,22859,28955
-      },
-      /*Y'  qi=32  OC_MODE_INTER_NOMV*/
-      {
-          267, 1525, 4671, 8723,11973,14143,16405,17968,
-        19245,20675,21989,23148,24337,25365,26320,33830
-      },
-      /*Y'  qi=32  OC_MODE_INTER_MV*/
-      {
-          707, 1899, 5099, 8501,11504,13616,15266,16833,
-        18363,19875,21252,22536,23698,24786,25767,30302
-      },
-      /*Y'  qi=32  OC_MDOE_INTER_MV_LAST*/
-      {
-          342, 1676, 4968, 8685,11449,13535,15398,17073,
-        18605,20040,21370,22636,23795,24917,25903,30209
-      },
-      /*Y'  qi=32  OC_MODE_INTER_MV_LAST2*/
-      {
-          346, 1725, 4957, 8657,11660,13788,15517,17077,
-        18514,19935,21238,22447,23559,24625,25470,30262
-      },
-      /*Y'  qi=32  OC_MODE_INTER_MV_FOUR*/
-      {
-          396, 1787, 5006, 8549,11358,13577,15489,17145,
-        18697,20145,21480,22695,23813,24891,25856,29355
-      },
-      /*Y'  qi=32  OC_MODE_GOLDEN_NOMV*/
-      {
-          250, 1375, 4893, 8834,11321,12960,14467,15712,
-        16599,18479,19754,20640,21218,21921,22923,30610
-      },
-      /*Y'  qi=32  OC_MODE_GOLDEN_MV*/
-      {
-          452, 1878, 5054, 8555,11522,13840,15809,17570,
-        19146,20601,21791,22976,24039,24958,25772,29921
-      }
-    },
-    {
-      /*Cb  qi=32  OC_MODE_INTRA*/
-      {
-         2047, 6510, 9723,12559,14845,16217,17606,19077,
-        21033,22790,24396,26315,27318,28472,29468,34646
-      },
-      /*Cb  qi=32  OC_MODE_INTER_NOMV*/
-      {
-          632, 2336, 7255,11079,12978,16747,33804,21393,
-        26808,27554,24382,23564,26545,36253,34739,31423
-      },
-      /*Cb  qi=32  OC_MODE_INTER_MV*/
-      {
-          840, 3859, 8589,11536,14964,18409,20980,22632,
-        24036,25768,26899,27728,29379,30349,33557,34888
-      },
-      /*Cb  qi=32  OC_MDOE_INTER_MV_LAST*/
-      {
-          533, 2916, 8513,11749,15432,18920,20974,22041,
-        22928,23333,23639,23540,22399,22108,22247,22730
-      },
-      /*Cb  qi=32  OC_MODE_INTER_MV_LAST2*/
-      {
-          690, 3247, 8620,11571,14966,18426,21065,23404,
-        24679,25341,26715,25738,28769,29059,30455,34549
-      },
-      /*Cb  qi=32  OC_MODE_INTER_MV_FOUR*/
-      {
-          566, 2901, 8010,11543,14945,18245,20861,23043,
-        24688,26788,27286,28525,30162,29595,33294,35082
-      },
-      /*Cb  qi=32  OC_MODE_GOLDEN_NOMV*/
-      {
-          678, 2610, 6565, 9338,12222,13971,15278,15470,
-        16770,17961,18876,19909,18754,19819,19685,22435
-      },
-      /*Cb  qi=32  OC_MODE_GOLDEN_MV*/
-      {
-          613, 3278, 8564,11721,14710,17208,17628,18242,
-        18491,18941,19013,19211,19229,20124,20427,22622
-      }
-    },
-    {
-      /*Cr  qi=32  OC_MODE_INTRA*/
-      {
-         1155, 4279, 7062, 9177,11005,12602,14186,15784,
-        17336,18205,19011,20476,21562,22217,23443,27368
-      },
-      /*Cr  qi=32  OC_MODE_INTER_NOMV*/
-      {
-          285, 1091, 3616, 7578,10223,11660,25728,13838,
-        13575,10429, 7561, 8383, 9048,10260, 7922, 6986
-      },
-      /*Cr  qi=32  OC_MODE_INTER_MV*/
-      {
-          416, 1659, 4618, 8477,11347,13604,15135,16871,
-        17411,18826,20225,19769,21601,22810,23433,16131
-      },
-      /*Cr  qi=32  OC_MDOE_INTER_MV_LAST*/
-      {
-          279, 1486, 4564, 8673,11667,13699,15345,15804,
-        15683,14358,13769,12840,12095,12500,12988,11537
-      },
-      /*Cr  qi=32  OC_MODE_INTER_MV_LAST2*/
-      {
-          357, 1632, 4354, 8110,11090,13644,15348,16196,
-        16731,15376,15037,16882,15450,19400,18238,18981
-      },
-      /*Cr  qi=32  OC_MODE_INTER_MV_FOUR*/
-      {
-          302, 1566, 4728, 8365,11147,13357,15114,16647,
-        18197,19566,21128,21647,22364,24033,25056,25930
-      },
-      /*Cr  qi=32  OC_MODE_GOLDEN_NOMV*/
-      {
-          314, 1527, 3662, 6743, 7985, 8636, 9778, 9814,
-         9881,10192,10618,10920,11088,11512,11691,12385
-      },
-      /*Cr  qi=32  OC_MODE_GOLDEN_MV*/
-      {
-          336, 1734, 4541, 8192,10056,11657,12109,11901,
-        11894,11589,11247,11796,11629,12519,11988,11980
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=33  OC_MODE_INTRA*/
-      {
-         1418, 3828, 7054, 9524,11597,13299,14788,15961,
-        17474,18957,20099,20875,21885,22963,23860,30051
-      },
-      /*Y'  qi=33  OC_MODE_INTER_NOMV*/
-      {
-          278, 1826, 5471, 9738,12918,15177,17315,18761,
-        20231,21725,23134,24168,25427,26617,27403,35824
-      },
-      /*Y'  qi=33  OC_MODE_INTER_MV*/
-      {
-          664, 2232, 5741, 9451,12182,14295,16115,17782,
-        19360,20874,22243,23522,24710,25868,26880,31212
-      },
-      /*Y'  qi=33  OC_MDOE_INTER_MV_LAST*/
-      {
-          375, 2103, 5697, 9566,12371,14481,16299,17970,
-        19505,20962,22317,23568,24760,25869,26870,31419
-      },
-      /*Y'  qi=33  OC_MODE_INTER_MV_LAST2*/
-      {
-          357, 2109, 5680, 9575,12680,14837,16534,18045,
-        19530,21002,22416,23681,24932,26102,27000,32635
-      },
-      /*Y'  qi=33  OC_MODE_INTER_MV_FOUR*/
-      {
-          408, 2284, 5878, 9497,12356,14583,16542,18238,
-        19840,21330,22757,24003,25189,26255,27255,30874
-      },
-      /*Y'  qi=33  OC_MODE_GOLDEN_NOMV*/
-      {
-          288, 1704, 5633, 9650,12068,13713,15231,16528,
-        17584,19936,21120,21817,22483,23045,24014,31873
-      },
-      /*Y'  qi=33  OC_MODE_GOLDEN_MV*/
-      {
-          504, 2254, 5781, 9466,12421,14694,16720,18511,
-        20111,21635,22924,24084,25249,26132,27074,31199
-      }
-    },
-    {
-      /*Cb  qi=33  OC_MODE_INTRA*/
-      {
-         2179, 7027,10362,13241,15611,17014,18414,19968,
-        21969,23829,25448,27401,28425,29627,30588,35605
-      },
-      /*Cb  qi=33  OC_MODE_INTER_NOMV*/
-      {
-          725, 2616, 7939,11742,14083,17691,33989,21492,
-        27686,34551,27995,38656,26829,32971,31099,37794
-      },
-      /*Cb  qi=33  OC_MODE_INTER_MV*/
-      {
-          625, 3297, 9147,12672,16556,20170,22678,24658,
-        26370,27301,29015,28921,29486,33331,34455,36091
-      },
-      /*Cb  qi=33  OC_MDOE_INTER_MV_LAST*/
-      {
-          657, 3305, 9184,12450,16145,19663,21826,23061,
-        24026,24601,24659,24477,23245,23577,23648,23862
-      },
-      /*Cb  qi=33  OC_MODE_INTER_MV_LAST2*/
-      {
-          830, 3295, 9327,12377,15735,19190,21898,24660,
-        25058,28442,26437,27039,32469,31320,27184,34665
-      },
-      /*Cb  qi=33  OC_MODE_INTER_MV_FOUR*/
-      {
-          662, 3279, 8783,12286,15622,18878,21774,23923,
-        25664,27526,28749,29728,31653,31409,35557,36790
-      },
-      /*Cb  qi=33  OC_MODE_GOLDEN_NOMV*/
-      {
-          791, 2910, 7064, 9566,12641,14893,15589,16251,
-        17729,18891,19660,20748,19798,20840,20383,23473
-      },
-      /*Cb  qi=33  OC_MODE_GOLDEN_MV*/
-      {
-          716, 3594, 9307,12547,15589,18031,18516,19257,
-        19322,19489,19964,20603,20390,20841,21110,23830
-      }
-    },
-    {
-      /*Cr  qi=33  OC_MODE_INTRA*/
-      {
-         1205, 4556, 7452, 9629,11548,13208,14832,16474,
-        18107,19028,19829,21384,22570,23113,24301,28136
-      },
-      /*Cr  qi=33  OC_MODE_INTER_NOMV*/
-      {
-          338, 1237, 4135, 8187,10913,11982,13533,13968,
-        15471,10483, 7468, 6335, 9869, 9886, 8679, 5688
-      },
-      /*Cr  qi=33  OC_MODE_INTER_MV*/
-      {
-          319, 1693, 5231, 9375,12372,14552,16124,17323,
-        18579,20356,21617,22091,23149,24689,22919,26209
-      },
-      /*Cr  qi=33  OC_MDOE_INTER_MV_LAST*/
-      {
-          344, 1718, 5145, 9210,12254,14419,16053,16667,
-        16394,15244,14488,13691,12585,13158,13711,12341
-      },
-      /*Cr  qi=33  OC_MODE_INTER_MV_LAST2*/
-      {
-          398, 1804, 4772, 8885,11975,14031,15750,16290,
-        17374,15497,13530,14946,17620,22459,15097,21146
-      },
-      /*Cr  qi=33  OC_MODE_INTER_MV_FOUR*/
-      {
-          356, 1776, 5208, 8994,11811,14110,15986,17504,
-        19186,20523,22404,22816,23480,25386,21741,27279
-      },
-      /*Cr  qi=33  OC_MODE_GOLDEN_NOMV*/
-      {
-          376, 1690, 4133, 7208, 8328, 9164,10403,10240,
-        10264,10736,11141,11516,11580,11996,12238,13040
-      },
-      /*Cr  qi=33  OC_MODE_GOLDEN_MV*/
-      {
-          381, 1920, 5008, 8864,10777,12249,13101,12287,
-        12695,12092,11815,12054,12258,12725,12561,12706
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=34  OC_MODE_INTRA*/
-      {
-         1423, 3846, 7059, 9532,11589,13298,14784,15947,
-        17469,18968,20105,20883,21893,22971,23876,30061
-      },
-      /*Y'  qi=34  OC_MODE_INTER_NOMV*/
-      {
-          278, 1841, 5485, 9744,12915,15112,17294,18677,
-        20282,21849,23117,24276,25306,26524,27515,35779
-      },
-      /*Y'  qi=34  OC_MODE_INTER_MV*/
-      {
-          814, 2314, 5691, 9364,12196,14334,16160,17749,
-        19326,20831,22157,23423,24608,25801,26838,31287
-      },
-      /*Y'  qi=34  OC_MDOE_INTER_MV_LAST*/
-      {
-          375, 2114, 5773, 9625,12305,14384,16218,17936,
-        19504,20997,22364,23678,24863,26011,26987,31486
-      },
-      /*Y'  qi=34  OC_MODE_INTER_MV_LAST2*/
-      {
-          359, 2158, 5674, 9561,12662,14801,16506,18025,
-        19481,20950,22282,23533,24670,25878,26762,32662
-      },
-      /*Y'  qi=34  OC_MODE_INTER_MV_FOUR*/
-      {
-          404, 2216, 5823, 9463,12305,14535,16498,18182,
-        19782,21263,22679,23910,25116,26185,27217,30861
-      },
-      /*Y'  qi=34  OC_MODE_GOLDEN_NOMV*/
-      {
-          278, 1681, 5643, 9653,12082,13759,15240,16453,
-        17644,20319,21042,21763,22409,23103,23933,31904
-      },
-      /*Y'  qi=34  OC_MODE_GOLDEN_MV*/
-      {
-          516, 2280, 5798, 9462,12438,14705,16711,18510,
-        20094,21584,22899,24069,25228,26109,27082,31215
-      }
-    },
-    {
-      /*Cb  qi=34  OC_MODE_INTRA*/
-      {
-         2191, 7043,10370,13253,15632,17042,18428,19967,
-        22011,23843,25468,27365,28431,29621,30520,35659
-      },
-      /*Cb  qi=34  OC_MODE_INTER_NOMV*/
-      {
-          729, 2638, 8026,11949,13972,17625,36800,21164,
-        27520,22243,30549,24021,26624,35520,34445,33363
-      },
-      /*Cb  qi=34  OC_MODE_INTER_MV*/
-      {
-          741, 3684, 9210,12483,16258,19972,22679,24451,
-        26747,27593,28306,29759,31089,30608,33624,35439
-      },
-      /*Cb  qi=34  OC_MDOE_INTER_MV_LAST*/
-      {
-          614, 3259, 9215,12597,16384,19811,21945,23092,
-        23969,24418,24689,24592,23498,23169,23547,23897
-      },
-      /*Cb  qi=34  OC_MODE_INTER_MV_LAST2*/
-      {
-          808, 3287, 9321,12359,15793,19274,22096,24454,
-        25524,26912,29152,35085,31687,31813,33216,35580
-      },
-      /*Cb  qi=34  OC_MODE_INTER_MV_FOUR*/
-      {
-          673, 3230, 8731,12294,15650,19011,21739,23966,
-        25741,27695,28698,30185,32731,30735,35696,36688
-      },
-      /*Cb  qi=34  OC_MODE_GOLDEN_NOMV*/
-      {
-          790, 2901, 7112, 9517,12631,15040,15684,16315,
-        17687,19094,19546,20991,19857,20779,20454,23605
-      },
-      /*Cb  qi=34  OC_MODE_GOLDEN_MV*/
-      {
-          715, 3622, 9303,12551,15503,18156,18551,19205,
-        19139,19612,20176,20327,20470,20844,21176,23891
-      }
-    },
-    {
-      /*Cr  qi=34  OC_MODE_INTRA*/
-      {
-         1218, 4570, 7463, 9644,11556,13217,14839,16527,
-        18116,19027,19848,21382,22573,23192,24311,28288
-      },
-      /*Cr  qi=34  OC_MODE_INTER_NOMV*/
-      {
-          357, 1256, 4135, 8224,10899,11941,13213,19623,
-        15609,10466, 6997, 6756, 7667, 9547, 9647, 5621
-      },
-      /*Cr  qi=34  OC_MODE_INTER_MV*/
-      {
-          394, 1822, 5197, 9265,12177,14549,16146,17544,
-        18645,20551,21920,22364,22892,22864,25710,26017
-      },
-      /*Cr  qi=34  OC_MDOE_INTER_MV_LAST*/
-      {
-          322, 1659, 5202, 9351,12355,14455,16071,16553,
-        16478,15320,14215,13474,13065,12824,13673,12301
-      },
-      /*Cr  qi=34  OC_MODE_INTER_MV_LAST2*/
-      {
-          399, 1826, 4806, 8858,11735,14137,15857,16566,
-        16713,15566,14334,17076,15440,19211,17441,19567
-      },
-      /*Cr  qi=34  OC_MODE_INTER_MV_FOUR*/
-      {
-          366, 1777, 5226, 9010,11835,14085,16100,17517,
-        19082,20470,22151,22885,23798,24502,25534,27018
-      },
-      /*Cr  qi=34  OC_MODE_GOLDEN_NOMV*/
-      {
-          407, 1697, 4156, 7201, 8277, 9250,10410,10243,
-        10438,10795,11290,11264,11511,11699,12333,12945
-      },
-      /*Cr  qi=34  OC_MODE_GOLDEN_MV*/
-      {
-          389, 1927, 5024, 8880,10744,12232,13213,12541,
-        12834,12250,11880,12238,12035,12511,12324,12697
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=35  OC_MODE_INTRA*/
-      {
-         1458, 3977, 7249, 9717,11790,13509,15011,16170,
-        17719,19253,20394,21181,22217,23296,24211,30497
-      },
-      /*Y'  qi=35  OC_MODE_INTER_NOMV*/
-      {
-          283, 1950, 5762,10117,13224,15451,17646,19100,
-        20727,22145,23453,24656,25754,27193,28353,35975
-      },
-      /*Y'  qi=35  OC_MODE_INTER_MV*/
-      {
-          844, 2451, 5913, 9626,12510,14660,16515,18123,
-        19701,21247,22674,23967,25226,26414,27262,31919
-      },
-      /*Y'  qi=35  OC_MDOE_INTER_MV_LAST*/
-      {
-          382, 2231, 6009, 9917,12635,14735,16578,18278,
-        19878,21353,22739,24028,25283,26404,27470,31982
-      },
-      /*Y'  qi=35  OC_MODE_INTER_MV_LAST2*/
-      {
-          365, 2255, 5874, 9717,12987,15226,16938,18467,
-        19950,21410,22718,23931,24960,26059,26843,33397
-      },
-      /*Y'  qi=35  OC_MODE_INTER_MV_FOUR*/
-      {
-          409, 2309, 6040, 9758,12612,14845,16808,18496,
-        20104,21616,23017,24278,25453,26583,27627,31322
-      },
-      /*Y'  qi=35  OC_MODE_GOLDEN_NOMV*/
-      {
-          282, 1747, 5859, 9967,12329,13991,15483,16737,
-        18066,20613,21428,22237,22735,23543,24263,32395
-      },
-      /*Y'  qi=35  OC_MODE_GOLDEN_MV*/
-      {
-          515, 2368, 6005, 9803,12783,15051,17053,18894,
-        20482,21949,23337,24498,25657,26544,27593,31713
-      }
-    },
-    {
-      /*Cb  qi=35  OC_MODE_INTRA*/
-      {
-         2345, 7462,10863,13760,16182,17613,19023,20555,
-        22601,24482,26091,28037,29166,30336,31144,36295
-      },
-      /*Cb  qi=35  OC_MODE_INTER_NOMV*/
-      {
-          818, 2904, 8494,12298,14666,18428,37824,22192,
-        27782,25110,28008,28675,26830,33600,30790,37299
-      },
-      /*Cb  qi=35  OC_MODE_INTER_MV*/
-      {
-          893, 3985, 9830,13099,16901,20491,23119,25254,
-        27072,28097,29753,29447,31341,31784,34688,36574
-      },
-      /*Cb  qi=35  OC_MDOE_INTER_MV_LAST*/
-      {
-          691, 3622, 9810,13162,16937,20444,22547,23833,
-        24759,25378,25514,24989,24253,23974,24357,24725
-      },
-      /*Cb  qi=35  OC_MODE_INTER_MV_LAST2*/
-      {
-          906, 3399, 9752,12982,16154,19491,22183,25080,
-        26210,28690,31232,28511,30502,34784,36320,36584
-      },
-      /*Cb  qi=35  OC_MODE_INTER_MV_FOUR*/
-      {
-          750, 3524, 9265,12894,16342,19856,22639,25009,
-        26602,28513,28861,30193,32526,31565,35258,37068
-      },
-      /*Cb  qi=35  OC_MODE_GOLDEN_NOMV*/
-      {
-          873, 3149, 7497,10299,13388,15372,16155,16924,
-        18319,19959,20312,21663,20852,21771,21359,24477
-      },
-      /*Cb  qi=35  OC_MODE_GOLDEN_MV*/
-      {
-          808, 3931, 9892,13169,16205,18694,19170,19868,
-        19910,20369,20558,21148,21062,21655,21929,24773
-      }
-    },
-    {
-      /*Cr  qi=35  OC_MODE_INTRA*/
-      {
-         1270, 4720, 7683, 9903,11862,13564,15216,16896,
-        18577,19468,20308,21844,23147,23715,24872,28708
-      },
-      /*Cr  qi=35  OC_MODE_INTER_NOMV*/
-      {
-          393, 1352, 4497, 8673,11667,12576,23656,14957,
-        17280,11736, 7134,16939,10338, 8763, 9114, 5273
-      },
-      /*Cr  qi=35  OC_MODE_INTER_MV*/
-      {
-          450, 1926, 5501, 9780,12713,15004,16595,18209,
-        19201,20418,22188,21924,23574,23374,25170,25270
-      },
-      /*Cr  qi=35  OC_MDOE_INTER_MV_LAST*/
-      {
-          350, 1796, 5561, 9846,12848,14943,16628,16992,
-        16853,15353,14647,13609,13261,13588,14032,12704
-      },
-      /*Cr  qi=35  OC_MODE_INTER_MV_LAST2*/
-      {
-          428, 1902, 5128, 9101,11887,14311,15810,16457,
-        16755,15651,13750,13108,17206,22560,13067,18696
-      },
-      /*Cr  qi=35  OC_MODE_INTER_MV_FOUR*/
-      {
-          394, 1893, 5557, 9455,12337,14587,16561,18036,
-        19596,21233,22420,23050,24136,23837,27248,27160
-      },
-      /*Cr  qi=35  OC_MODE_GOLDEN_NOMV*/
-      {
-          453, 1774, 4420, 7725, 8626, 9449,10738,10604,
-        10652,11073,11578,11727,11891,12109,12618,13282
-      },
-      /*Cr  qi=35  OC_MODE_GOLDEN_MV*/
-      {
-          418, 2045, 5327, 9335,11088,12506,13472,12900,
-        13113,12528,12228,12573,12562,12778,12786,13110
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=36  OC_MODE_INTRA*/
-      {
-         1702, 4611, 8057,10498,12610,14355,15881,17070,
-        18657,20230,21398,22200,23251,24368,25298,31760
-      },
-      /*Y'  qi=36  OC_MODE_INTER_NOMV*/
-      {
-          320, 2413, 6692,11165,14215,16483,18594,20095,
-        21743,23257,24681,26075,27256,28351,29699,37722
-      },
-      /*Y'  qi=36  OC_MODE_INTER_MV*/
-      {
-          936, 3057, 6779,10630,13447,15609,17510,19220,
-        20881,22432,23890,25183,26459,27545,28629,33321
-      },
-      /*Y'  qi=36  OC_MDOE_INTER_MV_LAST*/
-      {
-          434, 2839, 6867,10853,13587,15707,17586,19340,
-        20961,22520,23934,25265,26544,27684,28770,33416
-      },
-      /*Y'  qi=36  OC_MODE_INTER_MV_LAST2*/
-      {
-          409, 2645, 6973,10888,13910,16103,17819,19426,
-        21024,22535,23957,25354,26345,27663,28583,34820
-      },
-      /*Y'  qi=36  OC_MODE_INTER_MV_FOUR*/
-      {
-          442, 2857, 6939,10719,13573,15818,17824,19573,
-        21230,22796,24253,25586,26828,27934,29025,32846
-      },
-      /*Y'  qi=36  OC_MODE_GOLDEN_NOMV*/
-      {
-          346, 2214, 6705,10866,13196,14903,16406,17651,
-        19258,21824,22560,23443,24053,24770,25836,33772
-      },
-      /*Y'  qi=36  OC_MODE_GOLDEN_MV*/
-      {
-          515, 2942, 6860,10758,13737,16020,18053,19937,
-        21566,23118,24515,25731,26977,27852,28847,33085
-      }
-    },
-    {
-      /*Cb  qi=36  OC_MODE_INTRA*/
-      {
-         2490, 7968,11475,14383,16826,18333,19705,21248,
-        23362,25250,26831,28753,29837,31069,31748,36691
-      },
-      /*Cb  qi=36  OC_MODE_INTER_NOMV*/
-      {
-          914, 3212, 9254,13193,15695,19072,38681,24362,
-        24781,28381,26732,24921,38048,33266,31820,38249
-      },
-      /*Cb  qi=36  OC_MODE_INTER_MV*/
-      {
-          915, 3954,10307,13875,17919,21550,24191,26187,
-        28066,29345,30558,31050,31588,33798,37904,35969
-      },
-      /*Cb  qi=36  OC_MDOE_INTER_MV_LAST*/
-      {
-          783, 4026,10500,13889,17680,21245,23410,24766,
-        25638,26132,26414,26378,24850,25092,25080,25349
-      },
-      /*Cb  qi=36  OC_MODE_INTER_MV_LAST2*/
-      {
-         1056, 4627,10563,13647,17028,20416,23252,25441,
-        26259,31854,30829,26947,31940,38632,29080,36458
-      },
-      /*Cb  qi=36  OC_MODE_INTER_MV_FOUR*/
-      {
-          847, 3919, 9956,13632,17085,20546,23465,25801,
-        27516,29565,31044,32328,33150,34350,37366,37726
-      },
-      /*Cb  qi=36  OC_MODE_GOLDEN_NOMV*/
-      {
-          977, 3488, 7952,10660,13708,16254,17146,17710,
-        19011,20908,21231,22156,21643,22437,22252,25296
-      },
-      /*Cb  qi=36  OC_MODE_GOLDEN_MV*/
-      {
-          920, 4337,10578,13865,16859,19309,19847,20511,
-        20451,21144,21599,21774,21879,22176,22801,25468
-      }
-    },
-    {
-      /*Cr  qi=36  OC_MODE_INTRA*/
-      {
-         1362, 5078, 8146,10426,12449,14199,15912,17627,
-        19342,20168,21098,22579,23837,24515,25705,29652
-      },
-      /*Cr  qi=36  OC_MODE_INTER_NOMV*/
-      {
-          456, 1550, 5028, 9427,12288,27456,13974,20724,
-        19887,10460, 6570,19904, 8339, 9050, 8451, 4815
-      },
-      /*Cr  qi=36  OC_MODE_INTER_MV*/
-      {
-          481, 2118, 6073,10425,13334,15531,17425,19006,
-        20457,21433,23840,23801,24102,24284,25173,28673
-      },
-      /*Cr  qi=36  OC_MDOE_INTER_MV_LAST*/
-      {
-          418, 2057, 6179,10504,13467,15645,17326,17639,
-        17500,16169,14816,14489,13673,14268,14300,13171
-      },
-      /*Cr  qi=36  OC_MODE_INTER_MV_LAST2*/
-      {
-          525, 2148, 5624, 9855,12736,14935,16764,17196,
-        18050,15446,13619,13409,18035,23367,16698,20958
-      },
-      /*Cr  qi=36  OC_MODE_INTER_MV_FOUR*/
-      {
-          466, 2150, 6127,10080,12966,15267,17227,18852,
-        20353,22243,23709,23733,24629,26269,24783,28448
-      },
-      /*Cr  qi=36  OC_MODE_GOLDEN_NOMV*/
-      {
-          522, 1979, 4863, 7994, 9073, 9912,11102,11206,
-        11325,11684,12092,12139,12558,12698,13676,14009
-      },
-      /*Cr  qi=36  OC_MODE_GOLDEN_MV*/
-      {
-          497, 2297, 5932, 9919,11696,13199,13998,13671,
-        13402,13416,12800,13293,13020,13286,13004,13686
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=37  OC_MODE_INTRA*/
-      {
-         1773, 4793, 8348,10782,12907,14693,16240,17459,
-        19060,20655,21844,22647,23698,24833,25778,32371
-      },
-      /*Y'  qi=37  OC_MODE_INTER_NOMV*/
-      {
-          332, 2591, 7102,11643,14633,16952,19029,20643,
-        22356,23868,25168,26574,27742,28990,30392,38749
-      },
-      /*Y'  qi=37  OC_MODE_INTER_MV*/
-      {
-          981, 3307, 7131,11019,13877,16046,17967,19689,
-        21371,22964,24470,25753,27023,28229,29349,33999
-      },
-      /*Y'  qi=37  OC_MDOE_INTER_MV_LAST*/
-      {
-          434, 3022, 7222,11273,14023,16169,18062,19835,
-        21493,23055,24509,25867,27143,28341,29417,34118
-      },
-      /*Y'  qi=37  OC_MODE_INTER_MV_LAST2*/
-      {
-          436, 3099, 7189,11329,14443,16617,18359,19912,
-        21489,23030,24530,25895,27121,28629,28935,35662
-      },
-      /*Y'  qi=37  OC_MODE_INTER_MV_FOUR*/
-      {
-          450, 2985, 7240,11091,13991,16269,18291,20057,
-        21742,23332,24825,26171,27431,28562,29669,33520
-      },
-      /*Y'  qi=37  OC_MODE_GOLDEN_NOMV*/
-      {
-          358, 2348, 7010,11218,13557,15315,16704,18026,
-        19881,22355,23135,24054,24572,25413,26583,34456
-      },
-      /*Y'  qi=37  OC_MODE_GOLDEN_MV*/
-      {
-          521, 3112, 7194,11182,14208,16493,18553,20447,
-        22129,23671,25163,26336,27629,28443,29589,33805
-      }
-    },
-    {
-      /*Cb  qi=37  OC_MODE_INTRA*/
-      {
-         2659, 8440,12038,14942,17406,18924,20344,21923,
-        23959,25928,27582,29513,30605,31906,32528,37697
-      },
-      /*Cb  qi=37  OC_MODE_INTER_NOMV*/
-      {
-         1009, 3538, 9812,13792,16205,19915,40064,24199,
-        23807,26456,26257,28297,32510,38357,31614,41967
-      },
-      /*Cb  qi=37  OC_MODE_INTER_MV*/
-      {
-         1044, 4398,11032,14515,18618,22199,24927,27037,
-        28765,30031,30921,32370,32313,34698,35887,38480
-      },
-      /*Cb  qi=37  OC_MDOE_INTER_MV_LAST*/
-      {
-          869, 4359,11138,14563,18353,21922,24113,25512,
-        26406,27018,27228,26883,26161,25696,26038,26168
-      },
-      /*Cb  qi=37  OC_MODE_INTER_MV_LAST2*/
-      {
-         1282, 4577,11219,14404,17663,20877,24029,27649,
-        29896,29600,32588,28234,31853,35712,35205,36756
-      },
-      /*Cb  qi=37  OC_MODE_INTER_MV_FOUR*/
-      {
-          937, 4262,10543,14284,17738,21275,24290,26534,
-        28474,30672,31537,33390,35441,34814,37823,39286
-      },
-      /*Cb  qi=37  OC_MODE_GOLDEN_NOMV*/
-      {
-         1075, 3762, 8373,11099,14114,17044,17644,18435,
-        19879,21520,22194,22964,22662,23255,23118,26197
-      },
-      /*Cb  qi=37  OC_MODE_GOLDEN_MV*/
-      {
-         1026, 4706,11205,14538,17525,20036,20503,21135,
-        21215,21993,21842,22474,22910,23312,23452,26374
-      }
-    },
-    {
-      /*Cr  qi=37  OC_MODE_INTRA*/
-      {
-         1432, 5371, 8566,10917,12994,14787,16530,18303,
-        20033,20893,21837,23432,24622,25225,26572,30616
-      },
-      /*Cr  qi=37  OC_MODE_INTER_NOMV*/
-      {
-          500, 1749, 5597, 9930,12678,13568,17523,16407,
-        20168,10593, 6083, 5331, 9274,11442, 7366, 5114
-      },
-      /*Cr  qi=37  OC_MODE_INTER_MV*/
-      {
-          551, 2384, 6662,11070,13972,16278,18142,19617,
-        21157,22068,23878,22642,24641,24970,25715,28421
-      },
-      /*Cr  qi=37  OC_MDOE_INTER_MV_LAST*/
-      {
-          467, 2280, 6832,11183,14131,16310,18030,18298,
-        18103,16599,15900,14960,14516,14745,15392,13989
-      },
-      /*Cr  qi=37  OC_MODE_INTER_MV_LAST2*/
-      {
-          574, 2433, 6157,10507,13344,15426,17230,17962,
-        18454,15943,16044,18763,20106,23248,21261,22400
-      },
-      /*Cr  qi=37  OC_MODE_INTER_MV_FOUR*/
-      {
-          518, 2375, 6672,10730,13646,15962,17766,19530,
-        21122,22952,24138,24743,25315,27140,27714,29582
-      },
-      /*Cr  qi=37  OC_MODE_GOLDEN_NOMV*/
-      {
-          569, 2140, 5242, 8578, 9574,10373,11763,11754,
-        12039,12084,12665,12853,13143,13320,14246,14533
-      },
-      /*Cr  qi=37  OC_MODE_GOLDEN_MV*/
-      {
-          551, 2517, 6475,10536,12300,13678,14539,14175,
-        13858,13973,13159,13819,13865,13993,13919,14094
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=38  OC_MODE_INTRA*/
-      {
-         1780, 4787, 8358,10794,12920,14714,16268,17499,
-        19104,20688,21860,22682,23727,24862,25815,32553
-      },
-      /*Y'  qi=38  OC_MODE_INTER_NOMV*/
-      {
-          342, 2609, 7140,11667,14642,17052,19036,20740,
-        22348,23839,25144,26372,27581,28719,29624,35794
-      },
-      /*Y'  qi=38  OC_MODE_INTER_MV*/
-      {
-          939, 3319, 7312,11158,13892,16047,17913,19673,
-        21326,22908,24383,25754,27033,28250,29349,34167
-      },
-      /*Y'  qi=38  OC_MDOE_INTER_MV_LAST*/
-      {
-          456, 3027, 7161,11272,14139,16268,18125,19866,
-        21454,22992,24399,25721,26949,28066,29056,33460
-      },
-      /*Y'  qi=38  OC_MODE_INTER_MV_LAST2*/
-      {
-          434, 2879, 7058,11250,14451,16605,18371,20003,
-        21623,23289,24809,26324,27671,28764,29772,35577
-      },
-      /*Y'  qi=38  OC_MODE_INTER_MV_FOUR*/
-      {
-          462, 3025, 7258,11097,14027,16354,18380,20184,
-        21873,23494,25003,26306,27594,28761,29790,33817
-      },
-      /*Y'  qi=38  OC_MODE_GOLDEN_NOMV*/
-      {
-          367, 2362, 7048,11210,13553,15325,16824,18346,
-        20279,22469,23175,24149,24750,25560,26500,34695
-      },
-      /*Y'  qi=38  OC_MODE_GOLDEN_MV*/
-      {
-          555, 3121, 7188,11197,14207,16524,18585,20482,
-        22156,23720,25154,26354,27661,28449,29593,34097
-      }
-    },
-    {
-      /*Cb  qi=38  OC_MODE_INTRA*/
-      {
-         2666, 8449,12054,14964,17429,18983,20381,22022,
-        24036,25951,27588,29657,30790,32078,32745,37862
-      },
-      /*Cb  qi=38  OC_MODE_INTER_NOMV*/
-      {
-         1013, 3554,10046,14169,17179,20775,22118,22709,
-        23700,24324,24802,24798,25513,25419,25415,27056
-      },
-      /*Cb  qi=38  OC_MODE_INTER_MV*/
-      {
-          867, 4420,11094,14679,18684,22431,25018,27300,
-        29071,30664,31949,32791,34233,37183,37472,40515
-      },
-      /*Cb  qi=38  OC_MDOE_INTER_MV_LAST*/
-      {
-          940, 4359,11066,14404,18148,21853,24363,26499,
-        28365,29695,30986,32363,32948,34688,33750,34766
-      },
-      /*Cb  qi=38  OC_MODE_INTER_MV_LAST2*/
-      {
-         1174, 4106,11234,14391,17575,21028,23729,25745,
-        27456,30292,30826,30816,32680,37485,38400,38747
-      },
-      /*Cb  qi=38  OC_MODE_INTER_MV_FOUR*/
-      {
-          947, 4246,10536,14286,17746,21208,24110,26399,
-        28481,30643,31948,33409,34971,36921,35573,40561
-      },
-      /*Cb  qi=38  OC_MODE_GOLDEN_NOMV*/
-      {
-         1078, 3767, 8290,11083,14016,16904,17482,18364,
-        19862,21172,22382,23252,22819,23459,23545,27513
-      },
-      /*Cb  qi=38  OC_MODE_GOLDEN_MV*/
-      {
-         1024, 4693,11191,14533,17553,20053,20623,21346,
-        21424,22175,22267,22520,23166,23562,24059,28088
-      }
-    },
-    {
-      /*Cr  qi=38  OC_MODE_INTRA*/
-      {
-         1434, 5382, 8585,10944,13026,14826,16571,18337,
-        20098,20999,21924,23497,24663,25287,26709,30626
-      },
-      /*Cr  qi=38  OC_MODE_INTER_NOMV*/
-      {
-          510, 1769, 5661,10404,12676,14317,15186,15319,
-        14562,14187,14056,13703,14226,14489,14606,11470
-      },
-      /*Cr  qi=38  OC_MODE_INTER_MV*/
-      {
-          467, 2273, 6875,11323,14359,16820,17105,20802,
-        22009,22808,23671,23620,24123,26468,26129,28914
-      },
-      /*Cr  qi=38  OC_MDOE_INTER_MV_LAST*/
-      {
-          507, 2362, 6656,10824,14032,16657,19213,20866,
-        21477,22286,21873,24563,26229,24029,22848,27272
-      },
-      /*Cr  qi=38  OC_MODE_INTER_MV_LAST2*/
-      {
-          577, 2339, 6328,10706,13570,15634,18054,19472,
-        20027,19226,14586,21056,21841,23237,25527,19373
-      },
-      /*Cr  qi=38  OC_MODE_INTER_MV_FOUR*/
-      {
-          528, 2377, 6675,10769,13704,16014,17908,19643,
-        21269,22785,23695,24873,26008,26659,27755,30604
-      },
-      /*Cr  qi=38  OC_MODE_GOLDEN_NOMV*/
-      {
-          576, 2137, 5248, 8493, 9344,10127,11612,11551,
-        12070,12507,13051,13345,13793,13835,14850,14813
-      },
-      /*Cr  qi=38  OC_MODE_GOLDEN_MV*/
-      {
-          554, 2521, 6463,10561,12244,13758,14626,14545,
-        14174,14362,13644,14244,14300,14563,14791,14924
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=39  OC_MODE_INTRA*/
-      {
-         2040, 5409, 9045,11481,13665,15488,17061,18308,
-        19940,21534,22732,23541,24609,25730,26706,33653
-      },
-      /*Y'  qi=39  OC_MODE_INTER_NOMV*/
-      {
-          424, 3075, 7962,12505,15545,17948,19988,21765,
-        23465,24855,26305,27499,28821,29855,30730,36949
-      },
-      /*Y'  qi=39  OC_MODE_INTER_MV*/
-      {
-         1030, 3576, 8075,11879,14752,16947,18851,20636,
-        22287,23812,25247,26554,27820,28949,30005,34637
-      },
-      /*Y'  qi=39  OC_MDOE_INTER_MV_LAST*/
-      {
-          648, 3826, 8009,12039,14832,17046,19011,20830,
-        22542,24152,25690,27100,28439,29747,30846,35948
-      },
-      /*Y'  qi=39  OC_MODE_INTER_MV_LAST2*/
-      {
-          474, 3682, 8195,12161,15254,17426,19174,20862,
-        22644,24317,25936,27276,28797,29943,30982,37328
-      },
-      /*Y'  qi=39  OC_MODE_INTER_MV_FOUR*/
-      {
-          490, 3394, 7907,11916,14792,17071,19081,20911,
-        22665,24339,25897,27299,28587,29751,30831,35080
-      },
-      /*Y'  qi=39  OC_MODE_GOLDEN_NOMV*/
-      {
-          434, 2838, 7848,11973,14309,16029,17741,19707,
-        21746,23362,24191,25223,25575,26558,27084,35875
-      },
-      /*Y'  qi=39  OC_MODE_GOLDEN_MV*/
-      {
-          596, 3647, 7968,12008,15039,17372,19448,21378,
-        23124,24728,26167,27461,28701,29526,30676,35244
-      }
-    },
-    {
-      /*Cb  qi=39  OC_MODE_INTRA*/
-      {
-         2895, 9021,12711,15632,18165,19750,21157,22822,
-        24894,26818,28610,30619,31742,33119,33922,38896
-      },
-      /*Cb  qi=39  OC_MODE_INTER_NOMV*/
-      {
-         1161, 3947,10709,14904,17739,21606,22695,23431,
-        24346,25125,25646,26059,26171,26802,26659,28101
-      },
-      /*Cb  qi=39  OC_MODE_INTER_MV*/
-      {
-          824, 5699,11598,15619,19439,23267,26217,28322,
-        30048,31842,33247,33628,35743,37755,40397,41728
-      },
-      /*Cb  qi=39  OC_MDOE_INTER_MV_LAST*/
-      {
-         1199, 5248,11993,15269,19061,22851,25388,27113,
-        29063,29267,30172,32132,30855,31186,31736,36850
-      },
-      /*Cb  qi=39  OC_MODE_INTER_MV_LAST2*/
-      {
-         1642, 6008,12049,15169,18533,21925,24632,26863,
-        28245,29947,31311,30986,37035,37490,34728,36826
-      },
-      /*Cb  qi=39  OC_MODE_INTER_MV_FOUR*/
-      {
-         1062, 4578,11252,15058,18676,22272,25211,27447,
-        29643,31945,33535,34562,36212,37567,39779,41733
-      },
-      /*Cb  qi=39  OC_MODE_GOLDEN_NOMV*/
-      {
-         1206, 4124, 8845,11727,14661,17338,18275,19049,
-        20763,22258,23314,24051,23687,24019,24501,28684
-      },
-      /*Cb  qi=39  OC_MODE_GOLDEN_MV*/
-      {
-         1143, 5233,11913,15297,18415,20768,21547,22170,
-        22160,23156,23593,23687,23735,24514,24906,29422
-      }
-    },
-    {
-      /*Cr  qi=39  OC_MODE_INTRA*/
-      {
-         1535, 5715, 9029,11467,13608,15435,17196,19030,
-        20816,21665,22642,24243,25528,25960,27597,31649
-      },
-      /*Cr  qi=39  OC_MODE_INTER_NOMV*/
-      {
-          570, 1980, 6288,10894,13144,14779,15734,15795,
-        15429,14610,13874,13794,14890,15205,14360,12310
-      },
-      /*Cr  qi=39  OC_MODE_INTER_MV*/
-      {
-          382, 2857, 7633,11397,14037,16661,18251,20920,
-        22186,24017,25123,25437,26311,27558,26652,27651
-      },
-      /*Cr  qi=39  OC_MDOE_INTER_MV_LAST*/
-      {
-          618, 2579, 7266,11938,15030,17355,19288,21044,
-        22112,22919,22417,24682,24441,26109,23595,22893
-      },
-      /*Cr  qi=39  OC_MODE_INTER_MV_LAST2*/
-      {
-          749, 2671, 6790,11528,14599,16887,18734,20240,
-        21047,18794,17830,20189,16552,13545,13577, 7731
-      },
-      /*Cr  qi=39  OC_MODE_INTER_MV_FOUR*/
-      {
-          560, 2577, 7241,11512,14495,16777,18730,20453,
-        21955,23438,25158,25914,25885,27454,28770,30897
-      },
-      /*Cr  qi=39  OC_MODE_GOLDEN_NOMV*/
-      {
-          627, 2344, 5711, 9022, 9790,10406,12218,12259,
-        12644,12963,13541,14098,14394,14547,15539,15486
-      },
-      /*Cr  qi=39  OC_MODE_GOLDEN_MV*/
-      {
-          598, 2804, 7070,11127,12870,14222,15418,14768,
-        15145,14787,14233,14690,14863,15279,15563,15533
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=40  OC_MODE_INTRA*/
-      {
-         2342, 5977, 9711,12109,14324,16168,17795,19071,
-        20719,22345,23553,24359,25464,26617,27626,34620
-      },
-      /*Y'  qi=40  OC_MODE_INTER_NOMV*/
-      {
-          519, 3574, 8803,13354,16341,18804,20780,22654,
-        24411,25958,27471,28780,30162,31481,32916,41493
-      },
-      /*Y'  qi=40  OC_MODE_INTER_MV*/
-      {
-         1367, 4344, 8889,12678,15705,17849,19649,21428,
-        23242,24984,26569,28073,29382,30566,31630,36393
-      },
-      /*Y'  qi=40  OC_MDOE_INTER_MV_LAST*/
-      {
-          734, 4406, 8792,12823,15607,17836,19853,21731,
-        23490,25126,26648,28068,29399,30579,31661,36372
-      },
-      /*Y'  qi=40  OC_MODE_INTER_MV_LAST2*/
-      {
-          636, 4483, 8878,12973,15960,18107,19967,21739,
-        23424,25056,26520,27887,29103,30290,31026,37164
-      },
-      /*Y'  qi=40  OC_MODE_INTER_MV_FOUR*/
-      {
-          540, 3861, 8618,12693,15594,17928,19980,21855,
-        23623,25291,26833,28229,29525,30712,31804,35862
-      },
-      /*Y'  qi=40  OC_MODE_GOLDEN_NOMV*/
-      {
-          481, 3258, 8642,12666,15081,16694,18737,20830,
-        22774,24223,25420,26055,26738,27476,28189,36767
-      },
-      /*Y'  qi=40  OC_MODE_GOLDEN_MV*/
-      {
-          647, 4106, 8693,12785,15872,18212,20329,22321,
-        24111,25726,27267,28514,29880,30676,31809,36072
-      }
-    },
-    {
-      /*Cb  qi=40  OC_MODE_INTRA*/
-      {
-         3256, 9823,13541,16511,19100,20670,22078,23745,
-        25879,27898,29715,31600,32809,34363,35093,40240
-      },
-      /*Cb  qi=40  OC_MODE_INTER_NOMV*/
-      {
-         1404, 4535,11191,14847,17779,21889,46198,42837,
-        31627,36224,27226,32523,34227,39467,35533,42171
-      },
-      /*Cb  qi=40  OC_MODE_INTER_MV*/
-      {
-         1941, 7008,12828,15885,19800,23664,26443,28705,
-        31799,32440,34658,36059,33980,39025,40661,41043
-      },
-      /*Cb  qi=40  OC_MDOE_INTER_MV_LAST*/
-      {
-         1196, 6039,12961,16227,20080,23894,26241,27612,
-        28647,29320,29375,29227,28008,28378,28144,28532
-      },
-      /*Cb  qi=40  OC_MODE_INTER_MV_LAST2*/
-      {
-         1866, 7063,12939,15825,19335,23397,26214,28577,
-        30055,30885,32518,34647,34015,39790,41742,44557
-      },
-      /*Cb  qi=40  OC_MODE_INTER_MV_FOUR*/
-      {
-         1265, 5166,12171,15951,19671,23461,26512,28904,
-        31169,33416,34605,35550,37627,38229,40115,42375
-      },
-      /*Cb  qi=40  OC_MODE_GOLDEN_NOMV*/
-      {
-         1403, 4628, 9511,12637,15437,18384,19542,19958,
-        21642,22969,24320,24537,24888,24758,24785,28312
-      },
-      /*Cb  qi=40  OC_MODE_GOLDEN_MV*/
-      {
-         1412, 5912,12872,16034,19063,21539,22443,22915,
-        23169,23954,24073,24297,24757,25573,25288,28562
-      }
-    },
-    {
-      /*Cr  qi=40  OC_MODE_INTRA*/
-      {
-         1690, 6153, 9563,12070,14269,16140,17969,19855,
-        21592,22490,23518,25137,26324,26930,28478,32738
-      },
-      /*Cr  qi=40  OC_MODE_INTER_NOMV*/
-      {
-          661, 2308, 6980,11382,14192,31265,34645,19090,
-        16926, 9416, 6264, 6193,12105,13241, 9378, 5669
-      },
-      /*Cr  qi=40  OC_MODE_INTER_MV*/
-      {
-          851, 3289, 8153,12568,15503,17939,19900,21913,
-        23866,25018,25727,26359,26499,27061,29078,30341
-      },
-      /*Cr  qi=40  OC_MDOE_INTER_MV_LAST*/
-      {
-          628, 2965, 8111,12625,15563,17804,19531,19701,
-        19343,18022,16895,16131,15829,16270,16634,15220
-      },
-      /*Cr  qi=40  OC_MODE_INTER_MV_LAST2*/
-      {
-          895, 3289, 7713,11529,15158,17760,19844,19920,
-        20837,17224,17246,18736,24057,26528,24432,23040
-      },
-      /*Cr  qi=40  OC_MODE_INTER_MV_FOUR*/
-      {
-          643, 2956, 8016,12245,15206,17547,19437,21151,
-        22734,24642,25752,26768,26977,29984,29090,32541
-      },
-      /*Cr  qi=40  OC_MODE_GOLDEN_NOMV*/
-      {
-          714, 2628, 6305, 9566,10721,11382,12923,12865,
-        12917,13444,13707,13830,14351,14547,15373,15925
-      },
-      /*Cr  qi=40  OC_MODE_GOLDEN_MV*/
-      {
-          703, 3234, 7831,11886,13543,14956,15779,15109,
-        15616,14980,14432,14689,14823,15136,15172,15408
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=41  OC_MODE_INTRA*/
-      {
-         2358, 6008, 9721,12128,14342,16190,17808,19086,
-        20738,22357,23553,24372,25476,26625,27634,34626
-      },
-      /*Y'  qi=41  OC_MODE_INTER_NOMV*/
-      {
-          521, 3603, 8830,13360,16355,18843,20791,22690,
-        24437,25885,27450,28706,30286,31491,32638,39675
-      },
-      /*Y'  qi=41  OC_MODE_INTER_MV*/
-      {
-         1434, 4383, 8862,12754,15809,17906,19709,21487,
-        23246,24973,26549,27990,29335,30483,31695,36372
-      },
-      /*Y'  qi=41  OC_MDOE_INTER_MV_LAST*/
-      {
-          664, 4424, 8808,12838,15631,17866,19871,21752,
-        23500,25114,26647,28068,29376,30597,31658,36410
-      },
-      /*Y'  qi=41  OC_MODE_INTER_MV_LAST2*/
-      {
-          685, 4276, 8939,12994,15981,18122,19962,21716,
-        23438,25033,26568,27913,29224,30479,31405,38314
-      },
-      /*Y'  qi=41  OC_MODE_INTER_MV_FOUR*/
-      {
-          556, 3890, 8643,12709,15604,17941,19992,21866,
-        23643,25300,26851,28254,29542,30738,31839,35913
-      },
-      /*Y'  qi=41  OC_MODE_GOLDEN_NOMV*/
-      {
-          501, 3227, 8667,12650,15062,16677,19010,21061,
-        22469,24046,25273,25838,26570,27455,28205,36788
-      },
-      /*Y'  qi=41  OC_MODE_GOLDEN_MV*/
-      {
-          658, 4127, 8695,12832,15905,18239,20360,22344,
-        24128,25780,27290,28558,29887,30688,31841,36096
-      }
-    },
-    {
-      /*Cb  qi=41  OC_MODE_INTRA*/
-      {
-         3255, 9838,13547,16532,19103,20683,22104,23761,
-        25868,27936,29686,31656,32837,34355,35046,40326
-      },
-      /*Cb  qi=41  OC_MODE_INTER_NOMV*/
-      {
-         1406, 4542,11200,14870,18056,22235,25921,42197,
-        29939,31322,30853,31666,29306,32985,34389,36448
-      },
-      /*Cb  qi=41  OC_MODE_INTER_MV*/
-      {
-         2099, 6965,12894,15821,19499,23392,26542,28581,
-        30933,32632,34378,36295,34347,37589,40389,41283
-      },
-      /*Cb  qi=41  OC_MDOE_INTER_MV_LAST*/
-      {
-         1220, 5965,12958,16269,20140,23903,26244,27587,
-        28749,29184,29564,29250,28078,28130,28362,28658
-      },
-      /*Cb  qi=41  OC_MODE_INTER_MV_LAST2*/
-      {
-         1833, 6945,12944,15848,19480,23356,26169,28784,
-        30395,31125,32407,32960,32937,37927,41960,42604
-      },
-      /*Cb  qi=41  OC_MODE_INTER_MV_FOUR*/
-      {
-         1271, 5160,12172,15966,19661,23438,26514,29078,
-        31015,33158,35136,35464,36675,38457,41130,43101
-      },
-      /*Cb  qi=41  OC_MODE_GOLDEN_NOMV*/
-      {
-         1404, 4636, 9492,12552,15372,18466,19364,19940,
-        21649,23104,24388,24609,24679,24806,24793,28303
-      },
-      /*Cb  qi=41  OC_MODE_GOLDEN_MV*/
-      {
-         1436, 5925,12890,16053,19039,21621,22369,22910,
-        23179,24020,24137,23954,24770,25544,25352,28491
-      }
-    },
-    {
-      /*Cr  qi=41  OC_MODE_INTRA*/
-      {
-         1692, 6159, 9566,12069,14275,16147,17972,19868,
-        21594,22503,23519,25148,26339,26892,28541,32725
-      },
-      /*Cr  qi=41  OC_MODE_INTER_NOMV*/
-      {
-          667, 2310, 7004,11719,14203,15678,34133,21660,
-        23152,19744,27520,20718,22343,13273,24704,29632
-      },
-      /*Cr  qi=41  OC_MODE_INTER_MV*/
-      {
-          891, 3340, 8048,12251,15370,17950,19889,20924,
-        23493,25438,25919,25142,26974,27360,28713,30505
-      },
-      /*Cr  qi=41  OC_MDOE_INTER_MV_LAST*/
-      {
-          633, 2950, 8155,12640,15585,17833,19522,19711,
-        19422,17589,16333,15469,15297,16050,16467,15119
-      },
-      /*Cr  qi=41  OC_MODE_INTER_MV_LAST2*/
-      {
-          895, 3269, 7721,11915,15309,17932,19744,19732,
-        20625,16588,13248,12098,29816,16070,12425, 6903
-      },
-      /*Cr  qi=41  OC_MODE_INTER_MV_FOUR*/
-      {
-          649, 2963, 8016,12261,15228,17531,19495,21120,
-        22915,25016,26001,26396,26625,29002,28904,31729
-      },
-      /*Cr  qi=41  OC_MODE_GOLDEN_NOMV*/
-      {
-          718, 2630, 6300, 9588,10684,11451,13023,12811,
-        13131,13355,13686,13821,14336,14517,15427,15792
-      },
-      /*Cr  qi=41  OC_MODE_GOLDEN_MV*/
-      {
-          701, 3240, 7857,11882,13586,14997,15665,15093,
-        15685,14894,14592,14811,14861,15211,15191,15360
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=42  OC_MODE_INTRA*/
-      {
-         2806, 6525,10485,12867,15118,17010,18698,20006,
-        21689,23322,24553,25357,26478,27627,28642,36098
-      },
-      /*Y'  qi=42  OC_MODE_INTER_NOMV*/
-      {
-          703, 4197, 9738,14276,17287,19785,21780,23689,
-        25480,27102,28640,30060,31484,32881,34176,42571
-      },
-      /*Y'  qi=42  OC_MODE_INTER_MV*/
-      {
-         1269, 4860, 9725,13600,16540,18793,20819,22663,
-        24386,25978,27453,28763,30039,31181,32211,36260
-      },
-      /*Y'  qi=42  OC_MDOE_INTER_MV_LAST*/
-      {
-          994, 5296, 9634,13687,16495,18772,20821,22746,
-        24539,26264,27878,29424,30846,31970,33088,37818
-      },
-      /*Y'  qi=42  OC_MODE_INTER_MV_LAST2*/
-      {
-          669, 5332, 9882,13990,16996,19204,21118,22875,
-        24595,26238,27775,29121,30369,32080,32939,39043
-      },
-      /*Y'  qi=42  OC_MODE_INTER_MV_FOUR*/
-      {
-          532, 4443, 9521,13594,16527,18914,21038,22968,
-        24824,26561,28132,29516,30827,31998,33065,37286
-      },
-      /*Y'  qi=42  OC_MODE_GOLDEN_NOMV*/
-      {
-          719, 3923, 9612,13507,15901,17442,19883,22061,
-        23593,24935,26106,26891,27542,28521,29223,38236
-      },
-      /*Y'  qi=42  OC_MODE_GOLDEN_MV*/
-      {
-          795, 4748, 9561,13751,16824,19187,21340,23343,
-        25221,26887,28397,29754,31098,32038,33474,37633
-      }
-    },
-    {
-      /*Cb  qi=42  OC_MODE_INTRA*/
-      {
-         3721,10681,14557,17677,20357,21933,23358,25054,
-        27265,29385,31188,33213,34498,36041,37026,42516
-      },
-      /*Cb  qi=42  OC_MODE_INTER_NOMV*/
-      {
-         1682, 5274,12603,16125,18965,22689,49664,39296,
-        33237,29529,31915,31760,36318,40304,36296,45239
-      },
-      /*Cb  qi=42  OC_MODE_INTER_MV*/
-      {
-         1056, 7345,13853,17711,21564,25614,28764,31146,
-        33377,35114,36673,37350,39041,41533,41871,44977
-      },
-      /*Cb  qi=42  OC_MDOE_INTER_MV_LAST*/
-      {
-         2316, 6853,14024,17273,21343,25353,27722,29400,
-        30505,31099,31053,31164,30464,30433,29806,30618
-      },
-      /*Cb  qi=42  OC_MODE_INTER_MV_LAST2*/
-      {
-         2413, 8215,14039,16931,20467,24379,27489,29589,
-        32602,32806,32368,33133,36089,43232,39334,40921
-      },
-      /*Cb  qi=42  OC_MODE_INTER_MV_FOUR*/
-      {
-         1453, 5889,13236,16958,20795,24702,28085,30440,
-        32845,35205,36611,37657,39740,39846,44547,44641
-      },
-      /*Cb  qi=42  OC_MODE_GOLDEN_NOMV*/
-      {
-         1765, 5358,10489,13487,16487,20068,20874,21438,
-        23180,24745,25849,26805,26138,27015,26655,30344
-      },
-      /*Cb  qi=42  OC_MODE_GOLDEN_MV*/
-      {
-         1707, 6730,13959,17098,20134,23087,25304,25888,
-        26532,26118,28409,26615,27337,28471,29994,30417
-      }
-    },
-    {
-      /*Cr  qi=42  OC_MODE_INTRA*/
-      {
-         1783, 6652,10214,12804,15080,17008,18885,20849,
-        22588,23582,24559,26226,27579,28137,29779,34190
-      },
-      /*Cr  qi=42  OC_MODE_INTER_NOMV*/
-      {
-          786, 2687, 7745,12064,14811,33231,32068,18275,
-        18297,12672, 7174, 6558,12558,11687,10283, 6356
-      },
-      /*Cr  qi=42  OC_MODE_INTER_MV*/
-      {
-          507, 3606, 9278,12984,15313,17857,20335,22273,
-        25646,26739,25877,27635,26516,29914,28594,30124
-      },
-      /*Cr  qi=42  OC_MDOE_INTER_MV_LAST*/
-      {
-          978, 3457, 8960,13774,16794,18966,20693,20880,
-        20640,19003,17924,17064,16934,17737,18049,16160
-      },
-      /*Cr  qi=42  OC_MODE_INTER_MV_LAST2*/
-      {
-         1095, 3753, 8358,12912,16423,19013,20558,21167,
-        21698,18408,17924,19372,25792,28896,23947,27675
-      },
-      /*Cr  qi=42  OC_MODE_INTER_MV_FOUR*/
-      {
-          746, 3378, 8757,13083,16157,18559,20512,22288,
-        24157,26012,26540,27849,27933,30219,30296,33172
-      },
-      /*Cr  qi=42  OC_MODE_GOLDEN_NOMV*/
-      {
-          913, 3044, 7018,10221,11253,12283,13750,13744,
-        14001,13822,14863,15038,15396,16272,16736,17450
-      },
-      /*Cr  qi=42  OC_MODE_GOLDEN_MV*/
-      {
-          839, 3717, 8666,12972,15255,16522,18611,18345,
-        18375,16574,15247,15977,16319,18232,17594,20370
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=43  OC_MODE_INTRA*/
-      {
-         3289, 7190,11308,13678,15948,17875,19595,20968,
-        22674,24337,25596,26402,27552,28744,29761,37437
-      },
-      /*Y'  qi=43  OC_MODE_INTER_NOMV*/
-      {
-          920, 4885,10742,15198,18260,20802,22898,24823,
-        26750,28425,29898,31528,32807,34000,35441,43432
-      },
-      /*Y'  qi=43  OC_MODE_INTER_MV*/
-      {
-         1444, 5464,10577,14543,17567,19922,22016,23917,
-        25650,27229,28692,30015,31227,32344,33358,37112
-      },
-      /*Y'  qi=43  OC_MDOE_INTER_MV_LAST*/
-      {
-         1596, 6088,10589,14660,17474,19763,21888,23870,
-        25745,27474,29134,30643,32055,33255,34450,39096
-      },
-      /*Y'  qi=43  OC_MODE_INTER_MV_LAST2*/
-      {
-          889, 6113,10805,14945,17973,20236,22221,24090,
-        25927,27645,29263,30714,32042,33505,34374,40119
-      },
-      /*Y'  qi=43  OC_MODE_INTER_MV_FOUR*/
-      {
-          610, 5018,10423,14524,17556,20010,22163,24125,
-        25975,27714,29305,30718,32030,33224,34310,38588
-      },
-      /*Y'  qi=43  OC_MODE_GOLDEN_NOMV*/
-      {
-          989, 4622,10601,14290,16652,18176,20942,23072,
-        24598,26249,27263,28263,28790,30047,30751,39354
-      },
-      /*Y'  qi=43  OC_MODE_GOLDEN_MV*/
-      {
-          936, 5259,10456,14775,17863,20307,22546,24590,
-        26475,28205,29665,30865,32128,32991,33963,38590
-      }
-    },
-    {
-      /*Cb  qi=43  OC_MODE_INTRA*/
-      {
-         3964,11162,15101,18273,20994,22585,23965,25683,
-        27901,30083,31877,33987,35176,36670,37782,43478
-      },
-      /*Cb  qi=43  OC_MODE_INTER_NOMV*/
-      {
-         1857, 5699,13165,16796,20112,23867,42634,27893,
-        31641,29870,32895,33651,34475,38438,38218,45563
-      },
-      /*Cb  qi=43  OC_MODE_INTER_MV*/
-      {
-         1173, 7972,14315,18055,21768,25955,29360,31582,
-        33297,35717,37523,38787,38302,42543,46508,46181
-      },
-      /*Cb  qi=43  OC_MDOE_INTER_MV_LAST*/
-      {
-         2514, 7581,14648,17897,22094,26197,28700,30278,
-        31283,31683,31803,31740,31196,30213,30693,31046
-      },
-      /*Cb  qi=43  OC_MODE_INTER_MV_LAST2*/
-      {
-         2608, 8727,14634,17555,21147,25209,28124,30664,
-        32413,32722,32947,33898,35312,40505,44275,40899
-      },
-      /*Cb  qi=43  OC_MODE_INTER_MV_FOUR*/
-      {
-         1552, 6326,13866,17635,21637,25633,28931,31619,
-        34457,36461,38180,39796,40973,42336,45427,45612
-      },
-      /*Cb  qi=43  OC_MODE_GOLDEN_NOMV*/
-      {
-         2018, 5733,10777,13637,16966,20475,21357,22113,
-        23806,25481,26490,27254,26495,27089,27029,30628
-      },
-      /*Cb  qi=43  OC_MODE_GOLDEN_MV*/
-      {
-         1868, 7105,14550,17761,21025,23730,24499,25264,
-        25322,26031,26400,26435,26861,27862,27689,31132
-      }
-    },
-    {
-      /*Cr  qi=43  OC_MODE_INTRA*/
-      {
-         1845, 7034,10741,13411,15740,17682,19602,21548,
-        23424,24322,25379,27031,28433,29061,30595,35063
-      },
-      /*Cr  qi=43  OC_MODE_INTER_NOMV*/
-      {
-          888, 3037, 8551,12928,16075,30592,18798,20979,
-        17966,14385, 8278, 8530,13270,13928,11067, 7091
-      },
-      /*Cr  qi=43  OC_MODE_INTER_MV*/
-      {
-          577, 4124, 9828,13266,15601,18148,21124,22739,
-        25448,27437,28391,29280,28867,31830,29954,32198
-      },
-      /*Cr  qi=43  OC_MDOE_INTER_MV_LAST*/
-      {
-         1141, 3842, 9622,14553,17590,19762,21532,21787,
-        21413,19304,18654,17188,16830,17196,17124,16638
-      },
-      /*Cr  qi=43  OC_MODE_INTER_MV_LAST2*/
-      {
-         1259, 4112, 8979,13874,17159,19481,21220,21440,
-        23092,19620,18345,19040,27648,31098,23883,29664
-      },
-      /*Cr  qi=43  OC_MODE_INTER_MV_FOUR*/
-      {
-          826, 3726, 9451,13888,17019,19451,21325,23373,
-        24943,27373,28554,28820,31212,31274,31500,35704
-      },
-      /*Cr  qi=43  OC_MODE_GOLDEN_NOMV*/
-      {
-         1067, 3368, 7355,10756,11713,12924,14326,14266,
-        14471,14726,15227,15529,15560,16123,16747,17327
-      },
-      /*Cr  qi=43  OC_MODE_GOLDEN_MV*/
-      {
-          940, 4114, 9319,13377,15041,16427,17419,16698,
-        17080,16448,16265,16277,16542,17003,16596,17213
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=44  OC_MODE_INTRA*/
-      {
-         3302, 7203,11316,13689,15961,17895,19619,20993,
-        22718,24366,25609,26426,27580,28772,29797,37464
-      },
-      /*Y'  qi=44  OC_MODE_INTER_NOMV*/
-      {
-          934, 4914,10792,15208,18307,20821,22898,24855,
-        26752,28406,30002,31464,32948,34225,35402,43846
-      },
-      /*Y'  qi=44  OC_MODE_INTER_MV*/
-      {
-         1443, 5500,10592,14642,17592,19897,21969,23852,
-        25586,27224,28701,29994,31281,32390,33448,37361
-      },
-      /*Y'  qi=44  OC_MDOE_INTER_MV_LAST*/
-      {
-         1542, 6108,10566,14639,17484,19813,21917,23894,
-        25754,27492,29128,30705,32029,33337,34419,39153
-      },
-      /*Y'  qi=44  OC_MODE_INTER_MV_LAST2*/
-      {
-          847, 6090,10805,15017,18004,20278,22259,24079,
-        25862,27574,29161,30559,31781,33252,34275,39992
-      },
-      /*Y'  qi=44  OC_MODE_INTER_MV_FOUR*/
-      {
-          621, 5022,10452,14537,17580,20025,22169,24146,
-        26031,27771,29381,30763,32094,33265,34382,38594
-      },
-      /*Y'  qi=44  OC_MODE_GOLDEN_NOMV*/
-      {
-          999, 4636,10592,14245,16639,18351,21000,22927,
-        24572,26163,27223,28249,28793,29997,30788,39374
-      },
-      /*Y'  qi=44  OC_MODE_GOLDEN_MV*/
-      {
-          959, 5279,10449,14792,17869,20306,22549,24611,
-        26489,28214,29665,30877,32182,32964,33986,38590
-      }
-    },
-    {
-      /*Cb  qi=44  OC_MODE_INTRA*/
-      {
-         3967,11162,15103,18268,21002,22572,23964,25678,
-        27911,30086,31906,33978,35198,36703,37860,43555
-      },
-      /*Cb  qi=44  OC_MODE_INTER_NOMV*/
-      {
-         1862, 5690,13111,16642,19690,23069,43156,26780,
-        30887,33322,32225,41792,38505,40732,45312,41531
-      },
-      /*Cb  qi=44  OC_MODE_INTER_MV*/
-      {
-         1144, 7847,14476,18440,22162,26319,29548,31638,
-        33454,36166,37629,38729,39270,40684,45352,47358
-      },
-      /*Cb  qi=44  OC_MDOE_INTER_MV_LAST*/
-      {
-         2610, 7422,14595,17880,22048,26121,28583,30238,
-        31296,31803,31887,31716,30673,30824,30165,31046
-      },
-      /*Cb  qi=44  OC_MODE_INTER_MV_LAST2*/
-      {
-         2614, 8796,14670,17573,21242,25360,28258,30781,
-        32710,33629,33595,35158,33264,38495,42782,41029
-      },
-      /*Cb  qi=44  OC_MODE_INTER_MV_FOUR*/
-      {
-         1555, 6302,13841,17582,21558,25600,28896,31648,
-        33817,36520,38013,38770,41130,40770,44940,47200
-      },
-      /*Cb  qi=44  OC_MODE_GOLDEN_NOMV*/
-      {
-         2010, 5771,10766,13440,16909,20345,21304,22065,
-        23899,25434,26388,27407,26477,27298,27086,30781
-      },
-      /*Cb  qi=44  OC_MODE_GOLDEN_MV*/
-      {
-         1871, 7093,14548,17749,20974,23730,24530,25188,
-        25408,25934,26330,26609,26806,27960,27596,31056
-      }
-    },
-    {
-      /*Cr  qi=44  OC_MODE_INTRA*/
-      {
-         1860, 7044,10761,13428,15760,17706,19624,21539,
-        23456,24346,25400,27086,28498,29087,30725,35136
-      },
-      /*Cr  qi=44  OC_MODE_INTER_NOMV*/
-      {
-          895, 3040, 8557,12905,15752,29405,24992,18027,
-        19781,14480, 8067,22613,25163,14079,11615, 6957
-      },
-      /*Cr  qi=44  OC_MODE_INTER_MV*/
-      {
-          569, 3981, 9948,13596,15800,18084,21082,23134,
-        25271,27538,29416,29548,28698,30269,31990,32680
-      },
-      /*Cr  qi=44  OC_MDOE_INTER_MV_LAST*/
-      {
-         1143, 3832, 9633,14498,17621,19758,21602,21783,
-        21382,19396,18273,16667,16719,17220,18122,16418
-      },
-      /*Cr  qi=44  OC_MODE_INTER_MV_LAST2*/
-      {
-         1260, 4139, 9015,13907,17055,19584,21531,21667,
-        23490,19429,18529,18426,27978,29728,25291,22384
-      },
-      /*Cr  qi=44  OC_MODE_INTER_MV_FOUR*/
-      {
-          834, 3723, 9441,13849,16975,19443,21344,23332,
-        25057,27589,28110,28412,30744,31605,31065,36196
-      },
-      /*Cr  qi=44  OC_MODE_GOLDEN_NOMV*/
-      {
-         1066, 3372, 7323,10743,11909,12994,14361,14211,
-        14637,14674,15316,15618,15699,16062,16940,17378
-      },
-      /*Cr  qi=44  OC_MODE_GOLDEN_MV*/
-      {
-          941, 4111, 9307,13348,15075,16470,17369,16644,
-        16987,16287,16196,16268,16524,17029,16407,17212
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=45  OC_MODE_INTRA*/
-      {
-         3618, 7694,11878,14214,16525,18473,20225,21623,
-        23360,25043,26330,27149,28332,29559,30626,38568
-      },
-      /*Y'  qi=45  OC_MODE_INTER_NOMV*/
-      {
-         1035, 5357,11465,15854,19003,21501,23656,25639,
-        27594,29297,30938,32424,33842,34941,36518,45179
-      },
-      /*Y'  qi=45  OC_MODE_INTER_MV*/
-      {
-         1428, 5941,11236,15286,18292,20706,22842,24765,
-        26509,28122,29564,30863,32170,33285,34312,38171
-      },
-      /*Y'  qi=45  OC_MDOE_INTER_MV_LAST*/
-      {
-         1624, 6652,11232,15339,18176,20480,22609,24625,
-        26533,28369,30107,31669,33125,34384,35544,40341
-      },
-      /*Y'  qi=45  OC_MODE_INTER_MV_LAST2*/
-      {
-          908, 6551,11469,15680,18721,21034,23030,24932,
-        26783,28579,30212,31649,33073,34452,35440,41410
-      },
-      /*Y'  qi=45  OC_MODE_INTER_MV_FOUR*/
-      {
-          663, 5408,11070,15184,18276,20762,22942,24941,
-        26842,28604,30212,31658,33005,34246,35372,39776
-      },
-      /*Y'  qi=45  OC_MODE_GOLDEN_NOMV*/
-      {
-         1036, 4985,11105,14745,17242,19084,21728,23656,
-        25679,26865,28122,29203,29706,30722,31658,40624
-      },
-      /*Y'  qi=45  OC_MODE_GOLDEN_MV*/
-      {
-         1017, 5638,11042,15498,18590,21076,23379,25440,
-        27365,29100,30592,31861,33171,33988,34994,39750
-      }
-    },
-    {
-      /*Cb  qi=45  OC_MODE_INTRA*/
-      {
-         4777,12393,16449,19624,22470,24160,25583,27369,
-        29829,32002,33813,36099,37426,38730,39917,46172
-      },
-      /*Cb  qi=45  OC_MODE_INTER_NOMV*/
-      {
-         2363, 6803,14595,18020,21590,24285,45978,42368,
-        38502,34553,33116,36069,39930,45142,40395,47738
-      },
-      /*Cb  qi=45  OC_MODE_INTER_MV*/
-      {
-         1470, 9351,15587,19387,23205,27617,31304,33825,
-        35985,38250,40048,41204,41553,45963,48442,49882
-      },
-      /*Cb  qi=45  OC_MDOE_INTER_MV_LAST*/
-      {
-         3373, 8778,16070,19322,23709,28094,30775,32440,
-        33647,33849,34067,34075,32594,33100,32775,33239
-      },
-      /*Cb  qi=45  OC_MODE_INTER_MV_LAST2*/
-      {
-         3291, 9969,16065,19074,22833,27088,30137,32659,
-        35108,36255,37279,36357,39942,44854,45931,48298
-      },
-      /*Cb  qi=45  OC_MODE_INTER_MV_FOUR*/
-      {
-         1945, 7431,15253,19094,23353,27683,31043,33877,
-        36675,38613,40273,41306,42988,44300,49010,49087
-      },
-      /*Cb  qi=45  OC_MODE_GOLDEN_NOMV*/
-      {
-         2446, 6805,11895,14139,17923,21575,22614,23828,
-        25500,27463,28004,28752,28249,28994,28962,32895
-      },
-      /*Cb  qi=45  OC_MODE_GOLDEN_MV*/
-      {
-         2315, 8198,15952,19288,22642,25724,26423,27237,
-        27396,27962,28103,28795,28314,29636,29410,33471
-      }
-    },
-    {
-      /*Cr  qi=45  OC_MODE_INTRA*/
-      {
-         2161, 7808,11646,14401,16807,18802,20807,22842,
-        24743,25664,26733,28437,29974,30465,32026,36670
-      },
-      /*Cr  qi=45  OC_MODE_INTER_NOMV*/
-      {
-         1116, 3670, 9743,13835,16525,30454,36404,23131,
-        21962,13590, 8567, 9727,17055,15453,14277, 8225
-      },
-      /*Cr  qi=45  OC_MODE_INTER_MV*/
-      {
-          750, 4917,10839,14292,16804,19625,22367,24326,
-        27406,28054,29071,31502,31134,32962,33327,34408
-      },
-      /*Cr  qi=45  OC_MDOE_INTER_MV_LAST*/
-      {
-         1490, 4481,10620,15611,18782,21105,22864,23232,
-        22722,20518,19609,18577,18072,18370,19646,17753
-      },
-      /*Cr  qi=45  OC_MODE_INTER_MV_LAST2*/
-      {
-         1568, 4762, 9913,14918,18203,20993,22586,23226,
-        24760,20496,19420,21934,22816,30592,32409,29056
-      },
-      /*Cr  qi=45  OC_MODE_INTER_MV_FOUR*/
-      {
-         1048, 4382,10503,15046,18249,20759,22854,24706,
-        26508,28048,29254,30771,31422,32113,33912,36501
-      },
-      /*Cr  qi=45  OC_MODE_GOLDEN_NOMV*/
-      {
-         1292, 4017, 8109,11521,12827,13902,15247,15512,
-        15588,15916,16054,16244,16821,17101,17696,18495
-      },
-      /*Cr  qi=45  OC_MODE_GOLDEN_MV*/
-      {
-         1173, 4794,10313,14434,16063,17568,18828,18155,
-        18191,17488,17168,17656,17596,17853,17665,18369
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=46  OC_MODE_INTRA*/
-      {
-         3629, 7709,11892,14231,16547,18502,20258,21647,
-        23386,25058,26345,27170,28351,29576,30628,38557
-      },
-      /*Y'  qi=46  OC_MODE_INTER_NOMV*/
-      {
-         1049, 5374,11480,15853,19030,21503,23647,25653,
-        27602,29297,30879,32418,33862,35157,36397,45512
-      },
-      /*Y'  qi=46  OC_MODE_INTER_MV*/
-      {
-         1419, 5913,11225,15288,18282,20684,22801,24738,
-        26500,28125,29573,30873,32187,33302,34330,38150
-      },
-      /*Y'  qi=46  OC_MDOE_INTER_MV_LAST*/
-      {
-         1815, 6696,11313,15399,18199,20444,22566,24594,
-        26502,28320,30083,31671,33091,34326,35518,40362
-      },
-      /*Y'  qi=46  OC_MODE_INTER_MV_LAST2*/
-      {
-          926, 6415,11480,15691,18710,21030,23039,24989,
-        26808,28609,30329,31743,33127,34335,35429,41199
-      },
-      /*Y'  qi=46  OC_MODE_INTER_MV_FOUR*/
-      {
-          675, 5447,11076,15190,18293,20787,22957,24955,
-        26842,28617,30248,31655,33048,34237,35403,39808
-      },
-      /*Y'  qi=46  OC_MODE_GOLDEN_NOMV*/
-      {
-         1045, 5001,11126,14736,17229,19445,21829,23707,
-        25770,27020,28229,29430,29869,30763,31781,40598
-      },
-      /*Y'  qi=46  OC_MODE_GOLDEN_MV*/
-      {
-         1032, 5609,11073,15522,18620,21092,23404,25463,
-        27371,29112,30599,31877,33172,33995,35025,39799
-      }
-    },
-    {
-      /*Cb  qi=46  OC_MODE_INTRA*/
-      {
-         4770,12386,16447,19621,22463,24154,25567,27365,
-        29811,32009,33803,36062,37426,38810,39879,46087
-      },
-      /*Cb  qi=46  OC_MODE_INTER_NOMV*/
-      {
-         2357, 6807,14668,18271,21361,24442,45964,29751,
-        36203,44279,33683,34801,38994,42228,46406,46182
-      },
-      /*Cb  qi=46  OC_MODE_INTER_MV*/
-      {
-         1524, 9216,15698,19435,23186,27752,31351,31669,
-        35141,37486,39578,42469,43135,45545,49579,50148
-      },
-      /*Cb  qi=46  OC_MDOE_INTER_MV_LAST*/
-      {
-         3426, 9238,16030,19298,23696,27985,30693,32375,
-        33374,34001,33831,33837,32684,33152,32364,33198
-      },
-      /*Cb  qi=46  OC_MODE_INTER_MV_LAST2*/
-      {
-         3289,10029,16057,19090,22989,26953,30095,32959,
-        34810,35331,35401,37250,37604,40471,41172,46153
-      },
-      /*Cb  qi=46  OC_MODE_INTER_MV_FOUR*/
-      {
-         1951, 7441,15281,19099,23335,27573,31107,33918,
-        36503,38591,40391,41614,43099,43183,48565,49169
-      },
-      /*Cb  qi=46  OC_MODE_GOLDEN_NOMV*/
-      {
-         2439, 6826,11940,14027,17834,21519,22512,23690,
-        25494,27199,28051,28812,28202,28991,29035,32794
-      },
-      /*Cb  qi=46  OC_MODE_GOLDEN_MV*/
-      {
-         2297, 8214,15959,19296,22651,25721,26336,27232,
-        27224,27638,28036,28654,28427,29547,28919,33329
-      }
-    },
-    {
-      /*Cr  qi=46  OC_MODE_INTRA*/
-      {
-         2196, 7820,11650,14400,16806,18811,20813,22845,
-        24780,25657,26726,28429,29995,30496,31982,36695
-      },
-      /*Cr  qi=46  OC_MODE_INTER_NOMV*/
-      {
-         1122, 3681, 9781,13876,16609,30310,22373,22233,
-        19349,12108, 8165,13057,15518,13802, 9205, 8244
-      },
-      /*Cr  qi=46  OC_MODE_INTER_MV*/
-      {
-          774, 4843,10839,14300,16721,19561,22035,24232,
-        28025,29490,31490,31310,30890,33592,34190,33714
-      },
-      /*Cr  qi=46  OC_MDOE_INTER_MV_LAST*/
-      {
-         1588, 4521,10637,15640,18757,21139,22870,23091,
-        22671,20567,19623,18745,17770,18267,19153,17704
-      },
-      /*Cr  qi=46  OC_MODE_INTER_MV_LAST2*/
-      {
-         1548, 4798, 9932,15073,18146,20615,22667,23138,
-        24712,20925,19784,22758,28769,29476,36005,28816
-      },
-      /*Cr  qi=46  OC_MODE_INTER_MV_FOUR*/
-      {
-         1059, 4375,10512,15057,18277,20767,22812,24710,
-        26458,28366,29067,30329,32154,32929,31290,38090
-      },
-      /*Cr  qi=46  OC_MODE_GOLDEN_NOMV*/
-      {
-         1289, 4023, 8162,11280,12776,13848,15320,15469,
-        15691,15998,16041,16235,16806,17089,17531,18554
-      },
-      /*Cr  qi=46  OC_MODE_GOLDEN_MV*/
-      {
-         1174, 4796,10334,14439,16053,17571,18668,18085,
-        18158,17572,17048,17341,17764,18175,17400,18377
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=47  OC_MODE_INTRA*/
-      {
-         4730, 9169,13387,15726,18119,20164,21984,23445,
-        25245,26940,28240,29092,30317,31577,32703,41087
-      },
-      /*Y'  qi=47  OC_MODE_INTER_NOMV*/
-      {
-         1637, 6754,13086,17449,20720,23291,25565,27679,
-        29734,31474,33221,34598,36295,37292,38794,47292
-      },
-      /*Y'  qi=47  OC_MODE_INTER_MV*/
-      {
-         1887, 7379,12801,16928,20013,22466,24619,26588,
-        28368,30037,31497,32867,34174,35312,36366,40413
-      },
-      /*Y'  qi=47  OC_MDOE_INTER_MV_LAST*/
-      {
-         2325, 8258,12863,16948,19873,22310,24559,26643,
-        28579,30373,32117,33710,35154,36455,37687,42883
-      },
-      /*Y'  qi=47  OC_MODE_INTER_MV_LAST2*/
-      {
-         1508, 8285,13060,17322,20413,22865,25036,27006,
-        28825,30524,32076,33442,34799,36226,37474,43806
-      },
-      /*Y'  qi=47  OC_MODE_INTER_MV_FOUR*/
-      {
-         1038, 6684,12664,16810,20019,22639,24913,27002,
-        28964,30739,32366,33791,35177,36427,37589,42215
-      },
-      /*Y'  qi=47  OC_MODE_GOLDEN_NOMV*/
-      {
-         1547, 6321,12645,16274,18837,21201,23682,25754,
-        27800,29272,30511,31368,32191,33319,33924,43252
-      },
-      /*Y'  qi=47  OC_MODE_GOLDEN_MV*/
-      {
-         1523, 6913,12670,17190,20345,22931,25301,27470,
-        29416,31172,32571,33906,35171,36075,37226,42175
-      }
-    },
-    {
-      /*Cb  qi=47  OC_MODE_INTRA*/
-      {
-         5200,13068,17255,20518,23455,25164,26598,28508,
-        30888,33185,35074,37320,38772,40057,41260,47457
-      },
-      /*Cb  qi=47  OC_MODE_INTER_NOMV*/
-      {
-         2677, 7474,15617,19199,23189,27234,44183,45184,
-        35324,38324,35110,36973,39301,43984,44397,51349
-      },
-      /*Cb  qi=47  OC_MODE_INTER_MV*/
-      {
-         1731, 9719,16481,20376,24216,28992,32626,35409,
-        36887,39352,41655,42609,43601,46408,49854,53638
-      },
-      /*Cb  qi=47  OC_MDOE_INTER_MV_LAST*/
-      {
-         3881, 9507,16800,20128,24733,29206,31961,33691,
-        34839,35289,35279,35328,33971,34397,33776,34447
-      },
-      /*Cb  qi=47  OC_MODE_INTER_MV_LAST2*/
-      {
-         3607,10756,16906,20049,24018,28440,31811,33930,
-        36275,37793,38112,38799,38238,45909,44646,52001
-      },
-      /*Cb  qi=47  OC_MODE_INTER_MV_FOUR*/
-      {
-         2181, 7976,16001,19912,24284,28627,32274,35179,
-        37841,40179,42294,43503,45145,44897,50907,51379
-      },
-      /*Cb  qi=47  OC_MODE_GOLDEN_NOMV*/
-      {
-         2783, 7433,12476,14577,18464,22064,23360,24597,
-        26681,27951,29187,29832,29240,29957,29632,33888
-      },
-      /*Cb  qi=47  OC_MODE_GOLDEN_MV*/
-      {
-         2575, 8801,16712,20121,23652,26795,27403,28257,
-        28141,28726,29195,29641,29626,30999,30721,34542
-      }
-    },
-    {
-      /*Cr  qi=47  OC_MODE_INTRA*/
-      {
-         2407, 8398,12393,15229,17711,19704,21795,23916,
-        25887,26813,27913,29720,31073,31733,33403,38050
-      },
-      /*Cr  qi=47  OC_MODE_INTER_NOMV*/
-      {
-         1297, 4218,10634,15021,17893,34880,38592,26482,
-        22476,12298, 9860,14926,17042,15898,10228, 8690
-      },
-      /*Cr  qi=47  OC_MODE_INTER_MV*/
-      {
-          923, 5330,11718,15299,17706,20435,23648,25455,
-        28634,31893,33078,33426,32688,34856,33960,35533
-      },
-      /*Cr  qi=47  OC_MDOE_INTER_MV_LAST*/
-      {
-         1815, 5023,11582,16674,19812,22284,24034,24276,
-        23770,21451,20359,19564,18661,19471,20062,18508
-      },
-      /*Cr  qi=47  OC_MODE_INTER_MV_LAST2*/
-      {
-         1887, 5423,10774,16361,19540,22346,24257,24245,
-        26270,22601,22188,24354,31443,31616,34432,33011
-      },
-      /*Cr  qi=47  OC_MODE_INTER_MV_FOUR*/
-      {
-         1200, 4902,11362,15998,19329,21885,24020,26038,
-        27911,29644,31069,32488,32706,34163,33736,38724
-      },
-      /*Cr  qi=47  OC_MODE_GOLDEN_NOMV*/
-      {
-         1493, 4532, 8580,11789,13337,14681,15964,16289,
-        16359,16452,17025,16886,17725,18041,18338,19060
-      },
-      /*Cr  qi=47  OC_MODE_GOLDEN_MV*/
-      {
-         1346, 5358,11205,15312,16956,18676,19561,18900,
-        18961,18586,18118,18545,18730,18984,18611,19708
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=48  OC_MODE_INTRA*/
-      {
-         4879, 9394,13622,15956,18359,20397,22239,23727,
-        25525,27234,28553,29421,30657,31944,33064,41578
-      },
-      /*Y'  qi=48  OC_MODE_INTER_NOMV*/
-      {
-         1664, 6952,13322,17680,20964,23583,25889,28065,
-        30152,31986,33582,35354,36565,38026,39299,47964
-      },
-      /*Y'  qi=48  OC_MODE_INTER_MV*/
-      {
-         1936, 7615,12986,17128,20178,22632,24867,26915,
-        28764,30437,31942,33318,34662,35788,36914,40982
-      },
-      /*Y'  qi=48  OC_MDOE_INTER_MV_LAST*/
-      {
-         2538, 8636,13261,17341,20281,22716,24986,27078,
-        28983,30838,32537,34097,35502,36906,38187,43390
-      },
-      /*Y'  qi=48  OC_MODE_INTER_MV_LAST2*/
-      {
-         1437, 8113,13306,17540,20699,23188,25334,27388,
-        29320,31161,32742,34095,35283,36732,38159,44466
-      },
-      /*Y'  qi=48  OC_MODE_INTER_MV_FOUR*/
-      {
-         1055, 6908,12891,17040,20258,22917,25237,27347,
-        29318,31143,32775,34231,35606,36899,38075,42762
-      },
-      /*Y'  qi=48  OC_MODE_GOLDEN_NOMV*/
-      {
-         1582, 6494,12877,16505,19074,21439,23890,26036,
-        28222,29561,30848,31764,32589,33483,34491,43788
-      },
-      /*Y'  qi=48  OC_MODE_GOLDEN_MV*/
-      {
-         1563, 7057,12942,17445,20618,23215,25664,27822,
-        29771,31566,33030,34365,35584,36516,37647,42770
-      }
-    },
-    {
-      /*Cb  qi=48  OC_MODE_INTRA*/
-      {
-         5287,13251,17483,20726,23685,25428,26836,28748,
-        31163,33470,35409,37691,39151,40522,41661,47824
-      },
-      /*Cb  qi=48  OC_MODE_INTER_NOMV*/
-      {
-         2733, 7649,15790,19547,23393,26745,44687,33429,
-        34634,35233,38946,36687,39940,48864,44800,55222
-      },
-      /*Cb  qi=48  OC_MODE_INTER_MV*/
-      {
-         1902, 9923,16822,20658,24554,29361,33095,35766,
-        37385,39565,42311,42371,44481,46737,51108,55424
-      },
-      /*Cb  qi=48  OC_MDOE_INTER_MV_LAST*/
-      {
-         3957,10394,17062,20370,25123,29736,32418,34070,
-        35372,35543,35424,35631,34588,34968,33869,34804
-      },
-      /*Cb  qi=48  OC_MODE_INTER_MV_LAST2*/
-      {
-         3657,10905,17160,20309,24026,28241,32017,37442,
-        37405,41344,37864,38926,41875,46621,43949,52480
-      },
-      /*Cb  qi=48  OC_MODE_INTER_MV_FOUR*/
-      {
-         2216, 8204,16322,20220,24624,29040,32654,35557,
-        38477,40434,41705,43662,46704,45342,51120,52149
-      },
-      /*Cb  qi=48  OC_MODE_GOLDEN_NOMV*/
-      {
-         2820, 7587,12603,14782,18757,22390,23905,24854,
-        26748,28208,29640,30002,29438,30067,30077,34131
-      },
-      /*Cb  qi=48  OC_MODE_GOLDEN_MV*/
-      {
-         2599, 8991,16990,20415,23887,26983,27947,28621,
-        28766,29207,29403,29960,30171,31153,30549,34897
-      }
-    },
-    {
-      /*Cr  qi=48  OC_MODE_INTRA*/
-      {
-         2412, 8407,12392,15232,17703,19703,21798,23936,
-        25904,26868,27799,29676,31093,31630,33413,38129
-      },
-      /*Cr  qi=48  OC_MODE_INTER_NOMV*/
-      {
-         1300, 4219,10686,15171,18067,20458,34720,23178,
-        23074,13556,10108,13796,19395,16425,12114, 8993
-      },
-      /*Cr  qi=48  OC_MODE_INTER_MV*/
-      {
-          985, 5299,11672,15333,18104,20968,23798,25722,
-        27979,30311,31122,32800,32918,34221,33294,35616
-      },
-      /*Cr  qi=48  OC_MDOE_INTER_MV_LAST*/
-      {
-         1984, 5132,11475,16856,19802,22229,24024,24370,
-        23619,21436,20360,19365,19242,19227,20418,18369
-      },
-      /*Cr  qi=48  OC_MODE_INTER_MV_LAST2*/
-      {
-         1815, 5356,10766,16075,19527,22055,23832,23954,
-        26195,21376,20645,22591,32992,34279,26112,32256
-      },
-      /*Cr  qi=48  OC_MODE_INTER_MV_FOUR*/
-      {
-         1209, 4891,11379,16057,19358,21842,24087,25855,
-        27800,30102,30844,31684,32802,34478,35500,38822
-      },
-      /*Cr  qi=48  OC_MODE_GOLDEN_NOMV*/
-      {
-         1494, 4538, 8583,11745,13335,14731,15962,16339,
-        16273,16525,16967,16829,17490,17967,18397,18917
-      },
-      /*Cr  qi=48  OC_MODE_GOLDEN_MV*/
-      {
-         1341, 5361,11196,15273,16980,18660,19505,19003,
-        18926,18336,18016,18279,18758,18884,18784,19326
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=49  OC_MODE_INTRA*/
-      {
-         4881, 9394,13621,15953,18353,20399,22238,23725,
-        25530,27238,28555,29425,30656,31944,33076,41598
-      },
-      /*Y'  qi=49  OC_MODE_INTER_NOMV*/
-      {
-         1664, 6952,13325,17678,20958,23581,25883,28060,
-        30119,31921,33617,35146,36518,38117,39204,48627
-      },
-      /*Y'  qi=49  OC_MODE_INTER_MV*/
-      {
-         1923, 7628,12984,17132,20182,22636,24866,26915,
-        28773,30440,31948,33327,34645,35791,36914,41014
-      },
-      /*Y'  qi=49  OC_MDOE_INTER_MV_LAST*/
-      {
-         2511, 8639,13263,17342,20282,22718,24986,27083,
-        28986,30842,32527,34097,35522,36932,38168,43403
-      },
-      /*Y'  qi=49  OC_MODE_INTER_MV_LAST2*/
-      {
-         1434, 8104,13303,17539,20702,23186,25336,27375,
-        29335,31133,32711,34205,35300,36727,37960,44375
-      },
-      /*Y'  qi=49  OC_MODE_INTER_MV_FOUR*/
-      {
-         1055, 6908,12893,17041,20258,22915,25237,27347,
-        29319,31148,32766,34239,35606,36908,38092,42769
-      },
-      /*Y'  qi=49  OC_MODE_GOLDEN_NOMV*/
-      {
-         1583, 6495,12878,16506,19072,21441,23880,26017,
-        28273,29554,30832,31860,32586,33531,34520,43815
-      },
-      /*Y'  qi=49  OC_MODE_GOLDEN_MV*/
-      {
-         1565, 7059,12938,17446,20615,23221,25664,27826,
-        29772,31583,33034,34369,35605,36532,37657,42771
-      }
-    },
-    {
-      /*Cb  qi=49  OC_MODE_INTRA*/
-      {
-         5288,13256,17482,20726,23691,25434,26862,28770,
-        31165,33422,35384,37687,39069,40504,41614,47887
-      },
-      /*Cb  qi=49  OC_MODE_INTER_NOMV*/
-      {
-         2733, 7647,15794,19550,23432,26831,44687,36584,
-        37631,35409,37609,36976,37783,47403,42347,56087
-      },
-      /*Cb  qi=49  OC_MODE_INTER_MV*/
-      {
-         1903, 9931,16816,20661,24585,29349,33030,35485,
-        37467,39441,42259,42727,43914,47935,51269,55437
-      },
-      /*Cb  qi=49  OC_MDOE_INTER_MV_LAST*/
-      {
-         3960,10390,17063,20366,25144,29640,32413,34090,
-        35423,35640,35281,35957,34448,35047,34009,34820
-      },
-      /*Cb  qi=49  OC_MODE_INTER_MV_LAST2*/
-      {
-         3644,10901,17155,20309,24111,28343,31979,35084,
-        37792,40149,38167,39346,41952,47019,44453,53363
-      },
-      /*Cb  qi=49  OC_MODE_INTER_MV_FOUR*/
-      {
-         2215, 8203,16322,20222,24637,29031,32599,35511,
-        38536,40779,42099,43932,45720,44593,51653,52058
-      },
-      /*Cb  qi=49  OC_MODE_GOLDEN_NOMV*/
-      {
-         2819, 7583,12604,14786,18747,22260,23819,24763,
-        26634,28156,29624,29914,29406,29984,30079,34169
-      },
-      /*Cb  qi=49  OC_MODE_GOLDEN_MV*/
-      {
-         2599, 8990,16991,20415,23924,26969,27980,28590,
-        28739,29289,29443,29912,30383,31185,30685,34921
-      }
-    },
-    {
-      /*Cr  qi=49  OC_MODE_INTRA*/
-      {
-         2413, 8408,12397,15238,17709,19713,21800,23931,
-        25890,26850,27775,29671,31112,31721,33416,38152
-      },
-      /*Cr  qi=49  OC_MODE_INTER_NOMV*/
-      {
-         1299, 4222,10695,15007,17734,20428,34720,22770,
-        22189,12874, 9584,13159,17965,14891,11490, 8920
-      },
-      /*Cr  qi=49  OC_MODE_INTER_MV*/
-      {
-          983, 5306,11678,15341,18038,20981,23653,25531,
-        28434,30209,32888,33479,32522,35173,33019,36252
-      },
-      /*Cr  qi=49  OC_MDOE_INTER_MV_LAST*/
-      {
-         1986, 5134,11491,16851,19804,22270,24032,24366,
-        23608,21302,20330,19614,18926,19106,20048,18341
-      },
-      /*Cr  qi=49  OC_MODE_INTER_MV_LAST2*/
-      {
-         1819, 5355,10735,16143,19463,22134,24253,24031,
-        25946,21850,20617,23022,33344,30144,25984,32256
-      },
-      /*Cr  qi=49  OC_MODE_INTER_MV_FOUR*/
-      {
-         1209, 4891,11382,16046,19387,21863,24051,25942,
-        27814,29879,31268,31786,33486,34532,34788,38546
-      },
-      /*Cr  qi=49  OC_MODE_GOLDEN_NOMV*/
-      {
-         1494, 4537, 8586,11738,13265,14710,15869,16211,
-        16291,16433,16939,16921,17536,17974,18516,19126
-      },
-      /*Cr  qi=49  OC_MODE_GOLDEN_MV*/
-      {
-         1343, 5362,11194,15285,17012,18702,19490,18977,
-        18917,18377,17984,18180,18763,18949,18767,19495
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=50  OC_MODE_INTRA*/
-      {
-         5361,10126,14415,16733,19177,21252,23133,24652,
-        26492,28207,29568,30476,31754,33088,34269,43215
-      },
-      /*Y'  qi=50  OC_MODE_INTER_NOMV*/
-      {
-         1830, 7669,14137,18486,21857,24539,26945,29192,
-        31319,33139,34792,36547,37950,39746,40984,49289
-      },
-      /*Y'  qi=50  OC_MODE_INTER_MV*/
-      {
-         2588, 8854,14019,18093,21365,23911,26080,28129,
-        30117,32045,33856,35359,36859,38147,39388,45274
-      },
-      /*Y'  qi=50  OC_MDOE_INTER_MV_LAST*/
-      {
-         2354, 9213,14138,18207,21174,23629,25948,28111,
-        30084,31987,33765,35395,36929,38356,39672,45171
-      },
-      /*Y'  qi=50  OC_MODE_INTER_MV_LAST2*/
-      {
-         1781, 9086,14067,18281,21464,23997,26227,28292,
-        30210,31916,33487,34864,36238,37282,38348,43573
-      },
-      /*Y'  qi=50  OC_MODE_INTER_MV_FOUR*/
-      {
-         1148, 7446,13731,17944,21224,23925,26295,28463,
-        30450,32273,33949,35454,36935,38280,39519,43944
-      },
-      /*Y'  qi=50  OC_MODE_GOLDEN_NOMV*/
-      {
-         1680, 7032,13567,17265,19843,22271,24900,27135,
-        29197,30719,32131,32949,33760,34819,35798,45647
-      },
-      /*Y'  qi=50  OC_MODE_GOLDEN_MV*/
-      {
-         1684, 7654,13760,18383,21586,24276,26771,29027,
-        31094,32836,34481,35825,37178,38090,39337,44599
-      }
-    },
-    {
-      /*Cb  qi=50  OC_MODE_INTRA*/
-      {
-         6275,14635,19082,22443,25609,27411,28891,30882,
-        33423,35766,37844,40263,41724,43266,44505,50809
-      },
-      /*Cb  qi=50  OC_MODE_INTER_NOMV*/
-      {
-         3502, 9124,17309,21126,25603,28700,51217,35675,
-        37791,39051,42442,43576,44020,49689,47979,46874
-      },
-      /*Cb  qi=50  OC_MODE_INTER_MV*/
-      {
-         5092,11943,18624,22043,26497,31495,35220,37695,
-        39478,45589,44037,45666,50413,51230,53471,52168
-      },
-      /*Cb  qi=50  OC_MDOE_INTER_MV_LAST*/
-      {
-         4512,11765,18693,22310,27439,32367,35301,37144,
-        38407,38635,38639,38223,37687,37423,36570,37475
-      },
-      /*Cb  qi=50  OC_MODE_INTER_MV_LAST2*/
-      {
-         4664,12154,18649,22073,26062,30622,34443,38591,
-        39906,41062,40690,43313,44522,54357,45872,55895
-      },
-      /*Cb  qi=50  OC_MODE_INTER_MV_FOUR*/
-      {
-         2794, 9527,18000,22218,26936,31815,35675,38821,
-        41868,43774,46081,46738,50080,52904,55980,56297
-      },
-      /*Cb  qi=50  OC_MODE_GOLDEN_NOMV*/
-      {
-         3487, 8883,13741,16033,20425,24003,25929,27256,
-        28972,30839,32135,32360,32126,32681,32536,36978
-      },
-      /*Cb  qi=50  OC_MODE_GOLDEN_MV*/
-      {
-         3290,10312,18697,22346,26157,29546,30344,30914,
-        31400,32074,31842,32387,32868,33523,33661,37513
-      }
-    },
-    {
-      /*Cr  qi=50  OC_MODE_INTRA*/
-      {
-         2796, 9244,13427,16332,18882,20971,23170,25317,
-        27400,28462,29454,31405,32992,33648,35347,40251
-      },
-      /*Cr  qi=50  OC_MODE_INTER_NOMV*/
-      {
-         1615, 5075,12012,16517,19867,22255,31296,23824,
-        25402,16120,12403,33621,29159,32249,31514,28448
-      },
-      /*Cr  qi=50  OC_MODE_INTER_MV*/
-      {
-         2221, 6192,12505,17561,21045,24040,26036,27808,
-        30539,30854,32352,34101,33029,34248,37564,33992
-      },
-      /*Cr  qi=50  OC_MDOE_INTER_MV_LAST*/
-      {
-         2364, 5897,12788,17999,21266,24020,25865,26100,
-        25537,23189,21625,20983,20747,20601,21546,19153
-      },
-      /*Cr  qi=50  OC_MODE_INTER_MV_LAST2*/
-      {
-         2329, 6199,12066,15423,19308,22974,25247,26117,
-        27830,25277,24568,23862,31606,32832,19173,31544
-      },
-      /*Cr  qi=50  OC_MODE_INTER_MV_FOUR*/
-      {
-         1446, 5686,12632,17328,20690,23398,25618,27783,
-        29987,31675,33484,34389,36527,37395,37820,30062
-      },
-      /*Cr  qi=50  OC_MODE_GOLDEN_NOMV*/
-      {
-         1806, 5306, 9443,12574,14453,15988,17155,17452,
-        17527,17914,18244,18407,18877,19416,19935,20595
-      },
-      /*Cr  qi=50  OC_MODE_GOLDEN_MV*/
-      {
-         1631, 6164,12385,16675,18321,20231,20798,20495,
-        20418,19738,19277,19499,19958,20434,19564,20920
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=51  OC_MODE_INTRA*/
-      {
-         5361,10126,14415,16733,19177,21252,23133,24652,
-        26492,28207,29568,30476,31754,33088,34269,43215
-      },
-      /*Y'  qi=51  OC_MODE_INTER_NOMV*/
-      {
-         1830, 7669,14137,18486,21857,24539,26945,29192,
-        31319,33139,34792,36547,37950,39746,40984,49289
-      },
-      /*Y'  qi=51  OC_MODE_INTER_MV*/
-      {
-         2588, 8854,14019,18093,21365,23911,26080,28129,
-        30117,32045,33856,35359,36859,38147,39388,45274
-      },
-      /*Y'  qi=51  OC_MDOE_INTER_MV_LAST*/
-      {
-         2354, 9213,14138,18207,21174,23629,25948,28111,
-        30084,31987,33765,35395,36929,38356,39672,45171
-      },
-      /*Y'  qi=51  OC_MODE_INTER_MV_LAST2*/
-      {
-         1781, 9086,14067,18281,21464,23997,26227,28292,
-        30210,31916,33487,34864,36238,37282,38348,43573
-      },
-      /*Y'  qi=51  OC_MODE_INTER_MV_FOUR*/
-      {
-         1148, 7446,13731,17944,21224,23925,26295,28463,
-        30450,32273,33949,35454,36935,38280,39519,43944
-      },
-      /*Y'  qi=51  OC_MODE_GOLDEN_NOMV*/
-      {
-         1680, 7032,13567,17265,19843,22271,24900,27135,
-        29197,30719,32131,32949,33760,34819,35798,45647
-      },
-      /*Y'  qi=51  OC_MODE_GOLDEN_MV*/
-      {
-         1684, 7654,13760,18383,21586,24276,26771,29027,
-        31094,32836,34481,35825,37178,38090,39337,44599
-      }
-    },
-    {
-      /*Cb  qi=51  OC_MODE_INTRA*/
-      {
-         6275,14635,19082,22443,25609,27411,28891,30882,
-        33423,35766,37844,40263,41724,43266,44505,50809
-      },
-      /*Cb  qi=51  OC_MODE_INTER_NOMV*/
-      {
-         3502, 9124,17309,21126,25603,28700,51217,35675,
-        37791,39051,42442,43576,44020,49689,47979,46874
-      },
-      /*Cb  qi=51  OC_MODE_INTER_MV*/
-      {
-         5092,11943,18624,22043,26497,31495,35220,37695,
-        39478,45589,44037,45666,50413,51230,53471,52168
-      },
-      /*Cb  qi=51  OC_MDOE_INTER_MV_LAST*/
-      {
-         4512,11765,18693,22310,27439,32367,35301,37144,
-        38407,38635,38639,38223,37687,37423,36570,37475
-      },
-      /*Cb  qi=51  OC_MODE_INTER_MV_LAST2*/
-      {
-         4664,12154,18649,22073,26062,30622,34443,38591,
-        39906,41062,40690,43313,44522,54357,45872,55895
-      },
-      /*Cb  qi=51  OC_MODE_INTER_MV_FOUR*/
-      {
-         2794, 9527,18000,22218,26936,31815,35675,38821,
-        41868,43774,46081,46738,50080,52904,55980,56297
-      },
-      /*Cb  qi=51  OC_MODE_GOLDEN_NOMV*/
-      {
-         3487, 8883,13741,16033,20425,24003,25929,27256,
-        28972,30839,32135,32360,32126,32681,32536,36978
-      },
-      /*Cb  qi=51  OC_MODE_GOLDEN_MV*/
-      {
-         3290,10312,18697,22346,26157,29546,30344,30914,
-        31400,32074,31842,32387,32868,33523,33661,37513
-      }
-    },
-    {
-      /*Cr  qi=51  OC_MODE_INTRA*/
-      {
-         2796, 9244,13427,16332,18882,20971,23170,25317,
-        27400,28462,29454,31405,32992,33648,35347,40251
-      },
-      /*Cr  qi=51  OC_MODE_INTER_NOMV*/
-      {
-         1615, 5075,12012,16517,19867,22255,31296,23824,
-        25402,16120,12403,33621,29159,32249,31514,28448
-      },
-      /*Cr  qi=51  OC_MODE_INTER_MV*/
-      {
-         2221, 6192,12505,17561,21045,24040,26036,27808,
-        30539,30854,32352,34101,33029,34248,37564,33992
-      },
-      /*Cr  qi=51  OC_MDOE_INTER_MV_LAST*/
-      {
-         2364, 5897,12788,17999,21266,24020,25865,26100,
-        25537,23189,21625,20983,20747,20601,21546,19153
-      },
-      /*Cr  qi=51  OC_MODE_INTER_MV_LAST2*/
-      {
-         2329, 6199,12066,15423,19308,22974,25247,26117,
-        27830,25277,24568,23862,31606,32832,19173,31544
-      },
-      /*Cr  qi=51  OC_MODE_INTER_MV_FOUR*/
-      {
-         1446, 5686,12632,17328,20690,23398,25618,27783,
-        29987,31675,33484,34389,36527,37395,37820,30062
-      },
-      /*Cr  qi=51  OC_MODE_GOLDEN_NOMV*/
-      {
-         1806, 5306, 9443,12574,14453,15988,17155,17452,
-        17527,17914,18244,18407,18877,19416,19935,20595
-      },
-      /*Cr  qi=51  OC_MODE_GOLDEN_MV*/
-      {
-         1631, 6164,12385,16675,18321,20231,20798,20495,
-        20418,19738,19277,19499,19958,20434,19564,20920
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=52  OC_MODE_INTRA*/
-      {
-         6942,11991,16457,18879,21454,23664,25677,27337,
-        29250,31064,32508,33477,34840,36279,37573,47403
-      },
-      /*Y'  qi=52  OC_MODE_INTER_NOMV*/
-      {
-         2713, 9544,16191,20730,24399,27375,29921,32262,
-        34455,36337,38148,39941,41531,43352,44834,54542
-      },
-      /*Y'  qi=52  OC_MODE_INTER_MV*/
-      {
-         3061,10561,16064,20393,23669,26399,28758,30909,
-        32895,34700,36347,37845,39331,40676,41895,46387
-      },
-      /*Y'  qi=52  OC_MDOE_INTER_MV_LAST*/
-      {
-         3278,11234,16022,20347,23665,26432,28937,31226,
-        33286,35232,37083,38765,40481,42106,43510,49512
-      },
-      /*Y'  qi=52  OC_MODE_INTER_MV_LAST2*/
-      {
-         2586, 9404,16178,20793,24360,27064,29302,31472,
-        33529,35459,37086,38711,40332,41669,43198,50442
-      },
-      /*Y'  qi=52  OC_MODE_INTER_MV_FOUR*/
-      {
-         1971, 9159,15917,20316,23874,26807,29344,31625,
-        33772,35718,37550,39173,40825,42288,43606,48797
-      },
-      /*Y'  qi=52  OC_MODE_GOLDEN_NOMV*/
-      {
-         2728, 9078,15694,19512,22320,24977,27753,29999,
-        32323,34135,35512,36730,37973,39379,40963,51162
-      },
-      /*Y'  qi=52  OC_MODE_GOLDEN_MV*/
-      {
-         2811, 9650,15823,20601,24155,27078,29706,32086,
-        34196,36070,37745,39181,40696,41610,42919,48703
-      }
-    },
-    {
-      /*Cb  qi=52  OC_MODE_INTRA*/
-      {
-         7001,15640,20268,23732,27068,28932,30519,32606,
-        35300,37860,39882,42553,44256,45890,47586,54469
-      },
-      /*Cb  qi=52  OC_MODE_INTER_NOMV*/
-      {
-         3910,10326,18763,22755,27011,30647,38929,54016,
-        42381,42552,41727,44979,45195,47768,48092,54950
-      },
-      /*Cb  qi=52  OC_MODE_INTER_MV*/
-      {
-         2839,12332,19556,23811,28188,33842,38441,41529,
-        44077,47215,47995,50845,51287,56572,59388,61119
-      },
-      /*Cb  qi=52  OC_MDOE_INTER_MV_LAST*/
-      {
-         5697,11898,20027,23846,29489,34637,37962,39702,
-        41208,41526,41673,41743,40312,40658,39562,40304
-      },
-      /*Cb  qi=52  OC_MODE_INTER_MV_LAST2*/
-      {
-         4898,12851,20173,23885,28565,33455,37149,42363,
-        43435,46882,45839,50182,47159,57128,54509,56084
-      },
-      /*Cb  qi=52  OC_MODE_INTER_MV_FOUR*/
-      {
-         3253,10302,19227,23580,28576,33668,37929,41368,
-        44320,47160,48781,51051,52705,55093,58639,58079
-      },
-      /*Cb  qi=52  OC_MODE_GOLDEN_NOMV*/
-      {
-         4100, 9860,14696,16871,21243,25206,27593,29623,
-        31052,33781,35864,37355,36537,36954,36080,39582
-      },
-      /*Cb  qi=52  OC_MODE_GOLDEN_MV*/
-      {
-         3562,11291,19980,23810,27891,31821,32188,33053,
-        33608,34336,34483,35035,35639,36026,35956,40604
-      }
-    },
-    {
-      /*Cr  qi=52  OC_MODE_INTRA*/
-      {
-         3090,10208,14576,17637,20323,22521,24817,27029,
-        29238,30266,31426,33247,35152,35685,37319,42759
-      },
-      /*Cr  qi=52  OC_MODE_INTER_NOMV*/
-      {
-         1913, 6017,13114,17763,20962,23199,37623,28783,
-        25681,16197,27776,34368,31840,22199,17085,30112
-      },
-      /*Cr  qi=52  OC_MODE_INTER_MV*/
-      {
-         1640, 7068,13902,18090,20975,24542,27264,30163,
-        33166,34515,38615,36838,37795,40035,39768,39071
-      },
-      /*Cr  qi=52  OC_MDOE_INTER_MV_LAST*/
-      {
-         2635, 6712,14395,19858,23101,25867,27705,27713,
-        27415,24943,22739,22318,22147,22455,23541,19607
-      },
-      /*Cr  qi=52  OC_MODE_INTER_MV_LAST2*/
-      {
-         2431, 7250,13547,19061,23102,25840,27660,28193,
-        29441,24942,18720,30388,32843,40704,32960,26487
-      },
-      /*Cr  qi=52  OC_MODE_INTER_MV_FOUR*/
-      {
-         1728, 6590,13857,18883,22513,25372,27725,29862,
-        31584,35000,35402,36247,37820,40576,39450,34776
-      },
-      /*Cr  qi=52  OC_MODE_GOLDEN_NOMV*/
-      {
-         2241, 6300,10332,13768,15832,17725,20399,20062,
-        19519,19881,19100,19828,20381,20863,24843,24792
-      },
-      /*Cr  qi=52  OC_MODE_GOLDEN_MV*/
-      {
-         1949, 7029,13637,17827,19809,21670,22736,22379,
-        22373,21740,21140,21895,22367,22341,22664,23133
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=53  OC_MODE_INTRA*/
-      {
-         6942,11991,16457,18879,21454,23664,25677,27337,
-        29250,31064,32508,33477,34840,36279,37573,47403
-      },
-      /*Y'  qi=53  OC_MODE_INTER_NOMV*/
-      {
-         2713, 9544,16191,20730,24399,27375,29921,32262,
-        34455,36337,38148,39941,41531,43352,44834,54542
-      },
-      /*Y'  qi=53  OC_MODE_INTER_MV*/
-      {
-         3061,10561,16064,20393,23669,26399,28758,30909,
-        32895,34700,36347,37845,39331,40676,41895,46387
-      },
-      /*Y'  qi=53  OC_MDOE_INTER_MV_LAST*/
-      {
-         3278,11234,16022,20347,23665,26432,28937,31226,
-        33286,35232,37083,38765,40481,42106,43510,49512
-      },
-      /*Y'  qi=53  OC_MODE_INTER_MV_LAST2*/
-      {
-         2586, 9404,16178,20793,24360,27064,29302,31472,
-        33529,35459,37086,38711,40332,41669,43198,50442
-      },
-      /*Y'  qi=53  OC_MODE_INTER_MV_FOUR*/
-      {
-         1971, 9159,15917,20316,23874,26807,29344,31625,
-        33772,35718,37550,39173,40825,42288,43606,48797
-      },
-      /*Y'  qi=53  OC_MODE_GOLDEN_NOMV*/
-      {
-         2728, 9078,15694,19512,22320,24977,27753,29999,
-        32323,34135,35512,36730,37973,39379,40963,51162
-      },
-      /*Y'  qi=53  OC_MODE_GOLDEN_MV*/
-      {
-         2811, 9650,15823,20601,24155,27078,29706,32086,
-        34196,36070,37745,39181,40696,41610,42919,48703
-      }
-    },
-    {
-      /*Cb  qi=53  OC_MODE_INTRA*/
-      {
-         7001,15640,20268,23732,27068,28932,30519,32606,
-        35300,37860,39882,42553,44256,45890,47586,54469
-      },
-      /*Cb  qi=53  OC_MODE_INTER_NOMV*/
-      {
-         3910,10326,18763,22755,27011,30647,38929,54016,
-        42381,42552,41727,44979,45195,47768,48092,54950
-      },
-      /*Cb  qi=53  OC_MODE_INTER_MV*/
-      {
-         2839,12332,19556,23811,28188,33842,38441,41529,
-        44077,47215,47995,50845,51287,56572,59388,61119
-      },
-      /*Cb  qi=53  OC_MDOE_INTER_MV_LAST*/
-      {
-         5697,11898,20027,23846,29489,34637,37962,39702,
-        41208,41526,41673,41743,40312,40658,39562,40304
-      },
-      /*Cb  qi=53  OC_MODE_INTER_MV_LAST2*/
-      {
-         4898,12851,20173,23885,28565,33455,37149,42363,
-        43435,46882,45839,50182,47159,57128,54509,56084
-      },
-      /*Cb  qi=53  OC_MODE_INTER_MV_FOUR*/
-      {
-         3253,10302,19227,23580,28576,33668,37929,41368,
-        44320,47160,48781,51051,52705,55093,58639,58079
-      },
-      /*Cb  qi=53  OC_MODE_GOLDEN_NOMV*/
-      {
-         4100, 9860,14696,16871,21243,25206,27593,29623,
-        31052,33781,35864,37355,36537,36954,36080,39582
-      },
-      /*Cb  qi=53  OC_MODE_GOLDEN_MV*/
-      {
-         3562,11291,19980,23810,27891,31821,32188,33053,
-        33608,34336,34483,35035,35639,36026,35956,40604
-      }
-    },
-    {
-      /*Cr  qi=53  OC_MODE_INTRA*/
-      {
-         3090,10208,14576,17637,20323,22521,24817,27029,
-        29238,30266,31426,33247,35152,35685,37319,42759
-      },
-      /*Cr  qi=53  OC_MODE_INTER_NOMV*/
-      {
-         1913, 6017,13114,17763,20962,23199,37623,28783,
-        25681,16197,27776,34368,31840,22199,17085,30112
-      },
-      /*Cr  qi=53  OC_MODE_INTER_MV*/
-      {
-         1640, 7068,13902,18090,20975,24542,27264,30163,
-        33166,34515,38615,36838,37795,40035,39768,39071
-      },
-      /*Cr  qi=53  OC_MDOE_INTER_MV_LAST*/
-      {
-         2635, 6712,14395,19858,23101,25867,27705,27713,
-        27415,24943,22739,22318,22147,22455,23541,19607
-      },
-      /*Cr  qi=53  OC_MODE_INTER_MV_LAST2*/
-      {
-         2431, 7250,13547,19061,23102,25840,27660,28193,
-        29441,24942,18720,30388,32843,40704,32960,26487
-      },
-      /*Cr  qi=53  OC_MODE_INTER_MV_FOUR*/
-      {
-         1728, 6590,13857,18883,22513,25372,27725,29862,
-        31584,35000,35402,36247,37820,40576,39450,34776
-      },
-      /*Cr  qi=53  OC_MODE_GOLDEN_NOMV*/
-      {
-         2241, 6300,10332,13768,15832,17725,20399,20062,
-        19519,19881,19100,19828,20381,20863,24843,24792
-      },
-      /*Cr  qi=53  OC_MODE_GOLDEN_MV*/
-      {
-         1949, 7029,13637,17827,19809,21670,22736,22379,
-        22373,21740,21140,21895,22367,22341,22664,23133
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=54  OC_MODE_INTRA*/
-      {
-         6939,11990,16457,18878,21450,23659,25678,27336,
-        29251,31065,32507,33479,34845,36274,37577,47400
-      },
-      /*Y'  qi=54  OC_MODE_INTER_NOMV*/
-      {
-         2714, 9542,16185,20720,24387,27359,29909,32274,
-        34436,36342,38197,39982,41647,43476,44928,54250
-      },
-      /*Y'  qi=54  OC_MODE_INTER_MV*/
-      {
-         3074,10564,16064,20386,23675,26400,28754,30908,
-        32893,34703,36346,37850,39332,40684,41898,46358
-      },
-      /*Y'  qi=54  OC_MDOE_INTER_MV_LAST*/
-      {
-         3269,11234,16023,20348,23666,26432,28939,31218,
-        33282,35230,37084,38756,40494,42097,43535,49507
-      },
-      /*Y'  qi=54  OC_MODE_INTER_MV_LAST2*/
-      {
-         2575, 9412,16189,20801,24356,27057,29317,31482,
-        33498,35456,37086,38697,40176,41632,43225,50519
-      },
-      /*Y'  qi=54  OC_MODE_INTER_MV_FOUR*/
-      {
-         1971, 9160,15916,20315,23876,26807,29343,31631,
-        33772,35714,37551,39181,40814,42286,43618,48781
-      },
-      /*Y'  qi=54  OC_MODE_GOLDEN_NOMV*/
-      {
-         2725, 9089,15716,19548,22368,24993,27748,30002,
-        32304,34062,35559,36764,37966,39313,40934,51150
-      },
-      /*Y'  qi=54  OC_MODE_GOLDEN_MV*/
-      {
-         2813, 9646,15829,20606,24154,27079,29708,32082,
-        34194,36087,37751,39172,40708,41616,42938,48690
-      }
-    },
-    {
-      /*Cb  qi=54  OC_MODE_INTRA*/
-      {
-         7000,15639,20267,23731,27079,28935,30496,32612,
-        35348,37832,39874,42628,44225,45853,47624,54619
-      },
-      /*Cb  qi=54  OC_MODE_INTER_NOMV*/
-      {
-         3915,10331,18770,22716,26688,31032,39280,54016,
-        43067,44141,44586,46656,48242,48233,48662,52872
-      },
-      /*Cb  qi=54  OC_MODE_INTER_MV*/
-      {
-         2835,12328,19552,23794,28180,33859,38359,41700,
-        43980,47825,47205,51052,53495,54940,58546,62077
-      },
-      /*Cb  qi=54  OC_MDOE_INTER_MV_LAST*/
-      {
-         5693,11900,20026,23847,29503,34609,37953,39765,
-        41155,41539,41989,41578,40179,40732,39851,40295
-      },
-      /*Cb  qi=54  OC_MODE_INTER_MV_LAST2*/
-      {
-         4903,12896,20178,23879,28654,33442,36822,41682,
-        44267,45093,45580,48273,48344,51596,56965,53573
-      },
-      /*Cb  qi=54  OC_MODE_INTER_MV_FOUR*/
-      {
-         3251,10299,19221,23581,28570,33719,37991,41428,
-        44370,47240,48805,50934,51936,54540,59269,58003
-      },
-      /*Cb  qi=54  OC_MODE_GOLDEN_NOMV*/
-      {
-         4106, 9870,14715,16873,21676,25221,27562,29680,
-        31095,33664,35938,37511,36796,36684,36510,39624
-      },
-      /*Cb  qi=54  OC_MODE_GOLDEN_MV*/
-      {
-         3568,11287,19977,23806,27891,31789,32200,33087,
-        33661,34285,34478,34806,35537,36018,35758,40676
-      }
-    },
-    {
-      /*Cr  qi=54  OC_MODE_INTRA*/
-      {
-         3089,10206,14573,17636,20324,22528,24827,27012,
-        29227,30299,31497,33252,35183,35703,37458,42839
-      },
-      /*Cr  qi=54  OC_MODE_INTER_NOMV*/
-      {
-         1915, 6014,13097,17803,21132,22981,37623,29168,
-        26427,17279,27776,35296,32160,20701,16395,30112
-      },
-      /*Cr  qi=54  OC_MODE_INTER_MV*/
-      {
-         1643, 7071,13899,18069,21037,24370,27377,29606,
-        33654,34600,38237,37134,36995,40729,39803,39966
-      },
-      /*Cr  qi=54  OC_MDOE_INTER_MV_LAST*/
-      {
-         2635, 6711,14398,19825,23117,25902,27668,27671,
-        27408,25053,22765,22355,21909,22539,24022,19497
-      },
-      /*Cr  qi=54  OC_MODE_INTER_MV_LAST2*/
-      {
-         2433, 7248,13472,19130,23128,25802,27590,28323,
-        29628,25838,18991,30792,32605,40704,32720,25655
-      },
-      /*Cr  qi=54  OC_MODE_INTER_MV_FOUR*/
-      {
-         1728, 6588,13854,18893,22505,25340,27735,29968,
-        31700,34893,35627,36436,38711,40614,37385,34772
-      },
-      /*Cr  qi=54  OC_MODE_GOLDEN_NOMV*/
-      {
-         2243, 6319,10398,13773,15874,17831,20498,20199,
-        19730,20041,19071,19875,20495,21167,24878,24920
-      },
-      /*Cr  qi=54  OC_MODE_GOLDEN_MV*/
-      {
-         1950, 7028,13617,17823,19815,21669,22761,22381,
-        22366,21860,21100,21856,22408,22441,22429,23113
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=55  OC_MODE_INTRA*/
-      {
-         7585,12859,17340,19754,22352,24594,26651,28354,
-        30320,32169,33644,34653,36101,37580,38931,49238
-      },
-      /*Y'  qi=55  OC_MODE_INTER_NOMV*/
-      {
-         3105,10351,16966,21522,25295,28435,31088,33482,
-        35618,37695,39549,41565,43324,45349,46520,56481
-      },
-      /*Y'  qi=55  OC_MODE_INTER_MV*/
-      {
-         3284,11146,16951,21383,24779,27567,29980,32168,
-        34211,36078,37807,39385,40925,42302,43603,48003
-      },
-      /*Y'  qi=55  OC_MDOE_INTER_MV_LAST*/
-      {
-         3538,12132,16985,21382,24751,27551,30132,32514,
-        34675,36760,38747,40499,42257,44002,45477,51573
-      },
-      /*Y'  qi=55  OC_MODE_INTER_MV_LAST2*/
-      {
-         2702,11774,17584,22060,25538,28260,30554,32757,
-        34893,36812,38666,40431,42064,43617,45302,52231
-      },
-      /*Y'  qi=55  OC_MODE_INTER_MV_FOUR*/
-      {
-         2188, 9916,16802,21261,24912,27930,30562,32936,
-        35166,37222,39180,40866,42607,44166,45563,50923
-      },
-      /*Y'  qi=55  OC_MODE_GOLDEN_NOMV*/
-      {
-         2933, 9597,16328,20313,23215,25961,28848,31210,
-        33585,35498,36962,38124,39194,40411,41845,53158
-      },
-      /*Y'  qi=55  OC_MODE_GOLDEN_MV*/
-      {
-         3063,10372,16822,21658,25252,28244,30988,33452,
-        35634,37588,39373,40874,42472,43583,44796,50811
-      }
-    },
-    {
-      /*Cb  qi=55  OC_MODE_INTRA*/
-      {
-         7416,16297,21039,24504,27870,29777,31345,33558,
-        36278,38899,41080,43724,45586,47217,49085,56651
-      },
-      /*Cb  qi=55  OC_MODE_INTER_NOMV*/
-      {
-         4217,11174,19493,23702,28146,32313,38831,38804,
-        42737,42272,44050,50053,49242,52475,48444,55586
-      },
-      /*Cb  qi=55  OC_MODE_INTER_MV*/
-      {
-         3126,13212,20271,24583,28998,35094,39781,43271,
-        45360,49496,50351,52691,53234,59560,61704,61128
-      },
-      /*Cb  qi=55  OC_MDOE_INTER_MV_LAST*/
-      {
-         6190,12780,20942,24785,30629,35826,39366,41367,
-        42680,43065,43422,42682,41616,41920,41311,41791
-      },
-      /*Cb  qi=55  OC_MODE_INTER_MV_LAST2*/
-      {
-         5413,14398,21074,24820,29903,35286,39037,43983,
-        45659,46868,44402,47100,47702,54990,56656,56413
-      },
-      /*Cb  qi=55  OC_MODE_INTER_MV_FOUR*/
-      {
-         3496,10924,20086,24578,29799,35015,39448,42932,
-        46074,48597,50950,50467,55799,54860,62281,61182
-      },
-      /*Cb  qi=55  OC_MODE_GOLDEN_NOMV*/
-      {
-         4228,10369,15068,17132,21717,25401,28176,30286,
-        32341,34567,37443,38820,37404,37780,36951,41108
-      },
-      /*Cb  qi=55  OC_MODE_GOLDEN_MV*/
-      {
-         3682,11981,20881,24812,29116,32852,33284,34239,
-        34720,34839,36051,35597,36435,37083,37247,41844
-      }
-    },
-    {
-      /*Cr  qi=55  OC_MODE_INTRA*/
-      {
-         3575,11455,16124,19346,22204,24571,27013,29342,
-        31740,32916,34184,36135,37848,38617,40319,46117
-      },
-      /*Cr  qi=55  OC_MODE_INTER_NOMV*/
-      {
-         2422, 7403,15067,20396,23597,28400,27352,29243,
-        31348,19303,15051,35360,36689,30081,36568,28259
-      },
-      /*Cr  qi=55  OC_MODE_INTER_MV*/
-      {
-         2053, 8481,15452,19927,23193,26884,29707,33217,
-        37089,38607,42357,40236,41840,43810,43112,43514
-      },
-      /*Cr  qi=55  OC_MDOE_INTER_MV_LAST*/
-      {
-         3370, 7873,16195,22017,25435,28319,30041,30460,
-        29632,27090,25774,24567,24113,24757,23945,21423
-      },
-      /*Cr  qi=55  OC_MODE_INTER_MV_LAST2*/
-      {
-         3306, 8435,15231,21116,25011,28261,30169,30911,
-        32197,28294,28318,25999,32496,40277,37973,30352
-      },
-      /*Cr  qi=55  OC_MODE_INTER_MV_FOUR*/
-      {
-         2167, 7840,15704,21039,24888,27850,30421,32616,
-        34906,37697,38563,39848,42179,43795,43041,33918
-      },
-      /*Cr  qi=55  OC_MODE_GOLDEN_NOMV*/
-      {
-         2680, 7436,11333,15200,17644,19595,22134,22281,
-        21595,21810,21651,22292,23404,23402,25650,27281
-      },
-      /*Cr  qi=55  OC_MODE_GOLDEN_MV*/
-      {
-         2398, 8253,15611,20188,22074,24116,25295,24498,
-        24616,24259,23507,24188,24720,24464,25070,25328
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=56  OC_MODE_INTRA*/
-      {
-         7585,12871,17341,19762,22365,24609,26666,28356,
-        30322,32178,33644,34656,36112,37592,38942,49248
-      },
-      /*Y'  qi=56  OC_MODE_INTER_NOMV*/
-      {
-         3121,10358,16966,21526,25334,28436,31069,33529,
-        35690,37771,39683,41528,43362,45109,47107,57055
-      },
-      /*Y'  qi=56  OC_MODE_INTER_MV*/
-      {
-         3268,11129,16954,21392,24792,27588,30009,32182,
-        34219,36117,37871,39476,41006,42465,43735,48208
-      },
-      /*Y'  qi=56  OC_MDOE_INTER_MV_LAST*/
-      {
-         3564,12171,16992,21380,24753,27554,30144,32560,
-        34769,36829,38755,40542,42318,44082,45553,51566
-      },
-      /*Y'  qi=56  OC_MODE_INTER_MV_LAST2*/
-      {
-         2690,11759,17505,21957,25491,28249,30577,32787,
-        34853,36837,38708,40500,42108,43688,45325,52288
-      },
-      /*Y'  qi=56  OC_MODE_INTER_MV_FOUR*/
-      {
-         2192, 9938,16778,21252,24908,27924,30555,32946,
-        35186,37237,39188,40898,42617,44168,45536,50910
-      },
-      /*Y'  qi=56  OC_MODE_GOLDEN_NOMV*/
-      {
-         2926, 9654,16330,20260,23144,25931,28960,31157,
-        33637,35476,37077,38276,39201,40397,42148,53164
-      },
-      /*Y'  qi=56  OC_MODE_GOLDEN_MV*/
-      {
-         3072,10306,16797,21655,25247,28252,31000,33464,
-        35623,37587,39371,40874,42470,43532,44777,50830
-      }
-    },
-    {
-      /*Cb  qi=56  OC_MODE_INTRA*/
-      {
-         7384,16297,21041,24492,27858,29762,31381,33577,
-        36301,38884,41052,43782,45687,47311,49165,56729
-      },
-      /*Cb  qi=56  OC_MODE_INTER_NOMV*/
-      {
-         4223,11150,19540,23732,27696,31896,40399,54400,
-        50339,42353,42818,46207,43150,50352,50234,62960
-      },
-      /*Cb  qi=56  OC_MODE_INTER_MV*/
-      {
-         3021,13192,20359,24749,29312,35323,40121,43538,
-        45848,48121,51429,53594,53762,57173,63242,64059
-      },
-      /*Cb  qi=56  OC_MDOE_INTER_MV_LAST*/
-      {
-         6264,12799,20919,24744,30556,35734,39322,41250,
-        42683,42894,43396,42804,41778,42385,41013,41546
-      },
-      /*Cb  qi=56  OC_MODE_INTER_MV_LAST2*/
-      {
-         5338,14356,21063,24855,30098,34982,38422,45065,
-        45664,49718,47681,51025,51086,58656,56594,62306
-      },
-      /*Cb  qi=56  OC_MODE_INTER_MV_FOUR*/
-      {
-         3498,10926,20081,24560,29744,35008,39490,43082,
-        46331,48458,50790,53181,55030,55308,63275,65277
-      },
-      /*Cb  qi=56  OC_MODE_GOLDEN_NOMV*/
-      {
-         4232,10278,14962,17178,21532,25310,28372,30519,
-        32394,34840,37637,39115,38061,38234,37777,41266
-      },
-      /*Cb  qi=56  OC_MODE_GOLDEN_MV*/
-      {
-         3698,11978,20885,24812,29131,32844,33268,34137,
-        34757,34844,35813,35865,36478,36963,37343,42009
-      }
-    },
-    {
-      /*Cr  qi=56  OC_MODE_INTRA*/
-      {
-         3595,11453,16130,19349,22206,24589,27043,29340,
-        31752,32985,34194,36177,37945,38793,40537,46143
-      },
-      /*Cr  qi=56  OC_MODE_INTER_NOMV*/
-      {
-         2424, 7381,15014,20073,23315,26847,41872,27792,
-        28959,18367,14623,19797,25436,22354,17966,12709
-      },
-      /*Cr  qi=56  OC_MODE_INTER_MV*/
-      {
-         2018, 8424,15590,20045,23493,27155,29904,33587,
-        36718,38442,41587,40860,42112,44183,42955,45661
-      },
-      /*Cr  qi=56  OC_MDOE_INTER_MV_LAST*/
-      {
-         3394, 7865,16102,21999,25449,28282,30023,30411,
-        29506,27349,25705,25074,24243,25718,26203,23613
-      },
-      /*Cr  qi=56  OC_MODE_INTER_MV_LAST2*/
-      {
-         3295, 8490,15246,21248,25320,28358,30311,32545,
-        32226,28425,27738,32309,38061,34880,35728,42547
-      },
-      /*Cr  qi=56  OC_MODE_INTER_MV_FOUR*/
-      {
-         2167, 7849,15688,21025,24893,27870,30426,32651,
-        34917,37723,39130,39769,41273,44617,43303,47247
-      },
-      /*Cr  qi=56  OC_MODE_GOLDEN_NOMV*/
-      {
-         2685, 7397,11313,15310,17675,19678,22323,22299,
-        21613,22043,21820,22601,23258,23773,26846,27682
-      },
-      /*Cr  qi=56  OC_MODE_GOLDEN_MV*/
-      {
-         2402, 8253,15590,20113,22107,24125,25160,24464,
-        24541,24316,23503,24236,24757,24559,24980,25583
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=57  OC_MODE_INTRA*/
-      {
-         7586,12855,17352,19773,22374,24626,26680,28373,
-        30345,32210,33673,34677,36132,37624,38970,49274
-      },
-      /*Y'  qi=57  OC_MODE_INTER_NOMV*/
-      {
-         3121,10402,16880,21450,25354,28477,31076,33416,
-        35529,37699,39490,41251,43209,45324,46774,57834
-      },
-      /*Y'  qi=57  OC_MODE_INTER_MV*/
-      {
-         3294,11185,16991,21364,24762,27506,29955,32150,
-        34228,36092,37833,39415,40978,42342,43678,48175
-      },
-      /*Y'  qi=57  OC_MDOE_INTER_MV_LAST*/
-      {
-         3586,12162,16976,21367,24746,27557,30137,32542,
-        34691,36722,38715,40502,42320,43970,45524,51590
-      },
-      /*Y'  qi=57  OC_MODE_INTER_MV_LAST2*/
-      {
-         2656,11583,17454,21988,25511,28238,30524,32695,
-        34816,36787,38537,40314,41963,43523,45134,52245
-      },
-      /*Y'  qi=57  OC_MODE_INTER_MV_FOUR*/
-      {
-         2209, 9948,16743,21280,24932,27938,30562,32947,
-        35187,37230,39169,40885,42620,44167,45587,50900
-      },
-      /*Y'  qi=57  OC_MODE_GOLDEN_NOMV*/
-      {
-         2928, 9834,16255,20101,23088,26009,28802,31163,
-        33702,35361,37149,38340,39222,40450,41953,53207
-      },
-      /*Y'  qi=57  OC_MODE_GOLDEN_MV*/
-      {
-         3100,10292,16821,21663,25244,28233,30998,33463,
-        35621,37594,39368,40869,42456,43536,44778,50849
-      }
-    },
-    {
-      /*Cb  qi=57  OC_MODE_INTRA*/
-      {
-         7423,16292,21043,24501,27863,29784,31384,33604,
-        36261,38926,41043,43769,45708,47330,49174,56573
-      },
-      /*Cb  qi=57  OC_MODE_INTER_NOMV*/
-      {
-         4177,11235,19594,23757,27222,31517,39359,54656,
-        43467,50889,41737,42532,49158,52144,47945,56449
-      },
-      /*Cb  qi=57  OC_MODE_INTER_MV*/
-      {
-         2973,13176,20352,24693,29228,35174,39978,43546,
-        45192,48203,51132,52948,53287,58653,64472,65138
-      },
-      /*Cb  qi=57  OC_MDOE_INTER_MV_LAST*/
-      {
-         6237,12731,20914,24767,30636,35872,39337,41328,
-        42751,43011,43264,42554,41819,42063,42195,41683
-      },
-      /*Cb  qi=57  OC_MODE_INTER_MV_LAST2*/
-      {
-         5262,14258,21053,24859,30101,35355,39030,43759,
-        45385,50760,48525,48502,51213,56576,56753,63022
-      },
-      /*Cb  qi=57  OC_MODE_INTER_MV_FOUR*/
-      {
-         3501,10892,20085,24557,29730,35021,39449,43086,
-        45774,48760,50899,53835,54580,57073,64425,61761
-      },
-      /*Cb  qi=57  OC_MODE_GOLDEN_NOMV*/
-      {
-         4277,10237,14889,17099,21219,24892,27698,30154,
-        32181,34756,37616,38767,37628,38391,38034,40967
-      },
-      /*Cb  qi=57  OC_MODE_GOLDEN_MV*/
-      {
-         3691,11971,20888,24806,29092,32818,33207,34163,
-        34811,34959,36092,35901,36805,37152,37381,42040
-      }
-    },
-    {
-      /*Cr  qi=57  OC_MODE_INTRA*/
-      {
-         3581,11456,16128,19350,22200,24575,27000,29315,
-        31757,32960,34233,36195,38006,38690,40432,46117
-      },
-      /*Cr  qi=57  OC_MODE_INTER_NOMV*/
-      {
-         2390, 7475,15027,20114,23606,26567,47488,29806,
-        27168,16763,13333,20055,24279,18928,15239,11996
-      },
-      /*Cr  qi=57  OC_MODE_INTER_MV*/
-      {
-         2057, 8403,15491,19986,23442,27101,29997,33075,
-        36533,38268,40159,41724,41447,43596,42287,45303
-      },
-      /*Cr  qi=57  OC_MDOE_INTER_MV_LAST*/
-      {
-         3358, 7868,16179,22001,25462,28262,30015,30294,
-        29770,27661,25554,25621,24831,26117,25522,23901
-      },
-      /*Cr  qi=57  OC_MODE_INTER_MV_LAST2*/
-      {
-         3203, 8472,15289,21221,25366,28243,30157,32358,
-        32142,28049,27928,33351,35872,39738,37472,40934
-      },
-      /*Cr  qi=57  OC_MODE_INTER_MV_FOUR*/
-      {
-         2166, 7807,15692,21023,24874,27880,30443,32707,
-        35103,37921,38523,40494,41108,44124,42001,45736
-      },
-      /*Cr  qi=57  OC_MODE_GOLDEN_NOMV*/
-      {
-         2731, 7355,11248,14946,17637,19683,22173,22182,
-        21510,21880,21610,22377,22977,23626,25965,27288
-      },
-      /*Cr  qi=57  OC_MODE_GOLDEN_MV*/
-      {
-         2401, 8251,15608,20189,22068,24140,25231,24577,
-        24702,24374,23531,24371,24815,24890,24857,25540
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=58  OC_MODE_INTRA*/
-      {
-         9977,15841,20720,23042,25852,28204,30557,32457,
-        34628,36710,38352,39461,41099,42803,44300,55700
-      },
-      /*Y'  qi=58  OC_MODE_INTER_NOMV*/
-      {
-         4708,13186,20448,25800,29419,32290,34647,36938,
-        39477,41690,43829,46363,48217,50592,53434,63064
-      },
-      /*Y'  qi=58  OC_MODE_INTER_MV*/
-      {
-         4894,15280,20870,25222,28735,31424,33789,36195,
-        38579,40922,43217,45211,47184,48886,50606,57540
-      },
-      /*Y'  qi=58  OC_MDOE_INTER_MV_LAST*/
-      {
-         4848,15713,21053,25430,28691,31396,33894,36274,
-        38538,40745,42900,44859,46713,48264,49942,57074
-      },
-      /*Y'  qi=58  OC_MODE_INTER_MV_LAST2*/
-      {
-         4913,14273,20156,25100,28730,31533,34022,36471,
-        38780,41181,43404,45378,47248,48962,50814,58654
-      },
-      /*Y'  qi=58  OC_MODE_INTER_MV_FOUR*/
-      {
-         3622,12798,19914,24876,28723,31824,34542,37063,
-        39435,41710,43831,45778,47696,49470,51079,56822
-      },
-      /*Y'  qi=58  OC_MODE_GOLDEN_NOMV*/
-      {
-         4462,12361,19266,23612,27041,30258,33292,35731,
-        38178,39897,41795,43235,44181,45479,47075,59417
-      },
-      /*Y'  qi=58  OC_MODE_GOLDEN_MV*/
-      {
-         4734,12917,20352,25419,29036,31970,34747,37263,
-        39721,41967,43987,45821,47597,48948,50446,56684
-      }
-    },
-    {
-      /*Cb  qi=58  OC_MODE_INTRA*/
-      {
-         7382,16784,21595,24852,28243,30090,31591,33827,
-        36626,39224,41482,44298,46191,47634,49552,57567
-      },
-      /*Cb  qi=58  OC_MODE_INTER_NOMV*/
-      {
-         5258,12657,21444,25131,29236,34301,38339,37906,
-        47915,43269,46811,42285,47324,47125,58518,62304
-      },
-      /*Cb  qi=58  OC_MODE_INTER_MV*/
-      {
-         5495,14061,21342,25271,30612,35804,39867,43376,
-        43196,50963,51748,52862,55003,56510,64768,59848
-      },
-      /*Cb  qi=58  OC_MDOE_INTER_MV_LAST*/
-      {
-         2959,14209,21425,25415,30837,36301,39780,41995,
-        43185,43428,43764,43605,42625,42408,42350,42341
-      },
-      /*Cb  qi=58  OC_MODE_INTER_MV_LAST2*/
-      {
-         5645,13461,21411,25385,30369,35320,39253,44419,
-        46993,48328,45686,50755,48981,58627,50523,57217
-      },
-      /*Cb  qi=58  OC_MODE_INTER_MV_FOUR*/
-      {
-         3619,11280,20558,25194,30269,35629,40322,44038,
-        46971,49765,51025,52656,56950,55936,60694,60055
-      },
-      /*Cb  qi=58  OC_MODE_GOLDEN_NOMV*/
-      {
-         4337,10335,14813,17017,21075,24441,27550,30311,
-        32556,35667,37076,39095,37896,38037,38469,41921
-      },
-      /*Cb  qi=58  OC_MODE_GOLDEN_MV*/
-      {
-         3480,12298,21550,25498,29605,33271,34051,34843,
-        34776,35514,36624,36715,36887,37594,38124,42711
-      }
-    },
-    {
-      /*Cr  qi=58  OC_MODE_INTRA*/
-      {
-         4165,12467,17381,20765,23798,26284,28820,31413,
-        33880,35298,36489,38562,40133,40865,42859,48961
-      },
-      /*Cr  qi=58  OC_MODE_INTER_NOMV*/
-      {
-         3462, 8884,17548,22970,25569,31411,31220,33168,
-        30952,36032,14234,39694,34436,32896,39211,35212
-      },
-      /*Cr  qi=58  OC_MODE_INTER_MV*/
-      {
-         4127, 9528,17455,22786,26788,30685,33320,34808,
-        37309,39336,42532,40669,42004,40812,42220,41171
-      },
-      /*Cr  qi=58  OC_MDOE_INTER_MV_LAST*/
-      {
-         3324, 9372,17248,22657,26761,30077,31901,32302,
-        31793,29032,27803,26443,26064,27230,28172,24536
-      },
-      /*Cr  qi=58  OC_MODE_INTER_MV_LAST2*/
-      {
-         3495, 9698,17298,23143,26985,30248,32325,33497,
-        34459,26332,30242,26226,32413,36294,34474,30592
-      },
-      /*Cr  qi=58  OC_MODE_INTER_MV_FOUR*/
-      {
-         2623, 8879,17180,22756,26776,29873,32491,35108,
-        37423,40548,41935,41627,42581,40586,36359,27151
-      },
-      /*Cr  qi=58  OC_MODE_GOLDEN_NOMV*/
-      {
-         3196, 8291,11952,15640,18778,21048,23723,23803,
-        23872,24238,23392,24236,24499,25635,26774,28810
-      },
-      /*Cr  qi=58  OC_MODE_GOLDEN_MV*/
-      {
-         2693, 9483,17195,21918,23982,25880,27041,26600,
-        26539,26189,25242,26242,26972,26806,26422,27101
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=59  OC_MODE_INTRA*/
-      {
-         9985,15837,20723,23049,25866,28216,30588,32484,
-        34636,36716,38357,39473,41116,42811,44317,55694
-      },
-      /*Y'  qi=59  OC_MODE_INTER_NOMV*/
-      {
-         4760,13189,20360,25766,29387,32264,34563,36913,
-        39342,41838,44369,46832,49157,51466,52925,63586
-      },
-      /*Y'  qi=59  OC_MODE_INTER_MV*/
-      {
-         4870,15122,20915,25414,28852,31499,33926,36246,
-        38641,40986,43278,45329,47221,49064,50568,57919
-      },
-      /*Y'  qi=59  OC_MDOE_INTER_MV_LAST*/
-      {
-         4904,15769,21069,25435,28679,31375,33873,36267,
-        38546,40733,42868,44878,46663,48356,49938,56975
-      },
-      /*Y'  qi=59  OC_MODE_INTER_MV_LAST2*/
-      {
-         4951,14635,20578,25106,28631,31399,33869,36293,
-        38660,40918,43140,45154,47035,48824,50464,57905
-      },
-      /*Y'  qi=59  OC_MODE_INTER_MV_FOUR*/
-      {
-         3628,12842,19882,24858,28724,31836,34548,37071,
-        39463,41715,43883,45786,47741,49508,51075,56876
-      },
-      /*Y'  qi=59  OC_MODE_GOLDEN_NOMV*/
-      {
-         4475,12377,19169,23626,27127,30316,33371,35814,
-        38391,40046,41951,43367,44225,45622,47291,59594
-      },
-      /*Y'  qi=59  OC_MODE_GOLDEN_MV*/
-      {
-         4693,12913,20378,25404,29008,31964,34691,37233,
-        39686,41861,43995,45732,47576,48785,50318,56845
-      }
-    },
-    {
-      /*Cb  qi=59  OC_MODE_INTRA*/
-      {
-         7372,16773,21590,24851,28227,30074,31599,33816,
-        36598,39231,41472,44353,46161,47732,49501,57493
-      },
-      /*Cb  qi=59  OC_MODE_INTER_NOMV*/
-      {
-         5285,12649,21403,25113,28231,32964,38449,55552,
-        40714,44559,44432,44261,46268,61382,53840,51049
-      },
-      /*Cb  qi=59  OC_MODE_INTER_MV*/
-      {
-         6214,14101,21416,25129,30183,35110,39374,42010,
-        43449,49577,51859,51481,54555,54482,63349,58561
-      },
-      /*Cb  qi=59  OC_MDOE_INTER_MV_LAST*/
-      {
-         2823,14174,21423,25414,30830,36378,39773,41911,
-        43133,43754,43483,44253,42823,42260,42302,42528
-      },
-      /*Cb  qi=59  OC_MODE_INTER_MV_LAST2*/
-      {
-         4982,13884,21450,25550,30930,36777,40630,45982,
-        47414,47950,47692,49047,50714,56896,50295,62940
-      },
-      /*Cb  qi=59  OC_MODE_INTER_MV_FOUR*/
-      {
-         3620,11265,20531,25185,30270,35657,40215,43857,
-        46736,49790,51312,52904,56487,57927,65535,60459
-      },
-      /*Cb  qi=59  OC_MODE_GOLDEN_NOMV*/
-      {
-         4340,10437,14872,17001,20800,24414,28027,29983,
-        31894,35314,36802,38744,37641,37854,38115,41611
-      },
-      /*Cb  qi=59  OC_MODE_GOLDEN_MV*/
-      {
-         3685,12280,21529,25489,29625,33216,34128,34571,
-        35070,35505,36335,36675,37687,37797,38441,42841
-      }
-    },
-    {
-      /*Cr  qi=59  OC_MODE_INTRA*/
-      {
-         4161,12472,17378,20766,23802,26274,28811,31393,
-        33901,35286,36520,38509,40228,40873,42717,49068
-      },
-      /*Cr  qi=59  OC_MODE_INTER_NOMV*/
-      {
-         3490, 8947,17508,22319,26083,27291,52096,34546,
-        29664,33104,14177,38873,35328,34213,37863,35712
-      },
-      /*Cr  qi=59  OC_MODE_INTER_MV*/
-      {
-         4175, 9443,17203,22852,27037,30814,33252,34575,
-        37849,39027,42681,41848,41944,42120,35733,43603
-      },
-      /*Cr  qi=59  OC_MDOE_INTER_MV_LAST*/
-      {
-         3265, 9360,17245,22628,26777,30081,31880,32343,
-        31555,28979,27596,26933,26312,27081,28294,24931
-      },
-      /*Cr  qi=59  OC_MODE_INTER_MV_LAST2*/
-      {
-         3651, 9475,17388,23120,26883,30049,32269,33432,
-        34798,26300,29855,25327,35831,35846,33472,29216
-      },
-      /*Cr  qi=59  OC_MODE_INTER_MV_FOUR*/
-      {
-         2624, 8879,17183,22745,26765,29843,32481,35029,
-        36856,40486,41191,42268,40367,40227,33864,27617
-      },
-      /*Cr  qi=59  OC_MODE_GOLDEN_NOMV*/
-      {
-         3198, 8348,11831,15653,18693,20958,23656,23823,
-        23560,23963,23177,24460,24322,25948,26493,28168
-      },
-      /*Cr  qi=59  OC_MODE_GOLDEN_MV*/
-      {
-         2789, 9470,17106,21552,23982,26037,27088,26555,
-        26459,26370,25559,26401,26724,26827,26588,27047
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=60  OC_MODE_INTRA*/
-      {
-         9989,15795,20725,23040,25874,28230,30597,32510,
-        34649,36723,38362,39464,41116,42829,44309,55704
-      },
-      /*Y'  qi=60  OC_MODE_INTER_NOMV*/
-      {
-         4803,14017,20706,25852,29388,32199,34519,36666,
-        38879,41285,43645,46439,47627,50542,52023,65205
-      },
-      /*Y'  qi=60  OC_MODE_INTER_MV*/
-      {
-         4895,15459,20922,25347,28791,31460,33848,36179,
-        38483,40891,43140,45143,47109,48779,50585,57423
-      },
-      /*Y'  qi=60  OC_MDOE_INTER_MV_LAST*/
-      {
-         4777,15688,21071,25437,28676,31373,33883,36244,
-        38517,40709,42845,44795,46626,48314,49921,57076
-      },
-      /*Y'  qi=60  OC_MODE_INTER_MV_LAST2*/
-      {
-         4801,14129,19902,24898,28727,31721,34320,36793,
-        39218,41597,43832,45809,47670,49545,51306,58720
-      },
-      /*Y'  qi=60  OC_MODE_INTER_MV_FOUR*/
-      {
-         3632,12802,19870,24875,28731,31832,34543,37060,
-        39458,41699,43852,45789,47693,49493,51044,56866
-      },
-      /*Y'  qi=60  OC_MODE_GOLDEN_NOMV*/
-      {
-         4487,12402,19121,23622,27352,30307,33232,35604,
-        37952,39918,41718,43273,44100,45523,47105,59585
-      },
-      /*Y'  qi=60  OC_MODE_GOLDEN_MV*/
-      {
-         4702,12961,20428,25430,29021,31961,34681,37212,
-        39639,41833,43985,45739,47496,48756,50348,56609
-      }
-    },
-    {
-      /*Cb  qi=60  OC_MODE_INTRA*/
-      {
-         7465,16759,21595,24851,28229,30062,31566,33820,
-        36589,39236,41478,44300,46086,47793,49491,57505
-      },
-      /*Cb  qi=60  OC_MODE_INTER_NOMV*/
-      {
-         5662,13349,21455,25128,29002,35389,38071,39104,
-        42424,44037,44532,49867,47728,55221,60384,53546
-      },
-      /*Cb  qi=60  OC_MODE_INTER_MV*/
-      {
-         5830,14191,21372,25199,30247,35302,38538,42341,
-        45315,47771,51055,52060,53609,56354,60436,61795
-      },
-      /*Cb  qi=60  OC_MDOE_INTER_MV_LAST*/
-      {
-         2916,14139,21415,25405,30803,36262,39888,41756,
-        42655,43611,43373,43843,42542,42523,42389,42302
-      },
-      /*Cb  qi=60  OC_MODE_INTER_MV_LAST2*/
-      {
-         5484,11924,21179,25418,30580,35539,40376,45080,
-        46764,50926,47082,50634,51376,65535,59046,62132
-      },
-      /*Cb  qi=60  OC_MODE_INTER_MV_FOUR*/
-      {
-         3612,11249,20535,25190,30182,35655,40281,43722,
-        46394,50113,50920,52757,55478,56901,63591,60000
-      },
-      /*Cb  qi=60  OC_MODE_GOLDEN_NOMV*/
-      {
-         4363,10484,14910,17054,20776,24952,28021,30266,
-        32285,34798,37065,39207,37763,37864,37924,41679
-      },
-      /*Cb  qi=60  OC_MODE_GOLDEN_MV*/
-      {
-         3475,12359,21533,25495,29579,33236,33902,34378,
-        34900,35435,36299,36672,37446,37491,38209,42652
-      }
-    },
-    {
-      /*Cr  qi=60  OC_MODE_INTRA*/
-      {
-         4111,12466,17381,20757,23793,26257,28818,31390,
-        33906,35238,36438,38526,40218,40834,42918,48997
-      },
-      /*Cr  qi=60  OC_MODE_INTER_NOMV*/
-      {
-         3443, 8872,17662,23237,25625,31398,32068,33079,
-        28191,18193,12811,29696,22918,38089,37056,36352
-      },
-      /*Cr  qi=60  OC_MODE_INTER_MV*/
-      {
-         4228, 9493,17340,22629,26924,30470,31941,34882,
-        37498,39027,40754,41215,40290,40303,44942,40944
-      },
-      /*Cr  qi=60  OC_MDOE_INTER_MV_LAST*/
-      {
-         3294, 9337,17197,22570,26680,30022,31849,32159,
-        31477,29347,27996,26718,26604,27397,26411,24694
-      },
-      /*Cr  qi=60  OC_MODE_INTER_MV_LAST2*/
-      {
-         3339, 9305,17390,23307,27242,30424,32236,32735,
-        34811,29880,29567,25640,44768,37568,37200,30528
-      },
-      /*Cr  qi=60  OC_MODE_INTER_MV_FOUR*/
-      {
-         2615, 8873,17167,22697,26759,29826,32478,35146,
-        36988,40718,41498,40447,44015,39468,38076,27337
-      },
-      /*Cr  qi=60  OC_MODE_GOLDEN_NOMV*/
-      {
-         3211, 8380,11715,15760,18683,20890,23493,23653,
-        23497,23705,23170,24503,24123,26067,26602,28112
-      },
-      /*Cr  qi=60  OC_MODE_GOLDEN_MV*/
-      {
-         2697, 9478,17120,21480,23913,25934,27245,26386,
-        26332,26279,25478,26393,26603,26898,26850,27019
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=61  OC_MODE_INTRA*/
-      {
-         9983,15827,20737,23064,25890,28250,30622,32541,
-        34679,36732,38370,39468,41114,42825,44320,55702
-      },
-      /*Y'  qi=61  OC_MODE_INTER_NOMV*/
-      {
-         4811,14103,20721,25851,29381,32184,34474,36605,
-        38885,41228,43527,46218,47613,50721,51832,63429
-      },
-      /*Y'  qi=61  OC_MODE_INTER_MV*/
-      {
-         4887,15381,20937,25380,28798,31459,33864,36236,
-        38554,40944,43212,45181,47157,48824,50535,57596
-      },
-      /*Y'  qi=61  OC_MDOE_INTER_MV_LAST*/
-      {
-         4856,15738,21082,25443,28711,31393,33901,36249,
-        38518,40707,42833,44834,46672,48263,49881,57188
-      },
-      /*Y'  qi=61  OC_MODE_INTER_MV_LAST2*/
-      {
-         4741,13976,19919,24909,28730,31759,34391,36839,
-        39301,41620,43840,45876,47740,49495,51328,58790
-      },
-      /*Y'  qi=61  OC_MODE_INTER_MV_FOUR*/
-      {
-         3629,12837,19864,24871,28743,31851,34572,37092,
-        39478,41719,43862,45805,47732,49496,51054,56816
-      },
-      /*Y'  qi=61  OC_MODE_GOLDEN_NOMV*/
-      {
-         4495,12401,19103,23606,27290,30266,33189,35582,
-        37945,39717,41615,43236,44036,45385,47125,59643
-      },
-      /*Y'  qi=61  OC_MODE_GOLDEN_MV*/
-      {
-         4693,12930,20409,25428,29031,31977,34683,37214,
-        39627,41823,43962,45703,47570,48660,50261,56526
-      }
-    },
-    {
-      /*Cb  qi=61  OC_MODE_INTRA*/
-      {
-         7405,16765,21589,24852,28230,30064,31544,33785,
-        36553,39188,41457,44308,46190,47529,49455,57486
-      },
-      /*Cb  qi=61  OC_MODE_INTER_NOMV*/
-      {
-         5681,13362,21458,25118,28486,35183,38314,45978,
-        40914,43822,43208,41307,48260,47036,52749,55641
-      },
-      /*Cb  qi=61  OC_MODE_INTER_MV*/
-      {
-         5115,14267,21370,25243,30302,35264,38561,42119,
-        44416,47098,49259,54928,52825,55191,59258,61690
-      },
-      /*Cb  qi=61  OC_MDOE_INTER_MV_LAST*/
-      {
-         3022,14154,21415,25394,30698,36199,39937,41625,
-        42699,43295,43516,43798,43046,42494,41823,42324
-      },
-      /*Cb  qi=61  OC_MODE_INTER_MV_LAST2*/
-      {
-         5385,11885,21152,25496,30508,35431,40588,45604,
-        46888,50844,47119,48062,50234,63936,56316,61708
-      },
-      /*Cb  qi=61  OC_MODE_INTER_MV_FOUR*/
-      {
-         3614,11263,20556,25179,30197,35540,40210,43859,
-        46541,49712,50696,53132,57093,56213,61448,59422
-      },
-      /*Cb  qi=61  OC_MODE_GOLDEN_NOMV*/
-      {
-         4378,10474,14895,17089,20741,24939,27994,30126,
-        32203,34738,36752,39014,37508,37694,37560,41476
-      },
-      /*Cb  qi=61  OC_MODE_GOLDEN_MV*/
-      {
-         3501,12297,21537,25493,29517,33267,33735,34383,
-        34998,35417,36396,36485,37423,37386,38173,42790
-      }
-    },
-    {
-      /*Cr  qi=61  OC_MODE_INTRA*/
-      {
-         4144,12471,17388,20758,23786,26258,28804,31378,
-        33896,35240,36442,38423,40216,40843,42852,49074
-      },
-      /*Cr  qi=61  OC_MODE_INTER_NOMV*/
-      {
-         3430, 8893,17358,22812,26482,27239,38656,32364,
-        28199,35296,13753,33383,34664,27328,39040,35648
-      },
-      /*Cr  qi=61  OC_MODE_INTER_MV*/
-      {
-         4034, 9500,17380,22684,26997,30365,32415,34385,
-        36832,38251,39807,44565,42925,41803,36868,38131
-      },
-      /*Cr  qi=61  OC_MDOE_INTER_MV_LAST*/
-      {
-         3396, 9349,17190,22579,26655,29993,31776,32075,
-        31307,28978,27950,26731,26357,26876,27313,24595
-      },
-      /*Cr  qi=61  OC_MODE_INTER_MV_LAST2*/
-      {
-         3323, 9431,17361,23241,27215,30229,32266,32313,
-        33883,26348,29338,25467,36192,38944,32624,29664
-      },
-      /*Cr  qi=61  OC_MODE_INTER_MV_FOUR*/
-      {
-         2615, 8870,17164,22709,26742,29849,32447,35236,
-        37025,40547,41884,43228,41193,39505,35281,27504
-      },
-      /*Cr  qi=61  OC_MODE_GOLDEN_NOMV*/
-      {
-         3216, 8379,11650,15792,18756,20805,23623,23360,
-        23343,23693,23148,24074,24013,25617,27006,28736
-      },
-      /*Cr  qi=61  OC_MODE_GOLDEN_MV*/
-      {
-         2682, 9478,17118,21448,23984,25942,27208,26280,
-        26430,26322,25570,25998,26718,26996,26861,26951
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=62  OC_MODE_INTRA*/
-      {
-        11018,17178,22038,24368,27273,29713,32178,34197,
-        36401,38583,40323,41540,43292,45091,46665,58787
-      },
-      /*Y'  qi=62  OC_MODE_INTER_NOMV*/
-      {
-         5286,15155,22186,27460,30988,33858,36403,38804,
-        41287,43880,46356,48822,50694,54408,55514,65535
-      },
-      /*Y'  qi=62  OC_MODE_INTER_MV*/
-      {
-         5367,16633,22175,26652,30322,33190,35827,38393,
-        40959,43523,45863,48113,50190,52097,53822,60966
-      },
-      /*Y'  qi=62  OC_MDOE_INTER_MV_LAST*/
-      {
-         4888,17024,22407,26913,30357,33242,35951,38532,
-        40993,43409,45684,47823,49795,51335,53162,60633
-      },
-      /*Y'  qi=62  OC_MODE_INTER_MV_LAST2*/
-      {
-         5372,14075,21491,26761,30539,33615,36450,39162,
-        41801,44363,46647,48883,50783,52593,54468,62380
-      },
-      /*Y'  qi=62  OC_MODE_INTER_MV_FOUR*/
-      {
-         4846,14082,21164,26387,30456,33759,36682,39405,
-        41977,44421,46704,48793,50841,52734,54400,60296
-      },
-      /*Y'  qi=62  OC_MODE_GOLDEN_NOMV*/
-      {
-         3685,13164,20179,24874,28828,32215,35186,37760,
-        40368,42298,44232,45577,46556,47619,50034,62971
-      },
-      /*Y'  qi=62  OC_MODE_GOLDEN_MV*/
-      {
-         5333,14474,21825,26971,30764,33909,36865,39646,
-        42273,44714,47006,48863,50734,52041,53690,59811
-      }
-    },
-    {
-      /*Cb  qi=62  OC_MODE_INTRA*/
-      {
-         7337,16810,21625,24876,28257,30082,31527,33742,
-        36564,39185,41399,44283,46019,47440,49325,57568
-      },
-      /*Cb  qi=62  OC_MODE_INTER_NOMV*/
-      {
-         5378,13726,21489,25132,29673,33311,41502,56448,
-        50320,44824,50439,48279,51128,55841,48480,57757
-      },
-      /*Cb  qi=62  OC_MODE_INTER_MV*/
-      {
-         5144,14062,21411,25415,30512,35868,39404,41985,
-        44284,48052,51784,53453,52167,56340,58552,60869
-      },
-      /*Cb  qi=62  OC_MDOE_INTER_MV_LAST*/
-      {
-         2885,14056,21466,25443,30674,36009,39656,41545,
-        42356,43329,43065,43321,42358,42030,41688,41967
-      },
-      /*Cb  qi=62  OC_MODE_INTER_MV_LAST2*/
-      {
-         5139,12562,21441,25364,30396,35304,39595,44650,
-        46141,48736,45932,47478,47534,59975,58432,62510
-      },
-      /*Cb  qi=62  OC_MODE_INTER_MV_FOUR*/
-      {
-         3779,11325,20578,25216,30210,35513,40210,43889,
-        46266,49365,51051,53438,54664,56114,62846,60338
-      },
-      /*Cb  qi=62  OC_MODE_GOLDEN_NOMV*/
-      {
-         3433, 9865,14779,16892,20249,24336,28108,30079,
-        32351,35133,37843,38935,37118,37969,38528,41402
-      },
-      /*Cb  qi=62  OC_MODE_GOLDEN_MV*/
-      {
-         3447,12505,21556,25523,29502,33333,33671,34174,
-        34557,35350,35813,36809,36831,37765,37790,42547
-      }
-    },
-    {
-      /*Cr  qi=62  OC_MODE_INTRA*/
-      {
-         4504,13374,18493,21970,25144,27738,30516,33273,
-        35926,37393,38671,40835,42604,43726,45949,52439
-      },
-      /*Cr  qi=62  OC_MODE_INTER_NOMV*/
-      {
-         3889, 9831,18689,23797,28291,33033,57344,29186,
-        30473,40010,16136,41104,36443,20952,42048,38502
-      },
-      /*Cr  qi=62  OC_MODE_INTER_MV*/
-      {
-         4591,10528,18803,24268,28556,32637,34346,37536,
-        40198,41989,45421,43745,48797,48139,44224,39491
-      },
-      /*Cr  qi=62  OC_MDOE_INTER_MV_LAST*/
-      {
-         3704,10255,18516,24224,28650,32124,34011,34265,
-        33644,30560,29563,29050,27798,28884,29648,26379
-      },
-      /*Cr  qi=62  OC_MODE_INTER_MV_LAST2*/
-      {
-         3997,10408,18610,24726,28794,32108,34519,35308,
-        36674,27699,31603,27547,36475,43285,39307,40192
-      },
-      /*Cr  qi=62  OC_MODE_INTER_MV_FOUR*/
-      {
-         3066, 9886,18515,24367,28635,31972,34783,37316,
-        39659,42795,44154,45479,43653,53192,39624,29015
-      },
-      /*Cr  qi=62  OC_MODE_GOLDEN_NOMV*/
-      {
-         2788, 8873,12400,16679,19909,22191,25460,24946,
-        24748,25269,24967,26102,26496,27615,28677,30437
-      },
-      /*Cr  qi=62  OC_MODE_GOLDEN_MV*/
-      {
-         2958,10483,18422,23048,25590,27821,29005,28341,
-        28241,28060,27219,27610,28279,28657,28210,29042
-      }
-    }
-  },
-  {
-    {
-      /*Y'  qi=63  OC_MODE_INTRA*/
-      {
-        11558,17955,22921,25284,28269,30774,33291,35373,
-        37646,39911,41732,43011,44834,46687,48369,61056
-      },
-      /*Y'  qi=63  OC_MODE_INTER_NOMV*/
-      {
-         5704,16338,23392,28558,32177,35129,37786,40327,
-        43088,45889,48684,51353,53472,56645,57877,65535
-      },
-      /*Y'  qi=63  OC_MODE_INTER_MV*/
-      {
-         5608,17430,23193,27851,31629,34601,37344,40081,
-        42921,45718,48290,50641,52734,54872,56634,63699
-      },
-      /*Y'  qi=63  OC_MDOE_INTER_MV_LAST*/
-      {
-         5507,17905,23395,27970,31505,34491,37346,40088,
-        42757,45372,47836,50136,52160,53994,55751,63144
-      },
-      /*Y'  qi=63  OC_MODE_INTER_MV_LAST2*/
-      {
-         5656,14910,22171,27549,31627,34942,37918,40634,
-        43194,45760,48338,50591,52958,54882,57023,64999
-      },
-      /*Y'  qi=63  OC_MODE_INTER_MV_FOUR*/
-      {
-         5189,14819,22100,27479,31678,35114,38168,41027,
-        43716,46309,48696,50885,53024,55000,56708,62715
-      },
-      /*Y'  qi=63  OC_MODE_GOLDEN_NOMV*/
-      {
-         3863,13809,20993,25730,29805,33316,36484,39105,
-        41746,43824,45969,47273,48882,49880,51888,65431
-      },
-      /*Y'  qi=63  OC_MODE_GOLDEN_MV*/
-      {
-         5618,14999,22838,28117,32036,35354,38465,41431,
-        44224,46853,49142,51269,53225,54451,56158,62225
-      }
-    },
-    {
-      /*Cb  qi=63  OC_MODE_INTRA*/
-      {
-         7335,16805,21644,24903,28332,30135,31627,33856,
-        36612,39157,41402,44354,46124,47578,49435,57762
-      },
-      /*Cb  qi=63  OC_MODE_INTER_NOMV*/
-      {
-         5570,14249,21497,25176,30004,36027,38748,41937,
-        48640,46098,47623,48411,52140,50397,53303,62859
-      },
-      /*Cb  qi=63  OC_MODE_INTER_MV*/
-      {
-         5103,14047,21414,25245,30286,35396,38446,42150,
-        42730,46850,48970,51030,53658,55834,59934,62206
-      },
-      /*Cb  qi=63  OC_MDOE_INTER_MV_LAST*/
-      {
-         3135,14085,21472,25438,30643,35934,39704,41482,
-        42565,43119,42766,43219,42671,41921,41429,41668
-      },
-      /*Cb  qi=63  OC_MODE_INTER_MV_LAST2*/
-      {
-         5045,12541,21374,25850,30909,36393,41013,45814,
-        47198,50085,45739,49842,51627,60091,62336,64899
-      },
-      /*Cb  qi=63  OC_MODE_INTER_MV_FOUR*/
-      {
-         3764,11331,20599,25235,30201,35556,40046,43664,
-        46298,49688,50541,52289,54587,55953,62024,61965
-      },
-      /*Cb  qi=63  OC_MODE_GOLDEN_NOMV*/
-      {
-         3448, 9737,14801,16948,20288,24726,28083,30080,
-        32603,34916,37185,38691,37611,38978,38254,41762
-      },
-      /*Cb  qi=63  OC_MODE_GOLDEN_MV*/
-      {
-         3384,12465,21541,25511,29472,33169,33776,34310,
-        34919,34996,35791,36164,36665,37309,37453,42492
-      }
-    },
-    {
-      /*Cr  qi=63  OC_MODE_INTRA*/
-      {
-         4731,14048,19421,23021,26358,29096,31971,34869,
-        37665,39194,40570,42899,44920,45586,48385,55323
-      },
-      /*Cr  qi=63  OC_MODE_INTER_NOMV*/
-      {
-         4672,10842,20473,26017,30252,34195,42240,36258,
-        40438,26514,19893,42624,42191,44576,23717,35456
-      },
-      /*Cr  qi=63  OC_MODE_INTER_MV*/
-      {
-         5013,11465,19912,26015,30548,34611,37458,38948,
-        42717,45724,49301,44595,45208,44149,48865,45369
-      },
-      /*Cr  qi=63  OC_MDOE_INTER_MV_LAST*/
-      {
-         4383,11291,19830,25779,30402,34283,36263,36423,
-        35857,33041,31324,30471,28939,29927,31898,27794
-      },
-      /*Cr  qi=63  OC_MODE_INTER_MV_LAST2*/
-      {
-         4233,11664,20034,26638,30913,34172,36486,38263,
-        39196,32849,32392,34608,37843,41750,42240,33403
-      },
-      /*Cr  qi=63  OC_MODE_INTER_MV_FOUR*/
-      {
-         3324,10804,19858,25938,30354,33911,36693,39624,
-        41989,45559,46904,41902,49312,43578,51593,30360
-      },
-      /*Cr  qi=63  OC_MODE_GOLDEN_NOMV*/
-      {
-         2957, 9412,12794,17537,21090,23556,26774,26498,
-        26616,27479,26969,27537,28664,29173,30867,31724
-      },
-      /*Cr  qi=63  OC_MODE_GOLDEN_MV*/
-      {
-         3141,11491,19876,24885,27337,29503,30714,29953,
-        30092,29909,28929,29603,29853,30442,30411,30485
-      }
-    }
-  }
-};
-
-ogg_uint16_t OC_RES_DISTORTS[64][3][OC_NMODES][16];
-
-#if defined(OC_BITRATE_STATS)
-static ogg_int64_t OC_RES_BITRATE_ACCUM[64][3][OC_NMODES][16];
-static int         OC_RES_BITRATE_SAMPLES[64][3][OC_NMODES][16];
-static ogg_int64_t OC_RES_DISTORT_ACCUM[64][3][OC_NMODES][16];
-static ogg_int64_t OC_RES_DISTORT_SAMPLES[64][3][OC_NMODES][16];
-
-#include <stdio.h>
-
-void oc_bitrate_stats_read(void){
-  FILE *in;
-  in=fopen("modedec.stats","rb");
-  if(in==NULL)return;
-  fread(OC_RES_BITRATE_ACCUM,sizeof(OC_RES_BITRATE_ACCUM),1,in);
-  fread(OC_RES_BITRATE_SAMPLES,sizeof(OC_RES_BITRATE_SAMPLES),1,in);
-  fread(OC_RES_DISTORT_ACCUM,sizeof(OC_RES_DISTORT_ACCUM),1,in);
-  fread(OC_RES_DISTORT_SAMPLES,sizeof(OC_RES_DISTORT_SAMPLES),1,in);
-  /*Update the current bitrate statistics in use.*/
-  {
-    int qi;
-    for(qi=0;qi<64;qi++){
-      int pli;
-      for(pli=0;pli<3;pli++){
-        int modei;
-        for(modei=0;modei<OC_NMODES;modei++){
-          int erri;
-          for(erri=0;erri<16;erri++){
-            int n;
-            n=OC_RES_BITRATE_SAMPLES[qi][pli][modei][erri];
-            if(n!=0){
-              OC_RES_BITRATES[qi][pli][modei][erri]=(ogg_uint16_t)OC_MINI(65535,
-               ((OC_RES_BITRATE_ACCUM[qi][pli][modei][erri]<<1)+n)/(n<<1));
-            }
-            n=OC_RES_DISTORT_SAMPLES[qi][pli][modei][erri];
-            if(n!=0){
-              OC_RES_DISTORTS[qi][pli][modei][erri]=(ogg_uint16_t)OC_MINI(65535,
-               ((OC_RES_DISTORT_ACCUM[qi][pli][modei][erri]<<OC_DIS_SCALE+1)+n)/
-               (n<<1));
-            }
-          }
-        }
-      }
-    }
-  }
-}
-
-void oc_bitrate_stats_write(void){
-  FILE *out;
-  out=fopen("modedec.stats","wb");
-  fwrite(OC_RES_BITRATE_ACCUM,sizeof(OC_RES_BITRATE_ACCUM),1,out);
-  fwrite(OC_RES_BITRATE_SAMPLES,sizeof(OC_RES_BITRATE_SAMPLES),1,out);
-  fwrite(OC_RES_DISTORT_ACCUM,sizeof(OC_RES_DISTORT_ACCUM),1,out);
-  fwrite(OC_RES_DISTORT_SAMPLES,sizeof(OC_RES_DISTORT_SAMPLES),1,out);
-}
-
-void oc_bitrate_update_stats(oc_enc_ctx *_enc,int _huff_idxs[5][3]){
-  static OC_HUFF_GROUP_IDXS[64]={
-    0,1,1,1,1,1,2,2,
-    2,2,2,2,2,2,2,3,
-    3,3,3,3,3,3,3,3,
-    3,3,3,3,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
-  };
-  ogg_uint32_t  eob_bits[64];
-  int           eob_runs[64];
-  int           ref_idx;
-  int           pli;
-  int          *coded_fragi;
-  int          *coded_fragi_end;
-  int           ti[64];
-  int           ebi[64];
-  int           zzi;
-  int           hgi;
-  int           token;
-  int           eb;
-  int           skip;
-  memset(eob_runs,0,sizeof(eob_runs));
-  memcpy(ti,_enc->dct_token_offs[0],sizeof(ti));
-  memcpy(ebi,_enc->extra_bits_offs,sizeof(ebi));
-  /*Set up for EOB runs that span coefficient boundaries.*/
-  for(zzi=1;zzi<64;zzi++){
-    /*If we've found the last coefficient spanned by a multi-coefficient EOB
-       run...*/
-    if(ti[zzi]&&(ti[zzi]<_enc->ndct_tokens[zzi]||zzi>=63||!ti[zzi+1])){
-      int zzj;
-      int zzk;
-      /*Find the portion of the EOB run that used to be in this coefficient
-         and in any other coefficients after the first one spanned by the
-         run.*/
-      token=_enc->dct_tokens[zzi][0];
-      eb=OC_DCT_TOKEN_EXTRA_BITS[token]?_enc->extra_bits[zzi][0]:0;
-      skip=-oc_dct_token_skip(token,eb);
-      for(zzj=zzi-1;ti[zzj]>=_enc->ndct_tokens[zzj];zzj--){
-        if(ti[zzj]){
-          token=_enc->dct_tokens[zzj][0];
-          eb=OC_DCT_TOKEN_EXTRA_BITS[token]?_enc->extra_bits[zzj][0]:0;
-          skip-=oc_dct_token_skip(token,eb);
-        }
-      }
-      /*Find the first non-trivial coefficient in the EOB run.*/
-      for(zzk=zzj+1;!ti[zzk];zzk++);
-      /*Find the total length of the EOB run.*/
-      token=_enc->dct_tokens[zzj][_enc->ndct_tokens[zzj]-1];
-      eb=OC_DCT_TOKEN_EXTRA_BITS[token]?
-       _enc->extra_bits[zzj][_enc->nextra_bits[zzj]-1]:0;
-      eob_runs[zzk]=-oc_dct_token_skip(token,eb);
-      /*Find the Huffman group index and the color plane index where the EOB
-         run was actually coded.*/
-      hgi=OC_HUFF_GROUP_IDXS[zzj];
-      for(pli=0;pli<2;pli++){
-        if(_enc->dct_token_offs[pli+1][zzj]>=_enc->ndct_tokens[zzj])break;
-      }
-      eob_bits[zzk]=OC_DCT_TOKEN_EXTRA_BITS[token]+
-       _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<OC_BIT_SCALE;
-      /*Compute the bits that will be left to be distributed when we start
-         each non-trivial coefficient spanned by the run after the one the run
-         is started in.*/
-      for(;;){
-        while(eob_runs[zzk]>skip){
-          eob_bits[zzk]-=
-           ((eob_bits[zzk]<<1)+eob_runs[zzi])/(eob_runs[zzk]<<1);
-          eob_runs[zzk]--;
-        }
-        if(zzk>=zzi)break;
-        zzj=zzk;
-        /*Skip to the next non-trivial coefficient.*/
-        for(zzk++;!ti[zzk];zzk++);
-        eob_bits[zzk]=eob_bits[zzj];
-        eob_runs[zzk]=eob_runs[zzj];
-        /*And remove the EOB tokens that belonged to this coefficient.*/
-        token=_enc->dct_tokens[zzj][0];
-        eb=OC_DCT_TOKEN_EXTRA_BITS[token]?_enc->extra_bits[zzj][0]:0;
-        skip+=oc_dct_token_skip(token,eb);
-      }
-    }
-  }
-  /*Now, eob_bits and eob_runs are initialized exactly as they would be if we
-     were going through a coefficient at a time (as things are ordered in the
-     bitstream) instead of a block at a time.
-    That setup was a little complicated, but it lets us now go through in
-     block order, maintaining a counter for each coefficient, instead of
-     traversing each block for each coefficient and maintaining a counter and
-     bit count per block.*/
-  /*Go through the actual encoded tokens and assign the bits used by each to
-     the fragment(s) they came from.*/
-  ref_idx=_enc->state.ref_frame_idx[OC_FRAME_SELF];
-  coded_fragi_end=coded_fragi=_enc->state.coded_fragis;
-  for(pli=0;pli<3;pli++){
-    int ref_ystride;
-    int cur_ystride;
-    cur_ystride=_enc->state.input[pli].ystride;
-    ref_ystride=_enc->state.ref_frame_bufs[ref_idx][pli].ystride;
-    coded_fragi_end+=_enc->state.ncoded_fragis[pli];
-    for(;coded_fragi<coded_fragi_end;coded_fragi++){
-      oc_fragment *frag;
-      int          fragi;
-      fragi=*coded_fragi;
-      frag=_enc->state.frags+fragi;
-      if(frag->coded){
-        oc_fragment_enc_info *efrag;
-        ogg_uint32_t          frag_bits;
-        int                   err_bin;
-        efrag=_enc->frinfo+fragi;
-        frag_bits=0;
-        for(zzi=0;zzi<64;){
-          if(eob_runs[zzi]){
-            ogg_uint32_t bits;
-            /*Evenly divide the bits for an EOB run among the fragments
-               that it ends.
-              This incremental formulation ensures that the exact
-               correct number of bits gets distributed.*/
-            bits=((eob_bits[zzi]<<1)+eob_runs[zzi])/(eob_runs[zzi]<<1);
-            eob_bits[zzi]-=bits;
-            eob_runs[zzi]--;
-            frag_bits+=bits;
-            break;
-          }
-          token=_enc->dct_tokens[zzi][ti[zzi]++];
-          eb=OC_DCT_TOKEN_EXTRA_BITS[token]?
-           _enc->extra_bits[zzi][ebi[zzi]++]:0;
-          skip=oc_dct_token_skip(token,eb);
-          hgi=OC_HUFF_GROUP_IDXS[zzi];
-          if(skip<0){
-            eob_runs[zzi]=-skip;
-            eob_bits[zzi]=OC_DCT_TOKEN_EXTRA_BITS[token]+
-             _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<OC_BIT_SCALE;
-          }
-          else{
-            frag_bits+=OC_DCT_TOKEN_EXTRA_BITS[token]+
-             _enc->huff_codes[_huff_idxs[hgi][pli]][token].nbits<<OC_BIT_SCALE;
-            zzi+=skip;
-          }
-        }
-        err_bin=efrag->eerror>>(frag->mbmode==OC_MODE_INTRA?8:6);
-        err_bin=OC_MINI(15,err_bin);
-        if(!frag->invalid){
-          unsigned char *cur;
-          unsigned char *ref;
-          int            err;
-          int            i;
-          int            j;
-          OC_RES_BITRATE_ACCUM[frag->qi][pli][frag->mbmode][err_bin]+=frag_bits;
-          OC_RES_BITRATE_SAMPLES[frag->qi][pli][frag->mbmode][err_bin]++;
-          err=0;
-          cur=frag->buffer[OC_FRAME_IO];
-          ref=frag->buffer[ref_idx];
-          if(frag->border!=NULL){
-            ogg_int64_t mask;
-            mask=frag->border->mask;
-            for(i=0;i<8;i++){
-              for(j=0;j<8;j++){
-                if(mask&1){
-                  err+=abs(cur[j]-ref[j]);
-                }
-                mask>>=1;
-              }
-              cur+=cur_ystride;
-              ref+=ref_ystride;
-            }
-            OC_RES_DISTORT_SAMPLES[frag->qi][pli][frag->mbmode][err_bin]+=
-             frag->border->npixels;
-          }
-          else{
-            for(i=0;i<8;i++){
-              for(j=0;j<8;j++)err+=abs(cur[j]-ref[j]);
-              cur+=cur_ystride;
-              ref+=ref_ystride;
-            }
-            OC_RES_DISTORT_SAMPLES[frag->qi][pli][frag->mbmode][err_bin]+=64;
-          }
-          OC_RES_DISTORT_ACCUM[frag->qi][pli][frag->mbmode][err_bin]+=err;
-        }
-      }
-    }
-  }
-  /*Update the current bitrate statistics in use.*/
-  {
-    int qi;
-    for(qi=0;qi<64;qi++){
-      for(pli=0;pli<3;pli++){
-        int modei;
-        for(modei=0;modei<OC_NMODES;modei++){
-          int erri;
-          for(erri=0;erri<16;erri++){
-            int n;
-            n=OC_RES_BITRATE_SAMPLES[qi][pli][modei][erri];
-            if(n!=0){
-              OC_RES_BITRATES[qi][pli][modei][erri]=(ogg_uint16_t)OC_MINI(65535,
-               ((OC_RES_BITRATE_ACCUM[qi][pli][modei][erri]<<1)+n)/(n<<1));
-            }
-            n=OC_RES_DISTORT_SAMPLES[qi][pli][modei][erri];
-            if(n!=0){
-              OC_RES_DISTORTS[qi][pli][modei][erri]=(ogg_uint16_t)OC_MINI(65535,
-               ((OC_RES_DISTORT_ACCUM[qi][pli][modei][erri]<<OC_DIS_SCALE+1)+n)/
-               (n<<1));
-            }
-          }
-        }
-      }
-    }
-  }
-}
-#endif
-
-
-
-
-
-
-
-
-
-
-
-#if 0
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
-
-/*\rho domain rate-distortion analysis, after He \cite{He2001}
-  TODO: Is this worth the speed hit?
-
-  @PHDTHESIS{He2001,
-    author="Zhihai He",
-    title="\rho-Domain Rate-Distortion Analysis and Rate-Control for Visual
-     Coding and Communication",
-    school="University of California at Santa Barbara",
-    year=2001
-  }*/
-
-
-/*256*(A(\rho), B(\rho) and C(\rho)) for \rho=0/64..64/64, where
-   the bitrate for a macro block is approximated as
-   Q_{nz}(\rho)*A(\rho)+Q_z(\rho)*B(\rho)+C(\rho).
-  TODO: These numbers were extrapolated from numbers derived from JPEG.
-  We should derive our own numbers at some point.*/
-static const int OC_INTRA_RATE_PARAMS[65][3]={
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{311,-114,231},{311,-114,231},{311,-114,231},
-  {311,-114,231},{305,-115,231},{272,-119,232},{240,-124,234},
-  {207,-129,236},{194,-119,230},{181,-110,224},{168,-100,217},
-  {161, -96,212},{156, -93,208},{150, -90,203},{146, -82,196},
-  {145, -73,188},{143, -63,179},{137, -55,171},{125, -49,163},
-  {113, -43,156},{104, -38,150},{104, -38,150},{104, -38,150},
-  {104, -38,150}
-};
-
-/*Estimates the number of bits required to code this macro block in intra
-   mode.
-  _enc:     The encoding context.
-  _mbi:     The macro block index.
-  _nc_bits: Returns the number of bits required for the not-coded fragments.
-            This is used for key frame decisions.
-  Return: The number of bits required for the coded fragments.*/
-int oc_enc_intra_bits_est(oc_enc_ctx *_enc,int _mbi,int *_nc_bits){
-  oc_mb          *mb;
-  oc_mb_enc_info *emb;
-  ogg_uint16_t   *fquant;
-  ogg_uint16_t   *iquant;
-  ogg_int32_t     bits;
-  ogg_int32_t     nc_bits;
-  int             q_nz;
-  int             q_z;
-  int             rho;
-  int             bi;
-  emb=_enc->mbinfo+_mbi;
-  mb=_enc->state.mbs+_mbi;
-  fquant=_enc->enquant_tables[_enc->state.qi].intra_y;
-  iquant=_enc->state.dequant_tables[_enc->state.qi].intra_y;
-  bits=nc_bits=0;
-  for(bi=0;bi<4;bi++){
-    oc_fragment_enc_info *efrag;
-    ogg_int32_t           frag_bits;
-    int                   zzi;
-    int                   zrun;
-    efrag=_enc->frinfo+mb->map[0][bi];
-    q_nz=q_z=rho=zrun=0;
-    for(zzi=0;zzi<64;zzi++){
-      int c_abs;
-      int ci;
-      ci=OC_FZIG_ZAG[zzi];
-      c_abs=abs(efrag->dct_coeffs[ci]);
-      if(c_abs<=OC_MAXI(efrag->tols[ci],iquant[ci]>>1)){
-        zrun++;
-        rho++;
-      }
-      else{
-        if(zrun){
-          q_z+=1+oc_ilog(zrun);
-          zrun=0;
-        }
-        q_nz+=1+oc_ilog((ogg_int32_t)c_abs*fquant[ci]+OC_FQUANT_ROUND>>
-         OC_FQUANT_SHIFT);
-      }
-    }
-    if(zrun)q_z+=1+oc_ilog(zrun);
-    frag_bits=OC_INTRA_RATE_PARAMS[rho][0]*(ogg_int32_t)q_nz+
-     OC_INTRA_RATE_PARAMS[rho][1]*(ogg_int32_t)q_z+
-     OC_INTRA_RATE_PARAMS[rho][2];
-    if(_enc->state.frags[mb->map[0][bi]].coded)bits+=frag_bits;
-    else nc_bits=frag_bits;
-  }
-  /*TODO: Chroma fragments.*/
-  *_nc_bits=(int)(nc_bits+128>>8);
-  return (int)(bits+128>>8);
-}
-#endif

Deleted: experimental/j/theora-mashup/lib/dec/encinfo.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/encinfo.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/encinfo.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,115 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "encint.h"
-
-
-
-/*Packs a series of octets from a given byte array into the pack buffer.
-  _opb: The pack buffer to store the octets in.
-  _buf: The byte array containing the bytes to pack.
-  _len: The number of octets to pack.*/
-static void oc_pack_octets(oggpack_buffer *_opb,const char *_buf,int _len){
-  int i;
-  for(i=0;i<_len;i++)oggpackB_write(_opb,*_buf++,8);
-}
-
-
-
-int th_encode_flushheader(th_enc_ctx *_enc,th_comment *_tc,
- ogg_packet *_op){
-  if(_enc==NULL||_op==NULL)return TH_EFAULT;
-  switch(_enc->packet_state){
-    /*Codec info header.*/
-    case OC_PACKET_INFO_HDR:{
-      oggpackB_reset(&_enc->opb);
-      /*Mark this packet as the info header.*/
-      oggpackB_write(&_enc->opb,0x80,8);
-      /*Write the codec string.*/
-      oc_pack_octets(&_enc->opb,"theora",6);
-      /*Write the codec bitstream version.*/
-      oggpackB_write(&_enc->opb,TH_VERSION_MAJOR,8);
-      oggpackB_write(&_enc->opb,TH_VERSION_MINOR,8);
-      oggpackB_write(&_enc->opb,TH_VERSION_SUB,8);
-      /*Describe the encoded frame.*/
-      oggpackB_write(&_enc->opb,_enc->state.info.frame_width>>4,16);
-      oggpackB_write(&_enc->opb,_enc->state.info.frame_height>>4,16);
-      oggpackB_write(&_enc->opb,_enc->state.info.pic_width,24);
-      oggpackB_write(&_enc->opb,_enc->state.info.pic_height,24);
-      oggpackB_write(&_enc->opb,_enc->state.info.pic_x,8);
-      oggpackB_write(&_enc->opb,_enc->state.info.frame_height-
-       _enc->state.info.pic_height-_enc->state.info.pic_y,8);
-      oggpackB_write(&_enc->opb,_enc->state.info.fps_numerator,32);
-      oggpackB_write(&_enc->opb,_enc->state.info.fps_denominator,32);
-      oggpackB_write(&_enc->opb,_enc->state.info.aspect_numerator,24);
-      oggpackB_write(&_enc->opb,_enc->state.info.aspect_denominator,24);
-      oggpackB_write(&_enc->opb,_enc->state.info.colorspace,8);
-      oggpackB_write(&_enc->opb,_enc->state.info.target_bitrate,24);
-      oggpackB_write(&_enc->opb,_enc->state.info.quality,6);
-      oggpackB_write(&_enc->opb,_enc->state.info.keyframe_granule_shift,5);
-      oggpackB_write(&_enc->opb,_enc->state.info.pixel_fmt,2);
-      /*Spare configuration bits.*/
-      oggpackB_write(&_enc->opb,0,3);
-      _op->b_o_s=1;
-    }break;
-    /*Comment header.*/
-    case OC_PACKET_COMMENT_HDR:{
-      const char *vendor;
-      int         vendor_len;
-      int         i;
-      if(_tc==NULL)return TH_EFAULT;
-      vendor=th_version_string();
-      vendor_len=strlen(vendor);
-      oggpackB_reset(&_enc->opb);
-      /*Mark this packet as the comment header.*/
-      oggpackB_write(&_enc->opb,0x81,8);
-      /*Write the codec string.*/
-      oc_pack_octets(&_enc->opb, "theora", 6);
-      /*Write the vendor string.*/
-      oggpack_write(&_enc->opb,vendor_len,32);
-      oc_pack_octets(&_enc->opb,vendor,vendor_len);
-      oggpack_write(&_enc->opb,_tc->comments,32);
-      for(i=0;i<_tc->comments;i++){
-        if(_tc->user_comments[i]!=NULL){
-          oggpack_write(&_enc->opb,_tc->comment_lengths[i],32);
-          oc_pack_octets(&_enc->opb,_tc->user_comments[i],
-           _tc->comment_lengths[i]);
-        }
-        else oggpack_write(&_enc->opb,0,32);
-      }
-      _op->b_o_s=0;
-    }break;
-    /*Codec setup header.*/
-    case OC_PACKET_SETUP_HDR:{
-      int ret;
-      oggpackB_reset(&_enc->opb);
-      /*Mark this packet as the setup header.*/
-      oggpackB_write(&_enc->opb,0x82,8);
-      /*Write the codec string.*/
-      oc_pack_octets(&_enc->opb,"theora",6);
-      /*Write the quantizer tables.*/
-      oc_quant_params_pack(&_enc->opb,&_enc->qinfo);
-      /*Write the huffman codes.*/
-      ret=oc_huff_codes_pack(&_enc->opb,_enc->huff_codes);
-      /*This should never happen, because we validate the tables when they
-         are set.
-        If you see, it's a good chance memory is being corrupted.*/
-      if(ret<0)return ret;
-      _op->b_o_s=0;
-    }break;
-    /*No more headers to emit.*/
-    default:return 0;
-  }
-  /*This is kind of fugly: we hand the user a buffer which they do not own.
-    We will overwrite it when the next packet is output, so the user better be
-     done with it by then.
-    Vorbis is little better: it hands back buffers that it will free the next
-     time the headers are requested, or when the encoder is cleared.
-    Hopefully libogg2 will make this much cleaner.*/
-  _op->packet=oggpackB_get_buffer(&_enc->opb);
-  _op->bytes=oggpackB_bytes(&_enc->opb);
-  _op->e_o_s=0;
-  _op->granulepos=0;
-  /*Is this smart? Vorbis does not even set this field.*/
-  _op->packetno=0;
-  return ++_enc->packet_state+3;
-}

Deleted: experimental/j/theora-mashup/lib/dec/encint.h
===================================================================
--- experimental/j/theora-mashup/lib/dec/encint.h	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/encint.h	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,296 +0,0 @@
-#include <limits.h>
-#if !defined(_encint_H)
-# define _encint_H (1)
-# include "theora/theoraenc.h"
-# include "internal.h"
-
-typedef struct oc_enc_pipe_stage      oc_enc_pipe_stage;
-typedef struct oc_fragment_enc_info   oc_fragment_enc_info;
-typedef struct oc_mb_enc_info         oc_mb_enc_info;
-typedef struct oc_mode_scheme_chooser oc_mode_scheme_chooser;
-typedef struct oc_enc_vbr_ctx         oc_enc_vbr_ctx;
-typedef struct oc_mcenc_ctx           oc_mcenc_ctx;
-typedef struct th_enc_ctx         oc_enc_ctx;
-
-# include "fdct.h"
-# include "huffenc.h"
-# include "enquant.h"
-
-#define OC_1_LN2 (1.4426950408889634073F)
-
-/*Encoding modes.*/
-#define OC_ENC_MODE_VBR (0)
-#define OC_ENC_MODE_CQI (1)
-/*
-Not yet implemented:
-#define OC_ENC_MODE_CBR (2)
-#define OC_ENC_MODE_RDO (3)
-*/
-
-/*The function used to set the speed for the current encoding mode.
-  _speed: The encoding speed to use.
-          Higher values should provide faster encoding, at reduced
-           rate-distortion performance.
-          This will always be in the range [0..._enc->speed_max].*/
-typedef void (*oc_enc_set_speed_func)(oc_enc_ctx *_enc,int _speed);
-
-/*Constants for the packet-out state machine specific to the encoder.*/
-
-/*Next packet to emit: Data packet, but none are ready yet.*/
-#define OC_PACKET_EMPTY (0)
-/*Next packet to emit: Data packet, and one is ready.*/
-#define OC_PACKET_READY (1)
-
-
-
-/*An encoder pipeline stage.*/
-struct oc_enc_pipe_stage{
-  /*The encoder this pipeline stage belongs to.*/
-  oc_enc_ctx        *enc;
-  /*The next stage in the pipeline.*/
-  oc_enc_pipe_stage *next;
-  /*The number of rows processed so far in each plane.*/
-  int                y_procd[3];
-  /*Called before processing the first stripe.
-    This does not need to call the next stage's start function.
-    Return: 0 on success, or a negative value on error.*/
-  int (*pipe_start)(oc_enc_pipe_stage *_stage);
-  /*Called for each stripe as it becomes available.
-    This function is responsible for calling the next function in the chain.
-    It may do so in smaller or larger stripes than are passed to it, at its
-     discretion.
-    _y_avail: Rows 0 through _y_avail[pli] in plane pli will be available for
-               processing.
-    Return: 0 on success, or a negative value on error.*/
-  int (*pipe_proc)(oc_enc_pipe_stage *_stage,int _y_avail[3]);
-  /*Called after processing the last stripe.
-    This does not need to call the next stage's end function.
-    Return: 0 on success, or a negative value on error.*/
-  int (*pipe_end)(oc_enc_pipe_stage *_stage);
-};
-
-/*Fragment information specific to encoding.*/
-struct oc_fragment_enc_info{
-  /*The DCT coefficients for coding the fragment in intra mode.
-    These are computed in advance by the psycho-visual model, and then reused
-     during mode decision.*/
-  ogg_int16_t     dct_coeffs[64];
-  /*The maximum allowed distortion allowed for this coefficient.
-    The quantizer is free to choose any quantized value that does not move the
-     reconstructed value more than this amount away from the true coefficient
-     value.*/
-  ogg_uint16_t    tols[64];
-  /*The weight derived from the importance of this fragment.*/
-  float           imp_weight;
-  /*The actual error encoded by the residual after mode selection.*/
-  int             eerror;
-  /*The minimum quantizer allowed for each quantizer type.*/
-  unsigned char   qi_min[2];
-  /*The qi index selected for this fragment.*/
-  unsigned char   qii;
-};
-
-/*Macro block information specific to encoding.*/
-struct oc_mb_enc_info{
-  /*The neighboring macro blocks with motion vectors available for the current
-     frame.*/
-  int           cneighbors[4];
-  /*The number of current neighbors available.*/
-  int           ncneighbors;
-  /*The neighboring macro blocks with motion vectors available for the
-     previous frame.*/
-  int           pneighbors[4];
-  /*The number of previous neighbors available.*/
-  int           npneighbors;
-  /*Motion vectors for a macro block for the current frame and the previous
-     two frames.
-    Each is a set of 2 vectors against the previous frame and against the
-     golden frame, which can be used to judge constant velocity and constant
-     acceleration.
-    Uninitialized MVs are (0,0).*/
-  char          mvs[3][2][2];
-  /*Per-block motion vectors for this frame against the previous frame.*/
-  char          bmvs[4][2];
-  /*Minimum motion estimation error from the analysis stage.*/
-  int           aerror;
-  /*Minimum 4V motion estimation error from the analysis stage.*/
-  int           aerror4mv;
-};
-
-/*A structure used to track the optimal mode coding scheme, for use in
-   estimating the cost of coding each mode label during the mode selection
-   process.*/
-struct oc_mode_scheme_chooser{
-  /*Pointers to the Huffman codes associated with each mode scheme.
-    The first 7 are always OC_MODE_CODESA, and the last is always
-     OC_MODE_CODESB.*/
-  const th_huff_code *mode_codes[8];
-  /*Pointers to the a list containing the index of each mode in the mode
-     alphabet used by each scheme.
-    The first entry points to the dynamic scheme0_ranks, while the remaining
-     7 point to the constant entries stored in OC_MODE_SCHEMES.*/
-  const int              *mode_ranks[8];
-  /*The ranks for each mode when coded with scheme 0.
-    These are optimized so that the more frequent modes have lower ranks.*/
-  int                     scheme0_ranks[OC_NMODES];
-  /*The list of modes, sorted in descending order of frequency, that
-     corresponds to the ranks above.*/
-  int                     scheme0_list[OC_NMODES];
-  /*The number of times each mode has been chosen so far.*/
-  int                     mode_counts[OC_NMODES];
-  /*The list of mode coding schemes, sorted in ascending order of bit cost.*/
-  int                     scheme_list[8];
-  /*The number of bits used by each mode coding scheme.*/
-  int                     scheme_bits[8];
-};
-
-
-
-struct th_enc_ctx{
-  /*Shared encoder/decoder state.*/
-  oc_theora_state          state;
-  /*The start of the encoder pipeline.*/
-  oc_enc_pipe_stage       *pipe;
-  /*The maximum speed setting for the current encoding mode.*/
-  int                      speed_max;
-  /*The function used to set the speed level for the current encoding mode.*/
-  oc_enc_set_speed_func    set_speed;
-  /*The INTRA fDCT pipe stage.*/
-  oc_enc_pipe_stage        fdct_pipe;
-  /*The uncoded fragment copying pipe stage.*/
-  oc_enc_pipe_stage        copy_pipe;
-  /*The loop filter pipe stage.*/
-  oc_enc_pipe_stage        loop_pipe;
-  /*The border filling pipe stage.*/
-  oc_enc_pipe_stage        fill_pipe;
-  /*The packet assembly pipe stage.*/
-  oc_enc_pipe_stage        pack_pipe;
-  /*Whether or not packets are ready to be emitted.
-    This takes on negative values while there are remaining header packets to
-     be emitted, reaches 0 when the codec is ready for input, and goes to 1
-     when a frame has been processed and a data packet is ready.*/
-  int                      packet_state;
-  /*Buffer in which to assemble packets.*/
-  oggpack_buffer           opb;
-  /*The list of flags indicating which blocks are coded in all partially coded
-     super blocks.*/
-  char                    *block_coded_flags;
-  /*The number of block coded flags in the list.
-    This is 16 times the number of super blocks with their partially coded
-     flag set.*/
-  int                      nblock_coded_flags;
-  /*Special buffer used for the coded fragment flags.*/
-  oggpack_buffer           opb_coded_flags;
-  /*Encoder-specific fragment information.*/
-  oc_fragment_enc_info    *frinfo;
-  /*Encoder-specific macro block information.*/
-  oc_mb_enc_info          *mbinfo;
-  /*Context information used to perform motion estimation.*/
-  oc_mcenc_ctx            *mcenc;
-  /*Context information used for VBR encoding.*/
-  oc_enc_vbr_ctx          *vbr;
-  /*The qi value lists selected for each potential frame type.*/
-  int                      qis[2][3];
-  /*The number of qi values in the list for each frame type.*/
-  int                      nqis[2];
-  /*The number of coded fragments.*/
-  int                      ncoded_frags;
-  /*The current uncoded_fragi index being copied to each plane.*/
-  int                      uncoded_fragii[3];
-  /*The macro-block mode scheme chooser.*/
-  oc_mode_scheme_chooser   mode_scheme_chooser;
-  /*The motion vector scheme chosen.*/
-  int                      mv_scheme;
-  /*The maximum distance between keyframes.*/
-  ogg_uint32_t             keyframe_frequency_force;
-  /*Whether or not VP3-compatibility is enabled.*/
-  int                      vp3_compatible;
-  /*Whether or not the loop filter is enabled.
-    This is determined each frame, based on the quantizer it is encoded with.*/
-  int                      loop_filter_enabled;
-  /*The bounding value array used for the loop filter.*/
-  int                      bounding_values[512];
-  /*The huffman tables in use.*/
-  th_huff_code         huff_codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS];
-  /*The quantization parameters in use.*/
-  th_quant_info        qinfo;
-  /*Pointers to the quantization tables in use.*/
-  oc_quant_table          *enquant_tables[2][3];
-  /*Storage for the actual quantization tables.*/
-  oc_quant_tables          enqaunt_table_data[2][3];
-  /*The offset of the first DCT token for each coefficient for each plane.*/
-  int                      dct_token_offs[3][64];
-  /*The number of DCT tokens for each coefficient.*/
-  int                      ndct_tokens[64];
-  /*The DCT token lists.*/
-  unsigned char          **dct_tokens;
-  /*The number of extra bits entries for each coefficient.*/
-  int                      nextra_bits[64];
-  /*The offset of the first extra bits entry for each coefficient.*/
-  int                      extra_bits_offs[64];
-  /*The extra bits associated with DCT tokens.*/
-  ogg_uint16_t           **extra_bits;
-};
-
-extern const int OC_MODE_SCHEMES[7][OC_NMODES];
-extern const int OC_DCT_VAL_CAT_SIZES[6];
-extern const int OC_DCT_VAL_CAT_SHIFTS[6];
-extern const int OC_MODE_HAS_MV[OC_NMODES];
-extern const th_huff_code OC_MV_CODES[2][63];
-
-/*The number of fractional bits in bitrate statistics.*/
-#define OC_BIT_SCALE (7)
-/*The number of fractional bits in distortion statistics.*/
-#define OC_DIS_SCALE (9)
-
-/*Estimated bits needed to code a residual given the: quality index, color
-   plane, macro-block mode, and a SAD bin.
-  SAD values for a block are divided by 256 for INTRA mode and 64 for INTER
-   modes to find the appropriate bin.*/
-extern ogg_uint16_t OC_RES_BITRATES[64][3][OC_NMODES][16];
-
-#if defined(OC_BITRATE_STATS)
-void oc_bitrate_update_stats(oc_enc_ctx *_enc,int _huff_idxs[5][3]);
-#endif
-
-
-int oc_sad8_fullpel(const unsigned char *_cur,int _cur_stride,
- const unsigned char *_ref,int _ref_stride);
-int oc_sad8_fullpel_border(const unsigned char *_cur,int _cur_stride,
- const unsigned char *_ref,int _ref_stride,ogg_int64_t _mask);
-int oc_sad8_halfpel(const unsigned char *_cur,int _cur_stride,
- const unsigned char *_ref0,const unsigned char *_ref1,int _ref_stride);
-int oc_sad8_halfpel_border(const unsigned char *_cur,int _cur_stride,
- const unsigned char *_ref0,const unsigned char *_ref1,int _ref_stride,
- ogg_int64_t _mask);
-
-void oc_mode_scheme_chooser_init(oc_mode_scheme_chooser *_chooser);
-void oc_mode_scheme_chooser_reset(oc_mode_scheme_chooser *_chooser);
-int oc_mode_scheme_chooser_cost(oc_mode_scheme_chooser *_chooser,int _mode);
-void oc_mode_scheme_chooser_update(oc_mode_scheme_chooser *_chooser,
- int _mode);
-void oc_mode_scheme_chooser_add(oc_mode_scheme_chooser *_chooser,
- int _mode_counts[OC_NMODES]);
-
-oc_mcenc_ctx *oc_mcenc_alloc(oc_enc_ctx *_enc);
-void oc_mcenc_free(oc_mcenc_ctx *_mcenc);
-int oc_mcenc_search_1mv(oc_mcenc_ctx *_mcenc,int _mbi,int _frame);
-oc_enc_pipe_stage *oc_mcenc_prepend_to_pipe(oc_mcenc_ctx *_mcenc,
- oc_enc_pipe_stage *_next);
-
-oc_enc_vbr_ctx *oc_enc_vbr_alloc(oc_enc_ctx *_enc);
-void oc_enc_vbr_free(oc_enc_vbr_ctx *_vbr);
-int oc_enc_vbr_enable(oc_enc_vbr_ctx *_vbr,th_vbr_cfg *_cfg);
-
-void oc_enc_set_speed_null(oc_enc_ctx *_enc,int _speed);
-void oc_enc_frag_intra_fdct(oc_enc_ctx *_enc,const oc_fragment *_frag,
- ogg_int16_t _dct_vals[64],int _ystride,int _framei);
-int oc_enc_frag_sad(oc_enc_ctx *_enc,oc_fragment *_frag,int _dx,
- int _dy,int _pli,int _frame);
-int oc_enc_partial_sb_flags_pack(oc_enc_ctx *_enc,oggpack_buffer *_opb);
-int oc_enc_coded_sb_flags_pack(oc_enc_ctx *_enc,oggpack_buffer *_opb);
-int oc_enc_coded_block_flags_pack(oc_enc_ctx *_enc,oggpack_buffer *_opb);
-void oc_enc_do_inter_dcts(oc_enc_ctx *_enc);
-void oc_enc_merge_eob_runs(oc_enc_ctx *_enc);
-
-#endif

Deleted: experimental/j/theora-mashup/lib/dec/encmsc.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/encmsc.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/encmsc.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,234 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <ogg/ogg.h>
-#include "encint.h"
-
-
-
-/*The VLC code used for mode schemes 0-6.*/
-static const th_huff_code OC_MODE_CODESA[OC_NMODES]={
-  {0x00,1},{0x02,2},{0x06,3},{0x0E,4},{0x1E,5},{0x3E,6},{0x7E,7},{0x7F,7}
-};
-
-/*The CLC code used for mode scheme 7.*/
-static const th_huff_code OC_MODE_CODESB[OC_NMODES]={
-  {0x00,3},{0x01,3},{0x02,3},{0x03,3},{0x04,3},{0x05,3},{0x06,3},{0x07,3}
-};
-
-
-
-/*Initialize the mode scheme chooser.
-  This need only be called once per encoder.
-  This is probably the best place to describe the various schemes Theora uses
-   to encode macro block modes.
-  There are 8 possible schemes.
-  Schemes 0-6 use a highly unbalanced Huffman code to code each of the modes.
-  The same set of Huffman codes is used for each of these 7 schemes, but the
-   mode assigned to each code varies.
-  Schemes 1-6 have a fixed mapping from Huffman code to MB mode, while scheme
-   0 writes a custom mapping to the bitstream before all the modes.
-  Finally, scheme 7 just encodes each mode directly in 3 bits.
-  Be warned that the number assigned to each mode is slightly different in the
-   bitstream than in this implementation, so a translation needs to be done.
-
-  Mode name:                 Source-code index;  Bit-stream index:
-  OC_MODE_INTRA              0                   1
-  OC_MODE_INTER_NOMV         1                   0
-  OC_MODE_INTER_MV           2                   2
-  OC_MODE_INTER_MV_LAST      3                   3
-  OC_MODE_INTER_MV_LAST2     4                   4
-  OC_MODE_INTER_MV_FOUR      5                   6
-  OC_MODE_GOLDEN_NOMV        6                   7
-  OC_MODE_GOLDEN_MV          7                   5
-
-  The bit stream indices come from the constants assigned to each mode in the
-   original VP3 source.*/
-void oc_mode_scheme_chooser_init(oc_mode_scheme_chooser *_chooser){
-  int msi;
-  _chooser->mode_ranks[0]=_chooser->scheme0_ranks;
-  for(msi=0;msi<7;msi++){
-    _chooser->mode_codes[msi]=OC_MODE_CODESA;
-    _chooser->mode_ranks[msi+1]=OC_MODE_SCHEMES[msi];
-  }
-  _chooser->mode_codes[7]=OC_MODE_CODESB;
-}
-
-/*Reset the mode scheme chooser.
-  This needs to be called once for each frame, including the first.*/
-void oc_mode_scheme_chooser_reset(oc_mode_scheme_chooser *_chooser){
-  int i;
-  memset(_chooser->mode_counts,0,sizeof(_chooser->mode_counts));
-  /*Scheme 0 starts with 24 bits to store the mode list in.*/
-  _chooser->scheme_bits[0]=24;
-  memset(_chooser->scheme_bits+1,0,7*sizeof(_chooser->scheme_bits[1]));
-  for(i=0;i<8;i++){
-    /*Scheme 7 should always start first, and scheme 0 should always start
-       last.*/
-    _chooser->scheme_list[i]=7-i;
-    _chooser->scheme0_list[i]=_chooser->scheme0_ranks[i]=i;
-  }
-}
-
-/*This is the real purpose of this data structure: not actually selecting a
-   mode scheme, but estimating the cost of coding a given mode given all the
-   modes selected so far.
-  This is done via opportunity cost: the cost is defined as the number of bits
-   required to encode all the modes selected so far including the current one
-   using the best possible scheme, minus the number of bits required to encode
-   all the modes selected so far not including the current one using the best
-   possible scheme.
-  The computational expense of doing this probably makes it overkill.
-  Just be happy we take a greedy approach instead of trying to solve the
-   global mode-selection problem (which is NP-hard).
-  _mode: The mode to determine the cost of.
-  Return: The number of bits required to code this mode.*/
-int oc_mode_scheme_chooser_cost(oc_mode_scheme_chooser *_chooser,int _mode){
-  int scheme0;
-  int scheme1;
-  int si;
-  int scheme_bits;
-  int best_bits;
-  int mode_bits;
-  scheme0=_chooser->scheme_list[0];
-  scheme1=_chooser->scheme_list[1];
-  best_bits=_chooser->scheme_bits[scheme0];
-  mode_bits=_chooser->mode_codes[scheme0][
-   _chooser->mode_ranks[scheme0][_mode]].nbits;
-  /*Typical case: If the difference between the best scheme and the next best
-     is greater than 6 bits, then adding just one mode cannot change which
-     scheme we use.*/
-  if(_chooser->scheme_bits[scheme1]-best_bits>6)return mode_bits;
-  /*Otherwise, check to see if adding this mode selects a different scheme
-     as the best.*/
-  si=1;
-  best_bits+=mode_bits;
-  do{
-    scheme1=_chooser->scheme_list[si];
-    /*For any scheme except 0, we can just use the bit cost of the mode's rank
-       in that scheme.*/
-    if(scheme1!=0){
-      scheme_bits=_chooser->scheme_bits[scheme1]+
-       _chooser->mode_codes[scheme1][
-       _chooser->mode_ranks[scheme1][_mode]].nbits;
-    }
-    else{
-      int ri;
-      /*For scheme 0, incrementing the mode count could potentially change the
-         mode's rank.
-        Find the index where the mode would be moved to in the optimal list,
-         and use its bit cost instead of the one for the mode's current
-         position in the list.*/
-      for(ri=_chooser->scheme0_ranks[_mode];ri>0&&
-       _chooser->mode_counts[_mode]>=
-       _chooser->mode_counts[_chooser->scheme0_list[ri-1]];ri--);
-      scheme_bits=_chooser->scheme_bits[0]+OC_MODE_CODESA[ri].nbits;
-    }
-    if(scheme_bits<best_bits)best_bits=scheme_bits;
-    si++;
-  }
-  while(si<8&&_chooser->scheme_bits[_chooser->scheme_list[si]]-
-   _chooser->scheme_bits[scheme0]<=6);
-  return best_bits-_chooser->scheme_bits[scheme0];
-}
-
-/*Update the mode counts and per-scheme bit counts and re-order the scheme
-   lists once a mode has been selected.
-  _mode: The mode that was chosen.*/
-void oc_mode_scheme_chooser_update(oc_mode_scheme_chooser *_chooser,
- int _mode){
-  int ri;
-  int si;
-  _chooser->mode_counts[_mode]++;
-  /*Re-order the scheme0 mode list if necessary.*/
-  for(ri=_chooser->scheme0_ranks[_mode];ri>0;ri--){
-    int pmode;
-    pmode=_chooser->scheme0_list[ri-1];
-    if(_chooser->mode_counts[pmode]>=_chooser->mode_counts[_mode])break;
-    _chooser->scheme0_ranks[pmode]++;
-    _chooser->scheme0_list[ri]=pmode;
-  }
-  _chooser->scheme0_ranks[_mode]=ri;
-  _chooser->scheme0_list[ri]=_mode;
-  /*Now add the bit cost for the mode to each scheme.*/
-  for(si=0;si<8;si++){
-    _chooser->scheme_bits[si]+=
-     _chooser->mode_codes[si][_chooser->mode_ranks[si][_mode]].nbits;
-  }
-  /*Finally, re-order the list of schemes.*/
-  for(si=1;si<8;si++){
-    int sj;
-    int scheme0;
-    int bits0;
-    scheme0=_chooser->scheme_list[si];
-    bits0=_chooser->scheme_bits[scheme0];
-    sj=si;
-    do{
-      int scheme1;
-      scheme1=_chooser->scheme_list[sj-1];
-      if(bits0>=_chooser->scheme_bits[scheme1])break;
-      _chooser->scheme_list[sj]=scheme1;
-    }
-    while(--sj>0);
-    _chooser->scheme_list[sj]=scheme0;
-  }
-}
-
-/*Update the count for each mode by the given amounts, and then re-rank the
-   schemes appropriately.
-  This allows fewer (e.g. 1) updates to be done, at the cost of a more
-   expensive update.
-  _mode_counts: The amount to add to each mode count.*/
-void oc_mode_scheme_chooser_add(oc_mode_scheme_chooser *_chooser,
- int _mode_counts[OC_NMODES]){
-  int mi;
-  int mj;
-  int ri;
-  int rj;
-  int si;
-  for(mi=0;mi<OC_NMODES;mi++){
-    _chooser->mode_counts[mi]+=_mode_counts[mi];
-  }
-  /*Re-order the scheme0 mode list if necessary.*/
-  for(ri=1;ri<OC_NMODES;ri++){
-    mi=_chooser->scheme0_list[ri];
-    rj=ri;
-    do{
-      mj=_chooser->scheme0_list[rj-1];
-      if(_chooser->mode_counts[mj]>=_chooser->mode_counts[mi])break;
-      _chooser->scheme0_ranks[mj]++;
-      _chooser->scheme0_list[rj]=mj;
-    }
-    while(--rj>0);
-    _chooser->scheme0_ranks[mi]=rj;
-    _chooser->scheme0_list[rj]=mi;
-  }
-  /*Now recompute the bit cost for each scheme.*/
-  for(si=0;si<8;si++){
-    _chooser->scheme_bits[si]=0;
-    for(mi=0;mi<8;mi++){
-      _chooser->scheme_bits[si]+=
-       _chooser->mode_codes[si][_chooser->mode_ranks[si][mi]].nbits*
-        _chooser->mode_counts[mi];
-    }
-  }
-  /*Scheme 0 starts with 24 bits to store the mode list in.*/
-  _chooser->scheme_bits[0]+=24;
-  /*Finally, re-order the list of schemes.*/
-  for(si=1;si<8;si++){
-    int sj;
-    int scheme0;
-    int bits0;
-    scheme0=_chooser->scheme_list[si];
-    bits0=_chooser->scheme_bits[scheme0];
-    sj=si;
-    do{
-      int scheme1;
-      scheme1=_chooser->scheme_list[sj-1];
-      if(bits0>=_chooser->scheme_bits[scheme1])break;
-      _chooser->scheme_list[sj]=scheme1;
-    }
-    while(--sj>0);
-    _chooser->scheme_list[sj]=scheme0;
-  }
-}

Deleted: experimental/j/theora-mashup/lib/dec/encode.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/encode.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/encode.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,1529 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <ogg/ogg.h>
-#include "encint.h"
-#include "fdct.h"
-
-
-
-/*The mode orderings for the various mode coding schemes.
-  Scheme 0 uses a custom alphabet, which is not stored in this table.*/
-const int OC_MODE_SCHEMES[7][OC_NMODES]={
-  /*Last MV dominates.*/
-  /*L P M N I G GM 4*/
-  {4,3,2,0,1,7,5,6},
-  /*L P N M I G GM 4*/
-  {4,2,3,0,1,7,5,6},
-  /*L M P N I G GM 4*/
-  {4,3,1,0,2,7,5,6},
-  /*L M N P I G GM 4*/
-  {4,2,1,0,3,7,5,6},
-  /* No MV dominates.*/
-  /*N L P M I G GM 4*/
-  {4,0,3,1,2,7,5,6},
-  /*N G L P M I GM 4*/
-  {5,0,4,2,3,7,1,6},
-  /*Default ordering.*/
-  /*N I M L P G GM 4*/
-  {1,0,2,3,4,7,5,6}
-};
-
-/*The number of different DCT coefficient values that can be stored by each
-   of the different DCT value category tokens.*/
-const int OC_DCT_VAL_CAT_SIZES[6]={2,4,8,16,32,512};
-
-/*The number of bits to shift the sign of the DCT coefficient over by for each
-   of the different DCT value category tokens.*/
-const int OC_DCT_VAL_CAT_SHIFTS[6]={1,2,3,4,5,9};
-
-/*Whether or not each mode has a motion vector associated with it.
-  Otherwise, the mode is assumed to use the 0,0 vector.*/
-const int OC_MODE_HAS_MV[OC_NMODES]={0,0,1,1,1,1,0,1};
-
-/*The Huffman codes used for motion vectors.*/
-const th_huff_code OC_MV_CODES[2][63]={
-  /*Scheme 1: VLC code.*/
-  {
-             {0xFF,8},{0xFD,8},{0xFB,8},{0xF9,8},{0xF7,8},{0xF5,8},{0xF3,8},
-    {0xF1,8},{0xEF,8},{0xED,8},{0xEB,8},{0xE9,8},{0xE7,8},{0xE5,8},{0xE3,8},
-    {0xE1,8},{0x6F,7},{0x6D,7},{0x6B,7},{0x69,7},{0x67,7},{0x65,7},{0x63,7},
-    {0x61,7},{0x2F,6},{0x2D,6},{0x2B,6},{0x29,6},{0x09,4},{0x07,4},{0x02,3},
-    {0x00,3},
-    {0x01,3},{0x06,4},{0x08,4},{0x28,6},{0x2A,6},{0x2C,6},{0x2E,6},{0x60,7},
-    {0x62,7},{0x64,7},{0x66,7},{0x68,7},{0x6A,7},{0x6C,7},{0x6E,7},{0xE0,8},
-    {0xE2,8},{0xE4,8},{0xE6,8},{0xE8,8},{0xEA,8},{0xEC,8},{0xEE,8},{0xF0,8},
-    {0xF2,8},{0xF4,8},{0xF6,8},{0xF8,8},{0xFA,8},{0xFC,8},{0xFE,8}
-  },
-  /*Scheme 2: (5 bit magnitude),(1 bit sign).
-    This wastes a code word (0x01, negative zero), or a bit (0x00, positive
-     zero, requires only 5 bits to uniquely decode).*/
-  {
-             {0x3F,6},{0x3D,6},{0x3B,6},{0x39,6},{0x37,6},{0x35,6},{0x33,6},
-    {0x31,6},{0x2F,6},{0x2D,6},{0x2B,6},{0x29,6},{0x27,6},{0x25,6},{0x23,6},
-    {0x21,6},{0x1F,6},{0x1D,6},{0x1B,6},{0x19,6},{0x17,6},{0x15,6},{0x13,6},
-    {0x11,6},{0x0F,6},{0x0D,6},{0x0B,6},{0x09,6},{0x07,6},{0x05,6},{0x03,6},
-    {0x00,6},
-    {0x02,6},{0x04,6},{0x06,6},{0x08,6},{0x0A,6},{0x0C,6},{0x0E,6},{0x10,6},
-    {0x12,6},{0x14,6},{0x16,6},{0x18,6},{0x1A,6},{0x1C,6},{0x1E,6},{0x20,6},
-    {0x22,6},{0x24,6},{0x26,6},{0x28,6},{0x2A,6},{0x2C,6},{0x2E,6},{0x30,6},
-    {0x32,6},{0x34,6},{0x36,6},{0x38,6},{0x3A,6},{0x3C,6},{0x3E,6}
-  }
-};
-
-
-
-int oc_sad8_fullpel(const unsigned char *_cur,int _cur_ystride,
- const unsigned char *_ref,int _ref_ystride){
-  int i;
-  int j;
-  int err;
-  err=0;
-  for(i=0;i<8;i++){
-    for(j=0;j<8;j++)err+=abs((int)_cur[j]-_ref[j]);
-    _cur+=_cur_ystride;
-    _ref+=_ref_ystride;
-  }
-  return err;
-}
-
-int oc_sad8_fullpel_border(const unsigned char *_cur,int _cur_ystride,
- const unsigned char *_ref,int _ref_ystride,ogg_int64_t _mask){
-  int i;
-  int j;
-  int err;
-  err=0;
-  for(i=0;i<8;i++){
-    for(j=0;j<8;j++){
-      if(_mask&1)err+=abs((int)_cur[j]-_ref[j]);
-      _mask>>=1;
-    }
-    _cur+=_cur_ystride;
-    _ref+=_ref_ystride;
-  }
-  return err;
-}
-
-int oc_sad8_halfpel(const unsigned char *_cur,int _cur_ystride,
- const unsigned char *_ref0,const unsigned char *_ref1,int _ref_ystride){
-  int i;
-  int j;
-  int err;
-  err=0;
-  for(i=0;i<8;i++){
-    for(j=0;j<8;j++)err+=abs(_cur[j]-((int)_ref0[j]+_ref1[j]>>1));
-    _cur+=_cur_ystride;
-    _ref0+=_ref_ystride;
-    _ref1+=_ref_ystride;
-  }
-  return err;
-}
-
-int oc_sad8_halfpel_border(const unsigned char *_cur,int _cur_ystride,
- const unsigned char *_ref0,const unsigned char *_ref1,int _ref_ystride,
- ogg_int64_t _mask){
-  int i;
-  int j;
-  int err;
-  err=0;
-  for(i=0;i<8;i++){
-    for(j=0;j<8;j++){
-      if(_mask&1)err+=abs(_cur[j]-((int)_ref0[j]+_ref1[j])>>1);
-      _mask>>=1;
-    }
-    _cur+=_cur_ystride;
-    _ref0+=_ref_ystride;
-    _ref1+=_ref_ystride;
-  }
-  return err;
-}
-
-
-/*Writes the bit pattern for the run length of a run to the given
-   oggpack_buffer.
-  _opb:         The buffer to write to.
-  _value:       The length of the run.
-                This must be positive, and no more than the maximum value of a
-                 run that can be stored with the given prefix code.
-  _val_min:     The minimum value that can be coded in each interval, plus an
-                 extra entry for one past the last interval.
-  _code_prefix: The prefix code that is prepended to the value for
-                 each interval.
-  _code_nbits:   The total number of bits in the bit pattern encoded for each
-                 interval.
-  Return: The number of bits written.*/
-static int oc_run_pack(oggpack_buffer *_opb,int _value,const int _val_min[],
- const int _code_prefix[],const int _code_nbits[]){
-  int i;
-  for(i=0;_value>=_val_min[i+1];i++);
-  oggpackB_write(_opb,_code_prefix[i]+(_value-_val_min[i]),_code_nbits[i]);
-  return _code_nbits[i];
-}
-
-/*Writes the bit pattern for the run length of a super block run to the given
-   oggpack_buffer.
-  _opb:   The buffer to write to.
-  _value: The length of the run.
-          This must be positive, and no more than 4129.*/
-static int oc_sb_run_pack(oggpack_buffer *_opb,int _value){
-  /*Coding scheme:
-       Codeword            Run Length
-     0                       1
-     10x                     2-3
-     110x                    4-5
-     1110xx                  6-9
-     11110xxx                10-17
-     111110xxxx              18-33
-     111111xxxxxxxxxxxx      34-4129*/
-  static const int VAL_MIN[8]={1,2,4,6,10,18,34,4130};
-  static const int CODE_PREFIX[7]={0,4,0xC,0x38,0xF0,0x3E0,0x3F000};
-  static const int CODE_NBITS[7]={1,3,4,6,8,10,18};
-  return oc_run_pack(_opb,_value,VAL_MIN,CODE_PREFIX,CODE_NBITS);
-}
-
-/*Writes the bit pattern for the run length of a block run to the given
-   oggpack_buffer.
-  _opb:   The buffer to write to.
-  _value: The length of the run.
-          This must be positive, and no more than 30.*/
-static int oc_block_run_pack(oggpack_buffer *_opb,int _value){
-  /*Coding scheme:
-     Codeword             Run Length
-     0x                      1-2
-     10x                     3-4
-     110x                    5-6
-     1110xx                  7-10
-     11110xx                 11-14
-     11111xxxx               15-30*/
-  static const int VAL_MIN[7]={1,3,5,7,11,15,31};
-  static const int CODE_PREFIX[6]={0,4,0xC,0x38,0x78,0x1F0};
-  static const int CODE_NBITS[6]={2,3,4,6,7,9};
-  return oc_run_pack(_opb,_value,VAL_MIN,CODE_PREFIX,CODE_NBITS);
-}
-
-
-
-/*Initializes the macro block neighbor lists.
-  This assumes that the entire mbinfo memory region has been initialized with
-   zeros.
-  _enc: The encoding context.*/
-static void oc_enc_init_mbinfo(oc_enc_ctx *_enc){
-  oc_theora_state *state;
-  int              nmbs;
-  int              mbi;
-  state=&_enc->state;
-  /*Loop through the Y plane super blocks.*/
-  nmbs=state->nmbs;
-  for(mbi=0;mbi<nmbs;mbi++){
-    /*Because of the Hilbert curve ordering the macro blocks are
-       visited in, the available neighbors change depending on where in
-       a super block the macro block is located.
-      Only the first three vectors are used in the median calculation
-       for the optimal predictor, and so the most important should be
-       listed first.
-      Additional vectors are used, so there will always be at least 3, except
-       for in the upper-left most macro block.*/
-    /*The number of current neighbors for each macro block position.*/
-    static const int NCNEIGHBORS[4]={4,3,2,4};
-    /*The offset of each current neighbor in the X direction.*/
-    static const int CDX[4][4]={
-      {-1,0,1,-1},
-      {-1,0,-1,},
-      {-1,-1},
-      {-1,0,0,1}
-    };
-    /*The offset of each current neighbor in the Y direction.*/
-    static const int CDY[4][4]={
-      {0,-1,-1,-1},
-      {0,-1,-1},
-      {0,-1},
-      {0,-1,1,-1}
-    };
-    /*The offset of each previous neighbor in the X direction.*/
-    static const int PDX[4]={-1,0,1,0};
-    /*The offset of each previous neighbor in the Y direction.*/
-    static const int PDY[4]={0,-1,0,1};
-    oc_mb_enc_info *emb;
-    oc_mb          *mb;
-    int mbx;
-    int mby;
-    int mbn;
-    int nmbx;
-    int nmby;
-    int nmbi;
-    int i;
-    mb=state->mbs+mbi;
-    /*Make sure this macro block is within the encoded region.*/
-    if(mb->mode==OC_MODE_INVALID)continue;
-    emb=_enc->mbinfo+mbi;
-    mbn=mbi&3;
-    mbx=mb->x>>4;
-    mby=mb->y>>4;
-    /*Fill in the neighbors with current motion vectors available.*/
-    for(i=0;i<NCNEIGHBORS[mbn];i++){
-      nmbx=mbx+CDX[mbn][i];
-      nmby=mby+CDY[mbn][i];
-      if(nmbx<0||nmbx>=state->nhmbs||nmby<0||nmby>=state->nvmbs)continue;
-      nmbi=oc_state_mbi_for_pos(state,nmbx,nmby);
-      if(state->mbs[nmbi].mode==OC_MODE_INVALID)continue;
-      emb->cneighbors[emb->ncneighbors++]=nmbi;
-    }
-    /*Fill in the neighbors with previous motion vectors available.*/
-    for(i=0;i<4;i++){
-      nmbx=mbx+PDX[i];
-      nmby=mby+PDY[i];
-      if(nmbx<0||nmbx>=state->nhmbs||nmby<0||nmby>=state->nvmbs)continue;
-      nmbi=oc_state_mbi_for_pos(state,nmbx,nmby);
-      if(state->mbs[nmbi].mode==OC_MODE_INVALID)continue;
-      emb->pneighbors[emb->npneighbors++]=nmbi;
-    }
-  }
-}
-
-/*Sets the Huffman codes to use for the DCT tokens.
-  This may only be called before the setup header is written.
-  If it is called multiple times, only the last call has any effect.
-  _codes: An array of 80 Huffman tables with 32 elements each.
-          This may be NULL, in which case the default Huffman codes will be
-           used.
-  Return: 0 on success, or a negative value on error.
-          TH_EFAULT if _enc is NULL
-          TH_EINVAL if the setup header has already been written, the code is
-           not prefix free, or does not form a full binary tree.*/
-static int oc_enc_set_huffman_codes(oc_enc_ctx *_enc,
- const th_huff_code _codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS]){
-  int ret;
-  if(_enc==NULL)return TH_EFAULT;
-  if(_enc->packet_state>OC_PACKET_SETUP_HDR)return TH_EINVAL;
-  if(_codes==NULL)_codes=TH_VP31_HUFF_CODES;
-  /*Validate the codes.*/
-  oggpackB_reset(&_enc->opb);
-  ret=oc_huff_codes_pack(&_enc->opb,_codes);
-  if(ret<0)return ret;
-  memcpy(_enc->huff_codes,_codes,sizeof(_enc->huff_codes));
-  return 0;
-}
-
-/*Sets the quantization parameters to use.
-  This may only be called before the setup header is written.
-  If it is called multiple times, only the last call has any effect.
-  _qinfo: The quantization parameters.
-          These are described in more detail in theoraenc.h.
-          This can be NULL, in which case the default quantization parameters
-           will be used.*
-  Return: 0 on success, or a negative value on error.
-          TH_EFAULT if _enc is NULL.
-          TH_EINVAL if the setup header has already been written, or it cannot
-           be verified that the quantization level of for a particular qti,
-           pli, and ci never increases as qi increases.*/
-static int oc_enc_set_quant_params(th_enc_ctx *_enc,
- const th_quant_info *_qinfo){
-  int qti;
-  int pli;
-  int qri;
-  int qi;
-  int ci;
-  if(_enc==NULL)return TH_EFAULT;
-  if(_enc->packet_state>OC_PACKET_SETUP_HDR)return TH_EINVAL;
-  if(_qinfo==NULL)_qinfo=OC_DEF_QUANT_INFO+_enc->state.info.pixel_fmt;
-  /*Verify that, for a given qti, pli and ci, the actual quantizer will never
-     increase as qi increases.
-    This is required for efficient quantizer selection.*/
-  for(qi=64;qi-->1;){
-    if(_qinfo->ac_scale[qi]>_qinfo->ac_scale[qi-1])return TH_EINVAL;
-    if(_qinfo->dc_scale[qi]>_qinfo->dc_scale[qi-1])return TH_EINVAL;
-  }
-  for(qti=0;qti<2;qti++)for(pli=0;pli<3;pli++){
-    if(_qinfo->qi_ranges[qti][pli].nranges<=0)return TH_EINVAL;
-    for(qi=qri=0;qri<_qinfo->qi_ranges[qti][pli].nranges;qri++){
-      qi+=_qinfo->qi_ranges[qti][pli].sizes[qri];
-      for(ci=0;ci<64;ci++){
-        if(_qinfo->qi_ranges[qti][pli].base_matrices[qri+1][ci]>
-         _qinfo->qi_ranges[qti][pli].base_matrices[qri][ci]){
-          return TH_EINVAL;
-        }
-      }
-    }
-    if(qi!=63)return TH_EINVAL;
-  }
-  /*TODO: Analyze for packing purposes instead of just doing a shallow copy.*/
-  memcpy(&_enc->qinfo,_qinfo,sizeof(_enc->qinfo));
-  for(qti=0;qti<2;qti++)for(pli=0;pli<3;pli++){
-    _enc->state.dequant_tables[qti][pli]=
-     _enc->state.dequant_table_data[qti][pli];
-    _enc->enquant_tables[qti][pli]=_enc->enqaunt_table_data[qti][pli];
-  }
-  oc_enquant_tables_init(_enc->state.dequant_tables,_enc->enquant_tables,
-   _qinfo);
-  memcpy(_enc->state.loop_filter_limits,_qinfo->loop_filter_limits,
-   sizeof(_enc->state.loop_filter_limits));
-  return 0;
-}
-
-static void oc_enc_frame_header_pack(oc_enc_ctx *_enc){
-  /*Mark this packet as a data packet.*/
-  oggpackB_write(&_enc->opb,0,1);
-  /*Write out the frame type (I or P).*/
-  oggpackB_write(&_enc->opb,_enc->state.frame_type,1);
-  /*Write out the current qi list.*/
-  oggpackB_write(&_enc->opb,_enc->state.qis[0],6);
-  if(_enc->state.nqis>1){
-    oggpackB_write(&_enc->opb,1,1);
-    oggpackB_write(&_enc->opb,_enc->state.qis[1],6);
-    if(_enc->state.nqis>2){
-      oggpackB_write(&_enc->opb,1,1);
-      oggpackB_write(&_enc->opb,_enc->state.qis[2],6);
-    }
-    else oggpackB_write(&_enc->opb,0,1);
-  }
-  else oggpackB_write(&_enc->opb,0,1);
-  if(_enc->state.frame_type==OC_INTRA_FRAME){
-    /*Keyframes have 3 unused configuration bits, holdovers from VP3 days.
-      Most of the other unused bits in the VP3 headers were eliminated.
-      I don't know why these remain.*/
-    oggpackB_write(&_enc->opb,0,3);
-  }
-}
-
-static void oc_enc_block_qis_pack(oc_enc_ctx *_enc){
-  int *coded_fragi;
-  int *coded_fragi_end;
-  int  ncoded_fragis;
-  int  flag;
-  int  nqi0;
-  int  qii;
-  int  run_count;
-  ncoded_fragis=_enc->state.ncoded_fragis[0]+
-   _enc->state.ncoded_fragis[1]+_enc->state.ncoded_fragis[2];
-  if(_enc->state.nqis==1||ncoded_fragis<=0)return;
-  coded_fragi=_enc->state.coded_fragis;
-  coded_fragi_end=coded_fragi+ncoded_fragis;
-  flag=!!_enc->frinfo[*coded_fragi].qii;
-  oggpackB_write(&_enc->opb,flag,1);
-  nqi0=0;
-  while(coded_fragi<coded_fragi_end){
-    for(run_count=0;coded_fragi<coded_fragi_end;coded_fragi++){
-      if(!!_enc->frinfo[*coded_fragi].qii!=flag)break;
-      run_count++;
-      nqi0+=!flag;
-    }
-    while(run_count>4129){
-      oc_sb_run_pack(&_enc->opb,4129);
-      run_count-=4129;
-      oggpackB_write(&_enc->opb,flag,1);
-    }
-    oc_sb_run_pack(&_enc->opb,run_count);
-    flag=!flag;
-    if(run_count==4129&&coded_fragi<coded_fragi_end){
-      oggpackB_write(&_enc->opb,flag,1);
-    }
-  }
-  if(_enc->state.nqis!=3||nqi0>=ncoded_fragis)return;
-  coded_fragi=_enc->state.coded_fragis;
-  for(;!_enc->frinfo[*coded_fragi].qii;coded_fragi++);
-  flag=_enc->frinfo[*coded_fragi].qii-1;
-  oggpackB_write(&_enc->opb,flag,1);
-  while(coded_fragi<coded_fragi_end){
-    for(run_count=0;coded_fragi<coded_fragi_end;coded_fragi++){
-      qii=_enc->frinfo[*coded_fragi].qii;
-      if(!qii)continue;
-      if(qii-1!=flag)break;
-      run_count++;
-    }
-    while(run_count>4129){
-      oc_sb_run_pack(&_enc->opb,4129);
-      run_count-=4129;
-      oggpackB_write(&_enc->opb,flag,1);
-    }
-    oc_sb_run_pack(&_enc->opb,run_count);
-    flag=!flag;
-    if(run_count==4129&&coded_fragi<coded_fragi_end){
-      oggpackB_write(&_enc->opb,flag,1);
-    }
-  }
-}
-
-/*Performs an fDCT on a given fragment.
-  _frag:     The fragment to perform the 2D DCT on.
-  _dct_vals: The output buffer for the DCT coefficients.
-  _pli:      The color plane the fragment belongs to.*/
-static void oc_enc_frag_inter_fdct(oc_enc_ctx *_enc,const oc_fragment *_frag,
- ogg_int16_t _dct_vals[64],int _pli){
-  ogg_int16_t    pix_buf[64];
-  unsigned char *src;
-  unsigned char *ref0;
-  unsigned char *ref1;
-  int            pixi;
-  int            src_ystride;
-  int            ref_ystride;
-  int            ref_framei;
-  int            mvoffset0;
-  int            mvoffset1;
-  int            y;
-  int            x;
-  src_ystride=_enc->state.input[_pli].ystride;
-  ref_framei=_enc->state.ref_frame_idx[OC_FRAME_FOR_MODE[_frag->mbmode]];
-  ref_ystride=_enc->state.ref_frame_bufs[ref_framei][_pli].ystride;
-  src=_frag->buffer[OC_FRAME_IO];
-  if(oc_state_get_mv_offsets(&_enc->state,&mvoffset0,&mvoffset1,
-   _frag->mv[0],_frag->mv[1],ref_ystride,_pli)>1){
-    ref0=_frag->buffer[ref_framei]+mvoffset0;
-    ref1=_frag->buffer[ref_framei]+mvoffset1;
-    if(_frag->border!=NULL){
-      ogg_int64_t mask;
-      mask=_frag->border->mask;
-      for(pixi=y=0;y<8;y++){
-        for(x=0;x<8;x++,pixi++){
-          pix_buf[pixi]=(ogg_int16_t)(((int)mask&1)?
-           src[x]-((int)ref0[x]+ref1[x]>>1):0);
-          mask>>=1;
-        }
-        src+=src_ystride;
-        ref0+=ref_ystride;
-        ref1+=ref_ystride;
-      }
-      oc_fdct8x8_border(_frag->border,_dct_vals,pix_buf);
-    }
-    else{
-      for(pixi=y=0;y<8;y++){
-        for(x=0;x<8;x++,pixi++){
-          pix_buf[pixi]=(ogg_int16_t)(src[x]-((int)ref0[x]+ref1[x]>>1));
-        }
-        src+=src_ystride;
-        ref0+=ref_ystride;
-        ref1+=ref_ystride;
-      }
-      oc_fdct8x8(_dct_vals,pix_buf);
-    }
-  }
-  else{
-    ref0=_frag->buffer[ref_framei]+mvoffset0;
-    if(_frag->border!=NULL){
-      ogg_int64_t mask;
-      mask=_frag->border->mask;
-      for(pixi=y=0;y<8;y++){
-        for(x=0;x<8;x++,pixi++){
-          pix_buf[pixi]=(ogg_int16_t)(((int)mask&1)?src[x]-(int)ref0[x]:0);
-          mask>>=1;
-        }
-        src+=src_ystride;
-        ref0+=ref_ystride;
-      }
-      oc_fdct8x8_border(_frag->border,_dct_vals,pix_buf);
-    }
-    else{
-      for(pixi=y=0;y<8;y++){
-        for(x=0;x<8;x++,pixi++){
-          pix_buf[pixi]=(ogg_int16_t)(src[x]-(int)ref0[x]);
-        }
-        src+=src_ystride;
-        ref0+=ref_ystride;
-      }
-      oc_fdct8x8(_dct_vals,pix_buf);
-    }
-  }
-}
-
-/*Merge the final EOB run of each coefficient list with the start of the next,
-   if possible.
-  This assumes that dct_token_offs[0][zzi] is 0 for each zzi, and will
-   increase it as appropriate if an EOB run is merged with that of a previous
-   token index.*/
-void oc_enc_merge_eob_runs(oc_enc_ctx *_enc){
-  int    zzi;
-  for(zzi=1;zzi<64;zzi++){
-    static const int OC_EOB_RANGE[OC_NDCT_EOB_TOKEN_MAX]={1,1,1,4,8,16,4096};
-    static const int OC_EOB_OFFS[OC_NDCT_EOB_TOKEN_MAX]={1,2,3,4,8,16,0};
-    int old_tok1;
-    int old_tok2;
-    int old_eb1;
-    int old_eb2;
-    int new_tok;
-    int toki;
-    int zzj;
-    int ebi;
-    int runl;
-    /*Make sure this coefficient has tokens at all.*/
-    if(_enc->ndct_tokens[zzi]<=0)continue;
-    /*Ensure the first token is an EOB run.*/
-    old_tok2=_enc->dct_tokens[zzi][0];
-    if(old_tok2>=OC_NDCT_EOB_TOKEN_MAX)continue;
-    /*Search for a previous coefficient that has any tokens at all.*/
-    old_tok1=OC_NDCT_EOB_TOKEN_MAX;
-    zzj=zzi-1;
-    do{
-      toki=_enc->ndct_tokens[zzj]-1;
-      if(toki>=_enc->dct_token_offs[0][zzj]){
-        old_tok1=_enc->dct_tokens[zzj][toki];
-        break;
-      }
-    }
-    while(zzj-->0);
-    /*Ensure its last token was an EOB run.*/
-    if(old_tok1>=OC_NDCT_EOB_TOKEN_MAX)continue;
-    /*Pull off the associated extra bits, if any, and decode the runs.*/
-    ebi=_enc->nextra_bits[zzj];
-    old_eb1=OC_DCT_TOKEN_EXTRA_BITS[old_tok1]?_enc->extra_bits[zzj][--ebi]:0;
-    old_eb2=OC_DCT_TOKEN_EXTRA_BITS[old_tok2]?_enc->extra_bits[zzi][0]:0;
-    runl=OC_EOB_OFFS[old_tok1]+old_eb1+OC_EOB_OFFS[old_tok2]+old_eb2;
-    /*We can't possibly combine these into one run.
-      It might be possible to split them more optimally, but we'll just leave
-       them as is.*/
-    if(runl>=4096)continue;
-    /*We CAN combine them into one run.*/
-    for(new_tok=OC_DCT_EOB1_TOKEN;
-     runl-OC_EOB_OFFS[new_tok]>=OC_EOB_RANGE[new_tok];new_tok++);
-    /*toki is always initialized.
-      If your compiler thinks otherwise, it is dumb.*/
-    _enc->dct_tokens[zzj][toki]=(unsigned char)new_tok;
-    /*Update the two token lists.*/
-    if(OC_DCT_TOKEN_EXTRA_BITS[new_tok]){
-      _enc->extra_bits[zzj][ebi++]=(ogg_uint16_t)(
-       runl-OC_EOB_OFFS[new_tok]);
-    }
-    _enc->nextra_bits[zzj]=ebi;
-    _enc->dct_token_offs[0][zzi]++;
-    /*Note: We don't bother to update the offsets for planes 1 and 2 if
-       planes 0 or 1 don't have any tokens.
-      This turns out not to matter due to the way we use the offsets later.*/
-    if(OC_DCT_TOKEN_EXTRA_BITS[old_tok2])_enc->extra_bits_offs[zzi]++;
-  }
-}
-
-/*Counts the tokens of each type used for the given range of coefficient
-   indices in zig-zag order.
-  _enc: The encoding context.
-  _zzi_start:      The first zig-zag index to include.
-  _zzi_end:        The first zig-zag index to not include.
-  _token_counts_y: Returns the token counts for the Y' plane.
-  _token_counts_c: Returns the token counts for the Cb and Cr planes.*/
-static void oc_enc_count_tokens(oc_enc_ctx *_enc,int _zzi_start,int _zzi_end,
- int _token_counts_y[32],int _token_counts_c[32]){
-  int zzi;
-  int ti;
-  memset(_token_counts_y,0,sizeof(_token_counts_y[0])*32);
-  memset(_token_counts_c,0,sizeof(_token_counts_c[0])*32);
-  for(zzi=_zzi_start;zzi<_zzi_end;zzi++){
-    for(ti=_enc->dct_token_offs[0][zzi];ti<_enc->dct_token_offs[1][zzi];ti++){
-      _token_counts_y[_enc->dct_tokens[zzi][ti]]++;
-    }
-    /*Note: don't reset ti; dct_token_offs might be non-monotonic.*/
-    for(;ti<_enc->ndct_tokens[zzi];ti++){
-      _token_counts_c[_enc->dct_tokens[zzi][ti]]++;
-    }
-  }
-}
-
-/*Computes the number of bits used for each of the potential Huffman codes for
-   the given list of token counts.
-  The bits are added to whatever the current bit counts are.*/
-static void oc_enc_count_bits(oc_enc_ctx *_enc,int _hgi,const int _token_counts[32],
- int _bit_counts[16]){
-  int huffi;
-  int huff_base;
-  int token;
-  huff_base=_hgi<<4;
-  for(huffi=huff_base;huffi<huff_base+16;huffi++){
-    for(token=0;token<32;token++){
-      _bit_counts[huffi-huff_base]+=
-       _token_counts[token]*_enc->huff_codes[huffi][token].nbits;
-    }
-  }
-}
-
-/*Returns the Huffman index using the fewest number of bits.*/
-static int oc_enc_select_huffi(int _bit_counts[16]){
-  int best_huffi;
-  int huffi;
-  best_huffi=0;
-  for(huffi=1;huffi<16;huffi++)if(_bit_counts[huffi]<_bit_counts[best_huffi]){
-    best_huffi=huffi;
-  }
-  return best_huffi;
-}
-
-/*Packs the DCT tokens for the given range of coefficient indices in zig-zag
-   order using the given Huffman tables.*/
-static void oc_enc_huff_group_pack(oc_enc_ctx *_enc,int _zzi_start,
- int _zzi_end,int _huff_idxs[3]){
-  int zzi;
-  for(zzi=_zzi_start;zzi<_zzi_end;zzi++){
-    int pli;
-    int ti;
-    int ebi;
-    ti=_enc->dct_token_offs[0][zzi];
-    ebi=_enc->extra_bits_offs[zzi];
-    for(pli=0;pli<3;pli++){
-      const th_huff_code *huff_codes;
-      int                     token;
-      int                     ti_end;
-      /*Step 2: Write the tokens using these tables.*/
-      huff_codes=_enc->huff_codes[_huff_idxs[pli]];
-      /*Note: dct_token_offs[3] is really the ndct_tokens table.
-        Yes, this seems like a horrible hack, yet it's strangely elegant.*/
-      ti_end=_enc->dct_token_offs[pli+1][zzi];
-      /*Note: don't reset ti; dct_token_offs might be non-monotonic.*/
-      for(;ti<ti_end;ti++){
-        token=_enc->dct_tokens[zzi][ti];
-        oggpackB_write(&_enc->opb,huff_codes[token].pattern,
-         huff_codes[token].nbits);
-        if(OC_DCT_TOKEN_EXTRA_BITS[token]){
-          oggpackB_write(&_enc->opb,_enc->extra_bits[zzi][ebi++],
-           OC_DCT_TOKEN_EXTRA_BITS[token]);
-        }
-      }
-    }
-  }
-}
-
-static void oc_enc_residual_tokens_pack(oc_enc_ctx *_enc){
-  static const int OC_HUFF_LIST_MIN[5]={0,1,6,15,28};
-  static const int OC_HUFF_LIST_MAX[5]={1,6,15,28,64};
-  int bits_y[16];
-  int bits_c[16];
-  int token_counts_y[32];
-  int token_counts_c[32];
-  int huff_idxs[5][3];
-  int huffi_y;
-  int huffi_c;
-  int hgi;
-  /*Step 1a: Select Huffman tables for the DC token list.*/
-  memset(bits_y,0,sizeof(bits_y));
-  memset(bits_c,0,sizeof(bits_c));
-  oc_enc_count_tokens(_enc,0,1,token_counts_y,token_counts_c);
-  oc_enc_count_bits(_enc,0,token_counts_y,bits_y);
-  oc_enc_count_bits(_enc,0,token_counts_c,bits_c);
-  huffi_y=oc_enc_select_huffi(bits_y);
-  huffi_c=oc_enc_select_huffi(bits_c);
-  huff_idxs[0][0]=huffi_y;
-  huff_idxs[0][1]=huff_idxs[0][2]=huffi_c;
-  /*Step 1b: Write the DC token list with the chosen tables.*/
-  oggpackB_write(&_enc->opb,huffi_y,4);
-  oggpackB_write(&_enc->opb,huffi_c,4);
-  oc_enc_huff_group_pack(_enc,0,1,huff_idxs[0]);
-  /*Step 2a: Select Huffman tables for the AC token lists.*/
-  memset(bits_y,0,sizeof(bits_y));
-  memset(bits_y,0,sizeof(bits_c));
-  for(hgi=1;hgi<5;hgi++){
-    oc_enc_count_tokens(_enc,OC_HUFF_LIST_MIN[hgi],OC_HUFF_LIST_MAX[hgi],
-     token_counts_y,token_counts_c);
-    oc_enc_count_bits(_enc,hgi,token_counts_y,bits_y);
-    oc_enc_count_bits(_enc,hgi,token_counts_c,bits_c);
-  }
-  huffi_y=oc_enc_select_huffi(bits_y);
-  huffi_c=oc_enc_select_huffi(bits_c);
-  /*Step 2b: Write the AC token lists using the chosen tables.*/
-  oggpackB_write(&_enc->opb,huffi_y,4);
-  oggpackB_write(&_enc->opb,huffi_c,4);
-  for(hgi=1;hgi<5;hgi++){
-    huff_idxs[hgi][0]=huffi_y+(hgi<<4);
-    huff_idxs[hgi][1]=huff_idxs[hgi][2]=huffi_c+(hgi<<4);
-    oc_enc_huff_group_pack(_enc,OC_HUFF_LIST_MIN[hgi],OC_HUFF_LIST_MAX[hgi],
-     huff_idxs[hgi]);
-  }
-#if defined(OC_BITRATE_STATS)
-  oc_bitrate_update_stats(_enc,huff_idxs);
-#endif
-}
-
-
-static void oc_enc_mb_modes_pack(oc_enc_ctx *_enc){
-  const th_huff_code *codes;
-  const int              *mode_ranks;
-  int                    *coded_mbi;
-  int                    *coded_mbi_end;
-  int                     scheme;
-  scheme=_enc->mode_scheme_chooser.scheme_list[0];
-  oggpackB_write(&_enc->opb,scheme,3);
-  if(scheme==0){
-    int ranks[8];
-    int mi;
-    /*The numbers associated with each mode in the stream are slightly
-       different than what we use in the source.
-      The lookup here converts between the two.*/
-    for(mi=0;mi<OC_NMODES;mi++){
-      ranks[OC_MODE_SCHEMES[6][mi]]=
-       _enc->mode_scheme_chooser.scheme0_ranks[mi];
-    }
-    for(mi=0;mi<OC_NMODES;mi++)oggpackB_write(&_enc->opb,ranks[mi],3);
-  }
-  codes=_enc->mode_scheme_chooser.mode_codes[scheme];
-  mode_ranks=_enc->mode_scheme_chooser.mode_ranks[scheme];
-  coded_mbi=_enc->state.coded_mbis;
-  coded_mbi_end=coded_mbi+_enc->state.ncoded_mbis;
-  for(;coded_mbi<coded_mbi_end;coded_mbi++){
-    const th_huff_code *code;
-    oc_mb                  *mb;
-    mb=_enc->state.mbs+*coded_mbi;
-    code=codes+mode_ranks[mb->mode];
-    oggpackB_write(&_enc->opb,code->pattern,code->nbits);
-  }
-}
-
-static void oc_enc_mv_pack(oc_enc_ctx *_enc,int _dx,int _dy){
-  const th_huff_code *code;
-  code=OC_MV_CODES[_enc->mv_scheme]+_dx+31;
-  oggpackB_write(&_enc->opb,code->pattern,code->nbits);
-  code=OC_MV_CODES[_enc->mv_scheme]+_dy+31;
-  oggpackB_write(&_enc->opb,code->pattern,code->nbits);
-}
-
-static void oc_enc_mvs_pack(oc_enc_ctx *_enc){
-  int *coded_mbi;
-  int *coded_mbi_end;
-  oggpackB_write(&_enc->opb,_enc->mv_scheme,1);
-  coded_mbi=_enc->state.coded_mbis;
-  coded_mbi_end=coded_mbi+_enc->state.ncoded_mbis;
-  for(;coded_mbi<coded_mbi_end;coded_mbi++){
-    oc_mb          *mb;
-    oc_mb_enc_info *mbinfo;
-    int             mbi;
-    mbi=*coded_mbi;
-    mb=_enc->state.mbs+mbi;
-    switch(mb->mode){
-      case OC_MODE_INTER_MV:
-      case OC_MODE_GOLDEN_MV:{
-        int which_frame;
-        which_frame=OC_FRAME_FOR_MODE[mb->mode];
-        mbinfo=_enc->mbinfo+mbi;
-        oc_enc_mv_pack(_enc,mbinfo->mvs[0][which_frame][0],
-         mbinfo->mvs[0][which_frame][1]);
-      }break;
-      case OC_MODE_INTER_MV_FOUR:{
-        int bi;
-        mbinfo=_enc->mbinfo+mbi;
-        for(bi=0;bi<4;bi++){
-          int fragi;
-          fragi=mb->map[0][bi];
-          if(fragi>=0&&_enc->state.frags[fragi].coded){
-            oc_enc_mv_pack(_enc,mbinfo->bmvs[bi][0],mbinfo->bmvs[bi][1]);
-          }
-        }
-      }break;
-    }
-  }
-}
-
-static void oc_enc_enable_default_mode(oc_enc_ctx *_enc){
-  /*TODO: Right now we always use VBR mode.
-    When a CBR mode is available, we should use that by default if the user
-     specifies a bitrate, but not a quality, in the th_info struct.*/
-  if(_enc->vbr==NULL)_enc->vbr=oc_enc_vbr_alloc(_enc);
-  oc_enc_vbr_enable(_enc->vbr,NULL);
-}
-
-/*A pipeline stage for copying uncoded fragments.*/
-
-static int oc_copy_pipe_start(oc_enc_pipe_stage *_stage){
-  int pli;
-  for(pli=0;pli<3;pli++){
-    _stage->y_procd[pli]=0;
-    _stage->enc->uncoded_fragii[pli]=0;
-  }
-  return _stage->next!=NULL?(*_stage->next->pipe_start)(_stage->next):0;
-}
-
-static int oc_copy_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  int        *uncoded_fragis;
-  oc_enc_ctx *enc;
-  int         pli;
-  enc=_stage->enc;
-  uncoded_fragis=enc->state.uncoded_fragis;
-  for(pli=0;pli<3;pli++){
-    int y_avail;
-    y_avail=_y_avail[pli];
-    /*Process in units of super block rows, with the possible exception of the
-       last, partial super block row.*/
-    if(y_avail<enc->state.input[pli].height)y_avail&=~31;
-    if(y_avail>_stage->y_procd[pli]){
-      if(enc->uncoded_fragii[pli]<enc->state.nuncoded_fragis[pli]){
-        oc_fragment_plane *fplane;
-        int                fragi_end;
-        int                fragii;
-        fplane=enc->state.fplanes+pli;
-        fragi_end=(y_avail>>3)*fplane->nhfrags+fplane->froffset;
-        /*Count the uncoded fragments that belong in these super block rows.*/
-        for(fragii=enc->uncoded_fragii[pli];
-         fragii<enc->state.nuncoded_fragis[pli]&&
-         *(uncoded_fragis-fragii)<fragi_end;fragii++);
-        /*And copy them.*/
-        oc_state_frag_copy(&enc->state,uncoded_fragis-fragii,
-         fragii-enc->uncoded_fragii[pli],OC_FRAME_SELF,OC_FRAME_PREV,pli);
-        enc->uncoded_fragii[pli]=fragii;
-      }
-      _stage->y_procd[pli]=y_avail;
-      if(_stage->next!=NULL){
-        int ret;
-        ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-        if(ret<0)return ret;
-      }
-    }
-    uncoded_fragis-=enc->state.nuncoded_fragis[pli];
-  }
-  return 0;
-}
-
-static int oc_copy_pipe_end(oc_enc_pipe_stage *_stage){
-  return _stage->next!=NULL?(*_stage->next->pipe_end)(_stage->next):0;
-}
-
-/*Initialize the uncoded fragment copying stage of the pipeline.
-  _enc: The encoding context.*/
-static void oc_copy_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_copy_pipe_start;
-  _stage->pipe_proc=oc_copy_pipe_process;
-  _stage->pipe_end=oc_copy_pipe_end;
-}
-
-/*A pipeline stage for applying the loop filter.*/
-
-static int oc_loop_pipe_start(oc_enc_pipe_stage *_stage){
-  oc_enc_ctx *enc;
-  int         pli;
-  enc=_stage->enc;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=0;
-  enc->loop_filter_enabled=enc->ncoded_frags>0&&
-   !oc_state_loop_filter_init(&enc->state,enc->bounding_values+256);
-  return _stage->next!=NULL?(*_stage->next->pipe_start)(_stage->next):0;
-}
-
-static int oc_loop_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  oc_enc_ctx *enc;
-  int         pli;
-  enc=_stage->enc;
-  if(enc->loop_filter_enabled){
-    int refi;
-    refi=enc->state.ref_frame_idx[OC_FRAME_SELF];
-    for(pli=0;pli<3;pli++){
-      int delay;
-      int fragy0;
-      int fragy_end;
-      fragy0=_stage->y_procd[pli]+1>>3;
-      /*Add a 2 pixel delay for the vertical filter, except in the last row.*/
-      delay=(_y_avail[pli]<enc->state.ref_frame_bufs[refi][pli].height);
-      fragy_end=_y_avail[pli]-(delay<<1)>>3;
-      if(fragy_end>fragy0){
-        oc_state_loop_filter_frag_rows(&enc->state,enc->bounding_values+256,
-         refi,pli,fragy0,fragy_end);
-        /*We also add a 1 pixel delay to the next stage, since the vertical
-           filter for the next fragment row can still change the last row of
-           pixels from this fragment row.*/
-        _stage->y_procd[pli]=(fragy_end<<3)-delay;
-        if(_stage->next!=NULL){
-          int ret;
-          ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-          if(ret<0)return ret;
-        }
-      }
-    }
-  }
-  else{
-    for(pli=0;pli<3;pli++)_stage->y_procd[pli]=_y_avail[pli];
-    if(_stage->next!=NULL){
-      return (*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-    }
-  }
-  return 0;
-}
-
-static int oc_loop_pipe_end(oc_enc_pipe_stage *_stage){
-  return _stage->next!=NULL?(*_stage->next->pipe_end)(_stage->next):0;
-}
-
-/*Initialize the loop filter stage of the pipeline.
-  _enc: The encoding context.*/
-static void oc_loop_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_loop_pipe_start;
-  _stage->pipe_proc=oc_loop_pipe_process;
-  _stage->pipe_end=oc_loop_pipe_end;
-}
-
-/*A pipeline stage for filling in the image border.*/
-
-static int oc_fill_pipe_start(oc_enc_pipe_stage *_stage){
-  int pli;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=0;
-  return _stage->next!=NULL?(*_stage->next->pipe_start)(_stage->next):0;
-}
-
-static int oc_fill_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  int pli;
-  if(_stage->enc->ncoded_frags>0){
-    oc_theora_state *state;
-    int              refi;
-    state=&_stage->enc->state;
-    refi=state->ref_frame_idx[OC_FRAME_SELF];
-    for(pli=0;pli<3;pli++){
-      if(_stage->y_procd[pli]<_y_avail[pli]){
-        oc_state_borders_fill_rows(state,refi,pli,_stage->y_procd[pli],
-         _y_avail[pli]);
-        _stage->y_procd[pli]=_y_avail[pli];
-        if(_stage->next!=NULL){
-          int ret;
-          ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-          if(ret<0)return ret;
-        }
-      }
-    }
-  }
-  else{
-    for(pli=0;pli<3;pli++)_stage->y_procd[pli]=_y_avail[pli];
-    if(_stage->next!=NULL){
-      return (*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-    }
-  }
-  return 0;
-}
-
-static int oc_fill_pipe_end(oc_enc_pipe_stage *_stage){
-  oc_theora_state *state;
-  int              refi;
-  int              pli;
-  state=&_stage->enc->state;
-  refi=state->ref_frame_idx[OC_FRAME_SELF];
-  for(pli=0;pli<3;pli++)oc_state_borders_fill_caps(state,refi,pli);
-  return _stage->next!=NULL?(*_stage->next->pipe_end)(_stage->next):0;
-}
-
-/*Initialize the loop filter stage of the pipeline.
-  _enc: The encoding context.*/
-static void oc_fill_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_fill_pipe_start;
-  _stage->pipe_proc=oc_fill_pipe_process;
-  _stage->pipe_end=oc_fill_pipe_end;
-}
-
-/*A pipeline stage for storing the encoded frame contents in a packet.*/
-
-static int oc_pack_pipe_start(oc_enc_pipe_stage *_stage){
-  int pli;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=0;
-  return 0;
-}
-
-static int oc_pack_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  int pli;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=_y_avail[pli];
-  return 0;
-}
-
-static int oc_pack_pipe_end(oc_enc_pipe_stage *_stage){
-  oc_enc_ctx *enc;
-  int         ret;
-  if(_stage->next!=NULL){
-    ret=(*_stage->next->pipe_start)(_stage->next);
-    if(ret<0)return ret;
-  }
-  enc=_stage->enc;
-  oggpackB_reset(&enc->opb);
-  /*Only proceed if we have some coded blocks.
-    No coded blocks -> dropped frame -> 0 byte packet.*/
-  if(enc->ncoded_frags>0){
-    oc_enc_frame_header_pack(enc);
-    if(enc->state.frame_type==OC_INTER_FRAME){
-      oggpackB_writecopy(&enc->opb,
-       oggpackB_get_buffer(&enc->opb_coded_flags),
-       oggpackB_bits(&enc->opb_coded_flags));
-      oc_enc_mb_modes_pack(enc);
-      oc_enc_mvs_pack(enc);
-    }
-    oc_enc_block_qis_pack(enc);
-    /*Pack the quantized DCT coefficients.*/
-    oc_enc_residual_tokens_pack(enc);
-  }
-  /*Success: Mark the packet as ready to be flushed.*/
-  enc->packet_state=OC_PACKET_READY;
-  if(_stage->next!=NULL){
-    ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-    if(ret<0)return ret;
-    return (*_stage->next->pipe_end)(_stage->next);
-  }
-  return 0;
-}
-
-/*Initialize the loop filter stage of the pipeline.
-  _enc: The encoding context.*/
-static void oc_pack_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_pack_pipe_start;
-  _stage->pipe_proc=oc_pack_pipe_process;
-  _stage->pipe_end=oc_pack_pipe_end;
-}
-
-
-static int oc_enc_init(oc_enc_ctx *_enc,const th_info *_info){
-  int ret;
-  /*Initialize the shared encoder/decoder state.*/
-  ret=oc_state_init(&_enc->state,_info);
-  if(ret<0)return ret;
-  _enc->block_coded_flags=_ogg_calloc(_enc->state.nfrags,
-   sizeof(_enc->block_coded_flags[0]));
-  /*Initialize our packet buffers.*/
-  oggpackB_writeinit(&_enc->opb);
-  oggpackB_writeinit(&_enc->opb_coded_flags);
-  /*Allocate and initialize storage for encoder-specific fragment and macro
-     block storage, as well as DCT token storage.*/
-  _enc->frinfo=_ogg_calloc(_enc->state.nfrags,
-   sizeof(_enc->frinfo[0]));
-  _enc->mbinfo=_ogg_calloc(_enc->state.nmbs,sizeof(_enc->mbinfo[0]));
-  _enc->dct_tokens=(unsigned char **)oc_malloc_2d(64,
-   _enc->state.nfrags,sizeof(_enc->dct_tokens[0][0]));
-  _enc->extra_bits=(ogg_uint16_t **)oc_malloc_2d(64,
-   _enc->state.nfrags,sizeof(_enc->extra_bits[0][0]));
-  oc_enc_init_mbinfo(_enc);
-  /*Do one-time mode scheme chooser initialization.*/
-  oc_mode_scheme_chooser_init(&_enc->mode_scheme_chooser);
-  /*Set the maximum distance between key frames.*/
-  _enc->keyframe_frequency_force=1<<_enc->state.info.keyframe_granule_shift;
-  /*Initialize the motion compensation, high-level importance map, and
-     low-level psychovisual model plug-ins.*/
-  _enc->mcenc=oc_mcenc_alloc(_enc);
-  /*Reset the packet-out state machine.*/
-  _enc->packet_state=OC_PACKET_INFO_HDR;
-  /*Mark us as not VP3-compatible.*/
-  _enc->vp3_compatible=0;
-  /*Set the Huffman codes and quantization parameters to the defaults.*/
-  memcpy(_enc->huff_codes,TH_VP31_HUFF_CODES,sizeof(_enc->huff_codes));
-  oc_enc_set_quant_params(_enc,NULL);
-  /*Initialize the static pipeline stages.*/
-  oc_fdct_pipe_init(&_enc->fdct_pipe,_enc);
-  oc_copy_pipe_init(&_enc->copy_pipe,_enc);
-  oc_loop_pipe_init(&_enc->loop_pipe,_enc);
-  _enc->copy_pipe.next=&_enc->loop_pipe;
-  oc_fill_pipe_init(&_enc->fill_pipe,_enc);
-  _enc->loop_pipe.next=&_enc->fill_pipe;
-  oc_pack_pipe_init(&_enc->pack_pipe,_enc);
-  /*Delay initialization of the encoding pipeline until the application sets
-     an encoding mode or the first frame is submitted.*/
-  _enc->pipe=NULL;
-  _enc->vbr=NULL;
-  return 0;
-}
-
-static void oc_enc_clear(oc_enc_ctx *_enc){
-  oc_enc_vbr_free(_enc->vbr);
-  oc_mcenc_free(_enc->mcenc);
-  oc_free_2d(_enc->extra_bits);
-  oc_free_2d(_enc->dct_tokens);
-  _ogg_free(_enc->mbinfo);
-  _ogg_free(_enc->frinfo);
-  _ogg_free(_enc->block_coded_flags);
-  oc_state_clear(&_enc->state);
-}
-
-
-
-/*A default implementation of set_speed, to use when the encoding mode is not
-   configurable.
-  It does nothing.
-  _speed: The encoding speed to use.*/
-void oc_enc_set_speed_null(oc_enc_ctx *_enc,int _speed){}
-
-/*Computes the SAD value of a fragment in the input image with respect to its
-   motion compensated predictor..
-  _frag:     The fragment to find the SAD of.
-  _dx:       The X component of the motion vector.
-  _dy:       The Y component of the motion vector.
-  _pli:      The color plane the fragment belongs to.
-  _frame:    The reference frame to predict from.*/
-int oc_enc_frag_sad(oc_enc_ctx *_enc,oc_fragment *_frag,int _dx,
- int _dy,int _pli,int _frame){
-  int cur_ystride;
-  int ref_ystride;
-  int ref_framei;
-  int mvoffset0;
-  int mvoffset1;
-  cur_ystride=_enc->state.input[_pli].ystride;
-  ref_framei=_enc->state.ref_frame_idx[_frame];
-  ref_ystride=_enc->state.ref_frame_bufs[ref_framei][_pli].ystride;
-  if(oc_state_get_mv_offsets(&_enc->state,&mvoffset0,&mvoffset1,_dx,_dy,
-   ref_ystride,_pli)>1){
-    if(_frag->border==NULL){
-      return oc_sad8_halfpel(_frag->buffer[OC_FRAME_IO],cur_ystride,
-       _frag->buffer[ref_framei]+mvoffset0,
-       _frag->buffer[ref_framei]+mvoffset1,ref_ystride);
-    }
-    else{
-      return oc_sad8_halfpel_border(_frag->buffer[OC_FRAME_IO],cur_ystride,
-       _frag->buffer[ref_framei]+mvoffset0,
-       _frag->buffer[ref_framei]+mvoffset1,ref_ystride,_frag->border->mask);
-    }
-  }
-  else{
-    if(_frag->border==NULL){
-      return oc_sad8_fullpel(_frag->buffer[OC_FRAME_IO],cur_ystride,
-       _frag->buffer[ref_framei]+mvoffset0,ref_ystride);
-    }
-    else{
-      return oc_sad8_fullpel_border(_frag->buffer[OC_FRAME_IO],
-       cur_ystride,_frag->buffer[ref_framei]+mvoffset0,ref_ystride,
-       _frag->border->mask);
-    }
-  }
-}
-
-/*Writes the bit flags for whether or not each super block is partially coded
-   or not.
-  These flags are run-length encoded, with the flag value alternating between
-   each run.
-  Return: The number of bits written.*/
-int oc_enc_partial_sb_flags_pack(oc_enc_ctx *_enc,oggpack_buffer *_opb){
-  oc_sb    *sb;
-  oc_sb    *sb_end;
-  unsigned  flag;
-  int       run_count;
-  int       ret;
-  /*Write the list of partially coded super block flags.*/
-  flag=_enc->state.sbs[0].coded_partially;
-  oggpackB_write(_opb,flag,1);
-  ret=1;
-  sb=_enc->state.sbs;
-  sb_end=sb+_enc->state.nsbs;
-  while(sb<sb_end){
-    for(run_count=0;sb<sb_end;sb++){
-      if(sb->coded_partially!=flag)break;
-      run_count++;
-    }
-    /*The maximum run length we can encode is 4129.
-      If we encode a run that long, we need to specify the bit value for the
-       next run instead of being able to implicitly toggle it.
-      Note that the original VP3 implementation did not consider this case,
-       and would not write the extra bit for runs of 4129, and would write an
-       invalid code for longer runs.*/
-    /*First, encode runs until we have 4129 or fewer sbs left.*/
-    while(run_count>4129){
-      ret+=oc_sb_run_pack(_opb,4129);
-      run_count-=4129;
-      oggpackB_write(_opb,flag,1);
-      ret++;
-    }
-    /*Encode the last run.*/
-    ret+=oc_sb_run_pack(_opb,run_count);
-    flag=!flag;
-    /*If there are more sbs to come, and we had a run of 4129 exactly,
-       encode the flipped bit.*/
-    if(run_count==4129&&sb<sb_end){
-      oggpackB_write(_opb,flag,1);
-      ret++;
-    }
-  }
-  return ret;
-}
-
-/*Writes the coded/not coded flags for each super block that is not partially
-   coded.
-  These flags are run-length encoded, with the flag value altenating between
-   each run.
-  Return: The number of bits written.*/
-int oc_enc_coded_sb_flags_pack(oc_enc_ctx *_enc,oggpack_buffer *_opb){
-  oc_sb    *sb;
-  oc_sb    *sb_end;
-  unsigned  flag;
-  int       run_count;
-  int       ret;
-  /*Write the list of coded/not coded super block flags.*/
-  /*Skip partially coded super blocks: their flags have already been coded.*/
-  sb=_enc->state.sbs;
-  sb_end=sb+_enc->state.nsbs;
-  for(;;sb++){
-    if(sb>=sb_end)return 0;
-    if(!sb->coded_partially)break;
-  }
-  flag=sb->coded_fully;
-  oggpackB_write(_opb,flag,1);
-  ret=1;
-  while(sb<sb_end){
-    for(run_count=0;sb<sb_end;sb++){
-      if(sb->coded_partially)continue;
-      if(sb->coded_fully!=flag)break;
-      run_count++;
-    }
-    /*The maximum run length we can encode is 4129.
-      If we encode a run that long, we need to specify the bit value for the
-       next run instead of being able to implicitly toggle it.
-      Note that the original VP3 implementation did not consider this case,
-       and would not write the extra bit for runs of 4129, and would write an
-       invalid code for longer runs.*/
-    /*First, encode runs until we have 4129 or fewer sbs left.*/
-    while(run_count>4129){
-      ret+=oc_sb_run_pack(_opb,4129);
-      run_count-=4129;
-      oggpackB_write(_opb,flag,1);
-      ret++;
-    }
-    /*Encode the last run.*/
-    ret+=oc_sb_run_pack(_opb,run_count);
-    flag=!flag;
-    if(run_count==4129&&sb<sb_end){
-      oggpackB_write(_opb,flag,1);
-      ret++;
-    }
-  }
-  return ret;
-}
-
-/*Writes the coded/not coded flags for each block belonging to a partially
-   coded super block.
-  These flags are run-length encoded, with the flag value alternating between
-   each run.
-  Return: The number of bits written.*/
-int oc_enc_coded_block_flags_pack(oc_enc_ctx *_enc,oggpack_buffer *_opb){
-  int flag;
-  int run_count;
-  int bli;
-  int ret;
-  if(_enc->nblock_coded_flags<=0)return 0;
-  flag=_enc->block_coded_flags[0];
-  oggpackB_write(_opb,flag,1);
-  ret=1;
-  for(bli=0;bli<_enc->nblock_coded_flags;){
-    for(run_count=0;bli<_enc->nblock_coded_flags;bli++){
-      if(_enc->block_coded_flags[bli]!=flag)break;
-      run_count++;
-    }
-    /*Since each super block must have a mix of coded and not coded blocks to
-       get on this list, we are guaranteed a maximum run size of 30 (16 blocks
-       per super block, with flags (1000 0000 0000 0000, 0000 0000 0000 0001)
-       or its complement).
-      This avoids the nastiness of the VLC not letting us encode runs long
-       enough like above.*/
-    ret+=oc_block_run_pack(_opb,run_count);
-    flag=!flag;
-  }
-  return ret;
-}
-
-/*Performs a motion-compensated fDCT for each fragment coded in a mode other
-   than INTRA.*/
-void oc_enc_do_inter_dcts(oc_enc_ctx *_enc){
-  int *coded_fragi;
-  int *coded_fragi_end;
-  int  pli;
-  coded_fragi_end=coded_fragi=_enc->state.coded_fragis;
-  for(pli=0;pli<3;pli++){
-    coded_fragi_end+=_enc->state.ncoded_fragis[pli];
-    for(;coded_fragi<coded_fragi_end;coded_fragi++){
-      oc_fragment *frag;
-      frag=_enc->state.frags+*coded_fragi;
-      if(frag->mbmode!=OC_MODE_INTRA){
-        oc_fragment_enc_info *efrag;
-        efrag=_enc->frinfo+(frag-_enc->state.frags);
-        oc_enc_frag_inter_fdct(_enc,frag,efrag->dct_coeffs,pli);
-      }
-    }
-  }
-}
-
-
-th_enc_ctx *th_encode_alloc(const th_info *_info){
-  oc_enc_ctx *enc;
-  if(_info==NULL)return NULL;
-  enc=_ogg_malloc(sizeof(*enc));
-  if(oc_enc_init(enc,_info)<0){
-    _ogg_free(enc);
-    return NULL;
-  }
-  return enc;
-}
-
-void th_encode_free(th_enc_ctx *_enc){
-  if(_enc!=NULL){
-    oc_enc_clear(_enc);
-    _ogg_free(_enc);
-  }
-}
-
-
-
-typedef th_huff_code theora_huff_table[TH_NDCT_TOKENS];
-
-int th_encode_ctl(th_enc_ctx *_enc,int _req,void *_buf,
- size_t _buf_sz){
-  switch(_req){
-    case TH_ENCCTL_SET_HUFFMAN_CODES:{
-      if(_buf==NULL&&_buf_sz!=0||_buf!=NULL&&
-       _buf_sz!=sizeof(th_huff_code)*TH_NHUFFMAN_TABLES*TH_NDCT_TOKENS){
-        return TH_EINVAL;
-      }
-      return oc_enc_set_huffman_codes(_enc,(theora_huff_table *)_buf);
-    }break;
-    case TH_ENCCTL_SET_QUANT_PARAMS:{
-      if(_buf==NULL&&_buf_sz!=0||
-       _buf!=NULL&&_buf_sz!=sizeof(th_quant_info)){
-        return TH_EINVAL;
-      }
-      return oc_enc_set_quant_params(_enc,(th_quant_info *)_buf);
-    }break;
-    case TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE:{
-      ogg_uint32_t keyframe_frequency_force;
-      if(_enc==NULL||_buf==NULL)return TH_EFAULT;
-      if(_buf_sz!=sizeof(ogg_uint32_t))return TH_EINVAL;
-      keyframe_frequency_force=*(ogg_uint32_t *)_buf;
-      if(_enc->packet_state==OC_PACKET_INFO_HDR){
-        /*It's still early enough to enlarge keyframe_granule_shift.*/
-        _enc->state.info.keyframe_granule_shift=
-         OC_MAXI(_enc->state.info.keyframe_granule_shift,
-         OC_MINI(31,oc_ilog(keyframe_frequency_force-1)));
-      }
-      _enc->keyframe_frequency_force=OC_MINI(keyframe_frequency_force,
-       1U<<_enc->state.info.keyframe_granule_shift);
-      *(ogg_uint32_t *)_buf=_enc->keyframe_frequency_force;
-      return 0;
-    }break;
-    case TH_ENCCTL_SET_VP3_COMPATIBLE:{
-      int vp3_compatible;
-      int ret;
-      if(_enc==NULL||_buf==NULL)return TH_EFAULT;
-      if(_buf_sz!=sizeof(int))return TH_EINVAL;
-      vp3_compatible=*(int *)_buf;
-      _enc->vp3_compatible=vp3_compatible;
-      ret=oc_enc_set_huffman_codes(_enc,TH_VP31_HUFF_CODES);
-      if(ret<0)vp3_compatible=0;
-      ret=oc_enc_set_quant_params(_enc,&TH_VP31_QUANT_INFO);
-      if(ret<0)vp3_compatible=0;
-      if(_enc->state.info.pixel_fmt!=TH_PF_420||
-       _enc->state.info.pic_width<_enc->state.info.frame_width||
-       _enc->state.info.pic_height<_enc->state.info.frame_height||
-      /*If we have more than 4095 super blocks, VP3's RLE coding might
-         overflow.
-        We could overcome this by ensuring we flip the coded/not-coded flags on
-         at least one super block in the frame, but we pick the simple solution
-         of just marking the stream incompatible instead.
-        It's unlikely the old VP3 codec would be able to decode streams at this
-         resolution in real time in the first place.*/
-       _enc->state.nsbs>4095){
-        vp3_compatible=0;
-      }
-      *(int *)_buf=vp3_compatible;
-      return 0;
-    }break;
-    case TH_ENCCTL_GET_SPLEVEL_MAX:{
-      if(_enc==NULL||_buf==NULL)return TH_EFAULT;
-      if(_buf_sz!=sizeof(int))return TH_EINVAL;
-      /*We can only manipulate speed in the context of a given encoding mode.
-        Ensure one is selected if the user has not already done so.*/
-      if(_enc->set_speed==NULL)oc_enc_enable_default_mode(_enc);
-      *(int *)_buf=_enc->speed_max;
-      return 0;
-    }break;
-    case TH_ENCCTL_SET_SPLEVEL:{
-      int speed;
-      if(_enc==NULL||_buf==NULL)return TH_EFAULT;
-      if(_buf_sz!=sizeof(int))return TH_EINVAL;
-      speed=*(int *)_buf;
-      /*We can only manipulate speed in the context of a given encoding mode.
-        Ensure one is selected if the user has not already done so.*/
-      if(_enc->set_speed==NULL)oc_enc_enable_default_mode(_enc);
-      if(speed<0||speed>_enc->speed_max)return TH_EINVAL;
-      (*_enc->set_speed)(_enc,speed);
-      return 0;
-    }break;
-    case TH_ENCCTL_SETUP_VBR:{
-      if(_enc==NULL)return TH_EFAULT;
-      if(_buf==NULL&&_buf_sz!=0||_buf!=NULL&&_buf_sz!=sizeof(th_vbr_cfg)){
-        return TH_EINVAL;
-      }
-      if(_enc->vbr==NULL)_enc->vbr=oc_enc_vbr_alloc(_enc);
-      return oc_enc_vbr_enable(_enc->vbr,(th_vbr_cfg *)_buf);
-    }break;
-    default:return TH_EIMPL;
-  }
-}
-
-int th_encode_ycbcr_in(th_enc_ctx *_enc,th_ycbcr_buffer _img){
-  th_ycbcr_buffer img;
-  int                 y_avail[3];
-  int                 cwidth;
-  int                 cheight;
-  int                 ret;
-  int                 rfi;
-  int                 pli;
-  /*Step 1: validate parameters.*/
-  if(_enc==NULL||_img==NULL)return TH_EFAULT;
-  if(_enc->packet_state==OC_PACKET_DONE)return TH_EINVAL;
-  if(_img[0].width!=(int)_enc->state.info.frame_width||
-   _img[0].height!=(int)_enc->state.info.frame_height){
-    return TH_EINVAL;
-  }
-  cwidth=_enc->state.info.frame_width>>!(_enc->state.info.pixel_fmt&1);
-  cheight=_enc->state.info.frame_height>>!(_enc->state.info.pixel_fmt&2);
-  if(_img[1].width!=cwidth||_img[2].width!=cwidth||
-   _img[1].height!=cheight||_img[2].height!=cheight){
-    return TH_EINVAL;
-  }
-  /*Flip the input buffer upside down.*/
-  oc_ycbcr_buffer_flip(img,_img);
-  /*Step 2: Update buffer state.*/
-  if(_enc->state.ref_frame_idx[OC_FRAME_SELF]>=0){
-    _enc->state.ref_frame_idx[OC_FRAME_PREV]=
-     _enc->state.ref_frame_idx[OC_FRAME_SELF];
-    if(_enc->state.frame_type==OC_INTRA_FRAME){
-      /*The new frame becomes both the previous and gold reference frames.*/
-      _enc->state.keyframe_num=_enc->state.curframe_num;
-      _enc->state.ref_frame_idx[OC_FRAME_GOLD]=
-       _enc->state.ref_frame_idx[OC_FRAME_SELF];
-    }
-  }
-  /*If no encoding mode has been explicitly enabled by the application,
-     enable the default encoding mode with a default configuration.*/
-  else if(_enc->pipe==NULL)oc_enc_enable_default_mode(_enc);
-  /*Select a free buffer to use for the reconstructed version of this frame.*/
-  for(rfi=0;rfi==_enc->state.ref_frame_idx[OC_FRAME_GOLD]||
-   rfi==_enc->state.ref_frame_idx[OC_FRAME_PREV];rfi++);
-  _enc->state.ref_frame_idx[OC_FRAME_SELF]=rfi;
-  _enc->state.curframe_num++;
-  /*Fill the fragment array with pointers into the user buffer.*/
-  oc_state_fill_buffer_ptrs(&_enc->state,OC_FRAME_IO,img);
-  /*Reset the encoding pipeline.*/
-  ret=(*_enc->pipe->pipe_start)(_enc->pipe);
-  if(ret<0)return ret;
-  /*Push the image into the pipeline.*/
-  for(pli=0;pli<3;pli++)y_avail[pli]=_img[pli].height;
-  ret=(*_enc->pipe->pipe_proc)(_enc->pipe,y_avail);
-  if(ret<0)return ret;
-  /*Flush the results through.*/
-  ret=(*_enc->pipe->pipe_end)(_enc->pipe);
-  if(ret<0)return ret;
-  /*Note: All buffer management, etc., that is done after a frame is encoded
-     is delayed until the next frame is encoded.
-    This allows for a future API that would let an encoding application
-     examine the decompressed output and attempt to re-encode the same frame
-     again with different settings if it disapproved.
-    Here we just update the granpos needed for the output packet and return.*/
-  if(_enc->state.frame_type==OC_INTRA_FRAME){
-    _enc->state.granpos=
-     _enc->state.curframe_num<<_enc->state.info.keyframe_granule_shift;
-  }
-  else{
-    _enc->state.granpos=
-     (_enc->state.keyframe_num<<_enc->state.info.keyframe_granule_shift)+
-     (_enc->state.curframe_num-_enc->state.keyframe_num);
-  }
-#if defined(OC_DUMP_IMAGES)
-  /*This is done after the granpos update, because that's what it uses to name
-     the output file.*/
-  oc_state_dump_frame(&_enc->state,OC_FRAME_SELF,"rec");
-#endif
-  return 0;
-}
-
-int th_encode_packetout(th_enc_ctx *_enc,int _last,ogg_packet *_op){
-  if(_enc==NULL||_op==NULL)return TH_EFAULT;
-  if(_enc->packet_state!=OC_PACKET_READY)return 0;
-  _op->packet=oggpackB_get_buffer(&_enc->opb);
-  _op->bytes=oggpackB_bytes(&_enc->opb);
-  _op->b_o_s=0;
-  _op->e_o_s=_last;
-  _op->packetno=_enc->state.curframe_num;
-  _op->granulepos=_enc->state.granpos;
-  if(_last)_enc->packet_state=OC_PACKET_DONE;
-  else _enc->packet_state=OC_PACKET_EMPTY;
-  return 1;
-}

Deleted: experimental/j/theora-mashup/lib/dec/encvbr.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/encvbr.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/encvbr.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,1416 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <ogg/ogg.h>
-#include "encvbr.h"
-#include "fdct.h"
-
-
-
-/*Returns the number of bits used by the given motion vector with the VLC
-   motion vector codes (as opposed to the CLC codes, which always use 12 bits).
-  _dx: The X component of the vector, in half-pel units.
-  _dy: The Y component of the vector, in half-pel units.
-  Return: The number of bits required to store the vector with the VLC codes.*/
-static int oc_mvbitsa(int _dx,int _dy){
-  return OC_MV_CODES[0][_dx+31].nbits+OC_MV_CODES[0][_dy+31].nbits;
-}
-
-
-
-/*Select the set of quantizers to use for the current frame for each possible
-   frame type (intra or inter).
-  This does not assign a quantizer to each fragment, as that depends on the
-   quantizer type used and thus is done during mode decision.*/
-static void oc_enc_vbr_quant_sel_quality(oc_enc_ctx *_enc,int _intra_only){
-  unsigned              qmax[2][3];
-  int                   qi_min[2];
-  int                   qi_max[2];
-  int                   fti;
-  int                   qti;
-  int                   pli;
-  int                   dc_qi[2];
-  qi_min[0]=_enc->vbr->cfg.kf_qi_min;
-  qi_min[1]=_enc->vbr->cfg.df_qi_min;
-  qi_max[0]=_enc->vbr->cfg.kf_qi_max;
-  qi_max[1]=_enc->vbr->cfg.df_qi_max;
-  /*The first quantizer value is used for DC coefficients.
-    Select one that allows us to meet our quality requirements.*/
-  for(qti=0;qti<1+!_intra_only;qti++)for(pli=0;pli<3;pli++){
-    qmax[qti][pli]=OC_MAXI(2U*_enc->vbr->dc_tol_mins[pli],
-     OC_DC_QUANT_MIN[qti]);
-  }
-  /*For intra frames...(containing just INTRA fragments)*/
-  for(dc_qi[0]=qi_min[0];dc_qi[0]<qi_max[0];dc_qi[0]++){
-    if(_enc->state.dequant_tables[0][0][dc_qi[0]][0]<=qmax[0][0]&&
-     _enc->state.dequant_tables[0][1][dc_qi[0]][0]<=qmax[0][1]&&
-     _enc->state.dequant_tables[0][2][dc_qi[0]][0]<=qmax[0][2]){
-      break;
-    }
-  }
-  /*For inter frames...(containing both INTER and INTRA fragments)*/
-  if(!_intra_only){
-    for(dc_qi[1]=OC_CLAMPI(qi_min[1],dc_qi[0],qi_max[1]);dc_qi[1]<qi_max[1];
-     dc_qi[1]++){
-      if(_enc->state.dequant_tables[1][0][dc_qi[1]][0]<=qmax[1][0]&&
-       _enc->state.dequant_tables[1][1][dc_qi[1]][0]<=qmax[1][1]&&
-       _enc->state.dequant_tables[1][2][dc_qi[1]][0]<=qmax[1][2]){
-        break;
-      }
-    }
-  }
-  /*Now we select a full qi list for each frame type.*/
-  for(fti=0;fti<1+!_intra_only;fti++){
-    oc_fragment_enc_info *efrag;
-    int                   ncoded_fragis;
-    int                   nqis[64];
-    int                   qi;
-    int                   qi0;
-    int                   qi1;
-    int                   qi2;
-    /*Here we count up the number of fragments that can use each qi value.
-      Unless we know this is an intra frame, we don't know what quantizer type
-       will be used for each fragment, so we just count both of them.*/
-    memset(nqis,0,sizeof(nqis));
-    if(fti){
-      int *coded_fragi;
-      int *coded_fragi_end;
-      coded_fragi=_enc->state.coded_fragis;
-      ncoded_fragis=_enc->state.ncoded_fragis[0]+
-       _enc->state.ncoded_fragis[1]+_enc->state.ncoded_fragis[2];
-      coded_fragi_end=coded_fragi+ncoded_fragis;
-      for(;coded_fragi<coded_fragi_end;coded_fragi++){
-        efrag=_enc->frinfo+*coded_fragi;
-        for(qti=0;qti<2;qti++)nqis[efrag->qi_min[qti]]++;
-      }
-    }
-    else{
-      oc_fragment_enc_info *efrag_end;
-      ncoded_fragis=_enc->state.nfrags;
-      efrag=_enc->frinfo;
-      efrag_end=efrag+ncoded_fragis;
-      for(;efrag<efrag_end;efrag++)nqis[efrag->qi_min[0]]++;
-    }
-    /*We'll now choose the qi values that divide the fragments into equally
-       sized groups, or as close as we can make it.
-      We account for the DC coefficients by adding an extra amount to the qi
-       value they require.
-      Since there are usually many more DC coefficients coded than any one AC
-       coefficient, we use 1/8 of the number of fragments, instead of 1/64.*/
-    nqis[dc_qi[fti]]+=(ncoded_fragis<<fti)+7>>3;
-    /*Convert this into a moment table.*/
-    for(qi=63;qi-->0;)nqis[qi]+=nqis[qi+1];
-    /*If we have a lower limit on the QI range, promote and fragments with a
-       smaller QI, to ensure they're counted.*/
-    if(qi_min[fti]>0)nqis[qi_min[fti]]=nqis[0];
-    /*Select our first quantizer.*/
-    for(qi0=qi_max[fti]+1;qi0-->qi_min[fti]&&nqis[qi0]<=0;);
-    for(qi1=qi0-1;qi1>=qi_min[fti]&&nqis[qi1]<=nqis[qi0];qi1--);
-    /*Test to make sure there are even two unique quantizers.*/
-    if(qi1>=qi_min[fti]){
-      ogg_int64_t best_metric;
-      ogg_int64_t metric;
-      int         best_qi1;
-      int         best_qi2;
-      int         qii;
-      for(qi2=qi1-1;qi2>=qi_min[fti]&&nqis[qi2]<=nqis[qi1];qi2--);
-      /*Test to make sure there are three unique quantizers.*/
-      if(qi2>=0){
-        best_metric=(ogg_int64_t)(nqis[0]-nqis[qi2+1])*
-         (nqis[qi2+1]-nqis[qi1+1])*nqis[qi1+1];
-        best_qi1=qi1;
-        best_qi2=qi2;
-        for(;nqis[qi1]<nqis[1];qi1--){
-          for(qi2=qi1-1;nqis[qi2]<nqis[0];qi2--){
-            metric=(ogg_int64_t)(nqis[0]-nqis[qi2+1])*
-             (nqis[qi2+1]-nqis[qi1+1])*nqis[qi1+1];
-            if(metric>=best_metric){
-              best_qi1=qi1;
-              best_qi2=qi2;
-              best_metric=metric;
-            }
-          }
-        }
-        _enc->qis[fti][0]=qi0;
-        _enc->qis[fti][1]=best_qi1;
-        _enc->qis[fti][2]=best_qi2;
-        _enc->nqis[fti]=3;
-      }
-      else{
-        best_metric=(ogg_int64_t)(nqis[0]-nqis[qi1+1])*nqis[qi1+1];
-        best_qi1=qi1;
-        if(qi1>0)for(qi1--;nqis[qi1]<nqis[0];qi1--){
-          metric=(ogg_int64_t)(nqis[0]-nqis[qi1+1])*nqis[qi1+1];
-          if(metric>best_metric){
-            best_qi1=qi1;
-            best_metric=metric;
-          }
-        }
-        _enc->qis[fti][0]=qi0;
-        _enc->qis[fti][1]=best_qi1;
-        _enc->nqis[fti]=2;
-      }
-      /*Right now qis[0] is the largest.
-        We want to use the smallest that is still large enough for our DC
-         coefficients.*/
-      for(qii=1;qii<_enc->nqis[fti];qii++)if(_enc->qis[fti][qii]>=dc_qi[fti]){
-        qi0=_enc->qis[fti][0];
-        _enc->qis[fti][0]=_enc->qis[fti][qii];
-        _enc->qis[fti][qii]=qi0;
-      }
-    }
-    else{
-      _enc->qis[fti][0]=qi0;
-      _enc->nqis[fti]=1;
-    }
-    /*If we're in VP3 compatibility mode, just use the first quantizer.*/
-    if(_enc->vp3_compatible)_enc->nqis[fti]=1;
-  }
-}
-
-/*Mark all fragments as coded and in OC_MODE_INTRA.
-  This also selects a quantizer value for each fragment and builds up the
-   coded fragment list (in coded order) and clears the uncoded fragment list.
-  It does not update the coded macro block list, as that is not used when
-   coding INTRA frames.*/
-static void oc_enc_vbr_mark_all_intra(oc_enc_ctx *_enc){
-  oc_sb *sb;
-  oc_sb *sb_end;
-  int    pli;
-  int    qii;
-  int    ncoded_fragis;
-  int    prev_ncoded_fragis;
-  /*Select the quantizer list for INTRA frames.*/
-  _enc->state.nqis=_enc->nqis[OC_INTRA_FRAME];
-  for(qii=0;qii<_enc->state.nqis;qii++){
-    _enc->state.qis[qii]=_enc->qis[OC_INTRA_FRAME][qii];
-  }
-  prev_ncoded_fragis=ncoded_fragis=0;
-  sb=sb_end=_enc->state.sbs;
-  for(pli=0;pli<3;pli++){
-    const oc_fragment_plane *fplane;
-    fplane=_enc->state.fplanes+pli;
-    sb_end+=fplane->nsbs;
-    for(;sb<sb_end;sb++){
-      int quadi;
-      for(quadi=0;quadi<4;quadi++)if(sb->quad_valid&1<<quadi){
-        int bi;
-        for(bi=0;bi<4;bi++)if(sb->map[quadi][bi]>=0){
-          oc_fragment_enc_info *efrag;
-          oc_fragment          *frag;
-          int                   fragi;
-          int                   best_qii;
-          fragi=sb->map[quadi][bi];
-          frag=_enc->state.frags+fragi;
-          frag->coded=1;
-          frag->mbmode=OC_MODE_INTRA;
-          efrag=_enc->frinfo+fragi;
-          best_qii=0;
-          for(qii=1;qii<_enc->state.nqis;qii++){
-            if(efrag->qi_min[0]<=_enc->state.qis[qii]&&
-             (_enc->state.qis[best_qii]<efrag->qi_min[0]||
-             _enc->state.qis[qii]<_enc->state.qis[best_qii])){
-              best_qii=qii;
-            }
-          }
-          efrag->qii=(unsigned char)best_qii;
-          frag->qi=_enc->state.qis[best_qii];
-          _enc->state.coded_fragis[ncoded_fragis++]=fragi;
-#if defined(OC_BITRATE_STATS)
-          /*Compute the error function used for intra mode fragments.
-            This function can only use information known at mode decision time, and
-             so excludes the DC component.
-            TODO: Separate this out somewhere more useful.*/
-          {
-            oc_fragment_enc_info *efrag;
-            int                   ci;
-            int                   eerror;
-            efrag=_enc->frinfo+fragi;
-            eerror=0;
-            for(ci=1;ci<64;ci++)eerror+=abs(efrag->dct_coeffs[ci]);
-            efrag->eerror=eerror;
-          }
-#endif
-        }
-      }
-    }
-    _enc->state.ncoded_fragis[pli]=ncoded_fragis-prev_ncoded_fragis;
-    prev_ncoded_fragis=ncoded_fragis;
-    _enc->state.nuncoded_fragis[pli]=0;
-  }
-  _enc->ncoded_frags=ncoded_fragis;
-}
-
-
-
-/*Quantize and predict the DC coefficients.
-  This is done in a separate step because the prediction of DC coefficients
-   occurs in image order, not in the Hilbert-curve order, unlike the rest of
-   the encoding process.*/
-static void oc_enc_vbr_quant_dc(oc_enc_ctx *_enc){
-  oc_fragment_enc_info *efrag;
-  oc_fragment          *frag;
-  int                   pli;
-  frag=_enc->state.frags;
-  efrag=_enc->frinfo;
-  for(pli=0;pli<3;pli++){
-    oc_fragment_plane *fplane;
-    unsigned           fquant;
-    unsigned           iquant;
-    int                pred_last[3];
-    int                fragx;
-    int                fragy;
-    pred_last[OC_FRAME_GOLD]=0;
-    pred_last[OC_FRAME_PREV]=0;
-    pred_last[OC_FRAME_SELF]=0;
-    fplane=_enc->state.fplanes+pli;
-    for(fragy=0;fragy<fplane->nvfrags;fragy++){
-      for(fragx=0;fragx<fplane->nhfrags;fragx++,frag++,efrag++){
-        int qc_pred;
-        int qc;
-        if(!frag->coded)continue;
-        qc_pred=oc_frag_pred_dc(frag,fplane,fragx,fragy,pred_last);
-        /*Fragments outside the displayable region must still be coded in key
-           frames.
-          To minimize wasted bits, just use the predicted DC value.
-          TODO: We might do a better job in the lower-left hand corner by
-           propagating over the DC value of the first actually coded fragment,
-           but for the moment this is not done.*/
-        if(frag->invalid)qc=0;
-        else{
-          int c;
-          int c_abs;
-          int qti;
-          /*We now center the DC coefficient range around the predicted value
-             and perform token bits optimization based on the HVS-determined
-             tolerance range.
-            For more details, see oc_enc_vbr_frag_quant_tokenize().*/
-          qti=frag->mbmode!=OC_MODE_INTRA;
-          iquant=_enc->state.dequant_tables[qti][pli][_enc->state.qis[0]][0];
-          c=efrag->dct_coeffs[0]-qc_pred*iquant;
-          c_abs=abs(c);
-          if(c_abs<=efrag->tols[0])qc=0;
-          else{
-            int qc_signed[2];
-            int qc_max;
-            int qc_min;
-            int qc_offs;
-            int c_sign;
-            int c_min;
-            int c_recon;
-            int cati;
-            fquant=_enc->enquant_tables[qti][pli][_enc->state.qis[0]][0];
-            qc_max=(ogg_int32_t)c_abs*fquant+OC_FQUANT_ROUND>>OC_FQUANT_SHIFT;
-            c_sign=c<0;
-            c_recon=(qc_max-1)*iquant;
-            c_min=OC_MAXI(0,c_abs-efrag->tols[0]);
-            for(qc_min=qc_max;c_recon>=c_min;qc_min--)c_recon-=iquant;
-            if(qc_min<3+OC_NDCT_VAL_CAT2_SIZE)qc=qc_min;
-            else{
-              qc_offs=3+OC_NDCT_VAL_CAT2_SIZE;
-              for(cati=0;cati<5&&qc_min>=qc_offs+OC_DCT_VAL_CAT_SIZES[cati];
-               cati++){
-                qc_offs+=OC_DCT_VAL_CAT_SIZES[cati];
-              }
-              qc=OC_MINI(qc_offs+OC_DCT_VAL_CAT_SIZES[cati]-1,qc_max);
-            }
-            qc_signed[0]=qc;
-            qc_signed[1]=-qc;
-            qc=qc_signed[c_sign];
-          }
-        }
-        pred_last[OC_FRAME_FOR_MODE[frag->mbmode]]=frag->dc=qc+qc_pred;
-        efrag->dct_coeffs[0]=(ogg_int16_t)qc;
-      }
-    }
-  }
-}
-
-/*Quantize and tokenize the given fragment.
-  _efrag:   The encoder information for the fragment to quantize.
-  _qcoeffs: The quantized coefficients, in zig-zag order.
-  _fquant:  The forward quantization matrix to use.
-  _iquant:  The inverse quantization matrix to use.
-  Return: The number of coefficients before any final zero run.*/
-static int oc_enc_vbr_frag_quant_tokenize(oc_enc_ctx *_enc,
- oc_fragment_enc_info *_efrag,ogg_int16_t _qcoeffs[64],
- const ogg_uint16_t _fquant[64],const ogg_uint16_t _iquant[64]){
-  int zzi;
-  int zrun;
-  int qc;
-  int qc_offs;
-  int c_sign;
-  int cati;
-  int tli;
-  /*The DC coefficient is already quantized (it had to be for DC prediction).
-    Here we just tokenize it.*/
-  if(_efrag->dct_coeffs[0]){
-    qc=abs(_efrag->dct_coeffs[0]);
-    c_sign=_efrag->dct_coeffs[0]<0;
-    switch(qc){
-      case 1:{
-        _enc->dct_tokens[0][_enc->ndct_tokens[0]++]=
-         (unsigned char)(OC_ONE_TOKEN+c_sign);
-      }break;
-      case 2:{
-        _enc->dct_tokens[0][_enc->ndct_tokens[0]++]=
-         (unsigned char)(OC_TWO_TOKEN+c_sign);
-      }break;
-      default:{
-        if(qc-3<OC_NDCT_VAL_CAT2_SIZE){
-          _enc->dct_tokens[0][_enc->ndct_tokens[0]++]=
-           (unsigned char)(OC_DCT_VAL_CAT2+qc-3);
-          _enc->extra_bits[0][_enc->nextra_bits[0]++]=(ogg_uint16_t)c_sign;
-        }
-        else{
-          qc_offs=3+OC_NDCT_VAL_CAT2_SIZE;
-          for(cati=0;qc>=qc_offs+OC_DCT_VAL_CAT_SIZES[cati];cati++){
-            qc_offs+=OC_DCT_VAL_CAT_SIZES[cati];
-          }
-          _enc->dct_tokens[0][_enc->ndct_tokens[0]++]=
-           (unsigned char)(OC_DCT_VAL_CAT3+cati);
-          _enc->extra_bits[0][_enc->nextra_bits[0]++]=
-           (ogg_uint16_t)((c_sign<<OC_DCT_VAL_CAT_SHIFTS[cati])+qc-qc_offs);
-        }
-      }
-    }
-    zrun=0;
-  }
-  else zrun=1;
-  /*Now we quantize and tokenize each AC coefficient.*/
-  for(zzi=1;zzi<64;zzi++){
-    int qc_signed[2];
-    int qc_max;
-    int qc_min;
-    int c_sign;
-    int c_abs;
-    int c_min;
-    int c_recon;
-    int ci;
-    ci=OC_FZIG_ZAG[zzi];
-    c_abs=abs(_efrag->dct_coeffs[ci]);
-    /*Best case: we can encode this as a zero.*/
-    if(c_abs<=_efrag->tols[ci]){
-      zrun++;
-      _qcoeffs[zzi]=0;
-    }
-    else{
-      c_sign=_efrag->dct_coeffs[ci]<0;
-      /*qc_max is the most accurate quantized value.
-        This is the largest possible (absolute) value we will use.*/
-      qc_max=(ogg_int32_t)c_abs*_fquant[ci]+OC_FQUANT_ROUND>>OC_FQUANT_SHIFT;
-      /*qc_min is the smallest possible (by absolute value) quantized value
-         whose dequantized value is within the HVS-determined tolerance
-         range.*/
-      /*TODO: qc_min could be computed by a division (we do not want to allow
-         the rounding errors that are possible with the mul+shift quantization
-         used for qc_max), which would allow qc_max to be calculated only if
-         needed below.
-        Is this faster?
-        Who knows.*/
-      c_recon=(qc_max-1)*_iquant[ci];
-      c_min=c_abs-_efrag->tols[ci];
-      for(qc_min=qc_max;c_recon>=c_min;qc_min--)c_recon-=_iquant[ci];
-      /*We now proceed to find a token that is as close to qc_max as possible,
-         but does not use any more bits than would be required for qc_min.
-        The general assumption we make is that encoding a value closer to 0
-         always uses fewer bits.
-        qc_min can still reach 0 here despite the test above, if the quantizer
-         value is larger than the tolerance (which can happen for very small
-         tolerances; the quantizer value has a minimum it cannot go below).*/
-      if(qc_min==0){
-        zrun++;
-        _qcoeffs[zzi]=0;
-      }
-      else{
-        /*If we have an outstanding zero run, code it now.*/
-        if(zrun>0){
-          /*The zero run tokens appear on the list for the first zero in the
-             run.*/
-          tli=zzi-zrun;
-          /*Second assumption: coding a combined run/value token always uses
-             fewer bits than coding them separately.*/
-          /*CAT1 run/value tokens: the value is 1.*/
-          if(qc_min==1&&zrun<=17){
-            if(zrun<=5){
-              _enc->dct_tokens[tli][_enc->ndct_tokens[tli]++]=
-               (unsigned char)(OC_DCT_RUN_CAT1A+(zrun-1));
-              _enc->extra_bits[tli][_enc->nextra_bits[tli]++]=
-               (ogg_uint16_t)c_sign;
-            }
-            else if(zrun<=9){
-              _enc->dct_tokens[tli][_enc->ndct_tokens[tli]++]=
-               OC_DCT_RUN_CAT1B;
-              _enc->extra_bits[tli][_enc->nextra_bits[tli]++]=
-               (ogg_uint16_t)((c_sign<<2)+zrun-6);
-            }
-            else{
-              _enc->dct_tokens[tli][_enc->ndct_tokens[tli]++]=
-               OC_DCT_RUN_CAT1C;
-              _enc->extra_bits[tli][_enc->nextra_bits[tli]++]=
-               (ogg_uint16_t)((c_sign<<3)+zrun-10);
-            }
-            qc_signed[0]=1;
-            qc_signed[1]=-1;
-            _qcoeffs[zzi]=(ogg_int16_t)qc_signed[c_sign];
-            zrun=0;
-            /*Skip coding the DCT value below.*/
-            continue;
-          }
-          /*CAT2 run/value tokens: the value is 2-3.*/
-          else if(qc_min<=3&&zrun<=3){
-            if(zrun==1){
-              _enc->dct_tokens[tli][_enc->ndct_tokens[tli]++]=
-               OC_DCT_RUN_CAT2A;
-              qc=OC_MINI(3,qc_max);
-              _enc->extra_bits[tli][_enc->nextra_bits[tli]++]=
-               (ogg_uint16_t)((c_sign<<1)+qc-2);
-            }
-            else{
-              _enc->dct_tokens[tli][_enc->ndct_tokens[tli]++]=
-               OC_DCT_RUN_CAT2B;
-              qc=OC_MINI(3,qc_max);
-              _enc->extra_bits[tli][_enc->nextra_bits[tli]++]=
-               (ogg_uint16_t)((c_sign<<2)+(qc-2<<1)+zrun-2);
-            }
-            qc_signed[0]=qc;
-            qc_signed[1]=-qc;
-            _qcoeffs[zzi]=(ogg_int16_t)qc_signed[c_sign];
-            zrun=0;
-            /*Skip coding the DCT value below.*/
-            continue;
-          }
-          /*The run is too long or the quantized value too large: code them
-             separately.*/
-          else{
-            /*This is stupid: non-short ZRL tokens are never used for run
-               values less than 9, but codewords are reserved for them,
-               wasting bits.
-              Yes, yes, this would've meant a non-constant number of extra
-               bits for this token, but even so.*/
-            if(zrun<=8){
-              _enc->dct_tokens[tli][_enc->ndct_tokens[tli]++]=
-               OC_DCT_SHORT_ZRL_TOKEN;
-            }
-            else{
-              _enc->dct_tokens[tli][_enc->ndct_tokens[tli]++]=
-               OC_DCT_ZRL_TOKEN;
-            }
-            _enc->extra_bits[tli][_enc->nextra_bits[tli]++]=
-             (ogg_uint16_t)(zrun-1);
-            zrun=0;
-          }
-        }
-        /*No zero run, or the run and the qc value are being coded
-           separately.*/
-        switch(qc_min){
-          case 1:{
-            _enc->dct_tokens[zzi][_enc->ndct_tokens[zzi]++]=
-             (unsigned char)(OC_ONE_TOKEN+c_sign);
-            _qcoeffs[zzi]=(ogg_int16_t)((-c_sign<<1)+1);
-          }break;
-          case 2:{
-            _enc->dct_tokens[zzi][_enc->ndct_tokens[zzi]++]=
-             (unsigned char)(OC_TWO_TOKEN+c_sign);
-            _qcoeffs[zzi]=(ogg_int16_t)((-c_sign<<2)+2);
-          }break;
-          default:{
-            if(qc_min-3<OC_NDCT_VAL_CAT2_SIZE){
-              _enc->dct_tokens[zzi][_enc->ndct_tokens[zzi]++]=
-               (unsigned char)(OC_DCT_VAL_CAT2+qc_min-3);
-              _enc->extra_bits[zzi][_enc->nextra_bits[zzi]++]=
-               (ogg_uint16_t)c_sign;
-              qc_signed[0]=qc_min;
-              qc_signed[1]=-qc_min;
-              _qcoeffs[zzi]=(ogg_int16_t)qc_signed[c_sign];
-            }
-            else{
-              qc_offs=3+OC_NDCT_VAL_CAT2_SIZE;
-              for(cati=0;cati<5&&qc_min>=qc_offs+OC_DCT_VAL_CAT_SIZES[cati];
-               cati++){
-                qc_offs+=OC_DCT_VAL_CAT_SIZES[cati];
-              }
-              /*qc_min can be encoded in this category.
-                Since all DCT values in the category use the same number of
-                 bits, we encode the closest value to qc_max.
-                This is either qc_max itself, if it is in the category's
-                 range, or the largest value in the category.*/
-              qc=OC_MINI(qc_offs+OC_DCT_VAL_CAT_SIZES[cati]-1,qc_max);
-              qc_signed[0]=qc;
-              qc_signed[1]=-qc;
-              _qcoeffs[zzi]=(ogg_int16_t)qc_signed[c_sign];
-              _enc->dct_tokens[zzi][_enc->ndct_tokens[zzi]++]=
-               (unsigned char)(OC_DCT_VAL_CAT3+cati);
-              _enc->extra_bits[zzi][_enc->nextra_bits[zzi]++]=(ogg_uint16_t)
-               ((c_sign<<OC_DCT_VAL_CAT_SHIFTS[cati])+qc-qc_offs);
-            }
-          }
-        }
-      }
-    }
-  }
-  /*If there's a trailing zero run, code an EOB token.*/
-  if(zrun>0){
-    int old_tok;
-    int toki;
-    int ebi;
-    tli=64-zrun;
-    toki=_enc->ndct_tokens[tli]-1;
-    if(toki>=0)old_tok=_enc->dct_tokens[tli][toki];
-    else old_tok=-1;
-    /*Try to extend an EOB run.*/
-    switch(old_tok){
-      case OC_DCT_EOB1_TOKEN:
-      case OC_DCT_EOB2_TOKEN:{
-        _enc->dct_tokens[tli][toki]++;
-      }break;
-      case OC_DCT_EOB3_TOKEN:{
-        _enc->dct_tokens[tli][toki]++;
-        _enc->extra_bits[tli][_enc->nextra_bits[tli]++]=0;
-      }break;
-      case OC_DCT_REPEAT_RUN0_TOKEN:{
-        ebi=_enc->nextra_bits[tli]-1;
-        if(_enc->extra_bits[tli][ebi]<3)_enc->extra_bits[tli][ebi]++;
-        else{
-          _enc->dct_tokens[tli][toki]++;
-          _enc->extra_bits[tli][ebi]=0;
-        }
-      }break;
-      case OC_DCT_REPEAT_RUN1_TOKEN:{
-        ebi=_enc->nextra_bits[tli]-1;
-        if(_enc->extra_bits[tli][ebi]<7)_enc->extra_bits[tli][ebi]++;
-        else{
-          _enc->dct_tokens[tli][toki]++;
-          _enc->extra_bits[tli][ebi]=0;
-        }
-      }break;
-      case OC_DCT_REPEAT_RUN2_TOKEN:{
-        ebi=_enc->nextra_bits[tli]-1;
-        if(_enc->extra_bits[tli][ebi]<15)_enc->extra_bits[tli][ebi]++;
-        else{
-          _enc->dct_tokens[tli][toki]++;
-          /*Again stupid: we could encode runs up to 4127, but inexplicably
-             they don't subtract the bottom of the range here, so we can only
-             go to 4095 (unless we want to change the spec to deal with
-             wrap-around).*/
-          _enc->extra_bits[tli][ebi]=32;
-        }
-      }break;
-      case OC_DCT_REPEAT_RUN3_TOKEN:{
-        ebi=_enc->nextra_bits[tli]-1;
-        if(_enc->extra_bits[tli][ebi]<4095){
-          _enc->extra_bits[tli][ebi]++;
-          break;
-        }
-        /*else fall through.*/
-      }
-      /*Start a new EOB run.*/
-      default:{
-        _enc->dct_tokens[tli][_enc->ndct_tokens[tli]++]=OC_DCT_EOB1_TOKEN;
-      }
-    }
-  }
-  /*Return the number of coefficients before the final zero run.*/
-  return 64-zrun;
-}
-
-static void oc_enc_vbr_residual_tokenize(oc_enc_ctx *_enc){
-  int *coded_fragi;
-  int *coded_fragi_end;
-  int    pli;
-  int    zzi;
-  /*Clear any existing DCT tokens.*/
-  for(zzi=0;zzi<64;zzi++){
-    _enc->ndct_tokens[zzi]=_enc->nextra_bits[zzi]=0;
-    _enc->extra_bits_offs[zzi]=0;
-  }
-  coded_fragi_end=coded_fragi=_enc->state.coded_fragis;
-  for(pli=0;pli<3;pli++){
-    memcpy(_enc->dct_token_offs[pli],_enc->ndct_tokens,
-     sizeof(_enc->dct_token_offs[pli]));
-    coded_fragi_end+=_enc->state.ncoded_fragis[pli];
-    for(;coded_fragi<coded_fragi_end;coded_fragi++){
-      oc_quant_table       *iquants;
-      oc_fragment          *frag;
-      oc_fragment_enc_info *efrag;
-      ogg_int16_t           qcoeffs[64];
-      int                   fragi;
-      int                   qti;
-      int                   nnzc;
-      fragi=*coded_fragi;
-      frag=_enc->state.frags+fragi;
-      efrag=_enc->frinfo+fragi;
-      qti=frag->mbmode!=OC_MODE_INTRA;
-      iquants=_enc->state.dequant_tables[qti][pli];
-      nnzc=oc_enc_vbr_frag_quant_tokenize(_enc,efrag,qcoeffs,
-       _enc->enquant_tables[qti][pli][frag->qi],iquants[frag->qi]);
-      /*While we're here and things are in cache, reconstruct the quantized
-         fragment.*/
-      oc_state_frag_recon(&_enc->state,frag,pli,qcoeffs,nnzc,nnzc,
-       iquants[_enc->state.qis[0]][0],iquants[frag->qi]);
-    }
-  }
-  /*Merge the final EOB run of one coefficient list with the start of the
-     next, if possible.*/
-  for(zzi=1;zzi<64;zzi++){
-    static const int OC_EOB_RANGE[OC_NDCT_EOB_TOKEN_MAX]={1,1,1,4,8,16,4096};
-    static const int OC_EOB_OFFS[OC_NDCT_EOB_TOKEN_MAX]={1,2,3,4,8,16,0};
-    int old_tok1;
-    int old_tok2;
-    int old_eb1;
-    int old_eb2;
-    int new_tok;
-    int toki;
-    int zzj;
-    int ebi;
-    int runl;
-    /*Make sure this coefficient has tokens at all.*/
-    if(_enc->ndct_tokens[zzi]<=0)continue;
-    /*Ensure the first token is an EOB run.*/
-    old_tok2=_enc->dct_tokens[zzi][0];
-    if(old_tok2>=OC_NDCT_EOB_TOKEN_MAX)continue;
-    /*Search for a previous coefficient that has any tokens at all.*/
-    old_tok1=OC_NDCT_EOB_TOKEN_MAX;
-    zzj=zzi-1;
-    do{
-      toki=_enc->ndct_tokens[zzj]-1;
-      if(toki>=_enc->dct_token_offs[0][zzj]){
-        old_tok1=_enc->dct_tokens[zzj][toki];
-        break;
-      }
-    }
-    while(zzj-->0);
-    /*Ensure its last token was an EOB run.*/
-    if(old_tok1>=OC_NDCT_EOB_TOKEN_MAX)continue;
-    /*Pull off the associated extra bits, if any, and decode the runs.*/
-    ebi=_enc->nextra_bits[zzj];
-    old_eb1=OC_DCT_TOKEN_EXTRA_BITS[old_tok1]?_enc->extra_bits[zzj][--ebi]:0;
-    old_eb2=OC_DCT_TOKEN_EXTRA_BITS[old_tok2]?_enc->extra_bits[zzi][0]:0;
-    runl=OC_EOB_OFFS[old_tok1]+old_eb1+OC_EOB_OFFS[old_tok2]+old_eb2;
-    /*We can't possibly combine these into one run.
-      It might be possible to split them more optimally, but we'll just leave
-       them as is.*/
-    if(runl>=4096)continue;
-    /*We CAN combine them into one run.*/
-    for(new_tok=OC_DCT_EOB1_TOKEN;
-     runl-OC_EOB_OFFS[new_tok]>=OC_EOB_RANGE[new_tok];new_tok++);
-    /*toki is always initialized.
-      If your compiler thinks otherwise, it is dumb.*/
-    _enc->dct_tokens[zzj][toki]=(unsigned char)new_tok;
-    /*Update the two token lists.*/
-    if(OC_DCT_TOKEN_EXTRA_BITS[new_tok]){
-      _enc->extra_bits[zzj][ebi++]=(ogg_uint16_t)(
-       runl-OC_EOB_OFFS[new_tok]);
-    }
-    _enc->nextra_bits[zzj]=ebi;
-    _enc->dct_token_offs[0][zzi]++;
-    /*Note: We don't bother to update the offsets for planes 1 and 2 if
-       planes 0 or 1 don't have any tokens.
-      This turns out not to matter due to the way we use the offsets later.*/
-    if(OC_DCT_TOKEN_EXTRA_BITS[old_tok2])_enc->extra_bits_offs[zzi]++;
-  }
-}
-
-/*Marks each fragment as coded or not, based on the coefficient-level
-   thresholds computed in the psychovisual stage.
-  The MB mode of the fragments are not set, as they will be computed in
-   oc_enc_choose_mbmodes().
-  This also builds up the coded fragment and uncoded fragment lists.
-  The coded MB list is not built up.
-  That is done during mode decision.*/
-static void oc_enc_vbr_mark_coded(oc_enc_ctx *_enc){
-  oc_sb *sb;
-  oc_sb *sb_end;
-  int    pli;
-  int    bli;
-  int    ncoded_fragis;
-  int    prev_ncoded_fragis;
-  int    nuncoded_fragis;
-  int    prev_nuncoded_fragis;
-  _enc->nblock_coded_flags=bli=0;
-  prev_ncoded_fragis=ncoded_fragis=prev_nuncoded_fragis=nuncoded_fragis=0;
-  sb=sb_end=_enc->state.sbs;
-  for(pli=0;pli<3;pli++){
-    const oc_fragment_plane *fplane;
-    int                      ystride;
-    int                      prev_refi;
-    fplane=_enc->state.fplanes+pli;
-    sb_end+=fplane->nsbs;
-    prev_refi=_enc->state.ref_frame_idx[OC_FRAME_PREV];
-    ystride=_enc->state.ref_frame_bufs[prev_refi][pli].ystride;
-    for(;sb<sb_end;sb++){
-      int quadi;
-      sb->coded_fully=1;
-      sb->coded_partially=0;
-      for(quadi=0;quadi<4;quadi++)if(sb->quad_valid&1<<quadi){
-        int bi;
-        for(bi=0;bi<4;bi++){
-          int fragi;
-          fragi=sb->map[quadi][bi];
-          if(fragi>=0){
-            oc_fragment *frag;
-            int          flag;
-            frag=_enc->state.frags+fragi;
-            if(frag->invalid){
-              frag->coded=0;
-              *(_enc->state.uncoded_fragis-++nuncoded_fragis)=fragi;
-            }
-            else{
-              oc_fragment_enc_info *efrag;
-              ogg_int16_t           dct_buf[64];
-              int                   ci;
-              /*Check to see if the fragment can be skipped.
-                It is assumed that a skipped fragment always takes fewer bits
-                 than a coded fragment, though this may not necessarily be true.
-                A single skipped fragment could take up to 34 bits to encode
-                 its location in the RLE scheme Theora uses */
-              oc_frag_intra_fdct(frag,dct_buf,ystride,prev_refi);
-              efrag=_enc->frinfo+fragi;
-              /*The comparison against OC_DC_QUANT_MIN and OC_AC_QUANT_MIN
-                 ensures we mark a fragment as skipped if it would be quantized
-                 to all zeros in OC_MODE_INTER_NOMV.
-                These minimum quantizers represent the maximum quality the
-                 format is capable of, and can be larger than our tolerances.
-                The minimum for INTER modes is twice the minimum for INTRA
-                 modes, so technically if the tolerances are below this
-                 threshold, we might be able to do a better job representing
-                 this fragment by coding it in INTRA mode.
-                But the number of extra bits required to do that would be
-                 ridiculous, so we give up our devotion to minimum quality just
-                 this once.
-
-                Note: OC_DC_QUANT_MIN[0] should actually be
-                 OC_DC_QUANT_MIN[1]>>1, but in this case those are
-                 equivalent.*/
-              ci=0;
-              if((unsigned)abs(dct_buf[0]-efrag->dct_coeffs[0])<=
-               OC_MAXI(efrag->tols[0],OC_DC_QUANT_MIN[0])){
-                for(ci++;ci<64;ci++){
-                  if((unsigned)abs(dct_buf[ci]-efrag->dct_coeffs[ci])>
-                   OC_MAXI(efrag->tols[ci],OC_AC_QUANT_MIN[0])){
-                    break;
-                  }
-                }
-              }
-              if(ci>=64){
-                frag->coded=0;
-                *(_enc->state.uncoded_fragis-++nuncoded_fragis)=fragi;
-              }
-              else{
-                frag->coded=1;
-                _enc->state.coded_fragis[ncoded_fragis++]=fragi;
-              }
-            }
-            flag=frag->coded;
-            sb->coded_fully&=flag;
-            sb->coded_partially|=flag;
-            _enc->block_coded_flags[bli++]=(char)flag;
-          }
-        }
-      }
-      /*If this is a partially coded super block, keep the entries just added
-         to the code block flag list.*/
-      if(!sb->coded_fully&&sb->coded_partially){
-        _enc->nblock_coded_flags=bli;
-      }
-      /*Otherwise, discard these entries from the list, as they are
-         implicit.*/
-      else{
-        sb->coded_partially=0;
-        bli=_enc->nblock_coded_flags;
-      }
-    }
-    _enc->state.ncoded_fragis[pli]=ncoded_fragis-prev_ncoded_fragis;
-    prev_ncoded_fragis=ncoded_fragis;
-    _enc->state.nuncoded_fragis[pli]=nuncoded_fragis-prev_nuncoded_fragis;
-    prev_nuncoded_fragis=nuncoded_fragis;
-  }
-  _enc->ncoded_frags=ncoded_fragis;
-}
-
-/*Selects an appropriate coding mode for each macro block.
-  A mode is chosen for the macro blocks with at least one coded fragment.
-  A bit cost estimate for coding the frame with the selected modes is made,
-   and a similar estimate is made for coding the frame as a key frame.
-  These estimates are used to select the optimal frame type.
-  Return: The frame type to encode with: OC_INTER_FRAME or OC_INTRA_FRAME.*/
-static int oc_enc_choose_mbmodes(oc_enc_ctx *_enc){
-  oc_set_chroma_mvs_func  set_chroma_mvs;
-  oc_fragment_enc_info   *efrag;
-  oc_fragment            *frag;
-  oc_mb                  *mb;
-  oc_mb_enc_info         *mbinfo;
-  char                    last_mv[2][2];
-  int                    *uncoded_fragi;
-  int                    *uncoded_fragi_end;
-  int                     best_qii;
-  int                     qii;
-  int                     qi;
-  int                     pli;
-  int                     mbi;
-  int                     fragi;
-  int                     ci;
-  int                     nmbs;
-  int                     mvbitsa;
-  int                     mvbitsb;
-  int                     intra_bits;
-  int                     inter_bits;
-  nmbs=_enc->state.nmbs;
-  set_chroma_mvs=OC_SET_CHROMA_MVS_TABLE[_enc->state.info.pixel_fmt];
-  oc_mode_scheme_chooser_reset(&_enc->mode_scheme_chooser);
-  memset(last_mv,0,sizeof(last_mv));
-  mbinfo=_enc->mbinfo;
-  mvbitsa=mvbitsb=0;
-  inter_bits=2+7*_enc->state.nqis-(_enc->state.nqis==3);
-  intra_bits=inter_bits+3;
-  _enc->state.ncoded_mbis=0;
-  for(mbi=0;mbi<nmbs;mbi++){
-    mb=_enc->state.mbs+mbi;
-    if(mb->mode!=OC_MODE_INVALID){
-      oc_fragment_enc_info *efrag;
-      char                  bmvs[2][4][2];
-      char                  mbmv[2];
-      int                   err[OC_NMODES][12];
-      int                   bits[OC_NMODES];
-      int                   coded[13];
-      int                   frag_qii[12][2][2];
-      int                   ncoded;
-      int                   ncoded_luma;
-      int                   mapii;
-      int                   mapi;
-      int                   modei;
-      int                   codedi;
-      int                   mbintrabits;
-      int                   mbpmvbitsa;
-      int                   mbgmvbitsa;
-      int                   mb4mvbitsa;
-      int                   mb4mvbitsb;
-      int                   fti;
-      int                   qti;
-      int                   bi;
-      mbinfo=_enc->mbinfo+mbi;
-      /*Build up a list of coded fragments.*/
-      ncoded=0;
-      for(mapii=0;mapii<OC_MB_MAP_NIDXS[_enc->state.info.pixel_fmt];mapii++){
-        mapi=OC_MB_MAP_IDXS[_enc->state.info.pixel_fmt][mapii];
-        fragi=mb->map[mapi>>2][mapi&3];
-        if(fragi>=0&&_enc->state.frags[fragi].coded)coded[ncoded++]=mapi;
-      }
-      /*If we don't find any, mark this MB not coded and move on.*/
-      if(ncoded<=0){
-        mb->mode=OC_MODE_NOT_CODED;
-        /*Don't bother to do a MV search against the golden frame.
-          Just re-use the last vector, which should match well since the
-           contents of the MB haven't changed much.*/
-        mbinfo->mvs[0][OC_FRAME_GOLD][0]=mbinfo->mvs[1][OC_FRAME_GOLD][0];
-        mbinfo->mvs[0][OC_FRAME_GOLD][1]=mbinfo->mvs[1][OC_FRAME_GOLD][1];
-        continue;
-      }
-      /*Count the number of coded blocks that are luma blocks, and replace the
-         block MVs for not-coded blocks with (0,0).*/
-      memcpy(bmvs[0],mbinfo->bmvs,sizeof(bmvs[0]));
-      /*Mark the end of the list so we don't go past it below.*/
-      coded[ncoded]=-1;
-      for(mapi=ncoded_luma=0;mapi<4;mapi++){
-        if(coded[ncoded_luma]==mapi)ncoded_luma++;
-        else bmvs[0][mapi][0]=bmvs[0][mapi][1]=0;
-      }
-      /*Select a qi value for each coded fragment for each frame type and
-         quantizer type.*/
-      for(codedi=0;codedi<ncoded;codedi++){
-        mapi=coded[codedi];
-        efrag=_enc->frinfo+mb->map[mapi>>2][mapi&3];
-        for(fti=0;fti<2;fti++)for(qti=0;qti<=fti;qti++){
-          best_qii=0;
-          for(qii=1;qii<_enc->nqis[fti];qii++){
-            if(efrag->qi_min[qti]<=_enc->qis[fti][qii]&&
-             (_enc->qis[fti][qii]<_enc->qis[fti][best_qii]||
-             _enc->qis[fti][best_qii]<efrag->qi_min[qti])){
-              best_qii=qii;
-            }
-          }
-          frag_qii[codedi][fti][qti]=best_qii;
-        }
-      }
-      /*Special case: If no luma blocks are coded, but some chroma blocks are,
-         then the macro block defaults to OC_MODE_INTER_NOMV, and no mode need
-         be explicitly coded for it.*/
-      if(ncoded_luma<=0){
-        mb->mode=OC_MODE_NOT_CODED;
-        /*Don't bother to do a MV search against the golden frame.*/
-        mbinfo->mvs[0][OC_FRAME_GOLD][0]=mbinfo->mvs[0][OC_FRAME_GOLD][1]=0;
-        /*We do collect bitrate stats for frame type decision.*/
-        mbintrabits=bits[OC_MODE_INTER_NOMV]=0;
-        for(codedi=0;codedi<ncoded;codedi++){
-          mapi=coded[codedi];
-          pli=mapi>>2;
-          fragi=mb->map[pli][mapi&3];
-          frag=_enc->state.frags+fragi;
-          efrag=_enc->frinfo+fragi;
-          /*Set the MB mode and MV in the fragment.*/
-          frag->mbmode=OC_MODE_INTER_NOMV;
-          frag->mv[0]=frag->mv[1]=0;
-          /*Calculate the bitrate estimates.*/
-          err[OC_MODE_INTRA][mapi]=0;
-          for(ci=1;ci<64;ci++){
-            err[OC_MODE_INTRA][mapi]+=abs(efrag->dct_coeffs[ci]);
-          }
-          err[OC_MODE_INTER_NOMV][mapi]=oc_enc_frag_sad(_enc,frag,0,0,pli,
-           OC_FRAME_PREV);
-          qi=_enc->qis[OC_INTRA_FRAME][frag_qii[codedi][OC_INTRA_FRAME][0]];
-          mbintrabits+=OC_RES_BITRATES[qi][pli][OC_MODE_INTRA][
-           OC_MINI(err[OC_MODE_INTRA][mapi]>>8,15)];
-          qi=_enc->qis[OC_INTER_FRAME][frag_qii[codedi][OC_INTER_FRAME][1]];
-          bits[OC_MODE_INTER_NOMV]+=OC_RES_BITRATES[qi][pli][
-           OC_MODE_INTER_NOMV][OC_MINI(err[OC_MODE_INTER_NOMV][mapi]>>6,15)];
-          /*Also mark this fragment with the selected INTER qi.
-            It will be reset if we eventually code this as an INTRA frame.*/
-#if defined(OC_BITRATE_STATS)
-          efrag->eerror=err[OC_MODE_INTER_NOMV][mapi];
-#endif
-          efrag->qii=(unsigned char)frag_qii[codedi][OC_INTER_FRAME][1];
-          frag->qi=qi;
-        }
-        intra_bits+=mbintrabits+(1<<OC_BIT_SCALE-1)>>OC_BIT_SCALE;
-        inter_bits+=bits[OC_MODE_INTER_NOMV]+(1<<OC_BIT_SCALE-1)>>OC_BIT_SCALE;
-        continue;
-      }
-      /*Otherwise, add this to the coded MB list.*/
-      _enc->state.coded_mbis[_enc->state.ncoded_mbis++]=mbi;
-      /*Compute the chroma MVs for the 4MV mode.*/
-      (*set_chroma_mvs)(bmvs[1],bmvs[0]);
-      /*Do a MV search against the golden frame.*/
-      oc_mcenc_search_1mv(_enc->mcenc,mb-_enc->state.mbs,OC_FRAME_GOLD);
-      /*We are now ready to do mode decision for this macro block.
-        Mode decision is done by exhaustively examining all potential choices.
-        Since we use a minimum-quality encoding strategy, this amounts to
-         simply selecting the mode which uses the smallest number of bits,
-         since the minimum quality will be met in any mode.
-        Obviously, doing the motion compensation, fDCT, tokenization, and then
-         counting the bits each token uses is computationally expensive.
-        Theora's EOB runs can also split the cost of these tokens across
-         multiple fragments, and naturally we don't know what the optimal
-         choice of Huffman codes will be until we know all the tokens we're
-         going to encode in all the fragments.
-
-        So we use a simple approach to estimating the bit cost of each mode
-         based upon the SAD value of the residual.
-        The mathematics behind the technique are outlined by Kim \cite{Kim03},
-         but the process is very simple.
-        For each quality index and SAD value, we have a table containing the
-         average number of bits needed to code a fragment.
-        The SAD values are placed into a small number of bins (currently 16).
-        The bit counts are obtained by examining actual encoded frames, with
-         optimal Huffman codes selected and EOB bits appropriately divided
-         among all the blocks they involve.
-        A separate QIxSAD table is kept for each mode and color plane.
-        It may be possible to combine many of these, but only experimentation
-         will tell which ones truly represent the same distribution.
-
-        @ARTICLE{Kim03,
-          author="Hyun Mun Kim",
-          title="Adaptive Rate Control Using Nonlinear Regression",
-          journal="IEEE Transactions on Circuits and Systems for Video
-           Technology",
-          volume=13,
-          number=5,
-          pages="432--439",
-          month="May",
-          year=2003
-        }*/
-      memset(bits,0,sizeof(bits));
-      mbintrabits=0;
-      /*Find the SAD values for each coded fragment for each possible mode.*/
-      for(codedi=0;codedi<ncoded;codedi++){
-        mapi=coded[codedi];
-        pli=mapi>>2;
-        bi=mapi&3;
-        fragi=mb->map[pli][bi];
-        frag=_enc->state.frags+fragi;
-        efrag=_enc->frinfo+fragi;
-        err[OC_MODE_INTRA][mapi]=0;
-        for(ci=1;ci<64;ci++){
-          err[OC_MODE_INTRA][mapi]+=abs(efrag->dct_coeffs[ci]);
-        }
-        err[OC_MODE_INTER_NOMV][mapi]=oc_enc_frag_sad(_enc,frag,0,0,pli,
-         OC_FRAME_PREV);
-        err[OC_MODE_INTER_MV][mapi]=oc_enc_frag_sad(_enc,frag,
-         mbinfo->mvs[0][OC_FRAME_PREV][0],mbinfo->mvs[0][OC_FRAME_PREV][1],
-         pli,OC_FRAME_PREV);
-        err[OC_MODE_INTER_MV_LAST][mapi]=oc_enc_frag_sad(_enc,frag,
-         last_mv[0][0],last_mv[0][1],pli,OC_FRAME_PREV);
-        err[OC_MODE_INTER_MV_LAST2][mapi]=oc_enc_frag_sad(_enc,frag,
-         last_mv[1][0],last_mv[1][1],pli,OC_FRAME_PREV);
-        err[OC_MODE_INTER_MV_FOUR][mapi]=oc_enc_frag_sad(_enc,frag,
-         bmvs[!!pli][bi][0],bmvs[!!pli][bi][1],pli,OC_FRAME_PREV);
-        err[OC_MODE_GOLDEN_NOMV][mapi]=oc_enc_frag_sad(_enc,frag,
-         0,0,pli,OC_FRAME_GOLD);
-        err[OC_MODE_GOLDEN_MV][mapi]=oc_enc_frag_sad(_enc,frag,
-         mbinfo->mvs[0][OC_FRAME_GOLD][0],mbinfo->mvs[0][OC_FRAME_GOLD][1],
-         pli,OC_FRAME_GOLD);
-        /*Using these distortion values, estimate the number of bits needed to
-           code this fragment in each mode.*/
-        qi=_enc->qis[OC_INTRA_FRAME][frag_qii[codedi][OC_INTRA_FRAME][0]];
-        mbintrabits+=OC_RES_BITRATES[qi][pli][OC_MODE_INTRA][
-         OC_MINI(err[OC_MODE_INTRA][mapi]>>8,15)];
-        qi=_enc->qis[OC_INTER_FRAME][frag_qii[codedi][OC_INTER_FRAME][0]];
-        bits[OC_MODE_INTRA]+=OC_RES_BITRATES[qi][pli][OC_MODE_INTRA][
-         OC_MINI(err[OC_MODE_INTRA][mapi]>>8,15)];
-        qi=_enc->qis[OC_INTER_FRAME][frag_qii[codedi][OC_INTER_FRAME][1]];
-        for(modei=OC_MODE_INTRA+1;modei<OC_NMODES;modei++){
-          bits[modei]+=OC_RES_BITRATES[qi][pli][modei][
-           OC_MINI(err[modei][mapi]>>6,15)];
-        }
-      }
-      /*Bit costs are stored in the table with extra precision.
-        Round them down to whole bits here.*/
-      for(modei=0;modei<OC_NMODES;modei++){
-        bits[modei]=bits[modei]+(1<<OC_BIT_SCALE-1)>>OC_BIT_SCALE;
-      }
-      /*Estimate the cost of coding the label for each mode.
-        See comments at oc_mode_scheme_chooser_cost() for a description of the
-         method.*/
-      for(modei=0;modei<OC_NMODES;modei++){
-        bits[modei]+=oc_mode_scheme_chooser_cost(&_enc->mode_scheme_chooser,
-         modei);
-      }
-      /*Add the motion vector bits for each mode that requires them.*/
-      mbpmvbitsa=oc_mvbitsa(mbinfo->mvs[0][OC_FRAME_PREV][0],
-       mbinfo->mvs[0][OC_FRAME_PREV][1]);
-      mbgmvbitsa=oc_mvbitsa(mbinfo->mvs[1][OC_FRAME_GOLD][0],
-       mbinfo->mvs[0][OC_FRAME_GOLD][1]);
-      mb4mvbitsa=mb4mvbitsb=0;
-      for(codedi=0;codedi<ncoded_luma;codedi++){
-        mb4mvbitsa=oc_mvbitsa(bmvs[0][coded[codedi]][0],
-         bmvs[0][coded[codedi]][1]);
-        mb4mvbitsb+=12;
-      }
-      /*We use the same opportunity cost method of estimating the cost of
-         coding the motion vectors with the two different schemes as we do for
-         estimating the cost of the mode labels.
-        However, because there are only two schemes and they're both pretty
-         simple, this can just be done inline.*/
-      bits[OC_MODE_INTER_MV]+=OC_MINI(mvbitsa+mbpmvbitsa,mvbitsb+12)-
-       OC_MINI(mvbitsa,mvbitsb);
-      bits[OC_MODE_GOLDEN_MV]+=OC_MINI(mvbitsa+mbgmvbitsa,mvbitsb+12)-
-       OC_MINI(mvbitsa,mvbitsb);
-      bits[OC_MODE_INTER_MV_FOUR]+=OC_MINI(mvbitsa+mb4mvbitsa,
-       mvbitsb+mb4mvbitsb)-OC_MINI(mvbitsa,mvbitsb);
-      /*Finally, pick the mode with the cheapest estimated bit cost.*/
-      mb->mode=0;
-      for(modei=1;modei<OC_NMODES;modei++)if(bits[modei]<bits[mb->mode]){
-        /*Do not select 4MV mode when not all the luma blocks are coded when
-           we're in VP3 compatibility mode.*/
-        if(_enc->vp3_compatible&&modei==OC_MODE_INTER_MV_FOUR&&ncoded_luma<4){
-          continue;
-        }
-        mb->mode=modei;
-      }
-#if defined(OC_BITRATE_STATS)
-      /*Remember the error for the mode we selected in each fragment.*/
-      for(codedi=0;codedi<ncoded;codedi++){
-        mapi=coded[codedi];
-        fragi=mb->map[mapi>>2][mapi&3];
-        efrag=_enc->frinfo+fragi;
-        efrag->eerror=err[mb->mode][mapi];
-      }
-#endif
-      /*Go back and store the selected qi index corresponding to the selected
-         mode in each fragment.*/
-      for(codedi=0;codedi<ncoded;codedi++){
-        mapi=coded[codedi];
-        fragi=mb->map[mapi>>2][mapi&3];
-        frag=_enc->state.frags+fragi;
-        efrag=_enc->frinfo+fragi;
-        efrag->qii=(unsigned char)
-         frag_qii[codedi][OC_INTER_FRAME][mb->mode!=0];
-        frag->qi=_enc->qis[OC_INTER_FRAME][efrag->qii];
-      }
-      inter_bits+=bits[mb->mode];
-      intra_bits+=mbintrabits+(1<<OC_BIT_SCALE-1)>>OC_BIT_SCALE;
-      oc_mode_scheme_chooser_update(&_enc->mode_scheme_chooser,mb->mode);
-      switch(mb->mode){
-        case OC_MODE_INTER_MV:{
-          mvbitsa+=mbpmvbitsa;
-          mvbitsb+=12;
-          last_mv[1][0]=last_mv[0][0];
-          last_mv[1][1]=last_mv[0][1];
-          mbmv[0]=last_mv[0][0]=mbinfo->mvs[0][OC_FRAME_PREV][0];
-          mbmv[1]=last_mv[0][1]=mbinfo->mvs[0][OC_FRAME_PREV][1];
-        }break;
-        case OC_MODE_INTER_MV_LAST:{
-          mbmv[0]=last_mv[0][0];
-          mbmv[1]=last_mv[0][1];
-        }break;
-        case OC_MODE_INTER_MV_LAST2:{
-          mbmv[0]=last_mv[1][0];
-          mbmv[1]=last_mv[1][1];
-          last_mv[1][0]=last_mv[0][0];
-          last_mv[1][1]=last_mv[0][1];
-          last_mv[0][0]=mbmv[0];
-          last_mv[0][1]=mbmv[1];
-        }break;
-        case OC_MODE_INTER_MV_FOUR:{
-          mvbitsa+=mb4mvbitsa;
-          mvbitsb+=mb4mvbitsb;
-          if(ncoded_luma>0){
-            /*After 4MV mode, the last MV is the one from the last coded luma
-               block.*/
-            last_mv[1][0]=last_mv[0][0];
-            last_mv[1][1]=last_mv[0][1];
-            last_mv[0][0]=bmvs[0][coded[ncoded_luma-1]][0];
-            last_mv[0][1]=bmvs[0][coded[ncoded_luma-1]][1];
-          }
-        }break;
-        case OC_MODE_GOLDEN_MV:{
-          mvbitsa+=mbgmvbitsa;
-          mvbitsb+=12;
-          mbmv[0]=mbinfo->mvs[0][OC_FRAME_GOLD][0];
-          mbmv[1]=mbinfo->mvs[0][OC_FRAME_GOLD][1];
-        }break;
-      }
-      if(OC_MODE_HAS_MV[mb->mode]){
-        /*Special case 4MV mode.
-          MVs are stored in bmvs.*/
-        if(mb->mode==OC_MODE_INTER_MV_FOUR){
-          for(codedi=0;codedi<ncoded;codedi++){
-            mapi=coded[codedi];
-            pli=mapi>>2;
-            bi=mapi&3;
-            fragi=mb->map[pli][bi];
-            frag=_enc->state.frags+fragi;
-            frag->mbmode=mb->mode;
-            frag->mv[0]=bmvs[!!pli][bi][0];
-            frag->mv[1]=bmvs[!!pli][bi][1];
-          }
-        }
-        /*For every other mode with a MV, it is stored in mbmv.*/
-        else{
-          for(codedi=0;codedi<ncoded;codedi++){
-            mapi=coded[codedi];
-            fragi=mb->map[mapi>>2][mapi&3];
-            frag=_enc->state.frags+fragi;
-            frag->mbmode=mb->mode;
-            frag->mv[0]=mbmv[0];
-            frag->mv[1]=mbmv[1];
-          }
-        }
-      }
-      /*For modes with no MV, ensure 0,0 is stored in each fragment.*/
-      else{
-        for(codedi=0;codedi<ncoded;codedi++){
-          mapi=coded[codedi];
-          fragi=mb->map[mapi>>2][mapi&3];
-          frag=_enc->state.frags+fragi;
-          frag->mbmode=mb->mode;
-          frag->mv[0]=frag->mv[1]=0;
-        }
-      }
-    }
-  }
-  /*Finally, compare the cost of an INTER frame and an INTRA frame.*/
-  if(mvbitsb<mvbitsa){
-    _enc->mv_scheme=1;
-    inter_bits+=mvbitsb;
-  }
-  else{
-    _enc->mv_scheme=0;
-    inter_bits+=mvbitsa;
-  }
-  inter_bits+=_enc->mode_scheme_chooser.scheme_bits[
-   _enc->mode_scheme_chooser.scheme_list[0]];
-  /*The easiest way to count the bits needed for coded/not coded fragments is
-     to code them.
-    We need to do this anyway, might as well do it now.*/
-  oggpackB_reset(&_enc->opb_coded_flags);
-  inter_bits+=oc_enc_partial_sb_flags_pack(_enc,&_enc->opb_coded_flags);
-  inter_bits+=oc_enc_coded_sb_flags_pack(_enc,&_enc->opb_coded_flags);
-  inter_bits+=oc_enc_coded_block_flags_pack(_enc,&_enc->opb_coded_flags);
-  /*Select the quantizer list for INTER frames.*/
-  _enc->state.nqis=_enc->nqis[OC_INTER_FRAME];
-  for(qii=0;qii<_enc->state.nqis;qii++){
-    _enc->state.qis[qii]=_enc->qis[OC_INTER_FRAME][qii];
-  }
-  if(intra_bits>inter_bits){
-    _enc->vbr->est_bits=inter_bits;
-    return OC_INTER_FRAME;
-  }
-  /*All INTRA mode is smaller, but we haven't counted up the cost of all the
-     not coded fragments we will now have to code.*/
-  uncoded_fragi_end=uncoded_fragi=_enc->state.uncoded_fragis;
-  for(pli=0;pli<3;pli++){
-    uncoded_fragi_end-=_enc->state.nuncoded_fragis[pli];
-    while(uncoded_fragi-->uncoded_fragi_end){
-      fragi=*uncoded_fragi;
-      frag=_enc->state.frags+fragi;
-      /*Assume a very small bit cost for invalid fragments.*/
-      if(frag->invalid)intra_bits+=OC_RES_BITRATES[0][pli][OC_MODE_INTRA][0];
-      else{
-        int eerror;
-        eerror=0;
-        efrag=_enc->frinfo+fragi;
-        for(ci=1;ci<64;ci++)eerror+=abs(efrag->dct_coeffs[ci]);
-#if defined(OC_BITRATE_STATS)
-        efrag->eerror=eerror;
-#endif
-        qi=_enc->qis[OC_INTRA_FRAME][0];
-        for(qii=1;qii<_enc->nqis[OC_INTRA_FRAME];qii++){
-          if(_enc->qis[OC_INTRA_FRAME][qii]<qi&&
-           efrag->qi_min[0]<=_enc->qis[OC_INTRA_FRAME][qii]){
-            qi=_enc->qis[OC_INTRA_FRAME][qii];
-          }
-        }
-        intra_bits+=OC_RES_BITRATES[qi][pli][OC_MODE_INTRA][
-         OC_MINI(eerror>>8,15)];
-        /*If it turns out INTRA mode was more expensive, we're done.*/
-        if(intra_bits>inter_bits){
-          _enc->vbr->est_bits=inter_bits;
-          return OC_INTER_FRAME;
-        }
-      }
-    }
-  }
-  /*So, we've compared the full cost estimates, and INTRA is still better.
-    Code an INTRA frame instead.*/
-  oc_enc_vbr_mark_all_intra(_enc);
-  _enc->vbr->est_bits=intra_bits;
-  return OC_INTRA_FRAME;
-}
-
-/*A pipeline stage for transforming, quantizing, and tokenizing the frame.*/
-
-static int oc_vbr_pipe_start(oc_enc_pipe_stage *_stage){
-  int pli;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=0;
-  return 0;
-}
-
-static int oc_vbr_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  int pli;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=_y_avail[pli];
-  return 0;
-}
-
-static int oc_vbr_pipe_end(oc_enc_pipe_stage *_stage){
-  oc_enc_ctx *enc;
-  int         ret;
-  enc=_stage->enc;
-  if(enc->state.curframe_num==0||
-   enc->state.curframe_num-enc->state.keyframe_num>=
-   enc->keyframe_frequency_force){
-    enc->state.frame_type=OC_INTRA_FRAME;
-    oc_enc_vbr_quant_sel_quality(enc,1);
-    oc_enc_vbr_mark_all_intra(enc);
-  }
-  else{
-    oc_enc_vbr_mark_coded(enc);
-    /*Only proceed if we have some coded blocks.
-      No coded blocks -> dropped frame -> 0 byte packet.*/
-    if(enc->ncoded_frags>0){
-      oc_enc_vbr_quant_sel_quality(enc,0);
-      enc->state.frame_type=oc_enc_choose_mbmodes(enc);
-      if(enc->state.frame_type==OC_INTER_FRAME)oc_enc_do_inter_dcts(enc);
-    }
-  }
-  /*Only initialize subsequent stages after we know how many fragments will be
-     encoded, and at what quality (so the loop filter can be set up
-     properly).*/
-  if(_stage->next!=NULL){
-    ret=(*_stage->next->pipe_start)(_stage->next);
-    if(ret<0)return ret;
-  }
-  if(enc->ncoded_frags>0){
-    /*TODO: These stages could be pipelined with reconstruction.*/
-    oc_enc_vbr_quant_dc(enc);
-    oc_enc_vbr_residual_tokenize(enc);
-  }
-  if(_stage->next!=NULL){
-    ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-    if(ret<0)return ret;
-    return (*_stage->next->pipe_end)(_stage->next);
-  }
-  return 0;
-}
-
-/*Initialize the transform, quantization, and tokenization stage of the
-   pipeline.
-  _enc: The encoding context.*/
-static void oc_vbr_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_vbr_pipe_start;
-  _stage->pipe_proc=oc_vbr_pipe_process;
-  _stage->pipe_end=oc_vbr_pipe_end;
-}
-
-
-static int oc_enc_vbr_init(oc_enc_vbr_ctx *_vbr,oc_enc_ctx *_enc){
-  _vbr->cfg.qi=_enc->state.info.quality;
-  _vbr->cfg.kf_qi_min=_vbr->cfg.df_qi_min=0;
-  _vbr->cfg.kf_qi_max=_vbr->cfg.df_qi_max=63;
-  _vbr->enc=_enc;
-  _vbr->impmap=oc_impmap_alloc(_enc);
-  _vbr->psych=oc_psych_alloc(_enc);
-  oc_vbr_pipe_init(&_vbr->pipe,_enc);
-  return 0;
-}
-
-static void oc_enc_vbr_clear(oc_enc_vbr_ctx *_vbr){
-  oc_psych_free(_vbr->psych);
-  oc_impmap_free(_vbr->impmap);
-}
-
-static int oc_enc_vbr_cfg(oc_enc_vbr_ctx *_vbr,th_vbr_cfg *_cfg){
-  if(_cfg->qi<0||_cfg->qi>63||_cfg->kf_qi_min<0||_cfg->kf_qi_min>63||
-   _cfg->kf_qi_max<_cfg->kf_qi_min||_cfg->kf_qi_max>63||
-   _cfg->df_qi_min<0||_cfg->df_qi_min>63||
-   _cfg->df_qi_max<_cfg->df_qi_min||_cfg->df_qi_max>63){
-    return TH_EINVAL;
-  }
-  memcpy(&_vbr->cfg,_cfg,sizeof(_vbr->cfg));
-  return 0;
-}
-
-static oc_enc_pipe_stage *oc_enc_vbr_create_pipe(oc_enc_vbr_ctx *_vbr){
-  oc_enc_pipe_stage *pipe;
-  _vbr->enc->fill_pipe.next=&_vbr->enc->pack_pipe;
-  _vbr->pipe.next=&_vbr->enc->copy_pipe;
-  /*TODO: Disable spatial masking and CSF filtering based on
-     application-specified speed level.*/
-  pipe=oc_psych_prepend_to_pipe(_vbr->psych,&_vbr->pipe);
-  _vbr->enc->fdct_pipe.next=pipe;
-  /*TODO: Disable impmap based on application-specified speed level.*/
-  pipe=oc_impmap_prepend_to_pipe(_vbr->impmap,&_vbr->enc->fdct_pipe);
-  pipe=oc_mcenc_prepend_to_pipe(_vbr->enc->mcenc,pipe);
-  return pipe;
-}
-
-
-oc_enc_vbr_ctx *oc_enc_vbr_alloc(oc_enc_ctx *_enc){
-  oc_enc_vbr_ctx *vbr;
-  vbr=(oc_enc_vbr_ctx *)_ogg_malloc(sizeof(*vbr));
-  oc_enc_vbr_init(vbr,_enc);
-  return vbr;
-}
-
-void oc_enc_vbr_free(oc_enc_vbr_ctx *_vbr){
-  if(_vbr!=NULL){
-    oc_enc_vbr_clear(_vbr);
-    _ogg_free(_vbr);
-  }
-}
-
-int oc_enc_vbr_enable(oc_enc_vbr_ctx *_vbr,th_vbr_cfg *_cfg){
-  if(_cfg!=NULL){
-    int ret;
-    ret=oc_enc_vbr_cfg(_vbr,_cfg);
-    if(ret<0)return ret;
-  }
-  /*Map the qi to a multiple of JND values.*/
-  _vbr->qscale=_vbr->cfg.qi>=63?0.5F:1.5F*OC_POWF(2,0.0625F*(64-_vbr->cfg.qi));
-  _vbr->enc->pipe=oc_enc_vbr_create_pipe(_vbr);
-  /*TODO: Implement a real speed level.*/
-  _vbr->enc->speed_max=0;
-  _vbr->enc->set_speed=oc_enc_set_speed_null;
-  return 0;
-}

Deleted: experimental/j/theora-mashup/lib/dec/encvbr.h
===================================================================
--- experimental/j/theora-mashup/lib/dec/encvbr.h	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/encvbr.h	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,43 +0,0 @@
-#if !defined(_encvbr_H)
-# define _encvbr_H (1)
-# include "encint.h"
-
-
-
-typedef struct oc_impmap_ctx oc_impmap_ctx;
-typedef struct oc_psych_ctx  oc_psych_ctx;
-
-
-
-/*Context information for the VBR encoder.*/
-struct oc_enc_vbr_ctx{
-  /*Configuration information.*/
-  th_vbr_cfg     cfg;
-  /*The main VBR encoder's pipe stage.*/
-  oc_enc_pipe_stage  pipe;
-  /*The scale factor for the current quality setting.*/
-  float              qscale;
-  /*Minimum psychovisual tolerance for the DC coefficients in each plane.*/
-  unsigned           dc_tol_mins[3];
-  /*The estimated bit cost of the current frame.*/
-  int                est_bits;
-  /*The encode context.*/
-  oc_enc_ctx        *enc;
-  /*Context information used to generate the importance map.*/
-  oc_impmap_ctx     *impmap;
-  /*Context information used to generate low-level perceptual weightings.*/
-  oc_psych_ctx      *psych;
-};
-
-
-oc_impmap_ctx *oc_impmap_alloc(oc_enc_ctx *_enc);
-void oc_impmap_free(oc_impmap_ctx *_impmap);
-oc_enc_pipe_stage *oc_impmap_prepend_to_pipe(oc_impmap_ctx *_impmap,
- oc_enc_pipe_stage *_next);
-
-oc_psych_ctx *oc_psych_alloc(oc_enc_ctx *_enc);
-void oc_psych_free(oc_psych_ctx *_psych);
-oc_enc_pipe_stage *oc_psych_prepend_to_pipe(oc_psych_ctx *_psych,
- oc_enc_pipe_stage *_next);
-
-#endif

Deleted: experimental/j/theora-mashup/lib/dec/enquant.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/enquant.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/enquant.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,867 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <ogg/ogg.h>
-#include "enquant.h"
-#include "internal.h"
-
-
-/*The default quantization parameters used by VP3.1.*/
-static const int OC_VP31_RANGE_SIZES[1]={63};
-static const th_quant_base OC_VP31_BASES_INTRA_Y[2]={
-  {
-     16, 11, 10, 16, 24,  40, 51, 61,
-     12, 12, 14, 19, 26,  58, 60, 55,
-     14, 13, 16, 24, 40,  57, 69, 56,
-     14, 17, 22, 29, 51,  87, 80, 62,
-     18, 22, 37, 58, 68, 109,103, 77,
-     24, 35, 55, 64, 81, 104,113, 92,
-     49, 64, 78, 87,103, 121,120,101,
-     72, 92, 95, 98,112, 100,103, 99
-  },
-  {
-     16, 11, 10, 16, 24,  40, 51, 61,
-     12, 12, 14, 19, 26,  58, 60, 55,
-     14, 13, 16, 24, 40,  57, 69, 56,
-     14, 17, 22, 29, 51,  87, 80, 62,
-     18, 22, 37, 58, 68, 109,103, 77,
-     24, 35, 55, 64, 81, 104,113, 92,
-     49, 64, 78, 87,103, 121,120,101,
-     72, 92, 95, 98,112, 100,103, 99
-  }
-};
-static const th_quant_base OC_VP31_BASES_INTRA_C[2]={
-  {
-     17, 18, 24, 47, 99, 99, 99, 99,
-     18, 21, 26, 66, 99, 99, 99, 99,
-     24, 26, 56, 99, 99, 99, 99, 99,
-     47, 66, 99, 99, 99, 99, 99, 99,
-     99, 99, 99, 99, 99, 99, 99, 99,
-     99, 99, 99, 99, 99, 99, 99, 99,
-     99, 99, 99, 99, 99, 99, 99, 99,
-     99, 99, 99, 99, 99, 99, 99, 99
-  },
-  {
-     17, 18, 24, 47, 99, 99, 99, 99,
-     18, 21, 26, 66, 99, 99, 99, 99,
-     24, 26, 56, 99, 99, 99, 99, 99,
-     47, 66, 99, 99, 99, 99, 99, 99,
-     99, 99, 99, 99, 99, 99, 99, 99,
-     99, 99, 99, 99, 99, 99, 99, 99,
-     99, 99, 99, 99, 99, 99, 99, 99,
-     99, 99, 99, 99, 99, 99, 99, 99
-  }
-};
-static const th_quant_base OC_VP31_BASES_INTER[2]={
-  {
-     16, 16, 16, 20, 24, 28, 32, 40,
-     16, 16, 20, 24, 28, 32, 40, 48,
-     16, 20, 24, 28, 32, 40, 48, 64,
-     20, 24, 28, 32, 40, 48, 64, 64,
-     24, 28, 32, 40, 48, 64, 64, 64,
-     28, 32, 40, 48, 64, 64, 64, 96,
-     32, 40, 48, 64, 64, 64, 96,128,
-     40, 48, 64, 64, 64, 96,128,128
-  },
-  {
-     16, 16, 16, 20, 24, 28, 32, 40,
-     16, 16, 20, 24, 28, 32, 40, 48,
-     16, 20, 24, 28, 32, 40, 48, 64,
-     20, 24, 28, 32, 40, 48, 64, 64,
-     24, 28, 32, 40, 48, 64, 64, 64,
-     28, 32, 40, 48, 64, 64, 64, 96,
-     32, 40, 48, 64, 64, 64, 96,128,
-     40, 48, 64, 64, 64, 96,128,128
-  }
-};
-
-const th_quant_info TH_VP31_QUANT_INFO={
-  {
-    220,200,190,180,170,170,160,160,
-    150,150,140,140,130,130,120,120,
-    110,110,100,100, 90, 90, 90, 80,
-     80, 80, 70, 70, 70, 60, 60, 60,
-     60, 50, 50, 50, 50, 40, 40, 40,
-     40, 40, 30, 30, 30, 30, 30, 30,
-     30, 20, 20, 20, 20, 20, 20, 20,
-     20, 10, 10, 10, 10, 10, 10, 10
-  },
-  {
-    500,450,400,370,340,310,285,265,
-    245,225,210,195,185,180,170,160,
-    150,145,135,130,125,115,110,107,
-    100, 96, 93, 89, 85, 82, 75, 74,
-     70, 68, 64, 60, 57, 56, 52, 50,
-     49, 45, 44, 43, 40, 38, 37, 35,
-     33, 32, 30, 29, 28, 25, 24, 22,
-     21, 19, 18, 17, 15, 13, 12, 10
-  },
-  {
-    30,25,20,20,15,15,14,14,
-    13,13,12,12,11,11,10,10,
-     9, 9, 8, 8, 7, 7, 7, 7,
-     6, 6, 6, 6, 5, 5, 5, 5,
-     4, 4, 4, 4, 3, 3, 3, 3,
-     2, 2, 2, 2, 2, 2, 2, 2,
-     0, 0, 0, 0, 0, 0, 0, 0,
-     0, 0, 0, 0, 0, 0, 0, 0
-  },
-  {
-    {
-      {1,OC_VP31_RANGE_SIZES,OC_VP31_BASES_INTRA_Y},
-      {1,OC_VP31_RANGE_SIZES,OC_VP31_BASES_INTRA_C},
-      {1,OC_VP31_RANGE_SIZES,OC_VP31_BASES_INTRA_C}
-    },
-    {
-      {1,OC_VP31_RANGE_SIZES,OC_VP31_BASES_INTER},
-      {1,OC_VP31_RANGE_SIZES,OC_VP31_BASES_INTER},
-      {1,OC_VP31_RANGE_SIZES,OC_VP31_BASES_INTER}
-    }
-  }
-};
-
-
-
-static const int OC_DEF_QRANGE_SIZES[3]={15,16,32};
-
-static const th_quant_base OC_DEF_BASE_MATRICES[9][4]={
-  /*Y' matrices, 4:4:4 subsampling.*/
-  {
-    /*qi=0.*/
-    {
-      255, 54, 54, 54, 55, 57, 63, 71,
-       54, 54, 54, 54, 55, 58, 63, 71,
-       54, 54, 54, 54, 55, 58, 63, 72,
-       54, 54, 54, 55, 55, 58, 63, 72,
-       55, 55, 55, 55, 56, 59, 64, 73,
-       57, 58, 58, 58, 59, 62, 67, 76,
-       63, 63, 63, 63, 64, 67, 73, 83,
-       71, 71, 72, 72, 73, 76, 83, 94
-    },
-    /*qi=15.*/
-    {
-      255, 48, 48, 48, 49, 51, 56, 64,
-       48, 48, 48, 48, 49, 51, 56, 65,
-       48, 48, 48, 48, 49, 51, 57, 65,
-       48, 48, 48, 48, 49, 52, 57, 65,
-       49, 49, 49, 49, 50, 52, 58, 66,
-       51, 51, 51, 52, 52, 55, 61, 69,
-       56, 56, 57, 57, 58, 61, 67, 76,
-       64, 65, 65, 65, 66, 69, 76, 87
-    },
-    /*qi=31.*/
-    {
-      255, 46, 46, 46, 47, 49, 54, 62,
-       46, 46, 46, 46, 47, 50, 55, 63,
-       46, 46, 46, 46, 47, 50, 55, 63,
-       46, 46, 46, 47, 47, 50, 55, 63,
-       47, 47, 47, 47, 48, 51, 56, 64,
-       49, 50, 50, 50, 51, 53, 59, 67,
-       54, 55, 55, 55, 56, 59, 65, 74,
-       62, 63, 63, 63, 64, 67, 74, 86
-    },
-    /*qi=63.*/
-    {
-      255, 45, 45, 46, 46, 49, 54, 62,
-       45, 46, 46, 46, 46, 49, 54, 62,
-       45, 46, 46, 46, 47, 49, 54, 62,
-       46, 46, 46, 46, 47, 49, 54, 62,
-       46, 46, 47, 47, 47, 50, 55, 63,
-       49, 49, 49, 49, 50, 53, 58, 67,
-       54, 54, 54, 54, 55, 58, 64, 74,
-       62, 62, 62, 62, 63, 67, 74, 85
-    }
-  },
-  /*Cb matrices, 4:4:4 subsampling.*/
-  {
-    /*qi=0.*/
-    {
-      149, 34, 37, 41, 45, 49, 54, 60,
-       34, 38, 41, 46, 50, 55, 61, 67,
-       37, 41, 45, 49, 54, 60, 66, 73,
-       41, 46, 49, 54, 60, 66, 72, 80,
-       45, 50, 54, 60, 65, 72, 79, 88,
-       49, 55, 60, 66, 72, 79, 87, 96,
-       54, 61, 66, 72, 79, 87, 96,106,
-       60, 67, 73, 80, 88, 96,106,117
-    },
-    /*qi=15.*/
-    {
-      149, 31, 34, 37, 41, 46, 51, 56,
-       31, 35, 38, 42, 47, 52, 57, 63,
-       34, 38, 42, 46, 51, 56, 62, 69,
-       37, 42, 46, 51, 56, 62, 69, 76,
-       41, 47, 51, 56, 62, 69, 76, 84,
-       46, 52, 56, 62, 69, 76, 84, 93,
-       51, 57, 62, 69, 76, 84, 93,103,
-       56, 63, 69, 76, 84, 93,103,115
-    },
-    /*qi=31.*/
-    {
-      149, 30, 33, 36, 40, 45, 49, 55,
-       30, 34, 37, 41, 46, 51, 56, 62,
-       33, 37, 41, 45, 50, 55, 61, 68,
-       36, 41, 45, 50, 55, 61, 68, 75,
-       40, 46, 50, 55, 61, 68, 75, 83,
-       45, 51, 55, 61, 68, 75, 83, 93,
-       49, 56, 61, 68, 75, 83, 92,102,
-       55, 62, 68, 75, 83, 93,102,114
-    },
-    /*qi=63.*/
-    {
-      149, 30, 33, 36, 40, 44, 49, 55,
-       30, 34, 37, 41, 45, 50, 56, 62,
-       33, 37, 40, 45, 50, 55, 61, 68,
-       36, 41, 45, 50, 55, 61, 67, 75,
-       40, 45, 50, 55, 61, 68, 75, 83,
-       44, 50, 55, 61, 68, 75, 83, 92,
-       49, 56, 61, 67, 75, 83, 92,102,
-       55, 62, 68, 75, 83, 92,102,114
-    }
-  },
-  /*Cb matrices, 4:2:2 subsampling.*/
-  {
-    /*qi=0.*/
-    {
-      142, 31, 32, 34, 36, 38, 40, 42,
-       33, 35, 36, 38, 40, 42, 44, 47,
-       35, 38, 39, 41, 43, 46, 48, 51,
-       39, 41, 43, 45, 48, 50, 53, 55,
-       43, 45, 47, 50, 52, 55, 58, 61,
-       47, 50, 52, 55, 58, 61, 64, 67,
-       52, 55, 57, 60, 63, 67, 70, 74,
-       57, 61, 63, 67, 70, 74, 77, 81
-    },
-    /*qi=15.*/
-    {
-      142, 28, 29, 31, 33, 34, 36, 38,
-       30, 32, 33, 35, 37, 39, 41, 43,
-       32, 34, 36, 38, 40, 42, 45, 47,
-       36, 38, 40, 42, 44, 47, 49, 52,
-       39, 42, 44, 46, 49, 52, 54, 58,
-       44, 46, 49, 51, 54, 57, 60, 64,
-       48, 51, 54, 57, 60, 63, 67, 70,
-       53, 57, 60, 63, 66, 70, 74, 78
-    },
-    /*qi=31.*/
-    {
-      142, 27, 28, 30, 32, 33, 35, 37,
-       29, 31, 32, 34, 36, 38, 40, 42,
-       31, 33, 35, 37, 39, 41, 44, 46,
-       35, 37, 39, 41, 43, 46, 48, 51,
-       38, 41, 43, 45, 48, 51, 54, 57,
-       43, 45, 48, 50, 53, 56, 59, 63,
-       47, 50, 53, 56, 59, 62, 66, 70,
-       52, 56, 59, 62, 65, 69, 73, 77
-    },
-    /*qi=63.*/
-    {
-      142, 27, 28, 30, 31, 33, 35, 37,
-       28, 30, 32, 34, 35, 38, 40, 42,
-       31, 33, 35, 37, 39, 41, 43, 46,
-       34, 37, 39, 41, 43, 45, 48, 51,
-       38, 41, 43, 45, 48, 50, 53, 56,
-       42, 45, 47, 50, 53, 56, 59, 63,
-       47, 50, 52, 55, 59, 62, 65, 69,
-       52, 56, 58, 62, 65, 69, 73, 77
-    }
-  },
-  /*Cb matrices, subsampling in the Y direction.*/
-  {
-    /*qi=0.*/
-    {
-      142, 33, 35, 39, 43, 47, 52, 57,
-       31, 35, 38, 41, 45, 50, 55, 61,
-       32, 36, 39, 43, 47, 52, 57, 63,
-       34, 38, 41, 45, 50, 55, 60, 67,
-       36, 40, 43, 48, 52, 58, 63, 70,
-       38, 42, 46, 50, 55, 61, 67, 74,
-       40, 44, 48, 53, 58, 64, 70, 77,
-       42, 47, 51, 55, 61, 67, 74, 81
-    },
-    /*qi=15.*/
-    {
-      142, 30, 32, 36, 39, 44, 48, 53,
-       28, 32, 34, 38, 42, 46, 51, 57,
-       29, 33, 36, 40, 44, 49, 54, 60,
-       31, 35, 38, 42, 46, 51, 57, 63,
-       33, 37, 40, 44, 49, 54, 60, 66,
-       34, 39, 42, 47, 52, 57, 63, 70,
-       36, 41, 45, 49, 54, 60, 67, 74,
-       38, 43, 47, 52, 58, 64, 70, 78
-    },
-    /*qi=31.*/
-    {
-      142, 29, 31, 35, 38, 43, 47, 52,
-       27, 31, 33, 37, 41, 45, 50, 56,
-       28, 32, 35, 39, 43, 48, 53, 59,
-       30, 34, 37, 41, 45, 50, 56, 62,
-       32, 36, 39, 43, 48, 53, 59, 65,
-       33, 38, 41, 46, 51, 56, 62, 69,
-       35, 40, 44, 48, 54, 59, 66, 73,
-       37, 42, 46, 51, 57, 63, 70, 77
-    },
-    /*qi=63.*/
-    {
-      142, 28, 31, 34, 38, 42, 47, 52,
-       27, 30, 33, 37, 41, 45, 50, 56,
-       28, 32, 35, 39, 43, 47, 52, 58,
-       30, 34, 37, 41, 45, 50, 55, 62,
-       31, 35, 39, 43, 48, 53, 59, 65,
-       33, 38, 41, 45, 50, 56, 62, 69,
-       35, 40, 43, 48, 53, 59, 65, 73,
-       37, 42, 46, 51, 56, 63, 69, 77
-    }
-  },
-  /*Cb matrices, 4:2:0 subsampling.*/
-  {
-    /*qi=0.*/
-    {
-      135, 30, 31, 33, 34, 36, 38, 40,
-       30, 32, 33, 35, 36, 38, 40, 42,
-       31, 33, 34, 36, 38, 40, 42, 44,
-       33, 35, 36, 38, 40, 42, 44, 46,
-       34, 36, 38, 40, 42, 44, 46, 49,
-       36, 38, 40, 42, 44, 46, 49, 51,
-       38, 40, 42, 44, 46, 49, 51, 54,
-       40, 42, 44, 46, 49, 51, 54, 57
-    },
-    /*qi=15.*/
-    {
-      135, 27, 28, 29, 31, 33, 35, 36,
-       27, 28, 30, 31, 33, 35, 37, 39,
-       28, 30, 31, 33, 35, 37, 39, 41,
-       29, 31, 33, 35, 37, 39, 41, 43,
-       31, 33, 35, 37, 39, 41, 43, 45,
-       33, 35, 37, 39, 41, 43, 45, 48,
-       35, 37, 39, 41, 43, 45, 48, 51,
-       36, 39, 41, 43, 45, 48, 51, 53
-    },
-    /*qi=31.*/
-    {
-      135, 26, 27, 28, 30, 32, 34, 36,
-       26, 28, 29, 30, 32, 34, 36, 38,
-       27, 29, 30, 32, 34, 36, 38, 40,
-       28, 30, 32, 34, 36, 38, 40, 42,
-       30, 32, 34, 36, 38, 40, 42, 44,
-       32, 34, 36, 38, 40, 42, 44, 47,
-       34, 36, 38, 40, 42, 44, 47, 50,
-       36, 38, 40, 42, 44, 47, 50, 52
-    },
-    /*qi=63.*/
-    {
-      135, 25, 27, 28, 30, 31, 33, 35,
-       25, 27, 29, 30, 32, 34, 36, 38,
-       27, 29, 30, 32, 33, 35, 37, 40,
-       28, 30, 32, 33, 35, 37, 39, 42,
-       30, 32, 33, 35, 37, 39, 42, 44,
-       31, 34, 35, 37, 39, 42, 44, 47,
-       33, 36, 37, 39, 42, 44, 47, 49,
-       35, 38, 40, 42, 44, 47, 49, 52
-    }
-  },
-  /*Cr matrices, 4:4:4 subsampling.*/
-  {
-    /*qi=0.*/
-    {
-      195, 46, 52, 59, 67, 77, 88,101,
-       46, 54, 60, 69, 78, 89,102,117,
-       52, 60, 68, 77, 87,100,114,131,
-       59, 69, 77, 87, 99,114,130,149,
-       67, 78, 87, 99,113,130,148,170,
-       77, 89,100,114,130,148,169,194,
-       88,102,114,130,148,169,193,222,
-      101,117,131,149,170,194,222,255
-    },
-    /*qi=15.*/
-    {
-      195, 42, 48, 55, 63, 72, 83, 96,
-       42, 50, 56, 64, 74, 85, 98,113,
-       48, 56, 63, 73, 83, 96,110,127,
-       55, 64, 73, 83, 95,110,126,146,
-       63, 74, 83, 95,110,126,145,167,
-       72, 85, 96,110,126,145,166,192,
-       83, 98,110,126,145,166,191,221,
-       96,113,127,146,167,192,221,255
-    },
-    /*qi=31.*/
-    {
-      195, 41, 47, 53, 61, 71, 81, 94,
-       41, 49, 55, 63, 73, 84, 96,111,
-       47, 55, 62, 71, 82, 95,109,126,
-       53, 63, 71, 82, 94,109,125,145,
-       61, 73, 82, 94,108,125,144,166,
-       71, 84, 95,109,125,144,166,192,
-       81, 96,109,125,144,166,191,220,
-       94,111,126,145,166,192,220,255
-    },
-    /*qi=63.*/
-    {
-      195, 41, 46, 53, 61, 70, 81, 94,
-       41, 48, 55, 63, 72, 83, 96,111,
-       46, 55, 62, 71, 82, 94,108,125,
-       53, 63, 71, 82, 94,108,125,144,
-       61, 72, 82, 94,108,125,144,166,
-       70, 83, 94,108,125,144,165,191,
-       81, 96,108,125,144,165,190,220,
-       94,111,125,144,166,191,220,255
-    }
-  },
-  /*Cr matrices, 4:2:2 subsampling.*/
-  {
-    /*qi=0.*/
-    {
-      183, 41, 43, 46, 49, 53, 57, 61,
-       44, 47, 50, 54, 58, 62, 66, 71,
-       49, 53, 56, 60, 64, 69, 74, 79,
-       56, 60, 64, 68, 73, 78, 84, 90,
-       63, 69, 73, 78, 83, 89, 96,103,
-       72, 79, 83, 89, 95,102,109,118,
-       83, 90, 95,102,109,117,125,134,
-       95,103,109,117,125,134,144,154
-    },
-    /*qi=15.*/
-    {
-      183, 37, 39, 42, 45, 49, 53, 57,
-       40, 43, 46, 50, 53, 58, 62, 67,
-       45, 49, 52, 56, 60, 65, 70, 75,
-       51, 56, 60, 64, 69, 74, 80, 86,
-       59, 64, 69, 74, 79, 85, 92, 99,
-       68, 74, 79, 85, 91, 98,106,114,
-       78, 85, 91, 97,105,113,121,131,
-       90, 98,105,112,121,130,140,151
-    },
-    /*qi=31.*/
-    {
-      183, 36, 38, 41, 44, 48, 51, 55,
-       39, 42, 45, 48, 52, 56, 61, 66,
-       44, 48, 51, 55, 59, 64, 69, 74,
-       50, 55, 59, 63, 68, 73, 79, 85,
-       58, 63, 67, 72, 78, 84, 91, 98,
-       66, 73, 78, 83, 90, 97,104,113,
-       76, 84, 89, 96,103,112,120,130,
-       88, 97,103,111,120,129,139,150
-    },
-    /*qi=63.*/
-    {
-      183, 35, 38, 41, 44, 47, 51, 55,
-       38, 42, 45, 48, 52, 56, 60, 65,
-       43, 47, 51, 54, 59, 63, 68, 74,
-       50, 54, 58, 63, 67, 73, 78, 85,
-       57, 63, 67, 72, 78, 84, 90, 98,
-       66, 72, 77, 83, 90, 97,104,112,
-       76, 83, 89, 96,103,111,120,129,
-       88, 96,103,111,119,129,139,150
-    }
-  },
-  /*Cr matrices, subsampling in the Y direction.*/
-  {
-    /*qi=0.*/
-    {
-      183, 44, 49, 56, 63, 72, 83, 95,
-       41, 47, 53, 60, 69, 79, 90,103,
-       43, 50, 56, 64, 73, 83, 95,109,
-       46, 54, 60, 68, 78, 89,102,117,
-       49, 58, 64, 73, 83, 95,109,125,
-       53, 62, 69, 78, 89,102,117,134,
-       57, 66, 74, 84, 96,109,125,144,
-       61, 71, 79, 90,103,118,134,154
-    },
-    /*qi=15.*/
-    {
-      183, 40, 45, 51, 59, 68, 78, 90,
-       37, 43, 49, 56, 64, 74, 85, 98,
-       39, 46, 52, 60, 69, 79, 91,105,
-       42, 50, 56, 64, 74, 85, 97,112,
-       45, 53, 60, 69, 79, 91,105,121,
-       49, 58, 65, 74, 85, 98,113,130,
-       53, 62, 70, 80, 92,106,121,140,
-       57, 67, 75, 86, 99,114,131,151
-    },
-    /*qi=31.*/
-    {
-      183, 39, 44, 50, 58, 66, 76, 88,
-       36, 42, 48, 55, 63, 73, 84, 97,
-       38, 45, 51, 59, 67, 78, 89,103,
-       41, 48, 55, 63, 72, 83, 96,111,
-       44, 52, 59, 68, 78, 90,103,120,
-       48, 56, 64, 73, 84, 97,112,129,
-       51, 61, 69, 79, 91,104,120,139,
-       55, 66, 74, 85, 98,113,130,150
-    },
-    /*qi=63.*/
-    {
-      183, 38, 43, 50, 57, 66, 76, 88,
-       35, 42, 47, 54, 63, 72, 83, 96,
-       38, 45, 51, 58, 67, 77, 89,103,
-       41, 48, 54, 63, 72, 83, 96,111,
-       44, 52, 59, 67, 78, 90,103,119,
-       47, 56, 63, 73, 84, 97,111,129,
-       51, 60, 68, 78, 90,104,120,139,
-       55, 65, 74, 85, 98,112,129,150
-    }
-  },
-  /*Cr matrices, 4:2:0 subsampling.*/
-  {
-    /*qi=0.*/
-    {
-      172, 38, 41, 44, 47, 50, 54, 58,
-       38, 42, 44, 47, 51, 54, 58, 62,
-       41, 44, 47, 50, 54, 57, 62, 66,
-       44, 47, 50, 54, 57, 61, 66, 71,
-       47, 51, 54, 57, 61, 66, 70, 76,
-       50, 54, 57, 61, 66, 70, 75, 81,
-       54, 58, 62, 66, 70, 75, 81, 87,
-       58, 62, 66, 71, 76, 81, 87, 93
-    },
-    /*qi=15.*/
-    {
-      172, 35, 37, 40, 43, 46, 49, 53,
-       35, 38, 40, 43, 47, 50, 54, 58,
-       37, 40, 43, 46, 50, 53, 57, 62,
-       40, 43, 46, 50, 53, 57, 62, 67,
-       43, 47, 50, 53, 57, 62, 66, 72,
-       46, 50, 53, 57, 62, 66, 71, 77,
-       49, 54, 57, 62, 66, 71, 77, 83,
-       53, 58, 62, 67, 72, 77, 83, 89
-    },
-    /*qi=31.*/
-    {
-      172, 34, 36, 38, 41, 45, 48, 52,
-       34, 37, 39, 42, 45, 49, 53, 57,
-       36, 39, 42, 45, 48, 52, 56, 61,
-       38, 42, 45, 48, 52, 56, 61, 65,
-       41, 45, 48, 52, 56, 61, 65, 70,
-       45, 49, 52, 56, 61, 65, 70, 76,
-       48, 53, 56, 61, 65, 70, 76, 82,
-       52, 57, 61, 65, 70, 76, 82, 88
-    },
-    /*qi=63.*/
-    {
-      172, 33, 35, 38, 41, 44, 48, 52,
-       33, 36, 39, 42, 45, 49, 52, 57,
-       35, 39, 41, 45, 48, 52, 56, 60,
-       38, 42, 45, 48, 52, 56, 60, 65,
-       41, 45, 48, 52, 56, 60, 65, 70,
-       44, 49, 52, 56, 60, 65, 70, 76,
-       48, 52, 56, 60, 65, 70, 75, 81,
-       52, 57, 60, 65, 70, 76, 81, 88
-    }
-  }
-};
-
-const th_quant_info OC_DEF_QUANT_INFO[4]={
-  {
-    {
-        15,  14,  13,  13,  12,  12,  11,  11,
-        10,  10,   9,   9,   8,   8,   8,   7,
-         7,   7,   6,   6,   6,   6,   5,   5,
-         5,   5,   4,   4,   4,   4,   4,   3,
-         3,   3,   3,   3,   3,   3,   2,   2,
-         2,   2,   2,   2,   2,   2,   2,   1,
-         1,   1,   1,   1,   1,   1,   1,   1,
-         1,   1,   1,   1,   1,   1,   1,   1
-    },
-    {
-        71,  68,  65,  64,  62,  59,  57,  55,
-        53,  51,  50,  48,  46,  44,  43,  41,
-        40,  38,  36,  35,  33,  32,  31,  29,
-        29,  27,  26,  25,  24,  23,  22,  21,
-        20,  19,  19,  18,  17,  16,  16,  15,
-        14,  14,  13,  12,  12,  11,  11,  10,
-        10,  10,   9,   9,   8,   8,   8,   7,
-         7,   7,   6,   6,   6,   6,   5,   1
-    },
-    {
-        77,  74,  71,  68,  65,  62,  60,  57,
-        55,  52,  50,  48,  46,  44,  42,  40,
-        39,  37,  35,  34,  33,  31,  30,  29,
-        27,  26,  25,  24,  23,  22,  21,  20,
-        19,  19,  18,  17,  16,  16,  15,  14,
-        14,  13,  13,  12,  12,  11,  11,  10,
-        10,   9,   9,   8,   8,   8,   7,   7,
-         7,   7,   6,   6,   6,   6,   5,   2
-    },
-    {
-      {
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[0]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[4]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[8]}
-      },
-      {
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[0]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[4]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[8]}
-      }
-    }
-  },
-  {
-    {
-        15,  14,  13,  13,  12,  12,  11,  11,
-        10,  10,   9,   9,   8,   8,   8,   7,
-         7,   7,   6,   6,   6,   6,   5,   5,
-         5,   5,   4,   4,   4,   4,   4,   3,
-         3,   3,   3,   3,   3,   3,   2,   2,
-         2,   2,   2,   2,   2,   2,   2,   1,
-         1,   1,   1,   1,   1,   1,   1,   1,
-         1,   1,   1,   1,   1,   1,   1,   1
-    },
-    {
-        71,  68,  65,  64,  62,  59,  57,  55,
-        53,  51,  50,  48,  46,  44,  43,  41,
-        40,  38,  36,  35,  33,  32,  31,  29,
-        29,  27,  26,  25,  24,  23,  22,  21,
-        20,  19,  19,  18,  17,  16,  16,  15,
-        14,  14,  13,  12,  12,  11,  11,  10,
-        10,  10,   9,   9,   8,   8,   8,   7,
-         7,   7,   6,   6,   6,   6,   5,   1
-    },
-    {
-        77,  74,  71,  68,  65,  62,  60,  57,
-        55,  52,  50,  48,  46,  44,  42,  40,
-        39,  37,  35,  34,  33,  31,  30,  29,
-        27,  26,  25,  24,  23,  22,  21,  20,
-        19,  19,  18,  17,  16,  16,  15,  14,
-        14,  13,  13,  12,  12,  11,  11,  10,
-        10,   9,   9,   8,   8,   8,   7,   7,
-         7,   7,   6,   6,   6,   6,   5,   2
-    },
-    {
-      {
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[0]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[3]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[7]}
-      },
-      {
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[0]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[3]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[7]}
-      }
-    }
-  },
-  {
-    {
-        15,  14,  13,  13,  12,  12,  11,  11,
-        10,  10,   9,   9,   8,   8,   8,   7,
-         7,   7,   6,   6,   6,   6,   5,   5,
-         5,   5,   4,   4,   4,   4,   4,   3,
-         3,   3,   3,   3,   3,   3,   2,   2,
-         2,   2,   2,   2,   2,   2,   2,   1,
-         1,   1,   1,   1,   1,   1,   1,   1,
-         1,   1,   1,   1,   1,   1,   1,   1
-    },
-    {
-        71,  68,  65,  64,  62,  59,  57,  55,
-        53,  51,  50,  48,  46,  44,  43,  41,
-        40,  38,  36,  35,  33,  32,  31,  29,
-        29,  27,  26,  25,  24,  23,  22,  21,
-        20,  19,  19,  18,  17,  16,  16,  15,
-        14,  14,  13,  12,  12,  11,  11,  10,
-        10,  10,   9,   9,   8,   8,   8,   7,
-         7,   7,   6,   6,   6,   6,   5,   1
-    },
-    {
-        77,  74,  71,  68,  65,  62,  60,  57,
-        55,  52,  50,  48,  46,  44,  42,  40,
-        39,  37,  35,  34,  33,  31,  30,  29,
-        27,  26,  25,  24,  23,  22,  21,  20,
-        19,  19,  18,  17,  16,  16,  15,  14,
-        14,  13,  13,  12,  12,  11,  11,  10,
-        10,   9,   9,   8,   8,   8,   7,   7,
-         7,   7,   6,   6,   6,   6,   5,   2
-    },
-    {
-      {
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[0]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[2]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[6]}
-      },
-      {
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[0]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[2]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[6]}
-      }
-    }
-  },
-  {
-    {
-        15,  14,  13,  13,  12,  12,  11,  11,
-        10,  10,   9,   9,   8,   8,   8,   7,
-         7,   7,   6,   6,   6,   6,   5,   5,
-         5,   5,   4,   4,   4,   4,   4,   3,
-         3,   3,   3,   3,   3,   3,   2,   2,
-         2,   2,   2,   2,   2,   2,   2,   1,
-         1,   1,   1,   1,   1,   1,   1,   1,
-         1,   1,   1,   1,   1,   1,   1,   1
-    },
-    {
-        71,  68,  65,  64,  62,  59,  57,  55,
-        53,  51,  50,  48,  46,  44,  43,  41,
-        40,  38,  36,  35,  33,  32,  31,  29,
-        29,  27,  26,  25,  24,  23,  22,  21,
-        20,  19,  19,  18,  17,  16,  16,  15,
-        14,  14,  13,  12,  12,  11,  11,  10,
-        10,  10,   9,   9,   8,   8,   8,   7,
-         7,   7,   6,   6,   6,   6,   5,   1
-    },
-    {
-        77,  74,  71,  68,  65,  62,  60,  57,
-        55,  52,  50,  48,  46,  44,  42,  40,
-        39,  37,  35,  34,  33,  31,  30,  29,
-        27,  26,  25,  24,  23,  22,  21,  20,
-        19,  19,  18,  17,  16,  16,  15,  14,
-        14,  13,  13,  12,  12,  11,  11,  10,
-        10,   9,   9,   8,   8,   8,   7,   7,
-         7,   7,   6,   6,   6,   6,   5,   2
-    },
-    {
-      {
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[0]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[1]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[5]}
-      },
-      {
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[0]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[1]},
-        {3,OC_DEF_QRANGE_SIZES,OC_DEF_BASE_MATRICES[5]}
-      }
-    }
-  }
-};
-
-
-void oc_quant_params_pack(oggpack_buffer *_opb,
- const th_quant_info *_qinfo){
-  const th_quant_ranges *qranges;
-  const th_quant_base   *base_mats[2*3*64];
-  int                        indices[2][3][64];
-  int                        nbase_mats;
-  int                        nbits;
-  int                        ci;
-  int                        qi;
-  int                        qri;
-  int                        qti;
-  int                        pli;
-  int                        qtj;
-  int                        plj;
-  int                        bmi;
-  int                        i;
-  /*323 bits for the defaults.*/
-  /*Unlike the scale tables, we can't assume the maximum value will be in
-     index 0, so search for it here.*/
-  i=_qinfo->loop_filter_limits[0];
-  for(qi=1;qi<64;qi++)i=OC_MAXI(i,_qinfo->loop_filter_limits[qi]);
-  nbits=oc_ilog(i);
-  oggpackB_write(_opb,nbits,3);
-  for(qi=0;qi<64;qi++){
-    oggpackB_write(_opb,_qinfo->loop_filter_limits[qi],nbits);
-  }
-  /*452 bits for the defaults, 580 for VP3.*/
-  nbits=OC_MAXI(oc_ilog(_qinfo->ac_scale[0]),1);
-  oggpackB_write(_opb,nbits-1,4);
-  for(qi=0;qi<64;qi++)oggpackB_write(_opb,_qinfo->ac_scale[qi],nbits);
-  /*260 bits for the defaults, 516 for VP3.*/
-  nbits=OC_MAXI(oc_ilog(_qinfo->dc_scale[0]),1);
-  oggpackB_write(_opb,nbits-1,4);
-  for(qi=0;qi<64;qi++)oggpackB_write(_opb,_qinfo->dc_scale[qi],nbits);
-  /*Consolidate any duplicate base matrices.*/
-  nbase_mats=0;
-  for(qti=0;qti<2;qti++)for(pli=0;pli<3;pli++){
-    qranges=_qinfo->qi_ranges[qti]+pli;
-    for(qri=0;qri<=qranges->nranges;qri++){
-      for(bmi=0;;bmi++){
-        if(bmi>=nbase_mats){
-          base_mats[bmi]=qranges->base_matrices+qri;
-          indices[qti][pli][qri]=nbase_mats++;
-          break;
-        }
-        else if(memcmp(base_mats[bmi][0],qranges->base_matrices[qri],
-         sizeof(base_mats[bmi][0]))==0){
-          indices[qti][pli][qri]=bmi;
-          break;
-        }
-      }
-    }
-  }
-  /*Write out the list of unique base matrices.
-    6153 bits for our default matrices, 1545 bits for VP3 matrices.*/
-  oggpackB_write(_opb,nbase_mats-1,9);
-  for(bmi=0;bmi<nbase_mats;bmi++){
-    for(ci=0;ci<64;ci++)oggpackB_write(_opb,base_mats[bmi][0][ci],8);
-  }
-  /*Now store quant ranges and their associated indices into the base matrix
-     list.
-    236 bits for our default matrices, 46 bits for VP3 matrices.*/
-  nbits=oc_ilog(nbase_mats-1);
-  for(i=0;i<6;i++){
-    qti=i/3;
-    pli=i%3;
-    qranges=_qinfo->qi_ranges[qti]+pli;
-    if(i>0){
-      if(qti>0){
-        if(qranges->nranges==_qinfo->qi_ranges[qti-1][pli].nranges&&
-         memcmp(qranges->sizes,_qinfo->qi_ranges[qti-1][pli].sizes,
-         qranges->nranges*sizeof(qranges->sizes[0]))==0&&
-         memcmp(indices[qti][pli],indices[qti-1][pli],
-         (qranges->nranges+1)*sizeof(indices[qti][pli][0]))==0){
-          oggpackB_write(_opb,1,2);
-          continue;
-        }
-      }
-      qtj=(i-1)/3;
-      plj=(i-1)%3;
-      if(qranges->nranges==_qinfo->qi_ranges[qtj][plj].nranges&&
-       memcmp(qranges->sizes,_qinfo->qi_ranges[qtj][plj].sizes,
-       qranges->nranges*sizeof(qranges->sizes[0]))==0&&
-       memcmp(indices[qti][pli],indices[qtj][plj],
-       (qranges->nranges+1)*sizeof(indices[qti][pli][0]))==0){
-        oggpackB_write(_opb,0,1+(qti>0));
-        continue;
-      }
-      oggpackB_write(_opb,1,1);
-    }
-    oggpackB_write(_opb,indices[qti][pli][0],nbits);
-    for(qi=qri=0;qi<63;qri++){
-      oggpackB_write(_opb,qranges->sizes[qri]-1,oc_ilog(62-qi));
-      qi+=qranges->sizes[qri];
-      oggpackB_write(_opb,indices[qti][pli][qri+1],nbits);
-    }
-  }
-}
-
-
-
-/*See comments at oc_dequant_tables_init() for how the quantization tables'
-   storage should be initialized.*/
-void oc_enquant_tables_init(oc_quant_table *_dequant[2][3],
- oc_quant_table *_enquant[2][3],const th_quant_info *_qinfo){
-  int qti;
-  int pli;
-  /*Initialize the dequantization tables first.*/
-  oc_dequant_tables_init(_dequant,NULL,_qinfo);
-  /*Derive the quantization tables directly from the dequantization tables.*/
-  for(qti=0;qti<2;qti++)for(pli=0;pli<3;pli++){
-    int qi;
-    /*These simple checks help us improve cache coherency later.*/
-    if(pli>0&&_dequant[qti][pli]==_dequant[qti][pli-1]){
-      _enquant[qti][pli]=_enquant[qti][pli-1];
-      continue;
-    }
-    if(qti>0&&_dequant[qti][pli]==_dequant[qti-1][pli]){
-      _enquant[qti][pli]=_enquant[qti-1][pli];
-      continue;
-    }
-    for(qi=0;qi<64;qi++){
-      int ci;
-      /*All of that VP3.2 floating point code has been implemented as integer
-         code with exact precision.
-        I.e., (ogg_uint16_t)(1.0/q*OC_FQUANT_SCALE+0.5) has become
-         (2*OC_FQUANT_SCALE+q)/(q<<1).*/
-      for(ci=0;ci<64;ci++){
-        ogg_uint32_t q;
-        q=_dequant[qti][pli][qi][ci];
-        _enquant[qti][pli][qi][ci]=(ogg_uint16_t)(
-         (2*OC_FQUANT_SCALE+q)/(q<<1));
-      }
-    }
-  }
-}

Deleted: experimental/j/theora-mashup/lib/dec/fdct.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/fdct.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/fdct.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,446 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "dct.h"
-#include "fdct.h"
-
-
-
-/*Performs a forward 8 point Type-II DCT transform.
-  The output is scaled by a factor of 2 from the orthonormal version of the
-   transform.
-  _y: The buffer to store the result in.
-      Data will be placed in every 8th entry (e.g., in a column of an 8x8
-       block).
-  _x: The input coefficients.
-      The first 8 entries are used (e.g., from a row of an 8x8 block).*/
-static void fdct8(ogg_int16_t *_y,const ogg_int16_t _x[8]){
-  ogg_int32_t t[9];
-  ogg_int32_t r;
-  /*Stage 1:*/
-  /*0-7 butterfly.*/
-  t[0]=_x[0]+(ogg_int32_t)_x[7];
-  /*1-6 butterfly.*/
-  t[1]=_x[1]+(ogg_int32_t)_x[6];
-  /*2-5 butterfly.*/
-  t[2]=_x[2]+(ogg_int32_t)_x[5];
-  /*3-4 butterfly.*/
-  t[3]=_x[3]+(ogg_int32_t)_x[4];
-  t[4]=_x[3]-(ogg_int32_t)_x[4];
-  t[5]=_x[2]-(ogg_int32_t)_x[5];
-  t[6]=_x[1]-(ogg_int32_t)_x[6];
-  t[7]=_x[0]-(ogg_int32_t)_x[7];
-  /*Stage 2:*/
-  /*0-3 butterfly.*/
-  r=t[0]+t[3];
-  t[3]=t[0]-t[3];
-  t[0]=r;
-  /*1-2 butterfly.*/
-  r=t[1]+t[2];
-  t[2]=t[1]-t[2];
-  t[1]=r;
-  /*6-5 butterfly.*/
-  r=t[6]-t[5];
-  t[6]=OC_DIV2_16(OC_C4S4*(t[6]+t[5]));
-  t[5]=OC_DIV2_16(OC_C4S4*r);
-  /*Stage 3:*/
-  /*4-5 butterfly.*/
-  r=t[4]+t[5];
-  t[5]=t[4]-t[5];
-  t[4]=r;
-  /*7-6 butterfly.*/
-  r=t[7]+t[6];
-  t[6]=t[7]-t[6];
-  t[7]=r;
-  /*0-1 butterfly.*/
-  _y[0<<3]=(ogg_int16_t)(OC_DIV2_16(OC_C4S4*(t[0]+t[1])));
-  _y[4<<3]=(ogg_int16_t)(OC_DIV2_16(OC_C4S4*(t[0]-t[1])));
-  /*3-2 rotation by 6pi/16*/
-  _y[2<<3]=(ogg_int16_t)(OC_DIV2_16(OC_C2S6*t[3])+OC_DIV2_16(OC_C6S2*t[2]));
-  _y[6<<3]=(ogg_int16_t)(OC_DIV2_16(OC_C6S2*t[3])-OC_DIV2_16(OC_C2S6*t[2]));
-  /*Stage 4:*/
-  /*7-4 rotation by 7pi/16*/
-  _y[1<<3]=(ogg_int16_t)(OC_DIV2_16(OC_C1S7*t[7])+OC_DIV2_16(OC_C7S1*t[4]));
-  /*6-5 rotation by 3pi/16*/
-  _y[5<<3]=(ogg_int16_t)(OC_DIV2_16(OC_C5S3*t[6])+OC_DIV2_16(OC_C3S5*t[5]));
-  _y[3<<3]=(ogg_int16_t)(OC_DIV2_16(OC_C3S5*t[6])-OC_DIV2_16(OC_C5S3*t[5]));
-  _y[7<<3]=(ogg_int16_t)(OC_DIV2_16(OC_C7S1*t[7])-OC_DIV2_16(OC_C1S7*t[4]));
-}
-
-/*Performs a forward 8x8 Type-II DCT transform.
-  The output is scaled by a factor of 4 relative to the orthonormal version
-   of the transform.
-  _y: The buffer to store the result in.
-      This may be the same as _x.
-  _x: The input coefficients. */
-void oc_fdct8x8(ogg_int16_t _y[64],const ogg_int16_t _x[64]){
-  const ogg_int16_t *in;
-  ogg_int16_t       *end;
-  ogg_int16_t       *out;
-  ogg_int16_t        w[64];
-  /*Transform rows of x into columns of w.*/
-  for(in=_x,out=w,end=out+8;out<end;in+=8,out++)fdct8(out,in);
-  /*Transform rows of w into columns of y.*/
-  for(in=w,out=_y,end=out+8;out<end;in+=8,out++)fdct8(out,in);
-}
-
-/*Information needed to pad boundary blocks.
-  We multiply each row/column by an extension matrix that fills in the padding
-   values as a linear combination of the active values, so that an equivalent
-   number of coefficients are forced to zero.
-  This costs at most 16 multiplies, the same as a 1-D fDCT itself, and as
-   little as 7 multiplies.
-  We compute the extension matrices for every possible shape in advance, as
-   there are only 35.
-  The coefficients for all matrices are stored in a single array to take
-   advantage of the overlap and repetitiveness of many of the shapes.
-  A similar technique is applied to the offsets into this array.
-  This reduces the required table storage by about 48%.
-  See tools/extgen.c for details.
-  We could conceivably do the same for all 256 possible shapes.*/
-typedef struct oc_extension_info{
-  /*The mask of the active pixels in the shape.*/
-  short                     mask;
-  /*The number of active pixels in the shape.*/
-  short                     na;
-  /*The extension matrix.
-    This is (8-na)xna*/
-  const ogg_int32_t *const *ext;
-  /*The pixel indices: na active pixels followed by 8-na padding pixels.*/
-  unsigned char             pi[8];
-  /*The coefficient indices: na unconstrained coefficients followed by 8-na
-     coefficients to be forced to zero.*/
-  unsigned char             ci[8];
-}oc_extension_info;
-
-
-
-/*The precision at which the matrix coefficients are stored.*/
-#define OC_EXT_SHIFT (19)
-
-/*The number of shapes we need.*/
-#define OC_NSHAPES   (35)
-
-static const ogg_int32_t OC_EXT_COEFFS[231]={
-   0x80000,-0x1E085,-0x96FC9,-0x55871, 0x55871, 0x96FC9, 0x1E085, 0x96FC9,
-   0x55871,-0x55871,-0x96FC9,-0x1E085, 0x80000, 0x00000, 0x00000, 0x00000,
-   0x80000, 0x00000, 0x00000, 0x80000,-0x80000, 0x80000, 0x00000, 0x00000,
-   0x80000,-0x1E086, 0x1E086,-0x4F591,-0x55E37, 0x337C7, 0x8C148, 0x43448,
-   0x2266F, 0x43448, 0x8C148, 0x337C7,-0x55E37,-0x4F591,-0x75743, 0x4F591,
-   0x03B45,-0x1D29D, 0x929E0, 0x2CF2A, 0x929E0,-0x1D29D, 0x03B45, 0x4F591,
-  -0x75743, 0x11033, 0x7AEF5, 0x5224C,-0x209FA,-0x3D77A,-0x209FA, 0x5224C,
-   0x7AEF5, 0x11033, 0x668A4,-0x29124, 0x3A15B, 0x0E6BD,-0x05F98, 0x0E6BD,
-   0x3A15B,-0x29124, 0x668A4, 0x2A78F, 0x24019,-0x67F0F, 0x50F49, 0x4881E,
-   0x50F49,-0x67F0F, 0x24019, 0x2A78F,-0x06898, 0x27678, 0x5F220, 0x27678,
-  -0x06898, 0x1F910, 0x76C13,-0x16523, 0x76C13, 0x1F910, 0x9EB2C,-0x2E7B1,
-   0x0FC86,-0x2E7B1, 0x9EB2C, 0x4F594, 0x43452,-0x129E6, 0x43452, 0x4F594,
-  -0x0A8C0, 0x5D997, 0x2CF29, 0x5D997,-0x0A8C0, 0x30FBD,-0x0B7E5,-0x6AC38,
-  -0x153C8, 0x8B7E5, 0x4F043, 0x8B7E5,-0x153C8,-0x6AC38,-0x0B7E5, 0x30FBD,
-  -0x5A827, 0x153C8, 0x6AC38, 0x3C7A2, 0x1E085, 0x3C7A2, 0x6AC38, 0x153C8,
-  -0x5A827, 0x5A827, 0x6AC38, 0x153C8,-0x3C7A2,-0x1E085,-0x3C7A2, 0x153C8,
-   0x6AC38, 0x5A827, 0x30FBB, 0x4F045, 0x273D7,-0x273D7, 0x273D7, 0x1E08B,
-   0x61F75, 0x1E08B, 0x273D7,-0x273D7, 0x273D7, 0x4F045, 0x30FBB,-0x273D7,
-   0x273D7, 0x9E08B,-0x1E08B, 0x9E08B, 0x273D7,-0x273D7, 0x4F045, 0x30FBB,
-  -0x273D7, 0x273D7,-0x273D7, 0x30FBB, 0x4F045, 0x1FC86, 0x67AC8, 0x18538,
-  -0x1FC86, 0x18538, 0x67AC8, 0x1FC86, 0x45460,-0x1FC87, 0x1FC87, 0x3ABA0,
-   0x1FC87,-0x1FC87, 0x45460, 0x35052, 0x5586D,-0x0A8BF, 0x5586D, 0x35052,
-  -0x43EF2, 0x78F43, 0x4AFAE,-0x070BD, 0x3C10E, 0x3C10E,-0x070BD, 0x4AFAE,
-   0x78F43,-0x43EF2, 0x3C10E, 0x78F43,-0x35052, 0x78F43, 0x3C10E, 0x070BD,
-   0x236D6, 0x5586D, 0x236D6, 0x070BD,-0x07755, 0x3C79F, 0x4AFB6,-0x190D2,
-   0x4E11C, 0x9FC86, 0x153C4,-0x3504A, 0xAC38E, 0x08CBB, 0x1E086,-0x1E086,
-   0x80000, 0x08CBB, 0xAC38E,-0x3504A, 0x153C4, 0x9FC86, 0x4E11C,-0x190D2,
-   0x4AFB6, 0x3C79F,-0x07755,-0x5A818, 0xDA818,-0x5A818,-0x101C31, 0x181C31,
-  -0x101C31,-0xD0C67, 0x150C67,-0xD0C67,-0x7643F, 0xF643F,-0x7643F
-};
-
-static const ogg_int32_t *const OC_EXT_ROWS[96]={
-  OC_EXT_COEFFS+   0,OC_EXT_COEFFS+   0,OC_EXT_COEFFS+   0,OC_EXT_COEFFS+   0,
-  OC_EXT_COEFFS+   0,OC_EXT_COEFFS+   0,OC_EXT_COEFFS+   0,OC_EXT_COEFFS+   6,
-  OC_EXT_COEFFS+  27,OC_EXT_COEFFS+  38,OC_EXT_COEFFS+  43,OC_EXT_COEFFS+  32,
-  OC_EXT_COEFFS+  49,OC_EXT_COEFFS+  58,OC_EXT_COEFFS+  67,OC_EXT_COEFFS+  71,
-  OC_EXT_COEFFS+  62,OC_EXT_COEFFS+  53,OC_EXT_COEFFS+  12,OC_EXT_COEFFS+  15,
-  OC_EXT_COEFFS+  14,OC_EXT_COEFFS+  13,OC_EXT_COEFFS+  76,OC_EXT_COEFFS+  81,
-  OC_EXT_COEFFS+  86,OC_EXT_COEFFS+  91,OC_EXT_COEFFS+  96,OC_EXT_COEFFS+  98,
-  OC_EXT_COEFFS+  93,OC_EXT_COEFFS+  88,OC_EXT_COEFFS+  83,OC_EXT_COEFFS+  78,
-  OC_EXT_COEFFS+  12,OC_EXT_COEFFS+  15,OC_EXT_COEFFS+  15,OC_EXT_COEFFS+  12,
-  OC_EXT_COEFFS+  12,OC_EXT_COEFFS+  15,OC_EXT_COEFFS+  12,OC_EXT_COEFFS+  15,
-  OC_EXT_COEFFS+  15,OC_EXT_COEFFS+  12,OC_EXT_COEFFS+ 101,OC_EXT_COEFFS+ 106,
-  OC_EXT_COEFFS+ 112,OC_EXT_COEFFS+  16,OC_EXT_COEFFS+ 121,OC_EXT_COEFFS+ 125,
-  OC_EXT_COEFFS+  20,OC_EXT_COEFFS+ 116,OC_EXT_COEFFS+ 130,OC_EXT_COEFFS+ 133,
-  OC_EXT_COEFFS+ 143,OC_EXT_COEFFS+ 150,OC_EXT_COEFFS+ 157,OC_EXT_COEFFS+ 164,
-  OC_EXT_COEFFS+ 167,OC_EXT_COEFFS+ 160,OC_EXT_COEFFS+ 153,OC_EXT_COEFFS+ 146,
-  OC_EXT_COEFFS+ 136,OC_EXT_COEFFS+ 139,OC_EXT_COEFFS+ 171,OC_EXT_COEFFS+ 176,
-  OC_EXT_COEFFS+ 181,OC_EXT_COEFFS+ 186,OC_EXT_COEFFS+ 191,OC_EXT_COEFFS+ 196,
-  OC_EXT_COEFFS+ 201,OC_EXT_COEFFS+ 206,OC_EXT_COEFFS+ 209,OC_EXT_COEFFS+ 214,
-  OC_EXT_COEFFS+ 198,OC_EXT_COEFFS+ 203,OC_EXT_COEFFS+  24,OC_EXT_COEFFS+ 211,
-  OC_EXT_COEFFS+ 216,OC_EXT_COEFFS+ 193,OC_EXT_COEFFS+ 188,OC_EXT_COEFFS+ 178,
-  OC_EXT_COEFFS+ 183,OC_EXT_COEFFS+ 173,OC_EXT_COEFFS+ 219,OC_EXT_COEFFS+ 220,
-  OC_EXT_COEFFS+ 220,OC_EXT_COEFFS+  12,OC_EXT_COEFFS+  15,OC_EXT_COEFFS+ 219,
-  OC_EXT_COEFFS+ 219,OC_EXT_COEFFS+ 220,OC_EXT_COEFFS+ 222,OC_EXT_COEFFS+ 225,
-  OC_EXT_COEFFS+ 228,OC_EXT_COEFFS+ 229,OC_EXT_COEFFS+ 226,OC_EXT_COEFFS+ 223
-};
-
-static const oc_extension_info OC_EXTENSION_INFO[OC_NSHAPES]={
-  {0x7F,7,OC_EXT_ROWS+  0,{0,1,2,3,4,5,6,7},{0,1,2,4,5,6,7,3}},
-  {0xFE,7,OC_EXT_ROWS+  7,{1,2,3,4,5,6,7,0},{0,1,2,4,5,6,7,3}},
-  {0x3F,6,OC_EXT_ROWS+  8,{0,1,2,3,4,5,7,6},{0,1,3,4,6,7,5,2}},
-  {0xFC,6,OC_EXT_ROWS+ 10,{2,3,4,5,6,7,1,0},{0,1,3,4,6,7,5,2}},
-  {0x1F,5,OC_EXT_ROWS+ 12,{0,1,2,3,4,7,6,5},{0,2,3,5,7,6,4,1}},
-  {0xF8,5,OC_EXT_ROWS+ 15,{3,4,5,6,7,2,1,0},{0,2,3,5,7,6,4,1}},
-  {0x0F,4,OC_EXT_ROWS+ 18,{0,1,2,3,7,6,5,4},{0,2,4,6,7,5,3,1}},
-  {0xF0,4,OC_EXT_ROWS+ 18,{4,5,6,7,3,2,1,0},{0,2,4,6,7,5,3,1}},
-  {0x07,3,OC_EXT_ROWS+ 22,{0,1,2,7,6,5,4,3},{0,3,6,7,5,4,2,1}},
-  {0xE0,3,OC_EXT_ROWS+ 27,{5,6,7,4,3,2,1,0},{0,3,6,7,5,4,2,1}},
-  {0x03,2,OC_EXT_ROWS+ 32,{0,1,7,6,5,4,3,2},{0,4,7,6,5,3,2,1}},
-  {0xC0,2,OC_EXT_ROWS+ 32,{6,7,5,4,3,2,1,0},{0,4,7,6,5,3,2,1}},
-  {0x01,1,OC_EXT_ROWS+  0,{0,7,6,5,4,3,2,1},{0,7,6,5,4,3,2,1}},
-  {0x80,1,OC_EXT_ROWS+  0,{7,6,5,4,3,2,1,0},{0,7,6,5,4,3,2,1}},
-  {0x7E,6,OC_EXT_ROWS+ 42,{1,2,3,4,5,6,7,0},{0,1,2,5,6,7,4,3}},
-  {0x7C,5,OC_EXT_ROWS+ 44,{2,3,4,5,6,7,1,0},{0,1,4,5,7,6,3,2}},
-  {0x3E,5,OC_EXT_ROWS+ 47,{1,2,3,4,5,7,6,0},{0,1,4,5,7,6,3,2}},
-  {0x78,4,OC_EXT_ROWS+ 50,{3,4,5,6,7,2,1,0},{0,4,5,7,6,3,2,1}},
-  {0x3C,4,OC_EXT_ROWS+ 54,{2,3,4,5,7,6,1,0},{0,3,4,7,6,5,2,1}},
-  {0x1E,4,OC_EXT_ROWS+ 58,{1,2,3,4,7,6,5,0},{0,4,5,7,6,3,2,1}},
-  {0x70,3,OC_EXT_ROWS+ 62,{4,5,6,7,3,2,1,0},{0,5,7,6,4,3,2,1}},
-  {0x38,3,OC_EXT_ROWS+ 67,{3,4,5,7,6,2,1,0},{0,5,6,7,4,3,2,1}},
-  {0x1C,3,OC_EXT_ROWS+ 72,{2,3,4,7,6,5,1,0},{0,5,6,7,4,3,2,1}},
-  {0x0E,3,OC_EXT_ROWS+ 77,{1,2,3,7,6,5,4,0},{0,5,7,6,4,3,2,1}},
-  {0x60,2,OC_EXT_ROWS+ 82,{5,6,7,4,3,2,1,0},{0,2,7,6,5,4,3,1}},
-  {0x30,2,OC_EXT_ROWS+ 36,{4,5,7,6,3,2,1,0},{0,4,7,6,5,3,2,1}},
-  {0x18,2,OC_EXT_ROWS+ 90,{3,4,7,6,5,2,1,0},{0,1,7,6,5,4,3,2}},
-  {0x0C,2,OC_EXT_ROWS+ 34,{2,3,7,6,5,4,1,0},{0,4,7,6,5,3,2,1}},
-  {0x06,2,OC_EXT_ROWS+ 84,{1,2,7,6,5,4,3,0},{0,2,7,6,5,4,3,1}},
-  {0x40,1,OC_EXT_ROWS+  0,{6,7,5,4,3,2,1,0},{0,7,6,5,4,3,2,1}},
-  {0x20,1,OC_EXT_ROWS+  0,{5,7,6,4,3,2,1,0},{0,7,6,5,4,3,2,1}},
-  {0x10,1,OC_EXT_ROWS+  0,{4,7,6,5,3,2,1,0},{0,7,6,5,4,3,2,1}},
-  {0x08,1,OC_EXT_ROWS+  0,{3,7,6,5,4,2,1,0},{0,7,6,5,4,3,2,1}},
-  {0x04,1,OC_EXT_ROWS+  0,{2,7,6,5,4,3,1,0},{0,7,6,5,4,3,2,1}},
-  {0x02,1,OC_EXT_ROWS+  0,{1,7,6,5,4,3,2,0},{0,7,6,5,4,3,2,1}}
-};
-
-
-
-/*Pads a single row of a partial block and then performs a forward Type-II DCT
-   on the result.
-  The output is scaled by a factor of 2 from the orthonormal version of the
-   transform.
-  _y: The buffer to store the result in.
-      Data will be placed in every 8th entry (e.g., in a column of an 8x8
-       block).
-  _x: The input coefficients.
-      The first 8 entries are used (e.g., from a row of an 8x8 block).
-  _e: The extension information for the shape.*/
-static void fdct8_ext(ogg_int16_t *_y,ogg_int16_t _x[8],
- const oc_extension_info *_e){
-  if(_e->na==1){
-    int ci;
-    /*While the branch below is still correct for shapes with na==1, we can
-       perform the entire transform with just 1 multiply in this case instead
-       of 23.*/
-    _y[0]=(ogg_int16_t)(OC_DIV2_16(OC_C4S4*(_x[_e->pi[0]]<<3)));
-    for(ci=8;ci<64;ci+=8)_y[ci]=0;
-  }
-  else{
-    int zpi;
-    int api;
-    int nz;
-    /*First multiply by the extension matrix to compute the padding values.*/
-    nz=8-_e->na;
-    for(zpi=0;zpi<nz;zpi++){
-      ogg_int32_t v;
-      v=0;
-      for(api=0;api<_e->na;api++)v+=_e->ext[zpi][api]*_x[_e->pi[api]];
-      _x[_e->pi[zpi+_e->na]]=
-       (ogg_int16_t)OC_DIV_ROUND_POW2(v,OC_EXT_SHIFT,1<<OC_EXT_SHIFT-1);
-    }
-    fdct8(_y,_x);
-  }
-}
-
-/*Performs a forward 8x8 Type-II DCT transform on blocks which overlap the
-   border of the picture region.
-  This method ONLY works with rectangular regions.
-  _border:      A description of which pixels are inside the border.
-  _y:           The buffer to store the result in.
-                This may be the same as _x.
-  _x:           The input coefficients.
-                Pixel values outside the border will be modified.*/
-void oc_fdct8x8_border(const oc_border_info *_border,ogg_int16_t _y[64],
- ogg_int16_t _x[64]){
-  ogg_int16_t             *in;
-  ogg_int16_t             *end;
-  ogg_int16_t             *out;
-  ogg_int16_t              w[64];
-  ogg_int64_t              mask;
-  const oc_extension_info *rext;
-  const oc_extension_info *cext;
-  int                      rmask;
-  int                      cmask;
-  int                      ri;
-  /*Identify the shapes of the non-zero rows and columns.*/
-  rmask=cmask=0;
-  mask=_border->mask;
-  for(ri=0;ri<8;ri++){
-    rmask|=mask&0xFF;
-    cmask|=((mask&0xFF)!=0)<<ri;
-    mask>>=8;
-  }
-  /*Find the associated extension info for these shapes.*/
-  if(rmask==0xFF)rext=NULL;
-  else for(rext=OC_EXTENSION_INFO;rext->mask!=rmask;){
-    /*If we somehow can't find the shape, then just do an unpadded fDCT.
-      It won't be efficient, but it should still be correct.*/
-    if(++rext>=OC_EXTENSION_INFO+OC_NSHAPES){
-      oc_fdct8x8(_y,_x);
-      return;
-    }
-  }
-  if(cmask==0xFF)cext=NULL;
-  else for(cext=OC_EXTENSION_INFO;cext->mask!=cmask;){
-    /*If we somehow can't find the shape, then just do an unpadded fDCT.
-      It won't be efficient, but it should still be correct.*/
-    if(++cext>=OC_EXTENSION_INFO+OC_NSHAPES){
-      oc_fdct8x8(_y,_x);
-      return;
-    }
-  }
-  /*Transform the rows.
-    We can ignore zero rows without a problem.*/
-  if(rext==NULL)for(in=_x,out=w,end=out+8;out<end;in+=8,out++)fdct8(out,in);
-  else for(in=_x,out=w,end=out+8,ri=cmask;out<end;in+=8,out++,ri>>=1){
-    if(ri&1)fdct8_ext(out,in,rext);
-  }
-  /*Transform the columns.
-    We transform even columns that are supposedly zero, because rounding errors
-     may make them slightly non-zero, and this will give a more precise
-     reconstruction with very small quantizers.*/
-  if(cext==NULL)for(in=w,out=_y,end=out+8;out<end;in+=8,out++)fdct8(out,in);
-  else for(in=w,out=_y,end=out+8;out<end;in+=8,out++)fdct8_ext(out,in,cext);
-}
-
-/*Performs an fDCT on a given fragment.
-  _frag:     The fragment to perform the 2D DCT on.
-  _dct_vals: The output buffer for the DCT coefficients.
-  _ystride:  The Y stride of the plane the fragment belongs to.
-  _framei:   The picture buffer index to perform the DCT on.
-             Use OC_FRAME_IO for the current input frame.*/
-void oc_frag_intra_fdct(const oc_fragment *_frag,ogg_int16_t _dct_vals[64],
- int _ystride,int _framei){
-  ogg_int16_t    pix_buf[64];
-  unsigned char *pixels;
-  int            pixi;
-  int            y;
-  int            x;
-  /*NOTE: 128 is subtracted from each pixel value to make it signed.
-    The original VP3 source claimed that, "this reduces the internal precision
-     requirments [sic] in the DCT transform."
-    This is of course not actually true.
-    The transform must still support input in the range [-255,255] to code
-     predicted fragments, since the same transform is used for both.
-    This actually _reduces_ the precision of the results, because larger
-     (absolute) values would have fewer significant bits chopped off when
-     rounding.
-    We're stuck with it, however.
-    At least it might reduce bias towards 0 when coding unpredicted DC
-     coefficients, but that's not what VP3 justified it with.*/
-  pixels=_frag->buffer[_framei];
-  /*For border fragments, only copy pixels that are in the displayable
-     region of the image.
-    The DCT function will compute optimal padding values for the other
-     pixels.*/
-  if(_frag->border!=NULL){
-    ogg_int64_t mask;
-    mask=_frag->border->mask;
-    for(pixi=y=0;y<8;y++){
-      for(x=0;x<8;x++,pixi++){
-        pix_buf[pixi]=(ogg_int16_t)(((int)mask&1)?pixels[x]-128:0);
-        /*This branchless code is (almost) equivalent to the previous line:
-            int pmask;
-            pmask=-(int)mask&1;
-            pix_buf[pixi]=(ogg_int16_t)(pmask&pixels[x]);
-          We don't use this code to allow the user to pass in a buffer that is
-           the exact size of the displayed image, not the size padded to a
-           multiple of 16.
-          In the latter case, we might segfault on pixels[x] if it is not
-           mapped to a valid page, even though we would discard the value
-           we were attempting to read.*/
-        mask>>=1;
-      }
-      pixels+=_ystride;
-    }
-    oc_fdct8x8_border(_frag->border,_dct_vals,pix_buf);
-  }
-  /*Otherwise, copy all the pixels in the fragment and do a normal DCT.*/
-  else{
-    for(pixi=y=0;y<8;y++){
-      for(x=0;x<8;x++,pixi++)pix_buf[pixi]=(ogg_int16_t)(pixels[x]-128);
-      pixels+=_ystride;
-    }
-    oc_fdct8x8(_dct_vals,pix_buf);
-  }
-}
-
-/*A pipline stage for applying an fDCT to each (non-motion compensated) block
-   in a frame.*/
-
-static int oc_fdct_pipe_start(oc_enc_pipe_stage *_stage){
-  int pli;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=0;
-  return _stage->next!=NULL?(*_stage->next->pipe_start)(_stage->next):0;
-}
-
-/*Does the fDCTs.
-  This pipeline stage proceeds in a planar fashion.*/
-static int oc_fdct_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  int pli;
-  for(pli=0;pli<3;pli++){
-    int y_procd;
-    int y_avail;
-    /*Compute how far we can get in complete fragment rows.*/
-    y_procd=_stage->y_procd[pli];
-    y_avail=_y_avail[pli]&~7;
-    /*If that's farther than we've already gotten, do some fDCTs.*/
-    if(y_avail>y_procd){
-      oc_fragment_plane    *fplane;
-      oc_fragment          *frags;
-      oc_fragment          *frag_end;
-      oc_fragment_enc_info *efrags;
-      int                   ystride;
-      int                   yfrag0;
-      int                   yrows;
-      fplane=_stage->enc->state.fplanes+pli;
-      ystride=_stage->enc->state.input[pli].ystride;
-      yfrag0=fplane->froffset+(y_procd>>3)*fplane->nhfrags;
-      yrows=y_avail-y_procd>>3;
-      frags=_stage->enc->state.frags+yfrag0;
-      efrags=_stage->enc->frinfo+yfrag0;
-      do{
-        for(frag_end=frags+fplane->nhfrags;frags<frag_end;frags++,efrags++){
-          oc_frag_intra_fdct(frags,efrags->dct_coeffs,ystride,OC_FRAME_IO);
-        }
-        _stage->y_procd[pli]+=8;
-        if(_stage->next!=NULL){
-          int ret;
-          ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-          if(ret<0)return ret;
-        }
-      }
-      while(--yrows);
-    }
-  }
-  return 0;
-}
-
-static int oc_fdct_pipe_end(oc_enc_pipe_stage *_stage){
-  return _stage->next!=NULL?(*_stage->next->pipe_end)(_stage->next):0;
-}
-
-
-/*Initialize the fDCT stage of the pipeline.
-  _enc: The encoding context.*/
-void oc_fdct_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_fdct_pipe_start;
-  _stage->pipe_proc=oc_fdct_pipe_process;
-  _stage->pipe_end=oc_fdct_pipe_end;
-}

Deleted: experimental/j/theora-mashup/lib/dec/fdct.h
===================================================================
--- experimental/j/theora-mashup/lib/dec/fdct.h	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/fdct.h	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,13 +0,0 @@
-/*Forward DCT transforms.*/
-#include "encint.h"
-#if !defined(_fdct_H)
-# define _fdct_H (1)
-
-void oc_fdct8x8(ogg_int16_t _y[64],const ogg_int16_t _x[64]);
-void oc_fdct8x8_border(const oc_border_info *_border,ogg_int16_t _y[64],
- ogg_int16_t _x[64]);
-void oc_frag_intra_fdct(const oc_fragment *_frag,ogg_int16_t _dct_vals[64],
- int _ystride,int _framei);
-void oc_fdct_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc);
-
-#endif

Deleted: experimental/j/theora-mashup/lib/dec/huffenc.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/huffenc.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/huffenc.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,910 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <ogg/ogg.h>
-#include "huffenc.h"
-
-
-
-/*The default Huffman codes used for VP3.1.*/
-const th_huff_code TH_VP31_HUFF_CODES[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS]={
-  {
-    {0x002D, 6},{0x0026, 7},{0x0166, 9},{0x004E, 8},
-    {0x02CE,10},{0x059E,11},{0x027D,11},{0x0008, 5},
-    {0x04F9,12},{0x000F, 4},{0x000E, 4},{0x001B, 5},
-    {0x0006, 4},{0x0008, 4},{0x0005, 4},{0x001A, 5},
-    {0x0015, 5},{0x0007, 4},{0x000C, 4},{0x0001, 3},
-    {0x0000, 3},{0x0009, 4},{0x0017, 5},{0x0029, 6},
-    {0x0028, 6},{0x00B2, 8},{0x04F8,12},{0x059F,11},
-    {0x009E, 9},{0x013F,10},{0x0012, 6},{0x0058, 7}
-  },
-  {
-    {0x0010, 5},{0x0047, 7},{0x01FF, 9},{0x008C, 8},
-    {0x03FC,10},{0x046A,11},{0x0469,11},{0x0022, 6},
-    {0x11A1,13},{0x000E, 4},{0x000D, 4},{0x0004, 4},
-    {0x0005, 4},{0x0009, 4},{0x0006, 4},{0x001E, 5},
-    {0x0016, 5},{0x0007, 4},{0x000C, 4},{0x0001, 3},
-    {0x0000, 3},{0x000A, 4},{0x0017, 5},{0x007D, 7},
-    {0x007E, 7},{0x011B, 9},{0x08D1,12},{0x03FD,10},
-    {0x046B,11},{0x11A0,13},{0x007C, 7},{0x00FE, 8}
-  },
-  {
-    {0x0016, 5},{0x0020, 6},{0x0086, 8},{0x0087, 8},
-    {0x0367,10},{0x06CC,11},{0x06CB,11},{0x006E, 7},
-    {0x366D,14},{0x000F, 4},{0x000E, 4},{0x0004, 4},
-    {0x0005, 4},{0x000A, 4},{0x0006, 4},{0x001A, 5},
-    {0x0011, 5},{0x0007, 4},{0x000C, 4},{0x0001, 3},
-    {0x0000, 3},{0x0009, 4},{0x0017, 5},{0x006F, 7},
-    {0x006D, 7},{0x0364,10},{0x0D9A,12},{0x06CA,11},
-    {0x1B37,13},{0x366C,14},{0x0042, 7},{0x00D8, 8}
-  },
-  {
-    {0x0000, 4},{0x002D, 6},{0x00F7, 8},{0x0058, 7},
-    {0x0167, 9},{0x02CB,10},{0x02CA,10},{0x000E, 6},
-    {0x1661,13},{0x0003, 3},{0x0002, 3},{0x0008, 4},
-    {0x0009, 4},{0x000D, 4},{0x0002, 4},{0x001F, 5},
-    {0x0017, 5},{0x0001, 4},{0x000C, 4},{0x000E, 4},
-    {0x000A, 4},{0x0006, 5},{0x0078, 7},{0x000F, 6},
-    {0x007A, 7},{0x0164, 9},{0x0599,11},{0x02CD,10},
-    {0x0B31,12},{0x1660,13},{0x0079, 7},{0x00F6, 8}
-  },
-  {
-    {0x0003, 4},{0x003C, 6},{0x000F, 7},{0x007A, 7},
-    {0x001D, 8},{0x0020, 9},{0x0072,10},{0x0006, 6},
-    {0x0399,13},{0x0004, 3},{0x0005, 3},{0x0005, 4},
-    {0x0006, 4},{0x000E, 4},{0x0004, 4},{0x0000, 4},
-    {0x0019, 5},{0x0002, 4},{0x000D, 4},{0x0007, 4},
-    {0x001F, 5},{0x0030, 6},{0x0011, 8},{0x0031, 6},
-    {0x0005, 6},{0x0021, 9},{0x00E7,11},{0x0038, 9},
-    {0x01CD,12},{0x0398,13},{0x007B, 7},{0x0009, 7}
-  },
-  {
-    {0x0009, 4},{0x0002, 5},{0x0074, 7},{0x0007, 6},
-    {0x00EC, 8},{0x00D1, 9},{0x01A6,10},{0x0006, 6},
-    {0x0D21,13},{0x0005, 3},{0x0006, 3},{0x0008, 4},
-    {0x0007, 4},{0x000F, 4},{0x0004, 4},{0x0000, 4},
-    {0x001C, 5},{0x0002, 4},{0x0005, 4},{0x0003, 4},
-    {0x000C, 5},{0x0035, 7},{0x01A7,10},{0x001B, 6},
-    {0x0077, 7},{0x01A5,10},{0x0349,11},{0x00D0, 9},
-    {0x0691,12},{0x0D20,13},{0x0075, 7},{0x00ED, 8}
-  },
-  {
-    {0x000A, 4},{0x000C, 5},{0x0012, 6},{0x001B, 6},
-    {0x00B7, 8},{0x016C, 9},{0x0099, 9},{0x005A, 7},
-    {0x16D8,13},{0x0007, 3},{0x0006, 3},{0x0009, 4},
-    {0x0008, 4},{0x0000, 3},{0x0005, 4},{0x0017, 5},
-    {0x000E, 5},{0x0002, 4},{0x0003, 4},{0x000F, 5},
-    {0x001A, 6},{0x004D, 8},{0x2DB3,14},{0x002C, 6},
-    {0x0011, 6},{0x02DA,10},{0x05B7,11},{0x0098, 9},
-    {0x0B6D,12},{0x2DB2,14},{0x0010, 6},{0x0027, 7}
-  },
-  {
-    {0x000D, 4},{0x000F, 5},{0x001D, 6},{0x0008, 5},
-    {0x0051, 7},{0x0056, 8},{0x00AF, 9},{0x002A, 7},
-    {0x148A,13},{0x0007, 3},{0x0000, 2},{0x0008, 4},
-    {0x0009, 4},{0x000C, 4},{0x0006, 4},{0x0017, 5},
-    {0x000B, 5},{0x0016, 5},{0x0015, 5},{0x0009, 5},
-    {0x0050, 7},{0x00AE, 9},{0x2917,14},{0x001C, 6},
-    {0x0014, 6},{0x0290,10},{0x0523,11},{0x0149, 9},
-    {0x0A44,12},{0x2916,14},{0x0053, 7},{0x00A5, 8}
-  },
-  {
-    {0x0001, 4},{0x001D, 6},{0x00F5, 8},{0x00F4, 8},
-    {0x024D,10},{0x0499,11},{0x0498,11},{0x0001, 5},
-    {0x0021, 6},{0x0006, 3},{0x0005, 3},{0x0006, 4},
-    {0x0005, 4},{0x0002, 4},{0x0007, 5},{0x0025, 6},
-    {0x007B, 7},{0x001C, 6},{0x0020, 6},{0x000D, 6},
-    {0x0048, 7},{0x0092, 8},{0x0127, 9},{0x000E, 4},
-    {0x0004, 4},{0x0011, 5},{0x000C, 6},{0x003C, 6},
-    {0x000F, 5},{0x0000, 5},{0x001F, 5},{0x0013, 5}
-  },
-  {
-    {0x0005, 4},{0x003C, 6},{0x0040, 7},{0x000D, 7},
-    {0x0031, 9},{0x0061,10},{0x0060,10},{0x0002, 5},
-    {0x00F5, 8},{0x0006, 3},{0x0005, 3},{0x0007, 4},
-    {0x0006, 4},{0x0002, 4},{0x0009, 5},{0x0025, 6},
-    {0x0007, 6},{0x0021, 6},{0x0024, 6},{0x0010, 6},
-    {0x0041, 7},{0x00F4, 8},{0x0019, 8},{0x000E, 4},
-    {0x0003, 4},{0x0011, 5},{0x0011, 6},{0x003F, 6},
-    {0x003E, 6},{0x007B, 7},{0x0000, 4},{0x0013, 5}
-  },
-  {
-    {0x000A, 4},{0x0007, 5},{0x0001, 6},{0x0009, 6},
-    {0x0131, 9},{0x0261,10},{0x0260,10},{0x0015, 6},
-    {0x0001, 7},{0x0007, 3},{0x0006, 3},{0x0008, 4},
-    {0x0007, 4},{0x0006, 4},{0x0012, 5},{0x002F, 6},
-    {0x0014, 6},{0x0027, 6},{0x002D, 6},{0x0016, 6},
-    {0x004D, 7},{0x0099, 8},{0x0000, 7},{0x0004, 4},
-    {0x0001, 4},{0x0005, 5},{0x0017, 6},{0x002E, 6},
-    {0x002C, 6},{0x0008, 6},{0x0006, 5},{0x0001, 5}
-  },
-  {
-    {0x0000, 3},{0x000E, 5},{0x0017, 6},{0x002A, 6},
-    {0x0010, 7},{0x00F9,10},{0x00F8,10},{0x001E, 7},
-    {0x003F, 8},{0x0007, 3},{0x0006, 3},{0x0009, 4},
-    {0x0008, 4},{0x0006, 4},{0x000F, 5},{0x0005, 5},
-    {0x0016, 6},{0x0029, 6},{0x002B, 6},{0x0015, 6},
-    {0x0050, 7},{0x0011, 7},{0x007D, 9},{0x0004, 4},
-    {0x0017, 5},{0x0006, 5},{0x0014, 6},{0x002C, 6},
-    {0x002D, 6},{0x000E, 6},{0x0009, 6},{0x0051, 7}
-  },
-  {
-    {0x0002, 3},{0x0018, 5},{0x002F, 6},{0x000D, 5},
-    {0x0053, 7},{0x0295,10},{0x0294,10},{0x00A4, 8},
-    {0x007C, 8},{0x0000, 2},{0x0007, 3},{0x0009, 4},
-    {0x0008, 4},{0x001B, 5},{0x000C, 5},{0x0028, 6},
-    {0x006A, 7},{0x001E, 6},{0x001D, 6},{0x0069, 7},
-    {0x00D7, 8},{0x007D, 8},{0x014B, 9},{0x0019, 5},
-    {0x0016, 5},{0x002E, 6},{0x001C, 6},{0x002B, 6},
-    {0x002A, 6},{0x0068, 7},{0x003F, 7},{0x00D6, 8}
-  },
-  {
-    {0x0002, 3},{0x001B, 5},{0x000C, 5},{0x0018, 5},
-    {0x0029, 6},{0x007F, 8},{0x02F0,10},{0x0198, 9},
-    {0x0179, 9},{0x0000, 2},{0x0007, 3},{0x0009, 4},
-    {0x0008, 4},{0x001A, 5},{0x000D, 5},{0x002A, 6},
-    {0x0064, 7},{0x001E, 6},{0x0067, 7},{0x005F, 7},
-    {0x00CD, 8},{0x007E, 8},{0x02F1,10},{0x0016, 5},
-    {0x000E, 5},{0x002E, 6},{0x0065, 7},{0x002B, 6},
-    {0x0028, 6},{0x003E, 7},{0x00BD, 8},{0x0199, 9}
-  },
-  {
-    {0x0002, 3},{0x0007, 4},{0x0016, 5},{0x0006, 4},
-    {0x0036, 6},{0x005C, 7},{0x015D, 9},{0x015C, 9},
-    {0x02BF,10},{0x0000, 2},{0x0007, 3},{0x0009, 4},
-    {0x0008, 4},{0x0018, 5},{0x0034, 6},{0x002A, 6},
-    {0x005E, 7},{0x006A, 7},{0x0064, 7},{0x005D, 7},
-    {0x00CB, 8},{0x00AD, 8},{0x02BE,10},{0x0014, 5},
-    {0x0033, 6},{0x006E, 7},{0x005F, 7},{0x006F, 7},
-    {0x006B, 7},{0x00CA, 8},{0x00AC, 8},{0x015E, 9}
-  },
-  {
-    {0x000F, 4},{0x001D, 5},{0x0018, 5},{0x000B, 4},
-    {0x0019, 5},{0x0029, 6},{0x00D6, 8},{0x0551,11},
-    {0x0AA1,12},{0x0001, 2},{0x0000, 2},{0x0009, 4},
-    {0x0008, 4},{0x001B, 5},{0x0038, 6},{0x0028, 6},
-    {0x0057, 7},{0x006A, 7},{0x0068, 7},{0x0056, 7},
-    {0x00E5, 8},{0x0155, 9},{0x0AA0,12},{0x0073, 7},
-    {0x0069, 7},{0x00D7, 8},{0x00AB, 8},{0x00E4, 8},
-    {0x00A9, 8},{0x0151, 9},{0x0150, 9},{0x02A9,10}
-  },
-  {
-    {0x0008, 5},{0x0025, 7},{0x017A, 9},{0x02F7,10},
-    {0x0BDB,12},{0x17B4,13},{0x2F6B,14},{0x001D, 5},
-    {0x2F6A,14},{0x0008, 4},{0x0007, 4},{0x0001, 4},
-    {0x0002, 4},{0x000A, 4},{0x0006, 4},{0x0000, 4},
-    {0x001C, 5},{0x0009, 4},{0x000D, 4},{0x000F, 4},
-    {0x000C, 4},{0x0003, 4},{0x000A, 5},{0x0016, 5},
-    {0x0013, 6},{0x005D, 7},{0x0024, 7},{0x00BC, 8},
-    {0x005C, 7},{0x05EC,11},{0x000B, 5},{0x005F, 7}
-  },
-  {
-    {0x000F, 5},{0x0010, 6},{0x004B, 8},{0x00C6, 8},
-    {0x031D,10},{0x0C71,12},{0x0C70,12},{0x0001, 4},
-    {0x0C73,12},{0x0008, 4},{0x0009, 4},{0x0002, 4},
-    {0x0003, 4},{0x000B, 4},{0x0006, 4},{0x0000, 4},
-    {0x001C, 5},{0x0005, 4},{0x000D, 4},{0x000F, 4},
-    {0x000A, 4},{0x0019, 5},{0x0013, 6},{0x001D, 5},
-    {0x0030, 6},{0x0062, 7},{0x0024, 7},{0x004A, 8},
-    {0x018F, 9},{0x0C72,12},{0x000E, 5},{0x0011, 6}
-  },
-  {
-    {0x001B, 5},{0x0003, 6},{0x008D, 8},{0x0040, 7},
-    {0x0239,10},{0x0471,11},{0x08E0,12},{0x0003, 4},
-    {0x11C3,13},{0x000A, 4},{0x0009, 4},{0x0004, 4},
-    {0x0005, 4},{0x000E, 4},{0x0007, 4},{0x0001, 4},
-    {0x001E, 5},{0x0006, 4},{0x000C, 4},{0x000B, 4},
-    {0x0002, 4},{0x0000, 5},{0x0041, 7},{0x001F, 5},
-    {0x0022, 6},{0x0002, 6},{0x008F, 8},{0x008C, 8},
-    {0x011D, 9},{0x11C2,13},{0x001A, 5},{0x0021, 6}
-  },
-  {
-    {0x001F, 5},{0x0003, 6},{0x0003, 7},{0x0043, 7},
-    {0x000B, 9},{0x0015,10},{0x0051,12},{0x0003, 4},
-    {0x0050,12},{0x000D, 4},{0x000C, 4},{0x0004, 4},
-    {0x0006, 4},{0x000E, 4},{0x000A, 4},{0x0001, 4},
-    {0x001E, 5},{0x0005, 4},{0x0009, 4},{0x0007, 4},
-    {0x0011, 5},{0x0002, 6},{0x0004, 8},{0x0002, 4},
-    {0x002D, 6},{0x0020, 6},{0x0042, 7},{0x0001, 7},
-    {0x0000, 7},{0x0029,11},{0x0017, 5},{0x002C, 6}
-  },
-  {
-    {0x0003, 4},{0x001F, 6},{0x003A, 7},{0x005D, 7},
-    {0x0173, 9},{0x02E4,10},{0x172D,13},{0x0004, 4},
-    {0x172C,13},{0x000F, 4},{0x000E, 4},{0x0009, 4},
-    {0x0008, 4},{0x000C, 4},{0x000A, 4},{0x0001, 4},
-    {0x0016, 5},{0x0002, 4},{0x0005, 4},{0x001A, 5},
-    {0x002F, 6},{0x0038, 7},{0x05CA,11},{0x0006, 4},
-    {0x0037, 6},{0x001E, 6},{0x003B, 7},{0x0039, 7},
-    {0x00B8, 8},{0x0B97,12},{0x0000, 4},{0x0036, 6}
-  },
-  {
-    {0x0006, 4},{0x0037, 6},{0x005D, 7},{0x000C, 6},
-    {0x00B9, 8},{0x02E3,10},{0x05C4,11},{0x0004, 4},
-    {0x1715,13},{0x0000, 3},{0x000F, 4},{0x0008, 4},
-    {0x0007, 4},{0x000C, 4},{0x0009, 4},{0x001D, 5},
-    {0x0016, 5},{0x001C, 5},{0x001A, 5},{0x000B, 5},
-    {0x005E, 7},{0x0170, 9},{0x1714,13},{0x000A, 4},
-    {0x000A, 5},{0x0036, 6},{0x005F, 7},{0x001B, 7},
-    {0x001A, 7},{0x0B8B,12},{0x0002, 4},{0x0007, 5}
-  },
-  {
-    {0x000C, 4},{0x000B, 5},{0x0079, 7},{0x0022, 6},
-    {0x00F0, 8},{0x0119, 9},{0x0230,10},{0x001D, 5},
-    {0x08C4,12},{0x0001, 3},{0x0000, 3},{0x000A, 4},
-    {0x0009, 4},{0x000B, 4},{0x0007, 4},{0x001C, 5},
-    {0x003D, 6},{0x000D, 5},{0x0008, 5},{0x0015, 6},
-    {0x008D, 8},{0x118B,13},{0x118A,13},{0x000D, 4},
-    {0x0010, 5},{0x0009, 5},{0x0014, 6},{0x0047, 7},
-    {0x00F1, 8},{0x0463,11},{0x001F, 5},{0x000C, 5}
-  },
-  {
-    {0x0000, 3},{0x001A, 5},{0x0033, 6},{0x000C, 5},
-    {0x0046, 7},{0x01E3, 9},{0x03C5,10},{0x0017, 5},
-    {0x1E21,13},{0x0002, 3},{0x0001, 3},{0x0009, 4},
-    {0x000A, 4},{0x0007, 4},{0x001B, 5},{0x003D, 6},
-    {0x001B, 6},{0x0022, 6},{0x0079, 7},{0x00F0, 8},
-    {0x1E20,13},{0x1E23,13},{0x1E22,13},{0x000E, 4},
-    {0x0016, 5},{0x0018, 5},{0x0032, 6},{0x001A, 6},
-    {0x0047, 7},{0x0789,11},{0x001F, 5},{0x0010, 5}
-  },
-  {
-    {0x001D, 5},{0x0061, 7},{0x004E, 8},{0x009E, 9},
-    {0x027C,11},{0x09F5,13},{0x09F4,13},{0x0003, 4},
-    {0x0060, 7},{0x0000, 3},{0x000F, 4},{0x000B, 4},
-    {0x000A, 4},{0x0009, 4},{0x0005, 4},{0x000D, 5},
-    {0x0031, 6},{0x0008, 5},{0x0038, 6},{0x0012, 6},
-    {0x0026, 7},{0x013F,10},{0x04FB,12},{0x000D, 4},
-    {0x0002, 4},{0x000C, 5},{0x0039, 6},{0x001C, 6},
-    {0x000F, 5},{0x001D, 6},{0x0008, 4},{0x0019, 5}
-  },
-  {
-    {0x0007, 4},{0x0019, 6},{0x00AB, 8},{0x00AA, 8},
-    {0x0119,10},{0x0461,12},{0x0460,12},{0x001B, 5},
-    {0x0047, 8},{0x0001, 3},{0x0000, 3},{0x000C, 4},
-    {0x000B, 4},{0x0009, 4},{0x0005, 4},{0x000D, 5},
-    {0x0035, 6},{0x003D, 6},{0x003C, 6},{0x0018, 6},
-    {0x0022, 7},{0x008D, 9},{0x0231,11},{0x000E, 4},
-    {0x001F, 5},{0x0009, 5},{0x002B, 6},{0x0010, 6},
-    {0x0034, 6},{0x0054, 7},{0x0008, 4},{0x0014, 5}
-  },
-  {
-    {0x000C, 4},{0x0005, 5},{0x0008, 6},{0x005B, 7},
-    {0x004D, 9},{0x0131,11},{0x0261,12},{0x001A, 5},
-    {0x0012, 7},{0x0000, 3},{0x000F, 4},{0x000A, 4},
-    {0x0009, 4},{0x0006, 4},{0x001B, 5},{0x0006, 5},
-    {0x001C, 6},{0x002C, 6},{0x0015, 6},{0x005A, 7},
-    {0x0027, 8},{0x0099,10},{0x0260,12},{0x000E, 4},
-    {0x0004, 4},{0x000F, 5},{0x0007, 5},{0x001D, 6},
-    {0x000B, 5},{0x0014, 6},{0x0008, 4},{0x0017, 5}
-  },
-  {
-    {0x000F, 4},{0x0013, 5},{0x0075, 7},{0x0024, 6},
-    {0x0095, 8},{0x0251,10},{0x04A0,11},{0x0010, 5},
-    {0x00C8, 8},{0x0002, 3},{0x0001, 3},{0x0001, 4},
-    {0x0000, 4},{0x001A, 5},{0x0011, 5},{0x002C, 6},
-    {0x0065, 7},{0x0074, 7},{0x004B, 7},{0x00C9, 8},
-    {0x0129, 9},{0x0943,12},{0x0942,12},{0x0003, 3},
-    {0x000A, 4},{0x001C, 5},{0x0018, 5},{0x0033, 6},
-    {0x0017, 5},{0x002D, 6},{0x001B, 5},{0x003B, 6}
-  },
-  {
-    {0x0003, 3},{0x001A, 5},{0x002D, 6},{0x0038, 6},
-    {0x0028, 7},{0x0395,10},{0x0E51,12},{0x0037, 6},
-    {0x00E4, 8},{0x0001, 3},{0x0000, 3},{0x001F, 5},
-    {0x001E, 5},{0x0017, 5},{0x003A, 6},{0x0073, 7},
-    {0x002A, 7},{0x002B, 7},{0x0029, 7},{0x01CB, 9},
-    {0x0729,11},{0x1CA1,13},{0x1CA0,13},{0x0004, 3},
-    {0x000A, 4},{0x0004, 4},{0x0018, 5},{0x0036, 6},
-    {0x000B, 5},{0x002C, 6},{0x0019, 5},{0x003B, 6}
-  },
-  {
-    {0x0004, 3},{0x0004, 4},{0x003F, 6},{0x0017, 5},
-    {0x0075, 7},{0x01F5, 9},{0x07D1,11},{0x0017, 6},
-    {0x01F6, 9},{0x0001, 3},{0x0000, 3},{0x001B, 5},
-    {0x001A, 5},{0x000A, 5},{0x0032, 6},{0x0074, 7},
-    {0x00F8, 8},{0x00F9, 8},{0x01F7, 9},{0x03E9,10},
-    {0x0FA0,12},{0x1F43,13},{0x1F42,13},{0x0003, 3},
-    {0x000A, 4},{0x001E, 5},{0x001C, 5},{0x003B, 6},
-    {0x0018, 5},{0x0016, 6},{0x0016, 5},{0x0033, 6}
-  },
-  {
-    {0x0004, 3},{0x0007, 4},{0x0018, 5},{0x001E, 5},
-    {0x0036, 6},{0x0031, 7},{0x0177, 9},{0x0077, 7},
-    {0x0176, 9},{0x0001, 3},{0x0000, 3},{0x001A, 5},
-    {0x0019, 5},{0x003A, 6},{0x0019, 6},{0x005C, 7},
-    {0x00BA, 8},{0x0061, 8},{0x00C1, 9},{0x0180,10},
-    {0x0302,11},{0x0607,12},{0x0606,12},{0x0002, 3},
-    {0x000A, 4},{0x001F, 5},{0x001C, 5},{0x0037, 6},
-    {0x0016, 5},{0x0076, 7},{0x000D, 5},{0x002F, 6}
-  },
-  {
-    {0x0000, 3},{0x000A, 4},{0x001A, 5},{0x000C, 4},
-    {0x001D, 5},{0x0039, 6},{0x0078, 7},{0x005E, 7},
-    {0x0393,11},{0x0002, 3},{0x0001, 3},{0x0016, 5},
-    {0x000F, 5},{0x002E, 6},{0x005F, 7},{0x0073, 8},
-    {0x00E5, 9},{0x01C8,10},{0x0E4A,13},{0x1C97,14},
-    {0x1C96,14},{0x0E49,13},{0x0E48,13},{0x0004, 3},
-    {0x0006, 4},{0x001F, 5},{0x001B, 5},{0x001D, 6},
-    {0x0038, 6},{0x0038, 7},{0x003D, 6},{0x0079, 7}
-  },
-  {
-    {0x000B, 5},{0x002B, 7},{0x0054, 8},{0x01B7, 9},
-    {0x06D9,11},{0x0DB1,12},{0x0DB0,12},{0x0002, 4},
-    {0x00AB, 9},{0x0009, 4},{0x000A, 4},{0x0007, 4},
-    {0x0008, 4},{0x000F, 4},{0x000C, 4},{0x0003, 4},
-    {0x001D, 5},{0x0004, 4},{0x000B, 4},{0x0006, 4},
-    {0x001A, 5},{0x0003, 6},{0x00AA, 9},{0x0001, 4},
-    {0x0000, 5},{0x0014, 6},{0x006C, 7},{0x00DA, 8},
-    {0x0002, 6},{0x036D,10},{0x001C, 5},{0x0037, 6}
-  },
-  {
-    {0x001D, 5},{0x0004, 6},{0x00B6, 8},{0x006A, 8},
-    {0x05B9,11},{0x16E1,13},{0x16E0,13},{0x0007, 4},
-    {0x016F, 9},{0x000C, 4},{0x000D, 4},{0x0009, 4},
-    {0x0008, 4},{0x000F, 4},{0x000A, 4},{0x0003, 4},
-    {0x0017, 5},{0x0002, 4},{0x0004, 4},{0x001C, 5},
-    {0x002C, 6},{0x006B, 8},{0x0B71,12},{0x0005, 4},
-    {0x0003, 5},{0x001B, 6},{0x005A, 7},{0x0034, 7},
-    {0x0005, 6},{0x02DD,10},{0x0000, 4},{0x000C, 5}
-  },
-  {
-    {0x0003, 4},{0x007F, 7},{0x00A1, 8},{0x00A0, 8},
-    {0x020C,10},{0x0834,12},{0x106B,13},{0x0007, 4},
-    {0x0082, 8},{0x000E, 4},{0x000D, 4},{0x000B, 4},
-    {0x000C, 4},{0x0000, 3},{0x0009, 4},{0x0002, 4},
-    {0x0011, 5},{0x001E, 5},{0x0015, 5},{0x003E, 6},
-    {0x0040, 7},{0x041B,11},{0x106A,13},{0x0006, 4},
-    {0x000A, 5},{0x0029, 6},{0x007E, 7},{0x0051, 7},
-    {0x0021, 6},{0x0107, 9},{0x0004, 4},{0x000B, 5}
-  },
-  {
-    {0x0007, 4},{0x001B, 6},{0x00F6, 8},{0x00E9, 8},
-    {0x03A1,10},{0x0740,11},{0x0E82,12},{0x001F, 5},
-    {0x01EF, 9},{0x0001, 3},{0x0002, 3},{0x000B, 4},
-    {0x000C, 4},{0x000D, 4},{0x0008, 4},{0x001C, 5},
-    {0x0003, 5},{0x0012, 5},{0x0002, 5},{0x0075, 7},
-    {0x01D1, 9},{0x1D07,13},{0x1D06,13},{0x000A, 4},
-    {0x0013, 5},{0x003B, 6},{0x001A, 6},{0x007A, 7},
-    {0x003C, 6},{0x01EE, 9},{0x0000, 4},{0x000C, 5}
-  },
-  {
-    {0x000D, 4},{0x003D, 6},{0x0042, 7},{0x0037, 7},
-    {0x00D9, 9},{0x0362,11},{0x06C6,12},{0x001F, 5},
-    {0x0086, 8},{0x0001, 3},{0x0002, 3},{0x000C, 4},
-    {0x000B, 4},{0x000A, 4},{0x0001, 4},{0x000F, 5},
-    {0x0025, 6},{0x003C, 6},{0x001A, 6},{0x0087, 8},
-    {0x01B0,10},{0x0D8F,13},{0x0D8E,13},{0x000E, 4},
-    {0x0013, 5},{0x000C, 5},{0x0024, 6},{0x0020, 6},
-    {0x0011, 5},{0x006D, 8},{0x0000, 4},{0x000E, 5}
-  },
-  {
-    {0x0000, 3},{0x0012, 5},{0x0076, 7},{0x0077, 7},
-    {0x014D, 9},{0x0533,11},{0x14C9,13},{0x0013, 5},
-    {0x00A5, 8},{0x0002, 3},{0x0003, 3},{0x000B, 4},
-    {0x000C, 4},{0x0008, 4},{0x001A, 5},{0x002B, 6},
-    {0x0075, 7},{0x0074, 7},{0x00A7, 8},{0x0298,10},
-    {0x14C8,13},{0x14CB,13},{0x14CA,13},{0x000F, 4},
-    {0x001C, 5},{0x0007, 5},{0x002A, 6},{0x0028, 6},
-    {0x001B, 5},{0x00A4, 8},{0x0002, 4},{0x0006, 5}
-  },
-  {
-    {0x0002, 3},{0x001A, 5},{0x002B, 6},{0x003A, 6},
-    {0x00ED, 8},{0x0283,10},{0x0A0A,12},{0x0004, 5},
-    {0x00A1, 8},{0x0004, 3},{0x0003, 3},{0x000B, 4},
-    {0x000C, 4},{0x001F, 5},{0x0006, 5},{0x0077, 7},
-    {0x00A3, 8},{0x00A2, 8},{0x0140, 9},{0x1417,13},
-    {0x1416,13},{0x0A09,12},{0x0A08,12},{0x0000, 3},
-    {0x001E, 5},{0x0007, 5},{0x002A, 6},{0x0029, 6},
-    {0x001C, 5},{0x00EC, 8},{0x001B, 5},{0x0005, 5}
-  },
-  {
-    {0x0002, 3},{0x0002, 4},{0x0018, 5},{0x001D, 5},
-    {0x0035, 6},{0x00E4, 8},{0x01CF,11},{0x001D, 7},
-    {0x0072, 9},{0x0004, 3},{0x0005, 3},{0x0006, 4},
-    {0x0007, 4},{0x0006, 5},{0x0073, 7},{0x0038, 8},
-    {0x01CE,11},{0x039B,12},{0x0398,12},{0x0733,13},
-    {0x0732,13},{0x0735,13},{0x0734,13},{0x0000, 3},
-    {0x001F, 5},{0x001B, 5},{0x0034, 6},{0x000F, 6},
-    {0x001E, 5},{0x00E5, 8},{0x0019, 5},{0x0038, 6}
-  },
-  {
-    {0x0016, 5},{0x0050, 7},{0x0172, 9},{0x02E7,10},
-    {0x1732,13},{0x2E67,14},{0x2E66,14},{0x0006, 4},
-    {0x0051, 7},{0x0001, 3},{0x0000, 3},{0x000D, 4},
-    {0x000C, 4},{0x0009, 4},{0x001C, 5},{0x0009, 5},
-    {0x001C, 6},{0x001D, 6},{0x005D, 7},{0x00B8, 8},
-    {0x05CD,11},{0x1731,13},{0x1730,13},{0x000F, 4},
-    {0x0005, 4},{0x000F, 5},{0x0008, 5},{0x0029, 6},
-    {0x001D, 5},{0x002F, 6},{0x0008, 4},{0x0015, 5}
-  },
-  {
-    {0x0009, 4},{0x0021, 6},{0x0040, 7},{0x00AD, 8},
-    {0x02B0,10},{0x1589,13},{0x1588,13},{0x001C, 5},
-    {0x005F, 7},{0x0000, 3},{0x000F, 4},{0x000D, 4},
-    {0x000C, 4},{0x0006, 4},{0x0011, 5},{0x002A, 6},
-    {0x0057, 7},{0x005E, 7},{0x0041, 7},{0x0159, 9},
-    {0x0563,11},{0x158B,13},{0x158A,13},{0x0001, 3},
-    {0x0005, 4},{0x0014, 5},{0x003B, 6},{0x002E, 6},
-    {0x0004, 4},{0x003A, 6},{0x0007, 4},{0x0016, 5}
-  },
-  {
-    {0x000E, 4},{0x0007, 5},{0x0046, 7},{0x0045, 7},
-    {0x0064, 9},{0x032A,12},{0x0657,13},{0x0018, 5},
-    {0x000D, 6},{0x0000, 3},{0x000F, 4},{0x000A, 4},
-    {0x000B, 4},{0x001A, 5},{0x0036, 6},{0x0047, 7},
-    {0x0044, 7},{0x0018, 7},{0x0033, 8},{0x00CB,10},
-    {0x0656,13},{0x0329,12},{0x0328,12},{0x0002, 3},
-    {0x0006, 4},{0x0019, 5},{0x000E, 5},{0x0037, 6},
-    {0x0009, 4},{0x000F, 5},{0x0002, 4},{0x0010, 5}
-  },
-  {
-    {0x0003, 3},{0x0018, 5},{0x0023, 6},{0x0077, 7},
-    {0x0194, 9},{0x1956,13},{0x32AF,14},{0x003A, 6},
-    {0x0076, 7},{0x0002, 3},{0x0001, 3},{0x001F, 5},
-    {0x001E, 5},{0x0014, 5},{0x0022, 6},{0x0064, 7},
-    {0x0197, 9},{0x0196, 9},{0x032B,10},{0x0654,11},
-    {0x32AE,14},{0x1955,13},{0x1954,13},{0x0000, 3},
-    {0x0009, 4},{0x001C, 5},{0x0015, 5},{0x0010, 5},
-    {0x000D, 4},{0x0017, 5},{0x0016, 5},{0x0033, 6}
-  },
-  {
-    {0x0005, 3},{0x0006, 4},{0x003E, 6},{0x0010, 5},
-    {0x0048, 7},{0x093F,12},{0x24FA,14},{0x0032, 6},
-    {0x0067, 7},{0x0002, 3},{0x0001, 3},{0x001B, 5},
-    {0x001E, 5},{0x0034, 6},{0x0066, 7},{0x0092, 8},
-    {0x0126, 9},{0x024E,10},{0x049E,11},{0x49F7,15},
-    {0x49F6,15},{0x24F9,14},{0x24F8,14},{0x0000, 3},
-    {0x0007, 4},{0x0018, 5},{0x0011, 5},{0x003F, 6},
-    {0x000E, 4},{0x0013, 5},{0x0035, 6},{0x0025, 6}
-  },
-  {
-    {0x0005, 3},{0x0008, 4},{0x0012, 5},{0x001C, 5},
-    {0x001C, 6},{0x00EA, 9},{0x1D75,14},{0x001E, 6},
-    {0x0066, 7},{0x0001, 3},{0x0002, 3},{0x001B, 5},
-    {0x001A, 5},{0x001F, 6},{0x003B, 7},{0x0074, 8},
-    {0x01D6,10},{0x03AF,11},{0x1D74,14},{0x1D77,14},
-    {0x1D76,14},{0x0EB9,13},{0x0EB8,13},{0x000F, 4},
-    {0x0006, 4},{0x0013, 5},{0x003B, 6},{0x003A, 6},
-    {0x0000, 3},{0x0018, 5},{0x0032, 6},{0x0067, 7}
-  },
-  {
-    {0x0004, 3},{0x000A, 4},{0x001B, 5},{0x000C, 4},
-    {0x000D, 5},{0x00E6, 8},{0x0684,11},{0x0072, 7},
-    {0x00E7, 8},{0x0002, 3},{0x0001, 3},{0x0017, 5},
-    {0x0016, 5},{0x0018, 6},{0x00D1, 8},{0x01A0, 9},
-    {0x0686,11},{0x0D0F,12},{0x0D0A,12},{0x1A17,13},
-    {0x1A16,13},{0x1A1D,13},{0x1A1C,13},{0x000F, 4},
-    {0x001D, 5},{0x000E, 5},{0x0035, 6},{0x0038, 6},
-    {0x0000, 3},{0x000F, 5},{0x0019, 6},{0x0069, 7}
-  },
-  {
-    {0x0003, 3},{0x000C, 4},{0x001B, 5},{0x0000, 3},
-    {0x0003, 4},{0x002E, 6},{0x0051, 9},{0x00BC, 8},
-    {0x0053, 9},{0x0004, 3},{0x0002, 3},{0x0016, 5},
-    {0x0015, 5},{0x0015, 7},{0x0050, 9},{0x00A4,10},
-    {0x0294,12},{0x052B,13},{0x052A,13},{0x052D,13},
-    {0x052C,13},{0x052F,13},{0x052E,13},{0x000E, 4},
-    {0x001A, 5},{0x0004, 5},{0x0028, 6},{0x0029, 6},
-    {0x000F, 4},{0x000B, 6},{0x005F, 7},{0x00BD, 8}
-  },
-  {
-    {0x0003, 4},{0x0009, 6},{0x00D0, 8},{0x01A3, 9},
-    {0x0344,10},{0x0D14,12},{0x1A2B,13},{0x0004, 4},
-    {0x0015, 7},{0x0000, 3},{0x000F, 4},{0x000B, 4},
-    {0x000C, 4},{0x000E, 4},{0x0009, 4},{0x001B, 5},
-    {0x000A, 5},{0x0014, 5},{0x000D, 5},{0x002A, 6},
-    {0x0014, 7},{0x068B,11},{0x1A2A,13},{0x0008, 4},
-    {0x000B, 5},{0x002B, 6},{0x000B, 6},{0x0069, 7},
-    {0x0035, 6},{0x0008, 6},{0x0007, 4},{0x000C, 5}
-  },
-  {
-    {0x000A, 4},{0x003C, 6},{0x0032, 7},{0x0030, 7},
-    {0x00C5, 9},{0x0621,12},{0x0620,12},{0x001F, 5},
-    {0x0033, 7},{0x0001, 3},{0x0000, 3},{0x000E, 4},
-    {0x000D, 4},{0x000C, 4},{0x0004, 4},{0x000D, 5},
-    {0x0026, 6},{0x0027, 6},{0x0014, 6},{0x0063, 8},
-    {0x0189,10},{0x0623,12},{0x0622,12},{0x000B, 4},
-    {0x0012, 5},{0x003D, 6},{0x0022, 6},{0x0015, 6},
-    {0x000B, 5},{0x0023, 6},{0x0007, 4},{0x0010, 5}
-  },
-  {
-    {0x000F, 4},{0x000C, 5},{0x0043, 7},{0x0010, 6},
-    {0x0044, 8},{0x0114,10},{0x0455,12},{0x0018, 5},
-    {0x0023, 7},{0x0001, 3},{0x0000, 3},{0x000E, 4},
-    {0x000D, 4},{0x0009, 4},{0x0019, 5},{0x0009, 5},
-    {0x0017, 6},{0x0016, 6},{0x0042, 7},{0x008B, 9},
-    {0x0454,12},{0x0457,12},{0x0456,12},{0x000B, 4},
-    {0x0015, 5},{0x000A, 5},{0x0029, 6},{0x0020, 6},
-    {0x000D, 5},{0x0028, 6},{0x0007, 4},{0x0011, 5}
-  },
-  {
-    {0x0001, 3},{0x001A, 5},{0x0029, 6},{0x002A, 6},
-    {0x00A0, 8},{0x0285,10},{0x1425,13},{0x0002, 5},
-    {0x0000, 7},{0x0002, 3},{0x0003, 3},{0x000C, 4},
-    {0x000B, 4},{0x0008, 4},{0x0012, 5},{0x0001, 6},
-    {0x0051, 7},{0x0001, 7},{0x0143, 9},{0x0508,11},
-    {0x1424,13},{0x1427,13},{0x1426,13},{0x000F, 4},
-    {0x001C, 5},{0x0003, 5},{0x0037, 6},{0x002B, 6},
-    {0x0013, 5},{0x0036, 6},{0x001D, 5},{0x0001, 5}
-  },
-  {
-    {0x0004, 3},{0x001F, 5},{0x003D, 6},{0x0006, 5},
-    {0x0016, 7},{0x0053, 9},{0x014A,11},{0x0034, 6},
-    {0x002A, 8},{0x0002, 3},{0x0003, 3},{0x000B, 4},
-    {0x000C, 4},{0x001C, 5},{0x0037, 6},{0x0017, 7},
-    {0x002B, 8},{0x0028, 8},{0x00A4,10},{0x052D,13},
-    {0x052C,13},{0x052F,13},{0x052E,13},{0x0000, 3},
-    {0x001D, 5},{0x0007, 5},{0x0004, 5},{0x0035, 6},
-    {0x0014, 5},{0x0036, 6},{0x0015, 5},{0x003C, 6}
-  },
-  {
-    {0x0004, 3},{0x000A, 4},{0x0007, 5},{0x001D, 5},
-    {0x0009, 6},{0x01F3, 9},{0x07C7,11},{0x0008, 6},
-    {0x01F0, 9},{0x0003, 3},{0x0002, 3},{0x000D, 4},
-    {0x000C, 4},{0x0017, 5},{0x007D, 7},{0x01F2, 9},
-    {0x07C6,11},{0x07C5,11},{0x1F12,13},{0x3E27,14},
-    {0x3E26,14},{0x1F11,13},{0x1F10,13},{0x0000, 3},
-    {0x001E, 5},{0x0006, 5},{0x0039, 6},{0x0038, 6},
-    {0x003F, 6},{0x002C, 6},{0x0005, 5},{0x002D, 6}
-  },
-  {
-    {0x0002, 3},{0x0007, 4},{0x0018, 5},{0x0003, 4},
-    {0x0005, 5},{0x0035, 7},{0x004F, 9},{0x0012, 7},
-    {0x04E5,13},{0x0005, 3},{0x0004, 3},{0x000D, 4},
-    {0x000E, 4},{0x0033, 6},{0x0026, 8},{0x009D,10},
-    {0x04E4,13},{0x04E7,13},{0x04E6,13},{0x04E1,13},
-    {0x04E0,13},{0x04E3,13},{0x04E2,13},{0x0000, 3},
-    {0x001F, 5},{0x000C, 5},{0x003D, 6},{0x003C, 6},
-    {0x0032, 6},{0x0034, 7},{0x001B, 6},{0x0008, 6}
-  },
-  {
-    {0x0000, 3},{0x0004, 4},{0x001C, 5},{0x000F, 4},
-    {0x0002, 4},{0x0007, 5},{0x0075, 7},{0x00E8, 8},
-    {0x1D2A,13},{0x0005, 3},{0x0004, 3},{0x000D, 4},
-    {0x000C, 4},{0x0077, 7},{0x0E96,12},{0x3A57,14},
-    {0x3A56,14},{0x3A5D,14},{0x3A5C,14},{0x3A5F,14},
-    {0x3A5E,14},{0x1D29,13},{0x1D28,13},{0x0003, 3},
-    {0x0006, 5},{0x000A, 5},{0x002C, 7},{0x0017, 6},
-    {0x0076, 7},{0x01D3, 9},{0x03A4,10},{0x002D, 7}
-  },
-  {
-    {0x000A, 4},{0x0024, 6},{0x00BF, 8},{0x0085, 8},
-    {0x0211,10},{0x0842,12},{0x1087,13},{0x0018, 5},
-    {0x0020, 6},{0x0001, 3},{0x0002, 3},{0x000E, 4},
-    {0x000D, 4},{0x0007, 4},{0x0013, 5},{0x0025, 6},
-    {0x005E, 7},{0x0043, 7},{0x00BE, 8},{0x0109, 9},
-    {0x1086,13},{0x0841,12},{0x0840,12},{0x000F, 4},
-    {0x0001, 4},{0x0011, 5},{0x0000, 5},{0x002E, 6},
-    {0x0019, 5},{0x0001, 5},{0x0006, 4},{0x0016, 5}
-  },
-  {
-    {0x0002, 3},{0x000F, 5},{0x006F, 7},{0x0061, 7},
-    {0x0374,10},{0x1BA8,13},{0x3753,14},{0x0012, 5},
-    {0x0036, 6},{0x0000, 3},{0x0001, 3},{0x000A, 4},
-    {0x000B, 4},{0x001A, 5},{0x0031, 6},{0x0060, 7},
-    {0x00DC, 8},{0x01BB, 9},{0x06EB,11},{0x1BAB,13},
-    {0x3752,14},{0x3755,14},{0x3754,14},{0x000E, 4},
-    {0x0006, 4},{0x0013, 5},{0x000E, 5},{0x003E, 6},
-    {0x0008, 4},{0x001E, 5},{0x0019, 5},{0x003F, 6}
-  },
-  {
-    {0x0003, 3},{0x001C, 5},{0x0025, 6},{0x0024, 6},
-    {0x01DA, 9},{0x1DBD,13},{0x3B7C,14},{0x003C, 6},
-    {0x003D, 6},{0x0000, 3},{0x0001, 3},{0x000B, 4},
-    {0x000A, 4},{0x000B, 5},{0x0077, 7},{0x00EC, 8},
-    {0x03B6,10},{0x076E,11},{0x1DBF,13},{0x76FB,15},
-    {0x76FA,15},{0x3B79,14},{0x3B78,14},{0x000D, 4},
-    {0x001F, 5},{0x0013, 5},{0x000A, 5},{0x0008, 5},
-    {0x000C, 4},{0x0008, 4},{0x0009, 5},{0x003A, 6}
-  },
-  {
-    {0x0005, 3},{0x0003, 4},{0x0004, 5},{0x0010, 5},
-    {0x008F, 8},{0x0475,11},{0x11D1,13},{0x0079, 7},
-    {0x0027, 6},{0x0002, 3},{0x0003, 3},{0x0001, 4},
-    {0x0000, 4},{0x0026, 6},{0x0046, 7},{0x011C, 9},
-    {0x0477,11},{0x08ED,12},{0x11D0,13},{0x11D3,13},
-    {0x11D2,13},{0x11D9,13},{0x11D8,13},{0x000D, 4},
-    {0x001F, 5},{0x0012, 5},{0x0005, 5},{0x003D, 6},
-    {0x000C, 4},{0x000E, 4},{0x0022, 6},{0x0078, 7}
-  },
-  {
-    {0x0005, 3},{0x000C, 4},{0x001B, 5},{0x0000, 4},
-    {0x0006, 6},{0x03E2,10},{0x3E3D,14},{0x000F, 7},
-    {0x0034, 6},{0x0003, 3},{0x0002, 3},{0x001E, 5},
-    {0x001D, 5},{0x007D, 7},{0x01F0, 9},{0x07C6,11},
-    {0x3E3C,14},{0x3E3F,14},{0x3E3E,14},{0x3E39,14},
-    {0x3E38,14},{0x3E3B,14},{0x3E3A,14},{0x0008, 4},
-    {0x001C, 5},{0x0002, 5},{0x003F, 6},{0x0035, 6},
-    {0x0009, 4},{0x0001, 3},{0x000E, 7},{0x00F9, 8}
-  },
-  {
-    {0x0004, 3},{0x000B, 4},{0x0001, 4},{0x000A, 4},
-    {0x001E, 6},{0x00E0, 9},{0x0E1E,13},{0x0071, 8},
-    {0x0039, 7},{0x0007, 3},{0x0006, 3},{0x000D, 5},
-    {0x000C, 5},{0x0020, 7},{0x01C2,10},{0x1C3F,14},
-    {0x1C3E,14},{0x0E19,13},{0x0E18,13},{0x0E1B,13},
-    {0x0E1A,13},{0x0E1D,13},{0x0E1C,13},{0x0000, 4},
-    {0x0009, 5},{0x001D, 6},{0x001F, 6},{0x0011, 6},
-    {0x0005, 4},{0x0001, 3},{0x0043, 8},{0x0042, 8}
-  },
-  {
-    {0x0004, 3},{0x000D, 4},{0x0007, 4},{0x0002, 3},
-    {0x0014, 5},{0x016C, 9},{0x16D1,13},{0x02DF,10},
-    {0x016E, 9},{0x0000, 2},{0x0007, 3},{0x002C, 6},
-    {0x002B, 6},{0x02DE,10},{0x16D0,13},{0x16D3,13},
-    {0x16D2,13},{0x2DB5,14},{0x2DB4,14},{0x2DB7,14},
-    {0x2DB6,14},{0x16D9,13},{0x16D8,13},{0x000C, 5},
-    {0x002A, 6},{0x005A, 7},{0x001B, 6},{0x001A, 6},
-    {0x0017, 5},{0x000C, 4},{0x05B7,11},{0x05B5,11}
-  },
-  {
-    {0x0002, 2},{0x000F, 4},{0x001C, 5},{0x000C, 4},
-    {0x003B, 6},{0x01AC, 9},{0x1AD8,13},{0x35B3,14},
-    {0x35B2,14},{0x0001, 2},{0x0000, 2},{0x0069, 7},
-    {0x0068, 7},{0x35BD,14},{0x35BC,14},{0x35BF,14},
-    {0x35BE,14},{0x35B9,14},{0x35B8,14},{0x35BB,14},
-    {0x35BA,14},{0x35B5,14},{0x35B4,14},{0x01A9, 9},
-    {0x01A8, 9},{0x035A,10},{0x00D7, 8},{0x00D5, 8},
-    {0x003A, 6},{0x001B, 5},{0x35B7,14},{0x35B6,14}
-  },
-  {
-    {0x0000, 3},{0x0010, 5},{0x0072, 7},{0x0071, 7},
-    {0x0154, 9},{0x0AAB,12},{0x0AA8,12},{0x0014, 5},
-    {0x0070, 7},{0x0002, 3},{0x0003, 3},{0x000C, 4},
-    {0x000B, 4},{0x0003, 4},{0x0011, 5},{0x0073, 7},
-    {0x0054, 7},{0x00AB, 8},{0x02AB,10},{0x1553,13},
-    {0x1552,13},{0x1555,13},{0x1554,13},{0x000D, 4},
-    {0x001E, 5},{0x0012, 5},{0x003E, 6},{0x002B, 6},
-    {0x0002, 4},{0x003F, 6},{0x001D, 5},{0x0013, 5}
-  },
-  {
-    {0x0003, 3},{0x001F, 5},{0x0029, 6},{0x003D, 6},
-    {0x000C, 7},{0x0069,10},{0x0345,13},{0x0002, 5},
-    {0x0028, 6},{0x0002, 3},{0x0001, 3},{0x000E, 4},
-    {0x000C, 4},{0x0015, 5},{0x0007, 6},{0x001B, 8},
-    {0x006B,10},{0x006A,10},{0x0344,13},{0x0347,13},
-    {0x0346,13},{0x01A1,12},{0x01A0,12},{0x000B, 4},
-    {0x001A, 5},{0x0012, 5},{0x0000, 5},{0x003C, 6},
-    {0x0008, 4},{0x001B, 5},{0x0013, 5},{0x0001, 5}
-  },
-  {
-    {0x0004, 3},{0x0004, 4},{0x003F, 6},{0x0014, 5},
-    {0x0056, 7},{0x015C, 9},{0x15D5,13},{0x003C, 6},
-    {0x002A, 6},{0x0000, 3},{0x0001, 3},{0x000E, 4},
-    {0x000D, 4},{0x000C, 5},{0x00AF, 8},{0x02BB,10},
-    {0x15D4,13},{0x15D7,13},{0x15D6,13},{0x15D1,13},
-    {0x15D0,13},{0x15D3,13},{0x15D2,13},{0x000B, 4},
-    {0x0019, 5},{0x000D, 5},{0x003E, 6},{0x0031, 6},
-    {0x0007, 4},{0x0005, 4},{0x003D, 6},{0x0030, 6}
-  },
-  {
-    {0x0005, 3},{0x0008, 4},{0x001A, 5},{0x0000, 4},
-    {0x0036, 6},{0x0011, 8},{0x0106,12},{0x000A, 7},
-    {0x006E, 7},{0x0002, 3},{0x0003, 3},{0x0003, 4},
-    {0x0002, 4},{0x006F, 7},{0x0021, 9},{0x020F,13},
-    {0x020E,13},{0x0101,12},{0x0100,12},{0x0103,12},
-    {0x0102,12},{0x0105,12},{0x0104,12},{0x000C, 4},
-    {0x001E, 5},{0x0003, 5},{0x003E, 6},{0x003F, 6},
-    {0x0009, 4},{0x000E, 4},{0x000B, 7},{0x0009, 7}
-  },
-  {
-    {0x0002, 3},{0x000E, 4},{0x001E, 5},{0x000C, 4},
-    {0x001F, 5},{0x006E, 7},{0x00AD,10},{0x00AF,10},
-    {0x0014, 7},{0x0004, 3},{0x0003, 3},{0x001A, 5},
-    {0x0017, 5},{0x002A, 8},{0x0576,13},{0x0AEF,14},
-    {0x0AEE,14},{0x0571,13},{0x0570,13},{0x0573,13},
-    {0x0572,13},{0x0575,13},{0x0574,13},{0x0003, 4},
-    {0x0016, 5},{0x0004, 5},{0x0036, 6},{0x000B, 6},
-    {0x000A, 4},{0x0000, 3},{0x006F, 7},{0x00AC,10}
-  },
-  {
-    {0x0004, 3},{0x0005, 4},{0x0003, 3},{0x0001, 3},
-    {0x0004, 4},{0x002F, 6},{0x0526,11},{0x1495,13},
-    {0x00A6, 8},{0x0007, 3},{0x0006, 3},{0x002D, 6},
-    {0x002C, 6},{0x1494,13},{0x1497,13},{0x1496,13},
-    {0x1491,13},{0x1490,13},{0x1493,13},{0x1492,13},
-    {0x293D,14},{0x293C,14},{0x293F,14},{0x0000, 3},
-    {0x0028, 6},{0x00A5, 8},{0x0148, 9},{0x00A7, 8},
-    {0x002E, 6},{0x0015, 5},{0x0A4E,12},{0x293E,14}
-  },
-  {
-    {0x0004, 3},{0x0005, 4},{0x0003, 3},{0x0001, 3},
-    {0x0004, 4},{0x002F, 6},{0x0526,11},{0x1495,13},
-    {0x00A6, 8},{0x0007, 3},{0x0006, 3},{0x002D, 6},
-    {0x002C, 6},{0x1494,13},{0x1497,13},{0x1496,13},
-    {0x1491,13},{0x1490,13},{0x1493,13},{0x1492,13},
-    {0x293D,14},{0x293C,14},{0x293F,14},{0x0000, 3},
-    {0x0028, 6},{0x00A5, 8},{0x0148, 9},{0x00A7, 8},
-    {0x002E, 6},{0x0015, 5},{0x0A4E,12},{0x293E,14}
-  },
-  {
-    {0x0004, 3},{0x0005, 4},{0x0003, 3},{0x0001, 3},
-    {0x0004, 4},{0x002F, 6},{0x0526,11},{0x1495,13},
-    {0x00A6, 8},{0x0007, 3},{0x0006, 3},{0x002D, 6},
-    {0x002C, 6},{0x1494,13},{0x1497,13},{0x1496,13},
-    {0x1491,13},{0x1490,13},{0x1493,13},{0x1492,13},
-    {0x293D,14},{0x293C,14},{0x293F,14},{0x0000, 3},
-    {0x0028, 6},{0x00A5, 8},{0x0148, 9},{0x00A7, 8},
-    {0x002E, 6},{0x0015, 5},{0x0A4E,12},{0x293E,14}
-  },
-  {
-    {0x0003, 3},{0x0011, 5},{0x0020, 6},{0x0074, 7},
-    {0x010D, 9},{0x0863,12},{0x0860,12},{0x000A, 5},
-    {0x0075, 7},{0x0001, 3},{0x0000, 3},{0x000B, 4},
-    {0x000A, 4},{0x0018, 5},{0x0038, 6},{0x0042, 7},
-    {0x010F, 9},{0x010E, 9},{0x0219,10},{0x10C3,13},
-    {0x10C2,13},{0x10C5,13},{0x10C4,13},{0x000F, 4},
-    {0x0004, 4},{0x0019, 5},{0x000B, 5},{0x0039, 6},
-    {0x0009, 4},{0x001B, 5},{0x001A, 5},{0x003B, 6}
-  },
-  {
-    {0x0005, 3},{0x0001, 4},{0x003E, 6},{0x0001, 5},
-    {0x00E2, 8},{0x1C6F,13},{0x38D9,14},{0x0039, 6},
-    {0x001F, 6},{0x0002, 3},{0x0001, 3},{0x0009, 4},
-    {0x0008, 4},{0x0000, 5},{0x0070, 7},{0x01C7, 9},
-    {0x038C,10},{0x071A,11},{0x38D8,14},{0x38DB,14},
-    {0x38DA,14},{0x38DD,14},{0x38DC,14},{0x000D, 4},
-    {0x001D, 5},{0x000E, 5},{0x003F, 6},{0x003C, 6},
-    {0x000C, 4},{0x0006, 4},{0x003D, 6},{0x001E, 6}
-  },
-  {
-    {0x0006, 3},{0x000B, 4},{0x0011, 5},{0x001E, 5},
-    {0x0074, 7},{0x03AA,10},{0x1D5C,13},{0x0001, 6},
-    {0x0021, 6},{0x0001, 3},{0x0002, 3},{0x0007, 4},
-    {0x0006, 4},{0x003E, 6},{0x00EB, 8},{0x01D4, 9},
-    {0x0EAF,12},{0x3ABB,14},{0x3ABA,14},{0x1D59,13},
-    {0x1D58,13},{0x1D5B,13},{0x1D5A,13},{0x000A, 4},
-    {0x001C, 5},{0x0001, 5},{0x003F, 6},{0x003B, 6},
-    {0x0001, 4},{0x0009, 4},{0x0020, 6},{0x0000, 6}
-  },
-  {
-    {0x0004, 3},{0x000A, 4},{0x0017, 5},{0x0004, 4},
-    {0x0016, 6},{0x016A, 9},{0x16B1,13},{0x0017, 7},
-    {0x005B, 7},{0x0006, 3},{0x0007, 3},{0x0001, 4},
-    {0x0000, 4},{0x000A, 6},{0x02D7,10},{0x0B5A,12},
-    {0x16B0,13},{0x16B3,13},{0x16B2,13},{0x2D6D,14},
-    {0x2D6C,14},{0x2D6F,14},{0x2D6E,14},{0x0006, 4},
-    {0x000A, 5},{0x0004, 5},{0x002C, 6},{0x0017, 6},
-    {0x0003, 4},{0x0007, 4},{0x0016, 7},{0x00B4, 8}
-  },
-  {
-    {0x0005, 3},{0x000D, 4},{0x0005, 4},{0x0009, 4},
-    {0x0033, 6},{0x0193, 9},{0x192C,13},{0x0061, 8},
-    {0x0031, 7},{0x0000, 2},{0x0007, 3},{0x0010, 5},
-    {0x0011, 5},{0x00C8, 8},{0x192F,13},{0x325B,14},
-    {0x325A,14},{0x1929,13},{0x1928,13},{0x192B,13},
-    {0x192A,13},{0x325D,14},{0x325C,14},{0x0018, 5},
-    {0x001A, 6},{0x001B, 6},{0x0065, 7},{0x0019, 6},
-    {0x0004, 4},{0x0007, 4},{0x0060, 8},{0x0324,10}
-  },
-  {
-    {0x0006, 3},{0x0000, 3},{0x0002, 4},{0x000F, 4},
-    {0x0039, 6},{0x01D9, 9},{0x1D82,13},{0x0761,11},
-    {0x03BE,10},{0x0001, 2},{0x0002, 2},{0x000F, 6},
-    {0x000E, 6},{0x0762,11},{0x3B07,14},{0x3B06,14},
-    {0x3B1D,14},{0x3B1C,14},{0x3B1F,14},{0x3B1E,14},
-    {0x3B19,14},{0x3B18,14},{0x3B1B,14},{0x0038, 6},
-    {0x01DE, 9},{0x00ED, 8},{0x03BF,10},{0x00EE, 8},
-    {0x003A, 6},{0x0006, 5},{0x0EC0,12},{0x3B1A,14}
-  },
-  {
-    {0x0000, 2},{0x0002, 3},{0x000F, 5},{0x0006, 4},
-    {0x001C, 6},{0x01D0,10},{0x0E8C,13},{0x1D1B,14},
-    {0x1D1A,14},{0x0003, 2},{0x0002, 2},{0x00EA, 9},
-    {0x00E9, 9},{0x0E89,13},{0x0E88,13},{0x0E8B,13},
-    {0x0E8A,13},{0x1D65,14},{0x1D64,14},{0x1D67,14},
-    {0x1D66,14},{0x1D61,14},{0x1D60,14},{0x03AD,11},
-    {0x1D63,14},{0x1D62,14},{0x1D1D,14},{0x1D1C,14},
-    {0x003B, 7},{0x01D7,10},{0x1D1F,14},{0x1D1E,14}
-  },
-  {
-    {0x0002, 2},{0x000F, 4},{0x001C, 5},{0x000C, 4},
-    {0x003B, 6},{0x01AC, 9},{0x1AD8,13},{0x35B3,14},
-    {0x35B2,14},{0x0001, 2},{0x0000, 2},{0x0069, 7},
-    {0x0068, 7},{0x35BD,14},{0x35BC,14},{0x35BF,14},
-    {0x35BE,14},{0x35B9,14},{0x35B8,14},{0x35BB,14},
-    {0x35BA,14},{0x35B5,14},{0x35B4,14},{0x01A9, 9},
-    {0x01A8, 9},{0x035A,10},{0x00D7, 8},{0x00D5, 8},
-    {0x003A, 6},{0x001B, 5},{0x35B7,14},{0x35B6,14}
-  }
-};
-
-
-
-/*A description of a Huffman code value used when encoding the tree.*/
-typedef struct{
-  /*The bit pattern, left-shifted so that the MSB of all patterns is
-     aligned.*/
-  ogg_uint32_t pattern;
-  /*The amount the bit pattern was shifted.*/
-  int          shift;
-  /*The token this bit pattern represents.*/
-  int          token;
-}oc_huff_entry;
-
-
-
-/*Compares two oc_huff_entry structures by their bit patterns.
-  _c1: The first entry to compare.
-  _c2: The second entry to compare.
-  Return: <0 if _c1<_c2, >0 if _c1>_c2.*/
-static int huff_entry_cmp(const void *_c1,const void *_c2){
-  ogg_uint32_t b1;
-  ogg_uint32_t b2;
-  b1=((const oc_huff_entry *)_c1)->pattern;
-  b2=((const oc_huff_entry *)_c2)->pattern;
-  return b1<b2?-1:b1>b2?1:0;
-}
-
-/*Encodes a description of the given Huffman tables.
-  Although the codes are stored in the encoder as flat arrays, in the bit
-   stream and in the decoder they are structured as a tree.
-  This function recovers the tree structure from the flat array and then
-   writes it out.
-  Note that the codes MUST form a Huffman code, and not merely a prefix-free
-   code, since the binary tree is assumed to be full.
-  _opb:   The buffer to store the tree in.
-  _codes: The Huffman tables to pack.
-  Return: 0 on success, or a negative value if one of the given Huffman tables
-   does not form a full, prefix-free code.*/
-int oc_huff_codes_pack(oggpack_buffer *_opb,
- const th_huff_code _codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS]){
-  int i;
-  for(i=0;i<TH_NHUFFMAN_TABLES;i++){
-    oc_huff_entry entries[TH_NDCT_TOKENS];
-    int           bpos;
-    int           maxlen;
-    int           mask;
-    int           j;
-    /*First, find the maximum code length so we can align all the bit
-       patterns.*/
-    maxlen=_codes[i][0].nbits;
-    for(j=1;j<TH_NDCT_TOKENS;j++){
-      maxlen=OC_MAXI(_codes[i][j].nbits,maxlen);
-    }
-    mask=(1<<maxlen)-1;
-    /*Copy over the codes into our temporary workspace.
-      The bit patterns are aligned, and the original entry each code is from
-       is stored as well.*/
-    for(j=0;j<TH_NDCT_TOKENS;j++){
-      entries[j].shift=maxlen-_codes[i][j].nbits;
-      entries[j].pattern=_codes[i][j].pattern<<entries[j].shift&mask;
-      entries[j].token=j;
-    }
-    /*Sort the codes into ascending order.
-      This is the order the leaves of the tree will be traversed.*/
-    qsort(entries,TH_NDCT_TOKENS,sizeof(entries[0]),huff_entry_cmp);
-    /*For each leaf of the tree:*/
-    bpos=maxlen;
-    for(j=0;j<TH_NDCT_TOKENS;j++){
-      int bit;
-      /*If this code has any bits at all.*/
-      if(entries[j].shift<maxlen){
-        /*Descend into the tree, writing a bit for each branch.*/
-        for(;bpos>entries[j].shift;bpos--)oggpackB_write(_opb,0,1);
-        /*Mark this as a leaf node, and write its value.*/
-        oggpackB_write(_opb,1,1);
-        oggpackB_write(_opb,entries[j].token,5);
-        /*For each 1 branch we've descended, back up the tree until we reach a
-           0 branch.*/
-        bit=1<<bpos;
-        for(;entries[j].pattern&bit;bpos++)bit<<=1;
-        /*Validate the code.*/
-        if(j+1<TH_NDCT_TOKENS){
-          mask=~(bit-1)<<1;
-          /*The next entry should have a 1 bit where we had a 0, and should
-             match our code above that bit.
-            This verifies both fullness and prefix-freeness simultaneously.*/
-          if(!(entries[j+1].pattern&bit)||
-           (entries[j].pattern&mask)!=(entries[j+1].pattern&mask)){
-            return TH_EINVAL;
-          }
-        }
-        /*If there are no more codes, we should have ascended back to the top
-           of the tree.*/
-        else if(bpos<maxlen)return TH_EINVAL;
-      }
-    }
-  }
-  return 0;
-}

Deleted: experimental/j/theora-mashup/lib/dec/huffenc.h
===================================================================
--- experimental/j/theora-mashup/lib/dec/huffenc.h	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/huffenc.h	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,17 +0,0 @@
-#if !defined(_huffenc_H)
-# define _huffenc_H (1)
-# include "huffman.h"
-
-
-
-extern const th_huff_code
- TH_VP31_HUFF_CODES[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS];
-
-
-
-int oc_huff_codes_pack(oggpack_buffer *_opb,
- const th_huff_code _codes[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS]);
-
-
-
-#endif

Deleted: experimental/j/theora-mashup/lib/dec/impmap.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/impmap.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/impmap.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,2287 +0,0 @@
-#include <stdlib.h>
-#include <float.h>
-#include <math.h>
-#include <string.h>
-#include <ogg/ogg.h>
-#include "encint.h"
-#include "psych.h"
-#if defined(OC_DUMP_IMAGES)
-# include <stdio.h>
-# include "png.h"
-#endif
-
-/*Importance map calculations.
-
-  This is where we attempt to model high-level vision processes, such as
-   object tracking and visual attention.
-  The importance map isolates "regions of interest" or areas of the image that
-   are likely to draw viewer attention.
-  Because the visual accuity of the fovea is so much higher than in a viewer's
-   peripheral vision, bits can be taken from uninteresting areas and allocated
-   to areas that the viewer is actually looking at.
-
-  The algorithm here is mostly that which was described by Osberger in his
-   Ph.D. thesis \cite{Osb99}.
-  This document was once available online, but as both the student and his
-   supervising professor have since left the university, it does not appear to
-   be available any longer.
-  The algorithm has the advantages of being simple (and thus fairly fast),
-   requiring no tuning parameters, and having demonstrable correlation with
-   actual human fixations (for still images only).
-  It is also well described in the thesis, which makes a re-implementation
-   from scratch fairly easy.
-
-  It is, however, a fairly ad-hoc algorithm.
-  While its design decisions are in fact made by taking into account real
-   properties of the human visual system, they are not necessarily the only
-   decisions that could be made, or even the best.
-  Thus experimentation could potentially produce a better method, but this
-   would require collecting our own eye-tracking data to validate the model
-   against.
-
-  Also, its extension to video has not been experimentally validated.
-  Although correlation was demonstrated against actual human fixation points
-   for still images, a similar experiment was not carried out for video
-   sequences.
-
-  @PHDTHESIS{Osb99,
-    author="Wilfried Osberger",
-    title="Perceptual Vision Models for Picture Quality Assessment and
-     Compression Applications",
-    school="Queensland University of Technology",
-    address="Brisbane, Australia",
-    month="Mar.",
-    year=1999
-  }*/
-
-/*The number of weighting factors assigned to each segmented region.*/
-#define OC_IMPMAP_NSEG_WEIGHTS          (5)
-
-/*The number of weighting factors which must be rescaled into the interval
-   [0,1]*/
-#define OC_IMPMAP_NSEG_RESCALED_WEIGHTS (2)
-
-/*The list of weighting factors assigned to each segmented region.*/
-enum{
-  /*Contrast with surrounding regions.*/
-  OC_IMPMAP_WEIGHT_CONTRAST,
-  /*Unusualness of the region's shape.*/
-  OC_IMPMAP_WEIGHT_SHAPE,
-  /*Note: These three come last, since they do not need to be rescaled.*/
-  /*Size of the region.*/
-  OC_IMPMAP_WEIGHT_SIZE,
-  /*Closeness of the region to the image center.*/
-  OC_IMPMAP_WEIGHT_LOCATION,
-  /*Degree to which the region is in the foreground vs. background.*/
-  OC_IMPMAP_WEIGHT_FOREGROUND
-};
-
-/*The limits for assessing motion as an attractor of attention, in deg/sec.
-  Importance increases linearly from 0 to 1 over the range [min,p1], stays
-   constant over [p1,p2], and decreases linearly over the range [p2,max].
-  It might be wise to disable the upper limit, so that moving farther away
-   from the screen does not make the image look worse as faster motions are
-   slowed down enough to become visible.*/
-
-/*Minimum important motion.*/
-#define OC_IMPMAP_MOT_MIN (0.0F)
-/*First peak important motion.*/
-#define OC_IMPMAP_MOT_P1  (5.0F)
-/*Second peak important motion.*/
-#define OC_IMPMAP_MOT_P2  (10.0F)
-/*Maximum important motion.*/
-#define OC_IMPMAP_MOT_MAX (15.0F)
-
-/*Image segmentation code.
-  The image segmentation drives the rest of the importance map calculations.
-  Improving the segmentation process improves the entire rest of the process.
-  The segmentation algorithm used here roughly corresponds to the one
-   described by Osberger, since minimal research (a few hours on the web) did
-   not turn up anything that looked to have a better speed-quality tradeoff.
-
-  The algorithm is a standard split-merge variant.
-  The split phase starts with one region that covers the whole image.
-  So long as its variance is above a threshold, it is recursively subdivided
-   into four sub-regions.
-  After the split phase, a merge phase combines neighboring sub-regions so
-   long as the variance of the combined region stays below a threshold.
-  Finally, all regions smaller than a fixed number of pixels are combined with
-   their largest neighbor.
-  All determinations of borders, neighbors and connectedness use
-   4-connectivity.
-
-  Although Osberger used a fixed threshold to determine whether or not to
-   split or merge regions, we use the Bayesian Information Criterion instead.
-  This removes the only adjustable parameter from Osberger's model.
-  The BIC for a model is:
-
-  BIC(model)=log P(data|model)-
-   \lambda/2(model dimension)log(data sample count).
-
-  Using a Gaussian distribution as the model, this reduces to
-   -(1/2)(data sample count)log(variance)-\lambda*log(data sample count).
-  We scale this by two to avoid the extra multiply.
-  The weight \lambda in the last term is traditionally introduced to
-   penalize small samples, but can also serve as a compensation for the large
-   variances found with data in the range 0..255.
-  Like Osberger, however, a strict minimal region size is enforced.
-  The minimum size allows us to place a hard upper bound on the number of
-   regions in order to allocate storage once ahead of time.
-
-  The variances are computed using a reduced-resolution table of sums.
-  This table contains accumulated sums from the upper-left corner of the
-   image sampled every OC_SEG_MOMENT_RES pixels.
-  The initial row and column of the table contain all zeros, so that
-   sum[width][height] works as expected even if width or height are 0.
-  The reduced resolution is designed to reduce memory requirements, since
-   otherwise they would require 8 bytes per pixel.
-  With a resolution of 16 pixels, this is reduced to 1/32 byte per pixel.
-  Once recursion descends below this resolution level, a local moment table is
-   computed for the remaining lookups.
-  Because the local moment table is small (2312 bytes), it easily fits in
-   cache.
-  Thus even though this method requires scanning the input image as
-   much as two times, it yields a vast reduction in the amount of memory
-   outside of cache that is accessed (2.125 bytes read, 0.03125 bytes written
-   per pixel as compared to 10 bytes read, 8 bytes written).
-
-  Osberger never specifies how the next region pair to consider merging is
-   chosen, despite this order playing a large role in the final output.
-  Our strategy is as follows:
-  As soon as a region is created, its existing neighbors are enumerated and
-   any potential merge pairs are put on a heap.
-  The heap is then emptied by merging the pair at the top.
-  The newly created region then checks its neighbors and adds those pairs to
-   the heap if necessary, and the process continues until the heap is empty.
-  
-  First local regions are created in a local block, OC_SEG_MOMENT_RES by
-   OC_SEG_MOMENT_RES pixels.
-  These are given temporary, negative labels starting at -2 (-1 is reserved
-   to indicate no region).
-  Once all the regions in a local block are established, all the pairs
-   involving a local region that does not satisfy the minimum pixel size are
-   placed on the heap, and merging continues until the heap is empty.
-  This is unlike Osberger, who simply merged small regions with their largest
-   neighbor.
-
-  Because small regions can only accumulate in a local block, the total number
-   of regions present at any one time can be reasonably bounded.
-  Otherwise, the best bound available would be the number of pixels in the
-   image.
-  This also removes overhead early on required to deal with one pixel regions
-   that often accumulate on region borders.
-   
-  TODO: Initial results do not look very promising.
-  Candidates to replace this segmentation algorithm are needed.
-  One potential solution may be to perform the initial split based upon edge
-   detection results within the region instead of on region variance.
-  Also, operating on an RLE-compressed label image may provide further speed
-   improvements.*/
-
-/*The log base 2 of the resolution of the global moment table.*/
-#define OC_SEG_MOMENT_RES_LOG   (4)
-/*The resolution of the global moment table.*/
-#define OC_SEG_MOMENT_RES       (1<<OC_SEG_MOMENT_RES_LOG)
-/*A mask for the bits below the resolution of the moment table.*/
-#define OC_SEG_MOMENT_RES_MASK  (OC_SEG_MOMENT_RES-1)
-
-/*The maximum number of local regions.*/
-#define OC_SEG_NLOCAL_REGS      (OC_SEG_MOMENT_RES*OC_SEG_MOMENT_RES)
-/*The maximum number of local pairs.*/
-#define OC_SEG_NLOCAL_PAIRS     (OC_SEG_MOMENT_RES*(3*OC_SEG_MOMENT_RES+2)-6)
-
-/*The minimum size of a segmented region.
-  Imposing this limit gives us an upper bound on the number of regions that
-   can be created, which allows us to allocate storage in advance.*/
-#define OC_SEG_REGION_SZ_MIN    (16)
-
-/*The weight to associate with the model cost, scaled by a factor of 2.*/
-/*#define OC_SEG_MODEL_WEIGHT     (2*1)*/
-#define OC_SEG_MODEL_SPLIT_WEIGHT (2*4)
-#define OC_SEG_MODEL_MERGE_WEIGHT (2*16)
-
-
-
-typedef struct oc_seg_region       oc_seg_region;
-typedef struct oc_seg_link         oc_seg_link;
-typedef struct oc_seg_pair         oc_seg_pair;
-typedef struct oc_seg_ctx          oc_seg_ctx;
-
-
-
-/*Called when the BIC factor of a candidate merge pair has been updated to
-   add it to, remove it from, or update its position in the heap.
-  _seg:      The segmentation context.
-  _pair:     The pair that was updated.
-  _old_dbic: The old delta BIC factor.*/
-typedef void (*oc_seg_pair_reheap_func)(oc_seg_ctx *_seg,oc_seg_pair *_pair,
- float _old_dbic);
-
-
-
-/*Region pairs belong to two doubly linked lists: one for each region they
-   belong to.
-  This is a link used in those lists.
-  The lists are circular, to minimize special cases, with the head/tail link
-   pointing to a NULL pair contained in the region itself.*/
-struct oc_seg_link{
-  /*The region index of the other region in this pair.
-    For the link stored within a region itself, this index is the region label
-     to use after merging.*/
-  int          regi;
-  /*The pair this link is contained in, or NULL if it is the head/tail link.*/
-  oc_seg_pair *pair;
-  /*The next link in the chain.*/
-  oc_seg_link *next;
-  /*The previous link in the chain.*/
-  oc_seg_link *prev;
-};
-
-struct oc_seg_region{
-  /*The list of pairs to which this region belongs.*/
-  oc_seg_link link;
-  /*The number of pixels in the region.*/
-  int         npixels;
-  /*The sum of the pixel values in the region.*/
-  float       sumx;
-  /*The sum of the squared pixel values in the region.*/
-  float       sumx2;
-  /*The base BIC level used to drive merge decisions.*/
-  float       bic;
-};
-
-/*A pair of neighboring regions.*/
-struct oc_seg_pair{
-  /*The links for this pair.*/
-  oc_seg_link   links[2];
-  /*The number of pixels in the region.*/
-  int           npixels;
-  /*The sum of the pixel values in the region.*/
-  float         sumx;
-  /*The sum of the squared pixel values in the region.*/
-  float         sumx2;
-  /*The base BIC level used to drive merge decisions.*/
-  float         bic;
-  /*The location in the merge heap.*/
-  int           heapi;
-  /*The BIC delta for keeping the regions separate.*/
-  float         dbic;
-};
-
-/*Buffers and tables needed to drive the segmentation process.*/
-struct oc_seg_ctx{
-  /*The global first moment table.*/
-  float                   **sumx;
-  /*The global second moment table.*/
-  float                   **sumx2;
-  /*The local first moment table.*/
-  float                   **local_sumx;
-  /*The local second moment table.*/
-  float                   **local_sumx2;
-  /*The region labels for each pixel.*/
-  int                     **labels;
-  /*The minimum power of 2 greater than or equal to the image width and
-     height.*/
-  int                       level_max;
-  /*The number of local regions in a local segmentation.
-    This count starts at -2 and goes down as each region is added.*/
-  int                       nlocal_regions;
-  /*The number of regions in the segmentation.*/
-  int                       nregions;
-  /*The total number of regions allocated.*/
-  int                       cregions;
-  /*The number of pairs in use.*/
-  int                       npairs;
-  /*The size of the global heap.*/
-  int                       nheap;
-  /*The list of regions.*/
-  oc_seg_region            *regions;
-  /*The relabeling list used in the last step.*/
-  int                      *relabels;
-  /*The storage for the neighbor lists for each region.*/
-  oc_seg_pair              *pairs;
-  /*The list of available pairs.*/
-  oc_seg_link              *free_pairs;
-  /*The global merge heap.*/
-  oc_seg_pair             **heap;
-  /*The reheaping function.*/
-  oc_seg_pair_reheap_func   reheap;
-};
-
-
-
-typedef struct oc_impmap_region   oc_impmap_region;
-
-
-
-/*Called to fill in the importance values for each of the chroma plane
-   fragments given the Y plane fragments' importances.
-  A different version of this function is called depending on the type of
-   chroma decimation active.
-  _efrag:             The encoding fragment info array.
-  _map:               The fragment map for the current macro block.
-  _yfrag_imp_weights: The weight for each fragment in the Y plane.*/
-typedef void (*oc_impmap_chroma_frag_weight_func)(
- oc_fragment_enc_info *_efrag,oc_mb_map _map,
- const float _yfrag_imp_weights[4]);
-
-
-
-/*The per-region information gathered for the importance map.*/
-struct oc_impmap_region{
-  /*The number of pixels on the region's border.*/
-  int              nborder;
-  /*The number of pixels on the region's edge.*/
-  int              nedge;
-  /*The number of pixels in the central 25% of the image.*/
-  int              ncenter;
-  /*The weight given to the region because of its contrast.*/
-  float            weights[OC_IMPMAP_NSEG_WEIGHTS];
-  /*The final importance of the region.*/
-  float            importance;
-};
-
-/*Importance map context information.*/
-struct oc_impmap_ctx{
-  /*The pipeline stage.*/
-  oc_enc_pipe_stage                  pipe;
-  /*Segmentation information for the Y plane.
-    Some day we may also wish to segment the chroma planes, or derive a
-     segmentation using all 3 planes at once.*/
-  oc_seg_ctx                         seg;
-  /*The reciprocal of the maximum region size to count towards a region's
-     importance.
-    This cap prevents very large regions from dominating the scene.*/
-  float                              inv_region_sz_max;
-  /*The reciprocal of the maximum number of edge pixels required to consider a
-     region completely in the background.
-    This value is used when computing the foreground weight of a region.*/
-  float                              inv_edge_sz_max;
-  /*The horizontal offset used to convert from image buffer coordinates to
-     label buffer coordinates.*/
-  int                                pic_x;
-  /*The vertical offset used to convert from image buffer coordinates to label
-     buffer coordinates.*/
-  int                                pic_y;
-  /*The boundaries of each of the three piecewise sections of the importance
-     function for motion, pre-adjusted to half-pixels/frame.*/
-  float                              mot_limits[4];
-  /*The average importance from the previous frame.*/
-  float                              imp_avg;
-  /*The per-region information gathered for the importance map.*/
-  oc_impmap_region                  *regions;
-  /*The encoding context we're embedded in.*/
-  oc_enc_ctx                        *enc;
-  /*The function used to update chroma fragment importances.*/
-  oc_impmap_chroma_frag_weight_func  chroma_frag_weight;
-};
-
-
-
-/*The following masks are used to test quad-tree child nodes for boundary
-   conditions.
-  The bits they are tested against are the following:
-  0: size>width
-  1: size>height
-  2: (size/2)>width
-  3: (size/2)>height
-  4: (size/2)==width
-  5: (size/2)==height
-  Here "size" is the size of quadtree nodes at the parent's level, and "width"
-   and "height" are the dimensions of the part of the parent node that lies
-   inside the image.
-
-  The quadtree nodes are organized as:
-  +---+---+
-  | 0 | 1 |
-  +---+---+
-  | 2 | 3 |
-  +---+---+
-*/
-
-/*If any of the bits in these masks are set, the corresponding child node
-   is completely clipped by the border.*/
-static const int OC_SEG_CLIP_MASKS[4]={0x0,0x14,0x28,0x3C};
-/*If the bit in these masks is set, the width of the child node is partially
-   clipped by the border.*/
-static const int OC_SEG_BORDER_XMASKS[4]={0x4,0x1,0x4,0x1};
-/*If the bit in these masks is set, the height of the child node is partially
-   clipped by the border.*/
-static const int OC_SEG_BORDER_YMASKS[4]={0x8,0x8,0x2,0x2};
-/*If any of the bits in these masks are set, either the width or height of the
-   child node is partially clipped by the border.*/
-static const int OC_SEG_BORDER_MASKS[4]={0xC,0x9,0x6,0x3};
-
-
-
-/*Computes moments for an image row, saving samples every
-   OC_SEG_MOMENT_RES pixels.
-  These moments are added to the previous row value.
-  _xrow:       The storage for the first moments.
-  _x2row:      The storage for the second moments.
-  _xrow_prev:  The previous first moments for the row.
-  _x2row_prev: The previous second moments for the row.
-  _irow:       The image row to accumulate.
-  _width:      The width of the row in pixels.*/
-static void oc_seg_sum_moment_row(float *_xrow,float *_x2row,
- const float *_xrow_prev,const float *_x2row_prev,
- const unsigned char *_irow,int _width){
-  float xsum;
-  float x2sum;
-  int   xmax;
-  int   x;
-  int i;
-  xmax=_width>>OC_SEG_MOMENT_RES_LOG;
-  xsum=x2sum=0;
-  for(x=1;x<=xmax;x++){
-    for(i=0;i<OC_SEG_MOMENT_RES;i++){
-      xsum+=*_irow;
-      x2sum+=*_irow**_irow;
-      _irow++;
-    }
-    _xrow[x]=xsum+_xrow_prev[x];
-    _x2row[x]=x2sum+_x2row_prev[x];
-  }
-  i=_width&OC_SEG_MOMENT_RES_MASK;
-  if(i>0){
-    do{
-      xsum+=*_irow;
-      x2sum+=*_irow**_irow;
-      _irow++;
-    }
-    while(--i>0);
-    _xrow[x]=xsum+_xrow_prev[x];
-    _x2row[x]=x2sum+_x2row_prev[x];
-  }
-}
-
-/*Sum up 2-dimensional moments over the whole image.
-  These are used for fast variance calculations over rectangular
-   regions of the image during the split phase.
-  The value at each position is the moment summed over the image
-   region above and to the left.
-  _seg:    The image segmentation context.
-  _iplane: The image plane to sum the moments over.
-           This should already be adjusted to cover only the visible
-            frame, and not the full encoded frame.*/
-static void oc_seg_sum_moments(oc_seg_ctx *_seg,
- const th_img_plane *_iplane){
-  const unsigned char *ypix;
-  int                  ymax;
-  int                  y;
-  int                  i;
-  ypix=_iplane->data;
-  ymax=_iplane->height>>OC_SEG_MOMENT_RES_LOG;
-  for(y=1;y<=ymax;y++){
-    oc_seg_sum_moment_row(_seg->sumx[y],_seg->sumx2[y],
-     _seg->sumx[y-1],_seg->sumx2[y-1],ypix,_iplane->width);
-    ypix+=_iplane->ystride;
-    for(i=1;i<OC_SEG_MOMENT_RES;i++){
-      oc_seg_sum_moment_row(_seg->sumx[y],_seg->sumx2[y],
-       _seg->sumx[y],_seg->sumx2[y],ypix,_iplane->width);
-      ypix+=_iplane->ystride;
-    }
-  }
-  i=_iplane->height&OC_SEG_MOMENT_RES_MASK;
-  if(i>0){
-    oc_seg_sum_moment_row(_seg->sumx[y],_seg->sumx2[y],
-     _seg->sumx[y-1],_seg->sumx2[y-1],ypix,_iplane->width);
-    ypix+=_iplane->ystride;
-    while(--i>0){
-      oc_seg_sum_moment_row(_seg->sumx[y],_seg->sumx2[y],
-       _seg->sumx[y],_seg->sumx2[y],ypix,_iplane->width);
-      ypix+=_iplane->ystride;
-    }
-  }
-}
-
-/*Computes the sum over the given region using the given moment
-   table.
-  Note that coordinates are those of the table, not of the image from which
-   the moments were computed.
-  _sums:    The pre-computed moment table.
-  _tx:      The X coordinate in the table of the upper-left hand corner of the
-             region.
-  _ty:      The Y coordinate in the table of the upper-right hand corner of
-             the region.
-  _twidth:  The width of the region in the table.
-  _theight: The height of the region in the table.
-  Return: The sum of the appropriate value over the given region.*/
-static float oc_seg_sum_region(const float **_sums,int _tx,int _ty,
- int _twidth,int _theight){
-  return _sums[_ty][_tx]-_sums[_ty][_tx+_twidth]-
-   _sums[_ty+_theight][_tx]+_sums[_ty+_theight][_tx+_twidth];
-}
-
-/*Gets the region number for a given pixel label.
-  When a region is merged with another, its label becomes the other region
-   number (but not vice versa: the other region keeps its label as its own
-   region number).
-  However, if that other region should then merge later on, its label could
-   change.
-  Thus we must follow the labels until we find a region whose label is its
-   own region number.
-
-  This is the classic set membership problem, which can be very efficiently
-   solved by updating the region label each time a query is made to be the
-   most recent final answer.
-  This gives an amortized number of updates per query equal to the inverse
-   Ackerman's function: i.e., 4 or less for up to 4 billion regions, or very
-   nearly constant.
-
-  _seg:   The segmentation context.
-  _label: The pixel label to retrieve the region number for.
-  Return: The region number corresponding to the given label.*/
-static int oc_seg_get_label(oc_seg_ctx *_seg,int _label){
-  oc_seg_region *reg;
-  reg=_seg->regions+_label;
-  if(reg->link.regi!=_label){
-    return reg->link.regi=oc_seg_get_label(_seg,reg->link.regi);
-  }
-  return _label;
-}
-
-/*Returns an unused region pair structure.
-  _seg: The segmentation context.
-  Return: An unused region pair structure.*/
-static oc_seg_pair *oc_seg_pair_alloc(oc_seg_ctx *_seg){
-  oc_seg_pair *ret;
-  /*If there's any on the free_pairs list, use those.*/
-  if(_seg->free_pairs!=NULL){
-    ret=_seg->free_pairs->pair;
-    _seg->free_pairs=_seg->free_pairs->next;
-  }
-  /*Otherwise, pull one from the pre-allocated buffer of them.
-    It would simplify the code slightly to put these all on the free list when
-     we initially allocate them, but since we allocate a conservatively large
-     number, most of the time we won't need nearly that many.
-    Never touching the RAM means the pages won't ever actually be allocated by
-     some modern OSes.*/
-  else ret=_seg->pairs+_seg->npairs++;
-  return ret;
-}
-
-/*Free a region pair structure that is no longer in use.
-  _seg:  The segmentation context.
-  _pair: The pair to free.
-         This cannot be NULL.*/
-static void oc_seg_pair_free(oc_seg_ctx *_seg,oc_seg_pair *_pair){
-  _pair->links[0].next=_seg->free_pairs;
-  _seg->free_pairs=_pair->links+0;
-}
-
-/*Move the pair at the given index up in the pair heap as far as necessary.
-  This should be called when a pair's dbic value decreases to maintain the
-   heap invariants.
-  _seg:   The segmentation context.
-  _heapi: The index of the pair to try moving up.*/
-static void oc_seg_pair_heap_up(oc_seg_ctx *_seg,int _heapi){
-  oc_seg_pair **heap;
-  int           p;
-  p=_heapi;
-  heap=_seg->heap;
-  while(p>0){
-    oc_seg_pair *t;
-    int          q;
-    q=p;
-    p=(q+1>>1)-1;
-    if(heap[p]->dbic<=heap[q]->dbic)break;
-    heap[p]->heapi=q;
-    heap[q]->heapi=p;
-    t=heap[p];
-    heap[p]=heap[q];
-    heap[q]=t;
-  }
-}
-
-/*Move the pair at the given index down in the pair heap as far as necessary.
-  This should be called when a pair's dbic value increases to maintain the
-   heap invariants.
-  _seg:   The segmentation context.
-  _heapi: The index of the pair to try moving up.*/
-static void oc_seg_pair_heap_down(oc_seg_ctx *_seg,int _heapi){
-  oc_seg_pair **heap;
-  int           l;
-  int           r;
-  int           p;
-  heap=_seg->heap;
-  l=_seg->nheap>>1;
-  r=_seg->nheap-1;
-  p=_heapi;
-  while(p<l){
-    oc_seg_pair *t;
-    int          q;
-    q=(p<<1)+1;
-    if(q<r&&heap[q]->dbic>=heap[q+1]->dbic)q++;
-    if(heap[p]->dbic<=heap[q]->dbic)break;
-    heap[p]->heapi=q;
-    heap[q]->heapi=p;
-    t=heap[p];
-    heap[p]=heap[q];
-    heap[q]=t;
-    p=q;
-  }
-}
-
-/*Takes an unordered list of pairs in the heap array and arranages them into a
-   proper heap.
-  _seg: The segmentation context.*/
-static void oc_seg_pair_heapify(oc_seg_ctx *_seg){
-  oc_seg_pair **heap;
-  int           l;
-  int           r;
-  int           i;
-  heap=_seg->heap;
-  l=_seg->nheap>>1;
-  r=_seg->nheap-1;
-  for(i=l;i-->0;){
-    int p;
-    p=i;
-    do{
-      oc_seg_pair *t;
-      int          q;
-      q=(p<<1)+1;
-      if(q<r&&heap[q]->dbic>=heap[q+1]->dbic)q++;
-      if(heap[p]->dbic<=heap[q]->dbic)break;
-      heap[p]->heapi=q;
-      heap[q]->heapi=p;
-      t=heap[p];
-      heap[p]=heap[q];
-      heap[q]=t;
-      p=q;
-    }
-    while(p<l);
-  }
-}
-
-/*Adds a pair to the pair heap.
-  _seg:  The segmentation context.
-  _pair: The pair to add.*/
-static void oc_seg_pair_heap_add(oc_seg_ctx *_seg,oc_seg_pair *_pair){
-  _seg->heap[_seg->nheap]=_pair;
-  _pair->heapi=_seg->nheap++;
-  oc_seg_pair_heap_up(_seg,_pair->heapi);
-}
-
-/*Removes the head of the pair heap and returns it.
-  This does NOT reset the pair's heapi to -1.
-  The heap MUST not be empty when this is called.
-  _seg: The segmentation context.
-  Return: The pair that was at the top of the heap.*/
-static oc_seg_pair *oc_seg_pair_heap_delhead(oc_seg_ctx *_seg){
-  oc_seg_pair *ret;
-  ret=_seg->heap[0];
-  if(--_seg->nheap>0){
-    _seg->heap[0]=_seg->heap[_seg->nheap];
-    _seg->heap[0]->heapi=0;
-    oc_seg_pair_heap_down(_seg,0);
-  }
-  return ret;
-}
-
-/*Removes a pair from its position in the heap, wherever it is.
-  If the pair is not in the heap, this does nothing.
-  This does NOT reset the pair's heap to -1.
-  _seg:  The segmentation context.
-  _pair: The pair to remove from the heap.*/
-static void oc_seg_pair_heap_del(oc_seg_ctx *_seg,oc_seg_pair *_pair){
-  int heapi;
-  heapi=_pair->heapi;
-  if(heapi>=0){
-    _seg->nheap--;
-    if(_seg->nheap>heapi){
-      _seg->heap[heapi]=_seg->heap[_seg->nheap];
-      _seg->heap[heapi]->heapi=heapi;
-      if(_seg->heap[heapi]->dbic<_pair->dbic)oc_seg_pair_heap_up(_seg,heapi);
-      else oc_seg_pair_heap_down(_seg,heapi);
-    }
-  }
-}
-
-/*Adds, removes, or moves a pair in the pair heap after its dbic has changed.
-  This is the version of this function that does not force small regions to
-   keep their pairs in the heap.
-  _seg:      The segmentation context.
-  _pair:     The pair that was updated.
-  _old_dbic: The delta BIC value the pair used to have.
-             This is only used if the pair was in the heap previously and is
-              still in the heap to decide which direction to try to move it.*/
-static void oc_seg_pair_reheap(oc_seg_ctx *_seg,oc_seg_pair *_pair,
- float _old_dbic){
-  /*Place this pair on the merge heap if necessary.*/
-  if(_pair->dbic<=0){
-    if(_pair->heapi<0)oc_seg_pair_heap_add(_seg,_pair);
-    else if(_old_dbic<_pair->dbic)oc_seg_pair_heap_down(_seg,_pair->heapi);
-    else oc_seg_pair_heap_up(_seg,_pair->heapi);
-  }
-  else if(_pair->heapi>=0){
-    oc_seg_pair_heap_del(_seg,_pair);
-    _pair->heapi=-1;
-  }
-}
-
-/*Adds, removes, or moves a pair in the pair heap after its dbic has changed.
-  This is the version of this function that forces small regions to keep their
-   pairs in the heap.
-  _seg:      The segmentation context.
-  _pair:     The pair that was updated.
-  _old_dbic: The delta BIC value the pair used to have.
-             This is only used if the pair was in the heap previously and is
-              still in the heap to decide which direction to try to move it.*/
-static void oc_seg_pair_reheap_small(oc_seg_ctx *_seg,oc_seg_pair *_pair,
- float _old_dbic){
-  /*Place this pair on the merge heap if necessary.*/
-  if(_pair->dbic<=0||
-   (_seg->regions+_pair->links[0].regi)->npixels<OC_SEG_REGION_SZ_MIN||
-   (_seg->regions+_pair->links[1].regi)->npixels<OC_SEG_REGION_SZ_MIN){
-    if(_pair->heapi<0)oc_seg_pair_heap_add(_seg,_pair);
-    else if(_old_dbic<_pair->dbic)oc_seg_pair_heap_down(_seg,_pair->heapi);
-    else oc_seg_pair_heap_up(_seg,_pair->heapi);
-  }
-  else if(_pair->heapi>=0){
-    oc_seg_pair_heap_del(_seg,_pair);
-    _pair->heapi=-1;
-  }
-}
-
-/*Updates a pair's npixels, sumx, sumx2, bic and dbic fields, and its position
-   in the heap.
-  This is used after a pair is first created, and whenever one of its
-   constituent regions merges with another region.
-  _seg:  The segmentation context.
-  _pair: The pair to update.*/
-static float oc_seg_pair_update(oc_seg_ctx *_seg,oc_seg_pair *_pair){
-  oc_seg_region *reg0;
-  oc_seg_region *reg1;
-  float          area;
-  float          var;
-  float          old_dbic;
-  /*Compute the statistics of the merged region.*/
-  reg0=_seg->regions+_pair->links[0].regi;
-  reg1=_seg->regions+_pair->links[1].regi;
-  _pair->npixels=reg0->npixels+reg1->npixels;
-  _pair->sumx=reg0->sumx+reg1->sumx;
-  _pair->sumx2=reg0->sumx2+reg1->sumx2;
-  area=(float)_pair->npixels;
-  var=(_pair->sumx2*area-_pair->sumx*_pair->sumx)/(area*area);
-  _pair->bic=var>0?area*OC_LOGF(var):0;
-  old_dbic=_pair->dbic;
-  _pair->dbic=_pair->bic-reg0->bic-reg1->bic-
-   OC_SEG_MODEL_MERGE_WEIGHT*OC_LOGF(area);
-  return old_dbic;
-}
-
-/*Updates a pair's npixels, sumx, sumx2, bic and dbic fields, and its position
-   in the heap.
-  This is used after a pair is first created, and whenever one of its
-   constituent regions merges with another region.
-  _seg:  The segmentation context.
-  _pair: The pair to update.*/
-static void oc_seg_pair_update_reheap(oc_seg_ctx *_seg,oc_seg_pair *_pair){
-  _seg->reheap(_seg,_pair,oc_seg_pair_update(_seg,_pair));
-}
-
-
-/*Creates a new pair between two regions if one does not already exist.
-  The pair is never added to the merge heap.
-  _seg:   The segmentation context.
-  _regi0: The region number of the first region.
-          If this pair is eventually merged, this will be the label of the
-           merged region.
-  _regi1: The region number of the second region.
-          For efficiency purposes, one desires this to have the smaller
-           number of neighbors.*/
-static oc_seg_pair *oc_seg_create_pair(oc_seg_ctx *_seg,int _regi0,
- int _regi1){
-  oc_seg_region *reg0;
-  oc_seg_region *reg1;
-  oc_seg_link   *link;
-  oc_seg_pair   *pair;
-  /*Search the second region's neighbor list for the first region.*/
-  reg1=_seg->regions+_regi1;
-  /*Quick rejection: it's at the head of the list.*/
-  if(reg1->link.next->regi==_regi0)return NULL;
-  /*Otherwise start searching from the second element of the list.*/
-  for(link=reg1->link.next->next;link->pair!=NULL;link=link->next){
-    if(link->regi==_regi0){
-      /*We found it.
-        Now move this link to the head of the list, so that if the next pixel
-         also comes from the same region (highly likely), we can do a fast
-         rejection.*/
-      link->prev->next=link->next;
-      link->next->prev=link->prev;
-      link->next=reg1->link.next;
-      link->prev=&reg1->link;
-      link->next->prev=link;
-      reg1->link.next=link;
-      return NULL;
-    }
-  }
-  /*Add a new pair to the regions' lists.*/
-  reg0=_seg->regions+_regi0;
-  pair=oc_seg_pair_alloc(_seg);
-  pair->links[0].regi=_regi0;
-  pair->links[0].pair=pair;
-  pair->links[0].next=reg1->link.next;
-  pair->links[0].prev=&reg1->link;
-  reg1->link.next->prev=pair->links+0;
-  reg1->link.next=pair->links+0;
-  pair->links[1].regi=_regi1;
-  pair->links[1].pair=pair;
-  pair->links[1].next=reg0->link.next;
-  pair->links[1].prev=&reg0->link;
-  reg0->link.next->prev=pair->links+1;
-  reg0->link.next=pair->links+1;
-  pair->heapi=-1;
-  pair->dbic=0;
-  return pair;
-}
-
-/*Creates a new pair between two regions if one does not already exist.
-  If possible, the pair is added to the merge heap.
-  _seg:   The segmentation context.
-  _regi0: The region number of the first region.
-          If this pair is eventually merged, this will be the label of the
-           merged region.
-  _regi1: The region number of the second region.
-          For efficiency purposes, one desires this to have the smaller
-           number of neighbors.*/
-static void oc_seg_create_pair_reheap(oc_seg_ctx *_seg,int _regi0,int _regi1){
-  oc_seg_pair *pair;
-  pair=oc_seg_create_pair(_seg,_regi0,_regi1);
-  /*Check to see if these regions can potentially be merged.*/
-  if(pair!=NULL)oc_seg_pair_update_reheap(_seg,pair);
-}
-
-/*Merges the list of pairs in region _srci into the list in region _dsti,
-   relabling _srci to _dsti.
-  _srci's list is destructively modified, and should not be referenced any
-   further.
-  The (_dsti,_srci) pair should already be removed from both lists before
-   calling this function.
-  _seg:  The segmentation context.
-  _dsti: The destination region number.
-  _srci: The source region number.*/
-static void oc_seg_merge_pair_lists(oc_seg_ctx *_seg,int _dsti,int _srci){
-  oc_seg_region  *dst;
-  oc_seg_region  *src;
-  oc_seg_link    *dlink;
-  oc_seg_link    *dhead;
-  oc_seg_link    *slink;
-  oc_seg_link    *slink2;
-  oc_seg_link    *snext;
-  dst=_seg->regions+_dsti;
-  src=_seg->regions+_srci;
-  dhead=dst->link.next;
-  for(slink=src->link.next;slink->pair!=NULL;slink=snext){
-    snext=slink->next;
-    /*Grab a pointer to the other link in the pair.*/
-    slink2=slink->pair->links+(slink->pair->links+1-slink);
-    for(dlink=dhead;;dlink=dlink->next){
-      /*If we've reached the end of the list, then the pair was not found in
-         dst, so add it.*/
-      if(dlink->pair==NULL){
-        slink->next=dst->link.next;
-        slink->prev=&dst->link;
-        dst->link.next->prev=slink;
-        dst->link.next=slink;
-        /*Change the region index of the other link.*/
-        slink2->regi=_dsti;
-        break;
-      }
-      /*If we found a duplicate pair, move the duplicate off the part of the
-         list we're scanning, and delete the original from the other list it
-         is in.*/
-      else if(dlink->regi==slink->regi){
-        if(dlink==dhead)dhead=dlink->next;
-        else{
-          dlink->next->prev=dlink->prev;
-          dlink->prev->next=dlink->next;
-          dlink->next=dst->link.next;
-          dlink->prev=&dst->link;
-          dst->link.next->prev=dlink;
-          dst->link.next=dlink;
-        }
-        slink2->next->prev=slink2->prev;
-        slink2->prev->next=slink2->next;
-        /*And remove the pair from the merge heap if necessary.*/
-        oc_seg_pair_heap_del(_seg,slink->pair);
-        /*And finally free it.*/
-        oc_seg_pair_free(_seg,slink->pair);
-        break;
-      }
-    }
-  }
-}
-
-/*Performs pending merges until the pair heap is empty.
-  _seg: The segmentation context.*/
-static void oc_seg_merge(oc_seg_ctx *_seg){
-  /*While the heap is non-empty...*/
-  while(_seg->nheap>0){
-    oc_seg_pair   *pair;
-    oc_seg_link   *link;
-    oc_seg_region *reg[2];
-    int            regi[2];
-    int            dst;
-    /*Take the head off the heap.*/
-    pair=oc_seg_pair_heap_delhead(_seg);
-    /*Remove this pair from each region's neighbor list, since we're about to
-       merge the two.*/
-    pair->links[0].next->prev=pair->links[0].prev;
-    pair->links[0].prev->next=pair->links[0].next;
-    pair->links[1].next->prev=pair->links[1].prev;
-    pair->links[1].prev->next=pair->links[1].next;
-    regi[0]=pair->links[0].regi;
-    regi[1]=pair->links[1].regi;
-    /*We want to be sure we always prefer any global region label over a local
-       one, but otherwise we use the inherent order of the pair, which is
-       usually a good one.*/
-    dst=regi[0]<0&&0<=regi[1];
-    /*Merge the two neighbor lists.*/
-    oc_seg_merge_pair_lists(_seg,regi[dst],regi[1-dst]);
-    reg[0]=_seg->regions+regi[dst];
-    reg[1]=_seg->regions+regi[1-dst];
-    /*Fill the new region with statistics from the merge.*/
-    reg[0]->npixels=pair->npixels;
-    reg[0]->sumx=pair->sumx;
-    reg[0]->sumx2=pair->sumx2;
-    reg[0]->bic=pair->bic;
-    reg[1]->link.regi=regi[dst];
-    /*Finally free the pair.*/
-    oc_seg_pair_free(_seg,pair);
-    /*Now update all the pairs that involve the new merged region.*/
-    for(link=reg[0]->link.next;link->pair!=NULL;link=link->next){
-      oc_seg_pair_update_reheap(_seg,link->pair);
-    }
-  }
-}
-
-/*Attempts to merge a block that can't be split anymore with existing,
-   neighboring local regions.
-  If a successful candidate cannot be found, a new local region is created.
-  _seg:    The segmentation context.
-  _x0:     The X coordinate of the upper-left hand corner of the local block.
-  _y0:     The Y coordinate of the upper-left hand corner of the local block.
-  _dx:     The X offset of the local region in the local block.
-  _dy:     The Y offset of the local region in the lcoal block.
-  _width:  The width of the local region.
-  _height: The height of the local region.
-  _area:   The area of the local region.
-  _sumx:   The sum of the pixel values over the local region.
-  _sumx2   The sum of the squared pixel values over the local region.
-  _bic:    The BIC of the local region.*/
-static void oc_seg_merge_l(oc_seg_ctx *_seg,int _x0,int _y0,int _dx,int _dy,
- int _width,int _height,int _area,float _sumx,float _sumx2,float _bic){
-  oc_seg_region *reg;
-  int            regi;
-  int            xend;
-  int            yend;
-  int            x;
-  int            y;
-  _x0+=_dx;
-  _y0+=_dy;
-  xend=_x0+_width;
-  yend=_y0+_height;
-  /*Set up the region structure.*/
-  regi=_seg->nlocal_regions--;
-  reg=_seg->regions+regi;
-  reg->link.regi=regi;
-  reg->link.pair=NULL;
-  reg->link.next=&reg->link;
-  reg->link.prev=&reg->link;
-  reg->npixels=_area;
-  reg->sumx=_sumx;
-  reg->sumx2=_sumx2;
-  reg->bic=_bic;
-  /*Scan the left edge, if present, for adjacent regions.*/
-  if(_dx>0)for(y=_y0;y<yend;y++){
-    oc_seg_create_pair_reheap(_seg,
-     oc_seg_get_label(_seg,_seg->labels[y][_x0-1]),regi);
-  }
-  /*Scan the top edge, if present, for adjacent regions.*/
-  if(_dy>0)for(x=_x0;x<xend;x++){
-    oc_seg_create_pair_reheap(_seg,
-     oc_seg_get_label(_seg,_seg->labels[_y0-1][x]),regi);
-  }
-  /*Merge all mergeable regions.*/
-  oc_seg_merge(_seg);
-  /*If we merged away the region we just created, set it up for re-use.*/
-  if(reg->link.regi!=regi){
-    _seg->nlocal_regions++;
-    regi=oc_seg_get_label(_seg,regi);
-  }
-  /*Fill the block with the new region label.*/
-  for(y=_y0;y<yend;y++)for(x=_x0;x<xend;x++)_seg->labels[y][x]=regi;
-}
-
-/*Attempts to merge the local regions with neighboring global regions.
-  If a successful candidate cannot be found, and the local region is too
-   small, it is merged with its largest neighbor, local or not.
-  Otherwise, a new region is created.
-  _seg:    The segmentation context.
-  _x0:     The X coordinate of the upper-left hand corner of the local block.
-  _y0:     The Y coordinate of the upper-left hand corner of the local block.
-  _width:  The width of the block.
-  _height: The height of the block.*/
-static void oc_seg_merge_s(oc_seg_ctx *_seg,int _x0,int _y0,int _width,
- int _height){
-  oc_seg_region *reg;
-  oc_seg_region *lreg;
-  oc_seg_link   *link;
-  oc_seg_pair   *pair;
-  int            regi;
-  int            lregi;
-  int            xend;
-  int            yend;
-  int            x;
-  int            y;
-  /*Step 1: Add all the small region pairs to the heap.*/
-  for(lregi=-1;--lregi>_seg->nlocal_regions;){
-    lreg=_seg->regions+lregi;
-    /*If this region was not already merged with another and is small...*/
-    if(lreg->link.regi==lregi&&lreg->npixels<OC_SEG_REGION_SZ_MIN){
-      /*Add its pairs to the merge heap, regardless of whether or not they're
-         beneficial.
-        Don't worry about heap structure for now.*/
-      for(link=lreg->link.next;link->pair!=NULL;link=link->next){
-        pair=link->pair;
-        if(pair->heapi<0){
-          pair->heapi=_seg->nheap++;
-          _seg->heap[pair->heapi]=pair;
-        }
-      }
-    }
-  }
-  /*Make a heap out of all the pairs all at once.*/
-  oc_seg_pair_heapify(_seg);
-  /*Step 2: Merge all the small regions.*/
-  _seg->reheap=oc_seg_pair_reheap_small;
-  oc_seg_merge(_seg);
-  _seg->reheap=oc_seg_pair_reheap;
-  /*Step 3: Allocate global regions for each local region that survived.*/
-  for(lregi=-1;--lregi>_seg->nlocal_regions;){
-    lreg=_seg->regions+lregi;
-    /*If this region was not already merged with another...*/
-    if(lreg->link.regi==lregi){
-      /*Create a new global region out of it.*/
-      regi=_seg->nregions++;
-      reg=_seg->regions+regi;
-      *&reg->link=*&lreg->link;
-      reg->link.regi=regi;
-      reg->link.next->prev=&reg->link;
-      reg->link.prev->next=&reg->link;
-      reg->npixels=lreg->npixels;
-      reg->sumx=lreg->sumx;
-      reg->sumx2=lreg->sumx2;
-      reg->bic=lreg->bic;
-      lreg->link.regi=regi;
-      /*Relabel the region in all of its merge pairs.*/
-      for(link=reg->link.next;link->pair!=NULL;link=link->next){
-        pair=link->pair;
-        pair->links[(pair->links+1-link)].regi=regi;
-      }
-    }
-  }
-  /*Step 4: Update all pixel labels to refer to the global region labels.*/
-  for(lregi=-1;--lregi>_seg->nlocal_regions;)oc_seg_get_label(_seg,lregi);
-  xend=_x0+_width;
-  yend=_y0+_height;
-  for(y=_y0;y<yend;y++)for(x=_x0;x<xend;x++){
-    _seg->labels[y][x]=(_seg->regions+_seg->labels[y][x])->link.regi;
-  }
-  /*Step 5: Create pairs with other global regions.*/
-  /*Scan the left edge, if present, for adjacent regions.*/
-  if(_x0>0)for(y=_y0;y<yend;y++){
-    oc_seg_create_pair(_seg,_seg->labels[y][_x0-1],_seg->labels[y][_x0]);
-  }
-  /*Scan the top edge, if present, for adjacent regions.*/
-  if(_y0>0)for(x=_x0;x<xend;x++){
-    oc_seg_create_pair(_seg,_seg->labels[_y0-1][x],_seg->labels[_y0][x]);
-  }
-}
-
-/*Attempts to merge a block that can't be split anymore with existing,
-   neighboring regions.
-  If a successful candidate cannot be found, a new global region is created.
-  _seg:    The segmentation context.
-  _x0:     The X coordinate of the upper-left hand corner of the block.
-  _y0:     The Y coordinate of the upper-left hand corner of the block.
-  _width:  The width of the block.
-  _height: The height of the block.
-  _area:   The area of the block.
-  _sumx:   The sum of the pixel values over the block.
-  _sumx2   The sum of the squared pixel values over the block.
-  _bic:    The BIC of the block.*/
-static void oc_seg_merge_t(oc_seg_ctx *_seg,int _x0,int _y0,int _width,
- int _height,int _area,float _sumx,float _sumx2,float _bic){
-  oc_seg_region *reg;
-  int            regi;
-  int            xend;
-  int            yend;
-  int            x;
-  int            y;
-  xend=_x0+_width;
-  yend=_y0+_height;
-  /*Set up the region structure.*/
-  regi=_seg->nregions++;
-  reg=_seg->regions+regi;
-  reg->link.regi=regi;
-  reg->link.pair=NULL;
-  reg->link.next=&reg->link;
-  reg->link.prev=&reg->link;
-  reg->npixels=_area;
-  reg->sumx=_sumx;
-  reg->sumx2=_sumx2;
-  reg->bic=_bic;
-  /*Scan the left edge, if present, for adjacent regions.*/
-  if(_x0>0)for(y=_y0;y<yend;y++){
-    oc_seg_create_pair(_seg,
-     oc_seg_get_label(_seg,_seg->labels[y][_x0-1]),regi);
-  }
-  /*Scan the top edge, if present, for adjacent regions.*/
-  if(_y0>0)for(x=_x0;x<xend;x++){
-    oc_seg_create_pair(_seg,
-     oc_seg_get_label(_seg,_seg->labels[_y0-1][x]),regi);
-  }
-#if 0
-  /*Merge all mergeable regions.*/
-  oc_seg_merge(_seg);
-  /*If we merged away the region we just created, set it up for re-use.*/
-  if(reg->link.regi!=regi){
-    _seg->nregions--;
-    regi=oc_seg_get_label(_seg,regi);
-  }
-#endif
-  /*Fill the block with the new region label.*/
-  for(y=_y0;y<yend;y++)for(x=_x0;x<xend;x++)_seg->labels[y][x]=regi;
-}
-
-/*Recursive split-merge step.
-  Version for interior regions with local table lookups.
-  _seg:    The segmentation context.
-  _x0:     The X coordinate of the upper-left hand corner of the local region.
-  _y0:     The Y coordinate of the upper-left hand corner of the local region.
-  _dx:     The X coordinate of the upper-left hand corner of the block
-            relative to the local region.
-  _dy:     The Y coordinate of the upper-left hand corner of the block
-            relative to the local region.
-  _level:  The log base 2 of the block size.
-  _area:   The area of the block in pixels^2.
-  _sumx:   The sum of the pixel values over the block.
-  _sumx2:  The sum of the pixel values squared over the block.
-  _bic:    The BIC of the block.*/
-static void oc_seg_splitmerge_il(oc_seg_ctx *_seg,int _x0,int _y0,
- int _dx,int _dy,int _level,int _area,float _sumx,float _sumx2,float _bic){
-  int size;
-  if(_level>0){
-    float sumx[4];
-    float sumx2[4];
-    float bic[4];
-    float dbic;
-    int   dx[4];
-    int   dy[4];
-    int   area;
-    int   size_2;
-    int   i;
-    _level--;
-    area=1<<(_level<<1);
-    size_2=1<<_level;
-    dx[0]=dx[2]=dy[0]=dy[1]=0;
-    dx[1]=dx[3]=dy[2]=dy[3]=size_2;
-    dbic=_bic;
-    for(i=0;i<4;i++){
-      float var;
-      sumx[i]=oc_seg_sum_region(_seg->local_sumx,_dx+dx[i],_dy+dy[i],
-       size_2,size_2);
-      sumx2[i]=oc_seg_sum_region(_seg->local_sumx2,_dx+dx[i],_dy+dy[i],
-       size_2,size_2);
-      var=(sumx2[i]*area-sumx[i]*sumx[i])/(area*area);
-      bic[i]=var>0?area*OC_LOGF(var):0;
-      dbic-=bic[i];
-    }
-    dbic-=3*OC_SEG_MODEL_SPLIT_WEIGHT*OC_LOGF(_area);
-    if(dbic>=0){
-      for(i=0;i<4;i++){
-        oc_seg_splitmerge_il(_seg,_x0,_y0,_dx+dx[i],_dy+dy[i],_level,area,
-         sumx[i],sumx2[i],bic[i]);
-      }
-      return;
-    }
-    _level++;
-  }
-  size=1<<_level;
-  oc_seg_merge_l(_seg,_x0,_y0,_dx,_dy,size,size,_area,_sumx,_sumx2,_bic);
-}
-
-/*Recursive split-merge step.
-  Version for border regions with local table lookups.
-  _seg:    The segmentation context.
-  _x0:     The X coordinate of the upper-left hand corner of the local region.
-  _y0:     The Y coordinate of the upper-left hand corner of the local region.
-  _dx:     The X coordinate of the upper-left hand corner of the block
-            relative to the local region.
-  _dy:     The Y coordinate of the upper-left hand corner of the block
-            relative to the local region.
-  _width:  The width of the block in pixels.
-  _height: The height of the block in pixels.
-  _level:  The log base 2 of the block size.
-  _area:   The area of the block in pixels^2.
-  _sumx:   The sum of the pixel values over the block.
-  _sumx2:  The sum of the pixel values squared over the block.
-  _bic:    The BIC of the block.*/
-static void oc_seg_splitmerge_bl(oc_seg_ctx *_seg,
- int _x0,int _y0,int _dx,int _dy,int _width,int _height,int _level,
- int _area,float _sumx,float _sumx2,float _bic){
-  int size;
-  size=1<<_level;
-  if(_level>0){
-    float sumx[4];
-    float sumx2[4];
-    float bic[4];
-    float dbic;
-    float model_cost;
-    int   dx[4];
-    int   dy[4];
-    int   area[4];
-    int   width[4];
-    int   height[4];
-    int   size_2;
-    int   b;
-    int   i;
-    _level--;
-    size_2=1<<_level;
-    dx[0]=dx[2]=dy[0]=dy[1]=0;
-    dx[1]=dx[3]=dy[2]=dy[3]=size_2;
-    b=(size>_width)|((size>_height)<<1)|
-     ((size_2>_width)<<2)|((size_2>_height)<<3)|
-     ((size_2==_width)<<4)|((size_2==_height)<<5);
-    model_cost=OC_SEG_MODEL_SPLIT_WEIGHT*OC_LOGF(_area);
-    dbic=_bic+model_cost;
-    for(i=0;i<4;i++)if(!(b&OC_SEG_CLIP_MASKS[i])){
-      float var;
-      width[i]=(b&OC_SEG_BORDER_XMASKS[i])?_width-dx[i]:size_2;
-      height[i]=(b&OC_SEG_BORDER_YMASKS[i])?_height-dy[i]:size_2;
-      area[i]=width[i]*height[i];
-      sumx[i]=oc_seg_sum_region(_seg->local_sumx,_dx+dx[i],_dy+dy[i],
-       width[i],height[i]);
-      sumx2[i]=oc_seg_sum_region(_seg->local_sumx2,_dx+dx[i],_dy+dy[i],
-       width[i],height[i]);
-      var=(sumx2[i]*area[i]-sumx[i]*sumx[i])/(area[i]*area[i]);
-      bic[i]=var>0?area[i]*OC_LOGF(var):0;
-      dbic-=bic[i]+model_cost;
-    }
-    if(dbic>=0){
-      for(i=0;i<4;i++)if(!(b&OC_SEG_CLIP_MASKS[i])){
-        if(b&OC_SEG_BORDER_MASKS[i]){
-          oc_seg_splitmerge_bl(_seg,_x0,_y0,_dx+dx[i],_dy+dy[i],
-           width[i],height[i],_level,area[i],sumx[i],sumx2[i],bic[i]);
-        }
-        else{
-          oc_seg_splitmerge_il(_seg,_x0,_y0,_dx+dx[i],_dy+dy[i],
-           _level,area[i],sumx[i],sumx2[i],bic[i]);
-        }
-      }
-      return;
-    }
-  }
-  oc_seg_merge_l(_seg,_x0,_y0,_dx,_dy,_width,_height,_area,_sumx,_sumx2,_bic);
-}
-
-/*Recursive split-merge step.
-  Version for interior regions with manual summing.
-  _seg:    The segmentation context.
-  _x0:     The X coordinate of the upper-left hand corner of the block.
-  _y0:     The Y coordinate of the upper-left hand corner of the block.
-  _level:  The log base 2 of the block size.
-  _area:   The area of the block in pixels^2.
-  _sumx:   The sum of the pixel values over the block.
-  _sumx2:  The sum of the pixel values squared over the block.
-  _bic:    The BIC of the block.
-  _iplane: The image plane the block is contained in.*/
-static void oc_seg_splitmerge_is(oc_seg_ctx *_seg,
- int _x0,int _y0,int _level,int _area,float _sumx,float _sumx2,float _bic,
- const th_img_plane *_iplane){
-  const unsigned char *ypix;
-  int                  size;
-  int                  y;
-  int                  x;
-  size=1<<_level;
-  /*Compute a pixel-level moment table for this local region.*/
-  ypix=_iplane->data+_y0*_iplane->ystride+_x0;
-  for(y=1;y<=size;y++){
-    const unsigned char *xpix;
-    float                xsum;
-    float                x2sum;
-    xpix=ypix;
-    xsum=x2sum=0;
-    for(x=1;x<=size;x++){
-      xsum+=*xpix;
-      x2sum+=*xpix**xpix;
-      _seg->local_sumx[y][x]=_seg->local_sumx[y-1][x]+xsum;
-      _seg->local_sumx2[y][x]=_seg->local_sumx2[y-1][x]+x2sum;
-      xpix++;
-    }
-    ypix+=_iplane->ystride;
-  }
-  _seg->nlocal_regions=-2;
-  oc_seg_splitmerge_il(_seg,_x0,_y0,0,0,_level,_area,_sumx,_sumx2,_bic);
-  oc_seg_merge_s(_seg,_x0,_y0,size,size);
-}
-
-/*Recursive split-merge step.
-  Version for border regions with manual summing.
-  _seg:     The segmentation context.
-  _x0:      The X coordinate of the upper-left hand corner of the block.
-  _y0:      The Y coordinate of the upper-left hand corner of the block.
-  _width:   The width of the block in pixels.
-  _height:  The height of the block in pixels.
-  _level:   The log base 2 of the block size.
-  _area:    The area of the block in pixels^2.
-  _sumx:    The sum of the pixel values over the block.
-  _sumx2:   The sum of the pixel values squared over the block.
-  _bic:     The BIC of the block.
-  _iplane:  The image plane the block is contained in.*/
-static void oc_seg_splitmerge_bs(oc_seg_ctx *_seg,
- int _x0,int _y0,int _width,int _height,int _level,
- int _area,float _sumx,float _sumx2,float _bic,
- const th_img_plane *_iplane){
-  const unsigned char *ypix;
-  int                  size;
-  int                  y;
-  int                  x;
-  size=1<<_level;
-  /*Compute a pixel-level moment table for this local region.*/
-  ypix=_iplane->data+_y0*_iplane->ystride+_x0;
-  for(y=1;y<=_height;y++){
-    const unsigned char *xpix;
-    float                xsum;
-    float                x2sum;
-    xpix=ypix;
-    xsum=x2sum=0;
-    for(x=1;x<=_width;x++){
-      xsum+=*xpix;
-      x2sum+=*xpix**xpix;
-      _seg->local_sumx[y][x]=_seg->local_sumx[y-1][x]+xsum;
-      _seg->local_sumx2[y][x]=_seg->local_sumx2[y-1][x]+x2sum;
-      xpix++;
-    }
-    for(;x<=size;x++){
-      _seg->local_sumx[y][x]=_seg->local_sumx[y-1][x]+xsum;
-      _seg->local_sumx2[y][x]=_seg->local_sumx2[y-1][x]+x2sum;
-    }
-    ypix+=_iplane->ystride;
-  }
-  for(;y<=size;y++){
-    for(x=_width+1;x<=size;x++){
-      _seg->local_sumx[y][x]=_seg->local_sumx[y-1][x];
-      _seg->local_sumx2[y][x]=_seg->local_sumx2[y-1][x];
-    }
-  }
-  _seg->nlocal_regions=-2;
-  oc_seg_splitmerge_bl(_seg,_x0,_y0,0,0,_width,_height,_level,
-   _area,_sumx,_sumx2,_bic);
-  oc_seg_merge_s(_seg,_x0,_y0,_width,_height);
-}
-
-/*Recursive split-merge step.
-  Version for interior regions with reduced resolution table lookups.
-  _seg:     The segmentation context.
-  _x0:      The X coordinate of the upper-left hand corner of the block.
-  _y0:      The Y coordinate of the upper-left hand corner of the block.
-  _level:   The log base 2 of the block size.
-  _area:    The area of the block in pixels^2.
-  _sumx:    The sum of the pixel values over the block.
-  _sumx2:   The sum of the pixel values squared over the block.
-  _bic:     The BIC of the block.
-  _iplane:  The image plane the block is contained in.*/
-static void oc_seg_splitmerge_it(oc_seg_ctx *_seg,
- int _x0,int _y0,int _level,int _area,float _sumx,float _sumx2,float _bic,
- const th_img_plane *_iplane){
-  float sumx[4];
-  float sumx2[4];
-  float bic[4];
-  float dbic;
-  int   tdx[4];
-  int   tdy[4];
-  int   area;
-  int   tsize;
-  int   tx;
-  int   ty;
-  int   i;
-  _level--;
-  area=1<<(_level<<1);
-  tx=_x0>>OC_SEG_MOMENT_RES_LOG;
-  ty=_y0>>OC_SEG_MOMENT_RES_LOG;
-  tsize=1<<_level-OC_SEG_MOMENT_RES_LOG;
-  tdx[0]=tdx[2]=tdy[0]=tdy[1]=0;
-  tdx[1]=tdx[3]=tdy[2]=tdy[3]=tsize;
-  dbic=_bic;
-  for(i=0;i<4;i++){
-    float var;
-    sumx[i]=oc_seg_sum_region(_seg->sumx,tx+tdx[i],ty+tdy[i],tsize,tsize);
-    sumx2[i]=oc_seg_sum_region(_seg->sumx2,tx+tdx[i],ty+tdy[i],tsize,tsize);
-    var=(sumx2[i]-sumx[i]*sumx[i]/area)/area;
-    bic[i]=var>0?area*OC_LOGF(var):0;
-    dbic-=bic[i];
-  }
-  dbic-=3*OC_SEG_MODEL_SPLIT_WEIGHT*OC_LOGF(_area);
-  if(dbic>=0){
-    int dx[4];
-    int dy[4];
-    int size_2;
-    size_2=1<<_level;
-    dx[0]=dx[2]=dy[0]=dy[1]=0;
-    dx[1]=dx[3]=dy[2]=dy[3]=size_2;
-    if(_level>OC_SEG_MOMENT_RES_LOG)for(i=0;i<4;i++){
-      oc_seg_splitmerge_it(_seg,_x0+dx[i],_y0+dy[i],_level,area,
-       sumx[i],sumx2[i],bic[i],_iplane);
-    }
-    else for(i=0;i<4;i++){
-      oc_seg_splitmerge_is(_seg,_x0+dx[i],_y0+dy[i],_level,area,
-       sumx[i],sumx2[i],bic[i],_iplane);
-    }
-  }
-  else{
-    int size;
-    _level++;
-    size=1<<_level;
-    oc_seg_merge_t(_seg,_x0,_y0,size,size,_area,_sumx,_sumx2,_bic);
-  }
-}
-
-/*Recursive split-merge step.
-  Version for border regions with reduced resolution table lookups.
-  _seg:    The segmentation context.
-  _x0:     The X coordinate of the upper-left hand corner of the block.
-  _y0:     The Y coordinate of the upper-left hand corner of the block.
-  _width:  The width of the block in pixels.
-  _height: The height of the block in pixels.
-  _level:  The log base 2 of the block size.
-  _area:   The area of the block in pixels^2.
-  _sumx:   The sum of the pixel values over the block.
-  _sumx2:  The sum of the pixel values squared over the block.
-  _bic:    The BIC of the block.
-  _iplane: The image plane the block is contained in.*/
-static void oc_seg_splitmerge_bt(oc_seg_ctx *_seg,
- int _x0,int _y0,int _width,int _height,int _level,
- int _area,float _sumx,float _sumx2,float _bic,
- const th_img_plane *_iplane){
-  float sumx[4];
-  float sumx2[4];
-  float bic[4];
-  float dbic;
-  float model_cost;
-  int   dx[4];
-  int   dy[4];
-  int   tdx[4];
-  int   tdy[4];
-  int   area[4];
-  int   width[4];
-  int   height[4];
-  int   size;
-  int   size_2;
-  int   b;
-  int   tx;
-  int   ty;
-  int   i;
-  size=1<<_level;
-  _level--;
-  size_2=1<<_level;
-  dx[0]=dx[2]=dy[0]=dy[1]=0;
-  dx[1]=dx[3]=dy[2]=dy[3]=size_2;
-  tx=_x0>>OC_SEG_MOMENT_RES_LOG;
-  ty=_y0>>OC_SEG_MOMENT_RES_LOG;
-  tdx[0]=tdx[2]=tdy[0]=tdy[1]=0;
-  tdx[1]=tdx[3]=tdy[2]=tdy[3]=1<<_level-OC_SEG_MOMENT_RES_LOG;
-  b=(size>_width)|((size>_height)<<1)|
-   ((size_2>_width)<<2)|((size_2>_height)<<3)|
-   ((size_2==_width)<<4)|((size_2==_height)<<5);
-  model_cost=OC_SEG_MODEL_SPLIT_WEIGHT*OC_LOGF(_area);
-  dbic=_bic+model_cost;
-  for(i=0;i<4;i++)if(!(b&OC_SEG_CLIP_MASKS[i])){
-    float var;
-    int   twidth;
-    int   theight;
-    width[i]=(b&OC_SEG_BORDER_XMASKS[i])?_width-dx[i]:size_2;
-    height[i]=(b&OC_SEG_BORDER_YMASKS[i])?_height-dy[i]:size_2;
-    area[i]=width[i]*height[i];
-    twidth=width[i]+OC_SEG_MOMENT_RES-1>>OC_SEG_MOMENT_RES_LOG;
-    theight=height[i]+OC_SEG_MOMENT_RES-1>>OC_SEG_MOMENT_RES_LOG;
-    sumx[i]=oc_seg_sum_region(_seg->sumx,tx+tdx[i],ty+tdy[i],
-     twidth,theight);
-    sumx2[i]=oc_seg_sum_region(_seg->sumx2,tx+tdx[i],ty+tdy[i],
-     twidth,theight);
-    var=(sumx2[i]-sumx[i]*sumx[i]/area[i])/area[i];
-    bic[i]=var>0?area[i]*OC_LOGF(var):0;
-    dbic-=bic[i]+model_cost;
-  }
-  if(dbic>=0){
-    if(_level>OC_SEG_MOMENT_RES_LOG){
-      for(i=0;i<4;i++)if(!(b&OC_SEG_CLIP_MASKS[i])){
-        if(b&OC_SEG_BORDER_MASKS[i]){
-          oc_seg_splitmerge_bt(_seg,_x0+dx[i],_y0+dy[i],width[i],height[i],
-           _level,area[i],sumx[i],sumx2[i],bic[i],_iplane);
-        }
-        else{
-          oc_seg_splitmerge_it(_seg,_x0+dx[i],_y0+dy[i],
-           _level,area[i],sumx[i],sumx2[i],bic[i],_iplane);
-        }
-      }
-    }
-    else{
-      for(i=0;i<4;i++)if(!(b&OC_SEG_CLIP_MASKS[i])){
-        if(b&OC_SEG_BORDER_MASKS[i]){
-          oc_seg_splitmerge_bs(_seg,_x0+dx[i],_y0+dy[i],width[i],height[i],
-           _level,area[i],sumx[i],sumx2[i],bic[i],_iplane);
-        }
-        else{
-          oc_seg_splitmerge_is(_seg,_x0+dx[i],_y0+dy[i],
-           _level,area[i],sumx[i],sumx2[i],bic[i],_iplane);
-        }
-      }
-    }
-  }
-  else oc_seg_merge_t(_seg,_x0,_y0,_width,_height,_area,_sumx,_sumx2,_bic);
-}
-
-
-/*Initialize a segmentation context.
-  This pre-allocates all memory needed by the segmentation process.
-  _seg:    The segmentation context.
-  _width:  The width of the image to segment, in pixels.
-  _height: The height of the image to segment, in pixels.*/
-static void oc_seg_init(oc_seg_ctx *_seg,int _width,int _height){
-  int size;
-  int level_max;
-  int twidth;
-  int theight;
-  int cregions;
-  int cpairs;
-  int x;
-  int y;
-  /*Find the maximum recursion depth.*/
-  for(level_max=0,size=1;size<_width||size<_height;size<<=1)level_max++;
-  _seg->level_max=level_max;
-  /*Allocate space for the moment tables.
-    We rely on the initial row and column being zeroed out.*/
-  twidth=(_width+OC_SEG_MOMENT_RES-1>>OC_SEG_MOMENT_RES_LOG)+1;
-  theight=(_height+OC_SEG_MOMENT_RES-1>>OC_SEG_MOMENT_RES_LOG)+1;
-  _seg->sumx=(float **)oc_malloc_2d(theight,twidth,sizeof(_seg->sumx[0][0]));
-  _seg->sumx2=(float **)oc_malloc_2d(theight,twidth,
-   sizeof(_seg->sumx2[0][0]));
-  for(x=0;x<twidth;x++)_seg->sumx[0][x]=_seg->sumx2[0][x]=0;
-  for(y=1;y<theight;y++)_seg->sumx[y][0]=_seg->sumx2[y][0]=0;
-  _seg->local_sumx=(float **)oc_malloc_2d(OC_SEG_MOMENT_RES+1,
-   OC_SEG_MOMENT_RES+1,sizeof(_seg->local_sumx[0][0]));
-  _seg->local_sumx2=(float **)oc_malloc_2d(OC_SEG_MOMENT_RES+1,
-   OC_SEG_MOMENT_RES+1,sizeof(_seg->local_sumx2[0][0]));
-  for(x=0;x<OC_SEG_MOMENT_RES+1;x++){
-    _seg->local_sumx[0][x]=_seg->local_sumx2[0][x]=0;
-  }
-  for(y=1;y<OC_SEG_MOMENT_RES+1;y++){
-    _seg->local_sumx[y][0]=_seg->local_sumx2[y][0]=0;
-  }
-  _seg->labels=(int **)oc_malloc_2d(_height,_width,
-   sizeof(_seg->labels[0][0]));
-  /*Compute the maximum number of global regions in the segmentation:*/
-  cregions=(_width*_height+OC_SEG_REGION_SZ_MIN-1)/OC_SEG_REGION_SZ_MIN;
-  /*Compute the maximum number of pairs.
-    The maximum number of edges in a planar graph is 3n-6, where n is the
-     number of vertices and n>=3 (from Euler's formula).*/
-  cpairs=3*cregions-6+OC_SEG_NLOCAL_PAIRS;
-  if(cpairs<2)cpairs=2;
-  /*Allocate space for the region information and the neighbor lists.*/
-  _seg->nregions=0;
-  _seg->cregions=cregions;
-  _seg->regions=(oc_seg_region *)_ogg_malloc(
-   (OC_SEG_NLOCAL_REGS+1+cregions)*sizeof(_seg->regions[0]));
-  /*Local regions have negative labels.
-    However, to avoid lots of special casing when retreiving the region data
-     for a given label, we store them all in a single table.
-    Thus, we offset the regions pointer so that adding the region label always
-     points to a valid entry in the table.
-    The extra 1 entry is there to account for the special label -1, which
-     indicates no region.*/
-  _seg->regions+=OC_SEG_NLOCAL_REGS+1;
-  _seg->relabels=(int *)_ogg_malloc(cregions*sizeof(_seg->relabels[0]));
-  _seg->pairs=(oc_seg_pair *)_ogg_malloc(cpairs*sizeof(_seg->pairs[0]));
-  _seg->free_pairs=NULL;
-  _seg->heap=(oc_seg_pair **)_ogg_malloc(cpairs*sizeof(_seg->heap[0]));
-  _seg->reheap=oc_seg_pair_reheap;
-}
-
-/*Frees all memory used by the given segmentation context.
-  _seg: The segmentation context to clear.*/
-static void oc_seg_clear(oc_seg_ctx *_seg){
-  oc_free_2d(_seg->sumx);
-  oc_free_2d(_seg->sumx2);
-  oc_free_2d(_seg->local_sumx);
-  oc_free_2d(_seg->local_sumx2);
-  oc_free_2d(_seg->labels);
-  _ogg_free(_seg->regions-OC_SEG_NLOCAL_REGS-1);
-  _ogg_free(_seg->relabels);
-  _ogg_free(_seg->pairs);
-  _ogg_free(_seg->heap);
-}
-
-
-/*Perform segmentation over the given image plane.
-  _seg:    The segmentation context.
-  _iplane: The image plane to segment.*/
-static void oc_seg_plane(oc_seg_ctx *_seg,const th_img_plane *_iplane){
-  float sumx;
-  float sumx2;
-  float var;
-  float bic;
-  int   area;
-  int   twidth;
-  int   theight;
-  int   regi;
-  /*Build the moment tables.*/
-  oc_seg_sum_moments(_seg,_iplane);
-  /*Perform the splitting and merging to produce the segmentation.*/
-  _seg->npairs=0;
-  _seg->free_pairs=NULL;
-  _seg->nheap=0;
-  _seg->nregions=0;
-  area=_iplane->width*_iplane->height;
-  if(_seg->level_max>OC_SEG_MOMENT_RES_LOG){
-    twidth=_iplane->width+OC_SEG_MOMENT_RES-1>>OC_SEG_MOMENT_RES_LOG;
-    theight=_iplane->height+OC_SEG_MOMENT_RES-1>>OC_SEG_MOMENT_RES_LOG;
-  }
-  else twidth=theight=1;
-  sumx=oc_seg_sum_region(_seg->sumx,0,0,twidth,theight);
-  sumx2=oc_seg_sum_region(_seg->sumx2,0,0,twidth,theight);
-  var=(sumx2-sumx*sumx/area)/area;
-  bic=var>0?area*OC_LOGF(var):0;
-  if(_seg->level_max>OC_SEG_MOMENT_RES_LOG){
-    oc_seg_splitmerge_bt(_seg,0,0,_iplane->width,_iplane->height,
-     _seg->level_max,area,sumx,sumx2,bic,_iplane);
-  }
-  else{
-    oc_seg_splitmerge_bs(_seg,0,0,_iplane->width,_iplane->height,
-     _seg->level_max,area,sumx,sumx2,bic,_iplane);
-  }
-  /*Step 1: Add all the global region pairs to the heap.*/
-  for(regi=0;regi<_seg->nregions;regi++){
-    oc_seg_region *reg;
-    oc_seg_link   *link;
-    reg=_seg->regions+regi;
-    /*Add this region's pairs to the merge heap if necessary.
-      Don't worry about heap structure for now.*/
-    for(link=reg->link.next;link->pair!=NULL;link=link->next){
-      oc_seg_pair *pair;
-      pair=link->pair;
-      if(pair->links==link){
-        oc_seg_pair_update(_seg,pair);
-        if(pair->dbic<0){
-          pair->heapi=_seg->nheap++;
-          _seg->heap[pair->heapi]=pair;
-        }
-      }
-    }
-  }
-  /*Make a heap out of all the pairs all at once.*/
-  oc_seg_pair_heapify(_seg);
-  /*Step 2: Merge all the regions.*/
-  oc_seg_merge(_seg);
-  /*Make sure all the region labels are up to date.*/
-  for(regi=0;regi<_seg->nregions;regi++)oc_seg_get_label(_seg,regi);
-}
-
-
-
-/*Scans a newly created segmentation to enumerate neighbors, count border
-   pixels, count edge pixels, and count pixels near the center of the image.
-  _impmap: The importance map context.
-  _width:  The width of the image.
-  _height: The height of the image.*/
-static void oc_impmap_scan(oc_impmap_ctx *_impmap,int _width,int _height){
-  oc_seg_region     *sregions;
-  oc_impmap_region  *iregions;
-  int              **labels;
-  int               *relabels;
-  int                width_2;
-  int                height_2;
-  int                xend;
-  int                yend;
-  int                nregions;
-  int                regi;
-  int                regj;
-  int                x;
-  int                y;
-  /*First: compact the list of regions.*/
-  nregions=_impmap->seg.nregions;
-  sregions=_impmap->seg.regions;
-  relabels=_impmap->seg.relabels;
-  for(regi=regj=0;regi<nregions;regi++){
-    if(sregions[regi].link.regi==regi){
-      if(regi!=regj)*(sregions+regj)=*(sregions+regi);
-      relabels[regi]=regj++;
-    }
-    /*We may not know the final label of the region we were merged with:
-       save the old label.*/
-    else relabels[regi]=-1-sregions[regi].link.regi;
-  }
-  /*Go back and fix up the labels of any merged regions.*/
-  for(regi=0;regi<nregions;regi++){
-    if(relabels[regi]<0)relabels[regi]=relabels[-1-relabels[regi]];
-  }
-  nregions=_impmap->seg.nregions=regj;
-  /*And now update the neighbor lists.*/
-  for(regi=0;regi<nregions;regi++){
-    oc_seg_link *link;
-    link=&sregions[regi].link;
-    link->next->prev=link;
-    link->prev->next=link;
-    do{
-      link->regi=relabels[link->regi];
-      link=link->next;
-    }
-    while(link->pair!=NULL);
-  }
-  /*Second: Scan the image, gathering statistics and relabeling as we go.
-    We must be careful to relabel each pixel exactly once, because after
-     compacting, relabels[relabels[regi]]!=relabels[regi], so multiple
-     relabelings would be destructive.*/
-  labels=_impmap->seg.labels;
-  iregions=_impmap->regions;
-  /*Clear the region data.*/
-  memset(iregions,0,sizeof(iregions[0])*nregions);
-  /*Handle the corner(s):*/
-  regi=labels[0][0]=relabels[labels[0][0]];
-  iregions[regi].nborder++;
-  iregions[regi].nedge++;
-  if(_width>1){
-    regi=labels[0][_width-1]=relabels[labels[0][_width-1]];
-    iregions[regi].nborder++;
-    iregions[regi].nedge++;
-  }
-  if(_height>1){
-    regi=labels[_height-1][0]=relabels[labels[_height-1][0]];
-    iregions[regi].nborder++;
-    iregions[regi].nedge++;
-  }
-  if(_width>1&&_height>1){
-    regi=labels[_height-1][_width-1]=relabels[labels[_height-1][_width-1]];
-    iregions[regi].nborder++;
-    iregions[regi].nedge++;
-  }
-  /*Handle the interior edge(s):*/
-  for(x=1;x<_width-1;x++){
-    regi=labels[0][x]=relabels[labels[0][x]];
-    iregions[regi].nborder++;
-    iregions[regi].nedge++;
-  }
-  for(y=1;y<_height-1;y++){
-    regi=labels[y][0]=relabels[labels[y][0]];
-    iregions[regi].nborder++;
-    iregions[regi].nedge++;
-  }
-  /*Note: we DON'T store the new label for this edge.
-    See below.*/
-  if(_height>1)for(x=1;x<_width-1;x++){
-    regi=relabels[labels[_height-1][x]];
-    iregions[regi].nborder++;
-    iregions[regi].nedge++;
-  }
-  if(_width>1)for(y=1;y<_height-1;y++){
-    regi=labels[y][_width-1]=relabels[labels[y][_width-1]];
-    iregions[regi].nborder++;
-    iregions[regi].nedge++;
-  }
-  /*Handle the interior:*/
-  /*In the interior, we visit a pixel and all four of its neighbors.
-    To make sure we only relabel each pixel once, we operate under the
-     invariant that the current pixel, and all of its neighbors except the
-     one below it have already been relabeled.
-    Thus we relabel the next row right before we traverse it.
-    That's why we skipped relabeling the last row above.
-    But first, we must relabel the first row of the interior, because that
-     was not done above.*/
-  if(_height>1)for(x=1;x<_width-1;x++)labels[1][x]=relabels[labels[1][x]];
-  /*Now we proceed with the main interior loop.*/
-  for(y=1;y<_height-1;y++)for(x=1;x<_width-1;x++){
-    int border;
-    regi=labels[y][x];
-    border=regi^labels[y][x-1];
-    border|=regi^labels[y][x+1];
-    border|=regi^labels[y-1][x];
-    regj=labels[y+1][x]=relabels[labels[y+1][x]];
-    border|=regi^regj;
-    iregions[regi].nborder+=!!border;
-  }
-  /*Fifth: Handle the central 25% of the image.*/
-  width_2=_width>>1;
-  height_2=_height>>1;
-  xend=(width_2>>1)+width_2;
-  yend=(height_2>>1)+height_2;
-  for(y=height_2>>1;y<yend;y++)for(x=width_2>>1;x<xend;x++){
-    iregions[labels[y][x]].ncenter++;
-  }
-#if defined(OC_DUMP_IMAGES)
-  /*Dump a PNG of the segmented image.
-    Each segment is mapped to its mean gray level.*/
-  {
-    png_structp   png;
-    png_infop     info;
-    png_bytep    *image;
-    FILE         *fp;
-    char          fname[16];
-    sprintf(fname,"%08iseg.png",_impmap->enc->state.curframe_num);
-    fp=fopen(fname,"wb");
-    if(fp==NULL)return;
-    image=(png_bytep *)oc_malloc_2d(_height,_width,sizeof(image[0][0]));
-    png=png_create_write_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
-    if(png==NULL){
-      oc_free_2d(image);
-      fclose(fp);
-      return;
-    }
-    info=png_create_info_struct(png);
-    if(info==NULL){
-      png_destroy_write_struct(&png,NULL);
-      oc_free_2d(image);
-      fclose(fp);
-      return;
-    }
-    if(setjmp(png_jmpbuf(png))){
-      png_destroy_write_struct(&png,&info);
-      oc_free_2d(image);
-      fclose(fp);
-      return;
-    }
-    for(y=0;y<_height;y++)for(x=0;x<_width;x++){
-      int regi;
-      regi=labels[y][x];
-      image[_height-1-y][x]=(unsigned char)(
-       sregions[regi].sumx/sregions[regi].npixels+0.5F);
-    }
-    png_init_io(png,fp);
-    png_set_compression_level(png,Z_BEST_COMPRESSION);
-    png_set_IHDR(png,info,_width,_height,8,PNG_COLOR_TYPE_GRAY,
-     PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT);
-    png_set_rows(png,info,image);
-    png_write_png(png,info,PNG_TRANSFORM_IDENTITY,NULL);
-    png_write_end(png,info);
-    png_destroy_write_struct(&png,&info);
-    oc_free_2d(image);
-    fclose(fp);
-  }
-#endif
-}
-
-static void oc_impmap_regions_weight(oc_impmap_ctx *_impmap){
-  oc_seg_region    *sreg;
-  oc_impmap_region *ireg;
-  float             weight_mins[OC_IMPMAP_NSEG_RESCALED_WEIGHTS];
-  float             weight_maxs[OC_IMPMAP_NSEG_RESCALED_WEIGHTS];
-  float             weight_scales[OC_IMPMAP_NSEG_RESCALED_WEIGHTS];
-  float             imp_max;
-  float             imp_scale;
-  int               regi;
-  int               i;
-  /*Compute the importance values for each region:*/
-  for(i=0;i<OC_IMPMAP_NSEG_RESCALED_WEIGHTS;i++){
-    weight_mins[i]=FLT_MAX;
-    weight_maxs[i]=-FLT_MAX;
-  }
-  /*Step 1: Compute several weighting factors for each region.*/
-  for(regi=0;regi<_impmap->seg.nregions;regi++){
-    oc_seg_link *link;
-    float        nsumx;
-    int          narea;
-    ireg=_impmap->regions+regi;
-    sreg=_impmap->seg.regions+regi;
-    /*Contrast weight: measure contrast with neighboring regions.*/
-    nsumx=0;
-    narea=0;
-    for(link=sreg->link.next;link->pair!=NULL;link=link->next){
-      nsumx+=_impmap->seg.regions[link->regi].sumx;
-      narea+=_impmap->seg.regions[link->regi].npixels;
-    }
-    ireg->weights[OC_IMPMAP_WEIGHT_CONTRAST]=sreg->sumx/sreg->npixels;
-    if(narea>0)ireg->weights[OC_IMPMAP_WEIGHT_CONTRAST]-=nsumx/narea;
-    /*Osberger does not specify using an absolute value, but it seems like
-       that is really what one wants.*/
-    ireg->weights[OC_IMPMAP_WEIGHT_CONTRAST]=
-     OC_FABSF(ireg->weights[OC_IMPMAP_WEIGHT_CONTRAST]);
-    /*Size weight: measure the size of the region.*/
-    ireg->weights[OC_IMPMAP_WEIGHT_SIZE]=
-     OC_MINF(sreg->npixels*_impmap->inv_region_sz_max,1);
-    /*Shape weight: measure unusual (long/thin) shapes.*/
-    ireg->weights[OC_IMPMAP_WEIGHT_SHAPE]=
-     OC_POWF(ireg->nborder,1.75F)/sreg->npixels;
-    /*Location weight: weight regions in the image center.*/
-    ireg->weights[OC_IMPMAP_WEIGHT_LOCATION]=
-     ireg->ncenter/(float)sreg->npixels;
-    /*Foreground weight: weight regions in the image foreground.
-      As per Osberger, this is defined as regions which do not intersect the
-       border of the image.*/
-    ireg->weights[OC_IMPMAP_WEIGHT_FOREGROUND]=
-     OC_MAXF(1-ireg->nedge*_impmap->inv_edge_sz_max,0);
-    for(i=0;i<OC_IMPMAP_NSEG_RESCALED_WEIGHTS;i++){
-      weight_maxs[i]=OC_MAXF(weight_maxs[i],ireg->weights[i]);
-      weight_mins[i]=OC_MINF(weight_mins[i],ireg->weights[i]);
-    }
-  }
-  /*Rescale the weighting factors into the range [0,1] as necessary.*/
-  for(i=0;i<OC_IMPMAP_NSEG_RESCALED_WEIGHTS;i++){
-    if(weight_maxs[i]>weight_mins[i]){
-      weight_scales[i]=1/(weight_maxs[i]-weight_mins[i]);
-    }
-    else weight_scales[i]=1;
-  }
-  /*Step 2: Combine the weighting factors into a single importance value.*/
-  imp_max=0;
-  for(regi=0;regi<_impmap->seg.nregions;regi++){
-    ireg=_impmap->regions+regi;
-    for(i=0;i<OC_IMPMAP_NSEG_RESCALED_WEIGHTS;i++){
-      ireg->weights[i]=(ireg->weights[i]-weight_mins[i])*weight_scales[i];
-    }
-    ireg->importance=0;
-    for(i=0;i<OC_IMPMAP_NSEG_WEIGHTS;i++){
-      ireg->importance+=ireg->weights[i]*ireg->weights[i];
-    }
-    imp_max=OC_MAXF(imp_max,ireg->importance);
-  }
-  /*Rescale the regions' importances into the range [0,1].*/
-  if(imp_max>0){
-    imp_scale=1/imp_max;
-    for(regi=0;regi<_impmap->seg.nregions;regi++){
-      _impmap->regions[regi].importance*=imp_scale;
-    }
-  }
-}
-
-/*Computes the importance of a given motion vector.
-  _impmap: The importance map context.
-  _dx:     The horizontal motion, in half-pixels/frame.
-  _dy:     The vertical motion, in half-pixels/frame.*/
-static float oc_impmap_mot_weight(oc_impmap_ctx *_impmap,int _dx,int _dy){
-  float mot;
-  /*This computation is perhaps too simple: In reality, it is motion which
-     deviates from the average (3D) motion that attracts attention.
-    Consider a camera that is moving straight forward.
-    The motion with the largest magnitudes is on the edge of the image, but
-     the most likely center of attention is the vanishing point in the center
-     of the image.
-    All of the motion in the image can be explained by one global motion of
-     the camera, and so none of it in particular draws attention.
-    However, the Theora codec does not currently have a form of global motion
-     compensation, and computing it just for this measurement is awfully
-     expensive.*/
-  mot=OC_SQRTF(_dx*_dx+_dy*_dy);
-  if(mot<_impmap->mot_limits[0])return 0;
-  else if(mot<_impmap->mot_limits[1]){
-    return (mot-_impmap->mot_limits[0])/
-     (_impmap->mot_limits[1]-_impmap->mot_limits[0]);
-  }
-  else if(mot<_impmap->mot_limits[2])return 1;
-  else if(mot<_impmap->mot_limits[3]){
-    return (_impmap->mot_limits[3]-mot)/
-     (_impmap->mot_limits[3]-_impmap->mot_limits[2]);
-  }
-  else return 0;
-}
-
-static void oc_impmap_chroma_frag_weight00(oc_fragment_enc_info *_efrag,
- oc_mb_map _map,const float _yfrag_imp_weights[4]){
-  float cfrag_imp_weight;
-  cfrag_imp_weight=OC_MAXF(OC_MAXF(_yfrag_imp_weights[0],
-   _yfrag_imp_weights[1]),
-   OC_MAXF(_yfrag_imp_weights[2],_yfrag_imp_weights[3]));
-  _efrag[_map[1][0]].imp_weight=cfrag_imp_weight;
-  _efrag[_map[2][0]].imp_weight=cfrag_imp_weight;
-}
-
-static void oc_impmap_chroma_frag_weight01(oc_fragment_enc_info *_efrag,
- oc_mb_map _map,const float _yfrag_imp_weights[4]){
-  float cfrag_imp_weight;
-  cfrag_imp_weight=OC_MAXF(_yfrag_imp_weights[0],_yfrag_imp_weights[2]);
-  _efrag[_map[1][0]].imp_weight=cfrag_imp_weight;
-  _efrag[_map[2][0]].imp_weight=cfrag_imp_weight;
-  cfrag_imp_weight=OC_MAXF(_yfrag_imp_weights[1],_yfrag_imp_weights[3]);
-  _efrag[_map[1][1]].imp_weight=cfrag_imp_weight;
-  _efrag[_map[2][1]].imp_weight=cfrag_imp_weight;
-}
-
-static void oc_impmap_chroma_frag_weight10(oc_fragment_enc_info *_efrag,
- oc_mb_map _map,const float _yfrag_imp_weights[4]){
-  float cfrag_imp_weight;
-  cfrag_imp_weight=OC_MAXF(_yfrag_imp_weights[0],_yfrag_imp_weights[1]);
-  _efrag[_map[1][0]].imp_weight=cfrag_imp_weight;
-  _efrag[_map[2][0]].imp_weight=cfrag_imp_weight;
-  cfrag_imp_weight=OC_MAXF(_yfrag_imp_weights[2],_yfrag_imp_weights[3]);
-  _efrag[_map[1][2]].imp_weight=cfrag_imp_weight;
-  _efrag[_map[2][2]].imp_weight=cfrag_imp_weight;
-}
-
-static void oc_impmap_chroma_frag_weight11(oc_fragment_enc_info *_efrag,
- oc_mb_map _map,const float _yfrag_imp_weights[4]){
-  _efrag[_map[1][0]].imp_weight=_yfrag_imp_weights[0];
-  _efrag[_map[2][0]].imp_weight=_yfrag_imp_weights[0];
-  _efrag[_map[1][1]].imp_weight=_yfrag_imp_weights[1];
-  _efrag[_map[2][1]].imp_weight=_yfrag_imp_weights[1];
-  _efrag[_map[1][2]].imp_weight=_yfrag_imp_weights[2];
-  _efrag[_map[2][2]].imp_weight=_yfrag_imp_weights[2];
-  _efrag[_map[1][3]].imp_weight=_yfrag_imp_weights[3];
-  _efrag[_map[2][3]].imp_weight=_yfrag_imp_weights[3];
-}
-
-/*A table of functions used to fill in the chroma plane fragment importance
-   for a macro block for each type of chrominance decimation.
-  The importance of a chroma fragment is taken as the maximum importance of
-   any co-located luma fragment.*/
-static const oc_impmap_chroma_frag_weight_func
- OC_IMPMAP_CHROMA_FRAG_WEIGHT_TABLE[4]={
-  oc_impmap_chroma_frag_weight00,
-  oc_impmap_chroma_frag_weight01,
-  oc_impmap_chroma_frag_weight10,
-  oc_impmap_chroma_frag_weight11,
-};
-
-
-
-static float oc_impmap_mb_weight(oc_impmap_ctx *_impmap,int _mbi){
-  oc_mb *mb;
-  float  ret;
-  mb=_impmap->enc->state.mbs+_mbi;
-  ret=0;
-  if(mb->mode!=OC_MODE_INVALID){
-    static const int FRAG_DX[4]={0,8,0,8};
-    static const int FRAG_DY[4]={0,0,8,8};
-    oc_mb_enc_info    *emb;
-    oc_impmap_region  *iregions;
-    int              **labels;
-    float              frag_imps[4];
-    float              frag_imp_weights[4];
-    float              mot_imp;
-    int                x0;
-    int                y0;
-    int                i;
-    emb=_impmap->enc->mbinfo+_mbi;
-    mot_imp=oc_impmap_mot_weight(_impmap,emb->mvs[0][OC_FRAME_PREV][0],
-     emb->mvs[0][OC_FRAME_PREV][1]);
-    iregions=_impmap->regions;
-    labels=_impmap->seg.labels;
-    x0=mb->x-_impmap->pic_x;
-    y0=mb->y-_impmap->pic_y;
-    for(i=0;i<4;i++){
-      oc_fragment          *frag;
-      oc_fragment_enc_info *efrag;
-      int                   xend;
-      int                   yend;
-      int                   x;
-      int                   y;
-      frag=_impmap->enc->state.frags+mb->map[0][i];
-      efrag=_impmap->enc->frinfo+mb->map[0][i];
-      xend=x0+FRAG_DX[i]+8;
-      yend=y0+FRAG_DY[i]+8;
-      frag_imps[i]=0;
-      if(frag->invalid)continue;
-      if(frag->border==NULL){
-        for(y=y0+FRAG_DY[i];y<yend;y++)for(x=x0+FRAG_DX[i];x<xend;x++){
-          frag_imps[i]=OC_MAXF(frag_imps[i],
-           iregions[labels[y][x]].importance);
-        }
-      }
-      else{
-        oc_border_info *border;
-        ogg_int64_t     bit;
-        border=frag->border;
-        for(y=y0+FRAG_DY[i],bit=1;y<yend;y++){
-          for(x=x0+FRAG_DX[i];x<xend;x++,bit<<=1)if(border->mask&bit){
-            frag_imps[i]=OC_MAXF(frag_imps[i],
-             iregions[labels[y][x]].importance);
-          }
-        }
-      }
-      frag_imps[i]+=mot_imp;
-      ret+=frag_imps[i];
-      efrag->imp_weight=frag_imp_weights[i]=
-       (2*frag_imps[i]+_impmap->imp_avg)/(frag_imps[i]+2*_impmap->imp_avg);
-    }
-    (*_impmap->chroma_frag_weight)(_impmap->enc->frinfo,mb->map,
-     frag_imp_weights);
-  }
-  return ret;
-}
-static void oc_impmap_fill(oc_impmap_ctx *_impmap,float _duration){
-  th_img_plane yplane;
-  float            imp_sum;
-  int              img_offset;
-  int              nmbs;
-  int              mbi;
-  /*Segment the Y plane.*/
-  /*TODO: Use the same oc_border_info structure as everyone else.
-    This would make future integration of an alpha mask easier.*/
-  img_offset=_impmap->enc->state.input[0].ystride*
-   _impmap->enc->state.info.pic_y+_impmap->enc->state.info.pic_x;
-  yplane.data=_impmap->enc->state.input[0].data+img_offset;
-  yplane.width=_impmap->enc->state.info.pic_width;
-  yplane.height=_impmap->enc->state.info.pic_height;
-  yplane.ystride=_impmap->enc->state.input[0].ystride;
-  oc_seg_plane(&_impmap->seg,&yplane);
-  /*Gather statistics over the segmentation.*/
-  oc_impmap_scan(_impmap,yplane.width,yplane.height);
-  /*Compute weights for each segmented region.*/
-  oc_impmap_regions_weight(_impmap);
-  /*Rescale motion limits from deg/sec to half-pixels/frame.*/
-  _impmap->mot_limits[0]=2*OC_IMPMAP_MOT_MIN*OC_PIXELS_PER_DEGREE*_duration;
-  _impmap->mot_limits[1]=2*OC_IMPMAP_MOT_P1*OC_PIXELS_PER_DEGREE*_duration;
-  _impmap->mot_limits[2]=2*OC_IMPMAP_MOT_P2*OC_PIXELS_PER_DEGREE*_duration;
-  _impmap->mot_limits[3]=2*OC_IMPMAP_MOT_MAX*OC_PIXELS_PER_DEGREE*_duration;
-  nmbs=_impmap->enc->state.nmbs;
-  imp_sum=0;
-  for(mbi=0;mbi<nmbs;mbi++)imp_sum+=oc_impmap_mb_weight(_impmap,mbi);
-  _impmap->imp_avg=imp_sum/_impmap->enc->state.fplanes[0].nfrags;
-#if defined(OC_DUMP_IMAGES)
-  /*Dump a PNG of the importance maps.*/
-  {
-    int pli;
-    for(pli=0;pli<3;pli++){
-      oc_fragment_plane *fplane;
-      png_structp        png;
-      png_infop          info;
-      png_bytep         *image;
-      FILE              *fp;
-      char               fname[16];
-      int                x;
-      int                y;
-      sprintf(fname,"%08iim%i.png",(int)_impmap->enc->state.curframe_num,pli);
-      fp=fopen(fname,"wb");
-      if(fp==NULL)return;
-      fplane=_impmap->enc->state.fplanes+pli;
-      image=(png_bytep *)oc_malloc_2d(fplane->nvfrags,fplane->nhfrags,
-       sizeof(image[0][0]));
-      png=png_create_write_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
-      if(png==NULL){
-        oc_free_2d(image);
-        fclose(fp);
-        return;
-      }
-      info=png_create_info_struct(png);
-      if(info==NULL){
-        png_destroy_write_struct(&png,NULL);
-        oc_free_2d(image);
-        fclose(fp);
-        return;
-      }
-      if(setjmp(png_jmpbuf(png))){
-        png_destroy_write_struct(&png,&info);
-        oc_free_2d(image);
-        fclose(fp);
-        return;
-      }
-      for(y=0;y<fplane->nvfrags;y++)for(x=0;x<fplane->nhfrags;x++){
-        float imp;
-        imp=(_impmap->enc->frinfo+fplane->froffset+
-         (fplane->nvfrags-1-y)*fplane->nhfrags+x)->imp_weight;
-        image[y][x]=(unsigned char)(imp*64+128.5F);
-      }
-      png_init_io(png,fp);
-      png_set_compression_level(png,Z_BEST_COMPRESSION);
-      png_set_IHDR(png,info,fplane->nhfrags,fplane->nvfrags,8,
-       PNG_COLOR_TYPE_GRAY,PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,
-       PNG_FILTER_TYPE_DEFAULT);
-      png_set_rows(png,info,image);
-      png_write_png(png,info,PNG_TRANSFORM_IDENTITY,NULL);
-      png_write_end(png,info);
-      png_destroy_write_struct(&png,&info);
-      oc_free_2d(image);
-      fclose(fp);
-    }
-  }
-#endif
-}
-
-
-/*The importance map pipeline stage.
-  For now, for simplicity, this is not actually pipelined.
-  The quadtree segmentation algorithm does not really lend itself to it, and
-   even if an online segmentation algorithm were used, a full stall would be
-   created by the need to gather statistics over all the regions to assign
-   weights to any of them.*/
-
-static int oc_impmap_pipe_start(oc_enc_pipe_stage *_stage){
-  int pli;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=0;
-  return 0;
-}
-
-static int oc_impmap_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  int pli;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=_y_avail[pli];
-  return 0;
-}
-
-static int oc_impmap_pipe_end(oc_enc_pipe_stage *_stage){
-  oc_enc_ctx *enc;
-  enc=_stage->enc;
-  oc_impmap_fill(enc->vbr->impmap,
-   enc->state.info.fps_denominator/(float)enc->state.info.fps_numerator);
-  if(_stage->next!=NULL){
-    int ret;
-    ret=(*_stage->next->pipe_start)(_stage->next);
-    if(ret<0)return ret;
-    ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-    if(ret<0)return ret;
-    return (*_stage->next->pipe_end)(_stage->next);
-  }
-  return 0;
-}
-
-/*Initialize the importance map stage of the pipeline.
-  _enc: The encoding context.*/
-static void oc_impmap_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_impmap_pipe_start;
-  _stage->pipe_proc=oc_impmap_pipe_process;
-  _stage->pipe_end=oc_impmap_pipe_end;
-}
-
-
-oc_impmap_ctx *oc_impmap_alloc(oc_enc_ctx *_enc){
-  th_info   *info;
-  oc_impmap_ctx *impmap;
-  int            edge_sz;
-  int            width;
-  int            height;
-  info=&_enc->state.info;
-  width=info->pic_width;
-  height=info->pic_height;
-  impmap=(oc_impmap_ctx *)_ogg_malloc(sizeof(*impmap));
-  oc_seg_init(&impmap->seg,width,height);
-  impmap->inv_region_sz_max=100.0F/(width*height);
-  edge_sz=width>1?height>1?(width-2<<1)+(height<<1):width:height;
-  impmap->inv_edge_sz_max=2.0F/edge_sz;
-  impmap->pic_x=info->pic_x;
-  impmap->pic_y=info->pic_y;
-  impmap->imp_avg=0.5F;
-  /*Allocate space for the region stats and neighbor links.*/
-  impmap->regions=(oc_impmap_region *)_ogg_malloc(
-   impmap->seg.cregions*sizeof(impmap->regions[0]));
-  impmap->enc=_enc;
-  impmap->chroma_frag_weight=
-   OC_IMPMAP_CHROMA_FRAG_WEIGHT_TABLE[_enc->state.info.pixel_fmt];
-  oc_impmap_pipe_init(&impmap->pipe,_enc);
-  return impmap;
-}
-
-void oc_impmap_free(oc_impmap_ctx *_impmap){
-  if(_impmap!=NULL){
-    oc_seg_clear(&_impmap->seg);
-    _ogg_free(_impmap->regions);
-    _ogg_free(_impmap);
-  }
-}
-
-
-oc_enc_pipe_stage *oc_impmap_prepend_to_pipe(oc_impmap_ctx *_impmap,
- oc_enc_pipe_stage *_next){
-  _impmap->pipe.next=_next;
-  return &_impmap->pipe;
-}

Deleted: experimental/j/theora-mashup/lib/dec/mcenc.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/mcenc.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/mcenc.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,785 +0,0 @@
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-#include "encint.h"
-
-struct oc_mcenc_ctx{
-  oc_enc_ctx        *enc;
-  oc_enc_pipe_stage  pipe;
-  int                candidates[12][2];
-  int                setb0;
-  int                ncandidates;
-  ogg_int32_t        mvapw1[2];
-  ogg_int32_t        mvapw2[2];
-};
-
-/*The maximum Y plane SAD value for accepting the median predictor.*/
-#define OC_YSAD_THRESH1            (256)
-/*The amount to right shift the minimum error by when inflating it for
-   computing the second maximum Y plane SAD threshold.*/
-#define OC_YSAD_THRESH2_SCALE_BITS (3)
-/*The amount to add to the second maximum Y plane threshold when inflating
-   it.*/
-#define OC_YSAD_THRESH2_OFFSET     (128)
-
-/*The vector offsets in the X direction for each search site in the square
-   pattern.*/
-static const int OC_SQUARE_DX[9]={-1,0,1,-1,0,1,-1,0,1};
-/*The vector offsets in the Y direction for each search site in the square
-   pattern.*/
-static const int OC_SQUARE_DY[9]={-1,-1,-1,0,0,0,1,1,1};
-/*The number of sites to search for each boundary condition in the square
-   pattern.
-  Bit flags for the boundary conditions are as follows:
-  1: -16==dx
-  2:      dx==15(.5)
-  4: -16==dy
-  8:      dy==15(.5)*/
-static const int OC_SQUARE_NSITES[11]={8,5,5,0,5,3,3,0,5,3,3};
-/*The list of sites to search for each boundary condition in the square
-   pattern.*/
-static const int OC_SQUARE_SITES[11][8]={
-  /* -15.5<dx<31,       -15.5<dy<15(.5)*/
-  {0,1,2,3,5,6,7,8},
-  /*-15.5==dx,          -15.5<dy<15(.5)*/
-  {1,2,5,7,8},
-  /*     dx==15(.5),    -15.5<dy<15(.5)*/
-  {0,1,3,6,7},
-  /*-15.5==dx==15(.5),  -15.5<dy<15(.5)*/
-  {-1},
-  /* -15.5<dx<15(.5),  -15.5==dy*/
-  {3,5,6,7,8},
-  /*-15.5==dx,         -15.5==dy*/
-  {5,7,8},
-  /*     dx==15(.5),   -15.5==dy*/
-  {3,6,7},
-  /*-15.5==dx==15(.5), -15.5==dy*/
-  {-1},
-  /*-15.5dx<15(.5),           dy==15(.5)*/
-  {0,1,2,3,5},
-  /*-15.5==dx,                dy==15(.5)*/
-  {1,2,5},
-  /*       dx==15(.5),        dy==15(.5)*/
-  {0,1,3}
-};
-
-
-
-static void oc_mcenc_find_candidates(oc_mcenc_ctx *_mcenc,int _mbi,
- int _which_frame){
-  oc_mb_enc_info *nemb;
-  oc_mb_enc_info *emb;
-  ogg_int32_t     mvapw1;
-  ogg_int32_t     mvapw2;
-  int             a[3][2];
-  int             ncandidates;
-  int             i;
-  emb=_mcenc->enc->mbinfo+_mbi;
-  if(emb->ncneighbors>0){
-    /*Fill in the first part of set A: the last motion vectors used and the
-       vectors from adjacent blocks.*/
-    /*Skip a position to store the median predictor in.*/
-    ncandidates=1;
-    for(i=0;i<emb->ncneighbors;i++){
-      nemb=_mcenc->enc->mbinfo+emb->cneighbors[i];
-      _mcenc->candidates[ncandidates][0]=nemb->mvs[0][_which_frame][0];
-      _mcenc->candidates[ncandidates][1]=nemb->mvs[0][_which_frame][1];
-      ncandidates++;
-    }
-    /*Add a few additional vectors to set A: the vector used in the previous
-       frame and the (0,0) vector.*/
-    _mcenc->candidates[ncandidates][0]=emb->mvs[1][_which_frame][0];
-    _mcenc->candidates[ncandidates][1]=emb->mvs[1][_which_frame][1];
-    ncandidates++;
-    _mcenc->candidates[ncandidates][0]=0;
-    _mcenc->candidates[ncandidates][1]=0;
-    ncandidates++;
-    /*Use the first three vectors of set A to find our best predictor: their
-       median.*/
-    memcpy(a,_mcenc->candidates+1,sizeof(a[0])*3);
-    OC_SORT2I(a[0][0],a[1][0]);
-    OC_SORT2I(a[0][1],a[1][1]);
-    OC_SORT2I(a[1][0],a[2][0]);
-    OC_SORT2I(a[1][1],a[2][1]);
-    OC_SORT2I(a[0][0],a[1][0]);
-    OC_SORT2I(a[0][1],a[1][1]);
-    _mcenc->candidates[0][0]=a[1][0];
-    _mcenc->candidates[0][1]=a[1][1];
-  }
-  /*The upper-left most macro block has no neighbors at all
-    We just use 0,0 as the median predictor and its previous motion vector
-     for set A.*/
-  else{
-    _mcenc->candidates[0][0]=0;
-    _mcenc->candidates[0][1]=0;
-    _mcenc->candidates[1][0]=emb->mvs[1][_which_frame][0];
-    _mcenc->candidates[1][1]=emb->mvs[1][_which_frame][1];
-    ncandidates=2;
-  }
-  /*Fill in set B: accelerated predictors for this and adjacent macro
-     blocks.*/
-  _mcenc->setb0=ncandidates;
-  mvapw1=_mcenc->mvapw1[_which_frame];
-  mvapw2=_mcenc->mvapw2[_which_frame];
-  /*The first time through the loop use the current macro block.*/
-  nemb=emb;
-  for(i=0;;i++){
-    _mcenc->candidates[ncandidates][0]=
-     OC_DIV_ROUND_POW2(nemb->mvs[1][_which_frame][0]*mvapw1-
-     nemb->mvs[2][_which_frame][0]*mvapw2,16,0x8000);
-    _mcenc->candidates[ncandidates][1]=
-     OC_DIV_ROUND_POW2(nemb->mvs[1][_which_frame][1]*mvapw1-
-     nemb->mvs[2][_which_frame][1]*mvapw2,16,0x8000);
-    _mcenc->candidates[ncandidates][0]=OC_CLAMPI(-31,
-     _mcenc->candidates[ncandidates][0],31);
-    _mcenc->candidates[ncandidates][1]=OC_CLAMPI(-31,
-     _mcenc->candidates[ncandidates][1],31);
-    ncandidates++;
-    if(i>=emb->npneighbors)break;
-    nemb=_mcenc->enc->mbinfo+emb->pneighbors[i];
-  }
-  /*Truncate to full-pel positions.*/
-  for(i=0;i<ncandidates;i++){
-    _mcenc->candidates[i][0]=OC_DIV2(_mcenc->candidates[i][0]);
-    _mcenc->candidates[i][1]=OC_DIV2(_mcenc->candidates[i][1]);
-  }
-  _mcenc->ncandidates=ncandidates;
-}
-
-static int oc_sad16_halfpel(const oc_fragment *_frags,const int _fragis[4],
- int _cur_ystride,int _ref_ystride,int _mvoffset0,int _mvoffset1,
- int  _ref_framei){
-  int err;
-  int i;
-  err=0;
-  for(i=0;i<4;i++){
-    const oc_fragment *frag;
-    frag=_frags+_fragis[i];
-    if(frag->border==NULL){
-      if(!frag->invalid){
-        err+=oc_sad8_halfpel(frag->buffer[OC_FRAME_IO],_cur_ystride,
-         frag->buffer[_ref_framei]+_mvoffset0,
-         frag->buffer[_ref_framei]+_mvoffset1,_ref_ystride);
-      }
-    }
-    else{
-      err+=oc_sad8_halfpel_border(frag->buffer[OC_FRAME_IO],_cur_ystride,
-       frag->buffer[_ref_framei]+_mvoffset0,
-       frag->buffer[_ref_framei]+_mvoffset1,_ref_ystride,frag->border->mask);
-    }
-  }
-  return err;
-}
-
-static int oc_mcenc_sad_check_mbcandidate_fullpel(oc_mcenc_ctx *_mcenc,
- int _mbi,int _dx,int _dy,int _pli,int _ref_framei,int _block_err[4]){
-  const oc_fragment_plane *fplane;
-  const oc_fragment       *frags;
-  int                     *mb_map;
-  int                      cur_ystride;
-  int                      ref_ystride;
-  int                      mvoffset;
-  int                      err;
-  int                      bi;
-  /*TODO: customize error function for speed/(quality+size) tradeoff.*/
-  fplane=_mcenc->enc->state.fplanes+_pli;
-  cur_ystride=_mcenc->enc->state.input[_pli].ystride;
-  ref_ystride=_mcenc->enc->state.ref_frame_bufs[_ref_framei][_pli].ystride;
-  frags=_mcenc->enc->state.frags;
-  mb_map=_mcenc->enc->state.mbs[_mbi].map[_pli];
-  mvoffset=_dx+_dy*ref_ystride;
-  err=0;
-  for(bi=0;bi<4;bi++)if(mb_map[bi]>=0){
-    const oc_fragment *frag;
-    frag=frags+mb_map[bi];
-    if(frag->border==NULL){
-      if(!frag->invalid){
-        _block_err[bi]=oc_sad8_fullpel(frag->buffer[OC_FRAME_IO],cur_ystride,
-         frag->buffer[_ref_framei]+mvoffset,ref_ystride);
-      }
-    }
-    else{
-      _block_err[bi]=oc_sad8_fullpel_border(frag->buffer[OC_FRAME_IO],
-       cur_ystride,frag->buffer[_ref_framei]+mvoffset,ref_ystride,
-       frag->border->mask);
-    }
-    err+=_block_err[bi];
-
-  }
-  return err;
-}
-
-static int oc_mcenc_ysad_check_mbcandidate_fullpel(oc_mcenc_ctx *_mcenc,
- int _mbi,int _dx,int _dy,int _ref_framei,int _block_err[4]){
-  return oc_mcenc_sad_check_mbcandidate_fullpel(_mcenc,_mbi,_dx,_dy,0,
-   _ref_framei,_block_err);
-}
-
-static int oc_mcenc_ysad_halfpel_mbrefine(oc_mcenc_ctx *_mcenc,
- int _mbi,int _vec[2],int _best_err,int _ref_framei){
-  int                      offset_y[9];
-  const oc_fragment_plane *fplane;
-  const oc_fragment       *frags;
-  int                     *mb_map;
-  int                      cur_ystride;
-  int                      ref_ystride;
-  int                      mvoffset_base;
-  int                      best_site;
-  int                      sitei;
-  int                      err;
-  fplane=_mcenc->enc->state.fplanes+0;
-  cur_ystride=_mcenc->enc->state.input[0].ystride;
-  ref_ystride=_mcenc->enc->state.ref_frame_bufs[_ref_framei][0].ystride;
-  frags=_mcenc->enc->state.frags;
-  mb_map=_mcenc->enc->state.mbs[_mbi].map[0];
-  mvoffset_base=_vec[0]+_vec[1]*ref_ystride;
-  offset_y[0]=offset_y[1]=offset_y[2]=-ref_ystride;
-  offset_y[3]=offset_y[5]=0;
-  offset_y[6]=offset_y[7]=offset_y[8]=ref_ystride;
-  err=_best_err;
-  best_site=4;
-  for(sitei=0;sitei<8;sitei++){
-    int site;
-    int xmask;
-    int ymask;
-    int dx;
-    int dy;
-    int mvoffset0;
-    int mvoffset1;
-    site=OC_SQUARE_SITES[0][sitei];
-    dx=OC_SQUARE_DX[site];
-    dy=OC_SQUARE_DY[site];
-    /*The following code SHOULD be equivalent to
-      oc_state_get_mv_offsets(&_mcenc->enc.state,&mvoffset0,&mvoffset1,
-       (_vec[0]<<1)+dx,(_vec[1]<<1)+dy,ref_ystride,0);
-      However, it should also be much faster, as it involves no multiplies and
-       doesn't have to handle chroma vectors.*/
-    xmask=((_vec[0]<<1)+OC_SQUARE_DX[site]>>6)^(dx>>1);
-    ymask=((_vec[1]<<1)+OC_SQUARE_DY[site]>>6)^(dy>>1);
-    mvoffset0=mvoffset_base+(dx&xmask)+(offset_y[site]&ymask);
-    mvoffset1=mvoffset_base+(dx&~xmask)+(offset_y[site]&~ymask);
-    err=oc_sad16_halfpel(frags,mb_map,cur_ystride,ref_ystride,mvoffset0,
-     mvoffset1,_ref_framei);
-    if(err<_best_err){
-      _best_err=err;
-      best_site=site;
-    }
-  }
-  _vec[0]=(_vec[0]<<1)+OC_SQUARE_DX[best_site];
-  _vec[1]=(_vec[1]<<1)+OC_SQUARE_DY[best_site];
-  return _best_err;
-}
-
-static int oc_mcenc_ysad_halfpel_brefine(oc_mcenc_ctx *_mcenc,
- int _mbi,int _bi,int _vec[2],int _best_err,int _ref_framei){
-  int                      offset_y[9];
-  const oc_fragment_plane *fplane;
-  const oc_fragment       *frag;
-  int                      cur_ystride;
-  int                      ref_ystride;
-  int                      mvoffset_base;
-  int                      best_site;
-  int                      sitei;
-  int                      err;
-  fplane=_mcenc->enc->state.fplanes+0;
-  cur_ystride=_mcenc->enc->state.input[0].ystride;
-  ref_ystride=_mcenc->enc->state.ref_frame_bufs[_ref_framei][0].ystride;
-  frag=_mcenc->enc->state.frags+_mcenc->enc->state.mbs[_mbi].map[0][_bi];
-  if(frag->invalid)return _best_err;
-  mvoffset_base=_vec[0]+_vec[1]*ref_ystride;
-  offset_y[0]=offset_y[1]=offset_y[2]=-ref_ystride;
-  offset_y[3]=offset_y[5]=0;
-  offset_y[6]=offset_y[7]=offset_y[8]=ref_ystride;
-  err=_best_err;
-  best_site=4;
-  for(sitei=0;sitei<8;sitei++){
-    int site;
-    int xmask;
-    int ymask;
-    int dx;
-    int dy;
-    int mvoffset0;
-    int mvoffset1;
-    site=OC_SQUARE_SITES[0][sitei];
-    dx=OC_SQUARE_DX[site];
-    dy=OC_SQUARE_DY[site];
-    /*The following code SHOULD be equivalent to
-      oc_state_get_mv_offsets(&_mcenc->enc.state,&mvoffset0,&mvoffset1,
-       (_vec[0]<<1)+dx,(_vec[1]<<1)+dy,ref_ystride,0);
-      However, it should also be much faster, as it involves no multiplies and
-       doesn't have to handle chroma vectors.*/
-    xmask=((_vec[0]<<1)+OC_SQUARE_DX[site]>>6)^(dx>>1);
-    ymask=((_vec[1]<<1)+OC_SQUARE_DY[site]>>6)^(dy>>1);
-    mvoffset0=mvoffset_base+(dx&xmask)+(offset_y[site]&ymask);
-    mvoffset1=mvoffset_base+(dx&~xmask)+(offset_y[site]&~ymask);
-    if(frag->border==NULL){
-      err=oc_sad8_halfpel(frag->buffer[OC_FRAME_IO],cur_ystride,
-       frag->buffer[_ref_framei]+mvoffset0,
-       frag->buffer[_ref_framei]+mvoffset1,ref_ystride);
-    }
-    else{
-      err=oc_sad8_halfpel_border(frag->buffer[OC_FRAME_IO],cur_ystride,
-       frag->buffer[_ref_framei]+mvoffset0,
-       frag->buffer[_ref_framei]+mvoffset1,ref_ystride,frag->border->mask);
-    }
-    if(err<_best_err){
-      _best_err=err;
-      best_site=site;
-    }
-  }
-  _vec[0]=(_vec[0]<<1)+OC_SQUARE_DX[best_site];
-  _vec[1]=(_vec[1]<<1)+OC_SQUARE_DY[best_site];
-  return _best_err;
-}
-
-/*Perform a motion vector search for this macro block against a single
-   reference frame.
-  As a bonus, individual block motion vectors are computed as well, as much of
-   the work can be shared.
-  The actual motion vector is stored in the appropriate place in the
-   oc_mb_enc_info structure.
-  _mcenc:    The motion compensation context.
-  _mbi:      The macro block index.
-  _frame:    The frame to search, either OC_FRAME_PREV or OC_FRAME_GOLD.
-  _bmvs:     Returns the individual block motion vectors.
-  _error:    Returns the prediction error for the macro block motion vector.
-  _error4mv: Returns sum of the prediction error for the individual block
-              motion vectors.*/
-static void oc_mcenc_search(oc_mcenc_ctx *_mcenc,int _mbi,int _frame,
- char _bmvs[4][2],int *_error,int *_error4mv){
-  oc_mb_enc_info *embs;
-  oc_mb_enc_info *emb;
-  oc_mb          *mb;
-  ogg_int32_t     hit_cache[31];
-  ogg_int32_t     hitbit;
-  int             block_err[4];
-  int             best_block_err[4];
-  int             best_block_vec[4][2];
-  int             best_vec[2];
-  int             best_err;
-  int             candx;
-  int             candy;
-  int             ref_framei;
-  int             bi;
-  /*TODO: customize error function for speed/(quality+size) tradeoff.*/
-  ref_framei=_mcenc->enc->state.ref_frame_idx[_frame];
-  mb=_mcenc->enc->state.mbs+_mbi;
-  embs=_mcenc->enc->mbinfo;
-  emb=embs+_mbi;
-  /*Find some candidate motion vectors.*/
-  oc_mcenc_find_candidates(_mcenc,_mbi,_frame);
-  /*Clear the cache of locations we've examined.*/
-  memset(hit_cache,0,sizeof(hit_cache));
-  /*Start with the median predictor.*/
-  candx=_mcenc->candidates[0][0];
-  candy=_mcenc->candidates[0][1];
-  hit_cache[candy+15]|=(ogg_int32_t)1<<candx+15;
-  best_err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,candx,candy,
-   ref_framei,block_err);
-  best_vec[0]=candx;
-  best_vec[1]=candy;
-  for(bi=0;bi<4;bi++){
-    best_block_err[bi]=block_err[bi];
-    best_block_vec[bi][0]=candx;
-    best_block_vec[bi][1]=candy;
-  }
-  /*If this predictor fails, move on to set A.*/
-  if(best_err>OC_YSAD_THRESH1){
-    int err;
-    int ci;
-    int ncs;
-    int t2;
-    /*Compute the early termination threshold for set A.*/
-    t2=emb->aerror;
-    ncs=OC_MINI(3,emb->ncneighbors);
-    for(ci=0;ci<ncs;ci++)t2=OC_MAXI(t2,embs[emb->cneighbors[ci]].aerror);
-    t2=t2+(t2>>OC_YSAD_THRESH2_SCALE_BITS)+OC_YSAD_THRESH2_OFFSET;
-    /*Examine the candidates in set A.*/
-    for(ci=1;ci<_mcenc->setb0;ci++){
-      candx=_mcenc->candidates[ci][0];
-      candy=_mcenc->candidates[ci][1];
-      /*If we've already examined this vector, then we would be using it if it
-         was better than what we are using.*/
-      hitbit=(ogg_int32_t)1<<candx+15;
-      if(hit_cache[candy+15]&hitbit)continue;
-      hit_cache[candy+15]|=hitbit;
-      err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,candx,candy,
-       ref_framei,block_err);
-      if(err<best_err){
-        best_err=err;
-        best_vec[0]=candx;
-        best_vec[1]=candy;
-      }
-      for(bi=0;bi<4;bi++)if(block_err[bi]<best_block_err[bi]){
-        best_block_err[bi]=block_err[bi];
-        best_block_vec[bi][0]=candx;
-        best_block_vec[bi][1]=candy;
-      }
-    }
-    if(best_err>t2){
-      /*Examine the candidates in set B.*/
-      for(;ci<_mcenc->ncandidates;ci++){
-        candx=_mcenc->candidates[ci][0];
-        candy=_mcenc->candidates[ci][1];
-        hitbit=(ogg_int32_t)1<<candx+15;
-        if(hit_cache[candy+15]&hitbit)continue;
-        hit_cache[candy+15]|=hitbit;
-        err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,candx,candy,
-         ref_framei,block_err);
-        if(err<best_err){
-          best_err=err;
-          best_vec[0]=candx;
-          best_vec[1]=candy;
-        }
-        for(bi=0;bi<4;bi++)if(block_err[bi]<best_block_err[bi]){
-          best_block_err[bi]=block_err[bi];
-          best_block_vec[bi][0]=candx;
-          best_block_vec[bi][1]=candy;
-        }
-      }
-      /*Use the same threshold for set B as in set A.*/
-      if(best_err>t2){
-        int best_site;
-        int nsites;
-        int sitei;
-        int site;
-        int b;
-        /*Square pattern search.*/
-        for(;;){
-          best_site=4;
-          /*Compose the bit flags for boundary conditions.*/
-          b=OC_DIV16(-best_vec[0]+1)|OC_DIV16(best_vec[0]+1)<<1|
-           OC_DIV16(-best_vec[1]+1)<<2|OC_DIV16(best_vec[1]+1)<<3;
-          nsites=OC_SQUARE_NSITES[b];
-          for(sitei=0;sitei<nsites;sitei++){
-            site=OC_SQUARE_SITES[b][sitei];
-            candx=best_vec[0]+OC_SQUARE_DX[site];
-            candy=best_vec[1]+OC_SQUARE_DY[site];
-            hitbit=(ogg_int32_t)1<<candx+15;
-            if(hit_cache[candy+15]&hitbit)continue;
-            hit_cache[candy+15]|=hitbit;
-            err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,
-             candx,candy,ref_framei,block_err);
-            if(err<best_err){
-              best_err=err;
-              best_site=site;
-            }
-            for(bi=0;bi<4;bi++)if(block_err[bi]<best_block_err[bi]){
-              best_block_err[bi]=block_err[bi];
-              best_block_vec[bi][0]=candx;
-              best_block_vec[bi][1]=candy;
-            }
-          }
-          if(best_site==4)break;
-          best_vec[0]+=OC_SQUARE_DX[best_site];
-          best_vec[1]+=OC_SQUARE_DY[best_site];
-        }
-        /*Final 4-MV search.*/
-        /*Simply use 1/4 of the macro block set A and B threshold as the
-           individual block threshold.*/
-        t2>>=2;
-        for(bi=0;bi<4;bi++)if(best_block_err[bi]>t2){
-          /*Square pattern search.
-            We do this in a slightly interesting manner.
-            We continue to check the SAD of all four blocks in the macro
-             block.
-            This gives us two things:
-             1) We can continue to use the hit_cache to avoid duplicate
-                 checks.
-                Otherwise we could continue to read it, but not write to it
-                 without saving and restoring it for each block.
-                Note that we could still eliminate a large number of
-                 duplicate checks by taking into account the site we came
-                 from when choosing the site list.
-                We can still do that to avoid extra hit_cache queries, and it
-                 might even be a speed win.
-             2) It gives us a slightly better chance of escaping local minima.
-                We would not be here if we weren't doing a fairly bad job in
-                 finding a good vector, and checking these vectors can save us
-                 from 100 to several thousand points off our SAD 1 in 15
-                 times.
-            TODO: Is this a good idea?
-            Who knows.
-            It needs more testing.*/
-          for(;;){
-            int bestx;
-            int besty;
-            int bj;
-            bestx=best_block_vec[bi][0];
-            besty=best_block_vec[bi][1];
-            /*Compose the bit flags for boundary conditions.*/
-            b=OC_DIV16(-bestx+1)|OC_DIV16(bestx+1)<<1|
-             OC_DIV16(-besty+1)<<2|OC_DIV16(besty+1)<<3;
-            nsites=OC_SQUARE_NSITES[b];
-            for(sitei=0;sitei<nsites;sitei++){
-              site=OC_SQUARE_SITES[b][sitei];
-              candx=bestx+OC_SQUARE_DX[site];
-              candy=besty+OC_SQUARE_DY[site];
-              hitbit=(ogg_int32_t)1<<candx+15;
-              if(hit_cache[candy+15]&hitbit)continue;
-              hit_cache[candy+15]|=hitbit;
-              err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,
-               candx,candy,ref_framei,block_err);
-              if(err<best_err){
-                best_err=err;
-                best_vec[0]=candx;
-                best_vec[1]=candy;
-              }
-              for(bj=0;bj<4;bj++)if(block_err[bj]<best_block_err[bj]){
-                best_block_err[bj]=block_err[bj];
-                best_block_vec[bj][0]=candx;
-                best_block_vec[bj][1]=candy;
-              }
-            }
-            if(best_block_vec[bi][0]==bestx&&best_block_vec[bi][1]==besty){
-              break;
-            }
-          }
-        }
-      }
-    }
-  }
-  *_error=oc_mcenc_ysad_halfpel_mbrefine(_mcenc,_mbi,best_vec,best_err,
-   ref_framei);
-  emb->mvs[0][_frame][0]=(char)best_vec[0];
-  emb->mvs[0][_frame][1]=(char)best_vec[1];
-  *_error4mv=0;
-  for(bi=0;bi<4;bi++){
-    (*_error4mv)+=oc_mcenc_ysad_halfpel_brefine(_mcenc,_mbi,bi,
-     best_block_vec[bi],best_block_err[bi],ref_framei);
-    _bmvs[bi][0]=(char)best_block_vec[bi][0];
-    _bmvs[bi][1]=(char)best_block_vec[bi][1];
-  }
-}
-
-/*Perform a motion vector search for this macro block against a single
-   reference frame.
-  The actual motion vector is stored in the appropriate place in the
-   oc_mb_enc_info structure.
-  This is like the above oc_mcenc_search() routine, except that block-level
-   motion vectors are not computed.
-  _mcenc:    The motion compensation context.
-  _mbi:      The macro block index.
-  _frame:    The frame to search, either OC_FRAME_PREV or OC_FRAME_GOLD.
-  Returns: The prediction error for the macro block motion vector.*/
-int oc_mcenc_search_1mv(oc_mcenc_ctx *_mcenc,int _mbi,int _frame){
-  oc_mb_enc_info *embs;
-  oc_mb_enc_info *emb;
-  oc_mb          *mb;
-  ogg_int32_t     hit_cache[31];
-  ogg_int32_t     hitbit;
-  int             block_err[4];
-  int             best_vec[2];
-  int             best_err;
-  int             candx;
-  int             candy;
-  int             ref_framei;
-  /*TODO: customize error function for speed/(quality+size) tradeoff.*/
-  ref_framei=_mcenc->enc->state.ref_frame_idx[_frame];
-  mb=_mcenc->enc->state.mbs+_mbi;
-  embs=_mcenc->enc->mbinfo;
-  emb=embs+_mbi;
-  /*Find some candidate motion vectors.*/
-  oc_mcenc_find_candidates(_mcenc,_mbi,_frame);
-  /*Clear the cache of locations we've examined.*/
-  memset(hit_cache,0,sizeof(hit_cache));
-  /*Start with the median predictor.*/
-  candx=_mcenc->candidates[0][0];
-  candy=_mcenc->candidates[0][1];
-  hit_cache[candy+15]|=(ogg_int32_t)1<<candx+15;
-  best_err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,candx,candy,
-   ref_framei,block_err);
-  best_vec[0]=candx;
-  best_vec[1]=candy;
-  /*If this predictor fails, move on to set A.*/
-  if(best_err>OC_YSAD_THRESH1){
-    int err;
-    int ci;
-    int ncs;
-    int t2;
-    /*Compute the early termination threshold for set A.*/
-    t2=emb->aerror;
-    ncs=OC_MINI(3,emb->ncneighbors);
-    for(ci=0;ci<ncs;ci++)t2=OC_MAXI(t2,embs[emb->cneighbors[ci]].aerror);
-    t2=t2+(t2>>OC_YSAD_THRESH2_SCALE_BITS)+OC_YSAD_THRESH2_OFFSET;
-    /*Examine the candidates in set A.*/
-    for(ci=1;ci<_mcenc->setb0;ci++){
-      candx=_mcenc->candidates[ci][0];
-      candy=_mcenc->candidates[ci][1];
-      /*If we've already examined this vector, then we would be using it if it
-         was better than what we are using.*/
-      hitbit=(ogg_int32_t)1<<candx+15;
-      if(hit_cache[candy+15]&hitbit)continue;
-      hit_cache[candy+15]|=hitbit;
-      err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,candx,candy,
-       ref_framei,block_err);
-      if(err<best_err){
-        best_err=err;
-        best_vec[0]=candx;
-        best_vec[1]=candy;
-      }
-    }
-    if(best_err>t2){
-      /*Examine the candidates in set B.*/
-      for(;ci<_mcenc->ncandidates;ci++){
-        candx=_mcenc->candidates[ci][0];
-        candy=_mcenc->candidates[ci][1];
-        hitbit=(ogg_int32_t)1<<candx+15;
-        if(hit_cache[candy+15]&hitbit)continue;
-        hit_cache[candy+15]|=hitbit;
-        err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,candx,candy,
-         ref_framei,block_err);
-        if(err<best_err){
-          best_err=err;
-          best_vec[0]=candx;
-          best_vec[1]=candy;
-        }
-      }
-      /*Use the same threshold for set B as in set A.*/
-      if(best_err>t2){
-        int best_site;
-        int nsites;
-        int sitei;
-        int site;
-        int b;
-        /*Square pattern search.*/
-        for(;;){
-          best_site=4;
-          /*Compose the bit flags for boundary conditions.*/
-          b=OC_DIV16(-best_vec[0]+1)|OC_DIV16(best_vec[0]+1)<<1|
-           OC_DIV16(-best_vec[1]+1)<<2|OC_DIV16(best_vec[1]+1)<<3;
-          nsites=OC_SQUARE_NSITES[b];
-          for(sitei=0;sitei<nsites;sitei++){
-            site=OC_SQUARE_SITES[b][sitei];
-            candx=best_vec[0]+OC_SQUARE_DX[site];
-            candy=best_vec[1]+OC_SQUARE_DY[site];
-            hitbit=(ogg_int32_t)1<<candx+15;
-            if(hit_cache[candy+15]&hitbit)continue;
-            hit_cache[candy+15]|=hitbit;
-            err=oc_mcenc_ysad_check_mbcandidate_fullpel(_mcenc,_mbi,
-             candx,candy,ref_framei,block_err);
-            if(err<best_err){
-              best_err=err;
-              best_site=site;
-            }
-          }
-          if(best_site==4)break;
-          best_vec[0]+=OC_SQUARE_DX[best_site];
-          best_vec[1]+=OC_SQUARE_DY[best_site];
-        }
-      }
-    }
-  }
-  best_err=oc_mcenc_ysad_halfpel_mbrefine(_mcenc,_mbi,best_vec,best_err,
-   ref_framei);
-  emb->mvs[0][_frame][0]=(char)best_vec[0];
-  emb->mvs[0][_frame][1]=(char)best_vec[1];
-  return best_err;
-}
-
-/*A pipe to perform a motion vector search for each macro block.*/
-
-static int oc_mcenc_pipe_start(oc_enc_pipe_stage *_stage){
-  oc_enc_ctx  *enc;
-  ogg_int64_t  nframes;
-  int          pli;
-  int          mbi;
-  for(pli=0;pli<3;pli++)_stage->y_procd[pli]=0;
-  /*Move the motion vector predictors back a frame.
-    We could pipeline this, too, but it's probably not worth it.*/
-  enc=_stage->enc;
-  for(mbi=enc->state.fplanes[0].nsbs<<2;mbi-->0;){
-    oc_mb_enc_info *emb;
-    emb=enc->mbinfo+mbi;
-    memmove(emb->mvs+1,emb->mvs,2*sizeof(emb->mvs[0]));
-  }
-  /*Set up the accelerated MV weights for previous frame prediction.*/
-  enc->mcenc->mvapw1[OC_FRAME_PREV]=(ogg_int32_t)1<<17;
-  enc->mcenc->mvapw2[OC_FRAME_PREV]=(ogg_int32_t)1<<16;
-  /*Set up the accelerated MV weights for golden frame prediction.*/
-  nframes=enc->state.curframe_num-enc->state.keyframe_num;
-  enc->mcenc->mvapw1[OC_FRAME_GOLD]=(ogg_int32_t)(
-   nframes!=1?(nframes<<17)/(nframes-1):0);
-  enc->mcenc->mvapw2[OC_FRAME_GOLD]=(ogg_int32_t)(
-   nframes!=2?(nframes<<16)/(nframes-2):0);
-  return _stage->next!=NULL?(*_stage->next->pipe_start)(_stage->next):0;
-}
-
-static int oc_mcenc_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  oc_mcenc_ctx   *mcenc;
-  int             pli;
-  mcenc=_stage->enc->mcenc;
-  /*For now we ignore the chroma planes.*/
-  for(pli=1;pli<3;pli++)_stage->y_procd[pli]=_y_avail[pli];
-  /*Only do motion analysis if there is a previous frame; otherwise every
-     vector has already been initialized to (0,0).*/
-  if(mcenc->enc->state.ref_frame_idx[OC_FRAME_PREV]>=0){
-    int             y_avail;
-    y_avail=_y_avail[0];
-    /*Round to a super-block row, except for the last one, which may be
-       incomplete.*/
-    if(y_avail<(int)mcenc->enc->state.info.frame_height)y_avail&=~31;
-    while(_stage->y_procd[0]<y_avail){
-      oc_mb_enc_info *embs;
-      oc_mb          *mbs;
-      int             mbi;
-      int             mbi_end;
-      mbi=(_stage->y_procd[0]>>4)*mcenc->enc->state.fplanes[0].nhsbs;
-      mbi_end=mbi+mcenc->enc->state.fplanes[0].nhsbs<<1;
-      mbs=mcenc->enc->state.mbs;
-      embs=mcenc->enc->mbinfo;
-      for(;mbi<mbi_end;mbi++)if(mbs[mbi].mode!=OC_MODE_INVALID){
-        oc_mb_enc_info *emb;
-        emb=embs+mbi;
-        oc_mcenc_search(mcenc,mbi,OC_FRAME_PREV,emb->bmvs,&emb->aerror,
-         &emb->aerror4mv);
-      }
-      /*Chain to the next stage.*/
-      _stage->y_procd[0]=OC_MINI(_stage->y_procd[0]+32,y_avail);
-      if(_stage->next!=NULL){
-        int ret;
-        ret=_stage->next->pipe_proc(_stage->next,_stage->y_procd);
-        if(ret<0)return ret;
-      }
-    }
-  }
-  else{
-    _stage->y_procd[0]=_y_avail[0];
-    if(_stage->next!=NULL){
-      return _stage->next->pipe_proc(_stage->next,_stage->y_procd);
-    }
-  }
-  return 0;
-}
-
-static int oc_mcenc_pipe_end(oc_enc_pipe_stage *_stage){
-  return _stage->next!=NULL?(*_stage->next->pipe_end)(_stage->next):0;
-}
-
-/*Initialize the motion vector search stage of the pipeline.
-  _enc: The encoding context.*/
-static void oc_mcenc_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_mcenc_pipe_start;
-  _stage->pipe_proc=oc_mcenc_pipe_process;
-  _stage->pipe_end=oc_mcenc_pipe_end;
-}
-
-oc_mcenc_ctx *oc_mcenc_alloc(oc_enc_ctx *_enc){
-  oc_mcenc_ctx *mcenc;
-  mcenc=_ogg_calloc(1,sizeof(*mcenc));
-  mcenc->enc=_enc;
-  oc_mcenc_pipe_init(&mcenc->pipe,_enc);
-  return mcenc;
-}
-
-void oc_mcenc_free(oc_mcenc_ctx *_mcenc){
-  _ogg_free(_mcenc);
-}
-
-oc_enc_pipe_stage *oc_mcenc_prepend_to_pipe(oc_mcenc_ctx *_mcenc,
- oc_enc_pipe_stage *_next){
-  _mcenc->pipe.next=_next;
-  return &_mcenc->pipe;
-}

Deleted: experimental/j/theora-mashup/lib/dec/psych.c
===================================================================
--- experimental/j/theora-mashup/lib/dec/psych.c	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/psych.c	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,2740 +0,0 @@
-#include <float.h>
-#include <math.h>
-#include <string.h>
-#include "psych.h"
-
-/*This is where we attempt to model low-level vision processes, such as
-   sensitivities due to the way human eyes are constructed and how data flows
-   through the early stages of the vision system.
-  Most of the material here is derived from Marcus Nadenau's Ph.D. thesis,
-   though also draws on some earlier work by Scott Daly et al. \cite{Nad00,
-   DZL+00}.
-  Nadenau's thesis dealt almost exclusively with wavelet-based still image
-   codecs since it was targeted at JPEG 2000, but many of the results in it
-   can be generalized to any subband codec with a little work.
-  This is, in fact, one of the reasons it was chosen as a starting point.
-  It has the advantages that the algorithms described in it are fairly simple,
-   computationally efficient, and have shown definite performance increases.
-
-  Still, the results mainly apply to still image codecs.
-  There is plenty of room for improvement by considering temporal sensitivity,
-   temporal masking and other effects of dynamic images that we have not
-   considered \cite{Lam96}.
-  The techniques described in the cited reference requires at least a three
-   frame delay, and considerable computational overhead, however.
-
-  We also extend Nadenau's contrast sensitivity function measurements to the
-   supra-threshold levels video codecs typically operate at by using the
-   exponential model proposed by Mark Cannon Jr. \cite{Can85}.
-  This area of the literature is in general fairly thin, but his model has
-   the good properties of simplicity and a lack of magic constants.
-  When adapting from Michelson contrast to our simple model, the CSF never
-   reaches the flat curve predicted by contrast constancy in the useful range
-   of contrast levels.
-  However, recent research suggests that uniform quantization does not yield
-   optimal perceptual results at contrast levels far above threshold, although
-   the model they propose to account for this is both complicated, contains
-   many magic constants, and is not robust to varying display parameters
-   \cite{CH03}.
-
-  @ARTICLE{Can85,
-    author="Mark W. Cannon, Jr.",
-    title="Perceived contrast in the fovea and periphery",
-    journal="Journal of the Optical Society of America A",
-    volume=2,
-    number=10,
-    pages="1760--1758",
-    month="Oct.",
-    year=1985
-  }
-
-  @INPROCEEDINGS{CH03,
-    author="Damon M. Chandler and Sheila S. Hemami",
-    title="Suprathreshold image compression based on contrast allocation and
-     global precedence",
-    booktitle="Proc. Human Vision and Electronic Imaging 2003",
-    address="Santa Clara, CA",
-    month="Jan.",
-    year=2003,
-    URL="http://citeseer.nj.nec.com/579192.html"
-  }
-
-  @INPROCEEDINGS{DZL+00,
-    author="Scott Daly and Wenjun Zeng and Jin Li and Shawmin Lei",
-    title="Visual masking in wavelet compression for JPEG2000",
-    booktitle="Proceedings of the {SPIE/IS&T} Electronic Imaging: Image and
-     Video Communications and Processing Conference",
-    address="San Jose",
-    month="Jan.",
-    year=2000,
-    URL="http://www.ee.princeton.edu/~wzeng/EI00_wavelet_masking.zip"
-  }
-
-  @PHDTHESIS{Lam96,
-    author="Christian J. van den Branden Lambrecht",
-    title="Perceptual Models and Architectures for Video Coding Applications",
-    school="\'{E}cole Polytechnique F\'{e}d\'{e}rale de Lausanne",
-    year=1996,
-    URL="http://ltswww.epfl.ch/pub_files/vdb/dissertation/dissertation.pdf.gz"
-  }
-
-  @PHDTHESIS{Nad00,
-    author="Marcus Nadenau",
-    title="Integration of Human Color Visual Models into High
-     Quality Image Compression",
-    school="\'{E}cole Polytechnique F\'{e}d\'{e}rale de Lausanne",
-    year=2000,
-    URL="http://ltswww.epfl.ch/pub_files/nadenau/Thesis_Marcus_LQ.pdf"
-  }
-
-  @ARTICLE{PSY+93,
-    author="E. Peli and L. E. Arend and G. M. Young and R. B. Goldstein",
-    title="Contrast sensitivity to patch stimuli: effects of spatial bandwidth
-     and temporal presentation",
-    journal="Spatial Vision",
-    volume=7,
-    number=1,
-    pages="1--15",
-    year=1993
-  }
-
-  @INPROCEEDINGS{TS96,
-    author="Trac D. Tran and Robert Safranek",
-    title="A Locally Adaptive Perceptual Masking Threshold Model for Image
-     Coding",
-    booktitle="Proceedings of the {IEEE} Conference on Acoustics, Speech, and
-     Signal Processing",
-    address="Atlanta",
-    volume=4,
-    pages="1882--1885",
-    month="May",
-    year=1996,
-    URL="http://citeseer.nj.nec.com/tran96locally.html"
-  }
-  
-  @ARTICLE{WYS+97,
-    author="A. B. Watson and G. Y. Yang and J. A. Solomon and J. Villasenor",
-    title="Visibility of wavelet quantization noise",
-    journal="{IEEE} Transactions on Image Processing",
-    volume=6,
-    pages="1164--1175",
-    year=1997,
-    URL="http://citeseer.nj.nec.com/watson97visibility.html"
-  }*/
-
-/*All CSF curves are scaled so that their peak is at 1.0, but JND
-   values are computed at frequency 0, which is not the peak of the
-   Y curve.
-  This is 1/CSF_Y(0), which scales the frequency 0 value to 1.0
-   like the other curves.
-
-  The question is, should this even be used?
-  In Nadenau's earlier work, he used an arbitrary constant of 2 to scale Y
-   channel sensitivity.
-  In his later work, he forces the CSF curve to its maximum for every
-   frequency below the frequency it achives that maximum at.
-
-  For chroma curves, the maximum is at frequency 0, but for the luma curve,
-   it is not.
-  The idea is that as one moves farther away, one can increase the frequencies
-   in the image.
-  Thus, distortions classified as "invisible" by the CSF curve for one
-   distance might become visible from a farther distance.
-  Forcing the curve to its maximum for low frequencies solves this problem.
-
-  So now, either one can use the modified CSF curve, which has a value of 1.0
-   at frequency 0, or one can scale it by the value given below, which causes
-   its frequency 0 values to be over 20 times more important (since the filter
-   is run in both the horizontal and vertical directions).
-  Nadenau chose the former, with no justification, and this may likely be the
-   better choice.
-  His methods are at least tested and confirmed to give up to 29% bitrate
-   reductions for visually-lossless still image compression.
-  Other weight towards the former comes from measurements that show contrast
-   sensitivity of unmasked 1-octave Gabor patches is low-pass, not band-pass
-   \cite{PAY+93}, and that wavelet quantization sensitivity behaves similarly
-   \cite{WYS+97}.*/
-#define OC_YAMP (4.52514935207592383F)
-
-const float OC_YCbCr_SCALE[3][3]={
-  /*Unspecified.*/
-  {
-    0.62660577006129702908501F,
-    1.33082085846485050021660F,1.08759046924374083944404F
-    /*JND values:
-    1.59589976310332425729864F,
-    0.75141593523980064237395F,0.91946373959616699828994F
-    */
-  },
-  /*ITU-R BT Rec 470-6 System M.*/
-  {
-    0.58002163837392672895987F,
-    1.34159010104556952747146F,1.18947262510486906350593F
-    /*JND values:
-    1.72407361008715120931356F,
-    0.74538415214948960940688F,0.84070871316759865354840F
-    */
-  },
-  /*ITU-R BT Rec 470-6 Systems B,G.*/
-  {
-    0.67693128169295702090125F,
-    1.32013806299317915105007F,0.99443484770028645058915F
-    /*JND values:
-    1.47725482193564916499895F,
-    0.75749652860752847427506F,1.00559629654228577244623F
-    */
-  }
-};
-
-/*The maximum number of coefficients in a CSF filter.
-  All CSF filters are symmetric, so the real filter size is
-   OC_CSF_FILTER_SZ_MAX*2-1.*/
-#define OC_CSF_FILTER_SZ_MAX (4)
-
-/*A CSF filter.
-  CSF filters are symmetric, so only coefficients in one direction are
-   stored.*/
-typedef float oc_csf_filter[OC_CSF_FILTER_SZ_MAX];
-/*A set of CSF filters, one for each DCT coefficient.
-  CSF filters are separable, so only filters for the coefficients in one
-   dimension are stored.*/
-typedef oc_csf_filter oc_csf_filter_bank[8];
-
-/*Filter coefficients for the contrast sensitivity function.
-  There is a different filter set for each color channel, with both decimated
-   and undecimated versions for the chroma channels, and for 8 different
-    contrast levels.
-  These were generated with the measurements given in Chapter 5 of Nadenau's
-   thesis and using a modified version of the method described therein.
-  Instead of assuming an ideal frequency response with finite support, the
-   actual frequency response of the DCT filter is used to weight the portions
-   of the CSF that contribute to the importance of each coefficient.
-  Sensitivity at different levels of contrast is modeled as 1/(C-T)^\alpha,
-   where T is the threshold contrast level and \alpha is fixed at 0.5
-   \cite{Can85}.
-  Thus, as C increases, the curves approach constant contrast sensitivity.
-  See the Mathematica notebook in doc/theory/psych.nb and the code to generate
-   the tables in tools/csfgen.c for more details.
-
-  The fitlers are stored in this order: Y filters, full resolution Cr filters,
-   half resolution Cr filters, full resolution Cb filters, half resolution Cb
-   filters.*/
-static const oc_csf_filter_bank OC_CSF_FILTERS[5][8]={
-  /*Y channel filters.*/
-  {
-    /*Contrast level 0 filters.*/
-    {
-      {
-        +0.4974979156295645799090721F,+0.0012404707975748668555283F,
-        +0.0000080106551093210126942F,+0.0000016274187019290664437F
-      },
-      {
-        +0.4946513130812318914664161F,-0.0027037537913987231760760F,
-        -0.0000330471695690925902091F,-0.0000000906623724571996728F
-      },
-      {
-        +0.4938944467506038438209259F,+0.0030361290189818454336723F,
-        +0.0000114829773190052630345F,+0.0000031200579746008261025F
-      },
-      {
-        +0.4918574148437053206173175F,-0.0040659281073912763304623F,
-        +0.0000091342174863448405024F,+0.0000114285638008321142813F
-      },
-      {
-        +0.4849051006583633416369139F,+0.0074388198444532149800068F,
-        +0.0000588189223675330443548F,+0.0000151937943563432782852F
-      },
-      {
-        +0.4599362228688526066378017F,-0.0096332351312863901543482F,
-        -0.0001957936409766333567782F,-0.0000309739095527862133865F
-      },
-      {
-        +0.4171873318721850965040687F,+0.0075634147110850502918056F,
-        +0.0001406246499985776136129F,+0.0000245145898043081554107F
-      },
-      {
-        +0.3622492868463687010205376F,-0.0079619663638459698545846F,
-        -0.0011862532832578940970858F,-0.0004590931594731116269226F
-      }
-    },
-    /*Contrast level 1 filters.*/
-    {
-      {
-        +0.4985952211684308021943934F,+0.0006929968245834339539077F,
-        +0.0000073638012374395989327F,+0.0000013053828352005946804F
-      },
-      {
-        +0.4969616832351805846279547F,-0.0015468288080826119845063F,
-        -0.0000323471848981306134632F,-0.0000036473783112434650109F
-      },
-      {
-        +0.4965804229791817014927346F,+0.0016918596532595941896865F,
-        +0.0000135821463075017275781F,+0.0000027067370702343916607F
-      },
-      {
-        +0.4954015481252519448318594F,-0.0023145025955579063420275F,
-        -0.0000174013355874229034041F,+0.0000006393132048949258850F
-      },
-      {
-        +0.4917459840700729167828342F,+0.0040576527603305642677434F,
-        +0.0000415233172946356360019F,+0.0000094869260538222692232F
-      },
-      {
-        +0.4782417493570770838928752F,-0.0056026658195043634036470F,
-        -0.0001439184882724861233062F,-0.0000273935419950798459267F
-      },
-      {
-        +0.4540145745199611893028191F,+0.0048131669800966069699966F,
-        +0.0001039464112021163945355F,+0.0000182154037458178904034F
-      },
-      {
-        +0.4193616606144400793532157F,-0.0057237897506124645052861F,
-        -0.0008902510390405555086926F,-0.0003484643316722941109968F
-      }
-    },
-    /*Contrast level 2 filters.*/
-    {
-      {
-        +0.4993917553220076910314162F,+0.0002987792675789140432914F,
-        +0.0000042348429586058825263F,+0.0000007166109631133404283F
-      },
-      {
-        +0.4986711203344355025635082F,-0.0006806350200641122279860F,
-        -0.0000192753655634024158728F,-0.0000030386631529038878887F
-      },
-      {
-        +0.4985217616090412140472665F,+0.0007282459524106939079136F,
-        +0.0000084356735629882367231F,+0.0000015356572007092566149F
-      },
-      {
-        +0.4979969696822242886113941F,-0.0010147057124000465836572F,
-        -0.0000157298955555893672418F,-0.0000019577424496730524289F
-      },
-      {
-        +0.4964880417208658025529644F,+0.0017223189322020380272876F,
-        +0.0000213607135587729943769F,+0.0000045470742845642022351F
-      },
-      {
-        +0.4907852358193834363397912F,-0.0024832427159493979454408F,
-        -0.0000761508774030194012265F,-0.0000160598837680240097360F
-      },
-      {
-        +0.4802673087213260028072170F,+0.0022507695093204210280702F,
-        +0.0000547813876165770423702F,+0.0000096506977823251094439F
-      },
-      {
-        +0.4640144269579485336585378F,-0.0029380893686057701040537F,
-        -0.0004747406413986356718895F,-0.0001873528096329502869426F
-      }
-    },
-    /*Contrast level 4 filters.*/
-    {
-      {
-        +0.4998137274648045136338226F,+0.0000912696159462314342541F,
-        +0.0000014843787227076340130F,+0.0000002476038959338043932F
-      },
-      {
-        +0.4995905931066523808503632F,-0.0002104358660185189956477F,
-        -0.0000068762206074010203557F,-0.0000012099908446087239219F
-      },
-      {
-        +0.4995476579004028971908724F,+0.0002222846485656745560682F,
-        +0.0000030368461003509543638F,+0.0000005374256197622947177F
-      },
-      {
-        +0.4993842047634874381500936F,-0.0003131139985448601423951F,
-        -0.0000062949398654856223578F,-0.0000010179627295714944439F
-      },
-      {
-        +0.4989338104957108388504139F,+0.0005220844404367886272891F,
-        +0.0000071708090595083798122F,+0.0000014802646157887906511F
-      },
-      {
-        +0.4972087446540453536947268F,-0.0007696923273746066876053F,
-        -0.0000259513187718355942373F,-0.0000057346607886135720063F
-      },
-      {
-        +0.4939873062181578955431860F,+0.0007149727748709724245435F,
-        +0.0000185889993986410929395F,+0.0000032872263385569140901F
-      },
-      {
-        +0.4888015084144361477314078F,-0.0009818722410188439417983F,
-        -0.0001622454979429055661484F,-0.0000643148365864906962960F
-      }
-    },
-    /*Contrast level 8 filters.*/
-    {
-      {
-        +0.4999506506251316095834625F,+0.0000241593584209429973638F,
-        +0.0000004101192692365366679F,+0.0000000681748460570138379F
-      },
-      {
-        +0.4998913134190874352213996F,-0.0000559322844779620533722F,
-        -0.0000019105677112889524220F,-0.0000003464926297259606339F
-      },
-      {
-        +0.4998801908401898641542971F,+0.0000588248802183322815800F,
-        +0.0000008451931104155585646F,+0.0000001485113546988487278F
-      },
-      {
-        +0.4998366341415675928594453F,-0.0000831709695403873376087F,
-        -0.0000018013774219368567310F,-0.0000003081909154259488803F
-      },
-      {
-        +0.4997183096241975541751401F,+0.0001378632096540683619861F,
-        +0.0000019571651197377926674F,+0.0000004004136670677446209F
-      },
-      {
-        +0.4992630422329858985719397F,-0.0002047091578843848139625F,
-        -0.0000071181198253395804878F,-0.0000015954913789402466708F
-      },
-      {
-        +0.4984097096395556647507874F,+0.0001915690820724511792949F,
-        +0.0000050901402230419786208F,+0.0000009014031698120338827F
-      },
-      {
-        +0.4970176720677992321384409F,-0.0002674975577999730985690F,
-        -0.0000445377789255487871152F,-0.0000176810302770080758519F
-      }
-    },
-    /*Contrast level 16 filters.*/
-    {
-      {
-        +0.4999874755326983444270184F,+0.0000061300062681946914151F,
-        +0.0000001052519850200102338F,+0.0000000174816076134240805F
-      },
-      {
-        +0.4999724008191679947010755F,-0.0000142077480328958145281F,
-        -0.0000004910655416519663291F,-0.0000000897496156494382389F
-      },
-      {
-        +0.4999695954662750074781741F,+0.0000149247812929188784174F,
-        +0.0000002173130495546358248F,+0.0000000381174217736460805F
-      },
-      {
-        +0.4999585234855704052314707F,-0.0000211232580046656607154F,
-        -0.0000004664454746007790730F,-0.0000000809013500389663776F
-      },
-      {
-        +0.4999285617392343894493933F,+0.0000349577910372148478973F,
-        +0.0000005007013859360666698F,+0.0000001021999933913723439F
-      },
-      {
-        +0.4998131366671812458868374F,-0.0000520077885699183199470F,
-        -0.0000018234627141940781669F,-0.0000004102587958020365375F
-      },
-      {
-        +0.4995965797576074618469022F,+0.0000487642150325281225807F,
-        +0.0000013033288646874188726F,+0.0000002308959439591987542F
-      },
-      {
-        +0.4992420472953436605401123F,-0.0000683984570725664186566F,
-        -0.0000114117223943732663143F,-0.0000045321443743445158429F
-      }
-    },
-    /*Contrast level 32 filters.*/
-    {
-      {
-        +0.4999968569633094217508074F,+0.0000015382431506488678755F,
-        +0.0000000264880574917300026F,+0.0000000043985687513150228F
-      },
-      {
-        +0.4999930729477782831438049F,-0.0000035662676828781185600F,
-        -0.0000001236307688019724448F,-0.0000000226394465865930717F
-      },
-      {
-        +0.4999923700605397036689226F,+0.0000037451117790174111833F,
-        +0.0000000547153501346255138F,+0.0000000095930350228033560F
-      },
-      {
-        +0.4999895903930139939852495F,-0.0000053018917810338624179F,
-        -0.0000001176505431097798597F,-0.0000000204749807057907393F
-      },
-      {
-        +0.4999820757893215783518315F,+0.0000087707540888702817297F,
-        +0.0000001259081133986305178F,+0.0000000256845013920447803F
-      },
-      {
-        +0.4999531171855649547275391F,-0.0000130549165552376623663F,
-        -0.0000004586906133020776115F,-0.0000001032986356249514205F
-      },
-      {
-        +0.4998987726726807356847360F,+0.0000122467480165678056759F,
-        +0.0000003278109523803935838F,+0.0000000580804967483879606F
-      },
-      {
-        +0.4998097224713375918980773F,-0.0000171974173459937233895F,
-        -0.0000028707618790378860885F,-0.0000011402340485875928503F
-      }
-    },
-    /*Contrast level 64 filters.*/
-    {
-      {
-        +0.4999992134922559006149356F,+0.0000003849213285110855801F,
-        +0.0000000066330348569149570F,+0.0000000011014154584515877F
-      },
-      {
-        +0.4999982665248277613478933F,-0.0000008924671924946150712F,
-        -0.0000000309621248576388811F,-0.0000000056725963408933297F
-      },
-      {
-        +0.4999980907061378765376958F,+0.0000009371518088510124054F,
-        +0.0000000137032099503720727F,+0.0000000024022681798146420F
-      },
-      {
-        +0.4999973950557881074985289F,-0.0000013267969813612056625F,
-        -0.0000000294781131806493973F,-0.0000000051344897167296845F
-      },
-      {
-        +0.4999955148884093758532288F,+0.0000021946540386269054541F,
-        +0.0000000315231414668302833F,+0.0000000064295873978643399F
-      },
-      {
-        +0.4999882688124631657800023F,-0.0000032670567003315287756F,
-        -0.0000001148504838286859402F,-0.0000000258708892860719560F
-      },
-      {
-        +0.4999746697933456496265592F,+0.0000030651870298140881922F,
-        +0.0000000820772787340354999F,+0.0000000145425660809524183F
-      },
-      {
-        +0.4999523810248664434929822F,-0.0000043055079282289645130F,
-        -0.0000007188129863325958459F,-0.0000002855116819385006770F
-      }
-    }
-  },
-  /*Cr channel filters at full resolution.*/
-  {
-    /*Contrast level 0 filters.*/
-    {
-      {
-        +0.4466131034990036274834324F,+0.0204563871591344446920768F,
-        +0.0023939221213980293664902F,+0.0010480976513234819148118F
-      },
-      {
-        +0.3943525077511645382521976F,-0.0194312007508983461412377F,
-        -0.0002991392322740196491222F,-0.0000418658386670598238813F
-      },
-      {
-        +0.3602165550759829359961373F,+0.0109843676819592721283225F,
-        +0.0000340732083994970040108F,+0.0000034293744517165677533F
-      },
-      {
-        +0.3253604730307345649364947F,-0.0073474567266921218811060F,
-        -0.0000246081815279124990021F,+0.0000065726960631269384670F
-      },
-      {
-        +0.2935508632220520941480402F,+0.0050435024480460057330622F,
-        +0.0000197913611940059728437F,+0.0000029381559238051280840F
-      },
-      {
-        +0.2645790141301814224483735F,-0.0037929500982503520922773F,
-        -0.0000559497045800741237779F,-0.0000043288231670403312955F
-      },
-      {
-        +0.2388636589566937307171912F,+0.0026599487397785887346502F,
-        +0.0000499974651329198401147F,+0.0000088670737686502255963F
-      },
-      {
-        +0.2147883058975149639380220F,-0.0028258396905114393886371F,
-        -0.0004288976310994812375828F,-0.0001640767602695969852415F
-      }
-    },
-    /*Contrast level 1 filters.*/
-    {
-      {
-        +0.4698578102368252129572568F,+0.0119304558868460457848881F,
-        +0.0012115903786694226604986F,+0.0005277168711196883335926F
-      },
-      {
-        +0.4386269582433506841745441F,-0.0127862923907847078619504F,
-        -0.0001602430214692817463020F,-0.0000195722569996841122715F
-      },
-      {
-        +0.4169960531871078068810732F,+0.0081127134615084986468680F,
-        +0.0000232588063957524358741F,+0.0000026208146395139378962F
-      },
-      {
-        +0.3929024115992683086062698F,-0.0059554576317657707124065F,
-        -0.0000245114024840928133940F,+0.0000039573448279499121711F
-      },
-      {
-        +0.3689847372054864682588970F,+0.0044170269151178791558476F,
-        +0.0000194609155260757375413F,+0.0000029628609638351198479F
-      },
-      {
-        +0.3453540773032837130074313F,-0.0035679797526732407765560F,
-        -0.0000594312634054908807977F,-0.0000067749294918672538118F
-      },
-      {
-        +0.3228620127205077405818656F,+0.0026224919234070732595998F,
-        +0.0000512831165659902757066F,+0.0000090980082325552709372F
-      },
-      {
-        +0.3002502447130425689003630F,-0.0028854418338218387057870F,
-        -0.0004422565606365215572053F,-0.0001703816409394388322815F
-      }
-    },
-    /*Contrast level 2 filters.*/
-    {
-      {
-        +0.4867441391026595121083176F,+0.0053656903788364667534649F,
-        +0.0004887198367536145114307F,+0.0002120418626616244243098F
-      },
-      {
-        +0.4725122075211675154449154F,-0.0062630752460282896471044F,
-        -0.0000705061198436637121510F,-0.0000077503711692285297752F
-      },
-      {
-        +0.4623297540279411310670810F,+0.0043131917627408740065209F,
-        +0.0000131268391170999021992F,+0.0000016229653269626313114F
-      },
-      {
-        +0.4501951498452281263951136F,-0.0034152219551933818246503F,
-        -0.0000184809884634354849799F,+0.0000011277852315615552371F
-      },
-      {
-        +0.4373156975931161150050741F,+0.0027035532940359353892834F,
-        +0.0000139132810869793730032F,+0.0000021444756114345932393F
-      },
-      {
-        +0.4236370538857213152716952F,-0.0023418384173699924657996F,
-        -0.0000448056812193965004051F,-0.0000065017703255079614035F
-      },
-      {
-        +0.4097477895414575188581807F,+0.0018071018217870682756598F,
-        +0.0000373965827200492621210F,+0.0000066363077245494702270F
-      },
-      {
-        +0.3947357774885709158496638F,-0.0020825714057240850458907F,
-        -0.0003240988774238835897455F,-0.0001257375472981652896227F
-      }
-    },
-    /*Contrast level 4 filters.*/
-    {
-      {
-        +0.4958834656421001740866927F,+0.0016859519056663628544523F,
-        +0.0001445025023262314664389F,+0.0000625264961989884367156F
-      },
-      {
-        +0.4913874931139418089642845F,-0.0020593861138210665766290F,
-        -0.0000226092805204661257822F,-0.0000024066196304147228100F
-      },
-      {
-        +0.4881311311493955473750361F,+0.0014797430991360914238203F,
-        +0.0000049264898376419930071F,+0.0000006390190043181814159F
-      },
-      {
-        +0.4840996676637792650588210F,-0.0012237890166467769222786F,
-        -0.0000080407608920541696272F,+0.0000000413046765873424668F
-      },
-      {
-        +0.4796575272601830142171764F,+0.0010058742257652098298082F,
-        +0.0000058176418812422918563F,+0.0000009014941215735951753F
-      },
-      {
-        +0.4747253321574411710770391F,-0.0009118419706028339311379F,
-        -0.0000192799213040731582758F,-0.0000031517690586197395265F
-      },
-      {
-        +0.4695095348185415740083215F,+0.0007269098386637814091654F,
-        +0.0000157577834945070641821F,+0.0000027979576676246618138F
-      },
-      {
-        +0.4635866848505370008126647F,-0.0008690766903331083705411F,
-        -0.0001370659367807853113840F,-0.0000534285631685433790028F
-      }
-    },
-    /*Contrast level 8 filters.*/
-    {
-      {
-        +0.4989032657299813933171606F,+0.0004508885250507135020528F,
-        +0.0000378687776724978810631F,+0.0000163682592366822710517F
-      },
-      {
-        +0.4976990343814432504743195F,-0.0005590362807171194228784F,
-        -0.0000061344011583817215891F,-0.0000006520168673858460086F
-      },
-      {
-        +0.4968242080213455258430599F,+0.0004071780856574246858053F,
-        +0.0000014107694341815653082F,+0.0000001857550935630192576F
-      },
-      {
-        +0.4957271332146040987431945F,-0.0003417502727829278504935F,
-        -0.0000024117320912226457587F,-0.0000000314276727951980480F
-      },
-      {
-        +0.4945032049560656450815088F,+0.0002844597351455135101142F,
-        +0.0000017200658041290622997F,+0.0000002669964635612131963F
-      },
-      {
-        +0.4931229281906876482644009F,-0.0002621175868537459620160F,
-        -0.0000057553609042691053762F,-0.0000009770500636906775946F
-      },
-      {
-        +0.4916422352455450672792381F,+0.0002114292198477351887413F,
-        +0.0000046692051973829650031F,+0.0000008293473603515466290F
-      },
-      {
-        +0.4899298619593880910194628F,-0.0002564751824144358106558F,
-        -0.0000406737915269712537901F,-0.0000158824949035072251569F
-      }
-    },
-    /*Contrast level 16 filters.*/
-    {
-      {
-        +0.4997212087765695032182123F,+0.0001147340276179476589030F,
-        +0.0000095831952674561008592F,+0.0000041409109405756833042F
-      },
-      {
-        +0.4994146572400975925276612F,-0.0001428285422951212522633F,
-        -0.0000015683164162862297173F,-0.0000001668014581580321873F
-      },
-      {
-        +0.4991918010179293707651027F,+0.0001044086068593389111676F,
-        +0.0000003660134475814273868F,+0.0000000483845855363679069F
-      },
-      {
-        +0.4989113465804591029950643F,-0.0000879850330316772930939F,
-        -0.0000006334463649372846156F,-0.0000000113452095602269466F
-      },
-      {
-        +0.4985974113452554257186478F,+0.0000734863291078301071211F,
-        +0.0000004499859565283966385F,+0.0000000698815740383369691F
-      },
-      {
-        +0.4982418489567451147514987F,-0.0000680230325427612738439F,
-        -0.0000015096044607814982171F,-0.0000002588749307410131994F
-      },
-      {
-        +0.4978589080920167719845892F,+0.0000550484870529407562217F,
-        +0.0000012222017366671539300F,+0.0000002171121142022902965F
-      },
-      {
-        +0.4974137753766228464691324F,-0.0000670551786167608278528F,
-        -0.0000106512240094618133071F,-0.0000041611869214930319994F
-      }
-    },
-    /*Contrast level 32 filters.*/
-    {
-      {
-        +0.4999300076157416894417906F,+0.0000288122669341368914885F,
-        +0.0000024031677817380821061F,+0.0000010383274725146474736F
-      },
-      {
-        +0.4998530180929730004635303F,-0.0000359043654502861017967F,
-        -0.0000003943337487483114176F,-0.0000000419502539379778554F
-      },
-      {
-        +0.4997970386241146756312048F,+0.0000262705789622399434827F,
-        +0.0000000923755404781967567F,+0.0000000122237582557993805F
-      },
-      {
-        +0.4997265277821371642907877F,-0.0000221609962758671951073F,
-        -0.0000001603707912619345992F,-0.0000000030715237063176491F
-      },
-      {
-        +0.4996475316876837213797558F,+0.0000185253498948414021315F,
-        +0.0000001138075497721189058F,+0.0000000176761176087779480F
-      },
-      {
-        +0.4995579622322675605872178F,-0.0000171681429803162927475F,
-        -0.0000003820551272206407269F,-0.0000000656852223996049388F
-      },
-      {
-        +0.4994613979826325045330293F,+0.0000139052196437981325422F,
-        +0.0000003091555877587903549F,+0.0000000549200608453141957F
-      },
-      {
-        +0.4993490028543484671175179F,-0.0000169563752736321444613F,
-        -0.0000026945226572072131838F,-0.0000010528212293658266857F
-      }
-    },
-    /*Contrast level 64 filters.*/
-    {
-      {
-        +0.4999824833869556117704747F,+0.0000072111626411971994265F,
-        +0.0000006012544013488351046F,+0.0000002597763464667639583F
-      },
-      {
-        +0.4999632138959408389489170F,-0.0000089885049739711238428F,
-        -0.0000000987257403393744738F,-0.0000000105033892738312263F
-      },
-      {
-        +0.4999492023433999010606499F,+0.0000065782528205756289120F,
-        +0.0000000231490449847509044F,+0.0000000030640136122263519F
-      },
-      {
-        +0.4999315496351057763746439F,-0.0000055506345023664364709F,
-        -0.0000000402199501155586828F,-0.0000000007828676740402504F
-      },
-      {
-        +0.4999117683485769791928988F,+0.0000046410379760095441779F,
-        +0.0000000285348607848787503F,+0.0000000044320502364094861F
-      },
-      {
-        +0.4998893331834736164509536F,-0.0000043022910674822050300F,
-        -0.0000000958084528018879889F,-0.0000000164825877208729088F
-      },
-      {
-        +0.4998651398024888115045883F,+0.0000034853487944542519948F,
-        +0.0000000775170695289236531F,+0.0000000137706518824132828F
-      },
-      {
-        +0.4998369707575275877609045F,-0.0000042512783907376547603F,
-        -0.0000006756382634799853338F,-0.0000002639981667588252647F
-      }
-    }
-  },
-  /*Cr channel filters at half resolution.*/
-  {
-    /*Contrast level 0 filters.*/
-    {
-      {
-        +0.4695167969228932758340989F,+0.0118718351587125559715163F,
-        +0.0012965130664463896288663F,+0.0005662371678254208033285F
-      },
-      {
-        +0.4388143301023016418227485F,-0.0120135532251189214997256F,
-        -0.0001669247254022054969148F,-0.0000219481096099628507248F
-      },
-      {
-        +0.4181505572964309136452243F,+0.0072449968749778402565820F,
-        +0.0000217252708311208960943F,+0.0000023403819777649205360F
-      },
-      {
-        +0.3960235893103195570219555F,-0.0051270782000218707852301F,
-        -0.0000200642852007973282089F,+0.0000037481888840257615307F
-      },
-      {
-        +0.3748260081983196823074422F,+0.0036989182895335159101391F,
-        +0.0000158747291663022933005F,+0.0000023973135012358275899F
-      },
-      {
-        +0.3545217626567973567830450F,-0.0029239324108313942580939F,
-        -0.0000474467413179348193814F,-0.0000050008893046642872881F
-      },
-      {
-        +0.3356529259343632443091110F,+0.0021229471847555411896658F,
-        +0.0000412647623712182482218F,+0.0000073203779275024357106F
-      },
-      {
-        +0.3170744801586446448560253F,-0.0023213902831152118284852F,
-        -0.0003554375191269673302588F,-0.0001367245997123144366468F
-      }
-    },
-    /*Contrast level 1 filters.*/
-    {
-      {
-        +0.4836308306501569953539388F,+0.0064930538147626917083732F,
-        +0.0006526985361209555226714F,+0.0002842083171947500531279F
-      },
-      {
-        +0.4666233971978723804596711F,-0.0070385576201047496402996F,
-        -0.0000879030116116034856023F,-0.0000106718823583842997016F
-      },
-      {
-        +0.4548190941110913376732583F,+0.0045330041876995453425936F,
-        +0.0000134778920865219048995F,+0.0000015573016337061152485F
-      },
-      {
-        +0.4415150653445629180815502F,-0.0033917098317780849069114F,
-        -0.0000155793977831583760774F,+0.0000018471711366006795366F
-      },
-      {
-        +0.4281169344940197185600539F,+0.0025644228947526844994420F,
-        +0.0000120451710117027005194F,+0.0000018410050994371369771F
-      },
-      {
-        +0.4146162746402144438917503F,-0.0021234871914581768606589F,
-        -0.0000375476514876610172836F,-0.0000047810116910102886984F
-      },
-      {
-        +0.4015013744485408375695101F,+0.0015909657431346366836949F,
-        +0.0000319351503243229408835F,+0.0000056665154596238314467F
-      },
-      {
-        +0.3879615599270475057025465F,-0.0017874386453353410721817F,
-        -0.0002760029073079348018067F,-0.0001066589679214394040859F
-      }
-    },
-    /*Contrast level 2 filters.*/
-    {
-      {
-        +0.4931183466763838785240637F,+0.0027624669124665934827334F,
-        +0.0002622722165700911507898F,+0.0001139622500238115544724F
-      },
-      {
-        +0.4858305119870601762599449F,-0.0031335211278896418080064F,
-        -0.0000369976912359326878051F,-0.0000042651976814331478755F
-      },
-      {
-        +0.4806838540421569105909327F,+0.0021071386104229527895526F,
-        +0.0000064701285123968139555F,+0.0000007849955528773996738F
-      },
-      {
-        +0.4746734787500401786530801F,-0.0016403540209556381670314F,
-        -0.0000086974570476210647700F,+0.0000005907910888867568744F
-      },
-      {
-        +0.4684050905393940533727459F,+0.0012829464723505905852929F,
-        +0.0000065451033860091992257F,+0.0000010068727582205162545F
-      },
-      {
-        +0.4618447215616265366655568F,-0.0011019343858519544971514F,
-        -0.0000209715759562448650604F,-0.0000030052012807484980557F
-      },
-      {
-        +0.4552521864732587686397380F,+0.0008468924651249438995126F,
-        +0.0000175319929402584630349F,+0.0000031116120420323132983F
-      },
-      {
-        +0.4481800437012667948089018F,-0.0009756327739151399126502F,
-        -0.0001519317138244341113939F,-0.0000589296900896258015303F
-      }
-    },
-    /*Contrast level 4 filters.*/
-    {
-      {
-        +0.4979230383986483765568209F,+0.0008386946594426612474130F,
-        +0.0000773258988324650365807F,+0.0000335601179077375054286F
-      },
-      {
-        +0.4957033692105178301900992F,-0.0009731912675722631609482F,
-        -0.0000112503692463413741112F,-0.0000012688868966867814525F
-      },
-      {
-        +0.4941240320650327477736141F,+0.0006685765380286866430698F,
-        +0.0000021155999929475169844F,+0.0000002630086767322655800F
-      },
-      {
-        +0.4922455243204088559672016F,-0.0005313457985576951377038F,
-        -0.0000030637002743417027582F,+0.0000001278532581659137263F
-      },
-      {
-        +0.4902507554199150296980747F,+0.0004230034169241665524541F,
-        +0.0000022676475967969978322F,+0.0000003498646273309863166F
-      },
-      {
-        +0.4881199398960199276054084F,-0.0003707873262008414298393F,
-        -0.0000073671179573384878877F,-0.0000011179318763879160310F
-      },
-      {
-        +0.4859387204261632065005472F,+0.0002890910354338275308622F,
-        +0.0000061009910341029670108F,+0.0000010830508017200641850F
-      },
-      {
-        +0.4835472848145313529144573F,-0.0003382010472590805429116F,
-        -0.0000529549988910092426565F,-0.0000205825591428645541441F
-      }
-    },
-    /*Contrast level 8 filters.*/
-    {
-      {
-        +0.4994522596472190656413659F,+0.0002215954251715837803379F,
-        +0.0000202398722059418877627F,+0.0000087807935953227835225F
-      },
-      {
-        +0.4988652324428006212819753F,-0.0002589862726493012516638F,
-        -0.0000029777307354311767111F,-0.0000003338734239934711138F
-      },
-      {
-        +0.4984466365571178503302008F,+0.0001791227881210257541055F,
-        +0.0000005734587681423751531F,+0.0000000718381840537506100F
-      },
-      {
-        +0.4979458094231292708542469F,-0.0001433081786963304963406F,
-        -0.0000008500023180420679499F,+0.0000000283751801041673331F
-      },
-      {
-        +0.4974109122261932691699826F,+0.0001147401509354206179800F,
-        +0.0000006256148297418191691F,+0.0000000966091172726374355F
-      },
-      {
-        +0.4968356983378738878087688F,-0.0001012569514721387692584F,
-        -0.0000020414609043619688506F,-0.0000003153731734632332331F
-      },
-      {
-        +0.4962432896718967367810649F,+0.0000793254051083025387954F,
-        +0.0000016853717541981491899F,+0.0000002992147418594681153F
-      },
-      {
-        +0.4955890275489457375002189F,-0.0000932971052573183757747F,
-        -0.0000146365725569265970262F,-0.0000056929245737308219766F
-      }
-    },
-    /*Contrast level 16 filters.*/
-    {
-      {
-        +0.4998611570226071387779143F,+0.0000561986766606086413913F,
-        +0.0000051201431153412290474F,+0.0000022210636548893662555F
-      },
-      {
-        +0.4997122443089725418730040F,-0.0000658075071313614969873F,
-        -0.0000007556198837515174208F,-0.0000000845984030650239734F
-      },
-      {
-        +0.4996059977093053050545279F,+0.0000455960654235170221465F,
-        +0.0000001464572429874675988F,+0.0000000183842398706308098F
-      },
-      {
-        +0.4994786788442057146042430F,-0.0000365446796566987810182F,
-        -0.0000002184306321095725997F,+0.0000000068043642154947857F
-      },
-      {
-        +0.4993424888460161192860198F,+0.0000293044227604581471376F,
-        +0.0000001605224477450457797F,+0.0000000247941451891726096F
-      },
-      {
-        +0.4991957693624383129993305F,-0.0000259080892238846858329F,
-        -0.0000005244224383208276881F,-0.0000000814009094831105251F
-      },
-      {
-        +0.4990444159731659001799642F,+0.0000203229160262065034176F,
-        +0.0000004325853457851024372F,+0.0000000768016102306213593F
-      },
-      {
-        +0.4988769278291567133010176F,-0.0000239374237743052331758F,
-        -0.0000037573400835358366793F,-0.0000014617026288582778623F
-      }
-    },
-    /*Contrast level 32 filters.*/
-    {
-      {
-        +0.4999651678819846400969595F,+0.0000141005802437881223892F,
-        +0.0000012838532484197587457F,+0.0000005569064407644136500F
-      },
-      {
-        +0.4999278024453653879177750F,-0.0000165195509739608277109F,
-        -0.0000001896190359078884463F,-0.0000000212217826543456007F
-      },
-      {
-        +0.4999011390458626968857914F,+0.0000114511155948291469623F,
-        +0.0000000368129637366108189F,+0.0000000046233792250619020F
-      },
-      {
-        +0.4998691745725470925165723F,-0.0000091821067151572047016F,
-        -0.0000000549901868049509983F,+0.0000000016818023020295985F
-      },
-      {
-        +0.4998349695031858996863150F,+0.0000073658102040057640768F,
-        +0.0000000403959275072578960F,+0.0000000062398894288430272F
-      },
-      {
-        +0.4997981029274434772169400F,-0.0000065151595659965957439F,
-        -0.0000001320119339589072851F,-0.0000000205156585175137481F
-      },
-      {
-        +0.4997600560680905967814169F,+0.0000051123369183002634797F,
-        +0.0000001088706632325653276F,+0.0000000193291302784124363F
-      },
-      {
-        +0.4997179319509047479286323F,-0.0000060238427959572464932F,
-        -0.0000009456626233815313247F,-0.0000003679051068368071936F
-      }
-    },
-    /*Contrast level 64 filters.*/
-    {
-      {
-        +0.4999912843507081094962530F,+0.0000035283416991741613266F,
-        +0.0000003212028013558364107F,+0.0000001393295230733825218F
-      },
-      {
-        +0.4999819343728570397722422F,-0.0000041341391807609398598F,
-        -0.0000000474496259910934465F,-0.0000000053099819541588781F
-      },
-      {
-        +0.4999752621333932722791360F,+0.0000028660533055402908606F,
-        +0.0000000092157430372188399F,+0.0000000011575647993101375F
-      },
-      {
-        +0.4999672625488200128351934F,-0.0000022984150962871844118F,
-        -0.0000000137716468298074144F,+0.0000000004192254679993819F
-      },
-      {
-        +0.4999587013779953070802264F,+0.0000018439500011884936776F,
-        +0.0000000101156909511318107F,+0.0000000015625767578566138F
-      },
-      {
-        +0.4999494729936705961215182F,-0.0000016311898744777719547F,
-        -0.0000000330600760916600531F,-0.0000000051393441051615709F
-      },
-      {
-        +0.4999399481616498830405249F,+0.0000012800739524601243801F,
-        +0.0000000272632855386633490F,+0.0000000048403902040499782F
-      },
-      {
-        +0.4999294012661086861193382F,-0.0000015084473857850950143F,
-        -0.0000002368141965753492091F,-0.0000000921324503507289458F
-      }
-    }
-  },
-  /*Cb channel filters at full resolution.*/
-  {
-    /*Contrast level 0 filters.*/
-    {
-      {
-        +0.4312048850363129348650659F,+0.0261634755939081191378204F,
-        +0.0031750772564368176346938F,+0.0013874848035305088669172F
-      },
-      {
-        +0.3648564476712009008174675F,-0.0238426973284627599647401F,
-        -0.0003931252829393594699220F,-0.0000568657294143991526390F
-      },
-      {
-        +0.3223968430317957767350379F,+0.0128422442826788708175600F,
-        +0.0000414471825883240834083F,+0.0000039752432106109812865F
-      },
-      {
-        +0.2804836413065861511206833F,-0.0082241427090125433785328F,
-        -0.0000247997987440750155912F,+0.0000082214843948207206182F
-      },
-      {
-        +0.2435945701707277200043222F,+0.0054248167290125385436861F,
-        +0.0000200130780606898053223F,+0.0000029201978500570578793F
-      },
-      {
-        +0.2112512721676763349787365F,-0.0039216740912408594790795F,
-        -0.0000536838546757304984464F,-0.0000027834831585026808163F
-      },
-      {
-        +0.1835455014530386064208756F,+0.0026749983944352904649544F,
-        +0.0000491074270152470714447F,+0.0000087068880048752066592F
-      },
-      {
-        +0.1586010497517217898710840F,-0.0027823160561639618919283F,
-        -0.0004197741523304857730846F,-0.0001598432434828200409804F
-      }
-    },
-    /*Contrast level 1 filters.*/
-    {
-      {
-        +0.4598595927109241920938132F,+0.0159163878225080726580565F,
-        +0.0016119432715116484636231F,+0.0006998405760071078635792F
-      },
-      {
-        +0.4181353674799145880847107F,-0.0169522280480596566898388F,
-        -0.0002111367365725923131783F,-0.0000257194306344017703135F
-      },
-      {
-        +0.3892168484067823341909786F,+0.0106073402518933653654321F,
-        +0.0000291961906781608349808F,+0.0000032024654446753188805F
-      },
-      {
-        +0.3573460821204919035665171F,-0.0076310457238191273937611F,
-        -0.0000277582398580081882698F,+0.0000059669593279700587160F
-      },
-      {
-        +0.3261672078827498877373614F,+0.0055400531916913013652515F,
-        +0.0000227672648134058980317F,+0.0000034510563457196915127F
-      },
-      {
-        +0.2959995531918351852063154F,-0.0043536784504266436146569F,
-        -0.0000678837955147546022548F,-0.0000066564449870218959590F
-      },
-      {
-        +0.2679167049092647800989653F,+0.0031318494348818205763596F,
-        +0.0000595772196036073009139F,+0.0000105689747934208020362F
-      },
-      {
-        +0.2404884151403481606923407F,-0.0033699165768711993908247F,
-        -0.0005126013690148204437688F,-0.0001967977370010746637242F
-      }
-    },
-    /*Contrast level 2 filters.*/
-    {
-      {
-        +0.4817120792465502399082311F,+0.0074724315808237231836819F,
-        +0.0006516392309702905005775F,+0.0002815245153035708203064F
-      },
-      {
-        +0.4617799787784527820733160F,-0.0089330693685947138577008F,
-        -0.0000955207550748095015258F,-0.0000099040179076770895627F
-      },
-      {
-        +0.4473378472950032547217347F,+0.0062551941429642701417158F,
-        +0.0000184705180670257794635F,+0.0000023023823007004419637F
-      },
-      {
-        +0.4298781400943726405117218F,-0.0049940173805803457843244F,
-        -0.0000262842187295421361552F,+0.0000018287017578816391974F
-      },
-      {
-        +0.4111460548094960087972538F,+0.0039688514372345591249558F,
-        +0.0000200138575890065358422F,+0.0000030864724760458936325F
-      },
-      {
-        +0.3911410298434226384678425F,-0.0034301165480603622651157F,
-        -0.0000642853214180271072655F,-0.0000091227921858019962628F
-      },
-      {
-        +0.3708010298878299249025758F,+0.0026360598441461957110177F,
-        +0.0000538723161638011622024F,+0.0000095574740153336816919F
-      },
-      {
-        +0.3489120970486987993730565F,-0.0030100382871891414281185F,
-        -0.0004664723745621126649655F,-0.0001807859522167991827516F
-      }
-    },
-    /*Contrast level 4 filters.*/
-    {
-      {
-        +0.4941658856998470961130465F,+0.0024233123979785255175390F,
-        +0.0001932074875662472858429F,+0.0000831105211319156379464F
-      },
-      {
-        +0.4876602722868220163299213F,-0.0030905075007501259763687F,
-        -0.0000325596218445339458309F,-0.0000032790980791743816316F
-      },
-      {
-        +0.4828792576859727847526926F,+0.0022985545858219516741905F,
-        +0.0000079624515509959584961F,+0.0000010617060879139090464F
-      },
-      {
-        +0.4767652919061929894795071F,-0.0019577346550704111463603F,
-        -0.0000139992621280691532519F,-0.0000002220327960929667512F
-      },
-      {
-        +0.4698333763048777589332872F,+0.0016461203637354723458563F,
-        +0.0000099940339496473717793F,+0.0000015523470412585898549F
-      },
-      {
-        +0.4619130244036616095293368F,-0.0015265210571683931507769F,
-        -0.0000334995202072480791826F,-0.0000056997504999518381849F
-      },
-      {
-        +0.4533427707255207050884849F,+0.0012344541050524223367579F,
-        +0.0000271744585322142675251F,+0.0000048252310570862587505F
-      },
-      {
-        +0.4433828521055653837379396F,-0.0014946768504321328221301F,
-        -0.0002366335603871463639635F,-0.0000923892560281006428036F
-      }
-    },
-    /*Contrast level 8 filters.*/
-    {
-      {
-        +0.4984288343975059598633948F,+0.0006562052364283222152808F,
-        +0.0000507157536390280400920F,+0.0000217706132202295523607F
-      },
-      {
-        +0.4966642306360010139520966F,-0.0008555366892458960911827F,
-        -0.0000091624242974067453081F,-0.0000009415980610145982637F
-      },
-      {
-        +0.4953645681975468728630574F,+0.0006488105721603400384556F,
-        +0.0000024319488330673602594F,+0.0000003310769067458522383F
-      },
-      {
-        +0.4936691099865914145183865F,-0.0005654495738762885985798F,
-        -0.0000045674889466461169709F,-0.0000002004098700369449674F
-      },
-      {
-        +0.4917103047825460149233834F,+0.0004848166883451819619832F,
-        +0.0000031824191720537174520F,+0.0000004955723362595859390F
-      },
-      {
-        +0.4894149820816336426965165F,-0.0004620263922605706346722F,
-        -0.0000108293930905426763809F,-0.0000019525940715985574606F
-      },
-      {
-        +0.4868725721430893771390913F,+0.0003810932905231036670578F,
-        +0.0000086774531525387136184F,+0.0000015419547591789487515F
-      },
-      {
-        +0.4838244145301845988704770F,-0.0004736707507444618599907F,
-        -0.0000757640541296034704822F,-0.0000296696124696210131037F
-      }
-    },
-    /*Contrast level 16 filters.*/
-    {
-      {
-        +0.4995993603725594200959392F,+0.0001675790051963064412194F,
-        +0.0000128413222402595711072F,+0.0000055087749513106696301F
-      },
-      {
-        +0.4991485323900807236086052F,-0.0002198113706306171393021F,
-        -0.0000023704700214431176567F,-0.0000002458308213386123646F
-      },
-      {
-        +0.4988163838127456783944069F,+0.0001675683041352075974568F,
-        +0.0000006433155295694552215F,+0.0000000880597963312900939F
-      },
-      {
-        +0.4983806733625466556247829F,-0.0001469739614975548638170F,
-        -0.0000012295239077028707444F,-0.0000000632154280827319493F
-      },
-      {
-        +0.4978746999205063694660112F,+0.0001266897221764517295853F,
-        +0.0000008508501271006457350F,+0.0000001325943198630668791F
-      },
-      {
-        +0.4972775592456645243899516F,-0.0001216788456608324940807F,
-        -0.0000029075619999733626398F,-0.0000005324822709820448539F
-      },
-      {
-        +0.4966117614934890123201683F,+0.0001009310800574111260421F,
-        +0.0000023216901090831847279F,+0.0000004126671295303846784F
-      },
-      {
-        +0.4958062635952286134610745F,-0.0001264380539211572914045F,
-        -0.0000202877312685135985186F,-0.0000079517431916540738722F
-      }
-    },
-    /*Contrast level 32 filters.*/
-    {
-      {
-        +0.4998993351771336968170090F,+0.0000421220032475569009607F,
-        +0.0000032206817961775215503F,+0.0000013813954564573950940F
-      },
-      {
-        +0.4997860047929443272352046F,-0.0000553368227772964353618F,
-        -0.0000005979284126332098208F,-0.0000000621689973188208138F
-      },
-      {
-        +0.4997025033015418116200124F,+0.0000422407185527253454887F,
-        +0.0000001631914270623181817F,+0.0000000223693885536100517F
-      },
-      {
-        +0.4995928101081758554435908F,-0.0000371101499479539579957F,
-        -0.0000003132820523681314136F,-0.0000000167087493931284721F
-      },
-      {
-        +0.4994652608212478139826374F,+0.0000320321692643728164838F,
-        +0.0000002164152696408874873F,+0.0000000337321614787282274F
-      },
-      {
-        +0.4993144520397829189128913F,-0.0000308273860686345823625F,
-        -0.0000007403465875189430361F,-0.0000001361243203404831883F
-      },
-      {
-        +0.4991460174323619214398207F,+0.0000256081933915283632122F,
-        +0.0000005906349708546492738F,+0.0000001049897350000978661F
-      },
-      {
-        +0.4989417607647111396751427F,-0.0000321459342115372963917F,
-        -0.0000051623025155033980537F,-0.0000020238177523863364102F
-      }
-    },
-    /*Contrast level 64 filters.*/
-    {
-      {
-        +0.4999748020039830875838049F,+0.0000105448136884012114769F,
-        +0.0000008058206653170043856F,+0.0000003456125767547167418F
-      },
-      {
-        +0.4999464301453608316982979F,-0.0000138584245076405129918F,
-        -0.0000001498193746973520146F,-0.0000000155877105180651935F
-      },
-      {
-        +0.4999255255535027808733162F,+0.0000105821860375712442561F,
-        +0.0000000409480959457036872F,+0.0000000056148971136907884F
-      },
-      {
-        +0.4998980539981414117356451F,-0.0000093007142669651292756F,
-        -0.0000000786964156299724979F,-0.0000000042351883624420844F
-      },
-      {
-        +0.4998661000495203121651855F,+0.0000080308026967991907055F,
-        +0.0000000543394130767120918F,+0.0000000084701788489652804F
-      },
-      {
-        +0.4998283015377052440619821F,-0.0000077326874018139165278F,
-        -0.0000001859434346391019483F,-0.0000000342227331225284434F
-      },
-      {
-        +0.4997860672041459784153972F,+0.0000064258732348099073471F,
-        +0.0000001483085835788009634F,+0.0000000263634466317491599F
-      },
-      {
-        +0.4997348201514046905913347F,-0.0000080705958338840041262F,
-        -0.0000012963274322268743507F,-0.0000005082386609530270635F
-      }
-    }
-  },
-  /*Cb channel filters at half resolution.*/
-  {
-    /*Contrast level 0 filters.*/
-    {
-      {
-        +0.4602086625268231867558200F,+0.0154644101646652411263805F,
-        +0.0017139680661844658524778F,+0.0007466224261652644900861F
-      },
-      {
-        +0.4203147358444114800590796F,-0.0153576587604778470874667F,
-        -0.0002193317653509145798759F,-0.0000293024896882381180032F
-      },
-      {
-        +0.3936824926826040793592654F,+0.0090546142646650024793376F,
-        +0.0000271981448294032643288F,+0.0000028520968546003849985F
-      },
-      {
-        +0.3656388142886505265849451F,-0.0062728057224575783576426F,
-        -0.0000229109237204130183061F,+0.0000050338770173233405873F
-      },
-      {
-        +0.3392500264538516607792928F,+0.0044399735298648775050356F,
-        +0.0000183308323441815770936F,+0.0000027524756651677612665F
-      },
-      {
-        +0.3144590386416039051731275F,-0.0034410259141278900368865F,
-        -0.0000537025101106421577212F,-0.0000050849766445565794187F
-      },
-      {
-        +0.2918304760154632471191860F,+0.0024638672926468457857752F,
-        +0.0000472080766446111824868F,+0.0000083739749129400848558F
-      },
-      {
-        +0.2699936349490731912759145F,-0.0026616819969186894696833F,
-        -0.0004059940385696034735596F,-0.0001558329947118572704652F
-      }
-    },
-    /*Contrast level 1 filters.*/
-    {
-      {
-        +0.4781615085884826643614076F,+0.0086926110131892875970694F,
-        +0.0008643706989259012513083F,+0.0003751101743641625449466F
-      },
-      {
-        +0.4553496839535168261292597F,-0.0094487315134822169593320F,
-        -0.0001166235533015845874088F,-0.0000140081971928498450576F
-      },
-      {
-        +0.4394739520269050903067409F,+0.0060756761788154593079136F,
-        +0.0000177467260284247707505F,+0.0000020379596196937894010F
-      },
-      {
-        +0.4216018120739419283715677F,-0.0045252927687756908797789F,
-        -0.0000200512127055128185288F,+0.0000026443219136367930252F
-      },
-      {
-        +0.4036527395526329220487582F,+0.0034038308211054510432625F,
-        +0.0000156547693173164447324F,+0.0000023906039343116392064F
-      },
-      {
-        +0.3856583774696092370426470F,-0.0027975648503294914953843F,
-        -0.0000485187662361873521294F,-0.0000059794524511424401126F
-      },
-      {
-        +0.3682790881502632229782535F,+0.0020835009412891406649360F,
-        +0.0000414545852249780631010F,+0.0000073551312341149776368F
-      },
-      {
-        +0.3504823381563014206285800F,-0.0023245622127997115149989F,
-        -0.0003580271056274965694663F,-0.0001382211213773269482905F
-      }
-    },
-    /*Contrast level 2 filters.*/
-    {
-      {
-        +0.4906477859441781275151584F,+0.0037824671969380191383081F,
-        +0.0003478083577686764070978F,+0.0001505152822959150151708F
-      },
-      {
-        +0.4806278681534560948129808F,-0.0043717135806460331523549F,
-        -0.0000500855122094850846079F,-0.0000055960073257212778543F
-      },
-      {
-        +0.4734921247384216158593517F,+0.0029813011626340811185965F,
-        +0.0000091368455226524458512F,+0.0000011218339131127151912F
-      },
-      {
-        +0.4650586901118646254715827F,-0.0023448450933404494343770F,
-        -0.0000126910334944193751934F,+0.0000007747036541429312930F
-      },
-      {
-        +0.4561722239177513626984251F,+0.0018480827148408185064965F,
-        +0.0000095324075788810215797F,+0.0000014683983753382557532F
-      },
-      {
-        +0.4467855777070405820516896F,-0.0015977740464431693448444F,
-        -0.0000306793872423118341381F,-0.0000044606182934143019040F
-      },
-      {
-        +0.4372856389699626977751734F,+0.0012327172165589896351418F,
-        +0.0000255927010398500871867F,+0.0000045421711509735831212F
-      },
-      {
-        +0.4270287690541813563349649F,-0.0014237534941442383726318F,
-        -0.0002218497230922978811184F,-0.0000860857157147907237245F
-      }
-    },
-    /*Contrast level 4 filters.*/
-    {
-      {
-        +0.4971460649591666336455376F,+0.0011636399729905537447916F,
-        +0.0001026463529986448337686F,+0.0000443439754802337109184F
-      },
-      {
-        +0.4940510732579490027482905F,-0.0013879215457904354926594F,
-        -0.0000155356132537631831116F,-0.0000016900389065118308948F
-      },
-      {
-        +0.4918260770604944154271720F,+0.0009749674164589081353655F,
-        +0.0000031493379731592939307F,+0.0000003999561078445047152F
-      },
-      {
-        +0.4891271714038635254340193F,-0.0007898209927561170018429F,
-        -0.0000048491536852577602865F,+0.0000001135143101289031343F
-      },
-      {
-        +0.4862096615978594993379147F,+0.0006385111597891724799850F,
-        +0.0000035506447732053923992F,+0.0000005490728968264281322F
-      },
-      {
-        +0.4830350565738341095389785F,-0.0005688295077240233853580F,
-        -0.0000116529508005388360943F,-0.0000018369478686018179049F
-      },
-      {
-        +0.4797342094944266333023108F,+0.0004483154263745252787916F,
-        +0.0000095871420639472317411F,+0.0000017021279368523581238F
-      },
-      {
-        +0.4760531716997873918906237F,-0.0005301129386037866080689F,
-        -0.0000833041296515965882987F,-0.0000324253810482480852423F
-      }
-    },
-    /*Contrast level 8 filters.*/
-    {
-      {
-        +0.4992444835974491068597558F,+0.0003088435876279362166281F,
-        +0.0000268779569733892417891F,+0.0000116042498986108184937F
-      },
-      {
-        +0.4984220668736984438673687F,-0.0003721105376605886175603F,
-        -0.0000041467601158370050266F,-0.0000004486458888485877789F
-      },
-      {
-        +0.4978292885293383318590088F,+0.0002638585555855297920189F,
-        +0.0000008707883622934384889F,+0.0000001117623868345653658F
-      },
-      {
-        +0.4971041132935203887832643F,-0.0002158359416585387110989F,
-        -0.0000013847094803124767368F,+0.0000000156756949140729970F
-      },
-      {
-        +0.4963136741525427386712011F,+0.0001759437344031844984403F,
-        +0.0000010049726651719525168F,+0.0000001555955914948288237F
-      },
-      {
-        +0.4954449600589856950172418F,-0.0001583577899523404405521F,
-        -0.0000033192061665273614916F,-0.0000005366863223510101579F
-      },
-      {
-        +0.4945334300806312199938475F,+0.0001257251918016510656550F,
-        +0.0000027180227895753001599F,+0.0000004826469863732972892F
-      },
-      {
-        +0.4935054054165609049853458F,-0.0001499437205014660632902F,
-        -0.0000236378241409296686122F,-0.0000092107328841456947798F
-      }
-    },
-    /*Contrast level 16 filters.*/
-    {
-      {
-        +0.4998082891290608342771407F,+0.0000784225821887767093367F,
-        +0.0000068001654637878569993F,+0.0000029353831595763431232F
-      },
-      {
-        +0.4995993942162609280366325F,-0.0000947438742531420726844F,
-        -0.0000010548637801785191399F,-0.0000001139981807388965032F
-      },
-      {
-        +0.4994487283513495134990023F,+0.0000673499430049362179983F,
-        +0.0000002236391116305261782F,+0.0000000287839074709941245F
-      },
-      {
-        +0.4992639881352125552638199F,-0.0000552367080491171106920F,
-        -0.0000003586844583628537256F,+0.0000000028994376696220573F
-      },
-      {
-        +0.4990621724709565221189678F,+0.0000451284840720293943983F,
-        +0.0000002596895744578047987F,+0.0000000402194703252865477F
-      },
-      {
-        +0.4988397692343520262170387F,-0.0000407318132483162168868F,
-        -0.0000008591626814938898862F,-0.0000001398615903289499636F
-      },
-      {
-        +0.4986058246389627468531103F,+0.0000324031698429677145158F,
-        +0.0000007026513732516271905F,+0.0000001247781641005778767F
-      },
-      {
-        +0.4983411637385160020130570F,-0.0000387374947664184600838F,
-        -0.0000061122319350186889525F,-0.0000023824033322084650407F
-      }
-    },
-    /*Contrast level 32 filters.*/
-    {
-      {
-        +0.4999518918227697228395812F,+0.0000196829210259502925928F,
-        +0.0000017051612382712894011F,+0.0000007360229095357550227F
-      },
-      {
-        +0.4998994581886274657378522F,-0.0000237957337813770248615F,
-        -0.0000002648825975177812061F,-0.0000000286180329343052322F
-      },
-      {
-        +0.4998616340735522745042374F,+0.0000169262785037985382926F,
-        +0.0000000562941480146951632F,+0.0000000072506125955771948F
-      },
-      {
-        +0.4998152285910394954093761F,-0.0000138912800753890178001F,
-        -0.0000000904840948884158553F,+0.0000000006569053684572551F
-      },
-      {
-        +0.4997645050846114544995658F,+0.0000113556814985429743562F,
-        +0.0000000654703268447273447F,+0.0000000101405530586313040F
-      },
-      {
-        +0.4997085684350353051996763F,-0.0000102567015065452848152F,
-        -0.0000002166976700434084466F,-0.0000000353365038058256193F
-      },
-      {
-        +0.4996496916819095912565274F,+0.0000081636499530921329481F,
-        +0.0000001771646242092627697F,+0.0000000314616523949115513F
-      },
-      {
-        +0.4995830317103385764809786F,-0.0000097655218729216240113F,
-        -0.0000015412181378217517645F,-0.0000006007760062033873553F
-      }
-    },
-    /*Contrast level 64 filters.*/
-    {
-      {
-        +0.4999879616215221478370268F,+0.0000049255846539969078327F,
-        +0.0000004266115348804893581F,+0.0000001841423067367882810F
-      },
-      {
-        +0.4999748400262142289385281F,-0.0000059558338066581850766F,
-        -0.0000000662940618596535339F,-0.0000000071619736813179048F
-      },
-      {
-        +0.4999653740934134060758254F,+0.0000042371546362524793879F,
-        +0.0000000140977703995967159F,+0.0000000018160990882293691F
-      },
-      {
-        +0.4999537588655347808419549F,-0.0000034779875496128436171F,
-        -0.0000000226723427446380982F,+0.0000000001599095928602632F
-      },
-      {
-        +0.4999410610317421288506523F,+0.0000028435525305817017172F,
-        +0.0000000164021520985583606F,+0.0000000025405447297687155F
-      },
-      {
-        +0.4999270557298786110678179F,-0.0000025688225646702732445F,
-        -0.0000000542947722626940048F,-0.0000000088575719125639121F
-      },
-      {
-        +0.4999123119399688786046454F,+0.0000020448752725206912492F,
-        +0.0000000443859118778854798F,+0.0000000078822671904045956F
-      },
-      {
-        +0.4998956157616588069636521F,-0.0000024464996226189751516F,
-        -0.0000003861349358219454581F,-0.0000001505205748074876969F
-      }
-    }
-  }
-};
-
-/*Distortion:
-
-  We measure distortion using Nadenau's IaCLA-2 masking model, as it performed
-   the best in his model comparisons.
-  Nadenau only used the model to predict the detection threshold for
-   distortions, and never gave an example of the bitrate savings achievable by
-   incorporating it into a visually-lossless compression system, as he did
-   with his CSF filtering and texture synthesis.
-  Thus, it is unknown on a quantifiable level how much this actually
-   contributes to performance.
-  Daly mentions that "the various visual optimization tools" when combined
-   have produced observed bit rate savings as high as 50%, though it is
-   unclear which tools he is referring to, and no reference is given.
-  Most likely he is talking about CSF filtering, point-wise masking and
-   neighborhood masking.
-
-  Unlike CSF filtering, which provides little benefit at low resolutions and
-   high contrast, neighborhood masking can provide bit rate reductions at any
-   resolution or contrast.
-
-  The IaCLA-2 masking model:
-
-  D = sum_{block coefficients i,j} (|c_{ij}'-\hat{c}_{ij}|/
-   (1+(1/(k_L^\nu N_{neighbors})) sum_{neighbors k.l} |c_{kl}'|^\nu)^
-   \epsilon)^\Beta)^{1/\Beta}
-
-  c_{ij}' = r_{csf} w_{csf} c_{ij}
-  \hat{c}_{ij} = r_{csf} w_{csf} \lfloor c_{ij}/(\Delta Q) \rfloor \Delta Q
-
-  Parameters:
-
-  r_{csf} = 1/128 (Nadenau used 1/8)
-  \epsilon = 1 (Nadenau claimed he used 0, but probably meant 1)
-  \Beta = \infty (Nadenau used 20)
-  N_\Gamma = 79-99 (Nadenau used 84)
-  k_L = 1E-4 (JPEG 2000 used 1E-4, Nadenau used 3E-6)
-  \nu = 0.2 (Nadenau estimated 0.389 and 0.477).
-
-  A detailed discussion of each parameter is given below.
-
-  r_{csf}: Coefficient scale factor.
-
-  Nadenau's explanation of r_{csf} was very brief:
-
-    Additionally, the viewing coniditions for the psycho-visual test were
-     chosen, so that the spatial frequencies affected by quantization
-     correspond to the frequencies for which the human observer is most
-     sensitive....
-    However, this way it is only guaranteed that the relative CSF-sensitivity
-     equals 1, but it needs to be expressed in terms of the dynamic range of
-     the wavelet coefficients c_{ij}.
-    This is done by setting c_{ij}' to:
-
-      c_{ij}' = r_{csf} c_{ij},
-
-     where r_{csf} is approximately 1/8.
-
-  No description of how the value 1/8 was derived is present.
-  However, the FCD of the JPEG 2000 standard gives us a hint of what a proper
-   value might be.
-  In Part II, Annex E, Section 2, it discusses the "point-wise extended
-   non-linearity" on which Nadenau's IaCLA-2 method is based.
-  There it suggests using a parameter a which would cause k_L to have an
-   equivalent value of 2^{component_bit_depth-1}*1E-4.
-  Nadenau reports, however, that the standard specifies a value of 1E-4
-   directly.
-  This makes us assume he has separated out the 2^{component_bit_depth-1}
-   part into his r_{csf} parameter.
-
-  Thus, we adopt a value of 1/(2^7) for r_{csf}.
-  The remaining discrepancy with Nadenau's value of 1/8 is likely accounted
-   for by some scaling introduced by his wavelet transform.
-  The scale factor of 2 in our DCT transform is already accounted for in our
-   CSF filter computations.
-
-  \epsilon: Threshold elevation non-linearity..
-
-  The original IaCLA model (used in JPEG 2000) also contained an exponent,
-   \epsilon, on the neighborhood threshold elevation term.
-  Nadenau found that this actually hurts performance, and in his IaCLA-2
-   model claims to set it to 0.
-  This was probably meant to be 1, since 0 would've disabled neighborhood
-   masking altogether.
-
-  \Beta: Error pooling exponent.
-
-  Again for simplicity, we use \Beta=\infty to turn the pooling into a max
-   operator, which is a close approximation for the fixed value of \Beta=20
-   used by Nadenau.
-
-  N_\Gamma: Masking neighborhood size.
-
-  Daly et al. use a causal masking neighborhood in a wavelet transform
-   \cite{DZL+00}.
-  They take all causal coefficients--those above or to the left--from the same
-   band in a 13x13 neighborhood, i.e. 84 coefficients.
-  They also talk about encroachments of the horizontal and vertical bands in
-   a wavelet decomposition on the diagonal bands, which can lead to excessive
-   horizontal and vertical masking around diagonal edges and decreased
-   diagonal masking.
-  The DCT has smaller frequency bands than wavelets, and so we can get a slight
-   improvement by moving some coefficients around in the high frequency
-   channels.
-
-  Each coefficient uses a combination of nearby coefficients in the same DCT
-   block and nearby coefficients in neighboring blocks for neighborhood
-   masking.
-  The number of coefficients in the same block is chosen to approximate the
-   octave structure of the HVS, while the number of neighboring blocks used is
-   chosen to give nearly the same number of neighbors for each masking group.
-
-  There are 9 groups for a single 8x8 DCT block:
-
-     0 1 2 3 4 5 6 7
-    +-+-+---+-------+
-  0 | |A|   |       |
-    +-+-+ D |       |
-  1 |B|C|   |       |
-    +-+-+---+   G   |
-  2 |   |   |       |
-    | E | F +-+     |
-  3 |   |   | |     |
-    +---+-+-+ +---+ |
-  4 |     |       | |
-    |     +-+     +-+
-  5 |       |       |
-    |   H   |   I   |
-  6 |       |       |
-    |       +-+     |
-  7 |         |     |
-    +---------+-----+
-
-  (no neighborhood masking is applied to the DC coefficient)
-  Groups A through C use a 9x9 neighborhood of blocks, for a total of
-   1*9*9-1=80 neighbors.
-  Groups D through F use a 5x5 neighborhood of blocks, for a total of
-   4*5*5-1=99 neighbors.
-  Groups G through I use the top, bottom, left and right neighboring blocks,
-   for a total of 16*5-1=79 neighbors.
-
-  There might be a smarter way to group these coefficients.
-  In addition, there is no reason that the groupings must form a partition,
-   but instead each coefficient could belong to multiple groups, potentially
-   increasing the total number of groups to one per coefficient.
-  One could also conceivably weight neighbors in a non-uniform manner.
-  This approach was investigated by Tran and Safranek \cite{TS96}, but too
-   little detail was reported to reproduce their results.
-  Tran's Master's thesis might contain more information, but no copy is
-   available online.
-
-  k_L: Masking dynamic range
-
-  This parameter controls the degree to which a signal can be masked.
-  We use the JPEG 2000 value.
-  See below for discussion.
-
-  \nu: Neighborhood coefficient exponent
-
-  Nadenau's estimates for \nu on observer data where observers have unlimited
-   time and can flicker back and forth between a distorted and undistorted
-   image were 0.389, with a standard deviation of 0.0142.
-  He found that values in the range of 0.4 were less likely to declare
-   homogenous regions near strong edges active than more usual values in the
-   literature, such as 2, while still classifying medium-sized coefficients as
-   active.
-  However, for observer data where observers had a limited amount of time and
-   could not flicker back and forth between the two still images, the
-   estimates grew to 0.477, with a standard deviation of 0.0171.
-
-  Unforunately, attempts to reproduce Nadenau's experiments have yielded
-   nonsense results.
-  With the small value of k_L and large value of \nu he suggests, coefficients
-   are masked by a value nearly two orders of magnitude greater than with the
-   JPEG 2000 recommended parameters.
-  Clearly some part of his description has been misinterpreted or was not
-   sufficiently described, but in any case the results are completely unusable
-   as-is.
-  Adopting the JPEG 2000 parameter values seems to give plausible results,
-   however, and so until this discrepancy can be resolved, that is what we
-   have done.
-
-  Finally, Nadenau ran the computed distortion through a Weibull fuction to
-   compute the probability of detection.
-  This function was parameterized by a base distortion, D_0, and a slope
-   value, \kappa, which he estimated from observer data.
-  The Weibull function is monotonic, and outside a narrow band around D_0 it
-   is very close to either 0 or 1, so we forgo applying it at all.
-
-  A note about point-wise masking:
-
-  Point-wise masking or self-masking or luma masking is sometimes suggested to
-   account for the HVS's decreased sensitivity in bright regions and vice
-   versa.
-  This type of masking is actually built in to our compression system since
-   we operate on gamma-pre-corrected signals with uniform quantization.
-  In effect, we are really performing non-uniform quantization on the
-   underlying linear signals.
-  The gamma exponent is not equal to the value of 3.0 generally assumed for
-   the HVS, but it is close enough that additional effort on our part would
-   not likely bring much improvement.*/
-
-/*This parameter, r_{csf}^\nu, compensates for the dyanmic range of the DCT
-   coefficients.*/
-#define OC_MASK_R_CSF_NU      (8.8388347648318440550E-2F)
-/*#define OC_MASK_R_CSF_NU      (0.37892914162759952059F)*/
-
-/*This parameter, k_L^\nu, determines the dynamic range of the neighborhood
-   masking.*/
-/*#define OC_MASK_K_L_NU        (1.7320508075688772935E-3F)*/
-#define OC_MASK_K_L_NU        (0.15848931924611134852F)
-
-/*#define OC_MASK_NU            (0.5F)*/
-#define OC_MASK_NU            (0.2F)
-
-/*The maximum half-width in blocks of a masking neighborhood.
-  This half-width is rounded up for consistency with the
-   OC_CSF_FILTER_SZ_MAX constant, so the real neighborhood width and height
-   are OC_MASK_WINDOW_SZ_MAX*2-1.*/
-#define OC_MASK_WINDOW_SZ_MAX (5)
-
-/*The number of DCT coefficient groups used for masking.*/
-#define OC_MASK_NGROUPS       (9)
-
-/*The number of DCT coefficient groups that use a full NxN neighborhood.*/
-#define OC_MASK_NFULL_GROUPS  (6)
-
-/*The half-width in blocks of each masking neighborhood, rounded down for
-   consistency with csf_filter_sizes values.*/
-static const int   OC_MASK_WINDOW_SIZES[OC_MASK_NGROUPS]={
-  4,4,4,2,2,2,1,1,1
-};
-/*The masking group that each DCT coefficient belongs to.*/
-static const int   OC_MASK_GROUP[64]={
-  9,0,3,3,6,6,6,6,
-  1,2,3,3,6,6,6,6,
-  4,4,5,5,6,6,6,6,
-  4,4,5,5,8,6,6,6,
-  7,7,7,8,8,8,8,6,
-  7,7,7,7,8,8,8,8,
-  7,7,7,7,8,8,8,8,
-  7,7,7,7,7,8,8,8
-};
-/*The weights for each coefficient masking group.
-  These terms absorb a good number of the constants in the model.*/
-static const float OC_MASK_WEIGHTS[OC_MASK_NGROUPS]={
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*80),
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*80),
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*80),
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*99),
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*99),
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*99),
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*79),
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*79),
-  OC_MASK_R_CSF_NU/(OC_MASK_K_L_NU*79),
-};
-
-/*This constant is used to absorb noise in the CSF values of low-amplitude
-   coefficients.*/
-#define OC_CSF_NOISE_LEVEL (8)
-/*The amount that the DC coefficient of the DC transform is shifted by.*/
-#define OC_CSF_DC_SHIFT    (4096)
-
-
-
-typedef float oc_weight_block[64];
-typedef float oc_mask_block[9];
-
-
-
-/*Scratch space used by the psychovisual model.*/
-struct oc_psych_ctx{
-  /*The CSF filter pipeline stage.*/
-  oc_enc_pipe_stage    csf_pipe;
-  /*The spatial masking pipeline stage.*/
-  oc_enc_pipe_stage    mask_pipe;
-  /*A single row of CSF-filtered coefficients (after vertical filtering).
-    This has OC_CSF_FILTER_SZ_MAX-1 blocks of padding on each side.*/
-  oc_weight_block     *csf_row;
-  /*OC_MASK_WINDOW_SZ_MAX rows of CSF-filtered coefficients (after both
-     vertical and horizontal filtering) for each plane.
-    This has no padding on either side.*/
-  oc_weight_block    **csf_weights[3];
-  /*The half-width of the CSF filters in the current filter banks, rounded
-     down.*/
-  int                  csf_filter_sizes[5][8];
-  /*The current CSF filter banks.
-    There are 5 in total:
-    0: Y channel (horizontal and vertical).
-    1: Cr channel horizontal.
-    2: Cr channel vertical.
-    3: Cb channel horizontal.
-    4: Cb channel vertical.*/
-  oc_csf_filter_bank   csf_filters[5];
-  /*Offsets used to protect against division by 0.*/
-  float                csf_offsets[3][64];
-  /*Sums of CSF-weighted masking values in each masking group over
-     OC_MASK_WINDOW_SZ_MAX*2-1 rows, with OC_MASK_WINDOW_SZ_MAX-1 blocks of
-     padding on either side.*/
-  oc_mask_block      **mask_groups[3];
-  /*Individual CSF-weighted masking values over OC_MASK_WINDOW_SZ_MAX rows.*/
-  oc_weight_block    **mask_weights[3];
-  /*The encoding context.*/
-  oc_enc_ctx          *enc;
-  /*The vertical delay for CSF filtering.*/
-  int                  vsize_max[3];
-};
-
-
-
-/*Computes a set of CSF filters to use for each plane given the current
-   expected contrast level.
-  _psych:    The psycho-visual context.
-  _contrast: The current expected contrast level.*/
-static void oc_psych_csf_filters_interpolate(oc_psych_ctx *_psych,
- float _contrast){
-  float logc;
-  int   logc0;
-  int   logc1;
-  float alpha;
-  int   hdec;
-  int   vdec;
-  int   i;
-  int   j;
-  int   k;
-  hdec=!(_psych->enc->state.info.pixel_fmt&1);
-  vdec=!(_psych->enc->state.info.pixel_fmt&2);
-  /*Select a pair of CSF filters to interpolate over for the given contrast
-     level.
-    For contrasts in the range 0..1, we interpolate linearly.
-    For contrasts in the range 1..64, we interpolate linearly in log space.*/
-  if(_contrast<=0){
-    logc0=logc1=0;
-    alpha=0;
-  }
-  else if(_contrast<=1){
-    logc0=0;
-    logc1=1;
-    alpha=_contrast;
-  }
-  else if(_contrast<=64){
-    logc=OC_LOGF(_contrast)*OC_1_LN2+1;
-    logc0=OC_IFLOORF(logc);
-    logc1=OC_ICEILF(logc);
-    alpha=logc-logc0;
-  }
-  else{
-    logc0=logc1=7;
-    alpha=0;
-  }
-  for(i=0;i<8;i++){
-    for(j=0;j<5;j++){
-      /*Horizontal and vertical Y filter.*/
-      _psych->csf_filters[0][i][j]=OC_CSF_FILTERS[0][logc0][i][j]+
-       alpha*(OC_CSF_FILTERS[0][logc1][i][j]-OC_CSF_FILTERS[0][logc0][i][j]);
-      /*Horizontal Cb filter.*/
-      _psych->csf_filters[1][i][j]=OC_CSF_FILTERS[1+hdec][logc0][i][j]+
-       alpha*(OC_CSF_FILTERS[1+hdec][logc1][i][j]-
-       OC_CSF_FILTERS[1+hdec][logc0][i][j]);
-      /*Vertical Cb filter.*/
-      _psych->csf_filters[2][i][j]=OC_CSF_FILTERS[1+vdec][logc0][i][j]+
-       alpha*(OC_CSF_FILTERS[1+vdec][logc1][i][j]-
-       OC_CSF_FILTERS[1+vdec][logc0][i][j]);
-      /*Horizontal Cr filter.*/
-      _psych->csf_filters[3][i][j]=OC_CSF_FILTERS[3+hdec][logc0][i][j]+
-       alpha*(OC_CSF_FILTERS[3+hdec][logc1][i][j]-
-       OC_CSF_FILTERS[3+hdec][logc0][i][j]);
-      /*Vertical Cr filter.*/
-      _psych->csf_filters[4][i][j]=OC_CSF_FILTERS[3+vdec][logc0][i][j]+
-       alpha*(OC_CSF_FILTERS[3+vdec][logc1][i][j]-
-       OC_CSF_FILTERS[3+vdec][logc0][i][j]);
-    }
-    /*Find the filter length that leaves us with less than 1% error.
-      For a filter size of n, the actual number of taps is 2*n+1.*/
-    for(k=0;k<5;k++){
-      for(j=OC_CSF_FILTER_SZ_MAX-1;
-       OC_FABSF(_psych->csf_filters[k][i][0]*0.01F)>
-       OC_FABSF(_psych->csf_filters[k][i][j]);j--);
-      _psych->csf_filter_sizes[k][i]=j;
-    }
-  }
-  /*Find the offsets used to protect against division by 0.*/
-  for(k=0;k<3;k++){
-    int vfilti;
-    int hfilti;
-    vfilti=k<<1;
-    hfilti=k>0?(k<<1)-1:0;
-    for(i=0;i<8;i++)for(j=0;j<8;j++){
-      int hi;
-      int vi;
-      _psych->csf_offsets[k][i<<3|j]=0;
-      for(vi=1;vi<=_psych->csf_filter_sizes[vfilti][i];vi++){
-        for(hi=1;hi<=_psych->csf_filter_sizes[hfilti][j];hi++){
-          _psych->csf_offsets[k][i<<3|j]+=_psych->csf_filters[vfilti][i][vi]*
-           _psych->csf_filters[hfilti][j][hi];
-        }
-      }
-      _psych->csf_offsets[k][i<<3|j]*=4;
-      for(vi=1;vi<=_psych->csf_filter_sizes[vfilti][i];vi++){
-        _psych->csf_offsets[k][i<<3|j]+=_psych->csf_filters[vfilti][i][vi]*2*
-         _psych->csf_filters[hfilti][j][0];
-      }
-      for(hi=1;hi<=_psych->csf_filter_sizes[hfilti][j];hi++){
-        _psych->csf_offsets[k][i<<3|j]+=_psych->csf_filters[vfilti][i][0]*2*
-         _psych->csf_filters[hfilti][j][hi];
-      }
-      _psych->csf_offsets[k][i<<3|j]+=_psych->csf_filters[vfilti][i][0]*
-       _psych->csf_filters[hfilti][j][0];
-      _psych->csf_offsets[k][i<<3|j]=OC_FABSF(_psych->csf_offsets[k][i<<3|j])*
-       (i||j?OC_CSF_NOISE_LEVEL:OC_CSF_DC_SHIFT);
-    }
-  }
-}
-
-static int oc_csf_pipe_start(oc_enc_pipe_stage *_stage){
-  oc_psych_ctx *psych;
-  int           pli;
-  psych=_stage->enc->vbr->psych;
-  oc_psych_csf_filters_interpolate(psych,_stage->enc->vbr->qscale);
-  for(pli=0;pli<3;pli++){
-    int *vsizes;
-    int  vfilti;
-    int  filti;
-    _stage->y_procd[pli]=0;
-    vfilti=pli<<1;
-    vsizes=psych->csf_filter_sizes[vfilti];
-    /*Find the number of rows we have to perform DCTs in advance.*/
-    psych->vsize_max[pli]=0;
-    for(filti=0;filti<8;filti++){
-      psych->vsize_max[pli]=OC_MAXI(psych->vsize_max[pli],vsizes[filti]);
-    }
-  }
-  return _stage->next!=NULL?(*_stage->next->pipe_start)(_stage->next):0;
-}
-
-static int oc_csf_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  oc_psych_ctx *psych;
-  int           pli;
-  psych=_stage->enc->vbr->psych;
-  for(pli=0;pli<3;pli++){
-    int y_procd;
-    int y_avail;
-    /*Compute how far we can get in complete fragment rows.*/
-    y_procd=_stage->y_procd[pli];
-    /*Add a vsize_max[pli] delay.*/
-    y_avail=(_y_avail[pli]&~7)-(psych->vsize_max[pli]<<3);
-    /*Perform CSF filtering on any newly available rows.*/
-    while(y_avail>y_procd){
-      oc_fragment_plane    *fplane;
-      oc_fragment          *frags;
-      oc_fragment_enc_info *efrags;
-      oc_weight_block      *maskw_row;
-      oc_weight_block      *csfw_row;
-      oc_csf_filter        *vfilters;
-      oc_csf_filter        *hfilters;
-      oc_mask_block        *maskg_row;
-      float                *csfw;
-      float                *maskw;
-      float                *maskg;
-      int                  *vsizes;
-      int                  *hsizes;
-      int                   fragi_end;
-      int                   fragx;
-      int                   cfragi0;
-      int                   cfragi;
-      int                   cfragj;
-      int                   mfragj;
-      int                   vfilti;
-      int                   hfilti;
-      int                   filti;
-      int                   ci;
-      int                   wi;
-      vfilti=pli<<1;
-      vfilters=psych->csf_filters[vfilti];
-      vsizes=psych->csf_filter_sizes[vfilti];
-      hfilti=(pli<<1)-(pli>0);
-      hfilters=psych->csf_filters[hfilti];
-      hsizes=psych->csf_filter_sizes[hfilti];
-      frags=psych->enc->state.frags;
-      efrags=psych->enc->frinfo;
-      fplane=psych->enc->state.fplanes+pli;
-      fragi_end=fplane->froffset+fplane->nfrags;
-      cfragi0=fplane->froffset+(y_procd>>3)*fplane->nhfrags;
-      /*First, the vertical filter.*/
-      for(fragx=0,cfragi=cfragi0;fragx<fplane->nhfrags;fragx++,cfragi++){
-        int fragi_off;
-        csfw=psych->csf_row[fragx+OC_CSF_FILTER_SZ_MAX-1];
-        for(ci=0;ci<64;ci++){
-          filti=ci>>3;
-          csfw[ci]=vfilters[filti][0]*efrags[cfragi].dct_coeffs[ci];
-          fragi_off=fplane->nhfrags;
-          for(wi=vsizes[filti];wi>0;wi--){
-            int coeffs;
-            cfragj=cfragi-fragi_off;
-            coeffs=cfragj>=fplane->froffset?efrags[cfragj].dct_coeffs[ci]:0;
-            cfragj=cfragi+fragi_off;
-            if(cfragj<fragi_end)coeffs+=efrags[cfragj].dct_coeffs[ci];
-            csfw[ci]+=0.5F*vfilters[filti][wi]*coeffs;
-            fragi_off+=fplane->nhfrags;
-          }
-        }
-      }
-      /*Next, the horizontal filtering.*/
-      maskg_row=psych->mask_groups[pli][OC_MASK_WINDOW_SZ_MAX-1<<1];
-      maskw_row=psych->mask_weights[pli][OC_MASK_WINDOW_SZ_MAX-1];
-      csfw_row=psych->csf_weights[pli][OC_MASK_WINDOW_SZ_MAX-1];
-      memset(maskg_row[0],0,sizeof(maskg_row[0])*(
-       fplane->nhfrags+(OC_MASK_WINDOW_SZ_MAX-1<<1)));
-      for(fragx=0,cfragi=cfragi0;fragx<fplane->nhfrags;fragx++,cfragi++){
-        csfw=csfw_row[fragx];
-        if(frags[cfragi].invalid)memset(csfw,0,sizeof(oc_weight_block));
-        else{
-          cfragj=fragx+OC_CSF_FILTER_SZ_MAX-1;
-          mfragj=fragx+OC_MASK_WINDOW_SZ_MAX-1;
-          for(ci=0;ci<64;ci++){
-            filti=ci&7;
-            csfw[ci]=hfilters[filti][0]*psych->csf_row[cfragj][ci];
-            for(wi=hsizes[filti];wi>0;wi--){
-              csfw[ci]+=0.5F*hfilters[filti][wi]*(
-               psych->csf_row[cfragj-wi][ci]+psych->csf_row[cfragj+wi][ci]);
-            }
-            csfw[ci]=OC_FABSF(csfw[ci]);
-          }
-          maskw=maskw_row[fragx];
-          maskg=maskg_row[mfragj];
-          for(ci=1;ci<64;ci++){
-            maskw[ci]=OC_POWF(csfw[ci],OC_MASK_NU);
-            maskg[OC_MASK_GROUP[ci]]+=maskw[ci];
-          }
-        }
-      }
-      y_procd+=8;
-      _stage->y_procd[pli]=y_procd;
-      if(_stage->next!=NULL){
-        int ret;
-        ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-        if(ret<0)return ret;
-      }
-    }
-  }
-  return 0;
-}
-
-static int oc_csf_pipe_end(oc_enc_pipe_stage *_stage){
-  oc_psych_ctx *psych;
-  int           pli;
-  int           ret;
-  int           y_avail[3];
-  psych=_stage->enc->vbr->psych;
-  for(pli=0;pli<3;pli++){
-    y_avail[pli]=_stage->enc->state.input[pli].height+
-    (psych->vsize_max[pli]<<3);
-  }
-  ret=oc_csf_pipe_process(_stage,y_avail);
-  if(ret<0)return ret;
-  return _stage->next!=NULL?(*_stage->next->pipe_end)(_stage->next):0;
-}
-
-/*Initialize the CSF filter stage of the pipeline.
-  _enc: The encoding context.*/
-static void oc_csf_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_csf_pipe_start;
-  _stage->pipe_proc=oc_csf_pipe_process;
-  _stage->pipe_end=oc_csf_pipe_end;
-}
-
-
-static int oc_mask_pipe_start(oc_enc_pipe_stage *_stage){
-  oc_psych_ctx *psych;
-  int           pli;
-  psych=_stage->enc->vbr->psych;
-  for(pli=0;pli<3;pli++){
-    oc_fragment_plane *fplane;
-    int                rowi;
-    _stage->y_procd[pli]=-(OC_MASK_WINDOW_SZ_MAX-1)<<3;
-    fplane=psych->enc->state.fplanes+pli;
-    /*Just clear out the mask group weights for the rows above the image.*/
-    for(rowi=OC_MASK_WINDOW_SZ_MAX-1;rowi<(OC_MASK_WINDOW_SZ_MAX-1<<1);rowi++){
-      memset(psych->mask_groups[pli][rowi][0],0,
-       sizeof(oc_mask_block)*(fplane->nhfrags+(OC_MASK_WINDOW_SZ_MAX-1<<1)));
-    }
-  }
-  return 0;
-}
-
-static int oc_mask_pipe_process(oc_enc_pipe_stage *_stage,int _y_avail[3]){
-  static const int o=OC_MASK_WINDOW_SZ_MAX-1;
-  oc_psych_ctx *psych;
-  int           pli;
-  psych=_stage->enc->vbr->psych;
-  for(pli=0;pli<3;pli++){
-    int y_procd;
-    int y_avail;
-    /*Compute how far we can get in complete fragment rows.*/
-    y_procd=_stage->y_procd[pli];
-    /*Add an (OC_MASK_WINDOW_SZ_MAX-1) delay.*/
-    y_avail=(_y_avail[pli]&~7)-(o<<3);
-    /*Perform CSF filtering on any newly available rows.*/
-    while(y_avail>y_procd){
-      oc_weight_block  *csfw_row;
-      oc_weight_block  *maskw_row;
-      oc_mask_block   **mask_groups;
-      oc_mask_block    *maskg_row;
-      int               rowi;
-      mask_groups=psych->mask_groups[pli];
-      if(y_procd>0){
-        oc_fragment_plane    *fplane;
-        oc_fragment_enc_info *efrag;
-        oc_mask_block         group_sums;
-        float                *csf_offset;
-        float                *csfw;
-        float                *maskw;
-        float                 fscale;
-        float                 pscale;
-        int                   fragx;
-        int                   mfragi;
-        int                   mfragj;
-        int                   qti;
-        int                   gi;
-        int                   wi;
-        int                   wj;
-        int                   ci;
-        pscale=OC_YCbCr_SCALE[psych->enc->state.info.colorspace][pli];
-        csf_offset=psych->csf_offsets[pli];
-        maskw_row=psych->mask_weights[pli][0];
-        csfw_row=psych->csf_weights[pli][0];
-        for(gi=0;gi<OC_MASK_NFULL_GROUPS;gi++){
-          group_sums[gi]=0;
-          for(wi=o-OC_MASK_WINDOW_SIZES[gi];wi<=o+OC_MASK_WINDOW_SIZES[gi];wi++){
-            for(wj=o;wj<o+OC_MASK_WINDOW_SIZES[gi];wj++){
-              group_sums[gi]+=mask_groups[wi][wj][gi];
-            }
-          }
-        }
-        fplane=psych->enc->state.fplanes+pli;
-        mfragi=fplane->froffset+(y_procd>>3)*fplane->nhfrags;
-        for(fragx=0;fragx<fplane->nhfrags;fragx++,mfragi++){
-          /*Add the parts of the group neighborhoods that are new.*/
-          mfragj=fragx+OC_MASK_WINDOW_SZ_MAX-1;
-          for(gi=0;gi<OC_MASK_NFULL_GROUPS;gi++){
-            wj=OC_MASK_WINDOW_SIZES[gi];
-            for(wi=o-wj;wi<=o+wj;wi++){
-              group_sums[gi]+=mask_groups[wi][mfragj+wj][gi];
-            }
-          }
-          /*These groups are so small it is not worth incremental updates.*/
-          for(;gi<OC_MASK_NGROUPS;gi++){
-            group_sums[gi]=mask_groups[o][mfragj][gi]+
-             mask_groups[o-1][mfragj][gi]+mask_groups[o+1][mfragj][gi]+
-             mask_groups[o][mfragj-1][gi]+mask_groups[o][mfragj+1][gi];
-          }
-          /*Mask the coefficients in this block.*/
-          /*An offset is added to the numerator and denominator to prevent
-             against division by zero.
-            In effect, this is like a small addition of noise to the signal, but
-             it should be well below the visual threshold.
-            This is the best solution I could come up with to handle the problem
-             of 0's in the intra DCT coefficients that, because of motion
-             compensation, are not 0 in the inter DCT coefficients and thus need
-             a valid weight.
-            The DC coefficient has a different offset added than the others,
-             because the pixel values have 128 subtracted from them before the
-             DCT is performed, which offsets the DC coefficient by 4096.*/
-          efrag=psych->enc->frinfo+mfragi;
-          csfw=psych->csf_row[fragx];
-          maskw=maskw_row[fragx];
-          /*Compute the scaling value for this fragment.*/
-          fscale=pscale*efrag->imp_weight/psych->enc->vbr->qscale;
-          /*The DC coefficient is not masked.*/
-          efrag->tols[0]=(ogg_uint16_t)OC_MINI(65535,(int)(
-           (OC_CSF_DC_SHIFT+abs(efrag->dct_coeffs[0]))/
-           (fscale*(csf_offset[0]+csfw[0]))));
-          psych->enc->vbr->dc_tol_mins[pli]=(unsigned)OC_MINI(
-           psych->enc->vbr->dc_tol_mins[pli],efrag->tols[0]);
-          /*The remaining coefficients are masked.*/
-          for(ci=1;ci<64;ci++){
-            float mask;
-            gi=OC_MASK_GROUP[ci];
-            mask=group_sums[gi]-maskw[ci];
-            efrag->tols[ci]=(ogg_uint16_t)OC_MINI(65535,(int)(
-             ((OC_CSF_NOISE_LEVEL+abs(efrag->dct_coeffs[ci]))*
-             (1+OC_MASK_WEIGHTS[gi]*mask))/
-             (fscale*(csf_offset[ci]+csfw[ci]))));
-          }
-          /*Select minimum qi values for each quantizer type.*/
-          for(qti=2;qti-->0;){
-            unsigned qmin;
-            int      qi_min;
-            /*This is the minimum quantizer Theora allows.
-              Don't inflate the qi unnecessarily if we have a tolerance less
-               than this.*/
-            qmin=OC_AC_QUANT_MIN[qti];
-            qi_min=qti?0:efrag->qi_min[1];
-            for(ci=0;qi_min<63;qi_min++){
-              while(psych->enc->state.dequant_tables[qti][pli][qi_min][ci]<=
-               OC_MAXI(2U*efrag->tols[ci],qmin)&&++ci<64);
-              if(ci==64)break;
-            }
-            efrag->qi_min[qti]=(unsigned char)qi_min;
-          }
-  #if 0
-          /*Now undo all the work we did above and just use a constant quantizer
-             value for testing purposes.*/
-          efrag->qi_min[0]=efrag->qi_min[1]=_psych->enc->state.info.quality;
-          for(ci=0;ci<64;ci++){
-            efrag->tols[ci]=OC_MINI(
-             psych->enc->state.dequant_tables[0][pli][efrag->qi_min[0]][ci],
-             psych->enc->state.dequant_tables[1][pli][efrag->qi_min[1]][ci])+
-             1>>1;
-          }
-  #endif
-          /*Remove the parts of the group neighborhoods that are old.*/
-          for(gi=0;gi<OC_MASK_NFULL_GROUPS;gi++){
-            wj=OC_MASK_WINDOW_SIZES[gi];
-            for(wi=o-wj;wi<=o+wj;wi++){
-              group_sums[gi]-=mask_groups[wi][mfragj-wj][gi];
-            }
-          }
-        }
-      }
-      /*Move the sliding windows.
-        The nice thing about these manually allocated 2D arrays is that we can
-         move rows around just by moving around the initial pointers to them,
-         not actually copying their contents.*/
-      maskg_row=mask_groups[0];
-      for(rowi=0;rowi<OC_MASK_WINDOW_SZ_MAX-1<<1;rowi++){
-        mask_groups[rowi]=mask_groups[rowi+1];
-      }
-      mask_groups[OC_MASK_WINDOW_SZ_MAX-1<<1]=maskg_row;
-      maskw_row=psych->mask_weights[pli][0];
-      csfw_row=psych->csf_weights[pli][0];
-      for(rowi=0;rowi<OC_MASK_WINDOW_SZ_MAX-1;rowi++){
-        psych->mask_weights[pli][rowi]=psych->mask_weights[pli][rowi+1];
-        psych->csf_weights[pli][rowi]=psych->csf_weights[pli][rowi+1];
-      }
-      psych->mask_weights[pli][OC_MASK_WINDOW_SZ_MAX-1]=maskw_row;
-      psych->csf_weights[pli][OC_MASK_WINDOW_SZ_MAX-1]=csfw_row;
-      y_procd+=8;
-    }
-    _stage->y_procd[pli]=y_procd;
-  }
-  return 0;
-}
-
-static int oc_mask_pipe_end(oc_enc_pipe_stage *_stage){
-  oc_psych_ctx *psych;
-  int           y_avail[3];
-  int           rowi;
-  int           pli;
-  int           ret;
-  psych=_stage->enc->vbr->psych;
-  /*To finish up this stage, we need to keep the sliding windows sliding, so
-     we make a separate call to pipe_process() for each row.*/
-  for(pli=0;pli<3;pli++)y_avail[pli]=_stage->enc->state.input[pli].height;
-  for(rowi=OC_MASK_WINDOW_SZ_MAX-1;rowi-->0;){
-    for(pli=0;pli<3;pli++){
-      oc_fragment_plane *fplane;
-      fplane=psych->enc->state.fplanes+pli;
-      /*Just clear out the mask group weights for the rows below the image.*/
-      memset(psych->mask_groups[pli][OC_MASK_WINDOW_SZ_MAX-1<<1][0],0,
-       sizeof(oc_mask_block)*(fplane->nhfrags+(OC_MASK_WINDOW_SZ_MAX-1<<1)));
-      y_avail[pli]+=8;
-    }
-    ret=oc_mask_pipe_process(_stage,y_avail);
-    if(ret<0)return ret;
-  }
-  /*Because dc_tol_mins[] is not complete until each plane has been completely
-     processed, we wait until then to execute the next pipeline stage.*/
-  if(_stage->next!=NULL){
-    ret=(*_stage->next->pipe_start)(_stage->next);
-    if(ret<0)return ret;
-    ret=(*_stage->next->pipe_proc)(_stage->next,_stage->y_procd);
-    if(ret<0)return ret;
-    return (*_stage->next->pipe_end)(_stage->next);
-  }
-  return 0;
-}
-
-/*Initialize the spatial masking stage of the pipeline.
-  _enc: The encoding context.*/
-static void oc_mask_pipe_init(oc_enc_pipe_stage *_stage,oc_enc_ctx *_enc){
-  _stage->enc=_enc;
-  _stage->next=NULL;
-  _stage->pipe_start=oc_mask_pipe_start;
-  _stage->pipe_proc=oc_mask_pipe_process;
-  _stage->pipe_end=oc_mask_pipe_end;
-}
-
-#if 0
-static void oc_psych_scan_plane(oc_psych_ctx *_psych,int _pli){
-  oc_csf_filter        *vfilters;
-  oc_csf_filter        *hfilters;
-  oc_fragment_plane    *fplane;
-  oc_fragment          *frags;
-  oc_fragment_enc_info *efrags;
-  oc_fragment_enc_info *efrag;
-  oc_mask_block        *maskg_row;
-  oc_weight_block      *maskw_row;
-  oc_weight_block      *csfw_row;
-  float                *csfw;
-  float                *maskw;
-  float                *maskg;
-  float                *csf_offset;
-  float                 pscale;
-  float                 fscale;
-  int                  *vsizes;
-  int                  *hsizes;
-  int                   vfilti;
-  int                   hfilti;
-  int                   filti;
-  int                   vsize_max;
-  int                   ystride;
-  int                   fragx;
-  int                   fragy;
-  int                   fragy_end;
-  int                   fragi_end;
-  int                   dfragi;
-  int                   cfragi;
-  int                   cfragj;
-  int                   mfragi;
-  int                   mfragj;
-  int                   qti;
-  int                   i;
-  int                   j;
-  int                   k;
-  csf_offset=_psych->csf_offsets[_pli];
-  /*Initialize the minimum psychovisual tolerance for the DC coefficient.*/
-  _psych->enc->vbr->dc_tol_mins[_pli]=32767;
-  /*Select the filter sets we're going to use.*/
-  vfilti=_pli<<1;
-  hfilti=_pli>0?(_pli<<1)-1:0;
-  vfilters=_psych->csf_filters[vfilti];
-  vsizes=_psych->csf_filter_sizes[vfilti];
-  hfilters=_psych->csf_filters[hfilti];
-  hsizes=_psych->csf_filter_sizes[hfilti];
-  /*Find the number of rows we have to perform DCTs in advance.*/
-  vsize_max=0;
-  for(i=0;i<8;i++)if(vsizes[i]>vsize_max)vsize_max=vsizes[i];
-  fplane=_psych->enc->state.fplanes+_pli;
-  frags=_psych->enc->state.frags;
-  efrags=_psych->enc->frinfo;
-  ystride=_psych->enc->state.input[_pli].ystride;
-  pscale=OC_YCbCr_SCALE[_psych->enc->state.info.colorspace][_pli];
-  /*Clear out the mask group weights for the rows above the image.*/
-  for(i=(OC_MASK_WINDOW_SZ_MAX-2<<1)-vsize_max;i<OC_MASK_WINDOW_SZ_MAX-1<<1;
-   i++){
-    memset(_psych->mask_groups[i][0],0,sizeof(oc_mask_block)*(
-     fplane->nhfrags+(OC_MASK_WINDOW_SZ_MAX-1<<1)));
-  }
-  /*Run each of the filters over the rows, with a suitable delay between
-     each.*/
-  fragy_end=fplane->nvfrags+vsize_max+OC_MASK_WINDOW_SZ_MAX-1;
-  fragi_end=fplane->froffset+fplane->nfrags;
-  dfragi=cfragi=mfragi=fplane->froffset;
-  for(fragy=0;fragy<fragy_end;fragy++){
-    /*Perform DCTs.*/
-    /*TODO: Move this out of here.
-      Yes, this is the first place it's needed, but it's needed in other
-       places too and conceptually does not belong to the psychovisual
-       model.*/
-    if(fragy<fplane->nvfrags){
-      for(fragx=0;fragx<fplane->nhfrags;fragx++,dfragi++){
-        if(frags[dfragi].invalid)continue;
-        oc_enc_frag_intra_fdct(_psych->enc,
-         frags+dfragi,efrags[dfragi].dct_coeffs,ystride,OC_FRAME_IO);
-      }
-    }
-    /*After a vsize_max delay, perform CSF filtering.*/
-    if(fragy>=vsize_max&&fragy<fplane->nvfrags+vsize_max){
-      int chfragi;
-      /*First, the vertical filter.*/
-      for(fragx=0,chfragi=cfragi;fragx<fplane->nhfrags;fragx++,chfragi++){
-        int fragi_off;
-        csfw=_psych->csf_row[fragx+OC_CSF_FILTER_SZ_MAX-1];
-        for(i=0;i<64;i++){
-          filti=i>>3;
-          csfw[i]=vfilters[filti][0]*efrags[chfragi].dct_coeffs[i];
-          fragi_off=fplane->nhfrags;
-          for(j=vsizes[filti];j>0;j--){
-            int coeffs;
-            int cvfragi;
-            cvfragi=chfragi-fragi_off;
-            coeffs=cvfragi>=fplane->froffset?efrags[cvfragi].dct_coeffs[i]:0;
-            cvfragi=chfragi+fragi_off;
-            if(cvfragi<fragi_end)coeffs+=efrags[cvfragi].dct_coeffs[i];
-            csfw[i]+=0.5F*vfilters[filti][j]*coeffs;
-            fragi_off+=fplane->nhfrags;
-          }
-        }
-      }
-      /*Next, the horizontal filtering.*/
-      maskg_row=_psych->mask_groups[OC_MASK_WINDOW_SZ_MAX-1<<1];
-      maskw_row=_psych->mask_weights[OC_MASK_WINDOW_SZ_MAX-1];
-      csfw_row=_psych->csf_weights[OC_MASK_WINDOW_SZ_MAX-1];
-      memset(maskg_row[0],0,sizeof(maskg_row[0])*(
-       fplane->nhfrags+(OC_MASK_WINDOW_SZ_MAX-1<<1)));
-      for(fragx=0;fragx<fplane->nhfrags;fragx++,cfragi++){
-        csfw=csfw_row[fragx];
-        if(frags[cfragi].invalid)memset(csfw,0,sizeof(oc_weight_block));
-        else{
-          cfragj=fragx+OC_CSF_FILTER_SZ_MAX-1;
-          mfragj=fragx+OC_MASK_WINDOW_SZ_MAX-1;
-          for(i=0;i<64;i++){
-            filti=i&7;
-            csfw[i]=hfilters[filti][0]*_psych->csf_row[cfragj][i];
-            for(j=hsizes[filti];j>0;j--){
-              csfw[i]+=0.5F*hfilters[filti][j]*(
-               _psych->csf_row[cfragj-j][i]+_psych->csf_row[cfragj+j][i]);
-            }
-            csfw[i]=OC_FABSF(csfw[i]);
-          }
-          maskw=maskw_row[fragx];
-          maskg=maskg_row[mfragj];
-          for(i=1;i<64;i++){
-            maskw[i]=OC_POWF(csfw[i],OC_MASK_NU);
-            maskg[OC_MASK_GROUP[i]]+=maskw[i];
-          }
-        }
-      }
-    }
-    else{
-      /*Clear out the mask group weights for the rows below the image.*/
-      memset(_psych->mask_groups[OC_MASK_WINDOW_SZ_MAX-1<<1][0],0,
-       sizeof(oc_mask_block)*(fplane->nhfrags+(OC_MASK_WINDOW_SZ_MAX-1<<1)));
-    }
-    /*After an additional OC_MASK_WINDOW_SZ_MAX delay, perform neighborhood
-       masking.*/
-    if(fragy>=vsize_max+OC_MASK_WINDOW_SZ_MAX-1){
-      static const int o=OC_MASK_WINDOW_SZ_MAX-1;
-      oc_mask_block group_sums;
-      for(i=0;i<OC_MASK_NFULL_GROUPS;i++){
-        group_sums[i]=0;
-        for(j=o-OC_MASK_WINDOW_SIZES[i];j<=o+OC_MASK_WINDOW_SIZES[i];j++){
-          for(k=o;k<o+OC_MASK_WINDOW_SIZES[i];k++){
-            group_sums[i]+=_psych->mask_groups[j][k][i];
-          }
-        }
-      }
-      maskw_row=_psych->mask_weights[0];
-      for(fragx=0;fragx<fplane->nhfrags;fragx++,mfragi++){
-        /*Add the parts of the group neighborhoods that are new.*/
-        mfragj=fragx+OC_MASK_WINDOW_SZ_MAX-1;
-        for(i=0;i<OC_MASK_NFULL_GROUPS;i++){
-          k=OC_MASK_WINDOW_SIZES[i];
-          for(j=o-k;j<=o+k;j++){
-            group_sums[i]+=_psych->mask_groups[j][mfragj+k][i];
-          }
-        }
-        /*These groups are so small it is not worth incremental updates.*/
-        for(;i<OC_MASK_NGROUPS;i++){
-          group_sums[i]=_psych->mask_groups[o][mfragj][i]+
-           _psych->mask_groups[o-1][mfragj][i]+
-           _psych->mask_groups[o+1][mfragj][i]+
-           _psych->mask_groups[o][mfragj-1][i]+
-           _psych->mask_groups[o][mfragj+1][i];
-        }
-        /*Mask the coefficients in this block.*/
-        /*An offset is added to the numerator and denominator to prevent
-           against division by zero.
-          In effect, this is like a small addition of noise to the signal, but
-           it should be well below the visual threshold.
-          This is the best solution I could come up with to handle the problem
-           of 0's in the inter DCT coefficients that, because of motion
-           compensation, are not 0 in the intra DCT coefficients and thus
-           need a valid weight.
-          The DC coefficient has a different offset added than the others,
-           because the pixel values have 128 subtracted from them before the
-           DCT is performed, which offsets the DC coefficient by 4096.*/
-        efrag=efrags+mfragi;
-        csfw=_psych->csf_weights[0][fragx];
-        maskw=maskw_row[fragx];
-        /*Compute the scaling value for this fragment.*/
-        fscale=pscale*efrag->imp_weight/_psych->enc->vbr->qscale;
-        /*The DC coefficient is not masked.*/
-        efrag->tols[0]=(ogg_uint16_t)OC_MINI(65535,(int)(
-         (OC_CSF_DC_SHIFT+abs(efrag->dct_coeffs[0]))/
-         (fscale*(csf_offset[0]+csfw[0]))));
-        _psych->enc->vbr->dc_tol_mins[_pli]=(unsigned)OC_MINI(
-         _psych->enc->vbr->dc_tol_mins[_pli],efrag->tols[0]);
-        /*The remaining coefficients are masked.*/
-        for(i=1;i<64;i++){
-          float mask;
-          int   groupi;
-          groupi=OC_MASK_GROUP[i];
-          mask=group_sums[groupi]-maskw[i];
-          efrag->tols[i]=(ogg_uint16_t)OC_MINI(65535,(int)(
-           ((OC_CSF_NOISE_LEVEL+abs(efrag->dct_coeffs[i]))*
-           (1+OC_MASK_WEIGHTS[groupi]*mask))/
-           (fscale*(csf_offset[i]+csfw[i]))));
-        }
-        /*Select minimum qi values for each quantizer type.*/
-        for(qti=2;qti-->0;){
-          unsigned qmin;
-          int      qi_min;
-          /*This is the minimum quantizer Theora allows.
-            Don't inflate the qi unnecessarily if we have a tolerance less
-             than this.*/
-          qmin=OC_AC_QUANT_MIN[qti];
-          qi_min=qti?0:efrag->qi_min[1];
-          for(i=0;qi_min<63;qi_min++){
-            while(_psych->enc->state.dequant_tables[qti][_pli][qi_min][i]<=
-             OC_MAXI(2U*efrag->tols[i],qmin)&&++i<64);
-            if(i==64)break;
-          }
-          efrag->qi_min[qti]=(unsigned char)qi_min;
-        }
-#if 0
-        /*Now undo all the work we did above and just use a constant quantizer
-           value for testing purposes.*/
-        efrag->qi_min[0]=efrag->qi_min[1]=_psych->enc->state.info.quality;
-        for(i=0;i<64;i++){
-          efrag->tols[i]=OC_MINI(
-           _psych->enc->state.dequant_tables[0][_pli][efrag->qi_min[0]][i],
-           _psych->enc->state.dequant_tables[1][_pli][efrag->qi_min[1]][i])+
-           1>>1;
-        }
-#endif
-        /*Remove the parts of the group neighborhoods that are old.*/
-        for(i=0;i<OC_MASK_NFULL_GROUPS;i++){
-          k=OC_MASK_WINDOW_SIZES[i];
-          for(j=o-k;j<=o+k;j++){
-            group_sums[i]-=_psych->mask_groups[j][mfragj-k][i];
-          }
-        }
-      }
-    }
-    /*Move the sliding windows.
-      The nice thing about these manually allocated 2D arrays is that we can
-       move rows around just by moving around the initial pointers to them,
-       not actually copying their contents.*/
-    maskg_row=_psych->mask_groups[0];
-    for(i=0;i<OC_MASK_WINDOW_SZ_MAX-1<<1;i++){
-      _psych->mask_groups[i]=_psych->mask_groups[i+1];
-    }
-    _psych->mask_groups[OC_MASK_WINDOW_SZ_MAX-1<<1]=maskg_row;
-    maskw_row=_psych->mask_weights[0];
-    csfw_row=_psych->csf_weights[0];
-    for(i=0;i<OC_MASK_WINDOW_SZ_MAX-1;i++){
-      _psych->mask_weights[i]=_psych->mask_weights[i+1];
-      _psych->csf_weights[i]=_psych->csf_weights[i+1];
-    }
-    _psych->mask_weights[OC_MASK_WINDOW_SZ_MAX-1]=maskw_row;
-    _psych->csf_weights[OC_MASK_WINDOW_SZ_MAX-1]=csfw_row;
-  }
-}
-#endif
-
-
-oc_psych_ctx *oc_psych_alloc(oc_enc_ctx *_enc){
-  oc_psych_ctx *psych;
-  int           nhfrags;
-  int           pli;
-  nhfrags=_enc->state.fplanes[0].nhfrags;
-  psych=(oc_psych_ctx *)_ogg_malloc(sizeof(*psych));
-  psych->csf_row=(oc_weight_block *)_ogg_calloc(
-   (nhfrags+(OC_CSF_FILTER_SZ_MAX-1<<1)),sizeof(psych->csf_row[0]));
-  for(pli=0;pli<3;pli++){
-    nhfrags=_enc->state.fplanes[pli].nhfrags;
-    psych->csf_weights[pli]=(oc_weight_block **)oc_malloc_2d(
-     OC_MASK_WINDOW_SZ_MAX,nhfrags,sizeof(oc_weight_block));
-    psych->mask_groups[pli]=(oc_mask_block **)oc_malloc_2d(
-     (OC_MASK_WINDOW_SZ_MAX<<1)-1,nhfrags+(OC_MASK_WINDOW_SZ_MAX-1<<1),
-     sizeof(oc_mask_block));
-    psych->mask_weights[pli]=(oc_weight_block **)oc_malloc_2d(
-     OC_MASK_WINDOW_SZ_MAX,nhfrags,sizeof(oc_weight_block));
-  }
-  psych->enc=_enc;
-  /*Initialize our pipeline stages.*/
-  oc_csf_pipe_init(&psych->csf_pipe,_enc);
-  oc_mask_pipe_init(&psych->mask_pipe,_enc);
-  psych->csf_pipe.next=&psych->mask_pipe;
-  return psych;
-}
-
-void oc_psych_free(oc_psych_ctx *_psych){
-  if(_psych!=NULL){
-    int pli;
-    _ogg_free(_psych->csf_row);
-    for(pli=0;pli<3;pli++){
-      oc_free_2d((void **)_psych->csf_weights[pli]);
-      oc_free_2d((void **)_psych->mask_groups[pli]);
-      oc_free_2d((void **)_psych->mask_weights[pli]);
-    }
-    _ogg_free(_psych);
-  }
-}
-
-oc_enc_pipe_stage *oc_psych_prepend_to_pipe(oc_psych_ctx *_psych,
- oc_enc_pipe_stage *_next){
-  _psych->mask_pipe.next=_next;
-  return &_psych->csf_pipe;
-}
-
-#if 0
-void oc_psych_scan(oc_psych_ctx *_psych,float _contrast){
-  int pli;
-  oc_psych_csf_filters_interpolate(_psych,_contrast);
-  for(pli=0;pli<3;pli++)oc_psych_scan_plane(_psych,pli);
-}
-#endif

Deleted: experimental/j/theora-mashup/lib/dec/psych.h
===================================================================
--- experimental/j/theora-mashup/lib/dec/psych.h	2007-03-13 11:41:53 UTC (rev 12749)
+++ experimental/j/theora-mashup/lib/dec/psych.h	2007-03-13 14:34:17 UTC (rev 12750)
@@ -1,18 +0,0 @@
-#if !defined(_psych_H)
-# define _psych_H (1)
-# include "encvbr.h"
-
-/*The assumed screen resolution vs. viewing distance.
-  This is taken to be constant under the assumption that viewers will sit
-   closer to higher resolution images, and farther from lower resolution ones.
-  This value corresponds to roughly 50 cm from an 44 pixel/inch display, and
-   is measured over a 1 degree arc around the perpendicular to the display
-   surface (i.e., the maximum resolution).*/
-#define OC_PIXELS_PER_DEGREE (15)
-
-/*The weightings of each color channel for each color space.
-  These are computed such that after weighting, a value of 1.0
-   roughly corresponds to a Just Noticible Difference.*/
-extern const float OC_YCbCr_SCALE[3][3];
-
-#endif



More information about the commits mailing list