commit f36428b8423044e87ca61ec0c92e18e7b0189a2d
parent f7f433a8843945a41af0904de22ef0b98e2cad88
Author: phoebos <ben@bvnf.space>
Date: Wed, 1 Sep 2021 19:04:46 +0100
cast to uint16_t for LSB values instead of mess
I have to say, it's neat how C can do this.
Diffstat:
M | gif.c | | | 18 | ++++++++++++++---- |
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/gif.c b/gif.c
@@ -8,6 +8,7 @@
#include <math.h>
#include <fcntl.h>
#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -19,8 +20,8 @@
typedef unsigned char rgb[3];
struct Gif {
char version[3]; /* 87a or 89a */
- int width;
- int height;
+ uint16_t width;
+ uint16_t height;
unsigned char flags; /* ABBBCDDD
A: global colour table [GCT] flag
B+1: colour resolution (bits per primary colour)
@@ -69,8 +70,17 @@ gif_decode(unsigned char *buf, size_t len){
fprintf(stderr, "GIF version %s, ", g.version);
buf += 3;
len -= 3;
- g.width = *buf++ | *buf++ << 2;
- g.height = *buf++ | *buf++ << 2;
+
+ uint16_t *tmp;
+
+ tmp = (uint16_t *)buf;
+ g.width = *tmp;
+ buf += 2;
+
+ tmp = (uint16_t *)buf;
+ g.height = *tmp;
+ buf += 2;
+
fprintf(stderr, "%d x %d\n", g.width, g.height);
g.flags = *buf++;