From 7718b3d642566921c47e23359ce17d33b570f617 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 28 Oct 2007 22:27:07 +0000 Subject: render stamp drawing is now done everywhere - (not just when saving images) separated stamp metadata and stamp draw functions. --- source/blender/imbuf/IMB_imbuf.h | 3 ++ source/blender/imbuf/intern/rectop.c | 67 +++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 27 deletions(-) (limited to 'source/blender/imbuf') diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 4d91a82a58f..dbbddd2a070 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -547,6 +547,9 @@ void IMB_freezbuffloatImBuf(struct ImBuf * ibuf); void IMB_rectfill(struct ImBuf *drect, float col[4]); void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2); +/* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */ +void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, float *col, int x1, int y1, int x2, int y2); + /* defined in imginfo.c */ int IMB_imginfo_change_field(struct ImBuf *img, const char *key, const char *field); 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); +} -- cgit v1.2.3