Coverage Report

Created: 2026-10-28 08:05

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
* This software module was originally contributed by Microsoft
4
* Corporation in the course of development of the
5
* ITU-T T.832 | ISO/IEC 29199-2 ("JPEG XR") format standard for
6
* reference purposes and its performance may not have been optimized.
7
*
8
* This software module is an implementation of one or more
9
* tools as specified by the JPEG XR standard.
10
*
11
* ITU/ISO/IEC give You a royalty-free, worldwide, non-exclusive
12
* copyright license to copy, distribute, and make derivative works
13
* of this software module or modifications thereof for use in
14
* products claiming conformance to the JPEG XR standard as
15
* specified by ITU-T T.832 | ISO/IEC 29199-2.
16
*
17
* ITU/ISO/IEC give users the same free license to this software
18
* module or modifications thereof for research purposes and further
19
* ITU/ISO/IEC standardization.
20
*
21
* Those intending to use this software module in products are advised
22
* that its use may infringe existing patents. ITU/ISO/IEC have no
23
* liability for use of this software module or modifications thereof.
24
*
25
* Copyright is not released for products that do not conform to
26
* to the JPEG XR standard as specified by ITU-T T.832 |
27
* ISO/IEC 29199-2.
28
*
29
******** Section to be removed when the standard is published ************
30
*
31
* Assurance that the contributed software module can be used
32
* (1) in the ITU-T "T.JXR" | ISO/IEC 29199 ("JPEG XR") standard once the
33
* standard has been adopted; and
34
* (2) to develop the JPEG XR standard:
35
*
36
* Microsoft Corporation and any subsequent contributors to the development
37
* of this software grant ITU/ISO/IEC all rights necessary to include
38
* the originally developed software module or modifications thereof in the
39
* JPEG XR standard and to permit ITU/ISO/IEC to offer such a royalty-free,
40
* worldwide, non-exclusive copyright license to copy, distribute, and make
41
* derivative works of this software module or modifications thereof for
42
* use in products claiming conformance to the JPEG XR standard as
43
* specified by ITU-T T.832 | ISO/IEC 29199-2, and to the extent that
44
* such originally developed software module or portions of it are included
45
* in an ITU/ISO/IEC standard. To the extent that the original contributors
46
* may own patent rights that would be required to make, use, or sell the
47
* originally developed software module or portions thereof included in the
48
* ITU/ISO/IEC standard in a conforming product, the contributors will
49
* assure ITU/ISO/IEC that they are willing to negotiate licenses under
50
* reasonable and non-discriminatory terms and conditions with
51
* applicants throughout the world and in accordance with their patent
52
* rights declarations made to ITU/ISO/IEC (if any).
53
*
54
* Microsoft, any subsequent contributors, and ITU/ISO/IEC additionally
55
* gives You a free license to this software module or modifications
56
* thereof for the sole purpose of developing the JPEG XR standard.
57
*
58
******** end of section to be removed when the standard is published *****
59
*
60
* Microsoft Corporation retains full right to modify and use the code
61
* for its own purpose, to assign or donate the code to a third party,
62
* and to inhibit third parties from using the code for products that
63
* do not conform to the JPEG XR standard as specified by ITU-T T.832 |
64
* ISO/IEC 29199-2.
65
*
66
* This copyright notice must be included in all copies or derivative
67
* works.
68
*
69
* Copyright (c) ITU-T/ISO/IEC 2008, 2009.
70
**********************************************************************/
71
72
#ifdef _MSC_VER
73
#pragma comment (user,"$Id: r_tile_spatial.c,v 1.10 2011-11-08 20:17:29 thor Exp $")
74
#endif
75
76
# include "jxr_priv.h"
77
# include <assert.h>
78
79
80
81
/*
82
* Process a single spatial time. The tx/ty is the coordintes of the
83
* tile in units of tiles. tx=0 for the first time, tx=1 for the
84
* second, and so forth.
85
*/
86
int _jxr_r_TILE_SPATIAL(jxr_image_t image, struct rbitstream*str,
87
                        unsigned tx, unsigned ty)
88
0
{
89
0
    int rc = 0;
90
0
    unsigned mx, my, plane_idx;
91
0
    unsigned char s0, s1, s2, s3;
92
0
    unsigned mb_height;
93
0
    unsigned mb_width;
94
95
0
    DODEBUG("START TILE_SPATIAL at tile=[%u %u] bitpos=%zu\n", tx, ty, _jxr_rbitstream_bitpos(str));
96
97
    /* TILE_STARTCODE == 1 */
98
0
    s0 = _jxr_rbitstream_uint8(str); /* 0x00 */
99
0
    s1 = _jxr_rbitstream_uint8(str); /* 0x00 */
100
0
    s2 = _jxr_rbitstream_uint8(str); /* 0x01 */
101
0
    s3 = _jxr_rbitstream_uint8(str); /* reserved */
102
0
    DODEBUG(" TILE_STARTCODE == %02x %02x %02x (reserved: %02x)\n", s0, s1, s2, s3);
103
0
    if (s0 != 0x00 || s1 != 0x00 || s2 != 0x01) {
104
0
      DODEBUG(" TILE_LOWPASS ERROR: Invalid marker.\n");
105
0
      return JXR_EC_ERROR;
106
      /* FIX THOR: Invalid TILE_STARTCODE detected */
107
0
    }
108
0
    (void)s3;
109
110
0
    image->trim_flexbits = 0;
111
0
    if (TRIM_FLEXBITS_FLAG(image)) {
112
0
        image->trim_flexbits =_jxr_rbitstream_uint4(str);
113
0
        DODEBUG(" TRIM_FLEXBITS = %u\n", image->trim_flexbits);
114
0
    }
115
116
    /* Read the tile header (which includes sub-headers for
117
    all the major passes). */
118
119
0
    _jxr_r_TILE_HEADER_DC(image, str, 0, tx, ty);
120
0
    if (image->bands_present != 3 /* DCONLY */) {
121
0
        _jxr_r_TILE_HEADER_LOWPASS(image, str, 0, tx, ty);
122
123
0
        if (image->bands_present != 2 /* NO_HIGHPASS */) {
124
0
            _jxr_r_TILE_HEADER_HIGHPASS(image, str, 0, tx, ty);
125
0
        }
126
0
    }
127
128
    /* If the alpha channel is present, then run another set of
129
    headers for the alpha channel. */
130
0
    if (ALPHACHANNEL_FLAG(image)) {
131
0
        _jxr_r_TILE_HEADER_DC(image->alpha, str, 1, tx, ty);
132
0
        if (image->bands_present != 3 /* DCONLY */) {
133
0
            _jxr_r_TILE_HEADER_LOWPASS(image->alpha, str, 1, tx, ty);
134
135
0
            if (image->bands_present != 2 /* NO_HIGHPASS */) {
136
0
                _jxr_r_TILE_HEADER_HIGHPASS(image->alpha, str, 1, tx, ty);
137
0
            }
138
0
        }
139
0
    }
140
141
142
    /* Now form and write out all the compressed data for the
143
    tile. This involves scanning the macroblocks, and the
144
    blocks within the macroblocks, generating bits as we go. */
145
146
0
    mb_height = EXTENDED_HEIGHT_BLOCKS(image);
147
0
    mb_width = EXTENDED_WIDTH_BLOCKS(image);
148
149
0
    if (TILING_FLAG(image)) {
150
0
        mb_height = image->tile_row_height[ty];
151
0
        mb_width = image->tile_column_width[tx];
152
0
    }
153
154
0
    for (my = 0 ; my < mb_height ; my += 1) {
155
0
        if (ALPHACHANNEL_FLAG(image))
156
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, my);
157
0
        _jxr_rflush_mb_strip(image, tx, ty, my);
158
159
0
        for (mx = 0 ; mx < mb_width ; mx += 1) {
160
0
        for(plane_idx = 0U; plane_idx < (ALPHACHANNEL_FLAG(image) ? 2U : 1U); plane_idx ++){
161
0
            int ch;
162
163
            /* There is one LP_QP_INDEX per macroblock (if any)
164
            and that value applies to all the channels.
165
            Same for HP_QP_INDEX. There is no DC_QP_INDEX
166
            because DC QP values are per-tile, not per MB. */
167
0
            int qp_index_lp = 0;
168
0
            int qp_index_hp = 0;
169
0
            jxr_image_t plane = (plane_idx == 0 ? image : image->alpha);
170
171
0
            if (plane->bands_present!=3) {
172
0
                if (plane->num_lp_qps>1 && !plane->lp_use_dc_qp) {
173
0
                    qp_index_lp = _jxr_DECODE_QP_INDEX(str, plane->num_lp_qps);
174
0
                    DODEBUG(" DECODE_QP_INDEX(%d) --> %u (LP)\n", plane->num_lp_qps, qp_index_lp);
175
0
                }
176
0
                qp_index_hp = 0;
177
0
                if (plane->bands_present!=2 && plane->num_hp_qps>1) {
178
0
                    if (!plane->hp_use_lp_qp) {
179
0
                        qp_index_hp = _jxr_DECODE_QP_INDEX(str, plane->num_hp_qps);
180
0
                        DODEBUG(" DECODE_QP_INDEX(%d) --> %u (HP)\n", plane->num_hp_qps, qp_index_hp);
181
0
                    }
182
0
                    else {
183
0
                        qp_index_hp = qp_index_lp;
184
0
                    }
185
0
                }
186
0
            }
187
0
            for (ch = 0 ; ch < plane->num_channels ; ch += 1) {
188
                /* Save the LP Quant *INDEX* here. Prediction needs it. */
189
0
                MACROBLK_CUR_LP_QUANT(plane,ch,tx,mx) = qp_index_lp;
190
0
                DODEBUG(" LP_QUANT INDEX for tx=%u ty=%u ch=%u MBx=%d is %d\n", tx, ty, ch, mx,
191
0
                    MACROBLK_CUR_LP_QUANT(plane,ch,tx,mx));
192
0
                MACROBLK_CUR_HP_QUANT(plane,ch,tx,mx) = plane->hp_quant_ch[ch][qp_index_hp];
193
0
                DODEBUG(" HP_QUANT VALUE for tx=%u ty=%u ch=%u MBx=%d is %d\n", tx, ty, ch, mx,
194
0
                    MACROBLK_CUR_HP_QUANT(plane,ch,tx,mx));
195
0
            }
196
197
0
            _jxr_r_MB_DC(plane, str, plane_idx, tx, ty, mx, my);
198
0
            if (plane->bands_present != 3 /* DCONLY */) {
199
0
                _jxr_r_MB_LP(plane, str, plane_idx, tx, ty, mx, my);
200
0
                _jxr_complete_cur_dclp(plane, tx, mx, my);
201
0
                if (plane->bands_present != 2 /* NOHIGHPASS */) {
202
0
                    rc = _jxr_r_MB_CBP(plane, str, plane_idx, tx, ty, mx, my);
203
0
                    if (rc < 0) {
204
0
                        DODEBUG("r_MB_CBP returned ERROR rc=%d\n", rc);
205
0
                        return rc;
206
0
                    }
207
0
                    rc = _jxr_r_MB_HP(plane, str, plane_idx, tx, ty, mx, my);
208
0
                    if (rc < 0) {
209
0
                        DODEBUG("r_MB_HP returned ERROR rc=%d\n", rc);
210
0
                        return rc;
211
0
                    }
212
0
                }
213
0
            } else {
214
0
                _jxr_complete_cur_dclp(plane, tx, mx, my);
215
0
            }
216
0
        }
217
0
    }
218
0
    }
219
220
    /* Flush the remaining strips to output. */
221
0
    if (tx+1 == image->tile_columns && ty+1 == image->tile_rows) {
222
0
        DODEBUG(" Cleanup flush after last tile (tx=%d, ty=%d)\n", tx, ty);
223
0
        if (ALPHACHANNEL_FLAG(image))
224
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, mb_height);
225
0
        _jxr_rflush_mb_strip(image, tx, ty, mb_height);
226
227
0
        if (ALPHACHANNEL_FLAG(image))
228
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, mb_height+1);
229
0
        _jxr_rflush_mb_strip(image, tx, ty, mb_height+1);
230
231
0
        if (ALPHACHANNEL_FLAG(image))
232
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, mb_height+2);
233
0
        _jxr_rflush_mb_strip(image, tx, ty, mb_height+2);
234
235
0
        if (ALPHACHANNEL_FLAG(image))
236
0
            _jxr_rflush_mb_strip(image->alpha, tx, ty, mb_height+3);
237
0
        _jxr_rflush_mb_strip(image, tx, ty, mb_height+3);
238
0
    }
239
0
    _jxr_rbitstream_syncbyte(str);
240
0
    DODEBUG("END TILE_SPATIAL\n");
241
0
    return 0;
242
0
}
243
244
/*
245
** Added by thor April 2nd 2010: Process one stripe at a time.
246
*/
247
int _jxr_r_TILE_SPATIAL_stripe(jxr_image_t image, struct rbitstream*str,
248
                               unsigned tx, unsigned ty)
249
0
{
250
0
  int rc = 0;
251
0
  unsigned char s0, s1, s2, s3;
252
253
0
  if (image->spatial_buffered_flag == 0) {
254
    /* Header is not yet parsed off. Do now.
255
     */
256
0
    DODEBUG("START TILE_SPATIAL at tile=[%u %u] bitpos=%zu\n", tx, ty, _jxr_rbitstream_bitpos(str));
257
258
0
    if(INDEXTABLE_PRESENT_FLAG(image)) {
259
0
      _jxr_rbitstream_seek(str, image->tile_index_table[image->tile_columns * ty + tx]);
260
0
    }
261
    /* TILE_STARTCODE == 1 */
262
0
    s0 = _jxr_rbitstream_uint8(str); /* 0x00 */
263
0
    s1 = _jxr_rbitstream_uint8(str); /* 0x00 */
264
0
    s2 = _jxr_rbitstream_uint8(str); /* 0x01 */
265
0
    s3 = _jxr_rbitstream_uint8(str); /* reserved */
266
0
    DODEBUG(" TILE_STARTCODE == %02x %02x %02x (reserved: %02x)\n", s0, s1, s2, s3);
267
0
    if (s0 != 0x00 || s1 != 0x00 || s2 != 0x01) {
268
0
      DODEBUG(" TILE_LOWPASS ERROR: Invalid marker.\n");
269
0
      return JXR_EC_ERROR;
270
      /* FIX THOR: Invalid TILE_STARTCODE detected */
271
0
    }
272
0
    (void)s3;
273
274
0
    image->trim_flexbits = 0;
275
0
    if (TRIM_FLEXBITS_FLAG(image)) {
276
0
      image->trim_flexbits =_jxr_rbitstream_uint4(str);
277
0
      DODEBUG(" TRIM_FLEXBITS = %u\n", image->trim_flexbits);
278
0
    }
279
280
    /* Read the tile header (which includes sub-headers for
281
       all the major passes). */
282
283
0
    _jxr_r_TILE_HEADER_DC(image, str, 0, tx, ty);
284
0
    if (image->bands_present != 3 /* DCONLY */) {
285
0
      _jxr_r_TILE_HEADER_LOWPASS(image, str, 0, tx, ty);
286
287
0
      if (image->bands_present != 2 /* NO_HIGHPASS */) {
288
0
        _jxr_r_TILE_HEADER_HIGHPASS(image, str, 0, tx, ty);
289
0
      }
290
0
    }
291
292
    /* If the alpha channel is present, then run another set of
293
    headers for the alpha channel. */
294
0
    if (ALPHACHANNEL_FLAG(image)) {
295
0
      _jxr_r_TILE_HEADER_DC(image->alpha, str, 1, tx, ty);
296
0
      if (image->bands_present != 3 /* DCONLY */) {
297
0
        _jxr_r_TILE_HEADER_LOWPASS(image->alpha, str, 1, tx, ty);
298
299
0
        if (image->bands_present != 2 /* NO_HIGHPASS */) {
300
0
          _jxr_r_TILE_HEADER_HIGHPASS(image->alpha, str, 1, tx, ty);
301
0
        }
302
0
      }
303
0
    }
304
305
306
    /* Now form and write out all the compressed data for the
307
    tile. This involves scanning the macroblocks, and the
308
    blocks within the macroblocks, generating bits as we go. */
309
0
    {
310
0
      unsigned mb_height = EXTENDED_HEIGHT_BLOCKS(image);
311
0
      unsigned mb_width = EXTENDED_WIDTH_BLOCKS(image);
312
313
0
      if (TILING_FLAG(image)) {
314
0
        mb_height = image->tile_row_height[ty];
315
0
        mb_width = image->tile_column_width[tx];
316
0
      }
317
318
0
      image->spatial_mb_height = mb_height;
319
0
      image->spatial_mb_width  = mb_width;
320
0
    }
321
    /*
322
    ** Done with the header. Initialize for the loop below.
323
    */
324
0
    image->spatial_buffered_flag = 1;
325
0
    image->stripe_my             = 0;
326
0
    image->cleanup_state         = 0;
327
0
    image->output_sent           = 0;
328
    // runs into the following.
329
0
  }
330
331
0
  switch(image->cleanup_state) {
332
0
  case 0:
333
0
    do {
334
0
      unsigned mx, plane_idx, my = image->stripe_my;
335
0
      unsigned mb_width = image->spatial_mb_width;
336
      /*
337
        for (my = 0 ; my < mb_height ; my += 1) {
338
      */
339
0
      if (ALPHACHANNEL_FLAG(image))
340
0
        _jxr_rflush_mb_strip(image->alpha, tx, ty, my);
341
0
      _jxr_rflush_mb_strip(image, tx, ty, my);
342
343
0
      for (mx = 0 ; mx < mb_width ; mx += 1) {
344
0
        for(plane_idx = 0U; plane_idx < (ALPHACHANNEL_FLAG(image) ? 2U : 1U); plane_idx ++){
345
0
          int ch;
346
347
          /* There is one LP_QP_INDEX per macroblock (if any)
348
             and that value applies to all the channels.
349
             Same for HP_QP_INDEX. There is no DC_QP_INDEX
350
             because DC QP values are per-tile, not per MB. */
351
0
          int qp_index_lp = 0;
352
0
          int qp_index_hp = 0;
353
0
          jxr_image_t plane = (plane_idx == 0 ? image : image->alpha);
354
355
0
          if (plane->bands_present!=3) {
356
0
            if (plane->num_lp_qps>1 && !plane->lp_use_dc_qp) {
357
0
              qp_index_lp = _jxr_DECODE_QP_INDEX(str, plane->num_lp_qps);
358
0
              DODEBUG(" DECODE_QP_INDEX(%d) --> %u (LP)\n", plane->num_lp_qps, qp_index_lp);
359
0
            }
360
0
            qp_index_hp = 0;
361
0
            if (plane->bands_present!=2 && plane->num_hp_qps>1) {
362
0
              if (!plane->hp_use_lp_qp) {
363
0
                qp_index_hp = _jxr_DECODE_QP_INDEX(str, plane->num_hp_qps);
364
0
                DODEBUG(" DECODE_QP_INDEX(%d) --> %u (HP)\n", plane->num_hp_qps, qp_index_hp);
365
0
              }
366
0
              else {
367
0
                qp_index_hp = qp_index_lp;
368
0
              }
369
0
            }
370
0
          }
371
0
          for (ch = 0 ; ch < plane->num_channels ; ch += 1) {
372
            /* Save the LP Quant *INDEX* here. Prediction needs it. */
373
0
            MACROBLK_CUR_LP_QUANT(plane,ch,tx,mx) = qp_index_lp;
374
0
            DODEBUG(" LP_QUANT INDEX for tx=%u ty=%u ch=%u MBx=%d is %d\n", tx, ty, ch, mx,
375
0
                  MACROBLK_CUR_LP_QUANT(plane,ch,tx,mx));
376
0
            MACROBLK_CUR_HP_QUANT(plane,ch,tx,mx) = plane->hp_quant_ch[ch][qp_index_hp];
377
0
            DODEBUG(" HP_QUANT VALUE for tx=%u ty=%u ch=%u MBx=%d is %d\n", tx, ty, ch, mx,
378
0
                  MACROBLK_CUR_HP_QUANT(plane,ch,tx,mx));
379
0
          }
380
381
0
          _jxr_r_MB_DC(plane, str, plane_idx, tx, ty, mx, my);
382
0
          if (plane->bands_present != 3 /* DCONLY */) {
383
0
            _jxr_r_MB_LP(plane, str, plane_idx, tx, ty, mx, my);
384
0
            _jxr_complete_cur_dclp(plane, tx, mx, my);
385
0
            if (plane->bands_present != 2 /* NOHIGHPASS */) {
386
0
              rc = _jxr_r_MB_CBP(plane, str, plane_idx, tx, ty, mx, my);
387
0
              if (rc < 0) {
388
0
                DODEBUG("r_MB_CBP returned ERROR rc=%d\n", rc);
389
0
                return rc;
390
0
              }
391
0
              rc = _jxr_r_MB_HP(plane, str, plane_idx, tx, ty, mx, my);
392
0
              if (rc < 0) {
393
0
                DODEBUG("r_MB_HP returned ERROR rc=%d\n", rc);
394
0
                return rc;
395
0
              }
396
0
            }
397
0
          } else {
398
0
            _jxr_complete_cur_dclp(plane, tx, mx, my);
399
0
          }
400
0
        }
401
0
      }
402
      /*
403
      ** Advance to the next MB row.
404
      */
405
0
      image->stripe_my++;
406
      /*
407
      ** The flush happens only as part of the last tile, so continue iterating
408
      ** until that tile is hit.
409
      */
410
0
    } while (image->stripe_my < image->spatial_mb_height && image->output_sent == 0);
411
412
    /*
413
    ** End of tile reached? If so, get the sycn marker
414
    */
415
0
    if (image->stripe_my == image->spatial_mb_height)
416
0
      _jxr_rbitstream_syncbyte(str);
417
418
    /*
419
    ** If this is an intermediate tile and not the right edge, continue with the next tile.
420
    */
421
0
    if (tx+1 != image->tile_columns) {
422
0
      image->spatial_buffered_flag = 0;
423
0
      image->stripe_my             = 0;
424
0
      return 1;
425
0
    }
426
    /*
427
    ** Otherwise, a stripe is complete, go to the user.
428
    */
429
0
    if (image->stripe_my < image->spatial_mb_height && image->output_sent) {
430
0
      image->output_sent = 0;
431
0
      return 0; /* not yet done with this strip, but return to the user. */
432
0
    }
433
0
    assert(image->stripe_my == image->spatial_mb_height);
434
    /*
435
    ** Done with this tile, go to the next. We're done in case this is not the last tile,
436
    ** otherwise iterate on until we get to the last one.
437
    */
438
0
    if (tx+1 == image->tile_columns && ty+1 == image->tile_rows) {
439
      // Last tile row. Continue with cleanup.
440
0
      image->cleanup_state = 1;
441
0
    } else {
442
0
      image->spatial_buffered_flag = 0;
443
0
      image->stripe_my             = 0;
444
0
      return JXR_EC_DONE;
445
0
    }
446
0
    if (image->output_sent)
447
0
      return 0;
448
    // runs into the following
449
0
  case 1:
450
    /* Flush the remaining strips to output. */
451
0
    if (tx+1 == image->tile_columns && ty+1 == image->tile_rows) {
452
0
      DODEBUG(" Cleanup flush after last tile (tx=%d, ty=%d)\n", tx, ty);
453
0
      if (ALPHACHANNEL_FLAG(image))
454
0
        _jxr_rflush_mb_strip(image->alpha, tx, ty, image->spatial_mb_height);
455
0
      _jxr_rflush_mb_strip(image, tx, ty, image->spatial_mb_height);
456
0
      image->cleanup_state++;
457
0
      if (image->output_sent) {
458
0
        image->output_sent = 0;
459
0
        return 0;
460
0
      }
461
0
    } else {
462
0
      return 1;
463
0
    }
464
    // runs into the following
465
0
  case 2:
466
0
    if (tx+1 == image->tile_columns && ty+1 == image->tile_rows) {
467
0
      if (ALPHACHANNEL_FLAG(image))
468
0
        _jxr_rflush_mb_strip(image->alpha, tx, ty, image->spatial_mb_height+1);
469
0
      _jxr_rflush_mb_strip(image, tx, ty, image->spatial_mb_height+1);
470
0
      image->cleanup_state++;
471
0
      if (image->output_sent) {
472
0
        image->output_sent = 0;
473
0
        return 0;
474
0
      }
475
0
    } else {
476
0
      return 1;
477
0
    }
478
    // runs into the following
479
0
  case 3:
480
0
    if (tx+1 == image->tile_columns && ty+1 == image->tile_rows) {
481
0
      if (ALPHACHANNEL_FLAG(image))
482
0
        _jxr_rflush_mb_strip(image->alpha, tx, ty, image->spatial_mb_height+2);
483
0
      _jxr_rflush_mb_strip(image, tx, ty, image->spatial_mb_height+2);
484
0
      image->cleanup_state++;
485
0
      if (image->output_sent) {
486
0
        image->output_sent = 0;
487
0
        return 0;
488
0
      }
489
0
    } else {
490
0
      return 1;
491
0
    }
492
    // runs into the following
493
0
  case 4:
494
0
    if (tx+1 == image->tile_columns && ty+1 == image->tile_rows) {
495
0
      if (ALPHACHANNEL_FLAG(image))
496
0
        _jxr_rflush_mb_strip(image->alpha, tx, ty, image->spatial_mb_height+3);
497
0
      _jxr_rflush_mb_strip(image, tx, ty, image->spatial_mb_height+3);
498
0
      image->cleanup_state++;
499
0
       if (image->output_sent) {
500
0
        image->output_sent = 0;
501
0
        return 0;
502
0
      }
503
0
    } else {
504
0
      return 1;
505
0
    }
506
    // runs into the following
507
0
  default:
508
0
    image->spatial_buffered_flag = 0;
509
0
    image->stripe_my             = 0;
510
0
    return JXR_EC_DONE;
511
0
  }
512
0
}
513
514
515
/*
516
* $Log: r_tile_spatial.c,v $
517
* Revision 1.10  2011-11-08 20:17:29  thor
518
* Merged a couple of fixes from the JNB.
519
*
520
* Revision 1.9  2011-04-28 08:45:43  thor
521
* Fixed compiler warnings, ported to gcc 4.4, removed obsolete files.
522
*
523
* Revision 1.8  2010-05-01 11:16:08  thor
524
* Fixed the tiff tag order. Added spatial/line mode.
525
*
526
* Revision 1.7  2010-03-31 07:50:59  thor
527
* Replaced by the latest MS version.
528
*
529
* Revision 1.55 2009/05/29 12:00:00 microsoft
530
* Reference Software v1.6 updates.
531
*
532
* Revision 1.54 2009/04/13 12:00:00 microsoft
533
* Reference Software v1.5 updates.
534
*
535
* Revision 1.53 2008/03/20 22:39:41 steve
536
* Fix various debug prints of QP data.
537
*
538
* Revision 1.52 2008/03/20 18:11:25 steve
539
* Handle case of NumLPQP==1 and NumHPQPS>1
540
*
541
* Revision 1.51 2008/03/18 21:09:12 steve
542
* Fix distributed color prediction.
543
*
544
* Revision 1.50 2008/03/07 19:00:52 steve
545
* Improved comments.
546
*
547
* Revision 1.49 2008/03/06 22:47:39 steve
548
* Clean up parsing/encoding of QP counts
549
*
550
* Revision 1.48 2008/03/06 02:05:48 steve
551
* Distributed quantization
552
*
553
* Revision 1.47 2008/02/26 23:52:44 steve
554
* Remove ident for MS compilers.
555
*
556
* Revision 1.46 2007/11/26 01:47:15 steve
557
* Add copyright notices per MS request.
558
*
559
* Revision 1.45 2007/11/21 23:26:14 steve
560
* make all strip buffers store MB data.
561
*
562
* Revision 1.44 2007/11/20 17:08:02 steve
563
* Fix SPATIAL processing of QUANT values for color.
564
*
565
* Revision 1.43 2007/11/16 21:33:48 steve
566
* Store MB Quant, not qp_index.
567
*
568
* Revision 1.42 2007/11/16 20:03:57 steve
569
* Store MB Quant, not qp_index.
570
*
571
* Revision 1.41 2007/11/16 00:29:06 steve
572
* Support FREQUENCY mode HP and FLEXBITS
573
*
574
* Revision 1.40 2007/11/14 23:56:17 steve
575
* Fix TILE ordering, using seeks, for FREQUENCY mode.
576
*
577
* Revision 1.39 2007/11/14 00:17:27 steve
578
* Fix parsing of QP indices.
579
*
580
* Revision 1.38 2007/11/13 03:27:24 steve
581
* Add Frequency mode LP support.
582
*
583
* Revision 1.37 2007/11/12 23:21:55 steve
584
* Infrastructure for frequency mode ordering.
585
*
586
* Revision 1.36 2007/11/08 19:38:38 steve
587
* Get stub DCONLY compression to work.
588
*
589
* Revision 1.35 2007/11/01 21:09:40 steve
590
* Multiple rows of tiles.
591
*
592
* Revision 1.34 2007/10/31 21:20:54 steve
593
* Init, not Adapt, on tile boundaries.
594
*
595
* Revision 1.33 2007/10/30 21:32:46 steve
596
* Support for multiple tile columns.
597
*
598
* Revision 1.32 2007/10/19 16:20:21 steve
599
* Parse YUV420 HP
600
*
601
* Revision 1.31 2007/10/04 23:03:26 steve
602
* HP blocks uf YUV42X chroma are not shuffled.
603
*
604
* Revision 1.30 2007/10/04 00:30:47 steve
605
* Fix prediction of HP CBP for YUV422 data.
606
*
607
* Revision 1.29 2007/10/02 20:36:29 steve
608
* Fix YUV42X DC prediction, add YUV42X HP parsing.
609
*
610
* Revision 1.28 2007/10/01 20:39:34 steve
611
* Add support for YUV422 LP bands.
612
*
613
* Revision 1.27 2007/09/18 17:00:50 steve
614
* Fix bad calculation of lap_mean for chroma.
615
*
616
* Revision 1.26 2007/09/13 23:12:34 steve
617
* Support color HP bands.
618
*
619
* Revision 1.25 2007/09/12 01:09:24 steve
620
* Dump the TRIM_FLEXBITS value.
621
*
622
* Revision 1.24 2007/09/11 01:06:12 steve
623
* Forgot to properly save LP data.
624
*
625
* Revision 1.23 2007/09/11 00:40:06 steve
626
* Fix rendering of chroma to add the missing *2.
627
* Fix handling of the chroma LP samples
628
* Parse some of the HP CBP data in chroma.
629
*
630
* Revision 1.22 2007/09/10 23:42:00 steve
631
* Fix LP processing steps when color involved.
632
*
633
* Revision 1.21 2007/09/08 01:01:44 steve
634
* YUV444 color parses properly.
635
*
636
* Revision 1.20 2007/09/04 22:48:09 steve
637
* Fix calculation of flex bits on 0 coefficients.
638
*
639
* Revision 1.19 2007/09/04 19:10:46 steve
640
* Finish level1 overlap filtering.
641
*
642
* Revision 1.18 2007/08/31 23:31:49 steve
643
* Initialize CBP VLC tables at the right time.
644
*
645
* Revision 1.17 2007/08/31 23:20:57 steve
646
* Dump MB_CBP details.
647
*
648
* Revision 1.16 2007/08/15 01:54:11 steve
649
* Add level2 filter to decoder.
650
*
651
* Revision 1.15 2007/08/13 22:24:43 steve
652
* Fix Reset Context of absLevelInd.
653
*
654
* Revision 1.14 2007/07/31 15:27:19 steve
655
* Get transpose of FLEXBITS right.
656
*
657
* Revision 1.13 2007/07/30 23:09:57 steve
658
* Interleave FLEXBITS within HP block.
659
*
660
* Revision 1.12 2007/07/24 20:56:28 steve
661
* Fix HP prediction and model bits calculations.
662
*
663
* Revision 1.11 2007/07/21 00:25:48 steve
664
* snapshot 2007 07 20
665
*
666
* Revision 1.10 2007/07/12 22:48:17 steve
667
* Decode FLEXBITS
668
*
669
* Revision 1.9 2007/07/11 00:53:36 steve
670
* HP adaptation and precition corrections.
671
*
672
* Revision 1.8 2007/07/06 23:18:41 steve
673
* calculate and propagate HP band predictions.
674
*
675
* Revision 1.7 2007/07/05 20:19:13 steve
676
* Fix accumulation of HP CBP, and add HP predictions.
677
*
678
* Revision 1.6 2007/07/03 20:45:11 steve
679
* Parse and place HP data.
680
*
681
* Revision 1.5 2007/06/28 20:03:11 steve
682
* LP processing seems to be OK now.
683
*
684
* Revision 1.4 2007/06/21 17:31:22 steve
685
* Successfully parse LP components.
686
*
687
* Revision 1.3 2007/06/11 20:00:09 steve
688
* Parse FLEXBITS
689
*
690
* Revision 1.2 2007/06/07 18:53:06 steve
691
* Parse HP coeffs that are all 0.
692
*
693
* Revision 1.1 2007/06/06 17:19:12 steve
694
* Introduce to CVS.
695
*
696
*/
697