Issue 4-23, June 9, 1999

Be Engineering Insights: Persistence of Vision

By Michael Morrissey

Recently, Ficus Kirkpatrick and I were musing about how to combine what he was working on (video stuff) with what I was working on (printing). My suggestion, something along the lines of finding a 60-page-per-second printer, was put down soundly. Ficus had a better idea: How about a little application to generate flipbooks from movie files? I was intrigued. So, with a little schooling about the new BMediaFile and BMediaTrack classes from Jeff Bush, a newsletter article was born:

<ftp://ftp.be.com/pub/samples/interface_kit/flipbook.zip>

Open the source code and follow along!

To use this little app, you'll need at least one movie, preferably one that shows a lot of motion. Drop the movie onto the app's window (or open it through the file panel). Notice the Print Information box. The first item, "Number of flip pages," tells you how many flip pages will be printed out. This is controlled by the "Print one frame per..." text control: printing one frame per 2, say, will print every other frame of the movie. The next item, "Flip pages per printed page," lets you know how many flip pages can be tiled onto a single printed page. This is affected by the paper size you choose in Page Setup. Finally, "Number of printed pages" does the arithmetic for you, showing how many pages this little movie will cost you. The "Generate" button produces and prints the flipbook.

Even if you don't have a printer, you can still have fun: just create a Preview printer to see what the pages look like. Using the Preview printer is also a useful way to see if your flipbook has enough, or too many, pages, without wasting lots of time and paper. (To create a Preview printer, go to the Printers Preferences panel, click "Add...," choose "Local Printer" and press "Continue," and select "Preview" from the "Printer Type" menu.)

The sample code uses a few features of the BPrintJob class that are new to R4.5. PageRect() and PrintableRect() can now be called on BPrintJobs which haven't been set up yet, either through the user running PageSetup(), or through a call to SetSettings(). In this case, these functions return the printer's default Page rectangle and the printer's default Printable rectangle. This is how we can suggest "Number of flip pages per printed page" even though the user hasn't yet run Page Setup -- we're using the printer's default Printable rectangle. (I won't go into how this is implemented on the printer driver side. If you're writing a printer driver, contact me for details.)

A new BPrintJob function that wasn't used in this sample code is GetResolution(), which returns the printer's resolution in the horizontal and vertical directions. Like PageRect() and PrintableRect(), it returns the printer driver's default settings if the BPrintJob has not yet been set up, and the user-selected resolution if it has been set up.

You'll also notice a new message being caught in FlipApp::MessageReceived(): B_PRINTER_CHANGED. In R4.5, this message is broadcast to all running applications when the user switches the default printer through the Printers Preferences panel, allowing applications to handle this change. Applications should, at a minimum, discard the previous printer's settings message and call ConfigPage() the next time the user invokes printing, rather than going directly to ConfigJob().

The application itself is straightforward. After receiving an entry ref, either from the Open dialog or through a drag-n-drop message, we open it through BMediaFile. We then step through the BMediaTracks, looking for one of type B_MEDIA_ENCODED_VIDEO. Upon finding such a track, we create a bitmap of the appropriate size, and tell the BMediaTrack that when we ask for a frame of video, it should return raw video. This "asking for a frame" occurs when we call BMediaTrack::ReadFrame(), where we pass in the aforementioned bitmap, which is populated with the video frame. Playing the movie, then, is nothing but a loop of calls to ReadFrame() followed by DrawBitmap(). (See FlipView::GenerateFlipbook().)

One way that Flipbook differs from most applications is that the "document" as such doesn't exist before we print. In fact, we don't even create a whole page before it is printed: doing so would needlessly consume memory (a full page of 32-bit bitmaps is costly!). Instead, we do it piecemeal: given a video frame, we create a flipbook page, determine where this flipbook page should be placed on the printed page, and then call BPrintJob::DrawView().

In DrawView(), the BPrintJob writes the drawing commands which describe this flipbook page out to the spool file, along with the BPoint which determines where it is to be placed on the printed page. We can create the document this way, piece-by-piece, because until BPrintJob::SpoolPage() is called, the BPrintJob is working only on one page, regardless of how many DrawView() commands are issued.

As always, I encourage you to twist the code to suit your own purposes. The illustrious Miss Melanie Walker informs me that there are companies that produce heavy, perforated paper specifically designed for making flipbooks. I haven't had a chance to find such paper yet, but if you do, you'll probably need to tweak the Layout code to match the perforation marks. (Don't be afraid to call SetScale(), in combination with GetResolution(), to get just the right size image.) Enjoy!


Developers' Workshop: Hell.com is Other People's Web Sites

By Doug Fulton

On the internet there is beer but no god. I found this out the other night when I was typing random domain names into NetPositive. Beer.com is the "official beer of the internet." God.com draws a blank. However, there is a Jesus.com ("New Chat Services Available!"), and a Buddha.com, which takes you to an online shopping site. In an emergency, visit angels.com: "This site is for emergency response when a disaster occurs and fellow human beings are in extreme danger. " Unfortunately, the site isn't ready yet even though it appears they've been working on it since 1995. So far, they offer a single solution to all emergencies: Send e-mail to archangel@angels.net.

There *is* a dog (dog.com, a site devoted to dogs), a cat (the Caterpillar tractor company, which assures us that their tractors are Y2K safe. That's a relief), a giraffe (bad art by the self-dubbed "Digital Giraffe"), a penguin (the paperback book publisher), and an ant (the Antagonist Games Network, featuring "Maimed in Illinois", "Tomorrow Never Dies", and the nightmarish "Jack Nicklaus 6: Golden Bear Challenge"), Hen.com is a photo album of a minutes-old newborn baby. My favorites: Baby lying in what appears to be a polyester jacket with a touch tone phone disturbingly close to his head, and Baby striking a Nosferatu pose, his perspective-distorted hands clawing at the camera. Mother and child are doing fine. (Or they were--the baby was born in July, 1997, and the site hasn't been updated since. But I'm sure his parent still love him.)

Whereas paranoia.com is merely suspicious, paranoid.com is belligerent: "We're not ready yet for you to view the Paranoia Family Tree. Why don't you try again in 2000? Get it? 2000??" . No, actually, I don't get it. But that's okay, I'll just back out and close the door quietly, alright? Suspicious.com appears to be Linux propaganda. Belligerent.com is a snow board shop. Attitude is one thing; whining is something else: There's no whine, or bad-mood, or cranky.com.

On to philosophy. There's an Erasmus.com (fittingly, a dutch insurance company), an Aristotle.com (unfittingly, an "internet in the grade schools" vomitorium--don't get me started). There's also a Schopenhauer.com, but it's owned by squatters. $500 and it's yours. $600 and we'll thrown in Hegel. And, of course, there is a Nietzche (and still no god--he was right after all). Nietzsche.com features inappropriate angels-in-infinity images, a couple of quotes, and the rather disturbing tag line "The Countdown has Begun." Poor Friedrich-- first the Nazis, now this.

Speaking of the auction block, MaryPoppins.com is for sale, also for $500. BouncingTigger.com will set you back a grand. Reformulated as Schopenhauer+Poppins=Tigger (or 19th century German pessimism + pseudo- Edwardian magic realism = mindless euphoria), this seems about right. As with most squatted domain names, the price for MaryPoppins (and BouncingTigger) is negotiable. Not so TheGodfather.com. That'll be $1500--no discussion--and you won't have any more spam troubles.

I was surprised that www.com.com is up for grabs, as is www.dot.com. But www.wwwdotcom.com, www.www.com, and www.dotcom.com are taken. The last of these is a domain name registry company that offers only "HIGH QUALITY" domain names that were developed "IN-HOUSE" using "sophisticated software analysis, web spider technology, and real- humans linguistics". But not, evidently, real-humans grammar.

The_end.com gives you "the psychosis of tomorrow at yesterday's prices." Sure. Theend.com is under construction. There is no heaven, but there really is a hell.


Are We There Yet?

By Jean-Louis Gassée

I mean—have we arrived in USB Heaven? In a previous column "Organic Pace of Change", I lamented the glacial speed of the reaction between the USB standard and the donors to PC clone organ bank. Ironically, Apple, the inventor of FireWire, took the leadership position in delivering meaningful USB hardware.

Some will say that Apple's impulse to run with USB was taken in the inimitable iCEO style. Others, such as yours truly, remember 1985, when analysts where calling Apple names for using the nonstandard 3.5" floppy instead of the proven 5.25" flavor favored by "serious" companies. Now it looks as if the x86 industry is starting to use the connectors that have been in the back of most PCs for more than 2 years. Fry's, my personal testing ground for what really sells (as opposed to what merely generates press releases) now has a nicely stocked USB section, not just for best-selling iMacs but also for "mere" PCs.

The Fry's test was reason enough for me to take the plunge. At home, I have a dual processor, dual boot system that is the source of both mirth and hand-wringing for Be engineers. With USB support on both sides of the dual boot, I could install USB peripherals. These offer less trouble, less competition for IRQs, CEO-proof connectivity in Windows 98, along with the extra-added benefit of death to ISA, serial ports, and LPTs.

I started with what I thought was a simple project—connecting an HP printer. Trying to be a good user, I connected everything with the power off, started my system, and told System Commander to launch Windows 98. Following the Plug&Play model, Windows announced it had detected new hardware and was installing the software for it. The HP installation CD-ROM auto-ran and I proceeded to install the printer software. I restarted the computer and... the printer was kind of detected but wouldn't print. The diagnostic software said it could only establish one-way communication.

No problem—just check cables and connections, test whether the printer will print off-line. Yes, it does! So, uninstall the software and try again—I must have gone through the steps too quickly the first time. Second try—same symptoms. A third try doesn't cure them. When all else fails, RTFM, read the fabulous manual. Hmmmm, I was a little too quick. I wasn't supposed to connect everything before turning the power on—just everything but the USB cable between the computer and the printer. Start Windows and, when it's finished launching, plug in the cable. The rest of the installation goes as expected and the printer works like a charm. I should have read the instructions instead of assuming I knew how P&P worked.

Needless to say, I'm tempted to contrast this with the way we connect devices via USB or modify network settings without having to restart the system. Emboldened by this experience, however, I decided to install another USB device, a CompactFlash reader, handy with a digital camera, costs $79, comes with a cable. And, even if you don't have (yet) BeOS drivers for it, the BeOS lets you grab those JPEG files in the Windows partition—which makes for nice demos and even nicer every day experience.

This time, I read the instructions carefully, and I'm baffled: the leaflet says I'll have to go through the software install three times. That's what I just did with the printer, but that was my mistake, sort of. And I don't plug the cable before launching Windows, but after. Windows detects the new hardware, asks for a pointer to a CD-ROM for software, gets to the "Finish" button, closes the installer, and immediately detects new hardware, declares it will install software for it, gets to "Finish" again, the installer closes again, and the process happens a third time.

The USB Compact Flash reader works, the Comdex pictures are there, and everything is fine. Sort of. Curiosity leads me to the Device Manager, to check the results of the three install phases. Everything appears in working order, no red flags or question marks. I have an E: drive now, the USB devices look normal, but now the system tells me I have a SCSI device as well. I swear under oath that I don't have SCSI hardware on my system, Your Honor. It's bizarre—the promised simplicity isn't quite there.

Still, let's consider the glass as more than half-full. With more USB hardware available, this is an opportunity to demonstrate that we do indeed offer a smoother, simpler user experience. And let's conclude on an upbeat note, if you'll pardon the forward reference: a USB guitar. Virtual DSP, a Seattle company, offers one. On today's version, on-board electronics do the pitch detection and the conversion to MIDI data passed on to the computer via the USB connection. Nice. And possibly even nicer: the low latency offered by the BeOS might allow most of the processing to be done inside the system. As a result, the complexity of the on-board electronics on the USB guitar could be dramatically reduced, cutting the cost of down to tens instead of hundreds of dollars.

Creative Commons License
Legal Notice
This work is licensed under a Creative Commons Attribution-Non commercial-No Derivative Works 3.0 License.