render stamp drawing is now done everywhere - (not just when saving
authorCampbell Barton <ideasman42@gmail.com>
Sun, 28 Oct 2007 22:27:07 +0000 (22:27 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 28 Oct 2007 22:27:07 +0000 (22:27 +0000)
images)
separated stamp metadata and stamp draw functions.

intern/bmfont/intern/BMF_BitmapFont.cpp
source/blender/blenkernel/BKE_image.h
source/blender/blenkernel/intern/image.c
source/blender/blenpluginapi/iff.h
source/blender/imbuf/IMB_imbuf.h
source/blender/imbuf/intern/rectop.c
source/blender/render/intern/source/pipeline.c

index c47b2b0719562b820da8ea488534e55e65dcd2d5..2ea14b4b203f2377c9e765d0c6a5491984d2cafa 100644 (file)
@@ -268,7 +268,7 @@ void BMF_BitmapFont::DrawStringBuf(char *str, int posx, int posy, float *col, un
                                for (y = 0; y < cd.height; y++) {
                                        unsigned char* chrRow = &m_fontData->bitmap_data[cd.data_offset + ((cd.width+7)/8)*y];
                                        for (x = cd.xorig; x < cd.width; x++) {
-                                               pixel = buf + 4 * (((posy + y) * w) + (posx + x));
+                                               pixel = buf + 4 * (((posy + y - cd.yorig) * w) + (posx + x));
                                                if ((pixel < max) && (pixel > buf)) {
                                                        int byteIdx = x/8;
                                                        int bitIdx = 7 - (x%8);
index 204e956dbc8bedab5965b50089996ad5b6f27cc0..b308342ac1e492e7647c22f2dc9039185e5d5250 100644 (file)
@@ -46,7 +46,8 @@ struct anim;
 /* call from library */
 void   free_image(struct Image *me);
 
-void   BKE_stamp(struct ImBuf *ibuf);
+void   BKE_stamp_info(struct ImBuf *ibuf);
+void   BKE_stamp_buf(unsigned char *rect, float *rectf, int width, int height);
 int            BKE_write_ibuf(struct ImBuf *ibuf, char *name, int imtype, int subimtype, int quality);
 void   BKE_makepicstring(char *string, char *base, int frame, int imtype);
 void   BKE_add_image_extension(char *string, int imtype);
index ea086481bac43780a70de9e225ad87fdbfe5d77a..bdf081496e5e747565fe191502117615bbac1099 100644 (file)
@@ -777,15 +777,21 @@ void BKE_add_image_extension(char *string, int imtype)
        strcat(string, extension);
 }
 
-void BKE_stamp(struct ImBuf *ibuf)
+/* could allow access externally */
+typedef struct StampData {
+       char    file[512];
+       char    note[512];
+       char    date[512];
+       char    marker[512];
+       char    time[512];
+       char    frame[512];
+       char    camera[512];
+       char    scene[512];
+} StampData;
+
+static void stampdata(StampData *stamp_data, int do_prefix)
 {
-       char text[256], infotext[256];
-       int x=0, y=0, h, m, s, f;
-       int font_height;
-       int text_width;
-       int text_pad;
-       struct BMF_Font *font;
-       
+       char text[256];
        
 #ifndef WIN32
        struct tm *tl;
@@ -793,101 +799,46 @@ void BKE_stamp(struct ImBuf *ibuf)
 #else
        char sdate[9];
 #endif /* WIN32 */
-
-       if (!ibuf)
-               return;
-       
-       switch (G.scene->r.stamp_font_id) {
-       case 1: /* tiny */
-               font = BMF_GetFont(BMF_kHelveticaBold8);
-               break;
-       case 2: /* small */
-               font = BMF_GetFont(BMF_kHelveticaBold10);
-               break;
-       case 3: /* medium */
-               font = BMF_GetFont(BMF_kScreen12);
-               break;
-       case 0: /* large - default */
-               font = BMF_GetFont(BMF_kScreen15);
-               break;
-       case 4: /* huge */
-               font = BMF_GetFont(BMF_kHelveticaBold14);
-               break;
-       default:
-               font = NULL;
-               break;
-       }
        
-       font_height = BMF_GetFontHeight(font);
-       /* All texts get halfspace+1 pixel on each side and 1 pix
-          above and below as padding against their backing rectangles */
-       text_pad = BMF_GetStringWidth(font, " ");
+       if (do_prefix)          sprintf(stamp_data->file, "File %s", G.sce);
+       else                            sprintf(stamp_data->file, "%s", G.sce);
        
-       IMB_imginfo_change_field (ibuf, "File", G.sce);
-       if (G.scene->r.stamp & R_STAMP_DRAW) {
-               /* Top left corner */
-               x = 1; /* Inits for everyone, text position, so 1 for padding, not 0 */
-               y = ibuf->y - font_height - 1; /* Also inits for everyone, notice padding pixel */
-               sprintf(text, "File %s", G.sce);
-               text_width = BMF_GetStringWidth(font, text);
-               IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-               BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               y -= font_height+2; /* Top and bottom 1 pix padding each */
-       }
-
        if (G.scene->r.stamp & R_STAMP_NOTE) {
-               IMB_imginfo_change_field (ibuf, "Note", G.scene->r.stamp_udata);
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       /* Top left corner, below File */
-                       text_width = BMF_GetStringWidth(font, G.scene->r.stamp_udata);
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, G.scene->r.stamp_udata, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-                       y -= font_height+2; /* Top and bottom 1 pix padding each */
-               }
+               if (do_prefix)          sprintf(stamp_data->note, "Note %s", G.scene->r.stamp_udata);
+               else                            sprintf(stamp_data->note, "%s", G.scene->r.stamp_udata);
+       } else {
+               stamp_data->note[0] = '\0';
        }
        
        if (G.scene->r.stamp & R_STAMP_DATE) {
 #ifdef WIN32
                _strdate (sdate);
-               sprintf (infotext, "%s", sdate);
+               sprintf (text, "%s", sdate);
 #else
                t = time (NULL);
                tl = localtime (&t);
-               sprintf (infotext, "%04d-%02d-%02d", tl->tm_year+1900, tl->tm_mon+1, tl->tm_mday);
+               sprintf (text, "%04d-%02d-%02d", tl->tm_year+1900, tl->tm_mon+1, tl->tm_mday);
 #endif /* WIN32 */
-               IMB_imginfo_change_field (ibuf, "Date", infotext);
-
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       /* Top left corner, below File (or Note) */
-                       sprintf (text, "Date %s", infotext);
-                       text_width = BMF_GetStringWidth(font, text);
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               }
+               if (do_prefix)          sprintf(stamp_data->date, "Date %s", text);
+               else                            sprintf(stamp_data->date, "%s", text);
+       } else {
+               stamp_data->date[0] = '\0';
        }
-
-
+       
        if (G.scene->r.stamp & R_STAMP_MARKER) {
                TimeMarker *marker = get_frame_marker(CFRA);
-               
-               if (marker) strcpy(infotext, marker->name);
-               else            strcpy(infotext, "<none>");
-               
-               IMB_imginfo_change_field (ibuf, "Marker", infotext);
+       
+               if (marker) strcpy(text, marker->name);
+               else            strcpy(text, "<none>");
                
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       /* Bottom left corner, leaving space for timing */
-                       x = 1;
-                       y = font_height+2+1; /* 2 for padding in TIME|FRAME fields below and 1 for padding in this one */
-                       sprintf (text, "Marker %s", infotext);
-                       text_width = BMF_GetStringWidth(font, text);
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               }
+               if (do_prefix)          sprintf(stamp_data->marker, "Marker %s", text);
+               else                            sprintf(stamp_data->marker, "%s", text);
+       } else {
+               stamp_data->marker[0] = '\0';
        }
-
+       
        if (G.scene->r.stamp & R_STAMP_TIME) {
+               int h, m, s, f;
                h= m= s= f= 0;
                f = (int)(G.scene->r.cfra % G.scene->r.frs_sec);
                s = (int)(G.scene->r.cfra / G.scene->r.frs_sec);
@@ -903,77 +854,174 @@ void BKE_stamp(struct ImBuf *ibuf)
                }
 
                if (G.scene->r.frs_sec < 100)
-                       sprintf (infotext, "%02d:%02d:%02d.%02d", h, m, s, f);
+                       sprintf (text, "%02d:%02d:%02d.%02d", h, m, s, f);
                else
-                       sprintf (infotext, "%02d:%02d:%02d.%03d", h, m, s, f);
+                       sprintf (text, "%02d:%02d:%02d.%03d", h, m, s, f);
                
-               IMB_imginfo_change_field (ibuf, "Time", infotext);
-               
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       /* Left bottom corner */
-                       x = 1;
-                       y = 1;
-                       sprintf (text, "Time %s", infotext);
-                       text_width = BMF_GetStringWidth(font, text);
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-                       x += text_width+text_pad+2; /* Both sides have 1 pix additional padding each */
-               }
+               if (do_prefix)          sprintf(stamp_data->time, "Time %s", text);
+               else                            sprintf(stamp_data->time, "%s", text);
+       } else {
+               stamp_data->time[0] = '\0';
        }
-
+       
        if (G.scene->r.stamp & R_STAMP_FRAME) {
-               sprintf (infotext, "%i", G.scene->r.cfra);
-               IMB_imginfo_change_field (ibuf, "Frame", infotext);
-
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       char format[32];
-
-                       /* First build "Frame %03i" for anims ending in frame 100-999, etc */
-                       sprintf(format, "Frame %%0%di\n", 1 + (int) log10(G.scene->r.efra));
-                       sprintf (text, format, G.scene->r.cfra);
-                       text_width = BMF_GetStringWidth(font, text);
-                       /* Left bottom corner (after SMPTE if exists) */
-                       if (!(G.scene->r.stamp & R_STAMP_TIME)) {
-                               x = 1;
-                       }
-                       y = 1;
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               }
+               char format[32];
+               if (do_prefix)          sprintf(format, "Frame %%0%di\n", 1 + (int) log10(G.scene->r.efra));
+               else                            sprintf(format, "%%0%di\n", 1 + (int) log10(G.scene->r.efra));
+               sprintf (stamp_data->frame, format, G.scene->r.cfra);
+       } else {
+               stamp_data->frame[0] = '\0';
        }
 
-
        if (G.scene->r.stamp & R_STAMP_CAMERA) {
-               sprintf(infotext, ((Camera *) G.scene->camera)->id.name+2);
-               IMB_imginfo_change_field (ibuf, "Camera", infotext);
-
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       sprintf (text, "Camera %s", infotext);
-                       text_width = BMF_GetStringWidth(font, text);
-                       /* Center of bottom edge */
-                       x = (ibuf->x/2) - (BMF_GetStringWidth(font, text)/2);
-                       y = 1;
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               }
+               if (do_prefix)          sprintf(stamp_data->camera, "Camera %s", ((Camera *) G.scene->camera)->id.name+2);
+               else                            sprintf(stamp_data->camera, "%s", ((Camera *) G.scene->camera)->id.name+2);
+       } else {
+               stamp_data->camera[0] = '\0';
        }
 
        if (G.scene->r.stamp & R_STAMP_SCENE) {
-               strcpy(infotext, G.scene->id.name+2);
-               IMB_imginfo_change_field (ibuf, "Scene", infotext);
-
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       sprintf (text, "Scene %s", infotext);
-                       text_width = BMF_GetStringWidth(font, text);
-                       /* Bottom right corner */
-                       x = ibuf->x - (BMF_GetStringWidth(font, text)+1+text_pad);
-                       y = 1;
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               }
+               if (do_prefix)          sprintf(stamp_data->scene, "Camera %s", G.scene->id.name+2);
+               else                            sprintf(stamp_data->scene, "%s", G.scene->id.name+2);
+       } else {
+               stamp_data->scene[0] = '\0';
+       }
+}
+
+void BKE_stamp_buf(unsigned char *rect, float *rectf, int width, int height)
+{
+       struct StampData stamp_data;
+       
+       int x,y;
+       int font_height;
+       int text_width;
+       int text_pad;
+       struct BMF_Font *font;
+       
+       if (!rect && !rectf)
+               return;
+       
+       stampdata(&stamp_data, 1);
+       
+       switch (G.scene->r.stamp_font_id) {
+       case 1: /* tiny */
+               font = BMF_GetFont(BMF_kHelveticaBold8);
+               break;
+       case 2: /* small */
+               font = BMF_GetFont(BMF_kHelveticaBold10);
+               break;
+       case 3: /* medium */
+               font = BMF_GetFont(BMF_kScreen12);
+               break;
+       case 0: /* large - default */
+               font = BMF_GetFont(BMF_kScreen15);
+               break;
+       case 4: /* huge */
+               font = BMF_GetFont(BMF_kHelveticaBold14);
+               break;
+       default:
+               font = NULL;
+               break;
+       }
+       
+       font_height = BMF_GetFontHeight(font);
+       /* All texts get halfspace+1 pixel on each side and 1 pix
+       above and below as padding against their backing rectangles */
+       text_pad = BMF_GetStringWidth(font, " ");
+       
+
+       if (stamp_data.file[0]) {
+               /* Top left corner */
+               x = 1; /* Inits for everyone, text position, so 1 for padding, not 0 */
+               y = height - font_height - 1; /* Also inits for everyone, notice padding pixel */
+               text_width = BMF_GetStringWidth(font, stamp_data.file);
+               buf_rectfill_area(rect, rectf, width, height, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+               BMF_DrawStringBuf(font, stamp_data.file, x+(text_pad/2), y, G.scene->r.fg_stamp, rect, rectf, width, height);
+               y -= font_height+2; /* Top and bottom 1 pix padding each */
+       }
+
+       /* Top left corner, below File */
+       if (stamp_data.note[0]) {
+               text_width = BMF_GetStringWidth(font, stamp_data.note);
+               buf_rectfill_area(rect, rectf, width, height, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+               BMF_DrawStringBuf(font, stamp_data.note, x+(text_pad/2), y, G.scene->r.fg_stamp, rect, rectf, width, height);
+               y -= font_height+2; /* Top and bottom 1 pix padding each */
+       }
+       
+       /* Top left corner, below File (or Note) */
+       if (stamp_data.date[0]) {
+               text_width = BMF_GetStringWidth(font, stamp_data.date);
+               buf_rectfill_area(rect, rectf, width, height, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+               BMF_DrawStringBuf(font, stamp_data.date, x+(text_pad/2), y, G.scene->r.fg_stamp, rect, rectf, width, height);
+       }
+
+       /* Bottom left corner, leaving space for timing */
+       if (stamp_data.marker[0]) {
+               x = 1;
+               y = font_height+2+1; /* 2 for padding in TIME|FRAME fields below and 1 for padding in this one */
+               text_width = BMF_GetStringWidth(font, stamp_data.marker);
+               buf_rectfill_area(rect, rectf, width, height, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+               BMF_DrawStringBuf(font, stamp_data.marker, x+(text_pad/2), y, G.scene->r.fg_stamp, rect, rectf, width, height);
+       }
+       
+       /* Left bottom corner */
+       if (stamp_data.time[0]) {
+               x = 1;
+               y = 1;
+               text_width = BMF_GetStringWidth(font, stamp_data.time);
+               buf_rectfill_area(rect, rectf, width, height, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+               BMF_DrawStringBuf(font, stamp_data.time, x+(text_pad/2), y, G.scene->r.fg_stamp, rect, rectf, width, height);
+               x += text_width+text_pad+2; /* Both sides have 1 pix additional padding each */
+       }
+       
+       if (stamp_data.frame[0]) {
+               text_width = BMF_GetStringWidth(font, stamp_data.frame);
+               /* Left bottom corner (after SMPTE if exists) */
+               if (!stamp_data.time[0])        x = 1;
+               y = 1;
+               buf_rectfill_area(rect, rectf, width, height, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+               BMF_DrawStringBuf(font, stamp_data.frame, x+(text_pad/2), y, G.scene->r.fg_stamp, rect, rectf, width, height);
+       }
+
+       if (stamp_data.camera[0]) {
+               text_width = BMF_GetStringWidth(font, stamp_data.camera);
+               /* Center of bottom edge */
+               x = (width/2) - (BMF_GetStringWidth(font, stamp_data.camera)/2);
+               y = 1;
+               buf_rectfill_area(rect, rectf, width, height, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+               BMF_DrawStringBuf(font, stamp_data.camera, x+(text_pad/2), y, G.scene->r.fg_stamp, rect, rectf, width, height);
+       }
+       
+       if (stamp_data.scene[0]) {
+               text_width = BMF_GetStringWidth(font, stamp_data.scene);
+               /* Bottom right corner */
+               x = width - (text_width+1+text_pad);
+               y = 1;
+               buf_rectfill_area(rect, rectf, width, height, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+               BMF_DrawStringBuf(font, stamp_data.scene, x+(text_pad/2), y, G.scene->r.fg_stamp, rect, rectf, width, height);
        }
 }
 
+
+void BKE_stamp_info(struct ImBuf *ibuf)
+{
+       struct StampData stamp_data;
+
+       if (!ibuf)      return;
+       
+       /* fill all the data values, no prefix */
+       stampdata(&stamp_data, 0);
+       
+       if (stamp_data.file[0])         IMB_imginfo_change_field (ibuf, "File",         stamp_data.file);
+       if (stamp_data.note[0])         IMB_imginfo_change_field (ibuf, "Note",         stamp_data.note);
+       if (stamp_data.date[0])         IMB_imginfo_change_field (ibuf, "Date",         stamp_data.date);
+       if (stamp_data.marker[0])       IMB_imginfo_change_field (ibuf, "Marker",       stamp_data.marker);
+       if (stamp_data.time[0])         IMB_imginfo_change_field (ibuf, "Time",         stamp_data.time);
+       if (stamp_data.frame[0])        IMB_imginfo_change_field (ibuf, "Frame",        stamp_data.frame);
+       if (stamp_data.camera[0])       IMB_imginfo_change_field (ibuf, "Camera",       stamp_data.camera);
+       if (stamp_data.scene[0])        IMB_imginfo_change_field (ibuf, "Scene",        stamp_data.scene);
+}
+
 int BKE_write_ibuf(ImBuf *ibuf, char *name, int imtype, int subimtype, int quality)
 {
        int ok;
@@ -1035,8 +1083,8 @@ int BKE_write_ibuf(ImBuf *ibuf, char *name, int imtype, int subimtype, int quali
        BLI_make_existing_file(name);
 
        if(G.scene->r.scemode & R_STAMP_INFO)
-               BKE_stamp(ibuf);
-
+               BKE_stamp_info(ibuf);
+       
        ok = IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat);
        if (ok == 0) {
                perror(name);
index f63f753e5539f6907a523001d2455ed11636ed51..5eb52158a1a71df323bed19ed5b5eb63b165e612 100644 (file)
@@ -209,6 +209,7 @@ LIBEXPORT void IMB_rectcpy(struct ImBuf *dbuf, struct ImBuf *sbuf,
 
 LIBEXPORT void IMB_rectfill(struct ImBuf *drect, float col[4]);
 LIBEXPORT void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2);
+LIBEXPORT void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, float *col, int x1, int y1, int x2, int y2);
 
 #endif /* IFF_H */
 
index 4d91a82a58f8c45b3d0adaabd9ac0aa419da018b..dbbddd2a070d2b35cbb5f73524a08a0d53aef36e 100644 (file)
@@ -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);
 
index 591ab066c57f1297aec36e4770574dc57d112f44..fde0b2b3623be7709781f8c897423480336c8f05 100644 (file)
@@ -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);
+}
index db077c8a1b1e57b98f4a524e284c700412dd9036..c368840c264612dc15454cd95a7e4aaa7be4bb3a 100644 (file)
@@ -1998,8 +1998,17 @@ static void yafrayRender(Render *re)
        RE_Database_Free(re);
 }
 
+
+
 #endif /* disable yafray */
 
+static void renderresult_stampinfo()
+{
+       RenderResult rres;
+       /* this is the basic trick to get the displayed float or char rect from render result */
+       RE_GetResultImage(RE_GetRender(G.scene->id.name), &rres);
+       BKE_stamp_buf((unsigned char *)rres.rect32, rres.rectf, rres.rectx, rres.recty);
+}
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 
@@ -2035,6 +2044,11 @@ static void do_render_all_options(Render *re)
        renderresult_add_names(re->result);
        
        re->i.lastframetime= PIL_check_seconds_timer()- re->i.starttime;
+       
+       /* stamp image info here */
+       if(G.scene->r.scemode & R_STAMP_INFO && G.scene->r.stamp & R_STAMP_DRAW)
+               renderresult_stampinfo();
+       
        re->stats_draw(&re->i);
 }