jidctint.c 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627
  1. /*
  2. * jidctint.c
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1991-1998, Thomas G. Lane.
  6. * Modification developed 2002-2018 by Guido Vollbeding.
  7. * libjpeg-turbo Modifications:
  8. * Copyright (C) 2015, 2020, D. R. Commander.
  9. * For conditions of distribution and use, see the accompanying README.ijg
  10. * file.
  11. *
  12. * This file contains a slower but more accurate integer implementation of the
  13. * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
  14. * must also perform dequantization of the input coefficients.
  15. *
  16. * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
  17. * on each row (or vice versa, but it's more convenient to emit a row at
  18. * a time). Direct algorithms are also available, but they are much more
  19. * complex and seem not to be any faster when reduced to code.
  20. *
  21. * This implementation is based on an algorithm described in
  22. * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
  23. * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
  24. * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
  25. * The primary algorithm described there uses 11 multiplies and 29 adds.
  26. * We use their alternate method with 12 multiplies and 32 adds.
  27. * The advantage of this method is that no data path contains more than one
  28. * multiplication; this allows a very simple and accurate implementation in
  29. * scaled fixed-point arithmetic, with a minimal number of shifts.
  30. *
  31. * We also provide IDCT routines with various output sample block sizes for
  32. * direct resolution reduction or enlargement without additional resampling:
  33. * NxN (N=1...16) pixels for one 8x8 input DCT block.
  34. *
  35. * For N<8 we simply take the corresponding low-frequency coefficients of
  36. * the 8x8 input DCT block and apply an NxN point IDCT on the sub-block
  37. * to yield the downscaled outputs.
  38. * This can be seen as direct low-pass downsampling from the DCT domain
  39. * point of view rather than the usual spatial domain point of view,
  40. * yielding significant computational savings and results at least
  41. * as good as common bilinear (averaging) spatial downsampling.
  42. *
  43. * For N>8 we apply a partial NxN IDCT on the 8 input coefficients as
  44. * lower frequencies and higher frequencies assumed to be zero.
  45. * It turns out that the computational effort is similar to the 8x8 IDCT
  46. * regarding the output size.
  47. * Furthermore, the scaling and descaling is the same for all IDCT sizes.
  48. *
  49. * CAUTION: We rely on the FIX() macro except for the N=1,2,4,8 cases
  50. * since there would be too many additional constants to pre-calculate.
  51. */
  52. #define JPEG_INTERNALS
  53. #include "jinclude.h"
  54. #include "jpeglib.h"
  55. #include "jdct.h" /* Private declarations for DCT subsystem */
  56. #ifdef DCT_ISLOW_SUPPORTED
  57. /*
  58. * This module is specialized to the case DCTSIZE = 8.
  59. */
  60. #if DCTSIZE != 8
  61. Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
  62. #endif
  63. /*
  64. * The poop on this scaling stuff is as follows:
  65. *
  66. * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
  67. * larger than the true IDCT outputs. The final outputs are therefore
  68. * a factor of N larger than desired; since N=8 this can be cured by
  69. * a simple right shift at the end of the algorithm. The advantage of
  70. * this arrangement is that we save two multiplications per 1-D IDCT,
  71. * because the y0 and y4 inputs need not be divided by sqrt(N).
  72. *
  73. * We have to do addition and subtraction of the integer inputs, which
  74. * is no problem, and multiplication by fractional constants, which is
  75. * a problem to do in integer arithmetic. We multiply all the constants
  76. * by CONST_SCALE and convert them to integer constants (thus retaining
  77. * CONST_BITS bits of precision in the constants). After doing a
  78. * multiplication we have to divide the product by CONST_SCALE, with proper
  79. * rounding, to produce the correct output. This division can be done
  80. * cheaply as a right shift of CONST_BITS bits. We postpone shifting
  81. * as long as possible so that partial sums can be added together with
  82. * full fractional precision.
  83. *
  84. * The outputs of the first pass are scaled up by PASS1_BITS bits so that
  85. * they are represented to better-than-integral precision. These outputs
  86. * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
  87. * with the recommended scaling. (To scale up 12-bit sample data further, an
  88. * intermediate JLONG array would be needed.)
  89. *
  90. * To avoid overflow of the 32-bit intermediate results in pass 2, we must
  91. * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
  92. * shows that the values given below are the most effective.
  93. */
  94. #if BITS_IN_JSAMPLE == 8
  95. #define CONST_BITS 13
  96. #define PASS1_BITS 2
  97. #else
  98. #define CONST_BITS 13
  99. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  100. #endif
  101. /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
  102. * causing a lot of useless floating-point operations at run time.
  103. * To get around this we use the following pre-calculated constants.
  104. * If you change CONST_BITS you may want to add appropriate values.
  105. * (With a reasonable C compiler, you can just rely on the FIX() macro...)
  106. */
  107. #if CONST_BITS == 13
  108. #define FIX_0_298631336 ((JLONG)2446) /* FIX(0.298631336) */
  109. #define FIX_0_390180644 ((JLONG)3196) /* FIX(0.390180644) */
  110. #define FIX_0_541196100 ((JLONG)4433) /* FIX(0.541196100) */
  111. #define FIX_0_765366865 ((JLONG)6270) /* FIX(0.765366865) */
  112. #define FIX_0_899976223 ((JLONG)7373) /* FIX(0.899976223) */
  113. #define FIX_1_175875602 ((JLONG)9633) /* FIX(1.175875602) */
  114. #define FIX_1_501321110 ((JLONG)12299) /* FIX(1.501321110) */
  115. #define FIX_1_847759065 ((JLONG)15137) /* FIX(1.847759065) */
  116. #define FIX_1_961570560 ((JLONG)16069) /* FIX(1.961570560) */
  117. #define FIX_2_053119869 ((JLONG)16819) /* FIX(2.053119869) */
  118. #define FIX_2_562915447 ((JLONG)20995) /* FIX(2.562915447) */
  119. #define FIX_3_072711026 ((JLONG)25172) /* FIX(3.072711026) */
  120. #else
  121. #define FIX_0_298631336 FIX(0.298631336)
  122. #define FIX_0_390180644 FIX(0.390180644)
  123. #define FIX_0_541196100 FIX(0.541196100)
  124. #define FIX_0_765366865 FIX(0.765366865)
  125. #define FIX_0_899976223 FIX(0.899976223)
  126. #define FIX_1_175875602 FIX(1.175875602)
  127. #define FIX_1_501321110 FIX(1.501321110)
  128. #define FIX_1_847759065 FIX(1.847759065)
  129. #define FIX_1_961570560 FIX(1.961570560)
  130. #define FIX_2_053119869 FIX(2.053119869)
  131. #define FIX_2_562915447 FIX(2.562915447)
  132. #define FIX_3_072711026 FIX(3.072711026)
  133. #endif
  134. /* Multiply an JLONG variable by an JLONG constant to yield an JLONG result.
  135. * For 8-bit samples with the recommended scaling, all the variable
  136. * and constant values involved are no more than 16 bits wide, so a
  137. * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
  138. * For 12-bit samples, a full 32-bit multiplication will be needed.
  139. */
  140. #if BITS_IN_JSAMPLE == 8
  141. #define MULTIPLY(var, const) MULTIPLY16C16(var, const)
  142. #else
  143. #define MULTIPLY(var, const) ((var) * (const))
  144. #endif
  145. /* Dequantize a coefficient by multiplying it by the multiplier-table
  146. * entry; produce an int result. In this module, both inputs and result
  147. * are 16 bits or less, so either int or short multiply will work.
  148. */
  149. #define DEQUANTIZE(coef, quantval) (((ISLOW_MULT_TYPE)(coef)) * (quantval))
  150. /*
  151. * Perform dequantization and inverse DCT on one block of coefficients.
  152. */
  153. GLOBAL(void)
  154. jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  155. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  156. JDIMENSION output_col)
  157. {
  158. JLONG tmp0, tmp1, tmp2, tmp3;
  159. JLONG tmp10, tmp11, tmp12, tmp13;
  160. JLONG z1, z2, z3, z4, z5;
  161. JCOEFPTR inptr;
  162. ISLOW_MULT_TYPE *quantptr;
  163. int *wsptr;
  164. JSAMPROW outptr;
  165. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  166. int ctr;
  167. int workspace[DCTSIZE2]; /* buffers data between passes */
  168. SHIFT_TEMPS
  169. /* Pass 1: process columns from input, store into work array. */
  170. /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
  171. /* furthermore, we scale the results by 2**PASS1_BITS. */
  172. inptr = coef_block;
  173. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  174. wsptr = workspace;
  175. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  176. /* Due to quantization, we will usually find that many of the input
  177. * coefficients are zero, especially the AC terms. We can exploit this
  178. * by short-circuiting the IDCT calculation for any column in which all
  179. * the AC terms are zero. In that case each output is equal to the
  180. * DC coefficient (with scale factor as needed).
  181. * With typical images and quantization tables, half or more of the
  182. * column DCT calculations can be simplified this way.
  183. */
  184. if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 2] == 0 &&
  185. inptr[DCTSIZE * 3] == 0 && inptr[DCTSIZE * 4] == 0 &&
  186. inptr[DCTSIZE * 5] == 0 && inptr[DCTSIZE * 6] == 0 &&
  187. inptr[DCTSIZE * 7] == 0) {
  188. /* AC terms all zero */
  189. int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE * 0],
  190. quantptr[DCTSIZE * 0]), PASS1_BITS);
  191. wsptr[DCTSIZE * 0] = dcval;
  192. wsptr[DCTSIZE * 1] = dcval;
  193. wsptr[DCTSIZE * 2] = dcval;
  194. wsptr[DCTSIZE * 3] = dcval;
  195. wsptr[DCTSIZE * 4] = dcval;
  196. wsptr[DCTSIZE * 5] = dcval;
  197. wsptr[DCTSIZE * 6] = dcval;
  198. wsptr[DCTSIZE * 7] = dcval;
  199. inptr++; /* advance pointers to next column */
  200. quantptr++;
  201. wsptr++;
  202. continue;
  203. }
  204. /* Even part: reverse the even part of the forward DCT. */
  205. /* The rotator is sqrt(2)*c(-6). */
  206. z2 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  207. z3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  208. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  209. tmp2 = z1 + MULTIPLY(z3, -FIX_1_847759065);
  210. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  211. z2 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  212. z3 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  213. tmp0 = LEFT_SHIFT(z2 + z3, CONST_BITS);
  214. tmp1 = LEFT_SHIFT(z2 - z3, CONST_BITS);
  215. tmp10 = tmp0 + tmp3;
  216. tmp13 = tmp0 - tmp3;
  217. tmp11 = tmp1 + tmp2;
  218. tmp12 = tmp1 - tmp2;
  219. /* Odd part per figure 8; the matrix is unitary and hence its
  220. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  221. */
  222. tmp0 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  223. tmp1 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  224. tmp2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  225. tmp3 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  226. z1 = tmp0 + tmp3;
  227. z2 = tmp1 + tmp2;
  228. z3 = tmp0 + tmp2;
  229. z4 = tmp1 + tmp3;
  230. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  231. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  232. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  233. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  234. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  235. z1 = MULTIPLY(z1, -FIX_0_899976223); /* sqrt(2) * ( c7-c3) */
  236. z2 = MULTIPLY(z2, -FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  237. z3 = MULTIPLY(z3, -FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  238. z4 = MULTIPLY(z4, -FIX_0_390180644); /* sqrt(2) * ( c5-c3) */
  239. z3 += z5;
  240. z4 += z5;
  241. tmp0 += z1 + z3;
  242. tmp1 += z2 + z4;
  243. tmp2 += z2 + z3;
  244. tmp3 += z1 + z4;
  245. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  246. wsptr[DCTSIZE * 0] = (int)DESCALE(tmp10 + tmp3, CONST_BITS - PASS1_BITS);
  247. wsptr[DCTSIZE * 7] = (int)DESCALE(tmp10 - tmp3, CONST_BITS - PASS1_BITS);
  248. wsptr[DCTSIZE * 1] = (int)DESCALE(tmp11 + tmp2, CONST_BITS - PASS1_BITS);
  249. wsptr[DCTSIZE * 6] = (int)DESCALE(tmp11 - tmp2, CONST_BITS - PASS1_BITS);
  250. wsptr[DCTSIZE * 2] = (int)DESCALE(tmp12 + tmp1, CONST_BITS - PASS1_BITS);
  251. wsptr[DCTSIZE * 5] = (int)DESCALE(tmp12 - tmp1, CONST_BITS - PASS1_BITS);
  252. wsptr[DCTSIZE * 3] = (int)DESCALE(tmp13 + tmp0, CONST_BITS - PASS1_BITS);
  253. wsptr[DCTSIZE * 4] = (int)DESCALE(tmp13 - tmp0, CONST_BITS - PASS1_BITS);
  254. inptr++; /* advance pointers to next column */
  255. quantptr++;
  256. wsptr++;
  257. }
  258. /* Pass 2: process rows from work array, store into output array. */
  259. /* Note that we must descale the results by a factor of 8 == 2**3, */
  260. /* and also undo the PASS1_BITS scaling. */
  261. wsptr = workspace;
  262. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  263. outptr = output_buf[ctr] + output_col;
  264. /* Rows of zeroes can be exploited in the same way as we did with columns.
  265. * However, the column calculation has created many nonzero AC terms, so
  266. * the simplification applies less often (typically 5% to 10% of the time).
  267. * On machines with very fast multiplication, it's possible that the
  268. * test takes more time than it's worth. In that case this section
  269. * may be commented out.
  270. */
  271. #ifndef NO_ZERO_ROW_TEST
  272. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  273. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  274. /* AC terms all zero */
  275. JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
  276. PASS1_BITS + 3) & RANGE_MASK];
  277. outptr[0] = dcval;
  278. outptr[1] = dcval;
  279. outptr[2] = dcval;
  280. outptr[3] = dcval;
  281. outptr[4] = dcval;
  282. outptr[5] = dcval;
  283. outptr[6] = dcval;
  284. outptr[7] = dcval;
  285. wsptr += DCTSIZE; /* advance pointer to next row */
  286. continue;
  287. }
  288. #endif
  289. /* Even part: reverse the even part of the forward DCT. */
  290. /* The rotator is sqrt(2)*c(-6). */
  291. z2 = (JLONG)wsptr[2];
  292. z3 = (JLONG)wsptr[6];
  293. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  294. tmp2 = z1 + MULTIPLY(z3, -FIX_1_847759065);
  295. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  296. tmp0 = LEFT_SHIFT((JLONG)wsptr[0] + (JLONG)wsptr[4], CONST_BITS);
  297. tmp1 = LEFT_SHIFT((JLONG)wsptr[0] - (JLONG)wsptr[4], CONST_BITS);
  298. tmp10 = tmp0 + tmp3;
  299. tmp13 = tmp0 - tmp3;
  300. tmp11 = tmp1 + tmp2;
  301. tmp12 = tmp1 - tmp2;
  302. /* Odd part per figure 8; the matrix is unitary and hence its
  303. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  304. */
  305. tmp0 = (JLONG)wsptr[7];
  306. tmp1 = (JLONG)wsptr[5];
  307. tmp2 = (JLONG)wsptr[3];
  308. tmp3 = (JLONG)wsptr[1];
  309. z1 = tmp0 + tmp3;
  310. z2 = tmp1 + tmp2;
  311. z3 = tmp0 + tmp2;
  312. z4 = tmp1 + tmp3;
  313. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  314. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  315. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  316. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  317. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  318. z1 = MULTIPLY(z1, -FIX_0_899976223); /* sqrt(2) * ( c7-c3) */
  319. z2 = MULTIPLY(z2, -FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  320. z3 = MULTIPLY(z3, -FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  321. z4 = MULTIPLY(z4, -FIX_0_390180644); /* sqrt(2) * ( c5-c3) */
  322. z3 += z5;
  323. z4 += z5;
  324. tmp0 += z1 + z3;
  325. tmp1 += z2 + z4;
  326. tmp2 += z2 + z3;
  327. tmp3 += z1 + z4;
  328. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  329. outptr[0] = range_limit[(int)DESCALE(tmp10 + tmp3,
  330. CONST_BITS + PASS1_BITS + 3) &
  331. RANGE_MASK];
  332. outptr[7] = range_limit[(int)DESCALE(tmp10 - tmp3,
  333. CONST_BITS + PASS1_BITS + 3) &
  334. RANGE_MASK];
  335. outptr[1] = range_limit[(int)DESCALE(tmp11 + tmp2,
  336. CONST_BITS + PASS1_BITS + 3) &
  337. RANGE_MASK];
  338. outptr[6] = range_limit[(int)DESCALE(tmp11 - tmp2,
  339. CONST_BITS + PASS1_BITS + 3) &
  340. RANGE_MASK];
  341. outptr[2] = range_limit[(int)DESCALE(tmp12 + tmp1,
  342. CONST_BITS + PASS1_BITS + 3) &
  343. RANGE_MASK];
  344. outptr[5] = range_limit[(int)DESCALE(tmp12 - tmp1,
  345. CONST_BITS + PASS1_BITS + 3) &
  346. RANGE_MASK];
  347. outptr[3] = range_limit[(int)DESCALE(tmp13 + tmp0,
  348. CONST_BITS + PASS1_BITS + 3) &
  349. RANGE_MASK];
  350. outptr[4] = range_limit[(int)DESCALE(tmp13 - tmp0,
  351. CONST_BITS + PASS1_BITS + 3) &
  352. RANGE_MASK];
  353. wsptr += DCTSIZE; /* advance pointer to next row */
  354. }
  355. }
  356. #ifdef IDCT_SCALING_SUPPORTED
  357. /*
  358. * Perform dequantization and inverse DCT on one block of coefficients,
  359. * producing a reduced-size 7x7 output block.
  360. *
  361. * Optimized algorithm with 12 multiplications in the 1-D kernel.
  362. * cK represents sqrt(2) * cos(K*pi/14).
  363. */
  364. GLOBAL(void)
  365. jpeg_idct_7x7(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  366. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  367. JDIMENSION output_col)
  368. {
  369. JLONG tmp0, tmp1, tmp2, tmp10, tmp11, tmp12, tmp13;
  370. JLONG z1, z2, z3;
  371. JCOEFPTR inptr;
  372. ISLOW_MULT_TYPE *quantptr;
  373. int *wsptr;
  374. JSAMPROW outptr;
  375. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  376. int ctr;
  377. int workspace[7 * 7]; /* buffers data between passes */
  378. SHIFT_TEMPS
  379. /* Pass 1: process columns from input, store into work array. */
  380. inptr = coef_block;
  381. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  382. wsptr = workspace;
  383. for (ctr = 0; ctr < 7; ctr++, inptr++, quantptr++, wsptr++) {
  384. /* Even part */
  385. tmp13 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  386. tmp13 = LEFT_SHIFT(tmp13, CONST_BITS);
  387. /* Add fudge factor here for final descale. */
  388. tmp13 += ONE << (CONST_BITS - PASS1_BITS - 1);
  389. z1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  390. z2 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  391. z3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  392. tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734)); /* c4 */
  393. tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123)); /* c6 */
  394. tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */
  395. tmp0 = z1 + z3;
  396. z2 -= tmp0;
  397. tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */
  398. tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536)); /* c2-c4-c6 */
  399. tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249)); /* c2+c4+c6 */
  400. tmp13 += MULTIPLY(z2, FIX(1.414213562)); /* c0 */
  401. /* Odd part */
  402. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  403. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  404. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  405. tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347)); /* (c3+c1-c5)/2 */
  406. tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339)); /* (c3+c5-c1)/2 */
  407. tmp0 = tmp1 - tmp2;
  408. tmp1 += tmp2;
  409. tmp2 = MULTIPLY(z2 + z3, -FIX(1.378756276)); /* -c1 */
  410. tmp1 += tmp2;
  411. z2 = MULTIPLY(z1 + z3, FIX(0.613604268)); /* c5 */
  412. tmp0 += z2;
  413. tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693)); /* c3+c1-c5 */
  414. /* Final output stage */
  415. wsptr[7 * 0] = (int)RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS - PASS1_BITS);
  416. wsptr[7 * 6] = (int)RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS - PASS1_BITS);
  417. wsptr[7 * 1] = (int)RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS - PASS1_BITS);
  418. wsptr[7 * 5] = (int)RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS - PASS1_BITS);
  419. wsptr[7 * 2] = (int)RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS - PASS1_BITS);
  420. wsptr[7 * 4] = (int)RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS - PASS1_BITS);
  421. wsptr[7 * 3] = (int)RIGHT_SHIFT(tmp13, CONST_BITS - PASS1_BITS);
  422. }
  423. /* Pass 2: process 7 rows from work array, store into output array. */
  424. wsptr = workspace;
  425. for (ctr = 0; ctr < 7; ctr++) {
  426. outptr = output_buf[ctr] + output_col;
  427. /* Even part */
  428. /* Add fudge factor here for final descale. */
  429. tmp13 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  430. tmp13 = LEFT_SHIFT(tmp13, CONST_BITS);
  431. z1 = (JLONG)wsptr[2];
  432. z2 = (JLONG)wsptr[4];
  433. z3 = (JLONG)wsptr[6];
  434. tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734)); /* c4 */
  435. tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123)); /* c6 */
  436. tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */
  437. tmp0 = z1 + z3;
  438. z2 -= tmp0;
  439. tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */
  440. tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536)); /* c2-c4-c6 */
  441. tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249)); /* c2+c4+c6 */
  442. tmp13 += MULTIPLY(z2, FIX(1.414213562)); /* c0 */
  443. /* Odd part */
  444. z1 = (JLONG)wsptr[1];
  445. z2 = (JLONG)wsptr[3];
  446. z3 = (JLONG)wsptr[5];
  447. tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347)); /* (c3+c1-c5)/2 */
  448. tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339)); /* (c3+c5-c1)/2 */
  449. tmp0 = tmp1 - tmp2;
  450. tmp1 += tmp2;
  451. tmp2 = MULTIPLY(z2 + z3, -FIX(1.378756276)); /* -c1 */
  452. tmp1 += tmp2;
  453. z2 = MULTIPLY(z1 + z3, FIX(0.613604268)); /* c5 */
  454. tmp0 += z2;
  455. tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693)); /* c3+c1-c5 */
  456. /* Final output stage */
  457. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp10 + tmp0,
  458. CONST_BITS + PASS1_BITS + 3) &
  459. RANGE_MASK];
  460. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp10 - tmp0,
  461. CONST_BITS + PASS1_BITS + 3) &
  462. RANGE_MASK];
  463. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp11 + tmp1,
  464. CONST_BITS + PASS1_BITS + 3) &
  465. RANGE_MASK];
  466. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp11 - tmp1,
  467. CONST_BITS + PASS1_BITS + 3) &
  468. RANGE_MASK];
  469. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp12 + tmp2,
  470. CONST_BITS + PASS1_BITS + 3) &
  471. RANGE_MASK];
  472. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp12 - tmp2,
  473. CONST_BITS + PASS1_BITS + 3) &
  474. RANGE_MASK];
  475. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp13,
  476. CONST_BITS + PASS1_BITS + 3) &
  477. RANGE_MASK];
  478. wsptr += 7; /* advance pointer to next row */
  479. }
  480. }
  481. /*
  482. * Perform dequantization and inverse DCT on one block of coefficients,
  483. * producing a reduced-size 6x6 output block.
  484. *
  485. * Optimized algorithm with 3 multiplications in the 1-D kernel.
  486. * cK represents sqrt(2) * cos(K*pi/12).
  487. */
  488. GLOBAL(void)
  489. jpeg_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  490. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  491. JDIMENSION output_col)
  492. {
  493. JLONG tmp0, tmp1, tmp2, tmp10, tmp11, tmp12;
  494. JLONG z1, z2, z3;
  495. JCOEFPTR inptr;
  496. ISLOW_MULT_TYPE *quantptr;
  497. int *wsptr;
  498. JSAMPROW outptr;
  499. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  500. int ctr;
  501. int workspace[6 * 6]; /* buffers data between passes */
  502. SHIFT_TEMPS
  503. /* Pass 1: process columns from input, store into work array. */
  504. inptr = coef_block;
  505. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  506. wsptr = workspace;
  507. for (ctr = 0; ctr < 6; ctr++, inptr++, quantptr++, wsptr++) {
  508. /* Even part */
  509. tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  510. tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
  511. /* Add fudge factor here for final descale. */
  512. tmp0 += ONE << (CONST_BITS - PASS1_BITS - 1);
  513. tmp2 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  514. tmp10 = MULTIPLY(tmp2, FIX(0.707106781)); /* c4 */
  515. tmp1 = tmp0 + tmp10;
  516. tmp11 = RIGHT_SHIFT(tmp0 - tmp10 - tmp10, CONST_BITS - PASS1_BITS);
  517. tmp10 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  518. tmp0 = MULTIPLY(tmp10, FIX(1.224744871)); /* c2 */
  519. tmp10 = tmp1 + tmp0;
  520. tmp12 = tmp1 - tmp0;
  521. /* Odd part */
  522. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  523. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  524. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  525. tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */
  526. tmp0 = tmp1 + LEFT_SHIFT(z1 + z2, CONST_BITS);
  527. tmp2 = tmp1 + LEFT_SHIFT(z3 - z2, CONST_BITS);
  528. tmp1 = LEFT_SHIFT(z1 - z2 - z3, PASS1_BITS);
  529. /* Final output stage */
  530. wsptr[6 * 0] = (int)RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS - PASS1_BITS);
  531. wsptr[6 * 5] = (int)RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS - PASS1_BITS);
  532. wsptr[6 * 1] = (int)(tmp11 + tmp1);
  533. wsptr[6 * 4] = (int)(tmp11 - tmp1);
  534. wsptr[6 * 2] = (int)RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS - PASS1_BITS);
  535. wsptr[6 * 3] = (int)RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS - PASS1_BITS);
  536. }
  537. /* Pass 2: process 6 rows from work array, store into output array. */
  538. wsptr = workspace;
  539. for (ctr = 0; ctr < 6; ctr++) {
  540. outptr = output_buf[ctr] + output_col;
  541. /* Even part */
  542. /* Add fudge factor here for final descale. */
  543. tmp0 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  544. tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
  545. tmp2 = (JLONG)wsptr[4];
  546. tmp10 = MULTIPLY(tmp2, FIX(0.707106781)); /* c4 */
  547. tmp1 = tmp0 + tmp10;
  548. tmp11 = tmp0 - tmp10 - tmp10;
  549. tmp10 = (JLONG)wsptr[2];
  550. tmp0 = MULTIPLY(tmp10, FIX(1.224744871)); /* c2 */
  551. tmp10 = tmp1 + tmp0;
  552. tmp12 = tmp1 - tmp0;
  553. /* Odd part */
  554. z1 = (JLONG)wsptr[1];
  555. z2 = (JLONG)wsptr[3];
  556. z3 = (JLONG)wsptr[5];
  557. tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */
  558. tmp0 = tmp1 + LEFT_SHIFT(z1 + z2, CONST_BITS);
  559. tmp2 = tmp1 + LEFT_SHIFT(z3 - z2, CONST_BITS);
  560. tmp1 = LEFT_SHIFT(z1 - z2 - z3, CONST_BITS);
  561. /* Final output stage */
  562. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp10 + tmp0,
  563. CONST_BITS + PASS1_BITS + 3) &
  564. RANGE_MASK];
  565. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp10 - tmp0,
  566. CONST_BITS + PASS1_BITS + 3) &
  567. RANGE_MASK];
  568. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp11 + tmp1,
  569. CONST_BITS + PASS1_BITS + 3) &
  570. RANGE_MASK];
  571. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp11 - tmp1,
  572. CONST_BITS + PASS1_BITS + 3) &
  573. RANGE_MASK];
  574. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp12 + tmp2,
  575. CONST_BITS + PASS1_BITS + 3) &
  576. RANGE_MASK];
  577. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp12 - tmp2,
  578. CONST_BITS + PASS1_BITS + 3) &
  579. RANGE_MASK];
  580. wsptr += 6; /* advance pointer to next row */
  581. }
  582. }
  583. /*
  584. * Perform dequantization and inverse DCT on one block of coefficients,
  585. * producing a reduced-size 5x5 output block.
  586. *
  587. * Optimized algorithm with 5 multiplications in the 1-D kernel.
  588. * cK represents sqrt(2) * cos(K*pi/10).
  589. */
  590. GLOBAL(void)
  591. jpeg_idct_5x5(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  592. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  593. JDIMENSION output_col)
  594. {
  595. JLONG tmp0, tmp1, tmp10, tmp11, tmp12;
  596. JLONG z1, z2, z3;
  597. JCOEFPTR inptr;
  598. ISLOW_MULT_TYPE *quantptr;
  599. int *wsptr;
  600. JSAMPROW outptr;
  601. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  602. int ctr;
  603. int workspace[5 * 5]; /* buffers data between passes */
  604. SHIFT_TEMPS
  605. /* Pass 1: process columns from input, store into work array. */
  606. inptr = coef_block;
  607. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  608. wsptr = workspace;
  609. for (ctr = 0; ctr < 5; ctr++, inptr++, quantptr++, wsptr++) {
  610. /* Even part */
  611. tmp12 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  612. tmp12 = LEFT_SHIFT(tmp12, CONST_BITS);
  613. /* Add fudge factor here for final descale. */
  614. tmp12 += ONE << (CONST_BITS - PASS1_BITS - 1);
  615. tmp0 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  616. tmp1 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  617. z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */
  618. z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */
  619. z3 = tmp12 + z2;
  620. tmp10 = z3 + z1;
  621. tmp11 = z3 - z1;
  622. tmp12 -= LEFT_SHIFT(z2, 2);
  623. /* Odd part */
  624. z2 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  625. z3 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  626. z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c3 */
  627. tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c1-c3 */
  628. tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c1+c3 */
  629. /* Final output stage */
  630. wsptr[5 * 0] = (int)RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS - PASS1_BITS);
  631. wsptr[5 * 4] = (int)RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS - PASS1_BITS);
  632. wsptr[5 * 1] = (int)RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS - PASS1_BITS);
  633. wsptr[5 * 3] = (int)RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS - PASS1_BITS);
  634. wsptr[5 * 2] = (int)RIGHT_SHIFT(tmp12, CONST_BITS - PASS1_BITS);
  635. }
  636. /* Pass 2: process 5 rows from work array, store into output array. */
  637. wsptr = workspace;
  638. for (ctr = 0; ctr < 5; ctr++) {
  639. outptr = output_buf[ctr] + output_col;
  640. /* Even part */
  641. /* Add fudge factor here for final descale. */
  642. tmp12 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  643. tmp12 = LEFT_SHIFT(tmp12, CONST_BITS);
  644. tmp0 = (JLONG)wsptr[2];
  645. tmp1 = (JLONG)wsptr[4];
  646. z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */
  647. z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */
  648. z3 = tmp12 + z2;
  649. tmp10 = z3 + z1;
  650. tmp11 = z3 - z1;
  651. tmp12 -= LEFT_SHIFT(z2, 2);
  652. /* Odd part */
  653. z2 = (JLONG)wsptr[1];
  654. z3 = (JLONG)wsptr[3];
  655. z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c3 */
  656. tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c1-c3 */
  657. tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c1+c3 */
  658. /* Final output stage */
  659. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp10 + tmp0,
  660. CONST_BITS + PASS1_BITS + 3) &
  661. RANGE_MASK];
  662. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp10 - tmp0,
  663. CONST_BITS + PASS1_BITS + 3) &
  664. RANGE_MASK];
  665. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp11 + tmp1,
  666. CONST_BITS + PASS1_BITS + 3) &
  667. RANGE_MASK];
  668. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp11 - tmp1,
  669. CONST_BITS + PASS1_BITS + 3) &
  670. RANGE_MASK];
  671. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp12,
  672. CONST_BITS + PASS1_BITS + 3) &
  673. RANGE_MASK];
  674. wsptr += 5; /* advance pointer to next row */
  675. }
  676. }
  677. /*
  678. * Perform dequantization and inverse DCT on one block of coefficients,
  679. * producing a reduced-size 3x3 output block.
  680. *
  681. * Optimized algorithm with 2 multiplications in the 1-D kernel.
  682. * cK represents sqrt(2) * cos(K*pi/6).
  683. */
  684. GLOBAL(void)
  685. jpeg_idct_3x3(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  686. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  687. JDIMENSION output_col)
  688. {
  689. JLONG tmp0, tmp2, tmp10, tmp12;
  690. JCOEFPTR inptr;
  691. ISLOW_MULT_TYPE *quantptr;
  692. int *wsptr;
  693. JSAMPROW outptr;
  694. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  695. int ctr;
  696. int workspace[3 * 3]; /* buffers data between passes */
  697. SHIFT_TEMPS
  698. /* Pass 1: process columns from input, store into work array. */
  699. inptr = coef_block;
  700. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  701. wsptr = workspace;
  702. for (ctr = 0; ctr < 3; ctr++, inptr++, quantptr++, wsptr++) {
  703. /* Even part */
  704. tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  705. tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
  706. /* Add fudge factor here for final descale. */
  707. tmp0 += ONE << (CONST_BITS - PASS1_BITS - 1);
  708. tmp2 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  709. tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */
  710. tmp10 = tmp0 + tmp12;
  711. tmp2 = tmp0 - tmp12 - tmp12;
  712. /* Odd part */
  713. tmp12 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  714. tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */
  715. /* Final output stage */
  716. wsptr[3 * 0] = (int)RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS - PASS1_BITS);
  717. wsptr[3 * 2] = (int)RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS - PASS1_BITS);
  718. wsptr[3 * 1] = (int)RIGHT_SHIFT(tmp2, CONST_BITS - PASS1_BITS);
  719. }
  720. /* Pass 2: process 3 rows from work array, store into output array. */
  721. wsptr = workspace;
  722. for (ctr = 0; ctr < 3; ctr++) {
  723. outptr = output_buf[ctr] + output_col;
  724. /* Even part */
  725. /* Add fudge factor here for final descale. */
  726. tmp0 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  727. tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
  728. tmp2 = (JLONG)wsptr[2];
  729. tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */
  730. tmp10 = tmp0 + tmp12;
  731. tmp2 = tmp0 - tmp12 - tmp12;
  732. /* Odd part */
  733. tmp12 = (JLONG)wsptr[1];
  734. tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */
  735. /* Final output stage */
  736. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp10 + tmp0,
  737. CONST_BITS + PASS1_BITS + 3) &
  738. RANGE_MASK];
  739. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp10 - tmp0,
  740. CONST_BITS + PASS1_BITS + 3) &
  741. RANGE_MASK];
  742. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp2,
  743. CONST_BITS + PASS1_BITS + 3) &
  744. RANGE_MASK];
  745. wsptr += 3; /* advance pointer to next row */
  746. }
  747. }
  748. /*
  749. * Perform dequantization and inverse DCT on one block of coefficients,
  750. * producing a 9x9 output block.
  751. *
  752. * Optimized algorithm with 10 multiplications in the 1-D kernel.
  753. * cK represents sqrt(2) * cos(K*pi/18).
  754. */
  755. GLOBAL(void)
  756. jpeg_idct_9x9(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  757. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  758. JDIMENSION output_col)
  759. {
  760. JLONG tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13, tmp14;
  761. JLONG z1, z2, z3, z4;
  762. JCOEFPTR inptr;
  763. ISLOW_MULT_TYPE *quantptr;
  764. int *wsptr;
  765. JSAMPROW outptr;
  766. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  767. int ctr;
  768. int workspace[8 * 9]; /* buffers data between passes */
  769. SHIFT_TEMPS
  770. /* Pass 1: process columns from input, store into work array. */
  771. inptr = coef_block;
  772. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  773. wsptr = workspace;
  774. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  775. /* Even part */
  776. tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  777. tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
  778. /* Add fudge factor here for final descale. */
  779. tmp0 += ONE << (CONST_BITS - PASS1_BITS - 1);
  780. z1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  781. z2 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  782. z3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  783. tmp3 = MULTIPLY(z3, FIX(0.707106781)); /* c6 */
  784. tmp1 = tmp0 + tmp3;
  785. tmp2 = tmp0 - tmp3 - tmp3;
  786. tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */
  787. tmp11 = tmp2 + tmp0;
  788. tmp14 = tmp2 - tmp0 - tmp0;
  789. tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */
  790. tmp2 = MULTIPLY(z1, FIX(1.083350441)); /* c4 */
  791. tmp3 = MULTIPLY(z2, FIX(0.245575608)); /* c8 */
  792. tmp10 = tmp1 + tmp0 - tmp3;
  793. tmp12 = tmp1 - tmp0 + tmp2;
  794. tmp13 = tmp1 - tmp2 + tmp3;
  795. /* Odd part */
  796. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  797. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  798. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  799. z4 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  800. z2 = MULTIPLY(z2, -FIX(1.224744871)); /* -c3 */
  801. tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955)); /* c5 */
  802. tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525)); /* c7 */
  803. tmp0 = tmp2 + tmp3 - z2;
  804. tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481)); /* c1 */
  805. tmp2 += z2 - tmp1;
  806. tmp3 += z2 + tmp1;
  807. tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */
  808. /* Final output stage */
  809. wsptr[8 * 0] = (int)RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS - PASS1_BITS);
  810. wsptr[8 * 8] = (int)RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS - PASS1_BITS);
  811. wsptr[8 * 1] = (int)RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS - PASS1_BITS);
  812. wsptr[8 * 7] = (int)RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS - PASS1_BITS);
  813. wsptr[8 * 2] = (int)RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS - PASS1_BITS);
  814. wsptr[8 * 6] = (int)RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS - PASS1_BITS);
  815. wsptr[8 * 3] = (int)RIGHT_SHIFT(tmp13 + tmp3, CONST_BITS - PASS1_BITS);
  816. wsptr[8 * 5] = (int)RIGHT_SHIFT(tmp13 - tmp3, CONST_BITS - PASS1_BITS);
  817. wsptr[8 * 4] = (int)RIGHT_SHIFT(tmp14, CONST_BITS - PASS1_BITS);
  818. }
  819. /* Pass 2: process 9 rows from work array, store into output array. */
  820. wsptr = workspace;
  821. for (ctr = 0; ctr < 9; ctr++) {
  822. outptr = output_buf[ctr] + output_col;
  823. /* Even part */
  824. /* Add fudge factor here for final descale. */
  825. tmp0 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  826. tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
  827. z1 = (JLONG)wsptr[2];
  828. z2 = (JLONG)wsptr[4];
  829. z3 = (JLONG)wsptr[6];
  830. tmp3 = MULTIPLY(z3, FIX(0.707106781)); /* c6 */
  831. tmp1 = tmp0 + tmp3;
  832. tmp2 = tmp0 - tmp3 - tmp3;
  833. tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */
  834. tmp11 = tmp2 + tmp0;
  835. tmp14 = tmp2 - tmp0 - tmp0;
  836. tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */
  837. tmp2 = MULTIPLY(z1, FIX(1.083350441)); /* c4 */
  838. tmp3 = MULTIPLY(z2, FIX(0.245575608)); /* c8 */
  839. tmp10 = tmp1 + tmp0 - tmp3;
  840. tmp12 = tmp1 - tmp0 + tmp2;
  841. tmp13 = tmp1 - tmp2 + tmp3;
  842. /* Odd part */
  843. z1 = (JLONG)wsptr[1];
  844. z2 = (JLONG)wsptr[3];
  845. z3 = (JLONG)wsptr[5];
  846. z4 = (JLONG)wsptr[7];
  847. z2 = MULTIPLY(z2, -FIX(1.224744871)); /* -c3 */
  848. tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955)); /* c5 */
  849. tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525)); /* c7 */
  850. tmp0 = tmp2 + tmp3 - z2;
  851. tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481)); /* c1 */
  852. tmp2 += z2 - tmp1;
  853. tmp3 += z2 + tmp1;
  854. tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */
  855. /* Final output stage */
  856. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp10 + tmp0,
  857. CONST_BITS + PASS1_BITS + 3) &
  858. RANGE_MASK];
  859. outptr[8] = range_limit[(int)RIGHT_SHIFT(tmp10 - tmp0,
  860. CONST_BITS + PASS1_BITS + 3) &
  861. RANGE_MASK];
  862. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp11 + tmp1,
  863. CONST_BITS + PASS1_BITS + 3) &
  864. RANGE_MASK];
  865. outptr[7] = range_limit[(int)RIGHT_SHIFT(tmp11 - tmp1,
  866. CONST_BITS + PASS1_BITS + 3) &
  867. RANGE_MASK];
  868. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp12 + tmp2,
  869. CONST_BITS + PASS1_BITS + 3) &
  870. RANGE_MASK];
  871. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp12 - tmp2,
  872. CONST_BITS + PASS1_BITS + 3) &
  873. RANGE_MASK];
  874. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp13 + tmp3,
  875. CONST_BITS + PASS1_BITS + 3) &
  876. RANGE_MASK];
  877. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp13 - tmp3,
  878. CONST_BITS + PASS1_BITS + 3) &
  879. RANGE_MASK];
  880. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp14,
  881. CONST_BITS + PASS1_BITS + 3) &
  882. RANGE_MASK];
  883. wsptr += 8; /* advance pointer to next row */
  884. }
  885. }
  886. /*
  887. * Perform dequantization and inverse DCT on one block of coefficients,
  888. * producing a 10x10 output block.
  889. *
  890. * Optimized algorithm with 12 multiplications in the 1-D kernel.
  891. * cK represents sqrt(2) * cos(K*pi/20).
  892. */
  893. GLOBAL(void)
  894. jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  895. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  896. JDIMENSION output_col)
  897. {
  898. JLONG tmp10, tmp11, tmp12, tmp13, tmp14;
  899. JLONG tmp20, tmp21, tmp22, tmp23, tmp24;
  900. JLONG z1, z2, z3, z4, z5;
  901. JCOEFPTR inptr;
  902. ISLOW_MULT_TYPE *quantptr;
  903. int *wsptr;
  904. JSAMPROW outptr;
  905. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  906. int ctr;
  907. int workspace[8 * 10]; /* buffers data between passes */
  908. SHIFT_TEMPS
  909. /* Pass 1: process columns from input, store into work array. */
  910. inptr = coef_block;
  911. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  912. wsptr = workspace;
  913. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  914. /* Even part */
  915. z3 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  916. z3 = LEFT_SHIFT(z3, CONST_BITS);
  917. /* Add fudge factor here for final descale. */
  918. z3 += ONE << (CONST_BITS - PASS1_BITS - 1);
  919. z4 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  920. z1 = MULTIPLY(z4, FIX(1.144122806)); /* c4 */
  921. z2 = MULTIPLY(z4, FIX(0.437016024)); /* c8 */
  922. tmp10 = z3 + z1;
  923. tmp11 = z3 - z2;
  924. tmp22 = RIGHT_SHIFT(z3 - LEFT_SHIFT(z1 - z2, 1),
  925. CONST_BITS - PASS1_BITS); /* c0 = (c4-c8)*2 */
  926. z2 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  927. z3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  928. z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c6 */
  929. tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */
  930. tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */
  931. tmp20 = tmp10 + tmp12;
  932. tmp24 = tmp10 - tmp12;
  933. tmp21 = tmp11 + tmp13;
  934. tmp23 = tmp11 - tmp13;
  935. /* Odd part */
  936. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  937. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  938. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  939. z4 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  940. tmp11 = z2 + z4;
  941. tmp13 = z2 - z4;
  942. tmp12 = MULTIPLY(tmp13, FIX(0.309016994)); /* (c3-c7)/2 */
  943. z5 = LEFT_SHIFT(z3, CONST_BITS);
  944. z2 = MULTIPLY(tmp11, FIX(0.951056516)); /* (c3+c7)/2 */
  945. z4 = z5 + tmp12;
  946. tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */
  947. tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */
  948. z2 = MULTIPLY(tmp11, FIX(0.587785252)); /* (c1-c9)/2 */
  949. z4 = z5 - tmp12 - LEFT_SHIFT(tmp13, CONST_BITS - 1);
  950. tmp12 = LEFT_SHIFT(z1 - tmp13 - z3, PASS1_BITS);
  951. tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */
  952. tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */
  953. /* Final output stage */
  954. wsptr[8 * 0] = (int)RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS - PASS1_BITS);
  955. wsptr[8 * 9] = (int)RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS - PASS1_BITS);
  956. wsptr[8 * 1] = (int)RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS - PASS1_BITS);
  957. wsptr[8 * 8] = (int)RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS - PASS1_BITS);
  958. wsptr[8 * 2] = (int)(tmp22 + tmp12);
  959. wsptr[8 * 7] = (int)(tmp22 - tmp12);
  960. wsptr[8 * 3] = (int)RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS - PASS1_BITS);
  961. wsptr[8 * 6] = (int)RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS - PASS1_BITS);
  962. wsptr[8 * 4] = (int)RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS - PASS1_BITS);
  963. wsptr[8 * 5] = (int)RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS - PASS1_BITS);
  964. }
  965. /* Pass 2: process 10 rows from work array, store into output array. */
  966. wsptr = workspace;
  967. for (ctr = 0; ctr < 10; ctr++) {
  968. outptr = output_buf[ctr] + output_col;
  969. /* Even part */
  970. /* Add fudge factor here for final descale. */
  971. z3 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  972. z3 = LEFT_SHIFT(z3, CONST_BITS);
  973. z4 = (JLONG)wsptr[4];
  974. z1 = MULTIPLY(z4, FIX(1.144122806)); /* c4 */
  975. z2 = MULTIPLY(z4, FIX(0.437016024)); /* c8 */
  976. tmp10 = z3 + z1;
  977. tmp11 = z3 - z2;
  978. tmp22 = z3 - LEFT_SHIFT(z1 - z2, 1); /* c0 = (c4-c8)*2 */
  979. z2 = (JLONG)wsptr[2];
  980. z3 = (JLONG)wsptr[6];
  981. z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c6 */
  982. tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */
  983. tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */
  984. tmp20 = tmp10 + tmp12;
  985. tmp24 = tmp10 - tmp12;
  986. tmp21 = tmp11 + tmp13;
  987. tmp23 = tmp11 - tmp13;
  988. /* Odd part */
  989. z1 = (JLONG)wsptr[1];
  990. z2 = (JLONG)wsptr[3];
  991. z3 = (JLONG)wsptr[5];
  992. z3 = LEFT_SHIFT(z3, CONST_BITS);
  993. z4 = (JLONG)wsptr[7];
  994. tmp11 = z2 + z4;
  995. tmp13 = z2 - z4;
  996. tmp12 = MULTIPLY(tmp13, FIX(0.309016994)); /* (c3-c7)/2 */
  997. z2 = MULTIPLY(tmp11, FIX(0.951056516)); /* (c3+c7)/2 */
  998. z4 = z3 + tmp12;
  999. tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */
  1000. tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */
  1001. z2 = MULTIPLY(tmp11, FIX(0.587785252)); /* (c1-c9)/2 */
  1002. z4 = z3 - tmp12 - LEFT_SHIFT(tmp13, CONST_BITS - 1);
  1003. tmp12 = LEFT_SHIFT(z1 - tmp13, CONST_BITS) - z3;
  1004. tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */
  1005. tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */
  1006. /* Final output stage */
  1007. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp20 + tmp10,
  1008. CONST_BITS + PASS1_BITS + 3) &
  1009. RANGE_MASK];
  1010. outptr[9] = range_limit[(int)RIGHT_SHIFT(tmp20 - tmp10,
  1011. CONST_BITS + PASS1_BITS + 3) &
  1012. RANGE_MASK];
  1013. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp21 + tmp11,
  1014. CONST_BITS + PASS1_BITS + 3) &
  1015. RANGE_MASK];
  1016. outptr[8] = range_limit[(int)RIGHT_SHIFT(tmp21 - tmp11,
  1017. CONST_BITS + PASS1_BITS + 3) &
  1018. RANGE_MASK];
  1019. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp22 + tmp12,
  1020. CONST_BITS + PASS1_BITS + 3) &
  1021. RANGE_MASK];
  1022. outptr[7] = range_limit[(int)RIGHT_SHIFT(tmp22 - tmp12,
  1023. CONST_BITS + PASS1_BITS + 3) &
  1024. RANGE_MASK];
  1025. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp23 + tmp13,
  1026. CONST_BITS + PASS1_BITS + 3) &
  1027. RANGE_MASK];
  1028. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp23 - tmp13,
  1029. CONST_BITS + PASS1_BITS + 3) &
  1030. RANGE_MASK];
  1031. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp24 + tmp14,
  1032. CONST_BITS + PASS1_BITS + 3) &
  1033. RANGE_MASK];
  1034. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp24 - tmp14,
  1035. CONST_BITS + PASS1_BITS + 3) &
  1036. RANGE_MASK];
  1037. wsptr += 8; /* advance pointer to next row */
  1038. }
  1039. }
  1040. /*
  1041. * Perform dequantization and inverse DCT on one block of coefficients,
  1042. * producing an 11x11 output block.
  1043. *
  1044. * Optimized algorithm with 24 multiplications in the 1-D kernel.
  1045. * cK represents sqrt(2) * cos(K*pi/22).
  1046. */
  1047. GLOBAL(void)
  1048. jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1049. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1050. JDIMENSION output_col)
  1051. {
  1052. JLONG tmp10, tmp11, tmp12, tmp13, tmp14;
  1053. JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;
  1054. JLONG z1, z2, z3, z4;
  1055. JCOEFPTR inptr;
  1056. ISLOW_MULT_TYPE *quantptr;
  1057. int *wsptr;
  1058. JSAMPROW outptr;
  1059. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  1060. int ctr;
  1061. int workspace[8 * 11]; /* buffers data between passes */
  1062. SHIFT_TEMPS
  1063. /* Pass 1: process columns from input, store into work array. */
  1064. inptr = coef_block;
  1065. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  1066. wsptr = workspace;
  1067. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  1068. /* Even part */
  1069. tmp10 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  1070. tmp10 = LEFT_SHIFT(tmp10, CONST_BITS);
  1071. /* Add fudge factor here for final descale. */
  1072. tmp10 += ONE << (CONST_BITS - PASS1_BITS - 1);
  1073. z1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  1074. z2 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  1075. z3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  1076. tmp20 = MULTIPLY(z2 - z3, FIX(2.546640132)); /* c2+c4 */
  1077. tmp23 = MULTIPLY(z2 - z1, FIX(0.430815045)); /* c2-c6 */
  1078. z4 = z1 + z3;
  1079. tmp24 = MULTIPLY(z4, -FIX(1.155664402)); /* -(c2-c10) */
  1080. z4 -= z2;
  1081. tmp25 = tmp10 + MULTIPLY(z4, FIX(1.356927976)); /* c2 */
  1082. tmp21 = tmp20 + tmp23 + tmp25 -
  1083. MULTIPLY(z2, FIX(1.821790775)); /* c2+c4+c10-c6 */
  1084. tmp20 += tmp25 + MULTIPLY(z3, FIX(2.115825087)); /* c4+c6 */
  1085. tmp23 += tmp25 - MULTIPLY(z1, FIX(1.513598477)); /* c6+c8 */
  1086. tmp24 += tmp25;
  1087. tmp22 = tmp24 - MULTIPLY(z3, FIX(0.788749120)); /* c8+c10 */
  1088. tmp24 += MULTIPLY(z2, FIX(1.944413522)) - /* c2+c8 */
  1089. MULTIPLY(z1, FIX(1.390975730)); /* c4+c10 */
  1090. tmp25 = tmp10 - MULTIPLY(z4, FIX(1.414213562)); /* c0 */
  1091. /* Odd part */
  1092. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  1093. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  1094. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  1095. z4 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  1096. tmp11 = z1 + z2;
  1097. tmp14 = MULTIPLY(tmp11 + z3 + z4, FIX(0.398430003)); /* c9 */
  1098. tmp11 = MULTIPLY(tmp11, FIX(0.887983902)); /* c3-c9 */
  1099. tmp12 = MULTIPLY(z1 + z3, FIX(0.670361295)); /* c5-c9 */
  1100. tmp13 = tmp14 + MULTIPLY(z1 + z4, FIX(0.366151574)); /* c7-c9 */
  1101. tmp10 = tmp11 + tmp12 + tmp13 -
  1102. MULTIPLY(z1, FIX(0.923107866)); /* c7+c5+c3-c1-2*c9 */
  1103. z1 = tmp14 - MULTIPLY(z2 + z3, FIX(1.163011579)); /* c7+c9 */
  1104. tmp11 += z1 + MULTIPLY(z2, FIX(2.073276588)); /* c1+c7+3*c9-c3 */
  1105. tmp12 += z1 - MULTIPLY(z3, FIX(1.192193623)); /* c3+c5-c7-c9 */
  1106. z1 = MULTIPLY(z2 + z4, -FIX(1.798248910)); /* -(c1+c9) */
  1107. tmp11 += z1;
  1108. tmp13 += z1 + MULTIPLY(z4, FIX(2.102458632)); /* c1+c5+c9-c7 */
  1109. tmp14 += MULTIPLY(z2, -FIX(1.467221301)) + /* -(c5+c9) */
  1110. MULTIPLY(z3, FIX(1.001388905)) - /* c1-c9 */
  1111. MULTIPLY(z4, FIX(1.684843907)); /* c3+c9 */
  1112. /* Final output stage */
  1113. wsptr[8 * 0] = (int)RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS - PASS1_BITS);
  1114. wsptr[8 * 10] = (int)RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS - PASS1_BITS);
  1115. wsptr[8 * 1] = (int)RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS - PASS1_BITS);
  1116. wsptr[8 * 9] = (int)RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS - PASS1_BITS);
  1117. wsptr[8 * 2] = (int)RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS - PASS1_BITS);
  1118. wsptr[8 * 8] = (int)RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS - PASS1_BITS);
  1119. wsptr[8 * 3] = (int)RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS - PASS1_BITS);
  1120. wsptr[8 * 7] = (int)RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS - PASS1_BITS);
  1121. wsptr[8 * 4] = (int)RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS - PASS1_BITS);
  1122. wsptr[8 * 6] = (int)RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS - PASS1_BITS);
  1123. wsptr[8 * 5] = (int)RIGHT_SHIFT(tmp25, CONST_BITS - PASS1_BITS);
  1124. }
  1125. /* Pass 2: process 11 rows from work array, store into output array. */
  1126. wsptr = workspace;
  1127. for (ctr = 0; ctr < 11; ctr++) {
  1128. outptr = output_buf[ctr] + output_col;
  1129. /* Even part */
  1130. /* Add fudge factor here for final descale. */
  1131. tmp10 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  1132. tmp10 = LEFT_SHIFT(tmp10, CONST_BITS);
  1133. z1 = (JLONG)wsptr[2];
  1134. z2 = (JLONG)wsptr[4];
  1135. z3 = (JLONG)wsptr[6];
  1136. tmp20 = MULTIPLY(z2 - z3, FIX(2.546640132)); /* c2+c4 */
  1137. tmp23 = MULTIPLY(z2 - z1, FIX(0.430815045)); /* c2-c6 */
  1138. z4 = z1 + z3;
  1139. tmp24 = MULTIPLY(z4, -FIX(1.155664402)); /* -(c2-c10) */
  1140. z4 -= z2;
  1141. tmp25 = tmp10 + MULTIPLY(z4, FIX(1.356927976)); /* c2 */
  1142. tmp21 = tmp20 + tmp23 + tmp25 -
  1143. MULTIPLY(z2, FIX(1.821790775)); /* c2+c4+c10-c6 */
  1144. tmp20 += tmp25 + MULTIPLY(z3, FIX(2.115825087)); /* c4+c6 */
  1145. tmp23 += tmp25 - MULTIPLY(z1, FIX(1.513598477)); /* c6+c8 */
  1146. tmp24 += tmp25;
  1147. tmp22 = tmp24 - MULTIPLY(z3, FIX(0.788749120)); /* c8+c10 */
  1148. tmp24 += MULTIPLY(z2, FIX(1.944413522)) - /* c2+c8 */
  1149. MULTIPLY(z1, FIX(1.390975730)); /* c4+c10 */
  1150. tmp25 = tmp10 - MULTIPLY(z4, FIX(1.414213562)); /* c0 */
  1151. /* Odd part */
  1152. z1 = (JLONG)wsptr[1];
  1153. z2 = (JLONG)wsptr[3];
  1154. z3 = (JLONG)wsptr[5];
  1155. z4 = (JLONG)wsptr[7];
  1156. tmp11 = z1 + z2;
  1157. tmp14 = MULTIPLY(tmp11 + z3 + z4, FIX(0.398430003)); /* c9 */
  1158. tmp11 = MULTIPLY(tmp11, FIX(0.887983902)); /* c3-c9 */
  1159. tmp12 = MULTIPLY(z1 + z3, FIX(0.670361295)); /* c5-c9 */
  1160. tmp13 = tmp14 + MULTIPLY(z1 + z4, FIX(0.366151574)); /* c7-c9 */
  1161. tmp10 = tmp11 + tmp12 + tmp13 -
  1162. MULTIPLY(z1, FIX(0.923107866)); /* c7+c5+c3-c1-2*c9 */
  1163. z1 = tmp14 - MULTIPLY(z2 + z3, FIX(1.163011579)); /* c7+c9 */
  1164. tmp11 += z1 + MULTIPLY(z2, FIX(2.073276588)); /* c1+c7+3*c9-c3 */
  1165. tmp12 += z1 - MULTIPLY(z3, FIX(1.192193623)); /* c3+c5-c7-c9 */
  1166. z1 = MULTIPLY(z2 + z4, -FIX(1.798248910)); /* -(c1+c9) */
  1167. tmp11 += z1;
  1168. tmp13 += z1 + MULTIPLY(z4, FIX(2.102458632)); /* c1+c5+c9-c7 */
  1169. tmp14 += MULTIPLY(z2, -FIX(1.467221301)) + /* -(c5+c9) */
  1170. MULTIPLY(z3, FIX(1.001388905)) - /* c1-c9 */
  1171. MULTIPLY(z4, FIX(1.684843907)); /* c3+c9 */
  1172. /* Final output stage */
  1173. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp20 + tmp10,
  1174. CONST_BITS + PASS1_BITS + 3) &
  1175. RANGE_MASK];
  1176. outptr[10] = range_limit[(int)RIGHT_SHIFT(tmp20 - tmp10,
  1177. CONST_BITS + PASS1_BITS + 3) &
  1178. RANGE_MASK];
  1179. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp21 + tmp11,
  1180. CONST_BITS + PASS1_BITS + 3) &
  1181. RANGE_MASK];
  1182. outptr[9] = range_limit[(int)RIGHT_SHIFT(tmp21 - tmp11,
  1183. CONST_BITS + PASS1_BITS + 3) &
  1184. RANGE_MASK];
  1185. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp22 + tmp12,
  1186. CONST_BITS + PASS1_BITS + 3) &
  1187. RANGE_MASK];
  1188. outptr[8] = range_limit[(int)RIGHT_SHIFT(tmp22 - tmp12,
  1189. CONST_BITS + PASS1_BITS + 3) &
  1190. RANGE_MASK];
  1191. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp23 + tmp13,
  1192. CONST_BITS + PASS1_BITS + 3) &
  1193. RANGE_MASK];
  1194. outptr[7] = range_limit[(int)RIGHT_SHIFT(tmp23 - tmp13,
  1195. CONST_BITS + PASS1_BITS + 3) &
  1196. RANGE_MASK];
  1197. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp24 + tmp14,
  1198. CONST_BITS + PASS1_BITS + 3) &
  1199. RANGE_MASK];
  1200. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp24 - tmp14,
  1201. CONST_BITS + PASS1_BITS + 3) &
  1202. RANGE_MASK];
  1203. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp25,
  1204. CONST_BITS + PASS1_BITS + 3) &
  1205. RANGE_MASK];
  1206. wsptr += 8; /* advance pointer to next row */
  1207. }
  1208. }
  1209. /*
  1210. * Perform dequantization and inverse DCT on one block of coefficients,
  1211. * producing a 12x12 output block.
  1212. *
  1213. * Optimized algorithm with 15 multiplications in the 1-D kernel.
  1214. * cK represents sqrt(2) * cos(K*pi/24).
  1215. */
  1216. GLOBAL(void)
  1217. jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1218. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1219. JDIMENSION output_col)
  1220. {
  1221. JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  1222. JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;
  1223. JLONG z1, z2, z3, z4;
  1224. JCOEFPTR inptr;
  1225. ISLOW_MULT_TYPE *quantptr;
  1226. int *wsptr;
  1227. JSAMPROW outptr;
  1228. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  1229. int ctr;
  1230. int workspace[8 * 12]; /* buffers data between passes */
  1231. SHIFT_TEMPS
  1232. /* Pass 1: process columns from input, store into work array. */
  1233. inptr = coef_block;
  1234. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  1235. wsptr = workspace;
  1236. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  1237. /* Even part */
  1238. z3 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  1239. z3 = LEFT_SHIFT(z3, CONST_BITS);
  1240. /* Add fudge factor here for final descale. */
  1241. z3 += ONE << (CONST_BITS - PASS1_BITS - 1);
  1242. z4 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  1243. z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */
  1244. tmp10 = z3 + z4;
  1245. tmp11 = z3 - z4;
  1246. z1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  1247. z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */
  1248. z1 = LEFT_SHIFT(z1, CONST_BITS);
  1249. z2 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  1250. z2 = LEFT_SHIFT(z2, CONST_BITS);
  1251. tmp12 = z1 - z2;
  1252. tmp21 = z3 + tmp12;
  1253. tmp24 = z3 - tmp12;
  1254. tmp12 = z4 + z2;
  1255. tmp20 = tmp10 + tmp12;
  1256. tmp25 = tmp10 - tmp12;
  1257. tmp12 = z4 - z1 - z2;
  1258. tmp22 = tmp11 + tmp12;
  1259. tmp23 = tmp11 - tmp12;
  1260. /* Odd part */
  1261. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  1262. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  1263. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  1264. z4 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  1265. tmp11 = MULTIPLY(z2, FIX(1.306562965)); /* c3 */
  1266. tmp14 = MULTIPLY(z2, -FIX_0_541196100); /* -c9 */
  1267. tmp10 = z1 + z3;
  1268. tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669)); /* c7 */
  1269. tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384)); /* c5-c7 */
  1270. tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716)); /* c1-c5 */
  1271. tmp13 = MULTIPLY(z3 + z4, -FIX(1.045510580)); /* -(c7+c11) */
  1272. tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */
  1273. tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */
  1274. tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) - /* c7-c11 */
  1275. MULTIPLY(z4, FIX(1.982889723)); /* c5+c7 */
  1276. z1 -= z4;
  1277. z2 -= z3;
  1278. z3 = MULTIPLY(z1 + z2, FIX_0_541196100); /* c9 */
  1279. tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865); /* c3-c9 */
  1280. tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065); /* c3+c9 */
  1281. /* Final output stage */
  1282. wsptr[8 * 0] = (int)RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS - PASS1_BITS);
  1283. wsptr[8 * 11] = (int)RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS - PASS1_BITS);
  1284. wsptr[8 * 1] = (int)RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS - PASS1_BITS);
  1285. wsptr[8 * 10] = (int)RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS - PASS1_BITS);
  1286. wsptr[8 * 2] = (int)RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS - PASS1_BITS);
  1287. wsptr[8 * 9] = (int)RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS - PASS1_BITS);
  1288. wsptr[8 * 3] = (int)RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS - PASS1_BITS);
  1289. wsptr[8 * 8] = (int)RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS - PASS1_BITS);
  1290. wsptr[8 * 4] = (int)RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS - PASS1_BITS);
  1291. wsptr[8 * 7] = (int)RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS - PASS1_BITS);
  1292. wsptr[8 * 5] = (int)RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS - PASS1_BITS);
  1293. wsptr[8 * 6] = (int)RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS - PASS1_BITS);
  1294. }
  1295. /* Pass 2: process 12 rows from work array, store into output array. */
  1296. wsptr = workspace;
  1297. for (ctr = 0; ctr < 12; ctr++) {
  1298. outptr = output_buf[ctr] + output_col;
  1299. /* Even part */
  1300. /* Add fudge factor here for final descale. */
  1301. z3 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  1302. z3 = LEFT_SHIFT(z3, CONST_BITS);
  1303. z4 = (JLONG)wsptr[4];
  1304. z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */
  1305. tmp10 = z3 + z4;
  1306. tmp11 = z3 - z4;
  1307. z1 = (JLONG)wsptr[2];
  1308. z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */
  1309. z1 = LEFT_SHIFT(z1, CONST_BITS);
  1310. z2 = (JLONG)wsptr[6];
  1311. z2 = LEFT_SHIFT(z2, CONST_BITS);
  1312. tmp12 = z1 - z2;
  1313. tmp21 = z3 + tmp12;
  1314. tmp24 = z3 - tmp12;
  1315. tmp12 = z4 + z2;
  1316. tmp20 = tmp10 + tmp12;
  1317. tmp25 = tmp10 - tmp12;
  1318. tmp12 = z4 - z1 - z2;
  1319. tmp22 = tmp11 + tmp12;
  1320. tmp23 = tmp11 - tmp12;
  1321. /* Odd part */
  1322. z1 = (JLONG)wsptr[1];
  1323. z2 = (JLONG)wsptr[3];
  1324. z3 = (JLONG)wsptr[5];
  1325. z4 = (JLONG)wsptr[7];
  1326. tmp11 = MULTIPLY(z2, FIX(1.306562965)); /* c3 */
  1327. tmp14 = MULTIPLY(z2, -FIX_0_541196100); /* -c9 */
  1328. tmp10 = z1 + z3;
  1329. tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669)); /* c7 */
  1330. tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384)); /* c5-c7 */
  1331. tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716)); /* c1-c5 */
  1332. tmp13 = MULTIPLY(z3 + z4, -FIX(1.045510580)); /* -(c7+c11) */
  1333. tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */
  1334. tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */
  1335. tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) - /* c7-c11 */
  1336. MULTIPLY(z4, FIX(1.982889723)); /* c5+c7 */
  1337. z1 -= z4;
  1338. z2 -= z3;
  1339. z3 = MULTIPLY(z1 + z2, FIX_0_541196100); /* c9 */
  1340. tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865); /* c3-c9 */
  1341. tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065); /* c3+c9 */
  1342. /* Final output stage */
  1343. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp20 + tmp10,
  1344. CONST_BITS + PASS1_BITS + 3) &
  1345. RANGE_MASK];
  1346. outptr[11] = range_limit[(int)RIGHT_SHIFT(tmp20 - tmp10,
  1347. CONST_BITS + PASS1_BITS + 3) &
  1348. RANGE_MASK];
  1349. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp21 + tmp11,
  1350. CONST_BITS + PASS1_BITS + 3) &
  1351. RANGE_MASK];
  1352. outptr[10] = range_limit[(int)RIGHT_SHIFT(tmp21 - tmp11,
  1353. CONST_BITS + PASS1_BITS + 3) &
  1354. RANGE_MASK];
  1355. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp22 + tmp12,
  1356. CONST_BITS + PASS1_BITS + 3) &
  1357. RANGE_MASK];
  1358. outptr[9] = range_limit[(int)RIGHT_SHIFT(tmp22 - tmp12,
  1359. CONST_BITS + PASS1_BITS + 3) &
  1360. RANGE_MASK];
  1361. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp23 + tmp13,
  1362. CONST_BITS + PASS1_BITS + 3) &
  1363. RANGE_MASK];
  1364. outptr[8] = range_limit[(int)RIGHT_SHIFT(tmp23 - tmp13,
  1365. CONST_BITS + PASS1_BITS + 3) &
  1366. RANGE_MASK];
  1367. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp24 + tmp14,
  1368. CONST_BITS + PASS1_BITS + 3) &
  1369. RANGE_MASK];
  1370. outptr[7] = range_limit[(int)RIGHT_SHIFT(tmp24 - tmp14,
  1371. CONST_BITS + PASS1_BITS + 3) &
  1372. RANGE_MASK];
  1373. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp25 + tmp15,
  1374. CONST_BITS + PASS1_BITS + 3) &
  1375. RANGE_MASK];
  1376. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp25 - tmp15,
  1377. CONST_BITS + PASS1_BITS + 3) &
  1378. RANGE_MASK];
  1379. wsptr += 8; /* advance pointer to next row */
  1380. }
  1381. }
  1382. /*
  1383. * Perform dequantization and inverse DCT on one block of coefficients,
  1384. * producing a 13x13 output block.
  1385. *
  1386. * Optimized algorithm with 29 multiplications in the 1-D kernel.
  1387. * cK represents sqrt(2) * cos(K*pi/26).
  1388. */
  1389. GLOBAL(void)
  1390. jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1391. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1392. JDIMENSION output_col)
  1393. {
  1394. JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
  1395. JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;
  1396. JLONG z1, z2, z3, z4;
  1397. JCOEFPTR inptr;
  1398. ISLOW_MULT_TYPE *quantptr;
  1399. int *wsptr;
  1400. JSAMPROW outptr;
  1401. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  1402. int ctr;
  1403. int workspace[8 * 13]; /* buffers data between passes */
  1404. SHIFT_TEMPS
  1405. /* Pass 1: process columns from input, store into work array. */
  1406. inptr = coef_block;
  1407. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  1408. wsptr = workspace;
  1409. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  1410. /* Even part */
  1411. z1 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  1412. z1 = LEFT_SHIFT(z1, CONST_BITS);
  1413. /* Add fudge factor here for final descale. */
  1414. z1 += ONE << (CONST_BITS - PASS1_BITS - 1);
  1415. z2 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  1416. z3 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  1417. z4 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  1418. tmp10 = z3 + z4;
  1419. tmp11 = z3 - z4;
  1420. tmp12 = MULTIPLY(tmp10, FIX(1.155388986)); /* (c4+c6)/2 */
  1421. tmp13 = MULTIPLY(tmp11, FIX(0.096834934)) + z1; /* (c4-c6)/2 */
  1422. tmp20 = MULTIPLY(z2, FIX(1.373119086)) + tmp12 + tmp13; /* c2 */
  1423. tmp22 = MULTIPLY(z2, FIX(0.501487041)) - tmp12 + tmp13; /* c10 */
  1424. tmp12 = MULTIPLY(tmp10, FIX(0.316450131)); /* (c8-c12)/2 */
  1425. tmp13 = MULTIPLY(tmp11, FIX(0.486914739)) + z1; /* (c8+c12)/2 */
  1426. tmp21 = MULTIPLY(z2, FIX(1.058554052)) - tmp12 + tmp13; /* c6 */
  1427. tmp25 = MULTIPLY(z2, -FIX(1.252223920)) + tmp12 + tmp13; /* c4 */
  1428. tmp12 = MULTIPLY(tmp10, FIX(0.435816023)); /* (c2-c10)/2 */
  1429. tmp13 = MULTIPLY(tmp11, FIX(0.937303064)) - z1; /* (c2+c10)/2 */
  1430. tmp23 = MULTIPLY(z2, -FIX(0.170464608)) - tmp12 - tmp13; /* c12 */
  1431. tmp24 = MULTIPLY(z2, -FIX(0.803364869)) + tmp12 - tmp13; /* c8 */
  1432. tmp26 = MULTIPLY(tmp11 - z2, FIX(1.414213562)) + z1; /* c0 */
  1433. /* Odd part */
  1434. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  1435. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  1436. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  1437. z4 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  1438. tmp11 = MULTIPLY(z1 + z2, FIX(1.322312651)); /* c3 */
  1439. tmp12 = MULTIPLY(z1 + z3, FIX(1.163874945)); /* c5 */
  1440. tmp15 = z1 + z4;
  1441. tmp13 = MULTIPLY(tmp15, FIX(0.937797057)); /* c7 */
  1442. tmp10 = tmp11 + tmp12 + tmp13 -
  1443. MULTIPLY(z1, FIX(2.020082300)); /* c7+c5+c3-c1 */
  1444. tmp14 = MULTIPLY(z2 + z3, -FIX(0.338443458)); /* -c11 */
  1445. tmp11 += tmp14 + MULTIPLY(z2, FIX(0.837223564)); /* c5+c9+c11-c3 */
  1446. tmp12 += tmp14 - MULTIPLY(z3, FIX(1.572116027)); /* c1+c5-c9-c11 */
  1447. tmp14 = MULTIPLY(z2 + z4, -FIX(1.163874945)); /* -c5 */
  1448. tmp11 += tmp14;
  1449. tmp13 += tmp14 + MULTIPLY(z4, FIX(2.205608352)); /* c3+c5+c9-c7 */
  1450. tmp14 = MULTIPLY(z3 + z4, -FIX(0.657217813)); /* -c9 */
  1451. tmp12 += tmp14;
  1452. tmp13 += tmp14;
  1453. tmp15 = MULTIPLY(tmp15, FIX(0.338443458)); /* c11 */
  1454. tmp14 = tmp15 + MULTIPLY(z1, FIX(0.318774355)) - /* c9-c11 */
  1455. MULTIPLY(z2, FIX(0.466105296)); /* c1-c7 */
  1456. z1 = MULTIPLY(z3 - z2, FIX(0.937797057)); /* c7 */
  1457. tmp14 += z1;
  1458. tmp15 += z1 + MULTIPLY(z3, FIX(0.384515595)) - /* c3-c7 */
  1459. MULTIPLY(z4, FIX(1.742345811)); /* c1+c11 */
  1460. /* Final output stage */
  1461. wsptr[8 * 0] = (int)RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS - PASS1_BITS);
  1462. wsptr[8 * 12] = (int)RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS - PASS1_BITS);
  1463. wsptr[8 * 1] = (int)RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS - PASS1_BITS);
  1464. wsptr[8 * 11] = (int)RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS - PASS1_BITS);
  1465. wsptr[8 * 2] = (int)RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS - PASS1_BITS);
  1466. wsptr[8 * 10] = (int)RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS - PASS1_BITS);
  1467. wsptr[8 * 3] = (int)RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS - PASS1_BITS);
  1468. wsptr[8 * 9] = (int)RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS - PASS1_BITS);
  1469. wsptr[8 * 4] = (int)RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS - PASS1_BITS);
  1470. wsptr[8 * 8] = (int)RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS - PASS1_BITS);
  1471. wsptr[8 * 5] = (int)RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS - PASS1_BITS);
  1472. wsptr[8 * 7] = (int)RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS - PASS1_BITS);
  1473. wsptr[8 * 6] = (int)RIGHT_SHIFT(tmp26, CONST_BITS - PASS1_BITS);
  1474. }
  1475. /* Pass 2: process 13 rows from work array, store into output array. */
  1476. wsptr = workspace;
  1477. for (ctr = 0; ctr < 13; ctr++) {
  1478. outptr = output_buf[ctr] + output_col;
  1479. /* Even part */
  1480. /* Add fudge factor here for final descale. */
  1481. z1 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  1482. z1 = LEFT_SHIFT(z1, CONST_BITS);
  1483. z2 = (JLONG)wsptr[2];
  1484. z3 = (JLONG)wsptr[4];
  1485. z4 = (JLONG)wsptr[6];
  1486. tmp10 = z3 + z4;
  1487. tmp11 = z3 - z4;
  1488. tmp12 = MULTIPLY(tmp10, FIX(1.155388986)); /* (c4+c6)/2 */
  1489. tmp13 = MULTIPLY(tmp11, FIX(0.096834934)) + z1; /* (c4-c6)/2 */
  1490. tmp20 = MULTIPLY(z2, FIX(1.373119086)) + tmp12 + tmp13; /* c2 */
  1491. tmp22 = MULTIPLY(z2, FIX(0.501487041)) - tmp12 + tmp13; /* c10 */
  1492. tmp12 = MULTIPLY(tmp10, FIX(0.316450131)); /* (c8-c12)/2 */
  1493. tmp13 = MULTIPLY(tmp11, FIX(0.486914739)) + z1; /* (c8+c12)/2 */
  1494. tmp21 = MULTIPLY(z2, FIX(1.058554052)) - tmp12 + tmp13; /* c6 */
  1495. tmp25 = MULTIPLY(z2, -FIX(1.252223920)) + tmp12 + tmp13; /* c4 */
  1496. tmp12 = MULTIPLY(tmp10, FIX(0.435816023)); /* (c2-c10)/2 */
  1497. tmp13 = MULTIPLY(tmp11, FIX(0.937303064)) - z1; /* (c2+c10)/2 */
  1498. tmp23 = MULTIPLY(z2, -FIX(0.170464608)) - tmp12 - tmp13; /* c12 */
  1499. tmp24 = MULTIPLY(z2, -FIX(0.803364869)) + tmp12 - tmp13; /* c8 */
  1500. tmp26 = MULTIPLY(tmp11 - z2, FIX(1.414213562)) + z1; /* c0 */
  1501. /* Odd part */
  1502. z1 = (JLONG)wsptr[1];
  1503. z2 = (JLONG)wsptr[3];
  1504. z3 = (JLONG)wsptr[5];
  1505. z4 = (JLONG)wsptr[7];
  1506. tmp11 = MULTIPLY(z1 + z2, FIX(1.322312651)); /* c3 */
  1507. tmp12 = MULTIPLY(z1 + z3, FIX(1.163874945)); /* c5 */
  1508. tmp15 = z1 + z4;
  1509. tmp13 = MULTIPLY(tmp15, FIX(0.937797057)); /* c7 */
  1510. tmp10 = tmp11 + tmp12 + tmp13 -
  1511. MULTIPLY(z1, FIX(2.020082300)); /* c7+c5+c3-c1 */
  1512. tmp14 = MULTIPLY(z2 + z3, -FIX(0.338443458)); /* -c11 */
  1513. tmp11 += tmp14 + MULTIPLY(z2, FIX(0.837223564)); /* c5+c9+c11-c3 */
  1514. tmp12 += tmp14 - MULTIPLY(z3, FIX(1.572116027)); /* c1+c5-c9-c11 */
  1515. tmp14 = MULTIPLY(z2 + z4, -FIX(1.163874945)); /* -c5 */
  1516. tmp11 += tmp14;
  1517. tmp13 += tmp14 + MULTIPLY(z4, FIX(2.205608352)); /* c3+c5+c9-c7 */
  1518. tmp14 = MULTIPLY(z3 + z4, -FIX(0.657217813)); /* -c9 */
  1519. tmp12 += tmp14;
  1520. tmp13 += tmp14;
  1521. tmp15 = MULTIPLY(tmp15, FIX(0.338443458)); /* c11 */
  1522. tmp14 = tmp15 + MULTIPLY(z1, FIX(0.318774355)) - /* c9-c11 */
  1523. MULTIPLY(z2, FIX(0.466105296)); /* c1-c7 */
  1524. z1 = MULTIPLY(z3 - z2, FIX(0.937797057)); /* c7 */
  1525. tmp14 += z1;
  1526. tmp15 += z1 + MULTIPLY(z3, FIX(0.384515595)) - /* c3-c7 */
  1527. MULTIPLY(z4, FIX(1.742345811)); /* c1+c11 */
  1528. /* Final output stage */
  1529. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp20 + tmp10,
  1530. CONST_BITS + PASS1_BITS + 3) &
  1531. RANGE_MASK];
  1532. outptr[12] = range_limit[(int)RIGHT_SHIFT(tmp20 - tmp10,
  1533. CONST_BITS + PASS1_BITS + 3) &
  1534. RANGE_MASK];
  1535. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp21 + tmp11,
  1536. CONST_BITS + PASS1_BITS + 3) &
  1537. RANGE_MASK];
  1538. outptr[11] = range_limit[(int)RIGHT_SHIFT(tmp21 - tmp11,
  1539. CONST_BITS + PASS1_BITS + 3) &
  1540. RANGE_MASK];
  1541. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp22 + tmp12,
  1542. CONST_BITS + PASS1_BITS + 3) &
  1543. RANGE_MASK];
  1544. outptr[10] = range_limit[(int)RIGHT_SHIFT(tmp22 - tmp12,
  1545. CONST_BITS + PASS1_BITS + 3) &
  1546. RANGE_MASK];
  1547. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp23 + tmp13,
  1548. CONST_BITS + PASS1_BITS + 3) &
  1549. RANGE_MASK];
  1550. outptr[9] = range_limit[(int)RIGHT_SHIFT(tmp23 - tmp13,
  1551. CONST_BITS + PASS1_BITS + 3) &
  1552. RANGE_MASK];
  1553. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp24 + tmp14,
  1554. CONST_BITS + PASS1_BITS + 3) &
  1555. RANGE_MASK];
  1556. outptr[8] = range_limit[(int)RIGHT_SHIFT(tmp24 - tmp14,
  1557. CONST_BITS + PASS1_BITS + 3) &
  1558. RANGE_MASK];
  1559. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp25 + tmp15,
  1560. CONST_BITS + PASS1_BITS + 3) &
  1561. RANGE_MASK];
  1562. outptr[7] = range_limit[(int)RIGHT_SHIFT(tmp25 - tmp15,
  1563. CONST_BITS + PASS1_BITS + 3) &
  1564. RANGE_MASK];
  1565. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp26,
  1566. CONST_BITS + PASS1_BITS + 3) &
  1567. RANGE_MASK];
  1568. wsptr += 8; /* advance pointer to next row */
  1569. }
  1570. }
  1571. /*
  1572. * Perform dequantization and inverse DCT on one block of coefficients,
  1573. * producing a 14x14 output block.
  1574. *
  1575. * Optimized algorithm with 20 multiplications in the 1-D kernel.
  1576. * cK represents sqrt(2) * cos(K*pi/28).
  1577. */
  1578. GLOBAL(void)
  1579. jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1580. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1581. JDIMENSION output_col)
  1582. {
  1583. JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  1584. JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;
  1585. JLONG z1, z2, z3, z4;
  1586. JCOEFPTR inptr;
  1587. ISLOW_MULT_TYPE *quantptr;
  1588. int *wsptr;
  1589. JSAMPROW outptr;
  1590. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  1591. int ctr;
  1592. int workspace[8 * 14]; /* buffers data between passes */
  1593. SHIFT_TEMPS
  1594. /* Pass 1: process columns from input, store into work array. */
  1595. inptr = coef_block;
  1596. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  1597. wsptr = workspace;
  1598. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  1599. /* Even part */
  1600. z1 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  1601. z1 = LEFT_SHIFT(z1, CONST_BITS);
  1602. /* Add fudge factor here for final descale. */
  1603. z1 += ONE << (CONST_BITS - PASS1_BITS - 1);
  1604. z4 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  1605. z2 = MULTIPLY(z4, FIX(1.274162392)); /* c4 */
  1606. z3 = MULTIPLY(z4, FIX(0.314692123)); /* c12 */
  1607. z4 = MULTIPLY(z4, FIX(0.881747734)); /* c8 */
  1608. tmp10 = z1 + z2;
  1609. tmp11 = z1 + z3;
  1610. tmp12 = z1 - z4;
  1611. tmp23 = RIGHT_SHIFT(z1 - LEFT_SHIFT(z2 + z3 - z4, 1),
  1612. CONST_BITS - PASS1_BITS); /* c0 = (c4+c12-c8)*2 */
  1613. z1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  1614. z2 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  1615. z3 = MULTIPLY(z1 + z2, FIX(1.105676686)); /* c6 */
  1616. tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */
  1617. tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */
  1618. tmp15 = MULTIPLY(z1, FIX(0.613604268)) - /* c10 */
  1619. MULTIPLY(z2, FIX(1.378756276)); /* c2 */
  1620. tmp20 = tmp10 + tmp13;
  1621. tmp26 = tmp10 - tmp13;
  1622. tmp21 = tmp11 + tmp14;
  1623. tmp25 = tmp11 - tmp14;
  1624. tmp22 = tmp12 + tmp15;
  1625. tmp24 = tmp12 - tmp15;
  1626. /* Odd part */
  1627. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  1628. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  1629. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  1630. z4 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  1631. tmp13 = LEFT_SHIFT(z4, CONST_BITS);
  1632. tmp14 = z1 + z3;
  1633. tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607)); /* c3 */
  1634. tmp12 = MULTIPLY(tmp14, FIX(1.197448846)); /* c5 */
  1635. tmp10 = tmp11 + tmp12 + tmp13 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */
  1636. tmp14 = MULTIPLY(tmp14, FIX(0.752406978)); /* c9 */
  1637. tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426)); /* c9+c11-c13 */
  1638. z1 -= z2;
  1639. tmp15 = MULTIPLY(z1, FIX(0.467085129)) - tmp13; /* c11 */
  1640. tmp16 += tmp15;
  1641. z1 += z4;
  1642. z4 = MULTIPLY(z2 + z3, -FIX(0.158341681)) - tmp13; /* -c13 */
  1643. tmp11 += z4 - MULTIPLY(z2, FIX(0.424103948)); /* c3-c9-c13 */
  1644. tmp12 += z4 - MULTIPLY(z3, FIX(2.373959773)); /* c3+c5-c13 */
  1645. z4 = MULTIPLY(z3 - z2, FIX(1.405321284)); /* c1 */
  1646. tmp14 += z4 + tmp13 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */
  1647. tmp15 += z4 + MULTIPLY(z2, FIX(0.674957567)); /* c1+c11-c5 */
  1648. tmp13 = LEFT_SHIFT(z1 - z3, PASS1_BITS);
  1649. /* Final output stage */
  1650. wsptr[8 * 0] = (int)RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS - PASS1_BITS);
  1651. wsptr[8 * 13] = (int)RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS - PASS1_BITS);
  1652. wsptr[8 * 1] = (int)RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS - PASS1_BITS);
  1653. wsptr[8 * 12] = (int)RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS - PASS1_BITS);
  1654. wsptr[8 * 2] = (int)RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS - PASS1_BITS);
  1655. wsptr[8 * 11] = (int)RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS - PASS1_BITS);
  1656. wsptr[8 * 3] = (int)(tmp23 + tmp13);
  1657. wsptr[8 * 10] = (int)(tmp23 - tmp13);
  1658. wsptr[8 * 4] = (int)RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS - PASS1_BITS);
  1659. wsptr[8 * 9] = (int)RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS - PASS1_BITS);
  1660. wsptr[8 * 5] = (int)RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS - PASS1_BITS);
  1661. wsptr[8 * 8] = (int)RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS - PASS1_BITS);
  1662. wsptr[8 * 6] = (int)RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS - PASS1_BITS);
  1663. wsptr[8 * 7] = (int)RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS - PASS1_BITS);
  1664. }
  1665. /* Pass 2: process 14 rows from work array, store into output array. */
  1666. wsptr = workspace;
  1667. for (ctr = 0; ctr < 14; ctr++) {
  1668. outptr = output_buf[ctr] + output_col;
  1669. /* Even part */
  1670. /* Add fudge factor here for final descale. */
  1671. z1 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  1672. z1 = LEFT_SHIFT(z1, CONST_BITS);
  1673. z4 = (JLONG)wsptr[4];
  1674. z2 = MULTIPLY(z4, FIX(1.274162392)); /* c4 */
  1675. z3 = MULTIPLY(z4, FIX(0.314692123)); /* c12 */
  1676. z4 = MULTIPLY(z4, FIX(0.881747734)); /* c8 */
  1677. tmp10 = z1 + z2;
  1678. tmp11 = z1 + z3;
  1679. tmp12 = z1 - z4;
  1680. tmp23 = z1 - LEFT_SHIFT(z2 + z3 - z4, 1); /* c0 = (c4+c12-c8)*2 */
  1681. z1 = (JLONG)wsptr[2];
  1682. z2 = (JLONG)wsptr[6];
  1683. z3 = MULTIPLY(z1 + z2, FIX(1.105676686)); /* c6 */
  1684. tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */
  1685. tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */
  1686. tmp15 = MULTIPLY(z1, FIX(0.613604268)) - /* c10 */
  1687. MULTIPLY(z2, FIX(1.378756276)); /* c2 */
  1688. tmp20 = tmp10 + tmp13;
  1689. tmp26 = tmp10 - tmp13;
  1690. tmp21 = tmp11 + tmp14;
  1691. tmp25 = tmp11 - tmp14;
  1692. tmp22 = tmp12 + tmp15;
  1693. tmp24 = tmp12 - tmp15;
  1694. /* Odd part */
  1695. z1 = (JLONG)wsptr[1];
  1696. z2 = (JLONG)wsptr[3];
  1697. z3 = (JLONG)wsptr[5];
  1698. z4 = (JLONG)wsptr[7];
  1699. z4 = LEFT_SHIFT(z4, CONST_BITS);
  1700. tmp14 = z1 + z3;
  1701. tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607)); /* c3 */
  1702. tmp12 = MULTIPLY(tmp14, FIX(1.197448846)); /* c5 */
  1703. tmp10 = tmp11 + tmp12 + z4 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */
  1704. tmp14 = MULTIPLY(tmp14, FIX(0.752406978)); /* c9 */
  1705. tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426)); /* c9+c11-c13 */
  1706. z1 -= z2;
  1707. tmp15 = MULTIPLY(z1, FIX(0.467085129)) - z4; /* c11 */
  1708. tmp16 += tmp15;
  1709. tmp13 = MULTIPLY(z2 + z3, -FIX(0.158341681)) - z4; /* -c13 */
  1710. tmp11 += tmp13 - MULTIPLY(z2, FIX(0.424103948)); /* c3-c9-c13 */
  1711. tmp12 += tmp13 - MULTIPLY(z3, FIX(2.373959773)); /* c3+c5-c13 */
  1712. tmp13 = MULTIPLY(z3 - z2, FIX(1.405321284)); /* c1 */
  1713. tmp14 += tmp13 + z4 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */
  1714. tmp15 += tmp13 + MULTIPLY(z2, FIX(0.674957567)); /* c1+c11-c5 */
  1715. tmp13 = LEFT_SHIFT(z1 - z3, CONST_BITS) + z4;
  1716. /* Final output stage */
  1717. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp20 + tmp10,
  1718. CONST_BITS + PASS1_BITS + 3) &
  1719. RANGE_MASK];
  1720. outptr[13] = range_limit[(int)RIGHT_SHIFT(tmp20 - tmp10,
  1721. CONST_BITS + PASS1_BITS + 3) &
  1722. RANGE_MASK];
  1723. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp21 + tmp11,
  1724. CONST_BITS + PASS1_BITS + 3) &
  1725. RANGE_MASK];
  1726. outptr[12] = range_limit[(int)RIGHT_SHIFT(tmp21 - tmp11,
  1727. CONST_BITS + PASS1_BITS + 3) &
  1728. RANGE_MASK];
  1729. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp22 + tmp12,
  1730. CONST_BITS + PASS1_BITS + 3) &
  1731. RANGE_MASK];
  1732. outptr[11] = range_limit[(int)RIGHT_SHIFT(tmp22 - tmp12,
  1733. CONST_BITS + PASS1_BITS + 3) &
  1734. RANGE_MASK];
  1735. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp23 + tmp13,
  1736. CONST_BITS + PASS1_BITS + 3) &
  1737. RANGE_MASK];
  1738. outptr[10] = range_limit[(int)RIGHT_SHIFT(tmp23 - tmp13,
  1739. CONST_BITS + PASS1_BITS + 3) &
  1740. RANGE_MASK];
  1741. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp24 + tmp14,
  1742. CONST_BITS + PASS1_BITS + 3) &
  1743. RANGE_MASK];
  1744. outptr[9] = range_limit[(int)RIGHT_SHIFT(tmp24 - tmp14,
  1745. CONST_BITS + PASS1_BITS + 3) &
  1746. RANGE_MASK];
  1747. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp25 + tmp15,
  1748. CONST_BITS + PASS1_BITS + 3) &
  1749. RANGE_MASK];
  1750. outptr[8] = range_limit[(int)RIGHT_SHIFT(tmp25 - tmp15,
  1751. CONST_BITS + PASS1_BITS + 3) &
  1752. RANGE_MASK];
  1753. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp26 + tmp16,
  1754. CONST_BITS + PASS1_BITS + 3) &
  1755. RANGE_MASK];
  1756. outptr[7] = range_limit[(int)RIGHT_SHIFT(tmp26 - tmp16,
  1757. CONST_BITS + PASS1_BITS + 3) &
  1758. RANGE_MASK];
  1759. wsptr += 8; /* advance pointer to next row */
  1760. }
  1761. }
  1762. /*
  1763. * Perform dequantization and inverse DCT on one block of coefficients,
  1764. * producing a 15x15 output block.
  1765. *
  1766. * Optimized algorithm with 22 multiplications in the 1-D kernel.
  1767. * cK represents sqrt(2) * cos(K*pi/30).
  1768. */
  1769. GLOBAL(void)
  1770. jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1771. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1772. JDIMENSION output_col)
  1773. {
  1774. JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
  1775. JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
  1776. JLONG z1, z2, z3, z4;
  1777. JCOEFPTR inptr;
  1778. ISLOW_MULT_TYPE *quantptr;
  1779. int *wsptr;
  1780. JSAMPROW outptr;
  1781. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  1782. int ctr;
  1783. int workspace[8 * 15]; /* buffers data between passes */
  1784. SHIFT_TEMPS
  1785. /* Pass 1: process columns from input, store into work array. */
  1786. inptr = coef_block;
  1787. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  1788. wsptr = workspace;
  1789. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  1790. /* Even part */
  1791. z1 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  1792. z1 = LEFT_SHIFT(z1, CONST_BITS);
  1793. /* Add fudge factor here for final descale. */
  1794. z1 += ONE << (CONST_BITS - PASS1_BITS - 1);
  1795. z2 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  1796. z3 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  1797. z4 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  1798. tmp10 = MULTIPLY(z4, FIX(0.437016024)); /* c12 */
  1799. tmp11 = MULTIPLY(z4, FIX(1.144122806)); /* c6 */
  1800. tmp12 = z1 - tmp10;
  1801. tmp13 = z1 + tmp11;
  1802. z1 -= LEFT_SHIFT(tmp11 - tmp10, 1); /* c0 = (c6-c12)*2 */
  1803. z4 = z2 - z3;
  1804. z3 += z2;
  1805. tmp10 = MULTIPLY(z3, FIX(1.337628990)); /* (c2+c4)/2 */
  1806. tmp11 = MULTIPLY(z4, FIX(0.045680613)); /* (c2-c4)/2 */
  1807. z2 = MULTIPLY(z2, FIX(1.439773946)); /* c4+c14 */
  1808. tmp20 = tmp13 + tmp10 + tmp11;
  1809. tmp23 = tmp12 - tmp10 + tmp11 + z2;
  1810. tmp10 = MULTIPLY(z3, FIX(0.547059574)); /* (c8+c14)/2 */
  1811. tmp11 = MULTIPLY(z4, FIX(0.399234004)); /* (c8-c14)/2 */
  1812. tmp25 = tmp13 - tmp10 - tmp11;
  1813. tmp26 = tmp12 + tmp10 - tmp11 - z2;
  1814. tmp10 = MULTIPLY(z3, FIX(0.790569415)); /* (c6+c12)/2 */
  1815. tmp11 = MULTIPLY(z4, FIX(0.353553391)); /* (c6-c12)/2 */
  1816. tmp21 = tmp12 + tmp10 + tmp11;
  1817. tmp24 = tmp13 - tmp10 + tmp11;
  1818. tmp11 += tmp11;
  1819. tmp22 = z1 + tmp11; /* c10 = c6-c12 */
  1820. tmp27 = z1 - tmp11 - tmp11; /* c0 = (c6-c12)*2 */
  1821. /* Odd part */
  1822. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  1823. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  1824. z4 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  1825. z3 = MULTIPLY(z4, FIX(1.224744871)); /* c5 */
  1826. z4 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  1827. tmp13 = z2 - z4;
  1828. tmp15 = MULTIPLY(z1 + tmp13, FIX(0.831253876)); /* c9 */
  1829. tmp11 = tmp15 + MULTIPLY(z1, FIX(0.513743148)); /* c3-c9 */
  1830. tmp14 = tmp15 - MULTIPLY(tmp13, FIX(2.176250899)); /* c3+c9 */
  1831. tmp13 = MULTIPLY(z2, -FIX(0.831253876)); /* -c9 */
  1832. tmp15 = MULTIPLY(z2, -FIX(1.344997024)); /* -c3 */
  1833. z2 = z1 - z4;
  1834. tmp12 = z3 + MULTIPLY(z2, FIX(1.406466353)); /* c1 */
  1835. tmp10 = tmp12 + MULTIPLY(z4, FIX(2.457431844)) - tmp15; /* c1+c7 */
  1836. tmp16 = tmp12 - MULTIPLY(z1, FIX(1.112434820)) + tmp13; /* c1-c13 */
  1837. tmp12 = MULTIPLY(z2, FIX(1.224744871)) - z3; /* c5 */
  1838. z2 = MULTIPLY(z1 + z4, FIX(0.575212477)); /* c11 */
  1839. tmp13 += z2 + MULTIPLY(z1, FIX(0.475753014)) - z3; /* c7-c11 */
  1840. tmp15 += z2 - MULTIPLY(z4, FIX(0.869244010)) + z3; /* c11+c13 */
  1841. /* Final output stage */
  1842. wsptr[8 * 0] = (int)RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS - PASS1_BITS);
  1843. wsptr[8 * 14] = (int)RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS - PASS1_BITS);
  1844. wsptr[8 * 1] = (int)RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS - PASS1_BITS);
  1845. wsptr[8 * 13] = (int)RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS - PASS1_BITS);
  1846. wsptr[8 * 2] = (int)RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS - PASS1_BITS);
  1847. wsptr[8 * 12] = (int)RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS - PASS1_BITS);
  1848. wsptr[8 * 3] = (int)RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS - PASS1_BITS);
  1849. wsptr[8 * 11] = (int)RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS - PASS1_BITS);
  1850. wsptr[8 * 4] = (int)RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS - PASS1_BITS);
  1851. wsptr[8 * 10] = (int)RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS - PASS1_BITS);
  1852. wsptr[8 * 5] = (int)RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS - PASS1_BITS);
  1853. wsptr[8 * 9] = (int)RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS - PASS1_BITS);
  1854. wsptr[8 * 6] = (int)RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS - PASS1_BITS);
  1855. wsptr[8 * 8] = (int)RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS - PASS1_BITS);
  1856. wsptr[8 * 7] = (int)RIGHT_SHIFT(tmp27, CONST_BITS - PASS1_BITS);
  1857. }
  1858. /* Pass 2: process 15 rows from work array, store into output array. */
  1859. wsptr = workspace;
  1860. for (ctr = 0; ctr < 15; ctr++) {
  1861. outptr = output_buf[ctr] + output_col;
  1862. /* Even part */
  1863. /* Add fudge factor here for final descale. */
  1864. z1 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  1865. z1 = LEFT_SHIFT(z1, CONST_BITS);
  1866. z2 = (JLONG)wsptr[2];
  1867. z3 = (JLONG)wsptr[4];
  1868. z4 = (JLONG)wsptr[6];
  1869. tmp10 = MULTIPLY(z4, FIX(0.437016024)); /* c12 */
  1870. tmp11 = MULTIPLY(z4, FIX(1.144122806)); /* c6 */
  1871. tmp12 = z1 - tmp10;
  1872. tmp13 = z1 + tmp11;
  1873. z1 -= LEFT_SHIFT(tmp11 - tmp10, 1); /* c0 = (c6-c12)*2 */
  1874. z4 = z2 - z3;
  1875. z3 += z2;
  1876. tmp10 = MULTIPLY(z3, FIX(1.337628990)); /* (c2+c4)/2 */
  1877. tmp11 = MULTIPLY(z4, FIX(0.045680613)); /* (c2-c4)/2 */
  1878. z2 = MULTIPLY(z2, FIX(1.439773946)); /* c4+c14 */
  1879. tmp20 = tmp13 + tmp10 + tmp11;
  1880. tmp23 = tmp12 - tmp10 + tmp11 + z2;
  1881. tmp10 = MULTIPLY(z3, FIX(0.547059574)); /* (c8+c14)/2 */
  1882. tmp11 = MULTIPLY(z4, FIX(0.399234004)); /* (c8-c14)/2 */
  1883. tmp25 = tmp13 - tmp10 - tmp11;
  1884. tmp26 = tmp12 + tmp10 - tmp11 - z2;
  1885. tmp10 = MULTIPLY(z3, FIX(0.790569415)); /* (c6+c12)/2 */
  1886. tmp11 = MULTIPLY(z4, FIX(0.353553391)); /* (c6-c12)/2 */
  1887. tmp21 = tmp12 + tmp10 + tmp11;
  1888. tmp24 = tmp13 - tmp10 + tmp11;
  1889. tmp11 += tmp11;
  1890. tmp22 = z1 + tmp11; /* c10 = c6-c12 */
  1891. tmp27 = z1 - tmp11 - tmp11; /* c0 = (c6-c12)*2 */
  1892. /* Odd part */
  1893. z1 = (JLONG)wsptr[1];
  1894. z2 = (JLONG)wsptr[3];
  1895. z4 = (JLONG)wsptr[5];
  1896. z3 = MULTIPLY(z4, FIX(1.224744871)); /* c5 */
  1897. z4 = (JLONG)wsptr[7];
  1898. tmp13 = z2 - z4;
  1899. tmp15 = MULTIPLY(z1 + tmp13, FIX(0.831253876)); /* c9 */
  1900. tmp11 = tmp15 + MULTIPLY(z1, FIX(0.513743148)); /* c3-c9 */
  1901. tmp14 = tmp15 - MULTIPLY(tmp13, FIX(2.176250899)); /* c3+c9 */
  1902. tmp13 = MULTIPLY(z2, -FIX(0.831253876)); /* -c9 */
  1903. tmp15 = MULTIPLY(z2, -FIX(1.344997024)); /* -c3 */
  1904. z2 = z1 - z4;
  1905. tmp12 = z3 + MULTIPLY(z2, FIX(1.406466353)); /* c1 */
  1906. tmp10 = tmp12 + MULTIPLY(z4, FIX(2.457431844)) - tmp15; /* c1+c7 */
  1907. tmp16 = tmp12 - MULTIPLY(z1, FIX(1.112434820)) + tmp13; /* c1-c13 */
  1908. tmp12 = MULTIPLY(z2, FIX(1.224744871)) - z3; /* c5 */
  1909. z2 = MULTIPLY(z1 + z4, FIX(0.575212477)); /* c11 */
  1910. tmp13 += z2 + MULTIPLY(z1, FIX(0.475753014)) - z3; /* c7-c11 */
  1911. tmp15 += z2 - MULTIPLY(z4, FIX(0.869244010)) + z3; /* c11+c13 */
  1912. /* Final output stage */
  1913. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp20 + tmp10,
  1914. CONST_BITS + PASS1_BITS + 3) &
  1915. RANGE_MASK];
  1916. outptr[14] = range_limit[(int)RIGHT_SHIFT(tmp20 - tmp10,
  1917. CONST_BITS + PASS1_BITS + 3) &
  1918. RANGE_MASK];
  1919. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp21 + tmp11,
  1920. CONST_BITS + PASS1_BITS + 3) &
  1921. RANGE_MASK];
  1922. outptr[13] = range_limit[(int)RIGHT_SHIFT(tmp21 - tmp11,
  1923. CONST_BITS + PASS1_BITS + 3) &
  1924. RANGE_MASK];
  1925. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp22 + tmp12,
  1926. CONST_BITS + PASS1_BITS + 3) &
  1927. RANGE_MASK];
  1928. outptr[12] = range_limit[(int)RIGHT_SHIFT(tmp22 - tmp12,
  1929. CONST_BITS + PASS1_BITS + 3) &
  1930. RANGE_MASK];
  1931. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp23 + tmp13,
  1932. CONST_BITS + PASS1_BITS + 3) &
  1933. RANGE_MASK];
  1934. outptr[11] = range_limit[(int)RIGHT_SHIFT(tmp23 - tmp13,
  1935. CONST_BITS + PASS1_BITS + 3) &
  1936. RANGE_MASK];
  1937. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp24 + tmp14,
  1938. CONST_BITS + PASS1_BITS + 3) &
  1939. RANGE_MASK];
  1940. outptr[10] = range_limit[(int)RIGHT_SHIFT(tmp24 - tmp14,
  1941. CONST_BITS + PASS1_BITS + 3) &
  1942. RANGE_MASK];
  1943. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp25 + tmp15,
  1944. CONST_BITS + PASS1_BITS + 3) &
  1945. RANGE_MASK];
  1946. outptr[9] = range_limit[(int)RIGHT_SHIFT(tmp25 - tmp15,
  1947. CONST_BITS + PASS1_BITS + 3) &
  1948. RANGE_MASK];
  1949. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp26 + tmp16,
  1950. CONST_BITS + PASS1_BITS + 3) &
  1951. RANGE_MASK];
  1952. outptr[8] = range_limit[(int)RIGHT_SHIFT(tmp26 - tmp16,
  1953. CONST_BITS + PASS1_BITS + 3) &
  1954. RANGE_MASK];
  1955. outptr[7] = range_limit[(int)RIGHT_SHIFT(tmp27,
  1956. CONST_BITS + PASS1_BITS + 3) &
  1957. RANGE_MASK];
  1958. wsptr += 8; /* advance pointer to next row */
  1959. }
  1960. }
  1961. /*
  1962. * Perform dequantization and inverse DCT on one block of coefficients,
  1963. * producing a 16x16 output block.
  1964. *
  1965. * Optimized algorithm with 28 multiplications in the 1-D kernel.
  1966. * cK represents sqrt(2) * cos(K*pi/32).
  1967. */
  1968. GLOBAL(void)
  1969. jpeg_idct_16x16(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1970. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1971. JDIMENSION output_col)
  1972. {
  1973. JLONG tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;
  1974. JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
  1975. JLONG z1, z2, z3, z4;
  1976. JCOEFPTR inptr;
  1977. ISLOW_MULT_TYPE *quantptr;
  1978. int *wsptr;
  1979. JSAMPROW outptr;
  1980. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  1981. int ctr;
  1982. int workspace[8 * 16]; /* buffers data between passes */
  1983. SHIFT_TEMPS
  1984. /* Pass 1: process columns from input, store into work array. */
  1985. inptr = coef_block;
  1986. quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
  1987. wsptr = workspace;
  1988. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  1989. /* Even part */
  1990. tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
  1991. tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
  1992. /* Add fudge factor here for final descale. */
  1993. tmp0 += ONE << (CONST_BITS - PASS1_BITS - 1);
  1994. z1 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
  1995. tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */
  1996. tmp2 = MULTIPLY(z1, FIX_0_541196100); /* c12[16] = c6[8] */
  1997. tmp10 = tmp0 + tmp1;
  1998. tmp11 = tmp0 - tmp1;
  1999. tmp12 = tmp0 + tmp2;
  2000. tmp13 = tmp0 - tmp2;
  2001. z1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
  2002. z2 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
  2003. z3 = z1 - z2;
  2004. z4 = MULTIPLY(z3, FIX(0.275899379)); /* c14[16] = c7[8] */
  2005. z3 = MULTIPLY(z3, FIX(1.387039845)); /* c2[16] = c1[8] */
  2006. tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447); /* (c6+c2)[16] = (c3+c1)[8] */
  2007. tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223); /* (c6-c14)[16] = (c3-c7)[8] */
  2008. tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */
  2009. tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */
  2010. tmp20 = tmp10 + tmp0;
  2011. tmp27 = tmp10 - tmp0;
  2012. tmp21 = tmp12 + tmp1;
  2013. tmp26 = tmp12 - tmp1;
  2014. tmp22 = tmp13 + tmp2;
  2015. tmp25 = tmp13 - tmp2;
  2016. tmp23 = tmp11 + tmp3;
  2017. tmp24 = tmp11 - tmp3;
  2018. /* Odd part */
  2019. z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
  2020. z2 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
  2021. z3 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
  2022. z4 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
  2023. tmp11 = z1 + z3;
  2024. tmp1 = MULTIPLY(z1 + z2, FIX(1.353318001)); /* c3 */
  2025. tmp2 = MULTIPLY(tmp11, FIX(1.247225013)); /* c5 */
  2026. tmp3 = MULTIPLY(z1 + z4, FIX(1.093201867)); /* c7 */
  2027. tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586)); /* c9 */
  2028. tmp11 = MULTIPLY(tmp11, FIX(0.666655658)); /* c11 */
  2029. tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528)); /* c13 */
  2030. tmp0 = tmp1 + tmp2 + tmp3 -
  2031. MULTIPLY(z1, FIX(2.286341144)); /* c7+c5+c3-c1 */
  2032. tmp13 = tmp10 + tmp11 + tmp12 -
  2033. MULTIPLY(z1, FIX(1.835730603)); /* c9+c11+c13-c15 */
  2034. z1 = MULTIPLY(z2 + z3, FIX(0.138617169)); /* c15 */
  2035. tmp1 += z1 + MULTIPLY(z2, FIX(0.071888074)); /* c9+c11-c3-c15 */
  2036. tmp2 += z1 - MULTIPLY(z3, FIX(1.125726048)); /* c5+c7+c15-c3 */
  2037. z1 = MULTIPLY(z3 - z2, FIX(1.407403738)); /* c1 */
  2038. tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282)); /* c1+c11-c9-c13 */
  2039. tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411)); /* c1+c5+c13-c7 */
  2040. z2 += z4;
  2041. z1 = MULTIPLY(z2, -FIX(0.666655658)); /* -c11 */
  2042. tmp1 += z1;
  2043. tmp3 += z1 + MULTIPLY(z4, FIX(1.065388962)); /* c3+c11+c15-c7 */
  2044. z2 = MULTIPLY(z2, -FIX(1.247225013)); /* -c5 */
  2045. tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809)); /* c1+c5+c9-c13 */
  2046. tmp12 += z2;
  2047. z2 = MULTIPLY(z3 + z4, -FIX(1.353318001)); /* -c3 */
  2048. tmp2 += z2;
  2049. tmp3 += z2;
  2050. z2 = MULTIPLY(z4 - z3, FIX(0.410524528)); /* c13 */
  2051. tmp10 += z2;
  2052. tmp11 += z2;
  2053. /* Final output stage */
  2054. wsptr[8 * 0] = (int)RIGHT_SHIFT(tmp20 + tmp0, CONST_BITS - PASS1_BITS);
  2055. wsptr[8 * 15] = (int)RIGHT_SHIFT(tmp20 - tmp0, CONST_BITS - PASS1_BITS);
  2056. wsptr[8 * 1] = (int)RIGHT_SHIFT(tmp21 + tmp1, CONST_BITS - PASS1_BITS);
  2057. wsptr[8 * 14] = (int)RIGHT_SHIFT(tmp21 - tmp1, CONST_BITS - PASS1_BITS);
  2058. wsptr[8 * 2] = (int)RIGHT_SHIFT(tmp22 + tmp2, CONST_BITS - PASS1_BITS);
  2059. wsptr[8 * 13] = (int)RIGHT_SHIFT(tmp22 - tmp2, CONST_BITS - PASS1_BITS);
  2060. wsptr[8 * 3] = (int)RIGHT_SHIFT(tmp23 + tmp3, CONST_BITS - PASS1_BITS);
  2061. wsptr[8 * 12] = (int)RIGHT_SHIFT(tmp23 - tmp3, CONST_BITS - PASS1_BITS);
  2062. wsptr[8 * 4] = (int)RIGHT_SHIFT(tmp24 + tmp10, CONST_BITS - PASS1_BITS);
  2063. wsptr[8 * 11] = (int)RIGHT_SHIFT(tmp24 - tmp10, CONST_BITS - PASS1_BITS);
  2064. wsptr[8 * 5] = (int)RIGHT_SHIFT(tmp25 + tmp11, CONST_BITS - PASS1_BITS);
  2065. wsptr[8 * 10] = (int)RIGHT_SHIFT(tmp25 - tmp11, CONST_BITS - PASS1_BITS);
  2066. wsptr[8 * 6] = (int)RIGHT_SHIFT(tmp26 + tmp12, CONST_BITS - PASS1_BITS);
  2067. wsptr[8 * 9] = (int)RIGHT_SHIFT(tmp26 - tmp12, CONST_BITS - PASS1_BITS);
  2068. wsptr[8 * 7] = (int)RIGHT_SHIFT(tmp27 + tmp13, CONST_BITS - PASS1_BITS);
  2069. wsptr[8 * 8] = (int)RIGHT_SHIFT(tmp27 - tmp13, CONST_BITS - PASS1_BITS);
  2070. }
  2071. /* Pass 2: process 16 rows from work array, store into output array. */
  2072. wsptr = workspace;
  2073. for (ctr = 0; ctr < 16; ctr++) {
  2074. outptr = output_buf[ctr] + output_col;
  2075. /* Even part */
  2076. /* Add fudge factor here for final descale. */
  2077. tmp0 = (JLONG)wsptr[0] + (ONE << (PASS1_BITS + 2));
  2078. tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
  2079. z1 = (JLONG)wsptr[4];
  2080. tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */
  2081. tmp2 = MULTIPLY(z1, FIX_0_541196100); /* c12[16] = c6[8] */
  2082. tmp10 = tmp0 + tmp1;
  2083. tmp11 = tmp0 - tmp1;
  2084. tmp12 = tmp0 + tmp2;
  2085. tmp13 = tmp0 - tmp2;
  2086. z1 = (JLONG)wsptr[2];
  2087. z2 = (JLONG)wsptr[6];
  2088. z3 = z1 - z2;
  2089. z4 = MULTIPLY(z3, FIX(0.275899379)); /* c14[16] = c7[8] */
  2090. z3 = MULTIPLY(z3, FIX(1.387039845)); /* c2[16] = c1[8] */
  2091. tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447); /* (c6+c2)[16] = (c3+c1)[8] */
  2092. tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223); /* (c6-c14)[16] = (c3-c7)[8] */
  2093. tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */
  2094. tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */
  2095. tmp20 = tmp10 + tmp0;
  2096. tmp27 = tmp10 - tmp0;
  2097. tmp21 = tmp12 + tmp1;
  2098. tmp26 = tmp12 - tmp1;
  2099. tmp22 = tmp13 + tmp2;
  2100. tmp25 = tmp13 - tmp2;
  2101. tmp23 = tmp11 + tmp3;
  2102. tmp24 = tmp11 - tmp3;
  2103. /* Odd part */
  2104. z1 = (JLONG)wsptr[1];
  2105. z2 = (JLONG)wsptr[3];
  2106. z3 = (JLONG)wsptr[5];
  2107. z4 = (JLONG)wsptr[7];
  2108. tmp11 = z1 + z3;
  2109. tmp1 = MULTIPLY(z1 + z2, FIX(1.353318001)); /* c3 */
  2110. tmp2 = MULTIPLY(tmp11, FIX(1.247225013)); /* c5 */
  2111. tmp3 = MULTIPLY(z1 + z4, FIX(1.093201867)); /* c7 */
  2112. tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586)); /* c9 */
  2113. tmp11 = MULTIPLY(tmp11, FIX(0.666655658)); /* c11 */
  2114. tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528)); /* c13 */
  2115. tmp0 = tmp1 + tmp2 + tmp3 -
  2116. MULTIPLY(z1, FIX(2.286341144)); /* c7+c5+c3-c1 */
  2117. tmp13 = tmp10 + tmp11 + tmp12 -
  2118. MULTIPLY(z1, FIX(1.835730603)); /* c9+c11+c13-c15 */
  2119. z1 = MULTIPLY(z2 + z3, FIX(0.138617169)); /* c15 */
  2120. tmp1 += z1 + MULTIPLY(z2, FIX(0.071888074)); /* c9+c11-c3-c15 */
  2121. tmp2 += z1 - MULTIPLY(z3, FIX(1.125726048)); /* c5+c7+c15-c3 */
  2122. z1 = MULTIPLY(z3 - z2, FIX(1.407403738)); /* c1 */
  2123. tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282)); /* c1+c11-c9-c13 */
  2124. tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411)); /* c1+c5+c13-c7 */
  2125. z2 += z4;
  2126. z1 = MULTIPLY(z2, -FIX(0.666655658)); /* -c11 */
  2127. tmp1 += z1;
  2128. tmp3 += z1 + MULTIPLY(z4, FIX(1.065388962)); /* c3+c11+c15-c7 */
  2129. z2 = MULTIPLY(z2, -FIX(1.247225013)); /* -c5 */
  2130. tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809)); /* c1+c5+c9-c13 */
  2131. tmp12 += z2;
  2132. z2 = MULTIPLY(z3 + z4, -FIX(1.353318001)); /* -c3 */
  2133. tmp2 += z2;
  2134. tmp3 += z2;
  2135. z2 = MULTIPLY(z4 - z3, FIX(0.410524528)); /* c13 */
  2136. tmp10 += z2;
  2137. tmp11 += z2;
  2138. /* Final output stage */
  2139. outptr[0] = range_limit[(int)RIGHT_SHIFT(tmp20 + tmp0,
  2140. CONST_BITS + PASS1_BITS + 3) &
  2141. RANGE_MASK];
  2142. outptr[15] = range_limit[(int)RIGHT_SHIFT(tmp20 - tmp0,
  2143. CONST_BITS + PASS1_BITS + 3) &
  2144. RANGE_MASK];
  2145. outptr[1] = range_limit[(int)RIGHT_SHIFT(tmp21 + tmp1,
  2146. CONST_BITS + PASS1_BITS + 3) &
  2147. RANGE_MASK];
  2148. outptr[14] = range_limit[(int)RIGHT_SHIFT(tmp21 - tmp1,
  2149. CONST_BITS + PASS1_BITS + 3) &
  2150. RANGE_MASK];
  2151. outptr[2] = range_limit[(int)RIGHT_SHIFT(tmp22 + tmp2,
  2152. CONST_BITS + PASS1_BITS + 3) &
  2153. RANGE_MASK];
  2154. outptr[13] = range_limit[(int)RIGHT_SHIFT(tmp22 - tmp2,
  2155. CONST_BITS + PASS1_BITS + 3) &
  2156. RANGE_MASK];
  2157. outptr[3] = range_limit[(int)RIGHT_SHIFT(tmp23 + tmp3,
  2158. CONST_BITS + PASS1_BITS + 3) &
  2159. RANGE_MASK];
  2160. outptr[12] = range_limit[(int)RIGHT_SHIFT(tmp23 - tmp3,
  2161. CONST_BITS + PASS1_BITS + 3) &
  2162. RANGE_MASK];
  2163. outptr[4] = range_limit[(int)RIGHT_SHIFT(tmp24 + tmp10,
  2164. CONST_BITS + PASS1_BITS + 3) &
  2165. RANGE_MASK];
  2166. outptr[11] = range_limit[(int)RIGHT_SHIFT(tmp24 - tmp10,
  2167. CONST_BITS + PASS1_BITS + 3) &
  2168. RANGE_MASK];
  2169. outptr[5] = range_limit[(int)RIGHT_SHIFT(tmp25 + tmp11,
  2170. CONST_BITS + PASS1_BITS + 3) &
  2171. RANGE_MASK];
  2172. outptr[10] = range_limit[(int)RIGHT_SHIFT(tmp25 - tmp11,
  2173. CONST_BITS + PASS1_BITS + 3) &
  2174. RANGE_MASK];
  2175. outptr[6] = range_limit[(int)RIGHT_SHIFT(tmp26 + tmp12,
  2176. CONST_BITS + PASS1_BITS + 3) &
  2177. RANGE_MASK];
  2178. outptr[9] = range_limit[(int)RIGHT_SHIFT(tmp26 - tmp12,
  2179. CONST_BITS + PASS1_BITS + 3) &
  2180. RANGE_MASK];
  2181. outptr[7] = range_limit[(int)RIGHT_SHIFT(tmp27 + tmp13,
  2182. CONST_BITS + PASS1_BITS + 3) &
  2183. RANGE_MASK];
  2184. outptr[8] = range_limit[(int)RIGHT_SHIFT(tmp27 - tmp13,
  2185. CONST_BITS + PASS1_BITS + 3) &
  2186. RANGE_MASK];
  2187. wsptr += 8; /* advance pointer to next row */
  2188. }
  2189. }
  2190. #endif /* IDCT_SCALING_SUPPORTED */
  2191. #endif /* DCT_ISLOW_SUPPORTED */