summaryrefslogtreecommitdiff
path: root/frontends/cocoa/apple_image.m
diff options
context:
space:
mode:
authorSven Weidauer <sven@5sw.de>2017-06-05 11:20:56 +0200
committerSven Weidauer <sven@5sw.de>2017-06-05 11:20:56 +0200
commit2ba97ae0dbd01a4f46c543ae025249e5349e0585 (patch)
tree5028ee570078f80f98049bd5a68b209ecfdaca59 /frontends/cocoa/apple_image.m
parent3ee40a10b123c36be3e29602767840a7a71aaafa (diff)
downloadnetsurf-2ba97ae0dbd01a4f46c543ae025249e5349e0585.tar.gz
netsurf-2ba97ae0dbd01a4f46c543ae025249e5349e0585.tar.bz2
Reformat code using clang-format.
Diffstat (limited to 'frontends/cocoa/apple_image.m')
-rw-r--r--frontends/cocoa/apple_image.m317
1 files changed, 158 insertions, 159 deletions
diff --git a/frontends/cocoa/apple_image.m b/frontends/cocoa/apple_image.m
index a14cd10e5..89a760969 100644
--- a/frontends/cocoa/apple_image.m
+++ b/frontends/cocoa/apple_image.m
@@ -32,66 +32,65 @@
#import "cocoa/bitmap.h"
typedef struct apple_image_content {
- struct content base;
+ struct content base;
- struct bitmap *bitmap; /**< Created NetSurf bitmap */
+ struct bitmap *bitmap; /**< Created NetSurf bitmap */
- NSUInteger frames;
- NSUInteger currentFrame;
- int *frameTimes;
+ NSUInteger frames;
+ NSUInteger currentFrame;
+ int *frameTimes;
} apple_image_content;
-
static void *apple_image_get_internal(const struct content *c, void *context)
{
- apple_image_content *ai_c = (apple_image_content *)c;
- return ai_c->bitmap;
+ apple_image_content *ai_c = (apple_image_content *)c;
+ return ai_c->bitmap;
}
static nserror apple_image_create(const content_handler *handler,
- lwc_string *imime_type, const struct http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c)
+ lwc_string *imime_type, const struct http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c)
{
- apple_image_content *ai;
- nserror error;
+ apple_image_content *ai;
+ nserror error;
- ai = calloc(1, sizeof(apple_image_content));
- if (ai == NULL)
- return NSERROR_NOMEM;
+ ai = calloc(1, sizeof(apple_image_content));
+ if (ai == NULL)
+ return NSERROR_NOMEM;
- error = content__init(&ai->base, handler, imime_type, params,
- llcache, fallback_charset, quirks);
- if (error != NSERROR_OK) {
- free(ai);
- return error;
- }
+ error = content__init(&ai->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ free(ai);
+ return error;
+ }
- *c = (struct content *) ai;
+ *c = (struct content *)ai;
- return NSERROR_OK;
+ return NSERROR_OK;
}
-
-static void animate_image_cb( void *ptr )
+static void animate_image_cb(void *ptr)
{
- struct apple_image_content *ai = ptr;
- ++ai->currentFrame;
- if (ai->currentFrame >= ai->frames) ai->currentFrame = 0;
-
- [(__bridge NSBitmapImageRep *)ai->bitmap setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: ai->currentFrame]];
- cocoa_bitmap_modified( ai->bitmap );
-
- union content_msg_data data;
- data.redraw.full_redraw = true;
- data.redraw.x = data.redraw.object_x = 0;
- data.redraw.y = data.redraw.object_y = 0;
- data.redraw.width = data.redraw.object_width = ai->base.width;
- data.redraw.height = data.redraw.object_height = ai->base.height;
- data.redraw.object = &ai->base;
- content_broadcast( &ai->base, CONTENT_MSG_REDRAW, data );
-
- cocoa_schedule(ai->frameTimes[ai->currentFrame], animate_image_cb, ai );
+ struct apple_image_content *ai = ptr;
+ ++ai->currentFrame;
+ if (ai->currentFrame >= ai->frames)
+ ai->currentFrame = 0;
+
+ [(__bridge NSBitmapImageRep *)ai->bitmap setProperty:NSImageCurrentFrame withValue:[NSNumber numberWithUnsignedInteger:ai->currentFrame]];
+ cocoa_bitmap_modified(ai->bitmap);
+
+ union content_msg_data data;
+ data.redraw.full_redraw = true;
+ data.redraw.x = data.redraw.object_x = 0;
+ data.redraw.y = data.redraw.object_y = 0;
+ data.redraw.width = data.redraw.object_width = ai->base.width;
+ data.redraw.height = data.redraw.object_height = ai->base.height;
+ data.redraw.object = &ai->base;
+ content_broadcast(&ai->base, CONTENT_MSG_REDRAW, data);
+
+ cocoa_schedule(ai->frameTimes[ai->currentFrame], animate_image_cb, ai);
}
/**
@@ -99,160 +98,160 @@ static void animate_image_cb( void *ptr )
*/
static bool apple_image_convert(struct content *c)
{
- apple_image_content *ai_c = (apple_image_content *)c;
- unsigned long size;
- const char *bytes = content__get_source_data(c, &size);
-
- NSData *data = [NSData dataWithBytesNoCopy: (char *)bytes length: size freeWhenDone: NO];
- NSBitmapImageRep *image = [NSBitmapImageRep imageRepWithData: data];
-
- if (image == nil) {
- union content_msg_data msg_data;
- msg_data.error = "cannot decode image";
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
- c->width = [image pixelsWide];
- c->height = [image pixelsHigh];
- ai_c->bitmap = (__bridge_retained void *)image;
-
- NSString *url = [NSString stringWithUTF8String: nsurl_access(llcache_handle_get_url( content_get_llcache_handle( c )) )];
- NSString *title = [NSString stringWithFormat: @"%@ (%dx%d)", [url lastPathComponent], c->width, c->height];
- content__set_title(c, [title UTF8String] );
-
- content_set_ready(c);
- content_set_done(c);
- content_set_status(c, "");
-
- struct apple_image_content *ai = (struct apple_image_content *)c;
- NSUInteger frames = [[image valueForProperty: NSImageFrameCount] unsignedIntegerValue];
- if (frames > 1) {
- ai->frames = frames;
- ai->currentFrame = 0;
- ai->frameTimes = calloc( ai->frames , sizeof(int));
- for (NSUInteger i = 0; i < frames; i++) {
- [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: i]];
- ai->frameTimes[i] = 1000 * [[image valueForProperty: NSImageCurrentFrameDuration] floatValue];
- }
- [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: 0]];
- cocoa_schedule( ai->frameTimes[0], animate_image_cb, ai );
- }
-
- return true;
+ apple_image_content *ai_c = (apple_image_content *)c;
+ unsigned long size;
+ const char *bytes = content__get_source_data(c, &size);
+
+ NSData *data = [NSData dataWithBytesNoCopy:(char *)bytes length:size freeWhenDone:NO];
+ NSBitmapImageRep *image = [NSBitmapImageRep imageRepWithData:data];
+
+ if (image == nil) {
+ union content_msg_data msg_data;
+ msg_data.error = "cannot decode image";
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
+
+ c->width = [image pixelsWide];
+ c->height = [image pixelsHigh];
+ ai_c->bitmap = (__bridge_retained void *)image;
+
+ NSString *url = [NSString stringWithUTF8String:nsurl_access(llcache_handle_get_url(content_get_llcache_handle(c)))];
+ NSString *title = [NSString stringWithFormat:@"%@ (%dx%d)", [url lastPathComponent], c->width, c->height];
+ content__set_title(c, [title UTF8String]);
+
+ content_set_ready(c);
+ content_set_done(c);
+ content_set_status(c, "");
+
+ struct apple_image_content *ai = (struct apple_image_content *)c;
+ NSUInteger frames = [[image valueForProperty:NSImageFrameCount] unsignedIntegerValue];
+ if (frames > 1) {
+ ai->frames = frames;
+ ai->currentFrame = 0;
+ ai->frameTimes = calloc(ai->frames, sizeof(int));
+ for (NSUInteger i = 0; i < frames; i++) {
+ [image setProperty:NSImageCurrentFrame withValue:[NSNumber numberWithUnsignedInteger:i]];
+ ai->frameTimes[i] = 1000 * [[image valueForProperty:NSImageCurrentFrameDuration] floatValue];
+ }
+ [image setProperty:NSImageCurrentFrame withValue:[NSNumber numberWithUnsignedInteger:0]];
+ cocoa_schedule(ai->frameTimes[0], animate_image_cb, ai);
+ }
+
+ return true;
}
-
static void apple_image_destroy(struct content *c)
{
- apple_image_content *ai_c = (apple_image_content *)c;
+ apple_image_content *ai_c = (apple_image_content *)c;
- id bitmap = (__bridge_transfer id)ai_c->bitmap;
+ id bitmap = (__bridge_transfer id)ai_c->bitmap;
bitmap = nil;
-
- ai_c->bitmap = NULL;
- cocoa_schedule(-1, animate_image_cb, c );
-}
+ ai_c->bitmap = NULL;
+ cocoa_schedule(-1, animate_image_cb, c);
+}
static nserror apple_image_clone(const struct content *old, struct content **newc)
{
- apple_image_content *ai;
- apple_image_content *ai_old = (apple_image_content *)old;
- nserror error;
-
- ai = calloc(1, sizeof(apple_image_content));
- if (ai == NULL)
- return NSERROR_NOMEM;
-
- error = content__clone(old, &ai->base);
- if (error != NSERROR_OK) {
- content_destroy(&ai->base);
- return error;
- }
-
- if (old->status == CONTENT_STATUS_READY ||
- old->status == CONTENT_STATUS_DONE) {
- ai->base.width = old->width;
- ai->base.height = old->height;
- ai->bitmap = (__bridge_retained void *)((__bridge id)ai_old->bitmap);
- }
-
- *newc = (struct content *) ai;
-
- return NSERROR_OK;
+ apple_image_content *ai;
+ apple_image_content *ai_old = (apple_image_content *)old;
+ nserror error;
+
+ ai = calloc(1, sizeof(apple_image_content));
+ if (ai == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &ai->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&ai->base);
+ return error;
+ }
+
+ if (old->status == CONTENT_STATUS_READY || old->status == CONTENT_STATUS_DONE) {
+ ai->base.width = old->width;
+ ai->base.height = old->height;
+ ai->bitmap = (__bridge_retained void *)((__bridge id)ai_old->bitmap);
+ }
+
+ *newc = (struct content *)ai;
+
+ return NSERROR_OK;
}
static content_type apple_image_content_type(void)
{
- return CONTENT_IMAGE;
+ return CONTENT_IMAGE;
}
/**
* Redraw a CONTENT_APPLE_IMAGE with appropriate tiling.
*/
static bool apple_image_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx)
+ const struct rect *clip, const struct redraw_context *ctx)
{
- apple_image_content *ai_c = (apple_image_content *)c;
- bitmap_flags_t flags = BITMAPF_NONE;
+ apple_image_content *ai_c = (apple_image_content *)c;
+ bitmap_flags_t flags = BITMAPF_NONE;
- if (data->repeat_x)
- flags |= BITMAPF_REPEAT_X;
- if (data->repeat_y)
- flags |= BITMAPF_REPEAT_Y;
+ if (data->repeat_x)
+ flags |= BITMAPF_REPEAT_X;
+ if (data->repeat_y)
+ flags |= BITMAPF_REPEAT_Y;
- return ctx->plot->bitmap(ctx, ai_c->bitmap, data->x, data->y, data->width, data->height,
- data->background_colour, flags);
+ return ctx->plot->bitmap(ctx, ai_c->bitmap, data->x, data->y, data->width, data->height,
+ data->background_colour, flags);
}
static const content_handler apple_image_content_handler = {
- .create = apple_image_create,
- .data_complete = apple_image_convert,
- .destroy = apple_image_destroy,
- .redraw = apple_image_redraw,
- .clone = apple_image_clone,
- .get_internal = apple_image_get_internal,
- .type = apple_image_content_type,
- .no_share = false
+ .create = apple_image_create,
+ .data_complete = apple_image_convert,
+ .destroy = apple_image_destroy,
+ .redraw = apple_image_redraw,
+ .clone = apple_image_clone,
+ .get_internal = apple_image_get_internal,
+ .type = apple_image_content_type,
+ .no_share = false
};
-static nserror register_for_type( NSString *mime )
+static nserror register_for_type(NSString *mime)
{
- const char *type = [mime UTF8String];
- /* nsgif has priority since it supports animated GIF */
+ const char *type = [mime UTF8String];
+/* nsgif has priority since it supports animated GIF */
#ifdef WITH_GIF
- if (strcmp(type, "image/gif") == 0)
- return NSERROR_OK;
+ if (strcmp(type, "image/gif") == 0)
+ return NSERROR_OK;
#endif
- nserror error = content_factory_register_handler( type, &apple_image_content_handler );
- if (error != NSERROR_OK) return error;
+ nserror error = content_factory_register_handler(type, &apple_image_content_handler);
+ if (error != NSERROR_OK)
+ return error;
- return NSERROR_OK;
+ return NSERROR_OK;
}
/* exported interface documented in cocoa/apple_image.h */
nserror apple_image_init(void)
{
- NSArray *utis = [NSBitmapImageRep imageTypes];
- for (NSString *uti in utis) {
- NSDictionary *declaration = (__bridge_transfer NSDictionary *)UTTypeCopyDeclaration( (__bridge CFStringRef)uti );
- 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) {
- nserror error = register_for_type( mime );
- if (error != NSERROR_OK) return error;
- }
- }
-
- return NSERROR_OK;
+ NSArray *utis = [NSBitmapImageRep imageTypes];
+ for (NSString *uti in utis) {
+ NSDictionary *declaration = (__bridge_transfer NSDictionary *)UTTypeCopyDeclaration((__bridge CFStringRef)uti);
+ 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) {
+ nserror error = register_for_type(mime);
+ if (error != NSERROR_OK)
+ return error;
+ }
+ }
+
+ return NSERROR_OK;
}
#endif /* WITH_APPLE_IMAGE */