rmagick 2.16.0 → 5.3.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 +138 -0
- data/.gitignore +7 -1
- data/.rspec +1 -0
- data/.rubocop.yml +37 -340
- data/.rubocop_todo.yml +448 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +455 -0
- data/CODE_OF_CONDUCT.md +122 -7
- data/CONTRIBUTING.md +37 -6
- data/Gemfile +0 -6
- data/README.md +316 -0
- data/Rakefile +74 -100
- data/before_install_linux.sh +65 -28
- data/before_install_osx.sh +58 -2
- data/ext/RMagick/extconf.rb +287 -393
- data/ext/RMagick/rmagick.c +106 -111
- data/ext/RMagick/rmagick.h +235 -331
- data/ext/RMagick/rmagick_gvl.h +224 -0
- data/ext/RMagick/rmdraw.c +516 -843
- data/ext/RMagick/rmenum.c +316 -755
- data/ext/RMagick/rmfill.c +281 -191
- data/ext/RMagick/rmilist.c +451 -456
- data/ext/RMagick/rmimage.c +6250 -5290
- data/ext/RMagick/rminfo.c +721 -894
- data/ext/RMagick/rmkinfo.c +228 -0
- data/ext/RMagick/rmmain.c +735 -521
- data/ext/RMagick/rmmontage.c +127 -172
- data/ext/RMagick/rmpixel.c +638 -431
- data/ext/RMagick/rmstruct.c +102 -282
- data/ext/RMagick/rmutil.c +450 -363
- data/lib/rmagick/version.rb +5 -4
- data/lib/rmagick.rb +2 -0
- data/lib/rmagick_internal.rb +349 -413
- 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 +63 -68
- data/lib/rvg/misc.rb +136 -139
- data/lib/rvg/paint.rb +2 -1
- data/lib/rvg/pathdata.rb +7 -8
- data/lib/rvg/rvg.rb +47 -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 +16 -39
- metadata +114 -392
- 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/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',
|
@@ -210,12 +227,19 @@ module Magick
|
|
210
227
|
|
211
228
|
def enquote(str)
|
212
229
|
if str.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(str)
|
213
|
-
|
230
|
+
str
|
214
231
|
else
|
215
|
-
|
232
|
+
'"' + str + '"'
|
216
233
|
end
|
217
234
|
end
|
218
235
|
|
236
|
+
def check_opacity(opacity)
|
237
|
+
return if opacity.is_a?(String) && opacity['%']
|
238
|
+
|
239
|
+
value = Float(opacity)
|
240
|
+
Kernel.raise ArgumentError, 'opacity must be >= 0 and <= 1.0' if value < 0 || value > 1.0
|
241
|
+
end
|
242
|
+
|
219
243
|
public
|
220
244
|
|
221
245
|
# Apply coordinate transformations to support scaling (s), rotation (r),
|
@@ -224,25 +248,35 @@ module Magick
|
|
224
248
|
primitive 'affine ' + sprintf('%g,%g,%g,%g,%g,%g', sx, rx, ry, sy, tx, ty)
|
225
249
|
end
|
226
250
|
|
251
|
+
# Set alpha (make transparent) in image according to the specified
|
252
|
+
# colorization rule
|
253
|
+
def alpha(x, y, method)
|
254
|
+
Kernel.raise ArgumentError, 'Unknown paint method' unless PAINT_METHOD_NAMES.key?(method.to_i)
|
255
|
+
name = Gem::Version.new(Magick::IMAGEMAGICK_VERSION) > Gem::Version.new('7.0.0') ? 'alpha ' : 'matte '
|
256
|
+
primitive name + sprintf('%g,%g, %s', x, y, PAINT_METHOD_NAMES[method.to_i])
|
257
|
+
end
|
258
|
+
|
227
259
|
# Draw an arc.
|
228
|
-
def arc(
|
229
|
-
primitive 'arc ' + sprintf(
|
230
|
-
|
260
|
+
def arc(start_x, start_y, end_x, end_y, start_degrees, end_degrees)
|
261
|
+
primitive 'arc ' + sprintf(
|
262
|
+
'%g,%g %g,%g %g,%g',
|
263
|
+
start_x, start_y, end_x, end_y, start_degrees, end_degrees
|
264
|
+
)
|
231
265
|
end
|
232
266
|
|
233
267
|
# Draw a bezier curve.
|
234
268
|
def bezier(*points)
|
235
|
-
if points.length
|
269
|
+
if points.length.zero?
|
236
270
|
Kernel.raise ArgumentError, 'no points specified'
|
237
271
|
elsif points.length.odd?
|
238
272
|
Kernel.raise ArgumentError, 'odd number of arguments specified'
|
239
273
|
end
|
240
|
-
primitive 'bezier ' + points.join(',')
|
274
|
+
primitive 'bezier ' + points.map! { |x| sprintf('%g', x) }.join(',')
|
241
275
|
end
|
242
276
|
|
243
277
|
# Draw a circle
|
244
|
-
def circle(
|
245
|
-
primitive 'circle ' + sprintf('%g,%g %g,%g',
|
278
|
+
def circle(origin_x, origin_y, perim_x, perim_y)
|
279
|
+
primitive 'circle ' + sprintf('%g,%g %g,%g', origin_x, origin_y, perim_x, perim_y)
|
246
280
|
end
|
247
281
|
|
248
282
|
# Invoke a clip-path defined by def_clip_path.
|
@@ -252,33 +286,27 @@ module Magick
|
|
252
286
|
|
253
287
|
# Define the clipping rule.
|
254
288
|
def clip_rule(rule)
|
255
|
-
unless
|
256
|
-
Kernel.raise ArgumentError, "Unknown clipping rule #{rule}"
|
257
|
-
end
|
289
|
+
Kernel.raise ArgumentError, "Unknown clipping rule #{rule}" unless %w[evenodd nonzero].include?(rule.downcase)
|
258
290
|
primitive "clip-rule #{rule}"
|
259
291
|
end
|
260
292
|
|
261
293
|
# Define the clip units
|
262
294
|
def clip_units(unit)
|
263
|
-
unless
|
264
|
-
Kernel.raise ArgumentError, "Unknown clip unit #{unit}"
|
265
|
-
end
|
295
|
+
Kernel.raise ArgumentError, "Unknown clip unit #{unit}" unless %w[userspace userspaceonuse objectboundingbox].include?(unit.downcase)
|
266
296
|
primitive "clip-units #{unit}"
|
267
297
|
end
|
268
298
|
|
269
299
|
# Set color in image according to specified colorization rule. Rule is one of
|
270
300
|
# point, replace, floodfill, filltoborder,reset
|
271
301
|
def color(x, y, method)
|
272
|
-
unless
|
273
|
-
|
274
|
-
end
|
275
|
-
primitive "color #{x},#{y},#{PAINT_METHOD_NAMES[method.to_i]}"
|
302
|
+
Kernel.raise ArgumentError, "Unknown PaintMethod: #{method}" unless PAINT_METHOD_NAMES.key?(method.to_i)
|
303
|
+
primitive 'color ' + sprintf('%g,%g,%s', x, y, PAINT_METHOD_NAMES[method.to_i])
|
276
304
|
end
|
277
305
|
|
278
306
|
# Specify EITHER the text decoration (none, underline, overline,
|
279
307
|
# line-through) OR the text solid background color (any color name or spec)
|
280
308
|
def decorate(decoration)
|
281
|
-
if
|
309
|
+
if DECORATION_TYPE_NAMES.key?(decoration.to_i)
|
282
310
|
primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}"
|
283
311
|
else
|
284
312
|
primitive "decorate #{enquote(decoration)}"
|
@@ -292,7 +320,7 @@ module Magick
|
|
292
320
|
# (pop) graphic-context".
|
293
321
|
def define_clip_path(name)
|
294
322
|
push('defs')
|
295
|
-
push(
|
323
|
+
push("clip-path \"#{name}\"")
|
296
324
|
push('graphic-context')
|
297
325
|
yield
|
298
326
|
ensure
|
@@ -302,9 +330,11 @@ module Magick
|
|
302
330
|
end
|
303
331
|
|
304
332
|
# Draw an ellipse
|
305
|
-
def ellipse(
|
306
|
-
primitive 'ellipse ' + sprintf(
|
307
|
-
|
333
|
+
def ellipse(origin_x, origin_y, width, height, arc_start, arc_end)
|
334
|
+
primitive 'ellipse ' + sprintf(
|
335
|
+
'%g,%g %g,%g %g,%g',
|
336
|
+
origin_x, origin_y, width, height, arc_start, arc_end
|
337
|
+
)
|
308
338
|
end
|
309
339
|
|
310
340
|
# Let anything through, but the only defined argument
|
@@ -317,18 +347,17 @@ module Magick
|
|
317
347
|
def fill(colorspec)
|
318
348
|
primitive "fill #{enquote(colorspec)}"
|
319
349
|
end
|
320
|
-
|
321
|
-
|
350
|
+
alias fill_color fill
|
351
|
+
alias fill_pattern fill
|
322
352
|
|
323
353
|
# Specify fill opacity (use "xx%" to indicate percentage)
|
324
354
|
def fill_opacity(opacity)
|
355
|
+
check_opacity(opacity)
|
325
356
|
primitive "fill-opacity #{opacity}"
|
326
357
|
end
|
327
358
|
|
328
359
|
def fill_rule(rule)
|
329
|
-
unless
|
330
|
-
Kernel.raise ArgumentError, "Unknown fill rule #{rule}"
|
331
|
-
end
|
360
|
+
Kernel.raise ArgumentError, "Unknown fill rule #{rule}" unless %w[evenodd nonzero].include?(rule.downcase)
|
332
361
|
primitive "fill-rule #{rule}"
|
333
362
|
end
|
334
363
|
|
@@ -342,38 +371,38 @@ module Magick
|
|
342
371
|
end
|
343
372
|
|
344
373
|
def font_stretch(stretch)
|
345
|
-
unless
|
346
|
-
Kernel.raise ArgumentError, 'Unknown stretch type'
|
347
|
-
end
|
374
|
+
Kernel.raise ArgumentError, 'Unknown stretch type' unless STRETCH_TYPE_NAMES.key?(stretch.to_i)
|
348
375
|
primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}"
|
349
376
|
end
|
350
377
|
|
351
378
|
def font_style(style)
|
352
|
-
unless
|
353
|
-
Kernel.raise ArgumentError, 'Unknown style type'
|
354
|
-
end
|
379
|
+
Kernel.raise ArgumentError, 'Unknown style type' unless STYLE_TYPE_NAMES.key?(style.to_i)
|
355
380
|
primitive "font-style #{STYLE_TYPE_NAMES[style.to_i]}"
|
356
381
|
end
|
357
382
|
|
358
383
|
# The font weight argument can be either a font weight
|
359
384
|
# constant or [100,200,...,900]
|
360
385
|
def font_weight(weight)
|
361
|
-
if
|
386
|
+
if weight.is_a?(WeightType)
|
362
387
|
primitive "font-weight #{FONT_WEIGHT_NAMES[weight.to_i]}"
|
363
388
|
else
|
364
|
-
primitive "font-weight #{weight}"
|
389
|
+
primitive "font-weight #{Integer(weight)}"
|
365
390
|
end
|
366
391
|
end
|
367
392
|
|
368
393
|
# Specify the text positioning gravity, one of:
|
369
394
|
# NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
|
370
395
|
def gravity(grav)
|
371
|
-
unless
|
372
|
-
Kernel.raise ArgumentError, 'Unknown text positioning gravity'
|
373
|
-
end
|
396
|
+
Kernel.raise ArgumentError, 'Unknown text positioning gravity' unless GRAVITY_NAMES.key?(grav.to_i)
|
374
397
|
primitive "gravity #{GRAVITY_NAMES[grav.to_i]}"
|
375
398
|
end
|
376
399
|
|
400
|
+
def image(composite, x, y, width, height, image_file_path)
|
401
|
+
Kernel.raise ArgumentError, 'Unknown composite' unless composite.is_a?(CompositeOperator)
|
402
|
+
composite_name = composite.to_s.sub!('CompositeOp', '')
|
403
|
+
primitive 'image ' + sprintf('%s %g,%g %g,%g %s', composite_name, x, y, width, height, enquote(image_file_path))
|
404
|
+
end
|
405
|
+
|
377
406
|
# IM 6.5.5-8 and later
|
378
407
|
def interline_spacing(space)
|
379
408
|
begin
|
@@ -411,27 +440,14 @@ module Magick
|
|
411
440
|
end
|
412
441
|
|
413
442
|
# 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]}"
|
443
|
+
def line(start_x, start_y, end_x, end_y)
|
444
|
+
primitive 'line ' + sprintf('%g,%g %g,%g', start_x, start_y, end_x, end_y)
|
425
445
|
end
|
426
446
|
|
427
447
|
# Specify drawing fill and stroke opacities. If the value is a string
|
428
448
|
# ending with a %, the number will be multiplied by 0.01.
|
429
449
|
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
|
450
|
+
check_opacity(opacity)
|
435
451
|
primitive "opacity #{opacity}"
|
436
452
|
end
|
437
453
|
|
@@ -447,7 +463,7 @@ module Magick
|
|
447
463
|
# as the argument to the 'fill' or 'stroke' methods
|
448
464
|
def pattern(name, x, y, width, height)
|
449
465
|
push('defs')
|
450
|
-
push("pattern #{name}
|
466
|
+
push("pattern #{name} " + sprintf('%g %g %g %g', x, y, width, height))
|
451
467
|
push('graphic-context')
|
452
468
|
yield
|
453
469
|
ensure
|
@@ -458,34 +474,34 @@ module Magick
|
|
458
474
|
|
459
475
|
# Set point to fill color.
|
460
476
|
def point(x, y)
|
461
|
-
primitive
|
477
|
+
primitive 'point ' + sprintf('%g,%g', x, y)
|
462
478
|
end
|
463
479
|
|
464
480
|
# Specify the font size in points. Yes, the primitive is "font-size" but
|
465
481
|
# in other places this value is called the "pointsize". Give it both names.
|
466
482
|
def pointsize(points)
|
467
|
-
primitive
|
483
|
+
primitive 'font-size ' + sprintf('%g', points)
|
468
484
|
end
|
469
|
-
|
485
|
+
alias font_size pointsize
|
470
486
|
|
471
487
|
# Draw a polygon
|
472
488
|
def polygon(*points)
|
473
|
-
if points.length
|
489
|
+
if points.length.zero?
|
474
490
|
Kernel.raise ArgumentError, 'no points specified'
|
475
491
|
elsif points.length.odd?
|
476
492
|
Kernel.raise ArgumentError, 'odd number of points specified'
|
477
493
|
end
|
478
|
-
primitive 'polygon ' + points.join(',')
|
494
|
+
primitive 'polygon ' + points.map! { |x| sprintf('%g', x) }.join(',')
|
479
495
|
end
|
480
496
|
|
481
497
|
# Draw a polyline
|
482
498
|
def polyline(*points)
|
483
|
-
if points.length
|
499
|
+
if points.length.zero?
|
484
500
|
Kernel.raise ArgumentError, 'no points specified'
|
485
501
|
elsif points.length.odd?
|
486
502
|
Kernel.raise ArgumentError, 'odd number of points specified'
|
487
503
|
end
|
488
|
-
primitive 'polyline ' + points.join(',')
|
504
|
+
primitive 'polyline ' + points.map! { |x| sprintf('%g', x) }.join(',')
|
489
505
|
end
|
490
506
|
|
491
507
|
# Return to the previously-saved set of whatever
|
@@ -495,11 +511,11 @@ module Magick
|
|
495
511
|
# pop('pattern')
|
496
512
|
|
497
513
|
def pop(*what)
|
498
|
-
if what.length
|
514
|
+
if what.length.zero?
|
499
515
|
primitive 'pop graphic-context'
|
500
516
|
else
|
501
517
|
# to_s allows a Symbol to be used instead of a String
|
502
|
-
primitive 'pop ' + what.map
|
518
|
+
primitive 'pop ' + what.map(&:to_s).join(' ')
|
503
519
|
end
|
504
520
|
end
|
505
521
|
|
@@ -509,50 +525,54 @@ module Magick
|
|
509
525
|
# push('gradient')
|
510
526
|
# push('pattern')
|
511
527
|
def push(*what)
|
512
|
-
if what.length
|
528
|
+
if what.length.zero?
|
513
529
|
primitive 'push graphic-context'
|
514
530
|
else
|
515
531
|
# to_s allows a Symbol to be used instead of a String
|
516
|
-
primitive 'push ' + what.map
|
532
|
+
primitive 'push ' + what.map(&:to_s).join(' ')
|
517
533
|
end
|
518
534
|
end
|
519
535
|
|
520
536
|
# Draw a rectangle
|
521
537
|
def rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y)
|
522
|
-
primitive 'rectangle ' + sprintf(
|
523
|
-
|
538
|
+
primitive 'rectangle ' + sprintf(
|
539
|
+
'%g,%g %g,%g',
|
540
|
+
upper_left_x, upper_left_y, lower_right_x, lower_right_y
|
541
|
+
)
|
524
542
|
end
|
525
543
|
|
526
544
|
# Specify coordinate space rotation. "angle" is measured in degrees
|
527
545
|
def rotate(angle)
|
528
|
-
primitive
|
546
|
+
primitive 'rotate ' + sprintf('%g', angle)
|
529
547
|
end
|
530
548
|
|
531
549
|
# Draw a rectangle with rounded corners
|
532
550
|
def roundrectangle(center_x, center_y, width, height, corner_width, corner_height)
|
533
|
-
primitive 'roundrectangle ' + sprintf(
|
534
|
-
|
551
|
+
primitive 'roundrectangle ' + sprintf(
|
552
|
+
'%g,%g,%g,%g,%g,%g',
|
553
|
+
center_x, center_y, width, height, corner_width, corner_height
|
554
|
+
)
|
535
555
|
end
|
536
556
|
|
537
557
|
# Specify scaling to be applied to coordinate space on subsequent drawing commands.
|
538
558
|
def scale(x, y)
|
539
|
-
primitive
|
559
|
+
primitive 'scale ' + sprintf('%g,%g', x, y)
|
540
560
|
end
|
541
561
|
|
542
562
|
def skewx(angle)
|
543
|
-
primitive
|
563
|
+
primitive 'skewX ' + sprintf('%g', angle)
|
544
564
|
end
|
545
565
|
|
546
566
|
def skewy(angle)
|
547
|
-
primitive
|
567
|
+
primitive 'skewY ' + sprintf('%g', angle)
|
548
568
|
end
|
549
569
|
|
550
570
|
# Specify the object stroke, a color name or pattern name.
|
551
571
|
def stroke(colorspec)
|
552
572
|
primitive "stroke #{enquote(colorspec)}"
|
553
573
|
end
|
554
|
-
|
555
|
-
|
574
|
+
alias stroke_color stroke
|
575
|
+
alias stroke_pattern stroke
|
556
576
|
|
557
577
|
# Specify if stroke should be antialiased or not
|
558
578
|
def stroke_antialias(bool)
|
@@ -562,88 +582,75 @@ module Magick
|
|
562
582
|
|
563
583
|
# Specify a stroke dash pattern
|
564
584
|
def stroke_dasharray(*list)
|
565
|
-
if list.length
|
585
|
+
if list.length.zero?
|
566
586
|
primitive 'stroke-dasharray none'
|
567
587
|
else
|
568
588
|
list.each do |x|
|
569
|
-
if x <= 0
|
570
|
-
Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)"
|
571
|
-
end
|
589
|
+
Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)" if x <= 0
|
572
590
|
end
|
573
591
|
primitive "stroke-dasharray #{list.join(',')}"
|
574
592
|
end
|
575
593
|
end
|
576
594
|
|
577
595
|
# Specify the initial offset in the dash pattern
|
578
|
-
def stroke_dashoffset(value=0)
|
579
|
-
primitive
|
596
|
+
def stroke_dashoffset(value = 0)
|
597
|
+
primitive 'stroke-dashoffset ' + sprintf('%g', value)
|
580
598
|
end
|
581
599
|
|
582
600
|
def stroke_linecap(value)
|
583
|
-
unless
|
584
|
-
Kernel.raise ArgumentError, "Unknown linecap type: #{value}"
|
585
|
-
end
|
601
|
+
Kernel.raise ArgumentError, "Unknown linecap type: #{value}" unless %w[butt round square].include?(value.downcase)
|
586
602
|
primitive "stroke-linecap #{value}"
|
587
603
|
end
|
588
604
|
|
589
605
|
def stroke_linejoin(value)
|
590
|
-
unless
|
591
|
-
Kernel.raise ArgumentError, "Unknown linejoin type: #{value}"
|
592
|
-
end
|
606
|
+
Kernel.raise ArgumentError, "Unknown linejoin type: #{value}" unless %w[round miter bevel].include?(value.downcase)
|
593
607
|
primitive "stroke-linejoin #{value}"
|
594
608
|
end
|
595
609
|
|
596
610
|
def stroke_miterlimit(value)
|
597
|
-
if value < 1
|
598
|
-
Kernel.raise ArgumentError, 'miterlimit must be >= 1'
|
599
|
-
end
|
611
|
+
Kernel.raise ArgumentError, 'miterlimit must be >= 1' if value < 1
|
600
612
|
primitive "stroke-miterlimit #{value}"
|
601
613
|
end
|
602
614
|
|
603
615
|
# Specify opacity of stroke drawing color
|
604
616
|
# (use "xx%" to indicate percentage)
|
605
|
-
def stroke_opacity(
|
606
|
-
|
617
|
+
def stroke_opacity(opacity)
|
618
|
+
check_opacity(opacity)
|
619
|
+
primitive "stroke-opacity #{opacity}"
|
607
620
|
end
|
608
621
|
|
609
622
|
# Specify stroke (outline) width in pixels.
|
610
623
|
def stroke_width(pixels)
|
611
|
-
primitive
|
624
|
+
primitive 'stroke-width ' + sprintf('%g', pixels)
|
612
625
|
end
|
613
626
|
|
614
627
|
# Draw text at position x,y. Add quotes to text that is not already quoted.
|
615
628
|
def text(x, y, text)
|
616
|
-
if text.to_s.empty?
|
617
|
-
Kernel.raise ArgumentError, 'missing text argument'
|
618
|
-
end
|
629
|
+
Kernel.raise ArgumentError, 'missing text argument' if text.to_s.empty?
|
619
630
|
if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
|
620
|
-
|
631
|
+
# text already quoted
|
621
632
|
elsif !text['\'']
|
622
|
-
text = '\''+text+'\''
|
633
|
+
text = '\'' + text + '\''
|
623
634
|
elsif !text['"']
|
624
|
-
text = '"'+text+'"'
|
635
|
+
text = '"' + text + '"'
|
625
636
|
elsif !(text['{'] || text['}'])
|
626
|
-
text = '{'+text+'}'
|
637
|
+
text = '{' + text + '}'
|
627
638
|
else
|
628
639
|
# escape existing braces, surround with braces
|
629
|
-
text = '{' +
|
640
|
+
text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
|
630
641
|
end
|
631
|
-
primitive
|
642
|
+
primitive 'text ' + sprintf('%g,%g %s', x, y, text)
|
632
643
|
end
|
633
644
|
|
634
645
|
# Specify text alignment relative to a given point
|
635
646
|
def text_align(alignment)
|
636
|
-
unless
|
637
|
-
Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}"
|
638
|
-
end
|
647
|
+
Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}" unless ALIGN_TYPE_NAMES.key?(alignment.to_i)
|
639
648
|
primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}"
|
640
649
|
end
|
641
650
|
|
642
651
|
# SVG-compatible version of text_align
|
643
652
|
def text_anchor(anchor)
|
644
|
-
unless
|
645
|
-
Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}"
|
646
|
-
end
|
653
|
+
Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}" unless ANCHOR_TYPE_NAMES.key?(anchor.to_i)
|
647
654
|
primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}"
|
648
655
|
end
|
649
656
|
|
@@ -661,7 +668,7 @@ module Magick
|
|
661
668
|
# Specify center of coordinate space to use for subsequent drawing
|
662
669
|
# commands.
|
663
670
|
def translate(x, y)
|
664
|
-
primitive
|
671
|
+
primitive 'translate ' + sprintf('%g,%g', x, y)
|
665
672
|
end
|
666
673
|
end # class Magick::Draw
|
667
674
|
|
@@ -764,19 +771,13 @@ module Magick
|
|
764
771
|
module Post_ObjectData_Descriptor
|
765
772
|
Confirmed_ObjectData_Size = '9:10'
|
766
773
|
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
774
|
end # module Magick::IPTC
|
774
775
|
|
775
776
|
# Ruby-level Magick::Image methods
|
776
777
|
class Image
|
777
778
|
include Comparable
|
778
779
|
|
779
|
-
|
780
|
+
alias affinity remap
|
780
781
|
|
781
782
|
# Provide an alternate version of Draw#annotate, for folks who
|
782
783
|
# want to find it in this class.
|
@@ -830,7 +831,7 @@ module Magick
|
|
830
831
|
# Thanks to Russell Norris!
|
831
832
|
def each_pixel
|
832
833
|
get_pixels(0, 0, columns, rows).each_with_index do |p, n|
|
833
|
-
yield(p, n%columns, n/columns)
|
834
|
+
yield(p, n % columns, n / columns)
|
834
835
|
end
|
835
836
|
self
|
836
837
|
end
|
@@ -841,13 +842,11 @@ module Magick
|
|
841
842
|
# arrays.
|
842
843
|
def get_exif_by_entry(*entry)
|
843
844
|
ary = []
|
844
|
-
if entry.length
|
845
|
+
if entry.length.zero?
|
845
846
|
exif_data = self['EXIF:*']
|
846
|
-
if exif_data
|
847
|
-
exif_data.split("\n").each { |exif| ary.push(exif.split('=')) }
|
848
|
-
end
|
847
|
+
exif_data.split("\n").each { |exif| ary.push(exif.split('=')) } if exif_data
|
849
848
|
else
|
850
|
-
get_exif_by_entry
|
849
|
+
get_exif_by_entry # ensure properties is populated with exif data
|
851
850
|
entry.each do |name|
|
852
851
|
rval = self["EXIF:#{name}"]
|
853
852
|
ary.push([name, rval])
|
@@ -859,19 +858,19 @@ module Magick
|
|
859
858
|
# Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
|
860
859
|
def get_exif_by_number(*tag)
|
861
860
|
hash = {}
|
862
|
-
if tag.length
|
861
|
+
if tag.length.zero?
|
863
862
|
exif_data = self['EXIF:!']
|
864
863
|
if exif_data
|
865
864
|
exif_data.split("\n").each do |exif|
|
866
865
|
tag, value = exif.split('=')
|
867
|
-
tag = tag[1,4].hex
|
866
|
+
tag = tag[1, 4].hex
|
868
867
|
hash[tag] = value
|
869
868
|
end
|
870
869
|
end
|
871
870
|
else
|
872
|
-
get_exif_by_number
|
871
|
+
get_exif_by_number # ensure properties is populated with exif data
|
873
872
|
tag.each do |num|
|
874
|
-
rval = self['#%04X'
|
873
|
+
rval = self[sprintf('#%04X', num.to_i)]
|
875
874
|
hash[num] = rval == 'unknown' ? nil : rval
|
876
875
|
end
|
877
876
|
end
|
@@ -881,7 +880,7 @@ module Magick
|
|
881
880
|
# Retrieve IPTC information by record number:dataset tag constant defined in
|
882
881
|
# Magick::IPTC, above.
|
883
882
|
def get_iptc_dataset(ds)
|
884
|
-
self['IPTC:'+ds]
|
883
|
+
self['IPTC:' + ds]
|
885
884
|
end
|
886
885
|
|
887
886
|
# Iterate over IPTC record number:dataset tags, yield for each non-nil dataset
|
@@ -909,7 +908,7 @@ module Magick
|
|
909
908
|
# look like they're in the old order.
|
910
909
|
|
911
910
|
# (Thanks to Al Evans for the suggestion.)
|
912
|
-
def level(black_point=0.0, white_point=nil, gamma=nil)
|
911
|
+
def level(black_point = 0.0, white_point = nil, gamma = nil)
|
913
912
|
black_point = Float(black_point)
|
914
913
|
|
915
914
|
white_point ||= Magick::QuantumRange - black_point
|
@@ -921,9 +920,7 @@ module Magick
|
|
921
920
|
|
922
921
|
if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs
|
923
922
|
gamma, white_point = white_point, gamma
|
924
|
-
unless gamma_arg
|
925
|
-
white_point = Magick::QuantumRange - black_point
|
926
|
-
end
|
923
|
+
white_point = Magick::QuantumRange - black_point unless gamma_arg
|
927
924
|
end
|
928
925
|
|
929
926
|
level2(black_point, white_point, gamma)
|
@@ -936,9 +933,9 @@ module Magick
|
|
936
933
|
# Make the pixel at (x,y) transparent.
|
937
934
|
def matte_point(x, y)
|
938
935
|
f = copy
|
939
|
-
f.
|
940
|
-
pixel = f.pixel_color(x,y)
|
941
|
-
pixel.
|
936
|
+
f.alpha(OpaqueAlphaChannel) unless f.alpha?
|
937
|
+
pixel = f.pixel_color(x, y)
|
938
|
+
pixel.alpha = TransparentAlpha
|
942
939
|
f.pixel_color(x, y, pixel)
|
943
940
|
f
|
944
941
|
end
|
@@ -947,7 +944,7 @@ module Magick
|
|
947
944
|
# pixel at (x, y).
|
948
945
|
def matte_replace(x, y)
|
949
946
|
f = copy
|
950
|
-
f.
|
947
|
+
f.alpha(OpaqueAlphaChannel) unless f.alpha?
|
951
948
|
target = f.pixel_color(x, y)
|
952
949
|
f.transparent(target)
|
953
950
|
end
|
@@ -956,56 +953,54 @@ module Magick
|
|
956
953
|
# at (x,y) and is a neighbor.
|
957
954
|
def matte_floodfill(x, y)
|
958
955
|
f = copy
|
959
|
-
f.
|
956
|
+
f.alpha(OpaqueAlphaChannel) unless f.alpha?
|
960
957
|
target = f.pixel_color(x, y)
|
961
|
-
f.matte_flood_fill(target,
|
962
|
-
x, y, FloodfillMethod)
|
958
|
+
f.matte_flood_fill(target, x, y, FloodfillMethod, alpha: TransparentAlpha)
|
963
959
|
end
|
964
960
|
|
965
961
|
# Make transparent any neighbor pixel that is not the border color.
|
966
962
|
def matte_fill_to_border(x, y)
|
967
963
|
f = copy
|
968
|
-
f.
|
969
|
-
f.matte_flood_fill(border_color,
|
970
|
-
x, y, FillToBorderMethod)
|
964
|
+
f.alpha(OpaqueAlphaChannel) unless f.alpha?
|
965
|
+
f.matte_flood_fill(border_color, x, y, FillToBorderMethod, alpha: TransparentAlpha)
|
971
966
|
end
|
972
967
|
|
973
968
|
# Make all pixels transparent.
|
974
969
|
def matte_reset!
|
975
|
-
|
970
|
+
alpha(TransparentAlphaChannel)
|
976
971
|
self
|
977
972
|
end
|
978
973
|
|
979
974
|
# Force an image to exact dimensions without changing the aspect ratio.
|
980
975
|
# Resize and crop if necessary. (Thanks to Jerett Taylor!)
|
981
|
-
def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity)
|
976
|
+
def resize_to_fill(ncols, nrows = nil, gravity = CenterGravity)
|
982
977
|
copy.resize_to_fill!(ncols, nrows, gravity)
|
983
978
|
end
|
984
979
|
|
985
|
-
def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity)
|
980
|
+
def resize_to_fill!(ncols, nrows = nil, gravity = CenterGravity)
|
986
981
|
nrows ||= ncols
|
987
982
|
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)
|
983
|
+
scale = [ncols / columns.to_f, nrows / rows.to_f].max
|
984
|
+
resize!(scale * columns + 0.5, scale * rows + 0.5)
|
990
985
|
end
|
991
986
|
crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows
|
992
987
|
self
|
993
988
|
end
|
994
989
|
|
995
990
|
# Preserve aliases used < RMagick 2.0.1
|
996
|
-
|
997
|
-
|
991
|
+
alias crop_resized resize_to_fill
|
992
|
+
alias crop_resized! resize_to_fill!
|
998
993
|
|
999
994
|
# Convenience method to resize retaining the aspect ratio.
|
1000
995
|
# (Thanks to Robert Manni!)
|
1001
|
-
def resize_to_fit(cols, rows=nil)
|
996
|
+
def resize_to_fit(cols, rows = nil)
|
1002
997
|
rows ||= cols
|
1003
998
|
change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
|
1004
999
|
resize(ncols, nrows)
|
1005
1000
|
end
|
1006
1001
|
end
|
1007
1002
|
|
1008
|
-
def resize_to_fit!(cols, rows=nil)
|
1003
|
+
def resize_to_fit!(cols, rows = nil)
|
1009
1004
|
rows ||= cols
|
1010
1005
|
change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
|
1011
1006
|
resize!(ncols, nrows)
|
@@ -1028,16 +1023,14 @@ module Magick
|
|
1028
1023
|
def view(x, y, width, height)
|
1029
1024
|
view = View.new(self, x, y, width, height)
|
1030
1025
|
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
return nil
|
1038
|
-
else
|
1039
|
-
return view
|
1026
|
+
return view unless block_given?
|
1027
|
+
|
1028
|
+
begin
|
1029
|
+
yield(view)
|
1030
|
+
ensure
|
1031
|
+
view.sync
|
1040
1032
|
end
|
1033
|
+
nil
|
1041
1034
|
end
|
1042
1035
|
|
1043
1036
|
# Magick::Image::View class
|
@@ -1047,12 +1040,8 @@ module Magick
|
|
1047
1040
|
|
1048
1041
|
def initialize(img, x, y, width, height)
|
1049
1042
|
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
|
1043
|
+
Kernel.raise ArgumentError, "invalid geometry (#{width}x#{height}+#{x}+#{y})" if width <= 0 || height <= 0
|
1044
|
+
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
1045
|
@view = img.get_pixels(x, y, width, height)
|
1057
1046
|
@img = img
|
1058
1047
|
@x = x
|
@@ -1069,7 +1058,7 @@ module Magick
|
|
1069
1058
|
end
|
1070
1059
|
|
1071
1060
|
# Store changed pixels back to image
|
1072
|
-
def sync(force=false)
|
1061
|
+
def sync(force = false)
|
1073
1062
|
@img.store_pixels(x, y, width, height, @view) if @dirty || force
|
1074
1063
|
@dirty || force
|
1075
1064
|
end
|
@@ -1078,7 +1067,7 @@ module Magick
|
|
1078
1067
|
# true, don't change it back to false!
|
1079
1068
|
def update(rows)
|
1080
1069
|
@dirty = true
|
1081
|
-
rows.delete_observer(self)
|
1070
|
+
rows.delete_observer(self) # No need to tell us again.
|
1082
1071
|
nil
|
1083
1072
|
end
|
1084
1073
|
|
@@ -1088,8 +1077,8 @@ module Magick
|
|
1088
1077
|
include Observable
|
1089
1078
|
|
1090
1079
|
# Define a getter and a setter for each channel.
|
1091
|
-
[
|
1092
|
-
module_eval <<-END_EVAL
|
1080
|
+
%i[red green blue opacity].each do |c|
|
1081
|
+
module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
1093
1082
|
def #{c}
|
1094
1083
|
return collect { |p| p.#{c} }
|
1095
1084
|
end
|
@@ -1099,7 +1088,7 @@ module Magick
|
|
1099
1088
|
notify_observers(self)
|
1100
1089
|
nil
|
1101
1090
|
end
|
1102
|
-
|
1091
|
+
END_EVAL
|
1103
1092
|
end
|
1104
1093
|
end # class Magick::Image::View::Pixels
|
1105
1094
|
|
@@ -1119,7 +1108,7 @@ module Magick
|
|
1119
1108
|
|
1120
1109
|
# Both View::Pixels and Magick::Pixel implement Observable
|
1121
1110
|
if @unique
|
1122
|
-
pixels = @view[@rows[0]
|
1111
|
+
pixels = @view[@rows[0] * @width + @cols[0]]
|
1123
1112
|
pixels.add_observer(self)
|
1124
1113
|
else
|
1125
1114
|
pixels = View::Pixels.new
|
@@ -1133,8 +1122,8 @@ module Magick
|
|
1133
1122
|
end
|
1134
1123
|
|
1135
1124
|
def []=(*args)
|
1136
|
-
rv = args.delete_at(-1)
|
1137
|
-
unless rv.is_a?(Pixel)
|
1125
|
+
rv = args.delete_at(-1) # get rvalue
|
1126
|
+
unless rv.is_a?(Pixel) # must be a Pixel or a color name
|
1138
1127
|
begin
|
1139
1128
|
rv = Pixel.from_color(rv)
|
1140
1129
|
rescue TypeError
|
@@ -1145,7 +1134,6 @@ module Magick
|
|
1145
1134
|
each { |x| @view[x] = rv.dup }
|
1146
1135
|
changed
|
1147
1136
|
notify_observers(self)
|
1148
|
-
nil
|
1149
1137
|
end
|
1150
1138
|
|
1151
1139
|
# A pixel has been modified. Tell the view.
|
@@ -1159,7 +1147,7 @@ module Magick
|
|
1159
1147
|
private
|
1160
1148
|
|
1161
1149
|
def cols(*args)
|
1162
|
-
@cols = args[0]
|
1150
|
+
@cols = args[0] # remove the outermost array
|
1163
1151
|
@unique = false
|
1164
1152
|
|
1165
1153
|
# Convert @rows to an Enumerable object
|
@@ -1173,12 +1161,8 @@ module Magick
|
|
1173
1161
|
@rows = @rows.first
|
1174
1162
|
else
|
1175
1163
|
@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
|
1164
|
+
@rows += @height if @rows < 0
|
1165
|
+
Kernel.raise IndexError, "index [#{@rows}] out of range" if @rows < 0 || @rows > @height - 1
|
1182
1166
|
# Convert back to an array
|
1183
1167
|
@rows = Array.new(1, @rows)
|
1184
1168
|
@unique = true
|
@@ -1189,27 +1173,23 @@ module Magick
|
|
1189
1173
|
length = Integer(@rows[1])
|
1190
1174
|
|
1191
1175
|
# Negative start -> start from last row
|
1192
|
-
if start < 0
|
1193
|
-
start += @height
|
1194
|
-
end
|
1176
|
+
start += @height if start < 0
|
1195
1177
|
|
1196
1178
|
if start > @height || start < 0 || length < 0
|
1197
1179
|
Kernel.raise IndexError, "index [#{@rows.first}] out of range"
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
length = [length, 0].max
|
1202
|
-
end
|
1180
|
+
elsif start + length > @height
|
1181
|
+
length = @height - length
|
1182
|
+
length = [length, 0].max
|
1203
1183
|
end
|
1204
1184
|
# Create a Range for the specified set of rows
|
1205
|
-
@rows = Range.new(start, start+length, true)
|
1185
|
+
@rows = Range.new(start, start + length, true)
|
1206
1186
|
end
|
1207
1187
|
|
1208
1188
|
case @cols.length
|
1209
|
-
when 0
|
1210
|
-
@cols = Range.new(0, @width, true)
|
1189
|
+
when 0 # all rows
|
1190
|
+
@cols = Range.new(0, @width, true) # convert to range
|
1211
1191
|
@unique = false
|
1212
|
-
when 1
|
1192
|
+
when 1 # Range, Array, or a single integer
|
1213
1193
|
# if the single element is already an Enumerable
|
1214
1194
|
# object, get it.
|
1215
1195
|
if @cols.first.respond_to? :each
|
@@ -1217,12 +1197,8 @@ module Magick
|
|
1217
1197
|
@unique = false
|
1218
1198
|
else
|
1219
1199
|
@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
|
1200
|
+
@cols += @width if @cols < 0
|
1201
|
+
Kernel.raise IndexError, "index [#{@cols}] out of range" if @cols < 0 || @cols > @width - 1
|
1226
1202
|
# Convert back to array
|
1227
1203
|
@cols = Array.new(1, @cols)
|
1228
1204
|
@unique &&= true
|
@@ -1233,20 +1209,16 @@ module Magick
|
|
1233
1209
|
length = Integer(@cols[1])
|
1234
1210
|
|
1235
1211
|
# Negative start -> start from last row
|
1236
|
-
if start < 0
|
1237
|
-
start += @width
|
1238
|
-
end
|
1212
|
+
start += @width if start < 0
|
1239
1213
|
|
1240
1214
|
if start > @width || start < 0 || length < 0
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
length = [length, 0].max
|
1246
|
-
end
|
1215
|
+
# nop
|
1216
|
+
elsif start + length > @width
|
1217
|
+
length = @width - length
|
1218
|
+
length = [length, 0].max
|
1247
1219
|
end
|
1248
1220
|
# Create a Range for the specified set of columns
|
1249
|
-
@cols = Range.new(start, start+length, true)
|
1221
|
+
@cols = Range.new(start, start + length, true)
|
1250
1222
|
@unique = false
|
1251
1223
|
end
|
1252
1224
|
end
|
@@ -1257,20 +1229,16 @@ module Magick
|
|
1257
1229
|
maxcols = @width - 1
|
1258
1230
|
|
1259
1231
|
@rows.each do |j|
|
1260
|
-
if j > maxrows
|
1261
|
-
Kernel.raise IndexError, "index [#{j}] out of range"
|
1262
|
-
end
|
1232
|
+
Kernel.raise IndexError, "index [#{j}] out of range" if j > maxrows
|
1263
1233
|
@cols.each do |i|
|
1264
|
-
if i > maxcols
|
1265
|
-
|
1266
|
-
end
|
1267
|
-
yield j*@width + i
|
1234
|
+
Kernel.raise IndexError, "index [#{i}] out of range" if i > maxcols
|
1235
|
+
yield j * @width + i
|
1268
1236
|
end
|
1269
1237
|
end
|
1270
|
-
nil
|
1238
|
+
nil # useless return value
|
1271
1239
|
end
|
1272
1240
|
end # class Magick::Image::View::Rows
|
1273
|
-
end
|
1241
|
+
end # class Magick::Image::View
|
1274
1242
|
end # class Magick::Image
|
1275
1243
|
|
1276
1244
|
class ImageList
|
@@ -1281,31 +1249,27 @@ module Magick
|
|
1281
1249
|
private
|
1282
1250
|
|
1283
1251
|
def get_current
|
1284
|
-
|
1252
|
+
@images[@scene].__id__
|
1253
|
+
rescue StandardError
|
1254
|
+
nil
|
1285
1255
|
end
|
1286
1256
|
|
1287
1257
|
protected
|
1288
1258
|
|
1289
|
-
def
|
1290
|
-
unless obj.is_a? Magick::Image
|
1291
|
-
Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)"
|
1292
|
-
end
|
1293
|
-
true
|
1259
|
+
def assert_image(obj)
|
1260
|
+
Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)" unless obj.is_a? Magick::Image
|
1294
1261
|
end
|
1295
1262
|
|
1296
1263
|
# 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
|
1264
|
+
def assert_image_array(ary)
|
1265
|
+
Kernel.raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)" unless ary.respond_to? :each
|
1266
|
+
ary.each { |obj| assert_image obj }
|
1303
1267
|
end
|
1304
1268
|
|
1305
1269
|
# Find old current image, update scene number
|
1306
1270
|
# current is the id of the old current image.
|
1307
1271
|
def set_current(current)
|
1308
|
-
if length
|
1272
|
+
if length.zero?
|
1309
1273
|
self.scene = nil
|
1310
1274
|
return
|
1311
1275
|
# Don't bother looking for current image
|
@@ -1316,10 +1280,8 @@ module Magick
|
|
1316
1280
|
# Find last instance of "current" in the list.
|
1317
1281
|
# If "current" isn't in the list, set current to last image.
|
1318
1282
|
self.scene = length - 1
|
1319
|
-
each_with_index do |f,i|
|
1320
|
-
if f.__id__ == current
|
1321
|
-
self.scene = i
|
1322
|
-
end
|
1283
|
+
each_with_index do |f, i|
|
1284
|
+
self.scene = i if f.__id__ == current
|
1323
1285
|
end
|
1324
1286
|
return
|
1325
1287
|
end
|
@@ -1331,25 +1293,22 @@ module Magick
|
|
1331
1293
|
# Allow scene to be set to nil
|
1332
1294
|
def scene=(n)
|
1333
1295
|
if n.nil?
|
1334
|
-
Kernel.raise IndexError, 'scene number out of bounds' unless @images.length
|
1296
|
+
Kernel.raise IndexError, 'scene number out of bounds' unless @images.length.zero?
|
1335
1297
|
@scene = nil
|
1336
|
-
return
|
1337
|
-
elsif @images.length
|
1298
|
+
return
|
1299
|
+
elsif @images.length.zero?
|
1338
1300
|
Kernel.raise IndexError, 'scene number out of bounds'
|
1339
1301
|
end
|
1340
1302
|
|
1341
1303
|
n = Integer(n)
|
1342
|
-
if n < 0 || n > length - 1
|
1343
|
-
Kernel.raise IndexError, 'scene number out of bounds'
|
1344
|
-
end
|
1304
|
+
Kernel.raise IndexError, 'scene number out of bounds' if n < 0 || n > length - 1
|
1345
1305
|
@scene = n
|
1346
|
-
@scene
|
1347
1306
|
end
|
1348
1307
|
|
1349
1308
|
# All the binary operators work the same way.
|
1350
1309
|
# 'other' should be either an ImageList or an Array
|
1351
|
-
%w
|
1352
|
-
module_eval <<-END_BINOPS
|
1310
|
+
%w[& + - |].each do |op|
|
1311
|
+
module_eval <<-END_BINOPS, __FILE__, __LINE__ + 1
|
1353
1312
|
def #{op}(other)
|
1354
1313
|
ilist = self.class.new
|
1355
1314
|
begin
|
@@ -1359,7 +1318,7 @@ module Magick
|
|
1359
1318
|
end
|
1360
1319
|
current = get_current()
|
1361
1320
|
a.each do |image|
|
1362
|
-
|
1321
|
+
assert_image image
|
1363
1322
|
ilist << image
|
1364
1323
|
end
|
1365
1324
|
ilist.set_current current
|
@@ -1368,19 +1327,17 @@ module Magick
|
|
1368
1327
|
END_BINOPS
|
1369
1328
|
end
|
1370
1329
|
|
1371
|
-
def *(
|
1372
|
-
unless
|
1373
|
-
Kernel.raise ArgumentError, "Integer required (#{n.class} given)"
|
1374
|
-
end
|
1330
|
+
def *(other)
|
1331
|
+
Kernel.raise ArgumentError, "Integer required (#{other.class} given)" unless other.is_a? Integer
|
1375
1332
|
current = get_current
|
1376
1333
|
ilist = self.class.new
|
1377
|
-
(@images *
|
1334
|
+
(@images * other).each { |image| ilist << image }
|
1378
1335
|
ilist.set_current current
|
1379
1336
|
ilist
|
1380
1337
|
end
|
1381
1338
|
|
1382
1339
|
def <<(obj)
|
1383
|
-
|
1340
|
+
assert_image obj
|
1384
1341
|
@images << obj
|
1385
1342
|
@scene = @images.length - 1
|
1386
1343
|
self
|
@@ -1392,23 +1349,19 @@ module Magick
|
|
1392
1349
|
# return if A.scene != B.scene
|
1393
1350
|
# return A.length <=> B.length
|
1394
1351
|
def <=>(other)
|
1395
|
-
unless other.is_a? self.class
|
1396
|
-
Kernel.raise TypeError, "#{self.class} required (#{other.class} given)"
|
1397
|
-
end
|
1352
|
+
Kernel.raise TypeError, "#{self.class} required (#{other.class} given)" unless other.is_a? self.class
|
1398
1353
|
size = [length, other.length].min
|
1399
1354
|
size.times do |x|
|
1400
1355
|
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}"
|
1356
|
+
return r unless r.zero?
|
1409
1357
|
end
|
1358
|
+
return 0 if @scene.nil? && other.scene.nil?
|
1359
|
+
|
1360
|
+
Kernel.raise TypeError, "cannot convert nil into #{other.scene.class}" if @scene.nil? && !other.scene.nil?
|
1361
|
+
Kernel.raise TypeError, "cannot convert nil into #{scene.class}" if !@scene.nil? && other.scene.nil?
|
1410
1362
|
r = scene <=> other.scene
|
1411
|
-
return r unless r
|
1363
|
+
return r unless r.zero?
|
1364
|
+
|
1412
1365
|
length <=> other.length
|
1413
1366
|
end
|
1414
1367
|
|
@@ -1416,7 +1369,7 @@ module Magick
|
|
1416
1369
|
a = @images[*args]
|
1417
1370
|
if a.respond_to?(:each)
|
1418
1371
|
ilist = self.class.new
|
1419
|
-
a.each {|image| ilist << image}
|
1372
|
+
a.each { |image| ilist << image }
|
1420
1373
|
a = ilist
|
1421
1374
|
end
|
1422
1375
|
a
|
@@ -1425,33 +1378,27 @@ module Magick
|
|
1425
1378
|
def []=(*args)
|
1426
1379
|
obj = @images.[]=(*args)
|
1427
1380
|
if obj && obj.respond_to?(:each)
|
1428
|
-
|
1381
|
+
assert_image_array(obj)
|
1429
1382
|
set_current obj.last.__id__
|
1430
1383
|
elsif obj
|
1431
|
-
|
1384
|
+
assert_image(obj)
|
1432
1385
|
set_current obj.__id__
|
1433
1386
|
else
|
1434
1387
|
set_current nil
|
1435
1388
|
end
|
1436
|
-
obj
|
1437
1389
|
end
|
1438
1390
|
|
1439
|
-
[
|
1440
|
-
|
1441
|
-
|
1391
|
+
%i[
|
1392
|
+
at each each_index empty? fetch
|
1393
|
+
first hash include? index length rindex sort!
|
1394
|
+
].each do |mth|
|
1395
|
+
module_eval <<-END_SIMPLE_DELEGATES, __FILE__, __LINE__ + 1
|
1442
1396
|
def #{mth}(*args, &block)
|
1443
1397
|
@images.#{mth}(*args, &block)
|
1444
1398
|
end
|
1445
1399
|
END_SIMPLE_DELEGATES
|
1446
1400
|
end
|
1447
|
-
|
1448
|
-
|
1449
|
-
# Array#nitems is not available in 1.9
|
1450
|
-
if Array.instance_methods.include?('nitems')
|
1451
|
-
def nitems
|
1452
|
-
@images.nitems
|
1453
|
-
end
|
1454
|
-
end
|
1401
|
+
alias size length
|
1455
1402
|
|
1456
1403
|
def clear
|
1457
1404
|
@scene = nil
|
@@ -1467,16 +1414,16 @@ module Magick
|
|
1467
1414
|
# override Enumerable#collect
|
1468
1415
|
def collect(&block)
|
1469
1416
|
current = get_current
|
1470
|
-
a = @images.
|
1417
|
+
a = @images.map(&block)
|
1471
1418
|
ilist = self.class.new
|
1472
|
-
a.each {|image| ilist << image}
|
1419
|
+
a.each { |image| ilist << image }
|
1473
1420
|
ilist.set_current current
|
1474
1421
|
ilist
|
1475
1422
|
end
|
1476
1423
|
|
1477
1424
|
def collect!(&block)
|
1478
|
-
@images.
|
1479
|
-
|
1425
|
+
@images.map!(&block)
|
1426
|
+
assert_image_array @images
|
1480
1427
|
self
|
1481
1428
|
end
|
1482
1429
|
|
@@ -1485,59 +1432,56 @@ module Magick
|
|
1485
1432
|
ditto = self.class.new
|
1486
1433
|
@images.each { |f| ditto << f.copy }
|
1487
1434
|
ditto.scene = @scene
|
1488
|
-
ditto.taint if tainted?
|
1489
1435
|
ditto
|
1490
1436
|
end
|
1491
1437
|
|
1492
1438
|
# Return the current image
|
1493
1439
|
def cur_image
|
1494
|
-
unless @scene
|
1495
|
-
Kernel.raise IndexError, 'no images in this list'
|
1496
|
-
end
|
1440
|
+
Kernel.raise IndexError, 'no images in this list' unless @scene
|
1497
1441
|
@images[@scene]
|
1498
1442
|
end
|
1499
1443
|
|
1500
1444
|
# ImageList#map took over the "map" name. Use alternatives.
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1445
|
+
alias map collect
|
1446
|
+
alias __map__ collect
|
1447
|
+
alias map! collect!
|
1448
|
+
alias __map__! collect!
|
1504
1449
|
|
1505
1450
|
# ImageMagic used affinity in 6.4.3, switch to remap in 6.4.4.
|
1506
|
-
|
1451
|
+
alias affinity remap
|
1507
1452
|
|
1508
1453
|
def compact
|
1509
1454
|
current = get_current
|
1510
1455
|
ilist = self.class.new
|
1511
1456
|
a = @images.compact
|
1512
|
-
a.each {|image| ilist << image}
|
1457
|
+
a.each { |image| ilist << image }
|
1513
1458
|
ilist.set_current current
|
1514
1459
|
ilist
|
1515
1460
|
end
|
1516
1461
|
|
1517
1462
|
def compact!
|
1518
1463
|
current = get_current
|
1519
|
-
a = @images.compact!
|
1464
|
+
a = @images.compact! # returns nil if no changes were made
|
1520
1465
|
set_current current
|
1521
1466
|
a.nil? ? nil : self
|
1522
1467
|
end
|
1523
1468
|
|
1524
1469
|
def concat(other)
|
1525
|
-
|
1526
|
-
other.each {|image| @images << image}
|
1527
|
-
@scene = length-1
|
1470
|
+
assert_image_array other
|
1471
|
+
other.each { |image| @images << image }
|
1472
|
+
@scene = length - 1
|
1528
1473
|
self
|
1529
1474
|
end
|
1530
1475
|
|
1531
1476
|
# Set same delay for all images
|
1532
1477
|
def delay=(d)
|
1533
|
-
if Integer(d) < 0
|
1534
|
-
|
1535
|
-
end
|
1478
|
+
raise ArgumentError, 'delay must be greater than or equal to 0' if Integer(d) < 0
|
1479
|
+
|
1536
1480
|
@images.each { |f| f.delay = Integer(d) }
|
1537
1481
|
end
|
1538
1482
|
|
1539
1483
|
def delete(obj, &block)
|
1540
|
-
|
1484
|
+
assert_image obj
|
1541
1485
|
current = get_current
|
1542
1486
|
a = @images.delete(obj, &block)
|
1543
1487
|
set_current current
|
@@ -1560,14 +1504,13 @@ module Magick
|
|
1560
1504
|
|
1561
1505
|
def dup
|
1562
1506
|
ditto = self.class.new
|
1563
|
-
@images.each {|img| ditto << img}
|
1507
|
+
@images.each { |img| ditto << img }
|
1564
1508
|
ditto.scene = @scene
|
1565
|
-
ditto.taint if tainted?
|
1566
1509
|
ditto
|
1567
1510
|
end
|
1568
1511
|
|
1569
1512
|
def eql?(other)
|
1570
|
-
|
1513
|
+
assert_image_array other
|
1571
1514
|
eql = other.eql?(@images)
|
1572
1515
|
begin # "other" is another ImageList
|
1573
1516
|
eql &&= @scene == other.scene
|
@@ -1578,10 +1521,10 @@ module Magick
|
|
1578
1521
|
end
|
1579
1522
|
|
1580
1523
|
def fill(*args, &block)
|
1581
|
-
|
1524
|
+
assert_image args[0] unless block_given?
|
1582
1525
|
current = get_current
|
1583
1526
|
@images.fill(*args, &block)
|
1584
|
-
|
1527
|
+
assert_image_array self
|
1585
1528
|
set_current current
|
1586
1529
|
self
|
1587
1530
|
end
|
@@ -1589,20 +1532,18 @@ module Magick
|
|
1589
1532
|
# Override Enumerable's find_all
|
1590
1533
|
def find_all(&block)
|
1591
1534
|
current = get_current
|
1592
|
-
a = @images.
|
1535
|
+
a = @images.select(&block)
|
1593
1536
|
ilist = self.class.new
|
1594
|
-
a.each {|image| ilist << image}
|
1537
|
+
a.each { |image| ilist << image }
|
1595
1538
|
ilist.set_current current
|
1596
1539
|
ilist
|
1597
1540
|
end
|
1598
|
-
|
1541
|
+
alias select find_all
|
1599
1542
|
|
1600
1543
|
def from_blob(*blobs, &block)
|
1601
|
-
if
|
1602
|
-
Kernel.raise ArgumentError, 'no blobs given'
|
1603
|
-
end
|
1544
|
+
Kernel.raise ArgumentError, 'no blobs given' if blobs.length.zero?
|
1604
1545
|
blobs.each do |b|
|
1605
|
-
Magick::Image.from_blob(b, &block).each { |n| @images << n
|
1546
|
+
Magick::Image.from_blob(b, &block).each { |n| @images << n }
|
1606
1547
|
end
|
1607
1548
|
@scene = length - 1
|
1608
1549
|
self
|
@@ -1615,14 +1556,12 @@ module Magick
|
|
1615
1556
|
filenames.each do |f|
|
1616
1557
|
Magick::Image.read(f, &block).each { |n| @images << n }
|
1617
1558
|
end
|
1618
|
-
|
1619
|
-
|
1620
|
-
end
|
1621
|
-
self
|
1559
|
+
|
1560
|
+
@scene = length - 1 if length > 0 # last image in array
|
1622
1561
|
end
|
1623
1562
|
|
1624
1563
|
def insert(index, *args)
|
1625
|
-
args.each {|image|
|
1564
|
+
args.each { |image| assert_image image }
|
1626
1565
|
current = get_current
|
1627
1566
|
@images.insert(index, *args)
|
1628
1567
|
set_current current
|
@@ -1632,27 +1571,24 @@ module Magick
|
|
1632
1571
|
# Call inspect for all the images
|
1633
1572
|
def inspect
|
1634
1573
|
img = []
|
1635
|
-
@images.each {|image| img << image.inspect }
|
1574
|
+
@images.each { |image| img << image.inspect }
|
1636
1575
|
img = '[' + img.join(",\n") + "]\nscene=#{@scene}"
|
1637
1576
|
end
|
1638
1577
|
|
1639
1578
|
# Set the number of iterations of an animated GIF
|
1640
1579
|
def iterations=(n)
|
1641
1580
|
n = Integer(n)
|
1642
|
-
if n < 0 || n >
|
1643
|
-
|
1644
|
-
end
|
1645
|
-
@images.each {|f| f.iterations=n}
|
1646
|
-
self
|
1581
|
+
Kernel.raise ArgumentError, 'iterations must be between 0 and 65535' if n < 0 || n > 65_535
|
1582
|
+
@images.each { |f| f.iterations = n }
|
1647
1583
|
end
|
1648
1584
|
|
1649
1585
|
def last(*args)
|
1650
|
-
if args.length
|
1586
|
+
if args.length.zero?
|
1651
1587
|
a = @images.last
|
1652
1588
|
else
|
1653
1589
|
a = @images.last(*args)
|
1654
1590
|
ilist = self.class.new
|
1655
|
-
a.each {|img| ilist << img}
|
1591
|
+
a.each { |img| ilist << img }
|
1656
1592
|
@scene = a.length - 1
|
1657
1593
|
a = ilist
|
1658
1594
|
end
|
@@ -1662,28 +1598,28 @@ module Magick
|
|
1662
1598
|
# Custom marshal/unmarshal for Ruby 1.8.
|
1663
1599
|
def marshal_dump
|
1664
1600
|
ary = [@scene]
|
1665
|
-
@images.each {|i| ary << Marshal.dump(i)}
|
1601
|
+
@images.each { |i| ary << Marshal.dump(i) }
|
1666
1602
|
ary
|
1667
1603
|
end
|
1668
1604
|
|
1669
1605
|
def marshal_load(ary)
|
1670
1606
|
@scene = ary.shift
|
1671
1607
|
@images = []
|
1672
|
-
ary.each {|a| @images << Marshal.load(a)}
|
1608
|
+
ary.each { |a| @images << Marshal.load(a) }
|
1673
1609
|
end
|
1674
1610
|
|
1675
1611
|
# The ImageList class supports the Magick::Image class methods by simply sending
|
1676
1612
|
# the method to the current image. If the method isn't explicitly supported,
|
1677
1613
|
# send it to the current image in the array. If there are no images, send
|
1678
1614
|
# it up the line. Catch a NameError and emit a useful message.
|
1679
|
-
def method_missing(
|
1615
|
+
def method_missing(meth_id, *args, &block)
|
1680
1616
|
if @scene
|
1681
|
-
@images[@scene].send(
|
1617
|
+
@images[@scene].send(meth_id, *args, &block)
|
1682
1618
|
else
|
1683
1619
|
super
|
1684
1620
|
end
|
1685
1621
|
rescue NoMethodError
|
1686
|
-
Kernel.raise NoMethodError, "undefined method `#{
|
1622
|
+
Kernel.raise NoMethodError, "undefined method `#{meth_id.id2name}' for #{self.class}"
|
1687
1623
|
rescue Exception
|
1688
1624
|
$ERROR_POSITION.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
|
1689
1625
|
Kernel.raise
|
@@ -1697,19 +1633,17 @@ module Magick
|
|
1697
1633
|
def partition(&block)
|
1698
1634
|
a = @images.partition(&block)
|
1699
1635
|
t = self.class.new
|
1700
|
-
a[0].each { |img| t << img}
|
1636
|
+
a[0].each { |img| t << img }
|
1701
1637
|
t.set_current nil
|
1702
1638
|
f = self.class.new
|
1703
|
-
a[1].each { |img| f << img}
|
1639
|
+
a[1].each { |img| f << img }
|
1704
1640
|
f.set_current nil
|
1705
1641
|
[t, f]
|
1706
1642
|
end
|
1707
1643
|
|
1708
1644
|
# Ping files and concatenate the new images
|
1709
1645
|
def ping(*files, &block)
|
1710
|
-
if
|
1711
|
-
Kernel.raise ArgumentError, 'no files given'
|
1712
|
-
end
|
1646
|
+
Kernel.raise ArgumentError, 'no files given' if files.length.zero?
|
1713
1647
|
files.each do |f|
|
1714
1648
|
Magick::Image.ping(f, &block).each { |n| @images << n }
|
1715
1649
|
end
|
@@ -1719,14 +1653,14 @@ module Magick
|
|
1719
1653
|
|
1720
1654
|
def pop
|
1721
1655
|
current = get_current
|
1722
|
-
a = @images.pop
|
1656
|
+
a = @images.pop # can return nil
|
1723
1657
|
set_current current
|
1724
1658
|
a
|
1725
1659
|
end
|
1726
1660
|
|
1727
1661
|
def push(*objs)
|
1728
1662
|
objs.each do |image|
|
1729
|
-
|
1663
|
+
assert_image image
|
1730
1664
|
@images << image
|
1731
1665
|
end
|
1732
1666
|
@scene = length - 1
|
@@ -1735,9 +1669,7 @@ module Magick
|
|
1735
1669
|
|
1736
1670
|
# Read files and concatenate the new images
|
1737
1671
|
def read(*files, &block)
|
1738
|
-
if
|
1739
|
-
Kernel.raise ArgumentError, 'no files given'
|
1740
|
-
end
|
1672
|
+
Kernel.raise ArgumentError, 'no files given' if files.length.zero?
|
1741
1673
|
files.each do |f|
|
1742
1674
|
Magick::Image.read(f, &block).each { |n| @images << n }
|
1743
1675
|
end
|
@@ -1750,7 +1682,7 @@ module Magick
|
|
1750
1682
|
current = get_current
|
1751
1683
|
ilist = self.class.new
|
1752
1684
|
a = @images.reject(&block)
|
1753
|
-
a.each {|image| ilist << image}
|
1685
|
+
a.each { |image| ilist << image }
|
1754
1686
|
ilist.set_current current
|
1755
1687
|
ilist
|
1756
1688
|
end
|
@@ -1764,21 +1696,22 @@ module Magick
|
|
1764
1696
|
end
|
1765
1697
|
|
1766
1698
|
def replace(other)
|
1767
|
-
|
1699
|
+
assert_image_array other
|
1768
1700
|
current = get_current
|
1769
1701
|
@images.clear
|
1770
|
-
other.each {|image| @images << image}
|
1771
|
-
@scene = length
|
1702
|
+
other.each { |image| @images << image }
|
1703
|
+
@scene = length.zero? ? nil : 0
|
1772
1704
|
set_current current
|
1773
1705
|
self
|
1774
1706
|
end
|
1775
1707
|
|
1776
1708
|
# Ensure respond_to? answers correctly when we are delegating to Image
|
1777
|
-
|
1778
|
-
def respond_to?(
|
1779
|
-
return true if __respond_to__?(
|
1709
|
+
alias __respond_to__? respond_to?
|
1710
|
+
def respond_to?(meth_id, priv = false)
|
1711
|
+
return true if __respond_to__?(meth_id, priv)
|
1712
|
+
|
1780
1713
|
if @scene
|
1781
|
-
@images[@scene].respond_to?(
|
1714
|
+
@images[@scene].respond_to?(meth_id, priv)
|
1782
1715
|
else
|
1783
1716
|
super
|
1784
1717
|
end
|
@@ -1787,7 +1720,7 @@ module Magick
|
|
1787
1720
|
def reverse
|
1788
1721
|
current = get_current
|
1789
1722
|
a = self.class.new
|
1790
|
-
@images.reverse_each {|image| a << image}
|
1723
|
+
@images.reverse_each { |image| a << image }
|
1791
1724
|
a.set_current current
|
1792
1725
|
a
|
1793
1726
|
end
|
@@ -1800,7 +1733,7 @@ module Magick
|
|
1800
1733
|
end
|
1801
1734
|
|
1802
1735
|
def reverse_each
|
1803
|
-
@images.reverse_each {|image| yield(image)}
|
1736
|
+
@images.reverse_each { |image| yield(image) }
|
1804
1737
|
self
|
1805
1738
|
end
|
1806
1739
|
|
@@ -1816,7 +1749,7 @@ module Magick
|
|
1816
1749
|
if slice
|
1817
1750
|
ilist = self.class.new
|
1818
1751
|
if slice.respond_to?(:each)
|
1819
|
-
slice.each {|image| ilist << image}
|
1752
|
+
slice.each { |image| ilist << image }
|
1820
1753
|
else
|
1821
1754
|
ilist << slice
|
1822
1755
|
end
|
@@ -1834,27 +1767,25 @@ module Magick
|
|
1834
1767
|
end
|
1835
1768
|
|
1836
1769
|
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
|
1770
|
+
Kernel.raise ArgumentError, 'ticks_per_second must be greater than or equal to 0' if Integer(t) < 0
|
1840
1771
|
@images.each { |f| f.ticks_per_second = Integer(t) }
|
1841
1772
|
end
|
1842
1773
|
|
1843
1774
|
def to_a
|
1844
1775
|
a = []
|
1845
|
-
@images.each {|image| a << image}
|
1776
|
+
@images.each { |image| a << image }
|
1846
1777
|
a
|
1847
1778
|
end
|
1848
1779
|
|
1849
1780
|
def uniq
|
1850
1781
|
current = get_current
|
1851
1782
|
a = self.class.new
|
1852
|
-
@images.uniq.each {|image| a << image}
|
1783
|
+
@images.uniq.each { |image| a << image }
|
1853
1784
|
a.set_current current
|
1854
1785
|
a
|
1855
1786
|
end
|
1856
1787
|
|
1857
|
-
def uniq!(*
|
1788
|
+
def uniq!(*_args)
|
1858
1789
|
current = get_current
|
1859
1790
|
a = @images.uniq!
|
1860
1791
|
set_current current
|
@@ -1863,7 +1794,7 @@ module Magick
|
|
1863
1794
|
|
1864
1795
|
# @scene -> new object
|
1865
1796
|
def unshift(obj)
|
1866
|
-
|
1797
|
+
assert_image obj
|
1867
1798
|
@images.unshift(obj)
|
1868
1799
|
@scene = 0
|
1869
1800
|
self
|
@@ -1872,14 +1803,19 @@ module Magick
|
|
1872
1803
|
def values_at(*args)
|
1873
1804
|
a = @images.values_at(*args)
|
1874
1805
|
a = self.class.new
|
1875
|
-
@images.values_at(*args).each {|image| a << image}
|
1806
|
+
@images.values_at(*args).each { |image| a << image }
|
1876
1807
|
a.scene = a.length - 1
|
1877
1808
|
a
|
1878
1809
|
end
|
1879
|
-
|
1880
|
-
|
1810
|
+
alias indexes values_at
|
1811
|
+
alias indices values_at
|
1881
1812
|
end # Magick::ImageList
|
1882
1813
|
|
1814
|
+
class Pixel
|
1815
|
+
# include Observable for Image::View class
|
1816
|
+
include Observable
|
1817
|
+
end
|
1818
|
+
|
1883
1819
|
# Collects non-specific optional method arguments
|
1884
1820
|
class OptionalMethodArguments
|
1885
1821
|
def initialize(img)
|
@@ -1914,21 +1850,21 @@ module Magick
|
|
1914
1850
|
# @dist is the number of pixels between hatch lines.
|
1915
1851
|
# See Magick::Draw examples.
|
1916
1852
|
class HatchFill
|
1917
|
-
def initialize(bgcolor, hatchcolor='white', dist=10)
|
1853
|
+
def initialize(bgcolor, hatchcolor = 'white', dist = 10)
|
1918
1854
|
@bgcolor = bgcolor
|
1919
1855
|
@hatchpixel = Pixel.from_color(hatchcolor)
|
1920
1856
|
@dist = dist
|
1921
1857
|
end
|
1922
1858
|
|
1923
|
-
def fill(img)
|
1859
|
+
def fill(img) # required
|
1924
1860
|
img.background_color = @bgcolor
|
1925
|
-
img.erase!
|
1861
|
+
img.erase! # sets image to background color
|
1926
1862
|
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)
|
1863
|
+
@dist.step((img.columns - 1) / @dist * @dist, @dist) do |x|
|
1864
|
+
img.store_pixels(x, 0, 1, img.rows, pixels)
|
1929
1865
|
end
|
1930
|
-
@dist.step((img.rows-1)
|
1931
|
-
img.store_pixels(0,y,img.columns,1,pixels)
|
1866
|
+
@dist.step((img.rows - 1) / @dist * @dist, @dist) do |y|
|
1867
|
+
img.store_pixels(0, y, img.columns, 1, pixels)
|
1932
1868
|
end
|
1933
1869
|
end
|
1934
1870
|
end
|