From: David Maciejak <[email protected]>
load.c is used to identify the file format, I rebased some checks on
what is defined in the spec of the format.
---
wrlib/load.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/wrlib/load.c b/wrlib/load.c
index 0f6b268..73b2d95 100644
--- a/wrlib/load.c
+++ b/wrlib/load.c
@@ -33,10 +33,6 @@
#include <time.h>
#include <assert.h>
-#ifdef USE_PNG
-#include <png.h>
-#endif
-
#include "wraster.h"
#include "imgformat.h"
@@ -309,11 +305,16 @@ static WRImgFormat identFile(const char *path)
|| (buffer[0] == 'M' && buffer[1] == 'M' && buffer[2] == 0 &&
buffer[3] == '*'))
return IM_TIFF;
-#ifdef USE_PNG
- /* check for PNG */
- if (!png_sig_cmp(buffer, 0, 8))
+ /*
+ * check for PNG
+ *
+ * The signature is defined in the PNG specifiation:
+ * http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html
+ * it is valid for v1.0, v1.1, v1.2 and ISO version
+ */
+ if (buffer[0] == 137 && buffer[1] == 80 && buffer[2] == 78 && buffer[3]
== 71 &&
+ buffer[4] == 13 && buffer[5] == 10 && buffer[6] == 26 && buffer[7]
== 10)
return IM_PNG;
-#endif
/* check for PBM or PGM or PPM */
if (buffer[0] == 'P' && (buffer[1] > '0' && buffer[1] < '7') &&
(buffer[2] == 0x0a || buffer[2] == 0x20 || buffer[2] == 0x09 || buffer[2] ==
0x0d))
@@ -324,7 +325,8 @@ static WRImgFormat identFile(const char *path)
return IM_JPEG;
/* check for GIF */
- if (buffer[0] == 'G' && buffer[1] == 'I' && buffer[2] == 'F')
+ if (buffer[0] == 'G' && buffer[1] == 'I' && buffer[2] == 'F' &&
buffer[3] == '8' &&
+ (buffer[4] == '7' || buffer[4] == '9') && buffer[5] == 'a')
return IM_GIF;
return IM_UNKNOWN;
--
1.8.5.3
--
To unsubscribe, send mail to [email protected].