pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

transform.solid_overlay

Open ScriptLineStudios opened this issue 2 years ago • 7 comments
trafficstars

closes #1847

import pygame

dis = pygame.display.set_mode((600, 600))

img = pygame.image.load("transparent_walt.png")
img = pygame.transform.solid_overlay(img, (0, 0, 0))

while True:
    dis.fill((100, 100, 100))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            raise SystemExit

    dis.blit(img, (30, 30))
    pygame.display.update()

produces:

Screenshot from 2023-07-11 14-01-26

ScriptLineStudios avatar Jul 11 '23 12:07 ScriptLineStudios

Any idea what's going on here?

import pygame

dis = pygame.display.set_mode((600, 600))

img = pygame.image.load("examples/data/alien1.png").convert_alpha()
img = pygame.transform.scale(img, (600, 600))

overlay_rect = pygame.Rect(200, 200, 100, 100)
subsurface = img.subsurface(overlay_rect)
subsurface = pygame.transform.solid_overlay(subsurface, (0, 0, 0))

while True:
    dis.fill((100, 100, 100))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            raise SystemExit

    dis.blit(img, (0, 0))
    pygame.draw.rect(dis, "red", overlay_rect, 2)
    pygame.display.update()

output

EDIT: I realize now that I am an idiot

oddbookworm avatar Jul 16 '23 01:07 oddbookworm

Also, when trying to use a string for the color, an error is raised:

pygame-ce 2.3.1.dev1 (SDL 2.26.4, Python 3.11.1)
Traceback (most recent call last):
  File "c:\Users\andre\Projects\pygame-ce\test.py", line 10, in <module>
    subsurface = pygame.transform.solid_overlay(subsurface, "black")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: invalid search_color argument

oddbookworm avatar Jul 16 '23 01:07 oddbookworm

That isn't really this PRs fault, though it's something I plan to tackle in the near future

ankith26 avatar Jul 27 '23 15:07 ankith26

As per @ScriptLineStudios on Discord I'll take over this PR.

itzpr3d4t0r avatar Jan 15 '24 20:01 itzpr3d4t0r

Ltl graph to show improvement for 32bit surfaces: image

itzpr3d4t0r avatar Jan 16 '24 13:01 itzpr3d4t0r

One test on Debian Multiarch / Debian (Bullseye - 11) [s390x] is failing but it's unclear why and it's the only platform exhibiting this behaviour. Hopefully is just a blip but correct me if i'm wrong here.

itzpr3d4t0r avatar Jan 16 '24 14:01 itzpr3d4t0r

One test on Debian Multiarch / Debian (Bullseye - 11) [s390x] is failing but it's unclear why and it's the only platform exhibiting this behaviour. Hopefully is just a blip but correct me if i'm wrong here.

Likely to be an endianness issue - s390x is big endian. I would first change this failing test to an assertEqual() type so it will show the values that are different on the CI.

MyreMylar avatar Feb 12 '24 14:02 MyreMylar

@itzpr3d4t0r after typing.py, ColorValue isn't available anymore. If you can you can update the branch and replace ColorValue with ColorLike from pygame.typing

damusss avatar Oct 01 '24 18:10 damusss

@itzpr3d4t0r after typing.py, ColorValue isn't available anymore. If you can you can update the branch and replace ColorValue with ColorLike from pygame.typing

I'm not sure i can do it right atm. I've always committed from github because of commit permissions being broken in my ide for some reason... so I'm afraid someone else has to do it.

itzpr3d4t0r avatar Oct 02 '24 08:10 itzpr3d4t0r