Managing data is a task every graphics application needs to perform. For Quartz, data management refers to supplying data to or receiving data from Quartz 2D routines. Some Quartz 2D routines move blocks of data into Quartz, such as those that get image or PDF data from a file or another part of your application. Other routines accept blocks of Quartz data, such as those that write image or PDF data to a file or provide the data to another part of your application.
Quartz provides a variety of functions for managing data. By reading this chapter, you should be able to determine which functions are best for your application. As you’ll see, some routines are available only in Mac OS X v10.4 and later while others have been with Quartz since its beginning.
Note: The preferred way to read and write image data in Mac OS X v10.4 and later is to use the Image I/O framework. See Image I/O Programming Guide. This guide describes how to use the CGImageSourceRef and CGImageDestinationRef opaque data types.
Quartz recognizes three broad categories of data sources and destinations:
URL. Data whose location can be specified as a URL can act as a supplier or receiver of data. You pass a URL to a Quartz function using the Core Foundation data type CFURLRef.
CFData. The Core Foundation data types CFDataRef and CFMutableDataRef are data objects that let simple allocated buffers take on the behavior of Core Foundation objects. CFData is “toll-free bridged” with its Cocoa Foundation counterpart, the NSData class. This means that if you are using Quartz 2D with the Cocoa framework, you can pass an NSData object to any Quartz function that takes a CFData object.
Raw data. You can provide a pointer to data of any type along with a set of callbacks that take care of basic memory management for the data.
The data itself, whether represented by a URL, a CFData object, or a data buffer, can be image data or PDF data. Image data can use any type of file format. Quartz understands most of the common image file formats. Some of the Quartz data management functions work specifically with image data, a few work only with PDF data, while others are more generic and can be used either for PDF or image data.
URL, CFData, and raw data sources and destinations refer to data outside the realm of Mac OS X graphics technologies, as shown in Figure 10-1. Your application can also move data between Quartz 2D and Core Image, which is another Mac OS X graphics technology. Although this is a fairly trivial operation, it’s an important one to keep in mind because Core Image can add impressive capabilities to your graphics application.
These sections provide detailed information on data management in Quartz 2D:
Last updated: 2007-12-11