aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/login
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 11:35:08 +0530
committerArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 11:35:08 +0530
commit600c337b1cdc884aebf59083eb57b178b43441ce (patch)
treed1f3cb7eb1020bcdcd66d9dbf0279f79d5856332 /src/scripts/login
parent98e7019c61ea0ffe344ef7ce809d38d62254a9fc (diff)
downloadbanglar-bhumi-utils-600c337b1cdc884aebf59083eb57b178b43441ce.tar.gz
banglar-bhumi-utils-600c337b1cdc884aebf59083eb57b178b43441ce.zip
docs: added some documentation comments to all functions
Diffstat (limited to 'src/scripts/login')
-rw-r--r--src/scripts/login/index.ts15
1 files changed, 15 insertions, 0 deletions
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++) {