libretro-common rbmp - add support for y-flipping

This commit is contained in:
zeromus 2017-07-23 20:36:35 -05:00
parent 6ced9e3942
commit 918f45e7a4
2 changed files with 71 additions and 21 deletions

View File

@ -143,7 +143,9 @@ static void dump_content(RFILE *file, const void *frame,
int j;
size_t line_size;
uint8_t *line = NULL;
int bytes_per_pixel = (type==RBMP_SOURCE_TYPE_ARGB8888?4:3);
enum rbmp_source_type format = type & RBMP_SOURCE_TYPE_FORMATMASK;
bool yflip = (type & RBMP_SOURCE_TYPE_YFLIPPED);
int bytes_per_pixel = (format==RBMP_SOURCE_TYPE_ARGB8888?4:3);
union
{
const uint8_t *u8;
@ -154,25 +156,47 @@ static void dump_content(RFILE *file, const void *frame,
u.u8 = (const uint8_t*)frame;
line_size = (width * bytes_per_pixel + 3) & ~3;
switch (type)
switch (format)
{
case RBMP_SOURCE_TYPE_BGR24:
{
/* BGR24 byte order input matches output. Can directly copy, but... need to make sure we pad it. */
uint32_t zeros = 0;
int pad = (int)(line_size-pitch);
for (j = 0; j < height; j++, u.u8 += pitch)
if(yflip)
{
filestream_write(file, u.u8, pitch);
if(pad != 0)
filestream_write(file, &zeros, pad);
u.u8 += pitch * (height - 1);
for (j = 0; j < height; j++, u.u8 -= pitch)
{
filestream_write(file, u.u8, pitch);
if(pad != 0)
filestream_write(file, &zeros, pad);
}
}
else
{
for(j = 0; j < height; j++, u.u8 += pitch)
{
filestream_write(file, u.u8, pitch);
if(pad != 0)
filestream_write(file, &zeros, pad);
}
}
}
break;
case RBMP_SOURCE_TYPE_ARGB8888:
/* ARGB8888 byte order input matches output. Can directly copy. */
for (j = 0; j < height; j++, u.u8 += pitch)
filestream_write(file, u.u8, line_size);
if(yflip)
{
u.u8 += pitch * (height - 1);
for (j = 0; j < height; j++, u.u8 -= pitch)
filestream_write(file, u.u8, line_size);
}
else
{
for(j = 0; j < height; j++, u.u8 += pitch)
filestream_write(file, u.u8, line_size);
}
return;
default:
break;
@ -184,20 +208,44 @@ static void dump_content(RFILE *file, const void *frame,
return;
*(uint32_t*)(line + line_size - 4) = 0;
switch (type)
switch (format)
{
case RBMP_SOURCE_TYPE_XRGB888:
for (j = 0; j < height; j++, u.u8 += pitch)
if(yflip)
{
dump_line_32_to_24(line, u.u32, width);
filestream_write(file, line, line_size);
u.u8 += pitch * (height - 1);
for (j = 0; j < height; j++, u.u8 -= pitch)
{
dump_line_32_to_24(line, u.u32, width);
filestream_write(file, line, line_size);
}
}
else
{
for(j = 0; j < height; j++, u.u8 += pitch)
{
dump_line_32_to_24(line, u.u32, width);
filestream_write(file, line, line_size);
}
}
break;
case RBMP_SOURCE_TYPE_RGB565:
for (j = 0; j < height; j++, u.u8 += pitch)
if(yflip)
{
dump_line_565_to_24(line, u.u16, width);
filestream_write(file, line, line_size);
u.u8 += pitch * (height - 1);
for (j = 0; j < height; j++, u.u8 -= pitch)
{
dump_line_565_to_24(line, u.u16, width);
filestream_write(file, line, line_size);
}
}
else
{
for(j = 0; j < height; j++, u.u8 += pitch)
{
dump_line_565_to_24(line, u.u16, width);
filestream_write(file, line, line_size);
}
}
break;
default:
@ -219,7 +267,7 @@ bool rbmp_save_image(
if (!file)
return false;
ret = write_header_bmp(file, width, height, type==RBMP_SOURCE_TYPE_ARGB8888);
ret = write_header_bmp(file, width, height, (type&RBMP_SOURCE_TYPE_FORMATMASK)==RBMP_SOURCE_TYPE_ARGB8888);
if (ret)
dump_content(file, frame, width, height, pitch, type);

View File

@ -31,11 +31,13 @@ RETRO_BEGIN_DECLS
enum rbmp_source_type
{
RBMP_SOURCE_TYPE_DONT_CARE,
RBMP_SOURCE_TYPE_BGR24,
RBMP_SOURCE_TYPE_XRGB888,
RBMP_SOURCE_TYPE_RGB565,
RBMP_SOURCE_TYPE_ARGB8888
RBMP_SOURCE_TYPE_DONT_CARE = 0,
RBMP_SOURCE_TYPE_BGR24 = 1,
RBMP_SOURCE_TYPE_XRGB888 = 2,
RBMP_SOURCE_TYPE_RGB565 = 3,
RBMP_SOURCE_TYPE_ARGB8888 = 4,
RBMP_SOURCE_TYPE_FORMATMASK = 7,
RBMP_SOURCE_TYPE_YFLIPPED = 16
};
typedef struct rbmp rbmp_t;