OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
ojph_codestream.cpp
Go to the documentation of this file.
1//***************************************************************************/
2// This software is released under the 2-Clause BSD license, included
3// below.
4//
5// Copyright (c) 2019, Aous Naman
6// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
7// Copyright (c) 2019, The University of New South Wales, Australia
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13// 1. Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
16// 2. Redistributions in binary form must reproduce the above copyright
17// notice, this list of conditions and the following disclaimer in the
18// documentation and/or other materials provided with the distribution.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//***************************************************************************/
32// This file is part of the OpenJPH software implementation.
33// File: ojph_codestream.cpp
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38
39#include <climits>
40#include <cmath>
41
42#include "ojph_mem.h"
43#include "ojph_params.h"
44#include "ojph_codestream.h"
46
47namespace ojph {
48
50 //
51 //
52 //
53 //
54 //
56
59 {
60 if (state)
61 delete state;
62 state = NULL;
63 }
64
70
73 {
74 assert(state != NULL);
75 state->restart();
76 }
77
80 {
81 return param_siz(&state->siz);
82 }
83
86 {
87 return param_cod(&state->cod);
88 }
89
92 {
93 return param_qcd(&state->qcd);
94 }
95
98 {
99 return param_nlt(&state->nlt);
100 }
101
103 void codestream::set_planar(bool planar)
104 {
105 state->set_planar(planar ? 1 : 0);
106 }
107
109 void codestream::set_profile(const char *s)
110 {
111 state->set_profile(s);
112 }
113
115 void codestream::set_tilepart_divisions(bool at_resolutions,
116 bool at_components)
117 {
118 ui32 value = 0;
119 if (at_resolutions)
121 if (at_components)
123 state->set_tilepart_divisions(value);
124 }
125
128 {
129 ui32 res = state->get_tilepart_div() & OJPH_TILEPART_RESOLUTIONS;
130 return res ? true : false;
131 }
132
135 {
136 ui32 comp = state->get_tilepart_div() & OJPH_TILEPART_COMPONENTS;
137 return comp ? true : false;
138 }
139
142 {
143 state->request_tlm_marker(needed);
144 }
145
148 {
149 return state->is_tlm_needed();
150 }
151
154 {
155 return state->is_planar();
156 }
157
160 const comment_exchange* comments,
161 ui32 num_comments)
162 {
163 state->write_headers(file, comments, num_comments);
164 }
165
168 {
169 state->enable_resilience();
170 }
171
174 {
175 state->read_headers(file);
176 }
177
180 ui32 skipped_res_for_recon)
181 {
182 state->restrict_input_resolution(skipped_res_for_read,
183 skipped_res_for_recon);
184 }
185
188 {
189 state->read();
190 }
191
194 {
195 return state->pull(comp_num);
196 }
197
198
201 {
202 state->flush();
203 }
204
207 {
208 state->close();
209 }
210
213 {
214 return state->exchange(line, next_component);
215 }
216
217}
param_siz access_siz()
Returns the underlying SIZ marker segment object.
param_cod access_cod()
Returns the underlying COD marker segment object.
void restrict_input_resolution(ui32 skipped_res_for_data, ui32 skipped_res_for_recon)
This function restricts resolution decoding for a codestream. It is for a reading (decoding) codestre...
bool is_tilepart_division_at_resolutions()
Query if the tile will be partitioned at resolution boundary.
local::codestream * state
void close()
Call this function to close the underlying file; works for both encoding and decoding codestreams.
void set_planar(bool planar)
Sets the sequence of pushing or pull rows from the machinery.
~codestream()
default destructor
void enable_resilience()
This enables codestream resilience; that is, the library tries its best to decode the codestream,...
line_buf * exchange(line_buf *line, ui32 &next_component)
This call is used to send image data rows to the library. We expect to send one row from a single com...
void request_tlm_marker(bool needed)
Request the addition of the optional TLM marker segment. This request should occur before writing cod...
codestream()
default constructor
void set_profile(const char *s)
Sets the codestream profile.
param_qcd access_qcd()
Returns the underlying QCD marker segment object.
bool is_tilepart_division_at_components()
Query if the tile will be partitioned at component boundary.
void read_headers(infile_base *file)
This call reads the headers of a codestream. It is for a reading (or decoding) codestream,...
void set_tilepart_divisions(bool at_resolutions, bool at_components)
Sets the locations where a tile is partitioned into tile parts.
bool is_tlm_requested()
Query if the optional TLM marker segment is to be added.
void write_headers(outfile_base *file, const comment_exchange *comments=NULL, ui32 num_comments=0)
Writes codestream headers when the codestream is used for writing. This function should be called aft...
void create()
This call is for a decoding (or reading) codestream. Call this function after calling restrict_input_...
param_nlt access_nlt()
Returns the underlying NLT marker segment object.
bool is_planar() const
Query if the codestream extraction is planar or not. See the documentation for ojph::codestream::set_...
void flush()
This is the last call to a writing (encoding) codestream. This will write encoded bitstream data to t...
void restart()
Restarts the codestream.
line_buf * pull(ui32 &comp_num)
This call is to pull one row from the codestream, being decoded. The returned line_buf object holds o...
non-linearity point transformation object (implements NLT marker segment)
Quantization parameters object.
@ OJPH_TILEPART_RESOLUTIONS
@ OJPH_TILEPART_COMPONENTS
uint32_t ui32
Definition ojph_defs.h:54