NiVO / BY TECHNOGISGermany · Indonesia
Preview transparency tutorial

PNG tRNS Transparency: Read Opaque Palette Defaults in a Drone Map Preview

Expand a shortened indexed-PNG transparency table, retain the opaque defaults for omitted entries, and keep display alpha separate from raster validity.

PNG tRNS Transparency: Read Opaque Palette Defaults in a Drone Map Preview

Identify the transparency representation before judging the preview

A map preview with transparent regions can invite an immediate explanation about missing raster data or an incomplete drone survey. First inspect how the image represents transparency. An indexed PNG stores pixel indices into a color palette, and its optional tRNS chunk can provide a separate alpha table for those palette entries. That table may be shorter than the palette. Treating every omitted alpha entry as zero changes the declared display behavior and can make valid palette colors disappear in a custom reader.

This tutorial expands a small constructed alpha table and looks up transparency values for a short list of decoded indices. It does not open a PNG, decompress image data, inspect an actual NiVO product image, or determine which ground areas were surveyed. The example concerns indexed PNG transparency, not a complete rendering pipeline or an analytical raster validity policy. The catalogue photograph supplies separate product context. Keep that distinction explicit when using the example to explain why a preview or diagnostic display differs between tools.

Apply the indexed-PNG rule for a shortened alpha table

The W3C PNG Third Edition specification describes tRNS for color type three as one-byte alpha values corresponding to palette entries. Zero means fully transparent and 255 means fully opaque, regardless of the image bit depth. The table cannot contain more alpha entries than the palette contains colors. When it contains fewer, the unspecified tail entries have alpha 255. An entirely opaque indexed image can omit the tRNS chunk. These rules explain the default that the teaching function reconstructs.

For a four-entry palette and supplied alpha bytes zero and 128, the complete alpha table is zero, 128, 255, and 255. The first two values come from the supplied table; the final two come from its defined opaque default. A pixel using palette index three is therefore fully opaque in this constructed case, even though no fourth alpha byte was supplied. The intermediate value 128 describes partial alpha, not a measured percentage of land coverage, canopy density, confidence, or valid survey observations.

NiVO VTOL V5 product image showing the fixed wing and vertical-lift rotors
NiVO VTOL V5 product image showing the fixed wing and vertical-lift rotors.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.

Expand the table and inspect decoded pixel indices

The Python function below receives the known palette entry count, either supplied tRNS bytes or None for an absent chunk, and a small sequence of already decoded pixel indices. It validates the teaching input types and index bounds, builds an opaque table, then substitutes the supplied alpha bytes at its beginning. The result includes both the full alpha table and the per-index lookup. This keeps the default expansion visible rather than hiding it inside an unexplained image display.

Run the example locally. For indices zero, one, two, three, and one, the expected alpha lookup is zero, 128, 255, 255, and 128. The input bytes represent only the tRNS payload in this exercise, not a whole chunk with length, type, and checksum fields. The function deliberately supports a nonempty supplied table or an absent table; it is not a complete chunk validator. The sixty-four-index limit is a local demonstration bound, rather than a limit on PNG image dimensions or palette usage.

def indexed_alpha(palette_count, trns, indices):
    if type(palette_count) is not int or not 1 <= palette_count <= 256:
        raise ValueError("Expected the declared indexed-palette entry count")
    if trns is not None and (type(trns) is not bytes or
                             not 1 <= len(trns) <= palette_count):
        raise ValueError("Teaching profile uses absent or nonempty tRNS payload bytes")
    if not isinstance(indices, (list, tuple)) or len(indices) > 64:
        raise ValueError("Expected at most 64 already decoded teaching indices")
    if any(type(i) is not int or not 0 <= i < palette_count for i in indices):
        raise ValueError("Pixel index is outside the declared palette")
    alpha = [255] * palette_count
    if trns is not None:
        alpha[:len(trns)] = trns
    return {"palette_alpha": alpha,
            "pixel_alpha": [alpha[i] for i in indices]}

# Constructed indexed-PNG inputs, not an image or survey result.
print(indexed_alpha(4, bytes([0, 128]), [0, 1, 2, 3, 1]))
print(indexed_alpha(4, None, [0, 3]))

Do not confuse an opaque default with an invalid index

A missing tail alpha value and an out-of-range palette index are different situations. In the four-entry example, indices two and three refer to existing palette entries whose alpha defaults to opaque. Index four does not identify an entry in that palette at all. The function rejects it instead of extending the palette or returning a convenient zero. Preserve the palette count and the selected pixel indices when investigating a real reader discrepancy so that these two cases cannot be collapsed into one missing-value category.

The supplied alpha bytes also remain distinct from pixel indices. An alpha value of 255 is valid even when the palette contains only four colors; it is an eight-bit opacity value, not a request for palette entry 255. Conversely, a pixel index of one refers to the second palette entry, whose alpha may be zero, intermediate, or fully opaque. Keeping these roles in separate variables prevents an easy diagnostic mistake: applying the palette-count range to alpha values or treating an opacity value as a color-table position.

Keep display alpha separate from data validity and compositing

The expanded table describes transparency for this representation. It does not establish whether the corresponding analytical raster samples are valid, whether a location lies outside an accepted survey boundary, or whether an area was hidden intentionally for presentation. Those questions require the actual source data and its validity or project definitions. A transparent palette entry can still have a stored color and an index. A screenshot that hides it against a background is not an interchangeable substitute for the original indexed image or its underlying analytical dataset.

This function also does not composite colors against a background, apply color management, or predict the appearance of a partially transparent pixel on a particular display. It only reports alpha values. Do not infer a precise displayed RGB color from the alpha table alone. If two applications show different previews, establish their decoded palette, alpha interpretation, chosen background, and rendering stage before concluding that their image content differs. Rewriting the source merely to make a diagnostic look familiar can erase the evidence needed to explain the discrepancy.

Test the absent-table branch independently: every existing palette entry should remain opaque. Then supply an explicit zero at the final palette entry and confirm that it becomes transparent, unlike an omitted tail entry. A table filled with 255 should remain fully opaque without changing the index sequence. These comparisons isolate the default rule and replacement behavior. They do not establish that a real PNG has correct chunk ordering, checksums, color metadata, image dimensions, decompression results, or accepted geospatial content.

Deliver a transparency finding with its exact scope

For an actual preview investigation, preserve the received file and record the selected image, PNG color type, palette length, presence and length of tRNS, relevant decoded indices, reader version, and the resulting alpha lookup. Include a small comparison showing both explicitly supplied alpha and the defaulted opaque tail. If the discrepancy is an incorrect zero-filled tail in a custom reader, describe that specific interpretation error. Keep any independently performed image validation and geospatial checks as separate results with their own methods and evidence.

In a NiVO-related map handoff, the useful outcome is a reproducible explanation of transparency rather than an invented assessment of survey completeness. Another reviewer can reconstruct why a shortened table still leaves particular palette entries fully opaque. Retain original samples and metadata, and verify any necessary derivative in the actual receiving workflow. The small example provides one clear rule for indexed PNG, while leaving raster validity, analytical meaning, complete image integrity, and project acceptance to the evidence appropriate to each question.

Technical references

  1. W3C PNG Third Edition: indexed tRNS values and opaque defaults ↗
  2. W3C PNG Third Edition: palette entry indexing and limits ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team