summaryrefslogtreecommitdiff
path: root/cocoa/apple_image.m
diff options
context:
space:
mode:
Diffstat (limited to 'cocoa/apple_image.m')
-rw-r--r--cocoa/apple_image.m142
1 files changed, 137 insertions, 5 deletions
diff --git a/cocoa/apple_image.m b/cocoa/apple_image.m
index cdf3e537b..ab971667d 100644
--- a/cocoa/apple_image.m
+++ b/cocoa/apple_image.m
@@ -24,6 +24,119 @@
#include "content/content_protected.h"
#include "image/bitmap.h"
#include "desktop/plotters.h"
+#include "utils/talloc.h"
+
+typedef struct apple_image_content {
+ struct content base;
+} apple_image_content;
+
+static nserror apple_image_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c);
+static bool apple_image_convert(struct content *c);
+static void apple_image_destroy(struct content *c);
+static bool apple_image_redraw(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour);
+static bool apple_image_redraw_tiled(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour,
+ bool repeat_x, bool repeat_y);
+static nserror apple_image_clone(const struct content *old,
+ struct content **newc);
+static content_type apple_image_content_type(lwc_string *mime_type);
+
+static const content_handler apple_image_content_handler = {
+ apple_image_create,
+ NULL,
+ apple_image_convert,
+ NULL,
+ apple_image_destroy,
+ NULL,
+ NULL,
+ NULL,
+ apple_image_redraw,
+ apple_image_redraw_tiled,
+ NULL,
+ NULL,
+ apple_image_clone,
+ NULL,
+ apple_image_content_type,
+ false
+};
+
+static const char *apple_image_types[] = {
+ "image/jpeg",
+ "image/jpg",
+ "image/pjpeg"
+};
+
+static lwc_string *apple_image_mime_types[NOF_ELEMENTS(apple_image_types)];
+
+nserror apple_image_init(void)
+{
+ 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;
+ }
+
+ error = content_factory_register_handler(
+ apple_image_mime_types[i],
+ &apple_image_content_handler);
+ if (error != NSERROR_OK)
+ goto error;
+ }
+
+ return NSERROR_OK;
+
+error:
+ apple_image_fini();
+
+ return error;
+}
+
+void apple_image_fini(void)
+{
+ uint32_t i;
+
+ 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]);
+ }
+}
+
+nserror apple_image_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c)
+{
+ apple_image_content *ai;
+ nserror error;
+
+ ai = talloc_zero(0, 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) {
+ talloc_free(ai);
+ return error;
+ }
+
+ *c = (struct content *) ai;
+
+ return NSERROR_OK;
+}
/**
* Convert a CONTENT_APPLE_IMAGE for display.
@@ -67,18 +180,37 @@ void apple_image_destroy(struct content *c)
}
-bool apple_image_clone(const struct content *old, struct content *new_content)
+nserror apple_image_clone(const struct content *old, struct content **newc)
{
+ apple_image_content *ai;
+ nserror error;
+
+ ai = talloc_zero(0, 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) {
- new_content->width = old->width;
- new_content->height = old->height;
- new_content->bitmap = (void *)[(id)old->bitmap retain];
+ ai->base.width = old->width;
+ ai->base.height = old->height;
+ ai->base.bitmap = (void *)[(id)old->bitmap retain];
}
+
+ *newc = (struct content *) ai;
- return true;
+ return NSERROR_OK;
}
+content_type apple_image_content_type(lwc_string *mime_type)
+{
+ return CONTENT_IMAGE;
+}
/**
* Redraw a CONTENT_APPLE_IMAGE.