SHARE
TWEET

Untitled

a guest Feb 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. target_color      
  2. 'rgb(200,200,200)'
  3. 'rgb(190,29,209)'
  4.    
  5. target_hue   ~   target_saturation  ~ target_lightness   ~   hex_value
  6. 10          ~    40        ~         40           ~         a567ff
  7.    
  8. SET @rgb := 'rgb(190,29,209)' ;
  9.  
  10. SELECT @rgb
  11.      , @rgbv := SUBSTRING_INDEX(SUBSTRING_INDEX(@rgb,'rgb(',-1),')',1) AS `@rgbv`
  12.      , @v1 := SUBSTRING_INDEX(@rgbv,',',1)                             AS `@v1`
  13.      , @v2 := SUBSTRING_INDEX(SUBSTRING_INDEX(@rgbv,',',2),',',-1)     AS `@v2`
  14.      , @v3 := SUBSTRING_INDEX(SUBSTRING_INDEX(@rgbv,',',3),',',-1)     AS `@v3`
  15.      , 0 + @v1  AS R
  16.      , 0 + @v2  AS G
  17.      , 0 + @v3  AS B
  18.    
  19. GREATEST(0+@v1,0+@v2,0+@v3) - LEAST(0+@v1,0+@v2,0+@v3)
  20.    
  21. IF(0+@v1>0+@v2
  22.   ,IF(0+@v1>0+@v3,0+@v1,IF(0+@v2>0+@v3,0+@v2,0+@v3))
  23.   ,IF(0+@v2>0+@v3,0+@v2,0+@v3)
  24.   ) AS `max(R,G,B)`
  25.  
  26. IF(0+@v1<0+@v2
  27.   ,IF(0+@v1<0+@v3,0+@v1,IF(0+@v2<0+@v3,0+@v2,0+@v3))
  28.   ,IF(0+@v2<0+@v3,0+@v2,0+@v3)
  29.   ) AS `min(R,G,B)`
  30.    
  31. SELECT s.R
  32.      , s.G
  33.      , s.B
  34.      , IF(s.R>s.G,IF(s.R>s.B,s.R,s.B),IF(s.G>s.B,s.G,s.B)) AS `max(R,G,B)`
  35.      , IF(s.R<s.G,IF(s.R<s.B,s.R,s.B),IF(s.G<s.B,s.G,s.B)) AS `min(R,G,B)`
  36.   FROM (
  37.          SELECT t.rgb
  38.               , @rgbv := SUBSTRING_INDEX(SUBSTRING_INDEX(t.rgb,'rgb(',-1),')',1) AS `@rgbv`
  39.               , @v1 := SUBSTRING_INDEX(@rgbv,',',1)                              AS `@v1`
  40.               , @v2 := SUBSTRING_INDEX(SUBSTRING_INDEX(@rgbv,',',2),',',-1)      AS `@v2`
  41.               , @v3 := SUBSTRING_INDEX(SUBSTRING_INDEX(@rgbv,',',3),',',-1)      AS `@v3`
  42.               , 0 + @v1  AS v1
  43.               , 0 + @v2  AS v2
  44.               , 0 + @v3  AS v3
  45.            FROM mytable t
  46.        ) s
  47.    
  48. select
  49.    substring(rgb, locate('(',rgb)+1,locate(',',rgb) -1 - locate('(',rgb)) as red,
  50.    substring(substring_index(rgb,',',2) , locate(',',rgb)+1) as green,
  51.    substring(rgb, locate(',',rgb, locate(',',rgb)+1 )+1 , locate(')',rgb)
  52.                    -1 - locate(',',rgb, locate(',',rgb)+1 )) as blue
  53.    
  54. red  green  blue
  55. 190  29     209
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top