/src/ghostpdl/jpegxr/r_parse.c
Line | Count | Source |
1 | | |
2 | | /************************************************************************* |
3 | | * |
4 | | * This software module was originally contributed by Microsoft |
5 | | * Corporation in the course of development of the |
6 | | * ITU-T T.832 | ISO/IEC 29199-2 ("JPEG XR") format standard for |
7 | | * reference purposes and its performance may not have been optimized. |
8 | | * |
9 | | * This software module is an implementation of one or more |
10 | | * tools as specified by the JPEG XR standard. |
11 | | * |
12 | | * ITU/ISO/IEC give You a royalty-free, worldwide, non-exclusive |
13 | | * copyright license to copy, distribute, and make derivative works |
14 | | * of this software module or modifications thereof for use in |
15 | | * products claiming conformance to the JPEG XR standard as |
16 | | * specified by ITU-T T.832 | ISO/IEC 29199-2. |
17 | | * |
18 | | * ITU/ISO/IEC give users the same free license to this software |
19 | | * module or modifications thereof for research purposes and further |
20 | | * ITU/ISO/IEC standardization. |
21 | | * |
22 | | * Those intending to use this software module in products are advised |
23 | | * that its use may infringe existing patents. ITU/ISO/IEC have no |
24 | | * liability for use of this software module or modifications thereof. |
25 | | * |
26 | | * Copyright is not released for products that do not conform to |
27 | | * to the JPEG XR standard as specified by ITU-T T.832 | |
28 | | * ISO/IEC 29199-2. |
29 | | * |
30 | | * Microsoft Corporation retains full right to modify and use the code |
31 | | * for its own purpose, to assign or donate the code to a third party, |
32 | | * and to inhibit third parties from using the code for products that |
33 | | * do not conform to the JPEG XR standard as specified by ITU-T T.832 | |
34 | | * ISO/IEC 29199-2. |
35 | | * |
36 | | * This copyright notice must be included in all copies or derivative |
37 | | * works. |
38 | | * |
39 | | * Copyright (c) ITU-T/ISO/IEC 2008, 2009. |
40 | | ***********************************************************************/ |
41 | | |
42 | | #ifdef _MSC_VER |
43 | | #pragma comment (user,"$Id: r_parse.c,v 1.39 2008/03/24 18:06:56 steve Exp $") |
44 | | #else |
45 | | #ident "$Id: r_parse.c,v 1.39 2008/03/24 18:06:56 steve Exp $" |
46 | | #endif |
47 | | |
48 | | # include "jxr_priv.h" |
49 | | # include <stdlib.h> |
50 | | # include <memory.h> |
51 | | # include <assert.h> |
52 | | |
53 | | static int r_image_header(jxr_image_t image, struct rbitstream*str); |
54 | | static int r_image_plane_header(jxr_image_t image, struct rbitstream*str, int alpha); |
55 | | static int r_INDEX_TABLE(jxr_image_t image, struct rbitstream*str); |
56 | | static int64_t r_PROFILE_LEVEL_INFO(jxr_image_t image, struct rbitstream*str); |
57 | | static int r_TILE(jxr_image_t image, struct rbitstream*str); |
58 | | |
59 | | static int r_HP_QP(jxr_image_t image, struct rbitstream*str); |
60 | | |
61 | | static int32_t r_DEC_DC(jxr_image_t image, struct rbitstream*str, |
62 | | unsigned tx, unsigned ty, |
63 | | unsigned mx, unsigned my, |
64 | | int model_bits, int chroma_flag, int is_dc_ch); |
65 | | static uint32_t r_DECODE_ABS_LEVEL(jxr_image_t image, struct rbitstream*str, |
66 | | int band, int chroma_flag); |
67 | | static int r_DECODE_FIRST_INDEX(jxr_image_t image, struct rbitstream*str, |
68 | | int chroma_flag, int band); |
69 | | static int r_DECODE_INDEX(jxr_image_t image, struct rbitstream*str, |
70 | | int location, int chroma_flag, int band, int context); |
71 | | static int r_DECODE_RUN(jxr_image_t image, struct rbitstream*str, int max_run); |
72 | | static int r_REFINE_LP(struct rbitstream*str, int coeff, int model_bits); |
73 | | static int r_REFINE_CBP(struct rbitstream*str, int cbp); |
74 | | static void r_PredCBP(jxr_image_t image, int*diff_cbp, |
75 | | unsigned tx, unsigned ty, |
76 | | unsigned mx, unsigned my); |
77 | | static int r_DECODE_BLOCK_ADAPTIVE(jxr_image_t image, struct rbitstream*str, |
78 | | unsigned tx, unsigned mx, |
79 | | int cbp_flag, int chroma_flag, |
80 | | int channel, int block, int mbhp_pred_mode, |
81 | | unsigned model_bits); |
82 | | static void r_BLOCK_FLEXBITS(jxr_image_t image, struct rbitstream*str, |
83 | | unsigned tx, unsigned ty, |
84 | | unsigned mx, unsigned my, |
85 | | unsigned chan, unsigned bl, unsigned model_bits); |
86 | | static int r_calculate_mbhp_mode(jxr_image_t image, int tx, int mx); |
87 | | static int get_is_dc_yuv(struct rbitstream*str); |
88 | | static int dec_cbp_yuv_lp1(jxr_image_t image, struct rbitstream*str); |
89 | | static int dec_abslevel_index(jxr_image_t image, struct rbitstream*str, int vlc_select); |
90 | | static int get_num_cbp(struct rbitstream*str, struct adaptive_vlc_s*vlc); |
91 | | static int get_num_blkcbp(jxr_image_t image, struct rbitstream*str, struct adaptive_vlc_s*vlc); |
92 | | static int get_value_012(struct rbitstream*str); |
93 | | static int get_num_ch_blk(struct rbitstream*str); |
94 | | |
95 | | |
96 | | |
97 | | int jxr_read_image_bitstream(jxr_image_t image, FILE*fd) |
98 | 0 | { |
99 | 0 | int rc; |
100 | 0 | struct rbitstream bits; |
101 | 0 | uint8_t input_profile; |
102 | 0 | uint8_t input_level; |
103 | 0 | int64_t subsequent_bytes; |
104 | |
|
105 | 0 | _jxr_rbitstream_initialize(&bits, fd); |
106 | | |
107 | | /* Image header for the image overall */ |
108 | 0 | rc = r_image_header(image, &bits); |
109 | 0 | if (rc < 0) return rc; |
110 | | |
111 | | /* Image plane. */ |
112 | 0 | rc = r_image_plane_header(image, &bits, 0); |
113 | 0 | if (rc < 0) return rc; |
114 | | |
115 | | /* Make image structures that need header details. */ |
116 | 0 | rc = _jxr_make_mbstore(image, 0); |
117 | 0 | if (rc < 0) |
118 | 0 | return rc; |
119 | | |
120 | | /* If there is an alpa channel, process the image place header |
121 | | for it. */ |
122 | 0 | if (ALPHACHANNEL_FLAG(image)) { |
123 | 0 | int ch; |
124 | |
|
125 | 0 | image->alpha = jxr_create_input(); |
126 | 0 | if (image->alpha == NULL) |
127 | 0 | return -1; |
128 | 0 | *image->alpha = *image; |
129 | |
|
130 | 0 | rc = r_image_plane_header(image->alpha, &bits, 1); |
131 | 0 | if (rc < 0) return rc; |
132 | | |
133 | 0 | for(ch = 0; ch < image->num_channels; ch ++) |
134 | 0 | memset(&image->alpha->strip[ch], 0, sizeof(image->alpha->strip[ch])); |
135 | |
|
136 | 0 | rc = _jxr_make_mbstore(image->alpha, 0); |
137 | 0 | if (rc < 0) |
138 | 0 | return rc; |
139 | 0 | image->alpha->primary = 0; |
140 | 0 | } |
141 | | |
142 | 0 | rc = r_INDEX_TABLE(image, &bits); |
143 | | |
144 | | /* Store command line input values for later comparison */ |
145 | 0 | input_profile = image->profile_idc; |
146 | 0 | input_level = image->level_idc; |
147 | | |
148 | | /* inferred value as per Appendix B */ |
149 | 0 | image->profile_idc = 111; |
150 | 0 | image->level_idc = 255; |
151 | |
|
152 | 0 | subsequent_bytes = _jxr_rbitstream_intVLW(&bits); |
153 | 0 | DEBUG(" Subsequent bytes with %ld bytes\n", subsequent_bytes); |
154 | 0 | if (subsequent_bytes > 0) { |
155 | 0 | int64_t read_bytes = r_PROFILE_LEVEL_INFO(image,&bits); |
156 | 0 | int64_t additional_bytes = subsequent_bytes - read_bytes; |
157 | 0 | int64_t idx; |
158 | 0 | for (idx = 0 ; idx < additional_bytes ; idx += 1) { |
159 | 0 | _jxr_rbitstream_uint8(&bits); /* RESERVED_A_BYTE */ |
160 | 0 | } |
161 | 0 | } |
162 | |
|
163 | 0 | assert(image->profile_idc <= input_profile); |
164 | 0 | assert(image->level_idc <= input_level); |
165 | |
|
166 | 0 | rc = jxr_test_PROFILE_IDC(image, 1); |
167 | 0 | rc = jxr_test_LEVEL_IDC(image, 1); |
168 | |
|
169 | 0 | DEBUG("MARK HERE as the tile base. bitpos=%zu\n", _jxr_rbitstream_bitpos(&bits)); |
170 | 0 | _jxr_rbitstream_mark(&bits); |
171 | | |
172 | | /* The image data is in a TILE element even if there is no |
173 | | tiling. No tiling just means 1 big tile. */ |
174 | 0 | rc = r_TILE(image, &bits); |
175 | |
|
176 | 0 | DEBUG("Consumed %zu bytes of the bitstream\n", bits.read_count); |
177 | |
|
178 | 0 | #ifdef VERIFY_16BIT |
179 | 0 | if(image->lwf_test == 0) |
180 | 0 | DEBUG("Meet conditions for LONG_WORD_FLAG == 0!"); |
181 | 0 | else { |
182 | 0 | DEBUG("Don't meet conditions for LONG_WORD_FLAG == 0!"); |
183 | 0 | if (LONG_WORD_FLAG(image) == 0) |
184 | 0 | return JXR_EC_BADFORMAT; |
185 | 0 | } |
186 | 0 | #endif |
187 | | |
188 | 0 | return rc; |
189 | 0 | } |
190 | | |
191 | | int jxr_test_LONG_WORD_FLAG(jxr_image_t image, int flag) |
192 | 0 | { |
193 | 0 | #ifdef VERIFY_16BIT |
194 | 0 | if (flag == 0 && image->lwf_test != 0) { |
195 | 0 | DEBUG("Using LONG_WORD_FLAG decoder but did not meet LONG_WORD_FLAG == 0 conditions!"); |
196 | 0 | return JXR_EC_BADFORMAT; |
197 | 0 | } |
198 | 0 | else |
199 | 0 | #endif |
200 | 0 | return 0; |
201 | | |
202 | 0 | } |
203 | | |
204 | | #if defined(DETAILED_DEBUG) |
205 | | static const char*bitdepth_names[16] = { |
206 | | "BD1WHITE1", "BD8", "BD16", "BD16S", |
207 | | "BD16F", "RESERVED5", "BD32S", "BD32F", |
208 | | "BD5", "BD10", "BD565", "RESERVED11" |
209 | | "RESERVED12", "RESERVED12", "RESERVED12","BD1BLACK1" |
210 | | }; |
211 | | |
212 | | #endif |
213 | | |
214 | | static int r_image_header(jxr_image_t image, struct rbitstream*str) |
215 | 0 | { |
216 | 0 | const char GDI_SIG[] = "WMPHOTO\0"; |
217 | 0 | unsigned idx; |
218 | |
|
219 | 0 | unsigned version_info, version_sub_info; |
220 | 0 | unsigned hei_sum; |
221 | 0 | unsigned wid_sum = 0; |
222 | | |
223 | | /* Read and test the GDI_SIGNATURE magic number */ |
224 | 0 | for (idx = 0 ; idx < 8 ; idx += 1) { |
225 | 0 | uint8_t byte = _jxr_rbitstream_uint8(str); |
226 | 0 | if (byte != GDI_SIG[idx]) { |
227 | 0 | return JXR_EC_BADMAGIC; |
228 | 0 | } |
229 | 0 | } |
230 | | |
231 | 0 | DEBUG("Got magic number.\n"); |
232 | 0 | DEBUG("START IMAGE_HEADER (bitpos=%zu)\n", _jxr_rbitstream_bitpos(str)); |
233 | | |
234 | | /* Get the version info */ |
235 | 0 | version_info = _jxr_rbitstream_uint4(str); |
236 | |
|
237 | 0 | image->disableTileOverlapFlag = _jxr_rbitstream_uint1(str); |
238 | 0 | DEBUG(" disableTileOverlapFlag: %d\n", image->disableTileOverlapFlag); |
239 | |
|
240 | 0 | version_sub_info = _jxr_rbitstream_uint3(str); |
241 | 0 | DEBUG(" Version: %u.%u\n", version_info, version_sub_info); |
242 | | |
243 | | /* Read some of the flags as a group. There are a bunch of |
244 | | small flag values together here, so it is economical to |
245 | | just collect them all at once. */ |
246 | 0 | image->header_flags1 = _jxr_rbitstream_uint8(str); |
247 | 0 | image->header_flags2 = _jxr_rbitstream_uint8(str); |
248 | 0 | image->header_flags_fmt = _jxr_rbitstream_uint8(str); |
249 | | |
250 | | /* check container conformance */ |
251 | 0 | if (image->container_current_separate_alpha == 0) |
252 | 0 | assert(SOURCE_CLR_FMT(image) == image->container_color); |
253 | 0 | assert(((image->header_flags_fmt & 0x0f) == 15 ? 0 : (image->header_flags_fmt & 0x0f)) == image->container_bpc); |
254 | 0 | if (image->container_separate_alpha == 0) |
255 | 0 | assert(image->container_alpha == ALPHACHANNEL_FLAG(image)); |
256 | 0 | else |
257 | 0 | assert(ALPHACHANNEL_FLAG(image) == 0); |
258 | |
|
259 | 0 | DEBUG(" Flags group1=0x%02x\n", image->header_flags1); |
260 | 0 | DEBUG(" Flags group2=0x%02x\n", image->header_flags2); |
261 | 0 | DEBUG(" OUTPUT_CLR_FMT=%d\n", SOURCE_CLR_FMT(image)); |
262 | 0 | DEBUG(" OUTPUT_BITDEPTH=%d (%s)\n", SOURCE_BITDEPTH(image), bitdepth_names[SOURCE_BITDEPTH(image)]); |
263 | | |
264 | | /* Get the configured image dimensions. */ |
265 | 0 | if (SHORT_HEADER_FLAG(image)) { |
266 | 0 | DEBUG(" SHORT_HEADER_FLAG=true\n"); |
267 | 0 | image->width1 = _jxr_rbitstream_uint16(str); |
268 | 0 | image->height1 = _jxr_rbitstream_uint16(str); |
269 | 0 | } else { |
270 | 0 | DEBUG(" SHORT_HEADER_FLAG=false\n"); |
271 | 0 | image->width1 = _jxr_rbitstream_uint32(str); |
272 | 0 | image->height1 = _jxr_rbitstream_uint32(str); |
273 | 0 | } |
274 | | |
275 | | /* check container conformance */ |
276 | 0 | assert(image->width1 + 1 == image->container_width); |
277 | 0 | assert(image->height1 + 1 == image->container_height); |
278 | |
|
279 | 0 | DEBUG(" Image dimensions: %u x %u\n", image->width1+1, image->height1+1); |
280 | |
|
281 | 0 | assert(image->tile_row_height == 0); |
282 | 0 | assert(image->tile_column_width == 0); |
283 | 0 | assert(image->tile_column_position == 0); |
284 | 0 | if (jxr_get_TILING_FLAG(image)) { |
285 | 0 | image->tile_columns = _jxr_rbitstream_uint12(str) + 1; |
286 | 0 | image->tile_rows = _jxr_rbitstream_uint12(str) + 1; |
287 | 0 | DEBUG(" TILING %u columns, %u rows (bitpos=%zu)\n", |
288 | 0 | image->tile_columns, image->tile_rows, |
289 | 0 | _jxr_rbitstream_bitpos(str)); |
290 | | |
291 | |
|
292 | 0 | } else { |
293 | | /* NO TILING means that the entire image is exactly 1 |
294 | | tile. Configure the single tile to be the size of the |
295 | | entire image. */ |
296 | 0 | image->tile_columns = 1; |
297 | 0 | image->tile_rows = 1; |
298 | 0 | DEBUG(" NO TILING\n"); |
299 | 0 | } |
300 | | |
301 | | /* Collect the widths of the tile columns. All but the last |
302 | | column width are encoded in the input stream. The last is |
303 | | inferred from the accumulated width of the columns and the |
304 | | total width of the image. If there is no tiling, then there |
305 | | is exactly 1 tile, and this degenerates to the width of the |
306 | | image. |
307 | | |
308 | | The heights of tile rows is processed exactly the same way. */ |
309 | |
|
310 | 0 | image->tile_column_width = (unsigned*)calloc(2*image->tile_columns, sizeof(unsigned)); |
311 | 0 | image->tile_column_position = image->tile_column_width + image->tile_columns; |
312 | 0 | image->tile_row_height = (unsigned*)calloc(2*image->tile_rows, sizeof(unsigned)); |
313 | 0 | image->tile_row_position = image->tile_row_height + image->tile_rows; |
314 | |
|
315 | 0 | wid_sum = 0; |
316 | 0 | if (SHORT_HEADER_FLAG(image)) { |
317 | 0 | for (idx = 0 ; idx < image->tile_columns-1 ; idx += 1) { |
318 | 0 | image->tile_column_width[idx] = _jxr_rbitstream_uint8(str); |
319 | 0 | image->tile_column_position[idx] = wid_sum; |
320 | 0 | wid_sum += image->tile_column_width[idx]; |
321 | 0 | } |
322 | |
|
323 | 0 | } else { |
324 | 0 | for (idx = 0 ; idx < image->tile_columns-1 ; idx += 1) { |
325 | 0 | image->tile_column_width[idx] = _jxr_rbitstream_uint16(str); |
326 | 0 | image->tile_column_position[idx] = wid_sum; |
327 | 0 | wid_sum += image->tile_column_width[idx]; |
328 | 0 | } |
329 | 0 | } |
330 | | /* calculate final tile width after windowing parameters are found */ |
331 | |
|
332 | 0 | hei_sum = 0; |
333 | 0 | if (SHORT_HEADER_FLAG(image)) { |
334 | 0 | for (idx = 0 ; idx < image->tile_rows-1 ; idx += 1) { |
335 | 0 | image->tile_row_height[idx] = _jxr_rbitstream_uint8(str); |
336 | 0 | image->tile_row_position[idx] = hei_sum; |
337 | 0 | hei_sum += image->tile_row_height[idx]; |
338 | 0 | } |
339 | |
|
340 | 0 | } else { |
341 | 0 | for (idx = 0 ; idx < image->tile_rows-1 ; idx += 1) { |
342 | 0 | image->tile_row_height[idx] = _jxr_rbitstream_uint16(str); |
343 | 0 | image->tile_row_position[idx] = hei_sum; |
344 | 0 | hei_sum += image->tile_row_height[idx]; |
345 | 0 | } |
346 | 0 | } |
347 | | /* calculate final tile height after windowing parameters are found */ |
348 | |
|
349 | 0 | if (WINDOWING_FLAG(image)) { |
350 | 0 | image->window_extra_top = _jxr_rbitstream_uint6(str); |
351 | 0 | image->window_extra_left = _jxr_rbitstream_uint6(str); |
352 | 0 | image->window_extra_bottom = _jxr_rbitstream_uint6(str); |
353 | 0 | image->window_extra_right = _jxr_rbitstream_uint6(str); |
354 | 0 | } else { |
355 | 0 | image->window_extra_top = 0; |
356 | 0 | image->window_extra_left = 0; |
357 | 0 | if ((image->height1 + 1) % 16 == 0) |
358 | 0 | image->window_extra_bottom = 0; |
359 | 0 | else |
360 | 0 | image->window_extra_bottom = 16 - ((image->height1 + 1) % 16); |
361 | 0 | if ((image->width1 + 1) % 16 == 0) |
362 | 0 | image->window_extra_right = 0; |
363 | 0 | else |
364 | 0 | image->window_extra_right = 16 - ((image->width1 + 1) % 16); |
365 | 0 | DEBUG(" NO WINDOWING\n"); |
366 | 0 | } |
367 | 0 | image->extended_width = image->width1 + 1 + image->window_extra_left + image->window_extra_right; |
368 | 0 | image->extended_height = image->height1 + 1 + image->window_extra_top + image->window_extra_bottom; |
369 | |
|
370 | 0 | image->lwf_test = 0; |
371 | |
|
372 | 0 | image->tile_column_width[image->tile_columns-1] = (image->extended_width >> 4)-wid_sum; |
373 | 0 | image->tile_column_position[image->tile_columns-1] = wid_sum; |
374 | |
|
375 | 0 | image->tile_row_height[image->tile_rows-1] = (image->extended_height >> 4)-hei_sum; |
376 | 0 | image->tile_row_position[image->tile_rows-1] = hei_sum; |
377 | |
|
378 | | #if defined(DETAILED_DEBUG) |
379 | | DEBUG(" Tile widths:"); |
380 | | for (idx = 0 ; idx < image->tile_columns ; idx += 1) |
381 | | DEBUG(" %u", image->tile_column_width[idx]); |
382 | | DEBUG("\n"); |
383 | | DEBUG(" Tile heights:"); |
384 | | for (idx = 0 ; idx < image->tile_rows ; idx += 1) |
385 | | DEBUG(" %u", image->tile_row_height[idx]); |
386 | | DEBUG("\n"); |
387 | | #endif |
388 | | |
389 | | /* Perform some checks */ |
390 | 0 | assert(image->extended_width % 16 == 0); |
391 | 0 | if ((OVERLAP_INFO(image) >= 2) && (image->use_clr_fmt == 1 || image->use_clr_fmt == 2)) |
392 | 0 | { |
393 | 0 | assert(image->extended_width >= 32); |
394 | 0 | if (image->disableTileOverlapFlag) { |
395 | 0 | unsigned int idx = 0; |
396 | 0 | for (idx = 0; idx < image->tile_columns ; idx += 1) |
397 | 0 | assert(image->tile_column_width[idx] > 1); |
398 | 0 | } |
399 | 0 | } |
400 | 0 | assert(image->extended_height % 16 == 0); |
401 | |
|
402 | 0 | DEBUG("END IMAGE_HEADER (%zu bytes)\n", str->read_count); |
403 | 0 | return 0; |
404 | 0 | } |
405 | | |
406 | | static int r_image_plane_header(jxr_image_t image, struct rbitstream*str, int alpha) |
407 | 0 | { |
408 | 0 | size_t save_count = str->read_count; |
409 | 0 | uint16_t num_components; |
410 | |
|
411 | 0 | DEBUG("START IMAGE_PLANE_HEADER (bitpos=%zu)\n", _jxr_rbitstream_bitpos(str)); |
412 | | |
413 | | /* NOTE: The "use_clr_fmt" is the encoded color format, and is |
414 | | not necessarily the same as the image color format |
415 | | signaled in the image header. All of our processing of an |
416 | | image plane is handled using the "use_clr_fmt", and only |
417 | | transformed to the image color format on the way out. */ |
418 | |
|
419 | 0 | image->use_clr_fmt = _jxr_rbitstream_uint3(str); /* INTERNAL_CLR_FMT */ |
420 | 0 | image->scaled_flag = _jxr_rbitstream_uint1(str); /* NO_SCALED_FLAG */ |
421 | 0 | image->bands_present = _jxr_rbitstream_uint4(str); /* BANDS_PRESENT */ |
422 | | |
423 | | /* for alpha image plane, INTERNAL_CLR_FMT == YONLY */ |
424 | 0 | if (alpha) |
425 | 0 | assert(image->use_clr_fmt == 0); |
426 | |
|
427 | 0 | DEBUG(" INTERNAL_CLR_FMT = %d\n", image->use_clr_fmt); |
428 | 0 | DEBUG(" SCALED_FLAG = %s\n", image->scaled_flag? "true" : "false"); |
429 | 0 | DEBUG(" BANDS_PRESENT = %d\n", image->bands_present); |
430 | |
|
431 | 0 | switch (image->use_clr_fmt) { |
432 | 0 | case 0: /* YONLY */ |
433 | 0 | image->num_channels = 1; |
434 | 0 | break; |
435 | 0 | case 1: /* YUV420 */ |
436 | 0 | _jxr_rbitstream_uint1(str); /* RESERVED_E_BIT */ |
437 | 0 | image->chroma_centering_x = _jxr_rbitstream_uint3(str); /* CHROMA_CENTERING_X */ |
438 | 0 | _jxr_rbitstream_uint1(str); /* RESERVED_G_BIT */ |
439 | 0 | image->chroma_centering_y = _jxr_rbitstream_uint3(str); /* CHROMA_CENTERING_Y */ |
440 | 0 | image->num_channels = 3; |
441 | 0 | break; |
442 | 0 | case 2: /* YUV422 */ |
443 | 0 | _jxr_rbitstream_uint1(str); /* RESERVED_E_BIT */ |
444 | 0 | image->chroma_centering_x = _jxr_rbitstream_uint3(str); /* CHROMA_CENTERING_X */ |
445 | 0 | _jxr_rbitstream_uint4(str); /* RESERVED_H */ |
446 | 0 | image->chroma_centering_y = 0; |
447 | 0 | image->num_channels = 3; |
448 | 0 | break; |
449 | 0 | case 3: /* YUV444 */ |
450 | 0 | _jxr_rbitstream_uint4(str); /* RESERVED_F */ |
451 | 0 | _jxr_rbitstream_uint4(str); /* RESERVED_H */ |
452 | 0 | image->num_channels = 3; |
453 | 0 | break; |
454 | 0 | case 4: /* YUVK */ |
455 | 0 | image->num_channels = 4; |
456 | 0 | break; |
457 | 0 | case 6: /* NCOMPONENT */ |
458 | 0 | num_components = _jxr_rbitstream_uint4(str); |
459 | 0 | if (num_components == 0xf) { |
460 | 0 | image->num_channels = 16 + _jxr_rbitstream_uint12(str); |
461 | 0 | } |
462 | 0 | else { |
463 | 0 | image->num_channels = 1 + num_components; |
464 | 0 | _jxr_rbitstream_uint4(str); /* RESERVED_H */ |
465 | 0 | } |
466 | 0 | break; |
467 | 0 | case 5: /* RESERVED */ |
468 | 0 | case 7: /* RESERVED */ |
469 | 0 | break; |
470 | 0 | } |
471 | | |
472 | | /* |
473 | | check container conformance - specific for tag based container |
474 | | this section should be modified when the container is |
475 | | */ |
476 | 0 | if (image->container_alpha) { |
477 | 0 | if (image->container_separate_alpha) { |
478 | 0 | if (image->container_current_separate_alpha) { |
479 | 0 | assert(image->num_channels == 1); |
480 | 0 | assert(image->bands_present == image->container_alpha_band_presence || image->container_alpha_band_presence > 3 || image->container_alpha_band_presence < 0); |
481 | 0 | } |
482 | 0 | else { |
483 | 0 | assert(image->num_channels == image->container_nc - 1); |
484 | 0 | assert((image->bands_present == image->container_image_band_presence) || (image->container_image_band_presence > 3) || (image->container_image_band_presence < 0)); |
485 | 0 | } |
486 | 0 | } |
487 | 0 | else { |
488 | 0 | if (alpha) { |
489 | 0 | assert(image->num_channels == 1); |
490 | 0 | assert(image->bands_present == image->container_alpha_band_presence || image->container_alpha_band_presence > 3 || image->container_alpha_band_presence < 0); |
491 | 0 | } |
492 | 0 | else { |
493 | 0 | assert(image->num_channels == image->container_nc - 1); |
494 | 0 | assert(image->bands_present == image->container_image_band_presence || image->container_image_band_presence > 3 || (image->container_image_band_presence < 0)); |
495 | 0 | } |
496 | 0 | } |
497 | 0 | } |
498 | 0 | else { |
499 | 0 | assert(image->num_channels == image->container_nc); |
500 | 0 | assert(image->bands_present == image->container_image_band_presence || image->container_image_band_presence > 3 || (image->container_image_band_presence < 0)); |
501 | 0 | } |
502 | | |
503 | |
|
504 | 0 | switch (SOURCE_BITDEPTH(image)) { |
505 | 0 | case 0: /* BD1WHITE1 */ |
506 | 0 | case 1: /* BD8 */ |
507 | 0 | case 4: /* BD16F */ |
508 | 0 | case 8: /* BD5 */ |
509 | 0 | case 9: /* BD10 */ |
510 | 0 | case 15: /* BD1BLACK1 */ |
511 | 0 | image->shift_bits = 0; |
512 | 0 | break; |
513 | 0 | case 2: /* BD16 */ |
514 | 0 | case 3: /* BD16S */ |
515 | 0 | case 6: /* BD32S */ |
516 | 0 | image->shift_bits = _jxr_rbitstream_uint8(str); /* SHIFT_BITS */ |
517 | 0 | DEBUG(" SHIFT_BITS = %u\n", image->shift_bits); |
518 | 0 | break; |
519 | 0 | case 7: /* BD32F */ |
520 | 0 | image->len_mantissa = _jxr_rbitstream_uint8(str); /* LEN_MANTISSA */ |
521 | 0 | image->exp_bias = _jxr_rbitstream_uint8(str); /* EXP_BIAS */ |
522 | 0 | DEBUG(" LEN_MANTISSA = %u\n", image->len_mantissa); |
523 | 0 | DEBUG(" EXP_BIAS = %u\n", image->exp_bias); |
524 | 0 | break; |
525 | 0 | default: /* RESERVED */ |
526 | 0 | DEBUG(" XXXX Inexplicable SOURCE_BITDEPTH=%u\n", SOURCE_BITDEPTH(image)); |
527 | 0 | break; |
528 | 0 | } |
529 | | |
530 | | /* If the stream signals that the DC frames use a uniform |
531 | | quantization parameter, then collect that parameter |
532 | | here. In this case, DC quantization parameters elsewhere in |
533 | | the image are suppressed. Note that per macroblock, there |
534 | | is only 1 DC value, so only 1 DC QP is needed. */ |
535 | 0 | image->dc_frame_uniform = _jxr_rbitstream_uint1(str); |
536 | 0 | DEBUG(" DC_FRAME_UNIFORM = %s\n", image->dc_frame_uniform?"true":"false"); |
537 | 0 | if (image->dc_frame_uniform) { |
538 | 0 | _jxr_r_DC_QP(image, str); |
539 | 0 | } |
540 | |
|
541 | 0 | if (image->bands_present != 3 /*DCONLY*/) { |
542 | 0 | _jxr_rbitstream_uint1(str); /* RESERVED_I_BIT */ |
543 | |
|
544 | 0 | image->lp_frame_uniform = _jxr_rbitstream_uint1(str); |
545 | 0 | DEBUG(" LP_FRAME_UNIFORM = %s\n", image->lp_frame_uniform?"true":"false"); |
546 | 0 | if (image->lp_frame_uniform) { |
547 | 0 | image->num_lp_qps = 1; |
548 | 0 | _jxr_r_LP_QP(image, str); |
549 | 0 | } |
550 | |
|
551 | 0 | if (image->bands_present != 2 /*NOHIGHPASS*/) { |
552 | 0 | _jxr_rbitstream_uint1(str); /* RESERVED_J_BIT */ |
553 | |
|
554 | 0 | image->hp_frame_uniform = _jxr_rbitstream_uint1(str); |
555 | 0 | DEBUG(" HP_FRAME_UNIFORM = %s\n", image->hp_frame_uniform?"true":"false"); |
556 | 0 | if (image->hp_frame_uniform) { |
557 | 0 | image->num_hp_qps = 1; |
558 | 0 | r_HP_QP(image, str); |
559 | 0 | } |
560 | 0 | } |
561 | |
|
562 | 0 | } |
563 | |
|
564 | 0 | _jxr_rbitstream_syncbyte(str); |
565 | 0 | DEBUG("END IMAGE_PLANE_HEADER (%zd bytes, bitpos=%zu)\n", |
566 | 0 | str->read_count - save_count, _jxr_rbitstream_bitpos(str)); |
567 | |
|
568 | 0 | return 0; |
569 | 0 | } |
570 | | |
571 | | static int get_ch_mode(jxr_image_t image, struct rbitstream*str) |
572 | 0 | { |
573 | 0 | int ch_mode; |
574 | 0 | if (image->num_channels == 1) { |
575 | 0 | ch_mode = 0; /* UNIFORM */ |
576 | 0 | } else { |
577 | 0 | ch_mode = _jxr_rbitstream_uint2(str); |
578 | 0 | } |
579 | 0 | return ch_mode; |
580 | 0 | } |
581 | | |
582 | | int _jxr_r_DC_QP(jxr_image_t image, struct rbitstream*str) |
583 | 0 | { |
584 | 0 | unsigned idx; |
585 | |
|
586 | 0 | int ch_mode = get_ch_mode(image, str); |
587 | 0 | DEBUG(" DC_QP CH_MODE=%d ", ch_mode); |
588 | |
|
589 | 0 | switch (ch_mode) { |
590 | 0 | case 0: /* UNIFORM */ |
591 | 0 | image->dc_quant_ch[0] = _jxr_rbitstream_uint8(str); |
592 | 0 | DEBUG(" DC_QUANT UNIFORM =%u", image->dc_quant_ch[0]); |
593 | 0 | for (idx = 1 ; idx < image->num_channels ; idx += 1) |
594 | 0 | image->dc_quant_ch[idx] = image->dc_quant_ch[0]; |
595 | 0 | break; |
596 | 0 | case 1: /* SEPARATE */ |
597 | 0 | image->dc_quant_ch[0] = _jxr_rbitstream_uint8(str); |
598 | 0 | image->dc_quant_ch[1] = _jxr_rbitstream_uint8(str); |
599 | 0 | image->dc_quant_ch[2] = image->dc_quant_ch[1]; |
600 | 0 | DEBUG(" DC_QUANT SEPARATE Y=%u, Chr=%u", image->dc_quant_ch[0],image->dc_quant_ch[1]); |
601 | 0 | break; |
602 | 0 | case 2: /* INDEPENDENT */ |
603 | 0 | assert(image->num_channels <= MAX_CHANNELS); |
604 | 0 | for (idx = 0 ; idx < image->num_channels ; idx += 1) { |
605 | 0 | image->dc_quant_ch[idx] = _jxr_rbitstream_uint8(str); |
606 | 0 | DEBUG(" DC_QUANT INDEPENDENT[%d] = %u", idx, image->dc_quant_ch[idx]); |
607 | 0 | } |
608 | 0 | break; |
609 | 0 | case 3: /* Reserved */ |
610 | 0 | break; |
611 | 0 | default: |
612 | 0 | assert(0); |
613 | 0 | break; |
614 | 0 | } |
615 | 0 | DEBUG("\n"); |
616 | |
|
617 | 0 | return 0; |
618 | 0 | } |
619 | | |
620 | | int _jxr_r_LP_QP(jxr_image_t image, struct rbitstream*str) |
621 | 0 | { |
622 | 0 | unsigned q; |
623 | |
|
624 | 0 | for (q = 0 ; q < image->num_lp_qps ; q += 1) { |
625 | 0 | unsigned idx; |
626 | 0 | int ch_mode = get_ch_mode(image, str); |
627 | 0 | DEBUG(" LP_QP[%u] CH_MODE=%d LP_QUANT=", q, ch_mode); |
628 | |
|
629 | 0 | switch (ch_mode) { |
630 | 0 | case 0: /* UNIFORM */ |
631 | 0 | image->lp_quant_ch[0][q] = _jxr_rbitstream_uint8(str); |
632 | 0 | DEBUG("%d", image->lp_quant_ch[0][q]); |
633 | 0 | for (idx = 1 ; idx < image->num_channels ; idx += 1) |
634 | 0 | image->lp_quant_ch[idx][q] = image->lp_quant_ch[0][q]; |
635 | 0 | break; |
636 | 0 | case 1: /* SEPARATE */ |
637 | 0 | image->lp_quant_ch[0][q] = _jxr_rbitstream_uint8(str); |
638 | 0 | image->lp_quant_ch[1][q] = _jxr_rbitstream_uint8(str); |
639 | 0 | DEBUG("SEPARATE Y=%d Chr=%d", image->lp_quant_ch[0][q], image->lp_quant_ch[1][q]); |
640 | 0 | for (idx = 2 ; idx < image->num_channels ; idx += 1) |
641 | 0 | image->lp_quant_ch[idx][q] = image->lp_quant_ch[1][q]; |
642 | 0 | break; |
643 | 0 | case 2: /* INDEPENDENT */ |
644 | 0 | DEBUG("INDEPENDENT ="); |
645 | 0 | for (idx = 0 ; idx < image->num_channels ; idx += 1) { |
646 | 0 | image->lp_quant_ch[idx][q] = _jxr_rbitstream_uint8(str); |
647 | 0 | DEBUG(" %d", image->lp_quant_ch[idx][q]); |
648 | 0 | } |
649 | 0 | break; |
650 | 0 | case 3: /* Reserved */ |
651 | 0 | break; |
652 | 0 | default: |
653 | 0 | assert(0); |
654 | 0 | break; |
655 | 0 | } |
656 | 0 | DEBUG("\n"); |
657 | 0 | } |
658 | | |
659 | 0 | return 0; |
660 | 0 | } |
661 | | |
662 | | static int r_HP_QP(jxr_image_t image, struct rbitstream*str) |
663 | 0 | { |
664 | 0 | unsigned q; |
665 | |
|
666 | 0 | for (q = 0 ; q < image->num_hp_qps ; q += 1) { |
667 | 0 | unsigned idx; |
668 | 0 | int ch_mode = get_ch_mode(image, str); |
669 | 0 | DEBUG("HP_QP[%u] CH_MODE: %d ", q, ch_mode); |
670 | |
|
671 | 0 | switch (ch_mode) { |
672 | 0 | case 0: /* UNIFORM */ |
673 | 0 | image->HP_QUANT_Y[q] = _jxr_rbitstream_uint8(str); |
674 | 0 | DEBUG("UNIFORM %d", image->hp_quant_ch[0][q]); |
675 | 0 | for (idx = 1 ; idx < image->num_channels ; idx += 1) |
676 | 0 | image->hp_quant_ch[idx][q] = image->hp_quant_ch[0][q]; |
677 | 0 | break; |
678 | 0 | case 1: /* SEPARATE */ |
679 | 0 | image->HP_QUANT_Y[q] = _jxr_rbitstream_uint8(str); |
680 | 0 | image->hp_quant_ch[1][q] = _jxr_rbitstream_uint8(str); |
681 | 0 | DEBUG("SEPARATE Y=%d Chr=%d", image->hp_quant_ch[0][q], image->hp_quant_ch[1][q]); |
682 | 0 | for (idx = 2 ; idx < image->num_channels ; idx += 1) |
683 | 0 | image->hp_quant_ch[idx][q] = image->hp_quant_ch[1][q]; |
684 | 0 | break; |
685 | 0 | case 2: /* INDEPENDENT */ |
686 | 0 | DEBUG("INDEPENDENT ="); |
687 | 0 | for (idx = 0 ; idx < image->num_channels ; idx += 1) { |
688 | 0 | image->hp_quant_ch[idx][q] = _jxr_rbitstream_uint8(str); |
689 | 0 | DEBUG(" %d", image->hp_quant_ch[idx][q]); |
690 | 0 | } |
691 | 0 | break; |
692 | 0 | case 3: /* Reserved */ |
693 | 0 | break; |
694 | 0 | default: |
695 | 0 | assert(0); |
696 | 0 | break; |
697 | 0 | } |
698 | 0 | DEBUG(" bitpos=%zu\n", _jxr_rbitstream_bitpos(str)); |
699 | 0 | } |
700 | | |
701 | 0 | return 0; |
702 | 0 | } |
703 | | |
704 | | static int r_INDEX_TABLE(jxr_image_t image, struct rbitstream*str) |
705 | 0 | { |
706 | 0 | DEBUG("INDEX_TABLE START bitpos=%zu\n", _jxr_rbitstream_bitpos(str)); |
707 | 0 | if (INDEXTABLE_PRESENT_FLAG(image)) { |
708 | 0 | int num_index_table_entries; |
709 | 0 | int idx; |
710 | |
|
711 | 0 | uint8_t s0 = _jxr_rbitstream_uint8(str); |
712 | 0 | uint8_t s1 = _jxr_rbitstream_uint8(str); |
713 | 0 | DEBUG(" STARTCODE = 0x%02x 0x%02x\n", s0, s1); |
714 | 0 | if (s0 != 0x00 || s1 != 0x01) |
715 | 0 | return JXR_EC_ERROR; |
716 | | |
717 | 0 | if (FREQUENCY_MODE_CODESTREAM_FLAG(image) == 0 /* SPATIALMODE */) { |
718 | 0 | num_index_table_entries = image->tile_rows * image->tile_columns; |
719 | |
|
720 | 0 | } else { |
721 | 0 | num_index_table_entries = image->tile_rows * image->tile_columns; |
722 | 0 | switch (image->bands_present) { |
723 | 0 | case 4: /* ISOLATED */ |
724 | 0 | num_index_table_entries *= 4; |
725 | 0 | break; |
726 | 0 | default: |
727 | 0 | num_index_table_entries *= 4 - image->bands_present; |
728 | 0 | break; |
729 | 0 | } |
730 | 0 | } |
731 | 0 | image->tile_index_table_length = num_index_table_entries; |
732 | |
|
733 | 0 | assert(image->tile_index_table == 0); |
734 | 0 | image->tile_index_table = (int64_t*)calloc(num_index_table_entries, sizeof(int64_t)); |
735 | 0 | DEBUG(" INDEX_TABLE has %d table entries\n", num_index_table_entries); |
736 | |
|
737 | 0 | for (idx = 0 ; idx < num_index_table_entries ; idx += 1) { |
738 | 0 | int64_t off = _jxr_rbitstream_intVLW(str); |
739 | 0 | DEBUG(" ... %ld\n", off); |
740 | 0 | image->tile_index_table[idx] = off; |
741 | 0 | } |
742 | 0 | } |
743 | | |
744 | 0 | DEBUG("INTEX_TABLE DONE bitpos=%zu\n", _jxr_rbitstream_bitpos(str)); |
745 | 0 | return 0; |
746 | 0 | } |
747 | | |
748 | | static int64_t r_PROFILE_LEVEL_INFO(jxr_image_t image, struct rbitstream*str) |
749 | 0 | { |
750 | 0 | int64_t num_bytes = 0; |
751 | 0 | uint16_t reserved_l; |
752 | 0 | unsigned last_flag; |
753 | |
|
754 | 0 | int64_t last; |
755 | 0 | for (last = 0 ; last == 0 ; last = last_flag) { |
756 | 0 | image->profile_idc = _jxr_rbitstream_uint8(str); /* PROFILE_IDC */ |
757 | 0 | DEBUG(" Profile signaled in file %ld bytes\n", image->profile_idc); |
758 | 0 | image->level_idc = _jxr_rbitstream_uint8(str); /* LEVEL_IDC */ |
759 | 0 | DEBUG(" Level signaled in file %ld bytes\n", image->level_idc); |
760 | 0 | reserved_l = _jxr_rbitstream_uint15(str); /* RESERVED_L */ |
761 | 0 | last_flag = _jxr_rbitstream_uint1(str); /* LAST_FLAG */ |
762 | 0 | num_bytes += 4; |
763 | 0 | } |
764 | |
|
765 | 0 | return num_bytes; |
766 | 0 | } |
767 | | |
768 | | static int r_TILE(jxr_image_t image, struct rbitstream*str) |
769 | 0 | { |
770 | 0 | int rc = 0; |
771 | 0 | image->tile_quant = (struct jxr_tile_qp *) calloc(image->tile_columns*image->tile_rows, sizeof(*(image->tile_quant))); |
772 | 0 | assert(image->tile_quant); |
773 | |
|
774 | 0 | if (FREQUENCY_MODE_CODESTREAM_FLAG(image) == 0 /* SPATIALMODE */) { |
775 | |
|
776 | 0 | unsigned tx, ty, tt=0; |
777 | 0 | for (ty = 0 ; ty < image->tile_rows ; ty += 1) { |
778 | 0 | for (tx = 0 ; tx < image->tile_columns ; tx += 1) { |
779 | 0 | if(INDEXTABLE_PRESENT_FLAG(image)) |
780 | 0 | { |
781 | 0 | _jxr_rbitstream_seek(str, image->tile_index_table[tt]); |
782 | 0 | tt++; |
783 | 0 | } |
784 | 0 | rc = _jxr_r_TILE_SPATIAL(image, str, tx, ty); |
785 | 0 | if (rc < 0) goto RET; |
786 | 0 | } |
787 | 0 | } |
788 | 0 | } else { /* FREQUENCYMODE */ |
789 | |
|
790 | 0 | unsigned tx, ty, tt; |
791 | 0 | int num_bands = 0; |
792 | 0 | switch (image->bands_present) { |
793 | 0 | case 0: /* ALL */ |
794 | 0 | num_bands = 4; |
795 | 0 | break; |
796 | 0 | case 1: /* NOFLEXBITS */ |
797 | 0 | num_bands = 3; |
798 | 0 | break; |
799 | 0 | case 2: /* NOHIGHPASS */ |
800 | 0 | num_bands = 2; |
801 | 0 | break; |
802 | 0 | case 3: /* DCONLY */ |
803 | 0 | num_bands = 1; |
804 | 0 | break; |
805 | 0 | case 4: /* ISOLATED */ |
806 | 0 | break; |
807 | 0 | } |
808 | | |
809 | 0 | for (ty = 0, tt=0 ; ty < image->tile_rows ; ty += 1) { |
810 | 0 | for (tx = 0 ; tx < image->tile_columns ; tx += 1) { |
811 | 0 | _jxr_rbitstream_seek(str, image->tile_index_table[tt*num_bands+0]); |
812 | 0 | rc = _jxr_r_TILE_DC(image, str, tx, ty); |
813 | 0 | if (rc < 0) goto RET; |
814 | 0 | tt += 1; |
815 | 0 | } |
816 | 0 | } |
817 | | |
818 | 0 | if (num_bands > 1) { |
819 | 0 | for (ty = 0, tt=0 ; ty < image->tile_rows ; ty += 1) { |
820 | 0 | for (tx = 0 ; tx < image->tile_columns ; tx += 1) { |
821 | 0 | _jxr_rbitstream_seek(str, image->tile_index_table[tt*num_bands+1]); |
822 | 0 | rc = _jxr_r_TILE_LP(image, str, tx, ty); |
823 | 0 | if (rc < 0) goto RET; |
824 | 0 | tt += 1; |
825 | 0 | } |
826 | 0 | } |
827 | 0 | } |
828 | | |
829 | 0 | if (num_bands > 2) { |
830 | 0 | for (ty = 0, tt=0 ; ty < image->tile_rows ; ty += 1) { |
831 | 0 | for (tx = 0 ; tx < image->tile_columns ; tx += 1) { |
832 | 0 | _jxr_rbitstream_seek(str, image->tile_index_table[tt*num_bands+2]); |
833 | 0 | rc = _jxr_r_TILE_HP(image, str, tx, ty); |
834 | 0 | if (rc < 0) goto RET; |
835 | 0 | tt += 1; |
836 | 0 | } |
837 | 0 | } |
838 | 0 | } |
839 | | |
840 | 0 | if (num_bands > 3) { |
841 | 0 | for (ty = 0, tt=0 ; ty < image->tile_rows ; ty += 1) { |
842 | 0 | for (tx = 0 ; tx < image->tile_columns ; tx += 1) { |
843 | 0 | int64_t off = image->tile_index_table[tt*num_bands+3]; |
844 | 0 | if (off >= 0) { |
845 | 0 | _jxr_rbitstream_seek(str, off); |
846 | 0 | rc = _jxr_r_TILE_FLEXBITS(image, str, tx, ty); |
847 | 0 | if (rc < 0) goto RET; |
848 | 0 | } else { |
849 | 0 | _jxr_r_TILE_FLEXBITS_ESCAPE(image, tx, ty); |
850 | 0 | } |
851 | 0 | tt += 1; |
852 | 0 | } |
853 | 0 | } |
854 | 0 | } |
855 | | |
856 | 0 | _jxr_frequency_mode_render(image); |
857 | 0 | } |
858 | | |
859 | 0 | RET: |
860 | 0 | free(image->tile_quant); |
861 | 0 | return rc; |
862 | 0 | } |
863 | | |
864 | | void _jxr_r_TILE_HEADER_DC(jxr_image_t image, struct rbitstream*str, |
865 | | int alpha_flag, unsigned tx, unsigned ty) |
866 | 0 | { |
867 | 0 | DEBUG(" TILE_HEADER_DC START bitpos=%zu\n", _jxr_rbitstream_bitpos(str)); |
868 | 0 | if (image->dc_frame_uniform == 0) { |
869 | 0 | DEBUG(" TILE_HEADER_DC: parse non-uniform DC_QP\n"); |
870 | 0 | _jxr_r_DC_QP(image, str); |
871 | 0 | memcpy(image->tile_quant[ty*(image->tile_columns) + tx ].dc_quant_ch, image->dc_quant_ch, MAX_CHANNELS); |
872 | 0 | } |
873 | 0 | } |
874 | | |
875 | | void _jxr_r_TILE_HEADER_LOWPASS(jxr_image_t image, struct rbitstream*str, |
876 | | int alpha_flag, |
877 | | unsigned tx, unsigned ty) |
878 | 0 | { |
879 | 0 | DEBUG(" TILE_HEADER_LOWPASS START bitpos=%zu\n", _jxr_rbitstream_bitpos(str)); |
880 | 0 | if (image->lp_frame_uniform == 0) { |
881 | 0 | image->lp_use_dc_qp = _jxr_rbitstream_uint1(str); |
882 | 0 | DEBUG(" TILE_HEADER_LP: parse non-uniform LP_QP: USE_DC_QP=%u\n", |
883 | 0 | image->lp_use_dc_qp); |
884 | 0 | if (image->lp_use_dc_qp == 0) { |
885 | 0 | image->num_lp_qps = _jxr_rbitstream_uint4(str) + 1; |
886 | 0 | DEBUG(" TILE_HEADER_LP: NUM_LP_QPS = %d\n", image->num_lp_qps); |
887 | 0 | _jxr_r_LP_QP(image, str); |
888 | 0 | memcpy(image->tile_quant[ty*(image->tile_columns) + tx].lp_quant_ch, image->lp_quant_ch, MAX_CHANNELS*MAX_LP_QPS); |
889 | 0 | } |
890 | 0 | else |
891 | 0 | { |
892 | | /* Use the same quantization index as the dc band (the dc quantization step size could be different for each tile, so store it */ |
893 | 0 | int ch; |
894 | 0 | for(ch = 0; ch < image->num_channels; ch++) |
895 | 0 | image->tile_quant[ty*(image->tile_columns) + tx].lp_quant_ch[ch][0] = image->dc_quant_ch[ch]; |
896 | 0 | } |
897 | 0 | } |
898 | 0 | } |
899 | | |
900 | | |
901 | | void _jxr_r_TILE_HEADER_HIGHPASS(jxr_image_t image, struct rbitstream*str, |
902 | | int alpha_flag, |
903 | | unsigned tx, unsigned ty) |
904 | 0 | { |
905 | 0 | if (image->hp_frame_uniform == 0) { |
906 | 0 | image->hp_use_lp_qp = _jxr_rbitstream_uint1(str); |
907 | 0 | DEBUG(" TILE_HEADER_HP: parse non-uniform HP_QP: USE_LP_QP=%u\n", |
908 | 0 | image->hp_use_lp_qp); |
909 | |
|
910 | 0 | if (image->hp_use_lp_qp == 0) { |
911 | 0 | image->num_hp_qps = _jxr_rbitstream_uint4(str) + 1; |
912 | 0 | DEBUG(" TILE_HEADER_HIGHPASS: NUM_HP_QPS = %d\n", image->num_hp_qps); |
913 | 0 | r_HP_QP(image, str); |
914 | 0 | memcpy(image->tile_quant[ty*(image->tile_columns) + tx].hp_quant_ch, image->lp_quant_ch, MAX_CHANNELS*MAX_HP_QPS); |
915 | 0 | } |
916 | 0 | else |
917 | 0 | { |
918 | | /* Use the same quantization index as the lp band (the lp quantization step size could be different for each tile, so store it */ |
919 | 0 | int ch; |
920 | 0 | image->num_hp_qps = image->num_lp_qps; |
921 | 0 | for(ch = 0; ch < image->num_channels; ch++) { |
922 | 0 | memcpy(image->hp_quant_ch[ch], image->lp_quant_ch[ch], MAX_LP_QPS); |
923 | 0 | memcpy(image->tile_quant[ty*(image->tile_columns) + tx].hp_quant_ch[ch], image->lp_quant_ch[ch], MAX_LP_QPS); |
924 | 0 | } |
925 | 0 | } |
926 | 0 | } |
927 | 0 | } |
928 | | |
929 | | unsigned _jxr_DECODE_QP_INDEX(struct rbitstream*str, unsigned index_count) |
930 | 0 | { |
931 | 0 | static const int bits_per_qp_index[] = {0,0,1,1,2,2,3,3, 3,3,4,4,4,4,4,4,4}; |
932 | |
|
933 | 0 | int nonzero_flag = _jxr_rbitstream_uint1(str); |
934 | 0 | int bits_count; |
935 | |
|
936 | 0 | assert(index_count <= 16); |
937 | 0 | if (nonzero_flag == 0) |
938 | 0 | return 0; |
939 | | |
940 | 0 | bits_count = bits_per_qp_index[index_count]; |
941 | | /* DECODE_QP_INDEX is onny called if the index count is |
942 | | greater then 1. Therefore, the bits_count here must be more |
943 | | then zero. */ |
944 | 0 | assert(bits_count > 0); |
945 | |
|
946 | 0 | return _jxr_rbitstream_uintN(str, bits_count)+1; |
947 | 0 | } |
948 | | |
949 | | /* |
950 | | * Decode the single DC component for the macroblock. |
951 | | */ |
952 | | void _jxr_r_MB_DC(jxr_image_t image, struct rbitstream*str, |
953 | | int alpha_flag, |
954 | | unsigned tx, unsigned ty, |
955 | | unsigned mx, unsigned my) |
956 | 0 | { |
957 | 0 | int lap_mean[2]; |
958 | 0 | lap_mean[0] = 0; |
959 | 0 | lap_mean[1] = 0; |
960 | |
|
961 | 0 | DEBUG(" MB_DC tile=[%u %u] mb=[%u %u] bitpos=%zu\n", |
962 | 0 | tx, ty, mx, my, _jxr_rbitstream_bitpos(str)); |
963 | |
|
964 | 0 | if (_jxr_InitContext(image, tx, ty, mx, my)) { |
965 | 0 | DEBUG(" MB_DC: Initialize Context\n"); |
966 | 0 | _jxr_InitVLCTable(image, AbsLevelIndDCLum); |
967 | 0 | _jxr_InitVLCTable(image, AbsLevelIndDCChr); |
968 | 0 | _jxr_InitializeModelMB(&image->model_dc, 0/*DC*/); |
969 | 0 | } |
970 | |
|
971 | 0 | if (image->use_clr_fmt==0 || image->use_clr_fmt==4 || image->use_clr_fmt==6) { |
972 | | /* clr_fmt == YONLY, YUVK or NCOMPONENT */ |
973 | 0 | unsigned idx; |
974 | 0 | for (idx = 0 ; idx < image->num_channels ; idx += 1) { |
975 | 0 | int m = (idx == 0)? 0 : 1; |
976 | 0 | int model_bits = image->model_dc.bits[m]; |
977 | 0 | unsigned is_dc_ch = _jxr_rbitstream_uint1(str); |
978 | 0 | uint32_t dc_val; |
979 | 0 | DEBUG(" MB_DC: IS_DC_CH=%u, model_bits=%d\n", |
980 | 0 | is_dc_ch, model_bits); |
981 | 0 | if (is_dc_ch) { |
982 | 0 | lap_mean[m] += 1; |
983 | 0 | } |
984 | 0 | dc_val = r_DEC_DC(image, str, tx, ty, mx, my, |
985 | 0 | model_bits, 0/*chroma_flag==FALSE*/, |
986 | 0 | is_dc_ch); |
987 | |
|
988 | 0 | MACROBLK_CUR_DC(image,idx,tx, mx) = dc_val; |
989 | 0 | DEBUG(" dc_val at t=[%u %u], m=[%u %u] == %d (0x%08x)\n", |
990 | 0 | tx, ty, mx, my, (int32_t)dc_val, dc_val); |
991 | 0 | } |
992 | 0 | } else { |
993 | 0 | int is_dc_yuv = get_is_dc_yuv(str); |
994 | 0 | int model_bits_y = image->model_dc.bits[0]; |
995 | 0 | int model_bits_uv = image->model_dc.bits[1]; |
996 | 0 | uint32_t dc_val_v; |
997 | 0 | uint32_t dc_val_u; |
998 | 0 | uint32_t dc_val_y; |
999 | |
|
1000 | 0 | assert(image->num_channels == 3); |
1001 | 0 | DEBUG(" MB_DC: IS_DC_YUV=0x%x, model_bits[0]=%d, model_bits[1]=%d\n", |
1002 | 0 | is_dc_yuv, model_bits_y, model_bits_uv); |
1003 | |
|
1004 | 0 | if (is_dc_yuv&4) |
1005 | 0 | lap_mean[0] += 1; |
1006 | 0 | dc_val_y = r_DEC_DC(image, str, tx, ty, mx, my, |
1007 | 0 | model_bits_y, 0/*chroma_flag==FALSE*/, |
1008 | 0 | is_dc_yuv&4); |
1009 | |
|
1010 | 0 | if (is_dc_yuv&2) |
1011 | 0 | lap_mean[1] += 1; |
1012 | 0 | dc_val_u = r_DEC_DC(image, str, tx, ty, mx, my, |
1013 | 0 | model_bits_uv, 1/*chroma_flag==TRUE*/, |
1014 | 0 | is_dc_yuv&2); |
1015 | |
|
1016 | 0 | if (is_dc_yuv&1) |
1017 | 0 | lap_mean[1] += 1; |
1018 | 0 | dc_val_v = r_DEC_DC(image, str, tx, ty, mx, my, |
1019 | 0 | model_bits_uv, 1/*chroma_flag==TRUE*/, |
1020 | 0 | is_dc_yuv&1); |
1021 | |
|
1022 | 0 | MACROBLK_CUR_DC(image,0,tx, mx) = dc_val_y; |
1023 | 0 | MACROBLK_CUR_DC(image,1,tx, mx) = dc_val_u; |
1024 | 0 | MACROBLK_CUR_DC(image,2,tx, mx) = dc_val_v; |
1025 | 0 | DEBUG(" dc_val at t=[%u %u], m=[%u %u] == %d (0x%08x), %d (0x%08x), %d (0x%08x)\n", |
1026 | 0 | tx, ty, mx, my, (int)dc_val_y, dc_val_y, (int)dc_val_u, dc_val_u, (int)dc_val_v, dc_val_v); |
1027 | 0 | } |
1028 | | |
1029 | | /* */ |
1030 | 0 | DEBUG(" MB_DC: UpdateModelMB: lap_mean={%u %u}\n", lap_mean[0], lap_mean[1]); |
1031 | 0 | _jxr_UpdateModelMB(image, lap_mean, &image->model_dc, 0/*DC*/); |
1032 | 0 | if (_jxr_ResetContext(image, tx, mx)) { |
1033 | 0 | DEBUG(" MB_DC: Reset Context\n"); |
1034 | | /* AdaptDC */ |
1035 | 0 | _jxr_AdaptVLCTable(image, AbsLevelIndDCLum); |
1036 | 0 | _jxr_AdaptVLCTable(image, AbsLevelIndDCChr); |
1037 | 0 | } |
1038 | 0 | DEBUG(" MB_DC DONE tile=[%u %u] mb=[%u %u]\n", tx, ty, mx, my); |
1039 | 0 | } |
1040 | | |
1041 | | /* |
1042 | | * When the LP value is input from the stream, it is delivered into |
1043 | | * the target array based on a scan order. The "lopass_scanorder" |
1044 | | * array maps the list of LP values (actually the position in the |
1045 | | * list) to the location in the scan. Thus the scan order places the |
1046 | | * value into the lpinput array. |
1047 | | * |
1048 | | * A property of the lpinput is that it is sparse. The adpative scan |
1049 | | * order tries to adapt the scan order so that the most frequent value |
1050 | | * is pressed to the beginning of the input stream. It does this by |
1051 | | * counting the arrival of each value, and bubbling frequent values |
1052 | | * forward. |
1053 | | * |
1054 | | * Note in the code below that the "i" value ranges from 1-16 but the |
1055 | | * tables are numbered from 0-15. Thus "i-1" is used to index tables. |
1056 | | * |
1057 | | * Note that the scanorder is adapted while we go, but the only |
1058 | | * adjustment is to swap the current position with the previous. Thus, |
1059 | | * it is not possible to effect the current pass with the adaptation. |
1060 | | */ |
1061 | | static void AdaptiveLPScan(jxr_image_t image, int lpinput_n[], int i, int value) |
1062 | 0 | { |
1063 | 0 | int k; |
1064 | 0 | assert(i > 0); |
1065 | 0 | k = image->lopass_scanorder[i-1]; |
1066 | 0 | lpinput_n[k] = value; |
1067 | 0 | image->lopass_scantotals[i-1] += 1; |
1068 | 0 | if (i>1 && image->lopass_scantotals[i-1] > image->lopass_scantotals[i-2]) { |
1069 | 0 | SWAP(image->lopass_scantotals[i-1], image->lopass_scantotals[i-2]); |
1070 | 0 | SWAP(image->lopass_scanorder[i-1], image->lopass_scanorder[i-2]); |
1071 | 0 | } |
1072 | 0 | } |
1073 | | |
1074 | | void _jxr_r_MB_LP(jxr_image_t image, struct rbitstream*str, |
1075 | | int alpha_flag, |
1076 | | unsigned tx, unsigned ty, |
1077 | | unsigned mx, unsigned my) |
1078 | 0 | { |
1079 | 0 | static const int transpose420[4] = {0, 2, |
1080 | 0 | 1, 3 }; |
1081 | 0 | static const int transpose422[8] = {0, 2, 1, 3, 4, 6, 5, 7}; |
1082 | 0 | int LPInput[8][16]; |
1083 | 0 | int idx; |
1084 | 0 | int model_bits; |
1085 | 0 | int lap_mean[2]; |
1086 | 0 | int ndx; |
1087 | 0 | int full_planes; |
1088 | 0 | int cbplp; |
1089 | |
|
1090 | 0 | for (idx = 0 ; idx < 8 ; idx += 1) { |
1091 | 0 | int k; |
1092 | 0 | for (k = 0 ; k < 16 ; k += 1) |
1093 | 0 | LPInput[idx][k] = 0; |
1094 | 0 | } |
1095 | |
|
1096 | 0 | lap_mean[0] = 0; |
1097 | 0 | lap_mean[1] = 0; |
1098 | |
|
1099 | 0 | DEBUG(" MB_LP tile=[%u %u] mb=[%u %u] bitpos=%zu\n", |
1100 | 0 | tx, ty, mx, my, _jxr_rbitstream_bitpos(str)); |
1101 | |
|
1102 | 0 | if (_jxr_InitContext(image, tx, ty, mx, my)) { |
1103 | 0 | DEBUG(" Init contexts\n"); |
1104 | 0 | _jxr_InitializeCountCBPLP(image); |
1105 | 0 | _jxr_InitLPVLC(image); |
1106 | 0 | _jxr_InitializeAdaptiveScanLP(image); |
1107 | 0 | _jxr_InitializeModelMB(&image->model_lp, 1/*LP*/); |
1108 | 0 | } |
1109 | |
|
1110 | 0 | if (_jxr_ResetTotals(image, mx)) { |
1111 | 0 | _jxr_ResetTotalsAdaptiveScanLP(image); |
1112 | 0 | } |
1113 | |
|
1114 | 0 | full_planes = image->num_channels; |
1115 | 0 | if (image->use_clr_fmt==2 || image->use_clr_fmt==1) |
1116 | 0 | full_planes = 2; |
1117 | | |
1118 | | /* The CBPLP signals whether any non-zero coefficients are |
1119 | | present in the LP band for this macroblock. It is a bitmask |
1120 | | with a bit for each channel. So for example, YONLY, which |
1121 | | has 1 channel, has a 1-bit cbplp. */ |
1122 | |
|
1123 | 0 | cbplp = 0; |
1124 | | /* if CLR_FMT is YUV420, YUV422 or YUV444... */ |
1125 | 0 | if (image->use_clr_fmt==1 || image->use_clr_fmt==2 || image->use_clr_fmt==3) { |
1126 | 0 | int max = full_planes * 4 - 5; |
1127 | |
|
1128 | 0 | DEBUG(" MB_LP: Calculate YUV CBP using CountZeroCBPLP=%d, CountMaxCBPLP=%d bitpos=%zu\n", |
1129 | 0 | image->count_zero_CBPLP, image->count_max_CBPLP, _jxr_rbitstream_bitpos(str)); |
1130 | |
|
1131 | 0 | if (image->count_zero_CBPLP <= 0 || image->count_max_CBPLP < 0) { |
1132 | 0 | int cbp_yuv_lp1 = dec_cbp_yuv_lp1(image, str); |
1133 | 0 | if (image->count_max_CBPLP < image->count_zero_CBPLP) |
1134 | 0 | cbplp = max - cbp_yuv_lp1; |
1135 | 0 | else |
1136 | 0 | cbplp = cbp_yuv_lp1; |
1137 | 0 | } else { |
1138 | 0 | uint32_t cbp_yuv_lp2 = _jxr_rbitstream_uintN(str, full_planes); |
1139 | 0 | cbplp = cbp_yuv_lp2; |
1140 | 0 | } |
1141 | 0 | _jxr_UpdateCountCBPLP(image, cbplp, max); |
1142 | |
|
1143 | 0 | } else { |
1144 | 0 | int idx; |
1145 | 0 | cbplp = 0; |
1146 | 0 | for (idx = 0 ; idx < image->num_channels ; idx += 1) { |
1147 | 0 | int cbp_ch_lp = _jxr_rbitstream_uint1(str); |
1148 | 0 | cbplp |= cbp_ch_lp << idx; |
1149 | 0 | } |
1150 | 0 | } |
1151 | |
|
1152 | 0 | DEBUG(" MB_LP: cbplp = 0x%x (full_planes=%u)\n", cbplp, full_planes); |
1153 | |
|
1154 | 0 | for (ndx = 0 ; ndx < full_planes ; ndx += 1) { |
1155 | 0 | int idx; |
1156 | 0 | const int chroma_flag = ndx>0? 1 : 0; |
1157 | 0 | int num_nonzero = 0; |
1158 | |
|
1159 | 0 | DEBUG(" MB_LP: process full_plane %u, CBPLP for plane=%d, bitpos=%zu\n", |
1160 | 0 | ndx, (cbplp>>ndx)&1, _jxr_rbitstream_bitpos(str)); |
1161 | 0 | if ((cbplp>>ndx) & 1) { |
1162 | | /* If the CBPLP bit is set for this plane, then we |
1163 | | have parsing to do. Decode the (15) coeffs and |
1164 | | arrange them for use in the MB. */ |
1165 | 0 | int RLCoeffs[32] = {0}; |
1166 | 0 | int location = 1; |
1167 | 0 | for (idx = 0 ; idx < 32 ; idx += 1) |
1168 | 0 | RLCoeffs[idx] = 0; |
1169 | | |
1170 | | /* if CLR_FMT is YUV420 or YUV422 */ |
1171 | 0 | if (image->use_clr_fmt==1/*YUV420*/ && chroma_flag) |
1172 | 0 | location = 10; |
1173 | 0 | if (image->use_clr_fmt==2/*YUV422*/ && chroma_flag) |
1174 | 0 | location = 2; |
1175 | |
|
1176 | 0 | num_nonzero = r_DECODE_BLOCK(image, str, |
1177 | 0 | chroma_flag, RLCoeffs, 1/*LP*/, location); |
1178 | 0 | DEBUG(" : num_nonzero = %d\n", num_nonzero); |
1179 | 0 | assert(num_nonzero <= 16); |
1180 | |
|
1181 | 0 | if ((image->use_clr_fmt==1 || image->use_clr_fmt==2) && chroma_flag) { |
1182 | 0 | static const int remap_arr[] = {4, 1, 2, 3, 5, 6, 7}; |
1183 | 0 | int temp[14]; |
1184 | 0 | int idx; |
1185 | 0 | int k, i; |
1186 | 0 | int count_chr; |
1187 | 0 | int remap_off; |
1188 | 0 | for (idx = 0 ; idx < 14 ; idx += 1) |
1189 | 0 | temp[idx] = 0; |
1190 | |
|
1191 | 0 | remap_off = 0; |
1192 | 0 | if (image->use_clr_fmt==1/*YUV420*/) |
1193 | 0 | remap_off = 1; |
1194 | |
|
1195 | 0 | count_chr = 14; |
1196 | 0 | if (image->use_clr_fmt==1/*YUV420*/) |
1197 | 0 | count_chr = 6; |
1198 | |
|
1199 | 0 | i = 0; |
1200 | 0 | for (k = 0; k < num_nonzero; k+=1) { |
1201 | 0 | i += RLCoeffs[k*2+0]; |
1202 | 0 | temp[i] = RLCoeffs[k*2+1]; |
1203 | 0 | i += 1; |
1204 | 0 | } |
1205 | 0 | for (k = 0; k < count_chr; k+=1) { |
1206 | 0 | int remap = remap_arr[(k>>1) + remap_off]; |
1207 | 0 | int plane = (k&1) + 1; |
1208 | 0 | if (image->use_clr_fmt==1) |
1209 | 0 | remap = transpose420[remap]; |
1210 | 0 | if (image->use_clr_fmt==2) |
1211 | 0 | remap = transpose422[remap]; |
1212 | 0 | LPInput[plane][remap] = temp[k]; |
1213 | 0 | } |
1214 | 0 | #if defined(DEBUG) |
1215 | 0 | { |
1216 | 0 | int k; |
1217 | 0 | DEBUG(" RLCoeffs[ndx=%d] ==", ndx); |
1218 | 0 | for (k = 0 ; k<(num_nonzero*2); k+=2) { |
1219 | 0 | DEBUG(" %d/0x%x", RLCoeffs[k+0], RLCoeffs[k+1]); |
1220 | 0 | } |
1221 | 0 | DEBUG("\n"); |
1222 | 0 | DEBUG(" temp =="); |
1223 | 0 | for (k = 0 ; k<14; k+=1) { |
1224 | 0 | DEBUG(" 0x%x", temp[k]); |
1225 | 0 | } |
1226 | 0 | DEBUG("\n"); |
1227 | 0 | } |
1228 | 0 | #endif |
1229 | 0 | } else { |
1230 | | /* "i" is the current position in the LP |
1231 | | array. It is adjusted based in the run |
1232 | | each time around. This implines that the |
1233 | | run value is the number of 0 elements in |
1234 | | the LP array between non-zero values. */ |
1235 | 0 | int k, i = 1; |
1236 | 0 | for (k = 0; k < num_nonzero; k+=1) { |
1237 | 0 | i += RLCoeffs[k*2]; |
1238 | 0 | AdaptiveLPScan(image, LPInput[ndx], i, RLCoeffs[k*2+1]); |
1239 | 0 | i += 1; |
1240 | 0 | } |
1241 | 0 | } |
1242 | 0 | } |
1243 | |
|
1244 | 0 | #if defined(DEBUG) |
1245 | 0 | if (image->use_clr_fmt == 2/*YUV422*/) { |
1246 | 0 | int k; |
1247 | 0 | DEBUG(" lp val[ndx=%d] before refine ==", ndx); |
1248 | 0 | for (k = 1 ; k<8; k+=1) { |
1249 | 0 | DEBUG(" 0x%x/0x%x", LPInput[1][k], LPInput[2][k]); |
1250 | 0 | } |
1251 | 0 | DEBUG("\n"); |
1252 | |
|
1253 | 0 | } else if (image->use_clr_fmt == 1/*YUV420*/) { |
1254 | 0 | int k; |
1255 | 0 | DEBUG(" lp val[ndx=%d] before refine ==", ndx); |
1256 | 0 | for (k = 1 ; k<4; k+=1) { |
1257 | 0 | DEBUG(" 0x%x/0x%x", LPInput[1][k], LPInput[2][k]); |
1258 | 0 | } |
1259 | 0 | DEBUG("\n"); |
1260 | |
|
1261 | 0 | } else { |
1262 | 0 | int k; |
1263 | 0 | DEBUG(" lp val[ndx=%d] before refine ==", ndx); |
1264 | 0 | for (k = 1 ; k<16; k+=1) { |
1265 | 0 | DEBUG(" 0x%x", LPInput[ndx][k]); |
1266 | 0 | } |
1267 | 0 | DEBUG("\n"); |
1268 | 0 | DEBUG(" adapted scan order =="); |
1269 | 0 | for (k = 0 ; k<15; k+=1) { |
1270 | 0 | DEBUG(" %2d", image->lopass_scanorder[k]); |
1271 | 0 | } |
1272 | 0 | DEBUG("\n"); |
1273 | 0 | DEBUG(" adapted scan totals =="); |
1274 | 0 | for (k = 0 ; k<15; k+=1) { |
1275 | 0 | DEBUG(" %2d", image->lopass_scantotals[k]); |
1276 | 0 | } |
1277 | 0 | DEBUG("\n"); |
1278 | 0 | } |
1279 | 0 | #endif |
1280 | |
|
1281 | 0 | model_bits = image->model_lp.bits[chroma_flag]; |
1282 | 0 | lap_mean[chroma_flag] += num_nonzero; |
1283 | 0 | DEBUG(" MB_LP: start refine, model_bits=%d, bitpos=%zu\n", |
1284 | 0 | model_bits, _jxr_rbitstream_bitpos(str)); |
1285 | 0 | if (model_bits) { |
1286 | 0 | static const int transpose444[16] = { 0, 4, 8,12, |
1287 | 0 | 1, 5, 9,13, |
1288 | 0 | 2, 6,10,14, |
1289 | 0 | 3, 7,11,15 }; |
1290 | 0 | if (chroma_flag == 0) { |
1291 | 0 | int k; |
1292 | 0 | for (k=1 ;k<16; k+=1) { |
1293 | 0 | int k_ptr = transpose444[k]; |
1294 | 0 | LPInput[ndx][k_ptr] = r_REFINE_LP(str, LPInput[ndx][k_ptr], model_bits); |
1295 | 0 | } |
1296 | 0 | } else { |
1297 | 0 | int k; |
1298 | 0 | switch (image->use_clr_fmt) { |
1299 | 0 | case 1: /* YUV420 */ |
1300 | 0 | for (k=1 ; k<4; k+=1) { |
1301 | 0 | int k_ptr = transpose420[k]; |
1302 | 0 | LPInput[1][k_ptr] = r_REFINE_LP(str, LPInput[1][k_ptr], model_bits); |
1303 | 0 | LPInput[2][k_ptr] = r_REFINE_LP(str, LPInput[2][k_ptr], model_bits); |
1304 | 0 | } |
1305 | 0 | break; |
1306 | 0 | case 2: /* YUV422 */ |
1307 | 0 | for (k=1 ; k<8; k+=1) { |
1308 | 0 | int k_ptr = transpose422[k]; |
1309 | 0 | DEBUG(" MP_LP: Refine LP_Input[1/2][%d] = 0x%x/0x%x bitpos=%zu\n", |
1310 | 0 | k_ptr, LPInput[1][k_ptr], LPInput[2][k_ptr], |
1311 | 0 | _jxr_rbitstream_bitpos(str)); |
1312 | 0 | LPInput[1][k_ptr] = r_REFINE_LP(str, LPInput[1][k_ptr], model_bits); |
1313 | 0 | LPInput[2][k_ptr] = r_REFINE_LP(str, LPInput[2][k_ptr], model_bits); |
1314 | 0 | } |
1315 | 0 | break; |
1316 | 0 | default: /* All others */ |
1317 | 0 | for (k=1 ;k<16; k+=1) { |
1318 | 0 | int k_ptr = transpose444[k]; |
1319 | 0 | LPInput[ndx][k_ptr] = r_REFINE_LP(str, LPInput[ndx][k_ptr], model_bits); |
1320 | 0 | } |
1321 | 0 | break; |
1322 | 0 | } |
1323 | 0 | } |
1324 | 0 | } |
1325 | | |
1326 | | /* Stash the calculated LP values into the current |
1327 | | MACROBLK strip */ |
1328 | 0 | if (chroma_flag == 0) { |
1329 | | /* All luma planes are simply copied into the macroblk. */ |
1330 | 0 | int k; |
1331 | 0 | DEBUG(" lp val =="); |
1332 | 0 | for (k = 1 ; k<16; k+=1) { |
1333 | 0 | DEBUG(" 0x%x", LPInput[ndx][k]); |
1334 | 0 | MACROBLK_CUR_LP(image, ndx, tx, mx, k-1) = LPInput[ndx][k]; |
1335 | 0 | } |
1336 | 0 | DEBUG("\n"); |
1337 | 0 | } else { |
1338 | 0 | int k; |
1339 | 0 | DEBUG(" lp val (ch=%d) ==", ndx); |
1340 | 0 | switch (image->use_clr_fmt) { |
1341 | 0 | case 1:/* YUV420 */ |
1342 | | /* The chroma for YUV420 is interleaved. */ |
1343 | 0 | for (k = 1 ; k < 4 ; k+=1) { |
1344 | 0 | DEBUG(" 0x%x/0x%x", LPInput[1][k], LPInput[2][k]); |
1345 | 0 | MACROBLK_CUR_LP(image, 1, tx, mx, k-1) = LPInput[1][k]; |
1346 | 0 | MACROBLK_CUR_LP(image, 2, tx, mx, k-1) = LPInput[2][k]; |
1347 | 0 | } |
1348 | 0 | break; |
1349 | 0 | case 2:/* YUV422 */ |
1350 | | /* The chroma for YUV422 is interleaved. */ |
1351 | 0 | for (k = 1 ; k < 8 ; k+=1) { |
1352 | 0 | DEBUG(" 0x%x/0x%x", LPInput[1][k], LPInput[2][k]); |
1353 | 0 | MACROBLK_CUR_LP(image, 1, tx, mx, k-1) = LPInput[1][k]; |
1354 | 0 | MACROBLK_CUR_LP(image, 2, tx, mx, k-1) = LPInput[2][k]; |
1355 | 0 | } |
1356 | 0 | break; |
1357 | 0 | default: |
1358 | 0 | for (k = 1 ; k < 16 ; k += 1) { |
1359 | 0 | DEBUG(" 0x%x", LPInput[ndx][k]); |
1360 | 0 | MACROBLK_CUR_LP(image, ndx, tx, mx, k-1) = LPInput[ndx][k]; |
1361 | 0 | } |
1362 | 0 | break; |
1363 | 0 | } |
1364 | 0 | DEBUG("\n"); |
1365 | 0 | } |
1366 | 0 | } |
1367 | | |
1368 | 0 | DEBUG(" MB_LP: UpdateModelMB lap_mean={%d, %d}\n", lap_mean[0], lap_mean[1]); |
1369 | 0 | _jxr_UpdateModelMB(image, lap_mean, &image->model_lp, 1/*band=LP*/); |
1370 | 0 | if (_jxr_ResetContext(image, tx, mx)) { |
1371 | 0 | DEBUG(" AdaptLP at the end of mx=%d (my=%d, ndx=%u)\n", mx, my, ndx); |
1372 | 0 | _jxr_AdaptLP(image); |
1373 | 0 | } |
1374 | |
|
1375 | 0 | DEBUG(" MB_LP DONE tile=[%u %u] mb=[%u %u]\n", tx, ty, mx, my); |
1376 | 0 | } |
1377 | | |
1378 | | /* |
1379 | | * This decides the MBCBP for the macroblock. This value is then used |
1380 | | * by the MB_HP to know how to decide the HP values for the macroblock. |
1381 | | */ |
1382 | | int _jxr_r_MB_CBP(jxr_image_t image, struct rbitstream*str, int alpha_flag, |
1383 | | unsigned tx, unsigned ty, unsigned mx, unsigned my) |
1384 | 0 | { |
1385 | 0 | static const int flc_table[] = {0, 2, 1, 2, 2, 0}; |
1386 | 0 | static const int off_table[] = {0, 4, 2, 8, 12, 1}; |
1387 | 0 | static const int out_table[] = { |
1388 | 0 | 0, 15, 3, 12, |
1389 | 0 | 1, 2, 4, 8, |
1390 | 0 | 5, 6, 9, 10, |
1391 | 0 | 7, 11, 13, 14 }; |
1392 | |
|
1393 | 0 | int diff_cbp[MAX_CHANNELS]; |
1394 | 0 | int idx; |
1395 | 0 | int chan; |
1396 | 0 | int channels; |
1397 | |
|
1398 | 0 | for (idx = 0 ; idx < MAX_CHANNELS ; idx += 1) |
1399 | 0 | diff_cbp[idx] = 0; |
1400 | |
|
1401 | 0 | DEBUG(" MB_CBP tile=[%u %u] mb=[%u %u] bitpos=%zu\n", |
1402 | 0 | tx, ty, mx, my, _jxr_rbitstream_bitpos(str)); |
1403 | |
|
1404 | 0 | if (_jxr_InitContext(image, tx, ty, mx, my)) { |
1405 | 0 | DEBUG(" MB_CBP: InitContext\n"); |
1406 | | /* This happens only at the top left edge of the tile. */ |
1407 | 0 | _jxr_InitCBPVLC(image); |
1408 | 0 | } |
1409 | | |
1410 | | /* "Channels" is not quite the same as "planes". For the |
1411 | | purposes of CBP parsing, a color image has 1 channel. */ |
1412 | 0 | channels = 1; |
1413 | 0 | if (image->use_clr_fmt==4/*YUVK*/ || image->use_clr_fmt==6/*NCOMPONENT*/) |
1414 | 0 | channels = image->num_channels; |
1415 | | |
1416 | | /* This "for" loop decides not the code block pattern itself, |
1417 | | but the encoded difference values. These are then added to |
1418 | | the predicted values that are calculated later to make the |
1419 | | actual MBCBP values. */ |
1420 | 0 | for (chan = 0 ; chan < channels ; chan += 1) { |
1421 | 0 | struct adaptive_vlc_s*vlc = image->vlc_table + DecNumCBP; |
1422 | 0 | int num_cbp = get_num_cbp(str, vlc); |
1423 | 0 | int blk; |
1424 | 0 | static const int Num_CBP_Delta[5] = {0, -1, 0, 1, 1}; |
1425 | 0 | int cbp; |
1426 | |
|
1427 | 0 | DEBUG(" MB_CBP: Decode CBP for channel %d bitpos=%zu\n", chan, _jxr_rbitstream_bitpos(str)); |
1428 | |
|
1429 | 0 | assert(vlc->deltatable == 0 && num_cbp < 5); |
1430 | 0 | vlc->discriminant += Num_CBP_Delta[num_cbp]; |
1431 | |
|
1432 | 0 | DEBUG(" MB_CBP: Got num_cbp=%d, start REFINE_CBP at bitpos=%zu\n", |
1433 | 0 | num_cbp, _jxr_rbitstream_bitpos(str)); |
1434 | |
|
1435 | 0 | cbp = r_REFINE_CBP(str, num_cbp); |
1436 | |
|
1437 | 0 | DEBUG(" MB_CBP: Refined CBP=0x%x (num=%d)\n", cbp, num_cbp); |
1438 | | |
1439 | | /* The cbp is a "block present" bit hask for a group of |
1440 | | 4 blocks. This is used to inform the loop below that |
1441 | | then tries to fill discern the 4 bits for the range |
1442 | | enabled by this first level cbp. For example, if |
1443 | | cbp=0x5, then the 16 diff_cbp values are 0x0?0? where |
1444 | | the ? nibbles are yet to be resolved by the loop |
1445 | | below. */ |
1446 | |
|
1447 | 0 | for (blk = 0 ; blk < 4 ; blk += 1) { |
1448 | 0 | int code; |
1449 | 0 | int val; |
1450 | 0 | int blkcbp; |
1451 | 0 | int num_blkcbp; |
1452 | |
|
1453 | 0 | if ( (cbp & (1<<blk)) == 0 ) |
1454 | 0 | continue; |
1455 | | |
1456 | 0 | vlc = image->vlc_table + DecNumBlkCBP; |
1457 | 0 | DEBUG(" MB_CBP: block=%d Use DecNumBlkCBP table=%d, discriminant=%d, bitpos=%zu\n", |
1458 | 0 | blk, vlc->table, vlc->discriminant, _jxr_rbitstream_bitpos(str)); |
1459 | |
|
1460 | 0 | num_blkcbp = get_num_blkcbp(image, str, vlc); |
1461 | |
|
1462 | 0 | assert(vlc->deltatable == 0); |
1463 | |
|
1464 | 0 | if (image->use_clr_fmt==0 || image->use_clr_fmt==4 || image->use_clr_fmt==6) { |
1465 | 0 | static const int Num_BLKCBP_Delta5[5] = {0, -1, 0, 1, 1}; |
1466 | 0 | assert(num_blkcbp < 5); |
1467 | 0 | vlc->discriminant += Num_BLKCBP_Delta5[num_blkcbp]; |
1468 | 0 | } else { |
1469 | 0 | static const int Num_BLKCBP_Delta9[9] = {2, 2, 1, 1, -1, -2, -2, -2, -3}; |
1470 | 0 | assert(num_blkcbp < 9); |
1471 | 0 | vlc->discriminant += Num_BLKCBP_Delta9[num_blkcbp]; |
1472 | 0 | } |
1473 | |
|
1474 | 0 | DEBUG(" MB_CBP: NUM_BLKCBP=%d, discriminant becomes=%d, \n", |
1475 | 0 | num_blkcbp, vlc->discriminant); |
1476 | |
|
1477 | 0 | val = num_blkcbp + 1; |
1478 | |
|
1479 | 0 | blkcbp = 0; |
1480 | | |
1481 | | /* Should only be true if this is chroma data. */ |
1482 | 0 | if (val >= 6) { |
1483 | 0 | int chr_cbp = get_value_012(str); |
1484 | 0 | blkcbp = 0x10 * (chr_cbp+1); |
1485 | 0 | if (val >= 9) { |
1486 | 0 | int val_inc = get_value_012(str); |
1487 | 0 | val += val_inc; |
1488 | 0 | } |
1489 | 0 | DEBUG(" MB_CBP: iVal=%d, CHR_CBP=%x\n", val, chr_cbp); |
1490 | 0 | val -= 6; |
1491 | 0 | } |
1492 | 0 | assert(val < 6); |
1493 | |
|
1494 | 0 | code = off_table[val]; |
1495 | 0 | if (flc_table[val]) { |
1496 | 0 | code += _jxr_rbitstream_uintN(str, flc_table[val]); |
1497 | 0 | } |
1498 | |
|
1499 | 0 | assert(code < 16); |
1500 | 0 | blkcbp += out_table[code]; |
1501 | |
|
1502 | 0 | DEBUG(" MB_CBP: NUM_BLKCBP=%d, iCode=%d\n", num_blkcbp, code); |
1503 | 0 | DEBUG(" MB_CBP: blkcbp=0x%x for chunk blk=%d\n", blkcbp, blk); |
1504 | | |
1505 | | /* blkcbp is done. Now calculate the |
1506 | | diff_cbp. How this is done (and how many |
1507 | | there are) depend on the color format. */ |
1508 | |
|
1509 | 0 | switch (image->use_clr_fmt) { |
1510 | 0 | case 3: /*YUV444*/ |
1511 | 0 | diff_cbp[0] |= (blkcbp&0xf) << (blk * 4); |
1512 | 0 | if (blkcbp & 0x10) { |
1513 | 0 | int num_ch_blk = get_num_ch_blk(str); |
1514 | 0 | int cbp_chr = r_REFINE_CBP(str, num_ch_blk+1); |
1515 | 0 | DEBUG(" MB_CBP: Refined CBP_U=0x%x (num=%d)\n", cbp_chr, num_ch_blk); |
1516 | 0 | diff_cbp[1] |= cbp_chr << (blk*4); |
1517 | 0 | } |
1518 | 0 | if (blkcbp & 0x20) { |
1519 | 0 | int num_ch_blk = get_num_ch_blk(str); |
1520 | 0 | int cbp_chr = r_REFINE_CBP(str, num_ch_blk+1); |
1521 | 0 | DEBUG(" MB_CBP: Refined CBP_V=0x%x (num=%d)\n", cbp_chr, num_ch_blk); |
1522 | 0 | diff_cbp[2] |= cbp_chr << (blk*4); |
1523 | 0 | } |
1524 | 0 | break; |
1525 | | |
1526 | 0 | case 2: /*YUV422*/ |
1527 | 0 | diff_cbp[0] |= (blkcbp&0xf) << (blk*4); |
1528 | 0 | if (blkcbp & 0x10) { |
1529 | 0 | const int shift[4] = {0, 1, 4, 5}; |
1530 | 0 | int cbp_ch_blk = get_value_012(str); |
1531 | 0 | int cbp_chr = shift[cbp_ch_blk+1]; |
1532 | 0 | diff_cbp[1] |= cbp_chr << shift[blk]; |
1533 | 0 | DEBUG(" MB_CBP: Refined CBP_U=0x%x (cbp_ch_blk=%d, blk=%d)\n", |
1534 | 0 | diff_cbp[1], cbp_ch_blk, blk); |
1535 | 0 | } |
1536 | 0 | if (blkcbp & 0x20) { |
1537 | 0 | const int shift[4] = {0, 1, 4, 5}; |
1538 | 0 | int cbp_ch_blk = get_value_012(str); |
1539 | 0 | int cbp_chr = shift[cbp_ch_blk+1]; |
1540 | 0 | diff_cbp[2] |= cbp_chr << shift[blk]; |
1541 | 0 | DEBUG(" MB_CBP: Refined CBP_V=0x%x (cbp_ch_blk=%d, blk=%d)\n", |
1542 | 0 | diff_cbp[2], cbp_ch_blk, blk); |
1543 | 0 | } |
1544 | 0 | break; |
1545 | | |
1546 | 0 | case 1: /*YUV420*/ |
1547 | 0 | diff_cbp[0] |= (blkcbp & 0xf) << (blk*4); |
1548 | 0 | diff_cbp[1] |= ((blkcbp >> 4) & 1) << blk; |
1549 | 0 | diff_cbp[2] += ((blkcbp >> 5) & 1) << blk; |
1550 | 0 | break; |
1551 | | |
1552 | 0 | default: |
1553 | 0 | diff_cbp[chan] |= blkcbp << (blk*4); |
1554 | 0 | break; |
1555 | 0 | } |
1556 | 0 | } |
1557 | 0 | DEBUG(" MB_CBP: chan=%d, num_cbp=%d, cbp=0x%1x\n", chan, num_cbp, cbp); |
1558 | 0 | } |
1559 | | |
1560 | | #if defined(DETAILED_DEBUG) |
1561 | | for (chan = 0 ; chan < image->num_channels ; chan += 1) { |
1562 | | DEBUG(" MB_CBP: diff_cbp[%d]=0x%04x\n", chan, diff_cbp[chan]); |
1563 | | } |
1564 | | #endif |
1565 | | |
1566 | 0 | r_PredCBP(image, diff_cbp, tx, ty, mx, my); |
1567 | |
|
1568 | 0 | DEBUG(" MB_CBP done tile=[%u %u] mb=[%u %u]\n", tx, ty, mx, my); |
1569 | 0 | return 0; |
1570 | 0 | } |
1571 | | |
1572 | | static int r_REFINE_CBP(struct rbitstream*str, int num) |
1573 | 0 | { |
1574 | 0 | switch (num) { |
1575 | 0 | case 1: |
1576 | 0 | return 1 << _jxr_rbitstream_uint2(str); |
1577 | | |
1578 | 0 | case 2: |
1579 | | /* |
1580 | | * table value |
1581 | | * 00 3 |
1582 | | * 01 5 |
1583 | | * 100 6 |
1584 | | * 101 9 |
1585 | | * 110 10 |
1586 | | * 111 12 |
1587 | | */ |
1588 | 0 | if (_jxr_rbitstream_uint1(str) == 0) { |
1589 | 0 | if (_jxr_rbitstream_uint1(str) == 0) |
1590 | 0 | return 3; |
1591 | 0 | else |
1592 | 0 | return 5; |
1593 | 0 | } else { /* 1xx */ |
1594 | 0 | if (_jxr_rbitstream_uint1(str) == 0) { /* 10x */ |
1595 | 0 | if (_jxr_rbitstream_uint1(str) == 0) |
1596 | 0 | return 6; |
1597 | 0 | else |
1598 | 0 | return 9; |
1599 | 0 | } else { /* 11x */ |
1600 | 0 | if (_jxr_rbitstream_uint1(str) == 0) |
1601 | 0 | return 10; |
1602 | 0 | else |
1603 | 0 | return 12; |
1604 | 0 | } |
1605 | 0 | } |
1606 | | |
1607 | 0 | case 3: |
1608 | 0 | return 0x0f ^ (1 << _jxr_rbitstream_uint2(str)); |
1609 | | |
1610 | 0 | case 4: |
1611 | 0 | return 0x0f; |
1612 | | |
1613 | 0 | default: |
1614 | 0 | return 0x00; |
1615 | 0 | } |
1616 | 0 | } |
1617 | | |
1618 | | |
1619 | | int _jxr_r_MB_HP(jxr_image_t image, struct rbitstream*str, |
1620 | | int alpha_flag, |
1621 | | unsigned tx, unsigned ty, |
1622 | | unsigned mx, unsigned my) |
1623 | 0 | { |
1624 | 0 | int use_num_channels; |
1625 | 0 | int idx; |
1626 | 0 | int lap_mean[2]; |
1627 | 0 | int flex_flag; |
1628 | 0 | int mbhp_pred_mode; |
1629 | |
|
1630 | 0 | DEBUG(" MB_HP tile=[%u %u] mb=[%u %u] bitpos=%zu\n", |
1631 | 0 | tx, ty, mx, my, _jxr_rbitstream_bitpos(str)); |
1632 | |
|
1633 | 0 | if (_jxr_InitContext(image, tx, ty, mx, my)) { |
1634 | 0 | DEBUG(" MB_HP: InitContext\n"); |
1635 | | /* This happens only at the top left edge of the tile. */ |
1636 | 0 | _jxr_InitHPVLC(image); |
1637 | 0 | _jxr_InitializeAdaptiveScanHP(image); |
1638 | 0 | _jxr_InitializeModelMB(&image->model_hp, 2/*band=HP*/); |
1639 | 0 | } |
1640 | |
|
1641 | 0 | if (_jxr_ResetTotals(image, mx)) { |
1642 | 0 | _jxr_ResetTotalsAdaptiveScanHP(image); |
1643 | 0 | } |
1644 | | |
1645 | | /* FLEXBITS are embedded in the HP data if there are FLEXBITS |
1646 | | present in the bitstream AND we are in SPATIAL (not |
1647 | | FREQUENCY) mode. */ |
1648 | 0 | flex_flag = 1; |
1649 | 0 | if (image->bands_present == 1) /* NOFLEXBITS */ |
1650 | 0 | flex_flag = 0; |
1651 | 0 | if (FREQUENCY_MODE_CODESTREAM_FLAG(image) != 0) /* FREQUENCY_MODE */ |
1652 | 0 | flex_flag = 0; |
1653 | |
|
1654 | 0 | lap_mean[0] = 0; |
1655 | 0 | lap_mean[1] = 0; |
1656 | | |
1657 | | /* Calculate the MB HP prediction mode. This uses only local |
1658 | | information, namely the LP values. */ |
1659 | 0 | mbhp_pred_mode = r_calculate_mbhp_mode(image, tx, mx); |
1660 | 0 | assert(mbhp_pred_mode < 4); |
1661 | |
|
1662 | 0 | for (idx = 0 ; idx < image->num_channels; idx += 1) { |
1663 | 0 | int chroma_flag = idx>0? 1 : 0; |
1664 | 0 | int nblocks = 4; |
1665 | 0 | unsigned model_bits; |
1666 | 0 | int cbp; |
1667 | 0 | int block; |
1668 | |
|
1669 | 0 | if (chroma_flag && image->use_clr_fmt==1/*YUV420*/) |
1670 | 0 | nblocks = 1; |
1671 | 0 | else if (chroma_flag && image->use_clr_fmt==2/*YUV422*/) |
1672 | 0 | nblocks = 2; |
1673 | |
|
1674 | 0 | model_bits = image->model_hp.bits[chroma_flag]; |
1675 | 0 | cbp = MACROBLK_CUR_HPCBP(image, idx, tx, mx); |
1676 | |
|
1677 | 0 | DEBUG(" MB_HP channel=%d, cbp=0x%x, model_bits=%u MBHPMode=%d\n", |
1678 | 0 | idx, cbp, model_bits, mbhp_pred_mode); |
1679 | 0 | for (block=0 ; block<(nblocks*4) ; block += 1, cbp >>= 1) { |
1680 | 0 | int bpos = block; |
1681 | 0 | int num_nonzero; |
1682 | | /* Only remap the Y plane of YUV42X data. */ |
1683 | 0 | if (nblocks == 4) |
1684 | 0 | bpos = _jxr_hp_scan_map[block]; |
1685 | 0 | num_nonzero = r_DECODE_BLOCK_ADAPTIVE(image, str, tx, mx, |
1686 | 0 | cbp&1, chroma_flag, |
1687 | 0 | idx, bpos, mbhp_pred_mode, |
1688 | 0 | model_bits); |
1689 | 0 | if (num_nonzero < 0) { |
1690 | 0 | DEBUG("ERROR: r_DECODE_BLOCK_ADAPTIVE returned rc=%d\n", num_nonzero); |
1691 | 0 | return JXR_EC_ERROR; |
1692 | 0 | } |
1693 | 0 | if (flex_flag) |
1694 | 0 | r_BLOCK_FLEXBITS(image, str, tx, ty, mx, my, |
1695 | 0 | idx, bpos, model_bits); |
1696 | 0 | lap_mean[chroma_flag] += num_nonzero; |
1697 | 0 | } |
1698 | |
|
1699 | 0 | } |
1700 | | |
1701 | 0 | use_num_channels = image->num_channels; |
1702 | 0 | if (image->use_clr_fmt == 1/*YUV420*/ || image->use_clr_fmt == 2/*YUV422*/) |
1703 | 0 | use_num_channels = 1; |
1704 | | |
1705 | | /* Propagate HP predictions only in SPATIAL MODE. If this is |
1706 | | FREQUENCY mode, and there is a FLEXBITS pass later, then do |
1707 | | *not* do the predictions, leaving them to the FLEXBITS tile. */ |
1708 | 0 | if (FREQUENCY_MODE_CODESTREAM_FLAG(image) == 0 || image->bands_present == 1) { |
1709 | 0 | DEBUG(" MB_HP: propagate hp predictions within MB_HP function\n"); |
1710 | 0 | for (idx = 0 ; idx < use_num_channels ; idx += 1) |
1711 | 0 | _jxr_propagate_hp_predictions(image, idx, tx, mx, mbhp_pred_mode); |
1712 | 0 | } |
1713 | |
|
1714 | 0 | DEBUG(" MP_HP: lap_mean={%u, %u}, model_hp.bits={%u %u}, model_hp.state={%d %d}\n", |
1715 | 0 | lap_mean[0], lap_mean[1], |
1716 | 0 | image->model_hp.bits[0], image->model_hp.bits[1], |
1717 | 0 | image->model_hp.state[0], image->model_hp.state[1]); |
1718 | |
|
1719 | 0 | MACROBLK_CUR(image,0,tx,mx).mbhp_pred_mode = mbhp_pred_mode; |
1720 | 0 | MACROBLK_CUR(image,0,tx,mx).hp_model_bits[0] = image->model_hp.bits[0]; |
1721 | 0 | MACROBLK_CUR(image,0,tx,mx).hp_model_bits[1] = image->model_hp.bits[1]; |
1722 | |
|
1723 | 0 | _jxr_UpdateModelMB(image, lap_mean, &image->model_hp, 2/*band=HP*/); |
1724 | 0 | if (_jxr_ResetContext(image, tx, mx)) { |
1725 | 0 | DEBUG(" MB_HP: Run AdaptHP\n"); |
1726 | 0 | _jxr_AdaptHP(image); |
1727 | 0 | } |
1728 | |
|
1729 | 0 | DEBUG(" MP_HP: Updated: lap_mean={%u, %u}, model_hp.bits={%u %u}, model_hp.state={%d %d}\n", |
1730 | 0 | lap_mean[0], lap_mean[1], |
1731 | 0 | image->model_hp.bits[0], image->model_hp.bits[1], |
1732 | 0 | image->model_hp.state[0], image->model_hp.state[1]); |
1733 | |
|
1734 | 0 | DEBUG(" MB_HP DONE tile=[%u %u] mb=[%u %u]\n", tx, ty, mx, my); |
1735 | 0 | return 0; |
1736 | 0 | } |
1737 | | |
1738 | | int _jxr_r_MB_FLEXBITS(jxr_image_t image, struct rbitstream*str, |
1739 | | int alpha_flag, |
1740 | | unsigned tx, unsigned ty, |
1741 | | unsigned mx, unsigned my) |
1742 | 0 | { |
1743 | 0 | int idx; |
1744 | 0 | for (idx = 0 ; idx < image->num_channels ; idx += 1) { |
1745 | 0 | int chroma_flag = idx>0? 1 : 0; |
1746 | 0 | int nblocks = 4; |
1747 | 0 | unsigned model_bits; |
1748 | 0 | int block; |
1749 | 0 | if (chroma_flag && image->use_clr_fmt==1/*YUV420*/) |
1750 | 0 | nblocks = 1; |
1751 | 0 | else if (chroma_flag && image->use_clr_fmt==2/*YUV422*/) |
1752 | 0 | nblocks = 2; |
1753 | |
|
1754 | 0 | model_bits = MACROBLK_CUR(image,0,tx,mx).hp_model_bits[chroma_flag]; |
1755 | |
|
1756 | 0 | for (block=0 ; block<(nblocks*4) ; block += 1) { |
1757 | 0 | int bpos = block; |
1758 | | /* Only remap the Y plane of YUV42X data. */ |
1759 | 0 | if (nblocks == 4) |
1760 | 0 | bpos = _jxr_hp_scan_map[block]; |
1761 | |
|
1762 | 0 | r_BLOCK_FLEXBITS(image, str, tx, ty, mx, my, |
1763 | 0 | idx, bpos, model_bits); |
1764 | 0 | } |
1765 | 0 | } |
1766 | |
|
1767 | 0 | return 0; |
1768 | 0 | } |
1769 | | |
1770 | | /* |
1771 | | * Decode a single DC component value from the input stream. |
1772 | | */ |
1773 | | static int32_t r_DEC_DC(jxr_image_t image, struct rbitstream*str, |
1774 | | unsigned tx, unsigned ty, |
1775 | | unsigned mx, unsigned my, |
1776 | | int model_bits, int chroma_flag, int is_dc_ch) |
1777 | 0 | { |
1778 | 0 | int32_t dc_val = 0; |
1779 | |
|
1780 | 0 | if (is_dc_ch) { |
1781 | 0 | dc_val = r_DECODE_ABS_LEVEL(image, str, 0/*DC*/, chroma_flag) -1; |
1782 | 0 | DEBUG(" DEC_DC: DECODE_ABS_LEVEL = %u (0x%08x)\n", dc_val, dc_val); |
1783 | 0 | } |
1784 | | |
1785 | | /* If there are model_bits, then read them literally from the |
1786 | | bitstream and use them as the LSB bits for the DC value. */ |
1787 | 0 | if (model_bits > 0) { |
1788 | 0 | int idx; |
1789 | 0 | DEBUG(" DEC_DC: Collect %u model_bits\n", model_bits); |
1790 | 0 | for (idx = 0 ; idx < model_bits ; idx += 1) { |
1791 | 0 | dc_val <<= 1; |
1792 | 0 | dc_val |= _jxr_rbitstream_uint1(str); |
1793 | 0 | } |
1794 | 0 | } |
1795 | | |
1796 | | /* If the dc_val is non-zero, it may have a sign so decode the |
1797 | | sign bit and apply it. */ |
1798 | 0 | if (dc_val != 0) { |
1799 | 0 | int sign_flag = _jxr_rbitstream_uint1(str); |
1800 | 0 | DEBUG(" DEC_DC: sign_flag=%s\n", sign_flag? "true":"false"); |
1801 | 0 | if (sign_flag) |
1802 | 0 | dc_val = - dc_val; |
1803 | 0 | } |
1804 | |
|
1805 | 0 | DEBUG(" DEC_DC: DC value is %d (0x%08x)\n", dc_val, dc_val); |
1806 | 0 | return dc_val; |
1807 | 0 | } |
1808 | | |
1809 | | /* |
1810 | | * This function decodes one sample from one of the bands. The code is |
1811 | | * the same for any of the bands. The band (and chroma_flag) is only |
1812 | | * used to select the vlc_table. |
1813 | | * |
1814 | | * Note that the chroma_flag is only interpreted as the "chroma_flag" |
1815 | | * when the band is DC. Otherwise, the chroma_flag argument is taken |
1816 | | * as the "context" argument described in the specification. |
1817 | | */ |
1818 | | static uint32_t r_DECODE_ABS_LEVEL(jxr_image_t image, struct rbitstream*str, |
1819 | | int band, int chroma_flag) |
1820 | 0 | { |
1821 | 0 | int vlc_select = _jxr_vlc_select(band, chroma_flag); |
1822 | |
|
1823 | 0 | const int remap[] = {2, 3, 4, 6, 10, 14}; |
1824 | 0 | const int fixed_len[] = {0, 0, 1, 2, 2, 2}; |
1825 | 0 | uint32_t level; |
1826 | |
|
1827 | 0 | int abslevel_index = dec_abslevel_index(image, str, vlc_select); |
1828 | 0 | DEBUG(" Use vlc_select = %s (table=%d) to decode level index, bitpos=%zu\n", |
1829 | 0 | _jxr_vlc_index_name(vlc_select), image->vlc_table[vlc_select].table, |
1830 | 0 | _jxr_rbitstream_bitpos(str)); |
1831 | 0 | DEBUG(" ABSLEVEL_INDEX = %d\n", abslevel_index); |
1832 | |
|
1833 | 0 | image->vlc_table[vlc_select].discriminant += _jxr_abslevel_index_delta[abslevel_index]; |
1834 | |
|
1835 | 0 | if (abslevel_index < 6) { |
1836 | 0 | int fixed = fixed_len[abslevel_index]; |
1837 | 0 | uint32_t level_ref = 0; |
1838 | |
|
1839 | 0 | level = remap[abslevel_index]; |
1840 | 0 | if (fixed > 0) { |
1841 | 0 | int idx; |
1842 | 0 | assert(fixed <= 32); |
1843 | 0 | for (idx = 0 ; idx < fixed ; idx += 1) { |
1844 | 0 | level_ref <<= 1; |
1845 | 0 | level_ref |= _jxr_rbitstream_uint1(str); |
1846 | 0 | } |
1847 | 0 | level += level_ref; |
1848 | 0 | } |
1849 | 0 | DEBUG(" ABS_LEVEL = 0x%x (fixed = %d, level_ref = %d)\n", |
1850 | 0 | level, fixed, level_ref); |
1851 | 0 | } else { |
1852 | 0 | int fixed = 4 + _jxr_rbitstream_uint4(str); |
1853 | 0 | uint32_t level_ref; |
1854 | 0 | int idx; |
1855 | |
|
1856 | 0 | if (fixed == 19) { |
1857 | 0 | fixed += _jxr_rbitstream_uint2(str); |
1858 | 0 | if (fixed == 22) { |
1859 | 0 | fixed += _jxr_rbitstream_uint3(str); |
1860 | 0 | } |
1861 | 0 | } |
1862 | |
|
1863 | 0 | assert(fixed <= 32); |
1864 | |
|
1865 | 0 | level_ref = 0; |
1866 | 0 | for (idx = 0 ; idx < fixed ; idx += 1) { |
1867 | 0 | level_ref <<= 1; |
1868 | 0 | level_ref |= _jxr_rbitstream_uint1(str); |
1869 | 0 | } |
1870 | 0 | level = 2 + (1 << fixed) + level_ref; |
1871 | 0 | DEBUG(" ABS_LEVEL = 0x%x (fixed = %d, level_ref = %d)\n", |
1872 | 0 | level, fixed, level_ref); |
1873 | 0 | } |
1874 | |
|
1875 | 0 | return level; |
1876 | 0 | } |
1877 | | |
1878 | | /* |
1879 | | * The DECODE_BLOCK decodes the block as run/coefficient pairs. The |
1880 | | * run is the distance to the next coefficient, and is followed by the |
1881 | | * coefficient itself. The skipped values are implicitly zeros. A |
1882 | | * later process takes these pairs including adaptation of their position. |
1883 | | */ |
1884 | | int r_DECODE_BLOCK(jxr_image_t image, struct rbitstream*str, |
1885 | | int chroma_flag, int coeff[32], int band, int location) |
1886 | 0 | { |
1887 | 0 | int num_nz = 1; |
1888 | | |
1889 | | /* The index is a bit field that encodes three values: |
1890 | | * index[0] : 1 means the run to the next coeff is == 0 |
1891 | | * index[1] : 1 means the next coefficient is >1 |
1892 | | * index[3:2]: 0 This is the last coefficient |
1893 | | * 1 the next non-zero coefficient immediately follows |
1894 | | * 2 there are zero coefficients before the next. |
1895 | | */ |
1896 | 0 | int index = r_DECODE_FIRST_INDEX(image, str, chroma_flag, band); |
1897 | 0 | int sr = index & 1; |
1898 | 0 | int srn = index >> 2; |
1899 | 0 | int context = sr & srn; |
1900 | 0 | int sign_flag; |
1901 | |
|
1902 | 0 | DEBUG(" DECODE_BLOCK chroma_flag=%d, band=%d, location=%d bitpos=%zu\n", |
1903 | 0 | chroma_flag, band, location, _jxr_rbitstream_bitpos(str)); |
1904 | 0 | DEBUG(" first index=0x%x\n", index); |
1905 | | |
1906 | | |
1907 | | /* Decode the first coefficient. Note that the chroma_flag |
1908 | | argument to DECODE_ABS_LEVEL really is supposed to be the |
1909 | | context. It is "chroma" for DC values (band==0) and context |
1910 | | for LP and HP values. This DECODE_BLOCK is only called for |
1911 | | LP and HP blocks. */ |
1912 | 0 | sign_flag = _jxr_rbitstream_uint1(str); |
1913 | 0 | if (index&2) |
1914 | 0 | coeff[1] = r_DECODE_ABS_LEVEL(image, str, band, context); |
1915 | 0 | else |
1916 | 0 | coeff[1] = 1; |
1917 | |
|
1918 | 0 | if (sign_flag) |
1919 | 0 | coeff[1] = -coeff[1]; |
1920 | | |
1921 | | /* Decode the run to the first coefficient. */ |
1922 | 0 | if (index&1) { |
1923 | 0 | coeff[0] = 0; |
1924 | 0 | } else { |
1925 | 0 | assert( location < 15 ); |
1926 | 0 | coeff[0] = r_DECODE_RUN(image, str, 15-location); |
1927 | 0 | } |
1928 | |
|
1929 | 0 | DEBUG(" coeff[0] = %d (run)\n", coeff[0]); |
1930 | 0 | DEBUG(" coeff[1] = 0x%x (coeff)\n", coeff[1]); |
1931 | |
|
1932 | 0 | location += coeff[0] + 1; |
1933 | |
|
1934 | 0 | while (srn != 0) { /* While more coefficients are expected... */ |
1935 | 0 | sr = srn & 1; |
1936 | | |
1937 | | /* Decode run to the next coefficient. */ |
1938 | 0 | if (srn & 1) { |
1939 | 0 | coeff[num_nz*2] = 0; |
1940 | 0 | } else { |
1941 | 0 | coeff[num_nz*2] = r_DECODE_RUN(image, str, 15-location); |
1942 | 0 | } |
1943 | |
|
1944 | 0 | DEBUG(" coeff[%d*2+0] = %d (run)\n", num_nz, coeff[num_nz*2]); |
1945 | |
|
1946 | 0 | location += coeff[num_nz*2] + 1; |
1947 | | |
1948 | | /* The index is a bit field that encodes two values: |
1949 | | * index[0] : 1 means the run to the next coeff is == 0 |
1950 | | * index[2:1]: 0 This is the last coefficient |
1951 | | * 1 the next non-zero coefficient immediately follows |
1952 | | * 2 there are zero coefficients before the next. |
1953 | | * The location can clue the DECODE_INDEX that certain |
1954 | | * constraints on the possible index values may exist, |
1955 | | * and certain restricted tables are used. |
1956 | | */ |
1957 | 0 | index = r_DECODE_INDEX(image, str, location, chroma_flag, band, context); |
1958 | 0 | DEBUG(" next index=0x%x\n", index); |
1959 | |
|
1960 | 0 | srn = index >> 1; |
1961 | 0 | context &= srn; |
1962 | | |
1963 | | /* Decode the next coefficient. */ |
1964 | 0 | sign_flag = _jxr_rbitstream_uint1(str); |
1965 | 0 | if (index & 1) |
1966 | 0 | coeff[num_nz*2+1] = r_DECODE_ABS_LEVEL(image, str, |
1967 | 0 | band, context); |
1968 | 0 | else |
1969 | 0 | coeff[num_nz*2+1] = 1; |
1970 | |
|
1971 | 0 | if (sign_flag) |
1972 | 0 | coeff[num_nz*2+1] = -coeff[num_nz*2+1]; |
1973 | |
|
1974 | 0 | DEBUG(" coeff[%d*2+1] = 0x%x (coeff)\n", num_nz, coeff[num_nz*2+1]); |
1975 | 0 | num_nz += 1; |
1976 | 0 | } |
1977 | |
|
1978 | 0 | DEBUG(" DECODE_BLOCK done, num_nz=%d\n", num_nz); |
1979 | 0 | return num_nz; |
1980 | 0 | } |
1981 | | |
1982 | | static int r_DECODE_FIRST_INDEX(jxr_image_t image, struct rbitstream*str, |
1983 | | int chroma_flag, int band) |
1984 | 0 | { |
1985 | | /* VALUE TABLE0 |
1986 | | * 0 0000 1.. |
1987 | | * 1 0000 01. |
1988 | | * 2 0000 000 |
1989 | | * 3 0000 001 |
1990 | | * 4 0010 0.. |
1991 | | * 5 010. ... |
1992 | | * 6 0010 1.. |
1993 | | * 7 1... ... |
1994 | | * 8 0011 0.. |
1995 | | * 9 0001 ... |
1996 | | * 10 0011 1.. |
1997 | | * 11 011. ... |
1998 | | * (Table 59: Note that the first bit is handled as a special |
1999 | | * case, so the array only needs to account for the last 6 bits.) |
2000 | | */ |
2001 | 0 | static const unsigned char c0b[64] = { |
2002 | 0 | 6, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, |
2003 | 0 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
2004 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
2005 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
2006 | 0 | }; |
2007 | 0 | static const signed char c0v[64] = { |
2008 | 0 | 2, 3, 1, 1, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9, 9, 9, |
2009 | 0 | 4, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, 10,10,10,10, |
2010 | 0 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
2011 | 0 | 11,11,11,11, 11,11,11,11, 11,11,11,11, 11,11,11,11 |
2012 | 0 | }; |
2013 | | /* VALUE TABLE1 |
2014 | | * 0 0010 .. |
2015 | | * 1 0001 0. |
2016 | | * 2 0000 00 |
2017 | | * 3 0000 01 |
2018 | | * 4 0011 .. |
2019 | | * 5 010. .. |
2020 | | * 6 0001 1. |
2021 | | * 7 11.. .. |
2022 | | * 8 011. .. |
2023 | | * 9 100. .. |
2024 | | * 10 0000 1. |
2025 | | * 11 101. .. |
2026 | | */ |
2027 | 0 | static const unsigned char c1b[64] = { |
2028 | 0 | 6, 6, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, |
2029 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2030 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2031 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
2032 | 0 | }; |
2033 | 0 | static const signed char c1v[64] = { |
2034 | 0 | 2, 3,10,10, 1, 1, 6, 6, 0, 0, 0, 0, 4, 4, 4, 4, |
2035 | 0 | 5, 5, 5, 5, 5, 5, 5, 5, 8, 8, 8, 8, 8, 8, 8, 8, |
2036 | 0 | 9, 9, 9, 9, 9, 9, 9, 9, 11,11,11,11, 11,11,11,11, |
2037 | 0 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 |
2038 | 0 | }; |
2039 | | |
2040 | | /* VALUE TABLE2 |
2041 | | * 0 11.. ... |
2042 | | * 1 001. ... |
2043 | | * 2 0000 000 |
2044 | | * 3 0000 001 |
2045 | | * 4 0000 1.. |
2046 | | * 5 010. ... |
2047 | | * 6 0000 010 |
2048 | | * 7 011. ... |
2049 | | * 8 100. ... |
2050 | | * 9 101. ... |
2051 | | * 10 0000 011 |
2052 | | * 11 0001 ... |
2053 | | */ |
2054 | 0 | static const unsigned char c2b[128] = { |
2055 | 0 | 7, 7, 7, 7, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, |
2056 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2057 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2058 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2059 | |
|
2060 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2061 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2062 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
2063 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
2064 | 0 | }; |
2065 | 0 | static const signed char c2v[128] = { |
2066 | 0 | 2, 3, 6,10, 4, 4, 4, 4, 11,11,11,11, 11,11,11,11, |
2067 | 0 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
2068 | 0 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
2069 | 0 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
2070 | |
|
2071 | 0 | 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
2072 | 0 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
2073 | 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
2074 | 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
2075 | 0 | }; |
2076 | | |
2077 | | /* VALUE TABLE3 |
2078 | | * 0 001. ... |
2079 | | * 1 11.. ... |
2080 | | * 2 0000 000 |
2081 | | * 3 0000 1.. |
2082 | | * 4 0001 0.. |
2083 | | * 5 010. ... |
2084 | | * 6 0000 001 |
2085 | | * 7 011. ... |
2086 | | * 8 0001 1.. |
2087 | | * 9 100. ... |
2088 | | * 10 0000 01. |
2089 | | * 11 101. ... |
2090 | | */ |
2091 | 0 | static const unsigned char c3b[128] = { |
2092 | 0 | 7, 7, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
2093 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2094 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2095 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2096 | |
|
2097 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2098 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2099 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
2100 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
2101 | 0 | }; |
2102 | 0 | static const signed char c3v[128] = { |
2103 | 0 | 2, 6,10,10, 3, 3, 3, 3, 4, 4, 4, 4, 8, 8, 8, 8, |
2104 | 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
2105 | 0 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
2106 | 0 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
2107 | |
|
2108 | 0 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
2109 | 0 | 11,11,11,11, 11,11,11,11, 11,11,11,11, 11,11,11,11, |
2110 | 0 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
2111 | 0 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 |
2112 | 0 | }; |
2113 | | |
2114 | | /* VALUE TABLE4 |
2115 | | * 0 010. .... |
2116 | | * 1 1... .... |
2117 | | * 2 0000 001. |
2118 | | * 3 0001 .... |
2119 | | * 4 0000 010. |
2120 | | * 5 011. .... |
2121 | | * 6 0000 0000 |
2122 | | * 7 0010 .... |
2123 | | * 8 0000 011. |
2124 | | * 9 0011 .... |
2125 | | * 10 0000 0001 |
2126 | | * 11 0000 1... |
2127 | | */ |
2128 | 0 | static const unsigned char c4b[128] = { |
2129 | 0 | 7, 7, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, |
2130 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2131 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2132 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2133 | |
|
2134 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
2135 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
2136 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
2137 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
2138 | 0 | }; |
2139 | 0 | static const signed char c4v[128] = { |
2140 | 0 | 6,10, 2, 2, 4, 4, 8, 8, 11,11,11,11, 11,11,11,11, |
2141 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
2142 | 0 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
2143 | 0 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
2144 | |
|
2145 | 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
2146 | 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
2147 | 0 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
2148 | 0 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 |
2149 | 0 | }; |
2150 | |
|
2151 | 0 | typedef int deltatable_t[12]; |
2152 | 0 | const deltatable_t FirstIndexDelta[4] = { |
2153 | 0 | { 1, 1, 1, 1, 1, 0, 0,-1, 2, 1, 0, 0 }, |
2154 | 0 | { 2, 2,-1,-1,-1, 0,-2,-1, 0, 0,-2,-1 }, |
2155 | 0 | {-1, 1, 0, 2, 0, 0, 0, 0,-2, 0, 1, 1 }, |
2156 | 0 | { 0, 1, 0, 1,-2, 0,-1,-1,-2,-1,-2,-2 } |
2157 | 0 | }; |
2158 | |
|
2159 | 0 | int delta_table; |
2160 | 0 | int delta2table; |
2161 | 0 | int vlc_table; |
2162 | 0 | int first_index; |
2163 | |
|
2164 | 0 | abs_level_vlc_index_t vlc_select = (abs_level_vlc_index_t)0; |
2165 | |
|
2166 | 0 | switch (band) { |
2167 | 0 | case 1: /* LP */ |
2168 | 0 | if (chroma_flag) |
2169 | 0 | vlc_select = DecFirstIndLPChr; |
2170 | 0 | else |
2171 | 0 | vlc_select = DecFirstIndLPLum; |
2172 | 0 | break; |
2173 | 0 | case 2: /* HP */ |
2174 | 0 | if (chroma_flag) |
2175 | 0 | vlc_select = DecFirstIndHPChr; |
2176 | 0 | else |
2177 | 0 | vlc_select = DecFirstIndHPLum; |
2178 | 0 | break; |
2179 | 0 | default: |
2180 | 0 | assert(0); |
2181 | 0 | break; |
2182 | 0 | } |
2183 | | |
2184 | 0 | vlc_table = image->vlc_table[vlc_select].table; |
2185 | 0 | first_index = 0; |
2186 | |
|
2187 | 0 | switch (vlc_table) { |
2188 | 0 | case 0: |
2189 | 0 | if (_jxr_rbitstream_uint1(str)) { |
2190 | 0 | first_index = 7; |
2191 | 0 | } else { |
2192 | 0 | first_index = _jxr_rbitstream_intE(str, 6, c0b, c0v); |
2193 | 0 | } |
2194 | 0 | break; |
2195 | | |
2196 | 0 | case 1: |
2197 | 0 | first_index = _jxr_rbitstream_intE(str, 6, c1b, c1v); |
2198 | 0 | break; |
2199 | | |
2200 | 0 | case 2: |
2201 | 0 | first_index = _jxr_rbitstream_intE(str, 7, c2b, c2v); |
2202 | 0 | break; |
2203 | | |
2204 | 0 | case 3: |
2205 | 0 | first_index = _jxr_rbitstream_intE(str, 7, c3b, c3v); |
2206 | 0 | break; |
2207 | | |
2208 | 0 | case 4: |
2209 | 0 | if (_jxr_rbitstream_uint1(str)) { |
2210 | 0 | first_index = 1; |
2211 | 0 | } else { |
2212 | 0 | first_index = _jxr_rbitstream_intE(str, 7, c4b, c4v); |
2213 | 0 | } |
2214 | 0 | break; |
2215 | | |
2216 | 0 | default: |
2217 | 0 | assert(0); |
2218 | 0 | break; |
2219 | 0 | } |
2220 | | |
2221 | 0 | delta_table = image->vlc_table[vlc_select].deltatable; |
2222 | 0 | delta2table = image->vlc_table[vlc_select].delta2table; |
2223 | |
|
2224 | 0 | assert(delta_table < 4); |
2225 | 0 | assert(delta2table < 4); |
2226 | 0 | assert(first_index < 12); |
2227 | 0 | image->vlc_table[vlc_select].discriminant += FirstIndexDelta[delta_table][first_index]; |
2228 | 0 | image->vlc_table[vlc_select].discriminant2 += FirstIndexDelta[delta2table][first_index]; |
2229 | 0 | DEBUG(" DECODE_FIRST_INDEX: vlc_select = %s, vlc_table = %d, deltatable/2 = %d/%d, discriminant/2 = %d/%d, first_index=%d\n", |
2230 | 0 | _jxr_vlc_index_name(vlc_select), vlc_table, |
2231 | 0 | delta_table, delta2table, |
2232 | 0 | image->vlc_table[vlc_select].discriminant, |
2233 | 0 | image->vlc_table[vlc_select].discriminant2, first_index); |
2234 | |
|
2235 | 0 | return first_index; |
2236 | 0 | } |
2237 | | |
2238 | | static int r_DECODE_INDEX(jxr_image_t image, struct rbitstream*str, |
2239 | | int location, int chroma_flag, int band, int context) |
2240 | 0 | { |
2241 | 0 | int vlc_select = 0; |
2242 | 0 | int vlc_delta; |
2243 | 0 | int vlc_delta2; |
2244 | 0 | int vlc_table; |
2245 | 0 | int index; |
2246 | |
|
2247 | 0 | typedef int deltatable_t[6]; |
2248 | 0 | const deltatable_t Index1Delta[3] = { |
2249 | 0 | {-1, 1, 1, 1, 0, 1 }, |
2250 | 0 | {-2, 0, 0, 2, 0, 0 }, |
2251 | 0 | {-1,-1, 0, 1,-2, 0 } |
2252 | 0 | }; |
2253 | | |
2254 | |
|
2255 | 0 | switch (band) { |
2256 | 0 | case 1: /* LP */ |
2257 | 0 | if (chroma_flag) |
2258 | 0 | vlc_select = context? DecIndLPChr1 : DecIndLPChr0; |
2259 | 0 | else |
2260 | 0 | vlc_select = context? DecIndLPLum1 : DecIndLPLum0; |
2261 | 0 | break; |
2262 | 0 | case 2: /* HP */ |
2263 | 0 | if (chroma_flag) |
2264 | 0 | vlc_select = context? DecIndHPChr1 : DecIndHPChr0; |
2265 | 0 | else |
2266 | 0 | vlc_select = context? DecIndHPLum1 : DecIndHPLum0; |
2267 | 0 | break; |
2268 | 0 | default: |
2269 | 0 | assert(0); |
2270 | 0 | break; |
2271 | 0 | } |
2272 | | |
2273 | 0 | index = 0; |
2274 | | |
2275 | | /* If location > 15, then there can't possibly be coefficients |
2276 | | after the next, so the encoding will only encode the low |
2277 | | bit, that hints the run is zero or not. */ |
2278 | 0 | if (location > 15) { |
2279 | 0 | index = _jxr_rbitstream_uint1(str); |
2280 | 0 | DEBUG(" DECODE_INDEX: location=%d, index=%d\n", location, index); |
2281 | 0 | return index; |
2282 | 0 | } |
2283 | | |
2284 | | /* If location == 15, then this is probably the last |
2285 | | coefficient, but there may be more. We do know that there |
2286 | | are no zero coefficients before the next (if there is one). |
2287 | | Use a fixed table to decode the index with reduced alphabet. */ |
2288 | 0 | if (location == 15) { |
2289 | | /* Table 61 |
2290 | | * INDEX2 table |
2291 | | * 0 0 |
2292 | | * 2 10 |
2293 | | * 1 110 |
2294 | | * 3 111 |
2295 | | */ |
2296 | 0 | if (_jxr_rbitstream_uint1(str) == 0) |
2297 | 0 | index = 0; /* 0 */ |
2298 | 0 | else if (_jxr_rbitstream_uint1(str) == 0) |
2299 | 0 | index = 2; /* 10 */ |
2300 | 0 | else if (_jxr_rbitstream_uint1(str) == 0) |
2301 | 0 | index = 1; /* 110 */ |
2302 | 0 | else |
2303 | 0 | index = 3; /* 111 */ |
2304 | 0 | DEBUG(" DECODE_INDEX: location=%d, index=%d\n", location, index); |
2305 | 0 | return index; |
2306 | 0 | } |
2307 | | |
2308 | | /* For more general cases, use adaptive table selections to |
2309 | | decode the full set of index possibilities. */ |
2310 | 0 | vlc_table = image->vlc_table[vlc_select].table; |
2311 | 0 | DEBUG(" DECODE_INDEX: vlc_select = %s, vlc_table = %d chroma_flag=%d\n", |
2312 | 0 | _jxr_vlc_index_name(vlc_select), vlc_table, chroma_flag); |
2313 | | |
2314 | | /* Table 60 is implemented in this switch. */ |
2315 | 0 | switch (vlc_table) { |
2316 | 0 | case 0: |
2317 | | /* INDEX1 table0 |
2318 | | * 0 1 |
2319 | | * 1 00000 |
2320 | | * 2 001 |
2321 | | * 3 00001 |
2322 | | * 4 01 |
2323 | | * 5 0001 |
2324 | | */ |
2325 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
2326 | 0 | index = 0; /* 1 */ |
2327 | 0 | else if (_jxr_rbitstream_uint1(str) == 1) |
2328 | 0 | index = 4; /* 01 */ |
2329 | 0 | else if (_jxr_rbitstream_uint1(str) == 1) |
2330 | 0 | index = 2; /* 001 */ |
2331 | 0 | else if (_jxr_rbitstream_uint1(str) == 1) |
2332 | 0 | index = 5; /* 0001 */ |
2333 | 0 | else if (_jxr_rbitstream_uint1(str) == 1) |
2334 | 0 | index = 3; /* 00001 */ |
2335 | 0 | else |
2336 | 0 | index = 1; /* 00000 */ |
2337 | 0 | break; |
2338 | | |
2339 | 0 | case 1: |
2340 | | /* INDEX1 table1 |
2341 | | * 0 01 |
2342 | | * 1 0000 |
2343 | | * 2 10 |
2344 | | * 3 0001 |
2345 | | * 4 11 |
2346 | | * 5 001 |
2347 | | */ |
2348 | 0 | switch (_jxr_rbitstream_uint2(str)) { |
2349 | 0 | case 1: /* 01 */ |
2350 | 0 | index = 0; |
2351 | 0 | break; |
2352 | 0 | case 2: /* 10 */ |
2353 | 0 | index = 2; |
2354 | 0 | break; |
2355 | 0 | case 3: /* 11 */ |
2356 | 0 | index = 4; |
2357 | 0 | break; |
2358 | 0 | case 0: /* 00... */ |
2359 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
2360 | 0 | index = 5; /* 001 */ |
2361 | 0 | else if (_jxr_rbitstream_uint1(str) == 1) |
2362 | 0 | index = 3; /* 0001 */ |
2363 | 0 | else |
2364 | 0 | index = 1; /* 0000 */ |
2365 | 0 | break; |
2366 | 0 | } |
2367 | 0 | break; |
2368 | | |
2369 | 0 | case 2: |
2370 | | /* INDEX1 table2 |
2371 | | * 0 0000 |
2372 | | * 1 0001 |
2373 | | * 2 01 |
2374 | | * 3 10 |
2375 | | * 4 11 |
2376 | | * 5 001 |
2377 | | */ |
2378 | 0 | switch (_jxr_rbitstream_uint2(str)) { |
2379 | 0 | case 1: /* 01 */ |
2380 | 0 | index = 2; |
2381 | 0 | break; |
2382 | 0 | case 2: /* 10 */ |
2383 | 0 | index = 3; |
2384 | 0 | break; |
2385 | 0 | case 3: /* 11 */ |
2386 | 0 | index = 4; |
2387 | 0 | break; |
2388 | 0 | case 0: /* 00... */ |
2389 | 0 | if (_jxr_rbitstream_uint1(str)) |
2390 | 0 | index = 5; /* 001 */ |
2391 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2392 | 0 | index = 1; /* 0001 */ |
2393 | 0 | else |
2394 | 0 | index = 0; /* 0000 */ |
2395 | 0 | break; |
2396 | 0 | } |
2397 | 0 | break; |
2398 | | |
2399 | 0 | case 3: |
2400 | | /* INDEX1 table3 |
2401 | | * 0 00000 |
2402 | | * 1 00001 |
2403 | | * 2 01 |
2404 | | * 3 1 |
2405 | | * 4 0001 |
2406 | | * 5 001 |
2407 | | */ |
2408 | 0 | if (_jxr_rbitstream_uint1(str)) |
2409 | 0 | index = 3; /* 1 */ |
2410 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2411 | 0 | index = 2; /* 01 */ |
2412 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2413 | 0 | index = 5; /* 001 */ |
2414 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2415 | 0 | index = 4; /* 0001 */ |
2416 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2417 | 0 | index = 1; /* 00001 */ |
2418 | 0 | else |
2419 | 0 | index = 0; /* 00000 */ |
2420 | 0 | break; |
2421 | | |
2422 | 0 | default: |
2423 | 0 | assert(0); |
2424 | 0 | } |
2425 | | |
2426 | 0 | vlc_delta = image->vlc_table[vlc_select].deltatable; |
2427 | 0 | vlc_delta2 = image->vlc_table[vlc_select].delta2table; |
2428 | |
|
2429 | 0 | image->vlc_table[vlc_select].discriminant += Index1Delta[vlc_delta][index]; |
2430 | 0 | image->vlc_table[vlc_select].discriminant2+= Index1Delta[vlc_delta2][index]; |
2431 | |
|
2432 | 0 | DEBUG(" DECODE_INDEX: vlc_select = %s, deltatable/2 = %d/%d, discriminant/2 becomes %d/%d\n", |
2433 | 0 | _jxr_vlc_index_name(vlc_select), vlc_delta, vlc_delta2, |
2434 | 0 | image->vlc_table[vlc_select].discriminant, |
2435 | 0 | image->vlc_table[vlc_select].discriminant2); |
2436 | |
|
2437 | 0 | return index; |
2438 | 0 | } |
2439 | | |
2440 | | static int r_DECODE_RUN(jxr_image_t image, struct rbitstream*str, int max_run) |
2441 | 0 | { |
2442 | 0 | int run; |
2443 | |
|
2444 | 0 | if (max_run < 5) { |
2445 | 0 | DEBUG(" DECODE_RUN max_run=%d (<5) bitpos=%zu\n", |
2446 | 0 | max_run, _jxr_rbitstream_bitpos(str)); |
2447 | 0 | switch (max_run) { |
2448 | 0 | case 1: |
2449 | 0 | run = 1; |
2450 | 0 | break; |
2451 | 0 | case 2: |
2452 | 0 | if (_jxr_rbitstream_uint1(str)) |
2453 | 0 | run = 1; |
2454 | 0 | else |
2455 | 0 | run = 2; |
2456 | 0 | break; |
2457 | 0 | case 3: |
2458 | 0 | if (_jxr_rbitstream_uint1(str)) |
2459 | 0 | run = 1; |
2460 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2461 | 0 | run = 2; |
2462 | 0 | else |
2463 | 0 | run = 3; |
2464 | 0 | break; |
2465 | 0 | case 4: |
2466 | 0 | if (_jxr_rbitstream_uint1(str)) |
2467 | 0 | run = 1; |
2468 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2469 | 0 | run = 2; |
2470 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2471 | 0 | run = 3; |
2472 | 0 | else |
2473 | 0 | run = 4; |
2474 | 0 | break; |
2475 | 0 | } |
2476 | |
|
2477 | 0 | } else { |
2478 | 0 | static const int RunBin[15] = {-1,-1,-1,-1, 2,2,2, 1,1,1,1, 0,0,0,0 }; |
2479 | 0 | static const int RunFixedLen[15] = {0,0,1,1,3, 0,0,1,1,2, 0,0,0,0,1 }; |
2480 | 0 | static const int Remap[15] = {1,2,3,5,7, 1,2,3,5,7, 1,2,3,4,5 }; |
2481 | 0 | int run_index = 0; |
2482 | 0 | int fixed; |
2483 | 0 | int index; |
2484 | |
|
2485 | 0 | if (_jxr_rbitstream_uint1(str)) |
2486 | 0 | run_index = 0; /* 1 */ |
2487 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2488 | 0 | run_index = 1; /* 01 */ |
2489 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2490 | 0 | run_index = 2; /* 001 */ |
2491 | 0 | else if (_jxr_rbitstream_uint1(str)) |
2492 | 0 | run_index = 4; /* 0001 */ |
2493 | 0 | else |
2494 | 0 | run_index = 3; /* 0000 */ |
2495 | |
|
2496 | 0 | DEBUG(" DECODE_RUN max_run=%d, RUN_INDEX=%d\n", max_run, run_index); |
2497 | |
|
2498 | 0 | assert(max_run < 15); |
2499 | 0 | index = run_index + 5*RunBin[max_run]; |
2500 | 0 | DEBUG(" DECODE_RUN index=%d\n", index); |
2501 | |
|
2502 | 0 | assert(run_index < 15); |
2503 | 0 | fixed = RunFixedLen[index]; |
2504 | 0 | DEBUG(" DECODE_RUN fixed=%d (bitpos=%zu)\n", |
2505 | 0 | fixed, _jxr_rbitstream_bitpos(str)); |
2506 | |
|
2507 | 0 | assert(run_index < 15); |
2508 | 0 | run = Remap[index]; |
2509 | 0 | if (fixed) { |
2510 | 0 | run += _jxr_rbitstream_uintN(str, fixed); |
2511 | 0 | } |
2512 | 0 | } |
2513 | | |
2514 | 0 | DEBUG(" DECODE_RUN max_run=%d, run=%d\n", max_run, run); |
2515 | |
|
2516 | 0 | return run; |
2517 | 0 | } |
2518 | | |
2519 | | |
2520 | | static int r_REFINE_LP(struct rbitstream*str, int coeff, int model_bits) |
2521 | 0 | { |
2522 | 0 | int coeff_refinement = _jxr_rbitstream_uintN(str, model_bits); |
2523 | |
|
2524 | 0 | if (coeff > 0) { |
2525 | 0 | coeff <<= model_bits; |
2526 | 0 | coeff += coeff_refinement; |
2527 | 0 | } else if (coeff < 0) { |
2528 | 0 | coeff <<= model_bits; |
2529 | 0 | coeff -= coeff_refinement; |
2530 | 0 | } else { |
2531 | 0 | coeff = coeff_refinement; |
2532 | 0 | if (coeff) { |
2533 | 0 | int sign_flag = _jxr_rbitstream_uint1(str); |
2534 | 0 | if (sign_flag) |
2535 | 0 | coeff = -coeff; |
2536 | 0 | } |
2537 | 0 | } |
2538 | |
|
2539 | 0 | return coeff; |
2540 | 0 | } |
2541 | | |
2542 | | static void r_PredCBP(jxr_image_t image, int*diff_cbp, |
2543 | | unsigned tx, unsigned ty, |
2544 | | unsigned mx, unsigned my) |
2545 | 0 | { |
2546 | 0 | int idx; |
2547 | |
|
2548 | 0 | if (_jxr_InitContext(image, tx, ty, mx, my)) { |
2549 | 0 | _jxr_InitializeCBPModel(image); |
2550 | 0 | } |
2551 | |
|
2552 | 0 | assert(my == image->cur_my); |
2553 | 0 | switch (image->use_clr_fmt) { |
2554 | 0 | case 1: /*YUV420*/ |
2555 | 0 | MACROBLK_CUR_HPCBP(image, 0, tx, mx) |
2556 | 0 | = _jxr_PredCBP444(image, diff_cbp, 0, tx, mx, my); |
2557 | 0 | MACROBLK_CUR_HPCBP(image, 1, tx, mx) |
2558 | 0 | = _jxr_PredCBP420(image, diff_cbp, 1, tx, mx, my); |
2559 | 0 | MACROBLK_CUR_HPCBP(image, 2, tx, mx) |
2560 | 0 | = _jxr_PredCBP420(image, diff_cbp, 2, tx, mx, my); |
2561 | 0 | DEBUG(" PredCBP: Predicted HPCBP[ch=0]: 0x%04x (YUV420)\n", |
2562 | 0 | MACROBLK_CUR_HPCBP(image, 0, tx, mx)); |
2563 | 0 | DEBUG(" PredCBP: Predicted HPCBP[ch=1]: 0x%04x (YUV420)\n", |
2564 | 0 | MACROBLK_CUR_HPCBP(image, 1, tx, mx)); |
2565 | 0 | DEBUG(" PredCBP: Predicted HPCBP[ch=2]: 0x%04x (YUV420)\n", |
2566 | 0 | MACROBLK_CUR_HPCBP(image, 2, tx, mx)); |
2567 | 0 | break; |
2568 | 0 | case 2: /*YUV422*/ |
2569 | 0 | MACROBLK_CUR_HPCBP(image, 0, tx, mx) |
2570 | 0 | = _jxr_PredCBP444(image, diff_cbp, 0, tx, mx, my); |
2571 | 0 | MACROBLK_CUR_HPCBP(image, 1, tx, mx) |
2572 | 0 | = _jxr_PredCBP422(image, diff_cbp, 1, tx, mx, my); |
2573 | 0 | MACROBLK_CUR_HPCBP(image, 2, tx, mx) |
2574 | 0 | = _jxr_PredCBP422(image, diff_cbp, 2, tx, mx, my); |
2575 | 0 | DEBUG(" PredCBP: Predicted HPCBP[ch=0]: 0x%04x (YUV422)\n", |
2576 | 0 | MACROBLK_CUR_HPCBP(image, 0, tx, mx)); |
2577 | 0 | DEBUG(" PredCBP: Predicted HPCBP[ch=1]: 0x%04x (YUV422)\n", |
2578 | 0 | MACROBLK_CUR_HPCBP(image, 1, tx, mx)); |
2579 | 0 | DEBUG(" PredCBP: Predicted HPCBP[ch=2]: 0x%04x (YUV422)\n", |
2580 | 0 | MACROBLK_CUR_HPCBP(image, 2, tx, mx)); |
2581 | 0 | break; |
2582 | 0 | default: |
2583 | 0 | for (idx = 0; idx<image->num_channels; idx += 1) { |
2584 | 0 | MACROBLK_CUR_HPCBP(image, idx, tx, mx) |
2585 | 0 | = _jxr_PredCBP444(image, diff_cbp, idx, tx, mx, my); |
2586 | 0 | DEBUG(" PredCBP: Predicted HPCBP[ch=%d]: 0x%04x\n", |
2587 | 0 | idx, MACROBLK_CUR_HPCBP(image, idx, tx, mx)); |
2588 | 0 | } |
2589 | 0 | break; |
2590 | 0 | } |
2591 | 0 | } |
2592 | | |
2593 | | static void AdaptiveHPScan(jxr_image_t image, int hpinput_n[], |
2594 | | int i, int value, int MBHPMode) |
2595 | 0 | { |
2596 | 0 | assert(i > 0); |
2597 | |
|
2598 | 0 | if (MBHPMode == 1) { |
2599 | 0 | int k = image->hipass_ver_scanorder[i-1]; |
2600 | 0 | image->hipass_ver_scantotals[i-1] += 1; |
2601 | 0 | assert(k < 16); |
2602 | 0 | hpinput_n[k] = value; |
2603 | |
|
2604 | 0 | if ((i>1) && (image->hipass_ver_scantotals[i-1] > image->hipass_ver_scantotals[i-2])) { |
2605 | 0 | SWAP(image->hipass_ver_scantotals[i-1], image->hipass_ver_scantotals[i-2]); |
2606 | 0 | SWAP(image->hipass_ver_scanorder[i-1], image->hipass_ver_scanorder[i-2]); |
2607 | 0 | } |
2608 | 0 | } else { |
2609 | 0 | int k = image->hipass_hor_scanorder[i-1]; |
2610 | 0 | image->hipass_hor_scantotals[i-1] += 1; |
2611 | 0 | assert(k < 16); |
2612 | 0 | hpinput_n[k] = value; |
2613 | |
|
2614 | 0 | if ((i>1) && (image->hipass_hor_scantotals[i-1] > image->hipass_hor_scantotals[i-2])) { |
2615 | 0 | SWAP(image->hipass_hor_scantotals[i-1], image->hipass_hor_scantotals[i-2]); |
2616 | 0 | SWAP(image->hipass_hor_scanorder[i-1], image->hipass_hor_scanorder[i-2]); |
2617 | 0 | } |
2618 | 0 | } |
2619 | 0 | } |
2620 | | |
2621 | | /* |
2622 | | * For each block within the macroblk, there are 15 HP values and the |
2623 | | * DECODE_BLOCK_ADAPTIVE function is called to collect those values. |
2624 | | */ |
2625 | | static int r_DECODE_BLOCK_ADAPTIVE(jxr_image_t image, struct rbitstream*str, |
2626 | | unsigned tx, unsigned mx, |
2627 | | int cbp_flag, int chroma_flag, |
2628 | | int channel, int block, int mbhp_pred_mode, |
2629 | | unsigned model_bits) |
2630 | 0 | { |
2631 | 0 | int RLCoeffs[32] = {0}; |
2632 | |
|
2633 | 0 | int num_nonzero = 0; |
2634 | 0 | if (cbp_flag) { |
2635 | 0 | int idx, k; |
2636 | 0 | int hpinput[16]; |
2637 | 0 | for (k = 0 ; k < 16 ; k += 1) |
2638 | 0 | hpinput[k] = 0; |
2639 | |
|
2640 | 0 | num_nonzero = r_DECODE_BLOCK(image, str, chroma_flag, RLCoeffs, 2/*HP*/, 1); |
2641 | |
|
2642 | 0 | for (idx = 0, k = 1 ; idx < num_nonzero ; idx += 1) { |
2643 | 0 | assert(idx < 16); |
2644 | 0 | k += RLCoeffs[idx*2]; |
2645 | 0 | if (k >= 16) { |
2646 | 0 | DEBUG("ERROR: r_DECODE_BLOCK returned bogus RLCoeffs table. ch=%d, tx=%u, mx=%u, k=%d\n", |
2647 | 0 | channel, tx, mx, k); |
2648 | 0 | for (idx = 0 ; idx < num_nonzero ; idx += 1) { |
2649 | 0 | DEBUG(" : RLCoeffs[%d] = %d\n", idx*2, RLCoeffs[idx*2]); |
2650 | 0 | DEBUG(" : RLCoeffs[%d] = 0x%x\n", idx*2+1, RLCoeffs[idx*2+1]); |
2651 | 0 | } |
2652 | 0 | return JXR_EC_ERROR; |
2653 | 0 | } |
2654 | 0 | assert(k < 16); |
2655 | 0 | AdaptiveHPScan(image, hpinput, k, RLCoeffs[idx*2+1], mbhp_pred_mode); |
2656 | 0 | k += 1; |
2657 | 0 | } |
2658 | | #if defined(DETAILED_DEBUG) |
2659 | | { |
2660 | | DEBUG(" HP val[tx=%u, mx=%d, block=%d] ==", tx, mx, block); |
2661 | | for (k = 1 ; k<16; k+=1) { |
2662 | | DEBUG(" 0x%x", hpinput[k]); |
2663 | | } |
2664 | | DEBUG("\n"); |
2665 | | DEBUG(" adapted hor scan order (MBHPMode=%d) ==", mbhp_pred_mode); |
2666 | | for (k = 0 ; k<15; k+=1) { |
2667 | | DEBUG(" %2d", image->hipass_hor_scanorder[k]); |
2668 | | } |
2669 | | DEBUG("\n"); |
2670 | | DEBUG(" adapted hor scan totals =="); |
2671 | | for (k = 0 ; k<15; k+=1) { |
2672 | | DEBUG(" %2d", image->hipass_hor_scantotals[k]); |
2673 | | } |
2674 | | DEBUG("\n"); |
2675 | | DEBUG(" adapted ver scan order (MBHPMode=%d) ==", mbhp_pred_mode); |
2676 | | for (k = 0 ; k<15; k+=1) { |
2677 | | DEBUG(" %2d", image->hipass_ver_scanorder[k]); |
2678 | | } |
2679 | | DEBUG("\n"); |
2680 | | DEBUG(" adapted ver scan totals =="); |
2681 | | for (k = 0 ; k<15; k+=1) { |
2682 | | DEBUG(" %2d", image->hipass_ver_scantotals[k]); |
2683 | | } |
2684 | | DEBUG("\n"); |
2685 | | } |
2686 | | #endif |
2687 | 0 | if (SKIP_HP_DATA(image)) { |
2688 | 0 | for (idx = 1; idx < 16; idx += 1) |
2689 | 0 | MACROBLK_CUR_HP(image, channel, tx, mx, block, idx-1) = 0; |
2690 | 0 | } else { |
2691 | 0 | for (idx = 1; idx < 16; idx += 1) |
2692 | 0 | MACROBLK_CUR_HP(image, channel, tx, mx, block, idx-1) = hpinput[idx] << model_bits; |
2693 | 0 | } |
2694 | 0 | } |
2695 | | |
2696 | 0 | return num_nonzero; |
2697 | 0 | } |
2698 | | |
2699 | | |
2700 | | |
2701 | | static void r_DECODE_FLEX(jxr_image_t image, struct rbitstream*str, |
2702 | | unsigned tx, unsigned mx, |
2703 | | int ch, unsigned block, unsigned k, |
2704 | | unsigned flexbits) |
2705 | 0 | { |
2706 | | /* NOTE: The model_bits shift was already applied, when the HP |
2707 | | value was first parsed. */ |
2708 | 0 | int coeff = MACROBLK_CUR_HP(image, ch, tx, mx, block, k); |
2709 | |
|
2710 | 0 | int flex_ref = _jxr_rbitstream_uintN(str, flexbits); |
2711 | 0 | DEBUG(" DECODE_FLEX: coeff=0x%08x, flex_ref=0x%08x\n", coeff, flex_ref); |
2712 | 0 | if (coeff > 0) { |
2713 | 0 | coeff += flex_ref << image->trim_flexbits; |
2714 | 0 | } else if (coeff < 0) { |
2715 | 0 | coeff -= flex_ref << image->trim_flexbits; |
2716 | 0 | } else { |
2717 | 0 | if (flex_ref != 0 && _jxr_rbitstream_uint1(str)) |
2718 | 0 | coeff = (-flex_ref) << image->trim_flexbits; |
2719 | 0 | else |
2720 | 0 | coeff = (+flex_ref) << image->trim_flexbits; |
2721 | 0 | } |
2722 | |
|
2723 | 0 | if (! SKIP_FLEX_DATA(image)) |
2724 | 0 | MACROBLK_CUR_HP(image, ch, tx, mx, block, k) = coeff; |
2725 | 0 | } |
2726 | | |
2727 | | static void r_BLOCK_FLEXBITS(jxr_image_t image, struct rbitstream*str, |
2728 | | unsigned tx, unsigned ty, |
2729 | | unsigned mx, unsigned my, |
2730 | | unsigned ch, unsigned bl, unsigned model_bits) |
2731 | 0 | { |
2732 | 0 | const int transpose444 [16] = {0, 4, 8,12, |
2733 | 0 | 1, 5, 9,13, |
2734 | 0 | 2, 6,10,14, |
2735 | 0 | 3, 7,11,15 }; |
2736 | 0 | unsigned flexbits_left = model_bits; |
2737 | 0 | if (image->trim_flexbits > flexbits_left) |
2738 | 0 | flexbits_left = 0; |
2739 | 0 | else |
2740 | 0 | flexbits_left -= image->trim_flexbits; |
2741 | |
|
2742 | 0 | DEBUG(" BLOCK_FLEXBITS: flexbits_left=%u (model=%u, trim=%u) block=%u bitpos=%zu\n", |
2743 | 0 | flexbits_left, model_bits, image->trim_flexbits, bl, _jxr_rbitstream_bitpos(str)); |
2744 | 0 | if (flexbits_left > 0) { |
2745 | 0 | int idx; |
2746 | 0 | for (idx = 1; idx < 16; idx += 1) { |
2747 | 0 | int idx_trans = transpose444[idx]; |
2748 | 0 | r_DECODE_FLEX(image, str, tx, mx, ch, bl, idx_trans-1, flexbits_left); |
2749 | 0 | } |
2750 | 0 | } |
2751 | 0 | DEBUG(" BLOCK_FLEXBITS done\n"); |
2752 | 0 | } |
2753 | | |
2754 | | static int r_calculate_mbhp_mode(jxr_image_t image, int tx, int mx) |
2755 | 0 | { |
2756 | 0 | long strength_hor = 0; |
2757 | 0 | long strength_ver = 0; |
2758 | 0 | const long orientation_weight = 4; |
2759 | | |
2760 | | /* Add up the LP magnitudes along the top edge */ |
2761 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 0, tx, mx, 0)); |
2762 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 0, tx, mx, 1)); |
2763 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 0, tx, mx, 2)); |
2764 | | |
2765 | | /* Add up the LP magnitudes along the left edge */ |
2766 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 0, tx, mx, 3)); |
2767 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 0, tx, mx, 7)); |
2768 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 0, tx, mx, 11)); |
2769 | |
|
2770 | 0 | switch (image->use_clr_fmt) { |
2771 | 0 | case 0: /*YONLY*/ |
2772 | 0 | case 6: /*NCOMPONENT*/ |
2773 | 0 | break; |
2774 | 0 | case 3: /*YUV444*/ |
2775 | 0 | case 4: /*YUVK */ |
2776 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 1, tx, mx, 0)); |
2777 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 2, tx, mx, 0)); |
2778 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 1, tx, mx, 3)); |
2779 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 2, tx, mx, 3)); |
2780 | 0 | break; |
2781 | 0 | case 2: /*YUV422*/ |
2782 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 1, tx, mx, 0)); |
2783 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 2, tx, mx, 0)); |
2784 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 1, tx, mx, 1)); |
2785 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 2, tx, mx, 1)); |
2786 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 1, tx, mx, 4)); |
2787 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 2, tx, mx, 4)); |
2788 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 1, tx, mx, 5)); |
2789 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 2, tx, mx, 5)); |
2790 | 0 | break; |
2791 | 0 | case 1: /*YUV420*/ |
2792 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 1, tx, mx, 0)); |
2793 | 0 | strength_hor += abs(MACROBLK_CUR_LP(image, 2, tx, mx, 0)); |
2794 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 1, tx, mx, 1)); |
2795 | 0 | strength_ver += abs(MACROBLK_CUR_LP(image, 2, tx, mx, 1)); |
2796 | 0 | break; |
2797 | 0 | default: |
2798 | 0 | assert(0); |
2799 | 0 | } |
2800 | | |
2801 | 0 | if (strength_hor * orientation_weight < strength_ver) |
2802 | 0 | return 0; /* predict from left */ |
2803 | 0 | if (strength_ver * orientation_weight < strength_hor) |
2804 | 0 | return 1; /* predict from top */ |
2805 | | |
2806 | | /* There is no strong weight from top or left, so do not |
2807 | | bother with prediction. */ |
2808 | 0 | return 2; |
2809 | 0 | } |
2810 | | |
2811 | | |
2812 | | /* |
2813 | | * This function does HP coefficient propagation within a completed |
2814 | | * macroblock. |
2815 | | */ |
2816 | | void _jxr_propagate_hp_predictions(jxr_image_t image, int ch, unsigned tx, unsigned mx, |
2817 | | int mbhp_pred_mode) |
2818 | 0 | { |
2819 | 0 | if (mbhp_pred_mode == 0) { /* Prediction left to right */ |
2820 | 0 | int idx; |
2821 | 0 | for (idx = 1 ; idx < 16 ; idx += 1) { |
2822 | 0 | if (idx%4 == 0) |
2823 | 0 | continue; |
2824 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,ch,tx,mx,idx, 3), MACROBLK_CUR_HP(image,ch,tx,mx,idx, 7), MACROBLK_CUR_HP(image,ch,tx,mx,idx, 11)); |
2825 | 0 | MACROBLK_CUR_HP(image,ch,tx,mx,idx, 3) += MACROBLK_CUR_HP(image,ch,tx,mx,idx-1, 3); |
2826 | 0 | MACROBLK_CUR_HP(image,ch,tx,mx,idx, 7) += MACROBLK_CUR_HP(image,ch,tx,mx,idx-1, 7); |
2827 | 0 | MACROBLK_CUR_HP(image,ch,tx,mx,idx,11) += MACROBLK_CUR_HP(image,ch,tx,mx,idx-1,11); |
2828 | |
|
2829 | | #if defined(DETAILED_DEBUG) |
2830 | | { |
2831 | | int k; |
2832 | | DEBUG(" HP val predicted(l)[ch=%d, tx=%u, mx=%d, block=%d] ==", ch, tx, mx, idx); |
2833 | | for (k = 1 ; k<16; k+=1) { |
2834 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,ch,tx,mx,idx,k-1)); |
2835 | | } |
2836 | | DEBUG("\n"); |
2837 | | } |
2838 | | #endif |
2839 | 0 | } |
2840 | 0 | } else if (mbhp_pred_mode == 1) { /* Prediction top to bottom. */ |
2841 | 0 | int idx; |
2842 | 0 | for (idx = 4 ; idx < 16 ; idx += 1) { |
2843 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,ch,tx,mx,idx, 0), MACROBLK_CUR_HP(image,ch,tx,mx,idx, 1), MACROBLK_CUR_HP(image,ch,tx,mx,idx, 2)); |
2844 | 0 | MACROBLK_CUR_HP(image,ch,tx,mx,idx,0) += MACROBLK_CUR_HP(image,ch,tx,mx, idx-4,0); |
2845 | 0 | MACROBLK_CUR_HP(image,ch,tx,mx,idx,1) += MACROBLK_CUR_HP(image,ch,tx,mx, idx-4,1); |
2846 | 0 | MACROBLK_CUR_HP(image,ch,tx,mx,idx,2) += MACROBLK_CUR_HP(image,ch,tx,mx, idx-4,2); |
2847 | | #if defined(DETAILED_DEBUG) |
2848 | | { |
2849 | | int k; |
2850 | | DEBUG(" HP val predicted(t)[ch=%d, tx=%u, mx=%d, block=%d] ==", ch, tx, mx, idx); |
2851 | | for (k = 1 ; k<16; k+=1) { |
2852 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,ch,tx,mx,idx,k-1)); |
2853 | | } |
2854 | | DEBUG("\n"); |
2855 | | } |
2856 | | #endif |
2857 | 0 | } |
2858 | 0 | } |
2859 | |
|
2860 | 0 | switch (image->use_clr_fmt) { |
2861 | 0 | case 1:/*YUV420*/ |
2862 | 0 | assert(ch == 0); |
2863 | 0 | if (mbhp_pred_mode == 0) { |
2864 | 0 | int idx; |
2865 | 0 | for (idx = 1 ; idx <= 3 ; idx += 2) { |
2866 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,1,tx,mx,idx, 3), MACROBLK_CUR_HP(image,1,tx,mx,idx, 7), MACROBLK_CUR_HP(image,1,tx,mx,idx, 11)); |
2867 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,2,tx,mx,idx, 3), MACROBLK_CUR_HP(image,2,tx,mx,idx, 7), MACROBLK_CUR_HP(image,2,tx,mx,idx, 11)); |
2868 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,3) += MACROBLK_CUR_HP(image,1,tx,mx,idx-1,3); |
2869 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,3) += MACROBLK_CUR_HP(image,2,tx,mx,idx-1,3); |
2870 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,7) += MACROBLK_CUR_HP(image,1,tx,mx,idx-1,7); |
2871 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,7) += MACROBLK_CUR_HP(image,2,tx,mx,idx-1,7); |
2872 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,11)+= MACROBLK_CUR_HP(image,1,tx,mx,idx-1,11); |
2873 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,11)+= MACROBLK_CUR_HP(image,2,tx,mx,idx-1,11); |
2874 | | #if defined(DETAILED_DEBUG) |
2875 | | int k; |
2876 | | DEBUG(" HP val predicted(l)[ch=1, tx=%u, mx=%d, block=%d] ==", tx, mx, idx); |
2877 | | for (k = 1 ; k<16; k+=1) { |
2878 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,1,tx,mx,idx,k-1)); |
2879 | | } |
2880 | | DEBUG("\n"); |
2881 | | DEBUG(" HP val predicted(l)[ch=2, tx=%u, mx=%d, block=%d] ==", tx, mx, idx); |
2882 | | for (k = 1 ; k<16; k+=1) { |
2883 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,2,tx,mx,idx,k-1)); |
2884 | | } |
2885 | | DEBUG("\n"); |
2886 | | #endif |
2887 | 0 | } |
2888 | 0 | } else if (mbhp_pred_mode == 1) { |
2889 | 0 | int idx; |
2890 | 0 | for (idx = 2; idx <= 3 ; idx += 1) { |
2891 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,1,tx,mx,idx, 0), MACROBLK_CUR_HP(image,1,tx,mx,idx, 1), MACROBLK_CUR_HP(image,1,tx,mx,idx, 2)); |
2892 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,2,tx,mx,idx, 0), MACROBLK_CUR_HP(image,2,tx,mx,idx, 1), MACROBLK_CUR_HP(image,2,tx,mx,idx, 2)); |
2893 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,0) += MACROBLK_CUR_HP(image,1,tx,mx,idx-2,0); |
2894 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,0) += MACROBLK_CUR_HP(image,2,tx,mx,idx-2,0); |
2895 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,1) += MACROBLK_CUR_HP(image,1,tx,mx,idx-2,1); |
2896 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,1) += MACROBLK_CUR_HP(image,2,tx,mx,idx-2,1); |
2897 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,2) += MACROBLK_CUR_HP(image,1,tx,mx,idx-2,2); |
2898 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,2) += MACROBLK_CUR_HP(image,2,tx,mx,idx-2,2); |
2899 | | #if defined(DETAILED_DEBUG) |
2900 | | int k; |
2901 | | DEBUG(" HP val predicted(t)[ch=1, tx=%u, mx=%d, block=%d] ==", tx, mx, idx); |
2902 | | for (k = 1 ; k<16; k+=1) { |
2903 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,1,tx,mx,idx,k-1)); |
2904 | | } |
2905 | | DEBUG("\n"); |
2906 | | DEBUG(" HP val predicted(t)[ch=2, tx=%u, mx=%d, block=%d] ==", tx, mx, idx); |
2907 | | for (k = 1 ; k<16; k+=1) { |
2908 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,2,tx,mx,idx,k-1)); |
2909 | | } |
2910 | | DEBUG("\n"); |
2911 | | #endif |
2912 | 0 | } |
2913 | 0 | } |
2914 | 0 | break; |
2915 | | |
2916 | 0 | case 2:/*YUV422*/ |
2917 | 0 | assert(ch == 0); |
2918 | 0 | if (mbhp_pred_mode == 0) { |
2919 | 0 | int idx; |
2920 | 0 | for (idx = 1 ; idx <= 7 ; idx += 2) { |
2921 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,1,tx,mx,idx, 3), MACROBLK_CUR_HP(image,1,tx,mx,idx, 7), MACROBLK_CUR_HP(image,1,tx,mx,idx, 11)); |
2922 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,2,tx,mx,idx, 3), MACROBLK_CUR_HP(image,2,tx,mx,idx, 7), MACROBLK_CUR_HP(image,2,tx,mx,idx, 11)); |
2923 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,3) += MACROBLK_CUR_HP(image,1,tx,mx,idx-1,3); |
2924 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,3) += MACROBLK_CUR_HP(image,2,tx,mx,idx-1,3); |
2925 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,7) += MACROBLK_CUR_HP(image,1,tx,mx,idx-1,7); |
2926 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,7) += MACROBLK_CUR_HP(image,2,tx,mx,idx-1,7); |
2927 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,11)+= MACROBLK_CUR_HP(image,1,tx,mx,idx-1,11); |
2928 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,11)+= MACROBLK_CUR_HP(image,2,tx,mx,idx-1,11); |
2929 | | #if defined(DETAILED_DEBUG) |
2930 | | int k; |
2931 | | DEBUG(" HP val predicted(l)[ch=1, tx=%u, mx=%d, block=%d] ==", tx, mx, idx); |
2932 | | for (k = 1 ; k<16; k+=1) { |
2933 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,1,tx,mx,idx,k-1)); |
2934 | | } |
2935 | | DEBUG("\n"); |
2936 | | DEBUG(" HP val predicted(l)[ch=2, tx=%u, mx=%d, block=%d] ==", tx, mx, idx); |
2937 | | for (k = 1 ; k<16; k+=1) { |
2938 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,2,tx,mx,idx,k-1)); |
2939 | | } |
2940 | | DEBUG("\n"); |
2941 | | #endif |
2942 | 0 | } |
2943 | 0 | } else if (mbhp_pred_mode == 1) { |
2944 | 0 | int idx; |
2945 | 0 | for (idx = 2; idx <= 7 ; idx += 1) { |
2946 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,1,tx,mx,idx, 0), MACROBLK_CUR_HP(image,1,tx,mx,idx, 1), MACROBLK_CUR_HP(image,1,tx,mx,idx, 2)); |
2947 | 0 | CHECK3(image->lwf_test, MACROBLK_CUR_HP(image,2,tx,mx,idx, 0), MACROBLK_CUR_HP(image,2,tx,mx,idx, 1), MACROBLK_CUR_HP(image,2,tx,mx,idx, 2)); |
2948 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,0) += MACROBLK_CUR_HP(image,1,tx,mx,idx-2,0); |
2949 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,0) += MACROBLK_CUR_HP(image,2,tx,mx,idx-2,0); |
2950 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,1) += MACROBLK_CUR_HP(image,1,tx,mx,idx-2,1); |
2951 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,1) += MACROBLK_CUR_HP(image,2,tx,mx,idx-2,1); |
2952 | 0 | MACROBLK_CUR_HP(image,1,tx,mx,idx,2) += MACROBLK_CUR_HP(image,1,tx,mx,idx-2,2); |
2953 | 0 | MACROBLK_CUR_HP(image,2,tx,mx,idx,2) += MACROBLK_CUR_HP(image,2,tx,mx,idx-2,2); |
2954 | | #if defined(DETAILED_DEBUG) |
2955 | | int k; |
2956 | | DEBUG(" HP val predicted(t)[ch=1, tx=%u, mx=%d, block=%d] ==", tx, mx, idx); |
2957 | | for (k = 1 ; k<16; k+=1) { |
2958 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,1,tx,mx,idx,k-1)); |
2959 | | } |
2960 | | DEBUG("\n"); |
2961 | | DEBUG(" HP val predicted(t)[ch=2, tx=%u, mx=%d, block=%d] ==", tx, mx, idx); |
2962 | | for (k = 1 ; k<16; k+=1) { |
2963 | | DEBUG(" 0x%x", MACROBLK_CUR_HP(image,2,tx,mx,idx,k-1)); |
2964 | | } |
2965 | | DEBUG("\n"); |
2966 | | #endif |
2967 | 0 | } |
2968 | 0 | } |
2969 | 0 | break; |
2970 | | |
2971 | 0 | default: |
2972 | 0 | break; |
2973 | 0 | } |
2974 | 0 | } |
2975 | | |
2976 | | |
2977 | | /* |
2978 | | * Code IS_DC_YUV |
2979 | | * 10 0 |
2980 | | * 001 1 |
2981 | | * 00001 2 |
2982 | | * 0001 3 |
2983 | | * 11 4 |
2984 | | * 010 5 |
2985 | | * 00000 6 |
2986 | | * 011 7 |
2987 | | */ |
2988 | | static int get_is_dc_yuv(struct rbitstream*str) |
2989 | 0 | { |
2990 | 0 | if (_jxr_rbitstream_uint1(str) == 1) { /* 1... */ |
2991 | 0 | if (_jxr_rbitstream_uint1(str) == 1) /* 11 */ |
2992 | 0 | return 4; |
2993 | 0 | else /* 10 */ |
2994 | 0 | return 0; |
2995 | 0 | } |
2996 | 0 | else { |
2997 | 0 | switch (_jxr_rbitstream_uint2(str)) { /* 1... */ |
2998 | 0 | case 0: /* 000... */ |
2999 | 0 | if (_jxr_rbitstream_uint1(str) == 1) /* 0001 */ |
3000 | 0 | return 3; |
3001 | 0 | else if (_jxr_rbitstream_uint1(str) == 1) /* 00001 */ |
3002 | 0 | return 2; |
3003 | 0 | else /* 00000 */ |
3004 | 0 | return 6; |
3005 | 0 | case 1: /* 001 */ |
3006 | 0 | return 1; |
3007 | | |
3008 | 0 | case 2: /* 010 */ |
3009 | 0 | return 5; |
3010 | | |
3011 | 0 | case 3: /* 011 */ |
3012 | 0 | return 7; |
3013 | 0 | } |
3014 | 0 | } |
3015 | | |
3016 | 0 | assert(0); /* Should not get here. */ |
3017 | 0 | return -1; |
3018 | 0 | } |
3019 | | |
3020 | | /* |
3021 | | * table0 table1 value |
3022 | | * 1 1 0 |
3023 | | * 01 000 1 |
3024 | | * 001 001 2 |
3025 | | * 0000 010 3 |
3026 | | * 0001 011 4 |
3027 | | */ |
3028 | | static int get_num_cbp(struct rbitstream*str, struct adaptive_vlc_s*vlc) |
3029 | 0 | { |
3030 | 0 | assert(vlc->table < 2); |
3031 | |
|
3032 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
3033 | 0 | return 0; |
3034 | | |
3035 | 0 | if (vlc->table == 0) { |
3036 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
3037 | 0 | return 1; |
3038 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
3039 | 0 | return 2; |
3040 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
3041 | 0 | return 4; |
3042 | 0 | else |
3043 | 0 | return 3; |
3044 | 0 | } else { |
3045 | 0 | uint8_t tmp = _jxr_rbitstream_uint2(str); |
3046 | 0 | return tmp + 1; |
3047 | 0 | } |
3048 | 0 | } |
3049 | | |
3050 | | static int get_num_blkcbp(jxr_image_t image, struct rbitstream*str, |
3051 | | struct adaptive_vlc_s*vlc) |
3052 | 0 | { |
3053 | 0 | switch (image->use_clr_fmt) { |
3054 | 0 | case 0: /*YONLY*/ |
3055 | 0 | case 4: /*YUVK*/ |
3056 | 0 | case 6: /*NCOMPONENT*/ |
3057 | | /* |
3058 | | * table0 table1 value |
3059 | | * 1 1 0 |
3060 | | * 01 000 1 |
3061 | | * 001 001 2 |
3062 | | * 0000 010 3 |
3063 | | * 0001 011 4 |
3064 | | * |
3065 | | * NOTE that this is exactly the same table as for |
3066 | | * NUM_CBP above. |
3067 | | */ |
3068 | 0 | return get_num_cbp(str, vlc); |
3069 | | |
3070 | 0 | default: |
3071 | | /* |
3072 | | * table0 table1 value |
3073 | | * 010 1 0 |
3074 | | * 00000 001 1 |
3075 | | * 0010 010 2 |
3076 | | * 00001 0001 3 |
3077 | | * 00010 000001 4 |
3078 | | * 1 011 5 |
3079 | | * 011 00001 6 |
3080 | | * 00011 0000000 7 |
3081 | | * 0011 0000001 8 |
3082 | | */ |
3083 | 0 | if (vlc->table == 0) { |
3084 | 0 | static const unsigned char codeb[32] = { |
3085 | 0 | 5, 5, 5, 5, 4, 4, 4, 4, |
3086 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, |
3087 | 0 | 1, 1, 1, 1, 1, 1, 1, 1, /* 1xxxx */ |
3088 | 0 | 1, 1, 1, 1, 1, 1, 1, 1 |
3089 | 0 | }; |
3090 | 0 | static const signed char codev[32] = { |
3091 | 0 | 1, 3, 4, 7, 2, 2, 8, 8, |
3092 | 0 | 0, 0, 0, 0, 6, 6, 6, 6, |
3093 | 0 | 5, 5, 5, 5, 5, 5, 5, 5, |
3094 | 0 | 5, 5, 5, 5, 5, 5, 5, 5 |
3095 | 0 | }; |
3096 | 0 | return _jxr_rbitstream_intE(str, 5, codeb, codev); |
3097 | 0 | } else { |
3098 | 0 | static const unsigned char codeb[64] = { |
3099 | 0 | 6, 6, 5, 5, 4, 4, 4, 4, |
3100 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, |
3101 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, |
3102 | 0 | 3, 3, 3, 3, 3, 3, 3, 3, |
3103 | 0 | 1, 1, 1, 1, 1, 1, 1, 1, |
3104 | 0 | 1, 1, 1, 1, 1, 1, 1, 1, |
3105 | 0 | 1, 1, 1, 1, 1, 1, 1, 1, |
3106 | 0 | 1, 1, 1, 1, 1, 1, 1, 1 |
3107 | 0 | }; |
3108 | 0 | static const signed char codev[64] = { |
3109 | 0 | 7, 4, 6, 6, 3, 3, 3, 3, |
3110 | 0 | 1, 1, 1, 1, 1, 1, 1, 1, |
3111 | 0 | 2, 2, 2, 2, 2, 2, 2, 2, |
3112 | 0 | 5, 5, 5, 5, 5, 5, 5, 5, |
3113 | 0 | 0, 0, 0, 0, 0, 0, 0, 0, |
3114 | 0 | 0, 0, 0, 0, 0, 0, 0, 0, |
3115 | 0 | 0, 0, 0, 0, 0, 0, 0, 0, |
3116 | 0 | 0, 0, 0, 0, 0, 0, 0, 0 |
3117 | 0 | }; |
3118 | 0 | int tmp = _jxr_rbitstream_intE(str, 6, codeb, codev); |
3119 | 0 | if (tmp == 7) tmp += _jxr_rbitstream_uint1(str); |
3120 | 0 | return tmp; |
3121 | 0 | } |
3122 | 0 | } |
3123 | 0 | } |
3124 | | |
3125 | | |
3126 | | |
3127 | | /* |
3128 | | * value table0 table1 |
3129 | | * 0 01 1 |
3130 | | * 1 10 01 |
3131 | | * 2 11 001 |
3132 | | * 3 001 0001 |
3133 | | * 4 0001 00001 |
3134 | | * 5 00000 000000 |
3135 | | * 6 00001 000001 |
3136 | | */ |
3137 | | static const unsigned char abslevel_code0b[64] = { |
3138 | | 5, 5, 5, 5, 4, 4, 4, 4, /* 00000x, 00001x, 0001xx */ |
3139 | | 3, 3, 3, 3, 3, 3, 3, 3, /* 001xxx */ |
3140 | | 2, 2, 2, 2, 2, 2, 2, 2, /* 01xxxx */ |
3141 | | 2, 2, 2, 2, 2, 2, 2, 2, |
3142 | | 2, 2, 2, 2, 2, 2, 2, 2, /* 10xxxx */ |
3143 | | 2, 2, 2, 2, 2, 2, 2, 2, |
3144 | | 2, 2, 2, 2, 2, 2, 2, 2, /* 11xxxx */ |
3145 | | 2, 2, 2, 2, 2, 2, 2, 2 |
3146 | | }; |
3147 | | static const signed char abslevel_code0v[64] = { |
3148 | | 5, 5, 6, 6, 4, 4, 4, 4, |
3149 | | 3, 3, 3, 3, 3, 3, 3, 3, |
3150 | | 0, 0, 0, 0, 0, 0, 0, 0, |
3151 | | 0, 0, 0, 0, 0, 0, 0, 0, |
3152 | | 1, 1, 1, 1, 1, 1, 1, 1, |
3153 | | 1, 1, 1, 1, 1, 1, 1, 1, |
3154 | | 2, 2, 2, 2, 2, 2, 2, 2, |
3155 | | 2, 2, 2, 2, 2, 2, 2, 2 |
3156 | | }; |
3157 | | |
3158 | | static const unsigned char abslevel_code1b[64] = { |
3159 | | 6, 6, 5, 5, 4, 4, 4, 4, /* 000000, 000001, 00001x, 0001xx */ |
3160 | | 3, 3, 3, 3, 3, 3, 3, 3, /* 001xxx */ |
3161 | | 2, 2, 2, 2, 2, 2, 2, 2, /* 01xxxx */ |
3162 | | 2, 2, 2, 2, 2, 2, 2, 2, |
3163 | | 1, 1, 1, 1, 1, 1, 1, 1, /* 1xxxxx */ |
3164 | | 1, 1, 1, 1, 1, 1, 1, 1, |
3165 | | 1, 1, 1, 1, 1, 1, 1, 1, |
3166 | | 1, 1, 1, 1, 1, 1, 1, 1 |
3167 | | }; |
3168 | | static const signed char abslevel_code1v[64] = { |
3169 | | 5, 6, 4, 4, 3, 3, 3, 3, |
3170 | | 2, 2, 2, 2, 2, 2, 2, 2, |
3171 | | 1, 1, 1, 1, 1, 1, 1, 1, |
3172 | | 1, 1, 1, 1, 1, 1, 1, 1, |
3173 | | 0, 0, 0, 0, 0, 0, 0, 0, |
3174 | | 0, 0, 0, 0, 0, 0, 0, 0, |
3175 | | 0, 0, 0, 0, 0, 0, 0, 0, |
3176 | | 0, 0, 0, 0, 0, 0, 0, 0 |
3177 | | }; |
3178 | | |
3179 | | static int dec_abslevel_index(jxr_image_t image, struct rbitstream*str, int vlc_select) |
3180 | 0 | { |
3181 | 0 | const unsigned char*codeb = image->vlc_table[vlc_select].table? abslevel_code1b :abslevel_code0b; |
3182 | 0 | const signed char*codev = image->vlc_table[vlc_select].table? abslevel_code1v : abslevel_code0v; |
3183 | |
|
3184 | 0 | return _jxr_rbitstream_intE(str, 6, codeb, codev); |
3185 | 0 | } |
3186 | | |
3187 | | static int dec_cbp_yuv_lp1(jxr_image_t image, struct rbitstream*str) |
3188 | 0 | { |
3189 | 0 | static const unsigned char codeb[16] = { |
3190 | 0 | 1, 1, 1, 1, |
3191 | 0 | 1, 1, 1, 1, |
3192 | 0 | 3, 3, 4, 4, |
3193 | 0 | 4, 4, 4, 4 }; |
3194 | 0 | static const signed char codev[16] = { |
3195 | 0 | 0, 0, 0, 0, |
3196 | 0 | 0, 0, 0, 0, |
3197 | 0 | 1, 1, 2, 3, |
3198 | 0 | 4, 5, 6, 7 }; |
3199 | |
|
3200 | 0 | switch (image->use_clr_fmt) { |
3201 | 0 | case 3: /* YUV444 */ |
3202 | 0 | return _jxr_rbitstream_intE(str, 4, codeb, codev); |
3203 | 0 | case 1: /* YUV420 */ |
3204 | 0 | case 2: /* YUV422 */ |
3205 | 0 | if (_jxr_rbitstream_uint1(str) == 0) { |
3206 | 0 | return 0; |
3207 | |
|
3208 | 0 | } else if (_jxr_rbitstream_uint1(str) == 0) { |
3209 | 0 | return 1; |
3210 | |
|
3211 | 0 | } else if (_jxr_rbitstream_uint1(str) == 0) { |
3212 | 0 | return 2; |
3213 | |
|
3214 | 0 | } else { |
3215 | 0 | return 3; |
3216 | 0 | } |
3217 | 0 | default: |
3218 | 0 | assert(0); |
3219 | 0 | return 0; |
3220 | 0 | } |
3221 | 0 | } |
3222 | | |
3223 | | /* |
3224 | | * Bits Value |
3225 | | * 1 0 |
3226 | | * 01 1 |
3227 | | * 00 2 |
3228 | | */ |
3229 | | static int get_value_012(struct rbitstream*str) |
3230 | 0 | { |
3231 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
3232 | 0 | return 0; |
3233 | 0 | else if ( _jxr_rbitstream_uint1(str) == 1) |
3234 | 0 | return 1; |
3235 | 0 | else |
3236 | 0 | return 2; |
3237 | 0 | } |
3238 | | |
3239 | | /* |
3240 | | * Bits Value |
3241 | | * 1 0 |
3242 | | * 01 1 |
3243 | | * 000 2 |
3244 | | * 001 3 |
3245 | | */ |
3246 | | static int get_num_ch_blk(struct rbitstream*str) |
3247 | 0 | { |
3248 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
3249 | 0 | return 0; |
3250 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
3251 | 0 | return 1; |
3252 | 0 | if (_jxr_rbitstream_uint1(str) == 1) |
3253 | 0 | return 3; |
3254 | 0 | else |
3255 | 0 | return 2; |
3256 | 0 | } |
3257 | | |
3258 | | /* |
3259 | | * $Log: r_parse.c,v $ |
3260 | | * Revision 1.41 2009/05/29 12:00:00 microsoft |
3261 | | * Reference Software v1.6 updates. |
3262 | | * |
3263 | | * Revision 1.40 2009/04/13 12:00:00 microsoft |
3264 | | * Reference Software v1.5 updates. |
3265 | | * |
3266 | | * Revision 1.39 2008/03/24 18:06:56 steve |
3267 | | * Imrpove DEBUG messages around quantization. |
3268 | | * |
3269 | | * Revision 1.38 2008/03/21 18:30:21 steve |
3270 | | * Get HP Prediction right for YUVK (CMYK) |
3271 | | * |
3272 | | * Revision 1.37 2008/03/20 22:39:41 steve |
3273 | | * Fix various debug prints of QP data. |
3274 | | * |
3275 | | * Revision 1.36 2008/03/17 21:48:55 steve |
3276 | | * CMYK decode support |
3277 | | * |
3278 | | * Revision 1.35 2008/03/13 21:23:27 steve |
3279 | | * Add pipeline step for YUV420. |
3280 | | * |
3281 | | * Revision 1.34 2008/03/13 00:07:22 steve |
3282 | | * Encode HP of YUV422 |
3283 | | * |
3284 | | * Revision 1.33 2008/03/06 22:47:39 steve |
3285 | | * Clean up parsing/encoding of QP counts |
3286 | | * |
3287 | | * Revision 1.32 2008/03/06 02:05:48 steve |
3288 | | * Distributed quantization |
3289 | | * |
3290 | | * Revision 1.31 2008/03/05 04:04:30 steve |
3291 | | * Clarify constraints on USE_DC_QP in image plane header. |
3292 | | * |
3293 | | * Revision 1.30 2008/03/05 00:31:17 steve |
3294 | | * Handle UNIFORM/IMAGEPLANE_UNIFORM compression. |
3295 | | * |
3296 | | * Revision 1.29 2008/02/28 18:50:31 steve |
3297 | | * Portability fixes. |
3298 | | * |
3299 | | * Revision 1.28 2008/02/26 23:52:44 steve |
3300 | | * Remove ident for MS compilers. |
3301 | | * |
3302 | | * Revision 1.27 2008/02/23 01:55:51 steve |
3303 | | * CBP REFINE is more complex when CHR is involved. |
3304 | | * |
3305 | | * Revision 1.26 2008/02/22 23:01:33 steve |
3306 | | * Compress macroblock HP CBP packets. |
3307 | | * |
3308 | | * Revision 1.25 2008/01/01 01:07:26 steve |
3309 | | * Add missing HP prediction. |
3310 | | * |
3311 | | * Revision 1.24 2007/12/30 00:16:00 steve |
3312 | | * Add encoding of HP values. |
3313 | | * |
3314 | | * Revision 1.23 2007/12/13 18:01:09 steve |
3315 | | * Stubs for HP encoding. |
3316 | | * |
3317 | | * Revision 1.22 2007/12/12 00:37:33 steve |
3318 | | * Cleanup some debug messages. |
3319 | | * |
3320 | | * Revision 1.21 2007/12/06 23:12:41 steve |
3321 | | * Stubs for LP encode operations. |
3322 | | * |
3323 | | * Revision 1.20 2007/12/06 17:54:09 steve |
3324 | | * UpdateModelMB dump details. |
3325 | | * |
3326 | | * Revision 1.19 2007/11/26 01:47:15 steve |
3327 | | * Add copyright notices per MS request. |
3328 | | * |
3329 | | * Revision 1.18 2007/11/21 00:34:30 steve |
3330 | | * Rework spatial mode tile macroblock shuffling. |
3331 | | * |
3332 | | * Revision 1.17 2007/11/20 00:05:47 steve |
3333 | | * Complex handling of mbhp_pred_mode in frequency dmoe. |
3334 | | * |
3335 | | * Revision 1.16 2007/11/19 18:22:34 steve |
3336 | | * Skip ESCaped FLEXBITS tiles. |
3337 | | * |
3338 | | * Revision 1.15 2007/11/16 20:03:57 steve |
3339 | | * Store MB Quant, not qp_index. |
3340 | | * |
3341 | | * Revision 1.14 2007/11/16 17:33:24 steve |
3342 | | * Do HP prediction after FLEXBITS frequency tiles. |
3343 | | * |
3344 | | * Revision 1.13 2007/11/16 00:29:05 steve |
3345 | | * Support FREQUENCY mode HP and FLEXBITS |
3346 | | * |
3347 | | * Revision 1.12 2007/11/14 23:56:17 steve |
3348 | | * Fix TILE ordering, using seeks, for FREQUENCY mode. |
3349 | | * |
3350 | | * Revision 1.11 2007/11/14 00:17:26 steve |
3351 | | * Fix parsing of QP indices. |
3352 | | * |
3353 | | * Revision 1.10 2007/11/13 03:27:23 steve |
3354 | | * Add Frequency mode LP support. |
3355 | | * |
3356 | | * Revision 1.9 2007/11/12 23:21:55 steve |
3357 | | * Infrastructure for frequency mode ordering. |
3358 | | * |
3359 | | * Revision 1.8 2007/11/08 19:38:38 steve |
3360 | | * Get stub DCONLY compression to work. |
3361 | | * |
3362 | | * Revision 1.7 2007/11/01 21:09:40 steve |
3363 | | * Multiple rows of tiles. |
3364 | | * |
3365 | | * Revision 1.6 2007/10/30 21:32:46 steve |
3366 | | * Support for multiple tile columns. |
3367 | | * |
3368 | | * Revision 1.5 2007/09/08 01:01:43 steve |
3369 | | * YUV444 color parses properly. |
3370 | | * |
3371 | | * Revision 1.4 2007/07/30 23:09:57 steve |
3372 | | * Interleave FLEXBITS within HP block. |
3373 | | * |
3374 | | * Revision 1.3 2007/07/24 20:56:28 steve |
3375 | | * Fix HP prediction and model bits calculations. |
3376 | | * |
3377 | | * Revision 1.2 2007/06/07 18:53:06 steve |
3378 | | * Parse HP coeffs that are all 0. |
3379 | | * |
3380 | | * Revision 1.1 2007/06/06 17:19:12 steve |
3381 | | * Introduce to CVS. |
3382 | | * |
3383 | | */ |
3384 | | |