Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.71 KB | None | 0 0
  1. @nogc void ditherColorLine(LineT,ColT)(auto ref LineT line, int x0, int x1, int y, in ColT col1, in ColT col2) pure nothrow
  2. {
  3.     enum W = 8;
  4.     enum H = 8;
  5.     immutable ColT[2] cols = [col1, col2];
  6.     static immutable patterns = [
  7.         [0,0,0,0,1,1,1,1],
  8.         [0,0,0,1,0,1,1,1],
  9.         [0,0,1,0,1,0,1,1],
  10.         [0,1,0,1,0,1,0,1],
  11.        
  12.         [0,0,1,0,1,0,1,1],
  13.         [0,1,0,1,0,1,0,1],
  14.         [0,0,1,0,1,0,1,1],
  15.         [0,0,0,1,0,1,1,1]];
  16.     static assert(patterns.length    == H);
  17.     static assert(patterns[0].length == W);
  18.     const p = patterns[y % H];
  19.     auto l = line[x0..x1];
  20.     foreach(x;0..l.length)
  21.     {
  22.         const xw = x % W;
  23.         l[x] = cols[p[xw]];
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement