jfdctint.c 155 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415
  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 */