diff options
author | Sven Weidauer <sven.weidauer@gmail.com> | 2011-05-09 18:13:36 +0000 |
---|---|---|
committer | Sven Weidauer <sven.weidauer@gmail.com> | 2011-05-09 18:13:36 +0000 |
commit | 5e1a9bbfc03f36d682b7ec305d381399ef7777c8 (patch) | |
tree | b9c363ab84520c664e4e6c1c375b04c980765341 /cocoa | |
parent | bf69743db955a3a9733a0559a1a91cf3b83a9080 (diff) | |
download | netsurf-5e1a9bbfc03f36d682b7ec305d381399ef7777c8.tar.gz netsurf-5e1a9bbfc03f36d682b7ec305d381399ef7777c8.tar.bz2 |
Registering all image types NSBitmapImageRep can load and using ImageIO instead of other image libraries by default.
Regression: animated GIF doesn’t work anymore.
svn path=/trunk/netsurf/; revision=12350
Diffstat (limited to 'cocoa')
-rw-r--r-- | cocoa/apple_image.m | 93 |
1 files changed, 60 insertions, 33 deletions
diff --git a/cocoa/apple_image.m b/cocoa/apple_image.m index 80512948e..91a54ff06 100644 --- a/cocoa/apple_image.m +++ b/cocoa/apple_image.m @@ -55,52 +55,79 @@ static const content_handler apple_image_content_handler = { .no_share = false }; -static const char *apple_image_types[] = { - "image/jpeg", - "image/jpg", - "image/pjpeg" -}; +static lwc_string **apple_image_mime_types = NULL; +static size_t types_count = 0; +static size_t types_capacity = 0; -static lwc_string *apple_image_mime_types[NOF_ELEMENTS(apple_image_types)]; -nserror apple_image_init(void) +static bool reserve( size_t count ) { - uint32_t i; - lwc_error lerror; - nserror error; - - for (i = 0; i < NOF_ELEMENTS(apple_image_mime_types); i++) { - lerror = lwc_intern_string(apple_image_types[i], - strlen(apple_image_types[i]), - &apple_image_mime_types[i]); - if (lerror != lwc_error_ok) { - error = NSERROR_NOMEM; - goto error; + if (types_count + count <= types_capacity) return true; + + if (types_count == 0) { + types_capacity = count; + } else { + while (types_count + count > types_capacity) { + types_capacity *= 2; } - - error = content_factory_register_handler( - apple_image_mime_types[i], - &apple_image_content_handler); - if (error != NSERROR_OK) - goto error; } + apple_image_mime_types = (lwc_string **)realloc( apple_image_mime_types, types_capacity * sizeof( lwc_string * ) ); + + return apple_image_mime_types != NULL; +} + +static nserror register_for_type( NSString *mime ) +{ + if (!reserve( 1 )) return NSERROR_NOMEM; + + const char *type = [mime UTF8String]; + lwc_error lerror = lwc_intern_string( type, strlen( type ), &apple_image_mime_types[types_count] ); + if (lerror != lwc_error_ok) return NSERROR_NOMEM; - return NSERROR_OK; -error: - apple_image_fini(); + nserror error = content_factory_register_handler( apple_image_mime_types[types_count], &apple_image_content_handler ); - return error; + if (error != NSERROR_OK) return error; + + ++types_count; + + return NSERROR_OK; } -void apple_image_fini(void) +nserror apple_image_init(void) { - uint32_t i; + NSArray *utis = [NSBitmapImageRep imageTypes]; + for (NSString *uti in utis) { + NSDictionary *declaration = [(NSDictionary *)UTTypeCopyDeclaration( (CFStringRef)uti ) autorelease]; + id mimeTypes = [[declaration objectForKey: (NSString *)kUTTypeTagSpecificationKey] objectForKey: (NSString *)kUTTagClassMIMEType]; + + if (mimeTypes == nil) continue; + + if (![mimeTypes isKindOfClass: [NSArray class]]) { + mimeTypes = [NSArray arrayWithObject: mimeTypes]; + } + + for (NSString *mime in mimeTypes) { + NSLog( @"registering mime type %@", mime ); + nserror error = register_for_type( mime ); + if (error != NSERROR_OK) { + apple_image_fini(); + return error; + } + + } + } + + return NSERROR_OK; +} - for (i = 0; i < NOF_ELEMENTS(apple_image_mime_types); i++) { - if (apple_image_mime_types[i] != NULL) - lwc_string_unref(apple_image_mime_types[i]); +void apple_image_fini(void) +{ + for (size_t i = 0; i < types_count; i++) { + lwc_string_unref( apple_image_mime_types[i] ); } + + free( apple_image_mime_types ); } nserror apple_image_create(const content_handler *handler, |