Index: src_plugins/io_bxl/bxl_decode.c =================================================================== --- src_plugins/io_bxl/bxl_decode.c (revision 30722) +++ src_plugins/io_bxl/bxl_decode.c (revision 30723) @@ -132,8 +132,10 @@ /* fill levels */ while(node != NULL) { node = hnode_add_child(t, t->root, leaf_count); - if ((node != NULL) && (is_leaf(node))) + if ((node != NULL) && (is_leaf(node))) { + t->nodeList[leaf_count] = node; leaf_count++; + } } return t; } @@ -243,3 +245,31 @@ ctx->node = ctx->tree.root; decode_run(ctx); } + +int pcb_bxl_encode_char(hdecode_t *ctx, int inchr) +{ + int depth = 0; + int encoded[257]; /* we need to account for very asymmetric tree topologies */ + hnode_t *node = ctx->tree.nodeList[inchr]; + + inc_weight(node); + + while (node->level != 0) { + if (node == node->parent->left) + encoded[256-depth] = 1; /* left of parent */ + else + encoded[256-depth] = 0; /* right of parent */ + depth++; + node = node->parent; +/* out_file_length_in_bits++;*/ + } + + for(; depth > 0; depth--) { + if (encoded[257-depth]) + printf("1"); + else + printf("0"); + } + htree_update(ctx->tree.nodeList[inchr]); + return 0; +} Index: src_plugins/io_bxl/bxl_decode.h =================================================================== --- src_plugins/io_bxl/bxl_decode.h (revision 30722) +++ src_plugins/io_bxl/bxl_decode.h (revision 30723) @@ -37,6 +37,7 @@ typedef struct htree_s { hnode_t *root; hnode_t pool[512]; + hnode_t *nodeList[256]; int pool_used; } htree_t; @@ -59,3 +60,14 @@ output characters available in ctx->out[]; these must be saved before the next call. */ int pcb_bxl_decode_char(hdecode_t *ctx, int inchr); + + +/* 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) + +/* Feed the state machine with an output character. Returns the number of + encoded characters available in ctx->out[]; these must be saved before + the next call. */ +int pcb_bxl_encode_char(hdecode_t *ctx, int inchr); +