bool_t pdqDihedralHash256esFromFloatLuma()

in pdq/php/ext/pdq/impl/pdqhashing.c [143:248]


bool_t pdqDihedralHash256esFromFloatLuma(
  float* fullBuffer1, // numRows x numCols, row-major
  float* fullBuffer2, // numRows x numCols, row-major
  int numRows,
  int numCols,
  float buffer64x64[64][64],
  float buffer16x64[16][64],
  float buffer16x16[16][16],
  float buffer16x16Aux[16][16],
  Hash256* hashptrOriginal,
  Hash256* hashptrRotate90,
  Hash256* hashptrRotate180,
  Hash256* hashptrRotate270,
  Hash256* hashptrFlipX,
  Hash256* hashptrFlipY,
  Hash256* hashptrFlipPlus1,
  Hash256* hashptrFlipMinus1,
  int* pquality
) {
  if (numRows < MIN_HASHABLE_DIM || numCols < MIN_HASHABLE_DIM) {
    if (hashptrOriginal != NULL) {
      Hash256Clear(hashptrOriginal);
    }
    if (hashptrRotate90 != NULL) {
      Hash256Clear(hashptrRotate90);
    }
    if (hashptrRotate180 != NULL) {
      Hash256Clear(hashptrRotate180);
    }
    if (hashptrRotate270 != NULL) {
      Hash256Clear(hashptrRotate270);
    }
    if (hashptrFlipX != NULL) {
      Hash256Clear(hashptrFlipX);
    }
    if (hashptrFlipY != NULL) {
      Hash256Clear(hashptrFlipY);
    }
    if (hashptrFlipPlus1 != NULL) {
      Hash256Clear(hashptrFlipPlus1);
    }
    if (hashptrFlipMinus1 != NULL) {
      Hash256Clear(hashptrFlipMinus1);
    }
    *pquality = 0;
    return true;
  }

  // Downsample (blur and decimate)
  int windowSizeAlongRows = computeJaroszFilterWindowSize(numCols);
  int windowSizeAlongCols = computeJaroszFilterWindowSize(numRows);

  jaroszFilterFloat(
    fullBuffer1,
    fullBuffer2,
    numRows,
    numCols,
    windowSizeAlongRows,
    windowSizeAlongCols,
    PDQ_NUM_JAROSZ_XY_PASSES
  );

  decimateFloat(fullBuffer1, numRows, numCols, buffer64x64);

  // Quality metric.  Reuse the 64x64 image-domain downsample
  // since we already have it.
  *pquality = pdqImageDomainQualityMetric(buffer64x64);

  // 2D DCT
  dct64To16(buffer64x64, buffer16x64, buffer16x16);

  //  Output bits
  if (hashptrOriginal != NULL) {
    pdqBuffer16x16ToBits(buffer16x16, hashptrOriginal);
  }
  if (hashptrRotate90 != NULL) {
    dct16OriginalToRotate90(buffer16x16, buffer16x16Aux);
    pdqBuffer16x16ToBits(buffer16x16Aux, hashptrRotate90);
  }
  if (hashptrRotate180 != NULL) {
    dct16OriginalToRotate180(buffer16x16, buffer16x16Aux);
    pdqBuffer16x16ToBits(buffer16x16Aux, hashptrRotate180);
  }
  if (hashptrRotate270 != NULL) {
    dct16OriginalToRotate270(buffer16x16, buffer16x16Aux);
    pdqBuffer16x16ToBits(buffer16x16Aux, hashptrRotate270);
  }
  if (hashptrFlipX != NULL) {
    dct16OriginalToFlipX(buffer16x16, buffer16x16Aux);
    pdqBuffer16x16ToBits(buffer16x16Aux, hashptrFlipX);
  }
  if (hashptrFlipY != NULL) {
    dct16OriginalToFlipY(buffer16x16, buffer16x16Aux);
    pdqBuffer16x16ToBits(buffer16x16Aux, hashptrFlipY);
  }
  if (hashptrFlipPlus1 != NULL) {
    dct16OriginalToFlipPlus1(buffer16x16, buffer16x16Aux);
    pdqBuffer16x16ToBits(buffer16x16Aux, hashptrFlipPlus1);
  }
  if (hashptrFlipMinus1 != NULL) {
    dct16OriginalToFlipMinus1(buffer16x16, buffer16x16Aux);
    pdqBuffer16x16ToBits(buffer16x16Aux, hashptrFlipMinus1);
  }

  return true;
}