Coverage Report

Created: 2026-10-28 08:05

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