1ex12bit(3) Allegro manual ex12bit(3)
2
3
4
6 ex12bit - How to fake a 12-bit truecolor mode on an 8-bit card. Allegro
7 game programming library.
8
10 #include <allegro.h>
11
12
13 Example ex12bit
14
16 This program sets up a 12-bit mode on any 8-bit card, by setting up a
17 256-colour palette that will fool the eye into grouping two 8-bit pix‐
18 els into one 12-bit pixel. In order to do this, you make your
19 256-colour palette with all the combinations of blue and green, assum‐
20 ing green ranges from 0-15 and blue from 0-14. This takes up 16x15=240
21 colours. This leaves 16 colours to use as red (red ranges from 0-15).
22 Then you put your green/blue in one pixel, and your red in the pixel
23 next to it. The eye gets fooled into thinking it's all one pixel.
24
25 The example starts setting a normal 256 color mode, and construct a
26 special palette for it. But then comes the trick: you need to write to
27 a set of two adjacent pixels to form a single 12 bit dot. Two eight bit
28 pixels is the same as one 16 bit pixel, so after setting the video mode
29 you need to hack the screen bitmap about, halving the width and chang‐
30 ing it to use the 16 bit drawing code. Then, once you have packed a
31 color into the correct format (using the makecol12() function below),
32 any of the normal Allegro drawing functions can be used with this 12
33 bit display!
34
35 Things to note:
36
37 The horizontal width is halved, so you get resolutions like 320x480,
38 400x600, and 512x768.
39
40 Because each dot is spread over two actual pixels, the display will be
41 darker than in a normal video mode.
42
43 Any bitmap data will obviously need converting to the correct 12 bit
44 format: regular 15 or 16 bit images won't display correctly...
45
46 Although this works like a truecolor mode, it is actually using a 256
47 color palette, so palette fades are still possible!
48
49 This code only works in linear screen modes (don't try Mode-X).
50
51
53 BITMAP(3), END_OF_MAIN(3), MATRIX(3), PALETTE(3), RGB(3), alle‐
54 gro_error(3), allegro_init(3), allegro_message(3), apply_matrix(3),
55 blit(3), circle(3), clear_bitmap(3), clear_keybuf(3),
56 clear_to_color(3), create_bitmap(3), create_bitmap_ex(3), destroy_bit‐
57 map(3), ellipsefill(3), fade_out(3), fixcos(3), fixed(3), fixsin(3),
58 fixtoi(3), font(3), get_rotation_matrix(3), getpixel(3), install_key‐
59 board(3), itofix(3), keypressed(3), line(3), makecol(3),
60 masked_blit(3), putpixel(3), rest(3), screen(3), set_clip_rect(3),
61 set_color(3), set_gfx_mode(3), set_palette(3), text_height(3),
62 text_length(3), textout_ex(3), textprintf_ex(3)
63
64
65
66Allegro version 4.4.3 ex12bit(3)