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);
121 DeinitRastPort(&temprp
);
125 /***********************************************************************************/
128 #define KC_RIGHT 0x4E
133 /***********************************************************************************/
136 static void getevents(void)
138 struct IntuiMessage
*msg
;
140 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
144 case IDCMP_CLOSEWINDOW
:
150 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
152 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
158 ReplyMsg((struct Message
*)msg
);
164 /***********************************************************************************/
166 static void action(void)
168 static LONG tab
[SCREENWIDTH
* SCREENHEIGHT
];
170 LONG ar1
, ar2
, ar3
, ar4
;
171 LONG ag1
, ag2
, ag3
, ag4
;
172 LONG ab1
, ab2
, ab3
, ab4
;
180 LONG ttr1
, ttg1
, ttb1
;
181 LONG ttr2
, ttg2
, ttb2
;
182 LONG tttr
, tttg
, tttb
, ttta
;
187 struct IntuiMessage
*msg
;
191 ar1
= 0xFF; ag1
= 0xFF; ab1
= 0xFF;
192 ar2
= 0xFF; ag2
= 0x00; ab2
= 0x00;
193 ar3
= 0x00; ag3
= 0xFF; ab3
= 0x00;
194 ar4
= 0x00; ag4
= 0x00; ab4
= 0xFF;
196 r1
= 0xFF; g1
= 0xFF; b1
= 0xFF;
197 r2
= 0xFF; g2
= 0x00; b2
= 0x00;
198 r3
= 0x00; g3
= 0xFF; b3
= 0x00;
199 r4
= 0x00; g4
= 0x00; b4
= 0xFF;
202 if (x
< 0) x
= 0; else if (x
>= scr
->Width
) x
= scr
->Width
- 1;
204 r1
= ar1
+ (ar2
- ar1
) * x
/ (scr
->Width
- 1);
205 g1
= ag1
+ (ag2
- ag1
) * x
/ (scr
->Width
- 1);
206 b1
= ab1
+ (ab2
- ab1
) * x
/ (scr
->Width
- 1);
208 r2
= ar2
+ (ar3
- ar2
) * x
/ (scr
->Width
- 1);
209 g2
= ag2
+ (ag3
- ag2
) * x
/ (scr
->Width
- 1);
210 b2
= ab2
+ (ab3
- ab2
) * x
/ (scr
->Width
- 1);
212 r3
= ar3
+ (ar4
- ar3
) * x
/ (scr
->Width
- 1);
213 g3
= ag3
+ (ag4
- ag3
) * x
/ (scr
->Width
- 1);
214 b3
= ab3
+ (ab4
- ab3
) * x
/ (scr
->Width
- 1);
216 r4
= ar4
+ (ar1
- ar4
) * x
/ (scr
->Width
- 1);
217 g4
= ag4
+ (ag1
- ag4
) * x
/ (scr
->Width
- 1);
218 b4
= ab4
+ (ab1
- ab4
) * x
/ (scr
->Width
- 1);
220 ttta
= (scr
->MouseY
* 256) / (scr
->Height
);
221 if (ttta
< 0) ttta
= 0; else if (ttta
> 255) ttta
= 255;
223 for(y
= 0; y
< SCREENHEIGHT
; y
++)
225 for(x
= 0; x
< SCREENWIDTH
; x
++)
227 tr1
= r1
+ (r2
- r1
) * x
/ (SCREENWIDTH
- 1);
228 tg1
= g1
+ (g2
- g1
) * x
/ (SCREENWIDTH
- 1);
229 tb1
= b1
+ (b2
- b1
) * x
/ (SCREENWIDTH
- 1);
231 tr2
= r3
+ (r4
- r3
) * x
/ (SCREENWIDTH
- 1);
232 tg2
= g3
+ (g4
- g3
) * x
/ (SCREENWIDTH
- 1);
233 tb2
= b3
+ (b4
- b3
) * x
/ (SCREENWIDTH
- 1);
235 tr3
= r1
+ (r3
- r1
) * y
/ (SCREENHEIGHT
- 1);
236 tg3
= g1
+ (g3
- g1
) * y
/ (SCREENHEIGHT
- 1);
237 tb3
= b1
+ (b3
- b1
) * y
/ (SCREENHEIGHT
- 1);
239 tr4
= r2
+ (r4
- r2
) * y
/ (SCREENHEIGHT
- 1);
240 tg4
= g2
+ (g4
- g2
) * y
/ (SCREENHEIGHT
- 1);
241 tb4
= b2
+ (b4
- b2
) * y
/ (SCREENHEIGHT
- 1);
243 ttr1
= tr1
+ (tr2
- tr1
) * y
/ (SCREENHEIGHT
- 1);
244 ttg1
= tg1
+ (tg2
- tg1
) * y
/ (SCREENHEIGHT
- 1);
245 ttb1
= tg1
+ (tg2
- tg1
) * y
/ (SCREENHEIGHT
- 1);
247 ttr2
= tr3
+ (tr4
- tr3
) * x
/ (SCREENWIDTH
- 1);
248 ttg2
= tg3
+ (tg4
- tg3
) * x
/ (SCREENWIDTH
- 1);
249 ttb2
= tb3
+ (tb4
- tb3
) * x
/ (SCREENWIDTH
- 1);
251 tttr
= (ttr1
+ ttr2
) / 2;
252 tttg
= (ttg1
+ ttg2
) / 2;
253 tttb
= (ttb1
+ ttb2
) / 2;
256 col
= (ttta
<< 24) + (tttr
<< 16) + (tttg
<< 8) + tttb
;
258 col
= (tttb
<< 24) + (tttg
<< 16) + (tttr
<< 8) + ttta
;
260 //kprintf("col[%d,%d] = %08x\n", x,y,col);
261 tab
[y
* SCREENWIDTH
+ x
] = col
;
263 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
265 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
270 struct RastPort temprp
;
272 InitRastPort(&temprp
);
275 BltBitMap(bm
, 0, 0, bm
, 0, SCREENHEIGHT
, SCREENWIDTH
, SCREENHEIGHT
, 192, 255, 0);
277 WritePixelArrayAlpha(tab
, 0, 0, SCREENWIDTH
* sizeof(LONG
),
278 &temprp
, 0, SCREENHEIGHT
, SCREENWIDTH
, SCREENHEIGHT
,
281 BltBitMapRastPort(bm
, 0, SCREENHEIGHT
, win
->RPort
, win
->BorderLeft
, win
->BorderTop
, win
->GZZWidth
, win
->GZZHeight
, 192);
283 DeinitRastPort(&temprp
);
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 /***********************************************************************************/