📄 transform.c
字号:
/*COPYRIGHT, LICENSE AND WARRANTY INFORMATIONThis software module has been originally developed by Nokia Corporation. Provided that a person, entity or a company willing to use the Software (hereinafter Licensee) comply with all the terms and conditions of this Statement and subject to the limitations set forth in this Statement Nokia grants to such Licensee a non-exclusive, sub-licensable, worldwide, limited license under copyrights owned by Nokia to use the Software for the sole purpose of creating, manufacturing, selling, marketing, or distributing (including the right to make modifications to the Software) a fully compliant decoder implementation (hereinafter "Decoder") of ITU-T Recommendation H.264 / ISO/IEC International Standard 14496-10 and an encoder implementation producing output that is decodable with the Decoder.Nokia retains the ownership of copyrights to the Software. There is no patent nor other intellectual property right of Nokia licensed under this Statement (except the copyright license above). Licensee hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if patent licenses are required, it is their responsibility to acquire the license before utilizing the Software.The license by Nokia is subject to that the Licensee grants to Nokia the non-exclusive, worldwide, royalty-free, perpetual and irrevocable covenant that the Licensee(s) shall not bring a suit before any court or administrative agency or otherwise assert a claim for infringement under the Licensee intellectual property rights that, but for a license, would be infringed by the Software against (a) Nokia or Nokia's Affiliate; or (b) other recipient of a license and covenant not to sue with respect to the Software from Nokia; or (c) contractor, customer or distributor of a party listed above in a or b, which suit or claim is related to the Software or use thereof.The Licensee(s) further agrees to grant a reciprocal license to Nokia (as granted by Nokia to the Licensee(s) on the modifications made by Licensee(s) to the Software. THE SOFTWARE IS PROVIDED "AS IS" AND THE ORIGINAL DEVELOPER DISCLAIMS ANY AND ALL WARRANTIES WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. THOSE INTENDING TO USE THE SOFTWARE ARE EXPRESSLY ADVISED THAT ITS USE MAY INFRINGE EXISTING PATENTS AND BE SUBJECT TO ROYALTY PAYMENTS TO PATENT OWNERS. ANYONE USING THE SOFTWARE ON THE BASIS OF THIS LICENSE AGREES TO OBTAIN THE NECESSARY PERMISSIONS FROM ANY AND ALL APPLICABLE PATENT OWNERS FOR SUCH USE.IN NO EVENT SHALL THE ORIGINAL DEVELOPER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.This copyright, license and warranty information notice must be retained in all copies and derivative works of the Software or substantial portions thereof.*/#include <stdio.h>#include <math.h>#include <limits.h>#include "globals.h"#include "transform.h"#define QUANT_INTRA_ADD (TRA_QUANT_SCALE/3)#define QUANT_INTER_ADD (TRA_QUANT_SCALE/6)static const int16 quantCoef[6][16] = { {13107, 8066,13107, 8066, 8066, 5243, 8066, 5243,13107, 8066,13107, 8066, 8066, 5243, 8066, 5243}, {11916, 7490,11916, 7490, 7490, 4660, 7490, 4660,11916, 7490,11916, 7490, 7490, 4660, 7490, 4660}, {10082, 6554,10082, 6554, 6554, 4194, 6554, 4194,10082, 6554,10082, 6554, 6554, 4194, 6554, 4194}, { 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647, 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647}, { 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355, 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355}, { 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893, 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893}};extern const int8 qpPerTab[52];extern const int8 qpRemTab[52];/* array used to find expencive coefficients */static const int8 COEFF_COST[16] = { 3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0};/* * * traDCT4x4: * * Parameters: * src Source values, and also store the results * * Function: * Compute approximate 4x4 forward DCT. * * Returns: * - */void traDCT4x4(int src[4][4]){ int tmp[4][4]; int e; int f; int i; /* * A = 13a + 13b + 13c + 13d * B = 17a + 7b - 7c - 17d * C = 13a - 13b - 13c + 13d * D = 7a - 17b + 17c - 7d * * e = a + d * f = b + c * A = 13(e + f) * C = 13(e - f) * e = a - d * f = b - c * B = 17e + 7f * D = 7e - 17f */ /* Horizontal transform */ for (i = 0; i < 4; i++) { e = src[i][0] + src[i][3]; f = src[i][1] + src[i][2]; tmp[i][0] = e + f; tmp[i][2] = e - f; e = src[i][0] - src[i][3]; f = src[i][1] - src[i][2]; tmp[i][1] = 2*e + f; tmp[i][3] = e - 2*f; } /* Vertical transform */ for (i = 0; i < 4; i++) { e = tmp[0][i] + tmp[3][i]; f = tmp[1][i] + tmp[2][i]; src[0][i] = e + f; src[2][i] = e - f; e = tmp[0][i] - tmp[3][i]; f = tmp[1][i] - tmp[2][i]; src[1][i] = 2*e + f; src[3][i] = e - 2*f; }}/* * * traHada4x4: * * Parameters: * src Source values, and also store the results * * Function: * Compute Hadamard Transform. * * Returns: * - */void traHada4x4(int src[4][4]){ int tmp[4][4]; int e; int f; int i; /* Horizontal transform */ for (i = 0; i < 4; i++) { e = src[i][0] + src[i][3]; f = src[i][1] + src[i][2]; tmp[i][0] = e + f; tmp[i][2] = e - f; e = src[i][0] - src[i][3]; f = src[i][1] - src[i][2]; tmp[i][1] = e + f; tmp[i][3] = e - f; } /* Vertical transform */ for (i = 0; i < 4; i++) { e = tmp[0][i] + tmp[3][i]; f = tmp[1][i] + tmp[2][i]; src[0][i] = (e + f)>>1; src[2][i] = (e - f)>>1; e = tmp[0][i] - tmp[3][i]; f = tmp[1][i] - tmp[2][i]; src[1][i] = (e + f)>>1; src[3][i] = (e - f)>>1; }}/* * * traDCT2x2: * * Parameters: * src Source values, and also store the results * * Function: * Compute 2x2 forward DCT. * * Returns: * - */void traDCT2x2(int src[2][2]){ int DC0 = src[0][0]; int DC1 = src[0][1]; int DC2 = src[1][0]; int DC3 = src[1][1]; int A, B; /* * DC0 DC1 => DDC(0,0) DDC(1,0) * DC2 DC3 DDC(0,1) DDC(1,1) * * DDC(0,0) = (DC0+DC1+DC2+DC3) * DDC(1,0) = (DC0-DC1+DC2-DC3) * DDC(0,1) = (DC0+DC1-DC2-DC3) * DDC(1,1) = (DC0-DC1-DC2+DC3) */ A = DC0 + DC2; B = DC1 + DC3; src[0][0] = (A + B); src[0][1] = (A - B); A = DC0 - DC2; B = DC1 - DC3; src[1][0] = (A + B); src[1][1] = (A - B);}/* * * traHadamard4x4: * * Parameters: * src Source values, and also store the results * * Function: * Compute Hadamard Transform and sum of absolute coefficients * * Returns: * Sum of absolute coefficiets * */int traHadamard4x4(int src[4][4]){ int tmp[4][4]; int e; int f; int i; int sad; /* * A = a + b + c + d * B = a + b - c - d * C = a - b - c + d * D = a - b + c - d * * e = a + d * f = b + c * A = e + f * C = e - f * e = a - d * f = b - c * B = e + f * D = e - f */ /* Horizontal transform */ for (i = 0; i < 4; i++) { e = src[i][0] + src[i][3]; f = src[i][1] + src[i][2]; tmp[i][0] = e + f; tmp[i][2] = e - f; e = src[i][0] - src[i][3]; f = src[i][1] - src[i][2]; tmp[i][1] = e + f; tmp[i][3] = e - f; } /* Vertical transform and SATD */ for (sad = 0, i = 0; i < 4; i++) { e = tmp[0][i] + tmp[3][i]; f = tmp[1][i] + tmp[2][i]; sad += abs(e + f); sad += abs(e - f); e = tmp[0][i] - tmp[3][i]; f = tmp[1][i] - tmp[2][i]; sad += abs(e + f); sad += abs(e - f); } return sad;}/* * * traDiffSATD4x4: * * Parameters: * orig Original values * pred Prediction values * * Function: * Compute difference between orig and pred, compute hadamard * transform on difference matrix and compute sum of absolute * transformed differences. * * Returns: * Sum of absolute transformed differences * */int traDiffSATD4x4(u_int8 orig[BLK_SIZE][MBK_SIZE], u_int8 pred[BLK_SIZE][MBK_SIZE]){ int tmp[4][4]; int a, b, c, d; int e; int f;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -