rmagick 2.16.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rmagick might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.appveyor.yml +19 -0
- data/.circleci/config.yml +56 -0
- data/.rubocop.yml +8 -335
- data/.rubocop_todo.yml +255 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -49
- data/CHANGELOG.md +23 -0
- data/CONTRIBUTING.md +34 -0
- data/Gemfile +0 -6
- data/README.textile +11 -3
- data/Rakefile +23 -15
- data/before_install_linux.sh +12 -15
- data/doc/ex/InitialCoords.rb +4 -4
- data/doc/ex/NewCoordSys.rb +4 -4
- data/doc/ex/OrigCoordSys.rb +2 -2
- data/doc/ex/PreserveAspectRatio.rb +34 -34
- data/doc/ex/RotateScale.rb +7 -7
- data/doc/ex/Skew.rb +7 -7
- data/doc/ex/Use01.rb +1 -1
- data/doc/ex/Use02.rb +4 -4
- data/doc/ex/Use03.rb +2 -2
- data/doc/ex/ViewBox.rb +4 -4
- data/doc/ex/affine.rb +5 -5
- data/doc/ex/affine_transform.rb +3 -3
- data/doc/ex/arc.rb +9 -9
- data/doc/ex/arcpath.rb +2 -2
- data/doc/ex/arcs01.rb +6 -6
- data/doc/ex/arcs02.rb +8 -8
- data/doc/ex/axes.rb +11 -11
- data/doc/ex/baseline_shift01.rb +5 -5
- data/doc/ex/bilevel_channel.rb +1 -1
- data/doc/ex/blur_image.rb +1 -1
- data/doc/ex/border.rb +1 -1
- data/doc/ex/bounding_box.rb +11 -11
- data/doc/ex/cbezier1.rb +12 -12
- data/doc/ex/cbezier2.rb +13 -13
- data/doc/ex/cbezier3.rb +13 -13
- data/doc/ex/cbezier4.rb +13 -13
- data/doc/ex/cbezier5.rb +13 -13
- data/doc/ex/cbezier6.rb +19 -19
- data/doc/ex/channel.rb +2 -2
- data/doc/ex/chop.rb +2 -2
- data/doc/ex/circle.rb +7 -7
- data/doc/ex/circle01.rb +2 -2
- data/doc/ex/clip_path.rb +6 -6
- data/doc/ex/coalesce.rb +6 -6
- data/doc/ex/color_fill_to_border.rb +8 -8
- data/doc/ex/color_floodfill.rb +8 -8
- data/doc/ex/color_histogram.rb +2 -2
- data/doc/ex/color_reset.rb +2 -2
- data/doc/ex/colors.rb +4 -4
- data/doc/ex/compose_mask.rb +2 -2
- data/doc/ex/composite.rb +39 -39
- data/doc/ex/composite_layers.rb +1 -2
- data/doc/ex/contrast.rb +3 -3
- data/doc/ex/crop.rb +2 -2
- data/doc/ex/crop_with_gravity.rb +5 -5
- data/doc/ex/cubic01.rb +12 -12
- data/doc/ex/cubic02.rb +22 -22
- data/doc/ex/cycle_colormap.rb +3 -3
- data/doc/ex/dissolve.rb +0 -0
- data/doc/ex/drawcomp.rb +8 -9
- data/doc/ex/drop_shadow.rb +4 -4
- data/doc/ex/ellipse.rb +9 -9
- data/doc/ex/ellipse01.rb +3 -3
- data/doc/ex/enhance.rb +2 -2
- data/doc/ex/evenodd.rb +19 -19
- data/doc/ex/fill_pattern.rb +3 -3
- data/doc/ex/flatten_images.rb +1 -1
- data/doc/ex/font_styles.rb +13 -13
- data/doc/ex/fonts.rb +2 -6
- data/doc/ex/frame.rb +1 -1
- data/doc/ex/get_multiline_type_metrics.rb +3 -3
- data/doc/ex/get_pixels.rb +4 -6
- data/doc/ex/get_type_metrics.rb +26 -25
- data/doc/ex/gradientfill.rb +2 -2
- data/doc/ex/grav.rb +12 -12
- data/doc/ex/gravity.rb +14 -16
- data/doc/ex/group.rb +11 -11
- data/doc/ex/hatchfill.rb +2 -2
- data/doc/ex/image.rb +9 -9
- data/doc/ex/implode.rb +2 -2
- data/doc/ex/line.rb +10 -10
- data/doc/ex/line01.rb +7 -7
- data/doc/ex/mask.rb +0 -0
- data/doc/ex/matte_fill_to_border.rb +3 -3
- data/doc/ex/matte_floodfill.rb +2 -2
- data/doc/ex/matte_replace.rb +3 -3
- data/doc/ex/median_filter.rb +2 -2
- data/doc/ex/mono.rb +2 -2
- data/doc/ex/morph.rb +1 -1
- data/doc/ex/mosaic.rb +7 -5
- data/doc/ex/motion_blur.rb +1 -1
- data/doc/ex/negate_channel.rb +0 -0
- data/doc/ex/nested_rvg.rb +2 -2
- data/doc/ex/nonzero.rb +19 -19
- data/doc/ex/opacity.rb +9 -9
- data/doc/ex/path.rb +17 -17
- data/doc/ex/pattern1.rb +4 -4
- data/doc/ex/pattern2.rb +2 -2
- data/doc/ex/polaroid.rb +0 -1
- data/doc/ex/polygon.rb +7 -7
- data/doc/ex/polygon01.rb +7 -7
- data/doc/ex/polyline.rb +7 -7
- data/doc/ex/polyline01.rb +8 -8
- data/doc/ex/posterize.rb +0 -0
- data/doc/ex/qbezierpath.rb +16 -16
- data/doc/ex/quad01.rb +6 -6
- data/doc/ex/quantize-m.rb +2 -2
- data/doc/ex/random_threshold_channel.rb +1 -1
- data/doc/ex/rect01.rb +2 -2
- data/doc/ex/rect02.rb +3 -3
- data/doc/ex/rectangle.rb +6 -6
- data/doc/ex/reduce_noise.rb +2 -2
- data/doc/ex/remap.rb +0 -0
- data/doc/ex/resize_to_fill.rb +0 -0
- data/doc/ex/resize_to_fit.rb +0 -0
- data/doc/ex/roll.rb +1 -1
- data/doc/ex/rotate.rb +8 -8
- data/doc/ex/rotate_f.rb +1 -1
- data/doc/ex/roundrect.rb +6 -6
- data/doc/ex/rubyname.rb +4 -4
- data/doc/ex/rvg_clippath.rb +3 -3
- data/doc/ex/rvg_linecap.rb +7 -7
- data/doc/ex/rvg_linejoin.rb +7 -7
- data/doc/ex/rvg_opacity.rb +5 -5
- data/doc/ex/rvg_pattern.rb +8 -8
- data/doc/ex/rvg_stroke_dasharray.rb +2 -2
- data/doc/ex/sepiatone.rb +0 -0
- data/doc/ex/shadow.rb +6 -6
- data/doc/ex/shear.rb +2 -2
- data/doc/ex/skewx.rb +8 -8
- data/doc/ex/skewy.rb +9 -9
- data/doc/ex/smile.rb +5 -4
- data/doc/ex/sparse_color.rb +0 -4
- data/doc/ex/splice.rb +1 -1
- data/doc/ex/stegano.rb +4 -5
- data/doc/ex/stroke_dasharray.rb +10 -10
- data/doc/ex/stroke_fill.rb +2 -2
- data/doc/ex/stroke_linecap.rb +12 -12
- data/doc/ex/stroke_linejoin.rb +12 -12
- data/doc/ex/stroke_width.rb +11 -11
- data/doc/ex/swirl.rb +2 -2
- data/doc/ex/text.rb +6 -6
- data/doc/ex/text01.rb +4 -4
- data/doc/ex/text_align.rb +5 -5
- data/doc/ex/text_antialias.rb +2 -2
- data/doc/ex/text_styles.rb +8 -8
- data/doc/ex/text_undercolor.rb +4 -4
- data/doc/ex/texture_fill_to_border.rb +8 -8
- data/doc/ex/texture_floodfill.rb +8 -8
- data/doc/ex/texturefill.rb +2 -2
- data/doc/ex/threshold.rb +2 -2
- data/doc/ex/to_blob.rb +1 -1
- data/doc/ex/translate.rb +8 -8
- data/doc/ex/transparent.rb +6 -6
- data/doc/ex/transpose.rb +0 -0
- data/doc/ex/transverse.rb +0 -0
- data/doc/ex/tref01.rb +6 -6
- data/doc/ex/triangle01.rb +2 -2
- data/doc/ex/trim.rb +2 -2
- data/doc/ex/tspan01.rb +5 -5
- data/doc/ex/tspan02.rb +5 -5
- data/doc/ex/tspan03.rb +5 -5
- data/doc/ex/unsharp_mask.rb +3 -3
- data/doc/ex/viewex.rb +5 -5
- data/doc/ex/vignette.rb +0 -0
- data/doc/ex/watermark.rb +6 -6
- data/doc/ex/wet_floor.rb +2 -2
- data/doc/ex/writing_mode01.rb +12 -12
- data/doc/ex/writing_mode02.rb +12 -12
- data/examples/constitute.rb +1 -1
- data/examples/crop_with_gravity.rb +5 -5
- data/examples/demo.rb +6 -7
- data/examples/describe.rb +8 -10
- data/examples/find_similar_region.rb +3 -3
- data/examples/histogram.rb +192 -201
- data/examples/identify.rb +62 -73
- data/examples/image_opacity.rb +0 -1
- data/examples/import_export.rb +1 -1
- data/examples/pattern_fill.rb +3 -4
- data/examples/rotating_text.rb +5 -4
- data/examples/spinner.rb +5 -5
- data/examples/thumbnail.rb +3 -3
- data/examples/vignette.rb +5 -5
- data/ext/RMagick/extconf.rb +213 -230
- data/ext/RMagick/rmagick.c +1 -0
- data/ext/RMagick/rmagick.h +26 -29
- data/ext/RMagick/rmdraw.c +3 -38
- data/ext/RMagick/rmenum.c +36 -0
- data/ext/RMagick/rmimage.c +166 -10
- data/ext/RMagick/rminfo.c +7 -2
- data/ext/RMagick/rmkinfo.c +247 -0
- data/ext/RMagick/rmmain.c +96 -0
- data/ext/RMagick/rmutil.c +4 -0
- data/lib/rmagick/version.rb +3 -3
- data/lib/rmagick_internal.rb +226 -308
- data/lib/rvg/clippath.rb +2 -4
- data/lib/rvg/container.rb +25 -22
- data/lib/rvg/deep_equal.rb +11 -11
- data/lib/rvg/describable.rb +2 -2
- data/lib/rvg/embellishable.rb +60 -66
- data/lib/rvg/misc.rb +122 -128
- data/lib/rvg/pathdata.rb +15 -17
- data/lib/rvg/rvg.rb +41 -44
- data/lib/rvg/stretchable.rb +22 -28
- data/lib/rvg/stylable.rb +10 -10
- data/lib/rvg/text.rb +164 -165
- data/lib/rvg/transformable.rb +15 -15
- data/lib/rvg/units.rb +2 -2
- data/rmagick.gemspec +9 -33
- data/spec/rmagick/draw_spec.rb +5 -6
- data/spec/rmagick/image/blue_shift_spec.rb +1 -3
- data/spec/rmagick/image/channel_entropy_spec.rb +9 -0
- data/spec/rmagick/image/composite_spec.rb +2 -4
- data/spec/rmagick/image/constitute_spec.rb +2 -4
- data/spec/rmagick/image/dispatch_spec.rb +1 -3
- data/spec/rmagick/image/from_blob_spec.rb +1 -3
- data/spec/rmagick/image/ping_spec.rb +1 -3
- data/spec/rmagick/image/properties_spec.rb +0 -2
- data/spec/rmagick/image/read_spec.rb +28 -0
- data/spec/spec_helper.rb +7 -1
- data/spec/support/issue_200/app.rb +8 -0
- data/test/Image1.rb +70 -70
- data/test/Image2.rb +369 -361
- data/test/Image3.rb +64 -63
- data/test/ImageList1.rb +796 -792
- data/test/ImageList2.rb +43 -44
- data/test/Image_attributes.rb +26 -48
- data/test/Import_Export.rb +71 -77
- data/test/Info.rb +30 -31
- data/test/Magick.rb +47 -46
- data/test/Pixel.rb +24 -24
- data/test/Preview.rb +7 -6
- data/test/test_all_basic.rb +15 -7
- data/test/tmpnam_test.rb +3 -3
- metadata +57 -18
data/ext/RMagick/rminfo.c
CHANGED
@@ -1734,6 +1734,9 @@ Info_monitor_eq(VALUE self, VALUE monitor)
|
|
1734
1734
|
(void) SetImageInfoProgressMonitor(info, rm_progress_monitor, (void *)monitor);
|
1735
1735
|
}
|
1736
1736
|
|
1737
|
+
#if defined(_WIN32)
|
1738
|
+
rb_warn("Info#monitor= does not work on Windows");
|
1739
|
+
#endif
|
1737
1740
|
|
1738
1741
|
return self;
|
1739
1742
|
}
|
@@ -1839,10 +1842,12 @@ Info_origin_eq(VALUE self, VALUE origin_arg)
|
|
1839
1842
|
|
1840
1843
|
if (IsGeometry(origin) == MagickFalse)
|
1841
1844
|
{
|
1842
|
-
|
1845
|
+
magick_free(origin);
|
1846
|
+
rb_raise(rb_eArgError, "invalid origin geometry");
|
1843
1847
|
}
|
1844
1848
|
|
1845
1849
|
(void) SetImageOption(info, "origin", origin);
|
1850
|
+
magick_free(origin);
|
1846
1851
|
|
1847
1852
|
RB_GC_GUARD(origin_str);
|
1848
1853
|
|
@@ -1902,7 +1907,7 @@ Info_page_eq(VALUE self, VALUE page_arg)
|
|
1902
1907
|
info->page = NULL;
|
1903
1908
|
return self;
|
1904
1909
|
}
|
1905
|
-
|
1910
|
+
info->page = geometry;
|
1906
1911
|
|
1907
1912
|
RB_GC_GUARD(geom_str);
|
1908
1913
|
|
@@ -0,0 +1,247 @@
|
|
1
|
+
/************************************************************************//**
|
2
|
+
* KernelInfo class definitions for RMagick.
|
3
|
+
*
|
4
|
+
* Copyright © RMagick Project
|
5
|
+
*
|
6
|
+
* @file rmkinfo.c
|
7
|
+
* @version $Id: rmkinfo.c,v 1.0 2011/11/29 15:33:14 naquad Exp $
|
8
|
+
* @author Naquad
|
9
|
+
****************************************************************************/
|
10
|
+
|
11
|
+
#include "rmagick.h"
|
12
|
+
|
13
|
+
/**
|
14
|
+
* If there's a kernel info, delete it before destroying the KernelInfo
|
15
|
+
*
|
16
|
+
* No Ruby usage (internal function)
|
17
|
+
*
|
18
|
+
* @param kernel pointer to the KernelInfo object associated with instance
|
19
|
+
*/
|
20
|
+
|
21
|
+
static void
|
22
|
+
rm_kernel_info_destroy(void *kernel)
|
23
|
+
{
|
24
|
+
if (kernel)
|
25
|
+
DestroyKernelInfo((KernelInfo*)kernel);
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Create a KernelInfo object.
|
30
|
+
*
|
31
|
+
* No Ruby usage (internal function)
|
32
|
+
*
|
33
|
+
* @param class the Ruby class to use
|
34
|
+
* @return a new KernelInfo object
|
35
|
+
*/
|
36
|
+
VALUE
|
37
|
+
KernelInfo_alloc(VALUE class)
|
38
|
+
{
|
39
|
+
return Data_Wrap_Struct(class, NULL, rm_kernel_info_destroy, NULL);
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* KernelInfo object constructor
|
44
|
+
*
|
45
|
+
* Ruby usage:
|
46
|
+
* - @verbatim KernelInfo#initialize @endverbatim
|
47
|
+
*
|
48
|
+
* @param self this object
|
49
|
+
* @param kernel_string kernel info string representation to be parsed
|
50
|
+
* @return self
|
51
|
+
*/
|
52
|
+
VALUE
|
53
|
+
KernelInfo_initialize(VALUE self, VALUE kernel_string)
|
54
|
+
{
|
55
|
+
KernelInfo *kernel;
|
56
|
+
|
57
|
+
Check_Type(kernel_string, T_STRING);
|
58
|
+
|
59
|
+
kernel = AcquireKernelInfo(StringValueCStr(kernel_string));
|
60
|
+
|
61
|
+
if (kernel == NULL)
|
62
|
+
rb_raise(rb_eRuntimeError, "failed to parse kernel string");
|
63
|
+
|
64
|
+
DATA_PTR(self) = kernel;
|
65
|
+
|
66
|
+
return self;
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Zero kerne NaNs.
|
71
|
+
*
|
72
|
+
* Ruby usage:
|
73
|
+
* - @verbatim KernelInfo#zero_nans @endverbatim
|
74
|
+
*
|
75
|
+
* @param self this object
|
76
|
+
*/
|
77
|
+
VALUE
|
78
|
+
KernelInfo_zero_nans(VALUE self)
|
79
|
+
{
|
80
|
+
ZeroKernelNans((KernelInfo*)DATA_PTR(self));
|
81
|
+
return Qnil;
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Adds a given amount of the 'Unity' Convolution Kernel to the given pre-scaled and normalized Kernel.
|
86
|
+
*
|
87
|
+
* Ruby usage:
|
88
|
+
* - @verbatim KernelInfo#unity_add(scale) @endverbatim
|
89
|
+
*
|
90
|
+
* @param self this object
|
91
|
+
* @param scale scale to add
|
92
|
+
*/
|
93
|
+
VALUE
|
94
|
+
KernelInfo_unity_add(VALUE self, VALUE scale)
|
95
|
+
{
|
96
|
+
if (!FIXNUM_P(scale))
|
97
|
+
Check_Type(scale, T_FLOAT);
|
98
|
+
|
99
|
+
UnityAddKernelInfo((KernelInfo*)DATA_PTR(self), NUM2DBL(scale));
|
100
|
+
return Qnil;
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Dumps KernelInfo object to stderr
|
105
|
+
*
|
106
|
+
* Ruby usage:
|
107
|
+
* - @verbatim KernelInfo#show @endverbatim
|
108
|
+
*
|
109
|
+
* @param self this object
|
110
|
+
*/
|
111
|
+
VALUE
|
112
|
+
KernelInfo_show(VALUE self)
|
113
|
+
{
|
114
|
+
ShowKernelInfo((KernelInfo*)DATA_PTR(self));
|
115
|
+
return Qnil;
|
116
|
+
}
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Scales the given kernel list by the given amount, with or without normalization
|
120
|
+
* of the sum of the kernel values (as per given flags).
|
121
|
+
*
|
122
|
+
* Ruby usage:
|
123
|
+
* - @verbatim KernelInfo#scale(scale, flags) @endverbatim
|
124
|
+
*
|
125
|
+
* @param scale scale to use
|
126
|
+
* @param flags one of Magick::NormalizeValue, Magick::CorrelateNormalizeValue,
|
127
|
+
* and/or Magick::PercentValue
|
128
|
+
* @param self this object
|
129
|
+
*/
|
130
|
+
VALUE
|
131
|
+
KernelInfo_scale(VALUE self, VALUE scale, VALUE flags)
|
132
|
+
{
|
133
|
+
GeometryFlags geoflags;
|
134
|
+
|
135
|
+
if (!FIXNUM_P(scale))
|
136
|
+
Check_Type(scale, T_FLOAT);
|
137
|
+
|
138
|
+
if (rb_obj_is_instance_of(flags, Class_GeometryFlags))
|
139
|
+
VALUE_TO_ENUM(flags, geoflags, GeometryFlags);
|
140
|
+
else
|
141
|
+
rb_raise(rb_eArgError, "expected Fixnum or Magick::GeometryFlags to specify flags");
|
142
|
+
|
143
|
+
ScaleKernelInfo((KernelInfo*)DATA_PTR(self), NUM2DBL(scale), geoflags);
|
144
|
+
return Qnil;
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Takes a geometry argument string, typically provided as a "-set option:convolve:scale {geometry}" user setting,
|
149
|
+
* and modifies the kernel according to the parsed arguments of that setting.
|
150
|
+
*
|
151
|
+
* Ruby usage:
|
152
|
+
* - @verbatim KernelInfo#scale_geometry(geometry) @endverbatim
|
153
|
+
*
|
154
|
+
* @param geometry geometry string to parse and apply
|
155
|
+
* @param self this object
|
156
|
+
*/
|
157
|
+
VALUE
|
158
|
+
KernelInfo_scale_geometry(VALUE self, VALUE geometry)
|
159
|
+
{
|
160
|
+
Check_Type(geometry, T_STRING);
|
161
|
+
ScaleGeometryKernelInfo((KernelInfo*)DATA_PTR(self), StringValueCStr(geometry));
|
162
|
+
return Qnil;
|
163
|
+
}
|
164
|
+
|
165
|
+
/**
|
166
|
+
* Creates a new clone of the object so that its can be modified without effecting the original.
|
167
|
+
*
|
168
|
+
* Ruby usage:
|
169
|
+
* - @verbatim KernelInfo#clone @endverbatim
|
170
|
+
*
|
171
|
+
* @param self this object
|
172
|
+
* @return new KernelInfo instance
|
173
|
+
*/
|
174
|
+
VALUE
|
175
|
+
KernelInfo_clone(VALUE self)
|
176
|
+
{
|
177
|
+
KernelInfo *kernel = CloneKernelInfo((KernelInfo*)DATA_PTR(self));
|
178
|
+
return Data_Wrap_Struct(Class_KernelInfo, NULL, rm_kernel_info_destroy, kernel);
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* Create new instance of KernelInfo with one of the 'named' built-in types of
|
183
|
+
* kernels used for special purposes such as gaussian blurring, skeleton
|
184
|
+
* pruning, and edge distance determination.
|
185
|
+
*
|
186
|
+
* Ruby usage:
|
187
|
+
* - @verbatim KernelInfo.builtin(kernel, geometry = nil) @endverbatim
|
188
|
+
*
|
189
|
+
* @parms kernel one of Magick::KernelInfoType enums:
|
190
|
+
* Magick::UndefinedKernel
|
191
|
+
* Magick::UnityKernel
|
192
|
+
* Magick::GaussianKernel
|
193
|
+
* Magick::DoGKernel
|
194
|
+
* Magick::LoGKernel
|
195
|
+
* Magick::BlurKernel
|
196
|
+
* Magick::CometKernel
|
197
|
+
* Magick::LaplacianKernel
|
198
|
+
* Magick::SobelKernel
|
199
|
+
* Magick::FreiChenKernel
|
200
|
+
* Magick::RobertsKernel
|
201
|
+
* Magick::PrewittKernel
|
202
|
+
* Magick::CompassKernel
|
203
|
+
* Magick::KirschKernel
|
204
|
+
* Magick::DiamondKernel
|
205
|
+
* Magick::SquareKernel
|
206
|
+
* Magick::RectangleKernel
|
207
|
+
* Magick::OctagonKernel
|
208
|
+
* Magick::DiskKernel
|
209
|
+
* Magick::PlusKernel
|
210
|
+
* Magick::CrossKernel
|
211
|
+
* Magick::RingKernel
|
212
|
+
* Magick::PeaksKernel
|
213
|
+
* Magick::EdgesKernel
|
214
|
+
* Magick::CornersKernel
|
215
|
+
* Magick::DiagonalsKernel
|
216
|
+
* Magick::LineEndsKernel
|
217
|
+
* Magick::LineJunctionsKernel
|
218
|
+
* Magick::RidgesKernel
|
219
|
+
* Magick::ConvexHullKernel
|
220
|
+
* Magick::ThinSEKernel
|
221
|
+
* Magick::SkeletonKernel
|
222
|
+
* Magick::ChebyshevKernel
|
223
|
+
* Magick::ManhattanKernel
|
224
|
+
* Magick::OctagonalKernel
|
225
|
+
* Magick::EuclideanKernel
|
226
|
+
* Magick::UserDefinedKernel
|
227
|
+
* @param geometry geometry to pass to default kernel
|
228
|
+
* @return KernelInfo instance
|
229
|
+
*/
|
230
|
+
VALUE
|
231
|
+
KernelInfo_builtin(VALUE self, VALUE what, VALUE geometry)
|
232
|
+
{
|
233
|
+
KernelInfo *kernel;
|
234
|
+
KernelInfoType kernel_type;
|
235
|
+
GeometryInfo info;
|
236
|
+
|
237
|
+
Check_Type(geometry, T_STRING);
|
238
|
+
VALUE_TO_ENUM(what, kernel_type, KernelInfoType);
|
239
|
+
ParseGeometry(StringValueCStr(geometry), &info);
|
240
|
+
|
241
|
+
kernel = AcquireKernelBuiltIn(kernel_type, &info);
|
242
|
+
|
243
|
+
if (!kernel)
|
244
|
+
rb_raise(rb_eRuntimeError, "failed to acquire builtin kernel");
|
245
|
+
|
246
|
+
return Data_Wrap_Struct(self, NULL, rm_kernel_info_destroy, kernel);
|
247
|
+
}
|
data/ext/RMagick/rmmain.c
CHANGED
@@ -314,6 +314,7 @@ Init_RMagick2(void)
|
|
314
314
|
rb_define_method(Class_Image, "channel_depth", Image_channel_depth, -1);
|
315
315
|
rb_define_method(Class_Image, "channel_extrema", Image_channel_extrema, -1);
|
316
316
|
rb_define_method(Class_Image, "channel_mean", Image_channel_mean, -1);
|
317
|
+
rb_define_method(Class_Image, "channel_entropy", Image_channel_entropy, -1);
|
317
318
|
rb_define_method(Class_Image, "charcoal", Image_charcoal, -1);
|
318
319
|
rb_define_method(Class_Image, "chop", Image_chop, 4);
|
319
320
|
rb_define_method(Class_Image, "clut_channel", Image_clut_channel, -1);
|
@@ -335,6 +336,8 @@ Init_RMagick2(void)
|
|
335
336
|
rb_define_method(Class_Image, "contrast_stretch_channel", Image_contrast_stretch_channel, -1);
|
336
337
|
rb_define_method(Class_Image, "convolve", Image_convolve, 2);
|
337
338
|
rb_define_method(Class_Image, "convolve_channel", Image_convolve_channel, -1);
|
339
|
+
rb_define_method(Class_Image, "morphology", Image_morphology, 3);
|
340
|
+
rb_define_method(Class_Image, "morphology_channel", Image_morphology_channel, 4);
|
338
341
|
rb_define_method(Class_Image, "copy", Image_copy, 0);
|
339
342
|
rb_define_method(Class_Image, "crop", Image_crop, -1);
|
340
343
|
rb_define_method(Class_Image, "crop!", Image_crop_bang, -1);
|
@@ -748,6 +751,25 @@ Init_RMagick2(void)
|
|
748
751
|
DCL_ATTR_ACCESSOR(Info, units)
|
749
752
|
DCL_ATTR_ACCESSOR(Info, view)
|
750
753
|
|
754
|
+
/*-----------------------------------------------------------------------*/
|
755
|
+
/* Class Magick::KernelInfo */
|
756
|
+
/*-----------------------------------------------------------------------*/
|
757
|
+
|
758
|
+
Class_KernelInfo = rb_define_class_under(Module_Magick, "KernelInfo", rb_cObject);
|
759
|
+
|
760
|
+
rb_define_alloc_func(Class_KernelInfo, KernelInfo_alloc);
|
761
|
+
|
762
|
+
rb_define_method(Class_KernelInfo, "initialize", KernelInfo_initialize, 1);
|
763
|
+
rb_define_method(Class_KernelInfo, "zero_nans", KernelInfo_zero_nans, 0);
|
764
|
+
rb_define_method(Class_KernelInfo, "unity_add", KernelInfo_unity_add, 1);
|
765
|
+
rb_define_method(Class_KernelInfo, "show", KernelInfo_show, 0);
|
766
|
+
rb_define_method(Class_KernelInfo, "scale", KernelInfo_scale, 2);
|
767
|
+
rb_define_method(Class_KernelInfo, "scale_geometry", KernelInfo_scale_geometry, 1);
|
768
|
+
rb_define_method(Class_KernelInfo, "clone", KernelInfo_clone, 0);
|
769
|
+
rb_define_method(Class_KernelInfo, "dup", KernelInfo_clone, 0);
|
770
|
+
|
771
|
+
rb_define_singleton_method(Class_KernelInfo, "builtin", KernelInfo_builtin, 2);
|
772
|
+
|
751
773
|
|
752
774
|
/*-----------------------------------------------------------------------*/
|
753
775
|
/* Class Magick::Image::PolaroidOptions */
|
@@ -844,6 +866,7 @@ Init_RMagick2(void)
|
|
844
866
|
rb_define_method(Class_Enum, "to_i", Enum_to_i, 0);
|
845
867
|
rb_define_method(Class_Enum, "<=>", Enum_spaceship, 1);
|
846
868
|
rb_define_method(Class_Enum, "===", Enum_case_eq, 1);
|
869
|
+
rb_define_method(Class_Enum, "|", Enum_bitwise_or, 1);
|
847
870
|
|
848
871
|
// AlignType constants
|
849
872
|
DEF_ENUM(AlignType)
|
@@ -1552,6 +1575,79 @@ Init_RMagick2(void)
|
|
1552
1575
|
ENUMERATOR(LighterWeight)
|
1553
1576
|
END_ENUM
|
1554
1577
|
|
1578
|
+
// For KernelInfo scaling
|
1579
|
+
DEF_ENUM(GeometryFlags)
|
1580
|
+
ENUMERATOR(NormalizeValue)
|
1581
|
+
ENUMERATOR(CorrelateNormalizeValue)
|
1582
|
+
ENUMERATOR(PercentValue)
|
1583
|
+
END_ENUM
|
1584
|
+
|
1585
|
+
// Morphology methods
|
1586
|
+
DEF_ENUM(MorphologyMethod)
|
1587
|
+
ENUMERATOR(UndefinedMorphology)
|
1588
|
+
ENUMERATOR(ConvolveMorphology)
|
1589
|
+
ENUMERATOR(CorrelateMorphology)
|
1590
|
+
ENUMERATOR(ErodeMorphology)
|
1591
|
+
ENUMERATOR(DilateMorphology)
|
1592
|
+
ENUMERATOR(ErodeIntensityMorphology)
|
1593
|
+
ENUMERATOR(DilateIntensityMorphology)
|
1594
|
+
ENUMERATOR(DistanceMorphology)
|
1595
|
+
ENUMERATOR(OpenMorphology)
|
1596
|
+
ENUMERATOR(CloseMorphology)
|
1597
|
+
ENUMERATOR(OpenIntensityMorphology)
|
1598
|
+
ENUMERATOR(CloseIntensityMorphology)
|
1599
|
+
ENUMERATOR(SmoothMorphology)
|
1600
|
+
ENUMERATOR(EdgeInMorphology)
|
1601
|
+
ENUMERATOR(EdgeOutMorphology)
|
1602
|
+
ENUMERATOR(EdgeMorphology)
|
1603
|
+
ENUMERATOR(TopHatMorphology)
|
1604
|
+
ENUMERATOR(BottomHatMorphology)
|
1605
|
+
ENUMERATOR(HitAndMissMorphology)
|
1606
|
+
ENUMERATOR(ThinningMorphology)
|
1607
|
+
ENUMERATOR(ThickenMorphology)
|
1608
|
+
ENUMERATOR(VoronoiMorphology)
|
1609
|
+
END_ENUM
|
1610
|
+
|
1611
|
+
DEF_ENUM(KernelInfoType)
|
1612
|
+
ENUMERATOR(UndefinedKernel)
|
1613
|
+
ENUMERATOR(UnityKernel)
|
1614
|
+
ENUMERATOR(GaussianKernel)
|
1615
|
+
ENUMERATOR(DoGKernel)
|
1616
|
+
ENUMERATOR(LoGKernel)
|
1617
|
+
ENUMERATOR(BlurKernel)
|
1618
|
+
ENUMERATOR(CometKernel)
|
1619
|
+
ENUMERATOR(LaplacianKernel)
|
1620
|
+
ENUMERATOR(SobelKernel)
|
1621
|
+
ENUMERATOR(FreiChenKernel)
|
1622
|
+
ENUMERATOR(RobertsKernel)
|
1623
|
+
ENUMERATOR(PrewittKernel)
|
1624
|
+
ENUMERATOR(CompassKernel)
|
1625
|
+
ENUMERATOR(KirschKernel)
|
1626
|
+
ENUMERATOR(DiamondKernel)
|
1627
|
+
ENUMERATOR(SquareKernel)
|
1628
|
+
ENUMERATOR(RectangleKernel)
|
1629
|
+
ENUMERATOR(OctagonKernel)
|
1630
|
+
ENUMERATOR(DiskKernel)
|
1631
|
+
ENUMERATOR(PlusKernel)
|
1632
|
+
ENUMERATOR(CrossKernel)
|
1633
|
+
ENUMERATOR(RingKernel)
|
1634
|
+
ENUMERATOR(PeaksKernel)
|
1635
|
+
ENUMERATOR(EdgesKernel)
|
1636
|
+
ENUMERATOR(CornersKernel)
|
1637
|
+
ENUMERATOR(DiagonalsKernel)
|
1638
|
+
ENUMERATOR(LineEndsKernel)
|
1639
|
+
ENUMERATOR(LineJunctionsKernel)
|
1640
|
+
ENUMERATOR(RidgesKernel)
|
1641
|
+
ENUMERATOR(ConvexHullKernel)
|
1642
|
+
ENUMERATOR(ThinSEKernel)
|
1643
|
+
ENUMERATOR(SkeletonKernel)
|
1644
|
+
ENUMERATOR(ChebyshevKernel)
|
1645
|
+
ENUMERATOR(ManhattanKernel)
|
1646
|
+
ENUMERATOR(OctagonalKernel)
|
1647
|
+
ENUMERATOR(EuclideanKernel)
|
1648
|
+
ENUMERATOR(UserDefinedKernel)
|
1649
|
+
END_ENUM
|
1650
|
+
|
1555
1651
|
/*-----------------------------------------------------------------------*/
|
1556
1652
|
/* Struct classes */
|
1557
1653
|
/*-----------------------------------------------------------------------*/
|
data/ext/RMagick/rmutil.c
CHANGED
@@ -1445,6 +1445,7 @@ rm_progress_monitor(
|
|
1445
1445
|
const MagickSizeType sp,
|
1446
1446
|
void *client_data)
|
1447
1447
|
{
|
1448
|
+
#if !defined(_WIN32)
|
1448
1449
|
VALUE rval;
|
1449
1450
|
VALUE method, offset, span;
|
1450
1451
|
|
@@ -1468,6 +1469,9 @@ rm_progress_monitor(
|
|
1468
1469
|
RB_GC_GUARD(span);
|
1469
1470
|
|
1470
1471
|
return RTEST(rval) ? MagickTrue : MagickFalse;
|
1472
|
+
#else
|
1473
|
+
return MagickTrue;
|
1474
|
+
#endif
|
1471
1475
|
}
|
1472
1476
|
|
1473
1477
|
|
data/lib/rmagick/version.rb
CHANGED
data/lib/rmagick_internal.rb
CHANGED
@@ -8,6 +8,16 @@
|
|
8
8
|
# to the classes.
|
9
9
|
#==============================================================================
|
10
10
|
|
11
|
+
if RUBY_PLATFORM =~ /mingw/i
|
12
|
+
begin
|
13
|
+
require 'ruby_installer'
|
14
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).grep(/ImageMagick/i).each do |path|
|
15
|
+
RubyInstaller::Runtime.add_dll_directory(path)
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
require 'English'
|
12
22
|
require 'RMagick2.so'
|
13
23
|
|
@@ -17,11 +27,11 @@ module Magick
|
|
17
27
|
@exit_block_set_up = nil
|
18
28
|
|
19
29
|
class << self
|
20
|
-
def formats
|
30
|
+
def formats
|
21
31
|
@formats ||= init_formats
|
22
32
|
|
23
33
|
if block_given?
|
24
|
-
@formats.each{|k, v| yield k, v }
|
34
|
+
@formats.each { |k, v| yield k, v }
|
25
35
|
self
|
26
36
|
else
|
27
37
|
@formats
|
@@ -65,11 +75,11 @@ module Magick
|
|
65
75
|
|
66
76
|
attr_accessor :width, :height, :x, :y, :flag
|
67
77
|
|
68
|
-
def initialize(width=nil, height=nil, x=nil, y=nil, flag=nil)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
def initialize(width = nil, height = nil, x = nil, y = nil, flag = nil)
|
79
|
+
raise(ArgumentError, "width set to #{width}") if width.is_a? GeometryValue
|
80
|
+
raise(ArgumentError, "height set to #{height}") if height.is_a? GeometryValue
|
81
|
+
raise(ArgumentError, "x set to #{x}") if x.is_a? GeometryValue
|
82
|
+
raise(ArgumentError, "y set to #{y}") if y.is_a? GeometryValue
|
73
83
|
|
74
84
|
# Support floating-point width and height arguments so Geometry
|
75
85
|
# objects can be used to specify Image#density= arguments.
|
@@ -111,9 +121,7 @@ module Magick
|
|
111
121
|
else
|
112
122
|
Kernel.raise ArgumentError, 'invalid geometry format'
|
113
123
|
end
|
114
|
-
if str['%']
|
115
|
-
flag = PercentGeometry
|
116
|
-
end
|
124
|
+
flag = PercentGeometry if str['%']
|
117
125
|
Geometry.new(width, height, x, y, flag)
|
118
126
|
end
|
119
127
|
|
@@ -122,23 +130,19 @@ module Magick
|
|
122
130
|
str = ''
|
123
131
|
if @width > 0
|
124
132
|
fmt = @width.truncate == @width ? '%d' : '%.2f'
|
125
|
-
str <<
|
133
|
+
str << format(fmt, @width)
|
126
134
|
str << '%' if @flag == PercentGeometry
|
127
135
|
end
|
128
136
|
|
129
|
-
if (@width > 0 && @flag != PercentGeometry) || (@height > 0)
|
130
|
-
str << 'x'
|
131
|
-
end
|
137
|
+
str << 'x' if (@width > 0 && @flag != PercentGeometry) || (@height > 0)
|
132
138
|
|
133
139
|
if @height > 0
|
134
140
|
fmt = @height.truncate == @height ? '%d' : '%.2f'
|
135
|
-
str <<
|
141
|
+
str << format(fmt, @height)
|
136
142
|
str << '%' if @flag == PercentGeometry
|
137
143
|
end
|
138
|
-
str <<
|
139
|
-
if @flag != PercentGeometry
|
140
|
-
str << FLAGS[@flag.to_i]
|
141
|
-
end
|
144
|
+
str << format('%+d%+d', @x, @y) if @x != 0 || @y != 0
|
145
|
+
str << FLAGS[@flag.to_i] if @flag != PercentGeometry
|
142
146
|
str
|
143
147
|
end
|
144
148
|
end
|
@@ -167,7 +171,7 @@ module Magick
|
|
167
171
|
NormalWeight.to_i => 'normal',
|
168
172
|
BoldWeight.to_i => 'bold',
|
169
173
|
BolderWeight.to_i => 'bolder',
|
170
|
-
LighterWeight.to_i => 'lighter'
|
174
|
+
LighterWeight.to_i => 'lighter'
|
171
175
|
}.freeze
|
172
176
|
GRAVITY_NAMES = {
|
173
177
|
NorthWestGravity.to_i => 'northwest',
|
@@ -210,9 +214,9 @@ module Magick
|
|
210
214
|
|
211
215
|
def enquote(str)
|
212
216
|
if str.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(str)
|
213
|
-
|
217
|
+
str
|
214
218
|
else
|
215
|
-
|
219
|
+
'"' + str + '"'
|
216
220
|
end
|
217
221
|
end
|
218
222
|
|
@@ -221,18 +225,18 @@ module Magick
|
|
221
225
|
# Apply coordinate transformations to support scaling (s), rotation (r),
|
222
226
|
# and translation (t). Angles are specified in radians.
|
223
227
|
def affine(sx, rx, ry, sy, tx, ty)
|
224
|
-
primitive 'affine ' +
|
228
|
+
primitive 'affine ' + format('%g,%g,%g,%g,%g,%g', sx, rx, ry, sy, tx, ty)
|
225
229
|
end
|
226
230
|
|
227
231
|
# Draw an arc.
|
228
|
-
def arc(
|
229
|
-
primitive 'arc ' +
|
230
|
-
|
232
|
+
def arc(start_x, start_y, end_x, end_y, start_degrees, end_degrees)
|
233
|
+
primitive 'arc ' + format('%g,%g %g,%g %g,%g',
|
234
|
+
start_x, start_y, end_x, end_y, start_degrees, end_degrees)
|
231
235
|
end
|
232
236
|
|
233
237
|
# Draw a bezier curve.
|
234
238
|
def bezier(*points)
|
235
|
-
if points.length
|
239
|
+
if points.length.zero?
|
236
240
|
Kernel.raise ArgumentError, 'no points specified'
|
237
241
|
elsif points.length.odd?
|
238
242
|
Kernel.raise ArgumentError, 'odd number of arguments specified'
|
@@ -241,8 +245,8 @@ module Magick
|
|
241
245
|
end
|
242
246
|
|
243
247
|
# Draw a circle
|
244
|
-
def circle(
|
245
|
-
primitive 'circle ' +
|
248
|
+
def circle(origin_x, origin_y, perim_x, perim_y)
|
249
|
+
primitive 'circle ' + format('%g,%g %g,%g', origin_x, origin_y, perim_x, perim_y)
|
246
250
|
end
|
247
251
|
|
248
252
|
# Invoke a clip-path defined by def_clip_path.
|
@@ -252,33 +256,27 @@ module Magick
|
|
252
256
|
|
253
257
|
# Define the clipping rule.
|
254
258
|
def clip_rule(rule)
|
255
|
-
unless
|
256
|
-
Kernel.raise ArgumentError, "Unknown clipping rule #{rule}"
|
257
|
-
end
|
259
|
+
Kernel.raise ArgumentError, "Unknown clipping rule #{rule}" unless %w[evenodd nonzero].include?(rule.downcase)
|
258
260
|
primitive "clip-rule #{rule}"
|
259
261
|
end
|
260
262
|
|
261
263
|
# Define the clip units
|
262
264
|
def clip_units(unit)
|
263
|
-
unless
|
264
|
-
Kernel.raise ArgumentError, "Unknown clip unit #{unit}"
|
265
|
-
end
|
265
|
+
Kernel.raise ArgumentError, "Unknown clip unit #{unit}" unless %w[userspace userspaceonuse objectboundingbox].include?(unit.downcase)
|
266
266
|
primitive "clip-units #{unit}"
|
267
267
|
end
|
268
268
|
|
269
269
|
# Set color in image according to specified colorization rule. Rule is one of
|
270
270
|
# point, replace, floodfill, filltoborder,reset
|
271
271
|
def color(x, y, method)
|
272
|
-
unless
|
273
|
-
Kernel.raise ArgumentError, "Unknown PaintMethod: #{method}"
|
274
|
-
end
|
272
|
+
Kernel.raise ArgumentError, "Unknown PaintMethod: #{method}" unless PAINT_METHOD_NAMES.key?(method.to_i)
|
275
273
|
primitive "color #{x},#{y},#{PAINT_METHOD_NAMES[method.to_i]}"
|
276
274
|
end
|
277
275
|
|
278
276
|
# Specify EITHER the text decoration (none, underline, overline,
|
279
277
|
# line-through) OR the text solid background color (any color name or spec)
|
280
278
|
def decorate(decoration)
|
281
|
-
if
|
279
|
+
if DECORATION_TYPE_NAMES.key?(decoration.to_i)
|
282
280
|
primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}"
|
283
281
|
else
|
284
282
|
primitive "decorate #{enquote(decoration)}"
|
@@ -302,9 +300,9 @@ module Magick
|
|
302
300
|
end
|
303
301
|
|
304
302
|
# Draw an ellipse
|
305
|
-
def ellipse(
|
306
|
-
primitive 'ellipse ' +
|
307
|
-
|
303
|
+
def ellipse(origin_x, origin_y, width, height, arc_start, arc_end)
|
304
|
+
primitive 'ellipse ' + format('%g,%g %g,%g %g,%g',
|
305
|
+
origin_x, origin_y, width, height, arc_start, arc_end)
|
308
306
|
end
|
309
307
|
|
310
308
|
# Let anything through, but the only defined argument
|
@@ -317,8 +315,8 @@ module Magick
|
|
317
315
|
def fill(colorspec)
|
318
316
|
primitive "fill #{enquote(colorspec)}"
|
319
317
|
end
|
320
|
-
|
321
|
-
|
318
|
+
alias fill_color fill
|
319
|
+
alias fill_pattern fill
|
322
320
|
|
323
321
|
# Specify fill opacity (use "xx%" to indicate percentage)
|
324
322
|
def fill_opacity(opacity)
|
@@ -326,9 +324,7 @@ module Magick
|
|
326
324
|
end
|
327
325
|
|
328
326
|
def fill_rule(rule)
|
329
|
-
unless
|
330
|
-
Kernel.raise ArgumentError, "Unknown fill rule #{rule}"
|
331
|
-
end
|
327
|
+
Kernel.raise ArgumentError, "Unknown fill rule #{rule}" unless %w[evenodd nonzero].include?(rule.downcase)
|
332
328
|
primitive "fill-rule #{rule}"
|
333
329
|
end
|
334
330
|
|
@@ -342,23 +338,19 @@ module Magick
|
|
342
338
|
end
|
343
339
|
|
344
340
|
def font_stretch(stretch)
|
345
|
-
unless
|
346
|
-
Kernel.raise ArgumentError, 'Unknown stretch type'
|
347
|
-
end
|
341
|
+
Kernel.raise ArgumentError, 'Unknown stretch type' unless STRETCH_TYPE_NAMES.key?(stretch.to_i)
|
348
342
|
primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}"
|
349
343
|
end
|
350
344
|
|
351
345
|
def font_style(style)
|
352
|
-
unless
|
353
|
-
Kernel.raise ArgumentError, 'Unknown style type'
|
354
|
-
end
|
346
|
+
Kernel.raise ArgumentError, 'Unknown style type' unless STYLE_TYPE_NAMES.key?(style.to_i)
|
355
347
|
primitive "font-style #{STYLE_TYPE_NAMES[style.to_i]}"
|
356
348
|
end
|
357
349
|
|
358
350
|
# The font weight argument can be either a font weight
|
359
351
|
# constant or [100,200,...,900]
|
360
352
|
def font_weight(weight)
|
361
|
-
if
|
353
|
+
if FONT_WEIGHT_NAMES.key?(weight.to_i)
|
362
354
|
primitive "font-weight #{FONT_WEIGHT_NAMES[weight.to_i]}"
|
363
355
|
else
|
364
356
|
primitive "font-weight #{weight}"
|
@@ -368,9 +360,7 @@ module Magick
|
|
368
360
|
# Specify the text positioning gravity, one of:
|
369
361
|
# NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
|
370
362
|
def gravity(grav)
|
371
|
-
unless
|
372
|
-
Kernel.raise ArgumentError, 'Unknown text positioning gravity'
|
373
|
-
end
|
363
|
+
Kernel.raise ArgumentError, 'Unknown text positioning gravity' unless GRAVITY_NAMES.key?(grav.to_i)
|
374
364
|
primitive "gravity #{GRAVITY_NAMES[grav.to_i]}"
|
375
365
|
end
|
376
366
|
|
@@ -411,26 +401,22 @@ module Magick
|
|
411
401
|
end
|
412
402
|
|
413
403
|
# Draw a line
|
414
|
-
def line(
|
415
|
-
primitive 'line ' +
|
404
|
+
def line(start_x, start_y, end_x, end_y)
|
405
|
+
primitive 'line ' + format('%g,%g %g,%g', start_x, start_y, end_x, end_y)
|
416
406
|
end
|
417
407
|
|
418
408
|
# Set matte (make transparent) in image according to the specified
|
419
409
|
# colorization rule
|
420
410
|
def matte(x, y, method)
|
421
|
-
unless
|
422
|
-
Kernel.raise ArgumentError, 'Unknown paint method'
|
423
|
-
end
|
411
|
+
Kernel.raise ArgumentError, 'Unknown paint method' unless PAINT_METHOD_NAMES.key?(method.to_i)
|
424
412
|
primitive "matte #{x},#{y} #{PAINT_METHOD_NAMES[method.to_i]}"
|
425
413
|
end
|
426
414
|
|
427
415
|
# Specify drawing fill and stroke opacities. If the value is a string
|
428
416
|
# ending with a %, the number will be multiplied by 0.01.
|
429
417
|
def opacity(opacity)
|
430
|
-
if (Numeric
|
431
|
-
if opacity < 0 || opacity > 1.0
|
432
|
-
Kernel.raise ArgumentError, 'opacity must be >= 0 and <= 1.0'
|
433
|
-
end
|
418
|
+
if opacity.is_a?(Numeric)
|
419
|
+
Kernel.raise ArgumentError, 'opacity must be >= 0 and <= 1.0' if opacity < 0 || opacity > 1.0
|
434
420
|
end
|
435
421
|
primitive "opacity #{opacity}"
|
436
422
|
end
|
@@ -466,11 +452,11 @@ module Magick
|
|
466
452
|
def pointsize(points)
|
467
453
|
primitive "font-size #{points}"
|
468
454
|
end
|
469
|
-
|
455
|
+
alias font_size pointsize
|
470
456
|
|
471
457
|
# Draw a polygon
|
472
458
|
def polygon(*points)
|
473
|
-
if points.length
|
459
|
+
if points.length.zero?
|
474
460
|
Kernel.raise ArgumentError, 'no points specified'
|
475
461
|
elsif points.length.odd?
|
476
462
|
Kernel.raise ArgumentError, 'odd number of points specified'
|
@@ -480,7 +466,7 @@ module Magick
|
|
480
466
|
|
481
467
|
# Draw a polyline
|
482
468
|
def polyline(*points)
|
483
|
-
if points.length
|
469
|
+
if points.length.zero?
|
484
470
|
Kernel.raise ArgumentError, 'no points specified'
|
485
471
|
elsif points.length.odd?
|
486
472
|
Kernel.raise ArgumentError, 'odd number of points specified'
|
@@ -495,11 +481,11 @@ module Magick
|
|
495
481
|
# pop('pattern')
|
496
482
|
|
497
483
|
def pop(*what)
|
498
|
-
if what.length
|
484
|
+
if what.length.zero?
|
499
485
|
primitive 'pop graphic-context'
|
500
486
|
else
|
501
487
|
# to_s allows a Symbol to be used instead of a String
|
502
|
-
primitive 'pop ' + what.map
|
488
|
+
primitive 'pop ' + what.map(&:to_s).join(' ')
|
503
489
|
end
|
504
490
|
end
|
505
491
|
|
@@ -509,18 +495,18 @@ module Magick
|
|
509
495
|
# push('gradient')
|
510
496
|
# push('pattern')
|
511
497
|
def push(*what)
|
512
|
-
if what.length
|
498
|
+
if what.length.zero?
|
513
499
|
primitive 'push graphic-context'
|
514
500
|
else
|
515
501
|
# to_s allows a Symbol to be used instead of a String
|
516
|
-
primitive 'push ' + what.map
|
502
|
+
primitive 'push ' + what.map(&:to_s).join(' ')
|
517
503
|
end
|
518
504
|
end
|
519
505
|
|
520
506
|
# Draw a rectangle
|
521
507
|
def rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y)
|
522
|
-
primitive 'rectangle ' +
|
523
|
-
|
508
|
+
primitive 'rectangle ' + format('%g,%g %g,%g',
|
509
|
+
upper_left_x, upper_left_y, lower_right_x, lower_right_y)
|
524
510
|
end
|
525
511
|
|
526
512
|
# Specify coordinate space rotation. "angle" is measured in degrees
|
@@ -530,8 +516,8 @@ module Magick
|
|
530
516
|
|
531
517
|
# Draw a rectangle with rounded corners
|
532
518
|
def roundrectangle(center_x, center_y, width, height, corner_width, corner_height)
|
533
|
-
primitive 'roundrectangle ' +
|
534
|
-
|
519
|
+
primitive 'roundrectangle ' + format('%g,%g,%g,%g,%g,%g',
|
520
|
+
center_x, center_y, width, height, corner_width, corner_height)
|
535
521
|
end
|
536
522
|
|
537
523
|
# Specify scaling to be applied to coordinate space on subsequent drawing commands.
|
@@ -551,8 +537,8 @@ module Magick
|
|
551
537
|
def stroke(colorspec)
|
552
538
|
primitive "stroke #{enquote(colorspec)}"
|
553
539
|
end
|
554
|
-
|
555
|
-
|
540
|
+
alias stroke_color stroke
|
541
|
+
alias stroke_pattern stroke
|
556
542
|
|
557
543
|
# Specify if stroke should be antialiased or not
|
558
544
|
def stroke_antialias(bool)
|
@@ -562,41 +548,33 @@ module Magick
|
|
562
548
|
|
563
549
|
# Specify a stroke dash pattern
|
564
550
|
def stroke_dasharray(*list)
|
565
|
-
if list.length
|
551
|
+
if list.length.zero?
|
566
552
|
primitive 'stroke-dasharray none'
|
567
553
|
else
|
568
554
|
list.each do |x|
|
569
|
-
if x <= 0
|
570
|
-
Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)"
|
571
|
-
end
|
555
|
+
Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)" if x <= 0
|
572
556
|
end
|
573
557
|
primitive "stroke-dasharray #{list.join(',')}"
|
574
558
|
end
|
575
559
|
end
|
576
560
|
|
577
561
|
# Specify the initial offset in the dash pattern
|
578
|
-
def stroke_dashoffset(value=0)
|
562
|
+
def stroke_dashoffset(value = 0)
|
579
563
|
primitive "stroke-dashoffset #{value}"
|
580
564
|
end
|
581
565
|
|
582
566
|
def stroke_linecap(value)
|
583
|
-
unless
|
584
|
-
Kernel.raise ArgumentError, "Unknown linecap type: #{value}"
|
585
|
-
end
|
567
|
+
Kernel.raise ArgumentError, "Unknown linecap type: #{value}" unless %w[butt round square].include?(value.downcase)
|
586
568
|
primitive "stroke-linecap #{value}"
|
587
569
|
end
|
588
570
|
|
589
571
|
def stroke_linejoin(value)
|
590
|
-
unless
|
591
|
-
Kernel.raise ArgumentError, "Unknown linejoin type: #{value}"
|
592
|
-
end
|
572
|
+
Kernel.raise ArgumentError, "Unknown linejoin type: #{value}" unless %w[round miter bevel].include?(value.downcase)
|
593
573
|
primitive "stroke-linejoin #{value}"
|
594
574
|
end
|
595
575
|
|
596
576
|
def stroke_miterlimit(value)
|
597
|
-
if value < 1
|
598
|
-
Kernel.raise ArgumentError, 'miterlimit must be >= 1'
|
599
|
-
end
|
577
|
+
Kernel.raise ArgumentError, 'miterlimit must be >= 1' if value < 1
|
600
578
|
primitive "stroke-miterlimit #{value}"
|
601
579
|
end
|
602
580
|
|
@@ -613,37 +591,31 @@ module Magick
|
|
613
591
|
|
614
592
|
# Draw text at position x,y. Add quotes to text that is not already quoted.
|
615
593
|
def text(x, y, text)
|
616
|
-
if text.to_s.empty?
|
617
|
-
Kernel.raise ArgumentError, 'missing text argument'
|
618
|
-
end
|
594
|
+
Kernel.raise ArgumentError, 'missing text argument' if text.to_s.empty?
|
619
595
|
if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
|
620
|
-
|
596
|
+
# text already quoted
|
621
597
|
elsif !text['\'']
|
622
|
-
text = '\''+text+'\''
|
598
|
+
text = '\'' + text + '\''
|
623
599
|
elsif !text['"']
|
624
|
-
text = '"'+text+'"'
|
600
|
+
text = '"' + text + '"'
|
625
601
|
elsif !(text['{'] || text['}'])
|
626
|
-
text = '{'+text+'}'
|
602
|
+
text = '{' + text + '}'
|
627
603
|
else
|
628
604
|
# escape existing braces, surround with braces
|
629
|
-
text = '{' +
|
605
|
+
text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
|
630
606
|
end
|
631
607
|
primitive "text #{x},#{y} #{text}"
|
632
608
|
end
|
633
609
|
|
634
610
|
# Specify text alignment relative to a given point
|
635
611
|
def text_align(alignment)
|
636
|
-
unless
|
637
|
-
Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}"
|
638
|
-
end
|
612
|
+
Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}" unless ALIGN_TYPE_NAMES.key?(alignment.to_i)
|
639
613
|
primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}"
|
640
614
|
end
|
641
615
|
|
642
616
|
# SVG-compatible version of text_align
|
643
617
|
def text_anchor(anchor)
|
644
|
-
unless
|
645
|
-
Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}"
|
646
|
-
end
|
618
|
+
Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}" unless ANCHOR_TYPE_NAMES.key?(anchor.to_i)
|
647
619
|
primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}"
|
648
620
|
end
|
649
621
|
|
@@ -776,7 +748,7 @@ module Magick
|
|
776
748
|
class Image
|
777
749
|
include Comparable
|
778
750
|
|
779
|
-
|
751
|
+
alias affinity remap
|
780
752
|
|
781
753
|
# Provide an alternate version of Draw#annotate, for folks who
|
782
754
|
# want to find it in this class.
|
@@ -830,7 +802,7 @@ module Magick
|
|
830
802
|
# Thanks to Russell Norris!
|
831
803
|
def each_pixel
|
832
804
|
get_pixels(0, 0, columns, rows).each_with_index do |p, n|
|
833
|
-
yield(p, n%columns, n/columns)
|
805
|
+
yield(p, n % columns, n / columns)
|
834
806
|
end
|
835
807
|
self
|
836
808
|
end
|
@@ -841,13 +813,11 @@ module Magick
|
|
841
813
|
# arrays.
|
842
814
|
def get_exif_by_entry(*entry)
|
843
815
|
ary = []
|
844
|
-
if entry.length
|
816
|
+
if entry.length.zero?
|
845
817
|
exif_data = self['EXIF:*']
|
846
|
-
if exif_data
|
847
|
-
exif_data.split("\n").each { |exif| ary.push(exif.split('=')) }
|
848
|
-
end
|
818
|
+
exif_data.split("\n").each { |exif| ary.push(exif.split('=')) } if exif_data
|
849
819
|
else
|
850
|
-
get_exif_by_entry
|
820
|
+
get_exif_by_entry # ensure properties is populated with exif data
|
851
821
|
entry.each do |name|
|
852
822
|
rval = self["EXIF:#{name}"]
|
853
823
|
ary.push([name, rval])
|
@@ -859,19 +829,19 @@ module Magick
|
|
859
829
|
# Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
|
860
830
|
def get_exif_by_number(*tag)
|
861
831
|
hash = {}
|
862
|
-
if tag.length
|
832
|
+
if tag.length.zero?
|
863
833
|
exif_data = self['EXIF:!']
|
864
834
|
if exif_data
|
865
835
|
exif_data.split("\n").each do |exif|
|
866
836
|
tag, value = exif.split('=')
|
867
|
-
tag = tag[1,4].hex
|
837
|
+
tag = tag[1, 4].hex
|
868
838
|
hash[tag] = value
|
869
839
|
end
|
870
840
|
end
|
871
841
|
else
|
872
|
-
get_exif_by_number
|
842
|
+
get_exif_by_number # ensure properties is populated with exif data
|
873
843
|
tag.each do |num|
|
874
|
-
rval = self['#%04X'
|
844
|
+
rval = self[format('#%04X', num.to_i)]
|
875
845
|
hash[num] = rval == 'unknown' ? nil : rval
|
876
846
|
end
|
877
847
|
end
|
@@ -881,7 +851,7 @@ module Magick
|
|
881
851
|
# Retrieve IPTC information by record number:dataset tag constant defined in
|
882
852
|
# Magick::IPTC, above.
|
883
853
|
def get_iptc_dataset(ds)
|
884
|
-
self['IPTC:'+ds]
|
854
|
+
self['IPTC:' + ds]
|
885
855
|
end
|
886
856
|
|
887
857
|
# Iterate over IPTC record number:dataset tags, yield for each non-nil dataset
|
@@ -909,7 +879,7 @@ module Magick
|
|
909
879
|
# look like they're in the old order.
|
910
880
|
|
911
881
|
# (Thanks to Al Evans for the suggestion.)
|
912
|
-
def level(black_point=0.0, white_point=nil, gamma=nil)
|
882
|
+
def level(black_point = 0.0, white_point = nil, gamma = nil)
|
913
883
|
black_point = Float(black_point)
|
914
884
|
|
915
885
|
white_point ||= Magick::QuantumRange - black_point
|
@@ -921,9 +891,7 @@ module Magick
|
|
921
891
|
|
922
892
|
if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs
|
923
893
|
gamma, white_point = white_point, gamma
|
924
|
-
unless gamma_arg
|
925
|
-
white_point = Magick::QuantumRange - black_point
|
926
|
-
end
|
894
|
+
white_point = Magick::QuantumRange - black_point unless gamma_arg
|
927
895
|
end
|
928
896
|
|
929
897
|
level2(black_point, white_point, gamma)
|
@@ -937,7 +905,7 @@ module Magick
|
|
937
905
|
def matte_point(x, y)
|
938
906
|
f = copy
|
939
907
|
f.opacity = OpaqueOpacity unless f.matte
|
940
|
-
pixel = f.pixel_color(x,y)
|
908
|
+
pixel = f.pixel_color(x, y)
|
941
909
|
pixel.opacity = TransparentOpacity
|
942
910
|
f.pixel_color(x, y, pixel)
|
943
911
|
f
|
@@ -978,34 +946,34 @@ module Magick
|
|
978
946
|
|
979
947
|
# Force an image to exact dimensions without changing the aspect ratio.
|
980
948
|
# Resize and crop if necessary. (Thanks to Jerett Taylor!)
|
981
|
-
def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity)
|
949
|
+
def resize_to_fill(ncols, nrows = nil, gravity = CenterGravity)
|
982
950
|
copy.resize_to_fill!(ncols, nrows, gravity)
|
983
951
|
end
|
984
952
|
|
985
|
-
def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity)
|
953
|
+
def resize_to_fill!(ncols, nrows = nil, gravity = CenterGravity)
|
986
954
|
nrows ||= ncols
|
987
955
|
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)
|
956
|
+
scale = [ncols / columns.to_f, nrows / rows.to_f].max
|
957
|
+
resize!(scale * columns + 0.5, scale * rows + 0.5)
|
990
958
|
end
|
991
959
|
crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows
|
992
960
|
self
|
993
961
|
end
|
994
962
|
|
995
963
|
# Preserve aliases used < RMagick 2.0.1
|
996
|
-
|
997
|
-
|
964
|
+
alias crop_resized resize_to_fill
|
965
|
+
alias crop_resized! resize_to_fill!
|
998
966
|
|
999
967
|
# Convenience method to resize retaining the aspect ratio.
|
1000
968
|
# (Thanks to Robert Manni!)
|
1001
|
-
def resize_to_fit(cols, rows=nil)
|
969
|
+
def resize_to_fit(cols, rows = nil)
|
1002
970
|
rows ||= cols
|
1003
971
|
change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
|
1004
972
|
resize(ncols, nrows)
|
1005
973
|
end
|
1006
974
|
end
|
1007
975
|
|
1008
|
-
def resize_to_fit!(cols, rows=nil)
|
976
|
+
def resize_to_fit!(cols, rows = nil)
|
1009
977
|
rows ||= cols
|
1010
978
|
change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
|
1011
979
|
resize!(ncols, nrows)
|
@@ -1028,16 +996,14 @@ module Magick
|
|
1028
996
|
def view(x, y, width, height)
|
1029
997
|
view = View.new(self, x, y, width, height)
|
1030
998
|
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
return nil
|
1038
|
-
else
|
1039
|
-
return view
|
999
|
+
return view unless block_given?
|
1000
|
+
|
1001
|
+
begin
|
1002
|
+
yield(view)
|
1003
|
+
ensure
|
1004
|
+
view.sync
|
1040
1005
|
end
|
1006
|
+
nil
|
1041
1007
|
end
|
1042
1008
|
|
1043
1009
|
# Magick::Image::View class
|
@@ -1047,12 +1013,8 @@ module Magick
|
|
1047
1013
|
|
1048
1014
|
def initialize(img, x, y, width, height)
|
1049
1015
|
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
|
1016
|
+
Kernel.raise ArgumentError, "invalid geometry (#{width}x#{height}+#{x}+#{y})" if width <= 0 || height <= 0
|
1017
|
+
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
1018
|
@view = img.get_pixels(x, y, width, height)
|
1057
1019
|
@img = img
|
1058
1020
|
@x = x
|
@@ -1069,7 +1031,7 @@ module Magick
|
|
1069
1031
|
end
|
1070
1032
|
|
1071
1033
|
# Store changed pixels back to image
|
1072
|
-
def sync(force=false)
|
1034
|
+
def sync(force = false)
|
1073
1035
|
@img.store_pixels(x, y, width, height, @view) if @dirty || force
|
1074
1036
|
@dirty || force
|
1075
1037
|
end
|
@@ -1078,7 +1040,7 @@ module Magick
|
|
1078
1040
|
# true, don't change it back to false!
|
1079
1041
|
def update(rows)
|
1080
1042
|
@dirty = true
|
1081
|
-
rows.delete_observer(self)
|
1043
|
+
rows.delete_observer(self) # No need to tell us again.
|
1082
1044
|
nil
|
1083
1045
|
end
|
1084
1046
|
|
@@ -1088,7 +1050,7 @@ module Magick
|
|
1088
1050
|
include Observable
|
1089
1051
|
|
1090
1052
|
# Define a getter and a setter for each channel.
|
1091
|
-
[
|
1053
|
+
%i[red green blue opacity].each do |c|
|
1092
1054
|
module_eval <<-END_EVAL
|
1093
1055
|
def #{c}
|
1094
1056
|
return collect { |p| p.#{c} }
|
@@ -1099,7 +1061,7 @@ module Magick
|
|
1099
1061
|
notify_observers(self)
|
1100
1062
|
nil
|
1101
1063
|
end
|
1102
|
-
|
1064
|
+
END_EVAL
|
1103
1065
|
end
|
1104
1066
|
end # class Magick::Image::View::Pixels
|
1105
1067
|
|
@@ -1119,7 +1081,7 @@ module Magick
|
|
1119
1081
|
|
1120
1082
|
# Both View::Pixels and Magick::Pixel implement Observable
|
1121
1083
|
if @unique
|
1122
|
-
pixels = @view[@rows[0]
|
1084
|
+
pixels = @view[@rows[0] * @width + @cols[0]]
|
1123
1085
|
pixels.add_observer(self)
|
1124
1086
|
else
|
1125
1087
|
pixels = View::Pixels.new
|
@@ -1133,8 +1095,8 @@ module Magick
|
|
1133
1095
|
end
|
1134
1096
|
|
1135
1097
|
def []=(*args)
|
1136
|
-
rv = args.delete_at(-1)
|
1137
|
-
unless rv.is_a?(Pixel)
|
1098
|
+
rv = args.delete_at(-1) # get rvalue
|
1099
|
+
unless rv.is_a?(Pixel) # must be a Pixel or a color name
|
1138
1100
|
begin
|
1139
1101
|
rv = Pixel.from_color(rv)
|
1140
1102
|
rescue TypeError
|
@@ -1159,7 +1121,7 @@ module Magick
|
|
1159
1121
|
private
|
1160
1122
|
|
1161
1123
|
def cols(*args)
|
1162
|
-
@cols = args[0]
|
1124
|
+
@cols = args[0] # remove the outermost array
|
1163
1125
|
@unique = false
|
1164
1126
|
|
1165
1127
|
# Convert @rows to an Enumerable object
|
@@ -1173,12 +1135,8 @@ module Magick
|
|
1173
1135
|
@rows = @rows.first
|
1174
1136
|
else
|
1175
1137
|
@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
|
1138
|
+
@rows += @height if @rows < 0
|
1139
|
+
Kernel.raise IndexError, "index [#{@rows}] out of range" if @rows < 0 || @rows > @height - 1
|
1182
1140
|
# Convert back to an array
|
1183
1141
|
@rows = Array.new(1, @rows)
|
1184
1142
|
@unique = true
|
@@ -1189,27 +1147,23 @@ module Magick
|
|
1189
1147
|
length = Integer(@rows[1])
|
1190
1148
|
|
1191
1149
|
# Negative start -> start from last row
|
1192
|
-
if start < 0
|
1193
|
-
start += @height
|
1194
|
-
end
|
1150
|
+
start += @height if start < 0
|
1195
1151
|
|
1196
1152
|
if start > @height || start < 0 || length < 0
|
1197
1153
|
Kernel.raise IndexError, "index [#{@rows.first}] out of range"
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
length = [length, 0].max
|
1202
|
-
end
|
1154
|
+
elsif start + length > @height
|
1155
|
+
length = @height - length
|
1156
|
+
length = [length, 0].max
|
1203
1157
|
end
|
1204
1158
|
# Create a Range for the specified set of rows
|
1205
|
-
@rows = Range.new(start, start+length, true)
|
1159
|
+
@rows = Range.new(start, start + length, true)
|
1206
1160
|
end
|
1207
1161
|
|
1208
1162
|
case @cols.length
|
1209
|
-
when 0
|
1210
|
-
@cols = Range.new(0, @width, true)
|
1163
|
+
when 0 # all rows
|
1164
|
+
@cols = Range.new(0, @width, true) # convert to range
|
1211
1165
|
@unique = false
|
1212
|
-
when 1
|
1166
|
+
when 1 # Range, Array, or a single integer
|
1213
1167
|
# if the single element is already an Enumerable
|
1214
1168
|
# object, get it.
|
1215
1169
|
if @cols.first.respond_to? :each
|
@@ -1217,12 +1171,8 @@ module Magick
|
|
1217
1171
|
@unique = false
|
1218
1172
|
else
|
1219
1173
|
@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
|
1174
|
+
@cols += @width if @cols < 0
|
1175
|
+
Kernel.raise IndexError, "index [#{@cols}] out of range" if @cols < 0 || @cols > @width - 1
|
1226
1176
|
# Convert back to array
|
1227
1177
|
@cols = Array.new(1, @cols)
|
1228
1178
|
@unique &&= true
|
@@ -1233,20 +1183,16 @@ module Magick
|
|
1233
1183
|
length = Integer(@cols[1])
|
1234
1184
|
|
1235
1185
|
# Negative start -> start from last row
|
1236
|
-
if start < 0
|
1237
|
-
start += @width
|
1238
|
-
end
|
1186
|
+
start += @width if start < 0
|
1239
1187
|
|
1240
1188
|
if start > @width || start < 0 || length < 0
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
length = [length, 0].max
|
1246
|
-
end
|
1189
|
+
# nop
|
1190
|
+
elsif start + length > @width
|
1191
|
+
length = @width - length
|
1192
|
+
length = [length, 0].max
|
1247
1193
|
end
|
1248
1194
|
# Create a Range for the specified set of columns
|
1249
|
-
@cols = Range.new(start, start+length, true)
|
1195
|
+
@cols = Range.new(start, start + length, true)
|
1250
1196
|
@unique = false
|
1251
1197
|
end
|
1252
1198
|
end
|
@@ -1257,20 +1203,16 @@ module Magick
|
|
1257
1203
|
maxcols = @width - 1
|
1258
1204
|
|
1259
1205
|
@rows.each do |j|
|
1260
|
-
if j > maxrows
|
1261
|
-
Kernel.raise IndexError, "index [#{j}] out of range"
|
1262
|
-
end
|
1206
|
+
Kernel.raise IndexError, "index [#{j}] out of range" if j > maxrows
|
1263
1207
|
@cols.each do |i|
|
1264
|
-
if i > maxcols
|
1265
|
-
|
1266
|
-
end
|
1267
|
-
yield j*@width + i
|
1208
|
+
Kernel.raise IndexError, "index [#{i}] out of range" if i > maxcols
|
1209
|
+
yield j * @width + i
|
1268
1210
|
end
|
1269
1211
|
end
|
1270
|
-
nil
|
1212
|
+
nil # useless return value
|
1271
1213
|
end
|
1272
1214
|
end # class Magick::Image::View::Rows
|
1273
|
-
end
|
1215
|
+
end # class Magick::Image::View
|
1274
1216
|
end # class Magick::Image
|
1275
1217
|
|
1276
1218
|
class ImageList
|
@@ -1281,23 +1223,21 @@ module Magick
|
|
1281
1223
|
private
|
1282
1224
|
|
1283
1225
|
def get_current
|
1284
|
-
|
1226
|
+
@images[@scene].__id__
|
1227
|
+
rescue StandardError
|
1228
|
+
nil
|
1285
1229
|
end
|
1286
1230
|
|
1287
1231
|
protected
|
1288
1232
|
|
1289
1233
|
def is_an_image(obj)
|
1290
|
-
unless obj.is_a? Magick::Image
|
1291
|
-
Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)"
|
1292
|
-
end
|
1234
|
+
Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)" unless obj.is_a? Magick::Image
|
1293
1235
|
true
|
1294
1236
|
end
|
1295
1237
|
|
1296
1238
|
# Ensure array is always an array of Magick::Image objects
|
1297
1239
|
def is_an_image_array(ary)
|
1298
|
-
unless ary.respond_to? :each
|
1299
|
-
Kernel.raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)"
|
1300
|
-
end
|
1240
|
+
Kernel.raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)" unless ary.respond_to? :each
|
1301
1241
|
ary.each { |obj| is_an_image obj }
|
1302
1242
|
true
|
1303
1243
|
end
|
@@ -1305,7 +1245,7 @@ module Magick
|
|
1305
1245
|
# Find old current image, update scene number
|
1306
1246
|
# current is the id of the old current image.
|
1307
1247
|
def set_current(current)
|
1308
|
-
if length
|
1248
|
+
if length.zero?
|
1309
1249
|
self.scene = nil
|
1310
1250
|
return
|
1311
1251
|
# Don't bother looking for current image
|
@@ -1316,10 +1256,8 @@ module Magick
|
|
1316
1256
|
# Find last instance of "current" in the list.
|
1317
1257
|
# If "current" isn't in the list, set current to last image.
|
1318
1258
|
self.scene = length - 1
|
1319
|
-
each_with_index do |f,i|
|
1320
|
-
if f.__id__ == current
|
1321
|
-
self.scene = i
|
1322
|
-
end
|
1259
|
+
each_with_index do |f, i|
|
1260
|
+
self.scene = i if f.__id__ == current
|
1323
1261
|
end
|
1324
1262
|
return
|
1325
1263
|
end
|
@@ -1331,24 +1269,22 @@ module Magick
|
|
1331
1269
|
# Allow scene to be set to nil
|
1332
1270
|
def scene=(n)
|
1333
1271
|
if n.nil?
|
1334
|
-
Kernel.raise IndexError, 'scene number out of bounds' unless @images.length
|
1272
|
+
Kernel.raise IndexError, 'scene number out of bounds' unless @images.length.zero?
|
1335
1273
|
@scene = nil
|
1336
1274
|
return @scene
|
1337
|
-
elsif @images.length
|
1275
|
+
elsif @images.length.zero?
|
1338
1276
|
Kernel.raise IndexError, 'scene number out of bounds'
|
1339
1277
|
end
|
1340
1278
|
|
1341
1279
|
n = Integer(n)
|
1342
|
-
if n < 0 || n > length - 1
|
1343
|
-
Kernel.raise IndexError, 'scene number out of bounds'
|
1344
|
-
end
|
1280
|
+
Kernel.raise IndexError, 'scene number out of bounds' if n < 0 || n > length - 1
|
1345
1281
|
@scene = n
|
1346
1282
|
@scene
|
1347
1283
|
end
|
1348
1284
|
|
1349
1285
|
# All the binary operators work the same way.
|
1350
1286
|
# 'other' should be either an ImageList or an Array
|
1351
|
-
%w
|
1287
|
+
%w[& + - |].each do |op|
|
1352
1288
|
module_eval <<-END_BINOPS
|
1353
1289
|
def #{op}(other)
|
1354
1290
|
ilist = self.class.new
|
@@ -1368,13 +1304,11 @@ module Magick
|
|
1368
1304
|
END_BINOPS
|
1369
1305
|
end
|
1370
1306
|
|
1371
|
-
def *(
|
1372
|
-
unless
|
1373
|
-
Kernel.raise ArgumentError, "Integer required (#{n.class} given)"
|
1374
|
-
end
|
1307
|
+
def *(other)
|
1308
|
+
Kernel.raise ArgumentError, "Integer required (#{other.class} given)" unless other.is_a? Integer
|
1375
1309
|
current = get_current
|
1376
1310
|
ilist = self.class.new
|
1377
|
-
(@images *
|
1311
|
+
(@images * other).each { |image| ilist << image }
|
1378
1312
|
ilist.set_current current
|
1379
1313
|
ilist
|
1380
1314
|
end
|
@@ -1392,23 +1326,19 @@ module Magick
|
|
1392
1326
|
# return if A.scene != B.scene
|
1393
1327
|
# return A.length <=> B.length
|
1394
1328
|
def <=>(other)
|
1395
|
-
unless other.is_a? self.class
|
1396
|
-
Kernel.raise TypeError, "#{self.class} required (#{other.class} given)"
|
1397
|
-
end
|
1329
|
+
Kernel.raise TypeError, "#{self.class} required (#{other.class} given)" unless other.is_a? self.class
|
1398
1330
|
size = [length, other.length].min
|
1399
1331
|
size.times do |x|
|
1400
1332
|
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}"
|
1333
|
+
return r unless r.zero?
|
1409
1334
|
end
|
1335
|
+
return 0 if @scene.nil? && other.scene.nil?
|
1336
|
+
|
1337
|
+
Kernel.raise TypeError, "cannot convert nil into #{other.scene.class}" if @scene.nil? && !other.scene.nil?
|
1338
|
+
Kernel.raise TypeError, "cannot convert nil into #{scene.class}" if !@scene.nil? && other.scene.nil?
|
1410
1339
|
r = scene <=> other.scene
|
1411
|
-
return r unless r
|
1340
|
+
return r unless r.zero?
|
1341
|
+
|
1412
1342
|
length <=> other.length
|
1413
1343
|
end
|
1414
1344
|
|
@@ -1416,7 +1346,7 @@ module Magick
|
|
1416
1346
|
a = @images[*args]
|
1417
1347
|
if a.respond_to?(:each)
|
1418
1348
|
ilist = self.class.new
|
1419
|
-
a.each {|image| ilist << image}
|
1349
|
+
a.each { |image| ilist << image }
|
1420
1350
|
a = ilist
|
1421
1351
|
end
|
1422
1352
|
a
|
@@ -1436,15 +1366,15 @@ module Magick
|
|
1436
1366
|
obj
|
1437
1367
|
end
|
1438
1368
|
|
1439
|
-
[
|
1440
|
-
|
1369
|
+
%i[at each each_index empty? fetch
|
1370
|
+
first hash include? index length rindex sort!].each do |mth|
|
1441
1371
|
module_eval <<-END_SIMPLE_DELEGATES
|
1442
1372
|
def #{mth}(*args, &block)
|
1443
1373
|
@images.#{mth}(*args, &block)
|
1444
1374
|
end
|
1445
1375
|
END_SIMPLE_DELEGATES
|
1446
1376
|
end
|
1447
|
-
|
1377
|
+
alias size length
|
1448
1378
|
|
1449
1379
|
# Array#nitems is not available in 1.9
|
1450
1380
|
if Array.instance_methods.include?('nitems')
|
@@ -1469,7 +1399,7 @@ module Magick
|
|
1469
1399
|
current = get_current
|
1470
1400
|
a = @images.collect(&block)
|
1471
1401
|
ilist = self.class.new
|
1472
|
-
a.each {|image| ilist << image}
|
1402
|
+
a.each { |image| ilist << image }
|
1473
1403
|
ilist.set_current current
|
1474
1404
|
ilist
|
1475
1405
|
end
|
@@ -1491,48 +1421,45 @@ module Magick
|
|
1491
1421
|
|
1492
1422
|
# Return the current image
|
1493
1423
|
def cur_image
|
1494
|
-
unless @scene
|
1495
|
-
Kernel.raise IndexError, 'no images in this list'
|
1496
|
-
end
|
1424
|
+
Kernel.raise IndexError, 'no images in this list' unless @scene
|
1497
1425
|
@images[@scene]
|
1498
1426
|
end
|
1499
1427
|
|
1500
1428
|
# ImageList#map took over the "map" name. Use alternatives.
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1429
|
+
alias __map__ collect
|
1430
|
+
alias map! collect!
|
1431
|
+
alias __map__! collect!
|
1504
1432
|
|
1505
1433
|
# ImageMagic used affinity in 6.4.3, switch to remap in 6.4.4.
|
1506
|
-
|
1434
|
+
alias affinity remap
|
1507
1435
|
|
1508
1436
|
def compact
|
1509
1437
|
current = get_current
|
1510
1438
|
ilist = self.class.new
|
1511
1439
|
a = @images.compact
|
1512
|
-
a.each {|image| ilist << image}
|
1440
|
+
a.each { |image| ilist << image }
|
1513
1441
|
ilist.set_current current
|
1514
1442
|
ilist
|
1515
1443
|
end
|
1516
1444
|
|
1517
1445
|
def compact!
|
1518
1446
|
current = get_current
|
1519
|
-
a = @images.compact!
|
1447
|
+
a = @images.compact! # returns nil if no changes were made
|
1520
1448
|
set_current current
|
1521
1449
|
a.nil? ? nil : self
|
1522
1450
|
end
|
1523
1451
|
|
1524
1452
|
def concat(other)
|
1525
1453
|
is_an_image_array other
|
1526
|
-
other.each {|image| @images << image}
|
1527
|
-
@scene = length-1
|
1454
|
+
other.each { |image| @images << image }
|
1455
|
+
@scene = length - 1
|
1528
1456
|
self
|
1529
1457
|
end
|
1530
1458
|
|
1531
1459
|
# Set same delay for all images
|
1532
1460
|
def delay=(d)
|
1533
|
-
if Integer(d) < 0
|
1534
|
-
|
1535
|
-
end
|
1461
|
+
raise ArgumentError, 'delay must be greater than or equal to 0' if Integer(d) < 0
|
1462
|
+
|
1536
1463
|
@images.each { |f| f.delay = Integer(d) }
|
1537
1464
|
end
|
1538
1465
|
|
@@ -1560,7 +1487,7 @@ module Magick
|
|
1560
1487
|
|
1561
1488
|
def dup
|
1562
1489
|
ditto = self.class.new
|
1563
|
-
@images.each {|img| ditto << img}
|
1490
|
+
@images.each { |img| ditto << img }
|
1564
1491
|
ditto.scene = @scene
|
1565
1492
|
ditto.taint if tainted?
|
1566
1493
|
ditto
|
@@ -1591,18 +1518,16 @@ module Magick
|
|
1591
1518
|
current = get_current
|
1592
1519
|
a = @images.find_all(&block)
|
1593
1520
|
ilist = self.class.new
|
1594
|
-
a.each {|image| ilist << image}
|
1521
|
+
a.each { |image| ilist << image }
|
1595
1522
|
ilist.set_current current
|
1596
1523
|
ilist
|
1597
1524
|
end
|
1598
|
-
|
1525
|
+
alias select find_all
|
1599
1526
|
|
1600
1527
|
def from_blob(*blobs, &block)
|
1601
|
-
if
|
1602
|
-
Kernel.raise ArgumentError, 'no blobs given'
|
1603
|
-
end
|
1528
|
+
Kernel.raise ArgumentError, 'no blobs given' if blobs.length.zero?
|
1604
1529
|
blobs.each do |b|
|
1605
|
-
Magick::Image.from_blob(b, &block).each { |n| @images << n
|
1530
|
+
Magick::Image.from_blob(b, &block).each { |n| @images << n }
|
1606
1531
|
end
|
1607
1532
|
@scene = length - 1
|
1608
1533
|
self
|
@@ -1616,13 +1541,13 @@ module Magick
|
|
1616
1541
|
Magick::Image.read(f, &block).each { |n| @images << n }
|
1617
1542
|
end
|
1618
1543
|
if length > 0
|
1619
|
-
@scene = length - 1
|
1544
|
+
@scene = length - 1 # last image in array
|
1620
1545
|
end
|
1621
1546
|
self
|
1622
1547
|
end
|
1623
1548
|
|
1624
1549
|
def insert(index, *args)
|
1625
|
-
args.each {|image| is_an_image image}
|
1550
|
+
args.each { |image| is_an_image image }
|
1626
1551
|
current = get_current
|
1627
1552
|
@images.insert(index, *args)
|
1628
1553
|
set_current current
|
@@ -1632,27 +1557,25 @@ module Magick
|
|
1632
1557
|
# Call inspect for all the images
|
1633
1558
|
def inspect
|
1634
1559
|
img = []
|
1635
|
-
@images.each {|image| img << image.inspect }
|
1560
|
+
@images.each { |image| img << image.inspect }
|
1636
1561
|
img = '[' + img.join(",\n") + "]\nscene=#{@scene}"
|
1637
1562
|
end
|
1638
1563
|
|
1639
1564
|
# Set the number of iterations of an animated GIF
|
1640
1565
|
def iterations=(n)
|
1641
1566
|
n = Integer(n)
|
1642
|
-
if n < 0 || n >
|
1643
|
-
|
1644
|
-
end
|
1645
|
-
@images.each {|f| f.iterations=n}
|
1567
|
+
Kernel.raise ArgumentError, 'iterations must be between 0 and 65535' if n < 0 || n > 65_535
|
1568
|
+
@images.each { |f| f.iterations = n }
|
1646
1569
|
self
|
1647
1570
|
end
|
1648
1571
|
|
1649
1572
|
def last(*args)
|
1650
|
-
if args.length
|
1573
|
+
if args.length.zero?
|
1651
1574
|
a = @images.last
|
1652
1575
|
else
|
1653
1576
|
a = @images.last(*args)
|
1654
1577
|
ilist = self.class.new
|
1655
|
-
a.each {|img| ilist << img}
|
1578
|
+
a.each { |img| ilist << img }
|
1656
1579
|
@scene = a.length - 1
|
1657
1580
|
a = ilist
|
1658
1581
|
end
|
@@ -1662,28 +1585,28 @@ module Magick
|
|
1662
1585
|
# Custom marshal/unmarshal for Ruby 1.8.
|
1663
1586
|
def marshal_dump
|
1664
1587
|
ary = [@scene]
|
1665
|
-
@images.each {|i| ary << Marshal.dump(i)}
|
1588
|
+
@images.each { |i| ary << Marshal.dump(i) }
|
1666
1589
|
ary
|
1667
1590
|
end
|
1668
1591
|
|
1669
1592
|
def marshal_load(ary)
|
1670
1593
|
@scene = ary.shift
|
1671
1594
|
@images = []
|
1672
|
-
ary.each {|a| @images << Marshal.load(a)}
|
1595
|
+
ary.each { |a| @images << Marshal.load(a) }
|
1673
1596
|
end
|
1674
1597
|
|
1675
1598
|
# The ImageList class supports the Magick::Image class methods by simply sending
|
1676
1599
|
# the method to the current image. If the method isn't explicitly supported,
|
1677
1600
|
# send it to the current image in the array. If there are no images, send
|
1678
1601
|
# it up the line. Catch a NameError and emit a useful message.
|
1679
|
-
def method_missing(
|
1602
|
+
def method_missing(meth_id, *args, &block)
|
1680
1603
|
if @scene
|
1681
|
-
@images[@scene].send(
|
1604
|
+
@images[@scene].send(meth_id, *args, &block)
|
1682
1605
|
else
|
1683
1606
|
super
|
1684
1607
|
end
|
1685
1608
|
rescue NoMethodError
|
1686
|
-
Kernel.raise NoMethodError, "undefined method `#{
|
1609
|
+
Kernel.raise NoMethodError, "undefined method `#{meth_id.id2name}' for #{self.class}"
|
1687
1610
|
rescue Exception
|
1688
1611
|
$ERROR_POSITION.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
|
1689
1612
|
Kernel.raise
|
@@ -1697,19 +1620,17 @@ module Magick
|
|
1697
1620
|
def partition(&block)
|
1698
1621
|
a = @images.partition(&block)
|
1699
1622
|
t = self.class.new
|
1700
|
-
a[0].each { |img| t << img}
|
1623
|
+
a[0].each { |img| t << img }
|
1701
1624
|
t.set_current nil
|
1702
1625
|
f = self.class.new
|
1703
|
-
a[1].each { |img| f << img}
|
1626
|
+
a[1].each { |img| f << img }
|
1704
1627
|
f.set_current nil
|
1705
1628
|
[t, f]
|
1706
1629
|
end
|
1707
1630
|
|
1708
1631
|
# Ping files and concatenate the new images
|
1709
1632
|
def ping(*files, &block)
|
1710
|
-
if
|
1711
|
-
Kernel.raise ArgumentError, 'no files given'
|
1712
|
-
end
|
1633
|
+
Kernel.raise ArgumentError, 'no files given' if files.length.zero?
|
1713
1634
|
files.each do |f|
|
1714
1635
|
Magick::Image.ping(f, &block).each { |n| @images << n }
|
1715
1636
|
end
|
@@ -1719,7 +1640,7 @@ module Magick
|
|
1719
1640
|
|
1720
1641
|
def pop
|
1721
1642
|
current = get_current
|
1722
|
-
a = @images.pop
|
1643
|
+
a = @images.pop # can return nil
|
1723
1644
|
set_current current
|
1724
1645
|
a
|
1725
1646
|
end
|
@@ -1735,9 +1656,7 @@ module Magick
|
|
1735
1656
|
|
1736
1657
|
# Read files and concatenate the new images
|
1737
1658
|
def read(*files, &block)
|
1738
|
-
if
|
1739
|
-
Kernel.raise ArgumentError, 'no files given'
|
1740
|
-
end
|
1659
|
+
Kernel.raise ArgumentError, 'no files given' if files.length.zero?
|
1741
1660
|
files.each do |f|
|
1742
1661
|
Magick::Image.read(f, &block).each { |n| @images << n }
|
1743
1662
|
end
|
@@ -1750,7 +1669,7 @@ module Magick
|
|
1750
1669
|
current = get_current
|
1751
1670
|
ilist = self.class.new
|
1752
1671
|
a = @images.reject(&block)
|
1753
|
-
a.each {|image| ilist << image}
|
1672
|
+
a.each { |image| ilist << image }
|
1754
1673
|
ilist.set_current current
|
1755
1674
|
ilist
|
1756
1675
|
end
|
@@ -1767,18 +1686,19 @@ module Magick
|
|
1767
1686
|
is_an_image_array other
|
1768
1687
|
current = get_current
|
1769
1688
|
@images.clear
|
1770
|
-
other.each {|image| @images << image}
|
1771
|
-
@scene = length
|
1689
|
+
other.each { |image| @images << image }
|
1690
|
+
@scene = length.zero? ? nil : 0
|
1772
1691
|
set_current current
|
1773
1692
|
self
|
1774
1693
|
end
|
1775
1694
|
|
1776
1695
|
# Ensure respond_to? answers correctly when we are delegating to Image
|
1777
|
-
|
1778
|
-
def respond_to?(
|
1779
|
-
return true if __respond_to__?(
|
1696
|
+
alias __respond_to__? respond_to?
|
1697
|
+
def respond_to?(meth_id, priv = false)
|
1698
|
+
return true if __respond_to__?(meth_id, priv)
|
1699
|
+
|
1780
1700
|
if @scene
|
1781
|
-
@images[@scene].respond_to?(
|
1701
|
+
@images[@scene].respond_to?(meth_id, priv)
|
1782
1702
|
else
|
1783
1703
|
super
|
1784
1704
|
end
|
@@ -1787,7 +1707,7 @@ module Magick
|
|
1787
1707
|
def reverse
|
1788
1708
|
current = get_current
|
1789
1709
|
a = self.class.new
|
1790
|
-
@images.reverse_each {|image| a << image}
|
1710
|
+
@images.reverse_each { |image| a << image }
|
1791
1711
|
a.set_current current
|
1792
1712
|
a
|
1793
1713
|
end
|
@@ -1800,7 +1720,7 @@ module Magick
|
|
1800
1720
|
end
|
1801
1721
|
|
1802
1722
|
def reverse_each
|
1803
|
-
@images.reverse_each {|image| yield(image)}
|
1723
|
+
@images.reverse_each { |image| yield(image) }
|
1804
1724
|
self
|
1805
1725
|
end
|
1806
1726
|
|
@@ -1816,7 +1736,7 @@ module Magick
|
|
1816
1736
|
if slice
|
1817
1737
|
ilist = self.class.new
|
1818
1738
|
if slice.respond_to?(:each)
|
1819
|
-
slice.each {|image| ilist << image}
|
1739
|
+
slice.each { |image| ilist << image }
|
1820
1740
|
else
|
1821
1741
|
ilist << slice
|
1822
1742
|
end
|
@@ -1834,27 +1754,25 @@ module Magick
|
|
1834
1754
|
end
|
1835
1755
|
|
1836
1756
|
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
|
1757
|
+
Kernel.raise ArgumentError, 'ticks_per_second must be greater than or equal to 0' if Integer(t) < 0
|
1840
1758
|
@images.each { |f| f.ticks_per_second = Integer(t) }
|
1841
1759
|
end
|
1842
1760
|
|
1843
1761
|
def to_a
|
1844
1762
|
a = []
|
1845
|
-
@images.each {|image| a << image}
|
1763
|
+
@images.each { |image| a << image }
|
1846
1764
|
a
|
1847
1765
|
end
|
1848
1766
|
|
1849
1767
|
def uniq
|
1850
1768
|
current = get_current
|
1851
1769
|
a = self.class.new
|
1852
|
-
@images.uniq.each {|image| a << image}
|
1770
|
+
@images.uniq.each { |image| a << image }
|
1853
1771
|
a.set_current current
|
1854
1772
|
a
|
1855
1773
|
end
|
1856
1774
|
|
1857
|
-
def uniq!(*
|
1775
|
+
def uniq!(*_args)
|
1858
1776
|
current = get_current
|
1859
1777
|
a = @images.uniq!
|
1860
1778
|
set_current current
|
@@ -1872,12 +1790,12 @@ module Magick
|
|
1872
1790
|
def values_at(*args)
|
1873
1791
|
a = @images.values_at(*args)
|
1874
1792
|
a = self.class.new
|
1875
|
-
@images.values_at(*args).each {|image| a << image}
|
1793
|
+
@images.values_at(*args).each { |image| a << image }
|
1876
1794
|
a.scene = a.length - 1
|
1877
1795
|
a
|
1878
1796
|
end
|
1879
|
-
|
1880
|
-
|
1797
|
+
alias indexes values_at
|
1798
|
+
alias indices values_at
|
1881
1799
|
end # Magick::ImageList
|
1882
1800
|
|
1883
1801
|
# Collects non-specific optional method arguments
|
@@ -1914,21 +1832,21 @@ module Magick
|
|
1914
1832
|
# @dist is the number of pixels between hatch lines.
|
1915
1833
|
# See Magick::Draw examples.
|
1916
1834
|
class HatchFill
|
1917
|
-
def initialize(bgcolor, hatchcolor='white', dist=10)
|
1835
|
+
def initialize(bgcolor, hatchcolor = 'white', dist = 10)
|
1918
1836
|
@bgcolor = bgcolor
|
1919
1837
|
@hatchpixel = Pixel.from_color(hatchcolor)
|
1920
1838
|
@dist = dist
|
1921
1839
|
end
|
1922
1840
|
|
1923
|
-
def fill(img)
|
1841
|
+
def fill(img) # required
|
1924
1842
|
img.background_color = @bgcolor
|
1925
|
-
img.erase!
|
1843
|
+
img.erase! # sets image to background color
|
1926
1844
|
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)
|
1845
|
+
@dist.step((img.columns - 1) / @dist * @dist, @dist) do |x|
|
1846
|
+
img.store_pixels(x, 0, 1, img.rows, pixels)
|
1929
1847
|
end
|
1930
|
-
@dist.step((img.rows-1)
|
1931
|
-
img.store_pixels(0,y,img.columns,1,pixels)
|
1848
|
+
@dist.step((img.rows - 1) / @dist * @dist, @dist) do |y|
|
1849
|
+
img.store_pixels(0, y, img.columns, 1, pixels)
|
1932
1850
|
end
|
1933
1851
|
end
|
1934
1852
|
end
|