Class: Magick::Pixel
- Inherits:
-
Object
- Object
- Magick::Pixel
- Includes:
- Comparable, Observable
- Defined in:
- lib/rmagick_internal.rb,
ext/RMagick/rmmain.cpp
Overview
Magick::ImageList
Class Method Summary collapse
-
.from_color(name) ⇒ Magick::Pixel
Construct an Pixel corresponding to the given color name.
-
.from_hsla(hue, saturation, lightness, alpha = 1.0) ⇒ Magick::Pixel
Construct an RGB pixel.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Support Comparable mixin.
-
#===(other) ⇒ Boolean
“Case equal” operator for Pixel.
-
#alpha ⇒ Numeric
Get Pixel alpha value.
-
#alpha=(v) ⇒ Numeric
Set Pixel alpha value.
-
#black ⇒ Numeric
Get Pixel black value.
-
#black=(v) ⇒ Numeric
Set Pixel black value.
-
#blue ⇒ Numeric
Get Pixel blue value.
-
#blue=(v) ⇒ Numeric
Set Pixel blue value.
-
#clone ⇒ Magick::Pixel
Clone a Pixel.
-
#cyan ⇒ Numeric
Get Pixel cyan value.
-
#cyan=(v) ⇒ Numeric
Set Pixel cyan value.
-
#dup ⇒ Magick::Pixel
Duplicate a Pixel.
-
#eql?(other) ⇒ Boolean
Equality.
-
#fcmp(other, fuzz = 0.0, colorspace = Magick::RGBColorspace) ⇒ Boolean
Compare pixel values for equality.
-
#green ⇒ Numeric
Get Pixel green value.
-
#green=(v) ⇒ Numeric
Set Pixel green value.
-
#hash ⇒ Numeric
Compute a hash-code.
-
#initialize(red = 0, green = 0, blue = 0, opacity = 0) ⇒ Magick::Pixel
constructor
Initialize Pixel object.
-
#initialize_copy(orig) ⇒ Magick::Pixel
Initialize clone, dup methods.
-
#intensity ⇒ Numeric
Return the “intensity” of a pixel.
-
#magenta ⇒ Numeric
Get Pixel magenta value.
-
#magenta=(v) ⇒ Numeric
Set Pixel magenta value.
-
#marshal_dump ⇒ Hash
Support Marshal.dump.
-
#marshal_load(dpixel) ⇒ Object
Support Marshal.load.
-
#red ⇒ Numeric
Get Pixel red value.
-
#red=(v) ⇒ Numeric
Set Pixel red value.
-
#to_color(compliance = Magick::AllCompliance, alpha = false, depth = Magick::MAGICKCORE_QUANTUM_DEPTH, hex = true) ⇒ String
Return the color name corresponding to the pixel values.
-
#to_hsla ⇒ Array<Float>
Return [
hue,saturation,lightness,alpha] in the same ranges as Pixel.from_hsla. -
#to_s ⇒ String
Return a string representation of a Pixel object.
-
#yellow ⇒ Numeric
Get Pixel yellow value.
-
#yellow=(v) ⇒ Numeric
Set Pixel yellow value.
Constructor Details
#initialize(red = 0, green = 0, blue = 0, opacity = 0) ⇒ Magick::Pixel
Initialize Pixel object.
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
# File 'ext/RMagick/rmpixel.cpp', line 937
VALUE
Pixel_initialize(int argc, VALUE *argv, VALUE self)
{
Pixel *pixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
#if defined(IMAGEMAGICK_7)
pixel->alpha = OpaqueAlpha;
#endif
switch(argc)
{
case 4:
#if defined(IMAGEMAGICK_7)
if (argv[3] != Qnil)
{
pixel->alpha = APP2QUANTUM(argv[3]);
}
#else
if (argv[3] != Qnil)
{
pixel->opacity = APP2QUANTUM(argv[3]);
}
#endif
case 3:
if (argv[2] != Qnil)
{
pixel->blue = APP2QUANTUM(argv[2]);
}
case 2:
if (argv[1] != Qnil)
{
pixel->green = APP2QUANTUM(argv[1]);
}
case 1:
if (argv[0] != Qnil)
{
pixel->red = APP2QUANTUM(argv[0]);
}
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc);
}
return self;
}
|
Class Method Details
.from_color(name) ⇒ Magick::Pixel
Construct an Magick::Pixel corresponding to the given color name.
-
The “inverse” is Image#to_color, b/c the conversion of a pixel to a color name requires both a color depth and if the opacity value has meaning.
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'ext/RMagick/rmpixel.cpp', line 680
VALUE
Pixel_from_color(VALUE klass ATTRIBUTE_UNUSED, VALUE name)
{
PixelColor pp;
ExceptionInfo *exception;
MagickBooleanType okay;
exception = AcquireExceptionInfo();
okay = QueryColorCompliance(StringValueCStr(name), AllCompliance, &pp, exception);
CHECK_EXCEPTION();
DestroyExceptionInfo(exception);
if (!okay)
{
rb_raise(rb_eArgError, "invalid color name: %s", StringValueCStr(name));
}
return Pixel_from_PixelColor(&pp);
}
|
.from_hsla(hue, saturation, lightness, alpha = 1.0) ⇒ Magick::Pixel
Construct an RGB pixel.
-
0 <=
hue< 360 OR “0%” <=hue< “100%” -
0 <=
saturation<= 255 OR “0%” <=saturation<= “100%” -
0 <=
lightness<= 255 OR “0%” <=lightness<= “100%” -
0 <=
alpha<= 1 (0 is transparent, 1 is opaque) OR “0%” <=alpha<= “100%”
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
# File 'ext/RMagick/rmpixel.cpp', line 716
VALUE
Pixel_from_hsla(int argc, VALUE *argv, VALUE klass ATTRIBUTE_UNUSED)
{
double h, s, l, a = 1.0;
MagickPixel pp;
ExceptionInfo *exception;
char name[50];
MagickBooleanType alpha = MagickFalse;
switch (argc)
{
case 4:
a = rm_percentage(argv[3], 1.0);
alpha = MagickTrue;
case 3:
// saturation and lightness are out of 255 in new ImageMagicks and
// out of 100 in old ImageMagicks. Compromise: always use %.
l = rm_percentage(argv[2], 255.0);
s = rm_percentage(argv[1], 255.0);
h = rm_percentage(argv[0], 360.0);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
break;
}
if (alpha && (a < 0.0 || a > 1.0))
{
rb_raise(rb_eRangeError, "alpha %g out of range [0.0, 1.0]", a);
}
if (l < 0.0 || l > 255.0)
{
rb_raise(rb_eRangeError, "lightness %g out of range [0.0, 255.0]", l);
}
if (s < 0.0 || s > 255.0)
{
rb_raise(rb_eRangeError, "saturation %g out of range [0.0, 255.0]", s);
}
if (h < 0.0 || h >= 360.0)
{
rb_raise(rb_eRangeError, "hue %g out of range [0.0, 360.0)", h);
}
memset(name, 0, sizeof(name));
if (alpha)
{
snprintf(name, sizeof(name), "hsla(%-2.1f,%-2.1f,%-2.1f,%-2.1f)", h, s, l, a);
}
else
{
snprintf(name, sizeof(name), "hsl(%-2.1f,%-2.1f,%-2.1f)", h, s, l);
}
exception = AcquireExceptionInfo();
#if defined(IMAGEMAGICK_7)
QueryColorCompliance(name, AllCompliance, &pp, exception);
#else
QueryMagickColor(name, &pp, exception);
#endif
CHECK_EXCEPTION();
DestroyExceptionInfo(exception);
return Pixel_from_MagickPixel(&pp);
}
|
Instance Method Details
#<=>(other) ⇒ -1, ...
Support Comparable mixin.
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 |
# File 'ext/RMagick/rmpixel.cpp', line 1066
VALUE
Pixel_spaceship(VALUE self, VALUE other)
{
Pixel *self_pixel, *other_pixel;
if (CLASS_OF(self) != CLASS_OF(other)) {
return Qnil;
}
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, self_pixel);
TypedData_Get_Struct(other, Pixel, &rm_pixel_data_type, other_pixel);
if (self_pixel->red != other_pixel->red)
{
return INT2NUM((self_pixel->red - other_pixel->red)/abs((int)(self_pixel->red - other_pixel->red)));
}
else if(self_pixel->green != other_pixel->green)
{
return INT2NUM((self_pixel->green - other_pixel->green)/abs((int)(self_pixel->green - other_pixel->green)));
}
else if(self_pixel->blue != other_pixel->blue)
{
return INT2NUM((self_pixel->blue - other_pixel->blue)/abs((int)(self_pixel->blue - other_pixel->blue)));
}
#if defined(IMAGEMAGICK_7)
else if(self_pixel->alpha != other_pixel->alpha)
{
return INT2NUM((self_pixel->alpha - other_pixel->alpha)/abs((int)(self_pixel->alpha - other_pixel->alpha)));
}
#else
else if(self_pixel->opacity != other_pixel->opacity)
{
return INT2NUM(((QuantumRange - self_pixel->opacity) - (QuantumRange - other_pixel->opacity))/abs((int)((QuantumRange - self_pixel->opacity) - (QuantumRange - other_pixel->opacity))));
}
#endif
// Values are equal.
return INT2NUM(0);
}
|
#===(other) ⇒ Boolean
“Case equal” operator for Pixel.
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'ext/RMagick/rmpixel.cpp', line 511
VALUE
Pixel_case_eq(VALUE self, VALUE other)
{
if (CLASS_OF(self) == CLASS_OF(other))
{
Pixel *self_pixel, *other_pixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, self_pixel);
TypedData_Get_Struct(other, Pixel, &rm_pixel_data_type, other_pixel);
return (self_pixel->red == other_pixel->red
&& self_pixel->blue == other_pixel->blue
&& self_pixel->green == other_pixel->green
#if defined(IMAGEMAGICK_7)
&& self_pixel->alpha == other_pixel->alpha) ? Qtrue : Qfalse;
#else
&& self_pixel->opacity == other_pixel->opacity) ? Qtrue : Qfalse;
#endif
}
return Qfalse;
}
|
#alpha ⇒ Numeric
Get Pixel alpha value.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'ext/RMagick/rmpixel.cpp', line 99
VALUE
Pixel_alpha(VALUE self)
{
Pixel *pixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
#if defined(IMAGEMAGICK_7)
return C_int_to_R_int(pixel->alpha);
#else
return C_int_to_R_int(QuantumRange - pixel->opacity);
#endif
}
|
#alpha=(v) ⇒ Numeric
Set Pixel alpha value.
-
Pixel is Observable. Setters call #changed, #notify_observers
-
Setters return their argument values for backward compatibility to when Pixel was a Struct class.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'ext/RMagick/rmpixel.cpp', line 194
VALUE
Pixel_alpha_eq(VALUE self, VALUE v)
{
Pixel *pixel;
rb_check_frozen(self);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
#if defined(IMAGEMAGICK_7)
pixel->alpha = APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM(pixel->alpha);
#else
pixel->opacity = QuantumRange - APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM(QuantumRange - pixel->opacity);
#endif
}
|
#black ⇒ Numeric
Get Pixel black value.
333 334 335 336 337 338 339 340 |
# File 'ext/RMagick/rmpixel.cpp', line 333
VALUE
Pixel_black(VALUE self)
{
Pixel *pixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
return INT2NUM(pixel->black);
}
|
#black=(v) ⇒ Numeric
Set Pixel black value.
-
Pixel is Observable. Setters call #changed, #notify_observers
-
Setters return their argument values for backward compatibility to when Pixel was a Struct class.
353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'ext/RMagick/rmpixel.cpp', line 353
VALUE
Pixel_black_eq(VALUE self, VALUE v)
{
Pixel *pixel;
rb_check_frozen(self);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
pixel->black = APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM(pixel->black);
}
|
#blue ⇒ Numeric
Get Pixel blue value.
88 89 90 91 92 |
# File 'ext/RMagick/rmpixel.cpp', line 88
VALUE
Pixel_blue(VALUE self)
{
IMPLEMENT_TYPED_ATTR_READER(Pixel, blue, int, &rm_pixel_data_type);
}
|
#blue=(v) ⇒ Numeric
Set Pixel blue value.
-
Pixel is Observable. Setters call #changed, #notify_observers
-
Setters return their argument values for backward compatibility to when Pixel was a Struct class.
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'ext/RMagick/rmpixel.cpp', line 170
VALUE
Pixel_blue_eq(VALUE self, VALUE v)
{
Pixel *pixel;
rb_check_frozen(self);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
pixel->blue = APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM((pixel->blue));
}
|
#clone ⇒ Magick::Pixel
Clone a Pixel.
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'ext/RMagick/rmpixel.cpp', line 541
VALUE
Pixel_clone(VALUE self)
{
VALUE clone;
clone = Pixel_dup(self);
if (OBJ_FROZEN(self))
{
OBJ_FREEZE(clone);
}
RB_GC_GUARD(clone);
return clone;
}
|
#cyan ⇒ Numeric
Get Pixel cyan value.
219 220 221 222 223 224 225 226 |
# File 'ext/RMagick/rmpixel.cpp', line 219
VALUE
Pixel_cyan(VALUE self)
{
Pixel *pixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
return INT2NUM(pixel->red);
}
|
#cyan=(v) ⇒ Numeric
Set Pixel cyan value.
-
Pixel is Observable. Setters call #changed, #notify_observers
-
Setters return their argument values for backward compatibility to when Pixel was a Struct class.
239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'ext/RMagick/rmpixel.cpp', line 239
VALUE
Pixel_cyan_eq(VALUE self, VALUE v)
{
Pixel *pixel;
rb_check_frozen(self);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
pixel->red = APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM(pixel->red);
}
|
#dup ⇒ Magick::Pixel
Duplicate a Pixel.
565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'ext/RMagick/rmpixel.cpp', line 565
VALUE
Pixel_dup(VALUE self)
{
Pixel *pixel;
VALUE dup;
pixel = ALLOC(Pixel);
memset(pixel, '\0', sizeof(Pixel));
dup = TypedData_Wrap_Struct(CLASS_OF(self), &rm_pixel_data_type, pixel);
RB_GC_GUARD(dup);
return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
}
|
#eql?(other) ⇒ Boolean
Equality. Returns true only if receiver and other are the same object.
586 587 588 589 590 |
# File 'ext/RMagick/rmpixel.cpp', line 586
VALUE
Pixel_eql_q(VALUE self, VALUE other)
{
return NUM2INT(Pixel_spaceship(self, other)) == 0 ? Qtrue : Qfalse;
}
|
#fcmp(other, fuzz = 0.0, colorspace = Magick::RGBColorspace) ⇒ Boolean
Compare pixel values for equality.
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
# File 'ext/RMagick/rmpixel.cpp', line 602
VALUE
Pixel_fcmp(int argc, VALUE *argv, VALUE self)
{
double fuzz = 0.0;
unsigned int equal;
ColorspaceType colorspace = RGBColorspace;
PixelColor self_pixel_color, other_pixel_color;
#if defined(IMAGEMAGICK_6)
Image *image;
Info *info;
#endif
switch (argc)
{
case 3:
VALUE_TO_ENUM(argv[2], colorspace, ColorspaceType);
case 2:
fuzz = NUM2DBL(argv[1]);
case 1:
// Allow 1 argument
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 3)", argc);
break;
}
Color_to_PixelColor(&self_pixel_color, self);
Color_to_PixelColor(&other_pixel_color, argv[0]);
#if defined(IMAGEMAGICK_7)
self_pixel_color.fuzz = fuzz;
self_pixel_color.colorspace = colorspace;
other_pixel_color.fuzz = fuzz;
other_pixel_color.colorspace = colorspace;
equal = IsFuzzyEquivalencePixelInfo(&self_pixel_color, &other_pixel_color);
#else
// The IsColorSimilar function expects to get the
// colorspace and fuzz parameters from an Image structure.
info = CloneImageInfo(NULL);
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
image = rm_acquire_image(info);
// Delete Info now in case we have to raise an exception
DestroyImageInfo(info);
if (!image)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
image->colorspace = colorspace;
image->fuzz = fuzz;
equal = IsColorSimilar(image, &self_pixel_color, &other_pixel_color);
DestroyImage(image);
#endif
return equal ? Qtrue : Qfalse;
}
|
#green ⇒ Numeric
Get Pixel green value.
77 78 79 80 81 |
# File 'ext/RMagick/rmpixel.cpp', line 77
VALUE
Pixel_green(VALUE self)
{
IMPLEMENT_TYPED_ATTR_READER(Pixel, green, int, &rm_pixel_data_type);
}
|
#green=(v) ⇒ Numeric
Set Pixel green value.
-
Pixel is Observable. Setters call #changed, #notify_observers
-
Setters return their argument values for backward compatibility to when Pixel was a Struct class.
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'ext/RMagick/rmpixel.cpp', line 146
VALUE
Pixel_green_eq(VALUE self, VALUE v)
{
Pixel *pixel;
rb_check_frozen(self);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
pixel->green = APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM((pixel->green));
}
|
#hash ⇒ Numeric
Compute a hash-code.
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
# File 'ext/RMagick/rmpixel.cpp', line 884
VALUE
Pixel_hash(VALUE self)
{
Pixel *pixel;
unsigned int hash;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
hash = ScaleQuantumToChar(pixel->red) << 24;
hash += ScaleQuantumToChar(pixel->green) << 16;
hash += ScaleQuantumToChar(pixel->blue) << 8;
#if defined(IMAGEMAGICK_7)
hash += ScaleQuantumToChar(pixel->alpha);
#else
hash += ScaleQuantumToChar(QuantumRange - pixel->opacity);
#endif
return UINT2NUM(hash >> 1);
}
|
#initialize_copy(orig) ⇒ Magick::Pixel
Initialize clone, dup methods.
913 914 915 916 917 918 919 920 921 922 923 924 |
# File 'ext/RMagick/rmpixel.cpp', line 913
VALUE
Pixel_init_copy(VALUE self, VALUE orig)
{
Pixel *copy, *original;
TypedData_Get_Struct(orig, Pixel, &rm_pixel_data_type, original);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, copy);
*copy = *original;
return self;
}
|
#intensity ⇒ Numeric
Return the “intensity” of a pixel.
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
# File 'ext/RMagick/rmpixel.cpp', line 992
VALUE
Pixel_intensity(VALUE self)
{
Pixel *pixel;
Quantum intensity;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
intensity = ROUND_TO_QUANTUM((0.299*pixel->red)
+ (0.587*pixel->green)
+ (0.114*pixel->blue));
return QUANTUM2NUM((unsigned long) intensity);
}
|
#magenta ⇒ Numeric
Get Pixel magenta value.
257 258 259 260 261 262 263 264 |
# File 'ext/RMagick/rmpixel.cpp', line 257
VALUE
Pixel_magenta(VALUE self)
{
Pixel *pixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
return INT2NUM(pixel->green);
}
|
#magenta=(v) ⇒ Numeric
Set Pixel magenta value.
-
Pixel is Observable. Setters call #changed, #notify_observers
-
Setters return their argument values for backward compatibility to when Pixel was a Struct class.
277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'ext/RMagick/rmpixel.cpp', line 277
VALUE
Pixel_magenta_eq(VALUE self, VALUE v)
{
Pixel *pixel;
rb_check_frozen(self);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
pixel->green = APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM(pixel->green);
}
|
#marshal_dump ⇒ Hash
Support Marshal.dump.
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
# File 'ext/RMagick/rmpixel.cpp', line 1013
VALUE
Pixel_marshal_dump(VALUE self)
{
Pixel *pixel;
VALUE dpixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
dpixel = rb_hash_new();
rb_hash_aset(dpixel, CSTR2SYM("red"), QUANTUM2NUM(pixel->red));
rb_hash_aset(dpixel, CSTR2SYM("green"), QUANTUM2NUM(pixel->green));
rb_hash_aset(dpixel, CSTR2SYM("blue"), QUANTUM2NUM(pixel->blue));
#if defined(IMAGEMAGICK_7)
rb_hash_aset(dpixel, CSTR2SYM("alpha"), QUANTUM2NUM(pixel->alpha));
#else
rb_hash_aset(dpixel, CSTR2SYM("opacity"), QUANTUM2NUM(pixel->opacity));
#endif
RB_GC_GUARD(dpixel);
return dpixel;
}
|
#marshal_load(dpixel) ⇒ Object
Support Marshal.load.
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 |
# File 'ext/RMagick/rmpixel.cpp', line 1042
VALUE
Pixel_marshal_load(VALUE self, VALUE dpixel)
{
Pixel *pixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
pixel->red = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("red")));
pixel->green = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("green")));
pixel->blue = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("blue")));
#if defined(IMAGEMAGICK_7)
pixel->alpha = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("alpha")));
#else
pixel->opacity = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("opacity")));
#endif
return self;
}
|
#red ⇒ Numeric
Get Pixel red value.
66 67 68 69 70 |
# File 'ext/RMagick/rmpixel.cpp', line 66
VALUE
Pixel_red(VALUE self)
{
IMPLEMENT_TYPED_ATTR_READER(Pixel, red, int, &rm_pixel_data_type);
}
|
#red=(v) ⇒ Numeric
Set Pixel red value.
-
Pixel is Observable. Setters call #changed, #notify_observers
-
Setters return their argument values for backward compatibility to when Pixel was a Struct class.
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'ext/RMagick/rmpixel.cpp', line 122
VALUE
Pixel_red_eq(VALUE self, VALUE v)
{
Pixel *pixel;
rb_check_frozen(self);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
pixel->red = APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM((pixel->red));
}
|
#to_color(compliance = Magick::AllCompliance, alpha = false, depth = Magick::MAGICKCORE_QUANTUM_DEPTH, hex = true) ⇒ String
Return the color name corresponding to the pixel values.
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 |
# File 'ext/RMagick/rmpixel.cpp', line 1200
VALUE
Pixel_to_color(int argc, VALUE *argv, VALUE self)
{
Info *info;
Image *image;
Pixel *pixel;
MagickPixel mpp;
MagickBooleanType hex = MagickTrue;
char name[MaxTextExtent];
ExceptionInfo *exception;
ComplianceType compliance = AllCompliance;
MagickBooleanType alpha = MagickFalse;
unsigned int depth = MAGICKCORE_QUANTUM_DEPTH;
switch (argc)
{
case 4:
hex = (MagickBooleanType)RTEST(argv[3]);
case 3:
depth = NUM2UINT(argv[2]);
// Ensure depth is appropriate for the way xMagick was compiled.
switch (depth)
{
case 8:
#if MAGICKCORE_QUANTUM_DEPTH == 16 || MAGICKCORE_QUANTUM_DEPTH == 32
case 16:
#endif
#if MAGICKCORE_QUANTUM_DEPTH == 32
case 32:
#endif
break;
default:
rb_raise(rb_eArgError, "invalid depth (%d)", depth);
break;
}
case 2:
alpha = (MagickBooleanType)RTEST(argv[1]);
case 1:
VALUE_TO_ENUM(argv[0], compliance, ComplianceType);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc);
}
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
info = CloneImageInfo(NULL);
image = rm_acquire_image(info);
DestroyImageInfo(info);
if (!image)
{
rb_raise(rb_eNoMemError, "not enough memory to continue.");
}
exception = AcquireExceptionInfo();
image->depth = depth;
#if defined(IMAGEMAGICK_7)
if (alpha)
{
image->alpha_trait = BlendPixelTrait;
}
#else
image->matte = alpha;
#endif
rm_init_magickpixel(image, &mpp);
rm_set_magick_pixel_packet(pixel, &mpp);
// Support for hex-format color names moved out of QueryMagickColorname
// in 6.4.1-9. The 'hex' argument was removed as well.
if (hex)
{
if (compliance == XPMCompliance)
{
#if defined(IMAGEMAGICK_7)
mpp.alpha_trait = UndefinedPixelTrait;
#else
mpp.matte = MagickFalse;
#endif
mpp.depth = (unsigned long) min(1.0 * image->depth, 16.0);
}
GetColorTuple(&mpp, MagickTrue, name);
}
else
{
QueryColorname(image, &mpp, compliance, name, exception);
}
DestroyImage(image);
CHECK_EXCEPTION();
DestroyExceptionInfo(exception);
// Always return a string, even if it's ""
return rb_str_new2(name);
}
|
#to_hsla ⇒ Array<Float>
Return [hue, saturation, lightness, alpha] in the same ranges as from_hsla.
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 |
# File 'ext/RMagick/rmpixel.cpp', line 1114
VALUE
Pixel_to_hsla(VALUE self)
{
double hue, sat, lum, alpha;
Pixel *pixel;
VALUE hsla;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
ConvertRGBToHSL(pixel->red, pixel->green, pixel->blue, &hue, &sat, &lum);
hue *= 360.0;
sat *= 255.0;
lum *= 255.0;
#if defined(IMAGEMAGICK_7)
if (pixel->alpha == OpaqueAlpha)
{
alpha = 1.0;
}
else if (pixel->alpha == TransparentAlpha)
{
alpha = 0.0;
}
else
{
alpha = (double)(pixel->alpha) / (double)QuantumRange;
}
#else
if (pixel->opacity == OpaqueOpacity)
{
alpha = 1.0;
}
else if (pixel->opacity == TransparentOpacity)
{
alpha = 0.0;
}
else
{
alpha = (double)(QuantumRange - pixel->opacity) / (double)QuantumRange;
}
#endif
hsla = rb_ary_new3(4, rb_float_new(hue), rb_float_new(sat), rb_float_new(lum), rb_float_new(alpha));
RB_GC_GUARD(hsla);
return hsla;
}
|
#to_s ⇒ String
Return a string representation of a Magick::Pixel object.
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 |
# File 'ext/RMagick/rmpixel.cpp', line 1306
VALUE
Pixel_to_s(VALUE self)
{
Pixel *pixel;
char buff[100];
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
snprintf(buff, sizeof(buff), "red=" QuantumFormat ", green=" QuantumFormat ", blue=" QuantumFormat ", alpha=" QuantumFormat,
pixel->red, pixel->green, pixel->blue,
#if defined(IMAGEMAGICK_7)
pixel->alpha);
#else
(QuantumRange - pixel->opacity));
#endif
return rb_str_new2(buff);
}
|
#yellow ⇒ Numeric
Get Pixel yellow value.
295 296 297 298 299 300 301 302 |
# File 'ext/RMagick/rmpixel.cpp', line 295
VALUE
Pixel_yellow(VALUE self)
{
Pixel *pixel;
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
return INT2NUM(pixel->blue);
}
|
#yellow=(v) ⇒ Numeric
Set Pixel yellow value.
-
Pixel is Observable. Setters call #changed, #notify_observers
-
Setters return their argument values for backward compatibility to when Pixel was a Struct class.
315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'ext/RMagick/rmpixel.cpp', line 315
VALUE
Pixel_yellow_eq(VALUE self, VALUE v)
{
Pixel *pixel;
rb_check_frozen(self);
TypedData_Get_Struct(self, Pixel, &rm_pixel_data_type, pixel);
pixel->blue = APP2QUANTUM(v);
rb_funcall(self, rm_ID_changed, 0);
rb_funcall(self, rm_ID_notify_observers, 1, self);
return QUANTUM2NUM(pixel->blue);
}
|