| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210 |
- /*------------------------------------------------------------------------------
- -- --
- -- This software is confidential and proprietary and may be used --
- -- only as expressly authorized by a licensing agreement from --
- -- --
- -- Hantro Products Oy. --
- -- --
- -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
- -- ALL RIGHTS RESERVED --
- -- --
- -- The entire notice above must be reproduced --
- -- on all copies and should not be removed. --
- -- --
- --------------------------------------------------------------------------------
- --
- -- Description : JPEG decoder API source file
- --
- ------------------------------------------------------------------------------
- --
- -- Version control information, please leave untouched.
- --
- -- $RCSfile: jpegdecapi.c,v $
- -- $Revision: 1.263 $
- -- $Date: 2011/05/31 12:30:09 $
- --
- ------------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------------
- Table of contents
- 1. Include headers
- 2. External compiler flags
- 3. Module defines
- 4. Local function prototypes
- 5. Functions
- - JpegDecInit
- - JpegDecRelease
- - JpegDecGetImageInfo
- - JpegDecDecode
- ------------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------------
- 1. Include headers
- ------------------------------------------------------------------------------*/
- #include <linux/module.h>
- #include <linux/platform_device.h>
- #include "dwl.h"
- #include "basetype.h"
- #include "jpegdecapi.h"
- #include "jpegdeccontainer.h"
- #include "jpegdecmarkers.h"
- #include "jpegdecinternal.h"
- #include "jpegdecutils.h"
- #include "jpegdechdrs.h"
- #include "jpegdecscan.h"
- #include "jpegregdrv.h"
- #include "jpeg_pp_pipeline.h"
- #ifdef JPEGDEC_PP_TRACE
- #include "ppapi.h"
- #endif /* #ifdef JPEGDEC_PP_TRACE */
- static void JpegDecPreparePp(JpegDecContainer * pJpegDecCont);
- /*------------------------------------------------------------------------------
- Version Information - DO NOT CHANGE!
- ------------------------------------------------------------------------------*/
- #define JPG_MAJOR_VERSION 1
- #define JPG_MINOR_VERSION 1
- #define JPG_BUILD_MAJOR 1
- #define JPG_BUILD_MINOR 207
- #define JPG_SW_BUILD ((JPG_BUILD_MAJOR * 1000) + JPG_BUILD_MINOR)
- /*------------------------------------------------------------------------------
- 2. External compiler flags
- ------------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------------
- 3. Module defines
- ------------------------------------------------------------------------------*/
- #ifdef JPEGDEC_TRACE
- #define JPEGDEC_API_TRC(str) JpegDecTrace((str))
- #else
- #define JPEGDEC_API_TRC(str) //printk(str)
- #endif
- #define JPEGDEC_CLEAR_IRQ SetDecRegister(PTR_JPGC->jpegRegs, \
- HWIF_DEC_IRQ_STAT, 0); \
- SetDecRegister(PTR_JPGC->jpegRegs, \
- HWIF_DEC_IRQ, 0);
- /*------------------------------------------------------------------------------
- 4. Local function prototypes
- ------------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------------
- 5. Functions
- ------------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------------
- Function name: JpegDecInit
- Functional description:
- Init jpeg decoder
- Inputs:
- JpegDecInst * decInst a reference to the jpeg decoder instance is
- stored here
- Outputs:
- JPEGDEC_OK
- JPEGDEC_INITFAIL
- JPEGDEC_PARAM_ERROR
- JPEGDEC_DWL_ERROR
- JPEGDEC_MEMFAIL
- ------------------------------------------------------------------------------*/
- JpegDecRet JpegDecInit(JpegDecInst * pDecInst)
- {
- JpegDecContainer *pJpegCont;
- const void *dwl;
- u32 i = 0;
- u32 asicID;
- u32 fuseStatus = 0;
- u32 extensionsSupported;
- DWLInitParam_t dwlInit;
- // printk("JpegDecInit#\n");
- /* check that right shift on negative numbers is performed signed */
- /*lint -save -e* following check causes multiple lint messages */
- if(((-1) >> 1) != (-1))
- {
- printk("JpegDecInit# ERROR: Right shift is not signed\n");
- return (JPEGDEC_INITFAIL);
- }
- /*lint -restore */
- if(pDecInst == NULL)
- {
- printk("JpegDecInit# ERROR: decInst == NULL\n");
- return (JPEGDEC_PARAM_ERROR);
- }
- *pDecInst = NULL; /* return NULL instance for any error */
- /* check for proper hardware */
- asicID = DWLReadAsicID();
- {
- /* check that JPEG decoding supported in HW */
- DWLHwConfig_t hwCfg;
- DWLReadAsicConfig(&hwCfg);
- if(!hwCfg.jpegSupport)
- {
- printk(("JpegDecInit# ERROR: JPEG not supported in HW\n"));
- return JPEGDEC_FORMAT_NOT_SUPPORTED;
- }
- /* check progressive support */
- if((asicID >> 16) != 0x8170U)
- {
- /* progressive decoder */
- if(hwCfg.jpegSupport == JPEG_BASELINE)
- fuseStatus = 1;
- }
- extensionsSupported = hwCfg.jpegESupport;
- }
- dwlInit.clientType = DWL_CLIENT_TYPE_JPEG_DEC;
- /* Initialize Wrapper */
- dwl = DWLInit(&dwlInit);
- if(dwl == NULL)
- {
- printk("JpegDecInit# ERROR: DWL Init failed\n");
- return (JPEGDEC_DWL_ERROR);
- }
- pJpegCont = (JpegDecContainer *) DWLmalloc(sizeof(JpegDecContainer));
- if(pJpegCont == NULL)
- {
- (void) DWLRelease(dwl);
- return (JPEGDEC_MEMFAIL);
- }
- pJpegCont->dwl = dwl;
- /* reset internal structures */
- JpegDecClearStructs(pJpegCont);
- /* Reset shadow registers */
- for(i = 1; i < DEC_X170_REGISTERS; i++)
- {
- pJpegCont->jpegRegs[i] = 0;
- }
- /* these parameters are defined in deccfg.h */
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_OUT_ENDIAN,
- DEC_X170_OUTPUT_PICTURE_ENDIAN);
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_IN_ENDIAN,
- DEC_X170_INPUT_DATA_ENDIAN);
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_STRENDIAN_E,
- DEC_X170_INPUT_STREAM_ENDIAN);
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_MAX_BURST,
- DEC_X170_BUS_BURST_LENGTH);
- if((asicID >> 16) == 0x8170U)
- {
- SetDecRegister(pJpegCont->jpegRegs, HWIF_PRIORITY_MODE,
- DEC_X170_ASIC_SERVICE_PRIORITY);
- }
- else
- {
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_SCMD_DIS,
- DEC_X170_SCMD_DISABLE);
- }
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_LATENCY,
- DEC_X170_LATENCY_COMPENSATION);
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_DATA_DISC_E,
- DEC_X170_DATA_DISCARD_ENABLE);
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_OUTSWAP32_E,
- DEC_X170_OUTPUT_SWAP_32_ENABLE);
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_INSWAP32_E,
- DEC_X170_INPUT_DATA_SWAP_32_ENABLE);
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_STRSWAP32_E,
- DEC_X170_INPUT_STREAM_SWAP_32_ENABLE);
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_OUT_TILED_E, 0);
- #if( DEC_X170_HW_TIMEOUT_INT_ENA != 0)
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_TIMEOUT_E, 1);
- #else
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_TIMEOUT_E, 0);
- #endif
- #if( DEC_X170_INTERNAL_CLOCK_GATING != 0)
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_CLK_GATE_E, 1);
- #else
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_CLK_GATE_E, 0);
- #endif
- #if( DEC_X170_USING_IRQ == 0)
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_IRQ_DIS, 1);
- #else
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_IRQ_DIS, 0);
- #endif
- /* set AXI RW IDs */
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_AXI_RD_ID,
- (DEC_X170_AXI_ID_R & 0xFFU));
- SetDecRegister(pJpegCont->jpegRegs, HWIF_DEC_AXI_WR_ID,
- (DEC_X170_AXI_ID_W & 0xFFU));
- /* save HW version so we dont need to check it all
- * the time when deciding the control stuff */
- pJpegCont->is8190 = (asicID >> 16) != 0x8170U ? 1 : 0;
- /* set HW related config's */
- if(pJpegCont->is8190)
- {
- pJpegCont->fuseBurned = fuseStatus;
- /* max */
- pJpegCont->maxSupportedWidth = JPEGDEC_MAX_WIDTH_8190;
- pJpegCont->maxSupportedHeight = JPEGDEC_MAX_HEIGHT_8190;
- pJpegCont->maxSupportedPixelAmount = JPEGDEC_MAX_PIXEL_AMOUNT_8190;
- pJpegCont->maxSupportedSliceSize = JPEGDEC_MAX_SLICE_SIZE_8190;
- }
- else
- {
- /* max */
- pJpegCont->maxSupportedWidth = JPEGDEC_MAX_WIDTH;
- pJpegCont->maxSupportedHeight = JPEGDEC_MAX_HEIGHT;
- pJpegCont->maxSupportedPixelAmount = JPEGDEC_MAX_PIXEL_AMOUNT;
- pJpegCont->maxSupportedSliceSize = JPEGDEC_MAX_SLICE_SIZE;
- }
- /* min */
- pJpegCont->minSupportedWidth = JPEGDEC_MIN_WIDTH;
- pJpegCont->minSupportedHeight = JPEGDEC_MIN_HEIGHT;
- pJpegCont->extensionsSupported = extensionsSupported;
- *pDecInst = (JpegDecContainer *) pJpegCont;
- // printk("JpegDecInit# OK\n");
- return (JPEGDEC_OK);
- }
- /*------------------------------------------------------------------------------
- Function name: JpegDecRelease
- Functional description:
- Release Jpeg decoder
- Inputs:
- JpegDecInst decInst jpeg decoder instance
- void
- ------------------------------------------------------------------------------*/
- void JpegDecRelease(JpegDecInst decInst)
- {
- #define PTR_JPGC ((JpegDecContainer *) decInst)
- const void *dwl;
- JPEGDEC_API_TRC("JpegDecRelease#\n");
- if(PTR_JPGC == NULL)
- {
- JPEGDEC_API_TRC("JpegDecRelease# ERROR: decInst == NULL\n");
- return;
- }
- dwl = PTR_JPGC->dwl;
- if(PTR_JPGC->vlc.acTable0.vals)
- {
- DWLfree(PTR_JPGC->vlc.acTable0.vals);
- }
- if(PTR_JPGC->vlc.acTable1.vals)
- {
- DWLfree(PTR_JPGC->vlc.acTable1.vals);
- }
- if(PTR_JPGC->vlc.acTable2.vals)
- {
- DWLfree(PTR_JPGC->vlc.acTable2.vals);
- }
- if(PTR_JPGC->vlc.acTable3.vals)
- {
- DWLfree(PTR_JPGC->vlc.acTable3.vals);
- }
- if(PTR_JPGC->vlc.dcTable0.vals)
- {
- DWLfree(PTR_JPGC->vlc.dcTable0.vals);
- }
- if(PTR_JPGC->vlc.dcTable1.vals)
- {
- DWLfree(PTR_JPGC->vlc.dcTable1.vals);
- }
- if(PTR_JPGC->vlc.dcTable2.vals)
- {
- DWLfree(PTR_JPGC->vlc.dcTable2.vals);
- }
- if(PTR_JPGC->vlc.dcTable3.vals)
- {
- DWLfree(PTR_JPGC->vlc.dcTable3.vals);
- }
- if(PTR_JPGC->frame.pBuffer)
- {
- DWLfree(PTR_JPGC->frame.pBuffer);
- }
- /* progressive */
- if(PTR_JPGC->info.pCoeffBase.virtualAddress)
- {
- DWLFreeLinear(dwl, &(PTR_JPGC->info.pCoeffBase));
- PTR_JPGC->info.pCoeffBase.virtualAddress = NULL;
- }
- if(PTR_JPGC->info.tmpStrm.virtualAddress)
- {
- DWLFreeLinear(dwl, &(PTR_JPGC->info.tmpStrm));
- PTR_JPGC->info.tmpStrm.virtualAddress = NULL;
- }
- if(PTR_JPGC->frame.pTableBase.virtualAddress)
- {
- DWLFreeLinear(dwl, &(PTR_JPGC->frame.pTableBase));
- PTR_JPGC->frame.pTableBase.virtualAddress = NULL;
- }
- /* if not user allocated memories */
- if(!PTR_JPGC->info.userAllocMem)
- {
- if(PTR_JPGC->asicBuff.outLumaBuffer.virtualAddress != NULL)
- {
- DWLFreeRefFrm(dwl, &(PTR_JPGC->asicBuff.outLumaBuffer));
- PTR_JPGC->asicBuff.outLumaBuffer.virtualAddress = NULL;
- }
- if(PTR_JPGC->asicBuff.outChromaBuffer.virtualAddress != NULL)
- {
- DWLFreeRefFrm(dwl, &(PTR_JPGC->asicBuff.outChromaBuffer));
- PTR_JPGC->asicBuff.outChromaBuffer.virtualAddress = NULL;
- }
- if(PTR_JPGC->asicBuff.outChromaBuffer2.virtualAddress != NULL)
- {
- DWLFreeRefFrm(dwl, &(PTR_JPGC->asicBuff.outChromaBuffer2));
- PTR_JPGC->asicBuff.outChromaBuffer2.virtualAddress = NULL;
- }
- }
- else
- {
- PTR_JPGC->asicBuff.outLumaBuffer.virtualAddress = NULL;
- PTR_JPGC->asicBuff.outChromaBuffer.virtualAddress = NULL;
- }
- if(decInst)
- {
- DWLfree(PTR_JPGC);
- }
- (void) DWLRelease(dwl);
- JPEGDEC_API_TRC("JpegDecRelease# OK\n");
- return;
- #undef PTR_JPGC
- }
- /*------------------------------------------------------------------------------
- Function name: JpegDecGetImageInfo
- Functional description:
- Get image information of the JFIF
- Inputs:
- JpegDecInst decInst jpeg decoder instance
- JpegDecInput *pDecIn input stream information
- JpegDecImageInfo *pImageInfo
- structure where the image info is written
- Outputs:
- JPEGDEC_OK
- JPEGDEC_ERROR
- JPEGDEC_UNSUPPORTED
- JPEGDEC_PARAM_ERROR
- JPEGDEC_INCREASE_BUFFER
- JPEGDEC_INVALID_STREAM_LENGTH
- JPEGDEC_INVALID_INPUT_BUFFER_SIZE
- ------------------------------------------------------------------------------*/
- /* Get image information of the JFIF */
- JpegDecRet JpegDecGetImageInfo(JpegDecInst decInst, JpegDecInput * pDecIn,
- JpegDecImageInfo * pImageInfo)
- {
- #define PTR_JPGC ((JpegDecContainer *) decInst)
- u32 Nf = 0;
- u32 Ns = 0;
- u32 NsThumb = 0;
- u32 i, j = 0;
- u32 init = 0;
- u32 initThumb = 0;
- u32 H[MAX_NUMBER_OF_COMPONENTS];
- u32 V[MAX_NUMBER_OF_COMPONENTS];
- u32 Htn[MAX_NUMBER_OF_COMPONENTS];
- u32 Vtn[MAX_NUMBER_OF_COMPONENTS];
- u32 Hmax = 0;
- u32 Vmax = 0;
- u32 headerLength = 0;
- u32 currentByte = 0;
- u32 currentBytes = 0;
- u32 appLength = 0;
- u32 appBits = 0;
- u32 thumbnail = 0;
- u32 errorCode = 0;
- #ifdef JPEGDEC_ERROR_RESILIENCE
- u32 errorResilience = 0;
- u32 errorResilienceThumb = 0;
- #endif /* JPEGDEC_ERROR_RESILIENCE */
- StreamStorage stream;
- // printk("JpegDecGetImageInfo#\n");
- /* check pointers & parameters */
- if(decInst == NULL || pDecIn == NULL || pImageInfo == NULL ||
- X170_CHECK_VIRTUAL_ADDRESS(pDecIn->streamBuffer.pVirtualAddress) ||
- X170_CHECK_BUS_ADDRESS(pDecIn->streamBuffer.busAddress))
- {
- printk("JpegDecGetImageInfo# ERROR: NULL parameter\n");
- return (JPEGDEC_PARAM_ERROR);
- }
- /* Check the stream lenth */
- if(pDecIn->streamLength < 1)
- {
- printk("JpegDecGetImageInfo# ERROR: pDecIn->streamLength\n");
- return (JPEGDEC_INVALID_STREAM_LENGTH);
- }
- /* Check the stream lenth */
- if((pDecIn->streamLength > DEC_X170_MAX_STREAM) &&
- (pDecIn->bufferSize < JPEGDEC_X170_MIN_BUFFER ||
- pDecIn->bufferSize > JPEGDEC_X170_MAX_BUFFER))
- {
- JPEGDEC_API_TRC("JpegDecGetImageInfo# ERROR: pDecIn->bufferSize\n");
- return (JPEGDEC_INVALID_INPUT_BUFFER_SIZE);
- }
- /* Check the stream buffer size */
- if(pDecIn->bufferSize && (pDecIn->bufferSize < JPEGDEC_X170_MIN_BUFFER ||
- pDecIn->bufferSize > JPEGDEC_X170_MAX_BUFFER))
- {
- JPEGDEC_API_TRC("JpegDecGetImageInfo# ERROR: pDecIn->bufferSize\n");
- return (JPEGDEC_INVALID_INPUT_BUFFER_SIZE);
- }
- /* Check the stream buffer size */
- if(pDecIn->bufferSize && ((pDecIn->bufferSize % 8) != 0))
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: pDecIn->bufferSize % 8) != 0\n");
- return (JPEGDEC_INVALID_INPUT_BUFFER_SIZE);
- }
- /* reset sampling factors */
- for(i = 0; i < MAX_NUMBER_OF_COMPONENTS; i++)
- {
- H[i] = 0;
- V[i] = 0;
- Htn[i] = 0;
- Vtn[i] = 0;
- }
- /* imageInfo initialization */
- pImageInfo->displayWidth = 0;
- pImageInfo->displayHeight = 0;
- pImageInfo->outputWidth = 0;
- pImageInfo->outputHeight = 0;
- pImageInfo->version = 0;
- pImageInfo->units = 0;
- pImageInfo->xDensity = 0;
- pImageInfo->yDensity = 0;
- pImageInfo->outputFormat = 0;
- /* Default value to "Thumbnail" */
- pImageInfo->thumbnailType = JPEGDEC_NO_THUMBNAIL;
- pImageInfo->displayWidthThumb = 0;
- pImageInfo->displayHeightThumb = 0;
- pImageInfo->outputWidthThumb = 0;
- pImageInfo->outputHeightThumb = 0;
- pImageInfo->outputFormatThumb = 0;
- /* utils initialization */
- stream.bitPosInByte = 0;
- stream.pCurrPos = (u8 *) pDecIn->streamBuffer.pVirtualAddress;
- stream.pStartOfStream = (u8 *) pDecIn->streamBuffer.pVirtualAddress;
- stream.readBits = 0;
- stream.appnFlag = 0;
- // printk("+++++pVirtualAddress 0x%x+++++++++++++++++++\n",pDecIn->streamBuffer.pVirtualAddress);
- // printk("++++++pCurrPos 0x%x,pStartOfStream 0x%x++++++++++++++++++++\n",stream.pCurrPos,stream.pStartOfStream);
- /* stream length */
- if(!pDecIn->bufferSize)
- stream.streamLength = pDecIn->streamLength;
- else
- stream.streamLength = pDecIn->bufferSize;
- /* Read decoding parameters */
- for(stream.readBits = 0; (stream.readBits / 8) < stream.streamLength;
- stream.readBits++)
- {
- /* Look for marker prefix byte from stream */
- if(JpegDecGetByte(&(stream)) == 0xFF)
- {
- currentByte = JpegDecGetByte(&(stream));
- /* switch to certain header decoding */
- switch (currentByte)
- {
- /* baseline marker */
- case SOF0:
- /* progresive marker */
- case SOF2:
- if(currentByte == SOF0)
- pImageInfo->codingMode = PTR_JPGC->info.operationType =
- JPEGDEC_BASELINE;
- else
- pImageInfo->codingMode = PTR_JPGC->info.operationType =
- JPEGDEC_PROGRESSIVE;
- /* Frame header */
- i++;
- Hmax = 0;
- Vmax = 0;
- /* SOF0/SOF2 length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- /* Sample precision (only 8 bits/sample supported) */
- currentByte = JpegDecGetByte(&(stream));
- if(currentByte != 8)
- {
- printk
- ("JpegDecGetImageInfo# ERROR: Sample precision\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- /* Number of Lines */
- pImageInfo->outputHeight = JpegDecGet2Bytes(&(stream));
- pImageInfo->displayHeight = pImageInfo->outputHeight;
- if(pImageInfo->outputHeight < 1)
- {
- printk
- ("JpegDecGetImageInfo# ERROR: pImageInfo->outputHeight Unsupported\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- #ifdef JPEGDEC_ERROR_RESILIENCE
- if((pImageInfo->outputHeight & 0xF) &&
- (pImageInfo->outputHeight & 0xF) <= 8)
- errorResilience = 1;
- #endif /* JPEGDEC_ERROR_RESILIENCE */
- /* round up to next multiple-of-16 */
- pImageInfo->outputHeight += 0xf;
- pImageInfo->outputHeight &= ~(0xf);
- PTR_JPGC->frame.hwY = pImageInfo->outputHeight;
- /* Number of Samples per Line */
- pImageInfo->outputWidth = JpegDecGet2Bytes(&(stream));
- pImageInfo->displayWidth = pImageInfo->outputWidth;
- if(pImageInfo->outputWidth < 1)
- {
- printk
- ("JpegDecGetImageInfo# ERROR: pImageInfo->outputWidth unsupported\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- pImageInfo->outputWidth += 0xf;
- pImageInfo->outputWidth &= ~(0xf);
- PTR_JPGC->frame.hwX = pImageInfo->outputWidth;
- /* check for minimum and maximum dimensions */
- if(pImageInfo->outputWidth < PTR_JPGC->minSupportedWidth ||
- pImageInfo->outputHeight < PTR_JPGC->minSupportedHeight ||
- pImageInfo->outputWidth > PTR_JPGC->maxSupportedWidth ||
- pImageInfo->outputHeight > PTR_JPGC->maxSupportedHeight ||
- (pImageInfo->outputWidth * pImageInfo->outputHeight) >
- PTR_JPGC->maxSupportedPixelAmount)
- {
- printk
- ("JpegDecGetImageInfo# ERROR: Unsupported size\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- /* Number of Image Components per Frame */
- Nf = JpegDecGetByte(&(stream));
- if(Nf != 3 && Nf != 1)
- {
- printk
- ("JpegDecGetImageInfo# ERROR: Number of Image Components per Frame\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- for(j = 0; j < Nf; j++)
- {
- /* jump over component identifier */
- if(JpegDecFlushBits(&(stream), 8) == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- /* Horizontal sampling factor */
- currentByte = JpegDecGetByte(&(stream));
- H[j] = (currentByte >> 4);
- /* Vertical sampling factor */
- V[j] = (currentByte & 0xF);
- /* jump over Tq */
- if(JpegDecFlushBits(&(stream), 8) == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- if(H[j] > Hmax)
- Hmax = H[j];
- if(V[j] > Vmax)
- Vmax = V[j];
- }
- if(Hmax == 0 || Vmax == 0)
- {
- printk
- ("JpegDecGetImageInfo# ERROR: Hmax == 0 || Vmax == 0\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- #ifdef JPEGDEC_ERROR_RESILIENCE
- if(H[0] == 2 && V[0] == 2 &&
- H[1] == 1 && V[1] == 1 && H[2] == 1 && V[2] == 1)
- {
- pImageInfo->outputFormat = JPEGDEC_YCbCr420_SEMIPLANAR;
- }
- else
- {
- /* check if fill needed */
- if(errorResilience)
- {
- pImageInfo->outputHeight -= 16;
- pImageInfo->displayHeight = pImageInfo->outputHeight;
- }
- }
- #endif /* JPEGDEC_ERROR_RESILIENCE */
- /* check format */
- if(H[0] == 2 && V[0] == 2 &&
- H[1] == 1 && V[1] == 1 && H[2] == 1 && V[2] == 1)
- {
- pImageInfo->outputFormat = JPEGDEC_YCbCr420_SEMIPLANAR;
- PTR_JPGC->frame.numMcuInRow = (PTR_JPGC->frame.hwX / 16);
- PTR_JPGC->frame.numMcuInFrame = ((PTR_JPGC->frame.hwX *
- PTR_JPGC->frame.hwY) /
- 256);
- }
- else if(H[0] == 2 && V[0] == 1 &&
- H[1] == 1 && V[1] == 1 && H[2] == 1 && V[2] == 1)
- {
- pImageInfo->outputFormat = JPEGDEC_YCbCr422_SEMIPLANAR;
- PTR_JPGC->frame.numMcuInRow = (PTR_JPGC->frame.hwX / 16);
- PTR_JPGC->frame.numMcuInFrame = ((PTR_JPGC->frame.hwX *
- PTR_JPGC->frame.hwY) /
- 128);
- }
- else if(H[0] == 1 && V[0] == 2 &&
- H[1] == 1 && V[1] == 1 && H[2] == 1 && V[2] == 1)
- {
- pImageInfo->outputFormat = JPEGDEC_YCbCr440;
- PTR_JPGC->frame.numMcuInRow = (PTR_JPGC->frame.hwX / 8);
- PTR_JPGC->frame.numMcuInFrame = ((PTR_JPGC->frame.hwX *
- PTR_JPGC->frame.hwY) /
- 128);
- }
- else if(H[0] == 1 && V[0] == 1 &&
- H[1] == 0 && V[1] == 0 && H[2] == 0 && V[2] == 0)
- {
- pImageInfo->outputFormat = JPEGDEC_YCbCr400;
- PTR_JPGC->frame.numMcuInRow = (PTR_JPGC->frame.hwX / 8);
- PTR_JPGC->frame.numMcuInFrame = ((PTR_JPGC->frame.hwX *
- PTR_JPGC->frame.hwY) /
- 64);
- }
- else if(PTR_JPGC->extensionsSupported &&
- H[0] == 4 && V[0] == 1 &&
- H[1] == 1 && V[1] == 1 && H[2] == 1 && V[2] == 1)
- {
- /* YUV411 output has to be 32 pixel multiple */
- if(pImageInfo->outputWidth & 0x1F)
- {
- pImageInfo->outputWidth += 16;
- PTR_JPGC->frame.hwX = pImageInfo->outputWidth;
- }
- /* check for maximum dimensions */
- if(pImageInfo->outputWidth > PTR_JPGC->maxSupportedWidth ||
- (pImageInfo->outputWidth * pImageInfo->outputHeight) >
- PTR_JPGC->maxSupportedPixelAmount)
- {
- printk
- ("JpegDecGetImageInfo# ERROR: Unsupported size\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- pImageInfo->outputFormat = JPEGDEC_YCbCr411_SEMIPLANAR;
- PTR_JPGC->frame.numMcuInRow = (PTR_JPGC->frame.hwX / 32);
- PTR_JPGC->frame.numMcuInFrame = ((PTR_JPGC->frame.hwX *
- PTR_JPGC->frame.hwY) /
- 256);
- }
- else if(PTR_JPGC->extensionsSupported &&
- H[0] == 1 && V[0] == 1 &&
- H[1] == 1 && V[1] == 1 && H[2] == 1 && V[2] == 1)
- {
- pImageInfo->outputFormat = JPEGDEC_YCbCr444_SEMIPLANAR;
- PTR_JPGC->frame.numMcuInRow = (PTR_JPGC->frame.hwX / 8);
- PTR_JPGC->frame.numMcuInFrame = ((PTR_JPGC->frame.hwX *
- PTR_JPGC->frame.hwY) /
- 64);
- }
- else
- {
- printk
- ("JpegDecGetImageInfo# ERROR: Unsupported YCbCr format\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- /* restore output format */
- PTR_JPGC->info.yCbCrMode = PTR_JPGC->info.getInfoYCbCrMode =
- pImageInfo->outputFormat;
- break;
- case SOS:
- /* SOS length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- /* check if interleaved or non-ibnterleaved */
- Ns = JpegDecGetByte(&(stream));
- if(Ns == MIN_NUMBER_OF_COMPONENTS &&
- pImageInfo->outputFormat != JPEGDEC_YCbCr400 &&
- pImageInfo->codingMode == JPEGDEC_BASELINE)
- {
- pImageInfo->codingMode = PTR_JPGC->info.operationType =
- JPEGDEC_NONINTERLEAVED;
- }
- /* jump over SOS header */
- if(headerLength != 0)
- {
- stream.readBits += ((headerLength * 8) - 16);
- stream.pCurrPos += (((headerLength * 8) - 16) / 8);
- }
- if((stream.readBits + 8) < (8 * stream.streamLength))
- {
- PTR_JPGC->info.init = 1;
- init = 1;
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Needs to increase input buffer\n");
- return (JPEGDEC_INCREASE_INPUT_BUFFER);
- }
- break;
- case DQT:
- /* DQT length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- /* jump over DQT header */
- if(headerLength != 0)
- {
- stream.readBits += ((headerLength * 8) - 16);
- stream.pCurrPos += (((headerLength * 8) - 16) / 8);
- }
- break;
- case DHT:
- /* DHT length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- /* jump over DHT header */
- if(headerLength != 0)
- {
- stream.readBits += ((headerLength * 8) - 16);
- stream.pCurrPos += (((headerLength * 8) - 16) / 8);
- }
- break;
- case DRI:
- /* DRI length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- #if 0
- /* jump over DRI header */
- if(headerLength != 0)
- {
- stream.readBits += ((headerLength * 8) - 16);
- stream.pCurrPos += (((headerLength * 8) - 16) / 8);
- }
- #endif
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- PTR_JPGC->frame.Ri = headerLength;
- break;
- /* application segments */
- case APP0:
- JPEGDEC_API_TRC("JpegDecGetImageInfo# APP0 in GetImageInfo\n");
- /* reset */
- appBits = 0;
- appLength = 0;
- stream.appnFlag = 0;
- /* APP0 length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- appLength = headerLength;
- if(appLength < 16)
- {
- stream.appnFlag = 1;
- if(JpegDecFlushBits(&(stream), ((appLength * 8) - 16)) ==
- STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- break;
- }
- appBits += 16;
- /* check identifier */
- currentBytes = JpegDecGet2Bytes(&(stream));
- appBits += 16;
- if(currentBytes != 0x4A46)
- {
- stream.appnFlag = 1;
- if(JpegDecFlushBits(&(stream), ((appLength * 8) - appBits))
- == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- break;
- }
- currentBytes = JpegDecGet2Bytes(&(stream));
- appBits += 16;
- if(currentBytes != 0x4946 && currentBytes != 0x5858)
- {
- stream.appnFlag = 1;
- if(JpegDecFlushBits(&(stream), ((appLength * 8) - appBits))
- == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- break;
- }
- /* APP0 Extended */
- if(currentBytes == 0x5858)
- {
- thumbnail = 1;
- }
- currentByte = JpegDecGetByte(&(stream));
- appBits += 8;
- if(currentByte != 0x00)
- {
- stream.appnFlag = 1;
- if(JpegDecFlushBits(&(stream), ((appLength * 8) - appBits))
- == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- stream.appnFlag = 0;
- break;
- }
- /* APP0 Extended thumb type */
- if(thumbnail)
- {
- /* extension code */
- currentByte = JpegDecGetByte(&(stream));
- if(currentByte == JPEGDEC_THUMBNAIL_JPEG)
- {
- pImageInfo->thumbnailType = JPEGDEC_THUMBNAIL_JPEG;
- appBits += 8;
- stream.appnFlag = 1;
- /* check thumbnail data */
- Hmax = 0;
- Vmax = 0;
- /* Read decoding parameters */
- for(; (stream.readBits / 8) < stream.streamLength;
- stream.readBits++)
- {
- /* Look for marker prefix byte from stream */
- appBits += 8;
- if(JpegDecGetByte(&(stream)) == 0xFF)
- {
- /* switch to certain header decoding */
- appBits += 8;
- currentByte = JpegDecGetByte(&(stream));
- switch (currentByte)
- {
- /* baseline marker */
- case SOF0:
- /* progresive marker */
- case SOF2:
- if(currentByte == SOF0)
- pImageInfo->codingModeThumb =
- PTR_JPGC->info.operationTypeThumb =
- JPEGDEC_BASELINE;
- else
- pImageInfo->codingModeThumb =
- PTR_JPGC->info.operationTypeThumb =
- JPEGDEC_PROGRESSIVE;
- /* Frame header */
- i++;
- /* jump over Lf field */
- if(JpegDecFlushBits(&(stream), 16) ==
- STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- appBits += 16;
- /* Sample precision (only 8 bits/sample supported) */
- currentByte = JpegDecGetByte(&(stream));
- appBits += 8;
- if(currentByte != 8)
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Thumbnail Sample precision");
- return (JPEGDEC_UNSUPPORTED);
- }
- /* Number of Lines */
- pImageInfo->outputHeightThumb =
- JpegDecGet2Bytes(&(stream));
- appBits += 16;
- pImageInfo->displayHeightThumb =
- pImageInfo->outputHeightThumb;
- if(pImageInfo->outputHeightThumb < 1)
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: pImageInfo->outputHeightThumb unsupported\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- #ifdef JPEGDEC_ERROR_RESILIENCE
- if((pImageInfo->outputHeightThumb & 0xF) &&
- (pImageInfo->outputHeightThumb & 0xF) <=
- 8)
- errorResilienceThumb = 1;
- #endif /* JPEGDEC_ERROR_RESILIENCE */
- /* round up to next multiple-of-16 */
- pImageInfo->outputHeightThumb += 0xf;
- pImageInfo->outputHeightThumb &= ~(0xf);
- /* Number of Samples per Line */
- pImageInfo->outputWidthThumb =
- JpegDecGet2Bytes(&(stream));
- appBits += 16;
- pImageInfo->displayWidthThumb =
- pImageInfo->outputWidthThumb;
- if(pImageInfo->outputWidthThumb < 1)
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: pImageInfo->outputWidthThumb unsupported\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- pImageInfo->outputWidthThumb += 0xf;
- pImageInfo->outputWidthThumb &= ~(0xf);
- if(pImageInfo->outputWidthThumb <
- PTR_JPGC->minSupportedWidth ||
- pImageInfo->outputHeightThumb <
- PTR_JPGC->minSupportedHeight ||
- pImageInfo->outputWidthThumb >
- JPEGDEC_MAX_WIDTH_TN ||
- pImageInfo->outputHeightThumb >
- JPEGDEC_MAX_HEIGHT_TN)
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Thumbnail Unsupported size\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- /* Number of Image Components per Frame */
- Nf = JpegDecGetByte(&(stream));
- appBits += 8;
- if(Nf != 3 && Nf != 1)
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Thumbnail Number of Image Components per Frame\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- for(j = 0; j < Nf; j++)
- {
- /* jump over component identifier */
- if(JpegDecFlushBits(&(stream), 8) ==
- STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- appBits += 8;
- /* Horizontal sampling factor */
- currentByte = JpegDecGetByte(&(stream));
- appBits += 8;
- Htn[j] = (currentByte >> 4);
- /* Vertical sampling factor */
- Vtn[j] = (currentByte & 0xF);
- /* jump over Tq */
- if(JpegDecFlushBits(&(stream), 8) ==
- STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- appBits += 8;
- if(Htn[j] > Hmax)
- Hmax = Htn[j];
- if(Vtn[j] > Vmax)
- Vmax = Vtn[j];
- }
- if(Hmax == 0 || Vmax == 0)
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Thumbnail Hmax == 0 || Vmax == 0\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- #ifdef JPEGDEC_ERROR_RESILIENCE
- if(Htn[0] == 2 && Vtn[0] == 2 &&
- Htn[1] == 1 && Vtn[1] == 1 &&
- Htn[2] == 1 && Vtn[2] == 1)
- {
- pImageInfo->outputFormatThumb =
- JPEGDEC_YCbCr420_SEMIPLANAR;
- }
- else
- {
- /* check if fill needed */
- if(errorResilienceThumb)
- {
- pImageInfo->outputHeightThumb -= 16;
- pImageInfo->displayHeightThumb =
- pImageInfo->outputHeightThumb;
- }
- }
- #endif /* JPEGDEC_ERROR_RESILIENCE */
- /* check format */
- if(Htn[0] == 2 && Vtn[0] == 2 &&
- Htn[1] == 1 && Vtn[1] == 1 &&
- Htn[2] == 1 && Vtn[2] == 1)
- {
- pImageInfo->outputFormatThumb =
- JPEGDEC_YCbCr420_SEMIPLANAR;
- }
- else if(Htn[0] == 2 && Vtn[0] == 1 &&
- Htn[1] == 1 && Vtn[1] == 1 &&
- Htn[2] == 1 && Vtn[2] == 1)
- {
- pImageInfo->outputFormatThumb =
- JPEGDEC_YCbCr422_SEMIPLANAR;
- }
- else if(Htn[0] == 1 && Vtn[0] == 2 &&
- Htn[1] == 1 && Vtn[1] == 1 &&
- Htn[2] == 1 && Vtn[2] == 1)
- {
- pImageInfo->outputFormatThumb =
- JPEGDEC_YCbCr440;
- }
- else if(Htn[0] == 1 && Vtn[0] == 1 &&
- Htn[1] == 0 && Vtn[1] == 0 &&
- Htn[2] == 0 && Vtn[2] == 0)
- {
- pImageInfo->outputFormatThumb =
- JPEGDEC_YCbCr400;
- }
- else if(PTR_JPGC->is8190 &&
- Htn[0] == 4 && Vtn[0] == 1 &&
- Htn[1] == 1 && Vtn[1] == 1 &&
- Htn[2] == 1 && Vtn[2] == 1)
- {
- pImageInfo->outputFormatThumb =
- JPEGDEC_YCbCr411_SEMIPLANAR;
- }
- else if(PTR_JPGC->is8190 &&
- Htn[0] == 1 && Vtn[0] == 1 &&
- Htn[1] == 1 && Vtn[1] == 1 &&
- Htn[2] == 1 && Vtn[2] == 1)
- {
- pImageInfo->outputFormatThumb =
- JPEGDEC_YCbCr444_SEMIPLANAR;
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Thumbnail Unsupported YCbCr format\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- PTR_JPGC->info.initThumb = 1;
- initThumb = 1;
- break;
- case SOS:
- /* SOS length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits +
- ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- /* check if interleaved or non-ibnterleaved */
- NsThumb = JpegDecGetByte(&(stream));
- if(NsThumb == MIN_NUMBER_OF_COMPONENTS &&
- pImageInfo->outputFormatThumb !=
- JPEGDEC_YCbCr400 &&
- pImageInfo->codingModeThumb ==
- JPEGDEC_BASELINE)
- {
- pImageInfo->codingModeThumb =
- PTR_JPGC->info.operationTypeThumb =
- JPEGDEC_NONINTERLEAVED;
- }
- /* jump over SOS header */
- if(headerLength != 0)
- {
- stream.readBits +=
- ((headerLength * 8) - 16);
- stream.pCurrPos +=
- (((headerLength * 8) - 16) / 8);
- }
- if((stream.readBits + 8) <
- (8 * stream.streamLength))
- {
- PTR_JPGC->info.init = 1;
- init = 1;
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Needs to increase input buffer\n");
- return (JPEGDEC_INCREASE_INPUT_BUFFER);
- }
- break;
- case DQT:
- /* DQT length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- /* jump over DQT header */
- if(headerLength != 0)
- {
- stream.readBits +=
- ((headerLength * 8) - 16);
- stream.pCurrPos +=
- (((headerLength * 8) - 16) / 8);
- }
- appBits += (headerLength * 8);
- break;
- case DHT:
- /* DHT length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- /* jump over DHT header */
- if(headerLength != 0)
- {
- stream.readBits +=
- ((headerLength * 8) - 16);
- stream.pCurrPos +=
- (((headerLength * 8) - 16) / 8);
- }
- appBits += (headerLength * 8);
- break;
- case DRI:
- /* DRI length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- /* jump over DRI header */
- if(headerLength != 0)
- {
- stream.readBits +=
- ((headerLength * 8) - 16);
- stream.pCurrPos +=
- (((headerLength * 8) - 16) / 8);
- }
- appBits += (headerLength * 8);
- break;
- case APP0:
- case APP1:
- case APP2:
- case APP3:
- case APP4:
- case APP5:
- case APP6:
- case APP7:
- case APP8:
- case APP9:
- case APP10:
- case APP11:
- case APP12:
- case APP13:
- case APP14:
- case APP15:
- /* APPn length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- /* jump over APPn header */
- if(headerLength != 0)
- {
- stream.readBits +=
- ((headerLength * 8) - 16);
- stream.pCurrPos +=
- (((headerLength * 8) - 16) / 8);
- }
- appBits += (headerLength * 8);
- break;
- case DNL:
- /* DNL length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- /* jump over DNL header */
- if(headerLength != 0)
- {
- stream.readBits +=
- ((headerLength * 8) - 16);
- stream.pCurrPos +=
- (((headerLength * 8) - 16) / 8);
- }
- appBits += (headerLength * 8);
- break;
- case COM:
- /* COM length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- /* jump over COM header */
- if(headerLength != 0)
- {
- stream.readBits +=
- ((headerLength * 8) - 16);
- stream.pCurrPos +=
- (((headerLength * 8) - 16) / 8);
- }
- appBits += (headerLength * 8);
- break;
- /* unsupported coding styles */
- case SOF1:
- case SOF3:
- case SOF5:
- case SOF6:
- case SOF7:
- case SOF9:
- case SOF10:
- case SOF11:
- case SOF13:
- case SOF14:
- case SOF15:
- case DAC:
- case DHP:
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Unsupported coding styles\n");
- return (JPEGDEC_UNSUPPORTED);
- default:
- break;
- }
- if(PTR_JPGC->info.initThumb && initThumb)
- {
- /* flush the rest of thumbnail data */
- if(JpegDecFlushBits
- (&(stream),
- ((appLength * 8) - appBits)) ==
- STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- stream.appnFlag = 0;
- break;
- }
- }
- else
- {
- if(!PTR_JPGC->info.initThumb &&
- pDecIn->bufferSize)
- return (JPEGDEC_INCREASE_INPUT_BUFFER);
- else
- return (JPEGDEC_STRM_ERROR);
- }
- }
- break;
- }
- else
- {
- appBits += 8;
- pImageInfo->thumbnailType =
- JPEGDEC_THUMBNAIL_NOT_SUPPORTED_FORMAT;
- stream.appnFlag = 1;
- if(JpegDecFlushBits
- (&(stream),
- ((appLength * 8) - appBits)) == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- stream.appnFlag = 0;
- break;
- }
- }
- else
- {
- /* version */
- pImageInfo->version = JpegDecGet2Bytes(&(stream));
- appBits += 16;
- /* units */
- currentByte = JpegDecGetByte(&(stream));
- if(currentByte == 0)
- {
- pImageInfo->units = JPEGDEC_NO_UNITS;
- }
- else if(currentByte == 1)
- {
- pImageInfo->units = JPEGDEC_DOTS_PER_INCH;
- }
- else if(currentByte == 2)
- {
- pImageInfo->units = JPEGDEC_DOTS_PER_CM;
- }
- appBits += 8;
- /* Xdensity */
- pImageInfo->xDensity = JpegDecGet2Bytes(&(stream));
- appBits += 16;
- /* Ydensity */
- pImageInfo->yDensity = JpegDecGet2Bytes(&(stream));
- appBits += 16;
- /* jump over rest of header data */
- stream.appnFlag = 1;
- if(JpegDecFlushBits(&(stream), ((appLength * 8) - appBits))
- == STRM_ERROR)
- {
- errorCode = 1;
- break;
- }
- stream.appnFlag = 0;
- break;
- }
- case APP1:
- case APP2:
- case APP3:
- case APP4:
- case APP5:
- case APP6:
- case APP7:
- case APP8:
- case APP9:
- case APP10:
- case APP11:
- case APP12:
- case APP13:
- case APP14:
- case APP15:
- /* APPn length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- /* jump over APPn header */
- if(headerLength != 0)
- {
- stream.readBits += ((headerLength * 8) - 16);
- stream.pCurrPos += (((headerLength * 8) - 16) / 8);
- }
- break;
- case DNL:
- /* DNL length */
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- /* jump over DNL header */
- if(headerLength != 0)
- {
- stream.readBits += ((headerLength * 8) - 16);
- stream.pCurrPos += (((headerLength * 8) - 16) / 8);
- }
- break;
- case COM:
- headerLength = JpegDecGet2Bytes(&(stream));
- if(headerLength == STRM_ERROR ||
- ((stream.readBits + ((headerLength * 8) - 16)) >
- (8 * stream.streamLength)))
- {
- errorCode = 1;
- break;
- }
- /* jump over COM header */
- if(headerLength != 0)
- {
- stream.readBits += ((headerLength * 8) - 16);
- stream.pCurrPos += (((headerLength * 8) - 16) / 8);
- }
- break;
- /* unsupported coding styles */
- case SOF1:
- case SOF3:
- case SOF5:
- case SOF6:
- case SOF7:
- case SOF9:
- case SOF10:
- case SOF11:
- case SOF13:
- case SOF14:
- case SOF15:
- case DAC:
- case DHP:
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Unsupported coding styles\n");
- return (JPEGDEC_UNSUPPORTED);
- default:
- break;
- }
- if(PTR_JPGC->info.init && init)
- break;
- if(errorCode)
- {
- if(pDecIn->bufferSize)
- {
- JPEGDEC_API_TRC
- ("JpegDecGetImageInfo# ERROR: Image info failed!\n");
- return (JPEGDEC_INCREASE_INPUT_BUFFER);
- }
- else
- {
- JPEGDEC_API_TRC("JpegDecGetImageInfo# ERROR: Stream error\n");
- return (JPEGDEC_STRM_ERROR);
- }
- }
- }
- else
- {
- if(!PTR_JPGC->info.init)
- return (JPEGDEC_INCREASE_INPUT_BUFFER);
- else
- return (JPEGDEC_STRM_ERROR);
- }
- }
- if(PTR_JPGC->info.init)
- {
- if(pDecIn->bufferSize)
- PTR_JPGC->info.initBufferSize = pDecIn->bufferSize;
- return (JPEGDEC_OK);
- }
- else
- {
- printk("JpegDecGetImageInfo# ERROR\n");
- return (JPEGDEC_ERROR);
- }
- #undef PTR_JPGC
- }
- /*------------------------------------------------------------------------------
- Function name: JpegDecDecode
- Functional description:
- Decode JFIF
- Inputs:
- JpegDecInst decInst jpeg decoder instance
- JpegDecInput *pDecIn pointer to structure where the decoder
- stores input information
- JpegDecOutput *pDecOut pointer to structure where the decoder
- stores output frame information
- Outputs:
- JPEGDEC_FRAME_READY
- JPEGDEC_PARAM_ERROR
- JPEGDEC_INVALID_STREAM_LENGTH
- JPEGDEC_INVALID_INPUT_BUFFER_SIZE
- JPEGDEC_UNSUPPORTED
- JPEGDEC_ERROR
- JPEGDEC_STRM_ERROR
- JPEGDEC_HW_BUS_ERROR
- JPEGDEC_DWL_HW_TIMEOUT
- JPEGDEC_SYSTEM_ERROR
- JPEGDEC_HW_RESERVED
- JPEGDEC_STRM_PROCESSED
- ------------------------------------------------------------------------------*/
- JpegDecRet JpegDecDecode(JpegDecInst decInst, JpegDecInput * pDecIn,
- JpegDecOutput * pDecOut)
- {
- #define PTR_JPGC ((JpegDecContainer *) decInst)
- #define JPG_FRM PTR_JPGC->frame
- #define JPG_INFO PTR_JPGC->info
- i32 dwlret = -1;
- u32 i = 0;
- u32 currentByte = 0;
- u32 currentBytes = 0;
- u32 appLength = 0;
- u32 appBits = 0;
- u32 asic_status = 0;
- u32 HINTdec = 0;
- u32 asicSliceBit = 0;
- u32 intDec = 0;
- u32 currentPos = 0;
- u32 endOfImage = 0;
- u32 nonInterleavedRdy = 0;
- JpegDecRet infoRet;
- JpegDecRet retCode; /* Returned code container */
- JpegDecImageInfo infoTmp;
- u32 mcuSizeDivider = 0;
- /* check null */
- if(decInst == NULL || pDecIn == NULL ||
- X170_CHECK_VIRTUAL_ADDRESS(pDecIn->streamBuffer.pVirtualAddress) ||
- X170_CHECK_BUS_ADDRESS(pDecIn->streamBuffer.busAddress) ||
- pDecOut == NULL)
- {
- printk("JpegDecDecode# ERROR: NULL parameter");
- return (JPEGDEC_PARAM_ERROR);
- }
- /* check image decoding type */
- if(pDecIn->decImageType != 0 && pDecIn->decImageType != 1)
- {
- printk("JpegDecDecode# ERROR: decImageType");
- return (JPEGDEC_PARAM_ERROR);
- }
- /* check user allocated null */
- if((pDecIn->pictureBufferY.pVirtualAddress == NULL &&
- pDecIn->pictureBufferY.busAddress != 0) ||
- (pDecIn->pictureBufferY.pVirtualAddress != NULL &&
- pDecIn->pictureBufferY.busAddress == 0) ||
- (pDecIn->pictureBufferCbCr.pVirtualAddress == NULL &&
- pDecIn->pictureBufferCbCr.busAddress != 0) ||
- (pDecIn->pictureBufferCbCr.pVirtualAddress != NULL &&
- pDecIn->pictureBufferCbCr.busAddress == 0))
- {
- printk("JpegDecDecode# ERROR: NULL parameter");
- return (JPEGDEC_PARAM_ERROR);
- }
- /* Check the stream lenth */
- if(pDecIn->streamLength < 1)
- {
- printk("JpegDecDecode# ERROR: pDecIn->streamLength");
- return (JPEGDEC_INVALID_STREAM_LENGTH);
- }
- /* check the input buffer settings ==>
- * checks are discarded for last buffer */
- if(!PTR_JPGC->info.streamEndFlag)
- {
- /* Check the stream lenth */
- if(!PTR_JPGC->info.inputBufferEmpty &&
- (pDecIn->streamLength > DEC_X170_MAX_STREAM) &&
- (pDecIn->bufferSize < JPEGDEC_X170_MIN_BUFFER ||
- pDecIn->bufferSize > JPEGDEC_X170_MAX_BUFFER))
- {
- printk("JpegDecDecode# ERROR: pDecIn->bufferSize");
- return (JPEGDEC_INVALID_INPUT_BUFFER_SIZE);
- }
- /* Check the stream buffer size */
- if(!PTR_JPGC->info.inputBufferEmpty &&
- pDecIn->bufferSize && (pDecIn->bufferSize < JPEGDEC_X170_MIN_BUFFER
- || pDecIn->bufferSize >
- JPEGDEC_X170_MAX_BUFFER))
- {
- printk("JpegDecDecode# ERROR: pDecIn->bufferSize");
- return (JPEGDEC_INVALID_INPUT_BUFFER_SIZE);
- }
- /* Check the stream buffer size */
- if(!PTR_JPGC->info.inputBufferEmpty &&
- pDecIn->bufferSize && ((pDecIn->bufferSize % 256) != 0))
- {
- printk("JpegDecDecode# ERROR: pDecIn->bufferSize %% 256) != 0");
- return (JPEGDEC_INVALID_INPUT_BUFFER_SIZE);
- }
- if(!PTR_JPGC->info.inputBufferEmpty &&
- PTR_JPGC->info.init &&
- (pDecIn->bufferSize < PTR_JPGC->info.initBufferSize))
- {
- printk
- ("JpegDecDecode# ERROR: Increase input buffer size!\n");
- return (JPEGDEC_INVALID_INPUT_BUFFER_SIZE);
- }
- }
- if(!PTR_JPGC->info.init && !PTR_JPGC->info.SliceReadyForPause &&
- !PTR_JPGC->info.inputBufferEmpty)
- {
- printk(("JpegDecDecode#: Get Image Info!\n"));
- infoRet = JpegDecGetImageInfo(decInst, pDecIn, &infoTmp);
- if(infoRet != JPEGDEC_OK)
- {
- printk(("JpegDecDecode# ERROR: Image info failed!\n"));
- return (infoRet);
- }
- }
- /* Store the stream parameters */
- if(PTR_JPGC->info.progressiveScanReady == 0 &&
- PTR_JPGC->info.nonInterleavedScanReady == 0)
- {
- PTR_JPGC->stream.bitPosInByte = 0;
- PTR_JPGC->stream.pCurrPos = (u8 *) pDecIn->streamBuffer.pVirtualAddress;
- PTR_JPGC->stream.streamBus = pDecIn->streamBuffer.busAddress;
- PTR_JPGC->stream.pStartOfStream =
- (u8 *) pDecIn->streamBuffer.pVirtualAddress;
- PTR_JPGC->stream.readBits = 0;
- PTR_JPGC->stream.streamLength = pDecIn->streamLength;
- PTR_JPGC->stream.appnFlag = 0;
- pDecOut->outputPictureY.pVirtualAddress = NULL;
- pDecOut->outputPictureY.busAddress = 0;
- pDecOut->outputPictureCbCr.pVirtualAddress = NULL;
- pDecOut->outputPictureCbCr.busAddress = 0;
- pDecOut->outputPictureCr.pVirtualAddress = NULL;
- pDecOut->outputPictureCr.busAddress = 0;
- }
- else
- {
- PTR_JPGC->image.headerReady = 0;
- }
- /* set mcu/slice value */
- PTR_JPGC->info.sliceMbSetValue = pDecIn->sliceMbSet;
- /* check HW supported features */
- if(!PTR_JPGC->is8190)
- {
- /* return if not valid HW and unsupported operation type */
- if(PTR_JPGC->info.operationType == JPEGDEC_NONINTERLEAVED ||
- PTR_JPGC->info.operationType == JPEGDEC_PROGRESSIVE)
- {
- printk
- ("JpegDecDecode# ERROR: Operation type not supported\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- if(PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr400 ||
- PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr440 ||
- PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr444_SEMIPLANAR)
- mcuSizeDivider = 2;
- else
- mcuSizeDivider = 1;
- /* check slice config */
- if((pDecIn->sliceMbSet * (JPG_FRM.numMcuInRow / mcuSizeDivider)) >
- PTR_JPGC->maxSupportedSliceSize)
- {
- printk
- ("JpegDecDecode# ERROR: sliceMbSet > JPEGDEC_MAX_SLICE_SIZE\n");
- return (JPEGDEC_PARAM_ERROR);
- }
- /* check frame size */
- if((!pDecIn->sliceMbSet) &&
- JPG_FRM.numMcuInFrame > PTR_JPGC->maxSupportedSliceSize)
- {
- printk
- ("JpegDecDecode# ERROR: mcuInFrame > JPEGDEC_MAX_SLICE_SIZE\n");
- return (JPEGDEC_PARAM_ERROR);
- }
- }
- else
- {
- /* check if fuse was burned */
- if(PTR_JPGC->fuseBurned)
- {
- /* return if not valid HW and unsupported operation type */
- if(PTR_JPGC->info.operationType == JPEGDEC_PROGRESSIVE)
- {
- printk
- ("JpegDecDecode# ERROR: Operation type not supported\n");
- return (JPEGDEC_UNSUPPORTED);
- }
- }
- /* check slice config */
- if((pDecIn->sliceMbSet && pDecIn->decImageType == JPEGDEC_IMAGE &&
- PTR_JPGC->info.operationType != JPEGDEC_BASELINE) ||
- (pDecIn->sliceMbSet && pDecIn->decImageType == JPEGDEC_THUMBNAIL &&
- PTR_JPGC->info.operationTypeThumb != JPEGDEC_BASELINE))
- {
- printk
- ("JpegDecDecode# ERROR: Slice mode not supported for this operation type\n");
- return (JPEGDEC_SLICE_MODE_UNSUPPORTED);
- }
- /* check if frame size over 16M */
- if((!pDecIn->sliceMbSet) &&
- ((JPG_FRM.hwX * JPG_FRM.hwY) > JPEGDEC_MAX_PIXEL_AMOUNT))
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# ERROR: Resolution > 16M ==> use slice mode!\n");
- return (JPEGDEC_PARAM_ERROR);
- }
- if(PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr400 ||
- PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr440 ||
- PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr444_SEMIPLANAR)
- mcuSizeDivider = 2;
- else
- mcuSizeDivider = 1;
- /* check slice config */
- if((pDecIn->sliceMbSet * (JPG_FRM.numMcuInRow / mcuSizeDivider)) >
- PTR_JPGC->maxSupportedSliceSize)
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# ERROR: sliceMbSet > JPEGDEC_MAX_SLICE_SIZE\n");
- return (JPEGDEC_PARAM_ERROR);
- }
- }
- /* check slice size */
- if(pDecIn->sliceMbSet &&
- !PTR_JPGC->info.SliceReadyForPause && !PTR_JPGC->info.inputBufferEmpty)
- {
- if(PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr400 ||
- PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr440 ||
- PTR_JPGC->info.getInfoYCbCrMode == JPEGDEC_YCbCr444_SEMIPLANAR)
- mcuSizeDivider = 2;
- else
- mcuSizeDivider = 1;
- if((pDecIn->sliceMbSet * (JPG_FRM.numMcuInRow / mcuSizeDivider)) >
- JPG_FRM.numMcuInFrame)
- {
- printk
- ("JpegDecDecode# ERROR: (sliceMbSet * Number of MCU's in row) > Number of MCU's in frame\n");
- return (JPEGDEC_PARAM_ERROR);
- }
- }
- /* Handle stream/hw parameters after buffer empty */
- if(PTR_JPGC->info.inputBufferEmpty)
- {
- /* Store the stream parameters */
- PTR_JPGC->stream.bitPosInByte = 0;
- PTR_JPGC->stream.pCurrPos = (u8 *) pDecIn->streamBuffer.pVirtualAddress;
- PTR_JPGC->stream.streamBus = pDecIn->streamBuffer.busAddress;
- PTR_JPGC->stream.pStartOfStream =
- (u8 *) pDecIn->streamBuffer.pVirtualAddress;
- /* update hw parameters */
- PTR_JPGC->info.inputStreaming = 1;
- if(pDecIn->bufferSize)
- PTR_JPGC->info.inputBufferLen = pDecIn->bufferSize;
- else
- PTR_JPGC->info.inputBufferLen = pDecIn->streamLength;
- /* decoded stream */
- PTR_JPGC->info.decodedStreamLen += PTR_JPGC->info.inputBufferLen;
- if(PTR_JPGC->info.decodedStreamLen > pDecIn->streamLength)
- {
- printk
- ("JpegDecDecode# Error: All input stream already processed\n");
- return JPEGDEC_STRM_ERROR;
- }
- }
- /* update user allocated output */
- PTR_JPGC->info.givenOutLuma.virtualAddress =
- pDecIn->pictureBufferY.pVirtualAddress;
- PTR_JPGC->info.givenOutLuma.busAddress = pDecIn->pictureBufferY.busAddress;
- PTR_JPGC->info.givenOutChroma.virtualAddress =
- pDecIn->pictureBufferCbCr.pVirtualAddress;
- PTR_JPGC->info.givenOutChroma.busAddress =
- pDecIn->pictureBufferCbCr.busAddress;
- PTR_JPGC->info.givenOutChroma2.virtualAddress =
- pDecIn->pictureBufferCr.pVirtualAddress;
- PTR_JPGC->info.givenOutChroma2.busAddress =
- pDecIn->pictureBufferCr.busAddress;
- if(PTR_JPGC->info.progressiveFinish)
- {
- /* output set */
- if(PTR_JPGC->ppInstance == NULL)
- {
- pDecOut->outputPictureY.pVirtualAddress =
- PTR_JPGC->info.outLuma.virtualAddress;
- ASSERT(pDecOut->outputPictureY.pVirtualAddress);
- /* output set */
- pDecOut->outputPictureY.busAddress =
- PTR_JPGC->info.outLuma.busAddress;
- ASSERT(pDecOut->outputPictureY.busAddress);
- /* if not grayscale */
- if(PTR_JPGC->image.sizeChroma)
- {
- pDecOut->outputPictureCbCr.pVirtualAddress =
- PTR_JPGC->info.outChroma.virtualAddress;
- ASSERT(pDecOut->outputPictureCbCr.pVirtualAddress);
- pDecOut->outputPictureCbCr.busAddress =
- PTR_JPGC->info.outChroma.busAddress;
- ASSERT(pDecOut->outputPictureCbCr.busAddress);
- pDecOut->outputPictureCr.pVirtualAddress =
- PTR_JPGC->info.outChroma2.virtualAddress;
- pDecOut->outputPictureCr.busAddress =
- PTR_JPGC->info.outChroma2.busAddress;
- }
- }
- JpegDecInitHWEmptyScan(PTR_JPGC, PTR_JPGC->info.pfCompId);
- dwlret = DWLWaitHwReady(PTR_JPGC->dwl, PTR_JPGC->info.timeout);
- ASSERT(dwlret == DWL_HW_WAIT_OK);
- JpegRefreshRegs(PTR_JPGC);
- asic_status = GetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_IRQ_STAT);
- ASSERT(asic_status == 1);
- i = PTR_JPGC->info.pfCompId + 1;
- while(i < 3 && PTR_JPGC->info.pfNeeded[i] == 0)
- i++;
- if(i == 3)
- {
- PTR_JPGC->info.progressiveFinish = 0;
- return (JPEGDEC_FRAME_READY);
- }
- else
- {
- PTR_JPGC->info.pfCompId = i;
- return (JPEGDEC_SCAN_PROCESSED);
- }
- }
- /* check if input streaming used */
- if(!PTR_JPGC->info.SliceReadyForPause &&
- !PTR_JPGC->info.inputBufferEmpty && pDecIn->bufferSize)
- {
- PTR_JPGC->info.inputStreaming = 1;
- PTR_JPGC->info.inputBufferLen = pDecIn->bufferSize;
- PTR_JPGC->info.decodedStreamLen += PTR_JPGC->info.inputBufferLen;
- }
- /* find markers and go ! */
- do
- {
- /* if slice mode/slice done return to hw handling */
- if(PTR_JPGC->image.headerReady && PTR_JPGC->info.SliceReadyForPause)
- break;
- /* Look for marker prefix byte from stream */
- if(JpegDecGetByte(&(PTR_JPGC->stream)) == 0xFF)
- {
- currentByte = JpegDecGetByte(&(PTR_JPGC->stream));
- /* switch to certain header decoding */
- switch (currentByte)
- {
- case 0x00:
- break;
- case SOF0:
- case SOF2:
- /* Baseline/Progressive */
- PTR_JPGC->frame.codingType = currentByte;
- /* Set operation type */
- if(PTR_JPGC->frame.codingType == SOF0)
- PTR_JPGC->info.operationType = JPEGDEC_BASELINE;
- else
- PTR_JPGC->info.operationType = JPEGDEC_PROGRESSIVE;
- retCode = JpegDecDecodeFrameHdr(PTR_JPGC);
- if(retCode != JPEGDEC_OK)
- {
- if(retCode == JPEGDEC_STRM_ERROR)
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Stream error");
- return (retCode);
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# ERROR: JpegDecDecodeFrameHdr err");
- return (retCode);
- }
- }
- break;
- /* Start of Scan */
- case SOS:
- /* reset image ready */
- PTR_JPGC->image.imageReady = 0;
- JPEGDEC_API_TRC("JpegDecDecode# JpegDecDecodeScan dec");
- retCode = JpegDecDecodeScan(PTR_JPGC);
- PTR_JPGC->image.headerReady = 1;
- if(retCode != JPEGDEC_OK)
- {
- if(retCode == JPEGDEC_STRM_ERROR)
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Stream error");
- return (retCode);
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# JpegDecDecodeScan err\n");
- return (retCode);
- }
- }
- if(PTR_JPGC->stream.bitPosInByte)
- {
- /* delete stuffing bits */
- currentByte = (8 - PTR_JPGC->stream.bitPosInByte);
- if(JpegDecFlushBits
- (&(PTR_JPGC->stream),
- 8 - PTR_JPGC->stream.bitPosInByte) == STRM_ERROR)
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Stream error");
- return (JPEGDEC_STRM_ERROR);
- }
- }
- JPEGDEC_API_TRC("JpegDecDecode# Stuffing bits deleted\n");
- break;
- /* Start of Huffman tables */
- case DHT:
- JPEGDEC_API_TRC
- ("JpegDecDecode# JpegDecDecodeHuffmanTables dec");
- retCode = JpegDecDecodeHuffmanTables(PTR_JPGC);
- JPEGDEC_API_TRC
- ("JpegDecDecode# JpegDecDecodeHuffmanTables stops");
- if(retCode != JPEGDEC_OK)
- {
- if(retCode == JPEGDEC_STRM_ERROR)
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Stream error");
- return (retCode);
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# ERROR: JpegDecDecodeHuffmanTables err");
- return (retCode);
- }
- }
- break;
- /* start of Quantisation Tables */
- case DQT:
- JPEGDEC_API_TRC("JpegDecDecode# JpegDecDecodeQuantTables dec");
- retCode = JpegDecDecodeQuantTables(PTR_JPGC);
- if(retCode != JPEGDEC_OK)
- {
- if(retCode == JPEGDEC_STRM_ERROR)
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Stream error");
- return (retCode);
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# ERROR: JpegDecDecodeQuantTables err");
- return (retCode);
- }
- }
- break;
- /* Start of Image */
- case SOI:
- /* no actions needed, continue */
- break;
- /* End of Image */
- case EOI:
- if(PTR_JPGC->image.imageReady)
- {
- JPEGDEC_API_TRC("JpegDecDecode# EOI: OK\n");
- return (JPEGDEC_FRAME_READY);
- }
- else
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: EOI: NOK\n");
- return (JPEGDEC_ERROR);
- }
- /* Define Restart Interval */
- case DRI:
- JPEGDEC_API_TRC("JpegDecDecode# DRI");
- currentBytes = JpegDecGet2Bytes(&(PTR_JPGC->stream));
- if(currentBytes == STRM_ERROR)
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Read bits ");
- return (JPEGDEC_STRM_ERROR);
- }
- PTR_JPGC->frame.Ri = JpegDecGet2Bytes(&(PTR_JPGC->stream));
- break;
- /* Restart with modulo 8 count m */
- case RST0:
- case RST1:
- case RST2:
- case RST3:
- case RST4:
- case RST5:
- case RST6:
- case RST7:
- /* initialisation of DC predictors to zero value !!! */
- for(i = 0; i < MAX_NUMBER_OF_COMPONENTS; i++)
- {
- PTR_JPGC->scan.pred[i] = 0;
- }
- JPEGDEC_API_TRC("JpegDecDecode# DC predictors init");
- break;
- /* unsupported features */
- case DNL:
- case SOF1:
- case SOF3:
- case SOF5:
- case SOF6:
- case SOF7:
- case SOF9:
- case SOF10:
- case SOF11:
- case SOF13:
- case SOF14:
- case SOF15:
- case DAC:
- case DHP:
- case TEM:
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Unsupported Features");
- return (JPEGDEC_UNSUPPORTED);
- /* application data & comments */
- case APP0:
- JPEGDEC_API_TRC("JpegDecDecode# APP0 in Decode");
- /* APP0 Extended Thumbnail */
- if(pDecIn->decImageType == JPEGDEC_THUMBNAIL)
- {
- /* reset */
- appBits = 0;
- appLength = 0;
- /* length */
- appLength = JpegDecGet2Bytes(&(PTR_JPGC->stream));
- appBits += 16;
- /* check identifier */
- currentBytes = JpegDecGet2Bytes(&(PTR_JPGC->stream));
- appBits += 16;
- if(currentBytes != 0x4A46)
- {
- PTR_JPGC->stream.appnFlag = 1;
- if(JpegDecFlushBits
- (&(PTR_JPGC->stream),
- ((appLength * 8) - appBits)) == STRM_ERROR)
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# ERROR: Stream error");
- return (JPEGDEC_STRM_ERROR);
- }
- PTR_JPGC->stream.appnFlag = 0;
- break;
- }
- currentBytes = JpegDecGet2Bytes(&(PTR_JPGC->stream));
- appBits += 16;
- if(currentBytes != 0x5858)
- {
- PTR_JPGC->stream.appnFlag = 1;
- if(JpegDecFlushBits
- (&(PTR_JPGC->stream),
- ((appLength * 8) - appBits)) == STRM_ERROR)
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# ERROR: Stream error");
- return (JPEGDEC_STRM_ERROR);
- }
- PTR_JPGC->stream.appnFlag = 0;
- break;
- }
- currentByte = JpegDecGetByte(&(PTR_JPGC->stream));
- appBits += 8;
- if(currentByte != 0x00)
- {
- PTR_JPGC->stream.appnFlag = 1;
- if(JpegDecFlushBits
- (&(PTR_JPGC->stream),
- ((appLength * 8) - appBits)) == STRM_ERROR)
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# ERROR: Stream error");
- return (JPEGDEC_STRM_ERROR);
- }
- PTR_JPGC->stream.appnFlag = 0;
- break;
- }
- /* extension code */
- currentByte = JpegDecGetByte(&(PTR_JPGC->stream));
- PTR_JPGC->stream.appnFlag = 0;
- if(currentByte != JPEGDEC_THUMBNAIL_JPEG)
- {
- JPEGDEC_API_TRC(("JpegDecDecode# ERROR: thumbnail unsupported"));
- return (JPEGDEC_UNSUPPORTED);
- }
- /* thumbnail mode */
- JPEGDEC_API_TRC("JpegDecDecode# Thumbnail data ok!");
- PTR_JPGC->stream.thumbnail = 1;
- break;
- }
- else
- {
- /* Flush unsupported thumbnail */
- currentBytes = JpegDecGet2Bytes(&(PTR_JPGC->stream));
- PTR_JPGC->stream.appnFlag = 1;
- if(JpegDecFlushBits
- (&(PTR_JPGC->stream),
- ((currentBytes - 2) * 8)) == STRM_ERROR)
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Stream error");
- return (JPEGDEC_STRM_ERROR);
- }
- PTR_JPGC->stream.appnFlag = 0;
- break;
- }
- case APP1:
- case APP2:
- case APP3:
- case APP4:
- case APP5:
- case APP6:
- case APP7:
- case APP8:
- case APP9:
- case APP10:
- case APP11:
- case APP12:
- case APP13:
- case APP14:
- case APP15:
- case COM:
- JPEGDEC_API_TRC("JpegDecDecode# COM");
- currentBytes = JpegDecGet2Bytes(&(PTR_JPGC->stream));
- if(currentBytes == STRM_ERROR)
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR: Read bits ");
- return (JPEGDEC_STRM_ERROR);
- }
- /* jump over not supported header */
- if(currentBytes != 0)
- {
- PTR_JPGC->stream.readBits += ((currentBytes * 8) - 16);
- PTR_JPGC->stream.pCurrPos +=
- (((currentBytes * 8) - 16) / 8);
- }
- break;
- default:
- break;
- }
- }
- else
- {
- if(currentByte == 0xFFFFFFFF)
- {
- break;
- }
- }
- if(PTR_JPGC->image.headerReady)
- break;
- }
- while((PTR_JPGC->stream.readBits >> 3) <= PTR_JPGC->stream.streamLength);
- retCode = JPEGDEC_OK;
- /* Handle decoded image here */
- if(PTR_JPGC->image.headerReady)
- {
- /* loop until decoding control should return for user */
- do
- {
- /* if pp enabled ==> set pp control */
- if(PTR_JPGC->ppInstance != NULL)
- {
- PTR_JPGC->ppConfigQuery.tiledMode = 0;
- PTR_JPGC->PPConfigQuery(PTR_JPGC->ppInstance,
- &PTR_JPGC->ppConfigQuery);
- PTR_JPGC->ppControl.usePipeline =
- PTR_JPGC->ppConfigQuery.pipelineAccepted;
- /* set pp for combined mode */
- if(PTR_JPGC->ppControl.usePipeline)
- JpegDecPreparePp(PTR_JPGC);
- }
- /* check if we had to load imput buffer or not */
- if(!PTR_JPGC->info.inputBufferEmpty)
- {
- /* if slice mode ==> set slice height */
- if(PTR_JPGC->info.sliceMbSetValue &&
- PTR_JPGC->ppControl.usePipeline == 0)
- {
- JpegDecSliceSizeCalculation(PTR_JPGC);
- }
- /* Start HW or continue after pause */
- if(!PTR_JPGC->info.SliceReadyForPause)
- {
- if(!PTR_JPGC->info.progressiveScanReady ||
- PTR_JPGC->info.nonInterleavedScanReady)
- {
- JPEGDEC_API_TRC("JpegDecDecode# Start HW init\n");
- retCode = JpegDecInitHW(PTR_JPGC);
- PTR_JPGC->info.nonInterleavedScanReady = 0;
- if(retCode != JPEGDEC_OK)
- {
- /* return JPEGDEC_HW_RESERVED */
- return retCode;
- }
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# Continue HW decoding after progressive scan ready\n");
- JpegDecInitHWProgressiveContinue(PTR_JPGC);
- PTR_JPGC->info.progressiveScanReady = 0;
- }
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# Continue HW decoding after slice ready\n");
- JpegDecInitHWContinue(PTR_JPGC);
- }
- PTR_JPGC->info.SliceCount++;
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# Continue HW decoding after input buffer has been loaded\n");
- JpegDecInitHWInputBuffLoad(PTR_JPGC);
- /* buffer loaded ==> reset flag */
- PTR_JPGC->info.inputBufferEmpty = 0;
- }
- #ifdef JPEGDEC_PERFORMANCE
- dwlret = DWL_HW_WAIT_OK;
- #else
- /* wait hw ready */
- dwlret = DWLWaitHwReady(PTR_JPGC->dwl, PTR_JPGC->info.timeout);
- #endif /* #ifdef JPEGDEC_PERFORMANCE */
- /* Refresh regs */
- JpegRefreshRegs(PTR_JPGC);
- if(dwlret == DWL_HW_WAIT_OK)
- {
- JPEGDEC_API_TRC("JpegDecDecode# DWL_HW_WAIT_OK");
- #ifdef JPEGDEC_ASIC_TRACE
- {
- JPEGDEC_TRACE_INTERNAL(("\nJpegDecDecode# AFTER DWL_HW_WAIT_OK\n"));
- PrintJPEGReg(PTR_JPGC->jpegRegs);
- }
- #endif /* #ifdef JPEGDEC_ASIC_TRACE */
- /* check && reset status */
- asic_status =
- GetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_IRQ_STAT);
- if(asic_status & JPEGDEC_X170_IRQ_BUS_ERROR)
- {
- /* check PP status... and go */
- if(PTR_JPGC->ppInstance != NULL)
- {
- /* End PP co-operation */
- if(PTR_JPGC->ppControl.ppStatus == DECPP_RUNNING)
- {
- JPEGDEC_API_TRC("JpegDecDecode# PP END CALL");
- PTR_JPGC->PPEndCallback(PTR_JPGC->ppInstance);
- PTR_JPGC->ppControl.ppStatus = DECPP_PIC_READY;
- }
- }
- JPEGDEC_API_TRC
- ("JpegDecDecode# JPEGDEC_X170_IRQ_BUS_ERROR");
- /* clear interrupts */
- JPEGDEC_CLEAR_IRQ;
- DWLDisableHW(PTR_JPGC->dwl, 4 * 1, PTR_JPGC->jpegRegs[1]);
- /* Release HW */
- (void) DWLReleaseHw(PTR_JPGC->dwl);
- /* update asicRunning */
- PTR_JPGC->asicRunning = 0;
- return JPEGDEC_HW_BUS_ERROR;
- }
- else if(asic_status & JPEGDEC_X170_IRQ_STREAM_ERROR ||
- asic_status & JPEGDEC_X170_IRQ_TIMEOUT)
- {
- /* check PP status... and go */
- if(PTR_JPGC->ppInstance != NULL)
- {
- /* End PP co-operation */
- if(PTR_JPGC->ppControl.ppStatus == DECPP_RUNNING)
- {
- JPEGDEC_API_TRC("JpegDecDecode# PP END CALL");
- PTR_JPGC->PPEndCallback(PTR_JPGC->ppInstance);
- }
- PTR_JPGC->ppControl.ppStatus = DECPP_PIC_READY;
- }
- if(asic_status & JPEGDEC_X170_IRQ_STREAM_ERROR)
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# JPEGDEC_X170_IRQ_STREAM_ERROR");
- }
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# JPEGDEC_X170_IRQ_TIMEOUT");
- }
- /* clear interrupts */
- JPEGDEC_CLEAR_IRQ;
- DWLDisableHW(PTR_JPGC->dwl, 4 * 1, PTR_JPGC->jpegRegs[1]);
- /* Release HW */
- (void) DWLReleaseHw(PTR_JPGC->dwl);
- /* update asicRunning */
- PTR_JPGC->asicRunning = 0;
- /* output set */
- if(PTR_JPGC->ppInstance == NULL)
- {
- pDecOut->outputPictureY.pVirtualAddress =
- PTR_JPGC->info.outLuma.virtualAddress;
- ASSERT(pDecOut->outputPictureY.pVirtualAddress);
- /* output set */
- pDecOut->outputPictureY.busAddress =
- PTR_JPGC->info.outLuma.busAddress;
- ASSERT(pDecOut->outputPictureY.busAddress);
- /* if not grayscale */
- if(PTR_JPGC->image.sizeChroma)
- {
- pDecOut->outputPictureCbCr.pVirtualAddress =
- PTR_JPGC->info.outChroma.virtualAddress;
- ASSERT(pDecOut->outputPictureCbCr.pVirtualAddress);
- pDecOut->outputPictureCbCr.busAddress =
- PTR_JPGC->info.outChroma.busAddress;
- ASSERT(pDecOut->outputPictureCbCr.busAddress);
- pDecOut->outputPictureCr.pVirtualAddress =
- PTR_JPGC->info.outChroma2.virtualAddress;
- pDecOut->outputPictureCr.busAddress =
- PTR_JPGC->info.outChroma2.busAddress;
- }
- }
- return JPEGDEC_STRM_ERROR;
- }
- else if(asic_status & JPEGDEC_X170_IRQ_BUFFER_EMPTY)
- {
- /* check if frame is ready */
- if(!(asic_status & JPEGDEC_X170_IRQ_DEC_RDY))
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# JPEGDEC_X170_IRQ_BUFFER_EMPTY/STREAM PROCESSED");
- /* clear interrupts */
- SetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_BUFFER_INT,
- 0);
- /* flag to load buffer */
- PTR_JPGC->info.inputBufferEmpty = 1;
- /* check if all stream should be processed with the
- * next buffer ==> may affect to some API checks */
- if((PTR_JPGC->info.decodedStreamLen +
- PTR_JPGC->info.inputBufferLen) >=
- PTR_JPGC->stream.streamLength)
- {
- PTR_JPGC->info.streamEndFlag = 1;
- }
- /* output set */
- if(PTR_JPGC->ppInstance == NULL)
- {
- pDecOut->outputPictureY.pVirtualAddress =
- PTR_JPGC->info.outLuma.virtualAddress;
- ASSERT(pDecOut->outputPictureY.pVirtualAddress);
- /* output set */
- pDecOut->outputPictureY.busAddress =
- PTR_JPGC->info.outLuma.busAddress;
- ASSERT(pDecOut->outputPictureY.busAddress);
- /* if not grayscale */
- if(PTR_JPGC->image.sizeChroma)
- {
- pDecOut->outputPictureCbCr.pVirtualAddress =
- PTR_JPGC->info.outChroma.virtualAddress;
- ASSERT(pDecOut->outputPictureCbCr.
- pVirtualAddress);
- pDecOut->outputPictureCbCr.busAddress =
- PTR_JPGC->info.outChroma.busAddress;
- ASSERT(pDecOut->outputPictureCbCr.busAddress);
- pDecOut->outputPictureCr.pVirtualAddress =
- PTR_JPGC->info.outChroma2.virtualAddress;
- pDecOut->outputPictureCr.busAddress =
- PTR_JPGC->info.outChroma2.busAddress;
- }
- }
- return JPEGDEC_STRM_PROCESSED;
- }
- }
- SetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_RDY_INT, 0);
- HINTdec = GetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_IRQ);
- if(HINTdec)
- {
- JPEGDEC_API_TRC("JpegDecDecode# CLEAR interrupt");
- SetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_IRQ, 0);
- }
- /* check if slice ready */
- asicSliceBit = GetDecRegister(PTR_JPGC->jpegRegs,
- HWIF_JPEG_SLICE_H);
- intDec = GetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_SLICE_INT);
- /* slice ready ==> reset interrupt */
- if(asicSliceBit && intDec)
- {
- /* if x170 pp not in use */
- if(PTR_JPGC->ppInstance == NULL)
- PTR_JPGC->info.SliceReadyForPause = 1;
- else
- PTR_JPGC->info.SliceReadyForPause = 0;
- if(PTR_JPGC->ppInstance != NULL &&
- !PTR_JPGC->ppControl.usePipeline)
- {
- PTR_JPGC->info.SliceReadyForPause = 1;
- }
- /* if user allocated memory return given base */
- if(PTR_JPGC->info.userAllocMem == 1 &&
- PTR_JPGC->info.SliceReadyForPause == 1)
- {
- /* output addresses */
- pDecOut->outputPictureY.pVirtualAddress =
- PTR_JPGC->info.givenOutLuma.virtualAddress;
- pDecOut->outputPictureY.busAddress =
- PTR_JPGC->info.givenOutLuma.busAddress;
- if(PTR_JPGC->image.sizeChroma)
- {
- pDecOut->outputPictureCbCr.pVirtualAddress =
- PTR_JPGC->info.givenOutChroma.virtualAddress;
- pDecOut->outputPictureCbCr.busAddress =
- PTR_JPGC->info.givenOutChroma.busAddress;
- pDecOut->outputPictureCr.pVirtualAddress =
- PTR_JPGC->info.givenOutChroma2.virtualAddress;
- pDecOut->outputPictureCr.busAddress =
- PTR_JPGC->info.givenOutChroma2.busAddress;
- }
- }
- /* if not user allocated memory return slice base */
- if(PTR_JPGC->info.userAllocMem == 0 &&
- PTR_JPGC->info.SliceReadyForPause == 1)
- {
- /* output addresses */
- pDecOut->outputPictureY.pVirtualAddress =
- PTR_JPGC->info.outLuma.virtualAddress;
- pDecOut->outputPictureY.busAddress =
- PTR_JPGC->info.outLuma.busAddress;
- if(PTR_JPGC->image.sizeChroma)
- {
- pDecOut->outputPictureCbCr.pVirtualAddress =
- PTR_JPGC->info.outChroma.virtualAddress;
- pDecOut->outputPictureCbCr.busAddress =
- PTR_JPGC->info.outChroma.busAddress;
- pDecOut->outputPictureCr.pVirtualAddress =
- PTR_JPGC->info.outChroma2.virtualAddress;
- pDecOut->outputPictureCr.busAddress =
- PTR_JPGC->info.outChroma2.busAddress;
- }
- }
- /* No slice output in case decoder + PP (no pipeline) */
- if(PTR_JPGC->ppInstance != NULL &&
- PTR_JPGC->ppControl.usePipeline == 0)
- {
- /* output addresses */
- pDecOut->outputPictureY.pVirtualAddress = NULL;
- pDecOut->outputPictureY.busAddress = 0;
- if(PTR_JPGC->image.sizeChroma)
- {
- pDecOut->outputPictureCbCr.pVirtualAddress = NULL;
- pDecOut->outputPictureCbCr.busAddress = 0;
- pDecOut->outputPictureCr.pVirtualAddress = NULL;
- pDecOut->outputPictureCr.busAddress = 0;
- }
- JPEGDEC_API_TRC(("JpegDecDecode# Decoder + PP (Rotation/Flip), Slice ready"));
- /* PP not in pipeline, continue do <==> while */
- PTR_JPGC->info.noSliceIrqForUser = 1;
- }
- else
- {
- JPEGDEC_API_TRC(("JpegDecDecode# Slice ready"));
- return JPEGDEC_SLICE_READY;
- }
- }
- else
- {
- if(PTR_JPGC->info.operationType == JPEGDEC_PROGRESSIVE ||
- PTR_JPGC->info.operationType == JPEGDEC_NONINTERLEAVED)
- {
- currentPos =
- GetDecRegister(PTR_JPGC->jpegRegs,
- HWIF_RLC_VLC_BASE);
- /* update input buffer address */
- PTR_JPGC->stream.pCurrPos = ((u8 *) currentPos - 10);
- PTR_JPGC->stream.bitPosInByte = 0;
- PTR_JPGC->stream.readBits =
- ((PTR_JPGC->stream.pCurrPos -
- PTR_JPGC->stream.pStartOfStream) * 8);
- /* default if data ends */
- endOfImage = 1;
- /* check if last scan is decoded */
- for(i = 0;
- i <
- ((PTR_JPGC->stream.streamLength -
- (PTR_JPGC->stream.readBits / 8))); i++)
- {
- currentByte = PTR_JPGC->stream.pCurrPos[i];
- if(currentByte == 0xFF)
- {
- currentByte = PTR_JPGC->stream.pCurrPos[i + 1];
- if(currentByte == 0xD9)
- {
- endOfImage = 1;
- break;
- }
- else if(currentByte == 0xC4 ||
- currentByte == 0xDA)
- {
- endOfImage = 0;
- break;
- }
- }
- }
- currentByte = 0;
- PTR_JPGC->info.SliceCount = 0;
- PTR_JPGC->info.SliceReadyForPause = 0;
- /* if not the last scan of the stream */
- if(endOfImage == 0)
- {
- /* output set */
- if(PTR_JPGC->ppInstance == NULL &&
- !PTR_JPGC->info.noSliceIrqForUser)
- {
- pDecOut->outputPictureY.pVirtualAddress =
- PTR_JPGC->info.outLuma.virtualAddress;
- ASSERT(pDecOut->outputPictureY.pVirtualAddress);
- /* output set */
- pDecOut->outputPictureY.busAddress =
- PTR_JPGC->info.outLuma.busAddress;
- ASSERT(pDecOut->outputPictureY.busAddress);
- /* if not grayscale */
- if(PTR_JPGC->image.sizeChroma)
- {
- pDecOut->outputPictureCbCr.pVirtualAddress =
- PTR_JPGC->info.outChroma.virtualAddress;
- ASSERT(pDecOut->outputPictureCbCr.
- pVirtualAddress);
- pDecOut->outputPictureCbCr.busAddress =
- PTR_JPGC->info.outChroma.busAddress;
- ASSERT(pDecOut->outputPictureCbCr.
- busAddress);
- pDecOut->outputPictureCr.pVirtualAddress =
- PTR_JPGC->info.outChroma2.
- virtualAddress;
- pDecOut->outputPictureCr.busAddress =
- PTR_JPGC->info.outChroma2.busAddress;
- }
- }
- /* PP not in pipeline, continue do <==> while */
- PTR_JPGC->info.noSliceIrqForUser = 0;
- if(PTR_JPGC->info.operationType ==
- JPEGDEC_PROGRESSIVE)
- PTR_JPGC->info.progressiveScanReady = 1;
- else
- PTR_JPGC->info.nonInterleavedScanReady = 1;
- /* return control to application if progressive */
- if(PTR_JPGC->info.operationType !=
- JPEGDEC_NONINTERLEAVED)
- {
- /* non-interleaved scan ==> no output */
- if(PTR_JPGC->info.nonInterleaved == 0)
- PTR_JPGC->info.noSliceIrqForUser = 1;
- else
- {
- JPEGDEC_API_TRC
- ("JpegDecDecode# SCAN PROCESSED");
- return (JPEGDEC_SCAN_PROCESSED);
- }
- }
- else
- {
- /* set decoded component */
- PTR_JPGC->info.components[PTR_JPGC->info.
- componentId] = 1;
- /* check if we have decoded all components */
- if(PTR_JPGC->info.components[0] == 1 &&
- PTR_JPGC->info.components[1] == 1 &&
- PTR_JPGC->info.components[2] == 1)
- {
- /* continue decoding next scan */
- PTR_JPGC->info.noSliceIrqForUser = 0;
- nonInterleavedRdy = 0;
- }
- else
- {
- /* continue decoding next scan */
- PTR_JPGC->info.noSliceIrqForUser = 1;
- nonInterleavedRdy = 0;
- }
- }
- }
- else
- {
- if(PTR_JPGC->info.operationType ==
- JPEGDEC_NONINTERLEAVED)
- {
- /* set decoded component */
- PTR_JPGC->info.components[PTR_JPGC->info.
- componentId] = 1;
- /* check if we have decoded all components */
- if(PTR_JPGC->info.components[0] == 1 &&
- PTR_JPGC->info.components[1] == 1 &&
- PTR_JPGC->info.components[2] == 1)
- {
- /* continue decoding next scan */
- PTR_JPGC->info.noSliceIrqForUser = 0;
- nonInterleavedRdy = 1;
- }
- else
- {
- /* continue decoding next scan */
- PTR_JPGC->info.noSliceIrqForUser = 1;
- nonInterleavedRdy = 0;
- }
- }
- }
- }
- else
- {
- /* PP not in pipeline, continue do <==> while */
- PTR_JPGC->info.noSliceIrqForUser = 0;
- }
- }
- /* check PP status... and go */
- if(PTR_JPGC->ppInstance != NULL &&
- !PTR_JPGC->info.noSliceIrqForUser)
- {
- /* set pp for stand alone */
- if(!PTR_JPGC->ppControl.usePipeline)
- {
- JpegDecPreparePp(PTR_JPGC);
- JPEGDEC_TRACE_INTERNAL(("INTERNAL: Set output write disabled\n"));
- SetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_OUT_DIS, 1);
- /* Enable pp */
- JPEGDEC_TRACE_INTERNAL(("INTERNAL: Set Enable pp\n"));
- PTR_JPGC->PPRun(PTR_JPGC->ppInstance,
- &PTR_JPGC->ppControl);
- PTR_JPGC->ppControl.ppStatus = DECPP_RUNNING;
- PTR_JPGC->info.pipeline = 1;
- /* Flush regs to hw register */
- JpegFlushRegs(PTR_JPGC);
- }
- /* End PP co-operation */
- if(PTR_JPGC->ppControl.ppStatus == DECPP_RUNNING)
- {
- JPEGDEC_API_TRC("JpegDecDecode# PP END CALL");
- PTR_JPGC->PPEndCallback(PTR_JPGC->ppInstance);
- }
- PTR_JPGC->ppControl.ppStatus = DECPP_PIC_READY;
- }
- /* output set */
- if(PTR_JPGC->ppInstance == NULL &&
- !PTR_JPGC->info.noSliceIrqForUser)
- {
- pDecOut->outputPictureY.pVirtualAddress =
- PTR_JPGC->info.outLuma.virtualAddress;
- ASSERT(pDecOut->outputPictureY.pVirtualAddress);
- /* output set */
- pDecOut->outputPictureY.busAddress =
- PTR_JPGC->info.outLuma.busAddress;
- ASSERT(pDecOut->outputPictureY.busAddress);
- /* if not grayscale */
- if(PTR_JPGC->image.sizeChroma)
- {
- pDecOut->outputPictureCbCr.pVirtualAddress =
- PTR_JPGC->info.outChroma.virtualAddress;
- ASSERT(pDecOut->outputPictureCbCr.pVirtualAddress);
- pDecOut->outputPictureCbCr.busAddress =
- PTR_JPGC->info.outChroma.busAddress;
- ASSERT(pDecOut->outputPictureCbCr.busAddress);
- pDecOut->outputPictureCr.pVirtualAddress =
- PTR_JPGC->info.outChroma2.virtualAddress;
- pDecOut->outputPictureCr.busAddress =
- PTR_JPGC->info.outChroma2.busAddress;
- }
- }
- #ifdef JPEGDEC_ASIC_TRACE
- {
- JPEGDEC_TRACE_INTERNAL(("\nJpegDecDecode# TEST\n"));
- PrintJPEGReg(PTR_JPGC->jpegRegs);
- }
- #endif /* #ifdef JPEGDEC_ASIC_TRACE */
- if(PTR_JPGC->info.noSliceIrqForUser == 0)
- {
- /* Release HW */
- (void) DWLReleaseHw(PTR_JPGC->dwl);
- /* update asicRunning */
- PTR_JPGC->asicRunning = 0;
- JPEGDEC_API_TRC("JpegDecDecode# FRAME READY");
- /* set image ready */
- PTR_JPGC->image.imageReady = 1;
- PTR_JPGC->info.noSliceIrqForUser = 0;
- }
- /* get the current stream address */
- if(PTR_JPGC->info.operationType == JPEGDEC_PROGRESSIVE ||
- (PTR_JPGC->info.operationType == JPEGDEC_NONINTERLEAVED &&
- nonInterleavedRdy == 0))
- {
- retCode = JpegDecNextScanHdrs(PTR_JPGC);
- if(retCode != JPEGDEC_OK && retCode != JPEGDEC_FRAME_READY)
- {
- /* return */
- return retCode;
- }
- }
- }
- else if(dwlret == DWL_HW_WAIT_TIMEOUT)
- {
- JPEGDEC_API_TRC("SCAN: DWL HW TIMEOUT\n");
- /* Release HW */
- (void) DWLReleaseHw(PTR_JPGC->dwl);
- /* update asicRunning */
- PTR_JPGC->asicRunning = 0;
- return (JPEGDEC_DWL_HW_TIMEOUT);
- }
- else if(dwlret == DWL_HW_WAIT_ERROR)
- {
- JPEGDEC_API_TRC("SCAN: DWL HW ERROR\n");
- /* Release HW */
- (void) DWLReleaseHw(PTR_JPGC->dwl);
- /* update asicRunning */
- PTR_JPGC->asicRunning = 0;
- return (JPEGDEC_SYSTEM_ERROR);
- }
- }
- while(!PTR_JPGC->image.imageReady);
- }
- if(PTR_JPGC->image.imageReady)
- {
- JPEGDEC_API_TRC("JpegDecDecode# IMAGE READY");
- JPEGDEC_API_TRC("JpegDecDecode# OK\n");
- /* reset image status */
- PTR_JPGC->image.imageReady = 0;
- PTR_JPGC->image.headerReady = 0;
- if(PTR_JPGC->info.operationType == JPEGDEC_BASELINE)
- {
- return (JPEGDEC_FRAME_READY);
- }
- else
- {
- if(endOfImage == 0)
- return (JPEGDEC_SCAN_PROCESSED);
- else
- {
- if(PTR_JPGC->frame.Nf != 1)
- {
- /* determine first component that needs to be cheated */
- i = 0;
- while(i < 3 && PTR_JPGC->info.pfNeeded[i] == 0)
- i++;
- if(i == 3)
- return (JPEGDEC_FRAME_READY);
- JpegDecInitHWEmptyScan(PTR_JPGC, i++);
- dwlret = DWLWaitHwReady(PTR_JPGC->dwl,
- PTR_JPGC->info.timeout);
- ASSERT(dwlret == DWL_HW_WAIT_OK);
- JpegRefreshRegs(PTR_JPGC);
- asic_status =
- GetDecRegister(PTR_JPGC->jpegRegs, HWIF_DEC_IRQ_STAT);
- ASSERT(asic_status == 1);
- while(i < 3 && PTR_JPGC->info.pfNeeded[i] == 0)
- i++;
- if(i == 3)
- return (JPEGDEC_FRAME_READY);
- else
- {
- PTR_JPGC->info.progressiveFinish = 1;
- PTR_JPGC->info.pfCompId = i;
- return (JPEGDEC_SCAN_PROCESSED);
- }
- }
- else
- return (JPEGDEC_FRAME_READY);
- }
- }
- }
- else
- {
- JPEGDEC_API_TRC("JpegDecDecode# ERROR\n");
- return (JPEGDEC_ERROR);
- }
- #undef JPG_FRM
- #undef PTR_JPGC
- #undef PTR_INFO
- }
- /*------------------------------------------------------------------------------
- Function name: JpegDecPreparePp
- Functional description:
- Setup PP interface
- Input:
- container
- Return values:
- void
- ------------------------------------------------------------------------------*/
- static void JpegDecPreparePp(JpegDecContainer * pJpegDecCont)
- {
- pJpegDecCont->ppControl.picStruct = 0;
- pJpegDecCont->ppControl.topField = 0;
- {
- u32 tmp = GetDecRegister(pJpegDecCont->jpegRegs, HWIF_DEC_OUT_ENDIAN);
- pJpegDecCont->ppControl.littleEndian =
- (tmp == DEC_X170_LITTLE_ENDIAN) ? 1 : 0;
- }
- pJpegDecCont->ppControl.wordSwap = GetDecRegister(pJpegDecCont->jpegRegs,
- HWIF_DEC_OUTSWAP32_E) ? 1
- : 0;
- /* pipeline */
- if(pJpegDecCont->ppControl.usePipeline)
- {
- /* luma */
- pJpegDecCont->ppControl.inputBusLuma = 0;
- /* chroma */
- pJpegDecCont->ppControl.inputBusChroma = 0;
- }
- else
- {
- /* luma */
- pJpegDecCont->ppControl.inputBusLuma =
- pJpegDecCont->asicBuff.outLumaBuffer.busAddress;
- /* chroma */
- pJpegDecCont->ppControl.inputBusChroma =
- pJpegDecCont->asicBuff.outChromaBuffer.busAddress;
- }
- /* dimensions */
- pJpegDecCont->ppControl.inwidth =
- pJpegDecCont->ppControl.croppedW = pJpegDecCont->info.X;
- pJpegDecCont->ppControl.inheight =
- pJpegDecCont->ppControl.croppedH = pJpegDecCont->info.Y;
- }
- /*------------------------------------------------------------------------------
- 5.6. Function name: JpegGetAPIVersion
- Purpose: Returns version information about this API
- Input: void
- Output: JpegDecApiVersion
- ------------------------------------------------------------------------------*/
- JpegDecApiVersion JpegGetAPIVersion()
- {
- JpegDecApiVersion ver;
- ver.major = JPG_MAJOR_VERSION;
- ver.minor = JPG_MINOR_VERSION;
- JPEGDEC_API_TRC("JpegGetAPIVersion# OK\n");
- return ver;
- }
- /*------------------------------------------------------------------------------
- 5.7. Function name: JpegDecGetBuild
- Purpose: Returns the SW and HW build information
- Input: void
- Output: JpegDecGetBuild
- ------------------------------------------------------------------------------*/
- JpegDecBuild JpegDecGetBuild(void)
- {
- JpegDecBuild ver;
- DWLHwConfig_t hwCfg;
- DWLmemset(&ver, 0, sizeof(ver));
- ver.swBuild = JPG_SW_BUILD;
- ver.hwBuild = DWLReadAsicID();
- DWLReadAsicConfig(&hwCfg);
- SET_DEC_BUILD_SUPPORT(ver.hwConfig, hwCfg);
- JPEGDEC_API_TRC("JpegDecGetBuild# OK\n");
- return (ver);
- }
- /*------------------------------------------------------------------------------
- 5.8. Function name : jpegRegisterPP
- Description : Called internally by PP to enable the pipeline
- Return type : i32 - return 0 for success or a negative error code
- Argument : const void * decInst - decoder instance
- Argument : const void *ppInst - post-processor instance
- Argument : (*PPRun)(const void *) - decoder calls this to start PP
- Argument : void (*PPEndCallback)(const void *) - decoder calls this
- to notify PP that a picture was done.
- ------------------------------------------------------------------------------*/
- i32 jpegRegisterPP(const void *decInst, const void *ppInst,
- void (*PPRun) (const void *, DecPpInterface *),
- void (*PPEndCallback) (const void *),
- void (*PPConfigQuery) (const void *, DecPpQuery *))
- {
- JpegDecContainer *pDecCont;
- pDecCont = (JpegDecContainer *) decInst;
- if(decInst == NULL || pDecCont->ppInstance != NULL ||
- ppInst == NULL || PPRun == NULL || PPEndCallback == NULL)
- return -1;
- if(pDecCont->asicRunning)
- return -2;
- pDecCont->ppInstance = ppInst;
- pDecCont->PPEndCallback = PPEndCallback;
- pDecCont->PPRun = PPRun;
- pDecCont->PPConfigQuery = PPConfigQuery;
- return 0;
- }
- /*------------------------------------------------------------------------------
- 5.9. Function name : jpegUnregisterPP
- Description : Called internally by PP to disable the pipeline
- Return type : i32 - return 0 for success or a negative error code
- Argument : const void * decInst - decoder instance
- Argument : const void *ppInst - post-processor instance
- ------------------------------------------------------------------------------*/
- i32 jpegUnregisterPP(const void *decInst, const void *ppInst)
- {
- JpegDecContainer *pDecCont;
- pDecCont = (JpegDecContainer *) decInst;
- ASSERT(decInst != NULL && ppInst == pDecCont->ppInstance);
- if(decInst == NULL || ppInst != pDecCont->ppInstance)
- return -1;
- if(pDecCont->asicRunning)
- return -2;
- pDecCont->ppInstance = NULL;
- pDecCont->PPEndCallback = NULL;
- pDecCont->PPRun = NULL;
- return 0;
- }
|