comparison src/video/SDL_pixels.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents 450721ad5436
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
41 { 41 {
42 SDL_PixelFormat *format; 42 SDL_PixelFormat *format;
43 Uint32 mask; 43 Uint32 mask;
44 44
45 /* Allocate an empty pixel format structure */ 45 /* Allocate an empty pixel format structure */
46 format = malloc(sizeof(*format)); 46 format = SDL_malloc(sizeof(*format));
47 if ( format == NULL ) { 47 if ( format == NULL ) {
48 SDL_OutOfMemory(); 48 SDL_OutOfMemory();
49 return(NULL); 49 return(NULL);
50 } 50 }
51 memset(format, 0, sizeof(*format)); 51 SDL_memset(format, 0, sizeof(*format));
52 format->alpha = SDL_ALPHA_OPAQUE; 52 format->alpha = SDL_ALPHA_OPAQUE;
53 53
54 /* Set up the format */ 54 /* Set up the format */
55 format->BitsPerPixel = bpp; 55 format->BitsPerPixel = bpp;
56 format->BytesPerPixel = (bpp+7)/8; 56 format->BytesPerPixel = (bpp+7)/8;
123 if ( bpp <= 8 ) { /* Palettized mode */ 123 if ( bpp <= 8 ) { /* Palettized mode */
124 int ncolors = 1<<bpp; 124 int ncolors = 1<<bpp;
125 #ifdef DEBUG_PALETTE 125 #ifdef DEBUG_PALETTE
126 fprintf(stderr,"bpp=%d ncolors=%d\n",bpp,ncolors); 126 fprintf(stderr,"bpp=%d ncolors=%d\n",bpp,ncolors);
127 #endif 127 #endif
128 format->palette = (SDL_Palette *)malloc(sizeof(SDL_Palette)); 128 format->palette = (SDL_Palette *)SDL_malloc(sizeof(SDL_Palette));
129 if ( format->palette == NULL ) { 129 if ( format->palette == NULL ) {
130 SDL_FreeFormat(format); 130 SDL_FreeFormat(format);
131 SDL_OutOfMemory(); 131 SDL_OutOfMemory();
132 return(NULL); 132 return(NULL);
133 } 133 }
134 (format->palette)->ncolors = ncolors; 134 (format->palette)->ncolors = ncolors;
135 (format->palette)->colors = (SDL_Color *)malloc( 135 (format->palette)->colors = (SDL_Color *)SDL_malloc(
136 (format->palette)->ncolors*sizeof(SDL_Color)); 136 (format->palette)->ncolors*sizeof(SDL_Color));
137 if ( (format->palette)->colors == NULL ) { 137 if ( (format->palette)->colors == NULL ) {
138 SDL_FreeFormat(format); 138 SDL_FreeFormat(format);
139 SDL_OutOfMemory(); 139 SDL_OutOfMemory();
140 return(NULL); 140 return(NULL);
215 format->palette->colors[1].r = 0x00; 215 format->palette->colors[1].r = 0x00;
216 format->palette->colors[1].g = 0x00; 216 format->palette->colors[1].g = 0x00;
217 format->palette->colors[1].b = 0x00; 217 format->palette->colors[1].b = 0x00;
218 } else { 218 } else {
219 /* Create an empty palette */ 219 /* Create an empty palette */
220 memset((format->palette)->colors, 0, 220 SDL_memset((format->palette)->colors, 0,
221 (format->palette)->ncolors*sizeof(SDL_Color)); 221 (format->palette)->ncolors*sizeof(SDL_Color));
222 } 222 }
223 } 223 }
224 return(format); 224 return(format);
225 } 225 }
253 void SDL_FreeFormat(SDL_PixelFormat *format) 253 void SDL_FreeFormat(SDL_PixelFormat *format)
254 { 254 {
255 if ( format ) { 255 if ( format ) {
256 if ( format->palette ) { 256 if ( format->palette ) {
257 if ( format->palette->colors ) { 257 if ( format->palette->colors ) {
258 free(format->palette->colors); 258 SDL_free(format->palette->colors);
259 } 259 }
260 free(format->palette); 260 SDL_free(format->palette);
261 } 261 }
262 free(format); 262 SDL_free(format);
263 } 263 }
264 } 264 }
265 /* 265 /*
266 * Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors 266 * Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors
267 */ 267 */
436 int i; 436 int i;
437 437
438 if ( identical ) { 438 if ( identical ) {
439 if ( src->ncolors <= dst->ncolors ) { 439 if ( src->ncolors <= dst->ncolors ) {
440 /* If an identical palette, no need to map */ 440 /* If an identical palette, no need to map */
441 if ( memcmp(src->colors, dst->colors, src->ncolors* 441 if ( SDL_memcmp(src->colors, dst->colors, src->ncolors*
442 sizeof(SDL_Color)) == 0 ) { 442 sizeof(SDL_Color)) == 0 ) {
443 *identical = 1; 443 *identical = 1;
444 return(NULL); 444 return(NULL);
445 } 445 }
446 } 446 }
447 *identical = 0; 447 *identical = 0;
448 } 448 }
449 map = (Uint8 *)malloc(src->ncolors); 449 map = (Uint8 *)SDL_malloc(src->ncolors);
450 if ( map == NULL ) { 450 if ( map == NULL ) {
451 SDL_OutOfMemory(); 451 SDL_OutOfMemory();
452 return(NULL); 452 return(NULL);
453 } 453 }
454 for ( i=0; i<src->ncolors; ++i ) { 454 for ( i=0; i<src->ncolors; ++i ) {
464 int i; 464 int i;
465 int bpp; 465 int bpp;
466 unsigned alpha; 466 unsigned alpha;
467 467
468 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); 468 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
469 map = (Uint8 *)malloc(src->ncolors*bpp); 469 map = (Uint8 *)SDL_malloc(src->ncolors*bpp);
470 if ( map == NULL ) { 470 if ( map == NULL ) {
471 SDL_OutOfMemory(); 471 SDL_OutOfMemory();
472 return(NULL); 472 return(NULL);
473 } 473 }
474 474
488 SDL_Palette dithered; 488 SDL_Palette dithered;
489 SDL_Color colors[256]; 489 SDL_Color colors[256];
490 490
491 /* SDL_DitherColors does not initialize the 'unused' component of colors, 491 /* SDL_DitherColors does not initialize the 'unused' component of colors,
492 but Map1to1 compares it against dst, so we should initialize it. */ 492 but Map1to1 compares it against dst, so we should initialize it. */
493 memset(colors, 0, sizeof(colors)); 493 SDL_memset(colors, 0, sizeof(colors));
494 494
495 dithered.ncolors = 256; 495 dithered.ncolors = 256;
496 SDL_DitherColors(colors, 8); 496 SDL_DitherColors(colors, 8);
497 dithered.colors = colors; 497 dithered.colors = colors;
498 return(Map1to1(&dithered, dst, identical)); 498 return(Map1to1(&dithered, dst, identical));
501 SDL_BlitMap *SDL_AllocBlitMap(void) 501 SDL_BlitMap *SDL_AllocBlitMap(void)
502 { 502 {
503 SDL_BlitMap *map; 503 SDL_BlitMap *map;
504 504
505 /* Allocate the empty map */ 505 /* Allocate the empty map */
506 map = (SDL_BlitMap *)malloc(sizeof(*map)); 506 map = (SDL_BlitMap *)SDL_malloc(sizeof(*map));
507 if ( map == NULL ) { 507 if ( map == NULL ) {
508 SDL_OutOfMemory(); 508 SDL_OutOfMemory();
509 return(NULL); 509 return(NULL);
510 } 510 }
511 memset(map, 0, sizeof(*map)); 511 SDL_memset(map, 0, sizeof(*map));
512 512
513 /* Allocate the software blit data */ 513 /* Allocate the software blit data */
514 map->sw_data = (struct private_swaccel *)malloc(sizeof(*map->sw_data)); 514 map->sw_data = (struct private_swaccel *)SDL_malloc(sizeof(*map->sw_data));
515 if ( map->sw_data == NULL ) { 515 if ( map->sw_data == NULL ) {
516 SDL_FreeBlitMap(map); 516 SDL_FreeBlitMap(map);
517 SDL_OutOfMemory(); 517 SDL_OutOfMemory();
518 return(NULL); 518 return(NULL);
519 } 519 }
520 memset(map->sw_data, 0, sizeof(*map->sw_data)); 520 SDL_memset(map->sw_data, 0, sizeof(*map->sw_data));
521 521
522 /* It's ready to go */ 522 /* It's ready to go */
523 return(map); 523 return(map);
524 } 524 }
525 void SDL_InvalidateMap(SDL_BlitMap *map) 525 void SDL_InvalidateMap(SDL_BlitMap *map)
528 return; 528 return;
529 } 529 }
530 map->dst = NULL; 530 map->dst = NULL;
531 map->format_version = (unsigned int)-1; 531 map->format_version = (unsigned int)-1;
532 if ( map->table ) { 532 if ( map->table ) {
533 free(map->table); 533 SDL_free(map->table);
534 map->table = NULL; 534 map->table = NULL;
535 } 535 }
536 } 536 }
537 int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst) 537 int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst)
538 { 538 {
613 void SDL_FreeBlitMap(SDL_BlitMap *map) 613 void SDL_FreeBlitMap(SDL_BlitMap *map)
614 { 614 {
615 if ( map ) { 615 if ( map ) {
616 SDL_InvalidateMap(map); 616 SDL_InvalidateMap(map);
617 if ( map->sw_data != NULL ) { 617 if ( map->sw_data != NULL ) {
618 free(map->sw_data); 618 SDL_free(map->sw_data);
619 } 619 }
620 free(map); 620 SDL_free(map);
621 } 621 }
622 } 622 }