Coverage Report

Created: 2026-04-09 07:06

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
    for (ch = 0 ; ch < image->num_channels ; ch += 1) {
209
0
        size_t idx;
210
0
        if (up4_flag)
211
0
        {
212
0
            image->strip[ch].up4 = (struct macroblock_s*)
213
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
214
0
            if (image->strip[ch].up4 == NULL)
215
0
                return -1;
216
0
        }
217
0
        image->strip[ch].up3 = (struct macroblock_s*)
218
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
219
0
        if (image->strip[ch].up3 == NULL)
220
0
            return -1;
221
0
        image->strip[ch].up2 = (struct macroblock_s*)
222
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
223
0
        if (image->strip[ch].up2 == NULL)
224
0
            return -1;
225
0
        image->strip[ch].up1 = (struct macroblock_s*)
226
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
227
0
        if (image->strip[ch].up1 == NULL)
228
0
            return -1;
229
0
        image->strip[ch].cur = (struct macroblock_s*)
230
0
            jxr_calloc(image->alloc, EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
231
0
        if (image->strip[ch].cur == NULL)
232
0
            return -1;
233
234
0
        if (up4_flag) {
235
0
            image->strip[ch].up4[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
236
0
            if (image->strip[ch].up4[0].data == NULL)
237
0
                return -1;
238
0
            for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
239
0
                image->strip[ch].up4[idx].data = image->strip[ch].up4[idx-1].data + 256;
240
0
        }
241
0
        image->strip[ch].up3[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
242
0
        if (image->strip[ch].up3[0].data == NULL)
243
0
            return -1;
244
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
245
0
            image->strip[ch].up3[idx].data = image->strip[ch].up3[idx-1].data + 256;
246
247
0
        image->strip[ch].up2[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
248
0
        if (image->strip[ch].up2[0].data == NULL)
249
0
            return -1;
250
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
251
0
            image->strip[ch].up2[idx].data = image->strip[ch].up2[idx-1].data + 256;
252
253
0
        image->strip[ch].up1[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
254
0
        if (image->strip[ch].up1[0].data == NULL)
255
0
            return -1;
256
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
257
0
            image->strip[ch].up1[idx].data = image->strip[ch].up1[idx-1].data + 256;
258
259
0
        image->strip[ch].cur[0].data = (int*)jxr_calloc(image->alloc, 256 * EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
260
0
        if (image->strip[ch].cur[0].data == NULL)
261
0
            return -1;
262
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
263
0
            image->strip[ch].cur[idx].data = image->strip[ch].cur[idx-1].data + 256;
264
265
0
        if (up4_flag) {
266
0
            image->strip[ch].up4[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
267
0
            if (image->strip[ch].up4[0].pred_dclp == NULL)
268
0
                return -1;
269
0
            for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
270
0
                image->strip[ch].up4[idx].pred_dclp = image->strip[ch].up4[idx-1].pred_dclp + 7;
271
0
        }
272
273
0
        image->strip[ch].up3[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
274
0
        if (image->strip[ch].up3[0].pred_dclp == NULL)
275
0
            return -1;
276
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
277
0
            image->strip[ch].up3[idx].pred_dclp = image->strip[ch].up3[idx-1].pred_dclp + 7;
278
279
0
        image->strip[ch].up2[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
280
0
        if (image->strip[ch].up2[0].pred_dclp == NULL)
281
0
            return -1;
282
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
283
0
            image->strip[ch].up2[idx].pred_dclp = image->strip[ch].up2[idx-1].pred_dclp + 7;
284
285
0
        image->strip[ch].up1[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
286
0
        if (image->strip[ch].up1[0].pred_dclp == NULL)
287
0
            return -1;
288
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
289
0
            image->strip[ch].up1[idx].pred_dclp = image->strip[ch].up1[idx-1].pred_dclp + 7;
290
291
0
        image->strip[ch].cur[0].pred_dclp = (int*)jxr_calloc(image->alloc, 7*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
292
0
        if (image->strip[ch].cur[0].pred_dclp == NULL)
293
0
            return -1;
294
0
        for (idx = 1 ; idx < EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
295
0
            image->strip[ch].cur[idx].pred_dclp = image->strip[ch].cur[idx-1].pred_dclp + 7;
296
297
0
        if(ch!= 0)
298
0
        {
299
0
            if(image->use_clr_fmt == 2 || image->use_clr_fmt == 1) /* 422 or 420 */
300
0
            {
301
0
                image->strip[ch].upsample_memory_x = (int*)jxr_calloc(image->alloc, 16, sizeof(int));
302
0
                if (image->strip[ch].upsample_memory_x == NULL)
303
0
                    return -1;
304
0
            }
305
306
0
            if(image->use_clr_fmt == 1)/* 420 */
307
0
            {
308
0
                image->strip[ch].upsample_memory_y = (int*)jxr_calloc(image->alloc, 8*EXTENDED_WIDTH_BLOCKS(image), sizeof(int));
309
0
                if (image->strip[ch].upsample_memory_y == NULL)
310
0
                    return -1;
311
0
            }
312
0
        }
313
        
314
0
    }
315
316
    /* If there is tiling (in columns) then allocate a tile buffer
317
    that can hold an entire row of tiles. */
318
0
    if (FREQUENCY_MODE_CODESTREAM_FLAG(image)) { /* FREQUENCY MODE */
319
320
0
        if (make_mb_row_buffer(image, EXTENDED_HEIGHT_BLOCKS(image)))
321
0
            return -1;
322
323
0
    } else { /* SPATIAL */
324
0
        if (INDEXTABLE_PRESENT_FLAG(image)) { 
325
            /* This means that the tiling flag is used */
326
0
            unsigned max_tile_height = 0;
327
0
            unsigned idx;
328
0
            int format_scale;
329
0
            int ch;
330
0
            for (idx = 0 ; idx < image->tile_rows ; idx += 1) {
331
0
                if (image->tile_row_height[idx] > max_tile_height)
332
0
                    max_tile_height = image->tile_row_height[idx];
333
0
            }
334
335
0
            if (make_mb_row_buffer(image, max_tile_height))
336
0
                return -1;
337
338
            /* Save enough context MBs for 4 rows of
339
            macroblocks. */
340
341
0
            format_scale = 256;
342
0
            if (image->use_clr_fmt == 2 /* YUV422 */) {
343
0
                format_scale = 16 + 8*15;
344
0
            } else if (image->use_clr_fmt == 1 /* YUV420 */) {
345
0
                format_scale = 16 + 4*15;
346
0
            }
347
348
0
            for (ch = 0 ; ch < image->num_channels ; ch += 1) {
349
0
                int count = (ch==0)? 256 : format_scale;
350
0
                image->mb_row_context[ch] = (struct macroblock_s*)
351
0
                    jxr_calloc(image->alloc, 4*EXTENDED_WIDTH_BLOCKS(image), sizeof(struct macroblock_s));
352
0
                if (image->mb_row_context[ch] == NULL)
353
0
                    return -1;
354
0
                image->mb_row_context[ch][0].data = (int*)
355
0
                    jxr_calloc(image->alloc, 4*EXTENDED_WIDTH_BLOCKS(image)*count, sizeof(int));
356
0
                if (image->mb_row_context[ch][0].data == NULL)
357
0
                    return -1;
358
0
                for (idx = 1 ; idx < 4*EXTENDED_WIDTH_BLOCKS(image) ; idx += 1)
359
0
                    image->mb_row_context[ch][idx].data = image->mb_row_context[ch][idx-1].data+count;
360
0
            }
361
362
0
        }
363
0
    }
364
365
    /* since CBP processing is done at each row, need to save contexts is multiple tile columns */
366
0
    image->model_hp_buffer = 0;
367
0
    image->hp_cbp_model_buffer = 0;
368
0
    if (image->tile_columns > 1) {
369
0
        image->model_hp_buffer = (struct model_s*)
370
0
            jxr_calloc(image->alloc, image->tile_columns, sizeof(struct model_s));
371
0
        if (image->model_hp_buffer == NULL)
372
0
            return -1;
373
0
        image->hp_cbp_model_buffer = (struct cbp_model_s*)
374
0
            jxr_calloc(image->alloc, image->tile_columns, sizeof(struct cbp_model_s));
375
0
        if (image->hp_cbp_model_buffer == NULL)
376
0
            return -1;
377
0
    }
378
379
0
    image->cur_my = -1;
380
381
0
    return 0;
382
0
}
383
384
jxr_image_t jxr_create_input_alloc(jxr_alloc *alloc)
385
0
{
386
0
    struct jxr_image*image = __make_jxr(alloc);
387
388
0
    return image;
389
0
}
390
391
jxr_image_t jxr_create_input(void)
392
0
{
393
0
    return jxr_create_input_alloc(NULL);}
394
395
jxr_image_t jxr_create_image(int width, int height, unsigned char * windowing)
396
0
{
397
0
    return jxr_create_image_alloc(NULL, width, height, windowing);
398
0
}
399
400
jxr_image_t jxr_create_image_alloc(jxr_alloc *alloc, int width, int height, unsigned char * windowing)
401
0
{
402
0
    struct jxr_image*image;
403
404
0
    if (width == 0 || height == 0)
405
0
        return 0;
406
407
0
    image = __make_jxr(alloc);
408
0
    if (image == NULL)
409
0
        return 0;
410
411
0
    if (windowing[0] == 1) {
412
0
      unsigned extra_width  = (-(width + windowing[2]+windowing[4])) & 0x0f;
413
0
      unsigned extra_height = (-(height +windowing[1]+windowing[3])) & 0x0f;
414
415
      /*
416
      ** fixup the bottom and right borders such that the nominal image
417
      ** dimensions are divisible by 16
418
      */
419
420
0
      if (extra_width || extra_height)
421
0
        fprintf(stderr,"WARNING: enlarging the window borders to align the extended size to 16 pixel boundaries\n");
422
423
0
      windowing[4] += extra_width;
424
0
      windowing[3] += extra_height;
425
426
0
      assert(((width+windowing[2]+windowing[4]) & 0x0f) == 0);
427
0
      assert(((height+windowing[1]+windowing[3]) & 0x0f) == 0);
428
0
    }
429
0
    else {
430
0
        windowing[1] = windowing[2] = 0;
431
0
        windowing[3] = (((height + 15) >> 4) << 4) - height;
432
0
        windowing[4] = (((width + 15) >> 4) << 4) - width;
433
0
    }
434
435
0
    if (windowing[1] >= 64 || windowing[2] >= 64 || windowing[3] >= 64 || windowing[4] >= 64) {
436
0
      fprintf(stderr,"Window borders are larger or equal than 64 pixels which is unsupported\n");
437
0
      return 0;
438
0
    }
439
440
0
    image->width1 = width-1;
441
0
    image->height1 = height-1;
442
0
    image->extended_width = image->width1 + 1 + windowing[2] + windowing[4];
443
0
    image->extended_height = image->height1 + 1 + windowing[1] + windowing[3];
444
445
0
    image->dc_frame_uniform = 1;
446
0
    image->lp_frame_uniform = 1;
447
0
    image->lp_use_dc_qp = 0;
448
0
    image->num_lp_qps = 1;
449
0
    image->hp_use_lp_qp = 0;
450
0
    image->hp_frame_uniform = 1;
451
0
    image->num_hp_qps = 1;
452
453
0
    image->window_extra_top = windowing[1];
454
0
    image->window_extra_left = windowing[2];
455
0
    image->window_extra_bottom = windowing[3];
456
0
    image->window_extra_right = windowing[4];
457
458
0
    return image;
459
0
}
460
461
void jxr_flag_SKIP_HP_DATA(jxr_image_t image, int flag)
462
0
{
463
0
    if (flag)
464
0
        image->user_flags |= 0x0001;
465
0
    else
466
0
        image->user_flags &= ~0x0001;
467
0
}
468
469
void jxr_flag_SKIP_FLEX_DATA(jxr_image_t image, int flag)
470
0
{
471
0
    if (flag)
472
0
        image->user_flags |= 0x0002;
473
0
    else
474
0
        image->user_flags &= ~0x0002;
475
0
}
476
477
void jxr_destroy(jxr_image_t image)
478
0
{
479
0
    int idx, plane_idx = 1;
480
0
    if(image == NULL)
481
0
        return;
482
483
0
    if (ALPHACHANNEL_FLAG(image))
484
0
        plane_idx = 2;
485
    
486
0
    for (; plane_idx > 0; plane_idx --) {
487
0
        jxr_image_t plane = (plane_idx == 1 ? image : image->alpha);
488
489
0
        for (idx = 0 ; idx < plane->num_channels ; idx += 1) {
490
0
            if (plane->strip[idx].up4) {
491
0
              jxr_free(image->alloc, plane->strip[idx].up4[0].pred_dclp);
492
0
              jxr_free(image->alloc, plane->strip[idx].up4[0].data);
493
0
              jxr_free(image->alloc, plane->strip[idx].up4);
494
0
            }
495
0
            if (plane->strip[idx].up3) {
496
0
              jxr_free(image->alloc, plane->strip[idx].up3[0].pred_dclp);
497
0
              jxr_free(image->alloc, plane->strip[idx].up3[0].data);
498
0
              jxr_free(image->alloc, plane->strip[idx].up3);
499
0
            }
500
0
            if (plane->strip[idx].up2) {
501
0
              jxr_free(image->alloc, plane->strip[idx].up2[0].pred_dclp);
502
0
              jxr_free(image->alloc, plane->strip[idx].up2[0].data);
503
0
              jxr_free(image->alloc, plane->strip[idx].up2);
504
0
            }
505
0
            if (plane->strip[idx].up1) {
506
0
              jxr_free(image->alloc, plane->strip[idx].up1[0].pred_dclp);
507
0
              jxr_free(image->alloc, plane->strip[idx].up1[0].data);
508
0
              jxr_free(image->alloc, plane->strip[idx].up1);
509
0
            }
510
0
            if (plane->strip[idx].cur) {
511
0
              jxr_free(image->alloc, plane->strip[idx].cur[0].pred_dclp);
512
0
              jxr_free(image->alloc, plane->strip[idx].cur[0].data);
513
0
              jxr_free(image->alloc, plane->strip[idx].cur);
514
0
            }
515
0
            if(plane->strip[idx].upsample_memory_x)
516
0
                jxr_free(image->alloc, plane->strip[idx].upsample_memory_x);
517
0
            if(plane->strip[idx].upsample_memory_y)
518
0
                jxr_free(image->alloc, plane->strip[idx].upsample_memory_y);
519
520
0
        }
521
522
0
        for (idx = 0 ; idx < plane->num_channels ; idx += 1) {
523
0
            if (plane->mb_row_buffer[idx]) {
524
0
                jxr_free(image->alloc, plane->mb_row_buffer[idx][0].data);
525
0
                jxr_free(image->alloc, plane->mb_row_buffer[idx]);
526
0
            }
527
528
0
            if (plane->mb_row_context[idx]) {
529
0
                jxr_free(image->alloc, plane->mb_row_context[idx][0].data);
530
0
                jxr_free(image->alloc, plane->mb_row_context[idx]);
531
0
            }
532
0
        }
533
534
0
        if (plane->model_hp_buffer) {
535
0
            jxr_free(image->alloc, plane->model_hp_buffer);
536
0
        }
537
538
0
        if (plane->hp_cbp_model_buffer) {
539
0
            jxr_free(image->alloc, plane->hp_cbp_model_buffer);
540
0
        }
541
542
0
        if(plane_idx == 1){
543
0
            if (plane->tile_index_table)
544
0
              jxr_free(image->alloc, plane->tile_index_table);
545
0
            if (plane->tile_column_width)
546
0
              jxr_free(image->alloc, plane->tile_column_width);
547
0
            if (plane->tile_row_height)
548
0
              jxr_free(image->alloc, plane->tile_row_height);
549
0
        }
550
0
        jxr_free(image->alloc, plane);
551
0
    }
552
0
}
553
554
void *jxr_malloc(jxr_alloc *alloc, size_t z)
555
0
{
556
0
    if (alloc == NULL)
557
0
        return malloc(z);
558
0
    return alloc->malloc(alloc->handle, z);
559
0
}
560
561
void *jxr_calloc(jxr_alloc *alloc, size_t z, size_t n)
562
0
{
563
0
    if (alloc == NULL)
564
0
        return calloc(z, n);
565
0
    return alloc->calloc(alloc->handle, z, n);
566
0
}
567
568
void *jxr_realloc(jxr_alloc *alloc, void *ptr, size_t z)
569
0
{
570
0
    if (alloc == NULL)
571
0
        return realloc(ptr, z);
572
0
    return alloc->realloc(alloc->handle, ptr, z);
573
0
}
574
575
void jxr_free(jxr_alloc *alloc, void *ptr)
576
0
{
577
0
    if (alloc == NULL)
578
0
    {
579
0
        free(ptr);
580
0
        return;
581
0
    }
582
0
    alloc->free(alloc->handle, ptr);
583
0
}
584
585
/*
586
* $Log: init.c,v $
587
* Revision 1.12  2011-11-15 10:11:17  thor
588
* Bumped to release 1.30.
589
*
590
* Revision 1.11  2011-11-11 17:13:50  thor
591
* Fixed a memory bug, fixed padding channel on encoding bug.
592
* Fixed window sizes (again).
593
*
594
* Revision 1.10  2011-11-08 20:17:29  thor
595
* Merged a couple of fixes from the JNB.
596
*
597
* Revision 1.9  2011-04-28 08:45:43  thor
598
* Fixed compiler warnings, ported to gcc 4.4, removed obsolete files.
599
*
600
* Revision 1.8  2010-05-22 22:14:35  thor
601
* Fixed memory leaks in the TIFF parser.
602
*
603
* Revision 1.7  2010-03-31 07:50:58  thor
604
* Replaced by the latest MS version.
605
*
606
* Revision 1.25 2009/05/29 12:00:00 microsoft
607
* Reference Software v1.6 updates.
608
*
609
* Revision 1.24 2009/04/13 12:00:00 microsoft
610
* Reference Software v1.5 updates.
611
*
612
* Revision 1.23 2008/03/13 21:23:27 steve
613
* Add pipeline step for YUV420.
614
*
615
* Revision 1.22 2008/03/05 06:58:10 gus
616
* *** empty log message ***
617
*
618
* Revision 1.21 2008/02/28 18:50:31 steve
619
* Portability fixes.
620
*
621
* Revision 1.20 2008/02/26 23:52:44 steve
622
* Remove ident for MS compilers.
623
*
624
* Revision 1.19 2008/01/04 17:07:35 steve
625
* API interface for setting QP values.
626
*
627
* Revision 1.18 2007/11/26 01:47:15 steve
628
* Add copyright notices per MS request.
629
*
630
* Revision 1.17 2007/11/22 19:02:05 steve
631
* More fixes of color plane buffer sizes.
632
*
633
* Revision 1.16 2007/11/21 23:26:14 steve
634
* make all strip buffers store MB data.
635
*
636
* Revision 1.15 2007/11/21 00:34:30 steve
637
* Rework spatial mode tile macroblock shuffling.
638
*
639
* Revision 1.14 2007/11/15 17:44:13 steve
640
* Frequency mode color support.
641
*
642
* Revision 1.13 2007/11/14 23:56:17 steve
643
* Fix TILE ordering, using seeks, for FREQUENCY mode.
644
*
645
* Revision 1.12 2007/11/12 23:21:54 steve
646
* Infrastructure for frequency mode ordering.
647
*
648
* Revision 1.11 2007/11/08 02:52:32 steve
649
* Some progress in some encoding infrastructure.
650
*
651
* Revision 1.10 2007/11/05 02:01:12 steve
652
* Add support for mixed row/column tiles.
653
*
654
* Revision 1.9 2007/11/01 21:09:40 steve
655
* Multiple rows of tiles.
656
*
657
* Revision 1.8 2007/10/30 21:32:46 steve
658
* Support for multiple tile columns.
659
*
660
* Revision 1.7 2007/09/08 01:01:43 steve
661
* YUV444 color parses properly.
662
*
663
* Revision 1.6 2007/09/04 19:10:46 steve
664
* Finish level1 overlap filtering.
665
*
666
* Revision 1.5 2007/08/15 01:54:11 steve
667
* Add level2 filter to decoder.
668
*
669
* Revision 1.4 2007/08/04 00:15:31 steve
670
* Allow width/height of 1 pixel.
671
*
672
* Revision 1.3 2007/07/21 00:25:48 steve
673
* snapshot 2007 07 20
674
*
675
* Revision 1.2 2007/06/28 20:03:11 steve
676
* LP processing seems to be OK now.
677
*
678
* Revision 1.1 2007/06/06 17:19:12 steve
679
* Introduce to CVS.
680
*
681
*/
682