diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-10-29 01:27:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-10-29 01:27:07 +0300 |
commit | 7718b3d642566921c47e23359ce17d33b570f617 (patch) | |
tree | f9c427c610b24a1adba86b05398c8f484f0d65e5 /source/blender/imbuf/intern/rectop.c | |
parent | 47da2813d81b948e9e175e7c01ebaa794db395e1 (diff) |
render stamp drawing is now done everywhere - (not just when saving
images)
separated stamp metadata and stamp draw functions.
Diffstat (limited to 'source/blender/imbuf/intern/rectop.c')
-rw-r--r-- | source/blender/imbuf/intern/rectop.c | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index 591ab066c57..fde0b2b3623 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -521,18 +521,19 @@ void IMB_rectfill(struct ImBuf *drect, float col[4]) #define FTOCHAR(val) (val<=0.0f ? 0: (val>=1.0f ? 255: (char)(255.99f*val))) #define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c) #define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } -void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2) + +void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, float *col, int x1, int y1, int x2, int y2) { int i, j; float a, ai; - if ((!ibuf) || (!col)) + if ((!rect && !rectf) || (!col) || col[3]==0.0) return; /* sanity checks for coords */ - CLAMP(x1, 0, ibuf->x); - CLAMP(x2, 0, ibuf->x); - CLAMP(y1, 0, ibuf->y); - CLAMP(y2, 0, ibuf->y); + CLAMP(x1, 0, width); + CLAMP(x2, 0, width); + CLAMP(y1, 0, height); + CLAMP(y2, 0, height); if (x1>x2) SWAP(int,x1,x2); if (y1>y2) SWAP(int,y1,y2); @@ -541,38 +542,44 @@ void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, i a = col[3]; ai = 1-a; - if (ibuf->rect) { - unsigned char *img, *pixel; + + if (rect) { + unsigned char *pixel; unsigned char chr, chg, chb; - - chr = FTOCHAR(col[0]); - chg = FTOCHAR(col[1]); - chb = FTOCHAR(col[2]); + float fr, fg, fb; - img = (unsigned char *) ibuf->rect; + if (a == 1.0) { + chr = FTOCHAR(col[0]); + chg = FTOCHAR(col[1]); + chb = FTOCHAR(col[2]); + } else { + fr = col[0]*a; + fg = col[1]*a; + fb = col[2]*a; + } for (j = 0; j < y2-y1; j++) { for (i = 0; i < x2-x1; i++) { - pixel = img + 4 * (((y1 + j) * ibuf->x) + (x1 + i)); - if (a == 1.0) { - pixel[0] = chr; - pixel[1] = chg; - pixel[2] = chb; - } else { - pixel[0] = (char)((chr*a) + (pixel[0]*ai)); - pixel[1] = (char)((chg*a) + (pixel[1]*ai)); - pixel[2] = (char)((chb*a) + (pixel[2]*ai)); + pixel = rect + 4 * (((y1 + j) * width) + (x1 + i)); + if (pixel >= rect && pixel < rect+ (4 * (width * height))) { + if (a == 1.0) { + pixel[0] = chr; + pixel[1] = chg; + pixel[2] = chb; + } else { + pixel[0] = (char)(fr + ((float)pixel[0]*ai)); + pixel[1] = (char)(fg + ((float)pixel[1]*ai)); + pixel[2] = (char)(fb + ((float)pixel[2]*ai)); + } } - } } } - if (ibuf->rect_float) { - float *img, *pixel; - img = ibuf->rect_float; + if (rectf) { + float *pixel; for (j = 0; j < y2-y1; j++) { for (i = 0; i < x2-x1; i++) { - pixel = img + 4 * (((y1 + j) * ibuf->x) + (x1 + i)); + pixel = rectf + 4 * (((y1 + j) * width) + (x1 + i)); if (a == 1.0) { pixel[0] = col[0]; pixel[1] = col[1]; @@ -586,3 +593,9 @@ void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, i } } } + +void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2) +{ + if (!ibuf) return; + buf_rectfill_area((unsigned char *) ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, col, x1, y1, x2, y2); +} |