Skip to content

Commit d37d161

Browse files
committed
tasks/translation: delete unreachable BMP request-side branch
http_translate() opened with bool TRANSLATE_USE_BMP = false; as a local variable that was never assigned anywhere else in the tree, then branched on it: if (TRANSLATE_USE_BMP) { /* build a BMP blob in memory, base64 it, send */ } else { /* PNG encode via rpng_save_image_bgr24_string */ } The if-branch has been unreachable since the variable was introduced. The else-branch is the one that has actually been running in production for every translation-service request. Delete the dead branch, lift the surviving PNG encode out of the pointless else, localise the 'pitch' temporary into the one block that uses it, and drop the now-unused 'TRANSLATE_USE_BMP' declaration. The include of <formats/rbmp.h> was pulled in solely for the form_bmp_header call inside the dead branch; nothing else in this file uses the rbmp API (the response-side BMP parsing at line 411 does raw byte-offset reads of the BMP header, not rbmp API calls), so drop that include too. Keeps the variable name 'bmp_buffer' / 'bmp64_buffer' / 'bmp64_len' as-is - they are historical misnomers (the buffer holds PNG bytes, not BMP) but renaming them is pure churn and would conflict with other patches in flight. No behaviour change: only the live branch was reachable before, and it is what remains. Note: the response-side PNG path in handle_translation_response has its own copy-elimination opportunity (a per-pixel strip-alpha loop that could be folded into the scaler pass), but the scaler does not currently support ARGB8888 -> RGB565 as either a direct pixconv or via the full-pipeline path (see libretro-common/gfx/scaler/scaler.c lines 150-167 and 239-263), so replacing the intermediate BGR24 buffer would break the RGB565-core code path. That refactor needs either a new conv_argb8888_rgb565 entry in the scaler or a two-pass approach and is deferred to a separate commit.
1 parent 1759e1b commit d37d161

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

tasks/task_translation.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#endif
2727

2828
#include <encodings/base64.h>
29-
#include <formats/rbmp.h>
3029
#include <formats/rpng.h>
3130
#include <formats/rjson.h>
3231
#include <gfx/scaler/pixconv.h>
@@ -1200,14 +1199,12 @@ static bool http_translate(
12001199
void *userdata)
12011200
{
12021201
uint8_t *bmp_buffer = NULL;
1203-
size_t pitch;
12041202
uint64_t buffer_bytes = 0;
12051203
char *bmp64_buffer = NULL;
12061204
rjsonwriter_t *jsonwriter = NULL;
12071205
const char *json_buffer = NULL;
12081206
http_translate_ctx_t *ctx = NULL;
12091207
int bmp64_len = 0;
1210-
bool TRANSLATE_USE_BMP = false;
12111208
bool success = false;
12121209
settings_t *settings = config_get_ptr();
12131210
video_driver_state_t *video_st = video_state_get_ptr();
@@ -1218,28 +1215,17 @@ static bool http_translate(
12181215
access_state_t *access_st = access_state_get_ptr();
12191216
#endif
12201217

1221-
if (TRANSLATE_USE_BMP)
1222-
{
1223-
/*
1224-
At this point, we should have a screenshot in the buffer,
1225-
so allocate an array to contain the BMP image along with
1226-
the BMP header as bytes, and then covert that to a
1227-
b64 encoded array for transport in JSON.
1228-
*/
1229-
if (!(bmp_buffer = (uint8_t*)malloc(width * height * 3 + 54)))
1230-
goto finish;
1231-
1232-
form_bmp_header(bmp_buffer, width, height, false);
1233-
memcpy(bmp_buffer + 54,
1234-
bit24_image,
1235-
width * height * 3 * sizeof(uint8_t));
1236-
buffer_bytes = sizeof(uint8_t) * (width * height * 3 + 54);
1237-
}
1238-
else
1218+
/* Encode the framebuffer screenshot as a PNG (BGR24) for the
1219+
* translation service. rpng_save_image_bgr24_string handles the
1220+
* vertical flip via negative stride + bottom-row pointer, so no
1221+
* intermediate buffer is needed. Variable is named bmp_buffer for
1222+
* historical reasons (the request format was originally a BMP
1223+
* blob gated on an always-false TRANSLATE_USE_BMP local; that
1224+
* branch has been deleted as dead code). */
12391225
{
1240-
pitch = width * 3;
1226+
size_t pitch = width * 3;
12411227
bmp_buffer = rpng_save_image_bgr24_string(
1242-
bit24_image + width * (height-1) * 3,
1228+
bit24_image + width * (height - 1) * 3,
12431229
width, height, (signed)-pitch, &buffer_bytes);
12441230
}
12451231

0 commit comments

Comments
 (0)