Combine all image files into one

This commit is contained in:
twinaphex 2015-02-22 01:28:54 +01:00
parent 292298b367
commit fddddc3965
5 changed files with 225 additions and 287 deletions

View File

@ -166,10 +166,7 @@ OBJ += frontend/frontend.o \
record/record_driver.o \
performance.o
OBJ += gfx/image/image_rpng.o
#OBJ += gfx/image/image_mpng.o
#OBJ += libretro-common/formats/mpng/mpng_decode.o
OBJ += gfx/image/image.o
# LibretroDB

View File

@ -19,6 +19,9 @@
#endif
#include "image.h"
#ifdef _XBOX1
#include "../d3d/d3d_wrapper.h"
#endif
#include "../../file_ops.h"
#include <stdlib.h>
@ -27,6 +30,19 @@
#include "../../general.h"
#include <formats/rpng.h>
#if defined(__CELLOS_LV2__) || defined(__PSLIGHT__)
#include "../../ps3/sdk_defines.h"
#ifdef __PSL1GHT__
#include <ppu-asm.h>
#include <ppu-types.h>
#include <pngdec/pngdec.h>
#else
#include <cell/codec.h>
#endif
#endif
//#define HAVE_NONBLOCKING_TEST
#ifdef HAVE_NONBLOCKING_TEST
@ -259,10 +275,215 @@ void texture_image_free(struct texture_image *img)
if (!img)
return;
free(img->pixels);
#ifdef _XBOX1
d3d_vertex_buffer_free(img->vertex_buf);
d3d_texture_free(img->pixels);
#else
if (img->pixels)
free(img->pixels);
#endif
memset(img, 0, sizeof(*img));
}
#ifdef _XBOX1
bool texture_image_load(struct texture_image *out_img, const char *path)
{
D3DXIMAGE_INFO m_imageInfo;
d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
out_img->vertex_buf = NULL;
out_img->pixels = d3d_texture_new(d3d->dev, path,
D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, 0, &m_imageInfo, NULL);
if (!out_img->pixels)
return false;
/* create a vertex buffer for the quad that will display the texture */
out_img->vertex_buf = (LPDIRECT3DVERTEXBUFFER)d3d_vertex_buffer_new(
d3d->dev, 4 * sizeof(Vertex), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, NULL);
if (!out_img->vertex_buf)
{
d3d_texture_free(out_img->pixels);
return false;
}
out_img->width = m_imageInfo.Width;
out_img->height = m_imageInfo.Height;
return true;
}
#elif defined(__CELLOS_LV2__)
typedef struct CtrlMallocArg
{
uint32_t mallocCallCounts;
} CtrlMallocArg;
typedef struct CtrlFreeArg
{
uint32_t freeCallCounts;
} CtrlFreeArg;
void *img_malloc(uint32_t size, void *a)
{
#ifndef __PSL1GHT__
CtrlMallocArg *arg;
arg = (CtrlMallocArg *) a;
arg->mallocCallCounts++;
#endif
return malloc(size);
}
static int img_free(void *ptr, void *a)
{
#ifndef __PSL1GHT__
CtrlFreeArg *arg;
arg = (CtrlFreeArg *) a;
arg->freeCallCounts++;
#endif
free(ptr);
return 0;
}
static bool ps3_load_png(const char *path, struct texture_image *out_img)
{
#ifdef __PSL1GHT__
uint64_t output_bytes_per_line;
#else
CtrlMallocArg MallocArg;
CtrlFreeArg FreeArg;
CellPngDecDataCtrlParam dCtrlParam;
#endif
CellPngDecThreadInParam InParam;
CellPngDecThreadOutParam OutParam;
CellPngDecSrc src;
CellPngDecOpnInfo opnInfo;
CellPngDecInfo info;
CellPngDecInParam inParam;
CellPngDecOutParam outParam;
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.ppu_prio = 512;
InParam.spu_prio = 200;
#ifdef __PSL1GHT__
InParam.malloc_func = __get_addr32(__get_opd32(img_malloc));
InParam.free_func = __get_addr32(__get_opd32(img_free));
InParam.malloc_arg = 0;
InParam.free_arg = 0;
#else
MallocArg.mallocCallCounts = 0;
FreeArg.freeCallCounts = 0;
InParam.malloc_func = img_malloc;
InParam.malloc_arg = &MallocArg;
InParam.free_func = img_free;
InParam.free_arg = &FreeArg;
#endif
ret_png = cellPngDecCreate(&mHandle, &InParam, &OutParam);
if (ret_png != CELL_OK)
goto error;
memset(&src, 0, sizeof(CellPngDecSrc));
src.stream_select = CELL_PNGDEC_FILE;
#ifdef __PSL1GHT__
src.file_name = __get_addr32(path);
#else
src.file_name = path;
#endif
src.file_offset = 0;
src.file_size = 0;
src.stream_ptr = 0;
src.stream_size = 0;
src.spu_enable = CELL_PNGDEC_SPU_THREAD_ENABLE;
ret = cellPngDecOpen(mHandle, &sHandle, &src, &opnInfo);
if (ret != CELL_OK)
goto error;
ret = cellPngDecReadHeader(mHandle, sHandle, &info);
if (ret != CELL_OK)
goto error;
inParam.cmd_ptr = PTR_NULL;
inParam.output_mode = CELL_PNGDEC_TOP_TO_BOTTOM;
inParam.color_space = CELL_PNGDEC_ARGB;
inParam.bit_depth = 8;
inParam.pack_flag = CELL_PNGDEC_1BYTE_PER_1PIXEL;
inParam.alpha_select = CELL_PNGDEC_STREAM_ALPHA;
ret = cellPngDecSetParameter(mHandle, sHandle, &inParam, &outParam);
if (ret != CELL_OK)
goto error;
img_size = outParam.output_width *
outParam.output_height * sizeof(uint32_t);
out_img->pixels = (uint32_t*)malloc(img_size);
if (!out_img->pixels)
goto error;
memset(out_img->pixels, 0, img_size);
#ifdef __PSL1GHT__
output_bytes_per_line = outParam.output_width * 4;
ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)
out_img->pixels, &output_bytes_per_line, &dOutInfo);
#else
dCtrlParam.output_bytes_per_line = outParam.output_width * 4;
ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)
out_img->pixels, &dCtrlParam, &dOutInfo);
#endif
if (ret != CELL_OK || dOutInfo.status != CELL_PNGDEC_DEC_STATUS_FINISH)
goto error;
out_img->width = outParam.output_width;
out_img->height = outParam.output_height;
cellPngDecClose(mHandle, sHandle);
cellPngDecDestroy(mHandle);
return true;
error:
if (out_img->pixels)
free(out_img->pixels);
out_img->pixels = 0;
if (mHandle && sHandle)
cellPngDecClose(mHandle, sHandle);
if (mHandle)
cellPngDecDestroy(mHandle);
return false;
}
bool texture_image_load(struct texture_image *out_img, const char *path)
{
if (!out_img)
return false;
if (!ps3_load_png(path, out_img))
return false;
return true;
}
#else
bool texture_image_load(struct texture_image *out_img, const char *path)
{
/* This interface "leak" is very ugly. FIXME: Fix this properly ... */
@ -315,3 +536,4 @@ bool texture_image_load(struct texture_image *out_img, const char *path)
return ret;
}
#endif

View File

@ -1,215 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include "image.h"
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "../../general.h"
#include "../../ps3/sdk_defines.h"
#ifdef __PSL1GHT__
#include <ppu-asm.h>
#include <ppu-types.h>
#include <pngdec/pngdec.h>
#else
#include <cell/codec.h>
#endif
typedef struct CtrlMallocArg
{
uint32_t mallocCallCounts;
} CtrlMallocArg;
typedef struct CtrlFreeArg
{
uint32_t freeCallCounts;
} CtrlFreeArg;
void *img_malloc(uint32_t size, void *a)
{
#ifndef __PSL1GHT__
CtrlMallocArg *arg;
arg = (CtrlMallocArg *) a;
arg->mallocCallCounts++;
#endif
return malloc(size);
}
static int img_free(void *ptr, void *a)
{
#ifndef __PSL1GHT__
CtrlFreeArg *arg;
arg = (CtrlFreeArg *) a;
arg->freeCallCounts++;
#endif
free(ptr);
return 0;
}
static bool ps3_load_png(const char *path, struct texture_image *out_img)
{
#ifdef __PSL1GHT__
uint64_t output_bytes_per_line;
#else
CtrlMallocArg MallocArg;
CtrlFreeArg FreeArg;
CellPngDecDataCtrlParam dCtrlParam;
#endif
CellPngDecThreadInParam InParam;
CellPngDecThreadOutParam OutParam;
CellPngDecSrc src;
CellPngDecOpnInfo opnInfo;
CellPngDecInfo info;
CellPngDecInParam inParam;
CellPngDecOutParam outParam;
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.ppu_prio = 512;
InParam.spu_prio = 200;
#ifdef __PSL1GHT__
InParam.malloc_func = __get_addr32(__get_opd32(img_malloc));
InParam.free_func = __get_addr32(__get_opd32(img_free));
InParam.malloc_arg = 0;
InParam.free_arg = 0;
#else
MallocArg.mallocCallCounts = 0;
FreeArg.freeCallCounts = 0;
InParam.malloc_func = img_malloc;
InParam.malloc_arg = &MallocArg;
InParam.free_func = img_free;
InParam.free_arg = &FreeArg;
#endif
ret_png = cellPngDecCreate(&mHandle, &InParam, &OutParam);
if (ret_png != CELL_OK)
goto error;
memset(&src, 0, sizeof(CellPngDecSrc));
src.stream_select = CELL_PNGDEC_FILE;
#ifdef __PSL1GHT__
src.file_name = __get_addr32(path);
#else
src.file_name = path;
#endif
src.file_offset = 0;
src.file_size = 0;
src.stream_ptr = 0;
src.stream_size = 0;
src.spu_enable = CELL_PNGDEC_SPU_THREAD_ENABLE;
ret = cellPngDecOpen(mHandle, &sHandle, &src, &opnInfo);
if (ret != CELL_OK)
goto error;
ret = cellPngDecReadHeader(mHandle, sHandle, &info);
if (ret != CELL_OK)
goto error;
inParam.cmd_ptr = PTR_NULL;
inParam.output_mode = CELL_PNGDEC_TOP_TO_BOTTOM;
inParam.color_space = CELL_PNGDEC_ARGB;
inParam.bit_depth = 8;
inParam.pack_flag = CELL_PNGDEC_1BYTE_PER_1PIXEL;
inParam.alpha_select = CELL_PNGDEC_STREAM_ALPHA;
ret = cellPngDecSetParameter(mHandle, sHandle, &inParam, &outParam);
if (ret != CELL_OK)
goto error;
img_size = outParam.output_width *
outParam.output_height * sizeof(uint32_t);
out_img->pixels = (uint32_t*)malloc(img_size);
if (!out_img->pixels)
goto error;
memset(out_img->pixels, 0, img_size);
#ifdef __PSL1GHT__
output_bytes_per_line = outParam.output_width * 4;
ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)
out_img->pixels, &output_bytes_per_line, &dOutInfo);
#else
dCtrlParam.output_bytes_per_line = outParam.output_width * 4;
ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)
out_img->pixels, &dCtrlParam, &dOutInfo);
#endif
if (ret != CELL_OK || dOutInfo.status != CELL_PNGDEC_DEC_STATUS_FINISH)
goto error;
out_img->width = outParam.output_width;
out_img->height = outParam.output_height;
cellPngDecClose(mHandle, sHandle);
cellPngDecDestroy(mHandle);
return true;
error:
if (out_img->pixels)
free(out_img->pixels);
out_img->pixels = 0;
if (mHandle && sHandle)
cellPngDecClose(mHandle, sHandle);
if (mHandle)
cellPngDecDestroy(mHandle);
return false;
}
bool texture_image_load(struct texture_image *out_img, const char *path)
{
if (!out_img)
return false;
if (strstr(path, ".PNG") != NULL || strstr(path, ".png") != NULL)
{
if (!ps3_load_png(path, out_img))
return false;
}
return true;
}
void texture_image_free(struct texture_image *img)
{
if (!img)
return;
if (img->pixels)
free(img->pixels);
memset(img, 0, sizeof(*img));
}

View File

@ -1,60 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "image.h"
#include "../d3d/d3d_wrapper.h"
bool texture_image_load(struct texture_image *out_img, const char *path)
{
D3DXIMAGE_INFO m_imageInfo;
d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
out_img->vertex_buf = NULL;
out_img->pixels = d3d_texture_new(d3d->dev, path,
D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, 0, &m_imageInfo, NULL);
if (!out_img->pixels)
return false;
/* create a vertex buffer for the quad that will display the texture */
out_img->vertex_buf = (LPDIRECT3DVERTEXBUFFER)d3d_vertex_buffer_new(
d3d->dev, 4 * sizeof(Vertex), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, NULL);
if (!out_img->vertex_buf)
{
d3d_texture_free(out_img->pixels);
return false;
}
out_img->width = m_imageInfo.Width;
out_img->height = m_imageInfo.Height;
return true;
}
void texture_image_free(struct texture_image *img)
{
if (!img)
return;
d3d_vertex_buffer_free(img->vertex_buf);
d3d_texture_free(img->pixels);
memset(img, 0, sizeof(*img));
}

View File

@ -172,13 +172,7 @@ VIDEO SHADERS
VIDEO IMAGE
============================================================ */
#if defined(__CELLOS_LV2__)
#include "../gfx/image/image_ps3.c"
#elif defined(_XBOX1)
#include "../gfx/image/image_xdk1.c"
#else
#include "../gfx/image/image_rpng.c"
#endif
#include "../gfx/image/image.c"
#include "../libretro-common/formats/png/rpng_decode_fbio.c"
#include "../libretro-common/formats/png/rpng_decode_fnbio.c"