How Photoshop Clone Stamp Tool Duplicates Pixels
The Clone Stamp Tool in Adobe Photoshop duplicates pixel regions through a process of coordinate sampling, spatial offset mapping, and raster compositing. By establishing an initial source anchor via user input, Photoshop reads raw pixel data—including color channels and transparency—from an in-memory image buffer and redraws that exact data at a target destination based on designated brush dynamics.
Source Coordinate Mapping and Offset Vectors
The fundamental mechanism of the Clone Stamp Tool relies on a coordinate offset vector. When a user defines a sampling point using the Alt-click (Windows) or Option-click (macOS) command, Photoshop registers the Cartesian coordinates \((X_1, Y_1)\) of that specific pixel location within the document space.
When the user initiates a brush stroke at a new target point \((X_2, Y_2)\), the software calculates an offset vector:
\[\Delta X = X_2 - X_1\] \[\Delta Y = Y_2 - Y_1\]
With the "Aligned" option enabled, Photoshop maintains this relative offset constant throughout multiple distinct brush strokes. As the cursor moves, the sampling coordinates continuously update relative to the cursor's current position \((X_n - \Delta X, Y_n - \Delta Y)\). If "Aligned" is disabled, the software resets the sampling point back to the original source coordinates \((X_1, Y_1)\) every time the mouse button or stylus is released.
Memory Buffer and Layer Sampling
Photoshop reads the pixel data directly from the document's raster cache. Depending on the tool's configuration, the software samples from different memory states:
- Current Layer: Queries only the active layer's pixel array, ignoring all visibility or layers above and below.
- Current & Below: Performs a compositing operation from the active layer downward, sampling the flattened result up to that point in the layer stack.
- All Layers: Samples the fully composited image buffer as displayed in the viewport, pulling data from all visible layers.
During this read operation, Photoshop extracts the 8-bit, 16-bit, or 32-bit color values (such as Red, Green, and Blue) along with the Alpha (transparency) channel for every pixel within the footprint of the brush.
Brush Dynamics and Alpha Masking
The duplicated pixels are not simply pasted as hard rectangular blocks; they are modulated through Photoshop’s brush rendering engine.
- Spatial Mask Generation: Photoshop generates a temporary grayscale mask representing the brush tip. The hardness parameter determines the feathering (a Gaussian or cosine falloff) at the edges of the stroke.
- Opacity and Flow Calculations: The opacity setting determines the maximum transparency of the copied pixels, while flow dictates the rate at which color values accumulate over successive redraw cycles.
- Interpolation: If the user has applied rotation, scaling, or flipping via the Clone Source panel, Photoshop applies an affine transformation matrix to the sampled pixel array before writing it to the destination, using bicubic or bilinear interpolation to resample the transformed data.
Compositing and Blend Modes
Once the sampled pixels are transformed and masked, they pass through the software's compositing pipeline. Photoshop applies standard digital blend mode algorithms (such as Normal, Multiply, Screen, or Overlay) between the sampled source values and the existing destination pixels. The final RGBA values are then written to the active layer's raster array, completing the pixel duplication process in real time.