2 * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
3 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@freebsd.org>
4 * Copyright (c) 1999 Dag-Erling Coïdan Smørgrav
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/linker.h>
37 #include <sys/module.h>
40 #include <dev/fb/fbreg.h>
41 #include <dev/fb/splashreg.h>
43 static int splash_mode = -1;
44 static int splash_on = FALSE;
46 static int pcx_start(video_adapter_t *adp);
47 static int pcx_end(video_adapter_t *adp);
48 static int pcx_splash(video_adapter_t *adp, int on);
49 static int pcx_init(void *data, int sdepth);
50 static int pcx_draw(video_adapter_t *adp);
52 static splash_decoder_t pcx_decoder = {
57 .data_type = SPLASH_IMAGE,
60 SPLASH_DECODER(splash_pcx, pcx_decoder);
74 pcx_start(video_adapter_t *adp)
76 static int modes[] = {
86 if (pcx_decoder.data == NULL ||
87 pcx_decoder.data_size <= 0 ||
88 pcx_init(pcx_decoder.data, pcx_decoder.data_size))
92 printf("splash_pcx: image good:\n"
97 pcx_info.width, pcx_info.height,
98 pcx_info.bpp, pcx_info.planes);
100 for (i = 0; modes[i] >= 0; ++i) {
101 if (vidd_get_info(adp, modes[i], &info) != 0)
104 printf("splash_pcx: considering mode %d:\n"
110 info.vi_width, info.vi_height,
111 info.vi_depth, info.vi_planes);
112 if (info.vi_width >= pcx_info.width
113 && info.vi_height >= pcx_info.height
114 && info.vi_depth == pcx_info.bpp
115 && info.vi_planes == pcx_info.planes)
119 splash_mode = modes[i];
120 if (splash_mode == -1)
123 printf("splash_pcx: selecting mode %d\n", splash_mode);
128 pcx_end(video_adapter_t *adp)
135 pcx_splash(video_adapter_t *adp, int on)
139 if (vidd_set_mode(adp, splash_mode) || pcx_draw(adp))
161 uint8_t colormap[48];
170 #define MAXSCANLINE 1024
173 pcx_init(void *data, int size)
175 const struct pcx_header *hdr = data;
177 if (size < 128 + 1 + 1 + 768 ||
178 hdr->manufactor != 10 ||
180 hdr->encoding != 1 ||
183 hdr->bpsl > MAXSCANLINE ||
184 ((uint8_t *)data)[size - 769] != 12) {
185 printf("splash_pcx: invalid PCX image\n");
188 pcx_info.width = hdr->xmax - hdr->xmin + 1;
189 pcx_info.height = hdr->ymax - hdr->ymin + 1;
190 pcx_info.bpsl = hdr->bpsl;
191 pcx_info.bpp = hdr->bpp;
192 pcx_info.planes = hdr->nplanes;
193 pcx_info.zlen = size - (128 + 1 + 768);
194 pcx_info.zdata = (uint8_t *)data + 128;
195 pcx_info.palette = (uint8_t *)data + size - 768;
200 pcx_draw(video_adapter_t *adp)
203 int swidth, sheight, sbpsl, sdepth, splanes;
204 int banksize, origin;
205 int c, i, j, pos, scan, x, y;
206 uint8_t line[MAXSCANLINE];
208 if (pcx_info.zlen < 1)
211 vidd_load_palette(adp, pcx_info.palette);
213 vidmem = (uint8_t *)adp->va_window;
214 swidth = adp->va_info.vi_width;
215 sheight = adp->va_info.vi_height;
216 sbpsl = adp->va_line_width;
217 sdepth = adp->va_info.vi_depth;
218 splanes = adp->va_info.vi_planes;
219 banksize = adp->va_window_size;
221 for (origin = 0; origin < sheight*sbpsl; origin += banksize) {
222 vidd_set_win_org(adp, origin);
223 bzero(vidmem, banksize);
226 x = (swidth - pcx_info.width) / 2;
227 y = (sheight - pcx_info.height) / 2;
230 while (pos > banksize) {
234 vidd_set_win_org(adp, origin);
236 for (scan = i = 0; scan < pcx_info.height; ++scan, ++y, pos += sbpsl) {
237 for (j = 0; j < pcx_info.bpsl && i < pcx_info.zlen; ++i) {
238 if ((pcx_info.zdata[i] & 0xc0) == 0xc0) {
239 c = pcx_info.zdata[i++] & 0x3f;
240 if (i >= pcx_info.zlen)
245 if (j + c > pcx_info.bpsl)
248 line[j++] = pcx_info.zdata[i];
251 if (pos > banksize) {
254 vidd_set_win_org(adp, origin);
257 if (pos + pcx_info.width > banksize) {
258 /* scanline crosses bank boundary */
260 bcopy(line, vidmem + pos, j);
263 vidd_set_win_org(adp, origin);
264 bcopy(line + j, vidmem, pcx_info.width - j);
266 bcopy(line, vidmem + pos, pcx_info.width);