.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Color::Calc 3pm" .TH Color::Calc 3pm "2015-06-01" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Color::Calc \- Simple calculations with RGB colors. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 6 \& use Color::Calc (); \& my $background = \*(Aqgreen\*(Aq; \& print \*(Aqbackground: \*(Aq,Color::Calc::color_html($background),";\en"; \& print \*(Aqborder\-top: solid 1px \*(Aq,Color::Calc::light_html($background),";\en"; \& print \*(Aqborder\-bottom: solid 1px \*(Aq,Color::Calc::dark_html($background),";\en"; \& print \*(Aqcolor: \*(Aq,Color::Calc::contrast_bw_html($background),";\en"; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \f(CW\*(C`Color::Calc\*(C'\fR module implements simple calculations with \s-1RGB\s0 colors. This can be used to create a full color scheme from a few colors. .SS "\s-1USAGE\s0" .IX Subsection "USAGE" \fIConstructors\fR .IX Subsection "Constructors" .IP "Color::Calc\->new( ... )" 4 .IX Item "Color::Calc->new( ... )" This class method creates a new \f(CW\*(C`Color::Calc\*(C'\fR object. .Sp .Vb 3 \& use Color::Calc(); \& my $cc = new Color::Calc( \*(AqColorScheme\*(Aq => \*(AqX\*(Aq, OutputFormat => \*(AqHTML\*(Aq ); \& print $cc\->invert( \*(Aqwhite\*(Aq ); .Ve .Sp It accepts the following parameters: .RS 4 .IP "ColorScheme" 4 .IX Item "ColorScheme" One of the color schemes accepted by \f(CW\*(C`Graphics::ColorNames\*(C'\fR, which is used to interpret color names on input. Valid values include \f(CW\*(C`X\*(C'\fR (color names used in X\-Windows) and \f(CW\*(C`HTML\*(C'\fR (color names defined in the \s-1HTML 4.0\s0 specification). For a full list of possible values, please refer to the documentation of of \&\f(CW\*(C`Graphics::ColorNames\*(C'\fR. .Sp Unlike \f(CW\*(C`Graphics::ColorNames\*(C'\fR, barewords are \fIalways\fR interpreted as a module name under \f(CW\*(C`Graphics::ColorNames\*(C'\fR. If you really want to use a filename like \&\*(L"foo\*(R", you have to write it as \*(L"./foo\*(R". .Sp Default: \f(CW\*(C`X\*(C'\fR (Note: This is incompatible with \s-1HTML\s0 color names). .IP "OutputFormat" 4 .IX Item "OutputFormat" One of the output formats defined by this module. Possible values are: .RS 4 .IP "tuple" 4 .IX Item "tuple" Returns a list of three values in the range 0..255. The first value is guaranteed to have a \f(CW\*(C`length\*(C'\fR that is not a multiple of three. .IP "hex" 4 .IX Item "hex" Returns a hexadecimal \s-1RGB\s0 value as a scalar that contains a string in the format \s-1RRGGBB\s0 and a number representing the hexadecimal number 0xRRGGBB. .IP "html" 4 .IX Item "html" Returns a string compatible with W3C's \s-1HTML\s0 and \s-1CSS\s0 specifications, i.e. \fI#RRGGBB\fR or one of the sixteen \s-1HTML\s0 color names. .IP "obj" 4 .IX Item "obj" (\s-1DEPRECATED\s0) Returns a \f(CW\*(C`Color::Object\*(C'\fR reference. The module \f(CW\*(C`Color::Object\*(C'\fR must be installed, of course. .IP "object" 4 .IX Item "object" Returns a \f(CW\*(C`Graphics::ColorObject\*(C'\fR reference. The module \&\f(CW\*(C`Graphics::ColorObject\*(C'\fR must be installed, of course. .IP "pdf" 4 .IX Item "pdf" Returns a string compatible with \f(CW\*(C`PDF::API2\*(C'\fR, i.e. \fI#RRGGBB\fR. .IP "_\|_MODEvar" 4 .IX Item "__MODEvar" (\s-1DEPRECATED\s0) Uses the value of \f(CW$Color::Calc::MODE\fR to select one of the above output formats. You should use \f(CW\*(C`local\*(C'\fR when setting this variable: .Sp .Vb 1 \& local $Color::Calc::MODE = \*(Aqhtml\*(Aq; .Ve .RE .RS 4 .Sp Default: \f(CW\*(C`_\|_MODEvar\*(C'\fR (for compatibility) .RE .RE .RS 4 .RE .IP "Color::Calc\->import( ... )" 4 .IX Item "Color::Calc->import( ... )" This method creates a new, hidden object and binds its methods to the namespace of the calling module. .Sp This method is usually not called directly but from perl's \f(CW\*(C`use\*(C'\fR statement: .Sp .Vb 5 \& use Color::Calc( \& \*(AqColorScheme\*(Aq => \*(AqX\*(Aq, \& \*(AqOutputFormat\*(Aq => \*(AqHTML\*(Aq, \& \*(AqPrefix\*(Aq => \*(Aqcc\*(Aq ); \& print cc_invert( \*(Aqwhite\*(Aq ); # prints \*(Aqblack\*(Aq .Ve .Sp On import, you can specify the following parameters: .RS 4 .IP "ColorScheme" 4 .IX Item "ColorScheme" See above. .IP "OutputFormat" 4 .IX Item "OutputFormat" See above. .IP "Prefix" 4 .IX Item "Prefix" Adds a prefix to the front of the method names. The calculation methods are bound to the name \fIprefix\fR_\fImethod_name\fR (the specified prefix, an underscore, the calculation method's name). Further, \fIprefix\fR is made an alias for \fIprefix\fR\f(CW\*(C`_get\*(C'\fR. .Sp Default: \f(CW\*(C`color\*(C'\fR .RE .RS 4 .Sp Please note that with perl's \f(CW\*(C`use\*(C'\fR and \f(CW\*(C`import\*(C'\fR statemehts, omitting the list and specifying an empty list has different meanings: .Sp .Vb 1 \& use Color::Calc; # import with default settings (see below) \& \& use Color::Calc(); # don\*(Aqt import anything .Ve .RE .PP \fIProperty \*(L"set\*(R"/\*(L"get\*(R" methods\fR .IX Subsection "Property set/get methods" .PP These methods are inaccessible without a object reference, i.e. when the functions have been \f(CW\*(C`import\*(C'\fRed. .ie n .IP "$cc\->set_output_format( $format)" 4 .el .IP "\f(CW$cc\fR\->set_output_format( \f(CW$format\fR)" 4 .IX Item "$cc->set_output_format( $format)" Changes the output format for an existing \f(CW\*(C`Color::Calc\*(C'\fR object. .PP \fICalculation methods\fR .IX Subsection "Calculation methods" .PP All calculation methods \fIalways\fR accept the following formats for \f(CW$color\fR or \&\f(CW$color1\fR/\f(CW$color2\fR: .IP "\(bu" 4 An arrayref pointing to an array with three elements in the range \&\f(CW0\fR..\f(CW255\fR corresponding to the red, green, and blue component. .IP "\(bu" 4 A list of three values in the range \f(CW0\fR..\f(CW255\fR corresponding to the red, green, and blue component where the first value does not have 3 or a multiple of 3 digits (e.g. \f(CW\*(C`(\*(Aq0128\*(Aq,128,128)\*(C'\fR). .IP "\(bu" 4 A string containing a hexadecimal \s-1RGB\s0 value like \&\f(CW\*(C`#\f(CIRGB\f(CW\*(C'\fR/\f(CW\*(C`#\f(CIRRGGBB\f(CW\*(C'\fR/\f(CW\*(C`#\f(CIRRRGGGBBB\f(CW\*(C'\fR/..., or \&\f(CW\*(C`\f(CIRGB\f(CW\*(C'\fR/\f(CW\*(C`\f(CIRRGGBB\f(CW\*(C'\fR/\f(CW\*(C`\f(CIRRRGGGBBB\f(CW\*(C'\fR/... .IP "\(bu" 4 A color name accepted by \f(CW\*(C`Graphics::ColorNames\*(C'\fR. The interpretation is controlled by the \f(CW\*(C`ColorScheme\*(C'\fR parameter. .IP "\(bu" 4 A \f(CW\*(C`Graphics::ColorObject\*(C'\fR reference. .PP The calculation methods can be either accessed through a \f(CW\*(C`Color::Calc\*(C'\fR object reference (here: \f(CW$cc\fR) or through the method names imported by \f(CW\*(C`import\*(C'\fR (here using the prefix color). .ie n .IP "$cc\->get($color) / color($color)" 4 .el .IP "\f(CW$cc\fR\->get($color) / color($color)" 4 .IX Item "$cc->get($color) / color($color)" Returns \f(CW$color\fR as-is (but in the selected output format). This function can be used for color format conversion/normalisation. .ie n .IP "$cc\->invert($color) / color_invert($color)" 4 .el .IP "\f(CW$cc\fR\->invert($color) / color_invert($color)" 4 .IX Item "$cc->invert($color) / color_invert($color)" Returns the inverse of \f(CW$color\fR. .ie n .IP "$cc\->opposite($color) / color_opposite($color)" 4 .el .IP "\f(CW$cc\fR\->opposite($color) / color_opposite($color)" 4 .IX Item "$cc->opposite($color) / color_opposite($color)" Returns a color that is on the opposite side of the color wheel but roughly keeps the saturation and lightness. .ie n .IP "$cc\->bw($color) / color_bw($color)" 4 .el .IP "\f(CW$cc\fR\->bw($color) / color_bw($color)" 4 .IX Item "$cc->bw($color) / color_bw($color)" .PD 0 .ie n .IP "$cc\->grey($color) / color_grey($color)" 4 .el .IP "\f(CW$cc\fR\->grey($color) / color_grey($color)" 4 .IX Item "$cc->grey($color) / color_grey($color)" .ie n .IP "$cc\->gray($color) / color_gray($color)" 4 .el .IP "\f(CW$cc\fR\->gray($color) / color_gray($color)" 4 .IX Item "$cc->gray($color) / color_gray($color)" .PD Converts \f(CW$color\fR to greyscale. .ie n .IP "$cc\->round($color, $value_count) / color_round($color, $value_count)" 4 .el .IP "\f(CW$cc\fR\->round($color, \f(CW$value_count\fR) / color_round($color, \f(CW$value_count\fR)" 4 .IX Item "$cc->round($color, $value_count) / color_round($color, $value_count)" Rounds each component to to the nearest number determined by dividing the range 0..255 into \f(CW$value_count\fR+1 portions. .Sp The default for \f(CW$value_count\fR is 6, yielding 6^3\ =\ 216 colors. Values that are one higher than divisors of 255 yield the best results (e.g. 3+1, 5+1, 7+1, 9+1, 15+1, 17+1, ...). .ie n .IP "$cc\->safe($color) / color_safe($color)" 4 .el .IP "\f(CW$cc\fR\->safe($color) / color_safe($color)" 4 .IX Item "$cc->safe($color) / color_safe($color)" Rounds each color component to a multiple of 0x33 (dec. 51) or to a named color defined in the \s-1HTML 4.01\s0 specification. .Sp Historically, these colors have been known as web-safe colors. They still provide a convenient color palette. .ie n .IP "$cc\->mix($color1, $color2 [, $alpha]) / color_mix($color1, $color2 [, $alpha])" 4 .el .IP "\f(CW$cc\fR\->mix($color1, \f(CW$color2\fR [, \f(CW$alpha\fR]) / color_mix($color1, \f(CW$color2\fR [, \f(CW$alpha\fR])" 4 .IX Item "$cc->mix($color1, $color2 [, $alpha]) / color_mix($color1, $color2 [, $alpha])" Returns a color that is the mixture of \f(CW$color1\fR and \f(CW$color2\fR. .Sp The optional \f(CW$alpha\fR parameter can be a value between 0.0 (use \&\f(CW$color1\fR only) and 1.0 (use \f(CW$color2\fR only), the default is 0.5. .ie n .IP "$cc\->light($color [, $alpha]) / color_light($color [, $alpha])" 4 .el .IP "\f(CW$cc\fR\->light($color [, \f(CW$alpha\fR]) / color_light($color [, \f(CW$alpha\fR])" 4 .IX Item "$cc->light($color [, $alpha]) / color_light($color [, $alpha])" Returns a lighter version of \f(CW$color\fR, i.e. returns \&\f(CW\*(C`mix($color,[255,255,255],$alpha)\*(C'\fR. .Sp The optional \f(CW$alpha\fR parameter can be a value between 0.0 (use \f(CW$color\fR only) and 1.0 (use [255,255,255] only), the default is 0.5. .ie n .IP "$cc\->dark($color [, $alpha]) / color_dark($color [, $alpha])" 4 .el .IP "\f(CW$cc\fR\->dark($color [, \f(CW$alpha\fR]) / color_dark($color [, \f(CW$alpha\fR])" 4 .IX Item "$cc->dark($color [, $alpha]) / color_dark($color [, $alpha])" Returns a darker version of \f(CW$color\fR, i.e. returns \&\f(CW\*(C`mix($color,[0,0,0],$alpha)\*(C'\fR. .Sp The optional \f(CW$alpha\fR parameter can be a value between 0.0 (use \&\f(CW$color\fR only) and 1.0 (use [0,0,0] only), the default is 0.5. .ie n .IP "$cc\->contrast($color [, $cut]) / color_contrast($color [, $cut])" 4 .el .IP "\f(CW$cc\fR\->contrast($color [, \f(CW$cut\fR]) / color_contrast($color [, \f(CW$cut\fR])" 4 .IX Item "$cc->contrast($color [, $cut]) / color_contrast($color [, $cut])" Returns a color that has the highest possible contrast to the input color. .Sp This is done by setting the red, green, and blue values to 0 if the corresponding value in the input is above \f(CW\*(C`($cut * 255)\*(C'\fR and to 255 otherwise. .Sp The default for \f(CW$cut\fR is .5, representing a cutoff between 127 and 128. .ie n .IP "$cc\->contrast_bw($color [, $cut]) / color_contrast_bw($color [, $cut])" 4 .el .IP "\f(CW$cc\fR\->contrast_bw($color [, \f(CW$cut\fR]) / color_contrast_bw($color [, \f(CW$cut\fR])" 4 .IX Item "$cc->contrast_bw($color [, $cut]) / color_contrast_bw($color [, $cut])" Returns black or white, whichever has the higher contrast to \f(CW$color\fR. .Sp This is done by returning black if the grey value of \f(CW$color\fR is above \f(CW\*(C`($cut * 255)\*(C'\fR and white otherwise. .Sp The default for \f(CW$cut\fR is .5, representing a cutoff between 127 and 128. .ie n .IP "$cc\->blend($color [, $alpha]) / color_blend($color [, $alpha])" 4 .el .IP "\f(CW$cc\fR\->blend($color [, \f(CW$alpha\fR]) / color_blend($color [, \f(CW$alpha\fR])" 4 .IX Item "$cc->blend($color [, $alpha]) / color_blend($color [, $alpha])" Returns a color that blends into the background, i.e. it returns \&\f(CW\*(C`mix($color,contrast($color),$alpha)\*(C'\fR. .Sp The optional \f(CW$alpha\fR parameter can be a value between 0.0 (use \&\f(CW$color\fR only) and 1.0 (use \f(CW\*(C`contrast($color)\*(C'\fR only), the default is 0.5. .Sp The idea is that \f(CW$color\fR is the foreground color, so \&\f(CW\*(C`contrast($color)\*(C'\fR is similar to the background color. Mixing them returns a color somewhere between them. .Sp You might want to use \f(CW\*(C`mix($color, $background, $alpha)\*(C'\fR instead if you know the real background color. .ie n .IP "$cc\->blend_bw($color [, $alpha]) / color_blend_bw($color [, $alpha])" 4 .el .IP "\f(CW$cc\fR\->blend_bw($color [, \f(CW$alpha\fR]) / color_blend_bw($color [, \f(CW$alpha\fR])" 4 .IX Item "$cc->blend_bw($color [, $alpha]) / color_blend_bw($color [, $alpha])" Returns a mix of \f(CW$color\fR and black or white, whichever has the higher contrast to \f(CW$color\fR. .Sp The optional \f(CW$alpha\fR parameter can be a value between 0.0 (use \&\f(CW$color\fR only) and 1.0 (use black/white only), the default is 0.5. .PP \fIFunctions\fR .IX Subsection "Functions" .PP The calculation methods are also available as functions. The output format is selected through the function name. .PP These functions are deprecated as they do not allow selecting the scheme of recognized color names, which defaults to Graphics::ColorNames::X (and is incompatible with \s-1HTML\s0's color names). .PP By default, i.e. when no list is specified with \f(CW\*(C`use\*(C'\fR or \f(CW\*(C`import\*(C'\fR, all of these functions are exported. .IP "color, color_mix, ..." 4 .IX Item "color, color_mix, ..." Use \f(CW$Color::Calc::MODE\fR as the output format. This is the default. .IP "color_hex, color_mix_html, ..." 4 .IX Item "color_hex, color_mix_html, ..." Use \f(CW\*(C`hex\*(C'\fR as the output format. .IP "color_html, color_mix_html, ..." 4 .IX Item "color_html, color_mix_html, ..." Use \f(CW\*(C`html\*(C'\fR as the output format. Please note that the color names recognized are still based on X's color names, which are incompatible with \s-1HTML.\s0 You can't use the output of these functions as input for other color_*_html functions. .Sp See Color::Calc::WWW for an alternative that does not suffer from this problem. .IP "color_pdf, color_mix_pdf, ..." 4 .IX Item "color_pdf, color_mix_pdf, ..." Use \f(CW\*(C`pdf\*(C'\fR as the output format. .IP "color_object, color_mix_object, ..." 4 .IX Item "color_object, color_mix_object, ..." Use \f(CW\*(C`object\*(C'\fR as the output format. .SH "SEE ALSO" .IX Header "SEE ALSO" Graphics::ColorNames (required); Graphics::ColorObject (optional) .SH "AUTHOR" .IX Header "AUTHOR" Claus Fa\*:rber .SH "LICENSE" .IX Header "LICENSE" Copyright 2004\-2010 Claus Fa\*:rber. All rights reserved. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.