Revision db4fac64 libavcodec/xsubdec.c

View differences:

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