summaryrefslogtreecommitdiffstats
path: root/sub/img_convert.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-07-03 19:11:33 +0200
committerwm4 <wm4@nowhere>2016-07-03 19:32:31 +0200
commit37cf92c07a7d664907ede87e9464680cc36bd5ec (patch)
tree85c5cab0abfe7791e1539b2a1ee6db9a1e5897cc /sub/img_convert.c
parent59972fbfe119cd09b59cba8b9553acf0a6e5c035 (diff)
downloadmpv-37cf92c07a7d664907ede87e9464680cc36bd5ec.tar.bz2
mpv-37cf92c07a7d664907ede87e9464680cc36bd5ec.tar.xz
sub: change how libass output is converted to RGBA in some cases
This affects VOs (or other code which render OSD) which does not support the LIBASS format, but only RGBA. Instead of having a converter stage in osd.c, make mp_ass_packer_pack() output directly in RGBA. In general, this is work towards refcounted subtitle images. Although we could keep the "converter" design, doing it this way seems simpler, at least considering the current situation with only 2 OSD formats. It also prevents copying & packing the data twice, which will lead to better performance. (Although I guess this case is not important at all.) It also fixes --force-rgba-osd-rendering when used with vo_opengl, vo_vdpau, and vo_direct3d.
Diffstat (limited to 'sub/img_convert.c')
-rw-r--r--sub/img_convert.c97
1 files changed, 0 insertions, 97 deletions
diff --git a/sub/img_convert.c b/sub/img_convert.c
index 78be881fdf..e49b7785af 100644
--- a/sub/img_convert.c
+++ b/sub/img_convert.c
@@ -109,103 +109,6 @@ bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs)
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)
-{
- const unsigned int r = (color >> 24) & 0xff;
- const unsigned int g = (color >> 16) & 0xff;
- const unsigned int b = (color >> 8) & 0xff;
- const unsigned int a = 0xff - (color & 0xff);
-
- dst += dst_y * dst_stride + dst_x * 4;
-
- for (int y = 0; y < src_h; y++, dst += dst_stride, src += src_stride) {
- uint32_t *dstrow = (uint32_t *) dst;
- for (int x = 0; x < src_w; x++) {
- const unsigned int v = src[x];
- int rr = (r * a * v);
- int gg = (g * a * v);
- int bb = (b * a * v);
- int aa = a * v;
- uint32_t dstpix = dstrow[x];
- unsigned int dstb = dstpix & 0xFF;
- unsigned int dstg = (dstpix >> 8) & 0xFF;
- unsigned int dstr = (dstpix >> 16) & 0xFF;
- unsigned int dsta = (dstpix >> 24) & 0xFF;
- dstb = (bb + dstb * (255 * 255 - aa)) / (255 * 255);
- dstg = (gg + dstg * (255 * 255 - aa)) / (255 * 255);
- dstr = (rr + dstr * (255 * 255 - aa)) / (255 * 255);
- dsta = (aa * 255 + dsta * (255 * 255 - aa)) / (255 * 255);
- dstrow[x] = dstb | (dstg << 8) | (dstr << 16) | (dsta << 24);
- }
- }
-}
-
-bool osd_conv_ass_to_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs)
-{
- struct sub_bitmaps src = *imgs;
- if (src.format != SUBBITMAP_LIBASS)
- return false;
- assert(!src.scaled); // ASS is always unscaled
-
- struct mp_rect bb_list[MP_SUB_BB_LIST_MAX];
- int num_bb = mp_get_sub_bb_list(&src, bb_list, MP_SUB_BB_LIST_MAX);
-
- imgs->format = SUBBITMAP_RGBA;
- imgs->parts = c->part;
- imgs->num_parts = num_bb;
- imgs->packed = NULL;
-
- size_t newsize = 0;
- for (int n = 0; n < num_bb; n++) {
- struct mp_rect bb = bb_list[n];
- int w = bb.x1 - bb.x0;
- int h = bb.y1 - bb.y0;
- int stride = w * 4;
- newsize += h * stride;
- }
-
- if (talloc_get_size(c->scratch) < newsize) {
- talloc_free(c->scratch);
- c->scratch = talloc_array(c, uint8_t, newsize);
- }
-
- uint8_t *data = c->scratch;
-
- for (int n = 0; n < num_bb; n++) {
- struct mp_rect bb = bb_list[n];
- struct sub_bitmap *bmp = &c->part[n];
-
- bmp->x = bb.x0;
- bmp->y = bb.y0;
- bmp->w = bmp->dw = bb.x1 - bb.x0;
- bmp->h = bmp->dh = bb.y1 - bb.y0;
- bmp->stride = bmp->w * 4;
- bmp->bitmap = data;
- data += bmp->h * bmp->stride;
-
- memset_pic(bmp->bitmap, 0, bmp->w * 4, bmp->h, bmp->stride);
-
- for (int p = 0; p < src.num_parts; p++) {
- struct sub_bitmap *s = &src.parts[p];
-
- // Assume mp_get_sub_bb_list() never splits sub bitmaps
- // So we don't clip/adjust the size of the sub bitmap
- if (s->x > bb.x1 || s->x + s->w < bb.x0 ||
- s->y > bb.y1 || s->y + s->h < bb.y0)
- continue;
-
- draw_ass_rgba(s->bitmap, s->w, s->h, s->stride,
- bmp->bitmap, bmp->stride,
- s->x - bb.x0, s->y - bb.y0,
- s->libass.color);
- }
- }
-
- return true;
-}
-
bool mp_sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb)
{
struct mp_rect bb = {INT_MAX, INT_MAX, INT_MIN, INT_MIN};