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