Class: Magick::Pixel

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
ext/RMagick/rmmain.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

Ruby usage:

- @verbatim Pixel#initialize @endverbatim
- @verbatim Pixel#initialize(red) @endverbatim
- @verbatim Pixel#initialize(red,green) @endverbatim
- @verbatim Pixel#initialize(red,green,blue) @endverbatim
- @verbatim Pixel#initialize(red,green,blue,opacity) @endverbatim

Notes:

- Default red is 0.0
- Default green is 0.0
- Default blue is 0.0
- Default opacity is 0.0
- For backward compatibility, arguments may be nil.

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object



793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
# File 'ext/RMagick/rmpixel.c', line 793

VALUE
Pixel_initialize(int argc, VALUE *argv, VALUE self)
{
    Pixel *pixel;

    Data_Get_Struct(self, Pixel, pixel);

    switch(argc)
    {
        case 4:
            if (argv[3] != Qnil)
            {
                pixel->opacity = APP2QUANTUM(argv[3]);
            }
        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) ⇒ Object

Construct an Magick::Pixel corresponding to the given color name.

Ruby usage:

- @verbatim Magick::Pixel.from_color(string) @endverbatim

Notes:

- 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 (i.e. whether image->matte == True or not).

Parameters:

  • class

    the Ruby class to use

  • name

    the color name

Returns:

  • a new Magic::Pixel object

See Also:

  • Image_to_color
  • Pixel_to_color


495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'ext/RMagick/rmpixel.c', line 495

VALUE
Pixel_from_color(VALUE class, VALUE name)
{
    PixelColor pp;
    ExceptionInfo *exception;
    MagickBooleanType okay;

    class = class;      // defeat "never referenced" message from icc

    exception = AcquireExceptionInfo();
    okay = QueryColorCompliance(StringValuePtr(name), AllCompliance, &pp, exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(exception);

    if (!okay)
    {
        rb_raise(rb_eArgError, "invalid color name: %s", StringValuePtr(name));
    }

    return Pixel_from_PixelColor(&pp);
}

.from_HSL(hsl) ⇒ Object

Deprecated.

This method has been deprecated. Please use Pixel_from_hsla.

Construct an RGB pixel from the array [hue, saturation, luminosity].

Ruby usage:

- @verbatim Pixel.from_HSL  @endverbatim

Parameters:

  • class

    the Ruby class to use

  • hsl

    the array

Returns:

  • a new Magick::Pixel object



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'ext/RMagick/rmpixel.c', line 615

VALUE
Pixel_from_HSL(VALUE class, VALUE hsl)
{
    PixelColor rgb;
    double hue, saturation, luminosity;

    class = class;      // defeat "never referenced" message from icc
    memset(&rgb, 0, sizeof(rgb));

    hsl = rb_Array(hsl);    // Ensure array
    if (RARRAY_LEN(hsl) < 3)
    {
        rb_raise(rb_eArgError, "array argument must have at least 3 elements");
    }

    hue        = NUM2DBL(rb_ary_entry(hsl, 0));
    saturation = NUM2DBL(rb_ary_entry(hsl, 1));
    luminosity = NUM2DBL(rb_ary_entry(hsl, 2));

    rb_warning("Pixel#from_HSL is deprecated; use from_hsla");
    ConvertHSLToRGB(hue, saturation, luminosity,
                 &rgb.red, &rgb.green, &rgb.blue);
    return Pixel_from_PixelColor(&rgb);
}

.from_hsla(*args) ⇒ Object

Construct an RGB pixel.

Ruby usage:

- @verbatim Pixel#from_hsla(hue, saturation, lightness) @endverbatim
- @verbatim Pixel#from_hsla(hue, saturation, lightness, alpha) @endverbatim

Notes:

- Default alpha is 1.0
- 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%"
- Replaces brain-dead Pixel_from_HSL.

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • class

    the Ruby class to use

Returns:

  • a new Magick::Pixel object



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'ext/RMagick/rmpixel.c', line 538

VALUE
Pixel_from_hsla(int argc, VALUE *argv, VALUE class)
{
    double h, s, l, a = 1.0;
    MagickPixel pp;
    ExceptionInfo *exception;
    char name[50];
    MagickBooleanType alpha = MagickFalse;

    class = class;          // defeat "unused parameter" message.

    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)
    {
        sprintf(name, "hsla(%-2.1f,%-2.1f,%-2.1f,%-2.1f)", h, s, l, a);
    }
    else
    {
        sprintf(name, "hsl(%-2.1f,%-2.1f,%-2.1f)", h, s, l);
    }

    exception = AcquireExceptionInfo();

    (void) QueryMagickColor(name, &pp, exception);
    CHECK_EXCEPTION()

    (void) DestroyExceptionInfo(exception);

    return Pixel_from_MagickPixel(&pp);
}

Instance Method Details

#<=>(other) ⇒ Object

Support Comparable mixin.

Ruby usage:

- @verbatim Pixel#<=> @endverbatim

Parameters:

  • self

    this object

  • other

    the other Pixel

Returns:

  • -1, 0, 1



919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
# File 'ext/RMagick/rmpixel.c', line 919

VALUE
Pixel_spaceship(VALUE self, VALUE other)
{
    Pixel *this, *that;

    Data_Get_Struct(self, Pixel, this);
    Data_Get_Struct(other, Pixel, that);

    if (this->red != that->red)
    {
        return INT2NUM((this->red - that->red)/abs(this->red - that->red));
    }
    else if(this->green != that->green)
    {
        return INT2NUM((this->green - that->green)/abs(this->green - that->green));
    }
    else if(this->blue != that->blue)
    {
        return INT2NUM((this->blue - that->blue)/abs(this->blue - that->blue));
    }
    else if(this->opacity != that->opacity)
    {
        return INT2NUM((this->opacity - that->opacity)/abs(this->opacity - that->opacity));
    }

    // Values are equal, check class.

    return rb_funcall(CLASS_OF(self), rb_intern("<=>"), 1, CLASS_OF(other));

}

#===(other) ⇒ Object

“Case equal” operator for Pixel.

Ruby usage:

- @verbatim Pixel#=== @endverbatim

Parameters:

  • self

    this object

  • other

    the other object

Returns:

  • true or false



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'ext/RMagick/rmpixel.c', line 311

VALUE
Pixel_case_eq(VALUE self, VALUE other)
{
    Pixel *this, *that;

    if (CLASS_OF(self) == CLASS_OF(other))
    {
        Data_Get_Struct(self, Pixel, this);
        Data_Get_Struct(other, Pixel, that);
        return (this->red == that->red
            && this->blue == that->blue
            && this->green == that->green
            && this->opacity == that->opacity) ? Qtrue : Qfalse;
    }

    return Qfalse;
}

#cloneObject

Clone a Pixel.

Ruby usage:

- @verbatim Pixel#clone @endverbatim

Parameters:

  • self

    this object

Returns:

  • a clone

See Also:

  • Pixel_dup
  • Pixel_init_copy


341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'ext/RMagick/rmpixel.c', line 341

VALUE
Pixel_clone(VALUE self)
{
    VALUE clone;

    clone = Pixel_dup(self);
    if (OBJ_FROZEN(self))
    {
        OBJ_FREEZE(clone);
    }

    RB_GC_GUARD(clone);

    return clone;
}

#dupObject

Duplicate a Pixel.

Ruby usage:

- @verbatim Pixel#dup @endverbatim

Parameters:

  • self

    this object

Returns:

  • a clone

See Also:

  • Pixel_clone
  • Pixel_init_copy


369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'ext/RMagick/rmpixel.c', line 369

VALUE
Pixel_dup(VALUE self)
{
    Pixel *pixel;
    VALUE dup;

    pixel = ALLOC(Pixel);
    memset(pixel, '\0', sizeof(Pixel));
    dup = Data_Wrap_Struct(CLASS_OF(self), NULL, destroy_Pixel, pixel);
    if (rb_obj_tainted(self))
    {
        (void) rb_obj_taint(dup);
    }

    RB_GC_GUARD(dup);

    return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
}

#eql?(other) ⇒ Boolean

For use with Hash.

Ruby usage:

- @verbatim Pixel#eql? @endverbatim

Parameters:

  • self

    this object

  • other

    the other object

Returns:

  • (Boolean)

    true if hash to the same value, otherwise false



399
400
401
402
403
# File 'ext/RMagick/rmpixel.c', line 399

VALUE
Pixel_eql_q(VALUE self, VALUE other)
{
    return NUM2INT(Pixel_spaceship(self, other)) == 0 ? Qtrue : Qfalse;
}

#fcmp(*args) ⇒ Object

Compare pixel values for equality.

Ruby usage:

- @verbatim Pixel#fcmp(other, fuzz, colorspace) @endverbatim

Notes:

- Default fuzz is 0.0
- Default colorspace is RGBColorspace

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • true if equal, otherwise false



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'ext/RMagick/rmpixel.c', line 421

VALUE
Pixel_fcmp(int argc, VALUE *argv, VALUE self)
{
    Image *image;
    Info *info;

    Pixel *this, *that;
    ColorspaceType colorspace = RGBColorspace;
    double fuzz = 0.0;
    unsigned int equal;

    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;
    }

    Data_Get_Struct(self, Pixel, this);
    Data_Get_Struct(argv[0], Pixel, that);

    // 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
    (void) DestroyImageInfo(info);

    if (!image)
    {
        rb_raise(rb_eNoMemError, "not enough memory to continue");
    }

    image->colorspace = colorspace;
    image->fuzz = fuzz;

    equal = IsColorSimilar(image, this, that);
    (void) DestroyImage(image);

    return equal ? Qtrue : Qfalse;
}

#hashObject

Ruby usage:

- @verbatim Pixel#hash @endverbatim

Notes:

- INT2FIX left-shifts 1 bit. Sacrifice 1 bit from the opacity attribute to
  the FIXNUM_FLAG.

Parameters:

  • self

    this object

Returns:

  • the hash of self



730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
# File 'ext/RMagick/rmpixel.c', line 730

VALUE
Pixel_hash(VALUE self)
{
    Pixel *pixel;
    unsigned int hash;

    Data_Get_Struct(self, Pixel, pixel);

    hash  = ScaleQuantumToChar(pixel->red)   << 24;
    hash += ScaleQuantumToChar(pixel->green) << 16;
    hash += ScaleQuantumToChar(pixel->blue)  << 8;
    hash += ScaleQuantumToChar(pixel->opacity);

    return UINT2NUM(hash >> 1);
}

#initialize_copy(orig) ⇒ Object

Initialize clone, dup methods.

Ruby usage:

- @verbatim Pixel#initialize_copy @endverbatim

Parameters:

  • self

    this object

  • orig

    the original Pixel

Returns:

  • self

See Also:

  • Pixel_clone
  • Pixel_dup


759
760
761
762
763
764
765
766
767
768
769
770
# File 'ext/RMagick/rmpixel.c', line 759

VALUE
Pixel_init_copy(VALUE self, VALUE orig)
{
    Pixel *copy, *original;

    Data_Get_Struct(orig, Pixel, original);
    Data_Get_Struct(self, Pixel, copy);

    *copy = *original;

    return self;
}

#intensityObject

Return the “intensity” of a pixel.

Ruby usage:

- @verbatim Pixel#intensity @endverbatim

Parameters:

  • self

    this object

Returns:

  • the intensity



841
842
843
844
845
846
847
848
849
850
851
852
853
854
# File 'ext/RMagick/rmpixel.c', line 841

VALUE
Pixel_intensity(VALUE self)
{
    Pixel *pixel;
    Quantum intensity;

    Data_Get_Struct(self, Pixel, pixel);

    intensity = ROUND_TO_QUANTUM((0.299*pixel->red)
                                + (0.587*pixel->green)
                                + (0.114*pixel->blue));

    return QUANTUM2NUM((unsigned long) intensity);
}

#marshal_dumpObject

Support Marshal.dump.

Ruby usage:

- @verbatim Pixel#marshal_dump @endverbatim

Parameters:

  • self

    this object

Returns:

  • a string representing the dumped pixel



866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
# File 'ext/RMagick/rmpixel.c', line 866

VALUE
Pixel_marshal_dump(VALUE self)
{
    Pixel *pixel;
    VALUE dpixel;

    Data_Get_Struct(self, Pixel, 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));
    rb_hash_aset(dpixel, CSTR2SYM("opacity"), QUANTUM2NUM(pixel->opacity));

    RB_GC_GUARD(dpixel);

    return dpixel;
}

#marshal_load(dpixel) ⇒ Object

Support Marshal.load.

Ruby usage:

- @verbatim Pixel#marshal_load @endverbatim

Parameters:

  • self

    this object

  • dpixel

    the dumped pixel

Returns:

  • self



895
896
897
898
899
900
901
902
903
904
905
906
# File 'ext/RMagick/rmpixel.c', line 895

VALUE
Pixel_marshal_load(VALUE self, VALUE dpixel)
{
    Pixel *pixel;

    Data_Get_Struct(self, Pixel, 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")));
    pixel->opacity = NUM2QUANTUM(rb_hash_aref(dpixel, CSTR2SYM("opacity")));
    return self;
}

#to_color(*args) ⇒ Object

Return the color name corresponding to the pixel values.

Ruby usage:

- @verbatim Magick::Pixel#to_color @endverbatim
- @verbatim Magick::Pixel#to_color(compliance) @endverbatim
- @verbatim Magick::Pixel#to_color(compliance, matte) @endverbatim
- @verbatim Magick::Pixel#to_color(compliance, matte, depth) @endverbatim
- @verbatim Magick::Pixel#to_color(compliance, matte, depth, hex) @endverbatim

Notes:

- Default compliance is AllCompliance
- Default matte is false
- Default depth is MAGICKCORE_QUANTUM_DEPTH
- Default hex is false
- The conversion respects the value of the 'opacity' field in the Pixel

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • the color name as a String



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
1105
1106
1107
1108
1109
1110
1111
1112
1113
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
1162
# File 'ext/RMagick/rmpixel.c', line 1075

VALUE
Pixel_to_color(int argc, VALUE *argv, VALUE self)
{
    Info *info;
    Image *image;
    Pixel *pixel;
    MagickPixel mpp;
    MagickBooleanType hex = MagickFalse;
    char name[MaxTextExtent];
    ExceptionInfo *exception;
    ComplianceType compliance = AllCompliance;
    unsigned int matte = MagickFalse;
    unsigned int depth = MAGICKCORE_QUANTUM_DEPTH;

    switch (argc)
    {
        case 4:
            hex = 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:
            matte = 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);
    }

    Data_Get_Struct(self, Pixel, pixel);

    info = CloneImageInfo(NULL);
    image = rm_acquire_image(info);
    (void) DestroyImageInfo(info);

    if (!image)
    {
        rb_raise(rb_eNoMemError, "not enough memory to continue.");
    }

    image->depth = depth;
    image->matte = matte;

    rm_init_magickpixel(image, &mpp);
    rm_set_magick_pixel_packet(pixel, &mpp);

    exception = AcquireExceptionInfo();

    // 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)
        {
            mpp.matte = MagickFalse;
            mpp.depth = (unsigned long) min(1.0 * image->depth, 16.0);
        }
        (void) GetColorTuple(&mpp, MagickTrue, name);
    }
    else
    {
        (void) QueryMagickColorname(image, &mpp, compliance, name, exception);
    }

    (void) DestroyImage(image);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(exception);

    // Always return a string, even if it's ""
    return rb_str_new2(name);
}

#to_HSLObject

Deprecated.

This method has been deprecated. Please use Pixel_to_hsla.

Convert an RGB pixel to the array [hue, saturation, luminosity].

Ruby usage:

- @verbatim Pixel#to_HSL @endverbatim

Parameters:

  • self

    this object

Returns:

  • an array with hsl data



1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
# File 'ext/RMagick/rmpixel.c', line 1010

VALUE
Pixel_to_HSL(VALUE self)
{
    Pixel *pixel;
    double hue, saturation, luminosity;
    VALUE hsl;

    Data_Get_Struct(self, Pixel, pixel);

    rb_warning("Pixel#to_HSL is deprecated; use to_hsla");
    ConvertRGBToHSL(pixel->red, pixel->green, pixel->blue, &hue, &saturation, &luminosity);

    hsl = rb_ary_new3(3, rb_float_new(hue), rb_float_new(saturation),
                      rb_float_new(luminosity));

    RB_GC_GUARD(hsl);

    return hsl;
}

#to_hslaObject

Return [hue, saturation, lightness, alpha] in the same ranges as Pixel_from_hsla.

Ruby usage:

- @verbatim Pixel#to_hsla @endverbatim

Notes:

- Replace brain-dead Pixel_to_HSL.

Parameters:

  • self

    this object

Returns:

  • an array with hsla data

See Also:

  • Pixel_from_hsla


966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
# File 'ext/RMagick/rmpixel.c', line 966

VALUE
Pixel_to_hsla(VALUE self)
{
    double hue, sat, lum, alpha;
    Pixel *pixel;
    VALUE hsla;

    Data_Get_Struct(self, Pixel, pixel);

    ConvertRGBToHSL(pixel->red, pixel->green, pixel->blue, &hue, &sat, &lum);
    hue *= 360.0;
    sat *= 255.0;
    lum *= 255.0;

    if (pixel->opacity == OpaqueOpacity)
    {
        alpha = 1.0;
    }
    else if (pixel->opacity == TransparentOpacity)
    {
        alpha = 0.0;
    }
    else
    {
        alpha = (double)(QuantumRange - pixel->opacity) / (double)QuantumRange;
    }

    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_sObject

Create a string representation of a Magick::Pixel.

Ruby usage:

- @verbatim Magick::Pixel#to_s @endverbatim

Parameters:

  • self

    this object

Returns:

  • the string



1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
# File 'ext/RMagick/rmpixel.c', line 1174

VALUE
Pixel_to_s(VALUE self)
{
    Pixel *pixel;
    char buff[100];

    Data_Get_Struct(self, Pixel, pixel);
    sprintf(buff, "red=" QuantumFormat ", green=" QuantumFormat ", blue=" QuantumFormat ", opacity=" QuantumFormat
          , pixel->red, pixel->green, pixel->blue, pixel->opacity);
    return rb_str_new2(buff);
}