Login / Status
developer.Resource
Home . Documentation . Document Library . Extension Manuals
Sponsors
hosted by punkt.deTYPO3 and Open Source Magazine

1.2. Functions

hexadecimal2rgb ( $hex ):

This function converts a hexadecimal value to an array. It checks weather the user input was three or six character for a hexadecimal number. It returns the rgb array.

colorbrightness($r,$g,$b):

The colorbrightness is calculated by the formula: ((r-value * 299) + (g-value*587) + (b-value*114)) / 1000. The formula is taken from http://juicystudio.com/services/colourcontrast.php.

This funktion gets three values for red, green and blue and returns the amount of brightness.

http://juicystudio.com/services/colourcontrast.php

greyscalecolors($r,$g,$b):

This function greyscales a color by its rgb values. The grey value of a color calculated by this formula:

grey = 0.299*R + 0.587*G + 0.114*B

taken from http://www1.tip.nl/~t876506/ColorDesign.html .

After cutting the decimal places the grey value of the original color is returned.

When you click the checkbox “switch style” (see above) you can chose between different styles. One of them ist the grey scale view(see following picture)

.

rgb2lms($rgbarray):

This function converts an rgb array to a array with long, middle and short values.

The formula is:

long = r * 0.1992 + g * 0.4112 + b * 0.0742;

middle = r * 0.0353 + g * 0.2226 + b * 0.0574;

short = r * 0.0185 + g * 0.1231 + b * 1.355;

taken from http://www.fx.clemson.edu/~rkarl/c2g.html .

It gets the rgb array and returns the lms array.

lms2rgb($lmsarray)

This is the inverse function to rgb2lms. See above. It simply does the opposite. This function is taken from   http://www.fx.clemson.edu/~rkarl/c2g.html as well.

calculatedeficiency($rgbarray,$component):

Finally this is the method to simulate the deficiency. You put in the rgb array and the code for the dificiency you want to simulate.

H. Brettel, F. Vienot and J. Mollon found the algorithm to simulate protanopia, deuteranopia and tritanopia. It is only an research because normally you can't tell what a website looks from the eye of a colorblind.

This function takes an array of rgb values and converts it to lms values (see rgb2lms). Then you veryfy the lms value to declare alpha, beta and gamma . The formula is

alpha = m * s – s2 * m2;

beta  = s * l -  l2 * s2;

gamma = l * m – m2 * l2;

You need these values to re-calculate the lms values for the color deficiency.

L = -1 * (beta * m + gamma * s ) / alpha

M= -1 * (alpha * l + gamma * s) / beta

S = -1 * (alpha*  l + beta * m) / gamma

Finally you convert this array back into rgb values (see lms2rgb).

The code is taken from http://www.fx.clemson.edu/~rkarl/c2g.html

When you confirm the checkbox “simulate deficiency” you are able to chose between four types of color deficiencies. These are protanopia, deuteranopia, tritanopia and achromatopsia.

The last option is to show the page without a deficiency.

checkhex($hex):

This function checks the valid input of a hexadecimal number. If the characters are between  0 and F, they're valid. Else they aren't valid. It takes the string of the hexadecimal value and returns a boolean.

achromatopsia($r, $g, $b):

This function simulates achromatopsia. It takes three values for rgb and calculates the maximum out of it. The maximum value goes into any of the three values to have the grey tone of a color.

It returns the array with the grey values (each the same).