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

libavcodec/dctref.c

Go to the documentation of this file.
00001 /*
00002  * reference discrete cosine transform (double precision)
00003  * Copyright (C) 2009 Dylan Yudaken
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 
00032 #include "libavutil/mathematics.h"
00033 static double coefficients[8 * 8];
00034 
00039 av_cold void ff_ref_dct_init(void)
00040 {
00041     unsigned int i, j;
00042 
00043     for (j = 0; j < 8; ++j) {
00044         coefficients[j] = sqrt(0.125);
00045         for (i = 8; i < 64; i += 8) {
00046             coefficients[i + j] = 0.5 * cos(i * (j + 0.5) * M_PI / 64.0);
00047         }
00048     }
00049 }
00050 
00057 void ff_ref_fdct(short *block)
00058 {
00059     /* implement the equation: block = coefficients * block * coefficients' */
00060 
00061     unsigned int i, j, k;
00062     double out[8 * 8];
00063 
00064     /* out = coefficients * block */
00065     for (i = 0; i < 64; i += 8) {
00066         for (j = 0; j < 8; ++j) {
00067             double tmp = 0;
00068             for (k = 0; k < 8; ++k) {
00069                 tmp += coefficients[i + k] * block[k * 8 + j];
00070             }
00071             out[i + j] = tmp * 8;
00072         }
00073     }
00074 
00075     /* block = out * (coefficients') */
00076     for (j = 0; j < 8; ++j) {
00077         for (i = 0; i < 64; i += 8) {
00078             double tmp = 0;
00079             for (k = 0; k < 8; ++k) {
00080                 tmp += out[i + k] * coefficients[j * 8 + k];
00081             }
00082             block[i + j] = floor(tmp + 0.499999999999);
00083         }
00084     }
00085 }
00086 
00093 void ff_ref_idct(short *block)
00094 {
00095     /* implement the equation: block = (coefficients') * block * coefficients */
00096 
00097     unsigned int i, j, k;
00098     double out[8 * 8];
00099 
00100     /* out = block * coefficients */
00101     for (i = 0; i < 64; i += 8) {
00102         for (j = 0; j < 8; ++j) {
00103             double tmp = 0;
00104             for (k = 0; k < 8; ++k) {
00105                 tmp += block[i + k] * coefficients[k * 8 + j];
00106             }
00107             out[i + j] = tmp;
00108         }
00109     }
00110 
00111     /* block = (coefficients') * out */
00112     for (i = 0; i < 8; ++i) {
00113         for (j = 0; j < 8; ++j) {
00114             double tmp = 0;
00115             for (k = 0; k < 64; k += 8) {
00116                 tmp += coefficients[k + i] * out[k + j];
00117             }
00118             block[i * 8 + j] = floor(tmp + 0.5);
00119         }
00120     }
00121 }

Generated on Sat Feb 16 2013 09:23:11 for ffmpeg by  doxygen 1.7.1