Fixed SDL_ISPIXELFORMAT_ALPHA to check pixel orders that match pixel type.
authorRyan C. Gordon
Sun, 31 May 2015 01:45:20 -0400
changeset 9687ad9917a91c06
parent 9686 d84e21b0b0ba
child 9688 596a3da0c9cb
Fixed SDL_ISPIXELFORMAT_ALPHA to check pixel orders that match pixel type.

Otherwise, SDL_PIXELFORMAT_BGR24 is reported as having alpha, because
its SDL_ARRAYORDER_BGR pixel order uses the same integer value as
SDL_PACKEDORDER_RGBA, since we weren't checking the pixel type to
differentiate.

Fixes Bugzilla #2977.
include/SDL_pixels.h
     1.1 --- a/include/SDL_pixels.h	Sun May 31 00:58:43 2015 -0400
     1.2 +++ b/include/SDL_pixels.h	Sun May 31 01:45:20 2015 -0400
     1.3 @@ -86,6 +86,8 @@
     1.4  };
     1.5  
     1.6  /** Array component order, low byte -> high byte. */
     1.7 +/* !!! FIXME: in 2.1, make these not overlap differently with
     1.8 +   !!! FIXME:  SDL_PACKEDORDER_*, so we can simplify SDL_ISPIXELFORMAT_ALPHA */
     1.9  enum
    1.10  {
    1.11      SDL_ARRAYORDER_NONE,
    1.12 @@ -134,12 +136,31 @@
    1.13        (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
    1.14        (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
    1.15  
    1.16 +#define SDL_ISPIXELFORMAT_PACKED(format) \
    1.17 +    (!SDL_ISPIXELFORMAT_FOURCC(format) && \
    1.18 +     ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
    1.19 +      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
    1.20 +      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
    1.21 +
    1.22 +#define SDL_ISPIXELFORMAT_ARRAY(format) \
    1.23 +    (!SDL_ISPIXELFORMAT_FOURCC(format) && \
    1.24 +     ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
    1.25 +      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
    1.26 +      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
    1.27 +      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
    1.28 +      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
    1.29 +
    1.30  #define SDL_ISPIXELFORMAT_ALPHA(format)   \
    1.31 -    (!SDL_ISPIXELFORMAT_FOURCC(format) && \
    1.32 +    ((SDL_ISPIXELFORMAT_PACKED(format) && \
    1.33       ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
    1.34        (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
    1.35        (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
    1.36 -      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA)))
    1.37 +      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))) || \
    1.38 +    (SDL_ISPIXELFORMAT_ARRAY(format) && \
    1.39 +     ((SDL_PIXELORDER(format) == SDL_ARRAYORDER_ARGB) || \
    1.40 +      (SDL_PIXELORDER(format) == SDL_ARRAYORDER_RGBA) || \
    1.41 +      (SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || \
    1.42 +      (SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
    1.43  
    1.44  /* The flag is set to 1 because 0x1? is not in the printable ASCII range */
    1.45  #define SDL_ISPIXELFORMAT_FOURCC(format)    \