start fleshing out the headers a little
[AROS.git] / test / graphics / scalepixelarray.c
blobce451a379d5e564e6e010df85b8c061a04344b03
1 /*
2 Copyright © 1995-2013, 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("ScalePixelArray: %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_MinWidth , 50,
99 WA_MinHeight , 50,
100 WA_MaxWidth , -1,
101 WA_MaxHeight , -1,
102 WA_Title , (IPTR)"ScalePixelArray: Resize window!",
103 WA_DragBar , TRUE,
104 WA_DepthGadget , TRUE,
105 WA_CloseGadget , TRUE,
106 WA_SizeGadget , TRUE,
107 WA_Activate , TRUE,
108 WA_IDCMP , IDCMP_CLOSEWINDOW |
109 IDCMP_RAWKEY |
110 IDCMP_NEWSIZE,
111 TAG_DONE);
113 if (!win) cleanup("Can't open window");
115 rp = win->RPort;
118 /***********************************************************************************/
120 #define KC_LEFT 0x4F
121 #define KC_RIGHT 0x4E
122 #define KC_UP 0x4C
123 #define KC_DOWN 0x4D
124 #define KC_ESC 0x45
126 /***********************************************************************************/
128 static void getevents(void)
130 struct IntuiMessage *msg;
132 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
134 switch(msg->Class)
136 case IDCMP_CLOSEWINDOW:
137 Keys[KC_ESC] = 1;
138 break;
140 case IDCMP_RAWKEY:
142 WORD code = msg->Code & ~IECODE_UP_PREFIX;
144 Keys[code] = (code == msg->Code) ? 1 : 0;
147 break;
150 ReplyMsg((struct Message *)msg);
155 /***********************************************************************************/
157 static void action(void)
159 static LONG tab[SCREENWIDTH * SCREENHEIGHT];
160 LONG x, y;
161 LONG ar1, ar2, ar3, ar4;
162 LONG ag1, ag2, ag3, ag4;
163 LONG ab1, ab2, ab3, ab4;
164 LONG r1, r2, r3, r4;
165 LONG g1, g2, g3, g4;
166 LONG b1, b2, b3, b4;
167 LONG tr1, tg1, tb1;
168 LONG tr2, tg2, tb2;
169 LONG tr3, tg3, tb3;
170 LONG tr4, tg4, tb4;
171 LONG ttr1, ttg1, ttb1;
172 LONG ttr2, ttg2, ttb2;
173 LONG tttr, tttg, tttb;
175 LONG col;
177 ar1 = 0xFF; ag1 = 0xFF; ab1 = 0xFF;
178 ar2 = 0xFF; ag2 = 0x00; ab2 = 0x00;
179 ar3 = 0x00; ag3 = 0xFF; ab3 = 0x00;
180 ar4 = 0x00; ag4 = 0x00; ab4 = 0xFF;
182 r1 = 0xFF; g1 = 0xFF; b1 = 0xFF;
183 r2 = 0xFF; g2 = 0x00; b2 = 0x00;
184 r3 = 0x00; g3 = 0xFF; b3 = 0x00;
185 r4 = 0x00; g4 = 0x00; b4 = 0xFF;
187 while(!Keys[KC_ESC])
189 x = scr->MouseX;
190 if (x < 0) x = 0; else if (x >= scr->Width) x = scr->Width - 1;
192 r1 = ar1 + (ar2 - ar1) * x / (scr->Width - 1);
193 g1 = ag1 + (ag2 - ag1) * x / (scr->Width - 1);
194 b1 = ab1 + (ab2 - ab1) * x / (scr->Width - 1);
196 r2 = ar2 + (ar3 - ar2) * x / (scr->Width - 1);
197 g2 = ag2 + (ag3 - ag2) * x / (scr->Width - 1);
198 b2 = ab2 + (ab3 - ab2) * x / (scr->Width - 1);
200 r3 = ar3 + (ar4 - ar3) * x / (scr->Width - 1);
201 g3 = ag3 + (ag4 - ag3) * x / (scr->Width - 1);
202 b3 = ab3 + (ab4 - ab3) * x / (scr->Width - 1);
204 r4 = ar4 + (ar1 - ar4) * x / (scr->Width - 1);
205 g4 = ag4 + (ag1 - ag4) * x / (scr->Width - 1);
206 b4 = ab4 + (ab1 - ab4) * x / (scr->Width - 1);
209 for(y = 0; y < SCREENHEIGHT; y ++)
211 for(x = 0; x < SCREENWIDTH; x++)
213 tr1 = r1 + (r2 - r1) * x / (SCREENWIDTH - 1);
214 tg1 = g1 + (g2 - g1) * x / (SCREENWIDTH - 1);
215 tb1 = b1 + (b2 - b1) * x / (SCREENWIDTH - 1);
217 tr2 = r3 + (r4 - r3) * x / (SCREENWIDTH - 1);
218 tg2 = g3 + (g4 - g3) * x / (SCREENWIDTH - 1);
219 tb2 = b3 + (b4 - b3) * x / (SCREENWIDTH - 1);
221 tr3 = r1 + (r3 - r1) * y / (SCREENHEIGHT - 1);
222 tg3 = g1 + (g3 - g1) * y / (SCREENHEIGHT - 1);
223 tb3 = b1 + (b3 - b1) * y / (SCREENHEIGHT - 1);
225 tr4 = r2 + (r4 - r2) * y / (SCREENHEIGHT - 1);
226 tg4 = g2 + (g4 - g2) * y / (SCREENHEIGHT - 1);
227 tb4 = b2 + (b4 - b2) * y / (SCREENHEIGHT - 1);
229 ttr1 = tr1 + (tr2 - tr1) * y / (SCREENHEIGHT - 1);
230 ttg1 = tg1 + (tg2 - tg1) * y / (SCREENHEIGHT - 1);
231 ttb1 = tb1 + (tb2 - tb1) * y / (SCREENHEIGHT - 1);
233 ttr2 = tr3 + (tr4 - tr3) * x / (SCREENWIDTH - 1);
234 ttg2 = tg3 + (tg4 - tg3) * x / (SCREENWIDTH - 1);
235 ttb2 = tb3 + (tb4 - tb3) * x / (SCREENWIDTH - 1);
237 tttr = (ttr1 + ttr2) / 2;
238 tttg = (ttg1 + ttg2) / 2;
239 tttb = (ttb1 + ttb2) / 2;
241 #if AROS_BIG_ENDIAN
242 col = (tttr << 16) + (tttg << 8) + tttb;
243 #else
244 col = (tttb << 24) + (tttg << 16) + (tttr << 8);
245 #endif
246 //kprintf("col[%d,%d] = %08x\n", x,y,col);
247 tab[y * SCREENWIDTH + x] = col;
249 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
251 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
253 ScalePixelArray(tab, SCREENWIDTH, SCREENHEIGHT,
254 SCREENWIDTH * sizeof(LONG), win->RPort,
255 win->BorderLeft, win->BorderTop,
256 win->Width - win->BorderLeft - win->BorderRight,
257 win->Height - win->BorderTop - win->BorderBottom, RECTFMT_ARGB);
259 getevents();
261 } /* while(!Keys[KC_ESC]) */
264 /***********************************************************************************/
266 int main(void)
268 openlibs();
269 getvisual();
270 makewin();
271 action();
272 cleanup(0);
274 return 0; /* keep compiler happy */
277 /***********************************************************************************/