jfdctint.c 155 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416
  1. /*
  2. * jfdctint.c
  3. *
  4. * Copyright (C) 1991-1996, Thomas G. Lane.
  5. * Modification developed 2003-2018 by Guido Vollbeding.
  6. * This file is part of the Independent JPEG Group's software.
  7. * For conditions of distribution and use, see the accompanying README file.
  8. *
  9. * This file contains a slow-but-accurate integer implementation of the
  10. * forward DCT (Discrete Cosine Transform).
  11. *
  12. * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
  13. * on each column. Direct algorithms are also available, but they are
  14. * much more complex and seem not to be any faster when reduced to code.
  15. *
  16. * This implementation is based on an algorithm described in
  17. * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
  18. * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
  19. * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
  20. * The primary algorithm described there uses 11 multiplies and 29 adds.
  21. * We use their alternate method with 12 multiplies and 32 adds.
  22. * The advantage of this method is that no data path contains more than one
  23. * multiplication; this allows a very simple and accurate implementation in
  24. * scaled fixed-point arithmetic, with a minimal number of shifts.
  25. *
  26. * We also provide FDCT routines with various input sample block sizes for
  27. * direct resolution reduction or enlargement and for direct resolving the
  28. * common 2x1 and 1x2 subsampling cases without additional resampling: NxN
  29. * (N=1...16), 2NxN, and Nx2N (N=1...8) pixels for one 8x8 output DCT block.
  30. *
  31. * For N<8 we fill the remaining block coefficients with zero.
  32. * For N>8 we apply a partial N-point FDCT on the input samples, computing
  33. * just the lower 8 frequency coefficients and discarding the rest.
  34. *
  35. * We must scale the output coefficients of the N-point FDCT appropriately
  36. * to the standard 8-point FDCT level by 8/N per 1-D pass. This scaling
  37. * is folded into the constant multipliers (pass 2) and/or final/initial
  38. * shifting.
  39. *
  40. * CAUTION: We rely on the FIX() macro except for the N=1,2,4,8 cases
  41. * since there would be too many additional constants to pre-calculate.
  42. */
  43. #define JPEG_INTERNALS
  44. #include "jinclude.h"
  45. #include "jpeglib.h"
  46. #include "jdct.h" /* Private declarations for DCT subsystem */
  47. #ifdef DCT_ISLOW_SUPPORTED
  48. /*
  49. * This module is specialized to the case DCTSIZE = 8.
  50. */
  51. #if DCTSIZE != 8
  52. Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
  53. #endif
  54. /*
  55. * The poop on this scaling stuff is as follows:
  56. *
  57. * Each 1-D DCT step produces outputs which are a factor of sqrt(N)
  58. * larger than the true DCT outputs. The final outputs are therefore
  59. * a factor of N larger than desired; since N=8 this can be cured by
  60. * a simple right shift at the end of the algorithm. The advantage of
  61. * this arrangement is that we save two multiplications per 1-D DCT,
  62. * because the y0 and y4 outputs need not be divided by sqrt(N).
  63. * In the IJG code, this factor of 8 is removed by the quantization step
  64. * (in jcdctmgr.c), NOT in this module.
  65. *
  66. * We have to do addition and subtraction of the integer inputs, which
  67. * is no problem, and multiplication by fractional constants, which is
  68. * a problem to do in integer arithmetic. We multiply all the constants
  69. * by CONST_SCALE and convert them to integer constants (thus retaining
  70. * CONST_BITS bits of precision in the constants). After doing a
  71. * multiplication we have to divide the product by CONST_SCALE, with proper
  72. * rounding, to produce the correct output. This division can be done
  73. * cheaply as a right shift of CONST_BITS bits. We postpone shifting
  74. * as long as possible so that partial sums can be added together with
  75. * full fractional precision.
  76. *
  77. * The outputs of the first pass are scaled up by PASS1_BITS bits so that
  78. * they are represented to better-than-integral precision. These outputs
  79. * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
  80. * with the recommended scaling. (For 12-bit sample data, the intermediate
  81. * array is INT32 anyway.)
  82. *
  83. * To avoid overflow of the 32-bit intermediate results in pass 2, we must
  84. * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
  85. * shows that the values given below are the most effective.
  86. */
  87. #if BITS_IN_JSAMPLE == 8
  88. #define CONST_BITS 13
  89. #define PASS1_BITS 2
  90. #else
  91. #define CONST_BITS 13
  92. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  93. #endif
  94. /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
  95. * causing a lot of useless floating-point operations at run time.
  96. * To get around this we use the following pre-calculated constants.
  97. * If you change CONST_BITS you may want to add appropriate values.
  98. * (With a reasonable C compiler, you can just rely on the FIX() macro...)
  99. */
  100. #if CONST_BITS == 13
  101. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  102. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  103. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  104. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  105. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  106. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  107. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  108. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  109. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  110. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  111. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  112. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  113. #else
  114. #define FIX_0_298631336 FIX(0.298631336)
  115. #define FIX_0_390180644 FIX(0.390180644)
  116. #define FIX_0_541196100 FIX(0.541196100)
  117. #define FIX_0_765366865 FIX(0.765366865)
  118. #define FIX_0_899976223 FIX(0.899976223)
  119. #define FIX_1_175875602 FIX(1.175875602)
  120. #define FIX_1_501321110 FIX(1.501321110)
  121. #define FIX_1_847759065 FIX(1.847759065)
  122. #define FIX_1_961570560 FIX(1.961570560)
  123. #define FIX_2_053119869 FIX(2.053119869)
  124. #define FIX_2_562915447 FIX(2.562915447)
  125. #define FIX_3_072711026 FIX(3.072711026)
  126. #endif
  127. /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
  128. * For 8-bit samples with the recommended scaling, all the variable
  129. * and constant values involved are no more than 16 bits wide, so a
  130. * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
  131. * For 12-bit samples, a full 32-bit multiplication will be needed.
  132. */
  133. #if BITS_IN_JSAMPLE == 8
  134. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  135. #else
  136. #define MULTIPLY(var,const) ((var) * (const))
  137. #endif
  138. /*
  139. * Perform the forward DCT on one block of samples.
  140. */
  141. GLOBAL(void)
  142. jpeg_fdct_islow (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  143. {
  144. INT32 tmp0, tmp1, tmp2, tmp3;
  145. INT32 tmp10, tmp11, tmp12, tmp13;
  146. INT32 z1;
  147. DCTELEM *dataptr;
  148. JSAMPROW elemptr;
  149. int ctr;
  150. SHIFT_TEMPS
  151. /* Pass 1: process rows.
  152. * Note results are scaled up by sqrt(8) compared to a true DCT;
  153. * furthermore, we scale the results by 2**PASS1_BITS.
  154. * cK represents sqrt(2) * cos(K*pi/16).
  155. */
  156. dataptr = data;
  157. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  158. elemptr = sample_data[ctr] + start_col;
  159. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  160. * rotator "c1" should be "c6".
  161. */
  162. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);
  163. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);
  164. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);
  165. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);
  166. tmp10 = tmp0 + tmp3;
  167. tmp12 = tmp0 - tmp3;
  168. tmp11 = tmp1 + tmp2;
  169. tmp13 = tmp1 - tmp2;
  170. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);
  171. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);
  172. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);
  173. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);
  174. /* Apply unsigned->signed conversion. */
  175. dataptr[0] = (DCTELEM) ((tmp10 + tmp11 - 8 * CENTERJSAMPLE) << PASS1_BITS);
  176. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  177. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  178. /* Add fudge factor here for final descale. */
  179. z1 += ONE << (CONST_BITS-PASS1_BITS-1);
  180. dataptr[2] = (DCTELEM)
  181. RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  182. CONST_BITS-PASS1_BITS);
  183. dataptr[6] = (DCTELEM)
  184. RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  185. CONST_BITS-PASS1_BITS);
  186. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  187. * i0..i3 in the paper are tmp0..tmp3 here.
  188. */
  189. tmp12 = tmp0 + tmp2;
  190. tmp13 = tmp1 + tmp3;
  191. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  192. /* Add fudge factor here for final descale. */
  193. z1 += ONE << (CONST_BITS-PASS1_BITS-1);
  194. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  195. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  196. tmp12 += z1;
  197. tmp13 += z1;
  198. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  199. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  200. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  201. tmp0 += z1 + tmp12;
  202. tmp3 += z1 + tmp13;
  203. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  204. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  205. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  206. tmp1 += z1 + tmp13;
  207. tmp2 += z1 + tmp12;
  208. dataptr[1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS-PASS1_BITS);
  209. dataptr[3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS-PASS1_BITS);
  210. dataptr[5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS);
  211. dataptr[7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS-PASS1_BITS);
  212. dataptr += DCTSIZE; /* advance pointer to next row */
  213. }
  214. /* Pass 2: process columns.
  215. * We remove the PASS1_BITS scaling, but leave the results scaled up
  216. * by an overall factor of 8.
  217. * cK represents sqrt(2) * cos(K*pi/16).
  218. */
  219. dataptr = data;
  220. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  221. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  222. * rotator "c1" should be "c6".
  223. */
  224. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  225. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  226. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  227. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  228. /* Add fudge factor here for final descale. */
  229. tmp10 = tmp0 + tmp3 + (ONE << (PASS1_BITS-1));
  230. tmp12 = tmp0 - tmp3;
  231. tmp11 = tmp1 + tmp2;
  232. tmp13 = tmp1 - tmp2;
  233. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  234. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  235. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  236. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  237. dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp10 + tmp11, PASS1_BITS);
  238. dataptr[DCTSIZE*4] = (DCTELEM) RIGHT_SHIFT(tmp10 - tmp11, PASS1_BITS);
  239. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  240. /* Add fudge factor here for final descale. */
  241. z1 += ONE << (CONST_BITS+PASS1_BITS-1);
  242. dataptr[DCTSIZE*2] = (DCTELEM)
  243. RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  244. CONST_BITS+PASS1_BITS);
  245. dataptr[DCTSIZE*6] = (DCTELEM)
  246. RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  247. CONST_BITS+PASS1_BITS);
  248. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  249. * i0..i3 in the paper are tmp0..tmp3 here.
  250. */
  251. tmp12 = tmp0 + tmp2;
  252. tmp13 = tmp1 + tmp3;
  253. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  254. /* Add fudge factor here for final descale. */
  255. z1 += ONE << (CONST_BITS+PASS1_BITS-1);
  256. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  257. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  258. tmp12 += z1;
  259. tmp13 += z1;
  260. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  261. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  262. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  263. tmp0 += z1 + tmp12;
  264. tmp3 += z1 + tmp13;
  265. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  266. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  267. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  268. tmp1 += z1 + tmp13;
  269. tmp2 += z1 + tmp12;
  270. dataptr[DCTSIZE*1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS+PASS1_BITS);
  271. dataptr[DCTSIZE*3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS+PASS1_BITS);
  272. dataptr[DCTSIZE*5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS+PASS1_BITS);
  273. dataptr[DCTSIZE*7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS+PASS1_BITS);
  274. dataptr++; /* advance pointer to next column */
  275. }
  276. }
  277. #ifdef DCT_SCALING_SUPPORTED
  278. /*
  279. * Perform the forward DCT on a 7x7 sample block.
  280. */
  281. GLOBAL(void)
  282. jpeg_fdct_7x7 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  283. {
  284. INT32 tmp0, tmp1, tmp2, tmp3;
  285. INT32 tmp10, tmp11, tmp12;
  286. INT32 z1, z2, z3;
  287. DCTELEM *dataptr;
  288. JSAMPROW elemptr;
  289. int ctr;
  290. SHIFT_TEMPS
  291. /* Pre-zero output coefficient block. */
  292. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  293. /* Pass 1: process rows.
  294. * Note results are scaled up by sqrt(8) compared to a true DCT;
  295. * furthermore, we scale the results by 2**PASS1_BITS.
  296. * cK represents sqrt(2) * cos(K*pi/14).
  297. */
  298. dataptr = data;
  299. for (ctr = 0; ctr < 7; ctr++) {
  300. elemptr = sample_data[ctr] + start_col;
  301. /* Even part */
  302. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[6]);
  303. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[5]);
  304. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[4]);
  305. tmp3 = GETJSAMPLE(elemptr[3]);
  306. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[6]);
  307. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[5]);
  308. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[4]);
  309. z1 = tmp0 + tmp2;
  310. /* Apply unsigned->signed conversion. */
  311. dataptr[0] = (DCTELEM)
  312. ((z1 + tmp1 + tmp3 - 7 * CENTERJSAMPLE) << PASS1_BITS);
  313. tmp3 += tmp3;
  314. z1 -= tmp3;
  315. z1 -= tmp3;
  316. z1 = MULTIPLY(z1, FIX(0.353553391)); /* (c2+c6-c4)/2 */
  317. z2 = MULTIPLY(tmp0 - tmp2, FIX(0.920609002)); /* (c2+c4-c6)/2 */
  318. z3 = MULTIPLY(tmp1 - tmp2, FIX(0.314692123)); /* c6 */
  319. dataptr[2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS-PASS1_BITS);
  320. z1 -= z2;
  321. z2 = MULTIPLY(tmp0 - tmp1, FIX(0.881747734)); /* c4 */
  322. dataptr[4] = (DCTELEM)
  323. DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.707106781)), /* c2+c6-c4 */
  324. CONST_BITS-PASS1_BITS);
  325. dataptr[6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS-PASS1_BITS);
  326. /* Odd part */
  327. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(0.935414347)); /* (c3+c1-c5)/2 */
  328. tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.170262339)); /* (c3+c5-c1)/2 */
  329. tmp0 = tmp1 - tmp2;
  330. tmp1 += tmp2;
  331. tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.378756276)); /* -c1 */
  332. tmp1 += tmp2;
  333. tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.613604268)); /* c5 */
  334. tmp0 += tmp3;
  335. tmp2 += tmp3 + MULTIPLY(tmp12, FIX(1.870828693)); /* c3+c1-c5 */
  336. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);
  337. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);
  338. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);
  339. dataptr += DCTSIZE; /* advance pointer to next row */
  340. }
  341. /* Pass 2: process columns.
  342. * We remove the PASS1_BITS scaling, but leave the results scaled up
  343. * by an overall factor of 8.
  344. * We must also scale the output by (8/7)**2 = 64/49, which we fold
  345. * into the constant multipliers:
  346. * cK now represents sqrt(2) * cos(K*pi/14) * 64/49.
  347. */
  348. dataptr = data;
  349. for (ctr = 0; ctr < 7; ctr++) {
  350. /* Even part */
  351. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*6];
  352. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*5];
  353. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*4];
  354. tmp3 = dataptr[DCTSIZE*3];
  355. tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*6];
  356. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*5];
  357. tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*4];
  358. z1 = tmp0 + tmp2;
  359. dataptr[DCTSIZE*0] = (DCTELEM)
  360. DESCALE(MULTIPLY(z1 + tmp1 + tmp3, FIX(1.306122449)), /* 64/49 */
  361. CONST_BITS+PASS1_BITS);
  362. tmp3 += tmp3;
  363. z1 -= tmp3;
  364. z1 -= tmp3;
  365. z1 = MULTIPLY(z1, FIX(0.461784020)); /* (c2+c6-c4)/2 */
  366. z2 = MULTIPLY(tmp0 - tmp2, FIX(1.202428084)); /* (c2+c4-c6)/2 */
  367. z3 = MULTIPLY(tmp1 - tmp2, FIX(0.411026446)); /* c6 */
  368. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS+PASS1_BITS);
  369. z1 -= z2;
  370. z2 = MULTIPLY(tmp0 - tmp1, FIX(1.151670509)); /* c4 */
  371. dataptr[DCTSIZE*4] = (DCTELEM)
  372. DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.923568041)), /* c2+c6-c4 */
  373. CONST_BITS+PASS1_BITS);
  374. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+PASS1_BITS);
  375. /* Odd part */
  376. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.221765677)); /* (c3+c1-c5)/2 */
  377. tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.222383464)); /* (c3+c5-c1)/2 */
  378. tmp0 = tmp1 - tmp2;
  379. tmp1 += tmp2;
  380. tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.800824523)); /* -c1 */
  381. tmp1 += tmp2;
  382. tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.801442310)); /* c5 */
  383. tmp0 += tmp3;
  384. tmp2 += tmp3 + MULTIPLY(tmp12, FIX(2.443531355)); /* c3+c1-c5 */
  385. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS);
  386. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS);
  387. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS);
  388. dataptr++; /* advance pointer to next column */
  389. }
  390. }
  391. /*
  392. * Perform the forward DCT on a 6x6 sample block.
  393. */
  394. GLOBAL(void)
  395. jpeg_fdct_6x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  396. {
  397. INT32 tmp0, tmp1, tmp2;
  398. INT32 tmp10, tmp11, tmp12;
  399. DCTELEM *dataptr;
  400. JSAMPROW elemptr;
  401. int ctr;
  402. SHIFT_TEMPS
  403. /* Pre-zero output coefficient block. */
  404. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  405. /* Pass 1: process rows.
  406. * Note results are scaled up by sqrt(8) compared to a true DCT;
  407. * furthermore, we scale the results by 2**PASS1_BITS.
  408. * cK represents sqrt(2) * cos(K*pi/12).
  409. */
  410. dataptr = data;
  411. for (ctr = 0; ctr < 6; ctr++) {
  412. elemptr = sample_data[ctr] + start_col;
  413. /* Even part */
  414. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);
  415. tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);
  416. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);
  417. tmp10 = tmp0 + tmp2;
  418. tmp12 = tmp0 - tmp2;
  419. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);
  420. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);
  421. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);
  422. /* Apply unsigned->signed conversion. */
  423. dataptr[0] = (DCTELEM)
  424. ((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << PASS1_BITS);
  425. dataptr[2] = (DCTELEM)
  426. DESCALE(MULTIPLY(tmp12, FIX(1.224744871)), /* c2 */
  427. CONST_BITS-PASS1_BITS);
  428. dataptr[4] = (DCTELEM)
  429. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */
  430. CONST_BITS-PASS1_BITS);
  431. /* Odd part */
  432. tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)), /* c5 */
  433. CONST_BITS-PASS1_BITS);
  434. dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << PASS1_BITS));
  435. dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << PASS1_BITS);
  436. dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << PASS1_BITS));
  437. dataptr += DCTSIZE; /* advance pointer to next row */
  438. }
  439. /* Pass 2: process columns.
  440. * We remove the PASS1_BITS scaling, but leave the results scaled up
  441. * by an overall factor of 8.
  442. * We must also scale the output by (8/6)**2 = 16/9, which we fold
  443. * into the constant multipliers:
  444. * cK now represents sqrt(2) * cos(K*pi/12) * 16/9.
  445. */
  446. dataptr = data;
  447. for (ctr = 0; ctr < 6; ctr++) {
  448. /* Even part */
  449. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];
  450. tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];
  451. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
  452. tmp10 = tmp0 + tmp2;
  453. tmp12 = tmp0 - tmp2;
  454. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];
  455. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];
  456. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
  457. dataptr[DCTSIZE*0] = (DCTELEM)
  458. DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)), /* 16/9 */
  459. CONST_BITS+PASS1_BITS);
  460. dataptr[DCTSIZE*2] = (DCTELEM)
  461. DESCALE(MULTIPLY(tmp12, FIX(2.177324216)), /* c2 */
  462. CONST_BITS+PASS1_BITS);
  463. dataptr[DCTSIZE*4] = (DCTELEM)
  464. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */
  465. CONST_BITS+PASS1_BITS);
  466. /* Odd part */
  467. tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829)); /* c5 */
  468. dataptr[DCTSIZE*1] = (DCTELEM)
  469. DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
  470. CONST_BITS+PASS1_BITS);
  471. dataptr[DCTSIZE*3] = (DCTELEM)
  472. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)), /* 16/9 */
  473. CONST_BITS+PASS1_BITS);
  474. dataptr[DCTSIZE*5] = (DCTELEM)
  475. DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)), /* 16/9 */
  476. CONST_BITS+PASS1_BITS);
  477. dataptr++; /* advance pointer to next column */
  478. }
  479. }
  480. /*
  481. * Perform the forward DCT on a 5x5 sample block.
  482. */
  483. GLOBAL(void)
  484. jpeg_fdct_5x5 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  485. {
  486. INT32 tmp0, tmp1, tmp2;
  487. INT32 tmp10, tmp11;
  488. DCTELEM *dataptr;
  489. JSAMPROW elemptr;
  490. int ctr;
  491. SHIFT_TEMPS
  492. /* Pre-zero output coefficient block. */
  493. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  494. /* Pass 1: process rows.
  495. * Note results are scaled up by sqrt(8) compared to a true DCT;
  496. * furthermore, we scale the results by 2**PASS1_BITS.
  497. * We scale the results further by 2 as part of output adaption
  498. * scaling for different DCT size.
  499. * cK represents sqrt(2) * cos(K*pi/10).
  500. */
  501. dataptr = data;
  502. for (ctr = 0; ctr < 5; ctr++) {
  503. elemptr = sample_data[ctr] + start_col;
  504. /* Even part */
  505. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[4]);
  506. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[3]);
  507. tmp2 = GETJSAMPLE(elemptr[2]);
  508. tmp10 = tmp0 + tmp1;
  509. tmp11 = tmp0 - tmp1;
  510. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[4]);
  511. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[3]);
  512. /* Apply unsigned->signed conversion. */
  513. dataptr[0] = (DCTELEM)
  514. ((tmp10 + tmp2 - 5 * CENTERJSAMPLE) << (PASS1_BITS+1));
  515. tmp11 = MULTIPLY(tmp11, FIX(0.790569415)); /* (c2+c4)/2 */
  516. tmp10 -= tmp2 << 2;
  517. tmp10 = MULTIPLY(tmp10, FIX(0.353553391)); /* (c2-c4)/2 */
  518. dataptr[2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS-PASS1_BITS-1);
  519. dataptr[4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS-PASS1_BITS-1);
  520. /* Odd part */
  521. tmp10 = MULTIPLY(tmp0 + tmp1, FIX(0.831253876)); /* c3 */
  522. dataptr[1] = (DCTELEM)
  523. DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.513743148)), /* c1-c3 */
  524. CONST_BITS-PASS1_BITS-1);
  525. dataptr[3] = (DCTELEM)
  526. DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.176250899)), /* c1+c3 */
  527. CONST_BITS-PASS1_BITS-1);
  528. dataptr += DCTSIZE; /* advance pointer to next row */
  529. }
  530. /* Pass 2: process columns.
  531. * We remove the PASS1_BITS scaling, but leave the results scaled up
  532. * by an overall factor of 8.
  533. * We must also scale the output by (8/5)**2 = 64/25, which we partially
  534. * fold into the constant multipliers (other part was done in pass 1):
  535. * cK now represents sqrt(2) * cos(K*pi/10) * 32/25.
  536. */
  537. dataptr = data;
  538. for (ctr = 0; ctr < 5; ctr++) {
  539. /* Even part */
  540. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*4];
  541. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*3];
  542. tmp2 = dataptr[DCTSIZE*2];
  543. tmp10 = tmp0 + tmp1;
  544. tmp11 = tmp0 - tmp1;
  545. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*4];
  546. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*3];
  547. dataptr[DCTSIZE*0] = (DCTELEM)
  548. DESCALE(MULTIPLY(tmp10 + tmp2, FIX(1.28)), /* 32/25 */
  549. CONST_BITS+PASS1_BITS);
  550. tmp11 = MULTIPLY(tmp11, FIX(1.011928851)); /* (c2+c4)/2 */
  551. tmp10 -= tmp2 << 2;
  552. tmp10 = MULTIPLY(tmp10, FIX(0.452548340)); /* (c2-c4)/2 */
  553. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS+PASS1_BITS);
  554. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS+PASS1_BITS);
  555. /* Odd part */
  556. tmp10 = MULTIPLY(tmp0 + tmp1, FIX(1.064004961)); /* c3 */
  557. dataptr[DCTSIZE*1] = (DCTELEM)
  558. DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.657591230)), /* c1-c3 */
  559. CONST_BITS+PASS1_BITS);
  560. dataptr[DCTSIZE*3] = (DCTELEM)
  561. DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.785601151)), /* c1+c3 */
  562. CONST_BITS+PASS1_BITS);
  563. dataptr++; /* advance pointer to next column */
  564. }
  565. }
  566. /*
  567. * Perform the forward DCT on a 4x4 sample block.
  568. */
  569. GLOBAL(void)
  570. jpeg_fdct_4x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  571. {
  572. INT32 tmp0, tmp1;
  573. INT32 tmp10, tmp11;
  574. DCTELEM *dataptr;
  575. JSAMPROW elemptr;
  576. int ctr;
  577. SHIFT_TEMPS
  578. /* Pre-zero output coefficient block. */
  579. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  580. /* Pass 1: process rows.
  581. * Note results are scaled up by sqrt(8) compared to a true DCT;
  582. * furthermore, we scale the results by 2**PASS1_BITS.
  583. * We must also scale the output by (8/4)**2 = 2**2, which we add here.
  584. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  585. */
  586. dataptr = data;
  587. for (ctr = 0; ctr < 4; ctr++) {
  588. elemptr = sample_data[ctr] + start_col;
  589. /* Even part */
  590. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);
  591. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);
  592. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);
  593. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
  594. /* Apply unsigned->signed conversion. */
  595. dataptr[0] = (DCTELEM)
  596. ((tmp0 + tmp1 - 4 * CENTERJSAMPLE) << (PASS1_BITS+2));
  597. dataptr[2] = (DCTELEM) ((tmp0 - tmp1) << (PASS1_BITS+2));
  598. /* Odd part */
  599. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  600. /* Add fudge factor here for final descale. */
  601. tmp0 += ONE << (CONST_BITS-PASS1_BITS-3);
  602. dataptr[1] = (DCTELEM)
  603. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  604. CONST_BITS-PASS1_BITS-2);
  605. dataptr[3] = (DCTELEM)
  606. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  607. CONST_BITS-PASS1_BITS-2);
  608. dataptr += DCTSIZE; /* advance pointer to next row */
  609. }
  610. /* Pass 2: process columns.
  611. * We remove the PASS1_BITS scaling, but leave the results scaled up
  612. * by an overall factor of 8.
  613. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  614. */
  615. dataptr = data;
  616. for (ctr = 0; ctr < 4; ctr++) {
  617. /* Even part */
  618. /* Add fudge factor here for final descale. */
  619. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*3] + (ONE << (PASS1_BITS-1));
  620. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*2];
  621. tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];
  622. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];
  623. dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp0 + tmp1, PASS1_BITS);
  624. dataptr[DCTSIZE*2] = (DCTELEM) RIGHT_SHIFT(tmp0 - tmp1, PASS1_BITS);
  625. /* Odd part */
  626. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  627. /* Add fudge factor here for final descale. */
  628. tmp0 += ONE << (CONST_BITS+PASS1_BITS-1);
  629. dataptr[DCTSIZE*1] = (DCTELEM)
  630. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  631. CONST_BITS+PASS1_BITS);
  632. dataptr[DCTSIZE*3] = (DCTELEM)
  633. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  634. CONST_BITS+PASS1_BITS);
  635. dataptr++; /* advance pointer to next column */
  636. }
  637. }
  638. /*
  639. * Perform the forward DCT on a 3x3 sample block.
  640. */
  641. GLOBAL(void)
  642. jpeg_fdct_3x3 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  643. {
  644. INT32 tmp0, tmp1, tmp2;
  645. DCTELEM *dataptr;
  646. JSAMPROW elemptr;
  647. int ctr;
  648. SHIFT_TEMPS
  649. /* Pre-zero output coefficient block. */
  650. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  651. /* Pass 1: process rows.
  652. * Note results are scaled up by sqrt(8) compared to a true DCT;
  653. * furthermore, we scale the results by 2**PASS1_BITS.
  654. * We scale the results further by 2**2 as part of output adaption
  655. * scaling for different DCT size.
  656. * cK represents sqrt(2) * cos(K*pi/6).
  657. */
  658. dataptr = data;
  659. for (ctr = 0; ctr < 3; ctr++) {
  660. elemptr = sample_data[ctr] + start_col;
  661. /* Even part */
  662. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[2]);
  663. tmp1 = GETJSAMPLE(elemptr[1]);
  664. tmp2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[2]);
  665. /* Apply unsigned->signed conversion. */
  666. dataptr[0] = (DCTELEM)
  667. ((tmp0 + tmp1 - 3 * CENTERJSAMPLE) << (PASS1_BITS+2));
  668. dataptr[2] = (DCTELEM)
  669. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(0.707106781)), /* c2 */
  670. CONST_BITS-PASS1_BITS-2);
  671. /* Odd part */
  672. dataptr[1] = (DCTELEM)
  673. DESCALE(MULTIPLY(tmp2, FIX(1.224744871)), /* c1 */
  674. CONST_BITS-PASS1_BITS-2);
  675. dataptr += DCTSIZE; /* advance pointer to next row */
  676. }
  677. /* Pass 2: process columns.
  678. * We remove the PASS1_BITS scaling, but leave the results scaled up
  679. * by an overall factor of 8.
  680. * We must also scale the output by (8/3)**2 = 64/9, which we partially
  681. * fold into the constant multipliers (other part was done in pass 1):
  682. * cK now represents sqrt(2) * cos(K*pi/6) * 16/9.
  683. */
  684. dataptr = data;
  685. for (ctr = 0; ctr < 3; ctr++) {
  686. /* Even part */
  687. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*2];
  688. tmp1 = dataptr[DCTSIZE*1];
  689. tmp2 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*2];
  690. dataptr[DCTSIZE*0] = (DCTELEM)
  691. DESCALE(MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
  692. CONST_BITS+PASS1_BITS);
  693. dataptr[DCTSIZE*2] = (DCTELEM)
  694. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(1.257078722)), /* c2 */
  695. CONST_BITS+PASS1_BITS);
  696. /* Odd part */
  697. dataptr[DCTSIZE*1] = (DCTELEM)
  698. DESCALE(MULTIPLY(tmp2, FIX(2.177324216)), /* c1 */
  699. CONST_BITS+PASS1_BITS);
  700. dataptr++; /* advance pointer to next column */
  701. }
  702. }
  703. /*
  704. * Perform the forward DCT on a 2x2 sample block.
  705. */
  706. GLOBAL(void)
  707. jpeg_fdct_2x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  708. {
  709. DCTELEM tmp0, tmp1, tmp2, tmp3;
  710. JSAMPROW elemptr;
  711. /* Pre-zero output coefficient block. */
  712. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  713. /* Pass 1: process rows.
  714. * Note results are scaled up by sqrt(8) compared to a true DCT.
  715. */
  716. /* Row 0 */
  717. elemptr = sample_data[0] + start_col;
  718. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[1]);
  719. tmp1 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[1]);
  720. /* Row 1 */
  721. elemptr = sample_data[1] + start_col;
  722. tmp2 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[1]);
  723. tmp3 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[1]);
  724. /* Pass 2: process columns.
  725. * We leave the results scaled up by an overall factor of 8.
  726. * We must also scale the output by (8/2)**2 = 2**4.
  727. */
  728. /* Column 0 */
  729. /* Apply unsigned->signed conversion. */
  730. data[DCTSIZE*0] = (tmp0 + tmp2 - 4 * CENTERJSAMPLE) << 4;
  731. data[DCTSIZE*1] = (tmp0 - tmp2) << 4;
  732. /* Column 1 */
  733. data[DCTSIZE*0+1] = (tmp1 + tmp3) << 4;
  734. data[DCTSIZE*1+1] = (tmp1 - tmp3) << 4;
  735. }
  736. /*
  737. * Perform the forward DCT on a 1x1 sample block.
  738. */
  739. GLOBAL(void)
  740. jpeg_fdct_1x1 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  741. {
  742. DCTELEM dcval;
  743. /* Pre-zero output coefficient block. */
  744. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  745. dcval = GETJSAMPLE(sample_data[0][start_col]);
  746. /* We leave the result scaled up by an overall factor of 8. */
  747. /* We must also scale the output by (8/1)**2 = 2**6. */
  748. /* Apply unsigned->signed conversion. */
  749. data[0] = (dcval - CENTERJSAMPLE) << 6;
  750. }
  751. /*
  752. * Perform the forward DCT on a 9x9 sample block.
  753. */
  754. GLOBAL(void)
  755. jpeg_fdct_9x9 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  756. {
  757. INT32 tmp0, tmp1, tmp2, tmp3, tmp4;
  758. INT32 tmp10, tmp11, tmp12, tmp13;
  759. INT32 z1, z2;
  760. DCTELEM workspace[8];
  761. DCTELEM *dataptr;
  762. DCTELEM *wsptr;
  763. JSAMPROW elemptr;
  764. int ctr;
  765. SHIFT_TEMPS
  766. /* Pass 1: process rows.
  767. * Note results are scaled up by sqrt(8) compared to a true DCT;
  768. * we scale the results further by 2 as part of output adaption
  769. * scaling for different DCT size.
  770. * cK represents sqrt(2) * cos(K*pi/18).
  771. */
  772. dataptr = data;
  773. ctr = 0;
  774. for (;;) {
  775. elemptr = sample_data[ctr] + start_col;
  776. /* Even part */
  777. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[8]);
  778. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[7]);
  779. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[6]);
  780. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[5]);
  781. tmp4 = GETJSAMPLE(elemptr[4]);
  782. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[8]);
  783. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[7]);
  784. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[6]);
  785. tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[5]);
  786. z1 = tmp0 + tmp2 + tmp3;
  787. z2 = tmp1 + tmp4;
  788. /* Apply unsigned->signed conversion. */
  789. dataptr[0] = (DCTELEM) ((z1 + z2 - 9 * CENTERJSAMPLE) << 1);
  790. dataptr[6] = (DCTELEM)
  791. DESCALE(MULTIPLY(z1 - z2 - z2, FIX(0.707106781)), /* c6 */
  792. CONST_BITS-1);
  793. z1 = MULTIPLY(tmp0 - tmp2, FIX(1.328926049)); /* c2 */
  794. z2 = MULTIPLY(tmp1 - tmp4 - tmp4, FIX(0.707106781)); /* c6 */
  795. dataptr[2] = (DCTELEM)
  796. DESCALE(MULTIPLY(tmp2 - tmp3, FIX(1.083350441)) /* c4 */
  797. + z1 + z2, CONST_BITS-1);
  798. dataptr[4] = (DCTELEM)
  799. DESCALE(MULTIPLY(tmp3 - tmp0, FIX(0.245575608)) /* c8 */
  800. + z1 - z2, CONST_BITS-1);
  801. /* Odd part */
  802. dataptr[3] = (DCTELEM)
  803. DESCALE(MULTIPLY(tmp10 - tmp12 - tmp13, FIX(1.224744871)), /* c3 */
  804. CONST_BITS-1);
  805. tmp11 = MULTIPLY(tmp11, FIX(1.224744871)); /* c3 */
  806. tmp0 = MULTIPLY(tmp10 + tmp12, FIX(0.909038955)); /* c5 */
  807. tmp1 = MULTIPLY(tmp10 + tmp13, FIX(0.483689525)); /* c7 */
  808. dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp0 + tmp1, CONST_BITS-1);
  809. tmp2 = MULTIPLY(tmp12 - tmp13, FIX(1.392728481)); /* c1 */
  810. dataptr[5] = (DCTELEM) DESCALE(tmp0 - tmp11 - tmp2, CONST_BITS-1);
  811. dataptr[7] = (DCTELEM) DESCALE(tmp1 - tmp11 + tmp2, CONST_BITS-1);
  812. ctr++;
  813. if (ctr != DCTSIZE) {
  814. if (ctr == 9)
  815. break; /* Done. */
  816. dataptr += DCTSIZE; /* advance pointer to next row */
  817. } else
  818. dataptr = workspace; /* switch pointer to extended workspace */
  819. }
  820. /* Pass 2: process columns.
  821. * We leave the results scaled up by an overall factor of 8.
  822. * We must also scale the output by (8/9)**2 = 64/81, which we partially
  823. * fold into the constant multipliers and final/initial shifting:
  824. * cK now represents sqrt(2) * cos(K*pi/18) * 128/81.
  825. */
  826. dataptr = data;
  827. wsptr = workspace;
  828. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  829. /* Even part */
  830. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*0];
  831. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*7];
  832. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*6];
  833. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*5];
  834. tmp4 = dataptr[DCTSIZE*4];
  835. tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*0];
  836. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*7];
  837. tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*6];
  838. tmp13 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*5];
  839. z1 = tmp0 + tmp2 + tmp3;
  840. z2 = tmp1 + tmp4;
  841. dataptr[DCTSIZE*0] = (DCTELEM)
  842. DESCALE(MULTIPLY(z1 + z2, FIX(1.580246914)), /* 128/81 */
  843. CONST_BITS+2);
  844. dataptr[DCTSIZE*6] = (DCTELEM)
  845. DESCALE(MULTIPLY(z1 - z2 - z2, FIX(1.117403309)), /* c6 */
  846. CONST_BITS+2);
  847. z1 = MULTIPLY(tmp0 - tmp2, FIX(2.100031287)); /* c2 */
  848. z2 = MULTIPLY(tmp1 - tmp4 - tmp4, FIX(1.117403309)); /* c6 */
  849. dataptr[DCTSIZE*2] = (DCTELEM)
  850. DESCALE(MULTIPLY(tmp2 - tmp3, FIX(1.711961190)) /* c4 */
  851. + z1 + z2, CONST_BITS+2);
  852. dataptr[DCTSIZE*4] = (DCTELEM)
  853. DESCALE(MULTIPLY(tmp3 - tmp0, FIX(0.388070096)) /* c8 */
  854. + z1 - z2, CONST_BITS+2);
  855. /* Odd part */
  856. dataptr[DCTSIZE*3] = (DCTELEM)
  857. DESCALE(MULTIPLY(tmp10 - tmp12 - tmp13, FIX(1.935399303)), /* c3 */
  858. CONST_BITS+2);
  859. tmp11 = MULTIPLY(tmp11, FIX(1.935399303)); /* c3 */
  860. tmp0 = MULTIPLY(tmp10 + tmp12, FIX(1.436506004)); /* c5 */
  861. tmp1 = MULTIPLY(tmp10 + tmp13, FIX(0.764348879)); /* c7 */
  862. dataptr[DCTSIZE*1] = (DCTELEM)
  863. DESCALE(tmp11 + tmp0 + tmp1, CONST_BITS+2);
  864. tmp2 = MULTIPLY(tmp12 - tmp13, FIX(2.200854883)); /* c1 */
  865. dataptr[DCTSIZE*5] = (DCTELEM)
  866. DESCALE(tmp0 - tmp11 - tmp2, CONST_BITS+2);
  867. dataptr[DCTSIZE*7] = (DCTELEM)
  868. DESCALE(tmp1 - tmp11 + tmp2, CONST_BITS+2);
  869. dataptr++; /* advance pointer to next column */
  870. wsptr++; /* advance pointer to next column */
  871. }
  872. }
  873. /*
  874. * Perform the forward DCT on a 10x10 sample block.
  875. */
  876. GLOBAL(void)
  877. jpeg_fdct_10x10 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  878. {
  879. INT32 tmp0, tmp1, tmp2, tmp3, tmp4;
  880. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  881. DCTELEM workspace[8*2];
  882. DCTELEM *dataptr;
  883. DCTELEM *wsptr;
  884. JSAMPROW elemptr;
  885. int ctr;
  886. SHIFT_TEMPS
  887. /* Pass 1: process rows.
  888. * Note results are scaled up by sqrt(8) compared to a true DCT;
  889. * we scale the results further by 2 as part of output adaption
  890. * scaling for different DCT size.
  891. * cK represents sqrt(2) * cos(K*pi/20).
  892. */
  893. dataptr = data;
  894. ctr = 0;
  895. for (;;) {
  896. elemptr = sample_data[ctr] + start_col;
  897. /* Even part */
  898. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[9]);
  899. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[8]);
  900. tmp12 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[7]);
  901. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[6]);
  902. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[5]);
  903. tmp10 = tmp0 + tmp4;
  904. tmp13 = tmp0 - tmp4;
  905. tmp11 = tmp1 + tmp3;
  906. tmp14 = tmp1 - tmp3;
  907. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[9]);
  908. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[8]);
  909. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[7]);
  910. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[6]);
  911. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[5]);
  912. /* Apply unsigned->signed conversion. */
  913. dataptr[0] = (DCTELEM)
  914. ((tmp10 + tmp11 + tmp12 - 10 * CENTERJSAMPLE) << 1);
  915. tmp12 += tmp12;
  916. dataptr[4] = (DCTELEM)
  917. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.144122806)) - /* c4 */
  918. MULTIPLY(tmp11 - tmp12, FIX(0.437016024)), /* c8 */
  919. CONST_BITS-1);
  920. tmp10 = MULTIPLY(tmp13 + tmp14, FIX(0.831253876)); /* c6 */
  921. dataptr[2] = (DCTELEM)
  922. DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.513743148)), /* c2-c6 */
  923. CONST_BITS-1);
  924. dataptr[6] = (DCTELEM)
  925. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.176250899)), /* c2+c6 */
  926. CONST_BITS-1);
  927. /* Odd part */
  928. tmp10 = tmp0 + tmp4;
  929. tmp11 = tmp1 - tmp3;
  930. dataptr[5] = (DCTELEM) ((tmp10 - tmp11 - tmp2) << 1);
  931. tmp2 <<= CONST_BITS;
  932. dataptr[1] = (DCTELEM)
  933. DESCALE(MULTIPLY(tmp0, FIX(1.396802247)) + /* c1 */
  934. MULTIPLY(tmp1, FIX(1.260073511)) + tmp2 + /* c3 */
  935. MULTIPLY(tmp3, FIX(0.642039522)) + /* c7 */
  936. MULTIPLY(tmp4, FIX(0.221231742)), /* c9 */
  937. CONST_BITS-1);
  938. tmp12 = MULTIPLY(tmp0 - tmp4, FIX(0.951056516)) - /* (c3+c7)/2 */
  939. MULTIPLY(tmp1 + tmp3, FIX(0.587785252)); /* (c1-c9)/2 */
  940. tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.309016994)) + /* (c3-c7)/2 */
  941. (tmp11 << (CONST_BITS - 1)) - tmp2;
  942. dataptr[3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS-1);
  943. dataptr[7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS-1);
  944. ctr++;
  945. if (ctr != DCTSIZE) {
  946. if (ctr == 10)
  947. break; /* Done. */
  948. dataptr += DCTSIZE; /* advance pointer to next row */
  949. } else
  950. dataptr = workspace; /* switch pointer to extended workspace */
  951. }
  952. /* Pass 2: process columns.
  953. * We leave the results scaled up by an overall factor of 8.
  954. * We must also scale the output by (8/10)**2 = 16/25, which we partially
  955. * fold into the constant multipliers and final/initial shifting:
  956. * cK now represents sqrt(2) * cos(K*pi/20) * 32/25.
  957. */
  958. dataptr = data;
  959. wsptr = workspace;
  960. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  961. /* Even part */
  962. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*1];
  963. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*0];
  964. tmp12 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*7];
  965. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*6];
  966. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];
  967. tmp10 = tmp0 + tmp4;
  968. tmp13 = tmp0 - tmp4;
  969. tmp11 = tmp1 + tmp3;
  970. tmp14 = tmp1 - tmp3;
  971. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*1];
  972. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*0];
  973. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*7];
  974. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*6];
  975. tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];
  976. dataptr[DCTSIZE*0] = (DCTELEM)
  977. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(1.28)), /* 32/25 */
  978. CONST_BITS+2);
  979. tmp12 += tmp12;
  980. dataptr[DCTSIZE*4] = (DCTELEM)
  981. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.464477191)) - /* c4 */
  982. MULTIPLY(tmp11 - tmp12, FIX(0.559380511)), /* c8 */
  983. CONST_BITS+2);
  984. tmp10 = MULTIPLY(tmp13 + tmp14, FIX(1.064004961)); /* c6 */
  985. dataptr[DCTSIZE*2] = (DCTELEM)
  986. DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.657591230)), /* c2-c6 */
  987. CONST_BITS+2);
  988. dataptr[DCTSIZE*6] = (DCTELEM)
  989. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.785601151)), /* c2+c6 */
  990. CONST_BITS+2);
  991. /* Odd part */
  992. tmp10 = tmp0 + tmp4;
  993. tmp11 = tmp1 - tmp3;
  994. dataptr[DCTSIZE*5] = (DCTELEM)
  995. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp2, FIX(1.28)), /* 32/25 */
  996. CONST_BITS+2);
  997. tmp2 = MULTIPLY(tmp2, FIX(1.28)); /* 32/25 */
  998. dataptr[DCTSIZE*1] = (DCTELEM)
  999. DESCALE(MULTIPLY(tmp0, FIX(1.787906876)) + /* c1 */
  1000. MULTIPLY(tmp1, FIX(1.612894094)) + tmp2 + /* c3 */
  1001. MULTIPLY(tmp3, FIX(0.821810588)) + /* c7 */
  1002. MULTIPLY(tmp4, FIX(0.283176630)), /* c9 */
  1003. CONST_BITS+2);
  1004. tmp12 = MULTIPLY(tmp0 - tmp4, FIX(1.217352341)) - /* (c3+c7)/2 */
  1005. MULTIPLY(tmp1 + tmp3, FIX(0.752365123)); /* (c1-c9)/2 */
  1006. tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.395541753)) + /* (c3-c7)/2 */
  1007. MULTIPLY(tmp11, FIX(0.64)) - tmp2; /* 16/25 */
  1008. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS+2);
  1009. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS+2);
  1010. dataptr++; /* advance pointer to next column */
  1011. wsptr++; /* advance pointer to next column */
  1012. }
  1013. }
  1014. /*
  1015. * Perform the forward DCT on an 11x11 sample block.
  1016. */
  1017. GLOBAL(void)
  1018. jpeg_fdct_11x11 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1019. {
  1020. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  1021. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  1022. INT32 z1, z2, z3;
  1023. DCTELEM workspace[8*3];
  1024. DCTELEM *dataptr;
  1025. DCTELEM *wsptr;
  1026. JSAMPROW elemptr;
  1027. int ctr;
  1028. SHIFT_TEMPS
  1029. /* Pass 1: process rows.
  1030. * Note results are scaled up by sqrt(8) compared to a true DCT;
  1031. * we scale the results further by 2 as part of output adaption
  1032. * scaling for different DCT size.
  1033. * cK represents sqrt(2) * cos(K*pi/22).
  1034. */
  1035. dataptr = data;
  1036. ctr = 0;
  1037. for (;;) {
  1038. elemptr = sample_data[ctr] + start_col;
  1039. /* Even part */
  1040. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[10]);
  1041. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[9]);
  1042. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[8]);
  1043. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[7]);
  1044. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[6]);
  1045. tmp5 = GETJSAMPLE(elemptr[5]);
  1046. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[10]);
  1047. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[9]);
  1048. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[8]);
  1049. tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[7]);
  1050. tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[6]);
  1051. /* Apply unsigned->signed conversion. */
  1052. dataptr[0] = (DCTELEM)
  1053. ((tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 - 11 * CENTERJSAMPLE) << 1);
  1054. tmp5 += tmp5;
  1055. tmp0 -= tmp5;
  1056. tmp1 -= tmp5;
  1057. tmp2 -= tmp5;
  1058. tmp3 -= tmp5;
  1059. tmp4 -= tmp5;
  1060. z1 = MULTIPLY(tmp0 + tmp3, FIX(1.356927976)) + /* c2 */
  1061. MULTIPLY(tmp2 + tmp4, FIX(0.201263574)); /* c10 */
  1062. z2 = MULTIPLY(tmp1 - tmp3, FIX(0.926112931)); /* c6 */
  1063. z3 = MULTIPLY(tmp0 - tmp1, FIX(1.189712156)); /* c4 */
  1064. dataptr[2] = (DCTELEM)
  1065. DESCALE(z1 + z2 - MULTIPLY(tmp3, FIX(1.018300590)) /* c2+c8-c6 */
  1066. - MULTIPLY(tmp4, FIX(1.390975730)), /* c4+c10 */
  1067. CONST_BITS-1);
  1068. dataptr[4] = (DCTELEM)
  1069. DESCALE(z2 + z3 + MULTIPLY(tmp1, FIX(0.062335650)) /* c4-c6-c10 */
  1070. - MULTIPLY(tmp2, FIX(1.356927976)) /* c2 */
  1071. + MULTIPLY(tmp4, FIX(0.587485545)), /* c8 */
  1072. CONST_BITS-1);
  1073. dataptr[6] = (DCTELEM)
  1074. DESCALE(z1 + z3 - MULTIPLY(tmp0, FIX(1.620527200)) /* c2+c4-c6 */
  1075. - MULTIPLY(tmp2, FIX(0.788749120)), /* c8+c10 */
  1076. CONST_BITS-1);
  1077. /* Odd part */
  1078. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.286413905)); /* c3 */
  1079. tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.068791298)); /* c5 */
  1080. tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.764581576)); /* c7 */
  1081. tmp0 = tmp1 + tmp2 + tmp3 - MULTIPLY(tmp10, FIX(1.719967871)) /* c7+c5+c3-c1 */
  1082. + MULTIPLY(tmp14, FIX(0.398430003)); /* c9 */
  1083. tmp4 = MULTIPLY(tmp11 + tmp12, - FIX(0.764581576)); /* -c7 */
  1084. tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.399818907)); /* -c1 */
  1085. tmp1 += tmp4 + tmp5 + MULTIPLY(tmp11, FIX(1.276416582)) /* c9+c7+c1-c3 */
  1086. - MULTIPLY(tmp14, FIX(1.068791298)); /* c5 */
  1087. tmp10 = MULTIPLY(tmp12 + tmp13, FIX(0.398430003)); /* c9 */
  1088. tmp2 += tmp4 + tmp10 - MULTIPLY(tmp12, FIX(1.989053629)) /* c9+c5+c3-c7 */
  1089. + MULTIPLY(tmp14, FIX(1.399818907)); /* c1 */
  1090. tmp3 += tmp5 + tmp10 + MULTIPLY(tmp13, FIX(1.305598626)) /* c1+c5-c9-c7 */
  1091. - MULTIPLY(tmp14, FIX(1.286413905)); /* c3 */
  1092. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-1);
  1093. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-1);
  1094. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-1);
  1095. dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS-1);
  1096. ctr++;
  1097. if (ctr != DCTSIZE) {
  1098. if (ctr == 11)
  1099. break; /* Done. */
  1100. dataptr += DCTSIZE; /* advance pointer to next row */
  1101. } else
  1102. dataptr = workspace; /* switch pointer to extended workspace */
  1103. }
  1104. /* Pass 2: process columns.
  1105. * We leave the results scaled up by an overall factor of 8.
  1106. * We must also scale the output by (8/11)**2 = 64/121, which we partially
  1107. * fold into the constant multipliers and final/initial shifting:
  1108. * cK now represents sqrt(2) * cos(K*pi/22) * 128/121.
  1109. */
  1110. dataptr = data;
  1111. wsptr = workspace;
  1112. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1113. /* Even part */
  1114. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*2];
  1115. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*1];
  1116. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*0];
  1117. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*7];
  1118. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*6];
  1119. tmp5 = dataptr[DCTSIZE*5];
  1120. tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*2];
  1121. tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*1];
  1122. tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*0];
  1123. tmp13 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*7];
  1124. tmp14 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*6];
  1125. dataptr[DCTSIZE*0] = (DCTELEM)
  1126. DESCALE(MULTIPLY(tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5,
  1127. FIX(1.057851240)), /* 128/121 */
  1128. CONST_BITS+2);
  1129. tmp5 += tmp5;
  1130. tmp0 -= tmp5;
  1131. tmp1 -= tmp5;
  1132. tmp2 -= tmp5;
  1133. tmp3 -= tmp5;
  1134. tmp4 -= tmp5;
  1135. z1 = MULTIPLY(tmp0 + tmp3, FIX(1.435427942)) + /* c2 */
  1136. MULTIPLY(tmp2 + tmp4, FIX(0.212906922)); /* c10 */
  1137. z2 = MULTIPLY(tmp1 - tmp3, FIX(0.979689713)); /* c6 */
  1138. z3 = MULTIPLY(tmp0 - tmp1, FIX(1.258538479)); /* c4 */
  1139. dataptr[DCTSIZE*2] = (DCTELEM)
  1140. DESCALE(z1 + z2 - MULTIPLY(tmp3, FIX(1.077210542)) /* c2+c8-c6 */
  1141. - MULTIPLY(tmp4, FIX(1.471445400)), /* c4+c10 */
  1142. CONST_BITS+2);
  1143. dataptr[DCTSIZE*4] = (DCTELEM)
  1144. DESCALE(z2 + z3 + MULTIPLY(tmp1, FIX(0.065941844)) /* c4-c6-c10 */
  1145. - MULTIPLY(tmp2, FIX(1.435427942)) /* c2 */
  1146. + MULTIPLY(tmp4, FIX(0.621472312)), /* c8 */
  1147. CONST_BITS+2);
  1148. dataptr[DCTSIZE*6] = (DCTELEM)
  1149. DESCALE(z1 + z3 - MULTIPLY(tmp0, FIX(1.714276708)) /* c2+c4-c6 */
  1150. - MULTIPLY(tmp2, FIX(0.834379234)), /* c8+c10 */
  1151. CONST_BITS+2);
  1152. /* Odd part */
  1153. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.360834544)); /* c3 */
  1154. tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.130622199)); /* c5 */
  1155. tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.808813568)); /* c7 */
  1156. tmp0 = tmp1 + tmp2 + tmp3 - MULTIPLY(tmp10, FIX(1.819470145)) /* c7+c5+c3-c1 */
  1157. + MULTIPLY(tmp14, FIX(0.421479672)); /* c9 */
  1158. tmp4 = MULTIPLY(tmp11 + tmp12, - FIX(0.808813568)); /* -c7 */
  1159. tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.480800167)); /* -c1 */
  1160. tmp1 += tmp4 + tmp5 + MULTIPLY(tmp11, FIX(1.350258864)) /* c9+c7+c1-c3 */
  1161. - MULTIPLY(tmp14, FIX(1.130622199)); /* c5 */
  1162. tmp10 = MULTIPLY(tmp12 + tmp13, FIX(0.421479672)); /* c9 */
  1163. tmp2 += tmp4 + tmp10 - MULTIPLY(tmp12, FIX(2.104122847)) /* c9+c5+c3-c7 */
  1164. + MULTIPLY(tmp14, FIX(1.480800167)); /* c1 */
  1165. tmp3 += tmp5 + tmp10 + MULTIPLY(tmp13, FIX(1.381129125)) /* c1+c5-c9-c7 */
  1166. - MULTIPLY(tmp14, FIX(1.360834544)); /* c3 */
  1167. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+2);
  1168. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+2);
  1169. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+2);
  1170. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+2);
  1171. dataptr++; /* advance pointer to next column */
  1172. wsptr++; /* advance pointer to next column */
  1173. }
  1174. }
  1175. /*
  1176. * Perform the forward DCT on a 12x12 sample block.
  1177. */
  1178. GLOBAL(void)
  1179. jpeg_fdct_12x12 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1180. {
  1181. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  1182. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  1183. DCTELEM workspace[8*4];
  1184. DCTELEM *dataptr;
  1185. DCTELEM *wsptr;
  1186. JSAMPROW elemptr;
  1187. int ctr;
  1188. SHIFT_TEMPS
  1189. /* Pass 1: process rows.
  1190. * Note results are scaled up by sqrt(8) compared to a true DCT.
  1191. * cK represents sqrt(2) * cos(K*pi/24).
  1192. */
  1193. dataptr = data;
  1194. ctr = 0;
  1195. for (;;) {
  1196. elemptr = sample_data[ctr] + start_col;
  1197. /* Even part */
  1198. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[11]);
  1199. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[10]);
  1200. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[9]);
  1201. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[8]);
  1202. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[7]);
  1203. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[6]);
  1204. tmp10 = tmp0 + tmp5;
  1205. tmp13 = tmp0 - tmp5;
  1206. tmp11 = tmp1 + tmp4;
  1207. tmp14 = tmp1 - tmp4;
  1208. tmp12 = tmp2 + tmp3;
  1209. tmp15 = tmp2 - tmp3;
  1210. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[11]);
  1211. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[10]);
  1212. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[9]);
  1213. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[8]);
  1214. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[7]);
  1215. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[6]);
  1216. /* Apply unsigned->signed conversion. */
  1217. dataptr[0] = (DCTELEM) (tmp10 + tmp11 + tmp12 - 12 * CENTERJSAMPLE);
  1218. dataptr[6] = (DCTELEM) (tmp13 - tmp14 - tmp15);
  1219. dataptr[4] = (DCTELEM)
  1220. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.224744871)), /* c4 */
  1221. CONST_BITS);
  1222. dataptr[2] = (DCTELEM)
  1223. DESCALE(tmp14 - tmp15 + MULTIPLY(tmp13 + tmp15, FIX(1.366025404)), /* c2 */
  1224. CONST_BITS);
  1225. /* Odd part */
  1226. tmp10 = MULTIPLY(tmp1 + tmp4, FIX_0_541196100); /* c9 */
  1227. tmp14 = tmp10 + MULTIPLY(tmp1, FIX_0_765366865); /* c3-c9 */
  1228. tmp15 = tmp10 - MULTIPLY(tmp4, FIX_1_847759065); /* c3+c9 */
  1229. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.121971054)); /* c5 */
  1230. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.860918669)); /* c7 */
  1231. tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.580774953)) /* c5+c7-c1 */
  1232. + MULTIPLY(tmp5, FIX(0.184591911)); /* c11 */
  1233. tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.184591911)); /* -c11 */
  1234. tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.339493912)) /* c1+c5-c11 */
  1235. + MULTIPLY(tmp5, FIX(0.860918669)); /* c7 */
  1236. tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.725788011)) /* c1+c11-c7 */
  1237. - MULTIPLY(tmp5, FIX(1.121971054)); /* c5 */
  1238. tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.306562965)) /* c3 */
  1239. - MULTIPLY(tmp2 + tmp5, FIX_0_541196100); /* c9 */
  1240. dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS);
  1241. dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS);
  1242. dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS);
  1243. dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS);
  1244. ctr++;
  1245. if (ctr != DCTSIZE) {
  1246. if (ctr == 12)
  1247. break; /* Done. */
  1248. dataptr += DCTSIZE; /* advance pointer to next row */
  1249. } else
  1250. dataptr = workspace; /* switch pointer to extended workspace */
  1251. }
  1252. /* Pass 2: process columns.
  1253. * We leave the results scaled up by an overall factor of 8.
  1254. * We must also scale the output by (8/12)**2 = 4/9, which we partially
  1255. * fold into the constant multipliers and final shifting:
  1256. * cK now represents sqrt(2) * cos(K*pi/24) * 8/9.
  1257. */
  1258. dataptr = data;
  1259. wsptr = workspace;
  1260. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1261. /* Even part */
  1262. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*3];
  1263. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*2];
  1264. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*1];
  1265. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*0];
  1266. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*7];
  1267. tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*6];
  1268. tmp10 = tmp0 + tmp5;
  1269. tmp13 = tmp0 - tmp5;
  1270. tmp11 = tmp1 + tmp4;
  1271. tmp14 = tmp1 - tmp4;
  1272. tmp12 = tmp2 + tmp3;
  1273. tmp15 = tmp2 - tmp3;
  1274. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*3];
  1275. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*2];
  1276. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*1];
  1277. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*0];
  1278. tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*7];
  1279. tmp5 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*6];
  1280. dataptr[DCTSIZE*0] = (DCTELEM)
  1281. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(0.888888889)), /* 8/9 */
  1282. CONST_BITS+1);
  1283. dataptr[DCTSIZE*6] = (DCTELEM)
  1284. DESCALE(MULTIPLY(tmp13 - tmp14 - tmp15, FIX(0.888888889)), /* 8/9 */
  1285. CONST_BITS+1);
  1286. dataptr[DCTSIZE*4] = (DCTELEM)
  1287. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.088662108)), /* c4 */
  1288. CONST_BITS+1);
  1289. dataptr[DCTSIZE*2] = (DCTELEM)
  1290. DESCALE(MULTIPLY(tmp14 - tmp15, FIX(0.888888889)) + /* 8/9 */
  1291. MULTIPLY(tmp13 + tmp15, FIX(1.214244803)), /* c2 */
  1292. CONST_BITS+1);
  1293. /* Odd part */
  1294. tmp10 = MULTIPLY(tmp1 + tmp4, FIX(0.481063200)); /* c9 */
  1295. tmp14 = tmp10 + MULTIPLY(tmp1, FIX(0.680326102)); /* c3-c9 */
  1296. tmp15 = tmp10 - MULTIPLY(tmp4, FIX(1.642452502)); /* c3+c9 */
  1297. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(0.997307603)); /* c5 */
  1298. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.765261039)); /* c7 */
  1299. tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.516244403)) /* c5+c7-c1 */
  1300. + MULTIPLY(tmp5, FIX(0.164081699)); /* c11 */
  1301. tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.164081699)); /* -c11 */
  1302. tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.079550144)) /* c1+c5-c11 */
  1303. + MULTIPLY(tmp5, FIX(0.765261039)); /* c7 */
  1304. tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.645144899)) /* c1+c11-c7 */
  1305. - MULTIPLY(tmp5, FIX(0.997307603)); /* c5 */
  1306. tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.161389302)) /* c3 */
  1307. - MULTIPLY(tmp2 + tmp5, FIX(0.481063200)); /* c9 */
  1308. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+1);
  1309. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+1);
  1310. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+1);
  1311. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+1);
  1312. dataptr++; /* advance pointer to next column */
  1313. wsptr++; /* advance pointer to next column */
  1314. }
  1315. }
  1316. /*
  1317. * Perform the forward DCT on a 13x13 sample block.
  1318. */
  1319. GLOBAL(void)
  1320. jpeg_fdct_13x13 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1321. {
  1322. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  1323. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  1324. INT32 z1, z2;
  1325. DCTELEM workspace[8*5];
  1326. DCTELEM *dataptr;
  1327. DCTELEM *wsptr;
  1328. JSAMPROW elemptr;
  1329. int ctr;
  1330. SHIFT_TEMPS
  1331. /* Pass 1: process rows.
  1332. * Note results are scaled up by sqrt(8) compared to a true DCT.
  1333. * cK represents sqrt(2) * cos(K*pi/26).
  1334. */
  1335. dataptr = data;
  1336. ctr = 0;
  1337. for (;;) {
  1338. elemptr = sample_data[ctr] + start_col;
  1339. /* Even part */
  1340. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[12]);
  1341. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[11]);
  1342. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[10]);
  1343. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[9]);
  1344. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[8]);
  1345. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[7]);
  1346. tmp6 = GETJSAMPLE(elemptr[6]);
  1347. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[12]);
  1348. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[11]);
  1349. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[10]);
  1350. tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[9]);
  1351. tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[8]);
  1352. tmp15 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[7]);
  1353. /* Apply unsigned->signed conversion. */
  1354. dataptr[0] = (DCTELEM)
  1355. (tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 + tmp6 - 13 * CENTERJSAMPLE);
  1356. tmp6 += tmp6;
  1357. tmp0 -= tmp6;
  1358. tmp1 -= tmp6;
  1359. tmp2 -= tmp6;
  1360. tmp3 -= tmp6;
  1361. tmp4 -= tmp6;
  1362. tmp5 -= tmp6;
  1363. dataptr[2] = (DCTELEM)
  1364. DESCALE(MULTIPLY(tmp0, FIX(1.373119086)) + /* c2 */
  1365. MULTIPLY(tmp1, FIX(1.058554052)) + /* c6 */
  1366. MULTIPLY(tmp2, FIX(0.501487041)) - /* c10 */
  1367. MULTIPLY(tmp3, FIX(0.170464608)) - /* c12 */
  1368. MULTIPLY(tmp4, FIX(0.803364869)) - /* c8 */
  1369. MULTIPLY(tmp5, FIX(1.252223920)), /* c4 */
  1370. CONST_BITS);
  1371. z1 = MULTIPLY(tmp0 - tmp2, FIX(1.155388986)) - /* (c4+c6)/2 */
  1372. MULTIPLY(tmp3 - tmp4, FIX(0.435816023)) - /* (c2-c10)/2 */
  1373. MULTIPLY(tmp1 - tmp5, FIX(0.316450131)); /* (c8-c12)/2 */
  1374. z2 = MULTIPLY(tmp0 + tmp2, FIX(0.096834934)) - /* (c4-c6)/2 */
  1375. MULTIPLY(tmp3 + tmp4, FIX(0.937303064)) + /* (c2+c10)/2 */
  1376. MULTIPLY(tmp1 + tmp5, FIX(0.486914739)); /* (c8+c12)/2 */
  1377. dataptr[4] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS);
  1378. dataptr[6] = (DCTELEM) DESCALE(z1 - z2, CONST_BITS);
  1379. /* Odd part */
  1380. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.322312651)); /* c3 */
  1381. tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.163874945)); /* c5 */
  1382. tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.937797057)) + /* c7 */
  1383. MULTIPLY(tmp14 + tmp15, FIX(0.338443458)); /* c11 */
  1384. tmp0 = tmp1 + tmp2 + tmp3 -
  1385. MULTIPLY(tmp10, FIX(2.020082300)) + /* c3+c5+c7-c1 */
  1386. MULTIPLY(tmp14, FIX(0.318774355)); /* c9-c11 */
  1387. tmp4 = MULTIPLY(tmp14 - tmp15, FIX(0.937797057)) - /* c7 */
  1388. MULTIPLY(tmp11 + tmp12, FIX(0.338443458)); /* c11 */
  1389. tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.163874945)); /* -c5 */
  1390. tmp1 += tmp4 + tmp5 +
  1391. MULTIPLY(tmp11, FIX(0.837223564)) - /* c5+c9+c11-c3 */
  1392. MULTIPLY(tmp14, FIX(2.341699410)); /* c1+c7 */
  1393. tmp6 = MULTIPLY(tmp12 + tmp13, - FIX(0.657217813)); /* -c9 */
  1394. tmp2 += tmp4 + tmp6 -
  1395. MULTIPLY(tmp12, FIX(1.572116027)) + /* c1+c5-c9-c11 */
  1396. MULTIPLY(tmp15, FIX(2.260109708)); /* c3+c7 */
  1397. tmp3 += tmp5 + tmp6 +
  1398. MULTIPLY(tmp13, FIX(2.205608352)) - /* c3+c5+c9-c7 */
  1399. MULTIPLY(tmp15, FIX(1.742345811)); /* c1+c11 */
  1400. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS);
  1401. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS);
  1402. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS);
  1403. dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS);
  1404. ctr++;
  1405. if (ctr != DCTSIZE) {
  1406. if (ctr == 13)
  1407. break; /* Done. */
  1408. dataptr += DCTSIZE; /* advance pointer to next row */
  1409. } else
  1410. dataptr = workspace; /* switch pointer to extended workspace */
  1411. }
  1412. /* Pass 2: process columns.
  1413. * We leave the results scaled up by an overall factor of 8.
  1414. * We must also scale the output by (8/13)**2 = 64/169, which we partially
  1415. * fold into the constant multipliers and final shifting:
  1416. * cK now represents sqrt(2) * cos(K*pi/26) * 128/169.
  1417. */
  1418. dataptr = data;
  1419. wsptr = workspace;
  1420. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1421. /* Even part */
  1422. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*4];
  1423. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*3];
  1424. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*2];
  1425. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*1];
  1426. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*0];
  1427. tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*7];
  1428. tmp6 = dataptr[DCTSIZE*6];
  1429. tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*4];
  1430. tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*3];
  1431. tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*2];
  1432. tmp13 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*1];
  1433. tmp14 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*0];
  1434. tmp15 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*7];
  1435. dataptr[DCTSIZE*0] = (DCTELEM)
  1436. DESCALE(MULTIPLY(tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 + tmp6,
  1437. FIX(0.757396450)), /* 128/169 */
  1438. CONST_BITS+1);
  1439. tmp6 += tmp6;
  1440. tmp0 -= tmp6;
  1441. tmp1 -= tmp6;
  1442. tmp2 -= tmp6;
  1443. tmp3 -= tmp6;
  1444. tmp4 -= tmp6;
  1445. tmp5 -= tmp6;
  1446. dataptr[DCTSIZE*2] = (DCTELEM)
  1447. DESCALE(MULTIPLY(tmp0, FIX(1.039995521)) + /* c2 */
  1448. MULTIPLY(tmp1, FIX(0.801745081)) + /* c6 */
  1449. MULTIPLY(tmp2, FIX(0.379824504)) - /* c10 */
  1450. MULTIPLY(tmp3, FIX(0.129109289)) - /* c12 */
  1451. MULTIPLY(tmp4, FIX(0.608465700)) - /* c8 */
  1452. MULTIPLY(tmp5, FIX(0.948429952)), /* c4 */
  1453. CONST_BITS+1);
  1454. z1 = MULTIPLY(tmp0 - tmp2, FIX(0.875087516)) - /* (c4+c6)/2 */
  1455. MULTIPLY(tmp3 - tmp4, FIX(0.330085509)) - /* (c2-c10)/2 */
  1456. MULTIPLY(tmp1 - tmp5, FIX(0.239678205)); /* (c8-c12)/2 */
  1457. z2 = MULTIPLY(tmp0 + tmp2, FIX(0.073342435)) - /* (c4-c6)/2 */
  1458. MULTIPLY(tmp3 + tmp4, FIX(0.709910013)) + /* (c2+c10)/2 */
  1459. MULTIPLY(tmp1 + tmp5, FIX(0.368787494)); /* (c8+c12)/2 */
  1460. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+1);
  1461. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 - z2, CONST_BITS+1);
  1462. /* Odd part */
  1463. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.001514908)); /* c3 */
  1464. tmp2 = MULTIPLY(tmp10 + tmp12, FIX(0.881514751)); /* c5 */
  1465. tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.710284161)) + /* c7 */
  1466. MULTIPLY(tmp14 + tmp15, FIX(0.256335874)); /* c11 */
  1467. tmp0 = tmp1 + tmp2 + tmp3 -
  1468. MULTIPLY(tmp10, FIX(1.530003162)) + /* c3+c5+c7-c1 */
  1469. MULTIPLY(tmp14, FIX(0.241438564)); /* c9-c11 */
  1470. tmp4 = MULTIPLY(tmp14 - tmp15, FIX(0.710284161)) - /* c7 */
  1471. MULTIPLY(tmp11 + tmp12, FIX(0.256335874)); /* c11 */
  1472. tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(0.881514751)); /* -c5 */
  1473. tmp1 += tmp4 + tmp5 +
  1474. MULTIPLY(tmp11, FIX(0.634110155)) - /* c5+c9+c11-c3 */
  1475. MULTIPLY(tmp14, FIX(1.773594819)); /* c1+c7 */
  1476. tmp6 = MULTIPLY(tmp12 + tmp13, - FIX(0.497774438)); /* -c9 */
  1477. tmp2 += tmp4 + tmp6 -
  1478. MULTIPLY(tmp12, FIX(1.190715098)) + /* c1+c5-c9-c11 */
  1479. MULTIPLY(tmp15, FIX(1.711799069)); /* c3+c7 */
  1480. tmp3 += tmp5 + tmp6 +
  1481. MULTIPLY(tmp13, FIX(1.670519935)) - /* c3+c5+c9-c7 */
  1482. MULTIPLY(tmp15, FIX(1.319646532)); /* c1+c11 */
  1483. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+1);
  1484. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+1);
  1485. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+1);
  1486. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+1);
  1487. dataptr++; /* advance pointer to next column */
  1488. wsptr++; /* advance pointer to next column */
  1489. }
  1490. }
  1491. /*
  1492. * Perform the forward DCT on a 14x14 sample block.
  1493. */
  1494. GLOBAL(void)
  1495. jpeg_fdct_14x14 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1496. {
  1497. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  1498. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  1499. DCTELEM workspace[8*6];
  1500. DCTELEM *dataptr;
  1501. DCTELEM *wsptr;
  1502. JSAMPROW elemptr;
  1503. int ctr;
  1504. SHIFT_TEMPS
  1505. /* Pass 1: process rows.
  1506. * Note results are scaled up by sqrt(8) compared to a true DCT.
  1507. * cK represents sqrt(2) * cos(K*pi/28).
  1508. */
  1509. dataptr = data;
  1510. ctr = 0;
  1511. for (;;) {
  1512. elemptr = sample_data[ctr] + start_col;
  1513. /* Even part */
  1514. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[13]);
  1515. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[12]);
  1516. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[11]);
  1517. tmp13 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[10]);
  1518. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[9]);
  1519. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[8]);
  1520. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[7]);
  1521. tmp10 = tmp0 + tmp6;
  1522. tmp14 = tmp0 - tmp6;
  1523. tmp11 = tmp1 + tmp5;
  1524. tmp15 = tmp1 - tmp5;
  1525. tmp12 = tmp2 + tmp4;
  1526. tmp16 = tmp2 - tmp4;
  1527. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[13]);
  1528. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[12]);
  1529. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[11]);
  1530. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[10]);
  1531. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[9]);
  1532. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[8]);
  1533. tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[7]);
  1534. /* Apply unsigned->signed conversion. */
  1535. dataptr[0] = (DCTELEM)
  1536. (tmp10 + tmp11 + tmp12 + tmp13 - 14 * CENTERJSAMPLE);
  1537. tmp13 += tmp13;
  1538. dataptr[4] = (DCTELEM)
  1539. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.274162392)) + /* c4 */
  1540. MULTIPLY(tmp11 - tmp13, FIX(0.314692123)) - /* c12 */
  1541. MULTIPLY(tmp12 - tmp13, FIX(0.881747734)), /* c8 */
  1542. CONST_BITS);
  1543. tmp10 = MULTIPLY(tmp14 + tmp15, FIX(1.105676686)); /* c6 */
  1544. dataptr[2] = (DCTELEM)
  1545. DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.273079590)) /* c2-c6 */
  1546. + MULTIPLY(tmp16, FIX(0.613604268)), /* c10 */
  1547. CONST_BITS);
  1548. dataptr[6] = (DCTELEM)
  1549. DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.719280954)) /* c6+c10 */
  1550. - MULTIPLY(tmp16, FIX(1.378756276)), /* c2 */
  1551. CONST_BITS);
  1552. /* Odd part */
  1553. tmp10 = tmp1 + tmp2;
  1554. tmp11 = tmp5 - tmp4;
  1555. dataptr[7] = (DCTELEM) (tmp0 - tmp10 + tmp3 - tmp11 - tmp6);
  1556. tmp3 <<= CONST_BITS;
  1557. tmp10 = MULTIPLY(tmp10, - FIX(0.158341681)); /* -c13 */
  1558. tmp11 = MULTIPLY(tmp11, FIX(1.405321284)); /* c1 */
  1559. tmp10 += tmp11 - tmp3;
  1560. tmp11 = MULTIPLY(tmp0 + tmp2, FIX(1.197448846)) + /* c5 */
  1561. MULTIPLY(tmp4 + tmp6, FIX(0.752406978)); /* c9 */
  1562. dataptr[5] = (DCTELEM)
  1563. DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(2.373959773)) /* c3+c5-c13 */
  1564. + MULTIPLY(tmp4, FIX(1.119999435)), /* c1+c11-c9 */
  1565. CONST_BITS);
  1566. tmp12 = MULTIPLY(tmp0 + tmp1, FIX(1.334852607)) + /* c3 */
  1567. MULTIPLY(tmp5 - tmp6, FIX(0.467085129)); /* c11 */
  1568. dataptr[3] = (DCTELEM)
  1569. DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.424103948)) /* c3-c9-c13 */
  1570. - MULTIPLY(tmp5, FIX(3.069855259)), /* c1+c5+c11 */
  1571. CONST_BITS);
  1572. dataptr[1] = (DCTELEM)
  1573. DESCALE(tmp11 + tmp12 + tmp3 + tmp6 -
  1574. MULTIPLY(tmp0 + tmp6, FIX(1.126980169)), /* c3+c5-c1 */
  1575. CONST_BITS);
  1576. ctr++;
  1577. if (ctr != DCTSIZE) {
  1578. if (ctr == 14)
  1579. break; /* Done. */
  1580. dataptr += DCTSIZE; /* advance pointer to next row */
  1581. } else
  1582. dataptr = workspace; /* switch pointer to extended workspace */
  1583. }
  1584. /* Pass 2: process columns.
  1585. * We leave the results scaled up by an overall factor of 8.
  1586. * We must also scale the output by (8/14)**2 = 16/49, which we partially
  1587. * fold into the constant multipliers and final shifting:
  1588. * cK now represents sqrt(2) * cos(K*pi/28) * 32/49.
  1589. */
  1590. dataptr = data;
  1591. wsptr = workspace;
  1592. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1593. /* Even part */
  1594. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*5];
  1595. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*4];
  1596. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*3];
  1597. tmp13 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*2];
  1598. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*1];
  1599. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*0];
  1600. tmp6 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];
  1601. tmp10 = tmp0 + tmp6;
  1602. tmp14 = tmp0 - tmp6;
  1603. tmp11 = tmp1 + tmp5;
  1604. tmp15 = tmp1 - tmp5;
  1605. tmp12 = tmp2 + tmp4;
  1606. tmp16 = tmp2 - tmp4;
  1607. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*5];
  1608. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*4];
  1609. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*3];
  1610. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*2];
  1611. tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*1];
  1612. tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*0];
  1613. tmp6 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];
  1614. dataptr[DCTSIZE*0] = (DCTELEM)
  1615. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12 + tmp13,
  1616. FIX(0.653061224)), /* 32/49 */
  1617. CONST_BITS+1);
  1618. tmp13 += tmp13;
  1619. dataptr[DCTSIZE*4] = (DCTELEM)
  1620. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(0.832106052)) + /* c4 */
  1621. MULTIPLY(tmp11 - tmp13, FIX(0.205513223)) - /* c12 */
  1622. MULTIPLY(tmp12 - tmp13, FIX(0.575835255)), /* c8 */
  1623. CONST_BITS+1);
  1624. tmp10 = MULTIPLY(tmp14 + tmp15, FIX(0.722074570)); /* c6 */
  1625. dataptr[DCTSIZE*2] = (DCTELEM)
  1626. DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.178337691)) /* c2-c6 */
  1627. + MULTIPLY(tmp16, FIX(0.400721155)), /* c10 */
  1628. CONST_BITS+1);
  1629. dataptr[DCTSIZE*6] = (DCTELEM)
  1630. DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.122795725)) /* c6+c10 */
  1631. - MULTIPLY(tmp16, FIX(0.900412262)), /* c2 */
  1632. CONST_BITS+1);
  1633. /* Odd part */
  1634. tmp10 = tmp1 + tmp2;
  1635. tmp11 = tmp5 - tmp4;
  1636. dataptr[DCTSIZE*7] = (DCTELEM)
  1637. DESCALE(MULTIPLY(tmp0 - tmp10 + tmp3 - tmp11 - tmp6,
  1638. FIX(0.653061224)), /* 32/49 */
  1639. CONST_BITS+1);
  1640. tmp3 = MULTIPLY(tmp3 , FIX(0.653061224)); /* 32/49 */
  1641. tmp10 = MULTIPLY(tmp10, - FIX(0.103406812)); /* -c13 */
  1642. tmp11 = MULTIPLY(tmp11, FIX(0.917760839)); /* c1 */
  1643. tmp10 += tmp11 - tmp3;
  1644. tmp11 = MULTIPLY(tmp0 + tmp2, FIX(0.782007410)) + /* c5 */
  1645. MULTIPLY(tmp4 + tmp6, FIX(0.491367823)); /* c9 */
  1646. dataptr[DCTSIZE*5] = (DCTELEM)
  1647. DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(1.550341076)) /* c3+c5-c13 */
  1648. + MULTIPLY(tmp4, FIX(0.731428202)), /* c1+c11-c9 */
  1649. CONST_BITS+1);
  1650. tmp12 = MULTIPLY(tmp0 + tmp1, FIX(0.871740478)) + /* c3 */
  1651. MULTIPLY(tmp5 - tmp6, FIX(0.305035186)); /* c11 */
  1652. dataptr[DCTSIZE*3] = (DCTELEM)
  1653. DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.276965844)) /* c3-c9-c13 */
  1654. - MULTIPLY(tmp5, FIX(2.004803435)), /* c1+c5+c11 */
  1655. CONST_BITS+1);
  1656. dataptr[DCTSIZE*1] = (DCTELEM)
  1657. DESCALE(tmp11 + tmp12 + tmp3
  1658. - MULTIPLY(tmp0, FIX(0.735987049)) /* c3+c5-c1 */
  1659. - MULTIPLY(tmp6, FIX(0.082925825)), /* c9-c11-c13 */
  1660. CONST_BITS+1);
  1661. dataptr++; /* advance pointer to next column */
  1662. wsptr++; /* advance pointer to next column */
  1663. }
  1664. }
  1665. /*
  1666. * Perform the forward DCT on a 15x15 sample block.
  1667. */
  1668. GLOBAL(void)
  1669. jpeg_fdct_15x15 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1670. {
  1671. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  1672. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  1673. INT32 z1, z2, z3;
  1674. DCTELEM workspace[8*7];
  1675. DCTELEM *dataptr;
  1676. DCTELEM *wsptr;
  1677. JSAMPROW elemptr;
  1678. int ctr;
  1679. SHIFT_TEMPS
  1680. /* Pass 1: process rows.
  1681. * Note results are scaled up by sqrt(8) compared to a true DCT.
  1682. * cK represents sqrt(2) * cos(K*pi/30).
  1683. */
  1684. dataptr = data;
  1685. ctr = 0;
  1686. for (;;) {
  1687. elemptr = sample_data[ctr] + start_col;
  1688. /* Even part */
  1689. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[14]);
  1690. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[13]);
  1691. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[12]);
  1692. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[11]);
  1693. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[10]);
  1694. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[9]);
  1695. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[8]);
  1696. tmp7 = GETJSAMPLE(elemptr[7]);
  1697. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[14]);
  1698. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[13]);
  1699. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[12]);
  1700. tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[11]);
  1701. tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[10]);
  1702. tmp15 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[9]);
  1703. tmp16 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[8]);
  1704. z1 = tmp0 + tmp4 + tmp5;
  1705. z2 = tmp1 + tmp3 + tmp6;
  1706. z3 = tmp2 + tmp7;
  1707. /* Apply unsigned->signed conversion. */
  1708. dataptr[0] = (DCTELEM) (z1 + z2 + z3 - 15 * CENTERJSAMPLE);
  1709. z3 += z3;
  1710. dataptr[6] = (DCTELEM)
  1711. DESCALE(MULTIPLY(z1 - z3, FIX(1.144122806)) - /* c6 */
  1712. MULTIPLY(z2 - z3, FIX(0.437016024)), /* c12 */
  1713. CONST_BITS);
  1714. tmp2 += ((tmp1 + tmp4) >> 1) - tmp7 - tmp7;
  1715. z1 = MULTIPLY(tmp3 - tmp2, FIX(1.531135173)) - /* c2+c14 */
  1716. MULTIPLY(tmp6 - tmp2, FIX(2.238241955)); /* c4+c8 */
  1717. z2 = MULTIPLY(tmp5 - tmp2, FIX(0.798468008)) - /* c8-c14 */
  1718. MULTIPLY(tmp0 - tmp2, FIX(0.091361227)); /* c2-c4 */
  1719. z3 = MULTIPLY(tmp0 - tmp3, FIX(1.383309603)) + /* c2 */
  1720. MULTIPLY(tmp6 - tmp5, FIX(0.946293579)) + /* c8 */
  1721. MULTIPLY(tmp1 - tmp4, FIX(0.790569415)); /* (c6+c12)/2 */
  1722. dataptr[2] = (DCTELEM) DESCALE(z1 + z3, CONST_BITS);
  1723. dataptr[4] = (DCTELEM) DESCALE(z2 + z3, CONST_BITS);
  1724. /* Odd part */
  1725. tmp2 = MULTIPLY(tmp10 - tmp12 - tmp13 + tmp15 + tmp16,
  1726. FIX(1.224744871)); /* c5 */
  1727. tmp1 = MULTIPLY(tmp10 - tmp14 - tmp15, FIX(1.344997024)) + /* c3 */
  1728. MULTIPLY(tmp11 - tmp13 - tmp16, FIX(0.831253876)); /* c9 */
  1729. tmp12 = MULTIPLY(tmp12, FIX(1.224744871)); /* c5 */
  1730. tmp4 = MULTIPLY(tmp10 - tmp16, FIX(1.406466353)) + /* c1 */
  1731. MULTIPLY(tmp11 + tmp14, FIX(1.344997024)) + /* c3 */
  1732. MULTIPLY(tmp13 + tmp15, FIX(0.575212477)); /* c11 */
  1733. tmp0 = MULTIPLY(tmp13, FIX(0.475753014)) - /* c7-c11 */
  1734. MULTIPLY(tmp14, FIX(0.513743148)) + /* c3-c9 */
  1735. MULTIPLY(tmp16, FIX(1.700497885)) + tmp4 + tmp12; /* c1+c13 */
  1736. tmp3 = MULTIPLY(tmp10, - FIX(0.355500862)) - /* -(c1-c7) */
  1737. MULTIPLY(tmp11, FIX(2.176250899)) - /* c3+c9 */
  1738. MULTIPLY(tmp15, FIX(0.869244010)) + tmp4 - tmp12; /* c11+c13 */
  1739. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS);
  1740. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS);
  1741. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS);
  1742. dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS);
  1743. ctr++;
  1744. if (ctr != DCTSIZE) {
  1745. if (ctr == 15)
  1746. break; /* Done. */
  1747. dataptr += DCTSIZE; /* advance pointer to next row */
  1748. } else
  1749. dataptr = workspace; /* switch pointer to extended workspace */
  1750. }
  1751. /* Pass 2: process columns.
  1752. * We leave the results scaled up by an overall factor of 8.
  1753. * We must also scale the output by (8/15)**2 = 64/225, which we partially
  1754. * fold into the constant multipliers and final shifting:
  1755. * cK now represents sqrt(2) * cos(K*pi/30) * 256/225.
  1756. */
  1757. dataptr = data;
  1758. wsptr = workspace;
  1759. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1760. /* Even part */
  1761. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*6];
  1762. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*5];
  1763. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*4];
  1764. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*3];
  1765. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*2];
  1766. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*1];
  1767. tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*0];
  1768. tmp7 = dataptr[DCTSIZE*7];
  1769. tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*6];
  1770. tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*5];
  1771. tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*4];
  1772. tmp13 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*3];
  1773. tmp14 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*2];
  1774. tmp15 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*1];
  1775. tmp16 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*0];
  1776. z1 = tmp0 + tmp4 + tmp5;
  1777. z2 = tmp1 + tmp3 + tmp6;
  1778. z3 = tmp2 + tmp7;
  1779. dataptr[DCTSIZE*0] = (DCTELEM)
  1780. DESCALE(MULTIPLY(z1 + z2 + z3, FIX(1.137777778)), /* 256/225 */
  1781. CONST_BITS+2);
  1782. z3 += z3;
  1783. dataptr[DCTSIZE*6] = (DCTELEM)
  1784. DESCALE(MULTIPLY(z1 - z3, FIX(1.301757503)) - /* c6 */
  1785. MULTIPLY(z2 - z3, FIX(0.497227121)), /* c12 */
  1786. CONST_BITS+2);
  1787. tmp2 += ((tmp1 + tmp4) >> 1) - tmp7 - tmp7;
  1788. z1 = MULTIPLY(tmp3 - tmp2, FIX(1.742091575)) - /* c2+c14 */
  1789. MULTIPLY(tmp6 - tmp2, FIX(2.546621957)); /* c4+c8 */
  1790. z2 = MULTIPLY(tmp5 - tmp2, FIX(0.908479156)) - /* c8-c14 */
  1791. MULTIPLY(tmp0 - tmp2, FIX(0.103948774)); /* c2-c4 */
  1792. z3 = MULTIPLY(tmp0 - tmp3, FIX(1.573898926)) + /* c2 */
  1793. MULTIPLY(tmp6 - tmp5, FIX(1.076671805)) + /* c8 */
  1794. MULTIPLY(tmp1 - tmp4, FIX(0.899492312)); /* (c6+c12)/2 */
  1795. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z3, CONST_BITS+2);
  1796. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(z2 + z3, CONST_BITS+2);
  1797. /* Odd part */
  1798. tmp2 = MULTIPLY(tmp10 - tmp12 - tmp13 + tmp15 + tmp16,
  1799. FIX(1.393487498)); /* c5 */
  1800. tmp1 = MULTIPLY(tmp10 - tmp14 - tmp15, FIX(1.530307725)) + /* c3 */
  1801. MULTIPLY(tmp11 - tmp13 - tmp16, FIX(0.945782187)); /* c9 */
  1802. tmp12 = MULTIPLY(tmp12, FIX(1.393487498)); /* c5 */
  1803. tmp4 = MULTIPLY(tmp10 - tmp16, FIX(1.600246161)) + /* c1 */
  1804. MULTIPLY(tmp11 + tmp14, FIX(1.530307725)) + /* c3 */
  1805. MULTIPLY(tmp13 + tmp15, FIX(0.654463974)); /* c11 */
  1806. tmp0 = MULTIPLY(tmp13, FIX(0.541301207)) - /* c7-c11 */
  1807. MULTIPLY(tmp14, FIX(0.584525538)) + /* c3-c9 */
  1808. MULTIPLY(tmp16, FIX(1.934788705)) + tmp4 + tmp12; /* c1+c13 */
  1809. tmp3 = MULTIPLY(tmp10, - FIX(0.404480980)) - /* -(c1-c7) */
  1810. MULTIPLY(tmp11, FIX(2.476089912)) - /* c3+c9 */
  1811. MULTIPLY(tmp15, FIX(0.989006518)) + tmp4 - tmp12; /* c11+c13 */
  1812. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+2);
  1813. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+2);
  1814. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+2);
  1815. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+2);
  1816. dataptr++; /* advance pointer to next column */
  1817. wsptr++; /* advance pointer to next column */
  1818. }
  1819. }
  1820. /*
  1821. * Perform the forward DCT on a 16x16 sample block.
  1822. */
  1823. GLOBAL(void)
  1824. jpeg_fdct_16x16 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1825. {
  1826. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  1827. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;
  1828. DCTELEM workspace[DCTSIZE2];
  1829. DCTELEM *dataptr;
  1830. DCTELEM *wsptr;
  1831. JSAMPROW elemptr;
  1832. int ctr;
  1833. SHIFT_TEMPS
  1834. /* Pass 1: process rows.
  1835. * Note results are scaled up by sqrt(8) compared to a true DCT;
  1836. * furthermore, we scale the results by 2**PASS1_BITS.
  1837. * cK represents sqrt(2) * cos(K*pi/32).
  1838. */
  1839. dataptr = data;
  1840. ctr = 0;
  1841. for (;;) {
  1842. elemptr = sample_data[ctr] + start_col;
  1843. /* Even part */
  1844. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[15]);
  1845. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[14]);
  1846. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[13]);
  1847. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[12]);
  1848. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[11]);
  1849. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[10]);
  1850. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[9]);
  1851. tmp7 = GETJSAMPLE(elemptr[7]) + GETJSAMPLE(elemptr[8]);
  1852. tmp10 = tmp0 + tmp7;
  1853. tmp14 = tmp0 - tmp7;
  1854. tmp11 = tmp1 + tmp6;
  1855. tmp15 = tmp1 - tmp6;
  1856. tmp12 = tmp2 + tmp5;
  1857. tmp16 = tmp2 - tmp5;
  1858. tmp13 = tmp3 + tmp4;
  1859. tmp17 = tmp3 - tmp4;
  1860. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[15]);
  1861. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[14]);
  1862. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[13]);
  1863. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[12]);
  1864. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[11]);
  1865. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[10]);
  1866. tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[9]);
  1867. tmp7 = GETJSAMPLE(elemptr[7]) - GETJSAMPLE(elemptr[8]);
  1868. /* Apply unsigned->signed conversion. */
  1869. dataptr[0] = (DCTELEM)
  1870. ((tmp10 + tmp11 + tmp12 + tmp13 - 16 * CENTERJSAMPLE) << PASS1_BITS);
  1871. dataptr[4] = (DCTELEM)
  1872. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */
  1873. MULTIPLY(tmp11 - tmp12, FIX_0_541196100), /* c12[16] = c6[8] */
  1874. CONST_BITS-PASS1_BITS);
  1875. tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) + /* c14[16] = c7[8] */
  1876. MULTIPLY(tmp14 - tmp16, FIX(1.387039845)); /* c2[16] = c1[8] */
  1877. dataptr[2] = (DCTELEM)
  1878. DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982)) /* c6+c14 */
  1879. + MULTIPLY(tmp16, FIX(2.172734804)), /* c2+c10 */
  1880. CONST_BITS-PASS1_BITS);
  1881. dataptr[6] = (DCTELEM)
  1882. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243)) /* c2-c6 */
  1883. - MULTIPLY(tmp17, FIX(1.061594338)), /* c10+c14 */
  1884. CONST_BITS-PASS1_BITS);
  1885. /* Odd part */
  1886. tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) + /* c3 */
  1887. MULTIPLY(tmp6 - tmp7, FIX(0.410524528)); /* c13 */
  1888. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) + /* c5 */
  1889. MULTIPLY(tmp5 + tmp7, FIX(0.666655658)); /* c11 */
  1890. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) + /* c7 */
  1891. MULTIPLY(tmp4 - tmp7, FIX(0.897167586)); /* c9 */
  1892. tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) + /* c15 */
  1893. MULTIPLY(tmp6 - tmp5, FIX(1.407403738)); /* c1 */
  1894. tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) + /* -c11 */
  1895. MULTIPLY(tmp4 + tmp6, - FIX(1.247225013)); /* -c5 */
  1896. tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) + /* -c3 */
  1897. MULTIPLY(tmp5 - tmp4, FIX(0.410524528)); /* c13 */
  1898. tmp10 = tmp11 + tmp12 + tmp13 -
  1899. MULTIPLY(tmp0, FIX(2.286341144)) + /* c7+c5+c3-c1 */
  1900. MULTIPLY(tmp7, FIX(0.779653625)); /* c15+c13-c11+c9 */
  1901. tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */
  1902. - MULTIPLY(tmp6, FIX(1.663905119)); /* c7+c13+c1-c5 */
  1903. tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */
  1904. + MULTIPLY(tmp5, FIX(1.227391138)); /* c9-c11+c1-c13 */
  1905. tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */
  1906. + MULTIPLY(tmp4, FIX(2.167985692)); /* c1+c13+c5-c9 */
  1907. dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
  1908. dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
  1909. dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
  1910. dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
  1911. ctr++;
  1912. if (ctr != DCTSIZE) {
  1913. if (ctr == DCTSIZE * 2)
  1914. break; /* Done. */
  1915. dataptr += DCTSIZE; /* advance pointer to next row */
  1916. } else
  1917. dataptr = workspace; /* switch pointer to extended workspace */
  1918. }
  1919. /* Pass 2: process columns.
  1920. * We remove the PASS1_BITS scaling, but leave the results scaled up
  1921. * by an overall factor of 8.
  1922. * We must also scale the output by (8/16)**2 = 1/2**2.
  1923. * cK represents sqrt(2) * cos(K*pi/32).
  1924. */
  1925. dataptr = data;
  1926. wsptr = workspace;
  1927. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1928. /* Even part */
  1929. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*7];
  1930. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*6];
  1931. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*5];
  1932. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*4];
  1933. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*3];
  1934. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*2];
  1935. tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*1];
  1936. tmp7 = dataptr[DCTSIZE*7] + wsptr[DCTSIZE*0];
  1937. tmp10 = tmp0 + tmp7;
  1938. tmp14 = tmp0 - tmp7;
  1939. tmp11 = tmp1 + tmp6;
  1940. tmp15 = tmp1 - tmp6;
  1941. tmp12 = tmp2 + tmp5;
  1942. tmp16 = tmp2 - tmp5;
  1943. tmp13 = tmp3 + tmp4;
  1944. tmp17 = tmp3 - tmp4;
  1945. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*7];
  1946. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*6];
  1947. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*5];
  1948. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*4];
  1949. tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*3];
  1950. tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*2];
  1951. tmp6 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*1];
  1952. tmp7 = dataptr[DCTSIZE*7] - wsptr[DCTSIZE*0];
  1953. dataptr[DCTSIZE*0] = (DCTELEM)
  1954. DESCALE(tmp10 + tmp11 + tmp12 + tmp13, PASS1_BITS+2);
  1955. dataptr[DCTSIZE*4] = (DCTELEM)
  1956. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */
  1957. MULTIPLY(tmp11 - tmp12, FIX_0_541196100), /* c12[16] = c6[8] */
  1958. CONST_BITS+PASS1_BITS+2);
  1959. tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) + /* c14[16] = c7[8] */
  1960. MULTIPLY(tmp14 - tmp16, FIX(1.387039845)); /* c2[16] = c1[8] */
  1961. dataptr[DCTSIZE*2] = (DCTELEM)
  1962. DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982)) /* c6+c14 */
  1963. + MULTIPLY(tmp16, FIX(2.172734804)), /* c2+10 */
  1964. CONST_BITS+PASS1_BITS+2);
  1965. dataptr[DCTSIZE*6] = (DCTELEM)
  1966. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243)) /* c2-c6 */
  1967. - MULTIPLY(tmp17, FIX(1.061594338)), /* c10+c14 */
  1968. CONST_BITS+PASS1_BITS+2);
  1969. /* Odd part */
  1970. tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) + /* c3 */
  1971. MULTIPLY(tmp6 - tmp7, FIX(0.410524528)); /* c13 */
  1972. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) + /* c5 */
  1973. MULTIPLY(tmp5 + tmp7, FIX(0.666655658)); /* c11 */
  1974. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) + /* c7 */
  1975. MULTIPLY(tmp4 - tmp7, FIX(0.897167586)); /* c9 */
  1976. tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) + /* c15 */
  1977. MULTIPLY(tmp6 - tmp5, FIX(1.407403738)); /* c1 */
  1978. tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) + /* -c11 */
  1979. MULTIPLY(tmp4 + tmp6, - FIX(1.247225013)); /* -c5 */
  1980. tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) + /* -c3 */
  1981. MULTIPLY(tmp5 - tmp4, FIX(0.410524528)); /* c13 */
  1982. tmp10 = tmp11 + tmp12 + tmp13 -
  1983. MULTIPLY(tmp0, FIX(2.286341144)) + /* c7+c5+c3-c1 */
  1984. MULTIPLY(tmp7, FIX(0.779653625)); /* c15+c13-c11+c9 */
  1985. tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */
  1986. - MULTIPLY(tmp6, FIX(1.663905119)); /* c7+c13+c1-c5 */
  1987. tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */
  1988. + MULTIPLY(tmp5, FIX(1.227391138)); /* c9-c11+c1-c13 */
  1989. tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */
  1990. + MULTIPLY(tmp4, FIX(2.167985692)); /* c1+c13+c5-c9 */
  1991. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS+2);
  1992. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS+2);
  1993. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS+2);
  1994. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS+2);
  1995. dataptr++; /* advance pointer to next column */
  1996. wsptr++; /* advance pointer to next column */
  1997. }
  1998. }
  1999. /*
  2000. * Perform the forward DCT on a 16x8 sample block.
  2001. *
  2002. * 16-point FDCT in pass 1 (rows), 8-point in pass 2 (columns).
  2003. */
  2004. GLOBAL(void)
  2005. jpeg_fdct_16x8 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2006. {
  2007. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  2008. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;
  2009. INT32 z1;
  2010. DCTELEM *dataptr;
  2011. JSAMPROW elemptr;
  2012. int ctr;
  2013. SHIFT_TEMPS
  2014. /* Pass 1: process rows.
  2015. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2016. * furthermore, we scale the results by 2**PASS1_BITS.
  2017. * 16-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/32).
  2018. */
  2019. dataptr = data;
  2020. ctr = 0;
  2021. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  2022. elemptr = sample_data[ctr] + start_col;
  2023. /* Even part */
  2024. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[15]);
  2025. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[14]);
  2026. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[13]);
  2027. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[12]);
  2028. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[11]);
  2029. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[10]);
  2030. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[9]);
  2031. tmp7 = GETJSAMPLE(elemptr[7]) + GETJSAMPLE(elemptr[8]);
  2032. tmp10 = tmp0 + tmp7;
  2033. tmp14 = tmp0 - tmp7;
  2034. tmp11 = tmp1 + tmp6;
  2035. tmp15 = tmp1 - tmp6;
  2036. tmp12 = tmp2 + tmp5;
  2037. tmp16 = tmp2 - tmp5;
  2038. tmp13 = tmp3 + tmp4;
  2039. tmp17 = tmp3 - tmp4;
  2040. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[15]);
  2041. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[14]);
  2042. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[13]);
  2043. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[12]);
  2044. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[11]);
  2045. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[10]);
  2046. tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[9]);
  2047. tmp7 = GETJSAMPLE(elemptr[7]) - GETJSAMPLE(elemptr[8]);
  2048. /* Apply unsigned->signed conversion. */
  2049. dataptr[0] = (DCTELEM)
  2050. ((tmp10 + tmp11 + tmp12 + tmp13 - 16 * CENTERJSAMPLE) << PASS1_BITS);
  2051. dataptr[4] = (DCTELEM)
  2052. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */
  2053. MULTIPLY(tmp11 - tmp12, FIX_0_541196100), /* c12[16] = c6[8] */
  2054. CONST_BITS-PASS1_BITS);
  2055. tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) + /* c14[16] = c7[8] */
  2056. MULTIPLY(tmp14 - tmp16, FIX(1.387039845)); /* c2[16] = c1[8] */
  2057. dataptr[2] = (DCTELEM)
  2058. DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982)) /* c6+c14 */
  2059. + MULTIPLY(tmp16, FIX(2.172734804)), /* c2+c10 */
  2060. CONST_BITS-PASS1_BITS);
  2061. dataptr[6] = (DCTELEM)
  2062. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243)) /* c2-c6 */
  2063. - MULTIPLY(tmp17, FIX(1.061594338)), /* c10+c14 */
  2064. CONST_BITS-PASS1_BITS);
  2065. /* Odd part */
  2066. tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) + /* c3 */
  2067. MULTIPLY(tmp6 - tmp7, FIX(0.410524528)); /* c13 */
  2068. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) + /* c5 */
  2069. MULTIPLY(tmp5 + tmp7, FIX(0.666655658)); /* c11 */
  2070. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) + /* c7 */
  2071. MULTIPLY(tmp4 - tmp7, FIX(0.897167586)); /* c9 */
  2072. tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) + /* c15 */
  2073. MULTIPLY(tmp6 - tmp5, FIX(1.407403738)); /* c1 */
  2074. tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) + /* -c11 */
  2075. MULTIPLY(tmp4 + tmp6, - FIX(1.247225013)); /* -c5 */
  2076. tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) + /* -c3 */
  2077. MULTIPLY(tmp5 - tmp4, FIX(0.410524528)); /* c13 */
  2078. tmp10 = tmp11 + tmp12 + tmp13 -
  2079. MULTIPLY(tmp0, FIX(2.286341144)) + /* c7+c5+c3-c1 */
  2080. MULTIPLY(tmp7, FIX(0.779653625)); /* c15+c13-c11+c9 */
  2081. tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */
  2082. - MULTIPLY(tmp6, FIX(1.663905119)); /* c7+c13+c1-c5 */
  2083. tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */
  2084. + MULTIPLY(tmp5, FIX(1.227391138)); /* c9-c11+c1-c13 */
  2085. tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */
  2086. + MULTIPLY(tmp4, FIX(2.167985692)); /* c1+c13+c5-c9 */
  2087. dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
  2088. dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
  2089. dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
  2090. dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
  2091. dataptr += DCTSIZE; /* advance pointer to next row */
  2092. }
  2093. /* Pass 2: process columns.
  2094. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2095. * by an overall factor of 8.
  2096. * We must also scale the output by 8/16 = 1/2.
  2097. * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
  2098. */
  2099. dataptr = data;
  2100. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2101. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  2102. * rotator "c1" should be "c6".
  2103. */
  2104. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  2105. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  2106. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  2107. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  2108. tmp10 = tmp0 + tmp3;
  2109. tmp12 = tmp0 - tmp3;
  2110. tmp11 = tmp1 + tmp2;
  2111. tmp13 = tmp1 - tmp2;
  2112. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  2113. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  2114. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  2115. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  2116. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS+1);
  2117. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS+1);
  2118. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  2119. dataptr[DCTSIZE*2] = (DCTELEM)
  2120. DESCALE(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  2121. CONST_BITS+PASS1_BITS+1);
  2122. dataptr[DCTSIZE*6] = (DCTELEM)
  2123. DESCALE(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  2124. CONST_BITS+PASS1_BITS+1);
  2125. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  2126. * i0..i3 in the paper are tmp0..tmp3 here.
  2127. */
  2128. tmp12 = tmp0 + tmp2;
  2129. tmp13 = tmp1 + tmp3;
  2130. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  2131. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  2132. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  2133. tmp12 += z1;
  2134. tmp13 += z1;
  2135. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  2136. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  2137. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  2138. tmp0 += z1 + tmp12;
  2139. tmp3 += z1 + tmp13;
  2140. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  2141. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  2142. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  2143. tmp1 += z1 + tmp13;
  2144. tmp2 += z1 + tmp12;
  2145. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS+1);
  2146. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS+1);
  2147. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS+1);
  2148. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+PASS1_BITS+1);
  2149. dataptr++; /* advance pointer to next column */
  2150. }
  2151. }
  2152. /*
  2153. * Perform the forward DCT on a 14x7 sample block.
  2154. *
  2155. * 14-point FDCT in pass 1 (rows), 7-point in pass 2 (columns).
  2156. */
  2157. GLOBAL(void)
  2158. jpeg_fdct_14x7 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2159. {
  2160. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  2161. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  2162. INT32 z1, z2, z3;
  2163. DCTELEM *dataptr;
  2164. JSAMPROW elemptr;
  2165. int ctr;
  2166. SHIFT_TEMPS
  2167. /* Zero bottom row of output coefficient block. */
  2168. MEMZERO(&data[DCTSIZE*7], SIZEOF(DCTELEM) * DCTSIZE);
  2169. /* Pass 1: process rows.
  2170. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2171. * furthermore, we scale the results by 2**PASS1_BITS.
  2172. * 14-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/28).
  2173. */
  2174. dataptr = data;
  2175. for (ctr = 0; ctr < 7; ctr++) {
  2176. elemptr = sample_data[ctr] + start_col;
  2177. /* Even part */
  2178. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[13]);
  2179. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[12]);
  2180. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[11]);
  2181. tmp13 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[10]);
  2182. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[9]);
  2183. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[8]);
  2184. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[7]);
  2185. tmp10 = tmp0 + tmp6;
  2186. tmp14 = tmp0 - tmp6;
  2187. tmp11 = tmp1 + tmp5;
  2188. tmp15 = tmp1 - tmp5;
  2189. tmp12 = tmp2 + tmp4;
  2190. tmp16 = tmp2 - tmp4;
  2191. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[13]);
  2192. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[12]);
  2193. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[11]);
  2194. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[10]);
  2195. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[9]);
  2196. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[8]);
  2197. tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[7]);
  2198. /* Apply unsigned->signed conversion. */
  2199. dataptr[0] = (DCTELEM)
  2200. ((tmp10 + tmp11 + tmp12 + tmp13 - 14 * CENTERJSAMPLE) << PASS1_BITS);
  2201. tmp13 += tmp13;
  2202. dataptr[4] = (DCTELEM)
  2203. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.274162392)) + /* c4 */
  2204. MULTIPLY(tmp11 - tmp13, FIX(0.314692123)) - /* c12 */
  2205. MULTIPLY(tmp12 - tmp13, FIX(0.881747734)), /* c8 */
  2206. CONST_BITS-PASS1_BITS);
  2207. tmp10 = MULTIPLY(tmp14 + tmp15, FIX(1.105676686)); /* c6 */
  2208. dataptr[2] = (DCTELEM)
  2209. DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.273079590)) /* c2-c6 */
  2210. + MULTIPLY(tmp16, FIX(0.613604268)), /* c10 */
  2211. CONST_BITS-PASS1_BITS);
  2212. dataptr[6] = (DCTELEM)
  2213. DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.719280954)) /* c6+c10 */
  2214. - MULTIPLY(tmp16, FIX(1.378756276)), /* c2 */
  2215. CONST_BITS-PASS1_BITS);
  2216. /* Odd part */
  2217. tmp10 = tmp1 + tmp2;
  2218. tmp11 = tmp5 - tmp4;
  2219. dataptr[7] = (DCTELEM) ((tmp0 - tmp10 + tmp3 - tmp11 - tmp6) << PASS1_BITS);
  2220. tmp3 <<= CONST_BITS;
  2221. tmp10 = MULTIPLY(tmp10, - FIX(0.158341681)); /* -c13 */
  2222. tmp11 = MULTIPLY(tmp11, FIX(1.405321284)); /* c1 */
  2223. tmp10 += tmp11 - tmp3;
  2224. tmp11 = MULTIPLY(tmp0 + tmp2, FIX(1.197448846)) + /* c5 */
  2225. MULTIPLY(tmp4 + tmp6, FIX(0.752406978)); /* c9 */
  2226. dataptr[5] = (DCTELEM)
  2227. DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(2.373959773)) /* c3+c5-c13 */
  2228. + MULTIPLY(tmp4, FIX(1.119999435)), /* c1+c11-c9 */
  2229. CONST_BITS-PASS1_BITS);
  2230. tmp12 = MULTIPLY(tmp0 + tmp1, FIX(1.334852607)) + /* c3 */
  2231. MULTIPLY(tmp5 - tmp6, FIX(0.467085129)); /* c11 */
  2232. dataptr[3] = (DCTELEM)
  2233. DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.424103948)) /* c3-c9-c13 */
  2234. - MULTIPLY(tmp5, FIX(3.069855259)), /* c1+c5+c11 */
  2235. CONST_BITS-PASS1_BITS);
  2236. dataptr[1] = (DCTELEM)
  2237. DESCALE(tmp11 + tmp12 + tmp3 + tmp6 -
  2238. MULTIPLY(tmp0 + tmp6, FIX(1.126980169)), /* c3+c5-c1 */
  2239. CONST_BITS-PASS1_BITS);
  2240. dataptr += DCTSIZE; /* advance pointer to next row */
  2241. }
  2242. /* Pass 2: process columns.
  2243. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2244. * by an overall factor of 8.
  2245. * We must also scale the output by (8/14)*(8/7) = 32/49, which we
  2246. * partially fold into the constant multipliers and final shifting:
  2247. * 7-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/14) * 64/49.
  2248. */
  2249. dataptr = data;
  2250. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2251. /* Even part */
  2252. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*6];
  2253. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*5];
  2254. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*4];
  2255. tmp3 = dataptr[DCTSIZE*3];
  2256. tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*6];
  2257. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*5];
  2258. tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*4];
  2259. z1 = tmp0 + tmp2;
  2260. dataptr[DCTSIZE*0] = (DCTELEM)
  2261. DESCALE(MULTIPLY(z1 + tmp1 + tmp3, FIX(1.306122449)), /* 64/49 */
  2262. CONST_BITS+PASS1_BITS+1);
  2263. tmp3 += tmp3;
  2264. z1 -= tmp3;
  2265. z1 -= tmp3;
  2266. z1 = MULTIPLY(z1, FIX(0.461784020)); /* (c2+c6-c4)/2 */
  2267. z2 = MULTIPLY(tmp0 - tmp2, FIX(1.202428084)); /* (c2+c4-c6)/2 */
  2268. z3 = MULTIPLY(tmp1 - tmp2, FIX(0.411026446)); /* c6 */
  2269. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS+PASS1_BITS+1);
  2270. z1 -= z2;
  2271. z2 = MULTIPLY(tmp0 - tmp1, FIX(1.151670509)); /* c4 */
  2272. dataptr[DCTSIZE*4] = (DCTELEM)
  2273. DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.923568041)), /* c2+c6-c4 */
  2274. CONST_BITS+PASS1_BITS+1);
  2275. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+PASS1_BITS+1);
  2276. /* Odd part */
  2277. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.221765677)); /* (c3+c1-c5)/2 */
  2278. tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.222383464)); /* (c3+c5-c1)/2 */
  2279. tmp0 = tmp1 - tmp2;
  2280. tmp1 += tmp2;
  2281. tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.800824523)); /* -c1 */
  2282. tmp1 += tmp2;
  2283. tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.801442310)); /* c5 */
  2284. tmp0 += tmp3;
  2285. tmp2 += tmp3 + MULTIPLY(tmp12, FIX(2.443531355)); /* c3+c1-c5 */
  2286. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS+1);
  2287. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS+1);
  2288. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS+1);
  2289. dataptr++; /* advance pointer to next column */
  2290. }
  2291. }
  2292. /*
  2293. * Perform the forward DCT on a 12x6 sample block.
  2294. *
  2295. * 12-point FDCT in pass 1 (rows), 6-point in pass 2 (columns).
  2296. */
  2297. GLOBAL(void)
  2298. jpeg_fdct_12x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2299. {
  2300. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  2301. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  2302. DCTELEM *dataptr;
  2303. JSAMPROW elemptr;
  2304. int ctr;
  2305. SHIFT_TEMPS
  2306. /* Zero 2 bottom rows of output coefficient block. */
  2307. MEMZERO(&data[DCTSIZE*6], SIZEOF(DCTELEM) * DCTSIZE * 2);
  2308. /* Pass 1: process rows.
  2309. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2310. * furthermore, we scale the results by 2**PASS1_BITS.
  2311. * 12-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/24).
  2312. */
  2313. dataptr = data;
  2314. for (ctr = 0; ctr < 6; ctr++) {
  2315. elemptr = sample_data[ctr] + start_col;
  2316. /* Even part */
  2317. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[11]);
  2318. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[10]);
  2319. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[9]);
  2320. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[8]);
  2321. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[7]);
  2322. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[6]);
  2323. tmp10 = tmp0 + tmp5;
  2324. tmp13 = tmp0 - tmp5;
  2325. tmp11 = tmp1 + tmp4;
  2326. tmp14 = tmp1 - tmp4;
  2327. tmp12 = tmp2 + tmp3;
  2328. tmp15 = tmp2 - tmp3;
  2329. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[11]);
  2330. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[10]);
  2331. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[9]);
  2332. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[8]);
  2333. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[7]);
  2334. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[6]);
  2335. /* Apply unsigned->signed conversion. */
  2336. dataptr[0] = (DCTELEM)
  2337. ((tmp10 + tmp11 + tmp12 - 12 * CENTERJSAMPLE) << PASS1_BITS);
  2338. dataptr[6] = (DCTELEM) ((tmp13 - tmp14 - tmp15) << PASS1_BITS);
  2339. dataptr[4] = (DCTELEM)
  2340. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.224744871)), /* c4 */
  2341. CONST_BITS-PASS1_BITS);
  2342. dataptr[2] = (DCTELEM)
  2343. DESCALE(tmp14 - tmp15 + MULTIPLY(tmp13 + tmp15, FIX(1.366025404)), /* c2 */
  2344. CONST_BITS-PASS1_BITS);
  2345. /* Odd part */
  2346. tmp10 = MULTIPLY(tmp1 + tmp4, FIX_0_541196100); /* c9 */
  2347. tmp14 = tmp10 + MULTIPLY(tmp1, FIX_0_765366865); /* c3-c9 */
  2348. tmp15 = tmp10 - MULTIPLY(tmp4, FIX_1_847759065); /* c3+c9 */
  2349. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.121971054)); /* c5 */
  2350. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.860918669)); /* c7 */
  2351. tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.580774953)) /* c5+c7-c1 */
  2352. + MULTIPLY(tmp5, FIX(0.184591911)); /* c11 */
  2353. tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.184591911)); /* -c11 */
  2354. tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.339493912)) /* c1+c5-c11 */
  2355. + MULTIPLY(tmp5, FIX(0.860918669)); /* c7 */
  2356. tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.725788011)) /* c1+c11-c7 */
  2357. - MULTIPLY(tmp5, FIX(1.121971054)); /* c5 */
  2358. tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.306562965)) /* c3 */
  2359. - MULTIPLY(tmp2 + tmp5, FIX_0_541196100); /* c9 */
  2360. dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
  2361. dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
  2362. dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
  2363. dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
  2364. dataptr += DCTSIZE; /* advance pointer to next row */
  2365. }
  2366. /* Pass 2: process columns.
  2367. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2368. * by an overall factor of 8.
  2369. * We must also scale the output by (8/12)*(8/6) = 8/9, which we
  2370. * partially fold into the constant multipliers and final shifting:
  2371. * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12) * 16/9.
  2372. */
  2373. dataptr = data;
  2374. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2375. /* Even part */
  2376. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];
  2377. tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];
  2378. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
  2379. tmp10 = tmp0 + tmp2;
  2380. tmp12 = tmp0 - tmp2;
  2381. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];
  2382. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];
  2383. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
  2384. dataptr[DCTSIZE*0] = (DCTELEM)
  2385. DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)), /* 16/9 */
  2386. CONST_BITS+PASS1_BITS+1);
  2387. dataptr[DCTSIZE*2] = (DCTELEM)
  2388. DESCALE(MULTIPLY(tmp12, FIX(2.177324216)), /* c2 */
  2389. CONST_BITS+PASS1_BITS+1);
  2390. dataptr[DCTSIZE*4] = (DCTELEM)
  2391. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */
  2392. CONST_BITS+PASS1_BITS+1);
  2393. /* Odd part */
  2394. tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829)); /* c5 */
  2395. dataptr[DCTSIZE*1] = (DCTELEM)
  2396. DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
  2397. CONST_BITS+PASS1_BITS+1);
  2398. dataptr[DCTSIZE*3] = (DCTELEM)
  2399. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)), /* 16/9 */
  2400. CONST_BITS+PASS1_BITS+1);
  2401. dataptr[DCTSIZE*5] = (DCTELEM)
  2402. DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)), /* 16/9 */
  2403. CONST_BITS+PASS1_BITS+1);
  2404. dataptr++; /* advance pointer to next column */
  2405. }
  2406. }
  2407. /*
  2408. * Perform the forward DCT on a 10x5 sample block.
  2409. *
  2410. * 10-point FDCT in pass 1 (rows), 5-point in pass 2 (columns).
  2411. */
  2412. GLOBAL(void)
  2413. jpeg_fdct_10x5 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2414. {
  2415. INT32 tmp0, tmp1, tmp2, tmp3, tmp4;
  2416. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  2417. DCTELEM *dataptr;
  2418. JSAMPROW elemptr;
  2419. int ctr;
  2420. SHIFT_TEMPS
  2421. /* Zero 3 bottom rows of output coefficient block. */
  2422. MEMZERO(&data[DCTSIZE*5], SIZEOF(DCTELEM) * DCTSIZE * 3);
  2423. /* Pass 1: process rows.
  2424. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2425. * furthermore, we scale the results by 2**PASS1_BITS.
  2426. * 10-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/20).
  2427. */
  2428. dataptr = data;
  2429. for (ctr = 0; ctr < 5; ctr++) {
  2430. elemptr = sample_data[ctr] + start_col;
  2431. /* Even part */
  2432. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[9]);
  2433. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[8]);
  2434. tmp12 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[7]);
  2435. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[6]);
  2436. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[5]);
  2437. tmp10 = tmp0 + tmp4;
  2438. tmp13 = tmp0 - tmp4;
  2439. tmp11 = tmp1 + tmp3;
  2440. tmp14 = tmp1 - tmp3;
  2441. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[9]);
  2442. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[8]);
  2443. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[7]);
  2444. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[6]);
  2445. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[5]);
  2446. /* Apply unsigned->signed conversion. */
  2447. dataptr[0] = (DCTELEM)
  2448. ((tmp10 + tmp11 + tmp12 - 10 * CENTERJSAMPLE) << PASS1_BITS);
  2449. tmp12 += tmp12;
  2450. dataptr[4] = (DCTELEM)
  2451. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.144122806)) - /* c4 */
  2452. MULTIPLY(tmp11 - tmp12, FIX(0.437016024)), /* c8 */
  2453. CONST_BITS-PASS1_BITS);
  2454. tmp10 = MULTIPLY(tmp13 + tmp14, FIX(0.831253876)); /* c6 */
  2455. dataptr[2] = (DCTELEM)
  2456. DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.513743148)), /* c2-c6 */
  2457. CONST_BITS-PASS1_BITS);
  2458. dataptr[6] = (DCTELEM)
  2459. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.176250899)), /* c2+c6 */
  2460. CONST_BITS-PASS1_BITS);
  2461. /* Odd part */
  2462. tmp10 = tmp0 + tmp4;
  2463. tmp11 = tmp1 - tmp3;
  2464. dataptr[5] = (DCTELEM) ((tmp10 - tmp11 - tmp2) << PASS1_BITS);
  2465. tmp2 <<= CONST_BITS;
  2466. dataptr[1] = (DCTELEM)
  2467. DESCALE(MULTIPLY(tmp0, FIX(1.396802247)) + /* c1 */
  2468. MULTIPLY(tmp1, FIX(1.260073511)) + tmp2 + /* c3 */
  2469. MULTIPLY(tmp3, FIX(0.642039522)) + /* c7 */
  2470. MULTIPLY(tmp4, FIX(0.221231742)), /* c9 */
  2471. CONST_BITS-PASS1_BITS);
  2472. tmp12 = MULTIPLY(tmp0 - tmp4, FIX(0.951056516)) - /* (c3+c7)/2 */
  2473. MULTIPLY(tmp1 + tmp3, FIX(0.587785252)); /* (c1-c9)/2 */
  2474. tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.309016994)) + /* (c3-c7)/2 */
  2475. (tmp11 << (CONST_BITS - 1)) - tmp2;
  2476. dataptr[3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS-PASS1_BITS);
  2477. dataptr[7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS-PASS1_BITS);
  2478. dataptr += DCTSIZE; /* advance pointer to next row */
  2479. }
  2480. /* Pass 2: process columns.
  2481. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2482. * by an overall factor of 8.
  2483. * We must also scale the output by (8/10)*(8/5) = 32/25, which we
  2484. * fold into the constant multipliers:
  2485. * 5-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/10) * 32/25.
  2486. */
  2487. dataptr = data;
  2488. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2489. /* Even part */
  2490. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*4];
  2491. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*3];
  2492. tmp2 = dataptr[DCTSIZE*2];
  2493. tmp10 = tmp0 + tmp1;
  2494. tmp11 = tmp0 - tmp1;
  2495. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*4];
  2496. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*3];
  2497. dataptr[DCTSIZE*0] = (DCTELEM)
  2498. DESCALE(MULTIPLY(tmp10 + tmp2, FIX(1.28)), /* 32/25 */
  2499. CONST_BITS+PASS1_BITS);
  2500. tmp11 = MULTIPLY(tmp11, FIX(1.011928851)); /* (c2+c4)/2 */
  2501. tmp10 -= tmp2 << 2;
  2502. tmp10 = MULTIPLY(tmp10, FIX(0.452548340)); /* (c2-c4)/2 */
  2503. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS+PASS1_BITS);
  2504. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS+PASS1_BITS);
  2505. /* Odd part */
  2506. tmp10 = MULTIPLY(tmp0 + tmp1, FIX(1.064004961)); /* c3 */
  2507. dataptr[DCTSIZE*1] = (DCTELEM)
  2508. DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.657591230)), /* c1-c3 */
  2509. CONST_BITS+PASS1_BITS);
  2510. dataptr[DCTSIZE*3] = (DCTELEM)
  2511. DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.785601151)), /* c1+c3 */
  2512. CONST_BITS+PASS1_BITS);
  2513. dataptr++; /* advance pointer to next column */
  2514. }
  2515. }
  2516. /*
  2517. * Perform the forward DCT on an 8x4 sample block.
  2518. *
  2519. * 8-point FDCT in pass 1 (rows), 4-point in pass 2 (columns).
  2520. */
  2521. GLOBAL(void)
  2522. jpeg_fdct_8x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2523. {
  2524. INT32 tmp0, tmp1, tmp2, tmp3;
  2525. INT32 tmp10, tmp11, tmp12, tmp13;
  2526. INT32 z1;
  2527. DCTELEM *dataptr;
  2528. JSAMPROW elemptr;
  2529. int ctr;
  2530. SHIFT_TEMPS
  2531. /* Zero 4 bottom rows of output coefficient block. */
  2532. MEMZERO(&data[DCTSIZE*4], SIZEOF(DCTELEM) * DCTSIZE * 4);
  2533. /* Pass 1: process rows.
  2534. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2535. * furthermore, we scale the results by 2**PASS1_BITS.
  2536. * We must also scale the output by 8/4 = 2, which we add here.
  2537. * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
  2538. */
  2539. dataptr = data;
  2540. for (ctr = 0; ctr < 4; ctr++) {
  2541. elemptr = sample_data[ctr] + start_col;
  2542. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  2543. * rotator "c1" should be "c6".
  2544. */
  2545. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);
  2546. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);
  2547. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);
  2548. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);
  2549. tmp10 = tmp0 + tmp3;
  2550. tmp12 = tmp0 - tmp3;
  2551. tmp11 = tmp1 + tmp2;
  2552. tmp13 = tmp1 - tmp2;
  2553. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);
  2554. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);
  2555. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);
  2556. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);
  2557. /* Apply unsigned->signed conversion. */
  2558. dataptr[0] = (DCTELEM)
  2559. ((tmp10 + tmp11 - 8 * CENTERJSAMPLE) << (PASS1_BITS+1));
  2560. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << (PASS1_BITS+1));
  2561. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  2562. /* Add fudge factor here for final descale. */
  2563. z1 += ONE << (CONST_BITS-PASS1_BITS-2);
  2564. dataptr[2] = (DCTELEM)
  2565. RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  2566. CONST_BITS-PASS1_BITS-1);
  2567. dataptr[6] = (DCTELEM)
  2568. RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  2569. CONST_BITS-PASS1_BITS-1);
  2570. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  2571. * i0..i3 in the paper are tmp0..tmp3 here.
  2572. */
  2573. tmp12 = tmp0 + tmp2;
  2574. tmp13 = tmp1 + tmp3;
  2575. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  2576. /* Add fudge factor here for final descale. */
  2577. z1 += ONE << (CONST_BITS-PASS1_BITS-2);
  2578. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  2579. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  2580. tmp12 += z1;
  2581. tmp13 += z1;
  2582. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  2583. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  2584. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  2585. tmp0 += z1 + tmp12;
  2586. tmp3 += z1 + tmp13;
  2587. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  2588. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  2589. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  2590. tmp1 += z1 + tmp13;
  2591. tmp2 += z1 + tmp12;
  2592. dataptr[1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS-PASS1_BITS-1);
  2593. dataptr[3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS-PASS1_BITS-1);
  2594. dataptr[5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS-1);
  2595. dataptr[7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS-PASS1_BITS-1);
  2596. dataptr += DCTSIZE; /* advance pointer to next row */
  2597. }
  2598. /* Pass 2: process columns.
  2599. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2600. * by an overall factor of 8.
  2601. * 4-point FDCT kernel,
  2602. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  2603. */
  2604. dataptr = data;
  2605. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2606. /* Even part */
  2607. /* Add fudge factor here for final descale. */
  2608. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*3] + (ONE << (PASS1_BITS-1));
  2609. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*2];
  2610. tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];
  2611. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];
  2612. dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp0 + tmp1, PASS1_BITS);
  2613. dataptr[DCTSIZE*2] = (DCTELEM) RIGHT_SHIFT(tmp0 - tmp1, PASS1_BITS);
  2614. /* Odd part */
  2615. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  2616. /* Add fudge factor here for final descale. */
  2617. tmp0 += ONE << (CONST_BITS+PASS1_BITS-1);
  2618. dataptr[DCTSIZE*1] = (DCTELEM)
  2619. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  2620. CONST_BITS+PASS1_BITS);
  2621. dataptr[DCTSIZE*3] = (DCTELEM)
  2622. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  2623. CONST_BITS+PASS1_BITS);
  2624. dataptr++; /* advance pointer to next column */
  2625. }
  2626. }
  2627. /*
  2628. * Perform the forward DCT on a 6x3 sample block.
  2629. *
  2630. * 6-point FDCT in pass 1 (rows), 3-point in pass 2 (columns).
  2631. */
  2632. GLOBAL(void)
  2633. jpeg_fdct_6x3 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2634. {
  2635. INT32 tmp0, tmp1, tmp2;
  2636. INT32 tmp10, tmp11, tmp12;
  2637. DCTELEM *dataptr;
  2638. JSAMPROW elemptr;
  2639. int ctr;
  2640. SHIFT_TEMPS
  2641. /* Pre-zero output coefficient block. */
  2642. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  2643. /* Pass 1: process rows.
  2644. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2645. * furthermore, we scale the results by 2**PASS1_BITS.
  2646. * We scale the results further by 2 as part of output adaption
  2647. * scaling for different DCT size.
  2648. * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12).
  2649. */
  2650. dataptr = data;
  2651. for (ctr = 0; ctr < 3; ctr++) {
  2652. elemptr = sample_data[ctr] + start_col;
  2653. /* Even part */
  2654. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);
  2655. tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);
  2656. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);
  2657. tmp10 = tmp0 + tmp2;
  2658. tmp12 = tmp0 - tmp2;
  2659. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);
  2660. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);
  2661. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);
  2662. /* Apply unsigned->signed conversion. */
  2663. dataptr[0] = (DCTELEM)
  2664. ((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << (PASS1_BITS+1));
  2665. dataptr[2] = (DCTELEM)
  2666. DESCALE(MULTIPLY(tmp12, FIX(1.224744871)), /* c2 */
  2667. CONST_BITS-PASS1_BITS-1);
  2668. dataptr[4] = (DCTELEM)
  2669. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */
  2670. CONST_BITS-PASS1_BITS-1);
  2671. /* Odd part */
  2672. tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)), /* c5 */
  2673. CONST_BITS-PASS1_BITS-1);
  2674. dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << (PASS1_BITS+1)));
  2675. dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << (PASS1_BITS+1));
  2676. dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << (PASS1_BITS+1)));
  2677. dataptr += DCTSIZE; /* advance pointer to next row */
  2678. }
  2679. /* Pass 2: process columns.
  2680. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2681. * by an overall factor of 8.
  2682. * We must also scale the output by (8/6)*(8/3) = 32/9, which we partially
  2683. * fold into the constant multipliers (other part was done in pass 1):
  2684. * 3-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/6) * 16/9.
  2685. */
  2686. dataptr = data;
  2687. for (ctr = 0; ctr < 6; ctr++) {
  2688. /* Even part */
  2689. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*2];
  2690. tmp1 = dataptr[DCTSIZE*1];
  2691. tmp2 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*2];
  2692. dataptr[DCTSIZE*0] = (DCTELEM)
  2693. DESCALE(MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
  2694. CONST_BITS+PASS1_BITS);
  2695. dataptr[DCTSIZE*2] = (DCTELEM)
  2696. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(1.257078722)), /* c2 */
  2697. CONST_BITS+PASS1_BITS);
  2698. /* Odd part */
  2699. dataptr[DCTSIZE*1] = (DCTELEM)
  2700. DESCALE(MULTIPLY(tmp2, FIX(2.177324216)), /* c1 */
  2701. CONST_BITS+PASS1_BITS);
  2702. dataptr++; /* advance pointer to next column */
  2703. }
  2704. }
  2705. /*
  2706. * Perform the forward DCT on a 4x2 sample block.
  2707. *
  2708. * 4-point FDCT in pass 1 (rows), 2-point in pass 2 (columns).
  2709. */
  2710. GLOBAL(void)
  2711. jpeg_fdct_4x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2712. {
  2713. DCTELEM tmp0, tmp2, tmp10, tmp12, tmp4, tmp5;
  2714. INT32 tmp1, tmp3, tmp11, tmp13;
  2715. INT32 z1, z2, z3;
  2716. JSAMPROW elemptr;
  2717. SHIFT_TEMPS
  2718. /* Pre-zero output coefficient block. */
  2719. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  2720. /* Pass 1: process rows.
  2721. * Note results are scaled up by sqrt(8) compared to a true DCT.
  2722. * 4-point FDCT kernel,
  2723. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  2724. */
  2725. /* Row 0 */
  2726. elemptr = sample_data[0] + start_col;
  2727. /* Even part */
  2728. tmp4 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);
  2729. tmp5 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);
  2730. tmp0 = tmp4 + tmp5;
  2731. tmp2 = tmp4 - tmp5;
  2732. /* Odd part */
  2733. z2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);
  2734. z3 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
  2735. z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
  2736. /* Add fudge factor here for final descale. */
  2737. z1 += ONE << (CONST_BITS-3-1);
  2738. tmp1 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
  2739. tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
  2740. /* Row 1 */
  2741. elemptr = sample_data[1] + start_col;
  2742. /* Even part */
  2743. tmp4 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);
  2744. tmp5 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);
  2745. tmp10 = tmp4 + tmp5;
  2746. tmp12 = tmp4 - tmp5;
  2747. /* Odd part */
  2748. z2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);
  2749. z3 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
  2750. z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
  2751. tmp11 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
  2752. tmp13 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
  2753. /* Pass 2: process columns.
  2754. * We leave the results scaled up by an overall factor of 8.
  2755. * We must also scale the output by (8/4)*(8/2) = 2**3.
  2756. */
  2757. /* Column 0 */
  2758. /* Apply unsigned->signed conversion. */
  2759. data[DCTSIZE*0] = (tmp0 + tmp10 - 8 * CENTERJSAMPLE) << 3;
  2760. data[DCTSIZE*1] = (tmp0 - tmp10) << 3;
  2761. /* Column 1 */
  2762. data[DCTSIZE*0+1] = (DCTELEM) RIGHT_SHIFT(tmp1 + tmp11, CONST_BITS-3);
  2763. data[DCTSIZE*1+1] = (DCTELEM) RIGHT_SHIFT(tmp1 - tmp11, CONST_BITS-3);
  2764. /* Column 2 */
  2765. data[DCTSIZE*0+2] = (tmp2 + tmp12) << 3;
  2766. data[DCTSIZE*1+2] = (tmp2 - tmp12) << 3;
  2767. /* Column 3 */
  2768. data[DCTSIZE*0+3] = (DCTELEM) RIGHT_SHIFT(tmp3 + tmp13, CONST_BITS-3);
  2769. data[DCTSIZE*1+3] = (DCTELEM) RIGHT_SHIFT(tmp3 - tmp13, CONST_BITS-3);
  2770. }
  2771. /*
  2772. * Perform the forward DCT on a 2x1 sample block.
  2773. *
  2774. * 2-point FDCT in pass 1 (rows), 1-point in pass 2 (columns).
  2775. */
  2776. GLOBAL(void)
  2777. jpeg_fdct_2x1 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2778. {
  2779. DCTELEM tmp0, tmp1;
  2780. JSAMPROW elemptr;
  2781. /* Pre-zero output coefficient block. */
  2782. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  2783. elemptr = sample_data[0] + start_col;
  2784. tmp0 = GETJSAMPLE(elemptr[0]);
  2785. tmp1 = GETJSAMPLE(elemptr[1]);
  2786. /* We leave the results scaled up by an overall factor of 8.
  2787. * We must also scale the output by (8/2)*(8/1) = 2**5.
  2788. */
  2789. /* Even part */
  2790. /* Apply unsigned->signed conversion. */
  2791. data[0] = (tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 5;
  2792. /* Odd part */
  2793. data[1] = (tmp0 - tmp1) << 5;
  2794. }
  2795. /*
  2796. * Perform the forward DCT on an 8x16 sample block.
  2797. *
  2798. * 8-point FDCT in pass 1 (rows), 16-point in pass 2 (columns).
  2799. */
  2800. GLOBAL(void)
  2801. jpeg_fdct_8x16 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2802. {
  2803. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  2804. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;
  2805. INT32 z1;
  2806. DCTELEM workspace[DCTSIZE2];
  2807. DCTELEM *dataptr;
  2808. DCTELEM *wsptr;
  2809. JSAMPROW elemptr;
  2810. int ctr;
  2811. SHIFT_TEMPS
  2812. /* Pass 1: process rows.
  2813. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2814. * furthermore, we scale the results by 2**PASS1_BITS.
  2815. * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
  2816. */
  2817. dataptr = data;
  2818. ctr = 0;
  2819. for (;;) {
  2820. elemptr = sample_data[ctr] + start_col;
  2821. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  2822. * rotator "c1" should be "c6".
  2823. */
  2824. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);
  2825. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);
  2826. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);
  2827. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);
  2828. tmp10 = tmp0 + tmp3;
  2829. tmp12 = tmp0 - tmp3;
  2830. tmp11 = tmp1 + tmp2;
  2831. tmp13 = tmp1 - tmp2;
  2832. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);
  2833. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);
  2834. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);
  2835. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);
  2836. /* Apply unsigned->signed conversion. */
  2837. dataptr[0] = (DCTELEM) ((tmp10 + tmp11 - 8 * CENTERJSAMPLE) << PASS1_BITS);
  2838. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  2839. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  2840. dataptr[2] = (DCTELEM)
  2841. DESCALE(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  2842. CONST_BITS-PASS1_BITS);
  2843. dataptr[6] = (DCTELEM)
  2844. DESCALE(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  2845. CONST_BITS-PASS1_BITS);
  2846. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  2847. * i0..i3 in the paper are tmp0..tmp3 here.
  2848. */
  2849. tmp12 = tmp0 + tmp2;
  2850. tmp13 = tmp1 + tmp3;
  2851. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  2852. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  2853. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  2854. tmp12 += z1;
  2855. tmp13 += z1;
  2856. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  2857. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  2858. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  2859. tmp0 += z1 + tmp12;
  2860. tmp3 += z1 + tmp13;
  2861. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  2862. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  2863. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  2864. tmp1 += z1 + tmp13;
  2865. tmp2 += z1 + tmp12;
  2866. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);
  2867. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);
  2868. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);
  2869. dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS-PASS1_BITS);
  2870. ctr++;
  2871. if (ctr != DCTSIZE) {
  2872. if (ctr == DCTSIZE * 2)
  2873. break; /* Done. */
  2874. dataptr += DCTSIZE; /* advance pointer to next row */
  2875. } else
  2876. dataptr = workspace; /* switch pointer to extended workspace */
  2877. }
  2878. /* Pass 2: process columns.
  2879. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2880. * by an overall factor of 8.
  2881. * We must also scale the output by 8/16 = 1/2.
  2882. * 16-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/32).
  2883. */
  2884. dataptr = data;
  2885. wsptr = workspace;
  2886. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2887. /* Even part */
  2888. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*7];
  2889. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*6];
  2890. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*5];
  2891. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*4];
  2892. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*3];
  2893. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*2];
  2894. tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*1];
  2895. tmp7 = dataptr[DCTSIZE*7] + wsptr[DCTSIZE*0];
  2896. tmp10 = tmp0 + tmp7;
  2897. tmp14 = tmp0 - tmp7;
  2898. tmp11 = tmp1 + tmp6;
  2899. tmp15 = tmp1 - tmp6;
  2900. tmp12 = tmp2 + tmp5;
  2901. tmp16 = tmp2 - tmp5;
  2902. tmp13 = tmp3 + tmp4;
  2903. tmp17 = tmp3 - tmp4;
  2904. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*7];
  2905. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*6];
  2906. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*5];
  2907. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*4];
  2908. tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*3];
  2909. tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*2];
  2910. tmp6 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*1];
  2911. tmp7 = dataptr[DCTSIZE*7] - wsptr[DCTSIZE*0];
  2912. dataptr[DCTSIZE*0] = (DCTELEM)
  2913. DESCALE(tmp10 + tmp11 + tmp12 + tmp13, PASS1_BITS+1);
  2914. dataptr[DCTSIZE*4] = (DCTELEM)
  2915. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */
  2916. MULTIPLY(tmp11 - tmp12, FIX_0_541196100), /* c12[16] = c6[8] */
  2917. CONST_BITS+PASS1_BITS+1);
  2918. tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) + /* c14[16] = c7[8] */
  2919. MULTIPLY(tmp14 - tmp16, FIX(1.387039845)); /* c2[16] = c1[8] */
  2920. dataptr[DCTSIZE*2] = (DCTELEM)
  2921. DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982)) /* c6+c14 */
  2922. + MULTIPLY(tmp16, FIX(2.172734804)), /* c2+c10 */
  2923. CONST_BITS+PASS1_BITS+1);
  2924. dataptr[DCTSIZE*6] = (DCTELEM)
  2925. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243)) /* c2-c6 */
  2926. - MULTIPLY(tmp17, FIX(1.061594338)), /* c10+c14 */
  2927. CONST_BITS+PASS1_BITS+1);
  2928. /* Odd part */
  2929. tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) + /* c3 */
  2930. MULTIPLY(tmp6 - tmp7, FIX(0.410524528)); /* c13 */
  2931. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) + /* c5 */
  2932. MULTIPLY(tmp5 + tmp7, FIX(0.666655658)); /* c11 */
  2933. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) + /* c7 */
  2934. MULTIPLY(tmp4 - tmp7, FIX(0.897167586)); /* c9 */
  2935. tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) + /* c15 */
  2936. MULTIPLY(tmp6 - tmp5, FIX(1.407403738)); /* c1 */
  2937. tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) + /* -c11 */
  2938. MULTIPLY(tmp4 + tmp6, - FIX(1.247225013)); /* -c5 */
  2939. tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) + /* -c3 */
  2940. MULTIPLY(tmp5 - tmp4, FIX(0.410524528)); /* c13 */
  2941. tmp10 = tmp11 + tmp12 + tmp13 -
  2942. MULTIPLY(tmp0, FIX(2.286341144)) + /* c7+c5+c3-c1 */
  2943. MULTIPLY(tmp7, FIX(0.779653625)); /* c15+c13-c11+c9 */
  2944. tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */
  2945. - MULTIPLY(tmp6, FIX(1.663905119)); /* c7+c13+c1-c5 */
  2946. tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */
  2947. + MULTIPLY(tmp5, FIX(1.227391138)); /* c9-c11+c1-c13 */
  2948. tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */
  2949. + MULTIPLY(tmp4, FIX(2.167985692)); /* c1+c13+c5-c9 */
  2950. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS+1);
  2951. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS+1);
  2952. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS+1);
  2953. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS+1);
  2954. dataptr++; /* advance pointer to next column */
  2955. wsptr++; /* advance pointer to next column */
  2956. }
  2957. }
  2958. /*
  2959. * Perform the forward DCT on a 7x14 sample block.
  2960. *
  2961. * 7-point FDCT in pass 1 (rows), 14-point in pass 2 (columns).
  2962. */
  2963. GLOBAL(void)
  2964. jpeg_fdct_7x14 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2965. {
  2966. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  2967. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  2968. INT32 z1, z2, z3;
  2969. DCTELEM workspace[8*6];
  2970. DCTELEM *dataptr;
  2971. DCTELEM *wsptr;
  2972. JSAMPROW elemptr;
  2973. int ctr;
  2974. SHIFT_TEMPS
  2975. /* Pre-zero output coefficient block. */
  2976. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  2977. /* Pass 1: process rows.
  2978. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2979. * furthermore, we scale the results by 2**PASS1_BITS.
  2980. * 7-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/14).
  2981. */
  2982. dataptr = data;
  2983. ctr = 0;
  2984. for (;;) {
  2985. elemptr = sample_data[ctr] + start_col;
  2986. /* Even part */
  2987. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[6]);
  2988. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[5]);
  2989. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[4]);
  2990. tmp3 = GETJSAMPLE(elemptr[3]);
  2991. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[6]);
  2992. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[5]);
  2993. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[4]);
  2994. z1 = tmp0 + tmp2;
  2995. /* Apply unsigned->signed conversion. */
  2996. dataptr[0] = (DCTELEM)
  2997. ((z1 + tmp1 + tmp3 - 7 * CENTERJSAMPLE) << PASS1_BITS);
  2998. tmp3 += tmp3;
  2999. z1 -= tmp3;
  3000. z1 -= tmp3;
  3001. z1 = MULTIPLY(z1, FIX(0.353553391)); /* (c2+c6-c4)/2 */
  3002. z2 = MULTIPLY(tmp0 - tmp2, FIX(0.920609002)); /* (c2+c4-c6)/2 */
  3003. z3 = MULTIPLY(tmp1 - tmp2, FIX(0.314692123)); /* c6 */
  3004. dataptr[2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS-PASS1_BITS);
  3005. z1 -= z2;
  3006. z2 = MULTIPLY(tmp0 - tmp1, FIX(0.881747734)); /* c4 */
  3007. dataptr[4] = (DCTELEM)
  3008. DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.707106781)), /* c2+c6-c4 */
  3009. CONST_BITS-PASS1_BITS);
  3010. dataptr[6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS-PASS1_BITS);
  3011. /* Odd part */
  3012. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(0.935414347)); /* (c3+c1-c5)/2 */
  3013. tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.170262339)); /* (c3+c5-c1)/2 */
  3014. tmp0 = tmp1 - tmp2;
  3015. tmp1 += tmp2;
  3016. tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.378756276)); /* -c1 */
  3017. tmp1 += tmp2;
  3018. tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.613604268)); /* c5 */
  3019. tmp0 += tmp3;
  3020. tmp2 += tmp3 + MULTIPLY(tmp12, FIX(1.870828693)); /* c3+c1-c5 */
  3021. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);
  3022. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);
  3023. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);
  3024. ctr++;
  3025. if (ctr != DCTSIZE) {
  3026. if (ctr == 14)
  3027. break; /* Done. */
  3028. dataptr += DCTSIZE; /* advance pointer to next row */
  3029. } else
  3030. dataptr = workspace; /* switch pointer to extended workspace */
  3031. }
  3032. /* Pass 2: process columns.
  3033. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3034. * by an overall factor of 8.
  3035. * We must also scale the output by (8/7)*(8/14) = 32/49, which we
  3036. * fold into the constant multipliers:
  3037. * 14-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/28) * 32/49.
  3038. */
  3039. dataptr = data;
  3040. wsptr = workspace;
  3041. for (ctr = 0; ctr < 7; ctr++) {
  3042. /* Even part */
  3043. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*5];
  3044. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*4];
  3045. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*3];
  3046. tmp13 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*2];
  3047. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*1];
  3048. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*0];
  3049. tmp6 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];
  3050. tmp10 = tmp0 + tmp6;
  3051. tmp14 = tmp0 - tmp6;
  3052. tmp11 = tmp1 + tmp5;
  3053. tmp15 = tmp1 - tmp5;
  3054. tmp12 = tmp2 + tmp4;
  3055. tmp16 = tmp2 - tmp4;
  3056. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*5];
  3057. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*4];
  3058. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*3];
  3059. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*2];
  3060. tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*1];
  3061. tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*0];
  3062. tmp6 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];
  3063. dataptr[DCTSIZE*0] = (DCTELEM)
  3064. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12 + tmp13,
  3065. FIX(0.653061224)), /* 32/49 */
  3066. CONST_BITS+PASS1_BITS);
  3067. tmp13 += tmp13;
  3068. dataptr[DCTSIZE*4] = (DCTELEM)
  3069. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(0.832106052)) + /* c4 */
  3070. MULTIPLY(tmp11 - tmp13, FIX(0.205513223)) - /* c12 */
  3071. MULTIPLY(tmp12 - tmp13, FIX(0.575835255)), /* c8 */
  3072. CONST_BITS+PASS1_BITS);
  3073. tmp10 = MULTIPLY(tmp14 + tmp15, FIX(0.722074570)); /* c6 */
  3074. dataptr[DCTSIZE*2] = (DCTELEM)
  3075. DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.178337691)) /* c2-c6 */
  3076. + MULTIPLY(tmp16, FIX(0.400721155)), /* c10 */
  3077. CONST_BITS+PASS1_BITS);
  3078. dataptr[DCTSIZE*6] = (DCTELEM)
  3079. DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.122795725)) /* c6+c10 */
  3080. - MULTIPLY(tmp16, FIX(0.900412262)), /* c2 */
  3081. CONST_BITS+PASS1_BITS);
  3082. /* Odd part */
  3083. tmp10 = tmp1 + tmp2;
  3084. tmp11 = tmp5 - tmp4;
  3085. dataptr[DCTSIZE*7] = (DCTELEM)
  3086. DESCALE(MULTIPLY(tmp0 - tmp10 + tmp3 - tmp11 - tmp6,
  3087. FIX(0.653061224)), /* 32/49 */
  3088. CONST_BITS+PASS1_BITS);
  3089. tmp3 = MULTIPLY(tmp3 , FIX(0.653061224)); /* 32/49 */
  3090. tmp10 = MULTIPLY(tmp10, - FIX(0.103406812)); /* -c13 */
  3091. tmp11 = MULTIPLY(tmp11, FIX(0.917760839)); /* c1 */
  3092. tmp10 += tmp11 - tmp3;
  3093. tmp11 = MULTIPLY(tmp0 + tmp2, FIX(0.782007410)) + /* c5 */
  3094. MULTIPLY(tmp4 + tmp6, FIX(0.491367823)); /* c9 */
  3095. dataptr[DCTSIZE*5] = (DCTELEM)
  3096. DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(1.550341076)) /* c3+c5-c13 */
  3097. + MULTIPLY(tmp4, FIX(0.731428202)), /* c1+c11-c9 */
  3098. CONST_BITS+PASS1_BITS);
  3099. tmp12 = MULTIPLY(tmp0 + tmp1, FIX(0.871740478)) + /* c3 */
  3100. MULTIPLY(tmp5 - tmp6, FIX(0.305035186)); /* c11 */
  3101. dataptr[DCTSIZE*3] = (DCTELEM)
  3102. DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.276965844)) /* c3-c9-c13 */
  3103. - MULTIPLY(tmp5, FIX(2.004803435)), /* c1+c5+c11 */
  3104. CONST_BITS+PASS1_BITS);
  3105. dataptr[DCTSIZE*1] = (DCTELEM)
  3106. DESCALE(tmp11 + tmp12 + tmp3
  3107. - MULTIPLY(tmp0, FIX(0.735987049)) /* c3+c5-c1 */
  3108. - MULTIPLY(tmp6, FIX(0.082925825)), /* c9-c11-c13 */
  3109. CONST_BITS+PASS1_BITS);
  3110. dataptr++; /* advance pointer to next column */
  3111. wsptr++; /* advance pointer to next column */
  3112. }
  3113. }
  3114. /*
  3115. * Perform the forward DCT on a 6x12 sample block.
  3116. *
  3117. * 6-point FDCT in pass 1 (rows), 12-point in pass 2 (columns).
  3118. */
  3119. GLOBAL(void)
  3120. jpeg_fdct_6x12 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3121. {
  3122. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  3123. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  3124. DCTELEM workspace[8*4];
  3125. DCTELEM *dataptr;
  3126. DCTELEM *wsptr;
  3127. JSAMPROW elemptr;
  3128. int ctr;
  3129. SHIFT_TEMPS
  3130. /* Pre-zero output coefficient block. */
  3131. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3132. /* Pass 1: process rows.
  3133. * Note results are scaled up by sqrt(8) compared to a true DCT;
  3134. * furthermore, we scale the results by 2**PASS1_BITS.
  3135. * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12).
  3136. */
  3137. dataptr = data;
  3138. ctr = 0;
  3139. for (;;) {
  3140. elemptr = sample_data[ctr] + start_col;
  3141. /* Even part */
  3142. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);
  3143. tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);
  3144. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);
  3145. tmp10 = tmp0 + tmp2;
  3146. tmp12 = tmp0 - tmp2;
  3147. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);
  3148. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);
  3149. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);
  3150. /* Apply unsigned->signed conversion. */
  3151. dataptr[0] = (DCTELEM)
  3152. ((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << PASS1_BITS);
  3153. dataptr[2] = (DCTELEM)
  3154. DESCALE(MULTIPLY(tmp12, FIX(1.224744871)), /* c2 */
  3155. CONST_BITS-PASS1_BITS);
  3156. dataptr[4] = (DCTELEM)
  3157. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */
  3158. CONST_BITS-PASS1_BITS);
  3159. /* Odd part */
  3160. tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)), /* c5 */
  3161. CONST_BITS-PASS1_BITS);
  3162. dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << PASS1_BITS));
  3163. dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << PASS1_BITS);
  3164. dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << PASS1_BITS));
  3165. ctr++;
  3166. if (ctr != DCTSIZE) {
  3167. if (ctr == 12)
  3168. break; /* Done. */
  3169. dataptr += DCTSIZE; /* advance pointer to next row */
  3170. } else
  3171. dataptr = workspace; /* switch pointer to extended workspace */
  3172. }
  3173. /* Pass 2: process columns.
  3174. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3175. * by an overall factor of 8.
  3176. * We must also scale the output by (8/6)*(8/12) = 8/9, which we
  3177. * fold into the constant multipliers:
  3178. * 12-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/24) * 8/9.
  3179. */
  3180. dataptr = data;
  3181. wsptr = workspace;
  3182. for (ctr = 0; ctr < 6; ctr++) {
  3183. /* Even part */
  3184. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*3];
  3185. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*2];
  3186. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*1];
  3187. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*0];
  3188. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*7];
  3189. tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*6];
  3190. tmp10 = tmp0 + tmp5;
  3191. tmp13 = tmp0 - tmp5;
  3192. tmp11 = tmp1 + tmp4;
  3193. tmp14 = tmp1 - tmp4;
  3194. tmp12 = tmp2 + tmp3;
  3195. tmp15 = tmp2 - tmp3;
  3196. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*3];
  3197. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*2];
  3198. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*1];
  3199. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*0];
  3200. tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*7];
  3201. tmp5 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*6];
  3202. dataptr[DCTSIZE*0] = (DCTELEM)
  3203. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(0.888888889)), /* 8/9 */
  3204. CONST_BITS+PASS1_BITS);
  3205. dataptr[DCTSIZE*6] = (DCTELEM)
  3206. DESCALE(MULTIPLY(tmp13 - tmp14 - tmp15, FIX(0.888888889)), /* 8/9 */
  3207. CONST_BITS+PASS1_BITS);
  3208. dataptr[DCTSIZE*4] = (DCTELEM)
  3209. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.088662108)), /* c4 */
  3210. CONST_BITS+PASS1_BITS);
  3211. dataptr[DCTSIZE*2] = (DCTELEM)
  3212. DESCALE(MULTIPLY(tmp14 - tmp15, FIX(0.888888889)) + /* 8/9 */
  3213. MULTIPLY(tmp13 + tmp15, FIX(1.214244803)), /* c2 */
  3214. CONST_BITS+PASS1_BITS);
  3215. /* Odd part */
  3216. tmp10 = MULTIPLY(tmp1 + tmp4, FIX(0.481063200)); /* c9 */
  3217. tmp14 = tmp10 + MULTIPLY(tmp1, FIX(0.680326102)); /* c3-c9 */
  3218. tmp15 = tmp10 - MULTIPLY(tmp4, FIX(1.642452502)); /* c3+c9 */
  3219. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(0.997307603)); /* c5 */
  3220. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.765261039)); /* c7 */
  3221. tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.516244403)) /* c5+c7-c1 */
  3222. + MULTIPLY(tmp5, FIX(0.164081699)); /* c11 */
  3223. tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.164081699)); /* -c11 */
  3224. tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.079550144)) /* c1+c5-c11 */
  3225. + MULTIPLY(tmp5, FIX(0.765261039)); /* c7 */
  3226. tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.645144899)) /* c1+c11-c7 */
  3227. - MULTIPLY(tmp5, FIX(0.997307603)); /* c5 */
  3228. tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.161389302)) /* c3 */
  3229. - MULTIPLY(tmp2 + tmp5, FIX(0.481063200)); /* c9 */
  3230. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS);
  3231. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS);
  3232. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS);
  3233. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS);
  3234. dataptr++; /* advance pointer to next column */
  3235. wsptr++; /* advance pointer to next column */
  3236. }
  3237. }
  3238. /*
  3239. * Perform the forward DCT on a 5x10 sample block.
  3240. *
  3241. * 5-point FDCT in pass 1 (rows), 10-point in pass 2 (columns).
  3242. */
  3243. GLOBAL(void)
  3244. jpeg_fdct_5x10 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3245. {
  3246. INT32 tmp0, tmp1, tmp2, tmp3, tmp4;
  3247. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  3248. DCTELEM workspace[8*2];
  3249. DCTELEM *dataptr;
  3250. DCTELEM *wsptr;
  3251. JSAMPROW elemptr;
  3252. int ctr;
  3253. SHIFT_TEMPS
  3254. /* Pre-zero output coefficient block. */
  3255. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3256. /* Pass 1: process rows.
  3257. * Note results are scaled up by sqrt(8) compared to a true DCT;
  3258. * furthermore, we scale the results by 2**PASS1_BITS.
  3259. * 5-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/10).
  3260. */
  3261. dataptr = data;
  3262. ctr = 0;
  3263. for (;;) {
  3264. elemptr = sample_data[ctr] + start_col;
  3265. /* Even part */
  3266. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[4]);
  3267. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[3]);
  3268. tmp2 = GETJSAMPLE(elemptr[2]);
  3269. tmp10 = tmp0 + tmp1;
  3270. tmp11 = tmp0 - tmp1;
  3271. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[4]);
  3272. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[3]);
  3273. /* Apply unsigned->signed conversion. */
  3274. dataptr[0] = (DCTELEM)
  3275. ((tmp10 + tmp2 - 5 * CENTERJSAMPLE) << PASS1_BITS);
  3276. tmp11 = MULTIPLY(tmp11, FIX(0.790569415)); /* (c2+c4)/2 */
  3277. tmp10 -= tmp2 << 2;
  3278. tmp10 = MULTIPLY(tmp10, FIX(0.353553391)); /* (c2-c4)/2 */
  3279. dataptr[2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS-PASS1_BITS);
  3280. dataptr[4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS-PASS1_BITS);
  3281. /* Odd part */
  3282. tmp10 = MULTIPLY(tmp0 + tmp1, FIX(0.831253876)); /* c3 */
  3283. dataptr[1] = (DCTELEM)
  3284. DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.513743148)), /* c1-c3 */
  3285. CONST_BITS-PASS1_BITS);
  3286. dataptr[3] = (DCTELEM)
  3287. DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.176250899)), /* c1+c3 */
  3288. CONST_BITS-PASS1_BITS);
  3289. ctr++;
  3290. if (ctr != DCTSIZE) {
  3291. if (ctr == 10)
  3292. break; /* Done. */
  3293. dataptr += DCTSIZE; /* advance pointer to next row */
  3294. } else
  3295. dataptr = workspace; /* switch pointer to extended workspace */
  3296. }
  3297. /* Pass 2: process columns.
  3298. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3299. * by an overall factor of 8.
  3300. * We must also scale the output by (8/5)*(8/10) = 32/25, which we
  3301. * fold into the constant multipliers:
  3302. * 10-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/20) * 32/25.
  3303. */
  3304. dataptr = data;
  3305. wsptr = workspace;
  3306. for (ctr = 0; ctr < 5; ctr++) {
  3307. /* Even part */
  3308. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*1];
  3309. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*0];
  3310. tmp12 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*7];
  3311. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*6];
  3312. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];
  3313. tmp10 = tmp0 + tmp4;
  3314. tmp13 = tmp0 - tmp4;
  3315. tmp11 = tmp1 + tmp3;
  3316. tmp14 = tmp1 - tmp3;
  3317. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*1];
  3318. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*0];
  3319. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*7];
  3320. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*6];
  3321. tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];
  3322. dataptr[DCTSIZE*0] = (DCTELEM)
  3323. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(1.28)), /* 32/25 */
  3324. CONST_BITS+PASS1_BITS);
  3325. tmp12 += tmp12;
  3326. dataptr[DCTSIZE*4] = (DCTELEM)
  3327. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.464477191)) - /* c4 */
  3328. MULTIPLY(tmp11 - tmp12, FIX(0.559380511)), /* c8 */
  3329. CONST_BITS+PASS1_BITS);
  3330. tmp10 = MULTIPLY(tmp13 + tmp14, FIX(1.064004961)); /* c6 */
  3331. dataptr[DCTSIZE*2] = (DCTELEM)
  3332. DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.657591230)), /* c2-c6 */
  3333. CONST_BITS+PASS1_BITS);
  3334. dataptr[DCTSIZE*6] = (DCTELEM)
  3335. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.785601151)), /* c2+c6 */
  3336. CONST_BITS+PASS1_BITS);
  3337. /* Odd part */
  3338. tmp10 = tmp0 + tmp4;
  3339. tmp11 = tmp1 - tmp3;
  3340. dataptr[DCTSIZE*5] = (DCTELEM)
  3341. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp2, FIX(1.28)), /* 32/25 */
  3342. CONST_BITS+PASS1_BITS);
  3343. tmp2 = MULTIPLY(tmp2, FIX(1.28)); /* 32/25 */
  3344. dataptr[DCTSIZE*1] = (DCTELEM)
  3345. DESCALE(MULTIPLY(tmp0, FIX(1.787906876)) + /* c1 */
  3346. MULTIPLY(tmp1, FIX(1.612894094)) + tmp2 + /* c3 */
  3347. MULTIPLY(tmp3, FIX(0.821810588)) + /* c7 */
  3348. MULTIPLY(tmp4, FIX(0.283176630)), /* c9 */
  3349. CONST_BITS+PASS1_BITS);
  3350. tmp12 = MULTIPLY(tmp0 - tmp4, FIX(1.217352341)) - /* (c3+c7)/2 */
  3351. MULTIPLY(tmp1 + tmp3, FIX(0.752365123)); /* (c1-c9)/2 */
  3352. tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.395541753)) + /* (c3-c7)/2 */
  3353. MULTIPLY(tmp11, FIX(0.64)) - tmp2; /* 16/25 */
  3354. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS+PASS1_BITS);
  3355. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS+PASS1_BITS);
  3356. dataptr++; /* advance pointer to next column */
  3357. wsptr++; /* advance pointer to next column */
  3358. }
  3359. }
  3360. /*
  3361. * Perform the forward DCT on a 4x8 sample block.
  3362. *
  3363. * 4-point FDCT in pass 1 (rows), 8-point in pass 2 (columns).
  3364. */
  3365. GLOBAL(void)
  3366. jpeg_fdct_4x8 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3367. {
  3368. INT32 tmp0, tmp1, tmp2, tmp3;
  3369. INT32 tmp10, tmp11, tmp12, tmp13;
  3370. INT32 z1;
  3371. DCTELEM *dataptr;
  3372. JSAMPROW elemptr;
  3373. int ctr;
  3374. SHIFT_TEMPS
  3375. /* Pre-zero output coefficient block. */
  3376. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3377. /* Pass 1: process rows.
  3378. * Note results are scaled up by sqrt(8) compared to a true DCT;
  3379. * furthermore, we scale the results by 2**PASS1_BITS.
  3380. * We must also scale the output by 8/4 = 2, which we add here.
  3381. * 4-point FDCT kernel,
  3382. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  3383. */
  3384. dataptr = data;
  3385. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  3386. elemptr = sample_data[ctr] + start_col;
  3387. /* Even part */
  3388. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);
  3389. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);
  3390. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);
  3391. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
  3392. /* Apply unsigned->signed conversion. */
  3393. dataptr[0] = (DCTELEM)
  3394. ((tmp0 + tmp1 - 4 * CENTERJSAMPLE) << (PASS1_BITS+1));
  3395. dataptr[2] = (DCTELEM) ((tmp0 - tmp1) << (PASS1_BITS+1));
  3396. /* Odd part */
  3397. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  3398. /* Add fudge factor here for final descale. */
  3399. tmp0 += ONE << (CONST_BITS-PASS1_BITS-2);
  3400. dataptr[1] = (DCTELEM)
  3401. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  3402. CONST_BITS-PASS1_BITS-1);
  3403. dataptr[3] = (DCTELEM)
  3404. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  3405. CONST_BITS-PASS1_BITS-1);
  3406. dataptr += DCTSIZE; /* advance pointer to next row */
  3407. }
  3408. /* Pass 2: process columns.
  3409. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3410. * by an overall factor of 8.
  3411. * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
  3412. */
  3413. dataptr = data;
  3414. for (ctr = 0; ctr < 4; ctr++) {
  3415. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  3416. * rotator "c1" should be "c6".
  3417. */
  3418. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  3419. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  3420. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  3421. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  3422. /* Add fudge factor here for final descale. */
  3423. tmp10 = tmp0 + tmp3 + (ONE << (PASS1_BITS-1));
  3424. tmp12 = tmp0 - tmp3;
  3425. tmp11 = tmp1 + tmp2;
  3426. tmp13 = tmp1 - tmp2;
  3427. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  3428. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  3429. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  3430. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  3431. dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp10 + tmp11, PASS1_BITS);
  3432. dataptr[DCTSIZE*4] = (DCTELEM) RIGHT_SHIFT(tmp10 - tmp11, PASS1_BITS);
  3433. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  3434. /* Add fudge factor here for final descale. */
  3435. z1 += ONE << (CONST_BITS+PASS1_BITS-1);
  3436. dataptr[DCTSIZE*2] = (DCTELEM)
  3437. RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  3438. CONST_BITS+PASS1_BITS);
  3439. dataptr[DCTSIZE*6] = (DCTELEM)
  3440. RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  3441. CONST_BITS+PASS1_BITS);
  3442. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  3443. * i0..i3 in the paper are tmp0..tmp3 here.
  3444. */
  3445. tmp12 = tmp0 + tmp2;
  3446. tmp13 = tmp1 + tmp3;
  3447. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  3448. /* Add fudge factor here for final descale. */
  3449. z1 += ONE << (CONST_BITS+PASS1_BITS-1);
  3450. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  3451. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  3452. tmp12 += z1;
  3453. tmp13 += z1;
  3454. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  3455. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  3456. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  3457. tmp0 += z1 + tmp12;
  3458. tmp3 += z1 + tmp13;
  3459. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  3460. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  3461. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  3462. tmp1 += z1 + tmp13;
  3463. tmp2 += z1 + tmp12;
  3464. dataptr[DCTSIZE*1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS+PASS1_BITS);
  3465. dataptr[DCTSIZE*3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS+PASS1_BITS);
  3466. dataptr[DCTSIZE*5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS+PASS1_BITS);
  3467. dataptr[DCTSIZE*7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS+PASS1_BITS);
  3468. dataptr++; /* advance pointer to next column */
  3469. }
  3470. }
  3471. /*
  3472. * Perform the forward DCT on a 3x6 sample block.
  3473. *
  3474. * 3-point FDCT in pass 1 (rows), 6-point in pass 2 (columns).
  3475. */
  3476. GLOBAL(void)
  3477. jpeg_fdct_3x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3478. {
  3479. INT32 tmp0, tmp1, tmp2;
  3480. INT32 tmp10, tmp11, tmp12;
  3481. DCTELEM *dataptr;
  3482. JSAMPROW elemptr;
  3483. int ctr;
  3484. SHIFT_TEMPS
  3485. /* Pre-zero output coefficient block. */
  3486. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3487. /* Pass 1: process rows.
  3488. * Note results are scaled up by sqrt(8) compared to a true DCT;
  3489. * furthermore, we scale the results by 2**PASS1_BITS.
  3490. * We scale the results further by 2 as part of output adaption
  3491. * scaling for different DCT size.
  3492. * 3-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/6).
  3493. */
  3494. dataptr = data;
  3495. for (ctr = 0; ctr < 6; ctr++) {
  3496. elemptr = sample_data[ctr] + start_col;
  3497. /* Even part */
  3498. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[2]);
  3499. tmp1 = GETJSAMPLE(elemptr[1]);
  3500. tmp2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[2]);
  3501. /* Apply unsigned->signed conversion. */
  3502. dataptr[0] = (DCTELEM)
  3503. ((tmp0 + tmp1 - 3 * CENTERJSAMPLE) << (PASS1_BITS+1));
  3504. dataptr[2] = (DCTELEM)
  3505. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(0.707106781)), /* c2 */
  3506. CONST_BITS-PASS1_BITS-1);
  3507. /* Odd part */
  3508. dataptr[1] = (DCTELEM)
  3509. DESCALE(MULTIPLY(tmp2, FIX(1.224744871)), /* c1 */
  3510. CONST_BITS-PASS1_BITS-1);
  3511. dataptr += DCTSIZE; /* advance pointer to next row */
  3512. }
  3513. /* Pass 2: process columns.
  3514. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3515. * by an overall factor of 8.
  3516. * We must also scale the output by (8/6)*(8/3) = 32/9, which we partially
  3517. * fold into the constant multipliers (other part was done in pass 1):
  3518. * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12) * 16/9.
  3519. */
  3520. dataptr = data;
  3521. for (ctr = 0; ctr < 3; ctr++) {
  3522. /* Even part */
  3523. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];
  3524. tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];
  3525. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
  3526. tmp10 = tmp0 + tmp2;
  3527. tmp12 = tmp0 - tmp2;
  3528. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];
  3529. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];
  3530. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
  3531. dataptr[DCTSIZE*0] = (DCTELEM)
  3532. DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)), /* 16/9 */
  3533. CONST_BITS+PASS1_BITS);
  3534. dataptr[DCTSIZE*2] = (DCTELEM)
  3535. DESCALE(MULTIPLY(tmp12, FIX(2.177324216)), /* c2 */
  3536. CONST_BITS+PASS1_BITS);
  3537. dataptr[DCTSIZE*4] = (DCTELEM)
  3538. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */
  3539. CONST_BITS+PASS1_BITS);
  3540. /* Odd part */
  3541. tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829)); /* c5 */
  3542. dataptr[DCTSIZE*1] = (DCTELEM)
  3543. DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
  3544. CONST_BITS+PASS1_BITS);
  3545. dataptr[DCTSIZE*3] = (DCTELEM)
  3546. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)), /* 16/9 */
  3547. CONST_BITS+PASS1_BITS);
  3548. dataptr[DCTSIZE*5] = (DCTELEM)
  3549. DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)), /* 16/9 */
  3550. CONST_BITS+PASS1_BITS);
  3551. dataptr++; /* advance pointer to next column */
  3552. }
  3553. }
  3554. /*
  3555. * Perform the forward DCT on a 2x4 sample block.
  3556. *
  3557. * 2-point FDCT in pass 1 (rows), 4-point in pass 2 (columns).
  3558. */
  3559. GLOBAL(void)
  3560. jpeg_fdct_2x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3561. {
  3562. INT32 tmp0, tmp1;
  3563. INT32 tmp10, tmp11;
  3564. DCTELEM *dataptr;
  3565. JSAMPROW elemptr;
  3566. int ctr;
  3567. SHIFT_TEMPS
  3568. /* Pre-zero output coefficient block. */
  3569. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3570. /* Pass 1: process rows.
  3571. * Note results are scaled up by sqrt(8) compared to a true DCT.
  3572. */
  3573. dataptr = data;
  3574. for (ctr = 0; ctr < 4; ctr++) {
  3575. elemptr = sample_data[ctr] + start_col;
  3576. /* Even part */
  3577. tmp0 = GETJSAMPLE(elemptr[0]);
  3578. tmp1 = GETJSAMPLE(elemptr[1]);
  3579. /* Apply unsigned->signed conversion. */
  3580. dataptr[0] = (DCTELEM) (tmp0 + tmp1 - 2 * CENTERJSAMPLE);
  3581. /* Odd part */
  3582. dataptr[1] = (DCTELEM) (tmp0 - tmp1);
  3583. dataptr += DCTSIZE; /* advance pointer to next row */
  3584. }
  3585. /* Pass 2: process columns.
  3586. * We leave the results scaled up by an overall factor of 8.
  3587. * We must also scale the output by (8/2)*(8/4) = 2**3.
  3588. * 4-point FDCT kernel,
  3589. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  3590. */
  3591. dataptr = data;
  3592. for (ctr = 0; ctr < 2; ctr++) {
  3593. /* Even part */
  3594. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*3];
  3595. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*2];
  3596. tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];
  3597. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];
  3598. dataptr[DCTSIZE*0] = (DCTELEM) ((tmp0 + tmp1) << 3);
  3599. dataptr[DCTSIZE*2] = (DCTELEM) ((tmp0 - tmp1) << 3);
  3600. /* Odd part */
  3601. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  3602. /* Add fudge factor here for final descale. */
  3603. tmp0 += ONE << (CONST_BITS-3-1);
  3604. dataptr[DCTSIZE*1] = (DCTELEM)
  3605. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  3606. CONST_BITS-3);
  3607. dataptr[DCTSIZE*3] = (DCTELEM)
  3608. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  3609. CONST_BITS-3);
  3610. dataptr++; /* advance pointer to next column */
  3611. }
  3612. }
  3613. /*
  3614. * Perform the forward DCT on a 1x2 sample block.
  3615. *
  3616. * 1-point FDCT in pass 1 (rows), 2-point in pass 2 (columns).
  3617. */
  3618. GLOBAL(void)
  3619. jpeg_fdct_1x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3620. {
  3621. DCTELEM tmp0, tmp1;
  3622. /* Pre-zero output coefficient block. */
  3623. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3624. /* Pass 1: empty. */
  3625. /* Pass 2: process columns.
  3626. * We leave the results scaled up by an overall factor of 8.
  3627. * We must also scale the output by (8/1)*(8/2) = 2**5.
  3628. */
  3629. /* Even part */
  3630. tmp0 = GETJSAMPLE(sample_data[0][start_col]);
  3631. tmp1 = GETJSAMPLE(sample_data[1][start_col]);
  3632. /* Apply unsigned->signed conversion. */
  3633. data[DCTSIZE*0] = (tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 5;
  3634. /* Odd part */
  3635. data[DCTSIZE*1] = (tmp0 - tmp1) << 5;
  3636. }
  3637. #endif /* DCT_SCALING_SUPPORTED */
  3638. #endif /* DCT_ISLOW_SUPPORTED */