exec.library: place list of MemHeaderAllocatorCtx into IntExecBase
[AROS.git] / test / writepixelarrayalpha.c
blobda20d1fff93ff84de9bd50ff28387bf138e82152
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);
123 /***********************************************************************************/
125 #define KC_LEFT 0x4F
126 #define KC_RIGHT 0x4E
127 #define KC_UP 0x4C
128 #define KC_DOWN 0x4D
129 #define KC_ESC 0x45
131 /***********************************************************************************/
133 #if 0
134 static void getevents(void)
136 struct IntuiMessage *msg;
138 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
140 switch(msg->Class)
142 case IDCMP_CLOSEWINDOW:
143 Keys[KC_ESC] = 1;
144 break;
146 case IDCMP_RAWKEY:
148 WORD code = msg->Code & ~IECODE_UP_PREFIX;
150 Keys[code] = (code == msg->Code) ? 1 : 0;
153 break;
156 ReplyMsg((struct Message *)msg);
160 #endif
162 /***********************************************************************************/
164 static void action(void)
166 static LONG tab[SCREENWIDTH * SCREENHEIGHT];
167 LONG x, y;
168 LONG ar1, ar2, ar3, ar4;
169 LONG ag1, ag2, ag3, ag4;
170 LONG ab1, ab2, ab3, ab4;
171 LONG r1, r2, r3, r4;
172 LONG g1, g2, g3, g4;
173 LONG b1, b2, b3, b4;
174 LONG tr1, tg1, tb1;
175 LONG tr2, tg2, tb2;
176 LONG tr3, tg3, tb3;
177 LONG tr4, tg4, tb4;
178 LONG ttr1, ttg1, ttb1;
179 LONG ttr2, ttg2, ttb2;
180 LONG tttr, tttg, tttb, ttta;
182 LONG col;
183 BOOL quitme = FALSE;
185 struct IntuiMessage *msg;
187 while(!quitme)
189 ar1 = 0xFF; ag1 = 0xFF; ab1 = 0xFF;
190 ar2 = 0xFF; ag2 = 0x00; ab2 = 0x00;
191 ar3 = 0x00; ag3 = 0xFF; ab3 = 0x00;
192 ar4 = 0x00; ag4 = 0x00; ab4 = 0xFF;
194 r1 = 0xFF; g1 = 0xFF; b1 = 0xFF;
195 r2 = 0xFF; g2 = 0x00; b2 = 0x00;
196 r3 = 0x00; g3 = 0xFF; b3 = 0x00;
197 r4 = 0x00; g4 = 0x00; b4 = 0xFF;
199 x = scr->MouseX;
200 if (x < 0) x = 0; else if (x >= scr->Width) x = scr->Width - 1;
202 r1 = ar1 + (ar2 - ar1) * x / (scr->Width - 1);
203 g1 = ag1 + (ag2 - ag1) * x / (scr->Width - 1);
204 b1 = ab1 + (ab2 - ab1) * x / (scr->Width - 1);
206 r2 = ar2 + (ar3 - ar2) * x / (scr->Width - 1);
207 g2 = ag2 + (ag3 - ag2) * x / (scr->Width - 1);
208 b2 = ab2 + (ab3 - ab2) * x / (scr->Width - 1);
210 r3 = ar3 + (ar4 - ar3) * x / (scr->Width - 1);
211 g3 = ag3 + (ag4 - ag3) * x / (scr->Width - 1);
212 b3 = ab3 + (ab4 - ab3) * x / (scr->Width - 1);
214 r4 = ar4 + (ar1 - ar4) * x / (scr->Width - 1);
215 g4 = ag4 + (ag1 - ag4) * x / (scr->Width - 1);
216 b4 = ab4 + (ab1 - ab4) * x / (scr->Width - 1);
218 ttta = (scr->MouseY * 256) / (scr->Height);
219 if (ttta < 0) ttta = 0; else if (ttta > 255) ttta = 255;
221 for(y = 0; y < SCREENHEIGHT; y ++)
223 for(x = 0; x < SCREENWIDTH; x++)
225 tr1 = r1 + (r2 - r1) * x / (SCREENWIDTH - 1);
226 tg1 = g1 + (g2 - g1) * x / (SCREENWIDTH - 1);
227 tb1 = b1 + (b2 - b1) * x / (SCREENWIDTH - 1);
229 tr2 = r3 + (r4 - r3) * x / (SCREENWIDTH - 1);
230 tg2 = g3 + (g4 - g3) * x / (SCREENWIDTH - 1);
231 tb2 = b3 + (b4 - b3) * x / (SCREENWIDTH - 1);
233 tr3 = r1 + (r3 - r1) * y / (SCREENHEIGHT - 1);
234 tg3 = g1 + (g3 - g1) * y / (SCREENHEIGHT - 1);
235 tb3 = b1 + (b3 - b1) * y / (SCREENHEIGHT - 1);
237 tr4 = r2 + (r4 - r2) * y / (SCREENHEIGHT - 1);
238 tg4 = g2 + (g4 - g2) * y / (SCREENHEIGHT - 1);
239 tb4 = b2 + (b4 - b2) * y / (SCREENHEIGHT - 1);
241 ttr1 = tr1 + (tr2 - tr1) * y / (SCREENHEIGHT - 1);
242 ttg1 = tg1 + (tg2 - tg1) * y / (SCREENHEIGHT - 1);
243 ttb1 = tb1 + (tb2 - tb1) * y / (SCREENHEIGHT - 1);
245 ttr2 = tr3 + (tr4 - tr3) * x / (SCREENWIDTH - 1);
246 ttg2 = tg3 + (tg4 - tg3) * x / (SCREENWIDTH - 1);
247 ttb2 = tb3 + (tb4 - tb3) * x / (SCREENWIDTH - 1);
249 tttr = (ttr1 + ttr2) / 2;
250 tttg = (ttg1 + ttg2) / 2;
251 tttb = (ttb1 + ttb2) / 2;
253 #if AROS_BIG_ENDIAN
254 col = (ttta << 24) + (tttr << 16) + (tttg << 8) + tttb;
255 #else
256 col = (tttb << 24) + (tttg << 16) + (tttr << 8) + ttta;
257 #endif
258 //kprintf("col[%d,%d] = %08x\n", x,y,col);
259 tab[y * SCREENWIDTH + x] = col;
261 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
263 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
266 if (bm)
268 struct RastPort temprp;
270 InitRastPort(&temprp);
271 temprp.BitMap = bm;
273 BltBitMap(bm, 0, 0, bm, 0, SCREENHEIGHT, SCREENWIDTH, SCREENHEIGHT, 192, 255, 0);
275 WritePixelArrayAlpha(tab, 0, 0, SCREENWIDTH * sizeof(LONG),
276 &temprp, 0, SCREENHEIGHT, SCREENWIDTH, SCREENHEIGHT,
279 BltBitMapRastPort(bm, 0, SCREENHEIGHT, win->RPort, win->BorderLeft, win->BorderTop, win->GZZWidth, win->GZZHeight, 192);
281 else
283 WritePixelArrayAlpha(tab, 0, 0, SCREENWIDTH * sizeof(LONG),
284 win->RPort, win->BorderLeft, win->BorderTop, SCREENWIDTH, SCREENHEIGHT,
288 WaitPort(win->UserPort);
290 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
292 switch(msg->Class)
294 case IDCMP_CLOSEWINDOW:
295 quitme = TRUE;
296 break;
299 ReplyMsg((struct Message *)msg);
306 /***********************************************************************************/
308 int main(void)
310 openlibs();
311 getvisual();
312 makewin();
313 action();
314 cleanup(0);
316 return 0; /* keep compiler happy */
319 /***********************************************************************************/