#define BRESENHAM_LOOP(color) { \ if (steep) \ fb[x * width + y] = color; \ else \ fb[y * width + x] = color; \ \ while (x != x2) { \ x += xstep; \ error += derror; \ \ if (error << 1 >= dx) { \ y += ystep; \ error -= dx; \ } \ \ if (steep) \ fb[x * width + y] = color; \ else \ fb[y * width + x] = color; \ } \ } inline uint32 rgb_to_32(rgb_color color) { return (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } void AccelerantDriver::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &_color) { RGBColor color = _color; int32 width = mFrameBufferConfig.bytes_per_row; // setup variables for bresenham algorithm bool steep = abs(y2 - y1) > abs(x2 - x1); if (steep) { // swap x1 and y1 int32 temp = x1; x1 = y1; y1 = temp; // swap x2 and y2 temp = x2; x2 = y2; y2 = temp; } int32 dx = abs(x2 - x1); int32 dy = abs(y2 - y1); int32 error = 0; int32 derror = dy; int32 x = x1; int32 y = y1; int32 xstep = 1; int32 ystep = 1; if (x1 >= x2) xstep = -1; if (y1 >= y2) ystep = -1; switch (mDisplayMode.space) { case B_CMAP8: case B_GRAY8: { uint8 *fb = (uint8 *)mFrameBufferConfig.frame_buffer; uint8 draw_color = color.GetColor8(); BRESENHAM_LOOP(draw_color); } break; case B_RGB15_BIG: case B_RGBA15_BIG: case B_RGB15_LITTLE: case B_RGBA15_LITTLE: { uint16 *fb = (uint16 *)mFrameBufferConfig.frame_buffer; uint16 draw_color = color.GetColor15(); width /= 2; BRESENHAM_LOOP(draw_color); } break; case B_RGB16_BIG: case B_RGB16_LITTLE: { uint16 *fb = (uint16 *)mFrameBufferConfig.frame_buffer; uint16 draw_color = color.GetColor16(); width /= 2; BRESENHAM_LOOP(draw_color); } break; case B_RGB32_BIG: case B_RGBA32_BIG: case B_RGB32_LITTLE: case B_RGBA32_LITTLE: { uint32 *fb = (uint32 *)mFrameBufferConfig.frame_buffer; uint32 draw_color = rgb_to_32(color.GetColor32()); width /= 4; BRESENHAM_LOOP(draw_color); } break; default: printf("Error: Unknown color space\n"); } } void AccelerantDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d) { PatternHandler drawPattern(d->patt); int32 width = mFrameBufferConfig.bytes_per_row; // setup variables for bresenham algorithm bool steep = abs(y2 - y1) > abs(x2 - x1); if (steep) { // swap x1 and y1 int32 temp = x1; x1 = y1; y1 = temp; // swap x2 and y2 temp = x2; x2 = y2; y2 = temp; } int32 dx = abs(x2 - x1); int32 dy = abs(y2 - y1); int32 error = 0; int32 derror = dy; int32 x = x1; int32 y = y1; int32 xstep = 1; int32 ystep = 1; if (x1 >= x2) xstep = -1; if (y1 >= y2) ystep = -1; switch (mDisplayMode.space) { case B_CMAP8: case B_GRAY8: { uint8 *fb = (uint8 *)mFrameBufferConfig.frame_buffer; BRESENHAM_LOOP(drawPattern.ColorAt((float)x,(float)y).GetColor8()); } break; case B_RGB15_BIG: case B_RGBA15_BIG: case B_RGB15_LITTLE: case B_RGBA15_LITTLE: { uint16 *fb = (uint16 *)mFrameBufferConfig.frame_buffer; width /= 2; BRESENHAM_LOOP(drawPattern.ColorAt((float)x,(float)y).GetColor15()); } break; case B_RGB16_BIG: case B_RGB16_LITTLE: { uint16 *fb = (uint16 *)mFrameBufferConfig.frame_buffer; width /= 2; BRESENHAM_LOOP(drawPattern.ColorAt((float)x,(float)y).GetColor16()); } break; case B_RGB32_BIG: case B_RGBA32_BIG: case B_RGB32_LITTLE: case B_RGBA32_LITTLE: { uint32 *fb = (uint32 *)mFrameBufferConfig.frame_buffer; width /= 4; BRESENHAM_LOOP(rgb_to_32(drawPattern.ColorAt((float)x,(float)y).GetColor32())); } break; default: printf("Error: Unknown color space\n"); } }