]> Some of my projects - openlase.git/commitdiff
Implement tracer init/reinit/deinit properly
authorHector Martin <hector@marcansoft.com>
Sat, 12 Mar 2011 17:25:22 +0000 (18:25 +0100)
committerHector Martin <hector@marcansoft.com>
Sat, 12 Mar 2011 17:56:11 +0000 (18:56 +0100)
tools/playvid.c
tools/trace.c
tools/trace.h

index c400ec7f63b8c9be313b08df80f58d8887111f5f..efe389701fe81139023804c4efc85f00bf56b2bf 100644 (file)
@@ -478,7 +478,7 @@ int main (int argc, char *argv[])
                        thresh = thresh_dark;
 
                tparams.threshold = thresh;
-               olTraceReInit(&trace_ctx, &tparams);
+               olTraceReInit(trace_ctx, &tparams);
                olTraceFree(&result);
                obj = olTrace(trace_ctx, frame->data[0], frame->linesize[0], &result);
 
@@ -512,6 +512,8 @@ int main (int argc, char *argv[])
                } while ((time+frametime) < vidtime);
        }
 
+       olTraceDeinit(trace_ctx);
+
        for(i=0;i<FRAMES_BUF;i++)
                olRenderFrame(200);
 
index 8f5bcc02d8f72e6fe736ebb08b05b5f4efdbaa25..9d7788cbff4ae68c7211cd46e394bcb4e209a8a3 100644 (file)
@@ -211,11 +211,8 @@ static int trace_pixels(OLTraceCtx *ctx, uint16_t *buf, int output, icoord *cx,
        return iters;
 }
 
-int olTraceInit(OLTraceCtx **pctx, OLTraceParams *params)
+static void alloc_bufs(OLTraceCtx *ctx)
 {
-       OLTraceCtx *ctx = malloc(sizeof(OLTraceCtx));
-
-       ctx->p = *params;
        ctx->tracebuf = malloc(ctx->p.width * ctx->p.height * sizeof(*ctx->tracebuf));
 
        ctx->sb_size = ctx->p.width * 16;
@@ -227,14 +224,42 @@ int olTraceInit(OLTraceCtx **pctx, OLTraceParams *params)
        ctx->pb = malloc(ctx->pb_size * sizeof(*ctx->pb));
        ctx->pbp = ctx->pb;
        ctx->pb_end = ctx->pb + ctx->pb_size;
+}
 
+static void free_bufs(OLTraceCtx *ctx)
+{
+       if (ctx->tracebuf)
+               free(ctx->tracebuf);
+       if (ctx->sb)
+               free(ctx->sb);
+       if (ctx->pb)
+               free(ctx->pb);
+}
+
+int olTraceInit(OLTraceCtx **pctx, OLTraceParams *params)
+{
+       OLTraceCtx *ctx = malloc(sizeof(OLTraceCtx));
+
+       ctx->p = *params;
+
+       alloc_bufs(ctx);
 
        *pctx = ctx;
        return 0;
 }
-int olTraceReInit(OLTraceCtx **ctx, OLTraceParams *params)
+
+int olTraceReInit(OLTraceCtx *ctx, OLTraceParams *params)
 {
-       (*ctx)->p = *params;
+       if (ctx->p.mode != params->mode ||
+               ctx->p.width != params->width ||
+               ctx->p.height != params->height)
+       {
+               free_bufs(ctx);
+               ctx->p = *params;
+               alloc_bufs(ctx);
+       } else {
+               ctx->p = *params;
+       }
        return 0;
 }
 
@@ -249,9 +274,13 @@ void olTraceFree(OLTraceResult *result)
        }
 }
 
-
 void olTraceDeinit(OLTraceCtx *ctx)
 {
+       if (!ctx)
+               return;
+
+       free_bufs(ctx);
+       free(ctx);
 }
 
 static void find_edges_thresh(OLTraceCtx *ctx, uint8_t *src, unsigned int stride)
index 949eefcd29848f548b2eec95c3824ece4b1af3f1..0410d1ed76d727a4d442b60ce762f1986f9aae4f 100644 (file)
@@ -51,7 +51,7 @@ typedef struct {
 } OLTraceResult;
 
 int olTraceInit(OLTraceCtx **ctx, OLTraceParams *params);
-int olTraceReInit(OLTraceCtx **ctx, OLTraceParams *params);
+int olTraceReInit(OLTraceCtx *ctx, OLTraceParams *params);
 
 int olTrace(OLTraceCtx *ctx, uint8_t *src, icoord stride, OLTraceResult *result);
 void olTraceFree(OLTraceResult *result);