Coverage Report

Created: 2026-04-01 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/jpegxr/r_tile_spatial.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_tile_spatial.c,v 1.53 2008/03/20 22:39:41 steve Exp $")
44
#else
45
#ident "$Id: r_tile_spatial.c,v 1.53 2008/03/20 22:39:41 steve Exp $"
46
#endif
47
48
# include "jxr_priv.h"
49
# include <assert.h>
50
51
52
53
/*
54
* Process a single spatial time. The tx/ty is the coordintes of the
55
* tile in units of tiles. tx=0 for the first time, tx=1 for the
56
* second, and so forth.
57
*/
58
int _jxr_r_TILE_SPATIAL(jxr_image_t image, struct rbitstream*str,
59
                        unsigned tx, unsigned ty)
60
0
{
61
0
    int rc = 0;
62
0
    unsigned mx, my, plane_idx;
63
0
    unsigned char s0, s1, s2, s3;
64
0
    unsigned mb_height;
65
0
    unsigned mb_width;
66
67
0
    DEBUG("START TILE_SPATIAL at tile=[%u %u] bitpos=%zu\n", tx, ty, _jxr_rbitstream_bitpos(str));
68
69
    /* TILE_STARTCODE == 1 */
70
0
    s0 = _jxr_rbitstream_uint8(str); /* 0x00 */
71
0
    s1 = _jxr_rbitstream_uint8(str); /* 0x00 */
72
0
    s2 = _jxr_rbitstream_uint8(str); /* 0x01 */
73
0
    s3 = _jxr_rbitstream_uint8(str); /* reserved */
74
0
    DEBUG(" TILE_STARTCODE == %02x %02x %02x (reserved: %02x)\n", s0, s1, s2, s3);
75
76
0
    image->trim_flexbits = 0;
77
0
    if (TRIM_FLEXBITS_FLAG(image)) {
78
0
        image->trim_flexbits =_jxr_rbitstream_uint4(str);
79
0
        DEBUG(" TRIM_FLEXBITS = %u\n", image->trim_flexbits);
80
0
    }
81
82
    /* Read the tile header (which includes sub-headers for
83
    all the major passes). */
84
85
0
    _jxr_r_TILE_HEADER_DC(image, str, 0, tx, ty);
86
0
    if (image->bands_present != 3 /* DCONLY */) {
87
0
        _jxr_r_TILE_HEADER_LOWPASS(image, str, 0, tx, ty);
88
89
0
        if (image->bands_present != 2 /* NO_HIGHPASS */) {
90
0
            _jxr_r_TILE_HEADER_HIGHPASS(image, str, 0, tx, ty);
91
0
        }
92
0
    }
93
94
    /* If the alpha channel is present, then run another set of
95
    headers for the alpha channel. */
96
0
    if (ALPHACHANNEL_FLAG(image)) {
97
0
        _jxr_r_TILE_HEADER_DC(image->alpha, str, 1, tx, ty);
98
0
        if (image->bands_present != 3 /* DCONLY */) {
99
0
            _jxr_r_TILE_HEADER_LOWPASS(image->alpha, str, 1, tx, ty);
100
101
0
            if (image->bands_present != 2 /* NO_HIGHPASS */) {
102
0
                _jxr_r_TILE_HEADER_HIGHPASS(image->alpha, str, 1, tx, ty);
103
0
            }
104
0
        }
105
0
    }
106
107
108
    /* Now form and write out all the compressed data for the
109
    tile. This involves scanning the macroblocks, and the
110
    blocks within the macroblocks, generating bits as we go. */
111
112
0
    mb_height = EXTENDED_HEIGHT_BLOCKS(image);
113
0
    mb_width = EXTENDED_WIDTH_BLOCKS(image);
114
115
0
    if (TILING_FLAG(image)) {
116
0
        mb_height = image->tile_row_height[ty];
117
0
        mb_width = image->tile_column_width[tx];
118
0
    }
119
120
0
    for (my = 0 ; my < mb_height ; my += 1) {
121
0
        if (ALPHACHANNEL_FLAG(image))
122
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, my);
123
0
        _jxr_rflush_mb_strip(image, tx, ty, my);
124
125
0
        for (mx = 0 ; mx < mb_width ; mx += 1) {
126
0
        for(plane_idx = 0U; plane_idx < (ALPHACHANNEL_FLAG(image) ? 2U : 1U); plane_idx ++){
127
0
            int ch;
128
129
            /* There is one LP_QP_INDEX per macroblock (if any)
130
            and that value applies to all the channels.
131
            Same for HP_QP_INDEX. There is no DC_QP_INDEX
132
            because DC QP values are per-tile, not per MB. */
133
0
            int qp_index_lp = 0;
134
0
            int qp_index_hp = 0;
135
0
            jxr_image_t plane = (plane_idx == 0 ? image : image->alpha);
136
137
0
            if (plane->bands_present!=3) {
138
0
                if (plane->num_lp_qps>1 && !plane->lp_use_dc_qp) {
139
0
                    qp_index_lp = _jxr_DECODE_QP_INDEX(str, plane->num_lp_qps);
140
0
                    DEBUG(" DECODE_QP_INDEX(%d) --> %u (LP)\n", plane->num_lp_qps, qp_index_lp);
141
0
                }
142
0
                qp_index_hp = 0;
143
0
                if (plane->bands_present!=2 && plane->num_hp_qps>1) {
144
0
                    if (!plane->hp_use_lp_qp) {
145
0
                        qp_index_hp = _jxr_DECODE_QP_INDEX(str, plane->num_hp_qps);
146
0
                        DEBUG(" DECODE_QP_INDEX(%d) --> %u (HP)\n", plane->num_hp_qps, qp_index_hp);
147
0
                    }
148
0
                    else {
149
0
                        qp_index_hp = qp_index_lp;
150
0
                    }
151
0
                }
152
0
            }
153
0
            for (ch = 0 ; ch < plane->num_channels ; ch += 1) {
154
                /* Save the LP Quant *INDEX* here. Prediction needs it. */
155
0
                MACROBLK_CUR_LP_QUANT(plane,ch,tx,mx) = qp_index_lp;
156
0
                DEBUG(" LP_QUANT INDEX for tx=%u ty=%u ch=%u MBx=%d is %d\n", tx, ty, ch, mx,
157
0
                    MACROBLK_CUR_LP_QUANT(plane,ch,tx,mx));
158
0
                MACROBLK_CUR_HP_QUANT(plane,ch,tx,mx) = plane->hp_quant_ch[ch][qp_index_hp];
159
0
                DEBUG(" HP_QUANT VALUE for tx=%u ty=%u ch=%u MBx=%d is %d\n", tx, ty, ch, mx,
160
0
                    MACROBLK_CUR_HP_QUANT(plane,ch,tx,mx));
161
0
            }
162
163
0
            _jxr_r_MB_DC(plane, str, plane_idx, tx, ty, mx, my);
164
0
            if (plane->bands_present != 3 /* DCONLY */) {
165
0
                _jxr_r_MB_LP(plane, str, plane_idx, tx, ty, mx, my);
166
0
                _jxr_complete_cur_dclp(plane, tx, mx, my);
167
0
                if (plane->bands_present != 2 /* NOHIGHPASS */) {
168
0
                    rc = _jxr_r_MB_CBP(plane, str, plane_idx, tx, ty, mx, my);
169
0
                    if (rc < 0) {
170
0
                        DEBUG("r_MB_CBP returned ERROR rc=%d\n", rc);
171
0
                        return rc;
172
0
                    }
173
0
                    rc = _jxr_r_MB_HP(plane, str, plane_idx, tx, ty, mx, my);
174
0
                    if (rc < 0) {
175
0
                        DEBUG("r_MB_HP returned ERROR rc=%d\n", rc);
176
0
                        return rc;
177
0
                    }
178
0
                }
179
0
            } else {
180
0
                _jxr_complete_cur_dclp(plane, tx, mx, my);
181
0
            }
182
0
        }
183
0
    }
184
0
    }
185
186
    /* Flush the remaining strips to output. */
187
0
    if (tx+1 == image->tile_columns && ty+1 == image->tile_rows) {
188
0
        DEBUG(" Cleanup flush after last tile (tx=%d, ty=%d)\n", tx, ty);
189
0
        if (ALPHACHANNEL_FLAG(image))
190
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, mb_height);
191
0
        _jxr_rflush_mb_strip(image, tx, ty, mb_height);
192
193
0
        if (ALPHACHANNEL_FLAG(image))
194
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, mb_height+1);
195
0
        _jxr_rflush_mb_strip(image, tx, ty, mb_height+1);
196
197
0
        if (ALPHACHANNEL_FLAG(image))
198
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, mb_height+2);
199
0
        _jxr_rflush_mb_strip(image, tx, ty, mb_height+2);
200
201
0
        if (ALPHACHANNEL_FLAG(image))
202
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, mb_height+3);
203
0
        _jxr_rflush_mb_strip(image, tx, ty, mb_height+3);
204
0
    }
205
0
    _jxr_rbitstream_syncbyte(str);
206
0
    DEBUG("END TILE_SPATIAL\n");
207
0
    return 0;
208
0
}
209
210
/*
211
* $Log: r_tile_spatial.c,v $
212
* Revision 1.55 2009/05/29 12:00:00 microsoft
213
* Reference Software v1.6 updates.
214
*
215
* Revision 1.54 2009/04/13 12:00:00 microsoft
216
* Reference Software v1.5 updates.
217
*
218
* Revision 1.53 2008/03/20 22:39:41 steve
219
* Fix various debug prints of QP data.
220
*
221
* Revision 1.52 2008/03/20 18:11:25 steve
222
* Handle case of NumLPQP==1 and NumHPQPS>1
223
*
224
* Revision 1.51 2008/03/18 21:09:12 steve
225
* Fix distributed color prediction.
226
*
227
* Revision 1.50 2008/03/07 19:00:52 steve
228
* Improved comments.
229
*
230
* Revision 1.49 2008/03/06 22:47:39 steve
231
* Clean up parsing/encoding of QP counts
232
*
233
* Revision 1.48 2008/03/06 02:05:48 steve
234
* Distributed quantization
235
*
236
* Revision 1.47 2008/02/26 23:52:44 steve
237
* Remove ident for MS compilers.
238
*
239
* Revision 1.46 2007/11/26 01:47:15 steve
240
* Add copyright notices per MS request.
241
*
242
* Revision 1.45 2007/11/21 23:26:14 steve
243
* make all strip buffers store MB data.
244
*
245
* Revision 1.44 2007/11/20 17:08:02 steve
246
* Fix SPATIAL processing of QUANT values for color.
247
*
248
* Revision 1.43 2007/11/16 21:33:48 steve
249
* Store MB Quant, not qp_index.
250
*
251
* Revision 1.42 2007/11/16 20:03:57 steve
252
* Store MB Quant, not qp_index.
253
*
254
* Revision 1.41 2007/11/16 00:29:06 steve
255
* Support FREQUENCY mode HP and FLEXBITS
256
*
257
* Revision 1.40 2007/11/14 23:56:17 steve
258
* Fix TILE ordering, using seeks, for FREQUENCY mode.
259
*
260
* Revision 1.39 2007/11/14 00:17:27 steve
261
* Fix parsing of QP indices.
262
*
263
* Revision 1.38 2007/11/13 03:27:24 steve
264
* Add Frequency mode LP support.
265
*
266
* Revision 1.37 2007/11/12 23:21:55 steve
267
* Infrastructure for frequency mode ordering.
268
*
269
* Revision 1.36 2007/11/08 19:38:38 steve
270
* Get stub DCONLY compression to work.
271
*
272
* Revision 1.35 2007/11/01 21:09:40 steve
273
* Multiple rows of tiles.
274
*
275
* Revision 1.34 2007/10/31 21:20:54 steve
276
* Init, not Adapt, on tile boundaries.
277
*
278
* Revision 1.33 2007/10/30 21:32:46 steve
279
* Support for multiple tile columns.
280
*
281
* Revision 1.32 2007/10/19 16:20:21 steve
282
* Parse YUV420 HP
283
*
284
* Revision 1.31 2007/10/04 23:03:26 steve
285
* HP blocks uf YUV42X chroma are not shuffled.
286
*
287
* Revision 1.30 2007/10/04 00:30:47 steve
288
* Fix prediction of HP CBP for YUV422 data.
289
*
290
* Revision 1.29 2007/10/02 20:36:29 steve
291
* Fix YUV42X DC prediction, add YUV42X HP parsing.
292
*
293
* Revision 1.28 2007/10/01 20:39:34 steve
294
* Add support for YUV422 LP bands.
295
*
296
* Revision 1.27 2007/09/18 17:00:50 steve
297
* Fix bad calculation of lap_mean for chroma.
298
*
299
* Revision 1.26 2007/09/13 23:12:34 steve
300
* Support color HP bands.
301
*
302
* Revision 1.25 2007/09/12 01:09:24 steve
303
* Dump the TRIM_FLEXBITS value.
304
*
305
* Revision 1.24 2007/09/11 01:06:12 steve
306
* Forgot to properly save LP data.
307
*
308
* Revision 1.23 2007/09/11 00:40:06 steve
309
* Fix rendering of chroma to add the missing *2.
310
* Fix handling of the chroma LP samples
311
* Parse some of the HP CBP data in chroma.
312
*
313
* Revision 1.22 2007/09/10 23:42:00 steve
314
* Fix LP processing steps when color involved.
315
*
316
* Revision 1.21 2007/09/08 01:01:44 steve
317
* YUV444 color parses properly.
318
*
319
* Revision 1.20 2007/09/04 22:48:09 steve
320
* Fix calculation of flex bits on 0 coefficients.
321
*
322
* Revision 1.19 2007/09/04 19:10:46 steve
323
* Finish level1 overlap filtering.
324
*
325
* Revision 1.18 2007/08/31 23:31:49 steve
326
* Initialize CBP VLC tables at the right time.
327
*
328
* Revision 1.17 2007/08/31 23:20:57 steve
329
* Dump MB_CBP details.
330
*
331
* Revision 1.16 2007/08/15 01:54:11 steve
332
* Add level2 filter to decoder.
333
*
334
* Revision 1.15 2007/08/13 22:24:43 steve
335
* Fix Reset Context of absLevelInd.
336
*
337
* Revision 1.14 2007/07/31 15:27:19 steve
338
* Get transpose of FLEXBITS right.
339
*
340
* Revision 1.13 2007/07/30 23:09:57 steve
341
* Interleave FLEXBITS within HP block.
342
*
343
* Revision 1.12 2007/07/24 20:56:28 steve
344
* Fix HP prediction and model bits calculations.
345
*
346
* Revision 1.11 2007/07/21 00:25:48 steve
347
* snapshot 2007 07 20
348
*
349
* Revision 1.10 2007/07/12 22:48:17 steve
350
* Decode FLEXBITS
351
*
352
* Revision 1.9 2007/07/11 00:53:36 steve
353
* HP adaptation and precition corrections.
354
*
355
* Revision 1.8 2007/07/06 23:18:41 steve
356
* calculate and propagate HP band predictions.
357
*
358
* Revision 1.7 2007/07/05 20:19:13 steve
359
* Fix accumulation of HP CBP, and add HP predictions.
360
*
361
* Revision 1.6 2007/07/03 20:45:11 steve
362
* Parse and place HP data.
363
*
364
* Revision 1.5 2007/06/28 20:03:11 steve
365
* LP processing seems to be OK now.
366
*
367
* Revision 1.4 2007/06/21 17:31:22 steve
368
* Successfully parse LP components.
369
*
370
* Revision 1.3 2007/06/11 20:00:09 steve
371
* Parse FLEXBITS
372
*
373
* Revision 1.2 2007/06/07 18:53:06 steve
374
* Parse HP coeffs that are all 0.
375
*
376
* Revision 1.1 2007/06/06 17:19:12 steve
377
* Introduce to CVS.
378
*
379
*/
380