changeset 8516:315b302fcd1d libavcodec

Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
author michael
date Sat, 03 Jan 2009 19:17:18 +0000
parents 45506d633cdc
children 7e6cf3ff61d3
files avcodec.h dvbsub.c dvbsubdec.c dvdsubdec.c dvdsubenc.c xsubdec.c
diffstat 6 files changed, 52 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/avcodec.h	Sat Jan 03 18:41:35 2009 +0000
+++ b/avcodec.h	Sat Jan 03 19:17:18 2009 +0000
@@ -2399,9 +2399,12 @@
     int w;         ///< width            of pict, undefined when pict is not set
     int h;         ///< height           of pict, undefined when pict is not set
     int nb_colors; ///< number of colors in pict, undefined when pict is not set
-    int linesize;
-    uint32_t *rgba_palette;
-    uint8_t *bitmap;
+
+    /**
+     * data+linesize for the bitmap of this subtitle.
+     * can be set for text/ass as well once they where rendered
+     */
+    AVPicture pict;
 } AVSubtitleRect;
 
 typedef struct AVSubtitle {
--- a/dvbsub.c	Sat Jan 03 18:41:35 2009 +0000
+++ b/dvbsub.c	Sat Jan 03 19:17:18 2009 +0000
@@ -262,10 +262,11 @@
                 *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */
                 {
                     int a, r, g, b;
-                    a = (h->rects[clut_id]->rgba_palette[i] >> 24) & 0xff;
-                    r = (h->rects[clut_id]->rgba_palette[i] >> 16) & 0xff;
-                    g = (h->rects[clut_id]->rgba_palette[i] >> 8) & 0xff;
-                    b = (h->rects[clut_id]->rgba_palette[i] >> 0) & 0xff;
+                    uint32_t x= ((uint32_t*)h->rects[clut_id]->pict.data[1])[i];
+                    a = (x >> 24) & 0xff;
+                    r = (x >> 16) & 0xff;
+                    g = (x >>  8) & 0xff;
+                    b = (x >>  0) & 0xff;
 
                     *q++ = RGB_TO_Y_CCIR(r, g, b);
                     *q++ = RGB_TO_V_CCIR(r, g, b, 0);
@@ -358,10 +359,10 @@
                     dvb_encode_rle = dvb_encode_rle4;
 
                 top_ptr = q;
-                dvb_encode_rle(&q, h->rects[object_id]->bitmap, h->rects[object_id]->w * 2,
+                dvb_encode_rle(&q, h->rects[object_id]->pict.data[0], h->rects[object_id]->w * 2,
                                     h->rects[object_id]->w, h->rects[object_id]->h >> 1);
                 bottom_ptr = q;
-                dvb_encode_rle(&q, h->rects[object_id]->bitmap + h->rects[object_id]->w,
+                dvb_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w,
                                     h->rects[object_id]->w * 2, h->rects[object_id]->w,
                                     h->rects[object_id]->h >> 1);
 
--- a/dvbsubdec.c	Sat Jan 03 18:41:35 2009 +0000
+++ b/dvbsubdec.c	Sat Jan 03 19:17:18 2009 +0000
@@ -1305,7 +1305,7 @@
         rect->w = region->width;
         rect->h = region->height;
         rect->nb_colors = 16;
-        rect->linesize = region->width;
+        rect->pict.linesize[0] = region->width;
 
         clut = get_clut(ctx, region->clut);
 
@@ -1325,11 +1325,11 @@
             break;
         }
 
-        rect->rgba_palette = av_malloc((1 << region->depth) * sizeof(uint32_t));
-        memcpy(rect->rgba_palette, clut_table, (1 << region->depth) * sizeof(uint32_t));
+        rect->pict.data[1] = av_malloc((1 << region->depth) * sizeof(uint32_t));
+        memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
 
-        rect->bitmap = av_malloc(region->buf_size);
-        memcpy(rect->bitmap, region->pbuf, region->buf_size);
+        rect->pict.data[0] = av_malloc(region->buf_size);
+        memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
 
         i++;
     }
--- a/dvdsubdec.c	Sat Jan 03 18:41:35 2009 +0000
+++ b/dvdsubdec.c	Sat Jan 03 19:17:18 2009 +0000
@@ -319,8 +319,8 @@
             if (w > 0 && h > 0) {
                 if (sub_header->rects != NULL) {
                     for (i = 0; i < sub_header->num_rects; i++) {
-                        av_freep(&sub_header->rects[i]->bitmap);
-                        av_freep(&sub_header->rects[i]->rgba_palette);
+                        av_freep(&sub_header->rects[i]->pict.data[0]);
+                        av_freep(&sub_header->rects[i]->pict.data[1]);
                         av_freep(&sub_header->rects[i]);
                     }
                     av_freep(&sub_header->rects);
@@ -331,7 +331,7 @@
                 sub_header->rects = av_mallocz(sizeof(*sub_header->rects));
                 sub_header->rects[0] = av_mallocz(sizeof(AVSubtitleRect));
                 sub_header->num_rects = 1;
-                sub_header->rects[0]->bitmap = bitmap;
+                sub_header->rects[0]->pict.data[0] = bitmap;
                 decode_rle(bitmap, w * 2, w, (h + 1) / 2,
                            buf, offset1, buf_size, is_8bit);
                 decode_rle(bitmap + w, w * 2, w, h / 2,
@@ -339,20 +339,20 @@
                 if (is_8bit) {
                     if (yuv_palette == 0)
                         goto fail;
-                    sub_header->rects[0]->rgba_palette = av_malloc(256 * 4);
+                    sub_header->rects[0]->pict.data[1] = av_malloc(256 * 4);
                     sub_header->rects[0]->nb_colors = 256;
-                    yuv_a_to_rgba(yuv_palette, alpha, sub_header->rects[0]->rgba_palette, 256);
+                    yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256);
                 } else {
-                    sub_header->rects[0]->rgba_palette = av_malloc(4 * 4);
+                    sub_header->rects[0]->pict.data[1] = av_malloc(4 * 4);
                     sub_header->rects[0]->nb_colors = 4;
-                    guess_palette(sub_header->rects[0]->rgba_palette,
+                    guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1],
                                   colormap, alpha, 0xffff00);
                 }
                 sub_header->rects[0]->x = x1;
                 sub_header->rects[0]->y = y1;
                 sub_header->rects[0]->w = w;
                 sub_header->rects[0]->h = h;
-                sub_header->rects[0]->linesize = w;
+                sub_header->rects[0]->pict.linesize[0] = w;
             }
         }
         if (next_cmd_pos == cmd_pos)
@@ -364,8 +364,8 @@
  fail:
     if (sub_header->rects != NULL) {
         for (i = 0; i < sub_header->num_rects; i++) {
-            av_freep(&sub_header->rects[i]->bitmap);
-            av_freep(&sub_header->rects[i]->rgba_palette);
+            av_freep(&sub_header->rects[i]->pict.data[0]);
+            av_freep(&sub_header->rects[i]->pict.data[1]);
             av_freep(&sub_header->rects[i]);
         }
         av_freep(&sub_header->rects);
@@ -398,29 +398,29 @@
 
     memset(transp_color, 0, 256);
     for(i = 0; i < s->rects[0]->nb_colors; i++) {
-        if ((s->rects[0]->rgba_palette[i] >> 24) == 0)
+        if ((((uint32_t*)s->rects[0]->pict.data[1])[i] >> 24) == 0)
             transp_color[i] = 1;
     }
     y1 = 0;
-    while (y1 < s->rects[0]->h && is_transp(s->rects[0]->bitmap + y1 * s->rects[0]->linesize,
+    while (y1 < s->rects[0]->h && is_transp(s->rects[0]->pict.data[0] + y1 * s->rects[0]->pict.linesize[0],
                                   1, s->rects[0]->w, transp_color))
         y1++;
     if (y1 == s->rects[0]->h) {
-        av_freep(&s->rects[0]->bitmap);
+        av_freep(&s->rects[0]->pict.data[0]);
         s->rects[0]->w = s->rects[0]->h = 0;
         return 0;
     }
 
     y2 = s->rects[0]->h - 1;
-    while (y2 > 0 && is_transp(s->rects[0]->bitmap + y2 * s->rects[0]->linesize, 1,
+    while (y2 > 0 && is_transp(s->rects[0]->pict.data[0] + y2 * s->rects[0]->pict.linesize[0], 1,
                                s->rects[0]->w, transp_color))
         y2--;
     x1 = 0;
-    while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->bitmap + x1, s->rects[0]->linesize,
+    while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->pict.data[0] + x1, s->rects[0]->pict.linesize[0],
                                         s->rects[0]->h, transp_color))
         x1++;
     x2 = s->rects[0]->w - 1;
-    while (x2 > 0 && is_transp(s->rects[0]->bitmap + x2, s->rects[0]->linesize, s->rects[0]->h,
+    while (x2 > 0 && is_transp(s->rects[0]->pict.data[0] + x2, s->rects[0]->pict.linesize[0], s->rects[0]->h,
                                   transp_color))
         x2--;
     w = x2 - x1 + 1;
@@ -429,11 +429,11 @@
     if (!bitmap)
         return 1;
     for(y = 0; y < h; y++) {
-        memcpy(bitmap + w * y, s->rects[0]->bitmap + x1 + (y1 + y) * s->rects[0]->linesize, w);
+        memcpy(bitmap + w * y, s->rects[0]->pict.data[0] + x1 + (y1 + y) * s->rects[0]->pict.linesize[0], w);
     }
-    av_freep(&s->rects[0]->bitmap);
-    s->rects[0]->bitmap = bitmap;
-    s->rects[0]->linesize = w;
+    av_freep(&s->rects[0]->pict.data[0]);
+    s->rects[0]->pict.data[0] = bitmap;
+    s->rects[0]->pict.linesize[0] = w;
     s->rects[0]->w = w;
     s->rects[0]->h = h;
     s->rects[0]->x += x1;
@@ -494,8 +494,8 @@
     av_log(NULL, AV_LOG_INFO, "start=%d ms end =%d ms\n",
            sub->start_display_time,
            sub->end_display_time);
-    ppm_save("/tmp/a.ppm", sub->rects[0]->bitmap,
-             sub->rects[0]->w, sub->rects[0]->h, sub->rects[0]->rgba_palette);
+    ppm_save("/tmp/a.ppm", sub->rects[0]->pict.data[0],
+             sub->rects[0]->w, sub->rects[0]->h, sub->rects[0]->pict.data[1]);
 #endif
 
     *data_size = 1;
--- a/dvdsubenc.c	Sat Jan 03 18:41:35 2009 +0000
+++ b/dvdsubenc.c	Sat Jan 03 19:17:18 2009 +0000
@@ -109,9 +109,9 @@
     }
     for (object_id = 0; object_id < rects; object_id++)
         for (i=0; i<h->rects[object_id]->w*h->rects[object_id]->h; ++i) {
-            color = h->rects[object_id]->bitmap[i];
+            color = h->rects[object_id]->pict.data[0][i];
             // only count non-transparent pixels
-            alpha = h->rects[object_id]->rgba_palette[color] >> 24;
+            alpha = ((uint32_t*)h->rects[object_id]->pict.data[1])[color] >> 24;
             hist[color] += alpha;
         }
     for (color=3;; --color) {
@@ -143,12 +143,12 @@
             av_log(NULL, AV_LOG_ERROR, "dvd_subtitle too big\n");
             return -1;
         }
-        dvd_encode_rle(&q, h->rects[object_id]->bitmap,
+        dvd_encode_rle(&q, h->rects[object_id]->pict.data[0],
                        h->rects[object_id]->w*2,
                        h->rects[object_id]->w, h->rects[object_id]->h >> 1,
                        cmap);
         offset2[object_id] = q - outbuf;
-        dvd_encode_rle(&q, h->rects[object_id]->bitmap + h->rects[object_id]->w,
+        dvd_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w,
                        h->rects[object_id]->w*2,
                        h->rects[object_id]->w, h->rects[object_id]->h >> 1,
                        cmap);
--- a/xsubdec.c	Sat Jan 03 18:41:35 2009 +0000
+++ b/xsubdec.c	Sat Jan 03 19:17:18 2009 +0000
@@ -84,28 +84,28 @@
         sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
         sub->num_rects = 1;
     }
-    av_freep(&sub->rects[0]->bitmap);
+    av_freep(&sub->rects[0]->pict.data[0]);
     sub->rects[0]->x = x; sub->rects[0]->y = y;
     sub->rects[0]->w = w; sub->rects[0]->h = h;
-    sub->rects[0]->linesize = w;
-    sub->rects[0]->bitmap = av_malloc(w * h);
+    sub->rects[0]->pict.linesize[0] = w;
+    sub->rects[0]->pict.data[0] = av_malloc(w * h);
     sub->rects[0]->nb_colors = 4;
-    sub->rects[0]->rgba_palette = av_malloc(sub->rects[0]->nb_colors * 4);
+    sub->rects[0]->pict.data[1] = av_malloc(sub->rects[0]->nb_colors * 4);
 
     // read palette
     for (i = 0; i < sub->rects[0]->nb_colors; i++)
-        sub->rects[0]->rgba_palette[i] = bytestream_get_be24(&buf);
+        ((uint32_t*)sub->rects[0]->pict.data[1])[i] = bytestream_get_be24(&buf);
     // make all except background (first entry) non-transparent
     for (i = 1; i < sub->rects[0]->nb_colors; i++)
-        sub->rects[0]->rgba_palette[i] |= 0xff000000;
+        ((uint32_t*)sub->rects[0]->pict.data[1])[i] |= 0xff000000;
 
     // process RLE-compressed data
     rlelen = FFMIN(rlelen, buf_end - buf);
     init_get_bits(&gb, buf, rlelen * 8);
-    bitmap = sub->rects[0]->bitmap;
+    bitmap = sub->rects[0]->pict.data[0];
     for (y = 0; y < h; y++) {
         // interlaced: do odd lines
-        if (y == (h + 1) / 2) bitmap = sub->rects[0]->bitmap + w;
+        if (y == (h + 1) / 2) bitmap = sub->rects[0]->pict.data[0] + w;
         for (x = 0; x < w; ) {
             int log2 = ff_log2_tab[show_bits(&gb, 8)];
             int run = get_bits(&gb, 14 - 4 * (log2 >> 1));