简体   繁体   中英

Do indexed Surfaces support palettes with alpha values (other than 255)?

When I call myIndexedSurface.get_palette() , it returns a list of 32-bit RGBA values. I figured that because there is an alpha value included, I might be able to set and use palette indices with transparency effects, too. These surfaces could then be blitted as overlays or masks more efficiently than Surfaces with full-depth (32-bit) per-pixel data.

So far, though, the palette element alpha values seem locked at 255 and won't change by any method I've tried:

  • .set_palette_at(idx, (r,g,b,A)) correctly sets r , g , and b , but leaves the alpha value at 255, regardless of A 's value.

  • .set_palette(somePalette) raises ValueError: takes an alpha value of 255 if any somePalette RGBA tuple element has an alpha value other than 255.

Is what I'm trying to do possible? Is the alpha value in each palette-list element purely decorative, that it might be used more easily by other processes that expect 32-bit (RGBA) pixel data instead of just 24 (RGB)?

I feel like indexed surfaces in Pygame may not be equipped to handle this degree of complexity to begin with, but I also cannot think of or find a reason for why it shouldn't . Perhaps Pygame has one of its mysterious special_flags for this purpose?

I have tried initializing the Surface itself via myIndexedSurface = pygame.Surface(surfSize).convert(8) and myIndexedSurface = pygame.Surface(surfSize, flags=pygame.SRCALPHA).convert(8) to no effect.

I have not yet looked at PIL or Pygame's PixelArray for a solution.

As you had seen by yourself it does not. What you describe is kind of new invented approach. Four values are there just because it so declared in pyGame for color values, and some other properties. For example if you try this

S = pygame.Surface ((w,h),0,24)
r,g,b,a =S.get_masks()

You will see tuple of four values, despite 24 bit surface obviously has only three bytes to process, so the alpha just doesnt come in play by further blitting. If the data on your backend is originally indexed, like just number arrays, I would personally describe the combining logic also on the backend, using mask arrays.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM