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
;
34 ULONG cgfx_coltab
[256];
37 /***********************************************************************************/
39 static void cleanup(char *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
);
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!",
102 WA_DepthGadget
, TRUE
,
103 WA_CloseGadget
, TRUE
,
105 WA_ReportMouse
, TRUE
,
107 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_MOUSEMOVE
,
108 WA_BackFill
, (IPTR
)LAYERS_NOBACKFILL
,
111 if (!win
) cleanup("Can't open window");
115 bm
= AllocBitMap(win
->GZZWidth
, win
->GZZHeight
* 2, 0, 0, win
->RPort
->BitMap
);
118 struct RastPort temprp
;
120 InitRastPort(&temprp
);
123 ClipBlit(win
->RPort
, win
->BorderLeft
, win
->BorderTop
, &temprp
, 0, 0, win
->GZZWidth
, win
->GZZHeight
, 192);
127 /***********************************************************************************/
130 #define KC_RIGHT 0x4E
135 /***********************************************************************************/
138 static void getevents(void)
140 struct IntuiMessage
*msg
;
142 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
146 case IDCMP_CLOSEWINDOW
:
152 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
154 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
160 ReplyMsg((struct Message
*)msg
);
166 /***********************************************************************************/
168 static void action(void)
170 static LONG tab
[SCREENWIDTH
* SCREENHEIGHT
];
172 LONG ar1
, ar2
, ar3
, ar4
;
173 LONG ag1
, ag2
, ag3
, ag4
;
174 LONG ab1
, ab2
, ab3
, ab4
;
182 LONG ttr1
, ttg1
, ttb1
;
183 LONG ttr2
, ttg2
, ttb2
;
184 LONG tttr
, tttg
, tttb
, ttta
;
189 struct IntuiMessage
*msg
;
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;
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;
258 col
= (ttta
<< 24) + (tttr
<< 16) + (tttg
<< 8) + tttb
;
260 col
= (tttb
<< 24) + (tttg
<< 16) + (tttr
<< 8) + ttta
;
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 ++) */
272 struct RastPort temprp
;
274 InitRastPort(&temprp
);
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);
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
)))
298 case IDCMP_CLOSEWINDOW
:
303 ReplyMsg((struct Message
*)msg
);
310 /***********************************************************************************/
320 return 0; /* keep compiler happy */
323 /***********************************************************************************/