Documentation
¶
Index ¶
Constants ¶
const ( LumaFromRCoeff = 0.299 LumaFromGCoeff = 0.587 LumaFromBCoeff = 0.114 PdqNumJaroszXYPasses = 2 DownsampleDims = 512 MinHashableDim = 5 )
Various constants pulled from the reference implementation
Variables ¶
var ( ErrInvalidFile = errors.New("invalid input file name") // ErrImageTooLarge is returned when an input image exceeds MaxImagePixels. ErrImageTooLarge = errors.New("image exceeds maximum allowed pixel count") )
var MaxImagePixels = 100_000_000
MaxImagePixels bounds the total number of pixels (width * height) that will be hashed. It is a backstop against memory-exhaustion / decode-bomb DoS when hashing untrusted input: HashFromImage allocates two float32 buffers of width*height each (8 bytes/pixel total) on top of the decoded bitmap, all of which scale with the source dimensions. PDQ input should be resized to 512x512 or smaller before hashing (see helpers.ResizeIfNeeded), so the default of 100 megapixels is a generous safety ceiling, not a normal operating point. Set to 0 to disable the check.
Functions ¶
This section is empty.
Types ¶
type HashResult ¶
type HashResult struct {
Hash string
Quality int
ImageHeightTimesWidth int
HashDuration time.Duration
}
HashResult contains the output of a PDQ hash operation
func HashFromFile ¶
func HashFromFile(filename string) (*HashResult, error)
Opens a file at the specified file and uses image.Image to decode the image. Returns the result of HashFromImage. This is a convenience wrapper around HashFromImage that handles the IO and decoding for you. Ideally, you should call HashFromImage on your own with a 512x512 or smaller image that you have resized yourself. This function is provided only to match the reference implementation.
func HashFromImage ¶
func HashFromImage(img image.Image) (*HashResult, error)
HashFromImage generates a PDQ hash from an image.Image The image should idealy be pre-resizes to 512x512 or smaller for performance reasons. SEE: https://github.com/facebook/ThreatExchange/blob/main/hashing/hashing.pdf, "More on Downsampling" Returns a HashResult containing the hash and a quality score between 0 and 100. Please reference the evaluation data for selecting a good quality score. From hashing.pdf: "Confident-match distances are up to the system designer, of course, but 30, 20, or less has been found to produce good results on evaluation data."