diff options
author | Mike Melanson <mike@multimedia.cx> | 2004-03-14 21:27:03 +0000 |
---|---|---|
committer | Mike Melanson <mike@multimedia.cx> | 2004-03-14 21:27:03 +0000 |
commit | 5ece915e5903946b2aeab11640a19410f62870b9 (patch) | |
tree | 5d98979221fc3e26256bae46bc4a11db29a3a003 | |
parent | ebab86a8bee668e60d312ebd0536661388ce7dc1 (diff) | |
download | xine-lib-5ece915e5903946b2aeab11640a19410f62870b9.tar.gz xine-lib-5ece915e5903946b2aeab11640a19410f62870b9.tar.bz2 |
goodbye decoders-- you have served your purpose well and we salute you
CVS patchset: 6256
CVS date: 2004/03/14 21:27:03
-rw-r--r-- | src/libxineadec/28k8.c | 555 | ||||
-rw-r--r-- | src/libxineadec/Makefile.am | 27 | ||||
-rw-r--r-- | src/libxineadec/adpcm.c | 1687 | ||||
-rw-r--r-- | src/libxineadec/interplayaudio.c | 357 | ||||
-rw-r--r-- | src/libxineadec/logpcm.c | 312 | ||||
-rw-r--r-- | src/libxineadec/roqaudio.c | 242 | ||||
-rw-r--r-- | src/libxinevdec/Makefile.am | 69 | ||||
-rw-r--r-- | src/libxinevdec/cinepak.c | 566 | ||||
-rw-r--r-- | src/libxinevdec/cyuv.c | 288 | ||||
-rw-r--r-- | src/libxinevdec/fli.c | 602 | ||||
-rw-r--r-- | src/libxinevdec/idcinvideo.c | 408 | ||||
-rw-r--r-- | src/libxinevdec/interplayvideo.c | 1388 | ||||
-rw-r--r-- | src/libxinevdec/msrle.c | 377 | ||||
-rw-r--r-- | src/libxinevdec/msvc.c | 415 | ||||
-rw-r--r-- | src/libxinevdec/qtrle.c | 1040 | ||||
-rw-r--r-- | src/libxinevdec/qtrpza.c | 465 | ||||
-rw-r--r-- | src/libxinevdec/qtsmc.c | 698 | ||||
-rw-r--r-- | src/libxinevdec/roqvideo.c | 578 | ||||
-rw-r--r-- | src/libxinevdec/svq1.c | 1507 | ||||
-rw-r--r-- | src/libxinevdec/svq1_codebooks.h | 1506 | ||||
-rw-r--r-- | src/libxinevdec/wc3video.c | 539 |
21 files changed, 2 insertions, 13624 deletions
diff --git a/src/libxineadec/28k8.c b/src/libxineadec/28k8.c deleted file mode 100644 index f8c51d59c..000000000 --- a/src/libxineadec/28k8.c +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Copyright (C) 2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * RealAudio 28k8 Decoder by Ewald Snel <ewald@rambo.its.tudelft.nl> - * - * Based on public domain source code from: - * http://www.honeypot.net/audio/ - * - * $Id: 28k8.c,v 1.7 2004/01/12 17:35:17 miguelfreitas Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> -#include <math.h> - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" - -#define SUBBLOCK 38 -#define BLOCKSIZE 2736 - -typedef struct { - audio_decoder_class_t decoder_class; -} ra28k8_class_t; - -typedef struct ra28k8_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int output_open; - int decoder_ok; - - unsigned char buf[BLOCKSIZE]; - int size; - - float sb[41]; - float lhist[10]; - float output[40]; - float pr1[36]; - float st1a[111]; - float st1b[37]; - float st1[37]; - float pr2[10]; - float st2a[38]; - float st2b[11]; - float st2[11]; - -} ra28k8_decoder_t; - - -static const float ra28k8_amptable[8] = { - 0.515625, 0.90234375, 1.57910156, 2.76342773, - -0.515625,-0.90234375,-1.57910156,-2.76342773 -}; - -static const float ra28k8_codetable[128][5] = { - { 0.326171875, -1.4404296875, -0.6123046875, -0.8740234375, -1.24658203125 }, - { -2.45703125, -2.23486328125,-0.51025390625, 1.419921875, 1.6201171875 }, - { -1.37646484375,-1.30712890625,-0.462890625, -1.37939453125,-2.1728515625 }, - { -3.26123046875,-0.166015625, 0.7236328125, -0.623046875, 0.6162109375 }, - { -0.2744140625, -3.29931640625, 0.62548828125, 0.08740234375,-0.6220703125 }, - { -1.2265625, -3.4814453125, -2.40478515625, 3.37548828125, 1.17724609375 }, - { -1.2099609375, -0.076171875, 2.28662109375,-1.89111328125, 0 }, - { -4.0078125, 1.044921875, -0.2333984375, -1.35986328125, 0.26025390625 }, - { 0.92236328125, 1.34716796875, 0.67431640625,-3.39599609375,-2.88720703125 }, - { 2.4814453125, -1.201171875, -2.8212890625, 0.87744140625, 0.27734375 }, - { -1.078125, -1.61572265625,-2.20849609375,-3.044921875, -3.66455078125 }, - { -1.32763671875, 2.1279296875, -1.458984375, -0.56103515625, 1.30078125 }, - { 0.61474609375, 0.48583984375, 1.32373046875,-1.203125, -5.0732421875 }, - { 0.8408203125, -3.69580078125,-1.3388671875, 1.06005859375,-1.13720703125 }, - { 0.50390625, 0.36474609375,-0.4189453125, -3.8798828125, -6.27099609375 }, - { 1.5166015625, 2.37109375, -2.04736328125,-1.24072265625, 0.50537109375 }, - { 0.9091796875, -0.46875, -3.236328125, 0.2001953125, 2.8720703125 }, - { -1.21728515625,-1.283203125, -1.953125, -0.029296875, 3.5166015625 }, - { -1.3046875, 0.7060546875, 0.75, -1.87060546875, 0.60205078125 }, - { -2.5888671875, 3.375, 0.77587890625,-2.04443359375, 1.78955078125 }, - { -1.6875, -3.9892578125, -3.76416015625, 0.67578125, 2.2939453125 }, - { -2.29443359375,-3.03173828125,-5.45703125, 3.95703125, 8.2177734375 }, - { 0.4541015625, 3.419921875, 0.61962890625,-4.38330078125, 1.25341796875 }, - { 2.27001953125, 5.763671875, 1.68017578125,-2.76220703125, 0.58544921875 }, - { 1.2412109375, -0.08935546875,-4.32568359375,-3.89453125, 1.5771484375 }, - { -1.40234375, -0.98193359375,-4.74267578125,-4.09423828125, 6.33935546875 }, - { 1.5068359375, 1.044921875, -1.796875, -4.70849609375,-1.4140625 }, - { -3.71533203125, 3.18115234375,-1.11474609375,-1.2314453125, 3.091796875 }, - { -1.62744140625,-2.744140625, -4.4580078125, -5.43505859375, 2.70654296875 }, - { -0.19873046875,-3.28173828125,-8.5283203125, -1.41064453125, 5.6484375 }, - { 1.802734375, 3.318359375, -0.1279296875, -5.2958984375, -0.90625 }, - { 3.55224609375, 6.544921875, -1.45947265625,-5.17333984375, 2.41015625 }, - { 0.119140625, -1.08349609375, 1.296875, 1.84375, -2.642578125 }, - { -1.97412109375,-2.8974609375, 1.04052734375, 0.42138671875,-1.3994140625 }, - { -1.6123046875, 0.85107421875,-0.9794921875, -0.0625, -1.001953125 }, - { -3.10595703125, 1.6318359375, -0.77294921875,-0.01025390625, 0.5576171875 }, - { -1.87353515625,-0.89404296875, 3.12353515625, 1.24267578125,-1.390625 }, - { -4.556640625, -3.1875, 2.59228515625, 0.9697265625, -1.09619140625 }, - { -2.1923828125, 0.365234375, 0.94482421875,-1.47802734375,-0.24072265625 }, - { -4.51904296875, 2.6201171875, 1.55908203125,-2.19384765625, 0.87109375 }, - { 2.3359375, -0.1806640625, 0.9111328125, 0.51611328125,-0.92236328125 }, - { 3.5849609375, -1.3134765625, -1.25830078125, 0.330078125, -0.29833984375 }, - { -0.2451171875, 1.09130859375,-0.9033203125, -0.86767578125,-1.00048828125 }, - { 0.49365234375, 1.89453125, -1.20361328125, 1.07861328125,-0.07421875 }, - { 1.265625, 1.38134765625, 2.728515625, 1.38623046875,-3.5673828125 }, - { -1.48876953125,-2.4013671875, 2.90771484375, 4.49267578125,-2.17138671875 }, - { 0.34033203125, 1.908203125, 2.8310546875, -2.17333984375,-2.267578125 }, - { -1.03564453125, 2.658203125, -1.2548828125, 0.15673828125,-0.5869140625 }, - { 1.3896484375, -1.0185546875, 1.724609375, 0.2763671875, -0.345703125 }, - { -2.08935546875, 0.4638671875, 2.431640625, 1.83056640625, 0.220703125 }, - { -1.212890625, 1.7099609375, 0.83935546875,-0.0830078125, 0.1162109375 }, - { -1.67724609375, 0.12841796875, 1.0322265625, -0.97900390625, 1.15283203125 }, - { -3.5830078125, -0.58984375, 4.56396484375,-0.59375, -1.95947265625 }, - { -6.5908203125, -0.21435546875, 3.919921875, -2.06640625, 0.17626953125 }, - { -1.82080078125, 2.65283203125, 0.978515625, -2.30810546875,-0.61474609375 }, - { -1.9462890625, 3.78076171875, 4.11572265625,-1.80224609375,-0.48193359375 }, - { 2.5380859375, -0.20654296875, 0.5615234375, -0.62548828125, 0.3984375 }, - { 3.61767578125, 2.00634765625,-1.92822265625, 1.3134765625, 0.0146484384313 }, - { 0.6083984375, 1.49169921875,-0.01708984375,-0.6689453125, -0.1201171875 }, - { -0.72705078125, 2.75146484375,-0.3310546875, -1.28271484375, 1.5478515625 }, - { 2.3583984375, -2.23876953125, 0.98046875, -0.5185546875, 0.39013671875 }, - { -0.06298828125, 0.35009765625, 2.2431640625, 7.29345703125, 5.2275390625 }, - { 0.20361328125, 1.34716796875, 0.9033203125, -2.46923828125,-0.56298828125 }, - { -1.89794921875, 3.59423828125,-2.81640625, 2.09228515625, 0.3251953125 }, - { 0.70458984375,-0.4580078125, 0.009765625, -1.03466796875,-0.82861328125 }, - { -1.8125, -1.6611328125, -1.080078125, 0.0537109375, 1.04296875 }, - { -1.44140625, 0.005859375, -0.765625, -1.708984375, -0.90576171875 }, - { -0.64208984375,-0.84521484375, 0.56640625, -0.2724609375, 0.83447265625 }, - { 0.04296875, -2.23095703125, 0.0947265625, -0.2216796875, -1.44384765625 }, - { -1.38623046875,-0.8134765625, -0.13330078125, 1.017578125, -0.07568359375 }, - { -0.09228515625,-1.16015625, 0.81201171875,-0.5078125, -1.19580078125 }, - { -1.3876953125, -0.66845703125, 0.310546875, -0.12109375, -1.30712890625 }, - { 0.74072265625, 0.03857421875,-1.47119140625,-1.79150390625,-0.47509765625 }, - { 0.93408203125,-1.21728515625,-2.59375, -0.36572265625, 0.62060546875 }, - { -1.41748046875,-1.623046875, -1.833984375, -1.8017578125, -0.89306640625 }, - { -1.42236328125,-0.75537109375,-1.34765625, -0.6865234375, 0.548828125 }, - { 0.900390625, -0.8955078125, 0.22265625, 0.3447265625, -2.0859375 }, - { 0.22802734375,-2.078125, -0.93212890625, 0.74267578125, 0.5537109375 }, - { -0.06201171875,-0.4853515625, -0.31103515625,-0.72802734375,-3.1708984375 }, - { 0.42626953125,-0.99853515625,-1.869140625, -1.36328125, -0.2822265625 }, - { 1.12841796875,-0.88720703125, 1.28515625, -1.490234375, 0.9609375 }, - { 0.31298828125, 0.5830078125, 0.92431640625, 2.00537109375, 3.0966796875 }, - { -0.02197265625, 0.5849609375, 1.0546875, -0.70751953125, 1.07568359375 }, - { -0.978515625, 0.83642578125, 1.7177734375, 1.294921875, 2.07568359375 }, - { 1.43359375, -1.9375, 0.625, 0.06396484375,-0.720703125 }, - { 1.38037109375, 0.00390625, -0.94140625, 1.2978515625, 1.71533203125 }, - { 1.56201171875,-0.3984375, 1.31201171875,-0.85009765625,-0.68701171875 }, - { 1.439453125, 1.96728515625, 0.1923828125, -0.12353515625, 0.6337890625 }, - { 2.0927734375, 0.02490234375,-2.20068359375,-0.015625, -0.32177734375 }, - { 1.90576171875, 2.7568359375, -2.728515625, -1.265625, 2.78662109375 }, - { -0.2958984375, 0.6025390625, -0.78466796875,-2.53271484375, 0.32421875 }, - { -0.25634765625, 1.767578125, -1.0703125, -1.23388671875, 0.83349609375 }, - { 2.09814453125,-1.58740234375,-1.11474609375, 0.396484375, -1.10546875 }, - { 2.81494140625, 0.2578125, -1.60498046875, 0.66015625, 0.81640625 }, - { 1.33544921875, 0.60595703125,-0.53857421875,-1.59814453125,-1.66357421875 }, - { 1.96923828125, 0.8046875, -1.44775390625,-0.5732421875, 0.705078125 }, - { 0.0361328125, 0.4482421875, 0.97607421875, 0.44677734375,-0.5009765625 }, - { -1.21875, -0.78369140625, 0.9931640625, 1.4404296875, 0.11181640625 }, - { -1.05859375, 0.99462890625, 0.00732421921566,-0.6171875, -0.1015625 }, - { -1.734375, 0.7470703125, 0.28369140625, 0.72802734375, 0.4697265625 }, - { -1.27587890625,-1.1416015625, 1.76806640625,-0.7265625, -1.06689453125 }, - { -0.85302734375, 0.03955078125, 2.7041015625, 0.69921875, -1.10205078125 }, - { -0.49755859375, 0.42333984375, 0.1044921875, -1.115234375, -0.7373046875 }, - { -0.822265625, 1.375, -0.11181640625, 1.24560546875,-0.67822265625 }, - { 1.32177734375, 0.24609375, 0.23388671875, 1.35888671875,-0.49267578125 }, - { 1.22900390625,-0.72607421875,-0.779296875, 0.30322265625, 0.94189453125 }, - { -0.072265625, 1.0771484375, -2.09375, 0.630859375, -0.68408203125 }, - { -0.25732421875, 0.60693359375,-1.33349609375, 0.93212890625, 0.625 }, - { 1.04931640625,-0.73291015625, 1.80078125, 0.2978515625, -2.24169921875 }, - { 1.6142578125, -1.64501953125, 0.91552734375, 1.775390625, -0.59423828125 }, - { 1.2568359375, 1.22705078125, 0.70751953125,-1.5009765625, -2.43115234375 }, - { 0.3974609375, 0.8916015625, -1.21923828125, 2.0673828125, -1.99072265625 }, - { 0.8125, -0.107421875, 1.6689453125, 0.4892578125, 0.54443359375 }, - { 0.38134765625, 0.8095703125, 1.91357421875, 2.9931640625, 1.533203125 }, - { 0.560546875, 1.98486328125, 0.740234375, 0.39794921875, 0.09716796875 }, - { 0.58154296875, 1.21533203125, 1.25048828125, 1.18212890625, 1.19287109375 }, - { 0.3759765625, -2.88818359375, 2.69287109375,-0.1796875, -1.56201171875 }, - { 0.5810546875, 0.51123046875, 1.8271484375, 3.38232421875,-1.02001953125 }, - { 0.142578125, 1.51318359375, 2.103515625, -0.3701171875, -1.19873046875 }, - { 0.25537109375, 1.91455078125, 1.974609375, 0.6767578125, 0.04150390625 }, - { 2.13232421875, 0.4912109375, -0.611328125, -0.7158203125, -0.67529296875 }, - { 1.880859375, 0.77099609375,-0.03759765625, 1.0078125, 0.423828125 }, - { 2.49462890625, 1.42529296875,-0.0986328125, 0.17529296875,-0.24853515625 }, - { 1.7822265625, 1.5654296875, 1.12451171875, 0.82666015625, 0.6328125 }, - { 1.41845703125,-1.90771484375, 0.11181640625,-0.583984375, -1.138671875 }, - { 2.91845703125,-1.75048828125, 0.39306640625, 1.86767578125,-1.5322265625 }, - { 1.8291015625, -0.2958984375, 0.02587890625,-0.13134765625,-1.61181640625 }, - { 0.2958984375, 0.9853515625, -0.642578125, 1.984375, 0.1943359375 } -}; - -static const float ra28k8_table1[111] = { - 0.576690972, 0.580838025, 0.585013986, 0.589219987, 0.59345597, 0.597723007, - 0.602020264, 0.606384277, 0.610748291, 0.615142822, 0.619598389, 0.624084473, - 0.628570557, 0.633117676, 0.637695313, 0.642272949, 0.646911621, 0.651580811, - 0.656280518, 0.66104126, 0.665802002, 0.670593262, 0.675445557, 0.680328369, - 0.685241699, 0.690185547, 0.695159912, 0.700164795, 0.705230713, 0.710327148, - 0.715454102, 0.720611572, 0.725830078, 0.731048584, 0.736328125, 0.741638184, - 0.747009277, 0.752380371, 0.7578125, 0.763305664, 0.768798828, 0.774353027, - 0.779937744, 0.785583496, 0.791229248, 0.796936035, 0.802703857, 0.808502197, - 0.814331055, 0.820220947, 0.826141357, 0.832092285, 0.838104248, 0.844146729, - 0.850250244, 0.856384277, 0.862548828, 0.868774414, 0.875061035, 0.881378174, - 0.88772583, 0.894134521, 0.900604248, 0.907104492, 0.913635254, 0.920227051, - 0.926879883, 0.933563232, 0.940307617, 0.94708252, 0.953918457, 0.96081543, - 0.96774292, 0.974731445, 0.981781006, 0.988861084, 0.994842529, 0.998565674, - 0.999969482, 0.99911499, 0.996002197, 0.990600586, 0.982910156, 0.973022461, - 0.960876465, 0.946533203, 0.930053711, 0.911437988, 0.89074707, 0.868041992, - 0.843322754, 0.816680908, 0.788208008, 0.757904053, 0.725891113, 0.692199707, - 0.656921387, 0.620178223, 0.582000732, 0.542480469, 0.501739502, 0.459838867, - 0.416900635, 0.373016357, 0.328277588, 0.282775879, 0.236663818, 0.189971924, - 0.142852783, 0.0954284668,0.0477600098 -}; - -static const float ra28k8_table2[38] = { - 0.505699992, 0.524200022, 0.54339999, 0.563300014, 0.583953857, 0.60534668, - 0.627502441, 0.650482178, 0.674316406, 0.699005127, 0.724578857, 0.75112915, - 0.778625488, 0.807128906, 0.836669922, 0.86730957, 0.899078369, 0.932006836, - 0.961486816, 0.982757568, 0.995635986, 1, 0.995819092, 0.983154297, - 0.96206665, 0.932769775, 0.895507813, 0.850585938, 0.798400879, 0.739379883, - 0.674072266, 0.602996826, 0.526763916, 0.446014404, 0.361480713, 0.273834229, - 0.183868408, 0.0923461914 -}; - -static const float ra28k8_table1a[36] = { - 0.654184103, 0.66194123, 0.669790328, 0.677732527, 0.685768902, 0.693900526, - 0.702128589, 0.710454226, 0.718878567, 0.727402806, 0.736028135, 0.744755745, - 0.753586829, 0.762522638, 0.771564424, 0.780713439, 0.789970934, 0.799338162, - 0.808816493, 0.818407178, 0.828111589, 0.837931097, 0.847867012, 0.857920766, - 0.868093729, 0.878387332, 0.888803005, 0.899342179, 0.910006344, 0.920796931, - 0.931715488, 0.942763507, 0.953942537, 0.965254128, 0.976699829, 0.98828125 -}; - -static const float ra28k8_table2a[10] = { - 0.373657227, 0.41229248, 0.454956055, 0.50201416, 0.553955078, - 0.61126709, 0.674499512, 0.74432373, 0.821289063, 0.90625 -}; - - -static inline float sum (float *p1, float *p2, int len) { - float s = 0; - - while (len--) { - s += (*(p1++)) * (*(p2++)); - } - - return s; -} - -static inline void colmul (float *out, float *in, const float *table, int len) { - - while (len--) { - *(out++) = (*(in++)) * (*(table++)); - } -} - -static inline float clip (float a, float amin, float amax) { - if (a < amin) - return amin; - else if (a > amax) - return amax; - else - return a; -} - -static inline int predict (float *in, float *tgt, int n) { - int x, y; - float f0, f1, f2, temp; - - if (in[n] == 0 || in[0] <= 0) { - return 0; - } - - f0 = in[0]; - - for (x=n; (x > 0) && (f0 > 0); x--) { - f1 = in[(n - x) + 1]; - - for (y=1; y <= (n - x); y++) { - f1 += in[y] * tgt[x + y]; - } - - f2 = -f1 / f0; - f0 += f1 * f2; - - tgt[x] = f2; - - for (y=0; y < ((n - x) + 1)>>1; y++) { - temp = tgt[n - y] + tgt[x + y + 1] * f2; - tgt[x + y + 1] += tgt[n - y] * f2; - tgt[n - y] = temp; - } - } - - return (f0 > 0); -} - -static void decode_28k8_block (ra28k8_decoder_t *this, uint8_t *in, int16_t *out) { - int i, j, x, z, phase, phasep, code; - float buffer[5], work[111], temp1[37], temp2[11], d; - - for (x=0, z=0; x < 2304; x++) { - phasep = 5*(phase = (x & 7)); - - /* unpack */ - code = ((in[0] >> z) | (in[1] << (8 - z))) & (1023 >> (~x & 1)); - - if (z == 7 && (x & 1)) { - code |= (in[2] & 1) << 9; - } - - z += (9 + (x & 1)); - in += (z >> 3); - z &= 7; - - /* decode */ - memmove (this->sb, &this->sb[5], 36*sizeof(float)); - - for (i=0; i < 5; i++) { - this->sb[36 + i] = -sum (&this->sb[i], this->pr1, 36); - } - - /* convert log and do rms */ - d = clip (32 - sum (this->pr2, this->lhist, 10), 0, 60); - d = pow(10, d / 20) * ra28k8_amptable[code & 7]; - - for (i=0; i < 5; i++) { - buffer[i] = ra28k8_codetable[code >> 3][i] * d; - } - - d = sum (buffer, buffer, 5) / 5; - d = (d < 1) ? 0 : 10 * log10(d); - - /* shift and store */ - memmove (this->lhist, &this->lhist[1], 9*sizeof(float)); - this->lhist[9] = d - 32; - - for (i=1; i < 5; i++) { - for(j=0; j < i; j++) { - buffer[i] -= this->pr1[35 - j] * buffer[i - j - 1]; - } - } - - /* output */ - for (i=0; i < 5; i++) { - float f = clip (this->sb[36 + i] + buffer[i], -4095, 4095); - this->output[phasep + i] = this->sb[36 + i] = f; - *(out++) = (8 * f); - } - - if (phase == 3) { - - /* rotate and multiply */ - memmove (this->st1a, &this->st1a[40], 71*sizeof(float)); - memcpy (&this->st1a[71], &this->output[20], 20*sizeof(float)); - memcpy (&this->st1a[91], this->output, 20*sizeof(float)); - memmove (this->st2a, &this->st2a[8], 30*sizeof(float)); - memcpy (&this->st2a[30], &this->lhist[2], 4*sizeof(float)); - memcpy (&this->st2a[34], &this->lhist[6], 4*sizeof(float)); - - colmul (work, this->st1a, ra28k8_table1, 111); - - for (i=36; i >= 0; i--) { - this->st1b[i] = this->st1b[i] * (0.5625) + sum (&work[36 - i], &work[36], 40); - temp1[i] = this->st1b[i] + sum (&work[76 - i], &work[76], 35); - } - - colmul (work, this->st2a, ra28k8_table2, 38); - - for (i=10; i >= 0; i--) { - this->st2b[i] = this->st2b[i] * (0.5625) + sum (&work[10 - i], &work[10], 8); - temp2[i] = this->st2b[i] + sum (&work[18 - i], &work[18], 20); - } - - /* to prevent clipping */ - temp1[0] *= 1.00390625; - temp2[0] *= 1.00390625; - - if (predict (temp1, this->st1, 36)) { - colmul (this->pr1, &this->st1[1], ra28k8_table1a, 36); - } - if (predict (temp2, this->st2, 10)) { - colmul (this->pr2, &this->st2[1], ra28k8_table2a, 10); - } - } - } -} - -static void ra28k8_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - ra28k8_decoder_t *this = (ra28k8_decoder_t *) this_gen; - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) { - - } else if (buf->decoder_flags & BUF_FLAG_HEADER) { - - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, "Real 28.8"); - this->decoder_ok = 1; - if (!this->decoder_ok) - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); - - } else if (this->decoder_ok ) { - audio_buffer_t *audio_buffer; - int i, j; - - if (!this->output_open) { - this->output_open = this->stream->audio_out->open (this->stream->audio_out, - this->stream, 16, 8000, AO_CAP_MODE_MONO); - } - - /* copy and deinterleave sub-blocks */ - i = 0; - j = this->size; - - while (i < buf->size || j == BLOCKSIZE) { - if (j == BLOCKSIZE) { - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - - decode_28k8_block (this, this->buf, (int16_t *) audio_buffer->mem); - - audio_buffer->vpts = buf->pts; - audio_buffer->num_frames = 11520; - - this->stream->audio_out->put_buffer (this->stream->audio_out, - audio_buffer, this->stream); - - j = 0; - } else if ((buf->size - i) >= SUBBLOCK) { - memcpy (&this->buf[j], &buf->content[i], SUBBLOCK); - - if ((j += 12*SUBBLOCK) >= BLOCKSIZE) { - if (j == (BLOCKSIZE + 11*SUBBLOCK)) - j = BLOCKSIZE; - else - j -= (BLOCKSIZE - SUBBLOCK); - } - - i += SUBBLOCK; - } else { - memcpy (&this->buf[j], &buf->content[i], (buf->size - i)); - - j += (buf->size - i); - break; - } - } - - this->size = j; - } -} - -static void ra28k8_reset (audio_decoder_t *this_gen) { - ra28k8_decoder_t *this = (ra28k8_decoder_t *) this_gen; - - this->size = 0; - - memset (this->sb, 0, sizeof(this->sb)); - memset (this->lhist, 0, sizeof(this->lhist)); - memset (this->output, 0, sizeof(this->lhist)); - memset (this->pr1, 0, sizeof(this->pr1)); - memset (this->st1a, 0, sizeof(this->st1a)); - memset (this->st1b, 0, sizeof(this->st1b)); - memset (this->st1, 0, sizeof(this->st1)); - memset (this->pr2, 0, sizeof(this->pr2)); - memset (this->st2a, 0, sizeof(this->st2a)); - memset (this->st2b, 0, sizeof(this->st2b)); - memset (this->st2, 0, sizeof(this->st2)); -} - -static void ra28k8_discontinuity (audio_decoder_t *this_gen) { -} - -static void ra28k8_dispose (audio_decoder_t *this_gen) { - - ra28k8_decoder_t *this = (ra28k8_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - free (this_gen); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - ra28k8_decoder_t *this ; - - this = (ra28k8_decoder_t *) xine_xmalloc (sizeof (ra28k8_decoder_t)); - - this->audio_decoder.decode_data = ra28k8_decode_data; - this->audio_decoder.reset = ra28k8_reset; - this->audio_decoder.discontinuity = ra28k8_discontinuity; - this->audio_decoder.dispose = ra28k8_dispose; - - this->size = 0; - this->stream = stream; - - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - return "28k8"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "RealAudio 28k8 decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - ra28k8_class_t *this ; - - this = (ra28k8_class_t *) xine_xmalloc (sizeof (ra28k8_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_28_8, 0 -}; - -static decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 9 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "28k8", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxineadec/Makefile.am b/src/libxineadec/Makefile.am index f25dfe29d..4bad809de 100644 --- a/src/libxineadec/Makefile.am +++ b/src/libxineadec/Makefile.am @@ -9,25 +9,8 @@ AM_CFLAGS = -DNSF_PLAYER SUBDIRS = gsm610 nosefart lib_LTLIBRARIES = \ - xineplug_decode_adpcm.la \ - xineplug_decode_logpcm.la \ - xineplug_decode_roqaudio.la \ xineplug_decode_gsm610.la \ - xineplug_decode_interplayaudio.la \ - xineplug_decode_nsf.la \ - xineplug_decode_28k8.la - -xineplug_decode_roqaudio_la_SOURCES = roqaudio.c -xineplug_decode_roqaudio_la_LIBADD = $(XINE_LIB) -xineplug_decode_roqaudio_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_adpcm_la_SOURCES = adpcm.c -xineplug_decode_adpcm_la_LIBADD = $(XINE_LIB) -xineplug_decode_adpcm_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_logpcm_la_SOURCES = logpcm.c -xineplug_decode_logpcm_la_LIBADD = $(XINE_LIB) -xineplug_decode_logpcm_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ + xineplug_decode_nsf.la xineplug_decode_gsm610_la_SOURCES = gsm610.c xineplug_decode_gsm610_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ @@ -35,10 +18,6 @@ xineplug_decode_gsm610_la_LIBADD = \ $(XINE_LIB) \ $(top_builddir)/src/libxineadec/gsm610/libgsm610.la -xineplug_decode_interplayaudio_la_SOURCES = interplayaudio.c -xineplug_decode_interplayaudio_la_LIBADD = $(top_builddir)/src/xine-engine/libxine.la -xineplug_decode_interplayaudio_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - xineplug_decode_nsf_la_SOURCES = nsf.c #xineplug_decode_nsf_la_CFLAGS = -DNSF_PLAYER xineplug_decode_nsf_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ @@ -46,8 +25,4 @@ xineplug_decode_nsf_la_LIBADD = \ $(XINE_LIB) \ $(top_builddir)/src/libxineadec/nosefart/libnosefart.la -xineplug_decode_28k8_la_SOURCES = 28k8.c -xineplug_decode_28k8_la_LIBADD = $(top_builddir)/src/xine-engine/libxine.la -xineplug_decode_28k8_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - # noinst_HEADERS = diff --git a/src/libxineadec/adpcm.c b/src/libxineadec/adpcm.c deleted file mode 100644 index 85d7804f1..000000000 --- a/src/libxineadec/adpcm.c +++ /dev/null @@ -1,1687 +0,0 @@ -/* - * Copyright (C) 2000-2001 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * ADPCM Decoders by Mike Melanson (melanson@pcisys.net) - * - * This file is in charge of decoding all of the various ADPCM data - * formats that various entities have created. Details about the data - * formats can be found here: - * http://www.pcisys.net/~melanson/codecs/ - * CD-ROM/XA ADPCM decoder by Stuart Caie (kyzer@4u.net) - * - based on information in the USENET post by Jac Goudsmit (jac@codim.nl) - * <01bbc34c$dbf64020$f9c8a8c0@cray.codim.nl> - * - tested for correctness using Jon Atkins's CDXA software: - * http://jonatkins.org/cdxa/ - * this is also useful for extracting streams from Playstation discs - * - * - * $Id: adpcm.c,v 1.38 2004/01/12 17:35:18 miguelfreitas Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#define LOG_MODULE "adpcm_audio_decoder" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include "xine_internal.h" -#include "video_out.h" -#include "audio_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" - -/* pertinent tables */ -static int ima_adpcm_step[89] = { - 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, - 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, - 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, - 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, - 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, - 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, - 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, - 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, - 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 -}; - -static int dialogic_ima_step[49] = { - 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, - 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, - 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, - 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552 -}; - -static int ima_adpcm_index[16] = { - -1, -1, -1, -1, 2, 4, 6, 8, - -1, -1, -1, -1, 2, 4, 6, 8 -}; - -static int ms_adapt_table[] = { - 230, 230, 230, 230, 307, 409, 512, 614, - 768, 614, 512, 409, 307, 230, 230, 230 -}; - -static int ms_adapt_coeff1[] = { - 256, 512, 0, 192, 240, 460, 392 -}; - -static int ms_adapt_coeff2[] = { - 0, -256, 0, 64, 0, -208, -232 -}; - -static int ea_adpcm_table[] = { - 0, 240, 460, 392, 0, 0, -208, -220, 0, 1, - 3, 4, 7, 8, 10, 11, 0, -1, -3, -4 -}; - -static int xa_adpcm_table[] = { - 0, 240, 460, 392, 0, 0, -208, -220 -}; - -#define QT_IMA_ADPCM_PREAMBLE_SIZE 2 -#define QT_IMA_ADPCM_BLOCK_SIZE 0x22 -#define QT_IMA_ADPCM_SAMPLES_PER_BLOCK \ - ((QT_IMA_ADPCM_BLOCK_SIZE - QT_IMA_ADPCM_PREAMBLE_SIZE) * 2) - -#define MS_ADPCM_PREAMBLE_SIZE 7 -#define MS_IMA_ADPCM_PREAMBLE_SIZE 4 -#define DK4_ADPCM_PREAMBLE_SIZE 4 -#define DK3_ADPCM_PREAMBLE_SIZE 16 - -/* useful macros */ -/* clamp a number between 0 and 88 */ -#define CLAMP_0_TO_88(x) if (x < 0) x = 0; else if (x > 88) x = 88; -/* clamp a number within a signed 16-bit range */ -#define CLAMP_S16(x) if (x < -32768) x = -32768; \ - else if (x > 32767) x = 32767; -/* clamp a number above 16 */ -#define CLAMP_ABOVE_16(x) if (x < 16) x = 16; -/* sign extend a 16-bit value */ -#define SE_16BIT(x) if (x & 0x8000) x -= 0x10000; -/* sign extend a 4-bit value */ -#define SE_4BIT(x) if (x & 0x8) x -= 0x10; - -#define AUDIOBUFSIZE 128*1024 - -typedef struct { - audio_decoder_class_t decoder_class; -} adpcm_class_t; - -typedef struct adpcm_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - uint32_t rate; - uint32_t bits_per_sample; - uint32_t channels; - uint32_t ao_cap_mode; - - unsigned int buf_type; - int output_open; - - unsigned char *buf; - int bufsize; - int size; - - /* these fields are used for decoding ADPCM data transported in MS file */ - unsigned short *decode_buffer; - unsigned int in_block_size; - unsigned int out_block_size; /* size in samples (2 bytes/sample) */ - - int xa_mode; /* 1 for mode A, 0 for mode B or mode C */ - int xa_p_l; /* previous sample, left/mono channel */ - int xa_p_r; /* previous sample, right channel */ - int xa_pp_l; /* 2nd-previous sample, left/mono channel */ - int xa_pp_r; /* 2nd-previous sample, right channel */ - -} adpcm_decoder_t; - -/* - * decode_ima_nibbles - * - * So many different audio encoding formats leverage off of the IMA - * ADPCM algorithm that it makes sense to create a function that takes - * care of handling the common decoding portion. - * - * This function takes a buffer of ADPCM nibbles that are stored in an - * array of signed 16-bit numbers. The function then decodes the nibbles - * in place so that the buffer contains the decoded audio when the function - * is finished. - * - * The addresses of the initial predictor and index values are passed, - * rather than their values, so that the function can return the final - * predictor and index values after decoding. This is done in case the - * calling function cares (in the case of IMA ADPCM from Westwood Studios' - * VQA files, the values are initialized to 0 at the beginning of the file - * and maintained throughout all of the IMA blocks). - */ -static void decode_ima_nibbles(unsigned short *output, - int output_size, int channels, - int *predictor_l, int *index_l, - int *predictor_r, int *index_r) { - - int step[2]; - int predictor[2]; - int index[2]; - int diff; - int i; - int sign; - int delta; - int channel_number = 0; - - /* take care of the left */ - step[0] = ima_adpcm_step[*index_l]; - predictor[0] = *predictor_l; - index[0] = *index_l; - - /* only handle the right if non-NULL pointers */ - if (index_r) { - step[1] = ima_adpcm_step[*index_r]; - predictor[1] = *predictor_r; - index[1] = *index_r; - } - - for (i = 0; i < output_size; i++) { - delta = output[i]; - - index[channel_number] += ima_adpcm_index[delta]; - CLAMP_0_TO_88(index[channel_number]); - - sign = delta & 8; - delta = delta & 7; - - diff = step[channel_number] >> 3; - if (delta & 4) diff += step[channel_number]; - if (delta & 2) diff += step[channel_number] >> 1; - if (delta & 1) diff += step[channel_number] >> 2; - - if (sign) - predictor[channel_number] -= diff; - else - predictor[channel_number] += diff; - - CLAMP_S16(predictor[channel_number]); - output[i] = predictor[channel_number]; - step[channel_number] = ima_adpcm_step[index[channel_number]]; - - /* toggle channel */ - channel_number ^= channels - 1; - } - - /* save the index and predictor values in case the calling function cares */ - *predictor_l = predictor[0]; - *index_l = index[0]; - - /* only save the right channel information if pointers are non-NULL */ - if (predictor_r) { - *predictor_r = predictor[1]; - *index_r = index[1]; - } -} - -#define DK3_GET_NEXT_NIBBLE() \ - if (decode_top_nibble_next) \ - { \ - nibble = (last_byte >> 4) & 0x0F; \ - decode_top_nibble_next = 0; \ - } \ - else \ - { \ - last_byte = this->buf[i + j++]; \ - if (j > this->in_block_size) break; \ - nibble = last_byte & 0x0F; \ - decode_top_nibble_next = 1; \ - } - -static void dk3_adpcm_decode_block(adpcm_decoder_t *this, buf_element_t *buf) { - - int i, j; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - int sum_pred; - int diff_pred; - int sum_index; - int diff_index; - int diff_channel; - int out_ptr; - - unsigned char last_byte = 0; - unsigned char nibble; - int decode_top_nibble_next = 0; - - /* ADPCM work variables */ - int sign; - int delta; - int step; - int diff; - - /* make sure the input size checks out */ - if ((this->size % this->in_block_size) != 0) { - lprintf ("received DK3 ADPCM block that does not line up\n"); - this->size = 0; - return; - } - - /* iterate through each block in the in buffer */ - for (i = 0; i < this->size; i += this->in_block_size) { - - sum_pred = LE_16(&this->buf[i + 10]); - diff_pred = LE_16(&this->buf[i + 12]); - SE_16BIT(sum_pred); - SE_16BIT(diff_pred); - diff_channel = diff_pred; - sum_index = this->buf[i + 14]; - diff_index = this->buf[i + 15]; - - j = DK3_ADPCM_PREAMBLE_SIZE; /* start past the preamble */ - out_ptr = 0; - last_byte = 0; - decode_top_nibble_next = 0; - while (j < this->in_block_size) { - - /* process the first predictor of the sum channel */ - DK3_GET_NEXT_NIBBLE(); - - step = ima_adpcm_step[sum_index]; - - sign = nibble & 8; - delta = nibble & 7; - - diff = step >> 3; - if (delta & 4) diff += step; - if (delta & 2) diff += step >> 1; - if (delta & 1) diff += step >> 2; - - if (sign) - sum_pred -= diff; - else - sum_pred += diff; - - CLAMP_S16(sum_pred); - - sum_index += ima_adpcm_index[nibble]; - CLAMP_0_TO_88(sum_index); - - /* process the diff channel predictor */ - DK3_GET_NEXT_NIBBLE(); - - step = ima_adpcm_step[diff_index]; - - sign = nibble & 8; - delta = nibble & 7; - - diff = step >> 3; - if (delta & 4) diff += step; - if (delta & 2) diff += step >> 1; - if (delta & 1) diff += step >> 2; - - if (sign) - diff_pred -= diff; - else - diff_pred += diff; - - CLAMP_S16(diff_pred); - - diff_index += ima_adpcm_index[nibble]; - CLAMP_0_TO_88(diff_index); - - /* output the first pair of stereo PCM samples */ - diff_channel = (diff_channel + diff_pred) / 2; - this->decode_buffer[out_ptr++] = sum_pred + diff_channel; - this->decode_buffer[out_ptr++] = sum_pred - diff_channel; - - /* process the second predictor of the sum channel */ - DK3_GET_NEXT_NIBBLE(); - - step = ima_adpcm_step[sum_index]; - - sign = nibble & 8; - delta = nibble & 7; - - diff = step >> 3; - if (delta & 4) diff += step; - if (delta & 2) diff += step >> 1; - if (delta & 1) diff += step >> 2; - - if (sign) - sum_pred -= diff; - else - sum_pred += diff; - - CLAMP_S16(sum_pred); - - sum_index += ima_adpcm_index[nibble]; - CLAMP_0_TO_88(sum_index); - - /* output the second pair of stereo PCM samples */ - this->decode_buffer[out_ptr++] = sum_pred + diff_channel; - this->decode_buffer[out_ptr++] = sum_pred - diff_channel; - } - - /* dispatch the decoded audio */ - j = 0; - while (j < out_ptr) { - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - lprintf ("Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - /* out_ptr and j are sample counts, mem_size is a byte count */ - if (((out_ptr - j) * 2) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = (out_ptr - j) * 2; - - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[j], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - j += bytes_to_send / 2; /* 2 bytes per sample */ - } - } - - /* reset buffer */ - this->size = 0; -} - -static void dk4_adpcm_decode_block(adpcm_decoder_t *this, buf_element_t *buf) { - - int predictor_l = 0; - int predictor_r = 0; - int index_l = 0; - int index_r = 0; - - int i, j; - unsigned int out_ptr = 0; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - /* make sure the input size checks out */ - if ((this->size % this->in_block_size) != 0) { - lprintf ("received DK4 ADPCM block that does not line up\n"); - this->size = 0; - return; - } - - /* iterate through each block in the in buffer */ - for (i = 0; i < this->size; i += this->in_block_size) { - - out_ptr = 0; - - /* the first predictor value goes straight to the output */ - predictor_l = this->decode_buffer[0] = LE_16(&this->buf[i + 0]); - SE_16BIT(predictor_l); - index_l = this->buf[i + 2]; - if (this->channels == 2) { - predictor_r = this->decode_buffer[1] = LE_16(&this->buf[i + 4]); - SE_16BIT(predictor_r); - index_r = this->buf[i + 6]; - } - - /* break apart the ADPCM nibbles */ - out_ptr = this->channels; - for (j = DK4_ADPCM_PREAMBLE_SIZE * this->channels; - j < this->in_block_size; j++) { - this->decode_buffer[out_ptr++] = this->buf[i + j] >> 4; - this->decode_buffer[out_ptr++] = this->buf[i + j] & 0x0F; - } - - /* process the nibbles */ - decode_ima_nibbles(&this->decode_buffer[this->channels], - out_ptr - this->channels, - this->channels, - &predictor_l, &index_l, - &predictor_r, &index_r); - - /* dispatch the decoded audio */ - j = 0; - while (j < out_ptr) { - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - lprintf ("Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - /* out_ptr and j are sample counts, mem_size is a byte count */ - if (((out_ptr - j) * 2) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = (out_ptr - j) * 2; - - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[j], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - j += bytes_to_send / 2; /* 2 bytes per sample */ - } - } - - /* reset buffer */ - this->size = 0; -} - -static void ms_ima_adpcm_decode_block(adpcm_decoder_t *this, - buf_element_t *buf) { - - int predictor_l = 0; - int predictor_r = 0; - int index_l = 0; - int index_r = 0; - int channel_counter; - int channel_index; - int channel_index_l; - int channel_index_r; - - int i, j; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - /* check the size */ - if ((this->size % this->in_block_size) != 0) { - lprintf ("received MS IMA block that does not line up\n"); - this->size = 0; - return; - } - - /* iterate through each block in the in buffer */ - for (i = 0; i < this->size; i += this->in_block_size) { - - /* initialize algorithm for this block */ - predictor_l = LE_16(&this->buf[i]); - SE_16BIT(predictor_l); - index_l = this->buf[i + 2]; - if (this->channels == 2) { - predictor_r = LE_16(&this->buf[i + MS_IMA_ADPCM_PREAMBLE_SIZE]); - SE_16BIT(predictor_r); - index_r = this->buf[i + MS_IMA_ADPCM_PREAMBLE_SIZE + 2]; - } - - /* break apart all of the nibbles in the block */ - if (this->channels == 1) { - for (j = 0; - j < (this->in_block_size - MS_IMA_ADPCM_PREAMBLE_SIZE) / 2; j++) { - this->decode_buffer[j * 2 + 0] = - this->buf[i + MS_IMA_ADPCM_PREAMBLE_SIZE + j] & 0x0F; - this->decode_buffer[j * 2 + 1] = - this->buf[i + MS_IMA_ADPCM_PREAMBLE_SIZE + j] >> 4; - } - } else { - /* encoded as 8 nibbles (4 bytes) per channel; switch channel every - * 4th byte */ - channel_counter = 0; - channel_index_l = 0; - channel_index_r = 1; - channel_index = channel_index_l; - for (j = 0; - j < (this->in_block_size - MS_IMA_ADPCM_PREAMBLE_SIZE * 2); j++) { - this->decode_buffer[channel_index + 0] = - this->buf[i + MS_IMA_ADPCM_PREAMBLE_SIZE * 2 + j] & 0x0F; - this->decode_buffer[channel_index + 2] = - this->buf[i + MS_IMA_ADPCM_PREAMBLE_SIZE * 2 + j] >> 4; - channel_index += 4; - channel_counter++; - if (channel_counter == 4) { - channel_index_l = channel_index; - channel_index = channel_index_r; - } else if (channel_counter == 8) { - channel_index_r = channel_index; - channel_index = channel_index_l; - channel_counter = 0; - } - } - } - - /* process the nibbles */ - decode_ima_nibbles(this->decode_buffer, - this->out_block_size, - this->channels, - &predictor_l, &index_l, - &predictor_r, &index_r); - - /* dispatch the decoded audio */ - j = 0; - while (j < this->out_block_size) { - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - lprintf ("Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - /* out_block_size and j are sample counts, mem_size is a byte count */ - if (((this->out_block_size - j) * 2) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = (this->out_block_size - j) * 2; - - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[j], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - j += bytes_to_send / 2; /* 2 bytes per sample */ - } - } - - /* reset buffer */ - this->size = 0; - -} - -static void qt_ima_adpcm_decode_block(adpcm_decoder_t *this, - buf_element_t *buf) { - - int initial_predictor_l = 0; - int initial_predictor_r = 0; - int initial_index_l = 0; - int initial_index_r = 0; - - int i, j; - unsigned short *output; - unsigned int out_ptr; - audio_buffer_t *audio_buffer; - - /* check the size */ - if ((this->size % (QT_IMA_ADPCM_BLOCK_SIZE * this->channels) != 0)) { - lprintf ("received QT IMA block that does not line up\n"); - this->size = 0; - return; - } - - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - output = (unsigned short *)audio_buffer->mem; - out_ptr = 0; - - /* iterate through the blocks (and there are 2 bytes/sample) */ - for (i = 0; i < this->size; i+= - (QT_IMA_ADPCM_BLOCK_SIZE * this->channels)) { - - /* send the buffer if it gets full */ - if ((audio_buffer->mem_size / 2) <= - out_ptr + (QT_IMA_ADPCM_SAMPLES_PER_BLOCK * this->channels)) { - - audio_buffer->vpts = buf->pts; - buf->pts = 0; - audio_buffer->num_frames = out_ptr / this->channels; - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - /* get a new audio buffer */ - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - output = (unsigned short *)audio_buffer->mem; - out_ptr = 0; - } - - /* get the left (or mono) channel preamble bytes */ - initial_predictor_l = BE_16(&this->buf[i]); - initial_index_l = initial_predictor_l; - - /* mask, sign-extend, and clamp the predictor portion */ - initial_predictor_l &= 0xFF80; - SE_16BIT(initial_predictor_l); - CLAMP_S16(initial_predictor_l); - - /* mask and clamp the index portion */ - initial_index_l &= 0x7F; - CLAMP_0_TO_88(initial_index_l); - - /* if stereo, handle the right channel too */ - if (this->channels > 1) { - initial_predictor_r = BE_16(&this->buf[i + QT_IMA_ADPCM_BLOCK_SIZE]); - initial_index_r = initial_predictor_r; - - /* mask, sign-extend, and clamp the predictor portion */ - initial_predictor_r &= 0xFF80; - SE_16BIT(initial_predictor_r); - CLAMP_S16(initial_predictor_r); - - /* mask and clamp the index portion */ - initial_index_r &= 0x7F; - CLAMP_0_TO_88(initial_index_r); - } - - /* break apart all of the nibbles in the block */ - if (this->channels == 1) - for (j = 0; j < QT_IMA_ADPCM_SAMPLES_PER_BLOCK / 2; j++) { - output[out_ptr + j * 2 + 0] = this->buf[i + 2 + j] & 0x0F; - output[out_ptr + j * 2 + 1] = this->buf[i + 2 + j] >> 4; - } - else - for (j = 0; j < QT_IMA_ADPCM_SAMPLES_PER_BLOCK / 2 * 2; j++) { - output[out_ptr + j * 4 + 0] = this->buf[i + 2 + j] & 0x0F; - output[out_ptr + j * 4 + 1] = - this->buf[i + 2 + QT_IMA_ADPCM_BLOCK_SIZE + j] & 0x0F; - output[out_ptr + j * 4 + 2] = this->buf[i + 2 + j] >> 4; - output[out_ptr + j * 4 + 3] = - this->buf[i + 2 + QT_IMA_ADPCM_BLOCK_SIZE + j] >> 4; - } - - /* process the nibbles */ - decode_ima_nibbles(&output[out_ptr], - QT_IMA_ADPCM_SAMPLES_PER_BLOCK * this->channels, - this->channels, - &initial_predictor_l, &initial_index_l, - &initial_predictor_r, &initial_index_r); - - out_ptr += QT_IMA_ADPCM_SAMPLES_PER_BLOCK * this->channels; - } - - audio_buffer->vpts = buf->pts; - audio_buffer->num_frames = out_ptr / this->channels; - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - this->size = 0; -} - -static void ms_adpcm_decode_block(adpcm_decoder_t *this, buf_element_t *buf) { - - int i, j; - unsigned int out_ptr = 0; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - int current_channel = 0; - int idelta[2]; - int sample1[2]; - int sample2[2]; - int coeff1[2]; - int coeff2[2]; - int upper_nibble = 1; - int nibble; - int snibble; /* signed nibble */ - int predictor; - - /* make sure the input size checks out */ - if ((this->size % this->in_block_size) != 0) { - lprintf ("received MS ADPCM block that does not line up\n"); - this->size = 0; - return; - } - - /* iterate through each block in the in buffer */ - for (i = 0; i < this->size; i += this->in_block_size) { - - /* fetch the header information, in stereo if both channels are present */ - j = i; - upper_nibble = 1; - current_channel = 0; - out_ptr = 0; -#ifdef LOG - if (this->buf[j] > 6) - printf("MS ADPCM: coefficient (%d) out of range (should be [0..6])\n", - this->buf[j]); -#endif - coeff1[0] = ms_adapt_coeff1[this->buf[j]]; - coeff2[0] = ms_adapt_coeff2[this->buf[j]]; - j++; - if (this->channels == 2) { - if (this->buf[j] > 6) { - lprintf("MS ADPCM: coefficient (%d) out of range (should be [0..6])\n", - this->buf[j]); - } - coeff1[1] = ms_adapt_coeff1[this->buf[j]]; - coeff2[1] = ms_adapt_coeff2[this->buf[j]]; - j++; - } - - idelta[0] = LE_16(&this->buf[j]); - j += 2; - SE_16BIT(idelta[0]); - if (this->channels == 2) { - idelta[1] = LE_16(&this->buf[j]); - j += 2; - SE_16BIT(idelta[1]); - } - - sample1[0] = LE_16(&this->buf[j]); - j += 2; - SE_16BIT(sample1[0]); - if (this->channels == 2) { - sample1[1] = LE_16(&this->buf[j]); - j += 2; - SE_16BIT(sample1[1]); - } - - sample2[0] = LE_16(&this->buf[j]); - j += 2; - SE_16BIT(sample2[0]); - if (this->channels == 2) { - sample2[1] = LE_16(&this->buf[j]); - j += 2; - SE_16BIT(sample2[1]); - } - - /* first 2 samples go directly to the output */ - if (this->channels == 1) { - this->decode_buffer[out_ptr++] = sample2[0]; - this->decode_buffer[out_ptr++] = sample1[0]; - } else { - this->decode_buffer[out_ptr++] = sample2[0]; - this->decode_buffer[out_ptr++] = sample2[1]; - this->decode_buffer[out_ptr++] = sample1[0]; - this->decode_buffer[out_ptr++] = sample1[1]; - } - - j = MS_ADPCM_PREAMBLE_SIZE * this->channels; - while (j < this->in_block_size) { - /* get the next nibble */ - if (upper_nibble) - nibble = snibble = this->buf[i + j] >> 4; - else - nibble = snibble = this->buf[i + j++] & 0x0F; - upper_nibble ^= 1; - SE_4BIT(snibble); - - predictor = ( - ((sample1[current_channel] * coeff1[current_channel]) + - (sample2[current_channel] * coeff2[current_channel])) / 256) + - (snibble * idelta[current_channel]); - CLAMP_S16(predictor); - sample2[current_channel] = sample1[current_channel]; - sample1[current_channel] = predictor; - this->decode_buffer[out_ptr++] = predictor; - - /* compute the next adaptive scale factor (a.k.a. the variable idelta) */ - idelta[current_channel] = - (ms_adapt_table[nibble] * idelta[current_channel]) / 256; - CLAMP_ABOVE_16(idelta[current_channel]); - - /* toggle the channel */ - current_channel ^= this->channels - 1; - } - - /* dispatch the decoded audio */ - j = 0; - while (j < out_ptr) { - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - lprintf ("Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - /* out_ptr and j are sample counts, mem_size is a byte count */ - if (((out_ptr - j) * 2) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = (out_ptr - j) * 2; - - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[j], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - j += bytes_to_send / 2; /* 2 bytes per sample */ - } - } - - /* reset buffer */ - this->size = 0; -} - -static void smjpeg_adpcm_decode_block(adpcm_decoder_t *this, buf_element_t *buf) { - - unsigned int block_size; - int predictor = 0; - int index = 0; - - int i; - unsigned int out_ptr = 0; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - /* fetch the size for this block and check if the decode buffer needs - * to increase */ - block_size = buf->size - 4; /* compensate for preamble */ - block_size *= 2; /* 2 samples / byte */ - if (block_size > this->out_block_size) { - this->out_block_size = block_size; - if (this->decode_buffer) { - free(this->decode_buffer); - } - this->decode_buffer = xine_xmalloc(this->out_block_size * 2); - } - - out_ptr = 0; - predictor = BE_16(&this->buf[0]); - index = this->buf[2]; - - /* break apart the ADPCM nibbles (iterate through each byte in block) */ - for (i = 0; i < block_size / 2; i++) { - this->decode_buffer[out_ptr++] = this->buf[i + 4] & 0x0F; - this->decode_buffer[out_ptr++] = this->buf[i + 4] >> 4; - } - - /* process the nibbles */ - decode_ima_nibbles(this->decode_buffer, - out_ptr, - 1, - &predictor, &index, - 0, 0); - - /* dispatch the decoded audio */ - i = 0; - while (i < out_ptr) { - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - lprintf ("Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - /* out_ptr and i are sample counts, mem_size is a byte count */ - if (((out_ptr - i) * 2) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = (out_ptr - i) * 2; - - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[i], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - i += bytes_to_send / 2; /* 2 bytes per sample */ - } - - /* reset buffer */ - this->size = 0; -} - -static void vqa_adpcm_decode_block(adpcm_decoder_t *this, buf_element_t *buf) { - - /* VQA IMA blocks do not have a preamble with an initial index and - * predictor; there is one master index and predictor pair per channel that - * is initialized to 0 and maintained throughout all of the VQA IMA - * blocks. (That is why the following variables are static.) */ - static int index_l = 0; - static int index_r = 0; - static int predictor_l = 0; - static int predictor_r = 0; - - int out_ptr = 0; - int i; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - /* break apart the ADPCM nibbles */ - for (i = 0; i < this->size; i++) { - if (this->channels == 1) { - this->decode_buffer[out_ptr++] = this->buf[i] & 0x0F; - this->decode_buffer[out_ptr++] = (this->buf[i] >> 4) & 0x0F; - } else { - if ((i & 0x1) == 0) { - /* left channel */ - this->decode_buffer[out_ptr + 0] = this->buf[i] & 0x0F; - this->decode_buffer[out_ptr + 2] = (this->buf[i] >> 4) & 0x0F; - } else { - /* right channel */ - this->decode_buffer[out_ptr + 1] = this->buf[i] & 0x0F; - this->decode_buffer[out_ptr + 3] = (this->buf[i] >> 4) & 0x0F; - out_ptr += 4; - } - } - } - - /* process the nibbles */ - decode_ima_nibbles(this->decode_buffer, - out_ptr, - this->channels, - &predictor_l, &index_l, - &predictor_r, &index_r); - - /* dispatch the decoded audio */ - i = 0; - while (i < out_ptr) { - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - lprintf ("Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - /* out_ptr and i are sample counts, mem_size is a byte count */ - if (((out_ptr - i) * 2) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = (out_ptr - i) * 2; - - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[i], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - i += bytes_to_send / 2; /* 2 bytes per sample */ - } - - /* reset buffer */ - this->size = 0; -} - -static void ea_adpcm_decode_block(adpcm_decoder_t *this, buf_element_t *buf) { - uint32_t samples_in_chunk; - int32_t previous_left_sample, previous_right_sample; - int32_t current_left_sample, current_right_sample; - int32_t next_left_sample, next_right_sample; - int32_t coeff1l, coeff2l, coeff1r, coeff2r; - uint8_t shift_left, shift_right; - - int count1, count2, i = 0, j = 0; - - samples_in_chunk = ALE_32(&this->buf[i]); - i += 4; - current_left_sample = (int16_t)ALE_16(&this->buf[i]); - i += 2; - previous_left_sample = (int16_t)ALE_16(&this->buf[i]); - i += 2; - current_right_sample = (int16_t)ALE_16(&this->buf[i]); - i += 2; - previous_right_sample = (int16_t)ALE_16(&this->buf[i]); - i += 2; - - if (samples_in_chunk * 4 > this->out_block_size) { - this->out_block_size = samples_in_chunk * 4; - if (this->decode_buffer) { - free(this->decode_buffer); - } - this->decode_buffer = xine_xmalloc(this->out_block_size); - } - - for (count1 = 0; count1 < samples_in_chunk/28;count1++) { - coeff1l = ea_adpcm_table[(this->buf[i] >> 4) & 0x0F]; - coeff2l = ea_adpcm_table[((this->buf[i] >> 4) & 0x0F) + 4]; - coeff1r = ea_adpcm_table[this->buf[i] & 0x0F]; - coeff2r = ea_adpcm_table[(this->buf[i] & 0x0F) + 4]; - i++; - - shift_left = ((this->buf[i] >> 4) & 0x0F) + 8; - shift_right = (this->buf[i] & 0x0F) + 8; - i++; - - for (count2 = 0; count2 < 28; count2++) { - next_left_sample = (((this->buf[i] & 0xF0) << 24) >> shift_left); - next_right_sample = (((this->buf[i] & 0x0F) << 28) >> shift_right); - i++; - - next_left_sample = (next_left_sample + (current_left_sample * coeff1l) + (previous_left_sample * coeff2l) + 0x80) >> 8; - next_right_sample = (next_right_sample + (current_right_sample * coeff1r) + (previous_right_sample * coeff2r) + 0x80) >> 8; - CLAMP_S16(next_left_sample); - CLAMP_S16(next_right_sample); - - previous_left_sample = current_left_sample; - current_left_sample = next_left_sample; - previous_right_sample = current_right_sample; - current_right_sample = next_right_sample; - this->decode_buffer[j] = (unsigned short)current_left_sample; - j++; - this->decode_buffer[j] = (unsigned short)current_right_sample; - j++; - } - } - - i = 0; - while (i < j) { - audio_buffer_t *audio_buffer; - int bytes_to_send; - - audio_buffer = this->stream->audio_out->get_buffer(this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - lprintf ("Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - if (((j - i) * 2) > audio_buffer->mem_size) { - bytes_to_send = audio_buffer->mem_size; - } - else { - bytes_to_send = (j - i) * 2; - } - - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[i], bytes_to_send); - - audio_buffer->num_frames = (bytes_to_send / 4); - audio_buffer->vpts = buf->pts; - buf->pts = 0; - this->stream->audio_out->put_buffer(this->stream->audio_out, audio_buffer, this->stream); - - i += bytes_to_send / 2; - } - - this->size = 0; -} - -/* clamp a number between 0 and 48 */ -#define CLAMP_0_TO_48(x) if (x < 0) x = 0; else if (x > 48) x = 48; -/* clamp a number within a signed 12-bit range */ -#define CLAMP_S12(x) if (x < -2048) x = -2048; \ - else if (x > 2048) x = 2048; -static void dialogic_ima_decode_block(adpcm_decoder_t *this, buf_element_t *buf) { - - int i; - unsigned int out_ptr = 0; - audio_buffer_t *audio_buffer; - unsigned int block_size; - - /* IMA ADPCM work variables */ - /* the predictor and index values are initialized to 0 and maintained - * throughout the entire stream */ - static int predictor = 0; - static int index = 16; - int step = index; - int diff; - int sign; - int delta; - - /* fetch the size for this block and check if the decode buffer needs - * to increase */ - block_size = buf->size * 2; /* 2 samples / byte */ - if (block_size > this->out_block_size) { - this->out_block_size = block_size; - if (this->decode_buffer) { - free(this->decode_buffer); - } - this->decode_buffer = xine_xmalloc(this->out_block_size * 2); - } - - /* break apart the nibbles */ - for (i = 0; i < this->size; i++) { - this->decode_buffer[out_ptr++] = this->buf[i] >> 4; - this->decode_buffer[out_ptr++] = this->buf[i] & 0xF; - } - - /* decode the nibbles in place using an alternate IMA step table */ - for (i = 0; i < out_ptr; i++) { - - delta = this->decode_buffer[i]; - index += ima_adpcm_index[delta]; - CLAMP_0_TO_48(index); - - sign = delta & 8; - delta = delta & 7; - - diff = step >> 3; - if (delta & 4) diff += step; - if (delta & 2) diff += step >> 1; - if (delta & 1) diff += step >> 2; - - if (sign) - predictor -= diff; - else - predictor += diff; - - CLAMP_S12(predictor); - this->decode_buffer[i] = predictor << 4; - step = dialogic_ima_step[index]; - } - - /* dispatch the decoded audio */ - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - audio_buffer->vpts = buf->pts; - audio_buffer->num_frames = out_ptr; - xine_fast_memcpy(audio_buffer->mem, this->decode_buffer, out_ptr * 2); - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - /* reset buffer */ - this->size = 0; -} - - -static void xa_adpcm_decode_block(adpcm_decoder_t *this, buf_element_t *buf) { - int32_t p_l, pp_l, coeff_p_l, coeff_pp_l, range_l; - int32_t p_r, pp_r, coeff_p_r, coeff_pp_r, range_r; - int32_t snd_group, snd_unit, snd_data, samp, i, j; - uint8_t *inp; - - /* restore decoding history */ - p_l = this->xa_p_l; pp_l = this->xa_pp_l; - p_r = this->xa_p_r; pp_r = this->xa_pp_r; - - inp = &this->buf[0]; - j = 0; - - if (this->xa_mode) { - if (this->channels == 2) { - /* mode A (8 bits per sample / 4 sound units) stereo - * - sound units 0,2 are left channel, 1,3 are right channel - * - sound data (8 bits) is shifted left to 16-bit border, then - * shifted right by the range parameter, therefore it's shifted - * (8-range) bits left. - * - two coefficients tables (4 entries each) are merged into one - * - coefficients are multiples of 1/256, so '>> 8' is applied - * after multiplication to get correct answer. - */ - for (snd_group = 0; snd_group < 18; snd_group++, inp += 128) { - for (snd_unit = 0; snd_unit < 4; snd_unit += 2) { - /* get left channel coeffs and range */ - coeff_p_l = xa_adpcm_table[((inp[snd_unit] >> 4) & 0x3)]; - coeff_pp_l = xa_adpcm_table[((inp[snd_unit] >> 4) & 0x3) + 4]; - range_l = 8 - (inp[snd_unit] & 0xF); - - /* get right channel coeffs and range */ - coeff_p_r = xa_adpcm_table[((inp[snd_unit+1] >> 4) & 0x3)]; - coeff_pp_r = xa_adpcm_table[((inp[snd_unit+1] >> 4) & 0x3) + 4]; - range_r = 8 - (inp[snd_unit+1] & 0xF); - - for (snd_data = 0; snd_data < 28; snd_data++) { - /* left channel */ - samp = ((signed char *)inp)[16 + (snd_data << 2) + snd_unit]; - samp <<= range_l; - samp += (coeff_p_l * p_l + coeff_pp_l * pp_l) >> 8; - CLAMP_S16(samp); - pp_l = p_l; - p_l = samp; - this->decode_buffer[j++] = (unsigned short) samp; - - /* right channel */ - samp = ((signed char *)inp)[16 + (snd_data << 2) + snd_unit+1]; - samp <<= range_r; - samp += (coeff_p_r * p_r + coeff_pp_r * pp_r) >> 8; - CLAMP_S16(samp); - pp_r = p_r; - p_r = samp; - this->decode_buffer[j++] = (unsigned short) samp; - } - } - } - } - else { - /* mode A (8 bits per sample / 4 sound units) mono - * - other details as before - */ - for (snd_group = 0; snd_group < 18; snd_group++, inp += 128) { - for (snd_unit = 0; snd_unit < 4; snd_unit++) { - /* get coeffs and range */ - coeff_p_l = xa_adpcm_table[((inp[snd_unit] >> 4) & 0x3)]; - coeff_pp_l = xa_adpcm_table[((inp[snd_unit] >> 4) & 0x3) + 4]; - range_l = 8 - (inp[snd_unit] & 0xF); - - for (snd_data = 0; snd_data < 28; snd_data++) { - samp = ((signed char *)inp)[16 + (snd_data << 2) + snd_unit]; - samp <<= range_l; - samp += (coeff_p_l * p_l + coeff_pp_l * pp_l) >> 8; - CLAMP_S16(samp); - pp_l = p_l; p_l = samp; - this->decode_buffer[j++] = (unsigned short) samp; - } - } - } - } - } - else { - if (this->channels == 2) { - /* mode B/C (4 bits per sample / 8 sound units) stereo - * - sound units 0,2,4,6 are left channel, 1,3,5,7 are right channel - * - sound parameters 0-7 are stored as 16 bytes in the order - * "0123012345674567", so inp[x+4] gives sound parameter x while - * inp[x] doesn't. - * - sound data (4 bits) is shifted left to 16-bit border, then - * shifted right by the range parameter, therefore it's shifted - * (12-range) bits left. - * - other details as before - */ - for (snd_group = 0; snd_group < 18; snd_group++, inp += 128) { - for (snd_unit = 0; snd_unit < 8; snd_unit += 2) { - /* get left channel coeffs and range */ - coeff_p_l = xa_adpcm_table[((inp[snd_unit+4] >> 4) & 0x3)]; - coeff_pp_l = xa_adpcm_table[((inp[snd_unit+4] >> 4) & 0x3) + 4]; - range_l = 12 - (inp[snd_unit+4] & 0xF); - - /* get right channel coeffs and range */ - coeff_p_r = xa_adpcm_table[((inp[snd_unit+5] >> 4) & 0x3)]; - coeff_pp_r = xa_adpcm_table[((inp[snd_unit+5] >> 4) & 0x3) + 4]; - range_r = 12 - (inp[snd_unit+5] & 0xF); - - for (snd_data = 0; snd_data < 28; snd_data++) { - /* left channel */ - samp = (inp[16 + (snd_data << 2) + (snd_unit >> 1)]) & 0xF; - SE_4BIT(samp); - samp <<= range_l; - samp += (coeff_p_l * p_l + coeff_pp_l * pp_l) >> 8; - CLAMP_S16(samp); - pp_l = p_l; - p_l = samp; - this->decode_buffer[j++] = (unsigned short) samp; - - /* right channel */ - samp = (inp[16 + (snd_data << 2) + (snd_unit >> 1)] >> 4) & 0xF; - SE_4BIT(samp); - samp <<= range_r; - samp += (coeff_p_r * p_r + coeff_pp_r * pp_r) >> 8; - CLAMP_S16(samp); - pp_r = p_r; - p_r = samp; - this->decode_buffer[j++] = (unsigned short) samp; - } - } - } - } - else { - /* mode B or C (4 bits per sample / 8 sound units) mono - * - other details as before - */ - for (snd_group = 0; snd_group < 18; snd_group++, inp += 128) { - for (snd_unit = 0; snd_unit < 8; snd_unit++) { - /* get coeffs and range */ - coeff_p_l = xa_adpcm_table[((inp[snd_unit+4] >> 4) & 0x3)]; - coeff_pp_l = xa_adpcm_table[((inp[snd_unit+4] >> 4) & 0x3) + 4]; - range_l = 12 - (inp[snd_unit+4] & 0xF); - - for (snd_data = 0; snd_data < 28; snd_data++) { - samp = inp[16 + (snd_data << 2) + (snd_unit >> 1)]; - if (snd_unit & 1) samp >>= 4; samp &= 0xF; - SE_4BIT(samp); - samp <<= range_l; - samp += (coeff_p_l * p_l + coeff_pp_l * pp_l) >> 8; - CLAMP_S16(samp); - pp_l = p_l; - p_l = samp; - this->decode_buffer[j++] = (unsigned short) samp; - } - } - } - } - } - - /* store decoding history */ - this->xa_p_l = p_l; this->xa_pp_l = pp_l; - this->xa_p_r = p_r; this->xa_pp_r = pp_r; - - /* despatch the decoded audio */ - i = 0; - while (i < j) { - audio_buffer_t *audio_buffer; - int bytes_to_send; - - audio_buffer= this->stream->audio_out->get_buffer(this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - lprintf ("Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - if (((j - i) * 2) > audio_buffer->mem_size) { - bytes_to_send = audio_buffer->mem_size; - } - else { - bytes_to_send = (j - i) * 2; - } - - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[i], - bytes_to_send); - - audio_buffer->num_frames = bytes_to_send / (2 * this->channels); - audio_buffer->vpts = buf->pts; - buf->pts = 0; - this->stream->audio_out->put_buffer(this->stream->audio_out, - audio_buffer, this->stream); - - i += bytes_to_send / 2; - } - - /* reset input buffer */ - this->size = 0; -} - -static void adpcm_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - adpcm_decoder_t *this = (adpcm_decoder_t *) this_gen; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - xine_waveformatex *audio_header; - - this->rate = buf->decoder_info[1]; - this->channels = buf->decoder_info[3]; - this->ao_cap_mode = - (this->channels == 2) ? AO_CAP_MODE_STEREO : AO_CAP_MODE_MONO; - - this->buf = xine_xmalloc(AUDIOBUFSIZE); - this->bufsize = AUDIOBUFSIZE; - this->size = 0; - - /* load the stream information */ - switch (buf->type & 0xFFFF0000) { - - case BUF_AUDIO_MSADPCM: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "Microsoft ADPCM"); - break; - - case BUF_AUDIO_MSIMAADPCM: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "Microsoft IMA ADPCM"); - break; - - case BUF_AUDIO_QTIMAADPCM: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "QT IMA ADPCM"); - break; - - case BUF_AUDIO_DK3ADPCM: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "Duck DK3 ADPCM"); - break; - - case BUF_AUDIO_DK4ADPCM: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "Duck DK4 ADPCM"); - break; - - case BUF_AUDIO_SMJPEG_IMA: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "SMJPEG IMA ADPCM"); - break; - - case BUF_AUDIO_VQA_IMA: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "VQA IMA ADPCM"); - break; - - case BUF_AUDIO_EA_ADPCM: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "EA ADPCM"); - break; - - case BUF_AUDIO_DIALOGIC_IMA: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "Dialogic IMA ADPCM"); - break; - - case BUF_AUDIO_XA_ADPCM: - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "CD-ROM/XA ADPCM"); - break; - - } - - /* if the data was transported in an MS-type file (packet size will be - * non-0 indicating an audio header), create a decode buffer */ - if (buf->size) { - audio_header = (xine_waveformatex *)buf->content; - this->in_block_size = audio_header->nBlockAlign; - - switch(buf->type) { - case BUF_AUDIO_MSADPCM: - this->out_block_size = - (this->in_block_size - - ((MS_ADPCM_PREAMBLE_SIZE - 2) * this->channels)) * 2; - break; - - case BUF_AUDIO_DK4ADPCM: - /* A DK4 ADPCM block has 4 preamble bytes per channel and the - * initial predictor is also the first output sample (hence - * the +1) */ - this->out_block_size = - (this->in_block_size - (4 * this->channels)) * 2 + this->channels; - break; - - case BUF_AUDIO_DK3ADPCM: - /* A DK3 ADPCM block as 16 preamble bytes. A set of 3 nibbles, - * or 1.5 bytes, decodes to 4 PCM samples, so 6 nibbles, or 3 - * bytes, decode to 8 PCM samples. */ - this->out_block_size = - (this->in_block_size - DK3_ADPCM_PREAMBLE_SIZE) * 8 / 3; - break; - - case BUF_AUDIO_MSIMAADPCM: - /* a block of IMA ADPCM stored in an MS-type file has 4 - * preamble bytes per channel. */ - this->out_block_size = - (this->in_block_size - - (MS_IMA_ADPCM_PREAMBLE_SIZE * this->channels)) * 2; - break; - - default: - this->out_block_size = 0; - } - - /* allocate 2 bytes per sample */ - this->decode_buffer = xine_xmalloc(this->out_block_size * 2); - } - - /* the decoder will not know the size of the output buffer until - * an audio packet comes through */ - if ((buf->type == BUF_AUDIO_SMJPEG_IMA) || - (buf->type == BUF_AUDIO_EA_ADPCM) || - (buf->type == BUF_AUDIO_DIALOGIC_IMA)) { - this->in_block_size = this->out_block_size = 0; - this->decode_buffer = NULL; - } - - /* make this decode buffer large enough to hold a second of decoded - * audio */ - if (buf->type == BUF_AUDIO_VQA_IMA) { - this->out_block_size = this->rate * this->channels; - /* allocate 2 bytes per sample */ - this->decode_buffer = xine_xmalloc(this->out_block_size * 2); - } - - /* XA blocks are always 2304 bytes of input data. For output, there - * are 18 sound groups. These sound groups have 4 sound units (mode A) - * or 8 sound units (mode B or mode C). The sound units have 28 sound - * data samples. So, either 18*4*28=2016 or 18*8*28=4032 samples per - * sector. 2 bytes per sample means 4032 or 8064 bytes per sector. - */ - if ((buf->type & 0xFFFF0000) == BUF_AUDIO_XA_ADPCM) { - /* initialise decoder state */ - this->xa_mode = buf->decoder_info[2]; - this->xa_p_l = this->xa_pp_l = this->xa_p_r = this->xa_pp_r = 0; - /* allocate 2 bytes per sample */ - this->decode_buffer = xine_xmalloc((this->xa_mode) ? 4032 : 8064); - } - - return; - } - - if (!this->output_open) { - lprintf ("opening audio output (%d Hz sampling rate, mode=%d)\n", - this->rate, this->ao_cap_mode); - this->output_open = this->stream->audio_out->open (this->stream->audio_out, - this->stream, this->bits_per_sample, this->rate, this->ao_cap_mode); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - - /* accumulate compressed audio data */ - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - lprintf("increasing source buffer to %d to avoid overflow.\n", - this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - /* time to decode a frame */ - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - switch(buf->type & 0xFFFF0000) { - - case BUF_AUDIO_MSADPCM: - ms_adpcm_decode_block(this, buf); - break; - - case BUF_AUDIO_MSIMAADPCM: - ms_ima_adpcm_decode_block(this, buf); - break; - - case BUF_AUDIO_QTIMAADPCM: - qt_ima_adpcm_decode_block(this, buf); - break; - - case BUF_AUDIO_DK3ADPCM: - dk3_adpcm_decode_block(this, buf); - break; - - case BUF_AUDIO_DK4ADPCM: - dk4_adpcm_decode_block(this, buf); - break; - - case BUF_AUDIO_SMJPEG_IMA: - smjpeg_adpcm_decode_block(this, buf); - break; - - case BUF_AUDIO_VQA_IMA: - vqa_adpcm_decode_block(this, buf); - break; - - case BUF_AUDIO_EA_ADPCM: - ea_adpcm_decode_block(this, buf); - break; - - case BUF_AUDIO_DIALOGIC_IMA: - dialogic_ima_decode_block(this, buf); - break; - - case BUF_AUDIO_XA_ADPCM: - xa_adpcm_decode_block(this, buf); - break; - } - } -} - -static void adpcm_reset (audio_decoder_t *this_gen) { - - /* adpcm_decoder_t *this = (adpcm_decoder_t *) this_gen; */ - -} - -static void adpcm_discontinuity (audio_decoder_t *this_gen) { - - /* adpcm_decoder_t *this = (adpcm_decoder_t *) this_gen; */ - -} - -static void adpcm_dispose (audio_decoder_t *this_gen) { - - adpcm_decoder_t *this = (adpcm_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - if (this->decode_buffer) - free(this->decode_buffer); - if (this->buf) - free(this->buf); - - free (this_gen); -} - -/* - * ADPCM decoder class code - */ - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - adpcm_decoder_t *this ; - - this = (adpcm_decoder_t *) xine_xmalloc (sizeof (adpcm_decoder_t)); - - this->audio_decoder.decode_data = adpcm_decode_data; - this->audio_decoder.reset = adpcm_reset; - this->audio_decoder.discontinuity = adpcm_discontinuity; - this->audio_decoder.dispose = adpcm_dispose; - - this->output_open = 0; - this->rate = 0; - this->bits_per_sample = 16; /* these codecs always output 16-bit PCM */ - this->channels = 0; - this->ao_cap_mode = 0; - this->decode_buffer = NULL; - this->stream = stream; - - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - return "ADPCM"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "Multiple ADPCM audio format decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - adpcm_class_t *this ; - - this = (adpcm_class_t *) xine_xmalloc (sizeof (adpcm_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_MSADPCM, BUF_AUDIO_MSIMAADPCM, - BUF_AUDIO_QTIMAADPCM, BUF_AUDIO_DK3ADPCM, - BUF_AUDIO_DK4ADPCM, BUF_AUDIO_SMJPEG_IMA, - BUF_AUDIO_VQA_IMA, BUF_AUDIO_EA_ADPCM, - BUF_AUDIO_DIALOGIC_IMA, BUF_AUDIO_XA_ADPCM, - 0 - }; - -static decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 9 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "adpcm", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxineadec/interplayaudio.c b/src/libxineadec/interplayaudio.c deleted file mode 100644 index 7d05f41ac..000000000 --- a/src/libxineadec/interplayaudio.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (C) 2000-2001 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Interplay DPCM Audio Decoder by Mike Melanson (melanson@pcisys.net) - * For more information regarding the Interplay MVE file format, visit: - * http://www.pcisys.net/~melanson/codecs/ - * - * $Id: interplayaudio.c,v 1.8 2004/01/12 17:35:18 miguelfreitas Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" - -#define AUDIOBUFSIZE 128*1024 - -typedef struct { - audio_decoder_class_t decoder_class; -} interplay_class_t; - -typedef struct interplay_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int sample_rate; /* audio sample rate */ - int bits_per_sample; /* bits/sample, usually 8 or 16 */ - int channels; /* 1 or 2, usually */ - - int output_open; /* flag to indicate audio is ready */ - - unsigned char *buf; /* data accumulation buffer */ - int bufsize; /* maximum size of buf */ - int size; /* size of accumulated data in buf */ - - int last_left_delta; - int last_right_delta; - -} interplay_decoder_t; - -/************************************************************************** - * Interplay DPCM specific decode functions - *************************************************************************/ - -int interplay_delta_table[] = { - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 47, 51, 56, 61, - 66, 72, 79, 86, 94, 102, 112, 122, - 133, 145, 158, 173, 189, 206, 225, 245, - 267, 292, 318, 348, 379, 414, 452, 493, - 538, 587, 640, 699, 763, 832, 908, 991, - 1081, 1180, 1288, 1405, 1534, 1673, 1826, 1993, - 2175, 2373, 2590, 2826, 3084, 3365, 3672, 4008, - 4373, 4772, 5208, 5683, 6202, 6767, 7385, 8059, - 8794, 9597, 10472, 11428, 12471, 13609, 14851, 16206, - 17685, 19298, 21060, 22981, 25078, 27367, 29864, 32589, - -29973, -26728, -23186, -19322, -15105, -10503, -5481, -1, - 1, 1, 5481, 10503, 15105, 19322, 23186, 26728, - 29973, -32589, -29864, -27367, -25078, -22981, -21060, -19298, - -17685, -16206, -14851, -13609, -12471, -11428, -10472, -9597, - -8794, -8059, -7385, -6767, -6202, -5683, -5208, -4772, - -4373, -4008, -3672, -3365, -3084, -2826, -2590, -2373, - -2175, -1993, -1826, -1673, -1534, -1405, -1288, -1180, - -1081, -991, -908, -832, -763, -699, -640, -587, - -538, -493, -452, -414, -379, -348, -318, -292, - -267, -245, -225, -206, -189, -173, -158, -145, - -133, -122, -112, -102, -94, -86, -79, -72, - -66, -61, -56, -51, -47, -43, -42, -41, - -40, -39, -38, -37, -36, -35, -34, -33, - -32, -31, -30, -29, -28, -27, -26, -25, - -24, -23, -22, -21, -20, -19, -18, -17, - -16, -15, -14, -13, -12, -11, -10, -9, - -8, -7, -6, -5, -4, -3, -2, -1 - -}; - -/************************************************************************** - * xine audio plugin functions - *************************************************************************/ - -/* clamp a number within a signed 16-bit range */ -#define CLAMP_S16(x) if (x < -32768) x = -32768; \ - else if (x > 32767) x = 32767; - -static void interplay_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - interplay_decoder_t *this = (interplay_decoder_t *) this_gen; - audio_buffer_t *audio_buffer; - int i; - int samples_to_send; - int delta[2]; - int stream_ptr = 0; - int sequence_number; - int channel_number = 0; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - - /* When the engine sends a BUF_FLAG_HEADER flag, it is time to initialize - * the decoder. The buffer element type has 4 decoder_info fields, - * 0..3. Field 1 is the sample rate. Field 2 is the bits/sample. Field - * 3 is the number of channels. */ - this->sample_rate = buf->decoder_info[1]; - this->bits_per_sample = buf->decoder_info[2]; - this->channels = buf->decoder_info[3]; - - /* initialize the data accumulation buffer */ - this->buf = xine_xmalloc(AUDIOBUFSIZE); - this->bufsize = AUDIOBUFSIZE; - this->size = 0; - - /* take this opportunity to initialize stream/meta information */ - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "Interplay MVE DPCM"); - - return; - } - - /* if the audio output is not open yet, open the audio output */ - if (!this->output_open) { - this->output_open = this->stream->audio_out->open( - this->stream->audio_out, - this->stream, - 16, - this->sample_rate, - (this->channels == 2) ? AO_CAP_MODE_STEREO : AO_CAP_MODE_MONO); - } - - /* if the audio still isn't open, do not go any further with the decode */ - if (!this->output_open) - return; - - /* accumulate the data passed through the buffer element type; increase - * the accumulator buffer size as necessary */ - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "interplayaudio: increasing source buffer to %d to avoid overflow.\n", this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - /* When a buffer element type has the BUF_FLAG_FRAME_END flag set, it is - * time to decode the data in the buffer. */ - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - /* if this is the first frame, fetch the first deltas from the stream */ - sequence_number = LE_16(&this->buf[stream_ptr]); - stream_ptr += 6; /* skip over the stream mask and stream length */ - if (sequence_number == 1) { - delta[0] = LE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - if (this->channels == 2) { - delta[1] = LE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - } - } else { - delta[0] = this->last_left_delta; - if (this->channels == 2) - delta[1] = this->last_right_delta; - } - - /* iterate through each 8-bit delta in the input buffer */ - while (stream_ptr < this->size) { - - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "interplayaudio: Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - /* this->size and stream_ptr are sample counts, mem_size is a byte count */ - if ((this->size - stream_ptr) > (audio_buffer->mem_size / 2)) - samples_to_send = audio_buffer->mem_size / 2; - else - samples_to_send = this->size - stream_ptr; - - /* fill up this buffer */ - for (i = 0; i < samples_to_send; i++) { - delta[channel_number] += interplay_delta_table[this->buf[stream_ptr++]]; - CLAMP_S16(delta[channel_number]); - audio_buffer->mem[i] = delta[channel_number]; - - /* toggle channel */ - channel_number ^= this->channels - 1; - } - - audio_buffer->num_frames = samples_to_send / this->channels; - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - } - - /* stash away the deltas for the next block */ - this->last_left_delta = delta[0]; - this->last_right_delta = delta[1]; - - /* reset data accumulation buffer */ - this->size = 0; - } -} - -/* This function resets the state of the audio decoder. This usually - * entails resetting the data accumulation buffer. */ -static void interplay_reset (audio_decoder_t *this_gen) { - - interplay_decoder_t *this = (interplay_decoder_t *) this_gen; - - this->size = 0; -} - -/* This function resets the last pts value of the audio decoder. */ -static void interplay_discontinuity (audio_decoder_t *this_gen) { -} - -/* This function closes the audio output and frees the private audio decoder - * structure. */ -static void interplay_dispose (audio_decoder_t *this_gen) { - - interplay_decoder_t *this = (interplay_decoder_t *) this_gen; - - /* close the audio output */ - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - /* free anything that was allocated during operation */ - free(this->buf); - free(this); -} - -/* This function allocates, initializes, and returns a private audio - * decoder structure. */ -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - interplay_decoder_t *this ; - - this = (interplay_decoder_t *) xine_xmalloc (sizeof (interplay_decoder_t)); - - /* connect the member functions */ - this->audio_decoder.decode_data = interplay_decode_data; - this->audio_decoder.reset = interplay_reset; - this->audio_decoder.discontinuity = interplay_discontinuity; - this->audio_decoder.dispose = interplay_dispose; - - /* connect the stream */ - this->stream = stream; - - /* audio output is not open at the start */ - this->output_open = 0; - - /* initialize the basic audio parameters */ - this->channels = 0; - this->sample_rate = 0; - this->bits_per_sample = 0; - - /* initialize the data accumulation buffer */ - this->buf = NULL; - this->bufsize = 0; - this->size = 0; - - /* return the newly-initialized audio decoder */ - return &this->audio_decoder; -} - -/* This function returns a brief string that describes (usually with the - * decoder's most basic name) the audio decoder plugin. */ -static char *get_identifier (audio_decoder_class_t *this) { - return "Interplay DPCM Audio"; -} - -/* This function returns a slightly longer string describing the audio - * decoder plugin. */ -static char *get_description (audio_decoder_class_t *this) { - return "Interplay DPCM audio decoder plugin"; -} - -/* This function frees the audio decoder class and any other memory that was - * allocated. */ -static void dispose_class (audio_decoder_class_t *this_gen) { - - interplay_class_t *this = (interplay_class_t *)this_gen; - - free (this); -} - -/* This function allocates a private audio decoder class and initializes - * the class's member functions. */ -static void *init_plugin (xine_t *xine, void *data) { - - interplay_class_t *this ; - - this = (interplay_class_t *) xine_xmalloc (sizeof (interplay_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* This is a list of all of the internal xine audio buffer types that - * this decoder is able to handle. Check src/xine-engine/buffer.h for a - * list of valid buffer types (and add a new one if the one you need does - * not exist). Terminate the list with a 0. */ -static uint32_t audio_types[] = { - BUF_AUDIO_INTERPLAY, - 0 -}; - -/* This data structure combines the list of supported xine buffer types and - * the priority that the plugin should be given with respect to other - * plugins that handle the same buffer type. A plugin with priority (n+1) - * will be used instead of a plugin with priority (n). */ -static decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 5 /* priority */ -}; - -/* The plugin catalog entry. This is the only information that this plugin - * will export to the public. */ -plugin_info_t xine_plugin_info[] = { - /* { type, API version, "name", version, special_info, init_function }, */ - { PLUGIN_AUDIO_DECODER, 15, "interplayaudio", XINE_VERSION_CODE, &dec_info_audio, &init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; - diff --git a/src/libxineadec/logpcm.c b/src/libxineadec/logpcm.c deleted file mode 100644 index 3e2ea1a25..000000000 --- a/src/libxineadec/logpcm.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Logarithmic PCM Decoder - * This audio decoder handles the mu-law and A-law logarithmic coding - * standards. - * - * mu-law -> PCM conversion routine found at this site: - * http://www.speech.cs.cmu.edu/comp.speech/Section2/Q2.7.html - * and credited to this person: - * Craig Reese: IDA/Supercomputing Research Center - * - * A-law -> PCM conversion routine lifted from SoX Sound eXchange: - * http://sox.sourceforge.net/ - * which listed the code as being lifted from Sun Microsystems. - * - * $Id: logpcm.c,v 1.19 2004/01/12 17:35:18 miguelfreitas Exp $ - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> -#include <string.h> - -#include "buffer.h" -#include "xine_internal.h" -#include "video_out.h" -#include "audio_out.h" -#include "xineutils.h" -#include "bswap.h" - -#define AUDIOBUFSIZE 128*1024 -#define LOGPCM_BITS_PER_SAMPLE 16 - -typedef struct { - audio_decoder_class_t decoder_class; -} logpcm_class_t; - -typedef struct logpcm_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int64_t pts; - - int output_open; - int output_channels; - int samplerate; - - unsigned char *buf; - int bufsize; - int size; - - short logtable[256]; -} logpcm_decoder_t; - -/* -** This routine converts from ulaw to 16 bit linear. -** -** Craig Reese: IDA/Supercomputing Research Center -** 29 September 1989 -** -** References: -** 1) CCITT Recommendation G.711 (very difficult to follow) -** 2) MIL-STD-188-113,"Interoperability and Performance Standards -** for Analog-to_Digital Conversion Techniques," -** 17 February 1987 -** -** Input: 8 bit ulaw sample -** Output: signed 16 bit linear sample -*/ - -static int mulaw2linear(unsigned char mulawbyte) { - - static int exp_lut[8] = {0,132,396,924,1980,4092,8316,16764}; - int sign, exponent, mantissa, sample; - - mulawbyte = ~mulawbyte; - sign = (mulawbyte & 0x80); - exponent = (mulawbyte >> 4) & 0x07; - mantissa = mulawbyte & 0x0F; - sample = exp_lut[exponent] + (mantissa << (exponent + 3)); - if (sign != 0) sample = -sample; - - return(sample); -} - -/* - * The following A-law -> PCM conversion function came from SoX which in - * turn came from Sun Microsystems. - */ -#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ -#define QUANT_MASK (0xf) /* Quantization field mask. */ -#define SEG_SHIFT (4) /* Left shift for segment number. */ -#define SEG_MASK (0x70) /* Segment field mask. */ - -/* - * alaw2linear() - Convert an A-law value to 16-bit signed linear PCM - * - */ -static int alaw2linear(unsigned char a_val) { - - int t; - int seg; - - a_val ^= 0x55; - - t = (a_val & QUANT_MASK) << 4; - seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; - switch (seg) { - case 0: - t += 8; - break; - - case 1: - t += 0x108; - break; - - default: - t += 0x108; - t <<= seg - 1; - } - return ((a_val & SIGN_BIT) ? t : -t); -} - - -static void logpcm_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - logpcm_decoder_t *this = (logpcm_decoder_t *) this_gen; - audio_buffer_t *audio_buffer; - int in; - int i; - int bytes_to_send; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - - this->samplerate = buf->decoder_info[1]; - this->output_channels = buf->decoder_info[3]; - this->buf = xine_xmalloc(AUDIOBUFSIZE); - this->bufsize = AUDIOBUFSIZE; - this->size = 0; - - /* stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - (buf->type == BUF_AUDIO_MULAW) ? "mu-law log PCM" : - "A-law log PCM" ); - - /* pre-calculate the possible log values */ - if (buf->type == BUF_AUDIO_MULAW) - for (i = 0; i < 256; i++) - this->logtable[i] = (short)mulaw2linear(i); - else if (buf->type == BUF_AUDIO_ALAW) - for (i = 0; i < 256; i++) - this->logtable[i] = (short)alaw2linear(i); - - return; - } - - if (!this->output_open) { - this->output_open = this->stream->audio_out->open(this->stream->audio_out, - this->stream, LOGPCM_BITS_PER_SAMPLE, this->samplerate, - (this->output_channels == 2) ? AO_CAP_MODE_STEREO : AO_CAP_MODE_MONO); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "logpcm: increasing source buffer to %d to avoid overflow.\n", this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - - /* iterate through each 8-bit sample in the input buffer */ - in = 0; - while (in < this->size) { - - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "logpcm: Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - /* this->size and in are sample counts, mem_size is a byte count */ - if ((this->size - in) > (audio_buffer->mem_size / 2)) - bytes_to_send = audio_buffer->mem_size / 2; - else - bytes_to_send = this->size - in; - - /* fill up this buffer */ - for (i = 0; i < bytes_to_send; i++) - audio_buffer->mem[i] = this->logtable[this->buf[in++]]; - - audio_buffer->num_frames = bytes_to_send / this->output_channels; - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - } - - /* reset internal accumulation buffer */ - this->size = 0; - } -} - -static void logpcm_reset (audio_decoder_t *this_gen) { -} - -static void logpcm_discontinuity (audio_decoder_t *this_gen) { - logpcm_decoder_t *this = (logpcm_decoder_t *) this_gen; - - this->pts = 0; -} - -static void logpcm_dispose (audio_decoder_t *this_gen) { - - logpcm_decoder_t *this = (logpcm_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - if (this->buf) - free(this->buf); - - free (this_gen); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - logpcm_decoder_t *this ; - - this = (logpcm_decoder_t *) xine_xmalloc (sizeof (logpcm_decoder_t)); - - this->audio_decoder.decode_data = logpcm_decode_data; - this->audio_decoder.reset = logpcm_reset; - this->audio_decoder.discontinuity = logpcm_discontinuity; - this->audio_decoder.dispose = logpcm_dispose; - - this->output_open = 0; - this->output_channels = 0; - this->stream = stream; - this->buf = NULL; - this->size = 0; - - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - return "Log PCM"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "Logarithmic PCM audio format decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - logpcm_class_t *this ; - - this = (logpcm_class_t *) xine_xmalloc (sizeof (logpcm_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { BUF_AUDIO_MULAW, BUF_AUDIO_ALAW, 0 }; - -static decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 9 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "logpcm", XINE_VERSION_CODE, &dec_info_audio, &init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxineadec/roqaudio.c b/src/libxineadec/roqaudio.c deleted file mode 100644 index 6bc713a98..000000000 --- a/src/libxineadec/roqaudio.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * RoQ DPCM Audio Decoder by Mike Melanson (melanson@pcisys.net) - * For more information regarding the RoQ file format, visit: - * http://www.csse.monash.edu.au/~timf/ - * - * $Id: roqaudio.c,v 1.22 2004/01/12 17:35:18 miguelfreitas Exp $ - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> -#include <string.h> - -#include "xine_internal.h" -#include "audio_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" - -#define RoQ_AUDIO_SAMPLE_RATE 22050 -#define RoQ_AUDIO_BITS_PER_SAMPLE 16 - -#define AUDIOBUFSIZE 128*1024 - -#define CLAMP_S16(x) if (x < -32768) x = -32768; \ - else if (x > 32767) x = 32767; -#define SE_16BIT(x) if (x & 0x8000) x -= 0x10000; - -typedef struct { - audio_decoder_class_t decoder_class; -} roqaudio_class_t; - -typedef struct roqaudio_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int64_t pts; - - int output_open; - int output_channels; - - unsigned char *buf; - int bufsize; - int size; - - short square_array[256]; -} roqaudio_decoder_t; - -static void roqaudio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - roqaudio_decoder_t *this = (roqaudio_decoder_t *) this_gen; - audio_buffer_t *audio_buffer; - int in, out; - int predictor[2]; - int channel_number = 0; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - this->output_channels = buf->decoder_info[3]; - - this->buf = xine_xmalloc(AUDIOBUFSIZE); - this->bufsize = AUDIOBUFSIZE; - this->size = 0; - - /* stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, - "RoQ DPCM Audio"); - - return; - } - - if (!this->output_open) { - this->output_open = this->stream->audio_out->open(this->stream->audio_out, - this->stream, RoQ_AUDIO_BITS_PER_SAMPLE, RoQ_AUDIO_SAMPLE_RATE, - (this->output_channels == 2) ? AO_CAP_MODE_STEREO : AO_CAP_MODE_MONO); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "RoQ: increasing source buffer to %d to avoid overflow.\n", this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - - out = 0; - - /* prepare the initial predictors */ - if (this->output_channels == 1) - predictor[0] = LE_16(&this->buf[6]); - else - { - predictor[0] = this->buf[7] << 8; - predictor[1] = this->buf[6] << 8; - } - SE_16BIT(predictor[0]); - SE_16BIT(predictor[1]); - - /* decode the samples */ - for (in = 8; in < this->size; in++) - { - predictor[channel_number] += this->square_array[this->buf[in]]; - CLAMP_S16(predictor[channel_number]); - audio_buffer->mem[out++] = predictor[channel_number]; - - /* toggle channel */ - channel_number ^= this->output_channels - 1; - } - - audio_buffer->vpts = buf->pts; - audio_buffer->num_frames = - (buf->size - 8) / this->output_channels; - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - this->size = 0; - } -} - -static void roqaudio_reset (audio_decoder_t *this_gen) { -} - -static void roqaudio_discontinuity (audio_decoder_t *this_gen) { - - roqaudio_decoder_t *this = (roqaudio_decoder_t *) this_gen; - - this->pts = 0; -} - -static void roqaudio_dispose (audio_decoder_t *this_gen) { - - roqaudio_decoder_t *this = (roqaudio_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - if (this->buf) - free(this->buf); - - free (this_gen); -} - -static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - roqaudio_decoder_t *this; - int i; - short square; - - this = (roqaudio_decoder_t *) xine_xmalloc (sizeof (roqaudio_decoder_t)); - - this->audio_decoder.decode_data = roqaudio_decode_data; - this->audio_decoder.reset = roqaudio_reset; - this->audio_decoder.discontinuity = roqaudio_discontinuity; - this->audio_decoder.dispose = roqaudio_dispose; - this->size = 0; - - this->stream = stream; - - this->buf = NULL; - this->output_open = 0; - this->output_channels = 0; - - /* initialize tables of squares */ - for (i = 0; i < 128; i++) { - square = i * i; - this->square_array[i] = square; - this->square_array[i + 128] = -square; - } - - return &this->audio_decoder; -} - -static char *get_identifier (audio_decoder_class_t *this) { - return "RoQ Audio"; -} - -static char *get_description (audio_decoder_class_t *this) { - return "Id Roq audio decoder plugin"; -} - -static void dispose_class (audio_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - roqaudio_class_t *this; - - this = (roqaudio_class_t *) xine_xmalloc (sizeof (roqaudio_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -static uint32_t audio_types[] = { - BUF_AUDIO_ROQ, 0 -}; - -static decoder_info_t dec_info_audio = { - audio_types, /* supported types */ - 5 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 15, "roqaudio", XINE_VERSION_CODE, &dec_info_audio, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/Makefile.am b/src/libxinevdec/Makefile.am index c114f44d4..b8584f541 100644 --- a/src/libxinevdec/Makefile.am +++ b/src/libxinevdec/Makefile.am @@ -10,50 +10,13 @@ libdir = $(XINE_PLUGINDIR) lib_LTLIBRARIES = $(image_module) \ xineplug_decode_bitplane.la \ - xineplug_decode_cinepak.la \ - xineplug_decode_cyuv.la \ - xineplug_decode_fli.la \ - xineplug_decode_idcinvideo.la \ - xineplug_decode_msrle.la \ - xineplug_decode_msvc.la \ - xineplug_decode_qtsmc.la \ - xineplug_decode_roqvideo.la \ xineplug_decode_rgb.la \ - xineplug_decode_svq1.la \ - xineplug_decode_yuv.la \ - xineplug_decode_qtrpza.la \ - xineplug_decode_wc3video.la \ - xineplug_decode_qtrle.la \ - xineplug_decode_interplayvideo.la + xineplug_decode_yuv.la xineplug_decode_bitplane_la_SOURCES = bitplane.c xineplug_decode_bitplane_la_LIBADD = $(XINE_LIB) xineplug_decode_bitplane_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ -xineplug_decode_cinepak_la_SOURCES = cinepak.c -xineplug_decode_cinepak_la_LIBADD = $(XINE_LIB) -xineplug_decode_cinepak_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_cyuv_la_SOURCES = cyuv.c -xineplug_decode_cyuv_la_LIBADD = $(XINE_LIB) -xineplug_decode_cyuv_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_msvc_la_SOURCES = msvc.c -xineplug_decode_msvc_la_LIBADD = $(XINE_LIB) -xineplug_decode_msvc_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_roqvideo_la_SOURCES = roqvideo.c -xineplug_decode_roqvideo_la_LIBADD = $(XINE_LIB) -xineplug_decode_roqvideo_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_svq1_la_SOURCES = svq1.c svq1_codebooks.h -xineplug_decode_svq1_la_LIBADD = $(XINE_LIB) -xineplug_decode_svq1_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_fli_la_SOURCES = fli.c -xineplug_decode_fli_la_LIBADD = $(XINE_LIB) -xineplug_decode_fli_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - xineplug_decode_rgb_la_SOURCES = rgb.c xineplug_decode_rgb_la_LIBADD = $(XINE_LIB) xineplug_decode_rgb_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ @@ -62,36 +25,6 @@ xineplug_decode_yuv_la_SOURCES = yuv.c xineplug_decode_yuv_la_LIBADD = $(XINE_LIB) xineplug_decode_yuv_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ -xineplug_decode_msrle_la_SOURCES = msrle.c -xineplug_decode_msrle_la_LIBADD = $(XINE_LIB) -xineplug_decode_msrle_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_idcinvideo_la_SOURCES = idcinvideo.c -xineplug_decode_idcinvideo_la_LIBADD = $(XINE_LIB) -xineplug_decode_idcinvideo_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_qtsmc_la_SOURCES = qtsmc.c -xineplug_decode_qtsmc_la_LIBADD = $(XINE_LIB) -xineplug_decode_qtsmc_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_qtrpza_la_SOURCES = qtrpza.c -xineplug_decode_qtrpza_la_LIBADD = $(XINE_LIB) -xineplug_decode_qtrpza_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_wc3video_la_SOURCES = wc3video.c -xineplug_decode_wc3video_la_LIBADD = $(XINE_LIB) -xineplug_decode_wc3video_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_qtrle_la_SOURCES = qtrle.c -xineplug_decode_qtrle_la_LIBADD = $(XINE_LIB) -xineplug_decode_qtrle_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -xineplug_decode_interplayvideo_la_SOURCES = interplayvideo.c -xineplug_decode_interplayvideo_la_LIBADD = $(XINE_LIB) -xineplug_decode_interplayvideo_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - xineplug_decode_image_la_SOURCES = image.c xineplug_decode_image_la_LIBADD = $(XINE_LIB) $(DYNAMIC_LD_LIBS) $(PNG_LIBS) xineplug_decode_image_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -noinst_HEADERS = svq1_codebooks.h diff --git a/src/libxinevdec/cinepak.c b/src/libxinevdec/cinepak.c deleted file mode 100644 index a2fa78cce..000000000 --- a/src/libxinevdec/cinepak.c +++ /dev/null @@ -1,566 +0,0 @@ -/* - * Copyright (C) 2002-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * by Ewald Snel <ewald@rambo.its.tudelft.nl> - * - * based on overview of Cinepak algorithm and example decoder - * by Tim Ferguson: http://www.csse.monash.edu.au/~timf/ - * - * $Id: cinepak.c,v 1.38 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdlib.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "bswap.h" -#include "xineutils.h" - -#define MAX_STRIPS 32 -#define VIDEOBUFSIZE 128 * 1024 - - -typedef struct { - uint8_t y0, y1, y2, y3; - uint8_t u, v; -} cvid_codebook_t; - -typedef struct { - uint16_t id; - uint16_t x1, y1; - uint16_t x2, y2; - cvid_codebook_t v4_codebook[256]; - cvid_codebook_t v1_codebook[256]; -} cvid_strip_t; - -typedef struct { - video_decoder_class_t decoder_class; -} cvid_class_t; - -typedef struct cvid_decoder_s { - video_decoder_t video_decoder; - - cvid_class_t *class; - - xine_stream_t *stream; - int64_t video_step; - int decoder_ok; - - unsigned char *buf; - int bufsize; - int size; - - cvid_strip_t strips[MAX_STRIPS]; - - unsigned int coded_width; - unsigned int coded_height; - int luma_pitch; - int chroma_pitch; - uint8_t *current; - int offsets[3]; - - unsigned int width; - unsigned int height; - double ratio; -} cvid_decoder_t; - -static unsigned char yuv_palette[256 * 4]; -static int color_depth; - -static void cinepak_decode_codebook (cvid_codebook_t *codebook, - int chunk_id, int size, uint8_t *data) -{ - uint8_t *eod = (data + size); - uint32_t flag, mask; - int i, n; - - n = (chunk_id & 0x0400) ? 4 : 6; - flag = 0; - mask = 0; - - for (i=0; i < 256; i++) { - if ((chunk_id & 0x0100) && !(mask >>= 1)) { - if ((data + 4) > eod) - break; - - flag = BE_32 (data); - data += 4; - mask = 0x80000000; - } - - if (!(chunk_id & 0x0100) || (flag & mask)) { - if ((data + n) > eod) - break; - - if (n == 6) { - codebook[i].y0 = *data++; - codebook[i].y1 = *data++; - codebook[i].y2 = *data++; - codebook[i].y3 = *data++; - codebook[i].u = 128 + *data++; - codebook[i].v = 128 + *data++; - } else if (color_depth == 8) { - /* if color depth is 8, this codebook type indicates palette lookup */ - codebook[i].y0 = yuv_palette[*(data + 0) * 4]; - codebook[i].y1 = yuv_palette[*(data + 1) * 4]; - codebook[i].y2 = yuv_palette[*(data + 2) * 4]; - codebook[i].y3 = yuv_palette[*(data + 3) * 4]; - codebook[i].u = - (yuv_palette[*(data + 0) * 4 + 1] + - yuv_palette[*(data + 1) * 4 + 1] + - yuv_palette[*(data + 2) * 4 + 1] + - yuv_palette[*(data + 3) * 4 + 1]) / 4; - codebook[i].v = - (yuv_palette[*(data + 0) * 4 + 2] + - yuv_palette[*(data + 1) * 4 + 2] + - yuv_palette[*(data + 2) * 4 + 2] + - yuv_palette[*(data + 3) * 4 + 2]) / 4; - data += 4; - } else { - /* if color depth is 40, this codebook type indicates greyscale */ - codebook[i].y0 = *data++; - codebook[i].y1 = *data++; - codebook[i].y2 = *data++; - codebook[i].y3 = *data++; - codebook[i].u = 128; - codebook[i].v = 128; - } - } - } -} - -static int cinepak_decode_vectors (cvid_decoder_t *this, cvid_strip_t *strip, - int chunk_id, int size, uint8_t *data) -{ - uint8_t *eod = (data + size); - uint32_t flag, mask; - cvid_codebook_t *codebook; - unsigned int x, y; - uint8_t *iy[4]; - uint8_t *iu[2]; - uint8_t *iv[2]; - - flag = 0; - mask = 0; - - for (y=strip->y1; y < strip->y2; y+=4) { - - iy[0] = &this->current[strip->x1 + (y * this->luma_pitch) + this->offsets[0]]; - iy[1] = iy[0] + this->luma_pitch; - iy[2] = iy[1] + this->luma_pitch; - iy[3] = iy[2] + this->luma_pitch; - iu[0] = &this->current[(strip->x1/2) + ((y/2) * this->chroma_pitch) + this->offsets[1]]; - iu[1] = iu[0] + this->chroma_pitch; - iv[0] = &this->current[(strip->x1/2) + ((y/2) * this->chroma_pitch) + this->offsets[2]]; - iv[1] = iv[0] + this->chroma_pitch; - - for (x=strip->x1; x < strip->x2; x+=4) { - if ((chunk_id & 0x0100) && !(mask >>= 1)) { - if ((data + 4) > eod) - return -1; - - flag = BE_32 (data); - data += 4; - mask = 0x80000000; - } - - if (!(chunk_id & 0x0100) || (flag & mask)) { - if (!(chunk_id & 0x0200) && !(mask >>= 1)) { - if ((data + 4) > eod) - return -1; - - flag = BE_32 (data); - data += 4; - mask = 0x80000000; - } - - if ((chunk_id & 0x0200) || (~flag & mask)) { - if (data >= eod) - return -1; - - codebook = &strip->v1_codebook[*data++]; - iy[0][0] = codebook->y0; iy[0][1] = codebook->y0; - iy[1][0] = codebook->y0; iy[1][1] = codebook->y0; - iu[0][0] = codebook->u; iv[0][0] = codebook->v; - - iy[0][2] = codebook->y1; iy[0][3] = codebook->y1; - iy[1][2] = codebook->y1; iy[1][3] = codebook->y1; - iu[0][1] = codebook->u; iv[0][1] = codebook->v; - - iy[2][0] = codebook->y2; iy[2][1] = codebook->y2; - iy[3][0] = codebook->y2; iy[3][1] = codebook->y2; - iu[1][0] = codebook->u; iv[1][0] = codebook->v; - - iy[2][2] = codebook->y3; iy[2][3] = codebook->y3; - iy[3][2] = codebook->y3; iy[3][3] = codebook->y3; - iu[1][1] = codebook->u; iv[1][1] = codebook->v; - - } else if (flag & mask) { - if ((data + 4) > eod) - return -1; - - codebook = &strip->v4_codebook[*data++]; - iy[0][0] = codebook->y0; iy[0][1] = codebook->y1; - iy[1][0] = codebook->y2; iy[1][1] = codebook->y3; - iu[0][0] = codebook->u; iv[0][0] = codebook->v; - - codebook = &strip->v4_codebook[*data++]; - iy[0][2] = codebook->y0; iy[0][3] = codebook->y1; - iy[1][2] = codebook->y2; iy[1][3] = codebook->y3; - iu[0][1] = codebook->u; iv[0][1] = codebook->v; - - codebook = &strip->v4_codebook[*data++]; - iy[2][0] = codebook->y0; iy[2][1] = codebook->y1; - iy[3][0] = codebook->y2; iy[3][1] = codebook->y3; - iu[1][0] = codebook->u; iv[1][0] = codebook->v; - - codebook = &strip->v4_codebook[*data++]; - iy[2][2] = codebook->y0; iy[2][3] = codebook->y1; - iy[3][2] = codebook->y2; iy[3][3] = codebook->y3; - iu[1][1] = codebook->u; iv[1][1] = codebook->v; - } - } - - iy[0] += 4; iy[1] += 4; - iy[2] += 4; iy[3] += 4; - iu[0] += 2; iu[1] += 2; - iv[0] += 2; iv[1] += 2; - } - } - - return 0; -} - -static int cinepak_decode_strip (cvid_decoder_t *this, - cvid_strip_t *strip, uint8_t *data, int size) -{ - uint8_t *eod = (data + size); - int chunk_id, chunk_size; - - if (strip->x1 >= this->coded_width || strip->x2 > this->coded_width || - strip->y1 >= this->coded_height || strip->y2 > this->coded_height || - strip->x1 >= strip->x2 || strip->y1 >= strip->y2) - return -1; - - while ((data + 4) <= eod) { - chunk_id = BE_16 (&data[0]); - chunk_size = BE_16 (&data[2]) - 4; - data += 4; - chunk_size = ((data + chunk_size) > eod) ? (eod - data) : chunk_size; - - switch (chunk_id) { - case 0x2000: - case 0x2100: - case 0x2400: - case 0x2500: - cinepak_decode_codebook (strip->v4_codebook, chunk_id, chunk_size, data); - break; - case 0x2200: - case 0x2300: - case 0x2600: - case 0x2700: - cinepak_decode_codebook (strip->v1_codebook, chunk_id, chunk_size, data); - break; - case 0x3000: - case 0x3100: - case 0x3200: - return cinepak_decode_vectors (this, strip, chunk_id, chunk_size, data); - } - - data += chunk_size; - } - - return -1; -} - -static int cinepak_decode_frame (cvid_decoder_t *this, uint8_t *data, int size) { - uint8_t *eod = (data + size); - int i, result, strip_size, frame_flags, num_strips; - int y0 = 0; - - if (size < 10) - return -1; - - frame_flags = data[0]; - num_strips = BE_16 (&data[8]); - data += 10; - - if (num_strips > MAX_STRIPS) - num_strips = MAX_STRIPS; - - for (i=0; i < num_strips; i++) { - if ((data + 12) > eod) - return -1; - - this->strips[i].id = BE_16 (data); - this->strips[i].y1 = y0; - this->strips[i].x1 = 0; - this->strips[i].y2 = y0 + BE_16 (&data[8]); - this->strips[i].x2 = this->coded_width; - - strip_size = BE_16 (&data[2]) - 12; - data += 12; - strip_size = ((data + strip_size) > eod) ? (eod - data) : strip_size; - - if ((i > 0) && !(frame_flags & 0x01)) { - xine_fast_memcpy (this->strips[i].v4_codebook, this->strips[i-1].v4_codebook, - sizeof(this->strips[i].v4_codebook)); - - xine_fast_memcpy (this->strips[i].v1_codebook, this->strips[i-1].v1_codebook, - sizeof(this->strips[i].v1_codebook)); - } - - result = cinepak_decode_strip (this, &this->strips[i], data, strip_size); - - if (result != 0) - return result; - - data += strip_size; - y0 = this->strips[i].y2; - } - - return 0; -} - -static void cinepak_copy_frame (cvid_decoder_t *this, uint8_t *base[3], int pitches[3]) { - int i, j; - uint8_t *src, *dst; - - src = &this->current[this->offsets[0]]; - dst = base[0]; - - for (i=0; i < this->height; ++i) { - memcpy (dst, src, this->width); - src += this->luma_pitch; - dst += pitches[0]; - } - - for (i=1; i < 3; i++) { - src = &this->current[this->offsets[i]]; - dst = base[i]; - - for (j=0; j < (this->height / 2); ++j) { - memcpy (dst, src, (this->width / 2)); - src += this->chroma_pitch; - dst += pitches[i]; - } - } -} - -static void cvid_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { - cvid_decoder_t *this = (cvid_decoder_t *) this_gen; - - palette_entry_t *palette; - int i; - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - /* convert the RGB palette to a YUV palette */ - if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { - palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - for (i = 0; i < buf->decoder_info[2]; i++) { - yuv_palette[i * 4 + 0] = - COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); - yuv_palette[i * 4 + 1] = - COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); - yuv_palette[i * 4 + 2] = - COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - xine_bmiheader *bih; - int chroma_size; - - bih = (xine_bmiheader *) buf->content; - - this->width = (bih->biWidth + 1) & ~0x1; - this->height = (bih->biHeight + 1) & ~0x1; - this->ratio = (double)this->width/(double)this->height; - this->coded_width = (this->width + 3) & ~0x3; - this->coded_height = (this->height + 3) & ~0x3; - this->luma_pitch = this->coded_width; - this->chroma_pitch = this->coded_width / 2; - - chroma_size = (this->chroma_pitch * (this->coded_height / 2)); - this->current = (uint8_t *) realloc (this->current, 6*chroma_size); - this->offsets[0] = 0; - this->offsets[1] = 4*chroma_size; - this->offsets[2] = 5*chroma_size; - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - color_depth = bih->biBitCount; - - this->stream->video_out->open (this->stream->video_out, this->stream); - this->decoder_ok = 1; - - /* stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Cinepak"); - - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - vo_frame_t *img; - int result; - - result = cinepak_decode_frame (this, this->buf, this->size); - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, - XINE_IMGFMT_YV12, VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = (result != 0); - - if (result == 0) { - cinepak_copy_frame (this, img->base, img->pitches); - } - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -static void cvid_flush (video_decoder_t *this_gen) { -} - -static void cvid_reset (video_decoder_t *this_gen) { - cvid_decoder_t *this = (cvid_decoder_t *) this_gen; - - this->size = 0; -} - -static void cvid_discontinuity (video_decoder_t *this_gen) { -} - -static void cvid_dispose (video_decoder_t *this_gen) { - cvid_decoder_t *this = (cvid_decoder_t *) this_gen; - - if (this->current) { - free (this->current); - } - - if (this->buf) { - free (this->buf); - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - cvid_decoder_t *this ; - - this = (cvid_decoder_t *) xine_xmalloc (sizeof (cvid_decoder_t)); - - this->video_decoder.decode_data = cvid_decode_data; - this->video_decoder.flush = cvid_flush; - this->video_decoder.reset = cvid_reset; - this->video_decoder.discontinuity = cvid_discontinuity; - this->video_decoder.dispose = cvid_dispose; - this->size = 0; - - this->stream = stream; - this->class = (cvid_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "Cinepak"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Cinepak (CVID) video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - cvid_class_t *this; - - this = (cvid_class_t *) xine_xmalloc (sizeof (cvid_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t video_types[] = { - BUF_VIDEO_CINEPAK, - 0 - }; - -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 5 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "cinepak", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/cyuv.c b/src/libxinevdec/cyuv.c deleted file mode 100644 index b8393bc97..000000000 --- a/src/libxinevdec/cyuv.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * $Id: cyuv.c,v 1.26 2004/02/09 22:04:11 jstembridge Exp $ - */ - -/* And this is the header that came with the CYUV decoder: */ -/* ------------------------------------------------------------------------ - * Creative YUV Video Decoder - * - * Dr. Tim Ferguson, 2001. - * For more details on the algorithm: - * http://www.csse.monash.edu.au/~timf/videocodec.html - * - * This is a very simple predictive coder. A video frame is coded in YUV411 - * format. The first pixel of each scanline is coded using the upper four - * bits of its absolute value. Subsequent pixels for the scanline are coded - * using the difference between the last pixel and the current pixel (DPCM). - * The DPCM values are coded using a 16 entry table found at the start of the - * frame. Thus four bits per component are used and are as follows: - * UY VY YY UY VY YY UY VY... - * This code assumes the frame width will be a multiple of four pixels. This - * should probably be fixed. - * - * You may freely use this source code. I only ask that you reference its - * source in your projects documentation: - * Tim Ferguson: http://www.csse.monash.edu.au/~timf/ - * ------------------------------------------------------------------------ */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "xineutils.h" - -#define VIDEOBUFSIZE 128*1024 - -typedef struct { - video_decoder_class_t decoder_class; -} cyuv_class_t; - -typedef struct cyuv_decoder_s { - video_decoder_t video_decoder; - - xine_stream_t *stream; - cyuv_class_t *class; - - int video_step; - int skipframes; - unsigned char *buf; - int bufsize; - int size; - int width; - int height; - double ratio; -} cyuv_decoder_t; - -/* ------------------------------------------------------------------------ - * This function decodes a buffer containing a CYUV encoded frame. - * - * buf - the input buffer to be decoded - * size - the size of the input buffer - * frame - the output frame buffer (YUY2 format) - * width - the width of the output frame - * height - the height of the output frame - * bit_per_pixel - ignored for now: may be used later for conversions. - */ -static void cyuv_decode(unsigned char *buf, int size, unsigned char *frame, - int width, int height, int bit_per_pixel) { - - int i, xpos, ypos, cur_Y = 0, cur_U = 0, cur_V = 0; - char *delta_y_tbl, *delta_c_tbl, *ptr; - - delta_y_tbl = buf + 16; - delta_c_tbl = buf + 32; - ptr = buf + (16 * 3); - - for(ypos = 0; ypos < height; ypos++) { - for(xpos = 0; xpos < width; xpos += 4) { - /* first pixels in scanline */ - if(xpos == 0) { - cur_U = *(ptr++); - cur_Y = (cur_U & 0x0f) << 4; - cur_U = cur_U & 0xf0; - *frame++ = cur_Y; - *frame++ = cur_U; - - cur_V = *(ptr++); - cur_Y = (cur_Y + delta_y_tbl[cur_V & 0x0f]) & 0xff; - cur_V = cur_V & 0xf0; - *frame++ = cur_Y; - *frame++ = cur_V; - } - /* subsequent pixels in scanline */ - else { - i = *(ptr++); - cur_U = (cur_U + delta_c_tbl[i >> 4]) & 0xff; - cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; - *frame++ = cur_Y; - *frame++ = cur_U; - - i = *(ptr++); - cur_V = (cur_V + delta_c_tbl[i >> 4]) & 0xff; - cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; - *frame++ = cur_Y; - *frame++ = cur_V; - } - - i = *(ptr++); - cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; - *frame++ = cur_Y; - *frame++ = cur_U; - - cur_Y = (cur_Y + delta_y_tbl[i >> 4]) & 0xff; - *frame++ = cur_Y; - *frame++ = cur_V; - } - } -} - -static void cyuv_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - cyuv_decoder_t *this = (cyuv_decoder_t *) this_gen; - vo_frame_t *img; /* video out frame */ - - if (buf->decoder_flags & (BUF_FLAG_PREVIEW | BUF_FLAG_SPECIAL)) - return; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */ - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - this->buf = malloc(VIDEOBUFSIZE); - this->bufsize = VIDEOBUFSIZE; - this->size = 0; - this->width = *(unsigned int *)&buf->content[4]; - this->height = *(unsigned int *)&buf->content[8]; - this->ratio = (double)this->width/(double)this->height; - this->skipframes = 0; - - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Creative YUV"); - - return; - } - - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "CYUV: increasing source buffer to %d to avoid overflow.\n", this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, this->ratio, XINE_IMGFMT_YUY2, - VO_BOTH_FIELDS); - - img->pts = buf->pts; - img->duration = this->video_step; - - cyuv_decode(this->buf, this->size, img->base[0], - this->width, this->height, 0); - - this->skipframes = img->draw(img, this->stream); - if( this->skipframes < 0 ) - this->skipframes = 0; - img->free(img); - - this->size = 0; - } -} - -static void cyuv_flush (video_decoder_t *this_gen) { -} - -static void cyuv_reset (video_decoder_t *this_gen) { -} - -static void cyuv_discontinuity (video_decoder_t *this_gen) { -} - -static void cyuv_dispose (video_decoder_t *this_gen) { - - cyuv_decoder_t *this = (cyuv_decoder_t *) this_gen; - - this->stream->video_out->close(this->stream->video_out, this->stream); - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - cyuv_decoder_t *this ; - - this = (cyuv_decoder_t *) xine_xmalloc (sizeof (cyuv_decoder_t)); - - this->video_decoder.decode_data = cyuv_decode_data; - this->video_decoder.flush = cyuv_flush; - this->video_decoder.reset = cyuv_reset; - this->video_decoder.discontinuity = cyuv_discontinuity; - this->video_decoder.dispose = cyuv_dispose; - this->size = 0; - - this->stream = stream; - this->class = (cyuv_class_t *) class_gen; - - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "CYUV"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Creative YUV (CYUV) video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - cyuv_class_t *this; - - this = (cyuv_class_t *) xine_xmalloc (sizeof (cyuv_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t video_types[] = { - BUF_VIDEO_CYUV, - 0 - }; - -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 1 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "cyuv", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/fli.c b/src/libxinevdec/fli.c deleted file mode 100644 index 1baa1f6a5..000000000 --- a/src/libxinevdec/fli.c +++ /dev/null @@ -1,602 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * FLI Video Decoder by Mike Melanson (melanson@pcisys.net) and - * Roberto Togni <rtogni@bresciaonline.it> - * For more information on the FLI format, as well as various traps to - * avoid when implementing a FLI decoder, visit: - * http://www.pcisys.net/~melanson/codecs/ - * - * $Id: fli.c,v 1.27 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" - -#define VIDEOBUFSIZE 128*1024 - -#define PALETTE_SIZE (256 * 4) - -#define FLI_256_COLOR 4 -#define FLI_DELTA 7 -#define FLI_COLOR 11 -#define FLI_LC 12 -#define FLI_BLACK 13 -#define FLI_BRUN 15 -#define FLI_COPY 16 -#define FLI_MINI 18 - -/************************************************************************** - * fli specific decode functions - *************************************************************************/ - -typedef struct { - video_decoder_class_t decoder_class; -} fli_class_t; - -typedef struct fli_decoder_s { - video_decoder_t video_decoder; /* parent video decoder structure */ - - fli_class_t *class; - xine_stream_t *stream; - - /* these are traditional variables in a video decoder object */ - uint64_t video_step; /* frame duration in pts units */ - int decoder_ok; /* current decoder status */ - int skipframes; - - unsigned char *buf; /* the accumulated buffer data */ - int bufsize; /* the maximum size of buf */ - int size; /* the current size of buf */ - - int width; /* the width of a video frame */ - int height; /* the height of a video frame */ - double ratio; /* the width to height ratio */ - - /* FLI decoding parameters */ - unsigned char yuv_palette[PALETTE_SIZE]; - yuv_planes_t yuv_planes; - unsigned char *ghost_image; - int magic_number; /* FLI file magic number, e.g., 0xAF11 */ - -} fli_decoder_t; - -static void decode_fli_frame(fli_decoder_t *this) { - int stream_ptr = 0; - int stream_ptr_after_color_chunk; - int pixel_ptr; - int palette_ptr1; - int palette_ptr2; - unsigned char palette_idx1; - unsigned char palette_idx2; - - unsigned int frame_size; - int num_chunks; - - unsigned int chunk_size; - int chunk_type; - - int i, j; - - int color_packets; - int color_changes; - int color_shift; - unsigned char r, g, b; - - int lines, x; - int compressed_lines; - int starting_line; - signed short line_packets; - int y_ptr; - signed char byte_run; - int pixel_skip; - int update_whole_frame = 0; /* palette change flag */ - int ghost_pixel_ptr; - int ghost_y_ptr; - int pixel_countdown; - - frame_size = LE_32(&this->buf[stream_ptr]); - stream_ptr += 6; /* skip the magic number */ - num_chunks = LE_16(&this->buf[stream_ptr]); - stream_ptr += 10; /* skip padding */ - - /* iterate through the chunks */ - frame_size -= 16; - while ((frame_size > 0) && (num_chunks > 0)) { - chunk_size = LE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - chunk_type = LE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - - switch (chunk_type) { - case FLI_256_COLOR: - case FLI_COLOR: - stream_ptr_after_color_chunk = stream_ptr + chunk_size - 6; - /* check special case: if this has the internal magic number of - * 0xAF13, this file is from the Magic Carpet game and uses 6-bit - * colors even though it reports 256-color chunks in a 0xAF12-type - * file */ - if ((chunk_type == FLI_256_COLOR) && (this->magic_number != 0xAF13)) - color_shift = 0; - else - color_shift = 2; - /* set up the palette */ - color_packets = LE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - palette_ptr1 = 0; - for (i = 0; i < color_packets; i++) { - /* first byte is how many colors to skip */ - palette_ptr1 += (this->buf[stream_ptr++] * 4); - - /* next byte indicates how many entries to change */ - color_changes = this->buf[stream_ptr++]; - - /* if there are 0 color changes, there are actually 256 */ - if (color_changes == 0) - color_changes = 256; - - for (j = 0; j < color_changes; j++) { - - /* wrap around, for good measure */ - if (palette_ptr1 >= PALETTE_SIZE) - palette_ptr1 = 0; - - r = this->buf[stream_ptr + 0] << color_shift; - g = this->buf[stream_ptr + 1] << color_shift; - b = this->buf[stream_ptr + 2] << color_shift; - - this->yuv_palette[palette_ptr1++] = COMPUTE_Y(r, g, b); - this->yuv_palette[palette_ptr1++] = COMPUTE_U(r, g, b); - this->yuv_palette[palette_ptr1++] = COMPUTE_V(r, g, b); - - palette_ptr1++; - stream_ptr += 3; - } - } - - /* color chunks sometimes have weird 16-bit alignment issues; - * therefore, take the hardline approach and set the stream_ptr - * to the value calculate w.r.t. the size specified by the color - * chunk header */ - stream_ptr = stream_ptr_after_color_chunk; - - /* palette has changed, must update frame */ - update_whole_frame = 1; - break; - - case FLI_DELTA: - y_ptr = ghost_y_ptr = 0; - compressed_lines = LE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - while (compressed_lines > 0) { - line_packets = LE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - if (line_packets < 0) { - line_packets = -line_packets; - y_ptr += (line_packets * this->yuv_planes.row_width); - ghost_y_ptr += (line_packets * this->width); - } else { - pixel_ptr = y_ptr; - ghost_pixel_ptr = ghost_y_ptr; - for (i = 0; i < line_packets; i++) { - /* account for the skip bytes */ - pixel_skip = this->buf[stream_ptr++]; - pixel_ptr += pixel_skip; - ghost_pixel_ptr += pixel_skip; - byte_run = this->buf[stream_ptr++]; - if (byte_run < 0) { - byte_run = -byte_run; - palette_ptr1 = (palette_idx1 = this->buf[stream_ptr++]) * 4; - palette_ptr2 = (palette_idx2 = this->buf[stream_ptr++]) * 4; - for (j = 0; j < byte_run; j++) { - this->ghost_image[ghost_pixel_ptr++] = palette_idx1; - this->yuv_planes.y[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 0]; - this->yuv_planes.u[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 1]; - this->yuv_planes.v[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 2]; - pixel_ptr++; - - this->ghost_image[ghost_pixel_ptr++] = palette_idx2; - this->yuv_planes.y[pixel_ptr] = - this->yuv_palette[palette_ptr2 + 0]; - this->yuv_planes.u[pixel_ptr] = - this->yuv_palette[palette_ptr2 + 1]; - this->yuv_planes.v[pixel_ptr] = - this->yuv_palette[palette_ptr2 + 2]; - pixel_ptr++; - } - } else { - for (j = 0; j < byte_run * 2; j++) { - palette_ptr1 = (palette_idx1 = this->buf[stream_ptr++]) * 4; - this->ghost_image[ghost_pixel_ptr++] = palette_idx1; - this->yuv_planes.y[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 0]; - this->yuv_planes.u[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 1]; - this->yuv_planes.v[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 2]; - pixel_ptr++; - } - } - } - - y_ptr += this->yuv_planes.row_width; - ghost_y_ptr += this->width; - compressed_lines--; - } - } - break; - - case FLI_LC: - /* line compressed */ - starting_line = LE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - y_ptr = starting_line * this->yuv_planes.row_width; - ghost_y_ptr = starting_line * this->width; - - compressed_lines = LE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - while (compressed_lines > 0) { - pixel_ptr = y_ptr; - ghost_pixel_ptr = ghost_y_ptr; - line_packets = this->buf[stream_ptr++]; - if (line_packets > 0) { - for (i = 0; i < line_packets; i++) { - /* account for the skip bytes */ - pixel_skip = this->buf[stream_ptr++]; - pixel_ptr += pixel_skip; - ghost_pixel_ptr += pixel_skip; - byte_run = this->buf[stream_ptr++]; - if (byte_run > 0) { - for (j = 0; j < byte_run; j++) { - palette_ptr1 = (palette_idx1 = this->buf[stream_ptr++]) * 4; - this->ghost_image[ghost_pixel_ptr++] = palette_idx1; - this->yuv_planes.y[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 0]; - this->yuv_planes.u[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 1]; - this->yuv_planes.v[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 2]; - pixel_ptr++; - } - } else { - byte_run = -byte_run; - palette_ptr1 = (palette_idx1 = this->buf[stream_ptr++]) * 4; - for (j = 0; j < byte_run; j++) { - this->ghost_image[ghost_pixel_ptr++] = palette_idx1; - this->yuv_planes.y[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 0]; - this->yuv_planes.u[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 1]; - this->yuv_planes.v[pixel_ptr] = - this->yuv_palette[palette_ptr1 + 2]; - pixel_ptr++; - } - } - } - } - - y_ptr += this->yuv_planes.row_width; - ghost_y_ptr += this->width; - compressed_lines--; - } - break; - - case FLI_BLACK: - /* set the whole frame to color 0 (which is usually black) by - * clearing the ghost image and trigger a full frame update */ - memset(this->ghost_image, 0, - this->width * this->height * sizeof(unsigned char)); - update_whole_frame = 1; - break; - - case FLI_BRUN: - /* Byte run compression: This chunk type only occurs in the first - * FLI frame and it will update the entire frame. Take a lazy - * approach and update only the ghost image. Then let the ghost - * image updater at the end of the decoder handle the rest. */ - update_whole_frame = 1; - ghost_y_ptr = 0; - for (lines = 0; lines < this->height; lines++) { - ghost_pixel_ptr = ghost_y_ptr; - /* disregard the line packets; instead, iterate through all - * pixels on a row */ - stream_ptr++; - pixel_countdown = this->width; - while (pixel_countdown > 0) { - byte_run = this->buf[stream_ptr++]; - if (byte_run > 0) { - palette_ptr1 = (palette_idx1 = this->buf[stream_ptr++]) * 4; - for (j = 0; j < byte_run; j++) { - this->ghost_image[ghost_pixel_ptr++] = palette_idx1; - pixel_countdown--; - if (pixel_countdown < 0) - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "fli warning: pixel_countdown < 0 (%d)\n", pixel_countdown); - } - } else { /* copy bytes if byte_run < 0 */ - byte_run = -byte_run; - for (j = 0; j < byte_run; j++) { - palette_ptr1 = (palette_idx1 = this->buf[stream_ptr++]) * 4; - this->ghost_image[ghost_pixel_ptr++] = palette_idx1; - pixel_countdown--; - if (pixel_countdown < 0) - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "fli warning: pixel_countdown < 0 (%d)\n", pixel_countdown); - } - } - } - - ghost_y_ptr += this->width; - } - break; - - case FLI_COPY: - /* copy the chunk (uncompressed frame) to the ghost image and - * schedule the whole frame to be updated */ - if (chunk_size - 6 > this->width * this->height) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "FLI: in chunk FLI_COPY : source data (%d bytes) bigger than image, skipping chunk\n", - chunk_size - 6); - break; - } else - memcpy(this->ghost_image, &this->buf[stream_ptr], chunk_size - 6); - stream_ptr += chunk_size - 6; - update_whole_frame = 1; - break; - - case FLI_MINI: - /* some sort of a thumbnail? disregard this chunk... */ - stream_ptr += chunk_size - 6; - break; - - default: - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "FLI: Unrecognized chunk type: %d\n", chunk_type); - break; - } - - frame_size -= chunk_size; - num_chunks--; - } - - if (update_whole_frame) { - - pixel_ptr = ghost_pixel_ptr = 0; - for (lines = 0; lines < this->height; lines++) { - for (x = 0; x < this->width; x++) { - palette_ptr1 = this->ghost_image[ghost_pixel_ptr++] * 4; - this->yuv_planes.y[pixel_ptr] = this->yuv_palette[palette_ptr1 + 0]; - this->yuv_planes.u[pixel_ptr] = this->yuv_palette[palette_ptr1 + 1]; - this->yuv_planes.v[pixel_ptr] = this->yuv_palette[palette_ptr1 + 2]; - pixel_ptr++; - } - } - } - - /* by the end of the chunk, the stream ptr should equal the frame - * size (minus 1, possibly); if it doesn't, issue a warning */ - if ((stream_ptr != this->size) && (stream_ptr != this->size - 1)) - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "warning: processed FLI chunk where chunk size = %d\nand final chunk ptr = %d\n", - this->size, stream_ptr); -} - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -/* - * This function receives a buffer of data from the demuxer layer and - * figures out how to handle it based on its header flags. - */ -static void fli_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - fli_decoder_t *this = (fli_decoder_t *) this_gen; - vo_frame_t *img; /* video out frame */ - - /* a video decoder does not care about this flag (?) */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) - this->video_step = buf->decoder_info[0]; - - if (buf->decoder_flags & BUF_FLAG_HEADER) { /* need to initialize */ - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - /* RGB -> YUV converter requires even width */ - this->width = (LE_16(&buf->content[8]) + 1) & ~0x1; - this->height = LE_16(&buf->content[10]); - this->ratio = (double)this->width/(double)this->height; - this->magic_number = LE_16(&buf->content[4]); - - this->ghost_image = xine_xmalloc(this->width * this->height); - init_yuv_planes(&this->yuv_planes, this->width, this->height); - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - this->stream->video_out->open (this->stream->video_out, this->stream); - this->decoder_ok = 1; - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "FLI/FLC Video"); - - return; - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, XINE_IMGFMT_YUY2, VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = 0; - - decode_fli_frame(this); - yuv444_to_yuy2(&this->yuv_planes, img->base[0], img->pitches[0]); - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -/* - * This function is called when xine needs to flush the system. Not - * sure when or if this is used or even if it needs to do anything. - */ -static void fli_flush (video_decoder_t *this_gen) { -} - -/* - * This function resets the video decoder. - */ -static void fli_reset (video_decoder_t *this_gen) { - fli_decoder_t *this = (fli_decoder_t *) this_gen; - - this->size = 0; -} - -static void fli_discontinuity (video_decoder_t *this_gen) { -} - -/* - * This function frees the video decoder instance allocated to the decoder. - */ -static void fli_dispose (video_decoder_t *this_gen) { - - fli_decoder_t *this = (fli_decoder_t *) this_gen; - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - free_yuv_planes(&this->yuv_planes); - free(this->ghost_image); - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - fli_decoder_t *this ; - - this = (fli_decoder_t *) xine_xmalloc (sizeof (fli_decoder_t)); - - this->video_decoder.decode_data = fli_decode_data; - this->video_decoder.flush = fli_flush; - this->video_decoder.reset = fli_reset; - this->video_decoder.discontinuity = fli_discontinuity; - this->video_decoder.dispose = fli_dispose; - this->size = 0; - - this->stream = stream; - this->class = (fli_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "FLI Video"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Autodesk Animator FLI/FLC video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - fli_class_t *this; - - this = (fli_class_t *) xine_xmalloc (sizeof (fli_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t video_types[] = { - BUF_VIDEO_FLI, - 0 - }; - -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 5 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "fli", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; - diff --git a/src/libxinevdec/idcinvideo.c b/src/libxinevdec/idcinvideo.c deleted file mode 100644 index 65308eb4a..000000000 --- a/src/libxinevdec/idcinvideo.c +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Id CIN Video Decoder by Dr. Tim Ferguson. For more information about - * the Id CIN format, visit: - * http://www.csse.monash.edu.au/~timf/ - * - * $Id: idcinvideo.c,v 1.23 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "buffer.h" -#include "xine_internal.h" -#include "video_out.h" -#include "xineutils.h" -#include "bswap.h" - -#define VIDEOBUFSIZE 128*1024 - -typedef struct { - video_decoder_class_t decoder_class; -} idcinvideo_class_t; - -typedef struct idcinvideo_decoder_s { - video_decoder_t video_decoder; /* parent video decoder structure */ - - idcinvideo_class_t *class; - xine_stream_t *stream; - - /* these are traditional variables in a video decoder object */ - uint64_t video_step; /* frame duration in pts units */ - int decoder_ok; /* current decoder status */ - int skipframes; - - unsigned char *buf; /* the accumulated buffer data */ - int bufsize; /* the maximum size of buf */ - int size; /* the current size of buf */ - - int width; /* the width of a video frame */ - int height; /* the height of a video frame */ - double ratio; /* the width to height ratio */ - - unsigned char yuv_palette[256 * 4]; - yuv_planes_t yuv_planes; - -} idcinvideo_decoder_t; - -/************************************************************************** - * idcinvideo specific decode functions - *************************************************************************/ - -#define HUF_TOKENS 256 - -typedef struct -{ - long rate; - long width; - long channels; -} wavinfo_t; - -typedef struct -{ - int count; - unsigned char used; - int children[2]; -} hnode_t; - -static hnode_t huff_nodes[256][HUF_TOKENS*2]; -static int num_huff_nodes[256]; - -/* - * Decodes input Huffman data using the Huffman table. - */ -static void huff_decode(idcinvideo_decoder_t *this) { - hnode_t *hnodes; - long i; - int prev; - unsigned char v = 0; - int bit_pos, node_num, dat_pos; - int plane_ptr = 0; - - prev = bit_pos = dat_pos = 0; - for(i = 0; i < (this->width * this->height); i++) { - node_num = num_huff_nodes[prev]; - hnodes = huff_nodes[prev]; - - while(node_num >= HUF_TOKENS) { - if(!bit_pos) { - if(dat_pos > this->size) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "Huffman decode error.\n"); - return; - } - bit_pos = 8; - v = this->buf[dat_pos++]; - } - - node_num = hnodes[node_num].children[v & 0x01]; - v = v >> 1; - bit_pos--; - } - - this->yuv_planes.y[plane_ptr] = this->yuv_palette[node_num * 4 + 0]; - this->yuv_planes.u[plane_ptr] = this->yuv_palette[node_num * 4 + 1]; - this->yuv_planes.v[plane_ptr] = this->yuv_palette[node_num * 4 + 2]; - plane_ptr++; - - prev = node_num; - } -} - -/* - * Find the lowest probability node in a Huffman table, and mark it as - * being assigned to a higher probability. - * Returns the node index of the lowest unused node, or -1 if all nodes - * are used. - */ -static int huff_smallest_node(hnode_t *hnodes, int num_hnodes) { - int i; - int best, best_node; - - best = 99999999; - best_node = -1; - for(i = 0; i < num_hnodes; i++) { - if(hnodes[i].used) - continue; - if(!hnodes[i].count) - continue; - if(hnodes[i].count < best) { - best = hnodes[i].count; - best_node = i; - } - } - - if(best_node == -1) - return -1; - hnodes[best_node].used = 1; - return best_node; -} - -/* - * Build the Huffman tree using the generated/loaded probabilities histogram. - * - * On completion: - * huff_nodes[prev][i < HUF_TOKENS] - are the nodes at the base of the tree. - * huff_nodes[prev][i >= HUF_TOKENS] - are used to construct the tree. - * num_huff_nodes[prev] - contains the index to the root node of the tree. - * That is: huff_nodes[prev][num_huff_nodes[prev]] is the root node. - */ -static void huff_build_tree(int prev) { - hnode_t *node, *hnodes; - int num_hnodes, i; - - num_hnodes = HUF_TOKENS; - hnodes = huff_nodes[prev]; - for(i = 0; i < HUF_TOKENS * 2; i++) - hnodes[i].used = 0; - - while (1) { - node = &hnodes[num_hnodes]; /* next free node */ - - /* pick two lowest counts */ - node->children[0] = huff_smallest_node(hnodes, num_hnodes); - if(node->children[0] == -1) - break; /* reached the root node */ - - node->children[1] = huff_smallest_node(hnodes, num_hnodes); - if(node->children[1] == -1) - break; /* reached the root node */ - - /* combine nodes probability for new node */ - node->count = hnodes[node->children[0]].count + - hnodes[node->children[1]].count; - num_hnodes++; - } - - num_huff_nodes[prev] = num_hnodes - 1; -} - - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -/* - * This function receives a buffer of data from the demuxer layer and - * figures out how to handle it based on its header flags. - */ -static void idcinvideo_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - idcinvideo_decoder_t *this = (idcinvideo_decoder_t *) this_gen; - palette_entry_t *palette; - unsigned char *histograms; - int i, j, histogram_index = 0; - - vo_frame_t *img; /* video out frame */ - - /* a video decoder does not care about this flag (?) */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - /* load the palette */ - if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { - palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - for (i = 0; i < buf->decoder_info[2]; i++) { - this->yuv_palette[i * 4 + 0] = - COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 1] = - COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 2] = - COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */ - xine_bmiheader *bih = (xine_bmiheader *)buf->content; - - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - this->width = bih->biWidth; - this->height = bih->biHeight; - this->ratio = (double)this->width/(double)this->height; - - /* initialize the Huffman tables */ - histograms = (unsigned char *)buf->content + sizeof(xine_bmiheader); - for (i = 0; i < 256; i++) { - for(j = 0; j < HUF_TOKENS; j++) - huff_nodes[i][j].count = histograms[histogram_index++]; - huff_build_tree(i); - } - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - init_yuv_planes(&this->yuv_planes, this->width, this->height); - - this->stream->video_out->open (this->stream->video_out, this->stream); - this->decoder_ok = 1; - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Id CIN Video"); - - return; - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, XINE_IMGFMT_YUY2, VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = 0; - - huff_decode(this); - yuv444_to_yuy2(&this->yuv_planes, img->base[0], img->pitches[0]); - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -/* - * This function is called when xine needs to flush the system. Not - * sure when or if this is used or even if it needs to do anything. - */ -static void idcinvideo_flush (video_decoder_t *this_gen) { -} - -/* - * This function resets the video decoder. - */ -static void idcinvideo_reset (video_decoder_t *this_gen) { - idcinvideo_decoder_t *this = (idcinvideo_decoder_t *) this_gen; - - this->size = 0; -} - -static void idcinvideo_discontinuity (video_decoder_t *this_gen) { -} - -/* - * This function frees the video decoder instance allocated to the decoder. - */ -static void idcinvideo_dispose (video_decoder_t *this_gen) { - - idcinvideo_decoder_t *this = (idcinvideo_decoder_t *) this_gen; - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - idcinvideo_decoder_t *this ; - - this = (idcinvideo_decoder_t *) xine_xmalloc (sizeof (idcinvideo_decoder_t)); - - this->video_decoder.decode_data = idcinvideo_decode_data; - this->video_decoder.flush = idcinvideo_flush; - this->video_decoder.reset = idcinvideo_reset; - this->video_decoder.discontinuity = idcinvideo_discontinuity; - this->video_decoder.dispose = idcinvideo_dispose; - this->size = 0; - - this->stream = stream; - this->class = (idcinvideo_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "Id CIN Video"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Id Quake II Cinematic video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - idcinvideo_class_t *this; - - this = (idcinvideo_class_t *) xine_xmalloc (sizeof (idcinvideo_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_VIDEO_IDCIN, 0 }; - -static decoder_info_t video_decoder_info = { - supported_types, /* supported types */ - 5 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "idcinvideo", XINE_VERSION_CODE, &video_decoder_info, &init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/interplayvideo.c b/src/libxinevdec/interplayvideo.c deleted file mode 100644 index 503db7004..000000000 --- a/src/libxinevdec/interplayvideo.c +++ /dev/null @@ -1,1388 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Interplay MVE File Video Decoder by Mike Melanson (melanson@pcisys.net) - * For more information regarding the Interplay MVE format, visit: - * http://www.pcisys.net/~melanson/codecs/ - * - * $Id: interplayvideo.c,v 1.12 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" - -/* debugging support */ -#define DEBUG_INTERPLAY 0 -#if DEBUG_INTERPLAY -#define debug_interplay printf -#else -static inline void debug_interplay(const char *format, ...) { } -#endif - -#define VIDEOBUFSIZE 128*1024 - -typedef struct { - video_decoder_class_t decoder_class; -} interplay_class_t; - -typedef struct interplay_decoder_s { - video_decoder_t video_decoder; /* parent video decoder structure */ - - interplay_class_t *class; - xine_stream_t *stream; - - /* these are traditional variables in a video decoder object */ - uint64_t video_step; /* frame duration in pts units */ - int decoder_ok; /* current decoder status */ - int skipframes; - - unsigned char *buf; /* the accumulated buffer data */ - int bufsize; /* the maximum size of buf */ - int size; /* the current size of buf */ - - int width; /* the width of a video frame */ - int height; /* the height of a video frame */ - double ratio; /* the width to height ratio */ - - unsigned char yuv_palette[256 * 4]; - - yuv_planes_t yuv_planes1; - yuv_planes_t yuv_planes2; - - yuv_planes_t *current_frame; - yuv_planes_t *previous_frame; - - /* this is either 1 or 2 indicating the current_frame points to yuv_planes - * structure 1 or 2 */ - int current_planes; - - unsigned char *decode_map; - int decode_map_index; - -} interplay_decoder_t; - -/************************************************************************** - * Interplay Video specific decode functions - *************************************************************************/ - -#define CHECK_STREAM_PTR(n) \ - if ((stream_ptr + n) > this->size) { \ - printf ("Interplay video warning: stream_ptr out of bounds (%d >= %d)\n", \ - stream_ptr + n, this->size); \ - return; \ - } - -#define COPY_BLOCK_FROM_CURRENT() \ - if (motion_pixel_ptr < 0) \ - printf ("Interplay video warning: motion pixel ptr < 0 (%d), motion byte = %d (0x%X)\n", \ - motion_pixel_ptr, motion_byte, motion_byte); \ - else if (motion_pixel_ptr >= motion_limit) \ - printf ("Interplay video warning: motion pixel ptr out of motion range (%d >= %d), motion byte = %d (0x%X)\n", \ - motion_pixel_ptr, motion_limit, motion_byte, motion_byte); \ - else for (i = 0; i < 8; i++) { \ - xine_fast_memcpy(&this->current_frame->y[pixel_ptr], \ - &this->current_frame->y[motion_pixel_ptr], 8); \ - xine_fast_memcpy(&this->current_frame->u[pixel_ptr], \ - &this->current_frame->u[motion_pixel_ptr], 8); \ - xine_fast_memcpy(&this->current_frame->v[pixel_ptr], \ - &this->current_frame->v[motion_pixel_ptr], 8); \ - pixel_ptr += this->width; \ - } - -#define COPY_BLOCK_FROM_PREVIOUS() \ - if (motion_pixel_ptr < 0) \ - printf ("Interplay video warning: motion pixel ptr < 0 (%d), motion byte = %d (0x%X)\n", \ - motion_pixel_ptr, motion_byte, motion_byte); \ - else if (motion_pixel_ptr >= motion_limit) \ - printf ("Interplay video warning: motion pixel ptr out of motion range (%d >= %d), motion byte = %d (0x%X)\n", \ - motion_pixel_ptr, motion_limit, motion_byte, motion_byte); \ - else for (i = 0; i < 8; i++) { \ - xine_fast_memcpy(&this->current_frame->y[pixel_ptr], \ - &this->previous_frame->y[motion_pixel_ptr], 8); \ - xine_fast_memcpy(&this->current_frame->u[pixel_ptr], \ - &this->previous_frame->u[motion_pixel_ptr], 8); \ - xine_fast_memcpy(&this->current_frame->v[pixel_ptr], \ - &this->previous_frame->v[motion_pixel_ptr], 8); \ - pixel_ptr += this->width; \ - } - -static void interplay_decode_frame(interplay_decoder_t *this) { - - int pixel_ptr, motion_pixel_ptr; - int x, y; - int xp, yp; - int i, j; - unsigned char code; - int index = 0; - int stream_ptr = 14; - unsigned char color0, color1, color2, color3; - unsigned char y0, u0, v0; - unsigned char y1, u1, v1; - unsigned char y2, u2, v2; - unsigned char y3, u3, v3; - unsigned char y4 = 0, u4 = 0, v4 = 0; - int row_inc = this->width - 8; - unsigned char motion_byte; - int motion_limit = this->width * (this->height - 8); - unsigned int flags; - unsigned int flag_mask; - int code_counts[16]; - - for (i = 0; i < 6; i++) { - for (j = 0; j < 16; j++) - debug_interplay (" %02X", this->buf[i * 16 + j]); - debug_interplay ("\n"); - } - - for (i = 0; i < 16; i++) - code_counts[i] = 0; - - /* interate through the 8x8 blocks, left -> right, top -> bottom */ - for (y = 0; y < (this->width * this->height); y += (this->width * 8)) { - for (x = y; x < (y + this->width); x += 8) { - if (index & 1) - code = this->decode_map[index >> 1] >> 4; - else - code = this->decode_map[index >> 1] & 0xF; - index++; - - debug_interplay (" block %3d, %3d: encoding 0x%X\n", - x - y, y / this->width, code); - code_counts[code]++; - switch (code) { - - case 0x0: - case 0x1: - /* skip block (actually, copy from previous frame) */ - motion_pixel_ptr = pixel_ptr = x; - motion_byte = 0; - COPY_BLOCK_FROM_PREVIOUS(); - break; - - case 0x2: - /* copy block from current frame, right-bottom */ - CHECK_STREAM_PTR(1); - - motion_byte = this->buf[stream_ptr++]; - motion_pixel_ptr = pixel_ptr = x; - - if (motion_byte < 56) { - /* horizontal component */ - motion_pixel_ptr += 8 + (motion_byte % 7); - /* vertical component */ - motion_pixel_ptr += ((motion_byte / 7) * this->width); - } else { - /* horizontal component */ - motion_pixel_ptr += (-14 + ((motion_byte - 56) % 29)); - /* vertical component */ - motion_pixel_ptr += ((8 + ((motion_byte - 56) / 29)) * this->width); - } - COPY_BLOCK_FROM_CURRENT(); - break; - - case 0x3: - /* copy block from current frame, left-top */ - CHECK_STREAM_PTR(1); - - motion_byte = this->buf[stream_ptr++]; - motion_pixel_ptr = pixel_ptr = x; - - if (motion_byte < 56) { - /* horizontal component */ - motion_pixel_ptr -= 8 + (motion_byte % 7); - /* vertical component */ - motion_pixel_ptr -= ((motion_byte / 7) * this->width); - } else { - /* horizontal component */ - motion_pixel_ptr -= (-14 + ((motion_byte - 56) % 29)); - /* vertical component */ - motion_pixel_ptr -= ((8 + ((motion_byte - 56) / 29)) * this->width); - } - COPY_BLOCK_FROM_CURRENT(); - break; - - case 0x4: - /* copy block from previous frame, right-bottom */ - CHECK_STREAM_PTR(1); - - motion_byte = this->buf[stream_ptr++]; - motion_pixel_ptr = pixel_ptr = x; - - /* horizontal component */ - motion_pixel_ptr += (-8 + (motion_byte & 0xF)); - /* vertical component */ - motion_pixel_ptr += ((-8 + ((motion_byte >> 4) & 0xF)) * this->width); - COPY_BLOCK_FROM_PREVIOUS(); - break; - - case 0x5: - /* copy block from previous frame, left-top */ - CHECK_STREAM_PTR(2); - - motion_pixel_ptr = pixel_ptr = x; - /* horizontal component */ - motion_byte = this->buf[stream_ptr++]; - motion_pixel_ptr += (signed char)motion_byte; - /* vertical component */ - motion_byte = this->buf[stream_ptr++]; - motion_pixel_ptr += ((signed char)motion_byte * this->width); - COPY_BLOCK_FROM_PREVIOUS(); - break; - - case 0x6: - /* mystery opcode? skip multiple blocks? */ - break; - - case 0x7: - /* 2-color encoding */ - color0 = this->buf[stream_ptr++]; - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - color1 = this->buf[stream_ptr++]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - - if (color0 <= color1) { - /* get 8 bytes, or 64 flags from the bytestream; if a flag is 0 - * use color 0; 1, use color 1 */ - CHECK_STREAM_PTR(8); - pixel_ptr = x; - for (i = 0; i < 8; i++) { - flags = this->buf[stream_ptr++]; - for (flag_mask = 0x80; flag_mask != 0; flag_mask >>= 1) { - if (flags & flag_mask) { - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - } else { - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - } - pixel_ptr++; - } - pixel_ptr += row_inc; - } - } else { - /* get 2 bytes, or 16 flags from the bytestream; use them to - * paint 2x2 blocks */ - CHECK_STREAM_PTR(2); - flags = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - flag_mask = 0x8000; - - for (yp = x; yp < (x + this->width * 8); yp += (this->width * 2)) { - for (xp = yp; xp < (yp + 8); xp += 2) { - - if (flags & flag_mask) { - y2 = y1; - u2 = u1; - v2 = v1; - } else { - y2 = y0; - u2 = u0; - v2 = v0; - } - flag_mask >>= 1; - - pixel_ptr = xp; - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - this->current_frame->y[pixel_ptr] = y2; - this->current_frame->u[pixel_ptr] = u2; - this->current_frame->v[pixel_ptr] = v2; - pixel_ptr++; - } - pixel_ptr += this->width - 2; - } - } - } - } - break; - - case 0x8: - /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on - * either top and bottom or left and right halves */ - CHECK_STREAM_PTR(2); - color0 = this->buf[stream_ptr++]; - color1 = this->buf[stream_ptr++]; - if (color0 <= color1) { - /* there are 14 more byte in the stream, for a total of 16; - * each set of 4 bytes contains 2 colors and 16 bit flags to - * specify how one 4x4 quadrant should me painted */ - CHECK_STREAM_PTR(14); - - /* iterate through 4 quadrants */ - for (xp = 0; xp < 4; xp++) { - if (xp == 0) - pixel_ptr = x; - else if (xp == 1) - pixel_ptr = x + (this->width * 4); - else if (xp == 2) - pixel_ptr = x + 4; - else - pixel_ptr = x + (this->width * 4) + 4; - - /* get this quadrant's color pair if this is not the first - * quadrant (those colors have already been obtained) */ - if (xp > 0) { - color0 = this->buf[stream_ptr++]; - color1 = this->buf[stream_ptr++]; - } - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - - /* get the flags for this quadrant */ - flags = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - flag_mask = 0x8000; - - /* paint the 4x4 block */ - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - if (flags & flag_mask) { - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - } else { - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - } - pixel_ptr++; - flag_mask >>= 1; - } - pixel_ptr += this->width - 4; - } - } - } else { - /* there are 10 more bytes in the stream for a total of 12; - * each set of 6 bytes contains 2 colors and 32 bit flags to - * specify how half of the 8x8 block (either 8x4 or 4x8) will - * be painted */ - CHECK_STREAM_PTR(10); - color2 = this->buf[stream_ptr + 4]; - color3 = this->buf[stream_ptr + 5]; - if (color2 <= color3) { - /* block is split into left and right halves */ - for (xp = 0; xp < 2; xp++) { - if (xp == 0) { - pixel_ptr = x; - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - flags = BE_32(&this->buf[stream_ptr]); - } else { - pixel_ptr = x + 4; - y0 = this->yuv_palette[color2 * 4 + 0]; - u0 = this->yuv_palette[color2 * 4 + 1]; - v0 = this->yuv_palette[color2 * 4 + 2]; - y1 = this->yuv_palette[color3 * 4 + 0]; - u1 = this->yuv_palette[color3 * 4 + 1]; - v1 = this->yuv_palette[color3 * 4 + 2]; - flags = BE_32(&this->buf[stream_ptr + 6]); - } - flag_mask = 0x80000000; - - /* paint the 4x8 block */ - for (i = 0; i < 8; i++) { - for (j = 0; j < 4; j++) { - if (flags & flag_mask) { - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - } else { - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - } - pixel_ptr++; - flag_mask >>= 1; - } - pixel_ptr += this->width - 4; - } - } - } else { - /* block is split into top and bottom halves */ - for (xp = 0; xp < 2; xp++) { - if (xp == 0) { - pixel_ptr = x; - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - flags = BE_32(&this->buf[stream_ptr]); - } else { - pixel_ptr = x + (this->width * 4); - y0 = this->yuv_palette[color2 * 4 + 0]; - u0 = this->yuv_palette[color2 * 4 + 1]; - v0 = this->yuv_palette[color2 * 4 + 2]; - y1 = this->yuv_palette[color3 * 4 + 0]; - u1 = this->yuv_palette[color3 * 4 + 1]; - v1 = this->yuv_palette[color3 * 4 + 2]; - flags = BE_32(&this->buf[stream_ptr + 6]); - } - flag_mask = 0x80000000; - - /* paint the 8x4 block */ - for (i = 0; i < 4; i++) { - for (j = 0; j < 8; j++) { - if (flags & flag_mask) { - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - } else { - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - } - pixel_ptr++; - flag_mask >>= 1; - } - pixel_ptr += row_inc; - } - } - } - - stream_ptr += 10; - } - break; - - case 0x9: - /* 4-color encoding */ - CHECK_STREAM_PTR(4); - color0 = this->buf[stream_ptr++]; - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - color1 = this->buf[stream_ptr++]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - color2 = this->buf[stream_ptr++]; - y2 = this->yuv_palette[color2 * 4 + 0]; - u2 = this->yuv_palette[color2 * 4 + 1]; - v2 = this->yuv_palette[color2 * 4 + 2]; - color3 = this->buf[stream_ptr++]; - y3 = this->yuv_palette[color3 * 4 + 0]; - u3 = this->yuv_palette[color3 * 4 + 1]; - v3 = this->yuv_palette[color3 * 4 + 2]; - - if ((color0 <= color1) && (color2 <= color3)) { - - /* there are 16 bytes in the stream which form 64 2-bit - * flags to select the color of each of the 64 pixels in - * the 8x8 block */ - CHECK_STREAM_PTR(16); - pixel_ptr = x; - for (i = 0; i < 8; i++) { - /* reload the flags at every row */ - flags = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - flag_mask = 14; - for (j = 0; j < 8; j++) { - switch ((flags >> flag_mask) & 0x03) { - - case 0: - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - break; - - case 1: - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - break; - - case 2: - this->current_frame->y[pixel_ptr] = y2; - this->current_frame->u[pixel_ptr] = u2; - this->current_frame->v[pixel_ptr] = v2; - break; - - case 3: - this->current_frame->y[pixel_ptr] = y3; - this->current_frame->u[pixel_ptr] = u3; - this->current_frame->v[pixel_ptr] = v3; - break; - - } - pixel_ptr++; - flag_mask -= 2; - } - pixel_ptr += row_inc; - } - - } else if ((color0 <= color1) && (color2 > color3)) { - - /* there are 4 bytes in the stream comprising 16 2-bit - * flags which specify 1 of 4 colors for each of 16 2x2 - * blocks */ - CHECK_STREAM_PTR(4); - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - - for (yp = x; yp < (x + this->width * 8); yp += (this->width * 2)) { - for (xp = yp; xp < (yp + 8); xp += 2) { - - switch ((flags >> flag_mask) & 0x03) { - - case 0: - y4 = y0; - u4 = u0; - v4 = v0; - break; - - case 1: - y4 = y1; - u4 = u1; - v4 = v1; - break; - - case 2: - y4 = y2; - u4 = u2; - v4 = v2; - break; - - case 3: - y4 = y3; - u4 = u3; - v4 = v3; - break; - - } - flag_mask -= 2; - - pixel_ptr = xp; - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - this->current_frame->y[pixel_ptr] = y4; - this->current_frame->u[pixel_ptr] = u4; - this->current_frame->v[pixel_ptr] = v4; - pixel_ptr++; - } - pixel_ptr += this->width - 2; - } - } - } - - } else if ((color0 > color1) && (color2 <= color3)) { - - /* there are 8 bytes in the stream comprising 32 2-bit - * flags which specify 1 of 4 colors for each of 32 2x1 - * blocks */ - CHECK_STREAM_PTR(8); - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - - for (yp = x; yp < (x + this->width * 8); yp += this->width) { - - /* time to reload flags? */ - if (yp == (x + this->width * 4)) { - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - } - - for (xp = yp; xp < (yp + 8); xp += 2) { - - switch ((flags >> flag_mask) & 0x03) { - - case 0: - y4 = y0; - u4 = u0; - v4 = v0; - break; - - case 1: - y4 = y1; - u4 = u1; - v4 = v1; - break; - - case 2: - y4 = y2; - u4 = u2; - v4 = v2; - break; - - case 3: - y4 = y3; - u4 = u3; - v4 = v3; - break; - - } - flag_mask -= 2; - - pixel_ptr = xp; - for (i = 0; i < 2; i++) { - this->current_frame->y[pixel_ptr] = y4; - this->current_frame->u[pixel_ptr] = u4; - this->current_frame->v[pixel_ptr] = v4; - pixel_ptr++; - } - } - } - - } else { - - /* there are 8 bytes in the stream comprising 32 2-bit - * flags which specify 1 of 4 colors for each of 32 1x2 - * blocks */ - CHECK_STREAM_PTR(8); - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - - for (yp = x; yp < (x + this->width * 8); yp += (this->width * 2)) { - - /* time to reload flags? */ - if (yp == (x + this->width * 4)) { - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - } - - for (xp = yp; xp < (yp + 8); xp++) { - - switch ((flags >> flag_mask) & 0x03) { - - case 0: - y4 = y0; - u4 = u0; - v4 = v0; - break; - - case 1: - y4 = y1; - u4 = u1; - v4 = v1; - break; - - case 2: - y4 = y2; - u4 = u2; - v4 = v2; - break; - - case 3: - y4 = y3; - u4 = u3; - v4 = v3; - break; - - } - flag_mask -= 2; - - pixel_ptr = xp; - for (i = 0; i < 2; i++) { - this->current_frame->y[pixel_ptr] = y4; - this->current_frame->u[pixel_ptr] = u4; - this->current_frame->v[pixel_ptr] = v4; - pixel_ptr += row_inc; - } - } - } - } - break; - - case 0xA: - /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on - * either top and bottom or left and right halves */ - CHECK_STREAM_PTR(4); - color0 = this->buf[stream_ptr++]; - color1 = this->buf[stream_ptr++]; - color2 = this->buf[stream_ptr++]; - color3 = this->buf[stream_ptr++]; - if (color0 <= color1) { - /* there are 28 more byte in the stream, for a total of 32; - * each set of 8 bytes contains 4 colors and 16 2-bit flags to - * specify how one 4x4 quadrant should me painted */ - CHECK_STREAM_PTR(28); - - /* iterate through 4 quadrants */ - for (xp = 0; xp < 4; xp++) { - if (xp == 0) - pixel_ptr = x; - else if (xp == 1) - pixel_ptr = x + (this->width * 4); - else if (xp == 2) - pixel_ptr = x + 4; - else - pixel_ptr = x + (this->width * 4) + 4; - - /* get this quadrant's color pair if this is not the first - * quadrant (those colors have already been obtained) */ - if (xp > 0) { - color0 = this->buf[stream_ptr++]; - color1 = this->buf[stream_ptr++]; - color2 = this->buf[stream_ptr++]; - color3 = this->buf[stream_ptr++]; - } - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - y2 = this->yuv_palette[color2 * 4 + 0]; - u2 = this->yuv_palette[color2 * 4 + 1]; - v2 = this->yuv_palette[color2 * 4 + 2]; - y3 = this->yuv_palette[color3 * 4 + 0]; - u3 = this->yuv_palette[color3 * 4 + 1]; - v3 = this->yuv_palette[color3 * 4 + 2]; - - /* get the flags for this quadrant */ - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - - /* paint the 4x4 block */ - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - - switch ((flags >> flag_mask) & 0x03) { - - case 0: - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - break; - - case 1: - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - break; - - case 2: - this->current_frame->y[pixel_ptr] = y2; - this->current_frame->u[pixel_ptr] = u2; - this->current_frame->v[pixel_ptr] = v2; - break; - - case 3: - this->current_frame->y[pixel_ptr] = y3; - this->current_frame->u[pixel_ptr] = u3; - this->current_frame->v[pixel_ptr] = v3; - break; - - } - flag_mask -= 2; - pixel_ptr++; - } - pixel_ptr += this->width - 4; - } - } - } else { - /* there are 20 more bytes in the stream for a total of 24; - * each set of 12 bytes contains 4 colors and 64 2-bit flags to - * specify how half of the 8x8 block (either 8x4 or 4x8) will - * be painted */ - CHECK_STREAM_PTR(20); - - if (color2 <= color3) { - /* block is split into left and right halves */ - for (xp = 0; xp < 2; xp++) { - if (xp == 0) - pixel_ptr = x; - else { - color0 = this->buf[stream_ptr++]; - color1 = this->buf[stream_ptr++]; - color2 = this->buf[stream_ptr++]; - color3 = this->buf[stream_ptr++]; - pixel_ptr = x + 4; - } - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - y2 = this->yuv_palette[color2 * 4 + 0]; - u2 = this->yuv_palette[color2 * 4 + 1]; - v2 = this->yuv_palette[color2 * 4 + 2]; - y3 = this->yuv_palette[color3 * 4 + 0]; - u3 = this->yuv_palette[color3 * 4 + 1]; - v3 = this->yuv_palette[color3 * 4 + 2]; - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - - /* paint the 4x8 block */ - for (i = 0; i < 8; i++) { - - /* time to reload flags? */ - if (i == 4) { - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - } - for (j = 0; j < 4; j++) { - - switch ((flags >> flag_mask) & 0x03) { - - case 0: - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - break; - - case 1: - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - break; - - case 2: - this->current_frame->y[pixel_ptr] = y2; - this->current_frame->u[pixel_ptr] = u2; - this->current_frame->v[pixel_ptr] = v2; - break; - - case 3: - this->current_frame->y[pixel_ptr] = y3; - this->current_frame->u[pixel_ptr] = u3; - this->current_frame->v[pixel_ptr] = v3; - break; - - } - - pixel_ptr++; - flag_mask -= 2; - } - pixel_ptr += this->width - 4; - } - } - } else { - /* block is split into top and bottom halves */ - for (xp = 0; xp < 2; xp++) { - if (xp == 0) - pixel_ptr = x; - else { - color0 = this->buf[stream_ptr++]; - color1 = this->buf[stream_ptr++]; - color2 = this->buf[stream_ptr++]; - color3 = this->buf[stream_ptr++]; - pixel_ptr = x + (this->width * 4); - } - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - y2 = this->yuv_palette[color2 * 4 + 0]; - u2 = this->yuv_palette[color2 * 4 + 1]; - v2 = this->yuv_palette[color2 * 4 + 2]; - y3 = this->yuv_palette[color3 * 4 + 0]; - u3 = this->yuv_palette[color3 * 4 + 1]; - v3 = this->yuv_palette[color3 * 4 + 2]; - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - - /* paint the 8x4 block */ - for (i = 0; i < 4; i++) { - - /* time to reload flags? */ - if (i == 2) { - flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - flag_mask = 30; - } - for (j = 0; j < 8; j++) { - - switch ((flags >> flag_mask) & 0x03) { - - case 0: - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - break; - - case 1: - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - break; - - case 2: - this->current_frame->y[pixel_ptr] = y2; - this->current_frame->u[pixel_ptr] = u2; - this->current_frame->v[pixel_ptr] = v2; - break; - - case 3: - this->current_frame->y[pixel_ptr] = y3; - this->current_frame->u[pixel_ptr] = u3; - this->current_frame->v[pixel_ptr] = v3; - break; - - } - - pixel_ptr++; - flag_mask -= 2; - } - pixel_ptr += row_inc; - } - } - } - - stream_ptr += 10; - } - break; - - case 0xB: - /* 64-color encoding (each pixel is a different color) */ - CHECK_STREAM_PTR(64); - - pixel_ptr = x; - for (i = 0; i < 8; i++) { - for (j = 0; j < 8; j++) { - color0 = this->buf[stream_ptr++]; - this->current_frame->y[pixel_ptr] = - this->yuv_palette[color0 * 4 + 0]; - this->current_frame->u[pixel_ptr] = - this->yuv_palette[color0 * 4 + 1]; - this->current_frame->v[pixel_ptr] = - this->yuv_palette[color0 * 4 + 2]; - pixel_ptr++; - } - pixel_ptr += row_inc; - } - break; - - case 0xC: - /* 16-color block encoding: each 2x2 block is a different color */ - CHECK_STREAM_PTR(16); - for (yp = x; yp < (x + this->width * 8); yp += (this->width * 2)) { - for (xp = yp; xp < (yp + 8); xp += 2) { - color0 = this->buf[stream_ptr++]; - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - - pixel_ptr = xp; - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - pixel_ptr++; - } - pixel_ptr += this->width - 2; - } - } - } - break; - - case 0xD: - /* 4-color block encoding: each 4x4 block is a different color */ - CHECK_STREAM_PTR(4); - for (yp = x; yp < (x + this->width * 8); yp += (this->width * 4)) { - for (xp = yp; xp < (yp + 8); xp += 4) { - color0 = this->buf[stream_ptr++]; - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - - pixel_ptr = xp; - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - pixel_ptr++; - } - pixel_ptr += this->width - 4; - } - } - } - break; - - case 0xE: - /* 1-color encoding: the whole block is 1 solid color */ - CHECK_STREAM_PTR(1); - color0 = this->buf[stream_ptr++]; - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - - pixel_ptr = x; - for (i = 0; i < 8; i++) { - for (j = 0; j < 8; j++) { - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - pixel_ptr++; - } - pixel_ptr += row_inc; - } - break; - - case 0xF: - /* dithered encoding */ - CHECK_STREAM_PTR(2); - color0 = this->buf[stream_ptr++]; - y0 = this->yuv_palette[color0 * 4 + 0]; - u0 = this->yuv_palette[color0 * 4 + 1]; - v0 = this->yuv_palette[color0 * 4 + 2]; - color1 = this->buf[stream_ptr++]; - y1 = this->yuv_palette[color1 * 4 + 0]; - u1 = this->yuv_palette[color1 * 4 + 1]; - v1 = this->yuv_palette[color1 * 4 + 2]; - - pixel_ptr = x; - for (i = 0; i < 8; i++) { - for (j = 0; j < 4; j++) { - if (i & 1) { - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - pixel_ptr++; - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - pixel_ptr++; - } else { - this->current_frame->y[pixel_ptr] = y0; - this->current_frame->u[pixel_ptr] = u0; - this->current_frame->v[pixel_ptr] = v0; - pixel_ptr++; - this->current_frame->y[pixel_ptr] = y1; - this->current_frame->u[pixel_ptr] = u1; - this->current_frame->v[pixel_ptr] = v1; - pixel_ptr++; - } - } - pixel_ptr += row_inc; - } - break; - - } - } - } - - /* on the way out, make sure all the video data bytes were consumed */ - if (stream_ptr != this->size) - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "Interplay video warning: Finished decode with bytes left over (%d < %d)\n", - stream_ptr, this->size); - - debug_interplay ("code counts:\n"); - for (i = 0; i < 16; i++) - debug_interplay (" code %X: %d\n", i, code_counts[i]); -} - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -/* - * This function receives a buffer of data from the demuxer layer and - * figures out how to handle it based on its header flags. - */ -static void interplay_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - interplay_decoder_t *this = (interplay_decoder_t *) this_gen; - palette_entry_t *palette; - int i; - - vo_frame_t *img; /* video out frame */ - - /* a video decoder does not care about this flag (?) */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - /* load the palette */ - if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { - palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - for (i = 0; i < buf->decoder_info[2]; i++) { - this->yuv_palette[i * 4 + 0] = - COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 1] = - COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 2] = - COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */ - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - this->width = (buf->content[0] << 8) | buf->content[1]; - this->height = (buf->content[2] << 8) | buf->content[3]; - this->ratio = (double)this->width/(double)this->height; - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - /* the decode map consists of 4 bits for every 8x8 video block, or - * 1 byte for every 2 blocks (128 pixels) */ - this->decode_map = xine_xmalloc(this->width * this->height / 128); - this->decode_map_index = 0; - - init_yuv_planes(&this->yuv_planes1, this->width, this->height); - init_yuv_planes(&this->yuv_planes2, this->width, this->height); - this->current_planes = 1; - - /* take this opportunity to load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, - "Interplay MVE Video"); - - this->decoder_ok = 1; - - return; - } else if (this->decoder_ok) { - - /* check if the decoder map is being sent (keyframe flag is cleared */ - if ((buf->decoder_flags & BUF_FLAG_KEYFRAME) == 0) { - xine_fast_memcpy (&this->decode_map[this->decode_map_index], - buf->content, buf->size); - return; - } - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, - XINE_IMGFMT_YUY2, VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = 0; - - if (this->current_planes == 1) { - this->current_planes = 2; - this->current_frame = &this->yuv_planes1; - this->previous_frame = &this->yuv_planes2; - } else { - this->current_planes = 1; - this->current_frame = &this->yuv_planes2; - this->previous_frame = &this->yuv_planes1; - } - - interplay_decode_frame (this); - yuv444_to_yuy2(this->current_frame, img->base[0], img->pitches[0]); - - img->draw(img, this->stream); - img->free(img); - - this->size = this->decode_map_index = 0; - } - } -} - -/* - * This function is called when xine needs to flush the system. - */ -static void interplay_flush (video_decoder_t *this_gen) { -} - -/* - * This function resets the video decoder. - */ -static void interplay_reset (video_decoder_t *this_gen) { - interplay_decoder_t *this = (interplay_decoder_t *) this_gen; - - this->size = 0; -} - -/* - * The decoder should forget any stored pts values here. - */ -static void interplay_discontinuity (video_decoder_t *this_gen) { -} - -/* - * This function frees the video decoder instance allocated to the decoder. - */ -static void interplay_dispose (video_decoder_t *this_gen) { - - interplay_decoder_t *this = (interplay_decoder_t *) this_gen; - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decode_map) { - free (this->decode_map); - this->decode_map = NULL; - } - - free_yuv_planes(&this->yuv_planes1); - free_yuv_planes(&this->yuv_planes2); - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -/* - * This function allocates, initializes, and returns a private video - * decoder structure. - */ -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - interplay_decoder_t *this ; - - this = (interplay_decoder_t *) xine_xmalloc (sizeof (interplay_decoder_t)); - - this->video_decoder.decode_data = interplay_decode_data; - this->video_decoder.flush = interplay_flush; - this->video_decoder.reset = interplay_reset; - this->video_decoder.discontinuity = interplay_discontinuity; - this->video_decoder.dispose = interplay_dispose; - this->size = 0; - - this->stream = stream; - this->class = (interplay_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -/* - * This function returns a brief string that describes (usually with the - * decoder's most basic name) the video decoder plugin. - */ -static char *get_identifier (video_decoder_class_t *this) { - return "Interplay MVE Video"; -} - -/* - * This function returns a slightly longer string describing the video - * decoder plugin. - */ -static char *get_description (video_decoder_class_t *this) { - return "Interplay MVE File video decoder plugin"; -} - -/* - * This function frees the video decoder class and any other memory that was - * allocated. - */ -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -/* - * This function allocates a private video decoder class and initializes - * the class's member functions. - */ -static void *init_plugin (xine_t *xine, void *data) { - - interplay_class_t *this; - - this = (interplay_class_t *) xine_xmalloc (sizeof (interplay_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * This is a list of all of the internal xine video buffer types that - * this decoder is able to handle. Check src/xine-engine/buffer.h for a - * list of valid buffer types (and add a new one if the one you need does - * not exist). Terminate the list with a 0. - */ -static uint32_t video_types[] = { - BUF_VIDEO_INTERPLAY, - 0 -}; - -/* - * This data structure combines the list of supported xine buffer types and - * the priority that the plugin should be given with respect to other - * plugins that handle the same buffer type. A plugin with priority (n+1) - * will be used instead of a plugin with priority (n). - */ -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 5 /* priority */ -}; - -/* - * The plugin catalog entry. This is the only information that this plugin - * will export to the public. - */ -plugin_info_t xine_plugin_info[] = { - /* { type, API, "name", version, special_info, init_function } */ - { PLUGIN_VIDEO_DECODER, 18, "interplay", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/msrle.c b/src/libxinevdec/msrle.c deleted file mode 100644 index ded2ed56a..000000000 --- a/src/libxinevdec/msrle.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * MS RLE Decoder by Mike Melanson (melanson@pcisys.net) - * For more information on the MS RLE format, visit: - * http://www.pcisys.net/~melanson/codecs/ - * - * $Id: msrle.c,v 1.26 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" - -#define VIDEOBUFSIZE 128*1024 - -typedef struct { - video_decoder_class_t decoder_class; -} msrle_class_t; - -typedef struct msrle_decoder_s { - video_decoder_t video_decoder; /* parent video decoder structure */ - - msrle_class_t *class; - xine_stream_t *stream; - - /* these are traditional variables in a video decoder object */ - uint64_t video_step; /* frame duration in pts units */ - int decoder_ok; /* current decoder status */ - int skipframes; - - unsigned char *buf; /* the accumulated buffer data */ - int bufsize; /* the maximum size of buf */ - int size; /* the current size of buf */ - - int width; /* the width of a video frame */ - int height; /* the height of a video frame */ - double ratio; /* the width to height ratio */ - - unsigned char yuv_palette[256 * 4]; - yuv_planes_t yuv_planes; - -} msrle_decoder_t; - -/************************************************************************** - * MS RLE specific decode functions - *************************************************************************/ - -#define FETCH_NEXT_STREAM_BYTE() \ - if (stream_ptr >= this->size) \ - { \ - printf(_("MS RLE: stream ptr just went out of bounds (1)\n")); \ - return; \ - } \ - stream_byte = this->buf[stream_ptr++]; - -static void decode_msrle8(msrle_decoder_t *this) { - - int stream_ptr = 0; - unsigned char rle_code; - unsigned char extra_byte; - unsigned char stream_byte; - int pixel_ptr = 0; - int row_dec = this->yuv_planes.row_width; - int row_ptr = (this->height - 1) * row_dec; - int frame_size = this->yuv_planes.row_width * this->height; - unsigned char y, u, v; - - while (row_ptr >= 0) { - FETCH_NEXT_STREAM_BYTE(); - rle_code = stream_byte; - if (rle_code == 0) { - /* fetch the next byte to see how to handle escape code */ - FETCH_NEXT_STREAM_BYTE(); - if (stream_byte == 0) { - /* line is done, goto the next one */ - row_ptr -= row_dec; - pixel_ptr = 0; - } else if (stream_byte == 1) { - /* decode is done */ - return; - } else if (stream_byte == 2) { - /* reposition frame decode coordinates */ - FETCH_NEXT_STREAM_BYTE(); - pixel_ptr += stream_byte; - FETCH_NEXT_STREAM_BYTE(); - row_ptr -= stream_byte * row_dec; - } else { - /* copy pixels from encoded stream */ - if ((row_ptr + pixel_ptr + stream_byte > frame_size) || - (row_ptr < 0)) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "MS RLE: frame ptr just went out of bounds (1)\n"); - return; - } - - rle_code = stream_byte; - extra_byte = stream_byte & 0x01; - if (stream_ptr + rle_code + extra_byte > this->size) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "MS RLE: stream ptr just went out of bounds (2)\n"); - return; - } - - while (rle_code--) { - FETCH_NEXT_STREAM_BYTE(); - y = this->yuv_palette[stream_byte * 4 + 0]; - u = this->yuv_palette[stream_byte * 4 + 1]; - v = this->yuv_palette[stream_byte * 4 + 2]; - this->yuv_planes.y[row_ptr + pixel_ptr] = y; - this->yuv_planes.u[row_ptr + pixel_ptr] = u; - this->yuv_planes.v[row_ptr + pixel_ptr] = v; - pixel_ptr++; - } - - /* if the RLE code is odd, skip a byte in the stream */ - if (extra_byte) - stream_ptr++; - } - } else { - /* decode a run of data */ - if ((row_ptr + pixel_ptr + stream_byte > frame_size) || - (row_ptr < 0)) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "MS RLE: frame ptr just went out of bounds (2)\n"); - return; - } - - FETCH_NEXT_STREAM_BYTE(); - - y = this->yuv_palette[stream_byte * 4 + 0]; - u = this->yuv_palette[stream_byte * 4 + 1]; - v = this->yuv_palette[stream_byte * 4 + 2]; - - while(rle_code--) { - this->yuv_planes.y[row_ptr + pixel_ptr] = y; - this->yuv_planes.u[row_ptr + pixel_ptr] = u; - this->yuv_planes.v[row_ptr + pixel_ptr] = v; - pixel_ptr++; - } - } - } - - /* one last sanity check on the way out */ - if (stream_ptr < this->size) - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "MS RLE: ended frame decode with bytes left over (%d < %d)\n", - stream_ptr, this->size); -} - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -/* - * This function receives a buffer of data from the demuxer layer and - * figures out how to handle it based on its header flags. - */ -static void msrle_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - msrle_decoder_t *this = (msrle_decoder_t *) this_gen; - xine_bmiheader *bih; - palette_entry_t *palette; - int i; - vo_frame_t *img; /* video out frame */ - - /* a video decoder does not care about this flag (?) */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - /* load the palette */ - if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { - palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - for (i = 0; i < buf->decoder_info[2]; i++) { - this->yuv_palette[i * 4 + 0] = - COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 1] = - COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 2] = - COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */ - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - bih = (xine_bmiheader *) buf->content; - this->width = (bih->biWidth + 3) & ~0x03; - this->height = (bih->biHeight + 3) & ~0x03; - this->ratio = (double)this->width/(double)this->height; - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - init_yuv_planes(&this->yuv_planes, this->width, this->height); - - this->stream->video_out->open (this->stream->video_out, this->stream); - this->decoder_ok = 1; - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Microsoft RLE"); - - return; - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, XINE_IMGFMT_YUY2, VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = 0; - - decode_msrle8(this); - yuv444_to_yuy2(&this->yuv_planes, img->base[0], img->pitches[0]); - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -/* - * This function is called when xine needs to flush the system. Not - * sure when or if this is used or even if it needs to do anything. - */ -static void msrle_flush (video_decoder_t *this_gen) { -} - -/* - * This function resets the video decoder. - */ -static void msrle_reset (video_decoder_t *this_gen) { - msrle_decoder_t *this = (msrle_decoder_t *) this_gen; - - this->size = 0; -} - -static void msrle_discontinuity (video_decoder_t *this_gen) { -} - -/* - * This function frees the video decoder instance allocated to the decoder. - */ -static void msrle_dispose (video_decoder_t *this_gen) { - msrle_decoder_t *this = (msrle_decoder_t *) this_gen; - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - msrle_decoder_t *this ; - - this = (msrle_decoder_t *) xine_xmalloc (sizeof (msrle_decoder_t)); - - this->video_decoder.decode_data = msrle_decode_data; - this->video_decoder.flush = msrle_flush; - this->video_decoder.reset = msrle_reset; - this->video_decoder.discontinuity = msrle_discontinuity; - this->video_decoder.dispose = msrle_dispose; - this->size = 0; - - this->stream = stream; - this->class = (msrle_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "MS RLE"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Microsoft RLE video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - msrle_class_t *this; - - this = (msrle_class_t *) xine_xmalloc (sizeof (msrle_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t video_types[] = { - BUF_VIDEO_MSRLE, - 0 - }; - -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 1 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "msrle", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/msvc.c b/src/libxinevdec/msvc.c deleted file mode 100644 index a2be6dbc0..000000000 --- a/src/libxinevdec/msvc.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (C) 2002-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * by Ewald Snel <ewald@rambo.its.tudelft.nl> - * - * based on overview of Microsoft Video-1 algorithm - * by Mike Melanson: http://www.pcisys.net/~melanson/codecs/video1.txt - * - * $Id: msvc.c,v 1.30 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdlib.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "bswap.h" -#include "xineutils.h" - -#define VIDEOBUFSIZE 128 * 1024 - -typedef struct { - uint16_t yu; - uint16_t yv; -} yuy2_t; - -typedef struct { - video_decoder_class_t decoder_class; -} msvc_class_t; - -typedef struct msvc_decoder_s { - video_decoder_t video_decoder; - - msvc_class_t *class; - xine_stream_t *stream; - - int64_t video_step; - int decoder_ok; - - unsigned char *buf; - int bufsize; - int size; - - unsigned int coded_width; - unsigned int coded_height; - int pitch; - int depth; - uint8_t *current; - yuy2_t color_table[256]; - - unsigned int width; - unsigned int height; - double ratio; -} msvc_decoder_t; - -/* taken from libw32dll */ -#define MAXSAMPLE 255 -#define CENTERSAMPLE 128 - -#define SCALEBITS 16 -#define FIX(x) ( (int32_t) ( (x) * (1<<SCALEBITS) + 0.5 ) ) -#define ONE_HALF ( (int32_t) (1<< (SCALEBITS-1)) ) -#define CBCR_OFFSET (CENTERSAMPLE << SCALEBITS) - -static inline void rgb_to_yuy2 (const int bits, uint32_t rgb, yuy2_t *c) { - uint8_t r, g, b; - uint8_t y, u, v; - - if (bits == 15) { - b = (rgb & 0x001F) << 3; - g = (rgb & 0x03E0) >> 5 << 3; - r = (rgb & 0x7C00) >> 10 << 3; - } else { - b = (rgb & 0x0000FF); - g = (rgb & 0x00FF00) >> 8; - r = (rgb & 0xFF0000) >> 16; - } - - y = (FIX(0.299) * r + FIX(0.587) * g + FIX(0.114) * b + ONE_HALF) >> SCALEBITS; - u = (- FIX(0.16874) * r - FIX(0.33126) * g + FIX(0.5) * b + CBCR_OFFSET + ONE_HALF-1) >> SCALEBITS; - v = (FIX(0.5) * r - FIX(0.41869) * g - FIX(0.08131) * b + CBCR_OFFSET + ONE_HALF-1) >> SCALEBITS; - - c->yu = le2me_16 (y | (u << 8)); - c->yv = le2me_16 (y | (v << 8)); -} - -static int msvc_decode_frame (msvc_decoder_t *this, uint8_t *data, int size) { - uint8_t *eod = (data + size); - uint32_t ctrl, clr8, skip; - int x, y, i, j; - uint16_t *out[4]; - yuy2_t c[2]; - - skip = 0; - - for (y=(this->coded_height - 4); y >= 0; y-=4) { - - out[0] = (uint16_t *) &this->current[y * this->pitch]; - out[1] = (uint16_t *) (((uint8_t *) out[0]) + this->pitch); - out[2] = (uint16_t *) (((uint8_t *) out[1]) + this->pitch); - out[3] = (uint16_t *) (((uint8_t *) out[2]) + this->pitch); - - for (x=0; x < this->coded_width; x+=4) { - if (skip == 0 || --skip == 0) { - if ((data + 2) >= eod) - return 0; - - ctrl = LE_16 (data); - data += 2; - - if ((ctrl & ((this->depth == 8) ? 0xF000 : 0x8000)) == 0x8000) { - if ((ctrl & ~0x3FF) == 0x8400) { - skip = (ctrl & 0x3FF); - } else { - if (this->depth == 8) - c[0] = this->color_table[(ctrl & 0xFF)]; - else - rgb_to_yuy2 (15, ctrl, &c[0]); - - for (i=0; i < 4; i++) { - out[i][0] = c[0].yu; - out[i][1] = c[0].yv; - out[i][2] = c[0].yu; - out[i][3] = c[0].yv; - } - } - } else { - if (this->depth == 8) { - if ((data + 2) >= eod) - return -1; - - c[1] = this->color_table[data[0]]; - c[0] = this->color_table[data[1]]; - clr8 = (ctrl >= 0x9000); - data += 2; - } else { - if ((data + 4) >= eod) - return -1; - - rgb_to_yuy2 (15, LE_16 (&data[0]), &c[1]); - rgb_to_yuy2 (15, LE_16 (&data[2]), &c[0]); - clr8 = (data[1] & 0x80); - data += 4; - } - - for (i=0; i < 4; i+=2) { - for (j=0; j < 4; j+=2) { - out[3-i][j] = c[(ctrl & 1) ].yu; - out[3-i][j+1] = c[(ctrl & 2) >> 1].yv; - out[2-i][j] = c[(ctrl & 16)>> 4].yu; - out[2-i][j+1] = c[(ctrl & 32)>> 5].yv; - ctrl >>= 2; - - if (clr8 && !(i & j)) { - if (this->depth == 8) { - if ((data + 2) >= eod) - return -1; - - c[1] = this->color_table[data[0]]; - c[0] = this->color_table[data[1]]; - data += 2; - } else { - if ((data + 4) >= eod) - return -1; - - rgb_to_yuy2 (15, LE_16 (&data[0]), &c[1]); - rgb_to_yuy2 (15, LE_16 (&data[2]), &c[0]); - data += 4; - } - } - } - - ctrl >>= 4; - } - } - } - - out[0] += 4; - out[1] += 4; - out[2] += 4; - out[3] += 4; - } - } - - return 0; -} - -static void msvc_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { - msvc_decoder_t *this = (msvc_decoder_t *) this_gen; - - int i; - palette_entry_t *palette; - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { - palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - for (i = 0; i < buf->decoder_info[2]; i++) - rgb_to_yuy2( - 32, - (palette[i].r << 16) | - (palette[i].g << 8) | - (palette[i].b << 0), - &this->color_table[i]); - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - xine_bmiheader *bih; - int image_size; - - bih = (xine_bmiheader *) buf->content; - - this->width = (bih->biWidth + 1) & ~0x1; - this->height = bih->biHeight; - this->ratio = (double)this->width/(double)this->height; - this->coded_width = (this->width + 3) & ~0x3; - this->coded_height = (this->height + 3) & ~0x3; - this->pitch = 2*this->coded_width; - this->depth = bih->biBitCount; - - if (this->depth != 8 && this->depth != 16) { - fprintf (stderr, "Unsupported bit depth (%d)\n", this->depth); - return; - } - - image_size = (this->pitch * this->coded_height); - this->current = (uint8_t *) realloc (this->current, image_size); - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - this->stream->video_out->open (this->stream->video_out, this->stream); - this->decoder_ok = 1; - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Microsoft Video-1"); - - } else if (this->decoder_ok && !(buf->decoder_flags & BUF_FLAG_SPECIAL)) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - vo_frame_t *img; - int result; - - result = msvc_decode_frame (this, this->buf, this->size); - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, - XINE_IMGFMT_YUY2, VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = (result != 0); - - if (this->pitch == img->pitches[0]) { - xine_fast_memcpy (img->base[0], this->current, img->pitches[0]*this->height); - } else { - uint8_t *src, *dst; - - src = (uint8_t *) this->current; - dst = img->base[0]; - - for (i=0; i < this->height; i++) { - xine_fast_memcpy (dst, src, 2*this->width); - src += this->pitch; - dst += img->pitches[0]; - } - } - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -static void msvc_flush (video_decoder_t *this_gen) { -} - -static void msvc_reset (video_decoder_t *this_gen) { - msvc_decoder_t *this = (msvc_decoder_t *) this_gen; - - this->size = 0; -} - -static void msvc_discontinuity (video_decoder_t *this_gen) { -} - -static void msvc_dispose (video_decoder_t *this_gen) { - - msvc_decoder_t *this = (msvc_decoder_t *) this_gen; - - if (this->current) { - free (this->current); - this->current = NULL; - } - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - msvc_decoder_t *this ; - - this = (msvc_decoder_t *) xine_xmalloc (sizeof (msvc_decoder_t)); - - this->video_decoder.decode_data = msvc_decode_data; - this->video_decoder.flush = msvc_flush; - this->video_decoder.reset = msvc_reset; - this->video_decoder.discontinuity = msvc_discontinuity; - this->video_decoder.dispose = msvc_dispose; - this->size = 0; - - this->stream = stream; - this->class = (msvc_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "MSVC"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Microsoft Video-1 video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - msvc_class_t *this; - - this = (msvc_class_t *) xine_xmalloc (sizeof (msvc_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t video_types[] = { - BUF_VIDEO_MSVC, - 0 - }; - -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 5 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "msvc", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/qtrle.c b/src/libxinevdec/qtrle.c deleted file mode 100644 index 445dc71d7..000000000 --- a/src/libxinevdec/qtrle.c +++ /dev/null @@ -1,1040 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * QT RLE Decoder by Mike Melanson (melanson@pcisys.net) - * For more information on the QT RLE format, visit: - * http://www.pcisys.net/~melanson/codecs/ - * - * $Id: qtrle.c,v 1.20 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "xineutils.h" -#include "bswap.h" - -#define VIDEOBUFSIZE 128*1024 - -typedef struct { - video_decoder_class_t decoder_class; -} qtrle_class_t; - -typedef struct qtrle_decoder_s { - video_decoder_t video_decoder; /* parent video decoder structure */ - - qtrle_class_t *class; - xine_stream_t *stream; - - /* these are traditional variables in a video decoder object */ - uint64_t video_step; /* frame duration in pts units */ - int decoder_ok; /* current decoder status */ - int skipframes; - - unsigned char *buf; /* the accumulated buffer data */ - int bufsize; /* the maximum size of buf */ - int size; /* the current size of buf */ - - int width; /* the width of a video frame */ - int height; /* the height of a video frame */ - double ratio; /* the width to height ratio */ - int depth; /* color depth (bits/pixel) */ - - unsigned char yuv_palette[256 * 4]; - yuv_planes_t yuv_planes; - -} qtrle_decoder_t; - -/************************************************************************** - * QT RLE specific decode functions - *************************************************************************/ - -/* monochrome color definitions */ -#define Y_BLACK COMPUTE_Y(0x00, 0x00, 0x00) -#define U_BLACK COMPUTE_U(0x00, 0x00, 0x00) -#define V_BLACK COMPUTE_V(0x00, 0x00, 0x00) -#define Y_WHITE COMPUTE_Y(0xFF, 0xFF, 0xFF) -#define U_WHITE COMPUTE_U(0xFF, 0xFF, 0xFF) -#define V_WHITE COMPUTE_V(0xFF, 0xFF, 0xFF) - -#define CHECK_STREAM_PTR(n) \ - if ((stream_ptr + n) > this->size) { \ - printf ("QT RLE problem: stream_ptr out of bounds (%d >= %d)\n", \ - stream_ptr + n, this->size); \ - return; \ - } - -#define CHECK_PIXEL_PTR(n) \ - if (pixel_ptr + n > pixel_limit) { \ - printf ("QT RLE problem: pixel_ptr >= pixel_limit (%d >= %d)\n", \ - pixel_ptr + n, pixel_limit); \ - return; \ - } \ - -static void decode_qtrle_1(qtrle_decoder_t *this) { - - int stream_ptr; - int header; - int start_line; - int lines_to_change; - signed char rle_code; - unsigned char skip_code; - int row_ptr, pixel_ptr; - int row_inc = this->width; - unsigned char y[16], u[16], v[16]; - yuv_planes_t *yuv = &this->yuv_planes; - int i, flags, flag_mask; - int pixel_limit = this->width * this->height; - - /* check if this frame is even supposed to change */ - if (this->size < 8) - return; - - /* start after the chunk size */ - stream_ptr = 4; - - /* fetch the header */ - CHECK_STREAM_PTR(2); - header = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - - /* if a header is present, fetch additional decoding parameters */ - if (header & 0x0008) { - CHECK_STREAM_PTR(8); - start_line = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - lines_to_change = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - } else { - start_line = 0; - lines_to_change = this->height; - } - - row_ptr = row_inc * start_line; - pixel_ptr = row_ptr; - while (lines_to_change) { - - CHECK_STREAM_PTR(2); - skip_code = this->buf[stream_ptr++]; - rle_code = this->buf[stream_ptr++]; - - /* check if decode is finished */ - if (rle_code == 0) - return; - if ((skip_code == 0x80) && (rle_code == 0x00)) - return; - - /* check if it is time to move to the next line */ - if ((skip_code == 0x80) && (rle_code == -1)) { - row_ptr += row_inc; - pixel_ptr = row_ptr; - lines_to_change--; - } else { - - if (skip_code >= 0x80) { - /* skip to the next line and then skip more pixels */ - row_ptr += row_inc; - pixel_ptr = row_ptr + ((skip_code & 0x7F) * 16); - lines_to_change--; - } else - /* skip pixels on the current line */ - pixel_ptr += (skip_code * 16); - - if (rle_code < 0) { - /* decode the run length code */ - rle_code = -rle_code; - - /* get the next 16 bits from the stream and treat them as 16 - * monochrome pixels */ - CHECK_STREAM_PTR(2); - flags = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - for (i = 0, flag_mask = 0x8000; i < 16; i++, flag_mask >>= 1) { - if (flags & flag_mask) { - y[i] = Y_WHITE; - u[i] = U_WHITE; - v[i] = V_WHITE; - } else { - y[i] = Y_BLACK; - u[i] = U_BLACK; - v[i] = V_BLACK; - } - } - CHECK_PIXEL_PTR(rle_code * 16); - while (rle_code--) { - for (i = 0; i < 16; i++) { - yuv->y[pixel_ptr] = y[i]; - yuv->u[pixel_ptr] = u[i]; - yuv->v[pixel_ptr] = v[i]; - pixel_ptr++; - } - } - } else { - /* copy pixels directly to output */ - CHECK_STREAM_PTR(rle_code * 2); - CHECK_PIXEL_PTR(rle_code * 16); - while (rle_code--) { - flags = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - for (i = 0, flag_mask = 0x8000; i < 16; i++, flag_mask >>= 1) { - if (flags & flag_mask) { - yuv->y[pixel_ptr] = Y_WHITE; - yuv->u[pixel_ptr] = U_WHITE; - yuv->v[pixel_ptr] = V_WHITE; - } else { - yuv->y[pixel_ptr] = Y_BLACK; - yuv->u[pixel_ptr] = U_BLACK; - yuv->v[pixel_ptr] = V_BLACK; - } - pixel_ptr++; - } - } - } - } - } -} - -static void decode_qtrle_2(qtrle_decoder_t *this) { - - int stream_ptr; - int header; - int start_line; - int lines_to_change; - signed char rle_code; - unsigned char skip_code; - int row_ptr, pixel_ptr; - int row_inc = this->width; - unsigned char y[16], u[16], v[16]; - yuv_planes_t *yuv = &this->yuv_planes; - int i, shift, index, indices; - int start_of_line = 1; - int pixel_limit = this->width * this->height; - - /* check if this frame is even supposed to change */ - if (this->size < 8) - return; - - /* start after the chunk size */ - stream_ptr = 4; - - /* fetch the header */ - CHECK_STREAM_PTR(2); - header = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - - /* if a header is present, fetch additional decoding parameters */ - if (header & 0x0008) { - CHECK_STREAM_PTR(8); - start_line = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - lines_to_change = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - } else { - start_line = 0; - lines_to_change = this->height; - } - - row_ptr = row_inc * start_line; - pixel_ptr = row_ptr; - while (lines_to_change) { - if (start_of_line) { - CHECK_STREAM_PTR(stream_ptr); - skip_code = this->buf[stream_ptr++]; - if (skip_code == 0) - return; - skip_code--; - start_of_line = 0; - } else - skip_code = 0; - - CHECK_STREAM_PTR(skip_code); - rle_code = this->buf[stream_ptr++]; - - if (rle_code == 0) - return; - else if (rle_code == -1) { - /* reset to the start of next line */ - row_ptr += row_inc; - pixel_ptr = row_ptr; - start_of_line = 1; - lines_to_change--; - } else { - if (skip_code & 0x80) { - /* reset to the start of the next line and skip pixels */ - row_ptr += row_inc; - pixel_ptr = row_ptr + (skip_code & 0x7F); - lines_to_change--; - } else { - /* skip pixels on current line */ - pixel_ptr += skip_code; - } - - if (rle_code < 0) { - /* decode the run length code */ - rle_code = -rle_code; - - /* get the next 32 bits from the stream and treat them as 16 - * 2-bit indices into the palette */ - CHECK_STREAM_PTR(4); - indices = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - for (i = 0, shift = 30; i < 16; i++, shift -= 2) { - index = (indices >> shift) & 0x03; - y[i] = this->yuv_palette[index * 4 + 0]; - u[i] = this->yuv_palette[index * 4 + 1]; - v[i] = this->yuv_palette[index * 4 + 2]; - } - CHECK_PIXEL_PTR(rle_code * 16); - while (rle_code--) { - for (i = 0; i < 16; i++) { - yuv->y[pixel_ptr] = y[i]; - yuv->u[pixel_ptr] = u[i]; - yuv->v[pixel_ptr] = v[i]; - pixel_ptr++; - } - } - } else { - /* copy pixels directly to output */ - CHECK_STREAM_PTR(rle_code * 4); - CHECK_PIXEL_PTR(rle_code * 16); - while (rle_code--) { - indices = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - for (i = 0, shift = 30; i < 16; i++, shift -= 2) { - index = (indices >> shift) & 0x03; - yuv->y[pixel_ptr] = this->yuv_palette[index * 4 + 0]; - yuv->u[pixel_ptr] = this->yuv_palette[index * 4 + 1]; - yuv->v[pixel_ptr] = this->yuv_palette[index * 4 + 2]; - pixel_ptr++; - } - } - } - } - - row_ptr += row_inc; - } -} - -static void decode_qtrle_4(qtrle_decoder_t *this) { - - int stream_ptr; - int header; - int start_line; - int lines_to_change; - signed char rle_code; - int row_ptr, pixel_ptr; - int row_inc = this->width; - unsigned char y[8], u[8], v[8]; - yuv_planes_t *yuv = &this->yuv_planes; - int i, shift, index, indices; - int pixel_limit = this->width * this->height; - - /* check if this frame is even supposed to change */ - if (this->size < 8) - return; - - /* start after the chunk size */ - stream_ptr = 4; - - /* fetch the header */ - CHECK_STREAM_PTR(2); - header = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - - /* if a header is present, fetch additional decoding parameters */ - if (header & 0x0008) { - CHECK_STREAM_PTR(8); - start_line = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - lines_to_change = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - } else { - start_line = 0; - lines_to_change = this->height; - } - - row_ptr = row_inc * start_line; - while (lines_to_change--) { - CHECK_STREAM_PTR(2); - pixel_ptr = row_ptr + (this->buf[stream_ptr++] - 1); - - while ((rle_code = (signed char)this->buf[stream_ptr++]) != -1) { - if (rle_code == 0) { - /* there's another skip code in the stream */ - CHECK_STREAM_PTR(1); - pixel_ptr += (this->buf[stream_ptr++] - 1); - } else if (rle_code < 0) { - /* decode the run length code */ - rle_code = -rle_code; - - /* get the next 32 bits from the stream and treat them as 8 - * 4-bit indices into the palette */ - CHECK_STREAM_PTR(4); - indices = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - for (i = 0, shift = 28; i < 8; i++, shift -= 4) { - index = (indices >> shift) & 0x0F; - y[i] = this->yuv_palette[index * 4 + 0]; - u[i] = this->yuv_palette[index * 4 + 1]; - v[i] = this->yuv_palette[index * 4 + 2]; - } - CHECK_PIXEL_PTR(rle_code * 8); - while (rle_code--) { - for (i = 0; i < 8; i++) { - yuv->y[pixel_ptr] = y[i]; - yuv->u[pixel_ptr] = u[i]; - yuv->v[pixel_ptr] = v[i]; - pixel_ptr++; - } - } - } else { - /* copy pixels directly to output */ - CHECK_STREAM_PTR(rle_code * 4); - CHECK_PIXEL_PTR(rle_code * 8); - while (rle_code--) { - indices = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - for (i = 0, shift = 28; i < 8; i++, shift -= 4) { - index = (indices >> shift) & 0x0F; - yuv->y[pixel_ptr] = this->yuv_palette[index * 4 + 0]; - yuv->u[pixel_ptr] = this->yuv_palette[index * 4 + 1]; - yuv->v[pixel_ptr] = this->yuv_palette[index * 4 + 2]; - pixel_ptr++; - } - } - } - } - - row_ptr += row_inc; - } -} - -static void decode_qtrle_8(qtrle_decoder_t *this) { - - int stream_ptr; - int header; - int start_line; - int lines_to_change; - signed char rle_code; - int row_ptr, pixel_ptr; - int row_inc = this->width; - unsigned char y[4], u[4], v[4]; - yuv_planes_t *yuv = &this->yuv_planes; - int i; - int pixel_limit = this->width * this->height; - - /* check if this frame is even supposed to change */ - if (this->size < 8) - return; - - /* start after the chunk size */ - stream_ptr = 4; - - /* fetch the header */ - CHECK_STREAM_PTR(2); - header = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - - /* if a header is present, fetch additional decoding parameters */ - if (header & 0x0008) { - CHECK_STREAM_PTR(8); - start_line = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - lines_to_change = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - } else { - start_line = 0; - lines_to_change = this->height; - } - - row_ptr = row_inc * start_line; - while (lines_to_change--) { - CHECK_STREAM_PTR(2); - pixel_ptr = row_ptr + (4 * (this->buf[stream_ptr++] - 1)); - - while ((rle_code = (signed char)this->buf[stream_ptr++]) != -1) { - if (rle_code == 0) { - /* there's another skip code in the stream */ - pixel_ptr += (4 * (this->buf[stream_ptr++] - 1)); - CHECK_STREAM_PTR(1); - } else if (rle_code < 0) { - /* decode the run length code */ - rle_code = -rle_code; - /* get the next 4 bytes from the stream, treat them as palette - * indices, and output them to the rle_code times */ - CHECK_STREAM_PTR(4); - for (i = 0; i < 4; i++) { - y[i] = this->yuv_palette[this->buf[stream_ptr] * 4 + 0]; - u[i] = this->yuv_palette[this->buf[stream_ptr] * 4 + 1]; - v[i] = this->yuv_palette[this->buf[stream_ptr] * 4 + 2]; - stream_ptr++; - } - CHECK_PIXEL_PTR(rle_code * 4); - while (rle_code--) { - for (i = 0; i < 4; i++) { - yuv->y[pixel_ptr] = y[i]; - yuv->u[pixel_ptr] = u[i]; - yuv->v[pixel_ptr] = v[i]; - pixel_ptr++; - } - } - } else { - CHECK_STREAM_PTR(rle_code); - CHECK_PIXEL_PTR(rle_code); - - /* copy pixels directly to output */ - while (rle_code--) { - for (i = 0; i < 4; i++) { - yuv->y[pixel_ptr] = - this->yuv_palette[this->buf[stream_ptr] * 4 + 0]; - yuv->u[pixel_ptr] = - this->yuv_palette[this->buf[stream_ptr] * 4 + 1]; - yuv->v[pixel_ptr] = - this->yuv_palette[this->buf[stream_ptr] * 4 + 2]; - stream_ptr++; - pixel_ptr++; - } - } - } - } - - row_ptr += row_inc; - } -} - -static void decode_qtrle_16(qtrle_decoder_t *this) { - - int stream_ptr; - int header; - int start_line; - int lines_to_change; - signed char rle_code; - int row_ptr, pixel_ptr; - int row_inc = this->width; - unsigned char r, g, b; - unsigned char y, u, v; - unsigned short packed_pixel; - yuv_planes_t *yuv = &this->yuv_planes; - int pixel_limit = this->width * this->height; - - /* check if this frame is even supposed to change */ - if (this->size < 8) - return; - - /* start after the chunk size */ - stream_ptr = 4; - - /* fetch the header */ - CHECK_STREAM_PTR(2); - header = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - - /* if a header is present, fetch additional decoding parameters */ - if (header & 0x0008) { - CHECK_STREAM_PTR(8); - start_line = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - lines_to_change = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - } else { - start_line = 0; - lines_to_change = this->height; - } - - row_ptr = row_inc * start_line; - while (lines_to_change--) { - CHECK_STREAM_PTR(2); - pixel_ptr = row_ptr + (this->buf[stream_ptr++] - 1); - - while ((rle_code = (signed char)this->buf[stream_ptr++]) != -1) { - if (rle_code == 0) { - /* there's another skip code in the stream */ - CHECK_STREAM_PTR(1); - pixel_ptr += (this->buf[stream_ptr++] - 1); - } - else if (rle_code < 0) { - /* decode the run length code */ - rle_code = -rle_code; - CHECK_STREAM_PTR(2); - packed_pixel = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - UNPACK_RGB15(packed_pixel, r, g, b); - y = COMPUTE_Y(r, g, b); - u = COMPUTE_U(r, g, b); - v = COMPUTE_V(r, g, b); - - CHECK_PIXEL_PTR(rle_code); - - while (rle_code--) { - yuv->y[pixel_ptr] = y; - yuv->u[pixel_ptr] = u; - yuv->v[pixel_ptr] = v; - pixel_ptr++; - } - } else { - CHECK_PIXEL_PTR(rle_code); - CHECK_STREAM_PTR(rle_code * 2); - - /* copy pixels directly to output */ - while (rle_code--) { - packed_pixel = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - UNPACK_RGB15(packed_pixel, r, g, b); - y = COMPUTE_Y(r, g, b); - u = COMPUTE_U(r, g, b); - v = COMPUTE_V(r, g, b); - yuv->y[pixel_ptr] = y; - yuv->u[pixel_ptr] = u; - yuv->v[pixel_ptr] = v; - pixel_ptr++; - } - } - } - - row_ptr += row_inc; - } -} - -static void decode_qtrle_24(qtrle_decoder_t *this) { - - int stream_ptr; - int header; - int start_line; - int lines_to_change; - signed char rle_code; - int row_ptr, pixel_ptr; - int row_inc = this->width; - unsigned char r, g, b; - unsigned char y, u, v; - yuv_planes_t *yuv = &this->yuv_planes; - int pixel_limit = this->width * this->height; - - /* check if this frame is even supposed to change */ - if (this->size < 8) - return; - - /* start after the chunk size */ - stream_ptr = 4; - - /* fetch the header */ - CHECK_STREAM_PTR(2); - header = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - - /* if a header is present, fetch additional decoding parameters */ - if (header & 0x0008) { - CHECK_STREAM_PTR(8); - start_line = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - lines_to_change = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - } else { - start_line = 0; - lines_to_change = this->height; - } - - row_ptr = row_inc * start_line; - while (lines_to_change--) { - CHECK_STREAM_PTR(2); - pixel_ptr = row_ptr + (this->buf[stream_ptr++] - 1); - - while ((rle_code = (signed char)this->buf[stream_ptr++]) != -1) { - if (rle_code == 0) { - /* there's another skip code in the stream */ - CHECK_STREAM_PTR(1); - pixel_ptr += (this->buf[stream_ptr++] - 1); - } else if (rle_code < 0) { - /* decode the run length code */ - rle_code = -rle_code; - CHECK_STREAM_PTR(3); - r = this->buf[stream_ptr++]; - g = this->buf[stream_ptr++]; - b = this->buf[stream_ptr++]; - y = COMPUTE_Y(r, g, b); - u = COMPUTE_U(r, g, b); - v = COMPUTE_V(r, g, b); - - CHECK_PIXEL_PTR(rle_code); - - while (rle_code--) { - yuv->y[pixel_ptr] = y; - yuv->u[pixel_ptr] = u; - yuv->v[pixel_ptr] = v; - pixel_ptr++; - } - } else { - CHECK_PIXEL_PTR(rle_code); - CHECK_STREAM_PTR(rle_code * 3); - - /* copy pixels directly to output */ - while (rle_code--) { - r = this->buf[stream_ptr++]; - g = this->buf[stream_ptr++]; - b = this->buf[stream_ptr++]; - y = COMPUTE_Y(r, g, b); - u = COMPUTE_U(r, g, b); - v = COMPUTE_V(r, g, b); - yuv->y[pixel_ptr] = y; - yuv->u[pixel_ptr] = u; - yuv->v[pixel_ptr] = v; - pixel_ptr++; - } - } - } - - row_ptr += row_inc; - } -} - -static void decode_qtrle_32(qtrle_decoder_t *this) { - - int stream_ptr; - int header; - int start_line; - int lines_to_change; - signed char rle_code; - int row_ptr, pixel_ptr; - int row_inc = this->width; - unsigned char r, g, b; - unsigned char y, u, v; - yuv_planes_t *yuv = &this->yuv_planes; - int pixel_limit = this->width * this->height; - - /* check if this frame is even supposed to change */ - if (this->size < 8) - return; - - /* start after the chunk size */ - stream_ptr = 4; - - /* fetch the header */ - CHECK_STREAM_PTR(2); - header = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - - /* if a header is present, fetch additional decoding parameters */ - if (header & 0x0008) { - CHECK_STREAM_PTR(8); - start_line = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - lines_to_change = BE_16(&this->buf[stream_ptr]); - stream_ptr += 4; - } else { - start_line = 0; - lines_to_change = this->height; - } - - row_ptr = row_inc * start_line; - while (lines_to_change--) { - CHECK_STREAM_PTR(2); - pixel_ptr = row_ptr + (this->buf[stream_ptr++] - 1); - - while ((rle_code = (signed char)this->buf[stream_ptr++]) != -1) { - if (rle_code == 0) { - /* there's another skip code in the stream */ - CHECK_STREAM_PTR(1); - pixel_ptr += (this->buf[stream_ptr++] - 1); - } else if (rle_code < 0) { - /* decode the run length code */ - rle_code = -rle_code; - CHECK_STREAM_PTR(4); - stream_ptr++; /* skip alpha transparency (?) byte */ - r = this->buf[stream_ptr++]; - g = this->buf[stream_ptr++]; - b = this->buf[stream_ptr++]; - y = COMPUTE_Y(r, g, b); - u = COMPUTE_U(r, g, b); - v = COMPUTE_V(r, g, b); - - CHECK_PIXEL_PTR(rle_code); - - while (rle_code--) { - yuv->y[pixel_ptr] = y; - yuv->u[pixel_ptr] = u; - yuv->v[pixel_ptr] = v; - pixel_ptr++; - } - } else { - CHECK_PIXEL_PTR(rle_code); - CHECK_STREAM_PTR(rle_code * 4); - - /* copy pixels directly to output */ - while (rle_code--) { - stream_ptr++; /* skip alpha transparency (?) byte */ - r = this->buf[stream_ptr++]; - g = this->buf[stream_ptr++]; - b = this->buf[stream_ptr++]; - y = COMPUTE_Y(r, g, b); - u = COMPUTE_U(r, g, b); - v = COMPUTE_V(r, g, b); - yuv->y[pixel_ptr] = y; - yuv->u[pixel_ptr] = u; - yuv->v[pixel_ptr] = v; - pixel_ptr++; - } - } - } - - row_ptr += row_inc; - } -} - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -/* - * This function receives a buffer of data from the demuxer layer and - * figures out how to handle it based on its header flags. - */ -static void qtrle_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - qtrle_decoder_t *this = (qtrle_decoder_t *) this_gen; - xine_bmiheader *bih; - palette_entry_t *palette; - int i; - char codec_name[100]; - - vo_frame_t *img; /* video out frame */ - - /* a video decoder does not care about this flag (?) */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { - palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - for (i = 0; i < buf->decoder_info[2]; i++) { - this->yuv_palette[i * 4 + 0] = - COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 1] = - COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 2] = - COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */ - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - bih = (xine_bmiheader *) buf->content; - this->width = bih->biWidth; - this->height = bih->biHeight; - this->ratio = (double)this->width/(double)this->height; - this->depth = bih->biBitCount; - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - init_yuv_planes(&this->yuv_planes, this->width, this->height); - - this->decoder_ok = 1; - - /* load the stream/meta info */ - sprintf(codec_name, "%d bpp Quicktime Animation (RLE)", this->depth & 0x1F); - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, codec_name); - - return; - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, - XINE_IMGFMT_YUY2, VO_BOTH_FIELDS); - - switch (this->depth & 0x1F) { - - case 1: - decode_qtrle_1(this); - break; - - case 2: - decode_qtrle_2(this); - break; - - case 4: - decode_qtrle_4(this); - break; - - case 8: - decode_qtrle_8(this); - break; - - case 16: - decode_qtrle_16(this); - break; - - case 24: - decode_qtrle_24(this); - break; - - case 32: - decode_qtrle_32(this); - break; - - } - - yuv444_to_yuy2(&this->yuv_planes, img->base[0], img->pitches[0]); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = 0; - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -/* - * This function is called when xine needs to flush the system. Not - * sure when or if this is used or even if it needs to do anything. - */ -static void qtrle_flush (video_decoder_t *this_gen) { -} - -/* - * This function resets the video decoder. - */ -static void qtrle_reset (video_decoder_t *this_gen) { - qtrle_decoder_t *this = (qtrle_decoder_t *) this_gen; - - this->size = 0; -} - -static void qtrle_discontinuity (video_decoder_t *this_gen) { -} - -/* - * This function frees the video decoder instance allocated to the decoder. - */ -static void qtrle_dispose (video_decoder_t *this_gen) { - - qtrle_decoder_t *this = (qtrle_decoder_t *) this_gen; - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - qtrle_decoder_t *this ; - - this = (qtrle_decoder_t *) xine_xmalloc (sizeof (qtrle_decoder_t)); - - this->video_decoder.decode_data = qtrle_decode_data; - this->video_decoder.flush = qtrle_flush; - this->video_decoder.reset = qtrle_reset; - this->video_decoder.discontinuity = qtrle_discontinuity; - this->video_decoder.dispose = qtrle_dispose; - this->size = 0; - - this->stream = stream; - this->class = (qtrle_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "QT RLE"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Quicktime Animation (RLE) video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - qtrle_class_t *this; - - this = (qtrle_class_t *) xine_xmalloc (sizeof (qtrle_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ -static uint32_t video_types[] = { - BUF_VIDEO_QTRLE, - 0 -}; - -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 5 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "qtrle", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/qtrpza.c b/src/libxinevdec/qtrpza.c deleted file mode 100644 index f27593f5e..000000000 --- a/src/libxinevdec/qtrpza.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * QT RPZA Video Decoder by Roberto Togni <rtogni@bresciaonline.it> - * For more information about the RPZA format, visit: - * http://www.pcisys.net/~melanson/codecs/ - * - * $Id: qtrpza.c,v 1.24 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "buffer.h" -#include "xine_internal.h" -#include "video_out.h" -#include "xineutils.h" -#include "bswap.h" - -#define VIDEOBUFSIZE 128*1024 - -typedef struct { - video_decoder_class_t decoder_class; -} qtrpza_class_t; - -typedef struct qtrpza_decoder_s { - video_decoder_t video_decoder; /* parent video decoder structure */ - - qtrpza_class_t *class; - xine_stream_t *stream; - - /* these are traditional variables in a video decoder object */ - uint64_t video_step; /* frame duration in pts units */ - int decoder_ok; /* current decoder status */ - int skipframes; - - unsigned char *buf; /* the accumulated buffer data */ - int bufsize; /* the maximum size of buf */ - int size; /* the current size of buf */ - - int width; /* the width of a video frame */ - int height; /* the height of a video frame */ - double ratio; /* the width to height ratio */ - - yuv_planes_t yuv_planes; - -} qtrpza_decoder_t; - -/************************************************************************** - * RPZA specific decode functions - *************************************************************************/ - -#define ADVANCE_BLOCK() \ -{ \ - pixel_ptr += 4; \ - if (pixel_ptr >= this->width) \ - { \ - pixel_ptr = 0; \ - row_ptr += this->width * 4; \ - } \ - total_blocks--; \ - if (total_blocks < 0) \ - { \ - printf(_("warning: block counter just went negative (this should not happen)\n")); \ - return; \ - } \ -} - -#define COLOR_FIX(col_out, col_in) (col_out) = ((col_in) << 3) | ((col_in) >> 2) - -/* r, g, and b are defined in the function from which this is called */ -#define COLOR_TO_YUV(y_val, u_val, v_val, color) \ -{ \ - unsigned short tmp; \ - tmp = (color >> 10) & 0x1f; \ - COLOR_FIX (r, tmp); \ - tmp = (color >> 5) & 0x1f; \ - COLOR_FIX (g, tmp); \ - tmp = color & 0x1f; \ - COLOR_FIX (b, tmp); \ - y_val = COMPUTE_Y(r, g, b); \ - u_val = COMPUTE_U(r, g, b); \ - v_val = COMPUTE_V(r, g, b); \ -} - -static void decode_qtrpza(qtrpza_decoder_t *this) { - - int i; - int stream_ptr = 0; - int chunk_size; - unsigned char opcode; - int n_blocks; - unsigned short colorA = 0, colorB; - unsigned char r, g, b; - unsigned char y, u, v; - unsigned char rgb4[4][3]; - unsigned char yuv4[4][3]; - unsigned char index, idx; - - int row_ptr = 0; - int pixel_ptr = 0; - int pixel_x, pixel_y; - int row_inc = this->width - 4; - int block_ptr; - int total_blocks; - unsigned short ta, tb, tt; - - /* First byte is always 0xe1. Warn if it's different */ - if ((unsigned char)this->buf[stream_ptr] != 0xe1) - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "First chunk byte is 0x%02x instead of 0x1e\n", - (unsigned char)this->buf[stream_ptr]); - - /* Get chunk size, ingnoring first byte */ - chunk_size = BE_32(&this->buf[stream_ptr]) & 0x00FFFFFF; - stream_ptr += 4; - - /* If length mismatch use size from MOV file and try to decode anyway */ - if (chunk_size != this->size) - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "MOV chunk size != encoded chunk size; using MOV chunk size\n"); - - chunk_size = this->size; - - /* Number of 4x4 blocks in frame. */ - total_blocks = (this->width * this->height) / (4 * 4); - - /* Process chunk data */ - while (stream_ptr < chunk_size) { - opcode = this->buf[stream_ptr++]; /* Get opcode */ - - n_blocks = (opcode & 0x1f) +1; /* Extract block counter from opcode */ - - /* If opcode MSbit is 0, we need more data to decide what to do */ - if ((opcode & 0x80) == 0) { - colorA = (opcode << 8) | ((unsigned char)this->buf[stream_ptr++]); - opcode = 0; - if ((this->buf[stream_ptr] & 0x80) != 0) { - /* Must behave as opcode 110xxxxx, using colorA computed above.*/ - /* Use fake opcode 0x20 to enter switch block at the right place */ - opcode = 0x20; - n_blocks = 1; - } - } - - switch (opcode & 0xe0) { - /* Skip blocks */ - case 0x80: - while (n_blocks--) - ADVANCE_BLOCK(); - break; - - /* Fill blocks with one color */ - case 0xa0: - colorA = BE_16 (&this->buf[stream_ptr]); - stream_ptr += 2; - COLOR_TO_YUV (y, u, v, colorA); - while (n_blocks--) { - block_ptr = row_ptr + pixel_ptr; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - for (pixel_x = 0; pixel_x < 4; pixel_x++){ - this->yuv_planes.y[block_ptr] = y; - this->yuv_planes.u[block_ptr] = u; - this->yuv_planes.v[block_ptr] = v; - block_ptr++; - } - block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - /* Fill blocks with 4 colors */ - case 0xc0: - colorA = BE_16 (&this->buf[stream_ptr]); - stream_ptr += 2; - case 0x20: - colorB = BE_16 (&this->buf[stream_ptr]); - stream_ptr += 2; - - /* sort out the colors */ - ta = (colorA >> 10) & 0x1f; - tb = (colorB >> 10) & 0x1f; - COLOR_FIX (rgb4[3][0], ta); - COLOR_FIX (rgb4[0][0], tb); - tt = (11 * ta + 21 * tb) >> 5; - COLOR_FIX (rgb4[1][0], tt); - tt = (21 * ta + 11 * tb) >> 5; - COLOR_FIX (rgb4[2][0], tt); - ta = (colorA >> 5) & 0x1f; - tb = (colorB >> 5) & 0x1f; - COLOR_FIX (rgb4[3][1], ta); - COLOR_FIX (rgb4[0][1], tb); - tt = (11 * ta + 21 * tb) >> 5; - COLOR_FIX (rgb4[1][1], tt); - tt = (21 * ta + 11 * tb) >> 5; - COLOR_FIX (rgb4[2][1], tt); - ta = colorA & 0x1f; - tb = colorB & 0x1f; - COLOR_FIX (rgb4[3][2], ta); - COLOR_FIX (rgb4[0][2], tb); - tt = (11 * ta + 21 * tb) >> 5; - COLOR_FIX (rgb4[1][2], tt); - tt = (21 * ta + 11 * tb) >> 5; - COLOR_FIX (rgb4[2][2], tt); - - /* RGB -> YUV */ - for (i = 0; i < 4; i++) { - yuv4[i][0] = COMPUTE_Y(rgb4[i][0], rgb4[i][1], rgb4[i][2]); - yuv4[i][1] = COMPUTE_U(rgb4[i][0], rgb4[i][1], rgb4[i][2]); - yuv4[i][2] = COMPUTE_V(rgb4[i][0], rgb4[i][1], rgb4[i][2]); - } - - while (n_blocks--) { - block_ptr = row_ptr + pixel_ptr; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - index = this->buf[stream_ptr++]; - for (pixel_x = 0; pixel_x < 4; pixel_x++){ - idx = (index >> (2 * (3 - pixel_x))) & 0x03; - this->yuv_planes.y[block_ptr] = yuv4[idx][0]; - this->yuv_planes.u[block_ptr] = yuv4[idx][1]; - this->yuv_planes.v[block_ptr] = yuv4[idx][2]; - block_ptr++; - } - block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - /* Fill block with 16 colors */ - case 0x00: - block_ptr = row_ptr + pixel_ptr; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - for (pixel_x = 0; pixel_x < 4; pixel_x++){ - /* We already have color of upper left pixel */ - if ((pixel_y != 0) || (pixel_x !=0)) { - colorA = BE_16 (&this->buf[stream_ptr]); - stream_ptr += 2; - } - COLOR_TO_YUV (y, u, v, colorA); - this->yuv_planes.y[block_ptr] = y; - this->yuv_planes.u[block_ptr] = u; - this->yuv_planes.v[block_ptr] = v; - block_ptr++; - } - block_ptr += row_inc; - } - ADVANCE_BLOCK(); - break; - - /* Unknown opcode */ - default: - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "Unknown opcode %d in rpza chunk.Skip remaining %d bytes of chunk data.\n", - opcode, chunk_size - stream_ptr); - return; - } /* Opcode switch */ - - } -} - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -/* - * This function receives a buffer of data from the demuxer layer and - * figures out how to handle it based on its header flags. - */ -static void qtrpza_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - qtrpza_decoder_t *this = (qtrpza_decoder_t *) this_gen; - xine_bmiheader *bih; - - vo_frame_t *img; /* video out frame */ - - /* a video decoder does not care about this flag (?) */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */ - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - bih = (xine_bmiheader *) buf->content; - this->width = (bih->biWidth + 3) & ~0x03; - this->height = (bih->biHeight + 3) & ~0x03; - this->ratio = (double)this->width/(double)this->height; - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - init_yuv_planes(&this->yuv_planes, this->width, this->height); - - this->stream->video_out->open (this->stream->video_out, this->stream); - this->decoder_ok = 1; - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Quicktime Video (RPZA)"); - - return; - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, XINE_IMGFMT_YUY2, - VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = 0; - - decode_qtrpza(this); - yuv444_to_yuy2(&this->yuv_planes, img->base[0], img->pitches[0]); - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -/* - * This function is called when xine needs to flush the system. Not - * sure when or if this is used or even if it needs to do anything. - */ -static void qtrpza_flush (video_decoder_t *this_gen) { -} - -/* - * This function resets the video decoder. - */ -static void qtrpza_reset (video_decoder_t *this_gen) { - qtrpza_decoder_t *this = (qtrpza_decoder_t *) this_gen; - - this->size = 0; -} - -static void qtrpza_discontinuity (video_decoder_t *this_gen) { -} - -/* - * This function frees the video decoder instance allocated to the decoder. - */ -static void qtrpza_dispose (video_decoder_t *this_gen) { - - qtrpza_decoder_t *this = (qtrpza_decoder_t *) this_gen; - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - qtrpza_decoder_t *this ; - - this = (qtrpza_decoder_t *) xine_xmalloc (sizeof (qtrpza_decoder_t)); - - this->video_decoder.decode_data = qtrpza_decode_data; - this->video_decoder.flush = qtrpza_flush; - this->video_decoder.reset = qtrpza_reset; - this->video_decoder.discontinuity = qtrpza_discontinuity; - this->video_decoder.dispose = qtrpza_dispose; - this->size = 0; - - this->stream = stream; - this->class = (qtrpza_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "QT RPZA"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Quicktime Video (RPZA) decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - qtrpza_class_t *this; - - this = (qtrpza_class_t *) xine_xmalloc (sizeof (qtrpza_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_VIDEO_RPZA, 0 }; - -static decoder_info_t video_decoder_info = { - supported_types, /* supported types */ - 1 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "rpza", XINE_VERSION_CODE, &video_decoder_info, &init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/qtsmc.c b/src/libxinevdec/qtsmc.c deleted file mode 100644 index 1230062e0..000000000 --- a/src/libxinevdec/qtsmc.c +++ /dev/null @@ -1,698 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Apple Graphics (SMC) Decoder by Mike Melanson (melanson@pcisys.net) - * Special thanks to Roberto Togni <rtogni@bresciaonline.it> for tracking - * down the final, nagging bugs. - * For more information on the SMC format, visit: - * http://www.pcisys.net/~melanson/codecs/ - * - * $Id: qtsmc.c,v 1.24 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "buffer.h" -#include "xine_internal.h" -#include "video_out.h" -#include "xineutils.h" -#include "bswap.h" - -#define VIDEOBUFSIZE 128*1024 - -#define COLORS_PER_TABLE 256 -#define BYTES_PER_COLOR 4 - -#define CPAIR 2 -#define CQUAD 4 -#define COCTET 8 - -typedef struct { - video_decoder_class_t decoder_class; -} qtsmc_class_t; - -typedef struct qtsmc_decoder_s { - video_decoder_t video_decoder; /* parent video decoder structure */ - - qtsmc_class_t *class; - xine_stream_t *stream; - - /* these are traditional variables in a video decoder object */ - uint64_t video_step; /* frame duration in pts units */ - int decoder_ok; /* current decoder status */ - int skipframes; - - unsigned char *buf; /* the accumulated buffer data */ - int bufsize; /* the maximum size of buf */ - int size; /* the current size of buf */ - - int width; /* the width of a video frame */ - int height; /* the height of a video frame */ - double ratio; /* the width to height ratio */ - - /* SMC color tables */ - unsigned char color_pairs[COLORS_PER_TABLE * BYTES_PER_COLOR * CPAIR]; - unsigned char color_quads[COLORS_PER_TABLE * BYTES_PER_COLOR * CQUAD]; - unsigned char color_octets[COLORS_PER_TABLE * BYTES_PER_COLOR * COCTET]; - - unsigned char yuv_palette[256 * 4]; - yuv_planes_t yuv_planes; - -} qtsmc_decoder_t; - -/************************************************************************** - * SMC specific decode functions - *************************************************************************/ - -#define GET_BLOCK_COUNT \ - (opcode & 0x10) ? (1 + this->buf[stream_ptr++]) : 1 + (opcode & 0x0F); -#define ADVANCE_BLOCK() \ -{ \ - pixel_ptr += 4; \ - if (pixel_ptr >= this->width) \ - { \ - pixel_ptr = 0; \ - row_ptr += this->width * 4; \ - } \ - total_blocks--; \ - if (total_blocks < 0) \ - { \ - printf(_("warning: block counter just went negative (this should not happen)\n")); \ - return; \ - } \ -} - -static void decode_qtsmc(qtsmc_decoder_t *this) { - - int i; - int stream_ptr = 0; - int chunk_size; - unsigned char opcode; - int n_blocks; - unsigned int color_flags; - unsigned int color_flags_a; - unsigned int color_flags_b; - unsigned int flag_mask; - - yuv_planes_t *yuv = &this->yuv_planes; - - int image_size = this->height * this->width; - int row_ptr = 0; - int pixel_ptr = 0; - int pixel_x, pixel_y; - int row_inc = this->width - 4; - int block_ptr; - int prev_block_ptr; - int prev_block_ptr1, prev_block_ptr2; - int prev_block_flag; - int total_blocks; - int color_table_index; /* indexes to color pair, quad, or octet tables */ - int color_index; /* indexes into palette map */ - - int color_pair_index = 0; - int color_quad_index = 0; - int color_octet_index = 0; - - chunk_size = BE_32(&this->buf[stream_ptr]) & 0x00FFFFFF; - stream_ptr += 4; - if (chunk_size != this->size) - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n", - chunk_size, this->size); - - chunk_size = this->size; - total_blocks = (this->width * this->height) / (4 * 4); - - /* traverse through the blocks */ - while (total_blocks) { - /* sanity checks */ - /* make sure stream ptr hasn't gone out of bounds */ - if (stream_ptr > chunk_size) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "SMC decoder just went out of bounds (stream ptr = %d, chunk size = %d)\n", - stream_ptr, chunk_size); - return; - } - /* make sure the row pointer hasn't gone wild */ - if (row_ptr >= image_size) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "SMC decoder just went out of bounds (row ptr = %d, height = %d)\n", - row_ptr, image_size); - return; - } - - opcode = this->buf[stream_ptr++]; - switch (opcode & 0xF0) { - /* skip n blocks */ - case 0x00: - case 0x10: - n_blocks = GET_BLOCK_COUNT; - while (n_blocks--) - ADVANCE_BLOCK(); - break; - - /* repeat last block n times */ - case 0x20: - case 0x30: - n_blocks = GET_BLOCK_COUNT; - - /* sanity check */ - if ((row_ptr == 0) && (pixel_ptr == 0)) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "encountered repeat block opcode (%02X) but no blocks rendered yet\n", - opcode & 0xF0); - break; - } - - /* figure out where the previous block started */ - if (pixel_ptr == 0) - prev_block_ptr1 = (row_ptr - this->width * 4) + this->width - 4; - else - prev_block_ptr1 = row_ptr + pixel_ptr - 4; - - while (n_blocks--) { - block_ptr = row_ptr + pixel_ptr; - prev_block_ptr = prev_block_ptr1; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - for (pixel_x = 0; pixel_x < 4; pixel_x++) { - yuv->y[block_ptr] = yuv->y[prev_block_ptr]; - yuv->u[block_ptr] = yuv->u[prev_block_ptr]; - yuv->v[block_ptr] = yuv->v[prev_block_ptr]; - block_ptr++; - prev_block_ptr++; - } - block_ptr += row_inc; - prev_block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - /* repeat previous pair of blocks n times */ - case 0x40: - case 0x50: - n_blocks = GET_BLOCK_COUNT; - n_blocks *= 2; - - /* sanity check */ - if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "encountered repeat block opcode (%02X) but not enough blocks rendered yet\n", - opcode & 0xF0); - break; - } - - /* figure out where the previous 2 blocks started */ - if (pixel_ptr == 0) - prev_block_ptr1 = (row_ptr - this->width * 4) + - this->width - 4 * 2; - else if (pixel_ptr == 4) - prev_block_ptr1 = (row_ptr - this->width * 4) + row_inc; - else - prev_block_ptr1 = row_ptr + pixel_ptr - 4 * 2; - - if (pixel_ptr == 0) - prev_block_ptr2 = (row_ptr - this->width * 4) + row_inc; - else - prev_block_ptr2 = row_ptr + pixel_ptr - 4; - - prev_block_flag = 0; - while (n_blocks--) { - block_ptr = row_ptr + pixel_ptr; - if (prev_block_flag) - prev_block_ptr = prev_block_ptr2; - else - prev_block_ptr = prev_block_ptr1; - prev_block_flag = !prev_block_flag; - - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - for (pixel_x = 0; pixel_x < 4; pixel_x++) { - yuv->y[block_ptr] = yuv->y[prev_block_ptr]; - yuv->u[block_ptr] = yuv->u[prev_block_ptr]; - yuv->v[block_ptr] = yuv->v[prev_block_ptr]; - block_ptr++; - prev_block_ptr++; - } - block_ptr += row_inc; - prev_block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - /* 1-color block encoding */ - case 0x60: - case 0x70: - n_blocks = GET_BLOCK_COUNT; - color_index = this->buf[stream_ptr++] * 4; - - while (n_blocks--) { - block_ptr = row_ptr + pixel_ptr; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - for (pixel_x = 0; pixel_x < 4; pixel_x++) { - yuv->y[block_ptr] = this->yuv_palette[color_index + 0]; - yuv->u[block_ptr] = this->yuv_palette[color_index + 1]; - yuv->v[block_ptr] = this->yuv_palette[color_index + 2]; - block_ptr++; - } - block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - /* 2-color block encoding */ - case 0x80: - case 0x90: - n_blocks = (opcode & 0x0F) + 1; - - /* figure out which color pair to use to paint the 2-color block */ - if ((opcode & 0xF0) == 0x80) { - /* fetch the next 2 colors from bytestream and store in next - * available entry in the color pair table */ - for (i = 0; i < CPAIR; i++) { - color_index = this->buf[stream_ptr++] * BYTES_PER_COLOR; - color_table_index = CPAIR * BYTES_PER_COLOR * color_pair_index + - (i * BYTES_PER_COLOR); - this->color_pairs[color_table_index + 0] = - this->yuv_palette[color_index + 0]; - this->color_pairs[color_table_index + 1] = - this->yuv_palette[color_index + 1]; - this->color_pairs[color_table_index + 2] = - this->yuv_palette[color_index + 2]; - } - /* this is the base index to use for this block */ - color_table_index = CPAIR * BYTES_PER_COLOR * color_pair_index; - color_pair_index++; - /* wraparound */ - if (color_pair_index == COLORS_PER_TABLE) - color_pair_index = 0; - } - else - color_table_index = CPAIR * BYTES_PER_COLOR * this->buf[stream_ptr++]; - - while (n_blocks--) { - color_flags = BE_16(&this->buf[stream_ptr]); - stream_ptr += 2; - flag_mask = 0x8000; - block_ptr = row_ptr + pixel_ptr; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - for (pixel_x = 0; pixel_x < 4; pixel_x++) { - if (color_flags & flag_mask) - color_index = color_table_index + BYTES_PER_COLOR; - else - color_index = color_table_index; - flag_mask >>= 1; - - yuv->y[block_ptr] = this->color_pairs[color_index + 0]; - yuv->u[block_ptr] = this->color_pairs[color_index + 1]; - yuv->v[block_ptr] = this->color_pairs[color_index + 2]; - block_ptr++; - } - block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - /* 4-color block encoding */ - case 0xA0: - case 0xB0: - n_blocks = (opcode & 0x0F) + 1; - - /* figure out which color quad to use to paint the 4-color block */ - if ((opcode & 0xF0) == 0xA0) { - /* fetch the next 4 colors from bytestream and store in next - * available entry in the color quad table */ - for (i = 0; i < CQUAD; i++) { - color_index = this->buf[stream_ptr++] * BYTES_PER_COLOR; - color_table_index = CQUAD * BYTES_PER_COLOR * color_quad_index + - (i * BYTES_PER_COLOR); - this->color_quads[color_table_index + 0] = - this->yuv_palette[color_index + 0]; - this->color_quads[color_table_index + 1] = - this->yuv_palette[color_index + 1]; - this->color_quads[color_table_index + 2] = - this->yuv_palette[color_index + 2]; - } - /* this is the base index to use for this block */ - color_table_index = CQUAD * BYTES_PER_COLOR * color_quad_index; - color_quad_index++; - /* wraparound */ - if (color_quad_index == COLORS_PER_TABLE) - color_quad_index = 0; - } - else - color_table_index = CQUAD * BYTES_PER_COLOR * this->buf[stream_ptr++]; - - while (n_blocks--) { - color_flags = BE_32(&this->buf[stream_ptr]); - stream_ptr += 4; - /* flag mask actually acts as a bit shift count here */ - flag_mask = 30; - block_ptr = row_ptr + pixel_ptr; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - for (pixel_x = 0; pixel_x < 4; pixel_x++) { - color_index = color_table_index + (BYTES_PER_COLOR * - ((color_flags >> flag_mask) & 0x03)); - flag_mask -= 2; - - yuv->y[block_ptr] = this->color_quads[color_index + 0]; - yuv->u[block_ptr] = this->color_quads[color_index + 1]; - yuv->v[block_ptr] = this->color_quads[color_index + 2]; - block_ptr++; - } - block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - /* 8-color block encoding */ - case 0xC0: - case 0xD0: - n_blocks = (opcode & 0x0F) + 1; - - /* figure out which color octet to use to paint the 8-color block */ - if ((opcode & 0xF0) == 0xC0) { - /* fetch the next 8 colors from bytestream and store in next - * available entry in the color octet table */ - for (i = 0; i < COCTET; i++) { - color_index = this->buf[stream_ptr++] * BYTES_PER_COLOR; - color_table_index = COCTET * BYTES_PER_COLOR * color_octet_index + - (i * BYTES_PER_COLOR); - this->color_octets[color_table_index + 0] = - this->yuv_palette[color_index + 0]; - this->color_octets[color_table_index + 1] = - this->yuv_palette[color_index + 1]; - this->color_octets[color_table_index + 2] = - this->yuv_palette[color_index + 2]; - } - /* this is the base index to use for this block */ - color_table_index = COCTET * BYTES_PER_COLOR * color_octet_index; - color_octet_index++; - /* wraparound */ - if (color_octet_index == COLORS_PER_TABLE) - color_octet_index = 0; - } - else - color_table_index = COCTET * BYTES_PER_COLOR * this->buf[stream_ptr++]; - - while (n_blocks--) { - /* - For this input of 6 hex bytes: - 01 23 45 67 89 AB - Mangle it to this output: - flags_a = xx012456, flags_b = xx89A37B - */ - /* build the color flags */ - color_flags_a = color_flags_b = 0; - color_flags_a = - (this->buf[stream_ptr + 0] << 16) | - ((this->buf[stream_ptr + 1] & 0xF0) << 8) | - ((this->buf[stream_ptr + 2] & 0xF0) << 4) | - ((this->buf[stream_ptr + 2] & 0x0F) << 4) | - ((this->buf[stream_ptr + 3] & 0xF0) >> 4); - color_flags_b = - (this->buf[stream_ptr + 4] << 16) | - ((this->buf[stream_ptr + 5] & 0xF0) << 8) | - ((this->buf[stream_ptr + 1] & 0x0F) << 8) | - ((this->buf[stream_ptr + 3] & 0x0F) << 4) | - (this->buf[stream_ptr + 5] & 0x0F); - stream_ptr += 6; - - color_flags = color_flags_a; - /* flag mask actually acts as a bit shift count here */ - flag_mask = 21; - block_ptr = row_ptr + pixel_ptr; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - /* reload flags at third row (iteration pixel_y == 2) */ - if (pixel_y == 2) { - color_flags = color_flags_b; - flag_mask = 21; - } - for (pixel_x = 0; pixel_x < 4; pixel_x++) { - color_index = color_table_index + (BYTES_PER_COLOR * - ((color_flags >> flag_mask) & 0x07)); - flag_mask -= 3; - - yuv->y[block_ptr] = this->color_octets[color_index + 0]; - yuv->u[block_ptr] = this->color_octets[color_index + 1]; - yuv->v[block_ptr] = this->color_octets[color_index + 2]; - block_ptr++; - } - block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - /* 16-color block encoding (every pixel is a different color) */ - case 0xE0: - n_blocks = (opcode & 0x0F) + 1; - - while (n_blocks--) { - block_ptr = row_ptr + pixel_ptr; - for (pixel_y = 0; pixel_y < 4; pixel_y++) { - for (pixel_x = 0; pixel_x < 4; pixel_x++) { - color_index = this->buf[stream_ptr++] * BYTES_PER_COLOR; - yuv->y[block_ptr] = this->yuv_palette[color_index + 0]; - yuv->u[block_ptr] = this->yuv_palette[color_index + 1]; - yuv->v[block_ptr] = this->yuv_palette[color_index + 2]; - block_ptr++; - } - block_ptr += row_inc; - } - ADVANCE_BLOCK(); - } - break; - - case 0xF0: - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "0xF0 opcode seen in SMC chunk (xine developers would like to know)\n"); - break; - } - } -} - - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -/* - * This function receives a buffer of data from the demuxer layer and - * figures out how to handle it based on its header flags. - */ -static void qtsmc_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - qtsmc_decoder_t *this = (qtsmc_decoder_t *) this_gen; - xine_bmiheader *bih; - palette_entry_t *palette; - int i; - - vo_frame_t *img; /* video out frame */ - - /* a video decoder does not care about this flag (?) */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { - palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - for (i = 0; i < buf->decoder_info[2]; i++) { - this->yuv_palette[i * 4 + 0] = - COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 1] = - COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 2] = - COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */ - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - bih = (xine_bmiheader *) buf->content; - this->width = (bih->biWidth + 3) & ~0x03; - this->height = (bih->biHeight + 3) & ~0x03; - this->ratio = (double)this->width/(double)this->height; - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - init_yuv_planes(&this->yuv_planes, this->width, this->height); - - this->stream->video_out->open (this->stream->video_out, this->stream); - this->decoder_ok = 1; - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Quicktime Graphics (SMC)"); - - return; - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, - this->ratio, XINE_IMGFMT_YUY2, - VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = 0; - - decode_qtsmc(this); - yuv444_to_yuy2(&this->yuv_planes, img->base[0], img->pitches[0]); - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -/* - * This function is called when xine needs to flush the system. Not - * sure when or if this is used or even if it needs to do anything. - */ -static void qtsmc_flush (video_decoder_t *this_gen) { -} - -/* - * This function resets the video decoder. - */ -static void qtsmc_reset (video_decoder_t *this_gen) { - qtsmc_decoder_t *this = (qtsmc_decoder_t *) this_gen; - - this->size = 0; -} - -static void qtsmc_discontinuity (video_decoder_t *this_gen) { -} - -/* - * This function frees the video decoder instance allocated to the decoder. - */ -static void qtsmc_dispose (video_decoder_t *this_gen) { - - qtsmc_decoder_t *this = (qtsmc_decoder_t *) this_gen; - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - qtsmc_decoder_t *this ; - - this = (qtsmc_decoder_t *) xine_xmalloc (sizeof (qtsmc_decoder_t)); - - this->video_decoder.decode_data = qtsmc_decode_data; - this->video_decoder.flush = qtsmc_flush; - this->video_decoder.reset = qtsmc_reset; - this->video_decoder.discontinuity = qtsmc_discontinuity; - this->video_decoder.dispose = qtsmc_dispose; - this->size = 0; - - this->stream = stream; - this->class = (qtsmc_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "QT SMC"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Quicktime Graphics (SMC) video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - qtsmc_class_t *this; - - this = (qtsmc_class_t *) xine_xmalloc (sizeof (qtsmc_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_VIDEO_SMC, 0 }; - -static decoder_info_t video_decoder_info = { - supported_types, /* supported types */ - 9 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "smc", XINE_VERSION_CODE, &video_decoder_info, &init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; - diff --git a/src/libxinevdec/roqvideo.c b/src/libxinevdec/roqvideo.c deleted file mode 100644 index 7a316bfd6..000000000 --- a/src/libxinevdec/roqvideo.c +++ /dev/null @@ -1,578 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * $Id: roqvideo.c,v 1.28 2004/02/09 22:04:11 jstembridge Exp $ - */ - -/* And this is the header that came with the RoQ video decoder: */ -/* ------------------------------------------------------------------------ - * Id Software's RoQ video file format decoder - * - * Dr. Tim Ferguson, 2001. - * For more details on the algorithm: - * http://www.csse.monash.edu.au/~timf/videocodec.html - * - * This is a simple decoder for the Id Software RoQ video format. In - * this format, audio samples are DPCM coded and the video frames are - * coded using motion blocks and vector quantisation. - * - * Note: All information on the RoQ file format has been obtained through - * pure reverse engineering. This was achieved by giving known input - * audio and video frames to the roq.exe encoder and analysing the - * resulting output text and RoQ file. No decompiling of the Quake III - * Arena game was required. - * - * You may freely use this source code. I only ask that you reference its - * source in your projects documentation: - * Tim Ferguson: http://www.csse.monash.edu.au/~timf/ - * ------------------------------------------------------------------------ */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "xineutils.h" - -#define VIDEOBUFSIZE 128*1024 - -#define RoQ_INFO 0x1001 -#define RoQ_QUAD_CODEBOOK 0x1002 -#define RoQ_QUAD_VQ 0x1011 -#define RoQ_SOUND_MONO 0x1020 -#define RoQ_SOUND_STEREO 0x1021 - -#define RoQ_ID_MOT 0x00 -#define RoQ_ID_FCC 0x01 -#define RoQ_ID_SLD 0x02 -#define RoQ_ID_CCC 0x03 - -#define get_byte(in_buffer) *(in_buffer++) -#define get_word(in_buffer) ((unsigned short)(in_buffer += 2, \ - (in_buffer[-1] << 8 | in_buffer[-2]))) -#define get_long(in_buffer) ((unsigned long)(in_buffer += 4, \ - (in_buffer[-1] << 24 | in_buffer[-2] << 16 | in_buffer[-3] << 8 | in_buffer[-4]))) - -typedef struct { - unsigned char y0, y1, y2, y3, u, v; -} roq_cell; - -typedef struct { - int idx[4]; -} roq_qcell; - -typedef struct { - video_decoder_class_t decoder_class; -} roqvideo_class_t; - -typedef struct roq_decoder_s { - video_decoder_t video_decoder; - - roqvideo_class_t *class; - xine_stream_t *stream; - - - int video_step; - int skipframes; - unsigned char *buf; - int bufsize; - int size; - int width; - int height; - double ratio; - - roq_cell cells[256]; - roq_qcell qcells[256]; - long roq_start, aud_pos, vid_pos; - long *frame_offset; - unsigned long num_frames, num_audio_bytes; - unsigned char *y[2], *u[2], *v[2]; - int y_size; - int c_size; - - unsigned char *cur_y, *cur_u, *cur_v; - unsigned char *prev_y, *prev_u, *prev_v; - - /* this is either 0 or 1 indicating the cur_y points to y[0] or y[1], - * same for u and v */ - int current_planes; - -} roqvideo_decoder_t; - -/************************************************************************** - * RoQ video specific decode functions - *************************************************************************/ - -static void apply_vector_2x2(roqvideo_decoder_t *ri, int x, int y, roq_cell *cell) { - unsigned char *yptr; - - yptr = ri->cur_y + (y * ri->width) + x; - *yptr++ = cell->y0; - *yptr++ = cell->y1; - yptr += (ri->width - 2); - *yptr++ = cell->y2; - *yptr++ = cell->y3; - ri->cur_u[(y/2) * (ri->width/2) + x/2] = cell->u; - ri->cur_v[(y/2) * (ri->width/2) + x/2] = cell->v; -} - -static void apply_vector_4x4(roqvideo_decoder_t *ri, int x, int y, roq_cell *cell) { - unsigned long row_inc, c_row_inc; - register unsigned char y0, y1, u, v; - unsigned char *yptr, *uptr, *vptr; - - yptr = ri->cur_y + (y * ri->width) + x; - uptr = ri->cur_u + (y/2) * (ri->width/2) + x/2; - vptr = ri->cur_v + (y/2) * (ri->width/2) + x/2; - - row_inc = ri->width - 4; - c_row_inc = (ri->width/2) - 2; - *yptr++ = y0 = cell->y0; *uptr++ = u = cell->u; *vptr++ = v = cell->v; - *yptr++ = y0; - *yptr++ = y1 = cell->y1; *uptr++ = u; *vptr++ = v; - *yptr++ = y1; - - yptr += row_inc; - - *yptr++ = y0; - *yptr++ = y0; - *yptr++ = y1; - *yptr++ = y1; - - yptr += row_inc; uptr += c_row_inc; vptr += c_row_inc; - - *yptr++ = y0 = cell->y2; *uptr++ = u; *vptr++ = v; - *yptr++ = y0; - *yptr++ = y1 = cell->y3; *uptr++ = u; *vptr++ = v; - *yptr++ = y1; - - yptr += row_inc; - - *yptr++ = y0; - *yptr++ = y0; - *yptr++ = y1; - *yptr++ = y1; -} - -static void apply_motion_4x4(roqvideo_decoder_t *ri, int x, int y, unsigned char mv, - char mean_x, char mean_y) -{ - int i, mx, my; - unsigned char *pa, *pb; - - mx = x + 8 - (mv >> 4) - mean_x; - my = y + 8 - (mv & 0xf) - mean_y; - - pa = ri->cur_y + (y * ri->width) + x; - pb = ri->prev_y + (my * ri->width) + mx; - for(i = 0; i < 4; i++) { - pa[0] = pb[0]; - pa[1] = pb[1]; - pa[2] = pb[2]; - pa[3] = pb[3]; - pa += ri->width; - pb += ri->width; - } - - pa = ri->cur_u + (y/2) * (ri->width/2) + x/2; - pb = ri->prev_u + (my/2) * (ri->width/2) + (mx + 1)/2; - for(i = 0; i < 2; i++) { - pa[0] = pb[0]; - pa[1] = pb[1]; - pa += ri->width/2; - pb += ri->width/2; - } - - pa = ri->cur_v + (y/2) * (ri->width/2) + x/2; - pb = ri->prev_v + (my/2) * (ri->width/2) + (mx + 1)/2; - for(i = 0; i < 2; i++) { - pa[0] = pb[0]; - pa[1] = pb[1]; - pa += ri->width/2; - pb += ri->width/2; - } -} - -static void apply_motion_8x8(roqvideo_decoder_t *ri, int x, int y, - unsigned char mv, char mean_x, char mean_y) { - - int mx, my, i; - unsigned char *pa, *pb; - - mx = x + 8 - (mv >> 4) - mean_x; - my = y + 8 - (mv & 0xf) - mean_y; - - pa = ri->cur_y + (y * ri->width) + x; - pb = ri->prev_y + (my * ri->width) + mx; - for(i = 0; i < 8; i++) { - pa[0] = pb[0]; - pa[1] = pb[1]; - pa[2] = pb[2]; - pa[3] = pb[3]; - pa[4] = pb[4]; - pa[5] = pb[5]; - pa[6] = pb[6]; - pa[7] = pb[7]; - pa += ri->width; - pb += ri->width; - } - - pa = ri->cur_u + (y/2) * (ri->width/2) + x/2; - pb = ri->prev_u + (my/2) * (ri->width/2) + (mx + 1)/2; - for(i = 0; i < 4; i++) { - pa[0] = pb[0]; - pa[1] = pb[1]; - pa[2] = pb[2]; - pa[3] = pb[3]; - pa += ri->width/2; - pb += ri->width/2; - } - - pa = ri->cur_v + (y/2) * (ri->width/2) + x/2; - pb = ri->prev_v + (my/2) * (ri->width/2) + (mx + 1)/2; - for(i = 0; i < 4; i++) { - pa[0] = pb[0]; - pa[1] = pb[1]; - pa[2] = pb[2]; - pa[3] = pb[3]; - pa += ri->width/2; - pb += ri->width/2; - } -} - -static void roqvideo_decode_frame(roqvideo_decoder_t *ri) { - unsigned int chunk_id = 0, chunk_arg = 0; - unsigned long chunk_size = 0; - int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1; - int vqid, bpos, xpos, ypos, xp, yp, x, y; - int frame_stats[2][4] = {{0},{0}}; - roq_qcell *qcell; - unsigned char *buf = ri->buf; - unsigned char *buf_end = ri->buf + ri->size; - - while (buf < buf_end) { - chunk_id = get_word(buf); - chunk_size = get_long(buf); - chunk_arg = get_word(buf); - - if(chunk_id == RoQ_QUAD_VQ) - break; - if(chunk_id == RoQ_QUAD_CODEBOOK) { - if((nv1 = chunk_arg >> 8) == 0) - nv1 = 256; - if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size) - nv2 = 256; - for(i = 0; i < nv1; i++) { - ri->cells[i].y0 = get_byte(buf); - ri->cells[i].y1 = get_byte(buf); - ri->cells[i].y2 = get_byte(buf); - ri->cells[i].y3 = get_byte(buf); - ri->cells[i].u = get_byte(buf); - ri->cells[i].v = get_byte(buf); - } - for(i = 0; i < nv2; i++) - for(j = 0; j < 4; j++) - ri->qcells[i].idx[j] = get_byte(buf); - } - } - - bpos = xpos = ypos = 0; - while(bpos < chunk_size) { - for (yp = ypos; yp < ypos + 16; yp += 8) - for (xp = xpos; xp < xpos + 16; xp += 8) { - if (vqflg_pos < 0) { - vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8); - vqflg_pos = 7; - } - vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; - frame_stats[0][vqid]++; - vqflg_pos--; - - switch(vqid) { - case RoQ_ID_MOT: - apply_motion_8x8(ri, xp, yp, 0, 8, 8); - break; - case RoQ_ID_FCC: - apply_motion_8x8(ri, xp, yp, buf[bpos++], chunk_arg >> 8, - chunk_arg & 0xff); - break; - case RoQ_ID_SLD: - qcell = ri->qcells + buf[bpos++]; - apply_vector_4x4(ri, xp, yp, ri->cells + qcell->idx[0]); - apply_vector_4x4(ri, xp+4, yp, ri->cells + qcell->idx[1]); - apply_vector_4x4(ri, xp, yp+4, ri->cells + qcell->idx[2]); - apply_vector_4x4(ri, xp+4, yp+4, ri->cells + qcell->idx[3]); - break; - case RoQ_ID_CCC: - for (k = 0; k < 4; k++) { - x = xp; y = yp; - if(k & 0x01) x += 4; - if(k & 0x02) y += 4; - - if (vqflg_pos < 0) { - vqflg = buf[bpos++]; - vqflg |= (buf[bpos++] << 8); - vqflg_pos = 7; - } - vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; - frame_stats[1][vqid]++; - vqflg_pos--; - switch(vqid) { - case RoQ_ID_MOT: - apply_motion_4x4(ri, x, y, 0, 8, 8); - break; - case RoQ_ID_FCC: - apply_motion_4x4(ri, x, y, buf[bpos++], chunk_arg >> 8, - chunk_arg & 0xff); - break; - case RoQ_ID_SLD: - qcell = ri->qcells + buf[bpos++]; - apply_vector_2x2(ri, x, y, ri->cells + qcell->idx[0]); - apply_vector_2x2(ri, x+2, y, ri->cells + qcell->idx[1]); - apply_vector_2x2(ri, x, y+2, ri->cells + qcell->idx[2]); - apply_vector_2x2(ri, x+2, y+2, ri->cells + qcell->idx[3]); - break; - case RoQ_ID_CCC: - apply_vector_2x2(ri, x, y, ri->cells + buf[bpos]); - apply_vector_2x2(ri, x+2, y, ri->cells + buf[bpos+1]); - apply_vector_2x2(ri, x, y+2, ri->cells + buf[bpos+2]); - apply_vector_2x2(ri, x+2, y+2, ri->cells + buf[bpos+3]); - bpos += 4; - break; - } - } - break; - default: - xprintf(ri->stream->xine, XINE_VERBOSITY_DEBUG, "Unknown vq code: %d\n", vqid); - } - } - - xpos += 16; - if (xpos >= ri->width) { - xpos -= ri->width; - ypos += 16; - } - if(ypos >= ri->height) - break; - } -} - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -static void roqvideo_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - roqvideo_decoder_t *this = (roqvideo_decoder_t *) this_gen; - vo_frame_t *img; /* video out frame */ - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */ - xine_bmiheader *bih = (xine_bmiheader *)buf->content; - - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - this->buf = xine_xmalloc(VIDEOBUFSIZE); - this->bufsize = VIDEOBUFSIZE; - this->size = 0; - this->width = bih->biWidth; - this->height = bih->biHeight; - this->ratio = (double)this->width/(double)this->height; - this->skipframes = 0; - this->current_planes = 0; - - this->y_size = this->width * this->height; - this->c_size = (this->width * this->height) / 4; - - this->y[0] = xine_xmalloc(this->y_size); - this->y[1] = xine_xmalloc(this->y_size); - memset(this->y[0], 0x00, this->y_size); - memset(this->y[1], 0x00, this->y_size); - - this->u[0] = xine_xmalloc(this->c_size); - this->u[1] = xine_xmalloc(this->c_size); - memset(this->u[0], 0x80, this->c_size); - memset(this->u[1], 0x80, this->c_size); - - this->v[0] = xine_xmalloc(this->c_size); - this->v[1] = xine_xmalloc(this->c_size); - memset(this->v[0], 0x80, this->c_size); - memset(this->v[1], 0x80, this->c_size); - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "RoQ VQ Video"); - - return; - } - - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "RoQ: increasing source buffer to %d to avoid overflow.\n", this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - img = this->stream->video_out->get_frame (this->stream->video_out, - this->width, this->height, this->ratio, XINE_IMGFMT_YV12, - VO_BOTH_FIELDS); - - img->pts = buf->pts; - img->duration = this->video_step; - - if (this->current_planes == 0) { - this->cur_y = this->y[0]; - this->cur_u = this->u[0]; - this->cur_v = this->v[0]; - this->prev_y = this->y[1]; - this->prev_u = this->u[1]; - this->prev_v = this->v[1]; - this->current_planes = 1; - } else { - this->cur_y = this->y[1]; - this->cur_u = this->u[1]; - this->cur_v = this->v[1]; - this->prev_y = this->y[0]; - this->prev_u = this->u[0]; - this->prev_v = this->v[0]; - this->current_planes = 0; - } - roqvideo_decode_frame(this); - xine_fast_memcpy(img->base[0], this->cur_y, this->y_size); - xine_fast_memcpy(img->base[1], this->cur_u, this->c_size); - xine_fast_memcpy(img->base[2], this->cur_v, this->c_size); - - this->skipframes = img->draw(img, this->stream); - if( this->skipframes < 0 ) - this->skipframes = 0; - img->free(img); - - this->size = 0; - } -} - -static void roqvideo_flush (video_decoder_t *this_gen) { -} - -static void roqvideo_reset (video_decoder_t *this_gen) { -} - -static void roqvideo_discontinuity (video_decoder_t *this_gen) { -} - -static void roqvideo_dispose (video_decoder_t *this_gen) { - - roqvideo_decoder_t *this = (roqvideo_decoder_t *) this_gen; - - this->stream->video_out->close(this->stream->video_out, this->stream); - - free(this->y[0]); - free(this->y[1]); - free(this->u[0]); - free(this->u[1]); - free(this->v[0]); - free(this->v[1]); - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - roqvideo_decoder_t *this ; - - this = (roqvideo_decoder_t *) xine_xmalloc (sizeof (roqvideo_decoder_t)); - - this->video_decoder.decode_data = roqvideo_decode_data; - this->video_decoder.flush = roqvideo_flush; - this->video_decoder.reset = roqvideo_reset; - this->video_decoder.discontinuity = roqvideo_discontinuity; - this->video_decoder.dispose = roqvideo_dispose; - this->size = 0; - - this->stream = stream; - this->class = (roqvideo_class_t *) class_gen; - - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "RoQ Video"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Id RoQ video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - roqvideo_class_t *this; - - this = (roqvideo_class_t *) xine_xmalloc (sizeof (roqvideo_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t video_types[] = { - BUF_VIDEO_ROQ, - 0 - }; - -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 1 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "roq", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/svq1.c b/src/libxinevdec/svq1.c deleted file mode 100644 index 6c93eb1ab..000000000 --- a/src/libxinevdec/svq1.c +++ /dev/null @@ -1,1507 +0,0 @@ -/* - * Copyright (C) 2002-2003 the xine project - * - * This file is part of xine, a unix video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * $Id: svq1.c,v 1.32 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "xine_internal.h" -#include "video_out.h" -#include "buffer.h" -#include "bswap.h" -#include "xineutils.h" - -#include "svq1_codebooks.h" - -#define VIDEOBUFSIZE 128 * 1024 - -#define MEDIAN(a,b,c) ((a < b != b >= c) ? b : ((a < c != c > b) ? c : a)) - -#define SVQ1_BLOCK_SKIP 0 -#define SVQ1_BLOCK_INTER 1 -#define SVQ1_BLOCK_INTER_4V 2 -#define SVQ1_BLOCK_INTRA 3 - -#define SVQ1_FRAME_INTRA 0 -#define SVQ1_FRAME_INTER 1 -#define SVQ1_FRAME_DROPPABLE 2 - - -/* memory bit stream */ -typedef struct bit_buffer_s { - uint8_t *buffer; - unsigned int bitpos; - unsigned int length; -} bit_buffer_t; - -/* variable length (bit) code */ -typedef struct vlc_code_s { - int16_t value :10, - length :6; -} vlc_code_t; - -/* motion vector (prediction) */ -typedef struct svq1_pmv_s { - int x; - int y; -} svq1_pmv_t; - -typedef struct svq1_s { - int frame_code; - int frame_type; - int frame_width; - int frame_height; - int luma_width; - int luma_height; - int chroma_width; - int chroma_height; - svq1_pmv_t *motion; - uint8_t *current; - uint8_t *previous; - int offsets[3]; - int reference_frame; - - uint8_t *base[3]; - int width; - int height; - double ratio; -} svq1_t; - -typedef struct { - video_decoder_class_t decoder_class; -} svq1_class_t; - -typedef struct svq1dec_decoder_s { - video_decoder_t video_decoder; - - svq1_class_t *class; - xine_stream_t *stream; - - int64_t video_step; - int decoder_ok; - - unsigned char *buf; - int bufsize; - int size; - - svq1_t *svq1; -} svq1dec_decoder_t; - - -/* standard video sizes */ -static struct { int width; int height; } frame_size_table[8] = { - { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 }, - { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 } -}; - -/* block type, codes 000 .. 1xx */ -static vlc_code_t block_type_table[8] = { - { SVQ1_BLOCK_INTRA, 3 }, { SVQ1_BLOCK_INTER_4V, 3 }, - { SVQ1_BLOCK_INTER, 2 }, { SVQ1_BLOCK_INTER, 2 }, - { SVQ1_BLOCK_SKIP, 1 }, { SVQ1_BLOCK_SKIP, 1 }, - { SVQ1_BLOCK_SKIP, 1 }, { SVQ1_BLOCK_SKIP, 1 } -}; - -/* motion vector, codes 0000011 .. 011xxxx */ -static vlc_code_t motion_table_0[61] = { - { 7, 8 }, { 6, 8 }, { 5, 8 }, { 4, 7 }, { 4, 7 }, - { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, - { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, - { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 } -}; - -/* motion vector, codes 000000000010 ... 0000010111xx */ -static vlc_code_t motion_table_1[94] = { - {32, 13}, {31, 13}, {30, 12}, {30, 12}, {29, 12}, {29, 12}, - {28, 12}, {28, 12}, {27, 12}, {27, 12}, {26, 12}, {26, 12}, {25, 12}, {25, 12}, - {24, 11}, {24, 11}, {24, 11}, {24, 11}, {23, 11}, {23, 11}, {23, 11}, {23, 11}, - {22, 11}, {22, 11}, {22, 11}, {22, 11}, {21, 11}, {21, 11}, {21, 11}, {21, 11}, - {20, 11}, {20, 11}, {20, 11}, {20, 11}, {19, 11}, {19, 11}, {19, 11}, {19, 11}, - {18, 11}, {18, 11}, {18, 11}, {18, 11}, {17, 11}, {17, 11}, {17, 11}, {17, 11}, - {16, 11}, {16, 11}, {16, 11}, {16, 11}, {15, 11}, {15, 11}, {15, 11}, {15, 11}, - {14, 11}, {14, 11}, {14, 11}, {14, 11}, {13, 11}, {13, 11}, {13, 11}, {13, 11}, - {12, 11}, {12, 11}, {12, 11}, {12, 11}, {11, 11}, {11, 11}, {11, 11}, {11, 11}, - {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, - { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, - { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, -}; - -/* inter-coded vector codebook count tables, codes 000000 ... 111111 */ -static vlc_code_t inter_vector_tables[6][64] = { - /* 4x2 vector, codes 0000xxx ... 11xxxxx */ - { { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, - { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, - { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, - { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, - {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, - {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 } }, - - /* 4x4 vector, codes 0000xxx ... 11xxxxx */ - { { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, - { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, - { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, - { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, - {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, - {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 } }, - - /* 8x4 vector, codes 00000xx ... 1xxxxxx */ - { { 6, 5 }, { 6, 5 }, { 5, 5 }, { 5, 5 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, - { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 } }, - - /* 8x8 vector, codes 00000xx ... 1xxxxxx */ - { { 6, 5 }, { 6, 5 }, { 5, 5 }, { 5, 5 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, - { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 } }, - - /* 16x8 vector, codes 00000xx ... 1xxxxxx */ - { { 6, 5 }, { 6, 5 }, { 5, 5 }, { 5, 5 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, - { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 } }, - - /* 16x16 vector, codes 000000x ... 1xxxxxx */ - { { 6, 6 }, { 5, 6 }, { 4, 5 }, { 4, 5 }, { 3, 5 }, { 3, 5 }, { 2, 5 }, { 2, 5 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, - { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, - {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 } } -}; - -/* vector codebook count tables, codes 0000000 ... 1111111 */ -static vlc_code_t intra_vector_tables[6][128] = { - /* 4x2 vector, codes 00000xx ... 1xxxxxx */ - { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, {-1, 5 }, {-1, 5 }, {-1, 5 }, {-1, 5 }, - { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, - { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, - { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, - { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, - { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } }, - - /* 4x4 vector, codes 0000xxx ... 11xxxxx */ - { { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, - {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, - { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, - { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, - { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, - { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, - { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, - { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, - { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, - { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, - { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, - { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, - { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 } }, - - /* 8x4 vector, codes 00000xx ... 1xxxxxx */ - { { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, {-1, 5 }, {-1, 5 }, {-1, 5 }, {-1, 5 }, - { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, - { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, - { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, - { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, - { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } }, - - /* 8x8 vector, codes 000000x ... 1xxxxxx */ - { { 2, 6 }, { 2, 6 }, {-1, 6 }, {-1, 6 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, - { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, - { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, - { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } }, - - /* 16x8 vector, codes 000000x ... 1xxxxxx */ - { { 4, 6 }, { 4, 6 }, {-1, 6 }, {-1, 6 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, - { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, - { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, - { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } }, - - /* 16x16 vector, codes 0000000 ... 1xxxxxx */ - { { 5, 7 }, {-1, 7 }, { 4, 6 }, { 4, 6 }, { 6, 5 }, { 6, 5 }, { 6, 5 }, { 6, 5 }, - { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, - { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, - { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } } -}; - -/* intra mean value, codes 00100101 ... 1111xxxx */ -static vlc_code_t intra_mean_table_0[219] = { - {135, 8 }, {136, 8 }, {165, 8 }, - {134, 8 }, {129, 8 }, {164, 8 }, {163, 8 }, {133, 8 }, {162, 8 }, {174, 8 }, {175, 8 }, - {161, 8 }, {160, 8 }, {159, 8 }, {158, 8 }, {157, 8 }, {156, 8 }, {155, 8 }, {154, 8 }, - {153, 8 }, {151, 8 }, {152, 8 }, {132, 8 }, {110, 8 }, {131, 8 }, {108, 8 }, {130, 8 }, - {166, 8 }, {105, 8 }, {104, 8 }, {103, 8 }, {127, 8 }, {101, 8 }, {167, 8 }, {168, 8 }, - { 98, 8 }, {128, 8 }, { 48, 8 }, { 95, 8 }, { 62, 8 }, { 93, 8 }, { 92, 8 }, { 91, 8 }, - { 90, 8 }, { 89, 8 }, { 60, 8 }, { 87, 8 }, { 86, 8 }, { 57, 8 }, { 84, 8 }, { 83, 8 }, - { 82, 8 }, { 81, 8 }, { 80, 8 }, { 79, 8 }, { 78, 8 }, { 77, 8 }, { 76, 8 }, { 75, 8 }, - { 74, 8 }, { 73, 8 }, { 72, 8 }, { 71, 8 }, { 70, 8 }, { 69, 8 }, { 68, 8 }, { 67, 8 }, - { 66, 8 }, { 65, 8 }, { 56, 8 }, { 63, 8 }, { 23, 8 }, { 61, 8 }, { 30, 8 }, { 59, 8 }, - { 58, 8 }, { 52, 8 }, { 29, 8 }, { 55, 8 }, { 54, 8 }, { 53, 8 }, { 50, 8 }, { 51, 8 }, - { 22, 8 }, { 49, 8 }, { 85, 7 }, { 85, 7 }, { 97, 7 }, { 97, 7 }, { 88, 7 }, { 88, 7 }, - { 64, 7 }, { 64, 7 }, { 94, 7 }, { 94, 7 }, {106, 7 }, {106, 7 }, {107, 7 }, {107, 7 }, - {109, 7 }, {109, 7 }, {111, 7 }, {111, 7 }, {112, 7 }, {112, 7 }, {113, 7 }, {113, 7 }, - {114, 7 }, {114, 7 }, {115, 7 }, {115, 7 }, {116, 7 }, {116, 7 }, {117, 7 }, {117, 7 }, - {118, 7 }, {118, 7 }, {119, 7 }, {119, 7 }, {120, 7 }, {120, 7 }, { 99, 7 }, { 99, 7 }, - {102, 7 }, {102, 7 }, { 28, 7 }, { 28, 7 }, {100, 7 }, {100, 7 }, { 96, 7 }, { 96, 7 }, - {139, 7 }, {139, 7 }, { 24, 7 }, { 24, 7 }, { 1, 7 }, { 1, 7 }, {138, 7 }, {138, 7 }, - {121, 7 }, {121, 7 }, {122, 7 }, {122, 7 }, {123, 7 }, {123, 7 }, {124, 7 }, {124, 7 }, - {125, 7 }, {125, 7 }, {126, 7 }, {126, 7 }, {137, 7 }, {137, 7 }, {140, 7 }, {140, 7 }, - {150, 7 }, {150, 7 }, {144, 7 }, {144, 7 }, {141, 7 }, {141, 7 }, {142, 7 }, {142, 7 }, - {143, 7 }, {143, 7 }, {145, 7 }, {145, 7 }, {147, 7 }, {147, 7 }, {146, 7 }, {146, 7 }, - { 27, 6 }, { 27, 6 }, { 27, 6 }, { 27, 6 }, {148, 6 }, {148, 6 }, {148, 6 }, {148, 6 }, - {149, 6 }, {149, 6 }, {149, 6 }, {149, 6 }, { 0, 6 }, { 0, 6 }, { 0, 6 }, { 0, 6 }, - { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, - { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, - { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, - { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 } -}; - -/* intra mean value, codes 0000001101 ... 001001001x */ -static vlc_code_t intra_mean_table_1[135] = { - {218, 10}, {219, 10}, {220, 10}, - {221, 10}, {222, 10}, {217, 10}, {230, 10}, {215, 10}, {208, 10}, {207, 10}, {206, 10}, - {214, 10}, {204, 10}, {223, 10}, {224, 10}, {225, 10}, {226, 10}, {227, 10}, {228, 10}, - {229, 10}, {213, 10}, {212, 10}, {231, 10}, {232, 10}, {211, 10}, {210, 10}, {236, 10}, - {209, 10}, {216, 10}, {205, 10}, { 18, 10}, {186, 9 }, {186, 9 }, {185, 9 }, {185, 9 }, - {184, 9 }, {184, 9 }, {182, 9 }, {182, 9 }, {183, 9 }, {183, 9 }, {180, 9 }, {180, 9 }, - {181, 9 }, {181, 9 }, {178, 9 }, {178, 9 }, {187, 9 }, {187, 9 }, {176, 9 }, {176, 9 }, - {188, 9 }, {188, 9 }, {179, 9 }, {179, 9 }, {173, 9 }, {173, 9 }, {172, 9 }, {172, 9 }, - {171, 9 }, {171, 9 }, {170, 9 }, {170, 9 }, {169, 9 }, {169, 9 }, {189, 9 }, {189, 9 }, - {190, 9 }, {190, 9 }, {191, 9 }, {191, 9 }, {192, 9 }, {192, 9 }, {193, 9 }, {193, 9 }, - {194, 9 }, {194, 9 }, {195, 9 }, {195, 9 }, {196, 9 }, {196, 9 }, {197, 9 }, {197, 9 }, - {198, 9 }, {198, 9 }, {200, 9 }, {200, 9 }, {201, 9 }, {201, 9 }, {202, 9 }, {202, 9 }, - {203, 9 }, {203, 9 }, {199, 9 }, {199, 9 }, {177, 9 }, {177, 9 }, { 40, 9 }, { 40, 9 }, - { 39, 9 }, { 39, 9 }, { 38, 9 }, { 38, 9 }, { 37, 9 }, { 37, 9 }, { 36, 9 }, { 36, 9 }, - { 35, 9 }, { 35, 9 }, { 34, 9 }, { 34, 9 }, { 33, 9 }, { 33, 9 }, { 32, 9 }, { 32, 9 }, - { 31, 9 }, { 31, 9 }, { 21, 9 }, { 21, 9 }, { 11, 9 }, { 11, 9 }, { 41, 9 }, { 41, 9 }, - { 45, 9 }, { 45, 9 }, { 44, 9 }, { 44, 9 }, { 42, 9 }, { 42, 9 }, { 43, 9 }, { 43, 9 }, - { 47, 9 }, { 47, 9 }, { 46, 9 }, { 46, 9 } -}; - -/* intra mean value, codes 00000000000001 ... 00000011001xxx */ -static vlc_code_t intra_mean_table_2[207] = { - {255, 14}, { 14, 14}, { 13, 14}, { 17, 12}, { 17, 12}, { 17, 12}, { 17, 12}, - {243, 11}, {243, 11}, {243, 11}, {243, 11}, {243, 11}, {243, 11}, {243, 11}, {243, 11}, - {242, 11}, {242, 11}, {242, 11}, {242, 11}, {242, 11}, {242, 11}, {242, 11}, {242, 11}, - {241, 11}, {241, 11}, {241, 11}, {241, 11}, {241, 11}, {241, 11}, {241, 11}, {241, 11}, - {240, 11}, {240, 11}, {240, 11}, {240, 11}, {240, 11}, {240, 11}, {240, 11}, {240, 11}, - {237, 11}, {237, 11}, {237, 11}, {237, 11}, {237, 11}, {237, 11}, {237, 11}, {237, 11}, - {239, 11}, {239, 11}, {239, 11}, {239, 11}, {239, 11}, {239, 11}, {239, 11}, {239, 11}, - {235, 11}, {235, 11}, {235, 11}, {235, 11}, {235, 11}, {235, 11}, {235, 11}, {235, 11}, - {234, 11}, {234, 11}, {234, 11}, {234, 11}, {234, 11}, {234, 11}, {234, 11}, {234, 11}, - {233, 11}, {233, 11}, {233, 11}, {233, 11}, {233, 11}, {233, 11}, {233, 11}, {233, 11}, - {244, 11}, {244, 11}, {244, 11}, {244, 11}, {244, 11}, {244, 11}, {244, 11}, {244, 11}, - {238, 11}, {238, 11}, {238, 11}, {238, 11}, {238, 11}, {238, 11}, {238, 11}, {238, 11}, - { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, - {248, 11}, {248, 11}, {248, 11}, {248, 11}, {248, 11}, {248, 11}, {248, 11}, {248, 11}, - {249, 11}, {249, 11}, {249, 11}, {249, 11}, {249, 11}, {249, 11}, {249, 11}, {249, 11}, - {250, 11}, {250, 11}, {250, 11}, {250, 11}, {250, 11}, {250, 11}, {250, 11}, {250, 11}, - {251, 11}, {251, 11}, {251, 11}, {251, 11}, {251, 11}, {251, 11}, {251, 11}, {251, 11}, - {252, 11}, {252, 11}, {252, 11}, {252, 11}, {252, 11}, {252, 11}, {252, 11}, {252, 11}, - {253, 11}, {253, 11}, {253, 11}, {253, 11}, {253, 11}, {253, 11}, {253, 11}, {253, 11}, - {254, 11}, {254, 11}, {254, 11}, {254, 11}, {254, 11}, {254, 11}, {254, 11}, {254, 11}, - { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, - { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, - {245, 11}, {245, 11}, {245, 11}, {245, 11}, {245, 11}, {245, 11}, {245, 11}, {245, 11}, - {247, 11}, {247, 11}, {247, 11}, {247, 11}, {247, 11}, {247, 11}, {247, 11}, {247, 11}, - { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, - {246, 11}, {246, 11}, {246, 11}, {246, 11}, {246, 11}, {246, 11}, {246, 11}, {246, 11} -}; - -/* intra mean value, codes 00000000000000000000 ... 000000000000001xxxxx */ -static vlc_code_t intra_mean_table_3[64] = { - { 6, 20}, { 3, 20}, { 4, 20}, { 5, 20}, { 7, 20}, { 8, 20}, { 9, 19}, { 9, 19}, - { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, - { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, - { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, - { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, - { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, - { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, - { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15} -}; - -/* inter mean value, codes 00001011 ... 1xxxxxxx */ -static vlc_code_t inter_mean_table_0[245] = { - { 10, 8 }, { 12, 8 }, { 11, 8 }, {-11, 8 }, {-12, 8 }, - {-10, 8 }, { -9, 8 }, { -7, 7 }, { -7, 7 }, { -6, 7 }, { -6, 7 }, { 8, 7 }, { 8, 7 }, - { -8, 7 }, { -8, 7 }, { 9, 7 }, { 9, 7 }, { 6, 7 }, { 6, 7 }, { 7, 7 }, { 7, 7 }, - { -5, 6 }, { -5, 6 }, { -5, 6 }, { -5, 6 }, { -4, 6 }, { -4, 6 }, { -4, 6 }, { -4, 6 }, - { 5, 6 }, { 5, 6 }, { 5, 6 }, { 5, 6 }, { 4, 6 }, { 4, 6 }, { 4, 6 }, { 4, 6 }, - { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, - { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, - { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, - { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, - { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, - { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, - { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } -}; - -/* inter mean value, codes 000000010010 ... 00001011xxxx */ -static vlc_code_t inter_mean_table_1[158] = { - {-30, 12}, {-31, 12}, {-32, 12}, {-33, 12}, { 31, 12}, {-34, 12}, - {-35, 12}, { 29, 12}, { 30, 12}, { 33, 12}, { 34, 12}, { 32, 12}, {-29, 11}, {-29, 11}, - {-28, 11}, {-28, 11}, { 28, 11}, { 28, 11}, {-27, 11}, {-27, 11}, {-26, 11}, {-26, 11}, - { 27, 11}, { 27, 11}, { 26, 11}, { 26, 11}, { 25, 11}, { 25, 11}, { 24, 11}, { 24, 11}, - { 23, 11}, { 23, 11}, { 22, 11}, { 22, 11}, {-24, 11}, {-24, 11}, {-25, 11}, {-25, 11}, - {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10}, {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10}, - {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10}, {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10}, - {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10}, {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10}, - { 19, 10}, { 19, 10}, { 19, 10}, { 19, 10}, { 21, 10}, { 21, 10}, { 21, 10}, { 21, 10}, - { 20, 10}, { 20, 10}, { 20, 10}, { 20, 10}, { 18, 10}, { 18, 10}, { 18, 10}, { 18, 10}, - {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, - {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, - { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, - { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, - { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, - { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, - { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, - {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, - {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, - {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 } -}; - -/* inter mean value, codes 000000000010111 ... 0000000100011xx */ -static vlc_code_t inter_mean_table_2[121] = { - { 61, 15}, - { 52, 15}, { 58, 15}, {-56, 15}, {-57, 15}, { 59, 15}, {-55, 15}, { 60, 15}, {-54, 15}, - { 53, 15}, {-62, 15}, {-60, 15}, {-59, 15}, {-58, 15}, { 57, 15}, { 56, 15}, {-53, 15}, - { 55, 15}, { 54, 15}, { 50, 14}, { 50, 14}, { 45, 14}, { 45, 14}, {-52, 14}, {-52, 14}, - {-51, 14}, {-51, 14}, {-50, 14}, {-50, 14}, { 46, 14}, { 46, 14}, {-49, 14}, {-49, 14}, - {-48, 14}, {-48, 14}, { 48, 14}, { 48, 14}, {-47, 14}, {-47, 14}, { 49, 14}, { 49, 14}, - {-45, 14}, {-45, 14}, {-44, 14}, {-44, 14}, { 47, 14}, { 47, 14}, { 51, 14}, { 51, 14}, - { 44, 14}, { 44, 14}, {-46, 14}, {-46, 14}, {-43, 13}, {-43, 13}, {-43, 13}, {-43, 13}, - {-42, 13}, {-42, 13}, {-42, 13}, {-42, 13}, {-41, 13}, {-41, 13}, {-41, 13}, {-41, 13}, - {-40, 13}, {-40, 13}, {-40, 13}, {-40, 13}, {-39, 13}, {-39, 13}, {-39, 13}, {-39, 13}, - {-38, 13}, {-38, 13}, {-38, 13}, {-38, 13}, {-37, 13}, {-37, 13}, {-37, 13}, {-37, 13}, - {-36, 13}, {-36, 13}, {-36, 13}, {-36, 13}, { 42, 13}, { 42, 13}, { 42, 13}, { 42, 13}, - { 36, 13}, { 36, 13}, { 36, 13}, { 36, 13}, { 43, 13}, { 43, 13}, { 43, 13}, { 43, 13}, - { 41, 13}, { 41, 13}, { 41, 13}, { 41, 13}, { 40, 13}, { 40, 13}, { 40, 13}, { 40, 13}, - { 35, 13}, { 35, 13}, { 35, 13}, { 35, 13}, { 39, 13}, { 39, 13}, { 39, 13}, { 39, 13}, - { 38, 13}, { 38, 13}, { 38, 13}, { 38, 13}, { 37, 13}, { 37, 13}, { 37, 13}, { 37, 13} -}; - -/* inter mean value, codes 000000000000100101 ... 0000000000101101xx */ -static vlc_code_t inter_mean_table_3[147] = { - {111, 18}, {102, 18}, { 99, 18}, - {-86, 18}, { 97, 18}, {-97, 18}, { 96, 18}, {-95, 18}, {-76, 18}, {-77, 18}, {-78, 18}, - {-85, 18}, {-80, 18}, {-81, 18}, { 89, 18}, { 90, 18}, {-84, 18}, {-89, 18}, { 80, 18}, - {-90, 18}, {-88, 18}, { 92, 18}, { 93, 18}, { 95, 18}, {-109,18}, {-79, 17}, {-79, 17}, - {-83, 17}, {-83, 17}, {-75, 17}, {-75, 17}, {-74, 17}, {-74, 17}, {-73, 17}, {-73, 17}, - {-72, 17}, {-72, 17}, { 87, 17}, { 87, 17}, { 86, 17}, { 86, 17}, { 75, 17}, { 75, 17}, - { 85, 17}, { 85, 17}, { 84, 17}, { 84, 17}, { 81, 17}, { 81, 17}, { 79, 17}, { 79, 17}, - { 74, 17}, { 74, 17}, { 72, 17}, { 72, 17}, { 82, 17}, { 82, 17}, { 78, 17}, { 78, 17}, - { 83, 17}, { 83, 17}, { 76, 17}, { 76, 17}, { 73, 17}, { 73, 17}, { 77, 17}, { 77, 17}, - { 70, 16}, { 70, 16}, { 70, 16}, { 70, 16}, { 69, 16}, { 69, 16}, { 69, 16}, { 69, 16}, - { 64, 16}, { 64, 16}, { 64, 16}, { 64, 16}, {-68, 16}, {-68, 16}, {-68, 16}, {-68, 16}, - {-66, 16}, {-66, 16}, {-66, 16}, {-66, 16}, { 68, 16}, { 68, 16}, { 68, 16}, { 68, 16}, - {-69, 16}, {-69, 16}, {-69, 16}, {-69, 16}, { 65, 16}, { 65, 16}, { 65, 16}, { 65, 16}, - { 71, 16}, { 71, 16}, { 71, 16}, { 71, 16}, {-70, 16}, {-70, 16}, {-70, 16}, {-70, 16}, - {-65, 16}, {-65, 16}, {-65, 16}, {-65, 16}, {-67, 16}, {-67, 16}, {-67, 16}, {-67, 16}, - {-63, 16}, {-63, 16}, {-63, 16}, {-63, 16}, {-71, 16}, {-71, 16}, {-71, 16}, {-71, 16}, - { 67, 16}, { 67, 16}, { 67, 16}, { 67, 16}, {-61, 16}, {-61, 16}, {-61, 16}, {-61, 16}, - {-64, 16}, {-64, 16}, {-64, 16}, {-64, 16}, { 63, 16}, { 63, 16}, { 63, 16}, { 63, 16}, - { 62, 16}, { 62, 16}, { 62, 16}, { 62, 16}, { 66, 16}, { 66, 16}, { 66, 16}, { 66, 16} -}; - -/* inter mean value, codes 00000000000001001001 ... 0000000000001001001x */ -static vlc_code_t inter_mean_table_4[75] = { - {142, 20}, {135, 20}, {125, 20}, {123, 20}, {122, 20}, {119, 20}, {117, 20}, - {113, 20}, {104, 20}, {103, 20}, {-120,20}, {-114,20}, {-108,20}, {-104,20}, {-102,20}, - {-101,20}, {-93, 20}, {-91, 19}, {-91, 19}, {-96, 19}, {-96, 19}, { 88, 19}, { 88, 19}, - { 91, 19}, { 91, 19}, { 94, 19}, { 94, 19}, {121, 19}, {121, 19}, {120, 19}, {120, 19}, - {-110,19}, {-110,19}, {118, 19}, {118, 19}, {115, 19}, {115, 19}, {114, 19}, {114, 19}, - {112, 19}, {112, 19}, {107, 19}, {107, 19}, {110, 19}, {110, 19}, {109, 19}, {109, 19}, - {108, 19}, {108, 19}, {-103,19}, {-103,19}, {106, 19}, {106, 19}, {105, 19}, {105, 19}, - {-100,19}, {-100,19}, {101, 19}, {101, 19}, {100, 19}, {100, 19}, {-99, 19}, {-99, 19}, - {-82, 19}, {-82, 19}, {-87, 19}, {-87, 19}, {-94, 19}, {-94, 19}, {-98, 19}, {-98, 19}, - { 98, 19}, { 98, 19}, {-92, 19}, {-92, 19} -}; - -/* inter mean value, codes 0000000000000000000000 ... 000000000000010010001x */ -static vlc_code_t inter_mean_table_5[292] = { - {255, 22}, {254, 22}, {253, 22}, {252, 22}, {251, 22}, {250, 22}, {249, 22}, {248, 22}, - {247, 22}, {246, 22}, {245, 22}, {244, 22}, {243, 22}, {242, 22}, {241, 22}, {240, 22}, - {239, 22}, {238, 22}, {237, 22}, {236, 22}, {235, 22}, {234, 22}, {233, 22}, {232, 22}, - {231, 22}, {230, 22}, {229, 22}, {228, 22}, {227, 22}, {226, 22}, {225, 22}, {224, 22}, - {223, 22}, {222, 22}, {221, 22}, {220, 22}, {219, 22}, {218, 22}, {217, 22}, {216, 22}, - {215, 22}, {214, 22}, {213, 22}, {212, 22}, {211, 22}, {210, 22}, {209, 22}, {208, 22}, - {207, 22}, {206, 22}, {205, 22}, {204, 22}, {203, 22}, {202, 22}, {201, 22}, {200, 22}, - {199, 22}, {198, 22}, {197, 22}, {196, 22}, {195, 22}, {194, 22}, {193, 22}, {192, 22}, - {191, 22}, {190, 22}, {189, 22}, {188, 22}, {187, 22}, {186, 22}, {185, 22}, {184, 22}, - {183, 22}, {182, 22}, {181, 22}, {180, 22}, {179, 22}, {178, 22}, {177, 22}, {176, 22}, - {175, 22}, {174, 22}, {173, 22}, {172, 22}, {171, 22}, {170, 22}, {169, 22}, {168, 22}, - {167, 22}, {166, 22}, {-256,22}, {164, 22}, {-211,22}, {162, 22}, {161, 22}, {160, 22}, - {-210,22}, {-168,22}, {157, 22}, {156, 22}, {155, 22}, {154, 22}, {153, 22}, {152, 22}, - {151, 22}, {150, 22}, {149, 22}, {148, 22}, {147, 22}, {146, 22}, {145, 22}, {144, 22}, - {143, 22}, {-208,22}, {141, 22}, {140, 22}, {139, 22}, {-200,22}, {137, 22}, {136, 22}, - {-198,22}, {134, 22}, {133, 22}, {-196,22}, {-201,22}, {130, 22}, {129, 22}, {128, 22}, - {127, 22}, {126, 22}, {-195,22}, {124, 22}, {-167,22}, {-166,22}, {-165,22}, {-164,22}, - {-163,22}, {-162,22}, {-161,22}, {-180,22}, {-160,22}, {-159,22}, {-158,22}, {-157,22}, - {-156,22}, {-155,22}, {-154,22}, {-153,22}, {-152,22}, {-151,22}, {-150,22}, {-149,22}, - {-148,22}, {-147,22}, {-146,22}, {-145,22}, {-144,22}, {-143,22}, {-142,22}, {-141,22}, - {-140,22}, {-139,22}, {-138,22}, {-137,22}, {-136,22}, {-135,22}, {-134,22}, {-133,22}, - {-132,22}, {-131,22}, {-130,22}, {-129,22}, {-126,22}, {-125,22}, {-124,22}, {-123,22}, - {-122,22}, {-121,22}, {-118,22}, {-116,22}, {-115,22}, {-113,22}, {-112,22}, {-107,22}, - {-106,22}, {-169,22}, {-170,22}, {-171,22}, {-172,22}, {-173,22}, {-174,22}, {-175,22}, - {-176,22}, {-177,22}, {-178,22}, {-187,22}, {-179,22}, {-181,22}, {-182,22}, {-183,22}, - {-184,22}, {-185,22}, {-186,22}, {-235,22}, {-188,22}, {-189,22}, {-190,22}, {-191,22}, - {-192,22}, {-193,22}, {-194,22}, {-197,22}, {-255,22}, {-254,22}, {-253,22}, {-252,22}, - {-251,22}, {-250,22}, {-249,22}, {-248,22}, {-247,22}, {-246,22}, {-245,22}, {-244,22}, - {-243,22}, {-242,22}, {-241,22}, {-240,22}, {-239,22}, {-238,22}, {-237,22}, {-232,22}, - {-236,22}, {-234,22}, {-233,22}, {-217,22}, {-231,22}, {-230,22}, {-229,22}, {-228,22}, - {-227,22}, {-226,22}, {-225,22}, {-224,22}, {-223,22}, {-222,22}, {-221,22}, {-220,22}, - {-219,22}, {-216,22}, {-202,22}, {-205,22}, {-215,22}, {-214,22}, {-213,22}, {-204,22}, - {-212,22}, {-209,22}, {-218,22}, {-199,22}, {-207,22}, {-206,22}, {165, 21}, {165, 21}, - {131, 21}, {131, 21}, {163, 21}, {163, 21}, {-203,21}, {-203,21}, {116, 21}, {116, 21}, - {159, 21}, {159, 21}, {138, 21}, {138, 21}, {158, 21}, {158, 21}, {-105,21}, {-105,21}, - {-111,21}, {-111,21}, {132, 21}, {132, 21}, {128, 21}, {128, 21}, {-127,21}, {-127,21}, - {-119,21}, {-119,21}, {-117,21}, {-117,21} -}; - - -static uint32_t get_bits (bit_buffer_t *bitbuf, int count) { - uint32_t result; - - /* avoid buffer overflow */ - if ((bitbuf->bitpos + 24) >= bitbuf->length) { - int i; - - /* load upto 24 bits of data on sub-byte offset */ - result = 0; - - for (i=(bitbuf->bitpos & ~0x7); i < bitbuf->length; i+=8) { - result |= bitbuf->buffer[i >> 3] << (24 + (bitbuf->bitpos - i)); - } - } else { - /* load 32 bits of data (byte-aligned) */ - result = BE_32 (&bitbuf->buffer[bitbuf->bitpos >> 3]); - - /* compensate for sub-byte offset */ - result <<= (bitbuf->bitpos & 0x7); - } - - /* flush num bits */ - bitbuf->bitpos += count; - - /* return num bits */ - return result >> (32 - count); -} - -/* - * Return next 32 bits (left aligned). - */ -static uint32_t get_bit_cache(bit_buffer_t *bitbuf) { - uint32_t result; - - /* avoid buffer overflow */ - if ((bitbuf->bitpos + 24) >= bitbuf->length) { - int i; - - /* load upto 24 bits of data on sub-byte offset */ - result = 0; - - for (i=(bitbuf->bitpos & ~0x7); i < bitbuf->length; i+=8) { - result |= bitbuf->buffer[i >> 3] << (24 + (bitbuf->bitpos - i)); - } - } else { - /* load 32 bits of data (byte-aligned) */ - result = BE_32 (&bitbuf->buffer[bitbuf->bitpos >> 3]); - - /* compensate for sub-byte offset */ - result <<= (bitbuf->bitpos & 0x7); - } - - return result; -} - -static int decode_svq1_block (bit_buffer_t *bitbuf, uint8_t *pixels, int pitch, int intra) { - uint32_t bit_cache; - vlc_code_t *vlc; - uint8_t *list[63]; - uint32_t *dst; - uint32_t *codebook; - int entries[6]; - int i, j, m, n; - int mean, stages; - int x, y, width, height, level; - uint32_t n1, n2, n3, n4; - - /* initialize list for breadth first processing of vectors */ - list[0] = pixels; - - /* recursively process vector */ - for (i=0, m=1, n=1, level=5; i < n; i++) { - for (; level > 0; i++) { - - /* process next depth */ - if (i == m) { - m = n; - - if (--level == 0) - break; - } - - /* divide block if next bit set */ - if (get_bits (bitbuf, 1) == 0) - break; - - /* add child nodes */ - list[n++] = list[i]; - list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1)); - } - - /* destination address and vector size */ - dst = (uint32_t *) list[i]; - width = 1 << ((4 + level) /2); - height = 1 << ((3 + level) /2); - - /* get number of stages (-1 skips vector, 0 for mean only) */ - bit_cache = get_bit_cache (bitbuf); - - if (intra) - vlc = &intra_vector_tables[level][bit_cache >> (32 - 7)]; - else - vlc = &inter_vector_tables[level][bit_cache >> (32 - 6)]; - - /* flush bits */ - stages = vlc->value; - bitbuf->bitpos += vlc->length; - - if (stages == -1) { - if (intra) { - for (y=0; y < height; y++) { - memset (&dst[y*(pitch / 4)], 0, width); - } - } - continue; /* skip vector */ - } - - if ((stages > 0) && (level >= 4)) { - return -1; /* invalid vector */ - } - - /* get mean value for vector */ - bit_cache = get_bit_cache (bitbuf); - - if (intra) { - if (bit_cache >= 0x25000000) - vlc = &intra_mean_table_0[(bit_cache >> (32 - 8)) - 37]; - else if (bit_cache >= 0x03400000) - vlc = &intra_mean_table_1[(bit_cache >> (32 - 10)) - 13]; - else if (bit_cache >= 0x00040000) - vlc = &intra_mean_table_2[(bit_cache >> (32 - 14)) - 1]; - else - vlc = &intra_mean_table_3[bit_cache >> (32 - 20)]; - } else { - if (bit_cache >= 0x0B000000) - vlc = &inter_mean_table_0[(bit_cache >> (32 - 8)) - 11]; - else if (bit_cache >= 0x01200000) - vlc = &inter_mean_table_1[(bit_cache >> (32 - 12)) - 18]; - else if (bit_cache >= 0x002E0000) - vlc = &inter_mean_table_2[(bit_cache >> (32 - 15)) - 23]; - else if (bit_cache >= 0x00094000) - vlc = &inter_mean_table_3[(bit_cache >> (32 - 18)) - 37]; - else if (bit_cache >= 0x00049000) - vlc = &inter_mean_table_4[(bit_cache >> (32 - 20)) - 73]; - else - vlc = &inter_mean_table_5[bit_cache >> (32 - 22)]; - } - - /* flush bits */ - mean = vlc->value; - bitbuf->bitpos += vlc->length; - - if (intra && stages == 0) { - for (y=0; y < height; y++) { - memset (&dst[y*(pitch / 4)], mean, width); - } - } else { - codebook = (uint32_t *) (intra ? intra_codebooks[level] : inter_codebooks[level]); - bit_cache = get_bits (bitbuf, 4*stages); - - /* calculate codebook entries for this vector */ - for (j=0; j < stages; j++) { - entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1); - } - - mean -= (stages * 128); - n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF); - - for (y=0; y < height; y++) { - for (x=0; x < (width / 4); x++, codebook++) { - if (intra) { - n1 = n4; - n2 = n4; - } else { - n3 = dst[x]; - - /* add mean value to vector */ - n1 = ((n3 & 0xFF00FF00) >> 8) + n4; - n2 = (n3 & 0x00FF00FF) + n4; - } - - /* add codebook entries to vector */ - for (j=0; j < stages; j++) { - n3 = codebook[entries[j]] ^ 0x80808080; - n1 += ((n3 & 0xFF00FF00) >> 8); - n2 += (n3 & 0x00FF00FF); - } - - /* clip to [0..255] */ - if (n1 & 0xFF00FF00) { - n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; - n1 += 0x7F007F00; - n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; - n1 &= (n3 & 0x00FF00FF); - } - - if (n2 & 0xFF00FF00) { - n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; - n2 += 0x7F007F00; - n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001; - n2 &= (n3 & 0x00FF00FF); - } - - /* store result */ - dst[x] = (n1 << 8) | n2; - } - - dst += (pitch / 4); - } - } - } - - return 0; -} - -static int decode_motion_vector (bit_buffer_t *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) { - uint32_t bit_cache; - vlc_code_t *vlc; - int diff, sign; - int i; - - for (i=0; i < 2; i++) { - - /* get motion code */ - bit_cache = get_bit_cache (bitbuf); - - if (!(bit_cache & 0xFFE00000)) - return -1; /* invalid vlc code */ - - if (bit_cache & 0x80000000) { - diff = 0; - - /* flush bit */ - bitbuf->bitpos++; - - } else { - if (bit_cache >= 0x06000000) { - vlc = &motion_table_0[(bit_cache >> (32 - 7)) - 3]; - } else { - vlc = &motion_table_1[(bit_cache >> (32 - 12)) - 2]; - } - - /* decode motion vector differential */ - sign = (int) (bit_cache << (vlc->length - 1)) >> 31; - diff = (vlc->value ^ sign) - sign; - - /* flush bits */ - bitbuf->bitpos += vlc->length; - } - - /* add median of motion vector predictors and clip result */ - if (i == 1) - mv->y = ((diff + MEDIAN(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26; - else - mv->x = ((diff + MEDIAN(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26; - } - - return 0; -} - -static void clip_motion_vector (int x, int y, int width, int height, svq1_pmv_t *mv) { - - if (mv->x < -2*x) - mv->x = -2*x; - else if (mv->x > 2*(width - x)) - mv->x = 2*(width - x); - - if (mv->y < -2*y) - mv->y = -2*y; - else if (mv->y > 2*(height - y)) - mv->y = 2*(height - y); -} - -static void skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) { - uint8_t *src; - uint8_t *dst; - int i; - - src = &previous[x + y*pitch]; - dst = current; - - for (i=0; i < 16; i++) { - memcpy (dst, src, 16); - src += pitch; - dst += pitch; - } -} - -static int motion_inter_block (bit_buffer_t *bitbuf, - uint8_t *current, uint8_t *previous, int pitch, - svq1_pmv_t *motion, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height) { - uint8_t *src; - uint8_t *dst; - svq1_pmv_t mv; - svq1_pmv_t *pmv[3]; - int sx, sy; - int result; - - /* predict and decode motion vector */ - pmv[0] = &motion[0]; - pmv[1] = &motion[(x / 8) + 2]; - pmv[2] = &motion[(x / 8) + 4]; - - if (y == 0) { - pmv[1] = pmv[0]; - pmv[2] = pmv[0]; - } - - result = decode_motion_vector (bitbuf, &mv, pmv); - - if (result != 0) - return result; - - motion[0].x = mv.x; - motion[0].y = mv.y; - motion[(x / 8) + 2].x = mv.x; - motion[(x / 8) + 2].y = mv.y; - motion[(x / 8) + 3].x = mv.x; - motion[(x / 8) + 3].y = mv.y; - - /* clip motion vector to frame border */ - clip_motion_vector (x, y, (width - 16), (height - 16), &mv); - - src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch]; - dst = current; - - /* form prediction */ - if (mv.y & 0x1) { - if (mv.x & 0x1) { - for (sy=0; sy < 16; sy++) { - for (sx=0; sx < 16; sx++) { - dst[sx] = (src[sx] + src[sx + 1] + src[sx + pitch] + src[sx + pitch + 1] + 2) >> 2; - } - src += pitch; - dst += pitch; - } - } else { - for (sy=0; sy < 16; sy++) { - for (sx=0; sx < 16; sx++) { - dst[sx] = (src[sx] + src[sx + pitch] + 1) >> 1; - } - src += pitch; - dst += pitch; - } - } - } else { - if (mv.x & 0x1) { - for (sy=0; sy < 16; sy++) { - for (sx=0; sx < 16; sx++) { - dst[sx] = (src[sx] + src[sx + 1] + 1) >> 1; - } - src += pitch; - dst += pitch; - } - } else { - for (sy=0; sy < 16; sy++) { - memcpy (dst, src, 16); - src += pitch; - dst += pitch; - } - } - } - - return 0; -} - -static int motion_inter_4v_block (bit_buffer_t *bitbuf, - uint8_t *current, uint8_t *previous, int pitch, - svq1_pmv_t *motion, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height) { - uint8_t *src; - uint8_t *dst; - svq1_pmv_t mv; - svq1_pmv_t *pmv[4]; - int sx, sy; - int i, result; - - /* predict and decode motion vector (0) */ - pmv[0] = &motion[0]; - pmv[1] = &motion[(x / 8) + 2]; - pmv[2] = &motion[(x / 8) + 4]; - - if (y == 0) { - pmv[1] = pmv[0]; - pmv[2] = pmv[0]; - } - - result = decode_motion_vector (bitbuf, &mv, pmv); - - if (result != 0) - return result; - - /* predict and decode motion vector (1) */ - pmv[0] = &mv; - pmv[1] = &motion[(x / 8) + 3]; - - if (y == 0) { - pmv[1] = pmv[0]; - pmv[2] = pmv[0]; - } - - result = decode_motion_vector (bitbuf, &motion[0], pmv); - - if (result != 0) - return result; - - /* predict and decode motion vector (2) */ - pmv[1] = &motion[0]; - pmv[2] = &motion[(x / 8) + 1]; - - result = decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv); - - if (result != 0) - return result; - - /* predict and decode motion vector (3) */ - pmv[2] = &motion[(x / 8) + 2]; - pmv[3] = &motion[(x / 8) + 3]; - - result = decode_motion_vector (bitbuf, pmv[3], pmv); - - if (result != 0) - return result; - - /* clip motion vectors to frame border */ - clip_motion_vector (x, y, (width - 8), (height - 8), pmv[0]); - clip_motion_vector ((x + 8), y, (width - 8), (height - 8), pmv[1]); - clip_motion_vector (x, (y + 8), (width - 8), (height - 8), pmv[2]); - clip_motion_vector ((x + 8), (y + 8), (width - 8), (height - 8), pmv[3]); - - /* form predictions */ - for (i=0; i < 4; i++) { - src = &previous[(x + (pmv[i]->x >> 1)) + (y + (pmv[i]->y >> 1))*pitch]; - dst = current; - - if (pmv[i]->y & 0x1) { - if (pmv[i]->x & 0x1) { - for (sy=0; sy < 8; sy++) { - for (sx=0; sx < 8; sx++) { - dst[sx] = (src[sx] + src[sx + 1] + src[sx + pitch] + src[sx + pitch + 1] + 2) >> 2; - } - src += pitch; - dst += pitch; - } - } else { - for (sy=0; sy < 8; sy++) { - for (sx=0; sx < 8; sx++) { - dst[sx] = (src[sx] + src[sx + pitch] + 1) >> 1; - } - src += pitch; - dst += pitch; - } - } - } else { - if (pmv[i]->x & 0x1) { - for (sy=0; sy < 8; sy++) { - for (sx=0; sx < 8; sx++) { - dst[sx] = (src[sx] + src[sx + 1] + 1) >> 1; - } - src += pitch; - dst += pitch; - } - } else { - for (sy=0; sy < 8; sy++) { - memcpy (dst, src, 8); - src += pitch; - dst += pitch; - } - } - } - - /* select next block */ - if (i & 1) { - current += 8*(pitch - 1); - previous += 8*(pitch - 1); - } else { - current += 8; - previous += 8; - } - } - - return 0; -} - -static int decode_delta_block (bit_buffer_t *bitbuf, - uint8_t *current, uint8_t *previous, int pitch, - svq1_pmv_t *motion, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height) { - uint32_t bit_cache; - uint32_t block_type; - int result = 0; - - /* get block type */ - bit_cache = get_bit_cache (bitbuf); - - bit_cache >>= (32 - 3); - block_type = block_type_table[bit_cache].value; - bitbuf->bitpos += block_type_table[bit_cache].length; - - /* reset motion vectors */ - if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) { - motion[0].x = 0; - motion[0].y = 0; - motion[(x / 8) + 2].x = 0; - motion[(x / 8) + 2].y = 0; - motion[(x / 8) + 3].x = 0; - motion[(x / 8) + 3].y = 0; - } - - switch (block_type) { - case SVQ1_BLOCK_SKIP: - skip_block (current, previous, pitch, x, y); - break; - - case SVQ1_BLOCK_INTER: - result = motion_inter_block (bitbuf, current, previous, pitch, motion, x, y, width, height); - - if (result != 0) - break; - - result = decode_svq1_block (bitbuf, current, pitch, 0); - break; - - case SVQ1_BLOCK_INTER_4V: - result = motion_inter_4v_block (bitbuf, current, previous, pitch, motion, x, y, width, height); - - if (result != 0) - break; - - result = decode_svq1_block (bitbuf, current, pitch, 0); - break; - - case SVQ1_BLOCK_INTRA: - result = decode_svq1_block (bitbuf, current, pitch, 1); - break; - } - - return result; -} - -static int decode_frame_header (bit_buffer_t *bitbuf, svq1_t *svq1) { - int frame_size_code; - - /* unknown field */ - get_bits (bitbuf, 8); - - /* frame type */ - svq1->frame_type = get_bits (bitbuf, 2); - - if (svq1->frame_type == 3) - return -1; - - if (svq1->frame_type == SVQ1_FRAME_INTRA) { - - /* unknown fields */ - if (svq1->frame_code == 0x50 || svq1->frame_code == 0x60) { - get_bits (bitbuf, 16); - } - - if ((svq1->frame_code ^ 0x10) >= 0x50) { - bitbuf->bitpos += 8*get_bits (bitbuf, 8); - } - - get_bits (bitbuf, 2); - get_bits (bitbuf, 2); - get_bits (bitbuf, 1); - - /* load frame size */ - frame_size_code = get_bits (bitbuf, 3); - - if (frame_size_code == 7) { - /* load width, height (12 bits each) */ - svq1->frame_width = get_bits (bitbuf, 12); - svq1->frame_height = get_bits (bitbuf, 12); - - if (!svq1->frame_width || !svq1->frame_height) - return -1; - } else { - /* get width, height from table */ - svq1->frame_width = frame_size_table[frame_size_code].width; - svq1->frame_height = frame_size_table[frame_size_code].height; - } - } - - /* unknown fields */ - if (get_bits (bitbuf, 1) == 1) { - get_bits (bitbuf, 1); - get_bits (bitbuf, 1); - - if (get_bits (bitbuf, 2) != 0) - return -1; - } - - if (get_bits (bitbuf, 1) == 1) { - get_bits (bitbuf, 1); - get_bits (bitbuf, 4); - get_bits (bitbuf, 1); - get_bits (bitbuf, 2); - - while (get_bits (bitbuf, 1) == 1) { - get_bits (bitbuf, 8); - } - } - - return 0; -} - -static int svq1_decode_frame (svq1_t *svq1, uint8_t *buffer, int length) { - bit_buffer_t bitbuf; - uint8_t *current, *previous; - int result, i, x, y, width, height; - int luma_size, chroma_size; - - /* initialize bit buffer */ - bitbuf.buffer = buffer; - bitbuf.bitpos = 0; - bitbuf.length = 8*length; - - /* decode frame header */ - svq1->frame_code = get_bits (&bitbuf, 22); - - if ((svq1->frame_code & ~0x70) || !(svq1->frame_code & 0x60)) - return -1; - - /* swap some header bytes (why?) */ - if (svq1->frame_code != 0x20) { - uint32_t *src = (uint32_t *) (buffer + 4); - - for (i=0; i < 4; i++) { - src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; - } - } - - result = decode_frame_header (&bitbuf, svq1); - - if (result != 0 || bitbuf.bitpos > bitbuf.length) - return result; - - /* check frame size (changed?) */ - if (((svq1->frame_width + 3) & ~0x3) != svq1->width || - ((svq1->frame_height + 3) & ~0x3) != svq1->height) { - - /* free current buffers */ - free (svq1->current); - free (svq1->previous); - free (svq1->motion); - - svq1->width = (svq1->frame_width + 3) & ~0x3; - svq1->height = (svq1->frame_height + 3) & ~0x3; - svq1->ratio = (double)svq1->width/(double)svq1->height; - svq1->luma_width = (svq1->width + 15) & ~0xF; - svq1->luma_height = (svq1->height + 15) & ~0xF; - svq1->chroma_width = ((svq1->width / 4) + 15) & ~0xF; - svq1->chroma_height = ((svq1->height / 4) + 15) & ~0xF; - - /* allocate new pixel and motion buffers for updated frame size */ - luma_size = svq1->luma_width * svq1->luma_height; - chroma_size = svq1->chroma_width * svq1->chroma_height; - - svq1->motion = (svq1_pmv_t *) malloc (((svq1->luma_width / 8) + 3) * sizeof(svq1_pmv_t)); - svq1->current = (uint8_t *) malloc (luma_size + 2*chroma_size); - svq1->previous = (uint8_t *) malloc (luma_size + 2*chroma_size); - svq1->offsets[0] = 0; - svq1->offsets[1] = luma_size; - svq1->offsets[2] = luma_size + chroma_size; - - for (i=0; i < 3; i++) { - svq1->base[i] = svq1->current + svq1->offsets[i]; - } - - svq1->reference_frame = 0; - } - - /* delta frame requires reference frame */ - if (svq1->frame_type != SVQ1_FRAME_INTRA && !svq1->reference_frame) - return -1; - - /* decode y, u and v components */ - for (i=0; i < 3; i++) { - if (i == 0) { - width = svq1->luma_width; - height = svq1->luma_height; - } else { - width = svq1->chroma_width; - height = svq1->chroma_height; - } - - current = svq1->current + svq1->offsets[i]; - previous = svq1->previous + svq1->offsets[i]; - - if (svq1->frame_type == SVQ1_FRAME_INTRA) { - /* keyframe */ - for (y=0; y < height; y+=16) { - for (x=0; x < width; x+=16) { - result = decode_svq1_block (&bitbuf, ¤t[x], width, 1); - - if (result != 0 || bitbuf.bitpos > bitbuf.length) - return result; - } - - current += 16*width; - } - } else { - /* delta frame */ - memset (svq1->motion, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t)); - - for (y=0; y < height; y+=16) { - for (x=0; x < width; x+=16) { - result = decode_delta_block (&bitbuf, ¤t[x], previous, - width, svq1->motion, x, y, width, height); - - if (result != 0 || bitbuf.bitpos > bitbuf.length) - return result; - } - - svq1->motion[0].x = 0; - svq1->motion[0].y = 0; - - current += 16*width; - } - } - } - - /* update pixel buffers for frame copy */ - for (i=0; i < 3; i++) { - svq1->base[i] = svq1->current + svq1->offsets[i]; - } - - /* update backward reference frame */ - if (svq1->frame_type != SVQ1_FRAME_DROPPABLE) { - uint8_t *tmp = svq1->previous; - svq1->previous = svq1->current; - svq1->current = tmp; - svq1->reference_frame = 1; - } - - return 0; -} - -static void svq1dec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { - svq1dec_decoder_t *this = (svq1dec_decoder_t *) this_gen; - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - this->stream->video_out->open (this->stream->video_out, this->stream); - this->decoder_ok = 1; - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Sorenson Video 1"); - - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - vo_frame_t *img; - int result; - - result = svq1_decode_frame (this->svq1, this->buf, this->size); - - if (this->svq1->width > 0 && this->svq1->height > 0) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - this->svq1->width, - this->svq1->height, - this->svq1->ratio, - XINE_IMGFMT_YV12, - VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = (result != 0); - - if (result == 0) { - yuv9_to_yv12 (this->svq1->base[0], this->svq1->luma_width, - img->base[0], img->pitches[0], - this->svq1->base[1], this->svq1->chroma_width, - img->base[1], img->pitches[1], - this->svq1->base[2], this->svq1->chroma_width, - img->base[2], img->pitches[2], - this->svq1->width, this->svq1->height); - } - - img->draw(img, this->stream); - img->free(img); - } - - this->size = 0; - } - } -} - -static void svq1dec_flush (video_decoder_t *this_gen) { -} - -static void svq1dec_reset (video_decoder_t *this_gen) { - svq1dec_decoder_t *this = (svq1dec_decoder_t *) this_gen; - - if (this->svq1) { - this->svq1->reference_frame = 0; - } - - this->size = 0; -} - -static void svq1dec_discontinuity (video_decoder_t *this_gen) { -} - -static void svq1dec_dispose (video_decoder_t *this_gen) { - - svq1dec_decoder_t *this = (svq1dec_decoder_t *) this_gen; - - if (this->svq1) { - free (this->svq1->current); - free (this->svq1->previous); - free (this->svq1->motion); - free (this->svq1); - this->svq1 = NULL; - } - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - svq1dec_decoder_t *this ; - - this = (svq1dec_decoder_t *) xine_xmalloc (sizeof (svq1dec_decoder_t)); - - this->video_decoder.decode_data = svq1dec_decode_data; - this->video_decoder.flush = svq1dec_flush; - this->video_decoder.reset = svq1dec_reset; - this->video_decoder.discontinuity = svq1dec_discontinuity; - this->video_decoder.dispose = svq1dec_dispose; - this->size = 0; - - this->stream = stream; - this->class = (svq1_class_t *) class_gen; - - this->svq1 = (svq1_t *) xine_xmalloc (sizeof(svq1_t)); - - this->decoder_ok = 0; - this->buf = NULL; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "SVQ1"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Sorenson Video v1 decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - svq1_class_t *this; - - this = (svq1_class_t *) xine_xmalloc (sizeof (svq1_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* - * exported plugin catalog entry - */ - -static uint32_t video_types[] = { - BUF_VIDEO_SORENSON_V1, - 0 - }; - -static decoder_info_t dec_info_video = { - video_types, /* supported types */ - 6 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "svq1", XINE_VERSION_CODE, &dec_info_video, init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/libxinevdec/svq1_codebooks.h b/src/libxinevdec/svq1_codebooks.h deleted file mode 100644 index 062ed2721..000000000 --- a/src/libxinevdec/svq1_codebooks.h +++ /dev/null @@ -1,1506 +0,0 @@ -/* - * Copyright (C) 2002-2003 the xine project - * - * This file is part of xine, a unix video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * $Id: svq1_codebooks.h,v 1.2 2003/12/09 00:02:34 f1rmb Exp $ - */ - -#include <inttypes.h> - - -/* 6x16-entry codebook for inter-coded 4x2 vectors */ -static int8_t inter_codebook_4x2[768] = { - 7, 2, -6, -7, 7, 3, -3, -4, -7, -2, 7, 8, -8, -4, 3, 4, - 19, 17, 9, 3,-14,-16,-12, -8,-18,-16, -8, -3, 11, 14, 12, 8, - 7,-16,-10, 20, 7,-17,-10, 20, -6, 18, 8,-21, -7, 18, 9,-20, - 25, 3,-20,-14, 29, 7,-18,-13,-29, -4, 21, 14,-31, -6, 20, 14, - -19,-26,-28,-24, 31, 32, 22, 10, 15, 24, 31, 28,-32,-32,-22,-13, - 2, -8,-23,-26, -9, 3, 27, 35, 3, 11, 21, 21, 8, -4,-27,-34, - -30,-31, 12, 47,-29,-30, 13, 47, 38, 30,-17,-46, 34, 26,-19,-46, - -42,-50,-51,-43, 34, 48, 55, 48, 48, 54, 51, 42,-44,-52,-53,-47, - 4, 5, 0, -6, -2, -2, 0, 1,-11, -6, -1, -2, 1, 8, 9, 1, - 0, 1, -6, 5, 8, 1,-12, 2, 7,-14, -7, 8, 5, -8, 0, 8, - 1, 4, 11, 8,-12, -8, 0, -5, -1, 1, 0, 4,-15, -8, 3, 16, - 17, 8, -4, -6, 9, -4,-13, -8, 2, 6, 1,-18, -1, 11, 11,-12, - 6, 0, 2, 0, 14, 6, -7,-21, 1, -1,-13,-20, 1, 1, 10, 21, - -22, -5, 7, 13,-11, -1, 4, 12, -7, 0, 14, 19, -4, 3, -5,-19, - -26,-14, 10, 15, 18, 4, -6, -2, 25, 19, -5,-18,-20, -7, 4, 2, - -13, -6, -1, -4, 25, 37, -2,-35, 5, 4, 1, 1,-21,-36, 2, 43, - 2, -2, -1, 3, 8, -2, -6, -1, -2, -3, 2, 12, -5, -2, -2, -1, - -3, -1, -1, -5, -1, 7, 8, -2, 2, 7, 5, -3, 1, 1, -3, -8, - -3, -1, -3, -2, -2, -3, 2, 13, 15, 0,-11, -6, 3, 0, 0, 0, - -6, -9, -5, -4, 18, 4, 1, 3, 12, 3, 0, 4,-16, -3, 3, -3, - -17, 3, 18, 2, -1, -3, -1, -1, -6, 16, -8, 0, -9, 14, -7, 0, - 3,-13, 14, -5, 3,-13, 14, -4, -7, 20, 14,-23, 8, -7, -8, 4, - 8,-15,-19, 16,-10, 13, 11, -3, 9, -1, 1, 26, 5,-15,-27, 2, - -20, 7, 16, -4,-40, 9, 31, 1, 26,-12,-30, -7, 40, -2,-19, 4, - 6, 0, 0, 0, -6, -2, 1, 2, 0, -1, 0, -6, 9, 0, -2, -1, - -7, 8, 2, -3, -1, 2, -3, 2, 7, -4, -2, 4, 2, 0, 0, -6, - -3, -2, 9, 2, -2, -1, 0, -4, -3, -3, 0, -3, -6, 2, 10, 4, - 3, 0,-10, 8, 0, 0, -4, 4, -1, 1, 4, 2, 3, -7, -9, 7, - 2, 1, -9, -4, -1, 12, 0, 0, 3, -1, 7, -4, 3,-14, 4, 2, - -12, -9, 1, 11, 2, 5, 1, 0, 3, 1, 0, 2, 0, 8, 6,-19, - -6,-10, -7, -4, 9, 7, 5, 7, 6, 21, 3, -3,-11, -9, -5, -2, - -4, -9,-16, -1, -2, -5, 1, 36, 8, 11, 19, 0, 2, 5, -4,-41, - -1, -1, -2, -1, -2, -2, 1, 6, 0, 4, 1, -8, 1, 1, 1, 0, - -2, -3, 4, 0, 2, -1, 3, -3, 1, 3, -4, 1, -1, 3, 0, -5, - 3, 4, 2, 3, -2, -3, -6, -1, -2, -3, -2, 2, -4, 8, 1, 0, - -7, 4, 2, 6, -7, -1, 1, 0, -2, 2, -4, 1, 8, -6, 2, -1, - -6, 2, 0, 2, 5, 4, -8, -1, -1,-11, 0, 9, 0, -2, 2, 2, - 17, -5, -4, -1, -1, -4, -2, -2, 0,-13, 9, -3, -1, 12, -7, 2, - 0, -2, -5, 2, -7, -5, 20, -3, 7, 7, -1,-30, 3, 5, 8, 1, - -6, 3, -1, -4, 2, -2,-11, 18, 0, -7, 3, 14, 20, -3,-18, -9, - 7, -2, 0, -1, -2, 0, 0, -1, -4, -1, 1, 0, -2, 2, 0, 4, - 1, -3, 2, 1, 3, 1, -5, 1, -3, 0, -1, -2, 7, 1, 0, -3, - 2, 5, 0, -2, 2, -5, -1, 1, -1, -2, 4, -1, 0, -3, 5, 0, - 0, 3, -1, -2, -4, 1, 5, -1, -1, 0, -1, 9, -1, -2, -1, -1, - -2, 5, 5, -1, -2, 2, -3, -2, 1, 2,-11, 1, 2, 1, 3, 2, - 2,-10, -1, -2, 4, 2, 4, 1, 4, 5, -5, 1, 0, 6,-11, 1, - 1, 0, 6, 6, 0, 2, 1,-15, 7, 3, 5, 9,-30, 2, 2, 2, - -34, 1, 9, 2, 5, 8, 8, 2, 7, 2, 6, 6, 2,-27, 1, 4 -}; - -/* 6x16-entry codebook for inter-coded 4x4 vectors */ -static int8_t inter_codebook_4x4[1536] = { - 4, 0, -6, -7, -4, -8,-13, -9, -8, -8, -1, 6, -2, 5, 22, 27, - -16, -7, 11, 10,-18, -7, 13, 10,-15, -4, 12, 8, -9, -1, 9, 5, - -2, 2, 15,-16, -3, 2, 19,-19, -3, 2, 19,-19, -2, 3, 15,-14, - 17, 22, 22, 16, -6, -7, -5, -2,-12,-16,-16,-12, 1, 1, -1, -3, - 11,-17, 0, 8, 14,-21, -1, 9, 14,-21, -2, 8, 11,-16, -2, 6, - 7, -2,-16, 11, 9, -2,-21, 14, 10, -1,-22, 14, 8, -1,-18, 10, - -10, 16, 3, -9,-13, 20, 4,-11,-14, 21, 4,-10,-11, 16, 3, -8, - 11, 4, -9, -9, 15, 6,-12,-14, 17, 8,-12,-14, 16, 10, -7,-11, - 4, 10, 14, 13, -1, 7, 15, 16,-12, -7, 3, 8,-20,-23,-18,-10, - -10,-18,-26,-25, 4, 1, -6,-11, 13, 15, 11, 3, 12, 15, 13, 8, - -16,-19,-16,-11, 7, 12, 15, 11, 11, 16, 16, 11, -6, -9,-11,-10, - 18, 19, 12, 5, 18, 16, 5, -4, 6, 0,-10,-15, -9,-17,-23,-22, - -10,-14, -1, 21,-11,-17, 0, 29,-11,-16, 1, 30,-10,-14, 0, 23, - -16,-17,-12, -6,-19,-19,-14, -7, -3, -1, 1, 2, 27, 35, 29, 19, - -37, -8, 23, 23,-42, -9, 28, 29,-43,-10, 26, 28,-38,-11, 19, 22, - 32, 16,-16,-33, 39, 20,-18,-37, 38, 19,-19,-38, 32, 15,-17,-34, - 24, 9, -6, -4, -1,-10, -6, 3, -8, -9, -1, 3, 3, 7, 2, -6, - -1, -3, -1, 0, -1, 4, 2, -7, -3, 11, 3,-16, 1, 20, 9,-18, - -3, -8, 6, 12, -5,-10, 7, 13, -6, -9, 5, 7, -5, -5, 2, -1, - -8, 12, -3, -1,-10, 15, -3, 1,-11, 13, -4, 1,-11, 8, -3, 2, - 9, 6, -5,-12, 3, 0, -8,-13, -4, -4, -1, -1, -4, 1, 15, 18, - 9, 13, 14, 12, 4, 3, -1, -2, -2, -5, -8, -5, -7,-11, -9, -4, - 7, -5, -7, -4, 14, -2, -7, -4, 17, 0, -8, -5, 15, 1, -7, -5, - -10, -1, 6, 4,-15, -9, 2, 4, 2, -1, -3, 0, 25, 13, -8,-10, - 7, 11, -3,-16, 7, 11, -3,-15, 6, 7, -2, -9, 4, 2, -3, -5, - -7, -1, -1, 0, -9, -2, 2, 6,-12, -4, 6, 14,-13, -6, 8, 19, - -18,-18,-11, -5, -3, 0, 3, 4, 6, 8, 6, 6, 6, 6, 6, 6, - -5, 3, 13,-10, -6, 1, 15, -9, -6, -3, 15, -6, -6, -6, 10, -3, - 9, 1, -9, -9, 11, 9, 6, 5, 0, 3, 8, 7,-15,-14, -6, -5, - -11, -6, 11, 19, -2, -5, -9, -8, 6, 2, -9,-10, 6, 5, 4, 5, - -7, -3, 8, 15, -1, 3, 10, 15, 5, 5, -1, -2, 4, -2,-21,-25, - 6, -6, -6, 5, 8, -9, -7, 9, 8,-12, -7, 13, 4,-14, -7, 14, - -4, -3, 1, 1, -3, -5, -2, -3, 7, 0, -2, -4, 20, 7, -4, -4, - -3,-20, -6, 10, 6, 0, 0, 1, 5, 8, 5, -1, -3, 0, 0, -2, - 13, 6, -1, 2, 5, 3, 2, 3, -3, 0, 3, 0,-16, -8, -2, -5, - -2, -7, -6, 0, -3, -6, -3, 1, -5, -1, 2, -1, -1, 12, 16, 5, - -7, 1, 9, 8,-10, -2, 5, 3, -6, 2, 7, 3, -4, 0, -1, -7, - 3, 4, -9,-24, 0, 2, 6, 3, -1, -1, 4, 7, 5, 3, -1, -2, - 3, 6, -9, 2, 1, 6,-13, 1, 1, 8,-10, 2, 1, 8, -7, 1, - -3, -3, 2, 22, -2, -3, -5, 12, -2, -3,-10, 2, -3, -1, -4, 2, - 11, 12, 8, 2, -5, -5, -5, -8, -6, -4, 0, -3, -2, -1, 3, 3, - 12, -6, -2, -1, 12, -8, -2, -2, 9, -7, 0, -3, 4, -6, 2, -2, - -19, 1, 12, -3, -4, 4, 5, -4, 6, 1, -2, -1, 4, -4, -2, 7, - -3, -4, -7, -8, -4, -4, -2, 0, -1, 2, 14, 16, -4, -2, 4, 4, - -1, 7, 2, -5, -2, 0, -1, 1, 4, -3, -1, 13, 6,-12,-14, 8, - -1, 5, 4, -5, -2, 5, 3, -9, -2, 7, 4,-12, -1, 7, 4, -9, - -6, -3, 1, 1, 11, 11, 0, -6, 6, 4, -2, -7,-12,-10, 3, 10, - -2, -3, -3, -2, 6, 11, 14, 10, -9,-11,-10,-10, 2, 2, 3, 2, - -7, -5, -7, -1, -1, 2, 0, 7, -1, 1, 0, 9, 3, 4, -5, -1, - 10, -1,-15, -1, 4, 1, -5, 2, -3, 1, -1, 1, -3, 1, 4, 4, - 2, -1, 4, 10, 6, 2, -1, 0, 2, 2, -7,-12, -4, 2, 0, -3, - -1, -4, -1, -8, 3, -1, 2, -9, 4, 0, 5, -5, 2, 0, 8, 3, - 3, 2, 1, 1, 4, -2, 0, 3, 2, -1, 4, 1, 0, 6, -1,-25, - -1, -2, -2, -4, -3, 0, -1, -4, -1, -1, -4, 2, 0, -6, 2, 25, - -11, -1, 5, 0, 7, 0, -2, 2, 10, -1, -3, 4, -5, -5, -2, -1, - 0, 6, 3, -1, -2, -1, -1, 1, -1, -7,-12, -5, 8, 6, 2, 4, - 2, 6, -1, -6, 9, 10, -1, -4, 1, 0, -4, 0, 3, -2, -9, -5, - -4, 3, 4, 0, -4, 3, 3, 0,-11, 0, 3, 2,-11, 3, 7, 2, - 2, -4, 7, 3, 1, -8, 7, 1, -1,-12, 4, 1, 3, -9, 2, 2, - 2, -2, -2, 9,-17, -3, 3, 1, -4, 7, 1, -6, 5, 4, -1, 3, - -1, 2, 0, -4, -7, 8, 12, -1, -2, 5, 4, -5, 3, -5, -8, -2, - 0, 0, -5, -2, -2, -8, 3, 27, -1, -4, -3, 6, -3, 1, -2, -7, - 4, 4, 1, -1, -7,-10, -7, -3, 10, 10, 5, 3, -2, -2, -4, -3, - 0, 1, 5, 7, 4, -2,-16,-20, 0, 4, 7, 8, 2, 0, -2, -1, - -2, 1, 3, 17, -3, 1, -2, -1, -1, -2, -1, -2, -1, -5, -1, 0, - 5, -3, 1, 0, 6, -2, 0, 0, -1, -2, 0, -3,-11, 1, 8, -1, - 3, 0, 0, 0, 0, 2, 4, 1, 2, 0, 6, 1, -2,-18, -3, 2, - -14, 0, 6, 1, -5, -2, -1, 1, -1, 1, 0, 1, 1, 7, 4, 0, - -1, 0, 1, -4, 1, 8, 3, -4, -3, 4, 1, 3, -6, 1, -4, 1, - 1,-12, 3, 3, -1,-10, 0, -1, 2, 0, 2, 1, 3, 2, 2, 4, - 3, 0, 0, 3, 2, 0, -2, 1, 5, 2, -5, 0, 6, -1,-14, -1, - -2, -6, -3, -3, 2, -1, 4, 5, 6, -1, -2, 0, 4, 4, -1, -5, - -4, 1,-11, 0, -1, 2, -4, 1, 2, -3, 3, -1, 1, -2, 15, 0, - 1, -1, 0, -2, 1, -4, -7, 1, -2, -6, -1, 21, -2, 2, -1, 1, - 21, -1, -2, 0, -1, -3, 1, -2, -9, -2, 2, -1, 2, 1, -4, -1, - 1, 8, 2, -6,-10, -1, 4, 0, -4, -3, 3, 3, 5, 0, -1, -1, - 3, 2, 1, -2, -2, -2, 4, 3, 5, 2, -4,-17, 0, -2, 4, 3, - -7, -4, 0, 3, 9, 9, 2, -1,-11, -6, 0, -1, 5, 1, 0, 1, - 0, 17, 5,-11, 3, -2, -6, 0, 2, -2, -4, 1, -4, 1, 2, -1, - -5, -1, -5, -3, -3, 5, -3, -2, 4, 16, 2, -5, -2, 5, -1, -1, - 0, 0, -4, 1, -1, 2, 5, 11, -1, -1, -2, 1, -4, -2, -3, -1, - -5, -1, 10, 0, 6, 1, 0, -3, 0, -4, 1, 0, -2, -4, 3, -1, - 6, 9, 3, 0, -2, 1, -2, 0, -2, -3, -2, -2, 1, 0, 1, -6, - 1, 0, 2, 1, -1, 3, -2, 1, 0, -1,-15, 0, -1, 5, 2, 6, - 2, 0, 2, 2, 0,-12, -4, 6, 0, 1, 4, -1, 1, 2, 1, -4, - 1, -2, -7, 0, 0, 0, 0, -1, -5, 2, 11, 3, 1, 3, 0, -6, - 0, -3, -9, -4, 1, 3, -1, 0, 4, 1, -2, 0, 7, -3, -1, 6, - 1, -2, 6, 2, 0, -1, 3, -2, -2, 4, 0, 2, -1, 2,-14, 2, - 2, 2, 0, -1, -2, 3, -3,-14, 0, 2, 3, -3, 5, 1, 3, 2, - 1, -3, 4,-14, 1, -2, 11, -1, 0, -1, 3, 0, -1, 1, 0, 2, - -2, 3, -3, 2, -4, -1, -4, 3, -1, 2, 1, 3, -6, -2, 2, 7, - -2, 1, 2, 0, -2, 0, 0, -1, 12, 5, -1, 2, -8, -1, 1, -7, - 2, -2, -4, 2, 11, 0,-11, -2, 3, 1, -3, -1, 0, 3, 1, -1, - 0, 3, 0, -2, 0, -6, -1, -3, 12, -7, -2, 0, 7, -2, 1, 1, - 1, 2, 2, 2, -1, 2, 0, 2,-23, 0, 4, 0, 3, 2, 1, 3, - -4, -5, -1, 5, -3, 5, 10, -1, 0, 0, 3, -4, 1, -1, 2, -5 -}; - -/* 6x16-entry codebook for inter-coded 8x4 vectors */ -static int8_t inter_codebook_8x4[3072] = { - 9, 8, 4, 0, -3, -4, -4, -3, 9, 8, 4, -1, -4, -5, -5, -3, - 8, 7, 3, -2, -5, -5, -5, -4, 6, 4, 1, -2, -4, -5, -4, -3, - -12,-14,-11, -4, 1, 5, 6, 6, -8,-10, -7, -5, -2, 1, 1, 1, - 5, 4, 3, 1, 0, 0, -1, -1, 13, 13, 9, 6, 3, 0, -1, -2, - -4, -4, -3, -1, 1, 4, 8, 11, -5, -6, -4, -2, 0, 3, 8, 12, - -7, -7, -6, -4, -2, 2, 7, 10, -7, -7, -5, -4, -2, 1, 5, 8, - -3, -2, -1, 1, 3, 6, 7, 6, 2, 3, 5, 7, 8, 8, 6, 4, - 4, 5, 4, 3, 1, -2, -6, -7, 1, 0, -2, -7,-10,-14,-17,-16, - -5, -4, 1, 8, 9, 3, -3, -7, -7, -6, 1, 11, 12, 5, -3, -8, - -8, -7, 0, 9, 11, 5, -3, -7, -8, -6, -1, 5, 8, 4, -2, -6, - -4, -5, -7, -8, -9, -9, -8, -6, -4, -5, -6, -7, -7, -6, -4, -2, - 0, 1, 2, 3, 5, 8, 10, 9, 1, 2, 3, 6, 9, 12, 14, 13, - 5, 6, 6, 5, 4, 3, 2, 1, 5, 6, 7, 7, 6, 6, 6, 4, - -1, 0, 1, 1, 3, 5, 5, 5,-13,-16,-17,-17,-14,-10, -6, -4, - 9, 11, 13, 16, 15, 13, 12, 10, -4, -5, -6, -7, -7, -7, -6, -5, - -6, -6, -7, -7, -7, -7, -6, -5, -2, -1, 0, 0, 0, 0, 0, -1, - -11,-13,-15,-16,-16,-14,-12,-10, 2, 3, 4, 5, 4, 3, 3, 3, - 6, 7, 8, 8, 8, 7, 6, 5, 3, 4, 3, 3, 3, 3, 3, 3, - 3, 4, 4, 1, -2, -7,-13,-17, 5, 7, 7, 5, 1, -5,-13,-19, - 6, 8, 9, 8, 5, -1, -9,-16, 6, 8, 10, 10, 7, 2, -4,-11, - 18, 9, -1,-10,-13, -9, -4, 0, 22, 12, -1,-12,-15,-10, -4, 2, - 23, 13, 0,-10,-13, -9, -3, 2, 20, 12, 2, -6, -9, -6, -2, 2, - -6, -6, -6, -7, -7, -7, -7, -6, -6, -7, -8, -8, -9, -9, -9, -8, - -3, -3, -3, -3, -3, -3, -3, -3, 12, 15, 18, 21, 21, 19, 17, 14, - 14, 16, 18, 18, 18, 16, 15, 13, 5, 6, 6, 5, 5, 4, 4, 3, - -6, -7, -9,-10,-10,-10, -9, -7,-10,-11,-13,-14,-14,-13,-12,-10, - -27,-17, -4, 5, 9, 10, 10, 7,-32,-19, -3, 7, 11, 12, 11, 8, - -30,-16, -2, 8, 12, 12, 10, 7,-23,-12, 0, 7, 10, 11, 9, 6, - 16, 17, 16, 12, 6, -1, -8,-12, 17, 18, 15, 10, 1, -8,-15,-18, - 15, 14, 10, 4, -5,-14,-20,-23, 10, 8, 4, -1, -9,-16,-21,-22, - -10,-12,-12,-11, -5, 4, 14, 20,-11,-13,-15,-12, -4, 7, 19, 27, - -11,-13,-14,-11, -3, 8, 21, 28,-10,-11,-12, -9, -2, 8, 18, 25, - -1, -1, -1, 1, 4, 6, 6, 5, 0, 0, 0, 2, 4, 3, 1, -2, - 0, 0, 2, 4, 4, -1, -7,-10, 0, 0, 3, 5, 3, -3,-11,-15, - -14,-13, -8, -1, 3, 3, -1, -4, -5, -4, -1, 4, 8, 8, 3, 0, - 3, 2, 2, 3, 4, 5, 3, 1, 5, 3, 0, -2, -2, -1, -1, -1, - 9, 1, -6, -6, -5, -3, -2, -1, 12, 1, -6, -6, -4, -2, -1, 0, - 14, 4, -4, -4, -2, -2, -1, -1, 14, 6, -1, -1, -1, -1, -1, -1, - 4, 6, 8, 10, 11, 9, 7, 5, -1, -1, -1, 0, 0, -1, -1, -2, - -2, -4, -4, -5, -5, -5, -5, -4, -2, -3, -3, -4, -4, -3, -2, -1, - 2, 3, 4, 4, 3, 1, 0, 0, -1, 1, 4, 5, 6, 5, 4, 3, - -8, -6, -2, 2, 3, 4, 4, 3,-14,-13, -9, -5, -2, -1, 0, 0, - -3, -4, -5, -4, 0, 7, 12, 13, -3, -4, -5, -5, -2, 4, 9, 10, - -2, -3, -4, -5, -4, -1, 3, 4, -1, -1, -2, -3, -3, -2, 0, 1, - 9, 5, -2, -8,-11,-10, -7, -4, 12, 10, 6, 2, 0, -1, 0, 0, - 2, 2, 3, 4, 3, 1, 1, 1, -9, -8, -4, 0, 1, 2, 1, 0, - 6, 8, 8, 5, 1, -5,-11,-13, 0, 1, 2, 2, -1, -4, -8,-11, - -3, -2, 1, 3, 3, 1, -1, -4, -2, -1, 2, 5, 6, 6, 4, 1, - 3, 4, 5, 5, 4, 1, -3, -6, 5, 6, 4, 2, 2, 2, 0, -3, - 6, 5, 0, -5, -5, -2, -1, -2, 7, 4, -3,-11,-12, -7, -3, -2, - 1, 0, -1, -1, -1, 0, 0, 0, 2, 3, 4, 4, 5, 5, 4, 3, - -7, -9, -9,-10,-10, -9, -7, -6, 3, 4, 5, 6, 5, 5, 5, 5, - -7, -7, -7, -7, -6, -6, -5, -4, -5, -4, -3, -1, -1, -1, 0, 0, - -3, -2, 1, 4, 5, 5, 5, 5, -2, -1, 3, 6, 9, 10, 10, 9, - -14, 1, 10, 3, -2, 0, 1, 1,-16, 2, 13, 3, -3, -1, 1, 0, - -15, 2, 12, 3, -4, -2, 1, 1,-10, 3, 10, 2, -3, -1, 1, 1, - 0, 1, 4, 2, -5,-10, -3, 11, -1, 1, 4, 2, -6,-13, -2, 15, - -1, 0, 3, 1, -6,-12, -1, 15, -1, 1, 2, 1, -4, -8, 0, 11, - 10, 5, -2, -2, 2, 5, 1, -4, 7, 0, -8, -6, 1, 5, 2, -4, - 2, -5,-12, -7, 2, 7, 4, -1, -1, -7,-10, -4, 4, 9, 7, 2, - -5, -5, -4, -6, -6, -5, -5, -3, -1, -2, -2, -4, -5, -6, -5, -4, - 6, 7, 7, 4, 0, -2, -3, -3, 13, 14, 13, 10, 5, 1, -1, -2, - 1, 1, 2, 2, 2, 2, 2, 2, -5, -6, -8, -9, -9, -8, -7, -6, - 7, 9, 10, 11, 11, 9, 7, 5, -1, -2, -3, -3, -4, -4, -4, -3, - -1, -1, 0, 0, 0, 0, -1, -1, -3, -3, -4, -5, -4, -3, -3, -2, - 2, 1, -1, -3, -3, -2, -1, 0, 12, 12, 8, 3, 1, 0, 0, 1, - -6, -8, -8, -6, -2, 2, 6, 8, 1, 1, -1, -2, 0, 3, 5, 7, - 3, 3, 1, -1, -1, 0, 0, 2, 0, 1, 0, -1, -1, -1, -2, -1, - 1, 0, 0, 0, 0, 0, 2, 4, 2, 1, 3, 4, 3, 1, 0, 2, - 2, 1, 0, 0, -1, -1, 0, 3, 5, 1, -6,-12,-13, -8, -1, 4, - -2, 0, -1, -2, -1, 0, 2, 3, -6, -3, -2, 0, 1, 1, 1, 1, - -9, -5, 0, 4, 5, 3, 1, 0, -8, -3, 3, 7, 8, 4, 1, 0, - 1, 2, 2, 3, 3, 1, -1, -3, 4, 5, 5, 6, 6, 5, 2, 0, - 0, 0, 0, 0, 1, 0, -2, -4, -3, -3, -4, -3, -3, -4, -7, -8, - 14, 12, 6, -1, -3, -3, 0, 0, 7, 5, 1, -3, -5, -4, -2, -1, - -2, -2, -2, -2, -2, -2, -1, -1, -6, -4, -1, 1, 1, 1, 0, -1, - 2, 2, 1, -3, -6, -7, -6, -3, 1, 0, -1, -3, -2, 1, 4, 6, - 0, 0, 1, 2, 4, 7, 8, 7, 0, 0, 0, 0, -1, -4, -7, -8, - 0, 2, 1, -2, -3, -3, -2, -1, -1, 1, 0, -3, -5, -2, 0, 2, - -2, -1, -2, -5, -4, 1, 6, 9, -3, -2, -3, -4, -2, 5, 11, 13, - -4, -2, 2, 6, 4, -3,-10,-14, -2, -1, 1, 4, 4, 1, -1, -2, - 0, 0, -1, -2, -2, 0, 4, 6, 2, 2, 0, -3, -3, 0, 5, 9, - -4, -4, -2, 1, 6, 9, 3, -7, -2, -2, -2, -1, 4, 8, 0,-11, - 1, 1, 0, 0, 2, 6, -1,-10, 2, 2, 1, 0, 2, 4, 0, -7, - -1, -2, -3, -6, -7, -8, -8, -8, 2, 3, 3, 1, -1, -2, -3, -4, - 5, 5, 5, 4, 3, 2, 0, -1, 3, 3, 3, 3, 2, 2, 1, 1, - 3, 3, 2, -2, -3, 0, 7, 10, 1, 2, 2, -2, -5, -4, 0, 3, - 0, 3, 4, 2, -3, -5, -6, -4, 0, 2, 4, 4, 1, -4, -7, -7, - 2, 4, 5, 5, 5, 5, 6, 6, -4, -4, -3, -5, -5, -3, -3, -2, - -3, -4, -4, -5, -4, -2, -2, -2, 1, 1, 0, 0, 2, 4, 5, 4, - -2, 0, 3, 4, 4, 3, 2, 2, -9, -7, -4, 0, 3, 6, 6, 6, - -5, -5, -3, -2, 0, 1, 3, 4, 5, 5, 2, -2, -4, -6, -5, -3, - 1, -6, -4, 7, 5, -2, -2, 1, 5, -5, -4, 6, 4, -5, -4, 1, - 5, -5, -4, 6, 4, -5, -3, 1, 1, -7, -3, 8, 7, -1, -3, 1, - -8, -7, -4, 0, 2, 4, 5, 5, 5, 6, 5, 2, -1, -5, -7, -7, - 5, 6, 4, 1, -3, -5, -6, -5, -7, -7, -5, -2, 1, 6, 9, 10, - 6, 3, 0, 1, 3, 0, -8,-14, 3, 0, -1, 1, 4, 3, 0, -4, - 1, 0, 0, 1, 2, 1, 1, 1, -1, -1, 1, 2, 1, -1, -1, 0, - 1, 1, 1, 1, 0, -2, -3, 0, 1, 2, 1, 0, -2, -8, -9, -4, - 1, 3, 3, 2, 1, -3, -3, 1, 0, 1, 1, 1, 1, 1, 4, 8, - 2, 5, 9, 7, 2, -1, -1, 1, -4, -1, 1, 0, -3, -4, -1, 2, - -3, 0, 3, 3, 0, -1, 0, 2, -4, -1, 1, 1, -2, -4, -5, -4, - 1, -1, -2, -2, -1, 2, 4, 5, 2, 1, 1, 0, -1, -1, 0, 0, - 2, 3, 4, 5, 4, 2, 1, 0, -9, -9, -6, -3, -1, -1, -1, -1, - -6, -6, 4, 7, 0, -2, -1, -2, -1, -2, 5, 6, -1, -2, 0, -1, - 4, -1, 1, 0, -4, -2, 0, -2, 7, 1, -1, -2, -3, 1, 3, 1, - 4, 2, 1, 3, 3, 1, 1, 2, 2, -2, -4, 0, 3, 1, 0, 0, - 1, -4, -8, -4, 1, 2, 1, 0, 2, -3, -9, -6, 0, 3, 3, 2, - -1, -1, 0, -1, -1, 0, 1, 2, 3, 1, -4, -8, -7, -3, 1, 2, - 2, -1, -3, -2, -1, 0, 1, 0, -1, 0, 5, 11, 9, 3, -1, -3, - -1, -2, -2, -1, 1, 1, 1, 1, 0, -1, 0, 3, 6, 6, 5, 5, - 2, 1, -1, -1, -2, -5, -6, -4, 2, 2, 2, 1, -1, -4, -5, -5, - -1, -3, -6, -7, -6, -4, -1, 1, 5, 5, 3, 4, 4, 3, 4, 5, - -1, -2, -3, -2, -2, -2, 0, 1, 0, 0, 0, 0, 0, 1, 2, 3, - -6, -6, -4, -1, 2, 2, 2, 2, -6, -7, -5, -2, 0, -1, -1, 0, - 2, 2, 2, 4, 4, 3, 3, 4, 2, 1, 0, -1, 0, 0, 2, 4, - 12, 5, -5, -8, -5, 0, 2, 2, 2, -3, -6, -3, 0, 0, -1, -2, - -2, -3, -1, 3, 4, 1, -2, -3, 2, 2, 3, 4, 3, 1, -1, -1, - 3, 2, 1, 0, 1, 4, 3, 0, 4, 3, 0, -5, -6, 0, 3, 3, - 2, 3, 1, -7,-12, -6, 1, 3, 1, 3, 4, -1, -6, -4, 0, 1, - -9, -4, 2, 6, 7, 4, 1, 0, -7, -1, 4, 6, 4, 0, -3, -3, - -6, 0, 4, 4, 1, -2, -3, -2, -4, 1, 3, 2, 0, -2, -1, 0, - 0, 5, 2, -5, -3, 3, 1, -4, -2, 4, 2, -6, -3, 6, 4, -3, - -1, 5, 3, -5, -1, 7, 3, -4, -1, 2, 0, -6, -3, 5, 3, -3, - -8, -3, 3, 5, 3, 1, -2, -2, 2, 4, 4, -2, -4, -3, 1, 3, - 2, 1, -3, -5, -3, 3, 4, 3, -5, -6, -5, 3, 10, 8, -1, -5, - 0, 3, 2, -4, -9, -7, 0, 6, -5, -1, 5, 7, 4, -1, -3, -3, - -5, -5, -2, 3, 6, 5, -1, -4, 9, 6, 0, -4, -2, 1, 1, -1, - -1, -1, -1, 1, 1, 0, -1, 0, -1, 0, 0, 0, 0, -1, -1, 0, - 2, 1, -2, -1, 1, 1, 0, 0, 12, 8, 2, -1, -1, -4, -7, -7, - 2, 1, 3, 6, 7, 4, 2, 0, 1, 0, -1, 0, -1, -4, -7, -8, - 0, 0, -1, 0, 0, 0, -1, -3, 0, 0, 0, 0, 1, 1, 0, -2, - -1, 0, 1, 1, 0, 0, -1, -2, 0, 0, -1, -3, -4, -3, -1, 1, - -1, 0, 0, 0, 1, 4, 10, 12, -1, 0, -2, -2, -3, -3, -1, 1, - -3, -1, -2, -4, 2, 9, 9, 7, -3, 0, -1, -3, 0, 2, -1, 1, - -1, 1, -2, -3, 0, -1, -3, 0, 0, 0, -3, -2, 0, -1, -1, 1, - -1, -2, -1, -1, -2, -1, -1, -2, 2, -1, -2, -1, 0, 1, 0, -2, - 3, -1, -2, 2, 5, 3, -1, -3, 1, -5, -5, 1, 6, 6, 2, 0, - 1, 2, 0, -1, 0, 1, 0, -2, -5, -3, -1, 0, 1, 2, 1, -2, - -7, -5, -2, -2, -2, -2, 0, 1, -1, 0, 1, 1, 0, 3, 9, 12, - 0, 6, 5, 1, -2, -3, 0, 3, 0, 6, 5, 1, 1, 1, 2, 3, - -5, -2, -2, -3, 0, 0, 0, 0, -6, -3, -3, -2, 0, 0, -1, -2, - 4, 4, 2, 1, 0, -1, -1, 0, -2, -2, 0, 1, 2, 1, 1, 0, - 2, 2, 1, -1, -3, -5, -9,-10, 2, 1, -1, -1, 1, 4, 4, 1, - 4, 0, -2, -2, -2, -2, -1, 0, 7, 1, -4, -3, -2, 0, 1, 1, - 10, 5, -1, -2, 0, 1, 1, 0, 5, 1, -3, -4, -3, -1, -1, -2, - 2, 1, -1, -3, -3, 1, 1, -1, -2, -1, 3, 0, -1, 1, 1, 0, - -3, 1, 7, 2, -3, -2, -1, 0, -2, 4, 8, -1, -8, -5, 0, 2, - -4, -1, 1, 2, 1, -3, -4, -2, -5, -3, -2, 1, 4, 4, 4, 6, - -3, -2, -4, -3, 0, 1, 1, 2, 2, 2, 2, 1, 2, 1, -1, -1, - -4, -1, 0, -1, -3, -3, -1, -1, 1, 4, 4, 2, 0, -1, -2, -3, - 4, 6, 5, 3, 2, 1, -2, -4, 0, 1, 1, 1, 1, -1, -4, -6, - 1, 2, 2, -1, -6, -5, -1, 2, -3, -2, 1, 1, -4, -3, 2, 5, - -2, -1, 2, 2, -3, -4, 0, 3, -2, -2, 2, 6, 5, 2, 1, 2, - 2, -3, -3, 0, 0, 2, 3, 1, 3, -1, 1, 3, 1, 2, -1, -5, - -5, -7, -4, -2, 1, 8, 8, 1, -1, 0, 2, 0, -3, 0, 1, -3, - -2, -5, -5, -2, -3, -1, 0, -2, -1, -4, 0, 4, 0, 2, 4, 0, - 0, 0, 8, 10, 2, 1, 3, -1, -4, -3, 2, 3, -3, -3, 1, -1, - 1, -2, -4, 2, 7, 3, -2, -1, 6, 4, -2, -1, 2, 0, -1, 3, - 1, 1, -2, -2, -2, -5, -3, 4, -6, -2, 1, 1, -1, -4, -2, 4, - -2, -1, -2, -2, 0, 1, 0, -2, -1, 1, 0, -1, 0, 0, -1, -3, - 0, 1, -2, -4, -3, -1, 0, 0, 6, 8, 5, 0, 0, 1, 2, 3, - -2, -2, 2, 5, 2, 0, 0, 1, 2, -2, -2, -1, -1, 1, 2, 4, - 2, -1, 0, 1, 0, 0, 0, 1, -8, -7, -1, 1, -1, -1, 1, 3, - 0, 3, 6, 2, -2, 1, 2, 0,-10, -7, -1, 0, -3, -1, 2, 1, - 0, 0, 2, 2, 1, 1, 1, -1, 3, 0, -2, -2, 0, 2, 1, 0, - 8, 1, 0, 0, -2, -3, -1, 0, 2, -2, 2, 5, 1, -2, -1, 1, - -3, -6, -3, -1, -3, -3, -1, 2, 2, 0, 1, 2, 2, 1, 0, 0, - 1, -1, -1, -2, -1, 0, 1, 0, 15, 9, 2, -1, -2, -3, -3, -3, - 0, -3, -2, 0, 0, -1, -1, -1, 1, 0, 1, 0, 0, -1, -1, -1, - 0, 2, 2, -2, -3, -3, -7, -8, 0, 2, 2, 0, 1, 2, 1, 1, - 1, 2, 2, 2, 3, 1, 0, 3, 1, 0, -1, -2, -1, -2, 0, 5, - -11, -6, -1, 1, 2, 3, 1, -3, 1, 4, 3, -1, -2, 1, 2, -1, - 2, 2, 1, -1, -2, 0, 1, -1, 0, 0, -1, -1, 0, 2, 3, 2, - 1, 1, 2, 1, -1, 1, 0, -4, 0, 0, 0, -2, -2, 2, 4, -2, - -2, -3, 0, 0, -1, 2, 1, -6, 0, 2, 5, 5, 3, 2, -1, -7, - 4, 2, 0, 0, 3, 3, 1, -1, 0, -1, -1, 3, 6, 4, 1, -1, - -2, -2, 0, 2, 2, 0, -2, -2, -1, 0, -1, -5, -7, -5, -1, 1, - 5, -1, -2, 0, 2, 4, 2, -5, 0, -5, -2, 2, 1, 2, 0, -6, - 6, 1, 0, 1, -2, -1, 4, 2, 2, -3, -3, 0, -1, -2, 0, 0, - 1, -1, 0, 2, 0, 0, 6, 11, 2, -1, -1, 0, -3, -2, 3, 5, - 0, -2, -1, 0, -1, 0, 0, -3, 1, -1, -1, -1, -2, -1, -3, -7, - 1, 1, -2, -2, 1, 3, 1, -2, -1, 2, 0, -1, -1, 1, 0, 0, - -4, 2, 3, -1, -2, -2, 0, 1,-11, -2, 4, 5, 6, 2, -1, -2, - -6, -2, 1, -1, -3, -4, 1, 9, -3, 0, 3, 3, 2, -3, -3, 3, - 1, 1, 0, 0, 1, -1, -2, 3, 2, 0, -3, -3, 0, -1, -1, 3, - 1, -1, -3, 1, 2, -6, -4, 6, 0, -2, -5, -2, 0, -3, -2, 3, - 2, 2, 1, -2, -2, 1, 2, -1, -1, 1, 1, -2, -1, 6, 7, -1, - 1, 0, -4, -2, 1, -2, -3, 1, -4, 0, -3, -2, 2, 0, -3, 0, - -3, 4, 3, 1, 8, 7, 0, -1, -3, 4, 1, -4, 2, 3, -2, -3, - -3, 6, 1, -4, 1, 1, -1, -1, -2, 4, -3, -3, 3, 0, -1, -1, - 1, 2, -4, 2, 4, -3, -1, 2, 3, -1, -4, 5, 4, -6, -3, 2 -}; - -/* 6x16-entry codebook for inter-coded 8x8 vectors */ -static int8_t inter_codebook_8x8[6144] = { - -4, -3, 4, 5, 2, 1, 1, 0, -5, -3, 5, 5, 2, 1, 0, 0, - -6, -4, 5, 5, 2, 1, 0, 0, -7, -4, 4, 5, 2, 1, 0, 0, - -8, -5, 3, 4, 2, 1, 0, 0, -8, -6, 3, 4, 1, 1, 1, 0, - -8, -6, 2, 4, 2, 1, 1, 0, -8, -6, 2, 4, 1, 1, 1, 1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -2, -2, - -2, -3, -3, -3, -3, -3, -3, -3, -2, -3, -3, -3, -3, -3, -4, -3, - -2, -2, -2, -2, -2, -3, -3, -2, 1, 1, 1, 1, 1, 0, -1, -1, - 4, 5, 5, 5, 4, 3, 3, 2, 7, 7, 8, 8, 8, 7, 6, 5, - 2, 1, 2, 4, 4, 0, -4, -6, 1, 1, 2, 5, 5, 1, -5, -7, - 1, 2, 1, 4, 5, 1, -5, -8, 1, 1, 1, 5, 5, 0, -6, -8, - 0, 1, 1, 5, 6, 1, -6, -9, 0, 0, 1, 4, 5, 0, -5, -8, - 0, 0, 1, 4, 5, 0, -5, -7, 0, 0, 1, 4, 4, 1, -4, -7, - 1, 2, 3, 0, -3, -4, -3, -1, 1, 3, 4, 0, -3, -4, -3, -1, - 2, 4, 5, 1, -3, -4, -3, -2, 2, 5, 6, 1, -3, -5, -4, -2, - 3, 6, 6, 1, -3, -5, -4, -2, 3, 6, 6, 1, -3, -5, -4, -2, - 3, 6, 6, 1, -3, -5, -4, -2, 3, 5, 5, 1, -3, -4, -4, -2, - 2, 2, 2, 2, 1, 0, 0, -1, 4, 4, 4, 3, 2, 1, 1, 0, - 4, 5, 4, 4, 3, 3, 2, 1, 4, 4, 4, 4, 4, 3, 2, 2, - 2, 3, 3, 3, 3, 3, 2, 1, -1, -1, -1, -1, 0, 0, 0, 0, - -5, -6, -6, -5, -5, -4, -3, -3, -7, -9, -9, -8, -7, -6, -6, -5, - 6, 6, 6, 6, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, - 0, -1, -1, -1, -2, -2, -1, -1, -3, -5, -6, -6, -6, -6, -5, -4, - -3, -5, -6, -7, -6, -6, -5, -4, -1, -2, -2, -2, -2, -2, -1, -1, - 0, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 1, -2, -5, -4, 0, 2, 5, 2, 1, -2, -6, -5, 0, 3, 5, - 2, 1, -2, -6, -6, -1, 3, 6, 3, 2, -2, -7, -6, 0, 4, 7, - 2, 1, -2, -7, -5, 0, 5, 7, 2, 1, -2, -6, -5, 0, 4, 7, - 2, 1, -2, -6, -4, 0, 4, 6, 1, 1, -2, -5, -4, 0, 3, 6, - -10, -9, -6, -4, -1, 2, 3, 2,-10, -9, -5, -3, 0, 4, 4, 3, - -9, -7, -3, -1, 2, 5, 5, 3, -7, -5, -2, 0, 3, 5, 5, 3, - -6, -3, 0, 1, 4, 6, 5, 3, -4, -2, 1, 2, 3, 5, 4, 2, - -2, 0, 1, 2, 2, 4, 3, 1, -1, 1, 2, 2, 2, 3, 3, 1, - -4, -5, -5, -6, -6, -6, -6, -5, -3, -3, -4, -4, -4, -4, -4, -4, - 0, 0, 0, 0, -1, -1, -1, -1, 5, 5, 6, 5, 5, 4, 3, 2, - 5, 6, 7, 7, 7, 6, 5, 4, 3, 3, 4, 4, 4, 4, 3, 2, - 0, -1, 0, 0, -1, -1, 0, -1, -3, -3, -4, -4, -4, -4, -3, -3, - 1, -2, -5, 1, 5, 4, 2, 0, 1, -3, -6, 1, 6, 5, 2, 0, - 0, -4, -7, 0, 6, 6, 2, 1, -1, -5, -9, -1, 6, 6, 3, 1, - -1, -6,-10, -2, 6, 6, 3, 1, -1, -6, -9, -2, 5, 6, 3, 1, - -2, -6, -9, -2, 5, 5, 3, 1, -2, -6, -7, -2, 4, 4, 2, 1, - -5, -7, -8, -9, -9, -8, -7, -6, -5, -6, -6, -7, -7, -6, -6, -5, - -3, -3, -3, -4, -5, -5, -4, -4, -1, 0, 0, -1, -1, -1, -1, -1, - 0, 1, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 5, 5, 5, 4, - 3, 4, 5, 6, 8, 8, 8, 7, 3, 4, 5, 6, 7, 7, 7, 6, - 5, 6, 7, 8, 9, 10, 10, 9, 3, 4, 6, 7, 8, 9, 9, 8, - 0, 1, 2, 3, 4, 5, 5, 5, -1, -2, -1, -1, 0, 1, 2, 2, - -2, -3, -3, -3, -3, -2, -1, 0, -3, -4, -5, -5, -5, -5, -5, -4, - -4, -5, -5, -6, -7, -7, -6, -5, -3, -4, -5, -6, -7, -7, -6, -6, - 13, 7, 0, -3, -3, -4, -4, -5, 14, 7, 0, -3, -3, -4, -4, -4, - 15, 8, -1, -4, -4, -4, -5, -4, 15, 8, -1, -4, -4, -5, -4, -3, - 15, 7, -1, -4, -5, -5, -5, -4, 14, 7, -1, -4, -4, -4, -4, -3, - 12, 6, -1, -4, -4, -4, -4, -3, 11, 5, -1, -4, -4, -4, -4, -3, - -17, -4, 5, 4, 4, 4, 3, 3,-18, -5, 5, 4, 4, 4, 3, 3, - -19, -5, 6, 4, 4, 4, 3, 2,-20, -5, 6, 4, 4, 4, 3, 3, - -20, -4, 6, 4, 4, 5, 3, 3,-19, -5, 6, 4, 4, 5, 3, 3, - -18, -4, 5, 4, 4, 4, 3, 2,-17, -5, 4, 3, 4, 4, 3, 3, - -6, -6, -6, -4, -2, 1, 6, 11, -6, -7, -7, -4, -2, 2, 8, 13, - -8, -8, -7, -4, -2, 3, 9, 14, -8, -8, -7, -5, -1, 4, 10, 16, - -8, -8, -7, -5, -1, 4, 10, 17, -8, -8, -7, -4, 0, 5, 10, 16, - -8, -8, -6, -3, 0, 4, 9, 15, -7, -7, -5, -3, 0, 4, 8, 12, - 8, 7, 7, 5, 2, -2, -8,-14, 8, 8, 7, 5, 2, -2, -8,-15, - 8, 8, 7, 5, 1, -3, -9,-16, 8, 8, 7, 5, 1, -3,-10,-17, - 8, 9, 8, 5, 1, -3,-10,-17, 8, 8, 7, 4, 1, -4,-10,-16, - 7, 7, 7, 4, 1, -3, -9,-14, 6, 7, 6, 3, 0, -3, -9,-13, - 5, 1, -4, -4, -3, -1, 0, 0, 7, 2, -3, -3, -2, -1, 1, 0, - 7, 1, -3, -3, -1, 0, 1, 1, 6, 1, -3, -2, -1, 1, 1, 0, - 6, 0, -4, -2, -1, 0, 1, 0, 5, 0, -4, -3, -1, 0, 0, -1, - 5, 0, -3, -1, 0, 0, 0, -2, 4, 1, -2, -1, 0, 1, 0, -1, - 2, 2, 1, 1, -2, -6, -8, -8, 1, 1, 1, 1, -2, -5, -8, -8, - 1, 1, 1, 0, -1, -3, -5, -5, 0, 0, 0, 0, -1, -1, -1, -2, - 0, -1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 2, 3, 2, - 2, 1, 1, 1, 2, 3, 4, 3, 3, 3, 3, 3, 4, 4, 5, 4, - -4, -4, -3, -2, 0, 0, 1, 1, -4, -4, -3, -2, -1, 0, 0, 1, - -2, -2, -2, -1, -1, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, - 2, 2, 2, 2, 2, 2, 1, 1, 3, 4, 4, 4, 4, 4, 4, 3, - 1, 1, 1, 3, 3, 4, 3, 3, -5, -6, -5, -4, -3, -3, -2, -2, - -4, -2, -1, -1, -1, -1, 0, 1, -4, -2, -1, -1, -1, -1, 0, 1, - -3, -2, -1, -1, -1, 0, 1, 2, -4, -3, -2, -1, -1, 1, 3, 3, - -4, -3, -3, -1, -1, 1, 4, 5, -4, -3, -2, -2, -1, 1, 4, 7, - -2, -2, -1, -1, 0, 2, 6, 8, -1, 0, 0, 1, 1, 4, 7, 8, - -3, -3, -3, -2, -2, -1, -1, 0, -1, -1, 0, 1, 2, 2, 3, 3, - 0, 1, 2, 4, 5, 6, 6, 5, -1, 0, 2, 3, 5, 6, 5, 3, - -1, -1, 0, 2, 3, 3, 2, 1, -2, -2, -1, 0, -1, -3, -4, -4, - 0, 0, -1, -1, -2, -4, -8, -7, 1, 2, 1, 0, -1, -4, -6, -7, - -2, 4, 1, -6, 0, 3, 0, 0, -2, 5, 1, -7, 0, 3, 0, 0, - -3, 5, 1, -8, 0, 3, -1, -1, -2, 6, 1, -9, 0, 3, 0, -1, - -2, 6, 2, -8, 0, 4, 0, -1, -3, 5, 1, -7, 1, 4, 0, 0, - -2, 4, 1, -7, 0, 4, 1, 0, -1, 4, 1, -6, 0, 3, 1, 0, - 0, 0, 0, 3, 4, 5, 4, 1, 1, 1, 1, 2, 3, 3, 2, 0, - 2, 2, 1, 2, 2, 1, -1, -2, 4, 3, 1, 1, 0, -1, -3, -5, - 5, 3, 1, -1, -2, -3, -4, -6, 5, 3, 0, -2, -3, -5, -6, -7, - 4, 3, 0, -2, -3, -4, -5, -5, 4, 3, 0, -1, -2, -2, -3, -3, - 0, 0, 0, 0, -1, -5, -2, 6, 0, 0, 0, 1, -1, -6, -2, 8, - 0, 0, 0, 2, 0, -6, -3, 9, 0, -1, 0, 2, 0, -7, -2, 10, - 0, -1, 0, 2, -1, -8, -3, 10, 0, -1, -1, 2, -1, -7, -3, 9, - 0, -1, 0, 1, -1, -6, -3, 8, 0, 0, 0, 1, 0, -5, -2, 7, - 2, 3, 3, 2, 1, 0, -1, -1, 3, 4, 3, 2, 1, 0, -1, -2, - 3, 4, 4, 2, 1, -1, -2, -3, 2, 3, 3, 2, 0, -1, -2, -3, - -1, 0, 1, 1, 0, -1, -2, -2, -5, -4, -3, -1, 0, 1, 1, 1, - -8, -8, -5, -1, 1, 3, 4, 3,-10, -9, -5, 0, 3, 5, 6, 5, - -5, -1, 4, 5, 3, 1, 0, 0, -6, -1, 4, 5, 2, 0, -1, -2, - -6, -1, 5, 4, 2, -1, -2, -2, -7, -1, 4, 4, 1, -2, -3, -3, - -6, -1, 5, 4, 1, -2, -3, -3, -5, 0, 4, 4, 1, -1, -2, -2, - -4, 0, 5, 4, 1, -1, -1, -2, -3, 1, 4, 3, 1, -1, -1, -2, - -2, -3, -2, 1, 4, 6, 5, 3, -3, -4, -4, 0, 3, 5, 4, 2, - -3, -5, -5, -1, 2, 4, 3, 1, -4, -6, -4, -1, 2, 4, 2, -1, - -2, -4, -3, 1, 2, 4, 2, -1, -2, -4, -2, 1, 3, 3, 1, -2, - -2, -3, -2, 1, 3, 3, 1, -2, -2, -2, -1, 1, 3, 3, 0, -2, - -4, -4, -3, -2, -1, 2, 5, 7, -4, -4, -3, -3, -2, 1, 5, 7, - -2, -3, -2, -3, -3, -1, 3, 5, -1, -1, 0, -2, -3, -2, 2, 4, - 1, 1, 1, -1, -4, -3, 1, 3, 4, 3, 2, -1, -4, -3, -1, 1, - 6, 4, 3, 0, -3, -3, -2, 0, 6, 5, 3, 1, -2, -3, -2, -1, - 12, 11, 8, 4, 0, -2, -2, -1, 10, 9, 6, 2, -1, -2, -1, 0, - 4, 3, 2, 0, -1, -1, 0, 1, -1, -1, -1, -1, -2, 0, 1, 2, - -3, -5, -4, -2, -2, 0, 2, 3, -5, -5, -4, -2, -1, 0, 1, 2, - -5, -5, -4, -2, -1, 0, 1, 1, -4, -4, -3, -2, -2, -1, 0, 0, - 3, 3, 2, -1, -3, -4, -3, -2, 3, 2, 0, -2, -4, -4, -3, -2, - 2, 2, 1, -1, -3, -5, -4, -3, 3, 3, 3, 1, -2, -3, -3, -3, - 4, 4, 4, 3, 0, -2, -2, -2, 5, 5, 5, 3, 0, -1, -2, -2, - 5, 5, 4, 2, -1, -2, -3, -2, 3, 3, 3, 0, -2, -4, -4, -4, - -1, -1, 4, -2, -2, 6, 2, -5, -1, 0, 4, -2, -3, 6, 2, -6, - -1, 0, 4, -2, -3, 7, 3, -7, -1, -1, 4, -3, -4, 8, 3, -7, - 0, -1, 4, -3, -4, 7, 3, -6, -1, -1, 4, -3, -4, 7, 3, -6, - -1, -1, 3, -3, -4, 6, 3, -6, -1, 0, 3, -2, -3, 6, 3, -5, - 1, -2, -7, 2, 5, -2, -1, 1, 1, -2, -8, 3, 6, -3, -1, 2, - 2, -2, -9, 4, 7, -4, -2, 2, 3, -1, -9, 5, 7, -4, -1, 3, - 3, -1, -9, 4, 7, -4, -2, 2, 3, -1, -7, 4, 6, -4, -2, 1, - 2, 0, -6, 4, 6, -4, -1, 1, 2, 0, -5, 3, 4, -3, -1, 1, - -2, 2, 2, 0, 0, -1, -3, -4, -2, 2, 2, 1, 1, 0, -2, -4, - -2, 2, 2, 2, 2, 1, -1, -2, -3, 2, 3, 3, 4, 2, 0, -2, - -3, 2, 3, 2, 4, 2, 0, -3, -4, 1, 2, 1, 2, 1, -1, -3, - -5, 0, 1, 0, 1, 1, -2, -3, -4, 0, 0, 0, 1, 0, -2, -3, - 0, 0, -1, -2, -2, 2, 7, 8, 0, 0, -1, -3, -2, 1, 6, 7, - 0, 1, -1, -3, -3, 0, 4, 5, 0, 1, 0, -1, -1, 0, 1, 3, - 0, 2, 1, 1, 0, -1, 0, 1, -2, 0, 1, 2, 1, 0, -1, -1, - -5, -2, 0, 1, 1, 0, -3, -3, -6, -4, -1, 1, 1, -1, -3, -4, - -4, -2, 2, 5, 6, 4, 3, 2, -5, -3, 1, 4, 4, 2, 0, 0, - -4, -2, 0, 2, 1, -1, -2, -2, -2, -1, 0, 1, 0, -2, -3, -2, - -2, 0, 0, 0, -1, -1, -2, -1, -2, -1, -1, 0, 0, 0, 1, 2, - -2, -2, -1, -1, 0, 1, 3, 4, -2, -3, -2, -1, 0, 2, 4, 5, - 2, 1, -2, -2, -1, 0, 1, 0, 1, 0, -3, -3, -1, 0, 1, 0, - 0, -1, -3, -3, -1, 1, 1, 1, 0, 0, -3, -1, 1, 2, 3, 3, - 0, -1, -3, -1, 1, 3, 3, 3, -2, -2, -4, -2, 1, 3, 4, 4, - -3, -3, -4, -2, 1, 3, 3, 4, -2, -3, -5, -2, 1, 2, 3, 3, - 4, 5, 3, 4, 4, 4, 4, 5, 3, 3, 1, 0, 0, 0, 0, 1, - 1, 1, -1, -2, -3, -4, -3, -2, 2, 2, 0, -2, -2, -4, -3, -2, - 2, 3, 1, -1, -1, -3, -3, -2, 1, 2, 0, 0, -1, -2, -2, -1, - 0, 1, 0, -1, -1, -3, -2, -1, 1, 1, 0, -1, -1, -2, -2, -2, - -2, -1, -1, 0, 1, 2, 1, 0, 1, 2, 3, 5, 6, 5, 5, 3, - 1, 2, 3, 4, 5, 5, 4, 3, -2, -2, -3, -3, -2, -1, 0, 0, - -3, -3, -4, -5, -4, -3, -2, -1, -1, -1, -2, -2, -2, -1, 0, 0, - 0, 1, 0, -1, -1, 0, 0, 1, -1, 0, -1, -2, -3, -2, -2, -1, - 7, 7, 6, 5, 4, 2, -1, -2, 3, 3, 2, 2, 1, 0, -2, -3, - 0, -1, -1, -1, 0, -1, -2, -2, -1, -3, -2, -1, 0, 0, 0, 1, - 0, -2, -2, -1, -1, 1, 2, 2, 3, 1, -1, -1, -1, 1, 2, 2, - 3, 1, -2, -3, -2, -1, 1, 2, 1, -2, -5, -6, -5, -3, -2, 0, - 0, -1, -2, -3, -1, 0, -2, -2, 0, 0, -1, -1, 0, 1, -1, -2, - 0, 0, -2, -1, 0, 0, 0, -2, -1, -2, -3, -3, -2, -1, -3, -3, - -1, -2, -3, -3, -2, -2, -3, -4, 2, 2, 0, 0, 0, 0, -1, -2, - 5, 5, 3, 2, 2, 2, 0, -1, 8, 8, 6, 5, 4, 4, 2, 1, - -7, -8, -6, -3, -1, -1, -2, -1, -5, -5, -3, 0, 2, 1, 0, 0, - -1, -1, 0, 3, 4, 3, 1, 1, 2, 1, 1, 3, 4, 3, 2, 2, - 3, 2, 0, 2, 3, 2, 1, 2, 4, 2, -1, -1, 0, 1, 1, 1, - 3, 2, -2, -3, -2, -1, 0, 1, 3, 1, -3, -4, -3, -2, 0, 1, - -4, -2, -1, 2, 3, 3, 1, 0, -7, -5, -4, -2, 0, 0, -1, -2, - -6, -5, -5, -4, -2, -2, -2, -3, -1, 0, -1, -1, 0, 0, 0, -1, - 2, 3, 2, 2, 2, 2, 1, 0, 3, 5, 4, 3, 1, 0, 1, 0, - 3, 4, 3, 2, 0, -1, -1, -1, 5, 5, 3, 1, 0, -1, -1, -1, - 1, 1, 0, -1, -3, -5, -6, -4, 1, 1, 0, 0, 0, -3, -3, -1, - 0, -1, -1, 0, 1, 0, 1, 3, -2, -2, -3, -1, 2, 2, 4, 7, - -2, -2, -2, 0, 2, 2, 3, 6, -1, 0, 0, 1, 1, 0, 0, 3, - 0, 3, 3, 3, 1, -2, -3, -1, 1, 3, 4, 3, 0, -3, -5, -4, - 0, 2, 0, -1, -3, -4, -2, -2, 1, 4, 2, 0, -2, -3, -2, -1, - 3, 6, 3, 1, -2, -2, 0, -1, 4, 7, 4, 1, -2, -3, -1, 0, - 3, 6, 3, 0, -3, -3, -1, 0, 1, 3, 0, -1, -3, -2, 1, 1, - 0, 1, -1, -2, -3, -1, 2, 2, -2, -1, -3, -3, -3, -1, 1, 2, - 3, 1, -1, 0, 1, 0, 0, 0, 2, -1, -2, -1, 1, 0, -1, -1, - 1, -1, -2, 0, 1, 0, -2, -3, 0, -2, -1, 1, 3, 1, -3, -5, - 0, -2, -1, 2, 5, 2, -3, -5, 0, -2, -1, 4, 6, 3, -2, -5, - 0, -2, 0, 4, 7, 4, -2, -4, 0, -2, 0, 4, 6, 4, -2, -4, - -2, -2, -3, -4, -3, -2, -1, 0, 1, 1, 0, -1, -1, -1, 0, 1, - 3, 3, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 0, 0, 1, - 0, 0, 0, 0, -1, -1, -1, -1, -4, -4, -4, -4, -4, -4, -4, -3, - -3, -3, -2, -3, -2, -1, -1, 0, 3, 4, 4, 5, 5, 6, 6, 7, - -1, -2, 7, -2, -4, -1, -1, 0, -1, -2, 9, -1, -4, -1, -1, 0, - -1, -3, 10, -1, -4, -1, -1, 1, -1, -3, 10, -2, -3, -1, -1, 2, - -1, -2, 10, -2, -4, -1, -1, 2, -1, -2, 9, -2, -4, -1, -1, 2, - -1, -2, 8, -2, -4, 0, -1, 1, 0, -2, 7, -2, -3, -1, 0, 2, - 3, -4, 1, 3, -3, -2, 1, 0, 3, -5, 1, 4, -3, -2, 1, 0, - 3, -6, 2, 5, -3, -1, 3, 0, 3, -6, 2, 5, -3, -1, 2, 0, - 3, -6, 1, 5, -4, -2, 3, 0, 3, -6, 1, 5, -3, -2, 2, 0, - 2, -6, 1, 4, -3, -1, 1, 0, 2, -6, 1, 4, -2, -1, 1, 0, - 0, 0, 1, 1, 1, 0, 0, 2, 0, -1, 1, 1, 1, 0, 0, 2, - 0, -1, 0, 0, 0, 0, 0, 2, 0, -1, 0, 0, 0, 0, -1, 0, - 1, 0, 1, 0, 0, -1, -2, -1, 3, 1, 1, 0, 0, -2, -4, -3, - 5, 3, 2, 1, 0, -3, -5, -4, 5, 4, 2, 0, -1, -4, -5, -5, - 1, 0, -1, -2, -2, -3, -6, -9, 2, 0, -1, -1, 0, 0, -3, -6, - 1, 0, 0, -1, 0, 0, -2, -5, 2, 1, 1, 1, 1, 2, -1, -3, - 1, 1, 2, 1, 2, 2, 1, -1, 1, 1, 2, 1, 1, 1, 1, 1, - 0, 0, 2, 1, 0, 0, 2, 2, 0, 1, 2, 2, 0, 0, 2, 2, - -4, -3, 0, 1, 4, 6, 4, 3, -3, -2, 0, 0, 2, 4, 1, 0, - -1, -1, 0, 0, 1, 1, -2, -3, 1, 1, 1, 0, 1, 1, -3, -5, - 1, 1, 1, 0, 1, 1, -3, -5, -1, 0, 0, -1, 1, 1, -2, -4, - -1, 0, 0, -1, 1, 2, 0, -2, -1, 0, 0, 0, 2, 3, 1, 0, - -1, 0, 3, 4, 0, -4, -5, -5, 0, 0, 4, 5, 2, -2, -3, -2, - 0, -1, 2, 4, 2, -1, -1, 0, 0, -2, -1, 1, 0, -2, 0, 1, - 1, -2, -2, 0, 0, -1, -1, 1, 1, -2, -3, 0, 1, 0, -1, 0, - 1, -2, -2, 1, 3, 1, 0, 0, 1, -2, -1, 2, 4, 2, 0, 0, - 1, 2, 3, 2, 0, 2, 2, 1, -1, 0, 1, 0, -3, 1, 1, 1, - -1, 0, 0, -2, -4, 0, 2, 1, -1, 2, 2, -1, -5, 0, 2, 1, - -1, 3, 4, -1, -5, 0, 2, 1, -2, 2, 4, 0, -4, -1, 0, 0, - -4, 0, 2, 0, -4, -2, 0, 0, -5, -1, 2, 1, -2, 1, 3, 2, - 1, 0, 1, 0, 1, 2, -1, -2, 2, 0, -1, -2, 1, 3, 0, -1, - 3, 0, -2, -4, 0, 3, 1, 0, 5, 1, -3, -5, -2, 2, 1, 1, - 6, 1, -2, -5, -2, 1, 0, 1, 5, 1, -1, -5, -2, 0, -1, 0, - 3, 0, -2, -4, -2, 0, -1, 0, 1, -1, 0, -2, 0, 1, 0, 1, - 1, 1, 2, 3, 2, 1, 1, 2, -1, -1, 0, 1, 1, 0, 1, 1, - -4, -3, 0, 0, 1, 1, 1, 2, -4, -3, 0, 2, 2, 2, 3, 2, - -5, -4, 0, 1, 1, 1, 1, 2, -5, -4, -1, -1, -2, -2, -1, 0, - -3, -2, 0, 0, -2, -3, -2, -1, 2, 3, 4, 4, 2, 0, 0, 0, - -4, -2, 0, 1, 0, 0, 0, 0, -3, -1, 1, 1, 0, 0, 0, 0, - -2, 0, 2, 2, 0, 0, 0, 2, -1, 1, 2, 1, -1, 0, 3, 5, - 0, 2, 1, -1, -2, 0, 5, 6, 0, 1, 0, -3, -3, 0, 4, 6, - 1, 1, -2, -4, -4, -3, 1, 2, 1, 0, -2, -4, -5, -4, -2, 0, - -1, -3, -3, -3, -3, -2, -1, -1, 3, 2, 1, 0, 0, 1, 1, 1, - 5, 4, 3, 2, 1, 1, 2, 2, 2, 1, 0, -2, -2, -2, -1, -1, - 0, 0, 0, -1, -2, -2, -2, -2, 0, 1, 3, 3, 2, 1, -1, -1, - 0, 1, 3, 4, 3, 2, 1, -1, -4, -3, -1, 1, 0, -2, -3, -3, - -3, -4, -7, -8, -7, -4, -1, 2, 0, -1, -3, -4, -4, -2, 0, 2, - 1, 0, 0, -1, -3, -2, 0, 2, 2, 1, 1, 0, -1, -1, 0, 2, - 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 1, 2, 3, 3, 2, 2, 0, 0, 1, 3, 4, 4, 3, 2, - 3, 3, 3, 0, -1, 0, 1, 2, 1, 1, 1, -1, -2, -1, -1, 1, - -2, -2, -1, -3, -3, -2, -2, 0, -4, -4, -2, -2, -2, -2, -3, 0, - -4, -4, -1, 1, 1, 0, -1, 2, -3, -1, 2, 3, 4, 3, 3, 5, - -2, 0, 2, 3, 3, 3, 3, 3, -2, -2, 0, 0, 0, 0, 0, 1, - 0, 2, 1, -1, -3, -1, 3, -2, -1, 0, -1, -1, -3, 0, 4, -2, - -2, -2, -2, -2, -2, 1, 5, -2, -3, -2, -3, -1, -2, 1, 4, -3, - -2, 0, -1, 0, -1, 0, 3, -5, 1, 2, 1, 2, 0, 0, 2, -5, - 2, 4, 2, 3, 1, 1, 3, -3, 1, 2, 1, 1, 0, 1, 4, -2, - 4, -3, -4, -1, 3, 3, 1, 3, 4, -4, -4, -1, 3, 2, 0, 2, - 4, -3, -4, 0, 2, 2, -1, 1, 4, -3, -2, 1, 2, 1, -2, 0, - 2, -4, -2, 1, 2, 0, -3, 0, 2, -3, -2, 0, 1, 0, -2, 2, - 3, -1, -1, 0, 0, 0, 0, 3, 2, -2, -2, -2, -1, -1, -1, 2, - 2, 2, 3, 4, 3, 1, 0, -1, 1, 0, 1, 2, 1, -1, -2, -2, - 2, 1, 2, 1, 1, 0, -1, -1, 4, 3, 4, 3, 2, 1, 1, 1, - 3, 2, 2, 2, 1, 1, 1, 1, -1, -2, -1, 0, -1, -1, -1, -1, - -3, -3, -2, -1, -2, -2, -2, -2, -4, -4, -3, -3, -4, -4, -3, -3, - 2, 1, -1, -3, -4, -2, 3, 4, 2, 2, 1, -1, -3, -2, 1, 2, - 1, 2, 3, 3, 0, -2, -1, -2, -1, 0, 2, 4, 2, 0, -1, -3, - -2, -2, 0, 3, 3, 2, 0, -3, 0, -2, -3, -1, 1, 2, 2, -1, - 3, -1, -4, -5, -3, 0, 2, 0, 6, 3, -2, -6, -5, 0, 3, 1, - -2, 3, -2, 0, 3, -2, -2, 1, -3, 4, -3, 0, 3, -2, -1, 2, - -3, 5, -3, 0, 4, -2, -1, 2, -2, 4, -4, -1, 3, -3, -2, 2, - -3, 4, -3, 0, 3, -3, -1, 2, -2, 5, -2, 0, 3, -3, -1, 2, - -2, 4, -3, 1, 3, -2, -1, 2, -2, 3, -2, 1, 3, -2, 0, 2, - 1, 0, 0, -1, 1, 2, -4, -1, 2, 0, 0, -1, 1, 2, -4, -2, - 1, 1, 1, -1, 2, 4, -2, 0, 0, -1, 1, -1, 2, 5, -1, 1, - 0, -1, 0, -2, 1, 5, -1, 1, 0, -1, -1, -2, 0, 3, -3, -1, - 1, 1, 0, -2, 0, 3, -3, -1, 1, 1, 0, -3, 0, 3, -2, 0, - 1, 0, -1, 1, 1, 2, 4, 5, 1, 0, -1, 1, 1, 1, 5, 7, - 0, 0, -2, -1, -1, 0, 3, 5, 0, -1, -2, -1, -1, -1, 2, 3, - 0, -1, -3, -1, -1, -1, 1, 2, -1, -2, -4, -2, -2, -2, 0, 0, - -1, -2, -2, -1, -2, -2, 0, 0, 0, -1, -1, 0, -1, -1, 0, 0, - 3, 3, 0, -1, -1, 1, 4, 4, 2, 3, 0, -2, -2, 0, 1, 1, - 2, 3, 1, -1, -1, 0, 1, 0, 1, 2, 0, -1, -1, -1, 0, -2, - 0, 1, 0, -1, -2, -1, 0, -2, 0, 1, 0, -1, -2, -1, 1, 0, - 1, 1, -1, -3, -4, -3, 1, 3, 1, 2, -1, -3, -5, -4, 1, 3, - -3, -2, 0, 1, 1, 1, 0, -2, 0, 1, 1, 1, 0, 0, -1, -3, - 1, 2, 1, 1, 0, -1, -1, -2, 0, -1, -3, -1, -1, -1, 0, -1, - 0, -3, -6, -3, -2, -1, 1, 1, 2, -1, -4, -3, -2, 0, 2, 2, - 5, 4, 1, 1, 0, 1, 3, 2, 5, 4, 2, 1, 0, -1, 0, 1, - -2, 0, -2, -5, -6, -3, 0, 0, -2, 0, 1, 0, -1, 1, 2, 2, - -2, 0, 1, 3, 2, 2, 2, 1, -2, 0, 2, 4, 3, 2, 1, 1, - -2, 0, 2, 3, 2, 0, -1, 0, -3, -1, 1, 1, 0, -1, -1, 1, - -4, -1, 1, 0, -1, -2, 0, 2, -4, -1, 0, -1, -1, -2, 1, 4, - -3, 0, 0, -1, 1, 1, 1, 0, -3, 1, 0, -1, 0, 0, -1, -1, - -1, 3, 3, 0, 1, 0, 0, 1, -3, 2, 2, -2, -1, 0, 0, 1, - -5, 0, 0, -2, -1, 1, 0, 2, -7, -2, 1, 0, 1, 2, 2, 2, - -5, 0, 3, 2, 3, 3, 2, 2, -3, 2, 4, 1, 0, 0, -2, -3, - 5, 2, -2, -2, 0, -1, -1, -1, 2, -1, -4, -3, -1, -2, -1, -1, - 0, -2, -2, 1, 2, -1, 0, 1, -1, -2, -1, 3, 3, -1, 0, 2, - 1, 0, 0, 3, 3, -2, -1, 2, 2, 1, 1, 3, 2, -2, -2, 0, - 1, 0, -1, 1, 1, -3, -3, -2, 1, 0, 1, 2, 3, 0, 0, 0, - -4, -5, -3, 0, 1, -1, -2, -1, -2, -3, -1, 1, 2, 0, 0, 0, - 1, 1, 2, 1, 2, 1, 1, 1, 3, 4, 3, 1, 0, -2, -1, -1, - 3, 3, 2, 0, -2, -3, -3, -2, 1, 1, 0, -1, -2, -4, -2, -2, - 2, 1, 0, 0, 0, -1, 0, 1, 2, 1, 1, 1, 1, 1, 1, 3, - 0, 0, 0, -1, -2, -1, 1, 0, -2, -1, -1, -2, -3, -2, 0, 0, - -1, 0, 0, -1, -2, 0, 1, 1, 1, 1, 0, -1, -1, 1, 3, 1, - 2, 2, 0, -2, -1, 2, 3, 0, 3, 1, -1, -1, 1, 4, 2, -2, - 2, 0, -3, -1, 3, 5, 0, -5, 1, -1, -2, 0, 3, 3, -1, -6, - -1, 0, 3, 4, 2, 0, 1, 2, -2, -1, 0, 1, -1, -2, 0, 1, - -2, -3, -2, -3, -6, -7, -6, -3, 2, 2, 3, 1, -1, -2, -3, -2, - 2, 2, 3, 1, 0, 0, 0, 0, 2, 1, 1, 0, 1, 1, 0, 1, - 1, 0, 0, 0, 0, 1, 1, 2, 1, 0, -1, 0, 0, 2, 2, 1, - 1, 1, 3, 1, -1, -1, -1, 1, -2, -1, 0, 0, -2, -2, -1, 2, - -2, -2, 1, 1, 1, 0, 1, 3, -2, -2, 0, -1, 0, -1, 0, 2, - 0, 0, 1, 0, -1, -1, -2, 1, 3, 2, 2, 1, 0, -2, -2, 1, - 5, 3, 3, 2, 1, 1, 1, 4, 0, -3, -4, -5, -4, -3, -1, 1, - -6, -4, -1, 2, 2, 0, 0, -1, -4, -2, 1, 3, 3, 2, 2, 0, - -3, -2, -1, 2, 3, 3, 2, 0, -3, -2, -2, 1, 2, 1, 1, -1, - -2, -2, -2, 0, 2, 2, 1, -1, -1, -1, -1, 1, 2, 3, 2, 0, - -1, -1, -2, 1, 2, 2, 2, -1, 0, -1, -2, 0, 2, 1, 0, -1, - 6, 4, 2, 1, 0, 0, 0, 1, 4, 2, -1, -2, -2, -2, -1, -1, - 2, 1, -1, -2, -2, -2, -2, -1, 2, 2, 0, -2, -2, -2, -1, 0, - 0, 0, -1, -2, -2, -1, 0, 1, -3, -3, -2, -1, -1, -2, -1, 0, - -3, -2, 2, 3, 2, 0, -1, -2, -2, 0, 4, 5, 5, 2, 0, -1, - 5, 4, 2, 0, -1, -2, -1, -1, 4, 3, 2, 1, 0, -1, 0, -1, - 1, 1, 0, 1, 1, 0, 1, -1, -2, -1, -1, 0, 0, -2, -2, -3, - -1, 0, 0, 0, -1, -3, -3, -5, 0, 1, 1, -1, -1, -2, -2, -3, - -1, -1, -1, -2, -1, 1, 3, 1, -1, -2, -2, -1, 2, 5, 6, 5, - -3, -3, -2, 1, 1, -2, -1, -1, 1, 2, 3, 4, 1, -3, -1, -3, - 3, 2, 0, 1, -1, -3, -1, -3, 1, 0, -1, 0, -1, -1, 1, 0, - 1, 1, 0, 1, 2, 2, 5, 3, 1, 1, 1, 2, 2, 2, 3, 0, - -3, -1, -2, -2, -3, -3, -1, -3, -1, 1, 1, 0, -1, -1, 0, -2, - 2, 0, -2, -2, 2, 4, 1, -2, 1, 0, -2, -1, 3, 5, 2, -1, - -1, -2, -3, -2, 1, 3, 1, -2, -1, -2, -1, -1, 0, 2, 1, -1, - 0, 0, 1, 1, 1, 2, 2, 0, 0, 1, 4, 4, 2, 2, 3, 1, - -2, -1, 2, 1, -2, -3, -2, -3, -1, 0, 1, 0, -3, -4, -4, -5, - 4, 0, -3, -4, -4, -4, -2, -1, 5, 0, -1, 0, -1, -3, -2, -1, - 4, 0, 0, 1, 1, 0, 0, 0, 0, -3, -2, -1, 0, 0, 1, 0, - 0, -2, 0, 0, 1, 1, 2, 1, 2, 0, 0, 0, 1, 1, 1, 0, - 2, 0, -1, -1, 1, 1, 1, 0, 1, -1, -2, -2, 0, 2, 2, 2, - -3, -5, -2, 0, -1, -3, -3, 0, 0, -2, 0, 2, 2, 0, 0, 3, - 2, -1, -2, 0, 0, -1, -1, 2, 5, 2, -1, -1, -1, -1, -1, 2, - 5, 2, 0, -1, -1, 0, -1, 2, 2, 1, 0, 0, 0, 1, 0, 2, - -1, -1, 1, 1, 2, 2, 1, 2, -3, -2, 0, 0, 0, 0, -2, -1, - 0, 3, 2, 0, -2, -3, -3, -3, 0, 3, 3, 1, 0, 0, 1, 2, - -1, 0, -1, -2, -1, -1, 1, 3, -1, 0, -1, -2, -1, -1, 0, 2, - -1, 0, -1, -2, 0, 0, -1, 2, -1, 0, -1, -2, -1, -1, -2, 1, - 0, 1, 0, -3, -1, -1, -1, 2, 5, 5, 2, -1, -1, -1, 1, 3, - 0, 0, 1, -1, -3, -2, 0, 2, 1, 1, 3, 0, -2, -2, 0, 1, - 1, 1, 3, 1, 0, 0, -1, -1, 0, -1, 2, 1, 1, 0, -1, -3, - -1, -2, 1, 1, 1, 0, -2, -4, -1, 0, 2, 1, 1, 0, -1, -3, - 1, 1, 3, 2, 1, 0, -2, -3, 2, 2, 4, 2, 1, -1, -2, -4, - 1, 2, 2, 2, 0, -2, 0, 2, -1, -1, -2, -3, -4, -5, -3, 1, - 0, 1, 1, 0, -1, -1, -1, 1, 0, 1, 1, 1, 0, 0, 0, 2, - 0, 1, 1, 2, 1, 1, 1, 2, -1, -1, 0, 2, 2, 2, 2, 3, - -2, -4, -4, -1, -2, -2, -2, 0, 1, 0, 0, 1, 0, 0, 0, 1, - 0, -1, -3, -2, 0, 2, 2, 1, 0, -1, -2, -3, 0, 1, 1, 2, - 1, 0, -2, -3, -1, 0, 0, 1, -1, 0, -1, -2, 0, 0, -1, 0, - -1, 1, 1, 0, 2, 2, 0, 0, 0, 2, 3, 1, 3, 5, 3, 2, - -1, 1, 1, -2, 0, 3, 1, 1, -1, 0, 0, -4, -4, -1, -1, -1, - -1, 1, 1, 0, 1, 2, 1, 2, -3, 0, 1, 0, 1, 1, 0, 2, - -5, -3, -1, -1, 0, 1, 0, 1, -4, -3, -2, -3, -2, -1, -1, 0, - 0, 0, -1, -2, -2, -2, -2, 0, 3, 4, 2, 0, 0, 0, 0, 1, - 2, 1, 0, 0, 0, 0, -1, 0, 0, 1, 2, 3, 4, 4, 3, 2, - -1, 4, 7, 4, 0, 0, 0, 0, -1, 4, 6, 3, 0, 1, 1, 1, - 0, 3, 4, 0, -1, 0, 0, 1, 0, 1, 1, -2, -1, 0, -1, -1, - -1, 0, -1, -1, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -3, -3, 0, 1, -1, -2, -1, -3, -4, -4, -2, -1, -2, -2, -1, - 2, 2, 1, 0, 1, 1, 0, -3, -2, -1, 0, 0, 1, 1, 0, -3, - -2, -1, 0, 1, 2, 1, 1, -2, 1, 2, 2, 2, 3, 3, 2, -1, - 1, 2, 1, 0, 1, 1, 2, -1, 0, 1, -2, -4, -2, 0, 1, -1, - 1, 1, -1, -3, -2, 0, -1, -3, 1, 2, 0, -1, 0, 1, -1, -4, - -1, -1, -2, -2, 0, 3, 4, 3, 1, 1, -1, -3, -2, 0, 0, 0, - 2, 2, 2, 2, 2, 1, -1, -1, 1, 1, 1, 3, 3, 0, -2, -2, - 0, -1, -1, -1, 0, -2, -1, -1, -1, -3, -4, -3, -2, -2, 0, 2, - -1, -1, 0, 1, 2, 2, 3, 5, -2, -1, -1, 0, 0, 0, 0, 1, - -2, -3, 2, 0, 0, 1, 1, -1, -1, -4, 1, -2, -1, 2, 2, 0, - 1, -4, 0, -2, -2, 1, 1, -1, 2, -3, 1, -1, -1, 1, 1, -1, - 3, -2, 3, 1, 0, 1, 1, -1, 1, -3, 2, 1, 0, 1, 0, -1, - -1, -5, 1, 0, -1, 0, 1, 1, 0, -3, 3, 3, 1, 2, 3, 3, - 0, -1, -2, 1, 5, 5, 2, -1, 1, -1, -2, -1, 1, 1, -2, -5, - 1, 1, -1, -2, -1, -1, -1, -3, 1, 1, -1, -1, -1, 2, 4, 3, - -1, -1, -1, -1, -1, 0, 4, 3, -1, -1, 0, 1, -1, -3, -1, -1, - 0, 0, 0, 2, 2, 0, 0, -1, 0, -2, -3, 0, 1, 1, 3, 2, - 2, 3, 2, 1, 0, 0, -2, -2, 2, 3, 0, 1, 1, 3, 3, 2, - 0, 0, -3, -1, -1, 2, 2, 3, -2, -2, -3, 1, 1, 2, 1, 1, - -2, -1, -2, 2, 1, 1, -1, -2, 0, 1, 0, 2, 0, 0, -2, -2, - 0, 1, 0, 2, 0, 0, -2, -2, -3, -2, -2, 0, -1, -2, -2, -3, - 0, 1, -1, 3, -1, 1, 3, -1, 0, 1, -1, 3, -1, -1, 2, -3, - 1, 1, -2, 3, -1, -3, 0, -3, 2, 2, -2, 3, 0, -2, 1, -2, - 1, 1, -3, 3, -1, -2, 1, -3, 1, 1, -3, 3, 0, -1, 1, -2, - 1, 2, -1, 4, 0, -1, 1, -2, 0, 1, -1, 3, -1, -3, 0, -3, - -3, -3, -1, 1, 2, 1, -1, -2, -2, -2, 0, 2, 1, 0, -2, -2, - -3, -2, 1, 2, 1, -1, -2, -1, -3, -2, 2, 4, 0, -2, -2, 1, - -3, -1, 2, 4, 0, -2, -2, 2, -1, 1, 4, 3, -1, -3, -2, 2, - 0, 2, 4, 2, -1, -2, -1, 2, 0, 1, 2, 0, -1, 0, 1, 3, - 3, 0, -5, 1, 4, 0, 0, 1, 1, -2, -5, 2, 5, -1, -2, 1, - -1, 0, 0, 3, 3, 1, 0, -1, -2, 3, 4, -2, -3, -1, 0, -2, - -3, 3, 5, -3, -3, 0, 0, -2, -1, 3, 2, -2, -2, 2, 2, -1, - 2, 0, 0, -1, 0, 0, 0, 0, 0, -3, -2, 1, 3, 0, -2, -2 -}; - -/* list of codebooks for inter-coded vectors */ -static uint8_t *inter_codebooks[4] = { - inter_codebook_4x2, inter_codebook_4x4, inter_codebook_8x4, inter_codebook_8x8 -}; - -/* 6x16-entry codebook for intra-coded 4x2 vectors */ -static int8_t intra_codebook_4x2[768] = { - 12, 13, 13, 11, -7,-10,-15,-17,-16,-15,-12,-10, 11, 15, 15, 12, - 2, 17, 20, 15,-45,-24, 2, 13, 21, 20, -6,-36, 12, 16, -1,-27, - -18,-21, 10, 45,-11,-20, -7, 21, 43, -8,-28, 0, 33,-16,-28, 3, - -12,-18,-18, -6,-20,-10, 28, 55, -5,-18,-21,-18, 56, 30, -6,-20, - -34, 27, 29,-22,-30, 29, 26,-25, 30, 34, 33, 26,-25,-31,-35,-33, - -31,-35,-36,-32, 29, 36, 37, 31,-71,-12, 38, 34,-63, -1, 42, 33, - 58, 37,-31,-60, 55, 34,-33,-61,-57,-57, 22, 93,-57,-58, 21, 93, - 59, 69, 70, 62,-63,-68,-68,-60,-64,-71,-71,-64, 63, 73, 72, 62, - -2, 0, 7, 15,-11,-10, -3, 5, -5, -8,-10,-10, 1, 9, 14, 9, - 15, 8, -4,-11, 12, 2,-11,-12, -8, 0, 19, 28, 4, -1,-15,-26, - -15, 27, 2,-14,-14, 22, 1, -9, -4, -6,-13,-10, -6,-14, 6, 47, - -35,-20, 6, 23, 6, 9, 6, 4, -6, 2, 23,-22, -7, 4, 28,-21, - 20,-22, -2, 6, 22,-28, -5, 8,-10,-18,-16,-12, 36, 19, 2, -1, - -3, 0, 4, 8,-45,-10, 23, 23, 40, 15,-20,-35, -4, -1, 4, 1, - 9, -5,-33, 24, 8, 3,-26, 19, -1, 4, 6, -3, 32, 25,-13,-49, - 24, 24, 15, 7,-17,-27,-19, -7,-47, 0, 39, 24,-21, -6, 7, 4, - -1, 0,-10,-13, 1, 1, 5, 16, 20, 5, -3, -9, -1, -4, -2, -6, - -17, -7, 1, 4, 12, 7, 0, 0, 3, 0, 12, 11, -3, 1, 0,-23, - 4, 17, -6, 0, 6, 3,-25, 0,-17, 10, 8, 5,-14, 4, 1, 4, - 13, 10, 4, 2,-23, -9, 1, 2, 3, -3, 1, 7, 1,-23, -7, 20, - -7,-18, 2, 12, -5, -4, 10, 9, 4, 10, 7,-24, 6, 3, 4,-10, - 22,-14,-22, 6, 0, 5, 5, -1, -4, 3,-11, -4, -7, 31, 7,-14, - -5,-16, -1, 42, -4, -2, -9, -5, 5, -8, -6, -3, 42, -4,-21, -5, - -18, 12, 20,-12, 13,-13,-10, 7, -8, -9, -2,-18,-16, 6, 40, 8, - 10, -1, 0, 4, -3, 4, -1,-13, -2, 6, 1,-15, 5, 3, 1, 2, - -4, -2, 1, 3, 15, 0, -9, -4, -3, -4, -4, -4, -3, 5, 16, -3, - 2, 13, 3, 4, -3, -8,-10, 0, -6, -2, -4, -1, -2, -3, -6, 23, - 6, -6, 7, 1, 4,-18, 5, 1, -1, 1,-15, 14, -5, 6, -4, 4, - 2, 2, 2, 6,-24, 2, 7, 3,-26, 0, 3, 3, 5, 7, 1, 6, - 14, -2,-18, -3, 7, 5, -4, 2, -6, 3, 32, 1, -6, -6, -6,-12, - 5,-36, 7, 6, 9, -1, 11, 0, 4, 4, 5, 3, 4, 15, 3,-38, - 10, 23, -5,-42, 0, 4, 4, 4, 23, 17, -6,-13,-13,-37, 1, 29, - 5,-14, -1, 1, 5, 0, 3, 1, 0, 4, -5, 2, 8, 0, 0,-10, - 4, 7, -2, -3,-10, 3, 1, 1,-12, -1, 13, 3, 0, -1, 1, -3, - 0, -1, 3, 1, -6, -9, 3, 9, -6, 1, -4, -6, 8, -1, 0, 8, - -3, -3, 0, 18, -5, -1, -4, -1, -8, -2, 3, -4, 0, 17, -1, -5, - 5, -2, 9,-10, 1, -5, 6, -5, 4, 2, 2, 3, 10,-14, -8, 1, - -1, -2,-18, -1, -1, 20, 1, 2, -1, 1, -9, 1, -1, -9, 22, -4, - 6, -4, 8, -3, -1, 7,-19, 5, -7, 31, -4, -4, -6, 0, -5, -5, - -7, -8,-19, -4, 1, 1, 4, 32, 38, -1, -8, 4, -7, -8, -6,-12, - -1, 0, -7, 1, -1, 9, -1, 0, 9, -1, -1, 0, 2, -6, 1, -3, - -12, 0, 2, 1, 1, 1, 8, 0, 9, 1, 0, 2, -2, 1,-11, 0, - 0, 8, 2,-10, -1, 2, -1, 0, -2, -4, 0, -5, -2, -1, -1, 14, - -3, 7, -1, 5, 0,-10, 1, 1, -1, -5, 14, -1, -2, 1, -3, -2, - -6, 0, 0, 6, 2, 3, -9, 4, 4, -5, -1, -1, -7, 3, 8, -1, - 2, -4, -1,-11, 11, 2, 1, 0, -1, 2, 3, 9, 0, 2, 0,-15, - 3, 5,-20, 3, 3, -1, 3, 3, 1, -1, 16, 1, 2,-29, 9, 2, - -13, -6, -1, -3, 36, -1, -8, -3, 2, 5, 4, 2,-37, 9, 11, 3 -}; - -/* 6x16-entry codebook for intra-coded 4x4 vectors */ -static int8_t intra_codebook_4x4[1536] = { - -11, -3, 3, 6,-10, -1, 5, 7, -9, -1, 6, 7, -9, -1, 4, 6, - 5, 7, 0,-14, 6, 9, 2,-15, 6, 9, 2,-15, 4, 6, 0,-14, - 16, 3, -5, -6, 16, 1, -8, -8, 14, -1, -9, -9, 12, 0, -8, -8, - 8, 12, 16, 17, -2, 2, 6, 9,-10, -8, -4, 0,-15,-14,-11, -7, - -7,-10, -2, 16, -7,-11, -3, 18, -7,-11, -1, 20, -6, -8, 1, 19, - -9,-13,-16,-17, 2, -2, -7, -9, 11, 8, 4, -1, 16, 15, 11, 7, - -22, -2, 13, 15,-24, -2, 14, 16,-25, -4, 13, 15,-25, -6, 10, 13, - 26, 26, 22, 16, 17, 15, 9, 3, -2, -6,-11,-14,-20,-25,-28,-28, - -27,-27,-25,-21,-16,-15,-11, -7, 3, 8, 12, 13, 23, 28, 31, 30, - 20, 16, -7,-33, 22, 19, -6,-35, 22, 19, -6,-34, 20, 17, -6,-32, - -20,-20, 2, 38,-21,-22, 2, 40,-21,-22, 2, 40,-20,-20, 3, 38, - -47, -4, 24, 26,-50, -3, 26, 27,-50, -3, 26, 27,-47, -4, 24, 26, - 45, 6,-23,-27, 48, 5,-25,-28, 48, 5,-26,-28, 44, 6,-24,-27, - -30,-36,-10, 76,-31,-37,-11, 78,-31,-37,-11, 78,-31,-36,-10, 77, - -53,-32, 35, 52,-54,-34, 36, 52,-54,-34, 36, 52,-53,-33, 34, 51, - -93,-34, 62, 65,-93,-34, 62, 66,-93,-34, 62, 65,-93,-34, 60, 64, - -7, 0, 2, 2, -8, -1, 3, 3, -8, 0, 4, 5, -6, 1, 5, 5, - 3, 7, 11, 11, 2, 2, 3, 3, 1, -2, -6, -7, 1, -5,-11,-13, - 3, -2, -4, -3, 7, 0, -5, -5, 12, 4, -5, -7, 14, 6, -4, -7, - 18, 14, 3, -2, 6, 4, 0, -3, -8, -5, -2, 0,-16,-11, -2, 2, - -8, -6, 7, 18, -7, -8, 2, 13, -4, -6, -2, 6, 0, -4, -3, 1, - 1, -3,-13,-18, 0, -1, -5, -7, -1, 1, 6, 7, -2, 4, 15, 17, - -15,-14, -7, -2, -6, -5, -1, 0, 6, 6, 3, 1, 15, 13, 6, 1, - 2, -2,-11, 10, 2, -1,-12, 11, 3, -1,-12, 11, 2, -2,-11, 11, - -9, 14, -1, -5, -9, 15, -2, -5, -8, 16, -2, -5, -7, 15, -1, -4, - 2, 6, 8, 8, -2, 3, 9, 12,-11, -5, 4, 10,-19,-16, -8, 0, - 14, 8, -7,-15, 12, 7, -7,-14, 8, 5, -4, -9, 5, 3, -1, -4, - 12,-14, -2, 2, 13,-15, -1, 3, 14,-15, -1, 3, 13,-14, -1, 3, - 0, 6, 10,-13, 0, 6, 10,-15, 0, 7, 9,-17, 1, 6, 8,-16, - -8, -5, 15, -2, -8, -6, 17, -2, -8, -6, 16, -3, -8, -5, 15, -2, - -9,-11,-11,-10, 9, 10, 9, 8, 8, 10, 10, 9, -8, -9, -8, -7, - 9, 10, 9, 7, -8,-10,-10,-10, -7,-10,-11,-11, 11, 12, 11, 8, - 0, 10, 7, 0, 0, 7, 0, -6, 0, 2, -5, -6, -2, -1, -4, -1, - 5, 0, -6, -9, 2, 2, 2, 1, -2, 0, 5, 7, -6, -5, 1, 4, - 3, -8, 2, -1, 4, -9, 3, 0, 5, -7, 3, 0, 7, -5, 3, 0, - -5, -3, 2, 9, -6, -3, 1, 8, -6, -3, 1, 7, -5, -2, 0, 4, - 13, 8, 3, 1, -3, -5, -4, -1, -8, -7, -3, 0, -1, 1, 3, 2, - 3, 2, -5,-12, 4, 3, -2, -9, 3, 4, 1, -4, 3, 5, 4, -1, - -9, -8, -4, 0, 8, 6, 2, 0, 10, 8, 3, 0, -6, -5, -3, -1, - -3, -9,-12, -5, 0, -3, -5, 0, 2, 3, 2, 4, 5, 8, 7, 6, - -1, -2, 5, 12, -1, -1, 5, 9, 2, 1, -1, -2, 2, -1,-11,-17, - -7, 3, 3, -1, -9, 3, 4, -1,-10, 4, 6, -1, -9, 5, 7, 0, - -18, -7, 2, 2, -8, 1, 5, 3, 3, 4, 1, 0, 9, 5, -2, -3, - -2, 0, 6, 8, -4, -5, -5, -3, 1, -2, -6, -8, 10, 9, 3, -1, - 0, -2, -2, 0, 0, -4, -5, 0, -2, -8, -4, 8, -5, -7, 6, 24, - 9, 1, -7, 1, 9, 1, -8, 1, 8, 0,-10, 1, 8, -1,-11, -1, - 8, 8, 6, 3, 5, 4, 3, 2, -2, -3, -1, 0,-10,-13, -8, -4, - 0, 4, 2, -3, 0, 6, 3, -5, 3, 10, 2,-12, 5, 10, -4,-22, - 0, -4, -1, 3, 1, -4, -1, 5, 1, -5, 0, 8, -1, -6, -2, 7, - -1, -1, -2, -4, -1, -2, -4, -6, -1, -1, -1, -2, 1, 5, 10, 9, - 10, 3, 0, -2, 6, -1, -2, -5, 3, -1, -2, -6, 2, 0, 0, -5, - 6, 3, 0, 0, 6, 3, 1, 1, 4, -2, -2, 1, 0, -9, -9, -2, - -11, -3, 1, 2, -6, 2, 4, 5, -3, 2, 3, 4, -2, 1, 1, 2, - -6, -4, -1, -2, 2, -1, -1, -2, 10, 2, -2, -2, 11, 2, -4, -1, - 6, 0, -2, 2, 3, 3, 0, 0, -6, 3, 3, 0,-17, -1, 5, 0, - -1, 4, 10, 11, -3, -2, 0, 1, -3, -4, -5, -3, -1, -2, -2, -1, - 2, -3, -9,-12, 3, 3, 3, 2, 2, 2, 4, 4, 2, 1, -1, -2, - -2, 9, 5,-10, -3, 5, 5, -5, -2, 1, 2, 0, -1, -2, -2, 1, - -2, -3, 7, -2, -1, -3, 7, -3, -1, -2, 8, -4, -2, -2, 7, -3, - 1, -8, -3, 12, 2, -2, -2, 4, 1, 3, 0, -5, -1, 5, 2, -7, - -1, 3, 1, -5, -7, -2, 3, 1, -2, -7, -2, 2, 20, 3, -5, -1, - 5, 0, -3, -2, -7, -7, 0, 6, -6, 0, 7, 6, 2, 6, 0, -7, - -2, 6, -7, 1, -2, 7, -8, 3, -2, 7, -7, 3, -1, 7, -6, 2, - -5, -2, 5, 7, 4, 1, -4, -8, 6, 3, -2, -5, -7, -5, 3, 7, - -1, -1, 6, 5, 0, -1, 1, -4, 2, 1, 0, -7, 1, 0, 0, -4, - -8, 0, 3, 1, -2, 1, -1, -1, 1, -1, -3, 1, 1, -2, 1, 9, - 5, 2, -3, -4, -1, 0, -1, -3, -3, 1, 3, 1, -4, 0, 4, 2, - 2, -2, -2, 12, 0, -2, -5, 3, -1, 0, -3, 1, -3, -1, -2, 1, - 1, 5, 3, 0, -6, -4, -2, 1, 0, -2, -2, 2, 6, 1, -4, -1, - -3, -5, -5, -1, 3, 5, 5, 4, 0, 3, 1, -1, -2, 1, -2, -3, - 2, -4, -5, -3, 4, -2, -3, -2, 6, 0, -1, -1, 7, 1, 0, 0, - -3, -2, -2, 0, -2, -3, -5, -1, -2, 2, 0, -1, -1, 11, 9, -1, - 0, 1, -1,-10, -1, 1, 0, -6, 1, 0, 1, 4, 2, -5, -1, 13, - -2, 4, 5, 0, -5, 1, 6, 3, -6, -2, 3, 2, -5, -2, 0, -2, - -1, 1, 1, -2, -1, -2, 0, 2, 5, 5, 5, 7, 0, -4, -8, -7, - 0, 2, -1, -5, -1, 2, 2, -3, 0, 5, 3, -5, 3, 8, 2,-12, - 8, 4, 0, -2, 10, -1, -4, -1, 3, -6, -3, 0, -4, -5, 0, 0, - 0,-10, -4, 2, -1, -6, 3, 5, -1, -3, 6, 4, 0, -2, 4, 2, - 0, 8, 1, -1, 0, 11, 1, -3, -1, 6, -2, -4, -3, -2, -7, -4, - 0, -1, -1, -1, 4, 5, 6, 5, -5, -9, -8, -5, 2, 2, 3, 2, - 0, 2, 6, 1, 2, 0, 3, 0, 1, -2, -1, -2, 0, -1, -3, -6, - 0, 0, 2, 0, 4, 0, 2, 1, 5, -2, 0, 0, -2, -9, -1, 2, - 0, 1, 0,-10, -1, 1, 8, 0, -1, -2, 4, 0, 1, -1, 2, -1, - -3, -2, 2, -1, -3, -1, 2, -3, 0, -1, 1, 0, 8, 1, -1, 3, - 0, 1, 1, 2, 0, -4, -2, 0, -1, -5, 1, -1, -2, -1, 11, 2, - 1, 5, -2, -2, 0, 2, -4, 0, -2, 1, -5, 1, 0, 5, 0, 1, - -5, -3, 0, 6, -4, 2, 0, 0, -3, 5, 1, 0, -3, 3, 0, 0, - 3, -2, -3, 1, 1, -4, 0, 8, -2, -3, -2, 3, 1, 2, -1, -1, - 1, 1, 0, 2, 2, 0, 1, 6, 1, -1, 2, 1, 0, 3, 0,-19, - 1, -3, -2, 2, 6, 5, -2, -7, -3, 1, 3, 1, -1, -1, 0, 2, - -8, -1, -1, -4, 1, 1, -1, 2, 4, 3, 2, 3, -5, 1, 3, 0, - 0, 2, -1, 1, -3, 0, 0, 5, -5, -2, 0, 8, -4, -4, -4, 6, - 1, 2, 1, 2, 2, 2, -3, 2, 4, 0, -9, 0, 7, 0,-11, 1, - 0, 0, 0, -2, 3, 3, -1, -6, 4, 3, -3,-10, -1, 2, 6, 2, - 7, -2, -3, 5, -4, 0, 3, -1, -4, 2, 1, -7, 2, -1, -1, 3, - 3, 2, 2, 2, -5, -7, -7, -5, 5, 6, 4, 2, -2, -1, 0, 1 -}; - -/* 6x16-entry codebook for intra-coded 8x4 vectors */ -static int8_t intra_codebook_8x4[3072] = { - 5, 6, 6, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 1, 2, 3, - -3, -4, -4, -5, -5, -4, -3, -2, -4, -4, -4, -5, -4, -4, -3, -3, - 1, 2, 2, 2, 2, 3, 3, 3, 2, 3, 3, 4, 4, 5, 5, 5, - -1, 0, 1, 1, 2, 3, 4, 4, -9,-10, -9, -9, -8, -7, -6, -5, - -4, -4, -5, -6, -6, -7, -7, -7, 0, -1, -2, -2, -3, -3, -4, -4, - 4, 4, 3, 3, 2, 1, 1, 0, 7, 7, 7, 6, 6, 5, 4, 4, - 2, 4, 5, 6, 4, 1, -3, -6, 3, 4, 5, 5, 4, 0, -5, -8, - 2, 3, 4, 4, 2, -2, -7,-10, 2, 2, 2, 1, 0, -4, -9,-12, - -9, -7, -3, 1, 4, 4, 3, 3,-10, -7, -2, 3, 5, 5, 3, 3, - -9, -6, -2, 3, 6, 5, 4, 3, -8, -6, -1, 3, 4, 4, 3, 2, - -5, -5, -5, -5, -3, 1, 4, 7, -5, -5, -5, -4, -2, 1, 6, 8, - -4, -5, -4, -3, -1, 3, 8, 10, -3, -4, -3, -2, 1, 5, 9, 11, - -2, -2, -2, -2, -2, -2, -2, -2, -4, -5, -5, -5, -5, -5, -5, -4, - -3, -4, -4, -4, -4, -4, -4, -3, 9, 10, 10, 11, 11, 11, 10, 10, - 7, 4, 1, -2, -4, -6, -9,-10, 9, 7, 3, 0, -2, -4, -8, -9, - 11, 8, 4, 2, 0, -3, -6, -8, 11, 9, 5, 3, 1, -2, -5, -7, - -13,-13,-13,-12,-11,-10, -8, -8, 0, 1, 2, 3, 4, 4, 4, 3, - 3, 4, 5, 6, 6, 6, 5, 4, 3, 4, 4, 4, 3, 3, 3, 2, - 10, 10, 11, 10, 9, 9, 8, 7, 6, 6, 6, 6, 5, 4, 3, 2, - 0, 0, 0, -1, -2, -3, -4, -4,-10,-10,-11,-12,-13,-14,-14,-14, - 16, 16, 17, 16, 15, 13, 12, 11, -1, -2, -3, -4, -4, -4, -4, -3, - -4, -5, -6, -6, -6, -6, -6, -6, -5, -6, -6, -6, -6, -6, -5, -5, - -13,-13,-13,-12,-11,-10, -8, -6, -9, -8, -7, -6, -4, -2, 0, 1, - -2, -1, 1, 3, 5, 7, 8, 9, 5, 7, 9, 11, 13, 14, 15, 15, - 16, 14, 11, 7, 2, -3, -7, -9, 14, 12, 8, 3, -1, -6, -9,-11, - 11, 9, 4, 0, -4, -8,-11,-13, 8, 5, 1, -3, -6,-10,-12,-14, - -18,-15, -9, -3, 1, 6, 9, 11,-17,-13, -7, -1, 3, 7, 11, 12, - -15,-11, -5, 1, 5, 9, 12, 13,-13, -9, -3, 2, 5, 9, 11, 13, - 22, 21, 19, 15, 10, 3, -4, -9, 20, 18, 15, 9, 2, -5,-12,-17, - 16, 13, 8, 1, -7,-14,-20,-24, 10, 6, -1, -8,-15,-21,-25,-27, - -25,-23,-20,-14, -7, 1, 9, 14,-23,-21,-16, -9, 0, 9, 16, 21, - -20,-16,-10, -1, 8, 16, 22, 25,-15,-11, -3, 6, 14, 20, 25, 27, - -4, -2, 0, 1, 2, 2, 2, 2, -5, -2, 0, 2, 3, 3, 3, 3, - -6, -4, -1, 1, 2, 3, 3, 3, -7, -5, -2, 0, 1, 1, 2, 2, - 2, 1, 1, 1, 1, 0, -2, -3, 3, 3, 2, 1, 0, -1, -3, -4, - 4, 3, 2, 1, 0, -2, -4, -6, 5, 4, 3, 1, -1, -3, -5, -6, - 5, 6, 6, 4, 2, 0, -2, -3, 3, 4, 4, 4, 3, 1, 0, -1, - -2, -2, -1, -1, -1, -1, -2, -2, -5, -4, -3, -2, -2, -2, -3, -3, - -1, -1, -1, -1, -1, -1, -1, -1, -3, -4, -4, -4, -3, -3, -3, -3, - -1, -1, -1, -1, -1, -1, -1, -2, 5, 6, 6, 6, 6, 5, 4, 3, - 4, 4, 4, 4, 4, 5, 6, 7, 0, -1, -1, -1, -1, 0, 1, 2, - -2, -3, -3, -3, -3, -2, -1, 0, -3, -3, -4, -4, -4, -3, -2, -1, - 0, -2, -4, -4, -2, 0, 2, 3, 0, -2, -3, -3, -1, 2, 4, 5, - -1, -2, -4, -3, 0, 3, 5, 6, -2, -3, -4, -3, -1, 2, 4, 5, - 9, 4, 0, -3, -3, -1, 0, 1, 8, 4, -1, -4, -3, -1, 1, 2, - 6, 2, -3, -5, -4, -2, 0, 1, 5, 1, -3, -4, -4, -2, 0, 1, - 5, 3, 1, -1, -4, -8,-10,-10, 3, 3, 2, 1, 0, -2, -3, -4, - 1, 1, 1, 2, 3, 2, 1, 0, -1, 0, 1, 2, 3, 4, 3, 2, - 0, 1, 2, 2, 1, -1, -3, -3, 0, 1, 1, 1, -1, -2, -4, -3, - -3, -3, -3, -3, -3, -3, -1, 2, -4, -4, -3, 0, 3, 7, 12, 14, - -5, -5, -6, -6, -6, -6, -6, -5, 2, 2, 2, 1, 0, 0, 0, 0, - 4, 4, 3, 2, 1, 0, 0, 0, 6, 6, 5, 4, 2, 2, 1, 1, - -7, -7, -6, -3, 0, 4, 7, 8, -1, -2, -3, -3, -2, -1, 1, 2, - 3, 3, 1, -1, -2, -2, -2, -1, 6, 6, 4, 2, 0, -2, -2, -2, - -6, -5, -2, 2, 5, 9, 11, 12, -4, -4, -2, 0, 2, 4, 5, 6, - -3, -2, -2, -2, -2, -1, 0, 1, -2, -2, -2, -3, -3, -3, -3, -2, - -7, -3, 1, 3, 3, 0, -3, -5, -6, -2, 3, 5, 4, 1, -3, -5, - -5, -1, 4, 6, 5, 2, -3, -4, -4, 0, 5, 7, 6, 3, -1, -3, - 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -3, -3, -3, -3, -2, -1, - 6, 7, 8, 9, 9, 8, 7, 6, -4, -4, -5, -5, -6, -6, -5, -4, - -9, -8, -6, -4, 0, 3, 6, 6, -5, -4, -1, 3, 5, 6, 5, 3, - 1, 3, 6, 6, 4, 1, -2, -5, 6, 7, 5, 1, -3, -7,-10,-11, - 10, 9, 5, 1, -3, -6, -6, -4, 5, 3, -1, -5, -6, -5, -2, 2, - -2, -4, -6, -6, -4, 1, 6, 10, -6, -7, -7, -4, 1, 7, 11, 12, - 6, 5, 3, 2, 0, 0, 0, 0, 2, 1, -1, -2, -3, -2, -1, -1, - 0, -1, -2, -4, -4, -2, -1, 1, 0, 0, -1, -2, -1, 0, 2, 3, - 0, -1, -2, -2, -2, -2, -1, -1, 5, 4, 2, 1, 0, 0, 0, 0, - 6, 5, 3, 1, 0, 0, 0, 0, 2, 0, -2, -4, -4, -3, -2, -2, - -7, -4, 0, 2, 2, 2, 2, 1, -7, -3, 0, 0, 0, 0, 0, 0, - -4, -1, 1, 1, 0, 0, 0, 1, -1, 1, 2, 2, 2, 2, 3, 3, - -2, 0, 2, 2, 1, 1, 1, 1, -1, 1, 2, 2, 1, 0, 0, -1, - 0, 2, 4, 2, 0, -1, -2, -3, 1, 2, 3, 1, -2, -4, -6, -6, - 1, 2, 2, 4, 5, 6, 4, 1, 0, -1, -1, -1, 0, 0, -2, -4, - 0, 0, -1, -2, -2, -2, -4, -6, 2, 1, 0, 0, 1, 1, -1, -3, - 1, 1, 1, 1, 1, 2, 3, 3, 0, 0, 1, 0, 1, 2, 4, 4, - -1, -1, -1, -1, 0, 1, 2, 3, -4, -4, -5, -5, -5, -3, -1, 0, - -6, -5, -5, -4, -3, -2, -1, -1, -1, 0, 0, 1, 1, 2, 3, 3, - 0, 1, 1, 1, 2, 2, 3, 4, 0, 0, -1, -1, 0, 1, 2, 3, - 0, 1, 1, 1, 0, 0, -1, -1, 1, 3, 3, 2, 1, -1, -2, -2, - -2, 0, 2, 2, 2, 2, 1, 1, -9, -8, -4, -2, 1, 3, 3, 3, - -1, -1, -1, -2, -3, -3, -3, -4, 0, 0, 0, -1, -2, -2, -3, -3, - 2, 2, 2, 0, -1, -1, -1, -1, 5, 5, 4, 3, 2, 2, 2, 2, - 6, 3, -1, -4, -3, -1, 1, 1, 2, -1, -3, -4, -1, 2, 2, 0, - -1, -2, -2, 1, 4, 4, 1, -3, -2, -1, 1, 4, 6, 3, -3, -8, - 3, 3, 2, 1, -1, -2, -2, -2, -4, -4, -2, -1, 1, 3, 4, 4, - -4, -5, -5, -4, -2, 0, 2, 2, 7, 7, 4, 1, -1, -2, -3, -2, - -1, 1, 3, 0, -4, -6, 0, 6, -2, 1, 4, 1, -4, -6, -1, 7, - -3, 1, 4, 2, -3, -6, -1, 6, -2, 0, 3, 2, -2, -5, -1, 4, - 1, -1, -2, 1, 4, 4, -1, -7, 1, -1, -4, -1, 5, 6, 0, -6, - 3, 0, -4, -3, 3, 6, 2, -4, 3, 0, -5, -4, 1, 4, 1, -3, - 2, 2, 3, 3, 3, 3, 2, 2, -4, -5, -6, -7, -7, -7, -7, -6, - 1, 2, 3, 3, 3, 3, 2, 2, 0, 0, 1, 1, 1, 2, 2, 1, - 3, -3, -3, 3, 4, -2, -2, 2, 3, -4, -4, 4, 4, -4, -4, 2, - 4, -4, -4, 4, 4, -4, -3, 3, 3, -3, -4, 3, 3, -3, -3, 3, - -2, -2, -2, -2, -2, -2, -1, -1, 6, 7, 8, 8, 8, 7, 6, 5, - -5, -6, -7, -7, -8, -7, -6, -5, 1, 1, 2, 2, 2, 2, 1, 1, - 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, - -2, -3, -2, -2, -2, -3, -3, -3, 2, 3, 5, 6, 4, 2, 1, 0, - 8, 6, 2, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0, -1, -1, -1, - 1, -1, 0, 0, 0, -1, -2, -3, -2, -2, -1, 0, 0, -2, -4, -5, - 3, 1, -1, -2, -3, -4, -5, -5, 2, 1, 0, 0, 1, 1, 0, 0, - 0, -1, -1, 0, 2, 2, 2, 2, -1, -2, -1, 1, 2, 2, 2, 2, - 0, -1, -2, -1, -1, -1, -1, 0, -1, -2, -2, -1, -1, 0, 0, 1, - 2, 1, 1, 2, 2, 1, 1, 0, 6, 5, 3, 1, 0, -2, -4, -4, - -3, -2, -1, 0, 1, 1, 0, -1, 0, 1, 3, 4, 5, 5, 3, 1, - -1, -1, -1, 0, 1, 0, -1, -2, -2, -2, -2, -1, 0, -1, -2, -3, - 0, -1, -2, -2, -1, -1, 0, 2, 1, -1, -2, -1, -1, -1, 0, 2, - 1, 0, -2, -2, -2, -2, 1, 5, 1, -1, -2, -2, -2, 0, 5, 10, - 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 1, 2, - 1, 2, 2, 3, 4, 4, 6, 5, -3, -3, -3, -2, -2, -3, -3, -3, - 1, -1, -2, -2, 0, 3, 5, 7, 2, 0, -2, -3, -2, 0, 2, 3, - 3, 1, -2, -3, -3, -2, -1, -1, 3, 1, 0, -1, -1, -1, -1, -1, - 1, 3, 5, 4, 2, -1, -3, -4, -3, -2, 1, 2, 1, 0, -1, -2, - -5, -3, 0, 2, 2, 1, 0, 0, -3, -1, 1, 2, 2, 1, 0, 0, - 0, -1, -1, -1, 1, 2, 3, 4, -3, -4, -4, -3, -1, 0, 0, 1, - -2, -3, -2, -1, 1, 1, 1, 1, -2, -2, 0, 3, 4, 4, 3, 2, - -4, -4, -3, -2, -1, 1, 2, 3, 0, 1, 1, 1, -1, -2, -3, -3, - 3, 4, 5, 4, 2, -1, -3, -3, -2, -2, 0, 2, 2, 2, 1, 0, - -4, 0, 5, 7, 4, -1, -4, -4, -1, 2, 4, 3, 0, -3, -3, -2, - 2, 1, 0, -1, -2, -2, 0, 1, 0, 0, -1, -2, -2, -1, 1, 2, - -4, -3, -2, -1, 0, 1, 2, 2, 10, 9, 5, 0, -3, -4, -3, -2, - 1, -1, -2, -2, -1, 0, 0, 0, -2, -2, -1, 1, 1, 1, 0, -1, - -5, -3, 0, 3, 4, 2, 0, -2, -2, -1, 0, 1, 1, 0, -1, -1, - 3, 2, -1, -2, -2, -1, 1, 1, 7, 5, -1, -5, -6, -2, 2, 4, - -2, 3, 3, -3, -4, 1, 2, -2, -3, 3, 4, -3, -4, 2, 3, -2, - -3, 3, 4, -3, -4, 2, 3, -2, -4, 2, 4, -2, -3, 1, 2, -1, - 4, 3, -1, -3, -3, -1, 1, 2, -4, -6, -4, 0, 4, 5, 4, 1, - 0, 2, 5, 6, 2, -3, -5, -4, 1, 1, -1, -3, -5, -2, 2, 4, - -1, 0, 1, 2, 2, 3, 3, 4, -1, 0, 1, 1, 0, -1, -1, -1, - -1, 0, 1, 2, 2, 1, -1, -2, -3, -2, -1, 0, 0, -1, -2, -3, - 1, 1, 1, 1, 0, 0, 1, 2, 1, 0, -1, 0, 0, 1, 1, 0, - 1, -2, -4, -1, 1, 2, 1, 0, 1, -4, -7, -3, 1, 3, 2, 1, - 1, 1, 1, 1, 1, 1, 0, -1, 1, 1, 1, 0, 1, 2, 2, 0, - 1, 1, 0, 0, 0, 2, 0, -3, 3, 2, 0, -1, -1, -2, -6, -9, - 0, 0, 0, 1, 0, 0, 1, 2, 1, 0, 0, 0, -1, -1, 0, 2, - 0, 1, 1, 1, -1, -3, -2, 0, -7, -5, 1, 6, 6, 2, -1, -1, - 3, 1, -1, -3, -4, -2, 1, 4, 2, 0, -2, -3, -4, -3, -1, 2, - 2, 2, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, - -1, 1, 1, -2, -5, -6, -4, -1, -1, 1, 4, 3, 2, 0, 1, 2, - -1, 0, 2, 3, 1, 0, 0, 1, -1, 0, 1, 0, 0, -1, -1, 0, - 0, 1, 2, 2, 0, -2, -1, 1, -2, -1, -1, -2, -1, 2, 6, 8, - -1, -1, -2, -3, -2, 0, 1, 2, -1, 0, 0, -1, -1, 0, -1, -1, - 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, -1, -1, 1, - -1, 0, 2, 2, -1, -3, -2, 3, 0, 2, 3, 0, -5, -7, -2, 4, - -1, 0, 0, 0, -1, -2, -3, -3, -1, 0, -1, -2, -2, -2, -2, -2, - 1, 1, 0, 0, 1, 2, 0, -1, 1, 2, 1, 2, 5, 6, 2, 0, - -2, -4, -3, 0, 2, 2, 0, -3, 3, 1, 0, 1, 2, 1, -2, -3, - 3, 1, 0, 0, 0, 0, 0, -1, 1, -1, -2, -2, -1, 1, 3, 3, - 3, 2, 1, 2, 4, 3, 1, -2, -2, -4, -4, -3, -1, 0, -2, -3, - 1, 0, -1, -1, 0, 1, 0, -1, 3, 2, 0, 0, 0, 1, 1, 0, - 1, 1, 0, 0, 0, 0, 0, 0, 2, 3, 3, 2, 2, 2, 1, 1, - 0, -1, -2, -3, -5, -5, -5, -4, 1, 1, 0, -1, 0, 1, 3, 3, - -9, -6, -2, 0, 1, 1, 2, 2, -6, -2, 1, 2, 1, 1, 0, 1, - -2, 1, 2, 2, 1, 1, 1, 1, 0, 2, 2, 1, 0, 1, 1, 1, - 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, -3, -2, 0, - -3, -3, -3, -2, -1, 3, 7, 9, 1, 2, 2, 2, 0, -2, -4, -3, - 2, 0, -2, -1, 3, 4, -1, -6, 1, 0, -2, -3, -1, 3, 3, 0, - 0, 3, 3, 0, -2, -1, 1, 1, -6, -1, 3, 2, -1, -2, 0, 1, - 5, 3, 0, -2, -3, 0, 2, 1, 1, 1, 2, 2, 0, -2, -4, -7, - -3, -2, 1, 2, 2, 1, -1, -4, 2, 2, 0, -2, -2, 0, 2, 2, - 0, 0, -2, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, - -2, -1, 0, 1, 0, 1, 2, 3, -4, -2, 0, 0, -1, 0, 2, 3, - -2, -2, -2, -1, -1, 0, 2, 4, 0, 0, 0, 0, -1, -1, 0, 1, - 0, -1, -1, -1, -1, -1, 0, 0, 6, 4, 2, 0, -1, -2, -1, -1, - 0, 1, 1, 1, 1, -1, -5,-10, 1, 1, 1, 1, 1, 1, 0, -4, - 1, 0, 1, 1, 1, 1, 1, -1, 2, 1, 1, 1, 0, 0, 0, 0, - -3, 1, 4, 3, 3, 1, -1, 0, -4, 0, 1, 0, -1, 0, 0, 0, - -5, 0, 2, 1, 1, 1, 0, -1, -1, 2, 1, -2, -2, -1, 0, -1, - 2, 4, 5, 3, 0, -1, 1, 2, 0, 0, 1, 0, -2, -2, -1, -1, - -2, -2, -2, -2, -3, -2, -1, 0, 0, 0, 1, 0, 0, 0, 1, 2, - 0, -2, -2, -3, -1, 2, 2, -1, 1, 0, 0, 0, 1, 5, 3, -2, - -1, -1, 0, -1, 0, 2, 0, -5, -1, 0, 1, 0, 0, 2, 2, -2, - 3, 1, -1, -1, 0, 1, 1, 2, 1, 0, 0, 1, 1, 1, 1, 1, - -10, -8, -2, 1, 2, 1, 1, 1, -1, 1, 2, 1, 0, 0, 0, 0, - -1, -1, 0, 1, 2, 2, 2, 1, -1, -1, -1, 0, -1, -3, -5, -4, - 1, 1, 2, 1, 1, 0, 0, 2, -1, -2, -1, -1, -1, 0, 2, 4, - -3, -7, -5, 0, 2, 0, 0, 0, 3, -1, -2, 1, 2, 1, 1, 2, - 1, -2, -1, 1, 2, 1, 0, 1, 0, -1, 0, 3, 2, -1, -1, -1, - 2, 1, 1, 0, 0, 0, 0, 0, -9, -7, -2, 3, 3, 2, 1, 1, - 3, 2, 0, -2, -2, -1, 1, 1, 0, -1, 0, 0, 1, 1, 0, 0, - -2, -1, 1, 1, 1, 0, 0, 0, 1, 2, 1, -2, -4, -3, 1, 2, - 1, 2, 1, -2, -3, 0, 3, 1, -1, -1, 0, 0, 1, 3, 0, -4, - 2, 0, -1, 1, 2, -2, -2, 3, 2, 0, -1, 2, 3, -2, -4, 1, - 0, 1, 1, 1, 2, -2, -6, -2, -1, 0, 0, 0, 2, 0, -2, -1, - -1, -1, 1, 2, 1, -2, -3, -2, 3, -1, -2, -1, -1, 0, 1, 2, - 10, 4, 0, 0, -1, -2, -2, -1, 3, -1, -2, -1, 0, -1, -1, 0, - -5, 2, 7, 1, -4, -2, 1, 0, -2, 2, 3, -1, -3, 0, 2, 0, - 2, 1, 0, 0, 1, 1, -1, -2, 1, -2, -2, -1, -1, -2, 0, 0, - 0, 3, -2, -7, -1, 3, 0, 0, 1, 3, -3, -5, 2, 3, -1, 0, - 0, 2, -2, -2, 4, 2, -2, 0, -1, 1, -1, 0, 2, -1, -2, 1, - 4, 0, -3, -4, -2, 1, 2, 1, 0, 0, 3, 5, 3, 1, -1, -2, - 1, 1, 1, -1, -3, -1, 1, 1, 1, -1, -2, -2, 0, 0, -1, -2 -}; - -/* 6x16-entry codebook for intra-coded 8x8 vectors */ -static int8_t intra_codebook_8x8[6144] = { - 4, 4, 3, 2, 2, 1, 0, -1, 4, 3, 3, 2, 1, 0, -1, -1, - 3, 3, 2, 2, 1, 0, -1, -2, 3, 2, 2, 1, 0, -1, -2, -3, - 2, 2, 1, 0, -1, -1, -2, -3, 2, 1, 0, 0, -1, -2, -3, -4, - 1, 0, 0, -1, -2, -3, -4, -4, 0, 0, -1, -2, -2, -3, -4, -4, - 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, - 1, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1, 1, - -1, 0, 0, 0, 0, 0, 1, 1, -2, -2, -1, -1, -1, -1, -1, -1, - -3, -3, -3, -3, -3, -3, -2, -2, -5, -4, -4, -4, -4, -4, -4, -3, - -4, -2, -1, 0, 1, 2, 2, 3, -4, -2, -1, 0, 1, 2, 3, 3, - -4, -3, -1, 0, 1, 2, 3, 3, -4, -3, -1, 0, 1, 2, 3, 3, - -5, -3, -1, 0, 1, 2, 3, 3, -5, -3, -1, 0, 1, 2, 3, 3, - -5, -3, -1, 0, 1, 1, 2, 3, -5, -3, -2, -1, 0, 1, 2, 3, - 4, 4, 5, 5, 6, 6, 7, 7, 2, 2, 2, 3, 3, 4, 4, 4, - 0, 0, 0, 0, 1, 1, 1, 2, -2, -2, -2, -2, -1, -1, -1, 0, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -1, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -2, -2, -2, -2, - 5, 3, 1, -1, -2, -3, -3, -3, 5, 3, 1, -1, -2, -3, -3, -3, - 5, 3, 1, -1, -2, -3, -3, -3, 5, 3, 1, -1, -2, -3, -3, -3, - 5, 4, 1, 0, -2, -3, -3, -3, 6, 4, 2, 0, -2, -2, -3, -3, - 6, 4, 2, 0, -1, -2, -2, -3, 6, 4, 2, 1, -1, -2, -2, -2, - -1, 1, 3, 3, 2, 0, -3, -6, -1, 1, 3, 4, 3, 0, -3, -6, - -1, 1, 4, 4, 3, 1, -3, -6, -1, 1, 3, 4, 3, 1, -3, -6, - -2, 1, 3, 4, 3, 1, -3, -6, -2, 1, 3, 4, 3, 1, -3, -7, - -2, 1, 3, 3, 2, 0, -3, -7, -2, 0, 2, 3, 2, 0, -3, -6, - 10, 9, 8, 6, 6, 5, 4, 4, 6, 5, 4, 3, 2, 2, 2, 1, - 2, 1, 0, -1, -2, -2, -2, -1, -1, -2, -3, -4, -4, -4, -4, -3, - -2, -3, -4, -4, -5, -4, -4, -3, -2, -2, -3, -3, -3, -3, -2, -2, - -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 1, 1, 1, 1, 1, 2, - -2, -1, 1, 2, 4, 5, 7, 8, -3, -2, 0, 1, 3, 5, 7, 8, - -4, -3, -1, 0, 2, 4, 6, 7, -5, -4, -2, -1, 1, 3, 5, 7, - -6, -5, -3, -2, 0, 2, 4, 6, -6, -5, -4, -2, -1, 1, 3, 5, - -7, -6, -5, -3, -2, 0, 2, 3, -8, -7, -5, -4, -3, -1, 1, 2, - 11, 9, 7, 5, 3, 1, -1, -1, 10, 8, 6, 3, 1, 0, -2, -2, - 9, 7, 5, 2, 0, -2, -3, -4, 8, 6, 3, 1, -1, -3, -4, -4, - 6, 4, 2, -1, -3, -4, -5, -5, 5, 3, 0, -2, -4, -5, -6, -6, - 3, 1, -1, -3, -5, -6, -7, -7, 2, 0, -2, -4, -6, -6, -7, -7, - 5, 6, 7, 7, 7, 8, 8, 8, 3, 4, 5, 5, 6, 6, 6, 6, - 0, 2, 2, 3, 4, 4, 4, 5, -2, -1, 0, 1, 2, 2, 3, 3, - -4, -3, -2, -1, 0, 1, 1, 2, -6, -5, -4, -3, -2, -2, -1, 0, - -8, -7, -6, -6, -5, -4, -3, -3,-10, -9, -8, -8, -7, -6, -6, -5, - 6, 5, 3, 1, -1, -3, -6, -8, 6, 5, 4, 2, -1, -3, -6, -8, - 6, 5, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, 0, -3, -6, -8, - 6, 6, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, 0, -3, -6, -8, - 6, 5, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, -1, -3, -5, -8, - 11, 10, 9, 8, 7, 6, 5, 4, 8, 8, 7, 6, 5, 4, 3, 2, - 6, 5, 4, 4, 2, 2, 1, 0, 3, 3, 2, 1, 0, 0, -1, -2, - 1, 1, 0, -1, -2, -2, -3, -3, -1, -1, -2, -3, -4, -4, -5, -5, - -3, -4, -4, -5, -6, -6, -7, -7, -5, -5, -6, -7, -8, -8, -8, -8, - -14,-13,-12,-11, -9, -7, -6, -4,-12,-11,-10, -9, -7, -5, -3, -1, - -10, -9, -7, -6, -3, -2, 0, 2, -8, -6, -4, -2, 0, 2, 4, 5, - -5, -3, 0, 2, 4, 5, 7, 8, -2, 0, 2, 4, 6, 8, 9, 10, - 0, 3, 5, 7, 8, 10, 11, 12, 3, 5, 7, 8, 10, 11, 12, 12, - -19,-19,-18,-18,-17,-16,-15,-14,-15,-15,-14,-13,-12,-11,-10, -9, - -11,-10, -9, -8, -6, -5, -4, -3, -6, -5, -3, -2, -1, 0, 1, 2, - -1, 0, 2, 3, 4, 5, 6, 6, 4, 6, 7, 8, 9, 10, 10, 10, - 9, 10, 11, 12, 13, 14, 14, 14, 12, 14, 14, 15, 16, 16, 16, 16, - 22, 21, 19, 17, 14, 11, 9, 5, 20, 19, 17, 14, 11, 8, 4, 1, - 17, 15, 13, 10, 6, 3, 0, -4, 13, 11, 8, 5, 1, -2, -5, -9, - 9, 6, 3, -1, -4, -7,-11,-13, 4, 0, -3, -6, -9,-12,-15,-17, - -2, -5, -8,-11,-14,-16,-18,-20, -8,-10,-13,-16,-17,-19,-21,-22, - 17, 18, 18, 18, 17, 16, 16, 14, 16, 16, 15, 15, 14, 13, 12, 11, - 12, 12, 11, 10, 9, 8, 7, 5, 7, 6, 6, 4, 3, 2, 1, -1, - 1, 0, -1, -2, -3, -4, -5, -6, -5, -6, -7, -8, -9,-10,-11,-12, - -11,-12,-13,-14,-15,-16,-16,-17,-16,-17,-17,-18,-19,-20,-20,-20, - 0, 0, 0, 0, -1, -1, -2, -3, 1, 0, 0, 0, 0, -1, -2, -3, - 1, 1, 0, 0, -1, -1, -2, -2, 1, 1, 1, 0, 0, -1, -1, -2, - 2, 1, 1, 1, 0, -1, -1, -2, 2, 2, 1, 1, 0, 0, -1, -2, - 2, 2, 1, 1, 1, 0, -1, -1, 2, 2, 1, 1, 1, 0, 0, -2, - 0, -1, -1, 0, 0, 1, 2, 3, 0, -1, -1, 0, 1, 1, 2, 2, - -1, -1, -1, -1, 0, 1, 2, 2, -1, -1, -2, -1, 0, 1, 1, 2, - -1, -2, -2, -1, 0, 0, 1, 2, -1, -2, -2, -2, -1, 0, 1, 2, - -1, -1, -2, -1, 0, 0, 1, 2, -1, -1, -1, -1, 0, 1, 1, 2, - 3, 2, 2, 2, 1, 1, 0, 0, 3, 2, 2, 2, 2, 1, 0, 0, - 2, 2, 2, 1, 1, 1, 0, 0, 2, 2, 1, 1, 1, 0, 0, -1, - 1, 1, 1, 0, 0, 0, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -2, -2, -2, -2, - 5, 2, 0, 0, -1, 0, 0, 0, 4, 2, 0, -1, -1, -1, 0, -1, - 4, 1, -1, -1, -2, -1, -1, -1, 4, 1, -1, -1, -2, -1, -1, -1, - 4, 1, -1, -2, -2, -1, -1, -1, 4, 1, -1, -2, -2, -1, -1, -1, - 4, 1, -1, -1, -1, -1, -1, -1, 4, 2, 0, -1, 0, 0, 0, -1, - -2, -1, 0, 1, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 1, 1, - -3, -1, 0, 1, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 1, 1, - -3, -2, 0, 1, 2, 2, 1, 1, -4, -2, 0, 1, 2, 2, 2, 2, - -5, -3, -1, 1, 1, 2, 1, 2, -5, -3, -2, 0, 1, 1, 1, 1, - 3, 3, 1, 0, -2, -4, -4, -5, 3, 3, 2, 0, -1, -2, -3, -4, - 2, 2, 1, 1, 0, -1, -2, -2, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, -2, -1, -1, 0, 0, 1, 2, 2, - -3, -2, -2, -1, 0, 1, 2, 3, -3, -3, -2, -1, 0, 1, 2, 3, - -3, -3, -3, -3, -3, -2, -2, -2, -3, -3, -2, -2, -2, -1, -1, -1, - -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 2, 2, 2, 2, - 1, 1, 1, 2, 2, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, - -8, -7, -5, -3, -2, -1, 0, -1, -4, -3, -1, 0, 1, 2, 1, 1, - -1, 1, 2, 3, 3, 2, 2, 1, 1, 2, 3, 3, 2, 2, 1, 0, - 2, 3, 3, 2, 1, 0, 0, -1, 1, 2, 1, 0, -1, -1, -1, -1, - 1, 1, 0, -1, -1, -2, -2, -1, 1, 1, 0, 0, -1, -1, 0, -1, - -4, -3, -2, 0, 1, 2, 3, 3, -4, -3, -2, 0, 1, 2, 2, 2, - -3, -3, -2, -1, 0, 1, 1, 1, -2, -2, -2, -1, -1, 0, 0, 0, - 0, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 0, 0, -1, -1, -2, - 3, 3, 3, 1, 0, -1, -2, -2, 5, 4, 4, 2, 1, 0, -1, -2, - 0, 0, 0, 0, 1, 2, 3, 3, 0, -1, 0, 0, 1, 2, 3, 3, - 0, -1, 0, 0, 1, 2, 3, 2, 0, 0, 0, 1, 1, 2, 2, 2, - 2, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 1, 0, 0, -1, -2, - 2, 1, 0, 0, -2, -3, -5, -6, 0, -1, -1, -3, -5, -6, -8, -9, - -2, 0, 1, 2, 2, 1, -1, -4, -2, 0, 2, 2, 2, 1, -1, -4, - -2, 0, 2, 2, 2, 1, -1, -3, -2, 0, 2, 2, 2, 1, -1, -3, - -2, -1, 2, 2, 2, 1, -1, -3, -2, -1, 1, 2, 2, 1, -1, -3, - -3, -1, 1, 2, 2, 1, -1, -3, -2, -1, 1, 2, 2, 1, -1, -3, - -1, 1, 1, -1, -3, -3, 0, 4, -1, 1, 1, -1, -3, -3, 0, 4, - -1, 1, 1, 0, -3, -3, 0, 4, -1, 1, 2, 0, -3, -3, 0, 5, - 0, 1, 2, 0, -3, -4, 0, 4, 0, 1, 2, 0, -3, -4, 0, 5, - 0, 1, 2, 0, -3, -3, 0, 4, 0, 1, 2, -1, -2, -2, 0, 4, - 6, 6, 5, 6, 5, 5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, - 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 0, 0, 0, 0, 0, - -1, -2, -2, -2, -2, -2, -2, -1, -3, -3, -3, -3, -3, -3, -3, -2, - -3, -4, -4, -3, -3, -3, -2, -2, -2, -2, -2, -2, -1, -1, 0, 0, - 0, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6, - 4, 1, -2, -3, -3, -1, 1, 3, 4, 1, -2, -4, -3, -1, 1, 3, - 5, 1, -2, -4, -3, -1, 1, 4, 5, 1, -2, -3, -3, -1, 2, 4, - 5, 1, -2, -3, -3, -1, 2, 4, 4, 0, -3, -4, -3, -1, 2, 4, - 4, 0, -3, -3, -3, -1, 1, 3, 3, 0, -2, -3, -2, -1, 1, 3, - -3, -4, -4, -4, -4, -4, -4, -4, -1, -1, -1, -1, -1, -1, -2, -2, - 2, 1, 1, 2, 2, 1, 1, 1, 3, 3, 3, 4, 4, 3, 3, 3, - 3, 3, 3, 4, 4, 4, 3, 3, 1, 2, 1, 2, 2, 2, 2, 2, - -2, -2, -2, -1, -1, -1, 0, 0, -4, -4, -4, -4, -3, -3, -3, -3, - -1, -2, -3, -3, -2, -2, -1, 0, 0, -1, -2, -2, -2, -1, 0, 1, - 2, 1, -1, -1, -1, -1, 0, 1, 3, 1, 0, -1, -1, 0, 0, 1, - 3, 2, 0, -1, 0, 0, 0, 1, 3, 1, 0, -1, 0, 0, 0, 1, - 3, 1, 0, -1, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 1, 1, 2, 3, 4, 0, 0, -1, 0, 0, 0, 2, 3, - 0, -1, -1, -1, -1, -1, 0, 1, 0, -1, -1, -1, -1, -1, -1, 0, - 0, 0, -1, -1, -1, -2, -2, -1, 1, 0, 0, -1, -1, -2, -2, -1, - 2, 2, 1, 0, -1, -1, -1, -1, 3, 3, 2, 1, 0, -1, -1, 0, - 1, 0, 1, 0, 0, -1, -2, -1, 0, 0, 0, 0, -1, -1, -2, -1, - 0, -1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, -1, 0, 0, 0, 1, 1, -1, -1, -1, 0, 1, 1, 2, 3, - -2, -2, -1, 0, 1, 2, 3, 4, -2, -2, -1, 0, 1, 2, 4, 5, - -3, -1, 1, 0, 0, -1, 0, 1, -3, 0, 1, 0, -1, -1, 0, 2, - -3, 0, 1, 0, -1, -1, 0, 2, -2, 1, 2, 0, -1, -1, 0, 2, - -2, 1, 2, 0, -1, -1, 0, 2, -2, 1, 2, 0, -1, -1, 0, 2, - -1, 2, 2, 0, -1, -1, 0, 2, -1, 1, 1, 0, -1, -1, -1, 1, - -2, -2, -1, 1, 3, 4, 3, 1, -2, -2, -1, 0, 2, 3, 2, 0, - -2, -2, -1, 0, 1, 2, 1, -1, -1, -1, -1, 0, 1, 2, 1, -1, - -1, -1, -1, 0, 1, 1, 0, -2, 0, -1, -1, 0, 1, 1, 0, -1, - 0, -1, -1, 0, 1, 1, 1, -1, 0, -1, -1, 0, 0, 1, 0, -1, - -2, -1, 0, 1, 1, 1, 1, 1, -2, -1, 0, 0, 0, 0, 0, 0, - -2, -1, -1, 0, -1, -1, -2, -2, -2, -1, -1, -1, -1, -2, -2, -3, - -1, 0, 1, 1, 0, -1, -2, -2, 1, 2, 3, 3, 2, 1, 0, 0, - 1, 2, 3, 3, 3, 2, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, - 0, -1, -1, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, 0, 0, 1, 1, 0, 0, 0, - -3, -2, -1, -1, -1, -1, 0, -1, -5, -5, -4, -3, -2, -2, -2, -1, - 1, 1, 1, 1, 2, 1, 0, -1, 1, 1, 1, 2, 1, 1, 0, -1, - 1, 1, 1, 1, 1, 1, 0, -2, 2, 1, 1, 1, 1, 1, 0, -2, - 1, 1, 0, 0, 0, 0, -1, -3, 1, 1, 0, 0, 0, -1, -2, -3, - 1, 1, 0, 0, -1, -1, -2, -4, 1, 0, 0, -1, -2, -2, -3, -4, - 8, 7, 5, 3, 2, 1, 1, 1, 2, 1, 0, 0, -1, -1, -2, -1, - -1, -1, -1, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, -1, -1, 0, - 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, - -1, 0, 0, 0, 0, 0, -1, -1, -2, -2, -1, -1, -1, -2, -2, -1, - 9, 4, 0, -2, -2, -2, -1, -1, 7, 2, -1, -2, -2, -1, 0, 0, - 4, 0, -2, -2, -1, 0, 1, 1, 1, -2, -2, -2, -1, 0, 1, 1, - -1, -2, -2, -1, 0, 1, 1, 1, -1, -2, -1, 0, 1, 1, 1, 0, - -1, -1, 0, 1, 1, 1, 0, -1, 0, -1, 0, 1, 0, 0, -1, -1, - 0, 1, 1, 1, 1, 1, 0, 0, 1, 2, 2, 2, 1, 0, 0, 0, - 2, 2, 2, 2, 1, 0, -1, -1, 1, 1, 1, 0, -1, -2, -2, -2, - 0, 0, 0, -1, -2, -3, -2, -2, -1, -1, -1, -2, -2, -2, -1, 0, - -1, -1, -1, -1, 0, 0, 1, 2, -1, -1, -1, 0, 1, 2, 3, 4, - -1, -1, 0, 0, -1, -2, -3, -3, -1, -1, 0, 0, 0, -1, -1, -1, - -2, -2, -1, 0, 1, 1, 1, 1, -2, -2, -2, 0, 1, 2, 3, 3, - -1, -1, -1, 0, 1, 3, 3, 3, 1, 0, 0, 0, 1, 1, 2, 2, - 2, 2, 1, 0, 0, -1, -1, -1, 3, 2, 1, 0, -1, -2, -3, -3, - -1, -1, -1, -2, -2, -3, -4, -5, 0, 0, 0, -1, -1, -3, -3, -4, - 1, 1, 1, 0, 0, -1, -2, -3, 2, 2, 2, 1, 1, 0, -1, -1, - 2, 2, 2, 2, 1, 1, 0, -1, 2, 2, 2, 2, 2, 1, 0, 0, - 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, -1, - -2, 2, 3, 1, -1, 1, 1, -1, -3, 2, 3, 0, -1, 1, 1, -1, - -3, 2, 3, 0, -1, 1, 1, -1, -4, 2, 3, 0, -1, 1, 1, -2, - -4, 1, 3, 0, -1, 1, 1, -2, -4, 1, 3, -1, -2, 1, 1, -2, - -3, 1, 2, 0, -1, 1, 1, -2, -3, 1, 2, 0, -1, 1, 1, -1, - -1, -1, -1, -2, -2, -2, -2, -2, 1, 1, 1, 1, 0, 0, 0, 0, - 1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 2, 2, 2, - -2, -2, -1, -1, -1, 0, 0, 0, -3, -3, -3, -3, -3, -3, -3, -2, - -1, -1, -1, -1, -2, -2, -2, -2, 4, 4, 4, 4, 4, 3, 3, 2, - -3, -3, -2, -1, 0, 1, 2, 5, -3, -3, -3, -2, -1, 1, 3, 6, - -3, -3, -2, -2, 0, 2, 3, 5, -3, -2, -2, -2, 0, 1, 3, 5, - -2, -2, -2, -1, -1, 1, 3, 5, -2, -2, -1, -1, 0, 1, 2, 4, - -1, -1, -1, -1, 0, 1, 1, 4, -1, -1, -1, -1, 0, 1, 2, 3, - 0, -1, 0, 1, 1, 0, -1, -1, 0, 0, 0, 1, 2, 0, -1, -1, - 1, 0, -1, 0, 1, 0, 0, 0, 1, -1, -2, -1, 0, 0, 0, 0, - 1, -2, -3, -1, 0, 0, 0, 1, 1, -1, -3, -2, 0, 1, 1, 2, - 1, -1, -2, -1, 0, 1, 1, 2, 2, 0, -1, 0, 1, 1, 2, 2, - 1, 1, 1, 1, 0, 0, 1, 2, -1, 0, 0, -1, 0, 0, 0, 1, - -3, -2, -1, -1, -1, 0, 1, 1, -4, -2, -1, 0, 0, 1, 1, 1, - -3, -2, 0, 0, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 0, 0, - -1, 0, 1, 1, 1, 0, 0, -1, 0, 1, 2, 2, 1, 0, 0, -1, - -4, -4, -4, -3, -2, -1, -1, -1, -2, -2, -2, -1, 0, 0, 0, 0, - -1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, - 0, 0, 1, 1, 2, 2, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 1, 1, 1, 1, 0, -1, 0, 0, 1, 1, 1, 0, 0, - 1, 2, 2, 2, 1, -1, -2, -4, 1, 1, 2, 2, 1, 0, -2, -4, - 0, 1, 1, 1, 1, 0, -1, -3, -1, 0, 1, 1, 0, 0, -1, -2, - -1, 0, 1, 1, 1, 0, 0, -1, -2, -1, 0, 0, 0, 0, 0, -1, - -1, -1, 0, 1, 1, 0, 0, 0, -1, 0, 1, 1, 1, 1, 1, 0, - 2, 2, 0, -1, -2, -1, -1, -2, 1, 1, -1, -2, -2, -1, -1, -2, - 1, 1, -1, -2, -2, 0, 0, -1, 1, 1, 0, -2, -1, 1, 1, 0, - 1, 1, 0, -1, -1, 1, 2, 1, 1, 1, 0, -1, -1, 1, 2, 1, - 1, 1, 0, -1, -1, 1, 1, 1, 1, 1, 0, -1, 0, 1, 1, 1, - 0, 0, -1, -2, -4, -4, -4, -4, 3, 3, 3, 2, 1, 0, 0, 0, - 3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 1, - -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, - -1, -1, 0, -1, -1, 1, 2, -1, 1, 1, 0, 0, 0, 2, 3, -1, - 1, 1, 0, -1, -1, 1, 3, -1, 1, 1, 0, -2, -2, 0, 1, -2, - 1, 0, 0, -2, -2, 0, 1, -3, 0, 0, 0, 0, -1, 1, 1, -3, - 0, 1, 1, 0, 1, 2, 1, -3, -1, 0, 1, 1, 1, 2, 1, -4, - -4, -3, 0, 1, 1, 1, 0, 0, -4, -2, 0, 1, 1, 1, 0, -1, - -3, -1, 1, 1, 1, 0, -1, -1, -1, 1, 1, 1, 1, 0, -1, 0, - 1, 2, 2, 1, 0, -1, 0, 0, 2, 2, 1, 0, -1, -1, 0, 1, - 2, 1, 0, -1, -2, -1, 0, 1, 2, 2, 0, -1, -2, -1, 1, 1, - 1, 1, 0, 0, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1, - 1, 0, 0, -1, -1, -1, -1, -1, 2, 1, 0, 0, -1, -1, -1, -1, - 5, 3, 2, 1, 0, 0, 0, 0, 6, 5, 3, 2, 1, 0, 0, 0, - 4, 4, 3, 1, 0, 0, 0, 1, 3, 3, 2, 1, 0, 0, 0, 1, - 2, 2, 1, 0, -1, -1, 0, 1, 0, 0, 0, -1, -1, -1, 0, 1, - 0, 0, -1, -1, -2, -1, 0, 2, 0, -1, -1, -2, -2, -2, 0, 1, - 0, -1, -1, -2, -2, -2, -1, 0, 0, 0, -1, -2, -2, -2, -1, 0, - 0, 0, -1, -1, -1, 0, 2, 3, 0, -1, -2, -2, -1, -1, 1, 2, - 1, 0, -1, -1, -1, 0, 0, 0, 1, 1, 1, 0, 0, 0, -1, -1, - 1, 2, 1, 0, 0, -1, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1, - -3, -2, -1, -1, 0, 1, 1, 2, -4, -3, -1, 1, 2, 3, 5, 5, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, -1, 0, 0, 0, 1, -1, -1, -2, -2, -2, -1, -1, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, - 1, 1, 1, 1, 2, 2, 1, 1, -4, -3, -4, -4, -4, -4, -3, -3, - -1, 0, 1, 2, 2, 3, 3, 3, -1, -1, -1, -1, 0, 0, 0, 0, - 0, 0, -1, -2, -2, -3, -3, -2, 3, 2, 1, 0, -1, -2, -2, -2, - 4, 3, 2, 1, 1, 0, 0, 0, 2, 2, 1, 1, 0, 1, 1, 1, - 0, -1, -1, -1, -1, 0, 0, 1, -2, -2, -2, -2, -2, -1, 0, 0, - 1, -1, 0, 2, 1, -2, -1, 1, 1, -1, 0, 2, 1, -2, -2, 1, - 1, -1, 0, 3, 2, -2, -1, 1, 0, -2, 0, 3, 2, -2, -2, 1, - 0, -2, 0, 3, 2, -2, -2, 1, 0, -2, 0, 3, 1, -2, -1, 1, - 0, -2, 0, 2, 1, -2, -2, 1, 0, -1, 0, 2, 1, -2, -1, 1, - 0, 1, 2, 2, 3, 3, 2, 2, 0, 1, 1, 2, 3, 3, 2, 1, - 0, 0, 1, 2, 2, 2, 2, 1, -1, 0, 0, 1, 1, 1, 1, 1, - -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, - -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -2, -2, -2, -2, -2, -1, - 0, 0, -1, -2, -1, 0, 3, 5, 0, 0, -1, -1, -1, 0, 2, 4, - 1, 1, 0, 0, -1, -1, 1, 2, 1, 2, 1, 1, 0, -1, -1, 0, - 0, 1, 2, 1, 0, -1, -2, -2, -1, 0, 1, 2, 1, 0, -3, -3, - -2, -1, 1, 2, 2, 0, -2, -4, -2, -1, 0, 2, 2, 1, -1, -3, - 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, 0, 0, 0, 0, 0, - -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, - -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, 0, 0, 0, -1, -1, 0, - 0, 0, 1, 1, 0, 0, 0, 1, 3, 3, 3, 4, 3, 3, 3, 3, - 5, 1, -2, -2, 0, 0, 0, -1, 4, -1, -3, -1, 0, 0, 0, -1, - 3, -1, -1, 0, 1, 1, 0, -1, 2, 0, 0, 1, 1, 1, 0, -2, - 1, 0, 0, 1, 1, 1, 0, -2, 0, -1, -1, -1, 0, 0, 0, -1, - 0, -1, -1, -1, -1, 0, 0, -1, 2, 1, 0, 0, 0, 1, 0, 0, - 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, - 1, -1, -1, 0, 0, 0, 0, 0, 2, 0, -1, -1, -1, -1, -1, 0, - 3, 1, -1, -1, -2, -2, -2, -1, 4, 2, 1, 0, -1, -2, -2, -1, - 2, 1, 0, 0, -1, -1, 0, 0, 0, -1, -1, -1, -1, 0, 1, 1, - 0, 1, 2, 2, 2, 1, -1, -3, 0, 0, 1, 1, 1, 0, -1, -2, - 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, 0, 0, 1, 1, 0, - 0, 0, -1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, - 0, 0, 1, 1, 2, 1, -1, -3, 0, 0, 0, 1, 1, -1, -4, -5, - -2, -2, -2, -1, 0, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 0, - 1, 1, 1, 1, 1, 0, -2, -3, 0, 0, 1, 1, 0, -1, -3, -4, - -1, -1, 0, 1, 0, 0, -2, -3, -1, -1, 0, 1, 1, 1, 0, -1, - 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 1, 0, 0, 1, 1, 1, 2, 1, 2, 0, 0, 0, 0, -1, 1, - 0, 2, 0, -1, 1, 0, -1, 0, 0, 1, 0, 0, 2, 1, 0, 1, - 0, 1, -1, 0, 2, 2, 0, 1, -1, 0, -1, -1, 2, 1, 1, 2, - -2, -2, -3, -2, 0, 1, 1, 1, -2, -2, -3, -3, -1, -1, -1, 0, - -3, -1, 0, 1, 2, 1, 1, 0, -3, -1, 0, 1, 2, 1, 1, 1, - -2, 0, 0, 1, 1, 1, 1, 1, -1, 0, 0, 0, 0, 0, 0, 0, - -2, 0, 0, 0, 0, -1, -1, 0, -2, 0, 0, 0, 0, 0, -1, -1, - -3, 0, 1, 1, 1, 1, 0, 1, -5, -2, 0, 1, 2, 2, 1, 2, - -2, -1, -1, 0, 0, 1, 2, 3, 0, 0, 1, 1, 0, 0, 1, 2, - 0, 0, 1, 0, -1, -1, 0, 1, -1, -1, -1, -1, -2, -2, -1, 0, - -2, -2, -2, -2, -2, -1, 0, 1, 0, 0, 0, -1, 0, 1, 2, 2, - 2, 1, 0, 0, 0, 1, 2, 2, 2, 1, 0, -1, -1, -1, 0, 0, - 0, 1, 1, 1, 1, 1, -1, -4, -1, -1, 0, 1, 1, 1, 0, -3, - -2, -1, 0, 0, 1, 2, 2, -2, -1, 0, 0, 0, 0, 2, 3, -1, - -1, 0, 0, 0, 0, 1, 2, 0, 0, 0, -1, -2, -1, 1, 1, 0, - 0, 0, -1, -2, -2, 0, 2, 1, 0, 0, -1, -2, -1, 1, 2, 2, - 1, 0, 0, 0, -2, -3, -2, -3, 0, 0, 1, 0, -2, -2, -1, -1, - 0, -1, 1, 1, -1, -1, 0, 0, 0, -1, 1, 1, -1, -1, 0, 0, - 0, 1, 2, 1, -1, -1, 0, 1, 1, 2, 3, 2, 0, 0, 1, 2, - -1, 0, 2, 1, 0, 0, 2, 3, -2, -1, 0, 0, -1, 0, 1, 2, - 1, 1, 0, -1, -2, -2, -1, 1, 1, 1, 1, -1, -2, -2, 0, 2, - 1, 1, 1, -1, -1, -1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 2, - -1, -1, -1, 0, 0, 0, 1, 2, -1, -2, -1, 1, 1, 1, 0, 0, - -1, -2, -1, 1, 2, 2, 0, -1, -1, -2, -1, 2, 2, 2, 0, -1, - -1, -1, -1, -2, -1, -1, 0, 1, 0, 0, -1, -1, -1, 0, 1, 2, - 1, 0, 0, 0, 0, 1, 1, 2, 1, 1, 0, 0, 1, 1, 1, 1, - 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, -1, -1, -1, - 1, 2, 1, 0, -1, -2, -2, -3, 2, 2, 1, 0, -2, -3, -4, -4, - -4, -2, 1, 1, 1, 1, 0, 0, -2, 0, 1, 0, 0, 0, 0, 0, - 0, 1, 1, -2, -2, -1, 0, 1, 2, 2, 1, -2, -2, -1, 1, 2, - 1, 2, 1, -2, -2, -1, 1, 2, -1, 1, 1, -1, -1, -1, 0, 1, - -2, 0, 1, 1, 0, -1, -1, 0, -2, 0, 2, 2, 1, -1, -1, 0, - 1, 1, 0, 0, 0, 1, 0, 0, -2, -3, -3, -2, -2, -1, 0, 0, - -3, -4, -3, -2, -1, 0, 0, 0, -1, -1, 0, 1, 2, 3, 2, 1, - 0, 1, 2, 3, 3, 3, 2, 1, 1, 1, 1, 2, 1, 0, 0, -1, - 0, 0, 0, 0, -1, -1, -1, -1, 0, -1, -1, 0, 0, 0, 0, 0, - 1, 1, 0, 0, -1, -1, 0, 2, 0, 0, 1, 0, -1, -1, 1, 1, - -2, -1, 0, 1, 1, 1, 1, 1, -3, -3, 0, 2, 2, 1, 1, 0, - -2, -2, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, -1, -1, - 3, 1, -1, -3, -2, -1, 0, 1, 4, 2, -1, -3, -3, -1, 1, 2, - 0, 0, 0, -1, -1, -1, -1, -1, 1, 2, 1, 0, 0, 0, -1, -1, - 2, 3, 3, 2, 1, 0, -1, -1, 3, 4, 4, 2, 1, 0, -1, -2, - 3, 3, 2, 1, 0, -1, -2, -2, 1, 1, 0, -1, -1, -2, -2, -3, - 0, 0, 0, -1, -1, -2, -2, -2, -1, -1, -1, -1, -1, -2, -2, -1, - 1, 2, 2, 2, 2, 1, 2, 2, 0, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 1, 1, 0, -1, -2, 0, 0, 0, 0, 1, 0, -1, -4, - 1, 0, 0, 0, 0, 0, -2, -5, 1, 0, 0, 0, 0, 0, -1, -4, - 1, 0, -1, 0, 0, 0, -1, -3, 0, -1, -1, 0, 1, 1, 1, -1, - -2, -1, 0, 0, -1, -1, -1, -2, -1, 0, 0, 0, -1, -1, -2, -2, - 0, 1, 1, 0, -1, -1, -1, -2, 0, 1, 1, 0, 0, 0, -1, -1, - 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 2, 2, 1, - 1, 1, 0, 0, 1, 2, 2, 1, 1, 1, 0, -1, 0, 1, 1, 0, - 4, 2, 1, 0, 0, 1, 1, 1, 4, 2, 1, 0, 0, 0, 0, 1, - 3, 1, 0, 0, -1, -1, -1, 0, 1, 0, 0, -1, -1, -2, -1, 0, - 0, 0, 0, 0, -1, -1, -1, 0, -1, -1, 0, 0, -1, -1, 0, 1, - -2, -1, 0, -1, -1, 0, 0, 1, -2, -2, -1, -2, -1, 0, 0, 1, - 0, 1, 1, 1, 2, 1, 0, -1, -1, -1, -1, 0, 0, -1, -2, -2, - -1, 0, -1, 0, 0, -1, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2, - 0, 0, 0, 0, 0, 0, 2, 3, -1, 0, -1, -1, -1, -1, 0, 3, - -1, 0, 0, -1, -1, -2, 0, 3, 0, 0, 0, 0, -1, -1, 1, 4, - 2, 2, 0, 0, 0, 0, 0, 1, 1, 1, -1, -2, -1, -2, -1, 1, - -1, -1, -2, -2, -2, -3, -2, 0, -1, 0, -1, -1, -1, -2, -1, 1, - 1, 1, 0, 0, 1, 0, 0, 1, 2, 2, 0, 0, 1, 0, 0, 1, - 2, 2, 0, 0, 0, 0, -1, -1, 2, 2, 0, 0, 1, 0, -1, -1, - -1, 0, 1, 1, 0, -1, -1, -1, 1, 2, 3, 2, 1, 0, 0, 0, - 0, 1, 1, 1, 0, -1, 0, 0, -2, -2, -1, 0, 1, 0, 0, 0, - -2, -2, -1, 2, 2, 2, 1, 0, -2, -1, 0, 1, 1, 0, 0, -1, - -1, -1, 0, 0, -1, -2, -1, -2, 0, 1, 1, 1, 0, 0, 1, 1, - -3, -3, -3, -2, -1, -1, -2, -2, -1, -1, 0, 1, 2, 1, 0, 0, - 1, 1, 1, 2, 2, 1, 0, 0, 1, 1, 1, 1, 1, 0, -1, 1, - 1, 0, -1, -1, 0, 0, -1, 1, 0, -1, -1, -1, 0, -1, -1, 1, - 1, 0, -1, 0, 0, -1, 0, 2, 2, 0, -1, 0, 0, 0, 0, 2, - 1, 0, -2, -1, 0, 1, 1, 0, 2, 0, -1, -1, 0, 1, 1, 0, - 1, 0, -2, -1, 0, 1, 0, -1, 1, 0, -1, -1, 0, 1, 0, -1, - 0, 1, 1, 0, 1, 1, 0, 0, -2, 1, 2, 1, 0, 0, 0, 1, - -5, 0, 2, 1, 0, -1, 0, 1, -6, -1, 2, 1, 0, -1, 0, 0, - 5, 3, 0, -1, -2, -1, -1, -1, 1, 1, 0, -1, -1, 0, -1, -1, - -1, 0, 1, 1, 2, 2, 1, 0, -2, -1, 0, 1, 2, 1, 1, 1, - -2, -1, -1, -1, 0, -1, 0, 1, 0, 1, 0, 0, -1, -1, 0, 0, - 0, 1, 1, 1, 1, 0, 0, 0, -3, -2, 0, 1, 1, 0, 0, -1, - -1, 0, 1, 0, -1, 0, 2, 3, -1, 0, 0, -2, -4, -2, -1, 0, - 0, 1, 1, 0, -2, -1, 0, -1, 1, 2, 3, 1, 0, 1, 1, 0, - -1, 0, 1, 1, 1, 1, 1, 0, -2, -3, -2, 0, 0, 0, 1, 0, - -1, -2, -2, 0, 1, 0, 0, -1, 3, 1, 0, 0, 1, 0, -1, -1, - -2, -1, 0, 0, -1, -1, 0, 0, -1, 0, 0, 0, 0, 1, 1, 1, - -1, -1, -1, 0, 1, 1, 1, 1, 0, -2, -3, -1, 1, 0, 0, 0, - 1, -1, -3, -1, 1, 1, 0, -1, 3, 1, -1, 1, 2, 2, 0, -1, - 3, 1, 0, 1, 2, 1, 1, 0, 0, -2, -2, -1, -1, 0, 0, 0, - 1, 0, -1, -1, 1, 2, 1, 0, 0, -1, -2, -1, 1, 2, 2, 1, - -1, -1, -1, 0, 0, 1, 2, 0, -2, 0, 0, 0, 0, 0, 1, -1, - -1, 0, 1, 0, -1, -1, -1, -1, 0, 1, 1, 2, 0, -2, -1, 0, - 1, 2, 2, 2, 1, -1, -1, 0, 0, 1, 1, 1, 0, -2, -2, -1, - 0, 0, -1, -1, -1, -1, -2, -2, 0, 0, -1, 0, 1, 2, 2, 1, - 0, 0, -1, -1, 0, 1, 2, 2, 1, 1, -1, -2, -1, -1, -1, -1, - 2, 2, 1, 0, 0, -1, -2, -2, 1, 2, 2, 1, 0, 0, -2, -2, - 0, 0, 0, 0, 1, 1, 0, -1, 0, -1, -1, -1, 2, 3, 2, 1, - 0, -2, 1, 2, -1, 0, 0, 1, -1, -2, 2, 3, -1, 0, 0, 0, - 0, -2, 2, 3, -1, -1, 0, 0, 0, -1, 3, 2, -2, 0, 1, 0, - 0, -1, 3, 1, -2, 0, 1, 0, 0, -1, 2, 1, -1, 1, 0, -1, - 0, 0, 1, -1, -2, 0, 0, -1, 1, 0, 0, -2, -2, -1, -1, -1, - 1, 1, 1, 1, 1, -1, -1, -2, 0, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 1, 1, 1, 2, 3, 1, 0, 0, -1, 0, 0, 1, 2, - 0, -1, -1, -2, -1, 0, 1, 2, -2, -2, -2, -2, -1, 0, 1, 1, - -1, -1, -1, -1, 0, 0, 0, -1, 2, 2, 2, 0, -1, -1, -2, -4, - -1, -2, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1, 0, 1, 2, 3, - 1, 0, -1, 0, -1, 0, 1, 2, 1, 0, 0, 0, -1, 0, 2, 2, - 1, 0, -1, -1, -2, 0, 1, 2, 0, -2, -2, -2, -3, -1, 0, 1, - 0, -2, -2, -2, -2, -1, 1, 1, 0, 0, 0, 0, 0, 1, 2, 2 -}; - -/* list of codebooks for intra-coded vectors */ -static uint8_t *intra_codebooks[4] = { - intra_codebook_4x2, intra_codebook_4x4, intra_codebook_8x4, intra_codebook_8x8 -}; diff --git a/src/libxinevdec/wc3video.c b/src/libxinevdec/wc3video.c deleted file mode 100644 index 68ba2b43f..000000000 --- a/src/libxinevdec/wc3video.c +++ /dev/null @@ -1,539 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Video Decoder for Origin's Wing Commander III MVE Movie Files - * by Mario Brito (mbrito@student.dei.uc.pt) - * For more information on the WC3 Movie format, visit: - * http://www.pcisys.net/~melanson/codecs/ - * - * $Id: wc3video.c,v 1.20 2004/02/09 22:04:11 jstembridge Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <unistd.h> - -#include "buffer.h" -#include "xine_internal.h" -#include "video_out.h" -#include "xineutils.h" -#include "bswap.h" - -#define VIDEOBUFSIZE 128*1024 - -#define WC3_WIDTH 320 -#define WC3_HEIGHT 165 - -typedef struct { - video_decoder_class_t decoder_class; -} wc3video_class_t; - -typedef struct wc3video_decoder_s { - video_decoder_t video_decoder; /* parent video decoder structure */ - - wc3video_class_t *class; - xine_stream_t *stream; - - /* these are traditional variables in a video decoder object */ - uint64_t video_step; /* frame duration in pts units */ - int decoder_ok; /* current decoder status */ - int skipframes; - - unsigned char *buf; /* the accumulated buffer data */ - int bufsize; /* the maximum size of buf */ - int size; /* the current size of buf */ - - unsigned char yuv_palette[256 * 4]; - - yuv_planes_t yuv_planes1; - yuv_planes_t yuv_planes2; - - yuv_planes_t *current_frame; - yuv_planes_t *last_frame; - - /* this is either 1 or 2 indicating the current_frame points to yuv_planes - * structure 1 or 2 */ - int current_planes; - - double ratio; - -} wc3video_decoder_t; - -/************************************************************************** - * WC3 video specific decode functions - *************************************************************************/ - -#define SIZE (WC3_WIDTH * WC3_HEIGHT) -#define BYTE unsigned char - -static BYTE buffer1[SIZE]; -static BYTE buffer2[SIZE]; - -static BYTE * part1; -static BYTE * part2; -static BYTE * part3; -static BYTE * part4; - -static void bytecopy(BYTE * dest, BYTE * src, int count) { - - int i; - - /* Don't use memcpy because the memory locations often overlap and - * memcpy doesn't like that; it's not uncommon, for example, for - * dest = src+1, to turn byte A into pattern AAAAAAAA. - * This was originally repz movsb. */ - for (i = 0; i < count; i ++) - dest[i] = src[i]; -} - -static void wc3_build_frame (wc3video_decoder_t *this) { - - int frame_size = WC3_WIDTH * WC3_HEIGHT; - int index = 0; - BYTE pixel; - BYTE y, u, v; - int size = 0; - BYTE flag = 0; - int func; - - while (index < frame_size) { - func = *part1++; - size = 0; - - switch (func) { - case 0: - flag ^= 1; - continue; - - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - size = func; - break; - - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - size += (func - 10); - break; - - case 9: - case 19: - size = (*part2++); - break; - - case 10: - case 20: - size = BE_16(&part2[0]); - part2 += 2; - break; - - case 11: - case 21: - size = (part2[0] << 16) | (part2[1] << 8) | part2[2]; - part2 += 3; - break; - } - - /* run is unchanged from last frame */ - if (func < 12) { - flag = flag ^ 1; - if ( flag ) { - xine_fast_memcpy( - &this->current_frame->y[index], - &this->last_frame->y[index], - size); - xine_fast_memcpy( - &this->current_frame->u[index], - &this->last_frame->u[index], - size); - xine_fast_memcpy( - &this->current_frame->v[index], - &this->last_frame->v[index], - size); - index += size; - } else { - while (size > 0) { - pixel = *part4++; - y = this->yuv_palette[pixel * 4 + 0]; - u = this->yuv_palette[pixel * 4 + 1]; - v = this->yuv_palette[pixel * 4 + 2]; - this->current_frame->y[index] = y; - this->current_frame->u[index] = u; - this->current_frame->v[index] = v; - index++; - size --; - } - } - } else { - /* run displacement from last frame */ - int x = (*part3 >> 4) & 0xf; - int y = *part3 & 0xf; - part3++; - - /* extend sign */ - if (x & 8) x |= 0xfffffff0; - if (y & 8) y |= 0xfffffff0; - - /* copy a run of pixels from the previous frame */ - xine_fast_memcpy( - &this->current_frame->y[index], - &this->last_frame->y[index + x + y * WC3_WIDTH], - size); - xine_fast_memcpy( - &this->current_frame->u[index], - &this->last_frame->u[index + x + y * WC3_WIDTH], - size); - xine_fast_memcpy( - &this->current_frame->v[index], - &this->last_frame->v[index + x + y * WC3_WIDTH], - size); - index += size; - - flag = 0; - } - } -} - -static void wc3_do_part4 (BYTE * dest, BYTE * src) { - - int func; - int size; - int offset; - int byte1, byte2, byte3; - - for (;;) { - func = *src++; - - if ( (func & 0x80) == 0 ) { - - offset = *src++; - - size = func & 3; - bytecopy(dest, src, size); dest += size; src += size; - - size = ((func & 0x1c) >> 2) + 3; - bytecopy (dest, dest - ( ((func & 0x60) << 3) + offset + 1 ), size); - dest += size; - - } else if ( (func & 0x40) == 0 ) { - - byte1 = *src++; - byte2 = *src++; - - size = byte1 >> 6; - bytecopy (dest, src, size); dest += size; src += size; - - size = (func & 0x3f) + 4; - bytecopy (dest, dest - (((byte1 & 0x3f) << 8) + byte2 + 1), size); - dest += size; - - } else if ( (func & 0x20) == 0 ) { - - byte1 = *src++; - byte2 = *src++; - byte3 = *src++; - - size = func & 3; - bytecopy (dest, src, size); dest += size; src += size; - - size = byte3 + 5 + ((func & 0xc) << 6); - bytecopy (dest, - dest - ((((func & 0x10) >> 4) << 0x10) + 1 + (byte1 << 8) + byte2), - size); - dest += size; - } else { - size = ((func & 0x1f) << 2) + 4; - - if (size > 0x70) - break; - - bytecopy (dest, src, size); dest += size; src += size; - } - } - - size = func & 3; - bytecopy(dest, src, size); dest += size; src += size; -} - -static void wc3_do_part1 (BYTE * dest, BYTE * src) { - - BYTE byte = *src++; - BYTE ival = byte + 0x16; - BYTE * ptr = src + byte*2; - BYTE val = ival; - int counter = 0; - - BYTE bits = *ptr++; - - while ( val != 0x16 ) { - if ( (1 << counter) & bits ) - val = src[byte + val - 0x17]; - else - val = src[val - 0x17]; - - if ( val < 0x16 ) { - *dest++ = val; - val = ival; - } - - if (counter++ == 7) { - counter = 0; - bits = *ptr++; - } - } -} - -static void wc3_decode_frame (wc3video_decoder_t *this) { - - BYTE * ptr; - - part1 = buffer1; - part4 = buffer2; - - wc3_do_part1(part1, this->buf + LE_16(&this->buf[0])); - part2 = this->buf + LE_16(&this->buf[2]); - part3 = this->buf + LE_16(&this->buf[4]); - - ptr = this->buf + LE_16(&this->buf[6]); - if (*ptr++ == 2) - wc3_do_part4(part4, ptr); - else - part4 = ptr; - - wc3_build_frame(this); -} - -/************************************************************************** - * xine video plugin functions - *************************************************************************/ - -/* - * This function receives a buffer of data from the demuxer layer and - * figures out how to handle it based on its header flags. - */ -static void wc3video_decode_data (video_decoder_t *this_gen, - buf_element_t *buf) { - - wc3video_decoder_t *this = (wc3video_decoder_t *) this_gen; - palette_entry_t *palette; - int i; - - vo_frame_t *img; /* video out frame */ - - /* a video decoder does not care about this flag (?) */ - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - /* convert the RGB palette to a YUV palette */ - if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && - (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { - palette = (palette_entry_t *)buf->decoder_info_ptr[2]; - for (i = 0; i < buf->decoder_info[2]; i++) { - this->yuv_palette[i * 4 + 0] = - COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 1] = - COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); - this->yuv_palette[i * 4 + 2] = - COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); - } - } - - if (buf->decoder_flags & BUF_FLAG_FRAMERATE) { - this->video_step = buf->decoder_info[0]; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step); - } - - if (buf->decoder_flags & BUF_FLAG_HEADER) { /* need to initialize */ - this->stream->video_out->open (this->stream->video_out, this->stream); - - if(this->buf) - free(this->buf); - - if (this->buf) - free (this->buf); - this->bufsize = VIDEOBUFSIZE; - this->buf = malloc(this->bufsize); - this->size = 0; - - init_yuv_planes(&this->yuv_planes1, WC3_WIDTH, WC3_HEIGHT); - init_yuv_planes(&this->yuv_planes2, WC3_WIDTH, WC3_HEIGHT); - this->current_planes = 1; - - this->decoder_ok = 1; - - /* load the stream/meta info */ - _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, "Wing Commander III Video"); - - return; - } else if (this->decoder_ok) { - - if (this->size + buf->size > this->bufsize) { - this->bufsize = this->size + 2 * buf->size; - this->buf = realloc (this->buf, this->bufsize); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { - - img = this->stream->video_out->get_frame (this->stream->video_out, - WC3_WIDTH, WC3_HEIGHT, - this->ratio, XINE_IMGFMT_YUY2, VO_BOTH_FIELDS); - - img->duration = this->video_step; - img->pts = buf->pts; - img->bad_frame = 0; - - if (this->current_planes == 1) { - this->current_planes = 2; - this->current_frame = &this->yuv_planes1; - this->last_frame = &this->yuv_planes2; - } else { - this->current_planes = 1; - this->current_frame = &this->yuv_planes2; - this->last_frame = &this->yuv_planes1; - } - - wc3_decode_frame (this); - yuv444_to_yuy2(this->current_frame, img->base[0], img->pitches[0]); - - img->draw(img, this->stream); - img->free(img); - - this->size = 0; - } - } -} - -/* - * This function is called when xine needs to flush the system. Not - * sure when or if this is used or even if it needs to do anything. - */ -static void wc3video_flush (video_decoder_t *this_gen) { -} - -/* - * This function resets the video decoder. - */ -static void wc3video_reset (video_decoder_t *this_gen) { - wc3video_decoder_t *this = (wc3video_decoder_t *) this_gen; - - this->size = 0; -} - -static void wc3video_discontinuity (video_decoder_t *this_gen) { -} - -/* - * This function frees the video decoder instance allocated to the decoder. - */ -static void wc3video_dispose (video_decoder_t *this_gen) { - - wc3video_decoder_t *this = (wc3video_decoder_t *) this_gen; - - if (this->buf) { - free (this->buf); - this->buf = NULL; - } - - if (this->decoder_ok) { - this->decoder_ok = 0; - this->stream->video_out->close(this->stream->video_out, this->stream); - } - - free (this_gen); -} - -static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) { - - wc3video_decoder_t *this ; - - this = (wc3video_decoder_t *) xine_xmalloc (sizeof (wc3video_decoder_t)); - - this->video_decoder.decode_data = wc3video_decode_data; - this->video_decoder.flush = wc3video_flush; - this->video_decoder.reset = wc3video_reset; - this->video_decoder.discontinuity = wc3video_discontinuity; - this->video_decoder.dispose = wc3video_dispose; - this->size = 0; - - this->stream = stream; - this->class = (wc3video_class_t *) class_gen; - - this->decoder_ok = 0; - this->buf = NULL; - - this->ratio = (double)WC3_WIDTH/(double)WC3_HEIGHT; - - return &this->video_decoder; -} - -static char *get_identifier (video_decoder_class_t *this) { - return "WC3 Video"; -} - -static char *get_description (video_decoder_class_t *this) { - return "Wing Commander III video decoder plugin"; -} - -static void dispose_class (video_decoder_class_t *this) { - free (this); -} - -static void *init_plugin (xine_t *xine, void *data) { - - wc3video_class_t *this; - - this = (wc3video_class_t *) xine_xmalloc (sizeof (wc3video_class_t)); - - this->decoder_class.open_plugin = open_plugin; - this->decoder_class.get_identifier = get_identifier; - this->decoder_class.get_description = get_description; - this->decoder_class.dispose = dispose_class; - - return this; -} - -/* plugin catalog information */ -static uint32_t supported_types[] = { BUF_VIDEO_WC3, 0 }; - -static decoder_info_t video_decoder_info = { - supported_types, /* supported types */ - 9 /* priority */ -}; - -plugin_info_t xine_plugin_info[] = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_DECODER, 18, "wc3video", XINE_VERSION_CODE, &video_decoder_info, &init_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; |