summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-10-27 18:06:09 +0200
committerwm4 <wm4@nowhere>2012-11-01 02:07:45 +0100
commit9ba52ea6efd41db9dbd08311380f7fa633e22aa2 (patch)
tree698757630c88e96f323bc66461045234505ace91 /sub
parentd9839fe8623c855b6b335df3a5b9783e3ed22266 (diff)
downloadmpv-9ba52ea6efd41db9dbd08311380f7fa633e22aa2.tar.bz2
mpv-9ba52ea6efd41db9dbd08311380f7fa633e22aa2.tar.xz
screenshot, draw_bmp: use colorspace passed with mp_image
Remove the explicit struct mp_csp_details parameters from all related functions, and use mp_image.colorspace/levels instead.
Diffstat (limited to 'sub')
-rw-r--r--sub/draw_bmp.c73
-rw-r--r--sub/draw_bmp.h2
-rw-r--r--sub/sub.c9
-rw-r--r--sub/sub.h4
4 files changed, 53 insertions, 35 deletions
diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c
index 5f68e17f1d..e693afe137 100644
--- a/sub/draw_bmp.c
+++ b/sub/draw_bmp.c
@@ -43,6 +43,9 @@ struct sub_cache {
struct part {
int bitmap_pos_id;
+ int imgfmt;
+ enum mp_csp colorspace;
+ enum mp_csp_levels levels;
int num_imgs;
struct sub_cache *imgs;
};
@@ -53,7 +56,7 @@ struct mp_draw_sub_cache
};
static struct part *get_cache(struct mp_draw_sub_cache **cache,
- struct sub_bitmaps *sbs);
+ struct sub_bitmaps *sbs, struct mp_image *format);
static bool get_sub_area(struct mp_rect bb, struct mp_image *temp,
struct sub_bitmap *sb, struct mp_image *out_area,
int *out_src_x, int *out_src_y);
@@ -206,22 +209,24 @@ static void unpremultiply_and_split_BGR32(struct mp_image *img,
}
}
-static void scale_sb_rgba(struct sub_bitmap *sb, struct mp_csp_details *csp,
- int imgfmt, struct mp_image **out_sbi,
- struct mp_image **out_sba)
+// dst_format merely contains the target colorspace/format information
+static void scale_sb_rgba(struct sub_bitmap *sb, struct mp_image *dst_format,
+ struct mp_image **out_sbi, struct mp_image **out_sba)
{
struct mp_image *sbisrc = new_mp_image(sb->w, sb->h);
mp_image_setfmt(sbisrc, IMGFMT_BGR32);
sbisrc->planes[0] = sb->bitmap;
sbisrc->stride[0] = sb->stride;
struct mp_image *sbisrc2 = alloc_mpi(sb->dw, sb->dh, IMGFMT_BGR32);
- mp_image_swscale(sbisrc2, sbisrc, csp, SWS_BILINEAR);
+ mp_image_swscale(sbisrc2, sbisrc, SWS_BILINEAR);
struct mp_image *sba = alloc_mpi(sb->dw, sb->dh, IMGFMT_Y8);
unpremultiply_and_split_BGR32(sbisrc2, sba);
- struct mp_image *sbi = alloc_mpi(sb->dw, sb->dh, imgfmt);
- mp_image_swscale(sbi, sbisrc2, csp, SWS_BILINEAR);
+ struct mp_image *sbi = alloc_mpi(sb->dw, sb->dh, dst_format->imgfmt);
+ sbi->colorspace = dst_format->colorspace;
+ sbi->levels = dst_format->levels;
+ mp_image_swscale(sbi, sbisrc2, SWS_BILINEAR);
free_mp_image(sbisrc);
free_mp_image(sbisrc2);
@@ -231,10 +236,10 @@ static void scale_sb_rgba(struct sub_bitmap *sb, struct mp_csp_details *csp,
}
static void draw_rgba(struct mp_draw_sub_cache **cache, struct mp_rect bb,
- struct mp_image *temp, int bits, struct mp_csp_details *csp,
+ struct mp_image *temp, int bits,
struct sub_bitmaps *sbs)
{
- struct part *part = get_cache(cache, sbs);
+ struct part *part = get_cache(cache, sbs, temp);
for (int i = 0; i < sbs->num_parts; ++i) {
struct sub_bitmap *sb = &sbs->parts[i];
@@ -257,7 +262,7 @@ static void draw_rgba(struct mp_draw_sub_cache **cache, struct mp_rect bb,
}
if (!(sbi && sba))
- scale_sb_rgba(sb, csp, temp->imgfmt, &sbi, &sba);
+ scale_sb_rgba(sb, temp, &sbi, &sba);
int bytes = (bits + 7) / 8;
uint8_t *alpha_p = sba->planes[0] + src_y * sba->stride[0] + src_x;
@@ -278,11 +283,12 @@ static void draw_rgba(struct mp_draw_sub_cache **cache, struct mp_rect bb,
}
static void draw_ass(struct mp_draw_sub_cache **cache, struct mp_rect bb,
- struct mp_image *temp, int bits, struct mp_csp_details *csp,
- struct sub_bitmaps *sbs)
+ struct mp_image *temp, int bits, struct sub_bitmaps *sbs)
{
struct mp_csp_params cspar = MP_CSP_PARAMS_DEFAULTS;
- cspar.colorspace = *csp;
+ cspar.colorspace.format = temp->colorspace;
+ cspar.colorspace.levels_in = temp->levels;
+ cspar.colorspace.levels_out = MP_CSP_LEVELS_PC; // RGB (libass.color)
cspar.int_bits_in = bits;
cspar.int_bits_out = 8;
@@ -416,7 +422,7 @@ static void get_closest_y444_format(int imgfmt, int *out_format, int *out_bits)
}
static struct part *get_cache(struct mp_draw_sub_cache **cache,
- struct sub_bitmaps *sbs)
+ struct sub_bitmaps *sbs, struct mp_image *format)
{
if (cache && !*cache)
*cache = talloc_zero(NULL, struct mp_draw_sub_cache);
@@ -426,14 +432,25 @@ static struct part *get_cache(struct mp_draw_sub_cache **cache,
bool use_cache = sbs->format == SUBBITMAP_RGBA;
if (cache && use_cache) {
part = (*cache)->parts[sbs->render_index];
- if (part && part->bitmap_pos_id != sbs->bitmap_pos_id) {
- talloc_free(part);
- part = NULL;
+ if (part) {
+ if (part->bitmap_pos_id != sbs->bitmap_pos_id
+ || part->imgfmt != format->imgfmt
+ || part->colorspace != format->colorspace
+ || part->levels != format->levels)
+ {
+ talloc_free(part);
+ part = NULL;
+ }
}
if (!part) {
- part = talloc_zero(*cache, struct part);
- part->bitmap_pos_id = sbs->bitmap_pos_id;
- part->num_imgs = sbs->num_parts;
+ part = talloc(*cache, struct part);
+ *part = (struct part) {
+ .bitmap_pos_id = sbs->bitmap_pos_id,
+ .num_imgs = sbs->num_parts,
+ .imgfmt = format->imgfmt,
+ .levels = format->levels,
+ .colorspace = format->colorspace,
+ };
part->imgs = talloc_zero_array(part, struct sub_cache,
part->num_imgs);
}
@@ -468,7 +485,7 @@ static bool get_sub_area(struct mp_rect bb, struct mp_image *temp,
// containing scaled versions of sbs contents - free the cache with
// talloc_free()
void mp_draw_sub_bitmaps(struct mp_draw_sub_cache **cache, struct mp_image *dst,
- struct sub_bitmaps *sbs, struct mp_csp_details *csp)
+ struct sub_bitmaps *sbs)
{
assert(mp_draw_sub_formats[sbs->format]);
if (!mp_sws_supported_format(dst->imgfmt))
@@ -491,17 +508,23 @@ void mp_draw_sub_bitmaps(struct mp_draw_sub_cache **cache, struct mp_image *dst,
temp = &dst_region;
} else {
temp = alloc_mpi(bb.x1 - bb.x0, bb.y1 - bb.y0, format);
- mp_image_swscale(temp, &dst_region, csp, SWS_POINT); // chroma up
+ // temp is always YUV, dst_region not
+ // reduce amount of conversions in YUV case (upsampling/shifting only)
+ if (dst_region.flags & MP_IMGFLAG_YUV) {
+ temp->colorspace = dst_region.colorspace;
+ temp->levels = dst_region.levels;
+ }
+ mp_image_swscale(temp, &dst_region, SWS_POINT); // chroma up
}
if (sbs->format == SUBBITMAP_RGBA) {
- draw_rgba(cache, bb, temp, bits, csp, sbs);
+ draw_rgba(cache, bb, temp, bits, sbs);
} else if (sbs->format == SUBBITMAP_LIBASS) {
- draw_ass(cache, bb, temp, bits, csp, sbs);
+ draw_ass(cache, bb, temp, bits, sbs);
}
if (temp != &dst_region) {
- mp_image_swscale(&dst_region, temp, csp, SWS_AREA); // chroma down
+ mp_image_swscale(&dst_region, temp, SWS_AREA); // chroma down
free_mp_image(temp);
}
}
diff --git a/sub/draw_bmp.h b/sub/draw_bmp.h
index b7ebcf5e8a..489e91f666 100644
--- a/sub/draw_bmp.h
+++ b/sub/draw_bmp.h
@@ -8,7 +8,7 @@ struct sub_bitmaps;
struct mp_csp_details;
struct mp_draw_sub_cache;
void mp_draw_sub_bitmaps(struct mp_draw_sub_cache **cache, struct mp_image *dst,
- struct sub_bitmaps *sbs, struct mp_csp_details *csp);
+ struct sub_bitmaps *sbs);
extern const bool mp_draw_sub_formats[SUBBITMAP_COUNT];
diff --git a/sub/sub.c b/sub/sub.c
index 7cea5a3cd1..517de35fc3 100644
--- a/sub/sub.c
+++ b/sub/sub.c
@@ -234,7 +234,6 @@ void osd_draw(struct osd_state *osd, struct mp_osd_res res,
struct draw_on_image_closure {
struct osd_state *osd;
struct mp_image *dest;
- struct mp_csp_details *dest_csp;
bool changed;
};
@@ -242,18 +241,16 @@ static void draw_on_image(void *ctx, struct sub_bitmaps *imgs)
{
struct draw_on_image_closure *closure = ctx;
struct osd_state *osd = closure->osd;
- mp_draw_sub_bitmaps(&osd->draw_cache, closure->dest, imgs,
- closure->dest_csp);
+ mp_draw_sub_bitmaps(&osd->draw_cache, closure->dest, imgs);
talloc_steal(osd, osd->draw_cache);
closure->changed = true;
}
// Returns whether anything was drawn.
bool osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res,
- double video_pts, int draw_flags, struct mp_image *dest,
- struct mp_csp_details *dest_csp)
+ double video_pts, int draw_flags, struct mp_image *dest)
{
- struct draw_on_image_closure closure = {osd, dest, dest_csp};
+ struct draw_on_image_closure closure = {osd, dest};
osd_draw(osd, res, video_pts, draw_flags, mp_draw_sub_formats,
&draw_on_image, &closure);
return closure.changed;
diff --git a/sub/sub.h b/sub/sub.h
index 5013611e61..cdc094d290 100644
--- a/sub/sub.h
+++ b/sub/sub.h
@@ -205,10 +205,8 @@ void osd_draw(struct osd_state *osd, struct mp_osd_res res,
void (*cb)(void *ctx, struct sub_bitmaps *imgs), void *cb_ctx);
struct mp_image;
-struct mp_csp_details;
bool osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res,
- double video_pts, int draw_flags, struct mp_image *dest,
- struct mp_csp_details *dest_csp);
+ double video_pts, int draw_flags, struct mp_image *dest);
struct mp_rect;
bool sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb);