ext/RMagick/rmutil.c in rmagick-1.13.0 vs ext/RMagick/rmutil.c in rmagick-1.14.0
- old
+ new
@@ -1,6 +1,6 @@
-/* $Id: rmutil.c,v 1.78 2006/06/28 23:07:55 rmagick Exp $ */
+/* $Id: rmutil.c,v 1.83 2006/09/27 21:26:36 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2006 by Timothy P. Hunter
| Name: rmutil.c
| Author: Tim Hunter
| Purpose: Utility functions for RMagick
@@ -572,12 +572,11 @@
Pixel *pixel;
double hue, saturation, luminosity;
volatile VALUE hsl;
Data_Get_Struct(self, Pixel, pixel);
- TransformHSL(pixel->red, pixel->green, pixel->blue,
- &hue, &saturation, &luminosity);
+ TransformHSL(pixel->red, pixel->green, pixel->blue, &hue, &saturation, &luminosity);
hsl = rb_ary_new3(3, rb_float_new(hue), rb_float_new(saturation),
rb_float_new(luminosity));
return hsl;
@@ -1074,11 +1073,32 @@
{
rb_raise(rb_eArgError, "invalid color name %s", name);
}
}
+
/*
+ Extern: Pixel_from_MagickPixelPacket
+ Purpose: Create a Magick::Pixel from a MagickPixelPacket structure
+*/
+#if defined(HAVE_MAGICKPIXELPACKET)
+VALUE
+Pixel_from_MagickPixelPacket(MagickPixelPacket *mpp)
+{
+ PixelPacket pixel;
+
+ pixel.red = RoundToQuantum(mpp->red);
+ pixel.green = RoundToQuantum(mpp->green);
+ pixel.blue = RoundToQuantum(mpp->blue);
+ pixel.opacity = RoundToQuantum(mpp->opacity);
+
+ return Pixel_from_PixelPacket(&pixel);
+}
+#endif
+
+
+/*
Extern: AffineMatrix_to_AffineMatrix
Purpose: Convert a Magick::AffineMatrix object to a AffineMatrix structure.
Notes: If not initialized, the defaults are [sx,rx,ry,sy,tx,ty] = [1,0,0,1,0,0]
*/
void
@@ -1100,11 +1120,11 @@
am->ry = v == Qnil ? 0.0 : NUM2DBL(v);
v = rb_ary_entry(values, 3);
am->sy = v == Qnil ? 1.0 : NUM2DBL(v);
v = rb_ary_entry(values, 4);
am->tx = v == Qnil ? 0.0 : NUM2DBL(v);
- v = rb_ary_entry(values, 4);
+ v = rb_ary_entry(values, 5);
am->ty = v == Qnil ? 0.0 : NUM2DBL(v);
}
/*
@@ -1568,10 +1588,48 @@
return rm_enum_new(Class_InterlaceType, ID2SYM(rb_intern(name)), INT2FIX(interlace));
}
/*
+ Static: InterpolatePixelMethod_name
+ Purpose: Return the name of a InterpolatePixelMethod enum as a string
+*/
+#if defined(HAVE_INTERPOLATEPIXELCOLOR)
+static const char *
+InterpolatePixelMethod_name(InterpolatePixelMethod interpolate)
+{
+ switch(interpolate)
+ {
+ default:
+ ENUM_TO_NAME(UndefinedInterpolatePixel)
+ ENUM_TO_NAME(AverageInterpolatePixel)
+ ENUM_TO_NAME(BicubicInterpolatePixel)
+ ENUM_TO_NAME(BilinearInterpolatePixel)
+ ENUM_TO_NAME(FilterInterpolatePixel)
+ ENUM_TO_NAME(IntegerInterpolatePixel)
+ ENUM_TO_NAME(MeshInterpolatePixel)
+ ENUM_TO_NAME(NearestNeighborInterpolatePixel)
+ }
+}
+
+
+/*
+ External: InterpolatePixelMethod_new
+ Purpose: Construct an InterpolatePixelMethod enum object for the specified value.
+*/
+VALUE
+InterpolatePixelMethod_new(InterpolatePixelMethod interpolate)
+{
+ const char *name;
+
+ name = InterpolatePixelMethod_name(interpolate);
+ return rm_enum_new(Class_InterpolatePixelMethod, ID2SYM(rb_intern(name)), INT2FIX(interpolate));
+}
+#endif
+
+
+/*
External: MagickLayerMethod_new
Purpose: Construct an MagickLayerMethod enum object for the specified value.
*/
#if defined(HAVE_COMPAREIMAGELAYERS)
static const char *
@@ -2858,19 +2916,19 @@
Q(MAGICKNAME) " " MagickLibVersionText
, rb_id2name(rb_frame_last_func()));
}
/*
- Static: raise_error(msg, loc)
+ Static: rm_magick_error(msg, loc)
Purpose: create a new ImageMagickError object and raise an exception
Notes: does not return
This funky technique allows me to safely add additional
information to the ImageMagickError object in both 1.6.8 and
1.8.0. See www.ruby_talk.org/36408.
*/
-static void
-raise_error(const char *msg, const char *loc)
+void
+rm_magick_error(const char *msg, const char *loc)
{
volatile VALUE exc, mesg, extra;
mesg = rb_str_new2(msg);
extra = loc ? rb_str_new2(loc) : Qnil;
@@ -3319,14 +3377,14 @@
#endif
extra[sizeof(extra)-1] = '\0';
DestroyExceptionInfo(exception);
- raise_error(msg, extra);
+ rm_magick_error(msg, extra);
#else
DestroyExceptionInfo(exception);
- raise_error(msg, NULL);
+ rm_magick_error(msg, NULL);
#endif
}