コード例 #1
0
ファイル: PixelWand.c プロジェクト: ConstNW/haxe-imagemagick
/*
@description	Returns the normalized alpha color of the pixel wand.
*/
value nMagick_pixel_get_alpha( value pixel )
{
	PixelWand *pix;

	val_check_kind( pixel, k_pixel );

	pix = PIXEL( pixel );

	return alloc_float( PixelGetAlpha( pix ) );
}
コード例 #2
0
ファイル: imagickpixel_class.c プロジェクト: ptarjan/imagick
/* {{{ proto array ImagickPixel::getColor([bool normalized])
	Returns the color of the pixel in an array
*/
PHP_METHOD(imagickpixel, getcolor)
{
	php_imagickpixel_object *internp;
	zend_bool normalized = 0;
	double red, green, blue, alpha;

	/* Parse parameters given to function */
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &normalized) == FAILURE) {
		return;
	}

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

	if (normalized == 1) {

		red   = PixelGetRed(internp->pixel_wand);
		green = PixelGetGreen(internp->pixel_wand);
		blue  = PixelGetBlue(internp->pixel_wand);
		alpha = PixelGetAlpha(internp->pixel_wand);

		add_assoc_double(return_value, "r", red);
		add_assoc_double(return_value, "g", green);
		add_assoc_double(return_value, "b", blue);
		add_assoc_double(return_value, "a", alpha);
	
	} else {

		/* TODO: should this be quantum range instead of hardcoded 255.. */
		red   = PixelGetRed(internp->pixel_wand ) * 255;
		green = PixelGetGreen(internp->pixel_wand ) * 255;
		blue  = PixelGetBlue(internp->pixel_wand ) * 255;
		alpha = PixelGetAlpha(internp->pixel_wand);

		add_assoc_long(return_value, "r", (int)(red > 0.0 ? red + 0.5 : red - 0.5));
		add_assoc_long(return_value, "g", (int)(green > 0.0 ? green + 0.5 : green - 0.5));
		add_assoc_long(return_value, "b", (int)(blue > 0.0 ? blue + 0.5 : blue - 0.5));
		add_assoc_long(return_value, "a", alpha);
	}

	return;
}
コード例 #3
0
ファイル: imgmin.c プロジェクト: dpq/imgmin
/**
 * Converts a single row from MagickWand iterator into luma channel needed by DSSIM
 */
void convert_row_callback(const dssim_info *const inf, float *const channels[], const int num_channels, const int y, const int orig_width, void *user_data) {
    size_t x, width = orig_width;
    PixelWand **pmw = PixelGetNextIteratorRow((PixelIterator*)user_data, &width);

    for(x = 0; x < width; x++) {
        // Ideally it should be reading luma directly from JPEG
        // Only one channel (luma) is written for speed/simplicity sake.
        channels[0][x] = (
            .2126 * PixelGetRed(pmw[x]) + // I'm assuming IM gives perceptually uniform values
            .7152 * PixelGetGreen(pmw[x]) +
            .0722 * PixelGetBlue(pmw[x])
        ) * PixelGetAlpha(pmw[x]);
    }
}
コード例 #4
0
/* {{{ proto array ImagickPixel::getColor([int normalization])
	Returns the color of the pixel in an array
	normalization - 0 - values returned in the range 0,255 and will be ints, except
		for legacy reasons alpha which is 0-1
	normalization - 1 - values returned in the range 0,1 and will be floats
	normalization - 2 - values returned in the range 0,255 and will be ints including alpha
	values i.e. float if ImageMagick was compiled with HDRI, or integers normally.
*/
PHP_METHOD(imagickpixel, getcolor)
{
    php_imagickpixel_object *internp;
    im_long normalization = 0;
    double red, green, blue, alpha;

    /* Parse parameters given to function */
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &normalization) == FAILURE) {
        return;
    }

    internp = Z_IMAGICKPIXEL_P(getThis());
    array_init(return_value);

    red   = PixelGetRed(internp->pixel_wand);
    green = PixelGetGreen(internp->pixel_wand);
    blue  = PixelGetBlue(internp->pixel_wand);
    alpha = PixelGetAlpha(internp->pixel_wand);

    switch (normalization) {
    //values returned in the range 0,255 and will be ints
    case(0): {
        //Leave like this for legacy code
        //TODO fix the alpha not being normalised at next major/minor verysion
        red   *= 255;
        green *= 255;
        blue  *= 255;

        //values are always >=0, so the rounding below may not be necessary
        add_assoc_long(return_value, "r", (long) (red   > 0.0 ? red   + 0.5 : red   - 0.5));
        add_assoc_long(return_value, "g", (long) (green > 0.0 ? green + 0.5 : green - 0.5));
        add_assoc_long(return_value, "b", (long) (blue  > 0.0 ? blue  + 0.5 : blue  - 0.5));
        add_assoc_long(return_value, "a", alpha);
        break;
    }

    //values returned in the range 0,1 and will be floats
    case(1): {
        add_assoc_double(return_value, "r", red);
        add_assoc_double(return_value, "g", green);
        add_assoc_double(return_value, "b", blue);
        add_assoc_double(return_value, "a", alpha);
        break;
    }

    case(2): {
        red   *= 255;
        green *= 255;
        blue  *= 255;
        alpha *= 255;

        //values are always >=0, so the rounding below may not be necessary
        add_assoc_long(return_value, "r", (long) (red   > 0.0 ? red   + 0.5 : red   - 0.5));
        add_assoc_long(return_value, "g", (long) (green > 0.0 ? green + 0.5 : green - 0.5));
        add_assoc_long(return_value, "b", (long) (blue  > 0.0 ? blue  + 0.5 : blue  - 0.5));
        add_assoc_long(return_value, "a", (long) (alpha  > 0.0 ? alpha  + 0.5 : alpha  - 0.5));
        break;
    }
    }

    return;
}
コード例 #5
0
/* {{{ proto float ImagickPixel::getColorValue(int color)
	Gets the normalized value of a color in the ImagickPixel.
*/
PHP_METHOD(imagickpixel, getcolorvalue)
{
    php_imagick_color_t color_enum;
    php_imagickpixel_object *internp;
    im_long color;
    double color_value = 0;

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

    internp = Z_IMAGICKPIXEL_P(getThis());

    if (color <= PHP_IMAGICK_COLOR_MIN || color >= PHP_IMAGICK_COLOR_MAX) {
        php_imagick_throw_exception (IMAGICKPIXEL_CLASS, "Unknown color type" TSRMLS_CC);
        return;
    }

    color_enum = color;

    switch (color_enum) {

    case PHP_IMAGICK_COLOR_BLACK:
        color_value = PixelGetBlack(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_BLUE:
        color_value = PixelGetBlue(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_CYAN:
        color_value = PixelGetCyan(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_GREEN:
        color_value = PixelGetGreen(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_RED:
        color_value = PixelGetRed(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_YELLOW:
        color_value = PixelGetYellow(internp->pixel_wand);
        break;

    case PHP_IMAGICK_COLOR_MAGENTA:
        color_value = PixelGetMagenta(internp->pixel_wand);
        break;

#if MagickLibVersion < 0x700
    case PHP_IMAGICK_COLOR_OPACITY:
        color_value = PixelGetOpacity(internp->pixel_wand);
        break;
#endif

    case PHP_IMAGICK_COLOR_ALPHA:
        color_value = PixelGetAlpha(internp->pixel_wand);
        break;

#if MagickLibVersion > 0x628
    case PHP_IMAGICK_COLOR_FUZZ:
        color_value = PixelGetFuzz(internp->pixel_wand);
        break;
#endif

    default:
        php_imagick_throw_exception (IMAGICKPIXEL_CLASS, "Unknown color type" TSRMLS_CC);
        return;
        break;
    }
    RETVAL_DOUBLE(color_value);
}
コード例 #6
0
ファイル: imagickpixel_class.c プロジェクト: ptarjan/imagick
/* {{{ proto float ImagickPixel::getColorValue(int color)
	Gets the normalized color of the ImagickPixel.
*/
PHP_METHOD(imagickpixel, getcolorvalue)
{
	php_imagickpixel_object *internp;
	long color;
	double color_value = 0;

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

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

	switch (color) {

		case IMAGICKCOLORBLACK:
			color_value = PixelGetBlack(internp->pixel_wand);
		break;

		case IMAGICKCOLORBLUE:
			color_value = PixelGetBlue(internp->pixel_wand);
		break;

		case IMAGICKCOLORCYAN:
			color_value = PixelGetCyan(internp->pixel_wand);
		break;

		case IMAGICKCOLORGREEN:
			color_value = PixelGetGreen(internp->pixel_wand);
		break;

		case IMAGICKCOLORRED:
			color_value = PixelGetRed(internp->pixel_wand);
		break;

		case IMAGICKCOLORYELLOW:
			color_value = PixelGetYellow(internp->pixel_wand);
		break;

		case IMAGICKCOLORMAGENTA:
			color_value = PixelGetMagenta(internp->pixel_wand);
		break;

		case IMAGICKCOLOROPACITY:
			color_value = PixelGetOpacity(internp->pixel_wand);
		break;

		case IMAGICKCOLORALPHA:
			color_value = PixelGetAlpha(internp->pixel_wand);
		break;

#if MagickLibVersion > 0x628
		case IMAGICKCOLORFUZZ:
			color_value = PixelGetFuzz(internp->pixel_wand);
		break;
#endif

		default:
			php_imagick_throw_exception (IMAGICKPIXEL_CLASS, "Unknown color type" TSRMLS_CC);
			return;
		break;
	}
	RETVAL_DOUBLE(color_value);
}