@@ -218,6 +218,21 @@ - (void)test45WebPEncodingMaxFileSize {
218218 XCTAssertLessThanOrEqual (dataWithLimit.length , maxFileSize);
219219}
220220
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+
221236- (void )testWebPDecodeDoesNotTriggerCACopyImage {
222237 NSURL *staticWebPURL = [[NSBundle bundleForClass: [self class ]] URLForResource: @" TestColorspaceStatic" withExtension: @" webp" ];
223238 NSData *data = [NSData dataWithContentsOfURL: staticWebPURL];
@@ -356,10 +371,18 @@ - (void)testWebPEncodingWithICCProfile {
356371 CGFloat r1;
357372 CGFloat g1;
358373 CGFloat b1;
374+ #if SD_UIKIT
359375 [color1 getRed: &r1 green: &g1 blue: &b1 alpha: nil ];
360376 expect (255 * r1).beCloseToWithin (0 , 5 );
361377 expect (255 * g1).beCloseToWithin (38 , 5 );
362378 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
363386}
364387
365388@end
0 commit comments