Major rework of headers inclusion style on behalf of lebedev.ri (issue 1079)

This commit is contained in:
michael 2011-12-17 12:08:57 -05:00
parent d5c07f18b5
commit bf71a01ca5
303 changed files with 1180 additions and 6702 deletions

View File

@ -62,6 +62,7 @@ if (APPLE)
SET (CMAKE_OSX_DEPLOYMENT_TARGET "10.5")
endif (APPLE)
option(USE_CLANG "Build rawtherapee with clang" OFF)
option (AUTOMATED_BUILD_SYSTEM "TRUE if built by an automate" OFF)
option (BUILD_SHARED "Build rawtherapee with shared libraries" OFF)
@ -306,6 +307,40 @@ if (OPTION_OMP)
endif (OPENMP_FOUND)
endif (OPTION_OMP)
if(USE_CLANG)
find_file(CLANG_CMD clang)
find_file(CLANGPP_CMD clang++)
if ((CLANG_CMD STREQUAL CLANG_CMD-NOTFOUND) OR (CLANGPP_CMD STREQUAL CLANGPP_CMD-NOTFOUND))
message(FATAL_ERROR "clang not found! auto-disabling option USE_CLANG")
else ((CLANG_CMD STREQUAL CLANG_CMD-NOTFOUND) OR (CLANGPP_CMD STREQUAL CLANGPP_CMD-NOTFOUND))
message(STATUS "clang found: ${CLANG_CMD}")
message(STATUS "clang++ found: ${CLANGPP_CMD}")
SET (CMAKE_C_COMPILER ${CLANG_CMD})
SET (CMAKE_C_FLAGS "") #-Wall
SET (CMAKE_C_FLAGS_DEBUG "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_CXX_COMPILER ${CLANGPP_CMD})
SET (CMAKE_CXX_FLAGS "") #-Wall
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
endif ((CLANG_CMD STREQUAL CLANG_CMD-NOTFOUND) OR (CLANGPP_CMD STREQUAL CLANGPP_CMD-NOTFOUND))
find_file(LDGOLD_CMD ld.gold)
if (LDGOLD_CMD STREQUAL LDGOLD_CMD-NOTFOUND)
message(FATAL_ERROR "ld.gold not found! using standard linker")
else (LDGOLD_CMD STREQUAL LDGOLD_CMD-NOTFOUND)
message(STATUS "ld.gold found: ${LDGOLD_CMD}")
SET (CMAKE_LINKER LDGOLD_CMD)
endif (LDGOLD_CMD STREQUAL LDGOLD_CMD-NOTFOUND)
endif(USE_CLANG)
install (FILES AUTHORS.txt DESTINATION ${CREDITSDIR})
install (FILES LICENSE.txt DESTINATION ${LICENCEDIR})
install (FILES AboutThisBuild.txt DESTINATION ${CREDITSDIR})

View File

@ -1,5 +1,5 @@
#!/bin/sh
rm -v CMakeCache.txt
find -name CMakeCache.txt -delete
rm -v install_manifest.txt
rm -vr ./CMakeFiles

View File

@ -1,8 +1,6 @@
include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../rtexif
${EXTRA_INCDIR} ${GTHREAD_INCLUDE_DIRS} ${GOBJECT_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS}
include_directories (${EXTRA_INCDIR} ${GTHREAD_INCLUDE_DIRS} ${GOBJECT_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS}
${GLIBMM_INCLUDE_DIRS} ${IPTCDATA_INCLUDE_DIRS} ${LCMS_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/../rtgui ${GTKMM_INCLUDE_DIRS} ${GTK_INCLUDE_DIRS})
${GTKMM_INCLUDE_DIRS} ${GTK_INCLUDE_DIRS})
link_directories (${CMAKE_CURRENT_SOURCE_DIR}/../rtexif ${EXTRA_LIBDIR} ${GTHREAD_LIBRARY_DIRS}
${GOBJECT_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${GLIBMM_LIBRARY_DIRS}
${IPTCDATA_LIBRARY_DIRS} ${LCMS_LIBRARY_DIRS})
@ -10,15 +8,15 @@ link_directories (${CMAKE_CURRENT_SOURCE_DIR}/../rtexif ${EXTRA_LIBDIR} ${GTHREA
set (RTENGINESOURCEFILES safegtk.cc colortemp.cc curves.cc flatcurves.cc diagonalcurves.cc dcraw.cc iccstore.cc
dfmanager.cc ffmanager.cc rawimage.cc image8.cc image16.cc imagefloat.cc imagedata.cc imageio.cc improcfun.cc init.cc dcrop.cc
loadinitial.cc procparams.cc rawimagesource.cc demosaic_algos.cc shmap.cc simpleprocess.cc refreshmap.cc
stdimagesource.cc myfile.cc iccjpeg.c hlmultipliers.cc improccoordinator.cc
stdimagesource.cc myfile.cc iccjpeg.cc hlmultipliers.cc improccoordinator.cc
processingjob.cc rtthumbnail.cc utils.cc labimage.cc slicer.cc
iplab2rgb.cc ipsharpen.cc iptransform.cc ipresize.cc ipvibrance.cc
jpeg_memsrc.c jdatasrc.c
jpeg_memsrc.cc jdatasrc.cc
PF_correct_RT.cc
dirpyrLab_denoise.cc dirpyrLab_equalizer.cc dirpyr_equalizer.cc
calc_distort.c
klt/convolve.c klt/error.c klt/klt.c klt/klt_util.c klt/pnmio.c klt/pyramid.c klt/selectGoodFeatures.c
klt/storeFeatures.c klt/trackFeatures.c klt/writeFeatures.c
calc_distort.cc
klt/convolve.cc klt/error.cc klt/klt.cc klt/klt_util.cc klt/pnmio.cc klt/pyramid.cc klt/selectGoodFeatures.cc
klt/storeFeatures.cc klt/trackFeatures.cc klt/writeFeatures.cc
)
add_library (rtengine ${RTENGINESOURCEFILES})

View File

@ -35,11 +35,11 @@ It's likely that I'll take apart and rerelease contents of this file (in the dis
and rather supporting material. SparseConjugateGradient alone is a workhorse I and a few others have been exploiting for a few years.
EdgePreservingDecomposition.h and EdgePreservingDecomposition.cpp are released under the following licence:
It's free.
You may not incorporate this code as part of proprietary or commercial software, but via freeware you may use its output for profit.
You may modify and redistribute, but keep this big comment block intact and not for profit in any way unless I give specific permission.
If you're unsure about anything else, treat as public domain.
Don't be a dick.
<EFBFBD> It's free.
<EFBFBD> You may not incorporate this code as part of proprietary or commercial software, but via freeware you may use its output for profit.
<EFBFBD> You may modify and redistribute, but keep this big comment block intact and not for profit in any way unless I give specific permission.
<EFBFBD> If you're unsure about anything else, treat as public domain.
<EFBFBD> Don't be a dick.
My email address is my screen name followed by @yahoo.com. I'm also known as ben_s or nonbasketless. Enjoy!
*/
@ -47,8 +47,8 @@ My email address is my screen name followed by @yahoo.com. I'm also known as ben
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
//This is for solving big symmetric positive definite linear problems.

View File

@ -65,6 +65,8 @@
#define LUTi LUT<int>
#define LUTu LUT<unsigned int>
#include <cstring>
template<typename T>
class LUT {
private:

View File

@ -25,11 +25,11 @@
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//#include <rtengine.h>
//#include <math.h>
#include <gauss.h>
//#include <bilateral2.h>
#include <improcfun.h>
//#include "rtengine.h"
//#include <cmath>
#include "gauss.h"
//#include "bilateral2.h"
#include "improcfun.h"
#ifdef _OPENMP
#include <omp.h>

View File

@ -55,7 +55,7 @@
#ifndef ARRAY2D_H_
#define ARRAY2D_H_
#include <csignal> // for raise()
#include <assert.h>
#include <cassert>
// flags for use
#define ARRAY2D_LOCK_DATA 1

View File

@ -19,12 +19,12 @@
#ifndef _BILATERAL2_
#define _BILATERAL2_
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <alignedbuffer.h>
#include <mytime.h>
#include <gauss.h>
#include <cmath>
#include <cstring>
#include <cstdio>
#include "alignedbuffer.h"
#include "mytime.h"
#include "gauss.h"
#include <glibmm.h>
#ifdef _OPENMP
#include <omp.h>

View File

@ -16,9 +16,9 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <cstring>
#include <cstdio>
#define MAXVAL 65535.0
#define CLIP(a) ((a)>0.0?((a)<MAXVAL?(a):MAXVAL):0.0)

View File

@ -1,228 +0,0 @@
/**********************************************************************
Finds the N_FEATURES best features in an image, and tracks these
features to the next image. Saves the feature
locations (before and after tracking) to text files and to PPM files,
and prints the features to the screen.
**********************************************************************/
#include "klt/pnmio.h"
#include "klt/klt.h"
#include "math.h"
#define N_FEATURES 100
#define DELTA_1 0.05
#define DELTA_2 0.01
#define RXY_LIMIT 0.6
#define CENTER_R 0.3
//#define DEBUG_IMG
#ifdef DEBUG_IMG
void drawDotXY(unsigned char* img, int ncols, int nrows, int x, int y, int color)
{
img[x+y*ncols] = color;
}
void drawDot(unsigned char* img, int ncols, int nrows, double r0, double r10, int color)
{
if (r0>=0 && r0<1 && r10 >=0.8 && r10 <1.2)
drawDotXY (img, ncols, nrows, (int)(r0*ncols), (int)((r10-0.8)*2.5*nrows), color);
}
#endif
double calcDistortion(unsigned char* img1, unsigned char* img2, int ncols, int nrows)
{
KLT_TrackingContext tc;
KLT_FeatureList fl;
KLT_FeatureTable ft;
int nFeatures = N_FEATURES;
int i,n;
double radius, wc, hc;
double r0[N_FEATURES] = {0.0};
double r10[N_FEATURES] = {0.0};
tc = KLTCreateTrackingContext();
//tc->mindist = 20;
tc->lighting_insensitive = TRUE;
tc->nSkippedPixels = 5;
tc->step_factor = 2.0;
tc->max_iterations = 20;
//KLTPrintTrackingContext(tc);
fl = KLTCreateFeatureList(N_FEATURES);
ft = KLTCreateFeatureTable(2, N_FEATURES);
radius = sqrt(ncols*ncols+nrows*nrows)/2.0;
wc=((double)ncols)/2.0-0.5;
hc=((double)nrows)/2.0-0.5;
KLTSelectGoodFeatures(tc, img1, ncols, nrows, fl);
KLTStoreFeatureList(fl, ft, 0);
KLTTrackFeatures(tc, img1, img2, ncols, nrows, fl);
KLTStoreFeatureList(fl, ft, 1);
// add a shade to img2, we want to draw something on top of it.
for (i=0;i<ncols*nrows;i++) {
img2[i]=(img2[i]/2)+16;
}
// find the best comp and scale when assume r1 = r0*(1.0-comp+(r0*comp))*scale;
n=0;
double total_r10=0.0, total_r0=0.0;
for (i=0;i<N_FEATURES;i++) {
if (ft->feature[i][1]->val>=0) {
double x0,y0,x1,y1;
x0=ft->feature[i][0]->x;
y0=ft->feature[i][0]->y;
x1=ft->feature[i][1]->x;
y1=ft->feature[i][1]->y;
r0[n]=sqrt((x0-wc)*(x0-wc)+(y0-hc)*(y0-hc))/radius;
// dots too close to the center tends to have big diviation and create noise, extract them
if (r0[n]<CENTER_R)
continue;
r10[n]=(sqrt((x1-wc)*(x1-wc)+(y1-hc)*(y1-hc))/radius)/r0[n];
total_r10 += r10[n];
total_r0 += r0[n];
n++;
} else {
ft->feature[i][0]->x=-1.0;
ft->feature[i][0]->y=-1.0;
}
}
if (n < 5) {
printf ("Not sufficient features.\n");
return 0.0;
}
double avg_r10 = total_r10 / n;
double avg_r0 = total_r0 / n;
double Sxx = 0.0;
double Sxy = 0.0;
double Syy = 0.0;
for (i=0;i<n;i++) {
Sxx += (r0[i] - avg_r0) * (r0[i] - avg_r0);
Sxy += (r0[i] - avg_r0) * (r10[i] - avg_r10);
Syy += (r10[i] - avg_r10) * (r10[i] - avg_r10);
}
double u = Sxy/Sxx;
double v = avg_r10 - u * avg_r0;
double b = u + v;
double a = u / b;
double total_delta = 0.0;
double rxy = Sxy/sqrt(Sxx*Syy);
if (rxy<0) rxy= -rxy;
int new_n=n;
// calculate deviation
for (i=0;i<n;i++) {
double delta = r10[i] - (1.0-a+(r0[i]*a))*b;
delta = delta >= 0 ? delta : -delta;
#ifdef DEBUG_IMG
drawDot(img2, ncols, nrows, r0[i], r10[i], 255);
#endif
if (delta >= DELTA_1) {
total_r10 -= r10[i];
total_r0 -= r0[i];
r0[i] = -1.0;
new_n--;
}
total_delta += delta;
}
printf ("distortion amount=%lf scale=%lf deviation=%lf, rxy=%lf\n", a, b, total_delta/n, rxy);
if (new_n < 5) {
printf ("Not sufficient features.\n");
return 0.0;
}
printf ("Removed %d outstading data points\n", n-new_n);
avg_r10 = total_r10 / new_n;
avg_r0 = total_r0 / new_n;
Sxx = 0.0;
Sxy = 0.0;
Syy = 0.0;
for (i=0;i<n;i++) {
if (r0[i]<0) continue;
Sxx += (r0[i] - avg_r0) * (r0[i] - avg_r0);
Sxy += (r0[i] - avg_r0) * (r10[i] - avg_r10);
Syy += (r10[i] - avg_r10) * (r10[i] - avg_r10);
}
u = Sxy/Sxx;
v = avg_r10 - u * avg_r0;
b = u + v;
a = u / b;
total_delta = 0.0;
rxy = Sxy/sqrt(Sxx*Syy);
if (rxy<0) rxy= -rxy;
#ifdef DEBUG_IMG
// draw lines for curve and different deviation level, for debugging purpose
for (i=0; i< ncols; i++) {
double val= (1.0-a+((i/(double)ncols)*a))*b;
if (val >=0.8 && val <1.2) {
if (img2[i+((int)((val-0.8)*2.5*nrows))*ncols] != 255)
img2[i+((int)((val-0.8)*2.5*nrows))*ncols] = 0;
}
val += DELTA_1;
if (val >=0.8 && val <1.2) {
if (img2[i+((int)((val-0.8)*2.5*nrows))*ncols] != 255)
img2[i+((int)((val-0.8)*2.5*nrows))*ncols] = 8;
}
val -= DELTA_1*2;
if (val >=0.8 && val <1.2) {
if (img2[i+((int)((val-0.8)*2.5*nrows))*ncols] != 255)
img2[i+((int)((val-0.8)*2.5*nrows))*ncols] = 8;
}
val += DELTA_1+DELTA_2;
if (val >=0.8 && val <1.2) {
if (img2[i+((int)((val-0.8)*2.5*nrows))*ncols] != 255)
img2[i+((int)((val-0.8)*2.5*nrows))*ncols] = 16;
}
val -= DELTA_2*2;
if (val >=0.8 && val <1.2) {
if (img2[i+((int)((val-0.8)*2.5*nrows))*ncols] != 255)
img2[i+((int)((val-0.8)*2.5*nrows))*ncols] = 16;
}
}
KLTExtractFeatureList(fl, ft, 0);
KLTWriteFeatureListToPPM(fl,img1,ncols,nrows,"/tmp/feat0.ppm");
KLTExtractFeatureList(fl, ft, 1);
KLTWriteFeatureListToPPM(fl,img2,ncols,nrows,"/tmp/feat1.ppm");
#endif
// calculate deviation
for (i=0;i<n;i++) {
if (r0[i]<0) continue;
double delta = r10[i] - (1.0-a+(r0[i]*a))*b;
delta = delta >= 0 ? delta : -delta;
total_delta += delta;
}
printf ("distortion amount=%lf scale=%lf deviation=%lf, rxy=%lf\n", a, b, total_delta/n, rxy);
if (total_delta / new_n > DELTA_2) {
printf ("Deviation is too big.\n");
return 0.0;
}
if (rxy < RXY_LIMIT) {
printf ("Not linear enough\n");
return 0.0;
}
printf ("distortion amount=%lf scale=%lf deviation=%lf, rxy=%lf\n", a, b, total_delta/n, rxy);
return a;
}

View File

@ -1,6 +1,4 @@
#ifndef CALC_DISTORTION__H
#define CALC_DISTORTION__H
extern "C" {
double calcDistortion (unsigned char* img1, unsigned char* img2, int ncols, int nrows);
}
#endif

View File

@ -28,16 +28,16 @@
#define CLASS
/*
#include <ctype.h>
#include <errno.h>
#include <cctype>
#include <cerrno>
#include <fcntl.h>
#include <float.h>
#include <limits.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>*/
#include <math.h>
#include <cfloat>
#include <climits>
#include <csetjmp>
#include <cstdio>
#include <cstdlib>
#include <cstring>*/
#include <cmath>
//#include "shrtdct_float.c"

View File

@ -21,7 +21,7 @@ inline double tightestroot (double L, double a, double b, double r1, double r2,
#ifndef __COLORCLIP__
#define __COLORCLIP__
#include <math.h>
#include <cmath>
#include "median.h"
// gives back the tightest >0 amplification by which color clipping occures

View File

@ -16,11 +16,11 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <colortemp.h>
#include <iccmatrices.h>
#include <rtengine.h>
#include <improcfun.h>
#include <curves.h>
#include "colortemp.h"
#include "iccmatrices.h"
#include "rtengine.h"
#include "improcfun.h"
#include "curves.h"
namespace rtengine {

View File

@ -20,7 +20,7 @@
#define _COLORTEMP_
#include <gtkmm.h>
#include <math.h>
#include <cmath>
namespace rtengine {

View File

@ -20,7 +20,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <math.h>
#include <cmath>
#define FLOAT float

View File

@ -18,11 +18,11 @@
*/
#include <glib.h>
#include <glib/gstdio.h>
#include <curves.h>
#include <math.h>
#include "curves.h"
#include <cmath>
#include <vector>
#include <mytime.h>
#include <string.h>
#include "mytime.h"
#include <cstring>
#include "array2D.h"
#include "LUT.h"

View File

@ -22,10 +22,10 @@
#include <glibmm.h>
#include <map>
#include <string>
#include <math.h>
#include <mycurve.h>
#include <myflatcurve.h>
#include <mydiagonalcurve.h>
#include <cmath>
#include "../rtgui/mycurve.h"
#include "../rtgui/myflatcurve.h"
#include "../rtgui/mydiagonalcurve.h"
#include "LUT.h"

View File

@ -29,17 +29,17 @@
#define _GNU_SOURCE
#endif
#define _USE_MATH_DEFINES
#include <ctype.h>
#include <errno.h>
#include <cctype>
#include <cerrno>
#include <fcntl.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sys/types.h>
#ifdef NODEPS

View File

@ -40,17 +40,17 @@
#define _GNU_SOURCE
#endif
#define _USE_MATH_DEFINES
#include <ctype.h>
#include <errno.h>
#include <cctype>
#include <cerrno>
#include <fcntl.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sys/types.h>
#ifdef NODEPS

View File

@ -20,8 +20,8 @@
#ifndef DCRAW_H
#define DCRAW_H
#include <myfile.h>
#include <setjmp.h>
#include "myfile.h"
#include <csetjmp>
class DCraw

View File

@ -16,10 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <dcrop.h>
#include <curves.h>
#include <mytime.h>
#include <refreshmap.h>
#include "dcrop.h"
#include "curves.h"
#include "mytime.h"
#include "refreshmap.h"
#define CLIPTO(a,b,c) ((a)>b?((a)<c?(a):c):b)
#define CLIP(a) ((a)<65535 ? (a) : (65535));
#define SKIPS(a,b) ((a) / (b) + ((a) % (b) > 0))

View File

@ -19,13 +19,13 @@
#ifndef _CROP_H_
#define _CROP_H_
#include <improccoordinator.h>
#include <rtengine.h>
#include <improcfun.h>
#include <image8.h>
#include <image16.h>
#include <imagesource.h>
#include <procevents.h>
#include "improccoordinator.h"
#include "rtengine.h"
#include "improcfun.h"
#include "image8.h"
#include "image16.h"
#include "imagesource.h"
#include "procevents.h"
namespace rtengine {

View File

@ -16,19 +16,19 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rawimagesource.h>
#include <rawimagesource_i.h>
#include <median.h>
#include <rawimage.h>
#include <math.h>
#include <mytime.h>
#include <iccmatrices.h>
#include <iccstore.h>
#include <image8.h>
#include <curves.h>
#include <dfmanager.h>
#include <slicer.h>
#include <assert.h>
#include "rawimagesource.h"
#include "rawimagesource_i.h"
#include "median.h"
#include "rawimage.h"
#include <cmath>
#include "mytime.h"
#include "iccmatrices.h"
#include "iccstore.h"
#include "image8.h"
#include "curves.h"
#include "dfmanager.h"
#include "slicer.h"
#include <cassert>
#ifdef _OPENMP
#include <omp.h>

View File

@ -16,16 +16,16 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <dfmanager.h>
#include <options.h>
#include "dfmanager.h"
#include "../rtgui/options.h"
#include <giomm.h>
#include <guiutils.h>
#include <safegtk.h>
#include <rawimage.h>
#include "../rtgui/guiutils.h"
#include "safegtk.h"
#include "rawimage.h"
#include <sstream>
#include <iostream>
#include <stdio.h>
#include <imagedata.h>
#include <cstdio>
#include "imagedata.h"
namespace rtengine{

View File

@ -19,8 +19,8 @@
#include <string>
#include <glibmm/ustring.h>
#include <map>
#include <math.h>
#include <rawimage.h>
#include <cmath>
#include "rawimage.h"
namespace rtengine{

View File

@ -18,11 +18,11 @@
*/
#include <glib.h>
#include <glib/gstdio.h>
#include <curves.h>
#include <math.h>
#include "curves.h"
#include <cmath>
#include <vector>
#include <mytime.h>
#include <string.h>
#include "mytime.h"
#include <cstring>
#define CLIPD(a) ((a)>0.0?((a)<1.0?(a):1.0):0.0)

View File

@ -14,17 +14,17 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*
* © 2010 Emil Martinec <ejmartin@uchicago.edu>
* <EFBFBD> 2010 Emil Martinec <ejmartin@uchicago.edu>
*
*/
//#include <rtengine.h>
//#include "rtengine.h"
#include <cstddef>
#include <math.h>
#include <curves.h>
#include <labimage.h>
#include <improcfun.h>
#include <array2D.h>
#include <cmath>
#include "curves.h"
#include "labimage.h"
#include "improcfun.h"
#include "array2D.h"
#ifdef _OPENMP
#include <omp.h>

View File

@ -18,13 +18,13 @@
*
*/
//#include <rtengine.h>
//#include "rtengine.h"
#include <cstddef>
#include <math.h>
#include <curves.h>
#include <labimage.h>
#include <improcfun.h>
#include <rawimagesource.h>
#include <cmath>
#include "curves.h"
#include "labimage.h"
#include "improcfun.h"
#include "rawimagesource.h"
#ifdef _OPENMP
#include <omp.h>

View File

@ -18,14 +18,14 @@
*
*/
//#include <rtengine.h>
//#include "rtengine.h"
#include <cstddef>
#include <math.h>
#include <curves.h>
#include <labimage.h>
#include <improcfun.h>
#include <rawimagesource.h>
#include <array2D.h>
#include <cmath>
#include "curves.h"
#include "labimage.h"
#include "improcfun.h"
#include "rawimagesource.h"
#include "array2D.h"
#ifdef _OPENMP
#include <omp.h>

View File

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include "rtengine.h"
#include <iostream>
//#include <giomm.h>
#include <helpers.h>

View File

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include "rtengine.h"
#include <iostream>
//#include <giomm.h>
#include <helpers.h>

View File

@ -16,15 +16,15 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ffmanager.h>
#include <options.h>
#include "ffmanager.h"
#include "../rtgui/options.h"
#include <giomm.h>
#include <guiutils.h>
#include <safegtk.h>
#include <rawimage.h>
#include "../rtgui/guiutils.h"
#include "safegtk.h"
#include "rawimage.h"
#include <sstream>
#include <stdio.h>
#include <imagedata.h>
#include <cstdio>
#include "imagedata.h"
namespace rtengine{

View File

@ -19,8 +19,8 @@
#include <string>
#include <glibmm/ustring.h>
#include <map>
#include <math.h>
#include <rawimage.h>
#include <cmath>
#include "rawimage.h"
namespace rtengine{

View File

@ -18,11 +18,11 @@
*/
#include <glib.h>
#include <glib/gstdio.h>
#include <curves.h>
#include <math.h>
#include "curves.h"
#include <cmath>
#include <vector>
#include <mytime.h>
#include <string.h>
#include "mytime.h"
#include <cstring>
#include <gtkmm.h>
#include <fstream>

View File

@ -19,10 +19,10 @@
#ifndef _GAUSS_H_
#define _GAUSS_H_
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <alignedbuffer.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include "alignedbuffer.h"
#ifdef _OPENMP
#include <omp.h>
#endif

View File

@ -23,9 +23,9 @@
////////////////////////////////////////////////////////////////
#define TS 256 // Tile size
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define SQR(x) ((x)*(x))

View File

@ -22,13 +22,13 @@
//
////////////////////////////////////////////////////////////////
//#include <rtengine.h>
//#include "rtengine.h"
#include <cstddef>
#include <math.h>
#include <curves.h>
#include <array2D.h>
#include <improcfun.h>
#include <rawimagesource.h>
#include <cmath>
#include "curves.h"
#include "array2D.h"
#include "improcfun.h"
#include "rawimagesource.h"
//#include "stack1.h"

View File

@ -16,11 +16,11 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <limits.h>
#include <stdio.h>
#include <rawimagesource.h>
#include <rawimagesource_i.h>
#include <options.h>
#include <climits>
#include <cstdio>
#include "rawimagesource.h"
#include "rawimagesource_i.h"
#include "../rtgui/options.h"
#define MAXVAL 0xffff
#define CLIP(a) ((a)>0?((a)<MAXVAL?(a):MAXVAL):0)

View File

@ -1,248 +0,0 @@
/*
* iccprofile.c
*
* This file provides code to read and write International Color Consortium
* (ICC) device profiles embedded in JFIF JPEG image files. The ICC has
* defined a standard format for including such data in JPEG "APP2" markers.
* The code given here does not know anything about the internal structure
* of the ICC profile data; it just knows how to put the profile data into
* a JPEG file being written, or get it back out when reading.
*
* This code depends on new features added to the IJG JPEG library as of
* IJG release 6b; it will not compile or work with older IJG versions.
*
* NOTE: this code would need surgery to work on 16-bit-int machines
* with ICC profiles exceeding 64K bytes in size. If you need to do that,
* change all the "unsigned int" variables to "INT32". You'll also need
* to find a malloc() replacement that can allocate more than 64K.
*/
#include "iccjpeg.h"
#include <stdlib.h> /* define malloc() */
/*
* Since an ICC profile can be larger than the maximum size of a JPEG marker
* (64K), we need provisions to split it into multiple markers. The format
* defined by the ICC specifies one or more APP2 markers containing the
* following data:
* Identifying string ASCII "ICC_PROFILE\0" (12 bytes)
* Marker sequence number 1 for first APP2, 2 for next, etc (1 byte)
* Number of markers Total number of APP2's used (1 byte)
* Profile data (remainder of APP2 data)
* Decoders should use the marker sequence numbers to reassemble the profile,
* rather than assuming that the APP2 markers appear in the correct sequence.
*/
#define ICC_MARKER (JPEG_APP0 + 2) /* JPEG marker code for ICC */
#define ICC_OVERHEAD_LEN 14 /* size of non-profile data in APP2 */
#define MAX_BYTES_IN_MARKER 65533 /* maximum data len of a JPEG marker */
#define MAX_DATA_BYTES_IN_MARKER (MAX_BYTES_IN_MARKER - ICC_OVERHEAD_LEN)
/*
* This routine writes the given ICC profile data into a JPEG file.
* It *must* be called AFTER calling jpeg_start_compress() and BEFORE
* the first call to jpeg_write_scanlines().
* (This ordering ensures that the APP2 marker(s) will appear after the
* SOI and JFIF or Adobe markers, but before all else.)
*/
void
write_icc_profile (j_compress_ptr cinfo,
const JOCTET *icc_data_ptr,
unsigned int icc_data_len)
{
unsigned int num_markers; /* total number of markers we'll write */
int cur_marker = 1; /* per spec, counting starts at 1 */
unsigned int length; /* number of bytes to write in this marker */
/* Calculate the number of markers we'll need, rounding up of course */
num_markers = icc_data_len / MAX_DATA_BYTES_IN_MARKER;
if (num_markers * MAX_DATA_BYTES_IN_MARKER != icc_data_len)
num_markers++;
while (icc_data_len > 0) {
/* length of profile to put in this marker */
length = icc_data_len;
if (length > MAX_DATA_BYTES_IN_MARKER)
length = MAX_DATA_BYTES_IN_MARKER;
icc_data_len -= length;
/* Write the JPEG marker header (APP2 code and marker length) */
jpeg_write_m_header(cinfo, ICC_MARKER,
(unsigned int) (length + ICC_OVERHEAD_LEN));
/* Write the marker identifying string "ICC_PROFILE" (null-terminated).
* We code it in this less-than-transparent way so that the code works
* even if the local character set is not ASCII.
*/
jpeg_write_m_byte(cinfo, 0x49);
jpeg_write_m_byte(cinfo, 0x43);
jpeg_write_m_byte(cinfo, 0x43);
jpeg_write_m_byte(cinfo, 0x5F);
jpeg_write_m_byte(cinfo, 0x50);
jpeg_write_m_byte(cinfo, 0x52);
jpeg_write_m_byte(cinfo, 0x4F);
jpeg_write_m_byte(cinfo, 0x46);
jpeg_write_m_byte(cinfo, 0x49);
jpeg_write_m_byte(cinfo, 0x4C);
jpeg_write_m_byte(cinfo, 0x45);
jpeg_write_m_byte(cinfo, 0x0);
/* Add the sequencing info */
jpeg_write_m_byte(cinfo, cur_marker);
jpeg_write_m_byte(cinfo, (int) num_markers);
/* Add the profile data */
while (length--) {
jpeg_write_m_byte(cinfo, *icc_data_ptr);
icc_data_ptr++;
}
cur_marker++;
}
}
/*
* Prepare for reading an ICC profile
*/
void
setup_read_icc_profile (j_decompress_ptr cinfo)
{
/* Tell the library to keep any APP2 data it may find */
jpeg_save_markers(cinfo, ICC_MARKER, 0xFFFF);
}
/*
* Handy subroutine to test whether a saved marker is an ICC profile marker.
*/
static boolean
marker_is_icc (jpeg_saved_marker_ptr marker)
{
return
marker->marker == ICC_MARKER &&
marker->data_length >= ICC_OVERHEAD_LEN &&
/* verify the identifying string */
GETJOCTET(marker->data[0]) == 0x49 &&
GETJOCTET(marker->data[1]) == 0x43 &&
GETJOCTET(marker->data[2]) == 0x43 &&
GETJOCTET(marker->data[3]) == 0x5F &&
GETJOCTET(marker->data[4]) == 0x50 &&
GETJOCTET(marker->data[5]) == 0x52 &&
GETJOCTET(marker->data[6]) == 0x4F &&
GETJOCTET(marker->data[7]) == 0x46 &&
GETJOCTET(marker->data[8]) == 0x49 &&
GETJOCTET(marker->data[9]) == 0x4C &&
GETJOCTET(marker->data[10]) == 0x45 &&
GETJOCTET(marker->data[11]) == 0x0;
}
/*
* See if there was an ICC profile in the JPEG file being read;
* if so, reassemble and return the profile data.
*
* TRUE is returned if an ICC profile was found, FALSE if not.
* If TRUE is returned, *icc_data_ptr is set to point to the
* returned data, and *icc_data_len is set to its length.
*
* IMPORTANT: the data at **icc_data_ptr has been allocated with malloc()
* and must be freed by the caller with free() when the caller no longer
* needs it. (Alternatively, we could write this routine to use the
* IJG library's memory allocator, so that the data would be freed implicitly
* at jpeg_finish_decompress() time. But it seems likely that many apps
* will prefer to have the data stick around after decompression finishes.)
*
* NOTE: if the file contains invalid ICC APP2 markers, we just silently
* return FALSE. You might want to issue an error message instead.
*/
boolean
read_icc_profile (j_decompress_ptr cinfo,
JOCTET **icc_data_ptr,
unsigned int *icc_data_len)
{
jpeg_saved_marker_ptr marker;
int num_markers = 0;
int seq_no;
JOCTET *icc_data;
unsigned int total_length;
#define MAX_SEQ_NO 255 /* sufficient since marker numbers are bytes */
char marker_present[MAX_SEQ_NO+1]; /* 1 if marker found */
unsigned int data_length[MAX_SEQ_NO+1]; /* size of profile data in marker */
unsigned int data_offset[MAX_SEQ_NO+1]; /* offset for data in marker */
*icc_data_ptr = NULL; /* avoid confusion if FALSE return */
*icc_data_len = 0;
/* This first pass over the saved markers discovers whether there are
* any ICC markers and verifies the consistency of the marker numbering.
*/
for (seq_no = 1; seq_no <= MAX_SEQ_NO; seq_no++)
marker_present[seq_no] = 0;
for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
if (marker_is_icc(marker)) {
if (num_markers == 0)
num_markers = GETJOCTET(marker->data[13]);
else if (num_markers != GETJOCTET(marker->data[13]))
return FALSE; /* inconsistent num_markers fields */
seq_no = GETJOCTET(marker->data[12]);
if (seq_no <= 0 || seq_no > num_markers)
return FALSE; /* bogus sequence number */
if (marker_present[seq_no])
return FALSE; /* duplicate sequence numbers */
marker_present[seq_no] = 1;
data_length[seq_no] = marker->data_length - ICC_OVERHEAD_LEN;
}
}
if (num_markers == 0)
return FALSE;
/* Check for missing markers, count total space needed,
* compute offset of each marker's part of the data.
*/
total_length = 0;
for (seq_no = 1; seq_no <= num_markers; seq_no++) {
if (marker_present[seq_no] == 0)
return FALSE; /* missing sequence number */
data_offset[seq_no] = total_length;
total_length += data_length[seq_no];
}
if (total_length <= 0)
return FALSE; /* found only empty markers? */
/* Allocate space for assembled data */
icc_data = (JOCTET *) malloc(total_length * sizeof(JOCTET));
if (icc_data == NULL)
return FALSE; /* oops, out of memory */
/* and fill it in */
for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
if (marker_is_icc(marker)) {
JOCTET FAR *src_ptr;
JOCTET *dst_ptr;
unsigned int length;
seq_no = GETJOCTET(marker->data[12]);
dst_ptr = icc_data + data_offset[seq_no];
src_ptr = marker->data + ICC_OVERHEAD_LEN;
length = data_length[seq_no];
while (length--) {
*dst_ptr++ = *src_ptr++;
}
}
}
*icc_data_ptr = icc_data;
*icc_data_len = total_length;
return TRUE;
}

View File

@ -16,7 +16,7 @@
* for details.
*/
#include <stdio.h> /* needed to define "FILE", "NULL" */
#include <cstdio> /* needed to define "FILE", "NULL" */
#include "jpeglib.h"

View File

@ -16,16 +16,16 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iccstore.h>
#include "iccstore.h"
#ifdef WIN32
#include <winsock2.h>
#else
#include <netinet/in.h>
#endif
#include <iccmatrices.h>
#include "iccmatrices.h"
#include <glib/gstdio.h>
#include <safegtk.h>
#include <options.h>
#include "safegtk.h"
#include "../rtgui/options.h"
#include <cstring>
@ -67,10 +67,10 @@ std::vector<std::string> ICCStore::getOutputProfiles () {
std::vector<std::string> res;
for (std::map<std::string, cmsHPROFILE>::iterator i=fileProfiles.begin(); i!=fileProfiles.end(); i++){
std::string name(i->first);
std::string::size_type i = name.find_last_of('/');
if( i == std::string::npos )
i = name.find_last_of('\\');
if( i == std::string::npos )
std::string::size_type i2 = name.find_last_of('/');
if( i2 == std::string::npos )
i2 = name.find_last_of('\\');
if( i2 == std::string::npos )
res.push_back ( name ); // list only profiles inside selected profiles directory
}
return res;

View File

@ -16,12 +16,12 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <image16.h>
#include <imagefloat.h>
#include <image8.h>
#include <string.h>
#include <stdio.h>
#include <rtengine.h>
#include "image16.h"
#include "imagefloat.h"
#include "image8.h"
#include <cstring>
#include <cstdio>
#include "rtengine.h"
using namespace rtengine;

View File

@ -22,9 +22,9 @@
#ifndef _IMAGE16_
#define _IMAGE16_
#include <imageio.h>
#include <rtengine.h>
#include <imagefloat.h>
#include "imageio.h"
#include "rtengine.h"
#include "imagefloat.h"
namespace rtengine {

View File

@ -16,10 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
#include <image8.h>
#include <rtengine.h>
#include <cstring>
#include <cstdio>
#include "image8.h"
#include "rtengine.h"
using namespace rtengine;

View File

@ -22,8 +22,8 @@
#ifndef _IMAGE8_
#define _IMAGE8_
#include <imageio.h>
#include <rtengine.h>
#include "imageio.h"
#include "rtengine.h"
namespace rtengine {

View File

@ -16,10 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <imagedata.h>
#include <iptcpairs.h>
#include "imagedata.h"
#include "iptcpairs.h"
#include <glib/gstdio.h>
#include <safegtk.h>
#include "safegtk.h"
#ifndef GLIBMM_EXCEPTIONS_ENABLED
#include <memory>

View File

@ -19,14 +19,14 @@
#ifndef __IMAGEDATA_H__
#define __IMAGEDATA_H__
#include <stdio.h>
#include <rawimage.h>
#include <cstdio>
#include "rawimage.h"
#include <string>
#include <glibmm.h>
#include <rtexif.h>
#include <procparams.h>
#include "../rtexif/rtexif.h"
#include "procparams.h"
#include <libiptcdata/iptc-data.h>
#include <rtengine.h>
#include "rtengine.h"
namespace rtengine {

View File

@ -16,13 +16,13 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <imagefloat.h>
#include <image16.h>
#include <image8.h>
#include <string.h>
#include <rtengine.h>
#include <mytime.h>
#include <iccstore.h>
#include "imagefloat.h"
#include "image16.h"
#include "image8.h"
#include <cstring>
#include "rtengine.h"
#include "mytime.h"
#include "iccstore.h"
using namespace rtengine;

View File

@ -22,8 +22,8 @@
#ifndef _IMAGEFLOAT_
#define _IMAGEFLOAT_
#include <imageio.h>
#include <rtengine.h>
#include "imageio.h"
#include "rtengine.h"
namespace rtengine {
using namespace procparams;

View File

@ -19,24 +19,23 @@
*/
#include <png.h>
#include <glib/gstdio.h>
#include <imageio.h>
#include <safegtk.h>
#include "imageio.h"
#include "safegtk.h"
#include <tiff.h>
#include <tiffio.h>
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <fcntl.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <netinet/in.h>
#endif
#include <iptcpairs.h>
#include "iptcpairs.h"
#include <libiptcdata/iptc-jpeg.h>
extern "C" {
#include <iccjpeg.h>
}
#include "iccjpeg.h"
#include "jpeg.h"
Glib::ustring safe_locale_to_utf8 (const std::string& src);
@ -365,12 +364,12 @@ int ImageIO::loadJPEG (Glib::ustring fname) {
//jpeg_stdio_src(&cinfo,file);
jpeg_read_header(&cinfo, TRUE);
//if JPEG is CMYK, then abort reading
if (cinfo.jpeg_color_space == JCS_CMYK || cinfo.jpeg_color_space == JCS_YCCK) {
//if JPEG is CMYK, then abort reading
if (cinfo.jpeg_color_space == JCS_CMYK || cinfo.jpeg_color_space == JCS_YCCK) {
jpeg_destroy_decompress(&cinfo);
return IMIO_READERROR;
}
return IMIO_READERROR;
}
unsigned int proflen;
delete loadedProfileData;

View File

@ -27,11 +27,11 @@
#define IMIO_VARIANTNOTSUPPORTED 5
#define IMIO_FILETYPENOTSUPPORTED 6
#include <rtengine.h>
#include "rtengine.h"
#include <glibmm.h>
#include <procparams.h>
#include "procparams.h"
#include <libiptcdata/iptc-data.h>
#include <rtexif.h>
#include "../rtexif/rtexif.h"
namespace rtengine {

View File

@ -19,15 +19,15 @@
#ifndef _IMAGESOURCE_
#define _IMAGESOURCE_
#include <rtengine.h>
#include <colortemp.h>
#include "rtengine.h"
#include "colortemp.h"
#include <glibmm.h>
#include <image16.h>
#include <imagefloat.h>
#include <procparams.h>
#include <coord2d.h>
#include "image16.h"
#include "imagefloat.h"
#include "procparams.h"
#include "coord2d.h"
#include <vector>
#include <imagedata.h>
#include "imagedata.h"
#include "LUT.h"
namespace rtengine {

View File

@ -16,12 +16,12 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <improccoordinator.h>
#include <curves.h>
#include <mytime.h>
#include <refreshmap.h>
#include <simpleprocess.h>
#include "ppversion.h"
#include "improccoordinator.h"
#include "curves.h"
#include "mytime.h"
#include "refreshmap.h"
#include "simpleprocess.h"
#include "../rtgui/ppversion.h"
#define CLIPTO(a,b,c) ((a)>b?((a)<c?(a):c):b)
#define CLIP(a) ((a)>0?((a)<65535?(a):65535):0)

View File

@ -19,13 +19,13 @@
#ifndef _IMPROCCOORDINATOR_H_
#define _IMPROCCOORDINATOR_H_
#include <rtengine.h>
#include <improcfun.h>
#include <image8.h>
#include <image16.h>
#include <imagesource.h>
#include <procevents.h>
#include <dcrop.h>
#include "rtengine.h"
#include "improcfun.h"
#include "image8.h"
#include "image16.h"
#include "imagesource.h"
#include "procevents.h"
#include "dcrop.h"
#include "LUT.h"
namespace rtengine {

View File

@ -16,24 +16,24 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include <improcfun.h>
#include <curves.h>
#include <math.h>
#include <colorclip.h>
#include <gauss.h>
#include <bilateral2.h>
#include <minmax.h>
#include <mytime.h>
#include "rtengine.h"
#include "improcfun.h"
#include "curves.h"
#include <cmath>
#include "colorclip.h"
#include "gauss.h"
#include "bilateral2.h"
#include "minmax.h"
#include "mytime.h"
#include <glib.h>
#include <glibmm.h>
#include <iccstore.h>
#include <impulse_denoise.h>
#include <imagesource.h>
#include <rtthumbnail.h>
#include <utils.h>
#include <iccmatrices.h>
#include "iccstore.h"
#include "impulse_denoise.h"
#include "imagesource.h"
#include "rtthumbnail.h"
#include "../rtengine/utils.h"
#include "iccmatrices.h"
#include "calc_distort.h"
#ifdef _OPENMP
#include <omp.h>
@ -859,8 +859,6 @@ fclose(f);*/
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include "calc_distort.h"
double ImProcFunctions::getAutoDistor (const Glib::ustring &fname, int thumb_size) {
if (fname != "") {
rtengine::RawMetaDataLocation ri;

View File

@ -19,13 +19,13 @@
#ifndef _IMPROCFUN_H_
#define _IMPROCFUN_H_
#include <imagefloat.h>
#include <image16.h>
#include <image8.h>
#include <procparams.h>
#include <shmap.h>
#include <coord2d.h>
#include <labimage.h>
#include "imagefloat.h"
#include "image16.h"
#include "image8.h"
#include "procparams.h"
#include "shmap.h"
#include "coord2d.h"
#include "labimage.h"
#include "LUT.h"
namespace rtengine {

View File

@ -22,8 +22,8 @@
#include <cstddef>
#include <algorithm>
#include <labimage.h>
#include <improcfun.h>
#include "labimage.h"
#include "improcfun.h"
namespace rtengine {

View File

@ -16,14 +16,14 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include <iccstore.h>
#include <improcfun.h>
#include <improccoordinator.h>
#include <curves.h>
#include <dfmanager.h>
#include <ffmanager.h>
#include <rtthumbnail.h>
#include "rtengine.h"
#include "iccstore.h"
#include "improcfun.h"
#include "improccoordinator.h"
#include "curves.h"
#include "dfmanager.h"
#include "ffmanager.h"
#include "rtthumbnail.h"
namespace rtengine {

View File

@ -16,16 +16,16 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include <improcfun.h>
#include "rtengine.h"
#include "improcfun.h"
#include <glibmm.h>
#include <iccstore.h>
#include <iccmatrices.h>
#include <mytime.h>
#include <icmpanel.h>
#include <options.h>
#include <settings.h>
#include <curves.h>
#include "iccstore.h"
#include "iccmatrices.h"
#include "mytime.h"
#include "../rtgui/icmpanel.h"
#include "../rtgui/options.h"
#include "settings.h"
#include "curves.h"
#ifdef _OPENMP

View File

@ -16,14 +16,14 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include <improcfun.h>
#include "rtengine.h"
#include "improcfun.h"
#ifdef _OPENMP
#include <omp.h>
#endif
#include <minmax.h>
#include <gauss.h>
#include <bilateral2.h>
#include "minmax.h"
#include "gauss.h"
#include "bilateral2.h"
namespace rtengine {

View File

@ -16,12 +16,12 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include <improcfun.h>
#include "rtengine.h"
#include "improcfun.h"
#ifdef _OPENMP
#include <omp.h>
#endif
#include <mytime.h>
#include "mytime.h"
namespace rtengine {

View File

@ -17,10 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include <improcfun.h>
#include <iccstore.h>
#include <mytime.h>
#include "rtengine.h"
#include "improcfun.h"
#include "iccstore.h"
#include "mytime.h"
#ifdef _OPENMP
#include <omp.h>

View File

@ -1,411 +0,0 @@
#include <stdio.h>
#include <jpeglib.h>
#include <jerror.h>
#include "jpeg.h"
/*
* jdatasrc.c
*
* Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2010 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains decompression data source routines for the case of
* reading JPEG data from a file (or any stdio stream). While these routines
* are sufficient for most applications, some will want to use a different
* source manager.
* IMPORTANT: we assume that fread() will correctly transcribe an array of
* JOCTETs from 8-bit-wide elements on external storage. If char is wider
* than 8 bits on your machine, you may need to do some tweaking.
*/
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
//#include "jinclude.h"
#define JFREAD(file,buf,sizeofbuf) \
((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
#define JFWRITE(file,buf,sizeofbuf) \
((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
/* Expanded data source object for stdio input */
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
jmp_buf error_jmp_buf; /* error handler for this instance */
FILE * infile; /* source stream */
JOCTET * buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */
} my_source_mgr;
typedef my_source_mgr * my_src_ptr;
#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
/*
* Initialize source --- called by jpeg_read_header
* before any data is actually read.
*/
METHODDEF(void)
my_init_source (j_decompress_ptr cinfo)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
/* We reset the empty-input-file flag for each image,
* but we don't clear the input buffer.
* This is correct behavior for reading a series of images from one source.
*/
src->start_of_file = TRUE;
}
/*
* Fill the input buffer --- called whenever buffer is emptied.
*
* In typical applications, this should read fresh data into the buffer
* (ignoring the current state of next_input_byte & bytes_in_buffer),
* reset the pointer & count to the start of the buffer, and return TRUE
* indicating that the buffer has been reloaded. It is not necessary to
* fill the buffer entirely, only to obtain at least one more byte.
*
* There is no such thing as an EOF return. If the end of the file has been
* reached, the routine has a choice of ERREXIT() or inserting fake data into
* the buffer. In most cases, generating a warning message and inserting a
* fake EOI marker is the best course of action --- this will allow the
* decompressor to output however much of the image is there. However,
* the resulting error message is misleading if the real problem is an empty
* input file, so we handle that case specially.
*
* In applications that need to be able to suspend compression due to input
* not being available yet, a FALSE return indicates that no more data can be
* obtained right now, but more may be forthcoming later. In this situation,
* the decompressor will return to its caller (with an indication of the
* number of scanlines it has read, if any). The application should resume
* decompression after it has loaded more data into the input buffer. Note
* that there are substantial restrictions on the use of suspension --- see
* the documentation.
*
* When suspending, the decompressor will back up to a convenient restart point
* (typically the start of the current MCU). next_input_byte & bytes_in_buffer
* indicate where the restart point will be if the current call returns FALSE.
* Data beyond this point must be rescanned after resumption, so move it to
* the front of the buffer rather than discarding it.
*/
METHODDEF(boolean)
my_fill_input_buffer (j_decompress_ptr cinfo)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
size_t nbytes;
nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
if (nbytes <= 0) {
if (src->start_of_file) /* Treat empty input file as fatal error */
ERREXIT(cinfo, JERR_INPUT_EMPTY);
WARNMS(cinfo, JWRN_JPEG_EOF);
/* Insert a fake EOI marker */
src->buffer[0] = (JOCTET) 0xFF;
src->buffer[1] = (JOCTET) JPEG_EOI;
nbytes = 2;
}
if (src->start_of_file)
src->buffer[0] = (JOCTET) 0xFF;
src->pub.next_input_byte = src->buffer;
src->pub.bytes_in_buffer = nbytes;
src->start_of_file = FALSE;
return TRUE;
}
/*
* Skip data --- used to skip over a potentially large amount of
* uninteresting data (such as an APPn marker).
*
* Writers of suspendable-input applications must note that skip_input_data
* is not granted the right to give a suspension return. If the skip extends
* beyond the data currently in the buffer, the buffer can be marked empty so
* that the next read will cause a fill_input_buffer call that can suspend.
* Arranging for additional bytes to be discarded before reloading the input
* buffer is the application writer's problem.
*/
METHODDEF(void)
my_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
/* Just a dumb implementation for now. Could use fseek() except
* it doesn't work on pipes. Not clear that being smart is worth
* any trouble anyway --- large skips are infrequent.
*/
if (num_bytes > 0) {
while (num_bytes > (long) src->pub.bytes_in_buffer) {
num_bytes -= (long) src->pub.bytes_in_buffer;
(void) my_fill_input_buffer(cinfo);
/* note we assume that fill_input_buffer will never return FALSE,
* so suspension need not be handled.
*/
}
src->pub.next_input_byte += (size_t) num_bytes;
src->pub.bytes_in_buffer -= (size_t) num_bytes;
}
}
/*
* An additional method that can be provided by data source modules is the
* resync_to_restart method for error recovery in the presence of RST markers.
* For the moment, this source module just uses the default resync method
* provided by the JPEG library. That method assumes that no backtracking
* is possible.
*/
/*
* Terminate source --- called by jpeg_finish_decompress
* after all data has been read. Often a no-op.
*
* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
* application must deal with any cleanup that should happen even
* for error exit.
*/
METHODDEF(void)
my_term_source (j_decompress_ptr cinfo)
{
/* no work necessary here */
}
/*
* Prepare for input from a stdio stream.
* The caller must have already opened the stream, and is responsible
* for closing it after finishing decompression.
*/
GLOBAL(void)
my_jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
{
my_src_ptr src;
/* The source object and input buffer are made permanent so that a series
* of JPEG images can be read from the same file by calling jpeg_stdio_src
* only before the first one. (If we discarded the buffer at the end of
* one image, we'd likely lose the start of the next one.)
* This makes it unsafe to use this manager and a different source
* manager serially with the same JPEG object. Caveat programmer.
*/
if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof(my_source_mgr));
src = (my_src_ptr) cinfo->src;
src->buffer = (JOCTET *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
INPUT_BUF_SIZE * sizeof(JOCTET));
}
src = (my_src_ptr) cinfo->src;
src->pub.init_source = my_init_source;
src->pub.fill_input_buffer = my_fill_input_buffer;
src->pub.skip_input_data = my_skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
src->pub.term_source = my_term_source;
src->infile = infile;
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
src->pub.next_input_byte = NULL; /* until buffer loaded */
}
METHODDEF(void)
my_error_exit (j_common_ptr cinfo)
{
/* Always display the message */
(*cinfo->err->output_message) (cinfo);
/* Let the memory manager delete any temp files before we die */
//jpeg_destroy(cinfo);
j_decompress_ptr dinfo = (j_decompress_ptr)cinfo;
longjmp (((rt_jpeg_error_mgr*)(dinfo->src))->error_jmp_buf, 1);
}
//const char * const jpeg_std_message_table[] = {
//#include "jerror.h"
// NULL
//};
extern const char * const jpeg_std_message_table[];
/*
* Actual output of an error or trace message.
* Applications may override this method to send JPEG messages somewhere
* other than stderr.
*
* On Windows, printing to stderr is generally completely useless,
* so we provide optional code to produce an error-dialog popup.
* Most Windows applications will still prefer to override this routine,
* but if they don't, it'll do something at least marginally useful.
*
* NOTE: to use the library in an environment that doesn't support the
* C stdio library, you may have to delete the call to fprintf() entirely,
* not just not use this routine.
*/
METHODDEF(void)
output_message (j_common_ptr cinfo)
{
char buffer[JMSG_LENGTH_MAX];
/* Create the message */
(*cinfo->err->format_message) (cinfo, buffer);
#ifdef USE_WINDOWS_MESSAGEBOX
/* Display it in a message dialog box */
MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
MB_OK | MB_ICONERROR);
#else
/* Send it to stderr, adding a newline */
fprintf(stderr, "%s\n", buffer);
#endif
}
/*
* Decide whether to emit a trace or warning message.
* msg_level is one of:
* -1: recoverable corrupt-data warning, may want to abort.
* 0: important advisory messages (always display to user).
* 1: first level of tracing detail.
* 2,3,...: successively more detailed tracing messages.
* An application might override this method if it wanted to abort on warnings
* or change the policy about which messages to display.
*/
METHODDEF(void)
emit_message (j_common_ptr cinfo, int msg_level)
{
struct jpeg_error_mgr * err = cinfo->err;
if (msg_level < 0) {
/* It's a warning message. Since corrupt files may generate many warnings,
* the policy implemented here is to show only the first warning,
* unless trace_level >= 3.
*/
if (err->num_warnings == 0 || err->trace_level >= 3)
(*err->output_message) (cinfo);
/* Always count warnings in num_warnings. */
err->num_warnings++;
} else {
/* It's a trace message. Show it if trace_level >= msg_level. */
if (err->trace_level >= msg_level)
(*err->output_message) (cinfo);
}
}
/*
* Format a message string for the most recent JPEG error or message.
* The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
* characters. Note that no '\n' character is added to the string.
* Few applications should need to override this method.
*/
METHODDEF(void)
format_message (j_common_ptr cinfo, char * buffer)
{
struct jpeg_error_mgr * err = cinfo->err;
int msg_code = err->msg_code;
const char * msgtext = NULL;
const char * msgptr;
char ch;
boolean isstring;
/* Look up message string in proper table */
if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
msgtext = err->jpeg_message_table[msg_code];
} else if (err->addon_message_table != NULL &&
msg_code >= err->first_addon_message &&
msg_code <= err->last_addon_message) {
msgtext = err->addon_message_table[msg_code - err->first_addon_message];
}
/* Defend against bogus message number */
if (msgtext == NULL) {
err->msg_parm.i[0] = msg_code;
msgtext = err->jpeg_message_table[0];
}
/* Check for string parameter, as indicated by %s in the message text */
isstring = FALSE;
msgptr = msgtext;
while ((ch = *msgptr++) != '\0') {
if (ch == '%') {
if (*msgptr == 's') isstring = TRUE;
break;
}
}
/* Format the message into the passed buffer */
if (isstring)
sprintf(buffer, msgtext, err->msg_parm.s);
else
sprintf(buffer, msgtext,
err->msg_parm.i[0], err->msg_parm.i[1],
err->msg_parm.i[2], err->msg_parm.i[3],
err->msg_parm.i[4], err->msg_parm.i[5],
err->msg_parm.i[6], err->msg_parm.i[7]);
}
/*
* Reset error state variables at start of a new image.
* This is called during compression startup to reset trace/error
* processing to default state, without losing any application-specific
* method pointers. An application might possibly want to override
* this method if it has additional error processing state.
*/
METHODDEF(void)
reset_error_mgr (j_common_ptr cinfo)
{
cinfo->err->num_warnings = 0;
/* trace_level is not reset since it is an application-supplied parameter */
cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
}
GLOBAL(struct jpeg_error_mgr *)
my_jpeg_std_error (struct jpeg_error_mgr * err)
{
err->error_exit = my_error_exit;
err->emit_message = emit_message;
err->output_message = output_message;
err->format_message = format_message;
err->reset_error_mgr = reset_error_mgr;
err->trace_level = 0; /* default = no tracing */
err->num_warnings = 0; /* no warnings emitted yet */
err->msg_code = 0; /* may be useful as a flag for "no error" */
/* Initialize message table pointers */
err->jpeg_message_table = jpeg_std_message_table;
err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
err->addon_message_table = NULL;
err->first_addon_message = 0; /* for safety */
err->last_addon_message = 0;
return err;
}

View File

@ -1,7 +1,7 @@
#ifndef _RT_JPEG_H
#define _RT_JPEG_H
#include <setjmp.h>
#include <csetjmp>
#ifdef __cplusplus
extern "C" {

View File

@ -1,169 +0,0 @@
/*
* memsrc.c
*
* Copyright (C) 1994-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains decompression data source routines for the case of
* reading JPEG data from a memory buffer that is preloaded with the entire
* JPEG file. This would not seem especially useful at first sight, but
* a number of people have asked for it.
* This is really just a stripped-down version of jdatasrc.c. Comparison
* of this code with jdatasrc.c may be helpful in seeing how to make
* custom source managers for other purposes.
*/
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
//#include "jinclude.h"
//#include "jmorecfg.h"
//#include "jpeglib.h"
//#include "jerror.h"
#include <stdio.h>
#include <jpeglib.h>
#include <jerror.h>
#include "jpeg.h"
/* Expanded data source object for memory input */
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
jmp_buf error_jmp_buf; /* error handler for this instance */
JOCTET eoi_buffer[2]; /* a place to put a dummy EOI */
} my_source_mgr;
typedef my_source_mgr * my_src_ptr;
/*
* Initialize source --- called by jpeg_read_header
* before any data is actually read.
*/
static void
init_source (j_decompress_ptr cinfo)
{
/* No work, since jpeg_memory_src set up the buffer pointer and count.
* Indeed, if we want to read multiple JPEG images from one buffer,
* this *must* not do anything to the pointer.
*/
}
/*
* Fill the input buffer --- called whenever buffer is emptied.
*
* In this application, this routine should never be called; if it is called,
* the decompressor has overrun the end of the input buffer, implying we
* supplied an incomplete or corrupt JPEG datastream. A simple error exit
* might be the most appropriate response.
*
* But what we choose to do in this code is to supply dummy EOI markers
* in order to force the decompressor to finish processing and supply
* some sort of output image, no matter how corrupted.
*/
static int
fill_input_buffer(j_decompress_ptr cinfo)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
WARNMS(cinfo, JWRN_JPEG_EOF);
/* Create a fake EOI marker */
src->eoi_buffer[0] = (JOCTET) 0xFF;
src->eoi_buffer[1] = (JOCTET) JPEG_EOI;
src->pub.next_input_byte = src->eoi_buffer;
src->pub.bytes_in_buffer = 2;
return TRUE;
}
/*
* Skip data --- used to skip over a potentially large amount of
* uninteresting data (such as an APPn marker).
*
* If we overrun the end of the buffer, we let fill_input_buffer deal with
* it. An extremely large skip could cause some time-wasting here, but
* it really isn't supposed to happen ... and the decompressor will never
* skip more than 64K anyway.
*/
static void
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
if (num_bytes > 0) {
while (num_bytes > (long) src->pub.bytes_in_buffer) {
num_bytes -= (long) src->pub.bytes_in_buffer;
(void) fill_input_buffer(cinfo);
/* note we assume that fill_input_buffer will never return FALSE,
* so suspension need not be handled.
*/
}
src->pub.next_input_byte += (size_t) num_bytes;
src->pub.bytes_in_buffer -= (size_t) num_bytes;
}
}
/*
* An additional method that can be provided by data source modules is the
* resync_to_restart method for error recovery in the presence of RST markers.
* For the moment, this source module just uses the default resync method
* provided by the JPEG library. That method assumes that no backtracking
* is possible.
*/
/*
* Terminate source --- called by jpeg_finish_decompress
* after all data has been read. Often a no-op.
*
* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
* application must deal with any cleanup that should happen even
* for error exit.
*/
static void
term_source (j_decompress_ptr cinfo)
{
/* no work necessary here */
}
/*
* Prepare for input from a memory buffer.
*/
GLOBAL(void)
jpeg_memory_src (j_decompress_ptr cinfo, const JOCTET * buffer, size_t bufsize)
{
my_src_ptr src;
/* The source object is made permanent so that a series of JPEG images
* can be read from a single buffer by calling jpeg_memory_src
* only before the first one.
* This makes it unsafe to use this manager and a different source
* manager serially with the same JPEG object. Caveat programmer.
*/
if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof(my_source_mgr));
}
src = (my_src_ptr) cinfo->src;
src->pub.init_source = init_source;
src->pub.fill_input_buffer = fill_input_buffer;
src->pub.skip_input_data = skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
src->pub.term_source = term_source;
src->pub.next_input_byte = buffer;
src->pub.bytes_in_buffer = bufsize;
}

View File

@ -1,317 +0,0 @@
/*********************************************************************
* convolve.c
*********************************************************************/
/* Standard includes */
#include <assert.h>
#include <math.h>
#include <stdlib.h> /* malloc(), realloc() */
/* Our includes */
#include "base.h"
#include "error.h"
#include "convolve.h"
#include "klt_util.h" /* printing */
#define MAX_KERNEL_WIDTH 71
typedef struct {
int width;
float data[MAX_KERNEL_WIDTH];
} ConvolutionKernel;
/* Kernels */
static ConvolutionKernel gauss_kernel;
static ConvolutionKernel gaussderiv_kernel;
static float sigma_last = -10.0;
/*********************************************************************
* _KLTToFloatImage
*
* Given a pointer to image data (probably unsigned chars), copy
* data to a float image.
*/
void _KLTToFloatImage(
KLT_PixelType *img,
int ncols, int nrows,
_KLT_FloatImage floatimg)
{
KLT_PixelType *ptrend = img + ncols*nrows;
float *ptrout = floatimg->data;
/* Output image must be large enough to hold result */
assert(floatimg->ncols >= ncols);
assert(floatimg->nrows >= nrows);
floatimg->ncols = ncols;
floatimg->nrows = nrows;
while (img < ptrend) *ptrout++ = (float) *img++;
}
/*********************************************************************
* _computeKernels
*/
static void _computeKernels(
float sigma,
ConvolutionKernel *gauss,
ConvolutionKernel *gaussderiv)
{
const float factor = 0.01f; /* for truncating tail */
int i;
assert(MAX_KERNEL_WIDTH % 2 == 1);
assert(sigma >= 0.0);
/* Compute kernels, and automatically determine widths */
{
const int hw = MAX_KERNEL_WIDTH / 2;
float max_gauss = 1.0f, max_gaussderiv = (float) (sigma*exp(-0.5f));
/* Compute gauss and deriv */
for (i = -hw ; i <= hw ; i++) {
gauss->data[i+hw] = (float) exp(-i*i / (2*sigma*sigma));
gaussderiv->data[i+hw] = -i * gauss->data[i+hw];
}
/* Compute widths */
gauss->width = MAX_KERNEL_WIDTH;
for (i = -hw ; fabs(gauss->data[i+hw] / max_gauss) < factor ;
i++, gauss->width -= 2);
gaussderiv->width = MAX_KERNEL_WIDTH;
for (i = -hw ; fabs(gaussderiv->data[i+hw] / max_gaussderiv) < factor ;
i++, gaussderiv->width -= 2);
if (gauss->width == MAX_KERNEL_WIDTH ||
gaussderiv->width == MAX_KERNEL_WIDTH)
KLTError("(_computeKernels) MAX_KERNEL_WIDTH %d is too small for "
"a sigma of %f", MAX_KERNEL_WIDTH, sigma);
}
/* Shift if width less than MAX_KERNEL_WIDTH */
for (i = 0 ; i < gauss->width ; i++)
gauss->data[i] = gauss->data[i+(MAX_KERNEL_WIDTH-gauss->width)/2];
for (i = 0 ; i < gaussderiv->width ; i++)
gaussderiv->data[i] = gaussderiv->data[i+(MAX_KERNEL_WIDTH-gaussderiv->width)/2];
/* Normalize gauss and deriv */
{
const int hw = gaussderiv->width / 2;
float den;
den = 0.0;
for (i = 0 ; i < gauss->width ; i++) den += gauss->data[i];
for (i = 0 ; i < gauss->width ; i++) gauss->data[i] /= den;
den = 0.0;
for (i = -hw ; i <= hw ; i++) den -= i*gaussderiv->data[i+hw];
for (i = -hw ; i <= hw ; i++) gaussderiv->data[i+hw] /= den;
}
sigma_last = sigma;
}
/*********************************************************************
* _KLTGetKernelWidths
*
*/
void _KLTGetKernelWidths(
float sigma,
int *gauss_width,
int *gaussderiv_width)
{
_computeKernels(sigma, &gauss_kernel, &gaussderiv_kernel);
*gauss_width = gauss_kernel.width;
*gaussderiv_width = gaussderiv_kernel.width;
}
/*********************************************************************
* _convolveImageHoriz
*/
static void _convolveImageHoriz(
_KLT_FloatImage imgin,
ConvolutionKernel kernel,
_KLT_FloatImage imgout)
{
float *ptrrow = imgin->data; /* Points to row's first pixel */
float *ptrout = imgout->data, /* Points to next output pixel */
*ppp;
float sum;
int radius = kernel.width / 2;
int ncols = imgin->ncols, nrows = imgin->nrows;
int i, j, k;
/* Kernel width must be odd */
assert(kernel.width % 2 == 1);
/* Must read from and write to different images */
assert(imgin != imgout);
/* Output image must be large enough to hold result */
assert(imgout->ncols >= imgin->ncols);
assert(imgout->nrows >= imgin->nrows);
/* For each row, do ... */
for (j = 0 ; j < nrows ; j++) {
/* Zero leftmost columns */
for (i = 0 ; i < radius ; i++)
*ptrout++ = 0.0;
/* Convolve middle columns with kernel */
for ( ; i < ncols - radius ; i++) {
ppp = ptrrow + i - radius;
sum = 0.0;
for (k = kernel.width-1 ; k >= 0 ; k--)
sum += *ppp++ * kernel.data[k];
*ptrout++ = sum;
}
/* Zero rightmost columns */
for ( ; i < ncols ; i++)
*ptrout++ = 0.0;
ptrrow += ncols;
}
}
/*********************************************************************
* _convolveImageVert
*/
static void _convolveImageVert(
_KLT_FloatImage imgin,
ConvolutionKernel kernel,
_KLT_FloatImage imgout)
{
float *ptrcol = imgin->data; /* Points to row's first pixel */
float *ptrout = imgout->data, /* Points to next output pixel */
*ppp;
float sum;
int radius = kernel.width / 2;
int ncols = imgin->ncols, nrows = imgin->nrows;
int i, j, k;
/* Kernel width must be odd */
assert(kernel.width % 2 == 1);
/* Must read from and write to different images */
assert(imgin != imgout);
/* Output image must be large enough to hold result */
assert(imgout->ncols >= imgin->ncols);
assert(imgout->nrows >= imgin->nrows);
/* For each column, do ... */
for (i = 0 ; i < ncols ; i++) {
/* Zero topmost rows */
for (j = 0 ; j < radius ; j++) {
*ptrout = 0.0;
ptrout += ncols;
}
/* Convolve middle rows with kernel */
for ( ; j < nrows - radius ; j++) {
ppp = ptrcol + ncols * (j - radius);
sum = 0.0;
for (k = kernel.width-1 ; k >= 0 ; k--) {
sum += *ppp * kernel.data[k];
ppp += ncols;
}
*ptrout = sum;
ptrout += ncols;
}
/* Zero bottommost rows */
for ( ; j < nrows ; j++) {
*ptrout = 0.0;
ptrout += ncols;
}
ptrcol++;
ptrout -= nrows * ncols - 1;
}
}
/*********************************************************************
* _convolveSeparate
*/
static void _convolveSeparate(
_KLT_FloatImage imgin,
ConvolutionKernel horiz_kernel,
ConvolutionKernel vert_kernel,
_KLT_FloatImage imgout)
{
/* Create temporary image */
_KLT_FloatImage tmpimg;
tmpimg = _KLTCreateFloatImage(imgin->ncols, imgin->nrows);
/* Do convolution */
_convolveImageHoriz(imgin, horiz_kernel, tmpimg);
_convolveImageVert(tmpimg, vert_kernel, imgout);
/* Free memory */
_KLTFreeFloatImage(tmpimg);
}
/*********************************************************************
* _KLTComputeGradients
*/
void _KLTComputeGradients(
_KLT_FloatImage img,
float sigma,
_KLT_FloatImage gradx,
_KLT_FloatImage grady)
{
/* Output images must be large enough to hold result */
assert(gradx->ncols >= img->ncols);
assert(gradx->nrows >= img->nrows);
assert(grady->ncols >= img->ncols);
assert(grady->nrows >= img->nrows);
/* Compute kernels, if necessary */
if (fabs(sigma - sigma_last) > 0.05)
_computeKernels(sigma, &gauss_kernel, &gaussderiv_kernel);
_convolveSeparate(img, gaussderiv_kernel, gauss_kernel, gradx);
_convolveSeparate(img, gauss_kernel, gaussderiv_kernel, grady);
}
/*********************************************************************
* _KLTComputeSmoothedImage
*/
void _KLTComputeSmoothedImage(
_KLT_FloatImage img,
float sigma,
_KLT_FloatImage smooth)
{
/* Output image must be large enough to hold result */
assert(smooth->ncols >= img->ncols);
assert(smooth->nrows >= img->nrows);
/* Compute kernel, if necessary; gauss_deriv is not used */
if (fabs(sigma - sigma_last) > 0.05)
_computeKernels(sigma, &gauss_kernel, &gaussderiv_kernel);
_convolveSeparate(img, gauss_kernel, gauss_kernel, smooth);
}

View File

@ -1,56 +0,0 @@
/*********************************************************************
* error.c
*
* Error and warning messages, and system commands.
*********************************************************************/
/* Standard includes */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
/*********************************************************************
* KLTError
*
* Prints an error message and dies.
*
* INPUTS
* exactly like printf
*/
void KLTError(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fprintf(stderr, "KLT Error: ");
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
exit(1);
}
/*********************************************************************
* KLTWarning
*
* Prints a warning message.
*
* INPUTS
* exactly like printf
*/
void KLTWarning(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fprintf(stderr, "KLT Warning: ");
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
fflush(stderr);
va_end(args);
}

View File

@ -5,8 +5,8 @@
#ifndef _ERROR_H_
#define _ERROR_H_
#include <stdio.h>
#include <stdarg.h>
#include <cstdio>
#include <cstdarg>
void KLTError(char *fmt, ...);
void KLTWarning(char *fmt, ...);

View File

@ -1,531 +0,0 @@
/*********************************************************************
* klt.c
*
* Kanade-Lucas-Tomasi tracker
*********************************************************************/
/* Standard includes */
#include <assert.h>
#include <math.h> /* logf() */
#include <stdlib.h> /* malloc() */
/* Our includes */
#include "base.h"
#include "convolve.h"
#include "error.h"
#include "klt.h"
#include "pyramid.h"
static const int mindist = 10;
static const int window_size = 7;
static const int min_eigenvalue = 1;
static const float min_determinant = 0.01f;
static const float min_displacement = 0.1f;
static const int max_iterations = 10;
static const float max_residue = 10.0f;
static const float grad_sigma = 1.0f;
static const float smooth_sigma_fact = 0.1f;
static const float pyramid_sigma_fact = 0.9f;
static const float step_factor = 1.0f;
static const KLT_BOOL sequentialMode = FALSE;
static const KLT_BOOL lighting_insensitive = FALSE;
/* for affine mapping*/
static const int affineConsistencyCheck = -1;
static const int affine_window_size = 15;
static const int affine_max_iterations = 10;
static const float affine_max_residue = 10.0;
static const float affine_min_displacement = 0.02f;
static const float affine_max_displacement_differ = 1.5f;
static const KLT_BOOL smoothBeforeSelecting = TRUE;
static const KLT_BOOL writeInternalImages = FALSE;
static const int search_range = 15;
static const int nSkippedPixels = 0;
extern int KLT_verbose;
/*********************************************************************
* _createArray2D
*
* Creates a two-dimensional array.
*
* INPUTS
* ncols: no. of columns
* nrows: no. of rows
* nbytes: no. of bytes per entry
*
* RETURNS
* Pointer to an array. Must be coerced.
*
* EXAMPLE
* char **ar;
* ar = (char **) createArray2D(8, 5, sizeof(char));
*/
static void** _createArray2D(int ncols, int nrows, int nbytes)
{
char **tt;
int i;
tt = (char **) malloc(nrows * sizeof(void *) +
ncols * nrows * nbytes);
if (tt == NULL)
KLTError("(createArray2D) Out of memory");
for (i = 0 ; i < nrows ; i++)
tt[i] = ((char *) tt) + (nrows * sizeof(void *) +
i * ncols * nbytes);
return((void **) tt);
}
/*********************************************************************
* KLTCreateTrackingContext
*
*/
KLT_TrackingContext KLTCreateTrackingContext()
{
KLT_TrackingContext tc;
/* Allocate memory */
tc = (KLT_TrackingContext) malloc(sizeof(KLT_TrackingContextRec));
/* Set values to default values */
tc->mindist = mindist;
tc->window_width = window_size;
tc->window_height = window_size;
tc->sequentialMode = sequentialMode;
tc->smoothBeforeSelecting = smoothBeforeSelecting;
tc->writeInternalImages = writeInternalImages;
tc->lighting_insensitive = lighting_insensitive;
tc->min_eigenvalue = min_eigenvalue;
tc->min_determinant = min_determinant;
tc->max_iterations = max_iterations;
tc->min_displacement = min_displacement;
tc->max_residue = max_residue;
tc->grad_sigma = grad_sigma;
tc->smooth_sigma_fact = smooth_sigma_fact;
tc->pyramid_sigma_fact = pyramid_sigma_fact;
tc->step_factor = step_factor;
tc->nSkippedPixels = nSkippedPixels;
tc->pyramid_last = NULL;
tc->pyramid_last_gradx = NULL;
tc->pyramid_last_grady = NULL;
/* for affine mapping */
tc->affineConsistencyCheck = affineConsistencyCheck;
tc->affine_window_width = affine_window_size;
tc->affine_window_height = affine_window_size;
tc->affine_max_iterations = affine_max_iterations;
tc->affine_max_residue = affine_max_residue;
tc->affine_min_displacement = affine_min_displacement;
tc->affine_max_displacement_differ = affine_max_displacement_differ;
/* Change nPyramidLevels and subsampling */
KLTChangeTCPyramid(tc, search_range);
/* Update border, which is dependent upon */
/* smooth_sigma_fact, pyramid_sigma_fact, window_size, and subsampling */
KLTUpdateTCBorder(tc);
return(tc);
}
/*********************************************************************
* KLTCreateFeatureList
*
*/
KLT_FeatureList KLTCreateFeatureList(
int nFeatures)
{
KLT_FeatureList fl;
KLT_Feature first;
int nbytes = sizeof(KLT_FeatureListRec) +
nFeatures * sizeof(KLT_Feature) +
nFeatures * sizeof(KLT_FeatureRec);
int i;
/* Allocate memory for feature list */
fl = (KLT_FeatureList) malloc(nbytes);
/* Set parameters */
fl->nFeatures = nFeatures;
/* Set pointers */
fl->feature = (KLT_Feature *) (fl + 1);
first = (KLT_Feature) (fl->feature + nFeatures);
for (i = 0 ; i < nFeatures ; i++) {
fl->feature[i] = first + i;
fl->feature[i]->aff_img = NULL; /* initialization fixed by Sinisa Segvic */
fl->feature[i]->aff_img_gradx = NULL;
fl->feature[i]->aff_img_grady = NULL;
}
/* Return feature list */
return(fl);
}
/*********************************************************************
* KLTCreateFeatureHistory
*
*/
KLT_FeatureHistory KLTCreateFeatureHistory(
int nFrames)
{
KLT_FeatureHistory fh;
KLT_Feature first;
int nbytes = sizeof(KLT_FeatureHistoryRec) +
nFrames * sizeof(KLT_Feature) +
nFrames * sizeof(KLT_FeatureRec);
int i;
/* Allocate memory for feature history */
fh = (KLT_FeatureHistory) malloc(nbytes);
/* Set parameters */
fh->nFrames = nFrames;
/* Set pointers */
fh->feature = (KLT_Feature *) (fh + 1);
first = (KLT_Feature) (fh->feature + nFrames);
for (i = 0 ; i < nFrames ; i++)
fh->feature[i] = first + i;
/* Return feature history */
return(fh);
}
/*********************************************************************
* KLTCreateFeatureTable
*
*/
KLT_FeatureTable KLTCreateFeatureTable(
int nFrames,
int nFeatures)
{
KLT_FeatureTable ft;
KLT_Feature first;
int nbytes = sizeof(KLT_FeatureTableRec);
int i, j;
/* Allocate memory for feature history */
ft = (KLT_FeatureTable) malloc(nbytes);
/* Set parameters */
ft->nFrames = nFrames;
ft->nFeatures = nFeatures;
/* Set pointers */
ft->feature = (KLT_Feature **)
_createArray2D(nFrames, nFeatures, sizeof(KLT_Feature));
first = (KLT_Feature) malloc(nFrames * nFeatures * sizeof(KLT_FeatureRec));
for (j = 0 ; j < nFeatures ; j++)
for (i = 0 ; i < nFrames ; i++)
ft->feature[j][i] = first + j*nFrames + i;
/* Return feature table */
return(ft);
}
/*********************************************************************
* KLTPrintTrackingContext
*/
void KLTPrintTrackingContext(
KLT_TrackingContext tc)
{
fprintf(stderr, "\n\nTracking context:\n\n");
fprintf(stderr, "\tmindist = %d\n", tc->mindist);
fprintf(stderr, "\twindow_width = %d\n", tc->window_width);
fprintf(stderr, "\twindow_height = %d\n", tc->window_height);
fprintf(stderr, "\tsequentialMode = %s\n",
tc->sequentialMode ? "TRUE" : "FALSE");
fprintf(stderr, "\tsmoothBeforeSelecting = %s\n",
tc->smoothBeforeSelecting ? "TRUE" : "FALSE");
fprintf(stderr, "\twriteInternalImages = %s\n",
tc->writeInternalImages ? "TRUE" : "FALSE");
fprintf(stderr, "\tmin_eigenvalue = %d\n", tc->min_eigenvalue);
fprintf(stderr, "\tmin_determinant = %f\n", tc->min_determinant);
fprintf(stderr, "\tmin_displacement = %f\n", tc->min_displacement);
fprintf(stderr, "\tmax_iterations = %d\n", tc->max_iterations);
fprintf(stderr, "\tmax_residue = %f\n", tc->max_residue);
fprintf(stderr, "\tgrad_sigma = %f\n", tc->grad_sigma);
fprintf(stderr, "\tsmooth_sigma_fact = %f\n", tc->smooth_sigma_fact);
fprintf(stderr, "\tpyramid_sigma_fact = %f\n", tc->pyramid_sigma_fact);
fprintf(stderr, "\tnSkippedPixels = %d\n", tc->nSkippedPixels);
fprintf(stderr, "\tborderx = %d\n", tc->borderx);
fprintf(stderr, "\tbordery = %d\n", tc->bordery);
fprintf(stderr, "\tnPyramidLevels = %d\n", tc->nPyramidLevels);
fprintf(stderr, "\tsubsampling = %d\n", tc->subsampling);
fprintf(stderr, "\n\tpyramid_last = %s\n", (tc->pyramid_last!=NULL) ?
"points to old image" : "NULL");
fprintf(stderr, "\tpyramid_last_gradx = %s\n",
(tc->pyramid_last_gradx!=NULL) ?
"points to old image" : "NULL");
fprintf(stderr, "\tpyramid_last_grady = %s\n",
(tc->pyramid_last_grady!=NULL) ?
"points to old image" : "NULL");
fprintf(stderr, "\n\n");
}
/*********************************************************************
* KLTChangeTCPyramid
*
*/
void KLTChangeTCPyramid(
KLT_TrackingContext tc,
int search_range)
{
float window_halfwidth;
float subsampling;
/* Check window size (and correct if necessary) */
if (tc->window_width % 2 != 1) {
tc->window_width = tc->window_width+1;
KLTWarning("(KLTChangeTCPyramid) Window width must be odd. "
"Changing to %d.\n", tc->window_width);
}
if (tc->window_height % 2 != 1) {
tc->window_height = tc->window_height+1;
KLTWarning("(KLTChangeTCPyramid) Window height must be odd. "
"Changing to %d.\n", tc->window_height);
}
if (tc->window_width < 3) {
tc->window_width = 3;
KLTWarning("(KLTChangeTCPyramid) Window width must be at least three. \n"
"Changing to %d.\n", tc->window_width);
}
if (tc->window_height < 3) {
tc->window_height = 3;
KLTWarning("(KLTChangeTCPyramid) Window height must be at least three. \n"
"Changing to %d.\n", tc->window_height);
}
window_halfwidth = min(tc->window_width,tc->window_height)/2.0f;
subsampling = ((float) search_range) / window_halfwidth;
if (subsampling < 1.0) { /* 1.0 = 0+1 */
tc->nPyramidLevels = 1;
} else if (subsampling <= 3.0) { /* 3.0 = 2+1 */
tc->nPyramidLevels = 2;
tc->subsampling = 2;
} else if (subsampling <= 5.0) { /* 5.0 = 4+1 */
tc->nPyramidLevels = 2;
tc->subsampling = 4;
} else if (subsampling <= 9.0) { /* 9.0 = 8+1 */
tc->nPyramidLevels = 2;
tc->subsampling = 8;
} else {
/* The following lines are derived from the formula:
search_range =
window_halfwidth * \sum_{i=0}^{nPyramidLevels-1} 8^i,
which is the same as:
search_range =
window_halfwidth * (8^nPyramidLevels - 1)/(8 - 1).
Then, the value is rounded up to the nearest integer. */
float val = (float) (log(7.0*subsampling+1.0)/log(8.0));
tc->nPyramidLevels = (int) (val + 0.99);
tc->subsampling = 8;
}
}
/*********************************************************************
* NOTE: Manually must ensure consistency with _KLTComputePyramid()
*/
static float _pyramidSigma(
KLT_TrackingContext tc)
{
return (tc->pyramid_sigma_fact * tc->subsampling);
}
/*********************************************************************
* Updates border, which is dependent upon
* smooth_sigma_fact, pyramid_sigma_fact, window_size, and subsampling
*/
void KLTUpdateTCBorder(
KLT_TrackingContext tc)
{
float val;
int pyramid_gauss_hw;
int smooth_gauss_hw;
int gauss_width, gaussderiv_width;
int num_levels = tc->nPyramidLevels;
int n_invalid_pixels;
int window_hw;
int ss = tc->subsampling;
int ss_power;
int border;
int i;
/* Check window size (and correct if necessary) */
if (tc->window_width % 2 != 1) {
tc->window_width = tc->window_width+1;
KLTWarning("(KLTUpdateTCBorder) Window width must be odd. "
"Changing to %d.\n", tc->window_width);
}
if (tc->window_height % 2 != 1) {
tc->window_height = tc->window_height+1;
KLTWarning("(KLTUpdateTCBorder) Window height must be odd. "
"Changing to %d.\n", tc->window_height);
}
if (tc->window_width < 3) {
tc->window_width = 3;
KLTWarning("(KLTUpdateTCBorder) Window width must be at least three. \n"
"Changing to %d.\n", tc->window_width);
}
if (tc->window_height < 3) {
tc->window_height = 3;
KLTWarning("(KLTUpdateTCBorder) Window height must be at least three. \n"
"Changing to %d.\n", tc->window_height);
}
window_hw = max(tc->window_width, tc->window_height)/2;
/* Find widths of convolution windows */
_KLTGetKernelWidths(_KLTComputeSmoothSigma(tc),
&gauss_width, &gaussderiv_width);
smooth_gauss_hw = gauss_width/2;
_KLTGetKernelWidths(_pyramidSigma(tc),
&gauss_width, &gaussderiv_width);
pyramid_gauss_hw = gauss_width/2;
/* Compute the # of invalid pixels at each level of the pyramid.
n_invalid_pixels is computed with respect to the ith level
of the pyramid. So, e.g., if n_invalid_pixels = 5 after
the first iteration, then there are 5 invalid pixels in
level 1, which translated means 5*subsampling invalid pixels
in the original level 0. */
n_invalid_pixels = smooth_gauss_hw;
for (i = 1 ; i < num_levels ; i++) {
val = ((float) n_invalid_pixels + pyramid_gauss_hw) / ss;
n_invalid_pixels = (int) (val + 0.99); /* Round up */
}
/* ss_power = ss^(num_levels-1) */
ss_power = 1;
for (i = 1 ; i < num_levels ; i++)
ss_power *= ss;
/* Compute border by translating invalid pixels back into */
/* original image */
border = (n_invalid_pixels + window_hw) * ss_power;
tc->borderx = border;
tc->bordery = border;
}
/*********************************************************************
* KLTFreeTrackingContext
* KLTFreeFeatureList
* KLTFreeFeatureHistory
* KLTFreeFeatureTable
*/
void KLTFreeTrackingContext(
KLT_TrackingContext tc)
{
if (tc->pyramid_last)
_KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last);
if (tc->pyramid_last_gradx)
_KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last_gradx);
if (tc->pyramid_last_grady)
_KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last_grady);
free(tc);
}
void KLTFreeFeatureList(
KLT_FeatureList fl)
{
/* for affine mapping */
int indx;
for (indx = 0 ; indx < fl->nFeatures ; indx++) {
/* free image and gradient */
_KLTFreeFloatImage(fl->feature[indx]->aff_img);
_KLTFreeFloatImage(fl->feature[indx]->aff_img_gradx);
_KLTFreeFloatImage(fl->feature[indx]->aff_img_grady);
fl->feature[indx]->aff_img = NULL;
fl->feature[indx]->aff_img_gradx = NULL;
fl->feature[indx]->aff_img_grady = NULL;
}
free(fl);
}
void KLTFreeFeatureHistory(
KLT_FeatureHistory fh)
{
free(fh);
}
void KLTFreeFeatureTable(
KLT_FeatureTable ft)
{
free(ft->feature[0][0]); /* this plugs a memory leak found by Stefan Wachter */
free(ft->feature);
free(ft);
}
/*********************************************************************
* KLTStopSequentialMode
*/
void KLTStopSequentialMode(
KLT_TrackingContext tc)
{
tc->sequentialMode = FALSE;
_KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last);
_KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last_gradx);
_KLTFreePyramid((_KLT_Pyramid) tc->pyramid_last_grady);
tc->pyramid_last = NULL;
tc->pyramid_last_gradx = NULL;
tc->pyramid_last_grady = NULL;
}
/*********************************************************************
* KLTCountRemainingFeatures
*/
int KLTCountRemainingFeatures(
KLT_FeatureList fl)
{
int count = 0;
int i;
for (i = 0 ; i < fl->nFeatures ; i++)
if (fl->feature[i]->val >= 0)
count++;
return count;
}
/*********************************************************************
* KLTSetVerbosity
*/
void KLTSetVerbosity(
int verbosity)
{
KLT_verbose = verbosity;
}

View File

@ -1,165 +0,0 @@
/*********************************************************************
* klt_util.c
*********************************************************************/
/* Standard includes */
#include <assert.h>
#include <stdlib.h> /* malloc() */
#include <math.h> /* fabs() */
/* Our includes */
#include "base.h"
#include "error.h"
#include "pnmio.h"
#include "klt.h"
#include "klt_util.h"
/*********************************************************************/
float _KLTComputeSmoothSigma(
KLT_TrackingContext tc)
{
return (tc->smooth_sigma_fact * max(tc->window_width, tc->window_height));
}
/*********************************************************************
* _KLTCreateFloatImage
*/
_KLT_FloatImage _KLTCreateFloatImage(
int ncols,
int nrows)
{
_KLT_FloatImage floatimg;
int nbytes = sizeof(_KLT_FloatImageRec) +
ncols * nrows * sizeof(float);
floatimg = (_KLT_FloatImage) malloc(nbytes);
if (floatimg == NULL)
KLTError("(_KLTCreateFloatImage) Out of memory");
floatimg->ncols = ncols;
floatimg->nrows = nrows;
floatimg->data = (float *) (floatimg + 1);
return(floatimg);
}
/*********************************************************************
* _KLTFreeFloatImage
*/
void _KLTFreeFloatImage(
_KLT_FloatImage floatimg)
{
free(floatimg);
}
/*********************************************************************
* _KLTPrintSubFloatImage
*/
void _KLTPrintSubFloatImage(
_KLT_FloatImage floatimg,
int x0, int y0,
int width, int height)
{
int ncols = floatimg->ncols;
int offset;
int i, j;
assert(x0 >= 0);
assert(y0 >= 0);
assert(x0 + width <= ncols);
assert(y0 + height <= floatimg->nrows);
fprintf(stderr, "\n");
for (j = 0 ; j < height ; j++) {
for (i = 0 ; i < width ; i++) {
offset = (j+y0)*ncols + (i+x0);
fprintf(stderr, "%6.2f ", *(floatimg->data + offset));
}
fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
}
/*********************************************************************
* _KLTWriteFloatImageToPGM
*/
void _KLTWriteFloatImageToPGM(
_KLT_FloatImage img,
char *filename)
{
int npixs = img->ncols * img->nrows;
float mmax = -999999.9f, mmin = 999999.9f;
float fact;
float *ptr;
uchar *byteimg, *ptrout;
int i;
/* Calculate minimum and maximum values of float image */
ptr = img->data;
for (i = 0 ; i < npixs ; i++) {
mmax = max(mmax, *ptr);
mmin = min(mmin, *ptr);
ptr++;
}
/* Allocate memory to hold converted image */
byteimg = (uchar *) malloc(npixs * sizeof(uchar));
/* Convert image from float to uchar */
fact = 255.0f / (mmax-mmin);
ptr = img->data;
ptrout = byteimg;
for (i = 0 ; i < npixs ; i++) {
*ptrout++ = (uchar) ((*ptr++ - mmin) * fact);
}
/* Write uchar image to PGM */
pgmWriteFile(filename, byteimg, img->ncols, img->nrows);
/* Free memory */
free(byteimg);
}
/*********************************************************************
* _KLTWriteFloatImageToPGM
*/
void _KLTWriteAbsFloatImageToPGM(
_KLT_FloatImage img,
char *filename,float scale)
{
int npixs = img->ncols * img->nrows;
float fact;
float *ptr;
uchar *byteimg, *ptrout;
int i;
float tmp;
/* Allocate memory to hold converted image */
byteimg = (uchar *) malloc(npixs * sizeof(uchar));
/* Convert image from float to uchar */
fact = 255.0f / scale;
ptr = img->data;
ptrout = byteimg;
for (i = 0 ; i < npixs ; i++) {
tmp = (float) (fabs(*ptr++) * fact);
if(tmp > 255.0) tmp = 255.0;
*ptrout++ = (uchar) tmp;
}
/* Write uchar image to PGM */
pgmWriteFile(filename, byteimg, img->ncols, img->nrows);
/* Free memory */
free(byteimg);
}

View File

@ -1,7 +1,7 @@
// main.cpp : Defines the entry point for the console application.
//
#include <stdio.h> // printf
#include <cstdio> // printf
extern "C" {
void RunExample1();

View File

@ -1,333 +0,0 @@
/*********************************************************************
* pnmio.c
*
* Various routines to manipulate PNM files.
*********************************************************************/
/* Standard includes */
#include <stdio.h> /* FILE */
#include <stdlib.h> /* malloc(), atoi() */
/* Our includes */
#include "error.h"
#define LENGTH 80
/*********************************************************************/
static void _getNextString(
FILE *fp,
char *line)
{
int i;
line[0] = '\0';
while (line[0] == '\0') {
fscanf(fp, "%s", line);
i = -1;
do {
i++;
if (line[i] == '#') {
line[i] = '\0';
while (fgetc(fp) != '\n') ;
}
} while (line[i] != '\0');
}
}
/*********************************************************************
* pnmReadHeader
*/
void pnmReadHeader(
FILE *fp,
int *magic,
int *ncols, int *nrows,
int *maxval)
{
char line[LENGTH];
/* Read magic number */
_getNextString(fp, line);
if (line[0] != 'P')
KLTError("(pnmReadHeader) Magic number does not begin with 'P', "
"but with a '%c'", line[0]);
sscanf(line, "P%d", magic);
/* Read size, skipping comments */
_getNextString(fp, line);
*ncols = atoi(line);
_getNextString(fp, line);
*nrows = atoi(line);
if (*ncols < 0 || *nrows < 0 || *ncols > 10000 || *nrows > 10000)
KLTError("(pnmReadHeader) The dimensions %d x %d are unacceptable",
*ncols, *nrows);
/* Read maxval, skipping comments */
_getNextString(fp, line);
*maxval = atoi(line);
fread(line, 1, 1, fp); /* Read newline which follows maxval */
if (*maxval != 255)
KLTWarning("(pnmReadHeader) Maxval is not 255, but %d", *maxval);
}
/*********************************************************************
* pgmReadHeader
*/
void pgmReadHeader(
FILE *fp,
int *magic,
int *ncols, int *nrows,
int *maxval)
{
pnmReadHeader(fp, magic, ncols, nrows, maxval);
if (*magic != 5)
KLTError("(pgmReadHeader) Magic number is not 'P5', but 'P%d'", *magic);
}
/*********************************************************************
* ppmReadHeader
*/
void ppmReadHeader(
FILE *fp,
int *magic,
int *ncols, int *nrows,
int *maxval)
{
pnmReadHeader(fp, magic, ncols, nrows, maxval);
if (*magic != 6)
KLTError("(ppmReadHeader) Magic number is not 'P6', but 'P%d'", *magic);
}
/*********************************************************************
* pgmReadHeaderFile
*/
void pgmReadHeaderFile(
char *fname,
int *magic,
int *ncols, int *nrows,
int *maxval)
{
FILE *fp;
/* Open file */
if ( (fp = fopen(fname, "rb")) == NULL)
KLTError("(pgmReadHeaderFile) Can't open file named '%s' for reading\n", fname);
/* Read header */
pgmReadHeader(fp, magic, ncols, nrows, maxval);
/* Close file */
fclose(fp);
}
/*********************************************************************
* ppmReadHeaderFile
*/
void ppmReadHeaderFile(
char *fname,
int *magic,
int *ncols, int *nrows,
int *maxval)
{
FILE *fp;
/* Open file */
if ( (fp = fopen(fname, "rb")) == NULL)
KLTError("(ppmReadHeaderFile) Can't open file named '%s' for reading\n", fname);
/* Read header */
ppmReadHeader(fp, magic, ncols, nrows, maxval);
/* Close file */
fclose(fp);
}
/*********************************************************************
* pgmRead
*
* NOTE: If img is NULL, memory is allocated.
*/
unsigned char* pgmRead(
FILE *fp,
unsigned char *img,
int *ncols, int *nrows)
{
unsigned char *ptr;
int magic, maxval;
int i;
/* Read header */
pgmReadHeader(fp, &magic, ncols, nrows, &maxval);
/* Allocate memory, if necessary, and set pointer */
if (img == NULL) {
ptr = (unsigned char *) malloc(*ncols * *nrows * sizeof(char));
if (ptr == NULL)
KLTError("(pgmRead) Memory not allocated");
}
else
ptr = img;
/* Read binary image data */
{
unsigned char *tmpptr = ptr;
for (i = 0 ; i < *nrows ; i++) {
fread(tmpptr, *ncols, 1, fp);
tmpptr += *ncols;
}
}
return ptr;
}
/*********************************************************************
* pgmReadFile
*
* NOTE: If img is NULL, memory is allocated.
*/
unsigned char* pgmReadFile(
char *fname,
unsigned char *img,
int *ncols, int *nrows)
{
unsigned char *ptr;
FILE *fp;
/* Open file */
if ( (fp = fopen(fname, "rb")) == NULL)
KLTError("(pgmReadFile) Can't open file named '%s' for reading\n", fname);
/* Read file */
ptr = pgmRead(fp, img, ncols, nrows);
/* Close file */
fclose(fp);
return ptr;
}
/*********************************************************************
* pgmWrite
*/
void pgmWrite(
FILE *fp,
unsigned char *img,
int ncols,
int nrows)
{
int i;
/* Write header */
fprintf(fp, "P5\n");
fprintf(fp, "%d %d\n", ncols, nrows);
fprintf(fp, "255\n");
/* Write binary data */
for (i = 0 ; i < nrows ; i++) {
fwrite(img, ncols, 1, fp);
img += ncols;
}
}
/*********************************************************************
* pgmWriteFile
*/
void pgmWriteFile(
char *fname,
unsigned char *img,
int ncols,
int nrows)
{
FILE *fp;
/* Open file */
if ( (fp = fopen(fname, "wb")) == NULL)
KLTError("(pgmWriteFile) Can't open file named '%s' for writing\n", fname);
/* Write to file */
pgmWrite(fp, img, ncols, nrows);
/* Close file */
fclose(fp);
}
/*********************************************************************
* ppmWrite
*/
void ppmWrite(
FILE *fp,
unsigned char *redimg,
unsigned char *greenimg,
unsigned char *blueimg,
int ncols,
int nrows)
{
int i, j;
/* Write header */
fprintf(fp, "P6\n");
fprintf(fp, "%d %d\n", ncols, nrows);
fprintf(fp, "255\n");
/* Write binary data */
for (j = 0 ; j < nrows ; j++) {
for (i = 0 ; i < ncols ; i++) {
fwrite(redimg, 1, 1, fp);
fwrite(greenimg, 1, 1, fp);
fwrite(blueimg, 1, 1, fp);
redimg++; greenimg++; blueimg++;
}
}
}
/*********************************************************************
* ppmWriteFileRGB
*/
void ppmWriteFileRGB(
char *fname,
unsigned char *redimg,
unsigned char *greenimg,
unsigned char *blueimg,
int ncols,
int nrows)
{
FILE *fp;
/* Open file */
if ( (fp = fopen(fname, "wb")) == NULL)
KLTError("(ppmWriteFileRGB) Can't open file named '%s' for writing\n", fname);
/* Write to file */
ppmWrite(fp, redimg, greenimg, blueimg, ncols, nrows);
/* Close file */
fclose(fp);
}

View File

@ -5,7 +5,7 @@
#ifndef _PNMIO_H_
#define _PNMIO_H_
#include <stdio.h>
#include <cstdio>
/**********
* With pgmReadFile and pgmRead, setting img to NULL causes memory

View File

@ -1,143 +0,0 @@
/*********************************************************************
* pyramid.c
*
*********************************************************************/
/* Standard includes */
#include <assert.h>
#include <stdlib.h> /* malloc() ? */
#include <string.h> /* memset() ? */
#include <math.h> /* */
/* Our includes */
#include "base.h"
#include "error.h"
#include "convolve.h" /* for computing pyramid */
#include "pyramid.h"
/*********************************************************************
*
*/
_KLT_Pyramid _KLTCreatePyramid(
int ncols,
int nrows,
int subsampling,
int nlevels)
{
_KLT_Pyramid pyramid;
int nbytes = sizeof(_KLT_PyramidRec) +
nlevels * sizeof(_KLT_FloatImage *) +
nlevels * sizeof(int) +
nlevels * sizeof(int);
int i;
if (subsampling != 2 && subsampling != 4 &&
subsampling != 8 && subsampling != 16 && subsampling != 32)
KLTError("(_KLTCreatePyramid) Pyramid's subsampling must "
"be either 2, 4, 8, 16, or 32");
/* Allocate memory for structure and set parameters */
pyramid = (_KLT_Pyramid) malloc(nbytes);
if (pyramid == NULL)
KLTError("(_KLTCreatePyramid) Out of memory");
/* Set parameters */
pyramid->subsampling = subsampling;
pyramid->nLevels = nlevels;
pyramid->img = (_KLT_FloatImage *) (pyramid + 1);
pyramid->ncols = (int *) (pyramid->img + nlevels);
pyramid->nrows = (int *) (pyramid->ncols + nlevels);
/* Allocate memory for each level of pyramid and assign pointers */
for (i = 0 ; i < nlevels ; i++) {
pyramid->img[i] = _KLTCreateFloatImage(ncols, nrows);
pyramid->ncols[i] = ncols; pyramid->nrows[i] = nrows;
ncols /= subsampling; nrows /= subsampling;
}
return pyramid;
}
/*********************************************************************
*
*/
void _KLTFreePyramid(
_KLT_Pyramid pyramid)
{
int i;
/* Free images */
for (i = 0 ; i < pyramid->nLevels ; i++)
_KLTFreeFloatImage(pyramid->img[i]);
/* Free structure */
free(pyramid);
}
/*********************************************************************
*
*/
void _KLTComputePyramid(
_KLT_FloatImage img,
_KLT_Pyramid pyramid,
float sigma_fact)
{
_KLT_FloatImage currimg, tmpimg;
int ncols = img->ncols, nrows = img->nrows;
int subsampling = pyramid->subsampling;
int subhalf = subsampling / 2;
float sigma = subsampling * sigma_fact; /* empirically determined */
int oldncols;
int i, x, y;
if (subsampling != 2 && subsampling != 4 &&
subsampling != 8 && subsampling != 16 && subsampling != 32)
KLTError("(_KLTComputePyramid) Pyramid's subsampling must "
"be either 2, 4, 8, 16, or 32");
assert(pyramid->ncols[0] == img->ncols);
assert(pyramid->nrows[0] == img->nrows);
/* Copy original image to level 0 of pyramid */
memcpy(pyramid->img[0]->data, img->data, ncols*nrows*sizeof(float));
currimg = img;
for (i = 1 ; i < pyramid->nLevels ; i++) {
tmpimg = _KLTCreateFloatImage(ncols, nrows);
_KLTComputeSmoothedImage(currimg, sigma, tmpimg);
/* Subsample */
oldncols = ncols;
ncols /= subsampling; nrows /= subsampling;
for (y = 0 ; y < nrows ; y++)
for (x = 0 ; x < ncols ; x++)
pyramid->img[i]->data[y*ncols+x] =
tmpimg->data[(subsampling*y+subhalf)*oldncols +
(subsampling*x+subhalf)];
/* Reassign current image */
currimg = pyramid->img[i];
_KLTFreeFloatImage(tmpimg);
}
}

View File

@ -1,543 +0,0 @@
/*********************************************************************
* selectGoodFeatures.c
*
*********************************************************************/
/* Standard includes */
#include <assert.h>
#include <stdlib.h> /* malloc(), qsort() */
#include <stdio.h> /* fflush() */
#include <string.h> /* memset() */
#include <math.h> /* fsqrt() */
#define fsqrt(X) sqrt(X)
/* Our includes */
#include "base.h"
#include "error.h"
#include "convolve.h"
#include "klt.h"
#include "klt_util.h"
#include "pyramid.h"
int KLT_verbose = 1;
typedef enum {SELECTING_ALL, REPLACING_SOME} selectionMode;
/*********************************************************************
* _quicksort
* Replacement for qsort(). Computing time is decreased by taking
* advantage of specific knowledge of our array (that there are
* three ints associated with each point).
*
* This routine generously provided by
* Manolis Lourakis <lourakis@csi.forth.gr>
*
* NOTE: The results of this function may be slightly different from
* those of qsort(). This is due to the fact that different sort
* algorithms have different behaviours when sorting numbers with the
* same value: Some leave them in the same relative positions in the
* array, while others change their relative positions. For example,
* if you have the array [c d b1 a b2] with b1=b2, it may be sorted as
* [a b1 b2 c d] or [a b2 b1 c d].
*/
#define SWAP3(list, i, j) \
{ int *pi, *pj, tmp; \
pi=list+3*(i); pj=list+3*(j); \
\
tmp=*pi; \
*pi++=*pj; \
*pj++=tmp; \
\
tmp=*pi; \
*pi++=*pj; \
*pj++=tmp; \
\
tmp=*pi; \
*pi=*pj; \
*pj=tmp; \
}
void _quicksort(int *pointlist, int n)
{
unsigned int i, j, ln, rn;
while (n > 1)
{
SWAP3(pointlist, 0, n/2);
for (i = 0, j = n; ; )
{
do
--j;
while (pointlist[3*j+2] < pointlist[2]);
do
++i;
while (i < j && pointlist[3*i+2] > pointlist[2]);
if (i >= j)
break;
SWAP3(pointlist, i, j);
}
SWAP3(pointlist, j, 0);
ln = j;
rn = n - ++j;
if (ln < rn)
{
_quicksort(pointlist, ln);
pointlist += 3*j;
n = rn;
}
else
{
_quicksort(pointlist + 3*j, rn);
n = ln;
}
}
}
#undef SWAP3
/*********************************************************************/
static void _fillFeaturemap(
int x, int y,
uchar *featuremap,
int mindist,
int ncols,
int nrows)
{
int ix, iy;
for (iy = y - mindist ; iy <= y + mindist ; iy++)
for (ix = x - mindist ; ix <= x + mindist ; ix++)
if (ix >= 0 && ix < ncols && iy >= 0 && iy < nrows)
featuremap[iy*ncols+ix] = 1;
}
/*********************************************************************
* _enforceMinimumDistance
*
* Removes features that are within close proximity to better features.
*
* INPUTS
* featurelist: A list of features. The nFeatures property
* is used.
*
* OUTPUTS
* featurelist: Is overwritten. Nearby "redundant" features are removed.
* Writes -1's into the remaining elements.
*
* RETURNS
* The number of remaining features.
*/
static void _enforceMinimumDistance(
int *pointlist, /* featurepoints */
int npoints, /* number of featurepoints */
KLT_FeatureList featurelist, /* features */
int ncols, int nrows, /* size of images */
int mindist, /* min. dist b/w features */
int min_eigenvalue, /* min. eigenvalue */
KLT_BOOL overwriteAllFeatures)
{
int indx; /* Index into features */
int x, y, val; /* Location and trackability of pixel under consideration */
uchar *featuremap; /* Boolean array recording proximity of features */
int *ptr;
/* Cannot add features with an eigenvalue less than one */
if (min_eigenvalue < 1) min_eigenvalue = 1;
/* Allocate memory for feature map and clear it */
featuremap = (uchar *) malloc(ncols * nrows * sizeof(uchar));
memset(featuremap, 0, ncols*nrows);
/* Necessary because code below works with (mindist-1) */
mindist--;
/* If we are keeping all old good features, then add them to the featuremap */
if (!overwriteAllFeatures)
for (indx = 0 ; indx < featurelist->nFeatures ; indx++)
if (featurelist->feature[indx]->val >= 0) {
x = (int) featurelist->feature[indx]->x;
y = (int) featurelist->feature[indx]->y;
_fillFeaturemap(x, y, featuremap, mindist, ncols, nrows);
}
/* For each feature point, in descending order of importance, do ... */
ptr = pointlist;
indx = 0;
while (1) {
/* If we can't add all the points, then fill in the rest
of the featurelist with -1's */
if (ptr >= pointlist + 3*npoints) {
while (indx < featurelist->nFeatures) {
if (overwriteAllFeatures ||
featurelist->feature[indx]->val < 0) {
featurelist->feature[indx]->x = -1;
featurelist->feature[indx]->y = -1;
featurelist->feature[indx]->val = KLT_NOT_FOUND;
featurelist->feature[indx]->aff_img = NULL;
featurelist->feature[indx]->aff_img_gradx = NULL;
featurelist->feature[indx]->aff_img_grady = NULL;
featurelist->feature[indx]->aff_x = -1.0;
featurelist->feature[indx]->aff_y = -1.0;
featurelist->feature[indx]->aff_Axx = 1.0;
featurelist->feature[indx]->aff_Ayx = 0.0;
featurelist->feature[indx]->aff_Axy = 0.0;
featurelist->feature[indx]->aff_Ayy = 1.0;
}
indx++;
}
break;
}
x = *ptr++;
y = *ptr++;
val = *ptr++;
/* Ensure that feature is in-bounds */
assert(x >= 0);
assert(x < ncols);
assert(y >= 0);
assert(y < nrows);
while (!overwriteAllFeatures &&
indx < featurelist->nFeatures &&
featurelist->feature[indx]->val >= 0)
indx++;
if (indx >= featurelist->nFeatures) break;
/* If no neighbor has been selected, and if the minimum
eigenvalue is large enough, then add feature to the current list */
if (!featuremap[y*ncols+x] && val >= min_eigenvalue) {
featurelist->feature[indx]->x = (KLT_locType) x;
featurelist->feature[indx]->y = (KLT_locType) y;
featurelist->feature[indx]->val = (int) val;
featurelist->feature[indx]->aff_img = NULL;
featurelist->feature[indx]->aff_img_gradx = NULL;
featurelist->feature[indx]->aff_img_grady = NULL;
featurelist->feature[indx]->aff_x = -1.0;
featurelist->feature[indx]->aff_y = -1.0;
featurelist->feature[indx]->aff_Axx = 1.0;
featurelist->feature[indx]->aff_Ayx = 0.0;
featurelist->feature[indx]->aff_Axy = 0.0;
featurelist->feature[indx]->aff_Ayy = 1.0;
indx++;
/* Fill in surrounding region of feature map, but
make sure that pixels are in-bounds */
_fillFeaturemap(x, y, featuremap, mindist, ncols, nrows);
}
}
/* Free feature map */
free(featuremap);
}
/*********************************************************************
* _comparePoints
*
* Used by qsort (in _KLTSelectGoodFeatures) to determine
* which feature is better.
* By switching the '>' with the '<', qsort is fooled into sorting
* in descending order.
*/
#ifdef KLT_USE_QSORT
static int _comparePoints(const void *a, const void *b)
{
int v1 = *(((int *) a) + 2);
int v2 = *(((int *) b) + 2);
if (v1 > v2) return(-1);
else if (v1 < v2) return(1);
else return(0);
}
#endif
/*********************************************************************
* _sortPointList
*/
static void _sortPointList(
int *pointlist,
int npoints)
{
#ifdef KLT_USE_QSORT
qsort(pointlist, npoints, 3*sizeof(int), _comparePoints);
#else
_quicksort(pointlist, npoints);
#endif
}
/*********************************************************************
* _minEigenvalue
*
* Given the three distinct elements of the symmetric 2x2 matrix
* [gxx gxy]
* [gxy gyy],
* Returns the minimum eigenvalue of the matrix.
*/
static float _minEigenvalue(float gxx, float gxy, float gyy)
{
return (float) ((gxx + gyy - sqrt((gxx - gyy)*(gxx - gyy) + 4*gxy*gxy))/2.0f);
}
/*********************************************************************/
void _KLTSelectGoodFeatures(
KLT_TrackingContext tc,
KLT_PixelType *img,
int ncols,
int nrows,
KLT_FeatureList featurelist,
selectionMode mode)
{
_KLT_FloatImage floatimg, gradx, grady;
int window_hw, window_hh;
int *pointlist;
int npoints = 0;
KLT_BOOL overwriteAllFeatures = (mode == SELECTING_ALL) ?
TRUE : FALSE;
KLT_BOOL floatimages_created = FALSE;
/* Check window size (and correct if necessary) */
if (tc->window_width % 2 != 1) {
tc->window_width = tc->window_width+1;
KLTWarning("Tracking context's window width must be odd. "
"Changing to %d.\n", tc->window_width);
}
if (tc->window_height % 2 != 1) {
tc->window_height = tc->window_height+1;
KLTWarning("Tracking context's window height must be odd. "
"Changing to %d.\n", tc->window_height);
}
if (tc->window_width < 3) {
tc->window_width = 3;
KLTWarning("Tracking context's window width must be at least three. \n"
"Changing to %d.\n", tc->window_width);
}
if (tc->window_height < 3) {
tc->window_height = 3;
KLTWarning("Tracking context's window height must be at least three. \n"
"Changing to %d.\n", tc->window_height);
}
window_hw = tc->window_width/2;
window_hh = tc->window_height/2;
/* Create pointlist, which is a simplified version of a featurelist, */
/* for speed. Contains only integer locations and values. */
pointlist = (int *) malloc(ncols * nrows * 3 * sizeof(int));
/* Create temporary images, etc. */
if (mode == REPLACING_SOME &&
tc->sequentialMode && tc->pyramid_last != NULL) {
floatimg = ((_KLT_Pyramid) tc->pyramid_last)->img[0];
gradx = ((_KLT_Pyramid) tc->pyramid_last_gradx)->img[0];
grady = ((_KLT_Pyramid) tc->pyramid_last_grady)->img[0];
assert(gradx != NULL);
assert(grady != NULL);
} else {
floatimages_created = TRUE;
floatimg = _KLTCreateFloatImage(ncols, nrows);
gradx = _KLTCreateFloatImage(ncols, nrows);
grady = _KLTCreateFloatImage(ncols, nrows);
if (tc->smoothBeforeSelecting) {
_KLT_FloatImage tmpimg;
tmpimg = _KLTCreateFloatImage(ncols, nrows);
_KLTToFloatImage(img, ncols, nrows, tmpimg);
_KLTComputeSmoothedImage(tmpimg, _KLTComputeSmoothSigma(tc), floatimg);
_KLTFreeFloatImage(tmpimg);
} else _KLTToFloatImage(img, ncols, nrows, floatimg);
/* Compute gradient of image in x and y direction */
_KLTComputeGradients(floatimg, tc->grad_sigma, gradx, grady);
}
/* Write internal images */
if (tc->writeInternalImages) {
_KLTWriteFloatImageToPGM(floatimg, "kltimg_sgfrlf.pgm");
_KLTWriteFloatImageToPGM(gradx, "kltimg_sgfrlf_gx.pgm");
_KLTWriteFloatImageToPGM(grady, "kltimg_sgfrlf_gy.pgm");
}
/* Compute trackability of each image pixel as the minimum
of the two eigenvalues of the Z matrix */
{
float gx, gy;
float gxx, gxy, gyy;
int xx, yy;
int *ptr;
float val;
unsigned int limit = 1;
int borderx = tc->borderx; /* Must not touch cols */
int bordery = tc->bordery; /* lost by convolution */
int x, y;
int i;
if (borderx < window_hw) borderx = window_hw;
if (bordery < window_hh) bordery = window_hh;
/* Find largest value of an int */
for (i = 0 ; i < sizeof(int) ; i++) limit *= 256;
limit = limit/2 - 1;
/* For most of the pixels in the image, do ... */
ptr = pointlist;
for (y = bordery ; y < nrows - bordery ; y += tc->nSkippedPixels + 1)
for (x = borderx ; x < ncols - borderx ; x += tc->nSkippedPixels + 1) {
/* Sum the gradients in the surrounding window */
gxx = 0; gxy = 0; gyy = 0;
for (yy = y-window_hh ; yy <= y+window_hh ; yy++)
for (xx = x-window_hw ; xx <= x+window_hw ; xx++) {
gx = *(gradx->data + ncols*yy+xx);
gy = *(grady->data + ncols*yy+xx);
gxx += gx * gx;
gxy += gx * gy;
gyy += gy * gy;
}
/* Store the trackability of the pixel as the minimum
of the two eigenvalues */
*ptr++ = x;
*ptr++ = y;
val = _minEigenvalue(gxx, gxy, gyy);
if (val > limit) {
KLTWarning("(_KLTSelectGoodFeatures) minimum eigenvalue %f is "
"greater than the capacity of an int; setting "
"to maximum value", val);
val = (float) limit;
}
*ptr++ = (int) val;
npoints++;
}
}
/* Sort the features */
_sortPointList(pointlist, npoints);
/* Check tc->mindist */
if (tc->mindist < 0) {
KLTWarning("(_KLTSelectGoodFeatures) Tracking context field tc->mindist "
"is negative (%d); setting to zero", tc->mindist);
tc->mindist = 0;
}
/* Enforce minimum distance between features */
_enforceMinimumDistance(
pointlist,
npoints,
featurelist,
ncols, nrows,
tc->mindist,
tc->min_eigenvalue,
overwriteAllFeatures);
/* Free memory */
free(pointlist);
if (floatimages_created) {
_KLTFreeFloatImage(floatimg);
_KLTFreeFloatImage(gradx);
_KLTFreeFloatImage(grady);
}
}
/*********************************************************************
* KLTSelectGoodFeatures
*
* Main routine, visible to the outside. Finds the good features in
* an image.
*
* INPUTS
* tc: Contains parameters used in computation (size of image,
* size of window, min distance b/w features, sigma to compute
* image gradients, # of features desired).
* img: Pointer to the data of an image (probably unsigned chars).
*
* OUTPUTS
* features: List of features. The member nFeatures is computed.
*/
void KLTSelectGoodFeatures(
KLT_TrackingContext tc,
KLT_PixelType *img,
int ncols,
int nrows,
KLT_FeatureList fl)
{
if (KLT_verbose >= 1) {
fprintf(stderr, "(KLT) Selecting the %d best features "
"from a %d by %d image... ", fl->nFeatures, ncols, nrows);
fflush(stderr);
}
_KLTSelectGoodFeatures(tc, img, ncols, nrows,
fl, SELECTING_ALL);
if (KLT_verbose >= 1) {
fprintf(stderr, "\n\t%d features found.\n",
KLTCountRemainingFeatures(fl));
if (tc->writeInternalImages)
fprintf(stderr, "\tWrote images to 'kltimg_sgfrlf*.pgm'.\n");
fflush(stderr);
}
}
/*********************************************************************
* KLTReplaceLostFeatures
*
* Main routine, visible to the outside. Replaces the lost features
* in an image.
*
* INPUTS
* tc: Contains parameters used in computation (size of image,
* size of window, min distance b/w features, sigma to compute
* image gradients, # of features desired).
* img: Pointer to the data of an image (probably unsigned chars).
*
* OUTPUTS
* features: List of features. The member nFeatures is computed.
*/
void KLTReplaceLostFeatures(
KLT_TrackingContext tc,
KLT_PixelType *img,
int ncols,
int nrows,
KLT_FeatureList fl)
{
int nLostFeatures = fl->nFeatures - KLTCountRemainingFeatures(fl);
if (KLT_verbose >= 1) {
fprintf(stderr, "(KLT) Attempting to replace %d features "
"in a %d by %d image... ", nLostFeatures, ncols, nrows);
fflush(stderr);
}
/* If there are any lost features, replace them */
if (nLostFeatures > 0)
_KLTSelectGoodFeatures(tc, img, ncols, nrows,
fl, REPLACING_SOME);
if (KLT_verbose >= 1) {
fprintf(stderr, "\n\t%d features replaced.\n",
nLostFeatures - fl->nFeatures + KLTCountRemainingFeatures(fl));
if (tc->writeInternalImages)
fprintf(stderr, "\tWrote images to 'kltimg_sgfrlf*.pgm'.\n");
fflush(stderr);
}
}

View File

@ -1,117 +0,0 @@
/*********************************************************************
* storeFeatures.c
*
*********************************************************************/
/* Our includes */
#include "error.h"
#include "klt.h"
/*********************************************************************
*
*/
void KLTStoreFeatureList(
KLT_FeatureList fl,
KLT_FeatureTable ft,
int frame)
{
int feat;
if (frame < 0 || frame >= ft->nFrames)
KLTError("(KLTStoreFeatures) Frame number %d is not between 0 and %d",
frame, ft->nFrames - 1);
if (fl->nFeatures != ft->nFeatures)
KLTError("(KLTStoreFeatures) FeatureList and FeatureTable must "
"have the same number of features");
for (feat = 0 ; feat < fl->nFeatures ; feat++) {
ft->feature[feat][frame]->x = fl->feature[feat]->x;
ft->feature[feat][frame]->y = fl->feature[feat]->y;
ft->feature[feat][frame]->val = fl->feature[feat]->val;
}
}
/*********************************************************************
*
*/
void KLTExtractFeatureList(
KLT_FeatureList fl,
KLT_FeatureTable ft,
int frame)
{
int feat;
if (frame < 0 || frame >= ft->nFrames)
KLTError("(KLTExtractFeatures) Frame number %d is not between 0 and %d",
frame, ft->nFrames - 1);
if (fl->nFeatures != ft->nFeatures)
KLTError("(KLTExtractFeatures) FeatureList and FeatureTable must "
"have the same number of features");
for (feat = 0 ; feat < fl->nFeatures ; feat++) {
fl->feature[feat]->x = ft->feature[feat][frame]->x;
fl->feature[feat]->y = ft->feature[feat][frame]->y;
fl->feature[feat]->val = ft->feature[feat][frame]->val;
}
}
/*********************************************************************
*
*/
void KLTStoreFeatureHistory(
KLT_FeatureHistory fh,
KLT_FeatureTable ft,
int feat)
{
int frame;
if (feat < 0 || feat >= ft->nFeatures)
KLTError("(KLTStoreFeatureHistory) Feature number %d is not between 0 and %d",
feat, ft->nFeatures - 1);
if (fh->nFrames != ft->nFrames)
KLTError("(KLTStoreFeatureHistory) FeatureHistory and FeatureTable must "
"have the same number of frames");
for (frame = 0 ; frame < fh->nFrames ; frame++) {
ft->feature[feat][frame]->x = fh->feature[frame]->x;
ft->feature[feat][frame]->y = fh->feature[frame]->y;
ft->feature[feat][frame]->val = fh->feature[frame]->val;
}
}
/*********************************************************************
*
*/
void KLTExtractFeatureHistory(
KLT_FeatureHistory fh,
KLT_FeatureTable ft,
int feat)
{
int frame;
if (feat < 0 || feat >= ft->nFeatures)
KLTError("(KLTExtractFeatureHistory) Feature number %d is not between 0 and %d",
feat, ft->nFeatures - 1);
if (fh->nFrames != ft->nFrames)
KLTError("(KLTExtractFeatureHistory) FeatureHistory and FeatureTable must "
"have the same number of frames");
for (frame = 0 ; frame < fh->nFrames ; frame++) {
fh->feature[frame]->x = ft->feature[feat][frame]->x;
fh->feature[frame]->y = ft->feature[feat][frame]->y;
fh->feature[frame]->val = ft->feature[feat][frame]->val;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,743 +0,0 @@
/*********************************************************************
* writeFeatures.c
*
*********************************************************************
*/
/* Standard includes */
#include <assert.h>
#include <ctype.h> /* isdigit() */
#include <stdio.h> /* sprintf(), fprintf(), sscanf(), fscanf() */
#include <stdlib.h> /* malloc() */
#include <string.h> /* memcpy(), strcmp() */
/* Our includes */
#include "base.h"
#include "error.h"
#include "pnmio.h" /* ppmWriteFileRGB() */
#include "klt.h"
#define BINHEADERLENGTH 6
extern int KLT_verbose;
typedef enum {FEATURE_LIST, FEATURE_HISTORY, FEATURE_TABLE} structureType;
static char warning_line[] = "!!! Warning: This is a KLT data file. "
"Do not modify below this line !!!\n";
static char binheader_fl[BINHEADERLENGTH+1] = "KLTFL1";
static char binheader_fh[BINHEADERLENGTH+1] = "KLTFH1";
static char binheader_ft[BINHEADERLENGTH+1] = "KLTFT1";
/*********************************************************************
* KLTWriteFeatureListToPPM
*/
void KLTWriteFeatureListToPPM(
KLT_FeatureList featurelist,
KLT_PixelType *greyimg,
int ncols,
int nrows,
char *filename)
{
int nbytes = ncols * nrows * sizeof(char);
uchar *redimg, *grnimg, *bluimg;
int offset;
int x, y, xx, yy;
int i;
if (KLT_verbose >= 1)
fprintf(stderr, "(KLT) Writing %d features to PPM file: '%s'\n",
KLTCountRemainingFeatures(featurelist), filename);
/* Allocate memory for component images */
redimg = (uchar *) malloc(nbytes);
grnimg = (uchar *) malloc(nbytes);
bluimg = (uchar *) malloc(nbytes);
if (redimg == NULL || grnimg == NULL || bluimg == NULL)
KLTError("(KLTWriteFeaturesToPPM) Out of memory\n");
/* Copy grey image to component images */
if (sizeof(KLT_PixelType) != 1)
KLTWarning("(KLTWriteFeaturesToPPM) KLT_PixelType is not uchar");
memcpy(redimg, greyimg, nbytes);
memcpy(grnimg, greyimg, nbytes);
memcpy(bluimg, greyimg, nbytes);
/* Overlay features in red */
for (i = 0 ; i < featurelist->nFeatures ; i++)
if (featurelist->feature[i]->val >= 0) {
x = (int) (featurelist->feature[i]->x + 0.5);
y = (int) (featurelist->feature[i]->y + 0.5);
for (yy = y - 1 ; yy <= y + 1 ; yy++)
for (xx = x - 1 ; xx <= x + 1 ; xx++)
if (xx >= 0 && yy >= 0 && xx < ncols && yy < nrows) {
offset = yy * ncols + xx;
*(redimg + offset) = 255;
*(grnimg + offset) = 0;
*(bluimg + offset) = 0;
}
}
/* Write to PPM file */
ppmWriteFileRGB(filename, redimg, grnimg, bluimg, ncols, nrows);
/* Free memory */
free(redimg);
free(grnimg);
free(bluimg);
}
static FILE* _printSetupTxt(
char *fname, /* Input: filename, or NULL for stderr */
char *fmt, /* Input: format (e.g., %5.1f or %3d) */
char *format, /* Output: format (e.g., (%5.1f,%5.1f)=%3d) */
char *type) /* Output: either 'f' or 'd', based on input format */
{
FILE *fp;
const int val_width = 5;
int i;
/* Either open file or use stderr */
if (fname == NULL) fp = stderr;
else fp = fopen(fname, "wb");
if (fp == NULL)
KLTError("(KLTWriteFeatures) "
"Can't open file '%s' for writing\n", fname);
/* Parse format */
if (fmt[0] != '%')
KLTError("(KLTWriteFeatures) Bad Format: %s\n", fmt);
i = 0; while (fmt[i] != '\0') i++; *type = fmt[i-1];
if (*type != 'f' && *type != 'd')
KLTError("(KLTWriteFeatures) Format must end in 'f' or 'd'.");
/* Construct feature format */
sprintf(format, "(%s,%s)=%%%dd ", fmt, fmt, val_width);
return fp;
}
static FILE* _printSetupBin(
char *fname) /* Input: filename */
{
FILE *fp;
if (fname == NULL)
KLTError("(KLTWriteFeatures) Can't write binary data to stderr");
fp = fopen(fname, "wb");
if (fp == NULL)
KLTError("(KLTWriteFeatures) "
"Can't open file '%s' for writing", fname);
return fp;
}
static void _printNhyphens(
FILE *fp,
int n)
{
int i;
for (i = 0 ; i < n ; i++)
fprintf(fp, "-");
}
static void _printInteger(
FILE *fp,
int integer,
int width)
{
char fmt[80];
sprintf(fmt, "%%%dd", width);
fprintf(fp, fmt, integer);
}
static KLT_BOOL _isCharInString(
char c,
char *str)
{
int width = strlen(str);
int i;
for (i = 0 ; i < width ; i++)
if (c == str[i]) return TRUE;
return FALSE;
}
/*********************************************************************
* _findStringWidth
*
* Calculates the length of a string after expansion. E.g., the
* length of "(%6.1f)" is eight -- six for the floating-point number,
* and two for the parentheses.
*/
static int _findStringWidth(
char *str)
{
int width = 0;
int add;
int maxi = strlen(str) - 1;
int i = 0;
while (str[i] != '\0') {
if (str[i] == '%') {
if (isdigit(str[i+1])) {
sscanf(str+i+1, "%d", &add);
width += add;
i += 2;
while (!_isCharInString(str[i], "diouxefgn")) {
i++;
if (i > maxi)
KLTError("(_findStringWidth) Can't determine length "
"of string '%s'", str);
}
i++;
} else if (str[i+1] == 'c') {
width++;
i += 2;
} else
KLTError("(_findStringWidth) Can't determine length "
"of string '%s'", str);
} else {
i++;
width++;
}
}
return width;
}
static void _printHeader(
FILE *fp,
char *format,
structureType id,
int nFrames,
int nFeatures)
{
int width = _findStringWidth(format);
int i;
assert(id == FEATURE_LIST || id == FEATURE_HISTORY || id == FEATURE_TABLE);
if (fp != stderr) {
fprintf(fp, "Feel free to place comments here.\n\n\n");
fprintf(fp, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
fprintf(fp, "%s", warning_line);
fprintf(fp, "\n");
}
fprintf(fp, "------------------------------\n");
switch (id) {
case FEATURE_LIST: fprintf(fp, "KLT Feature List\n"); break;
case FEATURE_HISTORY: fprintf(fp, "KLT Feature History\n"); break;
case FEATURE_TABLE: fprintf(fp, "KLT Feature Table\n"); break;
}
fprintf(fp, "------------------------------\n\n");
switch (id) {
case FEATURE_LIST: fprintf(fp, "nFeatures = %d\n\n", nFeatures); break;
case FEATURE_HISTORY: fprintf(fp, "nFrames = %d\n\n", nFrames); break;
case FEATURE_TABLE: fprintf(fp, "nFrames = %d, nFeatures = %d\n\n",
nFrames, nFeatures); break;
}
switch (id) {
case FEATURE_LIST: fprintf(fp, "feature | (x,y)=val\n");
fprintf(fp, "--------+-");
_printNhyphens(fp, width);
fprintf(fp, "\n");
break;
case FEATURE_HISTORY: fprintf(fp, "frame | (x,y)=val\n");
fprintf(fp, "------+-");
_printNhyphens(fp, width);
fprintf(fp, "\n");
break;
case FEATURE_TABLE: fprintf(fp, "feature | frame\n");
fprintf(fp, " |");
for (i = 0 ; i < nFrames ; i++) _printInteger(fp, i, width);
fprintf(fp, "\n--------+-");
for (i = 0 ; i < nFrames ; i++) _printNhyphens(fp, width);
fprintf(fp, "\n");
break;
}
}
static void _printFeatureTxt(
FILE *fp,
KLT_Feature feat,
char *format,
char type)
{
assert(type == 'f' || type == 'd');
if (type == 'f')
fprintf(fp, format, (float) feat->x, (float) feat->y, feat->val);
else if (type == 'd') {
/* Round x & y to nearest integer, unless negative */
float x = feat->x;
float y = feat->y;
if (x >= 0.0) x += 0.5;
if (y >= 0.0) y += 0.5;
fprintf(fp, format,
(int) x, (int) y, feat->val);
}
}
static void _printFeatureBin(
FILE *fp,
KLT_Feature feat)
{
fwrite(&(feat->x), sizeof(KLT_locType), 1, fp);
fwrite(&(feat->y), sizeof(KLT_locType), 1, fp);
fwrite(&(feat->val), sizeof(int), 1, fp);
}
static void _printShutdown(
FILE *fp)
{
/* Close file, if necessary */
if (fp != stderr)
fclose(fp);
}
/*********************************************************************
* KLTWriteFeatureList()
* KLTWriteFeatureHistory()
* KLTWriteFeatureTable()
*
* Writes features to file or to screen.
*
* INPUTS
* fname: name of file to write data; if NULL, then print to stderr
* fmt: format for printing (e.g., "%5.1f" or "%3d");
* if NULL, and if fname is not NULL, then write to binary file.
*/
void KLTWriteFeatureList(
KLT_FeatureList fl,
char *fname,
char *fmt)
{
FILE *fp;
char format[100];
char type;
int i;
if (KLT_verbose >= 1 && fname != NULL) {
fprintf(stderr,
"(KLT) Writing feature list to %s file: '%s'\n",
(fmt == NULL ? "binary" : "text"), fname);
}
if (fmt != NULL) { /* text file or stderr */
fp = _printSetupTxt(fname, fmt, format, &type);
_printHeader(fp, format, FEATURE_LIST, 0, fl->nFeatures);
for (i = 0 ; i < fl->nFeatures ; i++) {
fprintf(fp, "%7d | ", i);
_printFeatureTxt(fp, fl->feature[i], format, type);
fprintf(fp, "\n");
}
_printShutdown(fp);
} else { /* binary file */
fp = _printSetupBin(fname);
fwrite(binheader_fl, sizeof(char), BINHEADERLENGTH, fp);
fwrite(&(fl->nFeatures), sizeof(int), 1, fp);
for (i = 0 ; i < fl->nFeatures ; i++) {
_printFeatureBin(fp, fl->feature[i]);
}
fclose(fp);
}
}
void KLTWriteFeatureHistory(
KLT_FeatureHistory fh,
char *fname,
char *fmt)
{
FILE *fp;
char format[100];
char type;
int i;
if (KLT_verbose >= 1 && fname != NULL) {
fprintf(stderr,
"(KLT) Writing feature history to %s file: '%s'\n",
(fmt == NULL ? "binary" : "text"), fname);
}
if (fmt != NULL) { /* text file or stderr */
fp = _printSetupTxt(fname, fmt, format, &type);
_printHeader(fp, format, FEATURE_HISTORY, fh->nFrames, 0);
for (i = 0 ; i < fh->nFrames ; i++) {
fprintf(fp, "%5d | ", i);
_printFeatureTxt(fp, fh->feature[i], format, type);
fprintf(fp, "\n");
}
_printShutdown(fp);
} else { /* binary file */
fp = _printSetupBin(fname);
fwrite(binheader_fh, sizeof(char), BINHEADERLENGTH, fp);
fwrite(&(fh->nFrames), sizeof(int), 1, fp);
for (i = 0 ; i < fh->nFrames ; i++) {
_printFeatureBin(fp, fh->feature[i]);
}
fclose(fp);
}
}
void KLTWriteFeatureTable(
KLT_FeatureTable ft,
char *fname,
char *fmt)
{
FILE *fp;
char format[100];
char type;
int i, j;
if (KLT_verbose >= 1 && fname != NULL) {
fprintf(stderr,
"(KLT) Writing feature table to %s file: '%s'\n",
(fmt == NULL ? "binary" : "text"), fname);
}
if (fmt != NULL) { /* text file or stderr */
fp = _printSetupTxt(fname, fmt, format, &type);
_printHeader(fp, format, FEATURE_TABLE, ft->nFrames, ft->nFeatures);
for (j = 0 ; j < ft->nFeatures ; j++) {
fprintf(fp, "%7d | ", j);
for (i = 0 ; i < ft->nFrames ; i++)
_printFeatureTxt(fp, ft->feature[j][i], format, type);
fprintf(fp, "\n");
}
_printShutdown(fp);
} else { /* binary file */
fp = _printSetupBin(fname);
fwrite(binheader_ft, sizeof(char), BINHEADERLENGTH, fp);
fwrite(&(ft->nFrames), sizeof(int), 1, fp);
fwrite(&(ft->nFeatures), sizeof(int), 1, fp);
for (j = 0 ; j < ft->nFeatures ; j++) {
for (i = 0 ; i < ft->nFrames ; i++) {
_printFeatureBin(fp, ft->feature[j][i]);
}
}
fclose(fp);
}
}
static structureType _readHeader(
FILE *fp,
int *nFrames,
int *nFeatures,
KLT_BOOL *binary)
{
#define LINELENGTH 100
char line[LINELENGTH];
structureType id;
/* If file is binary, then read data and return */
fread(line, sizeof(char), BINHEADERLENGTH, fp);
line[BINHEADERLENGTH] = 0;
if (strcmp(line, binheader_fl) == 0) {
assert(nFeatures != NULL);
fread(nFeatures, sizeof(int), 1, fp);
*binary = TRUE;
return FEATURE_LIST;
} else if (strcmp(line, binheader_fh) == 0) {
assert(nFrames != NULL);
fread(nFrames, sizeof(int), 1, fp);
*binary = TRUE;
return FEATURE_HISTORY;
} else if (strcmp(line, binheader_ft) == 0) {
assert(nFrames != NULL);
assert(nFeatures != NULL);
fread(nFrames, sizeof(int), 1, fp);
fread(nFeatures, sizeof(int), 1, fp);
*binary = TRUE;
return FEATURE_TABLE;
/* If file is NOT binary, then continue.*/
} else {
rewind(fp);
*binary = FALSE;
}
/* Skip comments until warning line */
while (strcmp(line, warning_line) != 0) {
fgets(line, LINELENGTH, fp);
if (feof(fp))
KLTError("(_readFeatures) File is corrupted -- Couldn't find line:\n"
"\t%s\n", warning_line);
}
/* Read 'Feature List', 'Feature History', or 'Feature Table' */
while (fgetc(fp) != '-');
while (fgetc(fp) != '\n');
fgets(line, LINELENGTH, fp);
if (strcmp(line, "KLT Feature List\n") == 0) id = FEATURE_LIST;
else if (strcmp(line, "KLT Feature History\n") == 0) id = FEATURE_HISTORY;
else if (strcmp(line, "KLT Feature Table\n") == 0) id = FEATURE_TABLE;
else
KLTError("(_readFeatures) File is corrupted -- (Not 'KLT Feature List', "
"'KLT Feature History', or 'KLT Feature Table')");
/* If there's an incompatibility between the type of file */
/* and the parameters passed, exit now before we attempt */
/* to write to non-allocated memory. Higher routine should */
/* detect and handle this error. */
if ((id == FEATURE_LIST && nFeatures == NULL) ||
(id == FEATURE_HISTORY && nFrames == NULL) ||
(id == FEATURE_TABLE && (nFeatures == NULL || nFrames == NULL)))
return id;
/* Read nFeatures and nFrames */
while (fgetc(fp) != '-');
while (fgetc(fp) != '\n');
fscanf(fp, "%s", line);
if (id == FEATURE_LIST) {
if (strcmp(line, "nFeatures") != 0)
KLTError("(_readFeatures) File is corrupted -- "
"(Expected 'nFeatures', found '%s' instead)", line);
} else if (strcmp(line, "nFrames") != 0)
KLTError("(_readFeatures) File is corrupted -- "
"(Expected 'nFrames', found '%s' instead)", line);
fscanf(fp, "%s", line);
if (strcmp(line, "=") != 0)
KLTError("(_readFeatures) File is corrupted -- "
"(Expected '=', found '%s' instead)", line);
if (id == FEATURE_LIST) fscanf(fp, "%d", nFeatures);
else fscanf(fp, "%d", nFrames);
/* If 'Feature Table', then also get nFeatures */
if (id == FEATURE_TABLE) {
fscanf(fp, "%s", line);
if (strcmp(line, ",") != 0)
KLTError("(_readFeatures) File '%s' is corrupted -- "
"(Expected 'comma', found '%s' instead)", line);
fscanf(fp, "%s", line);
if (strcmp(line, "nFeatures") != 0)
KLTError("(_readFeatures) File '%s' is corrupted -- "
"(2 Expected 'nFeatures ', found '%s' instead)", line);
fscanf(fp, "%s", line);
if (strcmp(line, "=") != 0)
KLTError("(_readFeatures) File '%s' is corrupted -- "
"(2 Expected '= ', found '%s' instead)", line);
fscanf(fp, "%d", nFeatures);
}
/* Skip junk before data */
while (fgetc(fp) != '-');
while (fgetc(fp) != '\n');
return id;
#undef LINELENGTH
}
static void _readFeatureTxt(
FILE *fp,
KLT_Feature feat)
{
while (fgetc(fp) != '(');
fscanf(fp, "%f,%f)=%d", &(feat->x), &(feat->y), &(feat->val));
}
static void _readFeatureBin(
FILE *fp,
KLT_Feature feat)
{
fread(&(feat->x), sizeof(KLT_locType), 1, fp);
fread(&(feat->y), sizeof(KLT_locType), 1, fp);
fread(&(feat->val), sizeof(int), 1, fp);
}
/*********************************************************************
* KLTReadFeatureList
* KLTReadFeatureHistory
* KLTReadFeatureTable
*
* If the first parameter (fl, fh, or ft) is NULL, then the
* corresponding structure is created.
*/
KLT_FeatureList KLTReadFeatureList(
KLT_FeatureList fl_in,
char *fname)
{
FILE *fp;
KLT_FeatureList fl;
int nFeatures;
structureType id;
int indx;
KLT_BOOL binary; /* whether file is binary or text */
int i;
fp = fopen(fname, "rb");
if (fp == NULL) KLTError("(KLTReadFeatureList) Can't open file '%s' "
"for reading", fname);
if (KLT_verbose >= 1)
fprintf(stderr, "(KLT) Reading feature list from '%s'\n", fname);
id = _readHeader(fp, NULL, &nFeatures, &binary);
if (id != FEATURE_LIST)
KLTError("(KLTReadFeatureList) File '%s' does not contain "
"a FeatureList", fname);
if (fl_in == NULL) {
fl = KLTCreateFeatureList(nFeatures);
fl->nFeatures = nFeatures;
}
else {
fl = fl_in;
if (fl->nFeatures != nFeatures)
KLTError("(KLTReadFeatureList) The feature list passed "
"does not contain the same number of features as "
"the feature list in file '%s' ", fname);
}
if (!binary) { /* text file */
for (i = 0 ; i < fl->nFeatures ; i++) {
fscanf(fp, "%d |", &indx);
if (indx != i) KLTError("(KLTReadFeatureList) Bad index at i = %d"
"-- %d", i, indx);
_readFeatureTxt(fp, fl->feature[i]);
}
} else { /* binary file */
for (i = 0 ; i < fl->nFeatures ; i++) {
_readFeatureBin(fp, fl->feature[i]);
}
}
fclose(fp);
return fl;
}
KLT_FeatureHistory KLTReadFeatureHistory(
KLT_FeatureHistory fh_in,
char *fname)
{
FILE *fp;
KLT_FeatureHistory fh;
int nFrames;
structureType id;
int indx;
KLT_BOOL binary; /* whether file is binary or text */
int i;
fp = fopen(fname, "rb");
if (fp == NULL) KLTError("(KLTReadFeatureHistory) Can't open file '%s' "
"for reading", fname);
if (KLT_verbose >= 1) fprintf(stderr, "(KLT) Reading feature history from '%s'\n", fname);
id = _readHeader(fp, &nFrames, NULL, &binary);
if (id != FEATURE_HISTORY) KLTError("(KLTReadFeatureHistory) File '%s' does not contain "
"a FeatureHistory", fname);
if (fh_in == NULL) {
fh = KLTCreateFeatureHistory(nFrames);
fh->nFrames = nFrames;
}
else {
fh = fh_in;
if (fh->nFrames != nFrames)
KLTError("(KLTReadFeatureHistory) The feature history passed "
"does not contain the same number of frames as "
"the feature history in file '%s' ", fname);
}
if (!binary) { /* text file */
for (i = 0 ; i < fh->nFrames ; i++) {
fscanf(fp, "%d |", &indx);
if (indx != i)
KLTError("(KLTReadFeatureHistory) Bad index at i = %d"
"-- %d", i, indx);
_readFeatureTxt(fp, fh->feature[i]);
}
} else { /* binary file */
for (i = 0 ; i < fh->nFrames ; i++) {
_readFeatureBin(fp, fh->feature[i]);
}
}
fclose(fp);
return fh;
}
KLT_FeatureTable KLTReadFeatureTable(
KLT_FeatureTable ft_in,
char *fname)
{
FILE *fp;
KLT_FeatureTable ft;
int nFrames;
int nFeatures;
structureType id;
int indx;
KLT_BOOL binary; /* whether file is binary or text */
int i, j;
fp = fopen(fname, "rb");
if (fp == NULL) KLTError("(KLTReadFeatureTable) Can't open file '%s' "
"for reading", fname);
if (KLT_verbose >= 1) fprintf(stderr, "(KLT) Reading feature table from '%s'\n", fname);
id = _readHeader(fp, &nFrames, &nFeatures, &binary);
if (id != FEATURE_TABLE) KLTError("(KLTReadFeatureTable) File '%s' does not contain "
"a FeatureTable", fname);
if (ft_in == NULL) {
ft = KLTCreateFeatureTable(nFrames, nFeatures);
ft->nFrames = nFrames;
ft->nFeatures = nFeatures;
}
else {
ft = ft_in;
if (ft->nFrames != nFrames || ft->nFeatures != nFeatures)
KLTError("(KLTReadFeatureTable) The feature table passed "
"does not contain the same number of frames and "
"features as the feature table in file '%s' ", fname);
}
if (!binary) { /* text file */
for (j = 0 ; j < ft->nFeatures ; j++) {
fscanf(fp, "%d |", &indx);
if (indx != j)
KLTError("(KLTReadFeatureTable) Bad index at j = %d"
"-- %d", j, indx);
for (i = 0 ; i < ft->nFrames ; i++)
_readFeatureTxt(fp, ft->feature[j][i]);
}
} else { /* binary file */
for (j = 0 ; j < ft->nFeatures ; j++) {
for (i = 0 ; i < ft->nFrames ; i++)
_readFeatureBin(fp, ft->feature[j][i]);
}
}
fclose(fp);
return ft;
}

View File

@ -1,4 +1,4 @@
#include <labimage.h>
#include "labimage.h"
#include <memory.h>
namespace rtengine {

View File

@ -19,7 +19,7 @@
#ifndef _LABIMAGE_H_
#define _LABIMAGE_H_
#include <image16.h>
#include "image16.h"
namespace rtengine {

View File

@ -16,9 +16,9 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include <stdimagesource.h>
#include <rawimagesource.h>
#include "rtengine.h"
#include "stdimagesource.h"
#include "rawimagesource.h"
namespace rtengine {

View File

@ -16,10 +16,10 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <myfile.h>
#include "myfile.h"
#include <cstdarg>
#include <glibmm.h>
#include <safegtk.h>
#include "safegtk.h"
#ifdef BZIP_SUPPORT
#include <bzlib.h>
#endif

View File

@ -20,8 +20,8 @@
#define _MYFILE_
#include <glib/gstdio.h>
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
struct IMFILE {
int fd;
int pos;

View File

@ -24,7 +24,7 @@
#elif defined __APPLE__
#include <sys/time.h>
#else
#include <time.h>
#include <ctime>
#endif
class MyTime {

View File

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <processingjob.h>
#include "processingjob.h"
namespace rtengine {

View File

@ -19,7 +19,7 @@
#ifndef _PROCESSINGJOB_
#define _PROCESSINGJOB_
#include <rtengine.h>
#include "rtengine.h"
namespace rtengine {

View File

@ -17,20 +17,20 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib/gstdio.h>
#include <safegtk.h>
#include <multilangmgr.h>
#include <procparams.h>
#include "safegtk.h"
#include "../rtgui/multilangmgr.h"
#include "procparams.h"
#include <glibmm.h>
#include <sstream>
#include <string.h>
#include "version.h"
#include <ppversion.h>
#include <mydiagonalcurve.h>
#include <myflatcurve.h>
#include <cstring>
#include "../rtgui/version.h"
#include "../rtgui/ppversion.h"
#include "../rtgui/mydiagonalcurve.h"
#include "../rtgui/myflatcurve.h"
#include "safekeyfile.h"
#include "rawimage.h"
#include "../rtgui/ppversion.h"
#include <safekeyfile.h>
#include <rawimage.h>
#include "ppversion.h"
#define APPVERSION VERSION
namespace rtengine {

View File

@ -4,16 +4,16 @@
* Created on: 20/nov/2010
*/
#include <rawimage.h>
#include <settings.h>
#include <colortemp.h>
#include <utils.h>
#include "rawimage.h"
#include "settings.h"
#include "colortemp.h"
#include "../rtengine/utils.h"
#ifdef WIN32
#include <winsock2.h>
#else
#include <netinet/in.h>
#endif
#include <safegtk.h>
#include "safegtk.h"
namespace rtengine{

View File

@ -19,9 +19,9 @@
#ifndef __RAWIMAGE_H
#define __RAWIMAGE_H
#include <time.h>
#include <ctime>
#include <glibmm.h>
#include <dcraw.h>
#include "dcraw.h"
namespace rtengine {

View File

@ -16,25 +16,25 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rawimagesource.h>
#include <rawimagesource_i.h>
#include <median.h>
#include <rawimage.h>
#include <math.h>
#include <mytime.h>
#include <iccmatrices.h>
#include <iccstore.h>
#include <image8.h>
#include <curves.h>
#include <dfmanager.h>
#include <ffmanager.h>
#include <slicer.h>
#include "rawimagesource.h"
#include "rawimagesource_i.h"
#include "median.h"
#include "rawimage.h"
#include <cmath>
#include "mytime.h"
#include "iccmatrices.h"
#include "iccstore.h"
#include "image8.h"
#include "curves.h"
#include "dfmanager.h"
#include "ffmanager.h"
#include "slicer.h"
#include <iostream>
#include <options.h>
#include "../rtgui/options.h"
#include <improcfun.h>
#include "improcfun.h"
#ifdef _OPENMP
#include <omp.h>
#endif

View File

@ -19,11 +19,11 @@
#ifndef _RAWIMAGESOURCE_
#define _RAWIMAGESOURCE_
#include <imagesource.h>
#include "imagesource.h"
#include <lcms2.h>
#include <array2D.h>
#include <curves.h>
#include <cacheimagedata.h>
#include "array2D.h"
#include "curves.h"
#include "../rtgui/cacheimagedata.h"
#define HR_SCALE 2

View File

@ -20,9 +20,9 @@
#ifndef RAWIMAGESOURCE_I_H_INCLUDED
#define RAWIMAGESOURCE_I_H_INCLUDED
#include <rawimagesource.h>
#include "rawimagesource.h"
#include <curves.h>
#include "curves.h"
#undef MAXVAL
#undef CLIP

View File

@ -16,8 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <refreshmap.h>
#include <procevents.h>
#include "refreshmap.h"
#include "procevents.h"
int refreshmap[rtengine::NUMOFEVENTS] = {
ALL, // EvPhotoLoaded,

View File

@ -19,17 +19,17 @@
#ifndef _RTENGINE_
#define _RTENGINE_
#include <procparams.h>
#include <procevents.h>
#include "procparams.h"
#include "procevents.h"
#include <lcms2.h>
#include <string>
#include <glibmm.h>
#include <time.h>
#include <rtexif.h>
#include <rawmetadatalocation.h>
#include <iimage.h>
#include <utils.h>
#include <settings.h>
#include <ctime>
#include "../rtexif/rtexif.h"
#include "rawmetadatalocation.h"
#include "iimage.h"
#include "../rtengine/utils.h"
#include "settings.h"
#include "LUT.h"
/**
* @file

View File

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include "rtengine.h"
#include <iostream>
//#include <giomm.h>
#include <helpers.h>

View File

@ -16,27 +16,27 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rtengine.h>
#include <rtthumbnail.h>
#include <image8.h>
#include "rtengine.h"
#include "rtthumbnail.h"
#include "image8.h"
#include <lcms2.h>
#include <curves.h>
#include "curves.h"
#include <glibmm.h>
#include <improcfun.h>
#include <colortemp.h>
#include <mytime.h>
#include <utils.h>
#include <iccstore.h>
#include <iccmatrices.h>
#include <rawimagesource.h>
#include <stdimagesource.h>
#include "improcfun.h"
#include "colortemp.h"
#include "mytime.h"
#include "../rtengine/utils.h"
#include "iccstore.h"
#include "iccmatrices.h"
#include "rawimagesource.h"
#include "stdimagesource.h"
#include <glib/gstdio.h>
#include <setjmp.h>
#include <safekeyfile.h>
#include <safegtk.h>
#include <rawimage.h>
#include <csetjmp>
#include "safekeyfile.h"
#include "safegtk.h"
#include "rawimage.h"
#include "jpeg.h"
#include "ppversion.h"
#include "../rtgui/ppversion.h"
#define MAXVAL 0xffff
#define CLIP(a) ((a)>0?((a)<MAXVAL?(a):MAXVAL):0)

View File

@ -19,11 +19,11 @@
#ifndef _THUMBPROCESSINGPARAMETERS_
#define _THUMBPROCESSINGPARAMETERS_
#include <rawmetadatalocation.h>
#include <procparams.h>
#include "rawmetadatalocation.h"
#include "procparams.h"
#include <glibmm.h>
#include <lcms2.h>
#include <image16.h>
#include "image16.h"
namespace rtengine {

View File

@ -19,17 +19,17 @@
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <safegtk.h>
#include <guiutils.h>
#include "safegtk.h"
#include "../rtgui/guiutils.h"
#include <glib/gstdio.h>
#include <fcntl.h>
#ifdef WIN32
#include <windows.h>
#include <shlobj.h>
#else
#include <stdio.h>
#include <cstdio>
#endif
#include <rtimage.h>
#include "../rtgui/rtimage.h"
#include <memory>

View File

@ -16,12 +16,12 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <shmap.h>
#include <gauss.h>
#include <bilateral2.h>
#include <rtengine.h>
#include "shmap.h"
#include "gauss.h"
#include "bilateral2.h"
#include "rtengine.h"
#include <rawimagesource.h>//for dirpyr
#include "rawimagesource.h"//for dirpyr
#undef MAXVAL

Some files were not shown because too many files have changed in this diff Show More