2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 #include <console/video_console.h>
33 #include <kdp/kdp_udp.h>
34 #include <kern/debug.h>
35 #include <mach/mach_time.h>
36 #include <sys/errno.h>
40 extern struct vc_info vinfo
;
41 extern boolean_t panicDialogDesired
;
43 #include "panic_image.c"
45 void panic_ui_initialize(const unsigned char * system_clut
);
46 int panic_dialog_set_image( const unsigned char * ptr
, unsigned int size
);
47 void panic_dialog_get_image( unsigned char ** ptr
, unsigned int * size
);
48 void draw_panic_dialog( void );
49 void panic_dialog_test( void );
51 static int panic_dialog_verify( const struct panicimage
* data
, unsigned int size
);
52 static int pixels_needed_to_blit_digit( int digit
);
53 static void blit_digit( int digit
);
54 static char * strnstr(const char * s
, const char * find
, size_t slen
);
55 static void dim_screen(void);
56 static void panic_blit_rect(unsigned int x
, unsigned int y
, unsigned int width
, unsigned int height
,
57 int transparent
, unsigned char * dataPtr
);
59 static int panic_info_x
;
60 static int panic_info_y
;
62 static const unsigned char * active_clut
= NULL
; /* This is a copy of the active clut */
64 static boolean_t panicDialogDrawn
= FALSE
;
66 static const struct panicimage
* panic_dialog
= NULL
; /* the active panic dialog */
67 static const unsigned char * panic_dialog_data
= NULL
; /* where the image data starts */
68 static const unsigned char * panic_dialog_clut
= NULL
; /* where the clut used for the image starts */
70 static unsigned char * curr_image_ptr
= NULL
; /* If NULL, the default panic dialog is active */
71 static unsigned int curr_image_size
= 0;
74 #define FONT_HEIGHT 16
75 static unsigned short rendered_font
[FONT_HEIGHT
][FONT_WIDTH
];
77 static char versionbuf
[20]; /* ####.###~###\0 */
79 #define isdigit(d) ((d) >= '0' && (d) <= '9')
81 #define CLUT_ENTRIES 256
82 #define CLUT_SIZE (CLUT_ENTRIES * 3)
86 * This routine sets up the default panic dialog
89 extern unsigned char iso_font
[];
90 extern const char version
[];
91 extern unsigned int panic_caller
;
94 panic_ui_initialize(const unsigned char * system_clut
)
99 panic_dialog_set_image( NULL
, 0 );
101 active_clut
= system_clut
;
103 strcpy(vstr
, "custom");
105 /* Convert xnu-####.###.obj~### into ####.###~### */
108 char * versionpos
= strnstr(version
, "xnu-", 20);
115 for (i
=0,len
=4;len
<20;len
++) {
116 if (isdigit(versionpos
[len
]) || versionpos
[len
] == '.') { /* extract ####.###. */
117 vstr
[i
++] = versionpos
[len
];
123 if ( versionpos
[len
-1] == '.' ) /* remove trailing period if present */
126 for (;len
<20;len
++) { /* skip to next digit if present */
127 if ( !isdigit(versionpos
[len
]) )
132 if ( versionpos
[len
-1] == '~' ) { /* extract ~### if present */
133 vstr
[i
++] = versionpos
[len
-1];
134 for (;len
<20;len
++) { /* extract ### */
135 if ( isdigit(versionpos
[len
]) ) {
136 vstr
[i
++] = versionpos
[len
];
147 strcpy(versionbuf
, vstr
);
153 panic_dialog_test( void )
155 boolean_t o_panicDialogDrawn
= panicDialogDrawn
;
156 boolean_t o_panicDialogDesired
= panicDialogDesired
;
157 unsigned int o_logPanicDataToScreen
= logPanicDataToScreen
;
158 unsigned int o_panic_caller
= panic_caller
;
159 unsigned int o_panicDebugging
= panicDebugging
;
162 panicDebugging
= TRUE
;
163 panic_caller
= (unsigned int) __builtin_return_address(0);
164 logPanicDataToScreen
= FALSE
;
165 panicDialogDesired
= TRUE
;
166 panicDialogDrawn
= FALSE
;
170 panicDebugging
= o_panicDebugging
;
171 panic_caller
= o_panic_caller
;
172 logPanicDataToScreen
= o_logPanicDataToScreen
;
173 panicDialogDesired
= o_panicDialogDesired
;
174 panicDialogDrawn
= o_panicDialogDrawn
;
179 draw_panic_dialog( void )
181 if (!panicDialogDrawn
&& panicDialogDesired
) {
182 if ( !logPanicDataToScreen
) {
184 int count
, nibble
, indx
;
185 struct ether_addr kdp_mac_addr
;
186 unsigned int panic_dialog_count
, ip_addr
;
187 char panic_num_chars
[13+8+1], mac_addr_chars
[17+1], ip_addr_chars
[15+1];
191 } panic_dialog_info
[3];
194 /* dim the screen 50% before putting up panic dialog */
197 /* set up to draw background box */
198 /* by locating where the upper left corner is placed */
200 pd_x
= (vinfo
.v_width
/2) - panic_dialog
->pd_width
/2;
201 pd_y
= (vinfo
.v_height
/2) - panic_dialog
->pd_height
/2;
203 /* draw panic dialog at pd_x/pd_y */
204 panic_blit_rect( pd_x
, pd_y
, panic_dialog
->pd_width
, panic_dialog
->pd_height
,
205 0, (unsigned char*) panic_dialog_data
);
207 panic_dialog_count
= 0; /* number of info items to display at the bottom of dialog */
209 if (panicDebugging
) {
215 * don't display the panic caller if it is 0
219 if ( panic_caller
!= 0 ) {
220 /* Calculate the pixels need to generate the panic number */
221 panic_dialog_info
[panic_dialog_count
].pixels
= 0;
223 for ( indx
=1, count
=0; count
< 13; count
++ ) {
224 if ( versionbuf
[count
] == '\0' )
227 panic_num_chars
[indx
++] = versionbuf
[count
];
228 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( versionbuf
[count
] );
231 panic_num_chars
[indx
++] = ':';
232 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( ':' );
234 for ( count
=8; count
!= 0; count
-- ) {
235 nibble
= (panic_caller
>> ((count
-1)<<2)) &0xF;
236 panic_num_chars
[indx
++] = nibble
;
237 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( nibble
);
240 panic_num_chars
[0] = indx
;
241 panic_dialog_info
[panic_dialog_count
].chars
= panic_num_chars
;
242 panic_dialog_count
++;
248 * if the mac address is not available, then use ff:ff:ff:ff:ff:ff
252 kdp_mac_addr
= kdp_get_mac_addr();
254 /* If no mac_addr has been set, then force to -1 */
255 if( ! (kdp_mac_addr
.ether_addr_octet
[0] || kdp_mac_addr
.ether_addr_octet
[1] || kdp_mac_addr
.ether_addr_octet
[2]
256 || kdp_mac_addr
.ether_addr_octet
[3] || kdp_mac_addr
.ether_addr_octet
[4] || kdp_mac_addr
.ether_addr_octet
[5])) {
257 for (count
= 0; count
< 6; count
++ )
258 kdp_mac_addr
.ether_addr_octet
[count
] = -1;
261 panic_dialog_info
[panic_dialog_count
].pixels
= 0;
263 for (indx
=1, count
=0; count
< 6; count
++ ) {
264 nibble
= (kdp_mac_addr
.ether_addr_octet
[count
] & 0xf0) >> 4;
265 mac_addr_chars
[indx
++] = nibble
;
266 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( nibble
);
268 nibble
= kdp_mac_addr
.ether_addr_octet
[count
] & 0xf;
269 mac_addr_chars
[indx
++] = nibble
;
270 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( nibble
);
273 mac_addr_chars
[indx
++] = ':';
274 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( ':' );
278 mac_addr_chars
[0] = indx
;
279 panic_dialog_info
[panic_dialog_count
].chars
= mac_addr_chars
;
280 panic_dialog_count
++;
285 * do not display the ip addresses if the machine isn't attachable.
286 * there's no sense in possibly confusing people.
289 if ( (ip_addr
= (unsigned int) ntohl(kdp_get_ip_address())) != 0 ) {
292 panic_dialog_info
[panic_dialog_count
].pixels
= 0;
294 for ( indx
=1, count
=0; count
< 4; count
++ ) {
295 nibble
= (ip_addr
& 0xff000000 ) >> 24;
297 d3
= (nibble
% 10) ; nibble
= nibble
/ 10;
298 d2
= (nibble
% 10) ; nibble
= nibble
/ 10;
302 ip_addr_chars
[indx
++] = d1
;
303 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( d1
);
306 ip_addr_chars
[indx
++] = d2
;
307 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( d2
);
309 ip_addr_chars
[indx
++] = d3
;
310 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( d3
);
313 ip_addr_chars
[indx
++] = '.';
314 panic_dialog_info
[panic_dialog_count
].pixels
+= pixels_needed_to_blit_digit( '.' );
318 ip_addr
= ip_addr
<< 8;
321 ip_addr_chars
[0] = indx
;
322 panic_dialog_info
[panic_dialog_count
].chars
= ip_addr_chars
;
323 panic_dialog_count
++;
327 /* vertical alignment for information to be displayed */
328 panic_info_y
= (vinfo
.v_height
/2) + panic_dialog
->pd_height
/2 - (panic_dialog
->pd_info_height
);
330 /* blit out all the information we gathered */
332 switch ( panic_dialog_count
) {
333 case 1 : /* one item is centered */
334 panic_info_x
= (vinfo
.v_width
/2) - (panic_dialog_info
[0].pixels
/2);
335 for (indx
=1; indx
< panic_dialog_info
[0].chars
[0]; indx
++)
336 blit_digit(panic_dialog_info
[0].chars
[indx
]);
340 case 2 : /* left centered and right centered */
341 x1
= ((panic_dialog
->pd_width
/2) - panic_dialog_info
[0].pixels
)/2;
342 panic_info_x
= ((vinfo
.v_width
/2) - (panic_dialog
->pd_width
/2)) + x1
;
344 for (indx
=1; indx
< panic_dialog_info
[0].chars
[0]; indx
++)
345 blit_digit(panic_dialog_info
[0].chars
[indx
]);
347 x2
= ((panic_dialog
->pd_width
/2) - panic_dialog_info
[1].pixels
)/2;
348 panic_info_x
= (vinfo
.v_width
/2) + x2
;
350 for (indx
=1; indx
< panic_dialog_info
[1].chars
[0]; indx
++)
351 blit_digit(panic_dialog_info
[1].chars
[indx
]);
355 case 3 : /* left centered, middle and right centered */
356 x1
= ((panic_dialog
->pd_width
/2) - panic_dialog_info
[0].pixels
- (panic_dialog_info
[1].pixels
/2))/2;
357 panic_info_x
= ((vinfo
.v_width
/2) - (panic_dialog
->pd_width
/2)) + x1
;
359 for (indx
=1; indx
< panic_dialog_info
[0].chars
[0]; indx
++)
360 blit_digit(panic_dialog_info
[0].chars
[indx
]);
362 panic_info_x
= (vinfo
.v_width
/2) - (panic_dialog_info
[1].pixels
/2);
364 for (indx
=1; indx
< panic_dialog_info
[1].chars
[0]; indx
++)
365 blit_digit(panic_dialog_info
[1].chars
[indx
]);
367 x2
= ((panic_dialog
->pd_width
/2) - panic_dialog_info
[2].pixels
- (panic_dialog_info
[1].pixels
/2))/2;
368 panic_info_x
= (vinfo
.v_width
/2) + x2
+ (panic_dialog_info
[1].pixels
/2);
370 for (indx
=1; indx
< panic_dialog_info
[2].chars
[0]; indx
++)
371 blit_digit(panic_dialog_info
[2].chars
[indx
]);
375 default : /* nothing */
379 } /* if panic_deugging */
380 } /* if ! logPanicDataToScreen */
381 } /* if ! panicDialogDrawn && ! panicDialogDesired */
383 panicDialogDrawn
= TRUE
;
384 panicDialogDesired
= FALSE
;
389 * This routine installs a new panic dialog
390 * If ptr is NULL, then the default "built-in" panic dialog will be installed.
391 * note: It is the caller that must take care of deallocating memory used for the previous panic dialog
395 panic_dialog_set_image( const unsigned char * ptr
, unsigned int size
)
398 unsigned int newsize
;
399 const struct panicimage
* newimage
;
401 /* if ptr is NULL, restore panic image to built-in default */
403 newimage
= &panic_dialog_default
;
404 newsize
= sizeof(struct panicimage
) + newimage
->pd_dataSize
;
407 newimage
= (struct panicimage
*) ptr
;
411 if ( (error
= panic_dialog_verify( newimage
, newsize
)) )
414 panic_dialog
= newimage
;
415 panic_dialog_data
= &panic_dialog
->data
[0];
416 panic_dialog_clut
= &panic_dialog
->data
[panic_dialog
->pd_dataSize
-CLUT_SIZE
];
418 curr_image_ptr
= (unsigned char *) ptr
;
419 curr_image_size
= size
;
426 * This routines returns the current address of the panic dialog
427 * If the default panic dialog is active, then *ptr will be NULL
431 panic_dialog_get_image( unsigned char ** ptr
, unsigned int * size
)
433 *ptr
= curr_image_ptr
;
434 *size
= curr_image_size
;
439 * This routine verifies the panic dialog image is valid.
443 panic_dialog_verify( const struct panicimage
* newimage
, unsigned int size
)
447 if ( size
< (sizeof(struct panicimage
) + newimage
->pd_dataSize
) )
450 if ( newimage
->pd_tag
!= 'RNMp' )
453 size
= newimage
->pd_dataSize
-CLUT_SIZE
;
454 for (sum
=0,i
=0; i
<size
; i
++) {
455 sum
+= newimage
->data
[i
];
459 if ( sum
!= newimage
->pd_sum
)
467 * Service Routines for managing the panic dialog
471 static const struct rendered_num
* find_rendered_digit( int digit
);
472 static void panic_blit_rect_8( unsigned int x
, unsigned int y
, unsigned int width
, unsigned int height
,
473 int transparent
, unsigned char * dataPtr
);
474 static void panic_blit_rect_16( unsigned int x
, unsigned int y
, unsigned int width
, unsigned int height
,
475 int transparent
, unsigned char * dataPtr
);
476 static void panic_blit_rect_32( unsigned int x
, unsigned int y
, unsigned int width
, unsigned int height
,
477 int transparent
, unsigned char * dataPtr
);
478 static int decode_rle( unsigned char * dataPtr
, unsigned int * quantity
, unsigned int * depth
, unsigned char ** value
);
481 /* Utilities to convert 8 bit/gray */
482 static unsigned int make24bitcolor( unsigned int index
, const unsigned char * clut
);
483 static unsigned char findIndexMatch( unsigned char index
);
484 static unsigned char color24togray8( unsigned int color24
);
485 static unsigned char findbestgray( unsigned int color24
);
486 static int isActiveClutOK( void );
489 pixels_needed_to_blit_digit( int digit
)
495 static const struct rendered_num
*
496 find_rendered_digit( int digit
)
498 //extern unsigned char iso_font[];
499 const struct rendered_num
*digitPtr
;
508 digitPtr
= (const struct rendered_num
*) &iso_font
[digit
* 16];
514 blit_digit( int digit
)
516 unsigned char * raw_data
= (unsigned char *) find_rendered_digit( digit
);
517 unsigned width
= FONT_WIDTH
, height
= FONT_HEIGHT
;
520 for (row
=0; row
<FONT_HEIGHT
; row
++) {
524 bits
= raw_data
[row
];
525 for( j
=FONT_WIDTH
-1; j
>=0; j
--) {
528 rendered_font
[row
][j
] = 0x0100 | panic_dialog
->pd_info_color
[0];
530 rendered_font
[row
][j
] = 0x0100 | panic_dialog
->pd_info_color
[1];
535 panic_blit_rect( panic_info_x
, panic_info_y
, width
, height
, 255, (unsigned char *) rendered_font
);
536 panic_info_x
+= width
;
541 panic_blit_rect( unsigned int x
, unsigned int y
,
542 unsigned int width
, unsigned int height
,
543 int transparent
, unsigned char * dataPtr
)
548 switch( vinfo
.v_depth
) {
550 panic_blit_rect_8( x
, y
, width
, height
, transparent
, dataPtr
);
553 panic_blit_rect_16( x
, y
, width
, height
, transparent
, dataPtr
);
556 panic_blit_rect_32( x
, y
, width
, height
, transparent
, dataPtr
);
562 * panic_blit_rect_8 decodes the RLE encoded image data on the fly, looks up the
563 * color by indexing into the clut, or attempts to find the best index.
567 panic_blit_rect_8( unsigned int x
, unsigned int y
,
568 unsigned int width
, unsigned int height
,
569 int transparent
, unsigned char * dataPtr
)
571 volatile unsigned char * dst
;
572 unsigned int line
, col
, i
;
573 static int clutOK
= -1;
574 unsigned int data
, quantity
, depth
;
575 unsigned char * value
;
579 clutOK
= isActiveClutOK();
581 dst
= (volatile unsigned char *) (vinfo
.v_baseaddr
+
582 (y
* vinfo
.v_rowbytes
) +
588 for( line
= 0; line
< height
; line
++) {
589 for( col
= 0; col
< width
; col
++) {
592 dataPtr
+= decode_rle(dataPtr
, &quantity
, &depth
, &value
);
599 data
= findIndexMatch( value
[i
++] );
609 dst
= (volatile unsigned char *) (((int)dst
) + vinfo
.v_rowbytes
);
614 * panic_blit_rect_16 decodes the RLE encoded image data on the fly, looks up the
615 * color by indexing into the clut, uses the top 5 bits to fill in each of the three
616 * pixel values (RGB) and writes each pixel to the screen.
620 panic_blit_rect_16( unsigned int x
, unsigned int y
,
621 unsigned int width
, unsigned int height
,
622 int transparent
, unsigned char * dataPtr
)
625 volatile unsigned short * dst
;
626 unsigned int line
, col
, i
;
627 unsigned int quantity
, index
, data
, depth
;
628 unsigned char * value
;
630 dst
= (volatile unsigned short *) (vinfo
.v_baseaddr
+
631 (y
* vinfo
.v_rowbytes
) +
637 for( line
= 0; line
< height
; line
++) {
638 for( col
= 0; col
< width
; col
++) {
641 dataPtr
+= decode_rle(dataPtr
, &quantity
, &depth
, &value
);
645 index
= value
[i
++] * 3;
647 data
= ( (unsigned short) (0xf8 & (panic_dialog_clut
[index
+ 0])) << 7)
648 | ( (unsigned short) (0xf8 & (panic_dialog_clut
[index
+ 1])) << 2)
649 | ( (unsigned short) (0xf8 & (panic_dialog_clut
[index
+ 2])) >> 3);
659 dst
= (volatile unsigned short *) (((int)dst
) + vinfo
.v_rowbytes
);
664 * panic_blit_rect_32 decodes the RLE encoded image data on the fly, and fills
665 * in each of the three pixel values from the clut (RGB) for each pixel and
666 * writes it to the screen.
670 panic_blit_rect_32( unsigned int x
, unsigned int y
,
671 unsigned int width
, unsigned int height
,
672 int transparent
, unsigned char * dataPtr
)
674 volatile unsigned int * dst
;
675 unsigned int line
, col
, i
;
676 unsigned int quantity
, index
, data
, depth
;
677 unsigned char * value
;
680 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
681 (y
* vinfo
.v_rowbytes
) +
687 for( line
= 0; line
< height
; line
++) {
688 for( col
= 0; col
< width
; col
++) {
691 dataPtr
+= decode_rle(dataPtr
, &quantity
, &depth
, &value
);
695 index
= value
[i
++] * 3;
697 data
= ( (unsigned int) panic_dialog_clut
[index
+ 0] << 16)
698 | ( (unsigned int) panic_dialog_clut
[index
+ 1] << 8)
699 | ( (unsigned int) panic_dialog_clut
[index
+ 2]);
709 dst
= (volatile unsigned int *) (((int)dst
) + vinfo
.v_rowbytes
);
714 decode_rle decodes a single quantity/value run of a "modified-RLE" encoded
715 image. The encoding works as follows:
717 The run is described in the first byte. If the MSB is zero, then the next seven bits
718 are the quantity of bytes that follow that make up the run of value bytes. (see case 0)
720 If the MSB is set, bits 0-3 are the quantity's least significant 4 bits. If bit 5 is set,
721 then the quantity is further described in the next byte, where an additional 7 bits (4-10)
722 worth of quantity will be found. If the MSB of this byte is set, then an additional
723 7 bits (11-17) worth of quantity will be found in the next byte. This repeats until the MSB of
724 a quantity byte is zero, thus ending the run of quantity bytes.
726 Bits 5/6 of the first byte, describe the number of bytes in the value run following the quantity run.
727 These bits describe value runs of 1 to 4 bytes. And the quantity describe the number of value runs.
730 encodings are: (q = quantity, v = value, c = quantity continues)
732 case 0: [ 0 q6-q0 ] [ v7-v0 ] ... [ v7-v0 ]
733 case 1: [ 1 0 0 c q3-q0 ] [ c q10-q4 ] [ c q17-q11 ] [ q24-q18 ] [ v7-v0 ]
734 case 2: [ 1 0 1 c q3-q0 ] [ c q10-q4 ] [ c q17-q11 ] [ q24-q18 ] [ v7-v0 ] [ v7-v0 ]
735 case 3: [ 1 1 0 c q3-q0 ] [ c q10-q4 ] [ c q17-q11 ] [ q24-q18 ] [ v7-v0 ] [ v7-v0 ] [ v7-v0 ]
736 case 4: [ 1 1 1 c q3-q0 ] [ c q10-q4 ] [ c q17-q11 ] [ q24-q18 ] [ v7-v0 ] [ v7-v0 ] [ v7-v0 ] [ v7-v0 ]
740 decode_rle( unsigned char * dataPtr
, unsigned int * quantity
, unsigned int * depth
, unsigned char ** value
)
743 int i
, runlen
, runsize
;
746 mask
= dataPtr
[i
] & 0xF0;
749 runsize
= ((mask
& 0x60) >> 5) + 1;
750 runlen
= dataPtr
[i
++] & 0x0F;
756 mask
= dataPtr
[i
] & 0x80;
757 runlen
|= ((dataPtr
[i
++] & 0x7F) << shift
);
763 runsize
= dataPtr
[i
++];
768 *value
= &dataPtr
[i
];
777 unsigned long *p
, *endp
, *row
;
778 int col
, rowline
, rowlongs
;
779 register unsigned long mask
;
784 if ( vinfo
.v_depth
== 32 )
786 else if ( vinfo
.v_depth
== 16 )
791 rowline
= vinfo
.v_rowscanbytes
/ 4;
792 rowlongs
= vinfo
.v_rowbytes
/ 4;
794 p
= (unsigned long*) vinfo
.v_baseaddr
;
795 endp
= p
+ (rowlongs
* vinfo
.v_height
);
797 for (row
= p
; row
< endp
; row
+= rowlongs
) {
798 for (p
= &row
[0], col
= 0; col
< rowline
; col
++) {
799 *p
++ = (*p
>> 1) & mask
;
805 /* From user mode Libc - this ought to be in a library */
807 strnstr(const char * s
, const char * find
, size_t slen
)
812 if ((c
= *find
++) != '\0') {
816 if ((sc
= *s
++) == '\0' || slen
-- < 1)
821 } while (strncmp(s
, find
, len
) != 0);
828 * these routines are for converting a color into grayscale
829 * in 8-bit mode, if the active clut is different than the
830 * clut used to create the panic dialog, then we must convert to gray
834 make24bitcolor( unsigned int index
, const unsigned char * clut
)
836 unsigned int color24
= 0;
839 color24
|= clut
[i
+0] << 16;
840 color24
|= clut
[i
+1] << 8;
841 color24
|= clut
[i
+2];
848 findbestgray( unsigned int color24
)
850 unsigned int c24
, rel
, bestindex
=-1, bestgray
= -1;
851 unsigned char gray8
, c8
;
853 #define abs(v) ((v) > 0)?(v):-(v)
855 gray8
= color24togray8( color24
); /* convert the original color into grayscale */
857 for (i
=0; i
<CLUT_ENTRIES
; i
++) {
858 c24
= make24bitcolor( i
, active_clut
);
859 if ( (((c24
>>16)&0xff) != ((c24
>>8)&0xff)) || ((c24
>>8)&0xff) != (c24
& 0xff) )
860 continue; /* only match against grays */
862 c8
= c24
& 0xFF; /* isolate the gray */
864 /* find the gray with the smallest difference */
865 rel
= abs( gray8
- c8
);
866 if ( rel
< bestgray
) {
872 /* Did we fail to find any grays ? */
873 if ( bestindex
== -1 ) {
874 /* someday we should look for the best color match */
875 /* but for now just return the gray as the index */
876 /* at least there might be something readble on the display */
887 color24togray8( unsigned int color24
)
893 R
= (color24
& 0xFF0000) >> 16 ;
894 G
= (color24
& 0xFF00) >> 8 ;
895 B
= (color24
& 0xFF);
897 Gray
= (R
*.30) + (G
*.59) + (B
*.11);
898 gray8
= (unsigned char) ( Gray
+ .5);
904 findIndexMatch( unsigned char index
)
906 static unsigned int last_in_index
= -1;
907 static unsigned char last_index
;
910 if ( index
== last_in_index
)
913 last_in_index
= index
;
914 sc
= make24bitcolor( index
, panic_dialog_clut
);
915 last_index
= findbestgray( sc
); /* find the nearest matching gray in the active clut */
921 isActiveClutOK( void )
924 int r
= 1; /* assume OK */
926 for (i
=0; i
<CLUT_ENTRIES
; i
++) {
927 if ( panic_dialog_clut
[i
] == active_clut
[i
] ) continue;