Mercurial > sdl-ios-xcode
annotate src/video/SDL_pixels.c @ 3667:cc7eca3a4e13
Fixed compiler warning.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 13 Jan 2010 16:18:36 +0000 |
parents | 7dec3fe9b580 |
children | f7b03b6838cb |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
2859 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1057
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1057
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1057
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1057
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1057
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1057
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
50
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* General (mostly internal) pixel/color manipulation routines for SDL */ | |
25 | |
26 #include "SDL_endian.h" | |
27 #include "SDL_video.h" | |
28 #include "SDL_sysvideo.h" | |
29 #include "SDL_blit.h" | |
30 #include "SDL_pixels_c.h" | |
31 #include "SDL_RLEaccel_c.h" | |
32 | |
3555
7549b986ccb1
The SDL_PaletteWatch structure is really internal-only.
Sam Lantinga <slouken@libsdl.org>
parents:
3484
diff
changeset
|
33 struct SDL_PaletteWatch |
7549b986ccb1
The SDL_PaletteWatch structure is really internal-only.
Sam Lantinga <slouken@libsdl.org>
parents:
3484
diff
changeset
|
34 { |
7549b986ccb1
The SDL_PaletteWatch structure is really internal-only.
Sam Lantinga <slouken@libsdl.org>
parents:
3484
diff
changeset
|
35 SDL_PaletteChangedFunc callback; |
7549b986ccb1
The SDL_PaletteWatch structure is really internal-only.
Sam Lantinga <slouken@libsdl.org>
parents:
3484
diff
changeset
|
36 void *userdata; |
7549b986ccb1
The SDL_PaletteWatch structure is really internal-only.
Sam Lantinga <slouken@libsdl.org>
parents:
3484
diff
changeset
|
37 struct SDL_PaletteWatch *next; |
7549b986ccb1
The SDL_PaletteWatch structure is really internal-only.
Sam Lantinga <slouken@libsdl.org>
parents:
3484
diff
changeset
|
38 }; |
7549b986ccb1
The SDL_PaletteWatch structure is really internal-only.
Sam Lantinga <slouken@libsdl.org>
parents:
3484
diff
changeset
|
39 |
0 | 40 /* Helper functions */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
41 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
42 SDL_bool |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
43 SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
44 Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
45 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
46 Uint32 masks[4]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
47 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
48 /* Initialize the values here */ |
3284
2b95b2c0b6d4
Fixed compatibility with SDL 1.2 pixel format (24 bits per pixel of color data with 4 bytes per pixel == 32 bpp)
Sam Lantinga <slouken@libsdl.org>
parents:
3182
diff
changeset
|
49 if (SDL_BYTESPERPIXEL(format) <= 2) { |
2b95b2c0b6d4
Fixed compatibility with SDL 1.2 pixel format (24 bits per pixel of color data with 4 bytes per pixel == 32 bpp)
Sam Lantinga <slouken@libsdl.org>
parents:
3182
diff
changeset
|
50 *bpp = SDL_BITSPERPIXEL(format); |
2b95b2c0b6d4
Fixed compatibility with SDL 1.2 pixel format (24 bits per pixel of color data with 4 bytes per pixel == 32 bpp)
Sam Lantinga <slouken@libsdl.org>
parents:
3182
diff
changeset
|
51 } else { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
52 *bpp = SDL_BYTESPERPIXEL(format) * 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
53 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
54 *Rmask = *Gmask = *Bmask = *Amask = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
55 |
3557
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
56 if (format == SDL_PIXELFORMAT_RGB24) { |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
57 #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
58 *Rmask = 0x00FF0000; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
59 *Gmask = 0x0000FF00; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
60 *Bmask = 0x000000FF; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
61 #else |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
62 *Rmask = 0x000000FF; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
63 *Gmask = 0x0000FF00; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
64 *Bmask = 0x00FF0000; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
65 #endif |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
66 return SDL_TRUE; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
67 } |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
68 |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
69 if (format == SDL_PIXELFORMAT_BGR24) { |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
70 #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
71 *Rmask = 0x000000FF; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
72 *Gmask = 0x0000FF00; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
73 *Bmask = 0x00FF0000; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
74 #else |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
75 *Rmask = 0x00FF0000; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
76 *Gmask = 0x0000FF00; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
77 *Bmask = 0x000000FF; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
78 #endif |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
79 return SDL_TRUE; |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
80 } |
7184580ab756
Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents:
3555
diff
changeset
|
81 |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
82 if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 && |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
83 SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 && |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
84 SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
85 /* Not a format that uses masks */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
86 return SDL_TRUE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
87 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
88 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
89 switch (SDL_PIXELLAYOUT(format)) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
90 case SDL_PACKEDLAYOUT_332: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
91 masks[0] = 0x00000000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
92 masks[1] = 0x000000E0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
93 masks[2] = 0x0000001C; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
94 masks[3] = 0x00000003; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
95 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
96 case SDL_PACKEDLAYOUT_4444: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
97 masks[0] = 0x0000F000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
98 masks[1] = 0x00000F00; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
99 masks[2] = 0x000000F0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
100 masks[3] = 0x0000000F; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
101 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
102 case SDL_PACKEDLAYOUT_1555: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
103 masks[0] = 0x00008000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
104 masks[1] = 0x00007C00; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
105 masks[2] = 0x000003E0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
106 masks[3] = 0x0000001F; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
107 break; |
3163
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
108 case SDL_PACKEDLAYOUT_5551: |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
109 masks[0] = 0x0000F800; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
110 masks[1] = 0x000007C0; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
111 masks[2] = 0x0000003E; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
112 masks[3] = 0x00000001; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
113 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
114 case SDL_PACKEDLAYOUT_565: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
115 masks[0] = 0x00000000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
116 masks[1] = 0x0000F800; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
117 masks[2] = 0x000007E0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
118 masks[3] = 0x0000001F; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
119 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
120 case SDL_PACKEDLAYOUT_8888: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
121 masks[0] = 0xFF000000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
122 masks[1] = 0x00FF0000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
123 masks[2] = 0x0000FF00; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
124 masks[3] = 0x000000FF; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
125 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
126 case SDL_PACKEDLAYOUT_2101010: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
127 masks[0] = 0xC0000000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
128 masks[1] = 0x3FF00000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
129 masks[2] = 0x000FFC00; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
130 masks[3] = 0x000003FF; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
131 break; |
3163
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
132 case SDL_PACKEDLAYOUT_1010102: |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
133 masks[0] = 0xFFC00000; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
134 masks[1] = 0x003FF000; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
135 masks[2] = 0x00000FFC; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
136 masks[3] = 0x00000003; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
137 break; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
138 default: |
3484
fed6d4c6c693
Set the error so someone can get more information
Sam Lantinga <slouken@libsdl.org>
parents:
3284
diff
changeset
|
139 SDL_SetError("Unknown pixel format"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
140 return SDL_FALSE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
141 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
142 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
143 switch (SDL_PIXELORDER(format)) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
144 case SDL_PACKEDORDER_XRGB: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
145 *Rmask = masks[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
146 *Gmask = masks[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
147 *Bmask = masks[3]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
148 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
149 case SDL_PACKEDORDER_RGBX: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
150 *Rmask = masks[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
151 *Gmask = masks[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
152 *Bmask = masks[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
153 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
154 case SDL_PACKEDORDER_ARGB: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
155 *Amask = masks[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
156 *Rmask = masks[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
157 *Gmask = masks[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
158 *Bmask = masks[3]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
159 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
160 case SDL_PACKEDORDER_RGBA: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
161 *Rmask = masks[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
162 *Gmask = masks[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
163 *Bmask = masks[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
164 *Amask = masks[3]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
165 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
166 case SDL_PACKEDORDER_XBGR: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
167 *Bmask = masks[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
168 *Gmask = masks[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
169 *Rmask = masks[3]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
170 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
171 case SDL_PACKEDORDER_BGRX: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
172 *Bmask = masks[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
173 *Gmask = masks[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
174 *Rmask = masks[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
175 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
176 case SDL_PACKEDORDER_BGRA: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
177 *Bmask = masks[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
178 *Gmask = masks[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
179 *Rmask = masks[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
180 *Amask = masks[3]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
181 break; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
182 case SDL_PACKEDORDER_ABGR: |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
183 *Amask = masks[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
184 *Bmask = masks[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
185 *Gmask = masks[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
186 *Rmask = masks[3]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
187 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
188 default: |
3484
fed6d4c6c693
Set the error so someone can get more information
Sam Lantinga <slouken@libsdl.org>
parents:
3284
diff
changeset
|
189 SDL_SetError("Unknown pixel format"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
190 return SDL_FALSE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
191 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
192 return SDL_TRUE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
193 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
194 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
195 Uint32 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
196 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
197 Uint32 Amask) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
198 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
199 switch (bpp) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
200 case 8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
201 switch (Rmask) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
202 case 0: |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
203 return SDL_PIXELFORMAT_INDEX8; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
204 case 0xE0: |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
205 return SDL_PIXELFORMAT_RGB332; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
206 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
207 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
208 case 12: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
209 switch (Rmask) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
210 case 0x0F00: |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
211 return SDL_PIXELFORMAT_RGB444; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
212 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
213 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
214 case 15: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
215 switch (Rmask) { |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2275
diff
changeset
|
216 case 0x001F: |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2275
diff
changeset
|
217 return SDL_PIXELFORMAT_BGR555; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
218 case 0x7C00: |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
219 return SDL_PIXELFORMAT_RGB555; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
220 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
221 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
222 case 16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
223 switch (Rmask) { |
3163
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
224 case 0x000F: |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
225 return SDL_PIXELFORMAT_ABGR4444; |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2275
diff
changeset
|
226 case 0x001F: |
3163
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
227 if (Gmask == 0x07E0) { |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
228 return SDL_PIXELFORMAT_BGR565; |
a252014ce27d
Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents:
2990
diff
changeset
|
229 } |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2275
diff
changeset
|
230 return SDL_PIXELFORMAT_ABGR1555; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
231 case 0x0F00: |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
232 return SDL_PIXELFORMAT_ARGB4444; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
233 case 0x7C00: |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
234 return SDL_PIXELFORMAT_ARGB1555; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
235 case 0xF800: |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
236 return SDL_PIXELFORMAT_RGB565; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
237 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
238 break; |
3182
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
239 case 24: |
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
240 switch (Rmask) { |
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
241 case 0x00FF0000: |
3597 | 242 #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
243 return SDL_PIXELFORMAT_RGB24; | |
244 #else | |
245 return SDL_PIXELFORMAT_BGR24; | |
246 #endif | |
3182
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
247 case 0x000000FF: |
3597 | 248 #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
249 return SDL_PIXELFORMAT_BGR24; | |
250 #else | |
251 return SDL_PIXELFORMAT_RGB24; | |
252 #endif | |
3182
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
253 case 0x00000000: |
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
254 /* FIXME: At this point we can't distinguish */ |
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
255 /* if this format is RGB24 or BGR24 */ |
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
256 return SDL_PIXELFORMAT_RGB24; |
9f82979eaaf0
Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents:
3163
diff
changeset
|
257 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
258 case 32: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
259 switch (Rmask) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
260 case 0xFF000000: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
261 if (Amask == 0x000000FF) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
262 return SDL_PIXELFORMAT_RGBA8888; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
263 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
264 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
265 case 0x00FF0000: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
266 if (Amask == 0xFF000000) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
267 return SDL_PIXELFORMAT_ARGB8888; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
268 } else { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
269 return SDL_PIXELFORMAT_RGB888; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
270 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
271 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
272 case 0x0000FF00: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
273 if (Amask == 0x000000FF) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
274 return SDL_PIXELFORMAT_BGRA8888; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
275 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
276 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
277 case 0x000000FF: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
278 if (Amask == 0xFF000000) { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
279 return SDL_PIXELFORMAT_ABGR8888; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
280 } else { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
281 return SDL_PIXELFORMAT_BGR888; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
282 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
283 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
284 case 0x3FF00000: |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
285 return SDL_PIXELFORMAT_ARGB2101010; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
286 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
287 } |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
288 return SDL_PIXELFORMAT_UNKNOWN; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
289 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
290 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
291 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
292 SDL_Palette * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
293 SDL_AllocPalette(int ncolors) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
294 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
295 SDL_Palette *palette; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
296 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
297 palette = (SDL_Palette *) SDL_malloc(sizeof(*palette)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
298 if (!palette) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
299 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
300 return NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
301 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
302 palette->colors = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
303 (SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
304 if (!palette->colors) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
305 SDL_free(palette); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
306 return NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
307 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
308 palette->ncolors = ncolors; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
309 palette->watch = NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
310 palette->refcount = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
311 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
312 SDL_memset(palette->colors, 0xFF, ncolors * sizeof(*palette->colors)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
313 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
314 return palette; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
315 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
316 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
317 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
318 SDL_AddPaletteWatch(SDL_Palette * palette, SDL_PaletteChangedFunc callback, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
319 void *userdata) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
320 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
321 SDL_PaletteWatch *watch; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
322 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
323 if (!palette) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
324 return -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
325 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
326 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
327 watch = (SDL_PaletteWatch *) SDL_malloc(sizeof(*watch)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
328 if (!watch) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
329 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
330 return -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
331 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
332 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
333 watch->callback = callback; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
334 watch->userdata = userdata; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
335 watch->next = palette->watch; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
336 palette->watch = watch; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
337 ++palette->refcount; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
338 return 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
339 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
340 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
341 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
342 SDL_DelPaletteWatch(SDL_Palette * palette, SDL_PaletteChangedFunc callback, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
343 void *userdata) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
344 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
345 SDL_PaletteWatch *prev, *watch; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
346 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
347 if (!palette) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
348 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
349 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
350 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
351 for (prev = NULL, watch = palette->watch; watch; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
352 prev = watch, watch = watch->next) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
353 if (watch->callback == callback && watch->userdata == userdata) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
354 if (prev) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
355 prev->next = watch->next; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
356 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
357 palette->watch = watch->next; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
358 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
359 SDL_free(watch); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
360 SDL_FreePalette(palette); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
361 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
362 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
363 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
364 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
365 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
366 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
367 SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
368 int firstcolor, int ncolors) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
369 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
370 SDL_PaletteWatch *watch; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
371 int status = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
372 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
373 /* Verify the parameters */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
374 if (!palette) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
375 return -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
376 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
377 if (ncolors > (palette->ncolors - firstcolor)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
378 ncolors = (palette->ncolors - firstcolor); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
379 status = -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
380 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
381 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
382 if (colors != (palette->colors + firstcolor)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
383 SDL_memcpy(palette->colors + firstcolor, colors, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
384 ncolors * sizeof(*colors)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
385 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
386 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
387 for (watch = palette->watch; watch; watch = watch->next) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
388 if (watch->callback(watch->userdata, palette) < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
389 status = -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
390 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
391 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
392 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
393 return status; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
394 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
395 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
396 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
397 SDL_FreePalette(SDL_Palette * palette) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
398 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
399 if (!palette) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
400 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
401 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
402 if (--palette->refcount > 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
403 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
404 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
405 if (palette->colors) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
406 SDL_free(palette->colors); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
407 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
408 SDL_free(palette); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
409 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
410 |
0 | 411 /* |
412 * Allocate a pixel format structure and fill it according to the given info. | |
413 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
414 SDL_PixelFormat * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
415 SDL_AllocFormat(int bpp, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
416 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) |
0 | 417 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
418 SDL_PixelFormat *format; |
0 | 419 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
420 /* Allocate an empty pixel format structure */ |
2967
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
421 format = SDL_malloc(sizeof(*format)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
422 if (format == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
423 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
424 return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
425 } |
0 | 426 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
427 /* Set up the format */ |
2967
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
428 return SDL_InitFormat(format, bpp, Rmask, Gmask, Bmask, Amask); |
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
429 } |
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
430 |
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
431 SDL_PixelFormat * |
2990 | 432 SDL_InitFormat(SDL_PixelFormat * format, int bpp, Uint32 Rmask, Uint32 Gmask, |
433 Uint32 Bmask, Uint32 Amask) | |
2967
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
434 { |
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
435 Uint32 mask; |
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
436 |
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
437 /* Set up the format */ |
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
438 SDL_zerop(format); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
439 format->BitsPerPixel = bpp; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
440 format->BytesPerPixel = (bpp + 7) / 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
441 if (Rmask || Bmask || Gmask) { /* Packed pixels with custom mask */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
442 format->Rshift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
443 format->Rloss = 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
444 if (Rmask) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
445 for (mask = Rmask; !(mask & 0x01); mask >>= 1) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
446 ++format->Rshift; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
447 for (; (mask & 0x01); mask >>= 1) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
448 --format->Rloss; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
449 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
450 format->Gshift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
451 format->Gloss = 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
452 if (Gmask) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
453 for (mask = Gmask; !(mask & 0x01); mask >>= 1) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
454 ++format->Gshift; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
455 for (; (mask & 0x01); mask >>= 1) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
456 --format->Gloss; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
457 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
458 format->Bshift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
459 format->Bloss = 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
460 if (Bmask) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
461 for (mask = Bmask; !(mask & 0x01); mask >>= 1) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
462 ++format->Bshift; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
463 for (; (mask & 0x01); mask >>= 1) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
464 --format->Bloss; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
465 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
466 format->Ashift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
467 format->Aloss = 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
468 if (Amask) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
469 for (mask = Amask; !(mask & 0x01); mask >>= 1) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
470 ++format->Ashift; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
471 for (; (mask & 0x01); mask >>= 1) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
472 --format->Aloss; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
473 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
474 format->Rmask = Rmask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
475 format->Gmask = Gmask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
476 format->Bmask = Bmask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
477 format->Amask = Amask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
478 } else if (bpp > 8) { /* Packed pixels with standard mask */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
479 /* R-G-B */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
480 if (bpp > 24) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
481 bpp = 24; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
482 format->Rloss = 8 - (bpp / 3); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
483 format->Gloss = 8 - (bpp / 3) - (bpp % 3); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
484 format->Bloss = 8 - (bpp / 3); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
485 format->Rshift = ((bpp / 3) + (bpp % 3)) + (bpp / 3); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
486 format->Gshift = (bpp / 3); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
487 format->Bshift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
488 format->Rmask = ((0xFF >> format->Rloss) << format->Rshift); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
489 format->Gmask = ((0xFF >> format->Gloss) << format->Gshift); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
490 format->Bmask = ((0xFF >> format->Bloss) << format->Bshift); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
491 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
492 /* Palettized formats have no mask info */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
493 format->Rloss = 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
494 format->Gloss = 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
495 format->Bloss = 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
496 format->Aloss = 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
497 format->Rshift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
498 format->Gshift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
499 format->Bshift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
500 format->Ashift = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
501 format->Rmask = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
502 format->Gmask = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
503 format->Bmask = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
504 format->Amask = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
505 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
506 format->palette = NULL; |
1057
e9d23bb80140
Date: Mon, 02 May 2005 04:23:16 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
1027
diff
changeset
|
507 |
2967
e4a469d6ddab
Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
508 return format; |
0 | 509 } |
510 | |
511 /* | |
512 * Change any previous mappings from/to the new surface format | |
513 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
514 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
515 SDL_FormatChanged(SDL_Surface * surface) |
0 | 516 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
517 static int format_version = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
518 ++format_version; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
519 if (format_version < 0) { /* It wrapped... */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
520 format_version = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
521 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
522 surface->format_version = format_version; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
523 SDL_InvalidateMap(surface->map); |
0 | 524 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
525 |
0 | 526 /* |
527 * Free a previously allocated format structure | |
528 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
529 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
530 SDL_FreeFormat(SDL_PixelFormat * format) |
0 | 531 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
532 if (!format) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
533 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
534 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
535 SDL_free(format); |
0 | 536 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
537 |
0 | 538 /* |
539 * Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors | |
540 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
541 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
542 SDL_DitherColors(SDL_Color * colors, int bpp) |
0 | 543 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
544 int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
545 if (bpp != 8) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
546 return; /* only 8bpp supported right now */ |
0 | 547 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
548 for (i = 0; i < 256; i++) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
549 int r, g, b; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
550 /* map each bit field to the full [0, 255] interval, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
551 so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
552 r = i & 0xe0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
553 r |= r >> 3 | r >> 6; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
554 colors[i].r = r; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
555 g = (i << 3) & 0xe0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
556 g |= g >> 3 | g >> 6; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
557 colors[i].g = g; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
558 b = i & 0x3; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
559 b |= b << 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
560 b |= b << 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
561 colors[i].b = b; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
562 colors[i].unused = SDL_ALPHA_OPAQUE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
563 } |
0 | 564 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
565 |
0 | 566 /* |
567 * Calculate the pad-aligned scanline width of a surface | |
568 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
569 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
570 SDL_CalculatePitch(SDL_Surface * surface) |
0 | 571 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
572 int pitch; |
0 | 573 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
574 /* Surface should be 4-byte aligned for speed */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
575 pitch = surface->w * surface->format->BytesPerPixel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
576 switch (surface->format->BitsPerPixel) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
577 case 1: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
578 pitch = (pitch + 7) / 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
579 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
580 case 4: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
581 pitch = (pitch + 1) / 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
582 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
583 default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
584 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
585 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
586 pitch = (pitch + 3) & ~3; /* 4-byte aligning */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
587 return (pitch); |
0 | 588 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
589 |
0 | 590 /* |
591 * Match an RGB value to a particular palette index | |
592 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
593 Uint8 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
594 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b) |
0 | 595 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
596 /* Do colorspace distance matching */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
597 unsigned int smallest; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
598 unsigned int distance; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
599 int rd, gd, bd; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
600 int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
601 Uint8 pixel = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
602 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
603 smallest = ~0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
604 for (i = 0; i < pal->ncolors; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
605 rd = pal->colors[i].r - r; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
606 gd = pal->colors[i].g - g; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
607 bd = pal->colors[i].b - b; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
608 distance = (rd * rd) + (gd * gd) + (bd * bd); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
609 if (distance < smallest) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
610 pixel = i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
611 if (distance == 0) { /* Perfect match! */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
612 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
613 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
614 smallest = distance; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
615 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
616 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
617 return (pixel); |
0 | 618 } |
619 | |
620 /* Find the opaque pixel value corresponding to an RGB triple */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
621 Uint32 |
2275
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
622 SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b) |
0 | 623 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
624 if (format->palette == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
625 return (r >> format->Rloss) << format->Rshift |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
626 | (g >> format->Gloss) << format->Gshift |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
627 | (b >> format->Bloss) << format->Bshift | format->Amask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
628 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
629 return SDL_FindColor(format->palette, r, g, b); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
630 } |
0 | 631 } |
632 | |
633 /* Find the pixel value corresponding to an RGBA quadruple */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
634 Uint32 |
2275
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
635 SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b, |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
636 Uint8 a) |
0 | 637 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
638 if (format->palette == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
639 return (r >> format->Rloss) << format->Rshift |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
640 | (g >> format->Gloss) << format->Gshift |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
641 | (b >> format->Bloss) << format->Bshift |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
642 | ((a >> format->Aloss) << format->Ashift & format->Amask); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
643 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
644 return SDL_FindColor(format->palette, r, g, b); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
645 } |
0 | 646 } |
647 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
648 void |
2275
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
649 SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g, |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
650 Uint8 * b) |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
651 { |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
652 if (format->palette == NULL) { |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
653 /* |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
654 * This makes sure that the result is mapped to the |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
655 * interval [0..255], and the maximum value for each |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
656 * component is 255. This is important to make sure |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
657 * that white is indeed reported as (255, 255, 255). |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
658 * This only works for RGB bit fields at least 4 bit |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
659 * wide, which is almost always the case. |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
660 */ |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
661 unsigned v; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
662 v = (pixel & format->Rmask) >> format->Rshift; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
663 *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1))); |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
664 v = (pixel & format->Gmask) >> format->Gshift; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
665 *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1))); |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
666 v = (pixel & format->Bmask) >> format->Bshift; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
667 *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1))); |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
668 } else { |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
669 *r = format->palette->colors[pixel].r; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
670 *g = format->palette->colors[pixel].g; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
671 *b = format->palette->colors[pixel].b; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
672 } |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
673 } |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
674 |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
675 void |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
676 SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format, |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
677 Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a) |
0 | 678 { |
2275
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
679 if (format->palette == NULL) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
680 /* |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
681 * This makes sure that the result is mapped to the |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
682 * interval [0..255], and the maximum value for each |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
683 * component is 255. This is important to make sure |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
684 * that white is indeed reported as (255, 255, 255), |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
685 * and that opaque alpha is 255. |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
686 * This only works for RGB bit fields at least 4 bit |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
687 * wide, which is almost always the case. |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
688 */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
689 unsigned v; |
2275
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
690 v = (pixel & format->Rmask) >> format->Rshift; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
691 *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1))); |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
692 v = (pixel & format->Gmask) >> format->Gshift; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
693 *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1))); |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
694 v = (pixel & format->Bmask) >> format->Bshift; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
695 *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1))); |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
696 if (format->Amask) { |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
697 v = (pixel & format->Amask) >> format->Ashift; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
698 *a = (v << format->Aloss) + (v >> (8 - (format->Aloss << 1))); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
699 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
700 *a = SDL_ALPHA_OPAQUE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
701 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
702 } else { |
2275
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
703 *r = format->palette->colors[pixel].r; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
704 *g = format->palette->colors[pixel].g; |
12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
705 *b = format->palette->colors[pixel].b; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
706 *a = SDL_ALPHA_OPAQUE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
707 } |
0 | 708 } |
709 | |
710 /* Apply gamma to a set of colors - this is easy. :) */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
711 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
712 SDL_ApplyGamma(Uint16 * gamma, SDL_Color * colors, SDL_Color * output, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
713 int ncolors) |
0 | 714 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
715 int i; |
0 | 716 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
717 for (i = 0; i < ncolors; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
718 output[i].r = gamma[0 * 256 + colors[i].r] >> 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
719 output[i].g = gamma[1 * 256 + colors[i].g] >> 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
720 output[i].b = gamma[2 * 256 + colors[i].b] >> 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
721 } |
0 | 722 } |
723 | |
724 /* Map from Palette to Palette */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
725 static Uint8 * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
726 Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) |
0 | 727 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
728 Uint8 *map; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
729 int i; |
0 | 730 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
731 if (identical) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
732 if (src->ncolors <= dst->ncolors) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
733 /* If an identical palette, no need to map */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
734 if (src == dst |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
735 || |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
736 (SDL_memcmp |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
737 (src->colors, dst->colors, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
738 src->ncolors * sizeof(SDL_Color)) == 0)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
739 *identical = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
740 return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
741 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
742 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
743 *identical = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
744 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
745 map = (Uint8 *) SDL_malloc(src->ncolors); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
746 if (map == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
747 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
748 return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
749 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
750 for (i = 0; i < src->ncolors; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
751 map[i] = SDL_FindColor(dst, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
752 src->colors[i].r, src->colors[i].g, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
753 src->colors[i].b); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
754 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
755 return (map); |
0 | 756 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
757 |
0 | 758 /* Map from Palette to BitField */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
759 static Uint8 * |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
760 Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
761 SDL_PixelFormat * dst) |
0 | 762 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
763 Uint8 *map; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
764 int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
765 int bpp; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
766 SDL_Palette *pal = src->palette; |
0 | 767 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
768 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
769 map = (Uint8 *) SDL_malloc(pal->ncolors * bpp); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
770 if (map == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
771 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
772 return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
773 } |
0 | 774 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
775 /* We memory copy to the pixel map so the endianness is preserved */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
776 for (i = 0; i < pal->ncolors; ++i) { |
2257
340942cfda48
Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents:
2120
diff
changeset
|
777 Uint8 A = Amod; |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
778 Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255); |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
779 Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255); |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
780 Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255); |
2257
340942cfda48
Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents:
2120
diff
changeset
|
781 ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
782 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
783 return (map); |
0 | 784 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
785 |
0 | 786 /* Map from BitField to Dithered-Palette to Palette */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
787 static Uint8 * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
788 MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical) |
0 | 789 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
790 /* Generate a 256 color dither palette */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
791 SDL_Palette dithered; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
792 SDL_Color colors[256]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
793 SDL_Palette *pal = dst->palette; |
0 | 794 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
795 dithered.ncolors = 256; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
796 SDL_DitherColors(colors, 8); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
797 dithered.colors = colors; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
798 return (Map1to1(&dithered, pal, identical)); |
0 | 799 } |
800 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
801 SDL_BlitMap * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
802 SDL_AllocBlitMap(void) |
0 | 803 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
804 SDL_BlitMap *map; |
0 | 805 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
806 /* Allocate the empty map */ |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
807 map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
808 if (map == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
809 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
810 return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
811 } |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
812 map->info.r = 0xFF; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
813 map->info.g = 0xFF; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
814 map->info.b = 0xFF; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
815 map->info.a = 0xFF; |
0 | 816 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
817 /* It's ready to go */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
818 return (map); |
0 | 819 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
820 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
821 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
822 SDL_InvalidateMap(SDL_BlitMap * map) |
0 | 823 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
824 if (!map) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
825 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
826 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
827 map->dst = NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
828 map->format_version = (unsigned int) -1; |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
829 if (map->info.table) { |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
830 SDL_free(map->info.table); |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
831 map->info.table = NULL; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
832 } |
0 | 833 } |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2275
diff
changeset
|
834 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
835 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
836 SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) |
0 | 837 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
838 SDL_PixelFormat *srcfmt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
839 SDL_PixelFormat *dstfmt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
840 SDL_BlitMap *map; |
0 | 841 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
842 /* Clear out any previous mapping */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
843 map = src->map; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
844 if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
845 SDL_UnRLESurface(src, 1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
846 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
847 SDL_InvalidateMap(map); |
0 | 848 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
849 /* Figure out what kind of mapping we're doing */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
850 map->identity = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
851 srcfmt = src->format; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
852 dstfmt = dst->format; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
853 switch (srcfmt->BytesPerPixel) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
854 case 1: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
855 switch (dstfmt->BytesPerPixel) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
856 case 1: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
857 /* Palette --> Palette */ |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
858 map->info.table = |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
859 Map1to1(srcfmt->palette, dstfmt->palette, &map->identity); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
860 if (!map->identity) { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
861 if (map->info.table == NULL) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
862 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
863 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
864 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
865 if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
866 map->identity = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
867 break; |
0 | 868 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
869 default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
870 /* Palette --> BitField */ |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
871 map->info.table = |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
872 Map1toN(srcfmt, src->map->info.r, src->map->info.g, |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
873 src->map->info.b, src->map->info.a, dstfmt); |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
874 if (map->info.table == NULL) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
875 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
876 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
877 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
878 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
879 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
880 default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
881 switch (dstfmt->BytesPerPixel) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
882 case 1: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
883 /* BitField --> Palette */ |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
884 map->info.table = MapNto1(srcfmt, dstfmt, &map->identity); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
885 if (!map->identity) { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
886 if (map->info.table == NULL) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
887 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
888 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
889 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
890 map->identity = 0; /* Don't optimize to copy */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
891 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
892 default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
893 /* BitField --> BitField */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
894 if (FORMAT_EQUAL(srcfmt, dstfmt)) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
895 map->identity = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
896 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
897 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
898 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
899 } |
0 | 900 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
901 map->dst = dst; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
902 map->format_version = dst->format_version; |
0 | 903 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
904 /* Choose your blitters wisely */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
905 return (SDL_CalculateBlit(src)); |
0 | 906 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
907 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
908 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
909 SDL_FreeBlitMap(SDL_BlitMap * map) |
0 | 910 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
911 if (map) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
912 SDL_InvalidateMap(map); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
913 SDL_free(map); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
914 } |
0 | 915 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
916 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1557
diff
changeset
|
917 /* vi: set ts=4 sw=4 expandtab: */ |