Commit 25eb5467 authored by Georges Basile Stavracas Neto's avatar Georges Basile Stavracas Neto
Browse files

stream-deck: Adjust texture uploading of Original (gen1)

We must send at most half of the BMP image in the first package,
then send the other half. If we send more than half of the image
in the first package - which should always happen with the current
code - Stream Deck Original (gen1) ignored the extra stuff we sent,
and that makes the image look corrupt.

Fix that
parent 863dfe16
Pipeline #385275 passed with stage
in 2 minutes and 23 seconds
......@@ -533,6 +533,7 @@ set_button_texture_original (BsStreamDeck *self,
const size_t package_size = 8191;
const size_t header_size = 16;
size_t bytes_remaining;
size_t report_size;
size_t buffer_size;
size_t page;
......@@ -541,6 +542,15 @@ set_button_texture_original (BsStreamDeck *self,
if (!bs_icon_renderer_convert_texture (self->icon_renderer, texture, (char **) &buffer, &buffer_size, error))
BS_RETURN (FALSE);
report_size = buffer_size / 2;
/*
* BMP images have fixed byte sizes for a given width and height, and
* in this case, a 72x72 BMP image should have exactly 15606 bytes.
*/
g_assert (buffer_size == 15606);
g_assert (package_size - header_size >= report_size);
payload = g_malloc (sizeof (unsigned char) * package_size);
payload[0] = 0x02;
payload[1] = 0x01;
......@@ -567,12 +577,12 @@ set_button_texture_original (BsStreamDeck *self,
size_t chunk_size;
size_t bytes_sent;
chunk_size = MIN (bytes_remaining, package_size - header_size);
chunk_size = MIN (bytes_remaining, report_size);
payload[2] = page + 1;
payload[4] = chunk_size == bytes_remaining ? 1 : 0;
bytes_sent = page * (package_size - header_size);
bytes_sent = page * report_size;
memcpy (payload + header_size, buffer + bytes_sent, chunk_size);
padding_size = package_size - header_size - chunk_size;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment