rmagick 2.13.2 → 4.2.2
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 +7 -0
- data/.codeclimate.yml +63 -0
- data/.editorconfig +17 -0
- data/.github/ISSUE_TEMPLATE.md +17 -0
- data/.github/workflows/ci.yml +107 -0
- data/.gitignore +25 -0
- data/.rspec +2 -0
- data/.rubocop.yml +37 -0
- data/.rubocop_todo.yml +449 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +1277 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +81 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +324 -0
- data/Rakefile +190 -0
- data/before_install_linux.sh +69 -0
- data/before_install_osx.sh +57 -0
- data/deprecated/RMagick.rb +6 -0
- data/ext/RMagick/extconf.rb +334 -333
- data/ext/RMagick/rmagick.c +129 -127
- data/ext/RMagick/rmagick.h +221 -320
- data/ext/RMagick/rmdraw.c +458 -767
- data/ext/RMagick/rmenum.c +305 -752
- data/ext/RMagick/rmfill.c +231 -199
- data/ext/RMagick/rmilist.c +437 -478
- data/ext/RMagick/rmimage.c +6130 -5342
- data/ext/RMagick/rminfo.c +695 -833
- data/ext/RMagick/rmkinfo.c +198 -0
- data/ext/RMagick/rmmain.c +752 -506
- data/ext/RMagick/rmmontage.c +94 -152
- data/ext/RMagick/rmpixel.c +619 -425
- data/ext/RMagick/rmstruct.c +206 -309
- data/ext/RMagick/rmutil.c +514 -344
- data/lib/rmagick/version.rb +5 -0
- data/lib/rmagick.rb +1 -0
- data/lib/rmagick_internal.rb +1922 -0
- data/lib/rvg/clippath.rb +35 -39
- data/lib/rvg/container.rb +123 -124
- data/lib/rvg/deep_equal.rb +45 -49
- data/lib/rvg/describable.rb +41 -47
- data/lib/rvg/embellishable.rb +380 -411
- data/lib/rvg/misc.rb +691 -711
- data/lib/rvg/paint.rb +43 -47
- data/lib/rvg/pathdata.rb +119 -125
- data/lib/rvg/rvg.rb +214 -213
- data/lib/rvg/stretchable.rb +153 -162
- data/lib/rvg/stylable.rb +111 -117
- data/lib/rvg/text.rb +169 -180
- data/lib/rvg/transformable.rb +121 -127
- data/lib/rvg/units.rb +58 -61
- data/rmagick.gemspec +36 -16
- metadata +188 -365
- data/ChangeLog +0 -773
- data/Doxyfile +0 -1514
- data/README-Mac-OSX.txt +0 -1
- data/README.html +0 -10
- data/build_tarball.rake +0 -215
- 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 -3269
- data/doc/ex/InitialCoords.rb +0 -23
- data/doc/ex/NewCoordSys.rb +0 -32
- data/doc/ex/OrigCoordSys.rb +0 -18
- data/doc/ex/PreserveAspectRatio.rb +0 -205
- data/doc/ex/RotateScale.rb +0 -37
- data/doc/ex/Skew.rb +0 -38
- data/doc/ex/Use01.rb +0 -16
- data/doc/ex/Use02.rb +0 -21
- data/doc/ex/Use03.rb +0 -16
- data/doc/ex/ViewBox.rb +0 -33
- data/doc/ex/adaptive_threshold.rb +0 -10
- data/doc/ex/add_noise.rb +0 -17
- 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 -33
- data/doc/ex/arcs01.rb +0 -28
- data/doc/ex/arcs02.rb +0 -61
- data/doc/ex/average.rb +0 -15
- data/doc/ex/axes.rb +0 -64
- data/doc/ex/baseline_shift01.rb +0 -18
- data/doc/ex/bilevel_channel.rb +0 -9
- data/doc/ex/blur_image.rb +0 -12
- data/doc/ex/border.rb +0 -10
- data/doc/ex/bounding_box.rb +0 -44
- data/doc/ex/cbezier1.rb +0 -42
- data/doc/ex/cbezier2.rb +0 -42
- data/doc/ex/cbezier3.rb +0 -42
- data/doc/ex/cbezier4.rb +0 -43
- data/doc/ex/cbezier5.rb +0 -43
- data/doc/ex/cbezier6.rb +0 -53
- data/doc/ex/channel.rb +0 -26
- 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 -17
- data/doc/ex/clip_path.rb +0 -60
- data/doc/ex/coalesce.rb +0 -60
- 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 -48
- 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 -23
- data/doc/ex/composite.rb +0 -135
- data/doc/ex/composite_layers.rb +0 -53
- data/doc/ex/composite_tiled.rb +0 -23
- data/doc/ex/contrast.rb +0 -36
- data/doc/ex/crop.rb +0 -31
- data/doc/ex/crop_with_gravity.rb +0 -46
- data/doc/ex/cubic01.rb +0 -45
- data/doc/ex/cubic02.rb +0 -94
- data/doc/ex/cycle_colormap.rb +0 -21
- data/doc/ex/dissolve.rb +0 -13
- 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 -22
- 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 -43
- data/doc/ex/fill_pattern.rb +0 -26
- 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 -34
- 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 -42
- data/doc/ex/get_pixels.rb +0 -48
- data/doc/ex/get_type_metrics.rb +0 -146
- data/doc/ex/gradientfill.rb +0 -27
- data/doc/ex/grav.rb +0 -46
- data/doc/ex/gravity.rb +0 -79
- data/doc/ex/group.rb +0 -26
- data/doc/ex/hatchfill.rb +0 -27
- data/doc/ex/image.rb +0 -46
- 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/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 -42
- data/doc/ex/line01.rb +0 -23
- data/doc/ex/mask.rb +0 -36
- data/doc/ex/matte_fill_to_border.rb +0 -40
- data/doc/ex/matte_floodfill.rb +0 -33
- data/doc/ex/matte_replace.rb +0 -40
- 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 -26
- 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 -43
- 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 -64
- data/doc/ex/pattern1.rb +0 -25
- data/doc/ex/pattern2.rb +0 -26
- data/doc/ex/polaroid.rb +0 -28
- data/doc/ex/polygon.rb +0 -24
- data/doc/ex/polygon01.rb +0 -23
- data/doc/ex/polyline.rb +0 -23
- data/doc/ex/polyline01.rb +0 -23
- data/doc/ex/posterize.rb +0 -8
- data/doc/ex/preview.rb +0 -9
- data/doc/ex/qbezierpath.rb +0 -52
- data/doc/ex/quad01.rb +0 -36
- 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 -15
- data/doc/ex/rect02.rb +0 -22
- data/doc/ex/rectangle.rb +0 -35
- data/doc/ex/reduce_noise.rb +0 -28
- data/doc/ex/remap.rb +0 -12
- data/doc/ex/remap_images.rb +0 -21
- data/doc/ex/resize_to_fill.rb +0 -10
- data/doc/ex/resize_to_fit.rb +0 -10
- data/doc/ex/roll.rb +0 -9
- data/doc/ex/rotate.rb +0 -45
- data/doc/ex/rotate_f.rb +0 -14
- data/doc/ex/roundrect.rb +0 -34
- data/doc/ex/rubyname.rb +0 -30
- data/doc/ex/rvg_clippath.rb +0 -14
- data/doc/ex/rvg_linecap.rb +0 -43
- data/doc/ex/rvg_linejoin.rb +0 -41
- data/doc/ex/rvg_opacity.rb +0 -19
- data/doc/ex/rvg_pattern.rb +0 -26
- data/doc/ex/rvg_stroke_dasharray.rb +0 -12
- data/doc/ex/segment.rb +0 -11
- data/doc/ex/sepiatone.rb +0 -8
- data/doc/ex/shade.rb +0 -11
- data/doc/ex/shadow.rb +0 -31
- data/doc/ex/shave.rb +0 -15
- data/doc/ex/shear.rb +0 -10
- data/doc/ex/sketch.rb +0 -18
- data/doc/ex/skewx.rb +0 -52
- 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 -55
- data/doc/ex/splice.rb +0 -9
- data/doc/ex/spread.rb +0 -11
- data/doc/ex/stegano.rb +0 -55
- data/doc/ex/stroke_dasharray.rb +0 -43
- data/doc/ex/stroke_fill.rb +0 -11
- 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 -17
- data/doc/ex/text_align.rb +0 -36
- data/doc/ex/text_antialias.rb +0 -38
- data/doc/ex/text_styles.rb +0 -21
- 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 -25
- data/doc/ex/threshold.rb +0 -13
- data/doc/ex/to_blob.rb +0 -14
- 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 -25
- data/doc/ex/triangle01.rb +0 -16
- data/doc/ex/trim.rb +0 -24
- data/doc/ex/tspan01.rb +0 -18
- data/doc/ex/tspan02.rb +0 -19
- data/doc/ex/tspan03.rb +0 -21
- data/doc/ex/unsharp_mask.rb +0 -28
- data/doc/ex/viewex.rb +0 -35
- data/doc/ex/vignette.rb +0 -12
- data/doc/ex/watermark.rb +0 -28
- data/doc/ex/wave.rb +0 -9
- data/doc/ex/wet_floor.rb +0 -59
- data/doc/ex/writing_mode01.rb +0 -27
- 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 -46
- data/examples/demo.rb +0 -324
- data/examples/describe.rb +0 -44
- data/examples/find_similar_region.rb +0 -34
- data/examples/histogram.rb +0 -325
- data/examples/identify.rb +0 -187
- 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 -45
- data/examples/spinner.rb +0 -50
- data/examples/thumbnail.rb +0 -65
- data/examples/vignette.rb +0 -79
- data/ext/RMagick/MANIFEST +0 -358
- data/lib/RMagick.rb +0 -1962
- data/metaconfig +0 -7
- data/post-clean.rb +0 -12
- data/post-install.rb +0 -50
- data/post-setup.rb +0 -254
- data/setup.rb +0 -1585
- data/uninstall.rb +0 -76
data/ext/RMagick/rmpixel.c
CHANGED
@@ -12,12 +12,13 @@
|
|
12
12
|
|
13
13
|
#include "rmagick.h"
|
14
14
|
|
15
|
+
#if defined(IMAGEMAGICK_6)
|
16
|
+
#define QueryColorname QueryMagickColorname
|
17
|
+
#endif
|
15
18
|
|
16
19
|
|
17
|
-
|
18
|
-
static void
|
19
|
-
|
20
|
-
|
20
|
+
static VALUE color_arg_rescue(VALUE, VALUE ATTRIBUTE_UNUSED) ATTRIBUTE_NORETURN;
|
21
|
+
static void Color_Name_to_PixelColor(PixelColor *, VALUE);
|
21
22
|
|
22
23
|
|
23
24
|
/**
|
@@ -35,125 +36,309 @@ destroy_Pixel(Pixel *pixel)
|
|
35
36
|
|
36
37
|
|
37
38
|
/**
|
38
|
-
* Get Pixel red
|
39
|
+
* Get Pixel red value.
|
39
40
|
*
|
40
|
-
*
|
41
|
-
|
41
|
+
* @return [Numeric] the red value
|
42
|
+
*/
|
43
|
+
VALUE
|
44
|
+
Pixel_red(VALUE self)
|
45
|
+
{
|
46
|
+
IMPLEMENT_ATTR_READER(Pixel, red, int);
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Get Pixel green value.
|
42
51
|
*
|
43
|
-
* @
|
44
|
-
* @return the red value
|
52
|
+
* @return [Numeric] the green value
|
45
53
|
*/
|
46
|
-
|
54
|
+
VALUE
|
55
|
+
Pixel_green(VALUE self)
|
56
|
+
{
|
57
|
+
IMPLEMENT_ATTR_READER(Pixel, green, int);
|
58
|
+
}
|
47
59
|
|
48
60
|
/**
|
49
|
-
* Get Pixel
|
61
|
+
* Get Pixel blue value.
|
50
62
|
*
|
51
|
-
*
|
52
|
-
|
63
|
+
* @return [Numeric] the blue value
|
64
|
+
*/
|
65
|
+
VALUE
|
66
|
+
Pixel_blue(VALUE self)
|
67
|
+
{
|
68
|
+
IMPLEMENT_ATTR_READER(Pixel, blue, int);
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Get Pixel alpha value.
|
53
73
|
*
|
54
|
-
* @
|
55
|
-
* @return the green value
|
74
|
+
* @return [Numeric] the alpha value
|
56
75
|
*/
|
57
|
-
|
76
|
+
VALUE
|
77
|
+
Pixel_alpha(VALUE self)
|
78
|
+
{
|
79
|
+
Pixel *pixel;
|
80
|
+
Data_Get_Struct(self, Pixel, pixel);
|
81
|
+
#if defined(IMAGEMAGICK_7)
|
82
|
+
return C_int_to_R_int(pixel->alpha);
|
83
|
+
#else
|
84
|
+
return C_int_to_R_int(QuantumRange - pixel->opacity);
|
85
|
+
#endif
|
86
|
+
}
|
58
87
|
|
59
88
|
/**
|
60
|
-
*
|
89
|
+
* Set Pixel red value.
|
61
90
|
*
|
62
|
-
*
|
63
|
-
*
|
91
|
+
* - Pixel is Observable. Setters call {Magick::Pixel#changed},
|
92
|
+
* {Magick::Pixel#notify_observers}
|
93
|
+
* - Setters return their argument values for backward compatibility to when
|
94
|
+
* Pixel was a Struct class.
|
64
95
|
*
|
65
|
-
* @param
|
66
|
-
* @return the
|
96
|
+
* @param v [Numeric] the red value
|
97
|
+
* @return [Numeric] the given red value
|
67
98
|
*/
|
68
|
-
|
99
|
+
VALUE
|
100
|
+
Pixel_red_eq(VALUE self, VALUE v)
|
101
|
+
{
|
102
|
+
Pixel *pixel;
|
103
|
+
|
104
|
+
rb_check_frozen(self);
|
105
|
+
Data_Get_Struct(self, Pixel, pixel);
|
106
|
+
pixel->red = APP2QUANTUM(v);
|
107
|
+
rb_funcall(self, rm_ID_changed, 0);
|
108
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
109
|
+
return QUANTUM2NUM((pixel->red));
|
110
|
+
}
|
69
111
|
|
70
112
|
/**
|
71
|
-
*
|
113
|
+
* Set Pixel green value.
|
72
114
|
*
|
73
|
-
*
|
74
|
-
*
|
115
|
+
* - Pixel is Observable. Setters call {Magick::Pixel#changed},
|
116
|
+
* {Magick::Pixel#notify_observers}
|
117
|
+
* - Setters return their argument values for backward compatibility to when
|
118
|
+
* Pixel was a Struct class.
|
75
119
|
*
|
76
|
-
* @param
|
77
|
-
* @return the
|
120
|
+
* @param v [Numeric] the green value
|
121
|
+
* @return [Numeric] the given green value
|
78
122
|
*/
|
79
|
-
|
123
|
+
VALUE
|
124
|
+
Pixel_green_eq(VALUE self, VALUE v)
|
125
|
+
{
|
126
|
+
Pixel *pixel;
|
127
|
+
|
128
|
+
rb_check_frozen(self);
|
129
|
+
Data_Get_Struct(self, Pixel, pixel);
|
130
|
+
pixel->green = APP2QUANTUM(v);
|
131
|
+
rb_funcall(self, rm_ID_changed, 0);
|
132
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
133
|
+
return QUANTUM2NUM((pixel->green));
|
134
|
+
}
|
80
135
|
|
81
136
|
/**
|
82
|
-
* Set Pixel
|
137
|
+
* Set Pixel blue value.
|
83
138
|
*
|
84
|
-
*
|
85
|
-
*
|
139
|
+
* - Pixel is Observable. Setters call {Magick::Pixel#changed},
|
140
|
+
* {Magick::Pixel#notify_observers}
|
141
|
+
* - Setters return their argument values for backward compatibility to when
|
142
|
+
* Pixel was a Struct class.
|
86
143
|
*
|
87
|
-
*
|
88
|
-
*
|
89
|
-
|
90
|
-
|
144
|
+
* @param v [Numeric] the blue value
|
145
|
+
* @return [Numeric] the given blue value
|
146
|
+
*/
|
147
|
+
VALUE
|
148
|
+
Pixel_blue_eq(VALUE self, VALUE v)
|
149
|
+
{
|
150
|
+
Pixel *pixel;
|
151
|
+
|
152
|
+
rb_check_frozen(self);
|
153
|
+
Data_Get_Struct(self, Pixel, pixel);
|
154
|
+
pixel->blue = APP2QUANTUM(v);
|
155
|
+
rb_funcall(self, rm_ID_changed, 0);
|
156
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
157
|
+
return QUANTUM2NUM((pixel->blue));
|
158
|
+
}
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Set Pixel alpha value.
|
91
162
|
*
|
92
|
-
*
|
93
|
-
*
|
94
|
-
*
|
163
|
+
* - Pixel is Observable. Setters call {Magick::Pixel#changed},
|
164
|
+
* {Magick::Pixel#notify_observers}
|
165
|
+
* - Setters return their argument values for backward compatibility to when
|
166
|
+
* Pixel was a Struct class.
|
167
|
+
*
|
168
|
+
* @param v [Numeric] the alpha value
|
169
|
+
* @return [Numeric] the given alpha value
|
95
170
|
*/
|
96
|
-
|
171
|
+
VALUE
|
172
|
+
Pixel_alpha_eq(VALUE self, VALUE v)
|
173
|
+
{
|
174
|
+
Pixel *pixel;
|
175
|
+
|
176
|
+
rb_check_frozen(self);
|
177
|
+
Data_Get_Struct(self, Pixel, pixel);
|
178
|
+
#if defined(IMAGEMAGICK_7)
|
179
|
+
pixel->alpha = APP2QUANTUM(v);
|
180
|
+
rb_funcall(self, rm_ID_changed, 0);
|
181
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
182
|
+
return QUANTUM2NUM(pixel->alpha);
|
183
|
+
#else
|
184
|
+
pixel->opacity = QuantumRange - APP2QUANTUM(v);
|
185
|
+
rb_funcall(self, rm_ID_changed, 0);
|
186
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
187
|
+
return QUANTUM2NUM(QuantumRange - pixel->opacity);
|
188
|
+
#endif
|
189
|
+
}
|
97
190
|
|
98
191
|
/**
|
99
|
-
*
|
192
|
+
* Get Pixel cyan value.
|
100
193
|
*
|
101
|
-
*
|
102
|
-
|
194
|
+
* @return [Numeric] the cyan value
|
195
|
+
*/
|
196
|
+
VALUE
|
197
|
+
Pixel_cyan(VALUE self)
|
198
|
+
{
|
199
|
+
Pixel *pixel;
|
200
|
+
|
201
|
+
Data_Get_Struct(self, Pixel, pixel);
|
202
|
+
return INT2NUM(pixel->red);
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* Set Pixel cyan value.
|
103
207
|
*
|
104
|
-
*
|
105
|
-
*
|
106
|
-
*
|
107
|
-
*
|
208
|
+
* - Pixel is Observable. Setters call {Magick::Pixel#changed},
|
209
|
+
* {Magick::Pixel#notify_observers}
|
210
|
+
* - Setters return their argument values for backward compatibility to when
|
211
|
+
* Pixel was a Struct class.
|
108
212
|
*
|
109
|
-
* @param
|
110
|
-
* @
|
111
|
-
|
213
|
+
* @param v [Numeric] the cyan value
|
214
|
+
* @return [Numeric] the given cyan value
|
215
|
+
*/
|
216
|
+
VALUE
|
217
|
+
Pixel_cyan_eq(VALUE self, VALUE v)
|
218
|
+
{
|
219
|
+
Pixel *pixel;
|
220
|
+
|
221
|
+
rb_check_frozen(self);
|
222
|
+
Data_Get_Struct(self, Pixel, pixel);
|
223
|
+
pixel->red = APP2QUANTUM(v);
|
224
|
+
rb_funcall(self, rm_ID_changed, 0);
|
225
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
226
|
+
return QUANTUM2NUM(pixel->red);
|
227
|
+
}
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Get Pixel magenta value.
|
231
|
+
*
|
232
|
+
* @return [Numeric] the magenta value
|
112
233
|
*/
|
113
|
-
|
234
|
+
VALUE
|
235
|
+
Pixel_magenta(VALUE self)
|
236
|
+
{
|
237
|
+
Pixel *pixel;
|
238
|
+
|
239
|
+
Data_Get_Struct(self, Pixel, pixel);
|
240
|
+
return INT2NUM(pixel->green);
|
241
|
+
}
|
114
242
|
|
115
243
|
/**
|
116
|
-
* Set Pixel
|
244
|
+
* Set Pixel magenta value.
|
117
245
|
*
|
118
|
-
*
|
119
|
-
*
|
246
|
+
* - Pixel is Observable. Setters call {Magick::Pixel#changed},
|
247
|
+
* {Magick::Pixel#notify_observers}
|
248
|
+
* - Setters return their argument values for backward compatibility to when
|
249
|
+
* Pixel was a Struct class.
|
120
250
|
*
|
121
|
-
*
|
122
|
-
*
|
123
|
-
|
124
|
-
|
251
|
+
* @param v [Numeric] the magenta value
|
252
|
+
* @return [Numeric] the given magenta value
|
253
|
+
*/
|
254
|
+
VALUE
|
255
|
+
Pixel_magenta_eq(VALUE self, VALUE v)
|
256
|
+
{
|
257
|
+
Pixel *pixel;
|
258
|
+
|
259
|
+
rb_check_frozen(self);
|
260
|
+
Data_Get_Struct(self, Pixel, pixel);
|
261
|
+
pixel->green = APP2QUANTUM(v);
|
262
|
+
rb_funcall(self, rm_ID_changed, 0);
|
263
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
264
|
+
return QUANTUM2NUM(pixel->green);
|
265
|
+
}
|
266
|
+
|
267
|
+
/**
|
268
|
+
* Get Pixel yellow value.
|
125
269
|
*
|
126
|
-
* @
|
127
|
-
* @param v the blue value
|
128
|
-
* @return self
|
270
|
+
* @return [Numeric] the yellow value
|
129
271
|
*/
|
130
|
-
|
272
|
+
VALUE
|
273
|
+
Pixel_yellow(VALUE self)
|
274
|
+
{
|
275
|
+
Pixel *pixel;
|
276
|
+
|
277
|
+
Data_Get_Struct(self, Pixel, pixel);
|
278
|
+
return INT2NUM(pixel->blue);
|
279
|
+
}
|
131
280
|
|
132
281
|
/**
|
133
|
-
* Set Pixel
|
282
|
+
* Set Pixel yellow value.
|
134
283
|
*
|
135
|
-
*
|
136
|
-
*
|
284
|
+
* - Pixel is Observable. Setters call {Magick::Pixel#changed},
|
285
|
+
* {Magick::Pixel#notify_observers}
|
286
|
+
* - Setters return their argument values for backward compatibility to when
|
287
|
+
* Pixel was a Struct class.
|
137
288
|
*
|
138
|
-
*
|
139
|
-
*
|
140
|
-
|
141
|
-
|
289
|
+
* @param v [Numeric] the yellow value
|
290
|
+
* @return [Numeric] the given yellow value
|
291
|
+
*/
|
292
|
+
VALUE
|
293
|
+
Pixel_yellow_eq(VALUE self, VALUE v)
|
294
|
+
{
|
295
|
+
Pixel *pixel;
|
296
|
+
|
297
|
+
rb_check_frozen(self);
|
298
|
+
Data_Get_Struct(self, Pixel, pixel);
|
299
|
+
pixel->blue = APP2QUANTUM(v);
|
300
|
+
rb_funcall(self, rm_ID_changed, 0);
|
301
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
302
|
+
return QUANTUM2NUM(pixel->blue);
|
303
|
+
}
|
304
|
+
|
305
|
+
/**
|
306
|
+
* Get Pixel black value.
|
142
307
|
*
|
143
|
-
* @
|
144
|
-
* @param v the opacity value
|
145
|
-
* @return self
|
308
|
+
* @return [Numeric] the black value
|
146
309
|
*/
|
147
|
-
|
310
|
+
VALUE
|
311
|
+
Pixel_black(VALUE self)
|
312
|
+
{
|
313
|
+
Pixel *pixel;
|
148
314
|
|
315
|
+
Data_Get_Struct(self, Pixel, pixel);
|
316
|
+
return INT2NUM(pixel->black);
|
317
|
+
}
|
149
318
|
|
150
|
-
|
151
|
-
*
|
319
|
+
/**
|
320
|
+
* Set Pixel black value.
|
321
|
+
*
|
322
|
+
* - Pixel is Observable. Setters call {Magick::Pixel#changed},
|
323
|
+
* {Magick::Pixel#notify_observers}
|
324
|
+
* - Setters return their argument values for backward compatibility to when
|
325
|
+
* Pixel was a Struct class.
|
326
|
+
*
|
327
|
+
* @param v [Numeric] the black value
|
328
|
+
* @return [Numeric] the given black value
|
152
329
|
*/
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
330
|
+
VALUE
|
331
|
+
Pixel_black_eq(VALUE self, VALUE v)
|
332
|
+
{
|
333
|
+
Pixel *pixel;
|
334
|
+
|
335
|
+
rb_check_frozen(self);
|
336
|
+
Data_Get_Struct(self, Pixel, pixel);
|
337
|
+
pixel->black = APP2QUANTUM(v);
|
338
|
+
rb_funcall(self, rm_ID_changed, 0);
|
339
|
+
rb_funcall(self, rm_ID_notify_observers, 1, self);
|
340
|
+
return QUANTUM2NUM(pixel->black);
|
341
|
+
}
|
157
342
|
|
158
343
|
|
159
344
|
/**
|
@@ -167,62 +352,108 @@ DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(black, opacity)
|
|
167
352
|
* @throw ArgumentError
|
168
353
|
*/
|
169
354
|
static VALUE
|
170
|
-
color_arg_rescue(VALUE arg)
|
355
|
+
color_arg_rescue(VALUE arg, VALUE raised_exc ATTRIBUTE_UNUSED)
|
171
356
|
{
|
172
357
|
rb_raise(rb_eTypeError, "argument must be color name or pixel (%s given)",
|
173
358
|
rb_class2name(CLASS_OF(arg)));
|
174
|
-
return (VALUE)0;
|
175
359
|
}
|
176
360
|
|
177
361
|
|
178
362
|
/**
|
179
|
-
* Convert either a String color name or a Magick::Pixel to a
|
363
|
+
* Convert either a String color name or a Magick::Pixel to a PixelColor.
|
180
364
|
*
|
181
365
|
* No Ruby usage (internal function)
|
182
366
|
*
|
183
|
-
* @param pp the
|
367
|
+
* @param pp the PixelColor to modify
|
184
368
|
* @param color the color name or Magick::Pixel
|
185
369
|
*/
|
186
370
|
void
|
187
|
-
|
371
|
+
Color_to_PixelColor(PixelColor *pp, VALUE color)
|
188
372
|
{
|
189
373
|
Pixel *pixel;
|
190
374
|
|
191
375
|
// Allow color name or Pixel
|
192
376
|
if (CLASS_OF(color) == Class_Pixel)
|
193
377
|
{
|
378
|
+
memset(pp, 0, sizeof(*pp));
|
194
379
|
Data_Get_Struct(color, Pixel, pixel);
|
195
|
-
|
380
|
+
pp->red = pixel->red;
|
381
|
+
pp->green = pixel->green;
|
382
|
+
pp->blue = pixel->blue;
|
383
|
+
#if defined(IMAGEMAGICK_7)
|
384
|
+
pp->alpha = pixel->alpha;
|
385
|
+
pp->black = pixel->black;
|
386
|
+
#else
|
387
|
+
pp->opacity = pixel->opacity;
|
388
|
+
#endif
|
196
389
|
}
|
197
390
|
else
|
198
391
|
{
|
199
392
|
// require 'to_str' here instead of just 'to_s'.
|
200
393
|
color = rb_rescue(rb_str_to_str, color, color_arg_rescue, color);
|
201
|
-
|
394
|
+
Color_Name_to_PixelColor(pp, color);
|
202
395
|
}
|
203
396
|
}
|
204
397
|
|
205
398
|
|
206
399
|
/**
|
207
|
-
* Convert a color name to a
|
400
|
+
* Convert either a String color name or a {Magick::Pixel} to a Pixel.
|
208
401
|
*
|
209
402
|
* No Ruby usage (internal function)
|
210
403
|
*
|
211
|
-
* @param
|
404
|
+
* @param pp the Pixel to modify
|
405
|
+
* @param color the color name or Magick::Pixel
|
406
|
+
*/
|
407
|
+
void
|
408
|
+
Color_to_Pixel(Pixel *pp, VALUE color)
|
409
|
+
{
|
410
|
+
PixelColor pixel_color;
|
411
|
+
|
412
|
+
memset(pp, 0, sizeof(*pp));
|
413
|
+
// Allow color name or Pixel
|
414
|
+
if (CLASS_OF(color) == Class_Pixel)
|
415
|
+
{
|
416
|
+
Pixel *pixel;
|
417
|
+
|
418
|
+
Data_Get_Struct(color, Pixel, pixel);
|
419
|
+
memcpy(pp, pixel, sizeof(Pixel));
|
420
|
+
}
|
421
|
+
else
|
422
|
+
{
|
423
|
+
Color_to_PixelColor(&pixel_color, color);
|
424
|
+
pp->red = pixel_color.red;
|
425
|
+
pp->green = pixel_color.green;
|
426
|
+
pp->blue = pixel_color.blue;
|
427
|
+
#if defined(IMAGEMAGICK_7)
|
428
|
+
pp->alpha = pixel_color.alpha;
|
429
|
+
pp->black = pixel_color.black;
|
430
|
+
#else
|
431
|
+
pp->opacity = pixel_color.opacity;
|
432
|
+
#endif
|
433
|
+
}
|
434
|
+
}
|
435
|
+
|
436
|
+
|
437
|
+
/**
|
438
|
+
* Convert a color name to a PixelColor
|
439
|
+
*
|
440
|
+
* No Ruby usage (internal function)
|
441
|
+
*
|
442
|
+
* @param color the PixelColor to modify
|
212
443
|
* @param name_arg the coor name
|
213
444
|
* @throw ArgumentError
|
214
445
|
*/
|
215
446
|
static void
|
216
|
-
|
447
|
+
Color_Name_to_PixelColor(PixelColor *color, VALUE name_arg)
|
217
448
|
{
|
218
449
|
MagickBooleanType okay;
|
219
450
|
char *name;
|
220
|
-
ExceptionInfo exception;
|
451
|
+
ExceptionInfo *exception;
|
221
452
|
|
222
|
-
|
223
|
-
name =
|
224
|
-
okay =
|
225
|
-
|
453
|
+
exception = AcquireExceptionInfo();
|
454
|
+
name = StringValueCStr(name_arg);
|
455
|
+
okay = QueryColorCompliance(name, AllCompliance, color, exception);
|
456
|
+
DestroyExceptionInfo(exception);
|
226
457
|
if (!okay)
|
227
458
|
{
|
228
459
|
rb_raise(rb_eArgError, "invalid color name %s", name);
|
@@ -234,10 +465,7 @@ Color_Name_to_PixelPacket(PixelPacket *color, VALUE name_arg)
|
|
234
465
|
/**
|
235
466
|
* Allocate a Pixel object.
|
236
467
|
*
|
237
|
-
*
|
238
|
-
*
|
239
|
-
* @param class the Ruby class to use
|
240
|
-
* @return a new Magick::Pixel object
|
468
|
+
* @return [Magick::Pixel] a new Magick::Pixel object
|
241
469
|
*/
|
242
470
|
VALUE
|
243
471
|
Pixel_alloc(VALUE class)
|
@@ -253,27 +481,27 @@ Pixel_alloc(VALUE class)
|
|
253
481
|
/**
|
254
482
|
* "Case equal" operator for Pixel.
|
255
483
|
*
|
256
|
-
*
|
257
|
-
*
|
258
|
-
*
|
259
|
-
* @param self this object
|
260
|
-
* @param other the other object
|
261
|
-
* @return true or false
|
484
|
+
* @param other [Object] the other object
|
485
|
+
* @return [Boolean] true or false
|
262
486
|
*/
|
263
487
|
|
264
488
|
VALUE
|
265
489
|
Pixel_case_eq(VALUE self, VALUE other)
|
266
490
|
{
|
267
|
-
Pixel *this, *that;
|
268
|
-
|
269
491
|
if (CLASS_OF(self) == CLASS_OF(other))
|
270
492
|
{
|
493
|
+
Pixel *this, *that;
|
494
|
+
|
271
495
|
Data_Get_Struct(self, Pixel, this);
|
272
496
|
Data_Get_Struct(other, Pixel, that);
|
273
497
|
return (this->red == that->red
|
274
498
|
&& this->blue == that->blue
|
275
499
|
&& this->green == that->green
|
500
|
+
#if defined(IMAGEMAGICK_7)
|
501
|
+
&& this->alpha == that->alpha) ? Qtrue : Qfalse;
|
502
|
+
#else
|
276
503
|
&& this->opacity == that->opacity) ? Qtrue : Qfalse;
|
504
|
+
#endif
|
277
505
|
}
|
278
506
|
|
279
507
|
return Qfalse;
|
@@ -283,18 +511,14 @@ Pixel_case_eq(VALUE self, VALUE other)
|
|
283
511
|
/**
|
284
512
|
* Clone a Pixel.
|
285
513
|
*
|
286
|
-
*
|
287
|
-
*
|
288
|
-
*
|
289
|
-
* @param self this object
|
290
|
-
* @return a clone
|
291
|
-
* @see Pixel_dup
|
292
|
-
* @see Pixel_init_copy
|
514
|
+
* @return [Magick::Pixel] a clone object
|
515
|
+
* @see #dup
|
516
|
+
* @see #initialize_copy
|
293
517
|
*/
|
294
518
|
VALUE
|
295
519
|
Pixel_clone(VALUE self)
|
296
520
|
{
|
297
|
-
|
521
|
+
VALUE clone;
|
298
522
|
|
299
523
|
clone = Pixel_dup(self);
|
300
524
|
if (OBJ_FROZEN(self))
|
@@ -302,6 +526,8 @@ Pixel_clone(VALUE self)
|
|
302
526
|
OBJ_FREEZE(clone);
|
303
527
|
}
|
304
528
|
|
529
|
+
RB_GC_GUARD(clone);
|
530
|
+
|
305
531
|
return clone;
|
306
532
|
}
|
307
533
|
|
@@ -309,40 +535,30 @@ Pixel_clone(VALUE self)
|
|
309
535
|
/**
|
310
536
|
* Duplicate a Pixel.
|
311
537
|
*
|
312
|
-
*
|
313
|
-
*
|
314
|
-
*
|
315
|
-
* @param self this object
|
316
|
-
* @return a clone
|
317
|
-
* @see Pixel_clone
|
318
|
-
* @see Pixel_init_copy
|
538
|
+
* @return [Magick::Pixel] a duplicated object
|
539
|
+
* @see #clone
|
540
|
+
* @see #initialize_copy
|
319
541
|
*/
|
320
542
|
VALUE
|
321
543
|
Pixel_dup(VALUE self)
|
322
544
|
{
|
323
545
|
Pixel *pixel;
|
324
|
-
|
546
|
+
VALUE dup;
|
325
547
|
|
326
548
|
pixel = ALLOC(Pixel);
|
327
549
|
memset(pixel, '\0', sizeof(Pixel));
|
328
550
|
dup = Data_Wrap_Struct(CLASS_OF(self), NULL, destroy_Pixel, pixel);
|
329
|
-
|
330
|
-
|
331
|
-
(void) rb_obj_taint(dup);
|
332
|
-
}
|
551
|
+
RB_GC_GUARD(dup);
|
552
|
+
|
333
553
|
return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
|
334
554
|
}
|
335
555
|
|
336
556
|
|
337
557
|
/**
|
338
|
-
*
|
339
|
-
*
|
340
|
-
* Ruby usage:
|
341
|
-
* - @verbatim Pixel#eql? @endverbatim
|
558
|
+
* Equality. Returns true only if receiver and other are the same object.
|
342
559
|
*
|
343
|
-
* @param
|
344
|
-
* @
|
345
|
-
* @return true if hash to the same value, otherwise false
|
560
|
+
* @param other [Object] the other object
|
561
|
+
* @return [Boolean] true if other is the same value, otherwise false
|
346
562
|
*/
|
347
563
|
VALUE
|
348
564
|
Pixel_eql_q(VALUE self, VALUE other)
|
@@ -354,28 +570,23 @@ Pixel_eql_q(VALUE self, VALUE other)
|
|
354
570
|
/**
|
355
571
|
* Compare pixel values for equality.
|
356
572
|
*
|
357
|
-
*
|
358
|
-
*
|
359
|
-
*
|
360
|
-
*
|
361
|
-
*
|
362
|
-
* - Default colorspace is RGBColorspace
|
363
|
-
*
|
364
|
-
* @param argc number of input arguments
|
365
|
-
* @param argv array of input arguments
|
366
|
-
* @param self this object
|
367
|
-
* @return true if equal, otherwise false
|
573
|
+
* @overload fcmp(other, fuzz = 0.0, colorspace = Magick::RGBColorspace)
|
574
|
+
* @param other [Magick::Pixel] The pixel to which the receiver is compared
|
575
|
+
* @param fuzz [Float] The amount of fuzz to allow before the colors are considered to be different
|
576
|
+
* @param colorspace [Magick::ColorspaceType] The colorspace
|
577
|
+
* @return [Boolean] true if equal, otherwise false
|
368
578
|
*/
|
369
579
|
VALUE
|
370
580
|
Pixel_fcmp(int argc, VALUE *argv, VALUE self)
|
371
581
|
{
|
372
|
-
Image *image;
|
373
|
-
Info *info;
|
374
|
-
|
375
|
-
Pixel *this, *that;
|
376
|
-
ColorspaceType colorspace = RGBColorspace;
|
377
582
|
double fuzz = 0.0;
|
378
583
|
unsigned int equal;
|
584
|
+
ColorspaceType colorspace = RGBColorspace;
|
585
|
+
PixelColor this, that;
|
586
|
+
#if defined(IMAGEMAGICK_6)
|
587
|
+
Image *image;
|
588
|
+
Info *info;
|
589
|
+
#endif
|
379
590
|
|
380
591
|
switch (argc)
|
381
592
|
{
|
@@ -391,9 +602,16 @@ Pixel_fcmp(int argc, VALUE *argv, VALUE self)
|
|
391
602
|
break;
|
392
603
|
}
|
393
604
|
|
394
|
-
|
395
|
-
|
605
|
+
Color_to_PixelColor(&this, self);
|
606
|
+
Color_to_PixelColor(&that, argv[0]);
|
396
607
|
|
608
|
+
#if defined(IMAGEMAGICK_7)
|
609
|
+
this.fuzz = fuzz;
|
610
|
+
this.colorspace = colorspace;
|
611
|
+
that.fuzz = fuzz;
|
612
|
+
that.colorspace = colorspace;
|
613
|
+
equal = IsFuzzyEquivalencePixelInfo(&this, &that);
|
614
|
+
#else
|
397
615
|
// The IsColorSimilar function expects to get the
|
398
616
|
// colorspace and fuzz parameters from an Image structure.
|
399
617
|
|
@@ -403,10 +621,10 @@ Pixel_fcmp(int argc, VALUE *argv, VALUE self)
|
|
403
621
|
rb_raise(rb_eNoMemError, "not enough memory to continue");
|
404
622
|
}
|
405
623
|
|
406
|
-
image =
|
624
|
+
image = rm_acquire_image(info);
|
407
625
|
|
408
626
|
// Delete Info now in case we have to raise an exception
|
409
|
-
|
627
|
+
DestroyImageInfo(info);
|
410
628
|
|
411
629
|
if (!image)
|
412
630
|
{
|
@@ -416,95 +634,82 @@ Pixel_fcmp(int argc, VALUE *argv, VALUE self)
|
|
416
634
|
image->colorspace = colorspace;
|
417
635
|
image->fuzz = fuzz;
|
418
636
|
|
419
|
-
equal = IsColorSimilar(image, this, that);
|
420
|
-
|
637
|
+
equal = IsColorSimilar(image, &this, &that);
|
638
|
+
DestroyImage(image);
|
639
|
+
#endif
|
421
640
|
|
422
641
|
return equal ? Qtrue : Qfalse;
|
423
642
|
}
|
424
643
|
|
425
644
|
|
426
645
|
/**
|
427
|
-
* Construct an Magick::Pixel corresponding to the given color name.
|
646
|
+
* Construct an {Magick::Pixel} corresponding to the given color name.
|
428
647
|
*
|
429
|
-
*
|
430
|
-
*
|
648
|
+
* - The "inverse" is {Image#to_color}, b/c the conversion of a pixel to a
|
649
|
+
* color name requires both a color depth and if the opacity value has
|
650
|
+
* meaning.
|
431
651
|
*
|
432
|
-
*
|
433
|
-
*
|
434
|
-
*
|
435
|
-
*
|
436
|
-
*
|
437
|
-
* @param class the Ruby class to use
|
438
|
-
* @param name the color name
|
439
|
-
* @return a new Magic::Pixel object
|
440
|
-
* @see Image_to_color
|
441
|
-
* @see Pixel_to_color
|
652
|
+
* @param name [String] the color name
|
653
|
+
* @return [Magick::Pixel] a new Magic::Pixel object
|
654
|
+
* @see Magick::Image#to_color
|
655
|
+
* @see Magick::Pixel#to_color
|
442
656
|
*/
|
443
657
|
VALUE
|
444
|
-
Pixel_from_color(VALUE class, VALUE name)
|
658
|
+
Pixel_from_color(VALUE class ATTRIBUTE_UNUSED, VALUE name)
|
445
659
|
{
|
446
|
-
|
447
|
-
ExceptionInfo exception;
|
660
|
+
PixelColor pp;
|
661
|
+
ExceptionInfo *exception;
|
448
662
|
MagickBooleanType okay;
|
449
663
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
CHECK_EXCEPTION()
|
455
|
-
(void) DestroyExceptionInfo(&exception);
|
664
|
+
exception = AcquireExceptionInfo();
|
665
|
+
okay = QueryColorCompliance(StringValueCStr(name), AllCompliance, &pp, exception);
|
666
|
+
CHECK_EXCEPTION();
|
667
|
+
DestroyExceptionInfo(exception);
|
456
668
|
|
457
669
|
if (!okay)
|
458
670
|
{
|
459
|
-
rb_raise(rb_eArgError, "invalid color name: %s",
|
671
|
+
rb_raise(rb_eArgError, "invalid color name: %s", StringValueCStr(name));
|
460
672
|
}
|
461
673
|
|
462
|
-
return
|
674
|
+
return Pixel_from_PixelColor(&pp);
|
463
675
|
}
|
464
676
|
|
465
677
|
|
466
678
|
/**
|
467
679
|
* Construct an RGB pixel.
|
468
680
|
*
|
469
|
-
*
|
470
|
-
*
|
471
|
-
*
|
472
|
-
*
|
473
|
-
*
|
474
|
-
*
|
475
|
-
*
|
476
|
-
*
|
477
|
-
*
|
478
|
-
*
|
479
|
-
*
|
480
|
-
*
|
481
|
-
* @param argc number of input arguments
|
482
|
-
* @param argv array of input arguments
|
483
|
-
* @param class the Ruby class to use
|
484
|
-
* @return a new Magick::Pixel object
|
681
|
+
* - 0 <= +hue+ < 360 OR "0%" <= +hue+ < "100%"
|
682
|
+
* - 0 <= +saturation+ <= 255 OR "0%" <= +saturation+ <= "100%"
|
683
|
+
* - 0 <= +lightness+ <= 255 OR "0%" <= +lightness+ <= "100%"
|
684
|
+
* - 0 <= +alpha+ <= 1 (0 is transparent, 1 is opaque) OR "0%" <= +alpha+ <= "100%"
|
685
|
+
*
|
686
|
+
* @overload from_hsla(hue, saturation, lightness, alpha = 1.0)
|
687
|
+
* @param hue [Numeric, String] A value in the range.
|
688
|
+
* @param saturation [Numeric, String] A value in the range.
|
689
|
+
* @param lightness [Numeric, String] A value in the range.
|
690
|
+
* @param alpha [Numeric] The alpha value.
|
691
|
+
* @return [Magick::Pixel] a new Magick::Pixel object
|
485
692
|
*/
|
486
693
|
VALUE
|
487
|
-
Pixel_from_hsla(int argc, VALUE *argv, VALUE class)
|
694
|
+
Pixel_from_hsla(int argc, VALUE *argv, VALUE class ATTRIBUTE_UNUSED)
|
488
695
|
{
|
489
696
|
double h, s, l, a = 1.0;
|
490
|
-
|
491
|
-
ExceptionInfo exception;
|
697
|
+
MagickPixel pp;
|
698
|
+
ExceptionInfo *exception;
|
492
699
|
char name[50];
|
493
700
|
MagickBooleanType alpha = MagickFalse;
|
494
701
|
|
495
|
-
class = class; // defeat "unused parameter" message.
|
496
|
-
|
497
702
|
switch (argc)
|
498
703
|
{
|
499
704
|
case 4:
|
500
|
-
a = rm_percentage(argv[3],1.0);
|
705
|
+
a = rm_percentage(argv[3], 1.0);
|
501
706
|
alpha = MagickTrue;
|
502
707
|
case 3:
|
503
708
|
// saturation and lightness are out of 255 in new ImageMagicks and
|
504
709
|
// out of 100 in old ImageMagicks. Compromise: always use %.
|
505
|
-
l = rm_percentage(argv[2],255.0);
|
506
|
-
s = rm_percentage(argv[1],255.0);
|
507
|
-
h = rm_percentage(argv[0],360.0);
|
710
|
+
l = rm_percentage(argv[2], 255.0);
|
711
|
+
s = rm_percentage(argv[1], 255.0);
|
712
|
+
h = rm_percentage(argv[0], 360.0);
|
508
713
|
break;
|
509
714
|
default:
|
510
715
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
|
@@ -528,131 +733,130 @@ Pixel_from_hsla(int argc, VALUE *argv, VALUE class)
|
|
528
733
|
rb_raise(rb_eRangeError, "hue %g out of range [0.0, 360.0)", h);
|
529
734
|
}
|
530
735
|
|
531
|
-
// Ugly way of checking for change in ImageMagick 6.5.6-5 to see whether
|
532
|
-
// saturation/lightness should be out of 255 or out of 100.
|
533
|
-
if(MagickLibVersion < 0x656 ||
|
534
|
-
(MagickLibVersion == 0x656 && strcmp(MagickLibSubversion,"-5") <= 0) )
|
535
|
-
{
|
536
|
-
s = s/2.55;
|
537
|
-
l = l/2.55;
|
538
|
-
}
|
539
|
-
|
540
736
|
memset(name, 0, sizeof(name));
|
541
737
|
if (alpha)
|
542
738
|
{
|
543
|
-
|
739
|
+
snprintf(name, sizeof(name), "hsla(%-2.1f,%-2.1f,%-2.1f,%-2.1f)", h, s, l, a);
|
544
740
|
}
|
545
741
|
else
|
546
742
|
{
|
547
|
-
|
743
|
+
snprintf(name, sizeof(name), "hsl(%-2.1f,%-2.1f,%-2.1f)", h, s, l);
|
548
744
|
}
|
549
745
|
|
550
|
-
|
746
|
+
exception = AcquireExceptionInfo();
|
551
747
|
|
552
|
-
|
553
|
-
|
748
|
+
#if defined(IMAGEMAGICK_7)
|
749
|
+
QueryColorCompliance(name, AllCompliance, &pp, exception);
|
750
|
+
#else
|
751
|
+
QueryMagickColor(name, &pp, exception);
|
752
|
+
#endif
|
753
|
+
CHECK_EXCEPTION();
|
554
754
|
|
555
|
-
|
755
|
+
DestroyExceptionInfo(exception);
|
556
756
|
|
557
|
-
return
|
757
|
+
return Pixel_from_MagickPixel(&pp);
|
558
758
|
}
|
559
759
|
|
560
760
|
|
561
761
|
/**
|
562
|
-
*
|
762
|
+
* Create a Magick::Pixel object from a MagickPixel structure.
|
763
|
+
*
|
764
|
+
* No Ruby usage (internal function)
|
563
765
|
*
|
564
|
-
*
|
565
|
-
* -
|
766
|
+
* Notes:
|
767
|
+
* - Bypasses normal Pixel.new, Pixel#initialize methods
|
566
768
|
*
|
567
|
-
* @param
|
568
|
-
* @param hsl the array
|
769
|
+
* @param pp the MagickPixel
|
569
770
|
* @return a new Magick::Pixel object
|
570
|
-
* @deprecated This method has been deprecated. Please use Pixel_from_hsla.
|
571
771
|
*/
|
572
772
|
VALUE
|
573
|
-
|
773
|
+
Pixel_from_MagickPixel(const MagickPixel *pp)
|
574
774
|
{
|
575
|
-
|
576
|
-
double hue, saturation, luminosity;
|
577
|
-
|
578
|
-
class = class; // defeat "never referenced" message from icc
|
579
|
-
memset(&rgb, 0, sizeof(rgb));
|
580
|
-
|
581
|
-
hsl = rb_Array(hsl); // Ensure array
|
582
|
-
if (RARRAY_LEN(hsl) < 3)
|
583
|
-
{
|
584
|
-
rb_raise(rb_eArgError, "array argument must have at least 3 elements");
|
585
|
-
}
|
775
|
+
Pixel *pixel;
|
586
776
|
|
587
|
-
|
588
|
-
|
589
|
-
|
777
|
+
pixel = ALLOC(Pixel);
|
778
|
+
pixel->red = pp->red;
|
779
|
+
pixel->green = pp->green;
|
780
|
+
pixel->blue = pp->blue;
|
781
|
+
#if defined(IMAGEMAGICK_7)
|
782
|
+
pixel->alpha = pp->alpha;
|
783
|
+
#else
|
784
|
+
pixel->opacity = pp->opacity;
|
785
|
+
#endif
|
786
|
+
pixel->black = pp->index;
|
590
787
|
|
591
|
-
|
592
|
-
ConvertHSLToRGB(hue, saturation, luminosity,
|
593
|
-
&rgb.red, &rgb.green, &rgb.blue);
|
594
|
-
return Pixel_from_PixelPacket(&rgb);
|
788
|
+
return Data_Wrap_Struct(Class_Pixel, NULL, destroy_Pixel, pixel);
|
595
789
|
}
|
596
790
|
|
597
791
|
|
598
792
|
/**
|
599
|
-
* Create a Magick::Pixel object from a
|
793
|
+
* Create a Magick::Pixel object from a PixelPacket structure.
|
600
794
|
*
|
601
795
|
* No Ruby usage (internal function)
|
602
796
|
*
|
603
797
|
* Notes:
|
604
798
|
* - Bypasses normal Pixel.new, Pixel#initialize methods
|
605
799
|
*
|
606
|
-
* @param pp the
|
800
|
+
* @param pp the PixelPacket
|
607
801
|
* @return a new Magick::Pixel object
|
608
802
|
*/
|
609
803
|
VALUE
|
610
|
-
|
804
|
+
Pixel_from_PixelPacket(const PixelPacket *pp)
|
611
805
|
{
|
612
806
|
Pixel *pixel;
|
613
807
|
|
614
808
|
pixel = ALLOC(Pixel);
|
615
|
-
pixel->red =
|
616
|
-
pixel->green =
|
617
|
-
pixel->blue =
|
618
|
-
|
809
|
+
pixel->red = pp->red;
|
810
|
+
pixel->green = pp->green;
|
811
|
+
pixel->blue = pp->blue;
|
812
|
+
#if defined(IMAGEMAGICK_7)
|
813
|
+
pixel->alpha = pp->alpha;
|
814
|
+
pixel->black = pp->black;
|
815
|
+
#else
|
816
|
+
pixel->opacity = pp->opacity;
|
817
|
+
pixel->black = 0;
|
818
|
+
#endif
|
619
819
|
|
620
820
|
return Data_Wrap_Struct(Class_Pixel, NULL, destroy_Pixel, pixel);
|
621
821
|
}
|
622
822
|
|
623
823
|
|
624
824
|
/**
|
625
|
-
* Create a Magick::Pixel object from a
|
825
|
+
* Create a Magick::Pixel object from a PixelColor structure.
|
626
826
|
*
|
627
827
|
* No Ruby usage (internal function)
|
628
828
|
*
|
629
829
|
* Notes:
|
630
830
|
* - Bypasses normal Pixel.new, Pixel#initialize methods
|
631
831
|
*
|
632
|
-
* @param pp the
|
832
|
+
* @param pp the PixelColor
|
633
833
|
* @return a new Magick::Pixel object
|
634
834
|
*/
|
635
835
|
VALUE
|
636
|
-
|
836
|
+
Pixel_from_PixelColor(const PixelColor *pp)
|
637
837
|
{
|
638
838
|
Pixel *pixel;
|
639
839
|
|
640
|
-
pixel
|
641
|
-
|
840
|
+
pixel = ALLOC(Pixel);
|
841
|
+
pixel->red = pp->red;
|
842
|
+
pixel->green = pp->green;
|
843
|
+
pixel->blue = pp->blue;
|
844
|
+
#if defined(IMAGEMAGICK_7)
|
845
|
+
pixel->alpha = pp->alpha;
|
846
|
+
pixel->black = pp->black;
|
847
|
+
#else
|
848
|
+
pixel->opacity = pp->opacity;
|
849
|
+
pixel->black = 0;
|
850
|
+
#endif
|
851
|
+
|
642
852
|
return Data_Wrap_Struct(Class_Pixel, NULL, destroy_Pixel, pixel);
|
643
853
|
}
|
644
854
|
|
645
855
|
|
646
856
|
/**
|
647
|
-
*
|
648
|
-
* - @verbatim Pixel#hash @endverbatim
|
649
|
-
*
|
650
|
-
* Notes:
|
651
|
-
* - INT2FIX left-shifts 1 bit. Sacrifice 1 bit from the opacity attribute to
|
652
|
-
* the FIXNUM_FLAG.
|
857
|
+
* Compute a hash-code.
|
653
858
|
*
|
654
|
-
* @
|
655
|
-
* @return the hash of self
|
859
|
+
* @return [Numeric] the hash of self
|
656
860
|
*/
|
657
861
|
VALUE
|
658
862
|
Pixel_hash(VALUE self)
|
@@ -665,25 +869,23 @@ Pixel_hash(VALUE self)
|
|
665
869
|
hash = ScaleQuantumToChar(pixel->red) << 24;
|
666
870
|
hash += ScaleQuantumToChar(pixel->green) << 16;
|
667
871
|
hash += ScaleQuantumToChar(pixel->blue) << 8;
|
668
|
-
|
669
|
-
hash
|
670
|
-
|
671
|
-
|
872
|
+
#if defined(IMAGEMAGICK_7)
|
873
|
+
hash += ScaleQuantumToChar(pixel->alpha);
|
874
|
+
#else
|
875
|
+
hash += ScaleQuantumToChar(QuantumRange - pixel->opacity);
|
876
|
+
#endif
|
672
877
|
|
878
|
+
return UINT2NUM(hash >> 1);
|
673
879
|
}
|
674
880
|
|
675
881
|
|
676
882
|
/**
|
677
883
|
* Initialize clone, dup methods.
|
678
884
|
*
|
679
|
-
*
|
680
|
-
*
|
681
|
-
*
|
682
|
-
* @
|
683
|
-
* @param orig the original Pixel
|
684
|
-
* @return self
|
685
|
-
* @see Pixel_clone
|
686
|
-
* @see Pixel_dup
|
885
|
+
* @param orig [Magick::Pixel] the original Pixel
|
886
|
+
* @return [Magick::Pixel] self
|
887
|
+
* @see #clone
|
888
|
+
* @see #dup
|
687
889
|
*/
|
688
890
|
VALUE
|
689
891
|
Pixel_init_copy(VALUE self, VALUE orig)
|
@@ -700,24 +902,14 @@ Pixel_init_copy(VALUE self, VALUE orig)
|
|
700
902
|
|
701
903
|
|
702
904
|
/**
|
703
|
-
*
|
704
|
-
*
|
705
|
-
*
|
706
|
-
*
|
707
|
-
*
|
708
|
-
*
|
709
|
-
*
|
710
|
-
*
|
711
|
-
* - Default red is 0.0
|
712
|
-
* - Default green is 0.0
|
713
|
-
* - Default blue is 0.0
|
714
|
-
* - Default opacity is 0.0
|
715
|
-
* - For backward compatibility, arguments may be nil.
|
716
|
-
*
|
717
|
-
* @param argc number of input arguments
|
718
|
-
* @param argv array of input arguments
|
719
|
-
* @param self this object
|
720
|
-
* @return self
|
905
|
+
* Initialize Pixel object.
|
906
|
+
*
|
907
|
+
* @overload initialize(red = 0, green = 0, blue = 0, opacity = 0)
|
908
|
+
* @param red [Numeric] The red value
|
909
|
+
* @param green [Numeric] The green value
|
910
|
+
* @param blue [Numeric] The blue value
|
911
|
+
* @param opacity [Numeric] The opacity value
|
912
|
+
* @return [Magick::Pixel] self
|
721
913
|
*/
|
722
914
|
VALUE
|
723
915
|
Pixel_initialize(int argc, VALUE *argv, VALUE self)
|
@@ -726,13 +918,24 @@ Pixel_initialize(int argc, VALUE *argv, VALUE self)
|
|
726
918
|
|
727
919
|
Data_Get_Struct(self, Pixel, pixel);
|
728
920
|
|
921
|
+
#if defined(IMAGEMAGICK_7)
|
922
|
+
pixel->alpha = OpaqueAlpha;
|
923
|
+
#endif
|
924
|
+
|
729
925
|
switch(argc)
|
730
926
|
{
|
731
927
|
case 4:
|
928
|
+
#if defined(IMAGEMAGICK_7)
|
929
|
+
if (argv[3] != Qnil)
|
930
|
+
{
|
931
|
+
pixel->alpha = APP2QUANTUM(argv[3]);
|
932
|
+
}
|
933
|
+
#else
|
732
934
|
if (argv[3] != Qnil)
|
733
935
|
{
|
734
936
|
pixel->opacity = APP2QUANTUM(argv[3]);
|
735
937
|
}
|
938
|
+
#endif
|
736
939
|
case 3:
|
737
940
|
if (argv[2] != Qnil)
|
738
941
|
{
|
@@ -761,11 +964,7 @@ Pixel_initialize(int argc, VALUE *argv, VALUE self)
|
|
761
964
|
/**
|
762
965
|
* Return the "intensity" of a pixel.
|
763
966
|
*
|
764
|
-
*
|
765
|
-
* - @verbatim Pixel#intensity @endverbatim
|
766
|
-
*
|
767
|
-
* @param self this object
|
768
|
-
* @return the intensity
|
967
|
+
* @return [Numeric] the intensity
|
769
968
|
*/
|
770
969
|
VALUE
|
771
970
|
Pixel_intensity(VALUE self)
|
@@ -786,24 +985,27 @@ Pixel_intensity(VALUE self)
|
|
786
985
|
/**
|
787
986
|
* Support Marshal.dump.
|
788
987
|
*
|
789
|
-
*
|
790
|
-
* - @verbatim Pixel#marshal_dump @endverbatim
|
791
|
-
*
|
792
|
-
* @param self this object
|
793
|
-
* @return a string representing the dumped pixel
|
988
|
+
* @return [Hash] a representing the dumped pixel
|
794
989
|
*/
|
795
990
|
VALUE
|
796
991
|
Pixel_marshal_dump(VALUE self)
|
797
992
|
{
|
798
993
|
Pixel *pixel;
|
799
|
-
|
994
|
+
VALUE dpixel;
|
800
995
|
|
801
996
|
Data_Get_Struct(self, Pixel, pixel);
|
802
997
|
dpixel = rb_hash_new();
|
803
998
|
rb_hash_aset(dpixel, CSTR2SYM("red"), QUANTUM2NUM(pixel->red));
|
804
999
|
rb_hash_aset(dpixel, CSTR2SYM("green"), QUANTUM2NUM(pixel->green));
|
805
1000
|
rb_hash_aset(dpixel, CSTR2SYM("blue"), QUANTUM2NUM(pixel->blue));
|
1001
|
+
#if defined(IMAGEMAGICK_7)
|
1002
|
+
rb_hash_aset(dpixel, CSTR2SYM("alpha"), QUANTUM2NUM(pixel->alpha));
|
1003
|
+
#else
|
806
1004
|
rb_hash_aset(dpixel, CSTR2SYM("opacity"), QUANTUM2NUM(pixel->opacity));
|
1005
|
+
#endif
|
1006
|
+
|
1007
|
+
RB_GC_GUARD(dpixel);
|
1008
|
+
|
807
1009
|
return dpixel;
|
808
1010
|
}
|
809
1011
|
|
@@ -811,11 +1013,7 @@ Pixel_marshal_dump(VALUE self)
|
|
811
1013
|
/**
|
812
1014
|
* Support Marshal.load.
|
813
1015
|
*
|
814
|
-
*
|
815
|
-
* - @verbatim Pixel#marshal_load @endverbatim
|
816
|
-
*
|
817
|
-
* @param self this object
|
818
|
-
* @param dpixel the dumped pixel
|
1016
|
+
* @param dpixel [Hash] the dumped pixel
|
819
1017
|
* @return self
|
820
1018
|
*/
|
821
1019
|
VALUE
|
@@ -827,7 +1025,11 @@ Pixel_marshal_load(VALUE self, VALUE dpixel)
|
|
827
1025
|
pixel->red = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("red")));
|
828
1026
|
pixel->green = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("green")));
|
829
1027
|
pixel->blue = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("blue")));
|
1028
|
+
#if defined(IMAGEMAGICK_7)
|
1029
|
+
pixel->alpha = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("alpha")));
|
1030
|
+
#else
|
830
1031
|
pixel->opacity = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("opacity")));
|
1032
|
+
#endif
|
831
1033
|
return self;
|
832
1034
|
}
|
833
1035
|
|
@@ -835,12 +1037,8 @@ Pixel_marshal_load(VALUE self, VALUE dpixel)
|
|
835
1037
|
/**
|
836
1038
|
* Support Comparable mixin.
|
837
1039
|
*
|
838
|
-
*
|
839
|
-
*
|
840
|
-
*
|
841
|
-
* @param self this object
|
842
|
-
* @param other the other Pixel
|
843
|
-
* @return -1, 0, 1
|
1040
|
+
* @param other [Object] the other Pixel
|
1041
|
+
* @return [-1, 0, 1, nil] the result of compare
|
844
1042
|
*/
|
845
1043
|
VALUE
|
846
1044
|
Pixel_spaceship(VALUE self, VALUE other)
|
@@ -852,20 +1050,27 @@ Pixel_spaceship(VALUE self, VALUE other)
|
|
852
1050
|
|
853
1051
|
if (this->red != that->red)
|
854
1052
|
{
|
855
|
-
return INT2NUM((this->red - that->red)/abs(this->red - that->red));
|
1053
|
+
return INT2NUM((this->red - that->red)/abs((int)(this->red - that->red)));
|
856
1054
|
}
|
857
1055
|
else if(this->green != that->green)
|
858
1056
|
{
|
859
|
-
return INT2NUM((this->green - that->green)/abs(this->green - that->green));
|
1057
|
+
return INT2NUM((this->green - that->green)/abs((int)(this->green - that->green)));
|
860
1058
|
}
|
861
1059
|
else if(this->blue != that->blue)
|
862
1060
|
{
|
863
|
-
return INT2NUM((this->blue - that->blue)/abs(this->blue - that->blue));
|
1061
|
+
return INT2NUM((this->blue - that->blue)/abs((int)(this->blue - that->blue)));
|
864
1062
|
}
|
1063
|
+
#if defined(IMAGEMAGICK_7)
|
1064
|
+
else if(this->alpha != that->alpha)
|
1065
|
+
{
|
1066
|
+
return INT2NUM((this->alpha - that->alpha)/abs((int)(this->alpha - that->alpha)));
|
1067
|
+
}
|
1068
|
+
#else
|
865
1069
|
else if(this->opacity != that->opacity)
|
866
1070
|
{
|
867
|
-
return INT2NUM((this->opacity - that->opacity)/abs(this->opacity - that->opacity));
|
1071
|
+
return INT2NUM(((QuantumRange - this->opacity) - (QuantumRange - that->opacity))/abs((int)((QuantumRange - this->opacity) - (QuantumRange - that->opacity))));
|
868
1072
|
}
|
1073
|
+
#endif
|
869
1074
|
|
870
1075
|
// Values are equal, check class.
|
871
1076
|
|
@@ -875,26 +1080,18 @@ Pixel_spaceship(VALUE self, VALUE other)
|
|
875
1080
|
|
876
1081
|
|
877
1082
|
/**
|
878
|
-
* Return [hue
|
879
|
-
*
|
880
|
-
*
|
881
|
-
*
|
882
|
-
* Ruby usage:
|
883
|
-
* - @verbatim Pixel#to_hsla @endverbatim
|
1083
|
+
* Return [+hue+, +saturation+, +lightness+, +alpha+] in the same ranges as
|
1084
|
+
* {Magick::Pixel.from_hsla}.
|
884
1085
|
*
|
885
|
-
*
|
886
|
-
*
|
887
|
-
*
|
888
|
-
* @param self this object
|
889
|
-
* @return an array with hsla data
|
890
|
-
* @see Pixel_from_hsla
|
1086
|
+
* @return [Array<Float>] an array with hsla data
|
1087
|
+
* @see Pixel.from_hsla
|
891
1088
|
*/
|
892
1089
|
VALUE
|
893
1090
|
Pixel_to_hsla(VALUE self)
|
894
1091
|
{
|
895
1092
|
double hue, sat, lum, alpha;
|
896
1093
|
Pixel *pixel;
|
897
|
-
|
1094
|
+
VALUE hsla;
|
898
1095
|
|
899
1096
|
Data_Get_Struct(self, Pixel, pixel);
|
900
1097
|
|
@@ -903,6 +1100,20 @@ Pixel_to_hsla(VALUE self)
|
|
903
1100
|
sat *= 255.0;
|
904
1101
|
lum *= 255.0;
|
905
1102
|
|
1103
|
+
#if defined(IMAGEMAGICK_7)
|
1104
|
+
if (pixel->alpha == OpaqueAlpha)
|
1105
|
+
{
|
1106
|
+
alpha = 1.0;
|
1107
|
+
}
|
1108
|
+
else if (pixel->alpha == TransparentAlpha)
|
1109
|
+
{
|
1110
|
+
alpha = 0.0;
|
1111
|
+
}
|
1112
|
+
else
|
1113
|
+
{
|
1114
|
+
alpha = (double)(pixel->alpha) / (double)QuantumRange;
|
1115
|
+
}
|
1116
|
+
#else
|
906
1117
|
if (pixel->opacity == OpaqueOpacity)
|
907
1118
|
{
|
908
1119
|
alpha = 1.0;
|
@@ -913,63 +1124,53 @@ Pixel_to_hsla(VALUE self)
|
|
913
1124
|
}
|
914
1125
|
else
|
915
1126
|
{
|
916
|
-
alpha =
|
1127
|
+
alpha = (double)(QuantumRange - pixel->opacity) / (double)QuantumRange;
|
917
1128
|
}
|
1129
|
+
#endif
|
918
1130
|
|
919
1131
|
hsla = rb_ary_new3(4, rb_float_new(hue), rb_float_new(sat), rb_float_new(lum), rb_float_new(alpha));
|
1132
|
+
|
1133
|
+
RB_GC_GUARD(hsla);
|
1134
|
+
|
920
1135
|
return hsla;
|
921
1136
|
}
|
922
1137
|
|
1138
|
+
|
923
1139
|
/**
|
924
|
-
* Convert
|
1140
|
+
* Convert a Pixel to a MagickPixel.
|
925
1141
|
*
|
926
|
-
* Ruby usage
|
927
|
-
* - @verbatim Pixel#to_HSL @endverbatim
|
1142
|
+
* No Ruby usage (internal function)
|
928
1143
|
*
|
929
|
-
*
|
930
|
-
*
|
931
|
-
*
|
1144
|
+
* Notes:
|
1145
|
+
* - Same code as the private function SetMagickPixelPacket in ImageMagick.
|
1146
|
+
*
|
1147
|
+
* @param pixel the pixel
|
1148
|
+
* @param pp the MagickPixel to be modified
|
932
1149
|
*/
|
933
|
-
|
934
|
-
|
1150
|
+
static void
|
1151
|
+
rm_set_magick_pixel_packet(Pixel *pixel, MagickPixel *pp)
|
935
1152
|
{
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
hsl = rb_ary_new3(3, rb_float_new(hue), rb_float_new(saturation),
|
946
|
-
rb_float_new(luminosity));
|
947
|
-
|
948
|
-
return hsl;
|
1153
|
+
pp->red = (MagickRealType) pixel->red;
|
1154
|
+
pp->green = (MagickRealType) pixel->green;
|
1155
|
+
pp->blue = (MagickRealType) pixel->blue;
|
1156
|
+
#if defined(IMAGEMAGICK_7)
|
1157
|
+
pp->alpha = (MagickRealType) pixel->alpha;
|
1158
|
+
#else
|
1159
|
+
pp->opacity = (MagickRealType) pixel->opacity;
|
1160
|
+
#endif
|
1161
|
+
pp->index = (MagickRealType) 0.0;
|
949
1162
|
}
|
950
1163
|
|
951
1164
|
|
952
1165
|
/**
|
953
1166
|
* Return the color name corresponding to the pixel values.
|
954
1167
|
*
|
955
|
-
*
|
956
|
-
*
|
957
|
-
*
|
958
|
-
*
|
959
|
-
*
|
960
|
-
*
|
961
|
-
*
|
962
|
-
* Notes:
|
963
|
-
* - Default compliance is AllCompliance
|
964
|
-
* - Default matte is false
|
965
|
-
* - Default depth is QuantumDepth
|
966
|
-
* - Default hex is false
|
967
|
-
* - The conversion respects the value of the 'opacity' field in the Pixel
|
968
|
-
*
|
969
|
-
* @param argc number of input arguments
|
970
|
-
* @param argv array of input arguments
|
971
|
-
* @param self this object
|
972
|
-
* @return the color name as a String
|
1168
|
+
* @overload to_color(compliance = Magick::AllCompliance, alpha = false, depth = Magick::MAGICKCORE_QUANTUM_DEPTH, hex = false)
|
1169
|
+
* @param compliance [Magick::ComplianceType] A ComplianceType constant
|
1170
|
+
* @param alpha [Boolean] If false, the pixel's alpha attribute is ignored
|
1171
|
+
* @param depth [Numeric] An image depth
|
1172
|
+
* @param hex [Boolean] If true, represent the color name in hex format
|
1173
|
+
* @return [String] the color name as a String
|
973
1174
|
*/
|
974
1175
|
VALUE
|
975
1176
|
Pixel_to_color(int argc, VALUE *argv, VALUE self)
|
@@ -977,13 +1178,13 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
|
|
977
1178
|
Info *info;
|
978
1179
|
Image *image;
|
979
1180
|
Pixel *pixel;
|
980
|
-
|
1181
|
+
MagickPixel mpp;
|
981
1182
|
MagickBooleanType hex = MagickFalse;
|
982
1183
|
char name[MaxTextExtent];
|
983
|
-
ExceptionInfo exception;
|
1184
|
+
ExceptionInfo *exception;
|
984
1185
|
ComplianceType compliance = AllCompliance;
|
985
|
-
unsigned int
|
986
|
-
unsigned int depth =
|
1186
|
+
unsigned int alpha = MagickFalse;
|
1187
|
+
unsigned int depth = MAGICKCORE_QUANTUM_DEPTH;
|
987
1188
|
|
988
1189
|
switch (argc)
|
989
1190
|
{
|
@@ -996,10 +1197,10 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
|
|
996
1197
|
switch (depth)
|
997
1198
|
{
|
998
1199
|
case 8:
|
999
|
-
#if
|
1200
|
+
#if MAGICKCORE_QUANTUM_DEPTH == 16 || MAGICKCORE_QUANTUM_DEPTH == 32
|
1000
1201
|
case 16:
|
1001
1202
|
#endif
|
1002
|
-
#if
|
1203
|
+
#if MAGICKCORE_QUANTUM_DEPTH == 32
|
1003
1204
|
case 32:
|
1004
1205
|
#endif
|
1005
1206
|
break;
|
@@ -1008,7 +1209,7 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
|
|
1008
1209
|
break;
|
1009
1210
|
}
|
1010
1211
|
case 2:
|
1011
|
-
|
1212
|
+
alpha = RTEST(argv[1]);
|
1012
1213
|
case 1:
|
1013
1214
|
VALUE_TO_ENUM(argv[0], compliance, ComplianceType);
|
1014
1215
|
case 0:
|
@@ -1020,38 +1221,52 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
|
|
1020
1221
|
Data_Get_Struct(self, Pixel, pixel);
|
1021
1222
|
|
1022
1223
|
info = CloneImageInfo(NULL);
|
1023
|
-
image =
|
1224
|
+
image = rm_acquire_image(info);
|
1225
|
+
DestroyImageInfo(info);
|
1226
|
+
|
1227
|
+
if (!image)
|
1228
|
+
{
|
1229
|
+
rb_raise(rb_eNoMemError, "not enough memory to continue.");
|
1230
|
+
}
|
1231
|
+
|
1232
|
+
exception = AcquireExceptionInfo();
|
1233
|
+
|
1024
1234
|
image->depth = depth;
|
1025
|
-
|
1026
|
-
|
1235
|
+
#if defined(IMAGEMAGICK_7)
|
1236
|
+
if (alpha)
|
1237
|
+
{
|
1238
|
+
image->alpha_trait = BlendPixelTrait;
|
1239
|
+
}
|
1240
|
+
#else
|
1241
|
+
image->matte = alpha;
|
1242
|
+
#endif
|
1027
1243
|
|
1028
|
-
|
1244
|
+
rm_init_magickpixel(image, &mpp);
|
1029
1245
|
rm_set_magick_pixel_packet(pixel, &mpp);
|
1030
1246
|
|
1031
|
-
GetExceptionInfo(&exception);
|
1032
|
-
|
1033
|
-
#if defined(HAVE_NEW_QUERYMAGICKCOLORNAME)
|
1034
1247
|
// Support for hex-format color names moved out of QueryMagickColorname
|
1035
1248
|
// in 6.4.1-9. The 'hex' argument was removed as well.
|
1036
1249
|
if (hex)
|
1037
1250
|
{
|
1038
1251
|
if (compliance == XPMCompliance)
|
1039
1252
|
{
|
1253
|
+
#if defined(IMAGEMAGICK_7)
|
1254
|
+
mpp.alpha_trait = UndefinedPixelTrait;
|
1255
|
+
#else
|
1040
1256
|
mpp.matte = MagickFalse;
|
1257
|
+
#endif
|
1041
1258
|
mpp.depth = (unsigned long) min(1.0 * image->depth, 16.0);
|
1042
1259
|
}
|
1043
|
-
|
1260
|
+
GetColorTuple(&mpp, MagickTrue, name);
|
1044
1261
|
}
|
1045
1262
|
else
|
1046
1263
|
{
|
1047
|
-
(
|
1264
|
+
QueryColorname(image, &mpp, compliance, name, exception);
|
1048
1265
|
}
|
1049
|
-
|
1050
|
-
(
|
1051
|
-
|
1052
|
-
(
|
1053
|
-
CHECK_EXCEPTION()
|
1054
|
-
(void) DestroyExceptionInfo(&exception);
|
1266
|
+
|
1267
|
+
DestroyImage(image);
|
1268
|
+
CHECK_EXCEPTION();
|
1269
|
+
DestroyExceptionInfo(exception);
|
1055
1270
|
|
1056
1271
|
// Always return a string, even if it's ""
|
1057
1272
|
return rb_str_new2(name);
|
@@ -1059,13 +1274,9 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
|
|
1059
1274
|
|
1060
1275
|
|
1061
1276
|
/**
|
1062
|
-
*
|
1277
|
+
* Return a string representation of a {Magick::Pixel} object.
|
1063
1278
|
*
|
1064
|
-
*
|
1065
|
-
* - @verbatim Magick::Pixel#to_s @endverbatim
|
1066
|
-
*
|
1067
|
-
* @param self this object
|
1068
|
-
* @return the string
|
1279
|
+
* @return [String] the string
|
1069
1280
|
*/
|
1070
1281
|
VALUE
|
1071
1282
|
Pixel_to_s(VALUE self)
|
@@ -1074,30 +1285,13 @@ Pixel_to_s(VALUE self)
|
|
1074
1285
|
char buff[100];
|
1075
1286
|
|
1076
1287
|
Data_Get_Struct(self, Pixel, pixel);
|
1077
|
-
|
1078
|
-
|
1288
|
+
snprintf(buff, sizeof(buff), "red=" QuantumFormat ", green=" QuantumFormat ", blue=" QuantumFormat ", alpha=" QuantumFormat,
|
1289
|
+
pixel->red, pixel->green, pixel->blue,
|
1290
|
+
#if defined(IMAGEMAGICK_7)
|
1291
|
+
pixel->alpha);
|
1292
|
+
#else
|
1293
|
+
(QuantumRange - pixel->opacity));
|
1294
|
+
#endif
|
1079
1295
|
return rb_str_new2(buff);
|
1080
1296
|
}
|
1081
1297
|
|
1082
|
-
|
1083
|
-
/**
|
1084
|
-
* Convert a PixelPacket to a MagickPixelPacket.
|
1085
|
-
*
|
1086
|
-
* No Ruby usage (internal function)
|
1087
|
-
*
|
1088
|
-
* Notes:
|
1089
|
-
* - Same code as the private function SetMagickPixelPacket in ImageMagick.
|
1090
|
-
*
|
1091
|
-
* @param pixel the pixel
|
1092
|
-
* @param pp the MagickPixelPacket to be modified
|
1093
|
-
*/
|
1094
|
-
void
|
1095
|
-
rm_set_magick_pixel_packet(Pixel *pixel, MagickPixelPacket *pp)
|
1096
|
-
{
|
1097
|
-
pp->red = (MagickRealType) pixel->red;
|
1098
|
-
pp->green = (MagickRealType) pixel->green;
|
1099
|
-
pp->blue = (MagickRealType) pixel->blue;
|
1100
|
-
pp->opacity = (MagickRealType) pixel->opacity;
|
1101
|
-
pp->index = (MagickRealType) 0.0;
|
1102
|
-
}
|
1103
|
-
|