📄 refframe.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 <assert.h>#include <string.h>#include <stdio.h>#include "nccglob.h"#include "debug.h"#include "RefFrame.h"#define ONEFOURTH1 20#define ONEFOURTH2 -5#define ONEFOURTH3 1void refFrmUpsampleLumaH(u_int8 *yBuf, u_int8 *reco, int picWidth, int picHeight, int xExt, int yExt);void refFrmUpsampleLumaV(u_int8 *yBuf, int picWidth, int picHeight, int xExt, int yExt);void refFrmPartialSum8x8(u_int8 *yBufIn, u_int16 *seaYBufIn, int picWidth, int picHeight, int xExt, int yExt);const u_int8 clip8Buf[768] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,};/* * * allocMemRef: * * Parameters: * blkSize Block size * unitSize unit size * * Function: * Allocate blkSize*unitSize bytes of memory * * Returns: * Pointer to allocated memory * */static void *allocMemRef(int blkSize, size_t unitSize){ void *mem; if ((mem = nccMalloc(blkSize*unitSize)) == NULL) { deb0f(stderr, "Cannot allocate memory for reference frame\n"); nccExit(1); } return mem;}/* * * refFrmOpen: * * Parameters: * pRefFrm Pointer to reference frame object * pEncPar Pointer to encoding parameter object * * Function: * Initialize the reference frame object, and allocate memory for frame * buffers. Each component has separate buffer, with extended area for * the extended bounfaries. Y buffer is different from u/v buffer in * that Y samples will be upsampled by 2 in both directions. * * Returns: * - * */void refFrmOpen(refFrmBuf_s *pRefFrm, encParams_s *pEncPar){ int extWidth, extHeight, extBufSize; pRefFrm->picWidth = (int16) pEncPar->picWidth; pRefFrm->picHeight = (int16) pEncPar->picHeight; // xExt & yExt are specified for original y, // so for y in reference buffer, the actual extension is twice as much, // but the extension for u/v is only half of xExt and yExt. // extension of 16 is not necessary, not it is nice to align the buffer pRefFrm->xExt = 16; pRefFrm->yExt = 16; // leave some margin so that it is easier to take care // boundary coundition in motion search pRefFrm->searchArea.x0 = (int16)(-pRefFrm->xExt + 2); pRefFrm->searchArea.y0 = (int16)(-pRefFrm->yExt + 2); pRefFrm->searchArea.x1 = (int16)(pRefFrm->picWidth + pRefFrm->xExt - 2); pRefFrm->searchArea.y1 = (int16)(pRefFrm->picHeight + pRefFrm->yExt - 2); extWidth = pRefFrm->picWidth + pRefFrm->xExt * 2; extHeight = pRefFrm->picHeight + pRefFrm->yExt * 2; pRefFrm->yBufWidth = (int16) (extWidth * 2); pRefFrm->yBufHeight = (int16) (extHeight * 2); pRefFrm->cBufWidth = (int16) (extWidth >> 1); extBufSize = extWidth * extHeight; pRefFrm->yBuf = (u_int8 *) allocMemRef(4 * extBufSize, sizeof(u_int8)); pRefFrm->uBuf = (u_int8 *) allocMemRef(extBufSize/4, sizeof(u_int8)); pRefFrm->vBuf = (u_int8 *) allocMemRef(extBufSize/4, sizeof(u_int8)); // always use SEA // : take away partial sum if (!pEncPar->low_complex_prof3) pRefFrm->seaYBuf = (u_int16 *)allocMemRef(extBufSize, sizeof(u_int16)); // the pointers pointing the first actual samples // y is upsampled by 2 in both horizontal and vertical directions pRefFrm->y = pRefFrm->yBuf + pRefFrm->yBufWidth * pRefFrm->yExt * 2 + pRefFrm->xExt * 2; pRefFrm->u = pRefFrm->uBuf + pRefFrm->cBufWidth * (pRefFrm->yExt/2) + pRefFrm->xExt/2; pRefFrm->v = pRefFrm->vBuf + pRefFrm->cBufWidth * (pRefFrm->yExt/2) + pRefFrm->xExt/2; // : take away partial sum if (!pEncPar->low_complex_prof3) pRefFrm->partSums = pRefFrm->seaYBuf + extWidth * pRefFrm->yExt + pRefFrm->xExt; pRefFrm->forOutput = 0; pRefFrm->forRef = 0; pRefFrm->frameNum = -1; pRefFrm->isShortTerm = -1; pRefFrm->picNum = 0; // the channel distortion array is based on MBs if (pEncPar->sIntraRefresh) pRefFrm->channelDistortion = (int*)nccMalloc(sizeof(int)*pRefFrm->picWidth/MBK_SIZE * pRefFrm->picHeight/MBK_SIZE); else pRefFrm->channelDistortion = NULL;}/* * * refFrmClose: * * Parameters: * pRefFrm Pointer to reference frame object to be released * low_complex_prof3 Low complexity prof 3 * use_search_win Use internal search window * * Function: * Deallocate reference frame buffer memory. * * Returns: * - * */void refFrmClose(refFrmBuf_s *pRefFrm, int low_complex_prof3){ nccFree(pRefFrm->yBuf); nccFree(pRefFrm->uBuf); nccFree(pRefFrm->vBuf); // : take away partial sum if (!low_complex_prof3) nccFree(pRefFrm->seaYBuf); if (pRefFrm->channelDistortion) nccFree(pRefFrm->channelDistortion);}/* * * refFrmUpsampleLumaH * * Parameters: * reco y component of reconstructed frame * yBuf Luma reference pixels * picWidth Picture width in pixels * picHeight Picture height in pixels * xExt Reference frame x-extension in pixels * yExt Reference frame y-extension in pixels * * Function: * Horizontal upsampling of luma. * * * Returns: * - */#if 0void refFrmUpsampleLumaH(u_int8 *reco, u_int8 *yBuf, int picWidth, int picHeight, int xExt, int yExt){ int i, j, tmp; u_int8 *yBufLine; int extBufWidth; // pRefFrm->yBufWidth/height has extended boundary extBufWidth = 2*(picWidth + 2*xExt); yBufLine = yBuf + 2*yExt*extBufWidth; // upsample by 2 and filter horizontally for (i = 0; i < picHeight; i ++) { int a, b, c, d, e, f; a = *reco++; // left pixel // left extension, these pixels are indentical for (j = xExt-2; j > 0; j--) { // left boundary *yBufLine++ = (u_int8) a; *yBufLine++ = (u_int8) a; } // Horizontal filtering to generate odd locations // Interpolate 6 values per iteration. We'll use variable // a,b,c,d,e and f in rotating manner to avoid unnecessary mem loads b = c = d = e = a; for (j = (2 + picWidth - 3) - 6; j >= 0; j -= 6) { f = *reco++; *yBufLine++ = (u_int8) c; tmp = (a + 5*(-b + 4*(c + d) - e) + f + 16) >> 5;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -