Initial commit: Final state of the master project
This commit is contained in:
276
Research/inc/pvm/codebase.h
Normal file
276
Research/inc/pvm/codebase.h
Normal file
@@ -0,0 +1,276 @@
|
||||
// (c) by Stefan Roettger, licensed under GPL 2+
|
||||
|
||||
#ifndef CODEBASE_H
|
||||
#define CODEBASE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#if !defined WINOS && !defined MACOSX && !defined LINUX
|
||||
#if defined _WIN32
|
||||
# define WINOS
|
||||
#elif defined __APPLE__
|
||||
# define MACOSX
|
||||
#else
|
||||
# define LINUX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(IRIX) || defined(LINUX) || defined(MACOSX)
|
||||
#define UNIX
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#ifdef UNIX
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#ifdef WINOS
|
||||
#include <windows.h>
|
||||
#include <winbase.h>
|
||||
#endif
|
||||
|
||||
#ifdef UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#define BOOLINT char
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (1)
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
|
||||
enum VR_ERROR
|
||||
{
|
||||
VR_ERROR_NONFATAL=0,
|
||||
VR_ERROR_FATAL=1,
|
||||
VR_ERROR_MEM=2,
|
||||
VR_ERROR_IO=3,
|
||||
VR_ERROR_CODE=4
|
||||
};
|
||||
|
||||
#define ERRORMSG() vrerrormsg(__FILE__,__LINE__,VR_ERROR_FATAL)
|
||||
#define MEMERROR() vrerrormsg(__FILE__,__LINE__,VR_ERROR_MEM)
|
||||
#define IOERROR() vrerrormsg(__FILE__,__LINE__,VR_ERROR_IO)
|
||||
#define CODEERROR() vrerrormsg(__FILE__,__LINE__,VR_ERROR_CODE)
|
||||
#define WARNMSG(msg) vrerrormsg(__FILE__,__LINE__,VR_ERROR_NONFATAL,msg)
|
||||
|
||||
inline void vrerrormsg(const char *file,int line,int fatal,const char *msg=NULL)
|
||||
{
|
||||
if (fatal==VR_ERROR_NONFATAL) fprintf(stderr,"warning");
|
||||
else if (fatal==VR_ERROR_MEM) fprintf(stderr,"insufficient memory");
|
||||
else if (fatal==VR_ERROR_IO) fprintf(stderr,"io error");
|
||||
else if (fatal==VR_ERROR_CODE) fprintf(stderr,"unimplemented code");
|
||||
else fprintf(stderr,"fatal error");
|
||||
fprintf(stderr," in <%s> at line %d!\n",file,line);
|
||||
if (msg!=NULL) fprintf(stderr,"description: %s\n",msg);
|
||||
}
|
||||
|
||||
#define PI (3.141593f)
|
||||
#define RAD (PI/180.0f)
|
||||
|
||||
#ifndef MAXFLOAT
|
||||
#define MAXFLOAT (FLT_MAX)
|
||||
#endif
|
||||
|
||||
#undef ffloor
|
||||
#define ffloor(x) floor((double)(x))
|
||||
#undef fceil
|
||||
#define fceil(x) ceil((double)(x))
|
||||
#define ftrc(x) (int)ffloor(x)
|
||||
|
||||
inline double FABS(const double x) {return((x<0.0)?-x:x);}
|
||||
#define fabs(x) FABS(x)
|
||||
|
||||
#ifndef min
|
||||
inline int min(const int a,const int b) {return((a<b)?a:b);}
|
||||
#endif
|
||||
inline double FMIN(const double a,const double b) {return((a<b)?a:b);}
|
||||
#define fmin(a,b) FMIN(a,b)
|
||||
|
||||
#ifndef max
|
||||
inline int max(const int a,const int b) {return((a>b)?a:b);}
|
||||
#endif
|
||||
inline double FMAX(const double a,const double b) {return((a>b)?a:b);}
|
||||
#define fmax(a,b) FMAX(a,b)
|
||||
|
||||
inline int sqr(const int x) {return(x*x);}
|
||||
inline double fsqr(const double x) {return(x*x);}
|
||||
|
||||
#undef fsqrt
|
||||
#define fsqrt(x) sqrt((double)(x))
|
||||
|
||||
#undef fsin
|
||||
#define fsin(x) sin((double)(x))
|
||||
#undef fcos
|
||||
#define fcos(x) cos((double)(x))
|
||||
#undef ftan
|
||||
#define ftan(x) tan((double)(x))
|
||||
|
||||
#undef fasin
|
||||
#define fasin(x) asin((double)(x))
|
||||
#undef facos
|
||||
#define facos(x) acos((double)(x))
|
||||
#undef fatan
|
||||
#define fatan(x) atan((double)(x))
|
||||
|
||||
#undef fexp
|
||||
#define fexp(x) exp((double)(x))
|
||||
#undef flog
|
||||
#define flog(x) log((double)(x))
|
||||
#undef fpow
|
||||
#define fpow(x,y) pow((double)(x),(double)(y))
|
||||
|
||||
#ifdef UNIX
|
||||
#define GETRANDOM() drand48()
|
||||
#endif
|
||||
#ifdef WINOS
|
||||
#define GETRANDOM() ((double)rand()/RAND_MAX)
|
||||
#endif
|
||||
|
||||
inline double GETTIME()
|
||||
{
|
||||
#ifdef UNIX
|
||||
struct timeval t;
|
||||
gettimeofday(&t,NULL);
|
||||
return(t.tv_sec+t.tv_usec/1.0E6);
|
||||
#endif
|
||||
#ifdef WINOS
|
||||
static int cpus=0;
|
||||
if (cpus==0)
|
||||
{
|
||||
SYSTEM_INFO SystemInfo;
|
||||
GetSystemInfo(&SystemInfo);
|
||||
cpus=SystemInfo.dwNumberOfProcessors;
|
||||
}
|
||||
if (cpus==1)
|
||||
{
|
||||
LARGE_INTEGER freq,count;
|
||||
if (QueryPerformanceFrequency(&freq)==0) ERRORMSG();
|
||||
QueryPerformanceCounter(&count);
|
||||
return((double)count.QuadPart/freq.QuadPart);
|
||||
}
|
||||
return((double)clock()/CLOCKS_PER_SEC);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline double gettime()
|
||||
{
|
||||
static double time;
|
||||
static BOOLINT settime=FALSE;
|
||||
|
||||
if (!settime)
|
||||
{
|
||||
time=GETTIME();
|
||||
settime=TRUE;
|
||||
}
|
||||
|
||||
return(GETTIME()-time);
|
||||
}
|
||||
|
||||
inline void waitfor(double secs)
|
||||
{
|
||||
if (secs<=0.0) return;
|
||||
#ifdef UNIX
|
||||
struct timespec dt,rt;
|
||||
dt.tv_sec=ftrc(secs);
|
||||
dt.tv_nsec=ftrc(1.0E9*(secs-ftrc(secs)));
|
||||
while (nanosleep(&dt,&rt)!=0) dt=rt;
|
||||
#else
|
||||
double time=gettime()+secs;
|
||||
while (gettime()<time);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline double getclockticks()
|
||||
{
|
||||
static double clockticks;
|
||||
static BOOLINT setclockticks=FALSE;
|
||||
|
||||
if (!setclockticks)
|
||||
{
|
||||
double time=gettime();
|
||||
while (time==gettime());
|
||||
clockticks=1.0/(gettime()-time);
|
||||
setclockticks=TRUE;
|
||||
}
|
||||
|
||||
return(clockticks);
|
||||
}
|
||||
|
||||
#ifdef WINOS
|
||||
|
||||
#define strdup _strdup
|
||||
#define snprintf _snprintf
|
||||
|
||||
#ifndef __MINGW32__
|
||||
inline int strcasecmp(const char *str1,const char *str2)
|
||||
{
|
||||
const char *ptr1,*ptr2;
|
||||
for (ptr1=str1,ptr2=str2; tolower(*ptr1)==tolower(*ptr2) && *ptr1!='\0' && *ptr2!='\0'; ptr1++,ptr2++);
|
||||
return(*ptr1-*ptr2);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline char *strcasestr(const char *str1,const char *str2)
|
||||
{
|
||||
unsigned int i,j;
|
||||
|
||||
unsigned int len1,len2;
|
||||
|
||||
len1=(unsigned int)strlen(str1);
|
||||
len2=(unsigned int)strlen(str2);
|
||||
|
||||
for (i=0; i+len2<=len1; i++)
|
||||
{
|
||||
for (j=0; j<len2; j++)
|
||||
if (tolower(str2[j])!=tolower(str1[i+j])) break;
|
||||
|
||||
if (j==len2) return((char *)&str1[i]);
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline char *strdup2(const char *str1,const char *str2)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (str1==NULL && str2==NULL) return(NULL);
|
||||
|
||||
if (str1==NULL) return(strdup(str2));
|
||||
if (str2==NULL) return(strdup(str1));
|
||||
|
||||
if ((str=(char *)malloc(strlen(str1)+strlen(str2)+1))==NULL) MEMERROR();
|
||||
|
||||
memcpy(str,str1,strlen(str1));
|
||||
memcpy(str+strlen(str1),str2,strlen(str2)+1);
|
||||
|
||||
return(str);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <stdio.h>
|
||||
#include <direct.h>
|
||||
inline int removefile(const char *file) {return(remove(file));}
|
||||
inline int removedir(const char *dir) {return(_rmdir(dir));}
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
inline int removefile(const char *file) {return(remove(file));}
|
||||
inline int removedir(const char *dir) {return(rmdir(dir));}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1146
Research/inc/pvm/ddsbase.cpp
Normal file
1146
Research/inc/pvm/ddsbase.cpp
Normal file
File diff suppressed because it is too large
Load Diff
48
Research/inc/pvm/ddsbase.h
Normal file
48
Research/inc/pvm/ddsbase.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// (c) by Stefan Roettger, licensed under GPL 2+
|
||||
|
||||
#ifndef DDSBASE_H
|
||||
#define DDSBASE_H
|
||||
|
||||
#include "codebase.h" // universal code base
|
||||
|
||||
void writeDDSfile(const char *filename,unsigned char *data,unsigned int bytes,unsigned int skip=0,unsigned int strip=0,BOOLINT nofree=FALSE);
|
||||
unsigned char *readDDSfile(const char *filename,unsigned int *bytes);
|
||||
|
||||
void writeRAWfile(const char *filename,unsigned char *data,unsigned int bytes,BOOLINT nofree=FALSE);
|
||||
unsigned char *readRAWfile(const char *filename,unsigned int *bytes);
|
||||
|
||||
void writePNMimage(const char *filename,unsigned char *image,unsigned int width,unsigned int height,unsigned int components,BOOLINT dds=FALSE);
|
||||
unsigned char *readPNMimage(const char *filename,unsigned int *width,unsigned int *height,unsigned int *components);
|
||||
|
||||
void writePVMvolume(const char *filename,unsigned char *volume,
|
||||
unsigned int width,unsigned int height,unsigned int depth,unsigned int components=1,
|
||||
float scalex=1.0f,float scaley=1.0f,float scalez=1.0f,
|
||||
unsigned char *description=NULL,
|
||||
unsigned char *courtesy=NULL,
|
||||
unsigned char *parameter=NULL,
|
||||
unsigned char *comment=NULL);
|
||||
|
||||
unsigned char *readPVMvolume(const char *filename,
|
||||
unsigned int *width,unsigned int *height,unsigned int *depth,unsigned int *components=NULL,
|
||||
float *scalex=NULL,float *scaley=NULL,float *scalez=NULL,
|
||||
unsigned char **description=NULL,
|
||||
unsigned char **courtesy=NULL,
|
||||
unsigned char **parameter=NULL,
|
||||
unsigned char **comment=NULL);
|
||||
|
||||
int checkfile(const char *filename);
|
||||
unsigned int checksum(unsigned char *data,unsigned int bytes);
|
||||
|
||||
void swapbytes(unsigned char *data,long long bytes);
|
||||
void convbytes(unsigned char *data,long long bytes);
|
||||
void convfloat(unsigned char **data,long long bytes);
|
||||
void convrgb(unsigned char **data,long long bytes);
|
||||
|
||||
unsigned char *quantize(unsigned char *volume,
|
||||
long long width,long long height,long long depth,
|
||||
BOOLINT msb=TRUE,
|
||||
BOOLINT linear=FALSE,BOOLINT nofree=FALSE);
|
||||
|
||||
char *processPVMvolume(const char *filename);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user