/* {{{ proto array GmagickPixel::getColor([boolean as_array = false, normalise_array = false])
	Returns the color of the pixel
*/
PHP_METHOD(gmagickpixel, getcolor)
{
	php_gmagickpixel_object *internp;
	zend_bool as_array = 0, normalise_array = 0;

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

	internp = Z_GMAGICKPIXEL_OBJ_P(getThis());

	if (!as_array) {
		char *buffer, *color_string;
		int len;
		
		color_string = PixelGetColorAsString(internp->pixel_wand);
		
		len = spprintf(&buffer, 50, "rgb(%s)", color_string);
		GMAGICK_FREE_MEMORY(char *, color_string);
		RETVAL_STRINGL(buffer, len);
		efree(buffer);
		return;
	} else {
		array_init(return_value);
		
		if (normalise_array == 1) {
			add_assoc_double(return_value, "r", PixelGetRed(internp->pixel_wand));
			add_assoc_double(return_value, "g", PixelGetGreen(internp->pixel_wand));
			add_assoc_double(return_value, "b", PixelGetBlue(internp->pixel_wand));
		} else {
			double red, green, blue;
			
			red = PixelGetRed(internp->pixel_wand ) * 255;
			green = PixelGetGreen(internp->pixel_wand ) * 255;
			blue = PixelGetBlue(internp->pixel_wand ) * 255;

			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));
		}
		return;
	}
}
Beispiel #2
0
/*
@description	Returns the normalized green color of the pixel wand.
*/
value nMagick_pixel_get_green( value pixel )
{
	PixelWand *pix;

	val_check_kind( pixel, k_pixel );

	pix = PIXEL( pixel );

	return alloc_float( PixelGetGreen( pix ) );
}
Beispiel #3
0
/* {{{ 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;
}
Beispiel #4
0
int pixel_compare_NN(double epsilon,void* source, void *kd,  double* pixel_position, PixelWand* color, PixelWand* neigh_color)
{
    struct kdres *neigh;
    double neigh_position[2]= {0,0};

    neigh = kd_nearest(kd,pixel_position);
    if(neigh == NULL)
        return 1;
    kd_res_item(neigh, neigh_position);
    kd_res_free(neigh);//need to free the memory used for the query
    MagickGetImagePixelColor(source,neigh_position[0],neigh_position[1],neigh_color); 
    MagickGetImagePixelColor(source,pixel_position[0],pixel_position[1],color); 
    double color_diff =0;
    color_diff += pow(PixelGetRed(color) - PixelGetRed(neigh_color),2);
    color_diff += pow(PixelGetGreen(color) - PixelGetGreen(neigh_color),2);
    color_diff += pow(PixelGetBlue(color) - PixelGetBlue(neigh_color),2);
    if(color_diff < epsilon)
        return 0;
    return 1;

}
/* {{{ proto float GmagickPixel::getColorValue(int color )
	Gets the normalized color of the GmagickPixel.
*/
PHP_METHOD(gmagickpixel, getcolorvalue)
{
	php_gmagickpixel_object *internp;
	zend_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_GMAGICKPIXEL_OBJ_P(getThis());

	switch (color) {

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

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

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

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

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

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

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

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

		default:
			GMAGICK_THROW_GMAGICKPIXEL_EXCEPTION(internp->pixel_wand, "Unknown color type");
		break;
	}
	RETVAL_DOUBLE(color_value);
}
Beispiel #6
0
/**
 * 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]);
    }
}
Beispiel #7
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;
}
Beispiel #8
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);
}
Beispiel #9
0
/* {{{ 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);
}
Beispiel #10
0
/* gcc -o imagick imagick-landscape-3d.c -Wall -Werror -I/usr/include/ImageMagick -lMagickWand */
int main()
{
  MagickWand *mw, *canvas;
  PixelWand  *pw;
  DrawingWand *line;
  size_t w, h, offset;
  int x, y, r, g, b, grey, lh;
  MagickBooleanType mbt;

  MagickWandGenesis();  /* startup */

  mw = NewMagickWand();

  mbt = MagickReadImage(mw, PNG_IN_FILE);
  assert(mbt == MagickTrue);
  w = MagickGetImageWidth(mw);
  h = MagickGetImageHeight(mw);

  pw = NewPixelWand();
  PixelSetColor(pw, "transparent");

  mbt = MagickShearImage(mw, pw, 45, 0);
  assert(mbt == MagickTrue);

  w = MagickGetImageWidth(mw);
  h = MagickGetImageHeight(mw);

  mbt = MagickScaleImage(mw, w, h/2);
  assert(mbt = MagickTrue);

  w = MagickGetImageWidth(mw);
  h = MagickGetImageHeight(mw);

  canvas = NewMagickWand();
  MagickGetImagePixelColor(mw, 0, 0, pw);
  MagickNewImage(canvas, w, h*2, pw);

  offset = h;
  for (x = 0; x < w; ++x) {
    line = NewDrawingWand();
    lh = 0;
    for (y = h-1; y >= 0; --y) {
      if (MagickGetImagePixelColor(mw, x, y, pw) == MagickFalse) continue;
      r = 255 * PixelGetRed(pw);
      g = 255 * PixelGetGreen(pw);
      b = 255 * PixelGetBlue(pw);

      grey = (r + g + b)/5;
      if (lh == 0 || lh < grey) {
        DrawSetFillColor(line, pw);
        DrawSetStrokeColor(line, pw);
        DrawLine(line, x, y + offset - lh, x, y - grey + offset);
        lh = grey;
      }
      lh--;
    }

    MagickDrawImage(canvas, line);
    DestroyDrawingWand(line);
  }

  MagickScaleImage(canvas, w - h, h * 2);
  
  mbt = MagickSetImageFormat(canvas, "png");
  assert(mbt == MagickTrue);
  mbt = MagickWriteImage(canvas, PNG_OUT_FILE);
  assert(mbt == MagickTrue);

  pw = DestroyPixelWand(pw);
  mw = DestroyMagickWand(mw);
  canvas = DestroyMagickWand(canvas);
  
  MagickWandTerminus(); /* shutdown */

  return 0;
}