Windows Image Acquisition Enhancements In Windows Vista

Windows Image Acquisition
Enhancements In Windows Vista
Avijit Sinha
Program Manager
D2–Digital Documents Platform and Solutions
Agenda
Scanning infrastructure in Windows Vista
Push Scanning Demo
WIA Enhancements in Windows Vista
Multi-image scanning Demo
WIA Service Security Context change
Additional Info
WDK Samples and Tools
WIA Automation Layer and WIA Video
64-bit support
TWAIN support in Windows Vista
Windows Scanning Infrastructure For
Network And Locally Connected Scanners
Windows Vista
WSD Scan
Protocol
Network connected
Network
Scanners
Locally connected
Scanners
Windows Rally
Scan WIA Class
Driver for
Network
Connected
Scanners
Windows Rally
IHV WIA Driver
for Network
Connected
Scanners
Vista WIA Driver
for Locally
Connected
Scanner
WIA Scanner
Windows XP or
Windows Server
2003 WIA Driver
TWAIN Scanner
TWAIN Data
Source
Scanned Document
Storage
Routing Agent
Routing
Destination
Windows Fax and Scan Application
Routing Dialog
W
I
A
S
E
R
V
I
C
E
Scan Profiles
Dialog
Scan
Dialog
Windows
Photo
Gallery
Scan
Profiles
Windows Vista WIA application
Windows XP or Windows Server
2003 WIA application
TWAIN Compatibility Layer
TWAIN Data Source
Manager
TWAIN application
Key
Device
New or
Enhanced in
Windows
Vista
Unchanged
in Windows
Vista
Push Scanning From A
Network Connected MFP
ImageRunner 3170
Scanner Tree Example
WIA represents scanners and images on a scanner using a tree of items
XP/Windows Server 2003
Windows Vista
Root Item
Root Item
Flatbed
Item
Image Item
Feeder
Item
Film
Item
Storage
Item
WIA Items And Properties
WIA “items” are used to represent both
device attributes and device data
Two kinds of items
Applications use IWiaItem(2) (application
items) – each application has its own
“item tree”
Drivers use IWiaDrvItem (driver items) –
there is only one “driver item tree” per device
Where do IWiaDrvItems come from?
IWiaDrvItems are created by the driver
using WIA helper functions
WIA Data Transfers
Application
Request Transfer
Return from Transfer
Optional Imaging
Filter
5
Process boundary
1. Lock driver
WIA
2. Ask driver to commit
properties to device
3. Ask driver for data
4. Unlock driver
5. Imaging filter processes
data from scanner
1
2
3
Key
4
Microsoft
IHV
Driver
Simplified data transfer
ISV
Stream-Based Transfers
IWiaTransfer for stream-based data transfers
Not required to support legacy transfers to get a logo
Legacy applications will still work via the compatibility layer
Implement the code for data transfer in
drvAcquireItemData
Check the lFlags parameter for
WIA_MINIDRV_TRANSFER_DOWNLOAD.
If true, the transfer is stream-based
Call QueryInterface on the minidriver callback,
requesting IID_IWiaMiniDrvTransferCallback
Call IWiaTransfer::GetNextStream to get an IStream
interface, and write data directly to that interface via
IStream::Write
Send progress messages, such as
WIA_TRANSFER_MSG_END_OF_STREAM,
via IWiaTransfer
Multi-Page Transfers
Multi-page transfers are supported with IWiaTransfer
Drivers needs to call IWiaTransfer::GetNextStream to get
streams for the next pages
Drivers should call GetNextStream in a loop
S_OK to indicate another page has been requested
Multiple files can be produced by this method – the
application requests the file types, and each page can
represent a file; Previously a single transfer resulted in a
single file
For multi-page TIFF files, request a single stream and
write all the pages to the stream
For multiple file transfers, request a stream for each file
New WIA Interfaces
In Windows Vista, WIA provides new
COM interfaces
IWiaItem2, IWiaDevMgr2, IEnumWiaItem2
IWiaTransfer, IWiaTransferCallback
IWiaImageFilter, IWiaSegmentationFilter,
IWiaPreview
IWiaErrorHandler, IWiaAppErrorHandler
IWiaItem Versus IWiaItem2
IWiaItem versus IWiaItem2
IWiaItem2 is a superset of IWiaItem
IWiaItem interface remains unchanged to guarantee compatibility
New WIA items are only accessible through IWiaItem2
IWiaItem2 supports multi-region scanning, IWiaItem does not
IWiaItem2 and IWiaItem support the preview filter
Windows Vista has a WIA Compatibility layer to
ensure that
Windows XP applications (IWiaItem) work with
Windows Vista drivers
Windows Vista applications (IWiaItem2) work with
Windows XP drivers
WIA Compatibility Layer
Windows XP or Windows Server 2003
WIA Application
Windows XP or Windows Server
to Windows Vista
Compat Layer
Windows Vista WIA Application
Windows Vista to
Windows XP or Windows Server
Compat Layer
WIA service
Windows XP or Windows Server 2003
WIA driver
Windows Vista WIA driver
Key
Flatbed and Feeder Scanners can be accessed from
older (v1) and newer (v2) WIA Applications
Microsoft
Storage and Film Scanners can only be accessed from
IHV
newer (v2) WIA Apps (e.g., Windows Fax and Scan
App, Windows Photo Gallery, New Scanning Common
ISV
Dialog, etc)
Windows Vista WIA
Driver Implications
New functionality enables
Simplified driver development in many areas e.g., data transfers
Looser coupling between value-add components
Example: Core driver functionality (data transfer, property negotiation)
and enhanced functionality (Image Processing, Segmentation) can be
separately implemented
Recommendation: Write separate drivers for older WIA
(Windows XP and Windows Server 2003) and enhanced
WIA (Windows Vista) functionality
WIA drivers developed for Windows XP and Windows Server
2003 will continue to work on Windows Vista but will not be able to
expose enhanced WIA functionality (e.g., image segmentation,
live preview, error handling)
Therefore it is easier to have separate drivers and install different
package depending on operating system
WIA Vendor Customization
And Extensions
Vendors can optionally provide
components to enhance the
user experience
UI customization DLL
Image processing filter
Segmentation filter
Error handler
These components run in the
application process
Not the same process as the driver
UI Customization
WIA provides system-supplied UI
Provides consistent user-interface across
many devices
Less work for vendors
Much of the UI is replaceable or extensible
Scan dialogs (replaceable only)
Shell extension (Windows XP and Server 2003 only)
Property pages (extensible only)
Context menu (Windows XP and Server 2003 only)
Segmentation Filter
WIA Application
Segmentation Filter
WIA service
Scanner Driver
The Segmentation Filter creates
child items and sets the coordinates
of the sub-images into each item.
It does not acquire the images
Key
Microsoft
IHV
ISV
Detects regions in preview image
“Cuts out” the regions creating
multiple images
Scenario: Scanning multiple
separate photos at the same time
from a flatbed scanner
Item Tree with
Segmented
Images
Segmentation Filter
Segmentation filter enables IHVs to provide region
detection code and expose this functionality to
WIA application
In-proc COM component (runs in the
application’s process)
Microsoft will provide a replaceable segmentation filter
Segmentation filter must support all image formats that
the driver supports!
Simple modification to driver’s INF file
[MyDriver.AddReg]
…
HKCR,CLSID\{UiClassId}\shellex\
SegmentationFilter\{FilterClassId}
Image Processing Filter
Used for two purposes
Filtering scanned image to do image processing that can’t be done in hardware
Provide live preview by modifying preview image with realistic estimate of the final
scan (no more flowers!)
The live preview is used by the Preview Component provided by Microsoft in
Windows Vista
Invoked in the application process by WIA components
WIA Application
Scanner
Driver
Key
IWiaPreview
IWiaTransfer
Microsoft
WIA Service
Image
Processing
Filter
IHV
ISV
Image Processing Filter
In-proc COM component implementing IWiaImageFilter and
IWiaTransferCallback
Runs in the application’s process
Needs to support any image format that driver supports
Filter and driver need to read WIA_DPS_PREVIEW to determine what
the current purpose is
E.g., preview scan or final scan
Recommend to move filtering functionality from driver to filter
At a minimum, all filters should implement brightness and contrast
Simple modification to driver’s INF file
[MyDriver.AddReg]
…
HKCR,CLSID\{UiClassId}\shellex\
ImageProcessingFilter\{FilterClassId}
Error Handling
Provides status and error messages
during data acquisitions
“Lamp warming up”
“Cover open”
“Paper Jam”
Can show UI (if application allows)
Runs in application’s process
Microsoft provides a default error handler
with limited number of messages
WIA Component Interfaces
Key
Microsoft
IWiaUIExtension(2)
IShellExtInit
WIA Application
IHV
…
COM Proxy
ISV
IWiaDevMgr(2)
IWiaItem(2)
IWiaDrvItem
…
Optional
vendor UI
Default UI
Segmentation
Filter
Process
boundary
WIA service
Vendor filter
IStiUsd
IWiaMiniDrv
Vendor User Mode Driver (USD)
Vendor Error Handler
User Mode
Bus Driver
Kernel Mode
Multi-image Scanning
MP780
Security Context Change
Driver now runs under
LocalService account
Assumptions about access to resources
can cause “Access denied” errors under
new security context
Typical areas affected
File system access
Registry access
Named kernel objects
Out-of-process COM objects
Creating and opening other processes
Security Context Change
Many problems can be solved by putting
correct security descriptors on objects
To share objects with other components
Create a discretionary access control list
(DACL) that allows access to the object
Security Context Change
File system access
Under LocalSystem in Windows XP, driver
had Read/Write access to almost
any directory
Under LocalService, driver has mainly Read
access only
If driver only reads files, then usually not
a problem
Drivers should create or write their private
files in the %userprofile% directory
Note: The user account in this case is
“LocalSystem” or “LocalService”
Security Context Change
Registry Access
Much of the registry is available for the driver
to read
WIA drivers should only write to the
DeviceData section of the registry key that is
handed to them in the IStiUSD::Initialize
entry point
Security Context Change
Named kernel objects
Two main problems
Namespaces
Access permissions
Applications and drivers may run in
different sessions
Each has its own namespace
Use the correct namespace when specifying the
object name e.g., Global\MyDeviceLock
Set the object permissions correctly when
creating the object
Don’t rely on default permissions
Security Context Change
Out-of-process COM components
Require two types of permissions
Launch permissions
Access permissions
Ensure the permissions on the COM objects
are set correctly
Use the COM supplied method of storing
your permissions under the AppID key
Call CoInitializeSecurity with the EOAC_APPID
This allows administrators to adjust permissions
if necessary
Security Context Change
Creating and opening processes
WIA drivers should not manually start other
processes on the system
In Fast User Switching or Terminal Services
environment, it is often difficult to say who the
“user” is
In Windows XP, driver could launch the process
under the incorrect account
Generally not possible under LocalService
account, unless
Activating an installed COM component
Windows NT service etc
WIA In Windows Driver Kit (WDK)
WDK contains a very rich set of WIA samples
and tools to help Scanner Driver Developers
quickly develop and test their new WIA drivers
Samples
Monster Driver Sample includes
Sample for flatbed, feeder, film and storage source
Error Handler Sample
WIA Transfer Sample
Filters Sample
WIA Micro driver sample
Diagnostic Tools to help driver development
WIA navigation and property tool
WIA Trace Viewer
WIA Tools In The WDK
Test tools required for Logo/Certification
New Data Transfer Test tool
New Item Tree and Properties Compatibility
Test tool
Error Handler Test tool
Twain Data-source Compliance Test tool
Power Management Test Tool for Scanners
Additional tools
Filter Test tool
Imaging Driver Robustness Test tool
WIA Video
Functionality deprecated in Windows Vista
No infrastructure support in WIA for
acquisition from web cams
Video acquisition support removed in
older common dialogs
WIA Automation Layer
Available as download from microsoft.com
Is now inbox in Windows Vista
WIA On x64 Versions Of
Windows Vista
32-bit and 64-bit functionality are identical
64-bit extension host
Allows 32-bit WIA applications to work with
64-bit WIA drivers by hosting 64-bit WIA
UI extensions
TWAIN
Support same as
Windows Server 2003 SP1
Only 32-bit TWAIN DSM in Windows Vista
STI hosting component in x64
Windows Vista to enable 32-bit TWAIN
data-source and 64-bit STI driver
combination to be functional
Call To Action
IHVs
Write drivers exposing the new item tree structure
Write drivers that support the new stream based data transfer
Differentiate your device by providing your own image
processing filters
Enhance device experience using error handlers
ISVs
Write WIA applications that use the new COM interfaces
Provide focused experience for different scanners
Provide a superior scanning experience by using imaging filters
and error handling capabilities
Ask the Experts at lunch today
References
Refer to “Security-related Best Practices
for WIA Driver Development” whitepaper
to ensure your WIA drivers work well in
the Local Service security context
http://www.microsoft.com/whdc/device/StillIm
age/default.mspx
Consult general security references
Security topics on MSDN
“Writing Secure Code” (ISBN 0-7356-1588-8)
© 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market
conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.
MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.