rl_image_create now requires a pre-allocated rl_image_t

This commit is contained in:
Andre Leiradella 2015-08-28 13:32:20 -03:00
parent 636ec2a9a5
commit 3a8db2f439
2 changed files with 21 additions and 28 deletions

View File

@ -17,40 +17,34 @@ void rl_image_translate( int x, int y )
tslt_y = y;
}
const rl_image_t* rl_image_create( const rl_imagedata_t* imagedata, int check_transp, uint16_t transparent )
int rl_image_create( rl_image_t* image, const rl_imagedata_t* imagedata, int check_transp, uint16_t transparent )
{
size_t size;
const void* data = rl_imagedata_rle_encode( &size, imagedata, check_transp, transparent );
if ( data )
{
rl_image_t* image = (rl_image_t*)rl_malloc( sizeof( rl_image_t ) );
if ( image )
union
{
union
{
const void* v;
const uint8_t* u8;
const uint16_t* u16;
const uint32_t* u32;
}
ptr;
image->rle = ptr.v = data;
image->width = *ptr.u16++;
image->height = *ptr.u16++;
image->used = *ptr.u32++;
image->data = ptr.u8;
return image;
const void* v;
const uint8_t* u8;
const uint16_t* u16;
const uint32_t* u32;
}
ptr;
rl_free( (void*)data );
image->rle = ptr.v = data;
image->width = *ptr.u16++;
image->height = *ptr.u16++;
image->used = *ptr.u32++;
image->data = ptr.u8;
return 0;
}
return NULL;
rl_free( (void*)data );
return -1;
}
void rl_image_blit_nobg( const rl_image_t* image, int x, int y )

View File

@ -5,7 +5,6 @@
#include <rl_imgdata.h>
#include <stdint.h>
#include <stddef.h>
/*
An image with RLE-encoded pixels and per-pixel alpha of 0, 25, 50, 75 and 100%.
@ -35,15 +34,15 @@ void rl_image_init( void );
void rl_image_translate( int x, int y );
/* Creates an image from a rl_imagedata_t. */
const rl_image_t* rl_image_create( const rl_imagedata_t* imagedata, int check_transp, uint16_t transparent );
int rl_image_create( rl_image_t* image, const rl_imagedata_t* imagedata, int check_transp, uint16_t transparent );
/* Destroys an image. */
#define rl_image_destroy( image ) do { rl_free( (void*)image->rle ); rl_free( (void*)image ); } while ( 0 )
#define rl_image_destroy( image ) do { rl_free( (void*)image->rle ); } while ( 0 )
/* Blits an image to the given background. */
void rl_image_blit_nobg( const rl_image_t* image, int x, int y );
void rl_image_blit_nobg( const rl_image_t* image, int x, int y );
/* Blits an image to the given background, saving overwritten pixels in bg. */
uint16_t* rl_image_blit( const rl_image_t* image, int x, int y, uint16_t* bg );
/* Erases an image from the given background, restoring overwritten pixels from bg. */
void rl_image_unblit( const rl_image_t* image, int x, int y, const uint16_t* bg );
void rl_image_unblit( const rl_image_t* image, int x, int y, const uint16_t* bg );
#endif /* RL_IMAGE_H */