Пример #1
0
/* {{{ proto bool ImagickPixel::isSimilar(float fuzz)
	Returns true if the distance between two colors is less than the specified distance.
*/
PHP_METHOD(imagickpixel, issimilar)
{
	zval *param;
	double fuzz;
	php_imagickpixel_object *internp;
	MagickBooleanType status;
	PixelWand *color_wand;
	zend_bool allocated;

	/* Parse parameters given to function */
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zd", &param, &fuzz) == FAILURE) {
		return;
	}

	internp = (php_imagickpixel_object *)zend_object_store_get_object(getThis() TSRMLS_CC);

	color_wand = php_imagick_zval_to_pixelwand (param, IMAGICKPIXEL_CLASS, &allocated TSRMLS_CC);
	if (!color_wand)
		return;

	status = IsPixelWandSimilar(internp->pixel_wand, color_wand, fuzz);
	if (allocated)
		color_wand = DestroyPixelWand (color_wand);

	if (status == MagickFalse) {
		RETURN_FALSE;
	}

	RETURN_TRUE;
}
Пример #2
0
/* {{{ proto bool ImagickPixel::isSimilar(float fuzz)
	Returns true if the distance between two colors is less than the specified distance.
*/
static
void s_is_pixelwand_similar(INTERNAL_FUNCTION_PARAMETERS, zend_bool use_quantum)
{
    zval *param;
    double fuzz;
    php_imagickpixel_object *internp;
    MagickBooleanType status;
    PixelWand *color_wand;
    zend_bool allocated;

    /* Parse parameters given to function */
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zd", &param, &fuzz) == FAILURE) {
        return;
    }

    internp = Z_IMAGICKPIXEL_P(getThis());

    color_wand = php_imagick_zval_to_pixelwand (param, IMAGICKPIXEL_CLASS, &allocated TSRMLS_CC);
    if (!color_wand)
        return;

    status = IsPixelWandSimilar(internp->pixel_wand, color_wand, (use_quantum ? (QuantumRange * fuzz) : fuzz));
    if (allocated)
        color_wand = DestroyPixelWand (color_wand);

    if (status == MagickFalse) {
        RETURN_FALSE;
    }

    RETURN_TRUE;
}
Пример #3
0
static bool isSimilar(ObjectData* this_, const Variant& color,
                      double fuzz, bool useQuantum) {
  auto wand = getPixelWandResource(this_);
  auto pixel = buildColorWand(color);
  if (useQuantum) {
    fuzz *= QuantumRange;
  }
  return IsPixelWandSimilar(wand->getWand(), pixel->getWand(), fuzz)
    != MagickFalse;
}