jpc_qmfb.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144
  1. /*
  2. * Copyright (c) 1999-2000 Image Power, Inc. and the University of
  3. * British Columbia.
  4. * Copyright (c) 2001-2003 Michael David Adams.
  5. * All rights reserved.
  6. */
  7. /* __START_OF_JASPER_LICENSE__
  8. *
  9. * JasPer License Version 2.0
  10. *
  11. * Copyright (c) 2001-2006 Michael David Adams
  12. * Copyright (c) 1999-2000 Image Power, Inc.
  13. * Copyright (c) 1999-2000 The University of British Columbia
  14. *
  15. * All rights reserved.
  16. *
  17. * Permission is hereby granted, free of charge, to any person (the
  18. * "User") obtaining a copy of this software and associated documentation
  19. * files (the "Software"), to deal in the Software without restriction,
  20. * including without limitation the rights to use, copy, modify, merge,
  21. * publish, distribute, and/or sell copies of the Software, and to permit
  22. * persons to whom the Software is furnished to do so, subject to the
  23. * following conditions:
  24. *
  25. * 1. The above copyright notices and this permission notice (which
  26. * includes the disclaimer below) shall be included in all copies or
  27. * substantial portions of the Software.
  28. *
  29. * 2. The name of a copyright holder shall not be used to endorse or
  30. * promote products derived from the Software without specific prior
  31. * written permission.
  32. *
  33. * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
  34. * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  35. * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
  36. * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  37. * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  38. * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
  39. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
  40. * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
  41. * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  42. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  43. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
  44. * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
  45. * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
  46. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
  47. * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
  48. * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
  49. * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
  50. * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
  51. * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
  52. * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
  53. * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
  54. * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
  55. * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
  56. * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
  57. * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
  58. * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
  59. *
  60. * __END_OF_JASPER_LICENSE__
  61. */
  62. /*
  63. * Quadrature Mirror-Image Filter Bank (QMFB) Library
  64. *
  65. * $Id: jpc_qmfb.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
  66. */
  67. /******************************************************************************\
  68. *
  69. \******************************************************************************/
  70. #undef WT_LENONE /* This is not needed due to normalization. */
  71. #define WT_DOSCALE
  72. /******************************************************************************\
  73. * Includes.
  74. \******************************************************************************/
  75. #include <assert.h>
  76. #include "jasper/jas_fix.h"
  77. #include "jasper/jas_malloc.h"
  78. #include "jasper/jas_math.h"
  79. #include "jpc_qmfb.h"
  80. #include "jpc_tsfb.h"
  81. #include "jpc_math.h"
  82. /******************************************************************************\
  83. *
  84. \******************************************************************************/
  85. #define QMFB_SPLITBUFSIZE 4096
  86. #define QMFB_JOINBUFSIZE 4096
  87. int jpc_ft_analyze(int *a, int xstart, int ystart, int width, int height,
  88. int stride);
  89. int jpc_ft_synthesize(int *a, int xstart, int ystart, int width, int height,
  90. int stride);
  91. int jpc_ns_analyze(int *a, int xstart, int ystart, int width, int height,
  92. int stride);
  93. int jpc_ns_synthesize(int *a, int xstart, int ystart, int width,
  94. int height, int stride);
  95. void jpc_ft_fwdlift_row(jpc_fix_t *a, int numcols, int parity);
  96. void jpc_ft_fwdlift_col(jpc_fix_t *a, int numrows, int stride,
  97. int parity);
  98. void jpc_ft_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride,
  99. int parity);
  100. void jpc_ft_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols,
  101. int stride, int parity);
  102. void jpc_ft_invlift_row(jpc_fix_t *a, int numcols, int parity);
  103. void jpc_ft_invlift_col(jpc_fix_t *a, int numrows, int stride,
  104. int parity);
  105. void jpc_ft_invlift_colgrp(jpc_fix_t *a, int numrows, int stride,
  106. int parity);
  107. void jpc_ft_invlift_colres(jpc_fix_t *a, int numrows, int numcols,
  108. int stride, int parity);
  109. void jpc_ns_fwdlift_row(jpc_fix_t *a, int numcols, int parity);
  110. void jpc_ns_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity);
  111. void jpc_ns_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
  112. int parity);
  113. void jpc_ns_invlift_row(jpc_fix_t *a, int numcols, int parity);
  114. void jpc_ns_invlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity);
  115. void jpc_ns_invlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
  116. int parity);
  117. void jpc_qmfb_split_row(jpc_fix_t *a, int numcols, int parity);
  118. void jpc_qmfb_split_col(jpc_fix_t *a, int numrows, int stride, int parity);
  119. void jpc_qmfb_split_colgrp(jpc_fix_t *a, int numrows, int stride, int parity);
  120. void jpc_qmfb_split_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
  121. int parity);
  122. void jpc_qmfb_join_row(jpc_fix_t *a, int numcols, int parity);
  123. void jpc_qmfb_join_col(jpc_fix_t *a, int numrows, int stride, int parity);
  124. void jpc_qmfb_join_colgrp(jpc_fix_t *a, int numrows, int stride, int parity);
  125. void jpc_qmfb_join_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
  126. int parity);
  127. double jpc_ft_lpenergywts[32] = {
  128. 1.2247448713915889,
  129. 1.6583123951776999,
  130. 2.3184046238739260,
  131. 3.2691742076555053,
  132. 4.6199296531440819,
  133. 6.5323713152269596,
  134. 9.2377452606141937,
  135. 13.0639951297449581,
  136. 18.4752262333915667,
  137. 26.1278968190610392,
  138. 36.9504194305524791,
  139. 52.2557819580462777,
  140. 73.9008347315741645,
  141. 104.5115624560829133,
  142. 147.8016689469569656,
  143. 209.0231247296646018,
  144. 295.6033378293900000,
  145. 418.0462494347059419,
  146. 591.2066756503630813,
  147. 836.0924988714708661,
  148. /* approximations */
  149. 836.0924988714708661,
  150. 836.0924988714708661,
  151. 836.0924988714708661,
  152. 836.0924988714708661,
  153. 836.0924988714708661,
  154. 836.0924988714708661,
  155. 836.0924988714708661,
  156. 836.0924988714708661,
  157. 836.0924988714708661,
  158. 836.0924988714708661,
  159. 836.0924988714708661,
  160. 836.0924988714708661
  161. };
  162. double jpc_ft_hpenergywts[32] = {
  163. 0.8477912478906585,
  164. 0.9601432184835760,
  165. 1.2593401049756179,
  166. 1.7444107171191079,
  167. 2.4538713036750726,
  168. 3.4656517695088755,
  169. 4.8995276398597856,
  170. 6.9283970402160842,
  171. 9.7980274940131444,
  172. 13.8564306871112652,
  173. 19.5959265076535587,
  174. 27.7128159494245487,
  175. 39.1918369552045860,
  176. 55.4256262207444053,
  177. 78.3836719028959124,
  178. 110.8512517317256822,
  179. 156.7673435548526868,
  180. 221.7025033739244293,
  181. 313.5346870787551552,
  182. 443.4050067351659550,
  183. /* approximations */
  184. 443.4050067351659550,
  185. 443.4050067351659550,
  186. 443.4050067351659550,
  187. 443.4050067351659550,
  188. 443.4050067351659550,
  189. 443.4050067351659550,
  190. 443.4050067351659550,
  191. 443.4050067351659550,
  192. 443.4050067351659550,
  193. 443.4050067351659550,
  194. 443.4050067351659550,
  195. 443.4050067351659550
  196. };
  197. double jpc_ns_lpenergywts[32] = {
  198. 1.4021081679297411,
  199. 2.0303718560817923,
  200. 2.9011625562785555,
  201. 4.1152851751758002,
  202. 5.8245108637728071,
  203. 8.2387599345725171,
  204. 11.6519546479210838,
  205. 16.4785606470644375,
  206. 23.3042776444606794,
  207. 32.9572515613740435,
  208. 46.6086013487782793,
  209. 65.9145194076860861,
  210. 93.2172084551803977,
  211. 131.8290408510004283,
  212. 186.4344176300625691,
  213. 263.6580819564562148,
  214. 372.8688353500955373,
  215. 527.3161639447193920,
  216. 745.7376707114038936,
  217. 1054.6323278917823245,
  218. /* approximations follow */
  219. 1054.6323278917823245,
  220. 1054.6323278917823245,
  221. 1054.6323278917823245,
  222. 1054.6323278917823245,
  223. 1054.6323278917823245,
  224. 1054.6323278917823245,
  225. 1054.6323278917823245,
  226. 1054.6323278917823245,
  227. 1054.6323278917823245,
  228. 1054.6323278917823245,
  229. 1054.6323278917823245,
  230. 1054.6323278917823245
  231. };
  232. double jpc_ns_hpenergywts[32] = {
  233. 1.4425227650161456,
  234. 1.9669426082455688,
  235. 2.8839248082788891,
  236. 4.1475208393432981,
  237. 5.8946497530677817,
  238. 8.3471789178590949,
  239. 11.8086046551047463,
  240. 16.7012780415647804,
  241. 23.6196657032246620,
  242. 33.4034255108592362,
  243. 47.2396388881632632,
  244. 66.8069597416714061,
  245. 94.4793162154500692,
  246. 133.6139330736999113,
  247. 188.9586372358249378,
  248. 267.2278678461869390,
  249. 377.9172750722391356,
  250. 534.4557359047058753,
  251. 755.8345502191498326,
  252. 1068.9114718353569060,
  253. /* approximations follow */
  254. 1068.9114718353569060,
  255. 1068.9114718353569060,
  256. 1068.9114718353569060,
  257. 1068.9114718353569060,
  258. 1068.9114718353569060,
  259. 1068.9114718353569060,
  260. 1068.9114718353569060,
  261. 1068.9114718353569060,
  262. 1068.9114718353569060,
  263. 1068.9114718353569060,
  264. 1068.9114718353569060
  265. };
  266. jpc_qmfb2d_t jpc_ft_qmfb2d = {
  267. jpc_ft_analyze,
  268. jpc_ft_synthesize,
  269. jpc_ft_lpenergywts,
  270. jpc_ft_hpenergywts
  271. };
  272. jpc_qmfb2d_t jpc_ns_qmfb2d = {
  273. jpc_ns_analyze,
  274. jpc_ns_synthesize,
  275. jpc_ns_lpenergywts,
  276. jpc_ns_hpenergywts
  277. };
  278. /******************************************************************************\
  279. * generic
  280. \******************************************************************************/
  281. void jpc_qmfb_split_row(jpc_fix_t *a, int numcols, int parity)
  282. {
  283. int bufsize = JPC_CEILDIVPOW2(numcols, 1);
  284. #if !defined(HAVE_VLA)
  285. jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
  286. #else
  287. jpc_fix_t splitbuf[bufsize];
  288. #endif
  289. jpc_fix_t *buf = splitbuf;
  290. register jpc_fix_t *srcptr;
  291. register jpc_fix_t *dstptr;
  292. register int n;
  293. register int m;
  294. int hstartcol;
  295. #if !defined(HAVE_VLA)
  296. /* Get a buffer. */
  297. if (bufsize > QMFB_SPLITBUFSIZE) {
  298. if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
  299. /* We have no choice but to commit suicide in this case. */
  300. abort();
  301. }
  302. }
  303. #endif
  304. if (numcols >= 2) {
  305. hstartcol = (numcols + 1 - parity) >> 1;
  306. m = (parity) ? hstartcol : (numcols - hstartcol);
  307. /* Save the samples destined for the highpass channel. */
  308. n = m;
  309. dstptr = buf;
  310. srcptr = &a[1 - parity];
  311. while (n-- > 0) {
  312. *dstptr = *srcptr;
  313. ++dstptr;
  314. srcptr += 2;
  315. }
  316. /* Copy the appropriate samples into the lowpass channel. */
  317. dstptr = &a[1 - parity];
  318. srcptr = &a[2 - parity];
  319. n = numcols - m - (!parity);
  320. while (n-- > 0) {
  321. *dstptr = *srcptr;
  322. ++dstptr;
  323. srcptr += 2;
  324. }
  325. /* Copy the saved samples into the highpass channel. */
  326. dstptr = &a[hstartcol];
  327. srcptr = buf;
  328. n = m;
  329. while (n-- > 0) {
  330. *dstptr = *srcptr;
  331. ++dstptr;
  332. ++srcptr;
  333. }
  334. }
  335. #if !defined(HAVE_VLA)
  336. /* If the split buffer was allocated on the heap, free this memory. */
  337. if (buf != splitbuf) {
  338. jas_free(buf);
  339. }
  340. #endif
  341. }
  342. void jpc_qmfb_split_col(jpc_fix_t *a, int numrows, int stride,
  343. int parity)
  344. {
  345. int bufsize = JPC_CEILDIVPOW2(numrows, 1);
  346. #if !defined(HAVE_VLA)
  347. jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
  348. #else
  349. jpc_fix_t splitbuf[bufsize];
  350. #endif
  351. jpc_fix_t *buf = splitbuf;
  352. register jpc_fix_t *srcptr;
  353. register jpc_fix_t *dstptr;
  354. register int n;
  355. register int m;
  356. int hstartcol;
  357. #if !defined(HAVE_VLA)
  358. /* Get a buffer. */
  359. if (bufsize > QMFB_SPLITBUFSIZE) {
  360. if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
  361. /* We have no choice but to commit suicide in this case. */
  362. abort();
  363. }
  364. }
  365. #endif
  366. if (numrows >= 2) {
  367. hstartcol = (numrows + 1 - parity) >> 1;
  368. m = (parity) ? hstartcol : (numrows - hstartcol);
  369. /* Save the samples destined for the highpass channel. */
  370. n = m;
  371. dstptr = buf;
  372. srcptr = &a[(1 - parity) * stride];
  373. while (n-- > 0) {
  374. *dstptr = *srcptr;
  375. ++dstptr;
  376. srcptr += stride << 1;
  377. }
  378. /* Copy the appropriate samples into the lowpass channel. */
  379. dstptr = &a[(1 - parity) * stride];
  380. srcptr = &a[(2 - parity) * stride];
  381. n = numrows - m - (!parity);
  382. while (n-- > 0) {
  383. *dstptr = *srcptr;
  384. dstptr += stride;
  385. srcptr += stride << 1;
  386. }
  387. /* Copy the saved samples into the highpass channel. */
  388. dstptr = &a[hstartcol * stride];
  389. srcptr = buf;
  390. n = m;
  391. while (n-- > 0) {
  392. *dstptr = *srcptr;
  393. dstptr += stride;
  394. ++srcptr;
  395. }
  396. }
  397. #if !defined(HAVE_VLA)
  398. /* If the split buffer was allocated on the heap, free this memory. */
  399. if (buf != splitbuf) {
  400. jas_free(buf);
  401. }
  402. #endif
  403. }
  404. void jpc_qmfb_split_colgrp(jpc_fix_t *a, int numrows, int stride,
  405. int parity)
  406. {
  407. int bufsize = JPC_CEILDIVPOW2(numrows, 1);
  408. #if !defined(HAVE_VLA)
  409. jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE * JPC_QMFB_COLGRPSIZE];
  410. #else
  411. jpc_fix_t splitbuf[bufsize * JPC_QMFB_COLGRPSIZE];
  412. #endif
  413. jpc_fix_t *buf = splitbuf;
  414. jpc_fix_t *srcptr;
  415. jpc_fix_t *dstptr;
  416. register jpc_fix_t *srcptr2;
  417. register jpc_fix_t *dstptr2;
  418. register int n;
  419. register int i;
  420. int m;
  421. int hstartcol;
  422. #if !defined(HAVE_VLA)
  423. /* Get a buffer. */
  424. if (bufsize > QMFB_SPLITBUFSIZE) {
  425. if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
  426. /* We have no choice but to commit suicide in this case. */
  427. abort();
  428. }
  429. }
  430. #endif
  431. if (numrows >= 2) {
  432. hstartcol = (numrows + 1 - parity) >> 1;
  433. m = (parity) ? hstartcol : (numrows - hstartcol);
  434. /* Save the samples destined for the highpass channel. */
  435. n = m;
  436. dstptr = buf;
  437. srcptr = &a[(1 - parity) * stride];
  438. while (n-- > 0) {
  439. dstptr2 = dstptr;
  440. srcptr2 = srcptr;
  441. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  442. *dstptr2 = *srcptr2;
  443. ++dstptr2;
  444. ++srcptr2;
  445. }
  446. dstptr += JPC_QMFB_COLGRPSIZE;
  447. srcptr += stride << 1;
  448. }
  449. /* Copy the appropriate samples into the lowpass channel. */
  450. dstptr = &a[(1 - parity) * stride];
  451. srcptr = &a[(2 - parity) * stride];
  452. n = numrows - m - (!parity);
  453. while (n-- > 0) {
  454. dstptr2 = dstptr;
  455. srcptr2 = srcptr;
  456. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  457. *dstptr2 = *srcptr2;
  458. ++dstptr2;
  459. ++srcptr2;
  460. }
  461. dstptr += stride;
  462. srcptr += stride << 1;
  463. }
  464. /* Copy the saved samples into the highpass channel. */
  465. dstptr = &a[hstartcol * stride];
  466. srcptr = buf;
  467. n = m;
  468. while (n-- > 0) {
  469. dstptr2 = dstptr;
  470. srcptr2 = srcptr;
  471. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  472. *dstptr2 = *srcptr2;
  473. ++dstptr2;
  474. ++srcptr2;
  475. }
  476. dstptr += stride;
  477. srcptr += JPC_QMFB_COLGRPSIZE;
  478. }
  479. }
  480. #if !defined(HAVE_VLA)
  481. /* If the split buffer was allocated on the heap, free this memory. */
  482. if (buf != splitbuf) {
  483. jas_free(buf);
  484. }
  485. #endif
  486. }
  487. void jpc_qmfb_split_colres(jpc_fix_t *a, int numrows, int numcols,
  488. int stride, int parity)
  489. {
  490. int bufsize = JPC_CEILDIVPOW2(numrows, 1);
  491. #if !defined(HAVE_VLA)
  492. jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE * JPC_QMFB_COLGRPSIZE];
  493. #else
  494. jpc_fix_t splitbuf[bufsize * numcols];
  495. #endif
  496. jpc_fix_t *buf = splitbuf;
  497. jpc_fix_t *srcptr;
  498. jpc_fix_t *dstptr;
  499. register jpc_fix_t *srcptr2;
  500. register jpc_fix_t *dstptr2;
  501. register int n;
  502. register int i;
  503. int m;
  504. int hstartcol;
  505. #if !defined(HAVE_VLA)
  506. /* Get a buffer. */
  507. if (bufsize > QMFB_SPLITBUFSIZE) {
  508. if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
  509. /* We have no choice but to commit suicide in this case. */
  510. abort();
  511. }
  512. }
  513. #endif
  514. if (numrows >= 2) {
  515. hstartcol = (numrows + 1 - parity) >> 1;
  516. m = (parity) ? hstartcol : (numrows - hstartcol);
  517. /* Save the samples destined for the highpass channel. */
  518. n = m;
  519. dstptr = buf;
  520. srcptr = &a[(1 - parity) * stride];
  521. while (n-- > 0) {
  522. dstptr2 = dstptr;
  523. srcptr2 = srcptr;
  524. for (i = 0; i < numcols; ++i) {
  525. *dstptr2 = *srcptr2;
  526. ++dstptr2;
  527. ++srcptr2;
  528. }
  529. dstptr += numcols;
  530. srcptr += stride << 1;
  531. }
  532. /* Copy the appropriate samples into the lowpass channel. */
  533. dstptr = &a[(1 - parity) * stride];
  534. srcptr = &a[(2 - parity) * stride];
  535. n = numrows - m - (!parity);
  536. while (n-- > 0) {
  537. dstptr2 = dstptr;
  538. srcptr2 = srcptr;
  539. for (i = 0; i < numcols; ++i) {
  540. *dstptr2 = *srcptr2;
  541. ++dstptr2;
  542. ++srcptr2;
  543. }
  544. dstptr += stride;
  545. srcptr += stride << 1;
  546. }
  547. /* Copy the saved samples into the highpass channel. */
  548. dstptr = &a[hstartcol * stride];
  549. srcptr = buf;
  550. n = m;
  551. while (n-- > 0) {
  552. dstptr2 = dstptr;
  553. srcptr2 = srcptr;
  554. for (i = 0; i < numcols; ++i) {
  555. *dstptr2 = *srcptr2;
  556. ++dstptr2;
  557. ++srcptr2;
  558. }
  559. dstptr += stride;
  560. srcptr += numcols;
  561. }
  562. }
  563. #if !defined(HAVE_VLA)
  564. /* If the split buffer was allocated on the heap, free this memory. */
  565. if (buf != splitbuf) {
  566. jas_free(buf);
  567. }
  568. #endif
  569. }
  570. void jpc_qmfb_join_row(jpc_fix_t *a, int numcols, int parity)
  571. {
  572. int bufsize = JPC_CEILDIVPOW2(numcols, 1);
  573. #if !defined(HAVE_VLA)
  574. jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
  575. #else
  576. jpc_fix_t joinbuf[bufsize];
  577. #endif
  578. jpc_fix_t *buf = joinbuf;
  579. register jpc_fix_t *srcptr;
  580. register jpc_fix_t *dstptr;
  581. register int n;
  582. int hstartcol;
  583. #if !defined(HAVE_VLA)
  584. /* Allocate memory for the join buffer from the heap. */
  585. if (bufsize > QMFB_JOINBUFSIZE) {
  586. if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
  587. /* We have no choice but to commit suicide. */
  588. abort();
  589. }
  590. }
  591. #endif
  592. hstartcol = (numcols + 1 - parity) >> 1;
  593. /* Save the samples from the lowpass channel. */
  594. n = hstartcol;
  595. srcptr = &a[0];
  596. dstptr = buf;
  597. while (n-- > 0) {
  598. *dstptr = *srcptr;
  599. ++srcptr;
  600. ++dstptr;
  601. }
  602. /* Copy the samples from the highpass channel into place. */
  603. srcptr = &a[hstartcol];
  604. dstptr = &a[1 - parity];
  605. n = numcols - hstartcol;
  606. while (n-- > 0) {
  607. *dstptr = *srcptr;
  608. dstptr += 2;
  609. ++srcptr;
  610. }
  611. /* Copy the samples from the lowpass channel into place. */
  612. srcptr = buf;
  613. dstptr = &a[parity];
  614. n = hstartcol;
  615. while (n-- > 0) {
  616. *dstptr = *srcptr;
  617. dstptr += 2;
  618. ++srcptr;
  619. }
  620. #if !defined(HAVE_VLA)
  621. /* If the join buffer was allocated on the heap, free this memory. */
  622. if (buf != joinbuf) {
  623. jas_free(buf);
  624. }
  625. #endif
  626. }
  627. void jpc_qmfb_join_col(jpc_fix_t *a, int numrows, int stride,
  628. int parity)
  629. {
  630. int bufsize = JPC_CEILDIVPOW2(numrows, 1);
  631. #if !defined(HAVE_VLA)
  632. jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
  633. #else
  634. jpc_fix_t joinbuf[bufsize];
  635. #endif
  636. jpc_fix_t *buf = joinbuf;
  637. register jpc_fix_t *srcptr;
  638. register jpc_fix_t *dstptr;
  639. register int n;
  640. int hstartcol;
  641. #if !defined(HAVE_VLA)
  642. /* Allocate memory for the join buffer from the heap. */
  643. if (bufsize > QMFB_JOINBUFSIZE) {
  644. if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
  645. /* We have no choice but to commit suicide. */
  646. abort();
  647. }
  648. }
  649. #endif
  650. hstartcol = (numrows + 1 - parity) >> 1;
  651. /* Save the samples from the lowpass channel. */
  652. n = hstartcol;
  653. srcptr = &a[0];
  654. dstptr = buf;
  655. while (n-- > 0) {
  656. *dstptr = *srcptr;
  657. srcptr += stride;
  658. ++dstptr;
  659. }
  660. /* Copy the samples from the highpass channel into place. */
  661. srcptr = &a[hstartcol * stride];
  662. dstptr = &a[(1 - parity) * stride];
  663. n = numrows - hstartcol;
  664. while (n-- > 0) {
  665. *dstptr = *srcptr;
  666. dstptr += 2 * stride;
  667. srcptr += stride;
  668. }
  669. /* Copy the samples from the lowpass channel into place. */
  670. srcptr = buf;
  671. dstptr = &a[parity * stride];
  672. n = hstartcol;
  673. while (n-- > 0) {
  674. *dstptr = *srcptr;
  675. dstptr += 2 * stride;
  676. ++srcptr;
  677. }
  678. #if !defined(HAVE_VLA)
  679. /* If the join buffer was allocated on the heap, free this memory. */
  680. if (buf != joinbuf) {
  681. jas_free(buf);
  682. }
  683. #endif
  684. }
  685. void jpc_qmfb_join_colgrp(jpc_fix_t *a, int numrows, int stride,
  686. int parity)
  687. {
  688. int bufsize = JPC_CEILDIVPOW2(numrows, 1);
  689. #if !defined(HAVE_VLA)
  690. jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
  691. #else
  692. jpc_fix_t joinbuf[bufsize * JPC_QMFB_COLGRPSIZE];
  693. #endif
  694. jpc_fix_t *buf = joinbuf;
  695. jpc_fix_t *srcptr;
  696. jpc_fix_t *dstptr;
  697. register jpc_fix_t *srcptr2;
  698. register jpc_fix_t *dstptr2;
  699. register int n;
  700. register int i;
  701. int hstartcol;
  702. #if !defined(HAVE_VLA)
  703. /* Allocate memory for the join buffer from the heap. */
  704. if (bufsize > QMFB_JOINBUFSIZE) {
  705. if (!(buf = jas_alloc2(bufsize, JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) {
  706. /* We have no choice but to commit suicide. */
  707. abort();
  708. }
  709. }
  710. #endif
  711. hstartcol = (numrows + 1 - parity) >> 1;
  712. /* Save the samples from the lowpass channel. */
  713. n = hstartcol;
  714. srcptr = &a[0];
  715. dstptr = buf;
  716. while (n-- > 0) {
  717. dstptr2 = dstptr;
  718. srcptr2 = srcptr;
  719. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  720. *dstptr2 = *srcptr2;
  721. ++dstptr2;
  722. ++srcptr2;
  723. }
  724. srcptr += stride;
  725. dstptr += JPC_QMFB_COLGRPSIZE;
  726. }
  727. /* Copy the samples from the highpass channel into place. */
  728. srcptr = &a[hstartcol * stride];
  729. dstptr = &a[(1 - parity) * stride];
  730. n = numrows - hstartcol;
  731. while (n-- > 0) {
  732. dstptr2 = dstptr;
  733. srcptr2 = srcptr;
  734. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  735. *dstptr2 = *srcptr2;
  736. ++dstptr2;
  737. ++srcptr2;
  738. }
  739. dstptr += 2 * stride;
  740. srcptr += stride;
  741. }
  742. /* Copy the samples from the lowpass channel into place. */
  743. srcptr = buf;
  744. dstptr = &a[parity * stride];
  745. n = hstartcol;
  746. while (n-- > 0) {
  747. dstptr2 = dstptr;
  748. srcptr2 = srcptr;
  749. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  750. *dstptr2 = *srcptr2;
  751. ++dstptr2;
  752. ++srcptr2;
  753. }
  754. dstptr += 2 * stride;
  755. srcptr += JPC_QMFB_COLGRPSIZE;
  756. }
  757. #if !defined(HAVE_VLA)
  758. /* If the join buffer was allocated on the heap, free this memory. */
  759. if (buf != joinbuf) {
  760. jas_free(buf);
  761. }
  762. #endif
  763. }
  764. void jpc_qmfb_join_colres(jpc_fix_t *a, int numrows, int numcols,
  765. int stride, int parity)
  766. {
  767. int bufsize = JPC_CEILDIVPOW2(numrows, 1);
  768. #if !defined(HAVE_VLA)
  769. jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
  770. #else
  771. jpc_fix_t joinbuf[bufsize * numcols];
  772. #endif
  773. jpc_fix_t *buf = joinbuf;
  774. jpc_fix_t *srcptr;
  775. jpc_fix_t *dstptr;
  776. register jpc_fix_t *srcptr2;
  777. register jpc_fix_t *dstptr2;
  778. register int n;
  779. register int i;
  780. int hstartcol;
  781. #if !defined(HAVE_VLA)
  782. /* Allocate memory for the join buffer from the heap. */
  783. if (bufsize > QMFB_JOINBUFSIZE) {
  784. if (!(buf = jas_alloc3(bufsize, numcols, sizeof(jpc_fix_t)))) {
  785. /* We have no choice but to commit suicide. */
  786. abort();
  787. }
  788. }
  789. #endif
  790. hstartcol = (numrows + 1 - parity) >> 1;
  791. /* Save the samples from the lowpass channel. */
  792. n = hstartcol;
  793. srcptr = &a[0];
  794. dstptr = buf;
  795. while (n-- > 0) {
  796. dstptr2 = dstptr;
  797. srcptr2 = srcptr;
  798. for (i = 0; i < numcols; ++i) {
  799. *dstptr2 = *srcptr2;
  800. ++dstptr2;
  801. ++srcptr2;
  802. }
  803. srcptr += stride;
  804. dstptr += numcols;
  805. }
  806. /* Copy the samples from the highpass channel into place. */
  807. srcptr = &a[hstartcol * stride];
  808. dstptr = &a[(1 - parity) * stride];
  809. n = numrows - hstartcol;
  810. while (n-- > 0) {
  811. dstptr2 = dstptr;
  812. srcptr2 = srcptr;
  813. for (i = 0; i < numcols; ++i) {
  814. *dstptr2 = *srcptr2;
  815. ++dstptr2;
  816. ++srcptr2;
  817. }
  818. dstptr += 2 * stride;
  819. srcptr += stride;
  820. }
  821. /* Copy the samples from the lowpass channel into place. */
  822. srcptr = buf;
  823. dstptr = &a[parity * stride];
  824. n = hstartcol;
  825. while (n-- > 0) {
  826. dstptr2 = dstptr;
  827. srcptr2 = srcptr;
  828. for (i = 0; i < numcols; ++i) {
  829. *dstptr2 = *srcptr2;
  830. ++dstptr2;
  831. ++srcptr2;
  832. }
  833. dstptr += 2 * stride;
  834. srcptr += numcols;
  835. }
  836. #if !defined(HAVE_VLA)
  837. /* If the join buffer was allocated on the heap, free this memory. */
  838. if (buf != joinbuf) {
  839. jas_free(buf);
  840. }
  841. #endif
  842. }
  843. /******************************************************************************\
  844. * 5/3 transform
  845. \******************************************************************************/
  846. void jpc_ft_fwdlift_row(jpc_fix_t *a, int numcols, int parity)
  847. {
  848. register jpc_fix_t *lptr;
  849. register jpc_fix_t *hptr;
  850. register int n;
  851. int llen;
  852. llen = (numcols + 1 - parity) >> 1;
  853. if (numcols > 1) {
  854. /* Apply the first lifting step. */
  855. lptr = &a[0];
  856. hptr = &a[llen];
  857. if (parity) {
  858. hptr[0] -= lptr[0];
  859. ++hptr;
  860. }
  861. n = numcols - llen - parity - (parity == (numcols & 1));
  862. while (n-- > 0) {
  863. hptr[0] -= (lptr[0] + lptr[1]) >> 1;
  864. ++hptr;
  865. ++lptr;
  866. }
  867. if (parity == (numcols & 1)) {
  868. hptr[0] -= lptr[0];
  869. }
  870. /* Apply the second lifting step. */
  871. lptr = &a[0];
  872. hptr = &a[llen];
  873. if (!parity) {
  874. lptr[0] += (hptr[0] + 1) >> 1;
  875. ++lptr;
  876. }
  877. n = llen - (!parity) - (parity != (numcols & 1));
  878. while (n-- > 0) {
  879. lptr[0] += (hptr[0] + hptr[1] + 2) >> 2;
  880. ++lptr;
  881. ++hptr;
  882. }
  883. if (parity != (numcols & 1)) {
  884. lptr[0] += (hptr[0] + 1) >> 1;
  885. }
  886. } else {
  887. if (parity) {
  888. lptr = &a[0];
  889. lptr[0] <<= 1;
  890. }
  891. }
  892. }
  893. void jpc_ft_fwdlift_col(jpc_fix_t *a, int numrows, int stride, int parity)
  894. {
  895. jpc_fix_t *lptr;
  896. jpc_fix_t *hptr;
  897. #if 0
  898. register jpc_fix_t *lptr2;
  899. register jpc_fix_t *hptr2;
  900. register int i;
  901. #endif
  902. register int n;
  903. int llen;
  904. llen = (numrows + 1 - parity) >> 1;
  905. if (numrows > 1) {
  906. /* Apply the first lifting step. */
  907. lptr = &a[0];
  908. hptr = &a[llen * stride];
  909. if (parity) {
  910. hptr[0] -= lptr[0];
  911. hptr += stride;
  912. }
  913. n = numrows - llen - parity - (parity == (numrows & 1));
  914. while (n-- > 0) {
  915. hptr[0] -= (lptr[0] + lptr[stride]) >> 1;
  916. hptr += stride;
  917. lptr += stride;
  918. }
  919. if (parity == (numrows & 1)) {
  920. hptr[0] -= lptr[0];
  921. }
  922. /* Apply the second lifting step. */
  923. lptr = &a[0];
  924. hptr = &a[llen * stride];
  925. if (!parity) {
  926. lptr[0] += (hptr[0] + 1) >> 1;
  927. lptr += stride;
  928. }
  929. n = llen - (!parity) - (parity != (numrows & 1));
  930. while (n-- > 0) {
  931. lptr[0] += (hptr[0] + hptr[stride] + 2) >> 2;
  932. lptr += stride;
  933. hptr += stride;
  934. }
  935. if (parity != (numrows & 1)) {
  936. lptr[0] += (hptr[0] + 1) >> 1;
  937. }
  938. } else {
  939. if (parity) {
  940. lptr = &a[0];
  941. lptr[0] <<= 1;
  942. }
  943. }
  944. }
  945. void jpc_ft_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity)
  946. {
  947. jpc_fix_t *lptr;
  948. jpc_fix_t *hptr;
  949. register jpc_fix_t *lptr2;
  950. register jpc_fix_t *hptr2;
  951. register int n;
  952. register int i;
  953. int llen;
  954. llen = (numrows + 1 - parity) >> 1;
  955. if (numrows > 1) {
  956. /* Apply the first lifting step. */
  957. lptr = &a[0];
  958. hptr = &a[llen * stride];
  959. if (parity) {
  960. lptr2 = lptr;
  961. hptr2 = hptr;
  962. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  963. hptr2[0] -= lptr2[0];
  964. ++hptr2;
  965. ++lptr2;
  966. }
  967. hptr += stride;
  968. }
  969. n = numrows - llen - parity - (parity == (numrows & 1));
  970. while (n-- > 0) {
  971. lptr2 = lptr;
  972. hptr2 = hptr;
  973. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  974. hptr2[0] -= (lptr2[0] + lptr2[stride]) >> 1;
  975. ++lptr2;
  976. ++hptr2;
  977. }
  978. hptr += stride;
  979. lptr += stride;
  980. }
  981. if (parity == (numrows & 1)) {
  982. lptr2 = lptr;
  983. hptr2 = hptr;
  984. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  985. hptr2[0] -= lptr2[0];
  986. ++lptr2;
  987. ++hptr2;
  988. }
  989. }
  990. /* Apply the second lifting step. */
  991. lptr = &a[0];
  992. hptr = &a[llen * stride];
  993. if (!parity) {
  994. lptr2 = lptr;
  995. hptr2 = hptr;
  996. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  997. lptr2[0] += (hptr2[0] + 1) >> 1;
  998. ++lptr2;
  999. ++hptr2;
  1000. }
  1001. lptr += stride;
  1002. }
  1003. n = llen - (!parity) - (parity != (numrows & 1));
  1004. while (n-- > 0) {
  1005. lptr2 = lptr;
  1006. hptr2 = hptr;
  1007. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1008. lptr2[0] += (hptr2[0] + hptr2[stride] + 2) >> 2;
  1009. ++lptr2;
  1010. ++hptr2;
  1011. }
  1012. lptr += stride;
  1013. hptr += stride;
  1014. }
  1015. if (parity != (numrows & 1)) {
  1016. lptr2 = lptr;
  1017. hptr2 = hptr;
  1018. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1019. lptr2[0] += (hptr2[0] + 1) >> 1;
  1020. ++lptr2;
  1021. ++hptr2;
  1022. }
  1023. }
  1024. } else {
  1025. if (parity) {
  1026. lptr2 = &a[0];
  1027. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1028. lptr2[0] <<= 1;
  1029. ++lptr2;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. void jpc_ft_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
  1035. int parity)
  1036. {
  1037. jpc_fix_t *lptr;
  1038. jpc_fix_t *hptr;
  1039. register jpc_fix_t *lptr2;
  1040. register jpc_fix_t *hptr2;
  1041. register int n;
  1042. register int i;
  1043. int llen;
  1044. llen = (numrows + 1 - parity) >> 1;
  1045. if (numrows > 1) {
  1046. /* Apply the first lifting step. */
  1047. lptr = &a[0];
  1048. hptr = &a[llen * stride];
  1049. if (parity) {
  1050. lptr2 = lptr;
  1051. hptr2 = hptr;
  1052. for (i = 0; i < numcols; ++i) {
  1053. hptr2[0] -= lptr2[0];
  1054. ++hptr2;
  1055. ++lptr2;
  1056. }
  1057. hptr += stride;
  1058. }
  1059. n = numrows - llen - parity - (parity == (numrows & 1));
  1060. while (n-- > 0) {
  1061. lptr2 = lptr;
  1062. hptr2 = hptr;
  1063. for (i = 0; i < numcols; ++i) {
  1064. hptr2[0] -= (lptr2[0] + lptr2[stride]) >> 1;
  1065. ++lptr2;
  1066. ++hptr2;
  1067. }
  1068. hptr += stride;
  1069. lptr += stride;
  1070. }
  1071. if (parity == (numrows & 1)) {
  1072. lptr2 = lptr;
  1073. hptr2 = hptr;
  1074. for (i = 0; i < numcols; ++i) {
  1075. hptr2[0] -= lptr2[0];
  1076. ++lptr2;
  1077. ++hptr2;
  1078. }
  1079. }
  1080. /* Apply the second lifting step. */
  1081. lptr = &a[0];
  1082. hptr = &a[llen * stride];
  1083. if (!parity) {
  1084. lptr2 = lptr;
  1085. hptr2 = hptr;
  1086. for (i = 0; i < numcols; ++i) {
  1087. lptr2[0] += (hptr2[0] + 1) >> 1;
  1088. ++lptr2;
  1089. ++hptr2;
  1090. }
  1091. lptr += stride;
  1092. }
  1093. n = llen - (!parity) - (parity != (numrows & 1));
  1094. while (n-- > 0) {
  1095. lptr2 = lptr;
  1096. hptr2 = hptr;
  1097. for (i = 0; i < numcols; ++i) {
  1098. lptr2[0] += (hptr2[0] + hptr2[stride] + 2) >> 2;
  1099. ++lptr2;
  1100. ++hptr2;
  1101. }
  1102. lptr += stride;
  1103. hptr += stride;
  1104. }
  1105. if (parity != (numrows & 1)) {
  1106. lptr2 = lptr;
  1107. hptr2 = hptr;
  1108. for (i = 0; i < numcols; ++i) {
  1109. lptr2[0] += (hptr2[0] + 1) >> 1;
  1110. ++lptr2;
  1111. ++hptr2;
  1112. }
  1113. }
  1114. } else {
  1115. if (parity) {
  1116. lptr2 = &a[0];
  1117. for (i = 0; i < numcols; ++i) {
  1118. lptr2[0] <<= 1;
  1119. ++lptr2;
  1120. }
  1121. }
  1122. }
  1123. }
  1124. void jpc_ft_invlift_row(jpc_fix_t *a, int numcols, int parity)
  1125. {
  1126. register jpc_fix_t *lptr;
  1127. register jpc_fix_t *hptr;
  1128. register int n;
  1129. int llen;
  1130. llen = (numcols + 1 - parity) >> 1;
  1131. if (numcols > 1) {
  1132. /* Apply the first lifting step. */
  1133. lptr = &a[0];
  1134. hptr = &a[llen];
  1135. if (!parity) {
  1136. lptr[0] -= (hptr[0] + 1) >> 1;
  1137. ++lptr;
  1138. }
  1139. n = llen - (!parity) - (parity != (numcols & 1));
  1140. while (n-- > 0) {
  1141. lptr[0] -= (hptr[0] + hptr[1] + 2) >> 2;
  1142. ++lptr;
  1143. ++hptr;
  1144. }
  1145. if (parity != (numcols & 1)) {
  1146. lptr[0] -= (hptr[0] + 1) >> 1;
  1147. }
  1148. /* Apply the second lifting step. */
  1149. lptr = &a[0];
  1150. hptr = &a[llen];
  1151. if (parity) {
  1152. hptr[0] += lptr[0];
  1153. ++hptr;
  1154. }
  1155. n = numcols - llen - parity - (parity == (numcols & 1));
  1156. while (n-- > 0) {
  1157. hptr[0] += (lptr[0] + lptr[1]) >> 1;
  1158. ++hptr;
  1159. ++lptr;
  1160. }
  1161. if (parity == (numcols & 1)) {
  1162. hptr[0] += lptr[0];
  1163. }
  1164. } else {
  1165. if (parity) {
  1166. lptr = &a[0];
  1167. lptr[0] >>= 1;
  1168. }
  1169. }
  1170. }
  1171. void jpc_ft_invlift_col(jpc_fix_t *a, int numrows, int stride, int parity)
  1172. {
  1173. jpc_fix_t *lptr;
  1174. jpc_fix_t *hptr;
  1175. #if 0
  1176. register jpc_fix_t *lptr2;
  1177. register jpc_fix_t *hptr2;
  1178. register int i;
  1179. #endif
  1180. register int n;
  1181. int llen;
  1182. llen = (numrows + 1 - parity) >> 1;
  1183. if (numrows > 1) {
  1184. /* Apply the first lifting step. */
  1185. lptr = &a[0];
  1186. hptr = &a[llen * stride];
  1187. if (!parity) {
  1188. lptr[0] -= (hptr[0] + 1) >> 1;
  1189. lptr += stride;
  1190. }
  1191. n = llen - (!parity) - (parity != (numrows & 1));
  1192. while (n-- > 0) {
  1193. lptr[0] -= (hptr[0] + hptr[stride] + 2) >> 2;
  1194. lptr += stride;
  1195. hptr += stride;
  1196. }
  1197. if (parity != (numrows & 1)) {
  1198. lptr[0] -= (hptr[0] + 1) >> 1;
  1199. }
  1200. /* Apply the second lifting step. */
  1201. lptr = &a[0];
  1202. hptr = &a[llen * stride];
  1203. if (parity) {
  1204. hptr[0] += lptr[0];
  1205. hptr += stride;
  1206. }
  1207. n = numrows - llen - parity - (parity == (numrows & 1));
  1208. while (n-- > 0) {
  1209. hptr[0] += (lptr[0] + lptr[stride]) >> 1;
  1210. hptr += stride;
  1211. lptr += stride;
  1212. }
  1213. if (parity == (numrows & 1)) {
  1214. hptr[0] += lptr[0];
  1215. }
  1216. } else {
  1217. if (parity) {
  1218. lptr = &a[0];
  1219. lptr[0] >>= 1;
  1220. }
  1221. }
  1222. }
  1223. void jpc_ft_invlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity)
  1224. {
  1225. jpc_fix_t *lptr;
  1226. jpc_fix_t *hptr;
  1227. register jpc_fix_t *lptr2;
  1228. register jpc_fix_t *hptr2;
  1229. register int n;
  1230. register int i;
  1231. int llen;
  1232. llen = (numrows + 1 - parity) >> 1;
  1233. if (numrows > 1) {
  1234. /* Apply the first lifting step. */
  1235. lptr = &a[0];
  1236. hptr = &a[llen * stride];
  1237. if (!parity) {
  1238. lptr2 = lptr;
  1239. hptr2 = hptr;
  1240. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1241. lptr2[0] -= (hptr2[0] + 1) >> 1;
  1242. ++lptr2;
  1243. ++hptr2;
  1244. }
  1245. lptr += stride;
  1246. }
  1247. n = llen - (!parity) - (parity != (numrows & 1));
  1248. while (n-- > 0) {
  1249. lptr2 = lptr;
  1250. hptr2 = hptr;
  1251. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1252. lptr2[0] -= (hptr2[0] + hptr2[stride] + 2) >> 2;
  1253. ++lptr2;
  1254. ++hptr2;
  1255. }
  1256. lptr += stride;
  1257. hptr += stride;
  1258. }
  1259. if (parity != (numrows & 1)) {
  1260. lptr2 = lptr;
  1261. hptr2 = hptr;
  1262. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1263. lptr2[0] -= (hptr2[0] + 1) >> 1;
  1264. ++lptr2;
  1265. ++hptr2;
  1266. }
  1267. }
  1268. /* Apply the second lifting step. */
  1269. lptr = &a[0];
  1270. hptr = &a[llen * stride];
  1271. if (parity) {
  1272. lptr2 = lptr;
  1273. hptr2 = hptr;
  1274. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1275. hptr2[0] += lptr2[0];
  1276. ++hptr2;
  1277. ++lptr2;
  1278. }
  1279. hptr += stride;
  1280. }
  1281. n = numrows - llen - parity - (parity == (numrows & 1));
  1282. while (n-- > 0) {
  1283. lptr2 = lptr;
  1284. hptr2 = hptr;
  1285. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1286. hptr2[0] += (lptr2[0] + lptr2[stride]) >> 1;
  1287. ++lptr2;
  1288. ++hptr2;
  1289. }
  1290. hptr += stride;
  1291. lptr += stride;
  1292. }
  1293. if (parity == (numrows & 1)) {
  1294. lptr2 = lptr;
  1295. hptr2 = hptr;
  1296. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1297. hptr2[0] += lptr2[0];
  1298. ++lptr2;
  1299. ++hptr2;
  1300. }
  1301. }
  1302. } else {
  1303. if (parity) {
  1304. lptr2 = &a[0];
  1305. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1306. lptr2[0] >>= 1;
  1307. ++lptr2;
  1308. }
  1309. }
  1310. }
  1311. }
  1312. void jpc_ft_invlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
  1313. int parity)
  1314. {
  1315. jpc_fix_t *lptr;
  1316. jpc_fix_t *hptr;
  1317. register jpc_fix_t *lptr2;
  1318. register jpc_fix_t *hptr2;
  1319. register int n;
  1320. register int i;
  1321. int llen;
  1322. llen = (numrows + 1 - parity) >> 1;
  1323. if (numrows > 1) {
  1324. /* Apply the first lifting step. */
  1325. lptr = &a[0];
  1326. hptr = &a[llen * stride];
  1327. if (!parity) {
  1328. lptr2 = lptr;
  1329. hptr2 = hptr;
  1330. for (i = 0; i < numcols; ++i) {
  1331. lptr2[0] -= (hptr2[0] + 1) >> 1;
  1332. ++lptr2;
  1333. ++hptr2;
  1334. }
  1335. lptr += stride;
  1336. }
  1337. n = llen - (!parity) - (parity != (numrows & 1));
  1338. while (n-- > 0) {
  1339. lptr2 = lptr;
  1340. hptr2 = hptr;
  1341. for (i = 0; i < numcols; ++i) {
  1342. lptr2[0] -= (hptr2[0] + hptr2[stride] + 2) >> 2;
  1343. ++lptr2;
  1344. ++hptr2;
  1345. }
  1346. lptr += stride;
  1347. hptr += stride;
  1348. }
  1349. if (parity != (numrows & 1)) {
  1350. lptr2 = lptr;
  1351. hptr2 = hptr;
  1352. for (i = 0; i < numcols; ++i) {
  1353. lptr2[0] -= (hptr2[0] + 1) >> 1;
  1354. ++lptr2;
  1355. ++hptr2;
  1356. }
  1357. }
  1358. /* Apply the second lifting step. */
  1359. lptr = &a[0];
  1360. hptr = &a[llen * stride];
  1361. if (parity) {
  1362. lptr2 = lptr;
  1363. hptr2 = hptr;
  1364. for (i = 0; i < numcols; ++i) {
  1365. hptr2[0] += lptr2[0];
  1366. ++hptr2;
  1367. ++lptr2;
  1368. }
  1369. hptr += stride;
  1370. }
  1371. n = numrows - llen - parity - (parity == (numrows & 1));
  1372. while (n-- > 0) {
  1373. lptr2 = lptr;
  1374. hptr2 = hptr;
  1375. for (i = 0; i < numcols; ++i) {
  1376. hptr2[0] += (lptr2[0] + lptr2[stride]) >> 1;
  1377. ++lptr2;
  1378. ++hptr2;
  1379. }
  1380. hptr += stride;
  1381. lptr += stride;
  1382. }
  1383. if (parity == (numrows & 1)) {
  1384. lptr2 = lptr;
  1385. hptr2 = hptr;
  1386. for (i = 0; i < numcols; ++i) {
  1387. hptr2[0] += lptr2[0];
  1388. ++lptr2;
  1389. ++hptr2;
  1390. }
  1391. }
  1392. } else {
  1393. if (parity) {
  1394. lptr2 = &a[0];
  1395. for (i = 0; i < numcols; ++i) {
  1396. lptr2[0] >>= 1;
  1397. ++lptr2;
  1398. }
  1399. }
  1400. }
  1401. }
  1402. int jpc_ft_analyze(int *a, int xstart, int ystart, int width, int height,
  1403. int stride)
  1404. {
  1405. int numrows = height;
  1406. int numcols = width;
  1407. int rowparity = ystart & 1;
  1408. int colparity = xstart & 1;
  1409. int i;
  1410. jpc_fix_t *startptr;
  1411. int maxcols;
  1412. maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
  1413. startptr = (jpc_fix_t*)&a[0];
  1414. for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
  1415. jpc_qmfb_split_colgrp(startptr, numrows, stride, rowparity);
  1416. jpc_ft_fwdlift_colgrp(startptr, numrows, stride, rowparity);
  1417. startptr += JPC_QMFB_COLGRPSIZE;
  1418. }
  1419. if (maxcols < numcols) {
  1420. jpc_qmfb_split_colres(startptr, numrows, numcols - maxcols, stride,
  1421. rowparity);
  1422. jpc_ft_fwdlift_colres(startptr, numrows, numcols - maxcols, stride,
  1423. rowparity);
  1424. }
  1425. startptr = (jpc_fix_t*)&a[0];
  1426. for (i = 0; i < numrows; ++i) {
  1427. jpc_qmfb_split_row(startptr, numcols, colparity);
  1428. jpc_ft_fwdlift_row(startptr, numcols, colparity);
  1429. startptr += stride;
  1430. }
  1431. return 0;
  1432. }
  1433. int jpc_ft_synthesize(int *a, int xstart, int ystart, int width, int height,
  1434. int stride)
  1435. {
  1436. int numrows = height;
  1437. int numcols = width;
  1438. int rowparity = ystart & 1;
  1439. int colparity = xstart & 1;
  1440. int maxcols;
  1441. jpc_fix_t *startptr;
  1442. int i;
  1443. startptr = (jpc_fix_t*)&a[0];
  1444. for (i = 0; i < numrows; ++i) {
  1445. jpc_ft_invlift_row(startptr, numcols, colparity);
  1446. jpc_qmfb_join_row(startptr, numcols, colparity);
  1447. startptr += stride;
  1448. }
  1449. maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
  1450. startptr = (jpc_fix_t*)&a[0];
  1451. for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
  1452. jpc_ft_invlift_colgrp(startptr, numrows, stride, rowparity);
  1453. jpc_qmfb_join_colgrp(startptr, numrows, stride, rowparity);
  1454. startptr += JPC_QMFB_COLGRPSIZE;
  1455. }
  1456. if (maxcols < numcols) {
  1457. jpc_ft_invlift_colres(startptr, numrows, numcols - maxcols, stride,
  1458. rowparity);
  1459. jpc_qmfb_join_colres(startptr, numrows, numcols - maxcols, stride,
  1460. rowparity);
  1461. }
  1462. return 0;
  1463. }
  1464. /******************************************************************************\
  1465. * 9/7 transform
  1466. \******************************************************************************/
  1467. #define ALPHA (-1.586134342059924)
  1468. #define BETA (-0.052980118572961)
  1469. #define GAMMA (0.882911075530934)
  1470. #define DELTA (0.443506852043971)
  1471. #define LGAIN (1.0 / 1.23017410558578)
  1472. #define HGAIN (1.0 / 1.62578613134411)
  1473. void jpc_ns_fwdlift_row(jpc_fix_t *a, int numcols, int parity)
  1474. {
  1475. register jpc_fix_t *lptr;
  1476. register jpc_fix_t *hptr;
  1477. register int n;
  1478. int llen;
  1479. llen = (numcols + 1 - parity) >> 1;
  1480. if (numcols > 1) {
  1481. /* Apply the first lifting step. */
  1482. lptr = &a[0];
  1483. hptr = &a[llen];
  1484. if (parity) {
  1485. jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  1486. lptr[0]));
  1487. ++hptr;
  1488. }
  1489. n = numcols - llen - parity - (parity == (numcols & 1));
  1490. while (n-- > 0) {
  1491. jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
  1492. jpc_fix_add(lptr[0], lptr[1])));
  1493. ++hptr;
  1494. ++lptr;
  1495. }
  1496. if (parity == (numcols & 1)) {
  1497. jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  1498. lptr[0]));
  1499. }
  1500. /* Apply the second lifting step. */
  1501. lptr = &a[0];
  1502. hptr = &a[llen];
  1503. if (!parity) {
  1504. jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  1505. hptr[0]));
  1506. ++lptr;
  1507. }
  1508. n = llen - (!parity) - (parity != (numcols & 1));
  1509. while (n-- > 0) {
  1510. jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(BETA),
  1511. jpc_fix_add(hptr[0], hptr[1])));
  1512. ++lptr;
  1513. ++hptr;
  1514. }
  1515. if (parity != (numcols & 1)) {
  1516. jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  1517. hptr[0]));
  1518. }
  1519. /* Apply the third lifting step. */
  1520. lptr = &a[0];
  1521. hptr = &a[llen];
  1522. if (parity) {
  1523. jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  1524. lptr[0]));
  1525. ++hptr;
  1526. }
  1527. n = numcols - llen - parity - (parity == (numcols & 1));
  1528. while (n-- > 0) {
  1529. jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
  1530. jpc_fix_add(lptr[0], lptr[1])));
  1531. ++hptr;
  1532. ++lptr;
  1533. }
  1534. if (parity == (numcols & 1)) {
  1535. jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  1536. lptr[0]));
  1537. }
  1538. /* Apply the fourth lifting step. */
  1539. lptr = &a[0];
  1540. hptr = &a[llen];
  1541. if (!parity) {
  1542. jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  1543. hptr[0]));
  1544. ++lptr;
  1545. }
  1546. n = llen - (!parity) - (parity != (numcols & 1));
  1547. while (n-- > 0) {
  1548. jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(DELTA),
  1549. jpc_fix_add(hptr[0], hptr[1])));
  1550. ++lptr;
  1551. ++hptr;
  1552. }
  1553. if (parity != (numcols & 1)) {
  1554. jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  1555. hptr[0]));
  1556. }
  1557. /* Apply the scaling step. */
  1558. #if defined(WT_DOSCALE)
  1559. lptr = &a[0];
  1560. n = llen;
  1561. while (n-- > 0) {
  1562. lptr[0] = jpc_fix_mul(lptr[0], jpc_dbltofix(LGAIN));
  1563. ++lptr;
  1564. }
  1565. hptr = &a[llen];
  1566. n = numcols - llen;
  1567. while (n-- > 0) {
  1568. hptr[0] = jpc_fix_mul(hptr[0], jpc_dbltofix(HGAIN));
  1569. ++hptr;
  1570. }
  1571. #endif
  1572. } else {
  1573. #if defined(WT_LENONE)
  1574. if (parity) {
  1575. lptr = &a[0];
  1576. lptr[0] <<= 1;
  1577. }
  1578. #endif
  1579. }
  1580. }
  1581. void jpc_ns_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride,
  1582. int parity)
  1583. {
  1584. jpc_fix_t *lptr;
  1585. jpc_fix_t *hptr;
  1586. register jpc_fix_t *lptr2;
  1587. register jpc_fix_t *hptr2;
  1588. register int n;
  1589. register int i;
  1590. int llen;
  1591. llen = (numrows + 1 - parity) >> 1;
  1592. if (numrows > 1) {
  1593. /* Apply the first lifting step. */
  1594. lptr = &a[0];
  1595. hptr = &a[llen * stride];
  1596. if (parity) {
  1597. lptr2 = lptr;
  1598. hptr2 = hptr;
  1599. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1600. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  1601. lptr2[0]));
  1602. ++hptr2;
  1603. ++lptr2;
  1604. }
  1605. hptr += stride;
  1606. }
  1607. n = numrows - llen - parity - (parity == (numrows & 1));
  1608. while (n-- > 0) {
  1609. lptr2 = lptr;
  1610. hptr2 = hptr;
  1611. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1612. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
  1613. jpc_fix_add(lptr2[0], lptr2[stride])));
  1614. ++lptr2;
  1615. ++hptr2;
  1616. }
  1617. hptr += stride;
  1618. lptr += stride;
  1619. }
  1620. if (parity == (numrows & 1)) {
  1621. lptr2 = lptr;
  1622. hptr2 = hptr;
  1623. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1624. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  1625. lptr2[0]));
  1626. ++lptr2;
  1627. ++hptr2;
  1628. }
  1629. }
  1630. /* Apply the second lifting step. */
  1631. lptr = &a[0];
  1632. hptr = &a[llen * stride];
  1633. if (!parity) {
  1634. lptr2 = lptr;
  1635. hptr2 = hptr;
  1636. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1637. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  1638. hptr2[0]));
  1639. ++lptr2;
  1640. ++hptr2;
  1641. }
  1642. lptr += stride;
  1643. }
  1644. n = llen - (!parity) - (parity != (numrows & 1));
  1645. while (n-- > 0) {
  1646. lptr2 = lptr;
  1647. hptr2 = hptr;
  1648. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1649. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
  1650. jpc_fix_add(hptr2[0], hptr2[stride])));
  1651. ++lptr2;
  1652. ++hptr2;
  1653. }
  1654. lptr += stride;
  1655. hptr += stride;
  1656. }
  1657. if (parity != (numrows & 1)) {
  1658. lptr2 = lptr;
  1659. hptr2 = hptr;
  1660. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1661. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  1662. hptr2[0]));
  1663. ++lptr2;
  1664. ++hptr2;
  1665. }
  1666. }
  1667. /* Apply the third lifting step. */
  1668. lptr = &a[0];
  1669. hptr = &a[llen * stride];
  1670. if (parity) {
  1671. lptr2 = lptr;
  1672. hptr2 = hptr;
  1673. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1674. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  1675. lptr2[0]));
  1676. ++hptr2;
  1677. ++lptr2;
  1678. }
  1679. hptr += stride;
  1680. }
  1681. n = numrows - llen - parity - (parity == (numrows & 1));
  1682. while (n-- > 0) {
  1683. lptr2 = lptr;
  1684. hptr2 = hptr;
  1685. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1686. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
  1687. jpc_fix_add(lptr2[0], lptr2[stride])));
  1688. ++lptr2;
  1689. ++hptr2;
  1690. }
  1691. hptr += stride;
  1692. lptr += stride;
  1693. }
  1694. if (parity == (numrows & 1)) {
  1695. lptr2 = lptr;
  1696. hptr2 = hptr;
  1697. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1698. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  1699. lptr2[0]));
  1700. ++lptr2;
  1701. ++hptr2;
  1702. }
  1703. }
  1704. /* Apply the fourth lifting step. */
  1705. lptr = &a[0];
  1706. hptr = &a[llen * stride];
  1707. if (!parity) {
  1708. lptr2 = lptr;
  1709. hptr2 = hptr;
  1710. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1711. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  1712. hptr2[0]));
  1713. ++lptr2;
  1714. ++hptr2;
  1715. }
  1716. lptr += stride;
  1717. }
  1718. n = llen - (!parity) - (parity != (numrows & 1));
  1719. while (n-- > 0) {
  1720. lptr2 = lptr;
  1721. hptr2 = hptr;
  1722. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1723. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
  1724. jpc_fix_add(hptr2[0], hptr2[stride])));
  1725. ++lptr2;
  1726. ++hptr2;
  1727. }
  1728. lptr += stride;
  1729. hptr += stride;
  1730. }
  1731. if (parity != (numrows & 1)) {
  1732. lptr2 = lptr;
  1733. hptr2 = hptr;
  1734. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1735. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  1736. hptr2[0]));
  1737. ++lptr2;
  1738. ++hptr2;
  1739. }
  1740. }
  1741. /* Apply the scaling step. */
  1742. #if defined(WT_DOSCALE)
  1743. lptr = &a[0];
  1744. n = llen;
  1745. while (n-- > 0) {
  1746. lptr2 = lptr;
  1747. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1748. lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(LGAIN));
  1749. ++lptr2;
  1750. }
  1751. lptr += stride;
  1752. }
  1753. hptr = &a[llen * stride];
  1754. n = numrows - llen;
  1755. while (n-- > 0) {
  1756. hptr2 = hptr;
  1757. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1758. hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(HGAIN));
  1759. ++hptr2;
  1760. }
  1761. hptr += stride;
  1762. }
  1763. #endif
  1764. } else {
  1765. #if defined(WT_LENONE)
  1766. if (parity) {
  1767. lptr2 = &a[0];
  1768. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  1769. lptr2[0] <<= 1;
  1770. ++lptr2;
  1771. }
  1772. }
  1773. #endif
  1774. }
  1775. }
  1776. void jpc_ns_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols,
  1777. int stride, int parity)
  1778. {
  1779. jpc_fix_t *lptr;
  1780. jpc_fix_t *hptr;
  1781. register jpc_fix_t *lptr2;
  1782. register jpc_fix_t *hptr2;
  1783. register int n;
  1784. register int i;
  1785. int llen;
  1786. llen = (numrows + 1 - parity) >> 1;
  1787. if (numrows > 1) {
  1788. /* Apply the first lifting step. */
  1789. lptr = &a[0];
  1790. hptr = &a[llen * stride];
  1791. if (parity) {
  1792. lptr2 = lptr;
  1793. hptr2 = hptr;
  1794. for (i = 0; i < numcols; ++i) {
  1795. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  1796. lptr2[0]));
  1797. ++hptr2;
  1798. ++lptr2;
  1799. }
  1800. hptr += stride;
  1801. }
  1802. n = numrows - llen - parity - (parity == (numrows & 1));
  1803. while (n-- > 0) {
  1804. lptr2 = lptr;
  1805. hptr2 = hptr;
  1806. for (i = 0; i < numcols; ++i) {
  1807. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
  1808. jpc_fix_add(lptr2[0], lptr2[stride])));
  1809. ++lptr2;
  1810. ++hptr2;
  1811. }
  1812. hptr += stride;
  1813. lptr += stride;
  1814. }
  1815. if (parity == (numrows & 1)) {
  1816. lptr2 = lptr;
  1817. hptr2 = hptr;
  1818. for (i = 0; i < numcols; ++i) {
  1819. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  1820. lptr2[0]));
  1821. ++lptr2;
  1822. ++hptr2;
  1823. }
  1824. }
  1825. /* Apply the second lifting step. */
  1826. lptr = &a[0];
  1827. hptr = &a[llen * stride];
  1828. if (!parity) {
  1829. lptr2 = lptr;
  1830. hptr2 = hptr;
  1831. for (i = 0; i < numcols; ++i) {
  1832. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  1833. hptr2[0]));
  1834. ++lptr2;
  1835. ++hptr2;
  1836. }
  1837. lptr += stride;
  1838. }
  1839. n = llen - (!parity) - (parity != (numrows & 1));
  1840. while (n-- > 0) {
  1841. lptr2 = lptr;
  1842. hptr2 = hptr;
  1843. for (i = 0; i < numcols; ++i) {
  1844. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
  1845. jpc_fix_add(hptr2[0], hptr2[stride])));
  1846. ++lptr2;
  1847. ++hptr2;
  1848. }
  1849. lptr += stride;
  1850. hptr += stride;
  1851. }
  1852. if (parity != (numrows & 1)) {
  1853. lptr2 = lptr;
  1854. hptr2 = hptr;
  1855. for (i = 0; i < numcols; ++i) {
  1856. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  1857. hptr2[0]));
  1858. ++lptr2;
  1859. ++hptr2;
  1860. }
  1861. }
  1862. /* Apply the third lifting step. */
  1863. lptr = &a[0];
  1864. hptr = &a[llen * stride];
  1865. if (parity) {
  1866. lptr2 = lptr;
  1867. hptr2 = hptr;
  1868. for (i = 0; i < numcols; ++i) {
  1869. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  1870. lptr2[0]));
  1871. ++hptr2;
  1872. ++lptr2;
  1873. }
  1874. hptr += stride;
  1875. }
  1876. n = numrows - llen - parity - (parity == (numrows & 1));
  1877. while (n-- > 0) {
  1878. lptr2 = lptr;
  1879. hptr2 = hptr;
  1880. for (i = 0; i < numcols; ++i) {
  1881. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
  1882. jpc_fix_add(lptr2[0], lptr2[stride])));
  1883. ++lptr2;
  1884. ++hptr2;
  1885. }
  1886. hptr += stride;
  1887. lptr += stride;
  1888. }
  1889. if (parity == (numrows & 1)) {
  1890. lptr2 = lptr;
  1891. hptr2 = hptr;
  1892. for (i = 0; i < numcols; ++i) {
  1893. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  1894. lptr2[0]));
  1895. ++lptr2;
  1896. ++hptr2;
  1897. }
  1898. }
  1899. /* Apply the fourth lifting step. */
  1900. lptr = &a[0];
  1901. hptr = &a[llen * stride];
  1902. if (!parity) {
  1903. lptr2 = lptr;
  1904. hptr2 = hptr;
  1905. for (i = 0; i < numcols; ++i) {
  1906. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  1907. hptr2[0]));
  1908. ++lptr2;
  1909. ++hptr2;
  1910. }
  1911. lptr += stride;
  1912. }
  1913. n = llen - (!parity) - (parity != (numrows & 1));
  1914. while (n-- > 0) {
  1915. lptr2 = lptr;
  1916. hptr2 = hptr;
  1917. for (i = 0; i < numcols; ++i) {
  1918. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
  1919. jpc_fix_add(hptr2[0], hptr2[stride])));
  1920. ++lptr2;
  1921. ++hptr2;
  1922. }
  1923. lptr += stride;
  1924. hptr += stride;
  1925. }
  1926. if (parity != (numrows & 1)) {
  1927. lptr2 = lptr;
  1928. hptr2 = hptr;
  1929. for (i = 0; i < numcols; ++i) {
  1930. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  1931. hptr2[0]));
  1932. ++lptr2;
  1933. ++hptr2;
  1934. }
  1935. }
  1936. /* Apply the scaling step. */
  1937. #if defined(WT_DOSCALE)
  1938. lptr = &a[0];
  1939. n = llen;
  1940. while (n-- > 0) {
  1941. lptr2 = lptr;
  1942. for (i = 0; i < numcols; ++i) {
  1943. lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(LGAIN));
  1944. ++lptr2;
  1945. }
  1946. lptr += stride;
  1947. }
  1948. hptr = &a[llen * stride];
  1949. n = numrows - llen;
  1950. while (n-- > 0) {
  1951. hptr2 = hptr;
  1952. for (i = 0; i < numcols; ++i) {
  1953. hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(HGAIN));
  1954. ++hptr2;
  1955. }
  1956. hptr += stride;
  1957. }
  1958. #endif
  1959. } else {
  1960. #if defined(WT_LENONE)
  1961. if (parity) {
  1962. lptr2 = &a[0];
  1963. for (i = 0; i < numcols; ++i) {
  1964. lptr2[0] <<= 1;
  1965. ++lptr2;
  1966. }
  1967. }
  1968. #endif
  1969. }
  1970. }
  1971. void jpc_ns_fwdlift_col(jpc_fix_t *a, int numrows, int stride,
  1972. int parity)
  1973. {
  1974. jpc_fix_t *lptr;
  1975. jpc_fix_t *hptr;
  1976. register jpc_fix_t *lptr2;
  1977. register jpc_fix_t *hptr2;
  1978. register int n;
  1979. int llen;
  1980. llen = (numrows + 1 - parity) >> 1;
  1981. if (numrows > 1) {
  1982. /* Apply the first lifting step. */
  1983. lptr = &a[0];
  1984. hptr = &a[llen * stride];
  1985. if (parity) {
  1986. lptr2 = lptr;
  1987. hptr2 = hptr;
  1988. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  1989. lptr2[0]));
  1990. ++hptr2;
  1991. ++lptr2;
  1992. hptr += stride;
  1993. }
  1994. n = numrows - llen - parity - (parity == (numrows & 1));
  1995. while (n-- > 0) {
  1996. lptr2 = lptr;
  1997. hptr2 = hptr;
  1998. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
  1999. jpc_fix_add(lptr2[0], lptr2[stride])));
  2000. ++lptr2;
  2001. ++hptr2;
  2002. hptr += stride;
  2003. lptr += stride;
  2004. }
  2005. if (parity == (numrows & 1)) {
  2006. lptr2 = lptr;
  2007. hptr2 = hptr;
  2008. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  2009. lptr2[0]));
  2010. ++lptr2;
  2011. ++hptr2;
  2012. }
  2013. /* Apply the second lifting step. */
  2014. lptr = &a[0];
  2015. hptr = &a[llen * stride];
  2016. if (!parity) {
  2017. lptr2 = lptr;
  2018. hptr2 = hptr;
  2019. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2020. hptr2[0]));
  2021. ++lptr2;
  2022. ++hptr2;
  2023. lptr += stride;
  2024. }
  2025. n = llen - (!parity) - (parity != (numrows & 1));
  2026. while (n-- > 0) {
  2027. lptr2 = lptr;
  2028. hptr2 = hptr;
  2029. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
  2030. jpc_fix_add(hptr2[0], hptr2[stride])));
  2031. ++lptr2;
  2032. ++hptr2;
  2033. lptr += stride;
  2034. hptr += stride;
  2035. }
  2036. if (parity != (numrows & 1)) {
  2037. lptr2 = lptr;
  2038. hptr2 = hptr;
  2039. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2040. hptr2[0]));
  2041. ++lptr2;
  2042. ++hptr2;
  2043. }
  2044. /* Apply the third lifting step. */
  2045. lptr = &a[0];
  2046. hptr = &a[llen * stride];
  2047. if (parity) {
  2048. lptr2 = lptr;
  2049. hptr2 = hptr;
  2050. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  2051. lptr2[0]));
  2052. ++hptr2;
  2053. ++lptr2;
  2054. hptr += stride;
  2055. }
  2056. n = numrows - llen - parity - (parity == (numrows & 1));
  2057. while (n-- > 0) {
  2058. lptr2 = lptr;
  2059. hptr2 = hptr;
  2060. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
  2061. jpc_fix_add(lptr2[0], lptr2[stride])));
  2062. ++lptr2;
  2063. ++hptr2;
  2064. hptr += stride;
  2065. lptr += stride;
  2066. }
  2067. if (parity == (numrows & 1)) {
  2068. lptr2 = lptr;
  2069. hptr2 = hptr;
  2070. jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  2071. lptr2[0]));
  2072. ++lptr2;
  2073. ++hptr2;
  2074. }
  2075. /* Apply the fourth lifting step. */
  2076. lptr = &a[0];
  2077. hptr = &a[llen * stride];
  2078. if (!parity) {
  2079. lptr2 = lptr;
  2080. hptr2 = hptr;
  2081. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  2082. hptr2[0]));
  2083. ++lptr2;
  2084. ++hptr2;
  2085. lptr += stride;
  2086. }
  2087. n = llen - (!parity) - (parity != (numrows & 1));
  2088. while (n-- > 0) {
  2089. lptr2 = lptr;
  2090. hptr2 = hptr;
  2091. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
  2092. jpc_fix_add(hptr2[0], hptr2[stride])));
  2093. ++lptr2;
  2094. ++hptr2;
  2095. lptr += stride;
  2096. hptr += stride;
  2097. }
  2098. if (parity != (numrows & 1)) {
  2099. lptr2 = lptr;
  2100. hptr2 = hptr;
  2101. jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  2102. hptr2[0]));
  2103. ++lptr2;
  2104. ++hptr2;
  2105. }
  2106. /* Apply the scaling step. */
  2107. #if defined(WT_DOSCALE)
  2108. lptr = &a[0];
  2109. n = llen;
  2110. while (n-- > 0) {
  2111. lptr2 = lptr;
  2112. lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(LGAIN));
  2113. ++lptr2;
  2114. lptr += stride;
  2115. }
  2116. hptr = &a[llen * stride];
  2117. n = numrows - llen;
  2118. while (n-- > 0) {
  2119. hptr2 = hptr;
  2120. hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(HGAIN));
  2121. ++hptr2;
  2122. hptr += stride;
  2123. }
  2124. #endif
  2125. } else {
  2126. #if defined(WT_LENONE)
  2127. if (parity) {
  2128. lptr2 = &a[0];
  2129. lptr2[0] <<= 1;
  2130. ++lptr2;
  2131. }
  2132. #endif
  2133. }
  2134. }
  2135. void jpc_ns_invlift_row(jpc_fix_t *a, int numcols, int parity)
  2136. {
  2137. register jpc_fix_t *lptr;
  2138. register jpc_fix_t *hptr;
  2139. register int n;
  2140. int llen;
  2141. llen = (numcols + 1 - parity) >> 1;
  2142. if (numcols > 1) {
  2143. /* Apply the scaling step. */
  2144. #if defined(WT_DOSCALE)
  2145. lptr = &a[0];
  2146. n = llen;
  2147. while (n-- > 0) {
  2148. lptr[0] = jpc_fix_mul(lptr[0], jpc_dbltofix(1.0 / LGAIN));
  2149. ++lptr;
  2150. }
  2151. hptr = &a[llen];
  2152. n = numcols - llen;
  2153. while (n-- > 0) {
  2154. hptr[0] = jpc_fix_mul(hptr[0], jpc_dbltofix(1.0 / HGAIN));
  2155. ++hptr;
  2156. }
  2157. #endif
  2158. /* Apply the first lifting step. */
  2159. lptr = &a[0];
  2160. hptr = &a[llen];
  2161. if (!parity) {
  2162. jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  2163. hptr[0]));
  2164. ++lptr;
  2165. }
  2166. n = llen - (!parity) - (parity != (numcols & 1));
  2167. while (n-- > 0) {
  2168. jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(DELTA),
  2169. jpc_fix_add(hptr[0], hptr[1])));
  2170. ++lptr;
  2171. ++hptr;
  2172. }
  2173. if (parity != (numcols & 1)) {
  2174. jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
  2175. hptr[0]));
  2176. }
  2177. /* Apply the second lifting step. */
  2178. lptr = &a[0];
  2179. hptr = &a[llen];
  2180. if (parity) {
  2181. jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  2182. lptr[0]));
  2183. ++hptr;
  2184. }
  2185. n = numcols - llen - parity - (parity == (numcols & 1));
  2186. while (n-- > 0) {
  2187. jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
  2188. jpc_fix_add(lptr[0], lptr[1])));
  2189. ++hptr;
  2190. ++lptr;
  2191. }
  2192. if (parity == (numcols & 1)) {
  2193. jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
  2194. lptr[0]));
  2195. }
  2196. /* Apply the third lifting step. */
  2197. lptr = &a[0];
  2198. hptr = &a[llen];
  2199. if (!parity) {
  2200. jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2201. hptr[0]));
  2202. ++lptr;
  2203. }
  2204. n = llen - (!parity) - (parity != (numcols & 1));
  2205. while (n-- > 0) {
  2206. jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(BETA),
  2207. jpc_fix_add(hptr[0], hptr[1])));
  2208. ++lptr;
  2209. ++hptr;
  2210. }
  2211. if (parity != (numcols & 1)) {
  2212. jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2213. hptr[0]));
  2214. }
  2215. /* Apply the fourth lifting step. */
  2216. lptr = &a[0];
  2217. hptr = &a[llen];
  2218. if (parity) {
  2219. jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  2220. lptr[0]));
  2221. ++hptr;
  2222. }
  2223. n = numcols - llen - parity - (parity == (numcols & 1));
  2224. while (n-- > 0) {
  2225. jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
  2226. jpc_fix_add(lptr[0], lptr[1])));
  2227. ++hptr;
  2228. ++lptr;
  2229. }
  2230. if (parity == (numcols & 1)) {
  2231. jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
  2232. lptr[0]));
  2233. }
  2234. } else {
  2235. #if defined(WT_LENONE)
  2236. if (parity) {
  2237. lptr = &a[0];
  2238. lptr[0] >>= 1;
  2239. }
  2240. #endif
  2241. }
  2242. }
  2243. void jpc_ns_invlift_colgrp(jpc_fix_t *a, int numrows, int stride,
  2244. int parity)
  2245. {
  2246. jpc_fix_t *lptr;
  2247. jpc_fix_t *hptr;
  2248. register jpc_fix_t *lptr2;
  2249. register jpc_fix_t *hptr2;
  2250. register int n;
  2251. register int i;
  2252. int llen;
  2253. llen = (numrows + 1 - parity) >> 1;
  2254. if (numrows > 1) {
  2255. /* Apply the scaling step. */
  2256. #if defined(WT_DOSCALE)
  2257. lptr = &a[0];
  2258. n = llen;
  2259. while (n-- > 0) {
  2260. lptr2 = lptr;
  2261. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2262. lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(1.0 / LGAIN));
  2263. ++lptr2;
  2264. }
  2265. lptr += stride;
  2266. }
  2267. hptr = &a[llen * stride];
  2268. n = numrows - llen;
  2269. while (n-- > 0) {
  2270. hptr2 = hptr;
  2271. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2272. hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(1.0 / HGAIN));
  2273. ++hptr2;
  2274. }
  2275. hptr += stride;
  2276. }
  2277. #endif
  2278. /* Apply the first lifting step. */
  2279. lptr = &a[0];
  2280. hptr = &a[llen * stride];
  2281. if (!parity) {
  2282. lptr2 = lptr;
  2283. hptr2 = hptr;
  2284. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2285. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2286. DELTA), hptr2[0]));
  2287. ++lptr2;
  2288. ++hptr2;
  2289. }
  2290. lptr += stride;
  2291. }
  2292. n = llen - (!parity) - (parity != (numrows & 1));
  2293. while (n-- > 0) {
  2294. lptr2 = lptr;
  2295. hptr2 = hptr;
  2296. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2297. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
  2298. jpc_fix_add(hptr2[0], hptr2[stride])));
  2299. ++lptr2;
  2300. ++hptr2;
  2301. }
  2302. lptr += stride;
  2303. hptr += stride;
  2304. }
  2305. if (parity != (numrows & 1)) {
  2306. lptr2 = lptr;
  2307. hptr2 = hptr;
  2308. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2309. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2310. DELTA), hptr2[0]));
  2311. ++lptr2;
  2312. ++hptr2;
  2313. }
  2314. }
  2315. /* Apply the second lifting step. */
  2316. lptr = &a[0];
  2317. hptr = &a[llen * stride];
  2318. if (parity) {
  2319. lptr2 = lptr;
  2320. hptr2 = hptr;
  2321. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2322. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2323. GAMMA), lptr2[0]));
  2324. ++hptr2;
  2325. ++lptr2;
  2326. }
  2327. hptr += stride;
  2328. }
  2329. n = numrows - llen - parity - (parity == (numrows & 1));
  2330. while (n-- > 0) {
  2331. lptr2 = lptr;
  2332. hptr2 = hptr;
  2333. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2334. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
  2335. jpc_fix_add(lptr2[0], lptr2[stride])));
  2336. ++lptr2;
  2337. ++hptr2;
  2338. }
  2339. hptr += stride;
  2340. lptr += stride;
  2341. }
  2342. if (parity == (numrows & 1)) {
  2343. lptr2 = lptr;
  2344. hptr2 = hptr;
  2345. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2346. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2347. GAMMA), lptr2[0]));
  2348. ++lptr2;
  2349. ++hptr2;
  2350. }
  2351. }
  2352. /* Apply the third lifting step. */
  2353. lptr = &a[0];
  2354. hptr = &a[llen * stride];
  2355. if (!parity) {
  2356. lptr2 = lptr;
  2357. hptr2 = hptr;
  2358. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2359. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2360. hptr2[0]));
  2361. ++lptr2;
  2362. ++hptr2;
  2363. }
  2364. lptr += stride;
  2365. }
  2366. n = llen - (!parity) - (parity != (numrows & 1));
  2367. while (n-- > 0) {
  2368. lptr2 = lptr;
  2369. hptr2 = hptr;
  2370. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2371. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
  2372. jpc_fix_add(hptr2[0], hptr2[stride])));
  2373. ++lptr2;
  2374. ++hptr2;
  2375. }
  2376. lptr += stride;
  2377. hptr += stride;
  2378. }
  2379. if (parity != (numrows & 1)) {
  2380. lptr2 = lptr;
  2381. hptr2 = hptr;
  2382. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2383. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2384. hptr2[0]));
  2385. ++lptr2;
  2386. ++hptr2;
  2387. }
  2388. }
  2389. /* Apply the fourth lifting step. */
  2390. lptr = &a[0];
  2391. hptr = &a[llen * stride];
  2392. if (parity) {
  2393. lptr2 = lptr;
  2394. hptr2 = hptr;
  2395. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2396. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2397. ALPHA), lptr2[0]));
  2398. ++hptr2;
  2399. ++lptr2;
  2400. }
  2401. hptr += stride;
  2402. }
  2403. n = numrows - llen - parity - (parity == (numrows & 1));
  2404. while (n-- > 0) {
  2405. lptr2 = lptr;
  2406. hptr2 = hptr;
  2407. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2408. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
  2409. jpc_fix_add(lptr2[0], lptr2[stride])));
  2410. ++lptr2;
  2411. ++hptr2;
  2412. }
  2413. hptr += stride;
  2414. lptr += stride;
  2415. }
  2416. if (parity == (numrows & 1)) {
  2417. lptr2 = lptr;
  2418. hptr2 = hptr;
  2419. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2420. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2421. ALPHA), lptr2[0]));
  2422. ++lptr2;
  2423. ++hptr2;
  2424. }
  2425. }
  2426. } else {
  2427. #if defined(WT_LENONE)
  2428. if (parity) {
  2429. lptr2 = &a[0];
  2430. for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
  2431. lptr2[0] >>= 1;
  2432. ++lptr2;
  2433. }
  2434. }
  2435. #endif
  2436. }
  2437. }
  2438. void jpc_ns_invlift_colres(jpc_fix_t *a, int numrows, int numcols,
  2439. int stride, int parity)
  2440. {
  2441. jpc_fix_t *lptr;
  2442. jpc_fix_t *hptr;
  2443. register jpc_fix_t *lptr2;
  2444. register jpc_fix_t *hptr2;
  2445. register int n;
  2446. register int i;
  2447. int llen;
  2448. llen = (numrows + 1 - parity) >> 1;
  2449. if (numrows > 1) {
  2450. /* Apply the scaling step. */
  2451. #if defined(WT_DOSCALE)
  2452. lptr = &a[0];
  2453. n = llen;
  2454. while (n-- > 0) {
  2455. lptr2 = lptr;
  2456. for (i = 0; i < numcols; ++i) {
  2457. lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(1.0 / LGAIN));
  2458. ++lptr2;
  2459. }
  2460. lptr += stride;
  2461. }
  2462. hptr = &a[llen * stride];
  2463. n = numrows - llen;
  2464. while (n-- > 0) {
  2465. hptr2 = hptr;
  2466. for (i = 0; i < numcols; ++i) {
  2467. hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(1.0 / HGAIN));
  2468. ++hptr2;
  2469. }
  2470. hptr += stride;
  2471. }
  2472. #endif
  2473. /* Apply the first lifting step. */
  2474. lptr = &a[0];
  2475. hptr = &a[llen * stride];
  2476. if (!parity) {
  2477. lptr2 = lptr;
  2478. hptr2 = hptr;
  2479. for (i = 0; i < numcols; ++i) {
  2480. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2481. DELTA), hptr2[0]));
  2482. ++lptr2;
  2483. ++hptr2;
  2484. }
  2485. lptr += stride;
  2486. }
  2487. n = llen - (!parity) - (parity != (numrows & 1));
  2488. while (n-- > 0) {
  2489. lptr2 = lptr;
  2490. hptr2 = hptr;
  2491. for (i = 0; i < numcols; ++i) {
  2492. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
  2493. jpc_fix_add(hptr2[0], hptr2[stride])));
  2494. ++lptr2;
  2495. ++hptr2;
  2496. }
  2497. lptr += stride;
  2498. hptr += stride;
  2499. }
  2500. if (parity != (numrows & 1)) {
  2501. lptr2 = lptr;
  2502. hptr2 = hptr;
  2503. for (i = 0; i < numcols; ++i) {
  2504. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2505. DELTA), hptr2[0]));
  2506. ++lptr2;
  2507. ++hptr2;
  2508. }
  2509. }
  2510. /* Apply the second lifting step. */
  2511. lptr = &a[0];
  2512. hptr = &a[llen * stride];
  2513. if (parity) {
  2514. lptr2 = lptr;
  2515. hptr2 = hptr;
  2516. for (i = 0; i < numcols; ++i) {
  2517. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2518. GAMMA), lptr2[0]));
  2519. ++hptr2;
  2520. ++lptr2;
  2521. }
  2522. hptr += stride;
  2523. }
  2524. n = numrows - llen - parity - (parity == (numrows & 1));
  2525. while (n-- > 0) {
  2526. lptr2 = lptr;
  2527. hptr2 = hptr;
  2528. for (i = 0; i < numcols; ++i) {
  2529. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
  2530. jpc_fix_add(lptr2[0], lptr2[stride])));
  2531. ++lptr2;
  2532. ++hptr2;
  2533. }
  2534. hptr += stride;
  2535. lptr += stride;
  2536. }
  2537. if (parity == (numrows & 1)) {
  2538. lptr2 = lptr;
  2539. hptr2 = hptr;
  2540. for (i = 0; i < numcols; ++i) {
  2541. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2542. GAMMA), lptr2[0]));
  2543. ++lptr2;
  2544. ++hptr2;
  2545. }
  2546. }
  2547. /* Apply the third lifting step. */
  2548. lptr = &a[0];
  2549. hptr = &a[llen * stride];
  2550. if (!parity) {
  2551. lptr2 = lptr;
  2552. hptr2 = hptr;
  2553. for (i = 0; i < numcols; ++i) {
  2554. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2555. hptr2[0]));
  2556. ++lptr2;
  2557. ++hptr2;
  2558. }
  2559. lptr += stride;
  2560. }
  2561. n = llen - (!parity) - (parity != (numrows & 1));
  2562. while (n-- > 0) {
  2563. lptr2 = lptr;
  2564. hptr2 = hptr;
  2565. for (i = 0; i < numcols; ++i) {
  2566. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
  2567. jpc_fix_add(hptr2[0], hptr2[stride])));
  2568. ++lptr2;
  2569. ++hptr2;
  2570. }
  2571. lptr += stride;
  2572. hptr += stride;
  2573. }
  2574. if (parity != (numrows & 1)) {
  2575. lptr2 = lptr;
  2576. hptr2 = hptr;
  2577. for (i = 0; i < numcols; ++i) {
  2578. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2579. hptr2[0]));
  2580. ++lptr2;
  2581. ++hptr2;
  2582. }
  2583. }
  2584. /* Apply the fourth lifting step. */
  2585. lptr = &a[0];
  2586. hptr = &a[llen * stride];
  2587. if (parity) {
  2588. lptr2 = lptr;
  2589. hptr2 = hptr;
  2590. for (i = 0; i < numcols; ++i) {
  2591. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2592. ALPHA), lptr2[0]));
  2593. ++hptr2;
  2594. ++lptr2;
  2595. }
  2596. hptr += stride;
  2597. }
  2598. n = numrows - llen - parity - (parity == (numrows & 1));
  2599. while (n-- > 0) {
  2600. lptr2 = lptr;
  2601. hptr2 = hptr;
  2602. for (i = 0; i < numcols; ++i) {
  2603. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
  2604. jpc_fix_add(lptr2[0], lptr2[stride])));
  2605. ++lptr2;
  2606. ++hptr2;
  2607. }
  2608. hptr += stride;
  2609. lptr += stride;
  2610. }
  2611. if (parity == (numrows & 1)) {
  2612. lptr2 = lptr;
  2613. hptr2 = hptr;
  2614. for (i = 0; i < numcols; ++i) {
  2615. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2616. ALPHA), lptr2[0]));
  2617. ++lptr2;
  2618. ++hptr2;
  2619. }
  2620. }
  2621. } else {
  2622. #if defined(WT_LENONE)
  2623. if (parity) {
  2624. lptr2 = &a[0];
  2625. for (i = 0; i < numcols; ++i) {
  2626. lptr2[0] >>= 1;
  2627. ++lptr2;
  2628. }
  2629. }
  2630. #endif
  2631. }
  2632. }
  2633. void jpc_ns_invlift_col(jpc_fix_t *a, int numrows, int stride,
  2634. int parity)
  2635. {
  2636. jpc_fix_t *lptr;
  2637. jpc_fix_t *hptr;
  2638. register jpc_fix_t *lptr2;
  2639. register jpc_fix_t *hptr2;
  2640. register int n;
  2641. int llen;
  2642. llen = (numrows + 1 - parity) >> 1;
  2643. if (numrows > 1) {
  2644. /* Apply the scaling step. */
  2645. #if defined(WT_DOSCALE)
  2646. lptr = &a[0];
  2647. n = llen;
  2648. while (n-- > 0) {
  2649. lptr2 = lptr;
  2650. lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(1.0 / LGAIN));
  2651. ++lptr2;
  2652. lptr += stride;
  2653. }
  2654. hptr = &a[llen * stride];
  2655. n = numrows - llen;
  2656. while (n-- > 0) {
  2657. hptr2 = hptr;
  2658. hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(1.0 / HGAIN));
  2659. ++hptr2;
  2660. hptr += stride;
  2661. }
  2662. #endif
  2663. /* Apply the first lifting step. */
  2664. lptr = &a[0];
  2665. hptr = &a[llen * stride];
  2666. if (!parity) {
  2667. lptr2 = lptr;
  2668. hptr2 = hptr;
  2669. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2670. DELTA), hptr2[0]));
  2671. ++lptr2;
  2672. ++hptr2;
  2673. lptr += stride;
  2674. }
  2675. n = llen - (!parity) - (parity != (numrows & 1));
  2676. while (n-- > 0) {
  2677. lptr2 = lptr;
  2678. hptr2 = hptr;
  2679. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
  2680. jpc_fix_add(hptr2[0], hptr2[stride])));
  2681. ++lptr2;
  2682. ++hptr2;
  2683. lptr += stride;
  2684. hptr += stride;
  2685. }
  2686. if (parity != (numrows & 1)) {
  2687. lptr2 = lptr;
  2688. hptr2 = hptr;
  2689. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2690. DELTA), hptr2[0]));
  2691. ++lptr2;
  2692. ++hptr2;
  2693. }
  2694. /* Apply the second lifting step. */
  2695. lptr = &a[0];
  2696. hptr = &a[llen * stride];
  2697. if (parity) {
  2698. lptr2 = lptr;
  2699. hptr2 = hptr;
  2700. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2701. GAMMA), lptr2[0]));
  2702. ++hptr2;
  2703. ++lptr2;
  2704. hptr += stride;
  2705. }
  2706. n = numrows - llen - parity - (parity == (numrows & 1));
  2707. while (n-- > 0) {
  2708. lptr2 = lptr;
  2709. hptr2 = hptr;
  2710. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
  2711. jpc_fix_add(lptr2[0], lptr2[stride])));
  2712. ++lptr2;
  2713. ++hptr2;
  2714. hptr += stride;
  2715. lptr += stride;
  2716. }
  2717. if (parity == (numrows & 1)) {
  2718. lptr2 = lptr;
  2719. hptr2 = hptr;
  2720. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2721. GAMMA), lptr2[0]));
  2722. ++lptr2;
  2723. ++hptr2;
  2724. }
  2725. /* Apply the third lifting step. */
  2726. lptr = &a[0];
  2727. hptr = &a[llen * stride];
  2728. if (!parity) {
  2729. lptr2 = lptr;
  2730. hptr2 = hptr;
  2731. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2732. hptr2[0]));
  2733. ++lptr2;
  2734. ++hptr2;
  2735. lptr += stride;
  2736. }
  2737. n = llen - (!parity) - (parity != (numrows & 1));
  2738. while (n-- > 0) {
  2739. lptr2 = lptr;
  2740. hptr2 = hptr;
  2741. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
  2742. jpc_fix_add(hptr2[0], hptr2[stride])));
  2743. ++lptr2;
  2744. ++hptr2;
  2745. lptr += stride;
  2746. hptr += stride;
  2747. }
  2748. if (parity != (numrows & 1)) {
  2749. lptr2 = lptr;
  2750. hptr2 = hptr;
  2751. jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
  2752. hptr2[0]));
  2753. ++lptr2;
  2754. ++hptr2;
  2755. }
  2756. /* Apply the fourth lifting step. */
  2757. lptr = &a[0];
  2758. hptr = &a[llen * stride];
  2759. if (parity) {
  2760. lptr2 = lptr;
  2761. hptr2 = hptr;
  2762. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2763. ALPHA), lptr2[0]));
  2764. ++hptr2;
  2765. ++lptr2;
  2766. hptr += stride;
  2767. }
  2768. n = numrows - llen - parity - (parity == (numrows & 1));
  2769. while (n-- > 0) {
  2770. lptr2 = lptr;
  2771. hptr2 = hptr;
  2772. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
  2773. jpc_fix_add(lptr2[0], lptr2[stride])));
  2774. ++lptr2;
  2775. ++hptr2;
  2776. hptr += stride;
  2777. lptr += stride;
  2778. }
  2779. if (parity == (numrows & 1)) {
  2780. lptr2 = lptr;
  2781. hptr2 = hptr;
  2782. jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
  2783. ALPHA), lptr2[0]));
  2784. ++lptr2;
  2785. ++hptr2;
  2786. }
  2787. } else {
  2788. #if defined(WT_LENONE)
  2789. if (parity) {
  2790. lptr2 = &a[0];
  2791. lptr2[0] >>= 1;
  2792. ++lptr2;
  2793. }
  2794. #endif
  2795. }
  2796. }
  2797. int jpc_ns_analyze(int *a, int xstart, int ystart, int width, int height,
  2798. int stride)
  2799. {
  2800. int numrows = height;
  2801. int numcols = width;
  2802. int rowparity = ystart & 1;
  2803. int colparity = xstart & 1;
  2804. int i;
  2805. jpc_fix_t *startptr;
  2806. int maxcols;
  2807. maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
  2808. startptr = (jpc_fix_t*)&a[0];
  2809. for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
  2810. jpc_qmfb_split_colgrp(startptr, numrows, stride, rowparity);
  2811. jpc_ns_fwdlift_colgrp(startptr, numrows, stride, rowparity);
  2812. startptr += JPC_QMFB_COLGRPSIZE;
  2813. }
  2814. if (maxcols < numcols) {
  2815. jpc_qmfb_split_colres(startptr, numrows, numcols - maxcols, stride,
  2816. rowparity);
  2817. jpc_ns_fwdlift_colres(startptr, numrows, numcols - maxcols, stride,
  2818. rowparity);
  2819. }
  2820. startptr = (jpc_fix_t*)&a[0];
  2821. for (i = 0; i < numrows; ++i) {
  2822. jpc_qmfb_split_row(startptr, numcols, colparity);
  2823. jpc_ns_fwdlift_row(startptr, numcols, colparity);
  2824. startptr += stride;
  2825. }
  2826. return 0;
  2827. }
  2828. int jpc_ns_synthesize(int *a, int xstart, int ystart, int width,
  2829. int height, int stride)
  2830. {
  2831. int numrows = height;
  2832. int numcols = width;
  2833. int rowparity = ystart & 1;
  2834. int colparity = xstart & 1;
  2835. int maxcols;
  2836. jpc_fix_t *startptr;
  2837. int i;
  2838. startptr = (jpc_fix_t*)&a[0];
  2839. for (i = 0; i < numrows; ++i) {
  2840. jpc_ns_invlift_row(startptr, numcols, colparity);
  2841. jpc_qmfb_join_row(startptr, numcols, colparity);
  2842. startptr += stride;
  2843. }
  2844. maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
  2845. startptr = (jpc_fix_t*)&a[0];
  2846. for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
  2847. jpc_ns_invlift_colgrp(startptr, numrows, stride, rowparity);
  2848. jpc_qmfb_join_colgrp(startptr, numrows, stride, rowparity);
  2849. startptr += JPC_QMFB_COLGRPSIZE;
  2850. }
  2851. if (maxcols < numcols) {
  2852. jpc_ns_invlift_colres(startptr, numrows, numcols - maxcols, stride,
  2853. rowparity);
  2854. jpc_qmfb_join_colres(startptr, numrows, numcols - maxcols, stride,
  2855. rowparity);
  2856. }
  2857. return 0;
  2858. }