123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980 |
- // SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause
- /*
- * Copyright (c) 2018, Chips&Media
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include "../jpuapi/regdefine.h"
- #include "../jpuapi/jpuapi.h"
- #include "../jpuapi/jpuapifunc.h"
- #include "../jpuapi/jputable.h"
- #include "jpulog.h"
- #include "main_helper.h"
- fb_context s_fb[MAX_NUM_INSTANCE];
- static int StoreYuvImageBurstFormat_V20(int chromaStride, Uint8 * dst, int picWidth, int picHeight, Uint32 bitDepth,Uint64 addrY, Uint64 addrCb, Uint64 addrCr, Uint32 stride, FrameFormat format, int endian, CbCrInterLeave interLeave, PackedFormat packed);
- // Figure A.6 - Zig-zag sequence of quantized DCT coefficients
- const int InvScanTable[64] = {
- 0, 1, 5, 6, 14, 15, 27, 28,
- 2, 4, 7, 13, 16, 26, 29, 42,
- 3, 8, 12, 17, 25, 30, 41, 43,
- 9, 11, 18, 24, 31, 40, 44, 53,
- 10, 19, 23, 32, 39, 45, 52, 54,
- 20, 22, 33, 38, 46, 51, 55, 60,
- 21, 34, 37, 47, 50, 56, 59, 61,
- 35, 36, 48, 49, 57, 58, 62, 63
- };
- const int ScanTable[64] = {
- 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63
- };
- /******************************************************************************
- DPB Image Data Control
- ******************************************************************************/
- #define MAX_ROW_IN_MCU 8
- static void TiledToLinear(Uint8* pSrc, Uint8* pDst, Uint32 width, Uint32 height, Uint32 cWidth, Uint32 cHeight, Uint32 lineWidth)
- {
- Uint32 picX, picY;
- Uint32 yuvAddr = 0;
- Uint32 convAddr = 0;
- Uint32 chromaBase = 0;
- Uint32 row = 0;
- Uint32 col = 0;
- Uint32 ncols = width / lineWidth;
- // Luma data.
- for (picY = 0; picY < height; picY++) {
- for (picX = 0; picX < width; picX += lineWidth) {
- convAddr = ((picY/MAX_ROW_IN_MCU)*MAX_ROW_IN_MCU*width) + (row*width) + col*lineWidth;
- memcpy(pDst + convAddr, pSrc + yuvAddr, lineWidth);
- yuvAddr += lineWidth;
- row++;
- row %= 8;
- if (row == 0) col++;
- col %= ncols;
- }
- }
- chromaBase = convAddr + lineWidth; // add last line
- // Chroma data.
- // lineWidth*2. only support Cb Cr interleaved format.
- lineWidth *= 2;
- col = row = 0;
- convAddr = 0;
- ncols = cWidth / lineWidth;
- for (picY = 0; picY < cHeight; picY++) {
- for (picX = 0; picX < cWidth; picX += lineWidth) {
- convAddr = ((picY/MAX_ROW_IN_MCU)*MAX_ROW_IN_MCU*cWidth) + (row*cWidth) + col*lineWidth;
- memcpy(pDst + chromaBase + convAddr, pSrc + yuvAddr, lineWidth);
- yuvAddr += lineWidth;
- row++;
- row %= 8;
- if (row == 0) col++;
- col %= ncols;
- }
- }
- }
- int SaveYuvImageHelper(
- Uint8* pYuv,
- FrameBuffer* fb,
- CbCrInterLeave interLeave,
- PackedFormat packed,
- Uint32 picWidth,
- Uint32 picHeight,
- Uint32 bitDepth
- )
- {
- int frameSize;
- if (pYuv == NULL) {
- JLOG(ERR, "%s:%d pYuv is NULL\n", __FUNCTION__, __LINE__);
- return 0;
- }
- frameSize = StoreYuvImageBurstFormat_V20(fb->strideC, pYuv, picWidth, picHeight, bitDepth,
- fb->bufY,
- fb->bufCb,
- fb->bufCr,
- fb->stride,
- fb->format,
- fb->endian,
- interLeave,
- packed);
- return frameSize;
- }
- int StoreYuvImageBurstFormatWhenNotAligned(int chromaStride, Uint8 * dst, int picWidth, int picHeight, Uint32 bitDepth,
- Uint64 addrY, Uint64 addrCb, Uint64 addrCr, Uint32 stride, FrameFormat format, int endian, CbCrInterLeave interLeave, PackedFormat packed)
- {
- int size;
- int y, nY = 0, nCb, nCr;
- Uint64 addr;
- int lumaSize, chromaSize = 0, chromaWidth = 0, chromaHeight =0;
- Uint8 * puc;
- int chromaStride_i = 0;
- Uint32 bytesPerPixel = (bitDepth + 7) / 8;
- chromaStride_i = chromaStride;
- switch (format)
- {
- case FORMAT_420:
- nY = picHeight;
- nCb = nCr = picHeight / 2;
- chromaSize = (picWidth/2) * (picHeight/2);
- chromaWidth = picWidth/2;
- chromaHeight = nY;
- break;
- case FORMAT_440:
- nY = picHeight;
- nCb = nCr = picHeight / 2;
- chromaSize = (picWidth) * (picHeight / 2);
- chromaWidth = picWidth;
- chromaHeight = nY;
- break;
- case FORMAT_422:
- nY = picHeight;
- nCb = nCr = picHeight;
- chromaSize = (picWidth/2) * picHeight ;
- chromaWidth = (picWidth/2);
- chromaHeight = nY*2;
- break;
- case FORMAT_444:
- nY = picHeight;
- nCb = nCr = picHeight;
- chromaSize = picWidth * picHeight;
- chromaWidth = picWidth;
- chromaHeight = nY*2;
- break;
- case FORMAT_400:
- nY = picHeight;
- nCb = nCr = 0;
- chromaSize = 0;
- chromaWidth = 0;
- chromaHeight = 0;
- break;
- default:
- return 0;
- }
- puc = dst;
- addr = addrY;
- if (packed)
- {
- if (packed == PACKED_FORMAT_444)
- picWidth *= 3;
- else
- picWidth *= 2;
- chromaSize = 0;
- }
- lumaSize = picWidth * nY;
- size = lumaSize + chromaSize*2;
- lumaSize *= bytesPerPixel;
- chromaSize *= bytesPerPixel;
- size *= bytesPerPixel;
- picWidth *= bytesPerPixel;
- chromaWidth *= bytesPerPixel;
- if (interLeave){
- chromaSize = chromaSize *2;
- chromaWidth = chromaWidth *2;
- chromaStride_i = chromaStride_i;
- }
- if ((picWidth != stride) || (chromaWidth != chromaStride_i))
- {
- for (y = 0; y < nY; ++y) {
- JpuReadMem(addr + stride * y, (Uint8 *)(puc + y * picWidth), picWidth, endian);
- }
- if(packed)
- return size;
- if (interLeave)
- {
- puc = dst + lumaSize;
- addr = addrCb;
- for (y = 0; y < (chromaHeight/2); ++y) {
- JpuReadMem(addr + (chromaStride_i)*y, (Uint8 *)(puc + y*(chromaWidth)), (chromaWidth), endian);
- }
- }
- else
- {
- puc = dst + lumaSize;
- addr = addrCb;
- for (y = 0; y < nCb; ++y) {
- JpuReadMem(addr + chromaStride_i * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
- }
- puc = dst + lumaSize + chromaSize;
- addr = addrCr;
- for (y = 0; y < nCr; ++y) {
- JpuReadMem(addr + chromaStride_i * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
- }
- }
- }
- else if (!packed && interLeave && lumaSize != (addrCb - addrY))
- {
- JpuReadMem(addr, (Uint8 *)( puc ), lumaSize, endian);
- puc = dst + lumaSize;
- addr = addrCb;
- JpuReadMem(addr, (Uint8 *)(puc), chromaSize, endian);
- }
- else if (!packed && !interLeave && (lumaSize != (addrCb - addrY) || chromaSize != addrCr - addrCb))
- {
- JpuReadMem(addr, (Uint8 *)( puc ), lumaSize, endian);
- puc = dst + lumaSize;
- addr = addrCb;
- JpuReadMem(addr, (Uint8 *)(puc), chromaSize, endian);
- puc = dst + lumaSize + chromaSize;
- addr = addrCr;
- JpuReadMem(addr, (Uint8 *)(puc), chromaSize, endian);
- }
- return size;
- }//lint !e429
- int SaveYuvImageHelperDma(
- Uint8* pYuv,
- FrameBuffer* fb,
- CbCrInterLeave interLeave,
- PackedFormat packed,
- Uint32 picWidth,
- Uint32 picHeight,
- Uint32 bitDepth
- )
- {
- int frameSize;
- if (pYuv == NULL) {
- JLOG(ERR, "%s:%d pYuv is NULL\n", __FUNCTION__, __LINE__);
- return 0;
- }
- frameSize = StoreYuvImageBurstFormatWhenNotAligned(fb->strideC, pYuv, picWidth, picHeight, bitDepth,
- fb->bufY,
- fb->bufCb,
- fb->bufCr,
- fb->stride,
- fb->format,
- fb->endian,
- interLeave,
- packed);
- return frameSize;
- }
- int SaveYuvImageHelperFormat_V20(
- FILE* yuvFp,
- Uint8* pYuv,
- FrameBuffer* fb,
- CbCrInterLeave interLeave,
- PackedFormat packed,
- Uint32 picWidth,
- Uint32 picHeight,
- Uint32 bitDepth,
- BOOL tiled2Linear
- )
- {
- int frameSize;
- if (pYuv == NULL) {
- JLOG(ERR, "%s:%d pYuv is NULL\n", __FUNCTION__, __LINE__);
- return 0;
- }
- frameSize = StoreYuvImageBurstFormat_V20(fb->strideC, pYuv, picWidth, picHeight, bitDepth,
- fb->bufY,
- fb->bufCb,
- fb->bufCr,
- fb->stride,
- fb->format,
- fb->endian,
- interLeave,
- packed);
- if (tiled2Linear == TRUE) {
- Uint32 Bpp = JPU_CEIL(8, bitDepth) / 8;
- Uint32 width = JPU_CEIL(picWidth,8) * Bpp;
- Uint32 height = JPU_CEIL(picHeight,8);
- Uint32 tiledFrameSize;
- Uint8* pConv = NULL;
- Uint8* base = NULL;
- Uint8* target = NULL;
- Uint32 cWidth = (fb->format == FORMAT_420 || fb->format == FORMAT_422) ? width / 2 : width;
- Uint32 cHeight = (fb->format == FORMAT_420 || fb->format == FORMAT_440) ? height / 2 : height;
- Uint32 lineWidth = 8 * Bpp;
- Uint32 y, linearChromaWidth, linearChromaHeight;
- switch (fb->format) {
- case FORMAT_400: linearChromaWidth = 0, linearChromaHeight = 0, tiledFrameSize = width * height; break;
- case FORMAT_420: linearChromaWidth = picWidth, linearChromaHeight = picHeight/2, tiledFrameSize = width * height * 3 /2; break;
- case FORMAT_422: linearChromaWidth = picWidth, linearChromaHeight = picHeight, tiledFrameSize = width * height * 2; break;
- case FORMAT_440: linearChromaWidth = picWidth*2, linearChromaHeight = picHeight/2, tiledFrameSize = width * height * 2; break;
- case FORMAT_444: linearChromaWidth = picWidth*2, linearChromaHeight = picHeight, tiledFrameSize = width * height * 3; break;
- default:
- JLOG(ERR, "%d:%d Unknown format:(%d)\n", __FUNCTION__, __LINE__, fb->format);
- return 0;
- }
- if ((pConv=(Uint8*)malloc(tiledFrameSize)) == NULL) {
- JLOG(ERR, "%s:%d Failed to allocate memory\n", __FUNCTION__, __LINE__);
- return 0;
- }
- if (fb->format == FORMAT_400) {
- cWidth = cHeight = 0;
- }
- cWidth *= 2; // Must be semi-planar.
- TiledToLinear(pYuv, pConv, width, height, cWidth, cHeight, lineWidth);
- base = pConv;
- target = pYuv;
- // Copy Luma
- for (y=0; y<picHeight; y++) {
- memcpy((void*)target, (void*)(base + y*width), picWidth);
- target += fb->stride;
- }
- base = pConv + (width*height);
- // Copy Chroma
- for (y=0; y<linearChromaHeight; y++) {
- memcpy((void*)target, (void*)(base+ y*cWidth), linearChromaWidth);
- target += fb->strideC;
- }
- free((void*)pConv);
- }
- if (yuvFp)
- {
- if( !fwrite(pYuv, sizeof(Uint8), frameSize , yuvFp) )
- {
- JLOG(ERR, "Frame Data fwrite failed file handle is 0x%x \n", yuvFp );
- return 0;
- }
- fflush(yuvFp);
- }
- return 1;
- }
- /******************************************************************************
- JPEG specific Helper
- ******************************************************************************/
- static int getTblElement(FILE *fp, char *str)
- {
- while (1) {
- if (fgets(str, 256, fp) == NULL)
- return 0;
- if ((str[0] != ';') && (str[0] != '/'))
- break;
- }
- return 1;
- }
- static int parseHuffmanTable(FILE * fp, EncMjpgParam *param, int prec)
- {
- char sLine[258] = {0,};
- unsigned int h[8] = {0,};
- BYTE *huffBit;
- BYTE *huffVal;
- int i, j;
- int max_ac = 162;
- if (prec)
- max_ac = 256;
- huffBit = param->huffBits[DC_TABLE_INDEX0];
- huffVal = param->huffVal[DC_TABLE_INDEX0];
- for (i=0; i<2; i++) // Luma DC BitLength
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++)
- *huffBit++ = (BYTE)h[j];
- }
- for (i=0; i<(16/8); i++) // Luma DC HuffValue
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++)
- *huffVal++ = (BYTE)h[j];
- }
- huffBit = param->huffBits[AC_TABLE_INDEX0];
- huffVal = param->huffVal[AC_TABLE_INDEX0];
- for (i=0; i<(16/8); i++) // Luma AC BitLength
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++)
- *huffBit++ = (BYTE)h[j];
- }
- for (i=0; i<(max_ac/8); i++) // Luma AC HuffValue
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++)
- *huffVal++ = (BYTE)h[j];
- }
- if (!prec){
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<2; j++)
- *huffVal++ = (BYTE)h[j];
- }
- huffBit = param->huffBits[DC_TABLE_INDEX1];
- huffVal = param->huffVal[DC_TABLE_INDEX1];
- for (i=0; i<(16/8); i++) // Chroma DC BitLength
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++)
- *huffBit++ = (BYTE)h[j];
- }
- for (i=0; i<(16/8); i++) // Chroma DC HuffValue
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++)
- *huffVal++ = (BYTE)h[j];
- }
- huffBit = param->huffBits[AC_TABLE_INDEX1];
- huffVal = param->huffVal[AC_TABLE_INDEX1];
- for (i=0; i<(16/8); i++) // Chroma AC BitLength
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++)
- *huffBit++ = (BYTE)h[j];
- }
- for (i=0; i<(max_ac/8); i++) // Luma AC HuffValue
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++)
- *huffVal++ = (BYTE)h[j];
- }
- if (!prec){
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<2; j++)
- *huffVal++ = (BYTE)h[j];
- }
- return 1;
- }
- static int parseQMatrix(FILE * fp, EncMjpgParam *param)
- {
- char sLine[256] = {0,};
- int i,j;
- unsigned int h[8] = {0,};
- short temp_dc[64], temp_ac[64];
- short *qTable_dc, *qTable_ac, *qTable;
- qTable = temp_dc;
- for (i=0; i < (64/8); i++)
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++){
- if (param->lumaQ12bit == TRUE)
- *qTable++ = h[j] & 0xffff;
- else
- *qTable++ = h[j] & 0x00ff;
- }
- }
- qTable = temp_ac;
- for (i=0; i < (64/8); i++)
- {
- if (getTblElement(fp, sLine) == 0)
- return 0;
- memset(h, 0x00, 8*sizeof(unsigned int));
- sscanf(sLine, "%x %x %x %x %x %x %x %x", &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7]);
- for (j=0; j<8; j++){
- if (param->chromaQ12bit == TRUE)
- *qTable++ = h[j] & 0xffff;
- else
- *qTable++ = h[j] & 0x00ff;
- }
- }
- qTable_dc = param->qMatTab[DC_TABLE_INDEX0];
- qTable_ac = param->qMatTab[AC_TABLE_INDEX0];
- for (i=0; i < 64; i++)
- {
- qTable_dc[InvScanTable[i]] = temp_dc[i];
- qTable_ac[InvScanTable[i]] = temp_ac[i];
- }
- memcpy(param->qMatTab[DC_TABLE_INDEX1], param->qMatTab[DC_TABLE_INDEX0], 64*sizeof(short));
- memcpy(param->qMatTab[AC_TABLE_INDEX1], param->qMatTab[AC_TABLE_INDEX0], 64*sizeof(short));
- return 1;
- }
- int jpgGetHuffTable(char *huffFileName, EncMjpgParam *param, int prec)
- {
- char huffFilePath[256];
- FILE *huffFp = NULL;
- if (huffFileName[0] != 0) {
- strcpy(huffFilePath, huffFileName);
- huffFp = fopen(huffFilePath, "rt");
- if (huffFp == NULL) {
- JLOG( ERR, "Can't open Huffman Table file %s \n", huffFilePath);
- return 0;
- }
- parseHuffmanTable(huffFp, param, prec);
- fclose(huffFp);
- }
- else {
- if (prec){
- memcpy(param->huffBits[DC_TABLE_INDEX0], lumaDcBits_ES, 16); // Luma DC BitLength
- memcpy(param->huffVal[DC_TABLE_INDEX0], lumaDcValue_ES, 16); // Luma DC HuffValue
- memcpy(param->huffBits[AC_TABLE_INDEX0], lumaAcBits_ES, 16); // Luma DC BitLength
- memcpy(param->huffVal[AC_TABLE_INDEX0], lumaAcValue_ES, 256); // Luma DC HuffValue
- memcpy(param->huffBits[DC_TABLE_INDEX1], chromaDcBits_ES, 16); // Chroma DC BitLength
- memcpy(param->huffVal[DC_TABLE_INDEX1], chromaDcValue_ES, 16); // Chroma DC HuffValue
- memcpy(param->huffBits[AC_TABLE_INDEX1], chromaAcBits_ES, 16); // Chroma AC BitLength
- memcpy(param->huffVal[AC_TABLE_INDEX1], chromaAcValue_ES, 256); // Chorma AC HuffValue
- } else {
- memcpy(param->huffBits[DC_TABLE_INDEX0], lumaDcBits, 16); // Luma DC BitLength
- memcpy(param->huffVal[DC_TABLE_INDEX0], lumaDcValue, 16); // Luma DC HuffValue
- memcpy(param->huffBits[AC_TABLE_INDEX0], lumaAcBits, 16); // Luma DC BitLength
- memcpy(param->huffVal[AC_TABLE_INDEX0], lumaAcValue, 162); // Luma DC HuffValue
- memcpy(param->huffBits[DC_TABLE_INDEX1], chromaDcBits, 16); // Chroma DC BitLength
- memcpy(param->huffVal[DC_TABLE_INDEX1], chromaDcValue, 16); // Chroma DC HuffValue
- memcpy(param->huffBits[AC_TABLE_INDEX1], chromaAcBits, 16); // Chroma AC BitLength
- memcpy(param->huffVal[AC_TABLE_INDEX1], chromaAcValue, 162); // Chorma AC HuffValue
- }
- }
- return 1;
- }
- int jpgGetQMatrix(char *qMatFileName, EncMjpgParam *param)
- {
- char qMatFilePath[256];
- FILE *qMatFp = NULL;
- int i;
- if ( qMatFileName[0] != 0 ) {
- strcpy(qMatFilePath, qMatFileName);
- qMatFp = fopen(qMatFilePath, "rt" );
- if ( !qMatFp ) {
- JLOG(ERR, "Can't open Q Matrix file %s \n", qMatFilePath);
- return 0;
- }
- parseQMatrix(qMatFp, param);
- fclose(qMatFp);
- }
- else {
- // Rearrange and insert pre-defined Q-matrix to deticated variable.
- for (i=0; i<64; i++){
- param->qMatTab[DC_TABLE_INDEX0][i] = lumaQ2[i] & 0x00ff;
- param->qMatTab[DC_TABLE_INDEX1][i] = lumaQ2[i] & 0x00ff;
- param->qMatTab[AC_TABLE_INDEX0][i] = chromaBQ2[i] & 0x00ff;
- param->qMatTab[AC_TABLE_INDEX1][i] = chromaBQ2[i] & 0x00ff;
- }
- }
- if (param->extendedSequence == TRUE) {
- /* CODAJ12 Constraint: The value of DC quantization should be greater or equal than 8. */
- /* FIXME: It might be wrong naming of DC_TABLE_INDEX and AC_TABLE_INDEX */
- if (param->qMatTab[DC_TABLE_INDEX0][0] < 8) {
- param->qMatTab[DC_TABLE_INDEX0][0] = 8;
- }
- if (param->qMatTab[AC_TABLE_INDEX0][0] < 8) {
- param->qMatTab[AC_TABLE_INDEX0][0] = 8;
- }
- if (param->qMatTab[DC_TABLE_INDEX1][0] < 8) {
- param->qMatTab[DC_TABLE_INDEX1][0] = 8;
- }
- if (param->qMatTab[AC_TABLE_INDEX1][0] < 8) {
- param->qMatTab[AC_TABLE_INDEX1][0] = 8;
- }
- }
- return 1;
- }
- /******************************************************************************
- EncOpenParam Initialization
- ******************************************************************************/
- int getJpgEncOpenParamDefault(JpgEncOpenParam *pEncOP, EncConfigParam *pEncConfig)
- {
- int ret;
- EncMjpgParam mjpgParam;
- memset(&mjpgParam, 0x00, sizeof(EncMjpgParam));
- pEncOP->jpg12bit = pEncConfig->extendedSequential;
- pEncOP->q_prec0 = FALSE;
- pEncOP->q_prec1 = FALSE;
- pEncOP->picWidth = pEncConfig->picWidth;
- pEncOP->picHeight = pEncConfig->picHeight;
- pEncOP->tiledModeEnable = pEncConfig->tiledModeEnable;
- pEncOP->sourceFormat = pEncConfig->sourceSubsample;
- pEncOP->restartInterval = 0;
- pEncOP->chromaInterleave = pEncConfig->chromaInterleave;
- pEncOP->packedFormat = pEncConfig->packedFormat;
- mjpgParam.sourceFormat = pEncConfig->sourceSubsample;
- ret = jpgGetHuffTable(pEncConfig->huffFileName, &mjpgParam, pEncOP->jpg12bit);
- if (ret == 0) return ret;
- ret = jpgGetQMatrix(pEncConfig->qMatFileName, &mjpgParam);
- if (ret == 0) return ret;
- memcpy(pEncOP->huffVal, mjpgParam.huffVal, 4*256);
- memcpy(pEncOP->huffBits, mjpgParam.huffBits, 4*256);
- memcpy(pEncOP->qMatTab, mjpgParam.qMatTab, 4*64*sizeof(short));
- //Currently only 2DC,2AC huffman table for 12-bit case
- //So, copy them to EX1 to EX2 to modeling rest 2 tables
- if (pEncOP->jpg12bit == TRUE){
- memcpy(&pEncOP->huffVal[4][0], &pEncOP->huffVal[0][0], 4*256);
- memcpy(&pEncOP->huffBits[4][0], &pEncOP->huffBits[0][0], 4*256);
- }
- return 1;
- }
- /**
- * To init EncOpenParam by CFG file
- * IN
- * EncConfigParam *pEncConfig
- * OUT
- * EncOpenParam *pEncOP
- * char *srcYuvFileName
- * @return TRUE on success, FALSE on failure.
- */
- BOOL GetJpgEncOpenParam(JpgEncOpenParam *pEncOP, EncConfigParam *pEncConfig)
- {
- ENC_CFG encCfg;
- Int32 ret;
- EncMjpgParam mjpgParam;
- char huffmanTablePath[MAX_FILE_PATH];
- char QMatTabPath[MAX_FILE_PATH];
- char cfgPath[MAX_FILE_PATH];
- char* srcYuvFileName = pEncConfig->yuvFileName;
- memset(&encCfg, 0x00, sizeof(ENC_CFG));
- memset(&mjpgParam, 0x00, sizeof(EncMjpgParam));
- encCfg.prec = pEncConfig->extendedSequential;
- snprintf(cfgPath, sizeof(cfgPath), "%s/%s", pEncConfig->strCfgDir, pEncConfig->cfgFileName);
- if (parseJpgCfgFile(&encCfg, cfgPath) == 0) {
- return FALSE;
- }
- if (strlen(srcYuvFileName) == 0) {
- strcpy(srcYuvFileName, encCfg.SrcFileName);
- }
- if (encCfg.FrmFormat == 0) {
- pEncConfig->chromaInterleave= CBCR_SEPARATED;
- }
- else if (encCfg.FrmFormat == 1) {
- pEncConfig->chromaInterleave = CBCR_INTERLEAVE;
- }
- else if (encCfg.FrmFormat == 2) {
- pEncConfig->chromaInterleave = CRCB_INTERLEAVE;
- }
- else {
- pEncConfig->chromaInterleave = CBCR_SEPARATED;
- }
- pEncConfig->mjpgFramerate = encCfg.FrameRate;
- /* Source format */
- pEncConfig->packedFormat = (PackedFormat)(encCfg.FrmFormat - 2);
- if (pEncConfig->packedFormat >= PACKED_FORMAT_MAX)
- pEncConfig->packedFormat = PACKED_FORMAT_NONE;
- pEncConfig->outNum = encCfg.NumFrame;
- if (pEncConfig->picWidth == 0) pEncConfig->picWidth = encCfg.PicX;
- if (pEncConfig->picHeight == 0) pEncConfig->picHeight = encCfg.PicY;
- if (pEncOP) {
- pEncOP->q_prec0 = encCfg.QMatPrec0;
- pEncOP->q_prec1 = encCfg.QMatPrec1;
- pEncOP->picWidth = encCfg.PicX;
- pEncOP->picHeight = encCfg.PicY;
- pEncOP->chromaInterleave = pEncConfig->chromaInterleave;
- pEncOP->packedFormat = pEncConfig->packedFormat;
- pEncOP->restartInterval = encCfg.RstIntval;
- pEncOP->tiledModeEnable = pEncConfig->tiledModeEnable;
- pEncOP->sourceFormat = encCfg.SrcFormat;
- mjpgParam.sourceFormat = encCfg.SrcFormat;
- pEncOP->jpg12bit = pEncConfig->extendedSequential;
- if (pEncOP->jpg12bit) {
- mjpgParam.lumaQ12bit = (BOOL)encCfg.QMatPrec0;
- mjpgParam.chromaQ12bit = (BOOL)encCfg.QMatPrec1;
- mjpgParam.extendedSequence = TRUE;
- }
- snprintf(huffmanTablePath, sizeof(huffmanTablePath), "%s/%s", pEncConfig->strCfgDir, encCfg.HuffTabName);
- ret = jpgGetHuffTable(huffmanTablePath, &mjpgParam, pEncOP->jpg12bit);
- if (ret == 0) {
- return ret;
- }
- snprintf(QMatTabPath, sizeof(QMatTabPath), "%s/%s", pEncConfig->strCfgDir, encCfg.QMatTabName);
- if ((ret=jpgGetQMatrix(QMatTabPath, &mjpgParam)) == FALSE) {
- return ret;
- }
- memcpy(pEncOP->huffVal, mjpgParam.huffVal, 4*256);
- memcpy(pEncOP->huffBits, mjpgParam.huffBits, 4*256);
- memcpy(pEncOP->qMatTab, mjpgParam.qMatTab, 4*64*sizeof(short));
- //Currently only 2DC,2AC huffman table for 12-bit case
- //So, copy them to EX1 to EX2 to modeling rest 2 tables
- if (pEncOP->jpg12bit){
- memcpy(&pEncOP->huffVal[4][0], &pEncOP->huffVal[0][0], 4*256);
- memcpy(&pEncOP->huffBits[4][0], &pEncOP->huffBits[0][0], 4*256);
- }
- }
- return TRUE;
- }
- //------------------------------------------------------------------------------
- // ENCODE PARAMETER PARSE FUNCSIONS
- //------------------------------------------------------------------------------
- // Parameter parsing helper
- static int GetValue(FILE *fp, char *para, char *value)
- {
- char lineStr[256];
- char paraStr[256];
- fseek(fp, 0, SEEK_SET);
- while (1) {
- if (fgets(lineStr, 256, fp) == NULL)
- return 0;
- sscanf(lineStr, "%s %s", paraStr, value);
- if (paraStr[0] != ';') {
- if (strcmp(para, paraStr) == 0)
- return 1;
- }
- }
- }
- int parseJpgCfgFile(ENC_CFG *pEncCfg, char *FileName)
- {
- FILE *Fp;
- char sLine[256] = {0,};
- int res = 0;
- Fp = fopen(FileName, "rt");
- if (Fp == NULL) {
- fprintf(stderr, " > ERROR: File not exist <%s>, %d\n", FileName, errno);
- goto end;
- }
- // source file name
- if (GetValue(Fp, "YUV_SRC_IMG", sLine) == 0)
- goto end;
- sscanf(sLine, "%s", (char *)pEncCfg->SrcFileName);
- // frame format
- // ; 0-planar, 1-NV12,NV16(CbCr interleave) 2-NV21,NV61(CbCr alternative)
- // ; 3-YUYV, 4-UYVY, 5-YVYU, 6-VYUY, 7-YUV packed (444 only)
- if (GetValue(Fp, "FRAME_FORMAT", sLine) == 0)
- goto end;
- sscanf(sLine, "%d", &pEncCfg->FrmFormat);
- // width
- if (GetValue(Fp, "PICTURE_WIDTH", sLine) == 0)
- goto end;
- sscanf(sLine, "%d", &pEncCfg->PicX);
- // height
- if (GetValue(Fp, "PICTURE_HEIGHT", sLine) == 0)
- goto end;
- sscanf(sLine, "%d", &pEncCfg->PicY);
- // frame_rate
- if (GetValue(Fp, "FRAME_RATE", sLine) == 0)
- goto end;
- {
- double frameRate;
- int timeRes, timeInc;
- frameRate = (double)(int)atoi(sLine);
- timeInc = 1;
- while ((int)frameRate != frameRate) {
- timeInc *= 10;
- frameRate *= 10;
- }
- timeRes = (int) frameRate;
- // divide 2 or 5
- if (timeInc%2 == 0 && timeRes%2 == 0) {
- timeInc /= 2;
- timeRes /= 2;
- }
- if (timeInc%5 == 0 && timeRes%5 == 0) {
- timeInc /= 5;
- timeRes /= 5;
- }
- if (timeRes == 2997 && timeInc == 100) {
- timeRes = 30000;
- timeInc = 1001;
- }
- pEncCfg->FrameRate = (timeInc - 1) << 16;
- pEncCfg->FrameRate |= timeRes;
- }
- // frame count
- if (GetValue(Fp, "FRAME_NUMBER_ENCODED", sLine) == 0)
- goto end;
- sscanf(sLine, "%d", &pEncCfg->NumFrame);
- if (GetValue(Fp, "VERSION_ID", sLine) == 0)
- goto end;
- sscanf(sLine, "%d", &pEncCfg->VersionID);
- if (GetValue(Fp, "RESTART_INTERVAL", sLine) == 0)
- goto end;
- sscanf(sLine, "%d", &pEncCfg->RstIntval);
- if (GetValue(Fp, "IMG_FORMAT", sLine) == 0)
- goto end;
- sscanf(sLine, "%d", (Int32*)&pEncCfg->SrcFormat);
- if (GetValue(Fp, "QMATRIX_TABLE", sLine) == 0)
- goto end;
- sscanf(sLine, "%s", (char *)pEncCfg->QMatTabName);
- if (GetValue(Fp, "QMATRIX_PREC0", sLine) == 0)
- pEncCfg->QMatPrec0 = 0;
- else
- sscanf(sLine, "%d", &pEncCfg->QMatPrec0);
- if (GetValue(Fp, "QMATRIX_PREC1", sLine) == 0)
- pEncCfg->QMatPrec1 = 0;
- else
- sscanf(sLine, "%d", &pEncCfg->QMatPrec1);
- if (GetValue(Fp, "HUFFMAN_TABLE", sLine) == 0)
- goto end;
- sscanf(sLine, "%s", (char *)pEncCfg->HuffTabName);
- res = 1;
- end:
- if(Fp)
- fclose(Fp);
- return res;
- }
- int StoreYuvImageBurstFormat_V20(int chromaStride, Uint8 * dst, int picWidth, int picHeight, Uint32 bitDepth,
- Uint64 addrY, Uint64 addrCb, Uint64 addrCr, Uint32 stride, FrameFormat format, int endian, CbCrInterLeave interLeave, PackedFormat packed)
- {
- int size;
- int y, nY = 0, nCb, nCr;
- Uint64 addr;
- int lumaSize, chromaSize = 0, chromaWidth = 0, chromaHeight =0;
- Uint8 * puc;
- int chromaStride_i = 0;
- Uint32 bytesPerPixel = (bitDepth + 7) / 8;
- chromaStride_i = chromaStride;
- switch (format)
- {
- case FORMAT_420:
- nY = picHeight;
- nCb = nCr = picHeight / 2;
- chromaSize = (picWidth/2) * (picHeight/2);
- chromaWidth = picWidth/2;
- chromaHeight = nY;
- break;
- case FORMAT_440:
- nY = picHeight;
- nCb = nCr = picHeight / 2;
- chromaSize = (picWidth) * (picHeight / 2);
- chromaWidth = picWidth;
- chromaHeight = nY;
- break;
- case FORMAT_422:
- nY = picHeight;
- nCb = nCr = picHeight;
- chromaSize = (picWidth/2) * picHeight ;
- chromaWidth = (picWidth/2);
- chromaHeight = nY*2;
- break;
- case FORMAT_444:
- nY = picHeight;
- nCb = nCr = picHeight;
- chromaSize = picWidth * picHeight;
- chromaWidth = picWidth;
- chromaHeight = nY*2;
- break;
- case FORMAT_400:
- nY = picHeight;
- nCb = nCr = 0;
- chromaSize = 0;
- chromaWidth = 0;
- chromaHeight = 0;
- break;
- default:
- return 0;
- }
- puc = dst;
- addr = addrY;
- if (packed)
- {
- if (packed == PACKED_FORMAT_444)
- picWidth *= 3;
- else
- picWidth *= 2;
- chromaSize = 0;
- }
- lumaSize = picWidth * nY;
- size = lumaSize + chromaSize*2;
- lumaSize *= bytesPerPixel;
- chromaSize *= bytesPerPixel;
- size *= bytesPerPixel;
- picWidth *= bytesPerPixel;
- chromaWidth *= bytesPerPixel;
- if (interLeave){
- chromaSize = chromaSize *2;
- chromaWidth = chromaWidth *2;
- chromaStride_i = chromaStride_i;
- }
- if ((picWidth == stride) && (chromaWidth == chromaStride_i))
- {
- JpuReadMem(addr, (Uint8 *)( puc ), lumaSize, endian);
- if(packed)
- return size;
- if (interLeave)
- {
- puc = dst + lumaSize;
- addr = addrCb;
- JpuReadMem(addr, (Uint8 *)(puc), chromaSize, endian);
- }
- else
- {
- puc = dst + lumaSize;
- addr = addrCb;
- JpuReadMem(addr, (Uint8 *)(puc), chromaSize, endian);
- puc = dst + lumaSize + chromaSize;
- addr = addrCr;
- JpuReadMem(addr, (Uint8 *)(puc), chromaSize, endian);
- }
- }
- else
- {
- for (y = 0; y < nY; ++y) {
- JpuReadMem(addr + stride * y, (Uint8 *)(puc + y * picWidth), picWidth, endian);
- }
- if(packed)
- return size;
- if (interLeave)
- {
- puc = dst + lumaSize;
- addr = addrCb;
- for (y = 0; y < (chromaHeight/2); ++y) {
- JpuReadMem(addr + (chromaStride_i)*y, (Uint8 *)(puc + y*(chromaWidth)), (chromaWidth), endian);
- }
- }
- else
- {
- puc = dst + lumaSize;
- addr = addrCb;
- for (y = 0; y < nCb; ++y) {
- JpuReadMem(addr + chromaStride_i * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
- }
- puc = dst + lumaSize + chromaSize;
- addr = addrCr;
- for (y = 0; y < nCr; ++y) {
- JpuReadMem(addr + chromaStride_i * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
- }
- }
- }
- return size;
- }//lint !e429
- void GetMcuUnitSize(int format, int *mcuWidth, int *mcuHeight)
- {
- switch(format)
- {
- case FORMAT_420:
- *mcuWidth = 16;
- *mcuHeight = 16;
- break;
- case FORMAT_422:
- *mcuWidth = 16;
- *mcuHeight = 8;
- break;
- case FORMAT_440:
- *mcuWidth = 8;
- *mcuHeight = 16;
- break;
- default://FORMAT_444,400
- *mcuWidth = 8;
- *mcuHeight = 8;
- break;
- }
- }
- int GetFrameBufSize(int framebufFormat, int picWidth, int picHeight)
- {
- int framebufSize = 0;
- int framebufWidth, framebufHeight;
- framebufWidth = picWidth;
- framebufHeight = picHeight;
- switch (framebufFormat)
- {
- case FORMAT_420:
- framebufSize = framebufWidth * ((framebufHeight+1)/2*2) + ((framebufWidth+1)/2)*((framebufHeight+1)/2)*2;
- break;
- case FORMAT_440:
- framebufSize = framebufWidth * ((framebufHeight+1)/2*2) + framebufWidth*((framebufHeight+1)/2)*2;
- break;
- case FORMAT_422:
- framebufSize = framebufWidth * framebufHeight + ((framebufWidth+1)/2)*framebufHeight*2;
- break;
- case FORMAT_444:
- framebufSize = framebufWidth * framebufHeight * 3;
- break;
- case FORMAT_400:
- framebufSize = framebufWidth * framebufHeight;
- break;
- }
- framebufSize = ((framebufSize+7)&~7);
- return framebufSize;
- }
- STATIC void GetFrameBufStride(FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed, BOOL scalerOn,
- Uint32 width, Uint32 height, Uint32 bytePerPixel,
- Uint32* oLumaStride, Uint32* oLumaHeight, Uint32* oChromaStride, Uint32* oChromaHeight)
- {
- Uint32 lStride, cStride;
- Uint32 lHeight, cHeight;
- lStride = JPU_CEIL(8, width);
- lHeight = height;
- cHeight = height/2;
- if (packed == PACKED_FORMAT_NONE) {
- Uint32 chromaDouble = (cbcrIntlv == CBCR_SEPARATED) ? 1 : 2;
- switch (subsample) {
- case FORMAT_400: cStride = 0; cHeight = 0; break;
- case FORMAT_420: cStride = (lStride/2)*chromaDouble; cHeight = height/2; break;
- case FORMAT_422: cStride = (lStride/2)*chromaDouble; cHeight = height; break;
- case FORMAT_440: cStride = lStride*chromaDouble; cHeight = height/2; break;
- case FORMAT_444: cStride = lStride*chromaDouble; cHeight = height; break;
- default: cStride = 0; lStride = 0; cHeight = 0; break;
- }
- }
- else {
- switch (packed) {
- case PACKED_FORMAT_422_YUYV:
- case PACKED_FORMAT_422_UYVY:
- case PACKED_FORMAT_422_YVYU:
- case PACKED_FORMAT_422_VYUY: lStride = lStride*2; cStride = 0; cHeight = 0; break;
- case PACKED_FORMAT_444: lStride = lStride*3; cStride = 0; cHeight = 0; break;
- default: lStride = 0; cStride = 0; break;
- }
- }
- if (scalerOn == TRUE) {
- /* Luma stride */
- if (subsample == FORMAT_420 || subsample == FORMAT_422 || (PACKED_FORMAT_422_YUYV <= packed && packed <= PACKED_FORMAT_422_VYUY)) {
- lStride = JPU_CEIL(32, lStride);
- }
- else {
- lStride = JPU_CEIL(16, lStride);
- }
- /* Chroma stride */
- if (cbcrIntlv == CBCR_SEPARATED) {
- if (subsample == FORMAT_444) {
- cStride = JPU_CEIL(16, cStride);
- }
- else {
- cStride = JPU_CEIL(8, cStride);
- }
- }
- else {
- cStride = JPU_CEIL(32, cStride);
- }
- }
- else {
- lStride = JPU_CEIL(8, lStride);
- if (subsample == FORMAT_420 || subsample == FORMAT_422) {
- cStride = JPU_CEIL(16, cStride);
- }
- else {
- cStride = JPU_CEIL(8, cStride);
- }
- }
- lHeight = JPU_CEIL(4, lHeight);
- cHeight = JPU_CEIL(4, cHeight);
- lStride *= bytePerPixel;
- cStride *= bytePerPixel;
- if (oLumaStride) *oLumaStride = lStride;
- if (oLumaHeight) *oLumaHeight = lHeight;
- if (oChromaStride) *oChromaStride = cStride;
- if (oChromaHeight) *oChromaHeight = cHeight;
- }
- BOOL AllocateFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed,
- Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth, Uint32 num)
- {
- fb_context *fb;
- Uint32 fbLumaStride, fbLumaHeight, fbChromaStride, fbChromaHeight;
- Uint32 fbLumaSize, fbChromaSize, fbSize;
- Uint32 i;
- Uint32 bytePerPixel = (bitDepth + 7)/8;
- if (rotation == 90 || rotation == 270) {
- if (subsample == FORMAT_422) subsample = FORMAT_440;
- else if (subsample == FORMAT_440) subsample = FORMAT_422;
- }
- GetFrameBufStride(subsample, cbcrIntlv, packed, scalerOn, width, height, bytePerPixel, &fbLumaStride, &fbLumaHeight, &fbChromaStride, &fbChromaHeight);
- fbLumaSize = fbLumaStride * fbLumaHeight;
- fbChromaSize = fbChromaStride * fbChromaHeight;
- if (cbcrIntlv == CBCR_SEPARATED) {
- /* fbChromaSize MUST be zero when format is packed mode */
- fbSize = fbLumaSize + 2*fbChromaSize;
- }
- else {
- /* Semi-planar */
- fbSize = fbLumaSize + fbChromaSize;
- }
- fb = &s_fb[instIdx];
- if (fb->vb_base.size == 0) {
- fb->vb_base.size = fbSize;
- fb->vb_base.size *= num;
- if (jdi_allocate_dma_memory(&fb->vb_base) < 0) {
- JLOG(ERR, "Fail to allocate frame buffer size=%d\n", fb->vb_base.size);
- return FALSE;
- }
- fb->last_addr = fb->vb_base.phys_addr;
- }
- for (i=fb->last_num; i<fb->last_num+num; i++) {
- fb->frameBuf[i].Format = subsample;
- fb->frameBuf[i].Index = i;
- fb->frameBuf[i].vbY.phys_addr = fb->last_addr;
- fb->frameBuf[i].vbY.size = fbLumaSize;
- fb->last_addr += fb->frameBuf[i].vbY.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- if (fbChromaSize) {
- fb->frameBuf[i].vbCb.phys_addr = fb->last_addr;
- fb->frameBuf[i].vbCb.size = fbChromaSize;
- fb->last_addr += fb->frameBuf[i].vbCb.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- fb->frameBuf[i].vbCr.phys_addr = (cbcrIntlv == CBCR_SEPARATED) ? fb->last_addr : 0;
- fb->frameBuf[i].vbCr.size = (cbcrIntlv == CBCR_SEPARATED) ? fbChromaSize : 0;
- fb->last_addr += fb->frameBuf[i].vbCr.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- }
- fb->frameBuf[i].strideY = fbLumaStride;
- fb->frameBuf[i].strideC = fbChromaStride;
- }
- fb->last_num += num;
- return TRUE;
- }
- BOOL UpdateFrameBuffers(Uint32 instIdx, Uint32 num, FRAME_BUF *frameBuf)
- {
- fb_context *fb = &s_fb[instIdx];
- Uint32 index = num - 1;
- fb->last_num = num;
- fb->last_addr = frameBuf[index].vbY.phys_addr;
- fb->last_addr += fb->frameBuf[index].vbCb.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- fb->last_addr += fb->frameBuf[index].vbCr.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- JLOG(INFO, "%s: Update %d buffers\r\n",__FUNCTION__, num);
- memcpy(fb->frameBuf, frameBuf, sizeof(FRAME_BUF) * num);
- return TRUE;
- }
- BOOL AttachOneFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed,
- Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth,
- void *virtAddress, Uint32 size, Uint32 *bufferIndex)
- {
- fb_context *fb;
- Uint32 fbLumaStride, fbLumaHeight, fbChromaStride, fbChromaHeight;
- Uint32 fbLumaSize, fbChromaSize;
- Uint32 fbSize;
- Uint32 bytePerPixel = (bitDepth + 7)/8;
- Uint32 i;
- JLOG(INFO, "%s function in width, height = [%d, %d]\r\n", __FUNCTION__, width, height);
- if (rotation == 90 || rotation == 270) {
- if (subsample == FORMAT_422) subsample = FORMAT_440;
- else if (subsample == FORMAT_440) subsample = FORMAT_422;
- }
- GetFrameBufStride(subsample, cbcrIntlv, packed, scalerOn, width, height, bytePerPixel, &fbLumaStride, &fbLumaHeight, &fbChromaStride, &fbChromaHeight);
- fbLumaSize = fbLumaStride * fbLumaHeight;
- fbChromaSize = fbChromaStride * fbChromaHeight;
- if (cbcrIntlv == CBCR_SEPARATED) {
- /* fbChromaSize MUST be zero when format is packed mode */
- fbSize = fbLumaSize + 2*fbChromaSize;
- }
- else {
- /* Semi-planar */
- fbSize = fbLumaSize + fbChromaSize;
- }
- fb = &s_fb[instIdx];
- fb->vb_base.virt_addr = (unsigned long)virtAddress;
- fb->vb_base.size = fbSize;
- if (jdi_attach_dma_memory(&fb->vb_base) < 0) {
- JLOG(ERR, "Fail to attach frame buffer\n");
- return FALSE;
- }
- fb->last_addr = fb->vb_base.phys_addr;
- i = fb->last_num;
- JLOG(INFO, "%s: store on index %d\r\n", __FUNCTION__, i);
- fb->frameBuf[i].Format = subsample;
- fb->frameBuf[i].Index = i;
- fb->frameBuf[i].vbY.phys_addr = fb->vb_base.phys_addr;
- fb->frameBuf[i].vbY.size = fbLumaSize;
- // Store virt addr
- fb->frameBuf[i].vbY.virt_addr = fb->vb_base.virt_addr;
- fb->last_addr += fb->frameBuf[i].vbY.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- JLOG(INFO, "%s: fbChromaSize = %d, fbLumaSize = %d\r\n", __FUNCTION__, fbChromaSize, fbLumaSize);
- if (fbChromaSize) {
- fb->frameBuf[i].vbCb.phys_addr = fb->last_addr;
- fb->frameBuf[i].vbCb.size = fbChromaSize;
- fb->last_addr += fb->frameBuf[i].vbCb.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- fb->frameBuf[i].vbCr.phys_addr = (cbcrIntlv == CBCR_SEPARATED) ? fb->last_addr : 0;
- fb->frameBuf[i].vbCr.size = (cbcrIntlv == CBCR_SEPARATED) ? fbChromaSize : 0;
- fb->last_addr += fb->frameBuf[i].vbCr.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- }
- JLOG(INFO, "%s vbCb = %x size = %d, vbCr = %x size = %d\r\n", __FUNCTION__, fb->frameBuf[i].vbCb.phys_addr,
- fb->frameBuf[i].vbCb.size, fb->frameBuf[i].vbCr.phys_addr, fb->frameBuf[i].vbCr.size);
- fb->frameBuf[i].strideY = fbLumaStride;
- fb->frameBuf[i].strideC = fbChromaStride;
- *bufferIndex = fb->last_num;
- fb->last_num += 1;
- JLOG(INFO, "%s function OUT, number = %d\r\n", __FUNCTION__, fb->last_num);
- return TRUE;
- }
- void *AllocateOneFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed,
- Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth, Uint32 bufferIndex)
- {
- fb_context *fb;
- Uint32 fbLumaStride, fbLumaHeight, fbChromaStride, fbChromaHeight;
- Uint32 fbLumaSize, fbChromaSize, fbSize;
- Uint32 i;
- Uint32 bytePerPixel = (bitDepth + 7)/8;
- void * virt_addr = NULL;
- JLOG(INFO, "%s function in width, height = [%d, %d]\r\n", __FUNCTION__, width, height);
- if (rotation == 90 || rotation == 270) {
- if (subsample == FORMAT_422) subsample = FORMAT_440;
- else if (subsample == FORMAT_440) subsample = FORMAT_422;
- }
- GetFrameBufStride(subsample, cbcrIntlv, packed, scalerOn, width, height, bytePerPixel, &fbLumaStride, &fbLumaHeight, &fbChromaStride, &fbChromaHeight);
- fbLumaSize = fbLumaStride * fbLumaHeight;
- fbChromaSize = fbChromaStride * fbChromaHeight;
- if (cbcrIntlv == CBCR_SEPARATED) {
- /* fbChromaSize MUST be zero when format is packed mode */
- fbSize = fbLumaSize + 2*fbChromaSize;
- }
- else {
- /* Semi-planar */
- fbSize = fbLumaSize + fbChromaSize;
- }
- if (fbSize == 0)
- {
- switch (subsample)
- {
- case FORMAT_420:
- fbSize = width * height * 3 / 2;
- break;
- case FORMAT_422:
- case FORMAT_440:
- fbSize = width * height * 2;
- case FORMAT_444:
- fbSize = width * height * 3;
- /* code */
- break;
- default:
- break;
- }
- JLOG(WARN, "%s: fbSize == 0! Use defalut size %d\r\n", __FUNCTION__, fbSize);
- }
- fb = &s_fb[instIdx];
- fb->vb_base.size = fbSize;
- if (jdi_allocate_dma_memory(&fb->vb_base) < 0) {
- JLOG(ERR, "Fail to allocate frame buffer size=%d\n", fb->vb_base.size);
- return NULL;
- }
- fb->vb[bufferIndex] = fb->vb_base;
- fb->last_addr = fb->vb_base.phys_addr;
- i = bufferIndex;
- JLOG(INFO, "%s: store on index %d\r\n", __FUNCTION__, i);
- fb->frameBuf[i].Format = subsample;
- fb->frameBuf[i].Index = i;
- fb->frameBuf[i].vbY.phys_addr = fb->vb_base.phys_addr;
- fb->frameBuf[i].vbY.size = fbLumaSize;
- // Store virt addr
- fb->frameBuf[i].vbY.virt_addr = fb->vb_base.virt_addr;
- fb->last_addr += fb->frameBuf[i].vbY.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- JLOG(INFO, "%s: fbChromaSize = %d, fbLumaSize = %d\r\n", __FUNCTION__, fbChromaSize, fbLumaSize);
- if (fbChromaSize) {
- fb->frameBuf[i].vbCb.phys_addr = fb->last_addr;
- fb->frameBuf[i].vbCb.size = fbChromaSize;
- fb->last_addr += fb->frameBuf[i].vbCb.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- fb->frameBuf[i].vbCr.phys_addr = (cbcrIntlv == CBCR_SEPARATED) ? fb->last_addr : 0;
- fb->frameBuf[i].vbCr.size = (cbcrIntlv == CBCR_SEPARATED) ? fbChromaSize : 0;
- fb->last_addr += fb->frameBuf[i].vbCr.size;
- fb->last_addr = JPU_CEIL(8, fb->last_addr);
- }
- fb->frameBuf[i].strideY = fbLumaStride;
- fb->frameBuf[i].strideC = fbChromaStride;
- virt_addr = (void *)fb->vb_base.virt_addr;
- fb->last_num = bufferIndex + 1;
- JLOG(INFO, "%s function OUT, number = %d, return = %p\r\n", __FUNCTION__, fb->last_num, virt_addr);
- return virt_addr;
- }
- int GetDPBBufSize(int framebufFormat, int picWidth, int picHeight, int picWidth_C, int interleave)
- {
- int framebufSize = 0;
- int framebufWidth, framebufHeight, framebufWidth_C;
- framebufWidth = picWidth;
- framebufHeight = picHeight;
- framebufWidth_C = picWidth_C;
- switch (framebufFormat)
- {
- case FORMAT_420:
- if (interleave == 0)
- framebufSize = framebufWidth * ((framebufHeight+1)/2*2) + framebufWidth_C *((framebufHeight+1)/2)*2;
- else
- framebufSize = framebufWidth * ((framebufHeight+1)/2*2) + framebufWidth_C *((framebufHeight+1)/2);
- break;
- case FORMAT_440:
- if (interleave == 0)
- framebufSize = framebufWidth * ((framebufHeight+1)/2*2) + framebufWidth_C*((framebufHeight+1)/2)*2 *2;
- else
- framebufSize = framebufWidth * ((framebufHeight+1)/2*2) + framebufWidth_C*((framebufHeight+1)/2)*2;
- break;
- case FORMAT_422:
- if (interleave == 0)
- framebufSize = framebufWidth * framebufHeight + framebufWidth_C*framebufHeight*2;
- else
- framebufSize = framebufWidth * framebufHeight + framebufWidth_C*framebufHeight;
- break;
- case FORMAT_444:
- framebufSize = framebufWidth * framebufHeight * 3;
- break;
- case FORMAT_400:
- framebufSize = framebufWidth * framebufHeight;
- if (interleave != 0)
- printf("Warning: 400 does not have interleave mode ! \n" );
- break;
- }
- framebufSize = ((framebufSize+7)&~7);
- return framebufSize;
- }
- BOOL ParseDecTestLongArgs(void* config, const char* argName, char* value)
- {
- BOOL ret = TRUE;
- DecConfigParam* dec = (DecConfigParam*)config;
- if (strcmp(argName, "output") == 0) {
- strcpy(dec->yuvFileName, value);
- }
- else if (strcmp(argName, "input") == 0) {
- strcpy(dec->bitstreamFileName, value);
- }
- else if (strcmp(argName, "stream-endian") == 0) {
- dec->StreamEndian = atoi(value);
- }
- else if (strcmp(argName, "frame-endian") == 0) {
- dec->FrameEndian = atoi(value);
- }
- else if (strcmp(argName, "pixelj") == 0) {
- dec->pixelJustification = atoi(value);
- if (dec->pixelJustification >= PIXEL_16BIT_JUSTIFICATION_MAX) {
- JLOG(ERR, "Invalid pixel justification\n");
- ret = FALSE;
- }
- }
- else if (strcmp(argName, "bs-size") == 0) {
- dec->bsSize = atoi(value);
- JLOG(INFO, "bitstream buffer size is:%d\n",dec->bsSize);
- if (dec->bsSize == 0) {
- JLOG(ERR, "bitstream buffer size is 0\n");
- ret = FALSE;
- }
- }
- else if (strcmp(argName, "roi") == 0) {
- char* val;
- val = strtok(value, ",");
- if (val == NULL) {
- JLOG(ERR, "Invalid ROI option: %s\n", value);
- ret = FALSE;
- }
- else {
- dec->roiOffsetX = atoi(val);
- }
- val = strtok(NULL, ",");
- if (val == NULL) {
- JLOG(ERR, "Invalid ROI option: %s\n", value);
- ret = FALSE;
- }
- else {
- dec->roiOffsetY = atoi(val);
- }
- val = strtok(NULL, ",");
- if (val == NULL) {
- JLOG(ERR, "Invalid ROI option: %s\n", value);
- ret = FALSE;
- }
- else {
- dec->roiWidth = atoi(val);
- }
- val = strtok(NULL, ",");
- if (val == NULL) {
- JLOG(ERR, "Invalid ROI option: %s\n", value);
- ret = FALSE;
- }
- else {
- dec->roiHeight = atoi(val);
- }
- dec->roiEnable = TRUE;
- }
- else if (strcmp(argName, "subsample") == 0) {
- if (strcasecmp(value, "none") == 0) {
- dec->subsample = FORMAT_MAX;
- }
- else if (strcasecmp(value, "420") == 0) {
- dec->subsample = FORMAT_420;
- }
- else if (strcasecmp(value, "422") == 0) {
- dec->subsample = FORMAT_422;
- }
- else if (strcasecmp(value, "444") == 0) {
- dec->subsample = FORMAT_444;
- }
- else {
- JLOG(ERR, "Not supported sub-sample: %s\n", value);
- ret = FALSE;
- }
- }
- else if (strcmp(argName, "ordering") == 0) {
- if (strcasecmp(value, "none") == 0) {
- dec->cbcrInterleave = CBCR_SEPARATED;
- dec->packedFormat = PACKED_FORMAT_NONE;
- }
- else if (strcasecmp(value, "nv12") == 0) {
- dec->cbcrInterleave = CBCR_INTERLEAVE;
- dec->packedFormat = PACKED_FORMAT_NONE;
- }
- else if (strcasecmp(value, "nv21") == 0) {
- dec->cbcrInterleave = CRCB_INTERLEAVE;
- dec->packedFormat = PACKED_FORMAT_NONE;
- }
- else if (strcasecmp(value, "yuyv") == 0) {
- dec->cbcrInterleave = CBCR_SEPARATED;
- dec->packedFormat = PACKED_FORMAT_422_YUYV;
- }
- else if (strcasecmp(value, "uyvy") == 0) {
- dec->cbcrInterleave = CBCR_SEPARATED;
- dec->packedFormat = PACKED_FORMAT_422_UYVY;
- }
- else if (strcasecmp(value, "yvyu") == 0) {
- dec->cbcrInterleave = CBCR_SEPARATED;
- dec->packedFormat = PACKED_FORMAT_422_YVYU;
- }
- else if (strcasecmp(value, "vyuy") == 0) {
- dec->cbcrInterleave = CBCR_SEPARATED;
- dec->packedFormat = PACKED_FORMAT_422_VYUY;
- }
- else if (strcasecmp(value, "ayuv") == 0) {
- dec->cbcrInterleave = CBCR_SEPARATED;
- dec->packedFormat = PACKED_FORMAT_444;
- }
- else {
- JLOG(ERR, "Not supported ordering: %s\n", value);
- ret = FALSE;
- }
- }
- else if (strcmp(argName, "rotation") == 0) {
- dec->rotation = atoi(value);
- }
- else if (strcmp(argName, "mirror") == 0) {
- dec->mirror = (JpgMirrorDirection)atoi(value);
- }
- else if (strcmp(argName, "scaleH") == 0) {
- dec->iHorScaleMode = atoi(value);
- }
- else if (strcmp(argName, "scaleV") == 0) {
- dec->iVerScaleMode = atoi(value);
- }
- else {
- JLOG(ERR, "Not defined option: %s\n", argName);
- ret = FALSE;
- }
- return ret;
- }
- BOOL ParseEncTestLongArgs(void* config, const char* argName, char* value)
- {
- BOOL ret = TRUE;
- EncConfigParam* enc = (EncConfigParam*)config;
- if (strcmp(argName, "output") == 0) {
- strcpy(enc->bitstreamFileName, value);
- }
- else if (strcmp(argName, "input") == 0) {
- strcpy(enc->cfgFileName, value);
- }
- else if (strcmp(argName, "12bit") == 0) {
- enc->extendedSequential = TRUE;
- }
- else if (strcmp(argName, "cfg-dir") == 0) {
- strcpy(enc->strCfgDir, value);
- }
- else if (strcmp(argName, "yuv-dir") == 0) {
- strcpy(enc->strYuvDir, value);
- }
- else if (strcmp(argName, "stream-endian") == 0) {
- enc->StreamEndian = atoi(value);
- }
- else if (strcmp(argName, "frame-endian") == 0) {
- enc->FrameEndian = atoi(value);
- }
- else if (strcmp(argName, "pixelj") == 0) {
- enc->pixelJustification = atoi(value);
- if (enc->pixelJustification >= PIXEL_16BIT_JUSTIFICATION_MAX) {
- JLOG(ERR, "Invalid pixel justification\n");
- ret = FALSE;
- }
- }
- else if (strcmp(argName, "bs-size") == 0) {
- enc->bsSize = atoi(value);
- if (enc->bsSize == 0) {
- JLOG(ERR, "bitstream buffer size is 0\n");
- ret = FALSE;
- }
- }
- else if (strcmp(argName, "quality") == 0) {
- enc->encQualityPercentage = atoi(value);
- if (enc->encQualityPercentage > 100) {
- JLOG(ERR, "Invalid quality factor: %d\n", enc->encQualityPercentage);
- ret = FALSE;
- }
- }
- else if (strcmp(argName, "enable-tiledMode") == 0) {
- enc->tiledModeEnable = (BOOL)atoi(value);
- }
- else if (strcmp(argName, "slice-height") == 0) {
- enc->sliceHeight = atoi(value);
- }
- else if (strcmp(argName, "enable-slice-intr") == 0) {
- enc->sliceInterruptEnable = atoi(value);
- }
- else if (strcmp(argName, "rotation") == 0) {
- enc->rotation = atoi(value);
- }
- else if (strcmp(argName, "mirror") == 0) {
- enc->mirror = (JpgMirrorDirection)atoi(value);
- }
- else {
- JLOG(ERR, "Not defined option: %s\n", argName);
- ret = FALSE;
- }
- return ret;
- }
- static BOOL ParseNoneTestLongArgs(void* config, const char* argName, char* value)
- {
- return FALSE;
- }
- static BOOL ParseMultipleTestArgs(TestMultiConfig* config, const char* argName, char* value)
- {
- char* tempArg;
- Uint32 i;
- BOOL (*parsers[3])(void* config, const char*, char*) = {
- ParseEncTestLongArgs,
- ParseDecTestLongArgs,
- ParseNoneTestLongArgs,
- };
- tempArg = strtok(value, ",");
- for(i = 0; i < MAX_NUM_INSTANCE; i++) {
- if (parsers[config->type[i]]((void*)&config->u[i], argName, tempArg) == FALSE) {
- return FALSE;
- }
- tempArg = strtok(NULL, ",");
- if (tempArg == NULL) {
- break;
- }
- }
- return TRUE;
- }
- BOOL ParseMultiLongOptions(TestMultiConfig* config, const char* argName, char* value)
- {
- BOOL ret = TRUE;
- Uint32 i;
- char* tempArg;
- if (strcmp(argName, "instance-num") == 0) {
- config->numInstances = atoi(value);
- }
- else if (strcmp(argName, "input") == 0) {
- ret = ParseMultipleTestArgs(config, argName, value);
- }
- else if (strcmp(argName, "output") == 0) {
- ret = ParseMultipleTestArgs(config, argName, value);
- }
- else if (strcmp(argName, "stream-endian") == 0) {
- ret = ParseMultipleTestArgs(config, argName, value);
- }
- else if (strcmp(argName, "frame-endian") == 0) {
- ret = ParseMultipleTestArgs(config, argName, value);
- }
- else if (strcmp(argName, "pixelj") == 0) {
- ret = ParseMultipleTestArgs(config, argName, value);
- }
- else if (strcmp(argName, "bs-size") == 0) {
- ret = ParseMultipleTestArgs(config, argName, value);
- }
- else if (strcmp(argName, "cfg-dir") == 0) {
- for (i=0; i<MAX_NUM_INSTANCE; i++) {
- if (config->type[i] == JPU_ENCODER) {
- ParseEncTestLongArgs((void*)&config->u[i], argName, value);
- }
- }
- }
- else if (strcmp(argName, "yuv-dir") == 0) {
- for (i=0; i<MAX_NUM_INSTANCE; i++) {
- if (config->type[i] == JPU_ENCODER) {
- ParseEncTestLongArgs((void*)&config->u[i], argName, value);
- }
- }
- }
- else if (strcmp(argName, "slice-height") == 0) {
- tempArg = strtok(value, ",");
- for(i = 0; i < MAX_NUM_INSTANCE; i++) {
- if (config->type[i] == JPU_ENCODER) {
- ParseEncTestLongArgs((void*)&config->u[i], argName, tempArg);
- }
- else {
- ParseDecTestLongArgs((void*)&config->u[i], argName, tempArg);
- }
- tempArg = strtok(NULL, ",");
- if (tempArg == NULL)
- break;
- }
- }
- else if (strcmp(argName, "enable-slice-intr") == 0) {
- tempArg = strtok(value, ",");
- for(i = 0; i < MAX_NUM_INSTANCE; i++) {
- if (config->type[i] == JPU_ENCODER) {
- ParseEncTestLongArgs((void*)&config->u[i], argName, tempArg);
- }
- else {
- ParseDecTestLongArgs((void*)&config->u[i], argName, tempArg);
- }
- tempArg = strtok(NULL, ",");
- if (tempArg == NULL)
- break;
- }
- }
- else if (strcmp(argName, "enable-tiledMode") == 0) {
- tempArg = strtok(value, ",");
- for(i = 0; i < MAX_NUM_INSTANCE; i++) {
- if (config->type[i] == JPU_ENCODER) {
- ParseEncTestLongArgs((void*)&config->u[i], argName, tempArg);
- }
- tempArg = strtok(NULL, ",");
- if (tempArg == NULL)
- break;
- }
- }
- else {
- JLOG(ERR, "Not defined option: %s\n", argName);
- ret = FALSE;
- }
- return ret;
- }
- int GetFrameBufBase(int instIdx)
- {
- fb_context *fb;
- fb = &s_fb[instIdx];
- return fb->vb_base.phys_addr;
- }
- int GetFrameBufAllocSize(int instIdx)
- {
- fb_context *fb;
- fb = &s_fb[instIdx];
- return (fb->last_addr - fb->vb_base.phys_addr);
- }
- FRAME_BUF *GetFrameBuffer(int instIdx, int idx)
- {
- fb_context *fb;
- fb = &s_fb[instIdx];
- return &fb->frameBuf[idx];
- }
- Uint32 GetFrameBufferCount(int instIdx)
- {
- fb_context *fb;
- fb = &s_fb[instIdx];
- return fb->last_num;
- }
- FRAME_BUF* FindFrameBuffer(int instIdx, PhysicalAddress addrY)
- {
- int i;
- fb_context *fb;
- fb = &s_fb[instIdx];
- for (i=0; i <MAX_FRAME; i++)
- {
- if (fb->frameBuf[i].vbY.phys_addr == addrY)
- {
- return &fb->frameBuf[i];
- }
- }
- return NULL;
- }
- void FreeOneFrameBuffer(int instIdx, unsigned int bufferIndex)
- {
- fb_context *fb;
- fb = &s_fb[instIdx];
- if(fb->vb[bufferIndex].base)
- {
- jdi_free_dma_memory(&fb->vb[bufferIndex]);
- fb->vb[bufferIndex].base = 0;
- }
- }
- void FreeFrameBuffer(int instIdx)
- {
- fb_context *fb;
- fb = &s_fb[instIdx];
- fb->last_num = 0;
- fb->last_addr = -1;
- if(fb->vb_base.base)
- {
- jdi_free_dma_memory(&fb->vb_base);
- fb->vb_base.base = 0;
- }
- }
- char* GetFileExtension(const char* filename)
- {
- Int32 len;
- Int32 i;
- len = strlen(filename);
- for (i=len-1; i>=0; i--) {
- if (filename[i] == '.') {
- return (char*)&filename[i+1];
- }
- }
- return NULL;
- }
|