summaryrefslogtreecommitdiffstats
path: root/libmpcodecs/vf_ass.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmpcodecs/vf_ass.c')
-rw-r--r--libmpcodecs/vf_ass.c137
1 files changed, 69 insertions, 68 deletions
diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c
index b88e7b37df..b13b148600 100644
--- a/libmpcodecs/vf_ass.c
+++ b/libmpcodecs/vf_ass.c
@@ -31,6 +31,7 @@
#include "config.h"
#include "mp_msg.h"
#include "help_mp.h"
+#include "options.h"
#include "img_format.h"
#include "mp_image.h"
@@ -65,33 +66,34 @@ static const struct vf_priv_s {
ass_renderer_t* ass_priv;
unsigned char* planes[3];
- unsigned char* dirty_rows;
+ struct line_limits {
+ uint16_t start;
+ uint16_t end;
+ } *line_limits;
} vf_priv_dflt;
-extern int opt_screen_size_x;
-extern int opt_screen_size_y;
-
extern ass_track_t* ass_track;
extern float sub_delay;
extern int sub_visibility;
-static int config(struct vf_instance_s* vf,
+static int config(struct vf_instance* vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt)
{
+ struct MPOpts *opts = vf->opts;
if (outfmt == IMGFMT_IF09) return 0;
vf->priv->outh = height + ass_top_margin + ass_bottom_margin;
vf->priv->outw = width;
- if(!opt_screen_size_x && !opt_screen_size_y){
+ if (!opts->screen_size_x && !opts->screen_size_y) {
d_width = d_width * vf->priv->outw / width;
d_height = d_height * vf->priv->outh / height;
}
vf->priv->planes[1] = malloc(vf->priv->outw * vf->priv->outh);
vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh);
- vf->priv->dirty_rows = malloc(vf->priv->outh);
+ vf->priv->line_limits = malloc((vf->priv->outh + 1) / 2 * sizeof(*vf->priv->line_limits));
if (vf->priv->ass_priv) {
ass_configure(vf->priv->ass_priv, vf->priv->outw, vf->priv->outh, 0);
@@ -101,7 +103,7 @@ static int config(struct vf_instance_s* vf,
return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, d_height, flags, outfmt);
}
-static void get_image(struct vf_instance_s* vf, mp_image_t *mpi)
+static void get_image(struct vf_instance* vf, mp_image_t *mpi)
{
if(mpi->type == MP_IMGTYPE_IPB) return;
if(mpi->flags & MP_IMGFLAG_PRESERVE) return;
@@ -115,7 +117,7 @@ static void get_image(struct vf_instance_s* vf, mp_image_t *mpi)
if((vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) &&
!(vf->dmpi->flags & MP_IMGFLAG_DIRECT)){
- mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible);
+ mp_tmsg(MSGT_ASS, MSGL_INFO, "Full DR not possible, trying SLICES instead!\n");
return;
}
@@ -160,11 +162,11 @@ static void blank(mp_image_t *mpi, int y1, int y2)
}
}
-static int prepare_image(struct vf_instance_s* vf, mp_image_t *mpi)
+static int prepare_image(struct vf_instance* vf, mp_image_t *mpi)
{
if(mpi->flags&MP_IMGFLAG_DIRECT || mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){
vf->dmpi = mpi->priv;
- if (!vf->dmpi) { mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL); return 0; }
+ if (!vf->dmpi) { mp_tmsg(MSGT_ASS, MSGL_WARN, "Why do we get NULL??\n"); return 0; }
mpi->priv = NULL;
// we've used DR, so we're ready...
if (ass_top_margin)
@@ -205,55 +207,58 @@ static int prepare_image(struct vf_instance_s* vf, mp_image_t *mpi)
return 0;
}
+static void update_limits(struct vf_instance *vf, int starty, int endy,
+ int startx, int endx)
+{
+ starty >>= 1;
+ endy = (endy + 1) >> 1;
+ startx >>= 1;
+ endx = (endx + 1) >> 1;
+ for (int i = starty; i < endy; i++) {
+ struct line_limits *ll = vf->priv->line_limits + i;
+ if (startx < ll->start)
+ ll->start = startx;
+ if (endx > ll->end)
+ ll->end = endx;
+ }
+}
+
/**
* \brief Copy specified rows from render_context.dmpi to render_context.planes, upsampling to 4:4:4
*/
-static void copy_from_image(struct vf_instance_s* vf, int first_row, int last_row)
+static void copy_from_image(struct vf_instance* vf)
{
int pl;
- int i, j, k;
- unsigned char val;
- int chroma_rows;
-
- first_row -= (first_row % 2);
- last_row += (last_row % 2);
- chroma_rows = (last_row - first_row) / 2;
for (pl = 1; pl < 3; ++pl) {
int dst_stride = vf->priv->outw;
int src_stride = vf->dmpi->stride[pl];
- unsigned char* src = vf->dmpi->planes[pl] + (first_row/2) * src_stride;
- unsigned char* dst = vf->priv->planes[pl] + first_row * dst_stride;
- unsigned char* dst_next = dst + dst_stride;
- for(i = 0; i < chroma_rows; ++i)
- {
- if ((vf->priv->dirty_rows[first_row + i*2] == 0) ||
- (vf->priv->dirty_rows[first_row + i*2 + 1] == 0)) {
- for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k+=2) {
- val = *(src + j);
- *(dst + k) = val;
- *(dst + k + 1) = val;
- *(dst_next + k) = val;
- *(dst_next + k + 1) = val;
- }
+ unsigned char* src = vf->dmpi->planes[pl];
+ unsigned char* dst = vf->priv->planes[pl];
+ for (int i = 0; i < (vf->priv->outh + 1) / 2; i++) {
+ struct line_limits *ll = vf->priv->line_limits + i;
+ unsigned char* dst_next = dst + dst_stride;
+ for (int j = ll->start; j < ll->end; j++) {
+ unsigned char val = src[j];
+ dst[j << 1] = val;
+ dst[(j << 1) + 1] = val;
+ dst_next[j << 1] = val;
+ dst_next[(j << 1) + 1] = val;
}
src += src_stride;
dst = dst_next + dst_stride;
- dst_next = dst + dst_stride;
}
}
- for (i = first_row; i < last_row; ++i)
- vf->priv->dirty_rows[i] = 1;
}
/**
* \brief Copy all previously copied rows back to render_context.dmpi
*/
-static void copy_to_image(struct vf_instance_s* vf)
+static void copy_to_image(struct vf_instance* vf)
{
int pl;
- int i, j, k;
+ int i, j;
for (pl = 1; pl < 3; ++pl) {
int dst_stride = vf->dmpi->stride[pl];
int src_stride = vf->priv->outw;
@@ -261,18 +266,14 @@ static void copy_to_image(struct vf_instance_s* vf)
unsigned char* dst = vf->dmpi->planes[pl];
unsigned char* src = vf->priv->planes[pl];
unsigned char* src_next = vf->priv->planes[pl] + src_stride;
- for(i = 0; i < vf->dmpi->chroma_height; ++i)
- {
- if ((vf->priv->dirty_rows[i*2] == 1)) {
- assert(vf->priv->dirty_rows[i*2 + 1] == 1);
- for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k+=2) {
- unsigned val = 0;
- val += *(src + k);
- val += *(src + k + 1);
- val += *(src_next + k);
- val += *(src_next + k + 1);
- *(dst + j) = val >> 2;
- }
+ for (i = 0; i < vf->dmpi->chroma_height; ++i) {
+ for (j = vf->priv->line_limits[i].start; j < vf->priv->line_limits[i].end; j++) {
+ unsigned val = 0;
+ val += src[j << 1];
+ val += src[(j << 1) + 1];
+ val += src_next[j << 1];
+ val += src_next[(j << 1) + 1];
+ dst[j] = val >> 2;
}
dst += dst_stride;
src = src_next + src_stride;
@@ -281,7 +282,7 @@ static void copy_to_image(struct vf_instance_s* vf)
}
}
-static void my_draw_bitmap(struct vf_instance_s* vf, unsigned char* bitmap, int bitmap_w, int bitmap_h, int stride, int dst_x, int dst_y, unsigned color)
+static void my_draw_bitmap(struct vf_instance* vf, unsigned char* bitmap, int bitmap_w, int bitmap_h, int stride, int dst_x, int dst_y, unsigned color)
{
unsigned char y = rgba2y(color);
unsigned char u = rgba2u(color);
@@ -297,10 +298,10 @@ static void my_draw_bitmap(struct vf_instance_s* vf, unsigned char* bitmap, int
dstv = vf->priv->planes[2] + dst_x + dst_y * vf->priv->outw;
for (i = 0; i < bitmap_h; ++i) {
for (j = 0; j < bitmap_w; ++j) {
- unsigned k = ((unsigned)src[j]) * opacity / 255;
- dsty[j] = (k*y + (255-k)*dsty[j]) / 255;
- dstu[j] = (k*u + (255-k)*dstu[j]) / 255;
- dstv[j] = (k*v + (255-k)*dstv[j]) / 255;
+ unsigned k = (src[j] * opacity + 255) >> 8;
+ dsty[j] = (k*y + (255-k)*dsty[j] + 255) >> 8;
+ dstu[j] = (k*u + (255-k)*dstu[j] + 255) >> 8;
+ dstv[j] = (k*v + (255-k)*dstv[j] + 255) >> 8;
}
src += stride;
dsty += dmpi->stride[0];
@@ -309,12 +310,15 @@ static void my_draw_bitmap(struct vf_instance_s* vf, unsigned char* bitmap, int
}
}
-static int render_frame(struct vf_instance_s* vf, mp_image_t *mpi, const ass_image_t* img)
+static int render_frame(struct vf_instance* vf, mp_image_t *mpi, const ass_image_t* img)
{
if (img) {
- memset(vf->priv->dirty_rows, 0, vf->priv->outh); // reset dirty rows
+ for (int i = 0; i < (vf->priv->outh + 1) / 2; i++)
+ vf->priv->line_limits[i] = (struct line_limits){65535, 0};
+ for (const ass_image_t *im = img; im; im = im->next)
+ update_limits(vf, im->dst_y, im->dst_y + im->h, im->dst_x, im->dst_x + im->w);
+ copy_from_image(vf);
while (img) {
- copy_from_image(vf, img->dst_y, img->dst_y + img->h);
my_draw_bitmap(vf, img->bitmap, img->w, img->h, img->stride,
img->dst_x, img->dst_y, img->color);
img = img->next;
@@ -324,7 +328,7 @@ static int render_frame(struct vf_instance_s* vf, mp_image_t *mpi, const ass_ima
return 0;
}
-static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
+static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts)
{
ass_image_t* images = 0;
if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE))
@@ -336,7 +340,7 @@ static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
return vf_next_put_image(vf, vf->dmpi, pts);
}
-static int query_format(struct vf_instance_s* vf, unsigned int fmt)
+static int query_format(struct vf_instance* vf, unsigned int fmt)
{
switch(fmt){
case IMGFMT_YV12:
@@ -362,16 +366,14 @@ static int control(vf_instance_t *vf, int request, void *data)
return vf_next_control(vf, request, data);
}
-static void uninit(struct vf_instance_s* vf)
+static void uninit(struct vf_instance* vf)
{
if (vf->priv->ass_priv)
ass_renderer_done(vf->priv->ass_priv);
- if (vf->priv->planes[1])
- free(vf->priv->planes[1]);
- if (vf->priv->planes[2])
- free(vf->priv->planes[2]);
- if (vf->priv->dirty_rows)
- free(vf->priv->dirty_rows);
+ free(vf->priv->planes[1]);
+ free(vf->priv->planes[2]);
+ free(vf->priv->line_limits);
+ free(vf->priv);
}
static const unsigned int fmt_list[]={
@@ -427,4 +429,3 @@ const vf_info_t vf_info_ass = {
open,
&vf_opts
};
-