[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Color shift when blitting



I do still have the issue with a bmp file - the pixel grabbed from the screen is different from the pixel from the image directly. 

What did help me was to do a convert() on the image, which I guess removes any potential alpha channel information. Using convert_alpha() on the image did not fix it. With convert(), the screen pixel is now the same as the image pixel color. It still doesn’t explain why the conversion was inconsistent (the same image color mapping to slightly different screen colors), but it does make me think there is something in the blit process with an alpha value that is causing problems.

I would like to understand this more, but at least it seems like I have a work-around.

I am on a Mac, though, so maybe there is some interplay there as you suggest.

Thanks,
David

On Nov 5, 2017, at 1:01 PM, Christopher Night <cosmologicon@xxxxxxxxx> wrote:

In the past I've found this to be an issue with PNGs on Mac. The PNG specification apparently allows for color correction on image load, based on your display settings, which means it's going to be very inconsistent between platforms (although it should look more consistent to the eye). If you require pixel values to be exact, I recommend trying BMP instead and seeing if you still see the issue.

On Sun, Nov 5, 2017 at 2:45 PM dejohnso <dejohnso@xxxxxxxxxxx> wrote:
Hi,

I am loading a background map and blitting it to the screen. Once I have done this, I am getting color values under the mouse cursor.

However, I am seeing small color shifts between the image and the blitted image. For example,

from the screen with the background image: (103, 255, 103, 255)
directly from the image: (102, 255, 102, 255)

This is also inconsistent. Sometimes, the colors are the same - even for the color shown above - so sometimes it gets shifted and sometimes not.

Does anyone know why this is happening? The inconsistency is particularly strange to me, as it implies the same start color is inconsistently blitted to the screen.

I am also seeing an overall color shift. The colors I am displaying from the screen or image are off by a few percent compared to the colors I see using a color picker in an image editing program.

The relevant code is

    map = pygame.image.load("AvoiderMap.png")
...
    while is_alive:
        # Check events by looping over the list of events
        for event in pygame.event.get():
        ….

        screen.blit(map, map_rect)

        pos = pygame.mouse.get_pos()
        cursor_color = screen.get_at(pos)
        img_color = map.get_at(pos)
        print(cursor_color, img_color)

Thanks,
David