OpenJPH: /build/openjph/src/OpenJPH/subprojects/js/src/ojph_wrapper.cpp Source File

OpenJPH Open-source implementation of JPEG2000 Part-15

Loading...
Searching...
No Matches
ojph_wrapper.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_wrapper.cpp
34// Author: Aous Naman
35// Date: 22 October 2019
36/****************************************************************************/
37
38#include <exception>
39#include <emscripten.h>
40
41#include "ojph_arch.h"
42#include "ojph_file.h"
43#include "ojph_mem.h"
44#include "ojph_params.h"
45#include "ojph_codestream.h"
46
48 struct j2k_struct
49{
50 ojph::codestream codestream;
51 ojph::mem_infile mem_file;
52};
53
55 j2k_struct* cpp_create_j2c_data(void)
56{
57 return new j2k_struct;
58}
59
61 void cpp_init_j2c_data(j2k_struct *j2c, const uint8_t *data, size_t size)
62{
63 try {
64 j2c->mem_file.open(data, size);
65 j2c->codestream.read_headers(&j2c->mem_file);
66 }
67 catch (const std::exception& e)
68 {
69 const char *p = e.what();
70 if (strncmp(p, "ojph error", 10) != 0)
71 printf("%s\n", p);
72 }
73}
74
76 void cpp_parse_j2c_data(j2k_struct *j2c)
77{
78 try {
79 j2c->codestream.set_planar(false);
80 j2c->codestream.create();
81 }
82 catch (const std::exception& e)
83 {
84 const char *p = e.what();
85 if (strncmp(p, "ojph error", 10) != 0)
86 printf("%s\n", p);
87 }
88}
89
91 void cpp_release_j2c_data(j2k_struct* j2c)
92{
93 if (j2c)
94 {
95 delete j2c;
96 }
97}
98
100 signed int* cpp_pull_j2c_line(j2k_struct* j2c)
101{
102 try {
103 ojph::ui32 comp_num;
104 ojph::line_buf *line = j2c->codestream.pull(comp_num);
105 return line->i32;
106 }
107 catch (const std::exception& e)
108 {
109 const char *p = e.what();
110 if (strncmp(p, "ojph error", 10) != 0)
111 printf("%s\n", p);
112 }
113 return NULL;
114}
115
117 void cpp_restrict_input_resolution(j2k_struct* j2c,
118 int skipped_res_for_read,
119 int skipped_res_for_recon)
120{
121 j2c->codestream.restrict_input_resolution(skipped_res_for_read,
122 skipped_res_for_recon);
123}
124
126extern "C"
127{
129 EMSCRIPTEN_KEEPALIVE
130 j2k_struct* create_j2c_data(void)
131 {
132 return cpp_create_j2c_data();
133 }
134
136 EMSCRIPTEN_KEEPALIVE
137 void init_j2c_data(j2k_struct *j2c, const uint8_t *data, size_t size)
138 {
139 cpp_init_j2c_data(j2c, data, size);
140 }
141
143 EMSCRIPTEN_KEEPALIVE
144 int get_j2c_width(j2k_struct* j2c, int comp_num)
145 {
146 ojph::param_siz siz = j2c->codestream.access_siz();
147 return siz.get_recon_width(comp_num);
148 }
149
151 EMSCRIPTEN_KEEPALIVE
152 int get_j2c_height(j2k_struct* j2c, int comp_num)
153 {
154 ojph::param_siz siz = j2c->codestream.access_siz();
155 return siz.get_recon_height(comp_num);
156 }
157
159 EMSCRIPTEN_KEEPALIVE
160 int get_j2c_bit_depth(j2k_struct* j2c, int comp_num)
161 {
162 ojph::param_siz siz = j2c->codestream.access_siz();
163 if (comp_num >= 0 && comp_num < siz.get_num_components())
164 return siz.get_bit_depth(comp_num);
165 else
166 return -1;
167 }
168
170 EMSCRIPTEN_KEEPALIVE
171 int get_j2c_is_signed(j2k_struct* j2c, int comp_num)
172 {
173 ojph::param_siz siz = j2c->codestream.access_siz();
174 if (comp_num >= 0 && comp_num < siz.get_num_components())
175 return siz.is_signed(comp_num) ? 1 : 0;
176 else
177 return -1;
178 }
179
181 EMSCRIPTEN_KEEPALIVE
182 int get_j2c_num_components(j2k_struct* j2c)
183 {
184 ojph::param_siz siz = j2c->codestream.access_siz();
185 return siz.get_num_components();
186 }
187
189 EMSCRIPTEN_KEEPALIVE
190 int get_j2c_downsampling_x(j2k_struct* j2c, int comp_num)
191 {
192 ojph::param_siz siz = j2c->codestream.access_siz();
193 if (comp_num >= 0 && comp_num < siz.get_num_components())
194 { return siz.get_downsampling(comp_num).x; }
195 else
196 { return -1; }
197 }
198
200 EMSCRIPTEN_KEEPALIVE
201 int get_j2c_downsampling_y(j2k_struct* j2c, int comp_num)
202 {
203 ojph::param_siz siz = j2c->codestream.access_siz();
204 if (comp_num >= 0 && comp_num < siz.get_num_components())
205 { return siz.get_downsampling(comp_num).y; }
206 else
207 { return -1; }
208 }
209
211 EMSCRIPTEN_KEEPALIVE
212 void parse_j2c_data(j2k_struct *j2c)
213 {
214 cpp_parse_j2c_data(j2c);
215 }
216
218 EMSCRIPTEN_KEEPALIVE
219 void restrict_input_resolution(j2k_struct* j2c,
220 int skipped_res_for_read,
221 int skipped_res_for_recon)
222 {
223 cpp_restrict_input_resolution(j2c, skipped_res_for_read,
224 skipped_res_for_recon);
225 }
226
228 EMSCRIPTEN_KEEPALIVE
229 void enable_resilience(j2k_struct* j2c)
230 {
231 j2c->codestream.enable_resilience();
232 }
233
235 EMSCRIPTEN_KEEPALIVE
236 signed int* pull_j2c_line(j2k_struct* j2c)
237 {
238 return cpp_pull_j2c_line(j2c);
239 }
240
242 EMSCRIPTEN_KEEPALIVE
243 void release_j2c_data(j2k_struct* j2c)
244 {
245 cpp_release_j2c_data(j2c);
246 }
247}
248
ojph::codestream
The object represent a codestream.
Definition ojph_codestream.h:89
ojph::codestream::access_siz
param_siz access_siz()
Returns the underlying SIZ marker segment object.
Definition ojph_codestream.cpp:79
ojph::codestream::restrict_input_resolution
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...
Definition ojph_codestream.cpp:179
ojph::codestream::set_planar
void set_planar(bool planar)
Sets the sequence of pushing or pull rows from the machinery.
Definition ojph_codestream.cpp:103
ojph::codestream::enable_resilience
void enable_resilience()
This enables codestream resilience; that is, the library tries its best to decode the codestream,...
Definition ojph_codestream.cpp:167
ojph::codestream::read_headers
void read_headers(infile_base *file)
This call reads the headers of a codestream. It is for a reading (or decoding) codestream,...
Definition ojph_codestream.cpp:173
ojph::codestream::create
void create()
This call is for a decoding (or reading) codestream. Call this function after calling restrict_input_...
Definition ojph_codestream.cpp:187
ojph::codestream::pull
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...
Definition ojph_codestream.cpp:193
ojph::line_buf
Definition ojph_mem.h:161
ojph::line_buf::i32
si32 * i32
Definition ojph_mem.h:185
ojph::mem_infile
Definition ojph_file.h:309
ojph::mem_infile::open
void open(const ui8 *data, size_t size)
Definition ojph_file.cpp:337
ojph::param_siz
Definition ojph_params.h:71
ojph::param_siz::get_bit_depth
ui32 get_bit_depth(ui32 comp_num) const
Definition ojph_params.cpp:127
ojph::param_siz::get_recon_height
ui32 get_recon_height(ui32 comp_num) const
Definition ojph_params.cpp:151
ojph::param_siz::get_downsampling
point get_downsampling(ui32 comp_num) const
Definition ojph_params.cpp:139
ojph::param_siz::get_recon_width
ui32 get_recon_width(ui32 comp_num) const
Definition ojph_params.cpp:145
ojph::param_siz::is_signed
bool is_signed(ui32 comp_num) const
Definition ojph_params.cpp:133
ojph::param_siz::get_num_components
ui32 get_num_components() const
Definition ojph_params.cpp:121
ojph::ui32
uint32_t ui32
Definition ojph_defs.h:54
ojph_arch.h
ojph_codestream.h
ojph_file.h
ojph_mem.h
ojph_params.h
pull_j2c_line
EMSCRIPTEN_KEEPALIVE signed int * pull_j2c_line(j2k_struct *j2c)
Definition ojph_wrapper.cpp:236
create_j2c_data
EMSCRIPTEN_KEEPALIVE j2k_struct * create_j2c_data(void)
Definition ojph_wrapper.cpp:130
get_j2c_num_components
EMSCRIPTEN_KEEPALIVE int get_j2c_num_components(j2k_struct *j2c)
Definition ojph_wrapper.cpp:182
get_j2c_downsampling_y
EMSCRIPTEN_KEEPALIVE int get_j2c_downsampling_y(j2k_struct *j2c, int comp_num)
Definition ojph_wrapper.cpp:201
parse_j2c_data
EMSCRIPTEN_KEEPALIVE void parse_j2c_data(j2k_struct *j2c)
Definition ojph_wrapper.cpp:212
enable_resilience
EMSCRIPTEN_KEEPALIVE void enable_resilience(j2k_struct *j2c)
Definition ojph_wrapper.cpp:229
release_j2c_data
EMSCRIPTEN_KEEPALIVE void release_j2c_data(j2k_struct *j2c)
Definition ojph_wrapper.cpp:243
get_j2c_height
EMSCRIPTEN_KEEPALIVE int get_j2c_height(j2k_struct *j2c, int comp_num)
Definition ojph_wrapper.cpp:152
cpp_pull_j2c_line
signed int * cpp_pull_j2c_line(j2k_struct *j2c)
Definition ojph_wrapper.cpp:100
init_j2c_data
EMSCRIPTEN_KEEPALIVE void init_j2c_data(j2k_struct *j2c, const uint8_t *data, size_t size)
Definition ojph_wrapper.cpp:137
cpp_parse_j2c_data
void cpp_parse_j2c_data(j2k_struct *j2c)
Definition ojph_wrapper.cpp:76
cpp_init_j2c_data
void cpp_init_j2c_data(j2k_struct *j2c, const uint8_t *data, size_t size)
Definition ojph_wrapper.cpp:61
cpp_restrict_input_resolution
void cpp_restrict_input_resolution(j2k_struct *j2c, int skipped_res_for_read, int skipped_res_for_recon)
Definition ojph_wrapper.cpp:117
get_j2c_is_signed
EMSCRIPTEN_KEEPALIVE int get_j2c_is_signed(j2k_struct *j2c, int comp_num)
Definition ojph_wrapper.cpp:171
cpp_create_j2c_data
j2k_struct * cpp_create_j2c_data(void)
Definition ojph_wrapper.cpp:55
get_j2c_downsampling_x
EMSCRIPTEN_KEEPALIVE int get_j2c_downsampling_x(j2k_struct *j2c, int comp_num)
Definition ojph_wrapper.cpp:190
get_j2c_bit_depth
EMSCRIPTEN_KEEPALIVE int get_j2c_bit_depth(j2k_struct *j2c, int comp_num)
Definition ojph_wrapper.cpp:160
get_j2c_width
EMSCRIPTEN_KEEPALIVE int get_j2c_width(j2k_struct *j2c, int comp_num)
Definition ojph_wrapper.cpp:144
restrict_input_resolution
EMSCRIPTEN_KEEPALIVE void restrict_input_resolution(j2k_struct *j2c, int skipped_res_for_read, int skipped_res_for_recon)
Definition ojph_wrapper.cpp:219
cpp_release_j2c_data
void cpp_release_j2c_data(j2k_struct *j2c)
Definition ojph_wrapper.cpp:91
j2k_struct
Definition ojph_wrapper.cpp:49
j2k_struct::mem_file
ojph::mem_infile mem_file
Definition ojph_wrapper.cpp:51
j2k_struct::codestream
ojph::codestream codestream
Definition ojph_wrapper.cpp:50
ojph::point::y
ui32 y
Definition ojph_base.h:60
ojph::point::x
ui32 x
Definition ojph_base.h:60