jpc_cs.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  2. * Copyright (c) 1999-2000 Image Power, Inc. and the University of
  3. * British Columbia.
  4. * Copyright (c) 2001-2002 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. * JPEG-2000 Code Stream Library
  64. *
  65. * $Id: jpc_cs.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
  66. */
  67. #ifndef JPC_CS_H
  68. #define JPC_CS_H
  69. /******************************************************************************\
  70. * Includes.
  71. \******************************************************************************/
  72. #include "jasper/jas_image.h"
  73. #include "jasper/jas_stream.h"
  74. #include "jpc_cod.h"
  75. /******************************************************************************\
  76. * Constants and Types.
  77. \******************************************************************************/
  78. /* The maximum number of resolution levels. */
  79. #define JPC_MAXRLVLS 33
  80. /* The maximum number of bands. */
  81. #define JPC_MAXBANDS (3 * JPC_MAXRLVLS + 1)
  82. /* The maximum number of layers. */
  83. #define JPC_MAXLYRS 16384
  84. /**************************************\
  85. * Code stream.
  86. \**************************************/
  87. /*
  88. * Code stream states.
  89. */
  90. /* Initial. */
  91. #define JPC_CS_INIT 0
  92. /* Main header. */
  93. #define JPC_CS_MHDR 1
  94. /* Tile-part header. */
  95. #define JPC_CS_THDR 2
  96. /* Main trailer. */
  97. #define JPC_CS_MTLR 3
  98. /* Tile-part data. */
  99. #define JPC_CS_TDATA 4
  100. /*
  101. * Unfortunately, the code stream syntax was not designed in such a way that
  102. * any given marker segment can be correctly decoded without additional state
  103. * derived from previously decoded marker segments.
  104. * For example, a RGN/COC/QCC marker segment cannot be decoded unless the
  105. * number of components is known.
  106. */
  107. /*
  108. * Code stream state information.
  109. */
  110. typedef struct {
  111. /* The number of components. */
  112. uint_fast16_t numcomps;
  113. } jpc_cstate_t;
  114. /**************************************\
  115. * SOT marker segment parameters.
  116. \**************************************/
  117. typedef struct {
  118. /* The tile number. */
  119. uint_fast16_t tileno;
  120. /* The combined length of the marker segment and its auxilary data
  121. (i.e., packet data). */
  122. uint_fast32_t len;
  123. /* The tile-part instance. */
  124. uint_fast8_t partno;
  125. /* The number of tile-parts. */
  126. uint_fast8_t numparts;
  127. } jpc_sot_t;
  128. /**************************************\
  129. * SIZ marker segment parameters.
  130. \**************************************/
  131. /* Per component information. */
  132. typedef struct {
  133. /* The precision of the samples. */
  134. uint_fast8_t prec;
  135. /* The signedness of the samples. */
  136. uint_fast8_t sgnd;
  137. /* The horizontal separation of samples with respect to the reference
  138. grid. */
  139. uint_fast8_t hsamp;
  140. /* The vertical separation of samples with respect to the reference
  141. grid. */
  142. uint_fast8_t vsamp;
  143. } jpc_sizcomp_t;
  144. /* SIZ marker segment parameters. */
  145. typedef struct {
  146. /* The code stream capabilities. */
  147. uint_fast16_t caps;
  148. /* The width of the image in units of the reference grid. */
  149. uint_fast32_t width;
  150. /* The height of the image in units of the reference grid. */
  151. uint_fast32_t height;
  152. /* The horizontal offset from the origin of the reference grid to the
  153. left side of the image area. */
  154. uint_fast32_t xoff;
  155. /* The vertical offset from the origin of the reference grid to the
  156. top side of the image area. */
  157. uint_fast32_t yoff;
  158. /* The nominal width of a tile in units of the reference grid. */
  159. uint_fast32_t tilewidth;
  160. /* The nominal height of a tile in units of the reference grid. */
  161. uint_fast32_t tileheight;
  162. /* The horizontal offset from the origin of the reference grid to the
  163. left side of the first tile. */
  164. uint_fast32_t tilexoff;
  165. /* The vertical offset from the origin of the reference grid to the
  166. top side of the first tile. */
  167. uint_fast32_t tileyoff;
  168. /* The number of components. */
  169. uint_fast16_t numcomps;
  170. /* The per-component information. */
  171. jpc_sizcomp_t *comps;
  172. } jpc_siz_t;
  173. /**************************************\
  174. * COD marker segment parameters.
  175. \**************************************/
  176. /*
  177. * Coding style constants.
  178. */
  179. /* Precincts may be used. */
  180. #define JPC_COX_PRT 0x01
  181. /* SOP marker segments may be used. */
  182. #define JPC_COD_SOP 0x02
  183. /* EPH marker segments may be used. */
  184. #define JPC_COD_EPH 0x04
  185. /*
  186. * Progression order constants.
  187. */
  188. /* Layer-resolution-component-precinct progressive
  189. (i.e., progressive by fidelity). */
  190. #define JPC_COD_LRCPPRG 0
  191. /* Resolution-layer-component-precinct progressive
  192. (i.e., progressive by resolution). */
  193. #define JPC_COD_RLCPPRG 1
  194. /* Resolution-precinct-component-layer progressive. */
  195. #define JPC_COD_RPCLPRG 2
  196. /* Precinct-component-resolution-layer progressive. */
  197. #define JPC_COD_PCRLPRG 3
  198. /* Component-position-resolution-layer progressive. */
  199. #define JPC_COD_CPRLPRG 4
  200. /*
  201. * Code block style constants.
  202. */
  203. #define JPC_COX_LAZY 0x01 /* Selective arithmetic coding bypass. */
  204. #define JPC_COX_RESET 0x02 /* Reset context probabilities. */
  205. #define JPC_COX_TERMALL 0x04 /* Terminate all coding passes. */
  206. #define JPC_COX_VSC 0x08 /* Vertical stripe causal context formation. */
  207. #define JPC_COX_PTERM 0x10 /* Predictable termination. */
  208. #define JPC_COX_SEGSYM 0x20 /* Use segmentation symbols. */
  209. /* Transform constants. */
  210. #define JPC_COX_INS 0x00 /* Irreversible 9/7. */
  211. #define JPC_COX_RFT 0x01 /* Reversible 5/3. */
  212. /* Multicomponent transform constants. */
  213. #define JPC_COD_NOMCT 0x00 /* No multicomponent transform. */
  214. #define JPC_COD_MCT 0x01 /* Multicomponent transform. */
  215. /* Get the code block size value from the code block size exponent. */
  216. #define JPC_COX_CBLKSIZEEXPN(x) ((x) - 2)
  217. /* Get the code block size exponent from the code block size value. */
  218. #define JPC_COX_GETCBLKSIZEEXPN(x) ((x) + 2)
  219. /* Per resolution-level information. */
  220. typedef struct {
  221. /* The packet partition width. */
  222. uint_fast8_t parwidthval;
  223. /* The packet partition height. */
  224. uint_fast8_t parheightval;
  225. } jpc_coxrlvl_t;
  226. /* Per component information. */
  227. typedef struct {
  228. /* The coding style. */
  229. uint_fast8_t csty;
  230. /* The number of decomposition levels. */
  231. uint_fast8_t numdlvls;
  232. /* The nominal code block width specifier. */
  233. uint_fast8_t cblkwidthval;
  234. /* The nominal code block height specifier. */
  235. uint_fast8_t cblkheightval;
  236. /* The style of coding passes. */
  237. uint_fast8_t cblksty;
  238. /* The QMFB employed. */
  239. uint_fast8_t qmfbid;
  240. /* The number of resolution levels. */
  241. int numrlvls;
  242. /* The per-resolution-level information. */
  243. jpc_coxrlvl_t rlvls[JPC_MAXRLVLS];
  244. } jpc_coxcp_t;
  245. /* COD marker segment parameters. */
  246. typedef struct {
  247. /* The general coding style. */
  248. uint_fast8_t csty;
  249. /* The progression order. */
  250. uint_fast8_t prg;
  251. /* The number of layers. */
  252. uint_fast16_t numlyrs;
  253. /* The multicomponent transform. */
  254. uint_fast8_t mctrans;
  255. /* Component-related parameters. */
  256. jpc_coxcp_t compparms;
  257. } jpc_cod_t;
  258. /* COC marker segment parameters. */
  259. typedef struct {
  260. /* The component number. */
  261. uint_fast16_t compno;
  262. /* Component-related parameters. */
  263. jpc_coxcp_t compparms;
  264. } jpc_coc_t;
  265. /**************************************\
  266. * RGN marker segment parameters.
  267. \**************************************/
  268. /* The maxshift ROI style. */
  269. #define JPC_RGN_MAXSHIFT 0x00
  270. typedef struct {
  271. /* The component to which the marker applies. */
  272. uint_fast16_t compno;
  273. /* The ROI style. */
  274. uint_fast8_t roisty;
  275. /* The ROI shift value. */
  276. uint_fast8_t roishift;
  277. } jpc_rgn_t;
  278. /**************************************\
  279. * QCD/QCC marker segment parameters.
  280. \**************************************/
  281. /*
  282. * Quantization style constants.
  283. */
  284. #define JPC_QCX_NOQNT 0 /* No quantization. */
  285. #define JPC_QCX_SIQNT 1 /* Scalar quantization, implicit. */
  286. #define JPC_QCX_SEQNT 2 /* Scalar quantization, explicit. */
  287. /*
  288. * Stepsize manipulation macros.
  289. */
  290. #define JPC_QCX_GETEXPN(x) ((x) >> 11)
  291. #define JPC_QCX_GETMANT(x) ((x) & 0x07ff)
  292. #define JPC_QCX_EXPN(x) (assert(!((x) & (~0x1f))), (((x) & 0x1f) << 11))
  293. #define JPC_QCX_MANT(x) (assert(!((x) & (~0x7ff))), ((x) & 0x7ff))
  294. /* Per component information. */
  295. typedef struct {
  296. /* The quantization style. */
  297. uint_fast8_t qntsty;
  298. /* The number of step sizes. */
  299. int numstepsizes;
  300. /* The step sizes. */
  301. uint_fast16_t *stepsizes;
  302. /* The number of guard bits. */
  303. uint_fast8_t numguard;
  304. } jpc_qcxcp_t;
  305. /* QCC marker segment parameters. */
  306. typedef struct {
  307. /* The component associated with this marker segment. */
  308. uint_fast16_t compno;
  309. /* The parameters. */
  310. jpc_qcxcp_t compparms;
  311. } jpc_qcc_t;
  312. /* QCD marker segment parameters. */
  313. typedef struct {
  314. /* The parameters. */
  315. jpc_qcxcp_t compparms;
  316. } jpc_qcd_t;
  317. /**************************************\
  318. * POD marker segment parameters.
  319. \**************************************/
  320. typedef struct {
  321. /* The progression order. */
  322. uint_fast8_t prgord;
  323. /* The lower bound (inclusive) on the resolution level for the
  324. progression order volume. */
  325. uint_fast8_t rlvlnostart;
  326. /* The upper bound (exclusive) on the resolution level for the
  327. progression order volume. */
  328. uint_fast8_t rlvlnoend;
  329. /* The lower bound (inclusive) on the component for the progression
  330. order volume. */
  331. uint_fast16_t compnostart;
  332. /* The upper bound (exclusive) on the component for the progression
  333. order volume. */
  334. uint_fast16_t compnoend;
  335. /* The upper bound (exclusive) on the layer for the progression
  336. order volume. */
  337. uint_fast16_t lyrnoend;
  338. } jpc_pocpchg_t;
  339. /* An alias for the above type. */
  340. typedef jpc_pocpchg_t jpc_pchg_t;
  341. /* POC marker segment parameters. */
  342. typedef struct {
  343. /* The number of progression order changes. */
  344. int numpchgs;
  345. /* The per-progression-order-change information. */
  346. jpc_pocpchg_t *pchgs;
  347. } jpc_poc_t;
  348. /**************************************\
  349. * PPM/PPT marker segment parameters.
  350. \**************************************/
  351. /* PPM marker segment parameters. */
  352. typedef struct {
  353. /* The index. */
  354. uint_fast8_t ind;
  355. /* The length. */
  356. uint_fast16_t len;
  357. /* The data. */
  358. uchar *data;
  359. } jpc_ppm_t;
  360. /* PPT marker segment parameters. */
  361. typedef struct {
  362. /* The index. */
  363. uint_fast8_t ind;
  364. /* The length. */
  365. uint_fast32_t len;
  366. /* The data. */
  367. unsigned char *data;
  368. } jpc_ppt_t;
  369. /**************************************\
  370. * COM marker segment parameters.
  371. \**************************************/
  372. /*
  373. * Registration IDs.
  374. */
  375. #define JPC_COM_BIN 0x00
  376. #define JPC_COM_LATIN 0x01
  377. typedef struct {
  378. /* The registration ID. */
  379. uint_fast16_t regid;
  380. /* The length of the data in bytes. */
  381. uint_fast16_t len;
  382. /* The data. */
  383. uchar *data;
  384. } jpc_com_t;
  385. /**************************************\
  386. * SOP marker segment parameters.
  387. \**************************************/
  388. typedef struct {
  389. /* The sequence number. */
  390. uint_fast16_t seqno;
  391. } jpc_sop_t;
  392. /**************************************\
  393. * CRG marker segment parameters.
  394. \**************************************/
  395. /* Per component information. */
  396. typedef struct {
  397. /* The horizontal offset. */
  398. uint_fast16_t hoff;
  399. /* The vertical offset. */
  400. uint_fast16_t voff;
  401. } jpc_crgcomp_t;
  402. typedef struct {
  403. /* The number of components. */
  404. int numcomps;
  405. /* Per component information. */
  406. jpc_crgcomp_t *comps;
  407. } jpc_crg_t;
  408. /**************************************\
  409. * Marker segment parameters for unknown marker type.
  410. \**************************************/
  411. typedef struct {
  412. /* The data. */
  413. uchar *data;
  414. /* The length. */
  415. uint_fast16_t len;
  416. } jpc_unk_t;
  417. /**************************************\
  418. * Generic marker segment parameters.
  419. \**************************************/
  420. typedef union {
  421. int soc; /* unused */
  422. jpc_sot_t sot;
  423. int sod; /* unused */
  424. int eoc; /* unused */
  425. jpc_siz_t siz;
  426. jpc_cod_t cod;
  427. jpc_coc_t coc;
  428. jpc_rgn_t rgn;
  429. jpc_qcd_t qcd;
  430. jpc_qcc_t qcc;
  431. jpc_poc_t poc;
  432. /* jpc_plm_t plm; */
  433. /* jpc_plt_t plt; */
  434. jpc_ppm_t ppm;
  435. jpc_ppt_t ppt;
  436. jpc_sop_t sop;
  437. int eph; /* unused */
  438. jpc_com_t com;
  439. jpc_crg_t crg;
  440. jpc_unk_t unk;
  441. } jpc_msparms_t;
  442. /**************************************\
  443. * Marker segment.
  444. \**************************************/
  445. /* Marker segment IDs. */
  446. /* The smallest valid marker value. */
  447. #define JPC_MS_MIN 0xff00
  448. /* The largest valid marker value. */
  449. #define JPC_MS_MAX 0xffff
  450. /* The minimum marker value that cannot occur within packet data. */
  451. #define JPC_MS_INMIN 0xff80
  452. /* The maximum marker value that cannot occur within packet data. */
  453. #define JPC_MS_INMAX 0xffff
  454. /* Delimiting marker segments. */
  455. #define JPC_MS_SOC 0xff4f /* Start of code stream (SOC). */
  456. #define JPC_MS_SOT 0xff90 /* Start of tile-part (SOT). */
  457. #define JPC_MS_SOD 0xff93 /* Start of data (SOD). */
  458. #define JPC_MS_EOC 0xffd9 /* End of code stream (EOC). */
  459. /* Fixed information marker segments. */
  460. #define JPC_MS_SIZ 0xff51 /* Image and tile size (SIZ). */
  461. /* Functional marker segments. */
  462. #define JPC_MS_COD 0xff52 /* Coding style default (COD). */
  463. #define JPC_MS_COC 0xff53 /* Coding style component (COC). */
  464. #define JPC_MS_RGN 0xff5e /* Region of interest (RGN). */
  465. #define JPC_MS_QCD 0xff5c /* Quantization default (QCD). */
  466. #define JPC_MS_QCC 0xff5d /* Quantization component (QCC). */
  467. #define JPC_MS_POC 0xff5f /* Progression order default (POC). */
  468. /* Pointer marker segments. */
  469. #define JPC_MS_TLM 0xff55 /* Tile-part lengths, main header (TLM). */
  470. #define JPC_MS_PLM 0xff57 /* Packet length, main header (PLM). */
  471. #define JPC_MS_PLT 0xff58 /* Packet length, tile-part header (PLT). */
  472. #define JPC_MS_PPM 0xff60 /* Packed packet headers, main header (PPM). */
  473. #define JPC_MS_PPT 0xff61 /* Packet packet headers, tile-part header (PPT). */
  474. /* In bit stream marker segments. */
  475. #define JPC_MS_SOP 0xff91 /* Start of packet (SOP). */
  476. #define JPC_MS_EPH 0xff92 /* End of packet header (EPH). */
  477. /* Informational marker segments. */
  478. #define JPC_MS_CRG 0xff63 /* Component registration (CRG). */
  479. #define JPC_MS_COM 0xff64 /* Comment (COM). */
  480. /* Forward declaration. */
  481. struct jpc_msops_s;
  482. /* Generic marker segment class. */
  483. typedef struct {
  484. /* The type of marker segment. */
  485. uint_fast16_t id;
  486. /* The length of the marker segment. */
  487. uint_fast16_t len;
  488. /* The starting offset within the stream. */
  489. uint_fast32_t off;
  490. /* The parameters of the marker segment. */
  491. jpc_msparms_t parms;
  492. /* The marker segment operations. */
  493. struct jpc_msops_s *ops;
  494. } jpc_ms_t;
  495. /* Marker segment operations (which depend on the marker segment type). */
  496. typedef struct jpc_msops_s {
  497. /* Destroy the marker segment parameters. */
  498. void (*destroyparms)(jpc_ms_t *ms);
  499. /* Get the marker segment parameters from a stream. */
  500. int (*getparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
  501. /* Put the marker segment parameters to a stream. */
  502. int (*putparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
  503. /* Dump the marker segment parameters (for debugging). */
  504. int (*dumpparms)(jpc_ms_t *ms, FILE *out);
  505. } jpc_msops_t;
  506. /******************************************************************************\
  507. * Macros/Functions.
  508. \******************************************************************************/
  509. /* Create a code-stream state object. */
  510. jpc_cstate_t *jpc_cstate_create(void);
  511. /* Destroy a code-stream state object. */
  512. void jpc_cstate_destroy(jpc_cstate_t *cstate);
  513. /* Create a marker segment. */
  514. jpc_ms_t *jpc_ms_create(int type);
  515. /* Destroy a marker segment. */
  516. void jpc_ms_destroy(jpc_ms_t *ms);
  517. /* Does a marker segment have parameters? */
  518. #define JPC_MS_HASPARMS(x) \
  519. (!((x) == JPC_MS_SOC || (x) == JPC_MS_SOD || (x) == JPC_MS_EOC || \
  520. (x) == JPC_MS_EPH || ((x) >= 0xff30 && (x) <= 0xff3f)))
  521. /* Get the marker segment type. */
  522. #define jpc_ms_gettype(ms) \
  523. ((ms)->id)
  524. /* Read a marker segment from a stream. */
  525. jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate);
  526. /* Write a marker segment to a stream. */
  527. int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms);
  528. /* Copy code stream data from one stream to another. */
  529. int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long n);
  530. /* Copy code stream data from one stream to another. */
  531. int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long n);
  532. /* Dump a marker segment (for debugging). */
  533. void jpc_ms_dump(jpc_ms_t *ms, FILE *out);
  534. /* Read a 8-bit unsigned integer from a stream. */
  535. int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val);
  536. /* Read a 16-bit unsigned integer from a stream. */
  537. int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val);
  538. /* Read a 32-bit unsigned integer from a stream. */
  539. int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val);
  540. /* Write a 8-bit unsigned integer to a stream. */
  541. int jpc_putuint8(jas_stream_t *out, uint_fast8_t val);
  542. /* Write a 16-bit unsigned integer to a stream. */
  543. int jpc_putuint16(jas_stream_t *out, uint_fast16_t val);
  544. /* Write a 32-bit unsigned integer to a stream. */
  545. int jpc_putuint32(jas_stream_t *out, uint_fast32_t val);
  546. #endif