3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <cybergraphx/cybergraphics.h>
6 #include <proto/exec.h>
8 #include <proto/graphics.h>
9 #include <proto/cybergraphics.h>
10 #include <proto/intuition.h>
16 #define SCREENWIDTH 300
17 #define SCREENHEIGHT 200
18 #define SCREENCY (SCREENHEIGHT / 2)
20 /***********************************************************************************/
22 struct IntuitionBase
*IntuitionBase
;
23 struct GfxBase
*GfxBase
;
24 struct Library
*CyberGfxBase
;
30 ULONG cgfx_coltab
[256];
33 /***********************************************************************************/
35 static void cleanup(char *msg
)
39 printf("WritePixelArrayAlpha: %s\n",msg
);
42 if (bm
) FreeBitMap(bm
);
43 if (win
) CloseWindow(win
);
45 if (scr
) UnlockPubScreen(0, scr
);
47 if (CyberGfxBase
) CloseLibrary(CyberGfxBase
);
48 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
49 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
54 /***********************************************************************************/
56 static void openlibs(void)
58 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
60 cleanup("Can't open intuition.library V39!");
63 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
65 cleanup("Can't open graphics.library V39!");
68 if (!(CyberGfxBase
= OpenLibrary("cybergraphics.library",0)))
70 cleanup("Can't open cybergraphics.library!");
74 /***********************************************************************************/
76 static void getvisual(void)
78 if (!(scr
= LockPubScreen(NULL
)))
80 cleanup("Can't lock pub screen!");
83 if (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) <= 8)
85 cleanup("Need hi or true color screen!");
89 /***********************************************************************************/
91 static void makewin(void)
93 win
= OpenWindowTags(NULL
, WA_CustomScreen
, (IPTR
)scr
,
94 WA_InnerWidth
, SCREENWIDTH
,
95 WA_InnerHeight
, SCREENHEIGHT
,
96 WA_Title
, (IPTR
)"WritePixelArrayAlpha: Move mouse!",
98 WA_DepthGadget
, TRUE
,
99 WA_CloseGadget
, TRUE
,
101 WA_ReportMouse
, TRUE
,
103 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_MOUSEMOVE
,
104 WA_BackFill
, (IPTR
)LAYERS_NOBACKFILL
,
107 if (!win
) cleanup("Can't open window");
111 bm
= AllocBitMap(win
->GZZWidth
, win
->GZZHeight
* 2, 0, 0, win
->RPort
->BitMap
);
114 struct RastPort temprp
;
116 InitRastPort(&temprp
);
119 ClipBlit(win
->RPort
, win
->BorderLeft
, win
->BorderTop
, &temprp
, 0, 0, win
->GZZWidth
, win
->GZZHeight
, 192);
123 /***********************************************************************************/
126 #define KC_RIGHT 0x4E
131 /***********************************************************************************/
134 static void getevents(void)
136 struct IntuiMessage
*msg
;
138 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
142 case IDCMP_CLOSEWINDOW
:
148 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
150 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
156 ReplyMsg((struct Message
*)msg
);
162 /***********************************************************************************/
164 static void action(void)
166 static LONG tab
[SCREENWIDTH
* SCREENHEIGHT
];
168 LONG ar1
, ar2
, ar3
, ar4
;
169 LONG ag1
, ag2
, ag3
, ag4
;
170 LONG ab1
, ab2
, ab3
, ab4
;
178 LONG ttr1
, ttg1
, ttb1
;
179 LONG ttr2
, ttg2
, ttb2
;
180 LONG tttr
, tttg
, tttb
, ttta
;
185 struct IntuiMessage
*msg
;
189 ar1
= 0xFF; ag1
= 0xFF; ab1
= 0xFF;
190 ar2
= 0xFF; ag2
= 0x00; ab2
= 0x00;
191 ar3
= 0x00; ag3
= 0xFF; ab3
= 0x00;
192 ar4
= 0x00; ag4
= 0x00; ab4
= 0xFF;
194 r1
= 0xFF; g1
= 0xFF; b1
= 0xFF;
195 r2
= 0xFF; g2
= 0x00; b2
= 0x00;
196 r3
= 0x00; g3
= 0xFF; b3
= 0x00;
197 r4
= 0x00; g4
= 0x00; b4
= 0xFF;
200 if (x
< 0) x
= 0; else if (x
>= scr
->Width
) x
= scr
->Width
- 1;
202 r1
= ar1
+ (ar2
- ar1
) * x
/ (scr
->Width
- 1);
203 g1
= ag1
+ (ag2
- ag1
) * x
/ (scr
->Width
- 1);
204 b1
= ab1
+ (ab2
- ab1
) * x
/ (scr
->Width
- 1);
206 r2
= ar2
+ (ar3
- ar2
) * x
/ (scr
->Width
- 1);
207 g2
= ag2
+ (ag3
- ag2
) * x
/ (scr
->Width
- 1);
208 b2
= ab2
+ (ab3
- ab2
) * x
/ (scr
->Width
- 1);
210 r3
= ar3
+ (ar4
- ar3
) * x
/ (scr
->Width
- 1);
211 g3
= ag3
+ (ag4
- ag3
) * x
/ (scr
->Width
- 1);
212 b3
= ab3
+ (ab4
- ab3
) * x
/ (scr
->Width
- 1);
214 r4
= ar4
+ (ar1
- ar4
) * x
/ (scr
->Width
- 1);
215 g4
= ag4
+ (ag1
- ag4
) * x
/ (scr
->Width
- 1);
216 b4
= ab4
+ (ab1
- ab4
) * x
/ (scr
->Width
- 1);
218 ttta
= (scr
->MouseY
* 256) / (scr
->Height
);
219 if (ttta
< 0) ttta
= 0; else if (ttta
> 255) ttta
= 255;
221 for(y
= 0; y
< SCREENHEIGHT
; y
++)
223 for(x
= 0; x
< SCREENWIDTH
; x
++)
225 tr1
= r1
+ (r2
- r1
) * x
/ (SCREENWIDTH
- 1);
226 tg1
= g1
+ (g2
- g1
) * x
/ (SCREENWIDTH
- 1);
227 tb1
= b1
+ (b2
- b1
) * x
/ (SCREENWIDTH
- 1);
229 tr2
= r3
+ (r4
- r3
) * x
/ (SCREENWIDTH
- 1);
230 tg2
= g3
+ (g4
- g3
) * x
/ (SCREENWIDTH
- 1);
231 tb2
= b3
+ (b4
- b3
) * x
/ (SCREENWIDTH
- 1);
233 tr3
= r1
+ (r3
- r1
) * y
/ (SCREENHEIGHT
- 1);
234 tg3
= g1
+ (g3
- g1
) * y
/ (SCREENHEIGHT
- 1);
235 tb3
= b1
+ (b3
- b1
) * y
/ (SCREENHEIGHT
- 1);
237 tr4
= r2
+ (r4
- r2
) * y
/ (SCREENHEIGHT
- 1);
238 tg4
= g2
+ (g4
- g2
) * y
/ (SCREENHEIGHT
- 1);
239 tb4
= b2
+ (b4
- b2
) * y
/ (SCREENHEIGHT
- 1);
241 ttr1
= tr1
+ (tr2
- tr1
) * y
/ (SCREENHEIGHT
- 1);
242 ttg1
= tg1
+ (tg2
- tg1
) * y
/ (SCREENHEIGHT
- 1);
243 ttb1
= tb1
+ (tb2
- tb1
) * y
/ (SCREENHEIGHT
- 1);
245 ttr2
= tr3
+ (tr4
- tr3
) * x
/ (SCREENWIDTH
- 1);
246 ttg2
= tg3
+ (tg4
- tg3
) * x
/ (SCREENWIDTH
- 1);
247 ttb2
= tb3
+ (tb4
- tb3
) * x
/ (SCREENWIDTH
- 1);
249 tttr
= (ttr1
+ ttr2
) / 2;
250 tttg
= (ttg1
+ ttg2
) / 2;
251 tttb
= (ttb1
+ ttb2
) / 2;
254 col
= (ttta
<< 24) + (tttr
<< 16) + (tttg
<< 8) + tttb
;
256 col
= (tttb
<< 24) + (tttg
<< 16) + (tttr
<< 8) + ttta
;
258 //kprintf("col[%d,%d] = %08x\n", x,y,col);
259 tab
[y
* SCREENWIDTH
+ x
] = col
;
261 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
263 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
268 struct RastPort temprp
;
270 InitRastPort(&temprp
);
273 BltBitMap(bm
, 0, 0, bm
, 0, SCREENHEIGHT
, SCREENWIDTH
, SCREENHEIGHT
, 192, 255, 0);
275 WritePixelArrayAlpha(tab
, 0, 0, SCREENWIDTH
* sizeof(LONG
),
276 &temprp
, 0, SCREENHEIGHT
, SCREENWIDTH
, SCREENHEIGHT
,
279 BltBitMapRastPort(bm
, 0, SCREENHEIGHT
, win
->RPort
, win
->BorderLeft
, win
->BorderTop
, win
->GZZWidth
, win
->GZZHeight
, 192);
283 WritePixelArrayAlpha(tab
, 0, 0, SCREENWIDTH
* sizeof(LONG
),
284 win
->RPort
, win
->BorderLeft
, win
->BorderTop
, SCREENWIDTH
, SCREENHEIGHT
,
288 WaitPort(win
->UserPort
);
290 while((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
294 case IDCMP_CLOSEWINDOW
:
299 ReplyMsg((struct Message
*)msg
);
306 /***********************************************************************************/
316 return 0; /* keep compiler happy */
319 /***********************************************************************************/