What to choose when scanning: TWAIN or WIA driver

Good evening to all visitors to my blog. Today's topic will be related to scanning. By scanning what comes with the MFP. Just over the weekend, a friend of mine asked me to scan a bunch of photos for him. And when fulfilling this request, I became interested in this interesting thing- as a scanner driver. On my MFP, Samsung SCX-4200, in the program you could select one of two drivers, with scary names. One was called TWAIN and the other WIA. Today we will deal with such incomprehensible words.

What is a scan driver?

I think it’s no secret to anyone that in order to interact with any external device and a computer, in addition to directly connecting the two devices with wires, you need to install a special program on the computer, called a driver. The driver itself is a kind of command base, described by programmers in a low-level language, for interacting with equipment. Well, actually in our example there is a scanner that the scanner performed our pressing of the “Scan” button; it must understand this action. That's why we install the driver. Which, the moment we press the “Scan” button, performs a certain algorithm and sends a command in binary language to the scanner, due to which the scanner begins to move the photo head. Driver manufacturers must adhere to certain standards when writing code. There can be many of them. We'll look at some of them. These are TWAIN and WIA.

What is a TWAIN driver?

TWAIN is a standard, as mentioned above, created by scanner manufacturers that allows the scanner to interact with the software. The scanner's Twain driver is software that transfers data from the scanner to the software application from which you call the scanner. Using the Twain driver, you can set parameters and the scanning area, perform preliminary scanning and viewing, and provide the ability to color correct and post-process the resulting image.

Officially, "TWAIN" is not an acronym, although the English version is widely used. Technology Without An Interesting Name (technology without an interesting name/name).

What is a WIA driver?

For details, please refer to Wikipedia.

Windows Image Acquisition(WIA, sometimes called Windows Imaging Architecture) is a Microsoft driver model and API for Windows ME and later Windows operating systems. This model allows graphics programs interact with equipment such as scanners, digital cameras and video cameras.

Compared to TWAIN, this standard emerged not so long ago, only in 2000.

Which is better TWAIN or WIA?

Unlike TWAIN drivers, WIA modules begin to work immediately, the moment a working device is connected to a PC via a port, such as USB. If TWAIN is intended for preliminary editing of images, then WIA is used to perform various operations - viewing, copying, editing.

Both drivers can scan over the network. They are mostly similar, but the functions of TWAIN and WIA are different. It is also worth saying that TWAIN drivers come from the manufacturer, while WIA is directly with the participation of Microsoft.

Conclusion

In the case of Windows systems, to be honest, the choice is yours. While in other systems TWAIN driver but will be a higher priority. But the final choice will be yours.

TWAIN is an Application Program Interface (API) standard between imaging devices (such as scanners) and the applications that control those devices.

In other words, TWAIN is a standard created by scanner manufacturers that allows the scanner to communicate with the software. The Twain scanner driver is a software application with a graphical interface that carries the functions of the scanner control panel and transfers data from the scanner to the software application from which you call the scanner. Using the Twain driver, you can set parameters and the scanning area, perform preliminary scanning and viewing, and provide the ability to color correct and post-process the resulting image.

The TWAIN Initiative was launched in 1992 by industry leaders who recognized the need to standardize the protocol and programming interface between applications and image capture devices (data sources). TWAIN defines such a standard.

Officially, "TWAIN" is not an acronym, although the English version is widely used. Technology Without An Interesting Name(technology without an interesting name/name). The word "TWAIN" is taken from Kipling's poem "The Ballad of East and West". …and never the twain shall meet…, reflects the complexity of the scanner's communication with the computer and is converted to uppercase for better emphasis.

Target working group TWAIN - continue to develop the standard to meet modern technologies.

More about TWAIN

[Fine], if the camera came with a CD from which you can install something called a TWAIN driver on your computer. The abbreviation TWAIN refers to a special protocol that allows image editing or cataloging programs to access a digital camera or scanner directly.

After installing the TWAIN driver, you can open files that are still stored in the camera's memory in image editing or cataloging programs. Of course, for this the camera must be connected to the computer. In addition, the image processing programs installed on your computer must be TWAIN-compatible, i.e. understand the TWAIN protocol.

Different programs provide different commands for opening files stored in the camera's memory. As a rule, they are located in the File menu and are designated something like Acquire or Import. Some programs require you to first specify which hardware component you want to access. To do this, use the TWAIN source command, also usually located in the File menu.

(The following is text dating back to approximately 2005 and taken from the site codenet.ru): Unlike printers, scanners were not originally supported by Windows and do not have an API for working with them. At the beginning of their appearance, scanners interacted with programs through an interface unique to each scanner model, which seriously complicated the inclusion of support for working with the scanner in application programs.

To solve this problem, TWAIN was developed - an industry standard interface software to transfer images from various devices to Windows and Macintosh. TWAIN is not a hardware protocol, it requires a driver (called Data Source or DS) for each device.

TWAIN is available for Windows [...] , Macintosh and OS/2. For Linux, the closest standard is SANE..

TWAIN Manager (DSM) - acts as a coordinator between applications and the Data Source. DSM has a minimal user interface - DS selection only. All interaction with the user outside the application program is carried out using DS.

Each data source is developed directly by the respective device manufacturer and their support for the TWAIN standard is voluntary.

Using TWAIN

DSM and DS are DLLs loaded into the application's address space and act as application routines. DSM uses interprocess communication to coordinate with its copies when more than one program is using TWAIN.

A simplified diagram of the operation of an application using TWAIN:

  1. Open the settings dialog for the corresponding device (the dialog displays DS) and set the appropriate settings.
  2. The application waits for a message from the DS that the image is ready. While waiting, all logged messages will be routed through TWAIN. If this is not done, the application will not receive a message that the image is ready.
  3. The application receives an image from the DS.
    TWAIN defines three types of image transfer:
    Native- on Windows this is a DIB in memory
    Memory - like blocks of pixels in memory buffers
    File- DS writes image directly to file (not necessarily supported)
  4. The application closes the DS.

Using EZTWAIN

This library was developed to simplify the development of programs using TWAIN by providing the developer with a simplified version of the TWAIN API.

EZTWAN ensures that all windows messages are transmitted through TWAIN and waits for messages when the image is ready.

The EZTWAIN library is a free and open source library. source codes. The library can be freely downloaded from the website: www.dosadi.com, the library is written in C and is intended to be used as a DLL; the module necessary for its use with Delphi can also be downloaded from the website. except her [...] can be downloaded a modification of this library intended for static linking with a Delphi program. The specified version (MultiTWAIN for Delphi) does not require the EZTW32.DLL library.

Functions used

Before calling the scanning functions, you must call the function:
TWAIN_SelectImageSource(hwnd: HWND): Integer;

This function allows you to select a data source from a list of TWAIN compatible devices. As a parameter, it receives the handle of the main window of the application program. It should be replaced that if there is one TWAIN-compatible device in the system, then it is not necessary to call the function.

To obtain an image, use the function:
TWAIN_AcquireNative(hwnd: HWND; pixmask: Integer): HBitmap;

Where:
hwnd - handle of the main window of the application program (0 can be specified);
pixmask - scanning mode (must be set to 0 - specifying a different mode may lead to an error);
hBitmap is a pointer to a memory area containing the received data in DIB format.

After you finish working with DIB data, you need to delete it by calling the procedure:
TWAIN_FreeNative(hDIB: HBitmap);

Where:
hDIB - pointer obtained when calling the function TWAIN_AcquireNative.

To facilitate the processing of received DIB data, the library has several service functions:

Example program

The full text of the example can be taken from here. We will only consider the function of receiving data from a TWAIN device:

Procedure TForm1.Accquire1Click(Sender: TObject); var dat: hBitMap; PInfo: PBitMapInfoHeader; Height,Width:integer; (Function for raising 2 to the power of s) function stp2(s:byte):longint; var m: longint; i:byte; begin m:=2; for i:=2 to s do m:=m*2; stp2:=m; end; begin (Get a pointer to graphic data) dat:=TWAIN_AcquireNative(Handle,0); if dat<>0 then begin (Get a pointer to the memory area containing DIB data and lock the memory area) PInfo:=GlobalLock(dat); (We analyze the received data) Height:=PInfo.biHeight ; Width:=PInfo.biWidth ; (Let's find out the size of the resulting image in centimeters) Wcm.Caption:=floatToStrF(100/PInfo.biXPelsPerMeter*Width,ffNumber,8,3) +" cm"; Hcm.Caption:=floatToStrF(100/PInfo.biYPelsPerMeter*Height,ffNumber,8,3) +" cm"; (Determine the number of colors in the image) Colors.Caption:= floatToStrF(stp2(PInfo.biBitCount),ffNumber,8,0)+ " colors"; (Unlock memory) GlobalUnlock(dat); (We transfer graphic data to the bit matrix) (And set up error interception) try MyBitMap.Palette:=TWAIN_CreateDibPalette(dat); MyBitMap.Width:= Width; MyBitMap.Height:= Height; TWAIN_DrawDibToDC(MyBitMap.Canvas.Handle,0,0,Width,Height,dat,0,0); except (We handle the most likely error associated with insufficient resources to load the image) on EOutOFResources do MessageDlg("TBitMap: There are no resources to load the image!", mtError,,0); end; (Display graphic data) Image1.Picture.Graphic:=MyBitMap; (Free up memory occupied by graphic data) TWAIN_FreeNative(dat); end; end;

Error handling is necessary because the TBitMap object has severe limitations on the size of the image it produces. In this case, the most likely error is processed; if another error occurs, its processing will be transferred to the default handler. Error handling in this case consists of issuing a diagnostic message. IN application program you can implement any necessary actions, for example, reduce the resolution and resubmit for loading into TBitMap.

The example given here was tested on a Umax 2000P scanner with the VistaScan32 V3.52 driver. When acquiring images, be aware that the maximum memory block size that Windows can allocate is 2 GB, and if you attempt to scan high-resolution A4 pages, you may exceed this limit. In addition, the fairly easy-to-use TBitMap object has much more serious restrictions on the size of loaded images, which requires direct work with DIB data. (End of quoted text from the site codenet.ru)

The delivery package of any scanner includes a software package responsible for correct recognition of the device when connected to personal computer, as well as ensuring its proper operation. This specialized software is called driver. The set of drivers may vary depending on the model, but there are also universal interfaces necessary for the scanner to interact with the computer operating system. In particular, you can often find abbreviations such as TWAIN, WIA And ISIS-drivers (standards, protocols). Let's try to figure out what each name means and what functions each driver performs.

In fact, TWAIN is not an abbreviation, but a word that means “pair” or “two” in English. By “pair” here we mean a tandem computer - scanner. In other words, a TWAIN-compatible driver is required so that the computer's operating system can interact with imaging devices, including scanners. The TWAIN scanner driver is typically implemented as a software application with an intuitive user interface. Its main function is to transfer information from the scanner to a computer application through which scanning commands are executed. It is with its help that such actions as previewing images, preliminary scanning, adjusting parameters (color, saturation, etc.) are performed. And it is thanks to the presence of the TWAIN driver that you can scan from any program that has the Scan command.

Since WIA stands for Windows Imaging Architecture, it is easy to guess that this standard was created specifically for the Windows OS, and it was developed by Microsoft. It is designed for more convenient control of the scanner using standard Windows tools familiar to users. For example, it is thanks to the WIA driver that the scanner is displayed in the computer’s device manager when connected, and we can view its properties and contents in the usual way. A driver component such as Scanner Wizard allows you to work with images using a standard interface in the form of windows. This interface offers a number of options for managing images - preview, adjusting resolution, brightness, color, scaling and others. Thus, regardless of the scanner model, the user can use familiar and understandable tools when working with documents and images.

The ISIS (Image and Scanner Interface Specification) interface, just like Twain, is designed for interaction between a scanner and a computer, but is capable of performing more complex tasks. It is a collection of modules, each of which performs a specific function (scanning, conversion, compression). These modules can be combined to form pipelines to perform complex, multi-step tasks. ISIS offers software developers a reliable and stable interface for integrating scanning tasks into applications. Since ISIS is an industry standard, the user of a scanner with an ISIS driver can be sure that the machine they purchase is compatible with all applications operating system, developed taking into account this standard.

Every person has at least a modicum of sadistic tendencies. The only difference is in their quantitative content and qualitative manifestation. For example, I like to ask people questions on topics they don’t understand anything about, and watch them suffer trying to guess the correct answer. It turns out that any specialist in his field likes to carry out exactly the same torture. How else can we explain, for example, the fact that almost any computer program working with an image scanner, the first time you use it, you will definitely ask a question like: “Which driver do you want to use when scanning: TWAIN or WIA? Or maybe you want to use our own driver? Or do you prefer ISIS drivers?”

Any normal computer user, after such a question, will go and hang himself, feeling his complete helplessness in this life. Or at least go on a drinking binge for a week.

My dears, no need! I will save you! At least from this specific question. Let's decide together which driver we would like to use in an ordinary Russian office when scanning ordinary Russian documents on an ordinary Russian Chinese American scanner.

Answer

If your device supports the ISIS driver, then this article is obviously not for you. These drivers are intended for industrial equipment, have a lot of capabilities and mean that they will be used by specialists who are deeply immersed in the essence of the issue. In general, for ordinary people, ISIS is not an option.

The TWAIN standard will turn three thousand years old next Tuesday. It would seem that using the same interface that our ancestors used in stone caves is not very smart. But nevertheless, this is the driver that is worth choosing if possible. There are several reasons for this:

  • this interface is specially designed for communication between computers and image capture devices
  • software to support the TWAIN interface is developed by the equipment manufacturer itself, which means it takes into account all its features and customization capabilities
  • The TWAIN interface allows for saving settings between separate sessions of working with the device


The WIA standard was developed by Microsoft to work with image capture devices. The main advantage of using this interface is that it uses standard dialog boxes operating system, which means that regardless of the device used, be it a camera or a scanner, the user will work in an environment familiar to him. However, this same advantage is also the main disadvantage of the WIA interface - no matter how rich configuration capabilities your scanner has, you will not be able to take full advantage of them, since the WIA interface knows nothing about them and will only offer you standard settings that are present in any other device.

Summary

When working with your scanner, use the TWAIN interface whenever possible.

When working with a camera or any other device that does not require special settings when transferring images, it is more convenient to use the WIA standard.

PS

One note. If the program you are working with has its own interface for working with the scanner, then in my opinion it is preferable to use it. I can explain this by the fact that, firstly, this interface does not change when using different scanners, and secondly, it contains only those settings that are important for this particular program. An example is the FineReader program:


However, even if you use the FineReader interface, you still have a choice suitable driver devices (TWAIN or WIA), so the information from the article remains relevant in this case.

For all applications on your computer to work correctly, you must: regular update drivers for all PC devices. A small program called DriverScanner will help users with this, allowing them to automatically scan the firmware versions of devices and display a list of drivers required for updating. After that, with the press of one button you can perform this “upgrade”. If you monitor the performance and correct operation of your computer, you can download DriverScanner for free and install its new version.

Possibilities:

  • updating firmware versions for equipment;
  • creating a backup copy when updating;
  • update all drivers with one click;
  • selective driver update.

Principle of operation:

DriverScanner features allow you to scan your computer's applications to find all driver versions. The utility shows the degree of their obsolescence. If you see the words “Ancient” next to some driver versions, you should update them immediately. You can install newer firmware versions of all or selected devices. In this case, the utility creates backups previous versions of drivers, so that if applications do not work correctly, you can roll back the action.

You can install DriverScanner for Windows XP, Vista, 7 and 8.

Pros:

  • batch update of driver versions;
  • returning the previous version of the driver if the new one does not work correctly;
  • Russian-language program menu;
  • the ability to download DriverScanner to your computer for free;
  • simple interface.

Minuses:

  • To update versions you need to buy a program key.

DriverScanner will be useful for every PC owner. This program automatically scans driver versions for the correct operation of all applications and allows you to update all firmware with the click of one button. In addition, the utility functions include backup data to return the previous version of the driver if the application does not work correctly. In short, for driver updates we recommend you use DriverScanner. Download it for free latest version any user can.

However, to download the drivers themselves you need to buy a program key.

For “every fireman”, here is an analogue of DriverScanner: - free program to reinstall driver versions in Windows.