jfdctint.c 155 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406
  1. /*
  2. * jfdctint.c
  3. *
  4. * Copyright (C) 1991-1996, Thomas G. Lane.
  5. * Modification developed 2003-2013 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. INT32 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] = (DCTELEM) ((tmp0 + tmp2 - 4 * CENTERJSAMPLE) << 4);
  731. data[DCTSIZE*1] = (DCTELEM) ((tmp0 - tmp2) << 4);
  732. /* Column 1 */
  733. data[DCTSIZE*0+1] = (DCTELEM) ((tmp1 + tmp3) << 4);
  734. data[DCTSIZE*1+1] = (DCTELEM) ((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. /* Pre-zero output coefficient block. */
  743. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  744. /* We leave the result scaled up by an overall factor of 8. */
  745. /* We must also scale the output by (8/1)**2 = 2**6. */
  746. /* Apply unsigned->signed conversion */
  747. data[0] = (DCTELEM)
  748. ((GETJSAMPLE(sample_data[0][start_col]) - CENTERJSAMPLE) << 6);
  749. }
  750. /*
  751. * Perform the forward DCT on a 9x9 sample block.
  752. */
  753. GLOBAL(void)
  754. jpeg_fdct_9x9 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  755. {
  756. INT32 tmp0, tmp1, tmp2, tmp3, tmp4;
  757. INT32 tmp10, tmp11, tmp12, tmp13;
  758. INT32 z1, z2;
  759. DCTELEM workspace[8];
  760. DCTELEM *dataptr;
  761. DCTELEM *wsptr;
  762. JSAMPROW elemptr;
  763. int ctr;
  764. SHIFT_TEMPS
  765. /* Pass 1: process rows.
  766. * Note results are scaled up by sqrt(8) compared to a true DCT;
  767. * we scale the results further by 2 as part of output adaption
  768. * scaling for different DCT size.
  769. * cK represents sqrt(2) * cos(K*pi/18).
  770. */
  771. dataptr = data;
  772. ctr = 0;
  773. for (;;) {
  774. elemptr = sample_data[ctr] + start_col;
  775. /* Even part */
  776. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[8]);
  777. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[7]);
  778. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[6]);
  779. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[5]);
  780. tmp4 = GETJSAMPLE(elemptr[4]);
  781. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[8]);
  782. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[7]);
  783. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[6]);
  784. tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[5]);
  785. z1 = tmp0 + tmp2 + tmp3;
  786. z2 = tmp1 + tmp4;
  787. /* Apply unsigned->signed conversion */
  788. dataptr[0] = (DCTELEM) ((z1 + z2 - 9 * CENTERJSAMPLE) << 1);
  789. dataptr[6] = (DCTELEM)
  790. DESCALE(MULTIPLY(z1 - z2 - z2, FIX(0.707106781)), /* c6 */
  791. CONST_BITS-1);
  792. z1 = MULTIPLY(tmp0 - tmp2, FIX(1.328926049)); /* c2 */
  793. z2 = MULTIPLY(tmp1 - tmp4 - tmp4, FIX(0.707106781)); /* c6 */
  794. dataptr[2] = (DCTELEM)
  795. DESCALE(MULTIPLY(tmp2 - tmp3, FIX(1.083350441)) /* c4 */
  796. + z1 + z2, CONST_BITS-1);
  797. dataptr[4] = (DCTELEM)
  798. DESCALE(MULTIPLY(tmp3 - tmp0, FIX(0.245575608)) /* c8 */
  799. + z1 - z2, CONST_BITS-1);
  800. /* Odd part */
  801. dataptr[3] = (DCTELEM)
  802. DESCALE(MULTIPLY(tmp10 - tmp12 - tmp13, FIX(1.224744871)), /* c3 */
  803. CONST_BITS-1);
  804. tmp11 = MULTIPLY(tmp11, FIX(1.224744871)); /* c3 */
  805. tmp0 = MULTIPLY(tmp10 + tmp12, FIX(0.909038955)); /* c5 */
  806. tmp1 = MULTIPLY(tmp10 + tmp13, FIX(0.483689525)); /* c7 */
  807. dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp0 + tmp1, CONST_BITS-1);
  808. tmp2 = MULTIPLY(tmp12 - tmp13, FIX(1.392728481)); /* c1 */
  809. dataptr[5] = (DCTELEM) DESCALE(tmp0 - tmp11 - tmp2, CONST_BITS-1);
  810. dataptr[7] = (DCTELEM) DESCALE(tmp1 - tmp11 + tmp2, CONST_BITS-1);
  811. ctr++;
  812. if (ctr != DCTSIZE) {
  813. if (ctr == 9)
  814. break; /* Done. */
  815. dataptr += DCTSIZE; /* advance pointer to next row */
  816. } else
  817. dataptr = workspace; /* switch pointer to extended workspace */
  818. }
  819. /* Pass 2: process columns.
  820. * We leave the results scaled up by an overall factor of 8.
  821. * We must also scale the output by (8/9)**2 = 64/81, which we partially
  822. * fold into the constant multipliers and final/initial shifting:
  823. * cK now represents sqrt(2) * cos(K*pi/18) * 128/81.
  824. */
  825. dataptr = data;
  826. wsptr = workspace;
  827. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  828. /* Even part */
  829. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*0];
  830. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*7];
  831. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*6];
  832. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*5];
  833. tmp4 = dataptr[DCTSIZE*4];
  834. tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*0];
  835. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*7];
  836. tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*6];
  837. tmp13 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*5];
  838. z1 = tmp0 + tmp2 + tmp3;
  839. z2 = tmp1 + tmp4;
  840. dataptr[DCTSIZE*0] = (DCTELEM)
  841. DESCALE(MULTIPLY(z1 + z2, FIX(1.580246914)), /* 128/81 */
  842. CONST_BITS+2);
  843. dataptr[DCTSIZE*6] = (DCTELEM)
  844. DESCALE(MULTIPLY(z1 - z2 - z2, FIX(1.117403309)), /* c6 */
  845. CONST_BITS+2);
  846. z1 = MULTIPLY(tmp0 - tmp2, FIX(2.100031287)); /* c2 */
  847. z2 = MULTIPLY(tmp1 - tmp4 - tmp4, FIX(1.117403309)); /* c6 */
  848. dataptr[DCTSIZE*2] = (DCTELEM)
  849. DESCALE(MULTIPLY(tmp2 - tmp3, FIX(1.711961190)) /* c4 */
  850. + z1 + z2, CONST_BITS+2);
  851. dataptr[DCTSIZE*4] = (DCTELEM)
  852. DESCALE(MULTIPLY(tmp3 - tmp0, FIX(0.388070096)) /* c8 */
  853. + z1 - z2, CONST_BITS+2);
  854. /* Odd part */
  855. dataptr[DCTSIZE*3] = (DCTELEM)
  856. DESCALE(MULTIPLY(tmp10 - tmp12 - tmp13, FIX(1.935399303)), /* c3 */
  857. CONST_BITS+2);
  858. tmp11 = MULTIPLY(tmp11, FIX(1.935399303)); /* c3 */
  859. tmp0 = MULTIPLY(tmp10 + tmp12, FIX(1.436506004)); /* c5 */
  860. tmp1 = MULTIPLY(tmp10 + tmp13, FIX(0.764348879)); /* c7 */
  861. dataptr[DCTSIZE*1] = (DCTELEM)
  862. DESCALE(tmp11 + tmp0 + tmp1, CONST_BITS+2);
  863. tmp2 = MULTIPLY(tmp12 - tmp13, FIX(2.200854883)); /* c1 */
  864. dataptr[DCTSIZE*5] = (DCTELEM)
  865. DESCALE(tmp0 - tmp11 - tmp2, CONST_BITS+2);
  866. dataptr[DCTSIZE*7] = (DCTELEM)
  867. DESCALE(tmp1 - tmp11 + tmp2, CONST_BITS+2);
  868. dataptr++; /* advance pointer to next column */
  869. wsptr++; /* advance pointer to next column */
  870. }
  871. }
  872. /*
  873. * Perform the forward DCT on a 10x10 sample block.
  874. */
  875. GLOBAL(void)
  876. jpeg_fdct_10x10 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  877. {
  878. INT32 tmp0, tmp1, tmp2, tmp3, tmp4;
  879. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  880. DCTELEM workspace[8*2];
  881. DCTELEM *dataptr;
  882. DCTELEM *wsptr;
  883. JSAMPROW elemptr;
  884. int ctr;
  885. SHIFT_TEMPS
  886. /* Pass 1: process rows.
  887. * Note results are scaled up by sqrt(8) compared to a true DCT;
  888. * we scale the results further by 2 as part of output adaption
  889. * scaling for different DCT size.
  890. * cK represents sqrt(2) * cos(K*pi/20).
  891. */
  892. dataptr = data;
  893. ctr = 0;
  894. for (;;) {
  895. elemptr = sample_data[ctr] + start_col;
  896. /* Even part */
  897. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[9]);
  898. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[8]);
  899. tmp12 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[7]);
  900. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[6]);
  901. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[5]);
  902. tmp10 = tmp0 + tmp4;
  903. tmp13 = tmp0 - tmp4;
  904. tmp11 = tmp1 + tmp3;
  905. tmp14 = tmp1 - tmp3;
  906. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[9]);
  907. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[8]);
  908. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[7]);
  909. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[6]);
  910. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[5]);
  911. /* Apply unsigned->signed conversion */
  912. dataptr[0] = (DCTELEM)
  913. ((tmp10 + tmp11 + tmp12 - 10 * CENTERJSAMPLE) << 1);
  914. tmp12 += tmp12;
  915. dataptr[4] = (DCTELEM)
  916. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.144122806)) - /* c4 */
  917. MULTIPLY(tmp11 - tmp12, FIX(0.437016024)), /* c8 */
  918. CONST_BITS-1);
  919. tmp10 = MULTIPLY(tmp13 + tmp14, FIX(0.831253876)); /* c6 */
  920. dataptr[2] = (DCTELEM)
  921. DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.513743148)), /* c2-c6 */
  922. CONST_BITS-1);
  923. dataptr[6] = (DCTELEM)
  924. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.176250899)), /* c2+c6 */
  925. CONST_BITS-1);
  926. /* Odd part */
  927. tmp10 = tmp0 + tmp4;
  928. tmp11 = tmp1 - tmp3;
  929. dataptr[5] = (DCTELEM) ((tmp10 - tmp11 - tmp2) << 1);
  930. tmp2 <<= CONST_BITS;
  931. dataptr[1] = (DCTELEM)
  932. DESCALE(MULTIPLY(tmp0, FIX(1.396802247)) + /* c1 */
  933. MULTIPLY(tmp1, FIX(1.260073511)) + tmp2 + /* c3 */
  934. MULTIPLY(tmp3, FIX(0.642039522)) + /* c7 */
  935. MULTIPLY(tmp4, FIX(0.221231742)), /* c9 */
  936. CONST_BITS-1);
  937. tmp12 = MULTIPLY(tmp0 - tmp4, FIX(0.951056516)) - /* (c3+c7)/2 */
  938. MULTIPLY(tmp1 + tmp3, FIX(0.587785252)); /* (c1-c9)/2 */
  939. tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.309016994)) + /* (c3-c7)/2 */
  940. (tmp11 << (CONST_BITS - 1)) - tmp2;
  941. dataptr[3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS-1);
  942. dataptr[7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS-1);
  943. ctr++;
  944. if (ctr != DCTSIZE) {
  945. if (ctr == 10)
  946. break; /* Done. */
  947. dataptr += DCTSIZE; /* advance pointer to next row */
  948. } else
  949. dataptr = workspace; /* switch pointer to extended workspace */
  950. }
  951. /* Pass 2: process columns.
  952. * We leave the results scaled up by an overall factor of 8.
  953. * We must also scale the output by (8/10)**2 = 16/25, which we partially
  954. * fold into the constant multipliers and final/initial shifting:
  955. * cK now represents sqrt(2) * cos(K*pi/20) * 32/25.
  956. */
  957. dataptr = data;
  958. wsptr = workspace;
  959. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  960. /* Even part */
  961. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*1];
  962. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*0];
  963. tmp12 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*7];
  964. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*6];
  965. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];
  966. tmp10 = tmp0 + tmp4;
  967. tmp13 = tmp0 - tmp4;
  968. tmp11 = tmp1 + tmp3;
  969. tmp14 = tmp1 - tmp3;
  970. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*1];
  971. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*0];
  972. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*7];
  973. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*6];
  974. tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];
  975. dataptr[DCTSIZE*0] = (DCTELEM)
  976. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(1.28)), /* 32/25 */
  977. CONST_BITS+2);
  978. tmp12 += tmp12;
  979. dataptr[DCTSIZE*4] = (DCTELEM)
  980. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.464477191)) - /* c4 */
  981. MULTIPLY(tmp11 - tmp12, FIX(0.559380511)), /* c8 */
  982. CONST_BITS+2);
  983. tmp10 = MULTIPLY(tmp13 + tmp14, FIX(1.064004961)); /* c6 */
  984. dataptr[DCTSIZE*2] = (DCTELEM)
  985. DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.657591230)), /* c2-c6 */
  986. CONST_BITS+2);
  987. dataptr[DCTSIZE*6] = (DCTELEM)
  988. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.785601151)), /* c2+c6 */
  989. CONST_BITS+2);
  990. /* Odd part */
  991. tmp10 = tmp0 + tmp4;
  992. tmp11 = tmp1 - tmp3;
  993. dataptr[DCTSIZE*5] = (DCTELEM)
  994. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp2, FIX(1.28)), /* 32/25 */
  995. CONST_BITS+2);
  996. tmp2 = MULTIPLY(tmp2, FIX(1.28)); /* 32/25 */
  997. dataptr[DCTSIZE*1] = (DCTELEM)
  998. DESCALE(MULTIPLY(tmp0, FIX(1.787906876)) + /* c1 */
  999. MULTIPLY(tmp1, FIX(1.612894094)) + tmp2 + /* c3 */
  1000. MULTIPLY(tmp3, FIX(0.821810588)) + /* c7 */
  1001. MULTIPLY(tmp4, FIX(0.283176630)), /* c9 */
  1002. CONST_BITS+2);
  1003. tmp12 = MULTIPLY(tmp0 - tmp4, FIX(1.217352341)) - /* (c3+c7)/2 */
  1004. MULTIPLY(tmp1 + tmp3, FIX(0.752365123)); /* (c1-c9)/2 */
  1005. tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.395541753)) + /* (c3-c7)/2 */
  1006. MULTIPLY(tmp11, FIX(0.64)) - tmp2; /* 16/25 */
  1007. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS+2);
  1008. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS+2);
  1009. dataptr++; /* advance pointer to next column */
  1010. wsptr++; /* advance pointer to next column */
  1011. }
  1012. }
  1013. /*
  1014. * Perform the forward DCT on an 11x11 sample block.
  1015. */
  1016. GLOBAL(void)
  1017. jpeg_fdct_11x11 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1018. {
  1019. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  1020. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  1021. INT32 z1, z2, z3;
  1022. DCTELEM workspace[8*3];
  1023. DCTELEM *dataptr;
  1024. DCTELEM *wsptr;
  1025. JSAMPROW elemptr;
  1026. int ctr;
  1027. SHIFT_TEMPS
  1028. /* Pass 1: process rows.
  1029. * Note results are scaled up by sqrt(8) compared to a true DCT;
  1030. * we scale the results further by 2 as part of output adaption
  1031. * scaling for different DCT size.
  1032. * cK represents sqrt(2) * cos(K*pi/22).
  1033. */
  1034. dataptr = data;
  1035. ctr = 0;
  1036. for (;;) {
  1037. elemptr = sample_data[ctr] + start_col;
  1038. /* Even part */
  1039. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[10]);
  1040. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[9]);
  1041. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[8]);
  1042. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[7]);
  1043. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[6]);
  1044. tmp5 = GETJSAMPLE(elemptr[5]);
  1045. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[10]);
  1046. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[9]);
  1047. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[8]);
  1048. tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[7]);
  1049. tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[6]);
  1050. /* Apply unsigned->signed conversion */
  1051. dataptr[0] = (DCTELEM)
  1052. ((tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 - 11 * CENTERJSAMPLE) << 1);
  1053. tmp5 += tmp5;
  1054. tmp0 -= tmp5;
  1055. tmp1 -= tmp5;
  1056. tmp2 -= tmp5;
  1057. tmp3 -= tmp5;
  1058. tmp4 -= tmp5;
  1059. z1 = MULTIPLY(tmp0 + tmp3, FIX(1.356927976)) + /* c2 */
  1060. MULTIPLY(tmp2 + tmp4, FIX(0.201263574)); /* c10 */
  1061. z2 = MULTIPLY(tmp1 - tmp3, FIX(0.926112931)); /* c6 */
  1062. z3 = MULTIPLY(tmp0 - tmp1, FIX(1.189712156)); /* c4 */
  1063. dataptr[2] = (DCTELEM)
  1064. DESCALE(z1 + z2 - MULTIPLY(tmp3, FIX(1.018300590)) /* c2+c8-c6 */
  1065. - MULTIPLY(tmp4, FIX(1.390975730)), /* c4+c10 */
  1066. CONST_BITS-1);
  1067. dataptr[4] = (DCTELEM)
  1068. DESCALE(z2 + z3 + MULTIPLY(tmp1, FIX(0.062335650)) /* c4-c6-c10 */
  1069. - MULTIPLY(tmp2, FIX(1.356927976)) /* c2 */
  1070. + MULTIPLY(tmp4, FIX(0.587485545)), /* c8 */
  1071. CONST_BITS-1);
  1072. dataptr[6] = (DCTELEM)
  1073. DESCALE(z1 + z3 - MULTIPLY(tmp0, FIX(1.620527200)) /* c2+c4-c6 */
  1074. - MULTIPLY(tmp2, FIX(0.788749120)), /* c8+c10 */
  1075. CONST_BITS-1);
  1076. /* Odd part */
  1077. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.286413905)); /* c3 */
  1078. tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.068791298)); /* c5 */
  1079. tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.764581576)); /* c7 */
  1080. tmp0 = tmp1 + tmp2 + tmp3 - MULTIPLY(tmp10, FIX(1.719967871)) /* c7+c5+c3-c1 */
  1081. + MULTIPLY(tmp14, FIX(0.398430003)); /* c9 */
  1082. tmp4 = MULTIPLY(tmp11 + tmp12, - FIX(0.764581576)); /* -c7 */
  1083. tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.399818907)); /* -c1 */
  1084. tmp1 += tmp4 + tmp5 + MULTIPLY(tmp11, FIX(1.276416582)) /* c9+c7+c1-c3 */
  1085. - MULTIPLY(tmp14, FIX(1.068791298)); /* c5 */
  1086. tmp10 = MULTIPLY(tmp12 + tmp13, FIX(0.398430003)); /* c9 */
  1087. tmp2 += tmp4 + tmp10 - MULTIPLY(tmp12, FIX(1.989053629)) /* c9+c5+c3-c7 */
  1088. + MULTIPLY(tmp14, FIX(1.399818907)); /* c1 */
  1089. tmp3 += tmp5 + tmp10 + MULTIPLY(tmp13, FIX(1.305598626)) /* c1+c5-c9-c7 */
  1090. - MULTIPLY(tmp14, FIX(1.286413905)); /* c3 */
  1091. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-1);
  1092. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-1);
  1093. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-1);
  1094. dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS-1);
  1095. ctr++;
  1096. if (ctr != DCTSIZE) {
  1097. if (ctr == 11)
  1098. break; /* Done. */
  1099. dataptr += DCTSIZE; /* advance pointer to next row */
  1100. } else
  1101. dataptr = workspace; /* switch pointer to extended workspace */
  1102. }
  1103. /* Pass 2: process columns.
  1104. * We leave the results scaled up by an overall factor of 8.
  1105. * We must also scale the output by (8/11)**2 = 64/121, which we partially
  1106. * fold into the constant multipliers and final/initial shifting:
  1107. * cK now represents sqrt(2) * cos(K*pi/22) * 128/121.
  1108. */
  1109. dataptr = data;
  1110. wsptr = workspace;
  1111. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1112. /* Even part */
  1113. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*2];
  1114. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*1];
  1115. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*0];
  1116. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*7];
  1117. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*6];
  1118. tmp5 = dataptr[DCTSIZE*5];
  1119. tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*2];
  1120. tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*1];
  1121. tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*0];
  1122. tmp13 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*7];
  1123. tmp14 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*6];
  1124. dataptr[DCTSIZE*0] = (DCTELEM)
  1125. DESCALE(MULTIPLY(tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5,
  1126. FIX(1.057851240)), /* 128/121 */
  1127. CONST_BITS+2);
  1128. tmp5 += tmp5;
  1129. tmp0 -= tmp5;
  1130. tmp1 -= tmp5;
  1131. tmp2 -= tmp5;
  1132. tmp3 -= tmp5;
  1133. tmp4 -= tmp5;
  1134. z1 = MULTIPLY(tmp0 + tmp3, FIX(1.435427942)) + /* c2 */
  1135. MULTIPLY(tmp2 + tmp4, FIX(0.212906922)); /* c10 */
  1136. z2 = MULTIPLY(tmp1 - tmp3, FIX(0.979689713)); /* c6 */
  1137. z3 = MULTIPLY(tmp0 - tmp1, FIX(1.258538479)); /* c4 */
  1138. dataptr[DCTSIZE*2] = (DCTELEM)
  1139. DESCALE(z1 + z2 - MULTIPLY(tmp3, FIX(1.077210542)) /* c2+c8-c6 */
  1140. - MULTIPLY(tmp4, FIX(1.471445400)), /* c4+c10 */
  1141. CONST_BITS+2);
  1142. dataptr[DCTSIZE*4] = (DCTELEM)
  1143. DESCALE(z2 + z3 + MULTIPLY(tmp1, FIX(0.065941844)) /* c4-c6-c10 */
  1144. - MULTIPLY(tmp2, FIX(1.435427942)) /* c2 */
  1145. + MULTIPLY(tmp4, FIX(0.621472312)), /* c8 */
  1146. CONST_BITS+2);
  1147. dataptr[DCTSIZE*6] = (DCTELEM)
  1148. DESCALE(z1 + z3 - MULTIPLY(tmp0, FIX(1.714276708)) /* c2+c4-c6 */
  1149. - MULTIPLY(tmp2, FIX(0.834379234)), /* c8+c10 */
  1150. CONST_BITS+2);
  1151. /* Odd part */
  1152. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.360834544)); /* c3 */
  1153. tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.130622199)); /* c5 */
  1154. tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.808813568)); /* c7 */
  1155. tmp0 = tmp1 + tmp2 + tmp3 - MULTIPLY(tmp10, FIX(1.819470145)) /* c7+c5+c3-c1 */
  1156. + MULTIPLY(tmp14, FIX(0.421479672)); /* c9 */
  1157. tmp4 = MULTIPLY(tmp11 + tmp12, - FIX(0.808813568)); /* -c7 */
  1158. tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.480800167)); /* -c1 */
  1159. tmp1 += tmp4 + tmp5 + MULTIPLY(tmp11, FIX(1.350258864)) /* c9+c7+c1-c3 */
  1160. - MULTIPLY(tmp14, FIX(1.130622199)); /* c5 */
  1161. tmp10 = MULTIPLY(tmp12 + tmp13, FIX(0.421479672)); /* c9 */
  1162. tmp2 += tmp4 + tmp10 - MULTIPLY(tmp12, FIX(2.104122847)) /* c9+c5+c3-c7 */
  1163. + MULTIPLY(tmp14, FIX(1.480800167)); /* c1 */
  1164. tmp3 += tmp5 + tmp10 + MULTIPLY(tmp13, FIX(1.381129125)) /* c1+c5-c9-c7 */
  1165. - MULTIPLY(tmp14, FIX(1.360834544)); /* c3 */
  1166. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+2);
  1167. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+2);
  1168. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+2);
  1169. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+2);
  1170. dataptr++; /* advance pointer to next column */
  1171. wsptr++; /* advance pointer to next column */
  1172. }
  1173. }
  1174. /*
  1175. * Perform the forward DCT on a 12x12 sample block.
  1176. */
  1177. GLOBAL(void)
  1178. jpeg_fdct_12x12 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1179. {
  1180. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  1181. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  1182. DCTELEM workspace[8*4];
  1183. DCTELEM *dataptr;
  1184. DCTELEM *wsptr;
  1185. JSAMPROW elemptr;
  1186. int ctr;
  1187. SHIFT_TEMPS
  1188. /* Pass 1: process rows.
  1189. * Note results are scaled up by sqrt(8) compared to a true DCT.
  1190. * cK represents sqrt(2) * cos(K*pi/24).
  1191. */
  1192. dataptr = data;
  1193. ctr = 0;
  1194. for (;;) {
  1195. elemptr = sample_data[ctr] + start_col;
  1196. /* Even part */
  1197. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[11]);
  1198. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[10]);
  1199. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[9]);
  1200. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[8]);
  1201. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[7]);
  1202. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[6]);
  1203. tmp10 = tmp0 + tmp5;
  1204. tmp13 = tmp0 - tmp5;
  1205. tmp11 = tmp1 + tmp4;
  1206. tmp14 = tmp1 - tmp4;
  1207. tmp12 = tmp2 + tmp3;
  1208. tmp15 = tmp2 - tmp3;
  1209. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[11]);
  1210. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[10]);
  1211. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[9]);
  1212. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[8]);
  1213. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[7]);
  1214. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[6]);
  1215. /* Apply unsigned->signed conversion */
  1216. dataptr[0] = (DCTELEM) (tmp10 + tmp11 + tmp12 - 12 * CENTERJSAMPLE);
  1217. dataptr[6] = (DCTELEM) (tmp13 - tmp14 - tmp15);
  1218. dataptr[4] = (DCTELEM)
  1219. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.224744871)), /* c4 */
  1220. CONST_BITS);
  1221. dataptr[2] = (DCTELEM)
  1222. DESCALE(tmp14 - tmp15 + MULTIPLY(tmp13 + tmp15, FIX(1.366025404)), /* c2 */
  1223. CONST_BITS);
  1224. /* Odd part */
  1225. tmp10 = MULTIPLY(tmp1 + tmp4, FIX_0_541196100); /* c9 */
  1226. tmp14 = tmp10 + MULTIPLY(tmp1, FIX_0_765366865); /* c3-c9 */
  1227. tmp15 = tmp10 - MULTIPLY(tmp4, FIX_1_847759065); /* c3+c9 */
  1228. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.121971054)); /* c5 */
  1229. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.860918669)); /* c7 */
  1230. tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.580774953)) /* c5+c7-c1 */
  1231. + MULTIPLY(tmp5, FIX(0.184591911)); /* c11 */
  1232. tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.184591911)); /* -c11 */
  1233. tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.339493912)) /* c1+c5-c11 */
  1234. + MULTIPLY(tmp5, FIX(0.860918669)); /* c7 */
  1235. tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.725788011)) /* c1+c11-c7 */
  1236. - MULTIPLY(tmp5, FIX(1.121971054)); /* c5 */
  1237. tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.306562965)) /* c3 */
  1238. - MULTIPLY(tmp2 + tmp5, FIX_0_541196100); /* c9 */
  1239. dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS);
  1240. dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS);
  1241. dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS);
  1242. dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS);
  1243. ctr++;
  1244. if (ctr != DCTSIZE) {
  1245. if (ctr == 12)
  1246. break; /* Done. */
  1247. dataptr += DCTSIZE; /* advance pointer to next row */
  1248. } else
  1249. dataptr = workspace; /* switch pointer to extended workspace */
  1250. }
  1251. /* Pass 2: process columns.
  1252. * We leave the results scaled up by an overall factor of 8.
  1253. * We must also scale the output by (8/12)**2 = 4/9, which we partially
  1254. * fold into the constant multipliers and final shifting:
  1255. * cK now represents sqrt(2) * cos(K*pi/24) * 8/9.
  1256. */
  1257. dataptr = data;
  1258. wsptr = workspace;
  1259. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1260. /* Even part */
  1261. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*3];
  1262. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*2];
  1263. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*1];
  1264. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*0];
  1265. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*7];
  1266. tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*6];
  1267. tmp10 = tmp0 + tmp5;
  1268. tmp13 = tmp0 - tmp5;
  1269. tmp11 = tmp1 + tmp4;
  1270. tmp14 = tmp1 - tmp4;
  1271. tmp12 = tmp2 + tmp3;
  1272. tmp15 = tmp2 - tmp3;
  1273. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*3];
  1274. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*2];
  1275. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*1];
  1276. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*0];
  1277. tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*7];
  1278. tmp5 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*6];
  1279. dataptr[DCTSIZE*0] = (DCTELEM)
  1280. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(0.888888889)), /* 8/9 */
  1281. CONST_BITS+1);
  1282. dataptr[DCTSIZE*6] = (DCTELEM)
  1283. DESCALE(MULTIPLY(tmp13 - tmp14 - tmp15, FIX(0.888888889)), /* 8/9 */
  1284. CONST_BITS+1);
  1285. dataptr[DCTSIZE*4] = (DCTELEM)
  1286. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.088662108)), /* c4 */
  1287. CONST_BITS+1);
  1288. dataptr[DCTSIZE*2] = (DCTELEM)
  1289. DESCALE(MULTIPLY(tmp14 - tmp15, FIX(0.888888889)) + /* 8/9 */
  1290. MULTIPLY(tmp13 + tmp15, FIX(1.214244803)), /* c2 */
  1291. CONST_BITS+1);
  1292. /* Odd part */
  1293. tmp10 = MULTIPLY(tmp1 + tmp4, FIX(0.481063200)); /* c9 */
  1294. tmp14 = tmp10 + MULTIPLY(tmp1, FIX(0.680326102)); /* c3-c9 */
  1295. tmp15 = tmp10 - MULTIPLY(tmp4, FIX(1.642452502)); /* c3+c9 */
  1296. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(0.997307603)); /* c5 */
  1297. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.765261039)); /* c7 */
  1298. tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.516244403)) /* c5+c7-c1 */
  1299. + MULTIPLY(tmp5, FIX(0.164081699)); /* c11 */
  1300. tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.164081699)); /* -c11 */
  1301. tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.079550144)) /* c1+c5-c11 */
  1302. + MULTIPLY(tmp5, FIX(0.765261039)); /* c7 */
  1303. tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.645144899)) /* c1+c11-c7 */
  1304. - MULTIPLY(tmp5, FIX(0.997307603)); /* c5 */
  1305. tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.161389302)) /* c3 */
  1306. - MULTIPLY(tmp2 + tmp5, FIX(0.481063200)); /* c9 */
  1307. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+1);
  1308. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+1);
  1309. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+1);
  1310. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+1);
  1311. dataptr++; /* advance pointer to next column */
  1312. wsptr++; /* advance pointer to next column */
  1313. }
  1314. }
  1315. /*
  1316. * Perform the forward DCT on a 13x13 sample block.
  1317. */
  1318. GLOBAL(void)
  1319. jpeg_fdct_13x13 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1320. {
  1321. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  1322. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  1323. INT32 z1, z2;
  1324. DCTELEM workspace[8*5];
  1325. DCTELEM *dataptr;
  1326. DCTELEM *wsptr;
  1327. JSAMPROW elemptr;
  1328. int ctr;
  1329. SHIFT_TEMPS
  1330. /* Pass 1: process rows.
  1331. * Note results are scaled up by sqrt(8) compared to a true DCT.
  1332. * cK represents sqrt(2) * cos(K*pi/26).
  1333. */
  1334. dataptr = data;
  1335. ctr = 0;
  1336. for (;;) {
  1337. elemptr = sample_data[ctr] + start_col;
  1338. /* Even part */
  1339. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[12]);
  1340. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[11]);
  1341. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[10]);
  1342. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[9]);
  1343. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[8]);
  1344. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[7]);
  1345. tmp6 = GETJSAMPLE(elemptr[6]);
  1346. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[12]);
  1347. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[11]);
  1348. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[10]);
  1349. tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[9]);
  1350. tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[8]);
  1351. tmp15 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[7]);
  1352. /* Apply unsigned->signed conversion */
  1353. dataptr[0] = (DCTELEM)
  1354. (tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 + tmp6 - 13 * CENTERJSAMPLE);
  1355. tmp6 += tmp6;
  1356. tmp0 -= tmp6;
  1357. tmp1 -= tmp6;
  1358. tmp2 -= tmp6;
  1359. tmp3 -= tmp6;
  1360. tmp4 -= tmp6;
  1361. tmp5 -= tmp6;
  1362. dataptr[2] = (DCTELEM)
  1363. DESCALE(MULTIPLY(tmp0, FIX(1.373119086)) + /* c2 */
  1364. MULTIPLY(tmp1, FIX(1.058554052)) + /* c6 */
  1365. MULTIPLY(tmp2, FIX(0.501487041)) - /* c10 */
  1366. MULTIPLY(tmp3, FIX(0.170464608)) - /* c12 */
  1367. MULTIPLY(tmp4, FIX(0.803364869)) - /* c8 */
  1368. MULTIPLY(tmp5, FIX(1.252223920)), /* c4 */
  1369. CONST_BITS);
  1370. z1 = MULTIPLY(tmp0 - tmp2, FIX(1.155388986)) - /* (c4+c6)/2 */
  1371. MULTIPLY(tmp3 - tmp4, FIX(0.435816023)) - /* (c2-c10)/2 */
  1372. MULTIPLY(tmp1 - tmp5, FIX(0.316450131)); /* (c8-c12)/2 */
  1373. z2 = MULTIPLY(tmp0 + tmp2, FIX(0.096834934)) - /* (c4-c6)/2 */
  1374. MULTIPLY(tmp3 + tmp4, FIX(0.937303064)) + /* (c2+c10)/2 */
  1375. MULTIPLY(tmp1 + tmp5, FIX(0.486914739)); /* (c8+c12)/2 */
  1376. dataptr[4] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS);
  1377. dataptr[6] = (DCTELEM) DESCALE(z1 - z2, CONST_BITS);
  1378. /* Odd part */
  1379. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.322312651)); /* c3 */
  1380. tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.163874945)); /* c5 */
  1381. tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.937797057)) + /* c7 */
  1382. MULTIPLY(tmp14 + tmp15, FIX(0.338443458)); /* c11 */
  1383. tmp0 = tmp1 + tmp2 + tmp3 -
  1384. MULTIPLY(tmp10, FIX(2.020082300)) + /* c3+c5+c7-c1 */
  1385. MULTIPLY(tmp14, FIX(0.318774355)); /* c9-c11 */
  1386. tmp4 = MULTIPLY(tmp14 - tmp15, FIX(0.937797057)) - /* c7 */
  1387. MULTIPLY(tmp11 + tmp12, FIX(0.338443458)); /* c11 */
  1388. tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.163874945)); /* -c5 */
  1389. tmp1 += tmp4 + tmp5 +
  1390. MULTIPLY(tmp11, FIX(0.837223564)) - /* c5+c9+c11-c3 */
  1391. MULTIPLY(tmp14, FIX(2.341699410)); /* c1+c7 */
  1392. tmp6 = MULTIPLY(tmp12 + tmp13, - FIX(0.657217813)); /* -c9 */
  1393. tmp2 += tmp4 + tmp6 -
  1394. MULTIPLY(tmp12, FIX(1.572116027)) + /* c1+c5-c9-c11 */
  1395. MULTIPLY(tmp15, FIX(2.260109708)); /* c3+c7 */
  1396. tmp3 += tmp5 + tmp6 +
  1397. MULTIPLY(tmp13, FIX(2.205608352)) - /* c3+c5+c9-c7 */
  1398. MULTIPLY(tmp15, FIX(1.742345811)); /* c1+c11 */
  1399. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS);
  1400. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS);
  1401. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS);
  1402. dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS);
  1403. ctr++;
  1404. if (ctr != DCTSIZE) {
  1405. if (ctr == 13)
  1406. break; /* Done. */
  1407. dataptr += DCTSIZE; /* advance pointer to next row */
  1408. } else
  1409. dataptr = workspace; /* switch pointer to extended workspace */
  1410. }
  1411. /* Pass 2: process columns.
  1412. * We leave the results scaled up by an overall factor of 8.
  1413. * We must also scale the output by (8/13)**2 = 64/169, which we partially
  1414. * fold into the constant multipliers and final shifting:
  1415. * cK now represents sqrt(2) * cos(K*pi/26) * 128/169.
  1416. */
  1417. dataptr = data;
  1418. wsptr = workspace;
  1419. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1420. /* Even part */
  1421. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*4];
  1422. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*3];
  1423. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*2];
  1424. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*1];
  1425. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*0];
  1426. tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*7];
  1427. tmp6 = dataptr[DCTSIZE*6];
  1428. tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*4];
  1429. tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*3];
  1430. tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*2];
  1431. tmp13 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*1];
  1432. tmp14 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*0];
  1433. tmp15 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*7];
  1434. dataptr[DCTSIZE*0] = (DCTELEM)
  1435. DESCALE(MULTIPLY(tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 + tmp6,
  1436. FIX(0.757396450)), /* 128/169 */
  1437. CONST_BITS+1);
  1438. tmp6 += tmp6;
  1439. tmp0 -= tmp6;
  1440. tmp1 -= tmp6;
  1441. tmp2 -= tmp6;
  1442. tmp3 -= tmp6;
  1443. tmp4 -= tmp6;
  1444. tmp5 -= tmp6;
  1445. dataptr[DCTSIZE*2] = (DCTELEM)
  1446. DESCALE(MULTIPLY(tmp0, FIX(1.039995521)) + /* c2 */
  1447. MULTIPLY(tmp1, FIX(0.801745081)) + /* c6 */
  1448. MULTIPLY(tmp2, FIX(0.379824504)) - /* c10 */
  1449. MULTIPLY(tmp3, FIX(0.129109289)) - /* c12 */
  1450. MULTIPLY(tmp4, FIX(0.608465700)) - /* c8 */
  1451. MULTIPLY(tmp5, FIX(0.948429952)), /* c4 */
  1452. CONST_BITS+1);
  1453. z1 = MULTIPLY(tmp0 - tmp2, FIX(0.875087516)) - /* (c4+c6)/2 */
  1454. MULTIPLY(tmp3 - tmp4, FIX(0.330085509)) - /* (c2-c10)/2 */
  1455. MULTIPLY(tmp1 - tmp5, FIX(0.239678205)); /* (c8-c12)/2 */
  1456. z2 = MULTIPLY(tmp0 + tmp2, FIX(0.073342435)) - /* (c4-c6)/2 */
  1457. MULTIPLY(tmp3 + tmp4, FIX(0.709910013)) + /* (c2+c10)/2 */
  1458. MULTIPLY(tmp1 + tmp5, FIX(0.368787494)); /* (c8+c12)/2 */
  1459. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+1);
  1460. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 - z2, CONST_BITS+1);
  1461. /* Odd part */
  1462. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.001514908)); /* c3 */
  1463. tmp2 = MULTIPLY(tmp10 + tmp12, FIX(0.881514751)); /* c5 */
  1464. tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.710284161)) + /* c7 */
  1465. MULTIPLY(tmp14 + tmp15, FIX(0.256335874)); /* c11 */
  1466. tmp0 = tmp1 + tmp2 + tmp3 -
  1467. MULTIPLY(tmp10, FIX(1.530003162)) + /* c3+c5+c7-c1 */
  1468. MULTIPLY(tmp14, FIX(0.241438564)); /* c9-c11 */
  1469. tmp4 = MULTIPLY(tmp14 - tmp15, FIX(0.710284161)) - /* c7 */
  1470. MULTIPLY(tmp11 + tmp12, FIX(0.256335874)); /* c11 */
  1471. tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(0.881514751)); /* -c5 */
  1472. tmp1 += tmp4 + tmp5 +
  1473. MULTIPLY(tmp11, FIX(0.634110155)) - /* c5+c9+c11-c3 */
  1474. MULTIPLY(tmp14, FIX(1.773594819)); /* c1+c7 */
  1475. tmp6 = MULTIPLY(tmp12 + tmp13, - FIX(0.497774438)); /* -c9 */
  1476. tmp2 += tmp4 + tmp6 -
  1477. MULTIPLY(tmp12, FIX(1.190715098)) + /* c1+c5-c9-c11 */
  1478. MULTIPLY(tmp15, FIX(1.711799069)); /* c3+c7 */
  1479. tmp3 += tmp5 + tmp6 +
  1480. MULTIPLY(tmp13, FIX(1.670519935)) - /* c3+c5+c9-c7 */
  1481. MULTIPLY(tmp15, FIX(1.319646532)); /* c1+c11 */
  1482. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+1);
  1483. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+1);
  1484. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+1);
  1485. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+1);
  1486. dataptr++; /* advance pointer to next column */
  1487. wsptr++; /* advance pointer to next column */
  1488. }
  1489. }
  1490. /*
  1491. * Perform the forward DCT on a 14x14 sample block.
  1492. */
  1493. GLOBAL(void)
  1494. jpeg_fdct_14x14 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1495. {
  1496. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  1497. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  1498. DCTELEM workspace[8*6];
  1499. DCTELEM *dataptr;
  1500. DCTELEM *wsptr;
  1501. JSAMPROW elemptr;
  1502. int ctr;
  1503. SHIFT_TEMPS
  1504. /* Pass 1: process rows.
  1505. * Note results are scaled up by sqrt(8) compared to a true DCT.
  1506. * cK represents sqrt(2) * cos(K*pi/28).
  1507. */
  1508. dataptr = data;
  1509. ctr = 0;
  1510. for (;;) {
  1511. elemptr = sample_data[ctr] + start_col;
  1512. /* Even part */
  1513. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[13]);
  1514. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[12]);
  1515. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[11]);
  1516. tmp13 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[10]);
  1517. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[9]);
  1518. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[8]);
  1519. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[7]);
  1520. tmp10 = tmp0 + tmp6;
  1521. tmp14 = tmp0 - tmp6;
  1522. tmp11 = tmp1 + tmp5;
  1523. tmp15 = tmp1 - tmp5;
  1524. tmp12 = tmp2 + tmp4;
  1525. tmp16 = tmp2 - tmp4;
  1526. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[13]);
  1527. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[12]);
  1528. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[11]);
  1529. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[10]);
  1530. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[9]);
  1531. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[8]);
  1532. tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[7]);
  1533. /* Apply unsigned->signed conversion */
  1534. dataptr[0] = (DCTELEM)
  1535. (tmp10 + tmp11 + tmp12 + tmp13 - 14 * CENTERJSAMPLE);
  1536. tmp13 += tmp13;
  1537. dataptr[4] = (DCTELEM)
  1538. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.274162392)) + /* c4 */
  1539. MULTIPLY(tmp11 - tmp13, FIX(0.314692123)) - /* c12 */
  1540. MULTIPLY(tmp12 - tmp13, FIX(0.881747734)), /* c8 */
  1541. CONST_BITS);
  1542. tmp10 = MULTIPLY(tmp14 + tmp15, FIX(1.105676686)); /* c6 */
  1543. dataptr[2] = (DCTELEM)
  1544. DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.273079590)) /* c2-c6 */
  1545. + MULTIPLY(tmp16, FIX(0.613604268)), /* c10 */
  1546. CONST_BITS);
  1547. dataptr[6] = (DCTELEM)
  1548. DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.719280954)) /* c6+c10 */
  1549. - MULTIPLY(tmp16, FIX(1.378756276)), /* c2 */
  1550. CONST_BITS);
  1551. /* Odd part */
  1552. tmp10 = tmp1 + tmp2;
  1553. tmp11 = tmp5 - tmp4;
  1554. dataptr[7] = (DCTELEM) (tmp0 - tmp10 + tmp3 - tmp11 - tmp6);
  1555. tmp3 <<= CONST_BITS;
  1556. tmp10 = MULTIPLY(tmp10, - FIX(0.158341681)); /* -c13 */
  1557. tmp11 = MULTIPLY(tmp11, FIX(1.405321284)); /* c1 */
  1558. tmp10 += tmp11 - tmp3;
  1559. tmp11 = MULTIPLY(tmp0 + tmp2, FIX(1.197448846)) + /* c5 */
  1560. MULTIPLY(tmp4 + tmp6, FIX(0.752406978)); /* c9 */
  1561. dataptr[5] = (DCTELEM)
  1562. DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(2.373959773)) /* c3+c5-c13 */
  1563. + MULTIPLY(tmp4, FIX(1.119999435)), /* c1+c11-c9 */
  1564. CONST_BITS);
  1565. tmp12 = MULTIPLY(tmp0 + tmp1, FIX(1.334852607)) + /* c3 */
  1566. MULTIPLY(tmp5 - tmp6, FIX(0.467085129)); /* c11 */
  1567. dataptr[3] = (DCTELEM)
  1568. DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.424103948)) /* c3-c9-c13 */
  1569. - MULTIPLY(tmp5, FIX(3.069855259)), /* c1+c5+c11 */
  1570. CONST_BITS);
  1571. dataptr[1] = (DCTELEM)
  1572. DESCALE(tmp11 + tmp12 + tmp3 + tmp6 -
  1573. MULTIPLY(tmp0 + tmp6, FIX(1.126980169)), /* c3+c5-c1 */
  1574. CONST_BITS);
  1575. ctr++;
  1576. if (ctr != DCTSIZE) {
  1577. if (ctr == 14)
  1578. break; /* Done. */
  1579. dataptr += DCTSIZE; /* advance pointer to next row */
  1580. } else
  1581. dataptr = workspace; /* switch pointer to extended workspace */
  1582. }
  1583. /* Pass 2: process columns.
  1584. * We leave the results scaled up by an overall factor of 8.
  1585. * We must also scale the output by (8/14)**2 = 16/49, which we partially
  1586. * fold into the constant multipliers and final shifting:
  1587. * cK now represents sqrt(2) * cos(K*pi/28) * 32/49.
  1588. */
  1589. dataptr = data;
  1590. wsptr = workspace;
  1591. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1592. /* Even part */
  1593. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*5];
  1594. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*4];
  1595. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*3];
  1596. tmp13 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*2];
  1597. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*1];
  1598. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*0];
  1599. tmp6 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];
  1600. tmp10 = tmp0 + tmp6;
  1601. tmp14 = tmp0 - tmp6;
  1602. tmp11 = tmp1 + tmp5;
  1603. tmp15 = tmp1 - tmp5;
  1604. tmp12 = tmp2 + tmp4;
  1605. tmp16 = tmp2 - tmp4;
  1606. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*5];
  1607. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*4];
  1608. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*3];
  1609. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*2];
  1610. tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*1];
  1611. tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*0];
  1612. tmp6 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];
  1613. dataptr[DCTSIZE*0] = (DCTELEM)
  1614. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12 + tmp13,
  1615. FIX(0.653061224)), /* 32/49 */
  1616. CONST_BITS+1);
  1617. tmp13 += tmp13;
  1618. dataptr[DCTSIZE*4] = (DCTELEM)
  1619. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(0.832106052)) + /* c4 */
  1620. MULTIPLY(tmp11 - tmp13, FIX(0.205513223)) - /* c12 */
  1621. MULTIPLY(tmp12 - tmp13, FIX(0.575835255)), /* c8 */
  1622. CONST_BITS+1);
  1623. tmp10 = MULTIPLY(tmp14 + tmp15, FIX(0.722074570)); /* c6 */
  1624. dataptr[DCTSIZE*2] = (DCTELEM)
  1625. DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.178337691)) /* c2-c6 */
  1626. + MULTIPLY(tmp16, FIX(0.400721155)), /* c10 */
  1627. CONST_BITS+1);
  1628. dataptr[DCTSIZE*6] = (DCTELEM)
  1629. DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.122795725)) /* c6+c10 */
  1630. - MULTIPLY(tmp16, FIX(0.900412262)), /* c2 */
  1631. CONST_BITS+1);
  1632. /* Odd part */
  1633. tmp10 = tmp1 + tmp2;
  1634. tmp11 = tmp5 - tmp4;
  1635. dataptr[DCTSIZE*7] = (DCTELEM)
  1636. DESCALE(MULTIPLY(tmp0 - tmp10 + tmp3 - tmp11 - tmp6,
  1637. FIX(0.653061224)), /* 32/49 */
  1638. CONST_BITS+1);
  1639. tmp3 = MULTIPLY(tmp3 , FIX(0.653061224)); /* 32/49 */
  1640. tmp10 = MULTIPLY(tmp10, - FIX(0.103406812)); /* -c13 */
  1641. tmp11 = MULTIPLY(tmp11, FIX(0.917760839)); /* c1 */
  1642. tmp10 += tmp11 - tmp3;
  1643. tmp11 = MULTIPLY(tmp0 + tmp2, FIX(0.782007410)) + /* c5 */
  1644. MULTIPLY(tmp4 + tmp6, FIX(0.491367823)); /* c9 */
  1645. dataptr[DCTSIZE*5] = (DCTELEM)
  1646. DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(1.550341076)) /* c3+c5-c13 */
  1647. + MULTIPLY(tmp4, FIX(0.731428202)), /* c1+c11-c9 */
  1648. CONST_BITS+1);
  1649. tmp12 = MULTIPLY(tmp0 + tmp1, FIX(0.871740478)) + /* c3 */
  1650. MULTIPLY(tmp5 - tmp6, FIX(0.305035186)); /* c11 */
  1651. dataptr[DCTSIZE*3] = (DCTELEM)
  1652. DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.276965844)) /* c3-c9-c13 */
  1653. - MULTIPLY(tmp5, FIX(2.004803435)), /* c1+c5+c11 */
  1654. CONST_BITS+1);
  1655. dataptr[DCTSIZE*1] = (DCTELEM)
  1656. DESCALE(tmp11 + tmp12 + tmp3
  1657. - MULTIPLY(tmp0, FIX(0.735987049)) /* c3+c5-c1 */
  1658. - MULTIPLY(tmp6, FIX(0.082925825)), /* c9-c11-c13 */
  1659. CONST_BITS+1);
  1660. dataptr++; /* advance pointer to next column */
  1661. wsptr++; /* advance pointer to next column */
  1662. }
  1663. }
  1664. /*
  1665. * Perform the forward DCT on a 15x15 sample block.
  1666. */
  1667. GLOBAL(void)
  1668. jpeg_fdct_15x15 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1669. {
  1670. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  1671. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  1672. INT32 z1, z2, z3;
  1673. DCTELEM workspace[8*7];
  1674. DCTELEM *dataptr;
  1675. DCTELEM *wsptr;
  1676. JSAMPROW elemptr;
  1677. int ctr;
  1678. SHIFT_TEMPS
  1679. /* Pass 1: process rows.
  1680. * Note results are scaled up by sqrt(8) compared to a true DCT.
  1681. * cK represents sqrt(2) * cos(K*pi/30).
  1682. */
  1683. dataptr = data;
  1684. ctr = 0;
  1685. for (;;) {
  1686. elemptr = sample_data[ctr] + start_col;
  1687. /* Even part */
  1688. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[14]);
  1689. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[13]);
  1690. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[12]);
  1691. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[11]);
  1692. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[10]);
  1693. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[9]);
  1694. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[8]);
  1695. tmp7 = GETJSAMPLE(elemptr[7]);
  1696. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[14]);
  1697. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[13]);
  1698. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[12]);
  1699. tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[11]);
  1700. tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[10]);
  1701. tmp15 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[9]);
  1702. tmp16 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[8]);
  1703. z1 = tmp0 + tmp4 + tmp5;
  1704. z2 = tmp1 + tmp3 + tmp6;
  1705. z3 = tmp2 + tmp7;
  1706. /* Apply unsigned->signed conversion */
  1707. dataptr[0] = (DCTELEM) (z1 + z2 + z3 - 15 * CENTERJSAMPLE);
  1708. z3 += z3;
  1709. dataptr[6] = (DCTELEM)
  1710. DESCALE(MULTIPLY(z1 - z3, FIX(1.144122806)) - /* c6 */
  1711. MULTIPLY(z2 - z3, FIX(0.437016024)), /* c12 */
  1712. CONST_BITS);
  1713. tmp2 += ((tmp1 + tmp4) >> 1) - tmp7 - tmp7;
  1714. z1 = MULTIPLY(tmp3 - tmp2, FIX(1.531135173)) - /* c2+c14 */
  1715. MULTIPLY(tmp6 - tmp2, FIX(2.238241955)); /* c4+c8 */
  1716. z2 = MULTIPLY(tmp5 - tmp2, FIX(0.798468008)) - /* c8-c14 */
  1717. MULTIPLY(tmp0 - tmp2, FIX(0.091361227)); /* c2-c4 */
  1718. z3 = MULTIPLY(tmp0 - tmp3, FIX(1.383309603)) + /* c2 */
  1719. MULTIPLY(tmp6 - tmp5, FIX(0.946293579)) + /* c8 */
  1720. MULTIPLY(tmp1 - tmp4, FIX(0.790569415)); /* (c6+c12)/2 */
  1721. dataptr[2] = (DCTELEM) DESCALE(z1 + z3, CONST_BITS);
  1722. dataptr[4] = (DCTELEM) DESCALE(z2 + z3, CONST_BITS);
  1723. /* Odd part */
  1724. tmp2 = MULTIPLY(tmp10 - tmp12 - tmp13 + tmp15 + tmp16,
  1725. FIX(1.224744871)); /* c5 */
  1726. tmp1 = MULTIPLY(tmp10 - tmp14 - tmp15, FIX(1.344997024)) + /* c3 */
  1727. MULTIPLY(tmp11 - tmp13 - tmp16, FIX(0.831253876)); /* c9 */
  1728. tmp12 = MULTIPLY(tmp12, FIX(1.224744871)); /* c5 */
  1729. tmp4 = MULTIPLY(tmp10 - tmp16, FIX(1.406466353)) + /* c1 */
  1730. MULTIPLY(tmp11 + tmp14, FIX(1.344997024)) + /* c3 */
  1731. MULTIPLY(tmp13 + tmp15, FIX(0.575212477)); /* c11 */
  1732. tmp0 = MULTIPLY(tmp13, FIX(0.475753014)) - /* c7-c11 */
  1733. MULTIPLY(tmp14, FIX(0.513743148)) + /* c3-c9 */
  1734. MULTIPLY(tmp16, FIX(1.700497885)) + tmp4 + tmp12; /* c1+c13 */
  1735. tmp3 = MULTIPLY(tmp10, - FIX(0.355500862)) - /* -(c1-c7) */
  1736. MULTIPLY(tmp11, FIX(2.176250899)) - /* c3+c9 */
  1737. MULTIPLY(tmp15, FIX(0.869244010)) + tmp4 - tmp12; /* c11+c13 */
  1738. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS);
  1739. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS);
  1740. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS);
  1741. dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS);
  1742. ctr++;
  1743. if (ctr != DCTSIZE) {
  1744. if (ctr == 15)
  1745. break; /* Done. */
  1746. dataptr += DCTSIZE; /* advance pointer to next row */
  1747. } else
  1748. dataptr = workspace; /* switch pointer to extended workspace */
  1749. }
  1750. /* Pass 2: process columns.
  1751. * We leave the results scaled up by an overall factor of 8.
  1752. * We must also scale the output by (8/15)**2 = 64/225, which we partially
  1753. * fold into the constant multipliers and final shifting:
  1754. * cK now represents sqrt(2) * cos(K*pi/30) * 256/225.
  1755. */
  1756. dataptr = data;
  1757. wsptr = workspace;
  1758. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1759. /* Even part */
  1760. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*6];
  1761. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*5];
  1762. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*4];
  1763. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*3];
  1764. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*2];
  1765. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*1];
  1766. tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*0];
  1767. tmp7 = dataptr[DCTSIZE*7];
  1768. tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*6];
  1769. tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*5];
  1770. tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*4];
  1771. tmp13 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*3];
  1772. tmp14 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*2];
  1773. tmp15 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*1];
  1774. tmp16 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*0];
  1775. z1 = tmp0 + tmp4 + tmp5;
  1776. z2 = tmp1 + tmp3 + tmp6;
  1777. z3 = tmp2 + tmp7;
  1778. dataptr[DCTSIZE*0] = (DCTELEM)
  1779. DESCALE(MULTIPLY(z1 + z2 + z3, FIX(1.137777778)), /* 256/225 */
  1780. CONST_BITS+2);
  1781. z3 += z3;
  1782. dataptr[DCTSIZE*6] = (DCTELEM)
  1783. DESCALE(MULTIPLY(z1 - z3, FIX(1.301757503)) - /* c6 */
  1784. MULTIPLY(z2 - z3, FIX(0.497227121)), /* c12 */
  1785. CONST_BITS+2);
  1786. tmp2 += ((tmp1 + tmp4) >> 1) - tmp7 - tmp7;
  1787. z1 = MULTIPLY(tmp3 - tmp2, FIX(1.742091575)) - /* c2+c14 */
  1788. MULTIPLY(tmp6 - tmp2, FIX(2.546621957)); /* c4+c8 */
  1789. z2 = MULTIPLY(tmp5 - tmp2, FIX(0.908479156)) - /* c8-c14 */
  1790. MULTIPLY(tmp0 - tmp2, FIX(0.103948774)); /* c2-c4 */
  1791. z3 = MULTIPLY(tmp0 - tmp3, FIX(1.573898926)) + /* c2 */
  1792. MULTIPLY(tmp6 - tmp5, FIX(1.076671805)) + /* c8 */
  1793. MULTIPLY(tmp1 - tmp4, FIX(0.899492312)); /* (c6+c12)/2 */
  1794. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z3, CONST_BITS+2);
  1795. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(z2 + z3, CONST_BITS+2);
  1796. /* Odd part */
  1797. tmp2 = MULTIPLY(tmp10 - tmp12 - tmp13 + tmp15 + tmp16,
  1798. FIX(1.393487498)); /* c5 */
  1799. tmp1 = MULTIPLY(tmp10 - tmp14 - tmp15, FIX(1.530307725)) + /* c3 */
  1800. MULTIPLY(tmp11 - tmp13 - tmp16, FIX(0.945782187)); /* c9 */
  1801. tmp12 = MULTIPLY(tmp12, FIX(1.393487498)); /* c5 */
  1802. tmp4 = MULTIPLY(tmp10 - tmp16, FIX(1.600246161)) + /* c1 */
  1803. MULTIPLY(tmp11 + tmp14, FIX(1.530307725)) + /* c3 */
  1804. MULTIPLY(tmp13 + tmp15, FIX(0.654463974)); /* c11 */
  1805. tmp0 = MULTIPLY(tmp13, FIX(0.541301207)) - /* c7-c11 */
  1806. MULTIPLY(tmp14, FIX(0.584525538)) + /* c3-c9 */
  1807. MULTIPLY(tmp16, FIX(1.934788705)) + tmp4 + tmp12; /* c1+c13 */
  1808. tmp3 = MULTIPLY(tmp10, - FIX(0.404480980)) - /* -(c1-c7) */
  1809. MULTIPLY(tmp11, FIX(2.476089912)) - /* c3+c9 */
  1810. MULTIPLY(tmp15, FIX(0.989006518)) + tmp4 - tmp12; /* c11+c13 */
  1811. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+2);
  1812. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+2);
  1813. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+2);
  1814. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+2);
  1815. dataptr++; /* advance pointer to next column */
  1816. wsptr++; /* advance pointer to next column */
  1817. }
  1818. }
  1819. /*
  1820. * Perform the forward DCT on a 16x16 sample block.
  1821. */
  1822. GLOBAL(void)
  1823. jpeg_fdct_16x16 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  1824. {
  1825. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  1826. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;
  1827. DCTELEM workspace[DCTSIZE2];
  1828. DCTELEM *dataptr;
  1829. DCTELEM *wsptr;
  1830. JSAMPROW elemptr;
  1831. int ctr;
  1832. SHIFT_TEMPS
  1833. /* Pass 1: process rows.
  1834. * Note results are scaled up by sqrt(8) compared to a true DCT;
  1835. * furthermore, we scale the results by 2**PASS1_BITS.
  1836. * cK represents sqrt(2) * cos(K*pi/32).
  1837. */
  1838. dataptr = data;
  1839. ctr = 0;
  1840. for (;;) {
  1841. elemptr = sample_data[ctr] + start_col;
  1842. /* Even part */
  1843. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[15]);
  1844. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[14]);
  1845. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[13]);
  1846. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[12]);
  1847. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[11]);
  1848. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[10]);
  1849. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[9]);
  1850. tmp7 = GETJSAMPLE(elemptr[7]) + GETJSAMPLE(elemptr[8]);
  1851. tmp10 = tmp0 + tmp7;
  1852. tmp14 = tmp0 - tmp7;
  1853. tmp11 = tmp1 + tmp6;
  1854. tmp15 = tmp1 - tmp6;
  1855. tmp12 = tmp2 + tmp5;
  1856. tmp16 = tmp2 - tmp5;
  1857. tmp13 = tmp3 + tmp4;
  1858. tmp17 = tmp3 - tmp4;
  1859. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[15]);
  1860. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[14]);
  1861. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[13]);
  1862. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[12]);
  1863. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[11]);
  1864. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[10]);
  1865. tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[9]);
  1866. tmp7 = GETJSAMPLE(elemptr[7]) - GETJSAMPLE(elemptr[8]);
  1867. /* Apply unsigned->signed conversion */
  1868. dataptr[0] = (DCTELEM)
  1869. ((tmp10 + tmp11 + tmp12 + tmp13 - 16 * CENTERJSAMPLE) << PASS1_BITS);
  1870. dataptr[4] = (DCTELEM)
  1871. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */
  1872. MULTIPLY(tmp11 - tmp12, FIX_0_541196100), /* c12[16] = c6[8] */
  1873. CONST_BITS-PASS1_BITS);
  1874. tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) + /* c14[16] = c7[8] */
  1875. MULTIPLY(tmp14 - tmp16, FIX(1.387039845)); /* c2[16] = c1[8] */
  1876. dataptr[2] = (DCTELEM)
  1877. DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982)) /* c6+c14 */
  1878. + MULTIPLY(tmp16, FIX(2.172734804)), /* c2+c10 */
  1879. CONST_BITS-PASS1_BITS);
  1880. dataptr[6] = (DCTELEM)
  1881. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243)) /* c2-c6 */
  1882. - MULTIPLY(tmp17, FIX(1.061594338)), /* c10+c14 */
  1883. CONST_BITS-PASS1_BITS);
  1884. /* Odd part */
  1885. tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) + /* c3 */
  1886. MULTIPLY(tmp6 - tmp7, FIX(0.410524528)); /* c13 */
  1887. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) + /* c5 */
  1888. MULTIPLY(tmp5 + tmp7, FIX(0.666655658)); /* c11 */
  1889. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) + /* c7 */
  1890. MULTIPLY(tmp4 - tmp7, FIX(0.897167586)); /* c9 */
  1891. tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) + /* c15 */
  1892. MULTIPLY(tmp6 - tmp5, FIX(1.407403738)); /* c1 */
  1893. tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) + /* -c11 */
  1894. MULTIPLY(tmp4 + tmp6, - FIX(1.247225013)); /* -c5 */
  1895. tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) + /* -c3 */
  1896. MULTIPLY(tmp5 - tmp4, FIX(0.410524528)); /* c13 */
  1897. tmp10 = tmp11 + tmp12 + tmp13 -
  1898. MULTIPLY(tmp0, FIX(2.286341144)) + /* c7+c5+c3-c1 */
  1899. MULTIPLY(tmp7, FIX(0.779653625)); /* c15+c13-c11+c9 */
  1900. tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */
  1901. - MULTIPLY(tmp6, FIX(1.663905119)); /* c7+c13+c1-c5 */
  1902. tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */
  1903. + MULTIPLY(tmp5, FIX(1.227391138)); /* c9-c11+c1-c13 */
  1904. tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */
  1905. + MULTIPLY(tmp4, FIX(2.167985692)); /* c1+c13+c5-c9 */
  1906. dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
  1907. dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
  1908. dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
  1909. dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
  1910. ctr++;
  1911. if (ctr != DCTSIZE) {
  1912. if (ctr == DCTSIZE * 2)
  1913. break; /* Done. */
  1914. dataptr += DCTSIZE; /* advance pointer to next row */
  1915. } else
  1916. dataptr = workspace; /* switch pointer to extended workspace */
  1917. }
  1918. /* Pass 2: process columns.
  1919. * We remove the PASS1_BITS scaling, but leave the results scaled up
  1920. * by an overall factor of 8.
  1921. * We must also scale the output by (8/16)**2 = 1/2**2.
  1922. * cK represents sqrt(2) * cos(K*pi/32).
  1923. */
  1924. dataptr = data;
  1925. wsptr = workspace;
  1926. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  1927. /* Even part */
  1928. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*7];
  1929. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*6];
  1930. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*5];
  1931. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*4];
  1932. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*3];
  1933. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*2];
  1934. tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*1];
  1935. tmp7 = dataptr[DCTSIZE*7] + wsptr[DCTSIZE*0];
  1936. tmp10 = tmp0 + tmp7;
  1937. tmp14 = tmp0 - tmp7;
  1938. tmp11 = tmp1 + tmp6;
  1939. tmp15 = tmp1 - tmp6;
  1940. tmp12 = tmp2 + tmp5;
  1941. tmp16 = tmp2 - tmp5;
  1942. tmp13 = tmp3 + tmp4;
  1943. tmp17 = tmp3 - tmp4;
  1944. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*7];
  1945. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*6];
  1946. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*5];
  1947. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*4];
  1948. tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*3];
  1949. tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*2];
  1950. tmp6 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*1];
  1951. tmp7 = dataptr[DCTSIZE*7] - wsptr[DCTSIZE*0];
  1952. dataptr[DCTSIZE*0] = (DCTELEM)
  1953. DESCALE(tmp10 + tmp11 + tmp12 + tmp13, PASS1_BITS+2);
  1954. dataptr[DCTSIZE*4] = (DCTELEM)
  1955. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */
  1956. MULTIPLY(tmp11 - tmp12, FIX_0_541196100), /* c12[16] = c6[8] */
  1957. CONST_BITS+PASS1_BITS+2);
  1958. tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) + /* c14[16] = c7[8] */
  1959. MULTIPLY(tmp14 - tmp16, FIX(1.387039845)); /* c2[16] = c1[8] */
  1960. dataptr[DCTSIZE*2] = (DCTELEM)
  1961. DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982)) /* c6+c14 */
  1962. + MULTIPLY(tmp16, FIX(2.172734804)), /* c2+10 */
  1963. CONST_BITS+PASS1_BITS+2);
  1964. dataptr[DCTSIZE*6] = (DCTELEM)
  1965. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243)) /* c2-c6 */
  1966. - MULTIPLY(tmp17, FIX(1.061594338)), /* c10+c14 */
  1967. CONST_BITS+PASS1_BITS+2);
  1968. /* Odd part */
  1969. tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) + /* c3 */
  1970. MULTIPLY(tmp6 - tmp7, FIX(0.410524528)); /* c13 */
  1971. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) + /* c5 */
  1972. MULTIPLY(tmp5 + tmp7, FIX(0.666655658)); /* c11 */
  1973. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) + /* c7 */
  1974. MULTIPLY(tmp4 - tmp7, FIX(0.897167586)); /* c9 */
  1975. tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) + /* c15 */
  1976. MULTIPLY(tmp6 - tmp5, FIX(1.407403738)); /* c1 */
  1977. tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) + /* -c11 */
  1978. MULTIPLY(tmp4 + tmp6, - FIX(1.247225013)); /* -c5 */
  1979. tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) + /* -c3 */
  1980. MULTIPLY(tmp5 - tmp4, FIX(0.410524528)); /* c13 */
  1981. tmp10 = tmp11 + tmp12 + tmp13 -
  1982. MULTIPLY(tmp0, FIX(2.286341144)) + /* c7+c5+c3-c1 */
  1983. MULTIPLY(tmp7, FIX(0.779653625)); /* c15+c13-c11+c9 */
  1984. tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */
  1985. - MULTIPLY(tmp6, FIX(1.663905119)); /* c7+c13+c1-c5 */
  1986. tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */
  1987. + MULTIPLY(tmp5, FIX(1.227391138)); /* c9-c11+c1-c13 */
  1988. tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */
  1989. + MULTIPLY(tmp4, FIX(2.167985692)); /* c1+c13+c5-c9 */
  1990. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS+2);
  1991. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS+2);
  1992. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS+2);
  1993. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS+2);
  1994. dataptr++; /* advance pointer to next column */
  1995. wsptr++; /* advance pointer to next column */
  1996. }
  1997. }
  1998. /*
  1999. * Perform the forward DCT on a 16x8 sample block.
  2000. *
  2001. * 16-point FDCT in pass 1 (rows), 8-point in pass 2 (columns).
  2002. */
  2003. GLOBAL(void)
  2004. jpeg_fdct_16x8 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2005. {
  2006. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  2007. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;
  2008. INT32 z1;
  2009. DCTELEM *dataptr;
  2010. JSAMPROW elemptr;
  2011. int ctr;
  2012. SHIFT_TEMPS
  2013. /* Pass 1: process rows.
  2014. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2015. * furthermore, we scale the results by 2**PASS1_BITS.
  2016. * 16-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/32).
  2017. */
  2018. dataptr = data;
  2019. ctr = 0;
  2020. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  2021. elemptr = sample_data[ctr] + start_col;
  2022. /* Even part */
  2023. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[15]);
  2024. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[14]);
  2025. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[13]);
  2026. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[12]);
  2027. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[11]);
  2028. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[10]);
  2029. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[9]);
  2030. tmp7 = GETJSAMPLE(elemptr[7]) + GETJSAMPLE(elemptr[8]);
  2031. tmp10 = tmp0 + tmp7;
  2032. tmp14 = tmp0 - tmp7;
  2033. tmp11 = tmp1 + tmp6;
  2034. tmp15 = tmp1 - tmp6;
  2035. tmp12 = tmp2 + tmp5;
  2036. tmp16 = tmp2 - tmp5;
  2037. tmp13 = tmp3 + tmp4;
  2038. tmp17 = tmp3 - tmp4;
  2039. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[15]);
  2040. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[14]);
  2041. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[13]);
  2042. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[12]);
  2043. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[11]);
  2044. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[10]);
  2045. tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[9]);
  2046. tmp7 = GETJSAMPLE(elemptr[7]) - GETJSAMPLE(elemptr[8]);
  2047. /* Apply unsigned->signed conversion */
  2048. dataptr[0] = (DCTELEM)
  2049. ((tmp10 + tmp11 + tmp12 + tmp13 - 16 * CENTERJSAMPLE) << PASS1_BITS);
  2050. dataptr[4] = (DCTELEM)
  2051. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */
  2052. MULTIPLY(tmp11 - tmp12, FIX_0_541196100), /* c12[16] = c6[8] */
  2053. CONST_BITS-PASS1_BITS);
  2054. tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) + /* c14[16] = c7[8] */
  2055. MULTIPLY(tmp14 - tmp16, FIX(1.387039845)); /* c2[16] = c1[8] */
  2056. dataptr[2] = (DCTELEM)
  2057. DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982)) /* c6+c14 */
  2058. + MULTIPLY(tmp16, FIX(2.172734804)), /* c2+c10 */
  2059. CONST_BITS-PASS1_BITS);
  2060. dataptr[6] = (DCTELEM)
  2061. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243)) /* c2-c6 */
  2062. - MULTIPLY(tmp17, FIX(1.061594338)), /* c10+c14 */
  2063. CONST_BITS-PASS1_BITS);
  2064. /* Odd part */
  2065. tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) + /* c3 */
  2066. MULTIPLY(tmp6 - tmp7, FIX(0.410524528)); /* c13 */
  2067. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) + /* c5 */
  2068. MULTIPLY(tmp5 + tmp7, FIX(0.666655658)); /* c11 */
  2069. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) + /* c7 */
  2070. MULTIPLY(tmp4 - tmp7, FIX(0.897167586)); /* c9 */
  2071. tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) + /* c15 */
  2072. MULTIPLY(tmp6 - tmp5, FIX(1.407403738)); /* c1 */
  2073. tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) + /* -c11 */
  2074. MULTIPLY(tmp4 + tmp6, - FIX(1.247225013)); /* -c5 */
  2075. tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) + /* -c3 */
  2076. MULTIPLY(tmp5 - tmp4, FIX(0.410524528)); /* c13 */
  2077. tmp10 = tmp11 + tmp12 + tmp13 -
  2078. MULTIPLY(tmp0, FIX(2.286341144)) + /* c7+c5+c3-c1 */
  2079. MULTIPLY(tmp7, FIX(0.779653625)); /* c15+c13-c11+c9 */
  2080. tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */
  2081. - MULTIPLY(tmp6, FIX(1.663905119)); /* c7+c13+c1-c5 */
  2082. tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */
  2083. + MULTIPLY(tmp5, FIX(1.227391138)); /* c9-c11+c1-c13 */
  2084. tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */
  2085. + MULTIPLY(tmp4, FIX(2.167985692)); /* c1+c13+c5-c9 */
  2086. dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
  2087. dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
  2088. dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
  2089. dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
  2090. dataptr += DCTSIZE; /* advance pointer to next row */
  2091. }
  2092. /* Pass 2: process columns.
  2093. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2094. * by an overall factor of 8.
  2095. * We must also scale the output by 8/16 = 1/2.
  2096. * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
  2097. */
  2098. dataptr = data;
  2099. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2100. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  2101. * rotator "c1" should be "c6".
  2102. */
  2103. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  2104. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  2105. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  2106. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  2107. tmp10 = tmp0 + tmp3;
  2108. tmp12 = tmp0 - tmp3;
  2109. tmp11 = tmp1 + tmp2;
  2110. tmp13 = tmp1 - tmp2;
  2111. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  2112. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  2113. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  2114. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  2115. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS+1);
  2116. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS+1);
  2117. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  2118. dataptr[DCTSIZE*2] = (DCTELEM)
  2119. DESCALE(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  2120. CONST_BITS+PASS1_BITS+1);
  2121. dataptr[DCTSIZE*6] = (DCTELEM)
  2122. DESCALE(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  2123. CONST_BITS+PASS1_BITS+1);
  2124. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  2125. * i0..i3 in the paper are tmp0..tmp3 here.
  2126. */
  2127. tmp12 = tmp0 + tmp2;
  2128. tmp13 = tmp1 + tmp3;
  2129. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  2130. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  2131. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  2132. tmp12 += z1;
  2133. tmp13 += z1;
  2134. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  2135. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  2136. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  2137. tmp0 += z1 + tmp12;
  2138. tmp3 += z1 + tmp13;
  2139. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  2140. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  2141. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  2142. tmp1 += z1 + tmp13;
  2143. tmp2 += z1 + tmp12;
  2144. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS+1);
  2145. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS+1);
  2146. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS+1);
  2147. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+PASS1_BITS+1);
  2148. dataptr++; /* advance pointer to next column */
  2149. }
  2150. }
  2151. /*
  2152. * Perform the forward DCT on a 14x7 sample block.
  2153. *
  2154. * 14-point FDCT in pass 1 (rows), 7-point in pass 2 (columns).
  2155. */
  2156. GLOBAL(void)
  2157. jpeg_fdct_14x7 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2158. {
  2159. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  2160. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  2161. INT32 z1, z2, z3;
  2162. DCTELEM *dataptr;
  2163. JSAMPROW elemptr;
  2164. int ctr;
  2165. SHIFT_TEMPS
  2166. /* Zero bottom row of output coefficient block. */
  2167. MEMZERO(&data[DCTSIZE*7], SIZEOF(DCTELEM) * DCTSIZE);
  2168. /* Pass 1: process rows.
  2169. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2170. * furthermore, we scale the results by 2**PASS1_BITS.
  2171. * 14-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/28).
  2172. */
  2173. dataptr = data;
  2174. for (ctr = 0; ctr < 7; ctr++) {
  2175. elemptr = sample_data[ctr] + start_col;
  2176. /* Even part */
  2177. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[13]);
  2178. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[12]);
  2179. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[11]);
  2180. tmp13 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[10]);
  2181. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[9]);
  2182. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[8]);
  2183. tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[7]);
  2184. tmp10 = tmp0 + tmp6;
  2185. tmp14 = tmp0 - tmp6;
  2186. tmp11 = tmp1 + tmp5;
  2187. tmp15 = tmp1 - tmp5;
  2188. tmp12 = tmp2 + tmp4;
  2189. tmp16 = tmp2 - tmp4;
  2190. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[13]);
  2191. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[12]);
  2192. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[11]);
  2193. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[10]);
  2194. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[9]);
  2195. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[8]);
  2196. tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[7]);
  2197. /* Apply unsigned->signed conversion */
  2198. dataptr[0] = (DCTELEM)
  2199. ((tmp10 + tmp11 + tmp12 + tmp13 - 14 * CENTERJSAMPLE) << PASS1_BITS);
  2200. tmp13 += tmp13;
  2201. dataptr[4] = (DCTELEM)
  2202. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.274162392)) + /* c4 */
  2203. MULTIPLY(tmp11 - tmp13, FIX(0.314692123)) - /* c12 */
  2204. MULTIPLY(tmp12 - tmp13, FIX(0.881747734)), /* c8 */
  2205. CONST_BITS-PASS1_BITS);
  2206. tmp10 = MULTIPLY(tmp14 + tmp15, FIX(1.105676686)); /* c6 */
  2207. dataptr[2] = (DCTELEM)
  2208. DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.273079590)) /* c2-c6 */
  2209. + MULTIPLY(tmp16, FIX(0.613604268)), /* c10 */
  2210. CONST_BITS-PASS1_BITS);
  2211. dataptr[6] = (DCTELEM)
  2212. DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.719280954)) /* c6+c10 */
  2213. - MULTIPLY(tmp16, FIX(1.378756276)), /* c2 */
  2214. CONST_BITS-PASS1_BITS);
  2215. /* Odd part */
  2216. tmp10 = tmp1 + tmp2;
  2217. tmp11 = tmp5 - tmp4;
  2218. dataptr[7] = (DCTELEM) ((tmp0 - tmp10 + tmp3 - tmp11 - tmp6) << PASS1_BITS);
  2219. tmp3 <<= CONST_BITS;
  2220. tmp10 = MULTIPLY(tmp10, - FIX(0.158341681)); /* -c13 */
  2221. tmp11 = MULTIPLY(tmp11, FIX(1.405321284)); /* c1 */
  2222. tmp10 += tmp11 - tmp3;
  2223. tmp11 = MULTIPLY(tmp0 + tmp2, FIX(1.197448846)) + /* c5 */
  2224. MULTIPLY(tmp4 + tmp6, FIX(0.752406978)); /* c9 */
  2225. dataptr[5] = (DCTELEM)
  2226. DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(2.373959773)) /* c3+c5-c13 */
  2227. + MULTIPLY(tmp4, FIX(1.119999435)), /* c1+c11-c9 */
  2228. CONST_BITS-PASS1_BITS);
  2229. tmp12 = MULTIPLY(tmp0 + tmp1, FIX(1.334852607)) + /* c3 */
  2230. MULTIPLY(tmp5 - tmp6, FIX(0.467085129)); /* c11 */
  2231. dataptr[3] = (DCTELEM)
  2232. DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.424103948)) /* c3-c9-c13 */
  2233. - MULTIPLY(tmp5, FIX(3.069855259)), /* c1+c5+c11 */
  2234. CONST_BITS-PASS1_BITS);
  2235. dataptr[1] = (DCTELEM)
  2236. DESCALE(tmp11 + tmp12 + tmp3 + tmp6 -
  2237. MULTIPLY(tmp0 + tmp6, FIX(1.126980169)), /* c3+c5-c1 */
  2238. CONST_BITS-PASS1_BITS);
  2239. dataptr += DCTSIZE; /* advance pointer to next row */
  2240. }
  2241. /* Pass 2: process columns.
  2242. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2243. * by an overall factor of 8.
  2244. * We must also scale the output by (8/14)*(8/7) = 32/49, which we
  2245. * partially fold into the constant multipliers and final shifting:
  2246. * 7-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/14) * 64/49.
  2247. */
  2248. dataptr = data;
  2249. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2250. /* Even part */
  2251. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*6];
  2252. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*5];
  2253. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*4];
  2254. tmp3 = dataptr[DCTSIZE*3];
  2255. tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*6];
  2256. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*5];
  2257. tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*4];
  2258. z1 = tmp0 + tmp2;
  2259. dataptr[DCTSIZE*0] = (DCTELEM)
  2260. DESCALE(MULTIPLY(z1 + tmp1 + tmp3, FIX(1.306122449)), /* 64/49 */
  2261. CONST_BITS+PASS1_BITS+1);
  2262. tmp3 += tmp3;
  2263. z1 -= tmp3;
  2264. z1 -= tmp3;
  2265. z1 = MULTIPLY(z1, FIX(0.461784020)); /* (c2+c6-c4)/2 */
  2266. z2 = MULTIPLY(tmp0 - tmp2, FIX(1.202428084)); /* (c2+c4-c6)/2 */
  2267. z3 = MULTIPLY(tmp1 - tmp2, FIX(0.411026446)); /* c6 */
  2268. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS+PASS1_BITS+1);
  2269. z1 -= z2;
  2270. z2 = MULTIPLY(tmp0 - tmp1, FIX(1.151670509)); /* c4 */
  2271. dataptr[DCTSIZE*4] = (DCTELEM)
  2272. DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.923568041)), /* c2+c6-c4 */
  2273. CONST_BITS+PASS1_BITS+1);
  2274. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+PASS1_BITS+1);
  2275. /* Odd part */
  2276. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.221765677)); /* (c3+c1-c5)/2 */
  2277. tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.222383464)); /* (c3+c5-c1)/2 */
  2278. tmp0 = tmp1 - tmp2;
  2279. tmp1 += tmp2;
  2280. tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.800824523)); /* -c1 */
  2281. tmp1 += tmp2;
  2282. tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.801442310)); /* c5 */
  2283. tmp0 += tmp3;
  2284. tmp2 += tmp3 + MULTIPLY(tmp12, FIX(2.443531355)); /* c3+c1-c5 */
  2285. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS+1);
  2286. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS+1);
  2287. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS+1);
  2288. dataptr++; /* advance pointer to next column */
  2289. }
  2290. }
  2291. /*
  2292. * Perform the forward DCT on a 12x6 sample block.
  2293. *
  2294. * 12-point FDCT in pass 1 (rows), 6-point in pass 2 (columns).
  2295. */
  2296. GLOBAL(void)
  2297. jpeg_fdct_12x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2298. {
  2299. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  2300. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  2301. DCTELEM *dataptr;
  2302. JSAMPROW elemptr;
  2303. int ctr;
  2304. SHIFT_TEMPS
  2305. /* Zero 2 bottom rows of output coefficient block. */
  2306. MEMZERO(&data[DCTSIZE*6], SIZEOF(DCTELEM) * DCTSIZE * 2);
  2307. /* Pass 1: process rows.
  2308. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2309. * furthermore, we scale the results by 2**PASS1_BITS.
  2310. * 12-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/24).
  2311. */
  2312. dataptr = data;
  2313. for (ctr = 0; ctr < 6; ctr++) {
  2314. elemptr = sample_data[ctr] + start_col;
  2315. /* Even part */
  2316. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[11]);
  2317. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[10]);
  2318. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[9]);
  2319. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[8]);
  2320. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[7]);
  2321. tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[6]);
  2322. tmp10 = tmp0 + tmp5;
  2323. tmp13 = tmp0 - tmp5;
  2324. tmp11 = tmp1 + tmp4;
  2325. tmp14 = tmp1 - tmp4;
  2326. tmp12 = tmp2 + tmp3;
  2327. tmp15 = tmp2 - tmp3;
  2328. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[11]);
  2329. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[10]);
  2330. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[9]);
  2331. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[8]);
  2332. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[7]);
  2333. tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[6]);
  2334. /* Apply unsigned->signed conversion */
  2335. dataptr[0] = (DCTELEM)
  2336. ((tmp10 + tmp11 + tmp12 - 12 * CENTERJSAMPLE) << PASS1_BITS);
  2337. dataptr[6] = (DCTELEM) ((tmp13 - tmp14 - tmp15) << PASS1_BITS);
  2338. dataptr[4] = (DCTELEM)
  2339. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.224744871)), /* c4 */
  2340. CONST_BITS-PASS1_BITS);
  2341. dataptr[2] = (DCTELEM)
  2342. DESCALE(tmp14 - tmp15 + MULTIPLY(tmp13 + tmp15, FIX(1.366025404)), /* c2 */
  2343. CONST_BITS-PASS1_BITS);
  2344. /* Odd part */
  2345. tmp10 = MULTIPLY(tmp1 + tmp4, FIX_0_541196100); /* c9 */
  2346. tmp14 = tmp10 + MULTIPLY(tmp1, FIX_0_765366865); /* c3-c9 */
  2347. tmp15 = tmp10 - MULTIPLY(tmp4, FIX_1_847759065); /* c3+c9 */
  2348. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.121971054)); /* c5 */
  2349. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.860918669)); /* c7 */
  2350. tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.580774953)) /* c5+c7-c1 */
  2351. + MULTIPLY(tmp5, FIX(0.184591911)); /* c11 */
  2352. tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.184591911)); /* -c11 */
  2353. tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.339493912)) /* c1+c5-c11 */
  2354. + MULTIPLY(tmp5, FIX(0.860918669)); /* c7 */
  2355. tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.725788011)) /* c1+c11-c7 */
  2356. - MULTIPLY(tmp5, FIX(1.121971054)); /* c5 */
  2357. tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.306562965)) /* c3 */
  2358. - MULTIPLY(tmp2 + tmp5, FIX_0_541196100); /* c9 */
  2359. dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
  2360. dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
  2361. dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
  2362. dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
  2363. dataptr += DCTSIZE; /* advance pointer to next row */
  2364. }
  2365. /* Pass 2: process columns.
  2366. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2367. * by an overall factor of 8.
  2368. * We must also scale the output by (8/12)*(8/6) = 8/9, which we
  2369. * partially fold into the constant multipliers and final shifting:
  2370. * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12) * 16/9.
  2371. */
  2372. dataptr = data;
  2373. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2374. /* Even part */
  2375. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];
  2376. tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];
  2377. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
  2378. tmp10 = tmp0 + tmp2;
  2379. tmp12 = tmp0 - tmp2;
  2380. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];
  2381. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];
  2382. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
  2383. dataptr[DCTSIZE*0] = (DCTELEM)
  2384. DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)), /* 16/9 */
  2385. CONST_BITS+PASS1_BITS+1);
  2386. dataptr[DCTSIZE*2] = (DCTELEM)
  2387. DESCALE(MULTIPLY(tmp12, FIX(2.177324216)), /* c2 */
  2388. CONST_BITS+PASS1_BITS+1);
  2389. dataptr[DCTSIZE*4] = (DCTELEM)
  2390. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */
  2391. CONST_BITS+PASS1_BITS+1);
  2392. /* Odd part */
  2393. tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829)); /* c5 */
  2394. dataptr[DCTSIZE*1] = (DCTELEM)
  2395. DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
  2396. CONST_BITS+PASS1_BITS+1);
  2397. dataptr[DCTSIZE*3] = (DCTELEM)
  2398. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)), /* 16/9 */
  2399. CONST_BITS+PASS1_BITS+1);
  2400. dataptr[DCTSIZE*5] = (DCTELEM)
  2401. DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)), /* 16/9 */
  2402. CONST_BITS+PASS1_BITS+1);
  2403. dataptr++; /* advance pointer to next column */
  2404. }
  2405. }
  2406. /*
  2407. * Perform the forward DCT on a 10x5 sample block.
  2408. *
  2409. * 10-point FDCT in pass 1 (rows), 5-point in pass 2 (columns).
  2410. */
  2411. GLOBAL(void)
  2412. jpeg_fdct_10x5 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2413. {
  2414. INT32 tmp0, tmp1, tmp2, tmp3, tmp4;
  2415. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  2416. DCTELEM *dataptr;
  2417. JSAMPROW elemptr;
  2418. int ctr;
  2419. SHIFT_TEMPS
  2420. /* Zero 3 bottom rows of output coefficient block. */
  2421. MEMZERO(&data[DCTSIZE*5], SIZEOF(DCTELEM) * DCTSIZE * 3);
  2422. /* Pass 1: process rows.
  2423. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2424. * furthermore, we scale the results by 2**PASS1_BITS.
  2425. * 10-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/20).
  2426. */
  2427. dataptr = data;
  2428. for (ctr = 0; ctr < 5; ctr++) {
  2429. elemptr = sample_data[ctr] + start_col;
  2430. /* Even part */
  2431. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[9]);
  2432. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[8]);
  2433. tmp12 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[7]);
  2434. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[6]);
  2435. tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[5]);
  2436. tmp10 = tmp0 + tmp4;
  2437. tmp13 = tmp0 - tmp4;
  2438. tmp11 = tmp1 + tmp3;
  2439. tmp14 = tmp1 - tmp3;
  2440. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[9]);
  2441. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[8]);
  2442. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[7]);
  2443. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[6]);
  2444. tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[5]);
  2445. /* Apply unsigned->signed conversion */
  2446. dataptr[0] = (DCTELEM)
  2447. ((tmp10 + tmp11 + tmp12 - 10 * CENTERJSAMPLE) << PASS1_BITS);
  2448. tmp12 += tmp12;
  2449. dataptr[4] = (DCTELEM)
  2450. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.144122806)) - /* c4 */
  2451. MULTIPLY(tmp11 - tmp12, FIX(0.437016024)), /* c8 */
  2452. CONST_BITS-PASS1_BITS);
  2453. tmp10 = MULTIPLY(tmp13 + tmp14, FIX(0.831253876)); /* c6 */
  2454. dataptr[2] = (DCTELEM)
  2455. DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.513743148)), /* c2-c6 */
  2456. CONST_BITS-PASS1_BITS);
  2457. dataptr[6] = (DCTELEM)
  2458. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.176250899)), /* c2+c6 */
  2459. CONST_BITS-PASS1_BITS);
  2460. /* Odd part */
  2461. tmp10 = tmp0 + tmp4;
  2462. tmp11 = tmp1 - tmp3;
  2463. dataptr[5] = (DCTELEM) ((tmp10 - tmp11 - tmp2) << PASS1_BITS);
  2464. tmp2 <<= CONST_BITS;
  2465. dataptr[1] = (DCTELEM)
  2466. DESCALE(MULTIPLY(tmp0, FIX(1.396802247)) + /* c1 */
  2467. MULTIPLY(tmp1, FIX(1.260073511)) + tmp2 + /* c3 */
  2468. MULTIPLY(tmp3, FIX(0.642039522)) + /* c7 */
  2469. MULTIPLY(tmp4, FIX(0.221231742)), /* c9 */
  2470. CONST_BITS-PASS1_BITS);
  2471. tmp12 = MULTIPLY(tmp0 - tmp4, FIX(0.951056516)) - /* (c3+c7)/2 */
  2472. MULTIPLY(tmp1 + tmp3, FIX(0.587785252)); /* (c1-c9)/2 */
  2473. tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.309016994)) + /* (c3-c7)/2 */
  2474. (tmp11 << (CONST_BITS - 1)) - tmp2;
  2475. dataptr[3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS-PASS1_BITS);
  2476. dataptr[7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS-PASS1_BITS);
  2477. dataptr += DCTSIZE; /* advance pointer to next row */
  2478. }
  2479. /* Pass 2: process columns.
  2480. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2481. * by an overall factor of 8.
  2482. * We must also scale the output by (8/10)*(8/5) = 32/25, which we
  2483. * fold into the constant multipliers:
  2484. * 5-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/10) * 32/25.
  2485. */
  2486. dataptr = data;
  2487. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2488. /* Even part */
  2489. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*4];
  2490. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*3];
  2491. tmp2 = dataptr[DCTSIZE*2];
  2492. tmp10 = tmp0 + tmp1;
  2493. tmp11 = tmp0 - tmp1;
  2494. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*4];
  2495. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*3];
  2496. dataptr[DCTSIZE*0] = (DCTELEM)
  2497. DESCALE(MULTIPLY(tmp10 + tmp2, FIX(1.28)), /* 32/25 */
  2498. CONST_BITS+PASS1_BITS);
  2499. tmp11 = MULTIPLY(tmp11, FIX(1.011928851)); /* (c2+c4)/2 */
  2500. tmp10 -= tmp2 << 2;
  2501. tmp10 = MULTIPLY(tmp10, FIX(0.452548340)); /* (c2-c4)/2 */
  2502. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS+PASS1_BITS);
  2503. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS+PASS1_BITS);
  2504. /* Odd part */
  2505. tmp10 = MULTIPLY(tmp0 + tmp1, FIX(1.064004961)); /* c3 */
  2506. dataptr[DCTSIZE*1] = (DCTELEM)
  2507. DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.657591230)), /* c1-c3 */
  2508. CONST_BITS+PASS1_BITS);
  2509. dataptr[DCTSIZE*3] = (DCTELEM)
  2510. DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.785601151)), /* c1+c3 */
  2511. CONST_BITS+PASS1_BITS);
  2512. dataptr++; /* advance pointer to next column */
  2513. }
  2514. }
  2515. /*
  2516. * Perform the forward DCT on an 8x4 sample block.
  2517. *
  2518. * 8-point FDCT in pass 1 (rows), 4-point in pass 2 (columns).
  2519. */
  2520. GLOBAL(void)
  2521. jpeg_fdct_8x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2522. {
  2523. INT32 tmp0, tmp1, tmp2, tmp3;
  2524. INT32 tmp10, tmp11, tmp12, tmp13;
  2525. INT32 z1;
  2526. DCTELEM *dataptr;
  2527. JSAMPROW elemptr;
  2528. int ctr;
  2529. SHIFT_TEMPS
  2530. /* Zero 4 bottom rows of output coefficient block. */
  2531. MEMZERO(&data[DCTSIZE*4], SIZEOF(DCTELEM) * DCTSIZE * 4);
  2532. /* Pass 1: process rows.
  2533. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2534. * furthermore, we scale the results by 2**PASS1_BITS.
  2535. * We must also scale the output by 8/4 = 2, which we add here.
  2536. * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
  2537. */
  2538. dataptr = data;
  2539. for (ctr = 0; ctr < 4; ctr++) {
  2540. elemptr = sample_data[ctr] + start_col;
  2541. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  2542. * rotator "c1" should be "c6".
  2543. */
  2544. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);
  2545. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);
  2546. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);
  2547. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);
  2548. tmp10 = tmp0 + tmp3;
  2549. tmp12 = tmp0 - tmp3;
  2550. tmp11 = tmp1 + tmp2;
  2551. tmp13 = tmp1 - tmp2;
  2552. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);
  2553. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);
  2554. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);
  2555. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);
  2556. /* Apply unsigned->signed conversion */
  2557. dataptr[0] = (DCTELEM)
  2558. ((tmp10 + tmp11 - 8 * CENTERJSAMPLE) << (PASS1_BITS+1));
  2559. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << (PASS1_BITS+1));
  2560. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  2561. /* Add fudge factor here for final descale. */
  2562. z1 += ONE << (CONST_BITS-PASS1_BITS-2);
  2563. dataptr[2] = (DCTELEM)
  2564. RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  2565. CONST_BITS-PASS1_BITS-1);
  2566. dataptr[6] = (DCTELEM)
  2567. RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  2568. CONST_BITS-PASS1_BITS-1);
  2569. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  2570. * i0..i3 in the paper are tmp0..tmp3 here.
  2571. */
  2572. tmp12 = tmp0 + tmp2;
  2573. tmp13 = tmp1 + tmp3;
  2574. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  2575. /* Add fudge factor here for final descale. */
  2576. z1 += ONE << (CONST_BITS-PASS1_BITS-2);
  2577. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  2578. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  2579. tmp12 += z1;
  2580. tmp13 += z1;
  2581. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  2582. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  2583. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  2584. tmp0 += z1 + tmp12;
  2585. tmp3 += z1 + tmp13;
  2586. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  2587. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  2588. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  2589. tmp1 += z1 + tmp13;
  2590. tmp2 += z1 + tmp12;
  2591. dataptr[1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS-PASS1_BITS-1);
  2592. dataptr[3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS-PASS1_BITS-1);
  2593. dataptr[5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS-1);
  2594. dataptr[7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS-PASS1_BITS-1);
  2595. dataptr += DCTSIZE; /* advance pointer to next row */
  2596. }
  2597. /* Pass 2: process columns.
  2598. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2599. * by an overall factor of 8.
  2600. * 4-point FDCT kernel,
  2601. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  2602. */
  2603. dataptr = data;
  2604. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2605. /* Even part */
  2606. /* Add fudge factor here for final descale. */
  2607. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*3] + (ONE << (PASS1_BITS-1));
  2608. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*2];
  2609. tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];
  2610. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];
  2611. dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp0 + tmp1, PASS1_BITS);
  2612. dataptr[DCTSIZE*2] = (DCTELEM) RIGHT_SHIFT(tmp0 - tmp1, PASS1_BITS);
  2613. /* Odd part */
  2614. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  2615. /* Add fudge factor here for final descale. */
  2616. tmp0 += ONE << (CONST_BITS+PASS1_BITS-1);
  2617. dataptr[DCTSIZE*1] = (DCTELEM)
  2618. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  2619. CONST_BITS+PASS1_BITS);
  2620. dataptr[DCTSIZE*3] = (DCTELEM)
  2621. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  2622. CONST_BITS+PASS1_BITS);
  2623. dataptr++; /* advance pointer to next column */
  2624. }
  2625. }
  2626. /*
  2627. * Perform the forward DCT on a 6x3 sample block.
  2628. *
  2629. * 6-point FDCT in pass 1 (rows), 3-point in pass 2 (columns).
  2630. */
  2631. GLOBAL(void)
  2632. jpeg_fdct_6x3 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2633. {
  2634. INT32 tmp0, tmp1, tmp2;
  2635. INT32 tmp10, tmp11, tmp12;
  2636. DCTELEM *dataptr;
  2637. JSAMPROW elemptr;
  2638. int ctr;
  2639. SHIFT_TEMPS
  2640. /* Pre-zero output coefficient block. */
  2641. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  2642. /* Pass 1: process rows.
  2643. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2644. * furthermore, we scale the results by 2**PASS1_BITS.
  2645. * We scale the results further by 2 as part of output adaption
  2646. * scaling for different DCT size.
  2647. * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12).
  2648. */
  2649. dataptr = data;
  2650. for (ctr = 0; ctr < 3; ctr++) {
  2651. elemptr = sample_data[ctr] + start_col;
  2652. /* Even part */
  2653. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);
  2654. tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);
  2655. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);
  2656. tmp10 = tmp0 + tmp2;
  2657. tmp12 = tmp0 - tmp2;
  2658. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);
  2659. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);
  2660. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);
  2661. /* Apply unsigned->signed conversion */
  2662. dataptr[0] = (DCTELEM)
  2663. ((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << (PASS1_BITS+1));
  2664. dataptr[2] = (DCTELEM)
  2665. DESCALE(MULTIPLY(tmp12, FIX(1.224744871)), /* c2 */
  2666. CONST_BITS-PASS1_BITS-1);
  2667. dataptr[4] = (DCTELEM)
  2668. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */
  2669. CONST_BITS-PASS1_BITS-1);
  2670. /* Odd part */
  2671. tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)), /* c5 */
  2672. CONST_BITS-PASS1_BITS-1);
  2673. dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << (PASS1_BITS+1)));
  2674. dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << (PASS1_BITS+1));
  2675. dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << (PASS1_BITS+1)));
  2676. dataptr += DCTSIZE; /* advance pointer to next row */
  2677. }
  2678. /* Pass 2: process columns.
  2679. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2680. * by an overall factor of 8.
  2681. * We must also scale the output by (8/6)*(8/3) = 32/9, which we partially
  2682. * fold into the constant multipliers (other part was done in pass 1):
  2683. * 3-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/6) * 16/9.
  2684. */
  2685. dataptr = data;
  2686. for (ctr = 0; ctr < 6; ctr++) {
  2687. /* Even part */
  2688. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*2];
  2689. tmp1 = dataptr[DCTSIZE*1];
  2690. tmp2 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*2];
  2691. dataptr[DCTSIZE*0] = (DCTELEM)
  2692. DESCALE(MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
  2693. CONST_BITS+PASS1_BITS);
  2694. dataptr[DCTSIZE*2] = (DCTELEM)
  2695. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(1.257078722)), /* c2 */
  2696. CONST_BITS+PASS1_BITS);
  2697. /* Odd part */
  2698. dataptr[DCTSIZE*1] = (DCTELEM)
  2699. DESCALE(MULTIPLY(tmp2, FIX(2.177324216)), /* c1 */
  2700. CONST_BITS+PASS1_BITS);
  2701. dataptr++; /* advance pointer to next column */
  2702. }
  2703. }
  2704. /*
  2705. * Perform the forward DCT on a 4x2 sample block.
  2706. *
  2707. * 4-point FDCT in pass 1 (rows), 2-point in pass 2 (columns).
  2708. */
  2709. GLOBAL(void)
  2710. jpeg_fdct_4x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2711. {
  2712. INT32 tmp0, tmp1;
  2713. INT32 tmp10, tmp11;
  2714. DCTELEM *dataptr;
  2715. JSAMPROW elemptr;
  2716. int ctr;
  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. * furthermore, we scale the results by 2**PASS1_BITS.
  2723. * We must also scale the output by (8/4)*(8/2) = 2**3, which we add here.
  2724. * 4-point FDCT kernel,
  2725. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  2726. */
  2727. dataptr = data;
  2728. for (ctr = 0; ctr < 2; ctr++) {
  2729. elemptr = sample_data[ctr] + start_col;
  2730. /* Even part */
  2731. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);
  2732. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);
  2733. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);
  2734. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
  2735. /* Apply unsigned->signed conversion */
  2736. dataptr[0] = (DCTELEM)
  2737. ((tmp0 + tmp1 - 4 * CENTERJSAMPLE) << (PASS1_BITS+3));
  2738. dataptr[2] = (DCTELEM) ((tmp0 - tmp1) << (PASS1_BITS+3));
  2739. /* Odd part */
  2740. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  2741. /* Add fudge factor here for final descale. */
  2742. tmp0 += ONE << (CONST_BITS-PASS1_BITS-4);
  2743. dataptr[1] = (DCTELEM)
  2744. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  2745. CONST_BITS-PASS1_BITS-3);
  2746. dataptr[3] = (DCTELEM)
  2747. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  2748. CONST_BITS-PASS1_BITS-3);
  2749. dataptr += DCTSIZE; /* advance pointer to next row */
  2750. }
  2751. /* Pass 2: process columns.
  2752. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2753. * by an overall factor of 8.
  2754. */
  2755. dataptr = data;
  2756. for (ctr = 0; ctr < 4; ctr++) {
  2757. /* Even part */
  2758. /* Add fudge factor here for final descale. */
  2759. tmp0 = dataptr[DCTSIZE*0] + (ONE << (PASS1_BITS-1));
  2760. tmp1 = dataptr[DCTSIZE*1];
  2761. dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp0 + tmp1, PASS1_BITS);
  2762. /* Odd part */
  2763. dataptr[DCTSIZE*1] = (DCTELEM) RIGHT_SHIFT(tmp0 - tmp1, PASS1_BITS);
  2764. dataptr++; /* advance pointer to next column */
  2765. }
  2766. }
  2767. /*
  2768. * Perform the forward DCT on a 2x1 sample block.
  2769. *
  2770. * 2-point FDCT in pass 1 (rows), 1-point in pass 2 (columns).
  2771. */
  2772. GLOBAL(void)
  2773. jpeg_fdct_2x1 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2774. {
  2775. INT32 tmp0, tmp1;
  2776. JSAMPROW elemptr;
  2777. /* Pre-zero output coefficient block. */
  2778. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  2779. elemptr = sample_data[0] + start_col;
  2780. tmp0 = GETJSAMPLE(elemptr[0]);
  2781. tmp1 = GETJSAMPLE(elemptr[1]);
  2782. /* We leave the results scaled up by an overall factor of 8.
  2783. * We must also scale the output by (8/2)*(8/1) = 2**5.
  2784. */
  2785. /* Even part */
  2786. /* Apply unsigned->signed conversion */
  2787. data[0] = (DCTELEM) ((tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 5);
  2788. /* Odd part */
  2789. data[1] = (DCTELEM) ((tmp0 - tmp1) << 5);
  2790. }
  2791. /*
  2792. * Perform the forward DCT on an 8x16 sample block.
  2793. *
  2794. * 8-point FDCT in pass 1 (rows), 16-point in pass 2 (columns).
  2795. */
  2796. GLOBAL(void)
  2797. jpeg_fdct_8x16 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2798. {
  2799. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  2800. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;
  2801. INT32 z1;
  2802. DCTELEM workspace[DCTSIZE2];
  2803. DCTELEM *dataptr;
  2804. DCTELEM *wsptr;
  2805. JSAMPROW elemptr;
  2806. int ctr;
  2807. SHIFT_TEMPS
  2808. /* Pass 1: process rows.
  2809. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2810. * furthermore, we scale the results by 2**PASS1_BITS.
  2811. * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
  2812. */
  2813. dataptr = data;
  2814. ctr = 0;
  2815. for (;;) {
  2816. elemptr = sample_data[ctr] + start_col;
  2817. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  2818. * rotator "c1" should be "c6".
  2819. */
  2820. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);
  2821. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);
  2822. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);
  2823. tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);
  2824. tmp10 = tmp0 + tmp3;
  2825. tmp12 = tmp0 - tmp3;
  2826. tmp11 = tmp1 + tmp2;
  2827. tmp13 = tmp1 - tmp2;
  2828. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);
  2829. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);
  2830. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);
  2831. tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);
  2832. /* Apply unsigned->signed conversion */
  2833. dataptr[0] = (DCTELEM) ((tmp10 + tmp11 - 8 * CENTERJSAMPLE) << PASS1_BITS);
  2834. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  2835. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  2836. dataptr[2] = (DCTELEM)
  2837. DESCALE(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  2838. CONST_BITS-PASS1_BITS);
  2839. dataptr[6] = (DCTELEM)
  2840. DESCALE(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  2841. CONST_BITS-PASS1_BITS);
  2842. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  2843. * i0..i3 in the paper are tmp0..tmp3 here.
  2844. */
  2845. tmp12 = tmp0 + tmp2;
  2846. tmp13 = tmp1 + tmp3;
  2847. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  2848. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  2849. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  2850. tmp12 += z1;
  2851. tmp13 += z1;
  2852. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  2853. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  2854. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  2855. tmp0 += z1 + tmp12;
  2856. tmp3 += z1 + tmp13;
  2857. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  2858. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  2859. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  2860. tmp1 += z1 + tmp13;
  2861. tmp2 += z1 + tmp12;
  2862. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);
  2863. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);
  2864. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);
  2865. dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS-PASS1_BITS);
  2866. ctr++;
  2867. if (ctr != DCTSIZE) {
  2868. if (ctr == DCTSIZE * 2)
  2869. break; /* Done. */
  2870. dataptr += DCTSIZE; /* advance pointer to next row */
  2871. } else
  2872. dataptr = workspace; /* switch pointer to extended workspace */
  2873. }
  2874. /* Pass 2: process columns.
  2875. * We remove the PASS1_BITS scaling, but leave the results scaled up
  2876. * by an overall factor of 8.
  2877. * We must also scale the output by 8/16 = 1/2.
  2878. * 16-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/32).
  2879. */
  2880. dataptr = data;
  2881. wsptr = workspace;
  2882. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  2883. /* Even part */
  2884. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*7];
  2885. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*6];
  2886. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*5];
  2887. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*4];
  2888. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*3];
  2889. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*2];
  2890. tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*1];
  2891. tmp7 = dataptr[DCTSIZE*7] + wsptr[DCTSIZE*0];
  2892. tmp10 = tmp0 + tmp7;
  2893. tmp14 = tmp0 - tmp7;
  2894. tmp11 = tmp1 + tmp6;
  2895. tmp15 = tmp1 - tmp6;
  2896. tmp12 = tmp2 + tmp5;
  2897. tmp16 = tmp2 - tmp5;
  2898. tmp13 = tmp3 + tmp4;
  2899. tmp17 = tmp3 - tmp4;
  2900. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*7];
  2901. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*6];
  2902. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*5];
  2903. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*4];
  2904. tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*3];
  2905. tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*2];
  2906. tmp6 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*1];
  2907. tmp7 = dataptr[DCTSIZE*7] - wsptr[DCTSIZE*0];
  2908. dataptr[DCTSIZE*0] = (DCTELEM)
  2909. DESCALE(tmp10 + tmp11 + tmp12 + tmp13, PASS1_BITS+1);
  2910. dataptr[DCTSIZE*4] = (DCTELEM)
  2911. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */
  2912. MULTIPLY(tmp11 - tmp12, FIX_0_541196100), /* c12[16] = c6[8] */
  2913. CONST_BITS+PASS1_BITS+1);
  2914. tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) + /* c14[16] = c7[8] */
  2915. MULTIPLY(tmp14 - tmp16, FIX(1.387039845)); /* c2[16] = c1[8] */
  2916. dataptr[DCTSIZE*2] = (DCTELEM)
  2917. DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982)) /* c6+c14 */
  2918. + MULTIPLY(tmp16, FIX(2.172734804)), /* c2+c10 */
  2919. CONST_BITS+PASS1_BITS+1);
  2920. dataptr[DCTSIZE*6] = (DCTELEM)
  2921. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243)) /* c2-c6 */
  2922. - MULTIPLY(tmp17, FIX(1.061594338)), /* c10+c14 */
  2923. CONST_BITS+PASS1_BITS+1);
  2924. /* Odd part */
  2925. tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) + /* c3 */
  2926. MULTIPLY(tmp6 - tmp7, FIX(0.410524528)); /* c13 */
  2927. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) + /* c5 */
  2928. MULTIPLY(tmp5 + tmp7, FIX(0.666655658)); /* c11 */
  2929. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) + /* c7 */
  2930. MULTIPLY(tmp4 - tmp7, FIX(0.897167586)); /* c9 */
  2931. tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) + /* c15 */
  2932. MULTIPLY(tmp6 - tmp5, FIX(1.407403738)); /* c1 */
  2933. tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) + /* -c11 */
  2934. MULTIPLY(tmp4 + tmp6, - FIX(1.247225013)); /* -c5 */
  2935. tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) + /* -c3 */
  2936. MULTIPLY(tmp5 - tmp4, FIX(0.410524528)); /* c13 */
  2937. tmp10 = tmp11 + tmp12 + tmp13 -
  2938. MULTIPLY(tmp0, FIX(2.286341144)) + /* c7+c5+c3-c1 */
  2939. MULTIPLY(tmp7, FIX(0.779653625)); /* c15+c13-c11+c9 */
  2940. tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */
  2941. - MULTIPLY(tmp6, FIX(1.663905119)); /* c7+c13+c1-c5 */
  2942. tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */
  2943. + MULTIPLY(tmp5, FIX(1.227391138)); /* c9-c11+c1-c13 */
  2944. tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */
  2945. + MULTIPLY(tmp4, FIX(2.167985692)); /* c1+c13+c5-c9 */
  2946. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS+1);
  2947. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS+1);
  2948. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS+1);
  2949. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS+1);
  2950. dataptr++; /* advance pointer to next column */
  2951. wsptr++; /* advance pointer to next column */
  2952. }
  2953. }
  2954. /*
  2955. * Perform the forward DCT on a 7x14 sample block.
  2956. *
  2957. * 7-point FDCT in pass 1 (rows), 14-point in pass 2 (columns).
  2958. */
  2959. GLOBAL(void)
  2960. jpeg_fdct_7x14 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  2961. {
  2962. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  2963. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  2964. INT32 z1, z2, z3;
  2965. DCTELEM workspace[8*6];
  2966. DCTELEM *dataptr;
  2967. DCTELEM *wsptr;
  2968. JSAMPROW elemptr;
  2969. int ctr;
  2970. SHIFT_TEMPS
  2971. /* Pre-zero output coefficient block. */
  2972. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  2973. /* Pass 1: process rows.
  2974. * Note results are scaled up by sqrt(8) compared to a true DCT;
  2975. * furthermore, we scale the results by 2**PASS1_BITS.
  2976. * 7-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/14).
  2977. */
  2978. dataptr = data;
  2979. ctr = 0;
  2980. for (;;) {
  2981. elemptr = sample_data[ctr] + start_col;
  2982. /* Even part */
  2983. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[6]);
  2984. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[5]);
  2985. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[4]);
  2986. tmp3 = GETJSAMPLE(elemptr[3]);
  2987. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[6]);
  2988. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[5]);
  2989. tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[4]);
  2990. z1 = tmp0 + tmp2;
  2991. /* Apply unsigned->signed conversion */
  2992. dataptr[0] = (DCTELEM)
  2993. ((z1 + tmp1 + tmp3 - 7 * CENTERJSAMPLE) << PASS1_BITS);
  2994. tmp3 += tmp3;
  2995. z1 -= tmp3;
  2996. z1 -= tmp3;
  2997. z1 = MULTIPLY(z1, FIX(0.353553391)); /* (c2+c6-c4)/2 */
  2998. z2 = MULTIPLY(tmp0 - tmp2, FIX(0.920609002)); /* (c2+c4-c6)/2 */
  2999. z3 = MULTIPLY(tmp1 - tmp2, FIX(0.314692123)); /* c6 */
  3000. dataptr[2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS-PASS1_BITS);
  3001. z1 -= z2;
  3002. z2 = MULTIPLY(tmp0 - tmp1, FIX(0.881747734)); /* c4 */
  3003. dataptr[4] = (DCTELEM)
  3004. DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.707106781)), /* c2+c6-c4 */
  3005. CONST_BITS-PASS1_BITS);
  3006. dataptr[6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS-PASS1_BITS);
  3007. /* Odd part */
  3008. tmp1 = MULTIPLY(tmp10 + tmp11, FIX(0.935414347)); /* (c3+c1-c5)/2 */
  3009. tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.170262339)); /* (c3+c5-c1)/2 */
  3010. tmp0 = tmp1 - tmp2;
  3011. tmp1 += tmp2;
  3012. tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.378756276)); /* -c1 */
  3013. tmp1 += tmp2;
  3014. tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.613604268)); /* c5 */
  3015. tmp0 += tmp3;
  3016. tmp2 += tmp3 + MULTIPLY(tmp12, FIX(1.870828693)); /* c3+c1-c5 */
  3017. dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);
  3018. dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);
  3019. dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);
  3020. ctr++;
  3021. if (ctr != DCTSIZE) {
  3022. if (ctr == 14)
  3023. break; /* Done. */
  3024. dataptr += DCTSIZE; /* advance pointer to next row */
  3025. } else
  3026. dataptr = workspace; /* switch pointer to extended workspace */
  3027. }
  3028. /* Pass 2: process columns.
  3029. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3030. * by an overall factor of 8.
  3031. * We must also scale the output by (8/7)*(8/14) = 32/49, which we
  3032. * fold into the constant multipliers:
  3033. * 14-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/28) * 32/49.
  3034. */
  3035. dataptr = data;
  3036. wsptr = workspace;
  3037. for (ctr = 0; ctr < 7; ctr++) {
  3038. /* Even part */
  3039. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*5];
  3040. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*4];
  3041. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*3];
  3042. tmp13 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*2];
  3043. tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*1];
  3044. tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*0];
  3045. tmp6 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];
  3046. tmp10 = tmp0 + tmp6;
  3047. tmp14 = tmp0 - tmp6;
  3048. tmp11 = tmp1 + tmp5;
  3049. tmp15 = tmp1 - tmp5;
  3050. tmp12 = tmp2 + tmp4;
  3051. tmp16 = tmp2 - tmp4;
  3052. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*5];
  3053. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*4];
  3054. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*3];
  3055. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*2];
  3056. tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*1];
  3057. tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*0];
  3058. tmp6 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];
  3059. dataptr[DCTSIZE*0] = (DCTELEM)
  3060. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12 + tmp13,
  3061. FIX(0.653061224)), /* 32/49 */
  3062. CONST_BITS+PASS1_BITS);
  3063. tmp13 += tmp13;
  3064. dataptr[DCTSIZE*4] = (DCTELEM)
  3065. DESCALE(MULTIPLY(tmp10 - tmp13, FIX(0.832106052)) + /* c4 */
  3066. MULTIPLY(tmp11 - tmp13, FIX(0.205513223)) - /* c12 */
  3067. MULTIPLY(tmp12 - tmp13, FIX(0.575835255)), /* c8 */
  3068. CONST_BITS+PASS1_BITS);
  3069. tmp10 = MULTIPLY(tmp14 + tmp15, FIX(0.722074570)); /* c6 */
  3070. dataptr[DCTSIZE*2] = (DCTELEM)
  3071. DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.178337691)) /* c2-c6 */
  3072. + MULTIPLY(tmp16, FIX(0.400721155)), /* c10 */
  3073. CONST_BITS+PASS1_BITS);
  3074. dataptr[DCTSIZE*6] = (DCTELEM)
  3075. DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.122795725)) /* c6+c10 */
  3076. - MULTIPLY(tmp16, FIX(0.900412262)), /* c2 */
  3077. CONST_BITS+PASS1_BITS);
  3078. /* Odd part */
  3079. tmp10 = tmp1 + tmp2;
  3080. tmp11 = tmp5 - tmp4;
  3081. dataptr[DCTSIZE*7] = (DCTELEM)
  3082. DESCALE(MULTIPLY(tmp0 - tmp10 + tmp3 - tmp11 - tmp6,
  3083. FIX(0.653061224)), /* 32/49 */
  3084. CONST_BITS+PASS1_BITS);
  3085. tmp3 = MULTIPLY(tmp3 , FIX(0.653061224)); /* 32/49 */
  3086. tmp10 = MULTIPLY(tmp10, - FIX(0.103406812)); /* -c13 */
  3087. tmp11 = MULTIPLY(tmp11, FIX(0.917760839)); /* c1 */
  3088. tmp10 += tmp11 - tmp3;
  3089. tmp11 = MULTIPLY(tmp0 + tmp2, FIX(0.782007410)) + /* c5 */
  3090. MULTIPLY(tmp4 + tmp6, FIX(0.491367823)); /* c9 */
  3091. dataptr[DCTSIZE*5] = (DCTELEM)
  3092. DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(1.550341076)) /* c3+c5-c13 */
  3093. + MULTIPLY(tmp4, FIX(0.731428202)), /* c1+c11-c9 */
  3094. CONST_BITS+PASS1_BITS);
  3095. tmp12 = MULTIPLY(tmp0 + tmp1, FIX(0.871740478)) + /* c3 */
  3096. MULTIPLY(tmp5 - tmp6, FIX(0.305035186)); /* c11 */
  3097. dataptr[DCTSIZE*3] = (DCTELEM)
  3098. DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.276965844)) /* c3-c9-c13 */
  3099. - MULTIPLY(tmp5, FIX(2.004803435)), /* c1+c5+c11 */
  3100. CONST_BITS+PASS1_BITS);
  3101. dataptr[DCTSIZE*1] = (DCTELEM)
  3102. DESCALE(tmp11 + tmp12 + tmp3
  3103. - MULTIPLY(tmp0, FIX(0.735987049)) /* c3+c5-c1 */
  3104. - MULTIPLY(tmp6, FIX(0.082925825)), /* c9-c11-c13 */
  3105. CONST_BITS+PASS1_BITS);
  3106. dataptr++; /* advance pointer to next column */
  3107. wsptr++; /* advance pointer to next column */
  3108. }
  3109. }
  3110. /*
  3111. * Perform the forward DCT on a 6x12 sample block.
  3112. *
  3113. * 6-point FDCT in pass 1 (rows), 12-point in pass 2 (columns).
  3114. */
  3115. GLOBAL(void)
  3116. jpeg_fdct_6x12 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3117. {
  3118. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  3119. INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  3120. DCTELEM workspace[8*4];
  3121. DCTELEM *dataptr;
  3122. DCTELEM *wsptr;
  3123. JSAMPROW elemptr;
  3124. int ctr;
  3125. SHIFT_TEMPS
  3126. /* Pre-zero output coefficient block. */
  3127. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3128. /* Pass 1: process rows.
  3129. * Note results are scaled up by sqrt(8) compared to a true DCT;
  3130. * furthermore, we scale the results by 2**PASS1_BITS.
  3131. * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12).
  3132. */
  3133. dataptr = data;
  3134. ctr = 0;
  3135. for (;;) {
  3136. elemptr = sample_data[ctr] + start_col;
  3137. /* Even part */
  3138. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);
  3139. tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);
  3140. tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);
  3141. tmp10 = tmp0 + tmp2;
  3142. tmp12 = tmp0 - tmp2;
  3143. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);
  3144. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);
  3145. tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);
  3146. /* Apply unsigned->signed conversion */
  3147. dataptr[0] = (DCTELEM)
  3148. ((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << PASS1_BITS);
  3149. dataptr[2] = (DCTELEM)
  3150. DESCALE(MULTIPLY(tmp12, FIX(1.224744871)), /* c2 */
  3151. CONST_BITS-PASS1_BITS);
  3152. dataptr[4] = (DCTELEM)
  3153. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */
  3154. CONST_BITS-PASS1_BITS);
  3155. /* Odd part */
  3156. tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)), /* c5 */
  3157. CONST_BITS-PASS1_BITS);
  3158. dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << PASS1_BITS));
  3159. dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << PASS1_BITS);
  3160. dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << PASS1_BITS));
  3161. ctr++;
  3162. if (ctr != DCTSIZE) {
  3163. if (ctr == 12)
  3164. break; /* Done. */
  3165. dataptr += DCTSIZE; /* advance pointer to next row */
  3166. } else
  3167. dataptr = workspace; /* switch pointer to extended workspace */
  3168. }
  3169. /* Pass 2: process columns.
  3170. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3171. * by an overall factor of 8.
  3172. * We must also scale the output by (8/6)*(8/12) = 8/9, which we
  3173. * fold into the constant multipliers:
  3174. * 12-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/24) * 8/9.
  3175. */
  3176. dataptr = data;
  3177. wsptr = workspace;
  3178. for (ctr = 0; ctr < 6; ctr++) {
  3179. /* Even part */
  3180. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*3];
  3181. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*2];
  3182. tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*1];
  3183. tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*0];
  3184. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*7];
  3185. tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*6];
  3186. tmp10 = tmp0 + tmp5;
  3187. tmp13 = tmp0 - tmp5;
  3188. tmp11 = tmp1 + tmp4;
  3189. tmp14 = tmp1 - tmp4;
  3190. tmp12 = tmp2 + tmp3;
  3191. tmp15 = tmp2 - tmp3;
  3192. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*3];
  3193. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*2];
  3194. tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*1];
  3195. tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*0];
  3196. tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*7];
  3197. tmp5 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*6];
  3198. dataptr[DCTSIZE*0] = (DCTELEM)
  3199. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(0.888888889)), /* 8/9 */
  3200. CONST_BITS+PASS1_BITS);
  3201. dataptr[DCTSIZE*6] = (DCTELEM)
  3202. DESCALE(MULTIPLY(tmp13 - tmp14 - tmp15, FIX(0.888888889)), /* 8/9 */
  3203. CONST_BITS+PASS1_BITS);
  3204. dataptr[DCTSIZE*4] = (DCTELEM)
  3205. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.088662108)), /* c4 */
  3206. CONST_BITS+PASS1_BITS);
  3207. dataptr[DCTSIZE*2] = (DCTELEM)
  3208. DESCALE(MULTIPLY(tmp14 - tmp15, FIX(0.888888889)) + /* 8/9 */
  3209. MULTIPLY(tmp13 + tmp15, FIX(1.214244803)), /* c2 */
  3210. CONST_BITS+PASS1_BITS);
  3211. /* Odd part */
  3212. tmp10 = MULTIPLY(tmp1 + tmp4, FIX(0.481063200)); /* c9 */
  3213. tmp14 = tmp10 + MULTIPLY(tmp1, FIX(0.680326102)); /* c3-c9 */
  3214. tmp15 = tmp10 - MULTIPLY(tmp4, FIX(1.642452502)); /* c3+c9 */
  3215. tmp12 = MULTIPLY(tmp0 + tmp2, FIX(0.997307603)); /* c5 */
  3216. tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.765261039)); /* c7 */
  3217. tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.516244403)) /* c5+c7-c1 */
  3218. + MULTIPLY(tmp5, FIX(0.164081699)); /* c11 */
  3219. tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.164081699)); /* -c11 */
  3220. tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.079550144)) /* c1+c5-c11 */
  3221. + MULTIPLY(tmp5, FIX(0.765261039)); /* c7 */
  3222. tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.645144899)) /* c1+c11-c7 */
  3223. - MULTIPLY(tmp5, FIX(0.997307603)); /* c5 */
  3224. tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.161389302)) /* c3 */
  3225. - MULTIPLY(tmp2 + tmp5, FIX(0.481063200)); /* c9 */
  3226. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS);
  3227. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS);
  3228. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS);
  3229. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS);
  3230. dataptr++; /* advance pointer to next column */
  3231. wsptr++; /* advance pointer to next column */
  3232. }
  3233. }
  3234. /*
  3235. * Perform the forward DCT on a 5x10 sample block.
  3236. *
  3237. * 5-point FDCT in pass 1 (rows), 10-point in pass 2 (columns).
  3238. */
  3239. GLOBAL(void)
  3240. jpeg_fdct_5x10 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3241. {
  3242. INT32 tmp0, tmp1, tmp2, tmp3, tmp4;
  3243. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  3244. DCTELEM workspace[8*2];
  3245. DCTELEM *dataptr;
  3246. DCTELEM *wsptr;
  3247. JSAMPROW elemptr;
  3248. int ctr;
  3249. SHIFT_TEMPS
  3250. /* Pre-zero output coefficient block. */
  3251. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3252. /* Pass 1: process rows.
  3253. * Note results are scaled up by sqrt(8) compared to a true DCT;
  3254. * furthermore, we scale the results by 2**PASS1_BITS.
  3255. * 5-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/10).
  3256. */
  3257. dataptr = data;
  3258. ctr = 0;
  3259. for (;;) {
  3260. elemptr = sample_data[ctr] + start_col;
  3261. /* Even part */
  3262. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[4]);
  3263. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[3]);
  3264. tmp2 = GETJSAMPLE(elemptr[2]);
  3265. tmp10 = tmp0 + tmp1;
  3266. tmp11 = tmp0 - tmp1;
  3267. tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[4]);
  3268. tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[3]);
  3269. /* Apply unsigned->signed conversion */
  3270. dataptr[0] = (DCTELEM)
  3271. ((tmp10 + tmp2 - 5 * CENTERJSAMPLE) << PASS1_BITS);
  3272. tmp11 = MULTIPLY(tmp11, FIX(0.790569415)); /* (c2+c4)/2 */
  3273. tmp10 -= tmp2 << 2;
  3274. tmp10 = MULTIPLY(tmp10, FIX(0.353553391)); /* (c2-c4)/2 */
  3275. dataptr[2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS-PASS1_BITS);
  3276. dataptr[4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS-PASS1_BITS);
  3277. /* Odd part */
  3278. tmp10 = MULTIPLY(tmp0 + tmp1, FIX(0.831253876)); /* c3 */
  3279. dataptr[1] = (DCTELEM)
  3280. DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.513743148)), /* c1-c3 */
  3281. CONST_BITS-PASS1_BITS);
  3282. dataptr[3] = (DCTELEM)
  3283. DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.176250899)), /* c1+c3 */
  3284. CONST_BITS-PASS1_BITS);
  3285. ctr++;
  3286. if (ctr != DCTSIZE) {
  3287. if (ctr == 10)
  3288. break; /* Done. */
  3289. dataptr += DCTSIZE; /* advance pointer to next row */
  3290. } else
  3291. dataptr = workspace; /* switch pointer to extended workspace */
  3292. }
  3293. /* Pass 2: process columns.
  3294. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3295. * by an overall factor of 8.
  3296. * We must also scale the output by (8/5)*(8/10) = 32/25, which we
  3297. * fold into the constant multipliers:
  3298. * 10-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/20) * 32/25.
  3299. */
  3300. dataptr = data;
  3301. wsptr = workspace;
  3302. for (ctr = 0; ctr < 5; ctr++) {
  3303. /* Even part */
  3304. tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*1];
  3305. tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*0];
  3306. tmp12 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*7];
  3307. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*6];
  3308. tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];
  3309. tmp10 = tmp0 + tmp4;
  3310. tmp13 = tmp0 - tmp4;
  3311. tmp11 = tmp1 + tmp3;
  3312. tmp14 = tmp1 - tmp3;
  3313. tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*1];
  3314. tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*0];
  3315. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*7];
  3316. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*6];
  3317. tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];
  3318. dataptr[DCTSIZE*0] = (DCTELEM)
  3319. DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(1.28)), /* 32/25 */
  3320. CONST_BITS+PASS1_BITS);
  3321. tmp12 += tmp12;
  3322. dataptr[DCTSIZE*4] = (DCTELEM)
  3323. DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.464477191)) - /* c4 */
  3324. MULTIPLY(tmp11 - tmp12, FIX(0.559380511)), /* c8 */
  3325. CONST_BITS+PASS1_BITS);
  3326. tmp10 = MULTIPLY(tmp13 + tmp14, FIX(1.064004961)); /* c6 */
  3327. dataptr[DCTSIZE*2] = (DCTELEM)
  3328. DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.657591230)), /* c2-c6 */
  3329. CONST_BITS+PASS1_BITS);
  3330. dataptr[DCTSIZE*6] = (DCTELEM)
  3331. DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.785601151)), /* c2+c6 */
  3332. CONST_BITS+PASS1_BITS);
  3333. /* Odd part */
  3334. tmp10 = tmp0 + tmp4;
  3335. tmp11 = tmp1 - tmp3;
  3336. dataptr[DCTSIZE*5] = (DCTELEM)
  3337. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp2, FIX(1.28)), /* 32/25 */
  3338. CONST_BITS+PASS1_BITS);
  3339. tmp2 = MULTIPLY(tmp2, FIX(1.28)); /* 32/25 */
  3340. dataptr[DCTSIZE*1] = (DCTELEM)
  3341. DESCALE(MULTIPLY(tmp0, FIX(1.787906876)) + /* c1 */
  3342. MULTIPLY(tmp1, FIX(1.612894094)) + tmp2 + /* c3 */
  3343. MULTIPLY(tmp3, FIX(0.821810588)) + /* c7 */
  3344. MULTIPLY(tmp4, FIX(0.283176630)), /* c9 */
  3345. CONST_BITS+PASS1_BITS);
  3346. tmp12 = MULTIPLY(tmp0 - tmp4, FIX(1.217352341)) - /* (c3+c7)/2 */
  3347. MULTIPLY(tmp1 + tmp3, FIX(0.752365123)); /* (c1-c9)/2 */
  3348. tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.395541753)) + /* (c3-c7)/2 */
  3349. MULTIPLY(tmp11, FIX(0.64)) - tmp2; /* 16/25 */
  3350. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS+PASS1_BITS);
  3351. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS+PASS1_BITS);
  3352. dataptr++; /* advance pointer to next column */
  3353. wsptr++; /* advance pointer to next column */
  3354. }
  3355. }
  3356. /*
  3357. * Perform the forward DCT on a 4x8 sample block.
  3358. *
  3359. * 4-point FDCT in pass 1 (rows), 8-point in pass 2 (columns).
  3360. */
  3361. GLOBAL(void)
  3362. jpeg_fdct_4x8 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3363. {
  3364. INT32 tmp0, tmp1, tmp2, tmp3;
  3365. INT32 tmp10, tmp11, tmp12, tmp13;
  3366. INT32 z1;
  3367. DCTELEM *dataptr;
  3368. JSAMPROW elemptr;
  3369. int ctr;
  3370. SHIFT_TEMPS
  3371. /* Pre-zero output coefficient block. */
  3372. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3373. /* Pass 1: process rows.
  3374. * Note results are scaled up by sqrt(8) compared to a true DCT;
  3375. * furthermore, we scale the results by 2**PASS1_BITS.
  3376. * We must also scale the output by 8/4 = 2, which we add here.
  3377. * 4-point FDCT kernel,
  3378. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  3379. */
  3380. dataptr = data;
  3381. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  3382. elemptr = sample_data[ctr] + start_col;
  3383. /* Even part */
  3384. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);
  3385. tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);
  3386. tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);
  3387. tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
  3388. /* Apply unsigned->signed conversion */
  3389. dataptr[0] = (DCTELEM)
  3390. ((tmp0 + tmp1 - 4 * CENTERJSAMPLE) << (PASS1_BITS+1));
  3391. dataptr[2] = (DCTELEM) ((tmp0 - tmp1) << (PASS1_BITS+1));
  3392. /* Odd part */
  3393. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  3394. /* Add fudge factor here for final descale. */
  3395. tmp0 += ONE << (CONST_BITS-PASS1_BITS-2);
  3396. dataptr[1] = (DCTELEM)
  3397. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  3398. CONST_BITS-PASS1_BITS-1);
  3399. dataptr[3] = (DCTELEM)
  3400. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  3401. CONST_BITS-PASS1_BITS-1);
  3402. dataptr += DCTSIZE; /* advance pointer to next row */
  3403. }
  3404. /* Pass 2: process columns.
  3405. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3406. * by an overall factor of 8.
  3407. * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
  3408. */
  3409. dataptr = data;
  3410. for (ctr = 0; ctr < 4; ctr++) {
  3411. /* Even part per LL&M figure 1 --- note that published figure is faulty;
  3412. * rotator "c1" should be "c6".
  3413. */
  3414. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  3415. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  3416. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  3417. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  3418. /* Add fudge factor here for final descale. */
  3419. tmp10 = tmp0 + tmp3 + (ONE << (PASS1_BITS-1));
  3420. tmp12 = tmp0 - tmp3;
  3421. tmp11 = tmp1 + tmp2;
  3422. tmp13 = tmp1 - tmp2;
  3423. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  3424. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  3425. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  3426. tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  3427. dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp10 + tmp11, PASS1_BITS);
  3428. dataptr[DCTSIZE*4] = (DCTELEM) RIGHT_SHIFT(tmp10 - tmp11, PASS1_BITS);
  3429. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); /* c6 */
  3430. /* Add fudge factor here for final descale. */
  3431. z1 += ONE << (CONST_BITS+PASS1_BITS-1);
  3432. dataptr[DCTSIZE*2] = (DCTELEM)
  3433. RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */
  3434. CONST_BITS+PASS1_BITS);
  3435. dataptr[DCTSIZE*6] = (DCTELEM)
  3436. RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */
  3437. CONST_BITS+PASS1_BITS);
  3438. /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  3439. * i0..i3 in the paper are tmp0..tmp3 here.
  3440. */
  3441. tmp12 = tmp0 + tmp2;
  3442. tmp13 = tmp1 + tmp3;
  3443. z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602); /* c3 */
  3444. /* Add fudge factor here for final descale. */
  3445. z1 += ONE << (CONST_BITS+PASS1_BITS-1);
  3446. tmp12 = MULTIPLY(tmp12, - FIX_0_390180644); /* -c3+c5 */
  3447. tmp13 = MULTIPLY(tmp13, - FIX_1_961570560); /* -c3-c5 */
  3448. tmp12 += z1;
  3449. tmp13 += z1;
  3450. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
  3451. tmp0 = MULTIPLY(tmp0, FIX_1_501321110); /* c1+c3-c5-c7 */
  3452. tmp3 = MULTIPLY(tmp3, FIX_0_298631336); /* -c1+c3+c5-c7 */
  3453. tmp0 += z1 + tmp12;
  3454. tmp3 += z1 + tmp13;
  3455. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
  3456. tmp1 = MULTIPLY(tmp1, FIX_3_072711026); /* c1+c3+c5-c7 */
  3457. tmp2 = MULTIPLY(tmp2, FIX_2_053119869); /* c1+c3-c5+c7 */
  3458. tmp1 += z1 + tmp13;
  3459. tmp2 += z1 + tmp12;
  3460. dataptr[DCTSIZE*1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS+PASS1_BITS);
  3461. dataptr[DCTSIZE*3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS+PASS1_BITS);
  3462. dataptr[DCTSIZE*5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS+PASS1_BITS);
  3463. dataptr[DCTSIZE*7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS+PASS1_BITS);
  3464. dataptr++; /* advance pointer to next column */
  3465. }
  3466. }
  3467. /*
  3468. * Perform the forward DCT on a 3x6 sample block.
  3469. *
  3470. * 3-point FDCT in pass 1 (rows), 6-point in pass 2 (columns).
  3471. */
  3472. GLOBAL(void)
  3473. jpeg_fdct_3x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3474. {
  3475. INT32 tmp0, tmp1, tmp2;
  3476. INT32 tmp10, tmp11, tmp12;
  3477. DCTELEM *dataptr;
  3478. JSAMPROW elemptr;
  3479. int ctr;
  3480. SHIFT_TEMPS
  3481. /* Pre-zero output coefficient block. */
  3482. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3483. /* Pass 1: process rows.
  3484. * Note results are scaled up by sqrt(8) compared to a true DCT;
  3485. * furthermore, we scale the results by 2**PASS1_BITS.
  3486. * We scale the results further by 2 as part of output adaption
  3487. * scaling for different DCT size.
  3488. * 3-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/6).
  3489. */
  3490. dataptr = data;
  3491. for (ctr = 0; ctr < 6; ctr++) {
  3492. elemptr = sample_data[ctr] + start_col;
  3493. /* Even part */
  3494. tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[2]);
  3495. tmp1 = GETJSAMPLE(elemptr[1]);
  3496. tmp2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[2]);
  3497. /* Apply unsigned->signed conversion */
  3498. dataptr[0] = (DCTELEM)
  3499. ((tmp0 + tmp1 - 3 * CENTERJSAMPLE) << (PASS1_BITS+1));
  3500. dataptr[2] = (DCTELEM)
  3501. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(0.707106781)), /* c2 */
  3502. CONST_BITS-PASS1_BITS-1);
  3503. /* Odd part */
  3504. dataptr[1] = (DCTELEM)
  3505. DESCALE(MULTIPLY(tmp2, FIX(1.224744871)), /* c1 */
  3506. CONST_BITS-PASS1_BITS-1);
  3507. dataptr += DCTSIZE; /* advance pointer to next row */
  3508. }
  3509. /* Pass 2: process columns.
  3510. * We remove the PASS1_BITS scaling, but leave the results scaled up
  3511. * by an overall factor of 8.
  3512. * We must also scale the output by (8/6)*(8/3) = 32/9, which we partially
  3513. * fold into the constant multipliers (other part was done in pass 1):
  3514. * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12) * 16/9.
  3515. */
  3516. dataptr = data;
  3517. for (ctr = 0; ctr < 3; ctr++) {
  3518. /* Even part */
  3519. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];
  3520. tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];
  3521. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
  3522. tmp10 = tmp0 + tmp2;
  3523. tmp12 = tmp0 - tmp2;
  3524. tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];
  3525. tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];
  3526. tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
  3527. dataptr[DCTSIZE*0] = (DCTELEM)
  3528. DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)), /* 16/9 */
  3529. CONST_BITS+PASS1_BITS);
  3530. dataptr[DCTSIZE*2] = (DCTELEM)
  3531. DESCALE(MULTIPLY(tmp12, FIX(2.177324216)), /* c2 */
  3532. CONST_BITS+PASS1_BITS);
  3533. dataptr[DCTSIZE*4] = (DCTELEM)
  3534. DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */
  3535. CONST_BITS+PASS1_BITS);
  3536. /* Odd part */
  3537. tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829)); /* c5 */
  3538. dataptr[DCTSIZE*1] = (DCTELEM)
  3539. DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
  3540. CONST_BITS+PASS1_BITS);
  3541. dataptr[DCTSIZE*3] = (DCTELEM)
  3542. DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)), /* 16/9 */
  3543. CONST_BITS+PASS1_BITS);
  3544. dataptr[DCTSIZE*5] = (DCTELEM)
  3545. DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)), /* 16/9 */
  3546. CONST_BITS+PASS1_BITS);
  3547. dataptr++; /* advance pointer to next column */
  3548. }
  3549. }
  3550. /*
  3551. * Perform the forward DCT on a 2x4 sample block.
  3552. *
  3553. * 2-point FDCT in pass 1 (rows), 4-point in pass 2 (columns).
  3554. */
  3555. GLOBAL(void)
  3556. jpeg_fdct_2x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3557. {
  3558. INT32 tmp0, tmp1;
  3559. INT32 tmp10, tmp11;
  3560. DCTELEM *dataptr;
  3561. JSAMPROW elemptr;
  3562. int ctr;
  3563. SHIFT_TEMPS
  3564. /* Pre-zero output coefficient block. */
  3565. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3566. /* Pass 1: process rows.
  3567. * Note results are scaled up by sqrt(8) compared to a true DCT.
  3568. * We must also scale the output by (8/2)*(8/4) = 2**3, which we add here.
  3569. */
  3570. dataptr = data;
  3571. for (ctr = 0; ctr < 4; ctr++) {
  3572. elemptr = sample_data[ctr] + start_col;
  3573. /* Even part */
  3574. tmp0 = GETJSAMPLE(elemptr[0]);
  3575. tmp1 = GETJSAMPLE(elemptr[1]);
  3576. /* Apply unsigned->signed conversion */
  3577. dataptr[0] = (DCTELEM) ((tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 3);
  3578. /* Odd part */
  3579. dataptr[1] = (DCTELEM) ((tmp0 - tmp1) << 3);
  3580. dataptr += DCTSIZE; /* advance pointer to next row */
  3581. }
  3582. /* Pass 2: process columns.
  3583. * We leave the results scaled up by an overall factor of 8.
  3584. * 4-point FDCT kernel,
  3585. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
  3586. */
  3587. dataptr = data;
  3588. for (ctr = 0; ctr < 2; ctr++) {
  3589. /* Even part */
  3590. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*3];
  3591. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*2];
  3592. tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];
  3593. tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];
  3594. dataptr[DCTSIZE*0] = (DCTELEM) (tmp0 + tmp1);
  3595. dataptr[DCTSIZE*2] = (DCTELEM) (tmp0 - tmp1);
  3596. /* Odd part */
  3597. tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
  3598. /* Add fudge factor here for final descale. */
  3599. tmp0 += ONE << (CONST_BITS-1);
  3600. dataptr[DCTSIZE*1] = (DCTELEM)
  3601. RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
  3602. CONST_BITS);
  3603. dataptr[DCTSIZE*3] = (DCTELEM)
  3604. RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
  3605. CONST_BITS);
  3606. dataptr++; /* advance pointer to next column */
  3607. }
  3608. }
  3609. /*
  3610. * Perform the forward DCT on a 1x2 sample block.
  3611. *
  3612. * 1-point FDCT in pass 1 (rows), 2-point in pass 2 (columns).
  3613. */
  3614. GLOBAL(void)
  3615. jpeg_fdct_1x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
  3616. {
  3617. INT32 tmp0, tmp1;
  3618. /* Pre-zero output coefficient block. */
  3619. MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
  3620. /* Pass 1: empty. */
  3621. /* Pass 2: process columns.
  3622. * We leave the results scaled up by an overall factor of 8.
  3623. * We must also scale the output by (8/1)*(8/2) = 2**5.
  3624. */
  3625. /* Even part */
  3626. tmp0 = GETJSAMPLE(sample_data[0][start_col]);
  3627. tmp1 = GETJSAMPLE(sample_data[1][start_col]);
  3628. /* Apply unsigned->signed conversion */
  3629. data[DCTSIZE*0] = (DCTELEM) ((tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 5);
  3630. /* Odd part */
  3631. data[DCTSIZE*1] = (DCTELEM) ((tmp0 - tmp1) << 5);
  3632. }
  3633. #endif /* DCT_SCALING_SUPPORTED */
  3634. #endif /* DCT_ISLOW_SUPPORTED */