mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 15:45:19 +00:00
(rbmp_encode.c) Cleanups
This commit is contained in:
parent
2559139154
commit
7a282eab23
@ -28,10 +28,10 @@
|
|||||||
|
|
||||||
static bool write_header_bmp(RFILE *file, unsigned width, unsigned height, bool is32bpp)
|
static bool write_header_bmp(RFILE *file, unsigned width, unsigned height, bool is32bpp)
|
||||||
{
|
{
|
||||||
|
uint8_t header[54];
|
||||||
unsigned line_size = (width * (is32bpp?4:3) + 3) & ~3;
|
unsigned line_size = (width * (is32bpp?4:3) + 3) & ~3;
|
||||||
unsigned size = line_size * height + 54;
|
unsigned size = line_size * height + 54;
|
||||||
unsigned size_array = line_size * height;
|
unsigned size_array = line_size * height;
|
||||||
uint8_t header[54];
|
|
||||||
|
|
||||||
/* Generic BMP stuff. */
|
/* Generic BMP stuff. */
|
||||||
|
|
||||||
@ -140,9 +140,9 @@ static void dump_line_32_to_24(uint8_t *line, const uint32_t *src, unsigned widt
|
|||||||
static void dump_content(RFILE *file, const void *frame,
|
static void dump_content(RFILE *file, const void *frame,
|
||||||
int width, int height, int pitch, enum rbmp_source_type type)
|
int width, int height, int pitch, enum rbmp_source_type type)
|
||||||
{
|
{
|
||||||
uint8_t *line;
|
|
||||||
size_t line_size;
|
|
||||||
int j;
|
int j;
|
||||||
|
size_t line_size;
|
||||||
|
uint8_t *line = NULL;
|
||||||
int bytes_per_pixel = (type==RBMP_SOURCE_TYPE_ARGB8888?4:3);
|
int bytes_per_pixel = (type==RBMP_SOURCE_TYPE_ARGB8888?4:3);
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
@ -154,58 +154,68 @@ static void dump_content(RFILE *file, const void *frame,
|
|||||||
u.u8 = (const uint8_t*)frame;
|
u.u8 = (const uint8_t*)frame;
|
||||||
line_size = (width * bytes_per_pixel + 3) & ~3;
|
line_size = (width * bytes_per_pixel + 3) & ~3;
|
||||||
|
|
||||||
if (type == RBMP_SOURCE_TYPE_BGR24)
|
switch (type)
|
||||||
{
|
{
|
||||||
/* BGR24 byte order input matches output. Can directly copy, but... need to make sure we pad it. */
|
case RBMP_SOURCE_TYPE_BGR24:
|
||||||
uint32_t zeros = 0;
|
{
|
||||||
int pad = line_size-pitch;
|
/* BGR24 byte order input matches output. Can directly copy, but... need to make sure we pad it. */
|
||||||
for (j = 0; j < height; j++, u.u8 += pitch)
|
uint32_t zeros = 0;
|
||||||
{
|
int pad = line_size-pitch;
|
||||||
filestream_write(file, u.u8, pitch);
|
for (j = 0; j < height; j++, u.u8 += pitch)
|
||||||
if(pad != 0)
|
{
|
||||||
filestream_write(file, &zeros, pad);
|
filestream_write(file, u.u8, pitch);
|
||||||
}
|
if(pad != 0)
|
||||||
return;
|
filestream_write(file, &zeros, pad);
|
||||||
}
|
}
|
||||||
else if(type == RBMP_SOURCE_TYPE_ARGB8888)
|
return;
|
||||||
{
|
}
|
||||||
/* ARGB8888 byte order input matches output. Can directly copy. */
|
break;
|
||||||
for (j = 0; j < height; j++, u.u8 += pitch)
|
case RBMP_SOURCE_TYPE_ARGB8888:
|
||||||
filestream_write(file, u.u8, line_size);
|
/* ARGB8888 byte order input matches output. Can directly copy. */
|
||||||
return;
|
for (j = 0; j < height; j++, u.u8 += pitch)
|
||||||
|
filestream_write(file, u.u8, line_size);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate line buffer, and initialize the final four bytes to zero, for deterministic padding */
|
/* allocate line buffer, and initialize the final four bytes to zero, for deterministic padding */
|
||||||
line = (uint8_t*)malloc(line_size);
|
line = (uint8_t*)malloc(line_size);
|
||||||
if (!line) return;
|
if (!line)
|
||||||
|
return;
|
||||||
*(uint32_t*)(line + line_size - 4) = 0;
|
*(uint32_t*)(line + line_size - 4) = 0;
|
||||||
|
|
||||||
if (type == RBMP_SOURCE_TYPE_XRGB888)
|
switch (type)
|
||||||
{
|
{
|
||||||
for (j = 0; j < height; j++, u.u8 += pitch)
|
case RBMP_SOURCE_TYPE_XRGB888:
|
||||||
{
|
for (j = 0; j < height; j++, u.u8 += pitch)
|
||||||
dump_line_32_to_24(line, u.u32, width);
|
{
|
||||||
filestream_write(file, line, line_size);
|
dump_line_32_to_24(line, u.u32, width);
|
||||||
}
|
filestream_write(file, line, line_size);
|
||||||
}
|
}
|
||||||
else /* type == RBMP_SOURCE_TYPE_RGB565 */
|
break;
|
||||||
{
|
case RBMP_SOURCE_TYPE_RGB565:
|
||||||
for (j = 0; j < height; j++, u.u8 += pitch)
|
for (j = 0; j < height; j++, u.u8 += pitch)
|
||||||
{
|
{
|
||||||
dump_line_565_to_24(line, u.u16, width);
|
dump_line_565_to_24(line, u.u16, width);
|
||||||
filestream_write(file, line, line_size);
|
filestream_write(file, line, line_size);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free allocated line buffer */
|
/* Free allocated line buffer */
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rbmp_save_image(const char *filename, const void *frame,
|
bool rbmp_save_image(
|
||||||
|
const char *filename,
|
||||||
|
const void *frame,
|
||||||
unsigned width, unsigned height,
|
unsigned width, unsigned height,
|
||||||
unsigned pitch, enum rbmp_source_type type)
|
unsigned pitch, enum rbmp_source_type type)
|
||||||
{
|
{
|
||||||
bool ret;
|
bool ret = false;
|
||||||
RFILE *file = filestream_open(filename, RFILE_MODE_WRITE, -1);
|
RFILE *file = filestream_open(filename, RFILE_MODE_WRITE, -1);
|
||||||
if (!file)
|
if (!file)
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user