rmagick 2.16.0 → 5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.devcontainer/Dockerfile +14 -0
- data/.devcontainer/ImageMagick6/devcontainer.json +11 -0
- data/.devcontainer/devcontainer.json +11 -0
- data/.devcontainer/setup-repo.sh +10 -0
- data/.devcontainer/setup-user.sh +45 -0
- data/.editorconfig +3 -0
- data/.github/ISSUE_TEMPLATE.md +17 -0
- data/.github/workflows/ci.yml +157 -0
- data/.gitignore +9 -1
- data/.rspec +1 -0
- data/.rubocop.yml +37 -340
- data/.rubocop_todo.yml +456 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +536 -0
- data/CODE_OF_CONDUCT.md +122 -7
- data/CONTRIBUTING.md +37 -6
- data/Gemfile +18 -4
- data/README.md +319 -0
- data/Rakefile +83 -98
- data/before_install_linux.sh +65 -28
- data/before_install_osx.sh +58 -2
- data/ext/RMagick/extconf.rb +310 -393
- data/ext/RMagick/{rmagick.c → rmagick.cpp} +119 -127
- data/ext/RMagick/rmagick.h +290 -363
- data/ext/RMagick/rmagick_gvl.h +224 -0
- data/ext/RMagick/rmdraw.cpp +1696 -0
- data/ext/RMagick/rmenum.cpp +796 -0
- data/ext/RMagick/{rmfill.c → rmfill.cpp} +287 -197
- data/ext/RMagick/rmilist.cpp +1275 -0
- data/ext/RMagick/rmimage.cpp +16459 -0
- data/ext/RMagick/{rminfo.c → rminfo.cpp} +738 -910
- data/ext/RMagick/rmkinfo.cpp +210 -0
- data/ext/RMagick/rmmain.cpp +1923 -0
- data/ext/RMagick/rmmontage.cpp +474 -0
- data/ext/RMagick/rmpixel.cpp +1322 -0
- data/ext/RMagick/{rmstruct.c → rmstruct.cpp} +104 -284
- data/ext/RMagick/{rmutil.c → rmutil.cpp} +500 -433
- data/lib/rmagick/version.rb +5 -4
- data/lib/rmagick.rb +2 -0
- data/lib/rmagick_internal.rb +397 -459
- data/lib/rvg/clippath.rb +3 -4
- data/lib/rvg/container.rb +30 -22
- data/lib/rvg/deep_equal.rb +11 -11
- data/lib/rvg/describable.rb +2 -2
- data/lib/rvg/embellishable.rb +67 -68
- data/lib/rvg/misc.rb +139 -142
- data/lib/rvg/paint.rb +2 -1
- data/lib/rvg/pathdata.rb +7 -8
- data/lib/rvg/rvg.rb +49 -46
- data/lib/rvg/stretchable.rb +22 -28
- data/lib/rvg/stylable.rb +12 -10
- data/lib/rvg/text.rb +169 -165
- data/lib/rvg/transformable.rb +17 -16
- data/lib/rvg/units.rb +5 -5
- data/rmagick.gemspec +7 -41
- data/sig/rmagick/_draw_common_methods.rbs +64 -0
- data/sig/rmagick/_image_common_methods.rbs +389 -0
- data/sig/rmagick/draw.rbs +38 -0
- data/sig/rmagick/draw_attribute.rbs +28 -0
- data/sig/rmagick/enum.rbs +814 -0
- data/sig/rmagick/error.rbs +11 -0
- data/sig/rmagick/fill.rbs +21 -0
- data/sig/rmagick/geometry.rbs +14 -0
- data/sig/rmagick/image.rbs +194 -0
- data/sig/rmagick/image_list.rbs +181 -0
- data/sig/rmagick/iptc.rbs +101 -0
- data/sig/rmagick/kernel_info.rbs +12 -0
- data/sig/rmagick/optional_method_arguments.rbs +10 -0
- data/sig/rmagick/pixel.rbs +46 -0
- data/sig/rmagick/struct.rbs +90 -0
- data/sig/rmagick.rbs +43 -0
- data/sig/rvg/clippath.rbs +34 -0
- data/sig/rvg/container.rbs +78 -0
- data/sig/rvg/deep_equal.rbs +48 -0
- data/sig/rvg/describable.rbs +30 -0
- data/sig/rvg/embellishable.rbs +226 -0
- data/sig/rvg/misc.rbs +145 -0
- data/sig/rvg/paint.rbs +55 -0
- data/sig/rvg/pathdata.rbs +77 -0
- data/sig/rvg/rvg.rbs +125 -0
- data/sig/rvg/stretchable.rbs +56 -0
- data/sig/rvg/stylable.rbs +66 -0
- data/sig/rvg/text.rbs +118 -0
- data/sig/rvg/transformable.rbs +59 -0
- data/sig/rvg/units.rbs +33 -0
- metadata +68 -428
- data/.hound.yml +0 -2
- data/.simplecov +0 -27
- data/.travis.yml +0 -74
- data/Doxyfile +0 -1514
- data/README.textile +0 -251
- data/deprecated/RMagick.rb +0 -6
- data/doc/.cvsignore +0 -1
- data/doc/comtasks.html +0 -287
- data/doc/constants.html +0 -1581
- data/doc/css/doc.css +0 -299
- data/doc/css/popup.css +0 -34
- data/doc/css/ref.css +0 -67
- data/doc/draw.html +0 -3272
- data/doc/ex/InitialCoords.rb +0 -22
- data/doc/ex/NewCoordSys.rb +0 -30
- data/doc/ex/OrigCoordSys.rb +0 -16
- data/doc/ex/PreserveAspectRatio.rb +0 -204
- data/doc/ex/RotateScale.rb +0 -36
- data/doc/ex/Skew.rb +0 -38
- data/doc/ex/Use01.rb +0 -15
- data/doc/ex/Use02.rb +0 -20
- data/doc/ex/Use03.rb +0 -16
- data/doc/ex/ViewBox.rb +0 -31
- data/doc/ex/adaptive_threshold.rb +0 -9
- data/doc/ex/add_noise.rb +0 -16
- data/doc/ex/affine.rb +0 -48
- data/doc/ex/affine_transform.rb +0 -20
- data/doc/ex/arc.rb +0 -49
- data/doc/ex/arcpath.rb +0 -32
- data/doc/ex/arcs01.rb +0 -28
- data/doc/ex/arcs02.rb +0 -59
- data/doc/ex/average.rb +0 -15
- data/doc/ex/axes.rb +0 -64
- data/doc/ex/baseline_shift01.rb +0 -17
- data/doc/ex/bilevel_channel.rb +0 -8
- data/doc/ex/blur_image.rb +0 -12
- data/doc/ex/border.rb +0 -10
- data/doc/ex/bounding_box.rb +0 -42
- data/doc/ex/cbezier1.rb +0 -41
- data/doc/ex/cbezier2.rb +0 -41
- data/doc/ex/cbezier3.rb +0 -41
- data/doc/ex/cbezier4.rb +0 -42
- data/doc/ex/cbezier5.rb +0 -42
- data/doc/ex/cbezier6.rb +0 -53
- data/doc/ex/channel.rb +0 -25
- data/doc/ex/charcoal.rb +0 -12
- data/doc/ex/chop.rb +0 -29
- data/doc/ex/circle.rb +0 -33
- data/doc/ex/circle01.rb +0 -16
- data/doc/ex/clip_path.rb +0 -60
- data/doc/ex/coalesce.rb +0 -57
- data/doc/ex/color_fill_to_border.rb +0 -29
- data/doc/ex/color_floodfill.rb +0 -28
- data/doc/ex/color_histogram.rb +0 -47
- data/doc/ex/color_reset.rb +0 -11
- data/doc/ex/colorize.rb +0 -16
- data/doc/ex/colors.rb +0 -64
- data/doc/ex/compose_mask.rb +0 -22
- data/doc/ex/composite.rb +0 -133
- data/doc/ex/composite_layers.rb +0 -53
- data/doc/ex/composite_tiled.rb +0 -21
- data/doc/ex/contrast.rb +0 -36
- data/doc/ex/crop.rb +0 -31
- data/doc/ex/crop_with_gravity.rb +0 -42
- data/doc/ex/cubic01.rb +0 -43
- data/doc/ex/cubic02.rb +0 -91
- data/doc/ex/cycle_colormap.rb +0 -21
- data/doc/ex/dissolve.rb +0 -12
- data/doc/ex/drawcomp.rb +0 -42
- data/doc/ex/drop_shadow.rb +0 -60
- data/doc/ex/edge.rb +0 -11
- data/doc/ex/ellipse.rb +0 -45
- data/doc/ex/ellipse01.rb +0 -21
- data/doc/ex/emboss.rb +0 -11
- data/doc/ex/enhance.rb +0 -28
- data/doc/ex/equalize.rb +0 -11
- data/doc/ex/evenodd.rb +0 -42
- data/doc/ex/fill_pattern.rb +0 -23
- data/doc/ex/flatten_images.rb +0 -36
- data/doc/ex/flip.rb +0 -11
- data/doc/ex/flop.rb +0 -11
- data/doc/ex/font_styles.rb +0 -32
- data/doc/ex/fonts.rb +0 -20
- data/doc/ex/frame.rb +0 -12
- data/doc/ex/gaussian_blur.rb +0 -11
- data/doc/ex/get_multiline_type_metrics.rb +0 -41
- data/doc/ex/get_pixels.rb +0 -47
- data/doc/ex/get_type_metrics.rb +0 -141
- data/doc/ex/gradientfill.rb +0 -27
- data/doc/ex/grav.rb +0 -45
- data/doc/ex/gravity.rb +0 -80
- data/doc/ex/group.rb +0 -26
- data/doc/ex/hatchfill.rb +0 -27
- data/doc/ex/image.rb +0 -44
- 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 +0 -34
- data/doc/ex/level.rb +0 -11
- data/doc/ex/level_colors.rb +0 -11
- data/doc/ex/line.rb +0 -41
- data/doc/ex/line01.rb +0 -21
- data/doc/ex/mask.rb +0 -35
- data/doc/ex/matte_fill_to_border.rb +0 -39
- data/doc/ex/matte_floodfill.rb +0 -32
- data/doc/ex/matte_replace.rb +0 -39
- data/doc/ex/median_filter.rb +0 -28
- data/doc/ex/modulate.rb +0 -11
- data/doc/ex/mono.rb +0 -23
- data/doc/ex/morph.rb +0 -25
- data/doc/ex/mosaic.rb +0 -35
- data/doc/ex/motion_blur.rb +0 -11
- data/doc/ex/negate.rb +0 -11
- data/doc/ex/negate_channel.rb +0 -9
- data/doc/ex/nested_rvg.rb +0 -21
- data/doc/ex/nonzero.rb +0 -42
- data/doc/ex/normalize.rb +0 -11
- data/doc/ex/oil_paint.rb +0 -11
- data/doc/ex/opacity.rb +0 -37
- data/doc/ex/ordered_dither.rb +0 -11
- data/doc/ex/path.rb +0 -63
- data/doc/ex/pattern1.rb +0 -25
- data/doc/ex/pattern2.rb +0 -26
- data/doc/ex/polaroid.rb +0 -27
- data/doc/ex/polygon.rb +0 -23
- data/doc/ex/polygon01.rb +0 -21
- data/doc/ex/polyline.rb +0 -22
- data/doc/ex/polyline01.rb +0 -21
- data/doc/ex/posterize.rb +0 -8
- data/doc/ex/preview.rb +0 -8
- data/doc/ex/qbezierpath.rb +0 -52
- data/doc/ex/quad01.rb +0 -34
- data/doc/ex/quantize-m.rb +0 -25
- data/doc/ex/radial_blur.rb +0 -9
- data/doc/ex/raise.rb +0 -8
- data/doc/ex/random_threshold_channel.rb +0 -13
- data/doc/ex/rect01.rb +0 -14
- data/doc/ex/rect02.rb +0 -20
- data/doc/ex/rectangle.rb +0 -34
- data/doc/ex/reduce_noise.rb +0 -28
- data/doc/ex/remap.rb +0 -11
- data/doc/ex/remap_images.rb +0 -19
- data/doc/ex/resize_to_fill.rb +0 -8
- data/doc/ex/resize_to_fit.rb +0 -8
- data/doc/ex/roll.rb +0 -9
- data/doc/ex/rotate.rb +0 -44
- data/doc/ex/rotate_f.rb +0 -14
- data/doc/ex/roundrect.rb +0 -33
- data/doc/ex/rubyname.rb +0 -30
- data/doc/ex/rvg_clippath.rb +0 -12
- data/doc/ex/rvg_linecap.rb +0 -42
- data/doc/ex/rvg_linejoin.rb +0 -40
- data/doc/ex/rvg_opacity.rb +0 -18
- data/doc/ex/rvg_pattern.rb +0 -26
- data/doc/ex/rvg_stroke_dasharray.rb +0 -11
- data/doc/ex/segment.rb +0 -11
- data/doc/ex/sepiatone.rb +0 -7
- data/doc/ex/shade.rb +0 -11
- data/doc/ex/shadow.rb +0 -30
- data/doc/ex/shave.rb +0 -15
- data/doc/ex/shear.rb +0 -10
- data/doc/ex/sketch.rb +0 -17
- data/doc/ex/skewx.rb +0 -51
- data/doc/ex/skewy.rb +0 -47
- data/doc/ex/smile.rb +0 -125
- data/doc/ex/solarize.rb +0 -11
- data/doc/ex/sparse_color.rb +0 -54
- data/doc/ex/splice.rb +0 -8
- data/doc/ex/spread.rb +0 -11
- data/doc/ex/stegano.rb +0 -55
- data/doc/ex/stroke_dasharray.rb +0 -42
- data/doc/ex/stroke_fill.rb +0 -10
- data/doc/ex/stroke_linecap.rb +0 -44
- data/doc/ex/stroke_linejoin.rb +0 -48
- data/doc/ex/stroke_width.rb +0 -49
- data/doc/ex/swirl.rb +0 -17
- data/doc/ex/text.rb +0 -37
- data/doc/ex/text01.rb +0 -16
- data/doc/ex/text_align.rb +0 -36
- data/doc/ex/text_antialias.rb +0 -37
- data/doc/ex/text_styles.rb +0 -19
- data/doc/ex/text_undercolor.rb +0 -28
- data/doc/ex/texture_fill_to_border.rb +0 -34
- data/doc/ex/texture_floodfill.rb +0 -32
- data/doc/ex/texturefill.rb +0 -24
- data/doc/ex/threshold.rb +0 -13
- data/doc/ex/to_blob.rb +0 -13
- data/doc/ex/translate.rb +0 -39
- data/doc/ex/transparent.rb +0 -38
- data/doc/ex/transpose.rb +0 -9
- data/doc/ex/transverse.rb +0 -9
- data/doc/ex/tref01.rb +0 -24
- data/doc/ex/triangle01.rb +0 -15
- data/doc/ex/trim.rb +0 -23
- data/doc/ex/tspan01.rb +0 -17
- data/doc/ex/tspan02.rb +0 -17
- data/doc/ex/tspan03.rb +0 -19
- data/doc/ex/unsharp_mask.rb +0 -28
- data/doc/ex/viewex.rb +0 -33
- data/doc/ex/vignette.rb +0 -12
- data/doc/ex/watermark.rb +0 -27
- data/doc/ex/wave.rb +0 -9
- data/doc/ex/wet_floor.rb +0 -58
- data/doc/ex/writing_mode01.rb +0 -26
- data/doc/ex/writing_mode02.rb +0 -26
- data/doc/ilist.html +0 -2056
- data/doc/image1.html +0 -4680
- data/doc/image2.html +0 -3665
- data/doc/image3.html +0 -4522
- data/doc/imageattrs.html +0 -1638
- data/doc/imusage.html +0 -514
- data/doc/index.html +0 -416
- data/doc/info.html +0 -1499
- data/doc/magick.html +0 -565
- data/doc/optequiv.html +0 -2435
- data/doc/rvg.html +0 -975
- data/doc/rvgclip.html +0 -248
- data/doc/rvggroup.html +0 -305
- data/doc/rvgimage.html +0 -289
- data/doc/rvgpattern.html +0 -475
- data/doc/rvgshape.html +0 -406
- data/doc/rvgstyle.html +0 -270
- data/doc/rvgtext.html +0 -465
- data/doc/rvgtspan.html +0 -238
- data/doc/rvgtut.html +0 -530
- data/doc/rvguse.html +0 -145
- data/doc/rvgxform.html +0 -294
- data/doc/scripts/doc.js +0 -22
- data/doc/scripts/stripeTables.js +0 -23
- data/doc/struct.html +0 -1339
- data/doc/usage.html +0 -1621
- data/examples/constitute.rb +0 -7
- data/examples/crop_with_gravity.rb +0 -42
- data/examples/demo.rb +0 -324
- data/examples/describe.rb +0 -43
- data/examples/find_similar_region.rb +0 -34
- data/examples/histogram.rb +0 -321
- data/examples/identify.rb +0 -185
- data/examples/image_opacity.rb +0 -29
- data/examples/import_export.rb +0 -31
- data/examples/pattern_fill.rb +0 -38
- data/examples/rotating_text.rb +0 -44
- data/examples/spinner.rb +0 -49
- data/examples/thumbnail.rb +0 -64
- data/examples/vignette.rb +0 -78
- data/ext/RMagick/rmdraw.c +0 -2022
- data/ext/RMagick/rmenum.c +0 -1235
- data/ext/RMagick/rmilist.c +0 -1270
- data/ext/RMagick/rmimage.c +0 -15427
- data/ext/RMagick/rmmain.c +0 -1741
- data/ext/RMagick/rmmontage.c +0 -519
- data/ext/RMagick/rmpixel.c +0 -1114
- data/spec/rmagick/ImageList1_spec.rb +0 -24
- data/spec/rmagick/draw_spec.rb +0 -156
- data/spec/rmagick/image/blue_shift_spec.rb +0 -16
- data/spec/rmagick/image/composite_spec.rb +0 -140
- data/spec/rmagick/image/constitute_spec.rb +0 -15
- data/spec/rmagick/image/dispatch_spec.rb +0 -18
- data/spec/rmagick/image/from_blob_spec.rb +0 -14
- data/spec/rmagick/image/ping_spec.rb +0 -14
- data/spec/rmagick/image/properties_spec.rb +0 -29
- data/spec/spec_helper.rb +0 -4
- data/test/Image1.rb +0 -565
- data/test/Image2.rb +0 -1304
- data/test/Image3.rb +0 -1030
- data/test/ImageList1.rb +0 -806
- data/test/ImageList2.rb +0 -385
- data/test/Image_attributes.rb +0 -697
- data/test/Import_Export.rb +0 -121
- data/test/Info.rb +0 -345
- data/test/Magick.rb +0 -321
- data/test/Pixel.rb +0 -116
- data/test/Preview.rb +0 -57
- data/test/cmyk.icm +0 -0
- data/test/srgb.icm +0 -0
- data/test/test_all_basic.rb +0 -38
- data/test/tmpnam_test.rb +0 -50
- data/wercker.yml +0 -10
data/lib/rmagick_internal.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# $Id: RMagick.rb,v 1.84 2009/09/15 22:08:41 rmagick Exp $
|
2
4
|
#==============================================================================
|
3
5
|
# Copyright (C) 2009 by Timothy P. Hunter
|
@@ -8,36 +10,55 @@
|
|
8
10
|
# to the classes.
|
9
11
|
#==============================================================================
|
10
12
|
|
13
|
+
if RUBY_PLATFORM =~ /mingw/i
|
14
|
+
begin
|
15
|
+
require 'ruby_installer'
|
16
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).grep(/ImageMagick/i).each do |path|
|
17
|
+
RubyInstaller::Runtime.add_dll_directory(path) if File.exist?(File.join(path, 'CORE_RL_magick_.dll')) || File.exist?(File.join(path, 'CORE_RL_MagickCore_.dll'))
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
require 'English'
|
24
|
+
require 'observer'
|
12
25
|
require 'RMagick2.so'
|
13
26
|
|
14
27
|
module Magick
|
15
|
-
|
16
|
-
@trace_proc = nil
|
17
|
-
@exit_block_set_up = nil
|
28
|
+
IMAGEMAGICK_VERSION = Magick::Magick_version.split[1].split('-').first
|
18
29
|
|
19
30
|
class << self
|
20
|
-
|
21
|
-
|
31
|
+
# Describes the image formats supported by ImageMagick.
|
32
|
+
# If the optional block is present, calls the block once for each image format.
|
33
|
+
# The first argument, +k+, is the format name. The second argument, +v+, is the
|
34
|
+
# properties string described below.
|
35
|
+
#
|
36
|
+
# - +B+ is "*" if the format has native blob support, or " " otherwise.
|
37
|
+
# - +R+ is "r" if ImageMagick can read that format, or "-" otherwise.
|
38
|
+
# - +W+ is "w" if ImageMagick can write that format, or "-" otherwise.
|
39
|
+
# - +A+ is "+" if the format supports multi-image files, or "-" otherwise.
|
40
|
+
#
|
41
|
+
# @overload formats
|
42
|
+
# @return [Hash] the formats hash
|
43
|
+
#
|
44
|
+
# @overload formats
|
45
|
+
# @yield [k, v]
|
46
|
+
# @yieldparam k [String] the format name
|
47
|
+
# @yieldparam v [String] the properties string
|
48
|
+
# @return [Magick]
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# p Magick.formats
|
52
|
+
# => {"3FR"=>" r-+", "3G2"=>" r-+", "3GP"=>" r-+", "A"=>"*rw+",
|
53
|
+
# ...
|
54
|
+
def formats
|
55
|
+
formats = init_formats
|
22
56
|
|
23
57
|
if block_given?
|
24
|
-
|
58
|
+
formats.each { |k, v| yield k, v }
|
25
59
|
self
|
26
60
|
else
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# remove reference to the proc at exit
|
32
|
-
def trace_proc=(p)
|
33
|
-
m = Mutex.new
|
34
|
-
m.synchronize do
|
35
|
-
if @trace_proc.nil? && !p.nil? && !@exit_block_set_up
|
36
|
-
at_exit { @trace_proc = nil }
|
37
|
-
@exit_block_set_up = true
|
38
|
-
end
|
39
|
-
|
40
|
-
@trace_proc = p
|
61
|
+
formats
|
41
62
|
end
|
42
63
|
end
|
43
64
|
end
|
@@ -55,21 +76,23 @@ module Magick
|
|
55
76
|
MinimumGeometry = GeometryValue.new(:MinimumGeometry, 6).freeze
|
56
77
|
|
57
78
|
class Geometry
|
58
|
-
FLAGS = ['', '%', '!', '<', '>', '@', '^']
|
59
|
-
RFLAGS = {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
79
|
+
FLAGS = ['', '%', '!', '<', '>', '@', '^'].freeze
|
80
|
+
RFLAGS = {
|
81
|
+
'%' => PercentGeometry,
|
82
|
+
'!' => AspectGeometry,
|
83
|
+
'<' => LessGeometry,
|
84
|
+
'>' => GreaterGeometry,
|
85
|
+
'@' => AreaGeometry,
|
86
|
+
'^' => MinimumGeometry
|
87
|
+
}.freeze
|
65
88
|
|
66
89
|
attr_accessor :width, :height, :x, :y, :flag
|
67
90
|
|
68
|
-
def initialize(width=nil, height=nil, x=nil, y=nil, flag=nil)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
91
|
+
def initialize(width = nil, height = nil, x = nil, y = nil, flag = nil)
|
92
|
+
raise(ArgumentError, "width set to #{width}") if width.is_a? GeometryValue
|
93
|
+
raise(ArgumentError, "height set to #{height}") if height.is_a? GeometryValue
|
94
|
+
raise(ArgumentError, "x set to #{x}") if x.is_a? GeometryValue
|
95
|
+
raise(ArgumentError, "y set to #{y}") if y.is_a? GeometryValue
|
73
96
|
|
74
97
|
# Support floating-point width and height arguments so Geometry
|
75
98
|
# objects can be used to specify Image#density= arguments.
|
@@ -111,24 +134,20 @@ module Magick
|
|
111
134
|
else
|
112
135
|
Kernel.raise ArgumentError, 'invalid geometry format'
|
113
136
|
end
|
114
|
-
if str['%']
|
115
|
-
flag = PercentGeometry
|
116
|
-
end
|
137
|
+
flag = PercentGeometry if str['%']
|
117
138
|
Geometry.new(width, height, x, y, flag)
|
118
139
|
end
|
119
140
|
|
120
141
|
# Convert object to a geometry string
|
121
142
|
def to_s
|
122
|
-
str =
|
143
|
+
str = String.new
|
123
144
|
if @width > 0
|
124
145
|
fmt = @width.truncate == @width ? '%d' : '%.2f'
|
125
146
|
str << sprintf(fmt, @width)
|
126
147
|
str << '%' if @flag == PercentGeometry
|
127
148
|
end
|
128
149
|
|
129
|
-
if (@width > 0 && @flag != PercentGeometry) || (@height > 0)
|
130
|
-
str << 'x'
|
131
|
-
end
|
150
|
+
str << 'x' if (@width > 0 && @flag != PercentGeometry) || (@height > 0)
|
132
151
|
|
133
152
|
if @height > 0
|
134
153
|
fmt = @height.truncate == @height ? '%d' : '%.2f'
|
@@ -136,9 +155,7 @@ module Magick
|
|
136
155
|
str << '%' if @flag == PercentGeometry
|
137
156
|
end
|
138
157
|
str << sprintf('%+d%+d', @x, @y) if @x != 0 || @y != 0
|
139
|
-
if @flag != PercentGeometry
|
140
|
-
str << FLAGS[@flag.to_i]
|
141
|
-
end
|
158
|
+
str << FLAGS[@flag.to_i] if @flag != PercentGeometry
|
142
159
|
str
|
143
160
|
end
|
144
161
|
end
|
@@ -167,7 +184,7 @@ module Magick
|
|
167
184
|
NormalWeight.to_i => 'normal',
|
168
185
|
BoldWeight.to_i => 'bold',
|
169
186
|
BolderWeight.to_i => 'bolder',
|
170
|
-
LighterWeight.to_i => 'lighter'
|
187
|
+
LighterWeight.to_i => 'lighter'
|
171
188
|
}.freeze
|
172
189
|
GRAVITY_NAMES = {
|
173
190
|
NorthWestGravity.to_i => 'northwest',
|
@@ -209,13 +226,31 @@ module Magick
|
|
209
226
|
private
|
210
227
|
|
211
228
|
def enquote(str)
|
229
|
+
str = to_string(str)
|
212
230
|
if str.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(str)
|
213
|
-
|
231
|
+
str
|
214
232
|
else
|
215
|
-
|
233
|
+
'"' + str + '"'
|
216
234
|
end
|
217
235
|
end
|
218
236
|
|
237
|
+
def to_opacity(opacity)
|
238
|
+
return opacity if opacity.is_a?(String) && opacity.end_with?('%')
|
239
|
+
|
240
|
+
value = Float(opacity)
|
241
|
+
Kernel.raise ArgumentError, 'opacity must be >= 0 and <= 1.0' if value < 0 || value > 1.0
|
242
|
+
|
243
|
+
value
|
244
|
+
end
|
245
|
+
|
246
|
+
def to_string(obj)
|
247
|
+
return obj if obj.is_a?(String)
|
248
|
+
return obj.to_s if obj.is_a?(Symbol)
|
249
|
+
return obj.to_str if obj.respond_to?(:to_str)
|
250
|
+
|
251
|
+
Kernel.raise TypeError, "no implicit conversion of #{obj.class} into String"
|
252
|
+
end
|
253
|
+
|
219
254
|
public
|
220
255
|
|
221
256
|
# Apply coordinate transformations to support scaling (s), rotation (r),
|
@@ -224,61 +259,67 @@ module Magick
|
|
224
259
|
primitive 'affine ' + sprintf('%g,%g,%g,%g,%g,%g', sx, rx, ry, sy, tx, ty)
|
225
260
|
end
|
226
261
|
|
262
|
+
# Set alpha (make transparent) in image according to the specified
|
263
|
+
# colorization rule
|
264
|
+
def alpha(x, y, method)
|
265
|
+
Kernel.raise ArgumentError, 'Unknown paint method' unless PAINT_METHOD_NAMES.key?(method.to_i)
|
266
|
+
name = Gem::Version.new(Magick::IMAGEMAGICK_VERSION) > Gem::Version.new('7.0.0') ? 'alpha ' : 'matte '
|
267
|
+
primitive name + sprintf('%g,%g, %s', x, y, PAINT_METHOD_NAMES[method.to_i])
|
268
|
+
end
|
269
|
+
|
227
270
|
# Draw an arc.
|
228
|
-
def arc(
|
229
|
-
primitive 'arc ' + sprintf(
|
230
|
-
|
271
|
+
def arc(start_x, start_y, end_x, end_y, start_degrees, end_degrees)
|
272
|
+
primitive 'arc ' + sprintf(
|
273
|
+
'%g,%g %g,%g %g,%g',
|
274
|
+
start_x, start_y, end_x, end_y, start_degrees, end_degrees
|
275
|
+
)
|
231
276
|
end
|
232
277
|
|
233
278
|
# Draw a bezier curve.
|
234
279
|
def bezier(*points)
|
235
|
-
if points.length
|
280
|
+
if points.length.zero?
|
236
281
|
Kernel.raise ArgumentError, 'no points specified'
|
237
282
|
elsif points.length.odd?
|
238
283
|
Kernel.raise ArgumentError, 'odd number of arguments specified'
|
239
284
|
end
|
240
|
-
primitive 'bezier ' + points.join(',')
|
285
|
+
primitive 'bezier ' + points.map! { |x| sprintf('%g', x) }.join(',')
|
241
286
|
end
|
242
287
|
|
243
288
|
# Draw a circle
|
244
|
-
def circle(
|
245
|
-
primitive 'circle ' + sprintf('%g,%g %g,%g',
|
289
|
+
def circle(origin_x, origin_y, perim_x, perim_y)
|
290
|
+
primitive 'circle ' + sprintf('%g,%g %g,%g', origin_x, origin_y, perim_x, perim_y)
|
246
291
|
end
|
247
292
|
|
248
293
|
# Invoke a clip-path defined by def_clip_path.
|
249
294
|
def clip_path(name)
|
250
|
-
primitive "clip-path #{name}"
|
295
|
+
primitive "clip-path #{to_string(name)}"
|
251
296
|
end
|
252
297
|
|
253
298
|
# Define the clipping rule.
|
254
299
|
def clip_rule(rule)
|
255
|
-
|
256
|
-
|
257
|
-
end
|
300
|
+
rule = to_string(rule)
|
301
|
+
Kernel.raise ArgumentError, "Unknown clipping rule #{rule}" unless %w[evenodd nonzero].include?(rule.downcase)
|
258
302
|
primitive "clip-rule #{rule}"
|
259
303
|
end
|
260
304
|
|
261
305
|
# Define the clip units
|
262
306
|
def clip_units(unit)
|
263
|
-
|
264
|
-
|
265
|
-
end
|
307
|
+
unit = to_string(unit)
|
308
|
+
Kernel.raise ArgumentError, "Unknown clip unit #{unit}" unless %w[userspace userspaceonuse objectboundingbox].include?(unit.downcase)
|
266
309
|
primitive "clip-units #{unit}"
|
267
310
|
end
|
268
311
|
|
269
312
|
# Set color in image according to specified colorization rule. Rule is one of
|
270
313
|
# point, replace, floodfill, filltoborder,reset
|
271
314
|
def color(x, y, method)
|
272
|
-
unless
|
273
|
-
|
274
|
-
end
|
275
|
-
primitive "color #{x},#{y},#{PAINT_METHOD_NAMES[method.to_i]}"
|
315
|
+
Kernel.raise ArgumentError, "Unknown PaintMethod: #{method}" unless PAINT_METHOD_NAMES.key?(method.to_i)
|
316
|
+
primitive 'color ' + sprintf('%g,%g,%s', x, y, PAINT_METHOD_NAMES[method.to_i])
|
276
317
|
end
|
277
318
|
|
278
319
|
# Specify EITHER the text decoration (none, underline, overline,
|
279
320
|
# line-through) OR the text solid background color (any color name or spec)
|
280
321
|
def decorate(decoration)
|
281
|
-
if
|
322
|
+
if DECORATION_TYPE_NAMES.key?(decoration.to_i)
|
282
323
|
primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}"
|
283
324
|
else
|
284
325
|
primitive "decorate #{enquote(decoration)}"
|
@@ -292,7 +333,7 @@ module Magick
|
|
292
333
|
# (pop) graphic-context".
|
293
334
|
def define_clip_path(name)
|
294
335
|
push('defs')
|
295
|
-
push(
|
336
|
+
push("clip-path #{enquote(name)}")
|
296
337
|
push('graphic-context')
|
297
338
|
yield
|
298
339
|
ensure
|
@@ -302,136 +343,104 @@ module Magick
|
|
302
343
|
end
|
303
344
|
|
304
345
|
# Draw an ellipse
|
305
|
-
def ellipse(
|
306
|
-
primitive 'ellipse ' + sprintf(
|
307
|
-
|
346
|
+
def ellipse(origin_x, origin_y, width, height, arc_start, arc_end)
|
347
|
+
primitive 'ellipse ' + sprintf(
|
348
|
+
'%g,%g %g,%g %g,%g',
|
349
|
+
origin_x, origin_y, width, height, arc_start, arc_end
|
350
|
+
)
|
308
351
|
end
|
309
352
|
|
310
353
|
# Let anything through, but the only defined argument
|
311
354
|
# is "UTF-8". All others are apparently ignored.
|
312
355
|
def encoding(encoding)
|
313
|
-
primitive "encoding #{encoding}"
|
356
|
+
primitive "encoding #{to_string(encoding)}"
|
314
357
|
end
|
315
358
|
|
316
359
|
# Specify object fill, a color name or pattern name
|
317
360
|
def fill(colorspec)
|
318
361
|
primitive "fill #{enquote(colorspec)}"
|
319
362
|
end
|
320
|
-
|
321
|
-
|
363
|
+
alias fill_color fill
|
364
|
+
alias fill_pattern fill
|
322
365
|
|
323
366
|
# Specify fill opacity (use "xx%" to indicate percentage)
|
324
367
|
def fill_opacity(opacity)
|
368
|
+
opacity = to_opacity(opacity)
|
325
369
|
primitive "fill-opacity #{opacity}"
|
326
370
|
end
|
327
371
|
|
328
372
|
def fill_rule(rule)
|
329
|
-
|
330
|
-
|
331
|
-
end
|
373
|
+
rule = to_string(rule)
|
374
|
+
Kernel.raise ArgumentError, "Unknown fill rule #{rule}" unless %w[evenodd nonzero].include?(rule.downcase)
|
332
375
|
primitive "fill-rule #{rule}"
|
333
376
|
end
|
334
377
|
|
335
378
|
# Specify text drawing font
|
336
379
|
def font(name)
|
337
|
-
primitive "font
|
380
|
+
primitive "font #{enquote(name)}"
|
338
381
|
end
|
339
382
|
|
340
383
|
def font_family(name)
|
341
|
-
primitive "font-family
|
384
|
+
primitive "font-family #{enquote(name)}"
|
342
385
|
end
|
343
386
|
|
344
387
|
def font_stretch(stretch)
|
345
|
-
unless
|
346
|
-
Kernel.raise ArgumentError, 'Unknown stretch type'
|
347
|
-
end
|
388
|
+
Kernel.raise ArgumentError, 'Unknown stretch type' unless STRETCH_TYPE_NAMES.key?(stretch.to_i)
|
348
389
|
primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}"
|
349
390
|
end
|
350
391
|
|
351
392
|
def font_style(style)
|
352
|
-
unless
|
353
|
-
Kernel.raise ArgumentError, 'Unknown style type'
|
354
|
-
end
|
393
|
+
Kernel.raise ArgumentError, 'Unknown style type' unless STYLE_TYPE_NAMES.key?(style.to_i)
|
355
394
|
primitive "font-style #{STYLE_TYPE_NAMES[style.to_i]}"
|
356
395
|
end
|
357
396
|
|
358
397
|
# The font weight argument can be either a font weight
|
359
398
|
# constant or [100,200,...,900]
|
360
399
|
def font_weight(weight)
|
361
|
-
if
|
400
|
+
if weight.is_a?(WeightType)
|
362
401
|
primitive "font-weight #{FONT_WEIGHT_NAMES[weight.to_i]}"
|
363
402
|
else
|
364
|
-
primitive "font-weight #{weight}"
|
403
|
+
primitive "font-weight #{Integer(weight)}"
|
365
404
|
end
|
366
405
|
end
|
367
406
|
|
368
407
|
# Specify the text positioning gravity, one of:
|
369
408
|
# NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
|
370
409
|
def gravity(grav)
|
371
|
-
unless
|
372
|
-
Kernel.raise ArgumentError, 'Unknown text positioning gravity'
|
373
|
-
end
|
410
|
+
Kernel.raise ArgumentError, 'Unknown text positioning gravity' unless GRAVITY_NAMES.key?(grav.to_i)
|
374
411
|
primitive "gravity #{GRAVITY_NAMES[grav.to_i]}"
|
375
412
|
end
|
376
413
|
|
414
|
+
def image(composite, x, y, width, height, image_file_path)
|
415
|
+
Kernel.raise ArgumentError, 'Unknown composite' unless composite.is_a?(CompositeOperator)
|
416
|
+
composite_name = composite.to_s.sub!('CompositeOp', '')
|
417
|
+
primitive 'image ' + sprintf('%s %g,%g %g,%g %s', composite_name, x, y, width, height, enquote(image_file_path))
|
418
|
+
end
|
419
|
+
|
377
420
|
# IM 6.5.5-8 and later
|
378
421
|
def interline_spacing(space)
|
379
|
-
|
380
|
-
Float(space)
|
381
|
-
rescue ArgumentError
|
382
|
-
Kernel.raise ArgumentError, 'invalid value for interline_spacing'
|
383
|
-
rescue TypeError
|
384
|
-
Kernel.raise TypeError, "can't convert #{space.class} into Float"
|
385
|
-
end
|
386
|
-
primitive "interline-spacing #{space}"
|
422
|
+
primitive "interline-spacing #{Float(space)}"
|
387
423
|
end
|
388
424
|
|
389
425
|
# IM 6.4.8-3 and later
|
390
426
|
def interword_spacing(space)
|
391
|
-
|
392
|
-
Float(space)
|
393
|
-
rescue ArgumentError
|
394
|
-
Kernel.raise ArgumentError, 'invalid value for interword_spacing'
|
395
|
-
rescue TypeError
|
396
|
-
Kernel.raise TypeError, "can't convert #{space.class} into Float"
|
397
|
-
end
|
398
|
-
primitive "interword-spacing #{space}"
|
427
|
+
primitive "interword-spacing #{Float(space)}"
|
399
428
|
end
|
400
429
|
|
401
430
|
# IM 6.4.8-3 and later
|
402
431
|
def kerning(space)
|
403
|
-
|
404
|
-
Float(space)
|
405
|
-
rescue ArgumentError
|
406
|
-
Kernel.raise ArgumentError, 'invalid value for kerning'
|
407
|
-
rescue TypeError
|
408
|
-
Kernel.raise TypeError, "can't convert #{space.class} into Float"
|
409
|
-
end
|
410
|
-
primitive "kerning #{space}"
|
432
|
+
primitive "kerning #{Float(space)}"
|
411
433
|
end
|
412
434
|
|
413
435
|
# Draw a line
|
414
|
-
def line(
|
415
|
-
primitive 'line ' + sprintf('%g,%g %g,%g',
|
416
|
-
end
|
417
|
-
|
418
|
-
# Set matte (make transparent) in image according to the specified
|
419
|
-
# colorization rule
|
420
|
-
def matte(x, y, method)
|
421
|
-
unless PAINT_METHOD_NAMES.has_key?(method.to_i)
|
422
|
-
Kernel.raise ArgumentError, 'Unknown paint method'
|
423
|
-
end
|
424
|
-
primitive "matte #{x},#{y} #{PAINT_METHOD_NAMES[method.to_i]}"
|
436
|
+
def line(start_x, start_y, end_x, end_y)
|
437
|
+
primitive 'line ' + sprintf('%g,%g %g,%g', start_x, start_y, end_x, end_y)
|
425
438
|
end
|
426
439
|
|
427
440
|
# Specify drawing fill and stroke opacities. If the value is a string
|
428
441
|
# ending with a %, the number will be multiplied by 0.01.
|
429
442
|
def opacity(opacity)
|
430
|
-
|
431
|
-
if opacity < 0 || opacity > 1.0
|
432
|
-
Kernel.raise ArgumentError, 'opacity must be >= 0 and <= 1.0'
|
433
|
-
end
|
434
|
-
end
|
443
|
+
opacity = to_opacity(opacity)
|
435
444
|
primitive "opacity #{opacity}"
|
436
445
|
end
|
437
446
|
|
@@ -439,7 +448,7 @@ module Magick
|
|
439
448
|
# primitive requires that the commands be surrounded by quotes or
|
440
449
|
# apostrophes. Here we simply use apostrophes.
|
441
450
|
def path(cmds)
|
442
|
-
primitive "path
|
451
|
+
primitive "path #{enquote(cmds)}"
|
443
452
|
end
|
444
453
|
|
445
454
|
# Define a pattern. In the block, call primitive methods to
|
@@ -447,7 +456,7 @@ module Magick
|
|
447
456
|
# as the argument to the 'fill' or 'stroke' methods
|
448
457
|
def pattern(name, x, y, width, height)
|
449
458
|
push('defs')
|
450
|
-
push("pattern #{name}
|
459
|
+
push("pattern #{to_string(name)} " + sprintf('%g %g %g %g', x, y, width, height))
|
451
460
|
push('graphic-context')
|
452
461
|
yield
|
453
462
|
ensure
|
@@ -458,34 +467,34 @@ module Magick
|
|
458
467
|
|
459
468
|
# Set point to fill color.
|
460
469
|
def point(x, y)
|
461
|
-
primitive
|
470
|
+
primitive 'point ' + sprintf('%g,%g', x, y)
|
462
471
|
end
|
463
472
|
|
464
473
|
# Specify the font size in points. Yes, the primitive is "font-size" but
|
465
474
|
# in other places this value is called the "pointsize". Give it both names.
|
466
475
|
def pointsize(points)
|
467
|
-
primitive
|
476
|
+
primitive 'font-size ' + sprintf('%g', points)
|
468
477
|
end
|
469
|
-
|
478
|
+
alias font_size pointsize
|
470
479
|
|
471
480
|
# Draw a polygon
|
472
481
|
def polygon(*points)
|
473
|
-
if points.length
|
482
|
+
if points.length.zero?
|
474
483
|
Kernel.raise ArgumentError, 'no points specified'
|
475
484
|
elsif points.length.odd?
|
476
485
|
Kernel.raise ArgumentError, 'odd number of points specified'
|
477
486
|
end
|
478
|
-
primitive 'polygon ' + points.join(',')
|
487
|
+
primitive 'polygon ' + points.map! { |x| sprintf('%g', x) }.join(',')
|
479
488
|
end
|
480
489
|
|
481
490
|
# Draw a polyline
|
482
491
|
def polyline(*points)
|
483
|
-
if points.length
|
492
|
+
if points.length.zero?
|
484
493
|
Kernel.raise ArgumentError, 'no points specified'
|
485
494
|
elsif points.length.odd?
|
486
495
|
Kernel.raise ArgumentError, 'odd number of points specified'
|
487
496
|
end
|
488
|
-
primitive 'polyline ' + points.join(',')
|
497
|
+
primitive 'polyline ' + points.map! { |x| sprintf('%g', x) }.join(',')
|
489
498
|
end
|
490
499
|
|
491
500
|
# Return to the previously-saved set of whatever
|
@@ -495,11 +504,10 @@ module Magick
|
|
495
504
|
# pop('pattern')
|
496
505
|
|
497
506
|
def pop(*what)
|
498
|
-
if what.length
|
507
|
+
if what.length.zero?
|
499
508
|
primitive 'pop graphic-context'
|
500
509
|
else
|
501
|
-
|
502
|
-
primitive 'pop ' + what.map {|w| w.to_s}.join(' ')
|
510
|
+
primitive 'pop ' + what.map { |x| to_string(x) }.join(' ')
|
503
511
|
end
|
504
512
|
end
|
505
513
|
|
@@ -509,50 +517,53 @@ module Magick
|
|
509
517
|
# push('gradient')
|
510
518
|
# push('pattern')
|
511
519
|
def push(*what)
|
512
|
-
if what.length
|
520
|
+
if what.length.zero?
|
513
521
|
primitive 'push graphic-context'
|
514
522
|
else
|
515
|
-
|
516
|
-
primitive 'push ' + what.map {|w| w.to_s}.join(' ')
|
523
|
+
primitive 'push ' + what.map { |x| to_string(x) }.join(' ')
|
517
524
|
end
|
518
525
|
end
|
519
526
|
|
520
527
|
# Draw a rectangle
|
521
528
|
def rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y)
|
522
|
-
primitive 'rectangle ' + sprintf(
|
523
|
-
|
529
|
+
primitive 'rectangle ' + sprintf(
|
530
|
+
'%g,%g %g,%g',
|
531
|
+
upper_left_x, upper_left_y, lower_right_x, lower_right_y
|
532
|
+
)
|
524
533
|
end
|
525
534
|
|
526
535
|
# Specify coordinate space rotation. "angle" is measured in degrees
|
527
536
|
def rotate(angle)
|
528
|
-
primitive
|
537
|
+
primitive 'rotate ' + sprintf('%g', angle)
|
529
538
|
end
|
530
539
|
|
531
540
|
# Draw a rectangle with rounded corners
|
532
541
|
def roundrectangle(center_x, center_y, width, height, corner_width, corner_height)
|
533
|
-
primitive 'roundrectangle ' + sprintf(
|
534
|
-
|
542
|
+
primitive 'roundrectangle ' + sprintf(
|
543
|
+
'%g,%g,%g,%g,%g,%g',
|
544
|
+
center_x, center_y, width, height, corner_width, corner_height
|
545
|
+
)
|
535
546
|
end
|
536
547
|
|
537
548
|
# Specify scaling to be applied to coordinate space on subsequent drawing commands.
|
538
549
|
def scale(x, y)
|
539
|
-
primitive
|
550
|
+
primitive 'scale ' + sprintf('%g,%g', x, y)
|
540
551
|
end
|
541
552
|
|
542
553
|
def skewx(angle)
|
543
|
-
primitive
|
554
|
+
primitive 'skewX ' + sprintf('%g', angle)
|
544
555
|
end
|
545
556
|
|
546
557
|
def skewy(angle)
|
547
|
-
primitive
|
558
|
+
primitive 'skewY ' + sprintf('%g', angle)
|
548
559
|
end
|
549
560
|
|
550
561
|
# Specify the object stroke, a color name or pattern name.
|
551
562
|
def stroke(colorspec)
|
552
563
|
primitive "stroke #{enquote(colorspec)}"
|
553
564
|
end
|
554
|
-
|
555
|
-
|
565
|
+
alias stroke_color stroke
|
566
|
+
alias stroke_pattern stroke
|
556
567
|
|
557
568
|
# Specify if stroke should be antialiased or not
|
558
569
|
def stroke_antialias(bool)
|
@@ -562,88 +573,79 @@ module Magick
|
|
562
573
|
|
563
574
|
# Specify a stroke dash pattern
|
564
575
|
def stroke_dasharray(*list)
|
565
|
-
if list.length
|
576
|
+
if list.length.zero?
|
566
577
|
primitive 'stroke-dasharray none'
|
567
578
|
else
|
568
|
-
list.each do |x|
|
569
|
-
if x <= 0
|
570
|
-
Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)"
|
571
|
-
end
|
579
|
+
list.map! { |x| Float(x) }.each do |x|
|
580
|
+
Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)" if x <= 0
|
572
581
|
end
|
573
582
|
primitive "stroke-dasharray #{list.join(',')}"
|
574
583
|
end
|
575
584
|
end
|
576
585
|
|
577
586
|
# Specify the initial offset in the dash pattern
|
578
|
-
def stroke_dashoffset(value=0)
|
579
|
-
primitive
|
587
|
+
def stroke_dashoffset(value = 0)
|
588
|
+
primitive 'stroke-dashoffset ' + sprintf('%g', value)
|
580
589
|
end
|
581
590
|
|
582
591
|
def stroke_linecap(value)
|
583
|
-
|
584
|
-
|
585
|
-
end
|
592
|
+
value = to_string(value)
|
593
|
+
Kernel.raise ArgumentError, "Unknown linecap type: #{value}" unless %w[butt round square].include?(value.downcase)
|
586
594
|
primitive "stroke-linecap #{value}"
|
587
595
|
end
|
588
596
|
|
589
597
|
def stroke_linejoin(value)
|
590
|
-
|
591
|
-
|
592
|
-
end
|
598
|
+
value = to_string(value)
|
599
|
+
Kernel.raise ArgumentError, "Unknown linejoin type: #{value}" unless %w[round miter bevel].include?(value.downcase)
|
593
600
|
primitive "stroke-linejoin #{value}"
|
594
601
|
end
|
595
602
|
|
596
603
|
def stroke_miterlimit(value)
|
597
|
-
|
598
|
-
|
599
|
-
end
|
604
|
+
value = Float(value)
|
605
|
+
Kernel.raise ArgumentError, 'miterlimit must be >= 1' if value < 1
|
600
606
|
primitive "stroke-miterlimit #{value}"
|
601
607
|
end
|
602
608
|
|
603
609
|
# Specify opacity of stroke drawing color
|
604
610
|
# (use "xx%" to indicate percentage)
|
605
|
-
def stroke_opacity(
|
606
|
-
|
611
|
+
def stroke_opacity(opacity)
|
612
|
+
opacity = to_opacity(opacity)
|
613
|
+
primitive "stroke-opacity #{opacity}"
|
607
614
|
end
|
608
615
|
|
609
616
|
# Specify stroke (outline) width in pixels.
|
610
617
|
def stroke_width(pixels)
|
611
|
-
primitive
|
618
|
+
primitive 'stroke-width ' + sprintf('%g', pixels)
|
612
619
|
end
|
613
620
|
|
614
621
|
# Draw text at position x,y. Add quotes to text that is not already quoted.
|
615
622
|
def text(x, y, text)
|
616
|
-
|
617
|
-
|
618
|
-
end
|
623
|
+
text = to_string(text)
|
624
|
+
Kernel.raise ArgumentError, 'missing text argument' if text.empty?
|
619
625
|
if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
|
620
|
-
|
626
|
+
# text already quoted
|
621
627
|
elsif !text['\'']
|
622
|
-
text = '\''+text+'\''
|
628
|
+
text = '\'' + text + '\''
|
623
629
|
elsif !text['"']
|
624
|
-
text = '"'+text+'"'
|
630
|
+
text = '"' + text + '"'
|
625
631
|
elsif !(text['{'] || text['}'])
|
626
|
-
text = '{'+text+'}'
|
632
|
+
text = '{' + text + '}'
|
627
633
|
else
|
628
634
|
# escape existing braces, surround with braces
|
629
|
-
text = '{' +
|
635
|
+
text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
|
630
636
|
end
|
631
|
-
primitive
|
637
|
+
primitive 'text ' + sprintf('%g,%g %s', x, y, text)
|
632
638
|
end
|
633
639
|
|
634
640
|
# Specify text alignment relative to a given point
|
635
641
|
def text_align(alignment)
|
636
|
-
unless
|
637
|
-
Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}"
|
638
|
-
end
|
642
|
+
Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}" unless ALIGN_TYPE_NAMES.key?(alignment.to_i)
|
639
643
|
primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}"
|
640
644
|
end
|
641
645
|
|
642
646
|
# SVG-compatible version of text_align
|
643
647
|
def text_anchor(anchor)
|
644
|
-
unless
|
645
|
-
Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}"
|
646
|
-
end
|
648
|
+
Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}" unless ANCHOR_TYPE_NAMES.key?(anchor.to_i)
|
647
649
|
primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}"
|
648
650
|
end
|
649
651
|
|
@@ -661,7 +663,7 @@ module Magick
|
|
661
663
|
# Specify center of coordinate space to use for subsequent drawing
|
662
664
|
# commands.
|
663
665
|
def translate(x, y)
|
664
|
-
primitive
|
666
|
+
primitive 'translate ' + sprintf('%g,%g', x, y)
|
665
667
|
end
|
666
668
|
end # class Magick::Draw
|
667
669
|
|
@@ -764,19 +766,13 @@ module Magick
|
|
764
766
|
module Post_ObjectData_Descriptor
|
765
767
|
Confirmed_ObjectData_Size = '9:10'
|
766
768
|
end
|
767
|
-
|
768
|
-
# Make all constants above immutable
|
769
|
-
constants.each do |record|
|
770
|
-
rec = const_get(record)
|
771
|
-
rec.constants.each { |ds| rec.const_get(ds).freeze }
|
772
|
-
end
|
773
769
|
end # module Magick::IPTC
|
774
770
|
|
775
771
|
# Ruby-level Magick::Image methods
|
776
772
|
class Image
|
777
773
|
include Comparable
|
778
774
|
|
779
|
-
|
775
|
+
alias affinity remap
|
780
776
|
|
781
777
|
# Provide an alternate version of Draw#annotate, for folks who
|
782
778
|
# want to find it in this class.
|
@@ -830,7 +826,7 @@ module Magick
|
|
830
826
|
# Thanks to Russell Norris!
|
831
827
|
def each_pixel
|
832
828
|
get_pixels(0, 0, columns, rows).each_with_index do |p, n|
|
833
|
-
yield(p, n%columns, n/columns)
|
829
|
+
yield(p, n % columns, n / columns)
|
834
830
|
end
|
835
831
|
self
|
836
832
|
end
|
@@ -841,13 +837,11 @@ module Magick
|
|
841
837
|
# arrays.
|
842
838
|
def get_exif_by_entry(*entry)
|
843
839
|
ary = []
|
844
|
-
if entry.length
|
840
|
+
if entry.length.zero?
|
845
841
|
exif_data = self['EXIF:*']
|
846
|
-
if exif_data
|
847
|
-
exif_data.split("\n").each { |exif| ary.push(exif.split('=')) }
|
848
|
-
end
|
842
|
+
exif_data.split("\n").each { |exif| ary.push(exif.split('=')) } if exif_data
|
849
843
|
else
|
850
|
-
get_exif_by_entry
|
844
|
+
get_exif_by_entry # ensure properties is populated with exif data
|
851
845
|
entry.each do |name|
|
852
846
|
rval = self["EXIF:#{name}"]
|
853
847
|
ary.push([name, rval])
|
@@ -859,19 +853,19 @@ module Magick
|
|
859
853
|
# Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
|
860
854
|
def get_exif_by_number(*tag)
|
861
855
|
hash = {}
|
862
|
-
if tag.length
|
856
|
+
if tag.length.zero?
|
863
857
|
exif_data = self['EXIF:!']
|
864
858
|
if exif_data
|
865
859
|
exif_data.split("\n").each do |exif|
|
866
860
|
tag, value = exif.split('=')
|
867
|
-
tag = tag[1,4].hex
|
861
|
+
tag = tag[1, 4].hex
|
868
862
|
hash[tag] = value
|
869
863
|
end
|
870
864
|
end
|
871
865
|
else
|
872
|
-
get_exif_by_number
|
866
|
+
get_exif_by_number # ensure properties is populated with exif data
|
873
867
|
tag.each do |num|
|
874
|
-
rval = self['#%04X'
|
868
|
+
rval = self[sprintf('#%04X', num.to_i)]
|
875
869
|
hash[num] = rval == 'unknown' ? nil : rval
|
876
870
|
end
|
877
871
|
end
|
@@ -881,7 +875,7 @@ module Magick
|
|
881
875
|
# Retrieve IPTC information by record number:dataset tag constant defined in
|
882
876
|
# Magick::IPTC, above.
|
883
877
|
def get_iptc_dataset(ds)
|
884
|
-
self['IPTC:'+ds]
|
878
|
+
self['IPTC:' + ds]
|
885
879
|
end
|
886
880
|
|
887
881
|
# Iterate over IPTC record number:dataset tags, yield for each non-nil dataset
|
@@ -909,7 +903,7 @@ module Magick
|
|
909
903
|
# look like they're in the old order.
|
910
904
|
|
911
905
|
# (Thanks to Al Evans for the suggestion.)
|
912
|
-
def level(black_point=0.0, white_point=nil, gamma=nil)
|
906
|
+
def level(black_point = 0.0, white_point = nil, gamma = nil)
|
913
907
|
black_point = Float(black_point)
|
914
908
|
|
915
909
|
white_point ||= Magick::QuantumRange - black_point
|
@@ -921,9 +915,7 @@ module Magick
|
|
921
915
|
|
922
916
|
if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs
|
923
917
|
gamma, white_point = white_point, gamma
|
924
|
-
unless gamma_arg
|
925
|
-
white_point = Magick::QuantumRange - black_point
|
926
|
-
end
|
918
|
+
white_point = Magick::QuantumRange - black_point unless gamma_arg
|
927
919
|
end
|
928
920
|
|
929
921
|
level2(black_point, white_point, gamma)
|
@@ -936,9 +928,9 @@ module Magick
|
|
936
928
|
# Make the pixel at (x,y) transparent.
|
937
929
|
def matte_point(x, y)
|
938
930
|
f = copy
|
939
|
-
f.
|
940
|
-
pixel = f.pixel_color(x,y)
|
941
|
-
pixel.
|
931
|
+
f.alpha(OpaqueAlphaChannel) unless f.alpha?
|
932
|
+
pixel = f.pixel_color(x, y)
|
933
|
+
pixel.alpha = TransparentAlpha
|
942
934
|
f.pixel_color(x, y, pixel)
|
943
935
|
f
|
944
936
|
end
|
@@ -947,7 +939,7 @@ module Magick
|
|
947
939
|
# pixel at (x, y).
|
948
940
|
def matte_replace(x, y)
|
949
941
|
f = copy
|
950
|
-
f.
|
942
|
+
f.alpha(OpaqueAlphaChannel) unless f.alpha?
|
951
943
|
target = f.pixel_color(x, y)
|
952
944
|
f.transparent(target)
|
953
945
|
end
|
@@ -956,56 +948,54 @@ module Magick
|
|
956
948
|
# at (x,y) and is a neighbor.
|
957
949
|
def matte_floodfill(x, y)
|
958
950
|
f = copy
|
959
|
-
f.
|
951
|
+
f.alpha(OpaqueAlphaChannel) unless f.alpha?
|
960
952
|
target = f.pixel_color(x, y)
|
961
|
-
f.matte_flood_fill(target,
|
962
|
-
x, y, FloodfillMethod)
|
953
|
+
f.matte_flood_fill(target, x, y, FloodfillMethod, alpha: TransparentAlpha)
|
963
954
|
end
|
964
955
|
|
965
956
|
# Make transparent any neighbor pixel that is not the border color.
|
966
957
|
def matte_fill_to_border(x, y)
|
967
958
|
f = copy
|
968
|
-
f.
|
969
|
-
f.matte_flood_fill(border_color,
|
970
|
-
x, y, FillToBorderMethod)
|
959
|
+
f.alpha(OpaqueAlphaChannel) unless f.alpha?
|
960
|
+
f.matte_flood_fill(border_color, x, y, FillToBorderMethod, alpha: TransparentAlpha)
|
971
961
|
end
|
972
962
|
|
973
963
|
# Make all pixels transparent.
|
974
964
|
def matte_reset!
|
975
|
-
|
965
|
+
alpha(TransparentAlphaChannel)
|
976
966
|
self
|
977
967
|
end
|
978
968
|
|
979
969
|
# Force an image to exact dimensions without changing the aspect ratio.
|
980
970
|
# Resize and crop if necessary. (Thanks to Jerett Taylor!)
|
981
|
-
def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity)
|
971
|
+
def resize_to_fill(ncols, nrows = nil, gravity = CenterGravity)
|
982
972
|
copy.resize_to_fill!(ncols, nrows, gravity)
|
983
973
|
end
|
984
974
|
|
985
|
-
def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity)
|
975
|
+
def resize_to_fill!(ncols, nrows = nil, gravity = CenterGravity)
|
986
976
|
nrows ||= ncols
|
987
977
|
if ncols != columns || nrows != rows
|
988
|
-
scale = [ncols/columns.to_f, nrows/rows.to_f].max
|
989
|
-
resize!(scale*columns+0.5, scale*rows+0.5)
|
978
|
+
scale = [ncols / columns.to_f, nrows / rows.to_f].max
|
979
|
+
resize!(scale * columns + 0.5, scale * rows + 0.5)
|
990
980
|
end
|
991
981
|
crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows
|
992
982
|
self
|
993
983
|
end
|
994
984
|
|
995
985
|
# Preserve aliases used < RMagick 2.0.1
|
996
|
-
|
997
|
-
|
986
|
+
alias crop_resized resize_to_fill
|
987
|
+
alias crop_resized! resize_to_fill!
|
998
988
|
|
999
989
|
# Convenience method to resize retaining the aspect ratio.
|
1000
990
|
# (Thanks to Robert Manni!)
|
1001
|
-
def resize_to_fit(cols, rows=nil)
|
991
|
+
def resize_to_fit(cols, rows = nil)
|
1002
992
|
rows ||= cols
|
1003
993
|
change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
|
1004
994
|
resize(ncols, nrows)
|
1005
995
|
end
|
1006
996
|
end
|
1007
997
|
|
1008
|
-
def resize_to_fit!(cols, rows=nil)
|
998
|
+
def resize_to_fit!(cols, rows = nil)
|
1009
999
|
rows ||= cols
|
1010
1000
|
change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
|
1011
1001
|
resize!(ncols, nrows)
|
@@ -1028,16 +1018,14 @@ module Magick
|
|
1028
1018
|
def view(x, y, width, height)
|
1029
1019
|
view = View.new(self, x, y, width, height)
|
1030
1020
|
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
return nil
|
1038
|
-
else
|
1039
|
-
return view
|
1021
|
+
return view unless block_given?
|
1022
|
+
|
1023
|
+
begin
|
1024
|
+
yield(view)
|
1025
|
+
ensure
|
1026
|
+
view.sync
|
1040
1027
|
end
|
1028
|
+
nil
|
1041
1029
|
end
|
1042
1030
|
|
1043
1031
|
# Magick::Image::View class
|
@@ -1047,12 +1035,8 @@ module Magick
|
|
1047
1035
|
|
1048
1036
|
def initialize(img, x, y, width, height)
|
1049
1037
|
img.check_destroyed
|
1050
|
-
if width <= 0 || height <= 0
|
1051
|
-
|
1052
|
-
end
|
1053
|
-
if x < 0 || y < 0 || (x+width) > img.columns || (y+height) > img.rows
|
1054
|
-
Kernel.raise RangeError, "geometry (#{width}x#{height}+#{x}+#{y}) exceeds image boundary"
|
1055
|
-
end
|
1038
|
+
Kernel.raise ArgumentError, "invalid geometry (#{width}x#{height}+#{x}+#{y})" if width <= 0 || height <= 0
|
1039
|
+
Kernel.raise RangeError, "geometry (#{width}x#{height}+#{x}+#{y}) exceeds image boundary" if x < 0 || y < 0 || (x + width) > img.columns || (y + height) > img.rows
|
1056
1040
|
@view = img.get_pixels(x, y, width, height)
|
1057
1041
|
@img = img
|
1058
1042
|
@x = x
|
@@ -1069,7 +1053,7 @@ module Magick
|
|
1069
1053
|
end
|
1070
1054
|
|
1071
1055
|
# Store changed pixels back to image
|
1072
|
-
def sync(force=false)
|
1056
|
+
def sync(force = false)
|
1073
1057
|
@img.store_pixels(x, y, width, height, @view) if @dirty || force
|
1074
1058
|
@dirty || force
|
1075
1059
|
end
|
@@ -1078,7 +1062,7 @@ module Magick
|
|
1078
1062
|
# true, don't change it back to false!
|
1079
1063
|
def update(rows)
|
1080
1064
|
@dirty = true
|
1081
|
-
rows.delete_observer(self)
|
1065
|
+
rows.delete_observer(self) # No need to tell us again.
|
1082
1066
|
nil
|
1083
1067
|
end
|
1084
1068
|
|
@@ -1088,18 +1072,18 @@ module Magick
|
|
1088
1072
|
include Observable
|
1089
1073
|
|
1090
1074
|
# Define a getter and a setter for each channel.
|
1091
|
-
[
|
1092
|
-
module_eval <<-END_EVAL
|
1075
|
+
%i[red green blue opacity].each do |c|
|
1076
|
+
module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
1093
1077
|
def #{c}
|
1094
|
-
|
1078
|
+
return collect { |p| p.#{c} }
|
1095
1079
|
end
|
1096
1080
|
def #{c}=(v)
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1081
|
+
each { |p| p.#{c} = v }
|
1082
|
+
changed
|
1083
|
+
notify_observers(self)
|
1084
|
+
v
|
1101
1085
|
end
|
1102
|
-
|
1086
|
+
END_EVAL
|
1103
1087
|
end
|
1104
1088
|
end # class Magick::Image::View::Pixels
|
1105
1089
|
|
@@ -1119,7 +1103,7 @@ module Magick
|
|
1119
1103
|
|
1120
1104
|
# Both View::Pixels and Magick::Pixel implement Observable
|
1121
1105
|
if @unique
|
1122
|
-
pixels = @view[@rows[0]
|
1106
|
+
pixels = @view[@rows[0] * @width + @cols[0]]
|
1123
1107
|
pixels.add_observer(self)
|
1124
1108
|
else
|
1125
1109
|
pixels = View::Pixels.new
|
@@ -1133,8 +1117,8 @@ module Magick
|
|
1133
1117
|
end
|
1134
1118
|
|
1135
1119
|
def []=(*args)
|
1136
|
-
rv = args.delete_at(-1)
|
1137
|
-
unless rv.is_a?(Pixel)
|
1120
|
+
rv = args.delete_at(-1) # get rvalue
|
1121
|
+
unless rv.is_a?(Pixel) # must be a Pixel or a color name
|
1138
1122
|
begin
|
1139
1123
|
rv = Pixel.from_color(rv)
|
1140
1124
|
rescue TypeError
|
@@ -1145,7 +1129,6 @@ module Magick
|
|
1145
1129
|
each { |x| @view[x] = rv.dup }
|
1146
1130
|
changed
|
1147
1131
|
notify_observers(self)
|
1148
|
-
nil
|
1149
1132
|
end
|
1150
1133
|
|
1151
1134
|
# A pixel has been modified. Tell the view.
|
@@ -1159,7 +1142,7 @@ module Magick
|
|
1159
1142
|
private
|
1160
1143
|
|
1161
1144
|
def cols(*args)
|
1162
|
-
@cols = args[0]
|
1145
|
+
@cols = args[0] # remove the outermost array
|
1163
1146
|
@unique = false
|
1164
1147
|
|
1165
1148
|
# Convert @rows to an Enumerable object
|
@@ -1173,12 +1156,8 @@ module Magick
|
|
1173
1156
|
@rows = @rows.first
|
1174
1157
|
else
|
1175
1158
|
@rows = Integer(@rows.first)
|
1176
|
-
if @rows < 0
|
1177
|
-
|
1178
|
-
end
|
1179
|
-
if @rows < 0 || @rows > @height-1
|
1180
|
-
Kernel.raise IndexError, "index [#{@rows}] out of range"
|
1181
|
-
end
|
1159
|
+
@rows += @height if @rows < 0
|
1160
|
+
Kernel.raise IndexError, "index [#{@rows}] out of range" if @rows < 0 || @rows > @height - 1
|
1182
1161
|
# Convert back to an array
|
1183
1162
|
@rows = Array.new(1, @rows)
|
1184
1163
|
@unique = true
|
@@ -1189,27 +1168,23 @@ module Magick
|
|
1189
1168
|
length = Integer(@rows[1])
|
1190
1169
|
|
1191
1170
|
# Negative start -> start from last row
|
1192
|
-
if start < 0
|
1193
|
-
start += @height
|
1194
|
-
end
|
1171
|
+
start += @height if start < 0
|
1195
1172
|
|
1196
1173
|
if start > @height || start < 0 || length < 0
|
1197
1174
|
Kernel.raise IndexError, "index [#{@rows.first}] out of range"
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
length = [length, 0].max
|
1202
|
-
end
|
1175
|
+
elsif start + length > @height
|
1176
|
+
length = @height - length
|
1177
|
+
length = [length, 0].max
|
1203
1178
|
end
|
1204
1179
|
# Create a Range for the specified set of rows
|
1205
|
-
@rows = Range.new(start, start+length, true)
|
1180
|
+
@rows = Range.new(start, start + length, true)
|
1206
1181
|
end
|
1207
1182
|
|
1208
1183
|
case @cols.length
|
1209
|
-
when 0
|
1210
|
-
@cols = Range.new(0, @width, true)
|
1184
|
+
when 0 # all rows
|
1185
|
+
@cols = Range.new(0, @width, true) # convert to range
|
1211
1186
|
@unique = false
|
1212
|
-
when 1
|
1187
|
+
when 1 # Range, Array, or a single integer
|
1213
1188
|
# if the single element is already an Enumerable
|
1214
1189
|
# object, get it.
|
1215
1190
|
if @cols.first.respond_to? :each
|
@@ -1217,12 +1192,8 @@ module Magick
|
|
1217
1192
|
@unique = false
|
1218
1193
|
else
|
1219
1194
|
@cols = Integer(@cols.first)
|
1220
|
-
if @cols < 0
|
1221
|
-
|
1222
|
-
end
|
1223
|
-
if @cols < 0 || @cols > @width-1
|
1224
|
-
Kernel.raise IndexError, "index [#{@cols}] out of range"
|
1225
|
-
end
|
1195
|
+
@cols += @width if @cols < 0
|
1196
|
+
Kernel.raise IndexError, "index [#{@cols}] out of range" if @cols < 0 || @cols > @width - 1
|
1226
1197
|
# Convert back to array
|
1227
1198
|
@cols = Array.new(1, @cols)
|
1228
1199
|
@unique &&= true
|
@@ -1233,20 +1204,16 @@ module Magick
|
|
1233
1204
|
length = Integer(@cols[1])
|
1234
1205
|
|
1235
1206
|
# Negative start -> start from last row
|
1236
|
-
if start < 0
|
1237
|
-
start += @width
|
1238
|
-
end
|
1207
|
+
start += @width if start < 0
|
1239
1208
|
|
1240
1209
|
if start > @width || start < 0 || length < 0
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
length = [length, 0].max
|
1246
|
-
end
|
1210
|
+
# nop
|
1211
|
+
elsif start + length > @width
|
1212
|
+
length = @width - length
|
1213
|
+
length = [length, 0].max
|
1247
1214
|
end
|
1248
1215
|
# Create a Range for the specified set of columns
|
1249
|
-
@cols = Range.new(start, start+length, true)
|
1216
|
+
@cols = Range.new(start, start + length, true)
|
1250
1217
|
@unique = false
|
1251
1218
|
end
|
1252
1219
|
end
|
@@ -1257,20 +1224,16 @@ module Magick
|
|
1257
1224
|
maxcols = @width - 1
|
1258
1225
|
|
1259
1226
|
@rows.each do |j|
|
1260
|
-
if j > maxrows
|
1261
|
-
Kernel.raise IndexError, "index [#{j}] out of range"
|
1262
|
-
end
|
1227
|
+
Kernel.raise IndexError, "index [#{j}] out of range" if j > maxrows
|
1263
1228
|
@cols.each do |i|
|
1264
|
-
if i > maxcols
|
1265
|
-
|
1266
|
-
end
|
1267
|
-
yield j*@width + i
|
1229
|
+
Kernel.raise IndexError, "index [#{i}] out of range" if i > maxcols
|
1230
|
+
yield j * @width + i
|
1268
1231
|
end
|
1269
1232
|
end
|
1270
|
-
nil
|
1233
|
+
nil # useless return value
|
1271
1234
|
end
|
1272
1235
|
end # class Magick::Image::View::Rows
|
1273
|
-
end
|
1236
|
+
end # class Magick::Image::View
|
1274
1237
|
end # class Magick::Image
|
1275
1238
|
|
1276
1239
|
class ImageList
|
@@ -1281,31 +1244,27 @@ module Magick
|
|
1281
1244
|
private
|
1282
1245
|
|
1283
1246
|
def get_current
|
1284
|
-
|
1247
|
+
@images[@scene].__id__
|
1248
|
+
rescue StandardError
|
1249
|
+
nil
|
1285
1250
|
end
|
1286
1251
|
|
1287
1252
|
protected
|
1288
1253
|
|
1289
|
-
def
|
1290
|
-
unless obj.is_a? Magick::Image
|
1291
|
-
Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)"
|
1292
|
-
end
|
1293
|
-
true
|
1254
|
+
def assert_image(obj)
|
1255
|
+
Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)" unless obj.is_a? Magick::Image
|
1294
1256
|
end
|
1295
1257
|
|
1296
1258
|
# Ensure array is always an array of Magick::Image objects
|
1297
|
-
def
|
1298
|
-
unless ary.respond_to? :each
|
1299
|
-
|
1300
|
-
end
|
1301
|
-
ary.each { |obj| is_an_image obj }
|
1302
|
-
true
|
1259
|
+
def assert_image_array(ary)
|
1260
|
+
Kernel.raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)" unless ary.respond_to? :each
|
1261
|
+
ary.each { |obj| assert_image obj }
|
1303
1262
|
end
|
1304
1263
|
|
1305
1264
|
# Find old current image, update scene number
|
1306
1265
|
# current is the id of the old current image.
|
1307
1266
|
def set_current(current)
|
1308
|
-
if length
|
1267
|
+
if length.zero?
|
1309
1268
|
self.scene = nil
|
1310
1269
|
return
|
1311
1270
|
# Don't bother looking for current image
|
@@ -1316,10 +1275,8 @@ module Magick
|
|
1316
1275
|
# Find last instance of "current" in the list.
|
1317
1276
|
# If "current" isn't in the list, set current to last image.
|
1318
1277
|
self.scene = length - 1
|
1319
|
-
each_with_index do |f,i|
|
1320
|
-
if f.__id__ == current
|
1321
|
-
self.scene = i
|
1322
|
-
end
|
1278
|
+
each_with_index do |f, i|
|
1279
|
+
self.scene = i if f.__id__ == current
|
1323
1280
|
end
|
1324
1281
|
return
|
1325
1282
|
end
|
@@ -1331,56 +1288,45 @@ module Magick
|
|
1331
1288
|
# Allow scene to be set to nil
|
1332
1289
|
def scene=(n)
|
1333
1290
|
if n.nil?
|
1334
|
-
Kernel.raise IndexError, 'scene number out of bounds' unless @images.length
|
1291
|
+
Kernel.raise IndexError, 'scene number out of bounds' unless @images.length.zero?
|
1335
1292
|
@scene = nil
|
1336
|
-
return
|
1337
|
-
elsif @images.length
|
1293
|
+
return
|
1294
|
+
elsif @images.length.zero?
|
1338
1295
|
Kernel.raise IndexError, 'scene number out of bounds'
|
1339
1296
|
end
|
1340
1297
|
|
1341
1298
|
n = Integer(n)
|
1342
|
-
if n < 0 || n > length - 1
|
1343
|
-
Kernel.raise IndexError, 'scene number out of bounds'
|
1344
|
-
end
|
1299
|
+
Kernel.raise IndexError, 'scene number out of bounds' if n < 0 || n > length - 1
|
1345
1300
|
@scene = n
|
1346
|
-
@scene
|
1347
1301
|
end
|
1348
1302
|
|
1349
1303
|
# All the binary operators work the same way.
|
1350
1304
|
# 'other' should be either an ImageList or an Array
|
1351
|
-
%w
|
1352
|
-
module_eval <<-END_BINOPS
|
1305
|
+
%w[& + - |].each do |op|
|
1306
|
+
module_eval <<-END_BINOPS, __FILE__, __LINE__ + 1
|
1353
1307
|
def #{op}(other)
|
1308
|
+
assert_image_array(other)
|
1354
1309
|
ilist = self.class.new
|
1355
|
-
|
1356
|
-
a = other #{op} @images
|
1357
|
-
rescue TypeError
|
1358
|
-
Kernel.raise ArgumentError, "Magick::ImageList expected, got " + other.class.to_s
|
1359
|
-
end
|
1310
|
+
a = other #{op} @images
|
1360
1311
|
current = get_current()
|
1361
|
-
a.each
|
1362
|
-
is_an_image image
|
1363
|
-
ilist << image
|
1364
|
-
end
|
1312
|
+
a.each { |image| ilist << image }
|
1365
1313
|
ilist.set_current current
|
1366
1314
|
return ilist
|
1367
1315
|
end
|
1368
1316
|
END_BINOPS
|
1369
1317
|
end
|
1370
1318
|
|
1371
|
-
def *(
|
1372
|
-
unless
|
1373
|
-
Kernel.raise ArgumentError, "Integer required (#{n.class} given)"
|
1374
|
-
end
|
1319
|
+
def *(other)
|
1320
|
+
Kernel.raise ArgumentError, "Integer required (#{other.class} given)" unless other.is_a? Integer
|
1375
1321
|
current = get_current
|
1376
1322
|
ilist = self.class.new
|
1377
|
-
(@images *
|
1323
|
+
(@images * other).each { |image| ilist << image }
|
1378
1324
|
ilist.set_current current
|
1379
1325
|
ilist
|
1380
1326
|
end
|
1381
1327
|
|
1382
1328
|
def <<(obj)
|
1383
|
-
|
1329
|
+
assert_image obj
|
1384
1330
|
@images << obj
|
1385
1331
|
@scene = @images.length - 1
|
1386
1332
|
self
|
@@ -1392,23 +1338,21 @@ module Magick
|
|
1392
1338
|
# return if A.scene != B.scene
|
1393
1339
|
# return A.length <=> B.length
|
1394
1340
|
def <=>(other)
|
1395
|
-
unless other.is_a? self.class
|
1396
|
-
|
1397
|
-
end
|
1341
|
+
return unless other.is_a? self.class
|
1342
|
+
|
1398
1343
|
size = [length, other.length].min
|
1399
1344
|
size.times do |x|
|
1400
1345
|
r = self[x] <=> other[x]
|
1401
|
-
return r unless r
|
1402
|
-
end
|
1403
|
-
if @scene.nil? && other.scene.nil?
|
1404
|
-
return 0
|
1405
|
-
elsif @scene.nil? && !other.scene.nil?
|
1406
|
-
Kernel.raise TypeError, "cannot convert nil into #{other.scene.class}"
|
1407
|
-
elsif ! @scene.nil? && other.scene.nil?
|
1408
|
-
Kernel.raise TypeError, "cannot convert nil into #{scene.class}"
|
1346
|
+
return r unless r.zero?
|
1409
1347
|
end
|
1348
|
+
|
1349
|
+
return 0 if @scene.nil? && other.scene.nil?
|
1350
|
+
return if @scene.nil? && !other.scene.nil?
|
1351
|
+
return if !@scene.nil? && other.scene.nil?
|
1352
|
+
|
1410
1353
|
r = scene <=> other.scene
|
1411
|
-
return r unless r
|
1354
|
+
return r unless r.zero?
|
1355
|
+
|
1412
1356
|
length <=> other.length
|
1413
1357
|
end
|
1414
1358
|
|
@@ -1416,7 +1360,7 @@ module Magick
|
|
1416
1360
|
a = @images[*args]
|
1417
1361
|
if a.respond_to?(:each)
|
1418
1362
|
ilist = self.class.new
|
1419
|
-
a.each {|image| ilist << image}
|
1363
|
+
a.each { |image| ilist << image }
|
1420
1364
|
a = ilist
|
1421
1365
|
end
|
1422
1366
|
a
|
@@ -1425,32 +1369,31 @@ module Magick
|
|
1425
1369
|
def []=(*args)
|
1426
1370
|
obj = @images.[]=(*args)
|
1427
1371
|
if obj && obj.respond_to?(:each)
|
1428
|
-
|
1372
|
+
assert_image_array(obj)
|
1429
1373
|
set_current obj.last.__id__
|
1430
1374
|
elsif obj
|
1431
|
-
|
1375
|
+
assert_image(obj)
|
1432
1376
|
set_current obj.__id__
|
1433
1377
|
else
|
1434
1378
|
set_current nil
|
1435
1379
|
end
|
1436
|
-
obj
|
1437
1380
|
end
|
1438
1381
|
|
1439
|
-
[
|
1440
|
-
|
1441
|
-
|
1382
|
+
%i[
|
1383
|
+
at each each_index empty? fetch
|
1384
|
+
first hash include? index length rindex
|
1385
|
+
].each do |mth|
|
1386
|
+
module_eval <<-END_SIMPLE_DELEGATES, __FILE__, __LINE__ + 1
|
1442
1387
|
def #{mth}(*args, &block)
|
1443
1388
|
@images.#{mth}(*args, &block)
|
1444
1389
|
end
|
1445
1390
|
END_SIMPLE_DELEGATES
|
1446
1391
|
end
|
1447
|
-
|
1392
|
+
alias size length
|
1448
1393
|
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
@images.nitems
|
1453
|
-
end
|
1394
|
+
def sort!(*args, &block)
|
1395
|
+
@images.sort!(*args, &block)
|
1396
|
+
self
|
1454
1397
|
end
|
1455
1398
|
|
1456
1399
|
def clear
|
@@ -1467,16 +1410,16 @@ module Magick
|
|
1467
1410
|
# override Enumerable#collect
|
1468
1411
|
def collect(&block)
|
1469
1412
|
current = get_current
|
1470
|
-
a = @images.
|
1413
|
+
a = @images.map(&block)
|
1471
1414
|
ilist = self.class.new
|
1472
|
-
a.each {|image| ilist << image}
|
1415
|
+
a.each { |image| ilist << image }
|
1473
1416
|
ilist.set_current current
|
1474
1417
|
ilist
|
1475
1418
|
end
|
1476
1419
|
|
1477
1420
|
def collect!(&block)
|
1478
|
-
@images.
|
1479
|
-
|
1421
|
+
@images.map!(&block)
|
1422
|
+
assert_image_array @images
|
1480
1423
|
self
|
1481
1424
|
end
|
1482
1425
|
|
@@ -1485,59 +1428,56 @@ module Magick
|
|
1485
1428
|
ditto = self.class.new
|
1486
1429
|
@images.each { |f| ditto << f.copy }
|
1487
1430
|
ditto.scene = @scene
|
1488
|
-
ditto.taint if tainted?
|
1489
1431
|
ditto
|
1490
1432
|
end
|
1491
1433
|
|
1492
1434
|
# Return the current image
|
1493
1435
|
def cur_image
|
1494
|
-
unless @scene
|
1495
|
-
Kernel.raise IndexError, 'no images in this list'
|
1496
|
-
end
|
1436
|
+
Kernel.raise IndexError, 'no images in this list' unless @scene
|
1497
1437
|
@images[@scene]
|
1498
1438
|
end
|
1499
1439
|
|
1500
1440
|
# ImageList#map took over the "map" name. Use alternatives.
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1441
|
+
alias map collect
|
1442
|
+
alias __map__ collect
|
1443
|
+
alias map! collect!
|
1444
|
+
alias __map__! collect!
|
1504
1445
|
|
1505
|
-
#
|
1506
|
-
|
1446
|
+
# ImageMagick used affinity in 6.4.3, switch to remap in 6.4.4.
|
1447
|
+
alias affinity remap
|
1507
1448
|
|
1508
1449
|
def compact
|
1509
1450
|
current = get_current
|
1510
1451
|
ilist = self.class.new
|
1511
1452
|
a = @images.compact
|
1512
|
-
a.each {|image| ilist << image}
|
1453
|
+
a.each { |image| ilist << image }
|
1513
1454
|
ilist.set_current current
|
1514
1455
|
ilist
|
1515
1456
|
end
|
1516
1457
|
|
1517
1458
|
def compact!
|
1518
1459
|
current = get_current
|
1519
|
-
a = @images.compact!
|
1460
|
+
a = @images.compact! # returns nil if no changes were made
|
1520
1461
|
set_current current
|
1521
1462
|
a.nil? ? nil : self
|
1522
1463
|
end
|
1523
1464
|
|
1524
1465
|
def concat(other)
|
1525
|
-
|
1526
|
-
other.each {|image| @images << image}
|
1527
|
-
@scene = length-1
|
1466
|
+
assert_image_array other
|
1467
|
+
other.each { |image| @images << image }
|
1468
|
+
@scene = length - 1
|
1528
1469
|
self
|
1529
1470
|
end
|
1530
1471
|
|
1531
1472
|
# Set same delay for all images
|
1532
1473
|
def delay=(d)
|
1533
|
-
if Integer(d) < 0
|
1534
|
-
|
1535
|
-
end
|
1474
|
+
raise ArgumentError, 'delay must be greater than or equal to 0' if Integer(d) < 0
|
1475
|
+
|
1536
1476
|
@images.each { |f| f.delay = Integer(d) }
|
1537
1477
|
end
|
1538
1478
|
|
1539
1479
|
def delete(obj, &block)
|
1540
|
-
|
1480
|
+
assert_image obj
|
1541
1481
|
current = get_current
|
1542
1482
|
a = @images.delete(obj, &block)
|
1543
1483
|
set_current current
|
@@ -1560,14 +1500,18 @@ module Magick
|
|
1560
1500
|
|
1561
1501
|
def dup
|
1562
1502
|
ditto = self.class.new
|
1563
|
-
@images.each {|img| ditto << img}
|
1503
|
+
@images.each { |img| ditto << img }
|
1564
1504
|
ditto.scene = @scene
|
1565
|
-
ditto.taint if tainted?
|
1566
1505
|
ditto
|
1567
1506
|
end
|
1568
1507
|
|
1569
1508
|
def eql?(other)
|
1570
|
-
|
1509
|
+
begin
|
1510
|
+
assert_image_array other
|
1511
|
+
rescue ArgumentError
|
1512
|
+
return false
|
1513
|
+
end
|
1514
|
+
|
1571
1515
|
eql = other.eql?(@images)
|
1572
1516
|
begin # "other" is another ImageList
|
1573
1517
|
eql &&= @scene == other.scene
|
@@ -1578,10 +1522,10 @@ module Magick
|
|
1578
1522
|
end
|
1579
1523
|
|
1580
1524
|
def fill(*args, &block)
|
1581
|
-
|
1525
|
+
assert_image args[0] unless block_given?
|
1582
1526
|
current = get_current
|
1583
1527
|
@images.fill(*args, &block)
|
1584
|
-
|
1528
|
+
assert_image_array self
|
1585
1529
|
set_current current
|
1586
1530
|
self
|
1587
1531
|
end
|
@@ -1589,20 +1533,18 @@ module Magick
|
|
1589
1533
|
# Override Enumerable's find_all
|
1590
1534
|
def find_all(&block)
|
1591
1535
|
current = get_current
|
1592
|
-
a = @images.
|
1536
|
+
a = @images.select(&block)
|
1593
1537
|
ilist = self.class.new
|
1594
|
-
a.each {|image| ilist << image}
|
1538
|
+
a.each { |image| ilist << image }
|
1595
1539
|
ilist.set_current current
|
1596
1540
|
ilist
|
1597
1541
|
end
|
1598
|
-
|
1542
|
+
alias select find_all
|
1599
1543
|
|
1600
1544
|
def from_blob(*blobs, &block)
|
1601
|
-
if
|
1602
|
-
Kernel.raise ArgumentError, 'no blobs given'
|
1603
|
-
end
|
1545
|
+
Kernel.raise ArgumentError, 'no blobs given' if blobs.length.zero?
|
1604
1546
|
blobs.each do |b|
|
1605
|
-
Magick::Image.from_blob(b, &block).each { |n| @images << n
|
1547
|
+
Magick::Image.from_blob(b, &block).each { |n| @images << n }
|
1606
1548
|
end
|
1607
1549
|
@scene = length - 1
|
1608
1550
|
self
|
@@ -1615,14 +1557,12 @@ module Magick
|
|
1615
1557
|
filenames.each do |f|
|
1616
1558
|
Magick::Image.read(f, &block).each { |n| @images << n }
|
1617
1559
|
end
|
1618
|
-
|
1619
|
-
|
1620
|
-
end
|
1621
|
-
self
|
1560
|
+
|
1561
|
+
@scene = length - 1 if length > 0 # last image in array
|
1622
1562
|
end
|
1623
1563
|
|
1624
1564
|
def insert(index, *args)
|
1625
|
-
args.each {|image|
|
1565
|
+
args.each { |image| assert_image image }
|
1626
1566
|
current = get_current
|
1627
1567
|
@images.insert(index, *args)
|
1628
1568
|
set_current current
|
@@ -1632,27 +1572,24 @@ module Magick
|
|
1632
1572
|
# Call inspect for all the images
|
1633
1573
|
def inspect
|
1634
1574
|
img = []
|
1635
|
-
@images.each {|image| img << image.inspect }
|
1575
|
+
@images.each { |image| img << image.inspect }
|
1636
1576
|
img = '[' + img.join(",\n") + "]\nscene=#{@scene}"
|
1637
1577
|
end
|
1638
1578
|
|
1639
1579
|
# Set the number of iterations of an animated GIF
|
1640
1580
|
def iterations=(n)
|
1641
1581
|
n = Integer(n)
|
1642
|
-
if n < 0 || n >
|
1643
|
-
|
1644
|
-
end
|
1645
|
-
@images.each {|f| f.iterations=n}
|
1646
|
-
self
|
1582
|
+
Kernel.raise ArgumentError, 'iterations must be between 0 and 65535' if n < 0 || n > 65_535
|
1583
|
+
@images.each { |f| f.iterations = n }
|
1647
1584
|
end
|
1648
1585
|
|
1649
1586
|
def last(*args)
|
1650
|
-
if args.length
|
1587
|
+
if args.length.zero?
|
1651
1588
|
a = @images.last
|
1652
1589
|
else
|
1653
1590
|
a = @images.last(*args)
|
1654
1591
|
ilist = self.class.new
|
1655
|
-
a.each {|img| ilist << img}
|
1592
|
+
a.each { |img| ilist << img }
|
1656
1593
|
@scene = a.length - 1
|
1657
1594
|
a = ilist
|
1658
1595
|
end
|
@@ -1662,28 +1599,30 @@ module Magick
|
|
1662
1599
|
# Custom marshal/unmarshal for Ruby 1.8.
|
1663
1600
|
def marshal_dump
|
1664
1601
|
ary = [@scene]
|
1665
|
-
@images.each {|i| ary << Marshal.dump(i)}
|
1602
|
+
@images.each { |i| ary << Marshal.dump(i) }
|
1666
1603
|
ary
|
1667
1604
|
end
|
1668
1605
|
|
1669
1606
|
def marshal_load(ary)
|
1670
1607
|
@scene = ary.shift
|
1671
1608
|
@images = []
|
1672
|
-
ary.each {|a| @images << Marshal.load(a)}
|
1609
|
+
ary.each { |a| @images << Marshal.load(a) }
|
1673
1610
|
end
|
1674
1611
|
|
1675
1612
|
# The ImageList class supports the Magick::Image class methods by simply sending
|
1676
1613
|
# the method to the current image. If the method isn't explicitly supported,
|
1677
1614
|
# send it to the current image in the array. If there are no images, send
|
1678
1615
|
# it up the line. Catch a NameError and emit a useful message.
|
1679
|
-
def method_missing(
|
1616
|
+
def method_missing(meth_id, *args, &block)
|
1680
1617
|
if @scene
|
1681
|
-
@images[@scene]
|
1618
|
+
img = @images[@scene]
|
1619
|
+
new_img = img.send(meth_id, *args, &block)
|
1620
|
+
img.object_id == new_img.object_id ? self : new_img
|
1682
1621
|
else
|
1683
1622
|
super
|
1684
1623
|
end
|
1685
1624
|
rescue NoMethodError
|
1686
|
-
Kernel.raise NoMethodError, "undefined method `#{
|
1625
|
+
Kernel.raise NoMethodError, "undefined method `#{meth_id.id2name}' for #{self.class}"
|
1687
1626
|
rescue Exception
|
1688
1627
|
$ERROR_POSITION.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
|
1689
1628
|
Kernel.raise
|
@@ -1697,19 +1636,17 @@ module Magick
|
|
1697
1636
|
def partition(&block)
|
1698
1637
|
a = @images.partition(&block)
|
1699
1638
|
t = self.class.new
|
1700
|
-
a[0].each { |img| t << img}
|
1639
|
+
a[0].each { |img| t << img }
|
1701
1640
|
t.set_current nil
|
1702
1641
|
f = self.class.new
|
1703
|
-
a[1].each { |img| f << img}
|
1642
|
+
a[1].each { |img| f << img }
|
1704
1643
|
f.set_current nil
|
1705
1644
|
[t, f]
|
1706
1645
|
end
|
1707
1646
|
|
1708
1647
|
# Ping files and concatenate the new images
|
1709
1648
|
def ping(*files, &block)
|
1710
|
-
if
|
1711
|
-
Kernel.raise ArgumentError, 'no files given'
|
1712
|
-
end
|
1649
|
+
Kernel.raise ArgumentError, 'no files given' if files.length.zero?
|
1713
1650
|
files.each do |f|
|
1714
1651
|
Magick::Image.ping(f, &block).each { |n| @images << n }
|
1715
1652
|
end
|
@@ -1719,14 +1656,14 @@ module Magick
|
|
1719
1656
|
|
1720
1657
|
def pop
|
1721
1658
|
current = get_current
|
1722
|
-
a = @images.pop
|
1659
|
+
a = @images.pop # can return nil
|
1723
1660
|
set_current current
|
1724
1661
|
a
|
1725
1662
|
end
|
1726
1663
|
|
1727
1664
|
def push(*objs)
|
1728
1665
|
objs.each do |image|
|
1729
|
-
|
1666
|
+
assert_image image
|
1730
1667
|
@images << image
|
1731
1668
|
end
|
1732
1669
|
@scene = length - 1
|
@@ -1735,9 +1672,7 @@ module Magick
|
|
1735
1672
|
|
1736
1673
|
# Read files and concatenate the new images
|
1737
1674
|
def read(*files, &block)
|
1738
|
-
if
|
1739
|
-
Kernel.raise ArgumentError, 'no files given'
|
1740
|
-
end
|
1675
|
+
Kernel.raise ArgumentError, 'no files given' if files.length.zero?
|
1741
1676
|
files.each do |f|
|
1742
1677
|
Magick::Image.read(f, &block).each { |n| @images << n }
|
1743
1678
|
end
|
@@ -1750,7 +1685,7 @@ module Magick
|
|
1750
1685
|
current = get_current
|
1751
1686
|
ilist = self.class.new
|
1752
1687
|
a = @images.reject(&block)
|
1753
|
-
a.each {|image| ilist << image}
|
1688
|
+
a.each { |image| ilist << image }
|
1754
1689
|
ilist.set_current current
|
1755
1690
|
ilist
|
1756
1691
|
end
|
@@ -1764,21 +1699,22 @@ module Magick
|
|
1764
1699
|
end
|
1765
1700
|
|
1766
1701
|
def replace(other)
|
1767
|
-
|
1702
|
+
assert_image_array other
|
1768
1703
|
current = get_current
|
1769
1704
|
@images.clear
|
1770
|
-
other.each {|image| @images << image}
|
1771
|
-
@scene = length
|
1705
|
+
other.each { |image| @images << image }
|
1706
|
+
@scene = length.zero? ? nil : 0
|
1772
1707
|
set_current current
|
1773
1708
|
self
|
1774
1709
|
end
|
1775
1710
|
|
1776
1711
|
# Ensure respond_to? answers correctly when we are delegating to Image
|
1777
|
-
|
1778
|
-
def respond_to?(
|
1779
|
-
return true if __respond_to__?(
|
1712
|
+
alias __respond_to__? respond_to?
|
1713
|
+
def respond_to?(meth_id, priv = false)
|
1714
|
+
return true if __respond_to__?(meth_id, priv)
|
1715
|
+
|
1780
1716
|
if @scene
|
1781
|
-
@images[@scene].respond_to?(
|
1717
|
+
@images[@scene].respond_to?(meth_id, priv)
|
1782
1718
|
else
|
1783
1719
|
super
|
1784
1720
|
end
|
@@ -1787,7 +1723,7 @@ module Magick
|
|
1787
1723
|
def reverse
|
1788
1724
|
current = get_current
|
1789
1725
|
a = self.class.new
|
1790
|
-
@images.reverse_each {|image| a << image}
|
1726
|
+
@images.reverse_each { |image| a << image }
|
1791
1727
|
a.set_current current
|
1792
1728
|
a
|
1793
1729
|
end
|
@@ -1800,7 +1736,7 @@ module Magick
|
|
1800
1736
|
end
|
1801
1737
|
|
1802
1738
|
def reverse_each
|
1803
|
-
@images.reverse_each {|image| yield(image)}
|
1739
|
+
@images.reverse_each { |image| yield(image) }
|
1804
1740
|
self
|
1805
1741
|
end
|
1806
1742
|
|
@@ -1816,7 +1752,7 @@ module Magick
|
|
1816
1752
|
if slice
|
1817
1753
|
ilist = self.class.new
|
1818
1754
|
if slice.respond_to?(:each)
|
1819
|
-
slice.each {|image| ilist << image}
|
1755
|
+
slice.each { |image| ilist << image }
|
1820
1756
|
else
|
1821
1757
|
ilist << slice
|
1822
1758
|
end
|
@@ -1834,27 +1770,25 @@ module Magick
|
|
1834
1770
|
end
|
1835
1771
|
|
1836
1772
|
def ticks_per_second=(t)
|
1837
|
-
if Integer(t) < 0
|
1838
|
-
Kernel.raise ArgumentError, 'ticks_per_second must be greater than or equal to 0'
|
1839
|
-
end
|
1773
|
+
Kernel.raise ArgumentError, 'ticks_per_second must be greater than or equal to 0' if Integer(t) < 0
|
1840
1774
|
@images.each { |f| f.ticks_per_second = Integer(t) }
|
1841
1775
|
end
|
1842
1776
|
|
1843
1777
|
def to_a
|
1844
1778
|
a = []
|
1845
|
-
@images.each {|image| a << image}
|
1779
|
+
@images.each { |image| a << image }
|
1846
1780
|
a
|
1847
1781
|
end
|
1848
1782
|
|
1849
1783
|
def uniq
|
1850
1784
|
current = get_current
|
1851
1785
|
a = self.class.new
|
1852
|
-
@images.uniq.each {|image| a << image}
|
1786
|
+
@images.uniq.each { |image| a << image }
|
1853
1787
|
a.set_current current
|
1854
1788
|
a
|
1855
1789
|
end
|
1856
1790
|
|
1857
|
-
def uniq!(*
|
1791
|
+
def uniq!(*_args)
|
1858
1792
|
current = get_current
|
1859
1793
|
a = @images.uniq!
|
1860
1794
|
set_current current
|
@@ -1863,23 +1797,27 @@ module Magick
|
|
1863
1797
|
|
1864
1798
|
# @scene -> new object
|
1865
1799
|
def unshift(obj)
|
1866
|
-
|
1800
|
+
assert_image obj
|
1867
1801
|
@images.unshift(obj)
|
1868
1802
|
@scene = 0
|
1869
1803
|
self
|
1870
1804
|
end
|
1871
1805
|
|
1872
1806
|
def values_at(*args)
|
1873
|
-
a = @images.values_at(*args)
|
1874
1807
|
a = self.class.new
|
1875
|
-
@images.values_at(*args).each {|image| a << image}
|
1808
|
+
@images.values_at(*args).each { |image| a << image }
|
1876
1809
|
a.scene = a.length - 1
|
1877
1810
|
a
|
1878
1811
|
end
|
1879
|
-
|
1880
|
-
|
1812
|
+
alias indexes values_at
|
1813
|
+
alias indices values_at
|
1881
1814
|
end # Magick::ImageList
|
1882
1815
|
|
1816
|
+
class Pixel
|
1817
|
+
# include Observable for Image::View class
|
1818
|
+
include Observable
|
1819
|
+
end
|
1820
|
+
|
1883
1821
|
# Collects non-specific optional method arguments
|
1884
1822
|
class OptionalMethodArguments
|
1885
1823
|
def initialize(img)
|
@@ -1914,21 +1852,21 @@ module Magick
|
|
1914
1852
|
# @dist is the number of pixels between hatch lines.
|
1915
1853
|
# See Magick::Draw examples.
|
1916
1854
|
class HatchFill
|
1917
|
-
def initialize(bgcolor, hatchcolor='white', dist=10)
|
1855
|
+
def initialize(bgcolor, hatchcolor = 'white', dist = 10)
|
1918
1856
|
@bgcolor = bgcolor
|
1919
|
-
@hatchpixel = Pixel.from_color(hatchcolor)
|
1857
|
+
@hatchpixel = hatchcolor.is_a?(Pixel) ? hatchcolor : Pixel.from_color(hatchcolor)
|
1920
1858
|
@dist = dist
|
1921
1859
|
end
|
1922
1860
|
|
1923
|
-
def fill(img)
|
1861
|
+
def fill(img) # required
|
1924
1862
|
img.background_color = @bgcolor
|
1925
|
-
img.erase!
|
1863
|
+
img.erase! # sets image to background color
|
1926
1864
|
pixels = Array.new([img.rows, img.columns].max, @hatchpixel)
|
1927
|
-
@dist.step((img.columns-1)
|
1928
|
-
img.store_pixels(x,0,1,img.rows,pixels)
|
1865
|
+
@dist.step((img.columns - 1) / @dist * @dist, @dist) do |x|
|
1866
|
+
img.store_pixels(x, 0, 1, img.rows, pixels)
|
1929
1867
|
end
|
1930
|
-
@dist.step((img.rows-1)
|
1931
|
-
img.store_pixels(0,y,img.columns,1,pixels)
|
1868
|
+
@dist.step((img.rows - 1) / @dist * @dist, @dist) do |y|
|
1869
|
+
img.store_pixels(0, y, img.columns, 1, pixels)
|
1932
1870
|
end
|
1933
1871
|
end
|
1934
1872
|
end
|