Click here to learn
about this Sponsor:
Home  |  News  |  Articles  |  Forum

  Home arrow Linux For Devices Articles arrow ELJonline:
Programming for EyeTap Systems


ELJonline:
Programming for EyeTap Systems

By Linux Devices

Rate This Article: Add This Article To:

An "EyeTap" is a camera/processor/display device you can wear. Here, two real-life cyborgs play by reversing X displays.



Over the past few years, we have been working on a number of programming environments for EyeTap systems. A common feature of EyeTap systems is the diverter, which renders image content as left-right reversed or top-bottom reversed. Accordingly, we have been developing a number of options and methodologies for dealing with the problem of reversed display.

Although early cathode-ray-tube EyeTap systems relied on swapping deflection yoke wires (in color EyeTaps one must be careful to swap only the horizontal yoke wiring, otherwise images are chopped off because of the critical timing of the filter wheel as synchronized with the vertical deflection), certain conditions arise where it is inconvenient to reverse the hardware.

Moreover, because the sensor apparatus (whether it be a camera or similar sensory system) also sees the world in reverse, it is often desired that the display actually portray a backward image to compensate properly, and thus the two will reverse each other and cancel out. Without reversing X, images would appear to the viewer as shown in Figure 1.

figure

Figure 1. An Image without Reversing X


One early attempt was a program called caplive, developed by Mann and extended by Mann, Fung and several others into something called xcaplive, along with a set of utilities called glinaccess, meant for use with EyeTap systems.

More recently, a thesis project proposed by Mann and carried out by Manders involved the reversal of XFree86 to facilitate use of XFree86 with an EyeTap system.

With the restructuring of the XFree86 code of late, XFree86 4.0.x has provided an easy means of left-right reversing the Xserver. Specifically, new installations of XFree86 version 4.0.x have an option to make use of a shadow buffer. In a regular install of XFree86 4.0, most chipsets will offer the option of rotating the Xserver by pi/4 radians. This is due to the efforts of Mark Vojkovich.

The initial code provided in the XFree86 4.0 distribution performs a harder task than what is needed to left-right reverse the Xserver. Any one of the drivers provided in XFree86 4.0 will have essentially the same structure that will be discussed here later on, but for the purpose of example, the NVIDIA driver (nv) has been chosen. Note that this manipulation has been performed successfully on almost all of the XFree86 4.0 drivers.

First, it is advantageous to examine the code to which the necessary modifications will occur. After expanding the XFree86 4.0 source code (available at ftp://ftp.xfree86.org/), we get the file .../xc/programs/Xserver/hw/xfree86/drivers/nv/nv_shadow.c. Listing 1 comes from this file.

Listing 1. Code from nv_shadow.c


Now, this code is active when the Shadow Buffer option is selected in the XFree86Config file. All it is doing is writing from allocated memory to the graphics card. Understanding this code is not that difficult if we consider what some of the variables are.

The sections of the hardware memory-mapped regions (pointed to by pNv->FbStart) that need to be redrawn because of changes are outlined by pboxes. A pbox is simply a set of four offsets, two x offsets and two y offsets, and num is the number of pboxes that need to be redrawn. The width and height of the pboxes may be calculated from these offsets.

The code in Listing 1 redraws on pbox at some time upon each iteration of the outer while loop, and src and dst are the memory addresses of the source and destination addresses in memory. The real changes that need to be made are that we must write the rgb information to the destination maintaining the order of the rgb bits, but one level of abstraction higher. These bit groups must be written in reverse order. This means we must write the pixels out in the destination starting from the pbox x coordinate opposite to the code in Listing 1. This may be accomplished by changing the following:


dst = pNv->FbStart + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp);

to


dst = pNv->FbStart + (pbox->y1 * FBPitch) + ((pScrn->virtualX - pbox->x1) * Bpp)

This will get us to the other end of the pbox in the representation in memory.

At this point, the code is beginning to read the source address from the correct location. For each horizontal line, the actual groups of rgb bits must be written out in reverse. This implies that the inner while must change as well.

Unfortunately, we can't write the bits out one "width" at a time (which is what the memcpy is doing in the original code). We must traverse the sections in finer increments, which leads us to change


while(height -- ) {
memcpy(dst,src,width);
dst += FBPitch;
src += pNv->ShadowPitch;
}

to


while(height -- ) {
for (i= 0; i memcpy(dst-i, src+i, Bpp);
dst += FBPitch;
src += pNv->ShadowPitch;
}

The previous code takes care of the painting of the pixels. Next we need to correct the positioning of the mouse (which is not yet reversed). A subrountine at the start of nv_shadow.c, named NVPointerMoved, allows us to do this. If we look at the NVPointerMoved subroutine, the code is used to change x coordinates to y coordinates and similarly to change y to x. This is, of course, not needed to reverse the Xserver, but the code may be modified to perform the function needed. Listing 2 has been commented to outline the necessary modifications.

Listing 2. Modifications to the NVPointerMoved Subroutine


What has been done in the new section of code is to take the original y coordinate and leave it unchanged and subtract the original x coordinate from width of the screen. This is all that is needed for left-right reversing the mouse. The variable pNv->Flip is important and will be explained in what follows.

To highlight further all the changes that have been made to this point, a completely modified example of nv_shadow.c is available [see Listing 3 at ftp://ftp.ssc.com/pub/elj/listings/issue06/4779.tgz].

The changes so far will left-right reverse the Xserver; now all that is needed is to get the driver to call it. Certainly the easiest way is to add an option to the XFree86Config file such that when called, the Xserver would be left-right reversed.

We need to get our new option (which we will call FlipLR) parsed by the driver. Specifically, when we add option "FlipLR" to the device section of the XFree86Config file we want to have our Xserver reversed.

Taking a careful look at nv_driver.c around line 299 [see Listing 4 at ftp://ftp.ssc.com/pub/elj/listings/issue06/4779.tgz], we find the structure shown in Listing 5.

Listing 5. Code from nv_driver.c


These are the usual options available to the driver. They will differ slightly from driver to driver, but some similar structure exists in each of the drivers. What is needed in the structure is a line that should appear as:


/* our new cyborg enhanced option */
{ OPTION_FLIP, "FlipLR", OPTV_BOOLEAN, {0}, FALSE },

The subroutine NVPreInit is used to parse the XFree86Config file and set various structure parameters to the correct values. The lines that need to be added can occur within a wide range of the subroutine. In keeping with the overall design, with the NVIDIA driver, it makes sense to add some code at line 1061 (right after the Rotate option is parsed):


if ((s = xf86GetOptValString(NVOptions, OPTION_FLIP))){
pNv->ShadowFB = TRUE;
pNv->NoAccel = TRUE;
pNv->HWCursor = FALSE;
pNv->Flip = TRUE;
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
"Left Right Reversing the screen - acceleration
disabled\n");
}

This will set the required variables in the pNv structure to the values necessary for left-right reversing the Xserver. At this point, the field pNv->Flip doesn't exist. This needs to be added to the header file and will be dealt with later.

If the variable pNv->Flip did in fact exist, we would have parsed the XFree86Config file properly. Now what is necessary is to have the function NVRefreshAreaFlip used when needed. This is done in NVScreenInit. Within NVScreenInit, there is a section dealing with the shadow buffer. Using a reasonable editor to make the changes, you can search for the string "if(pNv->ShadowFB)" in the NVIDIA driver; this occurs around line 1,779 of nv_driver.c. The original piece of code is shown in Listing 6.

Listing 6. Code from nv_driver.c


Since we want to add in the left-right reverse functionality, we can modify Listing 6 to consider our reverse X cyborg option by changing it to what's shown in Listing 7.

Listing 7. Adding Left-Right Reverse Functionality to NVScreenInit


All that is left to do is add the appropriate entries to the header file. The name of this file varies depending on the driver. Of course it is always a .h file, and that narrows the field greatly. All drivers will have a similar header, but for the NVIDIA driver, the file is nv_type.h. If the modifications are on a different driver, it's probably best to look at the NVIDIA .h file and grep for some similar entries in the directory of the driver that is being modified.

The pNv->Flip field must be defined. There is a struct that will be similar to Listing 8. To this listing we simply want to add the entry


Bool Flip;

Listing 8. Defining the pNv->Flip Field


Lastly, we want to add our newly created function for left-right reversing to the header. This probably belongs here


void NVRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);

and should be declared as


void NVRefreshAreaFlip(ScrnInfoPtr pScrn, int num, BoxPtr pbox);

Now, we may safely reverse the Xserver by adding the line Option "FlipLR" to the XFree86 4.0 XFree86Config file, which should be located in the directory /etc/X11.

Just in case any of the modifications above were not clear, a modified version of the nv_driver.c is available [see Listing 4 at ftp://ftp.ssc.com/pub/elj/listings/issue06/4779.tgz], and the header file nv_type.h also is available [see Listing 9 at ftp://ftp.ssc.com/pub/elj/listings/issue06/4779.tgz].



About the authors:

Dr. Steve Mann is regarded by many as the inventor of the wearable computer, of the EyeTap camera (a device that causes the eye itself to function as if it were a camera) and of the Reality Mediator (wearable image processor for the visually challenged, http://wearcam.org/mr.htm). He is currently a faculty member at the University of Toronto, Department of Electrical and Computer Engineering.


Corey Manders currently holds degrees in Computer Science (University of Toronto) and Fine Arts (York University) and will begin a Master's Degree in Applied Science at the University of Toronto starting in September 2001 under the supervision of Professor Steve Mann. For the last year he has been a resident cyborg in Mann's Humanistic Intelligence Lab.




Copyright © 2001 Specialized Systems Consultants, Inc. All rights reserved. Embedded Linux Journal Online is a cooperative project of Embedded Linux Journal and LinuxDevices.com.




Programming-for-EyeTap-Systems/ class=sidenav>Discuss ELJonline:
Programming for EyeTap Systems
 
>>> Programming-for-EyeTap-Systems/ class=sidenav>Be the FIRST to comment on this article!
 
 
 
>>> More Linux For Devices Articles Articles          >>> More By Linux Devices
 



FUEL Database on MontaVista Linux
Whether building a mobile handset, a car navigation system, a package tracking device, or a home entertainment console, developers need capable software systems, including an operating system, development tools, and supporting libraries, to gain maximum benefit from their hardware platform and to meet aggressive time-to-market goals.

Breaking New Ground: The Evolution of Linux Clustering
With a platform comprising a complete Linux distribution, enhanced for clustering, and tailored for HPC, Penguin Computing¿s Scyld Software provides the building blocks for organizations from enterprises to workgroups to deploy, manage, and maintain Linux clusters, regardless of their size.

Data Monitoring with NightStar LX
Unlike ordinary debuggers, NightStar LX doesn¿t leave you stranded in the dark. It¿s more than just a debugger, it¿s a whole suite of integrated diagnostic tools designed for time-critical Linux applications to reduce test time, increase productivity and lower costs. You can debug, monitor, analyze and tune with minimal intrusion, so you see real execution behavior. And that¿s positively illuminating.

Virtualizing Service Provider Networks with Vyatta
This paper highlights Vyatta's unique ability to virtualize networking functions using Vyatta's secure routing software in service provider environments.

High Availability Messaging Solution Using AXIGEN, Heartbeat and DRBD
This white paper discusses a high-availability messaging solution relying on the AXIGEN Mail Server, Heartbeat and DRBD. Solution architecture and implementation, as well as benefits of using AXIGEN for this setup are all presented in detail.

Understanding the Financial Benefits of Open Source
Will open source pay off? Open source is becoming standard within enterprises, often because of cost savings. Find out how much of a financial impact it can have on your organization. Get this methodology and calculator now, compliments of JBoss.

Embedded Hardware and OS Technology Empower PC-Based Platforms
The modern embedded computer is the jack of all trades appearing in many forms.

Data Management for Real-Time Distributed Systems
This paper provides an overview of the network-centric computing model, data distribution services, and distributed data management. It then describes how the SkyBoard integration and synchronization service, coupled with an implementation of the OMG¿s Data Distribution Service (DDS) standard, can be used to create an efficient data distribution, storage, and retrieval system.

7 Advantages of D2D Backup
For decades, tape has been the backup medium of choice. But, now, disk-to-disk (D2D) backup is gaining in favor. Learn why you should make the move in this whitepaper.

Got a HOT tip?   please tell us!
Free weekly newsletter
Enter your email...
PLATINUM SPONSORS
 
 
 
 
 
 

GOLD SPONSORS


(Become a sponsor)

(Become a sponsor)

ADVERTISEMENT
(Advertise here)

Check out the latest Linux powered...

Mobile phones!

MIDs, UMPCs
& tablets

Mobile devices

Other cool
gadgets

Resource Library

• Unix, Linux Uptime and Reliability Increase: Patch Management Woes Plague Windows Yankee Group survey finds IBM AIX Unix is highest in ...
• Scalable, Fault-Tolerant NAS for Oracle - The Next Generation For several years NAS has been evolving as a storage ...
• Managing Software Intellectual Property in an Open Source World This whitepaper draws on the experiences of the Black Duck ...
• Open Source Security Myths Dispelled Is it risky to trust mission-critical infrastructure to open source ...
• Bringing IT Operations Management to Open Source & Beyond Download this IDC analyst report to learn how open source ...


BREAKING NEWS

• NAS system houses 2.5-inch drives for up to 6TB
• Atom SBC boasts special low-power mode
• Android leaps to rugged handheld, and more phones
• Simulator runs Android apps on Ubuntu
• Fanless industrial PC taps Atom
• Router platform runs OpenWRT Linux
• Feature-packed UMPC survives four-foot drops
• UMPC pioneer gives up the ghost
• Biodegradable, solar-powered netbook runs Linux
• Hypervisor rev'd for higher reliability
• Eurotech spins Atom development kits
• Home media server to demo on Intel Atom platform
• Atom boards feature fanless DC operation
• Low-cost pluggable NAS adds Linux support
• Taiwan open source conference sets agenda


Most popular stories -- past 90 days:
• Linux boots in 2.97 seconds
• Tiniest Linux system, yet?
• Linux powers "cloud" gaming console
• Report: T-Mobile sells out first 1.5 million G1s
• Open set-top box ships
• E17 adapted to Linux devices, demo'd on Treo650
• Android debuts
• First ALP Linux smartphone?
• Cortex-A8 gaming handheld runs Linux
• Ubuntu announces ARM port


DesktopLinux headlines:
• Simulator runs Android apps on Ubuntu
• Hypervisor rev'd for higher reliability
• Pluggable NAS now supports Linux desktops
• Moblin v2 beta targets netbooks
• Linux-ready netbook touted as "Student rugged"
• USB display technology heading for Linux
• Ubuntu One takes baby step to the cloud
• Game over for Linux netbooks?
• Linux Foundation relaunches Linux web site
• Dell spins lower-cost netbook


Also visit our sister site:


Sign up for LinuxForDevices.com's...

news feed


Or, follow us on Twitter...