~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/3rdparty/libjasper/jpc_cs.h

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
8
/* __START_OF_JASPER_LICENSE__
 
9
 *
 
10
 * JasPer License Version 2.0
 
11
 *
 
12
 * Copyright (c) 2001-2006 Michael David Adams
 
13
 * Copyright (c) 1999-2000 Image Power, Inc.
 
14
 * Copyright (c) 1999-2000 The University of British Columbia
 
15
 *
 
16
 * All rights reserved.
 
17
 *
 
18
 * Permission is hereby granted, free of charge, to any person (the
 
19
 * "User") obtaining a copy of this software and associated documentation
 
20
 * files (the "Software"), to deal in the Software without restriction,
 
21
 * including without limitation the rights to use, copy, modify, merge,
 
22
 * publish, distribute, and/or sell copies of the Software, and to permit
 
23
 * persons to whom the Software is furnished to do so, subject to the
 
24
 * following conditions:
 
25
 *
 
26
 * 1.  The above copyright notices and this permission notice (which
 
27
 * includes the disclaimer below) shall be included in all copies or
 
28
 * substantial portions of the Software.
 
29
 *
 
30
 * 2.  The name of a copyright holder shall not be used to endorse or
 
31
 * promote products derived from the Software without specific prior
 
32
 * written permission.
 
33
 *
 
34
 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
 
35
 * LICENSE.  NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
 
36
 * THIS DISCLAIMER.  THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
 
37
 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 
38
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 
39
 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO
 
40
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
 
41
 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
 
42
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
43
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
44
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  NO ASSURANCES ARE
 
45
 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
 
46
 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
 
47
 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
 
48
 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
 
49
 * PROPERTY RIGHTS OR OTHERWISE.  AS A CONDITION TO EXERCISING THE RIGHTS
 
50
 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
 
51
 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY.  THE SOFTWARE
 
52
 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
 
53
 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
 
54
 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
 
55
 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
 
56
 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
 
57
 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
 
58
 * RISK ACTIVITIES").  THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
 
59
 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
 
60
 *
 
61
 * __END_OF_JASPER_LICENSE__
 
62
 */
 
63
 
 
64
/*
 
65
 * JPEG-2000 Code Stream Library
 
66
 *
 
67
 * $Id: jpc_cs.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
 
68
 */
 
69
 
 
70
#ifndef JPC_CS_H
 
71
#define JPC_CS_H
 
72
 
 
73
/******************************************************************************\
 
74
* Includes.
 
75
\******************************************************************************/
 
76
 
 
77
#include "jasper/jas_image.h"
 
78
#include "jasper/jas_stream.h"
 
79
 
 
80
#include "jpc_cod.h"
 
81
 
 
82
/******************************************************************************\
 
83
* Constants and Types.
 
84
\******************************************************************************/
 
85
 
 
86
/* The maximum number of resolution levels. */
 
87
#define JPC_MAXRLVLS    33
 
88
 
 
89
/* The maximum number of bands. */
 
90
#define JPC_MAXBANDS    (3 * JPC_MAXRLVLS + 1)
 
91
 
 
92
/* The maximum number of layers. */
 
93
#define JPC_MAXLYRS     16384
 
94
 
 
95
/**************************************\
 
96
* Code stream.
 
97
\**************************************/
 
98
 
 
99
/*
 
100
 * Code stream states.
 
101
 */
 
102
 
 
103
/* Initial. */
 
104
#define JPC_CS_INIT     0
 
105
/* Main header. */
 
106
#define JPC_CS_MHDR     1
 
107
/* Tile-part header. */
 
108
#define JPC_CS_THDR     2
 
109
/* Main trailer. */
 
110
#define JPC_CS_MTLR     3
 
111
/* Tile-part data. */
 
112
#define JPC_CS_TDATA    4
 
113
 
 
114
/*
 
115
 * Unfortunately, the code stream syntax was not designed in such a way that
 
116
 * any given marker segment can be correctly decoded without additional state
 
117
 * derived from previously decoded marker segments.
 
118
 * For example, a RGN/COC/QCC marker segment cannot be decoded unless the
 
119
 * number of components is known.
 
120
 */
 
121
 
 
122
/*
 
123
 * Code stream state information.
 
124
 */
 
125
 
 
126
typedef struct {
 
127
 
 
128
    /* The number of components. */
 
129
    uint_fast16_t numcomps;
 
130
 
 
131
} jpc_cstate_t;
 
132
 
 
133
/**************************************\
 
134
* SOT marker segment parameters.
 
135
\**************************************/
 
136
 
 
137
typedef struct {
 
138
 
 
139
    /* The tile number. */
 
140
    uint_fast16_t tileno;
 
141
 
 
142
    /* The combined length of the marker segment and its auxilary data
 
143
      (i.e., packet data). */
 
144
    uint_fast32_t len;
 
145
 
 
146
    /* The tile-part instance. */
 
147
    uint_fast8_t partno;
 
148
 
 
149
    /* The number of tile-parts. */
 
150
    uint_fast8_t numparts;
 
151
 
 
152
} jpc_sot_t;
 
153
 
 
154
/**************************************\
 
155
* SIZ marker segment parameters.
 
156
\**************************************/
 
157
 
 
158
/* Per component information. */
 
159
 
 
160
typedef struct {
 
161
 
 
162
    /* The precision of the samples. */
 
163
    uint_fast8_t prec;
 
164
 
 
165
    /* The signedness of the samples. */
 
166
    uint_fast8_t sgnd;
 
167
 
 
168
    /* The horizontal separation of samples with respect to the reference
 
169
      grid. */
 
170
    uint_fast8_t hsamp;
 
171
 
 
172
    /* The vertical separation of samples with respect to the reference
 
173
      grid. */
 
174
    uint_fast8_t vsamp;
 
175
 
 
176
} jpc_sizcomp_t;
 
177
 
 
178
/* SIZ marker segment parameters. */
 
179
 
 
180
typedef struct {
 
181
 
 
182
    /* The code stream capabilities. */
 
183
    uint_fast16_t caps;
 
184
 
 
185
    /* The width of the image in units of the reference grid. */
 
186
    uint_fast32_t width;
 
187
 
 
188
    /* The height of the image in units of the reference grid. */
 
189
    uint_fast32_t height;
 
190
 
 
191
    /* The horizontal offset from the origin of the reference grid to the
 
192
      left side of the image area. */
 
193
    uint_fast32_t xoff;
 
194
 
 
195
    /* The vertical offset from the origin of the reference grid to the
 
196
      top side of the image area. */
 
197
    uint_fast32_t yoff;
 
198
 
 
199
    /* The nominal width of a tile in units of the reference grid. */
 
200
    uint_fast32_t tilewidth;
 
201
 
 
202
    /* The nominal height of a tile in units of the reference grid. */
 
203
    uint_fast32_t tileheight;
 
204
 
 
205
    /* The horizontal offset from the origin of the reference grid to the
 
206
      left side of the first tile. */
 
207
    uint_fast32_t tilexoff;
 
208
 
 
209
    /* The vertical offset from the origin of the reference grid to the
 
210
      top side of the first tile. */
 
211
    uint_fast32_t tileyoff;
 
212
 
 
213
    /* The number of components. */
 
214
    uint_fast16_t numcomps;
 
215
 
 
216
    /* The per-component information. */
 
217
    jpc_sizcomp_t *comps;
 
218
 
 
219
} jpc_siz_t;
 
220
 
 
221
/**************************************\
 
222
* COD marker segment parameters.
 
223
\**************************************/
 
224
 
 
225
/*
 
226
 * Coding style constants.
 
227
 */
 
228
 
 
229
/* Precincts may be used. */
 
230
#define JPC_COX_PRT     0x01
 
231
/* SOP marker segments may be used. */
 
232
#define JPC_COD_SOP     0x02
 
233
/* EPH marker segments may be used. */
 
234
#define JPC_COD_EPH     0x04
 
235
 
 
236
/*
 
237
 * Progression order constants.
 
238
 */
 
239
 
 
240
/* Layer-resolution-component-precinct progressive
 
241
  (i.e., progressive by fidelity). */
 
242
#define JPC_COD_LRCPPRG 0
 
243
/* Resolution-layer-component-precinct progressive
 
244
  (i.e., progressive by resolution). */
 
245
#define JPC_COD_RLCPPRG 1
 
246
/* Resolution-precinct-component-layer progressive. */
 
247
#define JPC_COD_RPCLPRG 2
 
248
/* Precinct-component-resolution-layer progressive. */
 
249
#define JPC_COD_PCRLPRG 3
 
250
/* Component-position-resolution-layer progressive. */
 
251
#define JPC_COD_CPRLPRG 4
 
252
 
 
253
/*
 
254
 * Code block style constants.
 
255
 */
 
256
 
 
257
#define JPC_COX_LAZY    0x01 /* Selective arithmetic coding bypass. */
 
258
#define JPC_COX_RESET   0x02 /* Reset context probabilities. */
 
259
#define JPC_COX_TERMALL 0x04 /* Terminate all coding passes. */
 
260
#define JPC_COX_VSC             0x08 /* Vertical stripe causal context formation. */
 
261
#define JPC_COX_PTERM   0x10 /* Predictable termination. */
 
262
#define JPC_COX_SEGSYM  0x20 /* Use segmentation symbols. */
 
263
 
 
264
/* Transform constants. */
 
265
#define JPC_COX_INS     0x00 /* Irreversible 9/7. */
 
266
#define JPC_COX_RFT     0x01 /* Reversible 5/3. */
 
267
 
 
268
/* Multicomponent transform constants. */
 
269
#define JPC_COD_NOMCT   0x00 /* No multicomponent transform. */
 
270
#define JPC_COD_MCT             0x01 /* Multicomponent transform. */
 
271
 
 
272
/* Get the code block size value from the code block size exponent. */
 
273
#define JPC_COX_CBLKSIZEEXPN(x)         ((x) - 2)
 
274
/* Get the code block size exponent from the code block size value. */
 
275
#define JPC_COX_GETCBLKSIZEEXPN(x)      ((x) + 2)
 
276
 
 
277
/* Per resolution-level information. */
 
278
 
 
279
typedef struct {
 
280
 
 
281
    /* The packet partition width. */
 
282
    uint_fast8_t parwidthval;
 
283
 
 
284
    /* The packet partition height. */
 
285
    uint_fast8_t parheightval;
 
286
 
 
287
} jpc_coxrlvl_t;
 
288
 
 
289
/* Per component information. */
 
290
 
 
291
typedef struct {
 
292
 
 
293
    /* The coding style. */
 
294
    uint_fast8_t csty;
 
295
 
 
296
    /* The number of decomposition levels. */
 
297
    uint_fast8_t numdlvls;
 
298
 
 
299
    /* The nominal code block width specifier. */
 
300
    uint_fast8_t cblkwidthval;
 
301
 
 
302
    /* The nominal code block height specifier. */
 
303
    uint_fast8_t cblkheightval;
 
304
 
 
305
    /* The style of coding passes. */
 
306
    uint_fast8_t cblksty;
 
307
 
 
308
    /* The QMFB employed. */
 
309
    uint_fast8_t qmfbid;
 
310
 
 
311
    /* The number of resolution levels. */
 
312
    int numrlvls;
 
313
 
 
314
    /* The per-resolution-level information. */
 
315
    jpc_coxrlvl_t rlvls[JPC_MAXRLVLS];
 
316
 
 
317
} jpc_coxcp_t;
 
318
 
 
319
/* COD marker segment parameters. */
 
320
 
 
321
typedef struct {
 
322
 
 
323
    /* The general coding style. */
 
324
    uint_fast8_t csty;
 
325
 
 
326
    /* The progression order. */
 
327
    uint_fast8_t prg;
 
328
 
 
329
    /* The number of layers. */
 
330
    uint_fast16_t numlyrs;
 
331
 
 
332
    /* The multicomponent transform. */
 
333
    uint_fast8_t mctrans;
 
334
 
 
335
    /* Component-related parameters. */
 
336
    jpc_coxcp_t compparms;
 
337
 
 
338
} jpc_cod_t;
 
339
 
 
340
/* COC marker segment parameters. */
 
341
 
 
342
typedef struct {
 
343
 
 
344
    /* The component number. */
 
345
    uint_fast16_t compno;
 
346
 
 
347
    /* Component-related parameters. */
 
348
    jpc_coxcp_t compparms;
 
349
 
 
350
} jpc_coc_t;
 
351
 
 
352
/**************************************\
 
353
* RGN marker segment parameters.
 
354
\**************************************/
 
355
 
 
356
/* The maxshift ROI style. */
 
357
#define JPC_RGN_MAXSHIFT        0x00
 
358
 
 
359
typedef struct {
 
360
 
 
361
    /* The component to which the marker applies. */
 
362
    uint_fast16_t compno;
 
363
 
 
364
    /* The ROI style. */
 
365
    uint_fast8_t roisty;
 
366
 
 
367
    /* The ROI shift value. */
 
368
    uint_fast8_t roishift;
 
369
 
 
370
} jpc_rgn_t;
 
371
 
 
372
/**************************************\
 
373
* QCD/QCC marker segment parameters.
 
374
\**************************************/
 
375
 
 
376
/*
 
377
 * Quantization style constants.
 
378
 */
 
379
 
 
380
#define JPC_QCX_NOQNT   0 /* No quantization. */
 
381
#define JPC_QCX_SIQNT   1 /* Scalar quantization, implicit. */
 
382
#define JPC_QCX_SEQNT   2 /* Scalar quantization, explicit. */
 
383
 
 
384
/*
 
385
 * Stepsize manipulation macros.
 
386
 */
 
387
 
 
388
#define JPC_QCX_GETEXPN(x)      ((x) >> 11)
 
389
#define JPC_QCX_GETMANT(x)      ((x) & 0x07ff)
 
390
#define JPC_QCX_EXPN(x)         (assert(!((x) & (~0x1f))), (((x) & 0x1f) << 11))
 
391
#define JPC_QCX_MANT(x)         (assert(!((x) & (~0x7ff))), ((x) & 0x7ff))
 
392
 
 
393
/* Per component information. */
 
394
 
 
395
typedef struct {
 
396
 
 
397
    /* The quantization style. */
 
398
    uint_fast8_t qntsty;
 
399
 
 
400
    /* The number of step sizes. */
 
401
    int numstepsizes;
 
402
 
 
403
    /* The step sizes. */
 
404
    uint_fast16_t *stepsizes;
 
405
 
 
406
    /* The number of guard bits. */
 
407
    uint_fast8_t numguard;
 
408
 
 
409
} jpc_qcxcp_t;
 
410
 
 
411
/* QCC marker segment parameters. */
 
412
 
 
413
typedef struct {
 
414
 
 
415
    /* The component associated with this marker segment. */
 
416
    uint_fast16_t compno;
 
417
 
 
418
    /* The parameters. */
 
419
    jpc_qcxcp_t compparms;
 
420
 
 
421
} jpc_qcc_t;
 
422
 
 
423
/* QCD marker segment parameters. */
 
424
 
 
425
typedef struct {
 
426
 
 
427
    /* The parameters. */
 
428
    jpc_qcxcp_t compparms;
 
429
 
 
430
} jpc_qcd_t;
 
431
 
 
432
/**************************************\
 
433
* POD marker segment parameters.
 
434
\**************************************/
 
435
 
 
436
typedef struct {
 
437
 
 
438
    /* The progression order. */
 
439
    uint_fast8_t prgord;
 
440
 
 
441
    /* The lower bound (inclusive) on the resolution level for the
 
442
      progression order volume. */
 
443
    uint_fast8_t rlvlnostart;
 
444
 
 
445
    /* The upper bound (exclusive) on the resolution level for the
 
446
      progression order volume. */
 
447
    uint_fast8_t rlvlnoend;
 
448
 
 
449
    /* The lower bound (inclusive) on the component for the progression
 
450
      order volume. */
 
451
    uint_fast16_t compnostart;
 
452
 
 
453
    /* The upper bound (exclusive) on the component for the progression
 
454
      order volume. */
 
455
    uint_fast16_t compnoend;
 
456
 
 
457
    /* The upper bound (exclusive) on the layer for the progression
 
458
      order volume. */
 
459
    uint_fast16_t lyrnoend;
 
460
 
 
461
} jpc_pocpchg_t;
 
462
 
 
463
/* An alias for the above type. */
 
464
typedef jpc_pocpchg_t jpc_pchg_t;
 
465
 
 
466
/* POC marker segment parameters. */
 
467
 
 
468
typedef struct {
 
469
 
 
470
    /* The number of progression order changes. */
 
471
    int numpchgs;
 
472
 
 
473
    /* The per-progression-order-change information. */
 
474
    jpc_pocpchg_t *pchgs;
 
475
 
 
476
} jpc_poc_t;
 
477
 
 
478
/**************************************\
 
479
* PPM/PPT marker segment parameters.
 
480
\**************************************/
 
481
 
 
482
/* PPM marker segment parameters. */
 
483
 
 
484
typedef struct {
 
485
 
 
486
    /* The index. */
 
487
    uint_fast8_t ind;
 
488
 
 
489
    /* The length. */
 
490
    uint_fast16_t len;
 
491
 
 
492
    /* The data. */
 
493
    uchar *data;
 
494
 
 
495
} jpc_ppm_t;
 
496
 
 
497
/* PPT marker segment parameters. */
 
498
 
 
499
typedef struct {
 
500
 
 
501
    /* The index. */
 
502
    uint_fast8_t ind;
 
503
 
 
504
    /* The length. */
 
505
    uint_fast32_t len;
 
506
 
 
507
    /* The data. */
 
508
    unsigned char *data;
 
509
 
 
510
} jpc_ppt_t;
 
511
 
 
512
/**************************************\
 
513
* COM marker segment parameters.
 
514
\**************************************/
 
515
 
 
516
/*
 
517
 * Registration IDs.
 
518
 */
 
519
 
 
520
#define JPC_COM_BIN             0x00
 
521
#define JPC_COM_LATIN   0x01
 
522
 
 
523
typedef struct {
 
524
 
 
525
    /* The registration ID. */
 
526
    uint_fast16_t regid;
 
527
 
 
528
    /* The length of the data in bytes. */
 
529
    uint_fast16_t len;
 
530
 
 
531
    /* The data. */
 
532
    uchar *data;
 
533
 
 
534
} jpc_com_t;
 
535
 
 
536
/**************************************\
 
537
* SOP marker segment parameters.
 
538
\**************************************/
 
539
 
 
540
typedef struct {
 
541
 
 
542
    /* The sequence number. */
 
543
    uint_fast16_t seqno;
 
544
 
 
545
} jpc_sop_t;
 
546
 
 
547
/**************************************\
 
548
* CRG marker segment parameters.
 
549
\**************************************/
 
550
 
 
551
/* Per component information. */
 
552
 
 
553
typedef struct {
 
554
 
 
555
    /* The horizontal offset. */
 
556
    uint_fast16_t hoff;
 
557
 
 
558
    /* The vertical offset. */
 
559
    uint_fast16_t voff;
 
560
 
 
561
} jpc_crgcomp_t;
 
562
 
 
563
typedef struct {
 
564
 
 
565
    /* The number of components. */
 
566
    int numcomps;
 
567
 
 
568
    /* Per component information. */
 
569
    jpc_crgcomp_t *comps;
 
570
 
 
571
} jpc_crg_t;
 
572
 
 
573
/**************************************\
 
574
* Marker segment parameters for unknown marker type.
 
575
\**************************************/
 
576
 
 
577
typedef struct {
 
578
 
 
579
    /* The data. */
 
580
    uchar *data;
 
581
 
 
582
    /* The length. */
 
583
    uint_fast16_t len;
 
584
 
 
585
} jpc_unk_t;
 
586
 
 
587
/**************************************\
 
588
* Generic marker segment parameters.
 
589
\**************************************/
 
590
 
 
591
typedef union {
 
592
    int soc;    /* unused */
 
593
    jpc_sot_t sot;
 
594
    int sod;    /* unused */
 
595
    int eoc;    /* unused */
 
596
    jpc_siz_t siz;
 
597
    jpc_cod_t cod;
 
598
    jpc_coc_t coc;
 
599
    jpc_rgn_t rgn;
 
600
    jpc_qcd_t qcd;
 
601
    jpc_qcc_t qcc;
 
602
    jpc_poc_t poc;
 
603
    /* jpc_plm_t plm; */
 
604
    /* jpc_plt_t plt; */
 
605
    jpc_ppm_t ppm;
 
606
    jpc_ppt_t ppt;
 
607
    jpc_sop_t sop;
 
608
    int eph;    /* unused */
 
609
    jpc_com_t com;
 
610
    jpc_crg_t crg;
 
611
    jpc_unk_t unk;
 
612
} jpc_msparms_t;
 
613
 
 
614
/**************************************\
 
615
* Marker segment.
 
616
\**************************************/
 
617
 
 
618
/* Marker segment IDs. */
 
619
 
 
620
/* The smallest valid marker value. */
 
621
#define JPC_MS_MIN      0xff00
 
622
 
 
623
/* The largest valid marker value. */
 
624
#define JPC_MS_MAX      0xffff
 
625
 
 
626
/* The minimum marker value that cannot occur within packet data. */
 
627
#define JPC_MS_INMIN    0xff80
 
628
/* The maximum marker value that cannot occur within packet data. */
 
629
#define JPC_MS_INMAX    0xffff
 
630
 
 
631
/* Delimiting marker segments. */
 
632
#define JPC_MS_SOC      0xff4f /* Start of code stream (SOC). */
 
633
#define JPC_MS_SOT      0xff90 /* Start of tile-part (SOT). */
 
634
#define JPC_MS_SOD      0xff93 /* Start of data (SOD). */
 
635
#define JPC_MS_EOC      0xffd9 /* End of code stream (EOC). */
 
636
 
 
637
/* Fixed information marker segments. */
 
638
#define JPC_MS_SIZ      0xff51 /* Image and tile size (SIZ). */
 
639
 
 
640
/* Functional marker segments. */
 
641
#define JPC_MS_COD      0xff52 /* Coding style default (COD). */
 
642
#define JPC_MS_COC      0xff53 /* Coding style component (COC). */
 
643
#define JPC_MS_RGN      0xff5e /* Region of interest (RGN). */
 
644
#define JPC_MS_QCD      0xff5c /* Quantization default (QCD). */
 
645
#define JPC_MS_QCC      0xff5d /* Quantization component (QCC). */
 
646
#define JPC_MS_POC      0xff5f /* Progression order default (POC). */
 
647
 
 
648
/* Pointer marker segments. */
 
649
#define JPC_MS_TLM      0xff55 /* Tile-part lengths, main header (TLM). */
 
650
#define JPC_MS_PLM      0xff57 /* Packet length, main header (PLM). */
 
651
#define JPC_MS_PLT      0xff58 /* Packet length, tile-part header (PLT). */
 
652
#define JPC_MS_PPM      0xff60 /* Packed packet headers, main header (PPM). */
 
653
#define JPC_MS_PPT      0xff61 /* Packet packet headers, tile-part header (PPT). */
 
654
 
 
655
/* In bit stream marker segments. */
 
656
#define JPC_MS_SOP      0xff91  /* Start of packet (SOP). */
 
657
#define JPC_MS_EPH      0xff92  /* End of packet header (EPH). */
 
658
 
 
659
/* Informational marker segments. */
 
660
#define JPC_MS_CRG      0xff63 /* Component registration (CRG). */
 
661
#define JPC_MS_COM      0xff64 /* Comment (COM). */
 
662
 
 
663
/* Forward declaration. */
 
664
struct jpc_msops_s;
 
665
 
 
666
/* Generic marker segment class. */
 
667
 
 
668
typedef struct {
 
669
 
 
670
    /* The type of marker segment. */
 
671
    uint_fast16_t id;
 
672
 
 
673
    /* The length of the marker segment. */
 
674
    uint_fast16_t len;
 
675
 
 
676
    /* The starting offset within the stream. */
 
677
    uint_fast32_t off;
 
678
 
 
679
    /* The parameters of the marker segment. */
 
680
    jpc_msparms_t parms;
 
681
 
 
682
    /* The marker segment operations. */
 
683
    struct jpc_msops_s *ops;
 
684
 
 
685
} jpc_ms_t;
 
686
 
 
687
/* Marker segment operations (which depend on the marker segment type). */
 
688
 
 
689
typedef struct jpc_msops_s {
 
690
 
 
691
    /* Destroy the marker segment parameters. */
 
692
    void (*destroyparms)(jpc_ms_t *ms);
 
693
 
 
694
    /* Get the marker segment parameters from a stream. */
 
695
    int (*getparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
 
696
 
 
697
    /* Put the marker segment parameters to a stream. */
 
698
    int (*putparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
 
699
 
 
700
    /* Dump the marker segment parameters (for debugging). */
 
701
    int (*dumpparms)(jpc_ms_t *ms, FILE *out);
 
702
 
 
703
} jpc_msops_t;
 
704
 
 
705
/******************************************************************************\
 
706
* Macros/Functions.
 
707
\******************************************************************************/
 
708
 
 
709
/* Create a code-stream state object. */
 
710
jpc_cstate_t *jpc_cstate_create(void);
 
711
 
 
712
/* Destroy a code-stream state object. */
 
713
void jpc_cstate_destroy(jpc_cstate_t *cstate);
 
714
 
 
715
/* Create a marker segment. */
 
716
jpc_ms_t *jpc_ms_create(int type);
 
717
 
 
718
/* Destroy a marker segment. */
 
719
void jpc_ms_destroy(jpc_ms_t *ms);
 
720
 
 
721
/* Does a marker segment have parameters? */
 
722
#define JPC_MS_HASPARMS(x) \
 
723
    (!((x) == JPC_MS_SOC || (x) == JPC_MS_SOD || (x) == JPC_MS_EOC || \
 
724
      (x) == JPC_MS_EPH || ((x) >= 0xff30 && (x) <= 0xff3f)))
 
725
 
 
726
/* Get the marker segment type. */
 
727
#define jpc_ms_gettype(ms) \
 
728
    ((ms)->id)
 
729
 
 
730
/* Read a marker segment from a stream. */
 
731
jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate);
 
732
 
 
733
/* Write a marker segment to a stream. */
 
734
int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms);
 
735
 
 
736
/* Copy code stream data from one stream to another. */
 
737
int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long n);
 
738
 
 
739
/* Copy code stream data from one stream to another. */
 
740
int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long n);
 
741
 
 
742
/* Dump a marker segment (for debugging). */
 
743
void jpc_ms_dump(jpc_ms_t *ms, FILE *out);
 
744
 
 
745
/* Read a 8-bit unsigned integer from a stream. */
 
746
int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val);
 
747
 
 
748
/* Read a 16-bit unsigned integer from a stream. */
 
749
int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val);
 
750
 
 
751
/* Read a 32-bit unsigned integer from a stream. */
 
752
int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val);
 
753
 
 
754
/* Write a 8-bit unsigned integer to a stream. */
 
755
int jpc_putuint8(jas_stream_t *out, uint_fast8_t val);
 
756
 
 
757
/* Write a 16-bit unsigned integer to a stream. */
 
758
int jpc_putuint16(jas_stream_t *out, uint_fast16_t val);
 
759
 
 
760
/* Write a 32-bit unsigned integer to a stream. */
 
761
int jpc_putuint32(jas_stream_t *out, uint_fast32_t val);
 
762
 
 
763
#endif