@@ -23,16 +23,11 @@ Please see the included GNU General Public License (GPL) for
23
23
#include " AtomicParsley.h"
24
24
#import < Cocoa/Cocoa.h>
25
25
26
- bool isJPEG = false ;
27
- bool isPNG = false ;
26
+ static void DetermineType ( const char *picfilePath, bool & isJPEG, bool &isPNG) {
27
+ char picHeader[ 20 ] ;
28
28
29
- void DetermineType (const char *picfilePath) {
30
- char *picHeader = (char *)calloc (1 , sizeof (char ) * 20 );
31
- u_int64_t r;
32
-
33
- FILE *pic_file = NULL ;
34
- pic_file = fopen (picfilePath, " rb" );
35
- r = fread (picHeader, 8 , 1 , pic_file);
29
+ FILE *pic_file = fopen (picfilePath, " rb" );
30
+ u_int64_t r = fread (picHeader, 8 , 1 , pic_file);
36
31
fclose (pic_file);
37
32
38
33
if (memcmp (picHeader, " \x89\x50\x4E\x47\x0D\x0A\x1A\x0A " , 8 ) == 0 ) {
@@ -41,13 +36,14 @@ void DetermineType(const char *picfilePath) {
41
36
} else if (memcmp (picHeader, " \xFF\xD8\xFF " , 3 ) == 0 ) {
42
37
isJPEG = true ;
43
38
isPNG = false ;
39
+ } else {
40
+ isPNG = false ;
41
+ isJPEG = false ;
44
42
}
45
- free (picHeader);
46
- picHeader = NULL ;
47
- return ;
48
43
}
49
44
50
- char *DeriveNewPath (const char *filePath, PicPrefs myPicPrefs, char *newpath) {
45
+ static char *
46
+ DeriveNewPath (const char *filePath, PicPrefs myPicPrefs, char *newpath) {
51
47
const char *suffix = strrchr (filePath, ' .' );
52
48
53
49
size_t filepath_len = strlen (filePath);
@@ -73,14 +69,6 @@ void DetermineType(const char *picfilePath) {
73
69
strcat (newpath, suffix);
74
70
}
75
71
76
- if ((strncmp (suffix, " .jpg" , 4 ) == 0 ) || (strncmp (suffix, " .jpeg" , 5 ) == 0 ) ||
77
- (strncmp (suffix, " .JPG" , 4 ) == 0 ) || (strncmp (suffix, " .JPEG" , 5 ) == 0 )) {
78
- isJPEG = true ;
79
- } else if ((strncmp (suffix, " .png" , 4 ) == 0 ) ||
80
- (strncmp (suffix, " .PNG" , 4 ) == 0 )) {
81
- isPNG = true ;
82
- }
83
-
84
72
free (randstring);
85
73
randstring = NULL ;
86
74
return newpath;
@@ -181,7 +169,8 @@ bool ResizeGivenImage(const char *filePath,
181
169
resize = true ;
182
170
}
183
171
184
- DetermineType (filePath);
172
+ bool isJPEG, isPNG;
173
+ DetermineType (filePath, isJPEG, isPNG);
185
174
if ((isJPEG && myPicPrefs.allPNG ) ||
186
175
(isPNG && myPicPrefs.allJPEG )) { // handle jpeg->png & png->jpg conversion
187
176
resize = true ;
@@ -248,8 +237,6 @@ bool ResizeGivenImage(const char *filePath,
248
237
249
238
[image unlockFocus ];
250
239
[image release ];
251
- isJPEG = false ;
252
- isPNG = false ;
253
240
memcpy (resized_path,
254
241
[outFile cStringUsingEncoding: NSUTF8StringEncoding],
255
242
[outFile lengthOfBytesUsingEncoding: NSUTF8StringEncoding]);
0 commit comments