aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Eugen Hoyos <cehoyos@ag.or.at>2013-10-24 11:10:49 +0200
committerCarl Eugen Hoyos <cehoyos@ag.or.at>2013-10-24 11:56:36 +0200
commitf60c3a7c1b1ef3fa5adf4ea62bbe7b8ba346f7c5 (patch)
tree2376dce4985f24a90972988e6a7026b3ec3c010e
parentb2fdf3fc35b6dca8ac7f6d46bd73ea5eb1339193 (diff)
downloadffmpeg-f60c3a7c1b1ef3fa5adf4ea62bbe7b8ba346f7c5.tar.gz
lavd/x11grab: Support AV_PIX_FMT_PAL8.
Fixes ticket #3068.
-rw-r--r--libavdevice/x11grab.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c
index eb23ec332d..0e7b6ae5ee 100644
--- a/libavdevice/x11grab.c
+++ b/libavdevice/x11grab.c
@@ -77,6 +77,8 @@ struct x11grab {
int follow_mouse; /**< Set by a private option. */
int show_region; /**< set by a private option. */
AVRational framerate; /**< Set by a private option. */
+ int palette_changed;
+ uint32_t palette[256];
Cursor c;
Window region_win; /**< This is used by show_region option. */
@@ -167,6 +169,9 @@ x11grab_read_header(AVFormatContext *s1)
int use_shm;
char *dpyname, *offset;
int ret = 0;
+ Colormap color_map;
+ XColor color[256];
+ int i;
dpyname = av_strdup(s1->filename);
if (!dpyname)
@@ -258,6 +263,15 @@ x11grab_read_header(AVFormatContext *s1)
case 8:
av_log (s1, AV_LOG_DEBUG, "8 bit palette\n");
input_pixfmt = AV_PIX_FMT_PAL8;
+ color_map = DefaultColormap(dpy, screen);
+ for (i = 0; i < 256; ++i)
+ color[i].pixel = i;
+ XQueryColors(dpy, color_map, color, 256);
+ for (i = 0; i < 256; ++i)
+ x11grab->palette[i] = (color[i].red & 0xFF00) << 8 |
+ (color[i].green & 0xFF00) |
+ (color[i].blue & 0xFF00) >> 8;
+ x11grab->palette_changed = 1;
break;
case 16:
if ( image->red_mask == 0xf800 &&
@@ -489,6 +503,16 @@ x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
pkt->data = image->data;
pkt->size = s->frame_size;
pkt->pts = curtime;
+ if (s->palette_changed) {
+ uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
+ AVPALETTE_SIZE);
+ if (!pal) {
+ av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n");
+ } else {
+ memcpy(pal, s->palette, AVPALETTE_SIZE);
+ s->palette_changed = 0;
+ }
+ }
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);