Floating Point Issues and DTWAIN

Top  Previous  Next

For floating point parameters  DTWAIN relies on the DTWAIN_FLOAT, or 64-bit IEEE floating point type (this is equivalent to a double in C or C++).  Most languages support this type, however for some languages (examples are XBase++ from Alaska Software, or a scripting language such as Macro Scheduler), this type is minimally supported and/or the programmer will have difficulty getting the language to support this type.  This issue is evident if a log of the DTWAIN function is inspected, and instead of the floating point value being passed to the function, a garbage or totally wrong floating point number is passed to the DTWAIN function.

 

For this situation, DTWAIN has alternate functions to set and get floating point values, as well as set/get functions that requires usage of the DTWAIN_ARRAY's that hold DTWAIN_FLOAT types.  These functions are as follows:

 

DTWAIN_GetAcquireArea2String

DTWAIN_GetBrightnessString

DTWAIN_GetContrastString

DTWAIN_GetImageInfoString

DTWAIN_GetResolutionString

DTWAIN_GetRotationString

DTWAIN_SetAcquireArea2String

DTWAIN_SetAcquireImageScaleString

DTWAIN_SetBlankPageDetectionString

DTWAIN_SetBrightnessString

DTWAIN_SetContrastString

DTWAIN_SetPDFPageScaleString

DTWAIN_SetPDFPageSizeString

DTWAIN_SetResolutionString

DTWAIN_SetRotationString

DTWAIN_IsDIBBlankString

 

All of these functions substitute the DTWAIN_FLOAT parameter with an LPCTSTR parameter.  Since almost every (if not every) computer language that is available on the Windows platform handles strings with no issues, it is recommended to use the functions above to set certain capability values.

 

 

For DTWAIN_ARRAY usage and setting/getting capability values:

 

DTWAIN_ArrayFix32SetAt

DTWAIN_ArrayFix32GetAt

DTWAIN_ArrayConvertFloatToFix32

DTWAIN_ArrayConvertFix32ToFloat

 

 

The 4 functions above allow you to call functions such as DTWAIN_GetCapValues and DTWAIN_SetCapValues, where the capability requires DTWAIN_FLOAT values to get/set values.  The "Fix32" is a special TWAIN type called a TW_FIX32. This type consists of a whole and a fractional setting, allowing your application to create pseudo-floating point numbers that the DTWAIN library can process.

 

Here is a small 'C' example of using these functions (note that this example never needs to be done using 'C', since 'C' handles DTWAIN_FLOAT values with no issues.  The example is only for illustrative purposes):

 

  #include "dtwain.h"

 #include <stdio.h>

 

  void Test()

  {

      LONG TwainSource;

      DTWAIN_SysInitialize( );

      TwainSource = DTWAIN_SelectSource( );

      if ( TwainSource )

      {

            LONG i, Whole, Frac, numValues;

            double dVal;

            DTWAIN_ARRAY floatArray, fixedPtArray;

 

            /* get the resolution values that are used by the Source */

            DTWAIN_EnumResolutionValues( TwainSource, &floatArray, TRUE );

            numValues = DTWAIN_ArrayGetCount( floatArray );

 

            /* Convert to fixed point DTWAIN_ARRAY */

            fixedPtArray = DTWAIN_ArrayConvertFloatToFix32( floatArray );

           

            for (i = 0; i < numValues; ++i )

            {

                 /* Whole and Frac contain the values in the array */

                DTWAIN_ArrayFix32GetAt( fixedPtArrray, i, &Whole, &Frac );

                 printf( "%d.%d\n", Whole, Frac );

            }

 

            /* to test, convert the fixed point array back to a DTWAIN_ARRAYFLOAT array */

            floatArray = DTWAIN_ArrayConvertFix32ToFloat( fixedPtArray );          

 

            /* print out the floating point values */

            for (i = 0; i < numValues; ++i )

            {

                DTWAIN_ArrayGetAtFloat( floatArray, i, &dVal );

                 printf( "%lf\n", dVal );

            }

       }

      DTWAIN_SysDestroy( );

 }