diff --git a/src/trace/siox.cpp b/src/trace/siox.cpp
index ff894a48c542cbddd383cc7a6c379cbf5a627f08..c69af04a165c85266a3897e98cdd8576018dac8e 100644 (file)
--- a/src/trace/siox.cpp
+++ b/src/trace/siox.cpp
if (!_clab_inited_)
{
cbrt_table[0] = pow(float(1)/float(ROOT_TAB_SIZE*2), 0.3333);
- qn_table[0] = pow(float(1)/float(ROOT_TAB_SIZE*2), 0.2);
+ qn_table[0] = pow(float(1)/float(ROOT_TAB_SIZE*2), 0.2);
for(int i = 1; i < ROOT_TAB_SIZE +1; i++)
{
cbrt_table[i] = pow(float(i)/float(ROOT_TAB_SIZE), 0.3333);
Tupel(float minBgDistArg, long indexMinBgArg,
float minFgDistArg, long indexMinFgArg)
{
- minBgDist = minBgDistArg;
- indexMinBg = indexMinBgArg;
- minFgDist = minFgDistArg;
- indexMinFg = indexMinFgArg;
+ minBgDist = minBgDistArg;
+ indexMinBg = indexMinBgArg;
+ minFgDist = minFgDistArg;
+ indexMinFg = indexMinFgArg;
}
Tupel(const Tupel &other)
{
- minBgDist = other.minBgDist;
- indexMinBg = other.indexMinBg;
- minFgDist = other.minFgDist;
- indexMinFg = other.indexMinFg;
+ minBgDist = other.minBgDist;
+ indexMinBg = other.indexMinBg;
+ minFgDist = other.minFgDist;
+ indexMinFg = other.indexMinFg;
}
Tupel &operator=(const Tupel &other)
{
- minBgDist = other.minBgDist;
- indexMinBg = other.indexMinBg;
- minFgDist = other.minFgDist;
- indexMinFg = other.indexMinFg;
- return *this;
+ minBgDist = other.minBgDist;
+ indexMinBg = other.indexMinBg;
+ minFgDist = other.minFgDist;
+ indexMinFg = other.indexMinFg;
+ return *this;
}
virtual ~Tupel()
{}
if (cmdata) delete[] cmdata;
}
+/**
+ * Error logging
+ */
+void SioxImage::error(char *fmt, ...)
+{
+ char msgbuf[256];
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(msgbuf, 255, fmt, args);
+ va_end(args) ;
+#ifdef HAVE_GLIB
+ g_warning("SioxImage error: %s\n", msgbuf);
+#else
+ fprintf(stderr, "SioxImage error: %s\n", msgbuf);
+#endif
+}
+
+
/**
* Returns true if the previous operation on this image
* was successful, else false.
unsigned int y,
unsigned int pixval)
{
- if (x > width || y > height)
+ if (x >= width || y >= height)
+ {
+ error("setPixel: out of bounds (%d,%d)/(%d,%d)",
+ x, y, width, height);
return;
+ }
unsigned long offset = width * y + x;
pixdata[offset] = pixval;
}
unsigned int g,
unsigned int b)
{
- if (x > width || y > height)
+ if (x >= width || y >= height)
+ {
+ error("setPixel: out of bounds (%d,%d)/(%d,%d)",
+ x, y, width, height);
return;
+ }
unsigned long offset = width * y + x;
unsigned int pixval = ((a << 24) & 0xff000000) |
((r << 16) & 0x00ff0000) |
*/
unsigned int SioxImage::getPixel(unsigned int x, unsigned int y)
{
- if (x > width || y > height)
+ if (x >= width || y >= height)
+ {
+ error("getPixel: out of bounds (%d,%d)/(%d,%d)",
+ x, y, width, height);
return 0L;
+ }
unsigned long offset = width * y + x;
return pixdata[offset];
}
unsigned int y,
float confval)
{
- if (x > width || y > height)
+ if (x >= width || y >= height)
+ {
+ error("setConfidence: out of bounds (%d,%d)/(%d,%d)",
+ x, y, width, height);
return;
+ }
unsigned long offset = width * y + x;
cmdata[offset] = confval;
}
*/
float SioxImage::getConfidence(unsigned int x, unsigned int y)
{
- if (x > width || y > height)
+ if (x >= width || y >= height)
+ {
+ g_warning("getConfidence: out of bounds (%d,%d)/(%d,%d)",
+ x, y, width, height);
return 0.0;
+ }
unsigned long offset = width * y + x;
return cmdata[offset];
}
return workImage;
}
- trace("knownBg:%d knownFg:%d", knownBg.size(), knownFg.size());
+ trace("knownBg:%zu knownFg:%zu", knownBg.size(), knownFg.size());
std::vector<CieLab> bgSignature ;
*/
void Siox::normalizeMatrix(float *cm, int cmSize)
{
- float max = *std::max(cm, cm + cmSize);
+ float max= -1000000.0f;
+ for (int i=0; i<cmSize; i++)
+ if (cm[i] > max) max=cm[i];
+
+ //good to use STL, but max() is not iterative
+ //float max = *std::max(cm, cm + cmSize);
if (max<=0.0 || max==1.0)
return;