ndd@duke.cs.duke.edu (Ned Danieley) (06/01/88)
Does anyone have a collection of 16x16 bitmaps that can be used to provide depth shading on a monochrome monitor? We'd like at least 8 different bitmaps so we can have 8 different shadings. Ned Danieley (ndd@sunbar.mc.duke.edu) Basic Arrhythmia Laboratory Box 3140, Duke University Medical Center Durham, NC 27710 (919) 684-6807 or 684-6942
cmc@inf.rl.ac.uk (Chris Crampton) (07/11/88)
In article <11808@duke.cs.duke.edu> ndd@duke.cs.duke.edu (Ned Danieley) writes: >Does anyone have a collection of 16x16 bitmaps that can be used >to provide depth shading on a monochrome monitor? We'd like at >least 8 different bitmaps so we can have 8 different shadings. We also needed something along these lines and a colleague of mine showed me a clever idea that he had come up with for his PostScript (tm) interpreter that was posted to the net some time ago. Basically, he uses a matix of threshold values which is deviously designed so that for a given intensity one merely switches on the bits in a tile that correspond to values in the matrix which are less than the intensity value. The matrix values are distributed to avoid "patchy" shades. Crispin has a way of generating these matices for any size which is a power of two. A C implementation for building 8x8 bitmaps is enclosed below. As we don't actually use this stuff straight on top of X there are some bits missing, like how to convert some canonical string representation of a bitmap into a real X bitmap. Presumably this isn't too hard... Chris. -- /* ** grey shade generator ** ** This uses Crispin Goswell's algorithm for picking a grey texture ** by using a matrix of values and then using the intensity as a ** threshold. ** ** Copyright (c) Chris Crampton @ RAL, 1987 */ /* The clever matrix of values: if the value at a given point is ** <= to the desired intensity (0-64) then that bit in the (8x8 bit) ** texture should be "on". */ static int halftone [][8] = { {43, 11, 35, 3, 41, 9, 33, 1}, {27, 59, 19, 51, 25, 57, 17, 49}, {39, 7, 47, 15, 37, 5, 45, 13}, {23, 55, 31, 63, 21, 53, 29, 61}, {42, 10, 34, 2, 44, 12, 36, 4}, {26, 58, 18, 50, 28, 60, 20, 52}, {38, 6, 46, 14, 40, 8, 48, 16}, {22, 54, 30, 62, 24, 56, 32, 64} }; extern bitmap_type* string_to_bitmap(); bitmap_type* grey_tile (percent_intensity) unsigned int percent_intensity; { register int thresh, i; if (percent_intensity > 100) percent_intensity = 100; thresh = (percent_intensity * 64) / 100; /* use the matrix to build an encoded string ** from which a canvas can be constructed */ /* use a char array with space for 2 shorts for height and width ** plus 64 bits of bitmap data */ char pat[12]; pat[0] = 0; pat[1] = 8; /* 8 by 8 bitmap */ pat[2] = 0, pat[3] = 8; /* loop for each scan line */ for (i = 4; i < 12; i++) { register int b, j; for (j = 0, b = 0; j < 8; j++) /* loop for each bit */ if (halftone[i-4][j] <= thresh) /* switch the bit on */ b |= 1 << j; pat[i] = b; } /* now decode the string to a bitmap */ return string_to_bitmap (pat); } ======================================================================= Chris M Crampton UK JANET: cmc@uk.ac.rl.inf Rutherford Appleton Labs, ARPA: cmc%inf.rl.ac.uk@nss.cs.ucl.ac.uk Didcot, OXON, U.K. UUCP: ..!mcvax!ukc!rlvd!cmc +44 235 21900 ext. 6756 cmc@rlvd.uucp