initialize

This commit is contained in:
gb 2022-05-03 16:54:08 +08:00
commit b047fe3fab
102 changed files with 30944 additions and 0 deletions

17
device/device.def Normal file
View File

@ -0,0 +1,17 @@
LIBRARY hgscanner
EXPORTS
hg_scanner_initialize
hg_scanner_uninitialize
hg_scanner_get_version
hg_scanner_enum
hg_scanner_open
hg_scanner_close
hg_scanner_get_parameter
hg_scanner_set_parameter
hg_scanner_start
hg_scanner_stop
hg_scanner_get_img_info
hg_scanner_read_img_data
hg_scanner_get_status
hg_scanner_reset
hg_scanner_control

325
device/hgscanner.vcxproj Normal file
View File

@ -0,0 +1,325 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{9ed4b425-73e0-423e-9712-455e777481b4}</ProjectGuid>
<RootNamespace>hgscanner</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)..\..\device\hgdriver\3rdparty\nick;$(SolutionDir)..\..\device\hgdriver\3rdparty\opencv\include\win;$(SolutionDir)..\..\device\hgdriver\3rdparty\cyusb\inc\;$(SolutionDir)..\..\device\hgdriver\3rdparty\libtiff\include\;$(SolutionDir)..\..\device\hgdriver\3rdparty\log4cplus\include\;$(SolutionDir)..\..\device\sdk\;$(SolutionDir)..\..\device\hgdriver\ImageProcess\;$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\device\hgdriver\hgdev\;$(SolutionDir)..\..\device\hgdriver\wrapper\;$(ProjectDir);$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)..\..\device\hgdriver\3rdparty\nick;$(SolutionDir)..\..\device\hgdriver\3rdparty\opencv\include\win;$(SolutionDir)..\..\device\hgdriver\3rdparty\cyusb\inc\;$(SolutionDir)..\..\device\hgdriver\3rdparty\libtiff\include\;$(SolutionDir)..\..\device\hgdriver\3rdparty\log4cplus\include\;$(SolutionDir)..\..\device\sdk\;$(SolutionDir)..\..\device\hgdriver\ImageProcess\;$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\device\hgdriver\hgdev\;$(SolutionDir)..\..\device\hgdriver\wrapper\;$(ProjectDir);$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>$(SolutionDir)..\..\device\hgdriver\3rdparty\nick;$(SolutionDir)..\..\device\hgdriver\3rdparty\opencv\include\win;$(SolutionDir)..\..\device\hgdriver\3rdparty\cyusb\inc\;$(SolutionDir)..\..\device\hgdriver\3rdparty\libtiff\include\;$(SolutionDir)..\..\device\hgdriver\3rdparty\log4cplus\include\;$(SolutionDir)..\..\device\sdk\;$(SolutionDir)..\..\device\hgdriver\ImageProcess\;$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\device\hgdriver\hgdev\;$(SolutionDir)..\..\device\hgdriver\wrapper\;$(ProjectDir);$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>$(SolutionDir)..\..\device\hgdriver\3rdparty\nick;$(SolutionDir)..\..\device\hgdriver\3rdparty\opencv\include\win;$(SolutionDir)..\..\device\hgdriver\3rdparty\cyusb\inc\;$(SolutionDir)..\..\device\hgdriver\3rdparty\libtiff\include\;$(SolutionDir)..\..\device\hgdriver\3rdparty\log4cplus\include\;$(SolutionDir)..\..\device\sdk\;$(SolutionDir)..\..\device\hgdriver\ImageProcess\;$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\device\hgdriver\hgdev\;$(SolutionDir)..\..\device\hgdriver\wrapper\;$(ProjectDir);$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;HGSCANNER_EXPORT;CUSTOM_USBVIEW;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>opencv_world3414.lib;IlmImf.lib;ittnotify.lib;leptonica.lib;libjasper.lib;libjpeg-turbo.lib;libpng.lib;libtiff.lib;libwebp.lib;log4cplusS.lib;quirc.lib;tiff.lib;zlib.lib;user32.lib</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
<ModuleDefinitionFile>$(ProjectDir)device.def</ModuleDefinitionFile>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;HGSCANNER_EXPORT;CUSTOM_USBVIEW;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>opencv_world3414.lib;IlmImf.lib;ittnotify.lib;leptonica.lib;libjasper.lib;libjpeg-turbo.lib;libpng.lib;libtiff.lib;libwebp.lib;log4cplusS.lib;quirc.lib;tiff.lib;zlib.lib;user32.lib</AdditionalDependencies>
<ModuleDefinitionFile>$(ProjectDir)device.def</ModuleDefinitionFile>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\device\hgdriver\hgdev\common_setting.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_ipc.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner_200.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner_239.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner_300.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner_400.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\ImageMatQueue.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\ImageMultiOutput.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\image_process.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\jsonconfig.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\PaperSize.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\scanner_manager.cpp" />
<ClCompile Include="..\..\device\hgdriver\hgdev\usb_manager.cpp" />
<ClCompile Include="..\..\device\hgdriver\wrapper\hg_log.cpp" />
<ClCompile Include="..\..\device\hgdriver\wrapper\huagaoxxx_warraper_ex.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApply.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyAdjustColors.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyAutoContrast.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyAutoCrop.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyBWBinaray.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyChannel.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyColorRecognition.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyConcatenation.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyCrop.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyCustomCrop.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyCustomGamma.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyCvtColor.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyDetachNoise.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyDiscardBlank.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyDogEarDetection.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyFadeBackGroundColor.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyFilter.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyHSVCorrect.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyOutHole.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyRefuseInflow.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyResize.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyRotation.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplySharpen.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplySplit.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyTextureRemoval.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyUV.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageMulti.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageMultiOutputRed.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageProcess_Public.cpp" />
<ClCompile Include="..\..\device\hgdriver\ImageProcess\IMulti.cpp" />
<ClCompile Include="win_usb\usbview\devnode.c" />
<ClCompile Include="win_usb\usbview\enum.c" />
<ClCompile Include="win_usb\win_usb.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\device\hgdriver\hgdev\BlockingQueue.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\char_const.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\common_setting.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\filetools.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_ipc.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner_200.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner_239.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner_300.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner_400.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\ImageMatQueue.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\ImageMultiOutput.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\image_process.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\json.hpp" />
<ClInclude Include="..\..\device\hgdriver\hgdev\jsonconfig.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\PaperSize.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\raw_src.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\scanner_manager.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\threadpool.h" />
<ClInclude Include="..\..\device\hgdriver\hgdev\usb_manager.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApply.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyAdjustColors.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyAutoContrast.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyAutoCrop.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyBWBinaray.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyChannel.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyColorRecognition.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyConcatenation.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyCrop.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyCustomCrop.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyCustomGamma.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyCvtColor.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyDetachNoise.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyDiscardBlank.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyDogEarDetection.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyFadeBackGroundColor.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyFilter.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyHeaders.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyHSVCorrect.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyOutHole.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyRefuseInflow.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyResize.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyRotation.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplySharpen.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplySplit.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyTextureRemoval.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyUV.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageMulti.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageMultiOutputRed.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageProcess_Public.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\imgprocdefs.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\IMulti.h" />
<ClInclude Include="..\..\device\hgdriver\ImageProcess\MatEx.h" />
<ClInclude Include="..\..\sdk\hginclude\hgscanner_error.h" />
<ClInclude Include="..\..\sdk\hginclude\hg_log.h" />
<ClInclude Include="..\..\sdk\hginclude\huagaoxxx_warraper_ex.h" />
<ClInclude Include="win_usb\usbview\enum.h" />
<ClInclude Include="win_usb\usbview\usbdesc.h" />
<ClInclude Include="win_usb\usbview\uvcdesc.h" />
<ClInclude Include="win_usb\win_usb.h" />
</ItemGroup>
<ItemGroup>
<None Include="device.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,365 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="image">
<UniqueIdentifier>{69bf4790-4420-4dc8-bc81-a63a902ce9c9}</UniqueIdentifier>
</Filter>
<Filter Include="dev">
<UniqueIdentifier>{f707cca2-7b0e-41a8-b091-4340f974ff02}</UniqueIdentifier>
</Filter>
<Filter Include="usb">
<UniqueIdentifier>{01c7b72c-12be-466b-b93e-9a9c8fea21b4}</UniqueIdentifier>
</Filter>
<Filter Include="usb\usbview">
<UniqueIdentifier>{06629bf8-5d3e-4855-916b-260169824839}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\device\hgdriver\wrapper\huagaoxxx_warraper_ex.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApply.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyAdjustColors.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyAutoContrast.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyAutoCrop.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyBWBinaray.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyChannel.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyColorRecognition.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyConcatenation.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyCrop.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyCustomCrop.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyCustomGamma.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyCvtColor.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyDetachNoise.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyDiscardBlank.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyDogEarDetection.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyFadeBackGroundColor.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyFilter.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyHSVCorrect.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyOutHole.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyRefuseInflow.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyResize.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyRotation.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplySharpen.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplySplit.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyTextureRemoval.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageApplyUV.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageMulti.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageMultiOutputRed.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\ImageProcess_Public.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\ImageProcess\IMulti.cpp">
<Filter>image</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\common_setting.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_ipc.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner_200.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner_239.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\image_process.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\ImageMatQueue.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\ImageMultiOutput.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\jsonconfig.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\PaperSize.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\scanner_manager.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\usb_manager.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="win_usb\win_usb.cpp">
<Filter>usb</Filter>
</ClCompile>
<ClCompile Include="win_usb\usbview\enum.c">
<Filter>usb\usbview</Filter>
</ClCompile>
<ClCompile Include="win_usb\usbview\devnode.c">
<Filter>usb\usbview</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner_300.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\hgdev\hg_scanner_400.cpp">
<Filter>dev</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\wrapper\hg_log.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\sdk\hginclude\hg_log.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\hginclude\hgscanner_error.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\hginclude\huagaoxxx_warraper_ex.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApply.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyAdjustColors.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyAutoContrast.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyAutoCrop.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyBWBinaray.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyChannel.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyColorRecognition.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyConcatenation.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyCrop.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyCustomCrop.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyCustomGamma.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyCvtColor.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyDetachNoise.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyDiscardBlank.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyDogEarDetection.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyFadeBackGroundColor.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyFilter.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyHeaders.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyHSVCorrect.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyOutHole.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyRefuseInflow.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyResize.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyRotation.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplySharpen.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplySplit.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyTextureRemoval.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageApplyUV.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageMulti.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageMultiOutputRed.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\ImageProcess_Public.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\imgprocdefs.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\IMulti.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\ImageProcess\MatEx.h">
<Filter>image</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\BlockingQueue.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\common_setting.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\filetools.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_ipc.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner_200.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner_239.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\image_process.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\ImageMatQueue.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\ImageMultiOutput.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\json.hpp">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\jsonconfig.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\PaperSize.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\raw_src.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\scanner_manager.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\threadpool.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\usb_manager.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="win_usb\win_usb.h">
<Filter>usb</Filter>
</ClInclude>
<ClInclude Include="win_usb\usbview\enum.h">
<Filter>usb\usbview</Filter>
</ClInclude>
<ClInclude Include="win_usb\usbview\usbdesc.h">
<Filter>usb\usbview</Filter>
</ClInclude>
<ClInclude Include="win_usb\usbview\uvcdesc.h">
<Filter>usb\usbview</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner_300.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\hg_scanner_400.h">
<Filter>dev</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgdriver\hgdev\char_const.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="device.def">
<Filter>源文件</Filter>
</None>
</ItemGroup>
</Project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,60 @@
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_IDENTITY, MSG = MSG_GET, data: 0x02ee50d4,
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_IDENTITY, MSG = MSG_OPENDS, data: 0x02ee6b84, Identity(ID: 0x1b, Ver: 0x1, Proto: 1000d.79736145, Group: 0x6e616353, Manufacturer: EasyScan, ProductFamily: EasyScan, ProductName: EasyScan);
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GETCURRENT, data: 0x02ee6b34, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b34, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GETCURRENT, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GETCURRENT, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b34, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GETCURRENT, data: 0x02ee6b34, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b34, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_STATUS, MSG = MSG_GET, data: 0x02ee6b1c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b34, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GET, data: 0x02ee6b24, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b34, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b2c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b2c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_STATUS, MSG = MSG_GET, data: 0x02ee6b14, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b2c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b2c, Identity(same as the latest)
[21164] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_IDENTITY, MSG = MSG_GET, data: 0x0d468504,
[21164] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_IDENTITY, MSG = MSG_OPENDS, data: 0x0d46be54, Identity(ID: 0x1e, Ver: 0x1, Proto: 1000d.79736145, Group: 0x6e616353, Manufacturer: EasyScan, ProductFamily: EasyScan, ProductName: EasyScan);
[21164] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_STATUS, MSG = MSG_GET, data: 0x0d46beb0, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b8c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b6c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b6c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b8c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b7c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b8c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_STATUS, MSG = MSG_GET, data: 0x02ee6b74, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b6c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b6c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_IMAGE, DAT = DAT_IMAGELAYOUT, MSG = MSG_SET, data: 0x02ee6bac, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_STATUS, MSG = MSG_GET, data: 0x02ee6b94, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_IMAGE, DAT = DAT_IMAGELAYOUT, MSG = MSG_RESET, data: 0x02ee6bac, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6b8c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_USERINTERFACE, MSG = MSG_ENABLEDS, data: 0x02ee6b80, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_IMAGE, DAT = DAT_IMAGENATIVEXFER, MSG = MSG_GET, data: 0x02ee5518, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_STATUS, MSG = MSG_GET, data: 0x02ee5500, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_PENDINGXFERS, MSG = MSG_ENDXFER, data: 0x02ee5510, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_USERINTERFACE, MSG = MSG_DISABLEDS, data: 0x02ee5674, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6f84, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6f64, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6f64, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GETCURRENT, data: 0x02ee6f74, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_GETCURRENT, data: 0x02ee6f74, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6f84, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6f74, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6f84, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_STATUS, MSG = MSG_GET, data: 0x02ee6f6c, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6f64, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_CONTROL, DAT = DAT_CAPABILITY, MSG = MSG_SET, data: 0x02ee6f64, Identity(same as the latest)
[22772] [TWAIN-monitor] DG = DG_IMAGE, DAT = DAT_IMAGELAYOUT, MSG = MSG_SET, data: 0x02ee6fa4, Identity(same as the latest)

View File

@ -0,0 +1,336 @@
/*++
Copyright (c) 1998-2011 Microsoft Corporation
Module Name:
DEVNODE.C
--*/
/*****************************************************************************
I N C L U D E S
*****************************************************************************/
#include "enum.h"
/*****************************************************************************
DriverNameToDeviceInst()
Finds the Device instance of the DevNode with the matching DriverName.
Returns FALSE if the matching DevNode is not found and TRUE if found
*****************************************************************************/
BOOL
DriverNameToDeviceInst(
_In_reads_bytes_(cbDriverName) PCHAR DriverName,
_In_ size_t cbDriverName,
_Out_ HDEVINFO *pDevInfo,
_Out_writes_bytes_(sizeof(SP_DEVINFO_DATA)) PSP_DEVINFO_DATA pDevInfoData
)
{
HDEVINFO deviceInfo = INVALID_HANDLE_VALUE;
BOOL status = TRUE;
ULONG deviceIndex;
SP_DEVINFO_DATA deviceInfoData;
BOOL bResult = FALSE;
PCHAR pDriverName = NULL;
PSTR buf = NULL;
BOOL done = FALSE;
if (pDevInfo == NULL)
{
return FALSE;
}
if (pDevInfoData == NULL)
{
return FALSE;
}
memset(pDevInfoData, 0, sizeof(SP_DEVINFO_DATA));
*pDevInfo = INVALID_HANDLE_VALUE;
// Use local string to guarantee zero termination
pDriverName = (PCHAR) ALLOC((DWORD) cbDriverName + 1);
if (NULL == pDriverName)
{
status = FALSE;
goto Done;
}
StringCbCopyN(pDriverName, cbDriverName + 1, DriverName, cbDriverName);
//
// We cannot walk the device tree with CM_Get_Sibling etc. unless we assume
// the device tree will stabilize. Any devnode removal (even outside of USB)
// would force us to retry. Instead we use Setup API to snapshot all
// devices.
//
// Examine all present devices to see if any match the given DriverName
//
deviceInfo = SetupDiGetClassDevs(NULL,
NULL,
NULL,
DIGCF_ALLCLASSES | DIGCF_PRESENT);
if (deviceInfo == INVALID_HANDLE_VALUE)
{
status = FALSE;
goto Done;
}
deviceIndex = 0;
deviceInfoData.cbSize = sizeof(deviceInfoData);
while (done == FALSE)
{
//
// Get devinst of the next device
//
status = SetupDiEnumDeviceInfo(deviceInfo,
deviceIndex,
&deviceInfoData);
deviceIndex++;
if (!status)
{
//
// This could be an error, or indication that all devices have been
// processed. Either way the desired device was not found.
//
done = TRUE;
break;
}
//
// Get the DriverName value
//
bResult = GetDeviceProperty(deviceInfo,
&deviceInfoData,
SPDRP_DRIVER,
&buf);
// If the DriverName value matches, return the DeviceInstance
//
if (bResult == TRUE && buf != NULL && _stricmp(pDriverName, buf) == 0)
{
done = TRUE;
*pDevInfo = deviceInfo;
CopyMemory(pDevInfoData, &deviceInfoData, sizeof(deviceInfoData));
FREE(buf);
break;
}
if(buf != NULL)
{
FREE(buf);
buf = NULL;
}
}
Done:
if (bResult == FALSE)
{
if (deviceInfo != INVALID_HANDLE_VALUE)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
}
}
if (pDriverName != NULL)
{
FREE(pDriverName);
}
return status;
}
/*****************************************************************************
DriverNameToDeviceProperties()
Returns the Device properties of the DevNode with the matching DriverName.
Returns NULL if the matching DevNode is not found.
The caller should free the returned structure using FREE() macro
*****************************************************************************/
PUSB_DEVICE_PNP_STRINGS
DriverNameToDeviceProperties(
_In_reads_bytes_(cbDriverName) PCHAR DriverName,
_In_ size_t cbDriverName
)
{
HDEVINFO deviceInfo = INVALID_HANDLE_VALUE;
SP_DEVINFO_DATA deviceInfoData = {0};
ULONG len;
BOOL status;
PUSB_DEVICE_PNP_STRINGS DevProps = NULL;
DWORD lastError;
// Allocate device propeties structure
DevProps = (PUSB_DEVICE_PNP_STRINGS) ALLOC(sizeof(USB_DEVICE_PNP_STRINGS));
if(NULL == DevProps)
{
status = FALSE;
goto Done;
}
// Get device instance
status = DriverNameToDeviceInst(DriverName, cbDriverName, &deviceInfo, &deviceInfoData);
if (status == FALSE)
{
goto Done;
}
len = 0;
status = SetupDiGetDeviceInstanceId(deviceInfo,
&deviceInfoData,
NULL,
0,
&len);
lastError = GetLastError();
if (status != FALSE && lastError != ERROR_INSUFFICIENT_BUFFER)
{
status = FALSE;
goto Done;
}
//
// An extra byte is required for the terminating character
//
len++;
DevProps->DeviceId = ALLOC(len);
if (DevProps->DeviceId == NULL)
{
status = FALSE;
goto Done;
}
status = SetupDiGetDeviceInstanceId(deviceInfo,
&deviceInfoData,
DevProps->DeviceId,
len,
&len);
if (status == FALSE)
{
goto Done;
}
status = GetDeviceProperty(deviceInfo,
&deviceInfoData,
SPDRP_DEVICEDESC,
&DevProps->DeviceDesc);
if (status == FALSE)
{
goto Done;
}
//
// We don't fail if the following registry query fails as these fields are additional information only
//
GetDeviceProperty(deviceInfo,
&deviceInfoData,
SPDRP_HARDWAREID,
&DevProps->HwId);
GetDeviceProperty(deviceInfo,
&deviceInfoData,
SPDRP_SERVICE,
&DevProps->Service);
GetDeviceProperty(deviceInfo,
&deviceInfoData,
SPDRP_CLASS,
&DevProps->DeviceClass);
Done:
if (deviceInfo != INVALID_HANDLE_VALUE)
{
SetupDiDestroyDeviceInfoList(deviceInfo);
}
if (status == FALSE)
{
if (DevProps != NULL)
{
FreeDeviceProperties(&DevProps);
}
}
return DevProps;
}
/*****************************************************************************
FreeDeviceProperties()
Free the device properties structure
*****************************************************************************/
VOID FreeDeviceProperties(_In_ PUSB_DEVICE_PNP_STRINGS *ppDevProps)
{
if(ppDevProps == NULL)
{
return;
}
if(*ppDevProps == NULL)
{
return;
}
if ((*ppDevProps)->DeviceId != NULL)
{
FREE((*ppDevProps)->DeviceId);
}
if ((*ppDevProps)->DeviceDesc != NULL)
{
FREE((*ppDevProps)->DeviceDesc);
}
//
// The following are not necessary, but left in case
// in the future there is a later failure where these
// pointer fields would be allocated.
//
if ((*ppDevProps)->HwId != NULL)
{
FREE((*ppDevProps)->HwId);
}
if ((*ppDevProps)->Service != NULL)
{
FREE((*ppDevProps)->Service);
}
if ((*ppDevProps)->DeviceClass != NULL)
{
FREE((*ppDevProps)->DeviceClass);
}
if ((*ppDevProps)->PowerState != NULL)
{
FREE((*ppDevProps)->PowerState);
}
FREE(*ppDevProps);
*ppDevProps = NULL;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,682 @@
/*++
Copyright (c) 1997-2008 Microsoft Corporation
Module Name:
UVCVIEW.H
Abstract:
This is the header file for UVCVIEW
Environment:
user mode
Revision History:
04-25-97 : created
04/13/2005 : major bug fixing
--*/
/*****************************************************************************
I N C L U D E S
*****************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <initguid.h>
#include <devioctl.h>
#include <dbt.h>
#include <stdio.h>
#include <stddef.h>
#include <commctrl.h>
#include <usbioctl.h>
#include <usbiodef.h>
#include <intsafe.h>
#include <strsafe.h>
#include <specstrings.h>
#include <usb.h>
#include <usbuser.h>
#include <basetyps.h>
#include <wtypes.h>
#include <objbase.h>
#include <io.h>
#include <conio.h>
#include <shellapi.h>
#include <cfgmgr32.h>
#include <shlwapi.h>
#include <setupapi.h>
#include <winioctl.h>
#include <devpkey.h>
#include <math.h>
// This is mostly a private USB Audio descriptor header
#include "usbdesc.h"
// This is the inbox USBVideo driver descriptor header (copied locally)
#include "uvcdesc.h"
/*****************************************************************************
P R A G M A S
*****************************************************************************/
#pragma once
/*****************************************************************************
D E F I N E S
*****************************************************************************/
// define H264_SUPPORT to add H.264 support to uvcview.exe
#define H264_SUPPORT
#define TEXT_ITEM_LENGTH 64
#ifdef DEBUG
#undef DBG
#define DBG 1
#endif
#if DBG
#define OOPS() Oops(__FILE__, __LINE__)
#else
#define OOPS()
#endif
#if DBG
#define ALLOC(dwBytes) MyAlloc(__FILE__, __LINE__, (dwBytes))
#define REALLOC(hMem, dwBytes) MyReAlloc((hMem), (dwBytes))
#define FREE(hMem) MyFree((hMem))
#define CHECKFORLEAKS() MyCheckForLeaks()
#else
#define ALLOC(dwBytes) GlobalAlloc(GPTR,(dwBytes))
#define REALLOC(hMem, dwBytes) GlobalReAlloc((hMem), (dwBytes), (GMEM_MOVEABLE|GMEM_ZEROINIT))
#define FREE(hMem) GlobalFree((hMem))
#define CHECKFORLEAKS()
#endif
#define DEVICE_CONFIGURATION_TEXT_LENGTH 10240
#define STR_INVALID_POWER_STATE "(invalid state) "
#define STR_UNKNOWN_CONTROLLER_FLAVOR "Unknown"
FORCEINLINE
VOID
InitializeListHead(
_Out_ PLIST_ENTRY ListHead
)
{
ListHead->Flink = ListHead->Blink = ListHead;
}
//
// BOOLEAN
// IsListEmpty(
// PLIST_ENTRY ListHead
// );
//
#define IsListEmpty(ListHead) \
((ListHead)->Flink == (ListHead))
//
// PLIST_ENTRY
// RemoveHeadList(
// PLIST_ENTRY ListHead
// );
//
#define RemoveHeadList(ListHead) \
(ListHead)->Flink;\
{RemoveEntryList((ListHead)->Flink)}
//
// VOID
// RemoveEntryList(
// PLIST_ENTRY Entry
// );
//
#define RemoveEntryList(Entry) {\
PLIST_ENTRY _EX_Blink;\
PLIST_ENTRY _EX_Flink;\
_EX_Flink = (Entry)->Flink;\
_EX_Blink = (Entry)->Blink;\
_EX_Blink->Flink = _EX_Flink;\
_EX_Flink->Blink = _EX_Blink;\
}
//
// VOID
// InsertTailList(
// PLIST_ENTRY ListHead,
// PLIST_ENTRY Entry
// );
//
#define InsertTailList(ListHead,Entry) {\
PLIST_ENTRY _EX_Blink;\
PLIST_ENTRY _EX_ListHead;\
_EX_ListHead = (ListHead);\
_EX_Blink = _EX_ListHead->Blink;\
(Entry)->Flink = _EX_ListHead;\
(Entry)->Blink = _EX_Blink;\
_EX_Blink->Flink = (Entry);\
_EX_ListHead->Blink = (Entry);\
}
// global version for USB Video Class spec version (pre-release)
#define BCDVDC 0x0083
// A.2 Video Interface Subclass Codes
#define SC_VIDEO_INTERFACE_COLLECTION 0x03
// A.3 Video Interface Protocol Codes
#define PC_PROTOCOL_UNDEFINED 0x00
// USB Video Class spec version
#define NOT_UVC 0x0
#define UVC10 0x100
#define UVC11 0x110
#ifdef H264_SUPPORT
#define UVC15 0x150
#endif
#define OUTPUT_MESSAGE_MAX_LENGTH 1024
#define MAX_DEVICE_PROP 200
#define MAX_DRIVER_KEY_NAME 256
/*****************************************************************************
T Y P E D E F S
*****************************************************************************/
typedef enum _TREEICON
{
ComputerIcon,
HubIcon,
NoDeviceIcon,
GoodDeviceIcon,
BadDeviceIcon,
GoodSsDeviceIcon,
NoSsDeviceIcon
} TREEICON;
// Callback function for walking TreeView items
//
typedef VOID
(*LPFNTREECALLBACK)(
HWND hTreeWnd,
HTREEITEM hTreeItem,
PVOID pContext
);
// Callback notification function called at end of every tree depth
typedef VOID
(*LPFNTREENOTIFYCALLBACK)(PVOID pContext);
//
// Structure used to build a linked list of String Descriptors
// retrieved from a device.
//
typedef struct _STRING_DESCRIPTOR_NODE
{
struct _STRING_DESCRIPTOR_NODE *Next;
UCHAR DescriptorIndex;
USHORT LanguageID;
USB_STRING_DESCRIPTOR StringDescriptor[1];
} STRING_DESCRIPTOR_NODE, *PSTRING_DESCRIPTOR_NODE;
//
// A collection of device properties. The device can be hub, host controller or usb device
//
typedef struct _USB_DEVICE_PNP_STRINGS
{
PCHAR DeviceId;
PCHAR DeviceDesc;
PCHAR HwId;
PCHAR Service;
PCHAR DeviceClass;
PCHAR PowerState;
} USB_DEVICE_PNP_STRINGS, *PUSB_DEVICE_PNP_STRINGS;
typedef struct _DEVICE_INFO_NODE {
HDEVINFO DeviceInfo;
LIST_ENTRY ListEntry;
SP_DEVINFO_DATA DeviceInfoData;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceDetailData;
PSTR DeviceDescName;
ULONG DeviceDescNameLength;
PSTR DeviceDriverName;
ULONG DeviceDriverNameLength;
DEVICE_POWER_STATE LatestDevicePowerState;
} DEVICE_INFO_NODE, *PDEVICE_INFO_NODE;
//
// Structures assocated with TreeView items through the lParam. When an item
// is selected, the lParam is retrieved and the structure it which it points
// is used to display information in the edit control.
//
typedef enum _USBDEVICEINFOTYPE
{
HostControllerInfo,
RootHubInfo,
ExternalHubInfo,
DeviceInfo
} USBDEVICEINFOTYPE, *PUSBDEVICEINFOTYPE;
typedef struct _USBHOSTCONTROLLERINFO
{
USBDEVICEINFOTYPE DeviceInfoType;
LIST_ENTRY ListEntry;
PCHAR DriverKey;
ULONG VendorID;
ULONG DeviceID;
ULONG SubSysID;
ULONG Revision;
USB_POWER_INFO USBPowerInfo[6];
BOOL BusDeviceFunctionValid;
ULONG BusNumber;
USHORT BusDevice;
USHORT BusFunction;
PUSB_CONTROLLER_INFO_0 ControllerInfo;
PUSB_DEVICE_PNP_STRINGS UsbDeviceProperties;
} USBHOSTCONTROLLERINFO, *PUSBHOSTCONTROLLERINFO;
typedef struct _USBROOTHUBINFO
{
USBDEVICEINFOTYPE DeviceInfoType;
PUSB_NODE_INFORMATION HubInfo;
PUSB_HUB_INFORMATION_EX HubInfoEx;
PCHAR HubName;
PUSB_PORT_CONNECTOR_PROPERTIES PortConnectorProps;
PUSB_DEVICE_PNP_STRINGS UsbDeviceProperties;
PDEVICE_INFO_NODE DeviceInfoNode;
PUSB_HUB_CAPABILITIES_EX HubCapabilityEx;
} USBROOTHUBINFO, *PUSBROOTHUBINFO;
typedef struct _USBEXTERNALHUBINFO
{
USBDEVICEINFOTYPE DeviceInfoType;
PUSB_NODE_INFORMATION HubInfo;
PUSB_HUB_INFORMATION_EX HubInfoEx;
PCHAR HubName;
PUSB_NODE_CONNECTION_INFORMATION_EX ConnectionInfo;
PUSB_PORT_CONNECTOR_PROPERTIES PortConnectorProps;
PUSB_DESCRIPTOR_REQUEST ConfigDesc;
PUSB_DESCRIPTOR_REQUEST BosDesc;
PSTRING_DESCRIPTOR_NODE StringDescs;
PUSB_NODE_CONNECTION_INFORMATION_EX_V2 ConnectionInfoV2; // NULL if root HUB
PUSB_DEVICE_PNP_STRINGS UsbDeviceProperties;
PDEVICE_INFO_NODE DeviceInfoNode;
PUSB_HUB_CAPABILITIES_EX HubCapabilityEx;
} USBEXTERNALHUBINFO, *PUSBEXTERNALHUBINFO;
// HubInfo, HubName may be in USBDEVICEINFOTYPE, so they can be removed
typedef struct
{
USBDEVICEINFOTYPE DeviceInfoType;
PUSB_NODE_INFORMATION HubInfo; // NULL if not a HUB
PUSB_HUB_INFORMATION_EX HubInfoEx; // NULL if not a HUB
PCHAR HubName; // NULL if not a HUB
PUSB_NODE_CONNECTION_INFORMATION_EX ConnectionInfo; // NULL if root HUB
PUSB_PORT_CONNECTOR_PROPERTIES PortConnectorProps;
PUSB_DESCRIPTOR_REQUEST ConfigDesc; // NULL if root HUB
PUSB_DESCRIPTOR_REQUEST BosDesc; // NULL if root HUB
PSTRING_DESCRIPTOR_NODE StringDescs;
PUSB_NODE_CONNECTION_INFORMATION_EX_V2 ConnectionInfoV2; // NULL if root HUB
PUSB_DEVICE_PNP_STRINGS UsbDeviceProperties;
PDEVICE_INFO_NODE DeviceInfoNode;
PUSB_HUB_CAPABILITIES_EX HubCapabilityEx; // NULL if not a HUB
} USBDEVICEINFO, *PUSBDEVICEINFO;
typedef struct _STRINGLIST
{
#ifdef H264_SUPPORT
ULONGLONG ulFlag;
#else
ULONG ulFlag;
#endif
PCHAR pszString;
PCHAR pszModifier;
} STRINGLIST, * PSTRINGLIST;
typedef struct _DEVICE_GUID_LIST {
HDEVINFO DeviceInfo;
LIST_ENTRY ListHead;
} DEVICE_GUID_LIST, *PDEVICE_GUID_LIST;
/*****************************************************************************
G L O B A L S
*****************************************************************************/
//
// USBVIEW.C
//
BOOL gDoConfigDesc;
BOOL gDoAnnotation;
BOOL gLogDebug;
int TotalHubs;
//
// ENUM.C
//
PCHAR ConnectionStatuses[];
//
// DISPVID.C
//
DEFINE_GUID(YUY2_Format,0x32595559L,0x0000,0x0010,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71);
DEFINE_GUID(NV12_Format,0x3231564EL,0x0000,0x0010,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71);
#ifdef H264_SUPPORT
DEFINE_GUID(H264_Format,0x34363248, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71);
#endif
// The following flags/variables are all initialized in Display.c InitializePerDeviceSettings()
//
// Save the default frame from the MJPEG, Uncompressed, Vendor and Frame Based Format descriptor
// Check for this when processing the individual Frame descriptors
UCHAR g_chMJPEGFrameDefault;
UCHAR g_chUNCFrameDefault;
UCHAR g_chVendorFrameDefault;
UCHAR g_chFrameBasedFrameDefault;
// Spec version of UVC device
UINT g_chUVCversion;
// Base address of the USBDEVICEINFO for device we're parsing
PUSBDEVICEINFO CurrentUSBDeviceInfo;
// Base address of the Configuration descriptor we're parsing
PUSB_CONFIGURATION_DESCRIPTOR CurrentConfigDesc;
// Length of the current configuration descriptor
DWORD dwConfigLength;
// Our current position from the beginning of the config descriptor
DWORD dwConfigIndex;
//
// DISPLAY.C
//
int gDeviceSpeed;
// Save the current Configuration starting and ending addresses
// Used in ValidateDescAddress()
//
PUSB_CONFIGURATION_DESCRIPTOR g_pConfigDesc;
PSTRING_DESCRIPTOR_NODE g_pStringDescs;
PUCHAR g_descEnd;
/*****************************************************************************
F U N C T I O N P R O T O T Y P E S
*****************************************************************************/
//
// USBVIEW.C
//
HTREEITEM
AddLeaf (
HTREEITEM hTreeParent,
LPARAM lParam,
_In_ LPTSTR lpszText,
TREEICON TreeIcon
);
VOID
Oops
(
_In_ PCHAR File,
ULONG Line
);
//
// DISPLAY.C
//
EXTERN_C UINT IsIADDevice (PUSBDEVICEINFO info);
EXTERN_C UINT IsUVCDevice (PUSBDEVICEINFO info);
EXTERN_C PCHAR GetVendorString(USHORT idVendor);
EXTERN_C PCHAR GetLangIDString(USHORT idLang);
EXTERN_C UINT GetConfigurationSize (PUSBDEVICEINFO info);
EXTERN_C PUSB_COMMON_DESCRIPTOR
GetNextDescriptor(
_In_reads_bytes_(TotalLength)
PUSB_COMMON_DESCRIPTOR FirstDescriptor,
_In_
ULONG TotalLength,
_In_
PUSB_COMMON_DESCRIPTOR StartDescriptor,
_In_ long
DescriptorType
);
HRESULT
UpdateTreeItemDeviceInfo(
HWND hTreeWnd,
HTREEITEM hTreeItem
);
PCHAR
GetTextBuffer(
);
BOOL
ResetTextBuffer(
);
BOOL
CreateTextBuffer (
);
VOID
DestroyTextBuffer (
);
UINT
GetTextBufferPos (
);
VOID
UpdateEditControl (
HWND hEditWnd,
HWND hTreeWnd,
HTREEITEM hTreeItem
);
VOID __cdecl
AppendBuffer (
LPCTSTR lpFormat,
...
);
VOID __cdecl
AppendTextBuffer (
LPCTSTR lpFormat,
...
);
VOID
DisplayStringDescriptor (
UCHAR Index,
PSTRING_DESCRIPTOR_NODE StringDescs,
DEVICE_POWER_STATE LatestDevicePowerState
);
PCHAR
GetStringFromList(
PSTRINGLIST slPowerState,
ULONG ulNumElements,
#ifdef H264_SUPPORT
ULONGLONG ulFlag,
#else
ULONG ulFlag,
#endif
_In_ PCHAR szDefault
);
EXTERN_C PCHAR GetPowerStateString(
WDMUSB_POWER_STATE powerState
);
EXTERN_C PCHAR GetControllerFlavorString(
USB_CONTROLLER_FLAVOR flavor
);
EXTERN_C ULONG GetEhciDebugPort(
ULONG vendorId,
ULONG deviceId
);
VOID
WalkTreeTopDown(
_In_ HTREEITEM hTreeItem,
_In_ LPFNTREECALLBACK lpfnTreeCallback,
_In_opt_ PVOID pContext,
_In_opt_ LPFNTREENOTIFYCALLBACK lpfnTreeNotifyCallback
);
VOID RefreshTree (VOID);
//
// ENUM.C
//
VOID
EnumerateHostControllers (
HTREEITEM hTreeParent,
ULONG *DevicesConnected
);
VOID
CleanupItem (
HWND hTreeWnd,
HTREEITEM hTreeItem,
PVOID pContext
);
DEVICE_POWER_STATE
AcquireDevicePowerState(
_Inout_ PDEVICE_INFO_NODE pNode
);
_Success_(return == TRUE)
BOOL
GetDeviceProperty(
_In_ HDEVINFO DeviceInfoSet,
_In_ PSP_DEVINFO_DATA DeviceInfoData,
_In_ DWORD Property,
_Outptr_ LPTSTR *ppBuffer
);
void
ClearDeviceList(
PDEVICE_GUID_LIST DeviceList
);
//
// DEBUG.C
//
_Success_(return != NULL)
_Post_writable_byte_size_(dwBytes)
HGLOBAL
MyAlloc (
_In_ PCHAR File,
ULONG Line,
DWORD dwBytes
);
_Success_(return != NULL)
_Post_writable_byte_size_(dwBytes)
HGLOBAL
MyReAlloc (
HGLOBAL hMem,
DWORD dwBytes
);
HGLOBAL
MyFree (
HGLOBAL hMem
);
VOID
MyCheckForLeaks (
VOID
);
//
// DEVNODE.C
//
PUSB_DEVICE_PNP_STRINGS
DriverNameToDeviceProperties(
_In_reads_bytes_(cbDriverName) PCHAR DriverName,
_In_ size_t cbDriverName
);
VOID FreeDeviceProperties(
_In_ PUSB_DEVICE_PNP_STRINGS *ppDevProps
);
//
// DISPAUD.C
//
BOOL
DisplayAudioDescriptor (
PUSB_AUDIO_COMMON_DESCRIPTOR CommonDesc,
UCHAR bInterfaceSubClass
);
//
// DISPVID.C
//
BOOL
DisplayVideoDescriptor (
PVIDEO_SPECIFIC VidCommonDesc,
UCHAR bInterfaceSubClass,
PSTRING_DESCRIPTOR_NODE StringDescs,
DEVICE_POWER_STATE LatestDevicePowerState
);
//
// DISPLAY.C
//
BOOL
ValidateDescAddress (
PUSB_COMMON_DESCRIPTOR commonDesc
);
#ifdef CUSTOM_USBVIEW
EXTERN_C PUSBDEVICEINFO enumerate_hub_port(HANDLE hHubDevice, ULONG port_index);
EXTERN_C PUSBDEVICEINFO get_usb_device_info(const char* device_name/*\\\\.\\USB..*/);
EXTERN_C void free_usb_device_info(PUSBDEVICEINFO pudi);
#endif

View File

@ -0,0 +1,394 @@
/*++
Copyright (c) 1997-2008 Microsoft Corporation
Module Name:
USBDESC.H
Abstract:
This is a header file for USB descriptors which are not yet in
a standard system header file.
Environment:
user mode
Revision History:
03-06-1998 : created
03-28-2003 : minor changes to support UVC and USB200
--*/
#pragma pack(push, 1)
/*****************************************************************************
D E F I N E S
*****************************************************************************/
//
//Device Descriptor bDeviceClass values
//
#define USB_INTERFACE_CLASS_DEVICE 0x00
#define USB_COMMUNICATION_DEVICE 0x02
#define USB_HUB_DEVICE 0x09
#define USB_DEVICE_CLASS_BILLBOARD 0x11
#define USB_DIAGNOSTIC_DEVICE 0xDC
#define USB_WIRELESS_CONTROLLER_DEVICE 0xE0
#define USB_MISCELLANEOUS_DEVICE 0xEF
#define USB_VENDOR_SPECIFIC_DEVICE 0xFF
//
//Device Descriptor bDeviceSubClass values
//
#define USB_COMMON_SUB_CLASS 0x02
//
//Interface Descriptor bInterfaceClass values:
//
//#define USB_AUDIO_INTERFACE 0x01
//#define USB_CDC_CONTROL_INTERFACE 0x02
//#define USB_HID_INTERFACE 0x03
//#define USB_PHYSICAL_INTERFACE 0x05
//#define USB_IMAGE_INTERFACE 0x06
//#define USB_PRINTER_INTERFACE 0x07
//#define USB_MASS_STORAGE_INTERFACE 0x08
//#define USB_HUB_INTERFACE 0x09
#define USB_CDC_DATA_INTERFACE 0x0A
#define USB_CHIP_SMART_CARD_INTERFACE 0x0B
#define USB_CONTENT_SECURITY_INTERFACE 0x0D
#define USB_DIAGNOSTIC_DEVICE_INTERFACE 0xDC
#define USB_WIRELESS_CONTROLLER_INTERFACE 0xE0
#define USB_APPLICATION_SPECIFIC_INTERFACE 0xFE
//#define USB_VENDOR_SPECIFIC_INTERFACE 0xFF
#define USB_HID_DESCRIPTOR_TYPE 0x21
//
//IAD protocol values
//
#define USB_IAD_PROTOCOL 0x01
//
//Device class specific values
//
#define BILLBOARD_MAX_NUM_ALT_MODE 0x34
//
//USB 2.0 Specification Changes - New Descriptors
//
#define USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR_TYPE 0x07
#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 0x08
#define USB_OTG_DESCRIPTOR_TYPE 0x09
#define USB_DEBUG_DESCRIPTOR_TYPE 0x0A
#define USB_IAD_DESCRIPTOR_TYPE 0x0B
//
// USB Device Class Definition for Audio Devices
// Appendix A. Audio Device Class Codes
//
// A.2 Audio Interface Subclass Codes
//
#define USB_AUDIO_SUBCLASS_UNDEFINED 0x00
#define USB_AUDIO_SUBCLASS_AUDIOCONTROL 0x01
#define USB_AUDIO_SUBCLASS_AUDIOSTREAMING 0x02
#define USB_AUDIO_SUBCLASS_MIDISTREAMING 0x03
// A.4 Audio Class-Specific Descriptor Types
//
#define USB_AUDIO_CS_UNDEFINED 0x20
#define USB_AUDIO_CS_DEVICE 0x21
#define USB_AUDIO_CS_CONFIGURATION 0x22
#define USB_AUDIO_CS_STRING 0x23
#define USB_AUDIO_CS_INTERFACE 0x24
#define USB_AUDIO_CS_ENDPOINT 0x25
// A.5 Audio Class-Specific AC (Audio Control) Interface Descriptor Subtypes
//
#define USB_AUDIO_AC_UNDEFINED 0x00
#define USB_AUDIO_AC_HEADER 0x01
#define USB_AUDIO_AC_INPUT_TERMINAL 0x02
#define USB_AUDIO_AC_OUTPUT_TERMINAL 0x03
#define USB_AUDIO_AC_MIXER_UNIT 0x04
#define USB_AUDIO_AC_SELECTOR_UNIT 0x05
#define USB_AUDIO_AC_FEATURE_UNIT 0x06
#define USB_AUDIO_AC_PROCESSING_UNIT 0x07
#define USB_AUDIO_AC_EXTENSION_UNIT 0x08
// A.6 Audio Class-Specific AS (Audio Streaming) Interface Descriptor Subtypes
//
#define USB_AUDIO_AS_UNDEFINED 0x00
#define USB_AUDIO_AS_GENERAL 0x01
#define USB_AUDIO_AS_FORMAT_TYPE 0x02
#define USB_AUDIO_AS_FORMAT_SPECIFIC 0x03
// A.7 Processing Unit Process Types
//
#define USB_AUDIO_PROCESS_UNDEFINED 0x00
#define USB_AUDIO_PROCESS_UPDOWNMIX 0x01
#define USB_AUDIO_PROCESS_DOLBYPROLOGIC 0x02
#define USB_AUDIO_PROCESS_3DSTEREOEXTENDER 0x03
#define USB_AUDIO_PROCESS_REVERBERATION 0x04
#define USB_AUDIO_PROCESS_CHORUS 0x05
#define USB_AUDIO_PROCESS_DYNRANGECOMP 0x06
/*****************************************************************************
T Y P E D E F S
*****************************************************************************/
// HID Class HID Descriptor
//
typedef struct _USB_HID_DESCRIPTOR
{
UCHAR bLength;
UCHAR bDescriptorType;
USHORT bcdHID;
UCHAR bCountryCode;
UCHAR bNumDescriptors;
struct
{
UCHAR bDescriptorType;
USHORT wDescriptorLength;
} OptionalDescriptors[1];
} USB_HID_DESCRIPTOR, *PUSB_HID_DESCRIPTOR;
// OTG Descriptor
//
typedef struct _USB_OTG_DESCRIPTOR
{
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bmAttributes;
} USB_OTG_DESCRIPTOR, *PUSB_OTG_DESCRIPTOR;
// IAD Descriptor
//
typedef struct _USB_IAD_DESCRIPTOR
{
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bFirstInterface;
UCHAR bInterfaceCount;
UCHAR bFunctionClass;
UCHAR bFunctionSubClass;
UCHAR bFunctionProtocol;
UCHAR iFunction;
} USB_IAD_DESCRIPTOR, *PUSB_IAD_DESCRIPTOR;
// Common Class Endpoint Descriptor
//
typedef struct _USB_ENDPOINT_DESCRIPTOR2 {
UCHAR bLength; // offset 0, size 1
UCHAR bDescriptorType; // offset 1, size 1
UCHAR bEndpointAddress; // offset 2, size 1
UCHAR bmAttributes; // offset 3, size 1
USHORT wMaxPacketSize; // offset 4, size 2
USHORT wInterval; // offset 6, size 2
UCHAR bSyncAddress; // offset 8, size 1
} USB_ENDPOINT_DESCRIPTOR2, *PUSB_ENDPOINT_DESCRIPTOR2;
// Common Class Interface Descriptor
//
typedef struct _USB_INTERFACE_DESCRIPTOR2 {
UCHAR bLength; // offset 0, size 1
UCHAR bDescriptorType; // offset 1, size 1
UCHAR bInterfaceNumber; // offset 2, size 1
UCHAR bAlternateSetting; // offset 3, size 1
UCHAR bNumEndpoints; // offset 4, size 1
UCHAR bInterfaceClass; // offset 5, size 1
UCHAR bInterfaceSubClass; // offset 6, size 1
UCHAR bInterfaceProtocol; // offset 7, size 1
UCHAR iInterface; // offset 8, size 1
USHORT wNumClasses; // offset 9, size 2
} USB_INTERFACE_DESCRIPTOR2, *PUSB_INTERFACE_DESCRIPTOR2;
//
// USB Device Class Definition for Audio Devices
//
typedef struct _USB_AUDIO_COMMON_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
} USB_AUDIO_COMMON_DESCRIPTOR,
*PUSB_AUDIO_COMMON_DESCRIPTOR;
// 4.3.2 Class-Specific AC (Audio Control) Interface Descriptor
//
typedef struct _USB_AUDIO_AC_INTERFACE_HEADER_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
USHORT bcdADC;
USHORT wTotalLength;
UCHAR bInCollection;
UCHAR baInterfaceNr[1];
} USB_AUDIO_AC_INTERFACE_HEADER_DESCRIPTOR,
*PUSB_AUDIO_AC_INTERFACE_HEADER_DESCRIPTOR;
// 4.3.2.1 Input Terminal Descriptor
//
typedef struct _USB_AUDIO_INPUT_TERMINAL_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bTerminalID;
USHORT wTerminalType;
UCHAR bAssocTerminal;
UCHAR bNrChannels;
USHORT wChannelConfig;
UCHAR iChannelNames;
UCHAR iTerminal;
} USB_AUDIO_INPUT_TERMINAL_DESCRIPTOR,
*PUSB_AUDIO_INPUT_TERMINAL_DESCRIPTOR;
// 4.3.2.2 Output Terminal Descriptor
//
typedef struct _USB_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bTerminalID;
USHORT wTerminalType;
UCHAR bAssocTerminal;
UCHAR bSourceID;
UCHAR iTerminal;
} USB_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR,
*PUSB_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR;
// 4.3.2.3 Mixer Unit Descriptor
//
typedef struct _USB_AUDIO_MIXER_UNIT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bUnitID;
UCHAR bNrInPins;
UCHAR baSourceID[1];
} USB_AUDIO_MIXER_UNIT_DESCRIPTOR,
*PUSB_AUDIO_MIXER_UNIT_DESCRIPTOR;
// 4.3.2.4 Selector Unit Descriptor
//
typedef struct _USB_AUDIO_SELECTOR_UNIT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bUnitID;
UCHAR bNrInPins;
UCHAR baSourceID[1];
} USB_AUDIO_SELECTOR_UNIT_DESCRIPTOR,
*PUSB_AUDIO_SELECTOR_UNIT_DESCRIPTOR;
// 4.3.2.5 Feature Unit Descriptor
//
typedef struct _USB_AUDIO_FEATURE_UNIT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bUnitID;
UCHAR bSourceID;
UCHAR bControlSize;
UCHAR bmaControls[1];
} USB_AUDIO_FEATURE_UNIT_DESCRIPTOR,
*PUSB_AUDIO_FEATURE_UNIT_DESCRIPTOR;
// 4.3.2.6 Processing Unit Descriptor
//
typedef struct _USB_AUDIO_PROCESSING_UNIT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bUnitID;
USHORT wProcessType;
UCHAR bNrInPins;
UCHAR baSourceID[1];
} USB_AUDIO_PROCESSING_UNIT_DESCRIPTOR,
*PUSB_AUDIO_PROCESSING_UNIT_DESCRIPTOR;
// 4.3.2.7 Extension Unit Descriptor
//
typedef struct _USB_AUDIO_EXTENSION_UNIT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bUnitID;
USHORT wExtensionCode;
UCHAR bNrInPins;
UCHAR baSourceID[1];
} USB_AUDIO_EXTENSION_UNIT_DESCRIPTOR,
*PUSB_AUDIO_EXTENSION_UNIT_DESCRIPTOR;
// 4.5.2 Class-Specific AS Interface Descriptor
//
typedef struct _USB_AUDIO_GENERAL_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bTerminalLink;
UCHAR bDelay;
USHORT wFormatTag;
} USB_AUDIO_GENERAL_DESCRIPTOR,
*PUSB_AUDIO_GENERAL_DESCRIPTOR;
// 4.6.1.2 Class-Specific AS Endpoint Descriptor
//
typedef struct _USB_AUDIO_ENDPOINT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bmAttributes;
UCHAR bLockDelayUnits;
USHORT wLockDelay;
} USB_AUDIO_ENDPOINT_DESCRIPTOR,
*PUSB_AUDIO_ENDPOINT_DESCRIPTOR;
//
// USB Device Class Definition for Audio Data Formats
//
typedef struct _USB_AUDIO_COMMON_FORMAT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bFormatType;
} USB_AUDIO_COMMON_FORMAT_DESCRIPTOR,
*PUSB_AUDIO_COMMON_FORMAT_DESCRIPTOR;
// 2.1.5 Type I Format Type Descriptor
// 2.3.1 Type III Format Type Descriptor
//
typedef struct _USB_AUDIO_TYPE_I_OR_III_FORMAT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bFormatType;
UCHAR bNrChannels;
UCHAR bSubframeSize;
UCHAR bBitResolution;
UCHAR bSamFreqType;
} USB_AUDIO_TYPE_I_OR_III_FORMAT_DESCRIPTOR,
*PUSB_AUDIO_TYPE_I_OR_III_FORMAT_DESCRIPTOR;
// 2.2.6 Type II Format Type Descriptor
//
typedef struct _USB_AUDIO_TYPE_II_FORMAT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bDescriptorSubtype;
UCHAR bFormatType;
USHORT wMaxBitRate;
USHORT wSamplesPerFrame;
UCHAR bSamFreqType;
} USB_AUDIO_TYPE_II_FORMAT_DESCRIPTOR,
*PUSB_AUDIO_TYPE_II_FORMAT_DESCRIPTOR;
#pragma pack(pop)

File diff suppressed because it is too large Load Diff

1268
device/win_usb/win_usb.cpp Normal file

File diff suppressed because it is too large Load Diff

234
device/win_usb/win_usb.h Normal file
View File

@ -0,0 +1,234 @@
#pragma once
// implements USB as libusb on windows
//
// Date: 2022-04-01
#include <Windows.h>
#include <vector>
#include <algorithm>
#include <string>
#include <mutex>
#include <thread>
#include <memory>
#include "libusb-1.0/libusb.h"
// HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{6bdd1fc6-810f-11d0-bec7-08002be2092f}
#define HG_SCANNER_GUID "6BDD1FC6-810F-11D0-BEC7-08002BE2092F"
#define MONITOR_WINDOW_OWNER L"monitor_wnd_owner"
typedef struct _dev_id
{
int vid;
int pid;
bool operator==(const struct _dev_id& r)
{
return vid == r.vid && pid == r.pid;
}
}DEVID;
class usb_device // consider as libusb_device
{
volatile long ref_;
GUID guid_;
std::string name_;
DEVID id_;
bool is_ok_;
bool online_;
uint8_t port_;
enum
{
OVL_BULK_IN,
OVL_BULK_OUT,
OVL_CONTROL,
OVL_INTERRUPT,
OVL_MAX,
};
OVERLAPPED ovl_[OVL_MAX];
libusb_device_handle *handle_; // as file handle returned by CreateFile
libusb_device_descriptor *dev_desc_;
std::vector<libusb_config_descriptor*> cfg_desc_;
typedef struct _usb_pipe
{
UCHAR address;
int type;
HANDLE pipe;
}USBPIPE;
std::vector<USBPIPE> pipes_;
DWORD timout_ms_;
HANDLE find_pipe(UCHAR addr, int type);
int set_timeout(HANDLE h);
public:
usb_device(const char* name);
static DEVID vid_pid_from_name(const char* name); // device name like '\\?\usb#vid_3072&pid_0239#01234567aabbccddee#{a5dcbf10-6530-11d2-901f-00c04fb951ed}'
static DWORD from_hex_string(const char* hex_str);
static std::string driver_key_name(HANDLE file);
static std::string parent_hub_path_name(int vid, int pid, int *addr = NULL);
static bool find_vid_pid_in_hub(const char* utf8_hub_path_name, int vid, int pid, int *addr/*if *addr is not -1 or NULL, search the device with vid:pid and set the address in addr if it was not null, or-else chekc the device at *addr is vid:pid or not*/);
static int get_device_address(const char* device_name, LPGUID lpguid);
long add_ref(void);
long release(void);
protected:
~usb_device();
public:
bool operator==(const char* name);
bool operator==(const DEVID& id);
usb_device& operator=(const DEVID& id);
usb_device& operator=(const GUID& guid);
std::string name(void);
GUID guid(void);
DEVID id(void);
bool is_ok(void);
bool is_open(void);
bool is_online(void);
void set_online(bool online);
uint8_t port(void);
bool init(void);
void clear(void);
void online_statu_changed(bool online);
int get_descriptor(libusb_device_descriptor* desc);
int get_config_descriptor(int index, libusb_config_descriptor** desc);
int open(libusb_device_handle** dev_handle);
int close(void);
int set_timeout(unsigned milliseconds);
int transfer_bulk(unsigned endpoint, unsigned char* data, int* length, unsigned int timeout);
int transfer_control(uint8_t type, uint8_t req, uint16_t val, uint16_t ind, unsigned char* data, uint16_t len, unsigned timeout);
int transfer_interrupt(unsigned endpoint, unsigned char* data, int* length, unsigned int timeout);
};
class usb_callback
{
libusb_hotplug_callback_fn usb_cb_;
void* usb_cb_param_;
public:
usb_callback(libusb_hotplug_callback_fn cb, void* param);
~usb_callback();
public:
void notify(libusb_context* ctx, usb_device* dev, int ev);
};
class usb_monitor // consider as libusb_context
{
std::vector<usb_callback*> cbs_;
std::mutex lock_;
std::vector<usb_device*> devices_;
std::shared_ptr<std::thread> handle_msg_;
DWORD handle_msg_id_;
std::string cur_dev_name_;
volatile bool run_;
HWND wnd_monitor_;
static LRESULT CALLBACK monitor_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
static void register_monitor_wnd(const wchar_t* cls);
void notify_usb_event(usb_device*& dev, bool arrive);
int on_usb_pnp(WPARAM wp, LPARAM lp);
void find_usb(std::vector<std::string>& usb_devs);
public:
usb_monitor();
~usb_monitor();
static usb_monitor* usb_monitor_;
public:
usb_callback* reg_callback(libusb_hotplug_callback_fn cb, void* param);
void unreg_callback(usb_callback* cb);
void thread_run_device_event_wnd(void); // called in a seperate thread from libusb
void thread_handle_device_change_msg(void); // a seperate thread for WM_DEVICECHANGE cannot be blocked
void quit(void);
};
//1: \\?\usb#vid_0bda&pid_0129#20100201396000000#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
// DeviceIoControl error: 31
// USB\VID_0BDA&PID_0129\20100201396000000
// class: USB
// desc: Realtek USB 2.0 Card Reader
// HID: USB\VID_0BDA&PID_0129&REV_3960
// name: \Device\USBPDO-3
// bus : 1
// addr: 9
// guid: {36fc9e60-c465-11cf-8056-444553540000}
// path: PCIROOT(0)#PCI(1400)#USBROOT(0)#USB(9)
//
//2: \\?\usb#vid_06cb&pid_00ea#9bec419959f6#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
// Open error: 5
// USB\VID_06CB&PID_00EA\9BEC419959F6
// class: Biometric
// desc: Synaptics UWP WBDI
// HID: USB\VID_06CB&PID_00EA&REV_0000
// name: \Device\USBPDO-5
// bus : 1
// addr: 12
// guid: {53d29ef7-377c-4d14-864b-eb3a85769359}
// path: PCIROOT(0)#PCI(1400)#USBROOT(0)#USB(12)
//
//3: \\?\usb#vid_3072&pid_0239#01234567aabbccddee#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
// VID: 3072
// PID: 0239
// USB: 4.4
// USB\VID_3072&PID_0239\01234567AABBCCDDEE
// class: Image
// desc: HUAGOSCAN G200 TWAIN
// HID: USB\VID_3072&PID_0239&REV_0404
// name: \Device\USBPDO-7
// bus : 1
// addr: 8
// guid: {6bdd1fc6-810f-11d0-bec7-08002be2092f}
// path: PCIROOT(0)#PCI(1400)#USBROOT(0)#USB(8)
//
//4: \\?\usb#vid_17ef&pid_6100#5&4adfeed&0&6#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
// VID: 0000
// PID: 0000
// USB: 0.0
// USB\VID_17EF&PID_6100\5&4ADFEED&0&6
// class: USB
// desc: USB Composite Device
// HID: USB\VID_17EF&PID_6100&REV_0201
// name: \Device\USBPDO-1
// bus : 1
// addr: 6
// guid: {36fc9e60-c465-11cf-8056-444553540000}
// path: PCIROOT(0)#PCI(1400)#USBROOT(0)#USB(6)
//
//5: \\?\usb#vid_8087&pid_0026#5&4adfeed&0&14#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
// DeviceIoControl error: 50
// USB\VID_8087&PID_0026\5&4ADFEED&0&14
// class: Bluetooth
// desc: 英特尔(R) 无线 Bluetooth(R)
// HID: USB\VID_8087&PID_0026&REV_0002
// name: \Device\USBPDO-4
// bus : 1
// addr: 14
// guid: {e0cbf06c-cd8b-4647-bb8a-263b43f0f974}
// path: PCIROOT(0)#PCI(1400)#USBROOT(0)#USB(14)
//
//6: \\?\usb#vid_17ef&pid_608d#5&4adfeed&0&7#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
// Open error: 31
// USB\VID_17EF&PID_608D\5&4ADFEED&0&7
// class: HIDClass
// desc: USB 输入设备
// HID: USB\VID_17EF&PID_608D&REV_0100
// name: \Device\USBPDO-2
// bus : 1
// addr: 7
// guid: {745a17a0-74d3-11d0-b6fe-00a0c90f57da}
// path: PCIROOT(0)#PCI(1400)#USBROOT(0)#USB(7)
//

22
huagaotwain/dllmain.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "pch.h"
#include "huagaotwain.h"
HMODULE me_ = NULL;
BOOL APIENTRY DllMain(HMODULE hModule , DWORD ul_reason_for_call, LPVOID /* lpReserved */)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
//sane_invoker::initialize(hModule);
me_ = hModule;
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
//sane_invoker::uninitialize();
break;
}
return TRUE;
}

2189
huagaotwain/huagaotwain.cpp Normal file

File diff suppressed because it is too large Load Diff

446
huagaotwain/huagaotwain.h Normal file
View File

@ -0,0 +1,446 @@
#pragma once
#include "huagao/hgscanner_error.h"
#include <string>
#include <vector>
#include <algorithm>
#include <mutex>
#include "sane_option_trans.h"
class sane_invoker;
class scanner;
struct _dev;
class refer
{
volatile long ref_;
public:
refer() : ref_(1)
{}
protected:
virtual ~refer()
{}
public:
long add_ref(void)
{
return InterlockedIncrement(&ref_);
}
long release(void)
{
long ref = InterlockedDecrement(&ref_);
if (ref <= 0)
delete this;
return ref;
}
};
class scanned_img
{
SANE_Parameters param_;
std::vector<unsigned char> data_;
std::string file_header(SANE_FinalImgFormat* header, float resolution);
public:
scanned_img(SANE_Image* img, SANE_FinalImgFormat* header);
~scanned_img();
public:
int width(void);
int line_bytes(void);
int height(void);
int depth(void);
int channel(void);
SANE_Frame type(void);
unsigned int bytes(void);
unsigned char* bits(void);
void copy_header(SANE_Parameters* head);
};
extern HMODULE me_;
namespace local_utility
{
std::wstring reg_read(HKEY root, const wchar_t* path, const wchar_t* name);
std::wstring reg_get_app_installing_path(void);
}
class scanner : public refer
{
SANE_Handle hdev_;
sane_invoker* host_;
std::string name_;
std::string type_;
std::string vendor_;
std::string product_;
bool online_;
int option_count_;
std::mutex lock_img_;
std::vector<scanned_img*> img_;
SANE_FinalImgFormat *fmt_;
typedef struct _sane_option
{
int ind;
const SANE_Option_Descriptor* desc;
union
{
bool bv;
int iv;
double dv;
std::string* sv;
}val;
bool operator==(int id)
{
return ind == id;
}
}SANEOPTION;
std::vector<SANEOPTION> options_;
float dpi_;
HANDLE wait_img_;
volatile bool scanning_;
int err_;
std::string desc_;
void load_options(void);
void init_image_format(void);
std::string get_string(int opt, int bytes);
bool get_boolean(int opt);
int get_integer(int opt);
double get_double(int opt);
int set_string(int opt, std::string& val, int size, SANE_Int* afterdo = NULL);
enum twain_essential
{
TWAIN_RESOLUTION,
TWAIN_PAPER_SIZE,
};
int opt_ind_dpi_;
int opt_ind_color_mode_;
int opt_ind_paper_;
int opt_ind_scann_count_; // MAKELONG(count, scan_continue)
int opt_ind_text_direction_;
int opt_ind_page_;
int opt_ind_auto_descrew_;
int opt_ind_erase_black_frame_;
int opt_ind_filter_;
int opt_ind_bright_;
int opt_ind_contrast_;
int opt_ind_gamma_;
int opt_ind_ultrasonic_;
int opt_ind_flip_;
int opt_ind_rotate_bkg_;
int opt_ind_fill_blank_bkg_;
int opt_ind_edge_ident_;
int opt_ind_threshold_;
int opt_ind_bkg_filling_method_;
int opt_ind_fill_hole_;
int opt_ind_fill_hole_ratio_;
int opt_ind_noise_;
int opt_ind_noise_threshold_;
int opt_ind_rid_red_;
int opt_ind_rid_red_hsv_;
int opt_ind_sharpen_;
int opt_ind_screw_detect_;
int opt_ind_screw_detect_level_;
int opt_ind_staple_;
int opt_ind_dogear_;
int opt_ind_dark_sample_;
int opt_ind_split_;
int opt_ind_fade_bkg_;
int opt_ind_fade_bkg_val_;
int opt_ind_size_detect_;
int opt_ind_multi_out_;
SANE_ImageType img_fmt_;
int jpeg_quality_;
SANE_CompressionType compression_;
bool auto_crop_;
void(*event_cb_)(int, void*, unsigned int*, void*);
void* cb_param_;
public:
scanner(sane_invoker* host, struct _dev& dev);
static std::string type(SANE_Value_Type st);
static value_limit limit(SANE_Constraint_Type st);
protected:
~scanner();
public:
int close(void);
int start(void);
int stop(void);
void set_event_callback(void(*cb)(int, void*, unsigned int*, void*), void* param);
bool wait_image(DWORD milliseconds = -1);
int get_scanned_images(DWORD milliseconds = 0);
scanned_img* take_first_image(void); // delete returned value, plz
bool get_first_image_header(SANE_Parameters* header);
int last_error(void);
SANE_Handle handle(void);
bool is_online(void);
void set_online(bool online);
void put_image(SANE_Image* img, unsigned int* len);
void scan_finished(const char* desc, int err);
// up to sane, we set the CAP_xxx according to settings display in UI ...
bool get_value_info(int sn, std::string& type, value_limit& limit);
bool get_value(int sn, std::list<std::string>& values, std::string& now, std::string& init);
bool get_value(int sn, std::list<float>& values, float& now, float& init);
bool get_value(int sn, std::list<bool>& values, bool& now, bool& init);
bool get_value(int sn, int& now, int& init, int* lower = NULL, int* upper = NULL, int* step = NULL);
bool get_value(int sn, float& now, float& init, float* lower = NULL, float* upper = NULL, float* step = NULL);
int set_value(int sn, std::string val);
int set_value(int sn, bool val);
int set_value(int sn, int val);
int set_value(int sn, double val);
// attribute for twain ...
public:
int twain_set_resolution(float dpi);
float twain_get_resolution(float* init = NULL, std::vector<float>* values = NULL, value_limit* limit = NULL);
int twain_set_color_mode(int twain_pixel_type);
int twain_get_color_mode(int* init = NULL, std::vector<int>* values = NULL, value_limit* limit = NULL);
int twain_set_auto_color_type(int type);
int twain_get_paper_ind(void);
int twain_set_paper_lateral(bool lateral);
bool twain_is_paper_lateral(void);
int twain_set_paper_auto_match_size(bool match);
bool twain_is_paper_auto_match_size(void);
int twain_set_scan_count(int count);
int twain_get_scan_count(void);
int twain_set_final_format(SANE_ImageType type, void* param);
int twain_get_jpeg_quality(void);
SANE_ImageType get_final_format(void);
int twain_set_final_compression(int compression);
int twain_get_final_compression(int *init = NULL, std::vector<int>* values = NULL);
int twain_set_text_direction(double degree);
double twain_get_text_direction(double* init = NULL, std::list<double>* vals = NULL, value_limit* limit = NULL);
int twain_set_text_auto_matic(bool am);
bool twain_is_text_auto_matic(void);
int twain_set_page_duplex(bool dup);
bool twain_is_page_duplex(void);
int twain_set_page_discarding_blank_page(bool discard, bool receipt);
bool twain_is_page_discarding_blank_page(bool receipt);
int twain_set_page_fold(bool fold);
bool twain_is_page_fold(void);
int twain_set_auto_descrew(bool enable);
bool twain_is_auto_descrew(void);
int twain_set_erase_black_frame(bool erase);
bool twain_is_erase_black_frame(bool* init);
int twain_set_filter(int tw_filter, bool enhance);
int twain_get_filter(bool enhance);
int twain_set_bright(double bright);
double twain_get_bright(double* init = NULL, double* lower = NULL, double* upper = NULL, double* step = NULL);
int twain_set_contrast(double bright);
double twain_get_contrast(double* init = NULL, double* lower = NULL, double* upper = NULL, double* step = NULL);
int twain_set_gamma(double bright);
double twain_get_gamma(double* init = NULL, double* lower = NULL, double* upper = NULL, double* step = NULL);
int twain_set_ultrasonic_check(bool check);
bool twain_is_ultrasonic_check(bool* init = NULL);
bool twain_is_auto_crop(void);
bool twain_is_paper_on(void);
int twain_get_device_code(char* buf, unsigned int len);
int twain_set_sharpen(int sharpen);
int twain_get_sharpen(void);
int twain_get_serial_num(char buf[256]);
int twain_get_hareware_version(char buf[256]);
int twain_get_ip(char buf[256]);
int twain_get_dogear_distance(void);
int twain_set_dogear_distance(int dist);
int twain_set_power_level(int level);
int twain_get_power_level(void);
int twain_set_to_be_scan(bool yes);
bool twain_get_to_be_scan(void);
int twain_set_scan_with_hole(bool yes);
bool twain_get_scan_with_hole(void);
int twain_set_multioutput_type(int type);
int twain_get_multioutput_type(void);
int twain_get_flip_ind(void);
int twain_get_rotate_bkg_ind(void);
int twain_get_fill_black_bkg_ind(void);
int twain_get_edge_ident_ind(void);
int twain_get_threshold_ind(void);
int twain_bkg_filling_method_ind(void);
int twain_fill_hole_ind(void);
int twain_fill_hole_ratio_ind(void);
int twain_detach_noise_ind(void);
int twain_detach_noise_threshold_ind(void);
int twain_rid_red_ind(void);
int twain_rid_red_hsv_ind(void);
int twain_screw_detect_ind(void);
int twain_screw_detect_level_ind(void);
int twain_staple_detect_ind(void);
int twain_dogear_detect_ind(void);
int twain_dark_sample_ind(void);
int twain_image_split_ind(void);
int twain_fade_bkground_ind(void);
int twain_fade_bkground_val_ind(void);
int twain_size_detect_ind(void);
};
struct delete_scanner
{
void operator()(scanner* p)
{
p->release();
}
};
typedef struct _dev
{
scanner* scanner;
std::string name;
std::string type;
std::string vendor;
std::string product;
struct _dev()
{
scanner = NULL;
name = type = vendor = product = "";
}
bool operator==(const char* n)
{
return name == n;
}
bool operator==(SANE_Handle h)
{
return scanner && scanner->handle() == h;
}
}SANEDEV;
class sane_invoker
{
bool ok_;
std::wstring cfg_file_;
SANE_Int ver_;
HMODULE sane_;
HANDLE first_cb_;
SANEAPI sane_api_;
std::mutex lock_dev_;
std::vector<SANEDEV> devices_;
SANE_Status (*real_sane_init_)(SANE_Int* version_code, SANE_Auth_Callback authorize);
void (*real_sane_exit_)(void);
SANE_Status(*real_sane_get_devices_)(const SANE_Device*** device_list, SANE_Bool local_only);
SANE_Status(*real_sane_open_)(SANE_String_Const devicename, SANE_Handle* handle);
void (*real_sane_close_)(SANE_Handle handle);
const SANE_Option_Descriptor* (*real_sane_get_option_descriptor_)(SANE_Handle handle, SANE_Int option);
SANE_Status(*real_sane_control_option_)(SANE_Handle handle, SANE_Int option, SANE_Action action, void* value, SANE_Int* info);
SANE_Status(*real_sane_get_parameters_)(SANE_Handle handle, SANE_Parameters* params);
SANE_Status(*real_sane_start_)(SANE_Handle handle);
SANE_Status(*real_sane_read_)(SANE_Handle handle, SANE_Byte* data, SANE_Int max_length, SANE_Int* length);
void (*real_sane_cancel_)(SANE_Handle handle);
SANE_Status(*real_sane_set_io_mode_)(SANE_Handle handle, SANE_Bool non_blocking);
SANE_Status(*real_sane_get_select_fd_)(SANE_Handle handle, SANE_Int* fd);
SANE_String_Const(*real_sane_strstatus_)(SANE_Status status);
SANE_Status(*real_sane_init_ex_)(SANE_Int* version_code, sane_callback cb, void* param);
SANE_Status(*real_sane_io_control_)(SANE_Handle h, unsigned long code, void* data, unsigned* len);
void(*log_)(int, const char*);
bool load_sane(void);
int handle_sane_event(SANE_Handle hdev, int code, void* data, unsigned int* len);
void get_online_devices(std::vector<SANEDEV>& devs);
int get_online_device_count(void);
scanner* find_scanner(SANE_Handle hdev);
scanner* open(const char* name, int* err);
static void no_log(int, const char*);
static int sane_callback_handler( // 注册回调的对象,需要保证该回调是多线程安全的
SANE_Handle hdev // 产生事件的设备句柄
, int code // 回调事件代码
, void* data // 回调事件数据,根据事件代码有所不同,参照具体事件定义
, unsigned int* len // 数据长度字节或者event_data的缓冲区长度详细请看相应的事件代码
, void* param // 用户自定义数据与调用sane_init_ex传入时的保持一致
); // 返回值依不同的事件代码而定通常为“0”
static sane_invoker* inst_;
protected:
sane_invoker(const wchar_t* path);
~sane_invoker();
public:
static int load_dll(const wchar_t* path_dll, HMODULE* dll);
static bool initialize(HMODULE me);
static void uninitialize(void);
static std::string u2m(const wchar_t* u, int page = CP_ACP);
static std::wstring m2u(const char* m, int page = CP_ACP);
static std::string u2ansi(const wchar_t* u);
static std::string u2utf8(const wchar_t* u);
static std::string utf82ansi(const char* utf8);
static std::string ansi2utf8(const char* ansi);
static std::wstring utf82u(const char* utf8);
static std::wstring ansi2u(const char* ansi);
static void log_debug_info(const char* info);
#ifdef VLOG_OK
static void __cdecl log_debug_info(int bytes, const char* fmt, ...);
#endif
static SANE_Status invoke_sane_init(SANE_Int* version_code, SANE_Auth_Callback authorize);
static void invoke_sane_exit(void);
static SANE_Status invoke_sane_get_devices(const SANE_Device*** device_list, SANE_Bool local_only);
static SANE_Status invoke_sane_open(SANE_String_Const devicename, SANE_Handle* handle);
static void invoke_sane_close(SANE_Handle handle);
static const SANE_Option_Descriptor* invoke_sane_get_option_descriptor(SANE_Handle handle, SANE_Int option);
static SANE_Status invoke_sane_control_option(SANE_Handle handle, SANE_Int option, SANE_Action action, void* value, SANE_Int* info);
static SANE_Status invoke_sane_get_parameters(SANE_Handle handle, SANE_Parameters* params);
static SANE_Status invoke_sane_start(SANE_Handle handle);
static SANE_Status invoke_sane_read(SANE_Handle handle, SANE_Byte* data, SANE_Int max_length, SANE_Int* length);
static void invoke_sane_cancel(SANE_Handle handle);
static SANE_Status invoke_sane_set_io_mode(SANE_Handle handle, SANE_Bool non_blocking);
static SANE_Status invoke_sane_get_select_fd(SANE_Handle handle, SANE_Int* fd);
static SANE_String_Const invoke_sane_strstatus(SANE_Status status);
static SANE_Status invoke_sane_init_ex(SANE_Int* version_code, sane_callback cb, void* param);
static SANE_Status invoke_sane_io_control(SANE_Handle h, unsigned long code, void* data, unsigned* len);
static LPSANEAPI get_api(void);
public:
static bool is_ok(void);
static std::string version(LPDWORD v = NULL);
static void get_devices(std::vector<SANEDEV>& devs);
static scanner* open_scanner(const char* name, int* err);
static int online_devices(void);
};

View File

@ -0,0 +1,61 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// 中文(简体,中国) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // 中文(简体,中国) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,184 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{c3b47ce2-27ce-4509-ab59-3c0f194f0fce}</ProjectGuid>
<Keyword>DynamicLibrary</Keyword>
<RootNamespace>huagaotwain</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)..\..\sdk\include\;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)..\..\sdk\include\;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>TWPP_NO_NOTES;TWPP_IS_DS;HGSCANNER_EXPORT;CUSTOM_USBVIEW;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>$(ProjectDir)twain.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
copy $(TargetPath) $(WinDir)\twain_32\HuaGoScan\$(ProjectName).ds /y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>TWPP_NO_NOTES;TWPP_IS_DS;HGSCANNER_EXPORT;CUSTOM_USBVIEW;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>$(ProjectDir)twain.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
copy $(TargetPath) $(WinDir)\twain_32\HuaGoScan\$(ProjectName).ds /y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\sdk\hginclude\huagao_ui.h" />
<ClInclude Include="huagaotwain.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="sane_option_trans.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="twain\huagaods.hpp" />
<ClInclude Include="twain\twain_2.4.h" />
<ClInclude Include="twain\twpp.hpp" />
<ClInclude Include="twain\twpp\application.hpp" />
<ClInclude Include="twain\twpp\audio.hpp" />
<ClInclude Include="twain\twpp\capability.hpp" />
<ClInclude Include="twain\twpp\cie.hpp" />
<ClInclude Include="twain\twpp\curveresponse.hpp" />
<ClInclude Include="twain\twpp\customdata.hpp" />
<ClInclude Include="twain\twpp\datasource.hpp" />
<ClInclude Include="twain\twpp\deviceevent.hpp" />
<ClInclude Include="twain\twpp\element8.hpp" />
<ClInclude Include="twain\twpp\enums.hpp" />
<ClInclude Include="twain\twpp\env.hpp" />
<ClInclude Include="twain\twpp\event.hpp" />
<ClInclude Include="twain\twpp\exception.hpp" />
<ClInclude Include="twain\twpp\extimageinfo.hpp" />
<ClInclude Include="twain\twpp\filesystem.hpp" />
<ClInclude Include="twain\twpp\fix32.hpp" />
<ClInclude Include="twain\twpp\frame.hpp" />
<ClInclude Include="twain\twpp\identity.hpp" />
<ClInclude Include="twain\twpp\imageinfo.hpp" />
<ClInclude Include="twain\twpp\imagelayout.hpp" />
<ClInclude Include="twain\twpp\imagememxfer.hpp" />
<ClInclude Include="twain\twpp\imagenativexfer.hpp" />
<ClInclude Include="twain\twpp\internal.hpp" />
<ClInclude Include="twain\twpp\jpegcompression.hpp" />
<ClInclude Include="twain\twpp\memory.hpp" />
<ClInclude Include="twain\twpp\memoryops.hpp" />
<ClInclude Include="twain\twpp\palette8.hpp" />
<ClInclude Include="twain\twpp\passthrough.hpp" />
<ClInclude Include="twain\twpp\pendingxfers.hpp" />
<ClInclude Include="twain\twpp\setupfilexfer.hpp" />
<ClInclude Include="twain\twpp\setupmemxfer.hpp" />
<ClInclude Include="twain\twpp\status.hpp" />
<ClInclude Include="twain\twpp\strings.hpp" />
<ClInclude Include="twain\twpp\twglue.hpp" />
<ClInclude Include="twain\twpp\types.hpp" />
<ClInclude Include="twain\twpp\typesops.hpp" />
<ClInclude Include="twain\twpp\userinterface.hpp" />
<ClInclude Include="twain\twpp\utils.hpp" />
<ClInclude Include="ui.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="huagaotwain.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="sane_option_trans.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="twain\huagaods.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="ui.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="twain.def" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="huagaotwain.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,165 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="twain">
<UniqueIdentifier>{668e9513-f6db-4f9d-9e0e-76cb8b5b7882}</UniqueIdentifier>
</Filter>
<Filter Include="twain\twpp">
<UniqueIdentifier>{df21031b-938a-4a08-ae64-e869e2586201}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="huagaotwain.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="twain\huagaods.cpp">
<Filter>twain</Filter>
</ClCompile>
<ClCompile Include="sane_option_trans.cpp" />
<ClCompile Include="ui.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="huagaotwain.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="twain\twain_2.4.h">
<Filter>twain</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\application.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\audio.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\capability.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\cie.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\curveresponse.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\customdata.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\datasource.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\deviceevent.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\element8.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\enums.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\env.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\event.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\exception.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\extimageinfo.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\filesystem.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\fix32.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\frame.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\identity.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\imageinfo.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\imagelayout.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\imagememxfer.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\imagenativexfer.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\internal.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\jpegcompression.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\memory.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\memoryops.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\palette8.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\passthrough.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\pendingxfers.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\setupfilexfer.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\setupmemxfer.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\status.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\strings.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\twglue.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\types.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\typesops.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\userinterface.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\twpp\utils.hpp">
<Filter>twain\twpp</Filter>
</ClInclude>
<ClInclude Include="twain\huagaods.hpp">
<Filter>twain</Filter>
</ClInclude>
<ClInclude Include="twain\twpp.hpp">
<Filter>twain</Filter>
</ClInclude>
<ClInclude Include="sane_option_trans.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="..\..\sdk\hginclude\huagao_ui.h" />
<ClInclude Include="ui.h" />
</ItemGroup>
<ItemGroup>
<None Include="twain.def" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="huagaotwain.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

1
huagaotwain/pch.cpp Normal file
View File

@ -0,0 +1 @@
#include "pch.h"

9
huagaotwain/pch.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include "targetver.h"
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>

15
huagaotwain/resource.h Normal file
View File

@ -0,0 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 huagaotwain.rc 使用
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -0,0 +1,630 @@
#include "sane_option_trans.h"
#include <Windows.h>
#include "./twain/twain_2.4.h"
namespace sane_trans
{
bool get_value_list(const SANE_Option_Descriptor* desc, std::list<std::string>* values)
{
if (desc->type != SANE_TYPE_STRING)
return false;
if (desc->constraint_type != SANE_CONSTRAINT_STRING_LIST)
return false;
const SANE_String_Const* str = desc->constraint.string_list;
int ind = 0;
while (str[ind])
values->push_back(str[ind++]);
return true;
}
bool get_value_list(const SANE_Option_Descriptor* desc, std::list<double>* values)
{
if (desc->type != SANE_TYPE_INT && desc->type != SANE_TYPE_FIXED)
return false;
if (desc->constraint_type != SANE_CONSTRAINT_WORD_LIST)
return false;
const SANE_Word* val = desc->constraint.word_list;
if (desc->type == SANE_TYPE_FIXED)
{
for (int i = 0; i < val[0]; ++i)
values->push_back(SANE_UNFIX(val[i + 1]));
}
else
{
for (int i = 0; i < val[0]; ++i)
values->push_back(val[i + 1]);
}
return true;
}
bool get_value_range(const SANE_Option_Descriptor* desc, double* lower, double* upper)
{
if (desc->type != SANE_TYPE_INT && desc->type != SANE_TYPE_FIXED)
return false;
if (desc->constraint_type != SANE_CONSTRAINT_RANGE)
return false;
if (desc->type == SANE_TYPE_FIXED)
{
*lower = SANE_UNFIX(desc->constraint.range->min);
*upper = SANE_UNFIX(desc->constraint.range->max);
}
else
{
*lower = desc->constraint.range->min;
*upper = desc->constraint.range->max;
}
return true;
}
}
namespace color_mode
{
static char g_name[] = { "\351\242\234\350\211\262\346\250\241\345\274\217" }; // 颜色模式
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
struct
{
int tw_pixel;
char op_val[80];
}g_ops[] = { {TWPT_BW, { "\351\273\221\347\231\275" }}, // 黑白
{TWPT_GRAY, { "256\347\272\247\347\201\260\345\272\246" }}, // 256级灰度
{TWPT_RGB, { "24\344\275\215\345\275\251\350\211\262" }}, // 24位彩色
{TWPT_AUTOMATIC_COLOR, {"\351\242\234\350\211\262\350\207\252\345\212\250\350\257\206\345\210\253"}} // 颜色自动识别
};
int to_twain_pixel_type(const char* op_val)
{
for (size_t i = 0; i < _countof(g_ops); ++i)
{
if (strcmp(g_ops[i].op_val, op_val) == 0)
return g_ops[i].tw_pixel;
}
return TWPT_RGB;
}
std::string from_twain_pixel_type(int twpt)
{
for (size_t i = 0; i < _countof(g_ops); ++i)
{
if (g_ops[i].tw_pixel == twpt)
return g_ops[i].op_val;
}
return g_ops[_countof(g_ops) - 1].op_val;
}
}
namespace dpi
{
static char g_name[] = { "\345\210\206\350\276\250\347\216\207" }; // 分辨率
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace paper
{
static char g_name[] = { "\347\272\270\345\274\240\345\260\272\345\257\270" }; // 纸张尺寸
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
static char g_lateral[] = { "\346\250\252\345\220\221" };
bool is_lateral(const char* paper_val)
{
return strstr(paper_val, g_lateral) != NULL;
}
std::string lateral_title(void)
{
return g_lateral;
}
static char g_auto_size[] = { "\345\214\271\351\205\215\345\216\237\345\247\213\345\260\272\345\257\270" }; // 匹配原始尺寸
bool is_auto_size(const char* paper_val)
{
return strstr(paper_val, g_auto_size) != NULL;
}
std::string auto_size_title(void)
{
return g_auto_size;
}
static char g_auto_crop[] = { "\346\234\200\345\244\247\346\211\253\346\217\217\345\260\272\345\257\270\350\207\252\345\212\250\350\243\201\345\210\207" }; // 最大扫描尺寸自动裁切
bool is_auto_crop(const char* paper_val)
{
return strstr(paper_val, g_auto_crop) != NULL;
}
}
namespace scan_count
{
static char g_parent[] = { "\346\211\253\346\217\217\345\274\240\346\225\260" };// 扫描张数
bool is_parent(const char* desc_title)
{
return strcmp(g_parent, desc_title) == 0;
}
static char g_name[] = { "\346\211\253\346\217\217\346\225\260\351\207\217" }; // 扫描数量
bool is_me(const char* desc_title)
{
return strstr(desc_title, g_name);
}
std::string scan_continous_val(void)
{
return "\350\277\236\347\273\255\346\211\253\346\217\217"; // 连续扫描
}
}
namespace text_direction
{
static char g_direction[] = { "\346\226\207\347\250\277\346\226\271\345\220\221" }; // 文稿方向
bool is_me(const char* desc_title)
{
return strcmp(desc_title, g_direction) == 0;
}
struct
{
double angle;
std::string op_val;
}g_ops[] = { {.0f, "0\302\260"}
, {90.0f, "90\302\260"}
, {180.0f, "180\302\260"}
, {270.0f, "270\302\260"}
};
static char g_auto_dir[] = { "\350\207\252\345\212\250\346\226\207\346\234\254\346\226\271\345\220\221\350\257\206\345\210\253\302\260" }; // 自动文本方向识别°
double to_twain_angle(const char* opt_val)
{
for (size_t i = 0; i < _countof(g_ops); ++i)
{
if (g_ops[i].op_val == opt_val)
return g_ops[i].angle;
}
return g_ops[0].angle;
}
std::string from_twain_angle(double angle)
{
for (size_t i = 0; i < _countof(g_ops); ++i)
{
if (IS_DOUBLE_EQUAL(g_ops[i].angle, angle))
return g_ops[i].op_val;
}
return g_ops[0].op_val;
}
bool is_auto(const char* opt_val)
{
return strcmp(opt_val, g_auto_dir) == 0;
}
std::string auto_val(void)
{
return g_auto_dir;
}
}
namespace page
{
static char g_name[] = { "\346\211\253\346\217\217\351\241\265\351\235\242" }; // 扫描页面
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
static char g_not_duplex[] = { "\345\215\225\351\235\242" }; // 单面
static char g_duplex[] = { "\345\217\214\351\235\242" }; // 双面
bool is_duplex(const char* opval)
{
return strcmp(opval, g_duplex) == 0;
}
std::string from_duplex(bool duplex)
{
return duplex ? g_duplex : g_not_duplex;
}
static char g_discard_blank[] = { "\350\267\263\350\277\207\347\251\272\347\231\275\351\241\265\357\274\210\351\200\232\347\224\250\357\274\211" }; // 跳过空白页(通用)
static char g_discard_blank_receipt[] = { "\350\267\263\350\277\207\347\251\272\347\231\275\351\241\265\357\274\210\345\217\221\347\245\250\347\272\270\357\274\211" }; // 跳过空白页(发票纸)
bool is_discard_blank_page(const char* opval, bool receipt)
{
return receipt ? strcmp(g_discard_blank_receipt, opval) == 0 :
strcmp(g_discard_blank, opval) == 0;
}
std::string discard_blank_page_title(bool receipt)
{
return receipt ? g_discard_blank_receipt : g_discard_blank;
}
static char g_fold[] = { "\345\257\271\346\212\230" }; // 对折
bool is_fold(const char* opval)
{
return strcmp(g_fold, opval) == 0;
}
std::string fold_page_title(void)
{
return g_fold;
}
}
namespace auto_descrew
{
static char g_name[] = { "\350\207\252\345\212\250\347\272\240\345\201\217" }; // 自动纠偏
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace erase_black_frame
{
static char g_name[] = { "\346\266\210\351\231\244\351\273\221\346\241\206" }; // 消除黑框
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace filter
{
static char g_name[] = { "\347\201\260\345\272\246\346\210\226\351\273\221\347\231\275\345\233\276\345\203\217 - \351\231\244\350\211\262" }; // 灰度或黑白图像 - 除色
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
struct
{
int twfilter;
std::string opt_val;
}g_ops[] = { {TWFT_RED, "\351\231\244\347\272\242\350\211\262"} // 除红色
, {TWFT_GREEN, "\351\231\244\347\273\277\350\211\262"} // 除绿色
, {TWFT_BLUE, "\351\231\244\350\223\235\350\211\262"} // 除蓝色
, {TWFT_NONE, "\344\270\215\351\231\244\350\211\262"} // 不除色
// 颜色增强
// , {ENHANCE_COLOR_NONE, "\351\231\244\347\273\277\350\211\262"} // 不增强
, {ENHANCE_COLOR_RED, "\347\272\242\350\211\262\345\242\236\345\274\272"} // 红色增强
, {ENHANCE_COLOR_GREEN,"\347\273\277\350\211\262\345\242\236\345\274\272"} // 绿色增强
, {ENHANCE_COLOR_BLUE, "\350\223\235\350\211\262\345\242\236\345\274\272"} // 蓝色增强
};
static int g_enhance_base = 4;
int to_filter_type(const char* opt_val, bool enhance)
{
if (enhance)
{
for (size_t i = g_enhance_base; i < _countof(g_ops); ++i)
{
if (g_ops[i].opt_val == opt_val)
return g_ops[i].twfilter;
}
return ENHANCE_COLOR_NONE;
}
for (size_t i = 0; i < g_enhance_base; ++i)
{
if (g_ops[i].opt_val == opt_val)
return g_ops[i].twfilter;
}
return TWFT_NONE;
}
std::string from_filter_type(int filter, bool enhance)
{
if (enhance)
{
for (size_t i = g_enhance_base; i < _countof(g_ops); ++i)
{
if (g_ops[i].twfilter == filter)
return g_ops[i].opt_val;
}
}
else
{
for (size_t i = 0; i < g_enhance_base; ++i)
{
if (g_ops[i].twfilter == filter)
return g_ops[i].opt_val;
}
}
return g_ops[g_enhance_base - 1].opt_val;
}
}
namespace bright
{
static char g_name[] = { "\344\272\256\345\272\246" }; // 亮度
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace contrast
{
static char g_name[] = { "\345\257\271\346\257\224\345\272\246" }; // 对比度
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace gamma
{
static char g_name[] = { "\344\274\275\347\216\233" }; // 伽玛
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace ultrasonic
{
static char g_name[] = { "\350\266\205\345\243\260\346\263\242\346\243\200\346\265\213" }; // 超声波检测
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace flip
{
static char g_name[] = { "\344\272\244\346\215\242\346\255\243\345\217\215\351\235\242" }; // 交换正反面
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace rotate_bg
{
static char g_name[] = { "\350\203\214\351\235\242\346\227\213\350\275\254180\302\260" }; // 背面旋转180°
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace fill_black_border
{
static char g_name[] = { "\346\266\210\351\231\244\351\273\221\346\241\206" }; // 消除黑框
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace edge_ident
{
static char g_name[] = { "\350\276\271\347\274\230\347\274\251\350\277\233" }; // 边缘缩进
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace threshold
{
static char g_name[] = { "\351\230\210\345\200\274" }; // 阈值
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace bkg_filling_method
{
static char g_name[] = { "\350\203\214\346\231\257\345\241\253\345\205\205\346\226\271\345\274\217" }; // 背景填充方式
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
static char g_convex[] = { "\345\207\270\345\244\232\350\276\271\345\275\242" };// 凸多边形
bool is_convex(const char* opval)
{
return strcmp(opval, g_convex) == 0;
}
}
namespace fill_hole
{
static char g_name[] = { "\347\251\277\345\255\224\347\247\273\351\231\244" }; // 穿孔移除
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
static char g_ratio[] = { "\347\251\277\345\255\224\346\220\234\347\264\242\350\214\203\345\233\264\345\215\240\345\271\205\351\235\242\346\257\224\344\276\213" }; // 穿孔搜索范围占幅面比例
bool is_ratio(const char* desc_title)
{
return strstr(desc_title, g_ratio) != NULL;
}
}
namespace noise
{
static char g_name[] = { "\351\273\221\347\231\275\345\233\276\345\203\217\345\231\252\347\202\271\344\274\230\345\214\226" }; // 黑白图像噪点优化
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
static char g_threshold[] = { "\345\231\252\347\202\271\344\274\230\345\214\226\345\260\272\345\257\270" }; // 噪点优化尺寸
bool is_threshold(const char* desc_title)
{
return strstr(desc_title, g_threshold) != NULL;
}
}
namespace rid_red
{
static char g_name[] = { "24\344\275\215\345\275\251\350\211\262\345\233\276\345\203\217 - \345\244\232\346\265\201\350\276\223\345\207\272\351\231\244\347\272\242" }; // 24位彩色图像 - 多流输出除红
static char g_hsv[] = { "24\344\275\215\345\275\251\350\211\262\345\233\276\345\203\217 - \347\255\224\351\242\230\345\215\241\351\231\244\347\272\242" }; // 24位彩色图像 - 答题卡除红
bool is_me(const char* desc_title, bool hsv)
{
return strcmp(hsv ? g_hsv : g_name, desc_title) == 0;
}
}
namespace sharpen
{
static char g_name[] = { "\351\224\220\345\214\226\344\270\216\346\250\241\347\263\212" }; // 锐化与模糊
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
struct
{
int type;
std::string op_val;
}g_ops[] = { {SHARPEN_NONE, "\346\227\240"} // 无
, {SHARPEN_NORMAL, "\351\224\220\345\214\226"} // 锐化
, {SHARPEN_MORE, "\350\277\233\344\270\200\346\255\245\351\224\220\345\214\226"} // 进一步锐化
, {SHARPEN_BLUR, "\346\250\241\347\263\212"} // 模糊
, {SHARPEN_BLUR_MORE, "\350\277\233\344\270\200\346\255\245\346\250\241\347\263\212"} // 进一步模糊
};
int to_type(const char* opval)
{
for (size_t i = 0; i < _countof(g_ops); ++i)
{
if (g_ops[i].op_val == opval)
return g_ops[i].type;
}
return SHARPEN_NONE;
}
std::string from_type(int type)
{
for (size_t i = 0; i < _countof(g_ops); ++i)
{
if (g_ops[i].type == type)
return g_ops[i].op_val;
}
return g_ops[0].op_val;
}
}
namespace screw
{
static char g_name[] = { "\346\255\252\346\226\234\346\243\200\346\265\213" }; // 歪斜检测
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
static char g_level[] = { "\346\255\252\346\226\234\346\243\200\346\265\213\345\244\215\346\235\202\345\272\246" }; // 歪斜检测复杂度
bool is_level(const char* desc_title)
{
return strstr(desc_title, g_level) != NULL;
}
}
namespace staple
{
static char g_name[] = { "\350\243\205\350\256\242\346\243\200\346\265\213" }; // 装订检测
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace dogear
{
static char g_name[] = { "\346\212\230\350\247\222\346\243\200\346\265\213" }; // 折角检测
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace sample
{
static char g_name[] = { "\346\267\261\350\211\262\346\240\267\345\274\240" }; // 深色样张
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace split
{
static char g_name[] = { "\345\233\276\345\203\217\346\213\206\345\210\206" }; // 图像拆分
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace fade_bkg
{
static char g_name[] = { "\350\203\214\346\231\257\347\247\273\351\231\244" }; // 背景移除
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
static char g_val[] = { "\350\203\214\346\231\257\350\211\262\345\275\251\346\265\256\345\212\250\350\214\203\345\233\264" }; // 背景色彩浮动范围
bool is_value(const char* desc_title)
{
return strstr(desc_title, g_val) != NULL;
}
}
namespace size_detect
{
static char g_name[] = { "\345\260\272\345\257\270\346\243\200\346\265\213" }; // 尺寸检测
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
}
namespace multi_out
{
static char g_name[] = { "24\344\275\215\345\275\251\350\211\262\345\233\276\345\203\217-\345\244\232\346\265\201\350\276\223\345\207\272" }; // 24位彩色图像-多流输出
bool is_me(const char* desc_title)
{
return strcmp(g_name, desc_title) == 0;
}
struct
{
int type;
std::string op_val;
}g_ops[] = { {MULTI_OUT_NONE, "\344\270\215\351\200\211\346\213\251\350\276\223\345\207\272\346\250\241\345\274\217"} // 不选择输出模式
, {MULTI_OUT_ALL, "\345\275\251\350\211\262+\347\201\260\345\272\246+\351\273\221\347\231\275"} // 彩色+灰度+黑白
, {MULTI_OUT_COLOR_GRAY, "\345\275\251\350\211\262+\347\201\260\345\272\246"} // 彩色+灰度
, {MULTI_OUT_COLOR_BW, "\345\275\251\350\211\262+\351\273\221\347\231\275"} // 彩色+黑白
, {MULTI_OUT_GRAY_BW, "\347\201\260\345\272\246+\351\273\221\347\231\275"} // 灰度+黑白
};
int to_twain_type(const char* opval)
{
for (int i = 0; i < _countof(g_ops); ++i)
{
if (g_ops[i].op_val == opval)
return g_ops[i].type;
}
return MULTI_OUT_NONE;
}
std::string from_twain_type(int type)
{
for (int i = 0; i < _countof(g_ops); ++i)
{
if (g_ops[i].type == type)
return g_ops[i].op_val;
}
return g_ops[0].op_val;
}
}

View File

@ -0,0 +1,230 @@
// utilities for transfroming options between TWAIN and sane ...
//
// Date: 2022-04-14
//
#pragma once
#include "sane/sane_ex.h"
#include <list>
#include <string>
#include <math.h>
#define TWPT_AUTOMATIC_COLOR 0x0a0c
#define IS_DOUBLE_EQUAL(a, b) fabs((a) - (b)) < .000001
#define ENHANCE_COLOR_NONE 0
#define ENHANCE_COLOR_RED 1
#define ENHANCE_COLOR_GREEN 2
#define ENHANCE_COLOR_BLUE 3
#define SHARPEN_NONE 0
#define SHARPEN_NORMAL 1
#define SHARPEN_MORE 2
#define SHARPEN_BLUR 3
#define SHARPEN_BLUR_MORE 4
#define MULTI_OUT_NONE -1
#define MULTI_OUT_ALL 0
#define MULTI_OUT_COLOR_GRAY 1
#define MULTI_OUT_COLOR_BW 2
#define MULTI_OUT_GRAY_BW 3
enum value_limit
{
VAL_LIMIT_NONE = 0, //
VAL_LIMIT_ENUM, //
VAL_LIMIT_RANGE, //
};
namespace sane_trans
{
bool get_value_list(const SANE_Option_Descriptor* desc, std::list<std::string>* values);
bool get_value_list(const SANE_Option_Descriptor* desc, std::list<double>* values);
bool get_value_range(const SANE_Option_Descriptor* desc, double* lower, double* upper);
}
namespace color_mode
{
bool is_me(const char* desc_title);
int to_twain_pixel_type(const char* op_val);
std::string from_twain_pixel_type(int twpt);
}
namespace dpi
{
bool is_me(const char* desc_title);
}
namespace paper
{
bool is_me(const char* desc_title);
bool is_lateral(const char* paper_val);
std::string lateral_title(void);
bool is_auto_size(const char* paper_val);
std::string auto_size_title(void);
bool is_auto_crop(const char* paper_val);
}
namespace scan_count
{
bool is_parent(const char* desc_title);
bool is_me(const char* desc_title);
std::string scan_continous_val(void);
}
namespace text_direction
{
bool is_me(const char* desc_title);
double to_twain_angle(const char* opt_val);
std::string from_twain_angle(double angle);
bool is_auto(const char* opt_val);
std::string auto_val(void);
}
namespace page
{
bool is_me(const char* desc_title);
bool is_duplex(const char* opval);
std::string from_duplex(bool duplex);
bool is_discard_blank_page(const char* opval, bool receipt);
std::string discard_blank_page_title(bool receipt);
bool is_fold(const char* opval);
std::string fold_page_title(void);
}
namespace auto_descrew
{
bool is_me(const char* desc_title);
}
namespace erase_black_frame
{
bool is_me(const char* desc_title);
}
namespace filter
{
bool is_me(const char* desc_title);
int to_filter_type(const char* opt_val, bool enhance);
std::string from_filter_type(int filter, bool enhance);
}
namespace bright
{
bool is_me(const char* desc_title);
}
namespace contrast
{
bool is_me(const char* desc_title);
}
namespace gamma
{
bool is_me(const char* desc_title);
}
namespace ultrasonic
{
bool is_me(const char* desc_title);
}
namespace flip
{
bool is_me(const char* desc_title);
}
namespace rotate_bg
{
bool is_me(const char* desc_title);
}
namespace fill_black_border
{
bool is_me(const char* desc_title);
}
namespace edge_ident
{
bool is_me(const char* desc_title);
}
namespace threshold
{
bool is_me(const char* desc_title);
}
namespace bkg_filling_method
{
bool is_me(const char* desc_title);
bool is_convex(const char* opval);
}
namespace fill_hole
{
bool is_me(const char* desc_title);
bool is_ratio(const char* desc_title);
}
namespace noise
{
bool is_me(const char* desc_title);
bool is_threshold(const char* desc_title);
}
namespace rid_red
{
bool is_me(const char* desc_title, bool hsv/*是否为答题卡除红*/);
}
namespace sharpen
{
bool is_me(const char* desc_title);
int to_type(const char* opval);
std::string from_type(int type);
}
namespace screw
{
bool is_me(const char* desc_title);
bool is_level(const char* desc_title);
}
namespace staple
{
bool is_me(const char* desc_title);
}
namespace dogear
{
bool is_me(const char* desc_title);
}
namespace sample
{
bool is_me(const char* desc_title);
}
namespace split
{
bool is_me(const char* desc_title);
}
namespace fade_bkg
{
bool is_me(const char* desc_title);
bool is_value(const char* desc_title);
}
namespace size_detect
{
bool is_me(const char* desc_title);
}
namespace multi_out
{
bool is_me(const char* desc_title);
int to_twain_type(const char* opval);
std::string from_twain_type(int type);
}

8
huagaotwain/targetver.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
//如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>

3
huagaotwain/twain.def Normal file
View File

@ -0,0 +1,3 @@
LIBRARY huagaotwain
EXPORTS
DS_Entry

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,105 @@
#ifndef SIMPLEDS_HPP
#define SIMPLEDS_HPP
#include <unordered_map>
#include <vector>
#include <atlstr.h>
#include <functional>
#include <queue>
#include <string>
#include "twpp.hpp"
#include "../huagaotwain.h"
namespace std {
template<>
struct hash<Twpp::CapType> {
size_t operator()(Twpp::CapType cap) const {
return hash<Twpp::UInt16>()(static_cast<Twpp::UInt16>(cap));
}
};
}
class twain_ui;
class huagao_ds : public Twpp::SourceFromThis<huagao_ds> {
std::unordered_map<Twpp::CapType, std::function<Twpp::Result(Twpp::Msg msg, Twpp::Capability& data)>> m_caps;
std::unordered_map<Twpp::CapType, Twpp::MsgSupport> m_query;
std::unique_ptr <scanner, delete_scanner> scanner_;
Twpp::SetupFileXfer m_fileXfer;
Twpp::XferMech m_capXferMech = Twpp::XferMech::Native;
std::unique_ptr<std::thread> memoryinfo;
std::unique_ptr<twain_ui> ui_;
bool m_memoryfalg = true;
bool m_bFeederEnabled = true;
bool m_bAutoFeed = true;
HANDLE singleton_ = NULL;
Twpp::Bool m_autoscan = true;
int automaticcolortype_ = 0;
bool multi_out_ = false;
bool m_bIndicator = true;
static std::string get_hidedlg_path(void);
static void showmsg(const char* msg, int err);
static void scan_event(int sane_event, void* data, unsigned int* len, void* param);
void CapabilityPrintf(Twpp::Msg msg, std::string capability, std::string value = "");
Twpp::Result capCommon(const Twpp::Identity& origin, Twpp::Msg msg, Twpp::Capability& data);
Twpp::Result showTwainUI(Twpp::UserInterface& data, bool bUiOnly = false);
void init_support_caps(void);
void init_support_caps_ex(void);
void on_scan_event(int sane_event, void* data, unsigned int* len);
public:
huagao_ds();
virtual ~huagao_ds();
static const Twpp::Identity& defaultIdentity() noexcept;
static Twpp::Result selectIdentity(Twpp::Identity& ident) noexcept;
static Twpp::ConditionCode condition_code_from_hg_error(int hgerr);
// SourceFromThis interface
protected:
typedef Twpp::SourceFromThis<huagao_ds> Base;
virtual Twpp::Result capabilityGet(const Twpp::Identity& origin, Twpp::Capability& data) override;
virtual Twpp::Result capabilityGetCurrent(const Twpp::Identity& origin, Twpp::Capability& data) override;
virtual Twpp::Result capabilityGetDefault(const Twpp::Identity& origin, Twpp::Capability& data) override;
virtual Twpp::Result capabilityQuerySupport(const Twpp::Identity& origin, Twpp::Capability& data) override;
virtual Twpp::Result capabilityReset(const Twpp::Identity& origin, Twpp::Capability& data) override;
virtual Twpp::Result capabilityResetAll(const Twpp::Identity& origin) override;
virtual Twpp::Result capabilitySet(const Twpp::Identity& origin, Twpp::Capability& data) override;
virtual Twpp::Result eventProcess(const Twpp::Identity& origin, Twpp::Event& data) override;
virtual Twpp::Result deviceEventGet(const Twpp::Identity& origin, Twpp::DeviceEvent& data) override;
virtual Twpp::Result identityOpenDs(const Twpp::Identity& origin) override;
virtual Twpp::Result identityCloseDs(const Twpp::Identity& origin) override;
virtual Twpp::Result pendingXfersGet(const Twpp::Identity& origin, Twpp::PendingXfers& data) override;
virtual Twpp::Result pendingXfersEnd(const Twpp::Identity& origin, Twpp::PendingXfers& data) override;
virtual Twpp::Result pendingXfersReset(const Twpp::Identity& origin, Twpp::PendingXfers& data) override;
virtual Twpp::Result setupMemXferGet(const Twpp::Identity& origin, Twpp::SetupMemXfer& data) override;
virtual Twpp::Result userInterfaceDisable(const Twpp::Identity& origin, Twpp::UserInterface& data) override;
virtual Twpp::Result userInterfaceEnable(const Twpp::Identity& origin, Twpp::UserInterface& data) override;
virtual Twpp::Result userInterfaceEnableUiOnly(const Twpp::Identity& origin, Twpp::UserInterface& data) override;
virtual Twpp::Result imageInfoGet(const Twpp::Identity& origin, Twpp::ImageInfo& data) override;
virtual Twpp::Result imageLayoutGet(const Twpp::Identity& origin, Twpp::ImageLayout& data) override;
virtual Twpp::Result imageLayoutGetDefault(const Twpp::Identity& origin, Twpp::ImageLayout& data) override;
virtual Twpp::Result imageLayoutSet(const Twpp::Identity& origin, Twpp::ImageLayout& data) override;
virtual Twpp::Result imageLayoutReset(const Twpp::Identity& origin, Twpp::ImageLayout& data) override;
virtual Twpp::Result imageMemXferGet(const Twpp::Identity& origin, Twpp::ImageMemXfer& data) override;
virtual Twpp::Result imageNativeXferGet(const Twpp::Identity& origin, Twpp::ImageNativeXfer& data) override;
virtual Twpp::Result pendingXfersStopFeeder(const Twpp::Identity& origin, Twpp::PendingXfers& data) override;
virtual Twpp::Result imageFileXferGet(const Twpp::Identity& origin) override;
virtual Twpp::Result setupFileXferGet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result setupFileXferGetDefault(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result setupFileXferSet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result setupFileXferReset(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result call(const Twpp::Identity& origin, Twpp::DataGroup dg, Twpp::Dat dat, Twpp::Msg msg, void* data) override;
virtual Twpp::Result customDataGet(const Twpp::Identity& origin, Twpp::CustomData& data) override;
virtual Twpp::Result customDataSet(const Twpp::Identity& origin, Twpp::CustomData& data) override;
public:
void SetResoluton(const char* path, int resolution);
};
#endif // SIMPLEDS_HPP

File diff suppressed because it is too large Load Diff

114
huagaotwain/twain/twpp.hpp Normal file
View File

@ -0,0 +1,114 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_TWPP_HPP
#define TWPP_DETAIL_FILE_TWPP_HPP
#include "twpp/env.hpp"
#include <cstdint>
#include <cstdlib>
#include <initializer_list>
#include <memory>
#include <utility>
#include <iterator>
#include <type_traits>
#include <limits>
#include <stdexcept>
#include <mutex>
#include <condition_variable>
#include <map>
#include <string>
#include <list>
#include <cstring>
#include <array>
#include <utility>
#include <cassert>
#include "twpp/utils.hpp"
#include "twpp/types.hpp"
#include "twpp/strings.hpp"
#include "twpp/fix32.hpp"
#include "twpp/frame.hpp"
#include "twpp/exception.hpp"
#include "twpp/typesops.hpp"
#include "twpp/memoryops.hpp"
#include "twpp/memory.hpp"
#include "twpp/enums.hpp"
#include "twpp/status.hpp"
#include "twpp/identity.hpp"
#include "twpp/imageinfo.hpp"
#include "twpp/imagelayout.hpp"
#include "twpp/deviceevent.hpp"
#include "twpp/element8.hpp"
#include "twpp/audio.hpp"
#include "twpp/capability.hpp"
#include "twpp/customdata.hpp"
#include "twpp/cie.hpp"
#include "twpp/curveresponse.hpp"
#include "twpp/event.hpp"
#include "twpp/extimageinfo.hpp"
#include "twpp/filesystem.hpp"
#include "twpp/imagememxfer.hpp"
#include "twpp/imagenativexfer.hpp"
#include "twpp/internal.hpp"
#include "twpp/jpegcompression.hpp"
#include "twpp/palette8.hpp"
#include "twpp/passthrough.hpp"
#include "twpp/pendingxfers.hpp"
#include "twpp/setupfilexfer.hpp"
#include "twpp/setupmemxfer.hpp"
#include "twpp/userinterface.hpp"
#if !defined(TWPP_IS_DS)
# include "twpp/application.hpp"
#else
# include "twpp/datasource.hpp"
#endif
#if !defined(TWPP_NO_NOTES)
# if !defined(TWPP_IS_DS)
# pragma message ("note: using APPLICATION version of TWPP library, define TWPP_IS_DS before including twpp.hpp if you want DATA SOURCE version")
# if defined(TWPP_DETAIL_OS_WIN32)
# pragma message ("note: place the following into your module-definition (.def) file: EXPORTS DS_Entry @1")
# endif
# else
# pragma message ("note: using DATA SOURCE version of TWPP library, undefine TWPP_IS_DS if you want APPLICATION version")
# pragma message ("note: make sure to place TWPP_ENTRY(<your-source-class-type>) macro in exactly one source file")
# endif
# if defined(TWPP_DETAIL_OS_MAC)
# pragma message "warning: Str32, Str64, Str128 and Str255 are not null-terminated"
# endif
# pragma message ("note: to disable notes and warnings, define TWPP_NO_NOTES before including TWPP header")
#endif
#endif // TWPP_DETAIL_FILE_TWPP_HPP

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,119 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_AUDIO_HPP
#define TWPP_DETAIL_FILE_AUDIO_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Information about current audio transfer.
/// ArgType::AudioInfo
class AudioInfo {
public:
/// Creates empty audio info.
constexpr AudioInfo() noexcept :
m_name(), m_reserved(){}
/// Creates audio info with set name of audio data.
explicit constexpr AudioInfo(const Str255& name, UInt32 reserved = 0) noexcept :
m_name(name), m_reserved(reserved){}
/// Name of audio data.
constexpr const Str255& name() const noexcept{
return m_name;
}
/// Name of audio data.
Str255& name() noexcept{
return m_name;
}
constexpr UInt32 reserved() const noexcept{
return m_reserved;
}
void setReserved(UInt32 reserved) noexcept{
m_reserved = reserved;
}
private:
Str255 m_name;
UInt32 m_reserved;
};
/// Owner of audio transfer handle.
class AudioNativeXfer {
public:
template<typename T>
using Data = Detail::Lock<typename std::decay<T>::type>;
template<typename T>
using ConstData = Detail::Lock<const typename std::decay<T>::type>;
/// Creates an empty handle owner.
AudioNativeXfer() noexcept :
m_handle(){}
/// Creates a memory area of desired size for audio native transfer.
/// \throw std::bad_alloc
explicit AudioNativeXfer(UInt32 size) :
m_handle(Detail::alloc(size)){}
/// Audio data.
template<typename T = void>
Data<T> data() noexcept{
return m_handle.lock<typename std::decay<T>::type>();
}
/// Audio data.
template<typename T = void>
ConstData<T> data() const noexcept{
return m_handle.lock<const typename std::decay<T>::type>();
}
/// Releases the owned handle.
/// The user becomes responsible for freeing the handle.
Handle release() noexcept{
return m_handle.release();
}
private:
Detail::UniqueHandle m_handle;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_AUDIO_HPP

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,269 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_CIE_HPP
#define TWPP_DETAIL_FILE_CIE_HPP
#if 0
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Part of CieColor structure.
class CiePoint {
public:
/// Creates zero-initialized cie point.
constexpr CiePoint() noexcept :
m_x(), m_y(), m_z(){}
/// Creates cie point with desired values.
constexpr CiePoint(Fix32 x, Fix32 y, Fix32 z) noexcept :
m_x(x), m_y(y), m_z(z){}
/// X value of CIE space.
constexpr Fix32 x() const noexcept{
return m_x;
}
/// Y value of CIE space.
constexpr Fix32 y() const noexcept{
return m_y;
}
/// Z value of CIE space.
constexpr Fix32 z() const noexcept{
return m_z;
}
/// Sets x value of CIE space.
void setX(Fix32 x) noexcept{
m_x = x;
}
/// Sets y value of CIE space.
void setY(Fix32 y) noexcept{
m_y = y;
}
/// Sets z value of CIE space.
void setZ(Fix32 z) noexcept{
m_z = z;
}
private:
Fix32 m_x;
Fix32 m_y;
Fix32 m_z;
};
/// Defines parameters for channel transformations.
/// Part of TransformStage.
class DecodeFunction {
public:
/// Creates zero-initialized decode function.
constexpr DecodeFunction() noexcept{}
/// Creates initialized decode function.
constexpr DecodeFunction(
Fix32 startIn,
Fix32 breakIn,
Fix32 endIn,
Fix32 startOut,
Fix32 breakOut,
Fix32 endOut,
Fix32 gamma,
Fix32 sampleCount
) noexcept :
m_startIn(startIn), m_breakIn(breakIn), m_endIn(endIn),
m_startOut(startOut), m_breakOut(breakOut), m_endOut(endOut),
m_gamma(gamma), m_sampleCount(sampleCount){}
/// Starting input value.
constexpr Fix32 startIn() const noexcept{
return m_startIn;
}
/// Sets starting input value.
void setStartIn(Fix32 startIn) noexcept{
m_startIn = startIn;
}
/// Ending input value.
constexpr Fix32 breakIn() const noexcept{
return m_breakIn;
}
/// Sets ending input value.
void setBreakIn(Fix32 breakIn) noexcept{
m_breakIn = breakIn;
}
/// Input value when to switch from linear to gamma transformation.
constexpr Fix32 endIn() const noexcept{
return m_endIn;
}
/// Sets input value when to switch from linear to gamma transformation.
void setEndIn(Fix32 endIn) noexcept{
m_endIn = endIn;
}
/// Starting output value.
constexpr Fix32 startOut() const noexcept{
return m_startOut;
}
/// Sets starting output value.
void setStartOut(Fix32 startOut) noexcept{
m_startOut = startOut;
}
/// Ending output value.
constexpr Fix32 breakOut() const noexcept{
return m_breakOut;
}
/// Sets ending output value.
void setBreakOut(Fix32 breakOut) noexcept{
m_breakOut = breakOut;
}
/// Output value when to switch from linear to gamma transformation.
constexpr Fix32 endOut() const noexcept{
return m_endOut;
}
/// Sets output value when to switch from linear to gamma transformation.
void setEndOut(Fix32 endOut) noexcept{
m_endOut = endOut;
}
/// Constant, exponential used in gamma funciton.
constexpr Fix32 gamma() const noexcept{
return m_gamma;
}
/// Sets constant, exponential used in gamma funciton.
void setGamma(Fix32 gamma) noexcept{
m_gamma = gamma;
}
/// Number of samples in lookup table.
constexpr Fix32 sampleCount() const noexcept{
return m_sampleCount;
}
/// Sets number of samples in lookup table.
void setSampleCount(Fix32 sampleCount) noexcept{
m_sampleCount = sampleCount;
}
private:
Fix32 m_startIn;
Fix32 m_breakIn;
Fix32 m_endIn;
Fix32 m_startOut;
Fix32 m_breakOut;
Fix32 m_endOut;
Fix32 m_gamma;
Fix32 m_sampleCount;
};
/// Parameters of ABC or LMN transformations.
/// Refer to manual for more information about members.
class TransformStage {
public:
typedef std::array<DecodeFunction, 3> Decode;
typedef std::array<std::array<Fix32, 3>, 3> Mix;
constexpr TransformStage() noexcept :
m_decode(), m_mix(){}
constexpr TransformStage(const Decode& decode) noexcept :
m_decode(decode), m_mix(){}
constexpr TransformStage(const Mix& mix) noexcept :
m_decode(), m_mix(mix){}
constexpr TransformStage(const Decode& decode, const Mix& mix) noexcept :
m_decode(decode), m_mix(mix){}
constexpr const Decode& decode() const noexcept{
return m_decode;
}
Decode& decode() noexcept{
return m_decode;
}
constexpr const Mix& mix() const noexcept{
return m_mix;
}
Mix& mix() noexcept{
return m_mix;
}
private:
Decode m_decode;
Mix m_mix;
};
namespace Unsupported {
// TODO CieColor
/// Cie color
/// Currently stub, more info required.
struct CieColor {
UInt16 m_colorSpace;
Bool m_lowEndian;
Bool m_deviceDependent;
Int32 m_versionNumber;
TransformStage m_stageAbc;
TransformStage m_stageLmn;
CiePoint m_whitePoint;
CiePoint m_blackPoint;
CiePoint m_whitePaper;
CiePoint m_blackInk;
Fix32 m_samples[1]; // <- how many elements? how to use?
};
}
TWPP_DETAIL_PACK_END
}
#endif
#endif // TWPP_DETAIL_FILE_CIE_HPP

View File

@ -0,0 +1,116 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_CURVERESPONSE_HPP
#define TWPP_DETAIL_FILE_CURVERESPONSE_HPP
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
/// Base response class.
class CurveResponse {
public:
CurveResponse() noexcept{}
/// Creates a new (Rgb|Gray)Response with default elements, make sure that info.bitsPerPixel() is <= 8.
/// \throw RangeException When info.bitsPerPixel() is negative or greater than 8.
explicit CurveResponse(const ImageInfo& info) : CurveResponse(info.bitsPerPixel()){}
/// Creates a new (Rgb|Gray)Response with default elements, make sure that bitsPerPixel is <= 8.
/// \throw RangeException When bitsPerPixel is negative or greater than 8.
explicit CurveResponse(Int16 bitsPerPixel){
if (bitsPerPixel <= 0 || bitsPerPixel > 8){
throw RangeException();
}
UInt16 size = 1 << static_cast<UInt16>(bitsPerPixel);
m_data.reset(new Element8[size]);
for (UInt16 i = 0; i < size; i++){
m_data[i] = Element8(static_cast<UInt8>(i)); // 0..255 max
}
}
/// Array of size `2^ImageInfo.bitesPerPixel()`, up to 256 elements (2^8)
Element8* data() noexcept{
return m_data.get();
}
/// Array of size `2^ImageInfo.bitesPerPixel()`, up to 256 elements (2^8)
const Element8* data() const noexcept{
return m_data.get();
}
private:
std::unique_ptr<Element8[]> m_data;
};
}
/// Rgb response class.
class RgbResponse : public Detail::CurveResponse {
public:
RgbResponse() noexcept{}
/// Creates a new RgbResponse with default elements, make sure that info.bitesPerPixel() is <= 8.
/// \throw RangeException When info.bitsPerPixel() is negative or greater than 8.
explicit RgbResponse(const ImageInfo& info) :
Detail::CurveResponse(info) {}
/// Creates a new RgbResponse with default elements, make sure that bitsPerPixel is <= 8.
/// \throw RangeException When bitsPerPixel is negative or greater than 8.
explicit RgbResponse(Int16 bitsPerPixel) :
Detail::CurveResponse(bitsPerPixel) {}
};
/// Gray response class.
class GrayResponse : public Detail::CurveResponse {
public:
GrayResponse() noexcept{}
/// Creates a new GrayResponse with default elements, make sure that info.bitesPerPixel() is <= 8.
/// \throw RangeException When info.bitsPerPixel() is negative or greater than 8.
explicit GrayResponse(const ImageInfo& info) :
Detail::CurveResponse(info) {}
/// Creates a new GrayResponse with default elements, make sure that bitsPerPixel is <= 8.
/// \throw RangeException When bitsPerPixel is negative or greater than 8.
explicit GrayResponse(Int16 bitsPerPixel) :
Detail::CurveResponse(bitsPerPixel) {}
};
}
#endif // TWPP_DETAIL_FILE_CURVERESPONSE_HPP

View File

@ -0,0 +1,71 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_CUSTOMDATA_HPP
#define TWPP_DETAIL_FILE_CUSTOMDATA_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Structure for sending custom data to source or application.
class CustomData {
public:
template <typename T>
using Data = typename Detail::Lock<T>;
/// Creates empty custom data.
CustomData() noexcept :
m_size(0), m_handle(){}
/// Creates custom data with allocated memory.
/// \throw std::bad_alloc
explicit CustomData(UInt32 size) :
m_size(size), m_handle(Detail::alloc(size)){}
/// Locks and returns pointer to custom data memory.
template<typename T = void>
Data<T> lock() const noexcept{
return Data<T>(m_handle.get());
}
/// The size of contained memory block.
UInt32 size() const noexcept{
return m_size;
}
private:
UInt32 m_size;
Detail::UniqueHandle m_handle;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_CUSTOMDATA_HPP

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,251 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_DEVICEEVENT_HPP
#define TWPP_DETAIL_FILE_DEVICEEVENT_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Information about event sent by source.
class DeviceEvent {
public:
/// Event type.
enum class Type : UInt16 { // Capability->UInt16, DeviceEvent->UInt32
CheckAutomaticCapture = 0,
CheckBattery = 1,
CheckDeviceOnline = 2,
CheckFlash = 3,
CheckPowerSupply = 4,
CheckResolution = 5,
DeviceAdded = 6,
DeviceOffline = 7,
DeviceReady = 8,
DeviceRemoved = 9,
ImageCaptured = 10,
ImageDeleted = 11,
PaperDoubleFeed = 12,
PaperJam = 13,
LampFailure = 14,
PowerSave = 15,
PowerSaveNotify = 16,
CustomEvents = 0x8000
};
/// Creates event with only type and device name set.
static constexpr DeviceEvent simple(Type type, const Str255& deviceName) noexcept;
/// Creates event for checking battery.
static constexpr DeviceEvent checkBattery(
const Str255& deviceName,
UInt32 batteryMinutes,
Int16 batteryPercentage
) noexcept;
/// Creates event for checking power supply.
static constexpr DeviceEvent checkPowerSupply(
const Str255& deviceName,
PowerSupply powerSupply
) noexcept;
/// Creates event for checking resolution.
static constexpr DeviceEvent checkResolution(
const Str255& deviceName,
Fix32 xres,
Fix32 yres
) noexcept;
/// Creates event for checking flash settings.
static constexpr DeviceEvent checkFlash(
const Str255& deviceName,
Flash flash
) noexcept;
/// Creates event for checking number of images camera is going to capture.
static constexpr DeviceEvent checkAutomaticCapture(
const Str255& deviceName,
UInt32 autoCapture,
UInt32 timeBeforeFirstCapture,
UInt32 timeBetweenCaptures
) noexcept;
/// Creates uninitialized deice event.
constexpr DeviceEvent() noexcept :
m_type(static_cast<UInt32>(Type::CheckAutomaticCapture)), m_batteryMinutes(0),
m_batteryPercent(0), m_powerSupply(static_cast<Int32>(PowerSupply::External)),
m_flashUsed(static_cast<UInt32>(Flash::None)), m_autoCapture(0),
m_timeBeforeFirstCapture(0), m_timeBetweenCaptures(0){}
/// Event type.
constexpr Type type() const noexcept{
return static_cast<Type>(m_type);
}
/// Name of the device that sent the event.
constexpr const Str255& deviceName() const noexcept{
return m_deviceName;
}
/// Minutes of battery power remaining.
/// Valid only for Type::CheckBattery.
constexpr UInt32 batteryMinutes() const noexcept{
return m_batteryMinutes;
}
/// Percentage of battery power remaining.
/// Valid only for Type::CheckBattery.
constexpr Int16 batteryPercentage() const noexcept{
return m_batteryPercent;
}
/// Power supply in use.
/// Valid only for Type::CheckPowerSupply.
constexpr PowerSupply powerSupply() const noexcept{
return static_cast<PowerSupply>(m_powerSupply);
}
/// X resolution.
/// Valif only for Type::CheckResolution.
constexpr Fix32 xResolution() const noexcept{
return m_xres;
}
/// Y resolution.
/// Valid only for Type::CheckResolution.
constexpr Fix32 yResolution() const noexcept{
return m_yres;
}
/// Flash settings.
/// Valid only for Type::CheckFlash.
constexpr Flash flash() const noexcept{
return static_cast<Flash>(m_flashUsed);
}
/// Number of images camera will capture.
/// Valid only for Type::CheckAutomaticCapture.
constexpr UInt32 automaticCapture() const noexcept{
return m_autoCapture;
}
/// Number of seconds before first capture.
/// Valid only for Type::CheckAutomaticCapture.
constexpr UInt32 timeBeforeFirstCapture() const noexcept{
return m_timeBeforeFirstCapture;
}
/// Number of 1/100-seconds between captures.
/// Valid only for Type::CheckAutomaticCapture.
constexpr UInt32 timeBetweenCaptures() const noexcept{
return m_timeBetweenCaptures;
}
private:
constexpr DeviceEvent(
Type type,
const Str255& deviceName,
UInt32 batteryMinutes,
Int16 batteryPercentage,
PowerSupply powerSupply,
Fix32 xres,
Fix32 yres,
Flash flash,
UInt32 autoCapture,
UInt32 tbfc,
UInt32 tbc
) noexcept :
m_type(static_cast<UInt32>(type)), m_deviceName(deviceName),
m_batteryMinutes(batteryMinutes), m_batteryPercent(batteryPercentage),
m_powerSupply(static_cast<Int32>(powerSupply)), m_xres(xres), m_yres(yres),
m_flashUsed(static_cast<UInt32>(flash)), m_autoCapture(autoCapture),
m_timeBeforeFirstCapture(tbfc), m_timeBetweenCaptures(tbc){}
UInt32 m_type;
Str255 m_deviceName;
UInt32 m_batteryMinutes;
Int16 m_batteryPercent;
Int32 m_powerSupply;
Fix32 m_xres;
Fix32 m_yres;
UInt32 m_flashUsed;
UInt32 m_autoCapture;
UInt32 m_timeBeforeFirstCapture;
UInt32 m_timeBetweenCaptures;
};
TWPP_DETAIL_PACK_END
// must be defined outside the class because of msvc2015
constexpr inline DeviceEvent DeviceEvent::simple(Type type, const Str255& deviceName) noexcept{
return DeviceEvent(type, deviceName, 0, 0, PowerSupply::External, Fix32(), Fix32(), Flash::None, 0, 0, 0);
}
constexpr inline DeviceEvent DeviceEvent::checkBattery(
const Str255& deviceName,
UInt32 batteryMinutes,
Int16 batteryPercentage
) noexcept{
return DeviceEvent(Type::CheckBattery, deviceName, batteryMinutes, batteryPercentage, PowerSupply::External, Fix32(), Fix32(), Flash::None, 0, 0, 0);
}
constexpr inline DeviceEvent DeviceEvent::checkPowerSupply(
const Str255& deviceName,
PowerSupply powerSupply
) noexcept{
return DeviceEvent(Type::CheckPowerSupply, deviceName, 0, 0, powerSupply, Fix32(), Fix32(), Flash::None, 0, 0, 0);
}
constexpr inline DeviceEvent DeviceEvent::checkResolution(
const Str255& deviceName,
Fix32 xres,
Fix32 yres
) noexcept{
return DeviceEvent(Type::CheckResolution, deviceName, 0, 0, PowerSupply::External, xres, yres, Flash::None, 0, 0, 0);
}
constexpr inline DeviceEvent DeviceEvent::checkFlash(
const Str255& deviceName,
Flash flash
) noexcept{
return DeviceEvent(Type::CheckFlash, deviceName, 0, 0, PowerSupply::External, Fix32(), Fix32(), flash, 0, 0, 0);
}
constexpr inline DeviceEvent DeviceEvent::checkAutomaticCapture(
const Str255& deviceName,
UInt32 autoCapture,
UInt32 timeBeforeFirstCapture,
UInt32 timeBetweenCaptures
) noexcept{
return DeviceEvent(Type::CheckAutomaticCapture, deviceName, 0, 0, PowerSupply::External,
Fix32(), Fix32(), Flash::None, autoCapture, timeBeforeFirstCapture, timeBetweenCaptures);
}
}
#endif // TWPP_DETAIL_FILE_DEVICEEVENT_HPP

View File

@ -0,0 +1,118 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_ELEMENT8_HPP
#define TWPP_DETAIL_FILE_ELEMENT8_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Element in a palette consisting of 3 parts (RGB, CMY, ...)
/// in the order of the type alphabetic representation.
class Element8 {
public:
/// Creates zero-initialized element.
constexpr Element8() noexcept :
m_index(0), m_channel1(0), m_channel2(0), m_channel3(0){}
/// Creates zero-initialized element with specified index.
explicit constexpr Element8(UInt8 index) noexcept :
m_index(index), m_channel1(0), m_channel2(0), m_channel3(0){}
/// Creates element with set channels.
constexpr Element8(
UInt8 channel1,
UInt8 channel2,
UInt8 channel3
) noexcept :
m_index(0), m_channel1(channel1), m_channel2(channel2),
m_channel3(channel3){}
/// Creates element with set channels at index.
constexpr Element8(
UInt8 index,
UInt8 channel1,
UInt8 channel2,
UInt8 channel3
) noexcept :
m_index(index), m_channel1(channel1), m_channel2(channel2),
m_channel3(channel3){}
/// Index of the element in palette.
constexpr UInt8 index() const noexcept{
return m_index;
}
/// Sets index of the element in palette.
void setIndex(UInt8 index) noexcept{
m_index = index;
}
/// Channel 1 information.
constexpr UInt8 channel1() const noexcept{
return m_channel1;
}
/// Sets channel 1 information.
void setChannel1(UInt8 channel1) noexcept{
m_channel1 = channel1;
}
/// Channel 2 information.
constexpr UInt8 channel2() const noexcept{
return m_channel2;
}
/// Sets channel 2 information.
void setChannel2(UInt8 channel2) noexcept{
m_channel2 = channel2;
}
/// Channel 3 information.
constexpr UInt8 channel3() const noexcept{
return m_channel3;
}
/// Sets channel 3 information.
void setChannel3(UInt8 channel3) noexcept{
m_channel3 = channel3;
}
private:
UInt8 m_index;
UInt8 m_channel1;
UInt8 m_channel2;
UInt8 m_channel3;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_ELEMENT8_HPP

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,356 @@
/*
The MIT License (MIT)
Copyright (c) 2015-2017 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_ENV_HPP
#define TWPP_DETAIL_FILE_ENV_HPP
// =============
// Twpp specific
namespace Twpp {
namespace Detail {
enum {
ProtoMajor = 2,
ProtoMinor = 3,
Dsm2 = 0x10000000L,
App2 = 0x20000000L,
Ds2 = 0x40000000L
};
}
}
#if defined(TWPP_IS_DS)
# define TWPP_DETAIL_IS_DS 1
#else
# define TWPP_DETAIL_IS_DS 0
#endif
// ===========
// OS specific
// Windows
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
# define TWPP_DETAIL_OS_WIN 1
# if defined(WIN64) || defined(_WIN64)
# define TWPP_DETAIL_OS_WIN64 1
# else
# define TWPP_DETAIL_OS_WIN32 1
# endif
# if !defined(WIN32_LEAN_AND_MEAN)
# define WIN32_LEAN_AND_MEAN
# endif
# if !defined(NOMINMAX)
# define NOMINMAX
# endif
extern "C" {
# include <windows.h>
}
# define TWPP_DETAIL_CALLSTYLE PASCAL
# define TWPP_DETAIL_EXPORT __declspec(dllexport)
namespace Twpp {
namespace Detail {
typedef HANDLE RawHandle;
namespace DsmLibOs {
typedef HMODULE Handle;
static constexpr const Handle nullHandle = nullptr;
template<typename T>
static inline T resolve(Handle h) noexcept{
return reinterpret_cast<T>(::GetProcAddress(h, "DSM_Entry"));
}
# if defined(TWPP_DETAIL_OS_WIN32)
static inline Handle load(bool old) noexcept{
if (old){
auto h = ::LoadLibraryA("TWAIN_32.dll");
if (!h){
h = ::LoadLibraryA("TWAINDSM.dll");
}
return h;
} else {
auto h = ::LoadLibraryA("TWAINDSM.dll");
if (!h){
h = ::LoadLibraryA("TWAIN_32.dll");
}
return h;
}
}
# else
static inline Handle load(bool) noexcept{
return ::LoadLibraryA("TWAINDSM.dll");
}
# endif
static inline void unload(Handle h) noexcept{
::FreeLibrary(h);
}
} // namespace DsmLibOs
} // namespace Detail
} // namespace Twpp
// Mac OS
#elif defined(__APPLE__)
# pragma message "No testing has been done on this platform, this framework might not work correctly."
# define TWPP_DETAIL_OS_MAC 1
# include <limits>
extern "C" {
# include <objc/objc.h>
# include <objc/objc-runtime.h>
# include <objc/NSObjCRuntime.h>
# include <CoreServices/CoreServices.h>
# include <dlfcn.h>
}
# define TWPP_DETAIL_CALLSTYLE pascal
namespace Twpp {
namespace Detail {
typedef Handle RawHandle;
namespace DsmLibOs {
typedef void* Handle;
static constexpr const Handle nullHandle = nullptr;
template<typename T>
static inline T resolve(Handle h) noexcept{
return reinterpret_cast<T>(::dlsym(h, "DSM_Entry"));
}
static inline Handle load(bool) noexcept{
return ::dlopen("/System/Library/Frameworks/TWAIN.framework/TWAIN", RTLD_LAZY);
}
static inline void unload(Handle h) noexcept{
::dlclose(h);
}
} // namespace DsmLibOs
template<typename>
struct MacStatic {
static const ::Class g_autoreleasePool;
static const ::SEL g_release;
static const ::SEL g_alloc;
static const ::SEL g_init;
static const ::SEL g_nextEvent;
static const ::SEL g_postEvent;
static const ::SEL g_sendEvent;
static const ::id g_app;
static const ::id g_distantFuture;
static const ::Class g_event;
static const ::SEL g_otherEventWithType;
};
template<typename Dummy> const ::Class MacStatic<Dummy>::g_autoreleasePool = objc_getClass("NSAutoreleasePool");
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_release = sel_registerName("release");
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_alloc = sel_registerName("alloc");
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_init = sel_registerName("init");
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_nextEvent = sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:");
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_postEvent = sel_registerName("postEvent:atStart:");
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_sendEvent = sel_registerName("sendEvent:");
template<typename Dummy> const ::id MacStatic<Dummy>::g_app = objc_msgSend(reinterpret_cast<::id>(objc_getClass("NSApplication")), sel_registerName("sharedApplication"));
template<typename Dummy> const ::id MacStatic<Dummy>::g_distantFuture = objc_msgSend(reinterpret_cast<::id>(objc_getClass("NSDate")), sel_registerName("distantFuture"));
template<typename Dummy> const ::Class MacStatic<Dummy>::g_event = objc_getClass("NSEvent");
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_otherEventWithType = sel_registerName("otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:");
class NSAutoreleasePool {
public:
NSAutoreleasePool() noexcept :
m_id(createPool()) {}
~NSAutoreleasePool(){
release();
}
NSAutoreleasePool(const NSAutoreleasePool&) = delete;
NSAutoreleasePool& operator=(const NSAutoreleasePool&) = delete;
NSAutoreleasePool(NSAutoreleasePool&& o) noexcept :
m_id(o.m_id){
o.m_id = nullptr;
}
NSAutoreleasePool& operator=(NSAutoreleasePool&& o) noexcept{
if (this != &o){
release();
std::swap(m_id, o.m_id);
}
return *this;
}
void release() noexcept{
if (m_id != nullptr){
objc_msgSend(m_id, MacStatic<void>::g_release);
m_id = nullptr;
}
}
private:
static ::id createPool() noexcept{
auto poolId = objc_msgSend(reinterpret_cast<::id>(MacStatic<void>::g_autoreleasePool), MacStatic<void>::g_alloc);
return objc_msgSend(poolId, MacStatic<void>::g_init);
}
::id m_id;
};
namespace NSLoop {
static constexpr ::NSUInteger NSAnyEventMask = std::numeric_limits<::NSUInteger>::max();
static constexpr ::NSUInteger NSApplicationDefined = 15;
static void processEvent() noexcept{
auto event = objc_msgSend(MacStatic<void>::g_app, MacStatic<void>::g_nextEvent, NSAnyEventMask, MacStatic<void>::g_distantFuture, kCFRunLoopDefaultMode, YES);
objc_msgSend(MacStatic<void>::g_app, MacStatic<void>::g_sendEvent, event);
}
static void postDummy() noexcept{
auto event = objc_msgSend(reinterpret_cast<::id>(MacStatic<void>::g_event), MacStatic<void>::g_otherEventWithType, NSApplicationDefined, nullptr, 1, 0.0, 0, nullptr, static_cast<short>(0), 0, 0);
objc_msgSend(MacStatic<void>::g_app, MacStatic<void>::g_postEvent, event, NO);
}
} // namespace NSLoop
} // namespace Detail
} // namespace Twpp
// Linux
#elif defined(__linux__)
# warning "No testing has been done on this platform, this framework might not work correctly."
# define TWPP_DETAIL_OS_LINUX 1
extern "C" {
# include <dlfcn.h>
}
# define TWPP_DETAIL_CALLSTYLE
namespace Twpp {
namespace Detail {
typedef void* RawHandle;
namespace DsmLibOs {
typedef void* Handle;
static constexpr const Handle nullHandle = nullptr;
template<typename T>
static inline T resolve(Handle h) noexcept{
return reinterpret_cast<T>(::dlsym(h, "DSM_Entry"));
}
static inline Handle load(bool) noexcept{
return ::dlopen("libtwaindsm.so", RTLD_LAZY);
}
static inline void unload(Handle h) noexcept{
::dlclose(h);
}
} // namespace DsmLibOs
} // namespace Detail
} // namespace Twpp
// fail everything else
#else
# error "unsupported platform, supports only Windows, Mac OS and Linux"
#endif
// =================
// compiler specific
// MSVC
#if defined(_MSC_VER)
# define TWPP_DETAIL_PACK_BEGIN \
__pragma(pack (push, beforeTwpp)) \
__pragma(pack (2))
# define TWPP_DETAIL_PACK_END __pragma(pack (pop, beforeTwpp));
// GNU or CLang
#elif defined(__GNUC__) || defined(__clang__)
# if defined(TWPP_DETAIL_OS_MAC)
# define TWPP_DETAIL_PACK_BEGIN _Pragma("options align = power")
# define TWPP_DETAIL_PACK_END _Pragma("options align = reset")
# else
# define TWPP_DETAIL_PACK_BEGIN \
_Pragma("pack (push, beforeTwpp)") \
_Pragma("pack (2)")
# define TWPP_DETAIL_PACK_END _Pragma("pack (pop, beforeTwpp)")
# endif
# if !defined(TWPP_DETAIL_EXPORT)
# define TWPP_DETAIL_EXPORT __attribute__((__visibility__("default")))
# endif
// Borland
#elif defined(__BORLAND__) || defined(__BORLANDC__) || defined(__CODEGEARC__)
# define TWPP_DETAIL_PACK_BEGIN _Pragma("option -a2")
# define TWPP_DETAIL_PACK_END _Pragma("option -a")
// fail everything else
#else
# error "unsupported compiler, please define your own TWPP_DETAIL_PACK_BEGIN and TWPP_DETAIL_PACK_END and possibly TWPP_DETAIL_EXPORT in twpp/env.hpp and send me your patch"
#endif
#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1900) // msvc2015
# error "C++11 or later is required"
#endif
#endif // TWPP_DETAIL_FILE_ENV_HPP

View File

@ -0,0 +1,72 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_EVENT_HPP
#define TWPP_DETAIL_FILE_EVENT_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Loop event on Windows.
/// Used while waiting for transfer.
/// See manual for more info.
class Event {
public:
constexpr Event() noexcept :
m_event(nullptr), m_msg(Msg::Null){}
constexpr Event(void* event, Msg msg) noexcept :
m_event(event), m_msg(msg){}
constexpr void* event() const noexcept{
return m_event;
}
void setEvent(void* event) noexcept{
m_event = event;
}
constexpr Msg message() const noexcept{
return m_msg;
}
void setMessage(Msg msg) noexcept{
m_msg = msg;
}
private:
void* m_event;
Msg m_msg;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_EVENT_HPP

View File

@ -0,0 +1,42 @@
#ifndef TWPP_DETAIL_FILE_EXCEPTION_HPP
#define TWPP_DETAIL_FILE_EXCEPTION_HPP
#include "../twpp.hpp"
namespace Twpp {
/// Base class of TWPP exceptions.
class Exception : public std::exception {
public:
virtual const char* what() const noexcept override{
return "General TWPP error.";
}
};
/// Invalid type exception.
/// Used when an invalid or unsupported type identifier is used.
class TypeException : public Exception {
public:
virtual const char* what() const noexcept override{
return "Invalid type.";
}
};
/// Value out of valid range exception.
class RangeException : Exception {
public:
virtual const char* what() const noexcept override{
return "Value out of allowed range.";
}
};
}
#endif // TWPP_DETAIL_FILE_EXCEPTION_HPP

View File

@ -0,0 +1,532 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP
#define TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
/// Mapping of info type to type identifier and data type.
template<InfoId id> struct Ext {};
template<> struct Ext<InfoId::BarCodeCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::BarCodeConfidence> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::BarCodeRotation> {static constexpr const Type twty = Type::UInt32; typedef BarCodeRotation DataType;};
template<> struct Ext<InfoId::BarCodeTextLength> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::BarCodeText> {static constexpr const Type twty = Type::Handle; typedef char DataType;};
template<> struct Ext<InfoId::BarCodeX> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::BarCodeY> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::BarCodeType> {static constexpr const Type twty = Type::UInt32; typedef BarCodeType DataType;};
template<> struct Ext<InfoId::DeShadeCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeTop> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeLeft> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeHeight> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeWidth> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeSize> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeBlackCountOld> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeBlackCountNew> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeBlackRlMin> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeBlackRlMax> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeWhiteCountOld> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeWhiteCountNew> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeWhiteRlMin> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadeWhiteRlMax> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DeShadEWhiteRlAve> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SpecklesRemoved> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::BlackSpecklesRemoved> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::WhiteSpecklesRemoved> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::HorzLineCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::HorzLineXCoord> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::HorzLineYCoord> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::HorzLineLength> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::HorzLineThickness> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::VertLineCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::VertLineXCoord> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::VertLineYCoord> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::VertLineLength> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::VertLineThickness> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::PatchCode> {static constexpr const Type twty = Type::UInt32; typedef PatchCode DataType;};
template<> struct Ext<InfoId::DeskewStatus> {static constexpr const Type twty = Type::UInt32; typedef DeskewStatus DataType;};
template<> struct Ext<InfoId::SkewOriginalAngle> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewFinalAngle> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewConfidence> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewWindowX1> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewWindowY1> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewWindowX2> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewWindowY2> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewWindowX3> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewWindowY3> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewWindowX4> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::SkewWindowY4> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::EndorsedText> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
template<> struct Ext<InfoId::FormConfidence> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::FormTemplateMatch> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
template<> struct Ext<InfoId::FormTemplatePageMatch> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::FormHorzDocOffset> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::FormVertDocOffset> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::BookName> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
template<> struct Ext<InfoId::ChapterNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::DocumentNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::PageNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::Camera> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
template<> struct Ext<InfoId::FrameNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::Frame> {static constexpr const Type twty = Type::Frame; typedef Frame DataType;};
template<> struct Ext<InfoId::PixelFlavor> {static constexpr const Type twty = Type::UInt16; typedef PixelFlavor DataType;};
template<> struct Ext<InfoId::IccProfile> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
template<> struct Ext<InfoId::LastSegment> {static constexpr const Type twty = Type::Bool; typedef Bool DataType;};
template<> struct Ext<InfoId::SegmentNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::MagType> {static constexpr const Type twty = Type::UInt16; typedef MagType DataType;};
template<> struct Ext<InfoId::FileSystemSource> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
template<> struct Ext<InfoId::ImageMerged> {static constexpr const Type twty = Type::Bool; typedef Bool DataType;};
template<> struct Ext<InfoId::MagData> {static constexpr const Type twty = Type::Str255; typedef char DataType;}; // NOTE: InfoId::MagData may also contain Handle
template<> struct Ext<InfoId::MagDataLength> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::PageSide> {static constexpr const Type twty = Type::UInt16; typedef PageSide DataType;};
template<> struct Ext<InfoId::PaperCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
template<> struct Ext<InfoId::PrinterText> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
}
class Info;
class ExtImageInfo;
namespace Detail {
static Handle handleItem(Info& info) noexcept;
static void deleteInfo(Info& info) noexcept;
}
TWPP_DETAIL_PACK_BEGIN
/// Extended image information entry.
class Info {
friend class ExtImageInfo;
friend Handle Detail::handleItem(Info& info) noexcept;
friend void Detail::deleteInfo(Info& info) noexcept;
static constexpr const UInt32 DATA_HANDLE_THRESHOLD = sizeof(UIntPtr); // NOTE: specification says 4 bytes, yet pointer size makes more sense
public:
template<typename DataType>
class Items {
friend class Info;
public:
typedef Detail::MaybeLock<DataType> Data;
constexpr Items() noexcept :
m_parent(nullptr){}
Items(const Items&) = default;
Items& operator=(const Items&) = default;
Items(Items&&) = default;
Items& operator=(Items&&) = default;
operator bool() const noexcept{
return m_data;
}
Data at(UInt32 i) const{
if (m_parent->hasDataHandle() && m_parent->type() == Type::Handle){
return reinterpret_cast<Handle*>(m_data.data())[i];
} else {
return reinterpret_cast<DataType*>(m_data.data() + i * typeSize(m_parent->type()));
}
}
Data operator[](UInt32 i) const{
return at(i);
}
private:
Items(Info& parent, Detail::MaybeLock<char> data) noexcept :
m_parent(&parent), m_data(data){}
Info* m_parent;
Detail::MaybeLock<char> m_data;
// [items] <=> !(big and handle)
// [handles]->handles*[items] <=> big and handle (this should teoretically not happen)
};
Info(const Info&) = delete;
Info& operator=(const Info&) = delete;
Info(Info&&) = delete;
Info& operator=(Info&&) = delete;
/// Information type ID.
InfoId id() const noexcept{
return m_infoId;
}
/// Information data type ID.
Type type() const noexcept{
return m_itemType;
}
/// Number of items in this entry.
UInt16 size() const noexcept{
return m_numItems;
}
/// Allocates space for the supplied number of items.
/// Allocating handles is not supported.
/// \tparam id Information type ID. Data types are set accordingly.
/// \param count Number of items to allocate.
/// \throw TypeException When `type` is handle or invalid.
/// \throw std::bad_alloc
template<InfoId id>
void allocSimple(UInt16 count = 1){
allocSimple(Detail::Ext<id>::twty, count);
}
/// Allocates space for the supplied number of items.
/// Allocating handles is not supported.
/// \param type Data type ID.
/// \param count Number of items to allocate.
/// \throw TypeException When `type` is handle or invalid.
/// \throw std::bad_alloc
void allocSimple(Type type, UInt16 count = 1){
if (type == Type::Handle){
throw TypeException();
}
if (type == m_itemType && count == m_numItems){
return;
}
auto itemSize = typeSize(type);
bool big = hasDataHandle(type, count);
// [items] <=> !big
// handle->[items] <=> big
Detail::UniqueHandle newItem;
if (big){
newItem = Detail::alloc(itemSize * count);
}
Detail::deleteInfo(*this);
if (big){
*Detail::alias_cast<Handle*>(&m_item) = newItem.release();
}
m_itemType = type;
m_numItems = count;
}
/// Allocates a single memory area owned by a handle.
/// Info type changes to handle.
/// \param itemSize Number of bytes to allocate.
/// \throw std::bad_alloc
void allocHandle(UInt32 itemSize){
// handle->[chars]
auto newItem = Detail::UniqueHandle(Detail::alloc(itemSize));
Detail::deleteInfo(*this);
*Detail::alias_cast<Handle*>(&m_item) = newItem.release();
m_itemType = Type::Handle;
m_numItems = 1;
}
/// Status of this entry.
ReturnCode returnCode() const noexcept{
return m_returnCode;
}
/// Sets status of this entry.
void setReturnCode(ReturnCode rc) noexcept{
m_returnCode = rc;
}
/// Returns items contained in this entry.
/// \tparam type ID of the internal data type.
/// \tparam DataType Exported data type.
/// \throw TypeException When types don't match.
template<Type type, typename DataType>
Items<DataType> items(){
if (type != m_itemType || (type != Type::Handle && typeSize(type) != sizeof(DataType))){
throw TypeException();
}
return itemsPriv<DataType>();
}
/// Returns items contained in this entry.
/// \tparam type ID of the internal data type.
/// \throw TypeException When types don't match.
template<Type type>
Items<typename Detail::Twty<type>::Type> items(){
if (type != m_itemType){
throw TypeException();
}
return itemsPriv<typename Detail::Twty<type>::Type>();
}
/// Returns items contained in this entry.
/// \tparam id Information type ID. Data types are set accordingly.
/// \throw TypeException When types don't match.
template<InfoId id>
Items<typename Detail::Ext<id>::DataType> items(){
if (Detail::Ext<id>::twty != m_itemType){
throw TypeException();
}
return itemsPriv<typename Detail::Ext<id>::DataType>();
}
private:
bool hasDataHandle() const{
return hasDataHandle(type(), size());
}
static bool hasDataHandle(Type type, UInt16 size){
return type != Type::DontCare && size * typeSize(type) > DATA_HANDLE_THRESHOLD;
}
template<typename DataType>
Items<DataType> itemsPriv(){
bool big = hasDataHandle();
bool handle = m_itemType == Type::Handle;
Detail::MaybeLock<char> lock;
if (!big && !handle){
lock = Detail::alias_cast<char*>(&m_item);
} else {
lock = *Detail::alias_cast<Handle*>(&m_item);
}
return {*this, std::move(lock)};
}
template<typename T, std::size_t len>
static bool arrContains(const T(& arr)[len], const T& val) noexcept{
for (std::size_t i = 0; i < len; i++){
if (arr[i] == val){
return true;
}
}
return false;
}
InfoId m_infoId;
Type m_itemType;
UInt16 m_numItems;
ReturnCode m_returnCode;
UIntPtr m_item;
// [items] <=> !big and !handle
// handle->[items] <=> big xor handle
// handle->[handles]->handles*[items] <=> big and handle (this should teoretically not happen)
};
namespace Detail {
static inline Handle handleItem(Info& info) noexcept{
return Handle(*Detail::alias_cast<Handle::Raw*>(&info.m_item));
}
static inline void deleteInfo(Info& info) noexcept{
bool big = isType(info.type()) && info.hasDataHandle();
bool handle = info.type() == Type::Handle;
// [items] <=> !big and !handle
// handle->[items] <=> big xor handle
// handle->[handles]->handles*[items] <=> big and handle (this should teoretically not happen)
if (big && handle){
Detail::Lock<Handle> lock(handleItem(info));
for (UInt16 i = 0; i < info.size(); i++){
Detail::free(lock.data()[i]);
}
}
if (big || handle){
Detail::free(handleItem(info));
}
}
struct ExtImageInfoData {
UInt32 m_numInfos;
Info m_infos[1];
};
}
TWPP_DETAIL_PACK_END
/// Extended image information.
/// Application sends list of info IDs,
/// source sets their data.
class ExtImageInfo {
public:
typedef Info* iterator;
typedef const Info* const_iterator;
/// Creates an invalid object.
ExtImageInfo() noexcept {}
/// Creates a new structure for all supplied info IDs.
/// Sources must not call this constructor, they
/// are required to fill data in existing instance.
/// \param ids List of requested info IDs to be filled in by the source.
ExtImageInfo(std::initializer_list<InfoId> ids) :
m_data(new char[sizeof(Detail::ExtImageInfoData) - sizeof(Info) + ids.size() * sizeof(Info)]()){
d()->m_numInfos = static_cast<UInt32>(ids.size());
Info* infos = d()->m_infos;
UInt32 i = 0;
for (auto id : ids){
auto& info = infos[i];
i++;
info.m_infoId = id;
info.m_itemType = Type::DontCare;
}
}
ExtImageInfo(ExtImageInfo&&) = default;
ExtImageInfo& operator=(ExtImageInfo&&) = default;
operator bool() const noexcept{
return isValid();
}
bool isValid() const noexcept{
return static_cast<bool>(m_data);
}
/// Number of requested entries.
UInt32 size() const noexcept{
assert(isValid());
return d()->m_numInfos;
}
/// Information entry.
Info& at(UInt32 i) noexcept{
assert(isValid());
return d()->m_infos[i];
}
/// Information entry.
const Info& at(UInt32 i) const noexcept{
assert(isValid());
return d()->m_infos[i];
}
Info& operator[](UInt32 i) noexcept{
return at(i);
}
const Info& operator[](UInt32 i) const noexcept{
return at(i);
}
iterator begin() noexcept{
assert(isValid());
return d()->m_infos;
}
const_iterator begin() const noexcept{
return cbegin();
}
const_iterator cbegin() const noexcept{
assert(isValid());
return d()->m_infos;
}
iterator end() noexcept{
assert(isValid());
return d()->m_infos + d()->m_numInfos;
}
const_iterator end() const noexcept{
return cend();
}
const_iterator cend() const noexcept{
assert(isValid());
return d()->m_infos + d()->m_numInfos;
}
private:
Detail::ExtImageInfoData* d() noexcept{
return reinterpret_cast<Detail::ExtImageInfoData*>(m_data.get());
}
Detail::ExtImageInfoData* d() const noexcept{
return reinterpret_cast<Detail::ExtImageInfoData*>(m_data.get());
}
struct Deleter {
void operator()(char* ptr) noexcept{
Detail::ExtImageInfoData* data = reinterpret_cast<Detail::ExtImageInfoData*>(ptr);
if (data){
for (UInt32 i = 0; i < data->m_numInfos; i++){
Detail::deleteInfo(data->m_infos[i]);
}
delete [] ptr;
}
}
};
std::unique_ptr<char[], Deleter> m_data;
};
}
#endif // TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP

View File

@ -0,0 +1,248 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_FILESYSTEM_HPP
#define TWPP_DETAIL_FILE_FILESYSTEM_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Structure representing device filesystem and operations on it.
class FileSystem {
public:
/// Type of file.
enum class Type : Int32 {
Camera = 0,
CameraTop = 1,
CameraBottom = 2,
CameraPreview = 3,
Domain = 4,
Host = 5,
Directory = 6,
Image = 7,
Unknown = 8
};
/// Creates uninitialized file system.
constexpr FileSystem() noexcept :
m_context(nullptr), m_recursiveBool(), m_fileType(Type::Camera), m_size(),
m_freeSpace(), m_newImageSize(), m_numberOfFiles(), m_numberOfSnippets(),
m_deviceGroupMask(), m_reserved(){}
/// Creates file system with input and output paths and optional context.
constexpr FileSystem(const Str255& inputPath, const Str255& outputPath, void* context = nullptr) noexcept :
m_inputPath(inputPath), m_outputPath(outputPath), m_context(context),
m_recursiveBool(), m_fileType(Type::Camera), m_size(), m_freeSpace(), m_newImageSize(),
m_numberOfFiles(), m_numberOfSnippets(), m_deviceGroupMask(), m_reserved(){}
/// Input or source file.
constexpr const Str255& inputPath() const noexcept{
return m_inputPath;
}
/// Sets input or source file.
void setInputPath(const Str255& path) noexcept{
m_inputPath = path;
}
/// Operation result, or destination file.
constexpr const Str255& outputPath() const noexcept{
return m_outputPath;
}
/// Sets operation result, or destination file.
void setOutputPath(const Str255& path) noexcept{
m_outputPath = path;
}
/// Source specific context.
constexpr void* context() const noexcept{
return m_context;
}
/// Sets source specific context.
void setContext(void* context) noexcept{
m_context = context;
}
/// Whether the operation is recursive.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::Delete.
constexpr Bool recursive() const noexcept{
return m_recursiveBool;
}
/// Sets whether the operation is recursive.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::Delete.
void setRecursive(Bool recursive) noexcept{
m_recursiveBool = recursive;
}
/// File type.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
constexpr Type type() const noexcept{
return m_fileType;
}
/// Sets file type.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
void setType(Type type) noexcept{
m_fileType = type;
}
/// Number of bytes of the entry.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
constexpr UInt32 size() const noexcept{
return m_size;
}
/// Sets number of bytes of the entry.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
void setSize(UInt32 size) noexcept{
m_size = size;
}
/// Creation date of the file.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
/// YYYY/MM/DD HH:mm:SS:sss
constexpr const Str32& createdTimeDate() const noexcept{
return m_createdTimeDate;
}
/// Sets creation date of the file.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
/// YYYY/MM/DD HH:mm:SS:sss
void setCreatedTimeDate(const Str32& val) noexcept{
m_createdTimeDate = val;
}
/// Modification date of the file.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
/// YYYY/MM/DD HH:mm:SS:sss
constexpr const Str32& modifiedTimeDate() const noexcept{
return m_modifiedTimeDate;
}
/// Sets modification date of the file.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
/// YYYY/MM/DD HH:mm:SS:sss
void setModifiedTimeDate(const Str32& val) noexcept{
m_modifiedTimeDate = val;
}
/// Number of bytes left on the device.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
constexpr UInt32 freeSpace() const noexcept{
return m_freeSpace;
}
/// Sets number of bytes left on the device.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
void setFreeSpace(UInt32 freeSpace) noexcept{
m_freeSpace = freeSpace;
}
/// Estimated image size in bytes.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
constexpr Int32 newImageSize() const noexcept{
return m_newImageSize;
}
/// Sets estimated image size in bytes.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
void setNewImageSize(Int32 newImageSize) noexcept{
m_newImageSize = newImageSize;
}
/// Total number of files including subdirectories.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
constexpr UInt32 files() const noexcept{
return m_numberOfFiles;
}
/// Sets total number of files including subdirectories.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
void setFiles(UInt32 files) noexcept{
m_numberOfFiles = files;
}
/// Number of audio snippets.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
constexpr UInt32 snippets() const noexcept{
return m_numberOfSnippets;
}
/// Sets number of audio snippets.
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
void snippets(UInt32 snippets) noexcept{
m_numberOfSnippets = snippets;
}
/// See manual for explanation of this field, `DeviceGroupMask`.
constexpr UInt32 groupMask() const noexcept{
return m_deviceGroupMask;
}
/// See manual for explanation of this field, `DeviceGroupMask`.
void groupMask(UInt32 groupMask) noexcept{
m_deviceGroupMask = groupMask;
}
private:
void unused() const{
Detail::unused(m_reserved);
}
Str255 m_inputPath;
Str255 m_outputPath;
void* m_context;
// Copy, Delete
union {
int m_recursive;
Bool m_recursiveBool;
};
// GetInfo
Type m_fileType;
UInt32 m_size;
Str32 m_createdTimeDate;
Str32 m_modifiedTimeDate;
UInt32 m_freeSpace;
Int32 m_newImageSize;
UInt32 m_numberOfFiles;
UInt32 m_numberOfSnippets;
UInt32 m_deviceGroupMask;
Int8 m_reserved[508];
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_FILESYSTEM_HPP

View File

@ -0,0 +1,198 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_FIX32_HPP
#define TWPP_DETAIL_FILE_FIX32_HPP
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
static constexpr inline Int32 floatToValue(float val){
return static_cast<Int32>(
(val >= 0.0f) ?
(val * 65536.0f + 0.5f) :
(val * 65536.0f - 0.5f)
);
}
static constexpr inline Int16 floatToWhole(float val){
return static_cast<Int16>(floatToValue(val) >> 16);
}
static constexpr inline UInt16 floatToFrac(float val){
return static_cast<UInt16>(floatToValue(val) & 0xFFFF);
}
}
TWPP_DETAIL_PACK_BEGIN
/// TWAIN fixed point fractional type.
/// The fractional part has resolution of 1/65536.
class Fix32 {
public:
/// Creates zero-initialized fixed type.
constexpr Fix32() noexcept :
m_whole(0), m_frac(0){}
/// Creates fixed type from float at compile time if possible.
constexpr Fix32(float value) noexcept :
m_whole(Detail::floatToWhole(value)), m_frac(Detail::floatToFrac(value)){}
/// Creates fixed type from whole and fractional parts.
/// The fractional part has resolution of 1/65536.
constexpr Fix32(Int16 whole, UInt16 frac) noexcept :
m_whole(whole), m_frac(frac){}
/// Whole part of this fixed type.
constexpr Int16 whole() const noexcept{
return m_whole;
}
/// Sets whole part of this fixed type.
void setWhole(Int16 whole) noexcept{
m_whole = whole;
}
/// Fractional part of this fixed type.
/// Resolution of 1/65536.
constexpr UInt16 frac() const noexcept{
return m_frac;
}
/// Sets fractional part of this fixed type.
/// Resolution of 1/65536.
void setFrac(UInt16 frac) noexcept{
m_frac = frac;
}
explicit constexpr operator float() const noexcept{
return m_whole + m_frac / 65536.0f;
}
constexpr float toFloat() const noexcept{
return m_whole + m_frac / 65536.0f;
}
constexpr Fix32 operator-() const noexcept{
return -toFloat();
}
private:
Int16 m_whole;
UInt16 m_frac;
};
TWPP_DETAIL_PACK_END
namespace Detail {
static inline constexpr Fix32 fix32AddHelper(Int32 frac, Int16 whole){
return frac < 65536 ? Fix32(whole, frac) : Fix32(whole + 1, frac - 65536);
}
static inline constexpr Fix32 fix32SubHelper(Int32 frac, Int16 whole){
return frac >= 0 ? Fix32(whole, frac) : Fix32(whole - 1, frac + 65536);
}
}
static inline constexpr bool operator>(Fix32 a, Fix32 b) noexcept{
return a.whole() > b.whole() || (a.whole() == b.whole() && a.frac() > b.frac());
}
static inline constexpr bool operator<(Fix32 a, Fix32 b) noexcept{
return a.whole() < b.whole() || (a.whole() == b.whole() && a.frac() < b.frac());
}
static inline constexpr bool operator>=(Fix32 a, Fix32 b) noexcept{
return !(a < b);
}
static inline constexpr bool operator<=(Fix32 a, Fix32 b) noexcept{
return !(a > b);
}
static inline constexpr bool operator==(Fix32 a, Fix32 b) noexcept{
return a.whole() == b.whole() && a.frac() == b.frac();
}
static inline constexpr bool operator!=(Fix32 a, Fix32 b) noexcept{
return !(a == b);
}
static inline constexpr Fix32 operator+(Fix32 a, Fix32 b) noexcept{
return Detail::fix32AddHelper(static_cast<Int32>(a.frac()) + b.frac(), a.whole() + b.whole());
}
static inline constexpr Fix32 operator-(Fix32 a, Fix32 b) noexcept{
return Detail::fix32SubHelper(static_cast<Int32>(a.frac()) - b.frac(), a.whole() - b.whole());
}
static inline constexpr Fix32 operator*(Fix32 a, Fix32 b) noexcept{
return Fix32(static_cast<float>(a) * static_cast<float>(b));
}
static inline constexpr Fix32 operator/(Fix32 a, Fix32 b) noexcept{ // wonder about zero b
return Fix32(static_cast<float>(a) / static_cast<float>(b));
}
static inline Fix32& operator+=(Fix32& a, Fix32 b) noexcept{
return a = a + b;
}
static inline Fix32& operator-=(Fix32& a, Fix32 b) noexcept{
return a = a - b;
}
static inline Fix32& operator*=(Fix32& a, Fix32 b) noexcept{
return a = a * b;
}
static inline Fix32& operator/=(Fix32& a, Fix32 b) noexcept{ // wonder about zero b
return a = a / b;
}
namespace Literals {
static inline constexpr Fix32 operator "" _fix(long double val) noexcept{
return Fix32(static_cast<float>(val));
}
static inline constexpr Fix32 operator "" _fix(unsigned long long val) noexcept{
return Fix32(static_cast<float>(val));
}
}
}
#endif // TWPP_DETAIL_FILE_FIX32_HPP

View File

@ -0,0 +1,106 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_FRAME_HPP
#define TWPP_DETAIL_FILE_FRAME_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Section of an image to retrieve.
class Frame {
public:
/// Creates zero-initialized frame.
constexpr Frame() noexcept{}
/// Creates frame with set top-left and bottom-right corners.
constexpr Frame(Fix32 left, Fix32 top, Fix32 right, Fix32 bottom) noexcept :
m_left(left), m_top(top), m_right(right), m_bottom(bottom){}
/// Left position of the image frame.
constexpr Fix32 left() const noexcept{
return m_left;
}
/// Sets left position of the image frame.
void setLeft(Fix32 left) noexcept{
m_left = left;
}
/// Top position of the image frame.
constexpr Fix32 top() const noexcept{
return m_top;
}
/// Sets top position of the image frame.
void setTop(Fix32 top) noexcept{
m_top = top;
}
/// Right position of the image frame.
constexpr Fix32 right() const noexcept{
return m_right;
}
/// Sets right position of the image frame.
void setRight(Fix32 right) noexcept{
m_right = right;
}
/// Bottom position of the image frame.
constexpr Fix32 bottom() const noexcept{
return m_bottom;
}
/// Sets bottom position of the image frame.
void setBottom(Fix32 bottom) noexcept{
m_bottom = bottom;
}
private:
Fix32 m_left;
Fix32 m_top;
Fix32 m_right;
Fix32 m_bottom;
};
TWPP_DETAIL_PACK_END
static constexpr inline bool operator==(const Frame& a, const Frame& b) noexcept{
return a.left() == b.left() && a.top() == b.top() && a.right() == b.right() && a.bottom() == b.bottom();
}
static constexpr inline bool operator!=(const Frame& a, const Frame& b) noexcept{
return !(a == b);
}
}
#endif // TWPP_DETAIL_FILE_FRAME_HPP

View File

@ -0,0 +1,247 @@
/*
The MIT License (MIT)
Copyright (c) 2015-2017 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_IDENTITY_HPP
#define TWPP_DETAIL_FILE_IDENTITY_HPP
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
static constexpr const UInt32 identV2 = TWPP_DETAIL_IS_DS ? Detail::Ds2 : Detail::App2;
}
TWPP_DETAIL_PACK_BEGIN
/// Source or application version information.
class Version {
public:
/// Creates default-initialized version.
constexpr Version() noexcept :
m_majorNum(0), m_minorNum(0), m_language(Language::English),
m_country(Country::UnitedKingdom){}
/// Creates version initialized with supplied values.
constexpr Version(
UInt16 majorNumber,
UInt16 minorNumber,
Language language,
Country country,
const Str32& info = Str32()) noexcept :
m_majorNum(majorNumber), m_minorNum(minorNumber), m_language(language),
m_country(country), m_info(info){}
/// Major version number of the source or application.
constexpr UInt16 majorNumber() const noexcept{
return m_majorNum;
}
/// Sets major version number of the source or application.
void setMajorNumber(UInt16 major) noexcept{
m_majorNum = major;
}
/// Minor version number of the source or application.
constexpr UInt16 minorNumber() const noexcept{
return m_minorNum;
}
/// Sets minor version number of the source or application.
void setMinorNumber(UInt16 minor) noexcept{
m_minorNum = minor;
}
/// Language of the source or application.
constexpr Language language() const noexcept{
return m_language;
}
/// Sets language of the source or application.
void setLanguage(Language language) noexcept{
m_language = language;
}
/// Original country of the source or application.
constexpr Country country() const noexcept{
return m_country;
}
/// Set original country of the source or application.
void setCountry(Country country) noexcept{
m_country = country;
}
/// Additional version information of the source or application.
constexpr const Str32& info() const noexcept{
return m_info;
}
/// Sets additional version information of the source or application.
void setInfo(const Str32& info) noexcept{
m_info = info;
}
private:
UInt16 m_majorNum;
UInt16 m_minorNum;
Language m_language;
Country m_country;
Str32 m_info;
};
/// Source or application identity.
/// Uniquely identifies an endpoint.
class Identity {
public:
typedef
#if defined(TWPP_DETAIL_OS_MAC)
void*
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
UInt32
#else
# error "Identity::Id for your platform here"
#endif
Id;
/// Creates default-initialized identity.
/// ID is set to zero.
/// TWAIN protocol is always Detail::ProtoMajor and Detail::ProtoMinor.
/// Supported group always contains DG::Control and V2.
constexpr Identity() noexcept :
m_id(), m_protoMaj(Detail::ProtoMajor), m_protoMin(Detail::ProtoMinor),
m_groups(DataGroup::Control | Detail::identV2){}
/// Creates identity initialized with supplied values.
/// ID is set to zero.
/// TWAIN protocol is always Detail::ProtoMajor and Detail::ProtoMinor.
/// Supported group always contains DG::Control and V2.
constexpr Identity(
const Version& version,
DataGroup group,
const Str32& manufacturer,
const Str32& productFamily,
const Str32& productName) noexcept :
m_id(), m_version(version), m_protoMaj(Detail::ProtoMajor),
m_protoMin(Detail::ProtoMinor), m_groups(DataGroup::Control | group | Detail::identV2),
m_manuf(manufacturer), m_prodFamily(productFamily), m_prodName(productName){}
/// Creates identity initialized with supplied values.
constexpr Identity(
Id id,
const Version& version,
UInt16 protoMajor,
UInt16 protoMinor,
UInt32 groups,
const Str32& manufacturer,
const Str32& productFamily,
const Str32& productName) noexcept :
m_id(id), m_version(version), m_protoMaj(protoMajor), m_protoMin(protoMinor),
m_groups(groups), m_manuf(manufacturer), m_prodFamily(productFamily),
m_prodName(productName){}
/// DSM-supplied ID of this identity.
constexpr Id id() const{
return m_id;
}
/// Version information.
constexpr const Version& version() const noexcept{
return m_version;
}
/// Whether a data group is supported.
constexpr bool supports(DataGroup group) const noexcept{
return (m_groups & group) != 0;
}
/// Whether this is V2 application.
constexpr bool isAppV2() const noexcept{
return (m_groups & Detail::App2) != 0;
}
/// Whether this is V2 DSM.
constexpr bool isDsmV2() const noexcept{
return (m_groups & Detail::Dsm2) != 0;
}
/// Whether this is V2 source.
constexpr bool isDsV2() const noexcept{
return (m_groups & Detail::Ds2) != 0;
}
/// The manufacturer.
/// Manufacturer and product name uniquely identify a source.
constexpr const Str32& manufacturer() const noexcept{
return m_manuf;
}
/// The product name.
/// Manufacturer and product name uniquely identify a source.
constexpr const Str32& productName() const noexcept{
return m_prodName;
}
/// The product family.
constexpr const Str32& productFamily() const noexcept{
return m_prodFamily;
}
/// Raw data group flags.
constexpr UInt32 dataGroupsRaw() const noexcept{
return m_groups;
}
/// TWAIN protocol major version.
constexpr UInt16 protocolMajor() const noexcept{
return m_protoMaj;
}
/// TWAIN protocol minor version.
constexpr UInt16 protocolMinor() const noexcept{
return m_protoMin;
}
private:
Id m_id;
Version m_version;
UInt16 m_protoMaj;
UInt16 m_protoMin;
UInt32 m_groups;
Str32 m_manuf;
Str32 m_prodFamily;
Str32 m_prodName;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_IDENTITY_HPP

View File

@ -0,0 +1,190 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_IMAGEINFO_HPP
#define TWPP_DETAIL_FILE_IMAGEINFO_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Contains information about transfered image.
class ImageInfo {
typedef Detail::FixedArray<Int16, 8> BitsPerSampleImpl;
public:
typedef Int16 BitsPerSample[8];
/// Creates zero-initialized info.
constexpr ImageInfo() noexcept :
m_imgWidth(0), m_imgHeight(0), m_spp(0), m_bps(), m_bpp(0),
m_planar(0), m_pixelType(PixelType::BlackWhite), m_compression(Compression::None){}
/// Creates info with supplied values.
template<std::size_t inputSize>
constexpr ImageInfo(
Fix32 xResolution,
Fix32 yResolution,
Int32 width,
Int32 height,
Int16 samplesPerPixel,
const Int16(& bitsPerSample)[inputSize],
Int16 bitsPerPixel,
Bool planar,
PixelType pixelType,
Compression compression
) noexcept :
m_xres(xResolution), m_yres(yResolution), m_imgWidth(width), m_imgHeight(height),
m_spp(samplesPerPixel), m_bps(bitsPerSample), m_bpp(bitsPerPixel), m_planar(planar),
m_pixelType(pixelType), m_compression(compression){}
/// X-axis resolution of the image.
constexpr Fix32 xResolution() const noexcept{
return m_xres;
}
/// Sets x-axis resolution of the image.
void setXResolution(Fix32 xres) noexcept{
m_xres = xres;
}
/// Y-axis resolution of the image.
constexpr Fix32 yResolution() const noexcept{
return m_yres;
}
/// Sets y-axis resolution of the image.
void setYResolution(Fix32 yres) noexcept{
m_yres = yres;
}
/// Image width in pixels.
constexpr Int32 width() const noexcept{
return m_imgWidth;
}
/// Sets image width in pixels.
void setWidth(Int32 width) noexcept{
m_imgWidth = width;
}
/// Image height in pixels.
constexpr Int32 height() const noexcept{
return m_imgHeight;
}
/// Sets image height in pixels.
void setHeight(Int32 height) noexcept{
m_imgHeight = height;
}
/// Samples per single pixel.
constexpr Int16 samplesPerPixel() const noexcept{
return m_spp;
}
/// Sets samples per single pixel.
void setSamplesPerPixel(Int16 spp) noexcept{
m_spp = spp;
}
/// Array of bits per sample.
/// Contains `samplesPerPixel` entries.
constexpr const BitsPerSample& bitsPerSample() const noexcept{
return m_bps.array();
}
/// Array of bits per sample.
/// Contains `samplesPerPixel` entries.
BitsPerSample& bitsPerSample() noexcept{
return m_bps.array();
}
/// Total number of bits per pixel.
/// This should be true: bitsPerPixel = SUM[i=0..samplesPerPixel-1](bitsPerSample[i])
constexpr Int16 bitsPerPixel() const noexcept{
return m_bpp;
}
/// Sets total number of bits per pixel.
/// This should be true: bitsPerPixel = SUM[i=0..samplesPerPixel-1](bitsPerSample[i])
void setBitsPerPixel(Int16 bpp) noexcept{
m_bpp = bpp;
}
/// Whether the image is planar (consists of several sample planes) or is chunky
/// (samples are transferes in one plane and are interlaced).
constexpr Bool planar() const noexcept{
return m_planar;
}
/// Sets whether the image is planar (consists of several sample planes) or is chunky
/// (samples are transferes in one plane and are interlaced).
void setPlanar(Bool planar) noexcept{
m_planar = planar;
}
/// The type of image.
constexpr PixelType pixelType() const noexcept{
return m_pixelType;
}
/// Sets the type of image.
void setPixelType(PixelType pixelType) noexcept{
m_pixelType = pixelType;
}
/// Image compression.
constexpr Compression compression() const noexcept{
return m_compression;
}
/// Sets image compression.
void compression(Compression compression) noexcept{
m_compression = compression;
}
private:
Fix32 m_xres;
Fix32 m_yres;
Int32 m_imgWidth;
Int32 m_imgHeight;
Int16 m_spp;
BitsPerSampleImpl m_bps;
Int16 m_bpp;
Bool m_planar;
PixelType m_pixelType;
Compression m_compression;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_IMAGEINFO_HPP

View File

@ -0,0 +1,100 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_IMAGELAYOUT_HPP
#define TWPP_DETAIL_FILE_IMAGELAYOUT_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Provides image size and its position on the scanner and information about order of the image.
class ImageLayout {
public:
/// Creates layout.
constexpr ImageLayout(
const Frame& frame = Frame(),
UInt32 documentNumber = 1,
UInt32 pageNumber = 1,
UInt32 frameNumber = 1
) noexcept :
m_frame(frame), m_docNumber(documentNumber),
m_pageNumber(pageNumber), m_frameNumber(frameNumber){}
/// The image frame.
constexpr const Frame& frame() const noexcept{
return m_frame;
}
/// Sets the image frame.
void setFrame(const Frame& frame) noexcept{
m_frame = frame;
}
/// Number of the document, set by source.
constexpr UInt32 documentNumber() const noexcept{
return m_docNumber;
}
/// Sets number of the document.
void setDocumentNumber(UInt32 documentNumber) noexcept{
m_docNumber = documentNumber;
}
/// Number of the page, set by source.
constexpr UInt32 pageNumber() const noexcept{
return m_pageNumber;
}
/// Sets number of the page.
void setPageNumber(UInt32 pageNumber) noexcept{
m_pageNumber = pageNumber;
}
/// Number of the frame, set by source.
constexpr UInt32 frameNumber() const noexcept{
return m_frameNumber;
}
/// Sets number of the frame.
void setFrameNumber(UInt32 frameNumber) noexcept{
m_frameNumber = frameNumber;
}
private:
Frame m_frame;
UInt32 m_docNumber;
UInt32 m_pageNumber;
UInt32 m_frameNumber;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_IMAGELAYOUT_HPP

View File

@ -0,0 +1,207 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP
#define TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
namespace Detail {
/// Structure holding the information and data of memory and memory file transfers.
class ImageMemXferImpl {
public:
/// Creates a zero-initialized structure without any memory.
ImageMemXferImpl() noexcept :
m_compression(Compression::None), m_bytesPerRow(0), m_columns(0), m_rows(0),
m_xoff(0), m_yoff(0), m_bytesWritten(0){}
/// Creates an initialized structure from the supplied values and memory.
/// The ownership of the memory is taken over.
ImageMemXferImpl(
Compression compression,
UInt32 bytesPerRow,
UInt32 columns,
UInt32 rows,
UInt32 xOffset,
UInt32 yOffset,
UInt32 bytesWritten,
Memory memory
) noexcept :
m_compression(compression), m_bytesPerRow(bytesPerRow),
m_columns(columns), m_rows(rows), m_xoff(xOffset), m_yoff(yOffset),
m_bytesWritten(bytesWritten), m_memory(std::move(memory)){}
/// Compression used in the transfer.
Compression compression() const noexcept{
return m_compression;
}
/// Sets compression used in the transfer.
void setCompression(Compression compression) noexcept{
m_compression = compression;
}
/// Number of bytes per single row.
UInt32 bytesPerRow() const noexcept{
return m_bytesPerRow;
}
/// Sets number of bytes per single row.
void setBytesPerRow(UInt32 bytesPerRow) noexcept{
m_bytesPerRow = bytesPerRow;
}
/// Number of columns in the transfer.
UInt32 columns() const noexcept{
return m_columns;
}
/// Sets number of columns in the transfer.
void setColumns(UInt32 columns) noexcept{
m_columns = columns;
}
/// Number of rows in the transfer.
UInt32 rows() const noexcept{
return m_rows;
}
/// Sets number of rows in the transfer.
void setRows(UInt32 rows) noexcept{
m_rows = rows;
}
/// X offset from top-left corner in pixels of the image data in the transfer.
UInt32 xOffset() const noexcept{
return m_xoff;
}
/// Sets X offset from top-left corner in pixels of the image data in the transfer.
void setXOffset(UInt32 xOffset) noexcept{
m_xoff = xOffset;
}
/// Y offset from top-left corner in pixels of the image data in the transfer.
UInt32 yOffset() const noexcept{
return m_yoff;
}
/// Sets Y offset from top-left corner in pixels of the image data in the transfer.
void setYOffset(UInt32 yOffset) noexcept{
m_yoff = yOffset;
}
/// Number of bytes in this transfer, always contains whole rows or tiles.
UInt32 bytesWritten() const noexcept{
return m_bytesWritten;
}
/// Sets number of bytes in this transfer.
void setBytesWritten(UInt32 bytesWritten) noexcept{
m_bytesWritten = bytesWritten;
}
/// Contained memory structure.
const Memory& memory() const noexcept{
return m_memory;
}
/// Contained memory structure.
Memory& memory() noexcept{
return m_memory;
}
private:
Compression m_compression;
UInt32 m_bytesPerRow;
UInt32 m_columns;
UInt32 m_rows;
UInt32 m_xoff;
UInt32 m_yoff;
UInt32 m_bytesWritten;
Memory m_memory;
};
}
/// Structure holding the information and data of memory transfer.
class ImageMemXfer : public Detail::ImageMemXferImpl {
public:
/// Creates a zero-initialized structure without any memory.
ImageMemXfer() noexcept : Detail::ImageMemXferImpl(){}
/// Creates an initialized structure from the supplied values and memory.
/// The ownership of the memory is taken over.
ImageMemXfer(
Compression compression,
UInt32 bytesPerRow,
UInt32 columns,
UInt32 rows,
UInt32 xOffset,
UInt32 yOffset,
UInt32 bytesWritten,
Memory memory
) noexcept : Detail::ImageMemXferImpl(
compression, bytesPerRow, columns, rows, xOffset,
yOffset, bytesWritten, std::move(memory)){}
};
/// Structure holding the information and data of memory file transfer.
class ImageMemFileXfer : public Detail::ImageMemXferImpl {
public:
/// Creates a zero-initialized structure without any memory.
ImageMemFileXfer() noexcept : Detail::ImageMemXferImpl(){}
/// Creates an initialized structure from the supplied values and memory.
/// The ownership of the memory is taken over.
ImageMemFileXfer(
Compression compression,
UInt32 bytesPerRow,
UInt32 columns,
UInt32 rows,
UInt32 xOffset,
UInt32 yOffset,
UInt32 bytesWritten,
Memory memory
) noexcept : Detail::ImageMemXferImpl(
compression, bytesPerRow, columns, rows, xOffset,
yOffset, bytesWritten, std::move(memory)){}
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP

View File

@ -0,0 +1,98 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP
#define TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Structure holding native transfer image handle.
class ImageNativeXfer {
public:
template<typename T>
using Data = Detail::Lock<typename std::decay<T>::type>;
template<typename T>
using ConstData = Detail::Lock<const typename std::decay<T>::type>;
/// Creates empty, invalid native transfer.
ImageNativeXfer() noexcept :
m_handle(){}
/// Creates a new ImageNativeXfer object from a handle.
/// The ownership of the handle is taken over.
explicit ImageNativeXfer(Handle h) :
m_handle(h){}
/// Creates uninitialized native image with defines size in bytes.
/// \throw std::bad_alloc
explicit ImageNativeXfer(UInt32 size) :
m_handle(Detail::alloc(size)){}
/// Data of this native transfer.
/// Actual type depends on system and source.
/// Windows sources use BMP format without file header, version varies.
/// Linux uses TIFF, version varies.
/// Mac uses QuickDraw Picture.
template<typename T = void>
Data<T> data() noexcept{
return m_handle.lock<typename std::decay<T>::type>();
}
/// Data of this native transfer.
/// Actual type depends on system and source.
/// Windows sources use BMP format without file header, version varies.
/// Linux uses TIFF, version varies.
/// Mac uses QuickDraw Picture.
template<typename T = void>
ConstData<T> data() const noexcept{
return m_handle.lock<const typename std::decay<T>::type>();
}
operator bool() const noexcept{
return m_handle;
}
/// Releases the contained handle, making user responsible for freeing it.
Handle release() noexcept{
return m_handle.release();
}
private:
Detail::UniqueHandle m_handle;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP

View File

@ -0,0 +1,158 @@
/*
The MIT License (MIT)
Copyright (c) 2015-2017 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_INTERNAL_HPP
#define TWPP_DETAIL_FILE_INTERNAL_HPP
#include "../twpp.hpp"
namespace Twpp {
struct AudioFileXfer {};
struct ImageFileXfer {};
typedef Memory IccProfileMemory;
namespace Detail {
typedef ReturnCode (TWPP_DETAIL_CALLSTYLE* DsmEntry)(
Identity* origin,
Identity* dest,
DataGroup dg,
Dat dat,
Msg msg,
void* data
);
typedef DsmEntry CallBackFunc;
typedef
#if defined(TWPP_DETAIL_OS_MAC)
void*
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
UInt32
#else
# error "CallBackConstant for your platform here"
#endif
CallBackConstant;
TWPP_DETAIL_PACK_BEGIN
struct EntryPoint {
constexpr EntryPoint() noexcept :
m_size(sizeof(EntryPoint)), m_entry(nullptr), m_alloc(nullptr),
m_free(nullptr), m_lock(nullptr), m_unlock(nullptr){}
UInt32 m_size;
DsmEntry m_entry;
MemAlloc m_alloc;
MemFree m_free;
MemLock m_lock;
MemUnlock m_unlock;
};
struct CallBack {
constexpr CallBack(CallBackFunc func, CallBackConstant constant, Msg msg) noexcept :
m_func(func), m_constant(constant), m_msg(msg){}
CallBackFunc m_func;
CallBackConstant m_constant;
Msg m_msg;
};
struct CallBack2 {
constexpr CallBack2(CallBackFunc func, UIntPtr constant, Msg msg) noexcept :
m_func(func), m_constant(constant), m_msg(msg){}
CallBackFunc m_func;
UIntPtr m_constant;
Msg m_msg;
};
TWPP_DETAIL_PACK_END
/// Manages DSM dll/so/framework connection.
class DsmLib {
public:
constexpr DsmLib() noexcept :
m_handle(DsmLibOs::nullHandle){}
~DsmLib(){
unload();
}
DsmLib(const DsmLib&) = delete;
DsmLib& operator=(const DsmLib&) = delete;
DsmLib(DsmLib&& o) noexcept :
m_handle(o.m_handle){
o.m_handle = DsmLibOs::nullHandle;
}
DsmLib& operator=(DsmLib&& o) noexcept{
if (&o != this){
unload();
m_handle = o.m_handle;
o.m_handle = DsmLibOs::nullHandle;
}
return *this;
}
operator bool() const noexcept{
return m_handle != DsmLibOs::nullHandle;
}
bool load(bool preferOld = false) noexcept{
m_handle = DsmLibOs::load(preferOld);
return m_handle != DsmLibOs::nullHandle;
}
void unload() noexcept{
if (m_handle != DsmLibOs::nullHandle){
DsmLibOs::unload(m_handle);
m_handle = DsmLibOs::nullHandle;
}
}
DsmEntry resolve() const noexcept{
return DsmLibOs::resolve<DsmEntry>(m_handle);
}
private:
DsmLibOs::Handle m_handle;
};
}
}
#endif // TWPP_DETAIL_FILE_INTERNAL_HPP

View File

@ -0,0 +1,173 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP
#define TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// See manual for more info.
class JpegCompression {
public:
typedef UInt16 UInt16Arr4[4];
typedef Memory MemoryArr2[2];
typedef Memory MemoryArr4[4];
JpegCompression() noexcept :
m_colorSpace(PixelType::BlackWhite), m_subSampling(0x10001000), m_components(0),
m_restartFrequency(0), m_quantMap(), m_huffmanMap(){}
template<
std::size_t quantTableMapSize,
std::size_t quantTableSize,
std::size_t huffmanTableMapSize,
std::size_t huffmanDcSize,
std::size_t huffmanAcSize
>
JpegCompression(
PixelType colorSpace,
UInt32 subSampling,
UInt16 components,
UInt16 restartFrequency,
const UInt16(& quantTableMap)[quantTableMapSize],
Memory(& quantTable)[quantTableSize],
const UInt16(& huffmanTableMap)[huffmanTableMapSize],
Memory(& huffmanDc)[huffmanDcSize],
Memory(& huffmanAc)[huffmanAcSize]
) noexcept :
m_colorSpace(colorSpace),
m_subSampling(subSampling),
m_components(components),
m_restartFrequency(restartFrequency),
m_quantMap(quantTableMap),
m_huffmanMap(huffmanTableMap){
for (std::size_t i = 0; i < quantTableSize; i++){
m_quantTable[i] = std::move(quantTable[i]);
}
for (std::size_t i = 0; i < huffmanDcSize; i++){
m_huffmanDc[i] = std::move(huffmanDc[i]);
}
for (std::size_t i = 0; i < huffmanAcSize; i++){
m_huffmanAc[i] = std::move(huffmanAc[i]);
}
}
PixelType pixelType() const noexcept{
return m_colorSpace;
}
void setPixelType(PixelType pixelType) noexcept{
m_colorSpace = pixelType;
}
UInt32 subSampling() const noexcept{
return m_subSampling;
}
void setSubSampling(UInt32 subSampling) noexcept{
m_subSampling = subSampling;
}
UInt16 components() const noexcept{
return m_components;
}
void setComponents(UInt16 components) noexcept{
m_components = components;
}
UInt16 restartFrequency() const noexcept{
return m_restartFrequency;
}
void setRestartFrequency(UInt16 restartFrequency) noexcept{
m_restartFrequency = restartFrequency;
}
const UInt16Arr4& quantTableMap() const noexcept{
return m_quantMap.array();
}
UInt16Arr4& quantTableMap() noexcept{
return m_quantMap.array();
}
const MemoryArr4& quantTable() const noexcept{
return m_quantTable;
}
MemoryArr4& quantTable() noexcept{
return m_quantTable;
}
const UInt16Arr4& huffmanTableMap() const noexcept{
return m_huffmanMap.array();
}
UInt16Arr4& huffmanTableMap() noexcept{
return m_huffmanMap.array();
}
const MemoryArr2& huffmanDc() const noexcept{
return m_huffmanDc;
}
MemoryArr2& huffmanDc() noexcept{
return m_huffmanDc;
}
const MemoryArr2& huffmanAc() const noexcept{
return m_huffmanAc;
}
MemoryArr2& huffmanAc() noexcept{
return m_huffmanAc;
}
private:
PixelType m_colorSpace;
UInt32 m_subSampling;
UInt16 m_components;
UInt16 m_restartFrequency;
Detail::FixedArray<UInt16, 4> m_quantMap;
MemoryArr4 m_quantTable;
Detail::FixedArray<UInt16, 4> m_huffmanMap;
MemoryArr2 m_huffmanDc;
MemoryArr2 m_huffmanAc;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP

View File

@ -0,0 +1,194 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_MEMORY_HPP
#define TWPP_DETAIL_FILE_MEMORY_HPP
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
namespace Flags {
enum {
AppOwns = 0x0001,
DsmOwns = 0x0002,
DsOwns = 0x0004,
Pointer = 0x0008,
Handle = 0x0010
};
#if !defined(TWPP_IS_DS)
static constexpr const UInt32 thisOwns = AppOwns;
static constexpr const UInt32 otherOwns = DsOwns;
#else
static constexpr const UInt32 thisOwns = DsOwns;
static constexpr const UInt32 otherOwns = AppOwns;
#endif
}
}
TWPP_DETAIL_PACK_BEGIN
/// Holds and potentially owns a block of memory using either pointer or handle.
class Memory {
public:
typedef Detail::MaybeLock<char> Data;
typedef Detail::MaybeLock<const char> ConstData;
/// Creates an empty memory.
constexpr Memory() noexcept :
m_flags(0), m_size(0), m_data(nullptr){}
/// Creates a memory block of supplied size.
/// \throw std::bad_alloc
explicit Memory(UInt32 size) :
m_flags(Detail::Flags::thisOwns | Detail::Flags::Handle), m_size(size),
m_data(Detail::alloc(size).raw()){}
/// Creates a new memory object from Handle.
/// The memory ownership is taken over.
/// \param h The handle, see thisOwns for more information about memory ownership.
/// \param size Size of the memory in bytes, that handle h manages.
/// \param thisOwns {
/// If true, this object frees the memory once it goes out of scope.
///
/// If false the memory is not freed, and MUST be passed to the other side
/// (APP->DS or DS->APP) of the connection, that will free it.
/// }
Memory(Handle h, UInt32 size, bool thisOwns = true) noexcept :
m_flags((thisOwns ? Detail::Flags::thisOwns : Detail::Flags::otherOwns) | Detail::Flags::Handle),
m_size(size),
m_data(h.raw()){}
/// Creates a memory object from container.
/// The memory object does NOT take over the ownership of the data.
/// Make sure the container is destroyed after the memory object is.
template<typename Container>
explicit Memory(const Container& container) noexcept :
m_flags(Detail::Flags::thisOwns | Detail::Flags::Pointer),
m_size(sizeof(Container::value_type) * container.size()),
m_data(container.data()){}
/// Creates a memory object from pointer.
/// The memory object does NOT take over the ownership of the data.
/// Make sure the data is destroyed after the memory object is.
constexpr Memory(void* data, UInt32 size) noexcept :
m_flags(Detail::Flags::thisOwns | Detail::Flags::Pointer), m_size(size),
m_data(data){}
~Memory(){
freePriv();
}
Memory(const Memory& o) = delete;
Memory& operator=(const Memory& o) = delete;
Memory(Memory&& o) noexcept :
m_flags(o.m_flags), m_size(o.m_size), m_data(o.m_data)
{
o.m_flags = 0;
o.m_size = 0;
o.m_data = nullptr;
}
Memory& operator=(Memory&& o) noexcept{
if (&o != this){
freePriv();
m_flags = o.m_flags;
m_size = o.m_size;
m_data = o.m_data;
o.m_flags = 0;
o.m_size = 0;
o.m_data = nullptr;
}
return *this;
}
/// The data in this memory block.
ConstData data() const noexcept{
return m_flags & Detail::Flags::Handle ?
ConstData(Handle(static_cast<Handle::Raw>(m_data))) :
ConstData(static_cast<const char*>(m_data));
}
/// The data in this memory block.
Data data() noexcept{
return m_flags & Detail::Flags::Handle ?
Data(Handle(static_cast<Handle::Raw>(m_data))) :
Data(static_cast<char*>(m_data));
}
/// Number of bytes in the memory block.
UInt32 size() const noexcept{
return m_size;
}
/// In case of handle, frees memory regardless its owner; does nothing otherwise (pointer).
/// Potentially unsafe operation.
void free(){
if (m_flags & Detail::Flags::Handle){
Handle h(static_cast<Handle::Raw>(m_data));
if (h){
Detail::free(h);
}
m_size = 0;
m_data = nullptr;
m_flags = 0;
}
}
private:
void freePriv(){
if (m_flags & Detail::Flags::thisOwns){
if (m_flags & Detail::Flags::Handle){
Detail::free(Handle(static_cast<Handle::Raw>(m_data)));
}
}
}
UInt32 m_flags;
UInt32 m_size;
void* m_data;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_MEMORY_HPP

View File

@ -0,0 +1,439 @@
/*
The MIT License (MIT)
Copyright (c) 2015-2017 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_MEMORYOPS_HPP
#define TWPP_DETAIL_FILE_MEMORYOPS_HPP
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
extern "C" {
typedef Handle::Raw (TWPP_DETAIL_CALLSTYLE* MemAlloc)(UInt32 size);
typedef void (TWPP_DETAIL_CALLSTYLE* MemFree)(Handle::Raw handle);
typedef void* (TWPP_DETAIL_CALLSTYLE* MemLock)(Handle::Raw handle);
typedef void (TWPP_DETAIL_CALLSTYLE* MemUnlock)(Handle::Raw handle);
}
// templates behave as if they were defined in at most one module
// ideal for storing static data
template<typename Dummy>
struct GlobalMemFuncs {
#if defined(TWPP_DETAIL_OS_WIN)
static Handle::Raw TWPP_DETAIL_CALLSTYLE defAlloc(UInt32 size){
return ::GlobalAlloc(GHND, size);
}
static void TWPP_DETAIL_CALLSTYLE defFree(Handle::Raw handle){
::GlobalFree(handle);
}
static void* TWPP_DETAIL_CALLSTYLE defLock(Handle::Raw handle){
return ::GlobalLock(handle);
}
static void TWPP_DETAIL_CALLSTYLE defUnlock(Handle::Raw handle){
::GlobalUnlock(handle);
}
#elif defined(TWPP_DETAIL_OS_MAC)
static Handle::Raw TWPP_DETAIL_CALLSTYLE defAlloc(UInt32 size){
return ::NewHandle(size);
}
static void TWPP_DETAIL_CALLSTYLE defFree(Handle::Raw handle){
::DisposeHandle(handle);
}
static void* TWPP_DETAIL_CALLSTYLE defLock(Handle::Raw handle){
return *handle;
}
static void TWPP_DETAIL_CALLSTYLE defUnlock(Handle::Raw){
// noop
}
#elif !defined(TWPP_DETAIL_OS_LINUX) // Linux doesnt need default functions
# error "default memory functions for your platform here"
#endif
static MemAlloc alloc;
static MemFree free;
static MemLock lock;
static MemUnlock unlock;
#if defined(TWPP_IS_DS)
static Handle doNotFreeHandle;
#endif
};
#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_MAC)
template<typename Dummy>
MemAlloc GlobalMemFuncs<Dummy>::alloc = GlobalMemFuncs<Dummy>::defAlloc;
template<typename Dummy>
MemFree GlobalMemFuncs<Dummy>::free = GlobalMemFuncs<Dummy>::defFree;
template<typename Dummy>
MemLock GlobalMemFuncs<Dummy>::lock = GlobalMemFuncs<Dummy>::defLock;
template<typename Dummy>
MemUnlock GlobalMemFuncs<Dummy>::unlock = GlobalMemFuncs<Dummy>::defUnlock;
#elif defined(TWPP_DETAIL_OS_LINUX)
template<typename Dummy>
MemAlloc GlobalMemFuncs<Dummy>::alloc = nullptr;
template<typename Dummy>
MemFree GlobalMemFuncs<Dummy>::free = nullptr;
template<typename Dummy>
MemLock GlobalMemFuncs<Dummy>::lock = nullptr;
template<typename Dummy>
MemUnlock GlobalMemFuncs<Dummy>::unlock = nullptr;
#else
# error "default memory functions setup for your platform here"
#endif
#if defined(TWPP_IS_DS)
template<typename Dummy>
Handle GlobalMemFuncs<Dummy>::doNotFreeHandle;
#endif
inline static void setMemFuncs(MemAlloc alloc, MemFree free, MemLock lock, MemUnlock unlock) noexcept{
GlobalMemFuncs<void>::alloc = alloc;
GlobalMemFuncs<void>::free = free;
GlobalMemFuncs<void>::lock = lock;
GlobalMemFuncs<void>::unlock = unlock;
}
inline static void resetMemFuncs() noexcept{
#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_MAC)
GlobalMemFuncs<void>::alloc = GlobalMemFuncs<void>::defAlloc;
GlobalMemFuncs<void>::free = GlobalMemFuncs<void>::defFree;
GlobalMemFuncs<void>::lock = GlobalMemFuncs<void>::defLock;
GlobalMemFuncs<void>::unlock = GlobalMemFuncs<void>::defUnlock;
#elif defined(TWPP_DETAIL_OS_LINUX)
GlobalMemFuncs<void>::alloc = nullptr;
GlobalMemFuncs<void>::free = nullptr;
GlobalMemFuncs<void>::lock = nullptr;
GlobalMemFuncs<void>::unlock = nullptr;
#else
# error "resetMemFuncs for your platform here"
#endif
}
inline static Handle alloc(UInt32 size){
auto h = GlobalMemFuncs<void>::alloc(size);
if (!h){
throw std::bad_alloc();
}
return Handle(h);
}
inline static void* lock(Handle handle) noexcept{
return GlobalMemFuncs<void>::lock(handle.raw());
}
inline static void unlock(Handle handle) noexcept{
GlobalMemFuncs<void>::unlock(handle.raw());
}
inline static void free(Handle handle) noexcept{
GlobalMemFuncs<void>::free(handle.raw());
}
template<typename T>
static inline T* typeLock(Handle handle) noexcept{
return static_cast<T*>(lock(handle));
}
/// A lock that can contain either handle or raw pointer.
/// Locks and unlocks handle, noop for pointer.
template<typename T>
class MaybeLock {
public:
constexpr MaybeLock() noexcept :
m_handle(), m_pointer(nullptr){}
MaybeLock(Handle h) noexcept :
m_handle(h), m_pointer(typeLock<T>(h)){}
constexpr MaybeLock(T* ptr) noexcept :
m_handle(), m_pointer(ptr){}
~MaybeLock(){
unlock();
}
MaybeLock(const MaybeLock& o) noexcept :
m_handle(o.m_handle), m_pointer(o.m_handle ? typeLock<T>(o.m_handle) : o.m_pointer){}
MaybeLock& operator=(const MaybeLock& o) noexcept{
if (&o != this){
unlock();
m_handle = o.m_handle;
m_pointer = m_handle ? typeLock<T>(m_handle) : o.m_pointer;
}
return *this;
}
MaybeLock(MaybeLock&& o) noexcept :
m_handle(o.m_handle), m_pointer(o.m_pointer){
o.m_handle = Handle();
o.m_pointer = nullptr;
}
MaybeLock& operator=(MaybeLock&& o) noexcept{
if (&o != this){
unlock();
m_handle = o.m_handle;
m_pointer = o.m_pointer;
o.m_handle = Handle();
o.m_pointer = nullptr;
}
return *this;
}
T* data() const noexcept{
return m_pointer;
}
operator T*() const noexcept{
return m_pointer;
}
T* operator->() noexcept{
return m_pointer;
}
T* operator->() const noexcept{
return m_pointer;
}
bool hasData() const noexcept{
return m_pointer;
}
operator bool() const noexcept{
return m_pointer;
}
private:
void unlock() noexcept{
if (m_handle){
Detail::unlock(m_handle);
}
}
Handle m_handle;
T* m_pointer;
};
/// Simple handle lock.
/// Locks on creation and unlocks on destruction.
template<typename T>
class Lock {
public:
constexpr Lock() noexcept :
m_handle(), m_pointer(nullptr){}
Lock(Handle h) noexcept :
m_handle(h), m_pointer(typeLock<T>(h)){}
~Lock(){
unlock();
}
Lock(const Lock& o) noexcept :
m_handle(o.m_handle), m_pointer(typeLock<T>(o.m_handle)){}
Lock& operator=(const Lock& o) noexcept{
if (&o != this){
unlock();
m_handle = o.m_handle;
m_pointer = typeLock<T>(m_handle);
}
return *this;
}
Lock(Lock&& o) noexcept :
m_handle(o.m_handle), m_pointer(o.m_pointer){
o.m_handle = Handle();
o.m_pointer = nullptr;
}
Lock& operator=(Lock&& o) noexcept{
if (&o != this){
unlock();
m_handle = o.m_handle;
m_pointer = o.m_pointer;
o.m_handle = Handle();
o.m_pointer = nullptr;
}
return *this;
}
T* data() const noexcept{
return m_pointer;
}
operator T*() const noexcept{
return m_pointer;
}
T* operator->() noexcept{
return m_pointer;
}
T* operator->() const noexcept{
return m_pointer;
}
bool hasData() const noexcept{
return m_pointer;
}
operator bool() const noexcept{
return m_pointer;
}
private:
void unlock() noexcept{
if (m_handle){
Detail::unlock(m_handle);
}
}
Handle m_handle;
T* m_pointer;
};
/// Owns a handle and frees it upon destruction,
/// unless `release` is called beforehand.
class UniqueHandle {
public:
constexpr UniqueHandle(Handle h = Handle()) noexcept :
m_handle(h){}
~UniqueHandle(){
free();
}
UniqueHandle(const UniqueHandle&) = delete;
UniqueHandle& operator=(const UniqueHandle&) = delete;
UniqueHandle(UniqueHandle&& o) noexcept :
m_handle(o.m_handle){
o.m_handle = Handle();
}
UniqueHandle& operator=(UniqueHandle&& o) noexcept{
if (&o != this){
free();
m_handle = o.m_handle;
o.m_handle = Handle();
}
return *this;
}
operator bool() const noexcept{
return m_handle;
}
/// The contained handle.
Handle get() noexcept{
return m_handle;
}
/// The contained handle.
Handle get() const noexcept{
return m_handle;
}
/// Releases the contained handle, making the user responsible for freeing it.
Handle release() noexcept{
Handle ret = m_handle;
m_handle = Handle();
return ret;
}
template<typename T>
Lock<T> lock() const{
return m_handle;
}
private:
void free() noexcept{
#if defined(TWPP_IS_DS)
if (m_handle && m_handle != GlobalMemFuncs<void>::doNotFreeHandle){
#else
if (m_handle){
#endif
Detail::free(m_handle);
}
}
Handle m_handle;
};
}
}
#endif // TWPP_DETAIL_FILE_MEMORYOPS_HPP

View File

@ -0,0 +1,145 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_PALETTE8_HPP
#define TWPP_DETAIL_FILE_PALETTE8_HPP
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
// specialization for Element8
// we also want to set index of the element when placing it inside array
template<std::size_t arraySize, UInt8... i>
struct FixedArrayData<Element8, arraySize, IndexList<i...> > {
static constexpr Element8 updateIndex(UInt8 index, const Element8& e) noexcept{
return Element8(index, e.channel1(), e.channel2(), e.channel3());
}
template<std::size_t inputSize>
constexpr FixedArrayData(const Element8(& arr)[inputSize]) noexcept :
m_arr{updateIndex(i, FixedArrayFlat<Element8, arraySize>(arr)[i])...}{}
constexpr FixedArrayData() noexcept :
m_arr{Element8(i)...}{}
Element8 m_arr[arraySize];
};
}
TWPP_DETAIL_PACK_BEGIN
/// Palette information for memory transfers
class Palette8 {
public:
enum class Type : UInt16 {
Rgb = 0,
Gray = 1,
Cmy = 2
};
typedef Element8 Element8Arr256[256];
/// Creates an uninitialized palette.
constexpr Palette8() noexcept :
m_size(0), m_type(Type::Rgb), m_colors(){}
/// Creates a palette with the supplied type and elements.
template<std::size_t inputSize>
constexpr Palette8(Type type, const Element8(& colors)[inputSize]) noexcept :
m_size(inputSize), m_type(type),
m_colors(colors){
static_assert(inputSize <= 256, "too many colors");
}
/// Creates a palette with the supplied type and elements from container.
/// \throw RangeException When there are more than 256 colors.
template<typename Container>
Palette8(Type type, const Container& colors) :
m_size(static_cast<UInt16>(colors.size())), m_type(type){
if (colors.size() > 256){
throw RangeException();
}
auto& array = m_colors.array();
for (UInt16 i = 0; i < m_size; i++){
array[i] = colors[i];
array[i].setIndex(i);
}
}
/// Creates a palette with the supplied type and elements.
/// \throw RangeException When there are more than 256 colors.
Palette8(Type type, const Element8* colors, UInt16 size) :
m_size(size), m_type(type){
if (m_size > 256){
throw RangeException();
}
auto& array = m_colors.array();
for (UInt16 i = 0; i < m_size; i++){
array[i] = colors[i];
array[i].setIndex(static_cast<UInt8>(i)); // 0..255 max
}
}
/// Number of elements in the palette.
constexpr UInt16 size() const noexcept{
return m_size;
}
/// Type of palette data.
constexpr Type type() const noexcept{
return m_type;
}
/// Array of palette elements.
constexpr const Element8Arr256& colors() const noexcept{
return m_colors.array();
}
private:
UInt16 m_size;
Type m_type;
Detail::FixedArray<Element8, 256> m_colors;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_PALETTE8_HPP

View File

@ -0,0 +1,126 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_PASSTHROUGH_HPP
#define TWPP_DETAIL_FILE_PASSTHROUGH_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Structure for raw comminication with device in source.
/// See manual for more information, DAT_PASSTHRU, MSG_PASSTHRU.
class PassThrough {
public:
enum class Direction : Int32 {
Get = 1,
Set = 2
};
constexpr PassThrough(
void* command,
UInt32 commandSize,
Direction direction,
void* data,
UInt32 dataSize,
UInt32 dataXfered
) noexcept :
m_cmd(command), m_cmdSize(commandSize),
m_direction(direction),
m_data(data), m_dataSize(dataSize), m_dataXfered(dataXfered){}
constexpr void* command() const noexcept{
return m_cmd;
}
constexpr UInt32 commandSize() const noexcept{
return m_cmdSize;
}
template<typename Container>
void setCommand(const Container& command) noexcept{
m_cmd = command.data();
m_cmdSize = sizeof(Container::value_type) * command.size();
}
void setCommand(void* command, UInt32 size) noexcept{
m_cmd = command;
m_cmdSize = size;
}
constexpr Direction direction() const noexcept{
return m_direction;
}
void setDirection(Direction direction) noexcept{
m_direction = direction;
}
constexpr void* data() const noexcept{
return m_data;
}
constexpr UInt32 dataSize() const noexcept{
return m_dataSize;
}
template<typename Container>
void setData(const Container& data) noexcept{
m_data = data.data();
m_dataSize = sizeof(Container::value_type) * data.size();
m_dataXfered = 0;
}
void setData(void* data, UInt32 dataSize) noexcept{
m_data = data;
m_dataSize = dataSize;
m_dataXfered = 0;
}
constexpr UInt32 dataXfered() const noexcept{
return m_dataXfered;
}
void setDataXfered(Int32 dataXfered) noexcept{
m_dataXfered = dataXfered;
}
private:
void* m_cmd;
UInt32 m_cmdSize;
Direction m_direction;
void* m_data;
UInt32 m_dataSize;
UInt32 m_dataXfered;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_PASSTHROUGH_HPP

View File

@ -0,0 +1,86 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_PENDINGXFERS_HPP
#define TWPP_DETAIL_FILE_PENDINGXFERS_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Reports number of pending images, transfers.
class PendingXfers {
public:
/// Job control settings.
enum class JobPatch : UInt32 {
None = 0x0000,
MidSeparator = 0x0001,
P1 = 0x0002,
P2 = 0x0003,
P3 = 0x0004,
P4 = 0x0005,
P6 = 0x0006,
PT = 0x0007
};
/// Creates object to report number of pending transfers.
/// \param count Number of pending transfers.
/// \param patch Job control settings.
constexpr PendingXfers(UInt16 count = 0, JobPatch patch = JobPatch::None) noexcept :
m_count(count), m_eoj(patch){}
/// Number of pending images/transfers.
constexpr UInt16 count() const noexcept{
return m_count;
}
/// Sets number of pending images/transfers.
void setCount(UInt16 count) noexcept{
m_count = count;
}
/// Job control settings.
constexpr JobPatch jobPatch() const noexcept{
return m_eoj;
}
/// Sets job control settings.
void setJobPatch(JobPatch eoj) noexcept{
m_eoj = eoj;
}
private:
UInt16 m_count;
JobPatch m_eoj;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_PENDINGXFERS_HPP

View File

@ -0,0 +1,103 @@
/*
The MIT License (MIT)
Copyright (c) 2015-2017 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_SETUPFILEXFER_HPP
#define TWPP_DETAIL_FILE_SETUPFILEXFER_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Structure for setting up file transfer.
class SetupFileXfer {
public:
/// Creates zero-initialized instance.
constexpr SetupFileXfer() noexcept :
m_format(ImageFileFormat::Tiff), m_volRefNum(0){}
/// Creates instance with set file path and format.
/// And volume reference number on Mac OS.
/// \param filePath Path to transfered file.
/// \param format File format.
/// \param vrn Volume reference number. Mac OS only.
constexpr SetupFileXfer(
const Str255& filePath,
ImageFileFormat format,
Int16 vrn
#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
= -1
#elif !defined(TWPP_DETAIL_OS_MAC)
# error "Volume reference number for your platform here"
#endif
) noexcept :
m_filePath(filePath), m_format(format),
m_volRefNum(vrn){}
/// Path to transfered file.
constexpr const Str255& filePath() const noexcept{
return m_filePath;
}
/// Sets path to transfered file.
void setFilePath(const Str255& filePath) noexcept{
m_filePath = filePath;
}
/// Format of the transfered file.
constexpr ImageFileFormat format() const noexcept{
return m_format;
}
/// Sets format of the transfered file.
void setFormat(ImageFileFormat format) noexcept{
m_format = format;
}
/// Volume reference number.
/// Mac OS only.
constexpr Int16 volumeReferenceNumber() const noexcept{
return m_volRefNum;
}
/// Sets volume reference number.
/// Mac OS only.
void setVolumeReferenceNumber(Int16 volumeReferenceNumber) noexcept{
m_volRefNum = volumeReferenceNumber;
}
private:
Str255 m_filePath;
ImageFileFormat m_format;
Int16 m_volRefNum;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_SETUPFILEXFER_HPP

View File

@ -0,0 +1,92 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_SETUPMEMXFER_HPP
#define TWPP_DETAIL_FILE_SETUPMEMXFER_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Structure for setting up memory transfer.
class SetupMemXfer {
public:
/// Creates zero-initialized instance.
constexpr SetupMemXfer() noexcept :
m_minSize(0), m_maxSize(0), m_prefSize(0){}
/// Creates an initialized instance with set minimal, maximal and preferred sizes.
/// Must be true, or the behaviour is undefined: minSize <= preferredSize <= maxSize
constexpr SetupMemXfer(
UInt32 minSize,
UInt32 maxSize,
UInt32 preferredSize
) noexcept :
m_minSize(minSize), m_maxSize(maxSize), m_prefSize(preferredSize){}
/// Minimal supported buffer size in bytes.
constexpr UInt32 minSize() const noexcept{
return m_minSize;
}
/// Sets minimal supported buffer size in bytes.
void setMinSize(UInt32 minSize) noexcept{
m_minSize = minSize;
}
/// Maximal supported buffer size in bytes.
constexpr UInt32 maxSize() const noexcept{
return m_maxSize;
}
/// Sets maximal supported buffer size in bytes.
void setMaxSize(UInt32 maxSize) noexcept{
m_maxSize = maxSize;
}
/// Preferred buffer size in bytes.
constexpr UInt32 preferredSize() const noexcept{
return m_prefSize;
}
/// Sets preferred buffer size in bytes.
void setPreferredSize(UInt32 prefSize) noexcept{
m_prefSize = prefSize;
}
private:
UInt32 m_minSize;
UInt32 m_maxSize;
UInt32 m_prefSize;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_SETUPMEMXFER_HPP

View File

@ -0,0 +1,230 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_STATUS_HPP
#define TWPP_DETAIL_FILE_STATUS_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Additional status information about a performed TWAIN operation.
class Status {
public:
/// Creates operation status.
/// \param cond Status condition code.
/// \param data Additional status data, source-specific.
constexpr Status(CC cond = CC::Success, UInt16 data = 0) noexcept :
m_cond(cond), m_data(data){}
/// Status condition code.
constexpr CC condition() const noexcept{
return m_cond;
}
/// Sets status condition code.
void setCondition(CC cc) noexcept{
m_cond = cc;
}
/// Aditional status data, source-specific.
constexpr UInt16 data() const noexcept{
return m_data;
}
/// Sets aditional status data, source-specific.
void setData(UInt16 data) noexcept{
m_data = data;
}
constexpr operator CC() const noexcept{
return m_cond;
}
constexpr operator bool() const noexcept{
return success(m_cond);
}
constexpr bool operator==(CC o) const noexcept{return m_cond == o;}
constexpr bool operator!=(CC o) const noexcept{return m_cond != o;}
constexpr bool operator==(Status o) const noexcept{return m_cond == o.m_cond && m_data == o.m_data;}
constexpr bool operator!=(Status o) const noexcept{return m_cond != o.m_cond || m_data != o.m_data;}
private:
CC m_cond;
UInt16 m_data;
};
static inline constexpr bool success(Status stat) noexcept{
return stat;
}
/// Structure for translating status to UTF8 text.
class StatusUtf8 {
public:
typedef Detail::Lock<const char> ConstString;
/// Creates a status utf8 without string data.
StatusUtf8(Status status = Status()) noexcept :
m_status(status), m_size(0), m_string(){}
/// Creates a status utf8 containing copy of string data.
/// The string must be null-terminated.
/// \tparam inputSize Size of the string including null terminator.
/// \param str The string, must be null-terminated.
/// \throw std::bad_alloc
template<UInt32 inputSize>
StatusUtf8(Status status, const char(& str)[inputSize]) :
m_status(status), m_size(inputSize), m_string(Detail::alloc(inputSize)){
std::copy(str, str + inputSize, string().data());
}
/// Creates a new status utf8 containing a copy of the supplied string.
/// \param status
/// \param str Utf-8 string to copy, must be null-terminated.
/// \throw RangeException When string is too long, could not insert null terminator.
/// \throw std::bad_alloc
StatusUtf8(Status status, const char* str) :
m_status(status), m_size(0), m_string(){
auto len = strlen(str);
if (len >= std::numeric_limits<UInt32>::max()){
throw RangeException();
}
m_size = static_cast<UInt32>(len) + 1;
m_string = Detail::alloc(m_size);
std::copy(str, str + len + 1, m_string.lock<char>().data());
}
/// Creates a new status utf8 containing a copy of the supplied string.
/// \param status
/// \param str Utf-8 string to copy.
/// \throw RangeException When string is too long, could not insert null terminator.
/// \throw std::bad_alloc
StatusUtf8(Status status, const std::string& str) :
m_status(status), m_size(0), m_string(){
auto len = str.length();
if (len >= std::numeric_limits<UInt32>::max()){
throw RangeException();
}
m_size = static_cast<UInt32>(len) + 1;
m_string = Detail::alloc(m_size);
auto lock = m_string.lock<char>();
std::copy(str.cbegin(), str.cend(), lock.data());
lock[len] = '\0';
}
/// Creates a new StatusUtf8 containing a copy of the supplied string.
/// \param status
/// \param str Utf-8 string to copy, null terminator is not required.
/// \param strSize {Number of bytes to copy including null terminator.
/// Null terminator is inserted automatically.}
/// \throw RangeException When string is too short to satisfy the requested size.
/// \throw std::bad_alloc
StatusUtf8(Status status, const char* str, UInt32 strSize) :
m_status(status), m_size(0), m_string(){
auto len = strlen(str);
if (len < strSize){
throw RangeException();
}
m_size = static_cast<UInt32>(strSize) + 1;
m_string = Detail::alloc(m_size);
auto lock = m_string.lock<char>();
std::copy(str, str + strSize, lock.data());
lock[strSize] = '\0';
}
StatusUtf8(const StatusUtf8&) = delete;
StatusUtf8& operator=(const StatusUtf8&) = delete;
StatusUtf8(StatusUtf8&& o) noexcept :
m_status(o.m_status), m_size(o.m_size), m_string(std::move(o.m_string)){
o.m_status = Status();
o.m_size = 0;
}
StatusUtf8& operator=(StatusUtf8&& o) noexcept{
if (&o != this){
m_status = o.m_status;
m_size = o.m_size;
m_string = std::move(o.m_string);
o.m_status = Status();
o.m_size = 0;
}
return *this;
}
/// Returns the interpreted status.
Status status() const noexcept{
return m_status;
}
/// Sets the status to be interpreted.
void setStatus(Status status) noexcept{
m_status = status;
}
/// Returns the total number of bytes including null byte.
UInt32 size() const noexcept{
return m_string ? m_size : 0;
}
/// The UTF8 string itself.
ConstString string() const noexcept{
return m_string.lock<const char>();
}
private:
Status m_status;
UInt32 m_size;
Detail::UniqueHandle m_string;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_STATUS_HPP

View File

@ -0,0 +1,310 @@
/*
The MIT License (MIT)
Copyright (c) 2015-2017 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_STRINGS_HPP
#define TWPP_DETAIL_FILE_STRINGS_HPP
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
// specialization for twain strings
// on mac os, these strings do not contain null terminator
// instead, the first byte contains the length
template<std::size_t arraySize, std::size_t... i>
struct FixedArrayData<char, arraySize, IndexList<i...> > {
template<std::size_t inputSize>
constexpr FixedArrayData(const char(& arr)[inputSize]) noexcept :
m_arr{
#if defined(TWPP_DETAIL_OS_MAC)
unsignedToSigned<unsigned char>(inputSize - 1),
#elif !defined(TWPP_DETAIL_OS_WIN) && !defined(TWPP_DETAIL_OS_LINUX)
# error "string data setup for yout platform here"
#endif
FixedArrayFlat<char, arraySize>(arr)[i]...
}{}
constexpr FixedArrayData() noexcept :
m_arr(){}
char m_arr[arraySize];
};
// specialization for twain strings
// on mac os, these strings do not contain null terminator
// instead, the first byte contains the length
// so we provide one less index for the fixed array
// on windows, its element is zero-initialized due to it not being specified
// on mac os, the first byte contains the length, so the index is not used anyway
template<std::size_t arraySize>
struct FixedArray<char, arraySize> : public FixedArrayData<char, arraySize, typename Indexes<arraySize - 1>::Result> {
typedef FixedArrayData<char, arraySize, typename Indexes<arraySize - 1>::Result> ParentType;
typedef char Array[arraySize];
constexpr FixedArray() noexcept :
ParentType(){}
template<std::size_t inputSize>
constexpr FixedArray(const char(& arr)[inputSize]) noexcept :
ParentType(arr){
static_assert(inputSize <= arraySize, "string literal is too long");
}
constexpr const Array& array() const noexcept{
return ParentType::m_arr;
}
Array& array() noexcept{
return ParentType::m_arr;
}
};
/// TWAIN string template.
/// \tparam arraySize String capacity, including either null byte, or length byte (Mac OS).
template<std::size_t arraySize>
class Str : private FixedArray<char, arraySize>{
typedef FixedArray<char, arraySize> DataType;
public:
typedef const char* const_iterator;
typedef char* iterator;
/// Maximal number of characters this string may hold.
/// Excluding null byte (length byte).
static constexpr UInt32 maxSize() noexcept{
return arraySize - 1;
}
static_assert(maxSize() <= std::numeric_limits<unsigned char>::max(), "string type exceeds allowed sizes");
/// Creates an empty, zero-initialized string.
constexpr Str() noexcept{}
/// Creates a compile-time string from string literal (or char array).
/// \tparam inputSize Size of the string literal including null terminator.
/// \param str The string literal.
template<std::size_t inputSize>
constexpr Str(const char(& str)[inputSize]) noexcept :
DataType(str){
static_assert(inputSize <= arraySize, "string literal is too long");
}
/// Alias to length().
constexpr UInt32 size() const noexcept{
return length();
}
/// Length of the string (number of 8-bit characters).
/// O(1) on Mac OS, O(n) anywhere else.
constexpr UInt32 length() const noexcept{
#if defined(TWPP_DETAIL_OS_MAC)
return static_cast<unsigned const char>(this->array()[0]);
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
return strLen(data());
#else
# error "String::length for your platform here"
#endif
}
/// Pointer to constant data.
/// On Mac OS, the data is NOT null-terminated,
/// and points to the first character after size byte.
/// This operation is unsafe, and its use may not be platform-independent.
constexpr const char* data() const noexcept{
#if defined(TWPP_DETAIL_OS_MAC)
return this->array() + 1;
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
return this->array();
#else
# error "String::data for your platform here"
#endif
}
/// Pointer to data.
/// On Mac OS, the data is NOT null-terminated,
/// and points to the first character after size byte.
/// This operation is unsafe, and its use may not be platform-independent.
char* data() noexcept{
#if defined(TWPP_DETAIL_OS_MAC)
return this->array() + 1;
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
return this->array();
#else
# error "String::data for your platform here"
#endif
}
/// Sets string data.
/// Copies as much data as possible, discarding the rest.
/// The data needn't be null terminated.
/// \param str Data to copy.
/// \param size Maximal number of bytes to copy.
/// \return Number of bytes copied - the new length of this string.
UInt32 setData(const char* data, UInt32 size) noexcept{
char* arr = this->data();
UInt32 i = 0;
auto maxLen = std::min(maxSize(), size);
for ( ; i < maxLen && *data; i++, data++){
arr[i] = *data;
}
#if defined(TWPP_DETAIL_OS_MAC)
*reinterpret_cast<unsigned char*>(this->array()) = static_cast<unsigned char>(i);
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
arr[i] = '\0';
#else
# error "String::setData for your platform here"
#endif
return i;
}
/// Sets string data.
/// Copies as much data as possible, discarding the rest.
/// The string must be null terminated.
/// \param str String to copy.
/// \return Number of characters copied - the new length of this string.
UInt32 setData(const char* str) noexcept{
return setData(str, maxSize());
}
/// Sets string data from container (e.g. std::string).
/// Copies as much data as possible, discarding the rest.
/// The string needn't be null terminated.
/// \tparam Contaier Container type.
/// \param cont Container with data to be copied.
/// \return Number of characters copied - the new length of this string.
template<typename Container, typename = typename std::enable_if<std::is_same<typename Container::value_type, char>::value>::type>
UInt32 setData(const Container& cont) noexcept{
return setData(cont.data(), static_cast<UInt32>(std::min<typename Container::size_type>(cont.size(), maxSize())));
}
char operator[](UInt32 i) const noexcept{
return data()[i];
}
char& operator[](UInt32 i) noexcept{
return data()[i];
}
iterator begin() noexcept{
return data();
}
constexpr const_iterator begin() const noexcept{
return cbegin();
}
constexpr const_iterator cbegin() const noexcept{
return data();
}
iterator end() noexcept{
return data() + length();
}
constexpr const_iterator end() const noexcept{
return cend();
}
constexpr const_iterator cend() const noexcept{
return data() + length();
}
std::string string() const{
return std::string(cbegin(), cend());
}
};
}
template<std::size_t sizeA, std::size_t sizeB>
constexpr bool operator==(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
// length() is O(1) on mac os, O(n) anywhere else
#if defined(TWPP_DETAIL_OS_MAC)
return a.length() == b.length() && Detail::strCmp(a.data(), b.data()) == 0;
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
return Detail::strCmp(a.data(), b.data()) == 0;
#else
# error "String equals operator for your platform here"
#endif
}
template<std::size_t sizeA, std::size_t sizeB>
constexpr bool operator<(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
return Detail::strCmp(a.data(), b.data()) < 0;
}
template<std::size_t sizeA, std::size_t sizeB>
constexpr bool operator>(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
return Detail::strCmp(a.data(), b.data()) > 0;
}
template<std::size_t sizeA, std::size_t sizeB>
constexpr bool operator!=(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
return !(a == b);
}
template<std::size_t sizeA, std::size_t sizeB>
constexpr bool operator<=(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
return !(a > b);
}
template<std::size_t sizeA, std::size_t sizeB>
constexpr bool operator>=(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
return !(a < b);
}
/// TWAIN string that can contain up to 33 characters (bytes).
typedef Detail::Str<34> Str32;
/// TWAIN string that can contain up to 65 characters (bytes).
typedef Detail::Str<66> Str64;
/// TWAIN string that can contain up to 129 characters (bytes).
typedef Detail::Str<130> Str128;
/// TWAIN string that can contain up to 255 characters (bytes).
typedef Detail::Str<256> Str255;
}
#endif // TWPP_DETAIL_FILE_STRINGS_HPP

View File

@ -0,0 +1,17 @@
#ifndef TWGLUE_HPP
#define TWGLUE_HPP
#include <functional>
// #include "Device/PublicFunc.h"
struct TwGlue {
TwGlue(const std::function<void(const GScanCap&)>& scan, const std::function<void()>& cancel) :
m_scan(scan), m_cancel(cancel){}
std::function<void(const GScanCap&)> m_scan;
std::function<void()> m_cancel;
};
#endif // TWGLUE_HPP

View File

@ -0,0 +1,88 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_TYPES_HPP
#define TWPP_DETAIL_FILE_TYPES_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
typedef std::uintptr_t UIntPtr;
typedef std::uint8_t UInt8;
typedef std::uint16_t UInt16;
typedef std::uint32_t UInt32;
typedef std::int8_t Int8;
typedef std::int16_t Int16;
typedef std::int32_t Int32;
/// Boolean value.
/// Implemented as a class to provide better type safety.
class Bool {
public:
constexpr Bool(bool value = false) noexcept :
m_value(value){}
constexpr operator bool() const noexcept{
return m_value != 0;
}
private:
Int16 m_value;
};
/// Handle to memory area.
/// Implemented as a class to provide better type safety.
class Handle {
public:
typedef Detail::RawHandle Raw;
constexpr explicit Handle(Raw raw = Raw()) noexcept :
m_raw(raw){}
/// Underlying OS-dependent handle.
constexpr Raw raw() const noexcept{
return m_raw;
}
constexpr operator bool() const noexcept{
return m_raw != Raw();
}
private:
Raw m_raw;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_TYPES_HPP

View File

@ -0,0 +1,149 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_TYPESOPS_HPP
#define TWPP_DETAIL_FILE_TYPESOPS_HPP
#include "../twpp.hpp"
namespace Twpp {
/// Enumeration representing basic types.
enum class Type : UInt16 {
DontCare = 0xFFFF,
Int8 = 0x0000,
Int16 = 0x0001,
Int32 = 0x0002,
UInt8 = 0x0003,
UInt16 = 0x0004,
UInt32 = 0x0005,
Bool = 0x0006,
Fix32 = 0x0007,
Frame = 0x0008,
Str32 = 0x0009,
Str64 = 0x000a,
Str128 = 0x000b,
Str255 = 0x000c,
Handle = 0x000f
};
/// Whether the enum value actually is a type, DontCare is not a type.
static inline bool isType(Type type){
switch (type){
case Type::Int8:
case Type::UInt8:
case Type::Int16:
case Type::UInt16:
case Type::Int32:
case Type::UInt32:
case Type::Bool:
case Type::Fix32:
case Type::Str32:
case Type::Str64:
case Type::Str128:
case Type::Str255:
case Type::Frame:
case Type::Handle:
return true;
default:
return false;
}
}
/// Size in bytes of a type represented by enum value.
static inline UInt32 typeSize(Type type){
switch (type){
case Type::Int8: return sizeof(Int8);
case Type::UInt8: return sizeof(UInt8);
case Type::Int16: return sizeof(Int16);
case Type::UInt16: return sizeof(UInt16);
case Type::Int32: return sizeof(Int32);
case Type::UInt32: return sizeof(UInt32);
case Type::Bool: return sizeof(Bool);
case Type::Fix32: return sizeof(Fix32);
case Type::Str32: return sizeof(Str32);
case Type::Str64: return sizeof(Str64);
case Type::Str128: return sizeof(Str128);
case Type::Str255: return sizeof(Str255);
case Type::Frame: return sizeof(Frame);
case Type::Handle: return sizeof(Handle);
default: throw TypeException();
}
}
namespace Detail {
/// Conversion from Type enum to actual data type.
template<Type type> struct Twty {};
template<> struct Twty<Type::Int8> {typedef Int8 Type;};
template<> struct Twty<Type::Int16> {typedef Int16 Type;};
template<> struct Twty<Type::Int32> {typedef Int32 Type;};
template<> struct Twty<Type::UInt8> {typedef UInt8 Type;};
template<> struct Twty<Type::UInt16> {typedef UInt16 Type;};
template<> struct Twty<Type::UInt32> {typedef UInt32 Type;};
template<> struct Twty<Type::Bool> {typedef Bool Type;};
template<> struct Twty<Type::Fix32> {typedef Fix32 Type;};
template<> struct Twty<Type::Frame> {typedef Frame Type;};
template<> struct Twty<Type::Str32> {typedef Str32 Type;};
template<> struct Twty<Type::Str64> {typedef Str64 Type;};
template<> struct Twty<Type::Str128> {typedef Str128 Type;};
template<> struct Twty<Type::Str255> {typedef Str255 Type;};
template<> struct Twty<Type::Handle> {typedef Handle Type;};
// Conversion from data type to Type enum helpers.
template<typename DataType> struct Tytw;
template<typename DataType, bool isEnum> // true
struct TytwHelper : Tytw<typename std::underlying_type<DataType>::type> {};
template<typename DataType>
struct TytwHelper<DataType, false> {};
/// Conversion from data type to Type enum.
template<typename DataType> struct Tytw : TytwHelper<DataType, std::is_enum<DataType>::value> {};
template<> struct Tytw<Int8> {static constexpr const Type twty = Type::Int8;};
template<> struct Tytw<Int16> {static constexpr const Type twty = Type::Int16;};
template<> struct Tytw<Int32> {static constexpr const Type twty = Type::Int32;};
template<> struct Tytw<UInt8> {static constexpr const Type twty = Type::UInt8;};
template<> struct Tytw<UInt16> {static constexpr const Type twty = Type::UInt16;};
template<> struct Tytw<UInt32> {static constexpr const Type twty = Type::UInt32;};
template<> struct Tytw<Bool> {static constexpr const Type twty = Type::Bool;};
template<> struct Tytw<Fix32> {static constexpr const Type twty = Type::Fix32;};
template<> struct Tytw<Frame> {static constexpr const Type twty = Type::Frame;};
template<> struct Tytw<Str32> {static constexpr const Type twty = Type::Str32;};
template<> struct Tytw<Str64> {static constexpr const Type twty = Type::Str64;};
template<> struct Tytw<Str128> {static constexpr const Type twty = Type::Str128;};
template<> struct Tytw<Str255> {static constexpr const Type twty = Type::Str255;};
template<> struct Tytw<Handle> {static constexpr const Type twty = Type::Handle;};
}
}
#endif // TWPP_DETAIL_FILE_TYPESOPS_HPP

View File

@ -0,0 +1,79 @@
/*
The MIT License (MIT)
Copyright (c) 2015-2017 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_USERINTERFACE_HPP
#define TWPP_DETAIL_FILE_USERINTERFACE_HPP
#include "../twpp.hpp"
namespace Twpp {
TWPP_DETAIL_PACK_BEGIN
/// Structure holding parameters for enabling or disabling data source.
class UserInterface {
public:
/// Creates a new UserInterface.
/// \param showUi Whether to show internal DS GUI. Disabling DS GUI might not be supported.
/// \param modalUi Whether DS GUI should be modal. Not used on Linux. Might not be supported on Windows.
/// \param parent Windows-only, others set to null. Handle to parent window. This object does NOT take ownership.
#if defined(TWPP_DETAIL_OS_WIN)
constexpr UserInterface(Bool showUi, Bool modalUi, Handle parent) noexcept :
m_showUi(showUi), m_modalUi(modalUi), m_parent(parent){}
#elif defined(TWPP_DETAIL_OS_MAC) || defined(TWPP_DETAIL_OS_LINUX)
constexpr UserInterface(Bool showUi, Bool modalUi, Handle parent = Handle()) noexcept :
m_showUi(showUi), m_modalUi(modalUi), m_parent(parent){}
#else
# error "UserInterface constructor for your platform here"
#endif
/// Whether to show internal DS GUI.
constexpr Bool showUi() const noexcept{
return m_showUi;
}
/// Whether DS GUI should be modal
constexpr Bool modalUi() const noexcept{
return m_modalUi;
}
/// Handle to parent window.
constexpr Handle parent() const noexcept{
return m_parent;
}
private:
Bool m_showUi;
Bool m_modalUi;
Handle m_parent;
};
TWPP_DETAIL_PACK_END
}
#endif // TWPP_DETAIL_FILE_USERINTERFACE_HPP

View File

@ -0,0 +1,485 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Richter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TWPP_DETAIL_FILE_UTILS_HPP
#define TWPP_DETAIL_FILE_UTILS_HPP
#undef max
#undef min
#include <limits>
#include "../twpp.hpp"
namespace Twpp {
namespace Detail {
/// Creates a template for testing whether a class contains public static method.
/// Use this macro anywhere a class may be defined, and pass method name
/// as its parameter. Then use `HasStaticMethod_<your-method-name>` template.
///
/// E. g.:
/// TWPP_DETAIL_CREATE_HAS_STATIC_METHOD(myMethod) // <- semicolon not required
/// HasStaticMethod_myMethod<MyClass, void(int, char)>::value
///
/// This test whether `MyClass` has static method `void MyClass::myMethod(int, char)`.
/// That is whether you may do this:
/// MyClass::myMethod(10, 'a');
#define TWPP_DETAIL_CREATE_HAS_STATIC_METHOD(methodName) \
template<typename T, typename Fn>\
class HasStaticMethod_ ## methodName;\
\
template<typename T, typename Ret, typename... Args>\
class HasStaticMethod_ ## methodName <T, Ret(Args...)> {\
\
template<typename U>\
static constexpr auto test(U*) ->\
typename std::is_same<decltype(U::methodName(std::declval<Args>()...)), Ret>::type;\
\
template<typename>\
static constexpr std::false_type test(...);\
\
public:\
typedef decltype(test<T>(0)) type;\
static constexpr const bool value = type::value;\
\
};
/// Creates a template for testing whether a class contains public method.
/// Use this macro anywhere a class may be defined, and pass method name
/// as its parameter. Then use `HasMethod_<your-method-name>` template.
///
/// E. g.:
/// TWPP_DETAIL_CREATE_HAS_METHOD(myMethod) // <- semicolon not required
/// HasMethod_myMethod<MyClass, void(int, char)>::value
///
/// This test whether `MyClass` has method (AKA member function) `void MyClass::myMethod(int, char)`.
/// That is whether you may do this:
/// MyClass o ... ;
/// o.myMethod(10, 'a');
#define TWPP_DETAIL_CREATE_HAS_METHOD(methodName) \
template<typename T, typename Fn>\
class HasMethod_ ## methodName;\
\
template<typename T, typename Ret, typename... Args>\
class HasMethod_ ## methodName <T, Ret(Args...)> {\
\
template<typename U>\
static constexpr auto test(U*) ->\
typename std::is_same<decltype(std::declval<U>().methodName(std::declval<Args>()...)), Ret>::type;\
\
template<typename>\
static constexpr std::false_type test(...);\
\
public:\
typedef decltype(test<T>(0)) type;\
static constexpr const bool value = type::value;\
\
};
/// Performs a pointer type cast, suppresses strict aliasing warnings.
/// \tparam T Type of the returned pointer. Must be pointer type (e.g. `char*`).
/// \param ptr Pointer to be cast.
/// \return Cast pointer.
template<typename T>
static constexpr inline T alias_cast(void* ptr) noexcept{
return reinterpret_cast<T>(ptr);
}
/// Performs a constant pointer type cast, suppresses strict aliasing warnings.
/// \tparam T Type of the returned pointer. Must be pointer type (e.g. `char*`).
/// \param ptr Pointer to be cast.
/// \return Cast pointer.
template<typename T>
static constexpr inline T alias_cast(const void* ptr) noexcept{
return reinterpret_cast<T>(ptr);
}
/// Suppresses warnings about unused parameters or arguments.
/// \tparam Args List of argument types. No need to specify explicitly.
template<typename... Args>
static inline void unused(const Args& ...) noexcept{}
// CODE FROM http://www.macieira.org/blog/2011/07/initialising-an-array-with-cx0x-using-constexpr-and-variadic-templates/
// BEGIN
template<std::size_t... Idx> struct IndexList {};
template<typename IndexList, std::size_t Right> struct Append;
template<std::size_t... Left, std::size_t Right>
struct Append<IndexList<Left...>, Right>{ typedef IndexList<Left..., Right> Result; };
template<std::size_t N> struct Indexes {
typedef typename Append<typename Indexes<N - 1>::Result, N - 1>::Result Result;
};
template<> struct Indexes<0> { typedef IndexList<> Result; };
// END
/// Converts an array of arbitary size to array-like recursive structure of fixed size (at compile time).
/// Provide template specialization if special handling of elements is required, and you do care
/// about their positions - otherwise see FixedArrayData below.
/// \tparam T Element type.
/// \tparam arraySize Number of elements in the fixed array.
template<typename T, std::size_t arraySize>
struct FixedArrayFlat : FixedArrayFlat<T, arraySize - 1> {
/// The index this structure (with this `arraySize`) holds.
static constexpr const std::size_t g_index = arraySize - 1;
/// Performs the conversion from arbiraty-size array to fixed-size structure.
/// We use left recursion to initialize values of all inherited structures first.
/// Then the value of this one is initialized, either copied from the input array itself,
/// or default-initialized in case the array is not large enough.
/// \tparam inputSize {Size of the input array. If smaller than the fixed array,
/// excessive elements are default-initialized (may be changed in specializations).
/// Providing larger array results in undefined behaviour.}
/// \param arr The arbitary-size array.
template<std::size_t inputSize>
constexpr inline FixedArrayFlat(const T(& arr)[inputSize]) noexcept :
FixedArrayFlat<T, g_index>(arr), m_val(g_index < inputSize ? arr[g_index] : T()){}
/// Returns value contained at specific index.
/// If the index if smaller than the size of the input array, a value is returned
/// as if the operation was performed on that array. Otherwise a default value
/// of the type `T` is returned (or anything else a specialization provides).
/// Behaviour of this operator is undefined if the index equals to or is greater than
/// the size of the fixed array.
/// \param i Value index.
/// \return Value at index.
constexpr inline T operator[](std::size_t i) const noexcept{
return i == g_index ? m_val : FixedArrayFlat<T, g_index>::operator [](i);
}
/// Value held by this structure.
T m_val;
};
/// Converts an array of arbitary size to array-like recursive structure of fixed size (at compile time).
/// This template specialization terminates the recursion.
/// No need to provide any further specializations.
/// \tparam T Element type.
template<typename T>
struct FixedArrayFlat<T, 0> {
template<std::size_t inputSize>
constexpr inline FixedArrayFlat(const T(&)[inputSize]) noexcept{}
constexpr inline T operator[](std::size_t) const noexcept{
return T();
}
};
/// Converts an array of arbitary size to array of fixed size at compile time.
/// The job itself is done in the specialization below.
/// \tparam T Element type.
/// \tparam arraySize Number of elements in the fixed array.
/// \tparam IndexList Type holding indexes of the fixed array.
template<typename T, std::size_t arraySize, typename IndexList>
struct FixedArrayData {};
/// Converts an array of arbitary size to array of fixed size at compile time.
/// Provide template specialization if special handling of elements is required, and you
/// don't care about their positions.
/// \tparam T Element type.
/// \tparam arraySize Number of elements in the fixed array.
/// \tparam i Indexes of the fixed array.
template<typename T, std::size_t arraySize, std::size_t... i>
struct FixedArrayData<T, arraySize, IndexList<i...> > {
/// Performs the conversion from arbiraty-size array to fixed-size array.
/// Uses FixedArrayFlat to extend the input array to desired size.
/// \tparam inputSize Size of the input array.
/// \param arr The input array.
template<std::size_t inputSize>
constexpr FixedArrayData(const T(& arr)[inputSize]) noexcept :
m_arr{FixedArrayFlat<T, arraySize>(arr)[i]...}{}
/// Creates default-initialized array.
constexpr FixedArrayData() noexcept :
m_arr(){}
/// The fixed array.
T m_arr[arraySize];
};
/// Compile-time constructible fixed-size array of type `T` and length `arraySize`.
/// The array can be constructed from variable-sized array
/// of up to `arraySize` elements at compile time.
/// \tparam T Element type.
/// \tparam arraySize Number of elements in the array.
template<typename T, std::size_t arraySize>
struct FixedArray : public FixedArrayData<T, arraySize, typename Indexes<arraySize>::Result> {
typedef FixedArrayData<T, arraySize, typename Indexes<arraySize>::Result> ParentType;
typedef T Array[arraySize];
/// Creates default-initialized array.
constexpr FixedArray() noexcept :
ParentType(){}
/// Creates fixed-size array from variable-size array at compile time.
/// If the size of input array exceeds `arraySize`, a compile-time error is emited.
/// \tparam inputSize Number of elements of the input array.
/// \param arr The input array.
template<std::size_t inputSize>
constexpr FixedArray(const T(& arr)[inputSize]) noexcept :
ParentType(arr){
static_assert(inputSize <= arraySize, "array literal is too big");
}
/// The contained array.
constexpr const Array& array() const noexcept{
return ParentType::m_arr;
}
/// The contained array.
Array& array() noexcept{
return ParentType::m_arr;
}
};
/// Joins two arrays at compile time.
/// The job itself is done in the specialization below.
/// \tparam T Element type.
/// \tparam lenA Size of the first array.
/// \tparam lenB Size of the second array.
/// \tparam IndexList Type holding indexes of the resulting array.
template<typename T, std::size_t lenA, std::size_t lenB, typename IndexList>
struct ArrayJoinData {};
/// Joins two arrays at compile time.
/// The result of this operation is an array that contains all the elements
/// from the first array immediately followed by all the elements from
/// the second array.
/// \tparam T Element type.
/// \tparam lenA Size of the first array.
/// \tparam lenB Size of the second array.
/// \tparam i Indexes of the resulting array.
template<typename T, std::size_t lenA, std::size_t lenB, std::size_t... i>
struct ArrayJoinData<T, lenA, lenB, IndexList<i...> > {
/// Performs the join operation.
/// \param a The first array.
/// \param b The second array.
constexpr ArrayJoinData(const T(& a)[lenA], const T(& b)[lenB]) noexcept :
m_arr{(i < lenA ? a[i] : b[i - lenA])...}{}
/// The resulting array.
T m_arr[lenA + lenB];
};
/// Compile-time join operation of two arrays of the same type.
/// \tparam T Element type.
/// \tparam lenA Size of the first array.
/// \tparam lenB Size of the second array.
template<typename T, std::size_t lenA, std::size_t lenB>
struct ArrayJoin : public ArrayJoinData<T, lenA, lenB, typename Indexes<lenA + lenB>::Result> {
typedef ArrayJoinData<T, lenA, lenB, typename Indexes<lenA + lenB>::Result> ParentType;
typedef T Array[lenA + lenB];
/// Performs the join operation.
/// \param a The first array.
/// \param b The second array.
constexpr ArrayJoin(const T(& a)[lenA], const T(& b)[lenB]) noexcept :
ParentType(a, b){}
/// The joined array.
constexpr const Array& array() const noexcept{
return ParentType::m_arr;
}
/// The joined array.
Array& array() noexcept{
return ParentType::m_arr;
}
};
/// Performs compile-time array join operation.
/// This is a helper function, see ArrayJoin and ArrayJoinData for more info.
/// \tparam T Element type.
/// \tparam lenA Size of the first array.
/// \tparam lenB Size of the second array.
/// \param a The first array.
/// \param b The second array.
/// \return The joined array.
template<typename T, std::size_t lenA, std::size_t lenB>
static constexpr inline ArrayJoin<T, lenA, lenB> arrayJoin(const T(& a)[lenA], const T(& b)[lenB]) noexcept{
return {a, b};
}
/// The loop that checks the suffix at compile time, see endsWith below.
/// Checks are performed from right to left.
/// \tparam T Element type.
/// \tparam arrLen The size of the array to be checked for the suffix.
/// \tparam subLen The size of the suffix array.
/// \param arr The array to be checked for the suffix.
/// \param sub The suffix array.
/// \param endOff Offset from the last element to be checked in this call.
/// \return Whether the suffix is contained.
template<typename T, std::size_t arrLen, std::size_t subLen>
static constexpr inline bool endsWithLoop(const T(& arr)[arrLen], const T(& sub)[subLen], std::size_t endOff){
return endOff >= subLen || (arr[arrLen - 1 - endOff] == sub[subLen - 1 - endOff] && endsWithLoop(arr, sub, endOff + 1));
}
/// Checks whether the input array contains supplied suffix at compile time.
/// \tparam T Element type.
/// \tparam arrLen The size of the array to be checked for the suffix.
/// \tparam subLen The size of the suffix array.
/// \param arr The array to be checked for the suffix.
/// \param sub The suffix array.
/// \return Whether the suffix is contained.
template<typename T, std::size_t arrLen, std::size_t subLen>
static constexpr inline bool endsWith(const T(& arr)[arrLen], const T(& sub)[subLen]){
return arrLen >= subLen && endsWithLoop(arr, sub, 0);
}
/// Implementation of compile-time C string length.
/// Uses tail recursion.
/// \param str The string, or its remaining part.
/// \param len Length of the previous, already processed, part of the string.
/// \return Length of the string.
static constexpr inline std::size_t strLenImpl(const char* str, std::size_t len = 0) noexcept{
return *str == '\0' ? len : strLenImpl(str + 1, len + 1);
}
/// Compile-time C string length.
/// \param str The string.
/// \return Length of the string.
static constexpr inline std::size_t strLen(const char* str) noexcept{
return strLenImpl(str);
}
/// Unsigned to signed conversion, using static_cast.
/// Available only if integers are represented using 2 complement.
/// Specialization handles non-2 complement cases.
/// \tparam T An integral type.
/// \tparam _2complement Whether ints are represented as 2 complement.
template<typename T, bool _2complement> // true
struct UnsigToSig {
typedef typename std::make_signed<T>::type Signed;
typedef typename std::make_unsigned<T>::type Unsigned;
static constexpr Signed convert(Unsigned val) noexcept{
return static_cast<Signed>(val);
}
};
/// Unsigned to signed conversion.
/// This specialization is used when architecture does not use 2 complement.
/// \tparam T An integral type.
template<typename T>
struct UnsigToSig<T, false> {
typedef typename std::make_signed<T>::type Signed;
typedef typename std::make_unsigned<T>::type Unsigned;
static constexpr Signed convert(Unsigned val) noexcept{
return val <= std::numeric_limits<Signed>::max() ?
static_cast<Signed>(val) :
static_cast<Signed>(val - std::numeric_limits<Signed>::min()) + std::numeric_limits<Signed>::min();
}
};
/// Converts, at compile time, an unsigned integer to its signed counterpart.
/// This holds true: unsignedValue == static_cast<unsigned type>(unsignedToSigned(unsignedValue))
/// \tparam T Unsigned integral type.
/// \param val Unsigned value to be converted to signed.
/// \return Signed value that can be converted back to its unsigned type.
template<typename T, typename = typename std::enable_if<std::is_unsigned<T>::value>::type>
static constexpr inline typename std::make_signed<T>::type unsignedToSigned(T val) noexcept{
typedef typename std::make_signed<T>::type Signed;
typedef typename std::make_unsigned<T>::type Unsigned;
return UnsigToSig<T, static_cast<Signed>(-1) == static_cast<Signed>(~Unsigned(0))>::convert(val);
}
/// Compares two C strings at compile time as if strcmp was used.
/// \param a First string.
/// \param b Second string.
/// \return See strcmp.
static constexpr inline int strCmp(const char* a, const char* b) noexcept{
return *a != *b ? (static_cast<int>(*a) - *b) : (*a == '\0' ? 0 : strCmp(a + 1, b + 1));
}
/// Absolute value.
/// Default implementation handles signed values
/// of non-integral types.
/// \tparam T Data type.
/// \tparam integral Whether the type is integral.
/// \tparam unsig Whether the data type is unsigned.
template<typename T, bool integral, bool unsig> // false, false
struct Abs {
static constexpr inline T abs(T a) noexcept{
return a >= T() ? a : -a;
}
};
/// Absolute value.
/// This handles signed values of integral types.
/// \tparam T Data type.
template<typename T>
struct Abs<T, true, false> {
static constexpr inline T abs(T a) noexcept{
return std::abs(a);
}
};
/// Absolute value.
/// This handles unsigned values.
/// \tparam T Data type.
template<typename T, bool integral>
struct Abs<T, integral, true> {
static constexpr inline T abs(T a) noexcept{
return a;
}
};
/// Absolute value.
/// Handles anything that has `bool operator >=(const T&)` (or equiv.),
/// `T operator-()`, and its default value represents `zero`.
/// \tparam T Data type.
/// \param a Value.
template<typename T>
static constexpr inline T abs(T a) noexcept{
return Abs<T, std::is_integral<T>::value, std::is_unsigned<T>::value>::abs(a);
}
}
}
#endif // TWPP_DETAIL_FILE_UTILS_HPP

77
huagaotwain/ui.cpp Normal file
View File

@ -0,0 +1,77 @@
#include "pch.h"
#include "ui.h"
#include "huagaotwain.h" // for sane_invoker::load_dll
twain_ui::twain_ui(const wchar_t* path) : path_(path), dll_(NULL)
, show_(NULL), hide_(NULL), event_(NULL), hui_(NULL)
, good_(false)
{
good_ = load();
}
twain_ui::~twain_ui()
{
if (hui_ && hide_)
hide_(hui_);
if (dll_)
FreeLibrary(dll_);
}
bool twain_ui::load()
{
std::wstring dll(path_ + L"\\huagaoui.dll");
sane_invoker::load_dll(dll.c_str(), &dll_);
if (!dll_)
return false;
show_ = (ui_show_api)GetProcAddress(dll_, "ui_show");
hide_ = (ui_hide_api)GetProcAddress(dll_, "ui_hide");
event_ = (handle_event_api)GetProcAddress(dll_, "handle_event");
return show_ && hide_ && event_;
}
void twain_ui::show_main_ui(LPSANEAPI api)
{
type_ = UITYPE::UI_MAIN;
if (show_)
hui_ = show_(UITYPE::UI_MAIN, api);
}
void twain_ui::show_setting_ui(LPSANEAPI api, bool with_scan)
{
if (show_)
{
type_ = with_scan ? UITYPE::UI_SETTING_AND_SCAN : UITYPE::UI_SETTING;
hui_ = show_(type_, api);
}
}
void twain_ui::show_progress_ui(LPSANEAPI api)
{
type_ = UITYPE::UI_PROGRESS;
if (show_)
hui_ = show_(UITYPE::UI_PROGRESS, api);
}
void twain_ui::hide_ui(void)
{
if (hui_ && hide_)
hide_(hui_);
hui_ = NULL;
}
void twain_ui::handle_sane_event(int sane_ev, void* data, unsigned int* len)
{
if (event_)
event_((SANE_Event)sane_ev, data, len);
}
bool twain_ui::is_ok(void)
{
return good_;
}
bool twain_ui::is_progress_ui_showing(void)
{
return type_ == UITYPE::UI_PROGRESS;
}

34
huagaotwain/ui.h Normal file
View File

@ -0,0 +1,34 @@
#pragma once
#include <Windows.h>
#include <string>
#include "huagao/huagao_ui.h"
class twain_ui
{
HMODULE dll_;
ui_show_api show_;
ui_hide_api hide_;
handle_event_api event_;
ui_handle hui_;
std::wstring path_;
bool good_;
UITYPE type_;
bool load(void);
public:
twain_ui(const wchar_t* path);
~twain_ui();
public:
void show_main_ui(LPSANEAPI api);
void show_setting_ui(LPSANEAPI api, bool with_scan);
void show_progress_ui(LPSANEAPI api);
void hide_ui(void);
void handle_sane_event(int sane_ev, void* data, unsigned int* len);
bool is_ok(void);
bool is_progress_ui_showing(void);
};

222
protocol/hgsane.vcxproj Normal file
View File

@ -0,0 +1,222 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{6eec8a02-7f98-4422-8ed6-2434d43bd1e1}</ProjectGuid>
<RootNamespace>hgsane</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>hgsane</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)..\..\sdk\include;$(SolutionDir)..\..\device\include\;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\;$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)..\..\sdk\include;$(SolutionDir)..\..\device\include\;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\;$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>$(SolutionDir)..\..\sdk\include;$(SolutionDir)..\..\device\include\;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>$(SolutionDir)..\..\sdk\include;$(SolutionDir)..\..\device\include\;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>BACKEND_NAME=hgsane;TWPP_IS_DS;EXPORT_SANE_API;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>$(ProjectDir)sane.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>BACKEND_NAME=hgsane;TWPP_IS_DS;EXPORT_SANE_API;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>$(ProjectDir)sane.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)
move /Y "$(OutDirFullPath)$(ProjectName).exp" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).lib" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)"
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\device\hgdriver\wrapper\hg_log.cpp" />
<ClCompile Include="..\..\device\hgsane\cJSON.c" />
<ClCompile Include="..\..\device\hgsane\ini_file.cpp" />
<ClCompile Include="..\..\device\hgsane\json.cpp" />
<ClCompile Include="..\..\device\hgsane\main.c" />
<ClCompile Include="..\..\device\hgsane\sane_hg_mdw.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\device\hgsane\cJSON.h" />
<ClInclude Include="..\..\device\hgsane\ini_file.h" />
<ClInclude Include="..\..\device\hgsane\json.h" />
<ClInclude Include="..\..\device\hgsane\sane_hg_mdw.h" />
<ClInclude Include="..\..\sdk\include\huagao\hgscanner_error.h" />
<ClInclude Include="..\..\device\sdk\hginclude\hg_log.h" />
<ClInclude Include="..\..\device\sdk\hginclude\huagaoxxx_warraper_ex.h" />
<ClInclude Include="..\..\sdk\include\sane\sane.h" />
<ClInclude Include="..\..\sdk\include\sane\sanei.h" />
<ClInclude Include="..\..\sdk\include\sane\sanei_backend.h" />
<ClInclude Include="..\..\sdk\include\sane\sanei_debug.h" />
<ClInclude Include="..\..\sdk\include\sane\sane_ex.h" />
</ItemGroup>
<ItemGroup>
<None Include="sane.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\device\hgsane\cJSON.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgsane\ini_file.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgsane\json.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgsane\main.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgsane\sane_hg_mdw.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\..\device\hgdriver\wrapper\hg_log.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\device\hgsane\cJSON.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgsane\ini_file.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgsane\json.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\device\hgsane\sane_hg_mdw.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sane.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sane_ex.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sanei.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sanei_backend.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sanei_debug.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\device\sdk\hginclude\hg_log.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\huagao\hgscanner_error.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\device\sdk\hginclude\huagaoxxx_warraper_ex.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="sane.def">
<Filter>源文件</Filter>
</None>
</ItemGroup>
</Project>

Some files were not shown because too many files have changed in this diff Show More