2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
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>
19 struct Library
*PNGBase
;
22 LONG width
, height
, depth
, type
;
23 APTR paldata
, gfxdata
;
25 CONST_STRPTR wantedchunks
[] =
33 static void showimage(void)
35 win
= OpenWindowTags(0, WA_Title
, (IPTR
)"SimplePNG",
36 WA_InnerWidth
, width
+ 4,
37 WA_InnerHeight
, height
+ 4,
42 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_VANILLAKEY
,
46 if (GetBitMapAttr(win
->WScreen
->RastPort
.BitMap
, BMA_DEPTH
) >= 15)
70 WORD pen1
= ObtainBestPen(win
->WScreen
->ViewPort
.ColorMap
,
74 OBP_FailIfBad
, FALSE
);
75 WORD pen2
= ObtainBestPen(win
->WScreen
->ViewPort
.ColorMap
,
79 OBP_FailIfBad
, FALSE
);
81 SetAfPt(win
->RPort
, pat
, 4);
82 SetABPenDrMd(win
->RPort
, pen1
, pen2
, JAM2
);
83 RectFill(win
->RPort
, win
->BorderLeft
,
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
,
105 struct IntuiMessage
*msg
;
107 WaitPort(win
->UserPort
);
108 while((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
112 case IDCMP_CLOSEWINDOW
:
116 case IDCMP_VANILLAKEY
:
117 if (msg
->Code
== 27) quitme
= TRUE
;
121 ReplyMsg((struct Message
*)msg
);
129 int main(int argc
, char **argv
)
131 PNGBase
= OpenLibrary("datatypes/png.datatype", 0);
134 printf("Failed to open png.datatype!\n");
140 printf("Usage: simplepng <filename>\n");
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
);
160 PNG_GetChunkInfo(chunks
[0], (APTR
*) &data
, &size
);
162 printf("\nICON chunk found. Size %ld\n", (long)size
);
166 ULONG tag
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
175 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
179 printf("Icon X Position: %ld\n", (long)val
);
186 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
190 printf("Icon Y Position: %ld\n", (long)val
);
197 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
201 printf("Drawer X Position: %ld\n", (long)val
);
208 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
212 printf("Drawer Y Position: %ld\n", (long)val
);
219 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
223 printf("Drawer Width: %ld\n", (long)val
);
230 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
234 printf("Drawer Height: %ld\n", (long)val
);
241 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
245 printf("Drawer View/Type Flags: %lx\n", (unsigned long)val
);
256 PNG_FreeChunk(chunks
[0]);
259 if (gfxdata
) showimage();
261 PNG_FreeImage(handle
);
264 CloseLibrary(PNGBase
);