mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
Start preparing image transfer for RJPEG
This commit is contained in:
parent
17d39fd54f
commit
5068accc4e
@ -92,7 +92,7 @@ void image_transfer_set_buffer_ptr(
|
|||||||
int image_transfer_process(
|
int image_transfer_process(
|
||||||
void *data,
|
void *data,
|
||||||
enum image_type_enum type,
|
enum image_type_enum type,
|
||||||
uint32_t **buf,
|
uint32_t **buf, size_t len,
|
||||||
unsigned *width, unsigned *height)
|
unsigned *width, unsigned *height)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
@ -104,14 +104,17 @@ int image_transfer_process(
|
|||||||
|
|
||||||
return rpng_nbio_load_image_argb_process(
|
return rpng_nbio_load_image_argb_process(
|
||||||
(rpng_t*)data,
|
(rpng_t*)data,
|
||||||
buf,
|
buf, width, height);
|
||||||
width, height);
|
#else
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case IMAGE_TYPE_JPEG:
|
case IMAGE_TYPE_JPEG:
|
||||||
#ifdef HAVE_RJPEG
|
#ifdef HAVE_RJPEG
|
||||||
#endif
|
return rjpeg_process_image((rjpeg_t*)data,
|
||||||
|
buf, len, width, height);
|
||||||
|
#else
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -181,7 +181,7 @@ static void rjpeg__rewind(rjpeg__context *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int rjpeg__jpeg_test(rjpeg__context *s);
|
static int rjpeg__jpeg_test(rjpeg__context *s);
|
||||||
static uint8_t *rjpeg__jpeg_load(rjpeg__context *s, int *x, int *y, int *comp, int req_comp);
|
static uint8_t *rjpeg__jpeg_load(rjpeg__context *s, unsigned *x, unsigned *y, int *comp, int req_comp);
|
||||||
|
|
||||||
/* this is not threadsafe */
|
/* this is not threadsafe */
|
||||||
static const char *rjpeg__g_failure_reason;
|
static const char *rjpeg__g_failure_reason;
|
||||||
@ -205,7 +205,7 @@ static INLINE int rjpeg__err(const char *str)
|
|||||||
|
|
||||||
static int rjpeg__vertically_flip_on_load = 0;
|
static int rjpeg__vertically_flip_on_load = 0;
|
||||||
|
|
||||||
static unsigned char *rjpeg__load_main(rjpeg__context *s, int *x, int *y, int *comp, int req_comp)
|
static unsigned char *rjpeg__load_main(rjpeg__context *s, unsigned *x, unsigned *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
if (rjpeg__jpeg_test(s))
|
if (rjpeg__jpeg_test(s))
|
||||||
return rjpeg__jpeg_load(s,x,y,comp,req_comp);
|
return rjpeg__jpeg_load(s,x,y,comp,req_comp);
|
||||||
@ -213,7 +213,7 @@ static unsigned char *rjpeg__load_main(rjpeg__context *s, int *x, int *y, int *c
|
|||||||
return rjpeg__errpuc("unknown image type", "Image not of any known type, or corrupt");
|
return rjpeg__errpuc("unknown image type", "Image not of any known type, or corrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *rjpeg__load_flip(rjpeg__context *s, int *x, int *y, int *comp, int req_comp)
|
static unsigned char *rjpeg__load_flip(rjpeg__context *s, unsigned *x, unsigned *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
unsigned char *result = rjpeg__load_main(s, x, y, comp, req_comp);
|
unsigned char *result = rjpeg__load_main(s, x, y, comp, req_comp);
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ static unsigned char *rjpeg__load_flip(rjpeg__context *s, int *x, int *y, int *c
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t *rjpeg_load_from_memory(const uint8_t *buffer, int len, int *x, int *y, int *comp, int req_comp)
|
static uint8_t *rjpeg_load_from_memory(const uint8_t *buffer, int len, unsigned *x, unsigned *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
rjpeg__context s;
|
rjpeg__context s;
|
||||||
rjpeg__start_mem(&s,buffer,len);
|
rjpeg__start_mem(&s,buffer,len);
|
||||||
@ -2279,7 +2279,7 @@ static void rjpeg__cleanup_jpeg(rjpeg__jpeg *j)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp)
|
static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, unsigned *out_x, unsigned *out_y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
int n, decode_n;
|
int n, decode_n;
|
||||||
z->s->img_n = 0; /* make rjpeg__cleanup_jpeg safe */
|
z->s->img_n = 0; /* make rjpeg__cleanup_jpeg safe */
|
||||||
@ -2409,7 +2409,7 @@ static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, int *out_x, int *out_y, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *rjpeg__jpeg_load(rjpeg__context *s, int *x, int *y, int *comp, int req_comp)
|
static unsigned char *rjpeg__jpeg_load(rjpeg__context *s, unsigned *x, unsigned *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
rjpeg__jpeg j;
|
rjpeg__jpeg j;
|
||||||
j.s = s;
|
j.s = s;
|
||||||
@ -2446,25 +2446,31 @@ static INLINE void video_frame_convert_rgba_to_bgra(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rjpeg_image_load(uint8_t *_buf, void *data, size_t size,
|
int rjpeg_process_image(void *data, uint8_t *buf,
|
||||||
|
size_t size, unsigned *width, unsigned *height)
|
||||||
|
{
|
||||||
|
int comp;
|
||||||
|
struct texture_image *out_img = (struct texture_image*)data;
|
||||||
|
|
||||||
|
out_img->pixels = (uint32_t*)rjpeg_load_from_memory(buf, size, width, height, &comp, 4);
|
||||||
|
out_img->width = *width;
|
||||||
|
out_img->height = *height;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool rjpeg_image_load(uint8_t *buf, void *data, size_t size,
|
||||||
unsigned a_shift, unsigned r_shift,
|
unsigned a_shift, unsigned r_shift,
|
||||||
unsigned g_shift, unsigned b_shift)
|
unsigned g_shift, unsigned b_shift)
|
||||||
{
|
{
|
||||||
int comp;
|
unsigned width = 0;
|
||||||
int x = 0;
|
unsigned height = 0;
|
||||||
int y = 0;
|
|
||||||
struct texture_image *out_img = (struct texture_image*)data;
|
struct texture_image *out_img = (struct texture_image*)data;
|
||||||
|
|
||||||
out_img->pixels = (uint32_t*)rjpeg_load_from_memory(_buf, size, &x, &y, &comp, 4);
|
if (rjpeg_process_image(out_img, buf, size, &width, &height))
|
||||||
|
return true;
|
||||||
|
|
||||||
out_img->width = x;
|
return false;
|
||||||
out_img->height = y;
|
|
||||||
|
|
||||||
if (r_shift == 0 && b_shift == 16) { } /* RGBA, doesn't need conversion */
|
|
||||||
else
|
|
||||||
video_frame_convert_rgba_to_bgra(_buf, out_img->pixels, x);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rjpeg_free(rjpeg_t *rjpeg)
|
void rjpeg_free(rjpeg_t *rjpeg)
|
||||||
|
@ -1019,12 +1019,12 @@ bool rpng_is_valid(rpng_t *rpng)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rpng_set_buf_ptr(rpng_t *rpng, uint8_t *data)
|
bool rpng_set_buf_ptr(rpng_t *rpng, void *data)
|
||||||
{
|
{
|
||||||
if (!rpng)
|
if (!rpng)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
rpng->buff_data = data;
|
rpng->buff_data = (uint8_t*)data;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ void image_transfer_set_buffer_ptr(
|
|||||||
int image_transfer_process(
|
int image_transfer_process(
|
||||||
void *data,
|
void *data,
|
||||||
enum image_type_enum type,
|
enum image_type_enum type,
|
||||||
uint32_t **buf,
|
uint32_t **buf, size_t size,
|
||||||
unsigned *width, unsigned *height);
|
unsigned *width, unsigned *height);
|
||||||
|
|
||||||
bool image_transfer_iterate(void *data, enum image_type_enum type);
|
bool image_transfer_iterate(void *data, enum image_type_enum type);
|
||||||
|
@ -34,6 +34,9 @@ RETRO_BEGIN_DECLS
|
|||||||
|
|
||||||
typedef struct rjpeg rjpeg_t;
|
typedef struct rjpeg rjpeg_t;
|
||||||
|
|
||||||
|
int rjpeg_process_image(void *data, uint8_t *buf,
|
||||||
|
size_t size, unsigned *width, unsigned *height);
|
||||||
|
|
||||||
bool rjpeg_image_load(uint8_t *buf, void *data, size_t size,
|
bool rjpeg_image_load(uint8_t *buf, void *data, size_t size,
|
||||||
unsigned a_shift, unsigned r_shift, unsigned g_shift, unsigned b_shift);
|
unsigned a_shift, unsigned r_shift, unsigned g_shift, unsigned b_shift);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ rpng_t *rpng_nbio_load_image_argb_init(const char *path);
|
|||||||
|
|
||||||
bool rpng_is_valid(rpng_t *rpng);
|
bool rpng_is_valid(rpng_t *rpng);
|
||||||
|
|
||||||
bool rpng_set_buf_ptr(rpng_t *rpng, uint8_t *data);
|
bool rpng_set_buf_ptr(rpng_t *rpng, void *data);
|
||||||
|
|
||||||
rpng_t *rpng_alloc(void);
|
rpng_t *rpng_alloc(void);
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ static int rarch_main_data_image_process(
|
|||||||
int retval = image_transfer_process(
|
int retval = image_transfer_process(
|
||||||
nbio->image.handle,
|
nbio->image.handle,
|
||||||
nbio->image_type,
|
nbio->image_type,
|
||||||
&nbio->image.ti.pixels, width, height);
|
&nbio->image.ti.pixels, nbio->image.size, width, height);
|
||||||
|
|
||||||
if (retval == IMAGE_PROCESS_ERROR)
|
if (retval == IMAGE_PROCESS_ERROR)
|
||||||
return IMAGE_PROCESS_ERROR;
|
return IMAGE_PROCESS_ERROR;
|
||||||
@ -220,6 +220,7 @@ static int cb_nbio_generic(nbio_handle_t *nbio, size_t *len)
|
|||||||
|
|
||||||
image_transfer_set_buffer_ptr(nbio->image.handle, nbio->image_type, ptr);
|
image_transfer_set_buffer_ptr(nbio->image.handle, nbio->image_type, ptr);
|
||||||
|
|
||||||
|
nbio->image.size = *len;
|
||||||
nbio->image.pos_increment = (*len / 2) ? (*len / 2) : 1;
|
nbio->image.pos_increment = (*len / 2) ? (*len / 2) : 1;
|
||||||
nbio->image.processing_pos_increment = (*len / 4) ? (*len / 4) : 1;
|
nbio->image.processing_pos_increment = (*len / 4) ? (*len / 4) : 1;
|
||||||
|
|
||||||
@ -245,6 +246,7 @@ static int cb_nbio_image_menu_thumbnail(void *data, size_t len)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
nbio->image.handle = image_transfer_new(nbio->image_type);
|
nbio->image.handle = image_transfer_new(nbio->image_type);
|
||||||
|
nbio->image.size = len;
|
||||||
|
|
||||||
if (!nbio->image.handle)
|
if (!nbio->image.handle)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -62,6 +62,7 @@ typedef struct nbio_image_handle
|
|||||||
bool is_finished;
|
bool is_finished;
|
||||||
transfer_cb_t cb;
|
transfer_cb_t cb;
|
||||||
void *handle;
|
void *handle;
|
||||||
|
size_t size;
|
||||||
unsigned processing_pos_increment;
|
unsigned processing_pos_increment;
|
||||||
unsigned pos_increment;
|
unsigned pos_increment;
|
||||||
uint64_t frame_count;
|
uint64_t frame_count;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user