Revision: 17441
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17441
Author:   campbellbarton
Date:     2008-11-13 12:30:34 +0100 (Thu, 13 Nov 2008)

Log Message:
-----------
* use the existing function to only update a part of the image, should increase 
speed a lot, except when painting on seams from opposite parts of the image. - 
can speed this up with multiple boundboxes - TODO.
* use brush spacing and airbrush settings
* draw a circle while in texture paint mode.

Modified Paths:
--------------
    branches/projection-paint/source/blender/src/drawview.c
    branches/projection-paint/source/blender/src/imagepaint.c
    branches/projection-paint/source/blender/src/space.c

Modified: branches/projection-paint/source/blender/src/drawview.c
===================================================================
--- branches/projection-paint/source/blender/src/drawview.c     2008-11-13 
10:43:02 UTC (rev 17440)
+++ branches/projection-paint/source/blender/src/drawview.c     2008-11-13 
11:30:34 UTC (rev 17441)
@@ -3309,7 +3309,12 @@
                        fdrawXORcirc((float)c[0], (float)c[1], 
(float)pset->brush[pset->brushtype].size);
                }
        }
-
+       if(!G.obedit && OBACT && G.f&G_TEXTUREPAINT && 
area_is_active_area(v3d->area) && G.scene->toolsettings->imapaint.brush){
+               short c[2];
+               getmouseco_areawin(c);
+               fdrawXORcirc((float)c[0], (float)c[1], 
(float)G.scene->toolsettings->imapaint.brush->size/2);
+       }
+       
        if(v3d->persp>1) drawviewborder();
        if(v3d->flag2 & V3D_FLYMODE) drawviewborder_flymode();
        

Modified: branches/projection-paint/source/blender/src/imagepaint.c
===================================================================
--- branches/projection-paint/source/blender/src/imagepaint.c   2008-11-13 
10:43:02 UTC (rev 17440)
+++ branches/projection-paint/source/blender/src/imagepaint.c   2008-11-13 
11:30:34 UTC (rev 17441)
@@ -82,6 +82,8 @@
 #include "BIF_space.h"
 #include "BIF_toolbox.h"
 
+#include "BIF_editview.h" /* only for mouse_cursor - could remove this later */
+
 #include "BSE_drawipo.h"
 #include "BSE_node.h"
 #include "BSE_trans_types.h"
@@ -132,6 +134,10 @@
        float uv[2];
 } ImagePaintState;
 
+typedef struct ImagePaintPartialRedraw {
+       int x1, y1, x2, y2;
+       int enabled;
+} ImagePaintPartialRedraw;
 
 /* testing options */
 #define PROJ_BUCKET_DIV 128 /* TODO - test other values, this is a guess, 
seems ok */
@@ -194,6 +200,7 @@
        
        Image **projectImages;                  /* array of images we are 
painting onto while, use so we can tag for updates */
        ImBuf **projectImBufs;                  /* array of imbufs we are 
painting onto while, use so we can get the rect and rect_float quickly */
+       ImagePaintPartialRedraw *projectPartialRedraws; /* array of partial 
redraws */
        
        int projectImageTotal;                  /* size of projectImages array 
*/
        
@@ -235,8 +242,10 @@
 
 typedef struct ProjectPixel {
        float projCo2D[2]; /* the floating point screen projection of this 
pixel */
+       short x_px, y_px;
        void *pixel;
-       int image_index;
+       short image_index; /* if anyone wants to paint onto more then 32000 
images they can bite me */
+       short flag;
 } ProjectPixel;
 
 typedef struct ProjectPixelClone {
@@ -268,11 +277,6 @@
        ListBase tiles;
 } UndoElem;
 
-typedef struct ImagePaintPartialRedraw {
-       int x1, y1, x2, y2;
-       int enabled;
-} ImagePaintPartialRedraw;
-
 static ListBase undobase = {NULL, NULL};
 static UndoElem *curundo = NULL;
 static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0};
@@ -592,7 +596,7 @@
 {
        int i,j,n,m,x1,y1;
        unsigned char *dataI;
-       float a,b,w,wx,wy[4], outR,outG,outB,outA,*dataF,*outF;
+       float a,b,w,wx,wy[4], outR,outG,outB,outA,*dataF;
        int do_rect=0, do_float=0;
 
        if (in == NULL) return;
@@ -983,7 +987,6 @@
 static int uv_image_rect(float uv1[2], float uv2[2], float uv3[2], float 
uv4[2], int min_px[2], int max_px[2], int x_px, int y_px, int is_quad)
 {
        float min_uv[2], max_uv[2]; /* UV bounds */
-       int i;
        
        INIT_MINMAX2(min_uv, max_uv);
        
@@ -1251,7 +1254,7 @@
        return(Inp2f(u,h)/Inp2f(u,u));
 }
 
-static screen_px_from_ortho(
+static void screen_px_from_ortho(
                ProjectPaintState *ps, float uv[2],
                float v1co[3], float v2co[3], float v3co[3], /* Screenspace 
coords */
                float uv1co[2], float uv2co[2], float uv3co[2],
@@ -1264,7 +1267,7 @@
        pixelScreenCo[2] = v1co[2]*w[0] + v2co[2]*w[1] + v3co[2]*w[2];  
 }
 
-static screen_px_from_persp(
+static void screen_px_from_persp(
                ProjectPaintState *ps, float uv[2],
                float v1co[3], float v2co[3], float v3co[3], /* Worldspace 
coords */
                float uv1co[2], float uv2co[2], float uv3co[2],
@@ -1290,7 +1293,7 @@
 /* Only run this function once for new ProjectPixelClone's */
 #define pixel_size 4
 
-static void project_paint_uvpixel_init(ProjectPaintState *ps, int 
thread_index, ImBuf *ibuf, int x, int y, int bucket_index, int face_index, int 
image_index, float pixelScreenCo[4])
+static void project_paint_uvpixel_init(ProjectPaintState *ps, int 
thread_index, ImBuf *ibuf, short x, short y, int bucket_index, int face_index, 
int image_index, float pixelScreenCo[4])
 {
        ProjectPixel *projPixel;
        short size;
@@ -1327,6 +1330,8 @@
                }
                
                VECCOPY2D(projPixel->projCo2D, pixelScreenCo);
+               projPixel->x_px = x;
+               projPixel->y_px = y;
                
                /* done with view3d_project_float inline */
                if (ps->tool==PAINT_TOOL_CLONE) {
@@ -1561,17 +1566,17 @@
        int min_px[2], max_px[2]; /* UV Bounds converted to int's for pixel */
        int min_px_tf[2], max_px_tf[2]; /* UV Bounds converted to int's for 
pixel */
        int min_px_bucket[2], max_px_bucket[2]; /* Bucket Bounds converted to 
int's for pixel */
-       float *v1coSS, *v2coSS, *v3coSS, *v4coSS; /* vert co screen-space, 
these will be assigned to mf->v1,2,3 or mf->v1,3,4 */
-       float *v1co, *v2co, *v3co; /* vert co */
+       float *v1coSS, *v2coSS, *v3coSS; /* vert co screen-space, these will be 
assigned to mf->v1,2,3 or mf->v1,3,4 */
+       
        float *vCo[4]; /* vertex screenspace coords */
        
        float *uv1co, *uv2co, *uv3co; /* for convenience only, these will be 
assigned to tf->uv[0],1,2 or tf->uv[0],2,3 */
-       float pixelScreenCo[4], pixelScreenCoXMin[4], pixelScreenCoXMax[4];
-       int i, j;
+       float pixelScreenCo[4];
+       int i;
        
        /* vars for getting uvspace bounds */
        float bucket_bounds_uv[4][2]; /* bucket bounds in UV space so we can 
init pixels only for this face,  */
-       float w[3];
+       
        int i1,i2,i3;
        
        /* scanlines since quads can have 2 triangles intersecting the same 
vertical location */
@@ -1668,7 +1673,7 @@
                        /* Now create new UV's for the seam face */
                        float (*outset_uv)[2];
                        float insetCos[4][3]; /* inset face coords.  NOTE!!! 
ScreenSace for ortho, Worldspace in prespective view */
-                       float cent[3];
+
                        float *uv_seam_quad[4];
                        float fac;
                        float *vCoSS[4]; /* vertex screenspace coords */
@@ -1994,19 +1999,6 @@
 #endif
 }
 
-static int BLI_linklist_index(struct LinkNode *list, void *ptr)
-{
-       int index;
-       
-       for (index = 0; list; list= list->next, index++) {
-               if (list->link == ptr)
-                       return index;
-       }
-       
-       return -1;
-}
-
-
 static void project_paint_begin( ProjectPaintState *ps, short mval[2])
 {      
        /* Viewport vars */
@@ -2071,14 +2063,17 @@
                tot_faceSeamUVMem =                     sizeof(float) * 
ps->dm_totface * 8;
        }
 #endif
-
+       
+       /* BLI_memarena_new uses calloc */
        ps->projectArena =
                BLI_memarena_new(       tot_bucketMem +
                                                        tot_faceListMem +
                                                        tot_faceSeamFlagMem +
                                                        tot_faceSeamUVMem +
                                                        tot_bucketVertFacesMem 
+ (1<<18));
-       //BLI_memarena_use_calloc(ps->projectArena); ?
+       
+       BLI_memarena_use_calloc(ps->projectArena);
+       
        ps->projectBuckets = (LinkNode **)BLI_memarena_alloc( ps->projectArena, 
tot_bucketMem);
        ps->projectFaces= (LinkNode **)BLI_memarena_alloc( ps->projectArena, 
tot_faceListMem);
        
@@ -2091,17 +2086,17 @@
        }
 #endif
        
-       memset(ps->projectBuckets,              0, tot_bucketMem);
-       memset(ps->projectFaces,                0, tot_faceListMem);
-       memset(ps->projectBucketFlags,  0, tot_bucketFlagMem);
+       // calloced - memset(ps->projectBuckets,                0, 
tot_bucketMem);
+       // calloced -  memset(ps->projectFaces,         0, tot_faceListMem);
+       // calloced - memset(ps->projectBucketFlags,    0, tot_bucketFlagMem);
 #ifndef PROJ_DEBUG_NOSEAMBLEED
-       memset(ps->projectFaceSeamFlags,0, tot_faceSeamFlagMem);
+       // calloced - memset(ps->projectFaceSeamFlags,0, tot_faceSeamFlagMem);
        
-       if (ps->projectSeamBleed > 0.0) {
-               memset(ps->projectVertFaces,    0, tot_bucketVertFacesMem);
+       // calloced - if (ps->projectSeamBleed > 0.0) {
+               // calloced - memset(ps->projectVertFaces,      0, 
tot_bucketVertFacesMem);
                /* TODO dosnt need zeroing? */
-               memset(ps->projectFaceSeamUVs,  0, tot_faceSeamUVMem);
-       }
+               // calloced - memset(ps->projectFaceSeamUVs,    0, 
tot_faceSeamUVMem);
+       // calloced - }
 #endif
        
        /* Thread stuff */
@@ -2253,11 +2248,12 @@
        /* build an array of images we use*/
        ps->projectImages = BLI_memarena_alloc( ps->projectArena, sizeof(Image 
*) * ps->projectImageTotal);
        ps->projectImBufs = BLI_memarena_alloc( ps->projectArena, sizeof(ImBuf 
*) * ps->projectImageTotal);
+       ps->projectPartialRedraws = BLI_memarena_alloc( ps->projectArena, 
sizeof(ImagePaintPartialRedraw) * ps->projectImageTotal);
+       // calloced - memset(ps->projectPartialRedraws, 0, 
sizeof(ImagePaintPartialRedraw) * ps->projectImageTotal);
        
        for (node= image_LinkList, i=0; node; node= node->next, i++) {
                ps->projectImages[i] = node->link;
                ps->projectImages[i]->id.flag &= ~LIB_DOIT;
-               
                ps->projectImBufs[i] = BKE_image_get_ibuf(ps->projectImages[i], 
NULL);
        }
        /* we have built the array, discard the linked list */
@@ -2329,7 +2325,7 @@
 
 static void imapaint_dirty_region(Image *ima, ImBuf *ibuf, int x, int y, int 
w, int h)
 {
-       ImBuf *tmpibuf;
+       ImBuf *tmpibuf = NULL;
        UndoTile *tile;
        int srcx= 0, srcy= 0, origx, allocsize;
 
@@ -2356,9 +2352,6 @@
        h = ((y + h - 1) >> IMAPAINT_TILE_BITS);
        origx = (x >> IMAPAINT_TILE_BITS);
        y = (y >> IMAPAINT_TILE_BITS);
-
-       tmpibuf= IMB_allocImBuf(IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE, 32,
-                               IB_rectfloat|IB_rect, 0);
        
        for (; y <= h; y++) {
                for (x=origx; x <= w; x++) {
@@ -2367,6 +2360,9 @@
                                        break;
 
                        if(!tile) {
+                               if (tmpibuf==NULL)
+                                       tmpibuf = 
IMB_allocImBuf(IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE, 32, 
IB_rectfloat|IB_rect, 0);
+                               
                                tile= MEM_callocN(sizeof(UndoTile), 
"ImaUndoTile");
                                tile->id= ima->id;
                                tile->x= x;
@@ -2385,14 +2381,15 @@
        }
 
        ibuf->userflags |= IB_BITMAPDIRTY;
-
-       IMB_freeImBuf(tmpibuf);
+       
+       if (tmpibuf)
+               IMB_freeImBuf(tmpibuf);
 }
 
 static void imapaint_image_update(Image *image, ImBuf *ibuf, short texpaint)
 {
        if(ibuf->rect_float)
-               imb_freerectImBuf(ibuf); /* force recreate of char rect */
+               imb_freerectImBuf(ibuf); /* force recreate of char rect */ /* 
TODO - should just update a portion from imapaintpartial! */
        if(ibuf->mipmap[0])
                imb_freemipmapImBuf(ibuf);
 
@@ -2778,15 +2775,56 @@
        return 0;
 }
 
+static void partial_redraw_array_init(ImagePaintPartialRedraw *pr, int tot)
+{
+       while (tot--) {
+               pr->x1 = 10000000;
+               pr->y1 = 10000000;
+               
+               pr->x2 = -1;
+               pr->y2 = -1;
+               
+               pr->enabled = 1;
+               
+               pr++;
+       }
+}
+
+static void partial_redraw_array_merge(ImagePaintPartialRedraw *pr, 
ImagePaintPartialRedraw *pr_other, int tot)
+{
+       while (tot--) {
+               pr->x1 = MIN2(pr->x1, pr_other->x1);
+               pr->y1 = MIN2(pr->y1, pr_other->y1);
+               

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to