summaryrefslogtreecommitdiff
path: root/amiga/plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'amiga/plugin.c')
-rw-r--r--amiga/plugin.c191
1 files changed, 143 insertions, 48 deletions
diff --git a/amiga/plugin.c b/amiga/plugin.c
index e21a7c2fc..e68930283 100644
--- a/amiga/plugin.c
+++ b/amiga/plugin.c
@@ -26,25 +26,135 @@
#include "amiga/plugin.h"
#include "content/content_protected.h"
#include "desktop/plotters.h"
+#include "image/bitmap.h"
#include "render/box.h"
#include "utils/log.h"
#include "utils/messages.h"
+#include "utils/talloc.h"
#include <proto/datatypes.h>
#include <proto/intuition.h>
#include <datatypes/pictureclass.h>
+#include <intuition/classusr.h>
-bool plugin_create(struct content *c, const struct http_parameter *params)
+typedef struct plugin_content {
+ struct content base;
+
+ Object *dto;
+ int x;
+ int y;
+ int w;
+ int h;
+} plugin_content;
+
+static nserror plugin_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 plugin_convert(struct content *c);
+static void plugin_reformat(struct content *c, int width, int height);
+static void plugin_destroy(struct content *c);
+static bool plugin_redraw(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour);
+static void plugin_open(struct content *c, struct browser_window *bw,
+ struct content *page, struct box *box,
+ struct object_params *params);
+static void plugin_close(struct content *c);
+static nserror plugin_clone(const struct content *old, struct content **newc);
+static content_type plugin_content_type(lwc_string *mime_type);
+
+static const content_handler plugin_content_handler = {
+ plugin_create,
+ NULL,
+ plugin_convert,
+ plugin_reformat,
+ plugin_destroy,
+ NULL,
+ NULL,
+ NULL,
+ plugin_redraw,
+ NULL,
+ plugin_open,
+ plugin_close,
+ plugin_clone,
+ NULL,
+ plugin_content_type,
+ false
+};
+
+nserror plugin_init(void)
{
- LOG(("plugin_create"));
+ char dt_mime[50];
+ struct DataType *dt, *prevdt = NULL;
+ lwc_string *type;
+ lwc_error lerror;
+ nserror error;
- return true;
+ while((dt = ObtainDataType(DTST_RAM, NULL,
+ DTA_DataType, prevdt,
+ DTA_GroupID, GID_PICTURE, // we only support images for now
+ TAG_DONE)) != NULL)
+ {
+ ReleaseDataType(prevdt);
+ prevdt = dt;
+ ami_datatype_to_mimetype(dt, dt_mime);
+
+ LOG(("Guessed MIME from DT: %s", dt_mime));
+
+ lerror = lwc_intern_string(dt_mime, strlen(dt_mime), &type);
+ if (lerror != lwc_error_ok)
+ return NSERROR_NOMEM;
+
+ error = content_factory_register_handler(type,
+ &plugin_content_handler);
+
+ lwc_string_unref(type);
+
+ if (error != NSERROR_OK)
+ return error;
+
+ }
+
+ ReleaseDataType(prevdt);
+
+ return NSERROR_OK;
+}
+
+void plugin_fini(void)
+{
+ /* Nothing to do */
+}
+
+nserror plugin_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)
+{
+ plugin_content *plugin;
+ nserror error;
+
+ plugin = talloc_zero(0, plugin_content);
+ if (plugin == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&plugin->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(plugin);
+ return error;
+ }
+
+ *c = (struct content *) plugin;
+
+ return NSERROR_OK;
}
bool plugin_convert(struct content *c)
{
LOG(("plugin_convert"));
+ plugin_content *plugin = (plugin_content *) c;
union content_msg_data msg_data;
int width, height;
char title[100];
@@ -60,7 +170,7 @@ bool plugin_convert(struct content *c)
data = (uint8 *)content__get_source_data(c, &size);
- if(c->data.plugin.dto = NewDTObject(NULL,
+ if(plugin->dto = NewDTObject(NULL,
DTA_SourceType, DTST_MEMORY,
DTA_SourceAddress, data,
DTA_SourceSize, size,
@@ -68,7 +178,7 @@ bool plugin_convert(struct content *c)
PDTA_DestMode, PMODE_V43,
TAG_DONE))
{
- if(GetDTAttrs(c->data.plugin.dto, PDTA_BitMapHeader, &bmh, TAG_DONE))
+ if(GetDTAttrs(plugin->dto, PDTA_BitMapHeader, &bmh, TAG_DONE))
{
width = (int)bmh->bmh_Width;
height = (int)bmh->bmh_Height;
@@ -82,7 +192,7 @@ bool plugin_convert(struct content *c)
bm_buffer = bitmap_get_buffer(c->bitmap);
- IDoMethod(c->data.plugin.dto, PDTM_READPIXELARRAY,
+ IDoMethod(plugin->dto, PDTM_READPIXELARRAY,
bm_buffer, bm_format, bitmap_get_rowstride(c->bitmap),
0, 0, width, height);
}
@@ -110,12 +220,14 @@ bool plugin_convert(struct content *c)
void plugin_destroy(struct content *c)
{
+ plugin_content *plugin = (plugin_content *) c;
+
LOG(("plugin_destroy"));
if (c->bitmap != NULL)
bitmap_destroy(c->bitmap);
- DisposeDTObject(c->data.plugin.dto);
+ DisposeDTObject(plugin->dto);
return;
}
@@ -161,57 +273,40 @@ void plugin_reformat(struct content *c, int width, int height)
return;
}
-bool plugin_clone(const struct content *old, struct content *new_content)
+nserror plugin_clone(const struct content *old, struct content **newc)
{
+ plugin_content *plugin;
+ nserror error;
+
LOG(("plugin_clone"));
- /* We "clone" the old content by replaying creation and conversion */
- if (plugin_create(new_content, NULL) == false)
- return false;
+ plugin = talloc_zero(0, plugin_content);
+ if (plugin == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &plugin->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&plugin->base);
+ return error;
+ }
+
+ /* We "clone" the old content by replaying conversion */
if (old->status == CONTENT_STATUS_READY ||
old->status == CONTENT_STATUS_DONE) {
- if (plugin_convert(new_content) == false)
- return false;
+ if (plugin_convert(&plugin->base) == false) {
+ content_destroy(&plugin->base);
+ return NSERROR_CLONE_FAILED;
+ }
}
- return true;
+ *newc = (struct content *) plugin;
+
+ return NSERROR_OK;
}
-/**
- * Determines whether a content is handleable by a plugin
- *
- * \param mime_type The mime type of the content
- * \return true if the content is handleable, false otherwise
- */
-bool plugin_handleable(const char *mime_type)
+content_type plugin_content_type(lwc_string *mime_type)
{
- LOG(("plugin_handleable %s", mime_type));
-
- char dt_mime[50];
- struct DataType *dt, *prevdt = NULL;
- bool found = false;
-
- while((dt = ObtainDataType(DTST_RAM, NULL,
- DTA_DataType, prevdt,
- DTA_GroupID, GID_PICTURE, // we only support images for now
- TAG_DONE)) != NULL)
- {
- ReleaseDataType(prevdt);
- prevdt = dt;
- ami_datatype_to_mimetype(dt, &dt_mime);
-
- LOG(("Guessed MIME from DT: %s", dt_mime));
-
- if(strcmp(dt_mime, mime_type) == 0)
- {
- found = true;
- break;
- }
- }
-
- ReleaseDataType(prevdt);
-
- return found;
+ return CONTENT_IMAGE;
}
#endif