From 600c337b1cdc884aebf59083eb57b178b43441ce Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Mon, 13 Jul 2026 11:35:08 +0530 Subject: docs: added some documentation comments to all functions --- src/scripts/login/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/scripts/login') diff --git a/src/scripts/login/index.ts b/src/scripts/login/index.ts index bed05f9..dcf43e3 100644 --- a/src/scripts/login/index.ts +++ b/src/scripts/login/index.ts @@ -1,18 +1,33 @@ import { interceptPost, interceptGet } from "@/shared/intercept-jquery-ajax"; +/** + * Pre-processes a CAPTCHA image on a canvas by removing grayish + * background noise while preserving dark pixels, producing a clean + * binary image suitable for OCR. + * + * @param ctx - The 2D rendering context of the canvas. + * @param width - Canvas width in pixels. + * @param height - Canvas height in pixels. + */ function prepareCaptcha(ctx: CanvasRenderingContext2D, width: number, height: number) { const imgData = ctx.getImageData(0, 0, width, height); const data = imgData.data; const radius = 1; + /** Returns true when all three channels are below 50 (very dark). */ function isBlack(r: number, g: number, b: number) { return r < 50 && g < 50 && b < 50; } + /** Returns true when the colour is a mid-range grey (no strong hue). */ function isGrayish(r: number, g: number, b: number) { return Math.abs(r - g) < 15 && Math.abs(g - b) < 15 && r > 100 && r < 200; } + /** + * Checks whether a black pixel exists within `radius` pixels of (x, y). + * Used to preserve dark structures when removing grey noise. + */ function hasNearbyBlack(x: number, y: number) { for (let dx = -radius; dx <= radius; dx++) { for (let dy = -radius; dy <= radius; dy++) { -- cgit v1.2.3