rc

package module
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2024 License: GPL-3.0 Imports: 22 Imported by: 1

README

Ring Captcha

Ring Captcha is a library for creating and checking ring captcha.

Ring Captcha is a graphical type of captcha. A user must see an image and count rings drawn on the image. After the first guess attempt the captcha is destroyed to avoid getting an answer by brute force.

The library includes a manager which is able to serve created images via the HTTP protocol.

Documentation

Index

Constants

View Source
const (
	CaptchaImageMinWidth    = 128
	CaptchaImageMinHeight   = 128
	RingMinCount            = 3
	RingMaxCount            = 6
	RingMinRadius           = 24
	BrushOuterRadiusMin     = 2
	BrushOuterRadiusMax     = 32
	ColourComponentMaxValue = 65535
	KR                      = 0.5
	KDMin                   = 1.0
	KDMax                   = 1.5
)
View Source
const (
	ErrDimensions         = "dimensions error"
	ErrBrushRadiusRatio   = "brush radius ratio error"
	ErrDensityCoefficient = "density coefficient error"
	ErrAnomaly            = "anomaly"
)
View Source
const (
	ErrCanvasIsTooSmall              = "canvas is too small"
	ErrImagesHaveDifferentDimensions = "images have different dimensions"
)
View Source
const (
	// C1 is a maximum colour channel value of a pixel in an 'image.RGBA' of
	// the built-in library.
	C1 = float64(65_535)
)
View Source
const ErrFFileExtensionMismatch = "file extension mismatch: png vs %s"
View Source
const FileExtPng = `.png`

Variables

View Source
var (
	ColourWhite   = BrushColour{R: 1.0, G: 1.0, B: 1.0, A: 1.0}
	ColourRed     = BrushColour{R: 1.0, G: 0.0, B: 0.0, A: 1.0}
	ColourGreen   = BrushColour{R: 0.0, G: 1.0, B: 0.0, A: 1.0}
	ColourBlue    = BrushColour{R: 0.0, G: 0.0, B: 1.0, A: 1.0}
	ColourCyan    = BrushColour{R: 0.0, G: 1.0, B: 1.0, A: 1.0}
	ColourMagenta = BrushColour{R: 1.0, G: 0.0, B: 1.0, A: 1.0}
	ColourYellow  = BrushColour{R: 1.0, G: 1.0, B: 0.0, A: 1.0}
	ColourBlack   = BrushColour{R: 0.0, G: 0.0, B: 0.0, A: 1.0}
)

Functions

func BlendAlphaOverlay

func BlendAlphaOverlay(cB, cA float64) (cO float64)

BlendAlphaOverlay blends A and B alpha channels into O channel. B is the base layer, i.e. the bottom layer. A is the applied layer, i.e. the top layer.

func BlendChannelOverlay

func BlendChannelOverlay(cB, cA, aB, aA float64) (cO float64)

BlendChannelOverlay blends A and B channels into O channel. B is the base layer, i.e. the bottom layer. A is the applied layer, i.e. the top layer.

func BlendColourOverlay

func BlendColourOverlay(cB, cA color.Color) (cO color.Color)

BlendColourOverlay blends A and B pixels into O pixel. B is the base layer, i.e. the bottom layer. A is the applied layer, i.e. the top layer.

func BlendImages

func BlendImages(iB *image.NRGBA, iA *image.NRGBA) (iO *image.NRGBA, err error)

BlendImages blends A and B images into O image. B is the base layer, i.e. the bottom layer. A is the applied layer, i.e. the top layer.

func ConvertImageToNRGBA

func ConvertImageToNRGBA(in image.Image) (out *image.NRGBA)

func ConvertImageToRGBA

func ConvertImageToRGBA(in image.Image) (out *image.RGBA)

func CreateCaptchaImage

func CreateCaptchaImage(w, h uint, useSample bool, blend bool) (canvas *image.NRGBA, ringCount uint, err error)

func DegreeToRadian

func DegreeToRadian(degree float64) (radian float64)

func DrawImageToCanvas

func DrawImageToCanvas(in *image.RGBA, canvas image.Rectangle) (out *image.NRGBA)

DrawImageToCanvas draws an image on another canvas.

func DrawLineWithSimpleBrush

func DrawLineWithSimpleBrush(canvas *image.NRGBA, br *SimpleBrush, p1, p2 Point2D, blend bool)

DrawLineWithSimpleBrush draws a straight line using a simple brush.

func DrawRingWithSimpleBrush

func DrawRingWithSimpleBrush(canvas *image.NRGBA, br *SimpleBrush, center Point2D, radius float64, daDegree float64, useSample bool, blend bool)

func FillCanvasWithColour

func FillCanvasWithColour(canvas *image.NRGBA, col color.Color)

FillCanvasWithColour fills the canvas with colour.

func FillCanvasWithHGradient

func FillCanvasWithHGradient(canvas *image.NRGBA, cL, cR BrushColour) (err error)

FillCanvasWithHGradient fills the canvas with a horizontal gradient. cL specifies the left side colour and cR is the right side colour.

func FillCanvasWithVGradient

func FillCanvasWithVGradient(canvas *image.NRGBA, cT, cB BrushColour) (err error)

FillCanvasWithVGradient fills the canvas with a vertical gradient. cT specifies the top side colour and cB is the bottom side colour.

func GetColorComponentsPM

func GetColorComponentsPM(c color.Color) (r, g, b, a float64)

GetColorComponentsPM extracts colour's components as usable floating point numbers. The returned values are pre-multiplied with alpha channel.

func GetColorComponentsS

func GetColorComponentsS(c color.Color) (r, g, b, a float64)

GetColorComponentsS extracts colour's components as usable floating point numbers. The returned values use straight alpha channel.

func GetImageFromFilePath

func GetImageFromFilePath(filePath string) (img image.Image, err error)

func MakeRGBA64

func MakeRGBA64(r, g, b, a float64) color.RGBA64

MakeRGBA64 creates an RGBA64 colour with the provided channels.

func MinInt

func MinInt(a, b int) (min int)

func MinUint

func MinUint(a, b uint) (min uint)

func RadianToDegree

func RadianToDegree(radian float64) (degree float64)

func SaveImageAsPngFile

func SaveImageAsPngFile(img image.Image, filePath string) (err error)

func UseSimpleBrush

func UseSimpleBrush(canvas *image.NRGBA, brush *SimpleBrush, blend bool, u Point2D)

UseSimpleBrush creates a point using a simple brush.

func UseSimpleBrushS

func UseSimpleBrushS(canvas *image.NRGBA, brush *SimpleBrush, blend bool, u Point2D)

UseSimpleBrushS creates a point using a simple brush with a sample.

func UseSolidBrush

func UseSolidBrush(canvas *image.NRGBA, brush *SolidBrush, u Point2D)

UseSolidBrush creates a point using a solid brush.

Types

type BrushColour

type BrushColour struct {
	R float64
	G float64
	B float64
	A float64
}

func (BrushColour) PremultipliedToStraight

func (bc BrushColour) PremultipliedToStraight() (out BrushColour)

func (BrushColour) RGBA

func (bc BrushColour) RGBA() (r, g, b, a uint32)

RGBA method of the color.Color interface.

func (BrushColour) StraightToPremultiplied

func (bc BrushColour) StraightToPremultiplied() (out BrushColour)

type Distance

type Distance = float64

func Distance2D

func Distance2D(a, b Point2D) (s Distance)

type Point2D

type Point2D struct {
	X float64
	Y float64
}

type SimpleBrush

type SimpleBrush struct {
	InnerRadius float64
	OuterRadius float64
	Colour      BrushColour
	// contains filtered or unexported fields
}

SimpleBrush is a basic round brush with soft edges.

func (*SimpleBrush) GetSample

func (sb *SimpleBrush) GetSample() (sample *image.NRGBA)

type SolidBrush

type SolidBrush struct {
	InnerRadius float64
	Colour      BrushColour
}

SolidBrush is a basic round brush without any soft edges.

Directories

Path Synopsis
test
1
2
3

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL