2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2002-2003, Yannick Verschueren
10 * Copyright (c) 2005, Herve Drolon, FreeImage Team
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 #include "opj_includes.h"
38 * Read the information contains in VBAS [JPP/JPT stream message header]
39 * Store information (7 bits) in value
42 static unsigned int jpt_read_VBAS_info(opj_cio_t *cio, unsigned int value) {
45 elmt = cio_read(cio, 1);
46 while ((elmt >> 7) == 1) {
48 value |= (elmt & 0x7f);
49 elmt = cio_read(cio, 1);
52 value |= (elmt & 0x7f);
58 * Initialize the value of the message header structure
61 void jpt_init_msg_header(opj_jpt_msg_header_t * header) {
62 header->Id = 0; /* In-class Identifier */
63 header->last_byte = 0; /* Last byte information */
64 header->Class_Id = 0; /* Class Identifier */
65 header->CSn_Id = 0; /* CSn : index identifier */
66 header->Msg_offset = 0; /* Message offset */
67 header->Msg_length = 0; /* Message length */
68 header->Layer_nb = 0; /* Auxiliary for JPP case */
72 * Re-initialize the value of the message header structure
74 * Only parameters always present in message header
77 static void jpt_reinit_msg_header(opj_jpt_msg_header_t * header) {
78 header->Id = 0; /* In-class Identifier */
79 header->last_byte = 0; /* Last byte information */
80 header->Msg_offset = 0; /* Message offset */
81 header->Msg_length = 0; /* Message length */
85 * Read the message header for a JPP/JPT - stream
88 void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header) {
89 unsigned char elmt, Class = 0, CSn = 0;
90 jpt_reinit_msg_header(header);
95 elmt = cio_read(cio, 1);
97 /* See for Class and CSn */
98 switch ((elmt >> 5) & 0x03) {
100 opj_event_msg(cinfo, EVT_ERROR, "Forbidden value encounter in message header !!\n");
118 /* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
119 if (((elmt >> 4) & 0x01) == 1)
120 header->last_byte = 1;
122 /* In-class identifier */
123 header->Id |= (elmt & 0x0f);
124 if ((elmt >> 7) == 1)
125 header->Id = jpt_read_VBAS_info(cio, header->Id);
131 header->Class_Id = 0;
132 header->Class_Id = jpt_read_VBAS_info(cio, header->Class_Id);
140 header->CSn_Id = jpt_read_VBAS_info(cio, header->CSn_Id);
143 /* ----------------- */
144 /* VBAS : Msg_offset */
145 /* ----------------- */
146 header->Msg_offset = jpt_read_VBAS_info(cio, header->Msg_offset);
148 /* ----------------- */
149 /* VBAS : Msg_length */
150 /* ----------------- */
151 header->Msg_length = jpt_read_VBAS_info(cio, header->Msg_length);
156 if ((header->Class_Id & 0x01) == 1) {
157 header->Layer_nb = 0;
158 header->Layer_nb = jpt_read_VBAS_info(cio, header->Layer_nb);