intuition.library: implement EasyReqest and BuildEasyRequest that are x64/arm compatible
[AROS.git] / test / graphics / readpixelarray.c
blob405dc02c4360739108d79966d617b019868ae495
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/memory.h>
7 #include <dos/dos.h>
8 #include <intuition/intuition.h>
9 #include <graphics/gfx.h>
10 #include <cybergraphx/cybergraphics.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <proto/graphics.h>
14 #include <proto/cybergraphics.h>
15 #include <proto/intuition.h>
17 #include <math.h>
18 #include <stdio.h>
19 #include <stdlib.h>
21 #define SCREENWIDTH 300
22 #define SCREENHEIGHT 200
23 #define SCREENCY (SCREENHEIGHT / 2)
25 /***********************************************************************************/
27 struct IntuitionBase *IntuitionBase;
28 struct GfxBase *GfxBase;
29 struct Library *CyberGfxBase;
30 struct Screen *scr;
31 struct Window *win;
32 struct RastPort *rp;
34 ULONG cgfx_coltab[256];
35 UBYTE Keys[128];
37 /***********************************************************************************/
39 static void cleanup(char *msg)
41 if (msg)
43 printf("WritePixelArray: %s\n",msg);
46 if (win) CloseWindow(win);
48 if (scr) UnlockPubScreen(0, scr);
50 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
51 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
52 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
54 exit(0);
57 /***********************************************************************************/
59 static void openlibs(void)
61 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
63 cleanup("Can't open intuition.library V39!");
66 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
68 cleanup("Can't open graphics.library V39!");
71 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
73 cleanup("Can't open cybergraphics.library!");
77 /***********************************************************************************/
79 static void getvisual(void)
81 if (!(scr = LockPubScreen(NULL)))
83 cleanup("Can't lock pub screen!");
86 if (1)
88 LONG val;
90 val = GetCyberMapAttr(scr->RastPort.BitMap,CYBRMATTR_PIXFMT);
92 printf("cgfx attribute = %ld\n", (long)val);
95 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
97 cleanup("Need hi or true color screen!");
102 /***********************************************************************************/
104 static void makewin(void)
106 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
107 WA_InnerWidth , SCREENWIDTH,
108 WA_InnerHeight , SCREENHEIGHT,
109 WA_Title , (IPTR)"ReadPixelArray",
110 WA_DragBar , TRUE,
111 WA_DepthGadget , TRUE,
112 WA_CloseGadget , TRUE,
113 WA_Activate , TRUE,
114 WA_BackFill , (IPTR)LAYERS_NOBACKFILL,
115 WA_IDCMP , IDCMP_CLOSEWINDOW |
116 IDCMP_RAWKEY,
117 TAG_DONE);
119 if (!win) cleanup("Can't open window");
121 rp = win->RPort;
124 /***********************************************************************************/
126 #define KC_LEFT 0x4F
127 #define KC_RIGHT 0x4E
128 #define KC_UP 0x4C
129 #define KC_DOWN 0x4D
130 #define KC_ESC 0x45
132 /***********************************************************************************/
134 static void getevents(void)
136 struct IntuiMessage *msg;
138 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
140 switch(msg->Class)
142 case IDCMP_CLOSEWINDOW:
143 Keys[KC_ESC] = 1;
144 break;
146 case IDCMP_RAWKEY:
148 WORD code = msg->Code & ~IECODE_UP_PREFIX;
150 Keys[code] = (code == msg->Code) ? 1 : 0;
153 break;
156 ReplyMsg((struct Message *)msg);
161 /***********************************************************************************/
163 static void action(void)
165 UBYTE *buf = AllocVec(SCREENWIDTH * SCREENHEIGHT * sizeof(ULONG), MEMF_PUBLIC);
166 ULONG i;
168 if (buf)
170 ReadPixelArray(buf,
173 SCREENWIDTH * sizeof(ULONG),
174 win->RPort,
175 win->BorderLeft,
176 win->BorderTop,
177 SCREENWIDTH,
178 SCREENHEIGHT,
179 RECTFMT_ARGB);
181 for(i = 0; i < SCREENWIDTH * SCREENHEIGHT * 4; i += 4)
183 buf[i + 1] /= 2;
184 buf[i + 2] /= 2;
185 buf[i + 3] /= 2;
188 WritePixelArray(buf,
191 SCREENWIDTH * sizeof(ULONG),
192 win->RPort,
193 win->BorderLeft,
194 win->BorderTop,
195 SCREENWIDTH,
196 SCREENHEIGHT,
197 RECTFMT_ARGB);
201 while (!Keys[KC_ESC])
203 WaitPort(win->UserPort);
204 getevents();
206 } /* while(!Keys[KC_ESC]) */
208 FreeVec(buf);
211 /***********************************************************************************/
213 int main(void)
215 openlibs();
216 getvisual();
217 makewin();
218 action();
219 cleanup(0);
221 return 0; /* keep compiler happy */
224 /***********************************************************************************/