rmagick 4.0.0 → 4.1.0.rc1

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.

@@ -12,6 +12,18 @@
12
12
 
13
13
  #include "rmagick.h"
14
14
 
15
+ #define BEGIN_CHANNEL_MASK(image, channels) \
16
+ { \
17
+ ChannelType channel_mask=SetPixelChannelMask(image, (ChannelType)channels);
18
+
19
+ #define END_CHANNEL_MASK(image) \
20
+ SetPixelChannelMask(image, channel_mask); \
21
+ }
22
+
23
+ #define CHANGE_RESULT_CHANNEL_MASK(result) \
24
+ if (result != (Image *)NULL) \
25
+ SetPixelChannelMask(result, channel_mask);
26
+
15
27
  /** Method that effects an image */
16
28
  typedef Image *(effector_t)(const Image *, const double, const double, ExceptionInfo *);
17
29
  /** Method that flips an image */
@@ -23,7 +35,17 @@ typedef Image *(reader_t)(const Info *, ExceptionInfo *);
23
35
  /** Method that scales an image */
24
36
  typedef Image *(scaler_t)(const Image *, const size_t, const size_t, ExceptionInfo *);
25
37
  /** Method that computes threshold on an image */
26
- typedef MagickBooleanType (thresholder_t)(Image *, const char *);
38
+ #if defined(IMAGEMAGICK_7)
39
+ typedef MagickBooleanType (auto_channel_t)(Image *, ExceptionInfo *exception);
40
+ typedef Image *(channel_method_t)(const Image *, const double, const double, ExceptionInfo *);
41
+ typedef MagickBooleanType (thresholder_t)(Image *, const char *, ExceptionInfo *);
42
+ #else
43
+ typedef MagickBooleanType (auto_channel_t)(Image *, const ChannelType);
44
+ typedef Image *(channel_method_t)(const Image *, const ChannelType, const double, const double, ExceptionInfo *);
45
+ typedef MagickBooleanType (thresholder_t)(Image *, const char *);
46
+ #define IsEquivalentImage IsImageSimilar
47
+ #define OrderedDitherImage OrderedPosterizeImage
48
+ #endif
27
49
  /** Method that transforms an image */
28
50
  typedef Image *(xformer_t)(const Image *, const RectangleInfo *, ExceptionInfo *);
29
51
 
@@ -132,8 +154,7 @@ adaptive_method(int argc, VALUE *argv, VALUE self
132
154
  * @return a new image
133
155
  */
134
156
  static VALUE
135
- adaptive_channel_method(int argc, VALUE *argv, VALUE self
136
- , Image *fp(const Image *, const ChannelType, const double, const double, ExceptionInfo *))
157
+ adaptive_channel_method(int argc, VALUE *argv, VALUE self, channel_method_t fp)
137
158
  {
138
159
  Image *image, *new_image;
139
160
  double radius = 0.0;
@@ -159,7 +180,15 @@ adaptive_channel_method(int argc, VALUE *argv, VALUE self
159
180
 
160
181
  exception = AcquireExceptionInfo();
161
182
 
183
+ #if defined(IMAGEMAGICK_7)
184
+ BEGIN_CHANNEL_MASK(image, channels);
185
+ new_image = (fp)(image, radius, sigma, exception);
186
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
187
+ END_CHANNEL_MASK(image);
188
+ #else
162
189
  new_image = (fp)(image, channels, radius, sigma, exception);
190
+ #endif
191
+
163
192
  rm_check_exception(exception, new_image, DestroyOnError);
164
193
 
165
194
  (void) DestroyExceptionInfo(exception);
@@ -218,7 +247,11 @@ Image_adaptive_blur(int argc, VALUE *argv, VALUE self)
218
247
  VALUE
219
248
  Image_adaptive_blur_channel(int argc, VALUE *argv, VALUE self)
220
249
  {
250
+ #if defined(IMAGEMAGICK_7)
251
+ return adaptive_channel_method(argc, argv, self, AdaptiveBlurImage);
252
+ #else
221
253
  return adaptive_channel_method(argc, argv, self, AdaptiveBlurImageChannel);
254
+ #endif
222
255
  }
223
256
 
224
257
 
@@ -321,7 +354,11 @@ Image_adaptive_sharpen(int argc, VALUE *argv, VALUE self)
321
354
  VALUE
322
355
  Image_adaptive_sharpen_channel(int argc, VALUE *argv, VALUE self)
323
356
  {
357
+ #if defined(IMAGEMAGICK_7)
358
+ return adaptive_channel_method(argc, argv, self, AdaptiveSharpenImage);
359
+ #else
324
360
  return adaptive_channel_method(argc, argv, self, AdaptiveSharpenImageChannel);
361
+ #endif
325
362
  }
326
363
 
327
364
 
@@ -400,6 +437,10 @@ VALUE
400
437
  Image_add_compose_mask(VALUE self, VALUE mask)
401
438
  {
402
439
  Image *image, *mask_image = NULL;
440
+ #if defined(IMAGEMAGICK_7)
441
+ ExceptionInfo *exception;
442
+ Image *clip_mask = NULL;
443
+ #endif
403
444
 
404
445
  image = rm_check_frozen(self);
405
446
  mask_image = rm_check_destroyed(mask);
@@ -408,6 +449,17 @@ Image_add_compose_mask(VALUE self, VALUE mask)
408
449
  rb_raise(rb_eArgError, "mask must be the same size as image");
409
450
  }
410
451
 
452
+ #if defined(IMAGEMAGICK_7)
453
+ clip_mask = rm_clone_image(mask_image);
454
+
455
+ exception = AcquireExceptionInfo();
456
+ (void) NegateImage(clip_mask, MagickFalse, exception);
457
+ rm_check_exception(exception, clip_mask, DestroyOnError);
458
+ (void) SetImageMask(image, CompositePixelMask, clip_mask, exception);
459
+ (void) DestroyImage(clip_mask);
460
+ CHECK_EXCEPTION()
461
+ (void) DestroyExceptionInfo(exception);
462
+ #else
411
463
  // Delete any previously-existing mask image.
412
464
  // Store a clone of the new mask image.
413
465
  (void) SetImageMask(image, mask_image);
@@ -415,6 +467,7 @@ Image_add_compose_mask(VALUE self, VALUE mask)
415
467
 
416
468
  // Since both Set and GetImageMask clone the mask image I don't see any
417
469
  // way to negate the mask without referencing it directly. Sigh.
470
+ #endif
418
471
 
419
472
  return self;
420
473
  }
@@ -442,7 +495,11 @@ Image_add_noise(VALUE self, VALUE noise)
442
495
  VALUE_TO_ENUM(noise, noise_type, NoiseType);
443
496
 
444
497
  exception = AcquireExceptionInfo();
498
+ #if defined(IMAGEMAGICK_7)
499
+ new_image = AddNoiseImage(image, noise_type, 1.0, exception);
500
+ #else
445
501
  new_image = AddNoiseImage(image, noise_type, exception);
502
+ #endif
446
503
  rm_check_exception(exception, new_image, DestroyOnError);
447
504
 
448
505
  (void) DestroyExceptionInfo(exception);
@@ -493,7 +550,13 @@ Image_add_noise_channel(int argc, VALUE *argv, VALUE self)
493
550
  channels &= ~OpacityChannel;
494
551
 
495
552
  exception = AcquireExceptionInfo();
553
+ #if defined(IMAGEMAGICK_7)
554
+ BEGIN_CHANNEL_MASK(image, channels);
555
+ new_image = AddNoiseImage(image, noise_type, 1.0, exception);
556
+ END_CHANNEL_MASK(new_image);
557
+ #else
496
558
  new_image = AddNoiseImageChannel(image, channels, noise_type, exception);
559
+ #endif
497
560
  rm_check_exception(exception, new_image, DestroyOnError);
498
561
 
499
562
  (void) DestroyExceptionInfo(exception);
@@ -557,8 +620,13 @@ Image_add_profile(VALUE self, VALUE name)
557
620
  profile = GetImageProfile(profile_image, profile_name);
558
621
  if (profile)
559
622
  {
623
+ #if defined(IMAGEMAGICK_7)
624
+ (void) ProfileImage(image, profile_name, GetStringInfoDatum(profile), GetStringInfoLength(profile), exception);
625
+ if (rm_should_raise_exception(exception, RetainExceptionRetention))
626
+ #else
560
627
  (void) ProfileImage(image, profile_name, GetStringInfoDatum(profile), GetStringInfoLength(profile), MagickFalse);
561
628
  if (rm_should_raise_exception(&image->exception, RetainExceptionRetention))
629
+ #endif
562
630
  {
563
631
  break;
564
632
  }
@@ -567,8 +635,13 @@ Image_add_profile(VALUE self, VALUE name)
567
635
  }
568
636
 
569
637
  (void) DestroyImage(profile_image);
638
+ #if defined(IMAGEMAGICK_7)
639
+ CHECK_EXCEPTION()
640
+ (void) DestroyExceptionInfo(exception);
641
+ #else
570
642
  (void) DestroyExceptionInfo(exception);
571
643
  rm_check_image_exception(image, RetainOnError);
644
+ #endif
572
645
 
573
646
  return self;
574
647
  }
@@ -599,6 +672,9 @@ Image_alpha(int argc, VALUE *argv, VALUE self)
599
672
  {
600
673
  Image *image;
601
674
  AlphaChannelOption alpha;
675
+ #if defined(IMAGEMAGICK_7)
676
+ ExceptionInfo *exception;
677
+ #endif
602
678
 
603
679
 
604
680
  // For backward compatibility, make alpha() act like alpha?
@@ -615,8 +691,16 @@ Image_alpha(int argc, VALUE *argv, VALUE self)
615
691
  image = rm_check_frozen(self);
616
692
  VALUE_TO_ENUM(argv[0], alpha, AlphaChannelOption);
617
693
 
694
+ #if defined(IMAGEMAGICK_7)
695
+ exception = AcquireExceptionInfo();
696
+ (void) SetImageAlphaChannel(image, alpha, exception);
697
+ CHECK_EXCEPTION()
698
+ (void) DestroyExceptionInfo(exception);
699
+ #else
618
700
  (void) SetImageAlphaChannel(image, alpha);
619
701
  rm_check_image_exception(image, RetainOnError);
702
+ #endif
703
+
620
704
  return argv[0];
621
705
  }
622
706
 
@@ -638,7 +722,11 @@ VALUE
638
722
  Image_alpha_q(VALUE self)
639
723
  {
640
724
  Image *image = rm_check_destroyed(self);
725
+ #if defined(IMAGEMAGICK_7)
726
+ return image->alpha_trait == BlendPixelTrait ? Qtrue : Qfalse;
727
+ #else
641
728
  return GetImageAlphaChannel(image) ? Qtrue : Qfalse;
729
+ #endif
642
730
  }
643
731
 
644
732
 
@@ -849,10 +937,13 @@ crisscross(int bang, VALUE self, Image *fp(const Image *, ExceptionInfo *))
849
937
  * @return a new image
850
938
  */
851
939
  static VALUE
852
- auto_channel(int argc, VALUE *argv, VALUE self, MagickBooleanType (*fp)(Image *, const ChannelType))
940
+ auto_channel(int argc, VALUE *argv, VALUE self, auto_channel_t fp)
853
941
  {
854
942
  Image *image, *new_image;
855
943
  ChannelType channels;
944
+ #if defined(IMAGEMAGICK_7)
945
+ ExceptionInfo *exception;
946
+ #endif
856
947
 
857
948
  image = rm_check_destroyed(self);
858
949
  channels = extract_channels(&argc, argv);
@@ -863,8 +954,18 @@ auto_channel(int argc, VALUE *argv, VALUE self, MagickBooleanType (*fp)(Image *,
863
954
  }
864
955
 
865
956
  new_image = rm_clone_image(image);
957
+
958
+ #if defined(IMAGEMAGICK_7)
959
+ exception = AcquireExceptionInfo();
960
+ BEGIN_CHANNEL_MASK(new_image, channels);
961
+ (void) (fp)(new_image, exception);
962
+ END_CHANNEL_MASK(new_image);
963
+ rm_check_exception(exception, new_image, DestroyOnError);
964
+ (void) DestroyExceptionInfo(exception);
965
+ #else
866
966
  (void) (fp)(new_image, channels);
867
967
  rm_check_image_exception(new_image, DestroyOnError);
968
+ #endif
868
969
 
869
970
  return rm_image_new(new_image);
870
971
  }
@@ -887,7 +988,11 @@ auto_channel(int argc, VALUE *argv, VALUE self, MagickBooleanType (*fp)(Image *,
887
988
  VALUE
888
989
  Image_auto_gamma_channel(int argc, VALUE *argv, VALUE self)
889
990
  {
991
+ #if defined(IMAGEMAGICK_7)
992
+ return auto_channel(argc, argv, self, AutoGammaImage);
993
+ #else
890
994
  return auto_channel(argc, argv, self, AutoGammaImageChannel);
995
+ #endif
891
996
  }
892
997
 
893
998
 
@@ -908,7 +1013,11 @@ Image_auto_gamma_channel(int argc, VALUE *argv, VALUE self)
908
1013
  VALUE
909
1014
  Image_auto_level_channel(int argc, VALUE *argv, VALUE self)
910
1015
  {
1016
+ #if defined(IMAGEMAGICK_7)
1017
+ return auto_channel(argc, argv, self, AutoLevelImage);
1018
+ #else
911
1019
  return auto_channel(argc, argv, self, AutoLevelImageChannel);
1020
+ #endif
912
1021
  }
913
1022
 
914
1023
 
@@ -1122,9 +1231,27 @@ VALUE
1122
1231
  Image_bias(VALUE self)
1123
1232
  {
1124
1233
  Image *image;
1234
+ double bias = 0.0;
1125
1235
 
1126
1236
  image = rm_check_destroyed(self);
1127
- return rb_float_new(image->bias);
1237
+ #if defined(IMAGEMAGICK_7)
1238
+ {
1239
+ const char *artifact = GetImageArtifact(image, "convolve:bias");
1240
+ if (artifact != (const char *) NULL)
1241
+ {
1242
+ char *q;
1243
+
1244
+ bias = InterpretLocaleValue(artifact,&q);
1245
+ if (*q == '%')
1246
+ {
1247
+ bias *= ((double) QuantumRange + 1.0) / 100.0;
1248
+ }
1249
+ }
1250
+ }
1251
+ #else
1252
+ bias = image->bias;
1253
+ #endif
1254
+ return rb_float_new(bias);
1128
1255
  }
1129
1256
 
1130
1257
 
@@ -1146,7 +1273,17 @@ Image_bias_eq(VALUE self, VALUE pct)
1146
1273
 
1147
1274
  image = rm_check_frozen(self);
1148
1275
  bias = rm_percentage(pct, 1.0) * QuantumRange;
1276
+
1277
+ #if defined(IMAGEMAGICK_7)
1278
+ {
1279
+ char artifact[21];
1280
+
1281
+ snprintf(artifact, sizeof(artifact), "%.20g", bias);
1282
+ SetImageArtifact(image, "convolve:bias", artifact);
1283
+ }
1284
+ #else
1149
1285
  image->bias = bias;
1286
+ #endif
1150
1287
 
1151
1288
  return pct;
1152
1289
  }
@@ -1172,6 +1309,9 @@ Image_bilevel_channel(int argc, VALUE *argv, VALUE self)
1172
1309
  Image *image, *new_image;
1173
1310
  ChannelType channels;
1174
1311
  double threshold;
1312
+ #if defined(IMAGEMAGICK_7)
1313
+ ExceptionInfo *exception;
1314
+ #endif
1175
1315
 
1176
1316
  image = rm_check_destroyed(self);
1177
1317
  channels = extract_channels(&argc, argv);
@@ -1188,8 +1328,17 @@ Image_bilevel_channel(int argc, VALUE *argv, VALUE self)
1188
1328
  threshold = NUM2DBL(argv[0]);
1189
1329
  new_image = rm_clone_image(image);
1190
1330
 
1331
+ #if defined(IMAGEMAGICK_7)
1332
+ exception = AcquireExceptionInfo();
1333
+ BEGIN_CHANNEL_MASK(new_image, channels);
1334
+ (void) BilevelImage(new_image, threshold, exception);
1335
+ END_CHANNEL_MASK(new_image);
1336
+ rm_check_exception(exception, new_image, DestroyOnError);
1337
+ (void) DestroyExceptionInfo(exception);
1338
+ #else
1191
1339
  (void)BilevelImageChannel(new_image, channels, threshold);
1192
1340
  rm_check_image_exception(new_image, DestroyOnError);
1341
+ #endif
1193
1342
 
1194
1343
  return rm_image_new(new_image);
1195
1344
  }
@@ -1569,15 +1718,28 @@ special_composite(Image *image, Image *overlay, double image_pct, double overlay
1569
1718
  {
1570
1719
  Image *new_image;
1571
1720
  char geometry[20];
1721
+ #if defined(IMAGEMAGICK_7)
1722
+ ExceptionInfo *exception;
1723
+ #endif
1572
1724
 
1573
1725
  blend_geometry(geometry, sizeof(geometry), image_pct, overlay_pct);
1574
1726
  (void) CloneString(&overlay->geometry, geometry);
1575
1727
  (void) SetImageArtifact(overlay,"compose:args", geometry);
1576
1728
 
1577
1729
  new_image = rm_clone_image(image);
1730
+ (void) SetImageArtifact(new_image,"compose:args", geometry); // 6.9 appears to get this info from canvas (dest) image
1731
+
1732
+
1733
+ #if defined(IMAGEMAGICK_7)
1734
+ exception = AcquireExceptionInfo();
1735
+ (void) CompositeImage(new_image, overlay, op, MagickTrue, x_off, y_off, exception);
1736
+ rm_check_exception(exception, new_image, DestroyOnError);
1737
+ (void) DestroyExceptionInfo(exception);
1738
+ #else
1578
1739
  (void) CompositeImage(new_image, op, overlay, x_off, y_off);
1579
1740
 
1580
1741
  rm_check_image_exception(new_image, DestroyOnError);
1742
+ #endif
1581
1743
 
1582
1744
  return rm_image_new(new_image);
1583
1745
  }
@@ -1744,7 +1906,14 @@ Image_blur_channel(int argc, VALUE *argv, VALUE self)
1744
1906
  }
1745
1907
 
1746
1908
  exception = AcquireExceptionInfo();
1909
+ #if defined(IMAGEMAGICK_7)
1910
+ BEGIN_CHANNEL_MASK(image, channels);
1911
+ new_image = BlurImage(image, radius, sigma, exception);
1912
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
1913
+ END_CHANNEL_MASK(image);
1914
+ #else
1747
1915
  new_image = BlurImageChannel(image, channels, radius, sigma, exception);
1916
+ #endif
1748
1917
  rm_check_exception(exception, new_image, DestroyOnError);
1749
1918
 
1750
1919
  (void) DestroyExceptionInfo(exception);
@@ -1814,7 +1983,11 @@ border(int bang, VALUE self, VALUE width, VALUE height, VALUE color)
1814
1983
  Color_to_PixelColor(&image->border_color, color);
1815
1984
 
1816
1985
  exception = AcquireExceptionInfo();
1986
+ #if defined(IMAGEMAGICK_7)
1987
+ new_image = BorderImage(image, &rect, image->compose, exception);
1988
+ #else
1817
1989
  new_image = BorderImage(image, &rect, exception);
1990
+ #endif
1818
1991
  rm_check_exception(exception, new_image, DestroyOnError);
1819
1992
 
1820
1993
  (void) DestroyExceptionInfo(exception);
@@ -1972,6 +2145,9 @@ Image_capture(int argc, VALUE *argv, VALUE self ATTRIBUTE_UNUSED)
1972
2145
  ImageInfo *image_info;
1973
2146
  VALUE info_obj;
1974
2147
  XImportInfo ximage_info;
2148
+ #if defined(IMAGEMAGICK_7)
2149
+ ExceptionInfo *exception;
2150
+ #endif
1975
2151
 
1976
2152
  XGetImportInfo(&ximage_info);
1977
2153
  switch (argc)
@@ -2002,8 +2178,16 @@ Image_capture(int argc, VALUE *argv, VALUE self ATTRIBUTE_UNUSED)
2002
2178
  Data_Get_Struct(info_obj, Info, image_info);
2003
2179
 
2004
2180
  // If an error occurs, IM will call our error handler and we raise an exception.
2181
+ #if defined(IMAGEMAGICK_7)
2182
+ exception = AcquireExceptionInfo();
2183
+ new_image = XImportImage(image_info, &ximage_info, exception);
2184
+ rm_check_exception(exception, new_image, DestroyOnError);
2185
+ (void) DestroyExceptionInfo(exception);
2186
+ #else
2005
2187
  new_image = XImportImage(image_info, &ximage_info);
2006
2188
  rm_check_image_exception(new_image, DestroyOnError);
2189
+ #endif
2190
+
2007
2191
  rm_ensure_result(new_image);
2008
2192
 
2009
2193
  rm_set_user_artifact(new_image, image_info);
@@ -2094,6 +2278,9 @@ Image_channel(VALUE self, VALUE channel_arg)
2094
2278
  {
2095
2279
  Image *image, *new_image;
2096
2280
  ChannelType channel;
2281
+ #if defined(IMAGEMAGICK_7)
2282
+ ExceptionInfo *exception;
2283
+ #endif
2097
2284
 
2098
2285
  image = rm_check_destroyed(self);
2099
2286
 
@@ -2101,9 +2288,16 @@ Image_channel(VALUE self, VALUE channel_arg)
2101
2288
 
2102
2289
  new_image = rm_clone_image(image);
2103
2290
 
2291
+ #if defined(IMAGEMAGICK_7)
2292
+ exception = AcquireExceptionInfo();
2293
+ (void) SeparateImage(new_image, channel, exception);
2294
+ rm_check_exception(exception, new_image, DestroyOnError);
2295
+ (void) DestroyExceptionInfo(exception);
2296
+ #else
2104
2297
  (void) SeparateImageChannel(new_image, channel);
2105
2298
 
2106
2299
  rm_check_image_exception(new_image, DestroyOnError);
2300
+ #endif
2107
2301
  rm_ensure_result(new_image);
2108
2302
 
2109
2303
  return rm_image_new(new_image);
@@ -2144,7 +2338,13 @@ Image_channel_depth(int argc, VALUE *argv, VALUE self)
2144
2338
 
2145
2339
  exception = AcquireExceptionInfo();
2146
2340
 
2341
+ #if defined(IMAGEMAGICK_7)
2342
+ BEGIN_CHANNEL_MASK(image, channels);
2343
+ channel_depth = GetImageDepth(image, exception);
2344
+ END_CHANNEL_MASK(image);
2345
+ #else
2147
2346
  channel_depth = GetImageChannelDepth(image, channels, exception);
2347
+ #endif
2148
2348
  CHECK_EXCEPTION()
2149
2349
 
2150
2350
  (void) DestroyExceptionInfo(exception);
@@ -2193,7 +2393,13 @@ Image_channel_extrema(int argc, VALUE *argv, VALUE self)
2193
2393
  }
2194
2394
 
2195
2395
  exception = AcquireExceptionInfo();
2396
+ #if defined(IMAGEMAGICK_7)
2397
+ BEGIN_CHANNEL_MASK(image, channels);
2398
+ (void) GetImageExtrema(image, &min, &max, exception);
2399
+ END_CHANNEL_MASK(image);
2400
+ #else
2196
2401
  (void) GetImageChannelExtrema(image, channels, &min, &max, exception);
2402
+ #endif
2197
2403
  CHECK_EXCEPTION()
2198
2404
 
2199
2405
  (void) DestroyExceptionInfo(exception);
@@ -2243,7 +2449,13 @@ Image_channel_mean(int argc, VALUE *argv, VALUE self)
2243
2449
  }
2244
2450
 
2245
2451
  exception = AcquireExceptionInfo();
2452
+ #if defined(IMAGEMAGICK_7)
2453
+ BEGIN_CHANNEL_MASK(image, channels);
2454
+ (void) GetImageMean(image, &mean, &stddev, exception);
2455
+ END_CHANNEL_MASK(image);
2456
+ #else
2246
2457
  (void) GetImageChannelMean(image, channels, &mean, &stddev, exception);
2458
+ #endif
2247
2459
  CHECK_EXCEPTION()
2248
2460
 
2249
2461
  (void) DestroyExceptionInfo(exception);
@@ -2275,7 +2487,7 @@ Image_channel_mean(int argc, VALUE *argv, VALUE self)
2275
2487
  VALUE
2276
2488
  Image_channel_entropy(int argc, VALUE *argv, VALUE self)
2277
2489
  {
2278
- #if defined(HAVE_GETIMAGECHANNELENTROPY)
2490
+ #if defined(HAVE_GETIMAGECHANNELENTROPY) || defined(IMAGEMAGICK_7)
2279
2491
  Image *image;
2280
2492
  ChannelType channels;
2281
2493
  ExceptionInfo *exception;
@@ -2293,7 +2505,13 @@ Image_channel_entropy(int argc, VALUE *argv, VALUE self)
2293
2505
  }
2294
2506
 
2295
2507
  exception = AcquireExceptionInfo();
2508
+ #if defined(IMAGEMAGICK_7)
2509
+ BEGIN_CHANNEL_MASK(image, channels);
2510
+ (void) GetImageEntropy(image, &entropy, exception);
2511
+ END_CHANNEL_MASK(image);
2512
+ #else
2296
2513
  (void) GetImageChannelEntropy(image, channels, &entropy, exception);
2514
+ #endif
2297
2515
  CHECK_EXCEPTION()
2298
2516
 
2299
2517
  (void) DestroyExceptionInfo(exception);
@@ -2460,6 +2678,9 @@ Image_clut_channel(int argc, VALUE *argv, VALUE self)
2460
2678
  Image *image, *clut;
2461
2679
  ChannelType channels;
2462
2680
  MagickBooleanType okay;
2681
+ #if defined(IMAGEMAGICK_7)
2682
+ ExceptionInfo *exception;
2683
+ #endif
2463
2684
 
2464
2685
  image = rm_check_frozen(self);
2465
2686
 
@@ -2480,9 +2701,18 @@ Image_clut_channel(int argc, VALUE *argv, VALUE self)
2480
2701
 
2481
2702
  Data_Get_Struct(argv[0], Image, clut);
2482
2703
 
2704
+ #if defined(IMAGEMAGICK_7)
2705
+ exception = AcquireExceptionInfo();
2706
+ BEGIN_CHANNEL_MASK(image, channels);
2707
+ okay = ClutImage(image, clut, image->interpolate, exception);
2708
+ END_CHANNEL_MASK(image);
2709
+ CHECK_EXCEPTION()
2710
+ (void) DestroyExceptionInfo(exception);
2711
+ #else
2483
2712
  okay = ClutImageChannel(image, channels, clut);
2484
2713
  rm_check_image_exception(image, RetainOnError);
2485
2714
  rm_check_image_exception(clut, RetainOnError);
2715
+ #endif
2486
2716
  if (!okay)
2487
2717
  {
2488
2718
  rb_raise(rb_eRuntimeError, "ClutImageChannel failed.");
@@ -2510,20 +2740,29 @@ Image_color_histogram(VALUE self)
2510
2740
  Image *image, *dc_copy = NULL;
2511
2741
  VALUE hash, pixel;
2512
2742
  size_t x, colors;
2513
- ColorPacket *histogram;
2514
2743
  ExceptionInfo *exception;
2744
+ #if defined(IMAGEMAGICK_7)
2745
+ PixelInfo *histogram;
2746
+ #else
2747
+ ColorPacket *histogram;
2748
+ #endif
2515
2749
 
2516
2750
  image = rm_check_destroyed(self);
2517
2751
 
2752
+ exception = AcquireExceptionInfo();
2753
+
2518
2754
  // If image not DirectClass make a DirectClass copy.
2519
2755
  if (image->storage_class != DirectClass)
2520
2756
  {
2521
2757
  dc_copy = rm_clone_image(image);
2758
+ #if defined(IMAGEMAGICK_7)
2759
+ (void) SetImageStorageClass(dc_copy, DirectClass, exception);
2760
+ #else
2522
2761
  (void) SetImageStorageClass(dc_copy, DirectClass);
2762
+ #endif
2523
2763
  image = dc_copy;
2524
2764
  }
2525
2765
 
2526
- exception = AcquireExceptionInfo();
2527
2766
  histogram = GetImageHistogram(image, &colors, exception);
2528
2767
 
2529
2768
  if (histogram == NULL)
@@ -2548,7 +2787,11 @@ Image_color_histogram(VALUE self)
2548
2787
  hash = rb_hash_new();
2549
2788
  for (x = 0; x < colors; x++)
2550
2789
  {
2790
+ #if defined(IMAGEMAGICK_7)
2791
+ pixel = Pixel_from_PixelColor(&histogram[x]);
2792
+ #else
2551
2793
  pixel = Pixel_from_PixelColor(&histogram[x].pixel);
2794
+ #endif
2552
2795
  (void) rb_hash_aset(hash, pixel, ULONG2NUM((unsigned long)histogram[x].count));
2553
2796
  }
2554
2797
 
@@ -2626,8 +2869,13 @@ set_profile(VALUE self, const char *name, VALUE profile)
2626
2869
  /* Hack for versions of ImageMagick where the meta coder would change the iptc profile into an 8bim profile */
2627
2870
  if (rm_strcasecmp("8bim", profile_name) == 0 && rm_strcasecmp("iptc", name) == 0)
2628
2871
  {
2872
+ #if defined(IMAGEMAGICK_7)
2873
+ (void) ProfileImage(image, name, profile_blob, profile_length, exception);
2874
+ if (rm_should_raise_exception(exception, RetainExceptionRetention))
2875
+ #else
2629
2876
  (void) ProfileImage(image, name, profile_blob, profile_length, MagickFalse);
2630
2877
  if (rm_should_raise_exception(&image->exception, RetainExceptionRetention))
2878
+ #endif
2631
2879
  {
2632
2880
  break;
2633
2881
  }
@@ -2637,8 +2885,13 @@ set_profile(VALUE self, const char *name, VALUE profile)
2637
2885
  profile_data = GetImageProfile(profile_image, profile_name);
2638
2886
  if (profile_data)
2639
2887
  {
2888
+ #if defined(IMAGEMAGICK_7)
2889
+ (void) ProfileImage(image, name, GetStringInfoDatum(profile_data), GetStringInfoLength(profile_data), exception);
2890
+ if (rm_should_raise_exception(exception, RetainExceptionRetention))
2891
+ #else
2640
2892
  (void) ProfileImage(image, name, GetStringInfoDatum(profile_data), GetStringInfoLength(profile_data), MagickFalse);
2641
2893
  if (rm_should_raise_exception(&image->exception, RetainExceptionRetention))
2894
+ #endif
2642
2895
  {
2643
2896
  break;
2644
2897
  }
@@ -2648,8 +2901,14 @@ set_profile(VALUE self, const char *name, VALUE profile)
2648
2901
  }
2649
2902
 
2650
2903
  (void) DestroyImage(profile_image);
2904
+
2905
+ #if defined(IMAGEMAGICK_7)
2906
+ CHECK_EXCEPTION()
2907
+ (void) DestroyExceptionInfo(exception);
2908
+ #else
2651
2909
  (void) DestroyExceptionInfo(exception);
2652
2910
  rm_check_image_exception(image, RetainOnError);
2911
+ #endif
2653
2912
 
2654
2913
  return self;
2655
2914
  }
@@ -2745,6 +3004,9 @@ Image_color_flood_fill( VALUE self, VALUE target_color, VALUE fill_color
2745
3004
  int fill_method;
2746
3005
  MagickPixel target_mpp;
2747
3006
  MagickBooleanType invert;
3007
+ #if defined(IMAGEMAGICK_7)
3008
+ ExceptionInfo *exception;
3009
+ #endif
2748
3010
 
2749
3011
  image = rm_check_destroyed(self);
2750
3012
 
@@ -2793,10 +3055,18 @@ Image_color_flood_fill( VALUE self, VALUE target_color, VALUE fill_color
2793
3055
  target_mpp.blue = (MagickRealType) target.blue;
2794
3056
  }
2795
3057
 
3058
+ #if defined(IMAGEMAGICK_7)
3059
+ exception = AcquireExceptionInfo();
3060
+ (void) FloodfillPaintImage(new_image, draw_info, &target_mpp, x, y, invert, exception);
3061
+ (void) DestroyDrawInfo(draw_info);
3062
+ rm_check_exception(exception, new_image, DestroyOnError);
3063
+ (void) DestroyExceptionInfo(exception);
3064
+ #else
2796
3065
  (void) FloodfillPaintImage(new_image, DefaultChannels, draw_info, &target_mpp, x, y, invert);
2797
3066
 
2798
3067
  (void) DestroyDrawInfo(draw_info);
2799
3068
  rm_check_image_exception(new_image, DestroyOnError);
3069
+ #endif
2800
3070
 
2801
3071
  return rm_image_new(new_image);
2802
3072
  }
@@ -2849,7 +3119,11 @@ Image_colorize(int argc, VALUE *argv, VALUE self)
2849
3119
  }
2850
3120
 
2851
3121
  exception = AcquireExceptionInfo();
3122
+ #if defined(IMAGEMAGICK_7)
3123
+ new_image = ColorizeImage(image, opacity, &target, exception);
3124
+ #else
2852
3125
  new_image = ColorizeImage(image, opacity, target, exception);
3126
+ #endif
2853
3127
  rm_check_exception(exception, new_image, DestroyOnError);
2854
3128
 
2855
3129
  (void) DestroyExceptionInfo(exception);
@@ -3002,10 +3276,22 @@ Image_colorspace_eq(VALUE self, VALUE colorspace)
3002
3276
  {
3003
3277
  Image *image;
3004
3278
  ColorspaceType new_cs;
3279
+ #if defined(IMAGEMAGICK_7)
3280
+ ExceptionInfo *exception;
3281
+ #endif
3005
3282
 
3006
3283
  image = rm_check_frozen(self);
3007
3284
  VALUE_TO_ENUM(colorspace, new_cs, ColorspaceType);
3285
+
3286
+ #if defined(IMAGEMAGICK_7)
3287
+ exception = AcquireExceptionInfo();
3288
+ (void) TransformImageColorspace(image, new_cs, exception);
3289
+ CHECK_EXCEPTION()
3290
+ (void) DestroyExceptionInfo(exception);
3291
+ #else
3008
3292
  (void) TransformImageColorspace(image, new_cs);
3293
+ rm_check_image_exception(image, RetainOnError);
3294
+ #endif
3009
3295
 
3010
3296
  return colorspace;
3011
3297
  }
@@ -3080,7 +3366,13 @@ Image_compare_channel(int argc, VALUE *argv, VALUE self)
3080
3366
  VALUE_TO_ENUM(argv[1], metric_type, MetricType);
3081
3367
 
3082
3368
  exception = AcquireExceptionInfo();
3369
+ #if defined(IMAGEMAGICK_7)
3370
+ BEGIN_CHANNEL_MASK(image, channels);
3371
+ difference_image = CompareImages(image, r_image, metric_type, &distortion, exception);
3372
+ END_CHANNEL_MASK(image);
3373
+ #else
3083
3374
  difference_image = CompareImageChannels(image, r_image, channels, metric_type, &distortion, exception);
3375
+ #endif
3084
3376
  rm_check_exception(exception, difference_image, DestroyOnError);
3085
3377
 
3086
3378
  (void) DestroyExceptionInfo(exception);
@@ -3164,6 +3456,9 @@ composite(int bang, int argc, VALUE *argv, VALUE self, ChannelType channels)
3164
3456
  VALUE comp;
3165
3457
  signed long x_offset = 0;
3166
3458
  signed long y_offset = 0;
3459
+ #if defined(IMAGEMAGICK_7)
3460
+ ExceptionInfo *exception;
3461
+ #endif
3167
3462
 
3168
3463
  image = rm_check_destroyed(self);
3169
3464
 
@@ -3282,8 +3577,17 @@ composite(int bang, int argc, VALUE *argv, VALUE self, ChannelType channels)
3282
3577
 
3283
3578
  if (bang)
3284
3579
  {
3580
+ #if defined(IMAGEMAGICK_7)
3581
+ exception = AcquireExceptionInfo();
3582
+ BEGIN_CHANNEL_MASK(image, channels);
3583
+ (void) CompositeImage(image, comp_image, operator, MagickTrue, x_offset, y_offset, exception);
3584
+ END_CHANNEL_MASK(image);
3585
+ CHECK_EXCEPTION()
3586
+ (void) DestroyExceptionInfo(exception);
3587
+ #else
3285
3588
  (void) CompositeImageChannel(image, channels, operator, comp_image, x_offset, y_offset);
3286
3589
  rm_check_image_exception(image, RetainOnError);
3590
+ #endif
3287
3591
 
3288
3592
  return self;
3289
3593
  }
@@ -3291,8 +3595,17 @@ composite(int bang, int argc, VALUE *argv, VALUE self, ChannelType channels)
3291
3595
  {
3292
3596
  new_image = rm_clone_image(image);
3293
3597
 
3598
+ #if defined(IMAGEMAGICK_7)
3599
+ exception = AcquireExceptionInfo();
3600
+ BEGIN_CHANNEL_MASK(new_image, channels);
3601
+ (void) CompositeImage(new_image, comp_image, operator, MagickTrue, x_offset, y_offset, exception);
3602
+ END_CHANNEL_MASK(new_image);
3603
+ rm_check_exception(exception, new_image, DestroyOnError);
3604
+ (void) DestroyExceptionInfo(exception);
3605
+ #else
3294
3606
  (void) CompositeImageChannel(new_image, channels, operator, comp_image, x_offset, y_offset);
3295
3607
  rm_check_image_exception(new_image, DestroyOnError);
3608
+ #endif
3296
3609
 
3297
3610
  return rm_image_new(new_image);
3298
3611
  }
@@ -3360,6 +3673,9 @@ Image_composite_affine(VALUE self, VALUE source, VALUE affine_matrix)
3360
3673
  {
3361
3674
  Image *image, *composite_image, *new_image;
3362
3675
  AffineMatrix affine;
3676
+ #if defined(IMAGEMAGICK_7)
3677
+ ExceptionInfo *exception;
3678
+ #endif
3363
3679
 
3364
3680
  image = rm_check_destroyed(self);
3365
3681
  composite_image = rm_check_destroyed(source);
@@ -3367,8 +3683,15 @@ Image_composite_affine(VALUE self, VALUE source, VALUE affine_matrix)
3367
3683
  Export_AffineMatrix(&affine, affine_matrix);
3368
3684
  new_image = rm_clone_image(image);
3369
3685
 
3686
+ #if defined(IMAGEMAGICK_7)
3687
+ exception = AcquireExceptionInfo();
3688
+ (void) DrawAffineImage(new_image, composite_image, &affine, exception);
3689
+ rm_check_exception(exception, new_image, DestroyOnError);
3690
+ (void) DestroyExceptionInfo(exception);
3691
+ #else
3370
3692
  (void) DrawAffineImage(new_image, composite_image, &affine);
3371
3693
  rm_check_image_exception(new_image, DestroyOnError);
3694
+ #endif
3372
3695
 
3373
3696
  return rm_image_new(new_image);
3374
3697
  }
@@ -3553,6 +3876,9 @@ composite_tiled(int bang, int argc, VALUE *argv, VALUE self)
3553
3876
  unsigned long columns;
3554
3877
  ChannelType channels;
3555
3878
  MagickStatusType status;
3879
+ #if defined(IMAGEMAGICK_7)
3880
+ ExceptionInfo *exception;
3881
+ #endif
3556
3882
 
3557
3883
  // Ensure image and composite_image aren't destroyed.
3558
3884
  if (bang)
@@ -3595,16 +3921,31 @@ composite_tiled(int bang, int argc, VALUE *argv, VALUE self)
3595
3921
  status = MagickTrue;
3596
3922
  columns = comp_image->columns;
3597
3923
 
3924
+ #if defined(IMAGEMAGICK_7)
3925
+ exception = AcquireExceptionInfo();
3926
+ #endif
3927
+
3598
3928
  // Tile
3599
3929
  for (y = 0; y < (long) image->rows; y += comp_image->rows)
3600
3930
  {
3601
3931
  for (x = 0; status == MagickTrue && x < (long) image->columns; x += columns)
3602
3932
  {
3933
+ #if defined(IMAGEMAGICK_7)
3934
+ BEGIN_CHANNEL_MASK(image, channels);
3935
+ status = CompositeImage(image, comp_image, MagickTrue, operator, x, y, exception);
3936
+ END_CHANNEL_MASK(image);
3937
+ rm_check_exception(exception, image, bang ? RetainOnError: DestroyOnError);
3938
+ #else
3603
3939
  status = CompositeImageChannel(image, channels, operator, comp_image, x, y);
3604
3940
  rm_check_image_exception(image, bang ? RetainOnError: DestroyOnError);
3941
+ #endif
3605
3942
  }
3606
3943
  }
3607
3944
 
3945
+ #if defined(IMAGEMAGICK_7)
3946
+ (void) DestroyExceptionInfo(exception);
3947
+ #endif
3948
+
3608
3949
  return bang ? self : rm_image_new(image);
3609
3950
  }
3610
3951
 
@@ -3706,10 +4047,21 @@ Image_compress_colormap_bang(VALUE self)
3706
4047
  {
3707
4048
  Image *image;
3708
4049
  MagickBooleanType okay;
4050
+ #if defined(IMAGEMAGICK_7)
4051
+ ExceptionInfo *exception;
4052
+ #endif
3709
4053
 
3710
4054
  image = rm_check_frozen(self);
4055
+
4056
+ #if defined(IMAGEMAGICK_7)
4057
+ exception = AcquireExceptionInfo();
4058
+ okay = CompressImageColormap(image, exception);
4059
+ CHECK_EXCEPTION()
4060
+ (void) DestroyExceptionInfo(exception);
4061
+ #else
3711
4062
  okay = CompressImageColormap(image);
3712
4063
  rm_check_image_exception(image, RetainOnError);
4064
+ #endif
3713
4065
  if (!okay)
3714
4066
  {
3715
4067
  rb_warning("CompressImageColormap failed (probably DirectClass image)");
@@ -3840,27 +4192,53 @@ Image_constitute(VALUE class ATTRIBUTE_UNUSED, VALUE width_arg, VALUE height_arg
3840
4192
  rb_raise(rb_eNoMemError, "not enough memory to continue.");
3841
4193
  }
3842
4194
 
4195
+ #if defined(IMAGEMAGICK_7)
4196
+ exception = AcquireExceptionInfo();
4197
+ SetImageExtent(new_image, width, height, exception);
4198
+ #else
3843
4199
  SetImageExtent(new_image, width, height);
3844
4200
  exception = &new_image->exception;
4201
+ #endif
4202
+
3845
4203
  if (rm_should_raise_exception(exception, RetainExceptionRetention))
3846
4204
  {
3847
4205
  xfree(pixels.v);
4206
+ #if defined(IMAGEMAGICK_7)
3848
4207
  (void) DestroyImage(new_image);
3849
4208
  rm_raise_exception(exception);
4209
+ #else
4210
+ rm_check_image_exception(new_image, DestroyOnError);
4211
+ #endif
3850
4212
  }
3851
4213
 
4214
+ #if defined(IMAGEMAGICK_7)
4215
+ (void) SetImageBackgroundColor(new_image, exception);
4216
+ #else
3852
4217
  (void) SetImageBackgroundColor(new_image);
3853
4218
  exception = &new_image->exception;
4219
+ #endif
4220
+
3854
4221
  if (rm_should_raise_exception(exception, RetainExceptionRetention))
3855
4222
  {
3856
4223
  xfree(pixels.v);
4224
+ #if defined(IMAGEMAGICK_7)
3857
4225
  (void) DestroyImage(new_image);
3858
4226
  rm_raise_exception(exception);
4227
+ #else
4228
+ rm_check_image_exception(new_image, DestroyOnError);
4229
+ #endif
3859
4230
  }
3860
4231
 
4232
+ #if defined(IMAGEMAGICK_7)
4233
+ (void) ImportImagePixels(new_image, 0, 0, width, height, map, stg_type, (const void *)pixels.v, exception);
4234
+ xfree(pixels.v);
4235
+ rm_check_exception(exception, new_image, DestroyOnError);
4236
+ (void) DestroyExceptionInfo(exception);
4237
+ #else
3861
4238
  (void) ImportImagePixels(new_image, 0, 0, width, height, map, stg_type, (const void *)pixels.v);
3862
4239
  xfree(pixels.v);
3863
4240
  rm_check_image_exception(new_image, DestroyOnError);
4241
+ #endif
3864
4242
 
3865
4243
  RB_GC_GUARD(pixel);
3866
4244
  RB_GC_GUARD(pixel0);
@@ -3891,6 +4269,9 @@ Image_contrast(int argc, VALUE *argv, VALUE self)
3891
4269
  {
3892
4270
  Image *image, *new_image;
3893
4271
  unsigned int sharpen = 0;
4272
+ #if defined(IMAGEMAGICK_7)
4273
+ ExceptionInfo *exception;
4274
+ #endif
3894
4275
 
3895
4276
  image = rm_check_destroyed(self);
3896
4277
  if (argc > 1)
@@ -3904,8 +4285,15 @@ Image_contrast(int argc, VALUE *argv, VALUE self)
3904
4285
 
3905
4286
  new_image = rm_clone_image(image);
3906
4287
 
4288
+ #if defined(IMAGEMAGICK_7)
4289
+ exception = AcquireExceptionInfo();
4290
+ (void) ContrastImage(new_image, sharpen, exception);
4291
+ rm_check_exception(exception, new_image, DestroyOnError);
4292
+ (void) DestroyExceptionInfo(exception);
4293
+ #else
3907
4294
  (void) ContrastImage(new_image, sharpen);
3908
4295
  rm_check_image_exception(new_image, DestroyOnError);
4296
+ #endif
3909
4297
 
3910
4298
  return rm_image_new(new_image);
3911
4299
  }
@@ -4001,6 +4389,9 @@ Image_contrast_stretch_channel(int argc, VALUE *argv, VALUE self)
4001
4389
  Image *image, *new_image;
4002
4390
  ChannelType channels;
4003
4391
  double black_point, white_point;
4392
+ #if defined(IMAGEMAGICK_7)
4393
+ ExceptionInfo *exception;
4394
+ #endif
4004
4395
 
4005
4396
  image = rm_check_destroyed(self);
4006
4397
  channels = extract_channels(&argc, argv);
@@ -4013,8 +4404,17 @@ Image_contrast_stretch_channel(int argc, VALUE *argv, VALUE self)
4013
4404
 
4014
4405
  new_image = rm_clone_image(image);
4015
4406
 
4407
+ #if defined(IMAGEMAGICK_7)
4408
+ exception = AcquireExceptionInfo();
4409
+ BEGIN_CHANNEL_MASK(new_image, channels);
4410
+ (void) ContrastStretchImage(new_image, black_point, white_point, exception);
4411
+ END_CHANNEL_MASK(new_image);
4412
+ CHECK_EXCEPTION()
4413
+ (void) DestroyExceptionInfo(exception);
4414
+ #else
4016
4415
  (void) ContrastStretchImageChannel(new_image, channels, black_point, white_point);
4017
4416
  rm_check_image_exception(new_image, DestroyOnError);
4417
+ #endif
4018
4418
 
4019
4419
  return rm_image_new(new_image);
4020
4420
  }
@@ -4090,7 +4490,14 @@ Image_morphology_channel(VALUE self, VALUE channel_v, VALUE method_v, VALUE iter
4090
4490
 
4091
4491
  exception = AcquireExceptionInfo();
4092
4492
 
4493
+ #if defined(IMAGEMAGICK_7)
4494
+ BEGIN_CHANNEL_MASK(image, channel);
4495
+ new_image = MorphologyImage(image, method, NUM2LONG(iterations), kernel, exception);
4496
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
4497
+ END_CHANNEL_MASK(image);
4498
+ #else
4093
4499
  new_image = MorphologyImageChannel(image, channel, method, NUM2LONG(iterations), kernel, exception);
4500
+ #endif
4094
4501
  rm_check_exception(exception, new_image, DestroyOnError);
4095
4502
  (void) DestroyExceptionInfo(exception);
4096
4503
 
@@ -4098,31 +4505,82 @@ Image_morphology_channel(VALUE self, VALUE channel_v, VALUE method_v, VALUE iter
4098
4505
  return rm_image_new(new_image);
4099
4506
  }
4100
4507
 
4101
- /**
4102
- * Apply a custom convolution kernel to the image.
4103
- *
4104
- * Ruby usage:
4105
- * - @verbatim Image#convolve(order, kernel) @endverbatim
4106
- *
4107
- * @param self this object
4108
- * @param order_arg the number of rows and columns in the kernel
4109
- * @param kernel_arg an order**2 array of doubles
4110
- * @return a new image
4111
- */
4112
- VALUE
4113
- Image_convolve(VALUE self, VALUE order_arg, VALUE kernel_arg)
4508
+ #if defined(IMAGEMAGICK_7)
4509
+ // TODO: Move this to KernelInfo class as a constructor?
4510
+ KernelInfo*
4511
+ convolve_create_kernel_info(unsigned int order, VALUE kernel_arg)
4114
4512
  {
4115
- Image *image, *new_image;
4116
- int order;
4117
- ExceptionInfo *exception;
4118
- double *kernel;
4119
4513
  unsigned int x;
4514
+ KernelInfo *kernel;
4515
+ ExceptionInfo *exception;
4120
4516
 
4121
- image = rm_check_destroyed(self);
4122
-
4123
- order = NUM2INT(order_arg);
4124
-
4125
- if (order <= 0)
4517
+ exception = AcquireExceptionInfo();
4518
+ kernel = AcquireKernelInfo((const char *) NULL, exception);
4519
+ CHECK_EXCEPTION()
4520
+ (void) DestroyExceptionInfo(exception);
4521
+ if (!kernel)
4522
+ {
4523
+ rb_raise(rb_eNoMemError, "not enough memory to initialize KernelInfo");
4524
+ }
4525
+
4526
+ kernel->width = order;
4527
+ kernel->height = order;
4528
+ kernel->x = (ssize_t)(order - 1) / 2;
4529
+ kernel->y = (ssize_t)(order - 1) / 2;
4530
+ kernel->values = (MagickRealType *) AcquireAlignedMemory(order, order*sizeof(*kernel->values));
4531
+ if (!kernel->values)
4532
+ {
4533
+ (void) DestroyKernelInfo(kernel);
4534
+ rb_raise(rb_eNoMemError, "not enough memory to initialize KernelInfo values");
4535
+ }
4536
+
4537
+ for (x = 0; x < order*order; x++)
4538
+ {
4539
+ VALUE element = rb_ary_entry(kernel_arg, (long)x);
4540
+ if (rm_check_num2dbl(element))
4541
+ {
4542
+ kernel->values[x] = NUM2DBL(element);
4543
+ }
4544
+ else
4545
+ {
4546
+ (void) DestroyKernelInfo(kernel);
4547
+ rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(element)));
4548
+ }
4549
+ }
4550
+
4551
+ return kernel;
4552
+ }
4553
+ #endif
4554
+
4555
+ /**
4556
+ * Apply a custom convolution kernel to the image.
4557
+ *
4558
+ * Ruby usage:
4559
+ * - @verbatim Image#convolve(order, kernel) @endverbatim
4560
+ *
4561
+ * @param self this object
4562
+ * @param order_arg the number of rows and columns in the kernel
4563
+ * @param kernel_arg an order**2 array of doubles
4564
+ * @return a new image
4565
+ */
4566
+ VALUE
4567
+ Image_convolve(VALUE self, VALUE order_arg, VALUE kernel_arg)
4568
+ {
4569
+ Image *image, *new_image;
4570
+ int order;
4571
+ ExceptionInfo *exception;
4572
+ #if defined(IMAGEMAGICK_7)
4573
+ KernelInfo *kernel;
4574
+ #else
4575
+ double *kernel;
4576
+ unsigned int x;
4577
+ #endif
4578
+
4579
+ image = rm_check_destroyed(self);
4580
+
4581
+ order = NUM2INT(order_arg);
4582
+
4583
+ if (order <= 0)
4126
4584
  {
4127
4585
  rb_raise(rb_eArgError, "order must be non-zero and positive");
4128
4586
  }
@@ -4130,6 +4588,9 @@ Image_convolve(VALUE self, VALUE order_arg, VALUE kernel_arg)
4130
4588
  kernel_arg = rb_Array(kernel_arg);
4131
4589
  rm_check_ary_len(kernel_arg, (long)(order*order));
4132
4590
 
4591
+ #if defined(IMAGEMAGICK_7)
4592
+ kernel = convolve_create_kernel_info(order, kernel_arg);
4593
+ #else
4133
4594
  // Convert the kernel array argument to an array of doubles
4134
4595
 
4135
4596
  kernel = (double *)ALLOC_N(double, order*order);
@@ -4146,11 +4607,18 @@ Image_convolve(VALUE self, VALUE order_arg, VALUE kernel_arg)
4146
4607
  rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(element)));
4147
4608
  }
4148
4609
  }
4610
+ #endif
4149
4611
 
4150
4612
  exception = AcquireExceptionInfo();
4151
4613
 
4614
+ #if defined(IMAGEMAGICK_7)
4615
+ new_image = ConvolveImage(image, kernel, exception);
4616
+ DestroyKernelInfo(kernel);
4617
+ #else
4152
4618
  new_image = ConvolveImage(image, order, kernel, exception);
4153
4619
  xfree((void *)kernel);
4620
+ #endif
4621
+
4154
4622
  rm_check_exception(exception, new_image, DestroyOnError);
4155
4623
 
4156
4624
  (void) DestroyExceptionInfo(exception);
@@ -4182,8 +4650,12 @@ Image_convolve_channel(int argc, VALUE *argv, VALUE self)
4182
4650
  int order;
4183
4651
  ChannelType channels;
4184
4652
  ExceptionInfo *exception;
4653
+ #if defined(IMAGEMAGICK_7)
4654
+ KernelInfo *kernel;
4655
+ #else
4185
4656
  double *kernel;
4186
4657
  unsigned int x;
4658
+ #endif
4187
4659
 
4188
4660
  image = rm_check_destroyed(self);
4189
4661
 
@@ -4209,6 +4681,9 @@ Image_convolve_channel(int argc, VALUE *argv, VALUE self)
4209
4681
 
4210
4682
  rm_check_ary_len(ary, (long)(order*order));
4211
4683
 
4684
+ #if defined(IMAGEMAGICK_7)
4685
+ kernel = convolve_create_kernel_info(order, ary);
4686
+ #else
4212
4687
  kernel = ALLOC_N(double, (long)(order*order));
4213
4688
 
4214
4689
  // Convert the kernel array argument to an array of doubles
@@ -4225,11 +4700,21 @@ Image_convolve_channel(int argc, VALUE *argv, VALUE self)
4225
4700
  rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(element)));
4226
4701
  }
4227
4702
  }
4703
+ #endif
4228
4704
 
4229
4705
  exception = AcquireExceptionInfo();
4230
4706
 
4707
+ #if defined(IMAGEMAGICK_7)
4708
+ BEGIN_CHANNEL_MASK(image, channels);
4709
+ new_image = ConvolveImage(image, kernel, exception);
4710
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
4711
+ END_CHANNEL_MASK(image);
4712
+ (void) DestroyKernelInfo(kernel);
4713
+ #else
4231
4714
  new_image = ConvolveImageChannel(image, channels, order, kernel, exception);
4232
4715
  xfree((void *)kernel);
4716
+ #endif
4717
+
4233
4718
  rm_check_exception(exception, new_image, DestroyOnError);
4234
4719
 
4235
4720
  (void) DestroyExceptionInfo(exception);
@@ -4344,14 +4829,24 @@ Image_cycle_colormap(VALUE self, VALUE amount)
4344
4829
  {
4345
4830
  Image *image, *new_image;
4346
4831
  int amt;
4832
+ #if defined(IMAGEMAGICK_7)
4833
+ ExceptionInfo *exception;
4834
+ #endif
4347
4835
 
4348
4836
  amt = NUM2INT(amount);
4349
4837
 
4350
4838
  image = rm_check_destroyed(self);
4351
4839
  new_image = rm_clone_image(image);
4352
4840
 
4841
+ #if defined(IMAGEMAGICK_7)
4842
+ exception = AcquireExceptionInfo();
4843
+ (void) CycleColormapImage(new_image, amt, exception);
4844
+ rm_check_exception(exception, new_image, DestroyOnError);
4845
+ (void) DestroyExceptionInfo(exception);
4846
+ #else
4353
4847
  (void) CycleColormapImage(new_image, amt);
4354
4848
  rm_check_image_exception(new_image, DestroyOnError);
4849
+ #endif
4355
4850
 
4356
4851
  return rm_image_new(new_image);
4357
4852
  }
@@ -4374,7 +4869,11 @@ Image_density(VALUE self)
4374
4869
 
4375
4870
  image = rm_check_destroyed(self);
4376
4871
 
4872
+ #if defined(IMAGEMAGICK_7)
4873
+ sprintf(density, "%gx%g", image->resolution.x, image->resolution.y);
4874
+ #else
4377
4875
  sprintf(density, "%gx%g", image->x_resolution, image->y_resolution);
4876
+ #endif
4378
4877
  return rb_str_new2(density);
4379
4878
  }
4380
4879
 
@@ -4426,8 +4925,13 @@ Image_density_eq(VALUE self, VALUE density_arg)
4426
4925
  {
4427
4926
  rb_raise(rb_eArgError, "invalid x resolution: %f", x_res);
4428
4927
  }
4928
+ #if defined(IMAGEMAGICK_7)
4929
+ image->resolution.y = y_res != 0.0 ? y_res : x_res;
4930
+ image->resolution.x = x_res;
4931
+ #else
4429
4932
  image->y_resolution = y_res != 0.0 ? y_res : x_res;
4430
4933
  image->x_resolution = x_res;
4934
+ #endif
4431
4935
  }
4432
4936
 
4433
4937
  // Convert the argument to a string
@@ -4439,10 +4943,18 @@ Image_density_eq(VALUE self, VALUE density_arg)
4439
4943
  rb_raise(rb_eArgError, "invalid density geometry %s", density);
4440
4944
  }
4441
4945
 
4946
+ #if defined(IMAGEMAGICK_7)
4947
+ count = sscanf(density, "%lfx%lf", &image->resolution.x, &image->resolution.y);
4948
+ #else
4442
4949
  count = sscanf(density, "%lfx%lf", &image->x_resolution, &image->y_resolution);
4950
+ #endif
4443
4951
  if (count < 2)
4444
4952
  {
4953
+ #if defined(IMAGEMAGICK_7)
4954
+ image->resolution.y = image->resolution.x;
4955
+ #else
4445
4956
  image->y_resolution = image->x_resolution;
4957
+ #endif
4446
4958
  }
4447
4959
 
4448
4960
  }
@@ -4557,12 +5069,21 @@ VALUE
4557
5069
  Image_delete_compose_mask(VALUE self)
4558
5070
  {
4559
5071
  Image *image;
5072
+ #if defined(IMAGEMAGICK_7)
5073
+ ExceptionInfo *exception;
5074
+ #endif
4560
5075
 
4561
5076
  image = rm_check_frozen(self);
4562
5077
 
4563
- // Store a clone of the mask image
5078
+ #if defined(IMAGEMAGICK_7)
5079
+ exception = AcquireExceptionInfo();
5080
+ (void) SetImageMask(image, CompositePixelMask, NULL, exception);
5081
+ CHECK_EXCEPTION()
5082
+ (void) DestroyExceptionInfo(exception);
5083
+ #else
4564
5084
  (void) SetImageMask(image, NULL);
4565
5085
  rm_check_image_exception(image, RetainOnError);
5086
+ #endif
4566
5087
 
4567
5088
  return self;
4568
5089
  }
@@ -4767,13 +5288,23 @@ Image_difference(VALUE self, VALUE other)
4767
5288
  Image *image;
4768
5289
  Image *image2;
4769
5290
  VALUE mean, nmean, nmax;
5291
+ #if defined(IMAGEMAGICK_7)
5292
+ ExceptionInfo *exception;
5293
+ #endif
4770
5294
 
4771
5295
  image = rm_check_destroyed(self);
4772
5296
  other = rm_cur_image(other);
4773
5297
  image2 = rm_check_destroyed(other);
4774
5298
 
5299
+ #if defined(IMAGEMAGICK_7)
5300
+ exception = AcquireExceptionInfo();
5301
+ (void) IsImagesEqual(image, image2, exception);
5302
+ CHECK_EXCEPTION()
5303
+ (void) DestroyExceptionInfo(exception);
5304
+ #else
4775
5305
  (void) IsImagesEqual(image, image2);
4776
5306
  rm_check_image_exception(image, RetainOnError);
5307
+ #endif
4777
5308
 
4778
5309
  mean = rb_float_new(image->error.mean_error_per_pixel);
4779
5310
  nmean = rb_float_new(image->error.normalized_mean_error);
@@ -4984,6 +5515,9 @@ Image_display(VALUE self)
4984
5515
  Image *image;
4985
5516
  Info *info;
4986
5517
  VALUE info_obj;
5518
+ #if defined(IMAGEMAGICK_7)
5519
+ ExceptionInfo *exception;
5520
+ #endif
4987
5521
 
4988
5522
  image = rm_check_destroyed(self);
4989
5523
 
@@ -4995,8 +5529,15 @@ Image_display(VALUE self)
4995
5529
  info_obj = rm_info_new();
4996
5530
  Data_Get_Struct(info_obj, Info, info);
4997
5531
 
5532
+ #if defined(IMAGEMAGICK_7)
5533
+ exception = AcquireExceptionInfo();
5534
+ (void) DisplayImages(info, image, exception);
5535
+ CHECK_EXCEPTION()
5536
+ (void) DestroyExceptionInfo(exception);
5537
+ #else
4998
5538
  (void) DisplayImages(info, image);
4999
5539
  rm_check_image_exception(image, RetainOnError);
5540
+ #endif
5000
5541
 
5001
5542
  RB_GC_GUARD(info_obj);
5002
5543
 
@@ -5215,6 +5756,9 @@ Image_distortion_channel(int argc, VALUE *argv, VALUE self)
5215
5756
  MetricType metric;
5216
5757
  VALUE rec;
5217
5758
  double distortion;
5759
+ #if defined(IMAGEMAGICK_7)
5760
+ Image *difference_image;
5761
+ #endif
5218
5762
 
5219
5763
  image = rm_check_destroyed(self);
5220
5764
  channels = extract_channels(&argc, argv);
@@ -5231,7 +5775,15 @@ Image_distortion_channel(int argc, VALUE *argv, VALUE self)
5231
5775
  reconstruct = rm_check_destroyed(rec);
5232
5776
  VALUE_TO_ENUM(argv[1], metric, MetricType);
5233
5777
  exception = AcquireExceptionInfo();
5778
+ #if defined(IMAGEMAGICK_7)
5779
+ BEGIN_CHANNEL_MASK(image, channels);
5780
+ difference_image = CompareImages(image, reconstruct, metric, &distortion, exception);
5781
+ END_CHANNEL_MASK(image);
5782
+ (void) DestroyImage(difference_image);
5783
+ #else
5234
5784
  (void) GetImageChannelDistortion(image, reconstruct, channels, metric, &distortion, exception);
5785
+ #endif
5786
+
5235
5787
  CHECK_EXCEPTION()
5236
5788
 
5237
5789
  (void) DestroyExceptionInfo(exception);
@@ -5631,16 +6183,22 @@ VALUE
5631
6183
  Image_equalize(VALUE self)
5632
6184
  {
5633
6185
  Image *image, *new_image;
6186
+ #if defined(IMAGEMAGICK_7)
5634
6187
  ExceptionInfo *exception;
6188
+ #endif
5635
6189
 
5636
6190
  image = rm_check_destroyed(self);
5637
- exception = AcquireExceptionInfo();
5638
6191
  new_image = rm_clone_image(image);
5639
6192
 
6193
+ #if defined(IMAGEMAGICK_7)
6194
+ exception = AcquireExceptionInfo();
6195
+ (void) EqualizeImage(new_image, exception);
6196
+ rm_check_exception(exception, new_image, DestroyOnError);
6197
+ (void) DestroyExceptionInfo(exception);
6198
+ #else
5640
6199
  (void) EqualizeImage(new_image);
5641
6200
  rm_check_image_exception(new_image, DestroyOnError);
5642
-
5643
- (void) DestroyExceptionInfo(exception);
6201
+ #endif
5644
6202
 
5645
6203
  return rm_image_new(new_image);
5646
6204
  }
@@ -5666,7 +6224,9 @@ VALUE
5666
6224
  Image_equalize_channel(int argc, VALUE *argv, VALUE self)
5667
6225
  {
5668
6226
  Image *image, *new_image;
6227
+ #if defined(IMAGEMAGICK_7)
5669
6228
  ExceptionInfo *exception;
6229
+ #endif
5670
6230
  ChannelType channels;
5671
6231
 
5672
6232
  image = rm_check_destroyed(self);
@@ -5678,12 +6238,18 @@ Image_equalize_channel(int argc, VALUE *argv, VALUE self)
5678
6238
 
5679
6239
  new_image = rm_clone_image(image);
5680
6240
 
6241
+ #if defined(IMAGEMAGICK_7)
5681
6242
  exception = AcquireExceptionInfo();
5682
-
6243
+ BEGIN_CHANNEL_MASK(new_image, channels);
6244
+ (void) EqualizeImage(new_image, exception);
6245
+ END_CHANNEL_MASK(new_image);
6246
+ rm_check_exception(exception, new_image, DestroyOnError);
6247
+ (void) DestroyExceptionInfo(exception);
6248
+ #else
5683
6249
  (void) EqualizeImageChannel(new_image, channels);
5684
6250
 
5685
6251
  rm_check_image_exception(new_image, DestroyOnError);
5686
- (void) DestroyExceptionInfo(exception);
6252
+ #endif
5687
6253
 
5688
6254
  return rm_image_new(new_image);
5689
6255
  }
@@ -5705,11 +6271,21 @@ VALUE
5705
6271
  Image_erase_bang(VALUE self)
5706
6272
  {
5707
6273
  Image *image;
6274
+ #if defined(IMAGEMAGICK_7)
6275
+ ExceptionInfo *exception;
6276
+ #endif
5708
6277
 
5709
6278
  image = rm_check_frozen(self);
5710
6279
 
6280
+ #if defined(IMAGEMAGICK_7)
6281
+ exception = AcquireExceptionInfo();
6282
+ (void) SetImageBackgroundColor(image, exception);
6283
+ CHECK_EXCEPTION()
6284
+ (void) DestroyExceptionInfo(exception);
6285
+ #else
5711
6286
  (void) SetImageBackgroundColor(image);
5712
6287
  rm_check_image_exception(image, RetainOnError);
6288
+ #endif
5713
6289
 
5714
6290
  return self;
5715
6291
  }
@@ -6263,7 +6839,7 @@ Image_find_similar_region(int argc, VALUE *argv, VALUE self)
6263
6839
  }
6264
6840
 
6265
6841
  exception = AcquireExceptionInfo();
6266
- okay = IsImageSimilar(image, target, &x, &y, exception);
6842
+ okay = IsEquivalentImage(image, target, &x, &y, exception);
6267
6843
  CHECK_EXCEPTION();
6268
6844
  (void) DestroyExceptionInfo(exception);
6269
6845
 
@@ -6561,7 +7137,11 @@ Image_frame(int argc, VALUE *argv, VALUE self)
6561
7137
  }
6562
7138
 
6563
7139
  exception = AcquireExceptionInfo();
7140
+ #if defined(IMAGEMAGICK_7)
7141
+ new_image = FrameImage(image, &frame_info, image->compose, exception);
7142
+ #else
6564
7143
  new_image = FrameImage(image, &frame_info, exception);
7144
+ #endif
6565
7145
  rm_check_exception(exception, new_image, DestroyOnError);
6566
7146
 
6567
7147
  (void) DestroyExceptionInfo(exception);
@@ -6692,7 +7272,13 @@ Image_function_channel(int argc, VALUE *argv, VALUE self)
6692
7272
 
6693
7273
  exception = AcquireExceptionInfo();
6694
7274
  new_image = rm_clone_image(image);
7275
+ #if defined(IMAGEMAGICK_7)
7276
+ BEGIN_CHANNEL_MASK(new_image, channels);
7277
+ (void) FunctionImage(new_image, function, nparms, parms, exception);
7278
+ END_CHANNEL_MASK(new_image);
7279
+ #else
6695
7280
  (void) FunctionImageChannel(new_image, channels, function, nparms, parms, exception);
7281
+ #endif
6696
7282
  (void) xfree(parms);
6697
7283
  rm_check_exception(exception, new_image, DestroyOnError);
6698
7284
  DestroyExceptionInfo(exception);
@@ -6775,7 +7361,14 @@ Image_fx(int argc, VALUE *argv, VALUE self)
6775
7361
  expression = StringValuePtr(argv[0]);
6776
7362
 
6777
7363
  exception = AcquireExceptionInfo();
7364
+ #if defined(IMAGEMAGICK_7)
7365
+ BEGIN_CHANNEL_MASK(image, channels);
7366
+ new_image = FxImage(image, expression, exception);
7367
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
7368
+ END_CHANNEL_MASK(image);
7369
+ #else
6778
7370
  new_image = FxImageChannel(image, channels, expression, exception);
7371
+ #endif
6779
7372
  rm_check_exception(exception, new_image, DestroyOnError);
6780
7373
  (void) DestroyExceptionInfo(exception);
6781
7374
 
@@ -6810,6 +7403,9 @@ Image_gamma_channel(int argc, VALUE *argv, VALUE self)
6810
7403
  Image *image, *new_image;
6811
7404
  ChannelType channels;
6812
7405
  double gamma;
7406
+ #if defined(IMAGEMAGICK_7)
7407
+ ExceptionInfo *exception;
7408
+ #endif
6813
7409
 
6814
7410
  image = rm_check_destroyed(self);
6815
7411
  channels = extract_channels(&argc, argv);
@@ -6827,8 +7423,17 @@ Image_gamma_channel(int argc, VALUE *argv, VALUE self)
6827
7423
  gamma = NUM2DBL(argv[0]);
6828
7424
  new_image = rm_clone_image(image);
6829
7425
 
7426
+ #if defined(IMAGEMAGICK_7)
7427
+ exception = AcquireExceptionInfo();
7428
+ BEGIN_CHANNEL_MASK(new_image, channels);
7429
+ (void) GammaImage(new_image, gamma, exception);
7430
+ END_CHANNEL_MASK(new_image);
7431
+ rm_check_exception(exception, new_image, DestroyOnError);
7432
+ (void) DestroyExceptionInfo(exception);
7433
+ #else
6830
7434
  (void) GammaImageChannel(new_image, channels, gamma);
6831
7435
  rm_check_image_exception(new_image, DestroyOnError);
7436
+ #endif
6832
7437
 
6833
7438
  return rm_image_new(new_image);
6834
7439
  }
@@ -6857,6 +7462,9 @@ Image_gamma_correct(int argc, VALUE *argv, VALUE self)
6857
7462
  {
6858
7463
  Image *image, *new_image;
6859
7464
  double red_gamma, green_gamma, blue_gamma;
7465
+ #if defined(IMAGEMAGICK_7)
7466
+ ExceptionInfo *exception;
7467
+ #endif
6860
7468
 
6861
7469
  image = rm_check_destroyed(self);
6862
7470
  switch (argc)
@@ -6883,18 +7491,47 @@ Image_gamma_correct(int argc, VALUE *argv, VALUE self)
6883
7491
 
6884
7492
  new_image = rm_clone_image(image);
6885
7493
 
7494
+ #if defined(IMAGEMAGICK_7)
7495
+ exception = AcquireExceptionInfo();
7496
+ #endif
7497
+
6886
7498
  if ((red_gamma == green_gamma) && (green_gamma == blue_gamma))
6887
7499
  {
7500
+ #if defined(IMAGEMAGICK_7)
7501
+ BEGIN_CHANNEL_MASK(new_image, (ChannelType) (RedChannel | GreenChannel | BlueChannel));
7502
+ (void) GammaImage(new_image, red_gamma, exception);
7503
+ END_CHANNEL_MASK(new_image);
7504
+ #else
6888
7505
  (void) GammaImageChannel(new_image, (ChannelType) (RedChannel | GreenChannel | BlueChannel), red_gamma);
7506
+ #endif
6889
7507
  }
6890
7508
  else
6891
7509
  {
7510
+ #if defined(IMAGEMAGICK_7)
7511
+ BEGIN_CHANNEL_MASK(new_image, RedChannel);
7512
+ (void) GammaImage(new_image, red_gamma, exception);
7513
+ END_CHANNEL_MASK(new_image);
7514
+
7515
+ BEGIN_CHANNEL_MASK(new_image, GreenChannel);
7516
+ (void) GammaImage(new_image, green_gamma, exception);
7517
+ END_CHANNEL_MASK(new_image);
7518
+
7519
+ BEGIN_CHANNEL_MASK(new_image, BlueChannel);
7520
+ (void) GammaImage(new_image, blue_gamma, exception);
7521
+ END_CHANNEL_MASK(new_image);
7522
+ #else
6892
7523
  (void) GammaImageChannel(new_image, RedChannel, red_gamma);
6893
7524
  (void) GammaImageChannel(new_image, GreenChannel, green_gamma);
6894
7525
  (void) GammaImageChannel(new_image, BlueChannel, blue_gamma);
7526
+ #endif
6895
7527
  }
6896
7528
 
7529
+ #if defined(IMAGEMAGICK_7)
7530
+ CHECK_EXCEPTION()
7531
+ (void) DestroyExceptionInfo(exception);
7532
+ #else
6897
7533
  rm_check_image_exception(new_image, DestroyOnError);
7534
+ #endif
6898
7535
 
6899
7536
  return rm_image_new(new_image);
6900
7537
  }
@@ -6969,8 +7606,16 @@ Image_gaussian_blur_channel(int argc, VALUE *argv, VALUE self)
6969
7606
  }
6970
7607
 
6971
7608
  exception = AcquireExceptionInfo();
7609
+ #if defined(IMAGEMAGICK_7)
7610
+ BEGIN_CHANNEL_MASK(image, channels);
7611
+ new_image = GaussianBlurImage(image, radius, sigma, exception);
7612
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
7613
+ END_CHANNEL_MASK(image);
7614
+ rm_check_exception(exception, new_image, DestroyOnError);
7615
+ #else
6972
7616
  new_image = GaussianBlurImageChannel(image, channels, radius, sigma, exception);
6973
7617
  rm_check_exception(exception, new_image, DestroyOnError);
7618
+ #endif
6974
7619
 
6975
7620
  (void) DestroyExceptionInfo(exception);
6976
7621
 
@@ -7060,7 +7705,11 @@ Image_get_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg, VALUE row
7060
7705
  unsigned long columns, rows;
7061
7706
  long size, n;
7062
7707
  VALUE pixel_ary;
7708
+ #if defined(IMAGEMAGICK_7)
7709
+ const Quantum *pixels;
7710
+ #else
7063
7711
  const PixelPacket *pixels;
7712
+ #endif
7064
7713
 
7065
7714
  image = rm_check_destroyed(self);
7066
7715
  x = NUM2LONG(x_arg);
@@ -7095,7 +7744,19 @@ Image_get_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg, VALUE row
7095
7744
  // Convert the PixelPackets to Magick::Pixel objects
7096
7745
  for (n = 0; n < size; n++)
7097
7746
  {
7747
+ #if defined(IMAGEMAGICK_7)
7748
+ PixelPacket color;
7749
+ memset(&color, 0, sizeof(color));
7750
+ color.red = GetPixelRed(image, pixels);
7751
+ color.green = GetPixelGreen(image, pixels);
7752
+ color.blue = GetPixelBlue(image, pixels);
7753
+ color.alpha = GetPixelAlpha(image, pixels);
7754
+ rb_ary_store(pixel_ary, n, Pixel_from_PixelPacket(&color));
7755
+
7756
+ pixels += GetPixelChannels(image);
7757
+ #else
7098
7758
  rb_ary_store(pixel_ary, n, Pixel_from_PixelPacket(&pixels[n]));
7759
+ #endif
7099
7760
  }
7100
7761
 
7101
7762
  return pixel_ary;
@@ -7129,6 +7790,30 @@ has_attribute(VALUE self, MagickBooleanType (attr_test)(const Image *, Exception
7129
7790
  }
7130
7791
 
7131
7792
 
7793
+ #if defined(IMAGEMAGICK_7)
7794
+ /**
7795
+ * Run a function testing whether this image has an attribute.
7796
+ *
7797
+ * No Ruby usage (internal function)
7798
+ *
7799
+ * @param self this object
7800
+ * @param attr_test the attribute testing function
7801
+ * @return the result of attr_test.
7802
+ */
7803
+ static VALUE
7804
+ has_image_attribute(VALUE self, MagickBooleanType (attr_test)(const Image *))
7805
+ {
7806
+ Image *image;
7807
+ MagickBooleanType r;
7808
+
7809
+ image = rm_check_destroyed(self);
7810
+ r = (attr_test)(image);
7811
+
7812
+ return r ? Qtrue : Qfalse;
7813
+ }
7814
+ #endif
7815
+
7816
+
7132
7817
  /**
7133
7818
  * Return true if all the pixels in the image have the same red, green, and blue
7134
7819
  * intensities.
@@ -7222,7 +7907,11 @@ Image_implode(int argc, VALUE *argv, VALUE self)
7222
7907
  image = rm_check_destroyed(self);
7223
7908
  exception = AcquireExceptionInfo();
7224
7909
 
7910
+ #if defined(IMAGEMAGICK_7)
7911
+ new_image = ImplodeImage(image, amount, image->interpolate, exception);
7912
+ #else
7225
7913
  new_image = ImplodeImage(image, amount, exception);
7914
+ #endif
7226
7915
  rm_check_exception(exception, new_image, DestroyOnError);
7227
7916
  (void) DestroyExceptionInfo(exception);
7228
7917
 
@@ -7260,6 +7949,9 @@ Image_import_pixels(int argc, VALUE *argv, VALUE self)
7260
7949
  double *fpixels = NULL;
7261
7950
  void *buffer;
7262
7951
  unsigned int okay;
7952
+ #if defined(IMAGEMAGICK_7)
7953
+ ExceptionInfo *exception;
7954
+ #endif
7263
7955
 
7264
7956
  image = rm_check_frozen(self);
7265
7957
 
@@ -7391,7 +8083,12 @@ Image_import_pixels(int argc, VALUE *argv, VALUE self)
7391
8083
  }
7392
8084
 
7393
8085
 
8086
+ #if defined(IMAGEMAGICK_7)
8087
+ exception = AcquireExceptionInfo();
8088
+ okay = ImportImagePixels(image, x_off, y_off, cols, rows, map, stg_type, buffer, exception);
8089
+ #else
7394
8090
  okay = ImportImagePixels(image, x_off, y_off, cols, rows, map, stg_type, buffer);
8091
+ #endif
7395
8092
 
7396
8093
  // Free pixel array before checking for errors.
7397
8094
  if (pixels)
@@ -7405,10 +8102,18 @@ Image_import_pixels(int argc, VALUE *argv, VALUE self)
7405
8102
 
7406
8103
  if (!okay)
7407
8104
  {
8105
+ #if defined(IMAGEMAGICK_7)
8106
+ CHECK_EXCEPTION()
8107
+ (void) DestroyExceptionInfo(exception);
8108
+ #else
7408
8109
  rm_check_image_exception(image, RetainOnError);
8110
+ #endif
7409
8111
  // Shouldn't get here...
7410
8112
  rm_magick_error("ImportImagePixels failed with no explanation.");
7411
8113
  }
8114
+ #if defined(IMAGEMAGICK_7)
8115
+ (void) DestroyExceptionInfo(exception);
8116
+ #endif
7412
8117
 
7413
8118
  RB_GC_GUARD(pixel_arg);
7414
8119
  RB_GC_GUARD(pixel_ary);
@@ -7709,7 +8414,11 @@ Image_level2(int argc, VALUE *argv, VALUE self)
7709
8414
  {
7710
8415
  Image *image, *new_image;
7711
8416
  double black_point = 0.0, gamma_val = 1.0, white_point = (double)QuantumRange;
8417
+ #if defined(IMAGEMAGICK_7)
8418
+ ExceptionInfo *exception;
8419
+ #else
7712
8420
  char level[50];
8421
+ #endif
7713
8422
 
7714
8423
  image = rm_check_destroyed(self);
7715
8424
  switch (argc)
@@ -7736,9 +8445,16 @@ Image_level2(int argc, VALUE *argv, VALUE self)
7736
8445
 
7737
8446
  new_image = rm_clone_image(image);
7738
8447
 
8448
+ #if defined(IMAGEMAGICK_7)
8449
+ exception = AcquireExceptionInfo();
8450
+ (void) LevelImage(new_image, black_point, white_point, gamma_val, exception);
8451
+ rm_check_exception(exception, new_image, DestroyOnError);
8452
+ (void) DestroyExceptionInfo(exception);
8453
+ #else
7739
8454
  sprintf(level, "%gx%g+%g", black_point, white_point, gamma_val);
7740
8455
  (void) LevelImage(new_image, level);
7741
8456
  rm_check_image_exception(new_image, DestroyOnError);
8457
+ #endif
7742
8458
 
7743
8459
  return rm_image_new(new_image);
7744
8460
  }
@@ -7770,6 +8486,9 @@ Image_level_channel(int argc, VALUE *argv, VALUE self)
7770
8486
  Image *image, *new_image;
7771
8487
  double black_point = 0.0, gamma_val = 1.0, white_point = (double)QuantumRange;
7772
8488
  ChannelType channel;
8489
+ #if defined(IMAGEMAGICK_7)
8490
+ ExceptionInfo *exception;
8491
+ #endif
7773
8492
 
7774
8493
  image = rm_check_destroyed(self);
7775
8494
  switch (argc)
@@ -7798,8 +8517,17 @@ Image_level_channel(int argc, VALUE *argv, VALUE self)
7798
8517
 
7799
8518
  new_image = rm_clone_image(image);
7800
8519
 
8520
+ #if defined(IMAGEMAGICK_7)
8521
+ exception = AcquireExceptionInfo();
8522
+ BEGIN_CHANNEL_MASK(new_image, channel);
8523
+ (void) LevelImage(new_image, black_point, white_point, gamma_val, exception);
8524
+ END_CHANNEL_MASK(new_image);
8525
+ rm_check_exception(exception, new_image, DestroyOnError);
8526
+ (void) DestroyExceptionInfo(exception);
8527
+ #else
7801
8528
  (void) LevelImageChannel(new_image, channel, black_point, white_point, gamma_val);
7802
8529
  rm_check_image_exception(new_image, DestroyOnError);
8530
+ #endif
7803
8531
 
7804
8532
  return rm_image_new(new_image);
7805
8533
  }
@@ -7835,6 +8563,9 @@ Image_level_colors(int argc, VALUE *argv, VALUE self)
7835
8563
  ChannelType channels;
7836
8564
  MagickBooleanType invert = MagickTrue;
7837
8565
  MagickBooleanType status;
8566
+ #if defined(IMAGEMAGICK_7)
8567
+ ExceptionInfo *exception;
8568
+ #endif
7838
8569
 
7839
8570
  image = rm_check_destroyed(self);
7840
8571
 
@@ -7870,8 +8601,17 @@ Image_level_colors(int argc, VALUE *argv, VALUE self)
7870
8601
 
7871
8602
  new_image = rm_clone_image(image);
7872
8603
 
8604
+ #if defined(IMAGEMAGICK_7)
8605
+ exception = AcquireExceptionInfo();
8606
+ BEGIN_CHANNEL_MASK(new_image, channels);
8607
+ status = LevelImageColors(new_image, &black_color, &white_color, invert, exception);
8608
+ END_CHANNEL_MASK(new_image);
8609
+ rm_check_exception(exception, new_image, DestroyOnError);
8610
+ (void) DestroyExceptionInfo(exception);
8611
+ #else
7873
8612
  status = LevelColorsImageChannel(new_image, channels, &black_color, &white_color, invert);
7874
8613
  rm_check_image_exception(new_image, DestroyOnError);
8614
+ #endif
7875
8615
  if (!status)
7876
8616
  {
7877
8617
  rb_raise(rb_eRuntimeError, "LevelImageColors failed for unknown reason.");
@@ -7910,6 +8650,9 @@ Image_levelize_channel(int argc, VALUE *argv, VALUE self)
7910
8650
  double black_point, white_point;
7911
8651
  double gamma = 1.0;
7912
8652
  MagickBooleanType status;
8653
+ #if defined(IMAGEMAGICK_7)
8654
+ ExceptionInfo *exception;
8655
+ #endif
7913
8656
 
7914
8657
  image = rm_check_destroyed(self);
7915
8658
  channels = extract_channels(&argc, argv);
@@ -7936,8 +8679,18 @@ Image_levelize_channel(int argc, VALUE *argv, VALUE self)
7936
8679
  }
7937
8680
 
7938
8681
  new_image = rm_clone_image(image);
8682
+
8683
+ #if defined(IMAGEMAGICK_7)
8684
+ exception = AcquireExceptionInfo();
8685
+ BEGIN_CHANNEL_MASK(new_image, channels);
8686
+ status = LevelizeImage(new_image, black_point, white_point, gamma, exception);
8687
+ END_CHANNEL_MASK(new_image);
8688
+ rm_check_exception(exception, new_image, DestroyOnError);
8689
+ (void) DestroyExceptionInfo(exception);
8690
+ #else
7939
8691
  status = LevelizeImageChannel(new_image, channels, black_point, white_point, gamma);
7940
8692
  rm_check_image_exception(new_image, DestroyOnError);
8693
+ #endif
7941
8694
 
7942
8695
  if (!status)
7943
8696
  {
@@ -7969,13 +8722,23 @@ Image_linear_stretch(int argc, VALUE *argv, VALUE self)
7969
8722
  {
7970
8723
  Image *image, *new_image;
7971
8724
  double black_point, white_point;
8725
+ #if defined(IMAGEMAGICK_7)
8726
+ ExceptionInfo *exception;
8727
+ #endif
7972
8728
 
7973
8729
  image = rm_check_destroyed(self);
7974
8730
  get_black_white_point(image, argc, argv, &black_point, &white_point);
7975
8731
  new_image = rm_clone_image(image);
7976
8732
 
8733
+ #if defined(IMAGEMAGICK_7)
8734
+ exception = AcquireExceptionInfo();
8735
+ (void) LinearStretchImage(new_image, black_point, white_point, exception);
8736
+ rm_check_exception(exception, new_image, DestroyOnError);
8737
+ (void) DestroyExceptionInfo(exception);
8738
+ #else
7977
8739
  (void) LinearStretchImage(new_image, black_point, white_point);
7978
8740
  rm_check_image_exception(new_image, DestroyOnError);
8741
+ #endif
7979
8742
 
7980
8743
  return rm_image_new(new_image);
7981
8744
  }
@@ -8279,7 +9042,6 @@ Image_marshal_load(VALUE self, VALUE ary)
8279
9042
  return self;
8280
9043
  }
8281
9044
 
8282
-
8283
9045
  /**
8284
9046
  * Return the image's clip mask, or nil if it doesn't have a clip mask.
8285
9047
  *
@@ -8300,7 +9062,11 @@ get_image_mask(Image *image)
8300
9062
  exception = AcquireExceptionInfo();
8301
9063
 
8302
9064
  // The returned clip mask is a clone, ours to keep.
9065
+ #if defined(IMAGEMAGICK_7)
9066
+ mask = GetImageMask(image, WritePixelMask, exception);
9067
+ #else
8303
9068
  mask = GetImageClipMask(image, exception);
9069
+ #endif
8304
9070
  rm_check_exception(exception, mask, DestroyOnError);
8305
9071
 
8306
9072
  (void) DestroyExceptionInfo(exception);
@@ -8309,14 +9075,55 @@ get_image_mask(Image *image)
8309
9075
  }
8310
9076
 
8311
9077
  /**
8312
- * Sets the image's clip mask, or removes it when mask is nil.
9078
+ * Associate a mask with the image.
8313
9079
  *
8314
9080
  * No Ruby usage (internal function)
8315
9081
  *
8316
9082
  * @param image the image
8317
9083
  * @param mask the mask
8318
9084
  * @return copy of the current clip-mask or nil
9085
+ * @see get_image_mask
8319
9086
  */
9087
+ #if defined(IMAGEMAGICK_7)
9088
+ static VALUE
9089
+ set_image_mask(Image *image, VALUE mask)
9090
+ {
9091
+ Image *mask_image, *resized_image;
9092
+ Image *clip_mask;
9093
+ ExceptionInfo *exception;
9094
+
9095
+ exception = AcquireExceptionInfo();
9096
+
9097
+ if (mask != Qnil)
9098
+ {
9099
+ mask = rm_cur_image(mask);
9100
+ mask_image = rm_check_destroyed(mask);
9101
+ clip_mask = rm_clone_image(mask_image);
9102
+
9103
+ // Resize if necessary
9104
+ if (clip_mask->columns != image->columns || clip_mask->rows != image->rows)
9105
+ {
9106
+ resized_image = ResizeImage(clip_mask, image->columns, image->rows, image->filter, exception);
9107
+ (void) DestroyImage(clip_mask);
9108
+ rm_check_exception(exception, resized_image, DestroyOnError);
9109
+ rm_ensure_result(resized_image);
9110
+ clip_mask = resized_image;
9111
+ }
9112
+
9113
+ (void) SetImageMask(image, WritePixelMask, clip_mask, exception);
9114
+ (void) DestroyImage(clip_mask);
9115
+ }
9116
+ else
9117
+ {
9118
+ (void) SetImageMask(image, WritePixelMask, NULL, exception);
9119
+ }
9120
+ CHECK_EXCEPTION()
9121
+ (void) DestroyExceptionInfo(exception);
9122
+
9123
+ // Always return a copy of the mask!
9124
+ return get_image_mask(image);
9125
+ }
9126
+ #else
8320
9127
  static VALUE
8321
9128
  set_image_mask(Image *image, VALUE mask)
8322
9129
  {
@@ -8395,6 +9202,7 @@ set_image_mask(Image *image, VALUE mask)
8395
9202
  // Always return a copy of the mask!
8396
9203
  return get_image_mask(image);
8397
9204
  }
9205
+ #endif
8398
9206
 
8399
9207
 
8400
9208
  /**
@@ -8435,8 +9243,6 @@ Image_mask(int argc, VALUE *argv, VALUE self)
8435
9243
 
8436
9244
  rb_check_frozen(self);
8437
9245
  mask = argv[0];
8438
-
8439
- // Always return a copy of the mask!
8440
9246
  return set_image_mask(image, mask);
8441
9247
  }
8442
9248
 
@@ -8501,6 +9307,9 @@ Image_matte_flood_fill(int argc, VALUE *argv, VALUE self)
8501
9307
  DrawInfo *draw_info;
8502
9308
  MagickPixel target_mpp;
8503
9309
  MagickBooleanType invert;
9310
+ #if defined(IMAGEMAGICK_7)
9311
+ ExceptionInfo *exception;
9312
+ #endif
8504
9313
 
8505
9314
  image = rm_check_destroyed(self);
8506
9315
 
@@ -8535,7 +9344,11 @@ Image_matte_flood_fill(int argc, VALUE *argv, VALUE self)
8535
9344
  {
8536
9345
  rb_raise(rb_eNoMemError, "not enough memory to continue");
8537
9346
  }
9347
+ #if defined(IMAGEMAGICK_7)
9348
+ draw_info->fill.alpha = alpha;
9349
+ #else
8538
9350
  draw_info->fill.opacity = QuantumRange - alpha;
9351
+ #endif
8539
9352
 
8540
9353
  if (method == FillToBorderMethod)
8541
9354
  {
@@ -8552,10 +9365,20 @@ Image_matte_flood_fill(int argc, VALUE *argv, VALUE self)
8552
9365
  target_mpp.blue = (MagickRealType) target.blue;
8553
9366
  }
8554
9367
 
9368
+ #if defined(IMAGEMAGICK_7)
9369
+ exception = AcquireExceptionInfo();
9370
+ BEGIN_CHANNEL_MASK(new_image, OpacityChannel);
9371
+ (void) FloodfillPaintImage(new_image, draw_info, &target_mpp, x, y, invert, exception);
9372
+ END_CHANNEL_MASK(new_image);
9373
+ (void) DestroyDrawInfo(draw_info);
9374
+ rm_check_exception(exception, new_image, DestroyOnError);
9375
+ (void) DestroyExceptionInfo(exception);
9376
+ #else
8555
9377
  (void) FloodfillPaintImage(new_image, OpacityChannel, draw_info, &target_mpp, x, y, invert);
8556
9378
  (void) DestroyDrawInfo(draw_info);
8557
9379
 
8558
9380
  rm_check_image_exception(new_image, DestroyOnError);
9381
+ #endif
8559
9382
 
8560
9383
  return rm_image_new(new_image);
8561
9384
  }
@@ -8720,6 +9543,9 @@ Image_modulate(int argc, VALUE *argv, VALUE self)
8720
9543
  pct_saturation = 100.0,
8721
9544
  pct_hue = 100.0;
8722
9545
  char modulate[100];
9546
+ #if defined(IMAGEMAGICK_7)
9547
+ ExceptionInfo *exception;
9548
+ #endif
8723
9549
 
8724
9550
  image = rm_check_destroyed(self);
8725
9551
  switch (argc)
@@ -8746,8 +9572,15 @@ Image_modulate(int argc, VALUE *argv, VALUE self)
8746
9572
 
8747
9573
  new_image = rm_clone_image(image);
8748
9574
 
9575
+ #if defined(IMAGEMAGICK_7)
9576
+ exception = AcquireExceptionInfo();
9577
+ (void) ModulateImage(new_image, modulate, exception);
9578
+ rm_check_exception(exception, new_image, DestroyOnError);
9579
+ (void) DestroyExceptionInfo(exception);
9580
+ #else
8749
9581
  (void) ModulateImage(new_image, modulate);
8750
9582
  rm_check_image_exception(new_image, DestroyOnError);
9583
+ #endif
8751
9584
 
8752
9585
  return rm_image_new(new_image);
8753
9586
  }
@@ -8799,7 +9632,11 @@ Image_monitor_eq(VALUE self, VALUE monitor)
8799
9632
  VALUE
8800
9633
  Image_monochrome_q(VALUE self)
8801
9634
  {
9635
+ #if defined(IMAGEMAGICK_7)
9636
+ return has_image_attribute(self, IsImageMonochrome);
9637
+ #else
8802
9638
  return has_attribute(self, IsMonochromeImage);
9639
+ #endif
8803
9640
  }
8804
9641
 
8805
9642
 
@@ -8923,6 +9760,9 @@ Image_negate(int argc, VALUE *argv, VALUE self)
8923
9760
  {
8924
9761
  Image *image, *new_image;
8925
9762
  unsigned int grayscale = MagickFalse;
9763
+ #if defined(IMAGEMAGICK_7)
9764
+ ExceptionInfo *exception;
9765
+ #endif
8926
9766
 
8927
9767
  image = rm_check_destroyed(self);
8928
9768
  if (argc == 1)
@@ -8936,8 +9776,15 @@ Image_negate(int argc, VALUE *argv, VALUE self)
8936
9776
 
8937
9777
  new_image = rm_clone_image(image);
8938
9778
 
9779
+ #if defined(IMAGEMAGICK_7)
9780
+ exception = AcquireExceptionInfo();
9781
+ (void) NegateImage(new_image, grayscale, exception);
9782
+ rm_check_exception(exception, new_image, DestroyOnError);
9783
+ (void) DestroyExceptionInfo(exception);
9784
+ #else
8939
9785
  (void) NegateImage(new_image, grayscale);
8940
9786
  rm_check_image_exception(new_image, DestroyOnError);
9787
+ #endif
8941
9788
 
8942
9789
  return rm_image_new(new_image);
8943
9790
  }
@@ -8971,6 +9818,9 @@ Image_negate_channel(int argc, VALUE *argv, VALUE self)
8971
9818
  Image *image, *new_image;
8972
9819
  ChannelType channels;
8973
9820
  unsigned int grayscale = MagickFalse;
9821
+ #if defined(IMAGEMAGICK_7)
9822
+ ExceptionInfo *exception;
9823
+ #endif
8974
9824
 
8975
9825
  image = rm_check_destroyed(self);
8976
9826
  channels = extract_channels(&argc, argv);
@@ -8987,8 +9837,17 @@ Image_negate_channel(int argc, VALUE *argv, VALUE self)
8987
9837
 
8988
9838
  new_image = rm_clone_image(image);
8989
9839
 
9840
+ #if defined(IMAGEMAGICK_7)
9841
+ exception = AcquireExceptionInfo();
9842
+ BEGIN_CHANNEL_MASK(image, channels);
9843
+ (void) NegateImage(new_image, grayscale, exception);
9844
+ END_CHANNEL_MASK(image);
9845
+ rm_check_exception(exception, new_image, DestroyOnError);
9846
+ (void) DestroyExceptionInfo(exception);
9847
+ #else
8990
9848
  (void) NegateImageChannel(new_image, channels, grayscale);
8991
9849
  rm_check_image_exception(new_image, DestroyOnError);
9850
+ #endif
8992
9851
 
8993
9852
  return rm_image_new(new_image);
8994
9853
  }
@@ -9042,6 +9901,9 @@ Image_initialize(int argc, VALUE *argv, VALUE self)
9042
9901
  VALUE info_obj;
9043
9902
  Image *image;
9044
9903
  unsigned long cols, rows;
9904
+ #if defined(IMAGEMAGICK_7)
9905
+ ExceptionInfo *exception;
9906
+ #endif
9045
9907
 
9046
9908
  switch (argc)
9047
9909
  {
@@ -9071,14 +9933,28 @@ Image_initialize(int argc, VALUE *argv, VALUE self)
9071
9933
  // NOW store a real image in the image object.
9072
9934
  UPDATE_DATA_PTR(self, image);
9073
9935
 
9936
+ #if defined(IMAGEMAGICK_7)
9937
+ exception = AcquireExceptionInfo();
9938
+ SetImageExtent(image, cols, rows, exception);
9939
+ CHECK_EXCEPTION()
9940
+ (void) DestroyExceptionInfo(exception);
9941
+ #else
9074
9942
  SetImageExtent(image, cols, rows);
9943
+ #endif
9075
9944
 
9076
9945
  // If the caller did not supply a fill argument, call SetImageBackgroundColor
9077
9946
  // to fill the image using the background color. The background color can
9078
9947
  // be set by specifying it when creating the Info parm block.
9079
9948
  if (!fill)
9080
9949
  {
9950
+ #if defined(IMAGEMAGICK_7)
9951
+ exception = AcquireExceptionInfo();
9952
+ (void) SetImageBackgroundColor(image, exception);
9953
+ CHECK_EXCEPTION()
9954
+ (void) DestroyExceptionInfo(exception);
9955
+ #else
9081
9956
  (void) SetImageBackgroundColor(image);
9957
+ #endif
9082
9958
  }
9083
9959
  // fillobj.fill(self)
9084
9960
  else
@@ -9133,12 +10009,22 @@ VALUE
9133
10009
  Image_normalize(VALUE self)
9134
10010
  {
9135
10011
  Image *image, *new_image;
10012
+ #if defined(IMAGEMAGICK_7)
10013
+ ExceptionInfo *exception;
10014
+ #endif
9136
10015
 
9137
10016
  image = rm_check_destroyed(self);
9138
10017
  new_image = rm_clone_image(image);
9139
10018
 
10019
+ #if defined(IMAGEMAGICK_7)
10020
+ exception = AcquireExceptionInfo();
10021
+ (void) NormalizeImage(new_image, exception);
10022
+ rm_check_exception(exception, new_image, DestroyOnError);
10023
+ (void) DestroyExceptionInfo(exception);
10024
+ #else
9140
10025
  (void) NormalizeImage(new_image);
9141
10026
  rm_check_image_exception(new_image, DestroyOnError);
10027
+ #endif
9142
10028
 
9143
10029
  return rm_image_new(new_image);
9144
10030
  }
@@ -9164,6 +10050,9 @@ Image_normalize_channel(int argc, VALUE *argv, VALUE self)
9164
10050
  {
9165
10051
  Image *image, *new_image;
9166
10052
  ChannelType channels;
10053
+ #if defined(IMAGEMAGICK_7)
10054
+ ExceptionInfo *exception;
10055
+ #endif
9167
10056
 
9168
10057
  image = rm_check_destroyed(self);
9169
10058
  channels = extract_channels(&argc, argv);
@@ -9175,8 +10064,17 @@ Image_normalize_channel(int argc, VALUE *argv, VALUE self)
9175
10064
 
9176
10065
  new_image = rm_clone_image(image);
9177
10066
 
10067
+ #if defined(IMAGEMAGICK_7)
10068
+ exception = AcquireExceptionInfo();
10069
+ BEGIN_CHANNEL_MASK(new_image, channels);
10070
+ (void) NormalizeImage(new_image, exception);
10071
+ END_CHANNEL_MASK(new_image);
10072
+ rm_check_exception(exception, new_image, DestroyOnError);
10073
+ (void) DestroyExceptionInfo(exception);
10074
+ #else
9178
10075
  (void) NormalizeImageChannel(new_image, channels);
9179
10076
  rm_check_image_exception(new_image, DestroyOnError);
10077
+ #endif
9180
10078
 
9181
10079
  return rm_image_new(new_image);
9182
10080
  }
@@ -9257,6 +10155,9 @@ Image_oil_paint(int argc, VALUE *argv, VALUE self)
9257
10155
  Image *image, *new_image;
9258
10156
  double radius = 3.0;
9259
10157
  ExceptionInfo *exception;
10158
+ #if defined(IMAGEMAGICK_7)
10159
+ double sigma = 1.0;
10160
+ #endif
9260
10161
 
9261
10162
  image = rm_check_destroyed(self);
9262
10163
  switch (argc)
@@ -9272,7 +10173,11 @@ Image_oil_paint(int argc, VALUE *argv, VALUE self)
9272
10173
 
9273
10174
  exception = AcquireExceptionInfo();
9274
10175
 
10176
+ #if defined(IMAGEMAGICK_7)
10177
+ new_image = OilPaintImage(image, radius, sigma, exception);
10178
+ #else
9275
10179
  new_image = OilPaintImage(image, radius, exception);
10180
+ #endif
9276
10181
  rm_check_exception(exception, new_image, DestroyOnError);
9277
10182
 
9278
10183
  (void) DestroyExceptionInfo(exception);
@@ -9307,6 +10212,9 @@ Image_opaque(VALUE self, VALUE target, VALUE fill)
9307
10212
  MagickPixel target_pp;
9308
10213
  MagickPixel fill_pp;
9309
10214
  MagickBooleanType okay;
10215
+ #if defined(IMAGEMAGICK_7)
10216
+ ExceptionInfo *exception;
10217
+ #endif
9310
10218
 
9311
10219
  image = rm_check_destroyed(self);
9312
10220
 
@@ -9316,8 +10224,15 @@ Image_opaque(VALUE self, VALUE target, VALUE fill)
9316
10224
 
9317
10225
  new_image = rm_clone_image(image);
9318
10226
 
10227
+ #if defined(IMAGEMAGICK_7)
10228
+ exception = AcquireExceptionInfo();
10229
+ okay = OpaquePaintImage(new_image, &target_pp, &fill_pp, MagickFalse, exception);
10230
+ rm_check_exception(exception, new_image, DestroyOnError);
10231
+ (void) DestroyExceptionInfo(exception);
10232
+ #else
9319
10233
  okay = OpaquePaintImageChannel(new_image, DefaultChannels, &target_pp, &fill_pp, MagickFalse);
9320
10234
  rm_check_image_exception(new_image, DestroyOnError);
10235
+ #endif
9321
10236
 
9322
10237
  if (!okay)
9323
10238
  {
@@ -9359,6 +10274,9 @@ Image_opaque_channel(int argc, VALUE *argv, VALUE self)
9359
10274
  ChannelType channels;
9360
10275
  double keep, fuzz;
9361
10276
  MagickBooleanType okay, invert = MagickFalse;
10277
+ #if defined(IMAGEMAGICK_7)
10278
+ ExceptionInfo *exception;
10279
+ #endif
9362
10280
 
9363
10281
  image = rm_check_destroyed(self);
9364
10282
  channels = extract_channels(&argc, argv);
@@ -9394,10 +10312,20 @@ Image_opaque_channel(int argc, VALUE *argv, VALUE self)
9394
10312
  keep = new_image->fuzz;
9395
10313
  new_image->fuzz = fuzz;
9396
10314
 
10315
+ #if defined(IMAGEMAGICK_7)
10316
+ exception = AcquireExceptionInfo();
10317
+ BEGIN_CHANNEL_MASK(new_image, channels);
10318
+ okay = OpaquePaintImage(new_image, &target_pp, &fill_pp, MagickFalse, exception);
10319
+ END_CHANNEL_MASK(new_image);
10320
+ new_image->fuzz = keep;
10321
+ rm_check_exception(exception, new_image, DestroyOnError);
10322
+ (void) DestroyExceptionInfo(exception);
10323
+ #else
9397
10324
  okay = OpaquePaintImageChannel(new_image, channels, &target_pp, &fill_pp, invert);
9398
10325
 
9399
10326
  new_image->fuzz = keep;
9400
10327
  rm_check_image_exception(new_image, DestroyOnError);
10328
+ #endif
9401
10329
 
9402
10330
  if (!okay)
9403
10331
  {
@@ -9423,7 +10351,11 @@ Image_opaque_channel(int argc, VALUE *argv, VALUE self)
9423
10351
  VALUE
9424
10352
  Image_opaque_q(VALUE self)
9425
10353
  {
10354
+ #if defined(IMAGEMAGICK_7)
10355
+ return has_attribute(self, IsImageOpaque);
10356
+ #else
9426
10357
  return has_attribute(self, IsOpaqueImage);
10358
+ #endif
9427
10359
  }
9428
10360
 
9429
10361
 
@@ -9490,7 +10422,7 @@ Image_ordered_dither(int argc, VALUE *argv, VALUE self)
9490
10422
 
9491
10423
  exception = AcquireExceptionInfo();
9492
10424
 
9493
- (void) OrderedPosterizeImage(new_image, threshold_map, exception);
10425
+ (void) OrderedDitherImage(new_image, threshold_map, exception);
9494
10426
  rm_check_exception(exception, new_image, DestroyOnError);
9495
10427
 
9496
10428
  (void) DestroyExceptionInfo(exception);
@@ -9598,6 +10530,9 @@ Image_paint_transparent(int argc, VALUE *argv, VALUE self)
9598
10530
  Quantum alpha = TransparentAlpha;
9599
10531
  double keep, fuzz;
9600
10532
  MagickBooleanType okay, invert;
10533
+ #if defined(IMAGEMAGICK_7)
10534
+ ExceptionInfo *exception;
10535
+ #endif
9601
10536
 
9602
10537
  image = rm_check_destroyed(self);
9603
10538
 
@@ -9641,11 +10576,20 @@ Image_paint_transparent(int argc, VALUE *argv, VALUE self)
9641
10576
  keep = new_image->fuzz;
9642
10577
  new_image->fuzz = fuzz;
9643
10578
 
10579
+ #if defined(IMAGEMAGICK_7)
10580
+ exception = AcquireExceptionInfo();
10581
+ okay = TransparentPaintImage(new_image, (const MagickPixel *)&color, alpha, invert, exception);
10582
+ new_image->fuzz = keep;
10583
+ rm_check_exception(exception, new_image, DestroyOnError);
10584
+ (void) DestroyExceptionInfo(exception);
10585
+ #else
9644
10586
  okay = TransparentPaintImage(new_image, (const MagickPixel *)&color, QuantumRange - alpha, invert);
9645
10587
  new_image->fuzz = keep;
9646
10588
 
9647
10589
  // Is it possible for TransparentPaintImage to silently fail?
9648
10590
  rm_check_image_exception(new_image, DestroyOnError);
10591
+ #endif
10592
+
9649
10593
  if (!okay)
9650
10594
  {
9651
10595
  // Force exception
@@ -9669,7 +10613,11 @@ Image_paint_transparent(int argc, VALUE *argv, VALUE self)
9669
10613
  VALUE
9670
10614
  Image_palette_q(VALUE self)
9671
10615
  {
10616
+ #if defined(IMAGEMAGICK_7)
10617
+ return has_image_attribute(self, IsPaletteImage);
10618
+ #else
9672
10619
  return has_attribute(self, IsPaletteImage);
10620
+ #endif
9673
10621
  }
9674
10622
 
9675
10623
 
@@ -9720,7 +10668,13 @@ Image_pixel_color(int argc, VALUE *argv, VALUE self)
9720
10668
  long x, y;
9721
10669
  unsigned int set = False;
9722
10670
  MagickBooleanType okay;
10671
+ #if defined(IMAGEMAGICK_7)
10672
+ Quantum *pixel;
10673
+ const Quantum *old_pixel;
10674
+ #else
9723
10675
  PixelPacket *pixel;
10676
+ const PixelPacket *old_pixel;
10677
+ #endif
9724
10678
 
9725
10679
  memset(&old_color, 0, sizeof(old_color));
9726
10680
 
@@ -9748,11 +10702,18 @@ Image_pixel_color(int argc, VALUE *argv, VALUE self)
9748
10702
  if (!set)
9749
10703
  {
9750
10704
  exception = AcquireExceptionInfo();
9751
- old_color = *GetVirtualPixels(image, x, y, 1, 1, exception);
10705
+ old_pixel = GetVirtualPixels(image, x, y, 1, 1, exception);
9752
10706
  CHECK_EXCEPTION()
9753
10707
 
9754
10708
  (void) DestroyExceptionInfo(exception);
9755
10709
 
10710
+ #if defined(IMAGEMAGICK_7)
10711
+ old_color.red = GetPixelRed(image, old_pixel);
10712
+ old_color.green = GetPixelGreen(image, old_pixel);
10713
+ old_color.blue = GetPixelBlue(image, old_pixel);
10714
+ old_color.alpha = GetPixelAlpha(image, old_pixel);
10715
+ #else
10716
+ old_color = *old_pixel;
9756
10717
  // PseudoClass
9757
10718
  if (image->storage_class == PseudoClass)
9758
10719
  {
@@ -9763,6 +10724,7 @@ Image_pixel_color(int argc, VALUE *argv, VALUE self)
9763
10724
  {
9764
10725
  old_color.opacity = OpaqueOpacity;
9765
10726
  }
10727
+ #endif
9766
10728
  return Pixel_from_PixelPacket(&old_color);
9767
10729
  }
9768
10730
 
@@ -9773,29 +10735,57 @@ Image_pixel_color(int argc, VALUE *argv, VALUE self)
9773
10735
  return Pixel_from_PixelColor(&image->background_color);
9774
10736
  }
9775
10737
 
10738
+ #if defined(IMAGEMAGICK_7)
10739
+ exception = AcquireExceptionInfo();
10740
+ #endif
10741
+
9776
10742
  if (image->storage_class == PseudoClass)
9777
10743
  {
10744
+ #if defined(IMAGEMAGICK_7)
10745
+ okay = SetImageStorageClass(image, DirectClass, exception);
10746
+ CHECK_EXCEPTION()
10747
+ if (!okay)
10748
+ {
10749
+ (void) DestroyExceptionInfo(exception);
10750
+ rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't set pixel color.");
10751
+ }
10752
+ #else
9778
10753
  okay = SetImageStorageClass(image, DirectClass);
9779
10754
  rm_check_image_exception(image, RetainOnError);
9780
10755
  if (!okay)
9781
10756
  {
9782
10757
  rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't set pixel color.");
9783
10758
  }
10759
+ #endif
9784
10760
  }
9785
10761
 
10762
+ #if defined(IMAGEMAGICK_6)
9786
10763
  exception = AcquireExceptionInfo();
10764
+ #endif
9787
10765
 
9788
10766
  pixel = GetAuthenticPixels(image, x, y, 1, 1, exception);
9789
10767
  CHECK_EXCEPTION()
9790
10768
 
9791
10769
  if (pixel)
9792
10770
  {
10771
+ #if defined(IMAGEMAGICK_7)
10772
+ old_color.red = GetPixelRed(image, pixel);
10773
+ old_color.green = GetPixelGreen(image, pixel);
10774
+ old_color.blue = GetPixelBlue(image, pixel);
10775
+ old_color.alpha = GetPixelAlpha(image, pixel);
10776
+
10777
+ SetPixelRed(image, new_color.red, pixel);
10778
+ SetPixelGreen(image, new_color.green, pixel);
10779
+ SetPixelBlue(image, new_color.blue, pixel);
10780
+ SetPixelAlpha(image, new_color.alpha, pixel);
10781
+ #else
9793
10782
  old_color = *pixel;
9794
10783
  if (!image->matte)
9795
10784
  {
9796
10785
  old_color.opacity = OpaqueOpacity;
9797
10786
  }
9798
10787
  *pixel = new_color;
10788
+ #endif
9799
10789
 
9800
10790
  SyncAuthenticPixels(image, exception);
9801
10791
  CHECK_EXCEPTION()
@@ -9872,6 +10862,9 @@ Image_polaroid(int argc, VALUE *argv, VALUE self)
9872
10862
  double angle = -5.0;
9873
10863
  Draw *draw;
9874
10864
  ExceptionInfo *exception;
10865
+ #if defined(IMAGEMAGICK_7)
10866
+ char *caption = (char *) NULL;
10867
+ #endif
9875
10868
 
9876
10869
  image = rm_check_destroyed(self);
9877
10870
 
@@ -9894,7 +10887,11 @@ Image_polaroid(int argc, VALUE *argv, VALUE self)
9894
10887
  clone->border_color = draw->info->border_color;
9895
10888
 
9896
10889
  exception = AcquireExceptionInfo();
10890
+ #if defined(IMAGEMAGICK_7)
10891
+ new_image = PolaroidImage(clone, draw->info, caption, angle, image->interpolate, exception);
10892
+ #else
9897
10893
  new_image = PolaroidImage(clone, draw->info, angle, exception);
10894
+ #endif
9898
10895
  rm_check_exception(exception, clone, DestroyOnError);
9899
10896
 
9900
10897
  (void) DestroyImage(clone);
@@ -9929,6 +10926,9 @@ Image_posterize(int argc, VALUE *argv, VALUE self)
9929
10926
  Image *image, *new_image;
9930
10927
  MagickBooleanType dither = MagickFalse;
9931
10928
  unsigned long levels = 4;
10929
+ #if defined(IMAGEMAGICK_7)
10930
+ ExceptionInfo *exception;
10931
+ #endif
9932
10932
 
9933
10933
  image = rm_check_destroyed(self);
9934
10934
  switch (argc)
@@ -9947,8 +10947,15 @@ Image_posterize(int argc, VALUE *argv, VALUE self)
9947
10947
 
9948
10948
  new_image = rm_clone_image(image);
9949
10949
 
10950
+ #if defined(IMAGEMAGICK_7)
10951
+ exception = AcquireExceptionInfo();
10952
+ (void) PosterizeImage(new_image, levels, dither, exception);
10953
+ rm_check_exception(exception, new_image, DestroyOnError);
10954
+ (void) DestroyExceptionInfo(exception);
10955
+ #else
9950
10956
  (void) PosterizeImage(new_image, levels, dither);
9951
10957
  rm_check_image_exception(new_image, DestroyOnError);
10958
+ #endif
9952
10959
 
9953
10960
  return rm_image_new(new_image);
9954
10961
  }
@@ -10214,7 +11221,13 @@ Image_quantum_operator(int argc, VALUE *argv, VALUE self)
10214
11221
  }
10215
11222
 
10216
11223
  exception = AcquireExceptionInfo();
11224
+ #if defined(IMAGEMAGICK_7)
11225
+ BEGIN_CHANNEL_MASK(image, channel);
11226
+ (void) EvaluateImage(image, qop, rvalue, exception);
11227
+ END_CHANNEL_MASK(image);
11228
+ #else
10217
11229
  (void) EvaluateImageChannel(image, channel, qop, rvalue, exception);
11230
+ #endif
10218
11231
  CHECK_EXCEPTION()
10219
11232
 
10220
11233
  (void) DestroyExceptionInfo(exception);
@@ -10251,6 +11264,9 @@ Image_quantize(int argc, VALUE *argv, VALUE self)
10251
11264
  {
10252
11265
  Image *image, *new_image;
10253
11266
  QuantizeInfo quantize_info;
11267
+ #if defined(IMAGEMAGICK_7)
11268
+ ExceptionInfo *exception;
11269
+ #endif
10254
11270
 
10255
11271
  image = rm_check_destroyed(self);
10256
11272
  GetQuantizeInfo(&quantize_info);
@@ -10265,11 +11281,17 @@ Image_quantize(int argc, VALUE *argv, VALUE self)
10265
11281
  if (rb_obj_is_kind_of(argv[2], Class_DitherMethod))
10266
11282
  {
10267
11283
  VALUE_TO_ENUM(argv[2], quantize_info.dither_method, DitherMethod);
11284
+ #if defined(IMAGEMAGICK_6)
10268
11285
  quantize_info.dither = quantize_info.dither_method != NoDitherMethod;
11286
+ #endif
10269
11287
  }
10270
11288
  else
10271
11289
  {
11290
+ #if defined(IMAGEMAGICK_7)
11291
+ quantize_info.dither_method = RTEST(argv[2]) ? RiemersmaDitherMethod : NoDitherMethod;
11292
+ #else
10272
11293
  quantize_info.dither = (MagickBooleanType) RTEST(argv[2]);
11294
+ #endif
10273
11295
  }
10274
11296
  case 2:
10275
11297
  VALUE_TO_ENUM(argv[1], quantize_info.colorspace, ColorspaceType);
@@ -10284,8 +11306,15 @@ Image_quantize(int argc, VALUE *argv, VALUE self)
10284
11306
 
10285
11307
  new_image = rm_clone_image(image);
10286
11308
 
11309
+ #if defined(IMAGEMAGICK_7)
11310
+ exception = AcquireExceptionInfo();
11311
+ (void) QuantizeImage(&quantize_info, new_image, exception);
11312
+ rm_check_exception(exception, new_image, DestroyOnError);
11313
+ (void) DestroyExceptionInfo(exception);
11314
+ #else
10287
11315
  (void) QuantizeImage(&quantize_info, new_image);
10288
11316
  rm_check_image_exception(new_image, DestroyOnError);
11317
+ #endif
10289
11318
 
10290
11319
  return rm_image_new(new_image);
10291
11320
  }
@@ -10367,7 +11396,12 @@ Image_radial_blur_channel(int argc, VALUE *argv, VALUE self)
10367
11396
  angle = NUM2DBL(argv[0]);
10368
11397
  exception = AcquireExceptionInfo();
10369
11398
 
10370
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
11399
+ #if defined(IMAGEMAGICK_7)
11400
+ BEGIN_CHANNEL_MASK(image, channels);
11401
+ new_image = RotationalBlurImage(image, angle, exception);
11402
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
11403
+ END_CHANNEL_MASK(image);
11404
+ #elif defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
10371
11405
  new_image = RotationalBlurImageChannel(image, channels, angle, exception);
10372
11406
  #else
10373
11407
  new_image = RadialBlurImageChannel(image, channels, angle, exception);
@@ -10427,7 +11461,18 @@ Image_random_threshold_channel(int argc, VALUE *argv, VALUE self)
10427
11461
 
10428
11462
  exception = AcquireExceptionInfo();
10429
11463
 
11464
+ #if defined(IMAGEMAGICK_7)
11465
+ BEGIN_CHANNEL_MASK(new_image, channels);
11466
+ {
11467
+ GeometryInfo geometry_info;
11468
+
11469
+ (void) ParseGeometry(thresholds,&geometry_info);
11470
+ (void) RandomThresholdImage(new_image, geometry_info.rho, geometry_info.sigma, exception);
11471
+ }
11472
+ END_CHANNEL_MASK(new_image);
11473
+ #else
10430
11474
  (void) RandomThresholdImageChannel(new_image, channels, thresholds, exception);
11475
+ #endif
10431
11476
  rm_check_exception(exception, new_image, DestroyOnError);
10432
11477
 
10433
11478
  (void) DestroyExceptionInfo(exception);
@@ -10466,6 +11511,9 @@ Image_raise(int argc, VALUE *argv, VALUE self)
10466
11511
  Image *image, *new_image;
10467
11512
  RectangleInfo rect;
10468
11513
  int raised = MagickTrue; // default
11514
+ #if defined(IMAGEMAGICK_7)
11515
+ ExceptionInfo *exception;
11516
+ #endif
10469
11517
 
10470
11518
  memset(&rect, 0, sizeof(rect));
10471
11519
  rect.width = 6; // default
@@ -10489,8 +11537,15 @@ Image_raise(int argc, VALUE *argv, VALUE self)
10489
11537
 
10490
11538
  new_image = rm_clone_image(image);
10491
11539
 
11540
+ #if defined(IMAGEMAGICK_7)
11541
+ exception = AcquireExceptionInfo();
11542
+ (void) RaiseImage(new_image, &rect, raised, exception);
11543
+ rm_check_exception(exception, new_image, DestroyOnError);
11544
+ (void) DestroyExceptionInfo(exception);
11545
+ #else
10492
11546
  (void) RaiseImage(new_image, &rect, raised);
10493
11547
  rm_check_image_exception(new_image, DestroyOnError);
11548
+ #endif
10494
11549
 
10495
11550
  return rm_image_new(new_image);
10496
11551
  }
@@ -10644,17 +11699,31 @@ Image_recolor(VALUE self, VALUE color_matrix)
10644
11699
 
10645
11700
  order = (unsigned long)sqrt((double)(len + 1.0));
10646
11701
 
11702
+ exception = AcquireExceptionInfo();
11703
+ #if defined(IMAGEMAGICK_7)
11704
+ kernel_info = AcquireKernelInfo(NULL, exception);
11705
+ if (rm_should_raise_exception(exception, RetainExceptionRetention))
11706
+ {
11707
+ if (kernel_info != (KernelInfo *) NULL)
11708
+ {
11709
+ (void) DestroyKernelInfo(kernel_info);
11710
+ }
11711
+ xfree((void *)matrix);
11712
+ rm_raise_exception(exception);
11713
+ }
11714
+ #else
10647
11715
  kernel_info = AcquireKernelInfo(NULL);
11716
+ #endif
10648
11717
  if (kernel_info == (KernelInfo *) NULL)
10649
11718
  {
10650
11719
  xfree((void *) matrix);
11720
+ (void) DestroyExceptionInfo(exception);
10651
11721
  return Qnil;
10652
11722
  }
10653
11723
  kernel_info->width = order;
10654
11724
  kernel_info->height = order;
10655
11725
  kernel_info->values = (double *) matrix;
10656
11726
 
10657
- exception = AcquireExceptionInfo();
10658
11727
  new_image = ColorMatrixImage(image, kernel_info, exception);
10659
11728
  kernel_info->values = (double *) NULL;
10660
11729
  (void) DestroyKernelInfo(kernel_info);
@@ -10819,6 +11888,9 @@ Image_remap(int argc, VALUE *argv, VALUE self)
10819
11888
  {
10820
11889
  Image *image, *remap_image;
10821
11890
  QuantizeInfo quantize_info;
11891
+ #if defined(IMAGEMAGICK_7)
11892
+ ExceptionInfo *exception;
11893
+ #endif
10822
11894
 
10823
11895
  image = rm_check_frozen(self);
10824
11896
  if (argc > 0)
@@ -10834,7 +11906,9 @@ Image_remap(int argc, VALUE *argv, VALUE self)
10834
11906
  {
10835
11907
  case 2:
10836
11908
  VALUE_TO_ENUM(argv[1], quantize_info.dither_method, DitherMethod);
11909
+ #if defined(IMAGEMAGICK_6)
10837
11910
  quantize_info.dither = MagickTrue;
11911
+ #endif
10838
11912
  break;
10839
11913
  case 1:
10840
11914
  break;
@@ -10843,8 +11917,15 @@ Image_remap(int argc, VALUE *argv, VALUE self)
10843
11917
  break;
10844
11918
  }
10845
11919
 
11920
+ #if defined(IMAGEMAGICK_7)
11921
+ exception = AcquireExceptionInfo();
11922
+ (void) RemapImage(&quantize_info, image, remap_image, exception);
11923
+ CHECK_EXCEPTION()
11924
+ (void) DestroyExceptionInfo(exception);
11925
+ #else
10846
11926
  (void) RemapImage(&quantize_info, image, remap_image);
10847
11927
  rm_check_image_exception(image, RetainOnError);
11928
+ #endif
10848
11929
 
10849
11930
  return self;
10850
11931
  }
@@ -10913,7 +11994,9 @@ resample(int bang, int argc, VALUE *argv, VALUE self)
10913
11994
 
10914
11995
  // Set up defaults
10915
11996
  filter = image->filter;
11997
+ #if defined(IMAGEMAGICK_6)
10916
11998
  blur = image->blur;
11999
+ #endif
10917
12000
  x_resolution = 72.0;
10918
12001
  y_resolution = 72.0;
10919
12002
 
@@ -10939,10 +12022,17 @@ resample(int bang, int argc, VALUE *argv, VALUE self)
10939
12022
  {
10940
12023
  y_resolution = x_resolution;
10941
12024
  }
12025
+ #if defined(IMAGEMAGICK_7)
12026
+ width = (x_resolution * image->columns /
12027
+ (image->resolution.x == 0.0 ? 72.0 : image->resolution.x) + 0.5);
12028
+ height = (y_resolution * image->rows /
12029
+ (image->resolution.y == 0.0 ? 72.0 : image->resolution.y) + 0.5);
12030
+ #else
10942
12031
  width = (x_resolution * image->columns /
10943
12032
  (image->x_resolution == 0.0 ? 72.0 : image->x_resolution) + 0.5);
10944
12033
  height = (y_resolution * image->rows /
10945
12034
  (image->y_resolution == 0.0 ? 72.0 : image->y_resolution) + 0.5);
12035
+ #endif
10946
12036
  if (width > (double)ULONG_MAX || height > (double)ULONG_MAX)
10947
12037
  {
10948
12038
  rb_raise(rb_eRangeError, "resampled image too big");
@@ -10956,7 +12046,11 @@ resample(int bang, int argc, VALUE *argv, VALUE self)
10956
12046
  }
10957
12047
 
10958
12048
  exception = AcquireExceptionInfo();
12049
+ #if defined(IMAGEMAGICK_7)
12050
+ new_image = ResampleImage(image, x_resolution, y_resolution, filter, exception);
12051
+ #else
10959
12052
  new_image = ResampleImage(image, x_resolution, y_resolution, filter, blur, exception);
12053
+ #endif
10960
12054
  rm_check_exception(exception, new_image, DestroyOnError);
10961
12055
 
10962
12056
  (void) DestroyExceptionInfo(exception);
@@ -11060,7 +12154,9 @@ resize(int bang, int argc, VALUE *argv, VALUE self)
11060
12154
 
11061
12155
  // Set up defaults
11062
12156
  filter = image->filter;
12157
+ #if defined(IMAGEMAGICK_6)
11063
12158
  blur = image->blur;
12159
+ #endif
11064
12160
  rows = image->rows;
11065
12161
  columns = image->columns;
11066
12162
 
@@ -11099,7 +12195,11 @@ resize(int bang, int argc, VALUE *argv, VALUE self)
11099
12195
  }
11100
12196
 
11101
12197
  exception = AcquireExceptionInfo();
12198
+ #if defined(IMAGEMAGICK_7)
12199
+ new_image = ResizeImage(image, columns, rows, filter, exception);
12200
+ #else
11102
12201
  new_image = ResizeImage(image, columns, rows, filter, blur, exception);
12202
+ #endif
11103
12203
  rm_check_exception(exception, new_image, DestroyOnError);
11104
12204
 
11105
12205
  (void) DestroyExceptionInfo(exception);
@@ -11563,7 +12663,14 @@ Image_selective_blur_channel(int argc, VALUE *argv, VALUE self)
11563
12663
  threshold = rm_percentage(argv[2],1.0) * QuantumRange;
11564
12664
 
11565
12665
  exception = AcquireExceptionInfo();
12666
+ #if defined(IMAGEMAGICK_7)
12667
+ BEGIN_CHANNEL_MASK(image, channels);
12668
+ new_image = SelectiveBlurImage(image, radius, sigma, threshold, exception);
12669
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
12670
+ END_CHANNEL_MASK(image);
12671
+ #else
11566
12672
  new_image = SelectiveBlurImageChannel(image, channels, radius, sigma, threshold, exception);
12673
+ #endif
11567
12674
  rm_check_exception(exception, new_image, DestroyOnError);
11568
12675
  (void) DestroyExceptionInfo(exception);
11569
12676
  rm_ensure_result(new_image);
@@ -11589,14 +12696,26 @@ Image_set_channel_depth(VALUE self, VALUE channel_arg, VALUE depth)
11589
12696
  Image *image;
11590
12697
  ChannelType channel;
11591
12698
  unsigned long channel_depth;
12699
+ #if defined(IMAGEMAGICK_7)
12700
+ ExceptionInfo *exception;
12701
+ #endif
11592
12702
 
11593
12703
  image = rm_check_frozen(self);
11594
12704
 
11595
12705
  VALUE_TO_ENUM(channel_arg, channel, ChannelType);
11596
12706
  channel_depth = NUM2ULONG(depth);
11597
12707
 
12708
+ #if defined(IMAGEMAGICK_7)
12709
+ exception = AcquireExceptionInfo();
12710
+ BEGIN_CHANNEL_MASK(image, channel);
12711
+ (void) SetImageDepth(image, channel_depth, exception);
12712
+ END_CHANNEL_MASK(image);
12713
+ CHECK_EXCEPTION()
12714
+ (void) DestroyExceptionInfo(exception);
12715
+ #else
11598
12716
  (void) SetImageChannelDepth(image, channel, channel_depth);
11599
12717
  rm_check_image_exception(image, RetainOnError);
12718
+ #endif
11600
12719
 
11601
12720
  return self;
11602
12721
  }
@@ -11635,7 +12754,14 @@ Image_separate(int argc, VALUE *argv, VALUE self)
11635
12754
  }
11636
12755
 
11637
12756
  exception = AcquireExceptionInfo();
12757
+ #if defined(IMAGEMAGICK_7)
12758
+ BEGIN_CHANNEL_MASK(image, channels);
12759
+ new_images = SeparateImages(image, exception);
12760
+ CHANGE_RESULT_CHANNEL_MASK(new_images);
12761
+ END_CHANNEL_MASK(image);
12762
+ #else
11638
12763
  new_images = SeparateImages(image, channels, exception);
12764
+ #endif
11639
12765
  rm_check_exception(exception, new_images, DestroyOnError);
11640
12766
  DestroyExceptionInfo(exception);
11641
12767
  rm_ensure_result(new_images);
@@ -11720,6 +12846,9 @@ Image_segment(int argc, VALUE *argv, VALUE self)
11720
12846
  unsigned int verbose = MagickFalse;
11721
12847
  double cluster_threshold = 1.0;
11722
12848
  double smoothing_threshold = 1.5;
12849
+ #if defined(IMAGEMAGICK_7)
12850
+ ExceptionInfo *exception;
12851
+ #endif
11723
12852
 
11724
12853
  image = rm_check_destroyed(self);
11725
12854
  switch (argc)
@@ -11741,8 +12870,16 @@ Image_segment(int argc, VALUE *argv, VALUE self)
11741
12870
 
11742
12871
  new_image = rm_clone_image(image);
11743
12872
 
12873
+ #if defined(IMAGEMAGICK_7)
12874
+ exception = AcquireExceptionInfo();
12875
+ (void) SegmentImage(new_image, colorspace, verbose, cluster_threshold, smoothing_threshold, exception);
12876
+ rm_check_exception(exception, new_image, DestroyOnError);
12877
+ (void) DestroyExceptionInfo(exception);
12878
+ #else
11744
12879
  (void) SegmentImage(new_image, colorspace, verbose, cluster_threshold, smoothing_threshold);
11745
12880
  rm_check_image_exception(new_image, DestroyOnError);
12881
+ #endif
12882
+
11746
12883
  rm_ensure_result(new_image);
11747
12884
 
11748
12885
  return rm_image_new(new_image);
@@ -11769,9 +12906,16 @@ Image_properties(VALUE self)
11769
12906
  Image *image;
11770
12907
  VALUE attr_hash, ary;
11771
12908
  const char *property, *value;
12909
+ #if defined(IMAGEMAGICK_7)
12910
+ ExceptionInfo *exception;
12911
+ #endif
11772
12912
 
11773
12913
  image = rm_check_destroyed(self);
11774
12914
 
12915
+ #if defined(IMAGEMAGICK_7)
12916
+ exception = AcquireExceptionInfo();
12917
+ #endif
12918
+
11775
12919
  if (rb_block_given_p())
11776
12920
  {
11777
12921
  ary = rb_ary_new2(2);
@@ -11780,13 +12924,22 @@ Image_properties(VALUE self)
11780
12924
  property = GetNextImageProperty(image);
11781
12925
  while (property)
11782
12926
  {
12927
+ #if defined(IMAGEMAGICK_7)
12928
+ value = GetImageProperty(image, property, exception);
12929
+ #else
11783
12930
  value = GetImageProperty(image, property);
12931
+ #endif
11784
12932
  (void) rb_ary_store(ary, 0, rb_str_new2(property));
11785
12933
  (void) rb_ary_store(ary, 1, rb_str_new2(value));
11786
12934
  (void) rb_yield(ary);
11787
12935
  property = GetNextImageProperty(image);
11788
12936
  }
12937
+ #if defined(IMAGEMAGICK_7)
12938
+ CHECK_EXCEPTION()
12939
+ (void) DestroyExceptionInfo(exception);
12940
+ #else
11789
12941
  rm_check_image_exception(image, RetainOnError);
12942
+ #endif
11790
12943
 
11791
12944
  RB_GC_GUARD(ary);
11792
12945
 
@@ -11801,11 +12954,20 @@ Image_properties(VALUE self)
11801
12954
  property = GetNextImageProperty(image);
11802
12955
  while (property)
11803
12956
  {
12957
+ #if defined(IMAGEMAGICK_7)
12958
+ value = GetImageProperty(image, property, exception);
12959
+ #else
11804
12960
  value = GetImageProperty(image, property);
12961
+ #endif
11805
12962
  (void) rb_hash_aset(attr_hash, rb_str_new2(property), rb_str_new2(value));
11806
12963
  property = GetNextImageProperty(image);
11807
12964
  }
12965
+ #if defined(IMAGEMAGICK_7)
12966
+ CHECK_EXCEPTION()
12967
+ (void) DestroyExceptionInfo(exception);
12968
+ #else
11808
12969
  rm_check_image_exception(image, RetainOnError);
12970
+ #endif
11809
12971
 
11810
12972
  RB_GC_GUARD(attr_hash);
11811
12973
 
@@ -12016,7 +13178,14 @@ Image_sharpen_channel(int argc, VALUE *argv, VALUE self)
12016
13178
  }
12017
13179
 
12018
13180
  exception = AcquireExceptionInfo();
13181
+ #if defined(IMAGEMAGICK_7)
13182
+ BEGIN_CHANNEL_MASK(image, channels);
13183
+ new_image = SharpenImage(image, radius, sigma, exception);
13184
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
13185
+ END_CHANNEL_MASK(image);
13186
+ #else
12019
13187
  new_image = SharpenImageChannel(image, channels, radius, sigma, exception);
13188
+ #endif
12020
13189
 
12021
13190
  rm_check_exception(exception, new_image, DestroyOnError);
12022
13191
  (void) DestroyExceptionInfo(exception);
@@ -12131,6 +13300,9 @@ Image_sigmoidal_contrast_channel(int argc, VALUE *argv, VALUE self)
12131
13300
  double contrast = 3.0;
12132
13301
  double midpoint = 50.0;
12133
13302
  ChannelType channels;
13303
+ #if defined(IMAGEMAGICK_7)
13304
+ ExceptionInfo *exception;
13305
+ #endif
12134
13306
 
12135
13307
  image = rm_check_destroyed(self);
12136
13308
  channels = extract_channels(&argc, argv);
@@ -12152,8 +13324,17 @@ Image_sigmoidal_contrast_channel(int argc, VALUE *argv, VALUE self)
12152
13324
 
12153
13325
  new_image = rm_clone_image(image);
12154
13326
 
13327
+ #if defined(IMAGEMAGICK_7)
13328
+ exception = AcquireExceptionInfo();
13329
+ BEGIN_CHANNEL_MASK(new_image, channels);
13330
+ (void) SigmoidalContrastImage(new_image, sharpen, contrast, midpoint, exception);
13331
+ END_CHANNEL_MASK(new_image);
13332
+ rm_check_exception(exception, new_image, DestroyOnError);
13333
+ (void) DestroyExceptionInfo(exception);
13334
+ #else
12155
13335
  (void) SigmoidalContrastImageChannel(new_image, channels, sharpen, contrast, midpoint);
12156
13336
  rm_check_image_exception(new_image, DestroyOnError);
13337
+ #endif
12157
13338
 
12158
13339
  return rm_image_new(new_image);
12159
13340
  }
@@ -12174,11 +13355,21 @@ Image_signature(VALUE self)
12174
13355
  {
12175
13356
  Image *image;
12176
13357
  const char *signature;
13358
+ #if defined(IMAGEMAGICK_7)
13359
+ ExceptionInfo *exception;
13360
+ #endif
12177
13361
 
12178
13362
  image = rm_check_destroyed(self);
12179
13363
 
13364
+ #if defined(IMAGEMAGICK_7)
13365
+ exception = AcquireExceptionInfo();
13366
+ (void) SignatureImage(image, exception);
13367
+ CHECK_EXCEPTION()
13368
+ (void) DestroyExceptionInfo(exception);
13369
+ #else
12180
13370
  (void) SignatureImage(image);
12181
13371
  rm_check_image_exception(image, RetainOnError);
13372
+ #endif
12182
13373
  signature = rm_get_property(image, "signature");
12183
13374
  if (!signature)
12184
13375
  {
@@ -12239,6 +13430,9 @@ Image_solarize(int argc, VALUE *argv, VALUE self)
12239
13430
  {
12240
13431
  Image *image, *new_image;
12241
13432
  double threshold = 50.0;
13433
+ #if defined(IMAGEMAGICK_7)
13434
+ ExceptionInfo *exception;
13435
+ #endif
12242
13436
 
12243
13437
  image = rm_check_destroyed(self);
12244
13438
  switch (argc)
@@ -12258,8 +13452,15 @@ Image_solarize(int argc, VALUE *argv, VALUE self)
12258
13452
 
12259
13453
  new_image = rm_clone_image(image);
12260
13454
 
13455
+ #if defined(IMAGEMAGICK_7)
13456
+ exception = AcquireExceptionInfo();
13457
+ (void) SolarizeImage(new_image, threshold, exception);
13458
+ rm_check_exception(exception, new_image, DestroyOnError);
13459
+ (void) DestroyExceptionInfo(exception);
13460
+ #else
12261
13461
  (void) SolarizeImage(new_image, threshold);
12262
13462
  rm_check_image_exception(new_image, DestroyOnError);
13463
+ #endif
12263
13464
 
12264
13465
  return rm_image_new(new_image);
12265
13466
  }
@@ -12281,6 +13482,9 @@ Image_spaceship(VALUE self, VALUE other)
12281
13482
  Image *imageA, *imageB;
12282
13483
  const char *sigA, *sigB;
12283
13484
  int res;
13485
+ #if defined(IMAGEMAGICK_7)
13486
+ ExceptionInfo *exception;
13487
+ #endif
12284
13488
 
12285
13489
  imageA = rm_check_destroyed(self);
12286
13490
 
@@ -12292,8 +13496,17 @@ Image_spaceship(VALUE self, VALUE other)
12292
13496
 
12293
13497
  imageB = rm_check_destroyed(other);
12294
13498
 
13499
+ #if defined(IMAGEMAGICK_7)
13500
+ exception = AcquireExceptionInfo();
13501
+ (void) SignatureImage(imageA, exception);
13502
+ CHECK_EXCEPTION();
13503
+ (void) SignatureImage(imageB, exception);
13504
+ CHECK_EXCEPTION();
13505
+ (void) DestroyExceptionInfo(exception);
13506
+ #else
12295
13507
  (void) SignatureImage(imageA);
12296
13508
  (void) SignatureImage(imageB);
13509
+ #endif
12297
13510
  sigA = rm_get_property(imageA, "signature");
12298
13511
  sigB = rm_get_property(imageB, "signature");
12299
13512
  if (!sigA || !sigB)
@@ -12327,7 +13540,11 @@ count_channels(Image *image, ChannelType *channels)
12327
13540
  {
12328
13541
  *channels = (ChannelType) (*channels & ~IndexChannel); /* remove index channels from count */
12329
13542
  }
13543
+ #if defined(IMAGEMAGICK_7)
13544
+ if ( image->alpha_trait == UndefinedPixelTrait )
13545
+ #else
12330
13546
  if ( image->matte == MagickFalse )
13547
+ #endif
12331
13548
  {
12332
13549
  *channels = (ChannelType) (*channels & ~OpacityChannel); /* remove matte/alpha *channels from count */
12333
13550
  }
@@ -12457,12 +13674,23 @@ Image_sparse_color(int argc, VALUE *argv, VALUE self)
12457
13674
  }
12458
13675
  if (channels & OpacityChannel)
12459
13676
  {
13677
+ #if defined(IMAGEMAGICK_7)
13678
+ args[x++] = pp.alpha / QuantumRange;
13679
+ #else
12460
13680
  args[x++] = pp.opacity / QuantumRange;
13681
+ #endif
12461
13682
  }
12462
13683
  }
12463
13684
 
12464
13685
  exception = AcquireExceptionInfo();
13686
+ #if defined(IMAGEMAGICK_7)
13687
+ BEGIN_CHANNEL_MASK(image, channels);
13688
+ new_image = SparseColorImage(image, method, nargs, args, exception);
13689
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
13690
+ END_CHANNEL_MASK(image);
13691
+ #else
12465
13692
  new_image = SparseColorImage(image, channels, method, nargs, args, exception);
13693
+ #endif
12466
13694
  xfree((void *) args);
12467
13695
  rm_check_exception(exception, new_image, DestroyOnError);
12468
13696
  (void) DestroyExceptionInfo(exception);
@@ -12574,7 +13802,11 @@ Image_spread(int argc, VALUE *argv, VALUE self)
12574
13802
  }
12575
13803
 
12576
13804
  exception = AcquireExceptionInfo();
13805
+ #if defined(IMAGEMAGICK_7)
13806
+ new_image = SpreadImage(image, image->interpolate, radius, exception);
13807
+ #else
12577
13808
  new_image = SpreadImage(image, radius, exception);
13809
+ #endif
12578
13810
  rm_check_exception(exception, new_image, DestroyOnError);
12579
13811
  rm_ensure_result(new_image);
12580
13812
 
@@ -12706,6 +13938,9 @@ Image_class_type_eq(VALUE self, VALUE new_class_type)
12706
13938
  Image *image;
12707
13939
  ClassType class_type;
12708
13940
  QuantizeInfo qinfo;
13941
+ #if defined(IMAGEMAGICK_7)
13942
+ ExceptionInfo *exception;
13943
+ #endif
12709
13944
 
12710
13945
  image = rm_check_frozen(self);
12711
13946
 
@@ -12716,9 +13951,18 @@ Image_class_type_eq(VALUE self, VALUE new_class_type)
12716
13951
  rb_raise(rb_eArgError, "Invalid class type specified.");
12717
13952
  }
12718
13953
 
13954
+ #if defined(IMAGEMAGICK_7)
13955
+ exception = AcquireExceptionInfo();
13956
+ #endif
13957
+
12719
13958
  if (image->storage_class == PseudoClass && class_type == DirectClass)
12720
13959
  {
13960
+ #if defined(IMAGEMAGICK_7)
13961
+ (void) SyncImage(image, exception);
13962
+ CHECK_EXCEPTION()
13963
+ #else
12721
13964
  (void) SyncImage(image);
13965
+ #endif
12722
13966
  magick_free(image->colormap);
12723
13967
  image->colormap = NULL;
12724
13968
  }
@@ -12726,10 +13970,21 @@ Image_class_type_eq(VALUE self, VALUE new_class_type)
12726
13970
  {
12727
13971
  GetQuantizeInfo(&qinfo);
12728
13972
  qinfo.number_colors = QuantumRange+1;
13973
+ #if defined(IMAGEMAGICK_7)
13974
+ (void) QuantizeImage(&qinfo, image, exception);
13975
+ CHECK_EXCEPTION()
13976
+ #else
12729
13977
  (void) QuantizeImage(&qinfo, image);
13978
+ #endif
12730
13979
  }
12731
13980
 
13981
+ #if defined(IMAGEMAGICK_7)
13982
+ (void) SetImageStorageClass(image, class_type, exception);
13983
+ CHECK_EXCEPTION()
13984
+ (void) DestroyExceptionInfo(exception);
13985
+ #else
12732
13986
  (void) SetImageStorageClass(image, class_type);
13987
+ #endif
12733
13988
  return new_class_type;
12734
13989
  }
12735
13990
 
@@ -12765,7 +14020,11 @@ Image_store_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg
12765
14020
  unsigned long cols, rows;
12766
14021
  unsigned int okay;
12767
14022
  ExceptionInfo *exception;
14023
+ #if defined(IMAGEMAGICK_7)
14024
+ Quantum *pixels;
14025
+ #else
12768
14026
  PixelPacket *pixels;
14027
+ #endif
12769
14028
 
12770
14029
  image = rm_check_destroyed(self);
12771
14030
 
@@ -12782,21 +14041,30 @@ Image_store_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg
12782
14041
  size = (long)(cols * rows);
12783
14042
  rm_check_ary_len(new_pixels, size);
12784
14043
 
14044
+ #if defined(IMAGEMAGICK_7)
14045
+ exception = AcquireExceptionInfo();
14046
+ okay = SetImageStorageClass(image, DirectClass, exception);
14047
+ CHECK_EXCEPTION()
14048
+ if (!okay)
14049
+ {
14050
+ (void) DestroyExceptionInfo(exception);
14051
+ rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't store pixels.");
14052
+ }
14053
+ #else
12785
14054
  okay = SetImageStorageClass(image, DirectClass);
12786
14055
  rm_check_image_exception(image, RetainOnError);
12787
14056
  if (!okay)
12788
14057
  {
12789
14058
  rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't store pixels.");
12790
14059
  }
14060
+ exception = AcquireExceptionInfo();
14061
+ #endif
12791
14062
 
12792
14063
  // Get a pointer to the pixels. Replace the values with the PixelPackets
12793
14064
  // from the pixels argument.
12794
14065
  {
12795
- exception = AcquireExceptionInfo();
12796
-
12797
14066
  pixels = GetAuthenticPixels(image, x, y, cols, rows, exception);
12798
14067
  CHECK_EXCEPTION()
12799
- DestroyExceptionInfo(exception);
12800
14068
 
12801
14069
  if (pixels)
12802
14070
  {
@@ -12804,14 +14072,22 @@ Image_store_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg
12804
14072
  {
12805
14073
  new_pixel = rb_ary_entry(new_pixels, n);
12806
14074
  Data_Get_Struct(new_pixel, Pixel, pixel);
12807
- pixels[n] = *pixel;
14075
+ #if defined(IMAGEMAGICK_7)
14076
+ SetPixelRed(image, pixel->red, pixels);
14077
+ SetPixelGreen(image, pixel->green, pixels);
14078
+ SetPixelBlue(image, pixel->blue, pixels);
14079
+ SetPixelAlpha(image, pixel->alpha, pixels);
14080
+ pixels += GetPixelChannels(image);
14081
+ #else
14082
+ *pixels = *pixel;
14083
+ pixels++;
14084
+ #endif
12808
14085
  }
12809
- exception = AcquireExceptionInfo();
12810
-
12811
14086
  SyncAuthenticPixels(image, exception);
12812
14087
  CHECK_EXCEPTION()
12813
- DestroyExceptionInfo(exception);
12814
14088
  }
14089
+
14090
+ (void) DestroyExceptionInfo(exception);
12815
14091
  }
12816
14092
 
12817
14093
  RB_GC_GUARD(new_pixel);
@@ -12832,9 +14108,21 @@ Image_store_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg
12832
14108
  VALUE
12833
14109
  Image_strip_bang(VALUE self)
12834
14110
  {
14111
+ #if defined(IMAGEMAGICK_7)
14112
+ ExceptionInfo *exception;
14113
+ #endif
14114
+
12835
14115
  Image *image = rm_check_frozen(self);
14116
+
14117
+ #if defined(IMAGEMAGICK_7)
14118
+ exception = AcquireExceptionInfo();
14119
+ (void) StripImage(image, exception);
14120
+ CHECK_EXCEPTION()
14121
+ (void) DestroyExceptionInfo(exception);
14122
+ #else
12836
14123
  (void) StripImage(image);
12837
14124
  rm_check_image_exception(image, RetainOnError);
14125
+ #endif
12838
14126
  return self;
12839
14127
  }
12840
14128
 
@@ -12861,7 +14149,12 @@ Image_swirl(VALUE self, VALUE degrees_obj)
12861
14149
  image = rm_check_destroyed(self);
12862
14150
 
12863
14151
  exception = AcquireExceptionInfo();
14152
+
14153
+ #if defined(IMAGEMAGICK_7)
14154
+ new_image = SwirlImage(image, degrees, image->interpolate, exception);
14155
+ #else
12864
14156
  new_image = SwirlImage(image, degrees, exception);
14157
+ #endif
12865
14158
  rm_check_exception(exception, new_image, DestroyOnError);
12866
14159
 
12867
14160
  (void) DestroyExceptionInfo(exception);
@@ -12906,6 +14199,9 @@ Image_texture_flood_fill(VALUE self, VALUE color_obj, VALUE texture_obj
12906
14199
  PaintMethod method;
12907
14200
  MagickPixel color_mpp;
12908
14201
  MagickBooleanType invert;
14202
+ #if defined(IMAGEMAGICK_7)
14203
+ ExceptionInfo *exception;
14204
+ #endif
12909
14205
 
12910
14206
  image = rm_check_destroyed(self);
12911
14207
 
@@ -12955,10 +14251,18 @@ Image_texture_flood_fill(VALUE self, VALUE color_obj, VALUE texture_obj
12955
14251
  color_mpp.blue = (MagickRealType) color.blue;
12956
14252
  }
12957
14253
 
14254
+ #if defined(IMAGEMAGICK_7)
14255
+ exception = AcquireExceptionInfo();
14256
+ (void) FloodfillPaintImage(new_image, draw_info, &color_mpp, x, y, invert, exception);
14257
+ (void) DestroyDrawInfo(draw_info);
14258
+ rm_check_exception(exception, new_image, DestroyOnError);
14259
+ (void) DestroyExceptionInfo(exception);
14260
+ #else
12958
14261
  (void) FloodfillPaintImage(new_image, DefaultChannels, draw_info, &color_mpp, x, y, invert);
12959
14262
 
12960
14263
  (void) DestroyDrawInfo(draw_info);
12961
14264
  rm_check_image_exception(new_image, DestroyOnError);
14265
+ #endif
12962
14266
 
12963
14267
  RB_GC_GUARD(texture);
12964
14268
 
@@ -12982,12 +14286,22 @@ Image_threshold(VALUE self, VALUE threshold_obj)
12982
14286
  {
12983
14287
  Image *image, *new_image;
12984
14288
  double threshold = NUM2DBL(threshold_obj);
14289
+ #if defined(IMAGEMAGICK_7)
14290
+ ExceptionInfo *exception;
14291
+ #endif
12985
14292
 
12986
14293
  image = rm_check_destroyed(self);
12987
14294
  new_image = rm_clone_image(image);
12988
14295
 
14296
+ #if defined(IMAGEMAGICK_7)
14297
+ exception = AcquireExceptionInfo();
14298
+ (void) BilevelImage(new_image, threshold, exception);
14299
+ rm_check_exception(exception, new_image, DestroyOnError);
14300
+ (void) DestroyExceptionInfo(exception);
14301
+ #else
12989
14302
  (void) BilevelImageChannel(new_image, DefaultChannels, threshold);
12990
14303
  rm_check_image_exception(new_image, DestroyOnError);
14304
+ #endif
12991
14305
 
12992
14306
  return rm_image_new(new_image);
12993
14307
  }
@@ -13010,6 +14324,9 @@ VALUE threshold_image(int argc, VALUE *argv, VALUE self, thresholder_t threshold
13010
14324
  Image *image, *new_image;
13011
14325
  double red, green, blue, alpha;
13012
14326
  char ctarg[200];
14327
+ #if defined(IMAGEMAGICK_7)
14328
+ ExceptionInfo *exception;
14329
+ #endif
13013
14330
 
13014
14331
  image = rm_check_destroyed(self);
13015
14332
 
@@ -13043,8 +14360,15 @@ VALUE threshold_image(int argc, VALUE *argv, VALUE self, thresholder_t threshold
13043
14360
 
13044
14361
  new_image = rm_clone_image(image);
13045
14362
 
14363
+ #if defined(IMAGEMAGICK_7)
14364
+ exception = AcquireExceptionInfo();
14365
+ (thresholder)(new_image, ctarg, exception);
14366
+ rm_check_exception(exception, new_image, DestroyOnError);
14367
+ (void) DestroyExceptionInfo(exception);
14368
+ #else
13046
14369
  (thresholder)(new_image, ctarg);
13047
14370
  rm_check_image_exception(new_image, DestroyOnError);
14371
+ #endif
13048
14372
 
13049
14373
  return rm_image_new(new_image);
13050
14374
  }
@@ -13284,7 +14608,11 @@ Image_tint(int argc, VALUE *argv, VALUE self)
13284
14608
  Color_to_PixelColor(&tint, argv[0]);
13285
14609
  exception = AcquireExceptionInfo();
13286
14610
 
14611
+ #if defined(IMAGEMAGICK_7)
14612
+ new_image = TintImage(image, alpha, &tint, exception);
14613
+ #else
13287
14614
  new_image = TintImage(image, alpha, tint, exception);
14615
+ #endif
13288
14616
  rm_check_exception(exception, new_image, DestroyOnError);
13289
14617
 
13290
14618
  (void) DestroyExceptionInfo(exception);
@@ -13328,14 +14656,20 @@ Image_to_blob(VALUE self)
13328
14656
 
13329
14657
  image = rm_check_destroyed(self);
13330
14658
 
14659
+ exception = AcquireExceptionInfo();
14660
+
13331
14661
  // Copy the depth and magick fields to the Image
13332
14662
  if (info->depth != 0)
13333
14663
  {
14664
+ #if defined(IMAGEMAGICK_7)
14665
+ (void) SetImageDepth(image, info->depth, exception);
14666
+ CHECK_EXCEPTION()
14667
+ #else
13334
14668
  (void) SetImageDepth(image, info->depth);
13335
14669
  rm_check_image_exception(image, RetainOnError);
14670
+ #endif
13336
14671
  }
13337
14672
 
13338
- exception = AcquireExceptionInfo();
13339
14673
  if (*info->magick)
13340
14674
  {
13341
14675
  (void) SetImageInfo(info, MagickTrue, exception);
@@ -13412,6 +14746,11 @@ Image_to_color(VALUE self, VALUE pixel_arg)
13412
14746
  Color_to_PixelColor(&pixel, pixel_arg);
13413
14747
  exception = AcquireExceptionInfo();
13414
14748
 
14749
+ #if defined(IMAGEMAGICK_7)
14750
+ pixel.depth = MAGICKCORE_QUANTUM_DEPTH;
14751
+ pixel.colorspace = image->colorspace;
14752
+ #endif
14753
+
13415
14754
  // QueryColorname returns False if the color represented by the PixelPacket
13416
14755
  // doesn't have a "real" name, just a sequence of hex digits. We don't care
13417
14756
  // about that.
@@ -13464,10 +14803,22 @@ Image_total_ink_density(VALUE self)
13464
14803
  {
13465
14804
  Image *image;
13466
14805
  double density;
14806
+ #if defined(IMAGEMAGICK_7)
14807
+ ExceptionInfo *exception;
14808
+ #endif
13467
14809
 
13468
14810
  image = rm_check_destroyed(self);
14811
+
14812
+ #if defined(IMAGEMAGICK_7)
14813
+ exception = AcquireExceptionInfo();
14814
+ density = GetImageTotalInkDensity(image, exception);
14815
+ CHECK_EXCEPTION()
14816
+ (void) DestroyExceptionInfo(exception);
14817
+ #else
13469
14818
  density = GetImageTotalInkDensity(image);
13470
14819
  rm_check_image_exception(image, RetainOnError);
14820
+ #endif
14821
+
13471
14822
  return rb_float_new(density);
13472
14823
  }
13473
14824
 
@@ -13499,6 +14850,10 @@ Image_transparent(int argc, VALUE *argv, VALUE self)
13499
14850
  MagickPixel color;
13500
14851
  Quantum alpha = TransparentAlpha;
13501
14852
  MagickBooleanType okay;
14853
+ #if defined(IMAGEMAGICK_7)
14854
+ ExceptionInfo *exception;
14855
+ #endif
14856
+
13502
14857
 
13503
14858
  image = rm_check_destroyed(self);
13504
14859
 
@@ -13516,8 +14871,15 @@ Image_transparent(int argc, VALUE *argv, VALUE self)
13516
14871
 
13517
14872
  new_image = rm_clone_image(image);
13518
14873
 
14874
+ #if defined(IMAGEMAGICK_7)
14875
+ exception = AcquireExceptionInfo();
14876
+ okay = TransparentPaintImage(new_image, &color, alpha, MagickFalse, exception);
14877
+ rm_check_exception(exception, new_image, DestroyOnError);
14878
+ (void) DestroyExceptionInfo(exception);
14879
+ #else
13519
14880
  okay = TransparentPaintImage(new_image, &color, QuantumRange - alpha, MagickFalse);
13520
14881
  rm_check_image_exception(new_image, DestroyOnError);
14882
+ #endif
13521
14883
  if (!okay)
13522
14884
  {
13523
14885
  // Force exception
@@ -13555,6 +14917,9 @@ Image_transparent_chroma(int argc, VALUE *argv, VALUE self)
13555
14917
  MagickPixel low, high;
13556
14918
  MagickBooleanType invert = MagickFalse;
13557
14919
  MagickBooleanType okay;
14920
+ #if defined(IMAGEMAGICK_7)
14921
+ ExceptionInfo *exception;
14922
+ #endif
13558
14923
 
13559
14924
  image = rm_check_destroyed(self);
13560
14925
 
@@ -13582,8 +14947,15 @@ Image_transparent_chroma(int argc, VALUE *argv, VALUE self)
13582
14947
 
13583
14948
  new_image = rm_clone_image(image);
13584
14949
 
14950
+ #if defined(IMAGEMAGICK_7)
14951
+ exception = AcquireExceptionInfo();
14952
+ okay = TransparentPaintImageChroma(new_image, &low, &high, alpha, invert, exception);
14953
+ rm_check_exception(exception, new_image, DestroyOnError);
14954
+ (void) DestroyExceptionInfo(exception);
14955
+ #else
13585
14956
  okay = TransparentPaintImageChroma(new_image, &low, &high, QuantumRange - alpha, invert);
13586
14957
  rm_check_image_exception(new_image, DestroyOnError);
14958
+ #endif
13587
14959
  if (!okay)
13588
14960
  {
13589
14961
  // Force exception
@@ -13865,14 +15237,20 @@ VALUE Image_image_type(VALUE self)
13865
15237
  {
13866
15238
  Image *image;
13867
15239
  ImageType type;
15240
+ #if defined(IMAGEMAGICK_6)
13868
15241
  ExceptionInfo *exception;
15242
+ #endif
13869
15243
 
13870
15244
  image = rm_check_destroyed(self);
15245
+ #if defined(IMAGEMAGICK_7)
15246
+ type = GetImageType(image);
15247
+ #else
13871
15248
  exception = AcquireExceptionInfo();
13872
15249
  type = GetImageType(image, exception);
13873
15250
  CHECK_EXCEPTION()
13874
15251
 
13875
15252
  (void) DestroyExceptionInfo(exception);
15253
+ #endif
13876
15254
 
13877
15255
  return ImageType_find(type);
13878
15256
  }
@@ -13892,10 +15270,20 @@ VALUE Image_image_type_eq(VALUE self, VALUE image_type)
13892
15270
  {
13893
15271
  Image *image;
13894
15272
  ImageType type;
15273
+ #if defined(IMAGEMAGICK_7)
15274
+ ExceptionInfo *exception;
15275
+ #endif
13895
15276
 
13896
15277
  image = rm_check_frozen(self);
13897
15278
  VALUE_TO_ENUM(image_type, type, ImageType);
15279
+ #if defined(IMAGEMAGICK_7)
15280
+ exception = AcquireExceptionInfo();
15281
+ SetImageType(image, type, exception);
15282
+ CHECK_EXCEPTION()
15283
+ (void) DestroyExceptionInfo(exception);
15284
+ #else
13898
15285
  SetImageType(image, type);
15286
+ #endif
13899
15287
  return image_type;
13900
15288
  }
13901
15289
 
@@ -13998,23 +15386,38 @@ Image_units_eq(VALUE self, VALUE restype)
13998
15386
  case PixelsPerInchResolution:
13999
15387
  if (units == PixelsPerCentimeterResolution)
14000
15388
  {
15389
+ #if defined(IMAGEMAGICK_7)
15390
+ image->resolution.x /= 2.54;
15391
+ image->resolution.y /= 2.54;
15392
+ #else
14001
15393
  image->x_resolution /= 2.54;
14002
15394
  image->y_resolution /= 2.54;
15395
+ #endif
14003
15396
  }
14004
15397
  break;
14005
15398
 
14006
15399
  case PixelsPerCentimeterResolution:
14007
15400
  if (units == PixelsPerInchResolution)
14008
15401
  {
15402
+ #if defined(IMAGEMAGICK_7)
15403
+ image->resolution.x *= 2.54;
15404
+ image->resolution.y *= 2.54;
15405
+ #else
14009
15406
  image->x_resolution *= 2.54;
14010
15407
  image->y_resolution *= 2.54;
15408
+ #endif
14011
15409
  }
14012
15410
  break;
14013
15411
 
14014
15412
  default:
14015
15413
  // UndefinedResolution
15414
+ #if defined(IMAGEMAGICK_7)
15415
+ image->resolution.x = 0.0;
15416
+ image->resolution.y = 0.0;
15417
+ #else
14016
15418
  image->x_resolution = 0.0;
14017
15419
  image->y_resolution = 0.0;
15420
+ #endif
14018
15421
  break;
14019
15422
  }
14020
15423
 
@@ -14171,7 +15574,14 @@ Image_unsharp_mask_channel(int argc, VALUE *argv, VALUE self)
14171
15574
  unsharp_mask_args(argc, argv, &radius, &sigma, &amount, &threshold);
14172
15575
 
14173
15576
  exception = AcquireExceptionInfo();
15577
+ #if defined(IMAGEMAGICK_7)
15578
+ BEGIN_CHANNEL_MASK(image, channels);
15579
+ new_image = UnsharpMaskImage(image, radius, sigma, amount, threshold, exception);
15580
+ CHANGE_RESULT_CHANNEL_MASK(new_image);
15581
+ END_CHANNEL_MASK(image);
15582
+ #else
14174
15583
  new_image = UnsharpMaskImageChannel(image, channels, radius, sigma, amount, threshold, exception);
15584
+ #endif
14175
15585
  rm_check_exception(exception, new_image, DestroyOnError);
14176
15586
 
14177
15587
  (void) DestroyExceptionInfo(exception);
@@ -14283,11 +15693,21 @@ Image_virtual_pixel_method_eq(VALUE self, VALUE method)
14283
15693
  {
14284
15694
  Image *image;
14285
15695
  VirtualPixelMethod vpm;
15696
+ #if defined(IMAGEMAGICK_7)
15697
+ ExceptionInfo *exception;
15698
+ #endif
14286
15699
 
14287
15700
  image = rm_check_frozen(self);
14288
15701
  VALUE_TO_ENUM(method, vpm, VirtualPixelMethod);
15702
+ #if defined(IMAGEMAGICK_7)
15703
+ exception = AcquireExceptionInfo();
15704
+ (void) SetImageVirtualPixelMethod(image, vpm, exception);
15705
+ CHECK_EXCEPTION()
15706
+ (void) DestroyExceptionInfo(exception);
15707
+ #else
14289
15708
  (void) SetImageVirtualPixelMethod(image, vpm);
14290
15709
  rm_check_image_exception(image, RetainOnError);
15710
+ #endif
14291
15711
  return method;
14292
15712
  }
14293
15713
 
@@ -14322,6 +15742,9 @@ Image_watermark(int argc, VALUE *argv, VALUE self)
14322
15742
  long x_offset = 0L, y_offset = 0L;
14323
15743
  char geometry[20];
14324
15744
  VALUE ovly;
15745
+ #if defined(IMAGEMAGICK_7)
15746
+ ExceptionInfo *exception;
15747
+ #endif
14325
15748
 
14326
15749
  image = rm_check_destroyed(self);
14327
15750
 
@@ -14358,9 +15781,16 @@ Image_watermark(int argc, VALUE *argv, VALUE self)
14358
15781
  (void) SetImageArtifact(overlay,"compose:args", geometry);
14359
15782
 
14360
15783
  new_image = rm_clone_image(image);
15784
+ #if defined(IMAGEMAGICK_7)
15785
+ exception = AcquireExceptionInfo();
15786
+ (void) CompositeImage(new_image, overlay, ModulateCompositeOp, MagickTrue, x_offset, y_offset, exception);
15787
+ rm_check_exception(exception, new_image, DestroyOnError);
15788
+ (void) DestroyExceptionInfo(exception);
15789
+ #else
14361
15790
  (void) CompositeImage(new_image, ModulateCompositeOp, overlay, x_offset, y_offset);
14362
15791
 
14363
15792
  rm_check_image_exception(new_image, DestroyOnError);
15793
+ #endif
14364
15794
 
14365
15795
  RB_GC_GUARD(ovly);
14366
15796
 
@@ -14409,7 +15839,11 @@ Image_wave(int argc, VALUE *argv, VALUE self)
14409
15839
  }
14410
15840
 
14411
15841
  exception = AcquireExceptionInfo();
15842
+ #if defined(IMAGEMAGICK_7)
15843
+ new_image = WaveImage(image, amplitude, wavelength, image->interpolate, exception);
15844
+ #else
14412
15845
  new_image = WaveImage(image, amplitude, wavelength, exception);
15846
+ #endif
14413
15847
  rm_check_exception(exception, new_image, DestroyOnError);
14414
15848
 
14415
15849
  (void) DestroyExceptionInfo(exception);
@@ -14451,8 +15885,13 @@ VALUE
14451
15885
  Image_wet_floor(int argc, VALUE *argv, VALUE self)
14452
15886
  {
14453
15887
  Image *image, *reflection, *flip_image;
15888
+ #if defined(IMAGEMAGICK_7)
15889
+ const Quantum *p;
15890
+ Quantum *q;
15891
+ #else
14454
15892
  const PixelPacket *p;
14455
15893
  PixelPacket *q;
15894
+ #endif
14456
15895
  RectangleInfo geometry;
14457
15896
  long x, y, max_rows;
14458
15897
  double initial = 0.5;
@@ -14485,7 +15924,11 @@ Image_wet_floor(int argc, VALUE *argv, VALUE self)
14485
15924
  rb_raise(rb_eArgError, "Transparency change rate must be >= 0.0 (%g)", rate);
14486
15925
  }
14487
15926
 
15927
+ #if defined(IMAGEMAGICK_7)
15928
+ initial *= QuantumRange;
15929
+ #else
14488
15930
  initial *= TransparentOpacity;
15931
+ #endif
14489
15932
 
14490
15933
  // The number of rows in which to transition from the initial level of
14491
15934
  // transparency to complete transparency. rate == 0.0 -> no change.
@@ -14493,7 +15936,11 @@ Image_wet_floor(int argc, VALUE *argv, VALUE self)
14493
15936
  {
14494
15937
  max_rows = (long)((double)image->rows) / (3.0 * rate);
14495
15938
  max_rows = (long)min((unsigned long)max_rows, image->rows);
15939
+ #if defined(IMAGEMAGICK_7)
15940
+ step = (QuantumRange - initial) / max_rows;
15941
+ #else
14496
15942
  step = (TransparentOpacity - initial) / max_rows;
15943
+ #endif
14497
15944
  }
14498
15945
  else
14499
15946
  {
@@ -14516,19 +15963,33 @@ Image_wet_floor(int argc, VALUE *argv, VALUE self)
14516
15963
  CHECK_EXCEPTION();
14517
15964
 
14518
15965
 
15966
+ #if defined(IMAGEMAGICK_7)
15967
+ (void) SetImageStorageClass(reflection, DirectClass, exception);
15968
+ rm_check_exception(exception, reflection, DestroyOnError);
15969
+ (void) SetImageAlphaChannel(reflection, ActivateAlphaChannel, exception);
15970
+ rm_check_exception(exception, reflection, DestroyOnError);
15971
+ #else
14519
15972
  (void) SetImageStorageClass(reflection, DirectClass);
14520
15973
  rm_check_image_exception(reflection, DestroyOnError);
14521
15974
 
14522
15975
 
14523
15976
  reflection->matte = MagickTrue;
15977
+ #endif
14524
15978
  opacity = initial;
14525
15979
 
14526
15980
  for (y = 0; y < max_rows; y++)
14527
15981
  {
15982
+ #if defined(IMAGEMAGICK_7)
15983
+ if (opacity > QuantumRange)
15984
+ {
15985
+ opacity = QuantumRange;
15986
+ }
15987
+ #else
14528
15988
  if (opacity > TransparentOpacity)
14529
15989
  {
14530
15990
  opacity = TransparentOpacity;
14531
15991
  }
15992
+ #endif
14532
15993
 
14533
15994
  p = GetVirtualPixels(reflection, 0, y, image->columns, 1, exception);
14534
15995
  rm_check_exception(exception, reflection, DestroyOnError);
@@ -14551,7 +16012,14 @@ Image_wet_floor(int argc, VALUE *argv, VALUE self)
14551
16012
  {
14552
16013
  q[x] = p[x];
14553
16014
  // Never make a pixel *less* transparent than it already is.
16015
+ #if defined(IMAGEMAGICK_7)
16016
+ SetPixelAlpha(reflection, min(GetPixelAlpha(image, q), QuantumRange - (Quantum)opacity), q);
16017
+
16018
+ p += GetPixelChannels(reflection);
16019
+ q += GetPixelChannels(reflection);
16020
+ #else
14554
16021
  q[x].opacity = max(q[x].opacity, (Quantum)opacity);
16022
+ #endif
14555
16023
  }
14556
16024
 
14557
16025
 
@@ -14702,6 +16170,9 @@ Image_write(VALUE self, VALUE file)
14702
16170
  Image *image;
14703
16171
  Info *info;
14704
16172
  VALUE info_obj;
16173
+ #if defined(IMAGEMAGICK_7)
16174
+ ExceptionInfo *exception;
16175
+ #endif
14705
16176
 
14706
16177
  image = rm_check_destroyed(self);
14707
16178
 
@@ -14734,18 +16205,30 @@ Image_write(VALUE self, VALUE file)
14734
16205
  rm_sync_image_options(image, info);
14735
16206
 
14736
16207
  info->adjoin = MagickFalse;
16208
+ #if defined(IMAGEMAGICK_7)
16209
+ exception = AcquireExceptionInfo();
16210
+ (void) WriteImage(info, image, exception);
16211
+ CHECK_EXCEPTION()
16212
+ (void) DestroyExceptionInfo(exception);
16213
+ #else
14737
16214
  (void) WriteImage(info, image);
14738
16215
  rm_check_image_exception(image, RetainOnError);
16216
+ #endif
14739
16217
 
14740
16218
  RB_GC_GUARD(info_obj);
14741
16219
 
14742
16220
  return self;
14743
16221
  }
14744
16222
 
16223
+ #if defined(IMAGEMAGICK_7)
16224
+ DEF_ATTR_ACCESSORF(Image, x_resolution, resolution.x, dbl)
14745
16225
 
16226
+ DEF_ATTR_ACCESSORF(Image, y_resolution, resolution.y, dbl)
16227
+ #else
14746
16228
  DEF_ATTR_ACCESSOR(Image, x_resolution, dbl)
14747
16229
 
14748
16230
  DEF_ATTR_ACCESSOR(Image, y_resolution, dbl)
16231
+ #endif
14749
16232
 
14750
16233
 
14751
16234
  /**
@@ -14978,11 +16461,13 @@ xform_image(int bang, VALUE self, VALUE x, VALUE y, VALUE width, VALUE height, x
14978
16461
  rm_check_exception(exception, new_image, DestroyOnError);
14979
16462
  (void) DestroyExceptionInfo(exception);
14980
16463
 
16464
+ #if defined(IMAGEMAGICK_6)
14981
16465
  if (rm_should_raise_exception(&image->exception, RetainExceptionRetention))
14982
16466
  {
14983
16467
  (void) DestroyImage(new_image);
14984
16468
  rm_check_image_exception(image, RetainOnError);
14985
16469
  }
16470
+ #endif
14986
16471
 
14987
16472
  rm_ensure_result(new_image);
14988
16473