/**************************************************************************
 *
 * bitio_mem.c -- Functions for bitio to memory
 * Copyright (C) 1994  Neil Sharman
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 **************************************************************************/

#include "sysfuncs.h"

#include "bitio_m_mem.h"
#include "bitio_m.h"

int fprintf (FILE *, const char *,...);



void 
BIO_Mem_Encode_Start (void *buf, int rem, mem_bitio_state * bs)
{
  ENCODE_START (buf, rem)
    ENCODE_PAUSE (*bs)
}

void 
BIO_Mem_Encode_Done (mem_bitio_state * bs)
{
  ENCODE_CONTINUE (*bs)
    ENCODE_DONE
}


void 
BIO_Mem_Decode_Start (void *buf, int rem, mem_bitio_state * bs)
{
  DECODE_START (buf, rem)
    DECODE_PAUSE (*bs)
}




void 
BIO_Mem_Unary_Encode (mg_u_long val, mem_bitio_state * bs,
		      mg_u_long *bits)
{
  ENCODE_CONTINUE (*bs)
    if (bits)
    UNARY_ENCODE_L (val, *bits);
  else
    UNARY_ENCODE (val);
  ENCODE_PAUSE (*bs)
}


mg_u_long 
BIO_Mem_Unary_Decode (mem_bitio_state * bs,
		      mg_u_long *bits)
{
  register mg_u_long val;
  DECODE_CONTINUE (*bs)
    if (bits)
    UNARY_DECODE_L (val, *bits);
  else
    UNARY_DECODE (val);
  DECODE_PAUSE (*bs)
    return (val);
}







void 
BIO_Mem_Binary_Encode (mg_u_long val, mg_u_long b,
		       mem_bitio_state * bs, mg_u_long *bits)
{
  ENCODE_CONTINUE (*bs)
    if (bits)
    BINARY_ENCODE_L (val, b, *bits);
  else
    BINARY_ENCODE (val, b);
  ENCODE_PAUSE (*bs)
}


mg_u_long 
BIO_Mem_Binary_Decode (mg_u_long b, mem_bitio_state * bs,
		       mg_u_long *bits)
{
  register mg_u_long val;
  DECODE_CONTINUE (*bs)
    if (bits)
    BINARY_DECODE_L (val, b, *bits);
  else
    BINARY_DECODE (val, b);
  DECODE_PAUSE (*bs)
    return (val);
}







void 
BIO_Mem_Gamma_Encode (mg_u_long val, mem_bitio_state * bs,
		      mg_u_long *bits)
{
  ENCODE_CONTINUE (*bs)
    if (bits)
    GAMMA_ENCODE_L (val, *bits);
  else
    GAMMA_ENCODE (val);
  ENCODE_PAUSE (*bs)
}


mg_u_long 
BIO_Mem_Gamma_Decode (mem_bitio_state * bs, mg_u_long *bits)
{
  register mg_u_long val;
  DECODE_CONTINUE (*bs)
    if (bits)
    GAMMA_DECODE_L (val, *bits);
  else
    GAMMA_DECODE (val);
  DECODE_PAUSE (*bs)
    return (val);
}




void 
BIO_Mem_Delta_Encode (mg_u_long val, mem_bitio_state * bs,
		      mg_u_long *bits)
{
  ENCODE_CONTINUE (*bs)
    if (bits)
    DELTA_ENCODE_L (val, *bits);
  else
    DELTA_ENCODE (val);
  ENCODE_PAUSE (*bs)
}


mg_u_long 
BIO_Mem_Delta_Decode (mem_bitio_state * bs, mg_u_long *bits)
{
  register mg_u_long val;
  DECODE_CONTINUE (*bs)
    if (bits)
    DELTA_DECODE_L (val, *bits);
  else
    DELTA_DECODE (val);
  DECODE_PAUSE (*bs)
    return (val);
}

void 
BIO_Mem_Elias_Encode (mg_u_long val, mg_u_long b, double s,
		      mem_bitio_state * bs, mg_u_long *bits)
{
  ENCODE_CONTINUE (*bs)
    if (bits)
    ELIAS_ENCODE_L (val, b, s, *bits);
  else
    ELIAS_ENCODE (val, b, s);
  ENCODE_PAUSE (*bs)
}


mg_u_long 
BIO_Mem_Elias_Decode (mg_u_long b, double s,
		      mem_bitio_state * bs, mg_u_long *bits)
{
  register mg_u_long val;
  DECODE_CONTINUE (*bs)
    if (bits)
    ELIAS_DECODE_L (val, b, s, *bits);
  else
    ELIAS_DECODE (val, b, s);
  DECODE_PAUSE (*bs)
    return (val);
}

void 
BIO_Mem_Bblock_Encode (mg_u_long val, mg_u_long b,
		       mem_bitio_state * bs, mg_u_long *bits)
{
  ENCODE_CONTINUE (*bs)
    if (bits)
    BBLOCK_ENCODE_L (val, b, *bits);
  else
    BBLOCK_ENCODE (val, b);
  ENCODE_PAUSE (*bs)
}


mg_u_long 
BIO_Mem_Bblock_Decode (mg_u_long b, mem_bitio_state * bs,
		       mg_u_long *bits)
{
  register mg_u_long val;
  DECODE_CONTINUE (*bs)
    if (bits)
    BBLOCK_DECODE_L (val, b, *bits);
  else
    BBLOCK_DECODE (val, b);
  DECODE_PAUSE (*bs)
    return (val);
}

void 
BIO_Mem_Decode_Seek (mg_u_long pos, mem_bitio_state * bs)
{
  DECODE_CONTINUE (*bs)
    DECODE_SEEK (pos);
  DECODE_PAUSE (*bs)
}
