From patchwork Wed May 17 09:10:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 682915 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp251847wrt; Wed, 17 May 2023 02:14:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ60iG3Cfwib9dweOI5EfLfNw1+324hNcm16g2VSE2vPphLjaCbwIVUa/vBkShGF99C/gF0P X-Received: by 2002:a05:622a:1391:b0:3f5:938:db47 with SMTP id o17-20020a05622a139100b003f50938db47mr25243452qtk.11.1684314886060; Wed, 17 May 2023 02:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314886; cv=none; d=google.com; s=arc-20160816; b=XCUPwBxM25Bdmo8P7xOPEOnuA7a4lHUPQma5Dl/o673fjKFBUy35f18aPKsf/JwnJu lgLX0u0NIgjVvhCYJdEzPOnw7/XSwZ0joU5K9DLmAiUNu159BEOLF0lI3VEYLTJPBgP4 2ypRpTXNg6X1VefM0//oSz14ybP0gaCHH9qTtK2gbNtDkpYTy/7t60rlnhAg2af7lT1e vsFVfP+0Q0cZFn6gYy5yjTRQa+56yhZb08/zwfn4CcfaxfW8sAwl3dR9o+iFVdpuNl2E bGfNmZY3NLn8KcIdZdyX74Q4E24rbBPWBxqnFheIwSjMPPEt6dryq2JfxP+/d0pvV2ph GxOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=x+itHyhWYNTnDkIJRTc+VSC0I45qemW4bcbXNx6ySho=; b=Zc1gwm8oIIeOV8RwvV+Lev/zlvI6o1Np+x+V9DaOYQfVDwuuDUCz/Qo4cuIdQyf3MY qXbN3B5sD2GVXNsUba6NLWEnZCZ06ARRp2mLU9D5s+okeNwuBCpeLdaVqI5p3sr8dpkV YVWyMUz6sdBJK3XP0C7c8F6jKtNObnfJG1j+SB5cMcdqRmRWqe7HQ0WCLSTEprRO7eFA 4cQaX0SB6KSMDH4qV6OB8/yBtxKF4tnaVFptJuDrcnL5lQ98Wk3ABo8bRS8vXm5FkRlF VVUZ8RoGjyTDooZR/B6KvBgICXDShZE7RdLV8FMfzJU3pSk0QbiK5KYTgS1Grwp5iacC bOiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q20-20020a05622a04d400b003e384f9d039si12658424qtx.336.2023.05.17.02.14.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 May 2023 02:14:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzDC1-0001N1-L9; Wed, 17 May 2023 05:11:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzDBk-0000wJ-09; Wed, 17 May 2023 05:11:16 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzDBh-0006Pb-Tm; Wed, 17 May 2023 05:11:15 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id D6E32683A; Wed, 17 May 2023 12:10:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 51A865F0B; Wed, 17 May 2023 12:10:45 +0300 (MSK) Received: (nullmailer pid 3626726 invoked by uid 1000); Wed, 17 May 2023 09:10:42 -0000 From: Michael Tokarev To: qemu-stable@nongnu.org Cc: qemu-devel@nongnu.org, Peter Maydell , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v7.2.3 20/30] ui: Fix pixel colour channel order for PNG screenshots Date: Wed, 17 May 2023 12:10:32 +0300 Message-Id: <20230517091042.3626593-20-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell When we take a PNG screenshot the ordering of the colour channels in the data is not correct, resulting in the image having weird colouring compared to the actual display. (Specifically, on a little-endian host the blue and red channels are swapped; on big-endian everything is wrong.) This happens because the pixman idea of the pixel data and the libpng idea differ. PIXMAN_a8r8g8b8 defines that pixels are 32-bit values, with A in bits 24-31, R in bits 16-23, G in bits 8-15 and B in bits 0-7. This means that on little-endian systems the bytes in memory are B G R A and on big-endian systems they are A R G B libpng, on the other hand, thinks of pixels as being a series of values for each channel, so its format PNG_COLOR_TYPE_RGB_ALPHA always wants bytes in the order R G B A This isn't the same as the pixman order for either big or little endian hosts. The alpha channel is also unnecessary bulk in the output PNG file, because there is no alpha information in a screenshot. To handle the endianness issue, we already define in ui/qemu-pixman.h various PIXMAN_BE_* and PIXMAN_LE_* values that give consistent byte-order pixel channel formats. So we can use PIXMAN_BE_r8g8b8 and PNG_COLOR_TYPE_RGB, which both have an in-memory byte order of R G B and 3 bytes per pixel. (PPM format screenshots get this right; they already use the PIXMAN_BE_r8g8b8 format.) Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1622 Fixes: 9a0a119a382867 ("Added parameter to take screenshot with screendump as PNG") Signed-off-by: Peter Maydell Reviewed-by: Marc-André Lureau Message-id: 20230502135548.2451309-1-peter.maydell@linaro.org (cherry picked from commit cd22a0f520f471e3bd33bc19cf3b2fa772cdb2a8) Signed-off-by: Michael Tokarev --- ui/console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/console.c b/ui/console.c index 3c0d9b061a..646202214a 100644 --- a/ui/console.c +++ b/ui/console.c @@ -307,7 +307,7 @@ static bool png_save(int fd, pixman_image_t *image, Error **errp) png_struct *png_ptr; png_info *info_ptr; g_autoptr(pixman_image_t) linebuf = - qemu_pixman_linebuf_create(PIXMAN_a8r8g8b8, width); + qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, width); uint8_t *buf = (uint8_t *)pixman_image_get_data(linebuf); FILE *f = fdopen(fd, "wb"); int y; @@ -337,7 +337,7 @@ static bool png_save(int fd, pixman_image_t *image, Error **errp) png_init_io(png_ptr, f); png_set_IHDR(png_ptr, info_ptr, width, height, 8, - PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); png_write_info(png_ptr, info_ptr);