grub2: bring back build of aros-side grub2 tools
[AROS.git] / test / graphics / writepixelarray.c
blobb2d3796a36a97cbb643905fc6b88681d2bc0eb96
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;
33 ULONG cgfx_coltab[256];
34 UBYTE Keys[128];
36 /***********************************************************************************/
38 static void cleanup(char *msg)
40 if (msg)
42 printf("WritePixelArray: %s\n",msg);
45 if (win) CloseWindow(win);
47 if (scr) UnlockPubScreen(0, scr);
49 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
50 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
51 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
53 exit(0);
56 /***********************************************************************************/
58 static void openlibs(void)
60 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
62 cleanup("Can't open intuition.library V39!");
65 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
67 cleanup("Can't open graphics.library V39!");
70 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
72 cleanup("Can't open cybergraphics.library!");
76 /***********************************************************************************/
78 static void getvisual(void)
80 if (!(scr = LockPubScreen(NULL)))
82 cleanup("Can't lock pub screen!");
85 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
87 cleanup("Need hi or true color screen!");
91 /***********************************************************************************/
93 static void makewin(void)
95 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
96 WA_InnerWidth , SCREENWIDTH,
97 WA_InnerHeight , SCREENHEIGHT,
98 WA_Title , (IPTR)"WritePixelArray: Move mouse!",
99 WA_DragBar , TRUE,
100 WA_DepthGadget , TRUE,
101 WA_CloseGadget , TRUE,
102 WA_Activate , TRUE,
103 WA_IDCMP , IDCMP_CLOSEWINDOW |
104 IDCMP_RAWKEY,
105 TAG_DONE);
107 if (!win) cleanup("Can't open window");
109 rp = win->RPort;
112 /***********************************************************************************/
114 #define KC_LEFT 0x4F
115 #define KC_RIGHT 0x4E
116 #define KC_UP 0x4C
117 #define KC_DOWN 0x4D
118 #define KC_ESC 0x45
120 /***********************************************************************************/
122 static void getevents(void)
124 struct IntuiMessage *msg;
126 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
128 switch(msg->Class)
130 case IDCMP_CLOSEWINDOW:
131 Keys[KC_ESC] = 1;
132 break;
134 case IDCMP_RAWKEY:
136 WORD code = msg->Code & ~IECODE_UP_PREFIX;
138 Keys[code] = (code == msg->Code) ? 1 : 0;
141 break;
144 ReplyMsg((struct Message *)msg);
149 /***********************************************************************************/
151 static void action(void)
153 static LONG tab[SCREENWIDTH * SCREENHEIGHT];
154 LONG x, y;
155 LONG ar1, ar2, ar3, ar4;
156 LONG ag1, ag2, ag3, ag4;
157 LONG ab1, ab2, ab3, ab4;
158 LONG r1, r2, r3, r4;
159 LONG g1, g2, g3, g4;
160 LONG b1, b2, b3, b4;
161 LONG tr1, tg1, tb1;
162 LONG tr2, tg2, tb2;
163 LONG tr3, tg3, tb3;
164 LONG tr4, tg4, tb4;
165 LONG ttr1, ttg1, ttb1;
166 LONG ttr2, ttg2, ttb2;
167 LONG tttr, tttg, tttb;
169 LONG col;
171 ar1 = 0xFF; ag1 = 0xFF; ab1 = 0xFF;
172 ar2 = 0xFF; ag2 = 0x00; ab2 = 0x00;
173 ar3 = 0x00; ag3 = 0xFF; ab3 = 0x00;
174 ar4 = 0x00; ag4 = 0x00; ab4 = 0xFF;
176 r1 = 0xFF; g1 = 0xFF; b1 = 0xFF;
177 r2 = 0xFF; g2 = 0x00; b2 = 0x00;
178 r3 = 0x00; g3 = 0xFF; b3 = 0x00;
179 r4 = 0x00; g4 = 0x00; b4 = 0xFF;
181 while(!Keys[KC_ESC])
183 x = scr->MouseX;
184 if (x < 0) x = 0; else if (x >= scr->Width) x = scr->Width - 1;
186 r1 = ar1 + (ar2 - ar1) * x / (scr->Width - 1);
187 g1 = ag1 + (ag2 - ag1) * x / (scr->Width - 1);
188 b1 = ab1 + (ab2 - ab1) * x / (scr->Width - 1);
190 r2 = ar2 + (ar3 - ar2) * x / (scr->Width - 1);
191 g2 = ag2 + (ag3 - ag2) * x / (scr->Width - 1);
192 b2 = ab2 + (ab3 - ab2) * x / (scr->Width - 1);
194 r3 = ar3 + (ar4 - ar3) * x / (scr->Width - 1);
195 g3 = ag3 + (ag4 - ag3) * x / (scr->Width - 1);
196 b3 = ab3 + (ab4 - ab3) * x / (scr->Width - 1);
198 r4 = ar4 + (ar1 - ar4) * x / (scr->Width - 1);
199 g4 = ag4 + (ag1 - ag4) * x / (scr->Width - 1);
200 b4 = ab4 + (ab1 - ab4) * x / (scr->Width - 1);
203 for(y = 0; y < SCREENHEIGHT; y ++)
205 for(x = 0; x < SCREENWIDTH; x++)
207 tr1 = r1 + (r2 - r1) * x / (SCREENWIDTH - 1);
208 tg1 = g1 + (g2 - g1) * x / (SCREENWIDTH - 1);
209 tb1 = b1 + (b2 - b1) * x / (SCREENWIDTH - 1);
211 tr2 = r3 + (r4 - r3) * x / (SCREENWIDTH - 1);
212 tg2 = g3 + (g4 - g3) * x / (SCREENWIDTH - 1);
213 tb2 = b3 + (b4 - b3) * x / (SCREENWIDTH - 1);
215 tr3 = r1 + (r3 - r1) * y / (SCREENHEIGHT - 1);
216 tg3 = g1 + (g3 - g1) * y / (SCREENHEIGHT - 1);
217 tb3 = b1 + (b3 - b1) * y / (SCREENHEIGHT - 1);
219 tr4 = r2 + (r4 - r2) * y / (SCREENHEIGHT - 1);
220 tg4 = g2 + (g4 - g2) * y / (SCREENHEIGHT - 1);
221 tb4 = b2 + (b4 - b2) * y / (SCREENHEIGHT - 1);
223 ttr1 = tr1 + (tr2 - tr1) * y / (SCREENHEIGHT - 1);
224 ttg1 = tg1 + (tg2 - tg1) * y / (SCREENHEIGHT - 1);
225 ttb1 = tb1 + (tb2 - tb1) * y / (SCREENHEIGHT - 1);
227 ttr2 = tr3 + (tr4 - tr3) * x / (SCREENWIDTH - 1);
228 ttg2 = tg3 + (tg4 - tg3) * x / (SCREENWIDTH - 1);
229 ttb2 = tb3 + (tb4 - tb3) * x / (SCREENWIDTH - 1);
231 tttr = (ttr1 + ttr2) / 2;
232 tttg = (ttg1 + ttg2) / 2;
233 tttb = (ttb1 + ttb2) / 2;
235 #if AROS_BIG_ENDIAN
236 col = (tttr << 16) + (tttg << 8) + tttb;
237 #else
238 col = (tttb << 24) + (tttg << 16) + (tttr << 8);
239 #endif
240 //kprintf("col[%d,%d] = %08x\n", x,y,col);
241 tab[y * SCREENWIDTH + x] = col;
243 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
245 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
247 WritePixelArray(tab, 0, 0, SCREENWIDTH * sizeof(LONG),
248 win->RPort, win->BorderLeft, win->BorderTop, SCREENWIDTH, SCREENHEIGHT,
249 RECTFMT_ARGB);
251 getevents();
253 } /* while(!Keys[KC_ESC]) */
256 /***********************************************************************************/
258 int main(void)
260 openlibs();
261 getvisual();
262 makewin();
263 action();
264 cleanup(0);
266 return 0; /* keep compiler happy */
269 /***********************************************************************************/