qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-stable@nongnu.org,
	 Gerd Hoffmann <kraxel@redhat.com>,
	Kshitij Suri <kshitij.suri@nutanix.com>
Subject: Re: [PATCH] ui: Fix pixel colour channel order for PNG screenshots
Date: Tue, 9 May 2023 14:11:56 +0100	[thread overview]
Message-ID: <CAFEAcA8OBka2yGWpktMRyW2fNaLjg7PtPd7F=+C6EGc6uKVetw@mail.gmail.com> (raw)
In-Reply-To: <CAMxuvayLKQAaRyZZXdgKvAJtgwRcxsFUnQ-S5yB8qBRvJrgrRg@mail.gmail.com>

On Tue, 2 May 2023 at 20:36, Marc-André Lureau
<marcandre.lureau@redhat.com> wrote:
>
>
>
> On Tue, May 2, 2023 at 5:56 PM Peter Maydell <peter.maydell@linaro.org> wrote:
>>
>> 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 <peter.maydell@linaro.org>
>
>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Thanks; shall I take this via target-arm.next, or would you
prefer to take it via the UI queue (with the commit message
typo fixed) ?

-- PMM


  reply	other threads:[~2023-05-09 13:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 13:55 [PATCH] ui: Fix pixel colour channel order for PNG screenshots Peter Maydell
2023-05-02 19:36 ` Marc-André Lureau
2023-05-09 13:11   ` Peter Maydell [this message]
2023-05-09 13:30     ` Marc-André Lureau
2023-05-02 20:34 ` BALATON Zoltan
2023-05-03 12:47   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFEAcA8OBka2yGWpktMRyW2fNaLjg7PtPd7F=+C6EGc6uKVetw@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=kraxel@redhat.com \
    --cc=kshitij.suri@nutanix.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).