timer.device: Use AROS_UFIx() macros
[AROS.git] / test / simplepng.c
blobddd2a5f2b2b1742c951232485f225e9c481e79cb
1 #include <cybergraphx/cybergraphics.h>
2 #include <graphics/gfxmacros.h>
4 #include <proto/png.h>
5 #include <proto/exec.h>
6 #include <proto/graphics.h>
7 #include <proto/intuition.h>
8 #include <proto/cybergraphics.h>
10 #include <stdio.h>
12 APTR handle;
14 struct Library *PNGBase;
15 struct Window *win;
17 LONG width, height, depth, type;
18 APTR paldata, gfxdata;
20 CONST_STRPTR wantedchunks[] =
22 "icOn",
23 NULL
26 APTR chunks[1];
28 static void showimage(void)
30 win = OpenWindowTags(0, WA_Title, (IPTR)"SimplePNG",
31 WA_InnerWidth, width + 4,
32 WA_InnerHeight, height + 4,
33 WA_CloseGadget, TRUE,
34 WA_DragBar, TRUE,
35 WA_DepthGadget, TRUE,
36 WA_Activate, TRUE,
37 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY,
38 TAG_DONE);
39 if (win)
41 if (GetBitMapAttr(win->WScreen->RastPort.BitMap, BMA_DEPTH) >= 15)
43 BOOL quitme = FALSE;
46 static UWORD pat[] =
48 0xFF00,
49 0xFF00,
50 0xFF00,
51 0xFF00,
52 0xFF00,
53 0xFF00,
54 0xFF00,
55 0xFF00,
56 0x00FF,
57 0x00FF,
58 0x00FF,
59 0x00FF,
60 0x00FF,
61 0x00FF,
62 0x00FF,
63 0x00FF
65 WORD pen1 = ObtainBestPen(win->WScreen->ViewPort.ColorMap,
66 0x6b6b6b6b,
67 0x6b6b6b6b,
68 0x6b6b6b6b,
69 OBP_FailIfBad, FALSE);
70 WORD pen2 = ObtainBestPen(win->WScreen->ViewPort.ColorMap,
71 0x9c9c9c9c,
72 0x9c9c9c9c,
73 0x9c9c9c9c,
74 OBP_FailIfBad, FALSE);
76 SetAfPt(win->RPort, pat, 4);
77 SetABPenDrMd(win->RPort, pen1, pen2, JAM2);
78 RectFill(win->RPort, win->BorderLeft,
79 win->BorderTop,
80 win->Width - 1 - win->BorderRight,
81 win->Height - 1 - win->BorderBottom);
82 SetAfPt(win->RPort, NULL, 0);
84 if (pen1 != -1) ReleasePen(win->WScreen->ViewPort.ColorMap, pen1);
85 if (pen2 != -1) ReleasePen(win->WScreen->ViewPort.ColorMap, pen2);
88 WritePixelArrayAlpha(gfxdata,
91 width * depth / 8,
92 win->RPort,
93 win->BorderLeft + 2,
94 win->BorderTop + 2,
95 width,
96 height,
97 0);
98 while(!quitme)
100 struct IntuiMessage *msg;
102 WaitPort(win->UserPort);
103 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
105 switch(msg->Class)
107 case IDCMP_CLOSEWINDOW:
108 quitme = TRUE;
109 break;
111 case IDCMP_VANILLAKEY:
112 if (msg->Code == 27) quitme = TRUE;
113 break;
116 ReplyMsg((struct Message *)msg);
120 CloseWindow(win);
124 int main(int argc, char **argv)
126 PNGBase = OpenLibrary("datatypes/png.datatype", 0);
127 if (!PNGBase)
129 printf("Failed to open png.datatype!\n");
130 return 0;
133 if (argc < 2)
135 printf("Usage: simplepng <filename>\n");
136 return 0;
139 if ((handle = PNG_LoadImage(argv[1], wantedchunks, chunks, TRUE)))
141 printf("PNG_LoadImage ok\n");
143 PNG_GetImageInfo(handle, &width, &height, &depth, &type);
144 PNG_GetImageData(handle, &gfxdata, &paldata);
146 printf("Width %ld Height %ld Depth %ld Type %ld\n",
147 (long)width, (long)height, (long)depth, (long)type);
148 printf("GfxData %p PalData %p\n", gfxdata, paldata);
150 if (chunks[0])
152 UBYTE *data;
153 ULONG size;
155 PNG_GetChunkInfo(chunks[0], (APTR *) &data, &size);
157 printf("\nICON chunk found. Size %ld\n", (long)size);
159 while(size >= 4)
161 ULONG tag = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
162 size -= 4;
163 data += 4;
165 switch(tag)
167 case 0x80001001:
168 if (size >= 4)
170 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
171 size -= 4;
172 data += 4;
174 printf("Icon X Position: %ld\n", (long)val);
176 break;
178 case 0x80001002:
179 if (size >= 4)
181 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
182 size -= 4;
183 data += 4;
185 printf("Icon Y Position: %ld\n", (long)val);
187 break;
189 case 0x80001003:
190 if (size >= 4)
192 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
193 size -= 4;
194 data += 4;
196 printf("Drawer X Position: %ld\n", (long)val);
198 break;
200 case 0x80001004:
201 if (size >= 4)
203 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
204 size -= 4;
205 data += 4;
207 printf("Drawer Y Position: %ld\n", (long)val);
209 break;
211 case 0x80001005:
212 if (size >= 4)
214 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
215 size -= 4;
216 data += 4;
218 printf("Drawer Width: %ld\n", (long)val);
220 break;
222 case 0x80001006:
223 if (size >= 4)
225 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
226 size -= 4;
227 data += 4;
229 printf("Drawer Height: %ld\n", (long)val);
231 break;
233 case 0x80001007:
234 if (size >= 4)
236 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
237 size -= 4;
238 data += 4;
240 printf("Drawer View/Type Flags: %lx\n", (unsigned long)val);
242 break;
251 PNG_FreeChunk(chunks[0]);
254 if (gfxdata) showimage();
256 PNG_FreeImage(handle);
259 CloseLibrary(PNGBase);
261 return 0;