mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 21:32:45 +00:00
(RTGA) Cleanups
This commit is contained in:
parent
9a5b8f0475
commit
1075522147
@ -54,16 +54,16 @@ typedef struct
|
||||
uint8_t *img_buffer;
|
||||
uint8_t *img_buffer_end;
|
||||
uint8_t *img_buffer_original;
|
||||
} rtga__context;
|
||||
} rtga_context;
|
||||
|
||||
static INLINE uint8_t rtga__get8(rtga__context *s)
|
||||
static INLINE uint8_t rtga_get8(rtga_context *s)
|
||||
{
|
||||
if (s->img_buffer < s->img_buffer_end)
|
||||
return *s->img_buffer++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rtga__skip(rtga__context *s, int n)
|
||||
static void rtga_skip(rtga_context *s, int n)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
@ -73,7 +73,7 @@ static void rtga__skip(rtga__context *s, int n)
|
||||
s->img_buffer += n;
|
||||
}
|
||||
|
||||
static int rtga__getn(rtga__context *s, uint8_t *buffer, int n)
|
||||
static int rtga_getn(rtga_context *s, uint8_t *buffer, int n)
|
||||
{
|
||||
if (s->img_buffer+n <= s->img_buffer_end)
|
||||
{
|
||||
@ -85,13 +85,13 @@ static int rtga__getn(rtga__context *s, uint8_t *buffer, int n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtga__get16le(rtga__context *s)
|
||||
static int rtga_get16le(rtga_context *s)
|
||||
{
|
||||
int z = rtga__get8(s);
|
||||
return z + (rtga__get8(s) << 8);
|
||||
int z = rtga_get8(s);
|
||||
return z + (rtga_get8(s) << 8);
|
||||
}
|
||||
|
||||
static unsigned char *rtga__convert_format(
|
||||
static unsigned char *rtga_convert_format(
|
||||
unsigned char *data,
|
||||
int img_n,
|
||||
int req_comp,
|
||||
@ -195,24 +195,24 @@ static unsigned char *rtga__convert_format(
|
||||
return good;
|
||||
}
|
||||
|
||||
static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
static uint8_t *rtga_tga_load(rtga_context *s,
|
||||
unsigned *x, unsigned *y, int *comp, int req_comp)
|
||||
{
|
||||
/* Read in the TGA header stuff */
|
||||
int tga_offset = rtga__get8(s);
|
||||
int tga_indexed = rtga__get8(s);
|
||||
int tga_image_type = rtga__get8(s);
|
||||
int tga_offset = rtga_get8(s);
|
||||
int tga_indexed = rtga_get8(s);
|
||||
int tga_image_type = rtga_get8(s);
|
||||
int tga_is_RLE = 0;
|
||||
int tga_palette_start = rtga__get16le(s);
|
||||
int tga_palette_len = rtga__get16le(s);
|
||||
int tga_palette_bits = rtga__get8(s);
|
||||
int tga_x_origin = rtga__get16le(s);
|
||||
int tga_y_origin = rtga__get16le(s);
|
||||
int tga_width = rtga__get16le(s);
|
||||
int tga_height = rtga__get16le(s);
|
||||
int tga_bits_per_pixel = rtga__get8(s);
|
||||
int tga_palette_start = rtga_get16le(s);
|
||||
int tga_palette_len = rtga_get16le(s);
|
||||
int tga_palette_bits = rtga_get8(s);
|
||||
int tga_x_origin = rtga_get16le(s);
|
||||
int tga_y_origin = rtga_get16le(s);
|
||||
int tga_width = rtga_get16le(s);
|
||||
int tga_height = rtga_get16le(s);
|
||||
int tga_bits_per_pixel = rtga_get8(s);
|
||||
int tga_comp = tga_bits_per_pixel / 8;
|
||||
int tga_inverted = rtga__get8(s);
|
||||
int tga_inverted = rtga_get8(s);
|
||||
|
||||
/* image data */
|
||||
unsigned char *tga_data = NULL;
|
||||
@ -257,7 +257,7 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
return NULL;
|
||||
|
||||
/* skip to the data's starting position (offset usually = 0) */
|
||||
rtga__skip(s, tga_offset );
|
||||
rtga_skip(s, tga_offset );
|
||||
|
||||
if (!tga_indexed && !tga_is_RLE)
|
||||
{
|
||||
@ -266,7 +266,7 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
{
|
||||
int _y = tga_inverted ? (tga_height -i - 1) : i;
|
||||
uint8_t *tga_row = tga_data + _y * tga_width * tga_comp;
|
||||
rtga__getn(s, tga_row, tga_width * tga_comp);
|
||||
rtga_getn(s, tga_row, tga_width * tga_comp);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -282,7 +282,7 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
if (tga_indexed)
|
||||
{
|
||||
/* any data to skip? (offset usually = 0) */
|
||||
rtga__skip(s, tga_palette_start );
|
||||
rtga_skip(s, tga_palette_start );
|
||||
/* load the palette */
|
||||
tga_palette = (unsigned char*)malloc(tga_palette_len * tga_palette_bits / 8);
|
||||
|
||||
@ -292,7 +292,7 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!rtga__getn(s, tga_palette, tga_palette_len * tga_palette_bits / 8 ))
|
||||
if (!rtga_getn(s, tga_palette, tga_palette_len * tga_palette_bits / 8 ))
|
||||
{
|
||||
free(tga_data);
|
||||
free(tga_palette);
|
||||
@ -303,13 +303,13 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
/* load the data */
|
||||
for (i=0; i < tga_width * tga_height; ++i)
|
||||
{
|
||||
/* if I'm in RLE mode, do I need to get a RLE rtga__pngchunk? */
|
||||
/* if I'm in RLE mode, do I need to get a RLE rtga_png chunk? */
|
||||
if (tga_is_RLE)
|
||||
{
|
||||
if (RLE_count == 0)
|
||||
{
|
||||
/* yep, get the next byte as a RLE command */
|
||||
int RLE_cmd = rtga__get8(s);
|
||||
int RLE_cmd = rtga_get8(s);
|
||||
RLE_count = 1 + (RLE_cmd & 127);
|
||||
RLE_repeating = RLE_cmd >> 7;
|
||||
read_next_pixel = 1;
|
||||
@ -327,7 +327,7 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
if (tga_indexed)
|
||||
{
|
||||
/* read in 1 byte, then perform the lookup */
|
||||
int pal_idx = rtga__get8(s);
|
||||
int pal_idx = rtga_get8(s);
|
||||
if (pal_idx >= tga_palette_len) /* invalid index */
|
||||
pal_idx = 0;
|
||||
pal_idx *= tga_bits_per_pixel / 8;
|
||||
@ -338,7 +338,7 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
{
|
||||
/* read in the data raw */
|
||||
for (j = 0; j*8 < tga_bits_per_pixel; ++j)
|
||||
raw_data[j] = rtga__get8(s);
|
||||
raw_data[j] = rtga_get8(s);
|
||||
}
|
||||
|
||||
/* clear the reading flag for the next pixel */
|
||||
@ -397,7 +397,7 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
&& (req_comp >= 1 && req_comp <= 4)
|
||||
&& (req_comp != tga_comp))
|
||||
{
|
||||
tga_data = rtga__convert_format(tga_data, tga_comp, req_comp, tga_width, tga_height);
|
||||
tga_data = rtga_convert_format(tga_data, tga_comp, req_comp, tga_width, tga_height);
|
||||
}
|
||||
|
||||
return tga_data;
|
||||
@ -406,13 +406,13 @@ static uint8_t *rtga__tga_load(rtga__context *s,
|
||||
static uint8_t *rtga_load_from_memory(uint8_t const *buffer, int len,
|
||||
unsigned *x, unsigned *y, int *comp, int req_comp)
|
||||
{
|
||||
rtga__context s;
|
||||
rtga_context s;
|
||||
|
||||
s.img_buffer = (uint8_t *)buffer;
|
||||
s.img_buffer_original = (uint8_t *) buffer;
|
||||
s.img_buffer_end = (uint8_t *) buffer+len;
|
||||
|
||||
return rtga__tga_load(&s,x,y,comp,req_comp);
|
||||
return rtga_tga_load(&s,x,y,comp,req_comp);
|
||||
}
|
||||
|
||||
int rtga_process_image(rtga_t *rtga, void **buf_data,
|
||||
|
Loading…
x
Reference in New Issue
Block a user