next up previous
Next: Subclasses of ImagePresenter Up: QuickTime for Java Previous: The ImageSpec Interface

QuickTime For Java Presenters

When QuickTime plays back a movie, it does not generally read all of its media data into memory but rather reads chunks of data as required. A movie can be constructed that requires the media data to be loaded into memory or other parameters that will require more memory to be used but will generally improve the quality of the rendered movie. The QuickTime API documentation covers these customisations that a movie's author can make.

Due to the usefulness of, and in some cases requirement for, loading media data into memory, QuickTime for Java provides presenters. A presenter is an object that renders media data that is loaded or resides in memory. A presenter also uses a QuickTime service to render this media data.

QuickTime for Java has a built in ImagePresenter for rendering image data. The ImagePresenter class implements the QTDrawable interface. The ImagePresenter uses a DSequence to perform the rendering of the image data. It is the primary object that is used in QuickTime for Java to render image data. The TwoDSprite is also a presenter that presents image data loaded into memory. However, its role is specific to the membership of its Sprite in a SpriteWorld (which is represented in QuickTime for Java by the SWCompositor).

Though only an ImagePresenter is provided in the current release of QT4Java, a similar design strategy could be employed with other media types. For example, let's consider the music media type. MusicMedia is rendered in QuickTime by the TunePlayer class. A MusicPresenter class could be created that used the TunePlayer to render the MusicData. A MusicSpec interface could be described that returns a MusicDescription and the raw MusicData of the tune events.

The ImagePresenter manages the varying state and conditions of use of QuickTime's DSequence renderer. It is a useful abstraction because it hides such details from the user, creating a robust and reusable class.

The ImagePresenter is able to render its data faster than its corollary GraphicsImporterDrawer, which also implements the QTDrawable interface, for two reasons. First, the data is kept in memory and so it is quicker to read. (The GraphicsImporteDrawer reads its image data from its DataRef, typically a file.) Second, the image data of an ImagePresenter can be (and often is) kept in a format that is optimized for rendering or decompression. However, a GraphicsImporteDrawer will use less memory and is often more than sufficient for presenting an image where no demanding rendering tasks are required, such as constant, time-sensitive redrawing.

An ImagePresenter object can be created from many sources. For example, from a file:

ImagePresenter myImage = ImagePresenter.fromFile(imageFile);

In this case, the ImagePresenter will create a GraphicsImporter to read and load into memory the image data from the file. It will then decompress the image if necessary to a format optimized for rendering.

You can also create an ImagePresenter from generated image data and an ImageDescription that describes it:

int width = 100;
int height = 100;
IntEncodedImage myImageData = new IntEncodedImage (width * height);
//...fill in pixel values using standard java ARGB ordering
ImageDescription myDescription =
ImageDescription.getJavaDefaultPixelDescription (width,
height);
myDescription.setDataSize (myImageData.getSize());
ImagePresenter myPresenter =  ImagePresenter.fromQTImage(myImageData,
myDescription);

You can also create an ImagePresenter object from an onscreen or offscreen QDGraphics that you have previously drawn into:

QDGraphics gWorld = ....
Rect rect = ....
int colorDepth = ....
int quality = ....
int codecType = ....
CodecComponent codec = ....
ImagePresenter myIP = ImagePresenter.fromGWorld (myGWorld,
          myGWorld.getBounds(),
          myGWorld.getPixMap().getPixelSize(),
          myDerivedCompressionQuality,
          myDerivedCompressionType,
          myDerivedCodecComponent);



 
next up previous
Next: Subclasses of ImagePresenter Up: QuickTime for Java Previous: The ImageSpec Interface
Dave Marshall
10/4/2001