This commit is contained in:
twinaphex 2019-08-21 21:09:19 +02:00
parent ccc6d65c43
commit 95637cfe08

View File

@ -218,17 +218,19 @@ static void handle_translation_cb(
/* Get the video frame dimensions reference */
video_driver_cached_frame_get(&dummy_data, &width, &height, &pitch);
/* Get image data (24 bit), and conver to the emulated pixel format */
image_width = ((uint32_t) ((uint8_t) raw_bmp_data[21]) << 24) +
((uint32_t) ((uint8_t) raw_bmp_data[20]) << 16) +
((uint32_t) ((uint8_t) raw_bmp_data[19]) << 8) +
((uint32_t) ((uint8_t) raw_bmp_data[18]) << 0);
/* Get image data (24 bit), and convert to the emulated pixel format */
image_width =
((uint32_t) ((uint8_t)raw_bmp_data[21]) << 24) +
((uint32_t) ((uint8_t)raw_bmp_data[20]) << 16) +
((uint32_t) ((uint8_t)raw_bmp_data[19]) << 8) +
((uint32_t) ((uint8_t)raw_bmp_data[18]) << 0);
image_height = ((uint32_t) ((uint8_t) raw_bmp_data[25]) << 24) +
((uint32_t) ((uint8_t) raw_bmp_data[24]) << 16) +
((uint32_t) ((uint8_t) raw_bmp_data[23]) << 8) +
((uint32_t) ((uint8_t) raw_bmp_data[22]) << 0);
raw_image_data = raw_bmp_data+54*sizeof(uint8_t);
image_height =
((uint32_t) ((uint8_t)raw_bmp_data[25]) << 24) +
((uint32_t) ((uint8_t)raw_bmp_data[24]) << 16) +
((uint32_t) ((uint8_t)raw_bmp_data[23]) << 8) +
((uint32_t) ((uint8_t)raw_bmp_data[22]) << 0);
raw_image_data = raw_bmp_data + 54 * sizeof(uint8_t);
scaler = (struct scaler_ctx*)calloc(1, sizeof(struct scaler_ctx));
if (!scaler)
@ -256,17 +258,17 @@ static void handle_translation_cb(
if (video_driver_get_pixel_format() == RETRO_PIXEL_FORMAT_XRGB8888)
{
raw_output_data = (uint8_t*)malloc(width*height*4*sizeof(uint8_t));
raw_output_data = (uint8_t*)malloc(width * height * 4 * sizeof(uint8_t));
scaler->out_fmt = SCALER_FMT_ARGB8888;
pitch = width*4;
scaler->out_stride = width*4;
pitch = width * 4;
scaler->out_stride = width * 4;
}
else
{
raw_output_data = (uint8_t*)malloc(width*height*2*sizeof(uint8_t));
raw_output_data = (uint8_t*)malloc(width * height * 2 * sizeof(uint8_t));
scaler->out_fmt = SCALER_FMT_RGB565;
pitch = width*2;
scaler->out_stride = width*1;
pitch = width * 2;
scaler->out_stride = width * 1;
}
if (!raw_output_data)
@ -279,10 +281,10 @@ static void handle_translation_cb(
scaler->out_height = height;
scaler->scaler_type = SCALER_TYPE_POINT;
scaler_ctx_gen_filter(scaler);
scaler->in_stride = -1*width*3;
scaler->in_stride = -1 * width * 3;
scaler_ctx_scale_direct(scaler, raw_output_data,
(uint8_t*)raw_image_data+(image_height-1)*width*3);
(uint8_t*)raw_image_data + (image_height - 1) * width * 3);
video_driver_frame(raw_output_data, image_width, image_height, pitch);
}
@ -349,15 +351,6 @@ finish:
free(raw_output_data);
}
static void call_translation_server(const char* body)
{
settings_t *settings = config_get_ptr();
RARCH_LOG("Server URL: %s\n", settings->arrays.ai_service_url);
task_push_http_post_transfer(settings->arrays.ai_service_url,
body, true, NULL, handle_translation_cb, NULL);
}
bool run_translation_service(void)
{
/*
@ -387,12 +380,15 @@ bool run_translation_service(void)
the "image" field also as a base64 encoded, 24bit-BMP.
*/
struct video_viewport vp;
uint8_t header[54];
size_t pitch;
unsigned width, height;
const void *data = NULL;
uint8_t *bit24_image = NULL;
uint8_t *bit24_image_prev = NULL;
settings_t *settings = config_get_ptr();
enum retro_pixel_format pixel_format = video_driver_get_pixel_format();
struct scaler_ctx *scaler = (struct scaler_ctx*)
calloc(1, sizeof(struct scaler_ctx));
@ -403,9 +399,6 @@ bool run_translation_service(void)
char* json_buffer = NULL;
bool retval = false;
struct video_viewport vp;
uint8_t header[54];
int out_length = 0;
const char *rf1 = "{\"image\": \"";
const char *rf2 = "\"}\0";
@ -414,8 +407,10 @@ bool run_translation_service(void)
goto finish;
video_driver_cached_frame_get(&data, &width, &height, &pitch);
if (!data)
goto finish;
if (data == RETRO_HW_FRAME_BUFFER_VALID)
{
/*
@ -449,19 +444,19 @@ bool run_translation_service(void)
/* Rescale down to regular resolution */
#if 0
scaler->in_fmt = SCALER_FMT_BGR24;
scaler->in_width = vp.width;
scaler->in_height = vp.height;
scaler->in_fmt = SCALER_FMT_BGR24;
scaler->in_width = vp.width;
scaler->in_height = vp.height;
scaler->out_width = width;
scaler->out_height = height;
scaler->out_fmt = SCALER_FMT_BGR24;
scaler->out_width = width;
scaler->out_height = height;
scaler->out_fmt = SCALER_FMT_BGR24;
scaler->scaler_type = SCALER_TYPE_POINT;
scaler_ctx_gen_filter(scaler);
scaler->in_stride = vp.width*3;
scaler->out_stride = width*3;
scaler->in_stride = vp.width * 3;
scaler->out_stride = width * 3;
scaler_ctx_scale_direct(scaler, bit24_image, bit24_image_prev)
#endif
@ -472,7 +467,7 @@ bool run_translation_service(void)
}
else
{
bit24_image = (uint8_t*)malloc(width*height*3);
bit24_image = (uint8_t*)malloc(width * height * 3);
if (!bit24_image)
goto finish;
@ -503,8 +498,8 @@ bool run_translation_service(void)
}
/*
at this point, we should have a screenshot in the buffer, so allocate
an array to contain the bmp image along with the bmp header as bytes,
At this point, we should have a screenshot in the buffer, so allocate
an array to contain the BMP image along with the BMP header as bytes,
and then covert that to a b64 encoded array for transport in JSON.
*/
form_bmp_header(header, width, height, false);
@ -513,9 +508,9 @@ bool run_translation_service(void)
goto finish;
memcpy(bmp_buffer, header, 54*sizeof(uint8_t));
memcpy(bmp_buffer+54, bit24_image, width*height*3*sizeof(uint8_t));
memcpy(bmp_buffer+54, bit24_image, width * height * 3 * sizeof(uint8_t));
bmp64_buffer = base64((void *)bmp_buffer, (int)(width*height*3+54),
bmp64_buffer = base64((void *)bmp_buffer, (int)(width * height * 3 + 54),
&out_length);
if (!bmp64_buffer)
goto finish;
@ -529,7 +524,10 @@ bool run_translation_service(void)
memcpy(json_buffer+11, bmp64_buffer, (out_length)*sizeof(uint8_t));
memcpy(json_buffer+11+out_length, (const void*)rf2, 3*sizeof(uint8_t));
call_translation_server(json_buffer);
RARCH_LOG("Server URL: %s\n", settings->arrays.ai_service_url);
task_push_http_post_transfer(settings->arrays.ai_service_url,
json_buffer, true, NULL, handle_translation_cb, NULL);
error = false;
finish:
if (bit24_image_prev)