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.

@@ -82,6 +82,17 @@ rm_enum_to_cstr(VALUE enum_type)
82
82
  return rb_id2name(magick_enum->id);
83
83
  }
84
84
 
85
+ /**
86
+ * Free Enum or Enum subclass object
87
+ *
88
+ * No Ruby usage (internal function)
89
+ *
90
+ * @param magick_enum the enum
91
+ */
92
+ static void rm_enum_free(void *magick_enum)
93
+ {
94
+ xfree(magick_enum);
95
+ }
85
96
  /**
86
97
  * Enum class alloc function.
87
98
  *
@@ -96,11 +107,9 @@ Enum_alloc(VALUE class)
96
107
  MagickEnum *magick_enum;
97
108
  VALUE enumr;
98
109
 
99
- enumr = Data_Make_Struct(class, MagickEnum, NULL, NULL, magick_enum);
110
+ enumr = Data_Make_Struct(class, MagickEnum, NULL, rm_enum_free, magick_enum);
100
111
  rb_obj_freeze(enumr);
101
112
 
102
- RB_GC_GUARD(enumr);
103
-
104
113
  return enumr;
105
114
  }
106
115
 
@@ -132,7 +132,11 @@ point_fill(
132
132
 
133
133
  for (y = 0; y < (ssize_t) image->rows; y++)
134
134
  {
135
+ #if defined(IMAGEMAGICK_7)
136
+ Quantum *row_pixels;
137
+ #else
135
138
  PixelPacket *row_pixels;
139
+ #endif
136
140
 
137
141
  row_pixels = QueueAuthenticPixels(image, 0, y, image->columns, 1, exception);
138
142
  CHECK_EXCEPTION()
@@ -140,10 +144,20 @@ point_fill(
140
144
  for (x = 0; x < (ssize_t) image->columns; x++)
141
145
  {
142
146
  distance = sqrt((double)((x-x0)*(x-x0)+(y-y0)*(y-y0)));
147
+
148
+ #if defined(IMAGEMAGICK_7)
149
+ SetPixelRed(image, ROUND_TO_QUANTUM(start_color->red + (distance * red_step)), row_pixels);
150
+ SetPixelGreen(image, ROUND_TO_QUANTUM(start_color->green + (distance * green_step)), row_pixels);
151
+ SetPixelBlue(image, ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step)), row_pixels);
152
+ SetPixelAlpha(image, OpaqueAlpha, row_pixels);
153
+
154
+ row_pixels += GetPixelChannels(image);
155
+ #else
143
156
  row_pixels[x].red = ROUND_TO_QUANTUM(start_color->red + (distance * red_step));
144
157
  row_pixels[x].green = ROUND_TO_QUANTUM(start_color->green + (distance * green_step));
145
158
  row_pixels[x].blue = ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step));
146
159
  row_pixels[x].opacity = OpaqueOpacity;
160
+ #endif
147
161
  }
148
162
 
149
163
  SyncAuthenticPixels(image, exception);
@@ -173,9 +187,11 @@ vertical_fill(
173
187
  {
174
188
  double steps;
175
189
  ssize_t x, y;
176
- PixelPacket *master;
177
190
  MagickRealType red_step, green_step, blue_step;
178
191
  ExceptionInfo *exception;
192
+ #if defined(IMAGEMAGICK_6)
193
+ PixelPacket *master;
194
+ #endif
179
195
 
180
196
  exception = AcquireExceptionInfo();
181
197
 
@@ -193,6 +209,32 @@ vertical_fill(
193
209
  green_step = ((MagickRealType)stop_color->green - (MagickRealType)start_color->green) / steps;
194
210
  blue_step = ((MagickRealType)stop_color->blue - (MagickRealType)start_color->blue) / steps;
195
211
 
212
+
213
+ #if defined(IMAGEMAGICK_7)
214
+ for (y = 0; y < (ssize_t) image->rows; y++)
215
+ {
216
+ Quantum *row_pixels;
217
+
218
+ row_pixels = QueueAuthenticPixels(image, 0, y, image->columns, 1, exception);
219
+ CHECK_EXCEPTION()
220
+
221
+ for (x = 0; x < (ssize_t) image->columns; x++)
222
+ {
223
+ double distance = fabs(x1 - x);
224
+ SetPixelRed(image, ROUND_TO_QUANTUM(start_color->red + (distance * red_step)), row_pixels);
225
+ SetPixelGreen(image, ROUND_TO_QUANTUM(start_color->green + (distance * green_step)), row_pixels);
226
+ SetPixelBlue(image, ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step)), row_pixels);
227
+ SetPixelAlpha(image, OpaqueAlpha, row_pixels);
228
+
229
+ row_pixels += GetPixelChannels(image);
230
+ }
231
+
232
+ SyncAuthenticPixels(image, exception);
233
+ CHECK_EXCEPTION()
234
+ }
235
+
236
+ (void) DestroyExceptionInfo(exception);
237
+ #else
196
238
  // All the rows are the same. Make a "master row" and simply copy
197
239
  // it to each actual row.
198
240
  master = ALLOC_N(PixelPacket, image->columns);
@@ -231,6 +273,7 @@ vertical_fill(
231
273
  (void) DestroyExceptionInfo(exception);
232
274
 
233
275
  xfree((void *) master);
276
+ #endif
234
277
  }
235
278
 
236
279
  /**
@@ -252,9 +295,11 @@ horizontal_fill(
252
295
  {
253
296
  double steps;
254
297
  ssize_t x, y;
255
- PixelPacket *master;
256
298
  MagickRealType red_step, green_step, blue_step;
257
299
  ExceptionInfo *exception;
300
+ #if defined(IMAGEMAGICK_6)
301
+ PixelPacket *master;
302
+ #endif
258
303
 
259
304
  exception = AcquireExceptionInfo();
260
305
 
@@ -271,6 +316,31 @@ horizontal_fill(
271
316
  green_step = ((MagickRealType)stop_color->green - (MagickRealType)start_color->green) / steps;
272
317
  blue_step = ((MagickRealType)stop_color->blue - (MagickRealType)start_color->blue) / steps;
273
318
 
319
+ #if defined(IMAGEMAGICK_7)
320
+ for (y = 0; y < (ssize_t) image->rows; y++)
321
+ {
322
+ Quantum *row_pixels;
323
+
324
+ row_pixels = QueueAuthenticPixels(image, 0, y, image->columns, 1, exception);
325
+ CHECK_EXCEPTION()
326
+
327
+ double distance = fabs(y1 - y);
328
+ for (x = 0; x < (ssize_t) image->columns; x++)
329
+ {
330
+ SetPixelRed(image, ROUND_TO_QUANTUM(start_color->red + (distance * red_step)), row_pixels);
331
+ SetPixelGreen(image, ROUND_TO_QUANTUM(start_color->green + (distance * green_step)), row_pixels);
332
+ SetPixelBlue(image, ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step)), row_pixels);
333
+ SetPixelAlpha(image, OpaqueAlpha, row_pixels);
334
+
335
+ row_pixels += GetPixelChannels(image);
336
+ }
337
+
338
+ SyncAuthenticPixels(image, exception);
339
+ CHECK_EXCEPTION()
340
+ }
341
+
342
+ (void) DestroyExceptionInfo(exception);
343
+ #else
274
344
  // All the columns are the same, so make a master column and copy it to
275
345
  // each of the "real" columns.
276
346
  master = ALLOC_N(PixelPacket, image->rows);
@@ -308,6 +378,7 @@ horizontal_fill(
308
378
  (void) DestroyExceptionInfo(exception);
309
379
 
310
380
  xfree((void *) master);
381
+ #endif
311
382
  }
312
383
 
313
384
  /**
@@ -380,7 +451,11 @@ v_diagonal_fill(
380
451
 
381
452
  for (y = 0; y < (ssize_t) image->rows; y++)
382
453
  {
454
+ #if defined(IMAGEMAGICK_7)
455
+ Quantum *row_pixels;
456
+ #else
383
457
  PixelPacket *row_pixels;
458
+ #endif
384
459
 
385
460
  row_pixels = QueueAuthenticPixels(image, 0, y, image->columns, 1, exception);
386
461
  CHECK_EXCEPTION()
@@ -388,10 +463,19 @@ v_diagonal_fill(
388
463
  for (x = 0; x < (ssize_t) image->columns; x++)
389
464
  {
390
465
  double distance = (double) abs((int)(y-(m * x + b)));
466
+ #if defined(IMAGEMAGICK_7)
467
+ SetPixelRed(image, ROUND_TO_QUANTUM(start_color->red + (distance * red_step)), row_pixels);
468
+ SetPixelGreen(image, ROUND_TO_QUANTUM(start_color->green + (distance * green_step)), row_pixels);
469
+ SetPixelBlue(image, ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step)), row_pixels);
470
+ SetPixelAlpha(image, OpaqueAlpha, row_pixels);
471
+
472
+ row_pixels += GetPixelChannels(image);
473
+ #else
391
474
  row_pixels[x].red = ROUND_TO_QUANTUM(start_color->red + (distance * red_step));
392
475
  row_pixels[x].green = ROUND_TO_QUANTUM(start_color->green + (distance * green_step));
393
476
  row_pixels[x].blue = ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step));
394
477
  row_pixels[x].opacity = OpaqueOpacity;
478
+ #endif
395
479
  }
396
480
 
397
481
  SyncAuthenticPixels(image, exception);
@@ -473,7 +557,11 @@ h_diagonal_fill(
473
557
 
474
558
  for (y = 0; y < (ssize_t) image->rows; y++)
475
559
  {
560
+ #if defined(IMAGEMAGICK_7)
561
+ Quantum *row_pixels;
562
+ #else
476
563
  PixelPacket *row_pixels;
564
+ #endif
477
565
 
478
566
  row_pixels = QueueAuthenticPixels(image, 0, y, image->columns, 1, exception);
479
567
  CHECK_EXCEPTION()
@@ -481,10 +569,19 @@ h_diagonal_fill(
481
569
  for (x = 0; x < (ssize_t) image->columns; x++)
482
570
  {
483
571
  double distance = (double) abs((int)(x-((y-b)/m)));
572
+ #if defined(IMAGEMAGICK_7)
573
+ SetPixelRed(image, ROUND_TO_QUANTUM(start_color->red + (distance * red_step)), row_pixels);
574
+ SetPixelGreen(image, ROUND_TO_QUANTUM(start_color->green + (distance * green_step)), row_pixels);
575
+ SetPixelBlue(image, ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step)), row_pixels);
576
+ SetPixelAlpha(image, OpaqueAlpha, row_pixels);
577
+
578
+ row_pixels += GetPixelChannels(image);
579
+ #else
484
580
  row_pixels[x].red = ROUND_TO_QUANTUM(start_color->red + (distance * red_step));
485
581
  row_pixels[x].green = ROUND_TO_QUANTUM(start_color->green + (distance * green_step));
486
582
  row_pixels[x].blue = ROUND_TO_QUANTUM(start_color->blue + (distance * blue_step));
487
583
  row_pixels[x].opacity = OpaqueOpacity;
584
+ #endif
488
585
  }
489
586
 
490
587
  SyncAuthenticPixels(image, exception);
@@ -658,12 +755,22 @@ TextureFill_fill(VALUE self, VALUE image_obj)
658
755
  {
659
756
  rm_TextureFill *fill;
660
757
  Image *image;
758
+ #if defined(IMAGEMAGICK_7)
759
+ ExceptionInfo *exception;
760
+ #endif
661
761
 
662
762
  image = rm_check_destroyed(image_obj);
663
763
  Data_Get_Struct(self, rm_TextureFill, fill);
664
764
 
765
+ #if defined(IMAGEMAGICK_7)
766
+ exception = AcquireExceptionInfo();
767
+ (void) TextureImage(image, fill->texture, exception);
768
+ CHECK_EXCEPTION()
769
+ (void) DestroyExceptionInfo(exception);
770
+ #else
665
771
  (void) TextureImage(image, fill->texture);
666
772
  rm_check_image_exception(image, RetainOnError);
773
+ #endif
667
774
 
668
775
  return self;
669
776
  }
@@ -46,6 +46,9 @@ ImageList_animate(int argc, VALUE *argv, VALUE self)
46
46
  Info *info;
47
47
  VALUE info_obj;
48
48
  unsigned int delay;
49
+ #if defined(IMAGEMAGICK_7)
50
+ ExceptionInfo *exception;
51
+ #endif
49
52
 
50
53
  if (argc == 1)
51
54
  {
@@ -73,9 +76,17 @@ ImageList_animate(int argc, VALUE *argv, VALUE self)
73
76
  }
74
77
 
75
78
  Data_Get_Struct(info_obj, Info, info);
79
+ #if defined(IMAGEMAGICK_7)
80
+ exception = AcquireExceptionInfo();
81
+ (void) AnimateImages(info, images, exception);
82
+ rm_split(images);
83
+ CHECK_EXCEPTION()
84
+ (void) DestroyExceptionInfo(exception);
85
+ #else
76
86
  (void) AnimateImages(info, images);
77
- rm_check_image_exception(images, RetainOnError);
78
87
  rm_split(images);
88
+ rm_check_image_exception(images, RetainOnError);
89
+ #endif
79
90
 
80
91
  RB_GC_GUARD(info_obj);
81
92
 
@@ -201,7 +212,9 @@ ImageList_coalesce(VALUE self)
201
212
  */
202
213
  VALUE ImageList_combine(int argc, VALUE *argv, VALUE self)
203
214
  {
215
+ #if defined(IMAGEMAGICK_6)
204
216
  ChannelType channel;
217
+ #endif
205
218
  ColorspaceType colorspace, old_colorspace;
206
219
  long len;
207
220
  Image *images, *new_image;
@@ -222,6 +235,16 @@ VALUE ImageList_combine(int argc, VALUE *argv, VALUE self)
222
235
  break;
223
236
  }
224
237
 
238
+ #if defined(IMAGEMAGICK_7)
239
+ if (len > 5)
240
+ {
241
+ rb_raise(rb_eArgError, "invalid number of images in this image list");
242
+ }
243
+ if (len == 5 && colorspace != CMYKColorspace)
244
+ {
245
+ rb_raise(rb_eArgError, "invalid number of images in this image list");
246
+ }
247
+ #else
225
248
  channel = RedChannel;
226
249
  switch (len)
227
250
  {
@@ -248,15 +271,22 @@ VALUE ImageList_combine(int argc, VALUE *argv, VALUE self)
248
271
  rb_raise(rb_eArgError, "invalid number of images in this image list");
249
272
  break;
250
273
  }
274
+ #endif
251
275
 
252
276
  images = images_from_imagelist(self);
277
+ exception = AcquireExceptionInfo();
278
+ #if defined(IMAGEMAGICK_6)
253
279
  old_colorspace = images->colorspace;
254
280
  SetImageColorspace(images, colorspace);
255
-
256
- exception = AcquireExceptionInfo();
257
281
  new_image = CombineImages(images, channel, exception);
282
+ #else
283
+ new_image = CombineImages(images, colorspace, exception);
284
+ #endif
285
+
258
286
  rm_split(images);
287
+ #if defined(IMAGEMAGICK_6)
259
288
  images->colorspace = old_colorspace;
289
+ #endif
260
290
  rm_check_exception(exception, new_image, DestroyOnError);
261
291
  (void) DestroyExceptionInfo(exception);
262
292
 
@@ -349,7 +379,11 @@ ImageList_deconstruct(VALUE self)
349
379
 
350
380
  images = images_from_imagelist(self);
351
381
  exception = AcquireExceptionInfo();
382
+ #if defined(IMAGEMAGICK_7)
383
+ new_images = CompareImagesLayers(images, CompareAnyLayer, exception);
384
+ #else
352
385
  new_images = DeconstructImages(images, exception);
386
+ #endif
353
387
  rm_split(images);
354
388
  rm_check_exception(exception, new_images, DestroyOnError);
355
389
  (void) DestroyExceptionInfo(exception);
@@ -375,6 +409,9 @@ ImageList_display(VALUE self)
375
409
  Image *images;
376
410
  Info *info;
377
411
  VALUE info_obj;
412
+ #if defined(IMAGEMAGICK_7)
413
+ ExceptionInfo *exception;
414
+ #endif
378
415
 
379
416
  // Create a new Info object to use with this call
380
417
  info_obj = rm_info_new();
@@ -382,10 +419,17 @@ ImageList_display(VALUE self)
382
419
 
383
420
  // Convert the images array to an images sequence.
384
421
  images = images_from_imagelist(self);
385
-
422
+ #if defined(IMAGEMAGICK_7)
423
+ exception = AcquireExceptionInfo();
424
+ (void) DisplayImages(info, images, exception);
425
+ rm_split(images);
426
+ CHECK_EXCEPTION();
427
+ (void) DestroyExceptionInfo(exception);
428
+ #else
386
429
  (void) DisplayImages(info, images);
387
430
  rm_split(images);
388
431
  rm_check_image_exception(images, RetainOnError);
432
+ #endif
389
433
 
390
434
  RB_GC_GUARD(info_obj);
391
435
 
@@ -626,7 +670,11 @@ ImageList_optimize_layers(VALUE self, VALUE method)
626
670
  rm_check_exception(exception, new_images, DestroyOnError);
627
671
  // mogrify supports -dither here. We don't.
628
672
  GetQuantizeInfo(&quantize_info);
673
+ #if defined(IMAGEMAGICK_7)
674
+ (void) RemapImages(&quantize_info, new_images, NULL, exception);
675
+ #else
629
676
  (void) RemapImages(&quantize_info, new_images, NULL);
677
+ #endif
630
678
  break;
631
679
  case OptimizePlusLayer:
632
680
  new_images = OptimizePlusImageLayers(images, exception);
@@ -634,7 +682,11 @@ ImageList_optimize_layers(VALUE self, VALUE method)
634
682
  case CompareAnyLayer:
635
683
  case CompareClearLayer:
636
684
  case CompareOverlayLayer:
685
+ #if defined(IMAGEMAGICK_7)
686
+ new_images = CompareImagesLayers(images, mthd, exception);
687
+ #else
637
688
  new_images = CompareImageLayers(images, mthd, exception);
689
+ #endif
638
690
  break;
639
691
  case MosaicLayer:
640
692
  new_images = MergeImageLayers(images, mthd, exception);
@@ -914,6 +966,12 @@ ImageList_quantize(int argc, VALUE *argv, VALUE self)
914
966
  case 4:
915
967
  quantize_info.tree_depth = (unsigned long)NUM2INT(argv[3]);
916
968
  case 3:
969
+ #if defined(IMAGEMAGICK_7)
970
+ if (rb_obj_is_kind_of(argv[2], Class_DitherMethod))
971
+ {
972
+ VALUE_TO_ENUM(argv[2], quantize_info.dither_method, DitherMethod);
973
+ }
974
+ #else
917
975
  if (rb_obj_is_kind_of(argv[2], Class_DitherMethod))
918
976
  {
919
977
  VALUE_TO_ENUM(argv[2], quantize_info.dither_method, DitherMethod);
@@ -923,6 +981,7 @@ ImageList_quantize(int argc, VALUE *argv, VALUE self)
923
981
  {
924
982
  quantize_info.dither = (MagickBooleanType) RTEST(argv[2]);
925
983
  }
984
+ #endif
926
985
  case 2:
927
986
  VALUE_TO_ENUM(argv[1], quantize_info.colorspace, ColorspaceType);
928
987
  case 1:
@@ -944,8 +1003,11 @@ ImageList_quantize(int argc, VALUE *argv, VALUE self)
944
1003
 
945
1004
  rm_ensure_result(new_images);
946
1005
 
947
-
1006
+ #if defined(IMAGEMAGICK_7)
1007
+ (void) QuantizeImages(&quantize_info, new_images, exception);
1008
+ #else
948
1009
  (void) QuantizeImages(&quantize_info, new_images);
1010
+ #endif
949
1011
  rm_check_exception(exception, new_images, DestroyOnError);
950
1012
  (void) DestroyExceptionInfo(exception);
951
1013
 
@@ -991,7 +1053,9 @@ ImageList_remap(int argc, VALUE *argv, VALUE self)
991
1053
  {
992
1054
  Image *images, *remap_image = NULL;
993
1055
  QuantizeInfo quantize_info;
994
-
1056
+ #if defined(IMAGEMAGICK_7)
1057
+ ExceptionInfo *exception;
1058
+ #endif
995
1059
 
996
1060
  if (argc > 0 && argv[0] != Qnil)
997
1061
  {
@@ -1005,7 +1069,9 @@ ImageList_remap(int argc, VALUE *argv, VALUE self)
1005
1069
  if (argc > 1)
1006
1070
  {
1007
1071
  VALUE_TO_ENUM(argv[1], quantize_info.dither_method, DitherMethod);
1072
+ #if defined(IMAGEMAGICK_6)
1008
1073
  quantize_info.dither = MagickTrue;
1074
+ #endif
1009
1075
  }
1010
1076
  if (argc > 2)
1011
1077
  {
@@ -1014,9 +1080,16 @@ ImageList_remap(int argc, VALUE *argv, VALUE self)
1014
1080
 
1015
1081
  images = images_from_imagelist(self);
1016
1082
 
1017
- (void) RemapImages(&quantize_info, images, remap_image);
1018
- rm_check_image_exception(images, RetainOnError);
1083
+ #if defined(IMAGEMAGICK_7)
1084
+ exception = AcquireExceptionInfo();
1085
+ (void) RemapImages(&quantize_info, images, remap_image, exception);
1086
+ rm_split(images);
1087
+ CHECK_EXCEPTION()
1088
+ (void) DestroyExceptionInfo(exception);
1089
+ #else
1019
1090
  rm_split(images);
1091
+ rm_check_image_exception(images, RetainOnError);
1092
+ #endif
1020
1093
 
1021
1094
  return self;
1022
1095
  }
@@ -1165,7 +1238,9 @@ ImageList_write(VALUE self, VALUE file)
1165
1238
 
1166
1239
  m = GetMagickInfo(info->magick, exception);
1167
1240
  rm_check_exception(exception, images, RetainOnError);
1241
+ #if defined(IMAGEMAGICK_6)
1168
1242
  (void) DestroyExceptionInfo(exception);
1243
+ #endif
1169
1244
 
1170
1245
  // Tell WriteImage if we want a multi-images file.
1171
1246
  if (imagelist_length(self) > 1L && GetMagickAdjoin(m))
@@ -1176,15 +1251,24 @@ ImageList_write(VALUE self, VALUE file)
1176
1251
  for (img = images; img; img = GetNextImageInList(img))
1177
1252
  {
1178
1253
  rm_sync_image_options(img, info);
1254
+ #if defined(IMAGEMAGICK_7)
1255
+ (void) WriteImage(info, img, exception);
1256
+ rm_check_exception(exception, img, RetainOnError);
1257
+ #else
1179
1258
  (void) WriteImage(info, img);
1180
1259
  // images will be split before raising an exception
1181
1260
  rm_check_image_exception(images, RetainOnError);
1261
+ #endif
1182
1262
  if (info->adjoin)
1183
1263
  {
1184
1264
  break;
1185
1265
  }
1186
1266
  }
1187
1267
 
1268
+ #if defined(IMAGEMAGICK_7)
1269
+ (void) DestroyExceptionInfo(exception);
1270
+ #endif
1271
+
1188
1272
  rm_split(images);
1189
1273
 
1190
1274
  RB_GC_GUARD(info_obj);