rmagick-windows 2.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.editorconfig +14 -0
- data/.gitignore +23 -0
- data/.hound.yml +2 -0
- data/.rspec +1 -0
- data/.rubocop.yml +340 -0
- data/.simplecov +27 -0
- data/.travis.yml +60 -0
- data/CHANGELOG.md +915 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +50 -0
- data/Doxyfile +1514 -0
- data/Gemfile +10 -0
- data/LICENSE +20 -0
- data/README.textile +257 -0
- data/Rakefile +188 -0
- data/before_install_linux.sh +32 -0
- data/before_install_osx.sh +2 -0
- data/deprecated/RMagick.rb +6 -0
- data/doc/.cvsignore +1 -0
- data/doc/comtasks.html +287 -0
- data/doc/constants.html +1581 -0
- data/doc/css/doc.css +299 -0
- data/doc/css/popup.css +34 -0
- data/doc/css/ref.css +67 -0
- data/doc/draw.html +3272 -0
- data/doc/ex/InitialCoords.rb +22 -0
- data/doc/ex/NewCoordSys.rb +30 -0
- data/doc/ex/OrigCoordSys.rb +16 -0
- data/doc/ex/PreserveAspectRatio.rb +204 -0
- data/doc/ex/RotateScale.rb +36 -0
- data/doc/ex/Skew.rb +38 -0
- data/doc/ex/Use01.rb +15 -0
- data/doc/ex/Use02.rb +20 -0
- data/doc/ex/Use03.rb +16 -0
- data/doc/ex/ViewBox.rb +31 -0
- data/doc/ex/adaptive_threshold.rb +9 -0
- data/doc/ex/add_noise.rb +16 -0
- data/doc/ex/affine.rb +48 -0
- data/doc/ex/affine_transform.rb +20 -0
- data/doc/ex/arc.rb +49 -0
- data/doc/ex/arcpath.rb +32 -0
- data/doc/ex/arcs01.rb +28 -0
- data/doc/ex/arcs02.rb +59 -0
- data/doc/ex/average.rb +15 -0
- data/doc/ex/axes.rb +64 -0
- data/doc/ex/baseline_shift01.rb +17 -0
- data/doc/ex/bilevel_channel.rb +8 -0
- data/doc/ex/blur_image.rb +12 -0
- data/doc/ex/border.rb +10 -0
- data/doc/ex/bounding_box.rb +42 -0
- data/doc/ex/cbezier1.rb +41 -0
- data/doc/ex/cbezier2.rb +41 -0
- data/doc/ex/cbezier3.rb +41 -0
- data/doc/ex/cbezier4.rb +42 -0
- data/doc/ex/cbezier5.rb +42 -0
- data/doc/ex/cbezier6.rb +53 -0
- data/doc/ex/channel.rb +25 -0
- data/doc/ex/charcoal.rb +12 -0
- data/doc/ex/chop.rb +29 -0
- data/doc/ex/circle.rb +33 -0
- data/doc/ex/circle01.rb +16 -0
- data/doc/ex/clip_path.rb +60 -0
- data/doc/ex/coalesce.rb +57 -0
- data/doc/ex/color_fill_to_border.rb +29 -0
- data/doc/ex/color_floodfill.rb +28 -0
- data/doc/ex/color_histogram.rb +47 -0
- data/doc/ex/color_reset.rb +11 -0
- data/doc/ex/colorize.rb +16 -0
- data/doc/ex/colors.rb +64 -0
- data/doc/ex/compose_mask.rb +22 -0
- data/doc/ex/composite.rb +133 -0
- data/doc/ex/composite_layers.rb +53 -0
- data/doc/ex/composite_tiled.rb +21 -0
- data/doc/ex/contrast.rb +36 -0
- data/doc/ex/crop.rb +31 -0
- data/doc/ex/crop_with_gravity.rb +42 -0
- data/doc/ex/cubic01.rb +43 -0
- data/doc/ex/cubic02.rb +91 -0
- data/doc/ex/cycle_colormap.rb +21 -0
- data/doc/ex/dissolve.rb +12 -0
- data/doc/ex/drawcomp.rb +42 -0
- data/doc/ex/drop_shadow.rb +60 -0
- data/doc/ex/edge.rb +11 -0
- data/doc/ex/ellipse.rb +45 -0
- data/doc/ex/ellipse01.rb +21 -0
- data/doc/ex/emboss.rb +11 -0
- data/doc/ex/enhance.rb +28 -0
- data/doc/ex/equalize.rb +11 -0
- data/doc/ex/evenodd.rb +42 -0
- data/doc/ex/fill_pattern.rb +23 -0
- data/doc/ex/flatten_images.rb +36 -0
- data/doc/ex/flip.rb +11 -0
- data/doc/ex/flop.rb +11 -0
- data/doc/ex/font_styles.rb +32 -0
- data/doc/ex/fonts.rb +20 -0
- data/doc/ex/frame.rb +12 -0
- data/doc/ex/gaussian_blur.rb +11 -0
- data/doc/ex/get_multiline_type_metrics.rb +41 -0
- data/doc/ex/get_pixels.rb +47 -0
- data/doc/ex/get_type_metrics.rb +141 -0
- data/doc/ex/gradientfill.rb +27 -0
- data/doc/ex/grav.rb +45 -0
- data/doc/ex/gravity.rb +80 -0
- data/doc/ex/group.rb +26 -0
- data/doc/ex/hatchfill.rb +27 -0
- data/doc/ex/image.rb +44 -0
- data/doc/ex/images/Apple.miff +0 -0
- data/doc/ex/images/Ballerina.jpg +0 -0
- data/doc/ex/images/Ballerina3.jpg +0 -0
- data/doc/ex/images/Button_0.gif +0 -0
- data/doc/ex/images/Button_1.gif +0 -0
- data/doc/ex/images/Button_2.gif +0 -0
- data/doc/ex/images/Button_3.gif +0 -0
- data/doc/ex/images/Button_4.gif +0 -0
- data/doc/ex/images/Button_5.gif +0 -0
- data/doc/ex/images/Button_6.gif +0 -0
- data/doc/ex/images/Button_7.gif +0 -0
- data/doc/ex/images/Button_8.gif +0 -0
- data/doc/ex/images/Button_9.gif +0 -0
- data/doc/ex/images/Button_A.gif +0 -0
- data/doc/ex/images/Button_B.gif +0 -0
- data/doc/ex/images/Button_C.gif +0 -0
- data/doc/ex/images/Button_D.gif +0 -0
- data/doc/ex/images/Button_E.gif +0 -0
- data/doc/ex/images/Button_F.gif +0 -0
- data/doc/ex/images/Button_G.gif +0 -0
- data/doc/ex/images/Button_H.gif +0 -0
- data/doc/ex/images/Button_I.gif +0 -0
- data/doc/ex/images/Button_J.gif +0 -0
- data/doc/ex/images/Button_K.gif +0 -0
- data/doc/ex/images/Button_L.gif +0 -0
- data/doc/ex/images/Button_M.gif +0 -0
- data/doc/ex/images/Button_N.gif +0 -0
- data/doc/ex/images/Button_O.gif +0 -0
- data/doc/ex/images/Button_P.gif +0 -0
- data/doc/ex/images/Button_Q.gif +0 -0
- data/doc/ex/images/Button_R.gif +0 -0
- data/doc/ex/images/Button_S.gif +0 -0
- data/doc/ex/images/Button_T.gif +0 -0
- data/doc/ex/images/Button_U.gif +0 -0
- data/doc/ex/images/Button_V.gif +0 -0
- data/doc/ex/images/Button_W.gif +0 -0
- data/doc/ex/images/Button_X.gif +0 -0
- data/doc/ex/images/Button_Y.gif +0 -0
- data/doc/ex/images/Button_Z.gif +0 -0
- data/doc/ex/images/Cheetah.jpg +0 -0
- data/doc/ex/images/Coffee.wmf +0 -0
- data/doc/ex/images/Flower_Hat.jpg +0 -0
- data/doc/ex/images/Gold_Statue.jpg +0 -0
- data/doc/ex/images/Hot_Air_Balloons.jpg +0 -0
- data/doc/ex/images/Hot_Air_Balloons_H.jpg +0 -0
- data/doc/ex/images/Leaf.miff +0 -0
- data/doc/ex/images/No.wmf +0 -0
- data/doc/ex/images/Polynesia.jpg +0 -0
- data/doc/ex/images/Red_Rocks.jpg +0 -0
- data/doc/ex/images/Rocks_On_Beach.miff +0 -0
- data/doc/ex/images/Shorts.jpg +0 -0
- data/doc/ex/images/Snake.wmf +0 -0
- data/doc/ex/images/Violin.jpg +0 -0
- data/doc/ex/images/Yellow_Rose.miff +0 -0
- data/doc/ex/images/big-duck.gif +0 -0
- data/doc/ex/images/duck.gif +0 -0
- data/doc/ex/images/duck0.gif +0 -0
- data/doc/ex/images/duck1.gif +0 -0
- data/doc/ex/images/duck10.gif +0 -0
- data/doc/ex/images/duck11.gif +0 -0
- data/doc/ex/images/duck12.gif +0 -0
- data/doc/ex/images/duck13.gif +0 -0
- data/doc/ex/images/duck14.gif +0 -0
- data/doc/ex/images/duck15.gif +0 -0
- data/doc/ex/images/duck2.gif +0 -0
- data/doc/ex/images/duck3.gif +0 -0
- data/doc/ex/images/duck4.gif +0 -0
- data/doc/ex/images/duck5.gif +0 -0
- data/doc/ex/images/duck6.gif +0 -0
- data/doc/ex/images/duck7.gif +0 -0
- data/doc/ex/images/duck8.gif +0 -0
- data/doc/ex/images/duck9.gif +0 -0
- data/doc/ex/images/graydient230x6.gif +0 -0
- data/doc/ex/images/image_with_profile.jpg +0 -0
- data/doc/ex/images/logo400x83.gif +0 -0
- data/doc/ex/images/model.miff +0 -0
- data/doc/ex/images/notimplemented.gif +0 -0
- data/doc/ex/images/smile.miff +0 -0
- data/doc/ex/images/spin.gif +0 -0
- data/doc/ex/implode.rb +34 -0
- data/doc/ex/level.rb +11 -0
- data/doc/ex/level_colors.rb +11 -0
- data/doc/ex/line.rb +41 -0
- data/doc/ex/line01.rb +21 -0
- data/doc/ex/mask.rb +35 -0
- data/doc/ex/matte_fill_to_border.rb +39 -0
- data/doc/ex/matte_floodfill.rb +32 -0
- data/doc/ex/matte_replace.rb +39 -0
- data/doc/ex/median_filter.rb +28 -0
- data/doc/ex/modulate.rb +11 -0
- data/doc/ex/mono.rb +23 -0
- data/doc/ex/morph.rb +25 -0
- data/doc/ex/mosaic.rb +35 -0
- data/doc/ex/motion_blur.rb +11 -0
- data/doc/ex/negate.rb +11 -0
- data/doc/ex/negate_channel.rb +9 -0
- data/doc/ex/nested_rvg.rb +21 -0
- data/doc/ex/nonzero.rb +42 -0
- data/doc/ex/normalize.rb +11 -0
- data/doc/ex/oil_paint.rb +11 -0
- data/doc/ex/opacity.rb +37 -0
- data/doc/ex/ordered_dither.rb +11 -0
- data/doc/ex/path.rb +63 -0
- data/doc/ex/pattern1.rb +25 -0
- data/doc/ex/pattern2.rb +26 -0
- data/doc/ex/polaroid.rb +27 -0
- data/doc/ex/polygon.rb +23 -0
- data/doc/ex/polygon01.rb +21 -0
- data/doc/ex/polyline.rb +22 -0
- data/doc/ex/polyline01.rb +21 -0
- data/doc/ex/posterize.rb +8 -0
- data/doc/ex/preview.rb +8 -0
- data/doc/ex/qbezierpath.rb +52 -0
- data/doc/ex/quad01.rb +34 -0
- data/doc/ex/quantize-m.rb +25 -0
- data/doc/ex/radial_blur.rb +9 -0
- data/doc/ex/raise.rb +8 -0
- data/doc/ex/random_threshold_channel.rb +13 -0
- data/doc/ex/rect01.rb +14 -0
- data/doc/ex/rect02.rb +20 -0
- data/doc/ex/rectangle.rb +34 -0
- data/doc/ex/reduce_noise.rb +28 -0
- data/doc/ex/remap.rb +11 -0
- data/doc/ex/remap_images.rb +19 -0
- data/doc/ex/resize_to_fill.rb +8 -0
- data/doc/ex/resize_to_fit.rb +8 -0
- data/doc/ex/roll.rb +9 -0
- data/doc/ex/rotate.rb +44 -0
- data/doc/ex/rotate_f.rb +14 -0
- data/doc/ex/roundrect.rb +33 -0
- data/doc/ex/rubyname.rb +30 -0
- data/doc/ex/rvg_clippath.rb +12 -0
- data/doc/ex/rvg_linecap.rb +42 -0
- data/doc/ex/rvg_linejoin.rb +40 -0
- data/doc/ex/rvg_opacity.rb +18 -0
- data/doc/ex/rvg_pattern.rb +26 -0
- data/doc/ex/rvg_stroke_dasharray.rb +11 -0
- data/doc/ex/segment.rb +11 -0
- data/doc/ex/sepiatone.rb +7 -0
- data/doc/ex/shade.rb +11 -0
- data/doc/ex/shadow.rb +30 -0
- data/doc/ex/shave.rb +15 -0
- data/doc/ex/shear.rb +10 -0
- data/doc/ex/sketch.rb +17 -0
- data/doc/ex/skewx.rb +51 -0
- data/doc/ex/skewy.rb +47 -0
- data/doc/ex/smile.rb +125 -0
- data/doc/ex/solarize.rb +11 -0
- data/doc/ex/sparse_color.rb +54 -0
- data/doc/ex/splice.rb +8 -0
- data/doc/ex/spread.rb +11 -0
- data/doc/ex/stegano.rb +55 -0
- data/doc/ex/stroke_dasharray.rb +42 -0
- data/doc/ex/stroke_fill.rb +10 -0
- data/doc/ex/stroke_linecap.rb +44 -0
- data/doc/ex/stroke_linejoin.rb +48 -0
- data/doc/ex/stroke_width.rb +49 -0
- data/doc/ex/swirl.rb +17 -0
- data/doc/ex/text.rb +37 -0
- data/doc/ex/text01.rb +16 -0
- data/doc/ex/text_align.rb +36 -0
- data/doc/ex/text_antialias.rb +37 -0
- data/doc/ex/text_styles.rb +19 -0
- data/doc/ex/text_undercolor.rb +28 -0
- data/doc/ex/texture_fill_to_border.rb +34 -0
- data/doc/ex/texture_floodfill.rb +32 -0
- data/doc/ex/texturefill.rb +24 -0
- data/doc/ex/threshold.rb +13 -0
- data/doc/ex/to_blob.rb +13 -0
- data/doc/ex/translate.rb +39 -0
- data/doc/ex/transparent.rb +38 -0
- data/doc/ex/transpose.rb +9 -0
- data/doc/ex/transverse.rb +9 -0
- data/doc/ex/tref01.rb +24 -0
- data/doc/ex/triangle01.rb +15 -0
- data/doc/ex/trim.rb +23 -0
- data/doc/ex/tspan01.rb +17 -0
- data/doc/ex/tspan02.rb +17 -0
- data/doc/ex/tspan03.rb +19 -0
- data/doc/ex/unsharp_mask.rb +28 -0
- data/doc/ex/viewex.rb +33 -0
- data/doc/ex/vignette.rb +12 -0
- data/doc/ex/watermark.rb +27 -0
- data/doc/ex/wave.rb +9 -0
- data/doc/ex/wet_floor.rb +58 -0
- data/doc/ex/writing_mode01.rb +26 -0
- data/doc/ex/writing_mode02.rb +26 -0
- data/doc/ilist.html +2056 -0
- data/doc/image1.html +4680 -0
- data/doc/image2.html +3665 -0
- data/doc/image3.html +4522 -0
- data/doc/imageattrs.html +1638 -0
- data/doc/imusage.html +514 -0
- data/doc/index.html +416 -0
- data/doc/info.html +1499 -0
- data/doc/magick.html +565 -0
- data/doc/optequiv.html +2435 -0
- data/doc/rvg.html +975 -0
- data/doc/rvgclip.html +248 -0
- data/doc/rvggroup.html +305 -0
- data/doc/rvgimage.html +289 -0
- data/doc/rvgpattern.html +475 -0
- data/doc/rvgshape.html +406 -0
- data/doc/rvgstyle.html +270 -0
- data/doc/rvgtext.html +465 -0
- data/doc/rvgtspan.html +238 -0
- data/doc/rvgtut.html +530 -0
- data/doc/rvguse.html +145 -0
- data/doc/rvgxform.html +294 -0
- data/doc/scripts/doc.js +22 -0
- data/doc/scripts/stripeTables.js +23 -0
- data/doc/struct.html +1339 -0
- data/doc/usage.html +1621 -0
- data/examples/constitute.rb +7 -0
- data/examples/crop_with_gravity.rb +42 -0
- data/examples/demo.rb +324 -0
- data/examples/describe.rb +43 -0
- data/examples/find_similar_region.rb +34 -0
- data/examples/histogram.rb +321 -0
- data/examples/identify.rb +185 -0
- data/examples/image_opacity.rb +29 -0
- data/examples/import_export.rb +31 -0
- data/examples/pattern_fill.rb +38 -0
- data/examples/rotating_text.rb +44 -0
- data/examples/spinner.rb +49 -0
- data/examples/thumbnail.rb +64 -0
- data/examples/vignette.rb +78 -0
- data/ext/RMagick/extconf.rb +548 -0
- data/ext/RMagick/rmagick.c +401 -0
- data/ext/RMagick/rmagick.h +1287 -0
- data/ext/RMagick/rmdraw.c +2022 -0
- data/ext/RMagick/rmenum.c +1235 -0
- data/ext/RMagick/rmfill.c +720 -0
- data/ext/RMagick/rmilist.c +1270 -0
- data/ext/RMagick/rmimage.c +15427 -0
- data/ext/RMagick/rminfo.c +2590 -0
- data/ext/RMagick/rmmain.c +1741 -0
- data/ext/RMagick/rmmontage.c +519 -0
- data/ext/RMagick/rmpixel.c +1114 -0
- data/ext/RMagick/rmstruct.c +1124 -0
- data/ext/RMagick/rmutil.c +1754 -0
- data/lib/rmagick.rb +1 -0
- data/lib/rmagick/version.rb +6 -0
- data/lib/rmagick_internal.rb +1947 -0
- data/lib/rvg/clippath.rb +45 -0
- data/lib/rvg/container.rb +122 -0
- data/lib/rvg/deep_equal.rb +52 -0
- data/lib/rvg/describable.rb +47 -0
- data/lib/rvg/embellishable.rb +391 -0
- data/lib/rvg/misc.rb +723 -0
- data/lib/rvg/paint.rb +50 -0
- data/lib/rvg/pathdata.rb +126 -0
- data/lib/rvg/rvg.rb +283 -0
- data/lib/rvg/stretchable.rb +165 -0
- data/lib/rvg/stylable.rb +116 -0
- data/lib/rvg/text.rb +172 -0
- data/lib/rvg/transformable.rb +126 -0
- data/lib/rvg/units.rb +63 -0
- data/rmagick.gemspec +46 -0
- data/spec/rmagick/ImageList1_spec.rb +24 -0
- data/spec/rmagick/draw_spec.rb +156 -0
- data/spec/rmagick/image/blue_shift_spec.rb +16 -0
- data/spec/rmagick/image/composite_spec.rb +140 -0
- data/spec/rmagick/image/constitute_spec.rb +15 -0
- data/spec/rmagick/image/dispatch_spec.rb +18 -0
- data/spec/rmagick/image/from_blob_spec.rb +14 -0
- data/spec/rmagick/image/ping_spec.rb +14 -0
- data/spec/rmagick/image/properties_spec.rb +29 -0
- data/spec/spec_helper.rb +4 -0
- data/test/Image1.rb +565 -0
- data/test/Image2.rb +1304 -0
- data/test/Image3.rb +1030 -0
- data/test/ImageList1.rb +806 -0
- data/test/ImageList2.rb +385 -0
- data/test/Image_attributes.rb +697 -0
- data/test/Import_Export.rb +121 -0
- data/test/Info.rb +345 -0
- data/test/Magick.rb +321 -0
- data/test/Pixel.rb +116 -0
- data/test/Preview.rb +57 -0
- data/test/cmyk.icm +0 -0
- data/test/srgb.icm +0 -0
- data/test/test_all_basic.rb +38 -0
- data/test/tmpnam_test.rb +50 -0
- data/wercker.yml +10 -0
- metadata +509 -0
@@ -0,0 +1,720 @@
|
|
1
|
+
/**************************************************************************//**
|
2
|
+
* GradientFill, TextureFill class definitions for RMagick.
|
3
|
+
*
|
4
|
+
* Copyright © 2002 - 2009 by Timothy P. Hunter
|
5
|
+
*
|
6
|
+
* Changes since Nov. 2009 copyright © by Benjamin Thomas and Omer Bar-or
|
7
|
+
*
|
8
|
+
* @file rmfill.c
|
9
|
+
* @version $Id: rmfill.c,v 1.33 2009/12/20 02:33:33 baror Exp $
|
10
|
+
* @author Tim Hunter
|
11
|
+
******************************************************************************/
|
12
|
+
|
13
|
+
#include "rmagick.h"
|
14
|
+
|
15
|
+
/** Data associated with a GradientFill */
|
16
|
+
typedef struct
|
17
|
+
{
|
18
|
+
double x1; /**< x position of first point */
|
19
|
+
double y1; /**< y position of first point */
|
20
|
+
double x2; /**< x position of second point */
|
21
|
+
double y2; /**< y position of second point */
|
22
|
+
PixelPacket start_color; /**< the start color */
|
23
|
+
PixelPacket stop_color; /**< the stop color */
|
24
|
+
} rm_GradientFill;
|
25
|
+
|
26
|
+
/** Data associated with a TextureFill */
|
27
|
+
typedef struct
|
28
|
+
{
|
29
|
+
Image *texture; /**< the texture */
|
30
|
+
} rm_TextureFill;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Free Fill or Fill subclass object (except for TextureFill).
|
34
|
+
*
|
35
|
+
* No Ruby usage (internal function)
|
36
|
+
*
|
37
|
+
* @param fill the fill
|
38
|
+
*/
|
39
|
+
static void free_Fill(void *fill)
|
40
|
+
{
|
41
|
+
xfree(fill);
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Create new GradientFill object.
|
46
|
+
*
|
47
|
+
* No Ruby usage (internal function)
|
48
|
+
*
|
49
|
+
* @param class the Ruby class to use
|
50
|
+
* @return a new GradientFill object
|
51
|
+
*/
|
52
|
+
VALUE
|
53
|
+
GradientFill_alloc(VALUE class)
|
54
|
+
{
|
55
|
+
rm_GradientFill *fill;
|
56
|
+
|
57
|
+
return Data_Make_Struct(class, rm_GradientFill, NULL, free_Fill, fill);
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Store the vector points and the start and stop colors.
|
63
|
+
*
|
64
|
+
* Ruby usage:
|
65
|
+
* - @verbatim GradientFill#initialize(x1,y1,x2,y2,start_color,stop_color) @endverbatim
|
66
|
+
*
|
67
|
+
* @param self this object
|
68
|
+
* @param x1 x position of first point
|
69
|
+
* @param y1 y position of first point
|
70
|
+
* @param x2 x position of second point
|
71
|
+
* @param y2 y position of second point
|
72
|
+
* @param start_color the start color
|
73
|
+
* @param stop_color the stop color
|
74
|
+
* @return self
|
75
|
+
*/
|
76
|
+
VALUE
|
77
|
+
GradientFill_initialize(
|
78
|
+
VALUE self,
|
79
|
+
VALUE x1,
|
80
|
+
VALUE y1,
|
81
|
+
VALUE x2,
|
82
|
+
VALUE y2,
|
83
|
+
VALUE start_color,
|
84
|
+
VALUE stop_color)
|
85
|
+
{
|
86
|
+
rm_GradientFill *fill;
|
87
|
+
|
88
|
+
Data_Get_Struct(self, rm_GradientFill, fill);
|
89
|
+
|
90
|
+
fill->x1 = NUM2DBL(x1);
|
91
|
+
fill->y1 = NUM2DBL(y1);
|
92
|
+
fill->x2 = NUM2DBL(x2);
|
93
|
+
fill->y2 = NUM2DBL(y2);
|
94
|
+
Color_to_PixelPacket(&fill->start_color, start_color);
|
95
|
+
Color_to_PixelPacket(&fill->stop_color, stop_color);
|
96
|
+
|
97
|
+
return self;
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Do a gradient that radiates from a point.
|
102
|
+
*
|
103
|
+
* No Ruby usage (internal function)
|
104
|
+
*
|
105
|
+
* @param image the image on which to do the gradient
|
106
|
+
* @param x0 x position of the point
|
107
|
+
* @param y0 y position of the point
|
108
|
+
* @param start_color the start color
|
109
|
+
* @param stop_color the stop color
|
110
|
+
*/
|
111
|
+
static void
|
112
|
+
point_fill(
|
113
|
+
Image *image,
|
114
|
+
double x0,
|
115
|
+
double y0,
|
116
|
+
PixelPacket *start_color,
|
117
|
+
PixelPacket *stop_color)
|
118
|
+
{
|
119
|
+
double steps, distance;
|
120
|
+
unsigned long x, y;
|
121
|
+
MagickRealType red_step, green_step, blue_step;
|
122
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
123
|
+
ExceptionInfo *exception;
|
124
|
+
|
125
|
+
exception = AcquireExceptionInfo();
|
126
|
+
#endif
|
127
|
+
|
128
|
+
steps = sqrt((double)((image->columns-x0)*(image->columns-x0)
|
129
|
+
+ (image->rows-y0)*(image->rows-y0)));
|
130
|
+
|
131
|
+
red_step = ((MagickRealType)stop_color->red - (MagickRealType)start_color->red) / steps;
|
132
|
+
green_step = ((MagickRealType)stop_color->green - (MagickRealType)start_color->green) / steps;
|
133
|
+
blue_step = ((MagickRealType)stop_color->blue - (MagickRealType)start_color->blue) / steps;
|
134
|
+
|
135
|
+
for (y = 0; y < image->rows; y++)
|
136
|
+
{
|
137
|
+
PixelPacket *row_pixels;
|
138
|
+
|
139
|
+
#if defined(HAVE_QUEUEAUTHENTICPIXELS)
|
140
|
+
row_pixels = QueueAuthenticPixels(image, 0, (long int)y, image->columns, 1, exception);
|
141
|
+
CHECK_EXCEPTION()
|
142
|
+
#else
|
143
|
+
row_pixels = SetImagePixels(image, 0, (long int)y, image->columns, 1);
|
144
|
+
rm_check_image_exception(image, RetainOnError);
|
145
|
+
#endif
|
146
|
+
for (x = 0; x < image->columns; x++)
|
147
|
+
{
|
148
|
+
distance = sqrt((double)((x-x0)*(x-x0)+(y-y0)*(y-y0)));
|
149
|
+
row_pixels[x].red = ROUND_TO_QUANTUM(start_color->red + (distance * red_step));
|
150
|
+
row_pixels[x].green = ROUND_TO_QUANTUM(start_color->green + (distance * green_step));
|
151
|
+
row_pixels[x].blue = ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step));
|
152
|
+
row_pixels[x].opacity = OpaqueOpacity;
|
153
|
+
}
|
154
|
+
|
155
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS)
|
156
|
+
SyncAuthenticPixels(image, exception);
|
157
|
+
CHECK_EXCEPTION()
|
158
|
+
#else
|
159
|
+
SyncImagePixels(image);
|
160
|
+
rm_check_image_exception(image, RetainOnError);
|
161
|
+
#endif
|
162
|
+
}
|
163
|
+
|
164
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
165
|
+
DestroyExceptionInfo(exception);
|
166
|
+
#endif
|
167
|
+
}
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Do a gradient fill that proceeds from a vertical line to the right and left
|
171
|
+
* sides of the image.
|
172
|
+
*
|
173
|
+
* No Ruby usage (internal function)
|
174
|
+
*
|
175
|
+
* @param image the image on which to do the gradient
|
176
|
+
* @param x1 x position of the vertical line
|
177
|
+
* @param start_color the start color
|
178
|
+
* @param stop_color the stop color
|
179
|
+
*/
|
180
|
+
static void
|
181
|
+
vertical_fill(
|
182
|
+
Image *image,
|
183
|
+
double x1,
|
184
|
+
PixelPacket *start_color,
|
185
|
+
PixelPacket *stop_color)
|
186
|
+
{
|
187
|
+
double steps;
|
188
|
+
unsigned long x, y;
|
189
|
+
PixelPacket *master;
|
190
|
+
MagickRealType red_step, green_step, blue_step;
|
191
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
192
|
+
ExceptionInfo *exception;
|
193
|
+
|
194
|
+
exception = AcquireExceptionInfo();
|
195
|
+
#endif
|
196
|
+
|
197
|
+
steps = FMAX(x1, ((long)image->columns)-x1);
|
198
|
+
|
199
|
+
// If x is to the left of the x-axis, add that many steps so that
|
200
|
+
// the color at the right side will be that many steps away from
|
201
|
+
// the stop color.
|
202
|
+
if (x1 < 0)
|
203
|
+
{
|
204
|
+
steps -= x1;
|
205
|
+
}
|
206
|
+
|
207
|
+
red_step = ((MagickRealType)stop_color->red - (MagickRealType)start_color->red) / steps;
|
208
|
+
green_step = ((MagickRealType)stop_color->green - (MagickRealType)start_color->green) / steps;
|
209
|
+
blue_step = ((MagickRealType)stop_color->blue - (MagickRealType)start_color->blue) / steps;
|
210
|
+
|
211
|
+
// All the rows are the same. Make a "master row" and simply copy
|
212
|
+
// it to each actual row.
|
213
|
+
master = ALLOC_N(PixelPacket, image->columns);
|
214
|
+
|
215
|
+
for (x = 0; x < image->columns; x++)
|
216
|
+
{
|
217
|
+
double distance = fabs(x1 - x);
|
218
|
+
master[x].red = ROUND_TO_QUANTUM(start_color->red + (red_step * distance));
|
219
|
+
master[x].green = ROUND_TO_QUANTUM(start_color->green + (green_step * distance));
|
220
|
+
master[x].blue = ROUND_TO_QUANTUM(start_color->blue + (blue_step * distance));
|
221
|
+
master[x].opacity = OpaqueOpacity;
|
222
|
+
}
|
223
|
+
|
224
|
+
// Now copy the master row to each actual row.
|
225
|
+
for (y = 0; y < image->rows; y++)
|
226
|
+
{
|
227
|
+
PixelPacket *row_pixels;
|
228
|
+
|
229
|
+
#if defined(HAVE_QUEUEAUTHENTICPIXELS)
|
230
|
+
row_pixels = QueueAuthenticPixels(image, 0, (long int)y, image->columns, 1, exception);
|
231
|
+
CHECK_EXCEPTION()
|
232
|
+
#else
|
233
|
+
row_pixels = SetImagePixels(image, 0, (long int)y, image->columns, 1);
|
234
|
+
rm_check_image_exception(image, RetainOnError);
|
235
|
+
#endif
|
236
|
+
|
237
|
+
memcpy(row_pixels, master, image->columns * sizeof(PixelPacket));
|
238
|
+
|
239
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS)
|
240
|
+
SyncAuthenticPixels(image, exception);
|
241
|
+
CHECK_EXCEPTION()
|
242
|
+
#else
|
243
|
+
SyncImagePixels(image);
|
244
|
+
rm_check_image_exception(image, RetainOnError);
|
245
|
+
#endif
|
246
|
+
}
|
247
|
+
|
248
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
249
|
+
DestroyExceptionInfo(exception);
|
250
|
+
#endif
|
251
|
+
|
252
|
+
xfree((void *)master);
|
253
|
+
}
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Do a gradient fill that starts from a horizontal line.
|
257
|
+
*
|
258
|
+
* No Ruby usage (internal function)
|
259
|
+
*
|
260
|
+
* @param image the image on which to do the gradient
|
261
|
+
* @param y1 y position of the horizontal line
|
262
|
+
* @param start_color the start color
|
263
|
+
* @param stop_color the stop color
|
264
|
+
*/
|
265
|
+
static void
|
266
|
+
horizontal_fill(
|
267
|
+
Image *image,
|
268
|
+
double y1,
|
269
|
+
PixelPacket *start_color,
|
270
|
+
PixelPacket *stop_color)
|
271
|
+
{
|
272
|
+
double steps;
|
273
|
+
unsigned long x, y;
|
274
|
+
PixelPacket *master;
|
275
|
+
MagickRealType red_step, green_step, blue_step;
|
276
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
277
|
+
ExceptionInfo *exception;
|
278
|
+
|
279
|
+
exception = AcquireExceptionInfo();
|
280
|
+
#endif
|
281
|
+
|
282
|
+
steps = FMAX(y1, ((long)image->rows)-y1);
|
283
|
+
|
284
|
+
// If the line is below the y-axis, add that many steps so the color
|
285
|
+
// at the bottom of the image is that many steps away from the stop color
|
286
|
+
if (y1 < 0)
|
287
|
+
{
|
288
|
+
steps -= y1;
|
289
|
+
}
|
290
|
+
|
291
|
+
red_step = ((MagickRealType)stop_color->red - (MagickRealType)start_color->red) / steps;
|
292
|
+
green_step = ((MagickRealType)stop_color->green - (MagickRealType)start_color->green) / steps;
|
293
|
+
blue_step = ((MagickRealType)stop_color->blue - (MagickRealType)start_color->blue) / steps;
|
294
|
+
|
295
|
+
// All the columns are the same, so make a master column and copy it to
|
296
|
+
// each of the "real" columns.
|
297
|
+
master = ALLOC_N(PixelPacket, image->rows);
|
298
|
+
|
299
|
+
for (y = 0; y < image->rows; y++)
|
300
|
+
{
|
301
|
+
double distance = fabs(y1 - y);
|
302
|
+
master[y].red = ROUND_TO_QUANTUM(start_color->red + (distance * red_step));
|
303
|
+
master[y].green = ROUND_TO_QUANTUM(start_color->green + (distance * green_step));
|
304
|
+
master[y].blue = ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step));
|
305
|
+
master[y].opacity = OpaqueOpacity;
|
306
|
+
}
|
307
|
+
|
308
|
+
for (x = 0; x < image->columns; x++)
|
309
|
+
{
|
310
|
+
PixelPacket *col_pixels;
|
311
|
+
|
312
|
+
#if defined(HAVE_QUEUEAUTHENTICPIXELS)
|
313
|
+
col_pixels = QueueAuthenticPixels(image, (long int)x, 0, 1, image->rows, exception);
|
314
|
+
#else
|
315
|
+
col_pixels = SetImagePixels(image, (long int)x, 0, 1, image->rows);
|
316
|
+
rm_check_image_exception(image, RetainOnError);
|
317
|
+
#endif
|
318
|
+
memcpy(col_pixels, master, image->rows * sizeof(PixelPacket));
|
319
|
+
|
320
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS)
|
321
|
+
SyncAuthenticPixels(image, exception);
|
322
|
+
CHECK_EXCEPTION()
|
323
|
+
#else
|
324
|
+
SyncImagePixels(image);
|
325
|
+
rm_check_image_exception(image, RetainOnError);
|
326
|
+
#endif
|
327
|
+
}
|
328
|
+
|
329
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
330
|
+
DestroyExceptionInfo(exception);
|
331
|
+
#endif
|
332
|
+
|
333
|
+
xfree((PixelPacket *)master);
|
334
|
+
}
|
335
|
+
|
336
|
+
/**
|
337
|
+
* Do a gradient fill that starts from a diagonal line and ends at the top and
|
338
|
+
* bottom of the image.
|
339
|
+
*
|
340
|
+
* No Ruby usage (internal function)
|
341
|
+
*
|
342
|
+
* @param image the image on which to do the gradient
|
343
|
+
* @param x1 x position of the start of the diagonal line
|
344
|
+
* @param y1 y position of the start of the diagonal line
|
345
|
+
* @param x2 x position of the end of the diagonal line
|
346
|
+
* @param y2 y position of the end of the diagonal line
|
347
|
+
* @param start_color the start color
|
348
|
+
* @param stop_color the stop color
|
349
|
+
*/
|
350
|
+
static void
|
351
|
+
v_diagonal_fill(
|
352
|
+
Image *image,
|
353
|
+
double x1,
|
354
|
+
double y1,
|
355
|
+
double x2,
|
356
|
+
double y2,
|
357
|
+
PixelPacket *start_color,
|
358
|
+
PixelPacket *stop_color)
|
359
|
+
{
|
360
|
+
unsigned long x, y;
|
361
|
+
MagickRealType red_step, green_step, blue_step;
|
362
|
+
double m, b, steps = 0.0;
|
363
|
+
double d1, d2;
|
364
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
365
|
+
ExceptionInfo *exception;
|
366
|
+
|
367
|
+
exception = AcquireExceptionInfo();
|
368
|
+
#endif
|
369
|
+
|
370
|
+
// Compute the equation of the line: y=mx+b
|
371
|
+
m = ((double)(y2 - y1))/((double)(x2 - x1));
|
372
|
+
b = y1 - (m * x1);
|
373
|
+
|
374
|
+
// The number of steps is the greatest distance between the line and
|
375
|
+
// the top or bottom of the image between x=0 and x=image->columns
|
376
|
+
// When x=0, y=b. When x=image->columns, y = m*image->columns+b
|
377
|
+
d1 = b;
|
378
|
+
d2 = m * image->columns + b;
|
379
|
+
|
380
|
+
if (d1 < 0 && d2 < 0)
|
381
|
+
{
|
382
|
+
steps += FMAX(fabs(d1),fabs(d2));
|
383
|
+
}
|
384
|
+
else if (d1 > (double)image->rows && d2 > (double)image->rows)
|
385
|
+
{
|
386
|
+
steps += FMAX(d1-image->rows, d2-image->rows);
|
387
|
+
}
|
388
|
+
|
389
|
+
d1 = FMAX(b, image->rows-b);
|
390
|
+
d2 = FMAX(d2, image->rows-d2);
|
391
|
+
steps += FMAX(d1, d2);
|
392
|
+
|
393
|
+
// If the line is entirely > image->rows, swap the start & end color
|
394
|
+
if (steps < 0)
|
395
|
+
{
|
396
|
+
PixelPacket t = *stop_color;
|
397
|
+
*stop_color = *start_color;
|
398
|
+
*start_color = t;
|
399
|
+
steps = -steps;
|
400
|
+
}
|
401
|
+
|
402
|
+
red_step = ((MagickRealType)stop_color->red - (MagickRealType)start_color->red) / steps;
|
403
|
+
green_step = ((MagickRealType)stop_color->green - (MagickRealType)start_color->green) / steps;
|
404
|
+
blue_step = ((MagickRealType)stop_color->blue - (MagickRealType)start_color->blue) / steps;
|
405
|
+
|
406
|
+
for (y = 0; y < image->rows; y++)
|
407
|
+
{
|
408
|
+
PixelPacket *row_pixels;
|
409
|
+
|
410
|
+
#if defined(HAVE_QUEUEAUTHENTICPIXELS)
|
411
|
+
row_pixels = QueueAuthenticPixels(image, 0, (long int)y, image->columns, 1, exception);
|
412
|
+
CHECK_EXCEPTION()
|
413
|
+
#else
|
414
|
+
row_pixels = SetImagePixels(image, 0, (long int)y, image->columns, 1);
|
415
|
+
rm_check_image_exception(image, RetainOnError);
|
416
|
+
#endif
|
417
|
+
for (x = 0; x < image->columns; x++)
|
418
|
+
{
|
419
|
+
double distance = (double) abs((int)(y-(m * x + b)));
|
420
|
+
row_pixels[x].red = ROUND_TO_QUANTUM(start_color->red + (distance * red_step));
|
421
|
+
row_pixels[x].green = ROUND_TO_QUANTUM(start_color->green + (distance * green_step));
|
422
|
+
row_pixels[x].blue = ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step));
|
423
|
+
row_pixels[x].opacity = OpaqueOpacity;
|
424
|
+
}
|
425
|
+
|
426
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS)
|
427
|
+
SyncAuthenticPixels(image, exception);
|
428
|
+
CHECK_EXCEPTION()
|
429
|
+
#else
|
430
|
+
SyncImagePixels(image);
|
431
|
+
rm_check_image_exception(image, RetainOnError);
|
432
|
+
#endif
|
433
|
+
}
|
434
|
+
|
435
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
436
|
+
DestroyExceptionInfo(exception);
|
437
|
+
#endif
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
/**
|
442
|
+
* Do a gradient fill that starts from a diagonal line and ends at the sides of
|
443
|
+
* the image.
|
444
|
+
*
|
445
|
+
* No Ruby usage (internal function)
|
446
|
+
*
|
447
|
+
* @param image the image on which to do the gradient
|
448
|
+
* @param x1 x position of the start of the diagonal line
|
449
|
+
* @param y1 y position of the start of the diagonal line
|
450
|
+
* @param x2 x position of the end of the diagonal line
|
451
|
+
* @param y2 y position of the end of the diagonal line
|
452
|
+
* @param start_color the start color
|
453
|
+
* @param stop_color the stop color
|
454
|
+
*/
|
455
|
+
static void
|
456
|
+
h_diagonal_fill(
|
457
|
+
Image *image,
|
458
|
+
double x1,
|
459
|
+
double y1,
|
460
|
+
double x2,
|
461
|
+
double y2,
|
462
|
+
PixelPacket *start_color,
|
463
|
+
PixelPacket *stop_color)
|
464
|
+
{
|
465
|
+
unsigned long x, y;
|
466
|
+
double m, b, steps = 0.0;
|
467
|
+
MagickRealType red_step, green_step, blue_step;
|
468
|
+
double d1, d2;
|
469
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
470
|
+
ExceptionInfo *exception;
|
471
|
+
|
472
|
+
exception = AcquireExceptionInfo();
|
473
|
+
#endif
|
474
|
+
|
475
|
+
// Compute the equation of the line: y=mx+b
|
476
|
+
m = ((double)(y2 - y1))/((double)(x2 - x1));
|
477
|
+
b = y1 - (m * x1);
|
478
|
+
|
479
|
+
// The number of steps is the greatest distance between the line and
|
480
|
+
// the left or right side of the image between y=0 and y=image->rows.
|
481
|
+
// When y=0, x=-b/m. When y=image->rows, x = (image->rows-b)/m.
|
482
|
+
d1 = -b/m;
|
483
|
+
d2 = (double) ((image->rows-b) / m);
|
484
|
+
|
485
|
+
// If the line is entirely to the right or left of the image, increase
|
486
|
+
// the number of steps.
|
487
|
+
if (d1 < 0 && d2 < 0)
|
488
|
+
{
|
489
|
+
steps += FMAX(fabs(d1),fabs(d2));
|
490
|
+
}
|
491
|
+
else if (d1 > (double)image->columns && d2 > (double)image->columns)
|
492
|
+
{
|
493
|
+
steps += FMAX(abs((int)(image->columns-d1)),abs((int)(image->columns-d2)));
|
494
|
+
}
|
495
|
+
|
496
|
+
d1 = FMAX(d1, image->columns-d1);
|
497
|
+
d2 = FMAX(d2, image->columns-d2);
|
498
|
+
steps += FMAX(d1, d2);
|
499
|
+
|
500
|
+
// If the line is entirely > image->columns, swap the start & end color
|
501
|
+
if (steps < 0)
|
502
|
+
{
|
503
|
+
PixelPacket t = *stop_color;
|
504
|
+
*stop_color = *start_color;
|
505
|
+
*start_color = t;
|
506
|
+
steps = -steps;
|
507
|
+
}
|
508
|
+
|
509
|
+
red_step = ((MagickRealType)stop_color->red - (MagickRealType)start_color->red) / steps;
|
510
|
+
green_step = ((MagickRealType)stop_color->green - (MagickRealType)start_color->green) / steps;
|
511
|
+
blue_step = ((MagickRealType)stop_color->blue - (MagickRealType)start_color->blue) / steps;
|
512
|
+
|
513
|
+
for (y = 0; y < image->rows; y++)
|
514
|
+
{
|
515
|
+
PixelPacket *row_pixels;
|
516
|
+
|
517
|
+
#if defined(HAVE_QUEUEAUTHENTICPIXELS)
|
518
|
+
row_pixels = QueueAuthenticPixels(image, 0, (long int)y, image->columns, 1, exception);
|
519
|
+
CHECK_EXCEPTION()
|
520
|
+
#else
|
521
|
+
row_pixels = SetImagePixels(image, 0, (long int)y, image->columns, 1);
|
522
|
+
rm_check_image_exception(image, RetainOnError);
|
523
|
+
#endif
|
524
|
+
for (x = 0; x < image->columns; x++)
|
525
|
+
{
|
526
|
+
double distance = (double) abs((int)(x-((y-b)/m)));
|
527
|
+
row_pixels[x].red = ROUND_TO_QUANTUM(start_color->red + (distance * red_step));
|
528
|
+
row_pixels[x].green = ROUND_TO_QUANTUM(start_color->green + (distance * green_step));
|
529
|
+
row_pixels[x].blue = ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step));
|
530
|
+
row_pixels[x].opacity = OpaqueOpacity;
|
531
|
+
}
|
532
|
+
|
533
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS)
|
534
|
+
SyncAuthenticPixels(image, exception);
|
535
|
+
CHECK_EXCEPTION()
|
536
|
+
#else
|
537
|
+
SyncImagePixels(image);
|
538
|
+
rm_check_image_exception(image, RetainOnError);
|
539
|
+
#endif
|
540
|
+
}
|
541
|
+
|
542
|
+
#if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_QUEUEAUTHENTICPIXELS)
|
543
|
+
DestroyExceptionInfo(exception);
|
544
|
+
#endif
|
545
|
+
}
|
546
|
+
|
547
|
+
/**
|
548
|
+
* Call GradientFill with the start and stop colors specified when this fill
|
549
|
+
* object was created.
|
550
|
+
*
|
551
|
+
* Ruby usage:
|
552
|
+
* - @verbatim GradientFill#fill(image) @endverbatim
|
553
|
+
*
|
554
|
+
* @param self this object
|
555
|
+
* @param image_obj the image
|
556
|
+
* @return self
|
557
|
+
*/
|
558
|
+
VALUE
|
559
|
+
GradientFill_fill(VALUE self, VALUE image_obj)
|
560
|
+
{
|
561
|
+
rm_GradientFill *fill;
|
562
|
+
Image *image;
|
563
|
+
PixelPacket start_color, stop_color;
|
564
|
+
double x1, y1, x2, y2; // points on the line
|
565
|
+
|
566
|
+
Data_Get_Struct(self, rm_GradientFill, fill);
|
567
|
+
image = rm_check_destroyed(image_obj);
|
568
|
+
|
569
|
+
x1 = fill->x1;
|
570
|
+
y1 = fill->y1;
|
571
|
+
x2 = fill->x2;
|
572
|
+
y2 = fill->y2;
|
573
|
+
start_color = fill->start_color;
|
574
|
+
stop_color = fill->stop_color;
|
575
|
+
|
576
|
+
if (fabs(x2-x1) < 0.5) // vertical?
|
577
|
+
{
|
578
|
+
// If the x1,y1 and x2,y2 points are essentially the same
|
579
|
+
if (fabs(y2-y1) < 0.5)
|
580
|
+
{
|
581
|
+
point_fill(image, x1, y1, &start_color, &stop_color);
|
582
|
+
}
|
583
|
+
|
584
|
+
// A vertical line is a special case.
|
585
|
+
else
|
586
|
+
{
|
587
|
+
vertical_fill(image, x1, &start_color, &stop_color);
|
588
|
+
}
|
589
|
+
}
|
590
|
+
|
591
|
+
// A horizontal line is a special case.
|
592
|
+
else if (fabs(y2-y1) < 0.5)
|
593
|
+
{
|
594
|
+
horizontal_fill(image, y1, &start_color, &stop_color);
|
595
|
+
}
|
596
|
+
|
597
|
+
// This is the general case - a diagonal line. If the line is more horizontal
|
598
|
+
// than vertical, use the top and bottom of the image as the ends of the
|
599
|
+
// gradient, otherwise use the sides of the image.
|
600
|
+
else
|
601
|
+
{
|
602
|
+
double m = ((double)(y2 - y1))/((double)(x2 - x1));
|
603
|
+
double diagonal = ((double)image->rows)/image->columns;
|
604
|
+
if (fabs(m) <= diagonal)
|
605
|
+
{
|
606
|
+
v_diagonal_fill(image, x1, y1, x2, y2, &start_color, &stop_color);
|
607
|
+
}
|
608
|
+
else
|
609
|
+
{
|
610
|
+
h_diagonal_fill(image, x1, y1, x2, y2, &start_color, &stop_color);
|
611
|
+
}
|
612
|
+
}
|
613
|
+
|
614
|
+
return self;
|
615
|
+
}
|
616
|
+
|
617
|
+
|
618
|
+
/**
|
619
|
+
* Free the TextureFill struct and the texture image it points to.
|
620
|
+
*
|
621
|
+
* No Ruby usage (internal function)
|
622
|
+
*
|
623
|
+
* Notes:
|
624
|
+
* - Called from GC
|
625
|
+
*
|
626
|
+
* @param fill_obj the TextureFill
|
627
|
+
*/
|
628
|
+
static void
|
629
|
+
free_TextureFill(void *fill_obj)
|
630
|
+
{
|
631
|
+
rm_TextureFill *fill = (rm_TextureFill *)fill_obj;
|
632
|
+
|
633
|
+
// Do not trace destruction
|
634
|
+
(void) DestroyImage(fill->texture);
|
635
|
+
xfree(fill);
|
636
|
+
}
|
637
|
+
|
638
|
+
/**
|
639
|
+
* Create new TextureFill object.
|
640
|
+
*
|
641
|
+
* No Ruby usage (internal function)
|
642
|
+
*
|
643
|
+
* Notes:
|
644
|
+
* - The texture is an Image or Image *object
|
645
|
+
*
|
646
|
+
* @param class the Ruby class to use
|
647
|
+
* @return a new TextureFill object
|
648
|
+
*/
|
649
|
+
VALUE
|
650
|
+
TextureFill_alloc(VALUE class)
|
651
|
+
{
|
652
|
+
rm_TextureFill *fill;
|
653
|
+
return Data_Make_Struct(class
|
654
|
+
, rm_TextureFill
|
655
|
+
, NULL
|
656
|
+
, free_TextureFill
|
657
|
+
, fill);
|
658
|
+
}
|
659
|
+
|
660
|
+
/**
|
661
|
+
* Store the texture image.
|
662
|
+
*
|
663
|
+
* Ruby usage:
|
664
|
+
* - @verbatim TextureFill#initialize(texture) @endverbatim
|
665
|
+
*
|
666
|
+
* Notes:
|
667
|
+
* - The texture is an Image or Image *object
|
668
|
+
*
|
669
|
+
* @param self this object
|
670
|
+
* @param texture_arg the texture
|
671
|
+
* @return self
|
672
|
+
*/
|
673
|
+
VALUE
|
674
|
+
TextureFill_initialize(VALUE self, VALUE texture_arg)
|
675
|
+
{
|
676
|
+
rm_TextureFill *fill;
|
677
|
+
Image *texture;
|
678
|
+
VALUE texture_image;
|
679
|
+
|
680
|
+
Data_Get_Struct(self, rm_TextureFill, fill);
|
681
|
+
|
682
|
+
texture_image = rm_cur_image(texture_arg);
|
683
|
+
|
684
|
+
// Bump the reference count on the texture image.
|
685
|
+
texture = rm_check_destroyed(texture_image);
|
686
|
+
(void) ReferenceImage(texture);
|
687
|
+
|
688
|
+
fill->texture = texture;
|
689
|
+
|
690
|
+
RB_GC_GUARD(texture_image);
|
691
|
+
|
692
|
+
return self;
|
693
|
+
}
|
694
|
+
|
695
|
+
/**
|
696
|
+
* Call TextureFill with the texture specified when this fill object was
|
697
|
+
* created.
|
698
|
+
*
|
699
|
+
* Ruby usage:
|
700
|
+
* - @verbatim TextureFill#fill(image) @endverbatim
|
701
|
+
*
|
702
|
+
* @param self this object
|
703
|
+
* @param image_obj the image
|
704
|
+
* @return self
|
705
|
+
*/
|
706
|
+
VALUE
|
707
|
+
TextureFill_fill(VALUE self, VALUE image_obj)
|
708
|
+
{
|
709
|
+
rm_TextureFill *fill;
|
710
|
+
Image *image;
|
711
|
+
|
712
|
+
image = rm_check_destroyed(image_obj);
|
713
|
+
Data_Get_Struct(self, rm_TextureFill, fill);
|
714
|
+
|
715
|
+
(void) TextureImage(image, fill->texture);
|
716
|
+
rm_check_image_exception(image, RetainOnError);
|
717
|
+
|
718
|
+
return self;
|
719
|
+
}
|
720
|
+
|