Coverage Report

Created: 2026-09-14 07:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/jpegxr/init.c
Line
Count
Source
1
2
3
/*************************************************************************
4
*
5
* This software module was originally contributed by Microsoft
6
* Corporation in the course of development of the
7
* ITU-T T.832 | ISO/IEC 29199-2 ("JPEG XR") format standard for
8
* reference purposes and its performance may not have been optimized.
9
*
10
* This software module is an implementation of one or more
11
* tools as specified by the JPEG XR standard.
12
*
13
* ITU/ISO/IEC give You a royalty-free, worldwide, non-exclusive
14
* copyright license to copy, distribute, and make derivative works
15
* of this software module or modifications thereof for use in
16
* products claiming conformance to the JPEG XR standard as
17
* specified by ITU-T T.832 | ISO/IEC 29199-2.
18
*
19
* ITU/ISO/IEC give users the same free license to this software
20
* module or modifications thereof for research purposes and further
21
* ITU/ISO/IEC standardization.
22
*
23
* Those intending to use this software module in products are advised
24
* that its use may infringe existing patents. ITU/ISO/IEC have no
25
* liability for use of this software module or modifications thereof.
26
*
27
* Copyright is not released for products that do not conform to
28
* to the JPEG XR standard as specified by ITU-T T.832 |
29
* ISO/IEC 29199-2.
30
*
31
******** Section to be removed when the standard is published ************
32
*
33
* Assurance that the contributed software module can be used
34
* (1) in the ITU-T "T.JXR" | ISO/IEC 29199 ("JPEG XR") standard once the
35
* standard has been adopted; and
36
* (2) to develop the JPEG XR standard:
37
*
38
* Microsoft Corporation and any subsequent contributors to the development
39
* of this software grant ITU/ISO/IEC all rights necessary to include
40
* the originally developed software module or modifications thereof in the
41
* JPEG XR standard and to permit ITU/ISO/IEC to offer such a royalty-free,
42
* worldwide, non-exclusive copyright license to copy, distribute, and make
43
* derivative works of this software module or modifications thereof for
44
* use in products claiming conformance to the JPEG XR standard as
45
* specified by ITU-T T.832 | ISO/IEC 29199-2, and to the extent that
46
* such originally developed software module or portions of it are included
47
* in an ITU/ISO/IEC standard. To the extent that the original contributors
48
* may own patent rights that would be required to make, use, or sell the
49
* originally developed software module or portions thereof included in the
50
* ITU/ISO/IEC standard in a conforming product, the contributors will
51
* assure ITU/ISO/IEC that they are willing to negotiate licenses under
52
* reasonable and non-discriminatory terms and conditions with
53
* applicants throughout the world and in accordance with their patent
54
* rights declarations made to ITU/ISO/IEC (if any).
55
*
56
* Microsoft, any subsequent contributors, and ITU/ISO/IEC additionally
57
* gives You a free license to this software module or modifications
58
* thereof for the sole purpose of developing the JPEG XR standard.
59
*
60
******** end of section to be removed when the standard is published *****
61
*
62
* Microsoft Corporation retains full right to modify and use the code
63
* for its own purpose, to assign or donate the code to a third party,
64
* and to inhibit third parties from using the code for products that
65
* do not conform to the JPEG XR standard as specified by ITU-T T.832 |
66
* ISO/IEC 29199-2.
67
*
68
* This copyright notice must be included in all copies or derivative
69
* works.
70
*
71
* Copyright (c) ITU-T/ISO/IEC 2008, 2009.
72
***********************************************************************/
73
74
#ifdef _MSC_VER
75
#pragma comment (user,"$Id: init.c,v 1.12 2011-11-15 10:11:17 thor Exp $")
76
#endif
77
78
# include "jxr_priv.h"
79
# include <stdlib.h>
80
# include <assert.h>
81
82
const int _jxr_abslevel_index_delta[7] = { 1, 0, -1, -1, -1, -1, -1 };
83
84
static void clear_vlc_tables(jxr_image_t image)
85
0
{
86
0
    int idx;
87
0
    for (idx = 0 ; idx < AbsLevelInd_COUNT ; idx += 1) {
88
0
        image->vlc_table[idx].discriminant = 0;
89
0
        image->vlc_table[idx].discriminant2 = 0;
90
0
        image->vlc_table[idx].table = 0;
91
0
        image->vlc_table[idx].deltatable = 0;
92
0
        image->vlc_table[idx].delta2table = 0;
93
0
    }
94
0
}
95
96
static struct jxr_image* __make_jxr(jxr_alloc *alloc)
97
0
{
98
0
    struct jxr_image*image = (struct jxr_image*)jxr_calloc(alloc, 1, sizeof(struct jxr_image));
99
0
    int idx;
100
0
    if (image == NULL)
101
0
        return NULL;
102
0
    image->alloc = alloc;
103
0
    image->user_flags = 0;
104
0
    image->width1 = 0;
105
0
    image->height1 = 0;
106
0
    image->extended_width = 0;
107
0
    image->extended_height = 0;
108
0
    image->header_flags1 = 0;
109
0
    image->header_flags2 = 0x80; /* SHORT_HEADER_FLAG=1 */
110
0
    image->header_flags_fmt = 0;
111
0
    image->bands_present = 0; /* Default ALL bands present */
112
0
    image->num_channels = 0;
113
0
    image->tile_index_table = 0;
114
0
    image->tile_index_table_length = 0;
115
0
    image->tile_column_width = 0;
116
0
    image->tile_row_height = 0;
117
0
    image->primary = 1;
118
119
0
    clear_vlc_tables(image);
120
121
0
    for (idx = 0 ; idx < MAX_CHANNELS ; idx += 1) {
122
0
        image->strip[idx].up4 = 0;
123
0
        image->strip[idx].up3 = 0;
124
0
        image->strip[idx].up2 = 0;
125
0
        image->strip[idx].up1 = 0;
126
0
        image->strip[idx].cur = 0;
127
0
    }
128
129
0
    image->scaled_flag = 1;
130
131
0
    image->out_fun = 0;
132
133
0
    return image;
134
0
}
135
136
static int
137
make_mb_row_buffer_aux(jxr_image_t image, int ch, int format_scale, size_t block_count)
138
0
{
139
0
    int*data, *pred_dclp;
140
0
    size_t idx;
141
142
0
    image->mb_row_buffer[ch] = (struct macroblock_s*)jxr_calloc(image->alloc, block_count, sizeof(struct macroblock_s));
143
0
    if (image->mb_row_buffer[ch] == NULL)
144
0
        return -1;
145
0
    data = (int*)jxr_calloc(image->alloc, block_count*format_scale, sizeof(int));
146
0
    pred_dclp = (int*)jxr_calloc(image->alloc, block_count*7, sizeof(int));
147
0
    if (data == NULL || pred_dclp == NULL) {
148
0
        jxr_free(image->alloc, data);
149
0
        jxr_free(image->alloc, pred_dclp);
150
0
        return -1;
151
0
    }
152
153
0
    for (idx = 0 ; idx < block_count ; idx += 1) {
154
0
        image->mb_row_buffer[ch][idx].data = data + format_scale*idx;
155
        /* 7 (used as mutilpier) = 1 DC + 3 top LP + 3 left LP coefficients used for prediction */
156
0
        image->mb_row_buffer[ch][idx].pred_dclp = pred_dclp + 7*idx;
157
0
    }
158
159
0
    return 0;
160
0
}
161
162
static int make_mb_row_buffer(jxr_image_t image, unsigned use_height)
163
0
{
164
0
    size_t block_count = EXTENDED_WIDTH_BLOCKS(image) * use_height;
165
0
    size_t idx;
166
0
    int format_scale;
167
0
    int ch;
168
169
0
    if (make_mb_row_buffer_aux(image, 0, 256, block_count))
170
0
        return -1;
171
172
0
    format_scale = 256;
173
0
    if (image->use_clr_fmt == 2 /* YUV422 */) {
174
0
        format_scale = 16 + 8*15;
175
0
    } else if (image->use_clr_fmt == 1 /* YUV420 */) {
176
0
        format_scale = 16 + 4*15;
177
0
    }
178
179
0
    for (ch = 1 ; ch < image->num_channels ; ch += 1) {
180
0
        if (make_mb_row_buffer_aux(image, ch, format_scale, block_count))
181
0
            return -1;
182
0
    }
183
0
    return 0;
184
0
}
185
186
/*
187
* Allocate the macroblock strip store. Each macroblock points to 256
188
* values that are either the 256 pixel values, or the DC, LP and HP
189
* coefficients.
190
*
191
* DC/LP/HP arrangement -
192
* The first word is the DC.
193
* The next 15 are the LP coefficients.
194
* The remaining 240 are HP coefficients.
195
*/
196
int _jxr_make_mbstore(jxr_image_t image, int up4_flag)
197
0
{
198
0
    int ch;
199
200
0
    assert(image->strip[0].up4 == 0);
201
0
    assert(image->strip[0].up3 == 0);
202
0
    assert(image->strip[0].up2 == 0);
203
0
    assert(image->strip[0].up1 == 0);
204
0
    assert(image->strip[0].cur == 0);
205
206
0
    assert(image->num_channels > 0);
207
208
0
    if (EXTENDED_WIDTH_BLOCKS(image) == 0 || EXTENDED_HEIGHT_BLOCKS(image) == 0)
209
0
        return -1;
210
211
0
    for (ch = 0 ; ch < image->num_channels ; ch += 1) {
212
0
        size_t idx;
213
0
        if (up4_flag)
214
0
        {
215
0
            image->strip[ch].up4 = (struct macroblock_s*)
216
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
217
0
            if (image->strip[ch].up4 == NULL)
218
0
                return -1;
219
0
        }
220
0
        image->strip[ch].up3 = (struct macroblock_s*)
221
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
222
0
        if (image->strip[ch].up3 == NULL)
223
0
            return -1;
224
0
        image->strip[ch].up2 = (struct macroblock_s*)
225
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
226
0
        if (image->strip[ch].up2 == NULL)
227
0
            return -1;
228
0
        image->strip[ch].up1 = (struct macroblock_s*)
229
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
230
0
        if (image->strip[ch].up1 == NULL)
231
0
            return -1;
232
0
        image->strip[ch].cur = (struct macroblock_s*)
233
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
234
0
        if (image->strip[ch].cur == NULL)
235
0
            return -1;
236
237
0
        if (up4_flag) {
238
0
            image->strip[ch].up4[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
239
0
            if (image->strip[ch].up4[0].data == NULL)
240
0
                return -1;
241
0
            for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
242
0
                image->strip[ch].up4[idx].data = image->strip[ch].up4[idx-1].data + 256;
243
0
        }
244
0
        image->strip[ch].up3[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
245
0
        if (image->strip[ch].up3[0].data == NULL)
246
0
            return -1;
247
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
248
0
            image->strip[ch].up3[idx].data = image->strip[ch].up3[idx-1].data + 256;
249
250
0
        image->strip[ch].up2[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
251
0
        if (image->strip[ch].up2[0].data == NULL)
252
0
            return -1;
253
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
254
0
            image->strip[ch].up2[idx].data = image->strip[ch].up2[idx-1].data + 256;
255
256
0
        image->strip[ch].up1[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
257
0
        if (image->strip[ch].up1[0].data == NULL)
258
0
            return -1;
259
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
260
0
            image->strip[ch].up1[idx].data = image->strip[ch].up1[idx-1].data + 256;
261
262
0
        image->strip[ch].cur[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
263
0
        if (image->strip[ch].cur[0].data == NULL)
264
0
            return -1;
265
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
266
0
            image->strip[ch].cur[idx].data = image->strip[ch].cur[idx-1].data + 256;
267
268
0
        if (up4_flag) {
269
0
            image->strip[ch].up4[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
270
0
            if (image->strip[ch].up4[0].pred_dclp == NULL)
271
0
                return -1;
272
0
            for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
273
0
                image->strip[ch].up4[idx].pred_dclp = image->strip[ch].up4[idx-1].pred_dclp + 7;
274
0
        }
275
276
0
        image->strip[ch].up3[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
277
0
        if (image->strip[ch].up3[0].pred_dclp == NULL)
278
0
            return -1;
279
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
280
0
            image->strip[ch].up3[idx].pred_dclp = image->strip[ch].up3[idx-1].pred_dclp + 7;
281
282
0
        image->strip[ch].up2[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
283
0
        if (image->strip[ch].up2[0].pred_dclp == NULL)
284
0
            return -1;
285
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
286
0
            image->strip[ch].up2[idx].pred_dclp = image->strip[ch].up2[idx-1].pred_dclp + 7;
287
288
0
        image->strip[ch].up1[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
289
0
        if (image->strip[ch].up1[0].pred_dclp == NULL)
290
0
            return -1;
291
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
292
0
            image->strip[ch].up1[idx].pred_dclp = image->strip[ch].up1[idx-1].pred_dclp + 7;
293
294
0
        image->strip[ch].cur[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
295
0
        if (image->strip[ch].cur[0].pred_dclp == NULL)
296
0
            return -1;
297
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
298
0
            image->strip[ch].cur[idx].pred_dclp = image->strip[ch].cur[idx-1].pred_dclp + 7;
299
300
0
        if(ch!= 0)
301
0
        {
302
0
            if(image->use_clr_fmt == 2 || image->use_clr_fmt == 1) /* 422 or 420 */
303
0
            {
304
0
                image->strip[ch].upsample_memory_x = (int*)jxr_calloc(image->alloc, 16, sizeof(int));
305
0
                if (image->strip[ch].upsample_memory_x == NULL)
306
0
                    return -1;
307
0
            }
308
309
0
            if(image->use_clr_fmt == 1)/* 420 */
310
0
            {
311
0
                image->strip[ch].upsample_memory_y = (int*)jxr_calloc(image->alloc, 8*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
312
0
                if (image->strip[ch].upsample_memory_y == NULL)
313
0
                    return -1;
314
0
            }
315
0
        }
316
        
317
0
    }
318
319
    /* If there is tiling (in columns) then allocate a tile buffer
320
    that can hold an entire row of tiles. */
321
0
    if (FREQUENCY_MODE_CODESTREAM_FLAG(image)) { /* FREQUENCY MODE */
322
323
0
        if (make_mb_row_buffer(image, EXTENDED_HEIGHT_BLOCKS(image)))
324
0
            return -1;
325
326
0
    } else { /* SPATIAL */
327
0
        if (INDEXTABLE_PRESENT_FLAG(image)) { 
328
            /* This means that the tiling flag is used */
329
0
            unsigned max_tile_height = 0;
330
0
            unsigned idx;
331
0
            int format_scale;
332
0
            int ch;
333
0
            for (idx = 0 ; idx < image->tile_rows ; idx += 1) {
334
0
                if (image->tile_row_height[idx] > max_tile_height)
335
0
                    max_tile_height = image->tile_row_height[idx];
336
0
            }
337
338
0
            if (make_mb_row_buffer(image, max_tile_height))
339
0
                return -1;
340
341
            /* Save enough context MBs for 4 rows of
342
            macroblocks. */
343
344
0
            format_scale = 256;
345
0
            if (image->use_clr_fmt == 2 /* YUV422 */) {
346
0
                format_scale = 16 + 8*15;
347
0
            } else if (image->use_clr_fmt == 1 /* YUV420 */) {
348
0
                format_scale = 16 + 4*15;
349
0
            }
350
351
0
            for (ch = 0 ; ch < image->num_channels ; ch += 1) {
352
0
                int count = (ch==0)? 256 : format_scale;
353
0
                image->mb_row_context[ch] = (struct macroblock_s*)
354
0
                    jxr_calloc(image->alloc, 4*EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
355
0
                if (image->mb_row_context[ch] == NULL)
356
0
                    return -1;
357
0
                image->mb_row_context[ch][0].data = (int*)
358
0
                    jxr_calloc(image->alloc, 4*EXTENDED_WIDTH_BLOCKS(image)*count, sizeof(int));
359
0
                if (image->mb_row_context[ch][0].data == NULL)
360
0
                    return -1;
361
0
                for (idx = 1 ; idx < 4*EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
362
0
                    image->mb_row_context[ch][idx].data = image->mb_row_context[ch][idx-1].data+count;
363
0
            }
364
365
0
        }
366
0
    }
367
368
    /* since CBP processing is done at each row, need to save contexts is multiple tile columns */
369
0
    image->model_hp_buffer = 0;
370
0
    image->hp_cbp_model_buffer = 0;
371
0
    if (image->tile_columns > 1) {
372
0
        image->model_hp_buffer = (struct model_s*)
373
0
            jxr_calloc(image->alloc, image->tile_columns, sizeof(struct model_s));
374
0
        if (image->model_hp_buffer == NULL)
375
0
            return -1;
376
0
        image->hp_cbp_model_buffer = (struct cbp_model_s*)
377
0
            jxr_calloc(image->alloc, image->tile_columns, sizeof(struct cbp_model_s));
378
0
        if (image->hp_cbp_model_buffer == NULL)
379
0
            return -1;
380
0
    }
381
382
0
    image->cur_my = -1;
383
384
0
    return 0;
385
0
}
386
387
jxr_image_t jxr_create_input_alloc(jxr_alloc *alloc)
388
0
{
389
0
    struct jxr_image*image = __make_jxr(alloc);
390
391
0
    return image;
392
0
}
393
394
jxr_image_t jxr_create_input(void)
395
0
{
396
0
    return jxr_create_input_alloc(NULL);}
397
398
jxr_image_t jxr_create_image(int width, int height, unsigned char * windowing)
399
0
{
400
0
    return jxr_create_image_alloc(NULL, width, height, windowing);
401
0
}
402
403
jxr_image_t jxr_create_image_alloc(jxr_alloc *alloc, int width, int height, unsigned char * windowing)
404
0
{
405
0
    struct jxr_image*image;
406
407
0
    if (width == 0 || height == 0)
408
0
        return 0;
409
410
0
    image = __make_jxr(alloc);
411
0
    if (image == NULL)
412
0
        return 0;
413
414
0
    if (windowing[0] == 1) {
415
0
      unsigned extra_width  = (-(width + windowing[2]+windowing[4])) & 0x0f;
416
0
      unsigned extra_height = (-(height +windowing[1]+windowing[3])) & 0x0f;
417
418
      /*
419
      ** fixup the bottom and right borders such that the nominal image
420
      ** dimensions are divisible by 16
421
      */
422
423
0
      if (extra_width || extra_height)
424
0
        fprintf(stderr,"WARNING: enlarging the window borders to align the extended size to 16 pixel boundaries\n");
425
426
0
      windowing[4] += extra_width;
427
0
      windowing[3] += extra_height;
428
429
0
      assert(((width+windowing[2]+windowing[4]) & 0x0f) == 0);
430
0
      assert(((height+windowing[1]+windowing[3]) & 0x0f) == 0);
431
0
    }
432
0
    else {
433
0
        windowing[1] = windowing[2] = 0;
434
0
        windowing[3] = (((height + 15) >> 4) << 4) - height;
435
0
        windowing[4] = (((width + 15) >> 4) << 4) - width;
436
0
    }
437
438
0
    if (windowing[1] >= 64 || windowing[2] >= 64 || windowing[3] >= 64 || windowing[4] >= 64) {
439
0
      fprintf(stderr,"Window borders are larger or equal than 64 pixels which is unsupported\n");
440
0
      return 0;
441
0
    }
442
443
0
    image->width1 = width-1;
444
0
    image->height1 = height-1;
445
0
    image->extended_width = image->width1 + 1 + windowing[2] + windowing[4];
446
0
    image->extended_height = image->height1 + 1 + windowing[1] + windowing[3];
447
448
0
    image->dc_frame_uniform = 1;
449
0
    image->lp_frame_uniform = 1;
450
0
    image->lp_use_dc_qp = 0;
451
0
    image->num_lp_qps = 1;
452
0
    image->hp_use_lp_qp = 0;
453
0
    image->hp_frame_uniform = 1;
454
0
    image->num_hp_qps = 1;
455
456
0
    image->window_extra_top = windowing[1];
457
0
    image->window_extra_left = windowing[2];
458
0
    image->window_extra_bottom = windowing[3];
459
0
    image->window_extra_right = windowing[4];
460
461
0
    return image;
462
0
}
463
464
void jxr_flag_SKIP_HP_DATA(jxr_image_t image, int flag)
465
0
{
466
0
    if (flag)
467
0
        image->user_flags |= 0x0001;
468
0
    else
469
0
        image->user_flags &= ~0x0001;
470
0
}
471
472
void jxr_flag_SKIP_FLEX_DATA(jxr_image_t image, int flag)
473
0
{
474
0
    if (flag)
475
0
        image->user_flags |= 0x0002;
476
0
    else
477
0
        image->user_flags &= ~0x0002;
478
0
}
479
480
void jxr_destroy(jxr_image_t image)
481
0
{
482
0
    int idx, plane_idx = 1;
483
0
    if(image == NULL)
484
0
        return;
485
486
0
    if (ALPHACHANNEL_FLAG(image))
487
0
        plane_idx = 2;
488
    
489
0
    for (; plane_idx > 0; plane_idx --) {
490
0
        jxr_image_t plane = (plane_idx == 1 ? image : image->alpha);
491
492
0
        for (idx = 0 ; idx < plane->num_channels ; idx += 1) {
493
0
            if (plane->strip[idx].up4) {
494
0
              jxr_free(image->alloc, plane->strip[idx].up4[0].pred_dclp);
495
0
              jxr_free(image->alloc, plane->strip[idx].up4[0].data);
496
0
              jxr_free(image->alloc, plane->strip[idx].up4);
497
0
            }
498
0
            if (plane->strip[idx].up3) {
499
0
              jxr_free(image->alloc, plane->strip[idx].up3[0].pred_dclp);
500
0
              jxr_free(image->alloc, plane->strip[idx].up3[0].data);
501
0
              jxr_free(image->alloc, plane->strip[idx].up3);
502
0
            }
503
0
            if (plane->strip[idx].up2) {
504
0
              jxr_free(image->alloc, plane->strip[idx].up2[0].pred_dclp);
505
0
              jxr_free(image->alloc, plane->strip[idx].up2[0].data);
506
0
              jxr_free(image->alloc, plane->strip[idx].up2);
507
0
            }
508
0
            if (plane->strip[idx].up1) {
509
0
              jxr_free(image->alloc, plane->strip[idx].up1[0].pred_dclp);
510
0
              jxr_free(image->alloc, plane->strip[idx].up1[0].data);
511
0
              jxr_free(image->alloc, plane->strip[idx].up1);
512
0
            }
513
0
            if (plane->strip[idx].cur) {
514
0
              jxr_free(image->alloc, plane->strip[idx].cur[0].pred_dclp);
515
0
              jxr_free(image->alloc, plane->strip[idx].cur[0].data);
516
0
              jxr_free(image->alloc, plane->strip[idx].cur);
517
0
            }
518
0
            if(plane->strip[idx].upsample_memory_x)
519
0
                jxr_free(image->alloc, plane->strip[idx].upsample_memory_x);
520
0
            if(plane->strip[idx].upsample_memory_y)
521
0
                jxr_free(image->alloc, plane->strip[idx].upsample_memory_y);
522
523
0
        }
524
525
0
        for (idx = 0 ; idx < plane->num_channels ; idx += 1) {
526
0
            if (plane->mb_row_buffer[idx]) {
527
0
                jxr_free(image->alloc, plane->mb_row_buffer[idx][0].data);
528
0
                jxr_free(image->alloc, plane->mb_row_buffer[idx]);
529
0
            }
530
531
0
            if (plane->mb_row_context[idx]) {
532
0
                jxr_free(image->alloc, plane->mb_row_context[idx][0].data);
533
0
                jxr_free(image->alloc, plane->mb_row_context[idx]);
534
0
            }
535
0
        }
536
537
0
        if (plane->model_hp_buffer) {
538
0
            jxr_free(image->alloc, plane->model_hp_buffer);
539
0
        }
540
541
0
        if (plane->hp_cbp_model_buffer) {
542
0
            jxr_free(image->alloc, plane->hp_cbp_model_buffer);
543
0
        }
544
545
0
        if(plane_idx == 1){
546
0
            if (plane->tile_index_table)
547
0
              jxr_free(image->alloc, plane->tile_index_table);
548
0
            if (plane->tile_column_width)
549
0
              jxr_free(image->alloc, plane->tile_column_width);
550
0
            if (plane->tile_row_height)
551
0
              jxr_free(image->alloc, plane->tile_row_height);
552
0
        }
553
0
        jxr_free(image->alloc, plane);
554
0
    }
555
0
}
556
557
void *jxr_malloc(jxr_alloc *alloc, size_t z)
558
0
{
559
0
    if (alloc == NULL)
560
0
        return malloc(z);
561
0
    return alloc->malloc(alloc->handle, z);
562
0
}
563
564
void *jxr_calloc(jxr_alloc *alloc, size_t z, size_t n)
565
0
{
566
0
    if (alloc == NULL)
567
0
        return calloc(z, n);
568
0
    return alloc->calloc(alloc->handle, z, n);
569
0
}
570
571
void *jxr_realloc(jxr_alloc *alloc, void *ptr, size_t z)
572
0
{
573
0
    if (alloc == NULL)
574
0
        return realloc(ptr, z);
575
0
    return alloc->realloc(alloc->handle, ptr, z);
576
0
}
577
578
void jxr_free(jxr_alloc *alloc, void *ptr)
579
0
{
580
0
    if (alloc == NULL)
581
0
    {
582
0
        free(ptr);
583
0
        return;
584
0
    }
585
0
    alloc->free(alloc->handle, ptr);
586
0
}
587
588
/*
589
* $Log: init.c,v $
590
* Revision 1.12  2011-11-15 10:11:17  thor
591
* Bumped to release 1.30.
592
*
593
* Revision 1.11  2011-11-11 17:13:50  thor
594
* Fixed a memory bug, fixed padding channel on encoding bug.
595
* Fixed window sizes (again).
596
*
597
* Revision 1.10  2011-11-08 20:17:29  thor
598
* Merged a couple of fixes from the JNB.
599
*
600
* Revision 1.9  2011-04-28 08:45:43  thor
601
* Fixed compiler warnings, ported to gcc 4.4, removed obsolete files.
602
*
603
* Revision 1.8  2010-05-22 22:14:35  thor
604
* Fixed memory leaks in the TIFF parser.
605
*
606
* Revision 1.7  2010-03-31 07:50:58  thor
607
* Replaced by the latest MS version.
608
*
609
* Revision 1.25 2009/05/29 12:00:00 microsoft
610
* Reference Software v1.6 updates.
611
*
612
* Revision 1.24 2009/04/13 12:00:00 microsoft
613
* Reference Software v1.5 updates.
614
*
615
* Revision 1.23 2008/03/13 21:23:27 steve
616
* Add pipeline step for YUV420.
617
*
618
* Revision 1.22 2008/03/05 06:58:10 gus
619
* *** empty log message ***
620
*
621
* Revision 1.21 2008/02/28 18:50:31 steve
622
* Portability fixes.
623
*
624
* Revision 1.20 2008/02/26 23:52:44 steve
625
* Remove ident for MS compilers.
626
*
627
* Revision 1.19 2008/01/04 17:07:35 steve
628
* API interface for setting QP values.
629
*
630
* Revision 1.18 2007/11/26 01:47:15 steve
631
* Add copyright notices per MS request.
632
*
633
* Revision 1.17 2007/11/22 19:02:05 steve
634
* More fixes of color plane buffer sizes.
635
*
636
* Revision 1.16 2007/11/21 23:26:14 steve
637
* make all strip buffers store MB data.
638
*
639
* Revision 1.15 2007/11/21 00:34:30 steve
640
* Rework spatial mode tile macroblock shuffling.
641
*
642
* Revision 1.14 2007/11/15 17:44:13 steve
643
* Frequency mode color support.
644
*
645
* Revision 1.13 2007/11/14 23:56:17 steve
646
* Fix TILE ordering, using seeks, for FREQUENCY mode.
647
*
648
* Revision 1.12 2007/11/12 23:21:54 steve
649
* Infrastructure for frequency mode ordering.
650
*
651
* Revision 1.11 2007/11/08 02:52:32 steve
652
* Some progress in some encoding infrastructure.
653
*
654
* Revision 1.10 2007/11/05 02:01:12 steve
655
* Add support for mixed row/column tiles.
656
*
657
* Revision 1.9 2007/11/01 21:09:40 steve
658
* Multiple rows of tiles.
659
*
660
* Revision 1.8 2007/10/30 21:32:46 steve
661
* Support for multiple tile columns.
662
*
663
* Revision 1.7 2007/09/08 01:01:43 steve
664
* YUV444 color parses properly.
665
*
666
* Revision 1.6 2007/09/04 19:10:46 steve
667
* Finish level1 overlap filtering.
668
*
669
* Revision 1.5 2007/08/15 01:54:11 steve
670
* Add level2 filter to decoder.
671
*
672
* Revision 1.4 2007/08/04 00:15:31 steve
673
* Allow width/height of 1 pixel.
674
*
675
* Revision 1.3 2007/07/21 00:25:48 steve
676
* snapshot 2007 07 20
677
*
678
* Revision 1.2 2007/06/28 20:03:11 steve
679
* LP processing seems to be OK now.
680
*
681
* Revision 1.1 2007/06/06 17:19:12 steve
682
* Introduce to CVS.
683
*
684
*/
685