MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / calcDct2Hash

Method calcDct2Hash

testutil/image_hash.go:179–209  ·  view source on GitHub ↗

calcDct2Hash calculates the DCT hash for the given image data buffer

(buf []byte)

Source from the content-addressed store, hash-verified

177
178// calcDct2Hash calculates the DCT hash for the given image data buffer
179func (h *ImageHash) calcDct2Hash(buf []byte) error {
180 bufPtr := unsafe.Pointer(unsafe.SliceData(buf))
181
182 var dctArray *C.float
183 var length C.size_t
184
185 defer func() {
186 if dctArray != nil {
187 C.free(unsafe.Pointer(dctArray))
188 }
189 }()
190
191 //nolint:gocritic
192 result := C.vips_dct2_hash(bufPtr, C.size_t(len(buf)), &dctArray, &length)
193
194 if result != 0 {
195 return fmt.Errorf("failed to calculate DCT hash: %s", vipsErrorMessage())
196 }
197
198 dctHash := make([]float32, int(length))
199
200 // Convert C array to Go slice safely
201 cSlice := unsafe.Slice(dctArray, int(length))
202 for i, v := range cSlice {
203 dctHash[i] = float32(v)
204 }
205
206 h.dctHash = dctHash
207
208 return nil
209}
210
211// dumpDctHash writes the DCT hash to a writer
212func (h *ImageHash) dumpDctHash(w io.Writer) error {

Callers 1

NewImageHashFromBytesFunction · 0.95

Calls 3

vipsErrorMessageFunction · 0.85
freeMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected