2016-05-10 05:54:47 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2016-05-10 05:54:47 +00:00
|
|
|
*
|
|
|
|
* 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 <stdint.h>
|
2017-05-09 18:08:40 +00:00
|
|
|
#include <stdlib.h>
|
2016-05-10 05:54:47 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <file/nbio.h>
|
|
|
|
#include <formats/image.h>
|
|
|
|
#include <compat/strl.h>
|
2017-09-29 20:16:17 +00:00
|
|
|
#include <string/stdstring.h>
|
2016-05-10 05:54:47 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2019-05-28 11:55:31 +00:00
|
|
|
#include <features/features_cpu.h>
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2019-01-20 01:17:43 +00:00
|
|
|
#include "task_file_transfer.h"
|
2016-07-23 09:28:24 +00:00
|
|
|
#include "tasks_internal.h"
|
|
|
|
|
2019-07-08 15:58:02 +00:00
|
|
|
#include "../configuration.h"
|
2019-05-28 11:55:31 +00:00
|
|
|
|
2016-05-10 05:55:31 +00:00
|
|
|
enum image_status_enum
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2019-05-28 11:55:31 +00:00
|
|
|
IMAGE_STATUS_WAIT = 0,
|
|
|
|
IMAGE_STATUS_TRANSFER,
|
2016-05-10 05:55:31 +00:00
|
|
|
IMAGE_STATUS_TRANSFER_PARSE,
|
|
|
|
IMAGE_STATUS_PROCESS_TRANSFER,
|
2017-05-14 15:32:07 +00:00
|
|
|
IMAGE_STATUS_PROCESS_TRANSFER_PARSE
|
2016-05-10 05:54:47 +00:00
|
|
|
};
|
|
|
|
|
2022-10-06 04:53:13 +00:00
|
|
|
enum image_flags_enum
|
|
|
|
{
|
|
|
|
IMAGE_FLAG_IS_BLOCKING = (1 << 0),
|
|
|
|
IMAGE_FLAG_IS_BLOCKING_ON_PROCESSING = (1 << 1),
|
|
|
|
IMAGE_FLAG_IS_FINISHED = (1 << 2)
|
|
|
|
};
|
|
|
|
|
2016-05-13 13:00:44 +00:00
|
|
|
struct nbio_image_handle
|
|
|
|
{
|
2020-08-14 16:51:50 +00:00
|
|
|
void *handle;
|
|
|
|
transfer_cb_t cb;
|
|
|
|
struct texture_image ti; /* ptr alignment */
|
|
|
|
size_t size;
|
|
|
|
int processing_final_state;
|
|
|
|
unsigned frame_duration;
|
|
|
|
unsigned upscale_threshold;
|
2017-05-09 18:01:42 +00:00
|
|
|
enum image_type_enum type;
|
2017-09-29 20:36:48 +00:00
|
|
|
enum image_status_enum status;
|
2022-10-06 04:53:13 +00:00
|
|
|
uint8_t flags;
|
2016-05-13 13:00:44 +00:00
|
|
|
};
|
|
|
|
|
2019-05-22 02:54:37 +00:00
|
|
|
static int cb_image_upload_generic(void *data, size_t len)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
|
|
|
unsigned r_shift, g_shift, b_shift, a_shift;
|
2016-09-23 00:49:25 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-26 15:47:21 +00:00
|
|
|
if (!image)
|
2016-05-10 05:54:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2017-01-05 03:52:04 +00:00
|
|
|
switch (image->processing_final_state)
|
|
|
|
{
|
|
|
|
case IMAGE_PROCESS_ERROR:
|
|
|
|
case IMAGE_PROCESS_ERROR_END:
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
image_texture_set_color_shifts(&r_shift, &g_shift, &b_shift,
|
2016-12-29 22:22:40 +00:00
|
|
|
&a_shift, &image->ti);
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-05-18 10:57:44 +00:00
|
|
|
image_texture_color_convert(r_shift, g_shift, b_shift,
|
2016-05-13 13:18:40 +00:00
|
|
|
a_shift, &image->ti);
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2022-10-06 04:53:13 +00:00
|
|
|
image->flags &= ~IMAGE_FLAG_IS_BLOCKING_ON_PROCESSING;
|
|
|
|
image->flags |= IMAGE_FLAG_IS_BLOCKING;
|
|
|
|
image->flags |= IMAGE_FLAG_IS_FINISHED;
|
2016-05-13 13:18:40 +00:00
|
|
|
nbio->is_finished = true;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:13:36 +00:00
|
|
|
static int task_image_process(
|
2017-05-09 18:01:42 +00:00
|
|
|
struct nbio_image_handle *image,
|
2016-05-12 11:13:14 +00:00
|
|
|
unsigned *width,
|
|
|
|
unsigned *height)
|
|
|
|
{
|
2019-05-27 12:04:54 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!image_transfer_is_valid(image->handle, image->type))
|
|
|
|
return IMAGE_PROCESS_ERROR;
|
|
|
|
|
2022-07-08 22:53:08 +00:00
|
|
|
if ((retval = image_transfer_process(
|
2016-05-20 19:03:42 +00:00
|
|
|
image->handle,
|
2017-05-09 18:01:42 +00:00
|
|
|
image->type,
|
2022-07-08 22:53:08 +00:00
|
|
|
&image->ti.pixels, image->size, width, height)) == IMAGE_PROCESS_ERROR)
|
2016-05-12 11:13:14 +00:00
|
|
|
return IMAGE_PROCESS_ERROR;
|
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image->ti.width = *width;
|
|
|
|
image->ti.height = *height;
|
2016-05-10 06:23:49 +00:00
|
|
|
|
2016-05-11 18:38:09 +00:00
|
|
|
return retval;
|
2016-05-10 06:23:49 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 02:54:37 +00:00
|
|
|
static int cb_image_thumbnail(void *data, size_t len)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2017-05-14 06:09:21 +00:00
|
|
|
unsigned width = 0;
|
|
|
|
unsigned height = 0;
|
2017-12-12 07:55:31 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
2017-05-14 06:09:21 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2018-01-23 03:57:12 +00:00
|
|
|
int retval = image ? task_image_process(image, &width, &height) : IMAGE_PROCESS_ERROR;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2017-05-14 05:58:43 +00:00
|
|
|
if ((retval == IMAGE_PROCESS_ERROR) ||
|
|
|
|
(retval == IMAGE_PROCESS_ERROR_END)
|
|
|
|
)
|
2016-05-10 05:54:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2022-10-06 04:53:13 +00:00
|
|
|
if (retval != IMAGE_PROCESS_END)
|
|
|
|
image->flags |= IMAGE_FLAG_IS_BLOCKING_ON_PROCESSING;
|
|
|
|
else
|
|
|
|
image->flags &= ~IMAGE_FLAG_IS_BLOCKING_ON_PROCESSING;
|
|
|
|
if (retval == IMAGE_PROCESS_END)
|
|
|
|
image->flags |= IMAGE_FLAG_IS_FINISHED;
|
|
|
|
else
|
|
|
|
image->flags &= ~IMAGE_FLAG_IS_FINISHED;
|
2019-05-22 02:54:37 +00:00
|
|
|
image->cb = &cb_image_upload_generic;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-09 18:01:42 +00:00
|
|
|
static int task_image_iterate_process_transfer(struct nbio_image_handle *image)
|
2016-05-11 19:22:45 +00:00
|
|
|
{
|
2017-01-05 06:48:11 +00:00
|
|
|
int retval = 0;
|
|
|
|
unsigned width = 0;
|
|
|
|
unsigned height = 0;
|
2019-05-28 11:55:31 +00:00
|
|
|
retro_time_t start_time = cpu_features_get_time_usec();
|
2016-05-11 19:22:45 +00:00
|
|
|
|
2019-05-28 11:55:31 +00:00
|
|
|
do
|
2016-05-11 19:22:45 +00:00
|
|
|
{
|
2022-07-08 22:53:08 +00:00
|
|
|
if ((retval = task_image_process(image, &width, &height)) != IMAGE_PROCESS_NEXT)
|
2016-05-11 19:22:45 +00:00
|
|
|
break;
|
2020-06-26 18:00:19 +00:00
|
|
|
}while (cpu_features_get_time_usec() - start_time
|
2020-02-29 11:55:33 +00:00
|
|
|
< image->frame_duration);
|
2016-05-11 19:22:45 +00:00
|
|
|
|
|
|
|
if (retval == IMAGE_PROCESS_NEXT)
|
|
|
|
return 0;
|
|
|
|
|
2016-05-13 13:18:40 +00:00
|
|
|
image->processing_final_state = retval;
|
2016-05-11 19:22:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-14 05:58:43 +00:00
|
|
|
static void task_image_cleanup(nbio_handle_t *nbio)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2017-05-14 05:58:43 +00:00
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2017-05-14 05:58:43 +00:00
|
|
|
if (image)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2017-05-14 05:58:43 +00:00
|
|
|
image_transfer_free(image->handle, image->type);
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2022-07-08 22:53:08 +00:00
|
|
|
image->handle = NULL;
|
|
|
|
image->cb = NULL;
|
2017-05-14 05:58:43 +00:00
|
|
|
}
|
2017-09-30 04:23:23 +00:00
|
|
|
if (!string_is_empty(nbio->path))
|
2017-09-29 20:16:17 +00:00
|
|
|
free(nbio->path);
|
2017-05-14 05:58:43 +00:00
|
|
|
if (nbio->data)
|
|
|
|
free(nbio->data);
|
|
|
|
nbio_free(nbio->handle);
|
2017-09-29 20:16:17 +00:00
|
|
|
nbio->path = NULL;
|
2017-05-14 05:58:43 +00:00
|
|
|
nbio->data = NULL;
|
|
|
|
nbio->handle = NULL;
|
2016-05-10 06:09:12 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 16:08:37 +00:00
|
|
|
static void task_image_load_free(retro_task_t *task)
|
|
|
|
{
|
2022-07-08 22:53:08 +00:00
|
|
|
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
2017-05-13 16:08:37 +00:00
|
|
|
|
|
|
|
if (nbio)
|
|
|
|
{
|
2017-05-14 05:58:43 +00:00
|
|
|
task_image_cleanup(nbio);
|
2017-05-13 16:08:37 +00:00
|
|
|
free(nbio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-22 02:54:37 +00:00
|
|
|
static int cb_nbio_image_thumbnail(void *data, size_t len)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2017-05-14 06:06:40 +00:00
|
|
|
void *ptr = NULL;
|
2017-12-12 07:55:31 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
2019-05-28 11:55:31 +00:00
|
|
|
struct nbio_image_handle *image = nbio ? (struct nbio_image_handle*)nbio->data : NULL;
|
|
|
|
void *handle = image ? image_transfer_new(image->type) : NULL;
|
2019-07-08 15:58:02 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
float refresh_rate = 0.0f;
|
2016-05-13 02:28:16 +00:00
|
|
|
|
2016-05-18 15:27:05 +00:00
|
|
|
if (!handle)
|
2017-05-14 05:58:43 +00:00
|
|
|
return -1;
|
|
|
|
|
2019-05-28 11:55:31 +00:00
|
|
|
image->status = IMAGE_STATUS_TRANSFER;
|
2017-05-14 06:09:21 +00:00
|
|
|
image->handle = handle;
|
2019-05-22 02:54:37 +00:00
|
|
|
image->cb = &cb_image_thumbnail;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2017-05-14 06:09:21 +00:00
|
|
|
ptr = nbio_get_ptr(nbio->handle, &len);
|
2017-05-14 06:06:40 +00:00
|
|
|
|
2019-05-27 12:04:54 +00:00
|
|
|
image_transfer_set_buffer_ptr(image->handle, image->type, ptr, len);
|
2017-05-14 06:06:40 +00:00
|
|
|
|
2019-05-28 16:22:23 +00:00
|
|
|
/* Set image size */
|
|
|
|
image->size = len;
|
|
|
|
|
2019-05-28 11:55:31 +00:00
|
|
|
/* Set task iteration duration */
|
2019-07-08 15:58:02 +00:00
|
|
|
if (settings)
|
|
|
|
refresh_rate = settings->floats.video_refresh_rate;
|
|
|
|
|
|
|
|
if (refresh_rate <= 0.0f)
|
2019-05-28 11:55:31 +00:00
|
|
|
refresh_rate = 60.0f;
|
|
|
|
image->frame_duration = (unsigned)((1.0 / refresh_rate) * 1000000.0f);
|
2017-05-14 06:06:40 +00:00
|
|
|
|
|
|
|
if (!image_transfer_start(image->handle, image->type))
|
|
|
|
{
|
|
|
|
task_image_cleanup(nbio);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-10-06 04:53:13 +00:00
|
|
|
image->flags &= ~IMAGE_FLAG_IS_BLOCKING;
|
|
|
|
image->flags &= ~IMAGE_FLAG_IS_FINISHED;
|
2017-05-14 06:09:21 +00:00
|
|
|
nbio->is_finished = true;
|
2017-05-14 06:06:40 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-05-10 05:54:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 16:04:23 +00:00
|
|
|
static bool upscale_image(
|
|
|
|
unsigned scale_factor,
|
|
|
|
struct texture_image *image_src,
|
|
|
|
struct texture_image *image_dst)
|
|
|
|
{
|
|
|
|
uint32_t x_ratio, y_ratio;
|
2022-07-08 22:53:08 +00:00
|
|
|
unsigned y_dst;
|
2019-06-05 16:04:23 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if ((scale_factor < 1) || !image_src || !image_dst)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!image_src->pixels || (image_src->width < 1) || (image_src->height < 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Get output dimensions */
|
2022-07-08 22:53:08 +00:00
|
|
|
image_dst->width = image_src->width * scale_factor;
|
2019-06-05 16:04:23 +00:00
|
|
|
image_dst->height = image_src->height * scale_factor;
|
|
|
|
|
|
|
|
/* Allocate pixel buffer */
|
2022-07-08 22:53:08 +00:00
|
|
|
if (!(image_dst->pixels = (uint32_t*)calloc(image_dst->width * image_dst->height, sizeof(uint32_t))))
|
2019-06-05 16:04:23 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Perform nearest neighbour resampling */
|
|
|
|
x_ratio = ((image_src->width << 16) / image_dst->width);
|
|
|
|
y_ratio = ((image_src->height << 16) / image_dst->height);
|
|
|
|
|
|
|
|
for (y_dst = 0; y_dst < image_dst->height; y_dst++)
|
|
|
|
{
|
2022-07-08 22:53:08 +00:00
|
|
|
unsigned x_dst;
|
|
|
|
unsigned y_src = (y_dst * y_ratio) >> 16;
|
2019-06-05 16:04:23 +00:00
|
|
|
for (x_dst = 0; x_dst < image_dst->width; x_dst++)
|
|
|
|
{
|
2022-07-08 22:53:08 +00:00
|
|
|
unsigned x_src = (x_dst * x_ratio) >> 16;
|
2019-06-05 16:04:23 +00:00
|
|
|
image_dst->pixels[(y_dst * image_dst->width) + x_dst] = image_src->pixels[(y_src * image_src->width) + x_src];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-27 16:14:47 +00:00
|
|
|
bool task_image_load_handler(retro_task_t *task)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-12-29 21:53:10 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
|
|
|
|
struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-27 23:40:46 +00:00
|
|
|
if (image)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-12-27 23:40:46 +00:00
|
|
|
switch (image->status)
|
|
|
|
{
|
2019-05-28 11:55:31 +00:00
|
|
|
case IMAGE_STATUS_WAIT:
|
|
|
|
return true;
|
2016-12-27 23:40:46 +00:00
|
|
|
case IMAGE_STATUS_PROCESS_TRANSFER:
|
2019-05-28 11:55:31 +00:00
|
|
|
if (task_image_iterate_process_transfer(image) == -1)
|
2016-12-27 23:40:46 +00:00
|
|
|
image->status = IMAGE_STATUS_PROCESS_TRANSFER_PARSE;
|
2016-05-10 05:54:47 +00:00
|
|
|
break;
|
2016-12-27 23:40:46 +00:00
|
|
|
case IMAGE_STATUS_TRANSFER_PARSE:
|
2017-05-09 18:01:42 +00:00
|
|
|
if (image->handle && image->cb)
|
|
|
|
{
|
|
|
|
size_t len = 0;
|
2019-05-27 12:04:54 +00:00
|
|
|
if (image->cb(nbio, len) == -1)
|
|
|
|
return false;
|
2017-05-09 18:01:42 +00:00
|
|
|
}
|
2022-10-06 04:53:13 +00:00
|
|
|
if (image->flags & IMAGE_FLAG_IS_BLOCKING_ON_PROCESSING)
|
2016-12-27 23:40:46 +00:00
|
|
|
image->status = IMAGE_STATUS_PROCESS_TRANSFER;
|
|
|
|
break;
|
|
|
|
case IMAGE_STATUS_TRANSFER:
|
2022-10-06 04:53:13 +00:00
|
|
|
if ( !(image->flags & IMAGE_FLAG_IS_BLOCKING)
|
|
|
|
&& !(image->flags & IMAGE_FLAG_IS_FINISHED))
|
2017-05-14 05:58:43 +00:00
|
|
|
{
|
2019-05-28 11:55:31 +00:00
|
|
|
retro_time_t start_time = cpu_features_get_time_usec();
|
|
|
|
do
|
2017-05-14 05:58:43 +00:00
|
|
|
{
|
|
|
|
if (!image_transfer_iterate(image->handle, image->type))
|
|
|
|
{
|
|
|
|
image->status = IMAGE_STATUS_TRANSFER_PARSE;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-29 11:55:33 +00:00
|
|
|
}while (cpu_features_get_time_usec() - start_time
|
|
|
|
< image->frame_duration);
|
2017-05-14 05:58:43 +00:00
|
|
|
}
|
2016-12-27 23:40:46 +00:00
|
|
|
break;
|
|
|
|
case IMAGE_STATUS_PROCESS_TRANSFER_PARSE:
|
2017-05-09 18:01:42 +00:00
|
|
|
if (image->handle && image->cb)
|
|
|
|
{
|
|
|
|
size_t len = 0;
|
2019-05-27 12:04:54 +00:00
|
|
|
if (image->cb(nbio, len) == -1)
|
|
|
|
return false;
|
2017-05-09 18:01:42 +00:00
|
|
|
}
|
2022-10-06 04:53:13 +00:00
|
|
|
if (!(image->flags & IMAGE_FLAG_IS_FINISHED))
|
2016-12-27 23:40:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-10 05:54:47 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 19:28:49 +00:00
|
|
|
if ( nbio->is_finished
|
2022-10-06 04:53:13 +00:00
|
|
|
&& (image && (image->flags & IMAGE_FLAG_IS_FINISHED))
|
2017-02-21 19:29:29 +00:00
|
|
|
&& (!task_get_cancelled(task)))
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2017-05-17 23:31:14 +00:00
|
|
|
struct texture_image *img = (struct texture_image*)malloc(sizeof(struct texture_image));
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2017-05-17 23:31:14 +00:00
|
|
|
if (img)
|
|
|
|
{
|
2019-06-05 16:04:23 +00:00
|
|
|
/* Upscale image, if required */
|
|
|
|
if (image->upscale_threshold > 0)
|
|
|
|
{
|
|
|
|
if (((image->ti.width > 0) && (image->ti.height > 0)) &&
|
|
|
|
((image->ti.width < image->upscale_threshold) ||
|
|
|
|
(image->ti.height < image->upscale_threshold)))
|
|
|
|
{
|
|
|
|
unsigned min_size = (image->ti.width < image->ti.height) ?
|
|
|
|
image->ti.width : image->ti.height;
|
|
|
|
float scale_factor = (float)image->upscale_threshold /
|
|
|
|
(float)min_size;
|
|
|
|
unsigned scale_factor_int = (unsigned)scale_factor;
|
|
|
|
struct texture_image img_resampled = {
|
2020-08-14 22:44:35 +00:00
|
|
|
NULL,
|
2019-06-05 16:04:23 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
|
|
|
if (scale_factor - (float)scale_factor_int > 0.0f)
|
|
|
|
scale_factor_int += 1;
|
|
|
|
|
|
|
|
if (upscale_image(scale_factor_int, &image->ti, &img_resampled))
|
|
|
|
{
|
|
|
|
image->ti.width = img_resampled.width;
|
|
|
|
image->ti.height = img_resampled.height;
|
|
|
|
|
|
|
|
if (image->ti.pixels)
|
|
|
|
free(image->ti.pixels);
|
|
|
|
image->ti.pixels = img_resampled.pixels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 23:31:14 +00:00
|
|
|
img->width = image->ti.width;
|
|
|
|
img->height = image->ti.height;
|
|
|
|
img->pixels = image->ti.pixels;
|
|
|
|
img->supports_rgba = image->ti.supports_rgba;
|
|
|
|
}
|
2016-12-29 05:50:18 +00:00
|
|
|
|
2017-05-17 23:31:14 +00:00
|
|
|
task_set_data(task, img);
|
2016-05-10 05:54:47 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-22 04:17:08 +00:00
|
|
|
bool task_push_image_load(const char *fullpath,
|
2019-06-05 16:04:23 +00:00
|
|
|
bool supports_rgba, unsigned upscale_threshold,
|
2019-05-22 04:17:08 +00:00
|
|
|
retro_task_callback_t cb, void *user_data)
|
2016-05-10 05:54:47 +00:00
|
|
|
{
|
2016-12-29 21:53:10 +00:00
|
|
|
nbio_handle_t *nbio = NULL;
|
2016-09-23 00:50:29 +00:00
|
|
|
struct nbio_image_handle *image = NULL;
|
2018-11-22 14:45:52 +00:00
|
|
|
retro_task_t *t = task_init();
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2016-12-29 21:53:10 +00:00
|
|
|
if (!t)
|
2019-05-22 02:54:37 +00:00
|
|
|
return false;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2022-07-08 22:53:08 +00:00
|
|
|
if (!(nbio = (nbio_handle_t*)malloc(sizeof(*nbio))))
|
2019-05-22 02:54:37 +00:00
|
|
|
{
|
|
|
|
free(t);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2017-09-29 20:36:48 +00:00
|
|
|
nbio->type = NBIO_TYPE_NONE;
|
|
|
|
nbio->is_finished = false;
|
|
|
|
nbio->status = NBIO_STATUS_INIT;
|
|
|
|
nbio->pos_increment = 0;
|
|
|
|
nbio->status_flags = 0;
|
|
|
|
nbio->data = NULL;
|
|
|
|
nbio->handle = NULL;
|
2019-05-22 02:54:37 +00:00
|
|
|
nbio->cb = &cb_nbio_image_thumbnail;
|
2016-05-23 20:41:24 +00:00
|
|
|
|
2019-05-22 04:17:08 +00:00
|
|
|
if (supports_rgba)
|
2016-12-29 22:14:48 +00:00
|
|
|
BIT32_SET(nbio->status_flags, NBIO_FLAG_IMAGE_SUPPORTS_RGBA);
|
|
|
|
|
2022-07-08 22:53:08 +00:00
|
|
|
if (!(image = (struct nbio_image_handle*)malloc(sizeof(*image))))
|
2019-05-22 02:54:37 +00:00
|
|
|
{
|
|
|
|
free(nbio);
|
|
|
|
free(t);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nbio->path = strdup(fullpath);
|
2016-05-13 22:48:40 +00:00
|
|
|
|
2020-05-22 15:55:41 +00:00
|
|
|
image->type = image_texture_get_type(fullpath);
|
2019-05-28 11:55:31 +00:00
|
|
|
image->status = IMAGE_STATUS_WAIT;
|
2017-09-29 20:36:48 +00:00
|
|
|
image->processing_final_state = 0;
|
2019-05-28 11:55:31 +00:00
|
|
|
image->frame_duration = 0;
|
2017-09-29 20:36:48 +00:00
|
|
|
image->size = 0;
|
2019-06-05 16:04:23 +00:00
|
|
|
image->upscale_threshold = upscale_threshold;
|
2017-09-29 20:36:48 +00:00
|
|
|
image->handle = NULL;
|
|
|
|
|
|
|
|
image->ti.width = 0;
|
|
|
|
image->ti.height = 0;
|
|
|
|
image->ti.pixels = NULL;
|
2019-05-22 04:17:08 +00:00
|
|
|
/* TODO/FIXME - shouldn't we set this ? */
|
2017-09-29 20:36:48 +00:00
|
|
|
image->ti.supports_rgba = false;
|
2017-05-09 18:01:42 +00:00
|
|
|
|
2020-05-22 15:55:41 +00:00
|
|
|
switch (image->type)
|
2017-05-09 18:01:42 +00:00
|
|
|
{
|
2020-05-22 15:55:41 +00:00
|
|
|
case IMAGE_TYPE_PNG:
|
|
|
|
nbio->type = NBIO_TYPE_PNG;
|
|
|
|
break;
|
|
|
|
case IMAGE_TYPE_JPEG:
|
|
|
|
nbio->type = NBIO_TYPE_JPEG;
|
|
|
|
break;
|
|
|
|
case IMAGE_TYPE_BMP:
|
|
|
|
nbio->type = NBIO_TYPE_BMP;
|
|
|
|
break;
|
|
|
|
case IMAGE_TYPE_TGA:
|
|
|
|
nbio->type = NBIO_TYPE_TGA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nbio->type = NBIO_TYPE_NONE;
|
|
|
|
break;
|
2017-05-09 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 20:36:48 +00:00
|
|
|
nbio->data = (struct nbio_image_handle*)image;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2017-05-09 05:13:47 +00:00
|
|
|
t->state = nbio;
|
|
|
|
t->handler = task_file_load_handler;
|
|
|
|
t->cleanup = task_image_load_free;
|
|
|
|
t->callback = cb;
|
|
|
|
t->user_data = user_data;
|
2016-05-10 05:54:47 +00:00
|
|
|
|
2017-05-14 18:43:39 +00:00
|
|
|
task_queue_push(t);
|
2016-05-10 06:28:48 +00:00
|
|
|
|
2016-05-10 05:54:47 +00:00
|
|
|
return true;
|
|
|
|
}
|