[Forensics-changes] [SCM] debian-forensics/libphash branch, upstream, updated. upstream/0.7-1-g9c212ed

Tiago Bortoletto Vaz tiago at debian.org
Fri Dec 25 17:45:19 UTC 2009


The following commit has been merged in the upstream branch:
commit 9c212ed4af9cc037c691cdecca1c7fc68fb4ab4a
Author: Tiago Bortoletto Vaz <tiago at debian.org>
Date:   Fri Dec 25 15:41:25 2009 -0200

    Adding upstream version version.

diff --git a/examples/build_mvptree.cpp b/examples/build_mvptree.cpp
deleted file mode 100644
index ce90495..0000000
--- a/examples/build_mvptree.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-#include <stdio.h>
-#include <dirent.h>
-#include "pHash.h"
-
-
-
-int main(int argc, char **argv){
- 
-    const char *dir_name = argv[1];/* name of dir to retrieve image files */
-    const char *filename = argv[2];/* name of file to save db */
-
-    MVPFile mvpfile;
-    ph_mvp_init(&mvpfile);
-    mvpfile.filename = strdup(filename);
-    mvpfile.hashdist = hammingdistance;
-    mvpfile.hash_type = UINT64ARRAY;
-
-
-    ulong64 tmphash = 0;
-    
-    int nbfiles = 0;
-    printf("dir name: %s\n", dir_name);
-    char **files = ph_readfilenames(dir_name,nbfiles);
-    if (!files){
-	printf("mem alloc error\n");
-	exit(1);
-    }
-    printf("nbfiles = %d\n", nbfiles);
-    DP **hashlist = (DP**)malloc(nbfiles*sizeof(DP*));
-    if (!hashlist){
-	printf("mem alloc error\n");
-	exit(1);
-    }
-
-    int count = 0;
-    for (int i=0;i<nbfiles;i++){
-	printf("file[%d]: %s ", i, files[i]);
-	if (ph_dct_imagehash(files[i],tmphash) < 0){
-	    printf("could not get for file %s\n",files[i]);
-	    continue;
-	}
-	printf("hash = %llx\n", tmphash);
-
-        hashlist[count] = ph_malloc_datapoint(mvpfile.hash_type,mvpfile.pathlength);
-        if (!hashlist[count]){
-	    printf("mem alloc error\n");
-	    exit(1);
-	}
-	hashlist[count]->id = strdup(files[i]);
-        void *ptr_hash = malloc(8);
-	if (!ptr_hash){
-            printf("unable to allocate mem\n");
-            exit(1);
-        }
-        hashlist[count]->hash = ptr_hash;
-	ulong64 *ptr = (ulong64*)hashlist[count]->hash;
-        *ptr = tmphash;
-	hashlist[count]->hash_length = 1;
-         count++;
-    }
-
- 
-
-    if (ph_save_mvptree(&mvpfile, hashlist, count) < 0){
-	printf("unable to save %s\n", filename);
-	exit(1);
-    }
-
-    return 0;
-}
diff --git a/examples/test_audiophash.cpp b/examples/test_audiophash.cpp
deleted file mode 100644
index 205a3ed..0000000
--- a/examples/test_audiophash.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
-
-    pHash, the open source perceptual hash library
-    Copyright (C) 2009 Aetilius, Inc.
-    All rights reserved.
-
-    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 3 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, see <http://www.gnu.org/licenses/>.
-
-    Evan Klinger - eklinger at phash.org
-    David Starkweather - dstarkweather at phash.org
-
-*/
-
-#include <cstdio>
-#include <cstdlib>
-#include <dirent.h>
-#include <errno.h>
-#include <algorithm>
-#include <vector>
-#include <string.h>
-#include "audiophash.h"
-
-#define TRUE 1
-#define FALSE 0
-
-using namespace std;
-
-/**
- * struct to hold hash
- **/
-struct data_point {
-    int nbframes;    //number of frames, i.e. length of hash
-    char *name;      //name of file from which hash is computed
-    uint32_t *hash;  //pointer to start of hash
-};
-
-struct data_point* ph_malloc_dp(){
-    
-    return (struct data_point*)malloc(sizeof(struct data_point));
-    
-}
-/**
- * purpose: auxiliary function to compare data points by name for sorting
- **/
-bool cmp_lt_dp(struct data_point dpa, struct data_point dpb){
-    int result = strcmp(dpa.name, dpb.name);
-    if (result < 0)
-	return TRUE;
-    return FALSE;
-}
-/**
- *  TEST
- * 
- * purpose: test harness for audiohash functions; reads in files from two directories that are
- *          specified on the command line;  same number of files in each directory; each file name
- *          represented in each directory.  The program reads in the files, computes the hash 
- *          and sorts the hash into a vector. Each hash is then compared to the corresponding hash
- *          from the other directory in the sorted order.  These are the "inter" comparisons, where
- *          a confidence vector is computed, the max value being used as a confidence score to
- *          indicate the percentage confidence of a similar file.
- *
- *          The program then uses the first vector to compare hashes from different images.  Each
- *          hash is compared to each successive hash in the list in sorted order.  The max value
- *          of the confidence vector is used as a confidence score to indicate the confidence of 
- *          a match.  These are the "inter" comparisons.
- *
- *          params
- *                  ber threshold  - bit error rate threshold (0.25 to 0.35)
- *                  block_size     - size of block of frames to compare at a time (256)
- *      
- *          
- *         Confidence scores range from 0 to 1.0.  A good threshold for determining similarity
- *         is 0.50.
-**/
-int main(int argc, char **argv){
-
-    if (argc < 3){
-	printf("no args");
-	exit(1);
-    }
-    const char *dir_name  = argv[1];     //first directory
-    const char *dir_name2 = argv[2];     //second directory
-    const float threshold = 0.30;        //ber threshold (0.25-0.35)
-    const int block_size = 256;          //number of frames to compare at a time
-    const int sr = 8000;                 //sample rate to convert the stream
-    const int channels = 1;              //number of channels to convert stream
-    int N;
-    int nbframes;
-    float *buf = NULL;
-    uint32_t *hash = NULL;
-    errno = 0;
-    struct dirent *dir_entry;
-    struct data_point *dp;
-    vector<struct data_point> hashlist;  //vector for first directory hashes
-    vector<struct data_point> hashlist2; //vector for second directory hashes
-    int nbfiles = 0;
-    unsigned int i=0;
-
-
-    printf("reading files in %s ...\n",dir_name);
-    //open first directory
-    DIR *dir = opendir(dir_name);
-    if (!dir){
-	printf("could not open directory\n");
-	exit(1);
-    }
-    char path[100];
-    path[0]='\0';
-    while ((dir_entry = readdir(dir))!=0) {
-	if (strcmp(dir_entry->d_name,".") && strcmp(dir_entry->d_name,"..")){
-	    strcat(path,dir_name);
-	    strcat(path,"/");
-	    strcat(path,dir_entry->d_name);
-	    buf = ph_readaudio(path,sr,channels,N);
-	    if (!buf)
-		continue;
-	    hash = ph_audiohash(buf,N,sr,nbframes);
-            if (!hash)
-                continue;
-	    dp = ph_malloc_dp();
-	    dp->name = strdup(dir_entry->d_name);
-	    dp->hash = hash;
-	    dp->nbframes = nbframes;
-	    hashlist.push_back(*dp);
-	    i++;
-	    nbfiles++;
-	}
-	path[0]='\0';
-	errno = 0;
-    }
-
-    printf("sorting list ...\n");
-    sort(hashlist.begin(),hashlist.end(),cmp_lt_dp);
-
-    printf("hit any key\n");
-    getchar();
-
-    printf("reading files in %s ... \n",dir_name2);
-    //open first directory
-    dir = opendir(dir_name2);
-    if (!dir){
-	printf("could not open directory\n");
-	exit(1);
-    }
-    i=0;
-    path[0]='\0';
-    while ((dir_entry = readdir(dir)) != 0) {
-	if (strcmp(dir_entry->d_name,".") && strcmp(dir_entry->d_name,"..")){
-	    strcat(path,dir_name2);
-	    strcat(path,"/");
-	    strcat(path,dir_entry->d_name);
-	    buf = ph_readaudio(path,sr,channels,N);
-	    if (!buf)
-		continue;
-	    hash = ph_audiohash(buf,N,sr,nbframes);
-            if (!hash)
-                continue;
-	    dp = ph_malloc_dp();
-	    dp->name = strdup(dir_entry->d_name);
-	    dp->hash = hash;
-	    dp->nbframes = nbframes;
-	    hashlist2.push_back(*dp);
-	    i++;
-	    nbfiles++;
-	}
-	path[0]='\0';
-	errno = 0;
-    }
-
-    if (errno){
-	printf("error reading files\n");
-	exit(1);
-    }
-    
-    printf("sorting list ...\n");
-    sort(hashlist2.begin(),hashlist2.end(),cmp_lt_dp);
-
-    printf("hit any key\n");
-    getchar();
-
-    int Nc;
-    double maxC = 0.0;
-    double *pC = NULL;
-
-    printf("intra confidence values:\n");
-    printf("************************\n");
-    for (i=0;i<hashlist.size();i++){
-	printf("file1: %s    file2: %s ",hashlist[i].name,hashlist2[i].name);
-	pC = ph_audio_distance_ber(hashlist[i].hash, hashlist[i].nbframes, hashlist2[i].hash, hashlist2[i].nbframes, threshold, block_size, Nc);
-
-	maxC = 0.0;
-	for (int j=0;j<Nc;j++){
-	    if (pC[j] > maxC){
-		maxC = pC[j];
-	    }
-	}
-	printf("cs = %3.2f\n",maxC);
-    }
-
-    printf("***********************\n");
-    printf("hit any key\n");
-    getchar();
-
-
-    printf("inter confidence values\n");
-    printf("***********************\n");
-    for (i=0;i<hashlist.size();i++){
-	for (unsigned int j=i+1;j<hashlist.size();j++){
-	    printf("file1:%s file2: %s ",hashlist[i].name,hashlist[j].name);
-	    pC = ph_audio_distance_ber(hashlist[i].hash, hashlist[i].nbframes,hashlist[j].hash,hashlist[j].nbframes, threshold, block_size, Nc);
-	    maxC = 0.0;
-	    for (int k=0;k<Nc;k++){
-		if (pC[k]>maxC)
-		    maxC = pC[k];
-	    }
-	    printf("cs=%3.2f\n",maxC);
-	}
-    }
-    printf("done\n");
-
-    return 0;
-}
diff --git a/examples/test_dctvideohash.cpp b/examples/test_dctvideohash.cpp
deleted file mode 100644
index bd6d11d..0000000
--- a/examples/test_dctvideohash.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-#include "stdio.h"
-#include "pHash.h"
-#include "CImg.h"
-#include "cimgffmpeg.h"
-
-int main(int argc, char **argv){
-    if (argc < 2){
-	printf("not enough input arguments\n");
-	return -1;
-    }
-    const char *file1 = argv[1];
-    const char *file2t = argv[2];
-
-    char *file2 = strdup(file2t);
-
-    if (!file1 || !file2){
-	printf("not enough arguments\n");
-	exit(1);
-    }
-
-    ulong64 *hash1, *hash2;
-    int L1, L2;
-    double sim;
-
-    printf("file1=%s\n", file1);
-    hash1 = ph_dct_videohash(file1, L1);
-    if (!hash1){
-	exit(2);
-    }
-    printf("length %d\n", L1);
-   for (int i=0;i<L1;i++)
-       printf("hash1[%d]=%llx\n", i, hash1[i]);
-
-    do {
-
-	printf("file=%s\n", file2);
-	hash2 = ph_dct_videohash(file2, L2);
-	if (!hash2){
-	    printf("hash 2 is null\n");
-	    free(hash1);
-	    exit(3);
-	}
-
-	printf("length %d\n", L2);
-
-	sim = ph_dct_videohash_dist(hash1, L1, hash2, L2, 21);
-	printf("similarity %f\n", sim);
-
-	free(hash2);
-	hash2 = NULL;
-
-	file2 = fgets(file2, 80, stdin);
-	file2[strlen(file2)-1] = '\0';
-    } while (strcmp(file2,"exit"));
-
-    free(hash1);
-    free(hash2);
-    hash1 = NULL;
-    hash2 = NULL;
-       
-    printf("done\n");
-    return 0;
-}
- 
diff --git a/examples/test_texthash.cpp b/examples/test_texthash.cpp
deleted file mode 100644
index c103081..0000000
--- a/examples/test_texthash.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "pHash.h"
-
-int main(int argc, char **argv){
-
-    if (argc < 3){
-	printf("not enough input args\n");
-	exit(1);
-    }
-    const char *file1 = argv[1];
-    const char *file2 = argv[2];
-
-    printf("file1: %s\n", file1);
-    int nbhashes1 = 0;
-    TxtHashPoint *hash1 = ph_texthash(file1,&nbhashes1);
-    if (!hash1){
-	printf("unable to complete text hash function\n");
-	exit(1);
-    }
-    printf("length %d\n", nbhashes1);
-
-    
-    printf("file2: %s\n", file2);
-    int nbhashes2 = 0;
-    TxtHashPoint *hash2 = ph_texthash(file2,&nbhashes2);
-    if (!hash2){
-	printf("unable to complete text hash function\n");
-	exit(2);
-    }
-
-    printf("length %d\n", nbhashes2);
-    int count,j;
-    TxtMatch *matches = ph_compare_text_hashes(hash1, nbhashes1, hash2, nbhashes2, &count);
-    if (!matches){
-	printf("unable to complete compare function\n");
-	exit(3);
-    }
-    
-    printf(" %d matches\n", count);
-    printf(" indxA  indxB  length\n");
-    for (j=0;j<count;j++){
-	printf(" %d %d %d\n", matches[j].first_index, matches[j].second_index,matches[j].length); 
-    }
-
-    return 0;
-}
diff --git a/AUTHORS b/pHash-0.7.2/AUTHORS
similarity index 100%
rename from AUTHORS
rename to pHash-0.7.2/AUTHORS
diff --git a/COPYING b/pHash-0.7.2/COPYING
similarity index 100%
rename from COPYING
rename to pHash-0.7.2/COPYING
diff --git a/ChangeLog b/pHash-0.7.2/ChangeLog
similarity index 91%
rename from ChangeLog
rename to pHash-0.7.2/ChangeLog
index 6c211d5..7be0a89 100644
--- a/ChangeLog
+++ b/pHash-0.7.2/ChangeLog
@@ -1,8 +1,18 @@
-0.6
+0.7.1
+---
+12.22.2009 put code in cimgffmpeg.h header into own .cpp file
+           modify GetNumberVideoFrames() function in cimgffmpeg.cpp to make it faster
+12.20.2009 update java bindings, remove dependency on fftw, include spec file for building rpm
+
+
+0.7
 ---
 12.12.2009 added improvements to textual hash and texthash.cpp, texthash2.cpp example files
 12.10.2009 updated phash.cpp and cimgffmpeg.h code for cimg 1.3.2
 	   added alternate to mremap (munmap/mmap) in the case mremap isnt present
+
+0.6
+---
 10.07.2009 added new variable length dct video hash
 
 
diff --git a/INSTALL b/pHash-0.7.2/INSTALL
similarity index 100%
rename from INSTALL
rename to pHash-0.7.2/INSTALL
diff --git a/Makefile.am b/pHash-0.7.2/Makefile.am
similarity index 83%
rename from Makefile.am
rename to pHash-0.7.2/Makefile.am
index 48a1660..5fbbb4a 100644
--- a/Makefile.am
+++ b/pHash-0.7.2/Makefile.am
@@ -1,6 +1,6 @@
 SUBDIRS = src bindings examples
 
-EXTRA_DIST = $(subdirs)
+EXTRA_DIST = $(subdirs) libpHash.spec
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = pHash.pc
diff --git a/Makefile.in b/pHash-0.7.2/Makefile.in
similarity index 99%
rename from Makefile.in
rename to pHash-0.7.2/Makefile.in
index b0cd160..baecff0 100644
--- a/Makefile.in
+++ b/pHash-0.7.2/Makefile.in
@@ -246,7 +246,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 SUBDIRS = src bindings examples
-EXTRA_DIST = $(subdirs)
+EXTRA_DIST = $(subdirs) libpHash.spec
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = pHash.pc
 LIBTOOL_DEPS = @LIBTOOL_DEPS@
diff --git a/NEWS b/pHash-0.7.2/NEWS
similarity index 100%
rename from NEWS
rename to pHash-0.7.2/NEWS
diff --git a/README b/pHash-0.7.2/README
similarity index 100%
rename from README
rename to pHash-0.7.2/README
diff --git a/TODO b/pHash-0.7.2/TODO
similarity index 51%
rename from TODO
rename to pHash-0.7.2/TODO
index 3aff6ca..17cb86a 100644
--- a/TODO
+++ b/pHash-0.7.2/TODO
@@ -1,5 +1,5 @@
 update design docs with new video algorithm and api
 add optimized dct
 create one pass hash
-pHash Pro (detailed comments, support, one-pass hash?, remove dependency on swscale and fftw, multi-threaded/process, tcp/ip service?)
+pHash Pro (detailed comments, support, one-pass hash?, multi-threaded/process, tcp/ip service?)
 pHash Forensics (signature, iris, fingerprint) & gui app
diff --git a/aclocal.m4 b/pHash-0.7.2/aclocal.m4
similarity index 100%
rename from aclocal.m4
rename to pHash-0.7.2/aclocal.m4
diff --git a/bindings/Makefile.am b/pHash-0.7.2/bindings/Makefile.am
similarity index 100%
rename from bindings/Makefile.am
rename to pHash-0.7.2/bindings/Makefile.am
diff --git a/bindings/Makefile.in b/pHash-0.7.2/bindings/Makefile.in
similarity index 100%
rename from bindings/Makefile.in
rename to pHash-0.7.2/bindings/Makefile.in
diff --git a/bindings/java/Makefile.am b/pHash-0.7.2/bindings/java/Makefile.am
similarity index 100%
rename from bindings/java/Makefile.am
rename to pHash-0.7.2/bindings/java/Makefile.am
diff --git a/bindings/java/Makefile.in b/pHash-0.7.2/bindings/java/Makefile.in
similarity index 100%
rename from bindings/java/Makefile.in
rename to pHash-0.7.2/bindings/java/Makefile.in
diff --git a/bindings/java/pHash-jni.cpp b/pHash-0.7.2/bindings/java/pHash-jni.cpp
similarity index 89%
rename from bindings/java/pHash-jni.cpp
rename to pHash-0.7.2/bindings/java/pHash-jni.cpp
index bb56212..035f2c4 100644
--- a/bindings/java/pHash-jni.cpp
+++ b/pHash-0.7.2/bindings/java/pHash-jni.cpp
@@ -40,6 +40,13 @@ typedef struct ph_jni_hash_classes
 	jfieldID hashID;
 } jniHashes;
 
+float video_distance(DP *a, DP *b)
+{
+ulong64 *hash1 = (ulong64 *)a->hash;
+ulong64 *hash2 = (ulong64 *)b->hash;
+double sim = ph_dct_videohash_dist(hash1, a->hash_length, hash2, b->hash_length, 21);
+return (float)sim;
+}
 
 float image_distance(DP *pntA, DP *pntB)
 {
@@ -84,7 +91,7 @@ float audio_distance(DP *dpA, DP *dpB)
 static jniHashes hashes[] = 
 			{ 	
 				{imClass, UINT64ARRAY, image_distance, IMAGE_HASH, imCtor, imHash_hash}, 
-				{vidClass, UINT64ARRAY, image_distance, VIDEO_HASH, vidCtor, vidHash_hash}, 
+				{vidClass, UINT64ARRAY, video_distance, VIDEO_HASH, vidCtor, vidHash_hash}, 
 				{audioClass, UINT32ARRAY, audio_distance, AUDIO_HASH, audioCtor, audioHash_hash},
 			};
 
@@ -156,11 +163,11 @@ JNIEXPORT jboolean JNICALL Java_pHash_00024MVPTree_create
 				hashlist[i]->hash_length = 1;
 				break;
 			case VIDEO_HASH:
-				ulong64 videoHash;
-				ph_dct_videohash(path, videoHash);
-                               	hashlist[i]->hash = (ulong64 *)malloc(sizeof(ulong64));
-				if(!hashlist[i]->hash)
 				{
+				int len;
+				ulong64 *vhash = ph_dct_videohash(path, len);
+				if(!vhash)
+				{					
 					for(int i = 0; i < hashLen; i++)
 					{
 						if(hashlist[i])
@@ -171,8 +178,9 @@ JNIEXPORT jboolean JNICALL Java_pHash_00024MVPTree_create
 					e->ReleaseStringUTFChars(mvp, mvpfile.filename);
 					return JNI_FALSE;
 				}
-                                *(ulong64 *)hashlist[i]->hash = videoHash;
-                                hashlist[i]->hash_length = 1;
+                                hashlist[i]->hash = vhash;
+                                hashlist[i]->hash_length = len;
+				}
 				break;
 			case AUDIO_HASH:
 				const float threshold = 0.30;
@@ -516,19 +524,50 @@ JNIEXPORT jobject JNICALL Java_pHash_imageHash
 	
 }
 #ifdef HAVE_VIDEO_HASH
+
+JNIEXPORT jdouble JNICALL Java_pHash_videoDistance
+  (JNIEnv *e, jclass cl, jobject vidHash1, jobject vidHash2, jint thresh)
+{
+
+	if(vidHash1 == NULL || vidHash2 == NULL)
+	{
+		return (jdouble)-1.0;
+	}
+
+	jint hash1_len, hash2_len;
+	jlongArray hash1, hash2;
+	hash1 = (jlongArray)e->GetObjectField(vidHash1, vidHash_hash);
+	hash2 = (jlongArray)e->GetObjectField(vidHash2, vidHash_hash);
+	hash1_len = e->GetArrayLength(hash1);
+	hash2_len = e->GetArrayLength(hash2);
+	if(hash1_len <= 0 || hash2_len <= 0)
+	{
+		return (jdouble)-1.0;
+	}
+	ulong64 *hash1_n, *hash2_n;
+	
+	hash1_n = (ulong64 *)e->GetLongArrayElements(hash1, 0);
+	hash2_n = (ulong64 *)e->GetLongArrayElements(hash2, 0);
+	jdouble sim = ph_dct_videohash_dist(hash1_n, hash1_len, hash2_n, hash2_len, thresh);
+	e->ReleaseLongArrayElements(hash1, (jlong*)hash1_n, 0);
+	e->ReleaseLongArrayElements(hash2, (jlong*)hash2_n, 0);
+	return sim;	
+}
 JNIEXPORT jobject JNICALL Java_pHash_videoHash
   (JNIEnv *e, jclass cl, jstring f)
 {
     
 	const char *file = e->GetStringUTFChars(f,0);
-    
-	ulong64 hash;
-	ph_dct_videohash(file, hash);
+    	int len;
+	ulong64 *hash =	ph_dct_videohash(file, len);
 
 	jobject videoHash = e->NewObject(vidClass, vidCtor);
 	e->SetObjectField(videoHash, hash_filename, f);
 
-	e->SetLongField(videoHash, vidHash_hash, (jlong)hash);
+	jlongArray hashVals = (jlongArray)e->GetObjectField(videoHash, vidHash_hash);
+	
+	e->SetLongArrayRegion(hashVals, 0, len, (jlong *)hash);
+	free(hash);
     	e->ReleaseStringUTFChars(f,file);
 
 	return videoHash;
diff --git a/bindings/java/pHash-jni.h b/pHash-0.7.2/bindings/java/pHash-jni.h
similarity index 95%
rename from bindings/java/pHash-jni.h
rename to pHash-0.7.2/bindings/java/pHash-jni.h
index e81f57a..0980461 100644
--- a/bindings/java/pHash-jni.h
+++ b/pHash-0.7.2/bindings/java/pHash-jni.h
@@ -60,8 +60,8 @@ JNIEXPORT jdouble JNICALL Java_pHash_audioDistance
  * Method:    videoDistance
  * Signature: (LpHash/VideoHash;LpHash/VideoHash;)I
  */
-JNIEXPORT jint JNICALL Java_pHash_videoDistance
-  (JNIEnv *, jclass, jobject, jobject);
+JNIEXPORT jdouble JNICALL Java_pHash_videoDistance
+  (JNIEnv *, jclass, jobject, jobject, jint);
 
 /*
  * Class:     pHash
diff --git a/bindings/java/pHash.java b/pHash-0.7.2/bindings/java/pHash.java
similarity index 89%
rename from bindings/java/pHash.java
rename to pHash-0.7.2/bindings/java/pHash.java
index 4554790..757b9e1 100644
--- a/bindings/java/pHash.java
+++ b/pHash-0.7.2/bindings/java/pHash.java
@@ -12,7 +12,7 @@
 	}
 	class VideoHash extends Hash 
 	{
-		long hash;
+		long[] hash;
 	}
 	class ImageHash extends Hash 
 	{
@@ -37,7 +37,7 @@ class pHash
 	native static TextHash textHash(String file);
 	native static int imageDistance(ImageHash hash1, ImageHash hash2);
 	native static double audioDistance(AudioHash hash1, AudioHash hash2);
-	native static int videoDistance(VideoHash hash1, VideoHash hash2);
+	native static double videoDistance(VideoHash hash1, VideoHash hash2, int threshold);
 	native static int textDistance(TextHash txtHash1, TextHash txtHash2);
 	private native static void pHashInit();
 	private native static void cleanup();
@@ -69,7 +69,7 @@ class pHash
 			{
 				VideoHash vHash = videoHash(args[1]);
 				VideoHash vHash2 = videoHash(args[2]);
-				System.out.println(videoDistance(vHash,vHash2));
+				System.out.println(videoDistance(vHash,vHash2, 21));
 			}
 			else if(args[i].equals("-t"))
 			{
diff --git a/bindings/java/pHash_MVPTree.h b/pHash-0.7.2/bindings/java/pHash_MVPTree.h
similarity index 100%
rename from bindings/java/pHash_MVPTree.h
rename to pHash-0.7.2/bindings/java/pHash_MVPTree.h
diff --git a/config.guess b/pHash-0.7.2/config.guess
similarity index 100%
rename from config.guess
rename to pHash-0.7.2/config.guess
diff --git a/config.h.in b/pHash-0.7.2/config.h.in
similarity index 98%
rename from config.h.in
rename to pHash-0.7.2/config.h.in
index 467c734..b4abd32 100644
--- a/config.h.in
+++ b/pHash-0.7.2/config.h.in
@@ -21,9 +21,6 @@
 /* Define to 1 if you have the `avutil' library (-lavutil). */
 #undef HAVE_LIBAVUTIL
 
-/* Define to 1 if you have the `fftw3' library (-lfftw3). */
-#undef HAVE_LIBFFTW3
-
 /* Define to 1 if you have the `m' library (-lm). */
 #undef HAVE_LIBM
 
diff --git a/config.sub b/pHash-0.7.2/config.sub
similarity index 100%
rename from config.sub
rename to pHash-0.7.2/config.sub
diff --git a/configure b/pHash-0.7.2/configure
similarity index 99%
rename from configure
rename to pHash-0.7.2/configure
index 07a42ed..c81127c 100755
--- a/configure
+++ b/pHash-0.7.2/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.63 for pHash 0.7.0.
+# Generated by GNU Autoconf 2.63 for pHash 0.7.2.
 #
 # Report bugs to <support at phash.org>.
 #
@@ -745,8 +745,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 # Identity of this package.
 PACKAGE_NAME='pHash'
 PACKAGE_TARNAME='phash'
-PACKAGE_VERSION='0.7.0'
-PACKAGE_STRING='pHash 0.7.0'
+PACKAGE_VERSION='0.7.2'
+PACKAGE_STRING='pHash 0.7.2'
 PACKAGE_BUGREPORT='support at phash.org'
 
 ac_unique_file="src/pHash.cpp"
@@ -1497,7 +1497,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures pHash 0.7.0 to adapt to many kinds of systems.
+\`configure' configures pHash 0.7.2 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1567,7 +1567,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of pHash 0.7.0:";;
+     short | recursive ) echo "Configuration of pHash 0.7.2:";;
    esac
   cat <<\_ACEOF
 
@@ -1679,7 +1679,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-pHash configure 0.7.0
+pHash configure 0.7.2
 generated by GNU Autoconf 2.63
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1693,7 +1693,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by pHash $as_me 0.7.0, which was
+It was created by pHash $as_me 0.7.2, which was
 generated by GNU Autoconf 2.63.  Invocation command line was
 
   $ $0 $@
@@ -17842,10 +17842,10 @@ fi
 
 
 if test x"$found_cimg" = x"n"; then
-	{ $as_echo "$as_me:$LINENO: checking whether CImg.h is in the src directory." >&5
-$as_echo_n "checking whether CImg.h is in the src directory.... " >&6; }
+	{ $as_echo "$as_me:$LINENO: checking whether CImg.h is in the current or src directory." >&5
+$as_echo_n "checking whether CImg.h is in the current or src directory.... " >&6; }
 
-	if test `ls src | grep "CImg.h"` >/dev/null 2>&1; then
+	if test `ls . src | grep "CImg.h"` >/dev/null 2>&1; then
 		{ $as_echo "$as_me:$LINENO: result: yes" >&5
 $as_echo "yes" >&6; }
 		found_cimg="y"
@@ -18371,10 +18371,10 @@ fi
 
 
 if test x"$found_cimg" = x"n"; then
-	{ $as_echo "$as_me:$LINENO: checking whether CImg.h is in the src directory." >&5
-$as_echo_n "checking whether CImg.h is in the src directory.... " >&6; }
+	{ $as_echo "$as_me:$LINENO: checking whether CImg.h is in the current or src directory." >&5
+$as_echo_n "checking whether CImg.h is in the current or src directory.... " >&6; }
 
-	if test `ls src | grep "CImg.h"` >/dev/null 2>&1; then
+	if test `ls . src | grep "CImg.h"` >/dev/null 2>&1; then
 		{ $as_echo "$as_me:$LINENO: result: yes" >&5
 $as_echo "yes" >&6; }
 		found_cimg="y"
@@ -18758,98 +18758,6 @@ fi
 
 found_ffmpeg="y"
 	fi
-	if test "$found_fftw" != "y"; then
-
-
-{ $as_echo "$as_me:$LINENO: checking whether FFTW3 is present" >&5
-$as_echo_n "checking whether FFTW3 is present... " >&6; }
-
-{ $as_echo "$as_me:$LINENO: checking for fftw_plan_dft_r2c_1d in -lfftw3" >&5
-$as_echo_n "checking for fftw_plan_dft_r2c_1d in -lfftw3... " >&6; }
-if test "${ac_cv_lib_fftw3_fftw_plan_dft_r2c_1d+set}" = set; then
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lfftw3  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char fftw_plan_dft_r2c_1d ();
-int
-main ()
-{
-return fftw_plan_dft_r2c_1d ();
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_cxx_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext && {
-	 test "$cross_compiling" = yes ||
-	 $as_test_x conftest$ac_exeext
-       }; then
-  ac_cv_lib_fftw3_fftw_plan_dft_r2c_1d=yes
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_fftw3_fftw_plan_dft_r2c_1d=no
-fi
-
-rm -rf conftest.dSYM
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_fftw3_fftw_plan_dft_r2c_1d" >&5
-$as_echo "$ac_cv_lib_fftw3_fftw_plan_dft_r2c_1d" >&6; }
-if test "x$ac_cv_lib_fftw3_fftw_plan_dft_r2c_1d" = x""yes; then
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBFFTW3 1
-_ACEOF
-
-  LIBS="-lfftw3 $LIBS"
-
-else
-  { { $as_echo "$as_me:$LINENO: error:
-
-*** libfftw3 not found.
-You need FFTW3. Get it at <http://fftw.org/>" >&5
-$as_echo "$as_me: error:
-
-*** libfftw3 not found.
-You need FFTW3. Get it at <http://fftw.org/>" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
-found_fftw="y"
-	fi
 	CPPFLAGS="$CPPFLAGS -DHAVE_AUDIO_HASH=1"
 fi
 
@@ -19176,7 +19084,7 @@ if test "$use_png" = "y"; then
 fi
 
 
-
+CFLAGS="$CXXFLAGS"
 # Checks for header files.
 
 
@@ -20194,108 +20102,8 @@ fi
 
 
 
-for ac_func in malloc realloc floor gettimeofday memmove memset pow sqrt strcasecmp strdup strncasecmp
-do
-as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
-{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5
-$as_echo_n "checking for $ac_func... " >&6; }
-if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
-  $as_echo_n "(cached) " >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
-   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
-#define $ac_func innocuous_$ac_func
-
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char $ac_func (); below.
-    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-    <limits.h> exists even on freestanding compilers.  */
-
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
-
-#undef $ac_func
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char $ac_func ();
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined __stub_$ac_func || defined __stub___$ac_func
-choke me
-#endif
-
-int
-main ()
-{
-return $ac_func ();
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_cxx_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext && {
-	 test "$cross_compiling" = yes ||
-	 $as_test_x conftest$ac_exeext
-       }; then
-  eval "$as_ac_var=yes"
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	eval "$as_ac_var=no"
-fi
-
-rm -rf conftest.dSYM
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
-fi
-ac_res=`eval 'as_val=${'$as_ac_var'}
-		 $as_echo "$as_val"'`
-	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-as_val=`eval 'as_val=${'$as_ac_var'}
-		 $as_echo "$as_val"'`
-   if test "x$as_val" = x""yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-done
-
 
-for ac_func in mremap
+for ac_func in mremap malloc realloc floor gettimeofday memmove memset pow sqrt strcasecmp strdup strncasecmp
 do
 as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { $as_echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -20894,7 +20702,7 @@ exec 6>&1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by pHash $as_me 0.7.0, which was
+This file was extended by pHash $as_me 0.7.2, which was
 generated by GNU Autoconf 2.63.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -20957,7 +20765,7 @@ Report bugs to <bug-autoconf at gnu.org>."
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_version="\\
-pHash config.status 0.7.0
+pHash config.status 0.7.2
 configured by $0, generated by GNU Autoconf 2.63,
   with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/configure.ac b/pHash-0.7.2/configure.ac
similarity index 93%
rename from configure.ac
rename to pHash-0.7.2/configure.ac
index 4ad97ed..00cfa19 100644
--- a/configure.ac
+++ b/pHash-0.7.2/configure.ac
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.61)
-AC_INIT([pHash],[0.7.0],[support at phash.org])
+AC_INIT([pHash],[0.7.2],[support at phash.org])
 AM_INIT_AUTOMAKE($PACKAGE_NAME,$PACKAGE_VERSION)
 AC_CONFIG_SRCDIR([src/pHash.cpp])
 AC_CONFIG_HEADERS([config.h])
@@ -53,9 +53,9 @@ AC_DEFUN([AC_CHECK_CIMG], [
 AC_CHECK_HEADER([CImg.h], [found_cimg="y"], [found_cimg="n"])
 
 if test x"$found_cimg" = x"n"; then
-	AC_MSG_CHECKING([whether CImg.h is in the src directory.])
+	AC_MSG_CHECKING([whether CImg.h is in the current or src directory.])
 	
-	if [test `ls src | grep "CImg.h"` >/dev/null 2>&1]; then
+	if [test `ls . src | grep "CImg.h"` >/dev/null 2>&1]; then
 		AC_MSG_RESULT([yes])
 		found_cimg="y"
 	else
@@ -135,9 +135,6 @@ AS_IF([test x"$audio_hash" != x"no"],
 	if test "$found_ffmpeg" != "y"; then
 		AC_CHECK_FFMPEG() 
 	fi
-	if test "$found_fftw" != "y"; then
-		AC_CHECK_FFTW3() 
-	fi
 	CPPFLAGS="$CPPFLAGS -DHAVE_AUDIO_HASH=1"])
 
 
@@ -165,7 +162,7 @@ AS_IF([test "$use_png" = "y"],
 	CPPFLAGS="$CPPFLAGS -Dcimg_use_png"
 	LDFLAGS="$LDFLAGS -lpng"])
 
-
+CFLAGS="$CXXFLAGS"
 # Checks for header files.
 AC_CHECK_HEADERS([limits.h stdlib.h string.h sys/time.h unistd.h])
 
@@ -183,7 +180,6 @@ pHash requires 64-bit integers for video and image hashes.])])
 
 # Checks for library functions.
 AC_FUNC_ERROR_AT_LINE
-AC_CHECK_FUNCS([malloc realloc floor gettimeofday memmove memset pow sqrt strcasecmp strdup strncasecmp])
-AC_CHECK_FUNCS([mremap])
+AC_CHECK_FUNCS([mremap malloc realloc floor gettimeofday memmove memset pow sqrt strcasecmp strdup strncasecmp])
 AC_CONFIG_FILES([Makefile src/Makefile examples/Makefile pHash.pc bindings/Makefile bindings/java/Makefile])
 AC_OUTPUT
diff --git a/depcomp b/pHash-0.7.2/depcomp
similarity index 90%
rename from depcomp
rename to pHash-0.7.2/depcomp
index e5f9736..df8eea7 100755
--- a/depcomp
+++ b/pHash-0.7.2/depcomp
@@ -1,10 +1,10 @@
 #! /bin/sh
 # depcomp - compile a program generating dependencies as side-effects
 
-scriptversion=2007-03-29.01
+scriptversion=2009-04-28.21; # UTC
 
-# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007 Free Software
-# Foundation, Inc.
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
+# Software Foundation, Inc.
 
 # 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
@@ -17,9 +17,7 @@ scriptversion=2007-03-29.01
 # 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., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -87,6 +85,15 @@ if test "$depmode" = dashXmstdout; then
    depmode=dashmstdout
 fi
 
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+   # This is just like msvisualcpp but w/o cygpath translation.
+   # Just convert the backslash-escaped backslashes to single forward
+   # slashes to satisfy depend.m4
+   cygpath_u="sed s,\\\\\\\\,/,g"
+   depmode=msvisualcpp
+fi
+
 case "$depmode" in
 gcc3)
 ## gcc 3 implements dependency tracking that does exactly what
@@ -192,14 +199,14 @@ sgi)
 ' < "$tmpdepfile" \
     | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
     tr '
-' ' ' >> $depfile
-    echo >> $depfile
+' ' ' >> "$depfile"
+    echo >> "$depfile"
 
     # The second pass generates a dummy entry for each header file.
     tr ' ' '
 ' < "$tmpdepfile" \
    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
-   >> $depfile
+   >> "$depfile"
   else
     # The sourcefile does not contain any dependencies, so just
     # store a dummy comment line, to avoid errors with the Makefile
@@ -328,7 +335,12 @@ hp2)
   if test -f "$tmpdepfile"; then
     sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
     # Add `dependent.h:' lines.
-    sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
+    sed -ne '2,${
+	       s/^ *//
+	       s/ \\*$//
+	       s/$/:/
+	       p
+	     }' "$tmpdepfile" >> "$depfile"
   else
     echo "#dummy" > "$depfile"
   fi
@@ -404,7 +416,7 @@ dashmstdout)
 
   # Remove the call to Libtool.
   if test "$libtool" = yes; then
-    while test $1 != '--mode=compile'; do
+    while test "X$1" != 'X--mode=compile'; do
       shift
     done
     shift
@@ -455,32 +467,39 @@ makedepend)
   "$@" || exit $?
   # Remove any Libtool call
   if test "$libtool" = yes; then
-    while test $1 != '--mode=compile'; do
+    while test "X$1" != 'X--mode=compile'; do
       shift
     done
     shift
   fi
   # X makedepend
   shift
-  cleared=no
-  for arg in "$@"; do
+  cleared=no eat=no
+  for arg
+  do
     case $cleared in
     no)
       set ""; shift
       cleared=yes ;;
     esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
     case "$arg" in
     -D*|-I*)
       set fnord "$@" "$arg"; shift ;;
     # Strip any option that makedepend may not understand.  Remove
     # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
     -*|$object)
       ;;
     *)
       set fnord "$@" "$arg"; shift ;;
     esac
   done
-  obj_suffix="`echo $object | sed 's/^.*\././'`"
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
   touch "$tmpdepfile"
   ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
   rm -f "$depfile"
@@ -500,7 +519,7 @@ cpp)
 
   # Remove the call to Libtool.
   if test "$libtool" = yes; then
-    while test $1 != '--mode=compile'; do
+    while test "X$1" != 'X--mode=compile'; do
       shift
     done
     shift
@@ -538,13 +557,27 @@ cpp)
 
 msvisualcpp)
   # Important note: in order to support this mode, a compiler *must*
-  # always write the preprocessed file to stdout, regardless of -o,
-  # because we must use -o when running libtool.
+  # always write the preprocessed file to stdout.
   "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
   IFS=" "
   for arg
   do
     case "$arg" in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
     "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
 	set fnord "$@"
 	shift
@@ -557,16 +590,23 @@ msvisualcpp)
 	;;
     esac
   done
-  "$@" -E |
-  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
   rm -f "$depfile"
   echo "$object : \\" > "$depfile"
-  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
   echo "	" >> "$depfile"
-  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
   rm -f "$tmpdepfile"
   ;;
 
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
 none)
   exec "$@"
   ;;
@@ -585,5 +625,6 @@ exit 0
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
 # End:
diff --git a/examples/Makefile.am b/pHash-0.7.2/examples/Makefile.am
similarity index 100%
rename from examples/Makefile.am
rename to pHash-0.7.2/examples/Makefile.am
diff --git a/examples/Makefile.in b/pHash-0.7.2/examples/Makefile.in
similarity index 100%
rename from examples/Makefile.in
rename to pHash-0.7.2/examples/Makefile.in
diff --git a/examples/add_mvptree.cpp b/pHash-0.7.2/examples/add_mvptree.cpp
similarity index 67%
copy from examples/add_mvptree.cpp
copy to pHash-0.7.2/examples/add_mvptree.cpp
index 8666b0d..abf25c5 100644
--- a/examples/add_mvptree.cpp
+++ b/pHash-0.7.2/examples/add_mvptree.cpp
@@ -1,3 +1,27 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
 #include <stdio.h>
 #include <dirent.h>
 #include "pHash.h"
diff --git a/examples/add_mvptree_audio.cpp b/pHash-0.7.2/examples/add_mvptree_audio.cpp
similarity index 73%
rename from examples/add_mvptree_audio.cpp
rename to pHash-0.7.2/examples/add_mvptree_audio.cpp
index 6bf5953..e83619c 100644
--- a/examples/add_mvptree_audio.cpp
+++ b/pHash-0.7.2/examples/add_mvptree_audio.cpp
@@ -1,3 +1,27 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
 #include <stdio.h>
 #include <dirent.h>
 #include "pHash.h"
diff --git a/examples/add_mvptree.cpp b/pHash-0.7.2/examples/build_mvptree.cpp
similarity index 61%
rename from examples/add_mvptree.cpp
rename to pHash-0.7.2/examples/build_mvptree.cpp
index 8666b0d..29edb4f 100644
--- a/examples/add_mvptree.cpp
+++ b/pHash-0.7.2/examples/build_mvptree.cpp
@@ -1,7 +1,33 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
 #include <stdio.h>
 #include <dirent.h>
 #include "pHash.h"
 
+
+
 int main(int argc, char **argv){
  
     const char *dir_name = argv[1];/* name of dir to retrieve image files */
@@ -12,7 +38,7 @@ int main(int argc, char **argv){
     mvpfile.filename = strdup(filename);
     mvpfile.hashdist = hammingdistance;
     mvpfile.hash_type = UINT64ARRAY;
-   
+
 
     ulong64 tmphash = 0;
     
@@ -57,11 +83,11 @@ int main(int argc, char **argv){
          count++;
     }
 
-    printf("add files to file %s\n", filename);
-    int n = ph_add_mvptree(&mvpfile, hashlist, count);
-    printf("number saved %d out of %d\n", n,count);
-    if (n <= 0){
-	printf("unable to add points to %s\n", filename);
+ 
+
+    if (ph_save_mvptree(&mvpfile, hashlist, count) < 0){
+	printf("unable to save %s\n", filename);
+	exit(1);
     }
 
     return 0;
diff --git a/examples/build_mvptree_audio.cpp b/pHash-0.7.2/examples/build_mvptree_audio.cpp
similarity index 73%
rename from examples/build_mvptree_audio.cpp
rename to pHash-0.7.2/examples/build_mvptree_audio.cpp
index 1ca437c..ce65e72 100644
--- a/examples/build_mvptree_audio.cpp
+++ b/pHash-0.7.2/examples/build_mvptree_audio.cpp
@@ -1,3 +1,27 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
 #include <stdio.h>
 #include <dirent.h>
 #include "pHash.h"
diff --git a/examples/query_mvptree.cpp b/pHash-0.7.2/examples/query_mvptree.cpp
similarity index 75%
rename from examples/query_mvptree.cpp
rename to pHash-0.7.2/examples/query_mvptree.cpp
index a776886..4da8283 100644
--- a/examples/query_mvptree.cpp
+++ b/pHash-0.7.2/examples/query_mvptree.cpp
@@ -1,3 +1,27 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
 #include <stdio.h>
 #include <dirent.h>
 #include "pHash.h"
diff --git a/examples/query_mvptree_audio.cpp b/pHash-0.7.2/examples/query_mvptree_audio.cpp
similarity index 75%
rename from examples/query_mvptree_audio.cpp
rename to pHash-0.7.2/examples/query_mvptree_audio.cpp
index 3564fcd..a65bdf9 100644
--- a/examples/query_mvptree_audio.cpp
+++ b/pHash-0.7.2/examples/query_mvptree_audio.cpp
@@ -1,3 +1,27 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
 #include <stdio.h>
 #include <dirent.h>
 #include "pHash.h"
diff --git a/pHash-0.7.2/examples/test_audiophash.cpp b/pHash-0.7.2/examples/test_audiophash.cpp
new file mode 100644
index 0000000..f5ac90d
--- /dev/null
+++ b/pHash-0.7.2/examples/test_audiophash.cpp
@@ -0,0 +1,160 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
+#include <stdio.h>
+#include <errno.h>
+#include "pHash.h"
+#include "audiophash.h"
+
+#define TRUE 1
+#define FALSE 0
+
+
+
+int sort_names(char **names, int L1){
+
+    for (int i=0;i<L1;i++){
+	int min = i;
+	for (int j=i+1;j<L1;j++){
+	    if (strcmp(names[j], names[min]) <= 0)
+		min = j;
+	}
+	if (i != min){
+	    char *swap = names[i];
+	    names[i] = names[min];
+	    names[min] = swap;
+	}
+
+    }
+    return 0;
+}
+
+int main(int argc, char **argv){
+
+    if (argc < 3){
+	printf("no args");
+	exit(1);
+    }
+    const char *dir_name  = argv[1];     //first directory
+    const char *dir_name2 = argv[2];     //second directory
+    const float threshold = 0.30;        //ber threshold (0.25-0.35)
+    const int block_size = 256;          //number of frames to compare at a time
+    const int sr = 8000;                 //sample rate to convert the stream
+    const int channels = 1;              //number of channels to convert stream
+
+    int nbfiles1 = 0;
+    char **files1 = ph_readfilenames(dir_name, nbfiles1);
+    sort_names(files1, nbfiles1);
+    int nbfiles2 = 0;
+    char **files2 = ph_readfilenames(dir_name2, nbfiles2);
+    sort_names(files2, nbfiles2);
+
+    printf("dir: %s %d\n", dir_name, nbfiles1);
+    printf("dir: %s %d\n", dir_name2, nbfiles2);
+    if (nbfiles1 != nbfiles2){
+	printf("directories do not have same number of files\n");
+	exit(1);
+    }
+
+    uint32_t **hashes = (uint32_t**)malloc(nbfiles1*sizeof(uint32_t*));
+    int *lens = (int*)malloc(nbfiles1*sizeof(int));
+    float *buf;
+    int buflen;
+    uint32_t *hash1, *hash2;
+    int hashlen1, hashlen2;
+    double *cs;
+    int Nc;
+    int index, i, j;
+    
+    printf("intra distances\n");
+    printf("***************\n");
+    for (index=0;index<nbfiles1;index++){
+	printf("file1: %s\n", files1[index]);
+	buf = ph_readaudio(files1[index], sr, channels, buflen);
+	if (!buf){
+	    printf("unable to read audio\n");
+	    continue;
+	}
+	hash1 = ph_audiohash(buf, buflen, sr, hashlen1);
+	if (!hash1){
+	    printf("unable to get hash\n");
+	    continue;
+	}
+	hashes[index] = hash1;
+	lens[index] = hashlen1;
+	free(buf);
+
+	printf("file2: %s\n", files2[index]);
+	buf = ph_readaudio(files2[index], sr, channels, buflen);
+	if (!buf) {
+	    printf("unable to get audio\n");
+	    continue;
+	}
+        hash2 = ph_audiohash(buf, buflen, sr, hashlen2);
+	if (!hash2) {
+	    printf("unable to get hash\n");
+	    continue;
+	}
+
+	cs = ph_audio_distance_ber(hash1, hashlen1, hash2, hashlen2, threshold, block_size, Nc);
+	if (!cs){
+	    printf("unable to calc distance\n");
+	    continue;
+	}
+
+	double max_cs = 0.0;
+	for (i=0;i<Nc;i++){
+	    if (cs[i] > max_cs){
+		max_cs = cs[i];
+	    }
+	}
+	printf("max cs %f\n\n", max_cs);
+
+	free(hash2);
+	free(buf);
+	free(cs);
+    }
+    
+    printf("pause - hit any key\n\n");
+    getchar();
+    printf("inter dists\n");
+    printf("***********\n");
+    for (i=0;i<nbfiles1;i++){
+	printf("file1: %s\n", files1[i]);
+	for (j=i+1;j<nbfiles1;j++){
+	    printf("    file2: %s\n", files1[j]);
+	    cs=ph_audio_distance_ber(hashes[i],lens[i],hashes[j],lens[j],threshold,block_size,Nc);
+	    double max_f = 0.0;
+	    for (index=0;index<Nc;index++){
+		if (cs[index] > max_f)
+		    max_f = cs[index];
+	    }
+	    printf("    cs = %f\n", max_f);
+	}
+    }
+
+
+
+    return 0;
+}
diff --git a/pHash-0.7.2/examples/test_dctvideohash.cpp b/pHash-0.7.2/examples/test_dctvideohash.cpp
new file mode 100644
index 0000000..76f4ddf
--- /dev/null
+++ b/pHash-0.7.2/examples/test_dctvideohash.cpp
@@ -0,0 +1,89 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
+
+#include "stdio.h"
+#include "pHash.h"
+#include "CImg.h"
+#include "cimgffmpeg.h"
+
+int main(int argc, char **argv){
+    if (argc < 2){
+	printf("not enough input arguments\n");
+	return -1;
+    }
+    const char *file1 = argv[1];
+    const char *file2t = argv[2];
+
+    char *file2 = strdup(file2t);
+
+    if (!file1 || !file2){
+	printf("not enough arguments\n");
+	exit(1);
+    }
+
+    ulong64 *hash1, *hash2;
+    int L1, L2;
+    double sim;
+
+    printf("file1=%s\n", file1);
+    hash1 = ph_dct_videohash(file1, L1);
+    if (!hash1){
+	exit(2);
+    }
+    printf("length %d\n", L1);
+   for (int i=0;i<L1;i++)
+       printf("hash1[%d]=%llx\n", i, hash1[i]);
+
+    do {
+
+	printf("file=%s\n", file2);
+	hash2 = ph_dct_videohash(file2, L2);
+	if (!hash2){
+	    printf("hash 2 is null\n");
+	    free(hash1);
+	    exit(3);
+	}
+
+	printf("length %d\n", L2);
+
+	sim = ph_dct_videohash_dist(hash1, L1, hash2, L2, 21);
+	printf("similarity %f\n", sim);
+
+	free(hash2);
+	hash2 = NULL;
+
+	file2 = fgets(file2, 80, stdin);
+	file2[strlen(file2)-1] = '\0';
+    } while (strcmp(file2,"exit"));
+
+    free(hash1);
+    free(hash2);
+    hash1 = NULL;
+    hash2 = NULL;
+       
+    printf("done\n");
+    return 0;
+}
+ 
diff --git a/examples/test_imagephash.cpp b/pHash-0.7.2/examples/test_imagephash.cpp
similarity index 84%
rename from examples/test_imagephash.cpp
rename to pHash-0.7.2/examples/test_imagephash.cpp
index f49abe6..e274106 100644
--- a/examples/test_imagephash.cpp
+++ b/pHash-0.7.2/examples/test_imagephash.cpp
@@ -1,3 +1,27 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
 #include <stdio.h>
 #include <dirent.h>
 #include <errno.h>
diff --git a/pHash-0.7.2/examples/test_texthash.cpp b/pHash-0.7.2/examples/test_texthash.cpp
new file mode 100644
index 0000000..08d04d3
--- /dev/null
+++ b/pHash-0.7.2/examples/test_texthash.cpp
@@ -0,0 +1,72 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "pHash.h"
+
+int main(int argc, char **argv){
+
+    if (argc < 3){
+	printf("not enough input args\n");
+	exit(1);
+    }
+    const char *file1 = argv[1];
+    const char *file2 = argv[2];
+
+    printf("file1: %s\n", file1);
+    int nbhashes1 = 0;
+    TxtHashPoint *hash1 = ph_texthash(file1,&nbhashes1);
+    if (!hash1){
+	printf("unable to complete text hash function\n");
+	exit(1);
+    }
+    printf("length %d\n", nbhashes1);
+
+    
+    printf("file2: %s\n", file2);
+    int nbhashes2 = 0;
+    TxtHashPoint *hash2 = ph_texthash(file2,&nbhashes2);
+    if (!hash2){
+	printf("unable to complete text hash function\n");
+	exit(2);
+    }
+
+    printf("length %d\n", nbhashes2);
+    int count,j;
+    TxtMatch *matches = ph_compare_text_hashes(hash1, nbhashes1, hash2, nbhashes2, &count);
+    if (!matches){
+	printf("unable to complete compare function\n");
+	exit(3);
+    }
+    
+    printf(" %d matches\n", count);
+    printf(" indxA  indxB  length\n");
+    for (j=0;j<count;j++){
+	printf(" %d %d %d\n", matches[j].first_index, matches[j].second_index,matches[j].length); 
+    }
+
+    return 0;
+}
diff --git a/examples/test_texthash2.cpp b/pHash-0.7.2/examples/test_texthash2.cpp
similarity index 74%
rename from examples/test_texthash2.cpp
rename to pHash-0.7.2/examples/test_texthash2.cpp
index ae35910..047870e 100644
--- a/examples/test_texthash2.cpp
+++ b/pHash-0.7.2/examples/test_texthash2.cpp
@@ -1,3 +1,27 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include "pHash.h"
diff --git a/install-sh b/pHash-0.7.2/install-sh
similarity index 99%
rename from install-sh
rename to pHash-0.7.2/install-sh
index a5897de..6781b98 100755
--- a/install-sh
+++ b/pHash-0.7.2/install-sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # install - install a program, script, or datafile
 
-scriptversion=2006-12-25.00
+scriptversion=2009-04-28.21; # UTC
 
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
@@ -515,5 +515,6 @@ done
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
 # End:
diff --git a/pHash-0.7.2/libpHash.spec b/pHash-0.7.2/libpHash.spec
new file mode 100644
index 0000000..1b6d514
--- /dev/null
+++ b/pHash-0.7.2/libpHash.spec
@@ -0,0 +1,79 @@
+Name:           pHash
+Version:        0.7.1
+Release:        1%{?dist}
+Summary:        pHash, the open source perceptual hashing library
+
+Group:          System Environment/Libraries
+License:        GPLv3
+URL:            http://www.phash.org/
+Source0:        http://www.phash.org/releases/%{name}-%{version}.tar.gz
+BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+BuildRequires:  ffmpeg-devel >= 0.5
+BuildRequires:  libjpeg-devel
+BuildRequires:  libpng-devel
+Requires:	ffmpeg >= 0.5
+Requires:	libjpeg
+Requires:	libpng
+
+%description
+pHash is a perceptual hashing library that allows you to find similar 
+media files without them having to be bit-for-bit identical.
+
+%package        devel
+Summary:        Development files for %{name}
+Group:          Development/Libraries
+Requires:       %{name} = %{version}-%{release}
+
+%description    devel
+The %{name}-devel package contains libraries and header files for
+developing applications that use %{name}.
+
+
+%prep
+%setup -q
+
+
+%build
+%configure --disable-static
+make %{?_smp_mflags}
+
+
+%install
+rm -rf $RPM_BUILD_ROOT
+make install DESTDIR=$RPM_BUILD_ROOT
+find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%defattr(-,root,root,-)
+%doc
+%{_libdir}/*.so.*
+/usr/bin/add_mvptree
+/usr/bin/add_mvptree_audio
+/usr/bin/build_mvptree
+/usr/bin/build_mvptree_audio
+/usr/bin/query_mvptree
+/usr/bin/query_mvptree_audio
+/usr/bin/test_audio
+/usr/bin/test_image
+/usr/bin/test_video
+/usr/lib/pkgconfig/pHash.pc
+
+%files devel
+%defattr(-,root,root,-)
+%doc
+%{_includedir}/*
+%{_libdir}/*.so
+
+
+%changelog
diff --git a/ltmain.sh b/pHash-0.7.2/ltmain.sh
similarity index 100%
rename from ltmain.sh
rename to pHash-0.7.2/ltmain.sh
diff --git a/missing b/pHash-0.7.2/missing
similarity index 94%
rename from missing
rename to pHash-0.7.2/missing
index 1c8ff70..28055d2 100755
--- a/missing
+++ b/pHash-0.7.2/missing
@@ -1,10 +1,10 @@
 #! /bin/sh
 # Common stub for a few missing GNU programs while installing.
 
-scriptversion=2006-05-10.23
+scriptversion=2009-04-28.21; # UTC
 
-# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006
-#   Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
+# 2008, 2009 Free Software Foundation, Inc.
 # Originally by Fran,cois Pinard <pinard at iro.umontreal.ca>, 1996.
 
 # This program is free software; you can redistribute it and/or modify
@@ -18,9 +18,7 @@ scriptversion=2006-05-10.23
 # 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., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -89,6 +87,9 @@ Supported PROGRAM values:
   tar          try tar, gnutar, gtar, then tar without non-portable flags
   yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
 
+Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
+\`g' are ignored when checking the name.
+
 Send bug reports to <bug-automake at gnu.org>."
     exit $?
     ;;
@@ -106,15 +107,22 @@ Send bug reports to <bug-automake at gnu.org>."
 
 esac
 
+# normalize program name to check for.
+program=`echo "$1" | sed '
+  s/^gnu-//; t
+  s/^gnu//; t
+  s/^g//; t'`
+
 # Now exit if we have it, but it failed.  Also exit now if we
 # don't have it and --version was passed (most likely to detect
-# the program).
+# the program).  This is about non-GNU programs, so use $1 not
+# $program.
 case $1 in
-  lex|yacc)
+  lex*|yacc*)
     # Not GNU programs, they don't have --version.
     ;;
 
-  tar)
+  tar*)
     if test -n "$run"; then
        echo 1>&2 "ERROR: \`tar' requires --run"
        exit 1
@@ -138,7 +146,7 @@ esac
 
 # If it does not exist, or fails to run (possibly an outdated version),
 # try to emulate it.
-case $1 in
+case $program in
   aclocal*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
@@ -148,7 +156,7 @@ WARNING: \`$1' is $msg.  You should only need it if
     touch aclocal.m4
     ;;
 
-  autoconf)
+  autoconf*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`${configure_ac}'.  You might want to install the
@@ -157,7 +165,7 @@ WARNING: \`$1' is $msg.  You should only need it if
     touch configure
     ;;
 
-  autoheader)
+  autoheader*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`acconfig.h' or \`${configure_ac}'.  You might want
@@ -187,7 +195,7 @@ WARNING: \`$1' is $msg.  You should only need it if
 	   while read f; do touch "$f"; done
     ;;
 
-  autom4te)
+  autom4te*)
     echo 1>&2 "\
 WARNING: \`$1' is needed, but is $msg.
          You might have modified some files without having the
@@ -210,7 +218,7 @@ WARNING: \`$1' is needed, but is $msg.
     fi
     ;;
 
-  bison|yacc)
+  bison*|yacc*)
     echo 1>&2 "\
 WARNING: \`$1' $msg.  You should only need it if
          you modified a \`.y' file.  You may need the \`Bison' package
@@ -240,7 +248,7 @@ WARNING: \`$1' $msg.  You should only need it if
     fi
     ;;
 
-  lex|flex)
+  lex*|flex*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified a \`.l' file.  You may need the \`Flex' package
@@ -263,7 +271,7 @@ WARNING: \`$1' is $msg.  You should only need it if
     fi
     ;;
 
-  help2man)
+  help2man*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
 	 you modified a dependency of a manual page.  You may need the
@@ -277,11 +285,11 @@ WARNING: \`$1' is $msg.  You should only need it if
     else
 	test -z "$file" || exec >$file
 	echo ".ab help2man is required to generate this page"
-	exit 1
+	exit $?
     fi
     ;;
 
-  makeinfo)
+  makeinfo*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified a \`.texi' or \`.texinfo' file, or any other file
@@ -310,7 +318,7 @@ WARNING: \`$1' is $msg.  You should only need it if
     touch $file
     ;;
 
-  tar)
+  tar*)
     shift
 
     # We have already tried tar in the generic part.
@@ -363,5 +371,6 @@ exit 0
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
 # End:
diff --git a/pHash.pc.in b/pHash-0.7.2/pHash.pc.in
similarity index 100%
rename from pHash.pc.in
rename to pHash-0.7.2/pHash.pc.in
diff --git a/pHash-0.7.2/src/Makefile.am b/pHash-0.7.2/src/Makefile.am
new file mode 100644
index 0000000..2ef5daa
--- /dev/null
+++ b/pHash-0.7.2/src/Makefile.am
@@ -0,0 +1,13 @@
+lib_LTLIBRARIES = libpHash.la
+libpHash_la_SOURCES = pHash.cpp ph_fft.c ph_fft.h
+libpHash_la_LDFLAGS = -no-undefined
+include_HEADERS = pHash.h
+
+if HAVE_AUDIO_HASH
+libpHash_la_SOURCES += audiophash.cpp
+include_HEADERS += audiophash.h
+endif
+
+if HAVE_VIDEO_HASH
+libpHash_la_SOURCES += cimgffmpeg.cpp cimgffmpeg.h
+endif
diff --git a/src/Makefile.in b/pHash-0.7.2/src/Makefile.in
similarity index 90%
rename from src/Makefile.in
rename to pHash-0.7.2/src/Makefile.in
index 19fd410..4adbcb6 100644
--- a/src/Makefile.in
+++ b/pHash-0.7.2/src/Makefile.in
@@ -35,9 +35,11 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
- at HAVE_AUDIO_HASH_TRUE@am__append_1 = audiophash.cpp audiophash.h
+ at HAVE_AUDIO_HASH_TRUE@am__append_1 = audiophash.cpp
+ at HAVE_AUDIO_HASH_TRUE@am__append_2 = audiophash.h
+ at HAVE_VIDEO_HASH_TRUE@am__append_3 = cimgffmpeg.cpp cimgffmpeg.h
 subdir = src
-DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
+DIST_COMMON = $(am__include_HEADERS_DIST) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -71,9 +73,12 @@ am__base_list = \
 am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
 libpHash_la_LIBADD =
-am__libpHash_la_SOURCES_DIST = pHash.cpp audiophash.cpp audiophash.h
+am__libpHash_la_SOURCES_DIST = pHash.cpp ph_fft.c ph_fft.h \
+	audiophash.cpp cimgffmpeg.cpp cimgffmpeg.h
 @HAVE_AUDIO_HASH_TRUE at am__objects_1 = audiophash.lo
-am_libpHash_la_OBJECTS = pHash.lo $(am__objects_1)
+ at HAVE_VIDEO_HASH_TRUE@am__objects_2 = cimgffmpeg.lo
+am_libpHash_la_OBJECTS = pHash.lo ph_fft.lo $(am__objects_1) \
+	$(am__objects_2)
 libpHash_la_OBJECTS = $(am_libpHash_la_OBJECTS)
 libpHash_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
 	$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
@@ -82,15 +87,6 @@ DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
 depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
-CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
-	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
-LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
-	--mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
-	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
-CXXLD = $(CXX)
-CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
-	--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
-	$(LDFLAGS) -o $@
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
@@ -100,8 +96,18 @@ CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
 	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
 	$(LDFLAGS) -o $@
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
 SOURCES = $(libpHash_la_SOURCES)
 DIST_SOURCES = $(am__libpHash_la_SOURCES_DIST)
+am__include_HEADERS_DIST = pHash.h audiophash.h
 HEADERS = $(include_HEADERS)
 ETAGS = etags
 CTAGS = ctags
@@ -226,13 +232,14 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 lib_LTLIBRARIES = libpHash.la
-libpHash_la_SOURCES = pHash.cpp $(am__append_1)
+libpHash_la_SOURCES = pHash.cpp ph_fft.c ph_fft.h $(am__append_1) \
+	$(am__append_3)
 libpHash_la_LDFLAGS = -no-undefined
-include_HEADERS = pHash.h cimgffmpeg.h audiophash.h
+include_HEADERS = pHash.h $(am__append_2)
 all: all-am
 
 .SUFFIXES:
-.SUFFIXES: .cpp .lo .o .obj
+.SUFFIXES: .c .cpp .lo .o .obj
 $(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
 	@for dep in $?; do \
 	  case '$(am__configure_deps)' in \
@@ -304,7 +311,30 @@ distclean-compile:
 	-rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/audiophash.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cimgffmpeg.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pHash.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ph_fft.Plo at am__quote@
+
+.c.o:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ at am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
 
 .cpp.o:
 @am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/audiophash.cpp b/pHash-0.7.2/src/audiophash.cpp
similarity index 95%
rename from src/audiophash.cpp
rename to pHash-0.7.2/src/audiophash.cpp
index 693d370..369bdfb 100644
--- a/src/audiophash.cpp
+++ b/pHash-0.7.2/src/audiophash.cpp
@@ -236,10 +236,11 @@ uint32_t* ph_audiohash(float *buf, int N, int sr, int &nb_frames){
    }
    
    double frame[frame_length];
-   fftw_complex *pF;
-   fftw_plan p;
+   //fftw_complex *pF;
+   //fftw_plan p;
+   //pF = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*nfft);
+   complex double *pF = (complex double*)malloc(sizeof(complex double)*nfft);
 
-   pF = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*nfft);
    double magnF[nfft_half];
    double maxF = 0.0;
    double maxB = 0.0;
@@ -292,7 +293,7 @@ uint32_t* ph_audiohash(float *buf, int N, int sr, int &nb_frames){
        }
    }
 
-   p = fftw_plan_dft_r2c_1d(frame_length,frame,pF,FFTW_ESTIMATE);
+   //p = fftw_plan_dft_r2c_1d(frame_length,frame,pF,FFTW_ESTIMATE);
 
    while (end <= N){
        maxF = 0.0;
@@ -300,11 +301,16 @@ uint32_t* ph_audiohash(float *buf, int N, int sr, int &nb_frames){
        for (int i = 0;i<frame_length;i++){
 	   frame[i] = window[i]*buf[start+i];
        }
-       fftw_execute(p);
+       //fftw_execute(p);
+       if (fft(frame, frame_length, pF) < 0){
+	   return NULL;
+       }
        for (int i=0; i < nfft_half;i++){
-	   magnF[i] = sqrt(pF[i][0]*pF[i][0] +  pF[i][1]*pF[i][1] );
-	   if (magnF[i] > maxF)
+	   //magnF[i] = sqrt(pF[i][0]*pF[i][0] +  pF[i][1]*pF[i][1] );
+           magnF[i] = cabs(pF[i]);
+	   if (magnF[i] > maxF){
 	       maxF = magnF[i];
+	   }
        }
 
        for (int i=0;i<nfilts;i++){
@@ -336,8 +342,9 @@ uint32_t* ph_audiohash(float *buf, int N, int sr, int &nb_frames){
    
 
 
-   fftw_destroy_plan(p);
-   fftw_free(pF);
+   //fftw_destroy_plan(p);
+   //fftw_free(pF);
+   free(pF);
    for (int i=0;i<nfilts;i++){
        delete [] wts[i];
    }
diff --git a/src/audiophash.h b/pHash-0.7.2/src/audiophash.h
similarity index 99%
rename from src/audiophash.h
rename to pHash-0.7.2/src/audiophash.h
index d65ab95..2b41656 100644
--- a/src/audiophash.h
+++ b/pHash-0.7.2/src/audiophash.h
@@ -27,7 +27,6 @@
 
 #include <limits.h>
 #include <math.h>
-#include <fftw3.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <algorithm>
@@ -36,6 +35,7 @@ extern "C" {
 	#include "libavformat/avformat.h"
 	#include "libavcodec/avcodec.h"
 	#include "libswscale/swscale.h"
+        #include "ph_fft.h"
 }
 
 /*  /brief count number of samples in file
diff --git a/pHash-0.7.2/src/cimgffmpeg.cpp b/pHash-0.7.2/src/cimgffmpeg.cpp
new file mode 100644
index 0000000..cee72a8
--- /dev/null
+++ b/pHash-0.7.2/src/cimgffmpeg.cpp
@@ -0,0 +1,427 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
+
+#include "cimgffmpeg.h"
+
+void vfinfo_close(VFInfo  *vfinfo){
+    if (vfinfo->pFormatCtx != NULL){
+	avcodec_close(vfinfo->pCodecCtx);
+	vfinfo->pCodecCtx = NULL;
+	av_close_input_file(vfinfo->pFormatCtx);
+	vfinfo->pFormatCtx = NULL;
+	vfinfo->width = -1;
+	vfinfo->height = -1;
+    }
+}
+
+int ReadFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList, unsigned int low_index, unsigned int hi_index)
+{
+        //target pixel format
+	PixelFormat ffmpeg_pixfmt;
+	if (st_info->pixelformat == 0)
+	    ffmpeg_pixfmt = PIX_FMT_GRAY8;
+	else 
+	    ffmpeg_pixfmt = PIX_FMT_RGB24;
+
+	st_info->next_index = low_index;
+
+	if (st_info->pFormatCtx == NULL){
+	    st_info->current_index= 0;
+
+        av_log_set_level(AV_LOG_QUIET);
+	    av_register_all();
+	
+	    // Open video file
+	    if(av_open_input_file(&st_info->pFormatCtx, st_info->filename, NULL, 0, NULL)!=0)
+		return -1 ; // Couldn't open file
+	 
+	    // Retrieve stream information
+	    if(av_find_stream_info(st_info->pFormatCtx)<0)
+		return -1; // Couldn't find stream information
+	
+	    //dump_format(pFormatCtx,0,NULL,0);//debugging function to print infomation about format
+	
+	    unsigned int i;
+	    // Find the video stream
+	    for(i=0; i<st_info->pFormatCtx->nb_streams; i++)
+	    {
+		if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
+	        {
+		    st_info->videoStream=i;
+		    break;
+		}
+	    }
+	    if(st_info->videoStream==-1)
+		return -1; //no video stream
+	
+	
+	    // Get a pointer to the codec context for the video stream
+	    st_info->pCodecCtx = st_info->pFormatCtx->streams[st_info->videoStream]->codec;
+	    if (st_info->pCodecCtx == NULL){
+		return -1;
+	    }
+
+	    // Find the decoder
+	    st_info->pCodec = avcodec_find_decoder(st_info->pCodecCtx->codec_id);
+	    if(st_info->pCodec==NULL) 
+	    {
+	  	return -1 ; // Codec not found
+	    }
+	    // Open codec
+	    if(avcodec_open(st_info->pCodecCtx, st_info->pCodec)<0)
+		return -1; // Could not open codec
+
+	    st_info->height = (st_info->height<=0) ? st_info->pCodecCtx->height : st_info->height;
+	    st_info->width  = (st_info->width<= 0) ? st_info->pCodecCtx->width : st_info->width;
+	}
+
+        AVFrame *pFrame;
+
+	// Allocate video frame
+	pFrame=avcodec_alloc_frame();
+	if (pFrame==NULL)
+	    return -1;
+
+	// Allocate an AVFrame structure
+	AVFrame *pConvertedFrame = avcodec_alloc_frame();
+	if(pConvertedFrame==NULL)
+	  return -1;
+		
+	uint8_t *buffer;
+	int numBytes;
+	// Determine required buffer size and allocate buffer
+	numBytes=avpicture_get_size(ffmpeg_pixfmt, st_info->width,st_info->height);
+	buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
+	if (buffer == NULL)
+	    return -1;
+
+	avpicture_fill((AVPicture *)pConvertedFrame,buffer,ffmpeg_pixfmt,st_info->width,st_info->height);
+		
+	int frameFinished;
+	int size = 0;
+	
+	AVPacket packet;
+	int result = 1;
+	CImg<uint8_t> next_image;
+	SwsContext *c = sws_getContext(st_info->pCodecCtx->width, st_info->pCodecCtx->height, st_info->pCodecCtx->pix_fmt, st_info->width, st_info->height, ffmpeg_pixfmt , SWS_BICUBIC, NULL, NULL, NULL);
+	while ((result>=0)&&(size<st_info->nb_retrieval)&&(st_info->current_index<=hi_index)){  
+	  result =  av_read_frame(st_info->pFormatCtx, &packet);
+          if (result < 0)
+	      break;
+    	  if(packet.stream_index==st_info->videoStream) {
+	      avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
+	      if(frameFinished) {
+		  if (st_info->current_index == st_info->next_index){
+		      st_info->next_index += st_info->step;
+		      sws_scale(c, pFrame->data, pFrame->linesize, 0, st_info->pCodecCtx->height, pConvertedFrame->data, pConvertedFrame->linesize);
+			
+                      if (ffmpeg_pixfmt == PIX_FMT_GRAY8) {
+			  next_image.assign(pConvertedFrame->data[0],1,st_info->width,st_info->height,1,true);
+			  next_image.permute_axes("yzcx");
+			  pFrameList->push_back(next_image);
+			  size++;
+		      }
+		      else if (ffmpeg_pixfmt == PIX_FMT_RGB24){
+			  next_image.assign(*pConvertedFrame->data,3,st_info->width,st_info->height,1,true);
+			  next_image.permute_axes("yzcx");
+			  pFrameList->push_back(next_image);
+			  size++;
+		      }
+		  }    
+		  st_info->current_index++;
+	      }
+	      av_free_packet(&packet);
+	  }
+	}
+
+
+	if (result < 0){
+	    avcodec_close(st_info->pCodecCtx);
+	    av_close_input_file(st_info->pFormatCtx);
+	    st_info->pFormatCtx = NULL;
+	    st_info->pCodecCtx = NULL;
+	    st_info->width = -1;
+	    st_info->height = -1;
+	}
+
+	av_free(buffer);
+	buffer = NULL;
+	av_free(pConvertedFrame);
+	pConvertedFrame = NULL;
+	av_free(pFrame);
+	pFrame = NULL;
+	sws_freeContext(c);
+	c = NULL;
+
+	return size; 
+}
+
+
+int NextFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList)
+{
+        PixelFormat ffmpeg_pixfmt;
+	if (st_info->pixelformat == 0)
+	    ffmpeg_pixfmt = PIX_FMT_GRAY8;
+        else 
+	    ffmpeg_pixfmt = PIX_FMT_RGB24;
+
+	if (st_info->pFormatCtx == NULL)
+	{
+	        st_info->current_index = 0;
+		st_info->next_index = 0;
+		av_register_all();
+		st_info->videoStream = -1;
+		//st_info->pFormatCtx = (AVFormatContext*)malloc(sizeof(AVFormatContext));
+		//st_info->pCodecCtx = (AVCodecContext*)malloc(sizeof(AVCodecContext));
+		//st_info->pCodec = (AVCodec*)malloc(sizeof(AVCodec));
+
+		av_log_set_level(AV_LOG_QUIET);
+		// Open video file
+ 		if(av_open_input_file(&(st_info->pFormatCtx),st_info->filename,NULL,0,NULL)!=0){
+			return -1 ; // Couldn't open file
+		}
+	 
+		// Retrieve stream information
+		if(av_find_stream_info(st_info->pFormatCtx)<0){
+			return -1; // Couldn't find stream information
+		}
+
+		unsigned int i;
+
+		// Find the video stream
+		for(i=0; i< st_info->pFormatCtx->nb_streams; i++)
+		{
+			if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
+			{
+				st_info->videoStream=i;
+				break;
+			}
+		}
+
+		if(st_info->videoStream==-1){
+		    return -1; //no video stream
+		}
+	
+		// Get a pointer to the codec context for the video stream
+		st_info->pCodecCtx = st_info->pFormatCtx->streams[st_info->videoStream]->codec;
+
+		// Find the decoder
+		st_info->pCodec = avcodec_find_decoder(st_info->pCodecCtx->codec_id);
+		if(st_info->pCodec==NULL) 
+		{
+			return -1 ; // Codec not found
+		}
+		// Open codec
+		if(avcodec_open(st_info->pCodecCtx, st_info->pCodec)<0){
+		    return -1; // Could not open codec
+		}
+		
+		st_info->width = (st_info->width<=0) ? st_info->pCodecCtx->width : st_info->width;
+		st_info->height = (st_info->height<=0) ? st_info->pCodecCtx->height : st_info->height;
+		
+	} 
+
+	AVFrame *pFrame;
+
+	// Allocate video frame
+	pFrame=avcodec_alloc_frame();
+		
+	// Allocate an AVFrame structure
+	AVFrame *pConvertedFrame = avcodec_alloc_frame();
+	if(pConvertedFrame==NULL){
+	  return -1;
+	}
+		
+	uint8_t *buffer;
+	int numBytes;
+	// Determine required buffer size and allocate buffer
+	numBytes=avpicture_get_size(ffmpeg_pixfmt, st_info->width,st_info->height);
+	buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
+	if (buffer == NULL){
+	    return -1;
+	}
+
+	avpicture_fill((AVPicture *)pConvertedFrame,buffer,ffmpeg_pixfmt,st_info->width,st_info->height);
+		
+	int frameFinished;
+	int size = 0;
+	AVPacket packet;
+	int result = 1;
+	CImg<uint8_t> next_image;
+	SwsContext *c = sws_getContext(st_info->pCodecCtx->width, st_info->pCodecCtx->height, st_info->pCodecCtx->pix_fmt, st_info->width, st_info->height, ffmpeg_pixfmt , SWS_BICUBIC, NULL, NULL, NULL);
+	while ((result >= 0) && (size < st_info->nb_retrieval))
+	{
+
+		result = av_read_frame(st_info->pFormatCtx, &packet); 
+		if (result < 0) 
+			break;
+		if(packet.stream_index == st_info->videoStream) {
+			
+		    avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,
+		                         packet.data,packet.size);
+ 
+		    if(frameFinished) {
+		    	if (st_info->current_index == st_info->next_index)
+		    	{
+			    st_info->next_index += st_info->step;
+			   
+			    sws_scale(c, pFrame->data, pFrame->linesize, 0, st_info->pCodecCtx->height, pConvertedFrame->data, pConvertedFrame->linesize);
+				   	
+			    if (ffmpeg_pixfmt == PIX_FMT_RGB24){   
+				next_image.assign(*pConvertedFrame->data,3,st_info->width,st_info->height,1,true);
+				next_image.permute_axes("yzcx");
+				pFrameList->push_back(next_image);
+				size++;
+			    }
+			    else if (ffmpeg_pixfmt == PIX_FMT_GRAY8){
+				next_image.assign(pConvertedFrame->data[0],1,st_info->width,st_info->height,1,true);
+				next_image.permute_axes("yzcx");
+				pFrameList->push_back(next_image);
+				size++;
+			    }
+				   	 
+		    	}    
+				st_info->current_index++;
+		    }
+    	  }
+    	        av_free_packet(&packet);
+	}
+	
+	av_free(buffer);
+	buffer = NULL;
+	av_free(pConvertedFrame);
+	pConvertedFrame = NULL;
+	av_free(pFrame);
+	pFrame = NULL;
+	sws_freeContext(c);
+	c = NULL;
+	if (result < 0)
+	{
+		avcodec_close(st_info->pCodecCtx);
+		av_close_input_file(st_info->pFormatCtx);
+		st_info->pCodecCtx = NULL;
+		st_info->pFormatCtx = NULL;
+		st_info->pCodec = NULL;
+		st_info->width = -1;
+		st_info->height = -1;
+	}
+	return size; 
+}
+
+int GetNumberStreams(const char *file)
+{
+	 AVFormatContext *pFormatCtx;
+	 av_log_set_level(AV_LOG_QUIET);
+	 av_register_all();
+	// Open video file
+	if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
+	  return -1 ; // Couldn't open file
+		 
+	// Retrieve stream information
+	if(av_find_stream_info(pFormatCtx)<0)
+	  return -1; // Couldn't find stream information
+	int result = pFormatCtx->nb_streams;
+	av_close_input_file(pFormatCtx);
+	return result;
+}
+
+long GetNumberVideoFrames(const char *file)
+{
+    long nb_frames = 0L;
+	AVFormatContext *pFormatCtx;
+    av_log_set_level(AV_LOG_QUIET);
+	av_register_all();
+	// Open video file
+	if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
+	  return -1 ; // Couldn't open file
+			 
+	// Retrieve stream information
+	if(av_find_stream_info(pFormatCtx)<0)
+	  return -1; // Couldn't find stream information
+		
+	// Find the first video stream
+	int videoStream=-1;
+	for(unsigned int i=0; i<pFormatCtx->nb_streams; i++)
+	{
+	     if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
+	     {
+		    videoStream=i;
+		    break;
+             }
+	}
+	if(videoStream==-1)
+	   return -1; // Didn't find a video stream
+	AVStream *str = pFormatCtx->streams[videoStream];
+		
+        nb_frames = str->nb_frames;
+	if (nb_frames > 0)
+	{   //the easy way if value is already contained in struct 
+	    av_close_input_file(pFormatCtx);
+	    return nb_frames;
+	}
+	else { // frames must be counted
+	        AVPacket packet;
+		nb_frames = (long)av_index_search_timestamp(str,str->duration, AVSEEK_FLAG_ANY|AVSEEK_FLAG_BACKWARD);
+		// Close the video file
+		av_close_input_file(pFormatCtx); 
+		return nb_frames;
+	}
+}
+
+float fps(const char *filename)
+{
+        float result = 0;
+	AVFormatContext *pFormatCtx;
+	
+	// Open video file
+	if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL))
+	  return -1 ; // Couldn't open file
+				 
+	// Retrieve stream information
+	if(av_find_stream_info(pFormatCtx)<0)
+	  return -1; // Couldn't find stream information
+			
+	// Find the first video stream
+	int videoStream=-1;
+	for(unsigned int i=0; i<pFormatCtx->nb_streams; i++)
+	{
+		     if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
+		     {
+			    videoStream=i;
+			    break;
+		     }
+	}
+        if(videoStream==-1)
+	    return -1; // Didn't find a video stream
+	
+	int num = (pFormatCtx->streams[videoStream]->r_frame_rate).num;
+	int den = (pFormatCtx->streams[videoStream]->r_frame_rate).den;
+	result = num/den;
+
+	av_close_input_file(pFormatCtx);
+	
+	return result;
+
+}
diff --git a/pHash-0.7.2/src/cimgffmpeg.h b/pHash-0.7.2/src/cimgffmpeg.h
new file mode 100755
index 0000000..8bea87b
--- /dev/null
+++ b/pHash-0.7.2/src/cimgffmpeg.h
@@ -0,0 +1,72 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
+
+
+#ifndef CIMGFFMPEG_H_
+#define CIMGFFMPEG_H_
+
+#define cimg_display 0
+#define cimg_debug 0
+
+#include "CImg.h"
+
+extern "C" {
+	#include "libavformat/avformat.h"
+	#include "libavcodec/avcodec.h"
+	#include "libswscale/swscale.h"
+}
+
+using namespace cimg_library;
+
+typedef struct vf_info {
+    int step;
+    int nb_retrieval;
+    int pixelformat;
+    int videoStream;
+    int width, height;
+    long current_index;
+    long next_index;
+    AVFormatContext *pFormatCtx;
+    AVCodecContext *pCodecCtx;
+    AVCodec *pCodec;
+    const char *filename;
+} VFInfo;
+
+void vfinfo_close(VFInfo  *vfinfo);
+
+int ReadFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList, unsigned int low_index, unsigned int hi_index);
+
+
+int NextFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList);
+
+
+int GetNumberStreams(const char *file);
+
+
+long GetNumberVideoFrames(const char *file);
+
+float fps(const char *filename);
+
+#endif /*CIMGFFMPEG_H_*/
diff --git a/src/pHash.cpp b/pHash-0.7.2/src/pHash.cpp
similarity index 99%
rename from src/pHash.cpp
rename to pHash-0.7.2/src/pHash.cpp
index 80651e4..23211ff 100644
--- a/src/pHash.cpp
+++ b/pHash-0.7.2/src/pHash.cpp
@@ -1221,7 +1221,7 @@ MVPRetCode ph_query_mvptree(MVPFile *m, DP *query, int knearest, float radius,
     m->buf = (char*)mremap(m->buf,m->pgsize,int_pgsize,MREMAP_MAYMOVE);
 #else
     munmap(m->buf, m->pgsize);
-    m->buf = (char*)mmap(m->buf,m->int_pgsize, PROT_READ|PROT_WRITE, MAP_SHARED, m->fd, 0);
+    m->buf = (char*)mmap(m->buf,int_pgsize, PROT_READ|PROT_WRITE, MAP_SHARED, m->fd, 0);
 #endif
 
     if (m->buf == MAP_FAILED){
@@ -2323,3 +2323,34 @@ TxtMatch* ph_compare_text_hashes(TxtHashPoint *hash1, int N1, TxtHashPoint *hash
     }
     return found_matches;
 }
+
+static bool keepStats = false;
+struct ph_stats
+{
+	ulong64 reads;
+	ulong64 avg_atime, height;
+	
+};
+enum ph_option
+{
+	PH_STATS
+};
+
+const ph_stats ph_get_stats(MVPFile *m)
+{
+	if(keepStats)
+	{
+	
+	}
+}
+void ph_set_option(ph_option opt, int val)
+{
+	switch(opt)
+	{
+		case PH_STATS:
+			keepStats = (bool)val;
+			break;
+		default:
+			break;
+	}
+}
diff --git a/src/pHash.h b/pHash-0.7.2/src/pHash.h
similarity index 100%
rename from src/pHash.h
rename to pHash-0.7.2/src/pHash.h
diff --git a/pHash-0.7.2/src/ph_fft.c b/pHash-0.7.2/src/ph_fft.c
new file mode 100644
index 0000000..ef9b0da
--- /dev/null
+++ b/pHash-0.7.2/src/ph_fft.c
@@ -0,0 +1,74 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
+
+
+#include "ph_fft.h"
+
+complex double polar_to_complex(const double r, const double theta)
+{
+    complex double result;
+    result = r*cos(theta) + r*sin(theta)*I;
+
+    return result;
+}
+
+void fft_calc(const int N,const double *x,complex double *X,complex double *P,const int step,const complex double *twids)
+{
+    complex double *S = P + N/2;
+    if (N == 1){
+	X[0] = x[0];
+	return;
+    }
+    
+    fft_calc(N/2, x,      S,   X,2*step, twids);
+    fft_calc(N/2, x+step, P,   X,2*step, twids);	    
+
+    int k;
+    for (k=0;k<N/2;k++){
+	P[k] = P[k]*twids[k*step];
+	X[k]     = S[k] + P[k];
+	X[k+N/2] = S[k] - P[k];
+    }
+
+}
+
+
+int fft(double *x, int N, complex double *X)
+{
+
+    complex double *twiddle_factors = (complex double*)malloc(sizeof(complex double)*(N/2));
+    complex double *Xt = (complex double*)malloc(sizeof(complex double)*N);
+    int k;
+    for (k=0;k<N/2;k++){
+	twiddle_factors[k] = polar_to_complex(1.0, 2.0*PI*k/N);
+    }
+    fft_calc(N, x, X, Xt, 1, twiddle_factors);
+
+    free(twiddle_factors);
+    free(Xt);
+
+    return 0;
+
+}
diff --git a/pHash-0.7.2/src/ph_fft.h b/pHash-0.7.2/src/ph_fft.h
new file mode 100644
index 0000000..9b6ffc1
--- /dev/null
+++ b/pHash-0.7.2/src/ph_fft.h
@@ -0,0 +1,37 @@
+/*
+
+    pHash, the open source perceptual hash library
+    Copyright (C) 2009 Aetilius, Inc.
+    All rights reserved.
+
+    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 3 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, see <http://www.gnu.org/licenses/>.
+
+    Evan Klinger - eklinger at phash.org
+    David Starkweather - dstarkweather at phash.org
+
+*/
+
+
+#ifndef _FFT_H
+#define _FFT_H
+
+#define PI 3.1415926535897932
+
+#include <math.h>
+#include "complex.h"
+#include <stdlib.h>
+
+int fft(double *x, int N, complex double *X);
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
deleted file mode 100644
index 8cd6c3c..0000000
--- a/src/Makefile.am
+++ /dev/null
@@ -1,9 +0,0 @@
-lib_LTLIBRARIES = libpHash.la
-libpHash_la_SOURCES = pHash.cpp
-libpHash_la_LDFLAGS = -no-undefined
-include_HEADERS = pHash.h cimgffmpeg.h audiophash.h
-
-if HAVE_AUDIO_HASH
-libpHash_la_SOURCES += audiophash.cpp audiophash.h
-endif
-
diff --git a/src/cimgffmpeg.h b/src/cimgffmpeg.h
deleted file mode 100755
index 25c4e50..0000000
--- a/src/cimgffmpeg.h
+++ /dev/null
@@ -1,842 +0,0 @@
-/*
-#	File: cimgffmpeg.h
-#	
-#	Description: plugin allowing convenient access to
-#                 the frames of a video file through the
-#                 CImg and CImgList classes; uses the ffmpeg
-#                 function library.
-#	Copyright: David G. Starkweather
-#              starkdg at users.sourceforge.net
-#              starkdg at comcast.net
-#	License:
-#   
-#   Instructions:  This header depends on the ffmpeg libraries v13263
-#
-#		1.) obtain ffmpeg from svn (svn://svn.mplayerhq.hu/ffmpeg/trunk)
-#
-# 		2.) configure with the following options
-#            ./configure --prefix=/usr/local --enable-shared --enable-swscale 
-#                         --enable-avfilter --enable-pthreads --enable-gpl 
-#                         --disable-ffmpeg --disable-ffserver --disable-ffplay
-#           (I disable the ffmpeg, ffserver and ffplay utilities only because they
-             are not needed by this header.)
-#		3.) make
-#  		4.) make install
-#
-#       Simply include this header in your code and link to the necessary libs.
-#       You will probably have to edit the #include "cimgffmpeg.h" directives to
-#       point to the correct directory level.
-#
-#       For your project that uses this header:
-#
-#       A command line invocation of the compiler might look something like this:
-#
-#		g++ -Dcimg_use_xshm -Dcimg_use_xrandr -Ucimg_use_xrandr -Ucimg_use_xshm -I/usr/include/X11 
-#            -O2 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/ffmpegplugindemo.d" -MT"src/ffmpegplugindemo.d" -o"src/ffmpegplugindemo.o" "../src/ffmpegplugindemo.cpp"
-#
-#		And the linker:
-#
-#       g++ -L/usr/local/lib -L/usr/X11R6/lib64 -o{nameofyourproject}" ./src/{yourproject}.o
-#             -lavutil -lavformat -lavcodec -lavutil -lswscale -lm -ldl -X11 -lXext -lXrandr 
-#             -lpthread
-#
-#		set LD_LIBRARY_PATH environment variable to point to the lib location (e.g. /usr/local/lib)
-*/
-
-#ifndef CIMGFFMPEG_H_
-#define CIMGFFMPEG_H_
-
-#include "pthread.h"
-#include "string.h"
-#include "CImg.h"
-
-extern "C" {
-	#include "libavformat/avformat.h"
-	#include "libavcodec/avcodec.h"
-	#include "libswscale/swscale.h"
-}
-/*
-   struct to hold video information to be passed to PlayVideo thread
-*/
-struct video_info_t {
-	int fps;
-	void *pList;
-};
-
-using namespace cimg_library;
-
-
-typedef struct vf_info {
-    int step;
-    int nb_retrieval;
-    int pixelformat;
-    int videoStream;
-    int width, height;
-    long current_index;
-    long next_index;
-    AVFormatContext *pFormatCtx;
-    AVCodecContext *pCodecCtx;
-    AVCodec *pCodec;
-    const char *filename;
-} VFInfo;
-
-void vfinfo_close(VFInfo  *vfinfo){
-    if (vfinfo->pFormatCtx != NULL){
-	avcodec_close(vfinfo->pCodecCtx);
-	vfinfo->pCodecCtx = NULL;
-	av_close_input_file(vfinfo->pFormatCtx);
-	vfinfo->pFormatCtx = NULL;
-	vfinfo->width = -1;
-	vfinfo->height = -1;
-    }
-}
-
-//! Read frames from the given file into the CImgList parameter
-/*  
- *  Reads nb_retrieval frames from the video stream from low_index to hi_index in step number of intervals.
- *  The value of pixelformat parameter determines the frame type. The pixel format value is translated into
- *  ffmpeg library's corresponding PIX_FMT enumeration.
- * 
- *  @param filename const char* - complete filename
- *  @param pFrameList CImgList<>* - an empty CImgList
- *  @param lo_index   int - the start index frame
- *  @param hi_index   int - the end index frame
- *  @param step       int - the interval 
- *  @param nb_retrieval int - maximum number of frames to retrieve
- *  @param pixelformat int - pixel format ( =0 for GRAY8 (8bpp grayscale) and =1 for RGB24 (24 bpp RGB)  )
- *  @return int  -  the number of frames read; -1 for unable to read frames; 0 for no frames.
-*/
-int ReadFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList, unsigned int low_index, unsigned int hi_index)
-{
-        //target pixel format
-	PixelFormat ffmpeg_pixfmt;
-	if (st_info->pixelformat == 0)
-	    ffmpeg_pixfmt = PIX_FMT_GRAY8;
-	else 
-	    ffmpeg_pixfmt = PIX_FMT_RGB24;
-
-	st_info->next_index = low_index;
-
-	if (st_info->pFormatCtx == NULL){
-	    st_info->current_index= 0;
-
-        av_log_set_level(AV_LOG_QUIET);
-	    av_register_all();
-	
-	    // Open video file
-	    if(av_open_input_file(&st_info->pFormatCtx, st_info->filename, NULL, 0, NULL)!=0)
-		return -1 ; // Couldn't open file
-	 
-	    // Retrieve stream information
-	    if(av_find_stream_info(st_info->pFormatCtx)<0)
-		return -1; // Couldn't find stream information
-	
-	    //dump_format(pFormatCtx,0,NULL,0);//debugging function to print infomation about format
-	
-	    unsigned int i;
-	    // Find the video stream
-	    for(i=0; i<st_info->pFormatCtx->nb_streams; i++)
-	    {
-		if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
-	        {
-		    st_info->videoStream=i;
-		    break;
-		}
-	    }
-	    if(st_info->videoStream==-1)
-		return -1; //no video stream
-	
-	
-	    // Get a pointer to the codec context for the video stream
-	    st_info->pCodecCtx = st_info->pFormatCtx->streams[st_info->videoStream]->codec;
-	    if (st_info->pCodecCtx == NULL){
-		return -1;
-	    }
-
-	    // Find the decoder
-	    st_info->pCodec = avcodec_find_decoder(st_info->pCodecCtx->codec_id);
-	    if(st_info->pCodec==NULL) 
-	    {
-	  	return -1 ; // Codec not found
-	    }
-	    // Open codec
-	    if(avcodec_open(st_info->pCodecCtx, st_info->pCodec)<0)
-		return -1; // Could not open codec
-
-	    st_info->height = (st_info->height<=0) ? st_info->pCodecCtx->height : st_info->height;
-	    st_info->width  = (st_info->width<= 0) ? st_info->pCodecCtx->width : st_info->width;
-	}
-
-        AVFrame *pFrame;
-
-	// Allocate video frame
-	pFrame=avcodec_alloc_frame();
-	if (pFrame==NULL)
-	    return -1;
-
-	// Allocate an AVFrame structure
-	AVFrame *pConvertedFrame = avcodec_alloc_frame();
-	if(pConvertedFrame==NULL)
-	  return -1;
-		
-	uint8_t *buffer;
-	int numBytes;
-	// Determine required buffer size and allocate buffer
-	numBytes=avpicture_get_size(ffmpeg_pixfmt, st_info->width,st_info->height);
-	buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
-	if (buffer == NULL)
-	    return -1;
-
-	avpicture_fill((AVPicture *)pConvertedFrame,buffer,ffmpeg_pixfmt,st_info->width,st_info->height);
-		
-	int frameFinished;
-	int size = 0;
-	
-	AVPacket packet;
-	int result = 1;
-	CImg<uint8_t> next_image;
-	SwsContext *c = sws_getContext(st_info->pCodecCtx->width, st_info->pCodecCtx->height, st_info->pCodecCtx->pix_fmt, st_info->width, st_info->height, ffmpeg_pixfmt , SWS_BICUBIC, NULL, NULL, NULL);
-	while ((result>=0)&&(size<st_info->nb_retrieval)&&(st_info->current_index<=hi_index)){  
-	  result =  av_read_frame(st_info->pFormatCtx, &packet);
-          if (result < 0)
-	      break;
-    	  if(packet.stream_index==st_info->videoStream) {
-	      avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
-	      if(frameFinished) {
-		  if (st_info->current_index == st_info->next_index){
-		      st_info->next_index += st_info->step;
-		      sws_scale(c, pFrame->data, pFrame->linesize, 0, st_info->pCodecCtx->height, pConvertedFrame->data, pConvertedFrame->linesize);
-			
-                      if (ffmpeg_pixfmt == PIX_FMT_GRAY8) {
-			  next_image.assign(pConvertedFrame->data[0],1,st_info->width,st_info->height,1,true);
-			  next_image.permute_axes("yzcx");
-			  pFrameList->push_back(next_image);
-			  size++;
-		      }
-		      else if (ffmpeg_pixfmt == PIX_FMT_RGB24){
-			  next_image.assign(*pConvertedFrame->data,3,st_info->width,st_info->height,1,true);
-			  next_image.permute_axes("yzcx");
-			  pFrameList->push_back(next_image);
-			  size++;
-		      }
-		  }    
-		  st_info->current_index++;
-	      }
-	      av_free_packet(&packet);
-	  }
-	}
-
-
-	if (result < 0){
-	    avcodec_close(st_info->pCodecCtx);
-	    av_close_input_file(st_info->pFormatCtx);
-	    st_info->pFormatCtx = NULL;
-	    st_info->pCodecCtx = NULL;
-	    st_info->width = -1;
-	    st_info->height = -1;
-	}
-
-	av_free(buffer);
-	buffer = NULL;
-	av_free(pConvertedFrame);
-	pConvertedFrame = NULL;
-	av_free(pFrame);
-	pFrame = NULL;
-	sws_freeContext(c);
-	c = NULL;
-
-	return size; 
-}
-
-//! read frames from stream at index where it left off on previous invocation of function
-/*
- 	Read up to nb_retrieval frames from filename video stream at step intervals; convert 
- 	frames to given pixelformat; insert in empty pFrameList CImgList; meant to be called consecutively
- 	until the end of stream is reached, at which point another call will reinitialize at the beginning
- 	of the stream.
- 	@param filename const char* - name of the file
- 	@param pFrameList CImgList<>* - an empty CImgList<> 
- 	@param step int - the step interval
- 	@param nb_retrieval int - max number to retrieve at a time
- 	@param pixelformat int - pixel format ( 0 = GRAY8 (8bpp grayscale), 1 = RGB24 (24 bpp RGB) )
- 	@return number of frames read or 0 if end of stream reached,  -1 unable to read from stream
-*/
-int NextFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList)
-{
-        PixelFormat ffmpeg_pixfmt;
-	if (st_info->pixelformat == 0)
-	    ffmpeg_pixfmt = PIX_FMT_GRAY8;
-        else 
-	    ffmpeg_pixfmt = PIX_FMT_RGB24;
-
-	if (st_info->pFormatCtx == NULL)
-	{
-	        st_info->current_index = 0;
-		st_info->next_index = 0;
-		av_register_all();
-		st_info->videoStream = -1;
-		//st_info->pFormatCtx = (AVFormatContext*)malloc(sizeof(AVFormatContext));
-		//st_info->pCodecCtx = (AVCodecContext*)malloc(sizeof(AVCodecContext));
-		//st_info->pCodec = (AVCodec*)malloc(sizeof(AVCodec));
-
-		av_log_set_level(AV_LOG_QUIET);
-		// Open video file
- 		if(av_open_input_file(&(st_info->pFormatCtx),st_info->filename,NULL,0,NULL)!=0){
-			return -1 ; // Couldn't open file
-		}
-	 
-		// Retrieve stream information
-		if(av_find_stream_info(st_info->pFormatCtx)<0){
-			return -1; // Couldn't find stream information
-		}
-
-		unsigned int i;
-
-		// Find the video stream
-		for(i=0; i< st_info->pFormatCtx->nb_streams; i++)
-		{
-			if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
-			{
-				st_info->videoStream=i;
-				break;
-			}
-		}
-
-		if(st_info->videoStream==-1){
-		    return -1; //no video stream
-		}
-	
-		// Get a pointer to the codec context for the video stream
-		st_info->pCodecCtx = st_info->pFormatCtx->streams[st_info->videoStream]->codec;
-
-		// Find the decoder
-		st_info->pCodec = avcodec_find_decoder(st_info->pCodecCtx->codec_id);
-		if(st_info->pCodec==NULL) 
-		{
-			return -1 ; // Codec not found
-		}
-		// Open codec
-		if(avcodec_open(st_info->pCodecCtx, st_info->pCodec)<0){
-		    return -1; // Could not open codec
-		}
-		
-		st_info->width = (st_info->width<=0) ? st_info->pCodecCtx->width : st_info->width;
-		st_info->height = (st_info->height<=0) ? st_info->pCodecCtx->height : st_info->height;
-		
-	} 
-
-	AVFrame *pFrame;
-
-	// Allocate video frame
-	pFrame=avcodec_alloc_frame();
-		
-	// Allocate an AVFrame structure
-	AVFrame *pConvertedFrame = avcodec_alloc_frame();
-	if(pConvertedFrame==NULL){
-	  return -1;
-	}
-		
-	uint8_t *buffer;
-	int numBytes;
-	// Determine required buffer size and allocate buffer
-	numBytes=avpicture_get_size(ffmpeg_pixfmt, st_info->width,st_info->height);
-	buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
-	if (buffer == NULL){
-	    return -1;
-	}
-
-	avpicture_fill((AVPicture *)pConvertedFrame,buffer,ffmpeg_pixfmt,st_info->width,st_info->height);
-		
-	int frameFinished;
-	int size = 0;
-	AVPacket packet;
-	int result = 1;
-	CImg<uint8_t> next_image;
-	SwsContext *c = sws_getContext(st_info->pCodecCtx->width, st_info->pCodecCtx->height, st_info->pCodecCtx->pix_fmt, st_info->width, st_info->height, ffmpeg_pixfmt , SWS_BICUBIC, NULL, NULL, NULL);
-	while ((result >= 0) && (size < st_info->nb_retrieval))
-	{
-
-		result = av_read_frame(st_info->pFormatCtx, &packet); 
-		if (result < 0) 
-			break;
-		if(packet.stream_index == st_info->videoStream) {
-			
-		    avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,
-		                         packet.data,packet.size);
- 
-		    if(frameFinished) {
-		    	if (st_info->current_index == st_info->next_index)
-		    	{
-			    st_info->next_index += st_info->step;
-			   
-			    sws_scale(c, pFrame->data, pFrame->linesize, 0, st_info->pCodecCtx->height, pConvertedFrame->data, pConvertedFrame->linesize);
-				   	
-			    if (ffmpeg_pixfmt == PIX_FMT_RGB24){   
-				next_image.assign(*pConvertedFrame->data,3,st_info->width,st_info->height,1,true);
-				next_image.permute_axes("yzcx");
-				pFrameList->push_back(next_image);
-				size++;
-			    }
-			    else if (ffmpeg_pixfmt == PIX_FMT_GRAY8){
-				next_image.assign(pConvertedFrame->data[0],1,st_info->width,st_info->height,1,true);
-				next_image.permute_axes("yzcx");
-				pFrameList->push_back(next_image);
-				size++;
-			    }
-				   	 
-		    	}    
-				st_info->current_index++;
-		    }
-    	  }
-    	        av_free_packet(&packet);
-	}
-	
-	av_free(buffer);
-	buffer = NULL;
-	av_free(pConvertedFrame);
-	pConvertedFrame = NULL;
-	av_free(pFrame);
-	pFrame = NULL;
-	sws_freeContext(c);
-	c = NULL;
-	if (result < 0)
-	{
-		avcodec_close(st_info->pCodecCtx);
-		av_close_input_file(st_info->pFormatCtx);
-		st_info->pCodecCtx = NULL;
-		st_info->pFormatCtx = NULL;
-		st_info->pCodec = NULL;
-		st_info->width = -1;
-		st_info->height = -1;
-	}
-	return size; 
-}
-
-//! Get number of streams contained in given file
-/*
-	Return the number of streams contained in the given file format.
-	@param file const char*
-	@return number of streams
-*/
-int GetNumberStreams(const char *file)
-{
-	 AVFormatContext *pFormatCtx;
-     av_log_set_level(AV_LOG_QUIET);
-	 av_register_all();
-	// Open video file
-	if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
-	  return -1 ; // Couldn't open file
-		 
-	// Retrieve stream information
-	if(av_find_stream_info(pFormatCtx)<0)
-	  return -1; // Couldn't find stream information
-	int result = pFormatCtx->nb_streams;
-	av_close_input_file(pFormatCtx);
-	return result;
-}
-//! get number of video frames contained in file
-/*
- * return number of video frames in file.
- * @param file const char* - video file
- * @return number of video frames
-*/
-long GetNumberVideoFrames(const char *file)
-{
-    long nb_frames = 0L;
-	AVFormatContext *pFormatCtx;
-    av_log_set_level(AV_LOG_QUIET);
-	av_register_all();
-	// Open video file
-	if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
-	  return -1 ; // Couldn't open file
-			 
-	// Retrieve stream information
-	if(av_find_stream_info(pFormatCtx)<0)
-	  return -1; // Couldn't find stream information
-		
-	// Find the first video stream
-	int videoStream=-1;
-	for(unsigned int i=0; i<pFormatCtx->nb_streams; i++)
-	{
-	     if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
-	     {
-		    videoStream=i;
-		    break;
-             }
-	}
-	if(videoStream==-1)
-	   return -1; // Didn't find a video stream
-	
-		
-        nb_frames = pFormatCtx->streams[videoStream]->nb_frames;
-	if (nb_frames > 0)
-	{   //the easy way if value is already contained in struct 
-	    av_close_input_file(pFormatCtx);
-	    return nb_frames;
-	}
-	else { // frames must be counted
-	        AVPacket packet;
-		
-		//read each frame - one frame per packet
-		while(av_read_frame(pFormatCtx, &packet)>=0) 
-		{
-		  if(packet.stream_index==videoStream) {
-                  //packet is from video stream
-		      nb_frames++;
-		  }
-		  av_free_packet(&packet);
-		}
-
-		// Close the video file
-		av_close_input_file(pFormatCtx); 
-
-		return nb_frames;
-	}
-}
-float fps(const char *filename)
-{
-        float result = 0;
-	AVFormatContext *pFormatCtx;
-	
-	// Open video file
-	if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL))
-	  return -1 ; // Couldn't open file
-				 
-	// Retrieve stream information
-	if(av_find_stream_info(pFormatCtx)<0)
-	  return -1; // Couldn't find stream information
-			
-	// Find the first video stream
-	int videoStream=-1;
-	for(unsigned int i=0; i<pFormatCtx->nb_streams; i++)
-	{
-		     if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
-		     {
-			    videoStream=i;
-			    break;
-		     }
-	}
-        if(videoStream==-1)
-	    return -1; // Didn't find a video stream
-	
-	int num = (pFormatCtx->streams[videoStream]->r_frame_rate).num;
-	int den = (pFormatCtx->streams[videoStream]->r_frame_rate).den;
-	result = num/den;
-
-	av_close_input_file(pFormatCtx);
-	
-	return result;
-
-}
-
-//! play a list of CImg's given a CImgList.   
-  
-/*
- *  This function is not really meant to function as a video player as much as a simple 
- *  debugging tool.  It is meant to be run in a thread. The video is played at 1 CImg per second
- *  @param pVideo - a pointer to a CImgList object containing the CImg's to be played 
-*/
-void *PlayVideo(void *info)
-{
-	video_info_t *pvideo_info = (video_info_t *)info;
-	int fps = pvideo_info->fps;
-	CImgList<unsigned char> *videolist = (CImgList<unsigned char> *)pvideo_info->pList;
-	CImg<> current = videolist->front();
-    
-	CImgDisplay disp(current,"video");
-	
-	//display frame every second
-	clock_t interval = (time_t)((1/fps)*(CLOCKS_PER_SEC)); 
-			 
-	clock_t n = clock();
-	while (!videolist->is_empty() && !disp.is_closed())
-	{
-		if (videolist->size() > 1)
-		{
-			videolist->pop_front();
-			current = videolist->front();
-			disp.display(current);
-			while ( n + interval > clock()){};
-			n = clock();
-		}
-		else if (videolist->size() == 1){
-			videolist->pop_front();
-		}
-		else
-			pthread_exit(NULL);
-	}
-	pthread_exit(NULL);
-}
-/**
- * !write a sequence of CImg's to video file.
- * Purpose: write sequence of images  in cimg list at a given framerate 
- * using given filename, use pixel format PIX_FMT_YUV420P
- * The function expects the images to be either gray scale (dim v = 1) or 
- * rgb images (dim v == 3).  Other sizes return -1.
- * 
- * @param pImlist reference to CImgList
- * @param filename name of video file to create - with proper extension - e.g. 
- *                                ".avi, .mpeg, .wmv, etc."
- * @param fps int value for number of frames per second
- * @param stream_duration maximum length of video stream (secs)
- * @return int number of frames recorded to file, < 0 for errors
- **/
-template<class T>
-int WriteFrames(CImgList<T> *pImList,const char *filename, int fps,float stream_duration=100.0)
-{
-    int width  = (pImList->front()).dimx();
-    int height = (pImList->front()).dimy();
-    int nb_channels = (pImList->front()).dimv();
-    if ((nb_channels != 1) && (nb_channels != 3))
-	throw new CImgIOException("dimv of image not acceptable");
-    if (!filename)
-        throw new CImgIOException("no file name given");
-    int frame_count = 0;
-    PixelFormat dest_pxl_fmt = PIX_FMT_YUV420P;
-    PixelFormat src_pxl_fmt  = (nb_channels == 3) ? PIX_FMT_RGB24 : PIX_FMT_GRAY8;
-    
-    int sws_flags = SWS_FAST_BILINEAR;//interpolation method (keeping same size images for now)
-
-    AVOutputFormat *fmt = NULL;
-
-    fmt = guess_format(NULL,filename,NULL);
-    if (!fmt){
-	//default format "mpeg" 
-        fmt = guess_format("mpeg",NULL,NULL);
-    }
-    if (!fmt){
-	//unable to retrieve output format
-        throw new CImgIOException("could not determine format from filename");
-    }
-
-    AVFormatContext *oc = NULL;
-    oc = avformat_alloc_context(); 
-    if (!oc){
-	//unable to allocate format context
-        throw new CImgIOException("mem allocation error for format context");
-    }
-
-    AVCodec *codec = NULL;
-    AVFrame *picture = NULL;
-    AVFrame *tmp_pict = NULL;
-    oc->oformat = fmt;
-    snprintf(oc->filename, sizeof(oc->filename),"%s",filename);
-
-    av_register_all();
-
-    //add video stream
-    int stream_index = 0;
-    AVStream *video_str = NULL;
-    if (fmt->video_codec != CODEC_ID_NONE) {
-	video_str = av_new_stream(oc,stream_index);
-	if (!video_str){
-	    //no stream allocated
-            av_free(oc);
-	    throw new CImgIOException("unable to create new video stream");
-	}
-    } else {
-        //no codec identified
-        av_free(oc);
-	throw new CImgIOException("no codec identified"); 
-    }
-
-    AVCodecContext *c = video_str->codec;
-    c->codec_id = fmt->video_codec;
-    c->codec_type = CODEC_TYPE_VIDEO;
-    c->bit_rate = 400000;
-    c->width = width;
-    c->height = height;
-    c->time_base.num = 1;
-    c->time_base.den = fps;
-    c->gop_size = 12;
-    c->pix_fmt = dest_pxl_fmt;
-    if (c->codec_id == CODEC_ID_MPEG2VIDEO)
-	c->max_b_frames = 2;
-    if (c->codec_id == CODEC_ID_MPEG1VIDEO)
-        c->mb_decision = 2;
- 
-    if (av_set_parameters(oc,NULL) < 0){
-        //parameters not properly set
-        av_free(oc);
-        throw new CImgIOException("parameters for avcodec not properly set");
-    }
-   
-    //dump_format(oc,0,filename,1);
-
-    //open codecs and alloc buffers
-    codec = avcodec_find_encoder(c->codec_id);
-    if (!codec){
-	//unable to find codec
-        av_free(oc);
-        throw new CImgIOException("no codec found");
-    }
-    if (avcodec_open(c,codec) < 0)
-        //fail to open codec
-	throw new CImgIOException("unable to open codec");
-
-    tmp_pict = avcodec_alloc_frame();
-    if (!tmp_pict){
-	//unable to allocate memory for tmp_pict frame
-        avcodec_close(video_str->codec);
-        av_free(oc);
-        throw new CImgIOException("mem alloc error for tmp_pict data buffer");
-    }
-    tmp_pict->linesize[0] = (src_pxl_fmt == PIX_FMT_RGB24) ? 3*width : width ;
-    tmp_pict->type = FF_BUFFER_TYPE_USER;
-    int	tmp_size = avpicture_get_size(src_pxl_fmt,width,height);
-    uint8_t *tmp_buffer = (uint8_t*)av_malloc(tmp_size);
-    if (!tmp_buffer){
-	//unable to allocate memory for tmp buffer
-        av_free(tmp_pict);
-        avcodec_close(video_str->codec);
-        av_free(oc);
-        throw new CImgIOException("mem alloc error for tmp buffer");
-    }
-
-    //associate buffer with tmp_pict
-    avpicture_fill((AVPicture*)tmp_pict,tmp_buffer,src_pxl_fmt,width,height);
-
-    picture = avcodec_alloc_frame();
-    if (!picture){
-	//unable to allocate picture frame
-        av_free(tmp_pict->data[0]);
-        av_free(tmp_pict);
-        avcodec_close(video_str->codec);
-        av_free(oc);
-        throw new CImgIOException("mem alloc error for picture frame");
-    }
-
-    int size = avpicture_get_size(c->pix_fmt,width,height);
-    uint8_t *buffer = (uint8_t*)av_malloc(size);
-    if (!buffer){
-	//unable to allocate buffer
-        av_free(picture);
-        av_free(tmp_pict->data[0]);
-        av_free(tmp_pict);
-        avcodec_close(video_str->codec);
-        av_free(oc);
-        throw new CImgIOException("mem alloc error for picture frame buffer");
-    }
-    //associate the buffer with picture
-    avpicture_fill((AVPicture*)picture,buffer,c->pix_fmt,width,height);
-
-    //open file
-    if ( !(fmt->flags & AVFMT_NOFILE) ){
-	if (url_fopen(&oc->pb,filename,URL_WRONLY) < 0)
-	    throw new CImgIOException("unable to open file");
-    }
-
-    if (av_write_header(oc) < 0)
-	throw new CImgIOException("could not write header");
-    
-    double video_pts;
-
-    SwsContext *img_convert_context = NULL;
-    img_convert_context = sws_getContext(width,height,src_pxl_fmt,
-                                         c->width,c->height,c->pix_fmt,sws_flags,NULL,NULL,NULL);
-    if (!img_convert_context){
-	//unable to get swscale context
-        if (!(fmt->flags & AVFMT_NOFILE))
-	    url_fclose(oc->pb);
-        av_free(picture->data);
-        av_free(picture);
-        av_free(tmp_pict->data[0]);
-        av_free(tmp_pict);
-        avcodec_close(video_str->codec);
-        av_free(oc);
-        throw new CImgIOException("unable to get conversion context");
-    }
-    int ret=0, out_size;
-    uint8_t *video_outbuf = NULL;
-    int video_outbuf_size = 1000000;
-    video_outbuf = (uint8_t*)av_malloc(video_outbuf_size);    
-    if (!video_outbuf){
-	if (!(fmt->flags & AVFMT_NOFILE))
-	    url_fclose(oc->pb);
-	av_free(picture->data);
-        av_free(picture);
-        av_free(tmp_pict->data[0]);
-        av_free(tmp_pict);
-        avcodec_close(video_str->codec);
-        av_free(oc);
-        throw new CImgIOException("mem alloc error");
-    }
-
-    //loop through each image in list
-    for (unsigned int i = 0; i < pImList->size; i++)
-    {
-	frame_count++;
-        CImg<uint8_t> currentIm = pImList->at(i);
-	CImg<uint8_t> red,green,blue,gray;
-	if (src_pxl_fmt == PIX_FMT_RGB24){
-	    red = currentIm.get_channel(0);
-	    green = currentIm.get_channel(1);
-	    blue = currentIm.get_channel(2);
-            cimg_forXY(red,X,Y){
-		//assign pizel values to data buffer in interlaced RGBRGB ... format
-		tmp_pict->data[0][Y*tmp_pict->linesize[0] + 3*X]     = red(X,Y);
-                tmp_pict->data[0][Y*tmp_pict->linesize[0] + 3*X + 1] = green(X,Y);
-                tmp_pict->data[0][Y*tmp_pict->linesize[0] + 3*X + 2] = blue(X,Y);
-	    }
-	} else {
-	    gray = currentIm.get_channel(0);
-	    cimg_forXY(gray,X,Y){
-                tmp_pict->data[0][Y*tmp_pict->linesize[0] + X] = gray(X,Y);
-	    }
-	}
-
-
-	if (video_str)
-	    video_pts = (video_str->pts.val * video_str->time_base.num)/(video_str->time_base.den);
-        else
-	    video_pts = 0.0;
-        if ((!video_str) || (video_pts >= stream_duration))
-	    break;
-
-	if (sws_scale(img_convert_context,tmp_pict->data,tmp_pict->linesize,0,c->height,picture->data,picture->linesize) < 0){
-            break;;//break out of loop
-	}
-	out_size = avcodec_encode_video(c,video_outbuf,video_outbuf_size,picture);
-        
-        if (out_size > 0){
-	    AVPacket pkt;
-            av_init_packet(&pkt);
-            pkt.pts = av_rescale_q(c->coded_frame->pts,c->time_base,video_str->time_base);
-            if (c->coded_frame->key_frame){
-		pkt.flags |= PKT_FLAG_KEY;
-	    }
-            pkt.stream_index = video_str->index;
-            pkt.data = video_outbuf;
-            pkt.size = out_size;
-            ret = av_write_frame(oc,&pkt);
-	} else if (out_size < 0){
-            break;//failure occured in avcodec_encode_video() 
-	}
-        if (ret != 0){
-            //error occured in writing frame
-            break;
-	}
- 
-    }
-    //close codec
-    if (video_str){
-	avcodec_close(video_str->codec);
-        av_free(picture->data[0]);
-        av_free(picture);
-        av_free(tmp_pict->data[0]);
-        av_free(tmp_pict);
-    }
-    if (av_write_trailer(oc) < 0)
-	throw new CImgIOException("could not write trailer");
-    av_freep(&oc->streams[stream_index]->codec);
-    av_freep(&oc->streams[stream_index]);
-    if (!(fmt->flags & AVFMT_NOFILE)){
-        if (url_fclose(oc->pb) < 0)
-	    throw new CImgIOException("could not close file");
-    }
-    av_free(oc);
-    av_free(video_outbuf);
-
-    return frame_count;
-}
-#endif /*CIMGFFMPEG_H_*/

-- 
debian-forensics/libphash



More information about the forensics-changes mailing list