- Some read-only tag lists are now marked as const.
[cake.git] / test / writepixelarrayalpha.c
blob83b9a1981eb429a125551991a08ac580c293d5d1
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <cybergraphx/cybergraphics.h>
6 #include <proto/exec.h>
7 #include <proto/dos.h>
8 #include <proto/graphics.h>
9 #include <proto/cybergraphics.h>
10 #include <proto/intuition.h>
12 #include <math.h>
13 #include <stdio.h>
14 #include <stdlib.h>
16 #define SCREENWIDTH 300
17 #define SCREENHEIGHT 200
18 #define SCREENCY (SCREENHEIGHT / 2)
20 /***********************************************************************************/
22 struct IntuitionBase *IntuitionBase;
23 struct GfxBase *GfxBase;
24 struct Library *CyberGfxBase;
25 struct Screen *scr;
26 struct Window *win;
27 struct RastPort *rp;
28 struct BitMap *bm;
30 ULONG cgfx_coltab[256];
31 UBYTE Keys[128];
33 /***********************************************************************************/
35 static void cleanup(char *msg)
37 if (msg)
39 printf("WritePixelArrayAlpha: %s\n",msg);
42 if (bm) FreeBitMap(bm);
43 if (win) CloseWindow(win);
45 if (scr) UnlockPubScreen(0, scr);
47 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
48 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
49 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
51 exit(0);
54 /***********************************************************************************/
56 static void openlibs(void)
58 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
60 cleanup("Can't open intuition.library V39!");
63 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
65 cleanup("Can't open graphics.library V39!");
68 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
70 cleanup("Can't open cybergraphics.library!");
74 /***********************************************************************************/
76 static void getvisual(void)
78 if (!(scr = LockPubScreen(NULL)))
80 cleanup("Can't lock pub screen!");
83 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
85 cleanup("Need hi or true color screen!");
89 /***********************************************************************************/
91 static void makewin(void)
93 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
94 WA_InnerWidth , SCREENWIDTH,
95 WA_InnerHeight , SCREENHEIGHT,
96 WA_Title , (IPTR)"WritePixelArrayAlpha: Move mouse!",
97 WA_DragBar , TRUE,
98 WA_DepthGadget , TRUE,
99 WA_CloseGadget , TRUE,
100 WA_Activate , TRUE,
101 WA_ReportMouse , TRUE,
102 WA_MouseQueue , 1,
103 WA_IDCMP , IDCMP_CLOSEWINDOW | IDCMP_MOUSEMOVE,
104 WA_BackFill , (IPTR)LAYERS_NOBACKFILL,
105 TAG_DONE);
107 if (!win) cleanup("Can't open window");
109 rp = win->RPort;
111 bm = AllocBitMap(win->GZZWidth, win->GZZHeight * 2, 0, 0, win->RPort->BitMap);
112 if (bm)
114 struct RastPort temprp;
116 InitRastPort(&temprp);
117 temprp.BitMap = bm;
119 ClipBlit(win->RPort, win->BorderLeft, win->BorderTop, &temprp, 0, 0, win->GZZWidth, win->GZZHeight, 192);
121 DeinitRastPort(&temprp);
125 /***********************************************************************************/
127 #define KC_LEFT 0x4F
128 #define KC_RIGHT 0x4E
129 #define KC_UP 0x4C
130 #define KC_DOWN 0x4D
131 #define KC_ESC 0x45
133 /***********************************************************************************/
135 #if 0
136 static void getevents(void)
138 struct IntuiMessage *msg;
140 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
142 switch(msg->Class)
144 case IDCMP_CLOSEWINDOW:
145 Keys[KC_ESC] = 1;
146 break;
148 case IDCMP_RAWKEY:
150 WORD code = msg->Code & ~IECODE_UP_PREFIX;
152 Keys[code] = (code == msg->Code) ? 1 : 0;
155 break;
158 ReplyMsg((struct Message *)msg);
162 #endif
164 /***********************************************************************************/
166 static void action(void)
168 static LONG tab[SCREENWIDTH * SCREENHEIGHT];
169 LONG x, y;
170 LONG ar1, ar2, ar3, ar4;
171 LONG ag1, ag2, ag3, ag4;
172 LONG ab1, ab2, ab3, ab4;
173 LONG r1, r2, r3, r4;
174 LONG g1, g2, g3, g4;
175 LONG b1, b2, b3, b4;
176 LONG tr1, tg1, tb1;
177 LONG tr2, tg2, tb2;
178 LONG tr3, tg3, tb3;
179 LONG tr4, tg4, tb4;
180 LONG ttr1, ttg1, ttb1;
181 LONG ttr2, ttg2, ttb2;
182 LONG tttr, tttg, tttb, ttta;
184 LONG col;
185 BOOL quitme = FALSE;
187 struct IntuiMessage *msg;
189 while(!quitme)
191 ar1 = 0xFF; ag1 = 0xFF; ab1 = 0xFF;
192 ar2 = 0xFF; ag2 = 0x00; ab2 = 0x00;
193 ar3 = 0x00; ag3 = 0xFF; ab3 = 0x00;
194 ar4 = 0x00; ag4 = 0x00; ab4 = 0xFF;
196 r1 = 0xFF; g1 = 0xFF; b1 = 0xFF;
197 r2 = 0xFF; g2 = 0x00; b2 = 0x00;
198 r3 = 0x00; g3 = 0xFF; b3 = 0x00;
199 r4 = 0x00; g4 = 0x00; b4 = 0xFF;
201 x = scr->MouseX;
202 if (x < 0) x = 0; else if (x >= scr->Width) x = scr->Width - 1;
204 r1 = ar1 + (ar2 - ar1) * x / (scr->Width - 1);
205 g1 = ag1 + (ag2 - ag1) * x / (scr->Width - 1);
206 b1 = ab1 + (ab2 - ab1) * x / (scr->Width - 1);
208 r2 = ar2 + (ar3 - ar2) * x / (scr->Width - 1);
209 g2 = ag2 + (ag3 - ag2) * x / (scr->Width - 1);
210 b2 = ab2 + (ab3 - ab2) * x / (scr->Width - 1);
212 r3 = ar3 + (ar4 - ar3) * x / (scr->Width - 1);
213 g3 = ag3 + (ag4 - ag3) * x / (scr->Width - 1);
214 b3 = ab3 + (ab4 - ab3) * x / (scr->Width - 1);
216 r4 = ar4 + (ar1 - ar4) * x / (scr->Width - 1);
217 g4 = ag4 + (ag1 - ag4) * x / (scr->Width - 1);
218 b4 = ab4 + (ab1 - ab4) * x / (scr->Width - 1);
220 ttta = (scr->MouseY * 256) / (scr->Height);
221 if (ttta < 0) ttta = 0; else if (ttta > 255) ttta = 255;
223 for(y = 0; y < SCREENHEIGHT; y ++)
225 for(x = 0; x < SCREENWIDTH; x++)
227 tr1 = r1 + (r2 - r1) * x / (SCREENWIDTH - 1);
228 tg1 = g1 + (g2 - g1) * x / (SCREENWIDTH - 1);
229 tb1 = b1 + (b2 - b1) * x / (SCREENWIDTH - 1);
231 tr2 = r3 + (r4 - r3) * x / (SCREENWIDTH - 1);
232 tg2 = g3 + (g4 - g3) * x / (SCREENWIDTH - 1);
233 tb2 = b3 + (b4 - b3) * x / (SCREENWIDTH - 1);
235 tr3 = r1 + (r3 - r1) * y / (SCREENHEIGHT - 1);
236 tg3 = g1 + (g3 - g1) * y / (SCREENHEIGHT - 1);
237 tb3 = b1 + (b3 - b1) * y / (SCREENHEIGHT - 1);
239 tr4 = r2 + (r4 - r2) * y / (SCREENHEIGHT - 1);
240 tg4 = g2 + (g4 - g2) * y / (SCREENHEIGHT - 1);
241 tb4 = b2 + (b4 - b2) * y / (SCREENHEIGHT - 1);
243 ttr1 = tr1 + (tr2 - tr1) * y / (SCREENHEIGHT - 1);
244 ttg1 = tg1 + (tg2 - tg1) * y / (SCREENHEIGHT - 1);
245 ttb1 = tg1 + (tg2 - tg1) * y / (SCREENHEIGHT - 1);
247 ttr2 = tr3 + (tr4 - tr3) * x / (SCREENWIDTH - 1);
248 ttg2 = tg3 + (tg4 - tg3) * x / (SCREENWIDTH - 1);
249 ttb2 = tb3 + (tb4 - tb3) * x / (SCREENWIDTH - 1);
251 tttr = (ttr1 + ttr2) / 2;
252 tttg = (ttg1 + ttg2) / 2;
253 tttb = (ttb1 + ttb2) / 2;
255 #if AROS_BIG_ENDIAN
256 col = (ttta << 24) + (tttr << 16) + (tttg << 8) + tttb;
257 #else
258 col = (tttb << 24) + (tttg << 16) + (tttr << 8) + ttta;
259 #endif
260 //kprintf("col[%d,%d] = %08x\n", x,y,col);
261 tab[y * SCREENWIDTH + x] = col;
263 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
265 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
268 if (bm)
270 struct RastPort temprp;
272 InitRastPort(&temprp);
273 temprp.BitMap = bm;
275 BltBitMap(bm, 0, 0, bm, 0, SCREENHEIGHT, SCREENWIDTH, SCREENHEIGHT, 192, 255, 0);
277 WritePixelArrayAlpha(tab, 0, 0, SCREENWIDTH * sizeof(LONG),
278 &temprp, 0, SCREENHEIGHT, SCREENWIDTH, SCREENHEIGHT,
281 BltBitMapRastPort(bm, 0, SCREENHEIGHT, win->RPort, win->BorderLeft, win->BorderTop, win->GZZWidth, win->GZZHeight, 192);
283 DeinitRastPort(&temprp);
285 else
287 WritePixelArrayAlpha(tab, 0, 0, SCREENWIDTH * sizeof(LONG),
288 win->RPort, win->BorderLeft, win->BorderTop, SCREENWIDTH, SCREENHEIGHT,
292 WaitPort(win->UserPort);
294 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
296 switch(msg->Class)
298 case IDCMP_CLOSEWINDOW:
299 quitme = TRUE;
300 break;
303 ReplyMsg((struct Message *)msg);
310 /***********************************************************************************/
312 int main(void)
314 openlibs();
315 getvisual();
316 makewin();
317 action();
318 cleanup(0);
320 return 0; /* keep compiler happy */
323 /***********************************************************************************/