comparison src/video/SDL_pixels.c @ 1057:e9d23bb80140

Date: Mon, 02 May 2005 04:23:16 -0500 From: Jonathan Atkins Subject: Re: [PATCH] *CRITICAL* 8bit direct RGB palette not being created I think that SDL_AllocFormat should create the palette for all 8bit surfaces. And when the RGBAmasks match the normal 3:3:2:0 we need to apply the old behavior. If the mask doesn't match that, then we need to make the right palette assuming the masks are valid (I don't think we validate any masks for high color surfaces...so we wouldn't here) Then there's always a palette available for the 8bit surfaces. This restores the normal behavior and allows for masks to create palettes automatically for odd masks even, which would be a neato thing to have in there, as SDL never did this before.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 May 2005 05:34:58 +0000
parents c69697a85412
children c9b51268668f
comparison
equal deleted inserted replaced
1056:d33c095f7001 1057:e9d23bb80140
110 format->Gshift = (bpp/3); 110 format->Gshift = (bpp/3);
111 format->Bshift = 0; 111 format->Bshift = 0;
112 format->Rmask = ((0xFF>>format->Rloss)<<format->Rshift); 112 format->Rmask = ((0xFF>>format->Rloss)<<format->Rshift);
113 format->Gmask = ((0xFF>>format->Gloss)<<format->Gshift); 113 format->Gmask = ((0xFF>>format->Gloss)<<format->Gshift);
114 format->Bmask = ((0xFF>>format->Bloss)<<format->Bshift); 114 format->Bmask = ((0xFF>>format->Bloss)<<format->Bshift);
115 } else { /* Palettized mode */ 115 } else {
116 int i, ncolors = 1;
117 for ( i = 0; i < bpp; ++i ) {
118 ncolors *= 2;
119 }
120 format->palette = (SDL_Palette *)malloc(sizeof(SDL_Palette));
121 if ( format->palette == NULL ) {
122 SDL_FreeFormat(format);
123 SDL_OutOfMemory();
124 return(NULL);
125 }
126 (format->palette)->ncolors = ncolors;
127 (format->palette)->colors = (SDL_Color *)malloc(
128 (format->palette)->ncolors*sizeof(SDL_Color));
129 if ( (format->palette)->colors == NULL ) {
130 SDL_FreeFormat(format);
131 SDL_OutOfMemory();
132 return(NULL);
133 }
134 if ( ncolors == 2 ) {
135 /* Create a black and white bitmap palette */
136 format->palette->colors[0].r = 0xFF;
137 format->palette->colors[0].g = 0xFF;
138 format->palette->colors[0].b = 0xFF;
139 format->palette->colors[1].r = 0x00;
140 format->palette->colors[1].g = 0x00;
141 format->palette->colors[1].b = 0x00;
142 } else {
143 /* Create an empty palette */
144 memset((format->palette)->colors, 0,
145 (format->palette)->ncolors*sizeof(SDL_Color));
146 }
147
148 /* Palettized formats have no mask info */ 116 /* Palettized formats have no mask info */
149 format->Rloss = 8; 117 format->Rloss = 8;
150 format->Gloss = 8; 118 format->Gloss = 8;
151 format->Bloss = 8; 119 format->Bloss = 8;
152 format->Aloss = 8; 120 format->Aloss = 8;
156 format->Ashift = 0; 124 format->Ashift = 0;
157 format->Rmask = 0; 125 format->Rmask = 0;
158 format->Gmask = 0; 126 format->Gmask = 0;
159 format->Bmask = 0; 127 format->Bmask = 0;
160 format->Amask = 0; 128 format->Amask = 0;
129 }
130 if ( bpp <= 8 ) { /* Palettized mode */
131 int ncolors = 1<<bpp;
132 #ifdef DEBUG_PALETTE
133 fprintf(stderr,"bpp=%d ncolors=%d\n",bpp,ncolors);
134 #endif
135 format->palette = (SDL_Palette *)malloc(sizeof(SDL_Palette));
136 if ( format->palette == NULL ) {
137 SDL_FreeFormat(format);
138 SDL_OutOfMemory();
139 return(NULL);
140 }
141 (format->palette)->ncolors = ncolors;
142 (format->palette)->colors = (SDL_Color *)malloc(
143 (format->palette)->ncolors*sizeof(SDL_Color));
144 if ( (format->palette)->colors == NULL ) {
145 SDL_FreeFormat(format);
146 SDL_OutOfMemory();
147 return(NULL);
148 }
149 if ( Rmask || Bmask || Gmask ) {
150 /* create palette according to masks */
151 int i;
152 int Rm=0,Gm=0,Bm=0;
153 int Rw=0,Gw=0,Bw=0;
154 #ifdef ENABLE_PALETTE_ALPHA
155 int Am=0,Aw=0;
156 #endif
157 if(Rmask)
158 {
159 Rw=8-format->Rloss;
160 for(i=format->Rloss;i>0;i-=Rw)
161 Rm|=1<<i;
162 }
163 #ifdef DEBUG_PALETTE
164 fprintf(stderr,"Rw=%d Rm=0x%02X\n",Rw,Rm);
165 #endif
166 if(Gmask)
167 {
168 Gw=8-format->Gloss;
169 for(i=format->Gloss;i>0;i-=Gw)
170 Gm|=1<<i;
171 }
172 #ifdef DEBUG_PALETTE
173 fprintf(stderr,"Gw=%d Gm=0x%02X\n",Gw,Gm);
174 #endif
175 if(Bmask)
176 {
177 Bw=8-format->Bloss;
178 for(i=format->Bloss;i>0;i-=Bw)
179 Bm|=1<<i;
180 }
181 #ifdef DEBUG_PALETTE
182 fprintf(stderr,"Bw=%d Bm=0x%02X\n",Bw,Bm);
183 #endif
184 #ifdef ENABLE_PALETTE_ALPHA
185 if(Amask)
186 {
187 Aw=8-format->Aloss;
188 for(i=format->Aloss;i>0;i-=Aw)
189 Am|=1<<i;
190 }
191 # ifdef DEBUG_PALETTE
192 fprintf(stderr,"Aw=%d Am=0x%02X\n",Aw,Am);
193 # endif
194 #endif
195 for(i=0; i < ncolors; ++i) {
196 int r,g,b;
197 r=(i&Rmask)>>format->Rshift;
198 r=(r<<format->Rloss)|((r*Rm)>>Rw);
199 format->palette->colors[i].r=r;
200
201 g=(i&Gmask)>>format->Gshift;
202 g=(g<<format->Gloss)|((g*Gm)>>Gw);
203 format->palette->colors[i].g=g;
204
205 b=(i&Bmask)>>format->Bshift;
206 b=(b<<format->Bloss)|((b*Bm)>>Bw);
207 format->palette->colors[i].b=b;
208
209 #ifdef ENABLE_PALETTE_ALPHA
210 a=(i&Amask)>>format->Ashift;
211 a=(a<<format->Aloss)|((a*Am)>>Aw);
212 format->palette->colors[i].unused=a;
213 #else
214 format->palette->colors[i].unused=0;
215 #endif
216 }
217 } else if ( ncolors == 2 ) {
218 /* Create a black and white bitmap palette */
219 format->palette->colors[0].r = 0xFF;
220 format->palette->colors[0].g = 0xFF;
221 format->palette->colors[0].b = 0xFF;
222 format->palette->colors[1].r = 0x00;
223 format->palette->colors[1].g = 0x00;
224 format->palette->colors[1].b = 0x00;
225 } else {
226 /* Create an empty palette */
227 memset((format->palette)->colors, 0,
228 (format->palette)->ncolors*sizeof(SDL_Color));
229 }
161 } 230 }
162 return(format); 231 return(format);
163 } 232 }
164 SDL_PixelFormat *SDL_ReallocFormat(SDL_Surface *surface, int bpp, 233 SDL_PixelFormat *SDL_ReallocFormat(SDL_Surface *surface, int bpp,
165 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) 234 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)