1 #include <cybergraphx/cybergraphics.h>
2 #include <graphics/gfxmacros.h>
5 #include <proto/exec.h>
6 #include <proto/graphics.h>
7 #include <proto/intuition.h>
8 #include <proto/cybergraphics.h>
14 struct Library
*PNGBase
;
17 LONG width
, height
, depth
, type
;
18 APTR paldata
, gfxdata
;
20 STRPTR wantedchunks
[] =
28 static void showimage(void)
30 win
= OpenWindowTags(0, WA_Title
, (IPTR
)"SimplePNG",
31 WA_InnerWidth
, width
+ 4,
32 WA_InnerHeight
, height
+ 4,
37 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_VANILLAKEY
,
41 if (GetBitMapAttr(win
->WScreen
->RastPort
.BitMap
, BMA_DEPTH
) >= 15)
65 WORD pen1
= ObtainBestPen(win
->WScreen
->ViewPort
.ColorMap
,
69 OBP_FailIfBad
, FALSE
);
70 WORD pen2
= ObtainBestPen(win
->WScreen
->ViewPort
.ColorMap
,
74 OBP_FailIfBad
, FALSE
);
76 SetAfPt(win
->RPort
, pat
, 4);
77 SetABPenDrMd(win
->RPort
, pen1
, pen2
, JAM2
);
78 RectFill(win
->RPort
, win
->BorderLeft
,
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
,
100 struct IntuiMessage
*msg
;
102 WaitPort(win
->UserPort
);
103 while((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
107 case IDCMP_CLOSEWINDOW
:
111 case IDCMP_VANILLAKEY
:
112 if (msg
->Code
== 27) quitme
= TRUE
;
116 ReplyMsg((struct Message
*)msg
);
124 int main(int argc
, char **argv
)
126 PNGBase
= OpenLibrary("datatypes/png.datatype", 0);
129 printf("Failed to open png.datatype!\n");
135 printf("Usage: simplepng <filename>\n");
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 width
, height
, depth
, type
);
148 printf("GfxData %p PalData %p\n", gfxdata
, paldata
);
155 PNG_GetChunkInfo(chunks
[0], (APTR
*) &data
, &size
);
157 printf("\nICON chunk found. Size %ld\n", size
);
161 ULONG tag
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
170 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
174 printf("Icon X Position: %ld\n", val
);
181 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
185 printf("Icon Y Position: %ld\n", val
);
192 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
196 printf("Drawer X Position: %ld\n", val
);
203 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
207 printf("Drawer Y Position: %ld\n", val
);
214 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
218 printf("Drawer Width: %ld\n", val
);
225 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
229 printf("Drawer Height: %ld\n", val
);
236 LONG val
= (data
[0] << 24) | (data
[1] << 16) | (data
[2] << 8) | data
[3];
240 printf("Drawer View/Type Flags: %lx\n", val
);
251 PNG_FreeChunk(chunks
[0]);
254 if (gfxdata
) showimage();
256 PNG_FreeImage(handle
);
259 CloseLibrary(PNGBase
);