Index: src_plugins/io_bxl/bxl_decode.c =================================================================== --- src_plugins/io_bxl/bxl_decode.c (revision 30725) +++ src_plugins/io_bxl/bxl_decode.c (revision 30726) @@ -246,6 +246,17 @@ decode_run(ctx); } +static void append(hdecode_t *ctx, int bitval) +{ + ctx->chr <<= 1; + ctx->chr |= bitval; + ctx->bitpos++; + if (ctx->bitpos == 8) { + ctx->out[ctx->out_len++] = ctx->chr; + ctx->chr = ctx->bitpos = 0; + } +} + int pcb_bxl_encode_char(hdecode_t *ctx, int inchr) { int depth = 0; @@ -252,6 +263,7 @@ int encoded[257]; /* we need to account for very asymmetric tree topologies */ hnode_t *node = ctx->tree.nodeList[inchr]; + ctx->out_len = 0; inc_weight(node); while (node->level != 0) { @@ -261,19 +273,25 @@ encoded[256-depth] = 0; /* right of parent */ depth++; node = node->parent; -/* out_file_length_in_bits++;*/ } for(; depth > 0; depth--) { if (ctx->after_first_bit) { if (encoded[257-depth]) - printf("1"); + append(ctx, 1); else - printf("0"); + append(ctx, 0); } ctx->after_first_bit = 1; } htree_update(ctx->tree.nodeList[inchr]); - return 0; + return ctx->out_len; } + +void pcb_bxl_encode_init(hdecode_t *ctx) +{ + pcb_bxl_decode_init(ctx); + ctx->bitpos = 0; +} + Index: src_plugins/io_bxl/bxl_decode.h =================================================================== --- src_plugins/io_bxl/bxl_decode.h (revision 30725) +++ src_plugins/io_bxl/bxl_decode.h (revision 30726) @@ -65,7 +65,7 @@ /* Initialize an encode context, before the first output byte is pushed. No dynamic allocation is done during encoding so no uninit required. */ -#define pcb_bxl_encode_init(ctx) pcb_bxl_decode_init(ctx) +void pcb_bxl_encode_init(hdecode_t *ctx); /* Feed the state machine with an output character. Returns the number of encoded characters available in ctx->out[]; these must be saved before