summaryrefslogtreecommitdiffstats
path: root/sub/img_convert.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-25 23:32:35 +0100
committerwm4 <wm4@nowhere>2012-11-25 23:40:07 +0100
commit5d5ddb2ad00a13e719585cefbbb59fa307fa2f73 (patch)
tree51c67ee2f25cefbd09bbcb4275e4a3d5ee7a74ac /sub/img_convert.c
parent24bfa82a91a49b0e2a120b719a6b89ac2b1b415b (diff)
downloadmpv-5d5ddb2ad00a13e719585cefbbb59fa307fa2f73.tar.bz2
mpv-5d5ddb2ad00a13e719585cefbbb59fa307fa2f73.tar.xz
sub: add --sub-gray option to display image subs in grayscale
MPlayer/mplayer2 still show DVD subtitles in gray. Depending on who you ask, this can be considered a bug or a feature. Include rendering in gray as explicit feature, so the user can decide what is better. This affects all indexed sub bitmaps entering the OSD rendering path. Currently, this means all image subs are affected by this option, but nothing else.
Diffstat (limited to 'sub/img_convert.c')
-rw-r--r--sub/img_convert.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/sub/img_convert.c b/sub/img_convert.c
index 274a83d833..578a20b646 100644
--- a/sub/img_convert.c
+++ b/sub/img_convert.c
@@ -128,3 +128,38 @@ bool osd_conv_blur_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;
+}