Linux Game Programming for PC & Embedded Systems using SDL
Presented by
Fore June
Author of Windows Fan, Linux Fan

A simple video codec.

codecio.h
runhuf.h
encode.h
decode.h
dct_video.h
common.h
fbitios.h
avilib.h
vcodec.cpp
runhuf.cpp
encode.cpp
decode.cpp
dct_video.cpp
fbitios.cpp
Makefile
sample_video.avi ( not zipped )
avilib.o ( not zipped )



runhuf.h:
#ifndef RUNHUF_H
#define RUNHUF_H

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <set>
#include "fbitios.h"

using namespace std;

#define NSymbols        256
#define Qstep 		12

typedef struct {
  unsigned char run;
  short level;
  char last;
} run3D;

class RunHuff {
public:
  run3D r;
  unsigned int codeword;
  char hlen;            //length of Huffman code
  short index;          //table index where codeword saved
  RunHuff() {}          //constructors
  RunHuff ( run3D a, unsigned c, char len, short idx ) { r = a, codeword = c, hlen = len; index = idx; }

  //'<' operator is to order run-level tuples so that they can be saved in a binary tree ( set )
  friend bool operator < ( RunHuff left, RunHuff right ) {
    if ( left.r.run < right.r.run )
      return true;
    if ( left.r.run >  right.r.run )
      return false;
    //run equals
    if ( left.r.level < right.r.level )
      return true;
    if ( left.r.level > right.r.level )
      return false;
   //both run and level equal
    if ( left.r.last > right.r.last )
      return true;
    return false;       //so, the left object is not smaller than the right
  }
};

class Dtables {
public:
  short huf_tree[1024];                 //table containing Huffman Tree
  run3D run_table[512];                 //table containing run-level codewords
};

void quantize_block ( short coef[] );
void inverse_quantize_block ( short coef[] );
void reorder ( short Y[], short Yr[] );
void reverse_reorder ( short Yr[], short Y[] );
void run_block ( short Y[], run3D runs[] );
void run_decode ( run3D runs[], short Y[] );
void build_htable ( set<RunHuff> &htable );
void escape_encode ( bitFileIO &outputs, run3D &r );
void huff_encode ( set<RunHuff> &htable, run3D runs[], bitFileIO *outputs );
void build_huff_tree ( set<RunHuff> &htable, Dtables &d );
short huff_decode( bitFileIO *bf, Dtables &d,  run3D runs[] );
void print_htable ( set<RunHuff> &htable );
void print_block ( short s[] );
#endif