AdSense Mobile Ad

Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Monday, June 2, 2014

OS X: Creating Packages from the Command Line - Tutorial and a Makefile - Part II

In the previous part of this tutorial we examined how pkgbuild and productbuild are used to build component packages and product archives. We also saw how hdiutil can be used to create a DMG image file to nicely package and distribute your product archive.

Although simple, the procedure is somewhat tedious: lot of typing, three different commands (four or more if we include building), lots of different paths and a many options. All of which, in a precise order, in order to satisfy the dependencies of each commands and to make sure the archives are updated whenever some component file changes.

Exactly what a Makefile is for!

A Makefile to build a Product Archive

All the steps described in the previous part of this tutorial can be automated with a proper Makefile. The Makefile we are going to create is basic, but can be used as a starting point to provide your project a set of ready to go and easy to use make targets to package it into a product archive and distribute it into a DMG file. This Makefile assumes that it is located into your XCode project root directory so that project binaries can be built and installed using

$ xcodebuild install

If this is not the case, just update the relevant action to run the build from the correct directory.

Let's start writing the Makefile in a top-down fashion. Let's add a default all target depending on anything else:
  • $(DISTDIR) is the source folder for the DMG file, where the product archive will be stored.
  • $(DEPSDIR) is an ancillary folder used to store directory. You can add more than one if component packages are stored in multiple folders, or remove it altogether if your product archive will be made up of a single component package.
  • $(PRODUCT) is the product archive.
  • $(DMGFILE) is the DMG image file creating from the source folder $(DISTDIR).
The resulting target is:

.PHONY : all
all : $(DISTDIR) $(DEPSDIR) $(PRODUCT) $(DMGFILE)

$(DISTDIR) and $(DEPSDIR) are created by the Makefile since we assume it is the Makefile that populates them:

$(DISTDIR) :
  mkdir $(DISTDIR)

$(DEPSDIR) :
  mkdir $(DEPSDIR)

$(PRODUCT), the product archive, depends on:
  • $(BINARIES), the main component binaries.
  • $(DEPENDENCY), a placeholder for the dependencies, a set of component packages to add to the product archive. If you have multiple dependencies, you will create multiple entries of this kind. You could omit this entry altogether, since productbuild would fail if a required component package is missing, but I think it is preferable to have make fail because of a missing target dependency.
  • $(COMPONENT_PFILE), the component package property list file.
  • $(COMPONENT), the component package.
  • $(DISTRIBUTION_FILE), the distribution file.
  • $(REQUIREMENTS), the requirements file.

$(PRODUCT) : $(BINARIES) $(REQUIREMENTS) \
             $(DEPENDENCY) $(COMPONENT_PFILE) \
             $(COMPONENT) $(DISTRIBUTION_FILE)
  productbuild --distribution $(DISTRIBUTION_FILE) \
    --resources . \
    --package-path $(DEPSDIR) \
    --package-path $(DEPENDENCYDIR) \
    $(PRODUCT)

The $(BINARIES) are usually compiled and installed with xcodebuild:

$(BINARIES) :
  xcodebuild install

The component package property list file, $(COMPONENT_PFILE), must be created beforehand as seen in the previous post. Let's emit a meaningful error if it is missing referring to a target we will examine later on.

$(COMPONENT_PFILE) :
  @echo "Error: Missing component pfile."
  @echo "Create a component pfile with make compfiles."
  @exit 1

The main component package $(COMPONENT) depends on the binaries $(BINARIES) and the component property list file $(COMPONENT_PFILE) and it must be created with pkgbuild, as seen in the previous part of this tutorial:

$(COMPONENT) : $(BINARIES) $(COMPONENT_PFILE)
  pkgbuild --root $(BINARIES) \
  --component-plist $(COMPONENT_PFILE) \
  $(COMPONENT)

The distribution file $(DISTRIBUTION_FILE), as in the case of $(COMPONENT_PFILE), must be created beforehand. We will emit a meaningful error if it missing referring to a target we will examine later on:

$(DISTRIBUTION_FILE) :
  @echo "Error: Missing distribution file."
  @echo "Create a distribution file with make distfiles."
  @exit 1

Now the Makefile is functional except for one detail: who is going to create the two required property list files $(COMPONENT_PFILE) and $(DISTRIBUTION_FILE)? We have seen in the previous part of this tutorial that both pkgbuild and productbuild can be run in an analysis mode which analyses their input and creates an initial descriptor. We will add two targets to the Makefile that will provide the user a quick way to get initial versions of the required descriptors:

.PHONY : distfiles
distfiles : $(COMPONENT)
  productbuild --synthesize \
  --product $(REQUIREMENTS) \
  --package $(DEPENDENCY) \
  --package $(COMPONENT) \
  $(DISTRIBUTION_FILE).new
  @echo "Edit the $(DISTRIBUTION_FILE).new template to create a suitable $(DISTRIBUTION_FILE) file."

.PHONY : compfiles
compfiles : $(BINARIES)
  pkgbuild --analyze \
  --root $(BINARIES) \
  $(COMPONENT_PFILE).new
  @echo "Edit the $(COMPONENT_PFILE).new template to create a suitable $(COMPONENT_PFILE) file."

Note that in the distfiles target the $(DEPENDENCY) variable is used as argument of the --package option. As explained earlier, you have to either add as many "dependency variables" as required by your product archive, or remove it altogether if the product archive only contains one component package, $(COMPONENT).

The files created by both the distfiles and the compfiles targets must be manually edited by the user and moved to their expected name by removing the .new extension.

Finally, let's add some targets to perform some housekeeping:
  • clean, to remove the DMG file and all the packages.
  • distclean, to remove the distribution files.
  • compclean, to remove the component file.

.PHONY : clean
clean :
  -rm -f $(DMGFILE) $(PRODUCT) $(COMPONENT)
  -rm -rf $(BINARIES)

.PHONY : distclean
distclean :
  -rm -f $(DISTRIBUTION_FILE) $(DISTRIBUTION_FILE).new

.PHONY : compclean
compclean :
  -rm -f $(COMPONENT_PFILE) $(COMPONENT_PFILE).new

Populate the Variables

So far, we have used Makefile variables in our targets and actions in order to decouple the basic Makefile structure from the details of a specific project. Now, variables must be populated for the Makefile to work in every specific project.

This is the typical variable definition block I use at the top of this kind of Makefiles:

PROGRAM = Name
DISTDIR = ./dist
DEPSDIR = ./deps
BINARIES = /tmp/Name.dst
DMGFILE = $(PROGRAM).dmg
PRODUCT = $(DISTDIR)/$(PROGRAM).pkg
COMPONENT = $(DEPSDIR)/$(PROGRAM)Component.pkg
COMPONENT_PFILE = $(PROGRAM).plist
DISTRIBUTION_FILE = distribution.dist
REQUIREMENTS = requirements.plist

PROGRAM is a shared fragment which is typically set to the XCode project name. The DMG file name DMGFILE, the product archive name PRODUCT and the binary installation directory BINARIES are all initialised using this prefix. If want to customise any of these names or adjust any path to your needs, just modify accordingly the corresponding variable.

Use It

The default Makefile target, all, can be executed by simply invoking

$ make

If everything works correctly, you will find a DMG file image in your execution directory containing your product archive.

Conclusion

In this tutorial we have covered the basic tasks every OS X developer should master in order to build product packages for his own projects. Furthermore, the skeleton of a Makefile performing all the required operations has been provided. This is only the beginning of the work of creating an installer, since most of an installer properties and requirements must be manually set by the developer. However, the tedious part of building component packages and creating product packages can be automated in a relatively simple Makefile that I hope it will be useful to many of you.

OS X: Creating Packages from the Command Line - Tutorial and a Makefile - Part I

Over the years Apple has been removing useful tools from its flagship IDE, XCode, and PackageMaker was one of them. It didn't take me by surprise, though. But while on the one hand I understand that Apple would like most users to download software from the Mac App Store (for which plenty of functionality has been baked into XCode), on the other hand removing PackageMaker means leaving developers without a useful and simple graphical tool to build their packages. And even though you can still download it separately at the Mac Dev Center (search for a package called XCode Auxiliary Tools), PackageMaker is clearly an unsupported tool of the past, and you'd better rely on the current ones: pkgbuild and productbuild.

Both pkgbuild and productbuild are command-line tools and they provide developers all the functionality they need to (man page citation):
  • Build OS X installer component packages.
  • Build a product archive for the OS X installer.
  • Build a product archive for the Mac App Store.
The only issue with them is they do not have a GUI and XCode does not publish their functionality through its UI.

In this blog post I will give a brief overview of how this tools can be invoked to build your own packages. You will be able to:
  • Create your own product archives containing multiple component packages.
  • Create a DMG disk image for your product archive.

In the next part of this tutorial we will see how we can write a Makefile to perform all the commands required to package your product and streamline your workflow, maybe executing it in a custom XCode target of yours.

Using pkgbuild

pkgbuild is the tool used to create component packages, the building blocks of product archives, the final products users install. Although component packages are packages themselves and you could distribute them and install them, building a product archive is in my opinion always preferable. Besides, component packages cannot be submitted to the Mac App Store.

pkgbuild main mode of operation is driven by a property list file which specifies the configuration of the component package to create. Developers do not need to write this file from scratch though: pkgbuild provides an analyse mode of operation that analyses the contents found in the specified root path and outputs a template component property list file that can be used as a starting point.

Assuming we want to build a component package for an OS X application, we first invoke pkgbuild in analyse mode on a release installation directory to create an initial component property list file:

$ pkgbuild --analyze \
  --root /tmp/Name.dst \
  NameComponent.plist

The root path for an application project is an XCode project property (Project/Build Settings/Deployment/Installation Build Products Location) defaulting to /tmp/$(PROJECT_NAME) that can be specified when performing the xcodebuild install target by setting the DSTROOT variable.

When run, pkgbuild will create a file called NameComponent.plist containing default configuration values such as the following (output may vary):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
  <dict>
    <key>BundleHasStrictIdentifier</key>
    <true/>
    <key>BundleIsRelocatable</key>
    <true/>
    <key>BundleIsVersionChecked</key>
    <true/>
    <key>BundleOverwriteAction</key>
    <string>upgrade</string>
    <key>RootRelativeBundlePath</key>
    <string>Applications/Name.app</string>
  </dict>
</array>
</plist>

Tweak your component property file according to your needs (man pkgbuild for detailed information about the available configuration property) and when the configuration is ready pkgbuild can be run in its main mode to create the component package (split lines for better readability):

$ pkgbuild --root /tmp/Name.dst \
  --component-plist NameComponent.plist \
  NameComponent.pkg

Here, we use NameComponent.pkg as the name of the component package to distinguish from the name of the product archive package.

Sign Packages with pkgbuild

pkgbuild lets you sign packages using an "identity" (a certificate and the corresponding private key) that must be installed into one of your keychains. To sign a component package, invoke pkgbuild with the --sign identityName option where identityName is the common name (CN) of the desired certificate.

If you are creating a signed product, for example if you want to submit it to the Mac App Store, signing all its component packages is not required: you should only sign the product archive using productbuild.

Using productbuild

Let's now suppose you have created two component packages for your product:
  • NameComponent.pkg, created in the previous section.
  • MyFramework.pkg, a dependency of NameComponent.pkg (created as seen in the previous section).

productbuild is the tool used to create product archives, that is: packages to be installed by users or to be submitted to the Mac App Store. A product archive is made up of one or more component packages and in this tutorial we will create one containing the two aforementioned components.

Similarly to pkgbuild, productbuild runs in multiple modes (currently the available modes are 5, see the man page for detailed information), two of them being:
  • Analysis mode, to create an initial distribution file.
  • Create a product archive from a distribution file.
A distribution file is to the product archive what the component property list is for the component package: it includes all the configuration of the product archive, including (see the man page for detailed information):
  • A product license.
  • A product README file.
  • The list of component packages.
  • Constraints (such as minimum OS version).

To create the initial distribution file for our product archive, we run productbuild in analysis mode specifying the list of component packages to include. In this case we specify the --synthesize option to run productbuild in analysis mode, two component packages with multiple --package options, a requirement file (described in the next section) and the name of the resulting distribution file distribution.plist (split lines for better readability):

$ productbuild --synthesize \
  --product requirements.plist \
  --package MyFrameworkComponent.pkg \
  --package NameComponent.pkg \
  distribution.plist

Once productbuild creates the initial distribution file, you can manually modify it to satisfy your needs.

Adding a License

If you want to add a license to your product archive, prepare a license file in one of the supported formats (including rtf, html and plain txt) and add its reference to the distribution file using a <license/> element to the distribution file root element <installer-gui-script/>:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<installer-gui-script minSpecVersion="2">
  <title>Name</title>
  ...
  <license file="LICENSE.html"/>
  ...
</installer-gui-script>

Adding a README

A README file can be added using a procedure similar to what we have used to add a license file, but in this case the name of the element is <readme/>:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<installer-gui-script minSpecVersion="2">
  <title>Name</title>
  ...
  <license file="LICENSE.html"/>
  <readme file="README.html"/>
  ...
</installer-gui-script>

Creating a Requirements File

Requirements can be specified in a requirement property list file (see man page for detailed information). A requirement property list file is a property list whose element is a dictionary in which may constraints can be expressed using a series of keys, including (but not limited to):
  • os: Minimum allowable OS version.
  • arch: Supported architectures.
  • ram: Minimum required RAM.

To specify a dependency on OS X 10.9, we can create an empty property list file whose first child is a dictionary in which we add an os key with the constraint we need:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>os</key>
  <array>
    <string>10.9</string>
  </array>
</dict>
</plist>

Creating the Product Archive

Once the distribution file is ready, productbuild can be run to finally create the product archive. In this case we have to specify the distribution file with the --distribution option, the resource path where resource files are found (such as license and README, even if they are in the current working directory) the package path where component packages can be found using the --package-path options (in case they are not in the current working directory) and the name of the product package:

$ productbuild \
  --distribution distribution.plist
  --resources .
  --package-path path/to/MyFrameworkComponent.pkg
  --package-path path/to/NameComponent.pkg
  Name.pkg

Signing the Product Archive

As explained in the case of pkgbuild, productbuild lets you sign the product archive using the identity (a certificate common name) specified with the --sign option. The specified certificate must be available in an accessible keychain, otherwise the path of a specific keychain must be specified using the --keychain option.

A product archive can even be signed after it has been created using the productsign command (see the man page for further information).

Creating a DMG Disk Image

OS X installers are often distributed in a DMG disk image file. If you want to create a DMG file containing your product archive (and optionally other files) you have to:
  • Put all the files your want to include in a folder (the source folder in hdiutil jargon).
  • Use the hdiutil command-line utility to create a DMG disk image from the source folder.

Assuming we have created the ./dist source folder where we have copied the Name.pkg product archive, we can use the following command to create a Name.dmg DMG file (split lines for better readability) named My Product:

$ hdiutil create \
  -volname "My Product" \
  -srcfolder ./dist \
  -ov \
  Name.dmg

The optional -ov option is used to overwrite an existing DMG file.

A Makefile to Put It All Together

In the next part of this tutorial we will examine an example Makefile that can be used as a starting point to perform all the operations described in this post.

Sunday, August 12, 2012

Adobe Photoshop Lightroom Tutorial - Part XXIV - Organising Your Photo Catalog Using Metadata and Keywords

Part I - Index and Introduction

Metadata, in one of its simplest form, is defined as "data about data". In the case of photography, for example, you may think about EXIF data attached to your image: they provide technical information (camera settings, geolocation information etc.) about the picture. Depending on the tool you use, you can go beyond what's provided by standards (such as EXIF or IPTC) and provide your own metadata.

What's the point of using metadata? The basic idea is organizing your images and thus being able to make searches based on some criteria. For example, you may want to search for images shot with a specific camera, or with a specific lens; or you may looking for pictures taken at a certain shutter speed, aperture or geospatial coordinates. Or you may be willing to search for pictures using non-technical criteria, such as a portrait shot at a wedding and processed in black and white. Can you imagine what your Internet experience would be if search engines didn't exist? You couldn't find a way to the information you're looking for, and the very concept of "Internet" as you know it would be defied. The same thing happens with your photo catalogs. How could you possibly find something if you couldn't search using the criteria you need? Amateur photographers with small catalogs may be able to find the pictures they're looking for manually scanning the catalog, or trying to remember which folder or collection a picture is in. But as soon as your catalogs grow larger and larger things get worse and the problem starts to be insurmountable. That's why some products exist which provide the tools you need to overcome this problem. In fact, there's a dedicated category of such products: image management databases and Adobe Photoshop Lightroom is one of them.

If you're using Lightroom, you already know your images are stored into a catalog which acts as a "proxy" between you and the images managed by Lightroom. The catalog is basically a database which stores additional information (metadata) alongside your images. Such metadata makes the database searchable, so that you can look for images using search criteria. Lightroom, in this respect, is extremely helpful and powerful in that:
  • It comes with out-of-the-box support for an extensive set of well known or frequently used metadata (such as ratings, EXIF and IPTC).
  • It lets you extend the metadata model using your own keywords.
  • It lets you easily build search criteria mixing and matching any type of searchable field.
  • It lets you define smart collections, that is collections of pictures whose content are defined by a search filter and are automatically updated.

These are just the most important features provided by Lightroom, and we'll discover more of them in the following sections.

Flags, Ratings and Labels

The simplest forms of metadata you can catalog your images with are flags, ratings and labels:
  • Flags are used to pick or reject an image.
  • Ratings are used to rate images on a scale from 0 stars to 5.
  • Label is a one of 5 color codes (Red, Yellow, Green, Blue and Purple) that can be assigned to an image.

While the meaning of flags and ratings is pretty well defined, the meaning of labels can be customized by the user. By default, labels are just "colours" but their name, and thus their meaning, can be customized to be meaningful for the user. Lightroom, for example, provides an additional naming scheme for labels, inherited by Adobe Bridge, that uses the following convention:
  • Red: Select
  • Yellow: Second
  • Green: Approved
  • Blue: Review
  • Purple: To Do

You're free, however, to assign your own meanings to colour labels. In my workflow, for example, I just use the common three traffic light colours (red, yellow and green) to transition images from the undeveloped, partially developed and done states.

In the following picture, you can see a screenshot of some pictures in my catalog. Three of them (the first, the second and the third) are flagged because I picked them, rated (with 4, 3 and 4 stars respectively) and labelled green (because I finished processing them). The second image is unflagged (it's neither rejected nor picked), unrated (0 stars) and partially developed (yellow label).

Flags, ratings and labels

The basic rating and labeling metadata are flexible and easy to use and can be largely adjusted to any development workflow. In my workflow, for example, flags are used before starting developing images in order to pick only the pictures eligible for development. Images to be deleted, are marked as rejected and deleted pretty soon. Images I'm not sure about are left unflagged even if, eventually, they'll either be picked or rejected (and thus deleted). Ratings are usually applied at the end of the development process and are usually immutable while colour labels are just a quick visual aid to quickly identify pictures I should be working on. Eventually, when I finish developing a folder (or collection) all pictures will be labeled green.

Metadata

Images can be assigned metadata of many kinds. Lightroom support many kinds of metadata including:
  • EXIF
  • IPTC
  • DNG
  • Location
  • Metadata defined in a custom plugin
Lightroom can also read proprietary metadata (such as proprietary EXIF extensions) found on an image, but in this case it usually gives no way to modify it. In fact, Lightroom won't even read all proprietary metadata: if you're interested in reading a field not visible in Lightroom, you should look at the excellent ExifTool by Phil Harvey (a command line tool I will probably write a post about in the future).

Metadata can be inspected and modified using the Metadata panel in the Library module:

Metadata Panel

As you can see in the previous image, the Metadata panel shows information about the chosen type of metadata (in this case EXIF and IPTC) and lets you modify the writeable fields. At the topmost part of the panel, Lightroom provides some commonly used fields (Rating, Label, Title, Caption, etc.) as a convenience to speed up metadata editing.

To change the currently displayed metadata category, you just need to select the desired one in the list box in the upper left corner of the panel. In my Lightroom setup, these are the available choices:

Metadata Categories

If you're a developer, you could also extend available metadata writing a custom Lightroom plugin using the Lightroom SDK. Most users (even professional ones), however, will be just satisfied with what Lightroom offers out of the box.

Location Metadata

Location metadata is the perfect way to geographically localize where a shot was taken. Nowadays, many cameras populate these fields using data gathered by a GPS device, such as modern smartphones or GPS-equipped cameras. Many DSLR, however, still lack this functionality and their pictures require the user to manually introduce location metadata.

Up to Lightroom 3, location metadata were just made up of text fields, but with the latest Lightroom release (v. 4 at time of writing) you can use the Map module to populate these fields by dragging and dropping images over a map:

Map Module

Once an image is dropped over the map, Lightroom will automatically update its location metadata, as you can see in the following picture:

Location Metadata of a Photo

The Map module also provides the possibility of saving a location, a functionality that can greatly speed up your workflow. To save or load a location, just use the controls found in the Saved Locations panel of the Map module.

Since location metadata may contain sensitive information you're willing to protect, you may want to ensure that information about some locations are never exported. That might be the case of information about your home location, for example. To have Lightroom protect a location, you can add it to the list of saved locations and mark it as private:

New Private Location

In the New Location dialog box, you can specify a radius which will determine the area of the (circular) location you're saving and a checkbox that can be used to mark it as private. If an image is tagged into a private location, the corresponding metadata will never be exported, no matter which export mechanism or publish service is used.

Applying Metadata Changes to Multiple Images

Very often you find yourself applying the same metadata to multiple images. For example, it may often be the case for metadata in the location, copyright, contact and workflow categories. Lightroom offers two ways to perform "bulk" metadata changes:
  • Metadata synchronization.
  • Metadata presets.

Metadata synchronization is very similar to develop settings synchronization: you apply the modification you need to a picture and then sync other pictures with it. To sync metadata with a reference image, just select all the images to be synced paying attention that the reference image be the first image in the selection set. Once the images are select, press the Sync Metadata button in the bottom left corner of the right module panel:

Sync Buttons

Ligthroom will present a form in which fields to be synced can be chosen and copied to the metadata set of the other images.

Metadata presets are a very similar concept, with the difference that metadata values are saved in a preset (instead of copied from a reference image) and applied to a set of images. To create a preset, select the Edit Metadata Preset item in the Metadata menu or in the Preset listbox in the topmost section of the Metadata panel. A form will be presented in which fields to be saved in the preset can be chosen. A saved preset can be applied to one or multiple images simply selecting the corresponding preset in the Preset listbox.

Metadata presets are handy when a set of metadata values is frequently applied to many photos. To speed up my workflow, for example, I created a preset for each of the fixed sets of metadata I commonly use, such as contact information, copyright information and common locations where I use to shoot. Metadata synchronization, on the other hand, is more suitable when many images share a common set of characteristics (same job, same event, same model, etc.) whose value, however, aren't worth creating a preset which will most likely be scarcely reusable.

Keywords

Lightroom lets you apply keywords to an image. Keywords, or tags (an alternate name used in other contexts such as Flickr or Google+), are just text labels that can be searched for: hence, they provide a mean for an user to freely organize the catalog using user defined "keys". In this sense, keywords are the building blocks you use to organize your catalog "your own way". Metadata described so far, in fact, was related to some technical aspects of a picture or some standard attribute set (camera settings, location, etc.). Keywords, on the other hand, are "the words you use to describe a picture" and, hence, to keep your catalog organized using words meaningful to you.

You may want to define, for example, keywords for each style of photography you produce (portraits, landscape, etc.), for treatments you apply (duotone, sepia, black & white, cropped, etc.), names of persons appearing in a photo, etc.

Adding and Removing Keywords

To assign keywords to a picture, just use the Keywording or Keyword List panels of the Library module. The Keywording panel, shown in the following picture, is made up several distinct controls:
  • The Keyword Tags list box, used to change what's shown in the keywords box.
  • The keyword box, where you can see a list of keywords applied to your image whose content depend on the current Keyword Tags selection.
  • A text box that lets you add keywords.
  • Two grids, Keywords Suggestions and Keyword Set, which provide a visual shortcut to two set of keywords.

Keywording Panel

By default, the keyword box shows the keywords currently assigned to the selected picture(s). In case of a multiple selection, a keyword that's only assigned to a subset of images is postfixed by an asterisk (*). To add a keyword, you just need to type it in the keyword text box and press Enter: the keyword will be added to the currently selected image(s) and created (with the default options) if it's the first time you use it. If you want to tweak the behaviour of a keyword, as described in the following section, you maybe want to create it manually before entering it or manually changing its options later. I usually prefer creating them manually in order not to forget changing their options afterwards.

To speed up your workflow, Lightroom lets you quickly select keywords from two 3x3 grids: Keywords Suggestions and Keyword Set. The former contains suggestions based on last used keywords, based on the keywords currently applied to an image; you'll see that adding or removing keywords to the current image triggers a suggestions change as well. The latter, on the other hand, is made up of a static list of keywords you can create, save and use. Using the listbox on the right side of the keyword set grid (showing Outdoor Photography in the previous image) you can select, create, edit and remove your own keyword sets. Lightroom ships with some example sets but you should create your own, reflecting your "keywording habits" for each kind of photography you're interested to.

To remove a keyword, just deselect it from one of the suggestion grids or manually delete it from the keyword list.

Keyword List

The Keyword List panel shows a graphical representation of the current keyword tree. In fact, keywords aren't just a flat set of tags: Lightroom let you organize keywords into a hierarchy, as shown in the following picture:

Keyword List

The quickest way to build is a hierarchy out of already existing keywords is just rearranging them with your mouse. If you drag a keyword over another, the former will convert into a child of the latter.

But what's the point of building and maintaining a hierarchy? It's not only constraining the size of a keyword list that could potentially grow to a considerable size. The keyword hierarchy allows you to organize concepts in a tree establishing an "is a" relationship with the containing keywords. In the picture above, for example, the keyword cat is the leaf of the subtree animal/mammal/cat. That is: in the hierarchy I'm using the cat is a mammal and is an animal. This way, you don't have to tag an image three times (cat, mammal and animal) but just one: cat.

You can tweak how keywords behave in the hierarchy. In the example above, we wanted cat to be a mammal an an animal. There may be cases where you just use the hierarchy for organizational purpose and don't want a picture to automatically acquire all the containing keywords as well. For the same purpose, you may want to organize your catalog using certain keywords (such as names) but you want to prevent those keywords to appear elsewhere, such as in exported or published images. In this case, you can just edit a keyword and specify the behaviour you need (right clicking on it and selecting Edit Keyword Tag):

Edit Keyword Tag

In the Edit Keyword Tag window you can see how the behaviour of a keyword can be tweaked:
  • A keyword can be included in an export (or publish) operation if the Include on Export checkbox is selected.
  • A picture will inherit containing keywords if Export Containing Keywords is selected.
  • A picture will inherit a keywords synonyms (more on this in the following sections) if Export Synonyms is selected.
If you want to prevent a keyword to be exported or published, just deselect Include on Export: no matter how you export or publish image containing this keyword, Lightroom will remove it.

Effective Keywords

We've just seen how the set of keywords applied to an image not only depends on the ones you explicitly added but also on the behaviour and the operation keywords are considered for. If you want to inspect the list of keywords effectively applied to an image you can use the Keywording panel and choose the list you're interested in.

In the Keywords section we've seen that the Keywording panel features a Keyword Tags list box. Depending on your choice, the behaviour of the panel will change:
  • Enter Keywords: the default choice, whose functionality has been described in the Keywords section.
  • Keywords & Containing Keywords: if you choose this option, the panel will turn read-only and will show the list of all keywords inherited by the image (as described in the Keyword List section).
  • Will Export: if you choose this option, the panel will turn read-only and will show the list of all keywords that will be exported with the selected image.

Synonyms

In the Edit Keyword Tag window you may have notice a Synonyms text box whose functionality we haven't described yet. Lightroom lets you associate a set of synonyms to a keyword: synonyms can be thought as an additional list of keywords associated with a keyword, whose primary purpose is search. A synonym, in fact, won't even appear in the keyword list and can only be consulted checking the configuration of each specific keyword.

Many users wonder when a synonym or a keyword should be used. That really depends on how you build your own keyword hierarchy but here are some guidelines. You should try to keep your keywords hierarchy simple, clear and intuitive so that your workflow is smooth. Also, keywords represent concepts and we know that, literally speaking, a pure synonym doesn't offer nothing new, just an alternate spelling. This is a clear case in which a synonym should be created instead of yet another keyword.

Other times, some words just doesn't fit well into your keyword hierarchy. Let's take my animal hierarchy. I defined a cat as a mammal and an animal. What about pet? Or clawed? Or furry? You cannot feasibly build a hierarchy containing all nuances that can possibly come to your mind. Also, a cat can certainly be considered a "pet", but a bird can as well. But in my hierarchy, a cat is a mammal while a bird is not. What should I do? Create a pet keyword for each of them? You can easily see how that hierarchy can become more and more cluttered if we try to introduce these concepts. In this case, you'd better use a synonym. A cat may be a synonym of "pet", of "clawed", as well as a bird may.

If you then want a synonym to be inherited from a keyword, you can select the "Export Synonyms" options of the affected keyword so that it will be explicitly listed in the keyword list of an exported or published photo.

Searching and Filtering

Any kind of metadata can be used to search and filter your catalog images.  In Part V of this tutorial we already described the basic search and filtering facilities of Lightroom, so that we will only summarize them here.

A filter by flags, ratings or labels can easily be built using the Attribute filter bar. As you can see in the next image, you can just select on the graphical user interface the values you're interested in and Lightroom will filter the contents of the currently selected folder (or collection) according to your choices.

Attribute filter

If you want to filter using keywords, you can use multiple techniques. The first is using a Metadata filter. You can configure a Keyword column for such a filter and select the keywords you want to filter with. In the following image you can see how Lightroom intelligently makes things easy including only used keywords in the currently selected folder (or collection).

Metadata Filter (stacked with a Text Filter)

Another way to search using a keyword is using a Text search. You can either freely search on every searchable field or narrowing the choice specifying the field you want to look for (as seen in the following images).

Text Filter

Text Filter - Searchable Field

The last method you can use to filter for a specific keyword is using the Keyword List panel to build a quick filter. When you hover a keyword with your mouse, a small arrow appears on the right of the keyword record, as highlighted in red in the following image. Pressing the arrow control makes Lightroom create a Metadata filter using the selected keyword. If you need to filter with just one keyword, this method is probably the quickest one.

Keyword List

Filters can also be stacked together to build even more complex search queries, mixing and matching criteria built onto any metadata field that Lightroom manages:

Multiple Filters Stacked Together

Conclusions

As we've seen, Lightroom provides excellent management capabilities and you can keep your catalog perfectly organized with very little effort. The point of an image management database is just this: making your ever growing catalog manageable. There would be no point in storing thousands of images if you couldn't effectively use the tool to quickly retrieve what you're looking for.

Some photographers start to use this kind of tools without realising their real potential nor the issues they'll start experiencing when their catalogs overgrows a set of few hundreds images. Lightroom, furthermore, is an excellent tool to develop your RAW files and it's easy to forget about it being a catalog manager as well.

That's why is very important to learn about these feature soon and start applying them to your regular workflow. The sooner, the better.

Protect Your Privacy

I want to stress once more how Lightroom can help you protect sensitive data (keywords and location information) so that you don't accidentally publish them.

Protecting the location information is probably easier because, even if geolocation data is often added automatically and you may forget about it, Lightroom gives a simple solution to this problem: just create a private location specifying its centre and its radius and just forget about it.

In the case of keywords, marking them as not exportable is up to you and you may easily forget, especially if you get used to creating them automatically from the Keywording panel. Lightroom, furthermore, does not separately manage subject names as other tools do and this fact induces users to define a keyword hierarchy for it. If you forget to configure each and every keyword according to your needs, private data may unexpectedly leak.

If you want to help me keep on writing this blog, buy your Adobe Photoshop licenses at the best price on Amazon using the links below.

Monday, July 23, 2012

Adobe Photoshop Lightroom Tutorial - Part XXIII - Understanding Channel Mixing to Achieve Effective Black and White Photos

Part I - Index and Introduction

Converting a photo to black and white may seem one of the easiest thing you can do with your photo editing software of choice. Unfortunately, nothing could be further than the truth, and if you don't do it correctly you may end up with dull images, very different from what you thought you'd get.

The Basic Fallacy: Zeroing the Color Saturation (Depending on the Tool You Use)

An approach I see very often to convert an image to black and white is zeroing the color saturation. What's worse, I sometimes hear theories about not-well-defined advantages of this technique. You get a black and white image, of course. But that image doesn't represent the luminance your eyes are seeing, let alone the intuitive result you think you'd get. Depending on the colors that are present in the shot and their saturation, differences can either be subtle or very deep.

What's interesting to note, as we'll see in a minute, is that most differences will be noticeable on deep blues and saturated reds. Think about: skies and some skin tones. Indeed, this doesn't look like a great deal.

Without going into the technical detailes about concepts like relative luminance or luma in colorimetric spaces, a photographer should understand that the luminance values of pure RGB colors aren't all equal to the human eye. In fact, many standards try to model the behaviour of the human eye and most photo editing programs provide us the tools we require to achieve predictable results, according to how the human eye works. Just for the sake of example, here's the transform matrix from RBG to CIE 1931, where Y is the luminance:



As you can see, red contribution to luminance is approximately 4 times greater than green's (0.17697 vs. 0.81240) and more than 16 times greater than blue's (0.17697 vs. 0.01063).

Another example can be seen in the transform matrix from RGB to the Y'UV color space:


We can see the contribution of each RGB channel to the value of Y' (luma, a gamma compressed luminance). Once again, the contribution of red is smaller than green (0.299 vs. 0.587) and bigger than blue's (0.299 vs. 0.114).

What can we infer from this? That green brings the greatest contribution to the luminance value, followed at a big distance by red, and finally by blue. In other words: given three pure RGB colors with  the same component:
  • Green will be much brighter than the others,
  • Red will be much darker than green but slightly brighter than blue,
  • Blue will be the darkest of all.


What happens, then, zeroing the RGB color saturation?

What happens is simple: the smaller the saturation, the more colors will tend to equal a specific grey value. We're not interested in knowing which grey tone, but the important thing is that each channel will then have the same luminance.

Here's a visual example, better than a thousand words: in the following images you can see the same color chart with different values of color saturation: 100%, 50%, 25% and 0%.

Color Chart - Saturation: 100%

Color Chart - Saturation: 50%

Color Chart - Saturation: 25%

Color Chart - Saturation: 0%

What's clear from this example is that zeroing the color saturation is not what you want during a conversion to black and white. In fact, to achieve balanced and realistic results, or results that at least would faithfully represent what you're eyes are seeing, you'd expect relative luminance between different RGB colors to be respected. That is, red should be a darker shade of grey than green and blue an even darker shade of green.

What can you do, then? Simple: use the tools provided by your photo editing program and forget about the saturation adjustment.

To say the truth, this also depends on the tool you use. The saturation control of some photo editors, such as Lightroom, behave differently than this and, in fact, apply a default mix when desaturating colors. Even so, even basic photo editing programs have got a "Convert to black and white" feature which will hopefully do a better job than you can do with the saturation slider. More sophisticated program may offer better tool, the "channel mixer" being the most interesting and flexible from a photographer's point of view.

Channel Mixing

As we've seen, it's necessary to "mix" RGB values with certain coefficients to simulate the behaviour of the human eye, as far as relative luminance across RGB color is concerned. That's exactly what the channel mixer can do for you, and that's why it's an omnipresent feature of good photo editing programs, although little known to many amateurs.

The channel mixer simply lets you change the coefficient with which each color contributes to the luminance. Raising a color's coefficient means that its contribution will be bigger, and thus will appear brighter. On the contrary, lowering a color's coefficient means that its contribution will be smaller, and thus will appear darker.

Adobe Lightroom 4 applies a default "mix" when converting to black and white which I found pretty acceptable. However, since the tool is there to use it, I almost always tweak the mix a little bit to achieve the results I desire. For example, I often raise the value of the red and orange channels in portraits in order to reduce speckles and imperfections and to slightly brighten the skin.

Here's the result you achieve in Lightroom 4 when desaturating the reference color chart:

Lightroom 4 - Saturation: -100

As you can see, it has done a much better job than Photoshop in this case (beware: I say "much better" from a photographer's point of view, not from a theoretical one). Now, reds and blues are darker than greens, as expected.

On the other hand, if you convert it to black and white, here's the result you get:

Lightroom 4 - Black & White - Default Mix

and here's the default mix applied by Lightroom:

Lightroom 4 - Default Black & White Mix

The result is somewhat less contrasted, and you can see how blues are slightly brighter (+9) and greens are slightly darker (-27).

The point is there's no right or wrong here: the Black & White mix is a tool you can use to fine tune your shot and is much more flexible than just zeroing the saturation. For example: if you want a darker sky, for example, just decrease the Blue contribution. if you want some brighter reds, just increase their contribution.

Conclusion

The bottom line is: the channel mixer is pretty flexible and you can use it at your advantage, for example to simulate some B&W filters in post production. For example, I often increase the Red and Orange channel in many portraits, especially those taken during the summer, to get less contrast in the subject's skin thus getting it brighter and removing many imperfections. In the following shot, for example, you can see how simulating a red filter has given the photo more contrast in the red highlights and resulting in a smoother and brighter skin:

Red and Oraange channels were increased to simulate a red filter

The same effect was used in this shot to achieve a similar result:

Red and Oraange channels were increased to simulate a red filter

In the following shot, the subject was very tanned and the shot, when converted to black and white, had a look I really didn't like. Once again, using an appropriate mix, I could deliver a more natural skin tone and get rid of all the subject's speckles too.



If you want to help me keep on writing this blog, buy your Adobe Photoshop licenses at the best price on Amazon using the links below.

Saturday, July 14, 2012

Nikon Creative Lighting System Tutorial: The Basics

Nikon Creative Lighting System Tutorial: The Basics v. 1.1 (PDF)

Nikon's Creative Lighting System, in Nikon's word
offers photographers new and unprecedented levels of accuracy, automation and control.
Looking past the marketing jargon, Nikon CLS is a set of technologies (and automations) that enable photographers taking the most out of their flash systems with the minimum effort. The technologies making up CLS include:
  • i-TTL balanced fill flash.
  • Auto FP High Speed Sync.
  • Flash Value Lock (FV Lock).
  • Wide-Area AF-Assist illuminator.
  • Flash Color Communication.
  • Distance-Priority Manual Flash.
  • Modeling Flash.
  • Advanced Wireless Lighting.

As it happens with most automatic mechanisms, an incomplete understanding of their behaviour might negatively (or at least counterintuitively) affect the obtained result. In my opinion, the behaviour of several Nikon CLS technologies isn't properly documented in the camera and flash manuals and, "unfortunately", you will be using some of them each time you use a flash, including the pop-up flash of your Nikon camera.

The purpose of this document is to describe the fundamental behaviour of the basic technologies that make up the CLS technology, such as i-TTL balanced fill flash (TTL-BL), regular iTTL flash (TTL in this guide) and flash value lock (FV lock).

Flash photography implies multiple exposures

As we've seen in Flash exposure tutorial: the basics, any time you're making a photograph, you have to deal with multiple light sources which, in the context of this article, we will divide into two categories: ambient and flashIn this section we'll quickly recap the concepts exposed in that tutorial.

Even if extremely faint, you will always be dealing with ambient light, which you may consider as the amount of light coming from continuous light sources outside of your control (the Sun, environmental lighting, etc.). That's the light you're used to meter when taking a shot without controlling any flash.

As soon as you turn on a flash, you're introducing new variables into the equations. The first thing you've got to realize, apart from the distinctive traits of flash light we've already covered in the previous tutorial, is that you've got control over that light source and this is where the CLS technology comes into play.

Every time you shoot a picture using flashes the resulting image will be the combination of two exposures: an exposure coming from the ambient light and an exposure coming from the flashes. Depending on the results you want to achieve, you will have to meter both light sources and configure both your camera and your flashes to achieve the desired ratio a/f between ambient light a and flash light f that's going to be received by your sensor.

In the previous tutorial we've seen how common settings (such as ISO sensitivity, shutter speed and aperture) differently affect a and f and we've also quickly described how TTL metering automatically changes the flash power output and, in turn, how it affects a/fThe physics behind it is easy, but the resulting mechanisms are not intuitive, and that's why it's important for a photographer to know them, at least their broad outline.

Nikon CLS system is a set of technologies that further assist the photographer in getting the results he wants more quickly and more easily. Once again, though, it's important for you to know how that technology works and the assumptions it makes: that way, you will be able to get the most out of it and you will avoid being "trapped" into situations in which you're getting results you can't explain.



Which is your main light source?
Failing to correctly recognize which your main light source is often is the beginning of a novice photographer's problems. No matter the lighting condition, if the main subject is poorly lit, you turn on the flash and hope the camera metering system will solve the problem for you. Whilst this is not so bad an assumption (after all, that's why the TTL and CLS technology are there), you must realize that your gear is going to make an educated guess based on its assumptions and the lighting conditions it determines. That's a starting point, but it seldom is the correct guess.

In fact, look at the name of one of the most misunderstood CLS technologies: i-TTL balanced fill flashFill flash implies that the flash is not the main light source or, said in other words, that ambient light is stronger that flash light. Unfortunately, although understandably, i-TTL balanced fill flash is the flash mode Nikon cameras and flashes use by default.

One of the important things we've learnt is that flash is a nearly instantaneous light source whilst ambient light is continuousAs a consequence, you can adjust the ratio a/f of their contribution, at least to a certain degree. This fact allows you, for example, to get properly exposed subjects and properly exposed backgrounds, where properly means "according to your will". TTL metering makes this so easy because it automatically changes the flash power output to compensate a change in other parameters (such as aperture or ISO sensitivity) and get a properly exposed subject.
To summarize:
Ambient light exposure is controlled by the camera metering system, while flash exposure is controlled by the flash metering system.
Said in other words, they're decoupledThe only "problem" with TTL metering is that novice photographers are often unaware of it, and wonder what's going on when results aren't as expected or when they're ready to make a step forward and get more creative.

To understand the different nature of the two situations and the kind of issues you may run into, let's make a quick summary of what we've seen in the previous article, trying to distinguish between them.

Flash is the primary light source
When flash is the primary light source, things are pretty easy. If you want your subject to standout over an underexposed background, just reduce the contribution of ambient light (for example, reducing the shutter speed) and the ratio a/f will decrease as well. On the contrary, you can increase the contribution of ambient light and the ratio a/f (for example, lowering the shutter speed or raising the ISO sensitivity) if you want to get a more exposed background.

Ambient light is the primary light source
When ambient light is the primary light source, flash can be used to balance shadows of a poorly lit subject and this technique is usually called fill flashThe camera will be set to correctly expose the (lighter) foreground and the flash metering system will fire the flash at the correct power to correctly expose the subject. You could argue that the sum of the two light source could eventually overexpose the subject: it's true, and that's one of the aspects that the Nikon CLS system takes care of.

TTL vs. TTL-BL
In Nikon's jargon, TTL (regular TTL) and TTL-BL indicate how the metering systems of your camera and your flash will "react" to the lighting conditions you're shooting in. Unfortunately, the difference between the two systems is not well understood by many users and I recognize that Nikon is not making its best to clarify the differences between the two modes in its manuals.

As we've seen, common exposure parameters may have different effects on different kind of light sources and on the lighting conditions you're shooting in. If you shoot in regular TTL, you can separately manage the two exposures (ambient and flash) and get the results you want.

In TTL-BL mode, the metering systems will assume you want to balance the two exposures. Basically, you're telling your camera to assume that the subject is darker than the background. Nikon CLS has been improving over the years and I do recognize that you can get great results even when blindly shooting in TTL-BL all the time. However, you may sometimes get weird results when shooting TTL-BL and not meeting its assumptions, and it's important to understand why.

In the next sections, we will quickly recap how TTL and TTL-BL modes work, the assumptions the metering systems make and the decisions they take. Since I haven't found yet conclusive official documentation about the Nikon CLS internals, please take all of this with a grain of salt.

TTL flash

When using the flash in TTL mode, you're basically telling your camera metering systems to independently manage the two exposures: ambient light and flash light will be metered separately and no (or little) compensation logic will be applied.

The behaviour of the TTL metering system isn't always intuitive and, once again, it is not properly documented. When using this mode, the two metering systems will meter ambient light and flash light independently.

This fact, as detailed in the previous tutorial, may lead to overexposure: if both metering systems are calculating a "correct exposure", if the lighting conditions and the scene characteristics are such that the two sources of light are not negligible, at least in a certain area of the scene (such as the very subject), then the two "correct exposures" will sum up and this may lead to a 1 stop overexposure in that area.

But besides these generic problems, Nikon CLS' behaviour may introduce new issues. Recent cameras, for example, may try to avoid overexposure risks by automatically dialing a negative exposure compensation in automatic and semi-automatic modes. This reduction seems to be somehow proportional to the intensity of the ambient light. That's why you may sometimes get a background darker than expected, especially when ambient light is very bright. This issue clarifies why TTL flash may not be the best mode to use for flash fill, especially when the scene is bright.

Another very important aspect of how the flash metering system works is: which part of the scene does it meter? It comes out that it meters the center of the frame. If your subject is not in the center when shooting, the flash metering system will be deceived and you may end up with an incorrectly exposed subject. This is the reason why Nikon CLS has got a flash value lock feature (FV lock) that we will see in the following sections.

Ultimately, in all the cases when you don't need TTL-BL (see below), you should switch to TTL. The quickest way to do that with Nikon cameras is selecting the spot metering system. You will then have total control over your photo and, following the advices of the previous tutorial, you will be able to get very good results, especially being able to tune the relatively intensity of ambient and flash lights in your shots: using the camera common exposure settings (ISO sensitivity, aperture and shutter speed) you will tune how much ambient light is detected by the sensor and using flash exposure compensation you will tune how much flash light will light your subject.

TTL-BL flash

Fill flash is a technique in which you use a flash to "fill" the shadows in the subject when the ambient light is brighter than the subject itself. For example, if you shoot a backlit subject, such a person in front of a bright sky or a window, you may need to fill the shadows in the subject face using a flash. This is the use case Nikon invented TTL-BL for: TTL-BL is meant to balance ambient light with flash and get a properly exposed and balanced background and foreground.

TTL-BL is the mode used by default (unless spot metering is used) with both the pop-up flash and hot-shoe mounted flash units compatible with Nikon CLS. As stated in the introduction, modern TTL-BL flash implementations work really good even when using them when flash is the primary light source. However, you may get unexpected results at times; that's why you should learn about both flash modes and learn to choose and use the more suitable depending on the shoot you're taking.

When using TTL-BL, the two metering systems will coordinate together in order to achieve the desired balancing of ambient and flash light. Roughly speaking, when using TTL-BL, the two systems meter the light and exchange the information required in order for the flash to be fired at the power that will achieve the balance. Once again, though, the camera will set its parameters as if the flash wasn't usedinstead, the flash metering system will lower the flash output at the desired level, taking into account the intensity of the ambient light. If the subject is not darker than the background, then, you will get an overexposed subject.

Flash exposure compensation can be used to fine tune the flash power output even when you shoot TTL-BL. Very often, in fact, you'd rather reduce the flash power output in order for your subject not to stand out too much in the shot or to achieve more creative moods.

Hopefully, it's now clear that the rationale behind TTL-BL flash is balancing a darker subject against a brighter background. No matter how smart your metering system might be, if you're not shooting under this assumption, you should switch to TTL instead.


Aperture priority mode in a bright ambient
As already seen in the previous tutorial, extra care must be taken when using aperture priority mode with a flash, especially in bright ambient light. In fact, aperture has a direct effect on both ambient light and flash light reaching the sensor and, above all, on the flash power output required to correctly light the subject. If you recall the definition of guide number, your flash will be able to properly light a subject at a certain distance (see PDF version for more details).

Why does this fact matters so much? Because if the light gets brighter, or if the ISO sensitivity being used is increased, then the shutter speed selected by the camera will be increased to compensate for it. But there's a maximum shutter speed that can be used when using a flash (wnless your camera can use high speed flash sync) which can be as slow as 1/200 s. If the correct exposure is given by a shutter speed faster than this value, the camera won't be able to select it and you'll get an overexposed shot.

In bright light, such as when shooting in sunlight, that's a boundary that you'll hit very soon: the sunny 16 rules gives:
i = 100
s = 1/125
a = f/16

An aperture = f/16 is right at the limit. If you open it one stop, you'll get
i = 100
s = 1/250
a = f/11
and you've just hit the maximum shutter speed for flash sync.

I bet many people won't be usually using aperture priority mode at a = f/11 (or smaller) at they'll surely get an overexposed shot.

On the other hand, if you're aware of what's going on (your camera meter will indicate the overexposure) and close down your aperture, you may soon get your flash out of range. Professional speedlights (such as Nikon SB-910) have guide numbers around 34 meters which, at = f/16, give a maximum distance r from the subject of approximately 2 meters:
r = g/a = 34/16


Clearly, a very short flash range.

Why manual mode is a good choice when using TTL flash

There are several reasons why manual mode is a good choice when using a flash, especially in TTL mode.

Manual is not that challenging
The first one is that manual mode is not that challenging when shooting with a flash. The reasons are manifold. First of all, as we've stressed several times, the camera metering system pretty much ignores the flash, even more when used in TTL mode. As a consequence, manual mode lets you freely use the camera metering system to quickly evaluate ambient light conditions and achieve the effect you want. On the other hand, the flash metering system will do its job and will properly expose your subject.

The flash freezes the movement
The nearly instantaneous burst of light emitted by the flash will freeze the movement of your subject and, in a reasonable settings range, you won't have to worry too much about shutter speeds and about getting a blurred subject. If you remember what we've seen in the other tutorial, the shutter speed usually has no effect on the amount of flash light reaching the sensor. This is a "degree of freedom" when using manual mode with flash: you can set ISO and aperture according to the flash power output needs you have and then using slow shutter speeds, even when no tripod is used. In fact, you may get interesting and creative results: when using wide apertures a slightly blur in the background will be nearly indistinguishable with shallow depths of fields.

No need to use "slow sync"
When using automatic or semi automatic modes with a flash, cameras usually limit the shutter speed to a minimum which is usually around 1/60 s. Such a speed is often insufficient for the sensor to gather sufficient ambient light and you get the typical "white ghost" (your subject) over a dark background. To override this behaviour, you need to choose the slow sync mode: your camera will then choose slower shutter speeds.

But why? I think the reasoning behind that behaviour is that the camera prevents you from getting some ghosting in your shot. 1/60 s is sufficiently fast a speed for freezing a standing still subject when shooting without a tripod. It's sort of an "error prevention" mechanism you can override if want to.

However, in the previous section we've seen you can use the instantaneous flash light to freeze your subject movement when using slow shutter speeds. Should you get unacceptable ghosting, just increase your shutter speed in manual mode and you're done.

Use flash exposure compensation and exposure compensation interchangeably
This is an advantage in terms of ergonomics I like when using manual mode with TTL flash. As we've seen, photographers can use two mechanisms to compensate exposure: exposure compensation and flash exposure compensationThe former acts on both light sources and effectively changes camera settings to accordingly reduce ambient light and flash power output. The latter acts only on flash power output, and is commonly used to fine tune the ratio between flash light on the subject and ambient exposure.

But what happens when you're using manual mode? When using manual mode, exposure compensation just changes the value shown by your camera meter, but effectively has no effect on camera settings (beware that you must also disable auto ISO). As a consequence, exposure compensation will only affect flash power output and will give a result similar to what you'd obtain using flash exposure compensation instead.

Flash value lock (FV lock)

No matter which flash mode you're using, the flash metering system always meters the centre of the frame. This is a very important thing to know if you want to get predictable results when shooting with a flash.

The problem is somewhat analogous to what happens when you set a parameter and then recomposeMost photographers are aware of the risks of recomposing when using some automatisms such as exposure meters and autofocus systems. Unless you tell the camera somehow what your subject is, you won't get predictable results.

The same thing happens with the flash exposure metering system. As it measures reflected flash light at the centre of the frame, when your subject is not in the centre, its exposure will likely be incorrect. This problem can be amplified by the fact that very often, after recomposing, the centre of the frame contains a farther background or a nearer foreground object. In either case, the flash metering system will be deceived and, for the effect of the inverse-square law (see Flash exposure tutorial: the basics), its reading can greatly differ from the correct one. As a consequence, you may get strongly overexposed or underexposed subjects.

Similarly to what happens with exposure lock and focus lock, a new kind of lock is provided: flash value lockUsing flash value lock when pointing at your subject lets your camera meter a flash burst and lock the flash power output level. You can, then, recompose your shot and get the proper flash output. Furthermore, while the flash value is locked, you will be able to take a burst of photographs using exactly the same flash power output obtaining consistent results.

Depending on your camera settings, the locked flash value will be retained until
  • you unlock it, pushing FV lock again,
  • the metering system timeout elapses (by default, it's a few seconds on most cameras),
  • the camera is turned off.

For this reason, check your camera viewfinder and be sure the lock hasn't be released before taking the picture.

Using the FV lock burst at your advantage
I find that the FV lock flash burst can also be useful to "prepare" your subjects' eyes to the main flash bursts. After the lock burst, you can have your subject blink their eyes and get used to it. Then, you can take the shot and reduce the chances someone has blinked just when the main flash burst is emitted.


Examples

Here are some examples to better understand how we can take advantage of both metering systems, of Nikon CLS technology and, thus, of our flash.

TTL-BL fill flash}

First of all, let's see an example of how we can use Nikon TTL-BL to get a shot with a well-balanced subject. The subject in the following figure was partially in the shadow of a palm tree and was strongly backlit. Since ambient light is the main source of light and our subject was darker (at least partially), we needed some fill-flash. Hence, I switched my camera in matrix metering mode, the flash in TTL-BL mode, I locked the flash value pointing at my subject and took the shot. Since ambient light was very strong and strong reflections were coming from the pool, I dialed an exposure compensation of -0.7 EV. The result is a well balanced image with a properly exposed background and the shadows in my subjects' faces partially lifted by the filling flash. In this case, I'd probably dial in another -0.7 EV to the flash compensation in order for my subjects not to ``pop out'', but that's just a matter of taste.


Matrix metering, TTL-BL, Exposure compensation: −0.7 EV 



TTL flash in manual mode
In the following figure we can see what happens turning on the flash and taking the photo using the settings suggested by the camera metering system in matrix metering mode and flash in TTL-BL.

Matrix metering, TTL-BL    

In this case, the ambient light was moderately strong, even if were in the shadow, and the subject was as lit as most of the background (excluding the sky). The poor child is much too lit: he's popping out the photo as if it were a ghost. Also, that background is ugly, so that we could take advantage of manual mode and TTL flash in order to darken it a bit and lower the ratio $a/f$ between ambient light and flash light.

In the following figure you can see the result of shooting in manual mode with flash in TTL mode locked onto our subject.

Manual mode, TTL, f/7.1, 1/125 s., ISO 320 

With the specified parameters (f/7.1, 1/125 s., ISO 320) the camera was metering an underexposure of almost -1 EV, so that the background would be 1 stop darker. On the other hand, the flash was locked onto the subject and flash compensation was set to -2/3 EV. The result is a dark background and a brighter subject, although not as bright as before because of the negative flash compensation I dialed in.


Why? Once again, just a matter of taste. Most of the times I prefer reducing the flash output to reduce the "ghost" effect you get when flash output is too strong. In case you need more output, just change the compensation, that's part of the beauty of Nikon CLS in manual mode.


In the previous example we wanted to achieve a darker background and we used the camera in manual mode with flash in TTL mode to modify the ratio between ambient and flash light a/f accordingly. In the following figure we use the same technique to \emph{increase} the a/f ratio. Since I wanted a bright background for this photo and had no other lighting equipment with me, I put the subjects in front of a white wall and lit by artificial light while leaving them on partial shade. On the one hand, I set the camera parameters to slightly overexpose the wall and get a bright white background and on the other hand I locked the flash value on the baby's face to properly expose it with a little fill.


Manual mode, TTL, f/7.1, 1/30 s., ISO 400 


Freezing action
In the following figure you can see how we can take advantage of the manual mode and the flash TTL mode to get:
  • a not-so-dark background,
  • a properly lit subject and
  • frozen action.


The child was moving in a low light situation and I couldn't have frozen the action without the flash without severe underexposure.On the other hand, manual mode lets us use shutter speeds as low as we want to gather the desired amount of ambient light: in this case, 1/10 s. was enough to get background light spots sufficiently visible. On the other hand, 1/10 s. is too slow a speed to properly freeze the movement of a human being at a focal length of approximately 60 mm, let alone a child who's playing. The flash burst duration, on the other hand, is much shorter (it depends on the flash power but it's approximately 1/1000 s.) and it can freeze action quite effectively. In fact, although you can still see a ghosting effect around the child's arms and shoulders, the flash has frozen the child's action pretty well.

Manual mode, TTL, f/8.0, 1/10 s., ISO 1600 

Since background lights were very dim, I had to push the sensitivity up to ISO 1600 to be able to properly expose them at a shutter speed of 1/10 s. Of course, I could have use lower shutter speeds, but the resulting ghosting effect would have been too strong to be acceptable.

Nikon Creative Lighting System Tutorial: The Basics v. 1.1 (PDF)