17
17
#include < vector>
18
18
#include < string>
19
19
20
- #include " kdu_elementary.h "
21
- # include " kdu_params.h "
22
- #include " kdu_stripe_compressor .h"
23
- #include " kdu_compressed .h"
24
- #include " kdu_file_io .h"
25
- #include " kdu_messaging .h"
26
- #include " kdu_sample_processing .h"
27
- #include " kdu_stripe_decompressor .h"
28
-
29
- #include " openexr_compression .h"
30
-
20
+ #ifdef KDU_AVAILABLE
21
+
22
+ # include " openexr_compression .h"
23
+ # include " kdu_elementary .h"
24
+ # include " kdu_params .h"
25
+ # include " kdu_stripe_compressor .h"
26
+ # include " kdu_compressed .h"
27
+ # include " kdu_file_io .h"
28
+ # include " kdu_messaging.h "
29
+ # include " kdu_sample_processing .h"
30
+ # include " kdu_stripe_decompressor.h "
31
31
using namespace kdu_supp ;
32
32
33
- class mem_compressed_target : public kdu_compressed_target {
34
- public:
35
- mem_compressed_target () {}
33
+ class mem_compressed_target : public kdu_compressed_target
34
+ {
35
+ public:
36
+ mem_compressed_target () {}
36
37
37
- bool close () {
38
- this ->buf .clear ();
39
- return true ;
40
- }
38
+ bool close ()
39
+ {
40
+ this ->buf .clear ();
41
+ return true ;
42
+ }
41
43
42
- bool write (const kdu_byte* buf, int num_bytes) {
43
- std::copy (buf, buf + num_bytes, std::back_inserter (this ->buf ));
44
- return true ;
45
- }
44
+ bool write (const kdu_byte* buf, int num_bytes)
45
+ {
46
+ std::copy (buf, buf + num_bytes, std::back_inserter (this ->buf ));
47
+ return true ;
48
+ }
46
49
47
- void set_target_size (kdu_long num_bytes) { this ->buf .reserve (num_bytes); }
50
+ void set_target_size (kdu_long num_bytes) { this ->buf .reserve (num_bytes); }
48
51
49
- bool prefer_large_writes () const { return false ; }
52
+ bool prefer_large_writes () const { return false ; }
50
53
51
- std::vector<uint8_t >& get_buffer () { return this ->buf ; }
54
+ std::vector<uint8_t >& get_buffer () { return this ->buf ; }
52
55
53
- private:
54
- std::vector<uint8_t > buf;
56
+ private:
57
+ std::vector<uint8_t > buf;
55
58
};
56
59
57
- class error_message_handler : public kdu_core ::kdu_message {
58
- public:
59
-
60
- void put_text (const char * msg) {
61
- std::cout << msg;
62
- }
60
+ class error_message_handler : public kdu_core ::kdu_message
61
+ {
62
+ public:
63
+ void put_text (const char * msg) { std::cout << msg; }
63
64
64
- virtual void flush (bool end_of_message = false ) {
65
- if (end_of_message) {
66
- std::cout << std::endl;
65
+ virtual void flush (bool end_of_message = false )
66
+ {
67
+ if (end_of_message) { std::cout << std::endl; }
67
68
}
68
- }
69
69
};
70
70
71
71
static error_message_handler error_handler;
72
72
73
-
74
-
75
73
extern " C" exr_result_t
76
74
internal_exr_undo_htk (
77
75
exr_decode_pipeline_t * decode,
@@ -82,69 +80,77 @@ internal_exr_undo_htk (
82
80
{
83
81
exr_result_t rv = EXR_ERR_SUCCESS;
84
82
85
- std::vector<int > cs_to_file_ch (decode->channel_count );
86
- bool isRGB = make_channel_map (
83
+ std::vector<int > cs_to_file_ch (decode->channel_count );
84
+ bool isRGB = make_channel_map (
87
85
decode->channel_count , decode->channels , cs_to_file_ch);
88
86
89
- std::vector<int > heights (decode->channel_count );
90
- std::vector<int > sample_offsets (decode->channel_count );
87
+ std::vector<int > heights (decode->channel_count );
88
+ std::vector<int > sample_offsets (decode->channel_count );
91
89
92
- int32_t width = decode->chunk .width ;
90
+ int32_t width = decode->chunk .width ;
93
91
int32_t height = decode->chunk .height ;
94
92
95
- for (int i = 0 ; i < sample_offsets.size (); i++) {
93
+ for (int i = 0 ; i < sample_offsets.size (); i++)
94
+ {
96
95
sample_offsets[i] = cs_to_file_ch[i] * width;
97
96
}
98
97
99
- std::vector<int > row_gaps (decode->channel_count );
100
- std::fill (row_gaps.begin (), row_gaps.end (), width * decode->channel_count );
98
+ std::vector<int > row_gaps (decode->channel_count );
99
+ std::fill (
100
+ row_gaps.begin (), row_gaps.end (), width * decode->channel_count );
101
101
102
- kdu_core::kdu_customize_errors (&error_handler);
102
+ kdu_core::kdu_customize_errors (&error_handler);
103
103
104
- kdu_compressed_source_buffered infile ((kdu_byte*) (compressed_data), comp_buf_size);
104
+ kdu_compressed_source_buffered infile (
105
+ (kdu_byte*) (compressed_data), comp_buf_size);
105
106
106
- kdu_codestream cs;
107
- cs.create (&infile);
107
+ kdu_codestream cs;
108
+ cs.create (&infile);
108
109
109
110
kdu_dims dims;
110
- cs.get_dims (0 , dims, false );
111
+ cs.get_dims (0 , dims, false );
111
112
112
113
assert (width == dims.size .x );
113
114
assert (height == dims.size .y );
114
- assert (decode->channel_count == cs.get_num_components ());
115
+ assert (decode->channel_count == cs.get_num_components ());
115
116
assert (sizeof (int16_t ) == 2 );
116
117
117
118
kdu_stripe_decompressor d;
118
119
119
- d.start (cs);
120
+ d.start (cs);
120
121
121
- std::fill (heights.begin (), heights.end (), height);
122
- d.pull_stripe ((kdu_int16 *) uncompressed_data, heights.data (), sample_offsets.data (), NULL , row_gaps.data ());
122
+ std::fill (heights.begin (), heights.end (), height);
123
+ d.pull_stripe (
124
+ (kdu_int16*) uncompressed_data,
125
+ heights.data (),
126
+ sample_offsets.data (),
127
+ NULL ,
128
+ row_gaps.data ());
123
129
124
- d.finish ();
130
+ d.finish ();
125
131
126
- cs.destroy ();
132
+ cs.destroy ();
127
133
128
134
return rv;
129
135
}
130
136
131
- extern " C"
132
- exr_result_t
137
+ extern " C" exr_result_t
133
138
internal_exr_apply_htk (exr_encode_pipeline_t * encode)
134
139
{
135
140
exr_result_t rv = EXR_ERR_SUCCESS;
136
141
137
- std::vector<int > cs_to_file_ch (encode->channel_count );
138
- bool isRGB = make_channel_map (
142
+ std::vector<int > cs_to_file_ch (encode->channel_count );
143
+ bool isRGB = make_channel_map (
139
144
encode->channel_count , encode->channels , cs_to_file_ch);
140
145
141
146
int height = encode->chunk .height ;
142
147
int width = encode->chunk .width ;
143
-
144
- std::vector<int > heights (encode->channel_count );
145
- std::vector<int > sample_offsets (encode->channel_count );
146
- std::vector<int > row_gaps (encode->channel_count );
147
- std::fill (row_gaps.begin (), row_gaps.end (), width * encode->channel_count );
148
+
149
+ std::vector<int > heights (encode->channel_count );
150
+ std::vector<int > sample_offsets (encode->channel_count );
151
+ std::vector<int > row_gaps (encode->channel_count );
152
+ std::fill (
153
+ row_gaps.begin (), row_gaps.end (), width * encode->channel_count );
148
154
149
155
assert (
150
156
encode->packed_bytes == (encode->channel_count * 2 * height * width));
@@ -157,7 +163,7 @@ internal_exr_apply_htk (exr_encode_pipeline_t* encode)
157
163
siz.set (Nsigned, 0 , 0 , true );
158
164
static_cast <kdu_params&> (siz).finalize ();
159
165
160
- kdu_codestream codestream;
166
+ kdu_codestream codestream;
161
167
mem_compressed_target output;
162
168
163
169
// kdu_simple_file_target target("/tmp/out.j2c");
@@ -177,30 +183,66 @@ internal_exr_apply_htk (exr_encode_pipeline_t* encode)
177
183
cod->set (Clevels, 0 , 0 , 5 );
178
184
cod->set (Cycc, 0 , 0 , isRGB);
179
185
180
- kdu_params * nlt = codestream.access_siz ()->access_cluster (NLT_params);
186
+ kdu_params* nlt = codestream.access_siz ()->access_cluster (NLT_params);
181
187
182
- nlt->set (NLType, 0 , 0 , NLType_SMAG);
188
+ nlt->set (NLType, 0 , 0 , NLType_SMAG);
183
189
184
190
codestream.access_siz ()->finalize_all ();
185
191
186
192
kdu_stripe_compressor compressor;
187
193
compressor.start (codestream);
188
194
189
- std::fill (heights.begin (), heights.end (), height);
190
- compressor.push_stripe ((kdu_int16 *) encode->packed_buffer , heights.data (), sample_offsets.data (), NULL , row_gaps.data ());
195
+ std::fill (heights.begin (), heights.end (), height);
196
+ compressor.push_stripe (
197
+ (kdu_int16*) encode->packed_buffer ,
198
+ heights.data (),
199
+ sample_offsets.data (),
200
+ NULL ,
201
+ row_gaps.data ());
191
202
192
- compressor.finish ();
203
+ compressor.finish ();
193
204
194
- codestream.destroy ();
205
+ codestream.destroy ();
195
206
196
- int compressed_sz = static_cast <size_t > (output.get_buffer ().size ());
207
+ int compressed_sz = static_cast <size_t > (output.get_buffer ().size ());
197
208
198
209
if (compressed_sz < encode->packed_bytes )
199
210
{
200
- memcpy (encode->compressed_buffer , output.get_buffer ().data (), compressed_sz);
211
+ memcpy (
212
+ encode->compressed_buffer ,
213
+ output.get_buffer ().data (),
214
+ compressed_sz);
201
215
encode->compressed_bytes = compressed_sz;
202
216
}
203
217
else { encode->compressed_bytes = encode->packed_bytes ; }
204
218
205
219
return rv;
206
220
}
221
+
222
+ #else
223
+
224
+ #error
225
+
226
+ extern " C" exr_result_t
227
+ internal_exr_undo_htk (
228
+ exr_decode_pipeline_t * decode,
229
+ const void * compressed_data,
230
+ uint64_t comp_buf_size,
231
+ void * uncompressed_data,
232
+ uint64_t uncompressed_size)
233
+ {
234
+ return internal_exr_undo_ht (
235
+ decode,
236
+ compressed_data,
237
+ comp_buf_size,
238
+ uncompressed_data,
239
+ uncompressed_size);
240
+ }
241
+
242
+ extern " C" exr_result_t
243
+ internal_exr_apply_htk (exr_encode_pipeline_t * encode)
244
+ {
245
+ return internal_exr_apply_ht (encode);
246
+ }
247
+
248
+ #endif
0 commit comments