comparison src/video/SDL_surface.c @ 2267:c785543d1843

Okay, still some bugs, but everything builds again...
author Sam Lantinga <slouken@libsdl.org>
date Sat, 18 Aug 2007 05:39:09 +0000
parents e61ad15a205f
children 91e601d9df8b
comparison
equal deleted inserted replaced
2266:e61ad15a205f 2267:c785543d1843
50 50
51 surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask); 51 surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
52 if (!surface->format) { 52 if (!surface->format) {
53 SDL_FreeSurface(surface); 53 SDL_FreeSurface(surface);
54 return NULL; 54 return NULL;
55 }
56 if (Amask) {
57 surface->flags |= SDL_SRCALPHA;
58 } 55 }
59 surface->w = width; 56 surface->w = width;
60 surface->h = height; 57 surface->h = height;
61 surface->pitch = SDL_CalculatePitch(surface); 58 surface->pitch = SDL_CalculatePitch(surface);
62 SDL_SetClipRect(surface, NULL); 59 SDL_SetClipRect(surface, NULL);
136 SDL_FreeSurface(surface); 133 SDL_FreeSurface(surface);
137 return NULL; 134 return NULL;
138 } 135 }
139 SDL_FormatChanged(surface); 136 SDL_FormatChanged(surface);
140 137
138 /* By default surface with an alpha mask are set up for blending */
139 if (Amask) {
140 SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND);
141 }
142
141 /* The surface is ready to go */ 143 /* The surface is ready to go */
142 surface->refcount = 1; 144 surface->refcount = 1;
143 #ifdef CHECK_LEAKS 145 #ifdef CHECK_LEAKS
144 ++surfaces_allocated; 146 ++surfaces_allocated;
145 #endif 147 #endif
210 SDL_SurfacePaletteChanged, surface); 212 SDL_SurfacePaletteChanged, surface);
211 } 213 }
212 return 0; 214 return 0;
213 } 215 }
214 216
215 int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag) 217 int
216 { 218 SDL_SetSurfaceRLE(SDL_Surface * surface, int flag)
217 Uint32 flags; 219 {
218 220 int flags;
219 if (!surface) { 221
220 return -1; 222 if (!surface) {
221 } 223 return -1;
222 224 }
225
226 flags = surface->map->info.flags;
223 if (flag) { 227 if (flag) {
224 surface->flags |= SDL_RLEACCELOK; 228 surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
225 } else { 229 } else {
226 surface->flags &= ~SDL_RLEACCELOK; 230 surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
227 } 231 }
228 if (surface->flags != flags) { 232 if (surface->map->info.flags != flags) {
229 SDL_InvalidateMap(surface->map); 233 SDL_InvalidateMap(surface->map);
230 } 234 }
231 return 0; 235 return 0;
232 } 236 }
233 237
234 int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key) 238 int
239 SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key)
235 { 240 {
236 int flags; 241 int flags;
237 242
238 if (!surface) { 243 if (!surface) {
239 return -1; 244 return -1;
251 surface->map->info.flags &= ~SDL_COPY_COLORKEY; 256 surface->map->info.flags &= ~SDL_COPY_COLORKEY;
252 } 257 }
253 if (surface->map->info.flags != flags) { 258 if (surface->map->info.flags != flags) {
254 SDL_InvalidateMap(surface->map); 259 SDL_InvalidateMap(surface->map);
255 } 260 }
256 return 0; 261
257 } 262 /* Compatibility mode */
258 263 if (surface->map->info.flags & SDL_COPY_COLORKEY) {
259 int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b) 264 surface->flags |= SDL_SRCCOLORKEY;
265 } else {
266 surface->flags &= ~SDL_SRCCOLORKEY;
267 }
268
269 return 0;
270 }
271
272 int
273 SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
260 { 274 {
261 int flags; 275 int flags;
262 276
263 if (!surface) { 277 if (!surface) {
264 return -1; 278 return -1;
279 } 293 }
280 return 0; 294 return 0;
281 } 295 }
282 296
283 297
284 int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 * r, Uint8 * g, Uint8 * b) 298 int
299 SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b)
285 { 300 {
286 if (!surface) { 301 if (!surface) {
287 return -1; 302 return -1;
288 } 303 }
289 304
297 *b = surface->map->info.b; 312 *b = surface->map->info.b;
298 } 313 }
299 return 0; 314 return 0;
300 } 315 }
301 316
302 int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha) 317 int
318 SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha)
303 { 319 {
304 int flags; 320 int flags;
305 321
306 if (!surface) { 322 if (!surface) {
307 return -1; 323 return -1;
319 SDL_InvalidateMap(surface->map); 335 SDL_InvalidateMap(surface->map);
320 } 336 }
321 return 0; 337 return 0;
322 } 338 }
323 339
324 int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 * alpha) 340 int
341 SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha)
325 { 342 {
326 if (!surface) { 343 if (!surface) {
327 return -1; 344 return -1;
328 } 345 }
329 346
331 *alpha = surface->map->info.a; 348 *alpha = surface->map->info.a;
332 } 349 }
333 return 0; 350 return 0;
334 } 351 }
335 352
336 int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode) 353 int
354 SDL_SetSurfaceBlendMode(SDL_Surface * surface, int blendMode)
337 { 355 {
338 int flags, status; 356 int flags, status;
339 357
340 if (!surface) { 358 if (!surface) {
341 return -1; 359 return -1;
342 } 360 }
343 361
344 status = 0; 362 status = 0;
345 flags = surface->map->info.flags; 363 flags = surface->map->info.flags;
346 surface->map->info.flags &= ~(SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD); 364 surface->map->info.flags &=
365 ~(SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD);
347 switch (blendMode) { 366 switch (blendMode) {
348 case SDL_TEXTUREBLENDMODE_NONE: 367 case SDL_TEXTUREBLENDMODE_NONE:
349 break; 368 break;
350 case SDL_TEXTUREBLENDMODE_MASK: 369 case SDL_TEXTUREBLENDMODE_MASK:
351 surface->map->info.flags |= SDL_COPY_MASK; 370 surface->map->info.flags |= SDL_COPY_MASK;
366 } 385 }
367 386
368 if (surface->map->info.flags != flags) { 387 if (surface->map->info.flags != flags) {
369 SDL_InvalidateMap(surface->map); 388 SDL_InvalidateMap(surface->map);
370 } 389 }
390
391 /* Compatibility mode */
392 if (surface->map->info.flags & SDL_COPY_BLEND) {
393 surface->flags |= SDL_SRCALPHA;
394 } else {
395 surface->flags &= ~SDL_SRCALPHA;
396 }
397
371 return status; 398 return status;
372 } 399 }
373 400
374 int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode) 401 int
402 SDL_GetSurfaceBlendMode(SDL_Surface * surface, int *blendMode)
375 { 403 {
376 if (!surface) { 404 if (!surface) {
377 return -1; 405 return -1;
378 } 406 }
379 407
380 if (!blendMode) { 408 if (!blendMode) {
381 return 0; 409 return 0;
382 } 410 }
383 411
384 switch(surface->map->info.flags & (SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) { 412 switch (surface->map->info.
413 flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD |
414 SDL_COPY_MOD)) {
385 case SDL_COPY_MASK: 415 case SDL_COPY_MASK:
386 *blendMode = SDL_TEXTUREBLENDMODE_MASK: 416 *blendMode = SDL_TEXTUREBLENDMODE_MASK;
387 break; 417 break;
388 case SDL_COPY_BLEND: 418 case SDL_COPY_BLEND:
389 *blendMode = SDL_TEXTUREBLENDMODE_BLEND: 419 *blendMode = SDL_TEXTUREBLENDMODE_BLEND;
390 break; 420 break;
391 case SDL_COPY_ADD: 421 case SDL_COPY_ADD:
392 *blendMode = SDL_TEXTUREBLENDMODE_ADD: 422 *blendMode = SDL_TEXTUREBLENDMODE_ADD;
393 break; 423 break;
394 case SDL_COPY_MOD: 424 case SDL_COPY_MOD:
395 *blendMode = SDL_TEXTUREBLENDMODE_MOD: 425 *blendMode = SDL_TEXTUREBLENDMODE_MOD;
396 break; 426 break;
397 default: 427 default:
398 *blendMode = SDL_TEXTUREBLENDMODE_NONE: 428 *blendMode = SDL_TEXTUREBLENDMODE_NONE;
399 break; 429 break;
400 } 430 }
401 return 0; 431 return 0;
402 } 432 }
403 433
404 int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode) 434 int
435 SDL_SetSurfaceScaleMode(SDL_Surface * surface, int scaleMode)
405 { 436 {
406 int flags, status; 437 int flags, status;
407 438
408 if (!surface) { 439 if (!surface) {
409 return -1; 440 return -1;
434 SDL_InvalidateMap(surface->map); 465 SDL_InvalidateMap(surface->map);
435 } 466 }
436 return status; 467 return status;
437 } 468 }
438 469
439 int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode) 470 int
471 SDL_GetSurfaceScaleMode(SDL_Surface * surface, int *scaleMode)
440 { 472 {
441 if (!surface) { 473 if (!surface) {
442 return -1; 474 return -1;
443 } 475 }
444 476
445 if (!scaleMode) { 477 if (!scaleMode) {
446 return 0; 478 return 0;
447 } 479 }
448 480
449 switch(surface->map->info.flags & (SDL_COPY_LINEAR)) { 481 switch (surface->map->info.flags & (SDL_COPY_NEAREST)) {
450 case SDL_COPY_LINEAR: 482 case SDL_COPY_NEAREST:
451 *scaleMode = SDL_TEXTURESCALEMODE_FAST: 483 *scaleMode = SDL_TEXTURESCALEMODE_FAST;
452 break; 484 break;
453 default: 485 default:
454 *scaleMode = SDL_TEXTURESCALEMODE_NONE: 486 *scaleMode = SDL_TEXTURESCALEMODE_NONE;
455 break; 487 break;
456 } 488 }
457 return 0; 489 return 0;
458 } 490 }
459 491
704 /* Clean up the original surface, and update converted surface */ 736 /* Clean up the original surface, and update converted surface */
705 SDL_SetClipRect(convert, &surface->clip_rect); 737 SDL_SetClipRect(convert, &surface->clip_rect);
706 if (copy_flags & SDL_COPY_COLORKEY) { 738 if (copy_flags & SDL_COPY_COLORKEY) {
707 Uint8 keyR, keyG, keyB, keyA; 739 Uint8 keyR, keyG, keyB, keyA;
708 740
709 SDL_GetRGBA(colorkey, surface->format, &keyR, &keyG, &keyB, &keyA); 741 SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR,
742 &keyG, &keyB, &keyA);
710 SDL_SetColorKey(convert, 1, 743 SDL_SetColorKey(convert, 1,
711 SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); 744 SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA));
712 } 745 }
713 convert->map->info.r = surface->map->info.r; 746 convert->map->info.r = surface->map->info.r;
714 convert->map->info.g = surface->map->info.g; 747 convert->map->info.g = surface->map->info.g;