/*
 * Toolbox for image operations (class-independent)
 *
 * $Date$
 * $Revision$
 *
 */

#ifndef TOOLS_H__
#define TOOLS_H__
/** 
 * @addtogroup WImage 
 * @{ */

#include "WImage/miscdefs.h"

/** Convert a coeff value to a pixel.
 * @param c
 * the coefficient
 * @return the pixel value */
pixel tools_coeff2pixel (coeff c);

/** Convert a coeff value to a integer
 * @param c
 * the coefficient
 * @return the integer value */
int tools_coeff2int ( coeff c);

/** Return true if two double values are equal
 * @param d1 the first value
 * @param d2 the second value
 * @return true if equal */
bool tools_equals (double d1, double d2);

/** Return true if two double values are almost equal
 * @param d1 the first value
 * @param d2 the second value
 * @param epsilon the comparison epsilon
 * @return true if almost equal */
bool tools_epsilons (double d1, double d2, double epsilon);

/** Calculate an area from a string split to two characters
 * @param a1 the first character
 * @param a2 the second character
 * @param result the result
 * @return true if a valid area name was passed, else false */
bool tools_areaFromString (char a1, char a2, area &result);

/** Calculate an area from a string 
 * @param a the string containing the area name
 * @param result the result
 * @return true if a valid area name was passed, else false */
bool tools_areaFromString (char *a, area &result);

/** Return an external string constant containing the name of the area
 * passed to the function.
 * @param a the area
 * @return the area's name */
const char * tools_areaToString (const area a);

/** Find out whether a number is a power of two.
 * @param value the value to test
 * @param power (returned value) the power of two if the result is true.
 * @return true if value is a power of two. */
bool tools_powerOfTwo (int value, int &power);

/** Calculate a vector's start index so that a given position is in its center.
 * @param pos the position
 * @param length the vector's length
 * @return the start index */
int tools_startFromCenter (int pos, int length);

#ifndef _WIN32_WCE
/** Return the size of a file in bytes.
 * @exception invalid_argument if the file cannot be opened
 * @param fname the file name
 * @return the size in bytes. */
int tools_fileSize (const char *fname);
#endif

/** @} */

#endif /* TOOLS_H__*/
