summaryrefslogtreecommitdiff
path: root/recipes/netsurf/files/libnsgif-strict-aliasing.patch
blob: 4fe913c4917ed3cdfd2f1c844cf2c368d77fc566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
http://source.netsurf-browser.org/?view=rev&revision=9027
Stop utterly insane palette entry population.
Palette entries are always ABGR, regardless of platform endianness.
This change probably breaks big-endian platforms which, under the old approach,
had palette entries of the form RGBA (assuming I understood the code correctly).

http://source.netsurf-browser.org/?view=rev&revision=9138
Fix palette entry population some more. Hopefully, it's completely endian
agnostic now and still builds with GCC 4.4

--- libnsgif/src/libnsgif.c	2009/03/29 01:43:27	6984
+++ libnsgif/src/libnsgif.c	2009/08/09 22:24:14	9138
@@ -319,19 +319,34 @@
 				return GIF_INSUFFICIENT_DATA;
 			}
 			for (index = 0; index < gif->colour_table_size; index++) {
-				char colour[] = {0, 0, 0, (char)0xff};
-				colour[0] = gif_data[0];
-				colour[1] = gif_data[1];
-				colour[2] = gif_data[2];
-				gif->global_colour_table[index] = *((int *) (void *) colour);
+				/* Gif colour map contents are r,g,b.
+				 *
+				 * We want to pack them bytewise into the 
+				 * colour table, such that the red component
+				 * is in byte 0 and the alpha component is in
+				 * byte 3.
+				 */
+				unsigned char *entry = (unsigned char *) &gif->
+						global_colour_table[index];
+
+				entry[0] = gif_data[0];	/* r */
+				entry[1] = gif_data[1];	/* g */
+				entry[2] = gif_data[2];	/* b */
+				entry[3] = 0xff;	/* a */
+
 				gif_data += 3;
 			}
 			gif->buffer_position = (gif_data - gif->gif_data);
 		} else {
 			/*	Create a default colour table with the first two colours as black and white
 			*/
-			gif->global_colour_table[0] = 0xff000000;
-			gif->global_colour_table[1] = 0xffffffff;
+			unsigned int *entry = gif->global_colour_table;
+
+			entry[0] = 0x00000000;
+			/* Force Alpha channel to opaque */
+			((unsigned char *) entry)[3] = 0xff;
+
+			entry[1] = 0xffffffff;
 		}
 	}
 
@@ -844,11 +859,21 @@
 		colour_table = gif->local_colour_table;
 		if (!clear_image) {
 			for (index = 0; index < colour_table_size; index++) {
-				char colour[] = {0, 0, 0, (char)0xff};
-				colour[0] = gif_data[0];
-				colour[1] = gif_data[1];
-				colour[2] = gif_data[2];
-				colour_table[index] = *((int *) (void *) colour);
+				/* Gif colour map contents are r,g,b.
+				 *
+				 * We want to pack them bytewise into the 
+				 * colour table, such that the red component
+				 * is in byte 0 and the alpha component is in
+				 * byte 3.
+				 */
+				unsigned char *entry = 
+					(unsigned char *) &colour_table[index];
+
+				entry[0] = gif_data[0];	/* r */
+				entry[1] = gif_data[1];	/* g */
+				entry[2] = gif_data[2];	/* b */
+				entry[3] = 0xff;	/* a */
+
 				gif_data += 3;
 			}
 		} else {