From patchwork Sun Jan 31 19:41:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 25301 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6135C448D26 for ; Sun, 31 Jan 2021 21:51:03 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 380B4689AEA; Sun, 31 Jan 2021 21:51:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5BAAD689ADA for ; Sun, 31 Jan 2021 21:50:56 +0200 (EET) Received: by mail-qk1-f169.google.com with SMTP id v126so14249802qkd.11 for ; Sun, 31 Jan 2021 11:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nKxwp/6F18tWwu1PM7DHL1eBODBsrdlM3iOzlMleCqs=; b=OMx1laktEGHsi9ZvENdLr8iBgmU7RYEadvMsC4lv+WXSCRno35cLdRGmk8kvTe4bi7 WhK1OxGP5flLbhzJ8xkicJRM5rF4nec2Gva3yFGfEoM24qv6f6ErHMbAiaQAPo9Pxv35 5eTCKmbTU4rpmdFwseT7RMhSBHxgpFJpn21D37x5TB2bE172/a546LnI00S6+YQtdQ2v JLJ07+bRfLjqjaYwyJjGNtZHm7P3Afsl77nHJWKGsziQz2IV9WLjHfWZDC1TRvWhh5g9 AIKt3nM6V7ynnn84XYi29zc6i3ewcJ7bD/XJ7t1rzF481BiEpOxGicxQJKPhb69fMgK1 4elw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nKxwp/6F18tWwu1PM7DHL1eBODBsrdlM3iOzlMleCqs=; b=E8W30tckncPa9t/RvQ6dgP45Uoxjpg3UhN1rbDpntMTwxSjb0Wm+Sa6om+7QufrwMp q5aLNE6bh+4VYHC9PyA8hxoWhTfyj/0KDBVdp+MX87sBRsD7MTP21JVnGTwcleWbq/xZ nYQ5riJwnrO3kHLDCQ5fzCHMW7VCUJkDp3IB8oBvbhVZGiOuQ+iJwmD7V+kJVQNVcnG2 zw11UWpzUqBvpxkzJRCex3/4N0UM35QiqPlO20YqvS4NpJS6O1luSyi5PEeNK5BlPfmP 78BaFM0MYyT7iaKPHUAqfx1ztXr+iSkrX3bLx1l4iWMRZdVNl+oUQGZbbOjK8oLmbkv/ N++Q== X-Gm-Message-State: AOAM532/Sz0a48W1SX/bLo/RVbEfj90XO3YbijrYyb93v6Aoe+rUXUNW TbtMPcXETiVO6PX8IQkloh+YNcsa/P8= X-Google-Smtp-Source: ABdhPJxJchSYnNqNrHc+/7MV0JtImn6dY+DNK1Wr3KcFO0VkNEzlquygETG3ed81JN4+ECGOX3jeug== X-Received: by 2002:a37:2741:: with SMTP id n62mr13139253qkn.43.1612122267428; Sun, 31 Jan 2021 11:44:27 -0800 (PST) Received: from localhost.localdomain (c-73-149-98-40.hsd1.ma.comcast.net. [73.149.98.40]) by smtp.gmail.com with ESMTPSA id z15sm9283251qti.43.2021.01.31.11.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jan 2021 11:44:26 -0800 (PST) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Sun, 31 Jan 2021 14:41:47 -0500 Message-Id: <20210131194147.30246-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avdevice/xcbgrab: don't assume Xserver endianness X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman Xserver defines the endianness of the grabbed images. Use this information to set the correct pixel format. This also fixes format selection in configuration depth=32/bpp=32 with Xserver on a little endian machine. Before the patch, the big endian layout 0RGB was always selected which is incorrect because BGR0 should be used. RGB24 was also incorrectly assumed (but this format was removed in Xserver 1.20). The big-endian settings can be tested using docker+qemu from a little-endian machine: $ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes $ docker run --rm -it --privileged -v /tmp:/tmp -v $(pwd):/ffmpeg powerpc64/debian /bin/bash In docker container $ apt-get update $ apt-get install xvfb $ apt-get install x11-apps To test AV_PIX_FMT_0RGB32 $ Xvfb :2 -screen 0 1600x1200x24 & $ export DISPLAY=:2 $ xclock -geometry 1600x1200 -bg green #test different colors On your host machine grab the frames using the following command. View output to check that colors are rendered correctly $ ./ffmpeg -y -f x11grab -i :2.0 -codec:v mpeg2video out.mp4 Other pixel formats can be tested by modifying how Xvfb is started in the docker container: AV_PIX_FMT_RGB565 $ Xvfb :2 -screen 0 1600x1200x16 AV_PIX_FMT_RGB555 $ Xvfb :2 -screen 0 1600x1200x15 AV_PIX_FMT_BGR24 / AV_PIX_FMT_RGB24 This is difficult to test because bpp=24 support was removed in Xserver 1.20 https://lists.x.org/archives/xorg-devel/2018-February/056175.html?hmsr=joyk.com&utm_source=joyk.com&utm_medium=referral However, I was able to run previous version of Xvfb (with some modifications to force 24bpp) to check that images are rendered correctly. Signed-off-by: Andriy Gelman --- libavdevice/xcbgrab.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c index 95bdc8ab9d..be5d5ea2cf 100644 --- a/libavdevice/xcbgrab.c +++ b/libavdevice/xcbgrab.c @@ -513,21 +513,26 @@ static int pixfmt_from_pixmap_format(AVFormatContext *s, int depth, switch (depth) { case 32: if (fmt->bits_per_pixel == 32) - *pix_fmt = AV_PIX_FMT_0RGB; + *pix_fmt = setup->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST ? + AV_PIX_FMT_BGR0 : AV_PIX_FMT_0RGB; break; case 24: if (fmt->bits_per_pixel == 32) - *pix_fmt = AV_PIX_FMT_0RGB32; + *pix_fmt = setup->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST ? + AV_PIX_FMT_BGR0 : AV_PIX_FMT_0RGB; else if (fmt->bits_per_pixel == 24) - *pix_fmt = AV_PIX_FMT_RGB24; + *pix_fmt = setup->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST ? + AV_PIX_FMT_BGR24 : AV_PIX_FMT_RGB24; break; case 16: if (fmt->bits_per_pixel == 16) - *pix_fmt = AV_PIX_FMT_RGB565; + *pix_fmt = setup->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST ? + AV_PIX_FMT_RGB565LE : AV_PIX_FMT_RGB565BE; break; case 15: if (fmt->bits_per_pixel == 16) - *pix_fmt = AV_PIX_FMT_RGB555; + *pix_fmt = setup->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST ? + AV_PIX_FMT_RGB555LE : AV_PIX_FMT_RGB555BE; break; case 8: if (fmt->bits_per_pixel == 8)