diff options
author | wm4 <wm4@nowhere> | 2016-06-17 20:10:39 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-06-17 23:13:14 +0200 |
commit | f72eb5b394c5145c1f5ae2546f8c628550e928e4 (patch) | |
tree | 3d325fa0f00af42969f5b9511aa51e97a2bdd7d0 /sub/img_convert.c | |
parent | 454fff39ad2fbcdc0e26ae556996ca4e96eb4288 (diff) | |
download | mpv-f72eb5b394c5145c1f5ae2546f8c628550e928e4.tar.bz2 mpv-f72eb5b394c5145c1f5ae2546f8c628550e928e4.tar.xz |
sub: move paletted image handling completely to sd_lavc.c
Until now, subtitle renderers could export SUBBITMAP_INDEXED, which is a
8 bit per pixel with palette format. sd_lavc.c was the only renderer
doing this, and the result was converted to RGBA in every use-case
(except maybe when the subtitles were hidden.)
Change it so that sd_lavc.c converts to RGBA on its own. This simplifies
everything a bit, and the palette handling can be removed from the
common code.
This is also preparation for making subtitle images refcounted. The
"caching" in img_convert.c is a PITA in this respect, and needs to be
redone. So getting rid of some img_convert.c code is a positive side-
effect. Also related to refcounted subtitles is packing them into a
single mp_image. Fewer objects to refcount is easier, and for the libass
format the same will be done. The plan is to remove manual packing from
the VOs which need single images entirely.
Diffstat (limited to 'sub/img_convert.c')
-rw-r--r-- | sub/img_convert.c | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/sub/img_convert.c b/sub/img_convert.c index d86b8f4ad1..ebf9c209da 100644 --- a/sub/img_convert.c +++ b/sub/img_convert.c @@ -41,60 +41,6 @@ struct osd_conv_cache *osd_conv_cache_new(void) return talloc_zero(NULL, struct osd_conv_cache); } -static void rgba_to_premultiplied_rgba(uint32_t *colors, size_t count) -{ - for (int n = 0; n < count; n++) { - uint32_t c = colors[n]; - unsigned b = c & 0xFF; - unsigned g = (c >> 8) & 0xFF; - unsigned r = (c >> 16) & 0xFF; - unsigned a = (c >> 24) & 0xFF; - b = b * a / 255; - g = g * a / 255; - r = r * a / 255; - colors[n] = b | (g << 8) | (r << 16) | (a << 24); - } -} - -bool osd_conv_idx_to_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs) -{ - struct sub_bitmaps src = *imgs; - if (src.format != SUBBITMAP_INDEXED) - return false; - - imgs->format = SUBBITMAP_RGBA; - talloc_free(c->parts); - imgs->parts = c->parts = talloc_array(c, struct sub_bitmap, src.num_parts); - - for (int n = 0; n < src.num_parts; n++) { - struct sub_bitmap *d = &imgs->parts[n]; - struct sub_bitmap *s = &src.parts[n]; - struct osd_bmp_indexed sb = *(struct osd_bmp_indexed *)s->bitmap; - - rgba_to_premultiplied_rgba(sb.palette, 256); - - *d = *s; - struct mp_image *image = mp_image_alloc(IMGFMT_BGRA, s->w, s->h); - talloc_steal(c->parts, image); - if (!image) { - // on OOM, skip the region by making it 0 sized - d->w = d->h = d->dw = d->dh = 0; - continue; - } - - d->stride = image->stride[0]; - d->bitmap = image->planes[0]; - - for (int y = 0; y < s->h; y++) { - uint8_t *inbmp = sb.bitmap + y * s->stride; - uint32_t *outbmp = (uint32_t*)((uint8_t*)d->bitmap + y * d->stride); - for (int x = 0; x < s->w; x++) - *outbmp++ = sb.palette[*inbmp++]; - } - } - return true; -} - bool osd_conv_blur_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs, double gblur) { @@ -193,41 +139,6 @@ bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs) return true; } -static void rgba_to_gray(uint32_t *colors, size_t count) -{ - for (int n = 0; n < count; n++) { - uint32_t c = colors[n]; - int b = c & 0xFF; - int g = (c >> 8) & 0xFF; - int r = (c >> 16) & 0xFF; - int a = (c >> 24) & 0xFF; - r = g = b = (r + g + b) / 3; - colors[n] = b | (g << 8) | (r << 16) | (a << 24); - } -} - -bool osd_conv_idx_to_gray(struct osd_conv_cache *c, struct sub_bitmaps *imgs) -{ - struct sub_bitmaps src = *imgs; - if (src.format != SUBBITMAP_INDEXED) - return false; - - talloc_free(c->parts); - imgs->parts = c->parts = talloc_array(c, struct sub_bitmap, src.num_parts); - - for (int n = 0; n < src.num_parts; n++) { - struct sub_bitmap *d = &imgs->parts[n]; - struct sub_bitmap *s = &src.parts[n]; - struct osd_bmp_indexed sb = *(struct osd_bmp_indexed *)s->bitmap; - - rgba_to_gray(sb.palette, 256); - - *d = *s; - d->bitmap = talloc_memdup(c->parts, &sb, sizeof(sb)); - } - return true; -} - static void draw_ass_rgba(unsigned char *src, int src_w, int src_h, int src_stride, unsigned char *dst, size_t dst_stride, int dst_x, int dst_y, uint32_t color) |