2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
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>
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
;
33 ULONG cgfx_coltab
[256];
36 /***********************************************************************************/
38 static void cleanup(char *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
);
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!",
100 WA_DepthGadget
, TRUE
,
101 WA_CloseGadget
, TRUE
,
103 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
107 if (!win
) cleanup("Can't open window");
112 /***********************************************************************************/
115 #define KC_RIGHT 0x4E
120 /***********************************************************************************/
122 static void getevents(void)
124 struct IntuiMessage
*msg
;
126 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
130 case IDCMP_CLOSEWINDOW
:
136 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
138 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
144 ReplyMsg((struct Message
*)msg
);
149 /***********************************************************************************/
151 static void action(void)
153 static LONG tab
[SCREENWIDTH
* SCREENHEIGHT
];
155 LONG ar1
, ar2
, ar3
, ar4
;
156 LONG ag1
, ag2
, ag3
, ag4
;
157 LONG ab1
, ab2
, ab3
, ab4
;
165 LONG ttr1
, ttg1
, ttb1
;
166 LONG ttr2
, ttg2
, ttb2
;
167 LONG tttr
, tttg
, tttb
;
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;
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;
236 col
= (tttr
<< 16) + (tttg
<< 8) + tttb
;
238 col
= (tttb
<< 24) + (tttg
<< 16) + (tttr
<< 8);
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
,
253 } /* while(!Keys[KC_ESC]) */
256 /***********************************************************************************/
266 return 0; /* keep compiler happy */
269 /***********************************************************************************/