aboutsummaryrefslogtreecommitdiff
path: root/redist
diff options
context:
space:
mode:
authorJustin Berger <j.david.berger@gmail.com>2018-04-02 10:10:33 -0600
committerJustin Berger <j.david.berger@gmail.com>2018-04-02 10:10:33 -0600
commit75460f240c9d003e4ca2e6dda9b2146a74df7ffa (patch)
tree957b26f0539df176b61ad2ec72fbb0658b147919 /redist
parent2b63278497130d01b1fbc7e6a94b6ad8e32ab4dd (diff)
parent1724abef15a4090640bd82ba408681438316de7e (diff)
downloadlibsurvive-75460f240c9d003e4ca2e6dda9b2146a74df7ffa.tar.gz
libsurvive-75460f240c9d003e4ca2e6dda9b2146a74df7ffa.tar.bz2
Merge remote-tracking branch 'origin/master' into imu
Diffstat (limited to 'redist')
-rw-r--r--redist/linmath.c342
-rw-r--r--redist/linmath.h77
-rw-r--r--redist/minimal_opencv.c41
-rw-r--r--redist/os_generic.c337
-rw-r--r--redist/os_generic.h369
-rw-r--r--redist/symbol_enumerator.c11
6 files changed, 521 insertions, 656 deletions
diff --git a/redist/linmath.c b/redist/linmath.c
index d005074..01ae2b0 100644
--- a/redist/linmath.c
+++ b/redist/linmath.c
@@ -1,130 +1,125 @@
-//Copyright 2013,2016 <>< C. N. Lohr. This file licensed under the terms of the MIT license.
+// Copyright 2013,2016 <>< C. N. Lohr. This file licensed under the terms of the MIT license.
-#include <math.h>
#include "linmath.h"
#include <float.h>
+#include <math.h>
#include <string.h>
-void cross3d( FLT * out, const FLT * a, const FLT * b )
-{
- out[0] = a[1]*b[2] - a[2]*b[1];
- out[1] = a[2]*b[0] - a[0]*b[2];
- out[2] = a[0]*b[1] - a[1]*b[0];
+void cross3d(FLT *out, const FLT *a, const FLT *b) {
+ out[0] = a[1] * b[2] - a[2] * b[1];
+ out[1] = a[2] * b[0] - a[0] * b[2];
+ out[2] = a[0] * b[1] - a[1] * b[0];
}
-void sub3d( FLT * out, const FLT * a, const FLT * b )
-{
+void sub3d(FLT *out, const FLT *a, const FLT *b) {
out[0] = a[0] - b[0];
out[1] = a[1] - b[1];
out[2] = a[2] - b[2];
}
-void add3d( FLT * out, const FLT * a, const FLT * b )
-{
+void add3d(FLT *out, const FLT *a, const FLT *b) {
out[0] = a[0] + b[0];
out[1] = a[1] + b[1];
out[2] = a[2] + b[2];
}
-void scale3d( FLT * out, const FLT * a, FLT scalar )
-{
+void scale3d(FLT *out, const FLT *a, FLT scalar) {
out[0] = a[0] * scalar;
out[1] = a[1] * scalar;
out[2] = a[2] * scalar;
}
-void normalize3d( FLT * out, const FLT * in )
-{
+void normalize3d(FLT *out, const FLT *in) {
FLT r = ((FLT)1.) / FLT_SQRT(in[0] * in[0] + in[1] * in[1] + in[2] * in[2]);
out[0] = in[0] * r;
out[1] = in[1] * r;
out[2] = in[2] * r;
}
-FLT dot3d( const FLT * a, const FLT * b )
-{
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
-}
-
-int compare3d( const FLT * a, const FLT * b, FLT epsilon )
-{
- if( !a || !b ) return 0;
- if( a[2] - b[2] > epsilon ) return 1;
- if( b[2] - a[2] > epsilon ) return -1;
- if( a[1] - b[1] > epsilon ) return 1;
- if( b[1] - a[1] > epsilon ) return -1;
- if( a[0] - b[0] > epsilon ) return 1;
- if( b[0] - a[0] > epsilon ) return -1;
+FLT dot3d(const FLT *a, const FLT *b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; }
+
+int compare3d(const FLT *a, const FLT *b, FLT epsilon) {
+ if (!a || !b)
+ return 0;
+ if (a[2] - b[2] > epsilon)
+ return 1;
+ if (b[2] - a[2] > epsilon)
+ return -1;
+ if (a[1] - b[1] > epsilon)
+ return 1;
+ if (b[1] - a[1] > epsilon)
+ return -1;
+ if (a[0] - b[0] > epsilon)
+ return 1;
+ if (b[0] - a[0] > epsilon)
+ return -1;
return 0;
}
-void copy3d( FLT * out, const FLT * in )
-{
+void copy3d(FLT *out, const FLT *in) {
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
}
-FLT magnitude3d(const FLT * a )
-{
- return FLT_SQRT(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
+FLT magnitude3d(const FLT *a) { return FLT_SQRT(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); }
+FLT dist3d(const FLT *a, const FLT *b) {
+ LinmathPoint3d tmp;
+ sub3d(tmp, a, b);
+ return magnitude3d(tmp);
}
-FLT anglebetween3d( FLT * a, FLT * b )
-{
+FLT anglebetween3d(FLT *a, FLT *b) {
FLT an[3];
FLT bn[3];
- normalize3d( an, a );
- normalize3d( bn, b );
+ normalize3d(an, a);
+ normalize3d(bn, b);
FLT dot = dot3d(an, bn);
- if( dot < -0.9999999 ) return LINMATHPI;
- if( dot > 0.9999999 ) return 0;
+ if (dot < -0.9999999)
+ return LINMATHPI;
+ if (dot > 0.9999999)
+ return 0;
return FLT_ACOS(dot);
}
// algorithm found here: http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/
-void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle)
-{
+void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle) {
// TODO: this really should be external.
normalize3d(axis, axis);
FLT s = FLT_SIN(angle);
FLT c = FLT_COS(angle);
- FLT u=axis[0];
- FLT v=axis[1];
- FLT w=axis[2];
+ FLT u = axis[0];
+ FLT v = axis[1];
+ FLT w = axis[2];
- FLT x=invec3[0];
- FLT y=invec3[1];
- FLT z=invec3[2];
+ FLT x = invec3[0];
+ FLT y = invec3[1];
+ FLT z = invec3[2];
- outvec3[0] = u*(u*x + v*y + w*z)*(1-c) + x*c + (-w*y + v*z)*s;
- outvec3[1] = v*(u*x + v*y + w*z)*(1-c) + y*c + ( w*x - u*z)*s;
- outvec3[2] = w*(u*x + v*y + w*z)*(1-c) + z*c + (-v*x + u*y)*s;
+ outvec3[0] = u * (u * x + v * y + w * z) * (1 - c) + x * c + (-w * y + v * z) * s;
+ outvec3[1] = v * (u * x + v * y + w * z) * (1 - c) + y * c + (w * x - u * z) * s;
+ outvec3[2] = w * (u * x + v * y + w * z) * (1 - c) + z * c + (-v * x + u * y) * s;
}
-void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest)
-{
+void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest) {
FLT v0[3];
FLT v1[3];
normalize3d(v0, src);
normalize3d(v1, dest);
- FLT d = dot3d(v0, v1);// v0.dotProduct(v1);
+ FLT d = dot3d(v0, v1); // v0.dotProduct(v1);
// If dot == 1, vectors are the same
// If dot == -1, vectors are opposite
- if (FLT_FABS(d - 1) < DEFAULT_EPSILON)
- {
+ if (FLT_FABS(d - 1) < DEFAULT_EPSILON) {
axis[0] = 0;
axis[1] = 1;
axis[2] = 0;
*angle = 0;
return;
- }
- else if (FLT_FABS(d + 1) < DEFAULT_EPSILON)
- {
+ } else if (FLT_FABS(d + 1) < DEFAULT_EPSILON) {
axis[0] = 0;
axis[1] = 1;
axis[2] = 0;
@@ -137,33 +132,28 @@ void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest)
*angle = FLT_ACOS(d / (v0Len * v1Len));
- //cross3d(c, v0, v1);
+ // cross3d(c, v0, v1);
cross3d(axis, v1, v0);
-
}
-
-void axisanglefromquat(FLT *angle, FLT *axis, FLT *q)
-{
+void axisanglefromquat(FLT *angle, FLT *axis, FLT *q) {
// this way might be fine, too.
- //FLT dist = FLT_SQRT((q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]));
+ // FLT dist = FLT_SQRT((q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]));
//
//*angle = 2 * FLT_ATAN2(dist, q[0]);
- //axis[0] = q[1] / dist;
- //axis[1] = q[2] / dist;
- //axis[2] = q[3] / dist;
-
+ // axis[0] = q[1] / dist;
+ // axis[1] = q[2] / dist;
+ // axis[2] = q[3] / dist;
// Good mathematical foundation for this algorithm found here:
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
- FLT tmp[4] = { q[0], q[1], q[2], q[3] };
+ FLT tmp[4] = {q[0], q[1], q[2], q[3]};
quatnormalize(tmp, q);
- if (FLT_FABS(q[0] - 1) < FLT_EPSILON)
- {
+ if (FLT_FABS(q[0] - 1) < FLT_EPSILON) {
// we have a degenerate case where we're rotating approx. 0 degrees
*angle = 0;
axis[0] = 1;
@@ -180,11 +170,14 @@ void axisanglefromquat(FLT *angle, FLT *axis, FLT *q)
}
/////////////////////////////////////QUATERNIONS//////////////////////////////////////////
-//Originally from Mercury (Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman)
-//Under the mit/X11 license.
+// Originally from Mercury (Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman)
+// Under the mit/X11 license.
void quatsetnone(LinmathQuat q) {
- q[0] = 1; q[1] = 0; q[2] = 0; q[3] = 0;
+ q[0] = 1;
+ q[1] = 0;
+ q[2] = 0;
+ q[3] = 0;
}
void quatcopy(LinmathQuat qout, const LinmathQuat qin) {
@@ -195,9 +188,9 @@ void quatcopy(LinmathQuat qout, const LinmathQuat qin) {
}
void quatfromeuler(LinmathQuat q, const LinmathEulerAngle euler) {
- FLT X = euler[0]/2.0f; //roll
- FLT Y = euler[1]/2.0f; //pitch
- FLT Z = euler[2]/2.0f; //yaw
+ FLT X = euler[0] / 2.0f; // roll
+ FLT Y = euler[1] / 2.0f; // pitch
+ FLT Z = euler[2] / 2.0f; // yaw
FLT cx = FLT_COS(X);
FLT sx = FLT_SIN(X);
@@ -206,17 +199,17 @@ void quatfromeuler(LinmathQuat q, const LinmathEulerAngle euler) {
FLT cz = FLT_COS(Z);
FLT sz = FLT_SIN(Z);
- //Correct according to
- //http://en.wikipedia.org/wiki/Conversion_between_MQuaternions_and_Euler_angles
- q[0] = cx*cy*cz+sx*sy*sz;//q1
- q[1] = sx*cy*cz-cx*sy*sz;//q2
- q[2] = cx*sy*cz+sx*cy*sz;//q3
- q[3] = cx*cy*sz-sx*sy*cz;//q4
- quatnormalize( q, q );
+ // Correct according to
+ // http://en.wikipedia.org/wiki/Conversion_between_MQuaternions_and_Euler_angles
+ q[0] = cx * cy * cz + sx * sy * sz; // q1
+ q[1] = sx * cy * cz - cx * sy * sz; // q2
+ q[2] = cx * sy * cz + sx * cy * sz; // q3
+ q[3] = cx * cy * sz - sx * sy * cz; // q4
+ quatnormalize(q, q);
}
void quattoeuler(LinmathEulerAngle euler, const LinmathQuat q) {
- //According to http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles (Oct 26, 2009)
+ // According to http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles (Oct 26, 2009)
euler[0] = FLT_ATAN2(2 * (q[0] * q[1] + q[2] * q[3]), 1 - 2 * (q[1] * q[1] + q[2] * q[2]));
euler[1] = FLT_ASIN(2 * (q[0] * q[2] - q[3] * q[1]));
euler[2] = FLT_ATAN2(2 * (q[0] * q[3] + q[1] * q[2]), 1 - 2 * (q[2] * q[2] + q[3] * q[3]));
@@ -224,15 +217,15 @@ void quattoeuler(LinmathEulerAngle euler, const LinmathQuat q) {
void quatfromaxisangle(LinmathQuat q, const FLT *axis, FLT radians) {
FLT v[3];
- normalize3d( v, axis );
-
+ normalize3d(v, axis);
+
FLT sn = FLT_SIN(radians / 2.0f);
q[0] = FLT_COS(radians / 2.0f);
q[1] = sn * v[0];
q[2] = sn * v[1];
q[3] = sn * v[2];
- quatnormalize( q, q );
+ quatnormalize(q, q);
}
FLT quatmagnitude(const LinmathQuat q) {
@@ -240,19 +233,19 @@ FLT quatmagnitude(const LinmathQuat q) {
}
FLT quatinvsqmagnitude(const LinmathQuat q) {
- return ((FLT)1.)/FLT_SQRT((q[0]*q[0])+(q[1]*q[1])+(q[2]*q[2])+(q[3]*q[3]));
+ return ((FLT)1.) / FLT_SQRT((q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]));
}
void quatnormalize(LinmathQuat qout, const LinmathQuat qin) {
- FLT imag = quatinvsqmagnitude( qin );
- quatscale( qout, qin, imag );
+ FLT imag = quatinvsqmagnitude(qin);
+ quatscale(qout, qin, imag);
}
void quattomatrix(FLT *matrix44, const LinmathQuat qin) {
FLT q[4];
quatnormalize(q, qin);
- //Reduced calulation for speed
+ // Reduced calulation for speed
FLT xx = 2 * q[1] * q[1];
FLT xy = 2 * q[1] * q[2];
FLT xz = 2 * q[1] * q[3];
@@ -265,7 +258,7 @@ void quattomatrix(FLT *matrix44, const LinmathQuat qin) {
FLT zz = 2 * q[3] * q[3];
FLT zw = 2 * q[3] * q[0];
- //opengl major
+ // opengl major
matrix44[0] = 1 - yy - zz;
matrix44[1] = xy - zw;
matrix44[2] = xz + yw;
@@ -320,16 +313,16 @@ void quatfrommatrix33(FLT *q, const FLT *m) {
}
void quatfrommatrix(LinmathQuat q, const FLT *matrix44) {
- //Algorithm from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
+ // Algorithm from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
FLT tr = matrix44[0] + matrix44[5] + matrix44[10];
if (tr > 0) {
- FLT S = FLT_SQRT(tr+1.0) * 2.; // S=4*qw
+ FLT S = FLT_SQRT(tr + 1.0) * 2.; // S=4*qw
q[0] = 0.25f * S;
q[1] = (matrix44[9] - matrix44[6]) / S;
q[2] = (matrix44[2] - matrix44[8]) / S;
q[3] = (matrix44[4] - matrix44[1]) / S;
- } else if ((matrix44[0] > matrix44[5])&&(matrix44[0] > matrix44[10])) {
+ } else if ((matrix44[0] > matrix44[5]) && (matrix44[0] > matrix44[10])) {
FLT S = FLT_SQRT(1.0 + matrix44[0] - matrix44[5] - matrix44[10]) * 2.; // S=4*qx
q[0] = (matrix44[9] - matrix44[6]) / S;
q[1] = 0.25f * S;
@@ -350,13 +343,12 @@ void quatfrommatrix(LinmathQuat q, const FLT *matrix44) {
}
}
-
// Algorithm from http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/
void quattomatrix33(FLT *matrix33, const LinmathQuat qin) {
FLT q[4];
quatnormalize(q, qin);
- //Reduced calulation for speed
+ // Reduced calulation for speed
FLT xx = 2 * q[1] * q[1];
FLT xy = 2 * q[1] * q[2];
FLT xz = 2 * q[1] * q[3];
@@ -369,8 +361,7 @@ void quattomatrix33(FLT *matrix33, const LinmathQuat qin) {
FLT zz = 2 * q[3] * q[3];
FLT zw = 2 * q[3] * q[0];
-
- //opengl major
+ // opengl major
matrix33[0] = 1 - yy - zz;
matrix33[1] = xy + zw;
matrix33[2] = xz - yw;
@@ -393,8 +384,8 @@ void quatgetconjugate(LinmathQuat qout, const LinmathQuat qin) {
void quatgetreciprocal(LinmathQuat qout, const LinmathQuat qin) {
FLT m = quatinvsqmagnitude(qin);
- quatgetconjugate( qout, qin );
- quatscale( qout, qout, m );
+ quatgetconjugate(qout, qin);
+ quatscale(qout, qout, m);
}
void quatsub(LinmathQuat qout, const FLT *a, const FLT *b) {
@@ -412,11 +403,11 @@ void quatadd(LinmathQuat qout, const FLT *a, const FLT *b) {
}
void quatrotateabout(LinmathQuat qout, const LinmathQuat q1, const LinmathQuat q2) {
- //NOTE: Does not normalize
- qout[0] = (q1[0]*q2[0])-(q1[1]*q2[1])-(q1[2]*q2[2])-(q1[3]*q2[3]);
- qout[1] = (q1[0]*q2[1])+(q1[1]*q2[0])+(q1[2]*q2[3])-(q1[3]*q2[2]);
- qout[2] = (q1[0]*q2[2])-(q1[1]*q2[3])+(q1[2]*q2[0])+(q1[3]*q2[1]);
- qout[3] = (q1[0]*q2[3])+(q1[1]*q2[2])-(q1[2]*q2[1])+(q1[3]*q2[0]);
+ // NOTE: Does not normalize
+ qout[0] = (q1[0] * q2[0]) - (q1[1] * q2[1]) - (q1[2] * q2[2]) - (q1[3] * q2[3]);
+ qout[1] = (q1[0] * q2[1]) + (q1[1] * q2[0]) + (q1[2] * q2[3]) - (q1[3] * q2[2]);
+ qout[2] = (q1[0] * q2[2]) - (q1[1] * q2[3]) + (q1[2] * q2[0]) + (q1[3] * q2[1]);
+ qout[3] = (q1[0] * q2[3]) + (q1[1] * q2[2]) - (q1[2] * q2[1]) + (q1[3] * q2[0]);
}
void quatscale(LinmathQuat qout, const LinmathQuat qin, FLT s) {
@@ -427,96 +418,87 @@ void quatscale(LinmathQuat qout, const LinmathQuat qin, FLT s) {
}
FLT quatinnerproduct(const LinmathQuat qa, const LinmathQuat qb) {
- return (qa[0]*qb[0])+(qa[1]*qb[1])+(qa[2]*qb[2])+(qa[3]*qb[3]);
+ return (qa[0] * qb[0]) + (qa[1] * qb[1]) + (qa[2] * qb[2]) + (qa[3] * qb[3]);
}
void quatouterproduct(FLT *outvec3, LinmathQuat qa, LinmathQuat qb) {
- outvec3[0] = (qa[0]*qb[1])-(qa[1]*qb[0])-(qa[2]*qb[3])+(qa[3]*qb[2]);
- outvec3[1] = (qa[0]*qb[2])+(qa[1]*qb[3])-(qa[2]*qb[0])-(qa[3]*qb[1]);
- outvec3[2] = (qa[0]*qb[3])-(qa[1]*qb[2])+(qa[2]*qb[1])-(qa[3]*qb[0]);
+ outvec3[0] = (qa[0] * qb[1]) - (qa[1] * qb[0]) - (qa[2] * qb[3]) + (qa[3] * qb[2]);
+ outvec3[1] = (qa[0] * qb[2]) + (qa[1] * qb[3]) - (qa[2] * qb[0]) - (qa[3] * qb[1]);
+ outvec3[2] = (qa[0] * qb[3]) - (qa[1] * qb[2]) + (qa[2] * qb[1]) - (qa[3] * qb[0]);
}
void quatevenproduct(LinmathQuat q, LinmathQuat qa, LinmathQuat qb) {
- q[0] = (qa[0]*qb[0])-(qa[1]*qb[1])-(qa[2]*qb[2])-(qa[3]*qb[3]);
- q[1] = (qa[0]*qb[1])+(qa[1]*qb[0]);
- q[2] = (qa[0]*qb[2])+(qa[2]*qb[0]);
- q[3] = (qa[0]*qb[3])+(qa[3]*qb[0]);
+ q[0] = (qa[0] * qb[0]) - (qa[1] * qb[1]) - (qa[2] * qb[2]) - (qa[3] * qb[3]);
+ q[1] = (qa[0] * qb[1]) + (qa[1] * qb[0]);
+ q[2] = (qa[0] * qb[2]) + (qa[2] * qb[0]);
+ q[3] = (qa[0] * qb[3]) + (qa[3] * qb[0]);
}
void quatoddproduct(FLT *outvec3, LinmathQuat qa, LinmathQuat qb) {
- outvec3[0] = (qa[2]*qb[3])-(qa[3]*qb[2]);
- outvec3[1] = (qa[3]*qb[1])-(qa[1]*qb[3]);
- outvec3[2] = (qa[1]*qb[2])-(qa[2]*qb[1]);
+ outvec3[0] = (qa[2] * qb[3]) - (qa[3] * qb[2]);
+ outvec3[1] = (qa[3] * qb[1]) - (qa[1] * qb[3]);
+ outvec3[2] = (qa[1] * qb[2]) - (qa[2] * qb[1]);
}
void quatslerp(LinmathQuat q, const LinmathQuat qa, const LinmathQuat qb, FLT t) {
FLT an[4];
FLT bn[4];
- quatnormalize( an, qa );
- quatnormalize( bn, qb );
- FLT cosTheta = quatinnerproduct(an,bn);
+ quatnormalize(an, qa);
+ quatnormalize(bn, qb);
+ FLT cosTheta = quatinnerproduct(an, bn);
FLT sinTheta;
- //Careful: If cosTheta is exactly one, or even if it's infinitesimally over, it'll
+ // Careful: If cosTheta is exactly one, or even if it's infinitesimally over, it'll
// cause SQRT to produce not a number, and screw everything up.
- if ( 1 - (cosTheta*cosTheta) <= 0 )
+ if (1 - (cosTheta * cosTheta) <= 0)
sinTheta = 0;
else
- sinTheta = FLT_SQRT(1 - (cosTheta*cosTheta));
+ sinTheta = FLT_SQRT(1 - (cosTheta * cosTheta));
- FLT Theta = FLT_ACOS(cosTheta); //Theta is half the angle between the 2 MQuaternions
+ FLT Theta = FLT_ACOS(cosTheta); // Theta is half the angle between the 2 MQuaternions
if (FLT_FABS(Theta) < DEFAULT_EPSILON)
- quatcopy( q, qa );
- else if (FLT_FABS(sinTheta) < DEFAULT_EPSILON)
- {
- quatadd( q, qa, qb );
- quatscale( q, q, 0.5 );
- }
- else
- {
+ quatcopy(q, qa);
+ else if (FLT_FABS(sinTheta) < DEFAULT_EPSILON) {
+ quatadd(q, qa, qb);
+ quatscale(q, q, 0.5);
+ } else {
FLT aside[4];
FLT bside[4];
- quatscale( bside, qb, FLT_SIN(t * Theta));
- quatscale( aside, qa, FLT_SIN((1 - t)*Theta));
- quatadd( q, aside, bside );
- quatscale( q, q, ((FLT)1.)/sinTheta );
+ quatscale(bside, qb, FLT_SIN(t * Theta));
+ quatscale(aside, qa, FLT_SIN((1 - t) * Theta));
+ quatadd(q, aside, bside);
+ quatscale(q, q, ((FLT)1.) / sinTheta);
}
}
void quatrotatevector(FLT *vec3out, const LinmathQuat quat, const FLT *vec3in) {
- //See: http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/
+ // See: http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/
FLT tmp[3];
FLT tmp2[3];
- cross3d( tmp, &quat[1], vec3in );
+ cross3d(tmp, &quat[1], vec3in);
tmp[0] += vec3in[0] * quat[0];
tmp[1] += vec3in[1] * quat[0];
tmp[2] += vec3in[2] * quat[0];
- cross3d( tmp2, &quat[1], tmp );
+ cross3d(tmp2, &quat[1], tmp);
vec3out[0] = vec3in[0] + 2 * tmp2[0];
vec3out[1] = vec3in[1] + 2 * tmp2[1];
vec3out[2] = vec3in[2] + 2 * tmp2[2];
}
-
// Matrix Stuff
-Matrix3x3 inverseM33(const Matrix3x3 mat)
-{
+Matrix3x3 inverseM33(const Matrix3x3 mat) {
Matrix3x3 newMat;
- for (int a = 0; a < 3; a++)
- {
- for (int b = 0; b < 3; b++)
- {
+ for (int a = 0; a < 3; a++) {
+ for (int b = 0; b < 3; b++) {
newMat.val[a][b] = mat.val[a][b];
}
}
- for (int i = 0; i < 3; i++)
- {
- for (int j = i + 1; j < 3; j++)
- {
+ for (int i = 0; i < 3; i++) {
+ for (int j = i + 1; j < 3; j++) {
FLT tmp = newMat.val[i][j];
newMat.val[i][j] = newMat.val[j][i];
newMat.val[j][i] = tmp;
@@ -526,8 +508,7 @@ Matrix3x3 inverseM33(const Matrix3x3 mat)
return newMat;
}
-void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3])
-{
+void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3]) {
FLT q[4];
quatfrom2vectors(q, v1, v2);
@@ -535,8 +516,7 @@ void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3])
quattomatrix33(&(m->val[0][0]), q);
}
-void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot)
-{
+void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot) {
out[0] = rot.val[0][0] * in[0] + rot.val[1][0] * in[1] + rot.val[2][0] * in[2];
out[1] = rot.val[0][1] * in[0] + rot.val[1][1] * in[1] + rot.val[2][1] * in[2];
out[2] = rot.val[0][2] * in[0] + rot.val[1][2] * in[1] + rot.val[2][2] * in[2];
@@ -544,7 +524,6 @@ void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot)
return;
}
-
// This function based on code from Object-oriented Graphics Rendering Engine
// Copyright(c) 2000 - 2012 Torus Knot Software Ltd
// under MIT license
@@ -557,8 +536,7 @@ If you call this with a dest vector that is close to the inverse
of this vector, we will rotate 180 degrees around a generated axis if
since in this case ANY axis of rotation is valid.
*/
-void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest)
-{
+void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest) {
// Based on Stan Melax's article in Game Programming Gems
// Copy, since cannot modify local
@@ -567,32 +545,26 @@ void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest)
normalize3d(v0, src);
normalize3d(v1, dest);
- FLT d = dot3d(v0, v1);// v0.dotProduct(v1);
+ FLT d = dot3d(v0, v1); // v0.dotProduct(v1);
// If dot == 1, vectors are the same
- if (d >= 1.0f)
- {
+ if (d >= 1.0f) {
quatsetnone(q);
return;
}
- if (d < (1e-6f - 1.0f))
- {
+ if (d < (1e-6f - 1.0f)) {
// Generate an axis
- FLT unitX[3] = { 1, 0, 0 };
- FLT unitY[3] = { 0, 1, 0 };
-
+ FLT unitX[3] = {1, 0, 0};
+ FLT unitY[3] = {0, 1, 0};
+
FLT axis[3];
- cross3d(axis, unitX, src); // pick an angle
- if ((axis[0] < 1.0e-35f) &&
- (axis[1] < 1.0e-35f) &&
- (axis[2] < 1.0e-35f)) // pick another if colinear
+ cross3d(axis, unitX, src); // pick an angle
+ if ((axis[0] < 1.0e-35f) && (axis[1] < 1.0e-35f) && (axis[2] < 1.0e-35f)) // pick another if colinear
{
cross3d(axis, unitY, src);
}
normalize3d(axis, axis);
quatfromaxisangle(q, axis, LINMATHPI);
- }
- else
- {
+ } else {
FLT s = FLT_SQRT((1 + d) * 2);
FLT invs = 1 / s;
@@ -608,13 +580,9 @@ void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest)
}
}
-void matrix44copy(FLT * mout, const FLT * minm )
-{
- memcpy( mout, minm, sizeof( FLT ) * 16 );
-}
+void matrix44copy(FLT *mout, const FLT *minm) { memcpy(mout, minm, sizeof(FLT) * 16); }
-void matrix44transpose(FLT * mout, const FLT * minm )
-{
+void matrix44transpose(FLT *mout, const FLT *minm) {
mout[0] = minm[0];
mout[1] = minm[4];
mout[2] = minm[8];
@@ -634,7 +602,6 @@ void matrix44transpose(FLT * mout, const FLT * minm )
mout[13] = minm[7];
mout[14] = minm[11];
mout[15] = minm[15];
-
}
void ApplyPoseToPoint(LinmathPoint3d pout, const LinmathPose *pose, const LinmathPoint3d pin) {
@@ -654,5 +621,18 @@ void InvertPose(LinmathPose *poseout, const LinmathPose *pose) {
scale3d(poseout->Pos, poseout->Pos, -1);
}
+void PoseToMatrix(FLT *matrix44, const LinmathPose *pose_in) {
+ quattomatrix(matrix44, pose_in->Rot);
+
+ /*
+ matrix44[12] = pose_in->Pos[0];
+ matrix44[13] = pose_in->Pos[1];
+ matrix44[14] = pose_in->Pos[2];
+ */
+ matrix44[3] = pose_in->Pos[0];
+ matrix44[7] = pose_in->Pos[1];
+ matrix44[11] = pose_in->Pos[2];
+}
+
LinmathQuat LinmathQuat_Identity = {1.0};
LinmathPose LinmathPose_Identity = {.Rot = {1.0}};
diff --git a/redist/linmath.h b/redist/linmath.h
index 5d5bed2..76e1322 100644
--- a/redist/linmath.h
+++ b/redist/linmath.h
@@ -1,18 +1,22 @@
-//Copyright 2013,2016 <>< C. N. Lohr. This file licensed under the terms of the MIT/x11 license.
+// Copyright 2013,2016 <>< C. N. Lohr. This file licensed under the terms of the MIT/x11 license.
#ifndef _LINMATH_H
#define _LINMATH_H
-//Yes, I know it's kind of arbitrary.
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Yes, I know it's kind of arbitrary.
#define DEFAULT_EPSILON 0.001
-//For printf
+// For printf
#define PFTHREE(x) (x)[0], (x)[1], (x)[2]
#define PFFOUR(x) (x)[0], (x)[1], (x)[2], (x)[3]
#define LINMATHPI ((FLT)3.141592653589)
-//uncomment the following line to use double precision instead of single precision.
+// uncomment the following line to use double precision instead of single precision.
//#define USE_DOUBLE
#ifdef USE_DOUBLE
@@ -20,11 +24,11 @@
#define FLT double
#define FLT_SQRT sqrt
#define FLT_TAN tan
-#define FLT_SIN sin
-#define FLT_COS cos
-#define FLT_ACOS acos
-#define FLT_ASIN asin
-#define FLT_ATAN2 atan2
+#define FLT_SIN sin
+#define FLT_COS cos
+#define FLT_ACOS acos
+#define FLT_ASIN asin
+#define FLT_ATAN2 atan2
#define FLT_FABS__ fabs
#else
@@ -32,17 +36,17 @@
#define FLT float
#define FLT_SQRT sqrtf
#define FLT_TAN tanf
-#define FLT_SIN sinf
-#define FLT_COS cosf
-#define FLT_ACOS acosf
-#define FLT_ASIN asinf
-#define FLT_ATAN2 atan2f
+#define FLT_SIN sinf
+#define FLT_COS cosf
+#define FLT_ACOS acosf
+#define FLT_ASIN asinf
+#define FLT_ATAN2 atan2f
#define FLT_FABS__ fabsf
#endif
#ifdef TCC
-#define FLT_FABS(x) (((x)<0)?(-(x)):(x))
+#define FLT_FABS(x) (((x) < 0) ? (-(x)) : (x))
#else
#define FLT_FABS FLT_FABS__
#endif
@@ -59,33 +63,33 @@ typedef struct LinmathPose {
extern LinmathQuat LinmathQuat_Identity;
extern LinmathPose LinmathPose_Identity;
-//NOTE: Inputs may never be output with cross product.
-void cross3d( FLT * out, const FLT * a, const FLT * b );
+// NOTE: Inputs may never be output with cross product.
+void cross3d(FLT *out, const FLT *a, const FLT *b);
-void sub3d( FLT * out, const FLT * a, const FLT * b );
+void sub3d(FLT *out, const FLT *a, const FLT *b);
-void add3d( FLT * out, const FLT * a, const FLT * b );
+void add3d(FLT *out, const FLT *a, const FLT *b);
-void scale3d( FLT * out, const FLT * a, FLT scalar );
+void scale3d(FLT *out, const FLT *a, FLT scalar);
-void normalize3d( FLT * out, const FLT * in );
+void normalize3d(FLT *out, const FLT *in);
-FLT dot3d( const FLT * a, const FLT * b );
+FLT dot3d(const FLT *a, const FLT *b);
-//Returns 0 if equal. If either argument is null, 0 will ALWAYS be returned.
-int compare3d( const FLT * a, const FLT * b, FLT epsilon );
+// Returns 0 if equal. If either argument is null, 0 will ALWAYS be returned.
+int compare3d(const FLT *a, const FLT *b, FLT epsilon);
-void copy3d( FLT * out, const FLT * in );
+void copy3d(FLT *out, const FLT *in);
-FLT magnitude3d(const FLT * a );
-
-FLT anglebetween3d( FLT * a, FLT * b );
+FLT magnitude3d(const FLT *a);
+FLT dist3d(const FLT *a, const FLT *b);
+FLT anglebetween3d(FLT *a, FLT *b);
void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle);
void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest);
void axisanglefromquat(FLT *angle, FLT *axis, LinmathQuat quat);
-//Quaternion things...
+// Quaternion things...
typedef FLT LinmathEulerAngle[3];
@@ -126,10 +130,10 @@ void ApplyPoseToPose(LinmathPose *pout, const LinmathPose *lhs_pose, const Linma
// by definition.
void InvertPose(LinmathPose *poseout, const LinmathPose *pose_in);
+void PoseToMatrix(FLT *mat44, const LinmathPose *pose_in);
// Matrix Stuff
-typedef struct
-{
+typedef struct {
FLT val[3][3]; // row, column
} Matrix3x3;
@@ -137,12 +141,11 @@ void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot);
void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3]);
Matrix3x3 inverseM33(const Matrix3x3 mat);
+void matrix44copy(FLT *mout, const FLT *minm);
+void matrix44transpose(FLT *mout, const FLT *minm);
-void matrix44copy(FLT * mout, const FLT * minm );
-void matrix44transpose(FLT * mout, const FLT * minm );
-
-
+#ifdef __cplusplus
+}
#endif
-
-
+#endif
diff --git a/redist/minimal_opencv.c b/redist/minimal_opencv.c
index 50eb7df..988dd0f 100644
--- a/redist/minimal_opencv.c
+++ b/redist/minimal_opencv.c
@@ -1,5 +1,3 @@
-//#include "/home/justin/source/CLAPACK/INCLUDE/f2c.h"
-//#include "/home/justin/source/CLAPACK/INCLUDE/clapack.h"
#include <cblas.h>
#include <lapacke.h>
@@ -10,9 +8,15 @@
#include "string.h"
#include <limits.h>
-//#define DEBUG_PRINT
+#include <stdarg.h>
-int cvRound(float f) { return roundf(f); }
+#ifdef _WIN32
+#define SURVIVE_LOCAL_ONLY
+#else
+#define SURVIVE_LOCAL_ONLY __attribute__((visibility("hidden")))
+#endif
+
+SURVIVE_LOCAL_ONLY int cvRound(float f) { return roundf(f); }
#define CV_Error(code, msg) assert(0 && msg); // cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
const int DECOMP_SVD = 1;
@@ -20,11 +24,12 @@ const int DECOMP_LU = 2;
void print_mat(const CvMat *M);
-void cvCopyTo(const CvMat *srcarr, CvMat *dstarr) {
+SURVIVE_LOCAL_ONLY void cvCopyTo(const CvMat *srcarr, CvMat *dstarr) {
memcpy(dstarr->data.db, srcarr->data.db, sizeof(double) * dstarr->rows * dstarr->cols);
}
-void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src3, double beta, CvMat *dst, int tABC) {
+SURVIVE_LOCAL_ONLY void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src3, double beta,
+ CvMat *dst, int tABC) {
lapack_int rows1 = src1->rows;
lapack_int cols1 = src1->cols;
@@ -48,7 +53,7 @@ void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src
lda, src2->data.db, ldb, beta, dst->data.db, dst->cols);
}
-void cvMulTransposed(const CvMat *src, CvMat *dst, int order, const CvMat *delta, double scale) {
+SURVIVE_LOCAL_ONLY void cvMulTransposed(const CvMat *src, CvMat *dst, int order, const CvMat *delta, double scale) {
lapack_int rows = src->rows;
lapack_int cols = src->cols;
@@ -67,14 +72,14 @@ void cvMulTransposed(const CvMat *src, CvMat *dst, int order, const CvMat *delta
scale, src->data.db, cols, src->data.db, cols, beta, dst->data.db, dstCols);
}
-void *cvAlloc(size_t size) { return malloc(size); }
+SURVIVE_LOCAL_ONLY void *cvAlloc(size_t size) { return malloc(size); }
static void icvCheckHuge(CvMat *arr) {
if ((int64_t)arr->step * arr->rows > INT_MAX)
arr->type &= ~CV_MAT_CONT_FLAG;
}
-CvMat *cvCreateMatHeader(int rows, int cols, int type) {
+SURVIVE_LOCAL_ONLY CvMat *cvCreateMatHeader(int rows, int cols, int type) {
type = CV_MAT_TYPE(type);
assert(!(rows < 0 || cols < 0));
@@ -116,7 +121,7 @@ static inline int cvAlign(int size, int align) {
return (size + align - 1) & -align;
}
-void cvCreateData(CvMat *arr) {
+SURVIVE_LOCAL_ONLY void cvCreateData(CvMat *arr) {
if (CV_IS_MAT_HDR_Z(arr)) {
size_t step, total_size;
CvMat *mat = (CvMat *)arr;
@@ -144,14 +149,14 @@ void cvCreateData(CvMat *arr) {
CV_Error(CV_StsBadArg, "unrecognized or unsupported array type");
}
-CvMat *cvCreateMat(int height, int width, int type) {
+SURVIVE_LOCAL_ONLY CvMat *cvCreateMat(int height, int width, int type) {
CvMat *arr = cvCreateMatHeader(height, width, type);
cvCreateData(arr);
return arr;
}
-double cvInvert(const CvMat *srcarr, CvMat *dstarr, int method) {
+SURVIVE_LOCAL_ONLY double cvInvert(const CvMat *srcarr, CvMat *dstarr, int method) {
lapack_int inf;
lapack_int rows = srcarr->rows;
lapack_int cols = srcarr->cols;
@@ -206,13 +211,13 @@ double cvInvert(const CvMat *srcarr, CvMat *dstarr, int method) {
return 0;
}
-CvMat *cvCloneMat(const CvMat *mat) {
+SURVIVE_LOCAL_ONLY CvMat *cvCloneMat(const CvMat *mat) {
CvMat *rtn = cvCreateMat(mat->rows, mat->cols, mat->type);
cvCopyTo(mat, rtn);
return rtn;
}
-int cvSolve(const CvMat *Aarr, const CvMat *xarr, CvMat *Barr, int method) {
+SURVIVE_LOCAL_ONLY int cvSolve(const CvMat *Aarr, const CvMat *xarr, CvMat *Barr, int method) {
lapack_int inf;
lapack_int arows = Aarr->rows;
lapack_int acols = Aarr->cols;
@@ -288,7 +293,7 @@ int cvSolve(const CvMat *Aarr, const CvMat *xarr, CvMat *Barr, int method) {
return 0;
}
-void cvTranspose(const CvMat *M, CvMat *dst) {
+SURVIVE_LOCAL_ONLY void cvTranspose(const CvMat *M, CvMat *dst) {
bool inPlace = M == dst || M->data.db == dst->data.db;
double *src = M->data.db;
@@ -311,7 +316,7 @@ void cvTranspose(const CvMat *M, CvMat *dst) {
}
}
-void cvSVD(CvMat *aarr, CvMat *warr, CvMat *uarr, CvMat *varr, int flags) {
+SURVIVE_LOCAL_ONLY void cvSVD(CvMat *aarr, CvMat *warr, CvMat *uarr, CvMat *varr, int flags) {
char jobu = 'A';
char jobvt = 'A';
@@ -349,13 +354,13 @@ void cvSVD(CvMat *aarr, CvMat *warr, CvMat *uarr, CvMat *varr, int flags) {
}
}
-void cvSetZero(CvMat *arr) {
+SURVIVE_LOCAL_ONLY void cvSetZero(CvMat *arr) {
for (int i = 0; i < arr->rows; i++)
for (int j = 0; j < arr->cols; j++)
arr->data.db[i * arr->cols + j] = 0;
}
-void cvReleaseMat(CvMat **mat) {
+SURVIVE_LOCAL_ONLY void cvReleaseMat(CvMat **mat) {
assert(*(*mat)->refcount == 1);
free((*mat)->refcount);
free(*mat);
diff --git a/redist/os_generic.c b/redist/os_generic.c
deleted file mode 100644
index 3191357..0000000
--- a/redist/os_generic.c
+++ /dev/null
@@ -1,337 +0,0 @@
-#include "os_generic.h"
-
-#ifdef USE_WINDOWS
-
-#include <windows.h>
-
-void OGSleep( int is )
-{
- Sleep( is*1000 );
-}
-
-void OGUSleep( int ius )
-{
- Sleep( ius/1000 );
-}
-
-double OGGetAbsoluteTime()
-{
- static LARGE_INTEGER lpf;
- LARGE_INTEGER li;
-
- if( !lpf.QuadPart )
- {
- QueryPerformanceFrequency( &lpf );
- }
-
- QueryPerformanceCounter( &li );
- return (double)li.QuadPart / (double)lpf.QuadPart;
-}
-
-
-double OGGetFileTime( const char * file )
-{
- FILETIME ft;
-
- HANDLE h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
-
- if( h==INVALID_HANDLE_VALUE )
- return -1;
-
- GetFileTime( h, 0, 0, &ft );
-
- CloseHandle( h );
-
- return ft.dwHighDateTime + ft.dwLowDateTime;
-}
-
-
-og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter )
-{
- return (og_thread_t)CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)routine, parameter, 0, 0 );
-}
-
-void * OGJoinThread( og_thread_t ot )
-{
- WaitForSingleObject( ot, INFINITE );
- CloseHandle( ot );
- return 0;
-}
-
-void OGCancelThread( og_thread_t ot )
-{
- CloseHandle( ot );
-}
-
-og_mutex_t OGCreateMutex()
-{
- return CreateMutex( 0, 0, 0 );
-}
-
-void OGLockMutex( og_mutex_t om )
-{
- WaitForSingleObject(om, INFINITE);
-}
-
-void OGUnlockMutex( og_mutex_t om )
-{
- ReleaseMutex(om);
-}
-
-void OGDeleteMutex( og_mutex_t om )
-{
- CloseHandle( om );
-}
-
-
-
-og_sema_t OGCreateSema()
-{
- HANDLE sem = CreateSemaphore( 0, 0, 32767, 0 );
- return (og_sema_t)sem;
-}
-
-int OGGetSema( og_sema_t os )
-{
- typedef LONG NTSTATUS;
- HANDLE sem = (HANDLE)os;
- typedef NTSTATUS (NTAPI *_NtQuerySemaphore)(
- HANDLE SemaphoreHandle,
- DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */
- PVOID SemaphoreInformation, /* but this is to much to dump here */
- ULONG SemaphoreInformationLength,
- PULONG ReturnLength OPTIONAL
- );
-
- typedef struct _SEMAPHORE_BASIC_INFORMATION {
- ULONG CurrentCount;
- ULONG MaximumCount;
- } SEMAPHORE_BASIC_INFORMATION;
-
-
- static _NtQuerySemaphore NtQuerySemaphore;
- SEMAPHORE_BASIC_INFORMATION BasicInfo;
- NTSTATUS Status;
-
- if( !NtQuerySemaphore )
- {
- NtQuerySemaphore = (_NtQuerySemaphore)GetProcAddress (GetModuleHandle ("ntdll.dll"), "NtQuerySemaphore");
- if( !NtQuerySemaphore )
- {
- return -1;
- }
- }
-
-
- Status = NtQuerySemaphore (sem, 0 /*SemaphoreBasicInformation*/,
- &BasicInfo, sizeof (SEMAPHORE_BASIC_INFORMATION), NULL);
-
- if (Status == ERROR_SUCCESS)
- {
- return BasicInfo.CurrentCount;
- }
-
- return -2;
-}
-
-void OGLockSema( og_sema_t os )
-{
- WaitForSingleObject( (HANDLE)os, INFINITE );
-}
-
-void OGUnlockSema( og_sema_t os )
-{
- ReleaseSemaphore( (HANDLE)os, 1, 0 );
-}
-
-void OGDeleteSema( og_sema_t os )
-{
- CloseHandle( os );
-}
-
-#else
-
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE
-#endif
-
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <sys/time.h>
-#include <semaphore.h>
-#include <unistd.h>
-
-pthread_mutex_t g_RawMutexStart = PTHREAD_MUTEX_INITIALIZER;
-
-void OGSleep( int is )
-{
- sleep( is );
-}
-
-void OGUSleep( int ius )
-{
- usleep( ius );
-}
-
-double OGGetAbsoluteTime()
-{
- struct timeval tv;
- gettimeofday( &tv, 0 );
- return ((double)tv.tv_usec)/1000000. + (tv.tv_sec);
-}
-
-double OGGetFileTime( const char * file )
-{
- struct stat buff;
-
- int r = stat( file, &buff );
-
- if( r < 0 )
- {
- return -1;
- }
-
- return buff.st_mtime;
-}
-
-
-
-og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter )
-{
- pthread_t * ret = (pthread_t *)malloc( sizeof( pthread_t ) );
- int r = pthread_create( ret, 0, routine, parameter );
- if( r )
- {
- free( ret );
- return 0;
- }
- return (og_thread_t)ret;
-}
-
-void * OGJoinThread( og_thread_t ot )
-{
- void * retval;
- if( !ot )
- {
- return 0;
- }
- pthread_join( *(pthread_t*)ot, &retval );
- free( ot );
- return retval;
-}
-
-void OGCancelThread( og_thread_t ot )
-{
- if( !ot )
- {
- return;
- }
- pthread_cancel( *(pthread_t*)ot );
- free( ot );
-}
-
-og_mutex_t OGCreateMutex()
-{
- pthread_mutexattr_t mta;
- og_mutex_t r = malloc( sizeof( pthread_mutex_t ) );
-
- pthread_mutexattr_init(&mta);
- pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
-
- pthread_mutex_init( (pthread_mutex_t *)r, &mta );
-
- return r;
-}
-
-void OGLockMutex( og_mutex_t om )
-{
- if( !om )
- {
- return;
- }
- pthread_mutex_lock( (pthread_mutex_t*)om );
-}
-
-void OGUnlockMutex( og_mutex_t om )
-{
- if( !om )
- {
- return;
- }
- pthread_mutex_unlock( (pthread_mutex_t*)om );
-}
-
-void OGDeleteMutex( og_mutex_t om )
-{
- if( !om )
- {
- return;
- }
-
- pthread_mutex_destroy( (pthread_mutex_t*)om );
- free( om );
-}
-
-
-
-
-og_sema_t OGCreateSema()
-{
- sem_t * sem = (sem_t *)malloc( sizeof( sem_t ) );
- sem_init( sem, 0, 0 );
- return (og_sema_t)sem;
-}
-
-int OGGetSema( og_sema_t os )
-{
- int valp;
- sem_getvalue( (sem_t *)os, &valp );
- return valp;
-}
-
-
-void OGLockSema( og_sema_t os )
-{
- sem_wait( (sem_t *)os );
-}
-
-void OGUnlockSema( og_sema_t os )
-{
- sem_post( (sem_t *)os );
-}
-
-void OGDeleteSema( og_sema_t os )
-{
- sem_destroy( (sem_t *)os );
- free(os);
-}
-
-
-
-#endif
-
-//Date Stamp: 2012-02-15
-
-/*
- Copyright (c) 2011-2012 <>< Charles Lohr
-
- Permission is hereby granted, free of charge, to any person obtaining a
- copy of this software and associated documentation files (the "Software"),
- to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense,
- and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of this file.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- IN THE SOFTWARE.
-*/
-
diff --git a/redist/os_generic.h b/redist/os_generic.h
index 0924030..0d1c7e7 100644
--- a/redist/os_generic.h
+++ b/redist/os_generic.h
@@ -1,76 +1,293 @@
-#ifndef _OS_GENERIC_H
-#define _OS_GENERIC_H
-
-#if defined( WIN32 ) || defined (WINDOWS) || defined( _WIN32)
-#define USE_WINDOWS
-#endif
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//Things that shouldn't be macro'd
-double OGGetAbsoluteTime();
-void OGSleep( int is );
-void OGUSleep( int ius );
-double OGGetFileTime( const char * file );
-
-//Threads and Mutices
-typedef void* og_thread_t;
-typedef void* og_mutex_t;
-typedef void* og_sema_t;
-
-og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter );
-void * OGJoinThread( og_thread_t ot );
-void OGCancelThread( og_thread_t ot );
-
-//Always a recrusive mutex.
-og_mutex_t OGCreateMutex();
-void OGLockMutex( og_mutex_t om );
-void OGUnlockMutex( og_mutex_t om );
-void OGDeleteMutex( og_mutex_t om );
-
-//Always a semaphore
-og_sema_t OGCreateSema(); //Create a semaphore, comes locked initially. NOTE: Max count is 32767
-void OGLockSema( og_sema_t os );
-int OGGetSema( og_sema_t os ); //if <0 there was a failure.
-void OGUnlockSema( og_sema_t os );
-void OGDeleteSema( og_sema_t os );
-
-#ifdef __cplusplus
-};
-#endif
-
-
-
-#endif
-
-
-//Date Stamp: 2012-02-15
-
-/*
- NOTE: Portions (namely the top section) are part of headers from other
- sources.
-
- Copyright (c) 2011-2012 <>< Charles Lohr
-
- Permission is hereby granted, free of charge, to any person obtaining a
- copy of this software and associated documentation files (the "Software"),
- to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense,
- and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of this file.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- IN THE SOFTWARE.
-*/
-
+#ifndef _OS_GENERIC_H
+#define _OS_GENERIC_H
+/*
+ "osgeneric" Generic, platform independent tool for the following operations:
+
+ Delay functions:
+ void OGSleep( int is );
+ void OGUSleep( int ius );
+
+ Getting current time (may be time from program start, boot, or epoc)
+ double OGGetAbsoluteTime();
+ double OGGetFileTime( const char * file );
+
+ Thread functions
+ og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter );
+ void * OGJoinThread( og_thread_t ot );
+ void OGCancelThread( og_thread_t ot );
+
+ Mutex functions, used for protecting data structures.
+ (recursive on platforms where available.)
+ og_mutex_t OGCreateMutex();
+ void OGLockMutex( og_mutex_t om );
+ void OGUnlockMutex( og_mutex_t om );
+ void OGDeleteMutex( og_mutex_t om );
+
+//Always a semaphore (not recursive)
+// og_sema_t OGCreateSema(); //Create a semaphore, comes locked initially. NOTE: Max count is 32767
+// void OGLockSema( og_sema_t os );
+// int OGGetSema( og_sema_t os ); //if <0 there was a failure.
+// void OGUnlockSema( og_sema_t os );
+// void OGDeleteSema( og_sema_t os );
+
+
+
+ Copyright (c) 2011-2012,2013,2016,2018 <>< Charles Lohr
+ This file may be licensed under the MIT/x11 license or the NewBSD license.
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of this file.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+
+ Date Stamp: 2018-03-25: Switched to header-only format.
+*/
+
+#define OSG_INLINE static inline
+
+// Threads and Mutices
+typedef void *og_thread_t;
+typedef void *og_mutex_t;
+typedef void *og_sema_t;
+
+#if defined(WIN32) || defined(WINDOWS) || defined(_WIN32)
+#define USE_WINDOWS
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef USE_WINDOWS
+
+#include <windows.h>
+
+OSG_INLINE void OGSleep(int is) { Sleep(is * 1000); }
+
+OSG_INLINE void OGUSleep(int ius) { Sleep(ius / 1000); }
+
+OSG_INLINE double OGGetAbsoluteTime() {
+ static LARGE_INTEGER lpf;
+ LARGE_INTEGER li;
+
+ if (!lpf.QuadPart) {
+ QueryPerformanceFrequency(&lpf);
+ }
+
+ QueryPerformanceCounter(&li);
+ return (double)li.QuadPart / (double)lpf.QuadPart;
+}
+
+OSG_INLINE double OGGetFileTime(const char *file) {
+ FILETIME ft;
+
+ HANDLE h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (h == INVALID_HANDLE_VALUE)
+ return -1;
+
+ GetFileTime(h, 0, 0, &ft);
+
+ CloseHandle(h);
+
+ return ft.dwHighDateTime + ft.dwLowDateTime;
+}
+
+OSG_INLINE og_thread_t OGCreateThread(void *(routine)(void *), void *parameter) {
+ return (og_thread_t)CreateThread(0, 0, (LPTHREAD_START_ROUTINE)routine, parameter, 0, 0);
+}
+
+OSG_INLINE void *OGJoinThread(og_thread_t ot) {
+ WaitForSingleObject(ot, INFINITE);
+ CloseHandle(ot);
+ return 0;
+}
+
+OSG_INLINE void OGCancelThread(og_thread_t ot) { CloseHandle(ot); }
+
+OSG_INLINE og_mutex_t OGCreateMutex() { return CreateMutex(0, 0, 0); }
+
+OSG_INLINE void OGLockMutex(og_mutex_t om) { WaitForSingleObject(om, INFINITE); }
+
+OSG_INLINE void OGUnlockMutex(og_mutex_t om) { ReleaseMutex(om); }
+
+OSG_INLINE void OGDeleteMutex(og_mutex_t om) { CloseHandle(om); }
+
+OSG_INLINE og_sema_t OGCreateSema() {
+ HANDLE sem = CreateSemaphore(0, 0, 32767, 0);
+ return (og_sema_t)sem;
+}
+
+OSG_INLINE int OGGetSema(og_sema_t os) {
+ typedef LONG NTSTATUS;
+ HANDLE sem = (HANDLE)os;
+ typedef NTSTATUS(NTAPI * _NtQuerySemaphore)(
+ HANDLE SemaphoreHandle, DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */
+ PVOID SemaphoreInformation, /* but this is to much to dump here */
+ ULONG SemaphoreInformationLength, PULONG ReturnLength OPTIONAL);
+
+ typedef struct _SEMAPHORE_BASIC_INFORMATION {
+ ULONG CurrentCount;
+ ULONG MaximumCount;
+ } SEMAPHORE_BASIC_INFORMATION;
+
+ static _NtQuerySemaphore NtQuerySemaphore;
+ SEMAPHORE_BASIC_INFORMATION BasicInfo;
+ NTSTATUS Status;
+
+ if (!NtQuerySemaphore) {
+ NtQuerySemaphore = (_NtQuerySemaphore)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySemaphore");
+ if (!NtQuerySemaphore) {
+ return -1;
+ }
+ }
+
+ Status =
+ NtQuerySemaphore(sem, 0 /*SemaphoreBasicInformation*/, &BasicInfo, sizeof(SEMAPHORE_BASIC_INFORMATION), NULL);
+
+ if (Status == ERROR_SUCCESS) {
+ return BasicInfo.CurrentCount;
+ }
+
+ return -2;
+}
+
+OSG_INLINE void OGLockSema(og_sema_t os) { WaitForSingleObject((HANDLE)os, INFINITE); }
+
+OSG_INLINE void OGUnlockSema(og_sema_t os) { ReleaseSemaphore((HANDLE)os, 1, 0); }
+
+OSG_INLINE void OGDeleteSema(og_sema_t os) { CloseHandle(os); }
+
+#else
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+OSG_INLINE void OGSleep(int is) { sleep(is); }
+
+OSG_INLINE void OGUSleep(int ius) { usleep(ius); }
+
+OSG_INLINE double OGGetAbsoluteTime() {
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ return ((double)tv.tv_usec) / 1000000. + (tv.tv_sec);
+}
+
+OSG_INLINE double OGGetFileTime(const char *file) {
+ struct stat buff;
+
+ int r = stat(file, &buff);
+
+ if (r < 0) {
+ return -1;
+ }
+
+ return buff.st_mtime;
+}
+
+OSG_INLINE og_thread_t OGCreateThread(void *(routine)(void *), void *parameter) {
+ pthread_t *ret = malloc(sizeof(pthread_t));
+ int r = pthread_create(ret, 0, routine, parameter);
+ if (r) {
+ free(ret);
+ return 0;
+ }
+ return (og_thread_t)ret;
+}
+
+OSG_INLINE void *OGJoinThread(og_thread_t ot) {
+ void *retval;
+ if (!ot) {
+ return 0;
+ }
+ pthread_join(*(pthread_t *)ot, &retval);
+ free(ot);
+ return retval;
+}
+
+OSG_INLINE void OGCancelThread(og_thread_t ot) {
+ if (!ot) {
+ return;
+ }
+ pthread_cancel(*(pthread_t *)ot);
+ free(ot);
+}
+
+OSG_INLINE og_mutex_t OGCreateMutex() {
+ pthread_mutexattr_t mta;
+ og_mutex_t r = malloc(sizeof(pthread_mutex_t));
+
+ pthread_mutexattr_init(&mta);
+ pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
+
+ pthread_mutex_init((pthread_mutex_t *)r, &mta);
+
+ return r;
+}
+
+OSG_INLINE void OGLockMutex(og_mutex_t om) {
+ if (!om) {
+ return;
+ }
+ pthread_mutex_lock((pthread_mutex_t *)om);
+}
+
+OSG_INLINE void OGUnlockMutex(og_mutex_t om) {
+ if (!om) {
+ return;
+ }
+ pthread_mutex_unlock((pthread_mutex_t *)om);
+}
+
+OSG_INLINE void OGDeleteMutex(og_mutex_t om) {
+ if (!om) {
+ return;
+ }
+
+ pthread_mutex_destroy((pthread_mutex_t *)om);
+ free(om);
+}
+
+OSG_INLINE og_sema_t OGCreateSema() {
+ sem_t *sem = malloc(sizeof(sem_t));
+ sem_init(sem, 0, 0);
+ return (og_sema_t)sem;
+}
+
+OSG_INLINE int OGGetSema(og_sema_t os) {
+ int valp;
+ sem_getvalue(os, &valp);
+ return valp;
+}
+
+OSG_INLINE void OGLockSema(og_sema_t os) { sem_wait(os); }
+
+OSG_INLINE void OGUnlockSema(og_sema_t os) { sem_post(os); }
+
+OSG_INLINE void OGDeleteSema(og_sema_t os) {
+ sem_destroy(os);
+ free(os);
+}
+
+#endif
+
+#endif
diff --git a/redist/symbol_enumerator.c b/redist/symbol_enumerator.c
index fcb3727..31bb68e 100644
--- a/redist/symbol_enumerator.c
+++ b/redist/symbol_enumerator.c
@@ -60,13 +60,9 @@ BOOL WINAPI SymCleanup(
HANDLE hProcess
);
-BOOL CALLBACK __cdecl mycb(
- PSYMBOL_INFO pSymInfo,
- ULONG SymbolSize,
- PVOID UserContext
- ){
- SymEnumeratorCallback cb = (SymEnumeratorCallback)UserContext;
- return !cb( "", &pSymInfo->Name[0], (void*)pSymInfo->Address, (long) pSymInfo->Size );
+BOOL mycb(PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext) {
+ SymEnumeratorCallback cb = (SymEnumeratorCallback)UserContext;
+ return !cb("", &pSymInfo->Name[0], (void *)pSymInfo->Address, (long)pSymInfo->Size);
}
int EnumerateSymbols( SymEnumeratorCallback cb )
@@ -75,6 +71,7 @@ int EnumerateSymbols( SymEnumeratorCallback cb )
if( !SymInitialize( proc, 0, 1 ) ) return -1;
if( !SymEnumSymbols( proc, 0, "*!*", &mycb, (void*)cb ) )
{
+ fprintf(stderr, "SymEnumSymbols returned %d\n", GetLastError());
SymCleanup(proc);
return -2;
}