Move UsbStdDevDesc back in stack now that it does not get trashed anymore, makes...
[AROS.git] / test / simplepng.c
blob04f33578831925d017d0aaf59e5a26560474dfd9
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <cybergraphx/cybergraphics.h>
7 #include <graphics/gfxmacros.h>
9 #include <proto/pngdt.h>
10 #include <proto/exec.h>
11 #include <proto/graphics.h>
12 #include <proto/intuition.h>
13 #include <proto/cybergraphics.h>
15 #include <stdio.h>
17 APTR handle;
19 struct Library *PNGBase;
20 struct Window *win;
22 LONG width, height, depth, type;
23 APTR paldata, gfxdata;
25 CONST_STRPTR wantedchunks[] =
27 "icOn",
28 NULL
31 APTR chunks[1];
33 static void showimage(void)
35 win = OpenWindowTags(0, WA_Title, (IPTR)"SimplePNG",
36 WA_InnerWidth, width + 4,
37 WA_InnerHeight, height + 4,
38 WA_CloseGadget, TRUE,
39 WA_DragBar, TRUE,
40 WA_DepthGadget, TRUE,
41 WA_Activate, TRUE,
42 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY,
43 TAG_DONE);
44 if (win)
46 if (GetBitMapAttr(win->WScreen->RastPort.BitMap, BMA_DEPTH) >= 15)
48 BOOL quitme = FALSE;
51 static UWORD pat[] =
53 0xFF00,
54 0xFF00,
55 0xFF00,
56 0xFF00,
57 0xFF00,
58 0xFF00,
59 0xFF00,
60 0xFF00,
61 0x00FF,
62 0x00FF,
63 0x00FF,
64 0x00FF,
65 0x00FF,
66 0x00FF,
67 0x00FF,
68 0x00FF
70 WORD pen1 = ObtainBestPen(win->WScreen->ViewPort.ColorMap,
71 0x6b6b6b6b,
72 0x6b6b6b6b,
73 0x6b6b6b6b,
74 OBP_FailIfBad, FALSE);
75 WORD pen2 = ObtainBestPen(win->WScreen->ViewPort.ColorMap,
76 0x9c9c9c9c,
77 0x9c9c9c9c,
78 0x9c9c9c9c,
79 OBP_FailIfBad, FALSE);
81 SetAfPt(win->RPort, pat, 4);
82 SetABPenDrMd(win->RPort, pen1, pen2, JAM2);
83 RectFill(win->RPort, win->BorderLeft,
84 win->BorderTop,
85 win->Width - 1 - win->BorderRight,
86 win->Height - 1 - win->BorderBottom);
87 SetAfPt(win->RPort, NULL, 0);
89 if (pen1 != -1) ReleasePen(win->WScreen->ViewPort.ColorMap, pen1);
90 if (pen2 != -1) ReleasePen(win->WScreen->ViewPort.ColorMap, pen2);
93 WritePixelArrayAlpha(gfxdata,
96 width * depth / 8,
97 win->RPort,
98 win->BorderLeft + 2,
99 win->BorderTop + 2,
100 width,
101 height,
103 while(!quitme)
105 struct IntuiMessage *msg;
107 WaitPort(win->UserPort);
108 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
110 switch(msg->Class)
112 case IDCMP_CLOSEWINDOW:
113 quitme = TRUE;
114 break;
116 case IDCMP_VANILLAKEY:
117 if (msg->Code == 27) quitme = TRUE;
118 break;
121 ReplyMsg((struct Message *)msg);
125 CloseWindow(win);
129 int main(int argc, char **argv)
131 PNGBase = OpenLibrary("datatypes/png.datatype", 0);
132 if (!PNGBase)
134 printf("Failed to open png.datatype!\n");
135 return 0;
138 if (argc < 2)
140 printf("Usage: simplepng <filename>\n");
141 return 0;
144 if ((handle = PNG_LoadImage(argv[1], wantedchunks, chunks, TRUE)))
146 printf("PNG_LoadImage ok\n");
148 PNG_GetImageInfo(handle, &width, &height, &depth, &type);
149 PNG_GetImageData(handle, &gfxdata, &paldata);
151 printf("Width %ld Height %ld Depth %ld Type %ld\n",
152 (long)width, (long)height, (long)depth, (long)type);
153 printf("GfxData %p PalData %p\n", gfxdata, paldata);
155 if (chunks[0])
157 UBYTE *data;
158 ULONG size;
160 PNG_GetChunkInfo(chunks[0], (APTR *) &data, &size);
162 printf("\nICON chunk found. Size %ld\n", (long)size);
164 while(size >= 4)
166 ULONG tag = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
167 size -= 4;
168 data += 4;
170 switch(tag)
172 case 0x80001001:
173 if (size >= 4)
175 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
176 size -= 4;
177 data += 4;
179 printf("Icon X Position: %ld\n", (long)val);
181 break;
183 case 0x80001002:
184 if (size >= 4)
186 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
187 size -= 4;
188 data += 4;
190 printf("Icon Y Position: %ld\n", (long)val);
192 break;
194 case 0x80001003:
195 if (size >= 4)
197 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
198 size -= 4;
199 data += 4;
201 printf("Drawer X Position: %ld\n", (long)val);
203 break;
205 case 0x80001004:
206 if (size >= 4)
208 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
209 size -= 4;
210 data += 4;
212 printf("Drawer Y Position: %ld\n", (long)val);
214 break;
216 case 0x80001005:
217 if (size >= 4)
219 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
220 size -= 4;
221 data += 4;
223 printf("Drawer Width: %ld\n", (long)val);
225 break;
227 case 0x80001006:
228 if (size >= 4)
230 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
231 size -= 4;
232 data += 4;
234 printf("Drawer Height: %ld\n", (long)val);
236 break;
238 case 0x80001007:
239 if (size >= 4)
241 LONG val = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
242 size -= 4;
243 data += 4;
245 printf("Drawer View/Type Flags: %lx\n", (unsigned long)val);
247 break;
256 PNG_FreeChunk(chunks[0]);
259 if (gfxdata) showimage();
261 PNG_FreeImage(handle);
264 CloseLibrary(PNGBase);
266 return 0;