@@ -218,6 +218,21 @@ - (void)test45WebPEncodingMaxFileSize {
218
218
XCTAssertLessThanOrEqual (dataWithLimit.length , maxFileSize);
219
219
}
220
220
221
+ - (void )test46WebPEncodingMonochrome {
222
+ CGSize size = CGSizeMake (512 , 512 );
223
+ SDGraphicsImageRendererFormat *format = [[SDGraphicsImageRendererFormat alloc ] init ];
224
+ format.scale = 1 ;
225
+ SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc ] initWithSize: size format: format];
226
+ UIColor *monochromeColor = UIColor.clearColor ;
227
+ UIImage *monochromeImage = [renderer imageWithActions: ^(CGContextRef ctx) {
228
+ [monochromeColor setFill ];
229
+ CGContextFillRect (ctx, CGRectMake (0 , 0 , size.width , size.height ));
230
+ }];
231
+ XCTAssert (monochromeImage);
232
+ NSData *data = [SDImageWebPCoder.sharedCoder encodedDataWithImage: monochromeImage format: SDImageFormatWebP options: nil ];
233
+ XCTAssert (data);
234
+ }
235
+
221
236
- (void )testWebPDecodeDoesNotTriggerCACopyImage {
222
237
NSURL *staticWebPURL = [[NSBundle bundleForClass: [self class ]] URLForResource: @" TestColorspaceStatic" withExtension: @" webp" ];
223
238
NSData *data = [NSData dataWithContentsOfURL: staticWebPURL];
@@ -356,10 +371,18 @@ - (void)testWebPEncodingWithICCProfile {
356
371
CGFloat r1;
357
372
CGFloat g1;
358
373
CGFloat b1;
374
+ #if SD_UIKIT
359
375
[color1 getRed: &r1 green: &g1 blue: &b1 alpha: nil ];
360
376
expect (255 * r1).beCloseToWithin (0 , 5 );
361
377
expect (255 * g1).beCloseToWithin (38 , 5 );
362
378
expect (255 * b1).beCloseToWithin (135 , 5 );
379
+ #else
380
+ @try {
381
+ [color1 getRed: &r1 green: &g1 blue: &b1 alpha: nil ];
382
+ }
383
+ @catch (NSException *exception ) {}
384
+ expect (255 * r1).beCloseToWithin (0 , 5 );
385
+ #endif
363
386
}
364
387
365
388
@end
0 commit comments