1 /** 2 3 This module mostly exist to have a bridge with the ggplotd code and the ggplotd.color code. That is because the ggplotd.color code might become part of phobos one day and I don't want to depend directly on ggplotd's implementation, so that it stays easy to switch to an alternative (phobos) based implementation. 4 5 */ 6 module ggplotd.colourspace; 7 8 import chsx = ggplotd.color.hsx; 9 import crgb = ggplotd.color.rgb; 10 import cxyz = ggplotd.color.xyz; 11 import cconv = ggplotd.color.conv; 12 import cColor = ggplotd.color; 13 14 alias HCY = chsx.HCY!double; 15 alias RGB = crgb.RGB!("rgb",double); 16 alias RGBA = crgb.RGB!("rgba",double); 17 alias XYZ = cxyz.XYZ!double; 18 19 alias toColourSpace = cconv.convertColor; 20 alias isColour = cColor.isColor; 21 22 import cairo = cairo.cairo; 23 cairo.RGBA toCairoRGBA(C)( C from ) 24 { 25 auto rgb = toColourSpace!(RGBA,C)( from ); 26 return cairo.RGBA( 27 rgb.r, 28 rgb.g, 29 rgb.b, 30 rgb.a 31 ); 32 } 33 34 C fromCairoRGBA(C)( cairo.RGBA crgb ) 35 { 36 auto rgba = RGBA( crgb.red, crgb.green, crgb.blue, crgb.alpha ); 37 return toColourSpace!C( rgba ); 38 } 39 40 auto toTuple(T : HCY)( T colour ) 41 { 42 import std.typecons : Tuple; 43 return Tuple!(double, double, double)( colour.h, colour.c, colour.y ); 44 } 45 46 auto toTuple(T : XYZ)( T colour ) 47 { 48 import std.typecons : Tuple; 49 return Tuple!(double, double, double)( colour.X, colour.Y, colour.Z ); 50 } 51 52 auto toTuple(T)( T colour ) 53 { 54 import std.typecons : Tuple; 55 return Tuple!(double, double, double)( colour.r, colour.g, colour.b ); 56 } 57