make.tmpl: add missing compiler attribute to build_progs
[AROS.git] / test / graphics / writepixelarrayalpha.c
blobb9d95e2b5fde9f17b3604f104d4f4070dbcb1520
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dos/dos.h>
7 #include <intuition/intuition.h>
8 #include <graphics/gfx.h>
9 #include <cybergraphx/cybergraphics.h>
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/graphics.h>
13 #include <proto/cybergraphics.h>
14 #include <proto/intuition.h>
16 #include <math.h>
17 #include <stdio.h>
18 #include <stdlib.h>
20 #define SCREENWIDTH 300
21 #define SCREENHEIGHT 200
22 #define SCREENCY (SCREENHEIGHT / 2)
24 /***********************************************************************************/
26 struct IntuitionBase *IntuitionBase;
27 struct GfxBase *GfxBase;
28 struct Library *CyberGfxBase;
29 struct Screen *scr;
30 struct Window *win;
31 struct RastPort *rp;
32 struct BitMap *bm;
34 ULONG cgfx_coltab[256];
35 UBYTE Keys[128];
37 /***********************************************************************************/
39 static void cleanup(char *msg)
41 if (msg)
43 printf("WritePixelArrayAlpha: %s\n",msg);
46 if (bm) FreeBitMap(bm);
47 if (win) CloseWindow(win);
49 if (scr) UnlockPubScreen(0, scr);
51 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
52 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
53 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
55 exit(0);
58 /***********************************************************************************/
60 static void openlibs(void)
62 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
64 cleanup("Can't open intuition.library V39!");
67 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
69 cleanup("Can't open graphics.library V39!");
72 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
74 cleanup("Can't open cybergraphics.library!");
78 /***********************************************************************************/
80 static void getvisual(void)
82 if (!(scr = LockPubScreen(NULL)))
84 cleanup("Can't lock pub screen!");
87 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
89 cleanup("Need hi or true color screen!");
93 /***********************************************************************************/
95 static void makewin(void)
97 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
98 WA_InnerWidth , SCREENWIDTH,
99 WA_InnerHeight , SCREENHEIGHT,
100 WA_Title , (IPTR)"WritePixelArrayAlpha: Move mouse!",
101 WA_DragBar , TRUE,
102 WA_DepthGadget , TRUE,
103 WA_CloseGadget , TRUE,
104 WA_Activate , TRUE,
105 WA_ReportMouse , TRUE,
106 WA_MouseQueue , 1,
107 WA_IDCMP , IDCMP_CLOSEWINDOW | IDCMP_MOUSEMOVE,
108 WA_BackFill , (IPTR)LAYERS_NOBACKFILL,
109 TAG_DONE);
111 if (!win) cleanup("Can't open window");
113 rp = win->RPort;
115 bm = AllocBitMap(win->GZZWidth, win->GZZHeight * 2, 0, 0, win->RPort->BitMap);
116 if (bm)
118 struct RastPort temprp;
120 InitRastPort(&temprp);
121 temprp.BitMap = bm;
123 ClipBlit(win->RPort, win->BorderLeft, win->BorderTop, &temprp, 0, 0, win->GZZWidth, win->GZZHeight, 192);
127 /***********************************************************************************/
129 #define KC_LEFT 0x4F
130 #define KC_RIGHT 0x4E
131 #define KC_UP 0x4C
132 #define KC_DOWN 0x4D
133 #define KC_ESC 0x45
135 /***********************************************************************************/
137 #if 0
138 static void getevents(void)
140 struct IntuiMessage *msg;
142 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
144 switch(msg->Class)
146 case IDCMP_CLOSEWINDOW:
147 Keys[KC_ESC] = 1;
148 break;
150 case IDCMP_RAWKEY:
152 WORD code = msg->Code & ~IECODE_UP_PREFIX;
154 Keys[code] = (code == msg->Code) ? 1 : 0;
157 break;
160 ReplyMsg((struct Message *)msg);
164 #endif
166 /***********************************************************************************/
168 static void action(void)
170 static LONG tab[SCREENWIDTH * SCREENHEIGHT];
171 LONG x, y;
172 LONG ar1, ar2, ar3, ar4;
173 LONG ag1, ag2, ag3, ag4;
174 LONG ab1, ab2, ab3, ab4;
175 LONG r1, r2, r3, r4;
176 LONG g1, g2, g3, g4;
177 LONG b1, b2, b3, b4;
178 LONG tr1, tg1, tb1;
179 LONG tr2, tg2, tb2;
180 LONG tr3, tg3, tb3;
181 LONG tr4, tg4, tb4;
182 LONG ttr1, ttg1, ttb1;
183 LONG ttr2, ttg2, ttb2;
184 LONG tttr, tttg, tttb, ttta;
186 LONG col;
187 BOOL quitme = FALSE;
189 struct IntuiMessage *msg;
191 while(!quitme)
193 ar1 = 0xFF; ag1 = 0xFF; ab1 = 0xFF;
194 ar2 = 0xFF; ag2 = 0x00; ab2 = 0x00;
195 ar3 = 0x00; ag3 = 0xFF; ab3 = 0x00;
196 ar4 = 0x00; ag4 = 0x00; ab4 = 0xFF;
198 r1 = 0xFF; g1 = 0xFF; b1 = 0xFF;
199 r2 = 0xFF; g2 = 0x00; b2 = 0x00;
200 r3 = 0x00; g3 = 0xFF; b3 = 0x00;
201 r4 = 0x00; g4 = 0x00; b4 = 0xFF;
203 x = scr->MouseX;
204 if (x < 0) x = 0; else if (x >= scr->Width) x = scr->Width - 1;
206 r1 = ar1 + (ar2 - ar1) * x / (scr->Width - 1);
207 g1 = ag1 + (ag2 - ag1) * x / (scr->Width - 1);
208 b1 = ab1 + (ab2 - ab1) * x / (scr->Width - 1);
210 r2 = ar2 + (ar3 - ar2) * x / (scr->Width - 1);
211 g2 = ag2 + (ag3 - ag2) * x / (scr->Width - 1);
212 b2 = ab2 + (ab3 - ab2) * x / (scr->Width - 1);
214 r3 = ar3 + (ar4 - ar3) * x / (scr->Width - 1);
215 g3 = ag3 + (ag4 - ag3) * x / (scr->Width - 1);
216 b3 = ab3 + (ab4 - ab3) * x / (scr->Width - 1);
218 r4 = ar4 + (ar1 - ar4) * x / (scr->Width - 1);
219 g4 = ag4 + (ag1 - ag4) * x / (scr->Width - 1);
220 b4 = ab4 + (ab1 - ab4) * x / (scr->Width - 1);
222 ttta = (scr->MouseY * 256) / (scr->Height);
223 if (ttta < 0) ttta = 0; else if (ttta > 255) ttta = 255;
225 for(y = 0; y < SCREENHEIGHT; y ++)
227 for(x = 0; x < SCREENWIDTH; x++)
229 tr1 = r1 + (r2 - r1) * x / (SCREENWIDTH - 1);
230 tg1 = g1 + (g2 - g1) * x / (SCREENWIDTH - 1);
231 tb1 = b1 + (b2 - b1) * x / (SCREENWIDTH - 1);
233 tr2 = r3 + (r4 - r3) * x / (SCREENWIDTH - 1);
234 tg2 = g3 + (g4 - g3) * x / (SCREENWIDTH - 1);
235 tb2 = b3 + (b4 - b3) * x / (SCREENWIDTH - 1);
237 tr3 = r1 + (r3 - r1) * y / (SCREENHEIGHT - 1);
238 tg3 = g1 + (g3 - g1) * y / (SCREENHEIGHT - 1);
239 tb3 = b1 + (b3 - b1) * y / (SCREENHEIGHT - 1);
241 tr4 = r2 + (r4 - r2) * y / (SCREENHEIGHT - 1);
242 tg4 = g2 + (g4 - g2) * y / (SCREENHEIGHT - 1);
243 tb4 = b2 + (b4 - b2) * y / (SCREENHEIGHT - 1);
245 ttr1 = tr1 + (tr2 - tr1) * y / (SCREENHEIGHT - 1);
246 ttg1 = tg1 + (tg2 - tg1) * y / (SCREENHEIGHT - 1);
247 ttb1 = tb1 + (tb2 - tb1) * y / (SCREENHEIGHT - 1);
249 ttr2 = tr3 + (tr4 - tr3) * x / (SCREENWIDTH - 1);
250 ttg2 = tg3 + (tg4 - tg3) * x / (SCREENWIDTH - 1);
251 ttb2 = tb3 + (tb4 - tb3) * x / (SCREENWIDTH - 1);
253 tttr = (ttr1 + ttr2) / 2;
254 tttg = (ttg1 + ttg2) / 2;
255 tttb = (ttb1 + ttb2) / 2;
257 #if AROS_BIG_ENDIAN
258 col = (ttta << 24) + (tttr << 16) + (tttg << 8) + tttb;
259 #else
260 col = (tttb << 24) + (tttg << 16) + (tttr << 8) + ttta;
261 #endif
262 //kprintf("col[%d,%d] = %08x\n", x,y,col);
263 tab[y * SCREENWIDTH + x] = col;
265 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
267 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
270 if (bm)
272 struct RastPort temprp;
274 InitRastPort(&temprp);
275 temprp.BitMap = bm;
277 BltBitMap(bm, 0, 0, bm, 0, SCREENHEIGHT, SCREENWIDTH, SCREENHEIGHT, 192, 255, 0);
279 WritePixelArrayAlpha(tab, 0, 0, SCREENWIDTH * sizeof(LONG),
280 &temprp, 0, SCREENHEIGHT, SCREENWIDTH, SCREENHEIGHT,
283 BltBitMapRastPort(bm, 0, SCREENHEIGHT, win->RPort, win->BorderLeft, win->BorderTop, win->GZZWidth, win->GZZHeight, 192);
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 /***********************************************************************************/