• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/mqcdec.c

Go to the documentation of this file.
00001 /*
00002  * MQ-coder decoder
00003  * Copyright (c) 2007 Kamil Nowosad
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00028 #include "mqc.h"
00029 
00030 static void bytein(MqcState *mqc)
00031 {
00032     if (*mqc->bp == 0xff){
00033         if (*(mqc->bp+1) > 0x8f)
00034             mqc->c++;
00035         else{
00036             mqc->bp++;
00037             mqc->c += 2 + 0xfe00 - (*mqc->bp << 9);
00038         }
00039     } else{
00040         mqc->bp++;
00041         mqc->c += 1 + 0xff00 - (*mqc->bp << 8);
00042     }
00043 }
00044 
00045 static int exchange(MqcState *mqc, uint8_t *cxstate, int lps)
00046 {
00047     int d;
00048     if ((mqc->a < ff_mqc_qe[*cxstate]) ^ (!lps)){
00049         if (lps)
00050             mqc->a = ff_mqc_qe[*cxstate];
00051         d = *cxstate & 1;
00052         *cxstate = ff_mqc_nmps[*cxstate];
00053     } else{
00054         if (lps)
00055             mqc->a = ff_mqc_qe[*cxstate];
00056         d = 1 - (*cxstate & 1);
00057         *cxstate = ff_mqc_nlps[*cxstate];
00058     }
00059     // renormd:
00060     do{
00061         if (!(mqc->c & 0xff)){
00062             mqc->c -= 0x100;
00063             bytein(mqc);
00064         }
00065         mqc->a += mqc->a;
00066         mqc->c += mqc->c;
00067     } while (!(mqc->a & 0x8000));
00068     return d;
00069 }
00070 
00071 void ff_mqc_initdec(MqcState *mqc, uint8_t *bp)
00072 {
00073     ff_mqc_init_contexts(mqc);
00074     mqc->bp = bp;
00075     mqc->c = (*mqc->bp ^ 0xff) << 16;
00076     bytein(mqc);
00077     mqc->c = mqc->c << 7;
00078     mqc->a = 0x8000;
00079 }
00080 
00081 int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate)
00082 {
00083     mqc->a -= ff_mqc_qe[*cxstate];
00084     if ((mqc->c >> 16) < mqc->a){
00085         if (mqc->a & 0x8000)
00086             return *cxstate & 1;
00087         else
00088             return exchange(mqc, cxstate, 0);
00089     } else {
00090         mqc->c -= mqc->a << 16;
00091         return exchange(mqc, cxstate, 1);
00092     }
00093 }
Generated on Fri Feb 1 2013 14:34:40 for FFmpeg by doxygen 1.7.1