[91c838]: queryfeature.c Maximize Restore History

Download this file

queryfeature.c    212 lines (196 with data), 6.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* queryfeature.c
Feature querying functionality
See queryfeature.h
*/
#include <stdio.h>
#include <string.h>
#include "version.h"
#include "queryfeature.h"
#include "filter.h"
typedef struct {char* name; int value;} TIntFeature;
typedef struct {char* name; double value;} TDoubleFeature;
typedef struct {char* name; char* value;} TStringFeature;
// Fulvio Senore June.2004 changed the check to work with microsoft compiler
#ifdef _MSC_VER
//#ifdef MSVS
#define snprintf _snprintf
#endif
/***************** Feature tables: *************************/
TIntFeature intFeatures[] ={
{"CPErrorIsDistSphere",1}, // optimizer reports angular control point errors
{"NumLensTypes",5}, // source lens types 0..4
{"CanCropOutside",1},
{"CanHaveNegativeCP",1}
};
TDoubleFeature doubleFeatures[] ={
{"MaxFFOV",MAX_FISHEYE_FOV}
};
TStringFeature stringFeatures[]={
// Version info:
{PTVERSION_NAME_FILEVERSION,PTVERSION_FILEVERSION}, // "FileVersion"
{PTVERSION_NAME_LONG,LONGVERSION}, // "LongVersion"
{PTVERSION_NAME_LEGALCOPYRIGHT,PTVERSION_LEGALCOPYRIGHT}, // "LegalCopyright"
{PTVERSION_NAME_COMMENT,PTVERSION_COMMENT}, // "Comments"
// Source lens type names
// If a lens type is unavailable, set its name to ""
{"LensType0","Normal (rectilinear)"},
{"LensType1","Cylindrical"},
{"LensType2","Circular"},
{"LensType3","Full Frame"},
{"LensType4","Equirectangular"},
// Source lens type crop format (C)ircle or (R)ectangle:
{"LensMask0","R"},
{"LensMask1","R"},
{"LensMask2","C"},
{"LensMask3","R"},
{"LensMask4","R"},
#ifdef HasJava
{"Patch200504a", "Douglas Wilkins, Java support enabled"},
#else
{"Patch200504a", "Douglas Wilkins, Java support disabled"},
#endif
// Patches that have been applied
{"Patch200502a", "Joost Nieuwenhuijse, Crop outside of image, http://www.ptgui.com"},
{"Patch200410a", "Jim Watters, JPEG optimization, http://photocreations.ca/panotools"},
{"FastTransform01", "Fulvio Senore, Fast transform, http://www.fsoft.it/panorama/pano12.htm"},
{"Patch200407a", "Rik Littlefield, Kevin Kratzke, & Jim Watters, Fix multiple bugs - PSD, 16bit"},
{"MaskFromFocus_001", "Rik Littlefield, added mask-from-focus, http://www.janrik.ptools"},
{"Patch200405a", "Rik Littlefield, Improved optimizer, http://www.janrik.ptools"},
{"Patch200403a", "Kevin Kratzke, Radial Shift fix, http://www.kekus.com"},
{"Patch200312a", "Jim Watters, Updated PSD format, http://photocreations.ca/panotools"},
{"Patch200309a", "Jim Watters, Allowed linking of y, p, & r values, http://photocreations.ca/panotools"},
{"Patch200308a", "Jim Watters, Improved Radial Luminance, http://photocreations.ca/panotools"}
};
/***************** end feature tables **********************/
int queryFeatureInt(const char *name, int *result)
{
int i;
int count = sizeof( intFeatures ) / sizeof( intFeatures[0] );
for(i=0; i < count; i++)
{
if(strcmp(name,intFeatures[i].name)==0)
{
*result=intFeatures[i].value;
return 1;
}
}
return 0;
}
int queryFeatureDouble(const char *name, double *result)
{
int i;
int count = sizeof( doubleFeatures ) / sizeof( doubleFeatures[0] );
for(i=0; i < count; i++)
{
if(strcmp(name,doubleFeatures[i].name)==0)
{
*result=doubleFeatures[i].value;
return 1;
}
}
return 0;
}
int queryFeatureString(const char *name,char *result, const int bufsize)
{
int intvalue;
double doublevalue;
size_t i, length=0, count = (sizeof( stringFeatures ) / sizeof( stringFeatures[0] ));
const size_t tmp_len=200;
// Fulvio Senore, August 2004
// allocates a dummy buffer for the calls to snprintf
// the original code passed NULL to snprintf() but it caused problems (asserts) when compiling
// with the microsoft compiler that links with the debug libraries to avoid crashes
char *cpTmp = malloc( tmp_len + 1 );
cpTmp[tmp_len] = '\0';
for(i=0; i < count; i++)
{
if(strcmp(name,stringFeatures[i].name)==0)
{
if(result != NULL)
{
strncpy(result, stringFeatures[i].value, (size_t)bufsize);
}
length=strlen(stringFeatures[i].value);
break;
}
}
if(length <= 0)
{
// there's no string value with the specified name
// Let's check the int values too:
for(i=0; i < sizeof( intFeatures ) / sizeof( intFeatures[0] ); i++)
{
if(queryFeatureInt(name, &intvalue))
{
// length=snprintf(NULL,0,"%d",intvalue);
length=snprintf(cpTmp,tmp_len,"%d",intvalue);
if(result != NULL)
{
snprintf(result,(size_t)bufsize,"%d",intvalue);
}
break;
}
}
}
if(length <= 0)
{
// Let's check the double values too:
for(i=0; i < sizeof( doubleFeatures ) / sizeof( doubleFeatures[0] ); i++)
{
if(queryFeatureDouble(name, &doublevalue))
{
// length=snprintf(NULL,0,"%0.f",doublevalue);
length=snprintf(cpTmp,tmp_len,"%0.f",doublevalue);
if(result != NULL)
{
snprintf(result,(size_t)bufsize,"%0.f",doublevalue);
}
break;
}
}
}
// make sure that the copied string always is NULL terminated, even if truncated
// (except if the buffer holds only zero bytes):
if( result && (length >= bufsize) && (bufsize > 0) )
{
result[bufsize-1]=0;
}
free( cpTmp );
return length;
}
int queryFeatureCount()
{
return sizeof( intFeatures ) / sizeof( intFeatures[0] )+
sizeof( doubleFeatures ) / sizeof( doubleFeatures[0] ) +
sizeof( stringFeatures ) / sizeof( stringFeatures[0] );
}
void queryFeatures(int index,char** name,Tp12FeatureType* type)
{
if(index < (sizeof( intFeatures ) / sizeof( intFeatures[0] )))
{
if(name) *name=intFeatures[index].name;
if(type) *type=p12FeatureInt;
}
else
{
index -= sizeof( intFeatures ) / sizeof( intFeatures[0] );
if(index < sizeof( doubleFeatures ) / sizeof( doubleFeatures[0] ))
{
if(name) *name=doubleFeatures[index].name;
if(type) *type=p12FeatureDouble;
}
else
{
index -= sizeof( doubleFeatures ) / sizeof( doubleFeatures[0] );
if(index < sizeof( stringFeatures ) / sizeof( stringFeatures[0] ))
{
if(name) *name=stringFeatures[index].name;
if(type) *type=p12FeatureString;
}
else
{
if(type) *type=p12FeatureUnknown;
}
}
}
}