r6308@lvps87-230-33-50: verhaegs | 2007-12-03 22:24:30 +0100
[AROS.git] / test / readpixelarray.c
blob0f2bf09f780ce6fc3559bf388bc1b33f3874e8ca
1 #include <exec/memory.h>
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <cybergraphx/cybergraphics.h>
6 #include <proto/exec.h>
7 #include <proto/dos.h>
8 #include <proto/graphics.h>
9 #include <proto/cybergraphics.h>
10 #include <proto/intuition.h>
12 #include <math.h>
13 #include <stdio.h>
14 #include <stdlib.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;
25 struct Screen *scr;
26 struct Window *win;
27 struct RastPort *rp;
29 ULONG cgfx_coltab[256];
30 UBYTE Keys[128];
32 /***********************************************************************************/
34 static void cleanup(char *msg)
36 if (msg)
38 printf("WritePixelArray: %s\n",msg);
41 if (win) CloseWindow(win);
43 if (scr) UnlockPubScreen(0, scr);
45 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
46 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
47 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
49 exit(0);
52 /***********************************************************************************/
54 static void openlibs(void)
56 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
58 cleanup("Can't open intuition.library V39!");
61 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
63 cleanup("Can't open graphics.library V39!");
66 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
68 cleanup("Can't open cybergraphics.library!");
72 /***********************************************************************************/
74 static void getvisual(void)
76 if (!(scr = LockPubScreen(NULL)))
78 cleanup("Can't lock pub screen!");
81 if (1)
83 LONG val;
85 val = GetCyberMapAttr(scr->RastPort.BitMap,CYBRMATTR_PIXFMT);
87 printf("cgfx attribute = %ld\n", val);
90 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
92 cleanup("Need hi or true color screen!");
97 /***********************************************************************************/
99 static void makewin(void)
101 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
102 WA_InnerWidth , SCREENWIDTH,
103 WA_InnerHeight , SCREENHEIGHT,
104 WA_Title , (IPTR)"ReadPixelArray",
105 WA_DragBar , TRUE,
106 WA_DepthGadget , TRUE,
107 WA_CloseGadget , TRUE,
108 WA_Activate , TRUE,
109 WA_BackFill , (IPTR)LAYERS_NOBACKFILL,
110 WA_IDCMP , IDCMP_CLOSEWINDOW |
111 IDCMP_RAWKEY,
112 TAG_DONE);
114 if (!win) cleanup("Can't open window");
116 rp = win->RPort;
119 /***********************************************************************************/
121 #define KC_LEFT 0x4F
122 #define KC_RIGHT 0x4E
123 #define KC_UP 0x4C
124 #define KC_DOWN 0x4D
125 #define KC_ESC 0x45
127 /***********************************************************************************/
129 static void getevents(void)
131 struct IntuiMessage *msg;
133 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
135 switch(msg->Class)
137 case IDCMP_CLOSEWINDOW:
138 Keys[KC_ESC] = 1;
139 break;
141 case IDCMP_RAWKEY:
143 WORD code = msg->Code & ~IECODE_UP_PREFIX;
145 Keys[code] = (code == msg->Code) ? 1 : 0;
148 break;
151 ReplyMsg((struct Message *)msg);
156 /***********************************************************************************/
158 static void action(void)
160 UBYTE *buf = AllocVec(SCREENWIDTH * SCREENHEIGHT * sizeof(ULONG), MEMF_PUBLIC);
161 ULONG i;
163 if (buf)
165 ReadPixelArray(buf,
168 SCREENWIDTH * sizeof(ULONG),
169 win->RPort,
170 win->BorderLeft,
171 win->BorderTop,
172 SCREENWIDTH,
173 SCREENHEIGHT,
174 RECTFMT_ARGB);
176 for(i = 0; i < SCREENWIDTH * SCREENHEIGHT * 4; i += 4)
178 buf[i + 1] /= 2;
179 buf[i + 2] /= 2;
180 buf[i + 3] /= 2;
183 WritePixelArray(buf,
186 SCREENWIDTH * sizeof(ULONG),
187 win->RPort,
188 win->BorderLeft,
189 win->BorderTop,
190 SCREENWIDTH,
191 SCREENHEIGHT,
192 RECTFMT_ARGB);
196 while (!Keys[KC_ESC])
198 WaitPort(win->UserPort);
199 getevents();
201 } /* while(!Keys[KC_ESC]) */
203 if (buf)
204 FreeVec(buf);
207 /***********************************************************************************/
209 int main(void)
211 openlibs();
212 getvisual();
213 makewin();
214 action();
215 cleanup(0);
217 return 0; /* keep compiler happy */
220 /***********************************************************************************/