RAW Processing
This page follows a RAW file from the bytes on disk to the linear image that you edit. Since 1.7.0, almost all of it runs on the GPU: the CPU only unpacks the sensor data, then the GPU demosaics it and runs one develop pass for highlights, color, noise reduction and sharpening. This is the rendering engine introduced in 1.7.0 (Furka).
The code lives mainly in decode/raw_processing.rs, decode/demosaic.rs with shaders/demosaic.wgsl, decode/develop.rs with shaders/develop.wgsl, decode/white_balance.rs and decode/baseline_exposure.rs, plus the rawler decoder from the RapidRAW-DngLab fork of dnglab.
Most demos use real RAW files from Sony cameras. The highlight reconstruction demos use a synthetic test DNG with a clipped sun, because there the exact scene is known and every clipped channel can be mapped. All photos on this page are real RapidRAW output; the charts plot the formulas from the code.
1. Decoding
RAW or not is decided by the file extension. For RAW files, rawler identifies the format by looking at the content (TIFF tags, container types, the camera make) and picks the right decoder. Files are memory-mapped, so opening is fast even on slow disks. For EXIF data and embedded previews, RapidRAW first reads only the start of the file (256 KB, then 1 MB, 4 MB and 16 MB if needed) and only falls back to the whole file if that isn't enough. On a network drive this means the library and thumbnails don't download every RAW in full.
rawler unpacks (decompresses) the sensor data on the CPU into one 16-bit value per pixel. For most cameras that is all RapidRAW needs from it: the 16-bit values go to the GPU as they are, and every step below runs there. The few files that can't use the GPU demosaic (see CPU fallback) also use rawler's rescaling, demosaicing and cropping to the active area, but still get RapidRAW's own white balance, color conversion and highlight handling.
If decoding fails, RapidRAW looks for the largest JPEG preview embedded in the file, converts it to linear light and scales it by 0.4 so it sits at a RAW-like level. You can still edit it, but it is the camera's processed preview, and the editor shows a message that says so. A GPU error in the demosaic or develop pass leads to the same fallback, see GPU & Drivers.
Apple RAW 9 (macOS 27+, optional). When enabled, Apple's Core Image RAW engine develops the file instead (with highlight recovery on, and its own boost, local tone mapping, contrast, sharpening and lens correction off) and returns extended linear sRGB. RapidRAW's own steps below, including base color noise reduction and pre-sharpening, are then skipped. Thumbnails always use RapidRAW's own decoder, and so do files that Apple's engine can't open.
Non-RAW files (JPEG, PNG, TIFF, ...) are decoded, rotated by their EXIF orientation, converted to sRGB if they carry a color profile, and kept sRGB-encoded. The GPU converts them to linear.
2. Normalization
The first GPU step turns the 16-bit values into numbers the rest of the pipeline can work with:
- Black level is subtracted per position in the 2x2 color filter pattern. Values below black are clipped to 0.
- White level: RapidRAW scales the data so that 1.0 equals the sensor's white level. Values above it are kept (up to 1000) instead of being clipped, so later steps can still work with them.
- White balance: each value is multiplied by the camera's as-shot multiplier for its color (see White balance).
DNG linearization tables are applied earlier, by rawler while unpacking. DNG opcode lists (for example lens corrections stored by phones) are not applied.
Crop: the default crop from the file or the camera database decides which part of the sensor becomes the photo. Demosaicing still reads the pixels just outside it (inside the sensor's active area), so the edges of the photo are as clean as the center. Highlight reconstruction only looks at pixels inside the crop, so masked border pixels don't confuse it.
3. Demosaicing
A camera sensor records only one color per pixel, in a mosaic pattern. Demosaicing estimates the two missing colors at every pixel. It is also where most "digital" artifacts are born: colored speckles on fine grey detail (false color), maze-like patterns in fine textures, and colored moiré on fabric, fences and railings.

| Sensor | Editor and export | Thumbnails (fast mode) |
|---|---|---|
| Bayer (2x2) | RCD for green, then residual interpolation for red and blue, on the GPU | 4x4 block average, 1/4 size |
| Fujifilm X-Trans (6x6) | Markesteijn, 3 passes, on the GPU | 3x3 block average, 1/3 size |
| Other sensors | On the CPU, see CPU fallback | Superpixel |
In plain words, all of these methods work the same way. First they find out which way edges and lines run at each pixel. Then they fill in the missing values along the edge, not across it. And they lean on green: a Bayer sensor has twice as many green pixels as red or blue ones, so green carries most of the detail. Red and blue are not interpolated on their own. RapidRAW predicts them from green and only fills in how much they differ from that prediction, which changes slowly. That is why fine grey detail stays grey instead of turning into colored speckles, and why a thin line doesn't break up into a maze.
Demosaicing runs on white-balanced data (see Normalization), so a grey object has R = G = B, and the color differences and ratios the methods rely on stay small and smooth.
Tiles
The 16-bit sensor data is uploaded to the GPU once, as it is stored in the file (2 bytes per pixel). The GPU then works through the image in square tiles. A tile is at most 2048 px, and its working buffers may use at most 320 MB of GPU memory. That makes a tile about 1,380 px, or smaller on GPUs that only allow small buffers. Each tile also reads a border of 40 px (Bayer) or 32 px (X-Trans) that is computed and then thrown away, so the seams between tiles don't show. At the edge of the sensor, the data is mirrored in a way that keeps the color pattern intact.
Bayer green: RCD
RCD (Ratio Corrected Demosaicing, by Luis Sanz Rodríguez) fills in green at the red and blue pixels:
- Direction. At every pixel, a 7-tap high-pass filter measures how much the mosaic changes vertically and horizontally (V and H, each summed over three neighbouring rows or columns).
d = V / (V + H)says which way the detail runs. It is refined with the average of the four diagonal neighbours: whichever of the two is further from 0.5 (more decided) is used. - Four estimates. For north, south, west and east, the neighbouring green value is corrected by how the local brightness changes, using a 3x3 low-pass version
Lof the mosaic. This ratio correction gives RCD its name. - Blend. North and south are mixed by their gradients (the smoother side counts more), and so are west and east. The vertical and horizontal results are then mixed by
d: where the image changes a lot vertically, the horizontal estimate wins. - Green debias. In bright, flat areas such as snow, RCD can leave a faint checkerboard: the green values it fills in at red and blue pixels end up a little higher or lower than the real green pixels next to them. RapidRAW measures that checkerboard with a 7x7 binomial filter (weights 1 6 15 20 15 6 1 in each direction) on green with alternating signs, and subtracts it from the filled-in pixels only. The correction is limited to 4% of the local green level, so real fine detail is left alone.
d = V / (V + H) high-pass taps: 1 −3 −1 6 −1 −3 1
G_N = G(0,−1) · 2·L(0,0) / (L(0,0) + L(0,−2)) and G_S, G_W, G_E likewise
G_v = (grad_S·G_N + grad_N·G_S) / (grad_N + grad_S) grad = sum of 4 absolute differences
G = (1 − d)·G_v + d·G_h
Bayer red and blue: residual interpolation
With a full green channel, RapidRAW predicts red and blue from it and only interpolates the error of that prediction (the residual):
- Local fits. In a 9x9 window around every pixel, red is fitted as
a·G + bfrom the red pixels in the window, and blue the same way from the blue pixels. There are two fits. One matches the values, like a guided filter, with a small regularization that grows with brightness the way photon noise does. The other matches the local curvature (Laplacians) of red and green instead of the values (minimized-Laplacian residual interpolation, MLRI), and is weighted by how well it fits its window. The fit coefficients are then averaged again over 9x9. - Residuals. Each fit gives a tentative red at every pixel. At the real red pixels, the difference between the measured and the tentative value is known. It is interpolated bilinearly to all other pixels and added back.
- Choose per pixel. The two results are blended with weights that drop where a result strays from a plain color-difference interpolation and where that difference jumps around. The weights are smoothed with a Gaussian (σ = 1.5 px).
- At the real red and blue pixels, the measured values are kept.
Blending two residual interpolations per pixel is the idea behind adaptive residual interpolation (ARI). RapidRAW uses it only for red and blue, on top of RCD green, because ARI's own green step can leave maze patterns.
X-Trans: Markesteijn, 3 passes
The X-Trans pattern has no simple rows of alternating colors, so Bayer methods don't fit it. RapidRAW uses Frank Markesteijn's algorithm with three passes:
- Green. At every red and blue pixel, green is estimated in four directions with fixed weighted formulas over the nearest green pixels. Each estimate is clamped between the lowest and the highest of the six nearest greens.
- Red and blue are filled in from their difference to green: at the green pixels that sit alone between red and blue ones (horizontally, vertically, or along whichever of the two is smoother), at the red and blue pixels, and at the remaining green pixels from their nearest red and blue neighbours.
- Passes 2 and 3 recalculate green at the red and blue pixels from the closer, already interpolated values, and then repeat step 2. From the second pass on, there are 8 candidate results instead of 4.
- Choose. For every candidate, RapidRAW measures how smoothly brightness and color change along its direction (second differences in a luma and chroma space with Rec.2020 luma weights) and counts the smooth pixels around each pixel. Over a 5x5 area, it keeps the candidates within 1/8 of the best score and averages them.
Thumbnails: binned instead of demosaiced
When RapidRAW decodes a RAW for a library thumbnail (see Performance), it skips demosaicing. On the CPU, it averages each color inside blocks of 4x4 (Bayer) or 3x3 (X-Trans) sensor pixels, which directly gives an image at 1/4 or 1/3 of the full size. The X-Trans blocks are lined up with the pattern so that each one holds 5 green, 2 red and 2 blue pixels. Highlight reconstruction and color conversion then run in the GPU develop pass as usual, but without noise reduction and pre-sharpening, and with values clipped at 1.0.
CPU fallback
A few files can't use the GPU demosaic. rawler demosaics them on the CPU, and they rejoin the normal path afterwards:
- Fujifilm SuperCCD cameras (whose pixel grid is rotated by 45°), RAWs that store floating-point values and unusual three-color patterns: PPG, or rawler's X-Trans method for 6x6 patterns, then the same GPU develop pass as every other RAW.
- 4-color sensors (for example CYGM): bilinear demosaicing, then color conversion and the simpler highlight method on the CPU. Base color noise reduction and pre-sharpening still run on the GPU.
- RAWs without a usable color matrix: PPG (or rawler's X-Trans method), no color conversion, the simpler highlight method, then base color noise reduction and pre-sharpening on the GPU.
- Linear DNGs and monochrome sensors have nothing to demosaic. See Linear DNGs.
In fast mode (thumbnails), these files use rawler's superpixel method instead.
False color
Even a good demosaicer guesses wrong on some detail near the pixel pitch, and sensor noise adds colored speckles of its own. RCD with residual interpolation, and Markesteijn on X-Trans, produce much less false color and moiré than PPG, which RapidRAW used for Bayer sensors before 1.7.0.
What is left is removed later in the same develop pass by Base Color Noise Reduction: chroma that only follows the luminance texture is pulled back to the smooth color of the surroundings.
4. White balance
The camera stores the white balance as channel multipliers ("as-shot neutral"). RapidRAW uses them twice:
- Right before demosaicing, each channel is multiplied by its as-shot multiplier, so demosaicing and highlight reconstruction see a neutral object as R = G = B.
- Before the color conversion, the multipliers are taken out again, and the camera color matrix maps the camera's as-shot white to D65 white with a Bradford chromatic adaptation (see the next section).
So the decoded image is balanced to "as shot". Your Temperature and Tint edits are applied later on the GPU as an additional Bradford adaptation in LMS space, relative to as shot. The as-shot temperature and tint shown in Kelvin mode are calculated with Robertson's method from the camera neutral.
5. Highlight reconstruction
When a bright area is clipped in one or two color channels, a naive conversion produces wrong colors: skies turn cyan or flat yellow, and fully clipped areas turn magenta. RapidRAW reconstructs the missing channels in the GPU develop pass, right after demosaicing. There is no setting for it. It runs on every RAW with a normal three-color sensor and a usable color matrix: Bayer, X-Trans, and the files in the first group of the CPU fallback.
Step 1: find the real clip level. Many cameras saturate slightly below the white level written in the file. RapidRAW builds a histogram of each channel between 0.75 and 1.25 of the white level (2048 bins, before white balance) and looks for a sharp plateau, the pile-up of clipped pixels. The fullest bin counts as a plateau when it holds at least 1 in 5000 pixels (and at least 64), is at least 8 times higher than the typical (median) bin 0.5% to 2% below it, and fewer pixels lie above it than in it. If a channel has no plateau, the lowest level found in the other channels is used, or 1.0 if there is none. A channel then counts as clipped from 98.5% of its clip level, and reconstruction fades in from 90%.
Step 2: learn how the channels relate. Around every clipped area (within 24 px), RapidRAW looks at pixels that are bright but not clipped: above 20% of the clip level, below the clipped threshold, and more than 2 px away from a clipped pixel of the same channel. From them it learns how each channel compares to the other two:
opposed(c) = ( (∛p_other1 + ∛p_other2) / 2 )³ cube-root mean of the other two channels
offset(c) = weighted average of (p_c − opposed(c)), weight = (p_c / clip)²
These offsets are stored on a coarse grid (cells of 1 to 8 px, depending on the image size) and the gaps are filled smoothly with a push-pull pyramid: a cell with enough samples keeps its own value, a sparse one leans on the coarser level. This gives a local "color model" for every clipped area: for example, that red is normally a bit higher than green and blue in this sunset.
Step 3: rebuild the clipped channels. For every pixel close to clipping:
blend = smoothstep(0.90·clip, 0.985·clip, observed) soft start at 90 % of clip
rebuilt = max(observed, opposed + offset) never darker than recorded
p = observed + (rebuilt − observed)·blend 3 iterations
Step 4: keep light sources neutral. When all channels are near clipping (the sun, lamps), there's little real color information left. The rebuilt color is pulled toward neutral, down to 35% of its saturation, depending on how close the least-clipped channel is to clipping. If that channel is still 30% or more below its clip level, the full color is kept.
Step 5: fill fully blown cores. Pixels where all three channels are above 90% of their clip level get a gentle tint borrowed from the ring around them. RapidRAW samples nearby pixels (within 24 px) where exactly one channel is clipped, averages their rebuilt color as log ratios (red to green and blue to green, preferring the less saturated samples), and fills the gaps with a second push-pull pyramid. The tint is applied at half strength and fades out when the surrounding color is very saturated. So a blown sun becomes a warm white rather than pure white or magenta. Brightness (the sum of the three channels) is preserved, and no channel ends up below what the sensor recorded.
The simpler method. Files without a usable color matrix, linear DNGs and 4-color sensors use a simpler per-pixel method on the CPU, after color conversion: clipped green under red and blue (the classic magenta cast) is filled in, and colors are smoothly desaturated as they approach and exceed white.
6. Camera color
Color matrices. Each camera has matrices that convert its RGB to CIE XYZ. Most cameras have two, measured under tungsten (illuminant A, 2856 K) and daylight (D65, 6504 K). RapidRAW blends them according to the white balance of the shot, as the DNG specification describes:
M = M_D65
repeat until the temperature changes by less than 0.1 K (max 20 times):
T = color temperature of the as-shot white using M
w = clamp( (1/T − 1/6504) / (1/2856 − 1/6504), 0, 1 ) blend in mired
M = w·M_A + (1 − w)·M_D65
So a tungsten-lit photo uses the tungsten matrix, a daylight photo the daylight one, and anything in between a mix. This gives more accurate colors under artificial light than using the daylight matrix alone. A camera with only one matrix uses that one.
w from the formula above. Below 2856 K only the tungsten matrix is used, above 6504 K only the daylight one. Because the blend is linear in 1/T, most of the change happens at the warm end.Camera to sRGB:
C = pseudo-inverse(M) camera → XYZ
T = M_XYZ→sRGB · Bradford(as-shot white → D65)
camera → sRGB = T · C
In the develop pass, each pixel is first divided by the as-shot multipliers again (undoing the white balance from section 4), then multiplied by this matrix.
Gamut compression. Some colors a camera records (deep blue LEDs, saturated flowers) are outside the sRGB gamut and would produce negative values. Simply clipping them causes harsh, blotchy color. RapidRAW compresses them smoothly toward the neutral axis with the ACES reference gamut compression curve:
a = max(r, g, b) the neutral value
d = (a − channel) / a distance from neutral (> 1 means negative)
f(d) = d if d ≤ 0.8
f(d) = 0.8 + (d − 0.8) / (1 + ((d − 0.8)/s)^1.2)^(1/1.2) otherwise
channel = a − f(d)·a
Unlike ACES, which uses fixed limits, RapidRAW computes the limit for each camera from its own primaries, so the most saturated color the camera can record lands exactly on the edge of the gamut. Compression is only enabled for channels that can actually go negative for that camera.
The result is linear Rec.709/sRGB RGB with a D65 white, limited to 0 to 1000 (0 to 1 for thumbnails). The develop pass applies the EXIF orientation at the same time, so the next two steps already see the photo the right way up.
7. Base Color Noise Reduction
Default 0.5 (0 to 1), in Settings → Image Preprocessing. This stage removes color noise and demosaicing false color before you start editing, and never touches luminance. It runs in the GPU develop pass, on RAW files only, unless Apply Preprocessing to Non-RAWs is on. Thumbnails skip it.
First, the image is converted to square-root opponent channels:
q = √(L + 0.002) L = Rec.709 luma
cr = √(R + 0.002) − q
cb = √(B + 0.002) − q
Then it goes through these steps:
- Variance stabilization: the square root makes photon noise roughly equal at all brightness levels, so one setting works for shadows and highlights.
- Noise estimate: the noise level of luma and chroma is measured from the photo itself. RapidRAW takes the differences between pixels 4 px apart on a sparse grid (every 7th pixel of every 8th row) and uses their median, times 1.4826/√2, as the noise σ. So the filter adapts to each photo's ISO.
- Multi-scale filtering: the image is averaged down to half and quarter resolution. At quarter resolution, a weighted 3x3 average gives a first chroma reference and a 5x5 filter cleans it. The result is guided-upsampled to half resolution and becomes the reference for the same 5x5 filter there. The filter's weights depend on distance, on luma similarity, on how close each neighbour's chroma is to the reference, and on whether the neighbour sits on a luma edge. It fits a local linear model of chroma against luma: chroma changes that follow luma edges (real colored edges) are kept; chroma that does not follow luma (noise) is averaged out.
- Texture-aware coring: a chroma deviation from the reference only survives if it is clearly larger than the noise floor plus a margin proportional to the local luma texture (the luma range in the 3x3 neighbourhood). This runs at half and again at full resolution, and it is what removes demosaic false color in fine detail.
- Full-resolution reconstruction: the result is guided-upsampled to full size. Near strong luma edges the upsampled chroma is preferred, chroma is clamped to the range of the coarse neighbours (no new colors or halos), and RGB is rebuilt at the original luminance.
The amount widens the tolerances and the coring threshold:
luma tolerance = (1.5 + 2·amount) · σ_luma
chroma tolerance = (2 + 3·amount) · σ_chroma
spatial σ = 1.5 + amount in half- or quarter-resolution pixels
keep = clamp( |Δchroma| / (core + 4·(0.5 + amount)·luma_range) − 1, 0, 1 )
core = (2 + 2·amount) · σ_chroma at full resolution
8. Base Pre-Sharpening
Default 0.35 (0 to 1). A gentle unsharp mask on square-root luminance that recovers the slight softness of demosaicing. It runs in the GPU develop pass right after color noise reduction and is skipped for thumbnails. Like the noise reduction, it measures the noise of the photo first, so it doesn't sharpen grain:
d = q − blur5x5(q) q = √(luma + 0.002), binomial [1 4 6 4 1] blur
σ = 1.4826 · median |d| sampled at every 5th pixel of every 16th row
d = d³ / (d² + (1.5·σ)²) soft coring: noise-sized detail is ignored
d = d / (1 + |d| · 0.2/σ) large edges are compressed
delta = 4.5·amount·d
The change is then limited smoothly against the local 3x3 minimum and maximum. A brightening can approach, but never pass, the neighbourhood maximum plus 15% of the local range, and a darkening the minimum minus 5% of it. Dark halos are more visible, so they are limited more, and darkening is also scaled by 0.7. The result is applied as a luminance ratio, so colors don't shift, and it never creates new values above 1.0.
9. Baseline exposure and highlight-preserving modes
Baseline Exposure brightens RAW files by a fixed amount (default +0.7 EV, like darktable), so they open at a similar brightness to other editors. It is on by default since 1.7.0; if you used an older version, your saved choice is kept. It is added invisibly to the Exposure slider.
DNG files can carry their own BaselineExposure tag (plus an optional BaselineExposureOffset). When a file has it, RapidRAW uses the tag value instead of the fixed amount. Drones and phones use this tag to say how much their DNGs should be brightened, so adding the fixed amount on top, as versions before 1.7.0 did, made them too bright. Monochrome RAWs without the tag get no fixed amount.
Highlight Preservation Compensation (on by default) reads the maker notes and brightens files from camera modes that deliberately underexpose:
| Camera | Mode | Added |
|---|---|---|
| Fujifilm | DR200 / DR400 | +1 / +2 EV |
| Canon | Highlight Tone Priority | +1 EV |
| Canon | Auto Lighting Optimizer low / standard / high | +0.33 / +0.5 / +0.66 EV |
| Nikon | Active D-Lighting (by level) | +0.33 to +1.33 EV |
| Nikon | HLG tone mode | +2 EV |
| Olympus / OM | Gradation settings | +0.33 / +0.66 EV |
| Pentax | Dynamic Range Expansion | +1 EV |
This compensation is clamped to −1 to +4 EV. Both settings only apply to new edits, so edits made before these settings existed keep their look.
10. Linear DNGs
Linear DNGs (already demosaiced, for example from phones and HDR tools) skip demosaicing. Their highlights use the simpler method from section 5, and base color noise reduction and pre-sharpening run on the GPU afterwards. The four Linear RAW Processing options control two switches:
| Option | Applies the color matrix | Undoes a gamma curve |
|---|---|---|
| Auto | yes | no |
| Apply Gamma | yes | yes |
| Skip Calibrate | no | no |
| Apply Gamma & Skip Calibrate | no | yes |
"Skip Calibrate" treats the stored RGB as linear sRGB directly, which fixes color casts when a file's matrix doesn't match its data. "Apply Gamma" is for files that store gamma-encoded data in a linear container.
11. Performance
- For most RAWs, only unpacking the compressed sensor data runs on the CPU. Demosaicing and the develop pass run on the GPU, on their own queue (a second device on the same graphics card), separate from the one that draws the editor. So zooming and panning stay smooth while a photo loads. If the driver can't open that queue, decoding shares the display queue.
- The sensor data is uploaded as 16-bit integers, in bands of rows as the tiles move down the image. Nothing comes back to the CPU until the end: the developed image is read back once, in bands of up to 64 MB, while the GPU already works on the next band.
- The GPU programs for demosaicing and the develop pass are compiled in the background when RapidRAW starts.
- If the editor and the background preloader ask for the same file at the same time, it is decoded only once.
- A decode that is no longer needed is cancelled when you switch to another photo.
- Thumbnails of edited RAWs use the fast binned decode. So do all RAW thumbnails when Always Decode RAW is on or you set Default Adjustments. Otherwise RAW thumbnails use the JPEG preview embedded in the file.
RapidRAW