/* This code is part of the tng compression routines. * * Written by Daniel Spangberg * Copyright (c) 2010, 2013, The GROMACS development team. * * * This program is free software; you can redistribute it and/or * modify it under the terms of the Revised BSD License. */ #include #include "../../include/compression/warnmalloc.h" #include "../../include/compression/mtf.h" /* "Partial" MTF. Byte based. */ /* Move to front coding. Acceptable inputs are max 8 bits (0-0xFF) */ static void comp_conv_to_mtf_byte(unsigned char *vals, int nvals, unsigned char *valsmtf) { int i; /* Indices into a linked list */ int list[256]; int dict[256]; /* Head of the linked list */ int head; for (i=0; i<256; i++) dict[i]=i; for (i=0; i<255; i++) list[i]=i+1; list[255]=-1; /* end. */ head=0; for (i=0; i>(8*j))&0xFF); comp_conv_to_mtf_byte(tmp,nvals,tmp+nvals); for (i=0; i>(8*j))&0xFF); comp_conv_to_mtf_byte(tmp,nvals,valsmtf+j*nvals); } free(tmp); } /* Move to front decoding */ static void comp_conv_from_mtf_byte(unsigned char *valsmtf, int nvals, unsigned char *vals) { int i; /* Indices into a linked list */ int list[256]; int dict[256]; /* Head of the linked list */ int head; for (i=0; i<256; i++) dict[i]=i; for (i=0; i<255; i++) list[i]=i+1; list[255]=-1; /* end. */ head=0; for (i=0; i>(8*j))&0xFF); comp_conv_from_mtf_byte(tmp,nvals,tmp+nvals); for (i=0; i