* Automatic generation of varargs stub for a function can now be disabled by
[AROS.git] / test / HiddGraphics / GCReadWritePixelDirect.c
bloba780a0ea0f1ea14aaa2abcea1adb38f82dcfa76b
1 /*
2 (C) 1998 AROS - The Amiga Research OS
3 $Id$
5 Desc: Test for graphics.hidd
6 Lang: english
7 */
9 /*****************************************************************************
11 NAME
13 GCReadWritePixelDirect
15 SYNOPSIS
17 GCReadWritePixelDirect HIDD/K,WIDTH/N/K,HEIGHT/N/K,DEPTH/N/K,CHUNKY/S,DISPLAYABLE=DP/S
19 LOCATION
21 test/HiddGraphics
23 FUNCTION
25 Creates a gc, writes and reads some pixels and disposes
26 the gc.
28 INPUTS
29 HIDD - name of the hidd to use e.g. "graphics-X11.hidd"
30 (default: graphics.hidd)
31 WIDTH - width of bitmap (default: 320)
32 HEIGHT - height of bitmap (default: 200)
33 DEPTH - depth of bitmap (default: 8)
34 CHUNKY - create bitmap in chunky-mode (default: planar)
35 DISPLAYABLE - show bitmap (default: FALSE)
37 RESULT
38 RETURN_OK - hidd works
39 RETURN_ERROR - hidd produce errors
40 RETURN_FAIL - could not test hidd i.e. OpenLibrary() fails
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
50 INTERNALS
52 HISTORY
54 ******************************************************************************/
56 #define AROS_USE_OOP
58 #include <stdlib.h>
59 #include <stdio.h>
61 #include <aros/config.h>
63 #include <exec/types.h>
65 #include <proto/exec.h>
66 #include <proto/dos.h>
67 #include <proto/oop.h>
68 #include <proto/utility.h>
70 #include <utility/tagitem.h>
72 #include <oop/oop.h>
73 #include <hidd/graphics.h>
74 #include <hidd/graphics-amiga-intuition.h>
76 #include "gfxhiddtool.h"
78 #undef SDEBUG
79 #define SDEBUG 0
80 #undef DEBUG
81 #define DEBUG 0
82 #include <aros/debug.h>
84 struct DosLibrary *DOSBase;
85 struct Library *OOPBase;
86 struct Library *HIDDGraphicsBase;
88 struct ght_OpenLibs LibsArray[] =
90 GHT_LIB("dos.library" , 37, &DOSBase),
91 GHT_LIB(AROSOOP_NAME , 0, &OOPBase),
92 GHT_LIB(NULL , 0, NULL)
94 /***************************************************************/
96 int main(int argc, char **argv)
98 ULONG ret = RETURN_FAIL;
100 OOP_AttrBase HiddGCAttrBase;
101 OOP_AttrBase HiddGfxAttrBase;
102 OOP_AttrBase HiddBitMapAttrBase;
104 struct pHidd_BitMap_GetPixel msg_ReadPixel;
105 struct pHidd_BitMap_PutPixel msg_WritePixel;
107 OOP_Object *gfxHidd;
108 OOP_Object *bitMap;
109 OOP_Object *gc;
111 STRPTR hiddName = "graphics.hidd";
112 ULONG width = 320;
113 ULONG height = 200;
114 ULONG depth = 8;
115 ULONG format = vHidd_BitMap_Format_Planar;
117 WORD x, y;
118 ULONG val;
119 char wait;
121 struct Args
123 STRPTR hiddName;
124 IPTR *width;
125 IPTR *height;
126 IPTR *depth;
127 IPTR *chunky;
128 ULONG displayable;
131 struct Args args = {hiddName, &width, &height, &depth, 0, 0};
132 struct RDArgs *rda;
135 if(ght_OpenLibs(LibsArray))
137 rda = ReadArgs("HIDD/K,WIDTH/N/K,HEIGHT/N/K,DEPTH/N/K,CHUNKY/S,DISPLAYABLE=DP/S", (IPTR *)&args, NULL);
138 if (rda != NULL)
140 if(args.chunky != 0) format = vHidd_BitMap_Format_Chunky;
141 if(args.displayable != 0) args.displayable = (ULONG) TRUE;
143 HIDDGraphicsBase = OpenLibrary(args.hiddName, 0);
144 if(HIDDGraphicsBase)
146 ret = RETURN_ERROR;
148 HiddGfxAttrBase = OOP_ObtainAttrBase(IID_Hidd_Gfx);
149 HiddBitMapAttrBase = OOP_ObtainAttrBase(IID_Hidd_BitMap);
150 HiddGCAttrBase = OOP_ObtainAttrBase(IID_Hidd_GC);
152 if(HiddGfxAttrBase && HiddBitMapAttrBase && HiddGCAttrBase)
154 gfxHidd = OOP_NewObject(NULL, args.hiddName, NULL);
155 if(gfxHidd)
157 struct TagItem bm_tags[] =
159 {aHidd_BitMap_Width, (IPTR) *args.width},
160 {aHidd_BitMap_Height, (IPTR) *args.height},
161 {aHidd_BitMap_Depth, (IPTR) *args.depth},
162 {aHidd_BitMap_Format, (IPTR) format},
163 {aHidd_BitMap_Displayable, (IPTR) args.displayable},
164 {TAG_DONE, 0UL}
167 bitMap = HIDD_Gfx_NewBitMap(gfxHidd, bm_tags);
168 if(bitMap)
170 struct TagItem gc_tags[] =
172 {aHidd_GC_BitMap, (IPTR) bitMap},
173 {TAG_DONE, 0UL}
176 gc = HIDD_Gfx_NewGC(gfxHidd, gc_tags);
177 if(gc)
179 msg_WritePixel.val = 0;
180 msg_WritePixel.mID = GetMethodID(IID_Hidd_BitMap, moHidd_BitMap_PutPixel);
181 msg_ReadPixel.mID = GetMethodID(IID_Hidd_BitMap, moHidd_BitMap_GetPixel);
183 for(x = 0; x < 30; x++)
185 msg_WritePixel.x = x;
186 msg_WritePixel.y = 1;
187 OOP_DoMethod(gc, (OOP_Msg) &msg_WritePixel);
190 for(y = 1; y < 11; y++)
192 for(x = 0; x < 10; x++)
194 printf(" x: %i y: %i val: %li ", x, y, msg_WritePixel.val);
195 msg_WritePixel.x = x;
196 msg_WritePixel.y = y;
197 DoMethod(gc, (Msg) &msg_WritePixel);
199 msg_ReadPixel.x = x;
200 msg_ReadPixel.y = y;
201 printf("ret: %li: ", (val = OOP_DoMethod(gc, (OOP_Msg) &msg_ReadPixel)));
202 if(msg_WritePixel.val == OOP_DoMethod(gc, (OOP_Msg) &msg_ReadPixel))
204 printf("OK\n");
206 else
208 printf("ERROR\n");
209 ret = RETURN_ERROR;
212 msg_WritePixel.val++;
216 printf("Press enter to continue");
217 scanf("%c", &wait);
219 HIDD_Gfx_DisposeGC(gfxHidd, gc);
221 ret = RETURN_OK;
224 HIDD_Gfx_DisposeBitMap(gfxHidd, bitMap);
227 if(gfxHidd) OOP_DisposeObject(gfxHidd);
229 } /* if(HiddGfxAttrBase && HiddBitMapAttrBase && HiddGCAttrBase) */
231 if(HiddGfxAttrBase) OOP_ReleaseAttrBase(IID_Hidd_Gfx);
232 if(HiddBitMapAttrBase) OOP_ReleaseAttrBase(IID_Hidd_BitMap);
233 if(HiddGCAttrBase) OOP_ReleaseAttrBase(IID_Hidd_GC);
235 CloseLibrary(HIDDGraphicsBase);
236 } /* if(HIDDGraphicsBase) */
237 FreeArgs(rda);
239 else
241 PrintFault(IoErr(), "");
242 } /* if (rda != NULL) */
243 } /* if OpenLibs() */
245 ght_CloseLibs(LibsArray);
247 return(ret);