<sect2 id="editor-cm-wkspace">
    <title>The Working Space</title>

    <sect3>
        <title>
            So I told &digikam; where to find my monitor profile and I have a camera profile that I applied to the image file produced by my raw processing software. What's the next step in color management?
        </title>

        <para>
            You need to choose a working color space so you can edit your image. LCMS will transform your image from your camera color space to your chosen working space, via the PCS specified by your camera color profile.
        </para>

    </sect3>

    <sect3>
        <title>Why cannot I just edit my images in the color space described by the camera profile?</title>

        <para>
            After all, the camera profile should provide the best "fit" to the colors recorded by my camera, as processed by my raw processing procedure, right?  Wikipedia says, "Working spaces, such as sRGB or Adobe RGB, are color spaces that facilitate good results while editing. For instance, pixels with equal values of RGB should appear neutral."  "[P]ixels with equal values of RGB should appear neutral" just means that for any given pixel in an image that has been converted to a suitable working space, if R=G=B you should see grey or black or white on your screen. Many camera profiles violate this "neutral" condition. I am not aware of a list of other technical requirements for a suitable working space. However, I can think of another good reason why you wouldn't want to edit your image in your camera profile color space. If you look at the size of a typical camera profile, it is on the order of a quarter to a half a megabyte or more. It's got a lot of information about all the changes that need to be made at different regions of color and tonality in the original scene, to get accurate color rendition from the RGB values that come out of the raw processor. The camera profile is accurate (at least for colors in the original target) but not particularly mathematically smooth. Working space color profiles, on the other hand, are very small in size (half a kilobyte instead of half a megabyte) because they describe a color gamut in terms of smooth, continuous mathematical functions. Working space profiles don't need to make allowances for the "messiness" of real world sensors, so the mathematical manipulations performed during image editing will go much more smoothly and accurately than if you try to edit your image while it is still in the camera color space.
        </para>

    </sect3>

    <sect3>
        <title>Which working space should I choose?</title>

        <para>
            Everyone has an opinion. I'm just going to lay out some of the bits of information needed to make an informed choice. Working space profiles are characterized by:
        </para>

        <orderedlist>

            <listitem><para>
                Gamma (or other transfer function), which dictates how much the original linear intensity values captured by the camera sensor (and subjected to the in-camera A-to-D conversion, then interpolated by the raw processing program to produce the image file) are altered to make editing easier or more precise.
            </para></listitem>

            <listitem><para>
                RGB primaries which dictate the range of colors, that is, the color gamut, covered by a given profile.
            </para></listitem>

            <listitem><para>
                White point (usually D50 or D65 though other values may be used), which specifies the color temperature of the white point of the working space.
            </para></listitem>

        </orderedlist>

    </sect3>

    <sect3>
        <title>What gamma should my working space have?</title>

        <para>
            The gamma of a color profile dictates what power transform needs to take place to properly convert from an image's embedded color profile (perhaps your working color space or your camera color profile) to another color profile with a different gamma, such as your chosen working space, or the display profile used to display the image on the screen or perhaps from one working space to another, or perhaps from your working space to your printer's color space. Dcraw outputs a 16-bit image with a linear gamma, which means that a histogram of the resulting image file shows the actual amount of light that each pixel on the camera sensor captured during the exposure (paraphrasing <ulink url="http://www.guillermoluijk.com/tutorial/dcraw/index_en.htm">this page</ulink>). (Which is why at present applying a camera profile to the dcraw output also requires applying an appropriate gamma transform to get to the desired working space, unless the camera profile also uses gamma=1.)
        </para>

        <para>
            One practical consequence of the gamma of a working space is that the higher the gamma, the more discrete tones are available for editing in the shadows, with consequently fewer tones available in the highlights. Changing the gamma of an image redistributes the number of tones available in the lighter and darker areas of an image. Theoretically, if you are working on a very dark-toned (low key) image you might want a working space with a higher gamma. And if you are working on a high key image, say a picture taken in full noon sunlight of a wedding dress with snow as a backdrop, you might want to choose a working space with a lower gamma, so you have more available tonal gradations in the highlights.
        </para>

        <para>
            Theory aside, in the real world of real image editing, almost everyone uses working spaces with either a gamma of either 1.8 or 2.2. sRGB and L*-RGB are two notable exceptions.
        </para>

        <para>
            sRGB uses a transfer function close to that of a CRT (and thus not necessarily relevant to image editing or to display on an LCD). As Wikipedia notes, "Unlike most other RGB color spaces the sRGB gamma can not be expressed as a single numerical value. The overall gamma is approximately 2.2, consisting of a linear (gamma 1.0) section near black, and a non-linear section elsewhere involving a 2.4 exponent and a gamma (slope of log output versus log input) changing from 1.0 through about 2.3" (cited from <ulink url="https://en.wikipedia.org/wiki/SRGB">this page</ulink>), which makes for some complicated math during image processing.
        </para>

        <para>
            L*-RGB uses as its transfer function the same perceptually uniform transfer function as the CIELab color space. "When storing colors in limited precision values" using a perceptually uniform transfer function "can improve the reproduction of tones" (cited from <ulink url="https://en.wikipedia.org/wiki/Lab_color_space">this page</ulink>).
        </para>

        <para>
            In addition to gamma=1.8 and gamma=2.2, the only other gamma for a working space that gets much mention or use is linear gamma, or gamma=1.0. As noted above, dcraw outputs linear gamma files if you ask for 16-bit output. Linear gamma is used in HDR (high dynamic range) imaging and also if one wants to avoid introducing gamma-induced errors into one's regular low dynamic range editing.
        </para>

        <para>
            "Gamma-induced errors" is a topic outside the scope of this tutorial. But see "Gamma errors in picture scaling" (cited from <ulink url="http://www.4p8.com/eric.brasseur/gamma.html">this page</ulink>) for gamma-induced tonality shifts; and of course see Timo Autiokari's informative (albeit somewhat infamous) website for a whole-hearted endorsement of using linear gamma working spaces (Timo's website seems to be down at present, though archived copies of his articles are still available through google). Bruce Lindbloom mentions a commonly-encountered gamma-induced error that is caused by incorrectly calculating luminance in a nonlinear RGB working space (see <ulink url="http://www.brucelindbloom.com/index.html?WorkingSpaceInfo.html">this page</ulink>, sidenote 1). And in a similar vein, the calculations involved in mixing colors together to produce new colors (such as using a digital filter to add warmth to an image) result in gamma errors unless the new colors are calculated by first transforming all the relevant values back to their linear values.
        </para>

        <para>
            Unfortunately and despite their undeniable mathematical advantages, linear gamma working spaces have so few tones in the shadows that (in my opinion) they are impossible to use for editing if one is working in 8-bits, and still problematic at 16-bits. When the day comes when we are all doing our editing on 32-bit files produced by our HDR cameras on our personal supercomputers, I predict that we will all be using working spaces with gamma=1. Adobe Lightroom is already using a linear gamma working space "under the hood", CS2 allows the option of using linear gamma for mixing colors, and Lightzone has always used a linear gamma working space.
        </para>

    </sect3>

    <sect3>
        <title>How many discrete tonal steps are there in a digital image?</title>

        <para>
            In an 8-bit image, you have 256 tonal steps from solid black to solid white. In a 16-bit image theoretically you have 65536 steps. But remember, those 16-bits started out as either 10 bits (=1024 steps), 12 bits (=4096 steps), or 14 bits (=16384 steps) as produced by the camera's A-to-D converter - the extra bits to reach 16-bits start out as just padding. The available tones are not distributed evenly from light to dark. In linear gamma mode (as the camera sensor sees things), there's a whole lot more tones in the highlights than in the shadows. Hence the advice, if you shoot raw, to "expose to the right but don't blow the highlights". See Ron Bigelow's <ulink url="http://www.ronbigelow.com/articles/articles.htm">articles on "why raw"</ulink>, for a full discussion of the distribution of available tones in a raw image.
        </para>

    </sect3>

    <sect3>
        <title>Should I use a large-gamut or a small-gamut working space? </title>

        <para>
            One major consideration in choosing a working space is that some working spaces are bigger than others, meaning they cover more of the visible spectrum (and as a consequence include some imaginary colors - mathematical constructs that don't really exist). These bigger spaces offer the advantage of allowing you to keep all the colors captured by your camera and preserved by the LCMS conversion from your camera profile to the super-wide-gamut profile connection space and out again to your chosen working space.
        </para>

        <para>
            But keeping all the possible colors comes at a price, as explained below. And it seems that any given digital image likely only contains a small subset of all the possible visible colors that your camera is capable of capturing. This small subset is easily contained in one of the smaller working spaces (an exception requiring a larger color gamut would be a picture of a highly saturated object such as yellow daffodil).
        </para>

        <para>
            Using a very large working space means that editing your image (applying curves, increasing saturation, &etc;) can easily produce colors that your eventual output device (printer, monitor) simply cannot reproduce (you cannot see these colors while you're editing, either). So the conversion from your working space to your output device space (say your printer) will have to remap the out-of-gamut colors in your edited image, some of which might even be totally imaginary, to your printer color space with its much smaller color gamut. This remapping process will lead to inaccurate colors and loss of saturation at best. Even worse, the remapping can easily lead to banding (posterization - gaps in what should be a smooth color transition, say, across an expanse of blue sky) and clipping (&eg; your carefully crafted muted transitions across delicate shades of red, for example, might get remapped to a solid block of dull red after conversion to your printer's color space). Also, the experts say that 8-bit images just don't have enough tones to stretch across a wide gamut working space without banding and loss of saturation, even before conversion to an output space. So if you choose a large gamut working space, make sure you start with a 16-bit image.
        </para>

        <para>
            To summarize, large gamut working spaces, improperly handled, can lead to lost information on output. Small gamut working spaces can clip information on input. Medium-sized gamut working spaces try to strike a happy medium. Like Wikipedia says, it's a trade-off.
        </para>

        <para>
            Here are some oft-repeated bits of advice on choosing a working space:
        </para>

        <para>
            <orderedlist>

                <listitem><para>
                    For images intended for the web, use (or at least convert the final image to) sRGB.
                </para></listitem>

                <listitem><para>
                    For the most accuracy in your image editing (that is, making the most of your limited "bits" with the least risk of banding or clipping when you convert your image from your working space to an output space), use the smallest working space that includes all the colors in the scene that you photographed, plus a little extra room for those new colors you intentionally produce as you edit.
                </para></listitem>

                <listitem><para>
                    If you are working in 8-bits rather than 16-bits, choose a smaller rather than a larger working space to avoid clipping and banding.
                </para></listitem>

                <listitem><para>
                    For archival purposes, convert your raw file to a 16-bit tiff with a large gamut working space to avoid loosing color information. Then convert this archival tiff to your medium-gamut or large-gamut working space of choice (saving the converted working tiff under a new name, of course).
                </para></listitem>

            </orderedlist>
        </para>

        <para>
            For more information on choosing a working space, see <ulink url="http://www.brucelindbloom.com/">this page</ulink>, Information about RGB Working Spaces for a visual comparison of the gamut (array of included colors) of the various working color spaces. See <ulink url="http://www.luminous-landscape.com/tutorials/prophoto-rgb.shtml">here</ulink> and <ulink url="http://www.cambridgeincolour.com/tutorials/sRGB-AdobeRGB1998.htm">here</ulink> for a pro- and con- presentation, respectively, of the merits of using large gamut working spaces. And while you are on the cambridgeincolour.com website, check out the tutorial on color management.
        </para>

    </sect3>

</sect2>

<!--
Local Variables:
mode: sgml
sgml-minimize-attributes:nil
sgml-general-insert-case:lower
sgml-indent-step:0
sgml-indent-data:nil
End:
-->
