summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-07-03 19:05:19 +0200
committerwm4 <wm4@nowhere>2016-07-03 19:32:00 +0200
commit59972fbfe119cd09b59cba8b9553acf0a6e5c035 (patch)
treea94f74a851f5348e45413206582aab936d26f8e7
parentf1105528981fc83c5dbf15f1c1d409fb8842a1ea (diff)
downloadmpv-59972fbfe119cd09b59cba8b9553acf0a6e5c035.tar.bz2
mpv-59972fbfe119cd09b59cba8b9553acf0a6e5c035.tar.xz
sub: move around some code
Put the packing code into separate functions. Preparation for the following commit.
-rw-r--r--sub/ass_mp.c99
1 files changed, 60 insertions, 39 deletions
diff --git a/sub/ass_mp.c b/sub/ass_mp.c
index ed9db5436e..fc2c17d115 100644
--- a/sub/ass_mp.c
+++ b/sub/ass_mp.c
@@ -165,6 +165,65 @@ struct mp_ass_packer *mp_ass_packer_alloc(void *ta_parent)
return p;
}
+static bool pack(struct mp_ass_packer *p, struct sub_bitmaps *res, int imgfmt)
+{
+ packer_set_size(p->packer, res->num_parts);
+
+ for (int n = 0; n < res->num_parts; n++)
+ p->packer->in[n] = (struct pos){res->parts[n].w, res->parts[n].h};
+
+ if (p->packer->count == 0 || packer_pack(p->packer) < 0)
+ return false;
+
+ struct pos bb[2];
+ packer_get_bb(p->packer, bb);
+
+ res->packed_w = bb[1].x;
+ res->packed_h = bb[1].y;
+
+ if (!p->cached_img || p->cached_img->w < res->packed_w ||
+ p->cached_img->h < res->packed_h)
+ {
+ talloc_free(p->cached_img);
+ p->cached_img = mp_image_alloc(imgfmt, p->packer->w, p->packer->h);
+ if (!p->cached_img)
+ return false;
+ talloc_steal(p, p->cached_img);
+ }
+
+ res->packed = p->cached_img;
+
+ for (int n = 0; n < res->num_parts; n++) {
+ struct sub_bitmap *b = &res->parts[n];
+ struct pos pos = p->packer->result[n];
+
+ b->src_x = pos.x;
+ b->src_y = pos.y;
+ }
+
+ return true;
+}
+
+static bool pack_libass(struct mp_ass_packer *p, struct sub_bitmaps *res)
+{
+ if (!pack(p, res, IMGFMT_Y8))
+ return false;
+
+ for (int n = 0; n < res->num_parts; n++) {
+ struct sub_bitmap *b = &res->parts[n];
+
+ int stride = res->packed->stride[0];
+ void *pdata =
+ (uint8_t *)res->packed->planes[0] + b->src_y * stride + b->src_x;
+ memcpy_pic(pdata, b->bitmap, b->w, b->h, stride, b->stride);
+
+ b->bitmap = pdata;
+ b->stride = stride;
+ }
+
+ return true;
+}
+
// Pack the contents of image_lists[0] to image_lists[num_image_lists-1] into
// a single image, and make *out point to it. *out is completely overwritten.
// If libass reported any change, image_lists_changed must be set (it then
@@ -206,47 +265,9 @@ void mp_ass_packer_pack(struct mp_ass_packer *p, ASS_Image **image_lists,
}
}
- packer_set_size(p->packer, res.num_parts);
-
- for (int n = 0; n < res.num_parts; n++)
- p->packer->in[n] = (struct pos){res.parts[n].w, res.parts[n].h};
-
- if (p->packer->count == 0 || packer_pack(p->packer) < 0)
+ if (!pack_libass(p, &res))
return;
- struct pos bb[2];
- packer_get_bb(p->packer, bb);
-
- res.packed_w = bb[1].x;
- res.packed_h = bb[1].y;
-
- if (!p->cached_img || p->cached_img->w < res.packed_w ||
- p->cached_img->h < res.packed_h)
- {
- talloc_free(p->cached_img);
- p->cached_img = mp_image_alloc(IMGFMT_Y8, p->packer->w, p->packer->h);
- if (!p->cached_img)
- return;
- talloc_steal(p, p->cached_img);
- }
-
- res.packed = p->cached_img;
-
- for (int n = 0; n < res.num_parts; n++) {
- struct sub_bitmap *b = &res.parts[n];
- struct pos pos = p->packer->result[n];
-
- int stride = res.packed->stride[0];
- void *pdata = (uint8_t *)res.packed->planes[0] + pos.y * stride + pos.x;
- memcpy_pic(pdata, b->bitmap, b->w, b->h, stride, b->stride);
-
- b->bitmap = pdata;
- b->stride = stride;
-
- b->src_x = pos.x;
- b->src_y = pos.y;
- }
-
*out = res;
p->cached_subs = res;
p->cached_subs.change_id = 0;