Authored by Olivier Poitrey

Merge pull request #604 from akhenakh/webp_detect

Webp detect
  1 +//
  2 +// Created by Fabrice Aneche on 06/01/14.
  3 +// Copyright (c) 2014 Dailymotion. All rights reserved.
  4 +//
  5 +
  6 +#import <Foundation/Foundation.h>
  7 +
  8 +@interface NSData (ImageContentType)
  9 ++ (NSString *)contentTypeForImageData:(NSData *)data;
  10 +@end
  1 +//
  2 +// Created by Fabrice Aneche on 06/01/14.
  3 +// Copyright (c) 2014 Dailymotion. All rights reserved.
  4 +//
  5 +
  6 +#import "NSData+ImageContentType.h"
  7 +
  8 +
  9 +@implementation NSData (ImageContentType)
  10 +
  11 ++ (NSString *)contentTypeForImageData:(NSData *)data
  12 +{
  13 + uint8_t c;
  14 + [data getBytes:&c length:1];
  15 + switch (c)
  16 + {
  17 + case 0xFF:
  18 + return @"image/jpeg";
  19 + case 0x89:
  20 + return @"image/png";
  21 + case 0x47:
  22 + return @"image/gif";
  23 + case 0x49:
  24 + case 0x4D:
  25 + return @"image/tiff";
  26 + case 0x52:
  27 + // R as RIFF for WEBP
  28 + if ([data length] < 12)
  29 + {
  30 + return nil;
  31 + }
  32 +
  33 + NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
  34 + if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"])
  35 + {
  36 + return @"image/webp";
  37 + }
  38 +
  39 + return nil;
  40 + }
  41 + return nil;
  42 +}
  43 +
  44 +@end
@@ -22,6 +22,12 @@ @@ -22,6 +22,12 @@
22 /* End PBXAggregateTarget section */ 22 /* End PBXAggregateTarget section */
23 23
24 /* Begin PBXBuildFile section */ 24 /* Begin PBXBuildFile section */
  25 + 1797E364CA5D259B8CEDF8EE /* NSData+ImageContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 1797E851007E466318B38B47 /* NSData+ImageContentType.h */; };
  26 + 1797E37E262405DB1BFEDFFC /* NSData+ImageContentType.m in Sources */ = {isa = PBXBuildFile; fileRef = 1797E3D4E27D504ACD827BE1 /* NSData+ImageContentType.m */; };
  27 + 1797E59FBF11E6588BC89B66 /* NSData+ImageContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 1797E851007E466318B38B47 /* NSData+ImageContentType.h */; };
  28 + 1797E75161F3C9E8494E43E6 /* NSData+ImageContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 1797E851007E466318B38B47 /* NSData+ImageContentType.h */; };
  29 + 1797EBFB62F22E5C0A26A75D /* NSData+ImageContentType.m in Sources */ = {isa = PBXBuildFile; fileRef = 1797E3D4E27D504ACD827BE1 /* NSData+ImageContentType.m */; };
  30 + 1797ED4CD80EA8BD405365C3 /* NSData+ImageContentType.m in Sources */ = {isa = PBXBuildFile; fileRef = 1797E3D4E27D504ACD827BE1 /* NSData+ImageContentType.m */; };
25 530E49E816464C25002868E7 /* SDWebImageOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E71646388E002868E7 /* SDWebImageOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 31 530E49E816464C25002868E7 /* SDWebImageOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E71646388E002868E7 /* SDWebImageOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
26 530E49E916464C26002868E7 /* SDWebImageOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E71646388E002868E7 /* SDWebImageOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 32 530E49E916464C26002868E7 /* SDWebImageOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E71646388E002868E7 /* SDWebImageOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
27 530E49EA16464C7C002868E7 /* SDWebImageDownloaderOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E316460AE2002868E7 /* SDWebImageDownloaderOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 33 530E49EA16464C7C002868E7 /* SDWebImageDownloaderOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E316460AE2002868E7 /* SDWebImageDownloaderOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -77,7 +83,6 @@ @@ -77,7 +83,6 @@
77 537D957C17ECC1FE0097C263 /* SDWebImageDownloaderOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 530E49E416460AE2002868E7 /* SDWebImageDownloaderOperation.m */; }; 83 537D957C17ECC1FE0097C263 /* SDWebImageDownloaderOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 530E49E416460AE2002868E7 /* SDWebImageDownloaderOperation.m */; };
78 537D957D17ECC1FE0097C263 /* SDWebImageCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = 5340674F167780C40042B59E /* SDWebImageCompat.m */; }; 84 537D957D17ECC1FE0097C263 /* SDWebImageCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = 5340674F167780C40042B59E /* SDWebImageCompat.m */; };
79 537D957E17ECC1FE0097C263 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; }; 85 537D957E17ECC1FE0097C263 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; };
80 - 537D957F17ECC1FE0097C263 /* NSData+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CCC172DC33A00419892 /* NSData+GIF.m */; };  
81 537D958017ECC1FE0097C263 /* UIImage+MultiFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 53EDFB8917623F7C00698166 /* UIImage+MultiFormat.m */; }; 86 537D958017ECC1FE0097C263 /* UIImage+MultiFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 53EDFB8917623F7C00698166 /* UIImage+MultiFormat.m */; };
82 537D958117ECC1FE0097C263 /* UIImage+WebP.m in Sources */ = {isa = PBXBuildFile; fileRef = 53EDFB921762547C00698166 /* UIImage+WebP.m */; }; 87 537D958117ECC1FE0097C263 /* UIImage+WebP.m in Sources */ = {isa = PBXBuildFile; fileRef = 53EDFB921762547C00698166 /* UIImage+WebP.m */; };
83 537D958217ECC1FE0097C263 /* webp.c in Sources */ = {isa = PBXBuildFile; fileRef = 53EDFC9117625BE300698166 /* webp.c */; }; 88 537D958217ECC1FE0097C263 /* webp.c in Sources */ = {isa = PBXBuildFile; fileRef = 53EDFC9117625BE300698166 /* webp.c */; };
@@ -119,7 +124,6 @@ @@ -119,7 +124,6 @@
119 537D95A817ECC1FE0097C263 /* SDWebImageOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E71646388E002868E7 /* SDWebImageOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 124 537D95A817ECC1FE0097C263 /* SDWebImageOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E71646388E002868E7 /* SDWebImageOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
120 537D95A917ECC1FE0097C263 /* SDWebImageDownloaderOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E316460AE2002868E7 /* SDWebImageDownloaderOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 125 537D95A917ECC1FE0097C263 /* SDWebImageDownloaderOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 530E49E316460AE2002868E7 /* SDWebImageDownloaderOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
121 537D95AA17ECC1FE0097C263 /* UIImage+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CC5172DC28500419892 /* UIImage+GIF.h */; }; 126 537D95AA17ECC1FE0097C263 /* UIImage+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CC5172DC28500419892 /* UIImage+GIF.h */; };
122 - 537D95AB17ECC1FE0097C263 /* NSData+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CCB172DC33A00419892 /* NSData+GIF.h */; };  
123 537D95AC17ECC1FE0097C263 /* UIImage+MultiFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */; }; 127 537D95AC17ECC1FE0097C263 /* UIImage+MultiFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */; };
124 537D95AD17ECC1FE0097C263 /* UIImage+WebP.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EDFB911762547C00698166 /* UIImage+WebP.h */; }; 128 537D95AD17ECC1FE0097C263 /* UIImage+WebP.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EDFB911762547C00698166 /* UIImage+WebP.h */; };
125 537D95AE17ECC1FE0097C263 /* webpi.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EDFC9017625BE300698166 /* webpi.h */; }; 129 537D95AE17ECC1FE0097C263 /* webpi.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EDFC9017625BE300698166 /* webpi.h */; };
@@ -187,10 +191,6 @@ @@ -187,10 +191,6 @@
187 A18A6CC8172DC28500419892 /* UIImage+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CC5172DC28500419892 /* UIImage+GIF.h */; }; 191 A18A6CC8172DC28500419892 /* UIImage+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CC5172DC28500419892 /* UIImage+GIF.h */; };
188 A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; }; 192 A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; };
189 A18A6CCA172DC28500419892 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; }; 193 A18A6CCA172DC28500419892 /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CC6172DC28500419892 /* UIImage+GIF.m */; };
190 - A18A6CCD172DC33A00419892 /* NSData+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CCB172DC33A00419892 /* NSData+GIF.h */; };  
191 - A18A6CCE172DC33A00419892 /* NSData+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CCB172DC33A00419892 /* NSData+GIF.h */; };  
192 - A18A6CCF172DC33A00419892 /* NSData+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CCC172DC33A00419892 /* NSData+GIF.m */; };  
193 - A18A6CD0172DC33A00419892 /* NSData+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = A18A6CCC172DC33A00419892 /* NSData+GIF.m */; };  
194 /* End PBXBuildFile section */ 194 /* End PBXBuildFile section */
195 195
196 /* Begin PBXContainerItemProxy section */ 196 /* Begin PBXContainerItemProxy section */
@@ -204,6 +204,8 @@ @@ -204,6 +204,8 @@
204 /* End PBXContainerItemProxy section */ 204 /* End PBXContainerItemProxy section */
205 205
206 /* Begin PBXFileReference section */ 206 /* Begin PBXFileReference section */
  207 + 1797E3D4E27D504ACD827BE1 /* NSData+ImageContentType.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+ImageContentType.m"; sourceTree = SOURCE_ROOT; };
  208 + 1797E851007E466318B38B47 /* NSData+ImageContentType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+ImageContentType.h"; sourceTree = SOURCE_ROOT; };
207 530E49E316460AE2002868E7 /* SDWebImageDownloaderOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageDownloaderOperation.h; sourceTree = "<group>"; }; 209 530E49E316460AE2002868E7 /* SDWebImageDownloaderOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageDownloaderOperation.h; sourceTree = "<group>"; };
208 530E49E416460AE2002868E7 /* SDWebImageDownloaderOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDownloaderOperation.m; sourceTree = "<group>"; }; 210 530E49E416460AE2002868E7 /* SDWebImageDownloaderOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDownloaderOperation.m; sourceTree = "<group>"; };
209 530E49E71646388E002868E7 /* SDWebImageOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageOperation.h; sourceTree = "<group>"; }; 211 530E49E71646388E002868E7 /* SDWebImageOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageOperation.h; sourceTree = "<group>"; };
@@ -277,8 +279,6 @@ @@ -277,8 +279,6 @@
277 53FB894814D35E9E0020B787 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 279 53FB894814D35E9E0020B787 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
278 A18A6CC5172DC28500419892 /* UIImage+GIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+GIF.h"; sourceTree = "<group>"; }; 280 A18A6CC5172DC28500419892 /* UIImage+GIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+GIF.h"; sourceTree = "<group>"; };
279 A18A6CC6172DC28500419892 /* UIImage+GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+GIF.m"; sourceTree = "<group>"; }; 281 A18A6CC6172DC28500419892 /* UIImage+GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+GIF.m"; sourceTree = "<group>"; };
280 - A18A6CCB172DC33A00419892 /* NSData+GIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+GIF.h"; sourceTree = "<group>"; };  
281 - A18A6CCC172DC33A00419892 /* NSData+GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+GIF.m"; sourceTree = "<group>"; };  
282 /* End PBXFileReference section */ 282 /* End PBXFileReference section */
283 283
284 /* Begin PBXFrameworksBuildPhase section */ 284 /* Begin PBXFrameworksBuildPhase section */
@@ -365,8 +365,6 @@ @@ -365,8 +365,6 @@
365 children = ( 365 children = (
366 53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */, 366 53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */,
367 53EDFB8917623F7C00698166 /* UIImage+MultiFormat.m */, 367 53EDFB8917623F7C00698166 /* UIImage+MultiFormat.m */,
368 - A18A6CCB172DC33A00419892 /* NSData+GIF.h */,  
369 - A18A6CCC172DC33A00419892 /* NSData+GIF.m */,  
370 A18A6CC5172DC28500419892 /* UIImage+GIF.h */, 368 A18A6CC5172DC28500419892 /* UIImage+GIF.h */,
371 A18A6CC6172DC28500419892 /* UIImage+GIF.m */, 369 A18A6CC6172DC28500419892 /* UIImage+GIF.m */,
372 53EDFB911762547C00698166 /* UIImage+WebP.h */, 370 53EDFB911762547C00698166 /* UIImage+WebP.h */,
@@ -377,6 +375,8 @@ @@ -377,6 +375,8 @@
377 53922D94148C56230056699D /* UIButton+WebCache.m */, 375 53922D94148C56230056699D /* UIButton+WebCache.m */,
378 53922D95148C56230056699D /* UIImageView+WebCache.h */, 376 53922D95148C56230056699D /* UIImageView+WebCache.h */,
379 53922D96148C56230056699D /* UIImageView+WebCache.m */, 377 53922D96148C56230056699D /* UIImageView+WebCache.m */,
  378 + 1797E851007E466318B38B47 /* NSData+ImageContentType.h */,
  379 + 1797E3D4E27D504ACD827BE1 /* NSData+ImageContentType.m */,
380 ); 380 );
381 name = Categories; 381 name = Categories;
382 sourceTree = "<group>"; 382 sourceTree = "<group>";
@@ -504,7 +504,6 @@ @@ -504,7 +504,6 @@
504 530E49E916464C26002868E7 /* SDWebImageOperation.h in Headers */, 504 530E49E916464C26002868E7 /* SDWebImageOperation.h in Headers */,
505 530E49EB16464C7F002868E7 /* SDWebImageDownloaderOperation.h in Headers */, 505 530E49EB16464C7F002868E7 /* SDWebImageDownloaderOperation.h in Headers */,
506 A18A6CC8172DC28500419892 /* UIImage+GIF.h in Headers */, 506 A18A6CC8172DC28500419892 /* UIImage+GIF.h in Headers */,
507 - A18A6CCE172DC33A00419892 /* NSData+GIF.h in Headers */,  
508 53EDFB8B17623F7C00698166 /* UIImage+MultiFormat.h in Headers */, 507 53EDFB8B17623F7C00698166 /* UIImage+MultiFormat.h in Headers */,
509 53E481E017C300F6003E8957 /* alpha_processing.h in Headers */, 508 53E481E017C300F6003E8957 /* alpha_processing.h in Headers */,
510 53EDFB941762547D00698166 /* UIImage+WebP.h in Headers */, 509 53EDFB941762547D00698166 /* UIImage+WebP.h in Headers */,
@@ -522,6 +521,7 @@ @@ -522,6 +521,7 @@
522 53EDFCF617625F4100698166 /* utils.h in Headers */, 521 53EDFCF617625F4100698166 /* utils.h in Headers */,
523 53EDFCFC17625F5F00698166 /* filters.h in Headers */, 522 53EDFCFC17625F5F00698166 /* filters.h in Headers */,
524 53EDFD0217625F7900698166 /* thread.h in Headers */, 523 53EDFD0217625F7900698166 /* thread.h in Headers */,
  524 + 1797E75161F3C9E8494E43E6 /* NSData+ImageContentType.h in Headers */,
525 ); 525 );
526 runOnlyForDeploymentPostprocessing = 0; 526 runOnlyForDeploymentPostprocessing = 0;
527 }; 527 };
@@ -540,8 +540,8 @@ @@ -540,8 +540,8 @@
540 530E49E816464C25002868E7 /* SDWebImageOperation.h in Headers */, 540 530E49E816464C25002868E7 /* SDWebImageOperation.h in Headers */,
541 530E49EA16464C7C002868E7 /* SDWebImageDownloaderOperation.h in Headers */, 541 530E49EA16464C7C002868E7 /* SDWebImageDownloaderOperation.h in Headers */,
542 A18A6CC7172DC28500419892 /* UIImage+GIF.h in Headers */, 542 A18A6CC7172DC28500419892 /* UIImage+GIF.h in Headers */,
543 - A18A6CCD172DC33A00419892 /* NSData+GIF.h in Headers */,  
544 53EDFB8A17623F7C00698166 /* UIImage+MultiFormat.h in Headers */, 543 53EDFB8A17623F7C00698166 /* UIImage+MultiFormat.h in Headers */,
  544 + 1797E59FBF11E6588BC89B66 /* NSData+ImageContentType.h in Headers */,
545 ); 545 );
546 runOnlyForDeploymentPostprocessing = 0; 546 runOnlyForDeploymentPostprocessing = 0;
547 }; 547 };
@@ -560,7 +560,6 @@ @@ -560,7 +560,6 @@
560 537D95A817ECC1FE0097C263 /* SDWebImageOperation.h in Headers */, 560 537D95A817ECC1FE0097C263 /* SDWebImageOperation.h in Headers */,
561 537D95A917ECC1FE0097C263 /* SDWebImageDownloaderOperation.h in Headers */, 561 537D95A917ECC1FE0097C263 /* SDWebImageDownloaderOperation.h in Headers */,
562 537D95AA17ECC1FE0097C263 /* UIImage+GIF.h in Headers */, 562 537D95AA17ECC1FE0097C263 /* UIImage+GIF.h in Headers */,
563 - 537D95AB17ECC1FE0097C263 /* NSData+GIF.h in Headers */,  
564 537D95AC17ECC1FE0097C263 /* UIImage+MultiFormat.h in Headers */, 563 537D95AC17ECC1FE0097C263 /* UIImage+MultiFormat.h in Headers */,
565 537D95AD17ECC1FE0097C263 /* UIImage+WebP.h in Headers */, 564 537D95AD17ECC1FE0097C263 /* UIImage+WebP.h in Headers */,
566 537D95AE17ECC1FE0097C263 /* webpi.h in Headers */, 565 537D95AE17ECC1FE0097C263 /* webpi.h in Headers */,
@@ -578,6 +577,7 @@ @@ -578,6 +577,7 @@
578 537D95BA17ECC1FE0097C263 /* utils.h in Headers */, 577 537D95BA17ECC1FE0097C263 /* utils.h in Headers */,
579 537D95BB17ECC1FE0097C263 /* filters.h in Headers */, 578 537D95BB17ECC1FE0097C263 /* filters.h in Headers */,
580 537D95BC17ECC1FE0097C263 /* thread.h in Headers */, 579 537D95BC17ECC1FE0097C263 /* thread.h in Headers */,
  580 + 1797E364CA5D259B8CEDF8EE /* NSData+ImageContentType.h in Headers */,
581 ); 581 );
582 runOnlyForDeploymentPostprocessing = 0; 582 runOnlyForDeploymentPostprocessing = 0;
583 }; 583 };
@@ -726,7 +726,6 @@ @@ -726,7 +726,6 @@
726 531041CB157EAFA400BBABC3 /* MKAnnotationView+WebCache.m in Sources */, 726 531041CB157EAFA400BBABC3 /* MKAnnotationView+WebCache.m in Sources */,
727 530E49ED16464C84002868E7 /* SDWebImageDownloaderOperation.m in Sources */, 727 530E49ED16464C84002868E7 /* SDWebImageDownloaderOperation.m in Sources */,
728 A18A6CCA172DC28500419892 /* UIImage+GIF.m in Sources */, 728 A18A6CCA172DC28500419892 /* UIImage+GIF.m in Sources */,
729 - A18A6CD0172DC33A00419892 /* NSData+GIF.m in Sources */,  
730 53EDFB8D17623F7C00698166 /* UIImage+MultiFormat.m in Sources */, 729 53EDFB8D17623F7C00698166 /* UIImage+MultiFormat.m in Sources */,
731 53EDFB961762547D00698166 /* UIImage+WebP.m in Sources */, 730 53EDFB961762547D00698166 /* UIImage+WebP.m in Sources */,
732 53EDFC9517625BE300698166 /* webp.c in Sources */, 731 53EDFC9517625BE300698166 /* webp.c in Sources */,
@@ -754,6 +753,7 @@ @@ -754,6 +753,7 @@
754 53EDFCF817625F4100698166 /* utils.c in Sources */, 753 53EDFCF817625F4100698166 /* utils.c in Sources */,
755 53EDFCFE17625F5F00698166 /* filters.c in Sources */, 754 53EDFCFE17625F5F00698166 /* filters.c in Sources */,
756 53EDFD0417625F7900698166 /* thread.c in Sources */, 755 53EDFD0417625F7900698166 /* thread.c in Sources */,
  756 + 1797EBFB62F22E5C0A26A75D /* NSData+ImageContentType.m in Sources */,
757 ); 757 );
758 runOnlyForDeploymentPostprocessing = 0; 758 runOnlyForDeploymentPostprocessing = 0;
759 }; 759 };
@@ -771,8 +771,8 @@ @@ -771,8 +771,8 @@
771 530E49EC16464C84002868E7 /* SDWebImageDownloaderOperation.m in Sources */, 771 530E49EC16464C84002868E7 /* SDWebImageDownloaderOperation.m in Sources */,
772 53406750167780C40042B59E /* SDWebImageCompat.m in Sources */, 772 53406750167780C40042B59E /* SDWebImageCompat.m in Sources */,
773 A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */, 773 A18A6CC9172DC28500419892 /* UIImage+GIF.m in Sources */,
774 - A18A6CCF172DC33A00419892 /* NSData+GIF.m in Sources */,  
775 53EDFB8C17623F7C00698166 /* UIImage+MultiFormat.m in Sources */, 774 53EDFB8C17623F7C00698166 /* UIImage+MultiFormat.m in Sources */,
  775 + 1797E37E262405DB1BFEDFFC /* NSData+ImageContentType.m in Sources */,
776 ); 776 );
777 runOnlyForDeploymentPostprocessing = 0; 777 runOnlyForDeploymentPostprocessing = 0;
778 }; 778 };
@@ -790,7 +790,6 @@ @@ -790,7 +790,6 @@
790 537D957C17ECC1FE0097C263 /* SDWebImageDownloaderOperation.m in Sources */, 790 537D957C17ECC1FE0097C263 /* SDWebImageDownloaderOperation.m in Sources */,
791 537D957D17ECC1FE0097C263 /* SDWebImageCompat.m in Sources */, 791 537D957D17ECC1FE0097C263 /* SDWebImageCompat.m in Sources */,
792 537D957E17ECC1FE0097C263 /* UIImage+GIF.m in Sources */, 792 537D957E17ECC1FE0097C263 /* UIImage+GIF.m in Sources */,
793 - 537D957F17ECC1FE0097C263 /* NSData+GIF.m in Sources */,  
794 537D958017ECC1FE0097C263 /* UIImage+MultiFormat.m in Sources */, 793 537D958017ECC1FE0097C263 /* UIImage+MultiFormat.m in Sources */,
795 537D958117ECC1FE0097C263 /* UIImage+WebP.m in Sources */, 794 537D958117ECC1FE0097C263 /* UIImage+WebP.m in Sources */,
796 537D958217ECC1FE0097C263 /* webp.c in Sources */, 795 537D958217ECC1FE0097C263 /* webp.c in Sources */,
@@ -818,6 +817,7 @@ @@ -818,6 +817,7 @@
818 537D959817ECC1FE0097C263 /* utils.c in Sources */, 817 537D959817ECC1FE0097C263 /* utils.c in Sources */,
819 537D959917ECC1FE0097C263 /* filters.c in Sources */, 818 537D959917ECC1FE0097C263 /* filters.c in Sources */,
820 537D959A17ECC1FE0097C263 /* thread.c in Sources */, 819 537D959A17ECC1FE0097C263 /* thread.c in Sources */,
  820 + 1797ED4CD80EA8BD405365C3 /* NSData+ImageContentType.m in Sources */,
821 ); 821 );
822 runOnlyForDeploymentPostprocessing = 0; 822 runOnlyForDeploymentPostprocessing = 0;
823 }; 823 };
1 -//  
2 -// NSData+GIF.h  
3 -// SDWebImage  
4 -//  
5 -// Created by Andy LaVoy on 4/28/13.  
6 -// Copyright (c) 2013 Dailymotion. All rights reserved.  
7 -//  
8 -  
9 -#import <Foundation/Foundation.h>  
10 -  
11 -@interface NSData (GIF)  
12 -  
13 -- (BOOL)sd_isGIF;  
14 -  
15 -@end  
1 -//  
2 -// NSData+GIF.m  
3 -// SDWebImage  
4 -//  
5 -// Created by Andy LaVoy on 4/28/13.  
6 -// Copyright (c) 2013 Dailymotion. All rights reserved.  
7 -//  
8 -  
9 -#import "NSData+GIF.h"  
10 -  
11 -@implementation NSData (GIF)  
12 -  
13 -- (BOOL)sd_isGIF  
14 -{  
15 - BOOL isGIF = NO;  
16 -  
17 - uint8_t c;  
18 - [self getBytes:&c length:1];  
19 -  
20 - switch (c)  
21 - {  
22 - case 0x47: // probably a GIF  
23 - isGIF = YES;  
24 - break;  
25 - default:  
26 - break;  
27 - }  
28 -  
29 - return isGIF;  
30 -}  
31 -  
32 -@end  
@@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 // 7 //
8 8
9 -#import "NSData+GIF.h"  
10 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
11 10
12 @interface UIImage (GIF) 11 @interface UIImage (GIF)
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 8
9 #import "UIImage+MultiFormat.h" 9 #import "UIImage+MultiFormat.h"
10 #import "UIImage+GIF.h" 10 #import "UIImage+GIF.h"
11 - 11 +#import "NSData+ImageContentType.h"
12 #ifdef SD_WEBP 12 #ifdef SD_WEBP
13 #import "UIImage+WebP.h" 13 #import "UIImage+WebP.h"
14 #endif 14 #endif
@@ -18,22 +18,23 @@ @@ -18,22 +18,23 @@
18 + (UIImage *)sd_imageWithData:(NSData *)data 18 + (UIImage *)sd_imageWithData:(NSData *)data
19 { 19 {
20 UIImage *image; 20 UIImage *image;
21 -  
22 - if ([data sd_isGIF]) 21 + NSString *imageContentType = [NSData contentTypeForImageData:data];
  22 + if ([imageContentType isEqualToString:@"image/gif"])
23 { 23 {
24 image = [UIImage sd_animatedGIFWithData:data]; 24 image = [UIImage sd_animatedGIFWithData:data];
25 } 25 }
26 - else  
27 - {  
28 - image = [[UIImage alloc] initWithData:data];  
29 - }  
30 -  
31 #ifdef SD_WEBP 26 #ifdef SD_WEBP
32 - if (!image) // TODO: detect webp signature 27 + else if ([imageContentType isEqualToString:@"image/webp"])
33 { 28 {
34 image = [UIImage sd_imageWithWebPData:data]; 29 image = [UIImage sd_imageWithWebPData:data];
35 } 30 }
36 #endif 31 #endif
  32 + else
  33 + {
  34 + image = [[UIImage alloc] initWithData:data];
  35 + }
  36 +
  37 +
37 38
38 return image; 39 return image;
39 } 40 }