2
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3
* Copyright (c) 2002-2007, Professor Benoit Macq
4
* Copyright (c) 2002-2003, Yannick Verschueren
5
* Copyright (c) 2005, Herve Drolon, FreeImage Team
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
11
* 1. Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* 2. Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in the
15
* documentation and/or other materials provided with the distribution.
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
18
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
* POSSIBILITY OF SUCH DAMAGE.
30
#include "opj_includes.h"
33
* Read the information contains in VBAS [JPP/JPT stream message header]
34
* Store information (7 bits) in value
37
unsigned int jpt_read_VBAS_info(opj_cio_t *cio, unsigned int value) {
40
elmt = cio_read(cio, 1);
41
while ((elmt >> 7) == 1) {
43
value |= (elmt & 0x7f);
44
elmt = cio_read(cio, 1);
47
value |= (elmt & 0x7f);
53
* Initialize the value of the message header structure
56
void jpt_init_msg_header(opj_jpt_msg_header_t * header) {
57
header->Id = 0; /* In-class Identifier */
58
header->last_byte = 0; /* Last byte information */
59
header->Class_Id = 0; /* Class Identifier */
60
header->CSn_Id = 0; /* CSn : index identifier */
61
header->Msg_offset = 0; /* Message offset */
62
header->Msg_length = 0; /* Message length */
63
header->Layer_nb = 0; /* Auxiliary for JPP case */
67
* Re-initialize the value of the message header structure
69
* Only parameters always present in message header
72
void jpt_reinit_msg_header(opj_jpt_msg_header_t * header) {
73
header->Id = 0; /* In-class Identifier */
74
header->last_byte = 0; /* Last byte information */
75
header->Msg_offset = 0; /* Message offset */
76
header->Msg_length = 0; /* Message length */
80
* Read the message header for a JPP/JPT - stream
83
void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header) {
84
unsigned char elmt, Class = 0, CSn = 0;
85
jpt_reinit_msg_header(header);
90
elmt = cio_read(cio, 1);
92
/* See for Class and CSn */
93
switch ((elmt >> 5) & 0x03) {
95
opj_event_msg(cinfo, EVT_ERROR, "Forbidden value encounter in message header !!\n");
113
/* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
114
if (((elmt >> 4) & 0x01) == 1)
115
header->last_byte = 1;
117
/* In-class identifier */
118
header->Id |= (elmt & 0x0f);
119
if ((elmt >> 7) == 1)
120
header->Id = jpt_read_VBAS_info(cio, header->Id);
126
header->Class_Id = 0;
127
header->Class_Id = jpt_read_VBAS_info(cio, header->Class_Id);
135
header->CSn_Id = jpt_read_VBAS_info(cio, header->CSn_Id);
138
/* ----------------- */
139
/* VBAS : Msg_offset */
140
/* ----------------- */
141
header->Msg_offset = jpt_read_VBAS_info(cio, header->Msg_offset);
143
/* ----------------- */
144
/* VBAS : Msg_length */
145
/* ----------------- */
146
header->Msg_length = jpt_read_VBAS_info(cio, header->Msg_length);
151
if ((header->Class_Id & 0x01) == 1) {
152
header->Layer_nb = 0;
153
header->Layer_nb = jpt_read_VBAS_info(cio, header->Layer_nb);