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.

@@ -289,7 +289,11 @@ Export_ColorInfo(ColorInfo *ci, VALUE st)
289
289
  ci->color.red = (MagickRealType) pixel.red;
290
290
  ci->color.green = (MagickRealType) pixel.green;
291
291
  ci->color.blue = (MagickRealType) pixel.blue;
292
+ #if defined(IMAGEMAGICK_7)
293
+ ci->color.alpha = (MagickRealType) OpaqueAlpha;
294
+ #else
292
295
  ci->color.opacity = (MagickRealType) OpaqueOpacity;
296
+ #endif
293
297
  ci->color.index = (MagickRealType) 0;
294
298
  }
295
299
 
@@ -322,7 +326,11 @@ Color_to_MagickPixel(Image *image, MagickPixel *mpp, VALUE color)
322
326
  mpp->red = (MagickRealType) pp.red;
323
327
  mpp->green = (MagickRealType) pp.green;
324
328
  mpp->blue = (MagickRealType) pp.blue;
329
+ #if defined(IMAGEMAGICK_7)
330
+ mpp->alpha = (MagickRealType) pp.alpha;
331
+ #else
325
332
  mpp->opacity = (MagickRealType) pp.opacity;
333
+ #endif
326
334
  }
327
335
 
328
336
 
@@ -367,7 +375,12 @@ Color_to_s(VALUE self)
367
375
  #endif
368
376
  ci.name,
369
377
  ComplianceType_name(&ci.compliance),
370
- ci.color.red, ci.color.green, ci.color.blue, QuantumRange - ci.color.opacity);
378
+ ci.color.red, ci.color.green, ci.color.blue,
379
+ #if defined(IMAGEMAGICK_7)
380
+ ci.color.alpha);
381
+ #else
382
+ QuantumRange - ci.color.opacity);
383
+ #endif
371
384
 
372
385
  destroy_ColorInfo(&ci);
373
386
  return rb_str_new2(buff);
@@ -626,7 +626,18 @@ rm_app2quantum(VALUE obj)
626
626
  Image *
627
627
  rm_acquire_image(ImageInfo *info)
628
628
  {
629
+ #if defined(IMAGEMAGICK_7)
630
+ Image *new_image;
631
+ ExceptionInfo *exception;
632
+
633
+ exception = AcquireExceptionInfo();
634
+ new_image = AcquireImage(info, exception);
635
+ CHECK_EXCEPTION()
636
+ (void) DestroyExceptionInfo(exception);
637
+ return new_image;
638
+ #else
629
639
  return AcquireImage(info);
640
+ #endif
630
641
  }
631
642
 
632
643
 
@@ -660,12 +671,19 @@ rm_cur_image(VALUE img)
660
671
  VALUE
661
672
  rm_pixelcolor_to_color_name(Image *image, PixelColor *color)
662
673
  {
674
+ PixelColor pp;
663
675
  char name[MaxTextExtent];
664
676
  ExceptionInfo *exception;
665
677
 
666
678
  exception = AcquireExceptionInfo();
667
679
 
668
- (void) QueryColorname(image, color, X11Compliance, name, exception);
680
+ pp = *color;
681
+ #if defined(IMAGEMAGICK_7)
682
+ pp.depth = MAGICKCORE_QUANTUM_DEPTH;
683
+ pp.colorspace = image->colorspace;
684
+ #endif
685
+
686
+ (void) QueryColorname(image, &pp, X11Compliance, name, exception);
669
687
  CHECK_EXCEPTION()
670
688
  (void) DestroyExceptionInfo(exception);
671
689
 
@@ -701,7 +719,12 @@ rm_pixelcolor_to_color_name_info(Info *info, PixelColor *color)
701
719
  rb_raise(rb_eNoMemError, "not enough memory to continue.");
702
720
  }
703
721
 
722
+ #if defined(IMAGEMAGICK_7)
723
+ image->alpha_trait = UndefinedPixelTrait;
724
+ #else
704
725
  image->matte = MagickFalse;
726
+ #endif
727
+
705
728
  color_name = rm_pixelcolor_to_color_name(image, color);
706
729
  (void) DestroyImage(image);
707
730
 
@@ -719,7 +742,11 @@ rm_pixelcolor_to_color_name_info(Info *info, PixelColor *color)
719
742
  void
720
743
  rm_init_magickpixel(const Image *image, MagickPixel *pp)
721
744
  {
745
+ #if defined(IMAGEMAGICK_7)
746
+ GetPixelInfo(image, pp);
747
+ #else
722
748
  GetMagickPixelPacket(image, pp);
749
+ #endif
723
750
  }
724
751
 
725
752
  /**
@@ -736,7 +763,12 @@ rm_set_magickpixel(MagickPixel *pp, const char *color)
736
763
  ExceptionInfo *exception;
737
764
 
738
765
  exception = AcquireExceptionInfo();
766
+
767
+ #if defined(IMAGEMAGICK_7)
768
+ (void) QueryColorCompliance(color, AllCompliance, pp, exception);
769
+ #else
739
770
  (void) QueryMagickColor(color, pp, exception);
771
+ #endif
740
772
  // This exception is ignored because the color comes from places where we control
741
773
  // the value and it is very unlikely that an exception will be thrown.
742
774
  (void) DestroyExceptionInfo(exception);
@@ -922,7 +954,18 @@ ImageMagickError_initialize(int argc, VALUE *argv, VALUE self)
922
954
  const char *
923
955
  rm_get_property(const Image *img, const char *property)
924
956
  {
957
+ #if defined(IMAGEMAGICK_7)
958
+ const char *result;
959
+ ExceptionInfo *exception;
960
+
961
+ exception = AcquireExceptionInfo();
962
+ result = GetImageProperty(img, property, exception);
963
+ CHECK_EXCEPTION()
964
+ (void) DestroyExceptionInfo(exception);
965
+ return result;
966
+ #else
925
967
  return GetImageProperty(img, property);
968
+ #endif
926
969
  }
927
970
 
928
971
 
@@ -939,7 +982,18 @@ rm_get_property(const Image *img, const char *property)
939
982
  MagickBooleanType
940
983
  rm_set_property(Image *image, const char *property, const char *value)
941
984
  {
985
+ #if defined(IMAGEMAGICK_7)
986
+ ExceptionInfo *exception;
987
+ MagickBooleanType okay;
988
+
989
+ exception = AcquireExceptionInfo();
990
+ okay = SetImageProperty(image, property, value, exception);
991
+ CHECK_EXCEPTION()
992
+ (void) DestroyExceptionInfo(exception);
993
+ return okay;
994
+ #else
942
995
  return SetImageProperty(image, property, value);
996
+ #endif
943
997
  }
944
998
 
945
999
 
@@ -1046,6 +1100,9 @@ void rm_sync_image_options(Image *image, Info *info)
1046
1100
  MagickStatusType flags;
1047
1101
  GeometryInfo geometry_info;
1048
1102
  const char *option;
1103
+ #if defined(IMAGEMAGICK_7)
1104
+ ExceptionInfo *exception;
1105
+ #endif
1049
1106
 
1050
1107
  // The option strings will be set only when their attribute values were
1051
1108
  // set in the optional argument block.
@@ -1063,7 +1120,16 @@ void rm_sync_image_options(Image *image, Info *info)
1063
1120
 
1064
1121
  if (info->colorspace != UndefinedColorspace)
1065
1122
  {
1123
+ #if defined(IMAGEMAGICK_7)
1124
+ exception = AcquireExceptionInfo();
1125
+ SetImageColorspace(image, info->colorspace, exception);
1126
+ // We should not throw an exception in this method because we will
1127
+ // leak memory in the place where this method is called. And that is
1128
+ // why the exception is being ignored here.
1129
+ (void) DestroyExceptionInfo(exception);
1130
+ #else
1066
1131
  SetImageColorspace(image, info->colorspace);
1132
+ #endif
1067
1133
  }
1068
1134
 
1069
1135
  if (info->compression != UndefinedCompression)
@@ -1080,11 +1146,20 @@ void rm_sync_image_options(Image *image, Info *info)
1080
1146
  if (info->density)
1081
1147
  {
1082
1148
  flags = ParseGeometry(info->density, &geometry_info);
1149
+ #if defined(IMAGEMAGICK_7)
1150
+ image->resolution.x = geometry_info.rho;
1151
+ image->resolution.y = geometry_info.sigma;
1152
+ #else
1083
1153
  image->x_resolution = geometry_info.rho;
1084
1154
  image->y_resolution = geometry_info.sigma;
1155
+ #endif
1085
1156
  if ((flags & SigmaValue) == 0)
1086
1157
  {
1158
+ #if defined(IMAGEMAGICK_7)
1159
+ image->resolution.y = image->resolution.x;
1160
+ #else
1087
1161
  image->y_resolution = image->x_resolution;
1162
+ #endif
1088
1163
  }
1089
1164
  }
1090
1165
 
@@ -1174,8 +1249,13 @@ void rm_sync_image_options(Image *image, Info *info)
1174
1249
  {
1175
1250
  if (info->units == PixelsPerCentimeterResolution)
1176
1251
  {
1252
+ #if defined(IMAGEMAGICK_7)
1253
+ image->resolution.x /= 2.54;
1254
+ image->resolution.y /= 2.54;
1255
+ #else
1177
1256
  image->x_resolution /= 2.54;
1178
1257
  image->y_resolution /= 2.54;
1258
+ #endif
1179
1259
  }
1180
1260
  break;
1181
1261
  }
@@ -1183,8 +1263,13 @@ void rm_sync_image_options(Image *image, Info *info)
1183
1263
  {
1184
1264
  if (info->units == PixelsPerInchResolution)
1185
1265
  {
1266
+ #if defined(IMAGEMAGICK_7)
1267
+ image->resolution.x *= 2.54;
1268
+ image->resolution.y *= 2.54;
1269
+ #else
1186
1270
  image->x_resolution *= 2.54;
1187
1271
  image->y_resolution *= 2.54;
1272
+ #endif
1188
1273
  }
1189
1274
  break;
1190
1275
  }
@@ -1219,8 +1304,16 @@ rm_exif_by_entry(Image *image)
1219
1304
  char *str;
1220
1305
  size_t len = 0, property_l, value_l;
1221
1306
  VALUE v;
1307
+ #if defined(IMAGEMAGICK_7)
1308
+ ExceptionInfo *exception;
1222
1309
 
1310
+ exception = AcquireExceptionInfo();
1311
+ (void) GetImageProperty(image, "exif:*", exception);
1312
+ CHECK_EXCEPTION()
1313
+ #else
1223
1314
  (void) GetImageProperty(image, "exif:*");
1315
+ #endif
1316
+
1224
1317
  ResetImagePropertyIterator(image);
1225
1318
  property = GetNextImageProperty(image);
1226
1319
 
@@ -1236,7 +1329,12 @@ rm_exif_by_entry(Image *image)
1236
1329
  len += 1; // there will be a \n between property=value entries
1237
1330
  }
1238
1331
  len += property_l - 5;
1239
- value = GetImageProperty(image,property);
1332
+ #if defined(IMAGEMAGICK_7)
1333
+ value = GetImageProperty(image, property, exception);
1334
+ CHECK_EXCEPTION()
1335
+ #else
1336
+ value = GetImageProperty(image, property);
1337
+ #endif
1240
1338
  if (value)
1241
1339
  {
1242
1340
  // add 1 for the = between property and value
@@ -1248,8 +1346,12 @@ rm_exif_by_entry(Image *image)
1248
1346
 
1249
1347
  if (len == 0)
1250
1348
  {
1349
+ #if defined(IMAGEMAGICK_7)
1350
+ (void) DestroyExceptionInfo(exception);
1351
+ #endif
1251
1352
  return Qnil;
1252
1353
  }
1354
+
1253
1355
  str = xmalloc(len);
1254
1356
  len = 0;
1255
1357
 
@@ -1268,7 +1370,16 @@ rm_exif_by_entry(Image *image)
1268
1370
  }
1269
1371
  memcpy(str+len, property+5, property_l-5);
1270
1372
  len += property_l - 5;
1271
- value = GetImageProperty(image,property);
1373
+ #if defined(IMAGEMAGICK_7)
1374
+ value = GetImageProperty(image, property, exception);
1375
+ if (rm_should_raise_exception(exception, RetainExceptionRetention))
1376
+ {
1377
+ xfree(str);
1378
+ rm_raise_exception(exception);
1379
+ }
1380
+ #else
1381
+ value = GetImageProperty(image, property);
1382
+ #endif
1272
1383
  if (value)
1273
1384
  {
1274
1385
  value_l = strlen(value);
@@ -1280,6 +1391,10 @@ rm_exif_by_entry(Image *image)
1280
1391
  property = GetNextImageProperty(image);
1281
1392
  }
1282
1393
 
1394
+ #if defined(IMAGEMAGICK_7)
1395
+ (void) DestroyExceptionInfo(exception);
1396
+ #endif
1397
+
1283
1398
  v = rb_str_new(str, len);
1284
1399
  xfree(str);
1285
1400
 
@@ -1308,8 +1423,15 @@ rm_exif_by_number(Image *image)
1308
1423
  char *str;
1309
1424
  size_t len = 0, property_l, value_l;
1310
1425
  VALUE v;
1426
+ #if defined(IMAGEMAGICK_7)
1427
+ ExceptionInfo *exception;
1311
1428
 
1429
+ exception = AcquireExceptionInfo();
1430
+ (void) GetImageProperty(image, "exif:!", exception);
1431
+ CHECK_EXCEPTION()
1432
+ #else
1312
1433
  (void) GetImageProperty(image, "exif:!");
1434
+ #endif
1313
1435
  ResetImagePropertyIterator(image);
1314
1436
  property = GetNextImageProperty(image);
1315
1437
 
@@ -1325,7 +1447,12 @@ rm_exif_by_number(Image *image)
1325
1447
  len += 1; // there will be a \n between property=value entries
1326
1448
  }
1327
1449
  len += property_l;
1328
- value = GetImageProperty(image,property);
1450
+ #if defined(IMAGEMAGICK_7)
1451
+ value = GetImageProperty(image, property, exception);
1452
+ CHECK_EXCEPTION()
1453
+ #else
1454
+ value = GetImageProperty(image, property);
1455
+ #endif
1329
1456
  if (value)
1330
1457
  {
1331
1458
  // add 1 for the = between property and value
@@ -1337,8 +1464,12 @@ rm_exif_by_number(Image *image)
1337
1464
 
1338
1465
  if (len == 0)
1339
1466
  {
1467
+ #if defined(IMAGEMAGICK_7)
1468
+ (void) DestroyExceptionInfo(exception);
1469
+ #endif
1340
1470
  return Qnil;
1341
1471
  }
1472
+
1342
1473
  str = xmalloc(len);
1343
1474
  len = 0;
1344
1475
 
@@ -1357,7 +1488,16 @@ rm_exif_by_number(Image *image)
1357
1488
  }
1358
1489
  memcpy(str+len, property, property_l);
1359
1490
  len += property_l;
1360
- value = GetImageProperty(image,property);
1491
+ #if defined(IMAGEMAGICK_7)
1492
+ value = GetImageProperty(image, property, exception);
1493
+ if (rm_should_raise_exception(exception, RetainExceptionRetention))
1494
+ {
1495
+ xfree(str);
1496
+ rm_raise_exception(exception);
1497
+ }
1498
+ #else
1499
+ value = GetImageProperty(image, property);
1500
+ #endif
1361
1501
  if (value)
1362
1502
  {
1363
1503
  value_l = strlen(value);
@@ -1369,6 +1509,10 @@ rm_exif_by_number(Image *image)
1369
1509
  property = GetNextImageProperty(image);
1370
1510
  }
1371
1511
 
1512
+ #if defined(IMAGEMAGICK_7)
1513
+ (void) DestroyExceptionInfo(exception);
1514
+ #endif
1515
+
1372
1516
  v = rb_str_new(str, len);
1373
1517
  xfree(str);
1374
1518
 
@@ -1551,6 +1695,7 @@ rm_split(Image *image)
1551
1695
  }
1552
1696
 
1553
1697
 
1698
+ #if defined(IMAGEMAGICK_6)
1554
1699
  /**
1555
1700
  * If an ExceptionInfo struct in a list of images indicates a warning, issue a
1556
1701
  * warning message. If an ExceptionInfo struct indicates an error, raise an
@@ -1600,6 +1745,7 @@ rm_check_image_exception(Image *imglist, ErrorRetention retention)
1600
1745
 
1601
1746
  (void) DestroyExceptionInfo(exception);
1602
1747
  }
1748
+ #endif
1603
1749
 
1604
1750
 
1605
1751
  #define ERROR_MSG_SIZE 1024
@@ -1,5 +1,5 @@
1
1
  module Magick
2
- VERSION = '4.0.0'
2
+ VERSION = '4.1.0.rc1'
3
3
  MIN_RUBY_VERSION = '2.3.0'
4
4
  MIN_IM_VERSION = '6.7.7'
5
5
  end
@@ -25,6 +25,7 @@ module Magick
25
25
  @formats = nil
26
26
  @trace_proc = nil
27
27
  @exit_block_set_up = nil
28
+ IMAGEMAGICK_VERSION = Magick::Magick_version.split[1].split('-').first
28
29
 
29
30
  class << self
30
31
  def formats
@@ -239,7 +240,8 @@ module Magick
239
240
  # colorization rule
240
241
  def alpha(x, y, method)
241
242
  Kernel.raise ArgumentError, 'Unknown paint method' unless PAINT_METHOD_NAMES.key?(method.to_i)
242
- primitive 'matte ' + format('%g,%g, %s', x, y, PAINT_METHOD_NAMES[method.to_i])
243
+ name = Gem::Version.new(Magick::IMAGEMAGICK_VERSION) > Gem::Version.new('7.0.0') ? 'alpha ' : 'matte '
244
+ primitive name + format('%g,%g, %s', x, y, PAINT_METHOD_NAMES[method.to_i])
243
245
  end
244
246
 
245
247
  # Draw an arc.
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
24
24
  s.executables = executables
25
25
  s.require_paths << 'ext' << 'deprecated'
26
26
 
27
- s.rubyforge_project = 'rmagick'
28
27
  s.extensions = %w[ext/RMagick/extconf.rb]
29
28
  s.required_ruby_version = ">= #{Magick::MIN_RUBY_VERSION}"
30
29
  s.requirements << "ImageMagick #{Magick::MIN_IM_VERSION} or later"
@@ -0,0 +1,54 @@
1
+ RSpec.describe Magick::Image, '#dissolve' do
2
+ let(:img1) { Magick::Image.new(100, 100) { self.background_color = 'transparent' } }
3
+ let(:img2) { Magick::Image.new(100, 100) { self.background_color = 'green' } }
4
+
5
+ it 'raises an error given invalid arguments' do
6
+ expect { img1.dissolve }.to raise_error(ArgumentError)
7
+ expect { img1.dissolve(img2, 'x') }.to raise_error(ArgumentError)
8
+ expect { img1.dissolve(img2, 0.50, 'x') }.to raise_error(ArgumentError)
9
+ expect { img1.dissolve(img2, 0.50, Magick::NorthEastGravity, 'x') }.to raise_error(TypeError)
10
+ expect { img1.dissolve(img2, 0.50, Magick::NorthEastGravity, 10, 'x') }.to raise_error(TypeError)
11
+ end
12
+
13
+ context 'when given 2 arguments' do
14
+ it 'works when alpha is float 0.0 to 1.0' do
15
+ dissolved = img1.dissolve(img2, 0.50)
16
+ expect(dissolved).to be_instance_of(Magick::Image)
17
+ expect(Float(dissolved.pixel_color(2, 2).alpha) / Magick::QuantumRange).to be_between(0.45, 0.55)
18
+ dissolved = img1.dissolve(img2, 0.20)
19
+ expect(Float(dissolved.pixel_color(2, 2).alpha) / Magick::QuantumRange).to be_between(0.15, 0.25)
20
+ end
21
+ it 'works when alpha is string percentage' do
22
+ dissolved = img1.dissolve(img2, '50%')
23
+ expect(dissolved).to be_instance_of(Magick::Image)
24
+ expect(Float(dissolved.pixel_color(2, 2).alpha) / Magick::QuantumRange).to be_between(0.45, 0.55)
25
+ dissolved = img1.dissolve(img2, '20%')
26
+ expect(Float(dissolved.pixel_color(2, 2).alpha) / Magick::QuantumRange).to be_between(0.15, 0.25)
27
+ end
28
+ end
29
+
30
+ context 'when given gravity' do
31
+ # generate an image to use with gravity
32
+ wk = Magick::Image.new(40, 40) { self.background_color = 'transparent' }
33
+ d = Magick::Draw.new
34
+ d.stroke('none').fill('blue')
35
+ d.circle(wk.columns / 2, wk.rows / 2, 4, wk.rows / 2)
36
+ d.draw(wk)
37
+
38
+ it 'works on colored background' do
39
+ # generate an image to use with gravity
40
+ dissolved = img2.dissolve(wk, 0.50, 1.0, Magick::CenterGravity)
41
+ expect(dissolved).to be_instance_of(Magick::Image)
42
+ expect(dissolved.pixel_color(10, 10)).to eq(img2.pixel_color(10, 10))
43
+ expect(Float(dissolved.pixel_color(50, 50).blue) / Magick::QuantumRange).to be_between(0.45, 0.55)
44
+ expect(Float(dissolved.pixel_color(50, 50).green)).to be_between(0, img2.pixel_color(2, 2).green).exclusive
45
+ end
46
+ end
47
+
48
+ # still need to test with destination percentage, offsets
49
+
50
+ it 'raises an error when the image has been destroyed' do
51
+ img1.destroy!
52
+ expect { img1.dissolve(img2, 0.50) }.to raise_error(Magick::DestroyedImageError)
53
+ end
54
+ end