Skip to content

CaptchaGenerator — replace CxImage with ATL CImage / native GDI

Summary

CaptchaGenerator.cpp uses CxImage as its rendering library. CxImage is a legacy third-party library also used elsewhere in the codebase. Community-0.72 (irwir) removed this CxImage dependency from CaptchaGenerator and replaced it with ATL CImage / native GDI in commit 24d1de7. This is a targeted dependency reduction that:

  1. Removes the CxImage/xImage.h include from the captcha generator
  2. Replaces CxImage bitmap operations with BITMAPINFO/CreateDIBSection + GDI
  3. Uses <atlimage.h> (part of ATL, always available on Windows) for PNG export
  4. Eliminates the libpng transitive dependency for captcha output

Note: CxImage may still be used in other parts of the codebase (e.g., image preview dialogs). This refactor scopes to CaptchaGenerator only.

Reference Implementation

Source: community-0.72, commit 24d1de7 (January 2026)

Community's rewrite also changes the captcha rendering approach: - Old: 1bpp palette-indexed CxImage bitmap - New: 1bpp BITMAPINFO with RGBQUAD palette + CreateDIBSection + native GDI

Community's approach includes fixing several rendering parameters: - CROWDEDSIZE increased from 18 → 23 (wider letter spacing) - Captcha character set renamed from schCaptchaContentsCaptchaCharSet - Cleaner character rendering loop using SelectObject/DrawText

Relationship to BUG-008

BUG-008 (CaptchaGenerator rand() & 8 bimodal jitter) documents a separate bug in the jitter generation: nJitter = rand() & 8 produces only 0 or 8, never 1-7. Community's full rewrite incidentally eliminates this jitter code (their rendering approach doesn't use the same jitter pattern). Our targeted fix for BUG-008 should use rand() % 9 or a similar uniform distribution; the REF-027 rewrite would eliminate it entirely.

If REF-027 lands, close BUG-008 as resolved by refactor.

Acceptance Criteria

  • [ ] CaptchaGenerator.cpp no longer includes CxImage/xImage.h
  • [ ] Captcha bitmap generated using BITMAPINFO + CreateDIBSection or ATL::CImage
  • [ ] Generated captcha still passes CUpDownClient::ProcessCaptchaRequest size checks (height 11-49, width 11-149)
  • [ ] No regression in captcha readability
  • [ ] If CxImage has no other consumers after this change, remove it entirely (coordinate with a broader CxImage audit)