From patchwork Tue May 2 13:55:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 678401 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp521742wrs; Tue, 2 May 2023 06:56:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bi9bb82RtngwyyaPtxD2SPOLj499yZ5wvivOPZQ1KjUWvQRXJG869iM8ubc9801OSpAjq X-Received: by 2002:ac8:7d8f:0:b0:3e6:9847:661 with SMTP id c15-20020ac87d8f000000b003e698470661mr28222913qtd.38.1683035797515; Tue, 02 May 2023 06:56:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683035797; cv=none; d=google.com; s=arc-20160816; b=jtcR3XIctLcge/n7npEhUZ1sysEL0gVHvdMMJLdFJoF8Xd8KVkA48N2jROs2aW04Pf p0a9XdeO2sotxUrNEeylcE+blgn1MLyjryka25q0hWZEDIkCZSKd0Y5Debx0CdZkVMcD mdzuzrFHMqv6Xat6fc4tqUv8SSHaRpLLjRoDbO2eCEt4tWFqe+g2nB/pjH/AJCChwGBZ wyWvwKHaYDTgfvo5axoeo3qSE+2hhyIom38t7jMuNljV6gsNYCeH88J21vSo0QGjrUWu l/LGa1m6aqsauKd7gsxYuPj0nzrcebtpFCuff+5BYJ/46mJcR2wfE8szEy9jqBUG/kp7 biUg== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=+zLPJoePh+WgFj8dLn/J1noNQP1KAN6O873azoX70Vs=; b=cQXvjS1l76OYEnJipcvOnbZzTwZMtYU//eG+I+3+MCTUHz6FbsQbMqUtyeI+MUZ5HF YdkDzhDocqQAAGyTFJ90UxDYFa7Lry9cLhLoVGuop5krKb3kHn03ahawOpuAd0z1YdJa i9BvBlqlC6yJZJKQJy5IY4pbNwKfBFz9QhnTcjop+E8Pwf3vu9r9x41SivVZXHqGSFws JnT+iTLgZSr16vr9fyQ3S68H4dwmUjjOpw0flOcJDOebw3u7erGsWI0L0jKA+hA2urJt fWUVWxUiZbFCP2ddXzhxi1ywVVhhYq2RQ23Oklb4V6SdYKn3jDx5dxHnuvWjoX1iIVfy 0tUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NL+qWRV7; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k5-20020a05620a0b8500b0074ad9eb3b15si14355067qkh.325.2023.05.02.06.56.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 May 2023 06:56:37 -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; dkim=pass header.i=@linaro.org header.s=google header.b=NL+qWRV7; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptqTz-0000Fl-Vg; Tue, 02 May 2023 09:55:55 -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 1ptqTx-0000F2-Ui for qemu-devel@nongnu.org; Tue, 02 May 2023 09:55:53 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ptqTw-00037H-6Z for qemu-devel@nongnu.org; Tue, 02 May 2023 09:55:53 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f19a80a330so23313035e9.2 for ; Tue, 02 May 2023 06:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683035750; x=1685627750; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+zLPJoePh+WgFj8dLn/J1noNQP1KAN6O873azoX70Vs=; b=NL+qWRV7S3Y1ei4RuaNZc6WuSdeDmMDItklnRKjxUfzBiZRvyqeU6mhXYNcDzRHymM 5GofJE2+AKb2sa662GRKXmfAXNdy83thOTP9J9sJArN0It+UzqpbAKF5MEP4mRtK+3jl T2lo82OtEx8WL4j+SSSSVVhA1T4v8r4qbmMKYM8cQ8mdHXEpopaE3H13KK96R3XJKC41 KcoIuyaPRa7s1+ys2fQ9mJDHTCUnKjDLY07Oit5voa4EILEgbgN5t9eYSm2+enVoUe8n 2+uN4qKCI6pYxOLvkvTo/u98o4mBwFZzd8gSgmQRkqVgd7zibKB3EwKRDFWeOpB5u5dp IFOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683035750; x=1685627750; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+zLPJoePh+WgFj8dLn/J1noNQP1KAN6O873azoX70Vs=; b=FM4GlVFcDhcbwhtw4I1qBYi/OW4lpTklLnMiiJtKdlzLslvE/jmRfYw/or6cQ57k+G OZkNXtZPXneS4ViWz2QZrqrZivwfIyu7Yk4o7Cy66TcZB0ZIegMbXHskhjL+optzNlgD f2WLq3M7Rc0/PFnbLzprTIUZPiwAdoagpDA4TvKWAM5cxP+xunApxr6j1BOpBT/wiMyE +PW54U9oZ6iWIvLpQeLYtlFQTT/Bjmr2+GMoz/I4ujhk7lcmmHTb8PhZDGmUY/qdlvZ/ FCGQVbvs4nPLxDHn0AiEx1OnSzjZk46xr07COeLZryzM/Yb4+eXaTAIXY/cMY8AdcOz3 r7dw== X-Gm-Message-State: AC+VfDy7kMsvl2OKQNivQfyzo8ugOluruhHLurSZOUMeKP3jjJIS+bT1 xd0PU0YadkBzvY98gKEjYyFlgXbzD0Iu/SmNarc= X-Received: by 2002:a1c:ed0e:0:b0:3f1:800f:cc61 with SMTP id l14-20020a1ced0e000000b003f1800fcc61mr12132073wmh.13.1683035750524; Tue, 02 May 2023 06:55:50 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id o2-20020a05600c4fc200b003f1738e64c0sm39277008wmq.20.2023.05.02.06.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 06:55:50 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Gerd Hoffmann , =?utf-8?q?Mar?= =?utf-8?q?c-Andr=C3=A9_Lureau?= , Kshitij Suri Subject: [PATCH] ui: Fix pixel colour channel order for PNG screenshots Date: Tue, 2 May 2023 14:55:48 +0100 Message-Id: <20230502135548.2451309-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 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_a9r8g8b8 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 --- Disclaimer: I don't have a BE system that I have convenient graphics output from that I can use to test the screenshot format there. --- ui/console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/console.c b/ui/console.c index 6e8a3cdc62d..e173731e205 100644 --- a/ui/console.c +++ b/ui/console.c @@ -311,7 +311,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; @@ -341,7 +341,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);