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.
30 * $FreeBSD: src/sys/modules/splash/pcx/splash_pcx.c,v 1.4 1999/08/28 00:47:39 peter Exp $
31 * $DragonFly: src/sys/dev/video/fb/pcx/splash_pcx.c,v 1.3 2003/08/15 08:32:32 dillon Exp $
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/linker.h>
40 #include <dev/video/fb/fbreg.h>
41 #include <dev/video/fb/splashreg.h>
43 #define FADE_TIMEOUT 300 /* sec */
45 static int splash_mode = -1;
46 static int splash_on = FALSE;
48 static int pcx_start(video_adapter_t *adp);
49 static int pcx_end(video_adapter_t *adp);
50 static int pcx_splash(video_adapter_t *adp, int on);
51 static int pcx_init(const char *data, int sdepth);
52 static int pcx_draw(video_adapter_t *adp);
54 static splash_decoder_t pcx_decoder = {
55 "splash_pcx", pcx_start, pcx_end, pcx_splash, SPLASH_IMAGE,
58 SPLASH_DECODER(splash_pcx, pcx_decoder);
62 int width, height, bpsl;
63 int bpp, planes, zlen;
64 const u_char *zdata, *palette;
68 pcx_start(video_adapter_t *adp)
70 static int modes[] = {
80 if (pcx_decoder.data == NULL
81 || pcx_decoder.data_size <= 0
82 || pcx_init((u_char *)pcx_decoder.data, pcx_decoder.data_size))
86 printf("splash_pcx: image good:\n"
91 pcx_info.width, pcx_info.height,
92 pcx_info.bpp, pcx_info.planes);
94 for (i = 0; modes[i] >= 0; ++i) {
95 if (get_mode_info(adp, modes[i], &info) != 0)
98 printf("splash_pcx: considering mode %d:\n"
104 info.vi_width, info.vi_height,
105 info.vi_depth, info.vi_planes);
106 if (info.vi_width >= pcx_info.width
107 && info.vi_height >= pcx_info.height
108 && info.vi_depth == pcx_info.bpp
109 && info.vi_planes == pcx_info.planes)
113 splash_mode = modes[i];
114 if (splash_mode == -1)
117 printf("pcx_splash: selecting mode %d\n", splash_mode);
122 pcx_end(video_adapter_t *adp)
129 pcx_splash(video_adapter_t *adp, int on)
133 if (set_video_mode(adp, splash_mode) || pcx_draw(adp))
149 u_short xmin, ymin, xmax, ymax;
156 u_short hsize, vsize;
159 #define MAXSCANLINE 1024
162 pcx_init(const char *data, int size)
164 const struct pcxheader *hdr;
166 hdr = (const struct pcxheader *)data;
168 if (size < 128 + 1 + 1 + 768
169 || hdr->manufactor != 10
171 || hdr->encoding != 1
174 || hdr->bpsl > MAXSCANLINE
175 || data[size-769] != 12) {
176 printf("splash_pcx: invalid PCX image\n");
179 pcx_info.width = hdr->xmax - hdr->xmin + 1;
180 pcx_info.height = hdr->ymax - hdr->ymin + 1;
181 pcx_info.bpsl = hdr->bpsl;
182 pcx_info.bpp = hdr->bpp;
183 pcx_info.planes = hdr->nplanes;
184 pcx_info.zlen = size - (128 + 1 + 768);
185 pcx_info.zdata = data + 128;
186 pcx_info.palette = data + size - 768;
191 pcx_draw(video_adapter_t *adp)
194 int swidth, sheight, sbpsl, sdepth, splanes;
195 int banksize, origin;
196 int c, i, j, pos, scan, x, y;
197 u_char line[MAXSCANLINE];
199 if (pcx_info.zlen < 1)
202 load_palette(adp, pcx_info.palette);
204 vidmem = (u_char *)adp->va_window;
205 swidth = adp->va_info.vi_width;
206 sheight = adp->va_info.vi_height;
207 sbpsl = adp->va_line_width;
208 sdepth = adp->va_info.vi_depth;
209 splanes = adp->va_info.vi_planes;
210 banksize = adp->va_window_size;
212 for (origin = 0; origin < sheight*sbpsl; origin += banksize) {
213 set_origin(adp, origin);
214 bzero(vidmem, banksize);
217 x = (swidth - pcx_info.width) / 2;
218 y = (sheight - pcx_info.height) / 2;
221 while (pos > banksize) {
225 set_origin(adp, origin);
227 for (scan = i = 0; scan < pcx_info.height; ++scan, ++y, pos += sbpsl) {
228 for (j = 0; j < pcx_info.bpsl && i < pcx_info.zlen; ++i) {
229 if ((pcx_info.zdata[i] & 0xc0) == 0xc0) {
230 c = pcx_info.zdata[i++] & 0x3f;
231 if (i >= pcx_info.zlen)
236 if (j + c > pcx_info.bpsl)
239 line[j++] = pcx_info.zdata[i];
242 if (pos > banksize) {
245 set_origin(adp, origin);
248 if (pos + pcx_info.width > banksize) {
249 /* scanline crosses bank boundary */
251 bcopy(line, vidmem + pos, j);
254 set_origin(adp, origin);
255 bcopy(line + j, vidmem, pcx_info.width - j);
257 bcopy(line, vidmem + pos, pcx_info.width);