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

libavcodec/mqcenc.c

Go to the documentation of this file.
00001 /*
00002  * MQ-coder encoder
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 byteout(MqcState *mqc)
00031 {
00032 retry:
00033     if (*mqc->bp == 0xff){
00034         mqc->bp++;
00035         *mqc->bp = mqc->c >> 20;
00036         mqc->c &= 0xfffff;
00037         mqc->ct = 7;
00038     } else if ((mqc->c & 0x8000000)){
00039         (*mqc->bp)++;
00040         mqc->c &= 0x7ffffff;
00041         goto retry;
00042     } else{
00043         mqc->bp++;
00044         *mqc->bp = mqc->c >> 19;
00045         mqc->c &= 0x7ffff;
00046         mqc->ct = 8;
00047     }
00048 }
00049 
00050 static void renorme(MqcState *mqc)
00051 {
00052     do{
00053         mqc->a += mqc->a;
00054         mqc->c += mqc->c;
00055         if (!--mqc->ct)
00056             byteout(mqc);
00057     } while (!(mqc->a & 0x8000));
00058 }
00059 
00060 static void setbits(MqcState *mqc)
00061 {
00062     int tmp = mqc->c + mqc->a;
00063     mqc->c |= 0xffff;
00064     if (mqc->c >= tmp)
00065         mqc->c -= 0x8000;
00066 }
00067 
00068 void ff_mqc_initenc(MqcState *mqc, uint8_t *bp)
00069 {
00070     ff_mqc_init_contexts(mqc);
00071     mqc->a = 0x8000;
00072     mqc->c = 0;
00073     mqc->bp = bp-1;
00074     mqc->bpstart = bp;
00075     mqc->ct = 12 + (*mqc->bp == 0xff);
00076 }
00077 
00078 void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d)
00079 {
00080     int qe;
00081 
00082     qe = ff_mqc_qe[*cxstate];
00083     mqc->a -= qe;
00084     if ((*cxstate & 1) == d){
00085         if (!(mqc->a & 0x8000)){
00086             if (mqc->a < qe)
00087                 mqc->a = qe;
00088             else
00089                 mqc->c += qe;
00090             *cxstate = ff_mqc_nmps[*cxstate];
00091             renorme(mqc);
00092         } else
00093             mqc->c += qe;
00094     } else{
00095         if (mqc->a < qe)
00096             mqc->c += qe;
00097         else
00098             mqc->a = qe;
00099         *cxstate = ff_mqc_nlps[*cxstate];
00100         renorme(mqc);
00101     }
00102 }
00103 
00104 int ff_mqc_length(MqcState *mqc)
00105 {
00106     return mqc->bp - mqc->bpstart;
00107 }
00108 
00109 int ff_mqc_flush(MqcState *mqc)
00110 {
00111     setbits(mqc);
00112     mqc->c = mqc->c << mqc->ct;
00113     byteout(mqc);
00114     mqc->c = mqc->c << mqc->ct;
00115     byteout(mqc);
00116     if (*mqc->bp != 0xff)
00117         mqc->bp++;
00118     return mqc->bp - mqc->bpstart;
00119 }

Generated on Fri Feb 22 2013 07:24:28 for FFmpeg by  doxygen 1.7.1