File Coverage

blib/lib/PDL/Graphics/ColorSpace.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             #
2             # GENERATED WITH PDL::PP from color_space.pd! Don't modify!
3             #
4             package PDL::Graphics::ColorSpace;
5              
6             our @EXPORT_OK = qw(rgb_to_xyz xyz_to_rgb xyz_to_lab lab_to_xyz rgb_to_lch lch_to_rgb rgb_to_lab lab_to_rgb add_rgb_space rgb_to_cmyk cmyk_to_rgb rgb_to_hsl hsl_to_rgb rgb_to_hsv hsv_to_rgb xyY_to_xyz _rgb_to_xyz _xyz_to_rgb _xyz_to_lab _lab_to_xyz lab_to_lch lch_to_lab rgb_to_linear rgb_from_linear );
7             our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
8              
9 1     1   228201 use PDL::Core;
  1         2  
  1         10  
10 1     1   490 use PDL::Exporter;
  1         2  
  1         13  
11 1     1   36 use DynaLoader;
  1         2  
  1         561  
12              
13              
14             our $VERSION = '0.206';
15             our @ISA = ( 'PDL::Exporter','DynaLoader' );
16             push @PDL::Core::PP, __PACKAGE__;
17             bootstrap PDL::Graphics::ColorSpace $VERSION;
18              
19              
20              
21              
22              
23              
24              
25              
26             #line 13 "color_space.pd"
27              
28             =encoding utf8
29              
30             =head1 NAME
31              
32             PDL::Graphics::ColorSpace - colour-space conversions for PDL
33              
34             =head1 SYNOPSIS
35              
36             use PDL::LiteF;
37             use PDL::IO::Pic;
38             use PDL::Graphics::ColorSpace;
39              
40             my $image_rgb = PDL->rpic('photo.jpg') if PDL->rpiccan('JPEG');
41              
42             # convert RGB value from [0,255] to [0,1]
43             $image_rgb = $image_rgb->double / 255;
44              
45             my $image_xyz = $image_rgb->rgb_to_xyz( 'sRGB' );
46              
47             Or
48              
49             my $image_xyz = rgb_to_xyz( $image_rgb, 'sRGB' );
50              
51             =head1 DESCRIPTION
52              
53             Does image color space conversions such as RGB to XYZ and Lab to LCH. Derived from Graphics::ColorObject (Izvorski & Reibenschuh, 2005) but since it's implemented in C and PDL, it runs *much* faster.
54              
55             Often the conversion will return out-of-gamut values. Retaining out-of-gamut values allows chained conversions to be lossless and reverse conversions to produce the original values. You can clip the values to be within-gamut if necessary. Please check the specific color space for the gamut range.
56              
57             =head1 COLOR SPACES
58              
59             =head2 RGB
60              
61             An RGB color space is any additive color space based on the RGB color model. A particular RGB color space is defined by the three chromaticities of the red, green, and blue additive primaries, and can produce any chromaticity that is the triangle defined by those primary colors. The complete specification of an RGB color space also requires a white point chromaticity and a gamma correction curve.
62              
63             For more info on the RGB color space, see L.
64              
65             This module expects and produces RGB values normalized to be in the range of [0,1]. If you have / need integer value between [0,255], divide or multiply the values by 255.
66              
67             =head2 CMYK
68              
69             CMYK refers to the four inks used in some color printing: cyan, magenta, yellow, and key (black). The CMYK model works by partially or entirely masking colors on a lighter, usually white, background. The ink reduces the light that would otherwise be reflected. Such a model is called subtractive because inks "subtract" brightness from white.
70              
71             In additive color models such as RGB, white is the "additive" combination of all primary colored lights, while black is the absence of light. In the CMYK model, it is the opposite: white is the natural color of the paper or other background, while black results from a full combination of colored inks. To save money on ink, and to produce deeper black tones, unsaturated and dark colors are produced by using black ink instead of the combination of cyan, magenta and yellow.
72              
73             For more info, see L.
74              
75             =head2 HSL
76              
77             Hue, Saturation and Luminance (or brightness).
78              
79             The HSL color space defines colors more naturally: Hue specifies the base color, the other two values then let you specify the saturation of that color and how bright the color should be.
80              
81             Hue is specified here as degrees ranging from 0 to 360. There are 6 base colors:
82              
83             0 red
84             60 yellow
85             120 green
86             180 cyan
87             240 blue
88             300 magenta
89             360 red
90              
91             Saturation specifies the distance from the middle of the color wheel. So a saturation value of 0 (0%) means "center of the wheel", i.e. a grey value, whereas a saturation value of 1 (100%) means "at the border of the wheel", where the color is fully saturated.
92              
93             Luminance describes how "bright" the color is. 0 (0%) means 0 brightness and the color is black. 1 (100%) means maximum brightness and the color is white.
94              
95             For more info, see L.
96              
97             =head2 XYZ and xyY
98              
99             The CIE XYZ color space was derived the CIE RGB color space. XYZ are three hypothetical primaries. Y means brightness, Z is quasi-equal to blue stimulation, and X is a mix which looks like red sensitivity curve of cones. All visible colors can be represented by using only positive values of X, Y, and Z. The main advantage of the CIE XYZ space (and any color space based on it) is that this space is completely device-independent.
100              
101             For more info, see L.
102              
103             =head2 Lab
104              
105             A Lab color space is a color-opponent space with dimension L for lightness and a and b for the color-opponent dimensions, based on nonlinearly compressed CIE XYZ color space coordinates. It's derived from the "master" space CIE 1931 XYZ color space but is more perceptually uniform than XYZ. The Lab space is relative to the white point of the XYZ data they were converted from. Lab values do not define absolute colors unless the white point is also specified.
106              
107             For more info, see L.
108              
109             =head2 LCH
110              
111             This is possibly a little easier to comprehend than the Lab colour space, with which it shares several features. It is more correctly known as L*C*H*. Essentially it is in the form of a sphere. There are three axes; L* and C* and H°.
112              
113             The L* axis represents Lightness. This is vertical; from 0, which has no lightness (i.e. absolute black), at the bottom; through 50 in the middle, to 100 which is maximum lightness (i.e. absolute white) at the top.
114              
115             The C* axis represents Chroma or "saturation". This ranges from 0 at the centre of the circle, which is completely unsaturated (i.e. a neutral grey, black or white) to 100 or more at the edge of the circle for very high Chroma (saturation) or "colour purity".
116              
117             If we take a horizontal slice through the centre, we see a coloured circle. Around the edge of the circle we see every possible saturated colour, or Hue. This circular axis is known as H° for Hue. The units are in the form of degrees° (or angles), ranging from 0 (red) through 90 (yellow), 180 (green), 270 (blue) and back to 0.
118              
119             For more info, see L.
120              
121             =head1 OPTIONS
122              
123             Some conversions require specifying the RGB space which includes gamma curve and white point definitions. Supported RGB spaces include (aliases in square brackets):
124              
125             Adobe RGB (1998) [Adobe]
126             Apple RGB [Apple]
127             BestRGB
128             Beta RGB
129             BruceRGB
130             CIE
131             ColorMatch
132             DonRGB4
133             ECI
134             Ekta Space PS5
135             NTSC [601] [CIE Rec 601]
136             PAL/SECAM [PAL] [CIE ITU]
137             ProPhoto
138             SMPTE-C [SMPTE]
139             WideGamut
140             sRGB [709] [CIE Rec 709]
141             lsRGB
142              
143             You can also add custom RGB space definitions via the function add_rgb_space.
144             Alternatively, as of 0.202 you can directly supply the function with a
145             hash-ref in the same format.
146              
147             =head1 CONVERSIONS
148              
149             Some conversions, if not already included as functions, can be achieved
150             by chaining existing functions. For example, LCH to HSV conversion can
151             be achieved by chaining lch_to_rgb and rgb_to_hsv:
152              
153             my $hsv = rgb_to_hsv( lch_to_rgb( $lch, 'sRGB' ), 'sRGB' );
154              
155             To generate a local diagram of what conversions are available between
156             formats, using GraphViz, you can use this script:
157              
158             use blib;
159             use PDL::Graphics::ColorSpace;
160             print "digraph {\n";
161             print join(' -> ', split /_to_/), "\n"
162             for grep !/^_/ && /_to_/, @PDL::Graphics::ColorSpace::EXPORT_OK;
163             print "}\n";
164             # then:
165             perl scriptname >d.dot; dot -Tsvg d.dot >d.svg; display d.svg
166              
167             (As of 0.202, this is everything to and from C, plus C <->
168             C <-> C)
169              
170             =cut
171              
172             use strict;
173             use warnings;
174              
175             use Carp;
176             use PDL::LiteF;
177             use PDL::Graphics::ColorSpace::RGBSpace;
178              
179             my $RGB_SPACE = $PDL::Graphics::ColorSpace::RGBSpace::RGB_SPACE;
180             #line 181 "ColorSpace.pm"
181              
182              
183             =head1 FUNCTIONS
184              
185             =cut
186              
187              
188              
189              
190              
191              
192             =head2 rgb_to_cmyk
193              
194             =for sig
195              
196             Signature: (rgb(c=3); [o]cmyk(d=4))
197             Types: (double)
198              
199             =pod
200              
201             =for ref
202              
203             Converts an RGB color triple to an CMYK color quadruple.
204              
205             The first dimension of the ndarrays holding the rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...). The first dimension of the ndarrays holding the cmyk values must be size 4.
206              
207             =for usage
208              
209             Usage:
210              
211             my $cmyk = rgb_to_cmyk( $rgb );
212              
213             =pod
214              
215             Broadcasts over its inputs.
216              
217             =for bad
218              
219             =for bad
220              
221             If C encounters a bad value in any of the R, G, or B values the output ndarray will be marked as bad and the associated C, M, Y, and K values will all be marked as bad.
222              
223             =cut
224              
225              
226              
227              
228             *rgb_to_cmyk = \&PDL::rgb_to_cmyk;
229              
230              
231              
232              
233              
234              
235             =head2 cmyk_to_rgb
236              
237             =for sig
238              
239             Signature: (cmyk(d=4); [o]rgb(c=3))
240             Types: (double)
241              
242             =pod
243              
244             =for ref
245              
246             Converts an CMYK color quadruple to an RGB color triple
247              
248             The first dimension of the ndarrays holding the cmyk values must be size 4, i.e. the dimensions must look like (4, m, n, ...). The first dimension of the ndarray holding the rgb values must be 3.
249              
250             =for usage
251              
252             Usage:
253              
254             my $rgb = cmyk_to_rgb( $cmyk );
255              
256             =pod
257              
258             Broadcasts over its inputs.
259              
260             =for bad
261              
262             =for bad
263              
264             If C encounters a bad value in any of the C, M, Y, or K quantities, the output ndarray will be marked as bad and the associated R, G, and B color values will all be marked as bad.
265              
266             =cut
267              
268              
269              
270              
271             *cmyk_to_rgb = \&PDL::cmyk_to_rgb;
272              
273              
274              
275              
276              
277              
278             =head2 rgb_to_hsl
279              
280             =for sig
281              
282             Signature: (rgb(c=3); [o]hsl(c=3))
283             Types: (double)
284              
285             =pod
286              
287             =for ref
288              
289             Converts an RGB color triple to an HSL color triple.
290              
291             The first dimension of the ndarrays holding the hsl and rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
292              
293             =for usage
294              
295             Usage:
296              
297             my $hsl = rgb_to_hsl( $rgb );
298              
299             =pod
300              
301             Broadcasts over its inputs.
302              
303             =for bad
304              
305             =for bad
306              
307             If C encounters a bad value in any of the R, G, or B values the output ndarray will be marked as bad and the associated H, S, and L values will all be marked as bad.
308              
309             =cut
310              
311              
312              
313              
314             *rgb_to_hsl = \&PDL::rgb_to_hsl;
315              
316              
317              
318              
319              
320              
321             =head2 hsl_to_rgb
322              
323             =for sig
324              
325             Signature: (hsl(c=3); [o]rgb(c=3))
326             Types: (double)
327              
328             =pod
329              
330             =for ref
331              
332             Converts an HSL color triple to an RGB color triple
333              
334             The first dimension of the ndarrays holding the hsl and rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
335              
336             =for usage
337              
338             Usage:
339              
340             my $rgb = hsl_to_rgb( $hsl );
341              
342             =pod
343              
344             Broadcasts over its inputs.
345              
346             =for bad
347              
348             =for bad
349              
350             If C encounters a bad value in any of the H, S, or V quantities, the output ndarray will be marked as bad and the associated R, G, and B color values will all be marked as bad.
351              
352             =cut
353              
354              
355              
356              
357             *hsl_to_rgb = \&PDL::hsl_to_rgb;
358              
359              
360              
361              
362              
363              
364             =head2 rgb_to_hsv
365              
366             =for sig
367              
368             Signature: (rgb(c=3); [o]hsv(c=3))
369             Types: (double)
370              
371             =pod
372              
373             =for ref
374              
375             Converts an RGB color triple to an HSV color triple.
376              
377             The first dimension of the ndarrays holding the hsv and rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
378              
379             =for usage
380              
381             Usage:
382              
383             my $hsv = rgb_to_hsv( $rgb );
384              
385             =pod
386              
387             Broadcasts over its inputs.
388              
389             =for bad
390              
391             =for bad
392              
393             If C encounters a bad value in any of the R, G, or B values the output ndarray will be marked as bad and the associated H, S, and V values will all be marked as bad.
394              
395             =cut
396              
397              
398              
399              
400             *rgb_to_hsv = \&PDL::rgb_to_hsv;
401              
402              
403              
404              
405              
406              
407             =head2 hsv_to_rgb
408              
409             =for sig
410              
411             Signature: (hsv(c=3); [o]rgb(c=3))
412             Types: (double)
413              
414             =pod
415              
416             =for ref
417              
418             Converts an HSV color triple to an RGB color triple
419              
420             The first dimension of the ndarrays holding the hsv and rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
421              
422             =for usage
423              
424             Usage:
425              
426             my $rgb = hsv_to_rgb( $hsv );
427              
428             =pod
429              
430             Broadcasts over its inputs.
431              
432             =for bad
433              
434             =for bad
435              
436             If C encounters a bad value in any of the H, S, or V quantities, the output ndarray will be marked as bad and the associated R, G, and B color values will all be marked as bad.
437              
438             =cut
439              
440              
441              
442              
443             *hsv_to_rgb = \&PDL::hsv_to_rgb;
444              
445              
446              
447              
448              
449              
450             =head2 xyY_to_xyz
451              
452             =for sig
453              
454             Signature: (xyY(c=3); [o]xyz(c=3))
455             Types: (double)
456              
457             =for usage
458              
459             $xyz = xyY_to_xyz($xyY);
460             xyY_to_xyz($xyY, $xyz); # all arguments given
461             $xyz = $xyY->xyY_to_xyz; # method call
462             $xyY->xyY_to_xyz($xyz);
463             $xyY->inplace->xyY_to_xyz; # can be used inplace
464             xyY_to_xyz($xyY->inplace);
465              
466             =for ref
467              
468             Internal function for white point calculation. Use it if you must.
469              
470             =pod
471              
472             Broadcasts over its inputs.
473              
474             =for bad
475              
476             C processes bad values.
477             It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
478              
479             =cut
480              
481              
482              
483              
484             *xyY_to_xyz = \&PDL::xyY_to_xyz;
485              
486              
487              
488              
489             *_rgb_to_xyz = \&PDL::_rgb_to_xyz;
490              
491              
492              
493              
494             *_xyz_to_rgb = \&PDL::_xyz_to_rgb;
495              
496              
497              
498              
499             *_xyz_to_lab = \&PDL::_xyz_to_lab;
500              
501              
502              
503              
504             *_lab_to_xyz = \&PDL::_lab_to_xyz;
505              
506              
507              
508              
509              
510              
511             =head2 lab_to_lch
512              
513             =for sig
514              
515             Signature: (lab(c=3); [o]lch(c=3))
516             Types: (double)
517              
518             =pod
519              
520             =for ref
521              
522             Converts an Lab color triple to an LCH color triple.
523              
524             The first dimension of the ndarrays holding the lab values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
525              
526             =for usage
527              
528             Usage:
529              
530             my $lch = lab_to_lch( $lab );
531              
532             =pod
533              
534             Broadcasts over its inputs.
535              
536             =for bad
537              
538             =for bad
539              
540             If C encounters a bad value in any of the L, a, or b values the output ndarray will be marked as bad and the associated L, C, and H values will all be marked as bad.
541              
542             =cut
543              
544              
545              
546              
547             *lab_to_lch = \&PDL::lab_to_lch;
548              
549              
550              
551              
552              
553              
554             =head2 lch_to_lab
555              
556             =for sig
557              
558             Signature: (lch(c=3); [o]lab(c=3))
559             Types: (double)
560              
561             =pod
562              
563             =for ref
564              
565             Converts an LCH color triple to an Lab color triple.
566              
567             The first dimension of the ndarrays holding the lch values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
568              
569             =for usage
570              
571             Usage:
572              
573             my $lab = lch_to_lab( $lch );
574              
575             =pod
576              
577             Broadcasts over its inputs.
578              
579             =for bad
580              
581             =for bad
582              
583             If C encounters a bad value in any of the L, C, or H values the output ndarray will be marked as bad and the associated L, a, and b values will all be marked as bad.
584              
585             =cut
586              
587              
588              
589              
590             *lch_to_lab = \&PDL::lch_to_lab;
591              
592              
593              
594              
595              
596              
597             =head2 rgb_to_linear
598              
599             =for sig
600              
601             Signature: (rgb(c=3); gamma(); [o]out(c=3))
602             Types: (double)
603              
604             =for ref
605              
606             Converts an RGB color triple (presumably with gamma) to an RGB color triple
607             with linear values.
608              
609             =for usage
610              
611             Usage:
612              
613             my $rgb_linear = rgb_to_linear( $gammaed, 2.2 );
614              
615             =pod
616              
617             Broadcasts over its inputs.
618              
619             =for bad
620              
621             =for bad
622              
623             If C encounters a bad value in any of the R, G, or B
624             values the output ndarray will be marked as bad and the associated R,
625             G, and B values will all be marked as bad.
626              
627             =cut
628              
629              
630              
631              
632             *rgb_to_linear = \&PDL::rgb_to_linear;
633              
634              
635              
636              
637              
638              
639             =head2 rgb_from_linear
640              
641             =for sig
642              
643             Signature: (rgb(c=3); gamma(); [o]out(c=3))
644             Types: (double)
645              
646             =for ref
647              
648             Converts an RGB color triple (presumably linear) to an RGB color triple
649             with the specified gamma.
650              
651             =for usage
652              
653             Usage:
654              
655             my $gammaed = rgb_from_linear( $rgb_linear, 2.2 );
656              
657             =pod
658              
659             Broadcasts over its inputs.
660              
661             =for bad
662              
663             =for bad
664              
665             If C encounters a bad value in any of the R, G, or B
666             values the output ndarray will be marked as bad and the associated R,
667             G, and B values will all be marked as bad.
668              
669             =cut
670              
671              
672              
673              
674             *rgb_from_linear = \&PDL::rgb_from_linear;
675              
676              
677              
678              
679              
680             #line 752 "color_space.pd"
681              
682             =head2 rgb_to_xyz
683              
684             =for ref
685              
686             Converts an RGB color triple to an XYZ color triple.
687              
688             The first dimension of the ndarrays holding the rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
689              
690             =for bad
691              
692             If C encounters a bad value in any of the R, G, or B values the output ndarray will be marked as bad and the associated X, Y, and Z values will all be marked as bad.
693              
694             =for usage
695              
696             Usage:
697              
698             my $xyz = rgb_to_xyz( $rgb, 'sRGB' );
699             my $xyz = rgb_to_xyz( $rgb, \%rgb_spec );
700              
701             =cut
702              
703             *rgb_to_xyz = \&PDL::rgb_to_xyz;
704             sub PDL::rgb_to_xyz {
705             my ($rgb, $space) = @_;
706             my $spec = get_space($space);
707             my $m = PDL->topdl( $spec->{m} );
708             return _rgb_to_xyz( $rgb, $spec->{gamma}, $m );
709             }
710              
711             =head2 xyz_to_rgb
712              
713             =for ref
714              
715             Converts an XYZ color triple to an RGB color triple.
716              
717             The first dimension of the ndarrays holding the xyz and rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
718              
719             =for bad
720              
721             If C encounters a bad value in any of the X, Y, or Z values the output ndarray will be marked as bad and the associated R, G, and B values will all be marked as bad.
722              
723             =for usage
724              
725             Usage:
726              
727             my $rgb = xyz_to_rgb( $xyz, 'sRGB' );
728             my $rgb = xyz_to_rgb( $xyz, \%rgb_spec );
729              
730             =cut
731              
732             *xyz_to_rgb = \&PDL::xyz_to_rgb;
733             sub PDL::xyz_to_rgb {
734             my ($xyz, $space) = @_;
735             my $spec = get_space($space);
736             my $mstar = exists $spec->{mstar} ? PDL->topdl( $spec->{mstar} ) : PDL->topdl( $spec->{m} )->inv;
737             return _xyz_to_rgb( $xyz, $spec->{gamma}, $mstar );
738             }
739              
740             =head2 xyz_to_lab
741              
742             =for ref
743              
744             Converts an XYZ color triple to an Lab color triple.
745              
746             The first dimension of the ndarrays holding the xyz values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
747              
748             =for bad
749              
750             If C encounters a bad value in any of the X, Y, or Z values the output ndarray will be marked as bad and the associated L, a, and b values will all be marked as bad.
751              
752             =for usage
753              
754             Usage:
755              
756             my $lab = xyz_to_lab( $xyz, 'sRGB' );
757             my $lab = xyz_to_lab( $xyz, \%rgb_spec );
758              
759             =cut
760              
761             *xyz_to_lab = \&PDL::xyz_to_lab;
762             sub PDL::xyz_to_lab {
763             my ($xyz, $space) = @_;
764             my $spec = get_space($space);
765             my $w = PDL->topdl($spec->{white_point});
766             return _xyz_to_lab( $xyz, $w );
767             }
768              
769             =head2 lab_to_xyz
770              
771             =for ref
772              
773             Converts an Lab color triple to an XYZ color triple.
774              
775             The first dimension of the ndarrays holding the lab values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
776              
777             =for bad
778              
779             If C encounters a bad value in any of the L, a, or b values the output ndarray will be marked as bad and the associated X, Y, and Z values will all be marked as bad.
780              
781             =for usage
782              
783             Usage:
784              
785             my $xyz = lab_to_xyz( $lab, 'sRGB' );
786             my $xyz = lab_to_xyz( $lab, \%rgb_spec );
787              
788             =cut
789              
790             *lab_to_xyz = \&PDL::lab_to_xyz;
791             sub PDL::lab_to_xyz {
792             my ($lab, $space) = @_;
793             my $spec = get_space($space);
794             my $w = PDL->topdl($spec->{white_point});
795             return _lab_to_xyz( $lab, $w );
796             }
797              
798             =head2 rgb_to_lch
799              
800             =for ref
801              
802             Converts an RGB color triple to an LCH color triple.
803              
804             The first dimension of the ndarrays holding the rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
805              
806             =for bad
807              
808             If C encounters a bad value in any of the R, G, or B values the output ndarray will be marked as bad and the associated L, C, and H values will all be marked as bad.
809              
810             =for usage
811              
812             Usage:
813              
814             my $lch = rgb_to_lch( $rgb, 'sRGB' );
815             my $lch = rgb_to_lch( $rgb, \%rgb_spec );
816              
817             =cut
818              
819             *rgb_to_lch = \&PDL::rgb_to_lch;
820             sub PDL::rgb_to_lch {
821             my ($rgb, $space) = @_;
822             my $spec = get_space($space);
823             my $lab = xyz_to_lab( rgb_to_xyz( $rgb, $spec ), $spec );
824             return lab_to_lch( $lab );
825             }
826              
827             =head2 lch_to_rgb
828              
829             =for ref
830              
831             Converts an LCH color triple to an RGB color triple.
832              
833             The first dimension of the ndarrays holding the lch values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
834              
835             =for bad
836              
837             If C encounters a bad value in any of the L, C, or H values the output ndarray will be marked as bad and the associated R, G, and B values will all be marked as bad.
838              
839             =for usage
840              
841             Usage:
842              
843             my $rgb = lch_to_rgb( $lch, 'sRGB' );
844             my $rgb = lch_to_rgb( $lch, \%rgb_spec );
845              
846             =cut
847              
848             *lch_to_rgb = \&PDL::lch_to_rgb;
849             sub PDL::lch_to_rgb {
850             my ($lch, $space) = @_;
851             my $spec = get_space($space);
852             my $xyz = lab_to_xyz( lch_to_lab( $lch ), $spec );
853             return xyz_to_rgb( $xyz, $spec );
854             }
855              
856             =head2 rgb_to_lab
857              
858             =for ref
859              
860             Converts an RGB color triple to an LAB color triple.
861              
862             The first dimension of the ndarrays holding the rgb values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
863              
864             =for bad
865              
866             If C encounters a bad value in any of the R, G, or B values the output ndarray will be marked as bad and the associated L, A, and B values will all be marked as bad.
867              
868             =for usage
869              
870             Usage:
871              
872             my $lab = rgb_to_lab( $rgb, 'sRGB' );
873             my $lab = rgb_to_lab( $rgb, \%rgb_spec );
874              
875             =cut
876              
877             *rgb_to_lab = \&PDL::rgb_to_lab;
878             sub PDL::rgb_to_lab {
879             my ($rgb, $space) = @_;
880             my $spec = get_space($space);
881             return xyz_to_lab( rgb_to_xyz( $rgb, $spec ), $spec );
882             }
883              
884             =head2 lab_to_rgb
885              
886             =for ref
887              
888             Converts an LAB color triple to an RGB color triple.
889              
890             The first dimension of the ndarrays holding the lab values must be size 3, i.e. the dimensions must look like (3, m, n, ...).
891              
892             =for bad
893              
894             If C encounters a bad value in any of the L, A, or B values the output ndarray will be marked as bad and the associated R, G, and B values will all be marked as bad.
895              
896             =for usage
897              
898             Usage:
899              
900             my $rgb = lab_to_rgb( $lab, 'sRGB' );
901             my $rgb = lab_to_rgb( $lab, \%rgb_spec );
902              
903             =cut
904              
905             *lab_to_rgb = \&PDL::lab_to_rgb;
906             sub PDL::lab_to_rgb {
907             my ($lab, $space) = @_;
908             my $spec = get_space($space);
909             return xyz_to_rgb( lab_to_xyz( $lab, $spec ), $spec );
910             }
911              
912             =head2 add_rgb_space
913              
914             Supports adding custom RGB space definitions. The C and C
915             can be supplied as PDL ndarrays if desired. As of 0.202, you don't need
916             to provide an C since the inverse of the C will be calculated
917             (once) as a default.
918              
919             Usage:
920              
921             my %custom_space = (
922             custom_1 => {
923             'gamma' => '2.2',
924             'm' => [
925             [
926             '0.467384242424242',
927             '0.240995',
928             '0.0219086363636363'
929             ],
930             [
931             '0.294454030769231',
932             '0.683554',
933             '0.0736135076923076'
934             ],
935             [
936             '0.18863',
937             '0.075452',
938             '0.993451333333334'
939             ]
940             ],
941             'white_point' => [
942             '0.312713',
943             '0.329016'
944             ],
945             },
946             custom_2 => { ... },
947             );
948              
949             add_rgb_space( \%custom_space );
950              
951             my $rgb = lch_to_rgb( $lch, 'custom_1' );
952              
953             =cut
954              
955             *add_rgb_space = \&PDL::Graphics::ColorSpace::RGBSpace::add_rgb_space;
956             *get_space = \&PDL::Graphics::ColorSpace::RGBSpace::get_space;
957              
958             =head1 SEE ALSO
959              
960             Graphics::ColorObject
961              
962             =head1 AUTHOR
963              
964             ~~~~~~~~~~~~ ~~~~~ ~~~~~~~~ ~~~~~ ~~~ `` ><(((">
965              
966             Copyright (C) 2012 Maggie J. Xiong
967              
968             Original work sponsored by Shutterstock, LLC L
969              
970             All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation as described in the file COPYING in the PDL distribution.
971              
972             =cut
973             #line 974 "ColorSpace.pm"
974              
975             # Exit with OK status
976              
977             1;