ext/RMagick/rmimage.c in rmagick-3.2.0 vs ext/RMagick/rmimage.c in rmagick-4.0.0
- old
+ new
@@ -40,35 +40,24 @@
static const char *BlackPointCompensationKey = "PROFILE:black-point-compensation";
/**
- * Converts the opacity value to alpha and raises a warning.
- *
- * No Ruby usage (internal function)
- *
- * @opacity an opacity value
- */
-static Quantum
-get_alpha_from_opacity(VALUE opacity)
-{
- VALUE method = rb_id2str(rb_frame_this_func());
- rb_warning("Image#%"PRIsVALUE" requires a named argument for 'alpha' and now expects an alpha value instead of an opacity value.", method);
-
- return QuantumRange - APP2QUANTUM(opacity);
-}
-
-/**
* Returns the alpha value from the hash.
*
* No Ruby usage (internal function)
*
* @hash the hash
*/
static Quantum
-get_alpha_from_hash(VALUE hash)
+get_named_alpha_value(VALUE hash)
{
+ if (TYPE(hash) != T_HASH)
+ {
+ rb_raise(rb_eArgError, "missing keyword: alpha");
+ }
+
if (FIX2ULONG(rb_hash_size(hash)) != 1)
{
rb_raise(rb_eArgError, "wrong number of arguments");
}
@@ -79,30 +68,11 @@
}
return APP2QUANTUM(alpha);
}
-/**
- * Checks if opacity_or_alpha is a named argument called alpha and returns the alpha value or
- * converts the unnamed opacity value to alpha.
- *
- * No Ruby usage (internal function)
- *
- * @opacity_or_alpha an opacity or a named alpha value
- */
-static Quantum
-get_named_alpha_value(VALUE opacity_or_alpha)
-{
- if (TYPE(opacity_or_alpha) != T_HASH)
- {
- return get_alpha_from_opacity(opacity_or_alpha);
- }
- return get_alpha_from_hash(opacity_or_alpha);
-}
-
-
/**
* Call Adaptive(Blur|Sharpen)Image.
*
* No Ruby usage (internal function)
*
@@ -671,34 +641,10 @@
return GetImageAlphaChannel(image) ? Qtrue : Qfalse;
}
/**
- * Equivalent to -alpha option.
- *
- * Ruby usage:
- * - @verbatim Image#alpha=(alpha) @endverbatim
- *
- * @param self this object
- * @param type the alpha type
- * @return alpha
- * @deprecated This method has been deprecated. Please use Image_alpha.
- * @see Image_alpha
- * @see mogrify.c (in ImageMagick)
- */
-VALUE
-Image_alpha_eq(VALUE self, VALUE type)
-{
- VALUE argv[1];
- argv[0] = type;
- rb_warning("Image#alpha= is deprecated; use Image#alpha.");
- Image_alpha(1, argv, self);
- return type;
-}
-
-
-/**
* Transform an image as dictated by the affine matrix argument.
*
* Ruby usage:
* - @verbatim Image#affine_transform(affine_matrix) @endverbatim
*
@@ -1361,11 +1307,10 @@
*x_offset = (long)(image->columns) - (long)(mark->columns) - *x_offset;
break;
case NorthGravity:
case SouthGravity:
case CenterGravity:
- case StaticGravity:
*x_offset += (long)(image->columns/2) - (long)(mark->columns/2);
break;
default:
break;
}
@@ -1377,11 +1322,10 @@
*y_offset = (long)(image->rows) - (long)(mark->rows) - *y_offset;
break;
case EastGravity:
case WestGravity:
case CenterGravity:
- case StaticGravity:
*y_offset += (long)(image->rows/2) - (long)(mark->rows/2);
break;
case NorthEastGravity:
case NorthGravity:
default:
@@ -1427,11 +1371,10 @@
break;
case WestGravity:
*x_offset = 0;
*y_offset = ((long)(image->rows) - (long)(mark->rows)) / 2;
break;
- case StaticGravity:
case CenterGravity:
default:
*x_offset = ((long)(image->columns) - (long)(mark->columns)) / 2;
*y_offset = ((long)(image->rows) - (long)(mark->rows)) / 2;
break;
@@ -1755,57 +1698,10 @@
return rm_image_new(new_image);
}
/**
- * Get the blur attribute.
- *
- * Ruby usage:
- * - @verbatim Image#blur @endverbatim
- *
- * @param self this object
- * @return the blur
- * @deprecated This method has been deprecated.
- */
-VALUE
-Image_blur(VALUE self)
-{
- Image *image;
-
- rb_warning("Image#blur is deprecated");
- (void) rm_check_destroyed(self);
- Data_Get_Struct(self, Image, image);
- return C_dbl_to_R_dbl(image->blur);
-}
-
-
-/**
- * Set the blur attribute.
- *
- * Ruby usage:
- * - @verbatim Image#blur= @endverbatim
- *
- * @param self this object
- * @param value the blur
- * @return value
- * @deprecated This method has been deprecated.
- */
-VALUE
-Image_blur_eq(VALUE self, VALUE value)
-{
- Image *image;
-
- rb_warning("Image#blur= is deprecated");
- (void) rm_check_destroyed(self);
- rb_check_frozen(self);
- Data_Get_Struct(self, Image, image);
- image->blur = R_dbl_to_C_dbl(value);
- return value;
-}
-
-
-/**
* Call BlurImageChannel.
*
* Ruby usage:
* - @verbatim Image#blur_channel @endverbatim
* - @verbatim Image#blur_channel(radius) @endverbatim
@@ -3126,92 +3022,10 @@
*/
DEF_ATTR_READER(Image, columns, int)
/**
- * Combine the Red channel of the first image with the Green channel of the
- * 2nd image and the Blue channel of the 3rd image. Any of the image arguments
- * may be omitted or replaced by nil.
- *
- * Ruby usage:
- * - @verbatim new_image = Image.combine(red) @endverbatim
- * - @verbatim new_image = Image.combine(red, green) @endverbatim
- * - @verbatim new_image = Image.combine(red, green, blue) @endverbatim
- * - @verbatim new_image = Image.combine(red, green, blue, opacity) @endverbatim
- *
- * Notes:
- * - Calls CombineImages.
- *
- * @param argc number of input arguments
- * @param argv array of input arguments
- * @param self this object
- * @return a new image
- * @deprecated This method has been deprecated. Please use ImageList_combine.
- */
-VALUE Image_combine(int argc, VALUE *argv, VALUE self ATTRIBUTE_UNUSED)
-{
- ChannelType channel = 0;
- Image *image, *images = NULL, *new_image;
- ExceptionInfo *exception;
-
- rb_warning("Image#combine is deprecated; use ImageList#combine.");
-
- switch (argc)
- {
- case 4:
- if (argv[3] != Qnil)
- {
- channel |= OpacityChannel;
- image = rm_check_destroyed(argv[3]);
- AppendImageToList(&images, image);
- }
- case 3:
- if (argv[2] != Qnil)
- {
- channel |= BlueChannel;
- image = rm_check_destroyed(argv[2]);
- AppendImageToList(&images, image);
- }
- case 2:
- if (argv[1] != Qnil)
- {
- channel |= GreenChannel;
- image = rm_check_destroyed(argv[1]);
- AppendImageToList(&images, image);
- }
- case 1:
- if (argv[0] != Qnil)
- {
- channel |= RedChannel;
- image = rm_check_destroyed(argv[0]);
- AppendImageToList(&images, image);
- }
- break;
- default:
- rb_raise(rb_eArgError, "wrong number of arguments (1 to 4 expected, got %d)", argc);
- }
-
- if (channel == 0)
- {
- rb_raise(rb_eArgError, "no images to combine");
- }
-
- exception = AcquireExceptionInfo();
- ReverseImageList(&images);
- new_image = CombineImages(images, channel, exception);
- rm_check_exception(exception, images, RetainOnError);
- (void) DestroyExceptionInfo(exception);
- rm_split(images);
-
- rm_ensure_result(new_image);
-
- return rm_image_new(new_image);
-
-}
-
-
-/**
* Compare one or more channels in two images and returns the specified
* distortion metric and a comparison image.
*
* Ruby usage:
* - @verbatim Image#compare_channel(ref_image, metric) { optional arguments } @endverbatim
@@ -3391,11 +3205,10 @@
break;
case WestGravity:
x_offset = 0;
y_offset = ((long)(image->rows) - (long)(comp_image->rows)) / 2;
break;
- case StaticGravity:
case CenterGravity:
default:
x_offset = ((long)(image->columns) - (long)(comp_image->columns)) / 2;
y_offset = ((long)(image->rows) - (long)(comp_image->rows)) / 2;
break;
@@ -3439,11 +3252,10 @@
x_offset = ((long)(image->columns) - (long)(comp_image->columns)) - x_offset;
break;
case NorthGravity:
case SouthGravity:
case CenterGravity:
- case StaticGravity:
x_offset += (long)(image->columns/2) - (long)(comp_image->columns/2);
break;
default:
break;
}
@@ -3455,11 +3267,10 @@
y_offset = ((long)(image->rows) - (long)(comp_image->rows)) - y_offset;
break;
case EastGravity:
case WestGravity:
case CenterGravity:
- case StaticGravity:
y_offset += (long)(image->rows/2) - (long)(comp_image->rows/2);
break;
case NorthEastGravity:
case NorthGravity:
default:
@@ -5544,11 +5355,12 @@
*/
VALUE
Image_each_profile(VALUE self)
{
Image *image;
- VALUE ary, val;
+ VALUE ary;
+ VALUE val = Qnil;
char *name;
const StringInfo *profile;
image = rm_check_destroyed(self);
ResetImageProfileIterator(image);
@@ -6266,13 +6078,10 @@
sz = sizeof(double);
break;
case FloatPixel:
sz = sizeof(float);
break;
- case IntegerPixel:
- sz = sizeof(unsigned int);
- break;
case LongPixel:
sz = sizeof(unsigned long);
break;
case QuantumPixel:
sz = sizeof(Quantum);
@@ -7490,13 +7299,10 @@
type_sz = 1;
break;
case ShortPixel:
type_sz = sizeof(unsigned short);
break;
- case IntegerPixel:
- type_sz = sizeof(unsigned int);
- break;
case LongPixel:
type_sz = sizeof(unsigned long);
break;
case DoublePixel:
type_sz = sizeof(double);
@@ -8383,67 +8189,10 @@
return magnify(True, self, MagnifyImage);
}
/**
- * Call MapImage.
- *
- * Ruby usage:
- * - @verbatim Image#map(map_image) @endverbatim
- * - @verbatim Image#map(map_image, dither) @endverbatim
- *
- * Notes:
- * - Default dither is false
- *
- * @param argc number of input arguments
- * @param argv array of input arguments
- * @param self this object
- * @return a new image
- */
-VALUE
-Image_map(int argc, VALUE *argv, VALUE self)
-{
- Image *image, *new_image;
- Image *map;
- VALUE map_obj, map_arg;
- unsigned int dither = MagickFalse;
-
- QuantizeInfo quantize_info;
- rb_warning("Image#map is deprecated. Use Image#remap instead");
-
- image = rm_check_destroyed(self);
-
- switch (argc)
- {
- case 2:
- dither = RTEST(argv[1]);
- case 1:
- map_arg = argv[0];
- break;
- default:
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
- break;
- }
-
- map_obj = rm_cur_image(map_arg);
- map = rm_check_destroyed(map_obj);
-
- new_image = rm_clone_image(image);
-
- GetQuantizeInfo(&quantize_info);
- quantize_info.dither=dither;
- (void) RemapImage(&quantize_info, new_image, map);
- rm_check_image_exception(new_image, DestroyOnError);
-
- RB_GC_GUARD(map_obj);
- RB_GC_GUARD(map_arg);
-
- return rm_image_new(new_image);
-}
-
-
-/**
* Support Marshal.dump >= 1.8.
*
* Ruby usage:
* - @verbatim Image#marshal_dump @endverbatim
*
@@ -8647,33 +8396,10 @@
return get_image_mask(image);
}
/**
- * Set the image mask.
- *
- * Ruby usage:
- * - @verbatim Image#mask= @endverbatim
- *
- * @param self this object
- * @param mask the mask to use
- * @return copy of the current clip-mask or nil
- * @deprecated This method has been deprecated. Please use Image_mask(mask-image).
- * @see Image_mask(mask-image)
- * @see get_image_mask
- */
-VALUE
-Image_mask_eq(VALUE self, VALUE mask)
-{
- VALUE v[1];
- v[0] = mask;
- rb_warning("Image#mask= is deprecated; use Image#mask.");
- return Image_mask(1, v, self);
-}
-
-
-/**
* Associate a clip mask with the image.
*
* Ruby usage:
* - @verbatim Image#mask @endverbatim
* - @verbatim Image#mask(mask-image) @endverbatim
@@ -8714,66 +8440,10 @@
return set_image_mask(image, mask);
}
/**
- * Get matte attribute.
- *
- * Ruby usage:
- * - @verbatim Image#matte @endverbatim
- *
- * @param self this object
- * @return the matte
- * @deprecated This method has been deprecated. Please use Image_alpha.
- * @see Image_alpha
- * @see Image_alpha_eq
- */
-VALUE
-Image_matte(VALUE self)
-{
- Image *image;
-
- image = rm_check_destroyed(self);
- rb_warning("Image#matte is deprecated; use Image#alpha.");
- return image->matte ? Qtrue : Qfalse;
-}
-
-
-/**
- * Set matte attribute.
- *
- * Ruby usage:
- * - @verbatim Image#matte= @endverbatim
- *
- * @param self this object
- * @param matte the matte
- * @return the matte
- * @deprecated This method has been deprecated. Please use Image_alpha.
- * @see Image_alpha_eq
- * @see Image_alpha
- */
-VALUE
-Image_matte_eq(VALUE self, VALUE matte)
-{
- VALUE alpha_channel_type;
-
- if (RTEST(matte))
- {
- alpha_channel_type = rb_const_get(Module_Magick, rb_intern("ActivateAlphaChannel"));
- }
- else
- {
- alpha_channel_type = rb_const_get(Module_Magick, rb_intern("DeactivateAlphaChannel"));
- }
-
- rb_warning("Image#matte= is deprecated; use Image#alpha.");
-
- return Image_alpha_eq(self, alpha_channel_type);
-}
-
-
-/**
* Return the matte color.
*
* Ruby usage:
* - @verbatim Image#matte_color @endverbatim
*
@@ -8829,39 +8499,29 @@
long x, y;
PaintMethod method;
DrawInfo *draw_info;
MagickPixel target_mpp;
MagickBooleanType invert;
- int start_index;
image = rm_check_destroyed(self);
if (argc != 5)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 5)", argc);
}
- if (TYPE(argv[4]) == T_HASH)
- {
- alpha = get_alpha_from_hash(argv[4]);
- start_index = 1;
- }
- else
- {
- alpha = get_alpha_from_opacity(argv[1]);
- start_index = 2;
- }
+ alpha = get_named_alpha_value(argv[4]);
Color_to_PixelColor(&target, argv[0]);
- VALUE_TO_ENUM(argv[start_index + 2], method, PaintMethod);
+ VALUE_TO_ENUM(argv[3], method, PaintMethod);
if (!(method == FloodfillMethod || method == FillToBorderMethod))
{
rb_raise(rb_eArgError, "paint method_obj must be FloodfillMethod or "
"FillToBorderMethod (%d given)", method);
}
- x = NUM2LONG(argv[start_index]);
- y = NUM2LONG(argv[start_index + 1]);
+ x = NUM2LONG(argv[1]);
+ y = NUM2LONG(argv[2]);
if ((unsigned long)x > image->columns || (unsigned long)y > image->rows)
{
rb_raise(rb_eArgError, "target out of range. %ldx%ld given, image is %lux%lu"
, x, y, image->columns, image->rows);
}
@@ -9323,12 +8983,10 @@
else if (argc == 1)
{
grayscale = RTEST(argv[0]);
}
- Data_Get_Struct(self, Image, image);
-
new_image = rm_clone_image(image);
(void) NegateImageChannel(new_image, channels, grayscale);
rm_check_image_exception(new_image, DestroyOnError);
@@ -9966,18 +9624,11 @@
else
{
invert = RTEST(argv[2]);
}
case 2:
- if (TYPE(argv[argc - 1]) == T_HASH)
- {
- alpha = get_alpha_from_hash(argv[argc - 1]);
- }
- else
- {
- alpha = get_alpha_from_opacity(argv[1]);
- }
+ alpha = get_named_alpha_value(argv[argc - 1]);
case 1:
Color_to_MagickPixel(image, &color, argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 4)", argc);
@@ -10529,10 +10180,13 @@
qop = UniformNoiseEvaluateOperator;
break;
case CosineQuantumOperator:
qop = CosineEvaluateOperator;
break;
+ case SetQuantumOperator:
+ qop = SetEvaluateOperator;
+ break;
case SineQuantumOperator:
qop = SineEvaluateOperator;
break;
case AddModulusQuantumOperator:
qop = AddModulusEvaluateOperator;
@@ -12094,37 +11748,10 @@
return rm_image_new(new_image);
}
/**
- * Call SetImageOpacity.
- *
- * Ruby usage:
- * - @verbatim Image#opacity= @endverbatim
- *
- * @param self this object
- * @param opacity_arg the opacity
- * @return opacity_arg
- * @deprecated This method has been deprecated. Please use Image_alpha.
- */
-VALUE
-Image_opacity_eq(VALUE self, VALUE opacity_arg)
-{
- Image *image;
- Quantum opacity;
-
- rb_warning("Image#opacity is deprecated; use Image#alpha");
-
- image = rm_check_frozen(self);
- opacity = APP2QUANTUM(opacity_arg);
- (void) SetImageOpacity(image, opacity);
- rm_check_image_exception(image, RetainOnError);
- return opacity_arg;
-}
-
-
-/**
* Traverse the attributes and yield to the block. If no block, return a hash
* of all the attribute keys & values.
*
* Ruby usage:
* - @verbatim Image#properties [{ |k,v| block }] @endverbatim
@@ -13244,34 +12871,10 @@
return rm_image_new(new_image);
}
/**
- * Synchronize image properties with the image profiles.
- *
- * Ruby usage:
- * - @verbatim Image#sync_profiles @endverbatim
- *
- * @param self this object
- * @return true if succeeded, otherwise false
- * @deprecated This method has been deprecated.
- */
-VALUE
-Image_sync_profiles(VALUE self)
-{
- rb_warning("Image#sync_profiles is deprecated");
- Image *image = rm_check_destroyed(self);
- VALUE okay = SyncImageProfiles(image) ? Qtrue : Qfalse;
- rm_check_image_exception(image, RetainOnError);
-
- RB_GC_GUARD(okay);
-
- return okay;
-}
-
-
-/**
* Emulates Magick++'s floodFillTexture.
*
* If the FloodfillMethod method is specified, flood-fills texture across pixels
* starting at the target pixel and matching the specified color.
*
@@ -13965,18 +13568,11 @@
else
{
invert = RTEST(argv[2]);
}
case 3:
- if (TYPE(argv[argc - 1]) == T_HASH)
- {
- alpha = get_alpha_from_hash(argv[argc - 1]);
- }
- else
- {
- alpha = get_alpha_from_opacity(argv[2]);
- }
+ alpha = get_named_alpha_value(argv[argc - 1]);
case 2:
Color_to_MagickPixel(image, &high, argv[1]);
Color_to_MagickPixel(image, &low, argv[0]);
break;
default:
@@ -15228,11 +14824,10 @@
nx = image->columns - columns - nx;
break;
case NorthGravity:
case SouthGravity:
case CenterGravity:
- case StaticGravity:
nx += image->columns/2 - columns/2;
break;
default:
break;
}
@@ -15244,11 +14839,10 @@
ny = image->rows - rows - ny;
break;
case EastGravity:
case WestGravity:
case CenterGravity:
- case StaticGravity:
ny += image->rows/2 - rows/2;
break;
case NorthEastGravity:
case NorthGravity:
default:
@@ -15310,10 +14904,9 @@
break;
case SouthEastGravity:
nx = image->columns - columns;
ny = image->rows - rows;
break;
- case StaticGravity:
case CenterGravity:
nx = (image->columns - columns) / 2;
ny = (image->rows - rows) / 2;
break;
}