-
Notifications
You must be signed in to change notification settings - Fork 0
/
workers.c
31 lines (24 loc) · 1.09 KB
/
workers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include"utils.h"
/*thread worker to shift the filter kernel to the right, and calculate the median
for the middle cell and assign to output image*/
void *shiftKernel(void* args)
{
HistInfo* hi = (HistInfo*) args;
BMPImage* gray = hi->gray;
int *kernel_hist = malloc(sizeof(int) * BINS);
//initializing relevant histograms
kernel_hist = initializeHist(hi->radius, gray, kernel_hist, hi->mid_height);
int** col_hists = allocate_mem(BINS, hi->max_width);
col_hists = initializeColHist(gray, hi->radius, hi->max_width, col_hists, hi->mid_height);
int i = hi->mid_height + hi->radius;
//moving along one row
for(int j = hi->radius; j < (hi->max_width) - (hi->radius) - 1; j++)
{
int median = calcMedian(kernel_hist, hi->radius);
(hi->adaptive)->data[(i*(hi->max_width)+j)*3] = median;
(hi->adaptive)->data[(i*(hi->max_width)+j)*3 + 1] = median;
(hi->adaptive)->data[(i*(hi->max_width)+j)*3 + 2] = median;
kernel_hist = updateKernelRow(kernel_hist, col_hists, i, j, hi->radius);
}
pthread_exit(0);
}