Use Quartz image filters in Preview for macOS to apply special effects to your images.
0 Facebook x.com Reddit
Core Graphics provides default image filters for quickly applying special effects. Here's how to save image files in Preview for macOS with effects.
Apple's Core Graphics (Quartz) 2D imaging subsystem provides a high-performance, consistent API for creating, saving, and manipulating graphics. It's also responsible for rendering most text on Apple platforms (Core Text).
Text can be rendered by Quartz using subpixel precision and anti-aliasing (anti-aliasing), even if a particular display can't display the text at full computed resolution.
Quartz is extensive, covering nearly every aspect of 2D imaging on Apple operating systems, including iOS and macOS. Quartz is one of Apple's oldest platforms, debuting with Mac OS X.
The rendering model is based on compositing, in which multiple graphics layers can be combined with transparency (alpha), manipulated, transformed, saved, printed, or copied to a display.
The Quartz compositor is responsible for assembling and processing images, combining images and rotating, applying transforms, or shaping images. Once the final image is assembled, the display engine moves (or “blits”) the image to the display or printer.
For macOS, the window server additionally handles image culling and hiding to ensure that images intended for specific windows remain only in those windows.
The macOS window server itself uses the Quartz Compositor when assembling window contents.
To improve performance, the window server knows how to crop images so that only the parts visible in the windows are drawn. For example, when you click between windows in macOS, parts of the windows are hidden behind other windows.
By cropping images during display, the window server greatly improves rendering performance because it doesn't have to draw the entire contents of a window if part of it is hidden.
When Mac OS X was first released in 2000, the graphics engine and frameworks were the most advanced in the computing industry.
iOS devices work much like Macs, except they don't use a dedicated window server like macOS. Both use the same Quartz framework and API.
Almost everything on Macs and iOS devices is rendered using Quartz. This includes individual images and image files, as well as much of macOS itself and the contents of its windows.
In Mac OS X Tiger 10.4, Apple introduced Quartz 2D Extreme, which allows Quartz graphics to be offloaded to a dedicated GPU. In 10.5, Apple renamed Quartz Extreme to QuartzGL.
Quartz Compositor also uses QuartzGL to speed up rendering when a dedicated GPU is available.
Apple previously released an app called Quartz Composer, which is now discontinued.
Quartz Composer app from Apple.
Based on Geometry
What you see drawn on the screen or printed is only a close approximation of the graphics that Quartz actually computes. Quartz uses mathematical models behind the scenes to actually compute the graphics it's going to draw, unless the graphics are bitmaps, which exist as a page of pre-rendered pixels.
The mathematical models of such graphics are sometimes called vector graphics because they are first calculated using geometry, regardless of how they will be displayed or printed.
Vector graphics have the great advantage of being scalable to any size. To make an image larger or smaller, simply resample the image at a different scale or apply a scaling transformation before the graphic is drawn.
Transformations are mathematical adjustments applied to images to change their size or shape. When you rotate or warp an image in an image editing program, or when you manipulate a 3D object in space, you are applying a transformation to the model, which is then redrawn.
Transformations can also be applied to raster images, although this usually results in some distortion of the original image.
Bézier curves describe curved vector graphics, typically with a starting point, control points, one or more degrees of curvature, and shaping points or “handles” that can be used to change the shape of the curves. If you've ever used a vector graphics application like Adobe Illustrator, you've probably used Bézier curves to change the shape of objects.
For example, fonts use Bézier curve geometry and vector graphics to describe their outlines (strokes) that draw each character individually. When you change the font or font size for text in a document on macOS, you reapply the new calculation for each character you draw.
Each font file on macOS contains instructions on how to draw each text character in a given typeface.
Quartz Display Services
Quartz contains an additional subsystem called Quartz Display Services (QDS), which mainly deals with hardware displays themselves. Initially a very small API, QDS has now expanded to dozens of APIs handling:
- Find and identify displays
- Change display properties
- Configure all display configurations at once
- Capture a display
- Stream the contents of your displays
- Use fading effects
- Enable display mirroring
- Apply gamma and color correction
- Get updates on display changes
If you've ever changed the resolution of your displays or moved the main menu bar to another display in System Preferences, you've used QDS.
macOS apps must include code to receive notifications of display changes so they can reconfigure their windows and window contents to accommodate the new display properties.
The connected display that contains the macOS menu bar is called the primary display. Each display is assigned a DisplayID (32-bit CGDirectDisplayID) by macOS at startup.
Data Types
Quartz defines its own set of drawing primitives for use in graphics computations (which are described in the Core Graphics documentation). These primitives include everything from individual integers and floating-point numbers, geometric shapes such as points, dimensions, and rectangles, to paths, vectors, and transforms.
There are also display contexts, images (for bitmaps), layers, and colors and fonts. A display context is defined as a graphics environment in which you can draw.
Typically, each display has a drawing context, but there may also be additional off-screen and composite contexts.
You can also change the properties of drawing contexts to change the appearance of their contents when the context is redrawed.
Most of these data types are made up of simpler individual types. For example, a CGPoint in Quartz is defined as a structure containing two double-precision floating-point numbers: the X and Y coordinates. A CGPoint describes any single point on the display or in a context.
CGRect is made up of two other Quartz types: CGPoint (the starting point) and CGSize (the dimensions). The starting point for drawing in most 2D computer graphics systems is called the origin.
Some 2D systems measure distances from the upper-left corner to the right and down, others from the lower-left corner to the right and up.
Quartz also defines layers (CGLayer), each of which can be drawn individually, combined, and animated.
Another Apple framework called Core Animation can use layers (CALayer) to smoothly animate multiple graphic layers at once.
Adobe Portable Document Format (PDF) file.
PDF Files
PDF files are handled separately from Quartz on Apple platforms, except for their final rendering for display or printing. This is because PDF was originally an Adobe standard that used PostScript for rendering.
NeXT computers had a similar PostScript-based system called Display Postscript, which used Adobe technology for display and print rendering. PostScript also used vector graphics in its graphics calculations to provide smooth drawing at any scale.
While PDF is not an Apple technology, Quartz provides a data type for PDF called CGPDFDocument. This data type gets its contents from another Quartz type called CGDataProvider.
Using these two data types, you can create a representation of a PDF document for display or printing. You can also initialize a CGPDFDocument directly from a file or URL.
CGPSConverter is a Quartz type that can be used to directly convert to PDF files and legacy PostScript code. Older printers have PostScript built into the ROM, so they can receive and print PostScript and PDF files.
Apple has several other image and file processing frameworks, including ImageKit, PDFKit, Quartz Composer (now largely deprecated), and Quick Look.
Quartz and Preview
The Preview app for macOS is essentially a Quartz and PDF rendering app that can also display raster images.
Preview uses Quartz to layout and display files and images just like macOS does. It can run all the drawing commands and convert any other Quartz application.
It also knows how to display PDF and PostScript files directly in windows, and how to send them to laser or inkjet printers. When you open a PDF file in Preview, it uses the Quartz API to map the PDF drawing commands to be displayed on-screen in Apple's native system.
Quartz and Filters
Once everything is ready for display, you can apply Quartz filters (CIFilter) to apply special effects when displaying, saving, or printing graphics and image files. You can also apply image filters to PDF files using Apple's ColorSync technology.
Quartz provides a predefined set of standard filters that essentially apply familiar photographic-type effects to images, but you can also define and apply custom filters. macOS also includes a Filter Manager that is used to add, remove, and manage image filters.
CIFilters can be complex, but they rely on just two Quartz data types: CIImage and CIContext. CIImage is essentially an image generator that either takes an existing image as input or draws it into a CIContext to create a new image.
You don't have to worry about how images are modified with CIFilters – Apple has all of that code built in: you just choose the filter you want to use and specify an existing image or drawing context to modify, and Quartz does its thing.
It also standardizes filter effects so that they are consistent across all Mac platform software as long as the Quartz API is used.
After applying the selected filter, a new CIImage is output, ready for use. You can also apply CIColor to an image to change its overall color cast.
Apple also provides built-in filters for modifying geometry, compositing, gradients, lens effects, and more. All of the built-in filters are grouped into categories using constants that begin with “CI.” One group called CICategoryStylize offers several dozen ways to make images look like photographs, newsprint, comic books, and stained glass.
You've probably seen these types of effects in applications like Adobe Photoshop.
There are now hundreds of Apple-defined Quartz filters, which are detailed in the Apple SDK header file CIFilterBuiltins.h. But the best way to see all the filter types is to visit Noah Gilmore's third-party documentation project Core Image Filter Reference.
Gilmore also recommends a five-star Core Image reference app for iPad in the App Store called CIFIlter.io ($5), which details Apple’s built-in filters. Both the site and the app show the iOS and macOS versions each filter is available on.
Apple’s CIThermal filter in Noah Gilmore’s CIFilter.io app.
Applying Filters in Preview
Unfortunately, the Preview app for macOS isn’t yet a full-featured image editor. While you can do some basic things like resize and rotate, it doesn’t currently support common filter effects.
This is too bad, since Apple already ships all the filters in the OS. Currently, all you can do in Preview is draw basic lines and shapes, adjust colors, and add text.
However, in Preview, you can apply a filter when saving a file, but only for a small, select set of predefined filters. In fact, this set is a predefined set of ColorSync Core Image filters, which are located in /Library/ColorSync/Profiles and come with macOS.
To do this, choose File -> Save or Save As, and then from the Quartz Filter menu, choose one of the available filters (if the file format supports it):
Choose a file name, location, format, and the Quartz filter, if the format supports it.
Click the Save button to save the file.
Preview does not yet support applying filters to all file types when saving, including PNG files. Most of the provided filters in the Save preview sheet are for converting to black and white, grayscale, sepia, changing brightness, and optimizing file size.
For PDFs, there is also a custom filter for saving files as a PDFX-3 document, which is primarily used for professional printing.
While this set is limited, it is a quick and easy way to modify image files when saving. Hopefully, Apple will expand the set to include more predefined filters and more file types.
Core Image is a fascinating theme, incredibly simple and useful. If Apple decides to expand its support to macOS and iOS in the future, it will become even more useful.
If you're interested in programming Quartz on Apple platforms, see the outdated Quartz 2D Programming Guide. There's also a great third-party book called Programming with Quartz: 2D and PDF Graphics in Mac OS X.
Follow AppleInsider on Google News