diff options
Diffstat (limited to 'source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc')
-rw-r--r-- | source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc | 208 |
1 files changed, 93 insertions, 115 deletions
diff --git a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc index fed11d59b50..863171f105e 100644 --- a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc +++ b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc @@ -8,18 +8,13 @@ namespace blender::compositor { /* This part has been copied from the double edge mask. */ -static void do_adjacentKeepBorders(unsigned int t, - unsigned int rw, - const unsigned int *limask, - const unsigned int *lomask, - unsigned int *lres, - float *res, - unsigned int *rsize) +static void do_adjacentKeepBorders( + uint t, uint rw, const uint *limask, const uint *lomask, uint *lres, float *res, uint *rsize) { int x; - unsigned int isz = 0; /* Inner edge size. */ - unsigned int osz = 0; /* Outer edge size. */ - unsigned int gsz = 0; /* Gradient fill area size. */ + uint isz = 0; /* Inner edge size. */ + uint osz = 0; /* Outer edge size. */ + uint gsz = 0; /* Gradient fill area size. */ /* Test the four corners */ /* Upper left corner. */ x = t - rw + 1; @@ -178,18 +173,13 @@ static void do_adjacentKeepBorders(unsigned int t, rsize[2] = gsz; } -static void do_adjacentBleedBorders(unsigned int t, - unsigned int rw, - const unsigned int *limask, - const unsigned int *lomask, - unsigned int *lres, - float *res, - unsigned int *rsize) +static void do_adjacentBleedBorders( + uint t, uint rw, const uint *limask, const uint *lomask, uint *lres, float *res, uint *rsize) { int x; - unsigned int isz = 0; /* Inner edge size. */ - unsigned int osz = 0; /* Outer edge size. */ - unsigned int gsz = 0; /* Gradient fill area size. */ + uint isz = 0; /* Inner edge size. */ + uint osz = 0; /* Outer edge size. */ + uint gsz = 0; /* Gradient fill area size. */ /* Test the four corners */ /* Upper left corner. */ x = t - rw + 1; @@ -403,18 +393,13 @@ static void do_adjacentBleedBorders(unsigned int t, rsize[2] = gsz; } -static void do_allKeepBorders(unsigned int t, - unsigned int rw, - const unsigned int *limask, - const unsigned int *lomask, - unsigned int *lres, - float *res, - unsigned int *rsize) +static void do_allKeepBorders( + uint t, uint rw, const uint *limask, const uint *lomask, uint *lres, float *res, uint *rsize) { int x; - unsigned int isz = 0; /* Inner edge size. */ - unsigned int osz = 0; /* Outer edge size. */ - unsigned int gsz = 0; /* Gradient fill area size. */ + uint isz = 0; /* Inner edge size. */ + uint osz = 0; /* Outer edge size. */ + uint gsz = 0; /* Gradient fill area size. */ /* Test the four corners. */ /* Upper left corner. */ x = t - rw + 1; @@ -565,18 +550,13 @@ static void do_allKeepBorders(unsigned int t, rsize[2] = gsz; } -static void do_allBleedBorders(unsigned int t, - unsigned int rw, - const unsigned int *limask, - const unsigned int *lomask, - unsigned int *lres, - float *res, - unsigned int *rsize) +static void do_allBleedBorders( + uint t, uint rw, const uint *limask, const uint *lomask, uint *lres, float *res, uint *rsize) { int x; - unsigned int isz = 0; /* Inner edge size. */ - unsigned int osz = 0; /* Outer edge size. */ - unsigned int gsz = 0; /* Gradient fill area size. */ + uint isz = 0; /* Inner edge size. */ + uint osz = 0; /* Outer edge size. */ + uint gsz = 0; /* Gradient fill area size. */ /* Test the four corners */ /* Upper left corner. */ x = t - rw + 1; @@ -782,16 +762,16 @@ static void do_allBleedBorders(unsigned int t, rsize[2] = gsz; } -static void do_allEdgeDetection(unsigned int t, - unsigned int rw, - const unsigned int *limask, - const unsigned int *lomask, - unsigned int *lres, +static void do_allEdgeDetection(uint t, + uint rw, + const uint *limask, + const uint *lomask, + uint *lres, float *res, - unsigned int *rsize, - unsigned int in_isz, - unsigned int in_osz, - unsigned int in_gsz) + uint *rsize, + uint in_isz, + uint in_osz, + uint in_gsz) { int x; /* Pixel loop counter. */ int a; /* Pixel loop counter. */ @@ -853,16 +833,16 @@ static void do_allEdgeDetection(unsigned int t, rsize[2] = in_gsz; } -static void do_adjacentEdgeDetection(unsigned int t, - unsigned int rw, - const unsigned int *limask, - const unsigned int *lomask, - unsigned int *lres, +static void do_adjacentEdgeDetection(uint t, + uint rw, + const uint *limask, + const uint *lomask, + uint *lres, float *res, - unsigned int *rsize, - unsigned int in_isz, - unsigned int in_osz, - unsigned int in_gsz) + uint *rsize, + uint in_isz, + uint in_osz, + uint in_gsz) { int x; /* Pixel loop counter. */ int a; /* Pixel loop counter. */ @@ -925,30 +905,30 @@ static void do_adjacentEdgeDetection(unsigned int t, rsize[2] = in_gsz; } -static void do_createEdgeLocationBuffer(unsigned int t, - unsigned int rw, - const unsigned int *lres, +static void do_createEdgeLocationBuffer(uint t, + uint rw, + const uint *lres, float *res, - unsigned short *gbuf, - unsigned int *inner_edge_offset, - unsigned int *outer_edge_offset, - unsigned int isz, - unsigned int gsz) + ushort *gbuf, + uint *inner_edge_offset, + uint *outer_edge_offset, + uint isz, + uint gsz) { - int x; /* Pixel loop counter. */ - int a; /* Temporary pixel index buffer loop counter. */ - unsigned int ud; /* Unscaled edge distance. */ - unsigned int dmin; /* Minimum edge distance. */ + int x; /* Pixel loop counter. */ + int a; /* Temporary pixel index buffer loop counter. */ + uint ud; /* Unscaled edge distance. */ + uint dmin; /* Minimum edge distance. */ - unsigned int rsl; /* Long used for finding fast `1.0/sqrt`. */ - unsigned int gradient_fill_offset; + uint rsl; /* Long used for finding fast `1.0/sqrt`. */ + uint gradient_fill_offset; /* For looping inner edge pixel indexes, represents current position from offset. */ - unsigned int inner_accum = 0; + uint inner_accum = 0; /* For looping outer edge pixel indexes, represents current position from offset. */ - unsigned int outer_accum = 0; + uint outer_accum = 0; /* For looping gradient pixel indexes, represents current position from offset. */ - unsigned int gradient_accum = 0; + uint gradient_accum = 0; /* Disable clang-format to prevent line-wrapping. */ /* clang-format off */ @@ -958,12 +938,12 @@ static void do_createEdgeLocationBuffer(unsigned int t, * or outer edge. * * Allocation is done by requesting 4 bytes "sizeof(int)" per pixel, even - * though gbuf[] is declared as (unsigned short *) (2 bytes) because we don't + * though gbuf[] is declared as `(ushort *)` (2 bytes) because we don't * store the pixel indexes, we only store x,y location of pixel in buffer. * * This does make the assumption that x and y can fit in 16 unsigned bits * so if Blender starts doing renders greater than 65536 in either direction - * this will need to allocate gbuf[] as unsigned int *and allocate 8 bytes + * this will need to allocate gbuf[] as uint *and allocate 8 bytes * per flagged pixel. * * In general, the buffer on-screen: @@ -1028,20 +1008,20 @@ static void do_createEdgeLocationBuffer(unsigned int t, for (rsl = 0; rsl < rw; rsl++) { a = x + rsl; if (lres[a] == 2) { /* It is a gradient pixel flagged by 2. */ - ud = gradient_accum << 1; /* Double the index to reach correct unsigned short location. */ + ud = gradient_accum << 1; /* Double the index to reach correct ushort location. */ gbuf[ud] = dmin; /* Insert pixel's row into gradient pixel location buffer. */ gbuf[ud + 1] = rsl; /* Insert pixel's column into gradient pixel location buffer. */ gradient_accum++; /* Increment gradient index buffer pointer. */ } else if (lres[a] == 3) { /* It is an outer edge pixel flagged by 3. */ - ud = outer_accum << 1; /* Double the index to reach correct unsigned short location. */ + ud = outer_accum << 1; /* Double the index to reach correct ushort location. */ gbuf[ud] = dmin; /* Insert pixel's row into outer edge pixel location buffer. */ gbuf[ud + 1] = rsl; /* Insert pixel's column into outer edge pixel location buffer. */ outer_accum++; /* Increment outer edge index buffer pointer. */ res[a] = 0.0f; /* Set output pixel intensity now since it won't change later. */ } else if (lres[a] == 4) { /* It is an inner edge pixel flagged by 4. */ - ud = inner_accum << 1; /* Double int index to reach correct unsigned short location. */ + ud = inner_accum << 1; /* Double int index to reach correct ushort location. */ gbuf[ud] = dmin; /* Insert pixel's row into inner edge pixel location buffer. */ gbuf[ud + 1] = rsl; /* Insert pixel's column into inner edge pixel location buffer. */ inner_accum++; /* Increment inner edge index buffer pointer. */ @@ -1051,30 +1031,30 @@ static void do_createEdgeLocationBuffer(unsigned int t, } } -static void do_fillGradientBuffer(unsigned int rw, +static void do_fillGradientBuffer(uint rw, float *res, - const unsigned short *gbuf, - unsigned int isz, - unsigned int osz, - unsigned int gsz, - unsigned int inner_edge_offset, - unsigned int outer_edge_offset) + const ushort *gbuf, + uint isz, + uint osz, + uint gsz, + uint inner_edge_offset, + uint outer_edge_offset) { int x; /* Pixel loop counter. */ int a; /* Temporary pixel index buffer loop counter. */ int fsz; /* Size of the frame. */ - unsigned int rsl; /* Long used for finding fast `1.0/sqrt`. */ + uint rsl; /* Long used for finding fast `1.0/sqrt`. */ float rsf; /* Float used for finding fast `1.0/sqrt`. */ const float rsopf = 1.5f; /* Constant float used for finding fast `1.0/sqrt`. */ - unsigned int gradient_fill_offset; - unsigned int t; - unsigned int ud; /* Unscaled edge distance. */ - unsigned int dmin; /* Minimum edge distance. */ - float odist; /* Current outer edge distance. */ - float idist; /* Current inner edge distance. */ - int dx; /* X-delta (used for distance proportion calculation) */ - int dy; /* Y-delta (used for distance proportion calculation) */ + uint gradient_fill_offset; + uint t; + uint ud; /* Unscaled edge distance. */ + uint dmin; /* Minimum edge distance. */ + float odist; /* Current outer edge distance. */ + float idist; /* Current inner edge distance. */ + int dx; /* X-delta (used for distance proportion calculation) */ + int dy; /* Y-delta (used for distance proportion calculation) */ /* * The general algorithm used to color each gradient pixel is: @@ -1152,8 +1132,8 @@ static void do_fillGradientBuffer(unsigned int rw, } odist = (float)(dmin); /* Cast outer min to a float. */ rsf = odist * 0.5f; - rsl = *(unsigned int *)&odist; /* Use some peculiar properties of the way bits are stored. */ - rsl = 0x5f3759df - (rsl >> 1); /* In floats vs. unsigned ints to compute an approximate. */ + rsl = *(uint *)&odist; /* Use some peculiar properties of the way bits are stored. */ + rsl = 0x5f3759df - (rsl >> 1); /* In floats vs. uints to compute an approximate. */ odist = *(float *)&rsl; /* Reciprocal square root. */ odist = odist * (rsopf - (rsf * odist * odist)); /* -- This line can be iterated for more accuracy. -- */ @@ -1173,7 +1153,7 @@ static void do_fillGradientBuffer(unsigned int rw, /* Cast inner min to a float. */ idist = (float)(dmin); rsf = idist * 0.5f; - rsl = *(unsigned int *)&idist; + rsl = *(uint *)&idist; /* See notes above. */ rsl = 0x5f3759df - (rsl >> 1); @@ -1195,24 +1175,22 @@ static void do_fillGradientBuffer(unsigned int rw, void DoubleEdgeMaskOperation::do_double_edge_mask(float *imask, float *omask, float *res) { - unsigned int *lres; /* Pointer to output pixel buffer (for bit operations). */ - unsigned int *limask; /* Pointer to inner mask (for bit operations). */ - unsigned int *lomask; /* Pointer to outer mask (for bit operations). */ + uint *lres; /* Pointer to output pixel buffer (for bit operations). */ + uint *limask; /* Pointer to inner mask (for bit operations). */ + uint *lomask; /* Pointer to outer mask (for bit operations). */ int rw; /* Pixel row width. */ int t; /* Total number of pixels in buffer - 1 (used for loop starts). */ int fsz; /* Size of the frame. */ - unsigned int isz = 0; /* Size (in pixels) of inside edge pixel index buffer. */ - unsigned int osz = 0; /* Size (in pixels) of outside edge pixel index buffer. */ - unsigned int gsz = 0; /* Size (in pixels) of gradient pixel index buffer. */ - unsigned int rsize[3]; /* Size storage to pass to helper functions. */ - unsigned int inner_edge_offset = - 0; /* Offset into final buffer where inner edge pixel indexes start. */ - unsigned int outer_edge_offset = - 0; /* Offset into final buffer where outer edge pixel indexes start. */ + uint isz = 0; /* Size (in pixels) of inside edge pixel index buffer. */ + uint osz = 0; /* Size (in pixels) of outside edge pixel index buffer. */ + uint gsz = 0; /* Size (in pixels) of gradient pixel index buffer. */ + uint rsize[3]; /* Size storage to pass to helper functions. */ + uint inner_edge_offset = 0; /* Offset into final buffer where inner edge pixel indexes start. */ + uint outer_edge_offset = 0; /* Offset into final buffer where outer edge pixel indexes start. */ - unsigned short *gbuf; /* Gradient/inner/outer pixel location index buffer. */ + ushort *gbuf; /* Gradient/inner/outer pixel location index buffer. */ if (true) { /* If both input sockets have some data coming in... */ @@ -1223,9 +1201,9 @@ void DoubleEdgeMaskOperation::do_double_edge_mask(float *imask, float *omask, fl sizeof(float) * (t + 1)); /* Clear output buffer (not all pixels will be written later). */ - lres = (unsigned int *)res; /* Pointer to output buffer (for bit level ops).. */ - limask = (unsigned int *)imask; /* Pointer to input mask (for bit level ops).. */ - lomask = (unsigned int *)omask; /* Pointer to output mask (for bit level ops).. */ + lres = (uint *)res; /* Pointer to output buffer (for bit level ops).. */ + limask = (uint *)imask; /* Pointer to input mask (for bit level ops).. */ + lomask = (uint *)omask; /* Pointer to output mask (for bit level ops).. */ /* * The whole buffer is broken up into 4 parts. The four CORNERS, the FIRST and LAST rows, the @@ -1291,7 +1269,7 @@ void DoubleEdgeMaskOperation::do_double_edge_mask(float *imask, float *omask, fl /* Calculate size of pixel index buffer needed. */ fsz = gsz + isz + osz; /* Allocate edge/gradient pixel index buffer. */ - gbuf = (unsigned short *)MEM_callocN(sizeof(unsigned short) * fsz * 2, "DEM"); + gbuf = (ushort *)MEM_callocN(sizeof(ushort) * fsz * 2, "DEM"); do_createEdgeLocationBuffer( t, rw, lres, res, gbuf, &inner_edge_offset, &outer_edge_offset, isz, gsz); |