DDitherMorrow
Workflows

Coding workflows · Ordered grayscale dithering

03
Built around your work

A concrete starting point

Apply a repeating two-by-two threshold tile to integer grayscale pixels in matrices up to 64 by 64. Check black, white and threshold equality, rejecting ragged shapes and non-byte or Boolean pixels without changing the input.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Ordered grayscale dithering

A concrete starting point
def ordered_dither(pixels):
    pixels = [tuple(row) for row in pixels]
    width = len(pixels[0]) if pixels else 0
    if len(pixels) > 64 or width > 64 or any(len(row) != width for row in pixels):
        raise ValueError("image.shape")
    if any(type(v) is not int or not 0 <= v <= 255 for row in pixels for v in row):
        raise ValueError("pixel.byte")
    thresholds = ((32, 160), (224, 96))
    return [[value >= thresholds[r % 2][c % 2] for c, value in enumerate(row)]
            for r, row in enumerate(pixels)]

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗