2018-01-27 12:45:26 (UTC-02:00)
Marcel Rodrigues <marcelgmr@gmail.com>
Write partial byte iif offset % 8 != 0. The function end_key() flushes the last non-empty sub-block in a block. The length of this sub-block depends on whether there are bits waiting to fill up a temporary byte. If gif->offset is a multiple of 8, then all bits were already packed into bytes and written to gif->buffer. Otherwise, there are 8 - gif->offset % 8 bits that need to be written in the buffer, adding one byte to the sub-block.
diff --git a/gifenc.c b/gifenc.c index 9a35203..6403152 100644 --- a/gifenc.c +++ b/gifenc.c @@ -166,7 +166,8 @@ end_key(ge_GIF *gif) { int byte_offset; byte_offset = gif->offset / 8; - gif->buffer[byte_offset] = gif->partial & 0xFF; + if (gif->offset % 8) + gif->buffer[byte_offset++] = gif->partial & 0xFF; write(gif->fd, (uint8_t []) {byte_offset}, 1); write(gif->fd, gif->buffer, byte_offset); write(gif->fd, "\0", 1);