twain2/scn_config.cpp

191 lines
4.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "stdafx.h"
#include "scn_config.h"
#include "math.h"
#include "twain.h"
hgConfigClass::hgConfigClass()
{
initpaperTypes();
initPixType();
initResolution();
}
hgConfigClass::hgConfigClass(SFreeImage param)
{
initpaperTypes();
initPixType();
initResolution();
settwSS(param.m_HardWareParams.PaperType);
setTwPixelType(param.m_HardWareParams.PixType);
setResolution(200.0f);//param.m_HardWareParams.Resolution ÔÝʱӲ¼þÖ»Ö§³ÖÕæʵ200dpi
setDoubleFeedEnable(param.m_HardWareParams.DoubleFeederOn);
setStapleEnable(param.m_HardWareParams.StapleDetectOn);
setSkewDelection(param.m_HardWareParams.SkrewDetectOn);
switch (param.m_HardWareParams.SkrewDetectLevel)
{
case 1:
setBit(12, false);
setBit(13, false);
setBit(14, false);
break;
case 2:
setBit(12, true);
setBit(13, false);
setBit(14, false);
break;
case 3:
setBit(12, false);
setBit(13, true);
setBit(14, false);
break;
case 4:
setBit(12, true);
setBit(13, true);
setBit(14, false);
break;
case 5:
setBit(12, false);
setBit(13, false);
setBit(14, true);
break;
default:
break;
}
}
hgConfigClass::~hgConfigClass()
{
}
void hgConfigClass::settwSS(UINT32 value)
{
UINT32 uval;
if (ContainspaperTypesKey(value))
{
uval = paperTypes[value];
}
else
{
uval = 2;
}
for (size_t i = 1; i < 6; i++)
{
setBit(i, ((uval >> i - 1) & 0x1) == 0x01);
}
//printf("settwSS: %d\n", Data);
}
void hgConfigClass::setTwPixelType(UINT32 value)
{
UINT32 uval;
if (ContainsPixTypeKey(value))
uval = pixType[value];
else
uval = 2;
setBit(6, uval == 0x01);
}
void hgConfigClass::setResolution(UINT32 value)
{
UINT32 uval;
if (ContainsResolutionKey(value))
uval = resolutions[value];
else
uval = 1;
for (size_t i = 7; i < 9; i++)
{
setBit(i, ((uval << (i - 7)) & 0x1) == 0x01);
}
}
void hgConfigClass::setDoubleFeedEnable(bool value)
{
setBit(9, value);
}
void hgConfigClass::setStapleEnable(bool value)
{
setBit(10, value);
}
void hgConfigClass::setSkewDelection(bool value)
{
setBit(11, value);
}
UINT32 hgConfigClass::GetData()
{
return m_data.to_ulong();
}
void hgConfigClass::initpaperTypes()
{
paperTypes.insert(std::pair<uint16_t, UINT32>(11, 0));//A3
paperTypes.insert(std::pair<uint16_t, UINT32>(1, 1));//A4
paperTypes.insert(std::pair<uint16_t, UINT32>(60, 2));//A4R
paperTypes.insert(std::pair<uint16_t, UINT32>(5, 2));//A5
paperTypes.insert(std::pair<uint16_t, UINT32>(61, 2));//A5R
paperTypes.insert(std::pair<uint16_t, UINT32>(13, 2));//A6
paperTypes.insert(std::pair<uint16_t, UINT32>(62, 2));//A6R
paperTypes.insert(std::pair<uint16_t, UINT32>(6, 0));//B4
paperTypes.insert(std::pair<uint16_t, UINT32>(2, 0));//B5
paperTypes.insert(std::pair<uint16_t, UINT32>(70, 1));//B5R
paperTypes.insert(std::pair<uint16_t, UINT32>(7, 2));//B6
paperTypes.insert(std::pair<uint16_t, UINT32>(71, 2));//B6R
paperTypes.insert(std::pair<uint16_t, UINT32>(3, 1));//LETTER
paperTypes.insert(std::pair<uint16_t, UINT32>(80, 2));//LETTERR
paperTypes.insert(std::pair<uint16_t, UINT32>(81, 0));//DOUBLE LETTER
paperTypes.insert(std::pair<uint16_t, UINT32>(4, 0));//LEGAL
paperTypes.insert(std::pair<uint16_t, UINT32>(90, 0));//Auto °´ÕÕA3½øÐÐɨÃè
paperTypes.insert(std::pair<uint16_t, UINT32>(91, 16));//³¤Îĸå
}
void hgConfigClass::initPixType()
{
pixType.insert(std::pair<uint16_t, UINT32>(0, 0));//BW
pixType.insert(std::pair<uint16_t, UINT32>(1, 0));//Gray
pixType.insert(std::pair<uint16_t, UINT32>(2,1));//RGB
}
void hgConfigClass::initResolution()
{
resolutions.insert(std::pair<float, UINT32>(300, 0));//300
resolutions.insert(std::pair<float, UINT32>(200, 1));//200
resolutions.insert(std::pair<float, UINT32>(600, 2));//600
}
bool hgConfigClass::ContainspaperTypesKey(uint16_t key)
{
if (paperTypes.count(key) > 0)
{
return true;
}
return false;
}
bool hgConfigClass::ContainsPixTypeKey(uint16_t key)
{
if (pixType.count(key)>0)
{
return true;
}
return false;
}
bool hgConfigClass::ContainsResolutionKey(float key)
{
if (resolutions.count(key)>0)
{
return true;
}
return false;
}
void hgConfigClass::setBit(int i, bool flag)
{
m_data.set(i -1, flag);
}