| 75 | } |
| 76 | |
| 77 | void image_u8::draw_line(int xs, int ys, int xe, int ye, const color_quad_u8& color) |
| 78 | { |
| 79 | if (xs > xe) |
| 80 | { |
| 81 | std::swap(xs, xe); |
| 82 | std::swap(ys, ye); |
| 83 | } |
| 84 | |
| 85 | int dx = xe - xs, dy = ye - ys; |
| 86 | if (!dx) |
| 87 | { |
| 88 | if (ys > ye) |
| 89 | std::swap(ys, ye); |
| 90 | for (int i = ys; i <= ye; i++) |
| 91 | set_pixel_clipped(xs, i, color); |
| 92 | } |
| 93 | else if (!dy) |
| 94 | { |
| 95 | for (int i = xs; i < xe; i++) |
| 96 | set_pixel_clipped(i, ys, color); |
| 97 | } |
| 98 | else if (dy > 0) |
| 99 | { |
| 100 | if (dy <= dx) |
| 101 | { |
| 102 | int e = 2 * dy - dx, e_no_inc = 2 * dy, e_inc = 2 * (dy - dx); |
| 103 | rasterize_line(xs, ys, xe, ye, 0, 1, e, e_inc, e_no_inc, color); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | int e = 2 * dx - dy, e_no_inc = 2 * dx, e_inc = 2 * (dx - dy); |
| 108 | rasterize_line(xs, ys, xe, ye, 1, 1, e, e_inc, e_no_inc, color); |
| 109 | } |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | dy = -dy; |
| 114 | if (dy <= dx) |
| 115 | { |
| 116 | int e = 2 * dy - dx, e_no_inc = 2 * dy, e_inc = 2 * (dy - dx); |
| 117 | rasterize_line(xs, ys, xe, ye, 0, -1, e, e_inc, e_no_inc, color); |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | int e = 2 * dx - dy, e_no_inc = (2 * dx), e_inc = 2 * (dx - dy); |
| 122 | rasterize_line(xe, ye, xs, ys, 1, -1, e, e_inc, e_no_inc, color); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void image_u8::rasterize_line(int xs, int ys, int xe, int ye, int pred, int inc_dec, int e, int e_inc, int e_no_inc, const color_quad_u8& color) |
| 128 | { |
nothing calls this directly
no test coverage detected