Class: Magick::Image
- Inherits:
-
Object
- Object
- Magick::Image
- Includes:
- Comparable
- Defined in:
- lib/RMagick.rb,
ext/RMagick/rmmain.c
Overview
Ruby-level Magick::Image methods
Defined Under Namespace
Classes: DrawOptions, Info, PolaroidOptions, View
Class Method Summary collapse
-
._load(str) ⇒ Object
Method: Image._load Purpose: implement marshalling Notes: calls BlobToImage - see Image#_dump.
-
.capture(*args) ⇒ Object
Method: Image.capture(silent=false, frame=false, descend=false, screen=false, borders=false) { optional parms } Purpose: do a screen capture.
- .combine ⇒ Object
-
.constitute(width_arg, height_arg, map_arg, pixels_arg) ⇒ Object
Method: Image.constitute(width, height, map, pixels) Purpose: Creates an Image from the supplied pixel data.
-
.from_blob(blob_arg) ⇒ Object
Method: Image.from_blob(blob) <{ parm block }> Purpose: Call BlobToImage Notes: The blob is a String.
-
.ping(file_arg) ⇒ Object
Method: Image.ping(file) Purpose: Call ImagePing Returns: Same as Image.read, except that PingImage does not return the pixel data.
-
.read(file_arg) ⇒ Object
Method: Image.read(file) Purpose: Call ReadImage Returns: An array of 1 or more new image objects.
-
.read_inline(content) ⇒ Object
Method: Image.read_inline(content) Purpose: Read a Base64-encoded image Returns: an array of new images Notes: this is similar to, but not the same as ReadInlineImage.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Method: Image#spaceship (a <=> b) Purpose: compare two images Returns: -1, 0, 1.
- #[](key_arg) ⇒ Object
- #[]=(key_arg, attr_arg) ⇒ Object
-
#_dump(depth) ⇒ Object
Method: Image#_dump(aDepth) Purpose: implement marshalling Returns: a string representing the dumped image Notes: uses ImageToBlob - use the MIFF format in the blob since it’s the most general.
-
#adaptive_blur(*args) ⇒ Object
Method: Image#adaptive_blur(radius=0.0, sigma=1.0) Purpose: call AdaptiveBlurImage.
-
#adaptive_blur_channel(*args) ⇒ Object
Method: Image#adaptive_blur_channel(radius=0.0, sigma=1.0[ , channel…]) Purpose: call AdaptiveBlurImageChannel.
-
#adaptive_resize(*args) ⇒ Object
Method: Image#adaptive_resize(scale_val) Image#adaptive_resize(cols, rows) Purpose: Call AdaptiveResizeImage.
-
#adaptive_sharpen(*args) ⇒ Object
Method: Image#adaptive_sharpen(radius=0.0, sigma=1.0) Purpose: call AdaptiveSharpenImage.
-
#adaptive_sharpen_channel(*args) ⇒ Object
Method: Image#adaptive_sharpen_channel(radius=0.0, sigma=1.0[, channel…]) Purpose: Call AdaptiveSharpenImageChannel.
-
#adaptive_threshold(*args) ⇒ Object
Method: Image#adaptive_threshold(width=3, height=3, offset=0) Purpose: selects an individual threshold for each pixel based on the range of intensity values in its local neighborhood.
-
#add_compose_mask(mask) ⇒ Object
Method: Image#add_compose_mask(mask) Purpose: Set the image composite mask Ref: SetImageMask Notes: Returns self See also: Image#mask(), #delete_compose_mask().
-
#add_noise(noise) ⇒ Object
Method: Image#add_noise(noise_type) Purpose: add random noise to a copy of the image Returns: a new image.
-
#add_noise_channel(*args) ⇒ Object
Method: Image#add_noise_channel(noise_type) Purpose: add random noise to a copy of the image Returns: a new image.
-
#add_profile(name) ⇒ Object
Method: Image#add_profile(name) Purpose: adds all the profiles in the specified file Notes: ‘name’ is the profile filename.
-
#affine_transform(affine) ⇒ Object
Method: Image#affine_transform(affine_matrix) Purpose: transforms an image as dictated by the affine matrix argument Returns: a new image.
-
#alpha(*args) ⇒ Object
Method: Image#alpha(type) Purpose: Calls SetImageAlphaChannel Notes: Replaces matte=, alpha= Originally there was an alpha attribute getter and setter.
-
#alpha? ⇒ Boolean
Method: Image#alpha? Returns: true if the image’s alpha channel is activated Notes: Replaces Image#matte.
-
#annotate(draw, width, height, x, y, text, &block) ⇒ Object
Provide an alternate version of Draw#annotate, for folks who want to find it in this class.
- #auto_gamma_channel(*args) ⇒ Object
- #auto_level_channel(*args) ⇒ Object
- #auto_orient ⇒ Object
-
#auto_orient! ⇒ Object
Returns nil if the image is already properly oriented.
-
#bilevel_channel(*args) ⇒ Object
Method: Image#bilevel_channel(threshold, channel=AllChannels) Returns a new image.
-
#black_threshold(*args) ⇒ Object
Method: Image#black_threshold(red_channel [, green_channel [, blue_channel [, opacity_channel]]]); Purpose: Call BlackThresholdImage.
-
#blend(*args) ⇒ Object
Method: Image#blend(overlay, src_percent, dst_percent, x_offset=0, y_offset=0) Image#dissolve(overlay, src_percent, dst_percent, gravity, x_offset=0, y_offset=0) Purpose: Corresponds to the composite -blend operation Notes: ‘percent’ can be a number or a string in the form “NN%” The default value for dst_percent is 100.0-src_percent.
-
#blue_shift(*args) ⇒ Object
Method: Image#blue_shift(factor=1.5) Purpose: Call BlueShiftImage.
- #blur_channel ⇒ Object
-
#blur_image(*args) ⇒ Object
Method: Image#blur_image(radius=0.0, sigma=1.0) Purpose: Blur the image Notes: The “blur” name is used for the attribute.
- #border(width, height, color) ⇒ Object
- #border!(width, height, color) ⇒ Object
-
#change_geometry(geom_arg) ⇒ Object
Method: Image#change_geometry(geometry_string) { |cols, rows, image| } Purpose: parse geometry string, compute new image geometry.
-
#change_geometry!(geom_arg) ⇒ Object
Method: Image#change_geometry(geometry_string) { |cols, rows, image| } Purpose: parse geometry string, compute new image geometry.
-
#changed? ⇒ Boolean
Method: Image#changed? Purpose: Return true if any pixel in the image has been altered since the image was constituted.
-
#channel(channel_arg) ⇒ Object
Method: Image#channel Purpose: Extract a channel from the image.
-
#channel_compare(*args) ⇒ Object
Method: Image#compare_channel(ref_image, metric [, channel…]) { optional arguments } Purpose: compares one or more channels in two images and returns the specified distortion metric and a comparison image.
-
#channel_depth(*args) ⇒ Object
Method: Image#channel_depth(channel_depth=AllChannels) Purpose: GetImageChannelDepth.
-
#channel_extrema(*args) ⇒ Object
Method: Image#channel_extrema(channel=AllChannels) Purpose: Returns an array [min, max] where ‘min’ and ‘max’ are the minimum and maximum values of all channels.
-
#channel_mean(*args) ⇒ Object
Method: Image#channel_mean(channel=AllChannels) Returns An array [mean, std. deviation].
-
#charcoal(*args) ⇒ Object
Method: Image#charcoal(radius=0.0, sigma=1.0) Purpose: Return a new image that is a copy of the input image with the edges highlighted.
-
#check_destroyed ⇒ Object
Method: Image#check_destroyed Purpose: If the target image has been destroyed, raises Magick::DestroyedImageError.
-
#chop(x, y, width, height) ⇒ Object
Method: Image#chop Purpose: removes a region of an image and collapses the image to occupy the removed portion.
-
#clone ⇒ Object
Method: Image#clone Purpose: Copy an image, along with its frozen and tainted state.
-
#clut_channel(*args) ⇒ Object
Method: Image#clut_channel Purpose: Equivalent to -clut option.
-
#color_fill_to_border(x, y, fill) ⇒ Object
Set all pixels that are neighbors of x,y and are not the border color to the fill color.
-
#color_flood_fill(target_color, fill_color, xv, yv, method) ⇒ Object
Method: Image#color_flood_fill(target_color, fill_color, x, y, method) Purpose: changes the color value of any pixel that matches target_color and is an immediate neighbor.
-
#color_floodfill(x, y, fill) ⇒ Object
Set all pixels that have the same color as the pixel at x,y and are neighbors to the fill color.
-
#color_histogram ⇒ Object
Method: Image_color_histogram(VALUE self); Purpose: Call GetImageHistogram Notes: returns hash aPixel=>count.
-
#color_point(x, y, fill) ⇒ Object
Set the color at x,y.
-
#color_reset!(fill) ⇒ Object
Set all pixels to the fill color.
-
#colorize(*args) ⇒ Object
Method: Image#colorize(r, g, b, target) Purpose: blends the fill color specified by “target” with each pixel in the image.
-
#colormap(*args) ⇒ Object
Method: Image#colormap(index<, new-color>) Purpose: return the color in the colormap at the specified index.
-
#compare_channel(*args) ⇒ Object
Method: Image#compare_channel(ref_image, metric [, channel…]) { optional arguments } Purpose: compares one or more channels in two images and returns the specified distortion metric and a comparison image.
- #composite(*args) ⇒ Object
- #composite!(*args) ⇒ Object
-
#composite_affine(source, affine_matrix) ⇒ Object
Method: Image#composite_affine(composite, affine_matrix) Purpose: composites the source over the destination image as dictated by the affine transform.
- #composite_channel(*args) ⇒ Object
- #composite_channel!(*args) ⇒ Object
-
#composite_mathematics(*args) ⇒ Object
Method: Image#composite_mathematics img.composite_mathematics(comp_img, A, B, C, D, gravity) img.composite_mathematics(comp_img, A, B, C, D, x_off, y_off) img.composite_mathematics(comp_img, A, B, C, D, gravity, x_off, y_off) Purpose: Composite using MathematicsCompositeOp Notes: New in 6.5.4-3.
- #composite_tiled(*args) ⇒ Object
- #composite_tiled!(*args) ⇒ Object
-
#compress_colormap! ⇒ Object
Method: Image#compress_colormap! Purpose: call CompressImageColormap Notes: API was CompressColormap until 5.4.9.
-
#contrast(*args) ⇒ Object
Method: Image#contrast(<sharpen>) Purpose: enhances the intensity differences between the lighter and darker elements of the image.
-
#contrast_stretch_channel(*args) ⇒ Object
Method: Image#contrast_stretch_channel(black_point <, white_point> <, channel…>) Purpose: Call ContrastStretchImageChannel Notes: If white_point is not specified then it is #pixels-black_point.
-
#convolve(order_arg, kernel_arg) ⇒ Object
Method: Image#convolve(order, kernel) Purpose: apply a custom convolution kernel to the image Notes: “order” is the number of rows and columns in the kernel “kernel” is an order**2 array of doubles.
-
#convolve_channel(*args) ⇒ Object
Method: Image#convolve_channel(order, kernel[, channel[, channel…]]) Purpose: call ConvolveImageChannel.
-
#copy ⇒ Object
Method: Image#copy Purpose: Alias for dup.
-
#crop(*args) ⇒ Object
Method: Image#crop(x, y, width, height) Image#crop(gravity, width, height) Image#crop!(x, y, width, height) Image#crop!(gravity, width, height) Purpose: Extract a region of the image defined by width, height, x, y.
- #crop!(*args) ⇒ Object
-
#cur_image ⇒ Object
Used by ImageList methods - see ImageList#cur_image.
-
#cycle_colormap(amount) ⇒ Object
Method: Image#cycle_colormap Purpose: Call CycleColormapImage.
-
#decipher(passphrase) ⇒ Object
Method: Image#decipher(passphrase) Purpose: call DecipherImage.
-
#define(artifact, value) ⇒ Object
Method: value = Image#define(artifact, value) Purpose: Call SetImageArtifact Note: Normally a script should never call this method.
- #delete_compose_mask ⇒ Object
-
#delete_profile(name) ⇒ Object
Method: Image#delete_profile(name) Purpose: call ProfileImage Notes: name is the name of the profile to be deleted.
-
#deskew(*args) ⇒ Object
Method: Image#deskew(threshold=0.40, auto-crop-width) Purpose: Implement convert -deskew option.
-
#despeckle ⇒ Object
Method: Image#despeckle Purpose: reduces the speckle noise in an image while preserving the edges of the original image Returns: a new image.
-
#destroy! ⇒ Object
Method: Image#destroy! Purpose: Free all the memory associated with an image.
-
#destroyed? ⇒ Boolean
Method: Image#destroyed? Purpose: Returns true if the image has been destroyed, false otherwise.
-
#difference(other) ⇒ Object
Method: Image#difference Purpose: Call the IsImagesEqual function Returns: An array with 3 values: [0] mean error per pixel [1] normalized mean error [2] normalized maximum error Notes: “other” can be either an Image or an Image.
-
#dispatch(*args) ⇒ Object
Method: Image#dispatch(x, y, columns, rows, map <, float>) Purpose: Extracts pixel data from the image and returns it as an array of pixels.
- #displace ⇒ Object
-
#display ⇒ Object
(also: #__display__)
Method: Image#display Purpose: display the image to an X window screen.
-
#dissolve(*args) ⇒ Object
Method: Image#dissolve(overlay, src_percent, dst_percent, x_offset=0, y_offset=0) Image#dissolve(overlay, src_percent, dst_percent, gravity, x_offset=0, y_offset=0) Purpose: Corresponds to the composite_image -dissolve operation Notes: ‘percent’ can be a number or a string in the form “NN%” The “default” value of dst_percent is -1.0, which tells blend_geometry to leave it out of the geometry string.
-
#distort(*args) ⇒ Object
Method: Image#distort(type, points, bestfit=false) { optional arguments } Purpose: Call DistortImage Notes: points is an Array of Numeric values optional arguments are self.define “distort:viewport”, WxH+X+Y self.define “distort:scale”, N self.verbose true.
-
#distortion_channel(*args) ⇒ Object
Method: Image#distortion_channel(reconstructed_image, metric[, channel…]) Purpose: Call GetImageChannelDistortion.
-
#dup ⇒ Object
Method: Image#dup Purpose: Construct a new image object and call initialize_copy.
-
#each_iptc_dataset ⇒ Object
Iterate over IPTC record number:dataset tags, yield for each non-nil dataset.
-
#each_pixel ⇒ Object
Thanks to Russell Norris!.
-
#each_profile ⇒ Object
Method: Image#each_profile Purpose: Iterate over image profiles Notes: ImageMagick only.
-
#edge(*args) ⇒ Object
Method: Image#edge(radius=0) Purpose: finds edges in an image.
-
#emboss(*args) ⇒ Object
Method: Image#emboss(radius=0.0, sigma=1.0) Purpose: creates a grayscale image with a three-dimensional effect.
-
#encipher(passphrase) ⇒ Object
Method: Image#encipher(passphrase) Purpose: call EncipherImage.
-
#enhance ⇒ Object
Method: Image#enhance Purpose: applies a digital filter that improves the quality of a noisy image.
-
#equalize ⇒ Object
Method: Image#equalize Purpose: applies a histogram equalization to the image.
-
#equalize_channel(*args) ⇒ Object
Method: Image#equalize_channel Purpose: call EqualizeImageChannel.
-
#erase! ⇒ Object
Method: Image#erase! Purpose: reset the image to the background color Notes: one of the very few Image methods that do not return a new image.
- #excerpt(x, y, width, height) ⇒ Object
- #excerpt!(x, y, width, height) ⇒ Object
-
#export_pixels(*args) ⇒ Object
Method: Image#export_pixels(x=0, y=0, cols=self.columns, rows=self.rows, map=“RGB”) Purpose: extract image pixels in the form of an array.
-
#export_pixels_to_str(*args) ⇒ Object
Method: Image#export_pixels_to_str(x=0, y=0, cols=self.columns, rows=self.rows, map=“RGB”, type=Magick::CharPixel) Purpose: extract image pixels to a Ruby string.
-
#extent(*args) ⇒ Object
Method: Image#extent(width, height, x=0, y=0) Purpose: Call ExtentImage.
-
#find_similar_region(*args) ⇒ Object
Method: Image#find_similar_region(target, x=0, y=0) Purpose: Search for a region in the image that is “similar” to the target image.
- #flip ⇒ Object
- #flip! ⇒ Object
-
#flop ⇒ Object
Method: Image#flop Image#flop! Purpose: creates a horizontal mirror image by reflecting the pixels around the central y-axis Returns: flop: a new, flopped image flop!: self, flopped.
- #flop! ⇒ Object
-
#frame(*args) ⇒ Object
Method: Image#frame(<width<, height<, x<, y<, inner_bevel<, outer_bevel <, color>>>>>>>) Purpose: adds a simulated three-dimensional border around the image.
-
#function_channel(*args) ⇒ Object
Method: Image#function_channel(function, args[, channel…]).
- #gamma_channel ⇒ Object
-
#gamma_correct(*args) ⇒ Object
Method: Image#gamma_correct(red_gamma<, green_gamma<, blue_gamma>>>) Purpose: gamma-correct an image Notes: At least red_gamma must be specified.
-
#gaussian_blur(*args) ⇒ Object
Method: Image#gaussian_blur(radius, sigma) Purpose: blur the image Returns: a new image.
-
#gaussian_blur_channel(*args) ⇒ Object
Method: Image#gaussian_blur_channel(radius=0, sigma=1, channel=AllChannels) Notes: new in IM 6.0.0.
-
#get_exif_by_entry(*entry) ⇒ Object
Retrieve EXIF data by entry or all.
-
#get_exif_by_number(*tag) ⇒ Object
Retrieve EXIF data by tag number or all tag/value pairs.
-
#get_iptc_dataset(ds) ⇒ Object
Retrieve IPTC information by record number:dataset tag constant defined in Magick::IPTC, above.
-
#get_pixels(x_arg, y_arg, cols_arg, rows_arg) ⇒ Object
Method: Image#get_pixels(x, y, columns. rows) Purpose: Call AcquireImagePixels Returns: An array of Magick::Pixel objects corresponding to the pixels in the rectangle defined by the geometry parameters.
-
#gray? ⇒ Boolean
Method: Image#gray? Purpose: return true if all the pixels in the image have the same red, green, and blue intensities.
-
#grey? ⇒ Boolean
Method: Image#gray? Purpose: return true if all the pixels in the image have the same red, green, and blue intensities.
-
#histogram? ⇒ Boolean
Method: Image#histogram? Purpose: return true if has 1024 unique colors or less.
-
#implode(*args) ⇒ Object
Method: Image#implode(amount=0.50) Purpose: implode the image by the specified percentage Returns: a new image.
-
#import_pixels(*args) ⇒ Object
Method: Image#import_pixels Purpose: store image pixel data from an array Notes: See Image#export_pixels.
-
#initialize(*args) ⇒ Object
constructor
Method: Image#initialize(cols,rows,) Purpose: initialize a new Image object If the fill argument is omitted, fill with background color.
-
#initialize_copy(orig) ⇒ Object
Method: Image#initialize_copy Purpose: initialize copy, clone, dup.
- #inspect ⇒ Object
-
#level(black_point = 0.0, white_point = nil, gamma = nil) ⇒ Object
(Thanks to Al Evans for the suggestion.).
- #level2 ⇒ Object
-
#level_channel(*args) ⇒ Object
Method: Image#level_channel(aChannelType, black=0, white=QuantumRange, gamma=1.0) Purpose: similar to Image#level but applies to a single channel only Notes: black and white are 0-QuantumRange, gamma is 0-10.
-
#level_colors(*args) ⇒ Object
Method: Image#level_colors(black_color=“black”, white_color=“white”, invert=true [, channel…]) Purpose: Implement +level_colors blank_color,white_color.
-
#levelize_channel(*args) ⇒ Object
Method: Image#levelize_channel(black_point[, white_point[, gamma=1.0[, channel…]]).
-
#linear_stretch(*args) ⇒ Object
Method: Image_linear_stretch(black_point <, white_point>) Purpose: Call LinearStretchImage Notes: The default for white_point is #pixels-black_point.
-
#liquid_rescale(*args) ⇒ Object
Method: Image#liquid_rescale(columns, rows, delta_x=0.0, rigidity=0.0) Purpose: Call the LiquidRescaleImage API.
- #magnify ⇒ Object
- #magnify! ⇒ Object
-
#map(*args) ⇒ Object
Method: Image#map(map_image, dither=false) Purpose: Call MapImage Returns: a new image.
-
#marshal_dump ⇒ Object
Method: Image#marshal_dump Purpose: Support Marshal.dump >= 1.8 Returns: [img.filename, img.to_blob].
-
#marshal_load(ary) ⇒ Object
Method: Image#marshal_load Purpose: Support Marshal.load >= 1.8 Notes: On entry, ary is the array returned from marshal_dump.
-
#mask(*args) ⇒ Object
Method: Image#mask() Purpose: associates a clip mask with the image Returns: Copy of the current clip-mask Notes: Omit the argument to get a copy of the current clip mask.
-
#matte_fill_to_border(x, y) ⇒ Object
Make transparent any neighbor pixel that is not the border color.
-
#matte_flood_fill(color, opacity, x_obj, y_obj, method_obj) ⇒ Object
Method: Image#matte_flood_fill(color, opacity, x, y, method_obj) Purpose: Call MatteFloodFillImage.
-
#matte_floodfill(x, y) ⇒ Object
Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.
-
#matte_point(x, y) ⇒ Object
Make the pixel at (x,y) transparent.
-
#matte_replace(x, y) ⇒ Object
Make transparent all pixels that are the same color as the pixel at (x, y).
-
#matte_reset! ⇒ Object
Make all pixels transparent.
-
#median_filter(*args) ⇒ Object
Method: Image#median_filter(radius=0.0) Purpose: applies a digital filter that improves the quality of a noisy image.
-
#minify ⇒ Object
Method: Image#minify Image#minify! Purpose: Scales an image proportionally to half its size Returns: minify: a new image 1/2x the size of the input image minify!: self, 1/2x.
- #minify! ⇒ Object
-
#modulate(*args) ⇒ Object
Method: Image#modulate(<brightness<, saturation<, hue>>>) Purpose: control the brightness, saturation, and hue of an image Notes: all three arguments are optional and default to 100%.
-
#monochrome? ⇒ Boolean
Method: Image#monochrome? Purpose: return true if all the pixels in the image have the same red, green, and blue intensities and the intensity is either 0 or QuantumRange.
-
#motion_blur(*args) ⇒ Object
Method: Image#motion_blur(radius=0.0, sigma=1.0, angle=0.0) Purpose: simulates motion blur.
-
#negate(*args) ⇒ Object
Method: Image#negate(grayscale=false) Purpose: negates the colors in the reference image.
-
#negate_channel(*args) ⇒ Object
Method: Image#negate_channel(grayscale=false, channel=AllChannels) Returns a new image.
-
#normalize ⇒ Object
Method: Image#normalize Purpose: enhances the contrast of a color image by adjusting the pixels color to span the entire range of colors available.
-
#normalize_channel(*args) ⇒ Object
Method: Image#normalize_channel(channel=AllChannels) Purpose: Call NormalizeImageChannel.
- #oil_paint ⇒ Object
-
#opaque(target, fill) ⇒ Object
Method: Image#opaque(target-color-name, fill-color-name) Image#opaque(target-pixel, fill-pixel) Purpose: changes any pixel that matches target with the color defined by fill Notes: By default a pixel must match the specified target color exactly.
-
#opaque? ⇒ Boolean
Method: Image#opaque? Purpose: return true if any of the pixels in the image have an opacity value other than opaque ( 0 ).
-
#opaque_channel(*args) ⇒ Object
Method: Image#opaque_channel Purpose: Improved Image#opaque available in 6.3.7-10 Notes: opaque_channel(target, fill, invert=false, fuzz=img.fuzz [, channel…]).
-
#ordered_dither(*args) ⇒ Object
Method: Image#ordered_dither(threshold_map=‘2x2’) Purpose: perform ordered dither on image Notes: order must be 2, 3, or 4 (6.3.0) order can be any of the threshold strings listed by “convert -list Thresholds” but the default is still “2x2”.
-
#paint_transparent(*args) ⇒ Object
Method: Image#paint_transparent(target, opacity=TransparentOpacity, invert=false, fuzz=img.fuzz) Purpose: Improved version of Image#transparent available in 6.3.7-10.
-
#palette? ⇒ Boolean
Method: Image#palette? Purpose: return true if the image is PseudoClass and has 256 unique colors or less.
-
#pixel_color(*args) ⇒ Object
Method: Image#pixel_color(x, y<, color>) Purpose: Gets/sets the color of the pixel at x,y Returns: Magick::Pixel for pixel x,y.
-
#polaroid(*args) ⇒ Object
Method: Image#polaroid() Purpose: Call PolaroidImage Notes: Accepts an options block to get Draw attributes for drawing the label.
-
#posterize(*args) ⇒ Object
Method: posterize Purpose: call PosterizeImage Notes: Image#posterize(levels=4, dither=false).
-
#preview(preview) ⇒ Object
Method: preview Purpose: Call PreviewImage.
-
#profile!(name, profile) ⇒ Object
Method: Image#profile!(name, profile) Purpose: If “profile” is nil, deletes the profile.
-
#properties ⇒ Object
Method: Image#properties [{ |k,v| block }] Purpose: Traverse the attributes and yield to the block.
-
#quantize(*args) ⇒ Object
Method: Image#quantize(<number_colors<, colorspace<, dither<, tree_depth<, measure_error>>>>>) defaults: 256, Magick::RGBColorspace, true, 0, false Purpose: call QuantizeImage.
-
#quantum_operator(*args) ⇒ Object
Method: Image#quantum_operator(operator, rvalue[, channel] ) Purpose: This method is an adapter method that calls the EvaluateImageChannel method Note 1: Historically this method used QuantumOperatorRegionImage in GraphicsMagick.
-
#radial_blur(angle) ⇒ Object
Method: Image#radial_blur(angle) Purpose: Call RadialBlurImage Notes: Angle is in degrees.
-
#radial_blur_channel(*args) ⇒ Object
Method: Image#radial_blur_channel(angle[, channel..]) Purpose: Call RadialBlurImageChannel Notes: Angle is in degrees.
-
#raise(*args) ⇒ Object
Method: Image#raise(width=6, height=6, raised=true) Purpose: creates a simulated three-dimensional button-like effect by lightening and darkening the edges of the image.
-
#random_threshold_channel(*args) ⇒ Object
Method: Image#random_threshold_channel PUrpose: Call RandomThresholdImageChannel.
-
#recolor(color_matrix) ⇒ Object
Method: Image#recolor(matrix) Purpose: Call RecolorImage.
-
#reduce_noise(radius) ⇒ Object
Method: Image#reduce_noise(radius) Purpose: smooths the contours of an image while still preserving edge information Returns: a new image.
-
#remap(*args) ⇒ Object
(also: #affinity)
Method: Image#remap(remap_image, dither_method=RiemersmaDitherMethod) Purpose: Call RemapImage Notes: Immediate - modifies image in-place.
-
#resample(x_res = 72.0, y_res = nil) ⇒ Object
Corresponds to ImageMagick’s -resample option.
- #resize(*args) ⇒ Object
- #resize!(*args) ⇒ Object
-
#resize_to_fill(ncols, nrows = nil, gravity = CenterGravity) ⇒ Object
(also: #crop_resized)
Force an image to exact dimensions without changing the aspect ratio.
- #resize_to_fill!(ncols, nrows = nil, gravity = CenterGravity) ⇒ Object (also: #crop_resized!)
-
#resize_to_fit(cols, rows = nil) ⇒ Object
Convenience method to resize retaining the aspect ratio.
- #resize_to_fit!(cols, rows = nil) ⇒ Object
-
#roll(x_offset, y_offset) ⇒ Object
Method: Image#roll(x_offset, y_offset) Purpose: offsets an image as defined by x_offset and y_offset Returns: a rolled copy of the input image.
- #rotate(*args) ⇒ Object
- #rotate!(*args) ⇒ Object
- #sample ⇒ Object
- #sample!(*args) ⇒ Object
-
#scale(*args) ⇒ Object
Method: Image#scale(scale) or (cols, rows) Image#scale! Purpose: changes the size of an image to the given dimensions Returns: scale: a scaled copy of the input image scale!: self, scaled.
- #scale!(*args) ⇒ Object
-
#segment(*args) ⇒ Object
Method: Image#segment(colorspace=RGBColorspace, cluster_threshold=1.0, smoothing_threshold=1.5, verbose=false) Purpose: Call SegmentImage Notes: the default values are the same as Magick++.
- #selective_blur_channel ⇒ Object
-
#separate(*args) ⇒ Object
Method: separate(channel[, channel…]) Purpose: call SeparateImages Returns: returns a new ImageList.
-
#sepiatone(*args) ⇒ Object
Method: Image#sepiatone(threshold=QuantumRange) Purpose: Call SepiaToneImage.
-
#set_channel_depth(channel_arg, depth) ⇒ Object
Method: Image#set_channel_depth(channel, depth) Purpose: Call SetImageChannelDepth.
-
#shade(*args) ⇒ Object
Method: Image#shade(shading=false, azimuth=30, elevation=30) Purpose: shines a distant light on an image to create a three-dimensional effect.
-
#shadow(*args) ⇒ Object
Method: Image#shadow(x_offset=4, y_offset=4, sigma=4.0, opacity=1.0) x- and y-offsets are the pixel offset opacity is either a number between 0 and 1 or a string “NN%” sigma is the std.
-
#sharpen(*args) ⇒ Object
Method: Image#sharpen(radius=0, sigma=1) Purpose: sharpens an image Returns: a new image.
-
#sharpen_channel(*args) ⇒ Object
Method: Image#sharpen_channel(radius=0, sigma=1, channel=AllChannels) Returns: a new image.
-
#shave(width, height) ⇒ Object
Method: Image#shave(width, height) Image#shave!(width, height) Purpose: shaves pixels from the image edges, leaving a rectangle of the specified width & height in the center Returns: shave: a new image shave!: self, shaved.
- #shave!(width, height) ⇒ Object
-
#shear(x_shear, y_shear) ⇒ Object
Method: Image#shear(x_shear, y_shear) Purpose: Calls ShearImage Notes: shear angles are measured in degrees Returns: a new image.
-
#sigmoidal_contrast_channel(*args) ⇒ Object
Method: Image#sigmoidal_contrast_channel(contrast=3.0, midpoint=50.0, sharpen=false [, channel=AllChannels]);.
-
#signature ⇒ Object
Method: Image#signature Purpose: computes a message digest from an image pixel stream with an implementation of the NIST SHA-256 Message Digest algorithm.
-
#sketch(*args) ⇒ Object
Method: Image#sketch(radius=0.0, sigma=1.0, angle=0.0) Purpose: Call SketchImage.
-
#solarize(*args) ⇒ Object
Method: Image#solarize(threshold=50.0) Purpose: applies a special effect to the image, similar to the effect achieved in a photo darkroom by selectively exposing areas of photo sensitive paper to light.
- #sparse_color(*args) ⇒ Object
-
#splice(*args) ⇒ Object
Method: Image#splice(x, y, width, height[, color]) Purpose: Splice a solid color into the part of the image specified by the x, y, width, and height arguments.
-
#spread(*args) ⇒ Object
Method: Image#spread(radius=3) Purpose: randomly displaces each pixel in a block defined by “radius” Returns: a new image.
- #stegano ⇒ Object
-
#stereo(offset_image_arg) ⇒ Object
Method: Image#stereo(offset_image) Purpose: combines two images and produces a single image that is the composite of a left and right image of a stereo pair.
-
#store_pixels(x_arg, y_arg, cols_arg, rows_arg, new_pixels) ⇒ Object
Method: Image#store_pixels Purpose: Replace the pixels in the specified rectangle Notes: Calls GetImagePixels, then SyncImagePixels after replacing the pixels.
-
#strip! ⇒ Object
Method: Image#strip! Purpose: strips an image of all profiles and comments.
-
#swirl(degrees) ⇒ Object
Method: Image#swirl(degrees) Purpose: swirls the pixels about the center of the image, where degrees indicates the sweep of the arc through which each pixel is moved.
-
#sync_profiles ⇒ Object
Method: Image#sync_profiles() Purpose: synchronizes image properties with the image profiles.
-
#texture_fill_to_border(x, y, texture) ⇒ Object
Replace neighboring pixels to border color with texture pixels.
-
#texture_flood_fill(color_obj, texture_obj, x_obj, y_obj, method_obj) ⇒ Object
Method: Image#texture_flood_fill(color, texture, x, y, method) Purpose: 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.
-
#texture_floodfill(x, y, texture) ⇒ Object
Replace matching neighboring pixels with texture pixels.
-
#threshold(threshold) ⇒ Object
Method: Image#threshold(threshold) Purpose: changes the value of individual pixels based on the intensity of each pixel compared to threshold.
- #thumbnail(*args) ⇒ Object
- #thumbnail!(*args) ⇒ Object
-
#tint(*args) ⇒ Object
Method: Image#tint Purpose: Call TintImage Notes: Opacity values are percentages: 0.10 -> 10%.
- #to_blob ⇒ Object
- #to_color ⇒ Object
- #transparent ⇒ Object
- #transparent_chroma ⇒ Object
- #transpose ⇒ Object
- #transpose! ⇒ Object
- #transverse ⇒ Object
- #transverse! ⇒ Object
- #trim ⇒ Object
- #trim! ⇒ Object
- #undefine ⇒ Object
- #unique_colors ⇒ Object
- #unsharp_mask ⇒ Object
- #unsharp_mask_channel ⇒ Object
-
#view(x, y, width, height) ⇒ Object
Construct a view.
- #vignette ⇒ Object
- #watermark ⇒ Object
- #wave ⇒ Object
- #wet_floor ⇒ Object
- #white_threshold ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
Method: Image#initialize(cols,rows,) Purpose: initialize a new Image object
If the fill argument is omitted, fill with background color
7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 |
# File 'ext/RMagick/rmimage.c', line 7118
VALUE
Image_initialize(int argc, VALUE *argv, VALUE self)
{
volatile VALUE fill = 0;
Info *info;
volatile VALUE info_obj;
Image *image;
unsigned long cols, rows;
switch (argc)
{
case 3:
fill = argv[2];
case 2:
rows = NUM2ULONG(argv[1]);
cols = NUM2ULONG(argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
break;
}
// Create a new Info object to use when creating this image.
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
image = AcquireImage(info);
if (!image)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
rm_set_user_artifact(image, info);
// NOW store a real image in the image object.
UPDATE_DATA_PTR(self, image);
SetImageExtent(image, cols, rows);
// If the caller did not supply a fill argument, call SetImageBackgroundColor
// to fill the image using the background color. The background color can
// be set by specifying it when creating the Info parm block.
if (!fill)
{
(void) SetImageBackgroundColor(image);
}
// fillobj.fill(self)
else
{
(void) rb_funcall(fill, rm_ID_fill, 1, self);
}
return self;
}
|
Class Method Details
._load(str) ⇒ Object
Method: Image._load Purpose: implement marshalling Notes: calls BlobToImage - see Image#_dump
6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 |
# File 'ext/RMagick/rmimage.c', line 6236
VALUE
Image__load(VALUE class, VALUE str)
{
Image *image;
ImageInfo *info;
DumpedImage mi;
ExceptionInfo exception;
char *blob;
long length;
class = class; // Suppress "never referenced" message from icc
info = CloneImageInfo(NULL);
blob = rm_str2cstr(str, &length);
// Must be as least as big as the 1st 4 fields in DumpedImage
if (length <= (long)(sizeof(DumpedImage)-MaxTextExtent))
{
rb_raise(rb_eTypeError, "image is invalid or corrupted (too short)");
}
// Retrieve & validate the image format from the header portion
mi.id = ((DumpedImage *)blob)->id;
if (mi.id != DUMPED_IMAGE_ID)
{
rb_raise(rb_eTypeError, "image is invalid or corrupted (invalid header)");
}
mi.mj = ((DumpedImage *)blob)->mj;
mi.mi = ((DumpedImage *)blob)->mi;
if ( mi.mj != DUMPED_IMAGE_MAJOR_VERS
|| mi.mi > DUMPED_IMAGE_MINOR_VERS)
{
rb_raise(rb_eTypeError, "incompatible image format (can't be read)\n"
"\tformat version %d.%d required; %d.%d given"
, DUMPED_IMAGE_MAJOR_VERS, DUMPED_IMAGE_MINOR_VERS
, mi.mj, mi.mi);
}
mi.len = ((DumpedImage *)blob)->len;
// Must be bigger than the header
if (length <= (long)(mi.len+sizeof(DumpedImage)-MaxTextExtent))
{
rb_raise(rb_eTypeError, "image is invalid or corrupted (too short)");
}
memcpy(info->magick, ((DumpedImage *)blob)->magick, mi.len);
info->magick[mi.len] = '\0';
GetExceptionInfo(&exception);
blob += offsetof(DumpedImage,magick) + mi.len;
length -= offsetof(DumpedImage,magick) + mi.len;
image = BlobToImage(info, blob, (size_t) length, &exception);
(void) DestroyImageInfo(info);
rm_check_exception(&exception, image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(image);
return rm_image_new(image);
}
|
.capture(*args) ⇒ Object
Method: Image.capture(silent=false,
frame=false,
descend=false,
screen=false,
borders=false) { optional parms }
Purpose: do a screen capture
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 |
# File 'ext/RMagick/rmimage.c', line 1547
VALUE
Image_capture(int argc, VALUE *argv, VALUE self)
{
Image *image;
ImageInfo *image_info;
volatile VALUE info_obj;
XImportInfo ximage_info;
self = self; // Suppress "never referenced" message from icc
XGetImportInfo(&ximage_info);
switch (argc)
{
case 5:
ximage_info.borders = (MagickBooleanType)RTEST(argv[4]);
case 4:
ximage_info.screen = (MagickBooleanType)RTEST(argv[3]);
case 3:
ximage_info.descend = (MagickBooleanType)RTEST(argv[2]);
case 2:
ximage_info.frame = (MagickBooleanType)RTEST(argv[1]);
case 1:
ximage_info.silent = (MagickBooleanType)RTEST(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 5)", argc);
break;
}
// Get optional parms.
// Set info->filename = "root", window ID number or window name,
// or nothing to do an interactive capture
// Set info->server_name to the server name
// Also info->colorspace, depth, dither, interlace, type
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, image_info);
// If an error occurs, IM will call our error handler and we raise an exception.
image = XImportImage(image_info, &ximage_info);
rm_check_image_exception(image, DestroyOnError);
rm_ensure_result(image);
rm_set_user_artifact(image, image_info);
return rm_image_new(image);
}
|
.combine ⇒ Object
.constitute(width_arg, height_arg, map_arg, pixels_arg) ⇒ Object
Method: Image.constitute(width, height, map, pixels) Purpose: Creates an Image from the supplied pixel data. The
pixel data must be in scanline order, top-to-bottom.
The pixel data is an array of either all Fixed or all Float
elements. If Fixed, the elements must be in the range
[0..QuantumRange]. If Float, the elements must be normalized [0..1].
The "map" argument reflects the expected ordering of the pixel
array. It can be any combination or order of R = red, G = green,
B = blue, A = alpha, C = cyan, Y = yellow, M = magenta,
K = black, or I = intensity (for grayscale).
The pixel array must have width X height X strlen(map) elements.
Raises: ArgumentError, TypeError
2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 |
# File 'ext/RMagick/rmimage.c', line 2963
VALUE
Image_constitute(VALUE class, VALUE width_arg, VALUE height_arg
, VALUE map_arg, VALUE pixels_arg)
{
Image *image;
ExceptionInfo exception;
volatile VALUE pixel, pixel0;
unsigned long width, height;
long x, npixels;
char *map;
long map_l;
volatile union
{
double *f;
Quantum *i;
void *v;
} pixels;
volatile VALUE pixel_class;
StorageType stg_type;
class = class; // Suppress "never referenced" message from icc
// rb_Array converts objects that are not Arrays to Arrays if possible,
// and raises TypeError if it can't.
pixels_arg = rb_Array(pixels_arg);
width = NUM2ULONG(width_arg);
height = NUM2ULONG(height_arg);
if (width == 0 || height == 0)
{
rb_raise(rb_eArgError, "width and height must be non-zero");
}
map = rm_str2cstr(map_arg, &map_l);
npixels = (long)(width * height * map_l);
if (RARRAY_LEN(pixels_arg) != npixels)
{
rb_raise(rb_eArgError, "wrong number of array elements (%ld for %ld)"
, RARRAY_LEN(pixels_arg), npixels);
}
// Inspect the first element in the pixels array to determine the expected
// type of all the elements. Allocate the pixel buffer.
pixel0 = rb_ary_entry(pixels_arg, 0);
if (rb_obj_is_kind_of(pixel0, rb_cFloat) == Qtrue)
{
pixels.f = ALLOC_N(double, npixels);
stg_type = DoublePixel;
pixel_class = rb_cFloat;
}
else if (rb_obj_is_kind_of(pixel0, rb_cInteger) == Qtrue)
{
pixels.i = ALLOC_N(Quantum, npixels);
stg_type = QuantumPixel;
pixel_class = rb_cInteger;
}
else
{
rb_raise(rb_eTypeError, "element 0 in pixel array is %s, must be numeric"
, rb_class2name(CLASS_OF(pixel0)));
}
// Convert the array elements to the appropriate C type, store in pixel
// buffer.
for (x = 0; x < npixels; x++)
{
pixel = rb_ary_entry(pixels_arg, x);
if (rb_obj_is_kind_of(pixel, pixel_class) != Qtrue)
{
rb_raise(rb_eTypeError, "element %ld in pixel array is %s, expected %s"
, x, rb_class2name(CLASS_OF(pixel)),rb_class2name(CLASS_OF(pixel0)));
}
if (pixel_class == rb_cFloat)
{
pixels.f[x] = (float) NUM2DBL(pixel);
if (pixels.f[x] < 0.0 || pixels.f[x] > 1.0)
{
rb_raise(rb_eArgError, "element %ld is out of range [0..1]: %f", x, pixels.f[x]);
}
}
else
{
pixels.i[x] = NUM2QUANTUM(pixel);
}
}
GetExceptionInfo(&exception);
// This is based on ConstituteImage in IM 5.5.7
image = AcquireImage(NULL);
if (!image)
{
rb_raise(rb_eNoMemError, "not enough memory to continue.");
}
SetImageExtent(image, width, height);
rm_check_image_exception(image, DestroyOnError);
(void) SetImageBackgroundColor(image);
rm_check_image_exception(image, DestroyOnError);
(void) ImportImagePixels(image, 0, 0, width, height, map, stg_type, (const void *)pixels.v);
xfree(pixels.v);
rm_check_image_exception(image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
DestroyConstitute();
return rm_image_new(image);
}
|
.from_blob(blob_arg) ⇒ Object
Method: Image.from_blob(blob) <{ parm block }> Purpose: Call BlobToImage Notes: The blob is a String
5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 |
# File 'ext/RMagick/rmimage.c', line 5097
VALUE
Image_from_blob(VALUE class, VALUE blob_arg)
{
Image *images;
Info *info;
volatile VALUE info_obj;
ExceptionInfo exception;
void *blob;
long length;
class = class; // defeat gcc message
blob_arg = blob_arg; // defeat gcc message
blob = (void *) rm_str2cstr(blob_arg, &length);
// Get a new Info object - run the parm block if supplied
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
GetExceptionInfo(&exception);
images = BlobToImage(info, blob, (size_t)length, &exception);
rm_check_exception(&exception, images, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(images);
rm_set_user_artifact(images, info);
return array_from_images(images);
}
|
.ping(file_arg) ⇒ Object
Method: Image.ping(file) Purpose: Call ImagePing Returns: Same as Image.read, except that PingImage does not
return the pixel data.
7628 7629 7630 7631 7632 |
# File 'ext/RMagick/rmimage.c', line 7628
VALUE
Image_ping(VALUE class, VALUE file_arg)
{
return rd_image(class, file_arg, PingImage);
}
|
.read(file_arg) ⇒ Object
Method: Image.read(file) Purpose: Call ReadImage Returns: An array of 1 or more new image objects.
8319 8320 8321 8322 8323 |
# File 'ext/RMagick/rmimage.c', line 8319
VALUE
Image_read(VALUE class, VALUE file_arg)
{
return rd_image(class, file_arg, ReadImage);
}
|
.read_inline(content) ⇒ Object
Method: Image.read_inline(content) Purpose: Read a Base64-encoded image Returns: an array of new images Notes: this is similar to, but not the same as ReadInlineImage.
ReadInlineImage requires a comma preceeding the image
data. This method allows but does not require a comma.
8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 |
# File 'ext/RMagick/rmimage.c', line 8440
VALUE
Image_read_inline(VALUE self, VALUE content)
{
volatile VALUE info_obj;
Image *images;
ImageInfo *info;
char *image_data;
long x, image_data_l;
unsigned char *blob;
size_t blob_l;
ExceptionInfo exception;
self = self; // defeat gcc message
image_data = rm_str2cstr(content, &image_data_l);
// Search for a comma. If found, we'll set the start of the
// image data just following the comma. Otherwise we'll assume
// the image data starts with the first byte.
for (x = 0; x < image_data_l; x++)
{
if (image_data[x] == ',')
{
break;
}
}
if (x < image_data_l)
{
image_data += x + 1;
}
blob = Base64Decode(image_data, &blob_l);
if (blob_l == 0)
{
rb_raise(rb_eArgError, "can't decode image");
}
GetExceptionInfo(&exception);
// Create a new Info structure for this read. About the
// only useful attribute that can be set is `format'.
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
images = BlobToImage(info, blob, blob_l, &exception);
magick_free((void *)blob);
rm_check_exception(&exception, images, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_set_user_artifact(images, info);
return array_from_images(images);
}
|
Instance Method Details
#<=>(other) ⇒ Object
Method: Image#spaceship (a <=> b) Purpose: compare two images Returns: -1, 0, 1
9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 |
# File 'ext/RMagick/rmimage.c', line 9514
VALUE
Image_spaceship(VALUE self, VALUE other)
{
Image *imageA, *imageB;
const char *sigA, *sigB;
int res;
imageA = rm_check_destroyed(self);
// If the other object isn't a Image object, then they can't be equal.
if (!rb_obj_is_kind_of(other, Class_Image))
{
return Qnil;
}
imageB = rm_check_destroyed(other);
(void) SignatureImage(imageA);
(void) SignatureImage(imageB);
sigA = rm_get_property(imageA, "signature");
sigB = rm_get_property(imageB, "signature");
if (!sigA || !sigB)
{
rb_raise(Class_ImageMagickError, "can't get image signature");
}
res = memcmp(sigA, sigB, 64);
res = res > 0 ? 1 : (res < 0 ? -1 : 0); // reduce to 1, -1, 0
return INT2FIX(res);
}
|
#[](key_arg) ⇒ Object
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
# File 'ext/RMagick/rmimage.c', line 574
VALUE
Image_aref(VALUE self, VALUE key_arg)
{
Image *image;
const char *key;
const char *attr;
image = rm_check_destroyed(self);
switch (TYPE(key_arg))
{
case T_NIL:
return Qnil;
case T_SYMBOL:
key = rb_id2name((ID)SYM2ID(key_arg));
break;
default:
key = StringValuePtr(key_arg);
if (*key == '\0')
{
return Qnil;
}
break;
}
if (rm_strcasecmp(key, "EXIF:*") == 0)
{
return rm_exif_by_entry(image);
}
else if (rm_strcasecmp(key, "EXIF:!") == 0)
{
return rm_exif_by_number(image);
}
attr = rm_get_property(image, key);
return attr ? rb_str_new2(attr) : Qnil;
}
|
#[]=(key_arg, attr_arg) ⇒ Object
Method: Image# = attr
Image#[:key] = attr
Purpose: Update or add image attribute “key” Returns: self Notes: Specify attr=nil to remove the key from the list.
SetImageProperty normally APPENDS the new value
to any existing value. Since this usage is tremendously
counter-intuitive, this function always deletes the
existing value before setting the new value.
There's no use checking the return value since
SetImageProperty returns "False" for many reasons,
some legitimate.
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
# File 'ext/RMagick/rmimage.c', line 631
VALUE
Image_aset(VALUE self, VALUE key_arg, VALUE attr_arg)
{
Image *image;
const char *key;
char *attr;
unsigned int okay;
image = rm_check_frozen(self);
attr = attr_arg == Qnil ? NULL : StringValuePtr(attr_arg);
switch (TYPE(key_arg))
{
case T_NIL:
return self;
case T_SYMBOL:
key = rb_id2name((ID)SYM2ID(key_arg));
break;
default:
key = StringValuePtr(key_arg);
if (*key == '\0')
{
return self;
}
break;
}
// Delete existing value. SetImageProperty returns False if
// the attribute doesn't exist - we don't care.
(void) rm_set_property(image, key, NULL);
// Set new value
if (attr)
{
okay = rm_set_property(image, key, attr);
if (!okay)
{
rb_warning("SetImageProperty failed (probably out of memory)");
}
}
return self;
}
|
#_dump(depth) ⇒ Object
Method: Image#_dump(aDepth) Purpose: implement marshalling Returns: a string representing the dumped image Notes: uses ImageToBlob - use the MIFF format
in the blob since it's the most general
4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 |
# File 'ext/RMagick/rmimage.c', line 4095
VALUE
Image__dump(VALUE self, VALUE depth)
{
Image *image;
ImageInfo *info;
void *blob;
size_t length;
DumpedImage mi;
volatile VALUE str;
ExceptionInfo exception;
depth = depth; // Suppress "never referenced" message from icc
image = rm_check_destroyed(self);
info = CloneImageInfo(NULL);
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
strcpy(info->magick, image->magick);
GetExceptionInfo(&exception);
blob = ImageToBlob(info, image, &length, &exception);
// Free ImageInfo first - error handling may raise an exception
(void) DestroyImageInfo(info);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
if (!blob)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
// Create a header for the blob: ID and version
// numbers, followed by the length of the magick
// string stored as a byte, followed by the
// magick string itself.
mi.id = DUMPED_IMAGE_ID;
mi.mj = DUMPED_IMAGE_MAJOR_VERS;
mi.mi = DUMPED_IMAGE_MINOR_VERS;
strcpy(mi.magick, image->magick);
mi.len = (unsigned char) min((size_t)UCHAR_MAX, strlen(mi.magick));
// Concatenate the blob onto the header & return the result
str = rb_str_new((char *)&mi, (long)(mi.len+offsetof(DumpedImage,magick)));
str = rb_str_buf_cat(str, (char *)blob, (long)length);
magick_free((void*)blob);
return str;
}
|
#adaptive_blur(*args) ⇒ Object
Method: Image#adaptive_blur(radius=0.0, sigma=1.0) Purpose: call AdaptiveBlurImage
125 126 127 128 129 |
# File 'ext/RMagick/rmimage.c', line 125
VALUE
Image_adaptive_blur(int argc, VALUE *argv, VALUE self)
{
return adaptive_method(argc, argv, self, AdaptiveBlurImage);
}
|
#adaptive_blur_channel(*args) ⇒ Object
Method: Image#adaptive_blur_channel(radius=0.0, sigma=1.0[ , channel…]) Purpose: call AdaptiveBlurImageChannel
137 138 139 140 141 |
# File 'ext/RMagick/rmimage.c', line 137
VALUE
Image_adaptive_blur_channel(int argc, VALUE *argv, VALUE self)
{
return adaptive_channel_method(argc, argv, self, AdaptiveBlurImageChannel);
}
|
#adaptive_resize(*args) ⇒ Object
Method: Image#adaptive_resize(scale_val)
Image#adaptive_resize(cols, rows)
Purpose: Call AdaptiveResizeImage
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'ext/RMagick/rmimage.c', line 149
VALUE
Image_adaptive_resize(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
unsigned long rows, columns;
double scale_val, drows, dcols;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 2:
rows = NUM2ULONG(argv[1]);
columns = NUM2ULONG(argv[0]);
break;
case 1:
scale_val = NUM2DBL(argv[0]);
if (scale_val < 0.0)
{
rb_raise(rb_eArgError, "invalid scale_val value (%g given)", scale_val);
}
drows = scale_val * image->rows + 0.5;
dcols = scale_val * image->columns + 0.5;
if (drows > (double)ULONG_MAX || dcols > (double)ULONG_MAX)
{
rb_raise(rb_eRangeError, "resized image too big");
}
rows = (unsigned long) drows;
columns = (unsigned long) dcols;
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = AdaptiveResizeImage(image, columns, rows, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#adaptive_sharpen(*args) ⇒ Object
Method: Image#adaptive_sharpen(radius=0.0, sigma=1.0) Purpose: call AdaptiveSharpenImage
201 202 203 204 205 |
# File 'ext/RMagick/rmimage.c', line 201
VALUE
Image_adaptive_sharpen(int argc, VALUE *argv, VALUE self)
{
return adaptive_method(argc, argv, self, AdaptiveSharpenImage);
}
|
#adaptive_sharpen_channel(*args) ⇒ Object
Method: Image#adaptive_sharpen_channel(radius=0.0, sigma=1.0[, channel…]) Purpose: Call AdaptiveSharpenImageChannel
213 214 215 216 217 |
# File 'ext/RMagick/rmimage.c', line 213
VALUE
Image_adaptive_sharpen_channel(int argc, VALUE *argv, VALUE self)
{
return adaptive_channel_method(argc, argv, self, AdaptiveSharpenImageChannel);
}
|
#adaptive_threshold(*args) ⇒ Object
Method: Image#adaptive_threshold(width=3, height=3, offset=0) Purpose: selects an individual threshold for each pixel based on
the range of intensity values in its local neighborhood.
This allows for thresholding of an image whose global
intensity histogram doesn't contain distinctive peaks.
Returns: a new image
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'ext/RMagick/rmimage.c', line 229
VALUE
Image_adaptive_threshold(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
unsigned long width = 3, height = 3;
long offset = 0;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 3:
offset = NUM2LONG(argv[2]);
case 2:
height = NUM2ULONG(argv[1]);
case 1:
width = NUM2ULONG(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc);
}
GetExceptionInfo(&exception);
new_image = AdaptiveThresholdImage(image, width, height, offset, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#add_compose_mask(mask) ⇒ Object
Method: Image#add_compose_mask(mask) Purpose: Set the image composite mask Ref: SetImageMask Notes: Returns self See also: Image#mask(), #delete_compose_mask()
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'ext/RMagick/rmimage.c', line 272
VALUE
Image_add_compose_mask(VALUE self, VALUE mask)
{
Image *image;
Image *mask_image = NULL;
image = rm_check_frozen(self);
mask_image = rm_check_destroyed(mask);
if (image->columns != mask_image->columns || image->rows != mask_image->rows)
{
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.
(void) SetImageMask(image, mask_image);
(void) NegateImage(image->mask, MagickFalse);
// 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;
}
|
#add_noise(noise) ⇒ Object
Method: Image#add_noise(noise_type) Purpose: add random noise to a copy of the image Returns: a new image
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'ext/RMagick/rmimage.c', line 302
VALUE
Image_add_noise(VALUE self, VALUE noise)
{
Image *image, *new_image;
NoiseType noise_type;
ExceptionInfo exception;
image = rm_check_destroyed(self);
VALUE_TO_ENUM(noise, noise_type, NoiseType);
GetExceptionInfo(&exception);
new_image = AddNoiseImage(image, noise_type, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#add_noise_channel(*args) ⇒ Object
Method: Image#add_noise_channel(noise_type) Purpose: add random noise to a copy of the image Returns: a new image
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'ext/RMagick/rmimage.c', line 329
VALUE
Image_add_noise_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
NoiseType noise_type;
ExceptionInfo exception;
ChannelType channels;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// There must be 1 remaining argument.
if (argc == 0)
{
rb_raise(rb_eArgError, "missing noise type argument");
}
else if (argc > 1)
{
raise_ChannelType_error(argv[argc-1]);
}
VALUE_TO_ENUM(argv[0], noise_type, NoiseType);
channels &= ~OpacityChannel;
GetExceptionInfo(&exception);
new_image = AddNoiseImageChannel(image, channels, noise_type, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#add_profile(name) ⇒ Object
Method: Image#add_profile(name) Purpose: adds all the profiles in the specified file Notes: ‘name’ is the profile filename
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'ext/RMagick/rmimage.c', line 370
VALUE
Image_add_profile(VALUE self, VALUE name)
{
// ImageMagick code based on the code for the "-profile" option in mogrify.c
Image *image, *profile_image;
ImageInfo *info;
ExceptionInfo exception;
char *profile_name;
char *profile_filename = NULL;
long profile_filename_l = 0;
const StringInfo *profile;
image = rm_check_frozen(self);
// ProfileImage issues a warning if something goes wrong.
profile_filename = rm_str2cstr(name, &profile_filename_l);
info = CloneImageInfo(NULL);
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
profile = GetImageProfile(image, "iptc");
if (profile)
{
info->profile = (void *)CloneStringInfo(profile);
}
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);
(void) DestroyImageInfo(info);
rm_check_exception(&exception, profile_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(profile_image);
ResetImageProfileIterator(profile_image);
profile_name = GetNextImageProfile(profile_image);
while (profile_name)
{
profile = GetImageProfile(profile_image, profile_name);
if (profile)
{
(void)ProfileImage(image, profile_name, GetStringInfoDatum(profile)
, GetStringInfoLength(profile), MagickFalse);
if (image->exception.severity >= ErrorException)
{
break;
}
}
profile_name = GetNextImageProfile(profile_image);
}
(void) DestroyImage(profile_image);
rm_check_image_exception(image, RetainOnError);
return self;
}
|
#affine_transform(affine) ⇒ Object
Method: Image#affine_transform(affine_matrix) Purpose: transforms an image as dictated by the affine matrix argument Returns: a new image
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'ext/RMagick/rmimage.c', line 543
VALUE
Image_affine_transform(VALUE self, VALUE affine)
{
Image *image, *new_image;
ExceptionInfo exception;
AffineMatrix matrix;
image = rm_check_destroyed(self);
// Convert Magick::AffineMatrix to AffineMatrix structure.
Export_AffineMatrix(&matrix, affine);
GetExceptionInfo(&exception);
new_image = AffineTransformImage(image, &matrix, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#alpha(*args) ⇒ Object
Method: Image#alpha(type) Purpose: Calls SetImageAlphaChannel Notes: Replaces matte=, alpha=
Originally there was an alpha attribute getter and setter.
These are replaced with alpha? and alpha(type). We
still define (but don't document) alpha=. For backward
compatibility, if this method is called without an argument,
make it act like the old alpha getter and return true if the
matte channel is active, false otherwise.
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'ext/RMagick/rmimage.c', line 444
VALUE
Image_alpha(int argc, VALUE *argv, VALUE self)
{
Image *image;
AlphaChannelType alpha;
// For backward compatibility, make alpha() act like alpha?
if (argc == 0)
{
return Image_alpha_q(self);
}
else if (argc > 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
}
image = rm_check_frozen(self);
VALUE_TO_ENUM(argv[0], alpha, AlphaChannelType);
#if defined(HAVE_SETIMAGEALPHACHANNEL)
// Added in 6.3.6-9
(void) SetImageAlphaChannel(image, alpha);
rm_check_image_exception(image, RetainOnError);
#else
switch (alpha)
{
case ActivateAlphaChannel:
image->matte = MagickTrue;
break;
case DeactivateAlphaChannel:
image->matte = MagickFalse;
break;
case ResetAlphaChannel:
if (image->matte == MagickFalse)
{
(void) SetImageOpacity(image, OpaqueOpacity);
rm_check_image_exception(image, RetainOnError);
}
break;
case SetAlphaChannel:
(void) CompositeImage(image, CopyOpacityCompositeOp, image, 0, 0);
rm_check_image_exception(image, RetainOnError);
break;
default:
rb_raise(rb_eArgError, "unknown AlphaChannelType value");
break;
}
#endif
return argv[0];
}
|
#alpha? ⇒ Boolean
Method: Image#alpha? Returns: true if the image’s alpha channel is activated Notes: Replaces Image#matte
509 510 511 512 513 514 515 516 517 518 |
# File 'ext/RMagick/rmimage.c', line 509
VALUE
Image_alpha_q(VALUE self)
{
Image *image = rm_check_destroyed(self);
#if defined(HAVE_GETIMAGEALPHACHANNEL)
return GetImageAlphaChannel(image) ? Qtrue : Qfalse;
#else
return image->matte ? Qtrue : Qfalse;
#endif
}
|
#annotate(draw, width, height, x, y, text, &block) ⇒ Object
Provide an alternate version of Draw#annotate, for folks who want to find it in this class.
786 787 788 789 790 |
# File 'lib/RMagick.rb', line 786 def annotate(draw, width, height, x, y, text, &block) check_destroyed draw.annotate(self, width, height, x, y, text, &block) self end |
#auto_gamma_channel(*args) ⇒ Object
733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'ext/RMagick/rmimage.c', line 733
VALUE
Image_auto_gamma_channel(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_AUTOGAMMAIMAGECHANNEL)
return auto_channel(argc, argv, self, AutoGammaImageChannel);
#else
rm_not_implemented();
argc = argc;
argv = argv;
self = self;
#endif
}
|
#auto_level_channel(*args) ⇒ Object
747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'ext/RMagick/rmimage.c', line 747
VALUE
Image_auto_level_channel(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_AUTOLEVELIMAGECHANNEL)
return auto_channel(argc, argv, self, AutoLevelImageChannel);
#else
rm_not_implemented();
argc = argc;
argv = argv;
self = self;
#endif
}
|
#auto_orient ⇒ Object
822 823 824 825 826 827 |
# File 'ext/RMagick/rmimage.c', line 822
VALUE
Image_auto_orient(VALUE self)
{
(void) rm_check_destroyed(self);
return auto_orient(False, self);
}
|
#auto_orient! ⇒ Object
Returns nil if the image is already properly oriented
833 834 835 836 837 838 |
# File 'ext/RMagick/rmimage.c', line 833
VALUE
Image_auto_orient_bang(VALUE self)
{
(void) rm_check_frozen(self);
return auto_orient(True, self);
}
|
#bilevel_channel(*args) ⇒ Object
Method: Image#bilevel_channel(threshold, channel=AllChannels) Returns a new image
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
# File 'ext/RMagick/rmimage.c', line 938
VALUE
Image_bilevel_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ChannelType channels;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 1)
{
raise_ChannelType_error(argv[argc-1]);
}
if (argc == 0)
{
rb_raise(rb_eArgError, "no threshold specified");
}
new_image = rm_clone_image(image);
(void)BilevelImageChannel(new_image, channels, NUM2DBL(argv[0]));
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#black_threshold(*args) ⇒ Object
Method: Image#black_threshold(red_channel [, green_channel
[, blue_channel [, opacity_channel]]]);
Purpose: Call BlackThresholdImage
1015 1016 1017 1018 1019 |
# File 'ext/RMagick/rmimage.c', line 1015
VALUE
Image_black_threshold(int argc, VALUE *argv, VALUE self)
{
return threshold_image(argc, argv, self, BlackThresholdImage);
}
|
#blend(*args) ⇒ Object
Method: Image#blend(overlay, src_percent, dst_percent, x_offset=0, y_offset=0)
Image#dissolve(overlay, src_percent, dst_percent, gravity, x_offset=0, y_offset=0)
Purpose: Corresponds to the composite -blend operation Notes: ‘percent’ can be a number or a string in the form “NN%”
The default value for dst_percent is 100.0-src_percent
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 |
# File 'ext/RMagick/rmimage.c', line 1286
VALUE
Image_blend(int argc, VALUE *argv, VALUE self)
{
volatile VALUE ovly;
Image *image, *overlay;
double src_percent, dst_percent;
long x_offset = 0L, y_offset = 0L;
image = rm_check_destroyed(self);
if (argc < 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 6)", argc);
}
ovly = rm_cur_image(argv[0]);
overlay = rm_check_destroyed(ovly);
if (argc > 3)
{
get_composite_offsets(argc-3, &argv[3], image, overlay, &x_offset, &y_offset);
// There must be 3 arguments left
argc = 3;
}
switch (argc)
{
case 3:
dst_percent = rm_percentage(argv[2]) * 100.0;
src_percent = rm_percentage(argv[1]) * 100.0;
break;
case 2:
src_percent = rm_percentage(argv[1]) * 100.0;
dst_percent = FMAX(100.0 - src_percent, 0);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 6)", argc);
break;
}
return special_composite(image, overlay, src_percent, dst_percent
, x_offset, y_offset, BlendCompositeOp);
}
|
#blue_shift(*args) ⇒ Object
Method: Image#blue_shift(factor=1.5) Purpose: Call BlueShiftImage
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 |
# File 'ext/RMagick/rmimage.c', line 1337
VALUE
Image_blue_shift(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_BLUESHIFTIMAGE)
Image *image, *new_image;
double factor = 1.5;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 1:
factor = NUM2DBL(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = BlueShiftImage(image, factor, &exception);
CHECK_EXCEPTION();
DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
#else
rm_not_implemented();
return (VALUE)0;
argc = argc;
argv = argv;
self = self;
#endif
}
|
#blur_channel ⇒ Object
#blur_image(*args) ⇒ Object
Method: Image#blur_image(radius=0.0, sigma=1.0) Purpose: Blur the image Notes: The “blur” name is used for the attribute
1425 1426 1427 1428 1429 |
# File 'ext/RMagick/rmimage.c', line 1425
VALUE
Image_blur_image(int argc, VALUE *argv, VALUE self)
{
return effect_image(self, argc, argv, BlurImage);
}
|
#border(width, height, color) ⇒ Object
1484 1485 1486 1487 1488 1489 |
# File 'ext/RMagick/rmimage.c', line 1484
VALUE
Image_border(VALUE self, VALUE width, VALUE height, VALUE color)
{
(void) rm_check_destroyed(self);
return border(False, self, width, height, color);
}
|
#border!(width, height, color) ⇒ Object
1476 1477 1478 1479 1480 1481 |
# File 'ext/RMagick/rmimage.c', line 1476
VALUE
Image_border_bang(VALUE self, VALUE width, VALUE height, VALUE color)
{
(void) rm_check_frozen(self);
return border(True, self, width, height, color);
}
|
#change_geometry(geom_arg) ⇒ Object
Method: Image#change_geometry(geometry_string) { |cols, rows, image| } Purpose: parse geometry string, compute new image geometry
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 |
# File 'ext/RMagick/rmimage.c', line 1600
VALUE
Image_change_geometry(VALUE self, VALUE geom_arg)
{
Image *image;
RectangleInfo rect;
volatile VALUE geom_str;
char *geometry;
unsigned int flags;
volatile VALUE ary;
image = rm_check_destroyed(self);
geom_str = rm_to_s(geom_arg);
geometry = StringValuePtr(geom_str);
memset(&rect, 0, sizeof(rect));
SetGeometry(image, &rect);
rm_check_image_exception(image, RetainOnError);
flags = ParseMetaGeometry(geometry, &rect.x,&rect.y, &rect.width,&rect.height);
if (flags == NoValue)
{
rb_raise(rb_eArgError, "invalid geometry string `%s'", geometry);
}
ary = rb_ary_new2(3);
rb_ary_store(ary, 0, ULONG2NUM(rect.width));
rb_ary_store(ary, 1, ULONG2NUM(rect.height));
rb_ary_store(ary, 2, self);
return rb_yield(ary);
}
|
#change_geometry!(geom_arg) ⇒ Object
Method: Image#change_geometry(geometry_string) { |cols, rows, image| } Purpose: parse geometry string, compute new image geometry
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 |
# File 'ext/RMagick/rmimage.c', line 1600
VALUE
Image_change_geometry(VALUE self, VALUE geom_arg)
{
Image *image;
RectangleInfo rect;
volatile VALUE geom_str;
char *geometry;
unsigned int flags;
volatile VALUE ary;
image = rm_check_destroyed(self);
geom_str = rm_to_s(geom_arg);
geometry = StringValuePtr(geom_str);
memset(&rect, 0, sizeof(rect));
SetGeometry(image, &rect);
rm_check_image_exception(image, RetainOnError);
flags = ParseMetaGeometry(geometry, &rect.x,&rect.y, &rect.width,&rect.height);
if (flags == NoValue)
{
rb_raise(rb_eArgError, "invalid geometry string `%s'", geometry);
}
ary = rb_ary_new2(3);
rb_ary_store(ary, 0, ULONG2NUM(rect.width));
rb_ary_store(ary, 1, ULONG2NUM(rect.height));
rb_ary_store(ary, 2, self);
return rb_yield(ary);
}
|
#changed? ⇒ Boolean
Method: Image#changed? Purpose: Return true if any pixel in the image has been altered since
the image was constituted.
1638 1639 1640 1641 1642 1643 1644 1645 |
# File 'ext/RMagick/rmimage.c', line 1638
VALUE
Image_changed_q(VALUE self)
{
Image *image = rm_check_destroyed(self);
VALUE okay = IsTaintImage(image) ? Qtrue : Qfalse;
rm_check_image_exception(image, RetainOnError);
return okay;
}
|
#channel(channel_arg) ⇒ Object
Method: Image#channel Purpose: Extract a channel from the image. A channel is a particular color
component of each pixel in the image.
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 |
# File 'ext/RMagick/rmimage.c', line 1653
VALUE
Image_channel(VALUE self, VALUE channel_arg)
{
Image *image, *new_image;
ChannelType channel;
image = rm_check_destroyed(self);
VALUE_TO_ENUM(channel_arg, channel, ChannelType);
new_image = rm_clone_image(image);
(void) SeparateImageChannel(new_image, channel);
rm_check_image_exception(new_image, DestroyOnError);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#channel_compare(*args) ⇒ Object
Method: Image#compare_channel(ref_image, metric [, channel…]) { optional arguments } Purpose: compares one or more channels in two images and returns
the specified distortion metric and a comparison image.
Notes: If no channels are specified, the default is AllChannels.
That case is the equivalent of the CompareImages method in
ImageMagick.
Originally this method was called channel_compare, but
that doesn't match the general naming convention that
methods which accept multiple optional ChannelType
arguments have names that end in _channel. So I renamed
the method to compare_channel but kept channel_compare as
an alias.
The optional arguments are specified thusly:
self.highlight_color color
self.lowlight-color color
where color is either a color name or a Pixel.
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 |
# File 'ext/RMagick/rmimage.c', line 2441
VALUE
Image_compare_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *r_image, *difference_image;
double distortion;
volatile VALUE ary, ref;
MetricType metric_type;
ChannelType channels;
ExceptionInfo exception;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 2)
{
raise_ChannelType_error(argv[argc-1]);
}
if (argc != 2)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or more)", argc);
}
rm_get_optional_arguments(self);
ref = rm_cur_image(argv[0]);
r_image = rm_check_destroyed(ref);
VALUE_TO_ENUM(argv[1], metric_type, MetricType);
GetExceptionInfo(&exception);
difference_image = CompareImageChannels(image
, r_image
, channels
, metric_type
, &distortion
, &exception);
rm_check_exception(&exception, difference_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(difference_image);
ary = rb_ary_new2(2);
rb_ary_store(ary, 0, rm_image_new(difference_image));
rb_ary_store(ary, 1, rb_float_new(distortion));
return ary;
}
|
#channel_depth(*args) ⇒ Object
Method: Image#channel_depth(channel_depth=AllChannels) Purpose: GetImageChannelDepth
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 |
# File 'ext/RMagick/rmimage.c', line 1678
VALUE
Image_channel_depth(int argc, VALUE *argv, VALUE self)
{
Image *image;
ChannelType channels;
unsigned long channel_depth;
ExceptionInfo exception;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// Ensure all arguments consumed.
if (argc > 0)
{
raise_ChannelType_error(argv[argc-1]);
}
GetExceptionInfo(&exception);
channel_depth = GetImageChannelDepth(image, channels, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
return ULONG2NUM(channel_depth);
}
|
#channel_extrema(*args) ⇒ Object
Method: Image#channel_extrema(channel=AllChannels) Purpose: Returns an array [min, max] where ‘min’ and ‘max’
are the minimum and maximum values of all channels.
Notes: GM’s implementation is very different from ImageMagick.
This method follows the IM API very closely and then
shoehorn's the GM API to more-or-less fit. Note that
IM allows you to specify more than one channel argument.
GM does not.
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 |
# File 'ext/RMagick/rmimage.c', line 1716
VALUE
Image_channel_extrema(int argc, VALUE *argv, VALUE self)
{
Image *image;
ChannelType channels;
ExceptionInfo exception;
unsigned long min, max;
volatile VALUE ary;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// Ensure all arguments consumed.
if (argc > 0)
{
raise_ChannelType_error(argv[argc-1]);
}
GetExceptionInfo(&exception);
(void) GetImageChannelExtrema(image, channels, &min, &max, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
ary = rb_ary_new2(2);
rb_ary_store(ary, 0, ULONG2NUM(min));
rb_ary_store(ary, 1, ULONG2NUM(max));
return ary;
}
|
#channel_mean(*args) ⇒ Object
Method: Image#channel_mean(channel=AllChannels) Returns An array [mean, std. deviation]
1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 |
# File 'ext/RMagick/rmimage.c', line 1753
VALUE
Image_channel_mean(int argc, VALUE *argv, VALUE self)
{
Image *image;
ChannelType channels;
ExceptionInfo exception;
double mean, stddev;
volatile VALUE ary;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// Ensure all arguments consumed.
if (argc > 0)
{
raise_ChannelType_error(argv[argc-1]);
}
GetExceptionInfo(&exception);
(void) GetImageChannelMean(image, channels, &mean, &stddev, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
ary = rb_ary_new2(2);
rb_ary_store(ary, 0, rb_float_new(mean));
rb_ary_store(ary, 1, rb_float_new(stddev));
return ary;
}
|
#charcoal(*args) ⇒ Object
Method: Image#charcoal(radius=0.0, sigma=1.0) Purpose: Return a new image that is a copy of the input image with the
edges highlighted
1791 1792 1793 1794 1795 |
# File 'ext/RMagick/rmimage.c', line 1791
VALUE
Image_charcoal(int argc, VALUE *argv, VALUE self)
{
return effect_image(self, argc, argv, CharcoalImage);
}
|
#check_destroyed ⇒ Object
Method: Image#check_destroyed Purpose: If the target image has been destroyed, raises Magick::DestroyedImageError
1802 1803 1804 1805 1806 1807 |
# File 'ext/RMagick/rmimage.c', line 1802
VALUE
Image_check_destroyed(VALUE self)
{
(void) rm_check_destroyed(self);
return Qnil;
}
|
#chop(x, y, width, height) ⇒ Object
Method: Image#chop Purpose: removes a region of an image and collapses the image to occupy
the removed portion
1815 1816 1817 1818 1819 1820 |
# File 'ext/RMagick/rmimage.c', line 1815
VALUE
Image_chop(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
{
(void) rm_check_destroyed(self);
return xform_image(False, self, x, y, width, height, ChopImage);
}
|
#clone ⇒ Object
Method: Image#clone Purpose: Copy an image, along with its frozen and tainted state.
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 |
# File 'ext/RMagick/rmimage.c', line 1854
VALUE
Image_clone(VALUE self)
{
volatile VALUE clone;
clone = Image_dup(self);
if (OBJ_FROZEN(self))
{
OBJ_FREEZE(clone);
}
return clone;
}
|
#clut_channel(*args) ⇒ Object
Method: Image#clut_channel Purpose: Equivalent to -clut option.
1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 |
# File 'ext/RMagick/rmimage.c', line 1873
VALUE
Image_clut_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *clut;
ChannelType channels;
MagickBooleanType okay;
image = rm_check_frozen(self);
// check_destroyed before confirming the arguments
if (argc >= 1)
{
(void) rm_check_destroyed(argv[0]);
channels = extract_channels(&argc, argv);
if (argc != 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or more)", argc);
}
}
else
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or more)", argc);
}
Data_Get_Struct(argv[0], Image, clut);
okay = ClutImageChannel(image, channels, clut);
rm_check_image_exception(image, RetainOnError);
rm_check_image_exception(clut, RetainOnError);
if (!okay)
{
rb_raise(rb_eRuntimeError, "ClutImageChannel failed.");
}
return self;
}
|
#color_fill_to_border(x, y, fill) ⇒ Object
Set all pixels that are neighbors of x,y and are not the border color to the fill color
808 809 810 |
# File 'lib/RMagick.rb', line 808 def color_fill_to_border(x, y, fill) color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod) end |
#color_flood_fill(target_color, fill_color, xv, yv, method) ⇒ Object
Method: Image#color_flood_fill(target_color, fill_color, x, y, method) Purpose: changes the color value of any pixel that matches target_color
and is an immediate neighbor.
Notes: use fuzz= to specify the tolerance amount (see Image_opaque)
Accepts either the FloodfillMethod or the FillToBorderMethod
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 |
# File 'ext/RMagick/rmimage.c', line 2097
VALUE
Image_color_flood_fill( VALUE self, VALUE target_color, VALUE fill_color
, VALUE xv, VALUE yv, VALUE method)
{
Image *image, *new_image;
PixelPacket target;
DrawInfo *draw_info;
PixelPacket fill;
long x, y;
int fill_method;
image = rm_check_destroyed(self);
// The target and fill args can be either a color name or
// a Magick::Pixel.
Color_to_PixelPacket(&target, target_color);
Color_to_PixelPacket(&fill, fill_color);
x = NUM2LONG(xv);
y = NUM2LONG(yv);
if ((unsigned long)x > image->columns || (unsigned long)y > image->rows)
{
rb_raise(rb_eArgError, "target out of range. %lux%lu given, image is %lux%lu"
, x, y, image->columns, image->rows);
}
VALUE_TO_ENUM(method, fill_method, PaintMethod);
if (!(fill_method == FloodfillMethod || fill_method == FillToBorderMethod))
{
rb_raise(rb_eArgError, "paint method must be FloodfillMethod or "
"FillToBorderMethod (%d given)", fill_method);
}
draw_info = CloneDrawInfo(NULL, NULL);
if (!draw_info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
draw_info->fill = fill;
new_image = rm_clone_image(image);
#if defined(HAVE_FLOODFILLPAINTIMAGE)
{
MagickPixelPacket target_mpp;
MagickBooleanType invert;
GetMagickPixelPacket(new_image, &target_mpp);
if (fill_method == FillToBorderMethod)
{
invert = MagickTrue;
target_mpp.red = (MagickRealType) image->border_color.red;
target_mpp.green = (MagickRealType) image->border_color.green;
target_mpp.blue = (MagickRealType) image->border_color.blue;
}
else
{
invert = MagickFalse;
target_mpp.red = (MagickRealType) target.red;
target_mpp.green = (MagickRealType) target.green;
target_mpp.blue = (MagickRealType) target.blue;
}
(void) FloodfillPaintImage(new_image, DefaultChannels, draw_info, &target_mpp, x, y, invert);
}
#else
(void) ColorFloodfillImage(new_image, draw_info, target, x, y, (PaintMethod)fill_method);
#endif
// No need to check for error
(void) DestroyDrawInfo(draw_info);
return rm_image_new(new_image);
}
|
#color_floodfill(x, y, fill) ⇒ Object
Set all pixels that have the same color as the pixel at x,y and are neighbors to the fill color
801 802 803 804 |
# File 'lib/RMagick.rb', line 801 def color_floodfill(x, y, fill) target = pixel_color(x, y) color_flood_fill(target, fill, x, y, Magick::FloodfillMethod) end |
#color_histogram ⇒ Object
Method: Image_color_histogram(VALUE self); Purpose: Call GetImageHistogram Notes: returns hash aPixel=>count
1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 |
# File 'ext/RMagick/rmimage.c', line 1916
VALUE
Image_color_histogram(VALUE self)
{
Image *image, *dc_copy = NULL;
volatile VALUE hash, pixel;
unsigned long x, colors;
ColorPacket *histogram;
ExceptionInfo exception;
image = rm_check_destroyed(self);
// If image not DirectClass make a DirectClass copy.
if (image->storage_class != DirectClass)
{
dc_copy = rm_clone_image(image);
(void) SyncImage(dc_copy);
magick_free(dc_copy->colormap);
dc_copy->colormap = NULL;
dc_copy->storage_class = DirectClass;
image = dc_copy;
}
GetExceptionInfo(&exception);
histogram = GetImageHistogram(image, &colors, &exception);
if (histogram == NULL)
{
if (dc_copy)
{
(void) DestroyImage(dc_copy);
}
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
if (exception.severity != UndefinedException)
{
(void) RelinquishMagickMemory(histogram);
rm_check_exception(&exception, dc_copy, DestroyOnError);
}
(void) DestroyExceptionInfo(&exception);
hash = rb_hash_new();
for (x = 0; x < colors; x++)
{
pixel = Pixel_from_PixelPacket(&histogram[x].pixel);
(void) rb_hash_aset(hash, pixel, ULONG2NUM((unsigned long)histogram[x].count));
}
/*
Christy evidently didn't agree with Bob's memory management.
*/
(void) RelinquishMagickMemory(histogram);
if (dc_copy)
{
// Do not trace destruction
(void) DestroyImage(dc_copy);
}
return hash;
}
|
#color_point(x, y, fill) ⇒ Object
Set the color at x,y
793 794 795 796 797 |
# File 'lib/RMagick.rb', line 793 def color_point(x, y, fill) f = copy f.pixel_color(x, y, fill) return f end |
#color_reset!(fill) ⇒ Object
Set all pixels to the fill color. Very similar to Image#erase! Accepts either String or Pixel arguments
814 815 816 817 818 819 820 821 822 823 824 825 826 |
# File 'lib/RMagick.rb', line 814 def color_reset!(fill) save = background_color # Change the background color _outside_ the begin block # so that if this object is frozen the exeception will be # raised before we have to handle it explicitly. self.background_color = fill begin erase! ensure self.background_color = save end self end |
#colorize(*args) ⇒ Object
Method: Image#colorize(r, g, b, target) Purpose: blends the fill color specified by “target” with each pixel in
the image. Specify the percentage blend for each r, g, b
component.
2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 |
# File 'ext/RMagick/rmimage.c', line 2178
VALUE
Image_colorize(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double red, green, blue, matte;
char opacity[50];
PixelPacket target;
ExceptionInfo exception;
image = rm_check_destroyed(self);
if (argc == 4)
{
red = floor(100*NUM2DBL(argv[0])+0.5);
green = floor(100*NUM2DBL(argv[1])+0.5);
blue = floor(100*NUM2DBL(argv[2])+0.5);
Color_to_PixelPacket(&target, argv[3]);
sprintf(opacity, "%f/%f/%f", red, green, blue);
}
else if (argc == 5)
{
red = floor(100*NUM2DBL(argv[0])+0.5);
green = floor(100*NUM2DBL(argv[1])+0.5);
blue = floor(100*NUM2DBL(argv[2])+0.5);
matte = floor(100*NUM2DBL(argv[3])+0.5);
Color_to_PixelPacket(&target, argv[4]);
sprintf(opacity, "%f/%f/%f/%f", red, green, blue, matte);
}
else
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 4 or 5)", argc);
}
GetExceptionInfo(&exception);
new_image = ColorizeImage(image, opacity, target, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#colormap(*args) ⇒ Object
Method: Image#colormap(index<, new-color>) Purpose: return the color in the colormap at the specified index. If
a new color is specified, replaces the color at the index
with the new color.
Returns: the name of the color. Notes: The “new-color” argument can be either a color name or
a Magick::Pixel.
2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 |
# File 'ext/RMagick/rmimage.c', line 2232
VALUE
Image_colormap(int argc, VALUE *argv, VALUE self)
{
Image *image;
unsigned long idx;
PixelPacket color, new_color;
image = rm_check_destroyed(self);
// We can handle either 1 or 2 arguments. Nothing else.
if (argc == 0 || argc > 2)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
}
idx = NUM2ULONG(argv[0]);
if (idx > QuantumRange)
{
rb_raise(rb_eIndexError, "index out of range");
}
// If this is a simple "get" operation, ensure the image has a colormap.
if (argc == 1)
{
if (!image->colormap)
{
rb_raise(rb_eIndexError, "image does not contain a colormap");
}
// Validate the index
if (idx > image->colors-1)
{
rb_raise(rb_eIndexError, "index out of range");
}
return rm_pixelpacket_to_color_name(image, &image->colormap[idx]);
}
// This is a "set" operation. Things are different.
rb_check_frozen(self);
// Replace with new color? The arg can be either a color name or
// a Magick::Pixel.
Color_to_PixelPacket(&new_color, argv[1]);
// Handle no colormap or current colormap too small.
if (!image->colormap || idx > image->colors-1)
{
PixelPacket black;
unsigned long i;
memset(&black, 0, sizeof(black));
if (!image->colormap)
{
image->colormap = (PixelPacket *)magick_safe_malloc((idx+1), sizeof(PixelPacket));
image->colors = 0;
}
else
{
image->colormap = (PixelPacket *)magick_safe_realloc(image->colormap, (idx+1), sizeof(PixelPacket));
}
for (i = image->colors; i < idx; i++)
{
image->colormap[i] = black;
}
image->colors = idx+1;
}
// Save the current color so we can return it. Set the new color.
color = image->colormap[idx];
image->colormap[idx] = new_color;
return rm_pixelpacket_to_color_name(image, &color);
}
|
#compare_channel(*args) ⇒ Object
Method: Image#compare_channel(ref_image, metric [, channel…]) { optional arguments } Purpose: compares one or more channels in two images and returns
the specified distortion metric and a comparison image.
Notes: If no channels are specified, the default is AllChannels.
That case is the equivalent of the CompareImages method in
ImageMagick.
Originally this method was called channel_compare, but
that doesn't match the general naming convention that
methods which accept multiple optional ChannelType
arguments have names that end in _channel. So I renamed
the method to compare_channel but kept channel_compare as
an alias.
The optional arguments are specified thusly:
self.highlight_color color
self.lowlight-color color
where color is either a color name or a Pixel.
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 |
# File 'ext/RMagick/rmimage.c', line 2441
VALUE
Image_compare_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *r_image, *difference_image;
double distortion;
volatile VALUE ary, ref;
MetricType metric_type;
ChannelType channels;
ExceptionInfo exception;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 2)
{
raise_ChannelType_error(argv[argc-1]);
}
if (argc != 2)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or more)", argc);
}
rm_get_optional_arguments(self);
ref = rm_cur_image(argv[0]);
r_image = rm_check_destroyed(ref);
VALUE_TO_ENUM(argv[1], metric_type, MetricType);
GetExceptionInfo(&exception);
difference_image = CompareImageChannels(image
, r_image
, channels
, metric_type
, &distortion
, &exception);
rm_check_exception(&exception, difference_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(difference_image);
ary = rb_ary_new2(2);
rb_ary_store(ary, 0, rm_image_new(difference_image));
rb_ary_store(ary, 1, rb_float_new(distortion));
return ary;
}
|
#composite(*args) ⇒ Object
2683 2684 2685 2686 2687 |
# File 'ext/RMagick/rmimage.c', line 2683
VALUE
Image_composite(int argc, VALUE *argv, VALUE self)
{
return composite(False, argc, argv, self, DefaultChannels);
}
|
#composite!(*args) ⇒ Object
2676 2677 2678 2679 2680 |
# File 'ext/RMagick/rmimage.c', line 2676
VALUE
Image_composite_bang(int argc, VALUE *argv, VALUE self)
{
return composite(True, argc, argv, self, DefaultChannels);
}
|
#composite_affine(source, affine_matrix) ⇒ Object
Method: Image#composite_affine(composite, affine_matrix) Purpose: composites the source over the destination image as
dictated by the affine transform.
2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 |
# File 'ext/RMagick/rmimage.c', line 2695
VALUE
Image_composite_affine(VALUE self, VALUE source, VALUE affine_matrix)
{
Image *image, *composite_image, *new_image;
AffineMatrix affine;
image = rm_check_destroyed(self);
composite_image = rm_check_destroyed(source);
new_image = rm_clone_image(image);
Export_AffineMatrix(&affine, affine_matrix);
(void) DrawAffineImage(new_image, composite_image, &affine);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#composite_channel(*args) ⇒ Object
2741 2742 2743 2744 2745 |
# File 'ext/RMagick/rmimage.c', line 2741
VALUE
Image_composite_channel(int argc, VALUE *argv, VALUE self)
{
return composite_channel(False, argc, argv, self);
}
|
#composite_channel!(*args) ⇒ Object
2748 2749 2750 2751 2752 |
# File 'ext/RMagick/rmimage.c', line 2748
VALUE
Image_composite_channel_bang(int argc, VALUE *argv, VALUE self)
{
return composite_channel(True, argc, argv, self);
}
|
#composite_mathematics(*args) ⇒ Object
Method: Image#composite_mathematics
img.composite_mathematics(comp_img, A, B, C, D, gravity)
img.composite_mathematics(comp_img, A, B, C, D, x_off, y_off)
img.composite_mathematics(comp_img, A, B, C, D, gravity, x_off, y_off)
Purpose: Composite using MathematicsCompositeOp Notes: New in 6.5.4-3.
2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 |
# File 'ext/RMagick/rmimage.c', line 2763
VALUE
Image_composite_mathematics(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_ENUM_MATHEMATICSCOMPOSITEOP)
Image *composite_image;
VALUE args[5];
signed long x_off = 0L;
signed long y_off = 0L;
GravityType gravity = NorthWestGravity;
char compose_args[200];
rm_check_destroyed(self);
if (argc > 0)
{
composite_image = rm_check_destroyed(rm_cur_image(argv[0]));
}
switch (argc)
{
case 8:
VALUE_TO_ENUM(argv[5], gravity, GravityType);
x_off = NUM2LONG(argv[6]);
y_off = NUM2LONG(argv[7]);
break;
case 7:
x_off = NUM2LONG(argv[5]);
y_off = NUM2LONG(argv[6]);
break;
case 6:
VALUE_TO_ENUM(argv[5], gravity, GravityType);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (got %d, expected 6 to 8)", argc);
break;
}
(void) sprintf(compose_args, "%-.16g,%-.16g,%-.16g,%-.16g", NUM2DBL(argv[1]), NUM2DBL(argv[2]), NUM2DBL(argv[3]), NUM2DBL(argv[4]));
SetImageArtifact(composite_image,"compose:args", compose_args);
// Call composite(False, gravity, x_off, y_off, MathematicsCompositeOp, DefaultChannels)
args[0] = argv[0];
args[1] = GravityType_new(gravity);
args[2] = LONG2FIX(x_off);
args[3] = LONG2FIX(y_off);
args[4] = CompositeOperator_new(MathematicsCompositeOp);
return composite(False, 5, args, self, DefaultChannels);
#else
rm_not_implemented();
argc = argc;
argv = argv;
self = self;
return (VALUE)0;
#endif
}
|
#composite_tiled(*args) ⇒ Object
2898 2899 2900 2901 2902 |
# File 'ext/RMagick/rmimage.c', line 2898
VALUE
Image_composite_tiled(int argc, VALUE *argv, VALUE self)
{
return composite_tiled(False, argc, argv, self);
}
|
#composite_tiled!(*args) ⇒ Object
2905 2906 2907 2908 2909 |
# File 'ext/RMagick/rmimage.c', line 2905
VALUE
Image_composite_tiled_bang(int argc, VALUE *argv, VALUE self)
{
return composite_tiled(True, argc, argv, self);
}
|
#compress_colormap! ⇒ Object
Method: Image#compress_colormap! Purpose: call CompressImageColormap Notes: API was CompressColormap until 5.4.9
2937 2938 2939 2940 2941 2942 2943 2944 2945 |
# File 'ext/RMagick/rmimage.c', line 2937
VALUE
Image_compress_colormap_bang(VALUE self)
{
Image *image = rm_check_frozen(self);
(void) CompressImageColormap(image);
rm_check_image_exception(image, RetainOnError);
return self;
}
|
#contrast(*args) ⇒ Object
Method: Image#contrast(<sharpen>) Purpose: enhances the intensity differences between the lighter and
darker elements of the image. Set sharpen to "true" to
increase the image contrast otherwise the contrast is reduced.
Notes: if omitted, “sharpen” defaults to 0 Returns: new contrasted image
3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 |
# File 'ext/RMagick/rmimage.c', line 3086
VALUE
Image_contrast(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
unsigned int sharpen = 0;
image = rm_check_destroyed(self);
if (argc > 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
}
else if (argc == 1)
{
sharpen = RTEST(argv[0]);
}
new_image = rm_clone_image(image);
(void) ContrastImage(new_image, sharpen);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#contrast_stretch_channel(*args) ⇒ Object
Method: Image#contrast_stretch_channel(black_point <, white_point> <, channel…>) Purpose: Call ContrastStretchImageChannel Notes: If white_point is not specified then it is #pixels-black_point.
Both black_point and white_point can be specified as Floats
or as percentages, i.e. "10%"
3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 |
# File 'ext/RMagick/rmimage.c', line 3172
VALUE
Image_contrast_stretch_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ChannelType channels;
double black_point, white_point;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 2)
{
raise_ChannelType_error(argv[argc-1]);
}
get_black_white_point(image, argc, argv, &black_point, &white_point);
new_image = rm_clone_image(image);
(void) ContrastStretchImageChannel(new_image, channels, black_point, white_point);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#convolve(order_arg, kernel_arg) ⇒ Object
Method: Image#convolve(order, kernel) Purpose: apply a custom convolution kernel to the image Notes: “order” is the number of rows and columns in the kernel
"kernel" is an order**2 array of doubles
3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 |
# File 'ext/RMagick/rmimage.c', line 3202
VALUE
Image_convolve(VALUE self, VALUE order_arg, VALUE kernel_arg)
{
Image *image, *new_image;
double *kernel;
unsigned int x, order;
ExceptionInfo exception;
image = rm_check_destroyed(self);
order = NUM2UINT(order_arg);
kernel_arg = rb_Array(kernel_arg);
rm_check_ary_len(kernel_arg, (long)(order*order));
// Convert the kernel array argument to an array of doubles
kernel = (double *)ALLOC_N(double, order*order);
for (x = 0; x < order*order; x++)
{
kernel[x] = NUM2DBL(rb_ary_entry(kernel_arg, (long)x));
}
GetExceptionInfo(&exception);
new_image = ConvolveImage((const Image *)image, order, (double *)kernel, &exception);
xfree((void *)kernel);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#convolve_channel(*args) ⇒ Object
Method: Image#convolve_channel(order, kernel[, channel[, channel…]]) Purpose: call ConvolveImageChannel
3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 |
# File 'ext/RMagick/rmimage.c', line 3243
VALUE
Image_convolve_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double *kernel;
volatile VALUE ary;
unsigned int x, order;
ChannelType channels;
ExceptionInfo exception;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// There are 2 required arguments.
if (argc > 2)
{
raise_ChannelType_error(argv[argc-1]);
}
if (argc != 2)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or more)", argc);
}
order = NUM2UINT(argv[0]);
ary = argv[1];
rm_check_ary_len(ary, (long)(order*order));
kernel = ALLOC_N(double, (long)(order*order));
// Convert the kernel array argument to an array of doubles
for (x = 0; x < order*order; x++)
{
kernel[x] = NUM2DBL(rb_ary_entry(ary, (long)x));
}
GetExceptionInfo(&exception);
new_image = ConvolveImageChannel(image, channels, order, kernel, &exception);
xfree((void *)kernel);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#copy ⇒ Object
Method: Image#copy Purpose: Alias for dup
3299 3300 3301 3302 3303 |
# File 'ext/RMagick/rmimage.c', line 3299
VALUE
Image_copy(VALUE self)
{
return rb_funcall(self, rm_ID_dup, 0);
}
|
#crop(*args) ⇒ Object
3329 3330 3331 3332 3333 3334 |
# File 'ext/RMagick/rmimage.c', line 3329
VALUE
Image_crop(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_destroyed(self);
return cropper(False, argc, argv, self);
}
|
#crop!(*args) ⇒ Object
3337 3338 3339 3340 3341 3342 |
# File 'ext/RMagick/rmimage.c', line 3337
VALUE
Image_crop_bang(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_frozen(self);
return cropper(True, argc, argv, self);
}
|
#cur_image ⇒ Object
Used by ImageList methods - see ImageList#cur_image
829 830 831 |
# File 'lib/RMagick.rb', line 829 def cur_image self end |
#cycle_colormap(amount) ⇒ Object
Method: Image#cycle_colormap Purpose: Call CycleColormapImage
3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 |
# File 'ext/RMagick/rmimage.c', line 3349
VALUE
Image_cycle_colormap(VALUE self, VALUE amount)
{
Image *image, *new_image;
int amt;
image = rm_check_destroyed(self);
new_image = rm_clone_image(image);
amt = NUM2INT(amount);
(void) CycleColormapImage(new_image, amt);
// No need to check for an error
return rm_image_new(new_image);
}
|
#decipher(passphrase) ⇒ Object
Method: Image#decipher(passphrase) Purpose: call DecipherImage
3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 |
# File 'ext/RMagick/rmimage.c', line 3456
VALUE
Image_decipher(VALUE self, VALUE passphrase)
{
#if defined(HAVE_ENCIPHERIMAGE)
Image *image, *new_image;
char *pf;
ExceptionInfo exception;
MagickBooleanType okay;
image = rm_check_destroyed(self);
pf = StringValuePtr(passphrase); // ensure passphrase is a string
GetExceptionInfo(&exception);
new_image = rm_clone_image(image);
okay = DecipherImage(new_image, pf, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
if (!okay)
{
new_image = DestroyImage(new_image);
rb_raise(rb_eRuntimeError, "DecipherImage failed for unknown reason.");
}
DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
#else
self = self;
passphrase = passphrase;
rm_not_implemented();
return(VALUE)0;
#endif
}
|
#define(artifact, value) ⇒ Object
Method: value = Image#define(artifact, value) Purpose: Call SetImageArtifact Note: Normally a script should never call this method. Any calls
to SetImageArtifact will be part of the methods in which they're
needed, or be called via the OptionalMethodArguments class.
3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 |
# File 'ext/RMagick/rmimage.c', line 3498
VALUE
Image_define(VALUE self, VALUE artifact, VALUE value)
{
#if defined(HAVE_SETIMAGEARTIFACT)
Image *image;
char *key, *val;
MagickBooleanType status;
image = rm_check_frozen(self);
artifact = rb_String(artifact);
key = StringValuePtr(artifact);
if (value == Qnil)
{
(void) DeleteImageArtifact(image, key);
}
else
{
value = rb_String(value);
val = StringValuePtr(value);
status = SetImageArtifact(image, key, val);
if (!status)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
}
return value;
#else
rm_not_implemented();
artifact = artifact;
value = value;
self = self;
return(VALUE)0;
#endif
}
|
#delete_compose_mask ⇒ Object
#delete_profile(name) ⇒ Object
Method: Image#delete_profile(name) Purpose: call ProfileImage Notes: name is the name of the profile to be deleted
3564 3565 3566 3567 3568 3569 3570 3571 3572 |
# File 'ext/RMagick/rmimage.c', line 3564
VALUE
Image_delete_profile(VALUE self, VALUE name)
{
Image *image = rm_check_frozen(self);
(void) ProfileImage(image, StringValuePtr(name), NULL, 0, MagickTrue);
rm_check_image_exception(image, RetainOnError);
return self;
}
|
#deskew(*args) ⇒ Object
Method: Image#deskew(threshold=0.40, auto-crop-width) Purpose: Implement convert -deskew option
3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 |
# File 'ext/RMagick/rmimage.c', line 3605
VALUE
Image_deskew(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_DESKEWIMAGE)
Image *image, *new_image;
double threshold = 40.0 * QuantumRange / 100.0;
unsigned long width;
char auto_crop_width[20];
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 2:
width = NUM2ULONG(argv[1]);
memset(auto_crop_width, 0, sizeof(auto_crop_width));
sprintf(auto_crop_width, "%ld", width);
SetImageArtifact(image, "deskew:auto-crop", auto_crop_width);
case 1:
threshold = rm_percentage(argv[0]) * QuantumRange;
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = DeskewImage(image, threshold, &exception);
CHECK_EXCEPTION()
rm_ensure_result(new_image);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
#else
self = self; // defeat "unused parameter" message
argv = argv;
argc = argc;
rm_not_implemented();
return(VALUE)0;
#endif
}
|
#despeckle ⇒ Object
Method: Image#despeckle Purpose: reduces the speckle noise in an image while preserving the
edges of the original image
Returns: a new image
3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 |
# File 'ext/RMagick/rmimage.c', line 3657
VALUE
Image_despeckle(VALUE self)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = DespeckleImage(image, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#destroy! ⇒ Object
Method: Image#destroy! Purpose: Free all the memory associated with an image
3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 |
# File 'ext/RMagick/rmimage.c', line 3681
VALUE
Image_destroy_bang(VALUE self)
{
Image *image;
rb_check_frozen(self);
Data_Get_Struct(self, Image, image);
rm_image_destroy(image);
DATA_PTR(self) = NULL;
return self;
}
|
#destroyed? ⇒ Boolean
Method: Image#destroyed? Purpose: Returns true if the image has been destroyed, false otherwise
3698 3699 3700 3701 3702 3703 3704 3705 |
# File 'ext/RMagick/rmimage.c', line 3698
VALUE
Image_destroyed_q(VALUE self)
{
Image *image;
Data_Get_Struct(self, Image, image);
return image ? Qfalse : Qtrue;
}
|
#difference(other) ⇒ Object
Method: Image#difference Purpose: Call the IsImagesEqual function Returns: An array with 3 values:
[0] mean error per pixel
[1] normalized mean error
[2] normalized maximum error
Notes: “other” can be either an Image or an Image
3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 |
# File 'ext/RMagick/rmimage.c', line 3717
VALUE
Image_difference(VALUE self, VALUE other)
{
Image *image;
Image *image2;
volatile VALUE mean, nmean, nmax;
image = rm_check_destroyed(self);
other = rm_cur_image(other);
image2 = rm_check_destroyed(other);
(void) IsImagesEqual(image, image2);
// No need to check for error
mean = rb_float_new(image->error.mean_error_per_pixel);
nmean = rb_float_new(image->error.normalized_mean_error);
nmax = rb_float_new(image->error.normalized_maximum_error);
return rb_ary_new3(3, mean, nmean, nmax);
}
|
#dispatch(*args) ⇒ Object
Method: Image#dispatch(x, y, columns, rows, map <, float>) Purpose: Extracts pixel data from the image and returns it as an
array of pixels. The "x", "y", "width" and "height" parameters
specify the rectangle to be extracted. The "map" parameter
reflects the expected ordering of the pixel array. It can be
any combination or order of R = red, G = green, B = blue, A =
alpha, C = cyan, Y = yellow, M = magenta, K = black, or I =
intensity (for grayscale). If the "float" parameter is specified
and true, the pixel data is returned as floating-point numbers
in the range [0..1]. By default the pixel data is returned as
integers in the range [0..QuantumRange].
Returns: an Array Raises: ArgumentError
3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 |
# File 'ext/RMagick/rmimage.c', line 3804
VALUE
Image_dispatch(int argc, VALUE *argv, VALUE self)
{
Image *image;
long x, y;
unsigned long columns, rows, n, npixels;
volatile VALUE pixels_ary;
StorageType stg_type = QuantumPixel;
char *map;
long mapL;
MagickBooleanType okay;
ExceptionInfo exception;
volatile union
{
Quantum *i;
double *f;
void *v;
} pixels;
(void) rm_check_destroyed(self);
if (argc < 5 || argc > 6)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 5 or 6)", argc);
}
x = NUM2LONG(argv[0]);
y = NUM2LONG(argv[1]);
columns = NUM2ULONG(argv[2]);
rows = NUM2ULONG(argv[3]);
map = rm_str2cstr(argv[4], &mapL);
if (argc == 6)
{
stg_type = RTEST(argv[5]) ? DoublePixel : QuantumPixel;
}
// Compute the size of the pixel array and allocate the memory.
npixels = columns * rows * mapL;
pixels.v = stg_type == QuantumPixel ? (void *) ALLOC_N(Quantum, npixels)
: (void *) ALLOC_N(double, npixels);
// Create the Ruby array for the pixels. Return this even if ExportImagePixels fails.
pixels_ary = rb_ary_new();
Data_Get_Struct(self, Image, image);
GetExceptionInfo(&exception);
okay = ExportImagePixels(image, x, y, columns, rows, map, stg_type, (void *)pixels.v, &exception);
if (!okay)
{
goto exit;
}
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
// Convert the pixel data to the appropriate Ruby type
if (stg_type == QuantumPixel)
{
for (n = 0; n < npixels; n++)
{
(void) rb_ary_push(pixels_ary, QUANTUM2NUM(pixels.i[n]));
}
}
else
{
for (n = 0; n < npixels; n++)
{
(void) rb_ary_push(pixels_ary, rb_float_new(pixels.f[n]));
}
}
exit:
xfree((void *)pixels.v);
return pixels_ary;
}
|
#displace ⇒ Object
#display ⇒ Object Also known as: __display__
Method: Image#display Purpose: display the image to an X window screen
3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 |
# File 'ext/RMagick/rmimage.c', line 3888
VALUE
Image_display(VALUE self)
{
Image *image;
Info *info;
volatile VALUE info_obj;
image = rm_check_destroyed(self);
if (image->rows == 0 || image->columns == 0)
{
rb_raise(rb_eArgError, "invalid image geometry (%lux%lu)", image->rows, image->columns);
}
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
(void) DisplayImages(info, image);
rm_check_image_exception(image, RetainOnError);
return self;
}
|
#dissolve(*args) ⇒ Object
Method: Image#dissolve(overlay, src_percent, dst_percent, x_offset=0, y_offset=0)
Image#dissolve(overlay, src_percent, dst_percent, gravity, x_offset=0, y_offset=0)
Purpose: Corresponds to the composite_image -dissolve operation Notes: ‘percent’ can be a number or a string in the form “NN%”
The "default" value of dst_percent is -1.0, which tells
blend_geometry to leave it out of the geometry string.
3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 |
# File 'ext/RMagick/rmimage.c', line 3945
VALUE
Image_dissolve(int argc, VALUE *argv, VALUE self)
{
Image *image, *overlay;
double src_percent, dst_percent = -1.0;
long x_offset = 0L, y_offset = 0L;
volatile VALUE composite_image, ovly;
image = rm_check_destroyed(self);
if (argc < 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 6)", argc);
}
ovly = rm_cur_image(argv[0]);
overlay = rm_check_destroyed(ovly);
if (argc > 3)
{
get_composite_offsets(argc-3, &argv[3], image, overlay, &x_offset, &y_offset);
// There must be 3 arguments left
argc = 3;
}
switch (argc)
{
case 3:
dst_percent = rm_percentage(argv[2]) * 100.0;
case 2:
src_percent = rm_percentage(argv[1]) * 100.0;
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 6)", argc);
break;
}
composite_image = special_composite(image, overlay, src_percent, dst_percent
, x_offset, y_offset, DissolveCompositeOp);
return composite_image;
}
|
#distort(*args) ⇒ Object
Method: Image#distort(type, points, bestfit=false) { optional arguments } Purpose: Call DistortImage Notes: points is an Array of Numeric values
optional arguments are
self.define "distort:viewport", WxH+X+Y
self.define "distort:scale", N
self.verbose true
4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 |
# File 'ext/RMagick/rmimage.c', line 4000
VALUE
Image_distort(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
volatile VALUE pts;
unsigned long n, npoints;
DistortImageMethod distortion_method;
double *points;
MagickBooleanType bestfit = MagickFalse;
ExceptionInfo exception;
image = rm_check_destroyed(self);
rm_get_optional_arguments(self);
switch (argc)
{
case 3:
bestfit = RTEST(argv[2]);
case 2:
// Ensure pts is an array
pts = rb_Array(argv[1]);
VALUE_TO_ENUM(argv[0], distortion_method, DistortImageMethod);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (expected 2 or 3, got %d)", argc);
break;
}
npoints = RARRAY_LEN(pts);
// Allocate points array from Ruby's memory. If an error occurs Ruby will
// be able to clean it up.
points = ALLOC_N(double, npoints);
for (n = 0; n < npoints; n++)
{
points[n] = NUM2DBL(rb_ary_entry(pts, n));
}
GetExceptionInfo(&exception);
new_image = DistortImage(image, distortion_method, npoints, points, bestfit, &exception);
xfree(points);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#distortion_channel(*args) ⇒ Object
Method: Image#distortion_channel(reconstructed_image, metric[, channel…]) Purpose: Call GetImageChannelDistortion
4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 |
# File 'ext/RMagick/rmimage.c', line 4053
VALUE
Image_distortion_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *reconstruct;
ChannelType channels;
ExceptionInfo exception;
MetricType metric;
volatile VALUE rec;
double distortion;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 2)
{
raise_ChannelType_error(argv[argc-1]);
}
if (argc < 2)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or more)", argc);
}
rec = rm_cur_image(argv[0]);
reconstruct = rm_check_destroyed(rec);
VALUE_TO_ENUM(argv[1], metric, MetricType);
GetExceptionInfo(&exception);
(void) GetImageChannelDistortion(image, reconstruct, channels
, metric, &distortion, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
return rb_float_new(distortion);
}
|
#dup ⇒ Object
Method: Image#dup Purpose: Construct a new image object and call initialize_copy
4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 |
# File 'ext/RMagick/rmimage.c', line 4154
VALUE
Image_dup(VALUE self)
{
volatile VALUE dup;
(void) rm_check_destroyed(self);
dup = Data_Wrap_Struct(CLASS_OF(self), NULL, rm_image_destroy, NULL);
if (rb_obj_tainted(self))
{
(void) rb_obj_taint(dup);
}
return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
}
|
#each_iptc_dataset ⇒ Object
Iterate over IPTC record number:dataset tags, yield for each non-nil dataset
891 892 893 894 895 896 897 898 899 900 |
# File 'lib/RMagick.rb', line 891 def each_iptc_dataset Magick::IPTC.constants.each do |record| rec = Magick::IPTC.const_get(record) rec.constants.each do |dataset| data_field = get_iptc_dataset(rec.const_get(dataset)) yield(dataset, data_field) unless data_field.nil? end end nil end |
#each_pixel ⇒ Object
Thanks to Russell Norris!
834 835 836 837 838 839 |
# File 'lib/RMagick.rb', line 834 def each_pixel get_pixels(0, 0, columns, rows).each_with_index do |p, n| yield(p, n%columns, n/columns) end self end |
#each_profile ⇒ Object
Method: Image#each_profile Purpose: Iterate over image profiles Notes: ImageMagick only
4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 |
# File 'ext/RMagick/rmimage.c', line 4174
VALUE
Image_each_profile(VALUE self)
{
Image *image;
volatile VALUE ary, val;
char *name;
const StringInfo *profile;
image = rm_check_destroyed(self);
ResetImageProfileIterator(image);
ary = rb_ary_new2(2);
name = GetNextImageProfile(image);
while (name)
{
rb_ary_store(ary, 0, rb_str_new2(name));
profile = GetImageProfile(image, name);
if (!profile)
{
rb_ary_store(ary, 1, Qnil);
}
else
{
rb_ary_store(ary, 1, rb_str_new((char *)profile->datum, (long)profile->length));
}
val = rb_yield(ary);
name = GetNextImageProfile(image);
}
return val;
}
|
#edge(*args) ⇒ Object
Method: Image#edge(radius=0) Purpose: finds edges in an image. “radius” defines the radius of the
convolution filter. Use a radius of 0 and edge selects a
suitable radius
Returns: a new image
4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 |
# File 'ext/RMagick/rmimage.c', line 4216
VALUE
Image_edge(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double radius = 0.0;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 1:
radius = NUM2DBL(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = EdgeImage(image, radius, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#emboss(*args) ⇒ Object
Method: Image#emboss(radius=0.0, sigma=1.0) Purpose: creates a grayscale image with a three-dimensional effect
4295 4296 4297 4298 4299 |
# File 'ext/RMagick/rmimage.c', line 4295
VALUE
Image_emboss(int argc, VALUE *argv, VALUE self)
{
return effect_image(self, argc, argv, EmbossImage);
}
|
#encipher(passphrase) ⇒ Object
Method: Image#encipher(passphrase) Purpose: call EncipherImage
4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 |
# File 'ext/RMagick/rmimage.c', line 4306
VALUE
Image_encipher(VALUE self, VALUE passphrase)
{
#if defined(HAVE_ENCIPHERIMAGE)
Image *image, *new_image;
char *pf;
ExceptionInfo exception;
MagickBooleanType okay;
image = rm_check_destroyed(self);
pf = StringValuePtr(passphrase); // ensure passphrase is a string
GetExceptionInfo(&exception);
new_image = rm_clone_image(image);
okay = EncipherImage(new_image, pf, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
if (!okay)
{
new_image = DestroyImage(new_image);
rb_raise(rb_eRuntimeError, "EncipherImage failed for unknown reason.");
}
DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
#else
self = self;
passphrase = passphrase;
rm_not_implemented();
return(VALUE)0;
#endif
}
|
#enhance ⇒ Object
Method: Image#enhance Purpose: applies a digital filter that improves the quality of a noisy image
4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 |
# File 'ext/RMagick/rmimage.c', line 4370
VALUE
Image_enhance(VALUE self)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = EnhanceImage(image, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#equalize ⇒ Object
Method: Image#equalize Purpose: applies a histogram equalization to the image
4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 |
# File 'ext/RMagick/rmimage.c', line 4394
VALUE
Image_equalize(VALUE self)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = rm_clone_image(image);
(void) EqualizeImage(new_image);
rm_check_image_exception(new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#equalize_channel(*args) ⇒ Object
Method: Image#equalize_channel Purpose: call EqualizeImageChannel
4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 |
# File 'ext/RMagick/rmimage.c', line 4417
VALUE
Image_equalize_channel(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_EQUALIZEIMAGECHANNEL)
Image *image, *new_image;
ExceptionInfo exception;
ChannelType channels;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 0)
{
raise_ChannelType_error(argv[argc-1]);
}
new_image = rm_clone_image(image);
GetExceptionInfo(&exception);
(void) EqualizeImageChannel(new_image, channels);
rm_check_image_exception(new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
#else
argc = argc;
argv = argv;
self = self;
rm_not_implemented();
return(VALUE) 0;
#endif
}
|
#erase! ⇒ Object
Method: Image#erase! Purpose: reset the image to the background color Notes: one of the very few Image methods that do not
return a new image.
4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 |
# File 'ext/RMagick/rmimage.c', line 4458
VALUE
Image_erase_bang(VALUE self)
{
Image *image = rm_check_frozen(self);
(void) SetImageBackgroundColor(image);
rm_check_image_exception(image, RetainOnError);
return self;
}
|
#excerpt(x, y, width, height) ⇒ Object
4508 4509 4510 4511 4512 4513 |
# File 'ext/RMagick/rmimage.c', line 4508
VALUE
Image_excerpt(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
{
(void) rm_check_destroyed(self);
return excerpt(False, self, x, y, width, height);
}
|
#excerpt!(x, y, width, height) ⇒ Object
4516 4517 4518 4519 4520 4521 |
# File 'ext/RMagick/rmimage.c', line 4516
VALUE
Image_excerpt_bang(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
{
(void) rm_check_frozen(self);
return excerpt(True, self, x, y, width, height);
}
|
#export_pixels(*args) ⇒ Object
Method: Image#export_pixels(x=0, y=0, cols=self.columns, rows=self.rows, map=“RGB”) Purpose: extract image pixels in the form of an array
4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 |
# File 'ext/RMagick/rmimage.c', line 4528
VALUE
Image_export_pixels(int argc, VALUE *argv, VALUE self)
{
Image *image;
long x_off = 0L, y_off = 0L;
unsigned long cols, rows;
long n, npixels;
unsigned int okay;
const char *map = "RGB";
Quantum *pixels;
volatile VALUE ary;
ExceptionInfo exception;
image = rm_check_destroyed(self);
cols = image->columns;
rows = image->rows;
switch (argc)
{
case 5:
map = StringValuePtr(argv[4]);
case 4:
rows = NUM2ULONG(argv[3]);
case 3:
cols = NUM2ULONG(argv[2]);
case 2:
y_off = NUM2LONG(argv[1]);
case 1:
x_off = NUM2LONG(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 5)", argc);
break;
}
if ( x_off < 0 || (unsigned long)x_off > image->columns
|| y_off < 0 || (unsigned long)y_off > image->rows
|| cols == 0 || rows == 0)
{
rb_raise(rb_eArgError, "invalid extract geometry");
}
npixels = (long)(cols * rows * strlen(map));
pixels = ALLOC_N(Quantum, npixels);
if (!pixels) // app recovered from exception
{
return rb_ary_new2(0L);
}
GetExceptionInfo(&exception);
okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, QuantumPixel, (void *)pixels, &exception);
if (!okay)
{
xfree((void *)pixels);
CHECK_EXCEPTION()
// Should never get here...
rm_magick_error("ExportImagePixels failed with no explanation.", NULL);
}
(void) DestroyExceptionInfo(&exception);
ary = rb_ary_new2(npixels);
for (n = 0; n < npixels; n++)
{
(void) rb_ary_push(ary, QUANTUM2NUM(pixels[n]));
}
xfree((void *)pixels);
return ary;
}
|
#export_pixels_to_str(*args) ⇒ Object
Method: Image#export_pixels_to_str(x=0, y=0, cols=self.columns,
rows=self.rows, map="RGB", type=Magick::CharPixel)
Purpose: extract image pixels to a Ruby string
4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 |
# File 'ext/RMagick/rmimage.c', line 4669
VALUE
Image_export_pixels_to_str(int argc, VALUE *argv, VALUE self)
{
Image *image;
long x_off = 0L, y_off = 0L;
unsigned long cols, rows;
unsigned long npixels;
size_t sz;
unsigned int okay;
const char *map = "RGB";
StorageType type = CharPixel;
volatile VALUE string;
char *str;
ExceptionInfo exception;
image = rm_check_destroyed(self);
cols = image->columns;
rows = image->rows;
switch (argc)
{
case 6:
VALUE_TO_ENUM(argv[5], type, StorageType);
case 5:
map = StringValuePtr(argv[4]);
case 4:
rows = NUM2ULONG(argv[3]);
case 3:
cols = NUM2ULONG(argv[2]);
case 2:
y_off = NUM2LONG(argv[1]);
case 1:
x_off = NUM2LONG(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 6)", argc);
break;
}
if ( x_off < 0 || (unsigned long)x_off > image->columns
|| y_off < 0 || (unsigned long)y_off > image->rows
|| cols == 0 || rows == 0)
{
rb_raise(rb_eArgError, "invalid extract geometry");
}
npixels = cols * rows * strlen(map);
switch (type)
{
case CharPixel:
sz = sizeof(unsigned char);
break;
case ShortPixel:
sz = sizeof(unsigned short);
break;
case DoublePixel:
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);
break;
case UndefinedPixel:
default:
rb_raise(rb_eArgError, "undefined storage type");
break;
}
// Allocate a string long enough to hold the exported pixel data.
// Get a pointer to the buffer.
string = rb_str_new2("");
(void) rb_str_resize(string, (long)(sz * npixels));
str = StringValuePtr(string);
GetExceptionInfo(&exception);
okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, type, (void *)str, &exception);
if (!okay)
{
// Let GC have the string buffer.
(void) rb_str_resize(string, 0);
CHECK_EXCEPTION()
// Should never get here...
rm_magick_error("ExportImagePixels failed with no explanation.", NULL);
}
(void) DestroyExceptionInfo(&exception);
return string;
}
|
#extent(*args) ⇒ Object
Method: Image#extent(width, height, x=0, y=0) Purpose: Call ExtentImage
4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 |
# File 'ext/RMagick/rmimage.c', line 4610
VALUE
Image_extent(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
RectangleInfo geometry;
long height, width;
ExceptionInfo exception;
(void) rm_check_destroyed(self);
if (argc < 2 || argc > 4)
{
rb_raise(rb_eArgError, "wrong number of arguments (expected 2 to 4, got %d)", argc);
}
geometry.y = geometry.x = 0L;
switch (argc)
{
case 4:
geometry.y = NUM2LONG(argv[3]);
case 3:
geometry.x = NUM2LONG(argv[2]);
default:
geometry.height = height = NUM2LONG(argv[1]);
geometry.width = width = NUM2LONG(argv[0]);
break;
}
// Use the signed versions of these two values to test for < 0
if (height <= 0L || width <= 0L)
{
if (geometry.x == 0 && geometry.y == 0)
{
rb_raise(rb_eArgError, "invalid extent geometry %ldx%ld", width, height);
}
else
{
rb_raise(rb_eArgError, "invalid extent geometry %ldx%ld+%ld+%ld"
, width, height, geometry.x, geometry.y);
}
}
Data_Get_Struct(self, Image, image);
GetExceptionInfo(&exception);
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);
}
|
#find_similar_region(*args) ⇒ Object
Method: Image#find_similar_region(target, x=0, y=0) Purpose: Search for a region in the image that is “similar” to the
target image.
4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 |
# File 'ext/RMagick/rmimage.c', line 4833
VALUE
Image_find_similar_region(int argc, VALUE *argv, VALUE self)
{
Image *image, *target;
volatile VALUE region, targ;
long x = 0L, y = 0L;
ExceptionInfo exception;
unsigned int okay;
image = rm_check_destroyed(self);
switch (argc)
{
case 3:
y = NUM2LONG(argv[2]);
case 2:
x = NUM2LONG(argv[1]);
case 1:
targ = rm_cur_image(argv[0]);
target = rm_check_destroyed(targ);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 3)", argc);
break;
}
GetExceptionInfo(&exception);
okay = IsImageSimilar(image, target, &x, &y, &exception);
CHECK_EXCEPTION();
(void) DestroyExceptionInfo(&exception);
if (!okay)
{
return Qnil;
}
region = rb_ary_new2(2);
rb_ary_store(region, 0L, LONG2NUM(x));
rb_ary_store(region, 1L, LONG2NUM(y));
return region;
}
|
#flip ⇒ Object
4913 4914 4915 4916 4917 4918 |
# File 'ext/RMagick/rmimage.c', line 4913
VALUE
Image_flip(VALUE self)
{
(void) rm_check_destroyed(self);
return flipflop(False, self, FlipImage);
}
|
#flip! ⇒ Object
4921 4922 4923 4924 4925 4926 |
# File 'ext/RMagick/rmimage.c', line 4921
VALUE
Image_flip_bang(VALUE self)
{
(void) rm_check_frozen(self);
return flipflop(True, self, FlipImage);
}
|
#flop ⇒ Object
Method: Image#flop
Image#flop!
Purpose: creates a horizontal mirror image by reflecting the pixels around
the central y-axis
Returns: flop: a new, flopped image
flop!: self, flopped
4937 4938 4939 4940 4941 4942 |
# File 'ext/RMagick/rmimage.c', line 4937
VALUE
Image_flop(VALUE self)
{
(void) rm_check_destroyed(self);
return flipflop(False, self, FlopImage);
}
|
#flop! ⇒ Object
4945 4946 4947 4948 4949 4950 |
# File 'ext/RMagick/rmimage.c', line 4945
VALUE
Image_flop_bang(VALUE self)
{
(void) rm_check_frozen(self);
return flipflop(True, self, FlopImage);
}
|
#frame(*args) ⇒ Object
Method: Image#frame(<width<, height<, x<, y<, inner_bevel<, outer_bevel
<, color>>>>>>>)
Purpose: adds a simulated three-dimensional border around the image.
"Width" and "height" specify the width and height of the frame.
The "x" and "y" arguments position the image within the frame.
If the image is supposed to be centered in the frame, x and y
should be 1/2 the width and height of the frame. (I.e. if the
frame is 50 pixels high and 50 pixels wide, x and y should both
be 25)."Inner_bevel" and "outer_bevel" indicate the width of the
inner and outer shadows of the frame. They should be much
smaller than the frame and cannot be > 1/2 the frame width or
height of the image.
Default: All arguments are optional. The defaults are the same as they
are in Magick++:
width: image-columns+25*2
height: image-rows+25*2
x: 25
y: 25
inner: 6
outer: 6
color: image matte_color (which defaults to #bdbdbd, whatever
self.matte_color was set to when the image was created,
or whatever image.matte_color is currently set to)
Returns: a new image.
5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 |
# File 'ext/RMagick/rmimage.c', line 5041
VALUE
Image_frame(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ExceptionInfo exception;
FrameInfo frame_info;
image = rm_check_destroyed(self);
frame_info.width = image->columns + 50;
frame_info.height = image->rows + 50;
frame_info.x = 25;
frame_info.y = 25;
frame_info.inner_bevel = 6;
frame_info.outer_bevel = 6;
switch (argc)
{
case 7:
Color_to_PixelPacket(&image->matte_color, argv[6]);
case 6:
frame_info.outer_bevel = NUM2LONG(argv[5]);
case 5:
frame_info.inner_bevel = NUM2LONG(argv[4]);
case 4:
frame_info.y = NUM2LONG(argv[3]);
case 3:
frame_info.x = NUM2LONG(argv[2]);
case 2:
frame_info.height = image->rows + 2*NUM2LONG(argv[1]);
case 1:
frame_info.width = image->columns + 2*NUM2LONG(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 7)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = FrameImage(image, &frame_info, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#function_channel(*args) ⇒ Object
Method: Image#function_channel(function, args[, channel…])
5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 |
# File 'ext/RMagick/rmimage.c', line 5132
VALUE
Image_function_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
MagickFunction function;
unsigned long n, nparms;
volatile double *parameters;
double *parms;
ChannelType channels;
ExceptionInfo exception;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// The number of parameters depends on the function.
if (argc == 0)
{
rb_raise(rb_eArgError, "no function specified");
}
VALUE_TO_ENUM(argv[0], function, MagickFunction);
argc -= 1;
argv += 1;
switch (function)
{
case PolynomialFunction:
if (argc == 0)
{
rb_raise(rb_eArgError, "PolynomialFunction requires at least one argument.");
}
break;
case SinusoidFunction:
#if defined(HAVE_ENUM_ARCSINFUNCTION)
case ArcsinFunction:
#endif
#if defined(HAVE_ENUM_ARCTANFUNCTION)
case ArctanFunction:
#endif
if (argc < 1 || argc > 4)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 4)", argc);
}
break;
default:
rb_raise(rb_eArgError, "undefined function");
break;
}
nparms = argc;
parameters = parms = ALLOC_N(double, nparms);
for (n = 0; n < nparms; n++)
{
parms[n] = NUM2DBL(argv[n]);
}
GetExceptionInfo(&exception);
new_image = rm_clone_image(image);
(void) FunctionImageChannel(new_image, channels, function, nparms, parms, &exception);
(void) xfree(parms);
rm_check_exception(&exception, new_image, DestroyOnError);
DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#gamma_channel ⇒ Object
#gamma_correct(*args) ⇒ Object
Method: Image#gamma_correct(red_gamma<, green_gamma<, blue_gamma>>>) Purpose: gamma-correct an image Notes: At least red_gamma must be specified. If one or more levels are
omitted, the last specified number is used as the default.
For backward compatibility accept a 4th argument but ignore it.
5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 |
# File 'ext/RMagick/rmimage.c', line 5259
VALUE
Image_gamma_correct(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double red_gamma, green_gamma, blue_gamma;
char gamma_arg[50];
image = rm_check_destroyed(self);
switch (argc)
{
case 1:
red_gamma = NUM2DBL(argv[0]);
// Can't have all 4 gamma values == 1.0. Also, very small values
// cause ImageMagick to segv.
if (red_gamma == 1.0 || fabs(red_gamma) < 0.003)
{
rb_raise(rb_eArgError, "invalid gamma value (%f)", red_gamma);
}
green_gamma = blue_gamma = red_gamma;
break;
case 2:
red_gamma = NUM2DBL(argv[0]);
green_gamma = NUM2DBL(argv[1]);
blue_gamma = green_gamma;
break;
case 3:
case 4:
red_gamma = NUM2DBL(argv[0]);
green_gamma = NUM2DBL(argv[1]);
blue_gamma = NUM2DBL(argv[2]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 3)", argc);
break;
}
sprintf(gamma_arg, "%f,%f,%f", red_gamma, green_gamma, blue_gamma);
new_image = rm_clone_image(image);
(void) GammaImage(new_image, gamma_arg);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#gaussian_blur(*args) ⇒ Object
Method: Image#gaussian_blur(radius, sigma) Purpose: blur the image Returns: a new image
5312 5313 5314 5315 5316 |
# File 'ext/RMagick/rmimage.c', line 5312
VALUE
Image_gaussian_blur(int argc, VALUE *argv, VALUE self)
{
return effect_image(self, argc, argv, GaussianBlurImage);
}
|
#gaussian_blur_channel(*args) ⇒ Object
Method: Image#gaussian_blur_channel(radius=0, sigma=1, channel=AllChannels) Notes: new in IM 6.0.0
5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 |
# File 'ext/RMagick/rmimage.c', line 5323
VALUE
Image_gaussian_blur_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ChannelType channels;
ExceptionInfo exception;
double radius = 0.0, sigma = 1.0;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// There can be 0, 1, or 2 remaining arguments.
switch (argc)
{
case 2:
sigma = NUM2DBL(argv[1]);
/* Fall thru */
case 1:
radius = NUM2DBL(argv[0]);
/* Fall thru */
case 0:
break;
default:
raise_ChannelType_error(argv[argc-1]);
}
GetExceptionInfo(&exception);
new_image = GaussianBlurImageChannel(image, channels, radius, sigma, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#get_exif_by_entry(*entry) ⇒ Object
Retrieve EXIF data by entry or all. If one or more entry names specified, return the values associated with the entries. If no entries specified, return all entries and values. The return value is an array of [name,value] arrays.
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/RMagick.rb', line 845 def get_exif_by_entry(*entry) ary = Array.new if entry.length == 0 exif_data = self['EXIF:*'] if exif_data exif_data.split("\n").each { |exif| ary.push(exif.split('=')) } end else get_exif_by_entry() # ensure properties is populated with exif data entry.each do |name| rval = self["EXIF:#{name}"] ary.push([name, rval]) end end return ary end |
#get_exif_by_number(*tag) ⇒ Object
Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 |
# File 'lib/RMagick.rb', line 863 def get_exif_by_number(*tag) hash = Hash.new if tag.length == 0 exif_data = self['EXIF:!'] if exif_data exif_data.split("\n").each do |exif| tag, value = exif.split('=') tag = tag[1,4].hex hash[tag] = value end end else get_exif_by_number() # ensure properties is populated with exif data tag.each do |num| rval = self['#%04X' % num.to_i] hash[num] = rval == 'unknown' ? nil : rval end end return hash end |
#get_iptc_dataset(ds) ⇒ Object
Retrieve IPTC information by record number:dataset tag constant defined in Magick::IPTC, above.
886 887 888 |
# File 'lib/RMagick.rb', line 886 def get_iptc_dataset(ds) self['IPTC:'+ds] end |
#get_pixels(x_arg, y_arg, cols_arg, rows_arg) ⇒ Object
Method: Image#get_pixels(x, y, columns. rows) Purpose: Call AcquireImagePixels Returns: An array of Magick::Pixel objects corresponding to the pixels in
the rectangle defined by the geometry parameters.
Note: This is the complement of store_pixels. Notice that the
return value is an array object even when only one pixel is
returned.
store_pixels calls GetImagePixels, then SyncImage
5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 |
# File 'ext/RMagick/rmimage.c', line 5406
VALUE
Image_get_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg, VALUE rows_arg)
{
Image *image;
const PixelPacket *pixels;
ExceptionInfo exception;
long x, y;
unsigned long columns, rows;
long size, n;
VALUE pixel_ary;
image = rm_check_destroyed(self);
x = NUM2LONG(x_arg);
y = NUM2LONG(y_arg);
columns = NUM2ULONG(cols_arg);
rows = NUM2ULONG(rows_arg);
if ((x+columns) > image->columns || (y+rows) > image->rows)
{
rb_raise(rb_eRangeError, "geometry (%lux%lu%+ld%+ld) exceeds image bounds"
, columns, rows, x, y);
}
// Cast AcquireImagePixels to get rid of the const qualifier. We're not going
// to change the pixels but I don't want to make "pixels" const.
GetExceptionInfo(&exception);
#if defined(HAVE_GETVIRTUALPIXELS)
pixels = GetVirtualPixels(image, x, y, columns, rows, &exception);
#else
pixels = AcquireImagePixels(image, x, y, columns, rows, &exception);
#endif
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
// If the function failed, return a 0-length array.
if (!pixels)
{
return rb_ary_new();
}
// Allocate an array big enough to contain the PixelPackets.
size = (long)(columns * rows);
pixel_ary = rb_ary_new2(size);
// Convert the PixelPackets to Magick::Pixel objects
for (n = 0; n < size; n++)
{
rb_ary_store(pixel_ary, n, Pixel_from_PixelPacket(&pixels[n]));
}
return pixel_ary;
}
|
#gray? ⇒ Boolean
Method: Image#gray? Purpose: return true if all the pixels in the image have the same red,
green, and blue intensities.
5483 5484 5485 5486 5487 |
# File 'ext/RMagick/rmimage.c', line 5483
VALUE
Image_gray_q(VALUE self)
{
return has_attribute(self, (MagickBooleanType (*)(const Image *, ExceptionInfo *))IsGrayImage);
}
|
#grey? ⇒ Boolean
Method: Image#gray? Purpose: return true if all the pixels in the image have the same red,
green, and blue intensities.
5483 5484 5485 5486 5487 |
# File 'ext/RMagick/rmimage.c', line 5483
VALUE
Image_gray_q(VALUE self)
{
return has_attribute(self, (MagickBooleanType (*)(const Image *, ExceptionInfo *))IsGrayImage);
}
|
#histogram? ⇒ Boolean
Method: Image#histogram? Purpose: return true if has 1024 unique colors or less.
5494 5495 5496 5497 5498 |
# File 'ext/RMagick/rmimage.c', line 5494
VALUE
Image_histogram_q(VALUE self)
{
return has_attribute(self, IsHistogramImage);
}
|
#implode(*args) ⇒ Object
Method: Image#implode(amount=0.50) Purpose: implode the image by the specified percentage Returns: a new image
5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 |
# File 'ext/RMagick/rmimage.c', line 5506
VALUE
Image_implode(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double amount = 0.50;
ExceptionInfo exception;
switch (argc)
{
case 1:
amount = NUM2DBL(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
}
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = ImplodeImage(image, amount, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#import_pixels(*args) ⇒ Object
Method: Image#import_pixels Purpose: store image pixel data from an array Notes: See Image#export_pixels
5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 |
# File 'ext/RMagick/rmimage.c', line 5541
VALUE
Image_import_pixels(int argc, VALUE *argv, VALUE self)
{
Image *image;
long x_off, y_off;
unsigned long cols, rows;
unsigned long n, npixels;
long buffer_l;
char *map;
volatile VALUE pixel_arg, pixel_ary;
StorageType stg_type = CharPixel;
size_t type_sz, map_l;
Quantum *pixels = NULL;
double *fpixels = NULL;
void *buffer;
unsigned int okay;
image = rm_check_frozen(self);
switch (argc)
{
case 7:
VALUE_TO_ENUM(argv[6], stg_type, StorageType);
case 6:
x_off = NUM2LONG(argv[0]);
y_off = NUM2LONG(argv[1]);
cols = NUM2ULONG(argv[2]);
rows = NUM2ULONG(argv[3]);
map = StringValuePtr(argv[4]);
pixel_arg = argv[5];
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 6 or 7)", argc);
break;
}
if (x_off < 0 || y_off < 0 || cols <= 0 || rows <= 0)
{
rb_raise(rb_eArgError, "invalid import geometry");
}
map_l = strlen(map);
npixels = cols * rows * map_l;
// Assume that any object that responds to :to_str is a string buffer containing
// binary pixel data.
if (rb_respond_to(pixel_arg, rb_intern("to_str")))
{
buffer = (void *)rm_str2cstr(pixel_arg, &buffer_l);
switch (stg_type)
{
case CharPixel:
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);
break;
case FloatPixel:
type_sz = sizeof(float);
break;
case QuantumPixel:
type_sz = sizeof(Quantum);
break;
default:
rb_raise(rb_eArgError, "unsupported storage type %s", StorageType_name(stg_type));
break;
}
if (buffer_l % type_sz != 0)
{
rb_raise(rb_eArgError, "pixel buffer must be an exact multiple of the storage type size");
}
if ((buffer_l / type_sz) % map_l != 0)
{
rb_raise(rb_eArgError, "pixel buffer must contain an exact multiple of the map length");
}
if ((unsigned long)(buffer_l / type_sz) < npixels)
{
rb_raise(rb_eArgError, "pixel buffer too small (need %lu channel values, got %ld)"
, npixels, buffer_l/type_sz);
}
}
// Otherwise convert the argument to an array and convert the array elements
// to binary pixel data.
else
{
// rb_Array converts an object that is not an array to an array if possible,
// and raises TypeError if it can't. It usually is possible.
pixel_ary = rb_Array(pixel_arg);
if (RARRAY_LEN(pixel_ary) % map_l != 0)
{
rb_raise(rb_eArgError, "pixel array must contain an exact multiple of the map length");
}
if ((unsigned long)RARRAY_LEN(pixel_ary) < npixels)
{
rb_raise(rb_eArgError, "pixel array too small (need %lu elements, got %ld)"
, npixels, RARRAY_LEN(pixel_ary));
}
if (stg_type == DoublePixel || stg_type == FloatPixel)
{
// Get an array for double pixels. Use Ruby's memory so GC will clean up after
// us in case of an exception.
fpixels = ALLOC_N(double, npixels);
for (n = 0; n < npixels; n++)
{
fpixels[n] = NUM2DBL(rb_ary_entry(pixel_ary, n));
}
buffer = (void *) fpixels;
stg_type = DoublePixel;
}
else
{
// Get array for Quantum pixels. Use Ruby's memory so GC will clean up after us
// in case of an exception.
pixels = ALLOC_N(Quantum, npixels);
for (n = 0; n < npixels; n++)
{
volatile VALUE p = rb_ary_entry(pixel_ary, n);
pixels[n] = NUM2QUANTUM(p);
}
buffer = (void *) pixels;
stg_type = QuantumPixel;
}
}
okay = ImportImagePixels(image, x_off, y_off, cols, rows, map, stg_type, buffer);
// Free pixel array before checking for errors.
if (pixels)
{
xfree((void *)pixels);
}
if (fpixels)
{
xfree((void *)fpixels);
}
if (!okay)
{
rm_check_image_exception(image, RetainOnError);
// Shouldn't get here...
rm_magick_error("ImportImagePixels failed with no explanation.", NULL);
}
return self;
}
|
#initialize_copy(orig) ⇒ Object
Method: Image#initialize_copy Purpose: initialize copy, clone, dup
3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 |
# File 'ext/RMagick/rmimage.c', line 3309
VALUE
Image_init_copy(VALUE copy, VALUE orig)
{
Image *image, *new_image;
image = rm_check_destroyed(orig);
new_image = rm_clone_image(image);
UPDATE_DATA_PTR(copy, new_image);
return copy;
}
|
#inspect ⇒ Object
5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 |
# File 'ext/RMagick/rmimage.c', line 5839
VALUE
Image_inspect(VALUE self)
{
Image *image;
char buffer[MaxTextExtent]; // image description buffer
Data_Get_Struct(self, Image, image);
if (!image)
{
return rb_str_new2("#<Magick::Image: (destroyed)>");
}
build_inspect_string(image, buffer, sizeof(buffer));
return rb_str_new2(buffer);
}
|
#level(black_point = 0.0, white_point = nil, gamma = nil) ⇒ Object
(Thanks to Al Evans for the suggestion.)
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'lib/RMagick.rb', line 915 def level(black_point=0.0, white_point=nil, gamma=nil) black_point = Float(black_point) white_point ||= Magick::QuantumRange - black_point white_point = Float(white_point) gamma_arg = gamma gamma ||= 1.0 gamma = Float(gamma) if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs gamma, white_point = white_point, gamma unless gamma_arg white_point = Magick::QuantumRange - black_point end end return level2(black_point, white_point, gamma) end |
#level2 ⇒ Object
#level_channel(*args) ⇒ Object
Method: Image#level_channel(aChannelType, black=0, white=QuantumRange, gamma=1.0) Purpose: similar to Image#level but applies to a single channel only Notes: black and white are 0-QuantumRange, gamma is 0-10.
5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 |
# File 'ext/RMagick/rmimage.c', line 5979
VALUE
Image_level_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double black_point = 0.0, gamma_val = 1.0, white_point = (double)QuantumRange;
ChannelType channel;
image = rm_check_destroyed(self);
switch (argc)
{
case 1: // take all the defaults
break;
case 2:
black_point = NUM2DBL(argv[1]);
white_point = QuantumRange - black_point;
break;
case 3:
black_point = NUM2DBL(argv[1]);
white_point = NUM2DBL(argv[2]);
break;
case 4:
black_point = NUM2DBL(argv[1]);
white_point = NUM2DBL(argv[2]);
gamma_val = NUM2DBL(argv[3]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 4)", argc);
break;
}
VALUE_TO_ENUM(argv[0], channel, ChannelType);
new_image = rm_clone_image(image);
(void) LevelImageChannel(new_image, channel, black_point, white_point, gamma_val);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#level_colors(*args) ⇒ Object
Method: Image#level_colors(black_color=“black”, white_color=“white”, invert=true [, channel…]) Purpose: Implement +level_colors blank_color,white_color
6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 |
# File 'ext/RMagick/rmimage.c', line 6024
VALUE
Image_level_colors(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_LEVELIMAGECOLORS) || defined(HAVE_LEVELCOLORSIMAGECHANNEL)
Image *image, *new_image;
MagickPixelPacket black_color, white_color;
ChannelType channels;
ExceptionInfo exception;
MagickBooleanType invert = MagickTrue;
MagickBooleanType status;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
switch (argc)
{
case 3:
invert = RTEST(argv[2]);
case 2:
Color_to_MagickPixelPacket(image, &white_color, argv[1]);
Color_to_MagickPixelPacket(image, &black_color, argv[0]);
break;
case 1:
Color_to_MagickPixelPacket(image, &black_color, argv[0]);
GetExceptionInfo(&exception);
GetMagickPixelPacket(image, &white_color);
(void) QueryMagickColor("white", &white_color, &exception);
CHECK_EXCEPTION()
DestroyExceptionInfo(&exception);
case 0:
GetExceptionInfo(&exception);
GetMagickPixelPacket(image, &white_color);
(void) QueryMagickColor("white", &white_color, &exception);
CHECK_EXCEPTION()
GetMagickPixelPacket(image, &black_color);
(void) QueryMagickColor("black", &black_color, &exception);
CHECK_EXCEPTION()
DestroyExceptionInfo(&exception);
break;
default:
raise_ChannelType_error(argv[argc-1]);
break;
}
new_image = rm_clone_image(image);
#if defined(HAVE_LEVELCOLORSIMAGECHANNEL) // new in 6.5.6-4
status = LevelColorsImageChannel(new_image, channels, &black_color, &white_color, invert);
#else
status = LevelImageColors(new_image, channels, &black_color, &white_color, invert);
#endif
rm_check_image_exception(new_image, DestroyOnError);
if (!status)
{
rb_raise(rb_eRuntimeError, "LevelImageColors failed for unknown reason.");
}
return rm_image_new(new_image);
#else
rm_not_implemented();
self = self;
argc = argc;
argv = argv;
return(VALUE)0;
#endif
}
|
#levelize_channel(*args) ⇒ Object
Method: Image#levelize_channel(black_point[, white_point[, gamma=1.0[, channel…]])
6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 |
# File 'ext/RMagick/rmimage.c', line 6107
VALUE
Image_levelize_channel(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_LEVELIZEIMAGECHANNEL)
Image *image, *new_image;
ChannelType channels;
double black_point, white_point;
double gamma = 1.0;
MagickBooleanType status;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 3)
{
raise_ChannelType_error(argv[argc-1]);
}
switch (argc)
{
case 3:
gamma = NUM2DBL(argv[2]);
case 2:
white_point = NUM2DBL(argv[1]);
black_point = NUM2DBL(argv[0]);
break;
case 1:
black_point = NUM2DBL(argv[0]);
white_point = QuantumRange - black_point;
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or more)", argc);
break;
}
new_image = rm_clone_image(image);
status = LevelizeImageChannel(new_image, channels, black_point, white_point, gamma);
rm_check_image_exception(new_image, DestroyOnError);
if (!status)
{
rb_raise(rb_eRuntimeError, "LevelizeImageChannel failed for unknown reason.");
}
return rm_image_new(new_image);
#else
rm_not_implemented();
self = self;
argc = argc;
argv = argv;
return(VALUE)0;
#endif
}
|
#linear_stretch(*args) ⇒ Object
Method: Image_linear_stretch(black_point <, white_point>) Purpose: Call LinearStretchImage Notes: The default for white_point is #pixels-black_point.
See Image_contrast_stretch_channel.
6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 |
# File 'ext/RMagick/rmimage.c', line 6166
VALUE
Image_linear_stretch(int argc, VALUE *argv, VALUE self)
{
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);
new_image = rm_clone_image(image);
(void) LinearStretchImage(new_image, black_point, white_point);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#liquid_rescale(*args) ⇒ Object
Method: Image#liquid_rescale(columns, rows, delta_x=0.0, rigidity=0.0) Purpose: Call the LiquidRescaleImage API
6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 |
# File 'ext/RMagick/rmimage.c', line 6187
VALUE
Image_liquid_rescale(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_LIQUIDRESCALEIMAGE)
Image *image, *new_image;
unsigned long cols, rows;
double delta_x = 0.0;
double rigidity = 0.0;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 4:
rigidity = NUM2DBL(argv[3]);
case 3:
delta_x = NUM2DBL(argv[2]);
case 2:
rows = NUM2ULONG(argv[1]);
cols = NUM2ULONG(argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 4)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = LiquidRescaleImage(image, cols, rows, delta_x, rigidity, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
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
}
|
#magnify ⇒ Object
6340 6341 6342 6343 6344 6345 |
# File 'ext/RMagick/rmimage.c', line 6340
VALUE
Image_magnify(VALUE self)
{
(void) rm_check_destroyed(self);
return magnify(False, self, MagnifyImage);
}
|
#magnify! ⇒ Object
6348 6349 6350 6351 6352 6353 |
# File 'ext/RMagick/rmimage.c', line 6348
VALUE
Image_magnify_bang(VALUE self)
{
(void) rm_check_frozen(self);
return magnify(True, self, MagnifyImage);
}
|
#map(*args) ⇒ Object
Method: Image#map(map_image, dither=false) Purpose: Call MapImage Returns: a new image
6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 |
# File 'ext/RMagick/rmimage.c', line 6361
VALUE
Image_map(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
Image *map;
volatile VALUE map_obj, map_arg;
unsigned int dither = MagickFalse;
image = rm_check_destroyed(self);
#if defined(HAVE_REMAPIMAGE)
rb_warning("Image#map is deprecated. Use Image#remap instead");
#endif
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;
}
new_image = rm_clone_image(image);
map_obj = rm_cur_image(map_arg);
map = rm_check_destroyed(map_obj);
(void) MapImage(new_image, map, dither);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#marshal_dump ⇒ Object
Method: Image#marshal_dump Purpose: Support Marshal.dump >= 1.8 Returns: [img.filename, img.to_blob]
6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 |
# File 'ext/RMagick/rmimage.c', line 6403
VALUE
Image_marshal_dump(VALUE self)
{
Image *image;
Info *info;
unsigned char *blob;
size_t length;
VALUE ary;
ExceptionInfo exception;
image = rm_check_destroyed(self);
info = CloneImageInfo(NULL);
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to initialize Info object");
}
ary = rb_ary_new2(2);
if (image->filename)
{
rb_ary_store(ary, 0, rb_str_new2(image->filename));
}
else
{
rb_ary_store(ary, 0, Qnil);
}
GetExceptionInfo(&exception);
blob = ImageToBlob(info, image, &length, &exception);
// Destroy info before raising an exception
DestroyImageInfo(info);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
rb_ary_store(ary, 1, rb_str_new((char *)blob, (long)length));
magick_free((void*)blob);
return ary;
}
|
#marshal_load(ary) ⇒ Object
Method: Image#marshal_load Purpose: Support Marshal.load >= 1.8 Notes: On entry, ary is the array returned from marshal_dump.
6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 |
# File 'ext/RMagick/rmimage.c', line 6451
VALUE
Image_marshal_load(VALUE self, VALUE ary)
{
VALUE blob, filename;
Info *info;
Image *image;
ExceptionInfo exception;
info = CloneImageInfo(NULL);
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to initialize Info object");
}
filename = rb_ary_shift(ary);
blob = rb_ary_shift(ary);
GetExceptionInfo(&exception);
if (filename != Qnil)
{
strcpy(info->filename, RSTRING_PTR(filename));
}
image = BlobToImage(info, RSTRING_PTR(blob), RSTRING_LEN(blob), &exception);
// Destroy info before raising an exception
DestroyImageInfo(info);
CHECK_EXCEPTION();
(void) DestroyExceptionInfo(&exception);
UPDATE_DATA_PTR(self, image);
return self;
}
|
#mask(*args) ⇒ Object
Method: Image#mask() Purpose: associates a clip mask with the image Returns: Copy of the current clip-mask Notes: Omit the argument to get a copy of the current clip mask. Notes: pass “nil” for the mask-image to remove the current clip mask.
If the clip mask is not the same size as the target image,
resizes the clip mask to match the target.
Notes: Distinguish from Image#clip_mask=
6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 |
# File 'ext/RMagick/rmimage.c', line 6533
VALUE
Image_mask(int argc, VALUE *argv, VALUE self)
{
volatile VALUE mask;
Image *image, *mask_image, *resized_image;
Image *clip_mask;
long x, y;
PixelPacket *q;
ExceptionInfo exception;
image = rm_check_destroyed(self);
if (argc == 0)
{
return get_image_mask(image);
}
if (argc > 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (expected 0 or 1, got %d)", argc);
}
rb_check_frozen(self);
mask = argv[0];
if (mask != Qnil)
{
mask = rm_cur_image(mask);
mask_image = rm_check_destroyed(mask);
clip_mask = rm_clone_image(mask_image);
// Resize if necessary
if (clip_mask->columns != image->columns || clip_mask->rows != image->rows)
{
GetExceptionInfo(&exception);
resized_image = ResizeImage(clip_mask, image->columns, image->rows
, UndefinedFilter, 0.0, &exception);
rm_check_exception(&exception, resized_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(resized_image);
(void) DestroyImage(clip_mask);
clip_mask = resized_image;
}
// The following section is copied from mogrify.c (6.2.8-8)
#if defined(HAVE_SYNCAUTHENTICPIXELS)
GetExceptionInfo(&exception);
#endif
for (y = 0; y < (long) clip_mask->rows; y++)
{
#if defined(HAVE_GETAUTHENTICPIXELS)
q = GetAuthenticPixels(clip_mask, 0, y, clip_mask->columns, 1, &exception);
rm_check_exception(&exception, clip_mask, DestroyOnError);
#else
q = GetImagePixels(clip_mask, 0, y, clip_mask->columns, 1);
rm_check_image_exception(clip_mask, DestroyOnError);
#endif
if (!q)
{
break;
}
for (x = 0; x < (long) clip_mask->columns; x++)
{
if (clip_mask->matte == MagickFalse)
{
q->opacity = PIXEL_INTENSITY(q);
}
q->red = q->opacity;
q->green = q->opacity;
q->blue = q->opacity;
q += 1;
}
#if defined(HAVE_SYNCAUTHENTICPIXELS)
SyncAuthenticPixels(clip_mask, &exception);
rm_check_exception(&exception, clip_mask, DestroyOnError);
#else
SyncImagePixels(clip_mask);
rm_check_image_exception(clip_mask, DestroyOnError);
#endif
}
#if defined(HAVE_SYNCAUTHENTICPIXELS)
(void) DestroyExceptionInfo(&exception);
#endif
SetImageStorageClass(clip_mask, DirectClass);
rm_check_image_exception(clip_mask, DestroyOnError);
clip_mask->matte = MagickTrue;
// SetImageClipMask clones the clip_mask image. We can
// destroy our copy after SetImageClipMask is done with it.
(void) SetImageClipMask(image, clip_mask);
(void) DestroyImage(clip_mask);
}
else
{
(void) SetImageClipMask(image, NULL);
}
// Always return a copy of the mask!
return get_image_mask(image);
}
|
#matte_fill_to_border(x, y) ⇒ Object
Make transparent any neighbor pixel that is not the border color.
969 970 971 972 973 974 |
# File 'lib/RMagick.rb', line 969 def matte_fill_to_border(x, y) f = copy f.opacity = Magick::OpaqueOpacity unless f.matte f.matte_flood_fill(border_color, TransparentOpacity, x, y, FillToBorderMethod) end |
#matte_flood_fill(color, opacity, x_obj, y_obj, method_obj) ⇒ Object
Method: Image#matte_flood_fill(color, opacity, x, y, method_obj) Purpose: Call MatteFloodFillImage
6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 |
# File 'ext/RMagick/rmimage.c', line 6709
VALUE
Image_matte_flood_fill(VALUE self, VALUE color, VALUE opacity, VALUE x_obj, VALUE y_obj, VALUE method_obj)
{
Image *image, *new_image;
PixelPacket target;
Quantum op;
long x, y;
PaintMethod method;
image = rm_check_destroyed(self);
Color_to_PixelPacket(&target, color);
op = APP2QUANTUM(opacity);
VALUE_TO_ENUM(method_obj, method, PaintMethod);
if (!(method == FloodfillMethod || method == FillToBorderMethod))
{
rb_raise(rb_eArgError, "paint method_obj must be FloodfillMethod or "
"FillToBorderMethod (%d given)", method);
}
x = NUM2LONG(x_obj);
y = NUM2LONG(y_obj);
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);
}
new_image = rm_clone_image(image);
#if defined(HAVE_FLOODFILLPAINTIMAGE)
{
DrawInfo *draw_info;
MagickPixelPacket target_mpp;
MagickBooleanType invert;
// FloodfillPaintImage looks for the opacity in the DrawInfo.fill field.
draw_info = CloneDrawInfo(NULL, NULL);
if (!draw_info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
draw_info->fill.opacity = op;
if (method == FillToBorderMethod)
{
invert = MagickTrue;
target_mpp.red = (MagickRealType) image->border_color.red;
target_mpp.green = (MagickRealType) image->border_color.green;
target_mpp.blue = (MagickRealType) image->border_color.blue;
}
else
{
invert = MagickFalse;
target_mpp.red = (MagickRealType) target.red;
target_mpp.green = (MagickRealType) target.green;
target_mpp.blue = (MagickRealType) target.blue;
}
(void) FloodfillPaintImage(new_image, OpacityChannel, draw_info, &target_mpp, x, y, invert);
}
#else
(void) MatteFloodfillImage(new_image, target, op, x, y, method);
#endif
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#matte_floodfill(x, y) ⇒ Object
Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.
960 961 962 963 964 965 966 |
# File 'lib/RMagick.rb', line 960 def matte_floodfill(x, y) f = copy f.opacity = OpaqueOpacity unless f.matte target = f.pixel_color(x, y) f.matte_flood_fill(target, TransparentOpacity, x, y, FloodfillMethod) end |
#matte_point(x, y) ⇒ Object
Make the pixel at (x,y) transparent.
940 941 942 943 944 945 946 947 |
# File 'lib/RMagick.rb', line 940 def matte_point(x, y) f = copy f.opacity = OpaqueOpacity unless f.matte pixel = f.pixel_color(x,y) pixel.opacity = TransparentOpacity f.pixel_color(x, y, pixel) return f end |
#matte_replace(x, y) ⇒ Object
Make transparent all pixels that are the same color as the pixel at (x, y).
951 952 953 954 955 956 |
# File 'lib/RMagick.rb', line 951 def matte_replace(x, y) f = copy f.opacity = OpaqueOpacity unless f.matte target = f.pixel_color(x, y) f.transparent(target) end |
#matte_reset! ⇒ Object
Make all pixels transparent.
977 978 979 980 |
# File 'lib/RMagick.rb', line 977 def matte_reset! self.opacity = Magick::TransparentOpacity self end |
#median_filter(*args) ⇒ Object
Method: Image#median_filter(radius=0.0) Purpose: applies a digital filter that improves the quality of a noisy
image. Each pixel is replaced by the median in a set of
neighboring pixels as defined by radius.
Returns: a new image
6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 |
# File 'ext/RMagick/rmimage.c', line 6787
VALUE
Image_median_filter(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double radius = 0.0;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 1:
radius = NUM2DBL(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = MedianFilterImage(image, radius, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#minify ⇒ Object
Method: Image#minify
Image#minify!
Purpose: Scales an image proportionally to half its size Returns: minify: a new image 1/2x the size of the input image
minify!: self, 1/2x
6856 6857 6858 6859 6860 6861 |
# File 'ext/RMagick/rmimage.c', line 6856
VALUE
Image_minify(VALUE self)
{
(void) rm_check_destroyed(self);
return magnify(False, self, MinifyImage);
}
|
#minify! ⇒ Object
6864 6865 6866 6867 6868 6869 |
# File 'ext/RMagick/rmimage.c', line 6864
VALUE
Image_minify_bang(VALUE self)
{
(void) rm_check_frozen(self);
return magnify(True, self, MinifyImage);
}
|
#modulate(*args) ⇒ Object
Method: Image#modulate(<brightness<, saturation<, hue>>>) Purpose: control the brightness, saturation, and hue of an image Notes: all three arguments are optional and default to 100%
6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 |
# File 'ext/RMagick/rmimage.c', line 6877
VALUE
Image_modulate(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double pct_brightness = 100.0,
pct_saturation = 100.0,
pct_hue = 100.0;
char modulate[100];
image = rm_check_destroyed(self);
switch (argc)
{
case 3:
pct_hue = 100*NUM2DBL(argv[2]);
case 2:
pct_saturation = 100*NUM2DBL(argv[1]);
case 1:
pct_brightness = 100*NUM2DBL(argv[0]);
break;
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc);
break;
}
if (pct_brightness <= 0.0)
{
rb_raise(rb_eArgError, "brightness is %g%%, must be positive", pct_brightness);
}
sprintf(modulate, "%f%%,%f%%,%f%%", pct_brightness, pct_saturation, pct_hue);
new_image = rm_clone_image(image);
(void) ModulateImage(new_image, modulate);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#monochrome? ⇒ Boolean
Method: Image#monochrome? Purpose: return true if all the pixels in the image have the same red,
green, and blue intensities and the intensity is either 0 or
QuantumRange.
6951 6952 6953 6954 6955 |
# File 'ext/RMagick/rmimage.c', line 6951
VALUE
Image_monochrome_q(VALUE self)
{
return has_attribute(self, (MagickBooleanType (*)(const Image *, ExceptionInfo *))IsMonochromeImage);
}
|
#motion_blur(*args) ⇒ Object
Method: Image#motion_blur(radius=0.0, sigma=1.0, angle=0.0) Purpose: simulates motion blur. Convolves the image with a Gaussian
operator of the given radius and standard deviation (sigma).
For reasonable results, radius should be larger than sigma.
Use a radius of 0 and motion_blur selects a suitable radius
for you. Angle gives the angle of the blurring motion.
7022 7023 7024 7025 7026 7027 |
# File 'ext/RMagick/rmimage.c', line 7022
VALUE
Image_motion_blur(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_destroyed(self);
return motion_blur(argc, argv, self, MotionBlurImage);
}
|
#negate(*args) ⇒ Object
Method: Image#negate(grayscale=false) Purpose: negates the colors in the reference image. The grayscale option
means that only grayscale values within the image are negated.
Notes: The default for grayscale is false.
7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 |
# File 'ext/RMagick/rmimage.c', line 7037
VALUE
Image_negate(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
unsigned int grayscale = MagickFalse;
image = rm_check_destroyed(self);
if (argc == 1)
{
grayscale = RTEST(argv[0]);
}
else if (argc > 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
}
new_image = rm_clone_image(image);
(void) NegateImage(new_image, grayscale);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#negate_channel(*args) ⇒ Object
Method: Image#negate_channel(grayscale=false, channel=AllChannels) Returns a new image
7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 |
# File 'ext/RMagick/rmimage.c', line 7066
VALUE
Image_negate_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ChannelType channels;
unsigned int grayscale = MagickFalse;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// There can be at most 1 remaining argument.
if (argc > 1)
{
raise_ChannelType_error(argv[argc-1]);
}
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);
return rm_image_new(new_image);
}
|
#normalize ⇒ Object
Method: Image#normalize Purpose: enhances the contrast of a color image by adjusting the pixels
color to span the entire range of colors available
7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 |
# File 'ext/RMagick/rmimage.c', line 7199
VALUE
Image_normalize(VALUE self)
{
Image *image, *new_image;
image = rm_check_destroyed(self);
new_image = rm_clone_image(image);
(void) NormalizeImage(new_image);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#normalize_channel(*args) ⇒ Object
Method: Image#normalize_channel(channel=AllChannels) Purpose: Call NormalizeImageChannel
7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 |
# File 'ext/RMagick/rmimage.c', line 7218
VALUE
Image_normalize_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ChannelType channels;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// Ensure all arguments consumed.
if (argc > 0)
{
raise_ChannelType_error(argv[argc-1]);
}
new_image = rm_clone_image(image);
(void) NormalizeImageChannel(new_image, channels);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#oil_paint ⇒ Object
#opaque(target, fill) ⇒ Object
Method: Image#opaque(target-color-name, fill-color-name)
Image#opaque(target-pixel, fill-pixel)
Purpose: changes any pixel that matches target with the color defined by fill Notes: By default a pixel must match the specified target color exactly.
Use image.fuzz to set the amount of tolerance acceptable to consider
two colors as the same.
7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 |
# File 'ext/RMagick/rmimage.c', line 7315
VALUE
Image_opaque(VALUE self, VALUE target, VALUE fill)
{
Image *image, *new_image;
MagickPixelPacket target_pp;
MagickPixelPacket fill_pp;
MagickBooleanType okay;
image = rm_check_destroyed(self);
new_image = rm_clone_image(image);
// Allow color name or Pixel
Color_to_MagickPixelPacket(image, &target_pp, target);
Color_to_MagickPixelPacket(image, &fill_pp, fill);
#if defined(HAVE_OPAQUEPAINTIMAGECHANNEL)
okay = OpaquePaintImageChannel(new_image, DefaultChannels, &target_pp, &fill_pp, MagickFalse);
#else
okay = PaintOpaqueImageChannel(new_image, DefaultChannels, &target_pp, &fill_pp);
#endif
rm_check_image_exception(new_image, DestroyOnError);
if (!okay)
{
// Force exception
DestroyImage(new_image);
rm_ensure_result(NULL);
}
return rm_image_new(new_image);
}
|
#opaque? ⇒ Boolean
Method: Image#opaque? Purpose: return true if any of the pixels in the image have an opacity
value other than opaque ( 0 )
7427 7428 7429 7430 7431 |
# File 'ext/RMagick/rmimage.c', line 7427
VALUE
Image_opaque_q(VALUE self)
{
return has_attribute(self, IsOpaqueImage);
}
|
#opaque_channel(*args) ⇒ Object
Method: Image#opaque_channel Purpose: Improved Image#opaque available in 6.3.7-10 Notes: opaque_channel(target, fill, invert=false, fuzz=img.fuzz [, channel…])
7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 |
# File 'ext/RMagick/rmimage.c', line 7353
VALUE
Image_opaque_channel(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_OPAQUEPAINTIMAGECHANNEL)
Image *image, *new_image;
MagickPixelPacket target_pp, fill_pp;
ChannelType channels;
double keep, fuzz;
MagickBooleanType okay, invert = MagickFalse;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 4)
{
raise_ChannelType_error(argv[argc-1]);
}
// Default fuzz value is image's fuzz attribute.
fuzz = image->fuzz;
switch (argc)
{
case 4:
fuzz = NUM2DBL(argv[3]);
if (fuzz < 0.0)
{
rb_raise(rb_eArgError, "fuzz must be >= 0.0 (%g given)", fuzz);
}
case 3:
invert = RTEST(argv[2]);
case 2:
// Allow color name or Pixel
Color_to_MagickPixelPacket(image, &fill_pp, argv[1]);
Color_to_MagickPixelPacket(image, &target_pp, argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (got %d, expected 2 or more)", argc);
break;
}
new_image = rm_clone_image(image);
keep = new_image->fuzz;
new_image->fuzz = fuzz;
okay = OpaquePaintImageChannel(new_image, channels, &target_pp, &fill_pp, invert);
// Restore saved fuzz value
new_image->fuzz = keep;
rm_check_image_exception(new_image, DestroyOnError);
if (!okay)
{
// Force exception
DestroyImage(new_image);
rm_ensure_result(NULL);
}
return rm_image_new(new_image);
#else
argc = argc; // defeat "unused parameter" messages
argv = argv;
self = self;
rm_not_implemented();
return(VALUE)0;
#endif
}
|
#ordered_dither(*args) ⇒ Object
Method: Image#ordered_dither(threshold_map=‘2x2’) Purpose: perform ordered dither on image Notes: order must be 2, 3, or 4
(6.3.0) order can be any of the threshold strings listed
by "convert -list Thresholds" but the default is still "2x2".
I don't call OrderedDitherImages anymore. Sometime after
IM 6.0.0 it quit working. IM and GM use the routines I use
below to implement the "ordered-dither" option.
7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 |
# File 'ext/RMagick/rmimage.c', line 7444
VALUE
Image_ordered_dither(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
int order;
const char *threshold_map = "2x2";
ExceptionInfo exception;
image = rm_check_destroyed(self);
if (argc > 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
}
if (argc == 1)
{
if (TYPE(argv[0]) == T_STRING)
{
threshold_map = StringValuePtr(argv[0]);
}
else
{
order = NUM2INT(argv[0]);
if (order == 3)
{
threshold_map = "3x3";
}
else if (order == 4)
{
threshold_map = "4x4";
}
else if (order != 2)
{
rb_raise(rb_eArgError, "order must be 2, 3, or 4 (%d given)", order);
}
}
}
new_image = rm_clone_image(image);
GetExceptionInfo(&exception);
// ImageMagick >= 6.2.9
(void) OrderedPosterizeImage(new_image, threshold_map, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#paint_transparent(*args) ⇒ Object
Method: Image#paint_transparent(target, opacity=TransparentOpacity, invert=false, fuzz=img.fuzz) Purpose: Improved version of Image#transparent available in 6.3.7-10
7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 |
# File 'ext/RMagick/rmimage.c', line 7550
VALUE
Image_paint_transparent(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_TRANSPARENTPAINTIMAGE)
Image *image, *new_image;
MagickPixelPacket color;
Quantum opacity = TransparentOpacity;
double keep, fuzz;
MagickBooleanType okay, invert = MagickFalse;
image = rm_check_destroyed(self);
// Default fuzz value is image's fuzz attribute.
fuzz = image->fuzz;
switch (argc)
{
case 4:
fuzz = NUM2DBL(argv[3]);
case 3:
invert = RTEST(argv[2]);
case 2:
opacity = APP2QUANTUM(argv[1]);
case 1:
Color_to_MagickPixelPacket(image, &color, argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 4)", argc);
break;
}
new_image = rm_clone_image(image);
// Use fuzz value from caller
keep = new_image->fuzz;
new_image->fuzz = fuzz;
okay = TransparentPaintImage(new_image, (const MagickPixelPacket *)&color, opacity, invert);
new_image->fuzz = keep;
// Is it possible for TransparentPaintImage to silently fail?
rm_check_image_exception(new_image, DestroyOnError);
if (!okay)
{
// Force exception
DestroyImage(new_image);
rm_ensure_result(NULL);
}
return rm_image_new(new_image);
#else
argc = argc; // defeat "unused parameter" messages
argv = argv;
self = self;
rm_not_implemented();
return(VALUE)0;
#endif
}
|
#palette? ⇒ Boolean
Method: Image#palette? Purpose: return true if the image is PseudoClass and has 256 unique
colors or less.
7615 7616 7617 7618 7619 |
# File 'ext/RMagick/rmimage.c', line 7615
VALUE
Image_palette_q(VALUE self)
{
return has_attribute(self, IsPaletteImage);
}
|
#pixel_color(*args) ⇒ Object
Method: Image#pixel_color(x, y<, color>) Purpose: Gets/sets the color of the pixel at x,y Returns: Magick::Pixel for pixel x,y. If called to set a new
color, the return value is the old color.
Notes: “color”, if present, may be either a color name or a
Magick::Pixel.
Based on Magick++'s Magick::pixelColor methods
7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 |
# File 'ext/RMagick/rmimage.c', line 7644
VALUE
Image_pixel_color(int argc, VALUE *argv, VALUE self)
{
Image *image;
PixelPacket old_color, new_color, *pixel;
ExceptionInfo exception;
long x, y;
unsigned int set = False;
MagickBooleanType okay;
memset(&old_color, 0, sizeof(old_color));
image = rm_check_destroyed(self);
switch (argc)
{
case 3:
rb_check_frozen(self);
set = True;
// Replace with new color? The arg can be either a color name or
// a Magick::Pixel.
Color_to_PixelPacket(&new_color, argv[2]);
case 2:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
break;
}
x = NUM2LONG(argv[0]);
y = NUM2LONG(argv[1]);
// Get the color of a pixel
if (!set)
{
GetExceptionInfo(&exception);
#if defined(HAVE_GETVIRTUALPIXELS)
old_color = *GetVirtualPixels(image, x, y, 1, 1, &exception);
#else
old_color = *AcquireImagePixels(image, x, y, 1, 1, &exception);
#endif
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
// PseudoClass
if (image->storage_class == PseudoClass)
{
#if defined(HAVE_GETAUTHENTICINDEXQUEUE)
IndexPacket *indexes = GetAuthenticIndexQueue(image);
#else
IndexPacket *indexes = GetIndexes(image);
#endif
old_color = image->colormap[*indexes];
}
if (!image->matte)
{
old_color.opacity = OpaqueOpacity;
}
return Pixel_from_PixelPacket(&old_color);
}
// ImageMagick segfaults if the pixel location is out of bounds.
// Do what IM does and return the background color.
if (x < 0 || y < 0 || (unsigned long)x >= image->columns || (unsigned long)y >= image->rows)
{
return Pixel_from_PixelPacket(&image->background_color);
}
// Set the color of a pixel. Return previous color.
// Convert to DirectClass
if (image->storage_class == PseudoClass)
{
okay = SetImageStorageClass(image, DirectClass);
rm_check_image_exception(image, RetainOnError);
if (!okay)
{
rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't set pixel color.");
}
}
#if defined(HAVE_GETAUTHENTICPIXELS) || defined(HAVE_SYNCAUTHENTICPIXELS)
GetExceptionInfo(&exception);
#endif
#if defined(HAVE_GETAUTHENTICPIXELS)
pixel = GetAuthenticPixels(image, x, y, 1, 1, &exception);
CHECK_EXCEPTION()
#else
pixel = GetImagePixels(image, x, y, 1, 1);
rm_check_image_exception(image, RetainOnError);
#endif
if (pixel)
{
old_color = *pixel;
if (!image->matte)
{
old_color.opacity = OpaqueOpacity;
}
}
*pixel = new_color;
#if defined(HAVE_SYNCAUTHENTICPIXELS)
SyncAuthenticPixels(image, &exception);
CHECK_EXCEPTION()
#else
SyncImagePixels(image);
rm_check_image_exception(image, RetainOnError);
#endif
#if defined(HAVE_GETAUTHENTICPIXELS) || defined(HAVE_SYNCAUTHENTICPIXELS)
(void) DestroyExceptionInfo(&exception);
#endif
return Pixel_from_PixelPacket(&old_color);
}
|
#polaroid(*args) ⇒ Object
Method: Image#polaroid() Purpose: Call PolaroidImage Notes: Accepts an options block to get Draw attributes for drawing
the label. Specify self.border_color to set a non-default
border color.
7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 |
# File 'ext/RMagick/rmimage.c', line 7794
VALUE
Image_polaroid(int argc, VALUE *argv, VALUE self)
{
Image *image, *clone, *new_image;
volatile VALUE options;
double angle = -5.0;
Draw *draw;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 1:
angle = NUM2DBL(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
break;
}
options = rm_polaroid_new();
Data_Get_Struct(options, Draw, draw);
clone = rm_clone_image(image);
clone->background_color = draw->shadow_color;
clone->border_color = draw->info->border_color;
GetExceptionInfo(&exception);
new_image = PolaroidImage(clone, draw->info, angle, &exception);
rm_check_exception(&exception, clone, DestroyOnError);
(void) DestroyImage(clone);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#posterize(*args) ⇒ Object
Method: posterize Purpose: call PosterizeImage Notes: Image#posterize(levels=4, dither=false)
7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 |
# File 'ext/RMagick/rmimage.c', line 7841
VALUE
Image_posterize(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
MagickBooleanType dither = MagickFalse;
unsigned long levels = 4;
image = rm_check_destroyed(self);
switch (argc)
{
case 2:
dither = (MagickBooleanType) RTEST(argv[1]);
/* fall through */
case 1:
levels = NUM2ULONG(argv[0]);
/* fall through */
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc);
}
new_image = rm_clone_image(image);
(void) PosterizeImage(new_image, levels, dither);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#preview(preview) ⇒ Object
Method: preview Purpose: Call PreviewImage
7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 |
# File 'ext/RMagick/rmimage.c', line 7876
VALUE
Image_preview(VALUE self, VALUE preview)
{
Image *image, *new_image;
PreviewType preview_type;
ExceptionInfo exception;
GetExceptionInfo(&exception);
image = rm_check_destroyed(self);
VALUE_TO_ENUM(preview, preview_type, PreviewType);
new_image = PreviewImage(image, preview_type, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#profile!(name, profile) ⇒ Object
Method: Image#profile!(name, profile) Purpose: If “profile” is nil, deletes the profile. Otherwise “profile”
must be a string containing the specified profile.
7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 |
# File 'ext/RMagick/rmimage.c', line 7903
VALUE
Image_profile_bang(VALUE self, VALUE name, VALUE profile)
{
if (profile == Qnil)
{
return Image_delete_profile(self, name);
}
else
{
return set_profile(self, StringValuePtr(name), profile);
}
}
|
#properties ⇒ Object
Method: Image#properties [{ |k,v| block }] Purpose: Traverse the attributes and yield to the block.
If no block, return a hash of all the attribute
keys & values
Notes: I use the word “properties” to distinguish between
these "user-added" attribute strings and Image
object attributes.
9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 |
# File 'ext/RMagick/rmimage.c', line 9145
VALUE
Image_properties(VALUE self)
{
Image *image;
volatile VALUE attr_hash;
volatile VALUE ary;
char *property;
const char *value;
image = rm_check_destroyed(self);
if (rb_block_given_p())
{
ary = rb_ary_new2(2);
ResetImagePropertyIterator(image);
property = GetNextImageProperty(image);
while (property)
{
value = GetImageProperty(image, property);
(void) rb_ary_store(ary, 0, rb_str_new2(property));
(void) rb_ary_store(ary, 1, rb_str_new2(value));
(void) rb_yield(ary);
property = GetNextImageProperty(image);
}
rm_check_image_exception(image, RetainOnError);
return self;
}
// otherwise return properties hash
else
{
attr_hash = rb_hash_new();
ResetImagePropertyIterator(image);
property = GetNextImageProperty(image);
while (property)
{
value = GetImageProperty(image, property);
(void) rb_hash_aset(attr_hash, rb_str_new2(property), rb_str_new2(value));
property = GetNextImageProperty(image);
}
rm_check_image_exception(image, RetainOnError);
return attr_hash;
}
}
|
#quantize(*args) ⇒ Object
Method: Image#quantize(<number_colors<, colorspace<, dither<, tree_depth<, measure_error>>>>>)
defaults: 256, Magick::RGBColorspace, true, 0, false
Purpose: call QuantizeImage
8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 |
# File 'ext/RMagick/rmimage.c', line 8115
VALUE
Image_quantize(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
QuantizeInfo quantize_info;
image = rm_check_destroyed(self);
GetQuantizeInfo(&quantize_info);
switch (argc)
{
case 5:
quantize_info.measure_error = (MagickBooleanType) RTEST(argv[4]);
case 4:
quantize_info.tree_depth = NUM2UINT(argv[3]);
case 3:
#if defined(HAVE_TYPE_DITHERMETHOD) && defined(HAVE_ENUM_NODITHERMETHOD)
if (rb_obj_is_kind_of(argv[2], Class_DitherMethod))
{
VALUE_TO_ENUM(argv[2], quantize_info.dither_method, DitherMethod);
quantize_info.dither = quantize_info.dither_method != NoDitherMethod;
}
#else
quantize_info.dither = (MagickBooleanType) RTEST(argv[2]);
#endif
case 2:
VALUE_TO_ENUM(argv[1], quantize_info.colorspace, ColorspaceType);
case 1:
quantize_info.number_colors = NUM2UINT(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 5)", argc);
break;
}
new_image = rm_clone_image(image);
(void) QuantizeImage(&quantize_info, new_image);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#quantum_operator(*args) ⇒ Object
Method: Image#quantum_operator(operator, rvalue[, channel] ) Purpose: This method is an adapter method that calls the
EvaluateImageChannel method
Note 1: Historically this method used QuantumOperatorRegionImage
in GraphicsMagick. By necessity this method implements
the "lowest common denominator" of the two implementations.
Note 2: If the channel argument is omitted, the default is AllChannels.
7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 |
# File 'ext/RMagick/rmimage.c', line 7954
VALUE
Image_quantum_operator(int argc, VALUE *argv, VALUE self)
{
Image *image;
QuantumExpressionOperator operator;
MagickEvaluateOperator qop;
double rvalue;
ChannelType channel;
ExceptionInfo exception;
image = rm_check_destroyed(self);
// The default channel is AllChannels
channel = AllChannels;
/*
If there are 3 arguments, argument 2 is a ChannelType argument.
Arguments 1 and 0 are required and are the rvalue and operator,
respectively.
*/
switch (argc)
{
case 3:
VALUE_TO_ENUM(argv[2], channel, ChannelType);
/* Fall through */
case 2:
rvalue = NUM2DBL(argv[1]);
VALUE_TO_ENUM(argv[0], operator, QuantumExpressionOperator);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
break;
}
// Map QuantumExpressionOperator to MagickEvaluateOperator
switch (operator)
{
default:
case UndefinedQuantumOperator:
qop = UndefinedEvaluateOperator;
break;
case AddQuantumOperator:
qop = AddEvaluateOperator;
break;
case AndQuantumOperator:
qop = AndEvaluateOperator;
break;
case DivideQuantumOperator:
qop = DivideEvaluateOperator;
break;
case LShiftQuantumOperator:
qop = LeftShiftEvaluateOperator;
break;
case MaxQuantumOperator:
qop = MaxEvaluateOperator;
break;
case MinQuantumOperator:
qop = MinEvaluateOperator;
break;
case MultiplyQuantumOperator:
qop = MultiplyEvaluateOperator;
break;
case OrQuantumOperator:
qop = OrEvaluateOperator;
break;
case RShiftQuantumOperator:
qop = RightShiftEvaluateOperator;
break;
case SubtractQuantumOperator:
qop = SubtractEvaluateOperator;
break;
case XorQuantumOperator:
qop = XorEvaluateOperator;
break;
#if defined(HAVE_ENUM_POWEVALUATEOPERATOR)
case PowQuantumOperator:
qop = PowEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_LOGEVALUATEOPERATOR)
case LogQuantumOperator:
qop = LogEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_THRESHOLDEVALUATEOPERATOR)
case ThresholdQuantumOperator:
qop = ThresholdEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_THRESHOLDBLACKEVALUATEOPERATOR)
case ThresholdBlackQuantumOperator:
qop = ThresholdBlackEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_THRESHOLDWHITEEVALUATEOPERATOR)
case ThresholdWhiteQuantumOperator:
qop = ThresholdWhiteEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_GAUSSIANNOISEEVALUATEOPERATOR)
case GaussianNoiseQuantumOperator:
qop = GaussianNoiseEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_IMPULSENOISEEVALUATEOPERATOR)
case ImpulseNoiseQuantumOperator:
qop = ImpulseNoiseEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_LAPLACIANNOISEEVALUATEOPERATOR)
case LaplacianNoiseQuantumOperator:
qop = LaplacianNoiseEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_MULTIPLICATIVENOISEEVALUATEOPERATOR)
case MultiplicativeNoiseQuantumOperator:
qop = MultiplicativeNoiseEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_POISSONNOISEEVALUATEOPERATOR)
case PoissonNoiseQuantumOperator:
qop = PoissonNoiseEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_UNIFORMNOISEEVALUATEOPERATOR)
case UniformNoiseQuantumOperator:
qop = UniformNoiseEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_COSINEEVALUATEOPERATOR)
case CosineQuantumOperator:
qop = CosineEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_SINEEVALUATEOPERATOR)
case SineQuantumOperator:
qop = SineEvaluateOperator;
break;
#endif
#if defined(HAVE_ENUM_ADDMODULUSEVALUATEOPERATOR)
case AddModulusQuantumOperator:
qop = AddModulusEvaluateOperator;
break;
#endif
}
GetExceptionInfo(&exception);
(void) EvaluateImageChannel(image, channel, qop, rvalue, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
return self;
}
|
#radial_blur(angle) ⇒ Object
Method: Image#radial_blur(angle) Purpose: Call RadialBlurImage Notes: Angle is in degrees
8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 |
# File 'ext/RMagick/rmimage.c', line 8165
VALUE
Image_radial_blur(VALUE self, VALUE angle)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = RadialBlurImage(image, NUM2DBL(angle), &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#radial_blur_channel(*args) ⇒ Object
Method: Image#radial_blur_channel(angle[, channel..]) Purpose: Call RadialBlurImageChannel Notes: Angle is in degrees
8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 |
# File 'ext/RMagick/rmimage.c', line 8190
VALUE
Image_radial_blur_channel(
int argc,
VALUE *argv,
VALUE self)
{
Image *image, *new_image;
ExceptionInfo exception;
ChannelType channels;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// There must be 1 remaining argument.
if (argc == 0)
{
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1 or more)");
}
else if (argc > 1)
{
raise_ChannelType_error(argv[argc-1]);
}
GetExceptionInfo(&exception);
new_image = RadialBlurImageChannel(image, channels, NUM2DBL(argv[0]), &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#raise(*args) ⇒ Object
Method: Image#raise(width=6, height=6, raised=true) Purpose: creates a simulated three-dimensional button-like effect by
lightening and darkening the edges of the image. The "width"
and "height" arguments define the width of the vertical and
horizontal edge of the effect. If "raised" is true, creates
a raised effect, otherwise a lowered effect.
Returns: a new image
8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 |
# File 'ext/RMagick/rmimage.c', line 8278
VALUE
Image_raise(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
RectangleInfo rect;
int raised = MagickTrue; // default
memset(&rect, 0, sizeof(rect));
rect.width = 6; // default
rect.height = 6; // default
image = rm_check_destroyed(self);
switch (argc)
{
case 3:
raised = RTEST(argv[2]);
case 2:
rect.height = NUM2ULONG(argv[1]);
case 1:
rect.width = NUM2ULONG(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc);
break;
}
new_image = rm_clone_image(image);
(void) RaiseImage(new_image, &rect, raised);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#random_threshold_channel(*args) ⇒ Object
Method: Image#random_threshold_channel PUrpose: Call RandomThresholdImageChannel
8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 |
# File 'ext/RMagick/rmimage.c', line 8229
VALUE
Image_random_threshold_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ChannelType channels;
char *thresholds;
volatile VALUE geom_str;
ExceptionInfo exception;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// There must be 1 remaining argument.
if (argc == 0)
{
rb_raise(rb_eArgError, "missing threshold argument");
}
else if (argc > 1)
{
raise_ChannelType_error(argv[argc-1]);
}
// Accept any argument that has a to_s method.
geom_str = rm_to_s(argv[0]);
thresholds = StringValuePtr(geom_str);
new_image = rm_clone_image(image);
GetExceptionInfo(&exception);
(void) RandomThresholdImageChannel(new_image, channels, thresholds, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#recolor(color_matrix) ⇒ Object
Method: Image#recolor(matrix) Purpose: Call RecolorImage
8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 |
# File 'ext/RMagick/rmimage.c', line 8398
VALUE
Image_recolor(VALUE self, VALUE color_matrix)
{
Image *image, *new_image;
unsigned long order;
long x, len;
double *matrix;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
// Allocate color matrix from Ruby's memory
len = RARRAY_LEN(color_matrix);
matrix = ALLOC_N(double, len);
for (x = 0; x < len; x++)
{
matrix[x] = NUM2DBL(rb_ary_entry(color_matrix, x));
}
order = (unsigned long)sqrt((double)(len + 1.0));
// RecolorImage sets the ExceptionInfo and returns a NULL image if an error occurs.
new_image = RecolorImage(image, order, matrix, &exception);
xfree((void *)matrix);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#reduce_noise(radius) ⇒ Object
Method: Image#reduce_noise(radius) Purpose: smooths the contours of an image while still preserving edge information Returns: a new image
8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 |
# File 'ext/RMagick/rmimage.c', line 8525
VALUE
Image_reduce_noise(VALUE self, VALUE radius)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = ReduceNoiseImage(image, NUM2DBL(radius), &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#remap(*args) ⇒ Object Also known as: affinity
Method: Image#remap(remap_image, dither_method=RiemersmaDitherMethod) Purpose: Call RemapImage Notes: Immediate - modifies image in-place
8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 |
# File 'ext/RMagick/rmimage.c', line 8548
VALUE
Image_remap(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_REMAPIMAGE) || defined(HAVE_AFFINITYIMAGE)
Image *image, *remap_image;
QuantizeInfo quantize_info;
image = rm_check_frozen(self);
if (argc > 0)
{
volatile VALUE t = rm_cur_image(argv[0]);
remap_image = rm_check_destroyed(t);
}
GetQuantizeInfo(&quantize_info);
switch (argc)
{
case 2:
VALUE_TO_ENUM(argv[1], quantize_info.dither_method, DitherMethod);
quantize_info.dither = MagickTrue;
break;
case 1:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
break;
}
#if defined(HAVE_REMAPIMAGE)
(void) RemapImage(&quantize_info, image, remap_image);
#else
(void) AffinityImage(&quantize_info, image, remap_image);
#endif
rm_check_image_exception(image, RetainOnError);
return self;
#else
self = self;
argc = argc;
argv = argv;
rm_not_implemented();
return(VALUE)0;
#endif
}
|
#resample(x_res = 72.0, y_res = nil) ⇒ Object
Corresponds to ImageMagick’s -resample option
983 984 985 986 987 988 989 990 |
# File 'lib/RMagick.rb', line 983 def resample(x_res=72.0, y_res=nil) y_res ||= x_res width = x_res * columns / x_resolution + 0.5 height = y_res * rows / y_resolution + 0.5 self.x_resolution = x_res self.y_resolution = y_res resize(width, height) end |
#resize(*args) ⇒ Object
8700 8701 8702 8703 8704 8705 |
# File 'ext/RMagick/rmimage.c', line 8700
VALUE
Image_resize(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_destroyed(self);
return resize(False, argc, argv, self);
}
|
#resize!(*args) ⇒ Object
8708 8709 8710 8711 8712 8713 |
# File 'ext/RMagick/rmimage.c', line 8708
VALUE
Image_resize_bang(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_frozen(self);
return resize(True, argc, argv, self);
}
|
#resize_to_fill(ncols, nrows = nil, gravity = CenterGravity) ⇒ Object Also known as: crop_resized
Force an image to exact dimensions without changing the aspect ratio. Resize and crop if necessary. (Thanks to Jerett Taylor!)
994 995 996 |
# File 'lib/RMagick.rb', line 994 def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity) copy.resize_to_fill!(ncols, nrows, gravity) end |
#resize_to_fill!(ncols, nrows = nil, gravity = CenterGravity) ⇒ Object Also known as: crop_resized!
998 999 1000 1001 1002 1003 1004 1005 1006 |
# File 'lib/RMagick.rb', line 998 def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity) nrows ||= ncols if ncols != columns || nrows != rows scale = [ncols/columns.to_f, nrows/rows.to_f].max resize!(scale*columns+0.5, scale*rows+0.5) end crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows self end |
#resize_to_fit(cols, rows = nil) ⇒ Object
Convenience method to resize retaining the aspect ratio. (Thanks to Robert Manni!)
1014 1015 1016 1017 1018 1019 |
# File 'lib/RMagick.rb', line 1014 def resize_to_fit(cols, rows=nil) rows ||= cols change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| resize(ncols, nrows) end end |
#resize_to_fit!(cols, rows = nil) ⇒ Object
1021 1022 1023 1024 1025 1026 |
# File 'lib/RMagick.rb', line 1021 def resize_to_fit!(cols, rows=nil) rows ||= cols change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| resize!(ncols, nrows) end end |
#roll(x_offset, y_offset) ⇒ Object
Method: Image#roll(x_offset, y_offset) Purpose: offsets an image as defined by x_offset and y_offset Returns: a rolled copy of the input image
8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 |
# File 'ext/RMagick/rmimage.c', line 8721
VALUE
Image_roll(VALUE self, VALUE x_offset, VALUE y_offset)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = RollImage(image, NUM2LONG(x_offset), NUM2LONG(y_offset), &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#rotate(*args) ⇒ Object
8803 8804 8805 8806 8807 8808 |
# File 'ext/RMagick/rmimage.c', line 8803
VALUE
Image_rotate(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_destroyed(self);
return rotate(False, argc, argv, self);
}
|
#rotate!(*args) ⇒ Object
8811 8812 8813 8814 8815 8816 |
# File 'ext/RMagick/rmimage.c', line 8811
VALUE
Image_rotate_bang(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_frozen(self);
return rotate(True, argc, argv, self);
}
|
#sample ⇒ Object
#sample!(*args) ⇒ Object
8837 8838 8839 8840 8841 8842 |
# File 'ext/RMagick/rmimage.c', line 8837
VALUE
Image_sample_bang(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_frozen(self);
return scale(True, argc, argv, self, SampleImage);
}
|
#scale(*args) ⇒ Object
Method: Image#scale(scale) or (cols, rows)
Image#scale!
Purpose: changes the size of an image to the given dimensions Returns: scale: a scaled copy of the input image
scale!: self, scaled
8852 8853 8854 8855 8856 8857 |
# File 'ext/RMagick/rmimage.c', line 8852
VALUE
Image_scale(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_destroyed(self);
return scale(False, argc, argv, self, ScaleImage);
}
|
#scale!(*args) ⇒ Object
8860 8861 8862 8863 8864 8865 |
# File 'ext/RMagick/rmimage.c', line 8860
VALUE
Image_scale_bang(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_frozen(self);
return scale(True, argc, argv, self, ScaleImage);
}
|
#segment(*args) ⇒ Object
Method: Image#segment(colorspace=RGBColorspace,
cluster_threshold=1.0,
smoothing_threshold=1.5,
verbose=false)
Purpose: Call SegmentImage Notes: the default values are the same as Magick++
9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 |
# File 'ext/RMagick/rmimage.c', line 9081
VALUE
Image_segment(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
int colorspace = RGBColorspace; // These are the Magick++ defaults
unsigned int verbose = MagickFalse;
double cluster_threshold = 1.0;
double smoothing_threshold = 1.5;
image = rm_check_destroyed(self);
switch (argc)
{
case 4:
verbose = RTEST(argv[3]);
case 3:
smoothing_threshold = NUM2DBL(argv[2]);
case 2:
cluster_threshold = NUM2DBL(argv[1]);
case 1:
VALUE_TO_ENUM(argv[0], colorspace, ColorspaceType);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc);
break;
}
new_image = rm_clone_image(image);
(void) SegmentImage(new_image, colorspace, verbose, cluster_threshold, smoothing_threshold);
rm_check_image_exception(new_image, DestroyOnError);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#selective_blur_channel ⇒ Object
#separate(*args) ⇒ Object
Method: separate(channel[, channel…]) Purpose: call SeparateImages Returns: returns a new ImageList
9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 |
# File 'ext/RMagick/rmimage.c', line 9012
VALUE
Image_separate(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_images;
ChannelType channels = 0;
ExceptionInfo exception;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// All arguments are ChannelType enums
if (argc > 0)
{
raise_ChannelType_error(argv[argc-1]);
}
GetExceptionInfo(&exception);
new_images = SeparateImages(image, channels, &exception);
rm_check_exception(&exception, new_images, DestroyOnError);
DestroyExceptionInfo(&exception);
rm_ensure_result(new_images);
return rm_imagelist_from_images(new_images);
}
|
#sepiatone(*args) ⇒ Object
Method: Image#sepiatone(threshold=QuantumRange) Purpose: Call SepiaToneImage
9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 |
# File 'ext/RMagick/rmimage.c', line 9042
VALUE
Image_sepiatone(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double threshold = (double) QuantumRange;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 1:
threshold = NUM2DBL(argv[0]);
break;
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
}
GetExceptionInfo(&exception);
new_image = SepiaToneImage(image, threshold, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#set_channel_depth(channel_arg, depth) ⇒ Object
Method: Image#set_channel_depth(channel, depth) Purpose: Call SetImageChannelDepth
8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 |
# File 'ext/RMagick/rmimage.c', line 8988
VALUE
Image_set_channel_depth(VALUE self, VALUE channel_arg, VALUE depth)
{
Image *image;
ChannelType channel;
unsigned long channel_depth;
image = rm_check_frozen(self);
VALUE_TO_ENUM(channel_arg, channel, ChannelType);
channel_depth = NUM2ULONG(depth);
(void) SetImageChannelDepth(image, channel, channel_depth);
rm_check_image_exception(image, RetainOnError);
return self;
}
|
#shade(*args) ⇒ Object
Method: Image#shade(shading=false, azimuth=30, elevation=30) Purpose: shines a distant light on an image to create a three-dimensional
effect. You control the positioning of the light with azimuth
and elevation; azimuth is measured in degrees off the x axis
and elevation is measured in pixels above the Z axis
Returns: a new image
9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 |
# File 'ext/RMagick/rmimage.c', line 9201
VALUE
Image_shade(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double azimuth = 30.0, elevation = 30.0;
unsigned int shading=MagickFalse;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 3:
elevation = NUM2DBL(argv[2]);
case 2:
azimuth = NUM2DBL(argv[1]);
case 1:
shading = RTEST(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = ShadeImage(image, shading, azimuth, elevation, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#shadow(*args) ⇒ Object
Method: Image#shadow(x_offset=4, y_offset=4, sigma=4.0, opacity=1.0)
x- and y-offsets are the pixel offset
opacity is either a number between 0 and 1 or a string "NN%"
sigma is the std. dev. of the Gaussian, in pixels.
Purpose: Call ShadowImage Notes: The defaults are taken from the mogrify.c source, except
for opacity, which has no default.
Introduced in 6.1.7
9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 |
# File 'ext/RMagick/rmimage.c', line 9246
VALUE
Image_shadow(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double opacity = 100.0;
double sigma = 4.0;
long x_offset = 4L;
long y_offset = 4L;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 4:
opacity = rm_percentage(argv[3]); // Clamp to 1.0 < x <= 100.0
if (fabs(opacity) < 0.01)
{
rb_warning("shadow will be transparent - opacity %g very small", opacity);
}
opacity = FMIN(opacity, 1.0);
opacity = FMAX(opacity, 0.01);
opacity *= 100.0;
case 3:
sigma = NUM2DBL(argv[2]);
case 2:
y_offset = NUM2LONG(argv[1]);
case 1:
x_offset = NUM2LONG(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = ShadowImage(image, opacity, sigma, x_offset, y_offset, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#sharpen(*args) ⇒ Object
Method: Image#sharpen(radius=0, sigma=1) Purpose: sharpens an image Returns: a new image
9297 9298 9299 9300 9301 |
# File 'ext/RMagick/rmimage.c', line 9297
VALUE
Image_sharpen(int argc, VALUE *argv, VALUE self)
{
return effect_image(self, argc, argv, SharpenImage);
}
|
#sharpen_channel(*args) ⇒ Object
Method: Image#sharpen_channel(radius=0, sigma=1, channel=AllChannels) Returns: a new image
9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 |
# File 'ext/RMagick/rmimage.c', line 9308
VALUE
Image_sharpen_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ChannelType channels;
ExceptionInfo exception;
double radius = 0.0, sigma = 1.0;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
// There must be 0, 1, or 2 remaining arguments.
switch (argc)
{
case 2:
sigma = NUM2DBL(argv[1]);
/* Fall thru */
case 1:
radius = NUM2DBL(argv[0]);
/* Fall thru */
case 0:
break;
default:
raise_ChannelType_error(argv[argc-1]);
}
new_image = rm_clone_image(image);
GetExceptionInfo(&exception);
(void) SharpenImageChannel(new_image, channels, radius, sigma, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#shave(width, height) ⇒ Object
Method: Image#shave(width, height)
Image#shave!(width, height)
Purpose: shaves pixels from the image edges, leaving a rectangle
of the specified width & height in the center
Returns: shave: a new image
shave!: self, shaved
9354 9355 9356 9357 9358 9359 |
# File 'ext/RMagick/rmimage.c', line 9354
VALUE
Image_shave(VALUE self, VALUE width, VALUE height)
{
(void) rm_check_destroyed(self);
return xform_image(False, self, INT2FIX(0), INT2FIX(0), width, height, ShaveImage);
}
|
#shave!(width, height) ⇒ Object
9362 9363 9364 9365 9366 9367 |
# File 'ext/RMagick/rmimage.c', line 9362
VALUE
Image_shave_bang(VALUE self, VALUE width, VALUE height)
{
(void) rm_check_frozen(self);
return xform_image(True, self, INT2FIX(0), INT2FIX(0), width, height, ShaveImage);
}
|
#shear(x_shear, y_shear) ⇒ Object
Method: Image#shear(x_shear, y_shear) Purpose: Calls ShearImage Notes: shear angles are measured in degrees Returns: a new image
9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 |
# File 'ext/RMagick/rmimage.c', line 9376
VALUE
Image_shear(VALUE self, VALUE x_shear, VALUE y_shear)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#sigmoidal_contrast_channel(*args) ⇒ Object
Method: Image#sigmoidal_contrast_channel(contrast=3.0, midpoint=50.0,
sharpen=false [, channel=AllChannels]);
9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 |
# File 'ext/RMagick/rmimage.c', line 9399
VALUE
Image_sigmoidal_contrast_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
MagickBooleanType sharpen = MagickFalse;
double contrast = 3.0;
double midpoint = 50.0;
ChannelType channels;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
switch (argc)
{
case 3:
sharpen = (MagickBooleanType) RTEST(argv[2]);
case 2:
midpoint = NUM2DBL(argv[1]);
case 1:
contrast = NUM2DBL(argv[0]);
case 0:
break;
default:
raise_ChannelType_error(argv[argc-1]);
break;
}
new_image = rm_clone_image(image);
(void) SigmoidalContrastImageChannel(new_image, channels, sharpen, contrast, midpoint);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#signature ⇒ Object
Method: Image#signature Purpose: computes a message digest from an image pixel stream with an
implementation of the NIST SHA-256 Message Digest algorithm.
9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 |
# File 'ext/RMagick/rmimage.c', line 9440
VALUE
Image_signature(VALUE self)
{
Image *image;
const char *signature;
image = rm_check_destroyed(self);
(void) SignatureImage(image);
signature = rm_get_property(image, "signature");
rm_check_image_exception(image, RetainOnError);
if (!signature)
{
return Qnil;
}
return rb_str_new(signature, 64);
}
|
#sketch(*args) ⇒ Object
Method: Image#sketch(radius=0.0, sigma=1.0, angle=0.0) Purpose: Call SketchImage
9463 9464 9465 9466 9467 9468 |
# File 'ext/RMagick/rmimage.c', line 9463
VALUE
Image_sketch(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_destroyed(self);
return motion_blur(argc, argv, self, SketchImage);
}
|
#solarize(*args) ⇒ Object
Method: Image#solarize(threshold=50.0) Purpose: applies a special effect to the image, similar to the effect
achieved in a photo darkroom by selectively exposing areas of
photo sensitive paper to light. Threshold ranges from 0 to
QuantumRange and is a measure of the extent of the solarization.
9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 |
# File 'ext/RMagick/rmimage.c', line 9478
VALUE
Image_solarize(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double threshold = 50.0;
image = rm_check_destroyed(self);
switch (argc)
{
case 1:
threshold = NUM2DBL(argv[0]);
if (threshold < 0.0 || threshold > QuantumRange)
{
rb_raise(rb_eArgError, "threshold out of range, must be >= 0.0 and < QuantumRange");
}
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
break;
}
new_image = rm_clone_image(image);
(void) SolarizeImage(new_image, threshold);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#sparse_color(*args) ⇒ Object
9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 |
# File 'ext/RMagick/rmimage.c', line 9593
VALUE
Image_sparse_color(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_SPARSECOLORIMAGE)
Image *image, *new_image;
unsigned long x, nargs, ncolors;
SparseColorMethod method;
int n, exp;
double * volatile args;
ChannelType channels;
MagickPixelPacket pp;
ExceptionInfo exception;
image = rm_check_destroyed(self);
n = argc;
channels = extract_channels(&argc, argv);
n -= argc; // n is now the number of channel arguments
// After the channel arguments have been removed, and not counting the first
// (method) argument, the number of arguments should be a multiple of 3.
if (argc < 4 || argc % 3 != 1)
{
exp = argc - 1;
exp = (argc + 2) / 3 * 3;
exp = max(exp, 3);
rb_raise(rb_eArgError, "wrong number of arguments (expected at least %d, got %d)", n+exp+1, n+argc);
}
// Get the method from the argument list
VALUE_TO_ENUM(argv[0], method, SparseColorMethod);
argv += 1;
argc -= 1;
// A lot of the following code is based on SparseColorOption, in wand/mogrify.c
ncolors = count_channels(image, &channels);
nargs = (argc / 3) * (2 + ncolors);
// Allocate args from Ruby's memory so that GC will collect it if one of
// the type conversions below raises an exception.
args = ALLOC_N(double, nargs);
memset(args, 0, nargs * sizeof(double));
x = 0;
n = 0;
while (n < argc)
{
args[x++] = NUM2DBL(argv[n++]);
args[x++] = NUM2DBL(argv[n++]);
Color_to_MagickPixelPacket(NULL, &pp, argv[n++]);
if (channels & RedChannel)
{
args[x++] = pp.red / QuantumRange;
}
if (channels & GreenChannel)
{
args[x++] = pp.green / QuantumRange;
}
if (channels & BlueChannel)
{
args[x++] = pp.blue / QuantumRange;
}
if (channels & IndexChannel)
{
args[x++] = pp.index / QuantumRange;
}
if (channels & OpacityChannel)
{
args[x++] = pp.opacity / QuantumRange;
}
}
GetExceptionInfo(&exception);
new_image = SparseColorImage(image, channels, method, nargs, args, &exception);
xfree(args);
CHECK_EXCEPTION();
rm_ensure_result(new_image);
return rm_image_new(new_image);
#else
self = self;
argc = argc;
argv = argv;
rm_not_implemented();
return(VALUE)0;
#endif
}
|
#splice(*args) ⇒ Object
Method: Image#splice(x, y, width, height[, color]) Purpose: Splice a solid color into the part of the image specified
by the x, y, width, and height arguments. If the color
argument is specified it must be a color name or Pixel.
If not specified uses the background color.
Notes: splice is the inverse of chop
9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 |
# File 'ext/RMagick/rmimage.c', line 9692
VALUE
Image_splice(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
PixelPacket color, old_color;
RectangleInfo rectangle;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 4:
// use background color
color = image->background_color;
break;
case 5:
// Convert color argument to PixelPacket
Color_to_PixelPacket(&color, argv[4]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 4 or 5)", argc);
break;
}
rectangle.x = NUM2LONG(argv[0]);
rectangle.y = NUM2LONG(argv[1]);
rectangle.width = NUM2ULONG(argv[2]);
rectangle.height = NUM2ULONG(argv[3]);
GetExceptionInfo(&exception);
// Swap in color for the duration of this call.
old_color = image->background_color;
image->background_color = color;
new_image = SpliceImage(image, &rectangle, &exception);
image->background_color = old_color;
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#spread(*args) ⇒ Object
Method: Image#spread(radius=3) Purpose: randomly displaces each pixel in a block defined by “radius” Returns: a new image
9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 |
# File 'ext/RMagick/rmimage.c', line 9745
VALUE
Image_spread(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double radius = 3.0;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 1:
radius = NUM2DBL(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = SpreadImage(image, radius, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
rm_ensure_result(new_image);
(void) DestroyExceptionInfo(&exception);
return rm_image_new(new_image);
}
|
#stegano ⇒ Object
#stereo(offset_image_arg) ⇒ Object
Method: Image#stereo(offset_image) Purpose: combines two images and produces a single image that is the
composite of a left and right image of a stereo pair.
Special red-green stereo glasses are required to view this
effect.
Returns: a new image
9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 |
# File 'ext/RMagick/rmimage.c', line 9821
VALUE
Image_stereo(VALUE self, VALUE offset_image_arg)
{
Image *image, *new_image;
volatile VALUE offset_image;
Image *offset;
ExceptionInfo exception;
image = rm_check_destroyed(self);
offset_image = rm_cur_image(offset_image_arg);
offset = rm_check_destroyed(offset_image);
GetExceptionInfo(&exception);
new_image = StereoImage(image, offset, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#store_pixels(x_arg, y_arg, cols_arg, rows_arg, new_pixels) ⇒ Object
Method: Image#store_pixels Purpose: Replace the pixels in the specified rectangle Notes: Calls GetImagePixels, then SyncImagePixels after replacing
the pixels. This is the complement of get_pixels. The array
object returned by get_pixels is suitable for use as the
"new_pixels" argument.
9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 |
# File 'ext/RMagick/rmimage.c', line 9901
VALUE
Image_store_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg
, VALUE rows_arg, VALUE new_pixels)
{
Image *image;
Pixel *pixels, *pixel;
volatile VALUE new_pixel;
long n, size;
long x, y;
unsigned long cols, rows;
unsigned int okay;
image = rm_check_destroyed(self);
x = NUM2LONG(x_arg);
y = NUM2LONG(y_arg);
cols = NUM2ULONG(cols_arg);
rows = NUM2ULONG(rows_arg);
if (x < 0 || y < 0 || x+cols > image->columns || y+rows > image->rows)
{
rb_raise(rb_eRangeError, "geometry (%lux%lu%+ld%+ld) exceeds image bounds"
, cols, rows, x, y);
}
size = (long)(cols * rows);
rm_check_ary_len(new_pixels, size);
okay = SetImageStorageClass(image, DirectClass);
rm_check_image_exception(image, RetainOnError);
if (!okay)
{
rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't store pixels.");
}
// Get a pointer to the pixels. Replace the values with the PixelPackets
// from the pixels argument.
{
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_GETAUTHENTICPIXELS)
ExceptionInfo exception;
GetExceptionInfo(&exception);
#endif
#if defined(HAVE_GETAUTHENTICPIXELS)
pixels = GetAuthenticPixels(image, x, y, cols, rows, &exception);
CHECK_EXCEPTION()
#else
pixels = GetImagePixels(image, x, y, cols, rows);
rm_check_image_exception(image, RetainOnError);
#endif
if (pixels)
{
for (n = 0; n < size; n++)
{
new_pixel = rb_ary_entry(new_pixels, n);
Data_Get_Struct(new_pixel, Pixel, pixel);
pixels[n] = *pixel;
}
#if defined(HAVE_SYNCAUTHENTICPIXELS)
SyncAuthenticPixels(image, &exception);
CHECK_EXCEPTION()
#else
SyncImagePixels(image);
rm_check_image_exception(image, RetainOnError);
#endif
}
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_GETAUTHENTICPIXELS)
DestroyExceptionInfo(&exception);
#endif
}
return self;
}
|
#strip! ⇒ Object
Method: Image#strip! Purpose: strips an image of all profiles and comments.
9981 9982 9983 9984 9985 9986 9987 9988 |
# File 'ext/RMagick/rmimage.c', line 9981
VALUE
Image_strip_bang(VALUE self)
{
Image *image = rm_check_frozen(self);
(void) StripImage(image);
rm_check_image_exception(image, RetainOnError);
return self;
}
|
#swirl(degrees) ⇒ Object
Method: Image#swirl(degrees) Purpose: swirls the pixels about the center of the image, where degrees
indicates the sweep of the arc through which each pixel is moved.
You get a more dramatic effect as the degrees move from 1 to 360.
9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 |
# File 'ext/RMagick/rmimage.c', line 9997
VALUE
Image_swirl(VALUE self, VALUE degrees)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = SwirlImage(image, NUM2DBL(degrees), &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#sync_profiles ⇒ Object
Method: Image#sync_profiles() Purpose: synchronizes image properties with the image profiles
10021 10022 10023 10024 10025 10026 10027 10028 |
# File 'ext/RMagick/rmimage.c', line 10021
VALUE
Image_sync_profiles(VALUE self)
{
Image *image = rm_check_destroyed(self);
volatile VALUE okay = SyncImageProfiles(image) ? Qtrue : Qfalse;
rm_check_image_exception(image, RetainOnError);
return okay;
}
|
#texture_fill_to_border(x, y, texture) ⇒ Object
Replace neighboring pixels to border color with texture pixels
1035 1036 1037 |
# File 'lib/RMagick.rb', line 1035 def texture_fill_to_border(x, y, texture) texture_flood_fill(border_color, texture, x, y, FillToBorderMethod) end |
#texture_flood_fill(color_obj, texture_obj, x_obj, y_obj, method_obj) ⇒ Object
Method: Image#texture_flood_fill(color, texture, x, y, method) Purpose: 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.
If the FillToBorderMethod method is specified, flood-fills
"texture across pixels starting at the target pixel and
stopping at pixels matching the specified color."
10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 |
# File 'ext/RMagick/rmimage.c', line 10042
VALUE
Image_texture_flood_fill(VALUE self, VALUE color_obj, VALUE texture_obj
, VALUE x_obj, VALUE y_obj, VALUE method_obj)
{
Image *image, *new_image;
Image *texture_image;
PixelPacket color;
volatile VALUE texture;
DrawInfo *draw_info;
long x, y;
PaintMethod method;
image = rm_check_destroyed(self);
Color_to_PixelPacket(&color, color_obj);
texture = rm_cur_image(texture_obj);
texture_image = rm_check_destroyed(texture);
x = NUM2LONG(x_obj);
y = NUM2LONG(y_obj);
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);
}
VALUE_TO_ENUM(method_obj, method, PaintMethod);
if (method != FillToBorderMethod && method != FloodfillMethod)
{
rb_raise(rb_eArgError, "paint method must be FloodfillMethod or "
"FillToBorderMethod (%d given)", (int)method);
}
draw_info = CloneDrawInfo(NULL, NULL);
if (!draw_info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
draw_info->fill_pattern = rm_clone_image(texture_image);
new_image = rm_clone_image(image);
#if defined(HAVE_FLOODFILLPAINTIMAGE)
{
MagickPixelPacket color_mpp;
MagickBooleanType invert;
GetMagickPixelPacket(new_image, &color_mpp);
if (method == FillToBorderMethod)
{
invert = MagickTrue;
color_mpp.red = (MagickRealType) image->border_color.red;
color_mpp.green = (MagickRealType) image->border_color.green;
color_mpp.blue = (MagickRealType) image->border_color.blue;
}
else
{
invert = MagickFalse;
color_mpp.red = (MagickRealType) color.red;
color_mpp.green = (MagickRealType) color.green;
color_mpp.blue = (MagickRealType) color.blue;
}
(void) FloodfillPaintImage(new_image, DefaultChannels, draw_info, &color_mpp, x, y, invert);
}
#else
(void) ColorFloodfillImage(new_image, draw_info, color, x, y, method);
#endif
(void) DestroyDrawInfo(draw_info);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#texture_floodfill(x, y, texture) ⇒ Object
Replace matching neighboring pixels with texture pixels
1029 1030 1031 1032 |
# File 'lib/RMagick.rb', line 1029 def texture_floodfill(x, y, texture) target = pixel_color(x, y) texture_flood_fill(target, texture, x, y, FloodfillMethod) end |
#threshold(threshold) ⇒ Object
Method: Image#threshold(threshold) Purpose: changes the value of individual pixels based on the intensity of
each pixel compared to threshold. The result is a high-contrast,
two color image.
10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 |
# File 'ext/RMagick/rmimage.c', line 10128
VALUE
Image_threshold(VALUE self, VALUE threshold)
{
Image *image, *new_image;
image = rm_check_destroyed(self);
new_image = rm_clone_image(image);
(void) BilevelImageChannel(new_image, DefaultChannels, NUM2DBL(threshold));
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
|
#thumbnail(*args) ⇒ Object
10259 10260 10261 10262 10263 10264 |
# File 'ext/RMagick/rmimage.c', line 10259
VALUE
Image_thumbnail(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_destroyed(self);
return thumbnail(False, argc, argv, self);
}
|
#thumbnail!(*args) ⇒ Object
10267 10268 10269 10270 10271 10272 |
# File 'ext/RMagick/rmimage.c', line 10267
VALUE
Image_thumbnail_bang(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_frozen(self);
return thumbnail(True, argc, argv, self);
}
|
#tint(*args) ⇒ Object
Method: Image#tint Purpose: Call TintImage Notes: Opacity values are percentages: 0.10 -> 10%.
10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 11249 11250 11251 11252 11253 11254 11255 11256 11257 11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277 11278 11279 11280 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 11296 11297 11298 11299 11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 11351 11352 11353 11354 11355 11356 11357 11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 11411 11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 11430 11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449 11450 11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 11600 11601 11602 11603 11604 11605 11606 11607 11608 11609 11610 11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627 11628 11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 11680 11681 11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 11832 11833 11834 11835 11836 11837 11838 11839 11840 11841 |
# File 'ext/RMagick/rmimage.c', line 10301
VALUE
Image_tint(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
Pixel *tint;
double red_pct_opaque, green_pct_opaque, blue_pct_opaque;
double alpha_pct_opaque = 1.0;
char opacity[50];
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 2:
red_pct_opaque = NUM2DBL(argv[1]);
green_pct_opaque = blue_pct_opaque = red_pct_opaque;
break;
case 3:
red_pct_opaque = NUM2DBL(argv[1]);
green_pct_opaque = NUM2DBL(argv[2]);
blue_pct_opaque = red_pct_opaque;
break;
case 4:
red_pct_opaque = NUM2DBL(argv[1]);
green_pct_opaque = NUM2DBL(argv[2]);
blue_pct_opaque = NUM2DBL(argv[3]);
break;
case 5:
red_pct_opaque = NUM2DBL(argv[1]);
green_pct_opaque = NUM2DBL(argv[2]);
blue_pct_opaque = NUM2DBL(argv[3]);
alpha_pct_opaque = NUM2DBL(argv[4]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 5)", argc);
break;
}
if (red_pct_opaque < 0.0 || green_pct_opaque < 0.0
|| blue_pct_opaque < 0.0 || alpha_pct_opaque < 0.0)
{
rb_raise(rb_eArgError, "opacity percentages must be non-negative.");
}
#if defined(HAVE_SNPRINTF)
snprintf(opacity, sizeof(opacity),
#else
sprintf(opacity,
#endif
"%g,%g,%g,%g", red_pct_opaque*100.0, green_pct_opaque*100.0
, blue_pct_opaque*100.0, alpha_pct_opaque*100.0);
Data_Get_Struct(argv[0], Pixel, tint);
GetExceptionInfo(&exception);
new_image = TintImage(image, opacity, *tint, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
/*
Method: Image#to_blob
Purpose: Return a "blob" (a String) from the image
Notes: The magick member of the Image structure
determines the format of the returned blob
(GIG, JPEG, PNG, etc.)
*/
VALUE
Image_to_blob(VALUE self)
{
Image *image;
Info *info;
const MagickInfo *magick_info;
volatile VALUE info_obj;
volatile VALUE blob_str;
void *blob = NULL;
size_t length = 2048; // Do what Magick++ does
ExceptionInfo exception;
// The user can specify the depth (8 or 16, if the format supports
// both) and the image format by setting the depth and format
// values in the info parm block.
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
image = rm_check_destroyed(self);
// Copy the depth and magick fields to the Image
if (info->depth != 0)
{
(void) SetImageDepth(image, info->depth);
rm_check_image_exception(image, RetainOnError);
}
GetExceptionInfo(&exception);
if (*info->magick)
{
(void) SetImageInfo(info, MagickTrue, &exception);
CHECK_EXCEPTION()
if (*info->magick == '\0')
{
return Qnil;
}
strncpy(image->magick, info->magick, sizeof(info->magick)-1);
}
// Fix #2844 - libjpeg exits when image is 0x0
magick_info = GetMagickInfo(image->magick, &exception);
CHECK_EXCEPTION()
if (magick_info)
{
if ( (!rm_strcasecmp(magick_info->name, "JPEG")
|| !rm_strcasecmp(magick_info->name, "JPG"))
&& (image->rows == 0 || image->columns == 0))
{
rb_raise(rb_eRuntimeError, "Can't convert %lux%lu %.4s image to a blob"
, image->columns, image->rows, magick_info->name);
}
}
rm_sync_image_options(image, info);
blob = ImageToBlob(info, image, &length, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
if (length == 0 || !blob)
{
return Qnil;
}
blob_str = rb_str_new(blob, length);
magick_free((void*)blob);
return blob_str;
}
/*
Method: Image#to_color
Purpose: Return a color name for the color intensity specified by the
Magick::Pixel argument.
Notes: Respects depth and matte attributes
*/
VALUE
Image_to_color(VALUE self, VALUE pixel_arg)
{
Image *image;
Pixel *pixel;
ExceptionInfo exception;
char name[MaxTextExtent];
image = rm_check_destroyed(self);
Data_Get_Struct(pixel_arg, Pixel, pixel);
GetExceptionInfo(&exception);
// QueryColorname returns False if the color represented by the PixelPacket
// doesn't have a "real" name, just a sequence of hex digits. We don't care
// about that.
name[0] = '\0';
(void) QueryColorname(image, pixel, AllCompliance, name, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
return rb_str_new2(name);
}
/*
Method: Image#total_colors
Purpose: alias for Image#number_colors
Notes: This used to be a direct reference to the `total_colors' field in Image
but that field is not reliable.
*/
VALUE
Image_total_colors(VALUE self)
{
return Image_number_colors(self);
}
/*
Method: Image#total_ink_density
Purpose: Return value from GetImageTotalInkDensity
Notes: Raises an exception if the image is not CMYK
*/
VALUE
Image_total_ink_density(VALUE self)
{
Image *image;
double density;
image = rm_check_destroyed(self);
density = GetImageTotalInkDensity(image);
rm_check_image_exception(image, RetainOnError);
return rb_float_new(density);
}
/*
Method: Image#transparent(color-name<, opacity>)
Image#transparent(pixel<, opacity>)
Purpose: Call TransparentPaintImage
Notes: Can use Magick::OpaqueOpacity or Magick::TransparentOpacity,
or any value >= 0 && <= QuantumRange. The default is
Magick::TransparentOpacity.
Use Image#fuzz= to define the tolerance level.
*/
VALUE
Image_transparent(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
MagickPixelPacket color;
Quantum opacity = TransparentOpacity;
MagickBooleanType okay;
image = rm_check_destroyed(self);
switch (argc)
{
case 2:
opacity = APP2QUANTUM(argv[1]);
case 1:
Color_to_MagickPixelPacket(image, &color, argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
break;
}
new_image = rm_clone_image(image);
#if defined(HAVE_TRANSPARENTPAINTIMAGE)
okay = TransparentPaintImage(new_image, &color, opacity, MagickFalse);
#else
okay = PaintTransparentImage(new_image, &color, opacity);
#endif
rm_check_image_exception(new_image, DestroyOnError);
if (!okay)
{
// Force exception
DestroyImage(new_image);
rm_magick_error("TransparentPaintImage failed with no explanation", NULL);
}
return rm_image_new(new_image);
}
/*
Method: Image#transparent_chroma(low, high, opacity=TransparentOpacity, invert=false)
Purpose: Call TransparentPaintImageChroma (>= 6.4.5-6)
*/
VALUE
Image_transparent_chroma(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_TRANSPARENTPAINTIMAGECHROMA)
Image *image, *new_image;
Quantum opacity = TransparentOpacity;
MagickPixelPacket low, high;
MagickBooleanType invert = MagickFalse;
MagickBooleanType okay;
image = rm_check_destroyed(self);
switch (argc)
{
case 4:
invert = RTEST(argv[3]);
case 3:
opacity = APP2QUANTUM(argv[2]);
case 2:
Color_to_MagickPixelPacket(image, &high, argv[1]);
Color_to_MagickPixelPacket(image, &low, argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2, 3 or 4)", argc);
break;
}
new_image = rm_clone_image(image);
okay = TransparentPaintImageChroma(new_image, &low, &high, opacity, invert);
rm_check_image_exception(new_image, DestroyOnError);
if (!okay)
{
// Force exception
DestroyImage(new_image);
rm_magick_error("TransparentPaintImageChroma failed with no explanation", NULL);
}
return rm_image_new(new_image);
#else
rm_not_implemented();
return (VALUE)0;
argc = argc;
argv = argv;
self = self;
#endif
}
/*
Method: Image#transparent_color
Purpose: Return the name of the transparent color as a String.
*/
VALUE
Image_transparent_color(VALUE self)
{
Image *image = rm_check_destroyed(self);
return rm_pixelpacket_to_color_name(image, &image->transparent_color);
}
/*
Method: Image#transparent_color=
Purpose: Set the the transparent color to the specified color spec.
*/
VALUE
Image_transparent_color_eq(VALUE self, VALUE color)
{
Image *image = rm_check_frozen(self);
Color_to_PixelPacket(&image->transparent_color, color);
return self;
}
/*
* Method: Image#transpose
* Image#transpose!
* Purpose: Call TransposeImage
*/
VALUE
Image_transpose(VALUE self)
{
(void) rm_check_destroyed(self);
return crisscross(False, self, TransposeImage);
}
VALUE
Image_transpose_bang(VALUE self)
{
(void) rm_check_frozen(self);
return crisscross(True, self, TransposeImage);
}
/*
* Method: Image#transverse
* Image#transverse!
* Purpose: Call TransverseImage
*/
VALUE
Image_transverse(VALUE self)
{
(void) rm_check_destroyed(self);
return crisscross(False, self, TransverseImage);
}
VALUE
Image_transverse_bang(VALUE self)
{
(void) rm_check_frozen(self);
return crisscross(True, self, TransverseImage);
}
/*
* Method: Image#trim, Image#trim!
* Purpose: convenience front-end to CropImage
* Notes: respects fuzz attribute
*/
static VALUE
trimmer(int bang, int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ExceptionInfo exception;
int reset_page = 0;
switch (argc)
{
case 1:
reset_page = RTEST(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (expecting 0 or 1, got %d)", argc);
break;
}
Data_Get_Struct(self, Image, image);
GetExceptionInfo(&exception);
new_image = TrimImage(image, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
if (reset_page)
{
ResetImagePage(new_image, "0x0+0+0");
}
if (bang)
{
UPDATE_DATA_PTR(self, new_image);
(void) rm_image_destroy(image);
return self;
}
return rm_image_new(new_image);
}
VALUE
Image_trim(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_destroyed(self);
return trimmer(False, argc, argv, self);
}
VALUE
Image_trim_bang(int argc, VALUE *argv, VALUE self)
{
(void) rm_check_frozen(self);
return trimmer(True, argc, argv, self);
}
/*
Method: Image#gravity, gravity=
Purpose: Get/set the image gravity attribute
*/
VALUE Image_gravity(VALUE self)
{
Image *image = rm_check_destroyed(self);
return GravityType_new(image->gravity);
}
VALUE Image_gravity_eq(VALUE self, VALUE gravity)
{
Image *image = rm_check_frozen(self);
VALUE_TO_ENUM(gravity, image->gravity, GravityType);
return gravity;
}
/*
Method: Image#image_type, image_type=
Purpose: Call GetImageType/SetImageType to get/set the image type
*/
VALUE Image_image_type(VALUE self)
{
Image *image;
ImageType type;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
type = GetImageType(image, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
return ImageType_new(type);
}
VALUE Image_image_type_eq(VALUE self, VALUE image_type)
{
Image *image;
ImageType type;
image = rm_check_frozen(self);
VALUE_TO_ENUM(image_type, type, ImageType);
SetImageType(image, type);
return image_type;
}
/*
Method: Image#undefine(artifact)
Purpose: Call RemoveImageArtifact
Note: Normally a script should never call this method.
See Image_define.
*/
VALUE
Image_undefine(VALUE self, VALUE artifact)
{
#if defined(HAVE_REMOVEIMAGEARTIFACT)
Image *image;
char *key;
long key_l;
image = rm_check_frozen(self);
key = rm_str2cstr(artifact, &key_l);
(void) RemoveImageArtifact(image, key);
return self;
#else
rm_not_implemented();
artifact = artifact;
self = self;
return(VALUE)0;
#endif
}
/*
Method: Image#unique_colors
Purpose: Call UniqueImageColors
*/
VALUE
Image_unique_colors(VALUE self)
{
Image *image, *new_image;
ExceptionInfo exception;
image = rm_check_destroyed(self);
GetExceptionInfo(&exception);
new_image = UniqueImageColors(image, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
/*
Method: Image#units
Purpose: Get the resolution type field
*/
VALUE
Image_units(VALUE self)
{
Image *image = rm_check_destroyed(self);
return ResolutionType_new(image->units);
}
/*
Method: Image#units=
Purpose: Set the resolution type field
*/
VALUE
Image_units_eq(
VALUE self,
VALUE restype)
{
ResolutionType units;
Image *image = rm_check_frozen(self);
VALUE_TO_ENUM(restype, units, ResolutionType);
if (image->units != units)
{
switch (image->units)
{
case PixelsPerInchResolution:
if (units == PixelsPerCentimeterResolution)
{
image->x_resolution /= 2.54;
image->y_resolution /= 2.54;
}
break;
case PixelsPerCentimeterResolution:
if (units == PixelsPerInchResolution)
{
image->x_resolution *= 2.54;
image->y_resolution *= 2.54;
}
break;
default:
// UndefinedResolution
image->x_resolution = 0.0;
image->y_resolution = 0.0;
break;
}
image->units = units;
}
return self;
}
/*
Method: Image#unsharp_mask(radius=0.0, sigma=1.0, amount=1.0, threshold=0.05)
Purpose: sharpens an image. "amount" is the percentage of the difference
between the original and the blur image that is added back into
the original. "threshold" is the threshold in pixels needed to
apply the diffence amount.
*/
static void
unsharp_mask_args(int argc, VALUE *argv, double *radius, double *sigma
, double *amount, double *threshold)
{
switch (argc)
{
case 4:
*threshold = NUM2DBL(argv[3]);
if (*threshold < 0.0)
{
rb_raise(rb_eArgError, "threshold must be >= 0.0");
}
case 3:
*amount = NUM2DBL(argv[2]);
if (*amount <= 0.0)
{
rb_raise(rb_eArgError, "amount must be > 0.0");
}
case 2:
*sigma = NUM2DBL(argv[1]);
if (*sigma == 0.0)
{
rb_raise(rb_eArgError, "sigma must be != 0.0");
}
case 1:
*radius = NUM2DBL(argv[0]);
if (*radius < 0.0)
{
rb_raise(rb_eArgError, "radius must be >= 0.0");
}
case 0:
break;
// This case can't occur if we're called from Image_unsharp_mask_channel
// because it has already raised an exception for the the argc > 4 case.
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc);
}
}
VALUE
Image_unsharp_mask(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double radius = 0.0, sigma = 1.0, amount = 1.0, threshold = 0.05;
ExceptionInfo exception;
image = rm_check_destroyed(self);
unsharp_mask_args(argc, argv, &radius, &sigma, &amount, &threshold);
GetExceptionInfo(&exception);
new_image = UnsharpMaskImage(image, radius, sigma, amount, threshold, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
/*
Method: Image#unsharp_mask_channel(radius, sigma, amount,threshold,
channel=AllChannels)
Purpose: Call UnsharpMaskImageChannel
*/
VALUE
Image_unsharp_mask_channel(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
ChannelType channels;
double radius = 0.0, sigma = 1.0, amount = 1.0, threshold = 0.05;
ExceptionInfo exception;
image = rm_check_destroyed(self);
channels = extract_channels(&argc, argv);
if (argc > 4)
{
raise_ChannelType_error(argv[argc-1]);
}
unsharp_mask_args(argc, argv, &radius, &sigma, &amount, &threshold);
GetExceptionInfo(&exception);
new_image = UnsharpMaskImageChannel(image, channels, radius, sigma, amount
, threshold, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
/*
Method: Image#vignette(horz_radius, vert_radius, radius, sigma);
Purpose: soften the edges of an image
Notes: The outer edges of the image are replaced by the background color.
*/
VALUE
Image_vignette(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
long horz_radius, vert_radius;
double radius = 0.0, sigma = 10.0;
ExceptionInfo exception;
image = rm_check_destroyed(self);
horz_radius = (long)(image->columns * 0.10 + 0.5);
vert_radius = (long)(image->rows * 0.10 + 0.5);
switch (argc)
{
case 4:
sigma = NUM2DBL(argv[3]);
case 3:
radius = NUM2DBL(argv[2]);
case 2:
vert_radius = NUM2INT(argv[1]);
case 1:
horz_radius = NUM2INT(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = VignetteImage(image, radius, sigma, horz_radius, vert_radius, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
/*
Method: Image#virtual_pixel_method
Purpose: get the VirtualPixelMethod for the image
*/
VALUE
Image_virtual_pixel_method(VALUE self)
{
Image *image;
VirtualPixelMethod vpm;
image = rm_check_destroyed(self);
vpm = GetImageVirtualPixelMethod(image);
rm_check_image_exception(image, RetainOnError);
return VirtualPixelMethod_new(vpm);
}
/*
Method: Image#virtual_pixel_method=
Purpose: set the virtual pixel method for the image
*/
VALUE
Image_virtual_pixel_method_eq(VALUE self, VALUE method)
{
Image *image;
VirtualPixelMethod vpm;
image = rm_check_frozen(self);
VALUE_TO_ENUM(method, vpm, VirtualPixelMethod);
(void) SetImageVirtualPixelMethod(image, vpm);
rm_check_image_exception(image, RetainOnError);
return self;
}
/*
Method: Image#watermark(mark, brightness=100.0, saturation=100.0
, [gravity,] x_off=0, y_off=0)
Purpose: add a watermark to an image
Notes: x_off and y_off can be negative, which means measure from the right/bottom
of the target image.
*/
VALUE
Image_watermark(int argc, VALUE *argv, VALUE self)
{
Image *image, *overlay, *new_image;
double src_percent = 100.0, dst_percent = 100.0;
long x_offset = 0L, y_offset = 0L;
char geometry[20];
volatile VALUE ovly;
image = rm_check_destroyed(self);
if (argc < 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 6)", argc);
}
ovly = rm_cur_image(argv[0]);
overlay = rm_check_destroyed(ovly);
if (argc > 3)
{
get_composite_offsets(argc-3, &argv[3], image, overlay, &x_offset, &y_offset);
// There must be 3 arguments left
argc = 3;
}
switch (argc)
{
case 3:
dst_percent = rm_percentage(argv[2]) * 100.0;
case 2:
src_percent = rm_percentage(argv[1]) * 100.0;
case 1:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 6)", argc);
break;
}
blend_geometry(geometry, sizeof(geometry), src_percent, dst_percent);
(void) CloneString(&overlay->geometry, geometry);
#if defined(HAVE_SETIMAGEARTIFACT)
(void) SetImageArtifact(overlay,"compose:args", geometry);
#endif
new_image = rm_clone_image(image);
(void) CompositeImage(new_image, ModulateCompositeOp, overlay, x_offset, y_offset);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
/*
Method: Image#wave(amplitude=25.0, wavelength=150.0)
Purpose: creates a "ripple" effect in the image by shifting the pixels
vertically along a sine wave whose amplitude and wavelength is
specified by the given parameters.
Returns: self
*/
VALUE
Image_wave(int argc, VALUE *argv, VALUE self)
{
Image *image, *new_image;
double amplitude = 25.0, wavelength = 150.0;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 2:
wavelength = NUM2DBL(argv[1]);
case 1:
amplitude = NUM2DBL(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc);
break;
}
GetExceptionInfo(&exception);
new_image = WaveImage(image, amplitude, wavelength, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
/*
Method: Image#wet_floor(initial, rate)
Purpose: Construct a "wet floor" reflection.
Notes: `initial' is a number between 0 and 1, inclusive, that represents
the initial level of transparency. Smaller numbers are less
transparent than larger numbers. 0 is fully opaque. 1.0 is
fully transparent. The default is 0.5.
`rate' is the rate at which the initial level of transparency
changes to complete transparency. The default is 1.0. Values
larger than 1.0 cause the change to occur more rapidly. The
resulting reflection will be shorter. Values smaller than 1.0
cause the change to occur less rapidly. The resulting
reflection will be taller. If the rate is exactly 0 then the
amount of transparency doesn't change at all.
Notes: http://en.wikipedia.org/wiki/Wet_floor_effect
*/
VALUE
Image_wet_floor(int argc, VALUE *argv, VALUE self)
{
Image *image, *reflection, *flip_image;
const PixelPacket *p;
PixelPacket *q;
RectangleInfo geometry;
long x, y, max_rows;
double initial = 0.5;
double rate = 1.0;
double opacity, step;
const char *func;
ExceptionInfo exception;
image = rm_check_destroyed(self);
switch (argc)
{
case 2:
rate = NUM2DBL(argv[1]);
case 1:
initial = NUM2DBL(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc);
break;
}
if (initial < 0.0 || initial > 1.0)
{
rb_raise(rb_eArgError, "Initial transparency must be in the range 0.0-1.0 (%g)", initial);
}
if (rate < 0.0)
{
rb_raise(rb_eArgError, "Transparency change rate must be >= 0.0 (%g)", rate);
}
initial *= TransparentOpacity;
// The number of rows in which to transition from the initial level of
// transparency to complete transparency. rate == 0.0 -> no change.
if (rate > 0.0)
{
max_rows = (long)((double)image->rows) / (3.0 * rate);
max_rows = (long)min((unsigned long)max_rows, image->rows);
step = (TransparentOpacity - initial) / max_rows;
}
else
{
max_rows = (long)image->rows;
step = 0.0;
}
GetExceptionInfo(&exception);
flip_image = FlipImage(image, &exception);
CHECK_EXCEPTION();
geometry.x = 0;
geometry.y = 0;
geometry.width = image->columns;
geometry.height = max_rows;
reflection = CropImage(flip_image, &geometry, &exception);
DestroyImage(flip_image);
CHECK_EXCEPTION();
(void) SetImageStorageClass(reflection, DirectClass);
rm_check_image_exception(reflection, DestroyOnError);
reflection->matte = MagickTrue;
opacity = initial;
for (y = 0; y < max_rows; y++)
{
if (opacity > TransparentOpacity)
{
opacity = TransparentOpacity;
}
#if defined(HAVE_GETVIRTUALPIXELS)
p = GetVirtualPixels(reflection, 0, y, image->columns, 1, &exception);
#else
p = AcquireImagePixels(reflection, 0, y, image->columns, 1, &exception);
#endif
rm_check_exception(&exception, reflection, DestroyOnError);
if (!p)
{
func = "AcquireImagePixels";
goto error;
}
#if defined(HAVE_QUEUEAUTHENTICPIXELS)
q = QueueAuthenticPixels(reflection, 0, y, image->columns, 1, &exception);
#else
q = SetImagePixels(reflection, 0, y, image->columns, 1);
#endif
rm_check_exception(&exception, reflection, DestroyOnError);
if (!q)
{
func = "SetImagePixels";
goto error;
}
for (x = 0; x < (long) image->columns; x++)
{
q[x] = p[x];
// Never make a pixel *less* transparent than it already is.
q[x].opacity = max(q[x].opacity, (Quantum)opacity);
}
#if defined(HAVE_SYNCAUTHENTICPIXELS)
SyncAuthenticPixels(reflection, &exception);
rm_check_exception(&exception, reflection, DestroyOnError);
#else
SyncImagePixels(reflection);
rm_check_image_exception(reflection, DestroyOnError);
#endif
opacity += step;
}
(void) DestroyExceptionInfo(&exception);
return rm_image_new(reflection);
error:
(void) DestroyExceptionInfo(&exception);
(void) DestroyImage(reflection);
rb_raise(rb_eRuntimeError, "%s failed on row %lu", func, y);
return(VALUE)0;
}
/*
* Method: Image#white_threshold(red_channel [, green_channel
* [, blue_channel [, opacity_channel]]]);
* Purpose: Call WhiteThresholdImage
*/
VALUE
Image_white_threshold(int argc, VALUE *argv, VALUE self)
{
return threshold_image(argc, argv, self, WhiteThresholdImage);
}
/*
Copy the filename to the Info and to the Image. Add format
prefix if necessary. This complicated code is necessary to handle filenames
like the kind Tempfile.new produces, which have an "extension" in the form
".n", which confuses SetMagickInfo. So we don't use SetMagickInfo any longer.
*/
void add_format_prefix(Info *info, VALUE file)
{
char *filename;
long filename_l;
const MagickInfo *magick_info, *magick_info2;
ExceptionInfo exception;
char magic[MaxTextExtent];
size_t magic_l;
size_t prefix_l;
char *p;
// Convert arg to string. If an exception occurs raise an error condition.
file = rb_rescue(rb_String, file, file_arg_rescue, file);
filename = rm_str2cstr(file, &filename_l);
if (*info->magick == '\0')
{
memset(info->filename, 0, sizeof(info->filename));
memcpy(info->filename, filename, (size_t)min(filename_l, MaxTextExtent-1));
return;
}
// If the filename starts with a prefix, and it's a valid image format
// prefix, then check for a conflict. If it's not a valid format prefix,
// ignore it.
p = memchr(filename, ':', (size_t)filename_l);
if (p)
{
memset(magic, '\0', sizeof(magic));
magic_l = p - filename;
memcpy(magic, filename, magic_l);
GetExceptionInfo(&exception);
magick_info = GetMagickInfo(magic, &exception);
CHECK_EXCEPTION();
DestroyExceptionInfo(&exception);
if (magick_info && magick_info->module)
{
// We have to compare the module names because some formats have
// more than one name. JPG and JPEG, for example.
GetExceptionInfo(&exception);
magick_info2 = GetMagickInfo(info->magick, &exception);
CHECK_EXCEPTION();
DestroyExceptionInfo(&exception);
if (magick_info2->module && strcmp(magick_info->module, magick_info2->module) != 0)
{
rb_raise(rb_eRuntimeError
, "filename prefix `%s' conflicts with output format `%s'"
, magick_info->name, info->magick);
}
// The filename prefix already matches the specified format.
// Just copy the filename as-is.
memset(info->filename, 0, sizeof(info->filename));
filename_l = min((size_t)filename_l, sizeof(info->filename));
memcpy(info->filename, filename, (size_t)filename_l);
return;
}
}
// The filename doesn't start with a format prefix. Add the format from
// the image info as the filename prefix.
memset(info->filename, 0, sizeof(info->filename));
prefix_l = min(sizeof(info->filename)-1, strlen(info->magick));
memcpy(info->filename, info->magick, prefix_l);
info->filename[prefix_l++] = ':';
filename_l = min(sizeof(info->filename) - prefix_l - 1, (size_t)filename_l);
memcpy(info->filename+prefix_l, filename, (size_t)filename_l);
info->filename[prefix_l+filename_l] = '\0';
return;
}
/*
Method: Image#write(filename)
Purpose: Write the image to the file.
Returns: self
*/
VALUE
Image_write(VALUE self, VALUE file)
{
Image *image;
Info *info;
volatile VALUE info_obj;
image = rm_check_destroyed(self);
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
if (TYPE(file) == T_FILE)
{
OpenFile *fptr;
// Ensure file is open - raise error if not
GetOpenFile(file, fptr);
rb_io_check_writable(fptr);
SetImageInfoFile(info, GetWriteFile(fptr));
memset(image->filename, 0, sizeof(image->filename));
}
else
{
add_format_prefix(info, file);
strcpy(image->filename, info->filename);
SetImageInfoFile(info, NULL);
}
rm_sync_image_options(image, info);
info->adjoin = MagickFalse;
(void) WriteImage(info, image);
rm_check_image_exception(image, RetainOnError);
return self;
}
DEF_ATTR_ACCESSOR(Image, x_resolution, dbl)
DEF_ATTR_ACCESSOR(Image, y_resolution, dbl)
/*
Static: cropper
Purpose: determine if the argument list is
x, y, width, height
or
gravity, width, height
or
gravity, x, y, width, height
If the 2nd or 3rd, compute new x, y values.
The argument list can have a trailing true, false, or nil argument.
If present and true, after cropping reset the page fields in the image.
Call xform_image to do the cropping.
*/
static VALUE
cropper(int bang, int argc, VALUE *argv, VALUE self)
{
volatile VALUE x, y, width, height;
unsigned long nx = 0, ny = 0;
unsigned long columns, rows;
int reset_page = 0;
GravityType gravity;
Image *image;
VALUE cropped;
// Check for a "reset page" trailing argument.
if (argc >= 1)
{
switch (TYPE(argv[argc-1]))
{
case T_TRUE:
reset_page = 1;
// fall thru
case T_FALSE:
case T_NIL:
argc -= 1;
default:
break;
}
}
switch (argc)
{
case 5:
Data_Get_Struct(self, Image, image);
VALUE_TO_ENUM(argv[0], gravity, GravityType);
x = argv[1];
y = argv[2];
width = argv[3];
height = argv[4];
nx = NUM2ULONG(x);
ny = NUM2ULONG(y);
columns = NUM2ULONG(width);
rows = NUM2ULONG(height);
switch (gravity)
{
case NorthEastGravity:
case EastGravity:
case SouthEastGravity:
nx = image->columns - columns - nx;
break;
case NorthGravity:
case SouthGravity:
case CenterGravity:
case StaticGravity:
nx += image->columns/2 - columns/2;
break;
default:
break;
}
switch (gravity)
{
case SouthWestGravity:
case SouthGravity:
case SouthEastGravity:
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:
break;
}
x = ULONG2NUM(nx);
y = ULONG2NUM(ny);
break;
case 4:
x = argv[0];
y = argv[1];
width = argv[2];
height = argv[3];
break;
case 3:
// Convert the width & height arguments to unsigned longs.
// Compute the x & y offsets from the gravity and then
// convert them to VALUEs.
VALUE_TO_ENUM(argv[0], gravity, GravityType);
width = argv[1];
height = argv[2];
columns = NUM2ULONG(width);
rows = NUM2ULONG(height);
Data_Get_Struct(self, Image, image);
switch (gravity)
{
case ForgetGravity:
case NorthWestGravity:
nx = 0;
ny = 0;
break;
case NorthGravity:
nx = (image->columns - columns) / 2;
ny = 0;
break;
case NorthEastGravity:
nx = image->columns - columns;
ny = 0;
break;
case WestGravity:
nx = 0;
ny = (image->rows - rows) / 2;
break;
case EastGravity:
nx = image->columns - columns;
ny = (image->rows - rows) / 2;
break;
case SouthWestGravity:
nx = 0;
ny = image->rows - rows;
break;
case SouthGravity:
nx = (image->columns - columns) / 2;
ny = image->rows - rows;
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;
}
x = ULONG2NUM(nx);
y = ULONG2NUM(ny);
break;
default:
if (reset_page)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 4, 5, or 6)", argc);
}
else
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 3, 4, or 5)", argc);
}
break;
}
cropped = xform_image(bang, self, x, y, width, height, CropImage);
if (reset_page)
{
Data_Get_Struct(cropped, Image, image);
ResetImagePage(image, "0x0+0+0");
}
return cropped;
}
/*
Static: xform_image
Purpose: call one of the image transformation functions
Returns: a new image, or transformed self
*/
static VALUE
xform_image(int bang, VALUE self, VALUE x, VALUE y, VALUE width, VALUE height, xformer_t xformer)
{
Image *image, *new_image;
RectangleInfo rect;
ExceptionInfo exception;
Data_Get_Struct(self, Image, image);
rect.x = NUM2LONG(x);
rect.y = NUM2LONG(y);
rect.width = NUM2ULONG(width);
rect.height = NUM2ULONG(height);
GetExceptionInfo(&exception);
new_image = (xformer)(image, &rect, &exception);
// An exception can occur in either the old or the new images
rm_check_image_exception(image, RetainOnError);
rm_check_exception(&exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);
if (bang)
{
UPDATE_DATA_PTR(self, new_image);
(void) rm_image_destroy(image);
return self;
}
return rm_image_new(new_image);
}
/*
Extern: extract_channels
Purpose: Remove all the ChannelType arguments from the
end of the argument list.
Returns: A ChannelType value suitable for passing into
an xMagick function. Returns DefaultChannels if
no channel arguments were found. Returns the
number of remaining arguments.
*/
ChannelType extract_channels(int *argc, VALUE *argv)
{
volatile VALUE arg;
ChannelType channels, ch_arg;
channels = 0;
while (*argc > 0)
{
arg = argv[(*argc)-1];
// Stop when you find a non-ChannelType argument
if (CLASS_OF(arg) != Class_ChannelType)
{
break;
}
VALUE_TO_ENUM(arg, ch_arg, ChannelType);
channels |= ch_arg;
*argc -= 1;
}
if (channels == 0)
{
channels = DefaultChannels;
}
return channels;
}
/*
Extern: raise_ChannelType_error
Purpose: raise TypeError when an non-ChannelType object
is unexpectedly encountered
*/
void
raise_ChannelType_error(VALUE arg)
{
rb_raise(rb_eTypeError, "argument must be a ChannelType value (%s given)"
, rb_class2name(CLASS_OF(arg)));
}
/*
Static: call_trace_proc
Purpose: If Magick.trace_proc is not nil, build an argument
list and call the proc.
*/
static void call_trace_proc(Image *image, const char *which)
{
volatile VALUE trace;
VALUE trace_args[4];
if (rb_ivar_defined(Module_Magick, rm_ID_trace_proc) == Qtrue)
{
trace = rb_ivar_get(Module_Magick, rm_ID_trace_proc);
if (!NIL_P(trace))
{
// Maybe the stack won't get extended until we need the space.
char buffer[MaxTextExtent];
int n;
trace_args[0] = ID2SYM(rb_intern(which));
build_inspect_string(image, buffer, sizeof(buffer));
trace_args[1] = rb_str_new2(buffer);
n = sprintf(buffer, "%p", (void *)image);
buffer[n] = '\0';
trace_args[2] = rb_str_new2(buffer+2); // don't use leading 0x
trace_args[3] = ID2SYM(THIS_FUNC());
(void) rb_funcall2(trace, rm_ID_call, 4, (VALUE *)trace_args);
}
}
}
/*
External: rm_trace_creation
Purpose: should be obvious
*/
void rm_trace_creation(Image *image)
{
call_trace_proc(image, "c");
}
/*
External: rm_image_destroy
Purpose: Called from GC when all references to the image have gone out
of scope.
Notes: A NULL Image pointer indicates that the image has already been
destroyed by Image#destroy!
*/
void rm_image_destroy(void *img)
{
Image *image = (Image *)img;
if (img != NULL)
{
call_trace_proc(image, "d");
(void) DestroyImage(image);
}
}
|
#to_blob ⇒ Object
#to_color ⇒ Object
#transparent ⇒ Object
#transparent_chroma ⇒ Object
#transpose ⇒ Object
#transpose! ⇒ Object
#transverse ⇒ Object
#transverse! ⇒ Object
#trim ⇒ Object
#trim! ⇒ Object
#undefine ⇒ Object
#unique_colors ⇒ Object
#unsharp_mask ⇒ Object
#unsharp_mask_channel ⇒ Object
#view(x, y, width, height) ⇒ Object
Construct a view. If a block is present, yield and pass the view object, otherwise return the view object.
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 |
# File 'lib/RMagick.rb', line 1041 def view(x, y, width, height) view = View.new(self, x, y, width, height) if block_given? begin yield(view) ensure view.sync end return nil else return view end end |