NiVO / BY TECHNOGISGermany · Indonesia
Preview compositing tutorial

PNG Straight Alpha: Avoid Applying Opacity Twice in a Drone Preview Pipeline

Compare straight-alpha and double-multiplied calculations on constructed linear RGB values, keeping PNG representation separate from full color-managed rendering.

PNG Straight Alpha: Avoid Applying Opacity Twice in a Drone Preview Pipeline

Identify alpha association before explaining a dark edge

A preview pipeline can produce an unexpectedly dark transparent edge when one stage assumes that color values have already been multiplied by opacity and another stage multiplies them again. Before describing that appearance as damaged aerial imagery or missing map content, identify the representation passed between stages. Straight and premultiplied color values have different input contracts. A familiar RGBA label alone does not state which contract a decoded buffer or graphics API expects.

This tutorial uses constructed normalized linear RGB values and an opacity fraction. It does not open or alter a PNG, sample a real drone image, assess a monitor, or establish a NiVO rendering implementation. The catalogue photograph supplies separate product context. The exercise compares one correct straight-alpha calculation with an explicitly mistaken double multiplication. Its purpose is to explain a representation error, with no inference about actual survey coverage, image quality, transparency metadata, or the condition of a delivered map.

Read the PNG alpha rule and the compositing domain together

The W3C PNG specification states that stored color values are not premultiplied by alpha. This is also called unassociated alpha. Its alpha-processing guidance composites foreground and background intensity samples as alpha times foreground plus one minus alpha times background, with normalized values. The guidance explicitly calls for intensity samples rather than gamma-encoded samples. Those two requirements belong together: knowing that alpha is straight does not justify applying a linear compositing equation directly to arbitrary encoded image bytes.

For the invented foreground channels zero point eight, zero point four, and zero point two, alpha one-half, and a white linear background, the correct result is zero point nine, zero point seven, and zero point six. If the foreground is first multiplied by one-half and then treated as straight input to the same equation, the result becomes zero point seven, zero point six, and zero point five five. The second calculation deliberately illustrates the mistake; it is not an alternative rendering recommendation or a measured discrepancy in a real preview.

Restored NiVO VTOL V3 product image from the supplied brochure
Restored NiVO VTOL V3 product image from the supplied brochure.Source: NiVO / TechnoGIS catalogue materials supplied by the site owner · Catalogue photo
Product context only; this photograph does not depict the constructed examples in this article.

Compare two arithmetic paths on declared linear inputs

Run the following Python function locally. It accepts three foreground channels, one alpha fraction, and three opaque background channels, all finite and within zero through one. Booleans are rejected. The caller must already have values in the same linear intensity domain. The function performs no transfer-function decoding, profile conversion, image parsing, or display encoding. That explicit contract keeps the arithmetic demonstration useful without suggesting that it is a complete PNG compositor or color-management pipeline.

The returned dictionary includes the intermediate premultiplied foreground, the correct straight-over result, and the double-multiplied result clearly named wrong. Compare the two result tuples with the constructed values above. Floating-point comparisons should allow normal numerical rounding instead of requiring every printed decimal to have an identical spelling. The input sequences remain unchanged. No corrected image is produced, and the function does not decide how a real application should store an intermediate buffer or which representation its next stage requires.

import math

def compare_linear_alpha(foreground, alpha, background):
    for color in (foreground, background):
        if type(color) not in (list, tuple) or len(color) != 3:
            raise ValueError("Expected three linear RGB channels")
    values = tuple(foreground) + (alpha,) + tuple(background)
    if any(type(x) not in (int, float) or not math.isfinite(x)
           or not 0 <= x <= 1 for x in values):
        raise ValueError("Expected finite normalized linear values")
    premultiplied = tuple(alpha * x for x in foreground)
    correct = tuple(alpha * f + (1 - alpha) * b
                    for f, b in zip(foreground, background))
    wrong = tuple(alpha * f + (1 - alpha) * b
                  for f, b in zip(premultiplied, background))
    return {"premultiplied_foreground": premultiplied,
            "straight_over": correct, "wrong_double_alpha": wrong}

# Constructed linear values, not encoded image samples.
print(compare_linear_alpha((0.8, 0.4, 0.2), 0.5, (1, 1, 1)))

Use endpoint and partial-opacity cases to expose the mistake

Test alpha equal to zero and one separately. Both arithmetic paths agree at those endpoints, so an implementation tested only on fully transparent or fully opaque inputs can miss the double-multiplication error. The half-opacity case exposes it clearly. Also test a black background and unequal channel values to avoid hiding the behavior behind a single grayscale example. Keep the exact input values and expected equations with the test instead of relying solely on a visually plausible swatch.

For the stated non-negative linear profile, applying alpha twice reduces the foreground contribution at partial opacity. That observation explains the constructed numbers without establishing the cause of any actual dark edge. A real preview could differ for other reasons, including color-space handling or another processing step. Retain the original asset and identify the stage where representations change before proposing a correction. Do not repair a file merely because this small arithmetic example resembles an appearance seen in a screenshot.

Keep stored PNG samples, intermediate buffers, and display output distinct

PNG storage and an application intermediate buffer are different boundaries. A decoder or graphics pipeline may deliberately convert straight samples into a premultiplied working representation for later operations. That does not change the PNG storage rule, and it does not make premultiplication inherently erroneous. The error demonstrated here is treating an already multiplied intermediate as straight input and multiplying again. Document the contract on each side of the boundary, including whether a conversion has already occurred.

Similarly, normalized numeric values are not automatically linear intensity values. Dividing an encoded byte by its maximum establishes a numeric range, but it does not by itself undo a transfer function or reconcile foreground and background color spaces. The function deliberately omits those conversions. If a real investigation concerns image rendering, retain the relevant color metadata and use an established color-aware decoder or renderer alongside a narrow trace. Keep transparency interpretation, analytical raster validity, and survey evidence separate from the display calculation.

At zero opacity, a composited output equals the background regardless of the foreground channels. That output alone therefore cannot recover the original straight foreground color. Do not divide by a zero alpha value or invent a hidden color when trying to reverse an undocumented processing step. Preserve the original stored samples and association information whenever they are available. Any conversion back from a premultiplied working representation needs its own explicit zero-opacity policy and rounding treatment; neither inversion nor recovery is performed by this comparison function.

Deliver a representation trace with the unchanged preview

For an actual handoff investigation, retain the source image identity, decoder and renderer versions, selected pixel or edge location, stored color and alpha representation, any transfer-function or profile conversion, intermediate association state, background, and output encoding. Include a small independently checked example at the stage being examined. If a change is authorized, record the before-and-after behavior and verify the complete receiving path. This tutorial supplies only the isolated linear comparison and does not perform that wider validation.

In a NiVO-related preview discussion, this method explains why opacity can be applied twice even when each processing stage appears locally reasonable. It makes no product-format, accuracy, ground-coverage, or actual image-quality claim. Preserve the unchanged preview and continue the checks required for its intended use. The useful outcome is an auditable representation contract and a reproducible partial-opacity example, with the domain and processing boundary explicit rather than concealed by a generic RGBA label.

Technical references

  1. W3C PNG alpha representation: unassociated color values ↗
  2. W3C PNG alpha processing: compositing in the intensity domain ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team