jpc_t2dec.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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. * Tier 2 Decoder
  64. *
  65. * $Id: jpc_t2dec.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
  66. */
  67. /******************************************************************************\
  68. * Includes.
  69. \******************************************************************************/
  70. #include <stdio.h>
  71. #include <stdlib.h>
  72. #include <assert.h>
  73. #include "jasper/jas_types.h"
  74. #include "jasper/jas_fix.h"
  75. #include "jasper/jas_malloc.h"
  76. #include "jasper/jas_math.h"
  77. #include "jasper/jas_stream.h"
  78. #include "jasper/jas_debug.h"
  79. #include "jpc_bs.h"
  80. #include "jpc_dec.h"
  81. #include "jpc_cs.h"
  82. #include "jpc_mqdec.h"
  83. #include "jpc_t2dec.h"
  84. #include "jpc_t1cod.h"
  85. #include "jpc_math.h"
  86. /******************************************************************************\
  87. *
  88. \******************************************************************************/
  89. long jpc_dec_lookahead(jas_stream_t *in);
  90. static int jpc_getcommacode(jpc_bitstream_t *in);
  91. static int jpc_getnumnewpasses(jpc_bitstream_t *in);
  92. static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in, int compno, int lvlno,
  93. int prcno, int lyrno);
  94. /******************************************************************************\
  95. * Code.
  96. \******************************************************************************/
  97. static int jpc_getcommacode(jpc_bitstream_t *in)
  98. {
  99. int n;
  100. int v;
  101. n = 0;
  102. for (;;) {
  103. if ((v = jpc_bitstream_getbit(in)) < 0) {
  104. return -1;
  105. }
  106. if (jpc_bitstream_eof(in)) {
  107. return -1;
  108. }
  109. if (!v) {
  110. break;
  111. }
  112. ++n;
  113. }
  114. return n;
  115. }
  116. static int jpc_getnumnewpasses(jpc_bitstream_t *in)
  117. {
  118. int n;
  119. if ((n = jpc_bitstream_getbit(in)) > 0) {
  120. if ((n = jpc_bitstream_getbit(in)) > 0) {
  121. if ((n = jpc_bitstream_getbits(in, 2)) == 3) {
  122. if ((n = jpc_bitstream_getbits(in, 5)) == 31) {
  123. if ((n = jpc_bitstream_getbits(in, 7)) >= 0) {
  124. n += 36 + 1;
  125. }
  126. } else if (n >= 0) {
  127. n += 5 + 1;
  128. }
  129. } else if (n >= 0) {
  130. n += 2 + 1;
  131. }
  132. } else if (!n) {
  133. n += 2;
  134. }
  135. } else if (!n) {
  136. ++n;
  137. }
  138. return n;
  139. }
  140. static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in, int compno, int rlvlno,
  141. int prcno, int lyrno)
  142. {
  143. jpc_bitstream_t *inb;
  144. jpc_dec_tcomp_t *tcomp;
  145. jpc_dec_rlvl_t *rlvl;
  146. jpc_dec_band_t *band;
  147. jpc_dec_cblk_t *cblk;
  148. int n;
  149. int m;
  150. int i;
  151. jpc_tagtreenode_t *leaf;
  152. int included;
  153. int ret;
  154. int numnewpasses;
  155. jpc_dec_seg_t *seg;
  156. int len;
  157. int present;
  158. int savenumnewpasses;
  159. int mycounter;
  160. jpc_ms_t *ms;
  161. jpc_dec_tile_t *tile;
  162. jpc_dec_ccp_t *ccp;
  163. jpc_dec_cp_t *cp;
  164. int bandno;
  165. jpc_dec_prc_t *prc;
  166. int usedcblkcnt;
  167. int cblkno;
  168. uint_fast32_t bodylen;
  169. bool discard;
  170. int passno;
  171. int maxpasses;
  172. int hdrlen;
  173. int hdroffstart;
  174. int hdroffend;
  175. /* Avoid compiler warning about possible use of uninitialized
  176. variable. */
  177. bodylen = 0;
  178. discard = (lyrno >= dec->maxlyrs);
  179. tile = dec->curtile;
  180. cp = tile->cp;
  181. ccp = &cp->ccps[compno];
  182. /*
  183. * Decode the packet header.
  184. */
  185. /* Decode the SOP marker segment if present. */
  186. if (cp->csty & JPC_COD_SOP) {
  187. if (jpc_dec_lookahead(in) == JPC_MS_SOP) {
  188. if (!(ms = jpc_getms(in, dec->cstate))) {
  189. return -1;
  190. }
  191. if (jpc_ms_gettype(ms) != JPC_MS_SOP) {
  192. jpc_ms_destroy(ms);
  193. jas_eprintf("missing SOP marker segment\n");
  194. return -1;
  195. }
  196. jpc_ms_destroy(ms);
  197. }
  198. }
  199. hdroffstart = jas_stream_getrwcount(pkthdrstream);
  200. if (!(inb = jpc_bitstream_sopen(pkthdrstream, "r"))) {
  201. return -1;
  202. }
  203. if ((present = jpc_bitstream_getbit(inb)) < 0) {
  204. return 1;
  205. }
  206. JAS_DBGLOG(10, ("\n", present));
  207. JAS_DBGLOG(10, ("present=%d ", present));
  208. /* Is the packet non-empty? */
  209. if (present) {
  210. /* The packet is non-empty. */
  211. tcomp = &tile->tcomps[compno];
  212. rlvl = &tcomp->rlvls[rlvlno];
  213. bodylen = 0;
  214. for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
  215. ++bandno, ++band) {
  216. if (!band->data) {
  217. continue;
  218. }
  219. prc = &band->prcs[prcno];
  220. if (!prc->cblks) {
  221. continue;
  222. }
  223. usedcblkcnt = 0;
  224. for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
  225. ++cblkno, ++cblk) {
  226. ++usedcblkcnt;
  227. if (!cblk->numpasses) {
  228. leaf = jpc_tagtree_getleaf(prc->incltagtree, usedcblkcnt - 1);
  229. if ((included = jpc_tagtree_decode(prc->incltagtree, leaf, lyrno + 1, inb)) < 0) {
  230. return -1;
  231. }
  232. } else {
  233. if ((included = jpc_bitstream_getbit(inb)) < 0) {
  234. return -1;
  235. }
  236. }
  237. JAS_DBGLOG(10, ("\n"));
  238. JAS_DBGLOG(10, ("included=%d ", included));
  239. if (!included) {
  240. continue;
  241. }
  242. if (!cblk->numpasses) {
  243. i = 1;
  244. leaf = jpc_tagtree_getleaf(prc->numimsbstagtree, usedcblkcnt - 1);
  245. for (;;) {
  246. if ((ret = jpc_tagtree_decode(prc->numimsbstagtree, leaf, i, inb)) < 0) {
  247. return -1;
  248. }
  249. if (ret) {
  250. break;
  251. }
  252. ++i;
  253. }
  254. cblk->numimsbs = i - 1;
  255. cblk->firstpassno = cblk->numimsbs * 3;
  256. }
  257. if ((numnewpasses = jpc_getnumnewpasses(inb)) < 0) {
  258. return -1;
  259. }
  260. JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses));
  261. seg = cblk->curseg;
  262. savenumnewpasses = numnewpasses;
  263. mycounter = 0;
  264. if (numnewpasses > 0) {
  265. if ((m = jpc_getcommacode(inb)) < 0) {
  266. return -1;
  267. }
  268. cblk->numlenbits += m;
  269. JAS_DBGLOG(10, ("increment=%d ", m));
  270. while (numnewpasses > 0) {
  271. passno = cblk->firstpassno + cblk->numpasses + mycounter;
  272. /* XXX - the maxpasses is not set precisely but this doesn't matter... */
  273. maxpasses = JPC_SEGPASSCNT(passno, cblk->firstpassno, 10000, (ccp->cblkctx & JPC_COX_LAZY) != 0, (ccp->cblkctx & JPC_COX_TERMALL) != 0);
  274. if (!discard && !seg) {
  275. if (!(seg = jpc_seg_alloc())) {
  276. return -1;
  277. }
  278. jpc_seglist_insert(&cblk->segs, cblk->segs.tail, seg);
  279. if (!cblk->curseg) {
  280. cblk->curseg = seg;
  281. }
  282. seg->passno = passno;
  283. seg->type = JPC_SEGTYPE(seg->passno, cblk->firstpassno, (ccp->cblkctx & JPC_COX_LAZY) != 0);
  284. seg->maxpasses = maxpasses;
  285. }
  286. n = JAS_MIN(numnewpasses, maxpasses);
  287. mycounter += n;
  288. numnewpasses -= n;
  289. if ((len = jpc_bitstream_getbits(inb, cblk->numlenbits + jpc_floorlog2(n))) < 0) {
  290. return -1;
  291. }
  292. JAS_DBGLOG(10, ("len=%d ", len));
  293. if (!discard) {
  294. seg->lyrno = lyrno;
  295. seg->numpasses += n;
  296. seg->cnt = len;
  297. seg = seg->next;
  298. }
  299. bodylen += len;
  300. }
  301. }
  302. cblk->numpasses += savenumnewpasses;
  303. }
  304. }
  305. jpc_bitstream_inalign(inb, 0, 0);
  306. } else {
  307. if (jpc_bitstream_inalign(inb, 0x7f, 0)) {
  308. jas_eprintf("alignment failed\n");
  309. return -1;
  310. }
  311. }
  312. jpc_bitstream_close(inb);
  313. hdroffend = jas_stream_getrwcount(pkthdrstream);
  314. hdrlen = hdroffend - hdroffstart;
  315. if (jas_getdbglevel() >= 5) {
  316. jas_eprintf("hdrlen=%lu bodylen=%lu \n", (unsigned long) hdrlen,
  317. (unsigned long) bodylen);
  318. }
  319. if (cp->csty & JPC_COD_EPH) {
  320. if (jpc_dec_lookahead(pkthdrstream) == JPC_MS_EPH) {
  321. if (!(ms = jpc_getms(pkthdrstream, dec->cstate))) {
  322. jas_eprintf("cannot get (EPH) marker segment\n");
  323. return -1;
  324. }
  325. if (jpc_ms_gettype(ms) != JPC_MS_EPH) {
  326. jpc_ms_destroy(ms);
  327. jas_eprintf("missing EPH marker segment\n");
  328. return -1;
  329. }
  330. jpc_ms_destroy(ms);
  331. }
  332. }
  333. /* decode the packet body. */
  334. if (jas_getdbglevel() >= 1) {
  335. jas_eprintf("packet body offset=%06ld\n", (long) jas_stream_getrwcount(in));
  336. }
  337. if (!discard) {
  338. tcomp = &tile->tcomps[compno];
  339. rlvl = &tcomp->rlvls[rlvlno];
  340. for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
  341. ++bandno, ++band) {
  342. if (!band->data) {
  343. continue;
  344. }
  345. prc = &band->prcs[prcno];
  346. if (!prc->cblks) {
  347. continue;
  348. }
  349. for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
  350. ++cblkno, ++cblk) {
  351. seg = cblk->curseg;
  352. while (seg) {
  353. if (!seg->stream) {
  354. if (!(seg->stream = jas_stream_memopen(0, 0))) {
  355. return -1;
  356. }
  357. }
  358. #if 0
  359. jas_eprintf("lyrno=%02d, compno=%02d, lvlno=%02d, prcno=%02d, bandno=%02d, cblkno=%02d, passno=%02d numpasses=%02d cnt=%d numbps=%d, numimsbs=%d\n", lyrno, compno, rlvlno, prcno, band - rlvl->bands, cblk - prc->cblks, seg->passno, seg->numpasses, seg->cnt, band->numbps, cblk->numimsbs);
  360. #endif
  361. if (seg->cnt > 0) {
  362. if (jpc_getdata(in, seg->stream, seg->cnt) < 0) {
  363. return -1;
  364. }
  365. seg->cnt = 0;
  366. }
  367. if (seg->numpasses >= seg->maxpasses) {
  368. cblk->curseg = seg->next;
  369. }
  370. seg = seg->next;
  371. }
  372. }
  373. }
  374. } else {
  375. if (jas_stream_gobble(in, bodylen) != JAS_CAST(int, bodylen)) {
  376. return -1;
  377. }
  378. }
  379. return 0;
  380. }
  381. /********************************************************************************************/
  382. /********************************************************************************************/
  383. int jpc_dec_decodepkts(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in)
  384. {
  385. jpc_dec_tile_t *tile;
  386. jpc_pi_t *pi;
  387. int ret;
  388. tile = dec->curtile;
  389. pi = tile->pi;
  390. for (;;) {
  391. if (!tile->pkthdrstream || jas_stream_peekc(tile->pkthdrstream) == EOF) {
  392. switch (jpc_dec_lookahead(in)) {
  393. case JPC_MS_EOC:
  394. case JPC_MS_SOT:
  395. return 0;
  396. break;
  397. case JPC_MS_SOP:
  398. case JPC_MS_EPH:
  399. case 0:
  400. break;
  401. default:
  402. return -1;
  403. break;
  404. }
  405. }
  406. if ((ret = jpc_pi_next(pi))) {
  407. return ret;
  408. }
  409. if (dec->maxpkts >= 0 && dec->numpkts >= dec->maxpkts) {
  410. jas_eprintf("warning: stopping decode prematurely as requested\n");
  411. return 0;
  412. }
  413. if (jas_getdbglevel() >= 1) {
  414. jas_eprintf("packet offset=%08ld prg=%d cmptno=%02d "
  415. "rlvlno=%02d prcno=%03d lyrno=%02d\n", (long)
  416. jas_stream_getrwcount(in), jpc_pi_prg(pi), jpc_pi_cmptno(pi),
  417. jpc_pi_rlvlno(pi), jpc_pi_prcno(pi), jpc_pi_lyrno(pi));
  418. }
  419. if (jpc_dec_decodepkt(dec, pkthdrstream, in, jpc_pi_cmptno(pi), jpc_pi_rlvlno(pi),
  420. jpc_pi_prcno(pi), jpc_pi_lyrno(pi))) {
  421. return -1;
  422. }
  423. ++dec->numpkts;
  424. }
  425. return 0;
  426. }
  427. jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile)
  428. {
  429. jpc_pi_t *pi;
  430. int compno;
  431. jpc_picomp_t *picomp;
  432. jpc_pirlvl_t *pirlvl;
  433. jpc_dec_tcomp_t *tcomp;
  434. int rlvlno;
  435. jpc_dec_rlvl_t *rlvl;
  436. int prcno;
  437. int *prclyrno;
  438. jpc_dec_cmpt_t *cmpt;
  439. if (!(pi = jpc_pi_create0())) {
  440. return 0;
  441. }
  442. pi->numcomps = dec->numcomps;
  443. if (!(pi->picomps = jas_alloc2(pi->numcomps, sizeof(jpc_picomp_t)))) {
  444. jpc_pi_destroy(pi);
  445. return 0;
  446. }
  447. for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; ++compno,
  448. ++picomp) {
  449. picomp->pirlvls = 0;
  450. }
  451. for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps;
  452. compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
  453. picomp->numrlvls = tcomp->numrlvls;
  454. if (!(picomp->pirlvls = jas_alloc2(picomp->numrlvls,
  455. sizeof(jpc_pirlvl_t)))) {
  456. jpc_pi_destroy(pi);
  457. return 0;
  458. }
  459. for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
  460. picomp->numrlvls; ++rlvlno, ++pirlvl) {
  461. pirlvl->prclyrnos = 0;
  462. }
  463. for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
  464. rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
  465. /* XXX sizeof(long) should be sizeof different type */
  466. pirlvl->numprcs = rlvl->numprcs;
  467. if (!(pirlvl->prclyrnos = jas_alloc2(pirlvl->numprcs,
  468. sizeof(long)))) {
  469. jpc_pi_destroy(pi);
  470. return 0;
  471. }
  472. }
  473. }
  474. pi->maxrlvls = 0;
  475. for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps, cmpt =
  476. dec->cmpts; compno < pi->numcomps; ++compno, ++tcomp, ++picomp,
  477. ++cmpt) {
  478. picomp->hsamp = cmpt->hstep;
  479. picomp->vsamp = cmpt->vstep;
  480. for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
  481. rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
  482. pirlvl->prcwidthexpn = rlvl->prcwidthexpn;
  483. pirlvl->prcheightexpn = rlvl->prcheightexpn;
  484. for (prcno = 0, prclyrno = pirlvl->prclyrnos;
  485. prcno < pirlvl->numprcs; ++prcno, ++prclyrno) {
  486. *prclyrno = 0;
  487. }
  488. pirlvl->numhprcs = rlvl->numhprcs;
  489. }
  490. if (pi->maxrlvls < tcomp->numrlvls) {
  491. pi->maxrlvls = tcomp->numrlvls;
  492. }
  493. }
  494. pi->numlyrs = tile->cp->numlyrs;
  495. pi->xstart = tile->xstart;
  496. pi->ystart = tile->ystart;
  497. pi->xend = tile->xend;
  498. pi->yend = tile->yend;
  499. pi->picomp = 0;
  500. pi->pirlvl = 0;
  501. pi->x = 0;
  502. pi->y = 0;
  503. pi->compno = 0;
  504. pi->rlvlno = 0;
  505. pi->prcno = 0;
  506. pi->lyrno = 0;
  507. pi->xstep = 0;
  508. pi->ystep = 0;
  509. pi->pchgno = -1;
  510. pi->defaultpchg.prgord = tile->cp->prgord;
  511. pi->defaultpchg.compnostart = 0;
  512. pi->defaultpchg.compnoend = pi->numcomps;
  513. pi->defaultpchg.rlvlnostart = 0;
  514. pi->defaultpchg.rlvlnoend = pi->maxrlvls;
  515. pi->defaultpchg.lyrnoend = pi->numlyrs;
  516. pi->pchg = 0;
  517. pi->valid = 0;
  518. return pi;
  519. }
  520. long jpc_dec_lookahead(jas_stream_t *in)
  521. {
  522. uint_fast16_t x;
  523. if (jpc_getuint16(in, &x)) {
  524. return -1;
  525. }
  526. if (jas_stream_ungetc(in, x & 0xff) == EOF ||
  527. jas_stream_ungetc(in, x >> 8) == EOF) {
  528. return -1;
  529. }
  530. if (x >= JPC_MS_INMIN /*&& x <= JPC_MS_INMAX*/) {
  531. return x;
  532. }
  533. return 0;
  534. }