From 5e1a9bbfc03f36d682b7ec305d381399ef7777c8 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 9 May 2011 18:13:36 +0000 Subject: Registering all image types NSBitmapImageRep can load and using ImageIO instead of other image libraries by default. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regression: animated GIF doesn’t work anymore. svn path=/trunk/netsurf/; revision=12350 --- Makefile.defaults | 4 ++- cocoa/apple_image.m | 93 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/Makefile.defaults b/Makefile.defaults index dd3755049..e052d8820 100644 --- a/Makefile.defaults +++ b/Makefile.defaults @@ -396,7 +396,9 @@ ifeq ($(TARGET),cocoa) NETSURF_USE_NSSVG := YES NETSURF_USE_MNG := NO - + NETSURF_USE_BMP := NO + NETSURF_USE_GIF := NO + NETSURF_USE_PNG := NO NETSURF_USE_JPEG := NO NETSURF_USE_IMAGEIO := YES 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, -- cgit v1.2.3