static void fill_pixel_rect(DiaRenderer *self, int x, int y, int width, int height, Color *color) { DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self); guint8 r,g,b; guint8 *ptr; int i; int stride; CLIP_1D_LEN(renderer->clip_rect.left, renderer->clip_rect.right, x, width); if (width < 0) return; CLIP_1D_LEN(renderer->clip_rect.top, renderer->clip_rect.bottom, y, height); if (height < 0) return; r = color->red*0xff; g = color->green*0xff; b = color->blue*0xff; stride = renderer->pixel_width*3; ptr = renderer->rgb_buffer + x*3 + y*stride; for (i=0;i<=height;i++) { art_rgb_fill_run(ptr, r, g, b, width+1); ptr += stride; } }
static void draw_pixel_rect(DiaRenderer *self, int x, int y, int width, int height, Color *color) { DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self); guint8 r,g,b; int start, len; int stride; r = color->red*0xff; g = color->green*0xff; b = color->blue*0xff; stride = renderer->pixel_width*3; /* clip in x */ start = x; len = width; CLIP_1D_LEN(renderer->clip_rect.left, renderer->clip_rect.right, start, len); /* top line */ if ( (y>=renderer->clip_rect.top) && (y<=renderer->clip_rect.bottom) ) { draw_hline(self, start, y, len, r, g, b); } /* bottom line */ if ( (y+height>=renderer->clip_rect.top) && (y+height<=renderer->clip_rect.bottom) ) { draw_hline(self, start, y+height, len, r, g, b); } /* clip in y */ start = y; len = height; CLIP_1D_LEN(renderer->clip_rect.top, renderer->clip_rect.bottom, start, len); /* left line */ if ( (x>=renderer->clip_rect.left) && (x<renderer->clip_rect.right) ) { draw_vline(self, x, start, len, r, g, b); } /* right line */ if ( (x+width>=renderer->clip_rect.left) && (x+width<renderer->clip_rect.right) ) { draw_vline(self, x+width, start, len, r, g, b); } }
static void draw_pixel_line(DiaRenderer *self, int x1, int y1, int x2, int y2, Color *color) { DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self); guint8 r,g,b; guint8 *ptr; int start, len; int stride; int i; int x, y; int dx, dy, adx, ady; int incx, incy; int incx_ptr, incy_ptr; int frac_pos; IntRectangle *clip_rect; r = color->red*0xff; g = color->green*0xff; b = color->blue*0xff; if (y1==y2) { /* Horizontal line */ start = x1; len = x2-x1; CLIP_1D_LEN(renderer->clip_rect.left, renderer->clip_rect.right, start, len); /* top line */ if ( (y1>=renderer->clip_rect.top) && (y1<=renderer->clip_rect.bottom) ) { draw_hline(self, start, y1, len, r, g, b); } return; } if (x1==x2) { /* Vertical line */ start = y1; len = y2-y1; CLIP_1D_LEN(renderer->clip_rect.top, renderer->clip_rect.bottom, start, len); /* left line */ if ( (x1>=renderer->clip_rect.left) && (x1<=renderer->clip_rect.right) ) { draw_vline(self, x1, start, len, r, g, b); } return; } /* Ugh, kill me slowly for writing this line-drawer. * It is actually a standard bresenham, but not very optimized. * It is also not very well tested. */ stride = renderer->pixel_width*3; clip_rect = &renderer->clip_rect; dx = x2-x1; dy = y2-y1; adx = (dx>=0)?dx:-dx; ady = (dy>=0)?dy:-dy; x = x1; y = y1; ptr = renderer->rgb_buffer + x*3 + y*stride; if (adx>=ady) { /* x-major */ if (dx>0) { incx = 1; incx_ptr = 3; } else { incx = -1; incx_ptr = -3; } if (dy>0) { incy = 1; incy_ptr = stride; } else { incy = -1; incy_ptr = -stride; } frac_pos = adx; for (i=0;i<=adx;i++) { /* Amazing... He does the clipping in the inner loop! It must be horribly inefficient! */ if ( (x>=clip_rect->left) && (x<=clip_rect->right) && (y>=clip_rect->top) && (y<=clip_rect->bottom) ) { ptr[0] = r; ptr[1] = g; ptr[2] = b; } x += incx; ptr += incx_ptr; frac_pos += ady*2; if ((frac_pos > 2*adx) || ((dy>0)&&(frac_pos == 2*adx))) { y += incy; ptr += incy_ptr; frac_pos -= 2*adx; } } } else { /* y-major */ if (dx>0) { incx = 1; incx_ptr = 3; } else { incx = -1; incx_ptr = -3; } if (dy>0) { incy = 1; incy_ptr = stride; } else { incy = -1; incy_ptr = -stride; } frac_pos = ady; for (i=0;i<=ady;i++) { /* Amazing... He does the clipping in the inner loop! It must be horribly inefficient! */ if ( (x>=clip_rect->left) && (x<=clip_rect->right) && (y>=clip_rect->top) && (y<=clip_rect->bottom) ) { ptr[0] = r; ptr[1] = g; ptr[2] = b; } y += incy; ptr += incy_ptr; frac_pos += adx*2; if ((frac_pos > 2*ady) || ((dx>0)&&(frac_pos == 2*ady))) { x += incx; ptr += incx_ptr; frac_pos -= 2*ady; } } } }