xref: /haiku/src/system/boot/platform/generic/video_splash.cpp (revision c2f0a314a012bea8e4ebb35b8ce9e1a85c798727)
1 /*
2  * Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de.
3  * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>
4  * Copyright 2008, Philippe Saint-Pierre <stpere@gmail.com>
5  * Distributed under the terms of the MIT License.
6  */
7 
8 
9 #include <arch/cpu.h>
10 #include <boot/stage2.h>
11 #include <boot/platform.h>
12 #include <boot/menu.h>
13 #include <boot/kernel_args.h>
14 #include <boot/platform/generic/video.h>
15 #include <boot/images.h>
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 
22 //#define TRACE_VIDEO
23 #ifdef TRACE_VIDEO
24 #	define TRACE(x) dprintf x
25 #else
26 #	define TRACE(x) ;
27 #endif
28 
29 
30 extern "C" status_t
31 video_display_splash(addr_t frameBuffer)
32 {
33 	if (!gKernelArgs.frame_buffer.enabled)
34 		return B_NO_INIT;
35 
36 	// clear the video memory
37 	memset((void *)frameBuffer, 0,
38 		gKernelArgs.frame_buffer.physical_buffer.size);
39 
40 	uint8 *uncompressedLogo = NULL;
41 	switch (gKernelArgs.frame_buffer.depth) {
42 		case 8:
43 			platform_set_palette(k8BitPalette);
44 			uncompressedLogo = (uint8 *)kernel_args_malloc(kSplashLogoWidth
45 				* kSplashLogoHeight);
46 			if (uncompressedLogo == NULL)
47 				return B_NO_MEMORY;
48 			uncompress_8bit_RLE(kSplashLogo8BitCompressedImage,
49 				uncompressedLogo);
50 		break;
51 		default:
52 			uncompressedLogo = (uint8 *)kernel_args_malloc(kSplashLogoWidth
53 				* kSplashLogoHeight * 3);
54 			if (uncompressedLogo == NULL)
55 				return B_NO_MEMORY;
56 			uncompress_24bit_RLE(kSplashLogo24BitCompressedImage,
57 				uncompressedLogo);
58 		break;
59 	}
60 
61 	// TODO: support 4-bit indexed version of the images!
62 
63 	// render splash logo
64 	uint16 iconsHalfHeight = kSplashIconsHeight / 2;
65 
66 	int width = min_c(kSplashLogoWidth, gKernelArgs.frame_buffer.width);
67 	int height = min_c(kSplashLogoHeight + iconsHalfHeight,
68 		gKernelArgs.frame_buffer.height);
69 	int placementX = max_c(0, min_c(100, kSplashLogoPlacementX));
70 	int placementY = max_c(0, min_c(100, kSplashLogoPlacementY));
71 
72 	int x = (gKernelArgs.frame_buffer.width - width) * placementX / 100;
73 	int y = (gKernelArgs.frame_buffer.height - height) * placementY / 100;
74 
75 	height = min_c(kSplashLogoHeight, gKernelArgs.frame_buffer.height);
76 	switch (gKernelArgs.frame_buffer.depth) {
77 		case 8:
78 			break;
79 	}
80 	video_blit_image(frameBuffer, uncompressedLogo, width, height,
81 		kSplashLogoWidth, x, y);
82 
83 	kernel_args_free(uncompressedLogo);
84 
85 	const uint8* lowerHalfIconImage;
86 
87 	switch (gKernelArgs.frame_buffer.depth) {
88 		case 8:
89 			// pointer into the lower half of the icons image data
90 			gKernelArgs.boot_splash
91 				= (uint8 *)kernel_args_malloc(kSplashIconsWidth
92 					* kSplashIconsHeight);
93 			if (gKernelArgs.boot_splash == NULL)
94 				return B_NO_MEMORY;
95 			uncompress_8bit_RLE(kSplashIcons8BitCompressedImage,
96 				gKernelArgs.boot_splash );
97 			lowerHalfIconImage = gKernelArgs.boot_splash
98 				+ (kSplashIconsWidth * iconsHalfHeight);
99 		break;
100 		default:
101 			// pointer into the lower half of the icons image data
102 			gKernelArgs.boot_splash
103 				= (uint8 *)kernel_args_malloc(kSplashIconsWidth
104 					* kSplashIconsHeight * 3);
105 			if (gKernelArgs.boot_splash == NULL)
106 				return B_NO_MEMORY;
107 			uncompress_24bit_RLE(kSplashIcons24BitCompressedImage,
108 				gKernelArgs.boot_splash );
109 			lowerHalfIconImage = gKernelArgs.boot_splash
110 				+ (kSplashIconsWidth * iconsHalfHeight) * 3;
111 		break;
112 	}
113 
114 	// render initial (grayed out) icons
115 	// the grayed out version is the lower half of the icons image
116 
117 	width = min_c(kSplashIconsWidth, gKernelArgs.frame_buffer.width);
118 	height = min_c(kSplashLogoHeight + iconsHalfHeight,
119 		gKernelArgs.frame_buffer.height);
120 	placementX = max_c(0, min_c(100, kSplashIconsPlacementX));
121 	placementY = max_c(0, min_c(100, kSplashIconsPlacementY));
122 
123 	x = (gKernelArgs.frame_buffer.width - width) * placementX / 100;
124 	y = kSplashLogoHeight + (gKernelArgs.frame_buffer.height - height)
125 		* placementY / 100;
126 
127 	height = min_c(iconsHalfHeight, gKernelArgs.frame_buffer.height);
128 	video_blit_image(frameBuffer, lowerHalfIconImage, width, height,
129 		kSplashIconsWidth, x, y);
130 	return B_OK;
131 }
132 
133