rmagick 4.0.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (420) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +14 -0
  3. data/.devcontainer/ImageMagick6/devcontainer.json +11 -0
  4. data/.devcontainer/devcontainer.json +11 -0
  5. data/.devcontainer/setup-repo.sh +10 -0
  6. data/.devcontainer/setup-user.sh +45 -0
  7. data/.editorconfig +3 -0
  8. data/.github/ISSUE_TEMPLATE.md +17 -0
  9. data/.github/workflows/ci.yml +138 -0
  10. data/.gitignore +5 -1
  11. data/.rspec +1 -0
  12. data/.rubocop.yml +24 -0
  13. data/.rubocop_todo.yml +150 -297
  14. data/.yardopts +5 -0
  15. data/CHANGELOG.md +222 -0
  16. data/CODE_OF_CONDUCT.md +122 -7
  17. data/CONTRIBUTING.md +14 -10
  18. data/README.md +316 -0
  19. data/Rakefile +59 -93
  20. data/before_install_linux.sh +23 -29
  21. data/before_install_osx.sh +58 -2
  22. data/ext/RMagick/extconf.rb +191 -110
  23. data/ext/RMagick/rmagick.c +77 -104
  24. data/ext/RMagick/rmagick.h +138 -99
  25. data/ext/RMagick/rmagick_gvl.h +224 -0
  26. data/ext/RMagick/rmdraw.c +464 -526
  27. data/ext/RMagick/rmenum.c +132 -121
  28. data/ext/RMagick/rmfill.c +223 -83
  29. data/ext/RMagick/rmilist.c +360 -288
  30. data/ext/RMagick/rmimage.c +5550 -4318
  31. data/ext/RMagick/rminfo.c +637 -818
  32. data/ext/RMagick/rmkinfo.c +88 -92
  33. data/ext/RMagick/rmmain.c +462 -263
  34. data/ext/RMagick/rmmontage.c +105 -150
  35. data/ext/RMagick/rmpixel.c +554 -359
  36. data/ext/RMagick/rmstruct.c +81 -94
  37. data/ext/RMagick/rmutil.c +279 -270
  38. data/lib/rmagick/version.rb +3 -1
  39. data/lib/rmagick.rb +2 -0
  40. data/lib/rmagick_internal.rb +118 -104
  41. data/lib/rvg/clippath.rb +2 -1
  42. data/lib/rvg/container.rb +10 -5
  43. data/lib/rvg/describable.rb +1 -1
  44. data/lib/rvg/embellishable.rb +5 -4
  45. data/lib/rvg/misc.rb +15 -12
  46. data/lib/rvg/paint.rb +2 -1
  47. data/lib/rvg/pathdata.rb +12 -11
  48. data/lib/rvg/rvg.rb +10 -6
  49. data/lib/rvg/stylable.rb +9 -7
  50. data/lib/rvg/text.rb +11 -6
  51. data/lib/rvg/transformable.rb +3 -2
  52. data/lib/rvg/units.rb +1 -1
  53. data/rmagick.gemspec +13 -12
  54. metadata +63 -419
  55. data/.appveyor.yml +0 -45
  56. data/.circleci/config.yml +0 -56
  57. data/.ruby-version +0 -1
  58. data/.simplecov +0 -27
  59. data/.travis.yml +0 -62
  60. data/Doxyfile +0 -1514
  61. data/README.textile +0 -259
  62. data/benchmarks/memory/README.md +0 -50
  63. data/benchmarks/memory/image_new.rb +0 -8
  64. data/benchmarks/memory/rmagick.gnuplot +0 -16
  65. data/deprecated/RMagick.rb +0 -6
  66. data/doc/.cvsignore +0 -1
  67. data/doc/comtasks.html +0 -287
  68. data/doc/constants.html +0 -1581
  69. data/doc/css/doc.css +0 -299
  70. data/doc/css/popup.css +0 -34
  71. data/doc/css/ref.css +0 -67
  72. data/doc/draw.html +0 -3272
  73. data/doc/ex/InitialCoords.rb +0 -22
  74. data/doc/ex/NewCoordSys.rb +0 -30
  75. data/doc/ex/OrigCoordSys.rb +0 -16
  76. data/doc/ex/PreserveAspectRatio.rb +0 -204
  77. data/doc/ex/RotateScale.rb +0 -36
  78. data/doc/ex/Skew.rb +0 -38
  79. data/doc/ex/Use01.rb +0 -15
  80. data/doc/ex/Use02.rb +0 -20
  81. data/doc/ex/Use03.rb +0 -16
  82. data/doc/ex/ViewBox.rb +0 -31
  83. data/doc/ex/adaptive_threshold.rb +0 -9
  84. data/doc/ex/add_noise.rb +0 -16
  85. data/doc/ex/affine.rb +0 -48
  86. data/doc/ex/affine_transform.rb +0 -20
  87. data/doc/ex/arc.rb +0 -49
  88. data/doc/ex/arcpath.rb +0 -32
  89. data/doc/ex/arcs01.rb +0 -28
  90. data/doc/ex/arcs02.rb +0 -59
  91. data/doc/ex/average.rb +0 -15
  92. data/doc/ex/axes.rb +0 -64
  93. data/doc/ex/baseline_shift01.rb +0 -17
  94. data/doc/ex/bilevel_channel.rb +0 -8
  95. data/doc/ex/blur_image.rb +0 -12
  96. data/doc/ex/border.rb +0 -10
  97. data/doc/ex/bounding_box.rb +0 -42
  98. data/doc/ex/cbezier1.rb +0 -41
  99. data/doc/ex/cbezier2.rb +0 -41
  100. data/doc/ex/cbezier3.rb +0 -41
  101. data/doc/ex/cbezier4.rb +0 -42
  102. data/doc/ex/cbezier5.rb +0 -42
  103. data/doc/ex/cbezier6.rb +0 -53
  104. data/doc/ex/channel.rb +0 -25
  105. data/doc/ex/charcoal.rb +0 -12
  106. data/doc/ex/chop.rb +0 -29
  107. data/doc/ex/circle.rb +0 -33
  108. data/doc/ex/circle01.rb +0 -16
  109. data/doc/ex/clip_path.rb +0 -60
  110. data/doc/ex/coalesce.rb +0 -57
  111. data/doc/ex/color_fill_to_border.rb +0 -29
  112. data/doc/ex/color_floodfill.rb +0 -28
  113. data/doc/ex/color_histogram.rb +0 -47
  114. data/doc/ex/color_reset.rb +0 -11
  115. data/doc/ex/colorize.rb +0 -16
  116. data/doc/ex/colors.rb +0 -64
  117. data/doc/ex/compose_mask.rb +0 -22
  118. data/doc/ex/composite.rb +0 -133
  119. data/doc/ex/composite_layers.rb +0 -52
  120. data/doc/ex/composite_tiled.rb +0 -21
  121. data/doc/ex/contrast.rb +0 -36
  122. data/doc/ex/crop.rb +0 -31
  123. data/doc/ex/crop_with_gravity.rb +0 -42
  124. data/doc/ex/cubic01.rb +0 -43
  125. data/doc/ex/cubic02.rb +0 -91
  126. data/doc/ex/cycle_colormap.rb +0 -21
  127. data/doc/ex/dissolve.rb +0 -12
  128. data/doc/ex/drawcomp.rb +0 -41
  129. data/doc/ex/drop_shadow.rb +0 -60
  130. data/doc/ex/edge.rb +0 -11
  131. data/doc/ex/ellipse.rb +0 -45
  132. data/doc/ex/ellipse01.rb +0 -21
  133. data/doc/ex/emboss.rb +0 -11
  134. data/doc/ex/enhance.rb +0 -28
  135. data/doc/ex/equalize.rb +0 -11
  136. data/doc/ex/evenodd.rb +0 -42
  137. data/doc/ex/fill_pattern.rb +0 -23
  138. data/doc/ex/flatten_images.rb +0 -36
  139. data/doc/ex/flip.rb +0 -11
  140. data/doc/ex/flop.rb +0 -11
  141. data/doc/ex/font_styles.rb +0 -32
  142. data/doc/ex/fonts.rb +0 -16
  143. data/doc/ex/frame.rb +0 -12
  144. data/doc/ex/gaussian_blur.rb +0 -11
  145. data/doc/ex/get_multiline_type_metrics.rb +0 -41
  146. data/doc/ex/get_pixels.rb +0 -45
  147. data/doc/ex/get_type_metrics.rb +0 -142
  148. data/doc/ex/gradientfill.rb +0 -27
  149. data/doc/ex/grav.rb +0 -45
  150. data/doc/ex/gravity.rb +0 -78
  151. data/doc/ex/group.rb +0 -26
  152. data/doc/ex/hatchfill.rb +0 -27
  153. data/doc/ex/image.rb +0 -44
  154. data/doc/ex/images/Apple.miff +0 -0
  155. data/doc/ex/images/Ballerina.jpg +0 -0
  156. data/doc/ex/images/Ballerina3.jpg +0 -0
  157. data/doc/ex/images/Button_0.gif +0 -0
  158. data/doc/ex/images/Button_1.gif +0 -0
  159. data/doc/ex/images/Button_2.gif +0 -0
  160. data/doc/ex/images/Button_3.gif +0 -0
  161. data/doc/ex/images/Button_4.gif +0 -0
  162. data/doc/ex/images/Button_5.gif +0 -0
  163. data/doc/ex/images/Button_6.gif +0 -0
  164. data/doc/ex/images/Button_7.gif +0 -0
  165. data/doc/ex/images/Button_8.gif +0 -0
  166. data/doc/ex/images/Button_9.gif +0 -0
  167. data/doc/ex/images/Button_A.gif +0 -0
  168. data/doc/ex/images/Button_B.gif +0 -0
  169. data/doc/ex/images/Button_C.gif +0 -0
  170. data/doc/ex/images/Button_D.gif +0 -0
  171. data/doc/ex/images/Button_E.gif +0 -0
  172. data/doc/ex/images/Button_F.gif +0 -0
  173. data/doc/ex/images/Button_G.gif +0 -0
  174. data/doc/ex/images/Button_H.gif +0 -0
  175. data/doc/ex/images/Button_I.gif +0 -0
  176. data/doc/ex/images/Button_J.gif +0 -0
  177. data/doc/ex/images/Button_K.gif +0 -0
  178. data/doc/ex/images/Button_L.gif +0 -0
  179. data/doc/ex/images/Button_M.gif +0 -0
  180. data/doc/ex/images/Button_N.gif +0 -0
  181. data/doc/ex/images/Button_O.gif +0 -0
  182. data/doc/ex/images/Button_P.gif +0 -0
  183. data/doc/ex/images/Button_Q.gif +0 -0
  184. data/doc/ex/images/Button_R.gif +0 -0
  185. data/doc/ex/images/Button_S.gif +0 -0
  186. data/doc/ex/images/Button_T.gif +0 -0
  187. data/doc/ex/images/Button_U.gif +0 -0
  188. data/doc/ex/images/Button_V.gif +0 -0
  189. data/doc/ex/images/Button_W.gif +0 -0
  190. data/doc/ex/images/Button_X.gif +0 -0
  191. data/doc/ex/images/Button_Y.gif +0 -0
  192. data/doc/ex/images/Button_Z.gif +0 -0
  193. data/doc/ex/images/Cheetah.jpg +0 -0
  194. data/doc/ex/images/Coffee.png +0 -0
  195. data/doc/ex/images/Flower_Hat.jpg +0 -0
  196. data/doc/ex/images/Gold_Statue.jpg +0 -0
  197. data/doc/ex/images/Hot_Air_Balloons.jpg +0 -0
  198. data/doc/ex/images/Hot_Air_Balloons_H.jpg +0 -0
  199. data/doc/ex/images/Leaf.miff +0 -0
  200. data/doc/ex/images/No.png +0 -0
  201. data/doc/ex/images/Polynesia.jpg +0 -0
  202. data/doc/ex/images/Red_Rocks.jpg +0 -0
  203. data/doc/ex/images/Rocks_On_Beach.miff +0 -0
  204. data/doc/ex/images/Shorts.jpg +0 -0
  205. data/doc/ex/images/Snake.png +0 -0
  206. data/doc/ex/images/Violin.jpg +0 -0
  207. data/doc/ex/images/Yellow_Rose.miff +0 -0
  208. data/doc/ex/images/big-duck.gif +0 -0
  209. data/doc/ex/images/duck.gif +0 -0
  210. data/doc/ex/images/duck0.gif +0 -0
  211. data/doc/ex/images/duck1.gif +0 -0
  212. data/doc/ex/images/duck10.gif +0 -0
  213. data/doc/ex/images/duck11.gif +0 -0
  214. data/doc/ex/images/duck12.gif +0 -0
  215. data/doc/ex/images/duck13.gif +0 -0
  216. data/doc/ex/images/duck14.gif +0 -0
  217. data/doc/ex/images/duck15.gif +0 -0
  218. data/doc/ex/images/duck2.gif +0 -0
  219. data/doc/ex/images/duck3.gif +0 -0
  220. data/doc/ex/images/duck4.gif +0 -0
  221. data/doc/ex/images/duck5.gif +0 -0
  222. data/doc/ex/images/duck6.gif +0 -0
  223. data/doc/ex/images/duck7.gif +0 -0
  224. data/doc/ex/images/duck8.gif +0 -0
  225. data/doc/ex/images/duck9.gif +0 -0
  226. data/doc/ex/images/graydient230x6.gif +0 -0
  227. data/doc/ex/images/image_with_profile.jpg +0 -0
  228. data/doc/ex/images/logo400x83.gif +0 -0
  229. data/doc/ex/images/model.miff +0 -0
  230. data/doc/ex/images/notimplemented.gif +0 -0
  231. data/doc/ex/images/smile.miff +0 -0
  232. data/doc/ex/images/spin.gif +0 -0
  233. data/doc/ex/implode.rb +0 -34
  234. data/doc/ex/level.rb +0 -11
  235. data/doc/ex/level_colors.rb +0 -11
  236. data/doc/ex/line.rb +0 -41
  237. data/doc/ex/line01.rb +0 -21
  238. data/doc/ex/mask.rb +0 -35
  239. data/doc/ex/matte_fill_to_border.rb +0 -39
  240. data/doc/ex/matte_floodfill.rb +0 -32
  241. data/doc/ex/matte_replace.rb +0 -39
  242. data/doc/ex/median_filter.rb +0 -28
  243. data/doc/ex/modulate.rb +0 -11
  244. data/doc/ex/mono.rb +0 -23
  245. data/doc/ex/morph.rb +0 -25
  246. data/doc/ex/mosaic.rb +0 -37
  247. data/doc/ex/motion_blur.rb +0 -11
  248. data/doc/ex/negate.rb +0 -11
  249. data/doc/ex/negate_channel.rb +0 -9
  250. data/doc/ex/nested_rvg.rb +0 -21
  251. data/doc/ex/nonzero.rb +0 -42
  252. data/doc/ex/normalize.rb +0 -11
  253. data/doc/ex/oil_paint.rb +0 -11
  254. data/doc/ex/opacity.rb +0 -37
  255. data/doc/ex/ordered_dither.rb +0 -11
  256. data/doc/ex/path.rb +0 -63
  257. data/doc/ex/pattern1.rb +0 -25
  258. data/doc/ex/pattern2.rb +0 -26
  259. data/doc/ex/polaroid.rb +0 -26
  260. data/doc/ex/polygon.rb +0 -23
  261. data/doc/ex/polygon01.rb +0 -21
  262. data/doc/ex/polyline.rb +0 -22
  263. data/doc/ex/polyline01.rb +0 -21
  264. data/doc/ex/posterize.rb +0 -8
  265. data/doc/ex/preview.rb +0 -8
  266. data/doc/ex/qbezierpath.rb +0 -52
  267. data/doc/ex/quad01.rb +0 -34
  268. data/doc/ex/quantize-m.rb +0 -25
  269. data/doc/ex/radial_blur.rb +0 -9
  270. data/doc/ex/raise.rb +0 -8
  271. data/doc/ex/random_threshold_channel.rb +0 -13
  272. data/doc/ex/rect01.rb +0 -14
  273. data/doc/ex/rect02.rb +0 -20
  274. data/doc/ex/rectangle.rb +0 -34
  275. data/doc/ex/reduce_noise.rb +0 -28
  276. data/doc/ex/remap.rb +0 -11
  277. data/doc/ex/remap_images.rb +0 -19
  278. data/doc/ex/resize_to_fill.rb +0 -8
  279. data/doc/ex/resize_to_fit.rb +0 -8
  280. data/doc/ex/roll.rb +0 -9
  281. data/doc/ex/rotate.rb +0 -44
  282. data/doc/ex/rotate_f.rb +0 -14
  283. data/doc/ex/roundrect.rb +0 -33
  284. data/doc/ex/rubyname.rb +0 -30
  285. data/doc/ex/rvg_clippath.rb +0 -12
  286. data/doc/ex/rvg_linecap.rb +0 -42
  287. data/doc/ex/rvg_linejoin.rb +0 -40
  288. data/doc/ex/rvg_opacity.rb +0 -18
  289. data/doc/ex/rvg_pattern.rb +0 -26
  290. data/doc/ex/rvg_stroke_dasharray.rb +0 -11
  291. data/doc/ex/segment.rb +0 -11
  292. data/doc/ex/sepiatone.rb +0 -7
  293. data/doc/ex/shade.rb +0 -11
  294. data/doc/ex/shadow.rb +0 -30
  295. data/doc/ex/shave.rb +0 -15
  296. data/doc/ex/shear.rb +0 -10
  297. data/doc/ex/sketch.rb +0 -17
  298. data/doc/ex/skewx.rb +0 -51
  299. data/doc/ex/skewy.rb +0 -47
  300. data/doc/ex/smile.rb +0 -126
  301. data/doc/ex/solarize.rb +0 -11
  302. data/doc/ex/sparse_color.rb +0 -55
  303. data/doc/ex/splice.rb +0 -8
  304. data/doc/ex/spread.rb +0 -11
  305. data/doc/ex/stegano.rb +0 -54
  306. data/doc/ex/stroke_dasharray.rb +0 -42
  307. data/doc/ex/stroke_fill.rb +0 -10
  308. data/doc/ex/stroke_linecap.rb +0 -44
  309. data/doc/ex/stroke_linejoin.rb +0 -48
  310. data/doc/ex/stroke_width.rb +0 -49
  311. data/doc/ex/swirl.rb +0 -17
  312. data/doc/ex/text.rb +0 -37
  313. data/doc/ex/text01.rb +0 -16
  314. data/doc/ex/text_align.rb +0 -36
  315. data/doc/ex/text_antialias.rb +0 -37
  316. data/doc/ex/text_styles.rb +0 -19
  317. data/doc/ex/text_undercolor.rb +0 -28
  318. data/doc/ex/texture_fill_to_border.rb +0 -34
  319. data/doc/ex/texture_floodfill.rb +0 -32
  320. data/doc/ex/texturefill.rb +0 -24
  321. data/doc/ex/threshold.rb +0 -13
  322. data/doc/ex/to_blob.rb +0 -13
  323. data/doc/ex/translate.rb +0 -39
  324. data/doc/ex/transparent.rb +0 -38
  325. data/doc/ex/transpose.rb +0 -9
  326. data/doc/ex/transverse.rb +0 -9
  327. data/doc/ex/tref01.rb +0 -24
  328. data/doc/ex/triangle01.rb +0 -15
  329. data/doc/ex/trim.rb +0 -23
  330. data/doc/ex/tspan01.rb +0 -17
  331. data/doc/ex/tspan02.rb +0 -17
  332. data/doc/ex/tspan03.rb +0 -19
  333. data/doc/ex/unsharp_mask.rb +0 -28
  334. data/doc/ex/viewex.rb +0 -33
  335. data/doc/ex/vignette.rb +0 -12
  336. data/doc/ex/watermark.rb +0 -27
  337. data/doc/ex/wave.rb +0 -9
  338. data/doc/ex/wet_floor.rb +0 -58
  339. data/doc/ex/writing_mode01.rb +0 -26
  340. data/doc/ex/writing_mode02.rb +0 -26
  341. data/doc/ilist.html +0 -2056
  342. data/doc/image1.html +0 -4680
  343. data/doc/image2.html +0 -3665
  344. data/doc/image3.html +0 -4522
  345. data/doc/imageattrs.html +0 -1638
  346. data/doc/imusage.html +0 -514
  347. data/doc/index.html +0 -416
  348. data/doc/info.html +0 -1499
  349. data/doc/magick.html +0 -570
  350. data/doc/optequiv.html +0 -2435
  351. data/doc/rvg.html +0 -975
  352. data/doc/rvgclip.html +0 -248
  353. data/doc/rvggroup.html +0 -305
  354. data/doc/rvgimage.html +0 -289
  355. data/doc/rvgpattern.html +0 -475
  356. data/doc/rvgshape.html +0 -406
  357. data/doc/rvgstyle.html +0 -270
  358. data/doc/rvgtext.html +0 -465
  359. data/doc/rvgtspan.html +0 -238
  360. data/doc/rvgtut.html +0 -530
  361. data/doc/rvguse.html +0 -145
  362. data/doc/rvgxform.html +0 -294
  363. data/doc/scripts/doc.js +0 -22
  364. data/doc/scripts/stripeTables.js +0 -23
  365. data/doc/struct.html +0 -1339
  366. data/doc/usage.html +0 -1621
  367. data/examples/constitute.rb +0 -7
  368. data/examples/crop_with_gravity.rb +0 -43
  369. data/examples/demo.rb +0 -323
  370. data/examples/describe.rb +0 -41
  371. data/examples/find_similar_region.rb +0 -34
  372. data/examples/histogram.rb +0 -312
  373. data/examples/identify.rb +0 -174
  374. data/examples/image_opacity.rb +0 -28
  375. data/examples/import_export.rb +0 -31
  376. data/examples/pattern_fill.rb +0 -37
  377. data/examples/rotating_text.rb +0 -45
  378. data/examples/spinner.rb +0 -49
  379. data/examples/thumbnail.rb +0 -64
  380. data/examples/vignette.rb +0 -78
  381. data/spec/rmagick/ImageList1_spec.rb +0 -24
  382. data/spec/rmagick/draw_spec.rb +0 -155
  383. data/spec/rmagick/image/blue_shift_spec.rb +0 -14
  384. data/spec/rmagick/image/channel_entropy_spec.rb +0 -9
  385. data/spec/rmagick/image/composite_spec.rb +0 -72
  386. data/spec/rmagick/image/constitute_spec.rb +0 -13
  387. data/spec/rmagick/image/dispatch_spec.rb +0 -16
  388. data/spec/rmagick/image/from_blob_spec.rb +0 -12
  389. data/spec/rmagick/image/ping_spec.rb +0 -12
  390. data/spec/rmagick/image/properties_spec.rb +0 -27
  391. data/spec/rmagick/image/read_spec.rb +0 -28
  392. data/spec/spec_helper.rb +0 -10
  393. data/spec/support/issue_200/app.rb +0 -8
  394. data/test/Draw.rb +0 -351
  395. data/test/Enum.rb +0 -228
  396. data/test/Fill.rb +0 -93
  397. data/test/Image1.rb +0 -606
  398. data/test/Image2.rb +0 -1408
  399. data/test/Image3.rb +0 -1086
  400. data/test/ImageList1.rb +0 -858
  401. data/test/ImageList2.rb +0 -375
  402. data/test/Image_attributes.rb +0 -635
  403. data/test/Import_Export.rb +0 -111
  404. data/test/Info.rb +0 -436
  405. data/test/KernelInfo.rb +0 -59
  406. data/test/Magick.rb +0 -311
  407. data/test/Pixel.rb +0 -259
  408. data/test/PolaroidOptions.rb +0 -23
  409. data/test/Preview.rb +0 -26
  410. data/test/Struct.rb +0 -45
  411. data/test/appearance/Montage.rb +0 -26
  412. data/test/appearance/appearance_assertion.rb +0 -13
  413. data/test/appearance/expected/montage_border_color.jpg +0 -0
  414. data/test/cmyk.icm +0 -0
  415. data/test/lib/internal/Draw.rb +0 -811
  416. data/test/lib/internal/Geometry.rb +0 -98
  417. data/test/lib/internal/Magick.rb +0 -40
  418. data/test/srgb.icm +0 -0
  419. data/test/test_all_basic.rb +0 -49
  420. data/test/tmpnam_test.rb +0 -50
@@ -12,55 +12,22 @@
12
12
 
13
13
  #include "rmagick.h"
14
14
 
15
-
16
- /*
17
- * Declare Pixel channel attribute writers
18
- */
19
- //! Pixel channel attribute writer.
20
- #define DEF_PIXEL_CHANNEL_WRITER(_channel_) \
21
- extern VALUE \
22
- Pixel_##_channel_##_eq(VALUE self, VALUE v) \
23
- { \
24
- Pixel *pixel; \
25
- \
26
- rb_check_frozen(self); \
27
- Data_Get_Struct(self, Pixel, pixel); \
28
- pixel->_channel_ = APP2QUANTUM(v); \
29
- (void) rb_funcall(self, rm_ID_changed, 0); \
30
- (void) rb_funcall(self, rm_ID_notify_observers, 1, self); \
31
- return QUANTUM2NUM((pixel->_channel_)); \
32
- }
33
-
34
-
35
- /*
36
- * Declare Pixel CMYK channel attribute accessors
37
- */
38
- //! Pixel CMYK channel attribute accessor.
39
- #define DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(_cmyk_channel_, _rgb_channel_) \
40
- extern VALUE \
41
- Pixel_##_cmyk_channel_##_eq(VALUE self, VALUE v) \
42
- { \
43
- Pixel *pixel; \
44
- \
45
- rb_check_frozen(self); \
46
- Data_Get_Struct(self, Pixel, pixel); \
47
- pixel->_rgb_channel_ = APP2QUANTUM(v); \
48
- (void) rb_funcall(self, rm_ID_changed, 0); \
49
- (void) rb_funcall(self, rm_ID_notify_observers, 1, self); \
50
- return QUANTUM2NUM(pixel->_rgb_channel_); \
51
- } \
52
- \
53
- extern VALUE \
54
- Pixel_##_cmyk_channel_(VALUE self) \
55
- { \
56
- Pixel *pixel; \
57
- \
58
- Data_Get_Struct(self, Pixel, pixel); \
59
- return INT2NUM(pixel->_rgb_channel_); \
60
- }
15
+ #if defined(IMAGEMAGICK_6)
16
+ #define QueryColorname QueryMagickColorname
17
+ #endif
61
18
 
62
19
 
20
+ static VALUE color_arg_rescue(VALUE, VALUE ATTRIBUTE_UNUSED) ATTRIBUTE_NORETURN;
63
21
  static void Color_Name_to_PixelColor(PixelColor *, VALUE);
22
+ static void Pixel_destroy(void *);
23
+ static size_t Pixel_memsize(const void *);
24
+
25
+ const rb_data_type_t rm_pixel_data_type = {
26
+ "Magick::Pixel",
27
+ { NULL, Pixel_destroy, Pixel_memsize, },
28
+ 0, 0,
29
+ RUBY_TYPED_FROZEN_SHAREABLE,
30
+ };
64
31
 
65
32
 
66
33
  /**
@@ -68,151 +35,334 @@ static void Color_Name_to_PixelColor(PixelColor *, VALUE);
68
35
  *
69
36
  * No Ruby usage (internal function)
70
37
  *
71
- * @param pixel the Pixel object to destroy
38
+ * @param ptr the Pixel object to destroy
72
39
  */
73
- void
74
- destroy_Pixel(Pixel *pixel)
40
+ static void
41
+ Pixel_destroy(void *ptr)
75
42
  {
43
+ Pixel *pixel = (Pixel *)ptr;
76
44
  xfree(pixel);
77
45
  }
78
46
 
79
47
 
80
48
  /**
81
- * Get Pixel red attribute.
49
+ * Get Pixel object size.
50
+ *
51
+ * No Ruby usage (internal function)
52
+ *
53
+ * @param ptr pointer to the Pixel object
54
+ */
55
+ static size_t
56
+ Pixel_memsize(const void *ptr)
57
+ {
58
+ return sizeof(Pixel);
59
+ }
60
+
61
+
62
+ /**
63
+ * Get Pixel red value.
82
64
  *
83
- * Ruby usage:
84
- * - @verbatim Pixel#red @endverbatim
65
+ * @return [Numeric] the red value
66
+ */
67
+ VALUE
68
+ Pixel_red(VALUE self)
69
+ {
70
+ IMPLEMENT_TYPED_ATTR_READER(Pixel, red, int, &rm_pixel_data_type);
71
+ }
72
+
73
+ /**
74
+ * Get Pixel green value.
85
75
  *
86
- * @param self this object
87
- * @return the red value
76
+ * @return [Numeric] the green value
88
77
  */
89
- DEF_ATTR_READER(Pixel, red, int)
78
+ VALUE
79
+ Pixel_green(VALUE self)
80
+ {
81
+ IMPLEMENT_TYPED_ATTR_READER(Pixel, green, int, &rm_pixel_data_type);
82
+ }
90
83
 
91
84
  /**
92
- * Get Pixel green attribute.
85
+ * Get Pixel blue value.
93
86
  *
94
- * Ruby usage:
95
- * - @verbatim Pixel#green @endverbatim
87
+ * @return [Numeric] the blue value
88
+ */
89
+ VALUE
90
+ Pixel_blue(VALUE self)
91
+ {
92
+ IMPLEMENT_TYPED_ATTR_READER(Pixel, blue, int, &rm_pixel_data_type);
93
+ }
94
+
95
+ /**
96
+ * Get Pixel alpha value.
96
97
  *
97
- * @param self this object
98
- * @return the green value
98
+ * @return [Numeric] the alpha value
99
99
  */
100
- DEF_ATTR_READER(Pixel, green, int)
100
+ VALUE
101
+ Pixel_alpha(VALUE self)
102
+ {
103
+ Pixel *pixel;
104
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
105
+ #if defined(IMAGEMAGICK_7)
106
+ return C_int_to_R_int(pixel->alpha);
107
+ #else
108
+ return C_int_to_R_int(QuantumRange - pixel->opacity);
109
+ #endif
110
+ }
101
111
 
102
112
  /**
103
- * Get Pixel blue attribute.
113
+ * Set Pixel red value.
104
114
  *
105
- * Ruby usage:
106
- * - @verbatim Pixel#blue @endverbatim
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.
107
119
  *
108
- * @param self this object
109
- * @return the blue value
120
+ * @param v [Numeric] the red value
121
+ * @return [Numeric] the given red value
110
122
  */
111
- DEF_ATTR_READER(Pixel, blue, int)
123
+ VALUE
124
+ Pixel_red_eq(VALUE self, VALUE v)
125
+ {
126
+ Pixel *pixel;
127
+
128
+ rb_check_frozen(self);
129
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
130
+ pixel->red = APP2QUANTUM(v);
131
+ rb_funcall(self, rm_ID_changed, 0);
132
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
133
+ return QUANTUM2NUM((pixel->red));
134
+ }
112
135
 
113
136
  /**
114
- * Get Pixel alpha attribute.
137
+ * Set Pixel green value.
115
138
  *
116
- * Ruby usage:
117
- * - @verbatim Pixel#alpha @endverbatim
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.
118
143
  *
119
- * @param self this object
120
- * @return the alpha value
144
+ * @param v [Numeric] the green value
145
+ * @return [Numeric] the given green value
121
146
  */
122
147
  VALUE
123
- Pixel_alpha(VALUE self)
148
+ Pixel_green_eq(VALUE self, VALUE v)
124
149
  {
125
150
  Pixel *pixel;
126
- Data_Get_Struct(self, Pixel, pixel);
127
- return C_int_to_R_int(QuantumRange - pixel->opacity);
151
+
152
+ rb_check_frozen(self);
153
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
154
+ pixel->green = APP2QUANTUM(v);
155
+ rb_funcall(self, rm_ID_changed, 0);
156
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
157
+ return QUANTUM2NUM((pixel->green));
128
158
  }
129
159
 
130
160
  /**
131
- * Set Pixel red attribute.
161
+ * Set Pixel blue value.
132
162
  *
133
- * Ruby usage:
134
- * - @verbatim Pixel#red= @endverbatim
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.
135
167
  *
136
- * Notes:
137
- * - Pixel is Observable. Setters call changed, notify_observers
138
- * - Setters return their argument values for backward compatibility to when
139
- * Pixel was a Struct class.
168
+ * @param v [Numeric] the blue value
169
+ * @return [Numeric] the given blue value
170
+ */
171
+ VALUE
172
+ Pixel_blue_eq(VALUE self, VALUE v)
173
+ {
174
+ Pixel *pixel;
175
+
176
+ rb_check_frozen(self);
177
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
178
+ pixel->blue = APP2QUANTUM(v);
179
+ rb_funcall(self, rm_ID_changed, 0);
180
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
181
+ return QUANTUM2NUM((pixel->blue));
182
+ }
183
+
184
+ /**
185
+ * Set Pixel alpha value.
140
186
  *
141
- * @param self this object
142
- * @param v the red value
143
- * @return self
187
+ * - Pixel is Observable. Setters call {Magick::Pixel#changed},
188
+ * {Magick::Pixel#notify_observers}
189
+ * - Setters return their argument values for backward compatibility to when
190
+ * Pixel was a Struct class.
191
+ *
192
+ * @param v [Numeric] the alpha value
193
+ * @return [Numeric] the given alpha value
144
194
  */
145
- DEF_PIXEL_CHANNEL_WRITER(red)
195
+ VALUE
196
+ Pixel_alpha_eq(VALUE self, VALUE v)
197
+ {
198
+ Pixel *pixel;
199
+
200
+ rb_check_frozen(self);
201
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
202
+ #if defined(IMAGEMAGICK_7)
203
+ pixel->alpha = APP2QUANTUM(v);
204
+ rb_funcall(self, rm_ID_changed, 0);
205
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
206
+ return QUANTUM2NUM(pixel->alpha);
207
+ #else
208
+ pixel->opacity = QuantumRange - APP2QUANTUM(v);
209
+ rb_funcall(self, rm_ID_changed, 0);
210
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
211
+ return QUANTUM2NUM(QuantumRange - pixel->opacity);
212
+ #endif
213
+ }
146
214
 
147
215
  /**
148
- * Set Pixel green attribute.
216
+ * Get Pixel cyan value.
149
217
  *
150
- * Ruby usage:
151
- * - @verbatim Pixel#green= @endverbatim
218
+ * @return [Numeric] the cyan value
219
+ */
220
+ VALUE
221
+ Pixel_cyan(VALUE self)
222
+ {
223
+ Pixel *pixel;
224
+
225
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
226
+ return INT2NUM(pixel->red);
227
+ }
228
+
229
+ /**
230
+ * Set Pixel cyan value.
152
231
  *
153
- * Notes:
154
- * - Pixel is Observable. Setters call changed, notify_observers
155
- * - Setters return their argument values for backward compatibility to when
156
- * Pixel was a Struct class.
232
+ * - Pixel is Observable. Setters call {Magick::Pixel#changed},
233
+ * {Magick::Pixel#notify_observers}
234
+ * - Setters return their argument values for backward compatibility to when
235
+ * Pixel was a Struct class.
157
236
  *
158
- * @param self this object
159
- * @param v the green value
160
- * @return self
237
+ * @param v [Numeric] the cyan value
238
+ * @return [Numeric] the given cyan value
161
239
  */
162
- DEF_PIXEL_CHANNEL_WRITER(green)
240
+ VALUE
241
+ Pixel_cyan_eq(VALUE self, VALUE v)
242
+ {
243
+ Pixel *pixel;
244
+
245
+ rb_check_frozen(self);
246
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
247
+ pixel->red = APP2QUANTUM(v);
248
+ rb_funcall(self, rm_ID_changed, 0);
249
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
250
+ return QUANTUM2NUM(pixel->red);
251
+ }
163
252
 
164
253
  /**
165
- * Set Pixel blue attribute.
254
+ * Get Pixel magenta value.
166
255
  *
167
- * Ruby usage:
168
- * - @verbatim Pixel#blue= @endverbatim
256
+ * @return [Numeric] the magenta value
257
+ */
258
+ VALUE
259
+ Pixel_magenta(VALUE self)
260
+ {
261
+ Pixel *pixel;
262
+
263
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
264
+ return INT2NUM(pixel->green);
265
+ }
266
+
267
+ /**
268
+ * Set Pixel magenta value.
169
269
  *
170
- * Notes:
171
- * - Pixel is Observable. Setters call changed, notify_observers
172
- * - Setters return their argument values for backward compatibility to when
173
- * Pixel was a Struct class.
270
+ * - Pixel is Observable. Setters call {Magick::Pixel#changed},
271
+ * {Magick::Pixel#notify_observers}
272
+ * - Setters return their argument values for backward compatibility to when
273
+ * Pixel was a Struct class.
174
274
  *
175
- * @param self this object
176
- * @param v the blue value
177
- * @return self
275
+ * @param v [Numeric] the magenta value
276
+ * @return [Numeric] the given magenta value
178
277
  */
179
- DEF_PIXEL_CHANNEL_WRITER(blue)
278
+ VALUE
279
+ Pixel_magenta_eq(VALUE self, VALUE v)
280
+ {
281
+ Pixel *pixel;
282
+
283
+ rb_check_frozen(self);
284
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
285
+ pixel->green = APP2QUANTUM(v);
286
+ rb_funcall(self, rm_ID_changed, 0);
287
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
288
+ return QUANTUM2NUM(pixel->green);
289
+ }
180
290
 
181
291
  /**
182
- * Set Pixel alpha attribute.
292
+ * Get Pixel yellow value.
183
293
  *
184
- * Ruby usage:
185
- * - @verbatim Pixel#alpha= @endverbatim
294
+ * @return [Numeric] the yellow value
295
+ */
296
+ VALUE
297
+ Pixel_yellow(VALUE self)
298
+ {
299
+ Pixel *pixel;
300
+
301
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
302
+ return INT2NUM(pixel->blue);
303
+ }
304
+
305
+ /**
306
+ * Set Pixel yellow value.
186
307
  *
187
- * Notes:
188
- * - Pixel is Observable. Setters call changed, notify_observers
189
- * - Setters return their argument values for backward compatibility to when
190
- * Pixel was a Struct class.
308
+ * - Pixel is Observable. Setters call {Magick::Pixel#changed},
309
+ * {Magick::Pixel#notify_observers}
310
+ * - Setters return their argument values for backward compatibility to when
311
+ * Pixel was a Struct class.
191
312
  *
192
- * @param self this object
193
- * @param v the alpha value
194
- * @return self
313
+ * @param v [Numeric] the yellow value
314
+ * @return [Numeric] the given yellow value
195
315
  */
196
316
  VALUE
197
- Pixel_alpha_eq(VALUE self, VALUE v)
317
+ Pixel_yellow_eq(VALUE self, VALUE v)
198
318
  {
199
319
  Pixel *pixel;
200
-
320
+
201
321
  rb_check_frozen(self);
202
- Data_Get_Struct(self, Pixel, pixel);
203
- pixel->opacity = QuantumRange - APP2QUANTUM(v);
204
- (void) rb_funcall(self, rm_ID_changed, 0);
205
- (void) rb_funcall(self, rm_ID_notify_observers, 1, self);
206
- return QUANTUM2NUM(QuantumRange - pixel->opacity);
322
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
323
+ pixel->blue = APP2QUANTUM(v);
324
+ rb_funcall(self, rm_ID_changed, 0);
325
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
326
+ return QUANTUM2NUM(pixel->blue);
207
327
  }
208
328
 
209
- /*
210
- * Get/set Pixel CMYK attributes.
329
+ /**
330
+ * Get Pixel black value.
331
+ *
332
+ * @return [Numeric] the black value
211
333
  */
212
- DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(cyan, red)
213
- DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(magenta, green)
214
- DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(yellow, blue)
215
- DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(black, opacity)
334
+ VALUE
335
+ Pixel_black(VALUE self)
336
+ {
337
+ Pixel *pixel;
338
+
339
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
340
+ return INT2NUM(pixel->black);
341
+ }
342
+
343
+ /**
344
+ * Set Pixel black value.
345
+ *
346
+ * - Pixel is Observable. Setters call {Magick::Pixel#changed},
347
+ * {Magick::Pixel#notify_observers}
348
+ * - Setters return their argument values for backward compatibility to when
349
+ * Pixel was a Struct class.
350
+ *
351
+ * @param v [Numeric] the black value
352
+ * @return [Numeric] the given black value
353
+ */
354
+ VALUE
355
+ Pixel_black_eq(VALUE self, VALUE v)
356
+ {
357
+ Pixel *pixel;
358
+
359
+ rb_check_frozen(self);
360
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
361
+ pixel->black = APP2QUANTUM(v);
362
+ rb_funcall(self, rm_ID_changed, 0);
363
+ rb_funcall(self, rm_ID_notify_observers, 1, self);
364
+ return QUANTUM2NUM(pixel->black);
365
+ }
216
366
 
217
367
 
218
368
  /**
@@ -226,11 +376,10 @@ DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(black, opacity)
226
376
  * @throw ArgumentError
227
377
  */
228
378
  static VALUE
229
- color_arg_rescue(VALUE arg)
379
+ color_arg_rescue(VALUE arg, VALUE raised_exc ATTRIBUTE_UNUSED)
230
380
  {
231
381
  rb_raise(rb_eTypeError, "argument must be color name or pixel (%s given)",
232
382
  rb_class2name(CLASS_OF(arg)));
233
- return (VALUE)0;
234
383
  }
235
384
 
236
385
 
@@ -251,11 +400,16 @@ Color_to_PixelColor(PixelColor *pp, VALUE color)
251
400
  if (CLASS_OF(color) == Class_Pixel)
252
401
  {
253
402
  memset(pp, 0, sizeof(*pp));
254
- Data_Get_Struct(color, Pixel, pixel);
403
+ TypedData_Get_Struct(color, Pixel, &rm_pixel_data_type, pixel);
255
404
  pp->red = pixel->red;
256
405
  pp->green = pixel->green;
257
406
  pp->blue = pixel->blue;
407
+ #if defined(IMAGEMAGICK_7)
408
+ pp->black = pixel->black;
409
+ rm_set_pixelinfo_alpha(pp, pixel->alpha);
410
+ #else
258
411
  pp->opacity = pixel->opacity;
412
+ #endif
259
413
  }
260
414
  else
261
415
  {
@@ -266,6 +420,44 @@ Color_to_PixelColor(PixelColor *pp, VALUE color)
266
420
  }
267
421
 
268
422
 
423
+ /**
424
+ * Convert either a String color name or a {Magick::Pixel} to a Pixel.
425
+ *
426
+ * No Ruby usage (internal function)
427
+ *
428
+ * @param pp the Pixel to modify
429
+ * @param color the color name or Magick::Pixel
430
+ */
431
+ void
432
+ Color_to_Pixel(Pixel *pp, VALUE color)
433
+ {
434
+ PixelColor pixel_color;
435
+
436
+ memset(pp, 0, sizeof(*pp));
437
+ // Allow color name or Pixel
438
+ if (CLASS_OF(color) == Class_Pixel)
439
+ {
440
+ Pixel *pixel;
441
+
442
+ TypedData_Get_Struct(color, Pixel, &rm_pixel_data_type, pixel);
443
+ memcpy(pp, pixel, sizeof(Pixel));
444
+ }
445
+ else
446
+ {
447
+ Color_to_PixelColor(&pixel_color, color);
448
+ pp->red = pixel_color.red;
449
+ pp->green = pixel_color.green;
450
+ pp->blue = pixel_color.blue;
451
+ #if defined(IMAGEMAGICK_7)
452
+ pp->alpha = pixel_color.alpha;
453
+ pp->black = pixel_color.black;
454
+ #else
455
+ pp->opacity = pixel_color.opacity;
456
+ #endif
457
+ }
458
+ }
459
+
460
+
269
461
  /**
270
462
  * Convert a color name to a PixelColor
271
463
  *
@@ -283,9 +475,9 @@ Color_Name_to_PixelColor(PixelColor *color, VALUE name_arg)
283
475
  ExceptionInfo *exception;
284
476
 
285
477
  exception = AcquireExceptionInfo();
286
- name = StringValuePtr(name_arg);
478
+ name = StringValueCStr(name_arg);
287
479
  okay = QueryColorCompliance(name, AllCompliance, color, exception);
288
- (void) DestroyExceptionInfo(exception);
480
+ DestroyExceptionInfo(exception);
289
481
  if (!okay)
290
482
  {
291
483
  rb_raise(rb_eArgError, "invalid color name %s", name);
@@ -297,10 +489,7 @@ Color_Name_to_PixelColor(PixelColor *color, VALUE name_arg)
297
489
  /**
298
490
  * Allocate a Pixel object.
299
491
  *
300
- * No Ruby usage (internal function)
301
- *
302
- * @param class the Ruby class to use
303
- * @return a new Magick::Pixel object
492
+ * @return [Magick::Pixel] a new Magick::Pixel object
304
493
  */
305
494
  VALUE
306
495
  Pixel_alloc(VALUE class)
@@ -309,34 +498,34 @@ Pixel_alloc(VALUE class)
309
498
 
310
499
  pixel = ALLOC(Pixel);
311
500
  memset(pixel, '\0', sizeof(Pixel));
312
- return Data_Wrap_Struct(class, NULL, destroy_Pixel, pixel);
501
+ return TypedData_Wrap_Struct(class, &rm_pixel_data_type, pixel);
313
502
  }
314
503
 
315
504
 
316
505
  /**
317
506
  * "Case equal" operator for Pixel.
318
507
  *
319
- * Ruby usage:
320
- * - @verbatim Pixel#=== @endverbatim
321
- *
322
- * @param self this object
323
- * @param other the other object
324
- * @return true or false
508
+ * @param other [Object] the other object
509
+ * @return [Boolean] true or false
325
510
  */
326
511
 
327
512
  VALUE
328
513
  Pixel_case_eq(VALUE self, VALUE other)
329
514
  {
330
- Pixel *this, *that;
331
-
332
515
  if (CLASS_OF(self) == CLASS_OF(other))
333
516
  {
334
- Data_Get_Struct(self, Pixel, this);
335
- Data_Get_Struct(other, Pixel, that);
517
+ Pixel *this, *that;
518
+
519
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, this);
520
+ TypedData_Get_Struct(other, Pixel, &rm_pixel_data_type, that);
336
521
  return (this->red == that->red
337
522
  && this->blue == that->blue
338
523
  && this->green == that->green
524
+ #if defined(IMAGEMAGICK_7)
525
+ && this->alpha == that->alpha) ? Qtrue : Qfalse;
526
+ #else
339
527
  && this->opacity == that->opacity) ? Qtrue : Qfalse;
528
+ #endif
340
529
  }
341
530
 
342
531
  return Qfalse;
@@ -346,13 +535,9 @@ Pixel_case_eq(VALUE self, VALUE other)
346
535
  /**
347
536
  * Clone a Pixel.
348
537
  *
349
- * Ruby usage:
350
- * - @verbatim Pixel#clone @endverbatim
351
- *
352
- * @param self this object
353
- * @return a clone
354
- * @see Pixel_dup
355
- * @see Pixel_init_copy
538
+ * @return [Magick::Pixel] a clone object
539
+ * @see #dup
540
+ * @see #initialize_copy
356
541
  */
357
542
  VALUE
358
543
  Pixel_clone(VALUE self)
@@ -374,13 +559,9 @@ Pixel_clone(VALUE self)
374
559
  /**
375
560
  * Duplicate a Pixel.
376
561
  *
377
- * Ruby usage:
378
- * - @verbatim Pixel#dup @endverbatim
379
- *
380
- * @param self this object
381
- * @return a clone
382
- * @see Pixel_clone
383
- * @see Pixel_init_copy
562
+ * @return [Magick::Pixel] a duplicated object
563
+ * @see #clone
564
+ * @see #initialize_copy
384
565
  */
385
566
  VALUE
386
567
  Pixel_dup(VALUE self)
@@ -390,12 +571,7 @@ Pixel_dup(VALUE self)
390
571
 
391
572
  pixel = ALLOC(Pixel);
392
573
  memset(pixel, '\0', sizeof(Pixel));
393
- dup = Data_Wrap_Struct(CLASS_OF(self), NULL, destroy_Pixel, pixel);
394
- if (rb_obj_tainted(self))
395
- {
396
- (void) rb_obj_taint(dup);
397
- }
398
-
574
+ dup = TypedData_Wrap_Struct(CLASS_OF(self), &rm_pixel_data_type, pixel);
399
575
  RB_GC_GUARD(dup);
400
576
 
401
577
  return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
@@ -403,14 +579,10 @@ Pixel_dup(VALUE self)
403
579
 
404
580
 
405
581
  /**
406
- * For use with Hash.
582
+ * Equality. Returns true only if receiver and other are the same object.
407
583
  *
408
- * Ruby usage:
409
- * - @verbatim Pixel#eql? @endverbatim
410
- *
411
- * @param self this object
412
- * @param other the other object
413
- * @return true if hash to the same value, otherwise false
584
+ * @param other [Object] the other object
585
+ * @return [Boolean] true if other is the same value, otherwise false
414
586
  */
415
587
  VALUE
416
588
  Pixel_eql_q(VALUE self, VALUE other)
@@ -422,17 +594,11 @@ Pixel_eql_q(VALUE self, VALUE other)
422
594
  /**
423
595
  * Compare pixel values for equality.
424
596
  *
425
- * Ruby usage:
426
- * - @verbatim Pixel#fcmp(other, fuzz, colorspace) @endverbatim
427
- *
428
- * Notes:
429
- * - Default fuzz is 0.0
430
- * - Default colorspace is RGBColorspace
431
- *
432
- * @param argc number of input arguments
433
- * @param argv array of input arguments
434
- * @param self this object
435
- * @return true if equal, otherwise false
597
+ * @overload fcmp(other, fuzz = 0.0, colorspace = Magick::RGBColorspace)
598
+ * @param other [Magick::Pixel] The pixel to which the receiver is compared
599
+ * @param fuzz [Float] The amount of fuzz to allow before the colors are considered to be different
600
+ * @param colorspace [Magick::ColorspaceType] The colorspace
601
+ * @return [Boolean] true if equal, otherwise false
436
602
  */
437
603
  VALUE
438
604
  Pixel_fcmp(int argc, VALUE *argv, VALUE self)
@@ -440,9 +606,11 @@ Pixel_fcmp(int argc, VALUE *argv, VALUE self)
440
606
  double fuzz = 0.0;
441
607
  unsigned int equal;
442
608
  ColorspaceType colorspace = RGBColorspace;
609
+ PixelColor this, that;
610
+ #if defined(IMAGEMAGICK_6)
443
611
  Image *image;
444
612
  Info *info;
445
- Pixel *this, *that;
613
+ #endif
446
614
 
447
615
  switch (argc)
448
616
  {
@@ -458,9 +626,16 @@ Pixel_fcmp(int argc, VALUE *argv, VALUE self)
458
626
  break;
459
627
  }
460
628
 
461
- Data_Get_Struct(self, Pixel, this);
462
- Data_Get_Struct(argv[0], Pixel, that);
629
+ Color_to_PixelColor(&this, self);
630
+ Color_to_PixelColor(&that, argv[0]);
463
631
 
632
+ #if defined(IMAGEMAGICK_7)
633
+ this.fuzz = fuzz;
634
+ this.colorspace = colorspace;
635
+ that.fuzz = fuzz;
636
+ that.colorspace = colorspace;
637
+ equal = IsFuzzyEquivalencePixelInfo(&this, &that);
638
+ #else
464
639
  // The IsColorSimilar function expects to get the
465
640
  // colorspace and fuzz parameters from an Image structure.
466
641
 
@@ -473,7 +648,7 @@ Pixel_fcmp(int argc, VALUE *argv, VALUE self)
473
648
  image = rm_acquire_image(info);
474
649
 
475
650
  // Delete Info now in case we have to raise an exception
476
- (void) DestroyImageInfo(info);
651
+ DestroyImageInfo(info);
477
652
 
478
653
  if (!image)
479
654
  {
@@ -483,29 +658,25 @@ Pixel_fcmp(int argc, VALUE *argv, VALUE self)
483
658
  image->colorspace = colorspace;
484
659
  image->fuzz = fuzz;
485
660
 
486
- equal = IsColorSimilar(image, this, that);
487
- (void) DestroyImage(image);
661
+ equal = IsColorSimilar(image, &this, &that);
662
+ DestroyImage(image);
663
+ #endif
488
664
 
489
665
  return equal ? Qtrue : Qfalse;
490
666
  }
491
667
 
492
668
 
493
669
  /**
494
- * Construct an Magick::Pixel corresponding to the given color name.
670
+ * Construct an {Magick::Pixel} corresponding to the given color name.
495
671
  *
496
- * Ruby usage:
497
- * - @verbatim Magick::Pixel.from_color(string) @endverbatim
672
+ * - The "inverse" is {Image#to_color}, b/c the conversion of a pixel to a
673
+ * color name requires both a color depth and if the opacity value has
674
+ * meaning.
498
675
  *
499
- * Notes:
500
- * - The "inverse" is Image_to_color, b/c the conversion of a pixel to a
501
- * color name requires both a color depth and if the opacity value has
502
- * meaning (i.e. whether image->matte == True or not).
503
- *
504
- * @param class the Ruby class to use
505
- * @param name the color name
506
- * @return a new Magic::Pixel object
507
- * @see Image_to_color
508
- * @see Pixel_to_color
676
+ * @param name [String] the color name
677
+ * @return [Magick::Pixel] a new Magic::Pixel object
678
+ * @see Magick::Image#to_color
679
+ * @see Magick::Pixel#to_color
509
680
  */
510
681
  VALUE
511
682
  Pixel_from_color(VALUE class ATTRIBUTE_UNUSED, VALUE name)
@@ -515,13 +686,13 @@ Pixel_from_color(VALUE class ATTRIBUTE_UNUSED, VALUE name)
515
686
  MagickBooleanType okay;
516
687
 
517
688
  exception = AcquireExceptionInfo();
518
- okay = QueryColorCompliance(StringValuePtr(name), AllCompliance, &pp, exception);
519
- CHECK_EXCEPTION()
520
- (void) DestroyExceptionInfo(exception);
689
+ okay = QueryColorCompliance(StringValueCStr(name), AllCompliance, &pp, exception);
690
+ CHECK_EXCEPTION();
691
+ DestroyExceptionInfo(exception);
521
692
 
522
693
  if (!okay)
523
694
  {
524
- rb_raise(rb_eArgError, "invalid color name: %s", StringValuePtr(name));
695
+ rb_raise(rb_eArgError, "invalid color name: %s", StringValueCStr(name));
525
696
  }
526
697
 
527
698
  return Pixel_from_PixelColor(&pp);
@@ -531,21 +702,17 @@ Pixel_from_color(VALUE class ATTRIBUTE_UNUSED, VALUE name)
531
702
  /**
532
703
  * Construct an RGB pixel.
533
704
  *
534
- * Ruby usage:
535
- * - @verbatim Pixel#from_hsla(hue, saturation, lightness) @endverbatim
536
- * - @verbatim Pixel#from_hsla(hue, saturation, lightness, alpha) @endverbatim
537
- *
538
- * Notes:
539
- * - Default alpha is 1.0
540
- * - 0 <= hue < 360 OR "0%" <= hue < "100%"
541
- * - 0 <= saturation <= 255 OR "0%" <= saturation <= "100%"
542
- * - 0 <= lightness <= 255 OR "0%" <= lightness <= "100%"
543
- * - 0 <= alpha <= 1 (0 is transparent, 1 is opaque) OR "0%" <= alpha <= "100%"
544
- *
545
- * @param argc number of input arguments
546
- * @param argv array of input arguments
547
- * @param class the Ruby class to use
548
- * @return a new Magick::Pixel object
705
+ * - 0 <= +hue+ < 360 OR "0%" <= +hue+ < "100%"
706
+ * - 0 <= +saturation+ <= 255 OR "0%" <= +saturation+ <= "100%"
707
+ * - 0 <= +lightness+ <= 255 OR "0%" <= +lightness+ <= "100%"
708
+ * - 0 <= +alpha+ <= 1 (0 is transparent, 1 is opaque) OR "0%" <= +alpha+ <= "100%"
709
+ *
710
+ * @overload from_hsla(hue, saturation, lightness, alpha = 1.0)
711
+ * @param hue [Numeric, String] A value in the range.
712
+ * @param saturation [Numeric, String] A value in the range.
713
+ * @param lightness [Numeric, String] A value in the range.
714
+ * @param alpha [Numeric] The alpha value.
715
+ * @return [Magick::Pixel] a new Magick::Pixel object
549
716
  */
550
717
  VALUE
551
718
  Pixel_from_hsla(int argc, VALUE *argv, VALUE class ATTRIBUTE_UNUSED)
@@ -559,14 +726,14 @@ Pixel_from_hsla(int argc, VALUE *argv, VALUE class ATTRIBUTE_UNUSED)
559
726
  switch (argc)
560
727
  {
561
728
  case 4:
562
- a = rm_percentage(argv[3],1.0);
729
+ a = rm_percentage(argv[3], 1.0);
563
730
  alpha = MagickTrue;
564
731
  case 3:
565
732
  // saturation and lightness are out of 255 in new ImageMagicks and
566
733
  // out of 100 in old ImageMagicks. Compromise: always use %.
567
- l = rm_percentage(argv[2],255.0);
568
- s = rm_percentage(argv[1],255.0);
569
- h = rm_percentage(argv[0],360.0);
734
+ l = rm_percentage(argv[2], 255.0);
735
+ s = rm_percentage(argv[1], 255.0);
736
+ h = rm_percentage(argv[0], 360.0);
570
737
  break;
571
738
  default:
572
739
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
@@ -593,19 +760,23 @@ Pixel_from_hsla(int argc, VALUE *argv, VALUE class ATTRIBUTE_UNUSED)
593
760
  memset(name, 0, sizeof(name));
594
761
  if (alpha)
595
762
  {
596
- sprintf(name, "hsla(%-2.1f,%-2.1f,%-2.1f,%-2.1f)", h, s, l, a);
763
+ snprintf(name, sizeof(name), "hsla(%-2.1f,%-2.1f,%-2.1f,%-2.1f)", h, s, l, a);
597
764
  }
598
765
  else
599
766
  {
600
- sprintf(name, "hsl(%-2.1f,%-2.1f,%-2.1f)", h, s, l);
767
+ snprintf(name, sizeof(name), "hsl(%-2.1f,%-2.1f,%-2.1f)", h, s, l);
601
768
  }
602
769
 
603
770
  exception = AcquireExceptionInfo();
604
771
 
605
- (void) QueryMagickColor(name, &pp, exception);
606
- CHECK_EXCEPTION()
772
+ #if defined(IMAGEMAGICK_7)
773
+ QueryColorCompliance(name, AllCompliance, &pp, exception);
774
+ #else
775
+ QueryMagickColor(name, &pp, exception);
776
+ #endif
777
+ CHECK_EXCEPTION();
607
778
 
608
- (void) DestroyExceptionInfo(exception);
779
+ DestroyExceptionInfo(exception);
609
780
 
610
781
  return Pixel_from_MagickPixel(&pp);
611
782
  }
@@ -628,12 +799,17 @@ Pixel_from_MagickPixel(const MagickPixel *pp)
628
799
  Pixel *pixel;
629
800
 
630
801
  pixel = ALLOC(Pixel);
631
- pixel->red = ROUND_TO_QUANTUM(pp->red);
632
- pixel->green = ROUND_TO_QUANTUM(pp->green);
633
- pixel->blue = ROUND_TO_QUANTUM(pp->blue);
634
- pixel->opacity = ROUND_TO_QUANTUM(pp->opacity);
802
+ pixel->red = pp->red;
803
+ pixel->green = pp->green;
804
+ pixel->blue = pp->blue;
805
+ #if defined(IMAGEMAGICK_7)
806
+ pixel->alpha = pp->alpha;
807
+ #else
808
+ pixel->opacity = pp->opacity;
809
+ #endif
810
+ pixel->black = pp->index;
635
811
 
636
- return Data_Wrap_Struct(Class_Pixel, NULL, destroy_Pixel, pixel);
812
+ return TypedData_Wrap_Struct(Class_Pixel, &rm_pixel_data_type, pixel);
637
813
  }
638
814
 
639
815
 
@@ -657,9 +833,15 @@ Pixel_from_PixelPacket(const PixelPacket *pp)
657
833
  pixel->red = pp->red;
658
834
  pixel->green = pp->green;
659
835
  pixel->blue = pp->blue;
836
+ #if defined(IMAGEMAGICK_7)
837
+ pixel->alpha = pp->alpha;
838
+ pixel->black = pp->black;
839
+ #else
660
840
  pixel->opacity = pp->opacity;
841
+ pixel->black = 0;
842
+ #endif
661
843
 
662
- return Data_Wrap_Struct(Class_Pixel, NULL, destroy_Pixel, pixel);
844
+ return TypedData_Wrap_Struct(Class_Pixel, &rm_pixel_data_type, pixel);
663
845
  }
664
846
 
665
847
 
@@ -683,22 +865,22 @@ Pixel_from_PixelColor(const PixelColor *pp)
683
865
  pixel->red = pp->red;
684
866
  pixel->green = pp->green;
685
867
  pixel->blue = pp->blue;
868
+ #if defined(IMAGEMAGICK_7)
869
+ pixel->alpha = pp->alpha;
870
+ pixel->black = pp->black;
871
+ #else
686
872
  pixel->opacity = pp->opacity;
873
+ pixel->black = 0;
874
+ #endif
687
875
 
688
- return Data_Wrap_Struct(Class_Pixel, NULL, destroy_Pixel, pixel);
876
+ return TypedData_Wrap_Struct(Class_Pixel, &rm_pixel_data_type, pixel);
689
877
  }
690
878
 
691
879
 
692
880
  /**
693
- * Ruby usage:
694
- * - @verbatim Pixel#hash @endverbatim
695
- *
696
- * Notes:
697
- * - INT2FIX left-shifts 1 bit. Sacrifice 1 bit from the opacity attribute to
698
- * the FIXNUM_FLAG.
881
+ * Compute a hash-code.
699
882
  *
700
- * @param self this object
701
- * @return the hash of self
883
+ * @return [Numeric] the hash of self
702
884
  */
703
885
  VALUE
704
886
  Pixel_hash(VALUE self)
@@ -706,12 +888,16 @@ Pixel_hash(VALUE self)
706
888
  Pixel *pixel;
707
889
  unsigned int hash;
708
890
 
709
- Data_Get_Struct(self, Pixel, pixel);
891
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
710
892
 
711
893
  hash = ScaleQuantumToChar(pixel->red) << 24;
712
894
  hash += ScaleQuantumToChar(pixel->green) << 16;
713
895
  hash += ScaleQuantumToChar(pixel->blue) << 8;
896
+ #if defined(IMAGEMAGICK_7)
897
+ hash += ScaleQuantumToChar(pixel->alpha);
898
+ #else
714
899
  hash += ScaleQuantumToChar(QuantumRange - pixel->opacity);
900
+ #endif
715
901
 
716
902
  return UINT2NUM(hash >> 1);
717
903
  }
@@ -720,22 +906,18 @@ Pixel_hash(VALUE self)
720
906
  /**
721
907
  * Initialize clone, dup methods.
722
908
  *
723
- * Ruby usage:
724
- * - @verbatim Pixel#initialize_copy @endverbatim
725
- *
726
- * @param self this object
727
- * @param orig the original Pixel
728
- * @return self
729
- * @see Pixel_clone
730
- * @see Pixel_dup
909
+ * @param orig [Magick::Pixel] the original Pixel
910
+ * @return [Magick::Pixel] self
911
+ * @see #clone
912
+ * @see #dup
731
913
  */
732
914
  VALUE
733
915
  Pixel_init_copy(VALUE self, VALUE orig)
734
916
  {
735
917
  Pixel *copy, *original;
736
918
 
737
- Data_Get_Struct(orig, Pixel, original);
738
- Data_Get_Struct(self, Pixel, copy);
919
+ TypedData_Get_Struct(orig, Pixel, &rm_pixel_data_type, original);
920
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, copy);
739
921
 
740
922
  *copy = *original;
741
923
 
@@ -744,39 +926,40 @@ Pixel_init_copy(VALUE self, VALUE orig)
744
926
 
745
927
 
746
928
  /**
747
- * Ruby usage:
748
- * - @verbatim Pixel#initialize @endverbatim
749
- * - @verbatim Pixel#initialize(red) @endverbatim
750
- * - @verbatim Pixel#initialize(red,green) @endverbatim
751
- * - @verbatim Pixel#initialize(red,green,blue) @endverbatim
752
- * - @verbatim Pixel#initialize(red,green,blue,opacity) @endverbatim
753
- *
754
- * Notes:
755
- * - Default red is 0.0
756
- * - Default green is 0.0
757
- * - Default blue is 0.0
758
- * - Default opacity is 0.0
759
- * - For backward compatibility, arguments may be nil.
760
- *
761
- * @param argc number of input arguments
762
- * @param argv array of input arguments
763
- * @param self this object
764
- * @return self
929
+ * Initialize Pixel object.
930
+ *
931
+ * @overload initialize(red = 0, green = 0, blue = 0, opacity = 0)
932
+ * @param red [Numeric] The red value
933
+ * @param green [Numeric] The green value
934
+ * @param blue [Numeric] The blue value
935
+ * @param opacity [Numeric] The opacity value
936
+ * @return [Magick::Pixel] self
765
937
  */
766
938
  VALUE
767
939
  Pixel_initialize(int argc, VALUE *argv, VALUE self)
768
940
  {
769
941
  Pixel *pixel;
770
942
 
771
- Data_Get_Struct(self, Pixel, pixel);
943
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
944
+
945
+ #if defined(IMAGEMAGICK_7)
946
+ pixel->alpha = OpaqueAlpha;
947
+ #endif
772
948
 
773
949
  switch(argc)
774
950
  {
775
951
  case 4:
952
+ #if defined(IMAGEMAGICK_7)
953
+ if (argv[3] != Qnil)
954
+ {
955
+ pixel->alpha = APP2QUANTUM(argv[3]);
956
+ }
957
+ #else
776
958
  if (argv[3] != Qnil)
777
959
  {
778
960
  pixel->opacity = APP2QUANTUM(argv[3]);
779
961
  }
962
+ #endif
780
963
  case 3:
781
964
  if (argv[2] != Qnil)
782
965
  {
@@ -805,11 +988,7 @@ Pixel_initialize(int argc, VALUE *argv, VALUE self)
805
988
  /**
806
989
  * Return the "intensity" of a pixel.
807
990
  *
808
- * Ruby usage:
809
- * - @verbatim Pixel#intensity @endverbatim
810
- *
811
- * @param self this object
812
- * @return the intensity
991
+ * @return [Numeric] the intensity
813
992
  */
814
993
  VALUE
815
994
  Pixel_intensity(VALUE self)
@@ -817,7 +996,7 @@ Pixel_intensity(VALUE self)
817
996
  Pixel *pixel;
818
997
  Quantum intensity;
819
998
 
820
- Data_Get_Struct(self, Pixel, pixel);
999
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
821
1000
 
822
1001
  intensity = ROUND_TO_QUANTUM((0.299*pixel->red)
823
1002
  + (0.587*pixel->green)
@@ -830,11 +1009,7 @@ Pixel_intensity(VALUE self)
830
1009
  /**
831
1010
  * Support Marshal.dump.
832
1011
  *
833
- * Ruby usage:
834
- * - @verbatim Pixel#marshal_dump @endverbatim
835
- *
836
- * @param self this object
837
- * @return a string representing the dumped pixel
1012
+ * @return [Hash] a representing the dumped pixel
838
1013
  */
839
1014
  VALUE
840
1015
  Pixel_marshal_dump(VALUE self)
@@ -842,12 +1017,16 @@ Pixel_marshal_dump(VALUE self)
842
1017
  Pixel *pixel;
843
1018
  VALUE dpixel;
844
1019
 
845
- Data_Get_Struct(self, Pixel, pixel);
1020
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
846
1021
  dpixel = rb_hash_new();
847
1022
  rb_hash_aset(dpixel, CSTR2SYM("red"), QUANTUM2NUM(pixel->red));
848
1023
  rb_hash_aset(dpixel, CSTR2SYM("green"), QUANTUM2NUM(pixel->green));
849
1024
  rb_hash_aset(dpixel, CSTR2SYM("blue"), QUANTUM2NUM(pixel->blue));
1025
+ #if defined(IMAGEMAGICK_7)
1026
+ rb_hash_aset(dpixel, CSTR2SYM("alpha"), QUANTUM2NUM(pixel->alpha));
1027
+ #else
850
1028
  rb_hash_aset(dpixel, CSTR2SYM("opacity"), QUANTUM2NUM(pixel->opacity));
1029
+ #endif
851
1030
 
852
1031
  RB_GC_GUARD(dpixel);
853
1032
 
@@ -858,11 +1037,7 @@ Pixel_marshal_dump(VALUE self)
858
1037
  /**
859
1038
  * Support Marshal.load.
860
1039
  *
861
- * Ruby usage:
862
- * - @verbatim Pixel#marshal_load @endverbatim
863
- *
864
- * @param self this object
865
- * @param dpixel the dumped pixel
1040
+ * @param dpixel [Hash] the dumped pixel
866
1041
  * @return self
867
1042
  */
868
1043
  VALUE
@@ -870,11 +1045,15 @@ Pixel_marshal_load(VALUE self, VALUE dpixel)
870
1045
  {
871
1046
  Pixel *pixel;
872
1047
 
873
- Data_Get_Struct(self, Pixel, pixel);
1048
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
874
1049
  pixel->red = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("red")));
875
1050
  pixel->green = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("green")));
876
1051
  pixel->blue = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("blue")));
1052
+ #if defined(IMAGEMAGICK_7)
1053
+ pixel->alpha = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("alpha")));
1054
+ #else
877
1055
  pixel->opacity = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("opacity")));
1056
+ #endif
878
1057
  return self;
879
1058
  }
880
1059
 
@@ -882,37 +1061,40 @@ Pixel_marshal_load(VALUE self, VALUE dpixel)
882
1061
  /**
883
1062
  * Support Comparable mixin.
884
1063
  *
885
- * Ruby usage:
886
- * - @verbatim Pixel#<=> @endverbatim
887
- *
888
- * @param self this object
889
- * @param other the other Pixel
890
- * @return -1, 0, 1
1064
+ * @param other [Object] the other Pixel
1065
+ * @return [-1, 0, 1, nil] the result of compare
891
1066
  */
892
1067
  VALUE
893
1068
  Pixel_spaceship(VALUE self, VALUE other)
894
1069
  {
895
1070
  Pixel *this, *that;
896
1071
 
897
- Data_Get_Struct(self, Pixel, this);
898
- Data_Get_Struct(other, Pixel, that);
1072
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, this);
1073
+ TypedData_Get_Struct(other, Pixel, &rm_pixel_data_type, that);
899
1074
 
900
1075
  if (this->red != that->red)
901
1076
  {
902
- return INT2NUM((this->red - that->red)/abs(this->red - that->red));
1077
+ return INT2NUM((this->red - that->red)/abs((int)(this->red - that->red)));
903
1078
  }
904
1079
  else if(this->green != that->green)
905
1080
  {
906
- return INT2NUM((this->green - that->green)/abs(this->green - that->green));
1081
+ return INT2NUM((this->green - that->green)/abs((int)(this->green - that->green)));
907
1082
  }
908
1083
  else if(this->blue != that->blue)
909
1084
  {
910
- return INT2NUM((this->blue - that->blue)/abs(this->blue - that->blue));
1085
+ return INT2NUM((this->blue - that->blue)/abs((int)(this->blue - that->blue)));
911
1086
  }
1087
+ #if defined(IMAGEMAGICK_7)
1088
+ else if(this->alpha != that->alpha)
1089
+ {
1090
+ return INT2NUM((this->alpha - that->alpha)/abs((int)(this->alpha - that->alpha)));
1091
+ }
1092
+ #else
912
1093
  else if(this->opacity != that->opacity)
913
1094
  {
914
- return INT2NUM(((QuantumRange - this->opacity) - (QuantumRange - that->opacity))/abs((QuantumRange - this->opacity) - (QuantumRange - that->opacity)));
1095
+ return INT2NUM(((QuantumRange - this->opacity) - (QuantumRange - that->opacity))/abs((int)((QuantumRange - this->opacity) - (QuantumRange - that->opacity))));
915
1096
  }
1097
+ #endif
916
1098
 
917
1099
  // Values are equal, check class.
918
1100
 
@@ -922,16 +1104,11 @@ Pixel_spaceship(VALUE self, VALUE other)
922
1104
 
923
1105
 
924
1106
  /**
925
- * Return [hue, saturation, lightness, alpha] in the same ranges as
926
- * Pixel_from_hsla.
927
- *
1107
+ * Return [+hue+, +saturation+, +lightness+, +alpha+] in the same ranges as
1108
+ * {Magick::Pixel.from_hsla}.
928
1109
  *
929
- * Ruby usage:
930
- * - @verbatim Pixel#to_hsla @endverbatim
931
- *
932
- * @param self this object
933
- * @return an array with hsla data
934
- * @see Pixel_from_hsla
1110
+ * @return [Array<Float>] an array with hsla data
1111
+ * @see Pixel.from_hsla
935
1112
  */
936
1113
  VALUE
937
1114
  Pixel_to_hsla(VALUE self)
@@ -940,13 +1117,27 @@ Pixel_to_hsla(VALUE self)
940
1117
  Pixel *pixel;
941
1118
  VALUE hsla;
942
1119
 
943
- Data_Get_Struct(self, Pixel, pixel);
1120
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
944
1121
 
945
1122
  ConvertRGBToHSL(pixel->red, pixel->green, pixel->blue, &hue, &sat, &lum);
946
1123
  hue *= 360.0;
947
1124
  sat *= 255.0;
948
1125
  lum *= 255.0;
949
1126
 
1127
+ #if defined(IMAGEMAGICK_7)
1128
+ if (pixel->alpha == OpaqueAlpha)
1129
+ {
1130
+ alpha = 1.0;
1131
+ }
1132
+ else if (pixel->alpha == TransparentAlpha)
1133
+ {
1134
+ alpha = 0.0;
1135
+ }
1136
+ else
1137
+ {
1138
+ alpha = (double)(pixel->alpha) / (double)QuantumRange;
1139
+ }
1140
+ #else
950
1141
  if (pixel->opacity == OpaqueOpacity)
951
1142
  {
952
1143
  alpha = 1.0;
@@ -959,6 +1150,7 @@ Pixel_to_hsla(VALUE self)
959
1150
  {
960
1151
  alpha = (double)(QuantumRange - pixel->opacity) / (double)QuantumRange;
961
1152
  }
1153
+ #endif
962
1154
 
963
1155
  hsla = rb_ary_new3(4, rb_float_new(hue), rb_float_new(sat), rb_float_new(lum), rb_float_new(alpha));
964
1156
 
@@ -985,7 +1177,11 @@ rm_set_magick_pixel_packet(Pixel *pixel, MagickPixel *pp)
985
1177
  pp->red = (MagickRealType) pixel->red;
986
1178
  pp->green = (MagickRealType) pixel->green;
987
1179
  pp->blue = (MagickRealType) pixel->blue;
1180
+ #if defined(IMAGEMAGICK_7)
1181
+ pp->alpha = (MagickRealType) pixel->alpha;
1182
+ #else
988
1183
  pp->opacity = (MagickRealType) pixel->opacity;
1184
+ #endif
989
1185
  pp->index = (MagickRealType) 0.0;
990
1186
  }
991
1187
 
@@ -993,24 +1189,12 @@ rm_set_magick_pixel_packet(Pixel *pixel, MagickPixel *pp)
993
1189
  /**
994
1190
  * Return the color name corresponding to the pixel values.
995
1191
  *
996
- * Ruby usage:
997
- * - @verbatim Magick::Pixel#to_color @endverbatim
998
- * - @verbatim Magick::Pixel#to_color(compliance) @endverbatim
999
- * - @verbatim Magick::Pixel#to_color(compliance, matte) @endverbatim
1000
- * - @verbatim Magick::Pixel#to_color(compliance, matte, depth) @endverbatim
1001
- * - @verbatim Magick::Pixel#to_color(compliance, matte, depth, hex) @endverbatim
1002
- *
1003
- * Notes:
1004
- * - Default compliance is AllCompliance
1005
- * - Default matte is false
1006
- * - Default depth is MAGICKCORE_QUANTUM_DEPTH
1007
- * - Default hex is false
1008
- * - The conversion respects the value of the 'opacity' field in the Pixel
1009
- *
1010
- * @param argc number of input arguments
1011
- * @param argv array of input arguments
1012
- * @param self this object
1013
- * @return the color name as a String
1192
+ * @overload to_color(compliance = Magick::AllCompliance, alpha = false, depth = Magick::MAGICKCORE_QUANTUM_DEPTH, hex = false)
1193
+ * @param compliance [Magick::ComplianceType] A ComplianceType constant
1194
+ * @param alpha [Boolean] If false, the pixel's alpha attribute is ignored
1195
+ * @param depth [Numeric] An image depth
1196
+ * @param hex [Boolean] If true, represent the color name in hex format
1197
+ * @return [String] the color name as a String
1014
1198
  */
1015
1199
  VALUE
1016
1200
  Pixel_to_color(int argc, VALUE *argv, VALUE self)
@@ -1023,7 +1207,7 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
1023
1207
  char name[MaxTextExtent];
1024
1208
  ExceptionInfo *exception;
1025
1209
  ComplianceType compliance = AllCompliance;
1026
- unsigned int matte = MagickFalse;
1210
+ unsigned int alpha = MagickFalse;
1027
1211
  unsigned int depth = MAGICKCORE_QUANTUM_DEPTH;
1028
1212
 
1029
1213
  switch (argc)
@@ -1049,7 +1233,7 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
1049
1233
  break;
1050
1234
  }
1051
1235
  case 2:
1052
- matte = RTEST(argv[1]);
1236
+ alpha = RTEST(argv[1]);
1053
1237
  case 1:
1054
1238
  VALUE_TO_ENUM(argv[0], compliance, ComplianceType);
1055
1239
  case 0:
@@ -1058,44 +1242,55 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
1058
1242
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc);
1059
1243
  }
1060
1244
 
1061
- Data_Get_Struct(self, Pixel, pixel);
1245
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
1062
1246
 
1063
1247
  info = CloneImageInfo(NULL);
1064
1248
  image = rm_acquire_image(info);
1065
- (void) DestroyImageInfo(info);
1249
+ DestroyImageInfo(info);
1066
1250
 
1067
1251
  if (!image)
1068
1252
  {
1069
1253
  rb_raise(rb_eNoMemError, "not enough memory to continue.");
1070
1254
  }
1071
1255
 
1256
+ exception = AcquireExceptionInfo();
1257
+
1072
1258
  image->depth = depth;
1073
- image->matte = matte;
1259
+ #if defined(IMAGEMAGICK_7)
1260
+ if (alpha)
1261
+ {
1262
+ image->alpha_trait = BlendPixelTrait;
1263
+ }
1264
+ #else
1265
+ image->matte = alpha;
1266
+ #endif
1074
1267
 
1075
1268
  rm_init_magickpixel(image, &mpp);
1076
1269
  rm_set_magick_pixel_packet(pixel, &mpp);
1077
1270
 
1078
- exception = AcquireExceptionInfo();
1079
-
1080
1271
  // Support for hex-format color names moved out of QueryMagickColorname
1081
1272
  // in 6.4.1-9. The 'hex' argument was removed as well.
1082
1273
  if (hex)
1083
1274
  {
1084
1275
  if (compliance == XPMCompliance)
1085
1276
  {
1277
+ #if defined(IMAGEMAGICK_7)
1278
+ mpp.alpha_trait = UndefinedPixelTrait;
1279
+ #else
1086
1280
  mpp.matte = MagickFalse;
1281
+ #endif
1087
1282
  mpp.depth = (unsigned long) min(1.0 * image->depth, 16.0);
1088
1283
  }
1089
- (void) GetColorTuple(&mpp, MagickTrue, name);
1284
+ GetColorTuple(&mpp, MagickTrue, name);
1090
1285
  }
1091
1286
  else
1092
1287
  {
1093
- (void) QueryMagickColorname(image, &mpp, compliance, name, exception);
1288
+ QueryColorname(image, &mpp, compliance, name, exception);
1094
1289
  }
1095
1290
 
1096
- (void) DestroyImage(image);
1097
- CHECK_EXCEPTION()
1098
- (void) DestroyExceptionInfo(exception);
1291
+ DestroyImage(image);
1292
+ CHECK_EXCEPTION();
1293
+ DestroyExceptionInfo(exception);
1099
1294
 
1100
1295
  // Always return a string, even if it's ""
1101
1296
  return rb_str_new2(name);
@@ -1103,13 +1298,9 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
1103
1298
 
1104
1299
 
1105
1300
  /**
1106
- * Create a string representation of a Magick::Pixel.
1107
- *
1108
- * Ruby usage:
1109
- * - @verbatim Magick::Pixel#to_s @endverbatim
1301
+ * Return a string representation of a {Magick::Pixel} object.
1110
1302
  *
1111
- * @param self this object
1112
- * @return the string
1303
+ * @return [String] the string
1113
1304
  */
1114
1305
  VALUE
1115
1306
  Pixel_to_s(VALUE self)
@@ -1117,10 +1308,14 @@ Pixel_to_s(VALUE self)
1117
1308
  Pixel *pixel;
1118
1309
  char buff[100];
1119
1310
 
1120
- Data_Get_Struct(self, Pixel, pixel);
1121
- sprintf(buff, "red=" QuantumFormat ", green=" QuantumFormat ", blue=" QuantumFormat ", alpha=" QuantumFormat,
1311
+ TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
1312
+ snprintf(buff, sizeof(buff), "red=" QuantumFormat ", green=" QuantumFormat ", blue=" QuantumFormat ", alpha=" QuantumFormat,
1122
1313
  pixel->red, pixel->green, pixel->blue,
1314
+ #if defined(IMAGEMAGICK_7)
1315
+ pixel->alpha);
1316
+ #else
1123
1317
  (QuantumRange - pixel->opacity));
1318
+ #endif
1124
1319
  return rb_str_new2(buff);
1125
1320
  }
1126
1321