Skip to content

1-bpp BMP export/preview causes pixel shifting/corruption on non-32-bit aligned widths (e.g., 10px) #778

@nxyd

Description

@nxyd

Describe the bug

When exporting or previewing an image as a 1-bpp Monochromatic BMP with a custom width that is not a multiple of 32 bits (such as 10px × 16px), the pixel layout becomes corrupted and shifted in the preview window (and potentially in the exported file).

It appears that the DIB scanline padding bytes (4-byte alignment requirement for BMP) are being incorrectly parsed or treated as active pixels during the stride/offset calculation for the next row.

Steps to reproduce the behavior

  1. Create a new image with a size of 10 x 16 pixels.
  2. Use the Pencil tool (with antialiasing turned off) to draw a clean diagonal line.
  3. Go to File -> Save As -> Choose BMP.
  4. In the BMP options dialog, select:
    • Color model: Grayscale
    • Depth: 1-bpp
  5. Look at the after preview window. The smooth diagonal line becomes jagged, disconnected, and shifted horizontally near the bottom.

Expected behavior

The 1-bpp preview/export should perfectly retain the original pixel connectivity and positioning without any horizontal shifting, regardless of whether the canvas width matches the 4-byte (32-bit) stride alignment.

Environment

  • PhotoDemon Version: 2025.12 (as seen in the title bar)
  • OS: Windows 11 / Windows 10
Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions