• R/O
  • SSH

thirdparty-pngdib: Commit

A repository containing pngdib, which is planned to be incorporated into WinDirStat.

Its original home is over at http://entropymine.com/jason/pngdib/


Commit MetaInfo

Révision667e755bce233bcba7e7e26d0a1fad16140dfde8 (tree)
l'heure2014-01-18 13:21:42
AuteurOliver Schneider <oliver@assa...>
CommiterOliver Schneider

Message de Log

Moving in preparation for v3.0.1

Change Summary

Modification

diff -r fc50cede3040 -r 667e755bce23 bmp2png.c
--- a/bmp2png.c Sat Jan 18 04:19:04 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
1-// bmp2png.c
2-// A sample program that uses the PNGDIB library
3-// converts a BMP image file to a PNG image file
4-
5-#include <windows.h>
6-#include <stdio.h>
7-#include "pngdib.h"
8-
9-//#define DIB_ALPHA32
10-
11-// This is just a generic function to read a file into a memory block.
12-int read_bmp_to_mem(char *bmpfn,unsigned char **bmppp, DWORD *fsizep)
13-{
14- HANDLE hfile;
15- DWORD fsize;
16- unsigned char *fbuf;
17- DWORD bytesread;
18-
19- hfile=CreateFile(bmpfn,GENERIC_READ,FILE_SHARE_READ,NULL,
20- OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
21- if(hfile==INVALID_HANDLE_VALUE) return 1;
22-
23- fsize=GetFileSize(hfile,NULL);
24- if(fsize>0) {
25- fbuf=(unsigned char*)GlobalAlloc(GPTR,fsize);
26- if(fbuf) {
27- if(ReadFile(hfile,(void*)fbuf,fsize,&bytesread,NULL)) {
28- if(bytesread==fsize) {
29- (*bmppp) = fbuf;
30- (*fsizep) = fsize;
31- CloseHandle(hfile);
32- return 0; // success
33- }
34- }
35- GlobalFree((void*)fbuf);
36- }
37- }
38- CloseHandle(hfile);
39- return 1; // error
40-}
41-
42-
43-int main(int argc,char **argv)
44-{
45- char *bmpfn,*pngfn;
46- PNGD_D2PINFO d2p;
47- int ret;
48- unsigned char *bmpp;
49- DWORD bmpsize;
50- LPBITMAPFILEHEADER lpbmfh;
51- char errmsg[100];
52-
53- if(argc!=3) {
54- printf("Usage: %s <file.bmp> <file.png>\n",argv[0]);
55- return 1;
56- }
57- bmpfn=argv[1];
58- pngfn=argv[2];
59-
60-
61- if(read_bmp_to_mem(bmpfn,&bmpp, &bmpsize)) {
62- printf("can't read BMP from file\n");
63- return 1;
64- }
65-
66- ZeroMemory((void*)&d2p,sizeof(PNGD_D2PINFO));
67-
68- d2p.structsize=sizeof(PNGD_D2PINFO);
69-
70- d2p.flags=0;
71-#ifdef DIB_ALPHA32
72- d2p.flags |= PNGD_DIB_ALPHA32;
73-#endif
74-
75- d2p.pngfn=pngfn;
76-
77- // The first 14 bytes of a BMP file is a file header, the
78- // rest is a DIB.
79- d2p.lpdib = (LPBITMAPINFOHEADER)&bmpp[14];
80-
81- // This can be left at 0 if you know your DIB is valid.
82- d2p.dibsize = bmpsize-14;
83-
84- lpbmfh= (LPBITMAPFILEHEADER)bmpp;
85- if(lpbmfh->bfOffBits >= bmpsize) {
86- printf("Corrupt BMP\n");
87- return 1;
88- }
89-
90- // It's usually okay to leave lpbits set to NULL.
91- d2p.lpbits = &bmpp[lpbmfh->bfOffBits];
92-
93- // This can be left at 0 if you know your DIB is valid.
94- d2p.bitssize = bmpsize-lpbmfh->bfOffBits;
95-
96- d2p.software = "PNGDIB test app";
97- d2p.errmsg = errmsg; strcpy(errmsg,"");
98-
99- ret=write_dib_to_png(&d2p);
100- // returns 0 on success
101- if(ret) {
102- printf("Error: %s (%d)\n",d2p.errmsg,ret);
103- return 1;
104- }
105-
106- //
107- GlobalFree(bmpp);
108-
109- return 0;
110-}
111-
diff -r fc50cede3040 -r 667e755bce23 bmp2png/bmp2png.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bmp2png/bmp2png.c Sat Jan 18 04:21:42 2014 +0000
@@ -0,0 +1,111 @@
1+// bmp2png.c
2+// A sample program that uses the PNGDIB library
3+// converts a BMP image file to a PNG image file
4+
5+#include <windows.h>
6+#include <stdio.h>
7+#include "pngdib.h"
8+
9+//#define DIB_ALPHA32
10+
11+// This is just a generic function to read a file into a memory block.
12+int read_bmp_to_mem(char *bmpfn,unsigned char **bmppp, DWORD *fsizep)
13+{
14+ HANDLE hfile;
15+ DWORD fsize;
16+ unsigned char *fbuf;
17+ DWORD bytesread;
18+
19+ hfile=CreateFile(bmpfn,GENERIC_READ,FILE_SHARE_READ,NULL,
20+ OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
21+ if(hfile==INVALID_HANDLE_VALUE) return 1;
22+
23+ fsize=GetFileSize(hfile,NULL);
24+ if(fsize>0) {
25+ fbuf=(unsigned char*)GlobalAlloc(GPTR,fsize);
26+ if(fbuf) {
27+ if(ReadFile(hfile,(void*)fbuf,fsize,&bytesread,NULL)) {
28+ if(bytesread==fsize) {
29+ (*bmppp) = fbuf;
30+ (*fsizep) = fsize;
31+ CloseHandle(hfile);
32+ return 0; // success
33+ }
34+ }
35+ GlobalFree((void*)fbuf);
36+ }
37+ }
38+ CloseHandle(hfile);
39+ return 1; // error
40+}
41+
42+
43+int main(int argc,char **argv)
44+{
45+ char *bmpfn,*pngfn;
46+ PNGD_D2PINFO d2p;
47+ int ret;
48+ unsigned char *bmpp;
49+ DWORD bmpsize;
50+ LPBITMAPFILEHEADER lpbmfh;
51+ char errmsg[100];
52+
53+ if(argc!=3) {
54+ printf("Usage: %s <file.bmp> <file.png>\n",argv[0]);
55+ return 1;
56+ }
57+ bmpfn=argv[1];
58+ pngfn=argv[2];
59+
60+
61+ if(read_bmp_to_mem(bmpfn,&bmpp, &bmpsize)) {
62+ printf("can't read BMP from file\n");
63+ return 1;
64+ }
65+
66+ ZeroMemory((void*)&d2p,sizeof(PNGD_D2PINFO));
67+
68+ d2p.structsize=sizeof(PNGD_D2PINFO);
69+
70+ d2p.flags=0;
71+#ifdef DIB_ALPHA32
72+ d2p.flags |= PNGD_DIB_ALPHA32;
73+#endif
74+
75+ d2p.pngfn=pngfn;
76+
77+ // The first 14 bytes of a BMP file is a file header, the
78+ // rest is a DIB.
79+ d2p.lpdib = (LPBITMAPINFOHEADER)&bmpp[14];
80+
81+ // This can be left at 0 if you know your DIB is valid.
82+ d2p.dibsize = bmpsize-14;
83+
84+ lpbmfh= (LPBITMAPFILEHEADER)bmpp;
85+ if(lpbmfh->bfOffBits >= bmpsize) {
86+ printf("Corrupt BMP\n");
87+ return 1;
88+ }
89+
90+ // It's usually okay to leave lpbits set to NULL.
91+ d2p.lpbits = &bmpp[lpbmfh->bfOffBits];
92+
93+ // This can be left at 0 if you know your DIB is valid.
94+ d2p.bitssize = bmpsize-lpbmfh->bfOffBits;
95+
96+ d2p.software = "PNGDIB test app";
97+ d2p.errmsg = errmsg; strcpy(errmsg,"");
98+
99+ ret=write_dib_to_png(&d2p);
100+ // returns 0 on success
101+ if(ret) {
102+ printf("Error: %s (%d)\n",d2p.errmsg,ret);
103+ return 1;
104+ }
105+
106+ //
107+ GlobalFree(bmpp);
108+
109+ return 0;
110+}
111+
diff -r fc50cede3040 -r 667e755bce23 png2bmp.c
--- a/png2bmp.c Sat Jan 18 04:19:04 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
1-// png2dib.c
2-// sample using PNGDIB library
3-// convert a PNG image file to a BMP image file
4-
5-#include <windows.h>
6-#include <stdio.h>
7-#include "pngdib.h"
8-
9-//#define DIB_ALPHA32
10-
11-int write_dib_to_bmp(char *bmpfn, LPBITMAPINFOHEADER lpdib,
12- int dibsize, int bitsoffset)
13-{
14- HANDLE hfile;
15- BITMAPFILEHEADER h;
16- DWORD written, err;
17-
18- ZeroMemory((void*)&h,sizeof(h));
19- h.bfType= MAKEWORD('B','M');
20- h.bfSize= sizeof(BITMAPFILEHEADER)+dibsize;
21- h.bfOffBits= sizeof(BITMAPFILEHEADER)+bitsoffset;
22-
23- hfile=CreateFile(bmpfn,GENERIC_WRITE,FILE_SHARE_READ,NULL,
24- CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
25- if(hfile==INVALID_HANDLE_VALUE) return 1;
26-
27- if(!WriteFile(hfile,(void*)&h,sizeof(BITMAPFILEHEADER),&written,NULL)) {
28- err=GetLastError();
29- CloseHandle(hfile);
30- return 1;
31- }
32- if(!WriteFile(hfile,(void*)lpdib,dibsize,&written,NULL)) {
33- err=GetLastError();
34- CloseHandle(hfile);
35- return 1;
36- }
37- CloseHandle(hfile);
38- return 0;
39-}
40-
41-
42-int main(int argc,char **argv)
43-{
44- char *bmpfn,*pngfn;
45- PNGD_P2DINFO p2d;
46- int ret;
47- char errmsg[100];
48-
49-
50- if(argc!=3) {
51- printf("Usage: %s <file.png> <file.bmp>\n",argv[0]);
52- return 1;
53- }
54- pngfn=argv[1];
55- bmpfn=argv[2];
56-
57-
58- ZeroMemory((void*)&p2d,sizeof(PNGD_P2DINFO));
59-
60- p2d.structsize=sizeof(PNGD_P2DINFO);
61- p2d.flags=0;
62-#ifdef DIB_ALPHA32
63- p2d.flags |= PNGD_DIB_ALPHA32;
64-#else
65- p2d.flags |= PNGD_GAMMA_CORRECTION;
66-#endif
67- p2d.pngfn=pngfn; // name of the file to read
68- p2d.errmsg=errmsg; strcpy(errmsg,"");
69-
70- ret=read_png_to_dib(&p2d);
71- // returns 0 on success
72- if(ret) {
73- // see pngdib.h for a list of error codes
74- printf("Error: %s (%d)\n",errmsg,ret);
75- return 1;
76- }
77-
78- if(write_dib_to_bmp(bmpfn, p2d.lpdib, p2d.dibsize, p2d.bits_offs)) {
79- printf("Can't write BMP file\n");
80- }
81-
82- // The DIB will have been allocated with GlobalAlloc(GMEM_FIXED...).
83- // You should free it with GlobalFree when you're done with it.
84- GlobalFree((void*)p2d.lpdib);
85-
86- return 0;
87-}
diff -r fc50cede3040 -r 667e755bce23 png2bmp/png2bmp.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/png2bmp/png2bmp.c Sat Jan 18 04:21:42 2014 +0000
@@ -0,0 +1,87 @@
1+// png2dib.c
2+// sample using PNGDIB library
3+// convert a PNG image file to a BMP image file
4+
5+#include <windows.h>
6+#include <stdio.h>
7+#include "pngdib.h"
8+
9+//#define DIB_ALPHA32
10+
11+int write_dib_to_bmp(char *bmpfn, LPBITMAPINFOHEADER lpdib,
12+ int dibsize, int bitsoffset)
13+{
14+ HANDLE hfile;
15+ BITMAPFILEHEADER h;
16+ DWORD written, err;
17+
18+ ZeroMemory((void*)&h,sizeof(h));
19+ h.bfType= MAKEWORD('B','M');
20+ h.bfSize= sizeof(BITMAPFILEHEADER)+dibsize;
21+ h.bfOffBits= sizeof(BITMAPFILEHEADER)+bitsoffset;
22+
23+ hfile=CreateFile(bmpfn,GENERIC_WRITE,FILE_SHARE_READ,NULL,
24+ CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
25+ if(hfile==INVALID_HANDLE_VALUE) return 1;
26+
27+ if(!WriteFile(hfile,(void*)&h,sizeof(BITMAPFILEHEADER),&written,NULL)) {
28+ err=GetLastError();
29+ CloseHandle(hfile);
30+ return 1;
31+ }
32+ if(!WriteFile(hfile,(void*)lpdib,dibsize,&written,NULL)) {
33+ err=GetLastError();
34+ CloseHandle(hfile);
35+ return 1;
36+ }
37+ CloseHandle(hfile);
38+ return 0;
39+}
40+
41+
42+int main(int argc,char **argv)
43+{
44+ char *bmpfn,*pngfn;
45+ PNGD_P2DINFO p2d;
46+ int ret;
47+ char errmsg[100];
48+
49+
50+ if(argc!=3) {
51+ printf("Usage: %s <file.png> <file.bmp>\n",argv[0]);
52+ return 1;
53+ }
54+ pngfn=argv[1];
55+ bmpfn=argv[2];
56+
57+
58+ ZeroMemory((void*)&p2d,sizeof(PNGD_P2DINFO));
59+
60+ p2d.structsize=sizeof(PNGD_P2DINFO);
61+ p2d.flags=0;
62+#ifdef DIB_ALPHA32
63+ p2d.flags |= PNGD_DIB_ALPHA32;
64+#else
65+ p2d.flags |= PNGD_GAMMA_CORRECTION;
66+#endif
67+ p2d.pngfn=pngfn; // name of the file to read
68+ p2d.errmsg=errmsg; strcpy(errmsg,"");
69+
70+ ret=read_png_to_dib(&p2d);
71+ // returns 0 on success
72+ if(ret) {
73+ // see pngdib.h for a list of error codes
74+ printf("Error: %s (%d)\n",errmsg,ret);
75+ return 1;
76+ }
77+
78+ if(write_dib_to_bmp(bmpfn, p2d.lpdib, p2d.dibsize, p2d.bits_offs)) {
79+ printf("Can't write BMP file\n");
80+ }
81+
82+ // The DIB will have been allocated with GlobalAlloc(GMEM_FIXED...).
83+ // You should free it with GlobalFree when you're done with it.
84+ GlobalFree((void*)p2d.lpdib);
85+
86+ return 0;
87+}
Afficher sur ancien navigateur de dépôt.