White Papers Using a Multi-tasking I/O Adapter to Improve Scanner Performance Scanning a high-resolution picture always takes time. This article explores the possibility of using a multi-tasking I/O adapter to dramatically reduce the scan time. The Scanner Performance Most scanners today come with a very low-cost SCSI I/O adapter. While taking only a few seconds to scan a page of low-resolution data, the low-cost adapter takes minutes or hours to scan the same page of high-resolution data. For example, with the resolution of 100 bits-per-inch (BPI) with 256 gray scale, an 8.5x11" page of data is represented by (8.5 x 100) x (11 x 100) bytes -- 9.35 MB -- of digitized data. Using a program to copy the data to a disk drive, the average speed of reading using the low-end SCSI adapter is 400 KB/sec. In other words, one page of data takes 23.375 seconds -- 9.3 MB divides 400 KB/sec -- to complete the copy. When color is selected for scanning, the same 100 BPI page is represented by 9.3 MB x 3 (24-bit color) bytes, or 27.8 MB of digitized data. The same copy program will need 70.125 seconds to complete. The following table summarizes the program copy time. Resolution Color File size/MB Copy Time/Seconds 100x100 no 9.3 23.375 100x100 yes 27.9 70.125 300x300 no 81.9 210.375 300x300 yes 245.7 631.125 600x600 no 327.6 841.5 600x600 yes 982.8 2524.5 1200x1200 no 1310.4 3366 1200x1200 yes 3931.2 10098 (or 2.8 hours) At 1200x1200 color, the scanner using a low-end adapter which would need 10098 seconds or 2.8 hours to complete the copy! A high-end SCSI adapter with a properly designed copy program should be able to sustain the data transfer from the scanner at 9.5 MB per second (ten MB/sec minus SCSI overhead) and complete the copy of 3931 MB of data in less than seven minutes, an improvement of 23-fold. How Does the Scanner Work? A scanner moves a page forward underneath its sensors at constant speed. The digitized data from the sensors are copied into a 1 MB buffer. The buffer is emptied by a copy program running under either DOS, Windows, or other operating systems. The program reads data from the scanner and writes it out to disk or displays the data on a monitor. When the scanner buffer is filled up, the scanner must stop. For example, if a scanner moves forward at 2" per second and it reads at 100 x 100 resolution with gray scale, it will fill the buffer at (8.4 x 100) x (2 x 100) = 1.7 MB/second. If a low-end SCSI adapter is used to empty the buffer at 400 KB per second, the scanner will take only 1.0 MB/(1.7 MB - 0.4 MB)=0.77 seconds to fill up a one MB buffer. Once stopped, the scanner waits until the buffer is half empty, depending on how the scanner software is designed, before starting to scan again. When scanning at the resolution of 100 x 100 with color, the scanner will fill the buffer at (8.4 x 100) x (2 x 100) x 3 = 5.1 MB/second. Using the same low-end SCSI adapter to empty the buffer, the scanner will stop in only 1.0 MB/(5.1 MB - 0.4 MB)=0.21 seconds. The following table summarizes the scanner data rates. Resolution Color Buffer filling speed 100x100 no 1.7 100x100 yes 5.1 300x300 no 15.3 300x300 yes 45.3 or the maximum scanner buffer speed 600x600 no 61.2 or the maximum scanner buffer speed 600x600 yes 181.2 or the maximum scanner buffer speed 1200x1200 no 244.8 or the maximum scanner buffer speed 1200x1200 yes 724.8 or the maximum scanner buffer speed A Multi-tasking SCSI Adapter Using a multi-tasking SCSI adapter, a Windows copy program can speed up the scanner copy function ten-fold using the following algorithm: 1.Allocate a permanent swap file, occupying contiguous disk space, large enough to store the scanner input. 2.Use a DOS function call to get the first disk cluster address. 3.Allocate three buffers; link them into a circular list; mark them as empty. Send a scanner read command to fill the first buffer. 4.Wait for the completion of the scanner read. At the completion, immediately send another scanner read to fill the 2nd buffer using the ASPI manager posting feature. 5.Send a disk write command to empty the first buffer; Bump the disk block address. 6.(Both scanner read and disk write are going) Wait for the completion of either the scanner read or the disk write. If the scanner read is completed, go to Step 7. If the disk write is completed, go to Step 8. 7.(Just completed a scanner read; the disk is writing) If the scanner has no more data, go to Step 11. Mark the buffer as full. Check if the next buffer is empty, three buffers are linked in a circular list. If yes, start another scanner read and go to Step 6. 8.(Just completed a disk write; the scanner is reading) Mark the buffer as empty. Check if the next buffer is ready, three buffers are linked in a circular list. If yes, start another disk write; bump disk block address; go to Step 6. If not, go to Step 10. 9.(The scanner is stopped; all buffers are full) Wait until the completion of the disk write; mark the buffer empty. Start another disk write from the next buffer; bump the disk block address. Start a scanner read. Go to Step 6. 10.(The disk write is done; all buffers are empty) Wait until the completion of the scanner read; mark the buffer full. Start another scanner read to the next buffer. Start a disk write; bump the disk block address. Go to Step 6. 11.(Reading from the scanner is done) Empty all buffers to disk. Exit. (The essence of the algorithm is to keep both scanner reading and disk writing in concurrent. Consequently, the ten MB/sec SCSI bus is shared by two devices at five MB/sec for each device. The scanner copy speed will be improved from 400 KB/sec by 1000%. In general, the sustainable disk write is about five MB/sec unless disk array is used. In this case, we need to keep the disk array and scanner on separate SCSI channels to achieve ten MB/sec copy speed, provided the scanner is reading with enough high-resolution to feed SCSI bus at ten MB/sec.)