summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-05 19:18:24 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-05 19:18:24 +0000
commitf0caa7d190e51af9ba4a487dc371b56174d56f31 (patch)
treedf7126c72187056d36478c43e878137303b3d156 /libdimension
parent32216655e1d8e523cf3e1239000442b2a30da193 (diff)
downloaddimension-f0caa7d190e51af9ba4a487dc371b56174d56f31.tar.xz
Make optimizer registration fail if a canvas has already been written
to.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/canvas.c13
-rw-r--r--libdimension/dimension/canvas.h11
-rw-r--r--libdimension/gl.c5
-rw-r--r--libdimension/png.c5
4 files changed, 25 insertions, 9 deletions
diff --git a/libdimension/canvas.c b/libdimension/canvas.c
index d53c7ef..4151a0b 100644
--- a/libdimension/canvas.c
+++ b/libdimension/canvas.c
@@ -43,6 +43,7 @@ dmnsn_new_canvas(unsigned int x, unsigned int y)
/* Allocate room for the optimizers */
canvas->optimizers = dmnsn_new_array(sizeof(dmnsn_canvas_optimizer));
+ canvas->too_late = 0;
}
return canvas;
@@ -71,10 +72,15 @@ dmnsn_delete_canvas(dmnsn_canvas *canvas)
}
/* Set a canvas optimizer */
-void
+int
dmnsn_optimize_canvas(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer)
{
- dmnsn_array_push(canvas->optimizers, &optimizer);
+ if (canvas->too_late) {
+ return 1;
+ } else {
+ dmnsn_array_push(canvas->optimizers, &optimizer);
+ return 0;
+ }
}
/* Set the color of a pixel */
@@ -85,6 +91,9 @@ dmnsn_set_pixel(dmnsn_canvas *canvas, unsigned int x, unsigned int y,
unsigned int i;
dmnsn_canvas_optimizer optimizer;
+ /* Don't allow any more optimizers */
+ canvas->too_late = 1;
+
/* Set the pixel */
canvas->pixels[y*canvas->x + x] = color;
diff --git a/libdimension/dimension/canvas.h b/libdimension/dimension/canvas.h
index a14333d..aaf728b 100644
--- a/libdimension/dimension/canvas.h
+++ b/libdimension/dimension/canvas.h
@@ -29,14 +29,15 @@ typedef struct {
/* width, height */
unsigned int x, y;
+ /* An array of dmnsn_canvas_optimizer's */
+ dmnsn_array *optimizers;
+ int too_late; /* Is it too late to add optimizers? */
+
/*
* Stored in first-quadrant representation (origin is bottom-left). The pixel
* at (a,b) is accessible as pixels[b*x + a].
*/
dmnsn_color *pixels;
-
- /* An array of dmnsn_canvas_optimizer's */
- dmnsn_array *optimizers;
} dmnsn_canvas;
typedef struct dmnsn_canvas_optimizer dmnsn_canvas_optimizer;
@@ -59,8 +60,8 @@ dmnsn_canvas *dmnsn_new_canvas(unsigned int x, unsigned int y);
void dmnsn_delete_canvas(dmnsn_canvas *canvas);
/* Set a canvas optimizer */
-void dmnsn_optimize_canvas(dmnsn_canvas *canvas,
- dmnsn_canvas_optimizer optimizer);
+int dmnsn_optimize_canvas(dmnsn_canvas *canvas,
+ dmnsn_canvas_optimizer optimizer);
/* Pixel accessors */
diff --git a/libdimension/gl.c b/libdimension/gl.c
index a37d7f7..20c9af3 100644
--- a/libdimension/gl.c
+++ b/libdimension/gl.c
@@ -51,7 +51,10 @@ dmnsn_gl_optimize_canvas(dmnsn_canvas *canvas)
return 1;
}
- dmnsn_optimize_canvas(canvas, optimizer);
+ if (dmnsn_optimize_canvas(canvas, optimizer) != 0) {
+ free(optimizer.ptr);
+ return 1;
+ }
return 0;
}
diff --git a/libdimension/png.c b/libdimension/png.c
index c8ffc62..76308ca 100644
--- a/libdimension/png.c
+++ b/libdimension/png.c
@@ -54,7 +54,10 @@ dmnsn_png_optimize_canvas(dmnsn_canvas *canvas)
return 1;
}
- dmnsn_optimize_canvas(canvas, optimizer);
+ if (dmnsn_optimize_canvas(canvas, optimizer) != 0) {
+ free(optimizer.ptr);
+ return 1;
+ }
return 0;
}