summaryrefslogtreecommitdiff
path: root/trunk
diff options
context:
space:
mode:
authorJames Shaw <jshaw@netsurf-browser.org>2008-03-23 23:27:05 +0000
committerJames Shaw <jshaw@netsurf-browser.org>2008-03-23 23:27:05 +0000
commitee314c5193f4b9045b47a0028e43265c9e422581 (patch)
treeff643ccdf005de45e5779787c8850be74352d5af /trunk
parent4016cfba2d954196a9b4d7fe19d3b16d4c78b748 (diff)
downloadlibrosprite-ee314c5193f4b9045b47a0028e43265c9e422581.tar.gz
librosprite-ee314c5193f4b9045b47a0028e43265c9e422581.tar.bz2
Implement a memory loader, which probably doesn't work yet
svn path=/import/jshaw/libsprite/; revision=10014
Diffstat (limited to 'trunk')
-rw-r--r--trunk/librosprite.c30
-rw-r--r--trunk/librosprite.h4
2 files changed, 34 insertions, 0 deletions
diff --git a/trunk/librosprite.c b/trunk/librosprite.c
index 8b69254..50dacc8 100644
--- a/trunk/librosprite.c
+++ b/trunk/librosprite.c
@@ -40,6 +40,13 @@ struct rosprite_file_context {
FILE* f;
};
+struct rosprite_mem_context {
+ uint8_t* base;
+ unsigned long offset;
+ bool known_size;
+ unsigned long size;
+};
+
static const struct rosprite_mode oldmodes[] = {
/*0*/{ .colorbpp = 1, .maskbpp = 1, .mask_width = 1, .xdpi = 90, .ydpi = 45, .color_model = rosprite_rgb },
/*1*/{ .colorbpp = 2, .maskbpp = 1, .mask_width = 2, .xdpi = 45, .ydpi = 45, .color_model = rosprite_rgb },
@@ -204,6 +211,29 @@ int rosprite_file_reader(uint8_t* buf, size_t count, void* ctx)
return fread(buf, 1 /*size*/, count, ((struct rosprite_file_context*) ctx)->f);
}
+struct rosprite_mem_context* rosprite_create_mem_context(uint8_t* p, unsigned long total_size)
+{
+ struct rosprite_mem_context* ctx = malloc(sizeof(struct rosprite_mem_context));
+ ctx->base = p;
+ ctx->offset = 0;
+ ctx->known_size = true;
+ ctx->size = total_size;
+ return ctx;
+}
+
+void rosprite_destroy_mem_context(struct rosprite_mem_context* ctx)
+{
+ free(ctx);
+}
+
+int rosprite_mem_reader(uint8_t* buf, size_t count, void* ctx)
+{
+ struct rosprite_mem_context* memctx = (struct rosprite_mem_context*) ctx;
+ buf = memctx->base + memctx->offset;
+ memctx->offset += count;
+ return count; // TODO: assert size bounds, return real count
+}
+
/* TODO: get rid of this method */
uint32_t sprite_read_word(reader reader, void* ctx)
{
diff --git a/trunk/librosprite.h b/trunk/librosprite.h
index 74167b3..61e5e22 100644
--- a/trunk/librosprite.h
+++ b/trunk/librosprite.h
@@ -54,6 +54,10 @@ struct rosprite_file_context* rosprite_create_file_context(FILE* f);
void rosprite_destroy_file_context(struct rosprite_file_context* ctx);
int rosprite_file_reader(uint8_t* buf, size_t count, void* ctx);
+struct rosprite_mem_context* rosprite_create_mem_context(uint8_t* p, unsigned long total_size);
+void rosprite_destroy_mem_context(struct rosprite_mem_context* ctx);
+int rosprite_mem_reader(uint8_t* buf, size_t count, void* ctx);
+
struct rosprite_area* rosprite_load(reader reader, void* ctx);
void rosprite_destroy_sprite_area(struct rosprite_area *);