summaryrefslogtreecommitdiff
path: root/packages/u-boot/u-boot-1.1.4/at32stk1000/cmd-bmp-add-gzip-compressed-bmp.patch
blob: 47da73ef5e7f472d200bbe6853c2252d42d3e8af (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
83
84
85
86
87
88
89
90
Index: u-boot-orig/common/cmd_bmp.c
===================================================================
--- u-boot-orig.orig/common/cmd_bmp.c	2007-01-05 14:50:55.000000000 +0100
+++ u-boot-orig/common/cmd_bmp.c	2007-01-05 15:59:21.000000000 +0100
@@ -176,13 +176,83 @@
  */
 static int bmp_display(ulong addr, int x, int y)
 {
+	int ret;
+#ifdef CONFIG_VIDEO_BMP_GZIP
+	bmp_image_t *bmp = (bmp_image_t *)addr;
+	unsigned char *dst = NULL;
+	ulong len;
+
+	if (!((bmp->header.signature[0]=='B') &&
+	      (bmp->header.signature[1]=='M'))) {
+
+		/*
+		 * Decompress bmp image
+		 */
+		len = CFG_VIDEO_LOGO_MAX_SIZE;
+		dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE);
+		if (dst == NULL) {
+			printf("Error: malloc in gunzip failed!\n");
+			return(1);
+		}
+		if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)addr, &len) != 0) {
+			free(dst);
+			printf("There is no valid bmp file at the given address\n");
+			return(1);
+		}
+		if (len == CFG_VIDEO_LOGO_MAX_SIZE) {
+			printf("Image could be truncated "
+					"(increase CFG_VIDEO_LOGO_MAX_SIZE)!\n");
+		}
+
+		/*
+		 * Set addr to decompressed image
+		 */
+		bmp = (bmp_image_t *)dst;
+
+		/*
+		 * Check for bmp mark 'BM'
+		 */
+		if (!((bmp->header.signature[0] == 'B') &&
+		      (bmp->header.signature[1] == 'M'))) {
+			printf("There is no valid bmp file at the given address\n");
+			free(dst);
+			return(1);
+		}
+	}
+
+	if (dst) {
+		addr = (ulong)dst;
+	}
+#endif /* CONFIG_VIDEO_BMP_GZIP */
+
 #if defined(CONFIG_LCD)
 	extern int lcd_display_bitmap (ulong, int, int);
 
-	return (lcd_display_bitmap (addr, x, y));
+	ret = lcd_display_bitmap (addr, x, y);
+	if (ret) {
+#ifdef CONFIG_VIDEO_BMP_GZIP
+		free(dst);
+#endif
+		return ret;
+	}
+#ifdef CONFIG_VIDEO_BMP_GZIP
+		free(dst);
+#endif
+	return 0;
+
 #elif defined(CONFIG_VIDEO)
 	extern int video_display_bitmap (ulong, int, int);
-	return (video_display_bitmap (addr, x, y));
+	ret = video_display_bitmap (addr, x, y);
+	if (ret) {
+#ifdef CONFIG_VIDEO_BMP_GZIP
+		free(dst);
+#endif
+		return ret;
+	}
+#ifdef CONFIG_VIDEO_BMP_GZIP
+		free(dst);
+#endif
+	return 0;
 #else
 # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
 #endif