static void do_body (uint8_t *input, uint8_t *red, uint8_t *blue, uint8_t *green, GstBayer2RGB *filter) { int ip, op; /* input and output pointers */ int w, h; /* loop indices */ int type; /* calculated colour of current element */ int a1, a2; int v1, v2, h1, h2; /* * We are processing row (line) by row, starting with the second * row and continuing through the next to last. Each row is processed * column by column, starting with the second and continuing through * to the next to last. */ for (h = 1; h < filter->height - 1; h++) { /* * Remember we are processing "row by row". For each row, we need * to set the type of the first element to be processed. Since we * have already processed the edges, the "first element" will be * the pixel at position (1,1). Assuming RG format, this should * be BLUE for odd-numbered rows and GREENR for even rows. */ if (h & 1) type = RED; else type = GREENB; /* Calculate the starting position for the row */ op = h * filter->width; /* output (converted) pos */ ip = h * filter->stride; /* input (bayer data) pos */ for (w = 1; w < filter->width - 1; w++) { op++; /* we are processing "horizontally" */ ip++; switch (type) { case RED: red[op] = input[ip]; blue[op] = (input[ip - filter->stride - 1] + input[ip - filter->stride + 1] + input[ip + filter->stride - 1] + input[ip + filter->stride + 1] + 2) / 4; v1 = input[ip + filter->stride]; v2 = input[ip - filter->stride]; h1 = input[ip + 1]; h2 = input[ip - 1]; a1 = abs (v1 - v2); a2 = abs (h1 - h2); if (a1 < a2) green[op] = (v1 + v2 + 1) / 2; else if (a1 > a2) green[op] = (h1 + h2 + 1) / 2; else green[op] = (v1 + h1 + v2 + h2 + 2) / 4; type = GREENR; /* step horizontally */ break; case GREENR: red[op] = (input[ip + 1] + input[ip - 1] + 1) / 2; green[op] = input[ip]; blue[op] = (input[ip - filter->stride] + input[ip + filter->stride] + 1) / 2; type = RED; break; case GREENB: red[op] = (input[ip - filter->stride] + input[ip + filter->stride] + 1) / 2; green[op] = input[ip]; blue[op] = (input[ip + 1] + input[ip - 1] + 1) / 2; type = BLUE; break; case BLUE: red[op] = (input[ip - filter->stride - 1] + input[ip - filter->stride + 1] + input[ip + filter->stride - 1] + input[ip + filter->stride + 1] + 2) / 4; blue[op] = input[ip]; v1 = input[ip + filter->stride]; v2 = input[ip - filter->stride]; h1 = input[ip + 1]; h2 = input[ip - 1]; a1 = abs (v1 - v2); a2 = abs (h1 - h2); if (a1 < a2) green[op] = (v1 + v2 + 1) / 2; else if (a1 > a2) green[op] = (h1 + h2 + 1) / 2; else green[op] = (v1 + h1 + v2 + h2 + 2) / 4; type = GREENB; break; } } } }