Skip to main content

The *257 Packing Trick Behind Fake 16-bit Depth Map PNGs

PNG bit depth describes the container. Unique gray values, and a 257-step fingerprint, tell you what LightBurn, CNC, or a 3D printer will actually slice.

Updated 7 min readMarkdown
The *257 Packing Trick Behind Fake 16-bit Depth Map PNGs

A grayscale PNG stores one integer per pixel. The IHDR chunk records how wide that integer is: 8 bits for the range 0 to 255, or 16 bits for the range 0 to 65,535. A depth map, height map, or displacement map is just that integer read as height. CAM software, a laser controller, and a 3D-printing displacement modifier do not see a picture. They see a grid of numbers.

The bit-depth field is therefore a statement about the container, not about the data. It tells a decoder how many bits to read per sample. It does not promise that those samples use the extra bits.

That distinction is easy to miss. On a monitor, and in most preview widgets, 16-bit gray and 8-bit gray often look the same. The difference shows up later, when those integers become Z values or pass masks.

How 8-bit samples are written into a 16-bit PNG

A common conversion, used by exporters, "convert to 16-bit" buttons, and some resize or color-depth tools, takes each 8-bit value v and writes it as v * 257.

257 is not an arbitrary constant. It is the clean way to map 0..255 onto the full 16-bit range 0..65,535:

  • 0 * 257 = 0
  • 255 * 257 = 65,535

A left shift alone does not do this. v << 8 is v * 256, so 255 becomes 65,280 and never reaches 65,535. Multiplying by 257 is the same as copying the byte into both halves of the 16-bit word:

v * 257 = (v << 8) | v
# 0x7F becomes 0x7F7F
# 0xFF becomes 0xFFFF

The PNG header is then truthful about the container: bit depth 16, often color type 0 (grayscale). The payload is still an 8-bit field. There are at most 256 distinct integers in the file, and every one of them is a multiple of 257: 0, 257, 514, ..., 65,535.

That pattern is a useful fingerprint. A genuine 16-bit height field from a smooth surface almost never lands only on multiples of 257.

A JPEG round-trip, a screenshot, or an editor session that silently worked in 8 bits can also leave you with 256 or fewer levels, without this exact packing. Saving the result as a 16-bit PNG does not invent the missing values. I focus on the *257 case because it is the one that still looks correct in the header and in a histogram stretched to 0..65,535.

What I measured on my own test files

I generated three small synthetic depth maps (a dome, a linear ramp, and a coin-like medallion), then saved a true 16-bit PNG and a *257 packed version of each. These are my own test files, not a published study. The numbers below are unique-level counts, not engraving results.

Scene True 16-bit unique levels Packed / fake 16-bit unique levels
Dome 12,240 256 or fewer
Ramp 50,604 256 or fewer
Medallion 10,686 256 or fewer

None of the true files use all 65,536 possible values, and they should not be expected to. A real object uses as many levels as the surface and the pixel grid provide. Thousands of levels is the normal signature. A 16-bit header with 256 or fewer levels is the warning.

Read the count on the full-size export. A 64 x 64 crop has at most 4,096 distinct pixels, so a low count there proves little. A nearly flat plate with one small boss also has few levels for an honest reason. Use the count together with the *257 fingerprint, and judge it against the scene you actually exported.

Inspect the file, not the preview

ImageMagick 7 will print the header bit depth and the unique-color count in one line. For a single-channel gray PNG, unique colors are unique gray levels:

magick identify -format "%z-bit | %k unique levels | %f\n" your-depth-map.png

If you already have Python, numpy, and Pillow, this one-liner prints the array dtype, the unique-level count, and whether every value is a multiple of 257:

python3 -c "import numpy as np; from PIL import Image; a=np.array(Image.open('x.png')); print(a.dtype, np.unique(a).size, (a%257==0).all())"

On a true 16-bit file you should see a uint16 dtype, a count in the thousands, and False for the 257 test. On a packed file you should see uint16, a count of 256 or fewer, and True.

If you would rather not install a toolchain, the 16-bit depth map checker runs the same comparison in the browser. It is a free tool from Depth-Map.com, the site I make. The product page says it decodes the PNG in the browser and does not upload the file. I still keep ImageMagick or the Python line around for batch checks.

Do not try to do this by drawing the PNG onto an HTML canvas and calling getImageData. A canvas hands you 8-bit RGBA, so a 16-bit file is flattened before you count anything.

Why the level count shows up in Z and in pass counts

Once a tool treats gray as height, step size is just relief depth divided by the number of distinct levels. On a 3 mm relief, 256 levels give:

3 / 256 ≈ 0.0117 mm, or 11.7 µm per terrace.

For the true dome in the table above, the same 3 mm range over 12,240 levels is 3 / 12,240 ≈ 0.000245 mm, or about 0.245 µm per step. That is a file-side figure, not a machine tolerance. At 11.7 µm the file can be the bottleneck, especially on polished metal where a terrace edge catches raking light. At 0.245 µm the file has dropped below typical machine resolution, so something else will limit the surface first.

This is also why raising the pass count does not fix a packed file.

LightBurn 2.1 added 16-bit depth-map support (see the LightBurn documentation). 3D Sliced mode is for galvo lasers. I am not describing LightBurn's internals. What follows from the file, and what the community has pointed out, is that 3D Slice thresholds the image for each pass. If the source is 8-bit, or a 16-bit PNG that still holds only 256 levels, more than 256 passes does not add precision. You can spend more time, and you may go deeper, but you cannot slice values that are not in the file.

The same logic applies to a CNC Z step or a displacement modifier: the tool can only land on heights that exist in the grid.

Checklist before you send the file

  1. Confirm the PNG header reports 16-bit grayscale. That is necessary, and it is not sufficient.
  2. Count unique gray levels on the full-size file, not on a resized preview.
  3. If every value is a multiple of 257, treat the file as packed 8-bit data, whatever the header says.
  4. Divide your planned relief depth by the unique-level count. If the step is larger than you will accept on the finished surface, stop here.
  5. If you slice by threshold (laser passes, or any similar layering), do not expect passes beyond the real level count to add detail.
  6. If the file is packed, go back to the source tool and re-export in 16 bits. Converting the current PNG to 16-bit will not restore the missing levels.

No comments yet. Be the first to comment.