Revision db4fac64

View differences:

ffmpeg.c
1401 1401
        if (subtitle_to_free) {
1402 1402
            if (subtitle_to_free->rects != NULL) {
1403 1403
                for (i = 0; i < subtitle_to_free->num_rects; i++) {
1404
                    av_free(subtitle_to_free->rects[i].bitmap);
1405
                    av_free(subtitle_to_free->rects[i].rgba_palette);
1404
                    av_freep(&subtitle_to_free->rects[i]->bitmap);
1405
                    av_freep(&subtitle_to_free->rects[i]->rgba_palette);
1406
                    av_freep(&subtitle_to_free->rects[i]);
1406 1407
                }
1407 1408
                av_freep(&subtitle_to_free->rects);
1408 1409
            }
ffplay.c
636 636

  
637 637
    for (i = 0; i < sp->sub.num_rects; i++)
638 638
    {
639
        av_free(sp->sub.rects[i].bitmap);
640
        av_free(sp->sub.rects[i].rgba_palette);
639
        av_freep(&sp->sub.rects[i]->bitmap);
640
        av_freep(&sp->sub.rects[i]->rgba_palette);
641
        av_freep(&sp->sub.rects[i]);
641 642
    }
642 643

  
643 644
    av_free(sp->sub.rects);
......
721 722
                    pict.linesize[2] = vp->bmp->pitches[1];
722 723

  
723 724
                    for (i = 0; i < sp->sub.num_rects; i++)
724
                        blend_subrect(&pict, &sp->sub.rects[i],
725
                        blend_subrect(&pict, sp->sub.rects[i],
725 726
                                      vp->bmp->w, vp->bmp->h);
726 727

  
727 728
                    SDL_UnlockYUVOverlay (vp->bmp);
......
1435 1436

  
1436 1437
            for (i = 0; i < sp->sub.num_rects; i++)
1437 1438
            {
1438
                for (j = 0; j < sp->sub.rects[i].nb_colors; j++)
1439
                for (j = 0; j < sp->sub.rects[i]->nb_colors; j++)
1439 1440
                {
1440
                    RGBA_IN(r, g, b, a, sp->sub.rects[i].rgba_palette + j);
1441
                    RGBA_IN(r, g, b, a, sp->sub.rects[i]->rgba_palette + j);
1441 1442
                    y = RGB_TO_Y_CCIR(r, g, b);
1442 1443
                    u = RGB_TO_U_CCIR(r, g, b, 0);
1443 1444
                    v = RGB_TO_V_CCIR(r, g, b, 0);
1444
                    YUVA_OUT(sp->sub.rects[i].rgba_palette + j, y, u, v, a);
1445
                    YUVA_OUT(sp->sub.rects[i]->rgba_palette + j, y, u, v, a);
1445 1446
                }
1446 1447
            }
1447 1448

  
libavcodec/avcodec.h
2409 2409
    uint32_t start_display_time; /* relative to packet pts, in ms */
2410 2410
    uint32_t end_display_time; /* relative to packet pts, in ms */
2411 2411
    uint32_t num_rects;
2412
    AVSubtitleRect *rects;
2412
    AVSubtitleRect **rects;
2413 2413
} AVSubtitle;
2414 2414

  
2415 2415

  
libavcodec/dvbsub.c
228 228
    for (region_id = 0; region_id < h->num_rects; region_id++) {
229 229
        *q++ = region_id;
230 230
        *q++ = 0xff; /* reserved */
231
        bytestream_put_be16(&q, h->rects[region_id].x); /* left pos */
232
        bytestream_put_be16(&q, h->rects[region_id].y); /* top pos */
231
        bytestream_put_be16(&q, h->rects[region_id]->x); /* left pos */
232
        bytestream_put_be16(&q, h->rects[region_id]->y); /* top pos */
233 233
    }
234 234

  
235 235
    bytestream_put_be16(&pseg_len, q - pseg_len - 2);
......
239 239

  
240 240
            /* CLUT segment */
241 241

  
242
            if (h->rects[clut_id].nb_colors <= 4) {
242
            if (h->rects[clut_id]->nb_colors <= 4) {
243 243
                /* 2 bpp, some decoders do not support it correctly */
244 244
                bpp_index = 0;
245
            } else if (h->rects[clut_id].nb_colors <= 16) {
245
            } else if (h->rects[clut_id]->nb_colors <= 16) {
246 246
                /* 4 bpp, standard encoding */
247 247
                bpp_index = 1;
248 248
            } else {
......
257 257
            *q++ = clut_id;
258 258
            *q++ = (0 << 4) | 0xf; /* version = 0 */
259 259

  
260
            for(i = 0; i < h->rects[clut_id].nb_colors; i++) {
260
            for(i = 0; i < h->rects[clut_id]->nb_colors; i++) {
261 261
                *q++ = i; /* clut_entry_id */
262 262
                *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */
263 263
                {
264 264
                    int a, r, g, b;
265
                    a = (h->rects[clut_id].rgba_palette[i] >> 24) & 0xff;
266
                    r = (h->rects[clut_id].rgba_palette[i] >> 16) & 0xff;
267
                    g = (h->rects[clut_id].rgba_palette[i] >> 8) & 0xff;
268
                    b = (h->rects[clut_id].rgba_palette[i] >> 0) & 0xff;
265
                    a = (h->rects[clut_id]->rgba_palette[i] >> 24) & 0xff;
266
                    r = (h->rects[clut_id]->rgba_palette[i] >> 16) & 0xff;
267
                    g = (h->rects[clut_id]->rgba_palette[i] >> 8) & 0xff;
268
                    b = (h->rects[clut_id]->rgba_palette[i] >> 0) & 0xff;
269 269

  
270 270
                    *q++ = RGB_TO_Y_CCIR(r, g, b);
271 271
                    *q++ = RGB_TO_V_CCIR(r, g, b, 0);
......
282 282

  
283 283
        /* region composition segment */
284 284

  
285
        if (h->rects[region_id].nb_colors <= 4) {
285
        if (h->rects[region_id]->nb_colors <= 4) {
286 286
            /* 2 bpp, some decoders do not support it correctly */
287 287
            bpp_index = 0;
288
        } else if (h->rects[region_id].nb_colors <= 16) {
288
        } else if (h->rects[region_id]->nb_colors <= 16) {
289 289
            /* 4 bpp, standard encoding */
290 290
            bpp_index = 1;
291 291
        } else {
......
299 299
        q += 2; /* segment length */
300 300
        *q++ = region_id;
301 301
        *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */
302
        bytestream_put_be16(&q, h->rects[region_id].w); /* region width */
303
        bytestream_put_be16(&q, h->rects[region_id].h); /* region height */
302
        bytestream_put_be16(&q, h->rects[region_id]->w); /* region width */
303
        bytestream_put_be16(&q, h->rects[region_id]->h); /* region height */
304 304
        *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03;
305 305
        *q++ = region_id; /* clut_id == region_id */
306 306
        *q++ = 0; /* 8 bit fill colors */
......
322 322
        for (object_id = 0; object_id < h->num_rects; object_id++) {
323 323
            /* Object Data segment */
324 324

  
325
            if (h->rects[object_id].nb_colors <= 4) {
325
            if (h->rects[object_id]->nb_colors <= 4) {
326 326
                /* 2 bpp, some decoders do not support it correctly */
327 327
                bpp_index = 0;
328
            } else if (h->rects[object_id].nb_colors <= 16) {
328
            } else if (h->rects[object_id]->nb_colors <= 16) {
329 329
                /* 4 bpp, standard encoding */
330 330
                bpp_index = 1;
331 331
            } else {
......
358 358
                    dvb_encode_rle = dvb_encode_rle4;
359 359

  
360 360
                top_ptr = q;
361
                dvb_encode_rle(&q, h->rects[object_id].bitmap, h->rects[object_id].w * 2,
362
                                    h->rects[object_id].w, h->rects[object_id].h >> 1);
361
                dvb_encode_rle(&q, h->rects[object_id]->bitmap, h->rects[object_id]->w * 2,
362
                                    h->rects[object_id]->w, h->rects[object_id]->h >> 1);
363 363
                bottom_ptr = q;
364
                dvb_encode_rle(&q, h->rects[object_id].bitmap + h->rects[object_id].w,
365
                                    h->rects[object_id].w * 2, h->rects[object_id].w,
366
                                    h->rects[object_id].h >> 1);
364
                dvb_encode_rle(&q, h->rects[object_id]->bitmap + h->rects[object_id]->w,
365
                                    h->rects[object_id]->w * 2, h->rects[object_id]->w,
366
                                    h->rects[object_id]->h >> 1);
367 367

  
368 368
                bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr);
369 369
                bytestream_put_be16(&pbottom_field_len, q - bottom_ptr);
libavcodec/dvbsubdec.c
1285 1285

  
1286 1286
    sub->num_rects = ctx->display_list_size;
1287 1287

  
1288
    if (sub->num_rects > 0)
1289
        sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects);
1288
    if (sub->num_rects > 0){
1289
        sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects);
1290
        for(i=0; i<sub->num_rects; i++)
1291
            sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
1292
    }
1290 1293

  
1291 1294
    i = 0;
1292 1295

  
1293 1296
    for (display = ctx->display_list; display; display = display->next) {
1294 1297
        region = get_region(ctx, display->region_id);
1295
        rect = &sub->rects[i];
1298
        rect = sub->rects[i];
1296 1299

  
1297 1300
        if (!region)
1298 1301
            continue;
libavcodec/dvdsubenc.c
108 108
        cmap[i] = 0;
109 109
    }
110 110
    for (object_id = 0; object_id < rects; object_id++)
111
        for (i=0; i<h->rects[object_id].w*h->rects[object_id].h; ++i) {
112
            color = h->rects[object_id].bitmap[i];
111
        for (i=0; i<h->rects[object_id]->w*h->rects[object_id]->h; ++i) {
112
            color = h->rects[object_id]->bitmap[i];
113 113
            // only count non-transparent pixels
114
            alpha = h->rects[object_id].rgba_palette[color] >> 24;
114
            alpha = h->rects[object_id]->rgba_palette[color] >> 24;
115 115
            hist[color] += alpha;
116 116
        }
117 117
    for (color=3;; --color) {
......
138 138
    for (object_id = 0; object_id < rects; object_id++) {
139 139
        offset1[object_id] = q - outbuf;
140 140
        // worst case memory requirement: 1 nibble per pixel..
141
        if ((q - outbuf) + h->rects[object_id].w*h->rects[object_id].h/2
141
        if ((q - outbuf) + h->rects[object_id]->w*h->rects[object_id]->h/2
142 142
            + 17*rects + 21 > outbuf_size) {
143 143
            av_log(NULL, AV_LOG_ERROR, "dvd_subtitle too big\n");
144 144
            return -1;
145 145
        }
146
        dvd_encode_rle(&q, h->rects[object_id].bitmap,
147
                       h->rects[object_id].w*2,
148
                       h->rects[object_id].w, h->rects[object_id].h >> 1,
146
        dvd_encode_rle(&q, h->rects[object_id]->bitmap,
147
                       h->rects[object_id]->w*2,
148
                       h->rects[object_id]->w, h->rects[object_id]->h >> 1,
149 149
                       cmap);
150 150
        offset2[object_id] = q - outbuf;
151
        dvd_encode_rle(&q, h->rects[object_id].bitmap + h->rects[object_id].w,
152
                       h->rects[object_id].w*2,
153
                       h->rects[object_id].w, h->rects[object_id].h >> 1,
151
        dvd_encode_rle(&q, h->rects[object_id]->bitmap + h->rects[object_id]->w,
152
                       h->rects[object_id]->w*2,
153
                       h->rects[object_id]->w, h->rects[object_id]->h >> 1,
154 154
                       cmap);
155 155
    }
156 156

  
......
170 170
    // XXX not sure if more than one rect can really be encoded..
171 171
    // 12 bytes per rect
172 172
    for (object_id = 0; object_id < rects; object_id++) {
173
        int x2 = h->rects[object_id].x + h->rects[object_id].w - 1;
174
        int y2 = h->rects[object_id].y + h->rects[object_id].h - 1;
173
        int x2 = h->rects[object_id]->x + h->rects[object_id]->w - 1;
174
        int y2 = h->rects[object_id]->y + h->rects[object_id]->h - 1;
175 175

  
176 176
        *q++ = 0x05;
177 177
        // x1 x2 -> 6 nibbles
178
        *q++ = h->rects[object_id].x >> 4;
179
        *q++ = (h->rects[object_id].x << 4) | ((x2 >> 8) & 0xf);
178
        *q++ = h->rects[object_id]->x >> 4;
179
        *q++ = (h->rects[object_id]->x << 4) | ((x2 >> 8) & 0xf);
180 180
        *q++ = x2;
181 181
        // y1 y2 -> 6 nibbles
182
        *q++ = h->rects[object_id].y >> 4;
183
        *q++ = (h->rects[object_id].y << 4) | ((y2 >> 8) & 0xf);
182
        *q++ = h->rects[object_id]->y >> 4;
183
        *q++ = (h->rects[object_id]->y << 4) | ((y2 >> 8) & 0xf);
184 184
        *q++ = y2;
185 185

  
186 186
        *q++ = 0x06;
libavcodec/xsubdec.c
80 80

  
81 81
    // allocate sub and set values
82 82
    if (!sub->rects) {
83
        sub->rects = av_mallocz(sizeof(AVSubtitleRect));
83
        sub->rects =  av_mallocz(sizeof(*sub->rects));
84
        sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
84 85
        sub->num_rects = 1;
85 86
    }
86
    av_freep(&sub->rects[0].bitmap);
87
    sub->rects[0].x = x; sub->rects[0].y = y;
88
    sub->rects[0].w = w; sub->rects[0].h = h;
89
    sub->rects[0].linesize = w;
90
    sub->rects[0].bitmap = av_malloc(w * h);
91
    sub->rects[0].nb_colors = 4;
92
    sub->rects[0].rgba_palette = av_malloc(sub->rects[0].nb_colors * 4);
87
    av_freep(&sub->rects[0]->bitmap);
88
    sub->rects[0]->x = x; sub->rects[0]->y = y;
89
    sub->rects[0]->w = w; sub->rects[0]->h = h;
90
    sub->rects[0]->linesize = w;
91
    sub->rects[0]->bitmap = av_malloc(w * h);
92
    sub->rects[0]->nb_colors = 4;
93
    sub->rects[0]->rgba_palette = av_malloc(sub->rects[0]->nb_colors * 4);
93 94

  
94 95
    // read palette
95
    for (i = 0; i < sub->rects[0].nb_colors; i++)
96
        sub->rects[0].rgba_palette[i] = bytestream_get_be24(&buf);
96
    for (i = 0; i < sub->rects[0]->nb_colors; i++)
97
        sub->rects[0]->rgba_palette[i] = bytestream_get_be24(&buf);
97 98
    // make all except background (first entry) non-transparent
98
    for (i = 1; i < sub->rects[0].nb_colors; i++)
99
        sub->rects[0].rgba_palette[i] |= 0xff000000;
99
    for (i = 1; i < sub->rects[0]->nb_colors; i++)
100
        sub->rects[0]->rgba_palette[i] |= 0xff000000;
100 101

  
101 102
    // process RLE-compressed data
102 103
    rlelen = FFMIN(rlelen, buf_end - buf);
103 104
    init_get_bits(&gb, buf, rlelen * 8);
104
    bitmap = sub->rects[0].bitmap;
105
    bitmap = sub->rects[0]->bitmap;
105 106
    for (y = 0; y < h; y++) {
106 107
        // interlaced: do odd lines
107
        if (y == (h + 1) / 2) bitmap = sub->rects[0].bitmap + w;
108
        if (y == (h + 1) / 2) bitmap = sub->rects[0]->bitmap + w;
108 109
        for (x = 0; x < w; ) {
109 110
            int log2 = ff_log2_tab[show_bits(&gb, 8)];
110 111
            int run = get_bits(&gb, 14 - 4 * (log2 >> 1));

Also available in: Unified diff