use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ImplConvolveBox method vertical.
public static void vertical(GrayS32 input, GrayS32 output, int radius, @Nullable GrowArray<DogArray_I32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
final int kernelWidth = radius * 2 + 1;
final int backStep = kernelWidth * input.stride;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(radius, output.height-radius, kernelWidth, workspaces, (work, y0,y1)->{
final int y0 = radius, y1 = output.height - radius;
int[] totals = BoofMiscOps.checkDeclare(work, input.width, false);
for (int x = 0; x < input.width; x++) {
int indexIn = input.startIndex + (y0 - radius) * input.stride + x;
int indexOut = output.startIndex + output.stride * y0 + x;
int total = 0;
int indexEnd = indexIn + input.stride * kernelWidth;
for (; indexIn < indexEnd; indexIn += input.stride) {
total += input.data[indexIn];
}
totals[x] = total;
output.data[indexOut] = total;
}
// change the order it is processed in to reduce cache misses
for (int y = y0 + 1; y < y1; y++) {
int indexIn = input.startIndex + (y + radius) * input.stride;
int indexOut = output.startIndex + y * output.stride;
for (int x = 0; x < input.width; x++, indexIn++, indexOut++) {
int total = totals[x] - (input.data[indexIn - backStep]);
totals[x] = total += input.data[indexIn];
output.data[indexOut] = total;
}
}
// CONCURRENT_INLINE });
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ConvolveImageUnrolled_SB_S16_I16_Div method convolve11.
public static void convolve11(Kernel2D_S32 kernel, GrayS16 src, GrayI16 dest, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
final short[] dataSrc = src.data;
final short[] dataDst = dest.data;
final int width = src.getWidth();
final int height = src.getHeight();
final int halfDivisor = divisor / 2;
final int kernelRadius = kernel.getRadius();
final int kernelWidth = 2 * kernelRadius + 1;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(kernelRadius, height-kernelRadius, kernelWidth, workspaces, (work, y0, y1)->{
final int y0 = kernelRadius, y1 = height - kernelRadius;
int[] totalRow = BoofMiscOps.checkDeclare(work, src.width, false);
for (int y = y0; y < y1; y++) {
// first time through the value needs to be set
int k1 = kernel.data[0];
int k2 = kernel.data[1];
int k3 = kernel.data[2];
int k4 = kernel.data[3];
int k5 = kernel.data[4];
int k6 = kernel.data[5];
int k7 = kernel.data[6];
int k8 = kernel.data[7];
int k9 = kernel.data[8];
int k10 = kernel.data[9];
int k11 = kernel.data[10];
int indexSrcRow = src.startIndex + (y - kernelRadius) * src.stride - kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc++]) * k3;
total += (dataSrc[indexSrc++]) * k4;
total += (dataSrc[indexSrc++]) * k5;
total += (dataSrc[indexSrc++]) * k6;
total += (dataSrc[indexSrc++]) * k7;
total += (dataSrc[indexSrc++]) * k8;
total += (dataSrc[indexSrc++]) * k9;
total += (dataSrc[indexSrc++]) * k10;
total += (dataSrc[indexSrc]) * k11;
totalRow[x] = total;
}
// rest of the convolution rows are an addition
for (int i = 1; i < 11; i++) {
indexSrcRow = src.startIndex + (y + i - kernelRadius) * src.stride - kernelRadius;
k1 = kernel.data[i * 11 + 0];
k2 = kernel.data[i * 11 + 1];
k3 = kernel.data[i * 11 + 2];
k4 = kernel.data[i * 11 + 3];
k5 = kernel.data[i * 11 + 4];
k6 = kernel.data[i * 11 + 5];
k7 = kernel.data[i * 11 + 6];
k8 = kernel.data[i * 11 + 7];
k9 = kernel.data[i * 11 + 8];
k10 = kernel.data[i * 11 + 9];
k11 = kernel.data[i * 11 + 10];
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc++]) * k3;
total += (dataSrc[indexSrc++]) * k4;
total += (dataSrc[indexSrc++]) * k5;
total += (dataSrc[indexSrc++]) * k6;
total += (dataSrc[indexSrc++]) * k7;
total += (dataSrc[indexSrc++]) * k8;
total += (dataSrc[indexSrc++]) * k9;
total += (dataSrc[indexSrc++]) * k10;
total += (dataSrc[indexSrc]) * k11;
totalRow[x] += total;
}
}
int indexDst = dest.startIndex + y * dest.stride + kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
dataDst[indexDst++] = (short) ((totalRow[x] + halfDivisor) / divisor);
}
}
// CONCURRENT_INLINE });
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ConvolveImageUnrolled_SB_S32_S32_Div method convolve9.
public static void convolve9(Kernel2D_S32 kernel, GrayS32 src, GrayS32 dest, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
final int[] dataSrc = src.data;
final int[] dataDst = dest.data;
final int width = src.getWidth();
final int height = src.getHeight();
final int halfDivisor = divisor / 2;
final int kernelRadius = kernel.getRadius();
final int kernelWidth = 2 * kernelRadius + 1;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(kernelRadius, height-kernelRadius, kernelWidth, workspaces, (work, y0, y1)->{
final int y0 = kernelRadius, y1 = height - kernelRadius;
int[] totalRow = BoofMiscOps.checkDeclare(work, src.width, false);
for (int y = y0; y < y1; y++) {
// first time through the value needs to be set
int k1 = kernel.data[0];
int k2 = kernel.data[1];
int k3 = kernel.data[2];
int k4 = kernel.data[3];
int k5 = kernel.data[4];
int k6 = kernel.data[5];
int k7 = kernel.data[6];
int k8 = kernel.data[7];
int k9 = kernel.data[8];
int indexSrcRow = src.startIndex + (y - kernelRadius) * src.stride - kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc++]) * k3;
total += (dataSrc[indexSrc++]) * k4;
total += (dataSrc[indexSrc++]) * k5;
total += (dataSrc[indexSrc++]) * k6;
total += (dataSrc[indexSrc++]) * k7;
total += (dataSrc[indexSrc++]) * k8;
total += (dataSrc[indexSrc]) * k9;
totalRow[x] = total;
}
// rest of the convolution rows are an addition
for (int i = 1; i < 9; i++) {
indexSrcRow = src.startIndex + (y + i - kernelRadius) * src.stride - kernelRadius;
k1 = kernel.data[i * 9 + 0];
k2 = kernel.data[i * 9 + 1];
k3 = kernel.data[i * 9 + 2];
k4 = kernel.data[i * 9 + 3];
k5 = kernel.data[i * 9 + 4];
k6 = kernel.data[i * 9 + 5];
k7 = kernel.data[i * 9 + 6];
k8 = kernel.data[i * 9 + 7];
k9 = kernel.data[i * 9 + 8];
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc++]) * k3;
total += (dataSrc[indexSrc++]) * k4;
total += (dataSrc[indexSrc++]) * k5;
total += (dataSrc[indexSrc++]) * k6;
total += (dataSrc[indexSrc++]) * k7;
total += (dataSrc[indexSrc++]) * k8;
total += (dataSrc[indexSrc]) * k9;
totalRow[x] += total;
}
}
int indexDst = dest.startIndex + y * dest.stride + kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
dataDst[indexDst++] = ((totalRow[x] + halfDivisor) / divisor);
}
}
// CONCURRENT_INLINE });
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ConvolveImageUnrolled_SB_S32_S32_Div method convolve3.
public static void convolve3(Kernel2D_S32 kernel, GrayS32 src, GrayS32 dest, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
final int[] dataSrc = src.data;
final int[] dataDst = dest.data;
final int width = src.getWidth();
final int height = src.getHeight();
final int halfDivisor = divisor / 2;
final int kernelRadius = kernel.getRadius();
final int kernelWidth = 2 * kernelRadius + 1;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(kernelRadius, height-kernelRadius, kernelWidth, workspaces, (work, y0, y1)->{
final int y0 = kernelRadius, y1 = height - kernelRadius;
int[] totalRow = BoofMiscOps.checkDeclare(work, src.width, false);
for (int y = y0; y < y1; y++) {
// first time through the value needs to be set
int k1 = kernel.data[0];
int k2 = kernel.data[1];
int k3 = kernel.data[2];
int indexSrcRow = src.startIndex + (y - kernelRadius) * src.stride - kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc]) * k3;
totalRow[x] = total;
}
// rest of the convolution rows are an addition
for (int i = 1; i < 3; i++) {
indexSrcRow = src.startIndex + (y + i - kernelRadius) * src.stride - kernelRadius;
k1 = kernel.data[i * 3 + 0];
k2 = kernel.data[i * 3 + 1];
k3 = kernel.data[i * 3 + 2];
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc]) * k3;
totalRow[x] += total;
}
}
int indexDst = dest.startIndex + y * dest.stride + kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
dataDst[indexDst++] = ((totalRow[x] + halfDivisor) / divisor);
}
}
// CONCURRENT_INLINE });
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ConvolveImageUnrolled_SB_U16_I16_Div method convolve7.
public static void convolve7(Kernel2D_S32 kernel, GrayU16 src, GrayI16 dest, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
final short[] dataSrc = src.data;
final short[] dataDst = dest.data;
final int width = src.getWidth();
final int height = src.getHeight();
final int halfDivisor = divisor / 2;
final int kernelRadius = kernel.getRadius();
final int kernelWidth = 2 * kernelRadius + 1;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(kernelRadius, height-kernelRadius, kernelWidth, workspaces, (work, y0, y1)->{
final int y0 = kernelRadius, y1 = height - kernelRadius;
int[] totalRow = BoofMiscOps.checkDeclare(work, src.width, false);
for (int y = y0; y < y1; y++) {
// first time through the value needs to be set
int k1 = kernel.data[0];
int k2 = kernel.data[1];
int k3 = kernel.data[2];
int k4 = kernel.data[3];
int k5 = kernel.data[4];
int k6 = kernel.data[5];
int k7 = kernel.data[6];
int indexSrcRow = src.startIndex + (y - kernelRadius) * src.stride - kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++] & 0xFFFF) * k1;
total += (dataSrc[indexSrc++] & 0xFFFF) * k2;
total += (dataSrc[indexSrc++] & 0xFFFF) * k3;
total += (dataSrc[indexSrc++] & 0xFFFF) * k4;
total += (dataSrc[indexSrc++] & 0xFFFF) * k5;
total += (dataSrc[indexSrc++] & 0xFFFF) * k6;
total += (dataSrc[indexSrc] & 0xFFFF) * k7;
totalRow[x] = total;
}
// rest of the convolution rows are an addition
for (int i = 1; i < 7; i++) {
indexSrcRow = src.startIndex + (y + i - kernelRadius) * src.stride - kernelRadius;
k1 = kernel.data[i * 7 + 0];
k2 = kernel.data[i * 7 + 1];
k3 = kernel.data[i * 7 + 2];
k4 = kernel.data[i * 7 + 3];
k5 = kernel.data[i * 7 + 4];
k6 = kernel.data[i * 7 + 5];
k7 = kernel.data[i * 7 + 6];
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++] & 0xFFFF) * k1;
total += (dataSrc[indexSrc++] & 0xFFFF) * k2;
total += (dataSrc[indexSrc++] & 0xFFFF) * k3;
total += (dataSrc[indexSrc++] & 0xFFFF) * k4;
total += (dataSrc[indexSrc++] & 0xFFFF) * k5;
total += (dataSrc[indexSrc++] & 0xFFFF) * k6;
total += (dataSrc[indexSrc] & 0xFFFF) * k7;
totalRow[x] += total;
}
}
int indexDst = dest.startIndex + y * dest.stride + kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
dataDst[indexDst++] = (short) ((totalRow[x] + halfDivisor) / divisor);
}
}
// CONCURRENT_INLINE });
}
Aggregations