ext/RMagick/rmimage.c in rmagick-2.9.2 vs ext/RMagick/rmimage.c in rmagick-2.10.0
- old
+ new
@@ -1,6 +1,6 @@
-/* $Id: rmimage.c,v 1.346 2009/03/04 00:35:19 rmagick Exp $ */
+/* $Id: rmimage.c,v 1.349 2009/06/05 22:30:40 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2009 by Timothy P. Hunter
| Name: rmimage.c
| Author: Tim Hunter
| Purpose: Image class method definitions for RMagick
@@ -282,26 +282,12 @@
rb_raise(rb_eArgError, "mask must be the same size as image");
}
// Delete any previously-existing mask image.
// Store a clone of the new mask image.
-#if defined(HAVE_SETIMAGEMASK)
(void) SetImageMask(image, mask_image);
(void) NegateImage(image->mask, MagickFalse);
-#else
- if (image->clip_mask)
- {
- image->clip_mask = DestroyImage(image->clip_mask);
- }
- image->clip_mask = NewImageList();
- if (SetImageStorageClass(image, DirectClass) == MagickFalse)
- {
- rm_magick_error("SetImageStorageClass failed", NULL);
- }
- image->clip_mask = rm_clone_image(mask_image);
- (void) NegateImage(image->clip_mask, MagickFalse);
-#endif
// Since both Set and GetImageMask clone the mask image I don't see any
// way to negate the mask without referencing it directly. Sigh.
return self;
@@ -401,19 +387,15 @@
info = CloneImageInfo(NULL);
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
-#if defined(HAVE_ST_PROFILE)
profile = GetImageProfile(image, "iptc");
if (profile)
{
info->profile = (void *)CloneStringInfo(profile);
}
-#else
- info->client_data = GetImageProfile(image, "8bim");
-#endif
strncpy(info->filename, profile_filename, min((size_t)profile_filename_l, sizeof(info->filename)));
info->filename[MaxTextExtent-1] = '\0';
GetExceptionInfo(&exception);
profile_image = ReadImage(info, &exception);
@@ -460,11 +442,10 @@
matte channel is active, false otherwise.
*/
VALUE
Image_alpha(int argc, VALUE *argv, VALUE self)
{
-#if defined(HAVE_TYPE_ALPHACHANNELTYPE)
Image *image;
AlphaChannelType alpha;
// For backward compatibility, make alpha() act like alpha?
@@ -514,18 +495,10 @@
break;
}
#endif
return argv[0];
-
-#else // HAVE_ALPHACHANNELTYPE
- argc = argc;
- argv =argv;
- self = self;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
@@ -553,21 +526,14 @@
Notes: Deprecated. See Image_alpha.
*/
VALUE
Image_alpha_eq(VALUE self, VALUE type)
{
-#if defined(HAVE_TYPE_ALPHACHANNELTYPE)
VALUE argv[1];
argv[0] = type;
Image_alpha(1, argv, self);
return type;
-#else
- self = self;
- type = type;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
Method: Image#affine_transform(affine_matrix)
@@ -1812,11 +1778,10 @@
Purpose: Equivalent to -clut option.
*/
VALUE
Image_clut_channel(int argc, VALUE *argv, VALUE self)
{
-#if defined(HAVE_CLUTIMAGECHANNEL)
Image *image, *clut;
ChannelType channels;
MagickBooleanType okay;
image = rm_check_frozen(self);
@@ -1845,18 +1810,10 @@
{
rb_raise(rb_eRuntimeError, "ClutImageChannel failed.");
}
return self;
-
-#else
- argc = argc;
- argv = argv;
- self = self;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
Method: Image_color_histogram(VALUE self);
@@ -3435,22 +3392,12 @@
Image_delete_compose_mask(VALUE self)
{
Image *image = rm_check_frozen(self);
// Store a clone of the mask image
-#if defined(HAVE_SETIMAGEMASK)
- {
- (void) SetImageMask(image, NULL);
- rm_check_image_exception(image, RetainOnError);
- }
-#else
- if (image->clip_mask)
- {
- image->clip_mask = DestroyImage(image->clip_mask);
- }
- image->clip_mask = NewImageList();
-#endif
+ (void) SetImageMask(image, NULL);
+ rm_check_image_exception(image, RetainOnError);
return self;
}
@@ -3896,11 +3843,10 @@
VALUE
Image_distort(int argc, VALUE *argv, VALUE self)
{
-#if defined(HAVE_DISTORTIMAGE)
Image *image, *new_image;
volatile VALUE pts;
unsigned long n, npoints;
DistortImageMethod distortion_method;
double *points;
@@ -3940,17 +3886,10 @@
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
-#else
- self = self; // defeat "unused parameter" message
- argv = argv;
- argc = argc;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
* Method: Image#distortion_channel(reconstructed_image, metric[, channel...])
@@ -4380,11 +4319,10 @@
not update the page offset and its more efficient than cropping."
*/
static VALUE
excerpt(int bang, VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
{
-#if defined(HAVE_EXCERPTIMAGE)
Image *image, *new_image;
RectangleInfo rect;
ExceptionInfo exception;
memset(&rect,'\0', sizeof(rect));
@@ -4407,18 +4345,10 @@
(void) rm_image_destroy(image);
return self;
}
return rm_image_new(new_image);
-
-#else
- bang = bang; self = self;
- x = x; y = y;
- width = width; height = height;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
VALUE
Image_excerpt(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
@@ -4523,11 +4453,10 @@
Purpose: Call ExtentImage
*/
VALUE
Image_extent(int argc, VALUE *argv, VALUE self)
{
-#if defined(HAVE_EXTENTIMAGE)
Image *image, *new_image;
RectangleInfo geometry;
long height, width;
ExceptionInfo exception;
@@ -4572,17 +4501,10 @@
new_image = ExtentImage(image, &geometry, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
-#else
- argc = argc;
- argv = argv;
- self = self;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
Method: Image#export_pixels_to_str(x=0, y=0, cols=self.columns,
@@ -5344,17 +5266,11 @@
Purpose: return true if has 1024 unique colors or less.
*/
VALUE
Image_histogram_q(VALUE self)
{
-#if defined(HAVE_ISHISTOGRAMIMAGE)
return has_attribute(self, IsHistogramImage);
-#else
- self = self;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
Method: Image#implode(amount=0.50)
@@ -6018,11 +5934,10 @@
See Image_contrast_stretch_channel.
*/
VALUE
Image_linear_stretch(int argc, VALUE *argv, VALUE self)
{
-#if defined(HAVE_LINEARSTRETCHIMAGE)
Image *image, *new_image;
double black_point, white_point;
image = rm_check_destroyed(self);
get_black_white_point(image, argc, argv, &black_point, &white_point);
@@ -6030,17 +5945,10 @@
(void) LinearStretchImage(new_image, black_point, white_point);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
-#else
- argc = argc; // defeat "unused parameter" messages
- argv = argv;
- self = self;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
Method: Image#liquid_rescale(columns, rows, delta_x=0.0, rigidity=0.0)
@@ -6517,11 +6425,11 @@
Notes: Deprecated as of ImageMagick 6.3.6. See Image#alpha
*/
VALUE
Image_matte_eq(VALUE self, VALUE matte)
{
-#if defined(HAVE_TYPE_ALPHACHANNELTYPE) || defined(HAVE_SETIMAGEALPHACHANNEL)
+#if defined(HAVE_SETIMAGEALPHACHANNEL)
VALUE alpha_channel_type;
if (RTEST(matte))
{
alpha_channel_type = rb_const_get(Module_Magick, rb_intern("ActivateAlphaChannel"));
@@ -7654,11 +7562,10 @@
border color.
*/
VALUE
Image_polaroid(int argc, VALUE *argv, VALUE self)
{
-#if defined(HAVE_POLAROIDIMAGE)
Image *image, *clone, *new_image;
volatile VALUE options;
double angle = -5.0;
Draw *draw;
ExceptionInfo exception;
@@ -7691,17 +7598,10 @@
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
-#else
- argc = argc; // defeat "unused parameter" messages
- argv = argv;
- self = self;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
Method: posterize
@@ -8266,11 +8166,10 @@
Purpose: Call RecolorImage
*/
VALUE
Image_recolor(VALUE self, VALUE color_matrix)
{
-#if defined(HAVE_RECOLORIMAGE)
Image *image, *new_image;
unsigned long order;
long x, len;
double *matrix;
ExceptionInfo exception;
@@ -8295,17 +8194,10 @@
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
-
-#else
- self = self; // defeat "unused parameter" message
- color_matrix = color_matrix;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
Method: Image.read_inline(content)
@@ -8810,10 +8702,58 @@
DEF_ATTR_READER(Image, scene, ulong)
/*
+ * Method: Image#selective_blur_channel(radius, sigma, threshold[, channel...])
+ * Purpose: Call SelectiveBlurImageChannel
+ */
+VALUE
+Image_selective_blur_channel(int argc, VALUE *argv, VALUE self)
+{
+#if defined(HAVE_SELECTIVEBLURIMAGECHANNEL)
+ Image *image, *new_image;
+ double radius, sigma, threshold;
+ ExceptionInfo exception;
+ ChannelType channels;
+
+ image = rm_check_destroyed(self);
+ channels = extract_channels(&argc, argv);
+ if (argc > 3)
+ {
+ raise_ChannelType_error(argv[argc-1]);
+ }
+ if (argc != 3)
+ {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or more)", argc);
+ }
+ radius = NUM2DBL(argv[0]);
+ sigma = NUM2DBL(argv[1]);
+
+ // threshold is either a floating-point number or a string in the form "NN%".
+ // Either way it's supposed to represent a percentage of the QuantumRange.
+ threshold = rm_percentage(argv[2]) * QuantumRange;
+
+ GetExceptionInfo(&exception);
+ new_image = SelectiveBlurImageChannel(image, channels, radius, sigma, threshold, &exception);
+ rm_check_exception(&exception, new_image, DestroyOnError);
+ (void) DestroyExceptionInfo(&exception);
+ rm_ensure_result(new_image);
+
+ return rm_image_new(new_image);
+
+#else
+ rm_not_implemented();
+ argc = argc;
+ argv = argv;
+ self = self;
+ return (VALUE)0;
+#endif
+}
+
+
+/*
* Method: Image#set_channel_depth(channel, depth)
* Purpose: Call SetImageChannelDepth
*/
VALUE
Image_set_channel_depth(VALUE self, VALUE channel_arg, VALUE depth)
@@ -8976,50 +8916,10 @@
Image_properties(VALUE self)
{
Image *image;
volatile VALUE attr_hash;
volatile VALUE ary;
-
-#if !defined(HAVE_GETNEXTIMAGEPROPERTY)
- const ImageAttribute *attr;
-
- image = rm_check_destroyed(self);
-
- // If block, iterate over attributes
- if (rb_block_given_p())
- {
- ary = rb_ary_new2(2);
-
- ResetImageAttributeIterator(image);
- attr = GetNextImageAttribute(image);
- while (attr)
- {
- (void) rb_ary_store(ary, 0, rb_str_new2(attr->key));
- (void) rb_ary_store(ary, 1, rb_str_new2(attr->value));
- (void) rb_yield(ary);
- attr = GetNextImageAttribute(image);
- }
- rm_check_image_exception(image, RetainOnError);
- return self;
- }
-
- // otherwise return properties hash
- else
- {
- attr_hash = rb_hash_new();
- ResetImageAttributeIterator(image);
- attr = GetNextImageAttribute(image);
- while (attr)
- {
- (void) rb_hash_aset(attr_hash, rb_str_new2(attr->key), rb_str_new2(attr->value));
- attr = GetNextImageAttribute(image);
- }
- rm_check_image_exception(image, RetainOnError);
- return attr_hash;
- }
-
-#else
char *property;
const char *value;
image = rm_check_destroyed(self);
@@ -9055,11 +8955,10 @@
}
rm_check_image_exception(image, RetainOnError);
return attr_hash;
}
-#endif
}
/*
Method: Image#shade(shading=false, azimuth=30, elevation=30)
@@ -9890,20 +9789,14 @@
Purpose: synchronizes image properties with the image profiles
*/
VALUE
Image_sync_profiles(VALUE self)
{
-#if defined(HAVE_SYNCIMAGEPROFILES)
Image *image = rm_check_destroyed(self);
volatile VALUE okay = SyncImageProfiles(image) ? Qtrue : Qfalse;
rm_check_image_exception(image, RetainOnError);
return okay;
-#else
- self = self;
- rm_not_implemented();
- return(VALUE)0;
-#endif
}
/*
Method: Image#texture_flood_fill(color, texture, x, y, method)
@@ -10591,16 +10484,11 @@
rm_ensure_result(new_image);
if (reset_page)
{
-#if defined(HAVE_RESETIMAGEPAGE)
ResetImagePage(new_image, "0x0+0+0");
-#else
- new_image->page.x = new_image->page.y = 0L;
- new_image->page.width = new_image->page.height = 0UL;
-#endif
}
if (bang)
{
UPDATE_DATA_PTR(self, new_image);
@@ -11558,15 +11446,10 @@
cropped = xform_image(bang, self, x, y, width, height, CropImage);
if (reset_page)
{
Data_Get_Struct(cropped, Image, image);
-#if defined(HAVE_RESETIMAGEPAGE)
ResetImagePage(image, "0x0+0+0");
-#else
- image->page.x = image->page.y = 0L;
- image->page.width = image->page.height = 0UL;
-#endif
}
return cropped;
}