1 /* 2 * Copyright (C) 2007-2008 ARM Limited 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 /** 18 * 19 * File Name: omxVCM4P2_TransRecBlockCoef_intra.c 20 * OpenMAX DL: v1.0.2 21 * Revision: 9641 22 * Date: Thursday, February 7, 2008 23 * 24 * 25 * 26 * 27 * Description: 28 * Contains modules DCT->quant and reconstructing the intra texture data 29 * 30 */ 31 32 #include "omxtypes.h" 33 #include "armOMX.h" 34 #include "omxVC.h" 35 36 #include "armCOMM.h" 37 #include "armVC.h" 38 39 40 /** 41 * Function: omxVCM4P2_TransRecBlockCoef_intra (6.2.4.4.4) 42 * 43 * Description: 44 * Quantizes the DCT coefficients, implements intra block AC/DC coefficient 45 * prediction, and reconstructs the current intra block texture for prediction 46 * on the next frame. Quantized row and column coefficients are returned in 47 * the updated coefficient buffers. 48 * 49 * Input Arguments: 50 * 51 * pSrc - pointer to the pixels of current intra block; must be aligned on 52 * an 8-byte boundary. 53 * pPredBufRow - pointer to the coefficient row buffer containing 54 * ((num_mb_per_row * 2 + 1) * 8) elements of type OMX_S16. 55 * Coefficients are organized into blocks of eight as described 56 * below (Internal Prediction Coefficient Update Procedures). The 57 * DC coefficient is first, and the remaining buffer locations 58 * contain the quantized AC coefficients. Each group of eight row 59 * buffer elements combined with one element eight elements ahead 60 * contains the coefficient predictors of the neighboring block 61 * that is spatially above or to the left of the block currently to 62 * be decoded. A negative-valued DC coefficient indicates that this 63 * neighboring block is not INTRA-coded or out of bounds, and 64 * therefore the AC and DC coefficients are invalid. Pointer must 65 * be aligned on an 8-byte boundary. 66 * pPredBufCol - pointer to the prediction coefficient column buffer 67 * containing 16 elements of type OMX_S16. Coefficients are 68 * organized as described in section 6.2.2.5. Pointer must be 69 * aligned on an 8-byte boundary. 70 * pSumErr - pointer to a flag indicating whether or not AC prediction is 71 * required; AC prediction is enabled if *pSumErr >=0, but the 72 * value is not used for coefficient prediction, i.e., the sum of 73 * absolute differences starts from 0 for each call to this 74 * function. Otherwise AC prediction is disabled if *pSumErr < 0 . 75 * blockIndex - block index indicating the component type and position, as 76 * defined in [ISO14496-2], subclause 6.1.3.8. 77 * curQp - quantization parameter of the macroblock to which the current 78 * block belongs 79 * pQpBuf - pointer to a 2-element quantization parameter buffer; pQpBuf[0] 80 * contains the quantization parameter associated with the 8x8 81 * block left of the current block (QPa), and pQpBuf[1] contains 82 * the quantization parameter associated with the 8x8 block above 83 * the current block (QPc). In the event that the corresponding 84 * block is outside of the VOP bound, the Qp value will not affect 85 * the intra prediction process, as described in [ISO14496-2], 86 * sub-clause 7.4.3.3, Adaptive AC Coefficient Prediction. 87 * srcStep - width of the source buffer; must be a multiple of 8. 88 * dstStep - width of the reconstructed destination buffer; must be a 89 * multiple of 16. 90 * shortVideoHeader - binary flag indicating presence of 91 * short_video_header; shortVideoHeader==1 selects linear intra DC 92 * mode, and shortVideoHeader==0 selects non linear intra DC mode. 93 * 94 * Output Arguments: 95 * 96 * pDst - pointer to the quantized DCT coefficient buffer; pDst[0] contains 97 * the predicted DC coefficient; the remaining entries contain the 98 * quantized AC coefficients (without prediction). The pointer 99 * pDstmust be aligned on a 16-byte boundary. 100 * pRec - pointer to the reconstructed texture; must be aligned on an 101 * 8-byte boundary. 102 * pPredBufRow - pointer to the updated coefficient row buffer 103 * pPredBufCol - pointer to the updated coefficient column buffer 104 * pPreACPredict - if prediction is enabled, the parameter points to the 105 * start of the buffer containing the coefficient differences for 106 * VLC encoding. The entry pPreACPredict[0]indicates prediction 107 * direction for the current block and takes one of the following 108 * values: OMX_VC_NONE (prediction disabled), OMX_VC_HORIZONTAL, or 109 * OMX_VC_VERTICAL. The entries 110 * pPreACPredict[1]-pPreACPredict[7]contain predicted AC 111 * coefficients. If prediction is disabled (*pSumErr<0) then the 112 * contents of this buffer are undefined upon return from the 113 * function 114 * pSumErr - pointer to the value of the accumulated AC coefficient errors, 115 * i.e., sum of the absolute differences between predicted and 116 * unpredicted AC coefficients 117 * 118 * Return Value: 119 * 120 * OMX_Sts_NoErr - no error 121 * OMX_Sts_BadArgErr - Bad arguments: 122 * - At least one of the following pointers is NULL: pSrc, pDst, pRec, 123 * pCoefBufRow, pCoefBufCol, pQpBuf, pPreACPredict, pSumErr. 124 * - blockIndex < 0 or blockIndex >= 10; 125 * - curQP <= 0 or curQP >= 32. 126 * - srcStep, or dstStep <= 0 or not a multiple of 8. 127 * - pDst is not 16-byte aligned: . 128 * - At least one of the following pointers is not 8-byte aligned: 129 * pSrc, pRec. 130 * 131 * Note: The coefficient buffers must be updated in accordance with the 132 * update procedures defined in section in 6.2.2. 133 * 134 */ 135 136 OMXResult omxVCM4P2_TransRecBlockCoef_intra( 137 const OMX_U8 *pSrc, 138 OMX_S16 * pDst, 139 OMX_U8 * pRec, 140 OMX_S16 *pPredBufRow, 141 OMX_S16 *pPredBufCol, 142 OMX_S16 * pPreACPredict, 143 OMX_INT *pSumErr, 144 OMX_INT blockIndex, 145 OMX_U8 curQp, 146 const OMX_U8 *pQpBuf, 147 OMX_INT srcStep, 148 OMX_INT dstStep, 149 OMX_INT shortVideoHeader 150 ) 151 { 152 /* 64 elements are needed but to align it to 16 bytes need 153 8 more elements of padding */ 154 OMX_S16 tempBuf1[79], tempBuf2[79]; 155 OMX_S16 tempBuf3[79]; 156 OMX_S16 *pTempBuf1, *pTempBuf2,*pTempBuf3; 157 OMXVCM4P2VideoComponent videoComp; 158 OMX_U8 flag; 159 OMX_INT x, y, count, predDir; 160 OMX_INT predQP, ACPredFlag; 161 162 163 /* Aligning the local buffers */ 164 pTempBuf1 = armAlignTo16Bytes(tempBuf1); 165 pTempBuf2 = armAlignTo16Bytes(tempBuf2); 166 pTempBuf3 = armAlignTo16Bytes(tempBuf3); 167 168 /* Argument error checks */ 169 armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr); 170 armRetArgErrIf(pRec == NULL, OMX_Sts_BadArgErr); 171 armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr); 172 armRetArgErrIf(!armIs8ByteAligned(pSrc), OMX_Sts_BadArgErr); 173 armRetArgErrIf(!armIs8ByteAligned(pRec), OMX_Sts_BadArgErr); 174 armRetArgErrIf(!armIs16ByteAligned(pDst), OMX_Sts_BadArgErr); 175 armRetArgErrIf(pPredBufRow == NULL, OMX_Sts_BadArgErr); 176 armRetArgErrIf(pPredBufCol == NULL, OMX_Sts_BadArgErr); 177 armRetArgErrIf(pPreACPredict == NULL, OMX_Sts_BadArgErr); 178 armRetArgErrIf(pSumErr == NULL, OMX_Sts_BadArgErr); 179 armRetArgErrIf(pQpBuf == NULL, OMX_Sts_BadArgErr); 180 armRetArgErrIf((srcStep <= 0) || (dstStep <= 0) || 181 (dstStep & 7) || (srcStep & 7) 182 , OMX_Sts_BadArgErr); 183 armRetArgErrIf((blockIndex < 0) || (blockIndex > 9), OMX_Sts_BadArgErr); 184 185 armRetArgErrIf((curQp <= 0) || (curQp >=32), OMX_Sts_BadArgErr); 186 187 188 /* Setting the videoComp */ 189 if (blockIndex <= 3) 190 { 191 videoComp = OMX_VC_LUMINANCE; 192 } 193 else 194 { 195 videoComp = OMX_VC_CHROMINANCE; 196 } 197 /* Converting from 2-d to 1-d buffer */ 198 for (y = 0, count = 0; y < 8; y++) 199 { 200 for(x= 0; x < 8; x++, count++) 201 { 202 pTempBuf1[count] = pSrc[(y*srcStep) + x]; 203 } 204 } 205 206 omxVCM4P2_DCT8x8blk (pTempBuf1, pTempBuf2); 207 omxVCM4P2_QuantIntra_I( 208 pTempBuf2, 209 curQp, 210 blockIndex, 211 shortVideoHeader); 212 213 /* Converting from 1-D to 2-D buffer */ 214 for (y = 0, count = 0; y < 8; y++) 215 { 216 for(x = 0; x < 8; x++, count++) 217 { 218 /* storing tempbuf2 to tempbuf1 */ 219 pTempBuf1[count] = pTempBuf2[count]; 220 pDst[(y*dstStep) + x] = pTempBuf2[count]; 221 } 222 } 223 224 /* AC and DC prediction */ 225 armVCM4P2_SetPredDir( 226 blockIndex, 227 pPredBufRow, 228 pPredBufCol, 229 &predDir, 230 &predQP, 231 pQpBuf); 232 233 armRetDataErrIf(((predQP <= 0) || (predQP >= 32)), OMX_Sts_BadArgErr); 234 235 flag = 1; 236 if (*pSumErr < 0) 237 { 238 ACPredFlag = 0; 239 } 240 else 241 { 242 ACPredFlag = 1; 243 } 244 245 armVCM4P2_ACDCPredict( 246 pTempBuf2, 247 pPreACPredict, 248 pPredBufRow, 249 pPredBufCol, 250 curQp, 251 predQP, 252 predDir, 253 ACPredFlag, 254 videoComp, 255 flag, 256 pSumErr); 257 258 /* Reconstructing the texture data */ 259 omxVCM4P2_QuantInvIntra_I( 260 pTempBuf1, 261 curQp, 262 videoComp, 263 shortVideoHeader); 264 omxVCM4P2_IDCT8x8blk (pTempBuf1, pTempBuf3); 265 for(count = 0; count < 64; count++) 266 { 267 pRec[count] = armMax(0,pTempBuf3[count]); 268 } 269 270 return OMX_Sts_NoErr; 271 } 272 273 /* End of file */ 274 275 276