-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathTwainDefs.cs
3807 lines (3335 loc) · 136 KB
/
TwainDefs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Этот файл является частью библиотеки Saraff.Twain.NET
* © SARAFF SOFTWARE (Кирножицкий Андрей), 2011.
* Saraff.Twain.NET - свободная программа: вы можете перераспространять ее и/или
* изменять ее на условиях Меньшей Стандартной общественной лицензии GNU в том виде,
* в каком она была опубликована Фондом свободного программного обеспечения;
* либо версии 3 лицензии, либо (по вашему выбору) любой более поздней
* версии.
* Saraff.Twain.NET распространяется в надежде, что она будет полезной,
* но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
* или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Меньшей Стандартной
* общественной лицензии GNU.
* Вы должны были получить копию Меньшей Стандартной общественной лицензии GNU
* вместе с этой программой. Если это не так, см.
* <http://www.gnu.org/licenses/>.)
*
* This file is part of Saraff.Twain.NET.
* © SARAFF SOFTWARE (Kirnazhytski Andrei), 2011.
* Saraff.Twain.NET is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Saraff.Twain.NET is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with Saraff.Twain.NET. If not, see <http://www.gnu.org/licenses/>.
*
* PLEASE SEND EMAIL TO: [email protected].
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Drawing;
namespace Saraff.Twain {
#region Generic Constants
/// <summary>
/// Data Groups.
/// </summary>
[Flags]
internal enum TwDG : uint { // DG_.....
/// <summary>
/// Data pertaining to control.
/// </summary>
Control = 0x0001,
/// <summary>
/// Data pertaining to raster images.
/// </summary>
Image = 0x0002,
/// <summary>
/// Data pertaining to audio.
/// </summary>
Audio = 0x0004,
/// <summary>
/// added to the identity by the DSM.
/// </summary>
DSM2 = 0x10000000,
/// <summary>
/// Set by the App to indicate it would prefer to use DSM2.
/// </summary>
APP2 = 0x20000000,
/// <summary>
/// Set by the DS to indicate it would prefer to use DSM2.
/// </summary>
DS2 = 0x40000000
}
/// <summary>
/// Data codes.
/// </summary>
internal enum TwDAT : ushort { // DAT_....
#region Data Argument Types for the DG_CONTROL Data Group.
Null = 0x0000,
Capability = 0x0001,
Event = 0x0002,
Identity = 0x0003,
Parent = 0x0004,
PendingXfers = 0x0005,
SetupMemXfer = 0x0006,
SetupFileXfer = 0x0007,
Status = 0x0008,
UserInterface = 0x0009,
XferGroup = 0x000a,
TwunkIdentity = 0x000b,
CustomDSData = 0x000c,
DeviceEvent = 0x000d,
FileSystem = 0x000e,
PassThru = 0x000f,
Callback = 0x0010, /* TW_CALLBACK Added 2.0 */
StatusUtf8 = 0x0011, /* TW_STATUSUTF8 Added 2.1 */
Callback2 = 0x0012,
#endregion
#region Data Argument Types for the DG_IMAGE Data Group.
ImageInfo = 0x0101,
ImageLayout = 0x0102,
ImageMemXfer = 0x0103,
ImageNativeXfer = 0x0104,
ImageFileXfer = 0x0105,
CieColor = 0x0106,
GrayResponse = 0x0107,
RGBResponse = 0x0108,
JpegCompression = 0x0109,
Palette8 = 0x010a,
ExtImageInfo = 0x010b,
#endregion
#region misplaced
IccProfile = 0x0401, /* TW_MEMORY Added 1.91 This Data Argument is misplaced but belongs to the DG_IMAGE Data Group */
ImageMemFileXfer = 0x0402, /* TW_IMAGEMEMXFER Added 1.91 This Data Argument is misplaced but belongs to the DG_IMAGE Data Group */
EntryPoint = 0x0403, /* TW_ENTRYPOINT Added 2.0 This Data Argument is misplaced but belongs to the DG_CONTROL Data Group */
#endregion
}
/// <summary>
/// Messages.
/// </summary>
internal enum TwMSG : ushort { // MSG_.....
#region Generic messages may be used with any of several DATs.
/// <summary>
/// Used in TW_EVENT structure.
/// </summary>
Null = 0x0000,
/// <summary>
/// Get one or more values.
/// </summary>
Get = 0x0001,
/// <summary>
/// Get current value.
/// </summary>
GetCurrent = 0x0002,
/// <summary>
/// Get default (e.g. power up) value.
/// </summary>
GetDefault = 0x0003,
/// <summary>
/// Get first of a series of items, e.g. DSs.
/// </summary>
GetFirst = 0x0004,
/// <summary>
/// Iterate through a series of items.
/// </summary>
GetNext = 0x0005,
/// <summary>
/// Set one or more values.
/// </summary>
Set = 0x0006,
/// <summary>
/// Set current value to default value.
/// </summary>
Reset = 0x0007,
/// <summary>
/// Get supported operations on the cap.
/// </summary>
QuerySupport = 0x0008,
GetHelp = 0x0009,
GetLabel = 0x000a,
GetLabelEnum = 0x000b,
SetConstraint = 0x000c,
#endregion
#region Messages used with DAT_NULL
XFerReady = 0x0101,
CloseDSReq = 0x0102,
CloseDSOK = 0x0103,
DeviceEvent = 0x0104,
#endregion
#region Messages used with a pointer to a DAT_STATUS structure
/// <summary>
/// Get status information
/// </summary>
CheckStatus = 0x0201,
#endregion
#region Messages used with a pointer to DAT_PARENT data
/// <summary>
/// Open the DSM
/// </summary>
OpenDSM = 0x0301,
/// <summary>
/// Close the DSM
/// </summary>
CloseDSM = 0x0302,
#endregion
#region Messages used with a pointer to a DAT_IDENTITY structure
/// <summary>
/// Open a data source
/// </summary>
OpenDS = 0x0401,
/// <summary>
/// Close a data source
/// </summary>
CloseDS = 0x0402,
/// <summary>
/// Put up a dialog of all DS
/// </summary>
UserSelect = 0x0403,
#endregion
#region Messages used with a pointer to a DAT_USERINTERFACE structure
/// <summary>
/// Disable data transfer in the DS
/// </summary>
DisableDS = 0x0501,
/// <summary>
/// Enable data transfer in the DS
/// </summary>
EnableDS = 0x0502,
/// <summary>
/// Enable for saving DS state only.
/// </summary>
EnableDSUIOnly = 0x0503,
#endregion
#region Messages used with a pointer to a DAT_EVENT structure
ProcessEvent = 0x0601,
#endregion
#region Messages used with a pointer to a DAT_PENDINGXFERS structure
EndXfer = 0x0701,
StopFeeder = 0x0702,
#endregion
#region Messages used with a pointer to a DAT_FILESYSTEM structure
ChangeDirectory = 0x0801,
CreateDirectory = 0x0802,
Delete = 0x0803,
FormatMedia = 0x0804,
GetClose = 0x0805,
GetFirstFile = 0x0806,
GetInfo = 0x0807,
GetNextFile = 0x0808,
Rename = 0x0809,
Copy = 0x080A,
AutoCaptureDir = 0x080B,
#endregion
#region Messages used with a pointer to a DAT_PASSTHRU structure
PassThru = 0x0901,
#endregion
#region used with DAT_CALLBACK
RegisterCallback = 0x0902,
#endregion
#region used with DAT_CAPABILITY
ResetAll = 0x0A01
#endregion
}
/// <summary>
/// Return Codes
/// </summary>
public enum TwRC : ushort { // TWRC_....
/// <summary>
/// Operation was successful.
/// </summary>
Success = 0x0000,
/// <summary>
/// May be returned by any operation. An error has occurred.
/// </summary>
Failure = 0x0001,
/// <summary>
/// Intended for use with DAT_CAPABILITY and DAT_IMAGELAYOUT.
/// Operation failed to completely perform
/// the desired operation. For example, setting ICAP_BRIGHTNESS to
/// 3 when its range is -1000 to 1000 with a step of 200. The data source
/// may opt to set the value to 0 and return this status.
/// </summary>
CheckStatus = 0x0002,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations. Operation has been canceled.
/// </summary>
Cancel = 0x0003,
/// <summary>
/// Intended for use with DAT_EVENT. The data source processed the event.
/// </summary>
DSEvent = 0x0004,
/// <summary>
/// Intended for use with DAT_EVENT. The data source did not process the event.
/// </summary>
NotDSEvent = 0x0005,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations. The image has been fully transferred.
/// </summary>
XferDone = 0x0006,
/// <summary>
/// Intended for use with DAT_IDENTITY and DAT_FILESYSTEM.
/// </summary>
EndOfList = 0x0007,
/// <summary>
/// Intended for use with DAT_EXTIMAGEINFO.
/// The requested TWEI_ data is either not supported by this data source, or is not supported for this particular image.
/// </summary>
InfoNotSupported = 0x0008,
/// <summary>
/// Intended for use with DAT_EXTIMAGEINFO. There is no data available for the requested TWEI_ item.
/// </summary>
DataNotAvailable = 0x0009,
/// <summary>
/// The busy.
/// </summary>
Busy = 10,
/// <summary>
/// The scanner locked.
/// </summary>
ScannerLocked = 11
}
/// <summary>
/// Condition Codes
/// </summary>
public enum TwCC : ushort { // TWCC_....
/// <summary>
/// Operation was successful. This value should only be paired with TWRC_SUCCESS.
/// </summary>
Success = 0x0000,
/// <summary>
/// May be returned by any operation. The data source is in a critical state.
/// </summary>
Bummer = 0x0001,
/// <summary>
/// May be returned for any operation except ones that reduce state
/// (DAT_PENDINGXFERS / MSG_ENDXER, DAT_PENDINGXFERS / MSG_RESET,
/// DAT_USERINTERFACE / MSG_DISABLEDS, DAT_IDENTITY / MSG_CLOSEDS,
/// DAT_PARENT / MSG_CLOSEDSM).
/// </summary>
LowMemory = 0x0002,
/// <summary>
/// Intended for use with DAT_IDENTITY / MSG_OPENDS. The device is not online.
/// </summary>
NoDS = 0x0003,
/// <summary>
/// Intended for use with DAT_IDENTITY / MSG_OPENDS. The data
/// source cannot support any more connections to this device.
/// </summary>
MaxConnections = 0x0004,
/// <summary>
/// The operation failed, but the user has already been informed by the data source.
/// </summary>
OperationError = 0x0005,
/// <summary>
/// Intended for use with DAT_CAPABILITY. Returned by pre-1.7
/// data sources to indicate that the capability is not supported, that the
/// value was bad, or that the desired value could not be set at this time.
/// </summary>
BadCap = 0x0006,
/// <summary>
/// May be returned by any operation. The requested
/// DG_* / DAT_* / MSG_* is not supported by the data source.
/// </summary>
BadProtocol = 0x0009,
/// <summary>
/// May be returned by any operation. The capability or operation has
/// rejected the requested setting.
/// </summary>
BadValue = 0x000a,
/// <summary>
/// The seq error.
/// </summary>
SeqError = 0x000b,
/// <summary>
/// May be returned by any operation (save for the DAT_PARENT
/// operations). The TW_IDENTITY for the destination (the data
/// source) does not match any items opened by MSG_OPENDS.
/// </summary>
BadDest = 0x000c,
/// <summary>
/// Intended for use with DAT_CAPABILITY. The capability is not supported.
/// </summary>
CapUnsupported = 0x000d,
/// <summary>
/// Intended for use with DAT_CAPABILITY. The capability does not support the requested operation.
/// </summary>
CapBadOperation = 0x000e,
/// <summary>
/// Intended for use with DAT_CAPABILITY. The capability being
/// MSG_SET or MSG_RESET cannot be modified due to a setting for a
/// related capability. For instance, this may be returned by
/// ICAP_CITTKFACTOR if ICAP_COMPRESSION is set to any value
/// other than TWCP_GROUP32D.
/// </summary>
CapSeqError = 0x000f,
/// <summary>
/// Intended for DAT_IMAGEFILEXFER and DAT_FILESYSTEM, the
/// specified file or directory cannot be modified or deleted.
/// </summary>
Denied = 0x0010,
/// <summary>
/// Intended for DAT_FILESYSTEM. The specified file or directory already exists.
/// </summary>
FileExists = 0x0011,
/// <summary>
/// Intended for DAT_IMAGEFILEXFER and DAT_FILESYSTEM. The
/// specified file or directory cannot be found.
/// </summary>
FileNotFound = 0x0012,
/// <summary>
/// Intended for use with DAT_FILESYSTEM. Directory is in use, and cannot be deleted.
/// </summary>
NotEmpty = 0x0013,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations.
/// </summary>
PaperJam = 0x0014,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations.
/// </summary>
PaperDoubleFeed = 0x0015,
/// <summary>
/// Intended for DAT_IMAGEFILEXFER and DAT_FILESYSTEM, the
/// specified file or directory could not be written, usually indicating a
/// disk full condition, though it may also indicate a file or directory
/// that the user has no permission to write.
/// </summary>
FileWriteError = 0x0016,
/// <summary>
/// May be returned for any operation in state 4 or higher, except ones
/// that reduce state (DAT_PENDINGXFERS / MSG_ENDXER,
/// DAT_PENDINGXFERS / MSG_RESET, DAT_USERINTERFACE / MSG_DISABLEDS,
/// DAT_IDENTITY / MSG_CLOSEDS, DAT_PARENT / MSG_CLOSEDSM).
/// </summary>
CheckDeviceOnline = 0x0017,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations.
/// </summary>
InterLock = 24,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations.
/// </summary>
DamagedCorner = 25,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations.
/// </summary>
FocusError = 26,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations.
/// </summary>
DocTooLight = 27,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations.
/// </summary>
DocTooDark = 28,
/// <summary>
/// Intended for use with the DAT_IMAGE*XFER operations.
/// </summary>
NoMedia = 29,
}
/// <summary>
/// Generic Constants
/// </summary>
internal enum TwOn : ushort { // TWON_....
/// <summary>
/// Indicates TW_ARRAY container
/// </summary>
Array = 0x0003,
/// <summary>
/// Indicates TW_ENUMERATION container
/// </summary>
Enum = 0x0004,
/// <summary>
/// Indicates TW_ONEVALUE container
/// </summary>
One = 0x0005,
/// <summary>
/// Indicates TW_RANGE container
/// </summary>
Range = 0x0006,
DontCare = 0xffff
}
/// <summary>
/// Data Types
/// </summary>
internal enum TwType : ushort { // TWTY_....
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,
Str1024 = 0x000d,
Uni512 = 0x000e,
Handle = 0x000f
}
/// <summary>
/// Helper class for twain types.
/// <para xml:lang="ru">Вспомогательный класс для типов twain.</para>
/// </summary>
internal sealed class TwTypeHelper {
private static Dictionary<TwType, Type> _typeof = new Dictionary<TwType, Type> {
{TwType.Int8,typeof(sbyte)},
{TwType.Int16,typeof(short)},
{TwType.Int32,typeof(int)},
{TwType.UInt8,typeof(byte)},
{TwType.UInt16,typeof(ushort)},
{TwType.UInt32,typeof(uint)},
{TwType.Bool,typeof(TwBool)},
{TwType.Fix32,typeof(TwFix32)},
{TwType.Frame,typeof(TwFrame)},
{TwType.Str32,typeof(TwStr32)},
{TwType.Str64,typeof(TwStr64)},
{TwType.Str128,typeof(TwStr128)},
{TwType.Str255,typeof(TwStr255)},
{TwType.Str1024,typeof(TwStr1024)},
{TwType.Uni512,typeof(TwUni512)},
{TwType.Handle,typeof(IntPtr)}
};
private static Dictionary<int, TwType> _typeofAux = new Dictionary<int, TwType> {
{32,TwType.Str32},
{64,TwType.Str64},
{128,TwType.Str128},
{255,TwType.Str255},
{1024,TwType.Str1024},
{512,TwType.Uni512}
};
/// <summary>
/// Returns the corresponding twain type of the managed type.
/// <para xml:lang="ru">Возвращает соответствующий twain-типу управляемый тип.</para>
/// </summary>
/// <param name="type">Type code given by twain.<para xml:lang="ru">Код типа данный twain.</para></param>
/// <returns>Managed type.<para xml:lang="ru">Управляемый тип.</para></returns>
internal static Type TypeOf(TwType type) {
return TwTypeHelper._typeof[type];
}
/// <summary>
/// Returns the corresponding twain type for the managed type.
/// <para xml:lang="ru">Возвращает соответствующий управляемому типу twain-тип.</para>
/// </summary>
/// <param name="type">Managed type.<para xml:lang="ru">Управляемый тип.</para></param>
/// <returns>Type code given by twain.<para xml:lang="ru">Код типа данный twain.</para></returns>
internal static TwType TypeOf(Type type) {
Type _type = type.IsEnum ? Enum.GetUnderlyingType(type) : type;
foreach(var _item in TwTypeHelper._typeof) {
if(_item.Value == _type) {
return _item.Key;
}
}
if(type == typeof(bool)) {
return TwType.Bool;
}
if(type == typeof(float)) {
return TwType.Fix32;
}
if(type == typeof(RectangleF)) {
return TwType.Frame;
}
throw new KeyNotFoundException();
}
/// <summary>
/// Returns the corresponding twain type.
/// <para xml:lang="ru">Возвращает соответствующий объекту twain-тип.</para>
/// </summary>
/// <param name="obj">An object.<para xml:lang="ru">Объект.</para></param>
/// <returns>Type code given by twain.<para xml:lang="ru">Код типа данный twain.</para></returns>
internal static TwType TypeOf(object obj) {
if(obj is string) {
return TwTypeHelper._typeofAux[((string)obj).Length];
}
return TwTypeHelper.TypeOf(obj.GetType());
}
/// <summary>
/// Returns the size of a twain type in an unmanaged memory block.
/// <para xml:lang="ru">Возвращает размер twain-типа в неуправляемом блоке памяти.</para>
/// </summary>
/// <param name="type">Type code given by twain.<para xml:lang="ru">Код типа данный twain.</para></param>
/// <returns>Size in bytes.<para xml:lang="ru">Размер в байтах.</para></returns>
internal static int SizeOf(TwType type) {
return Marshal.SizeOf(TwTypeHelper._typeof[type]);
}
/// <summary>
/// Converts internal component types to common environment types.
/// <para xml:lang="ru">Приводит внутренние типы компонента к общим типам среды.</para>
/// </summary>
/// <param name="type">Twain type code.<para xml:lang="ru">Код twain-типа.</para></param>
/// <param name="value">Instance of the object.<para xml:lang="ru">Экземпляр объекта.</para></param>
/// <returns>Instance of the object.<para xml:lang="ru">Экземпляр объекта.</para></returns>
internal static object CastToCommon(TwType type, object value) {
switch(type) {
case TwType.Bool:
return (bool)(TwBool)value;
case TwType.Fix32:
return (float)(TwFix32)value;
case TwType.Frame:
return (RectangleF)(TwFrame)value;
case TwType.Str128:
case TwType.Str255:
case TwType.Str32:
case TwType.Str64:
case TwType.Uni512:
case TwType.Str1024:
return value.ToString();
}
return value;
}
/// <summary>
/// Converts generic media types to internal component types.
/// <para xml:lang="ru">Приводит общие типы среды к внутренним типам компонента.</para>
/// </summary>
/// <param name="type">Twain type code.<para xml:lang="ru">Код twain-типа.</para></param>
/// <param name="value">Instance of the object.<para xml:lang="ru">Экземпляр объекта.</para></param>
/// <returns>Instance of the object.<para xml:lang="ru">Экземпляр объекта.</para></returns>
internal static object CastToTw(TwType type, object value) {
switch(type) {
case TwType.Bool:
return (TwBool)(bool)value;
case TwType.Fix32:
return (TwFix32)(float)value;
case TwType.Frame:
return (TwFrame)(RectangleF)value;
case TwType.Str32:
return (TwStr32)value.ToString();
case TwType.Str64:
return (TwStr64)value.ToString();
case TwType.Str128:
return (TwStr128)value.ToString();
case TwType.Str255:
return (TwStr255)value.ToString();
case TwType.Uni512:
return (TwUni512)value.ToString();
case TwType.Str1024:
return (TwStr1024)value.ToString();
}
Type _type = value.GetType();
if(_type.IsEnum && Enum.GetUnderlyingType(_type) == TwTypeHelper.TypeOf(type)) {
return Convert.ChangeType(value, Enum.GetUnderlyingType(_type));
}
return value;
}
/// <summary>
/// Converts a value to an instance of the component's internal type.
/// <para xml:lang="ru">Выполняет преобразование значения в экземпляр внутреннего типа компонента.</para>
/// </summary>
/// <typeparam name="T">Тип значения.</typeparam>
/// <param name="type">Twain type code.<para xml:lang="ru">Код twain-типа.</para></param>
/// <param name="value">Value.<para xml:lang="ru">Значение.</para></param>
/// <returns>Instance of the object.<para xml:lang="ru">Экземпляр объекта.</para></returns>
internal static object ValueToTw<T>(TwType type, T value) {
int _size = Marshal.SizeOf(typeof(T));
IntPtr _mem = Marshal.AllocHGlobal(_size);
Twain32._Memory.ZeroMemory(_mem, (IntPtr)_size);
try {
Marshal.StructureToPtr(value, _mem, true);
return Marshal.PtrToStructure(_mem, TwTypeHelper.TypeOf(type));
} finally {
Marshal.FreeHGlobal(_mem);
}
}
/// <summary>
/// Converts an instance of an internal component type to a value.
/// <para xml:lang="ru">Выполняет преобразование экземпляра внутреннего типа компонента в значение.</para>
/// </summary>
/// <typeparam name="T">Тип значения.</typeparam>
/// <param name="value">Instance of the object.<para xml:lang="ru">Экземпляр объекта.</para></param>
/// <returns>Value.<para xml:lang="ru">Значение.</para></returns>
internal static T ValueFromTw<T>(object value) {
int _size = Math.Max(Marshal.SizeOf(typeof(T)), Marshal.SizeOf(value));
IntPtr _mem = Marshal.AllocHGlobal(_size);
Twain32._Memory.ZeroMemory(_mem, (IntPtr)_size);
try {
Marshal.StructureToPtr(value, _mem, true);
return (T)Marshal.PtrToStructure(_mem, typeof(T));
} finally {
Marshal.FreeHGlobal(_mem);
}
}
}
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
internal sealed class TwTypeAttribute : Attribute {
public TwTypeAttribute(TwType type) {
this.TwType = type;
}
public TwType TwType {
get;
private set;
}
}
/// <summary>
/// Capability Constants
/// </summary>
public enum TwCap : ushort {
/* image data sources MAY support these caps */
#pragma warning disable CS1591 // Missing XML comment for public visible type or member / Отсутствует комментарий XML для открытого видимого типа или члена
XferCount = 0x0001, // all data sources are REQUIRED to support these caps
ICompression = 0x0100, // ICAP_...
IPixelType = 0x0101,
IUnits = 0x0102, //default is TWUN_INCHES
IXferMech = 0x0103,
AutoBright = 0x1100,
Brightness = 0x1101,
Contrast = 0x1103,
CustHalftone = 0x1104,
ExposureTime = 0x1105,
Filter = 0x1106,
FlashUsed = 0x1107,
Gamma = 0x1108,
[TwType(TwType.Str32)]
Halftones = 0x1109,
Highlight = 0x110a,
ImageFileFormat = 0x110c,
LampState = 0x110d,
LightSource = 0x110e,
Orientation = 0x1110,
PhysicalWidth = 0x1111,
PhysicalHeight = 0x1112,
Shadow = 0x1113,
Frames = 0x1114,
XNativeResolution = 0x1116,
YNativeResolution = 0x1117,
XResolution = 0x1118,
YResolution = 0x1119,
MaxFrames = 0x111a,
Tiles = 0x111b,
BitOrder = 0x111c,
CcittKFactor = 0x111d,
LightPath = 0x111e,
PixelFlavor = 0x111f,
PlanarChunky = 0x1120,
Rotation = 0x1121,
SupportedSizes = 0x1122,
Threshold = 0x1123,
XScaling = 0x1124,
YScaling = 0x1125,
BitOrderCodes = 0x1126,
PixelFlavorCodes = 0x1127,
JpegPixelType = 0x1128,
TimeFill = 0x112a,
BitDepth = 0x112b,
BitDepthReduction = 0x112c, /* Added 1.5 */
UndefinedImageSize = 0x112d, /* Added 1.6 */
ImageDataSet = 0x112e, /* Added 1.7 */
ExtImageInfo = 0x112f, /* Added 1.7 */
MinimumHeight = 0x1130, /* Added 1.7 */
MinimumWidth = 0x1131, /* Added 1.7 */
AutoDiscardBlankPages = 0x1134, /* Added 2.0 */
FlipRotation = 0x1136, /* Added 1.8 */
BarCodeDetectionEnabled = 0x1137, /* Added 1.8 */
SupportedBarCodeTypes = 0x1138, /* Added 1.8 */
BarCodeMaxSearchPriorities = 0x1139, /* Added 1.8 */
BarCodeSearchPriorities = 0x113a, /* Added 1.8 */
BarCodeSearchMode = 0x113b, /* Added 1.8 */
BarCodeMaxRetries = 0x113c, /* Added 1.8 */
BarCodeTimeout = 0x113d, /* Added 1.8 */
ZoomFactor = 0x113e, /* Added 1.8 */
PatchCodeDetectionEnabled = 0x113f, /* Added 1.8 */
SupportedPatchCodeTypes = 0x1140, /* Added 1.8 */
PatchCodeMaxSearchPriorities = 0x1141, /* Added 1.8 */
PatchCodeSearchPriorities = 0x1142, /* Added 1.8 */
PatchCodeSearchMode = 0x1143, /* Added 1.8 */
PatchCodeMaxRetries = 0x1144, /* Added 1.8 */
PatchCodeTimeout = 0x1145, /* Added 1.8 */
FlashUsed2 = 0x1146, /* Added 1.8 */
ImageFilter = 0x1147, /* Added 1.8 */
NoiseFilter = 0x1148, /* Added 1.8 */
OverScan = 0x1149, /* Added 1.8 */
AutomaticBorderDetection = 0x1150, /* Added 1.8 */
AutomaticDeskew = 0x1151, /* Added 1.8 */
AutomaticRotate = 0x1152, /* Added 1.8 */
JpegQuality = 0x1153, /* Added 1.9 */
FeederType = 0x1154,
IccProfile = 0x1155,
AutoSize = 0x1156,
AutomaticCropUsesFrame = 0x1157,
AutomaticLengthDetection = 0x1158,
AutomaticColorEnabled = 0x1159,
AutomaticColorNonColorPixelType = 0x115a,
ColorManagementEnabled = 0x115b,
ImageMerge = 0x115c,
ImageMergeHeightThreshold = 0x115d,
SupportedExtImageInfo = 0x115e,
FilmType = 0x115f,
Mirror = 0x1160,
JpegSubSampling = 0x1161,
/* all data sources MAY support these caps */
[TwType(TwType.Str128)]
Author = 0x1000,
[TwType(TwType.Str255)]
Caption = 0x1001,
FeederEnabled = 0x1002,
FeederLoaded = 0x1003,
[TwType(TwType.Str32)]
TimeDate = 0x1004,
SupportedCaps = 0x1005,
ExtendedCaps = 0x1006,
AutoFeed = 0x1007,
ClearPage = 0x1008,
FeedPage = 0x1009,
RewindPage = 0x100a,
Indicators = 0x100b, /* Added 1.1 */
SupportedCapsExt = 0x100c, /* Added 1.6 */
PaperDetectable = 0x100d, /* Added 1.6 */
UIControllable = 0x100e, /* Added 1.6 */
DeviceOnline = 0x100f, /* Added 1.6 */
AutoScan = 0x1010, /* Added 1.6 */
ThumbnailsEnabled = 0x1011, /* Added 1.7 */
Duplex = 0x1012, /* Added 1.7 */
DuplexEnabled = 0x1013, /* Added 1.7 */
EnableDSUIOnly = 0x1014, /* Added 1.7 */
CustomDSData = 0x1015, /* Added 1.7 */
Endorser = 0x1016, /* Added 1.7 */
JobControl = 0x1017, /* Added 1.7 */
Alarms = 0x1018, /* Added 1.8 */
AlarmVolume = 0x1019, /* Added 1.8 */
AutomaticCapture = 0x101a, /* Added 1.8 */
TimeBeforeFirstCapture = 0x101b, /* Added 1.8 */
TimeBetweenCaptures = 0x101c, /* Added 1.8 */
ClearBuffers = 0x101d, /* Added 1.8 */
MaxBatchBuffers = 0x101e, /* Added 1.8 */
[TwType(TwType.Str32)]
DeviceTimeDate = 0x101f, /* Added 1.8 */
PowerSupply = 0x1020, /* Added 1.8 */
CameraPreviewUI = 0x1021, /* Added 1.8 */
DeviceEvent = 0x1022, /* Added 1.8 */
[TwType(TwType.Str255)]
SerialNumber = 0x1024, /* Added 1.8 */
Printer = 0x1026, /* Added 1.8 */
PrinterEnabled = 0x1027, /* Added 1.8 */
PrinterIndex = 0x1028, /* Added 1.8 */
PrinterMode = 0x1029, /* Added 1.8 */
[TwType(TwType.Str255)]
PrinterString = 0x102a, /* Added 1.8 */
[TwType(TwType.Str255)]
PrinterSuffix = 0x102b, /* Added 1.8 */
Language = 0x102c, /* Added 1.8 */
FeederAlignment = 0x102d, /* Added 1.8 */
FeederOrder = 0x102e, /* Added 1.8 */
ReacquireAllowed = 0x1030, /* Added 1.8 */
BatteryMinutes = 0x1032, /* Added 1.8 */
BatteryPercentage = 0x1033, /* Added 1.8 */
CameraSide = 0x1034,
Segmented = 0x1035,
CameraEnabled = 0x1036,
CameraOrder = 0x1037,
MicrEnabled = 0x1038,
FeederPrep = 0x1039,
FeederPocket = 0x103a,
AutomaticSenseMedium = 0x103b,
[TwType(TwType.Str255)]
CustomInterfaceGuid = 0x103c,
SupportedCapsSegmentUnique = 0x103d,
SupportedDats = 0x103e,
DoubleFeedDetection = 0x103f,
DoubleFeedDetectionLength = 0x1040,
DoubleFeedDetectionSensitivity = 0x1041,
DoubleFeedDetectionResponse = 0x1042,
PaperHandling = 0x1043,
IndicatorsMode = 0x1044,
PrinterVerticalOffset = 0x1045,
PowerSaveTime = 0x1046,
PrinterCharRotation = 0x1047,
PrinterFontStyle = 0x1048,
PrinterIndexLeadChar = 0x1049,
PrinterIndexMaxValue = 0x104A,
PrinterIndexNumDigits = 0x104B,
PrinterIndexStep = 0x104C,
PrinterIndexTrigger = 0x104D,
PrinterStringPreview = 0x104E,
SheetCount = 0x104F // Controls the number of sheets scanned (compare to CAP_XFERCOUNT that controls images)