Autogenerated full mask checks for pixel format match
authorSam Lantinga <slouken@libsdl.org>
Sat, 19 Feb 2011 14:19:15 -0800
changeset 535095712d32f0ed
parent 5349 02770b3c43f8
child 5351 176cd91c3907
Autogenerated full mask checks for pixel format match
src/video/SDL_pixels.c
     1.1 --- a/src/video/SDL_pixels.c	Sat Feb 19 11:26:49 2011 -0800
     1.2 +++ b/src/video/SDL_pixels.c	Sat Feb 19 14:19:15 2011 -0800
     1.3 @@ -236,60 +236,107 @@
     1.4  {
     1.5      switch (bpp) {
     1.6      case 8:
     1.7 -        switch (Rmask) {
     1.8 -        case 0:
     1.9 +        if (Rmask == 0) {
    1.10              return SDL_PIXELFORMAT_INDEX8;
    1.11 -        case 0xE0:
    1.12 -            return SDL_PIXELFORMAT_RGB332;
    1.13 +        }
    1.14 +        if (Rmask == 0xE0 &&
    1.15 +            Gmask == 0x1C &&
    1.16 +            Bmask == 0x03 &&
    1.17 +            Amask == 0x00) {
    1.18 +            return SDL_PIXELFORMAT_RGB332
    1.19          }
    1.20          break;
    1.21      case 12:
    1.22 -        switch (Rmask) {
    1.23 -        case 0x0F00:
    1.24 -            return SDL_PIXELFORMAT_RGB444;
    1.25 +        if (Rmask == 0) {
    1.26 +            return SDL_PIXELFORMAT_RGB444
    1.27 +        }
    1.28 +        if (Rmask == 0x0F00 &&
    1.29 +            Gmask == 0x00F0 &&
    1.30 +            Bmask == 0x000F &&
    1.31 +            Amask == 0x0000) {
    1.32 +            return SDL_PIXELFORMAT_RGB444
    1.33          }
    1.34          break;
    1.35      case 15:
    1.36          if (Rmask == 0) {
    1.37              return SDL_PIXELFORMAT_RGB555;
    1.38          }
    1.39 -        if (Rmask == 0x7C00 && Bmask == 0x001F) {
    1.40 -            return SDL_PIXELFORMAT_RGB555;
    1.41 +        /* Fall through to 16-bit checks */
    1.42 +    case 16:
    1.43 +        if (Rmask == 0) {
    1.44 +            return SDL_PIXELFORMAT_RGB565;
    1.45          }
    1.46 -        if (Rmask == 0x001F && Bmask == 0x7C00) {
    1.47 -            return SDL_PIXELFORMAT_BGR555;
    1.48 +        if (Rmask == 0x7C00 &&
    1.49 +            Gmask == 0x03E0 &&
    1.50 +            Bmask == 0x001F &&
    1.51 +            Amask == 0x0000) {
    1.52 +            return SDL_PIXELFORMAT_RGB555
    1.53          }
    1.54 -        break;
    1.55 -    case 16:
    1.56 -        switch (Rmask) {
    1.57 -        case 0:
    1.58 -            return SDL_PIXELFORMAT_RGB565;
    1.59 -        case 0xF000:
    1.60 -            return SDL_PIXELFORMAT_RGBA4444;
    1.61 -        case 0x0F00:
    1.62 -            return SDL_PIXELFORMAT_ARGB4444;
    1.63 -        case 0x00F0:
    1.64 -            return SDL_PIXELFORMAT_BGRA4444;
    1.65 -        case 0x000F:
    1.66 -            return SDL_PIXELFORMAT_ABGR4444;
    1.67 -        case 0xF800:
    1.68 -            if (Bmask == 0x001F) {
    1.69 -                return SDL_PIXELFORMAT_RGB565;
    1.70 -            }
    1.71 -            break;
    1.72 -        case 0x7C00:
    1.73 -            if (Bmask == 0x001F) {
    1.74 -                return SDL_PIXELFORMAT_RGB555;
    1.75 -            }
    1.76 -            break;
    1.77 -        case 0x001F:
    1.78 -            if (Bmask == 0xF800) {
    1.79 -                return SDL_PIXELFORMAT_BGR565;
    1.80 -            }
    1.81 -            if (Bmask == 0x7C00) {
    1.82 -                return SDL_PIXELFORMAT_BGR555;
    1.83 -            }
    1.84 -            break;
    1.85 +        if (Rmask == 0x001F &&
    1.86 +            Gmask == 0x03E0 &&
    1.87 +            Bmask == 0x7C00 &&
    1.88 +            Amask == 0x0000) {
    1.89 +            return SDL_PIXELFORMAT_BGR555
    1.90 +        }
    1.91 +        if (Rmask == 0x0F00 &&
    1.92 +            Gmask == 0x00F0 &&
    1.93 +            Bmask == 0x000F &&
    1.94 +            Amask == 0xF000) {
    1.95 +            return SDL_PIXELFORMAT_ARGB4444
    1.96 +        }
    1.97 +        if (Rmask == 0xF000 &&
    1.98 +            Gmask == 0x0F00 &&
    1.99 +            Bmask == 0x00F0 &&
   1.100 +            Amask == 0x000F) {
   1.101 +            return SDL_PIXELFORMAT_RGBA4444
   1.102 +        }
   1.103 +        if (Rmask == 0x000F &&
   1.104 +            Gmask == 0x00F0 &&
   1.105 +            Bmask == 0x0F00 &&
   1.106 +            Amask == 0xF000) {
   1.107 +            return SDL_PIXELFORMAT_ABGR4444
   1.108 +        }
   1.109 +        if (Rmask == 0x00F0 &&
   1.110 +            Gmask == 0x0F00 &&
   1.111 +            Bmask == 0xF000 &&
   1.112 +            Amask == 0x000F) {
   1.113 +            return SDL_PIXELFORMAT_BGRA4444
   1.114 +        }
   1.115 +        if (Rmask == 0x7C00 &&
   1.116 +            Gmask == 0x03E0 &&
   1.117 +            Bmask == 0x001F &&
   1.118 +            Amask == 0x8000) {
   1.119 +            return SDL_PIXELFORMAT_ARGB1555
   1.120 +        }
   1.121 +        if (Rmask == 0xF800 &&
   1.122 +            Gmask == 0x07C0 &&
   1.123 +            Bmask == 0x003E &&
   1.124 +            Amask == 0x0001) {
   1.125 +            return SDL_PIXELFORMAT_RGBA5551
   1.126 +        }
   1.127 +        if (Rmask == 0x001F &&
   1.128 +            Gmask == 0x03E0 &&
   1.129 +            Bmask == 0x7C00 &&
   1.130 +            Amask == 0x8000) {
   1.131 +            return SDL_PIXELFORMAT_ABGR1555
   1.132 +        }
   1.133 +        if (Rmask == 0x003E &&
   1.134 +            Gmask == 0x07C0 &&
   1.135 +            Bmask == 0xF800 &&
   1.136 +            Amask == 0x0001) {
   1.137 +            return SDL_PIXELFORMAT_BGRA5551
   1.138 +        }
   1.139 +        if (Rmask == 0xF800 &&
   1.140 +            Gmask == 0x07E0 &&
   1.141 +            Bmask == 0x001F &&
   1.142 +            Amask == 0x0000) {
   1.143 +            return SDL_PIXELFORMAT_RGB565
   1.144 +        }
   1.145 +        if (Rmask == 0x001F &&
   1.146 +            Gmask == 0x07E0 &&
   1.147 +            Bmask == 0xF800 &&
   1.148 +            Amask == 0x0000) {
   1.149 +            return SDL_PIXELFORMAT_BGR565
   1.150          }
   1.151          break;
   1.152      case 24:
   1.153 @@ -309,34 +356,50 @@
   1.154  #endif
   1.155          }
   1.156      case 32:
   1.157 -        switch (Rmask) {
   1.158 -        case 0xFF000000:
   1.159 -            if (Amask == 0x000000FF) {
   1.160 -                return SDL_PIXELFORMAT_RGBA8888;
   1.161 -            }
   1.162 -            break;
   1.163 -        case 0:
   1.164 -        case 0x00FF0000:
   1.165 -            if (Amask == 0xFF000000) {
   1.166 -                return SDL_PIXELFORMAT_ARGB8888;
   1.167 -            } else {
   1.168 -                return SDL_PIXELFORMAT_RGB888;
   1.169 -            }
   1.170 -            break;
   1.171 -        case 0x0000FF00:
   1.172 -            if (Amask == 0x000000FF) {
   1.173 -                return SDL_PIXELFORMAT_BGRA8888;
   1.174 -            }
   1.175 -            break;
   1.176 -        case 0x000000FF:
   1.177 -            if (Amask == 0xFF000000) {
   1.178 -                return SDL_PIXELFORMAT_ABGR8888;
   1.179 -            } else {
   1.180 -                return SDL_PIXELFORMAT_BGR888;
   1.181 -            }
   1.182 -            break;
   1.183 -        case 0x3FF00000:
   1.184 -            return SDL_PIXELFORMAT_ARGB2101010;
   1.185 +        if (Rmask == 0) {
   1.186 +            return SDL_PIXELFORMAT_RGB888;
   1.187 +        }
   1.188 +        if (Rmask == 0x00FF0000 &&
   1.189 +            Gmask == 0x0000FF00 &&
   1.190 +            Bmask == 0x000000FF &&
   1.191 +            Amask == 0x00000000) {
   1.192 +            return SDL_PIXELFORMAT_RGB888
   1.193 +        }
   1.194 +        if (Rmask == 0x000000FF &&
   1.195 +            Gmask == 0x0000FF00 &&
   1.196 +            Bmask == 0x00FF0000 &&
   1.197 +            Amask == 0x00000000) {
   1.198 +            return SDL_PIXELFORMAT_BGR888
   1.199 +        }
   1.200 +        if (Rmask == 0x00FF0000 &&
   1.201 +            Gmask == 0x0000FF00 &&
   1.202 +            Bmask == 0x000000FF &&
   1.203 +            Amask == 0xFF000000) {
   1.204 +            return SDL_PIXELFORMAT_ARGB8888
   1.205 +        }
   1.206 +        if (Rmask == 0xFF000000 &&
   1.207 +            Gmask == 0x00FF0000 &&
   1.208 +            Bmask == 0x0000FF00 &&
   1.209 +            Amask == 0x000000FF) {
   1.210 +            return SDL_PIXELFORMAT_RGBA8888
   1.211 +        }
   1.212 +        if (Rmask == 0x000000FF &&
   1.213 +            Gmask == 0x0000FF00 &&
   1.214 +            Bmask == 0x00FF0000 &&
   1.215 +            Amask == 0xFF000000) {
   1.216 +            return SDL_PIXELFORMAT_ABGR8888
   1.217 +        }
   1.218 +        if (Rmask == 0x0000FF00 &&
   1.219 +            Gmask == 0x00FF0000 &&
   1.220 +            Bmask == 0xFF000000 &&
   1.221 +            Amask == 0x000000FF) {
   1.222 +            return SDL_PIXELFORMAT_BGRA8888
   1.223 +        }
   1.224 +        if (Rmask == 0x3FF00000 &&
   1.225 +            Gmask == 0x000FFC00 &&
   1.226 +            Bmask == 0x000003FF &&
   1.227 +            Amask == 0xC0000000) {
   1.228 +            return SDL_PIXELFORMAT_ARGB2101010
   1.229          }
   1.230      }
   1.231      return SDL_PIXELFORMAT_UNKNOWN;