mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +00:00
(gfx/image) Cleanups
This commit is contained in:
parent
f861a10c44
commit
a1959a83c8
@ -182,14 +182,13 @@ error:
|
|||||||
|
|
||||||
static bool ps3_load_png(const char *path, struct texture_image *out_img)
|
static bool ps3_load_png(const char *path, struct texture_image *out_img)
|
||||||
{
|
{
|
||||||
size_t img_size;
|
#ifdef __PSL1GHT__
|
||||||
#ifndef __PSL1GHT__
|
uint64_t output_bytes_per_line;
|
||||||
CtrlMallocArg MallocArg;
|
#else
|
||||||
CtrlFreeArg FreeArg;
|
CtrlMallocArg MallocArg;
|
||||||
|
CtrlFreeArg FreeArg;
|
||||||
CellPngDecDataCtrlParam dCtrlParam;
|
CellPngDecDataCtrlParam dCtrlParam;
|
||||||
#endif
|
#endif
|
||||||
CellPngDecMainHandle mHandle = PTR_NULL;
|
|
||||||
CellPngDecSubHandle sHandle = PTR_NULL;
|
|
||||||
CellPngDecThreadInParam InParam;
|
CellPngDecThreadInParam InParam;
|
||||||
CellPngDecThreadOutParam OutParam;
|
CellPngDecThreadOutParam OutParam;
|
||||||
CellPngDecSrc src;
|
CellPngDecSrc src;
|
||||||
@ -198,15 +197,19 @@ static bool ps3_load_png(const char *path, struct texture_image *out_img)
|
|||||||
CellPngDecInParam inParam;
|
CellPngDecInParam inParam;
|
||||||
CellPngDecOutParam outParam;
|
CellPngDecOutParam outParam;
|
||||||
CellPngDecDataOutInfo dOutInfo;
|
CellPngDecDataOutInfo dOutInfo;
|
||||||
|
size_t img_size;
|
||||||
|
int ret_png, ret = -1;
|
||||||
|
CellPngDecMainHandle mHandle = PTR_NULL;
|
||||||
|
CellPngDecSubHandle sHandle = PTR_NULL;
|
||||||
|
|
||||||
InParam.spu_enable = CELL_PNGDEC_SPU_THREAD_ENABLE;
|
InParam.spu_enable = CELL_PNGDEC_SPU_THREAD_ENABLE;
|
||||||
InParam.ppu_prio = 512;
|
InParam.ppu_prio = 512;
|
||||||
InParam.spu_prio = 200;
|
InParam.spu_prio = 200;
|
||||||
#ifdef __PSL1GHT__
|
#ifdef __PSL1GHT__
|
||||||
InParam.malloc_func = __get_addr32(__get_opd32(img_malloc));
|
InParam.malloc_func = __get_addr32(__get_opd32(img_malloc));
|
||||||
InParam.free_func = __get_addr32(__get_opd32(img_free));
|
InParam.free_func = __get_addr32(__get_opd32(img_free));
|
||||||
InParam.malloc_arg = 0;
|
InParam.malloc_arg = 0;
|
||||||
InParam.free_arg = 0;
|
InParam.free_arg = 0;
|
||||||
#else
|
#else
|
||||||
MallocArg.mallocCallCounts = 0;
|
MallocArg.mallocCallCounts = 0;
|
||||||
FreeArg.freeCallCounts = 0;
|
FreeArg.freeCallCounts = 0;
|
||||||
@ -216,13 +219,13 @@ static bool ps3_load_png(const char *path, struct texture_image *out_img)
|
|||||||
InParam.free_arg = &FreeArg;
|
InParam.free_arg = &FreeArg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int ret_png, ret = -1;
|
|
||||||
ret_png = cellPngDecCreate(&mHandle, &InParam, &OutParam);
|
ret_png = cellPngDecCreate(&mHandle, &InParam, &OutParam);
|
||||||
|
|
||||||
if (ret_png != CELL_OK)
|
if (ret_png != CELL_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
memset(&src, 0, sizeof(CellPngDecSrc));
|
memset(&src, 0, sizeof(CellPngDecSrc));
|
||||||
|
|
||||||
src.stream_select = CELL_PNGDEC_FILE;
|
src.stream_select = CELL_PNGDEC_FILE;
|
||||||
#ifdef __PSL1GHT__
|
#ifdef __PSL1GHT__
|
||||||
src.file_name = __get_addr32(path);
|
src.file_name = __get_addr32(path);
|
||||||
@ -233,8 +236,7 @@ static bool ps3_load_png(const char *path, struct texture_image *out_img)
|
|||||||
src.file_size = 0;
|
src.file_size = 0;
|
||||||
src.stream_ptr = 0;
|
src.stream_ptr = 0;
|
||||||
src.stream_size = 0;
|
src.stream_size = 0;
|
||||||
|
src.spu_enable = CELL_PNGDEC_SPU_THREAD_ENABLE;
|
||||||
src.spu_enable = CELL_PNGDEC_SPU_THREAD_ENABLE;
|
|
||||||
|
|
||||||
ret = cellPngDecOpen(mHandle, &sHandle, &src, &opnInfo);
|
ret = cellPngDecOpen(mHandle, &sHandle, &src, &opnInfo);
|
||||||
|
|
||||||
@ -252,6 +254,7 @@ static bool ps3_load_png(const char *path, struct texture_image *out_img)
|
|||||||
inParam.bit_depth = 8;
|
inParam.bit_depth = 8;
|
||||||
inParam.pack_flag = CELL_PNGDEC_1BYTE_PER_1PIXEL;
|
inParam.pack_flag = CELL_PNGDEC_1BYTE_PER_1PIXEL;
|
||||||
inParam.alpha_select = CELL_PNGDEC_STREAM_ALPHA;
|
inParam.alpha_select = CELL_PNGDEC_STREAM_ALPHA;
|
||||||
|
|
||||||
ret = cellPngDecSetParameter(mHandle, sHandle, &inParam, &outParam);
|
ret = cellPngDecSetParameter(mHandle, sHandle, &inParam, &outParam);
|
||||||
|
|
||||||
if (ret != CELL_OK)
|
if (ret != CELL_OK)
|
||||||
@ -263,7 +266,7 @@ static bool ps3_load_png(const char *path, struct texture_image *out_img)
|
|||||||
memset(out_img->pixels, 0, img_size);
|
memset(out_img->pixels, 0, img_size);
|
||||||
|
|
||||||
#ifdef __PSL1GHT__
|
#ifdef __PSL1GHT__
|
||||||
uint64_t output_bytes_per_line = outParam.output_width * 4;
|
output_bytes_per_line = outParam.output_width * 4;
|
||||||
ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)
|
ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)
|
||||||
out_img->pixels, &output_bytes_per_line, &dOutInfo);
|
out_img->pixels, &output_bytes_per_line, &dOutInfo);
|
||||||
#else
|
#else
|
||||||
@ -305,11 +308,9 @@ bool texture_image_load(struct texture_image *out_img, const char *path)
|
|||||||
if (!ps3_load_png(path, out_img))
|
if (!ps3_load_png(path, out_img))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (!ps3_load_jpeg(path, out_img))
|
||||||
if (!ps3_load_jpeg(path, out_img))
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -108,49 +108,40 @@ static bool rpng_image_load_tga_shift(const char *path,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_ZLIB
|
||||||
static bool rpng_image_load_argb_shift(const char *path,
|
static bool rpng_image_load_argb_shift(const char *path,
|
||||||
struct texture_image *out_img,
|
struct texture_image *out_img,
|
||||||
unsigned a_shift, unsigned r_shift,
|
unsigned a_shift, unsigned r_shift,
|
||||||
unsigned g_shift, unsigned b_shift)
|
unsigned g_shift, unsigned b_shift)
|
||||||
{
|
{
|
||||||
if (strstr(path, ".tga"))
|
bool ret = rpng_load_image_argb(path,
|
||||||
return rpng_image_load_tga_shift(path, out_img,
|
&out_img->pixels, &out_img->width, &out_img->height);
|
||||||
a_shift, r_shift, g_shift, b_shift);
|
|
||||||
|
|
||||||
#ifdef HAVE_ZLIB
|
if (!ret)
|
||||||
if (strstr(path, ".png"))
|
return false;
|
||||||
|
|
||||||
|
/* This is quite uncommon. */
|
||||||
|
if (a_shift != 24 || r_shift != 16 || g_shift != 8 || b_shift != 0)
|
||||||
{
|
{
|
||||||
bool ret = rpng_load_image_argb(path,
|
uint32_t i;
|
||||||
&out_img->pixels, &out_img->width, &out_img->height);
|
uint32_t num_pixels = out_img->width * out_img->height;
|
||||||
|
uint32_t *pixels = (uint32_t*)out_img->pixels;
|
||||||
|
|
||||||
if (!ret)
|
for (i = 0; i < num_pixels; i++)
|
||||||
return false;
|
|
||||||
|
|
||||||
/* This is quite uncommon. */
|
|
||||||
if (a_shift != 24 || r_shift != 16 || g_shift != 8 || b_shift != 0)
|
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t col = pixels[i];
|
||||||
uint32_t num_pixels = out_img->width * out_img->height;
|
uint8_t a = (uint8_t)(col >> 24);
|
||||||
uint32_t *pixels = (uint32_t*)out_img->pixels;
|
uint8_t r = (uint8_t)(col >> 16);
|
||||||
|
uint8_t g = (uint8_t)(col >> 8);
|
||||||
for (i = 0; i < num_pixels; i++)
|
uint8_t b = (uint8_t)(col >> 0);
|
||||||
{
|
pixels[i] = (a << a_shift) |
|
||||||
uint32_t col = pixels[i];
|
(r << r_shift) | (g << g_shift) | (b << b_shift);
|
||||||
uint8_t a = (uint8_t)(col >> 24);
|
|
||||||
uint8_t r = (uint8_t)(col >> 16);
|
|
||||||
uint8_t g = (uint8_t)(col >> 8);
|
|
||||||
uint8_t b = (uint8_t)(col >> 0);
|
|
||||||
pixels[i] = (a << a_shift) |
|
|
||||||
(r << r_shift) | (g << g_shift) | (b << b_shift);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef GEKKO
|
#ifdef GEKKO
|
||||||
|
|
||||||
@ -226,9 +217,21 @@ void texture_image_free(struct texture_image *img)
|
|||||||
bool texture_image_load(struct texture_image *out_img, const char *path)
|
bool texture_image_load(struct texture_image *out_img, const char *path)
|
||||||
{
|
{
|
||||||
/* This interface "leak" is very ugly. FIXME: Fix this properly ... */
|
/* This interface "leak" is very ugly. FIXME: Fix this properly ... */
|
||||||
bool use_rgba = driver.gfx_use_rgba;
|
bool ret = false;
|
||||||
bool ret = rpng_image_load_argb_shift(path, out_img, 24,
|
bool use_rgba = driver.gfx_use_rgba;
|
||||||
use_rgba ? 0 : 16, 8, use_rgba ? 16 : 0);
|
unsigned a_shift = 24;
|
||||||
|
unsigned r_shift = use_rgba ? 0 : 16;
|
||||||
|
unsigned g_shift = 8;
|
||||||
|
unsigned b_shift = use_rgba ? 16 : 0;
|
||||||
|
|
||||||
|
if (strstr(path, ".tga"))
|
||||||
|
ret = rpng_image_load_tga_shift(path, out_img,
|
||||||
|
a_shift, r_shift, g_shift, b_shift);
|
||||||
|
#ifdef HAVE_ZLIB
|
||||||
|
else if (strstr(path, ".png"))
|
||||||
|
ret = rpng_image_load_argb_shift(path, out_img,
|
||||||
|
a_shift, r_shift, g_shift, b_shift);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef GEKKO
|
#ifdef GEKKO
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
|
|
||||||
bool texture_image_load(struct texture_image *out_img, const char *path)
|
bool texture_image_load(struct texture_image *out_img, const char *path)
|
||||||
{
|
{
|
||||||
d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
|
|
||||||
|
|
||||||
D3DXIMAGE_INFO m_imageInfo;
|
D3DXIMAGE_INFO m_imageInfo;
|
||||||
|
d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
|
||||||
|
|
||||||
out_img->vertex_buf = NULL;
|
out_img->vertex_buf = NULL;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user