From 5068accc4e5e0f9e89d16f04e6d97328370cdfe7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 13 May 2016 08:50:50 +0200 Subject: [PATCH] Start preparing image transfer for RJPEG --- libretro-common/formats/image_transfer.c | 13 ++++--- libretro-common/formats/jpeg/rjpeg.c | 44 ++++++++++++++---------- libretro-common/formats/png/rpng.c | 4 +-- libretro-common/include/formats/image.h | 2 +- libretro-common/include/formats/rjpeg.h | 3 ++ libretro-common/include/formats/rpng.h | 2 +- tasks/task_image.c | 4 ++- tasks/tasks_internal.h | 1 + 8 files changed, 44 insertions(+), 29 deletions(-) diff --git a/libretro-common/formats/image_transfer.c b/libretro-common/formats/image_transfer.c index ae29f8756d..b0a756163e 100644 --- a/libretro-common/formats/image_transfer.c +++ b/libretro-common/formats/image_transfer.c @@ -92,7 +92,7 @@ void image_transfer_set_buffer_ptr( int image_transfer_process( void *data, enum image_type_enum type, - uint32_t **buf, + uint32_t **buf, size_t len, unsigned *width, unsigned *height) { switch (type) @@ -104,14 +104,17 @@ int image_transfer_process( return rpng_nbio_load_image_argb_process( (rpng_t*)data, - buf, - width, height); -#endif + buf, width, height); +#else break; +#endif case IMAGE_TYPE_JPEG: #ifdef HAVE_RJPEG -#endif + return rjpeg_process_image((rjpeg_t*)data, + buf, len, width, height); +#else break; +#endif } return 0; diff --git a/libretro-common/formats/jpeg/rjpeg.c b/libretro-common/formats/jpeg/rjpeg.c index 8419e5bb12..4ac0defbff 100644 --- a/libretro-common/formats/jpeg/rjpeg.c +++ b/libretro-common/formats/jpeg/rjpeg.c @@ -181,7 +181,7 @@ static void rjpeg__rewind(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 */ 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 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)) 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"); } -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); @@ -241,7 +241,7 @@ static unsigned char *rjpeg__load_flip(rjpeg__context *s, int *x, int *y, int *c 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__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; 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; 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 g_shift, unsigned b_shift) { - int comp; - int x = 0; - int y = 0; + unsigned width = 0; + unsigned height = 0; 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; - 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; + return false; } void rjpeg_free(rjpeg_t *rjpeg) diff --git a/libretro-common/formats/png/rpng.c b/libretro-common/formats/png/rpng.c index ab92674082..3a52e2d2fc 100644 --- a/libretro-common/formats/png/rpng.c +++ b/libretro-common/formats/png/rpng.c @@ -1019,12 +1019,12 @@ bool rpng_is_valid(rpng_t *rpng) 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) return false; - rpng->buff_data = data; + rpng->buff_data = (uint8_t*)data; return true; } diff --git a/libretro-common/include/formats/image.h b/libretro-common/include/formats/image.h index 9e9794ac94..0cb7fd3c14 100644 --- a/libretro-common/include/formats/image.h +++ b/libretro-common/include/formats/image.h @@ -72,7 +72,7 @@ void image_transfer_set_buffer_ptr( int image_transfer_process( void *data, enum image_type_enum type, - uint32_t **buf, + uint32_t **buf, size_t size, unsigned *width, unsigned *height); bool image_transfer_iterate(void *data, enum image_type_enum type); diff --git a/libretro-common/include/formats/rjpeg.h b/libretro-common/include/formats/rjpeg.h index f0ddece720..afb51c942e 100644 --- a/libretro-common/include/formats/rjpeg.h +++ b/libretro-common/include/formats/rjpeg.h @@ -34,6 +34,9 @@ RETRO_BEGIN_DECLS 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, unsigned a_shift, unsigned r_shift, unsigned g_shift, unsigned b_shift); diff --git a/libretro-common/include/formats/rpng.h b/libretro-common/include/formats/rpng.h index 94db62932f..b9fa108b62 100644 --- a/libretro-common/include/formats/rpng.h +++ b/libretro-common/include/formats/rpng.h @@ -39,7 +39,7 @@ rpng_t *rpng_nbio_load_image_argb_init(const char *path); 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); diff --git a/tasks/task_image.c b/tasks/task_image.c index 124d0f712f..ed74d11719 100644 --- a/tasks/task_image.c +++ b/tasks/task_image.c @@ -101,7 +101,7 @@ static int rarch_main_data_image_process( int retval = image_transfer_process( nbio->image.handle, nbio->image_type, - &nbio->image.ti.pixels, width, height); + &nbio->image.ti.pixels, nbio->image.size, width, height); if (retval == 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); + nbio->image.size = *len; nbio->image.pos_increment = (*len / 2) ? (*len / 2) : 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; nbio->image.handle = image_transfer_new(nbio->image_type); + nbio->image.size = len; if (!nbio->image.handle) goto error; diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h index 7ab3291530..c393fb1609 100644 --- a/tasks/tasks_internal.h +++ b/tasks/tasks_internal.h @@ -62,6 +62,7 @@ typedef struct nbio_image_handle bool is_finished; transfer_cb_t cb; void *handle; + size_t size; unsigned processing_pos_increment; unsigned pos_increment; uint64_t frame_count;