Matrix-Based Drawing

Primitives and copying blocks of pixels are nice, but they’re kind of limiting. Oftentimes, you must take pixels and scale them, rotate them, and move them around. Of course, if you’ve worked with Java 2D, you know this as the concept of affine transformations , which maps one set of pixels to another set of pixels, keeping straight lines straight and parallel lines parallel.

If you’ve really worked with Java 2D’s affine transformations, you probably know that they’re represented as a linear algebra matrix, with coordinates mapped from source to destination by multiplying and/or adding pixel values against coefficients of the matrix. By changing the coefficients in the matrix to interesting values (or trigonometric functions), you can define different kinds of transformations.

QuickTime does exactly the same thing, with the minor exception that rather than hiding the matrix in a wrapper (like J2D’s AffineTransformation class), it puts the matrix front-and-center throughout the API. One reason for this is that it’s also a major part of the file format—tracks in a movie all have a matrix in their metadata to determine how they’re rendered at runtime.

QuickTime matrix manipulation can basically do three things for you:

Translation

Move a block of pixels from one location to another

Rotation

Rotate pixels around a given point

Scaling

Make block bigger or smaller, or change its shape

Tip

This is a lab, not a lecture, so you don’t get the all-singing, all-dancing, all-algebra ...

Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.