## NAME

         huf_compress - performs lossless Huffman coding

## SYNOPSIS

          #include <stdio.h>
          #include <stdlib.h>
          #include <time.h>
          #include <string.h>
          #include <sys/types.h>
          #include <sys/stat.h>
          #include "CVIPtoolkit.h"
          #include "CVIPconvert.h"
          #include "CVIPdef.h"
          #include "huffman.h"

         int huf_compress(Image *inputImage, char *filename)

          <filename> - pointer to a character array
          <inputImage> - pointer to the image

         Image *huf_decompress(char *filename)

          <filename> - pointer to a character array

## PATH

         $CVIPHOME/COMPRESSION/huffman.c

## DESCRIPTION

         huf_compress takes two parameters, they are a pointer to the
         input  image  structure,  and  the  file  name  to which the
         compressed image is to be stored.  The user doesn't have  to
         provide  the filename extension "huf". Even if the user for-
         gets to enter the extension or enters a wrong extension  the
         programme  takes  care  of it by appending or replacing with
         the correct extension("huf"). At the end of the compression,
         this  routine automatically writes to the working window the
         compression ratio. Series of steps are involved  in  huffman
         coding.  First the input image is read. Then the array table
         is built with the symbol(greylevel value) and  frequency  of
         occurence.  Then  a  binary  tree  is  built  from the array
         table(probability array). Using the  binary  tree  that  was
         built each symbol(greylevel value) is encoded and written to
         the user defined binary file.

         huf_decompress takes a pointer to the  character  array  and
         returns   a  pointer  to  the  image.  The  character  array
         represents the filename to be  decoded  with  the  extension
         "huf".  It  returns  a  pointer to the decoded image. During
         decompression process the encoded file is read. The  encoded
         file  size, symbol frequency, are extracted from the encoded
         file. A binary tree is built from the probability table that
         was  stored  in  the  encoded  file.  The  original image is
         recovered without any loss in information by parsing through
         the binary tree.

## TYPES AND CONSTANTS

         None

## RETURN VALUES

         huf_compress: 0 on success, -1 on failure

         huf_decompress: an uncompressed image pointer on success,  a
         NULL pointer on failure

## HISTORY

         History information recorded: None

## EXAMPLE

          #include <CVIPtoolkit.h>
          #include <CVIPimage.h>
          #include <CVIPdef.h>
          #include <CVIPconvert.h>
          #include <CVIPview.h>
          #include "huffman.h"
          #include <sys/types.h>
          #include <sys/stat.h>
          #define VIEWER "picture"
          #define VIDEO_APP "SunVideo &"

          void main()
          {
          Image *cvipImage;
          IMAGE_FORMAT format;
          char *inputfile,*outputfile;

          setDisplay_Image(VIEWER, "Default");

          print_CVIP("\n\t\tEnter the  Input File Name:  ");
          inputfile =(char *) getString_CVIP();
          format = getFormat_CVIP(inputfile);
          cvipImage = read_Image(inputfile,1);
          view_Image(cvipImage, inputfile);
          free(inputfile);
          /* the following call performs the huffman coding of
          the input image */
          huf_compress(cvipImage,"file1");
          /* the following call performs the huffman decoding
          of the "file1" */
          cvipImage=huf_decompress("file1");
          print_CVIP("\n\t\tEnter the Output File Name:  ");
          outputfile = getString_CVIP();
          view_Image(cvipImage,outputfile);
          write_Image(cvipImage,outputfile,CVIP_NO,CVIP_NO,format,1);
          free(outputfile);
          }

## SEE ALSO

         libcompress

## DIAGNOSTICS

         The Huffman coding and decoding algorithms was  designed  to
         work only on monochrome image(.pgm).

## AUTHOR

         Implemented By: Mark Heffron SIUE

         Ported By     : Muthu kumar, SIUE

         Copyright (C) 1996 SIUE - by Scott E. Umbaugh.