Don-Reba

RGB cube in Lab colourspace

May 7th, 2014
356
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. // REFERENCE: ConvertColor.dll
  2.  
  3. using ConvertColor;
  4. using System.IO;
  5.  
  6. def δ = 4;
  7. def vertexCount = 6 * (256 / δ + 1) * (256 / δ + 1);
  8. def faceCount   = 6 * (256 / δ) * (256 / δ);
  9.  
  10. def writer = File.CreateText("lab.ply");
  11. [ "ply"
  12. , "format ascii 1.0"
  13. , "comment Created by Alexey Badalov"
  14. , $"element vertex $vertexCount"
  15. , "property float x"
  16. , "property float y"
  17. , "property float z"
  18. , "property float red"
  19. , "property float green"
  20. , "property float blue"
  21. , $"element face $faceCount"
  22. , "property list uchar uint vertex_indices"
  23. , "end_header"
  24. ].Iter(writer.WriteLine);
  25.  
  26. def ProcessSide(WriteVertex : double * double -> void)
  27. {
  28.     foreach (b in [0, δ .. 256])
  29.     foreach (a in [0, δ .. 256])
  30.         WriteVertex(a / 256.0, b / 256.0);
  31. }
  32.  
  33. def WriteVertex(r, g, b)
  34. {
  35.     def (x, y, z) = (r, g, b) |> RgbToXyz |> XyzToLab;
  36.     def x = x / 50.0;
  37.     def y = y / 50.0;
  38.     def z = z / 50.0;
  39.     writer.WriteLine(string.Join(" ", array[x, y, z, r, g, b]))
  40. }
  41.  
  42. ProcessSide(WriteVertex(0, _, _));
  43. ProcessSide(WriteVertex(1, _, _));
  44. ProcessSide(WriteVertex(_, 0, _));
  45. ProcessSide(WriteVertex(_, 1, _));
  46. ProcessSide(WriteVertex(_, _, 0));
  47. ProcessSide(WriteVertex(_, _, 1));
  48.  
  49. foreach (k in [0 .. 5])
  50. foreach (b in [0 .. 256 / δ - 1])
  51. foreach (a in [0 .. 256 / δ - 1])
  52. {
  53.     def offset = k * (256 / δ + 1) * (256 / δ + 1);
  54.     def v0 = offset + (b + 0) * (256 / δ + 1) + a + 0;
  55.     def v1 = offset + (b + 1) * (256 / δ + 1) + a + 0;
  56.     def v2 = offset + (b + 1) * (256 / δ + 1) + a + 1;
  57.     def v3 = offset + (b + 0) * (256 / δ + 1) + a + 1;
  58.     writer.WriteLine("4 {0} {1} {2} {3}", v0, v1, v2, v3)
  59. }
  60.  
  61.  
  62. writer.Close();
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment