- Home /
Question by
ahmedandre · Nov 06, 2020 at 04:50 AM ·
unity 5threading
How would I convert that piece of function into Unity Job System ?
Hello, I'm doing filtering on a depth image and I would like to convert that piece of code into job system of unity, because it's so slow. The image update is called each frame
public unsafe void DRSFilter( byte * src, byte * dst, uint data_delta, uint history_scan_depth)
{
if (history_scan_depth > history_capacity)
{
history_scan_depth = history_capacity;
}
for (int i = 0; i < layer_size; i++)
{
byte b = src[i];
bool is_color_pixel = false;
uint avrg = 0;
for (int k = 0; k < history_scan_depth; k++)
{
avrg += history[k * layer_size + i];
if (history[k * layer_size + i] > 0)
{
is_color_pixel = true;
// break;
}
}
average[i] = (byte)(avrg / history_scan_depth);
//if (b > 0 || b == 0 && !is_color_pixel) {
if (Abs(b - average[i]) < data_delta)
{
dst[i] = b;
}
// }
history[layer * layer_size + i] = b;
}
layer++;
if (layer == history_scan_depth)
{
layer = 0;
}
}
private unsafe void ImageUpdated(Camera cam, ref Mat cvMatDepth)
{
long addrsrc = cvMatDepth.dataAddr();
long addrDst = dstResult.dataAddr();
DRSFilter((byte*)addrsrc, (byte*)addrDst, a, b);
Utils.matToTexture2D(dstResult, texture);
canvas.GetComponent<RawImage>().texture = texture;
}
Comment