int applyInputFrame(u_int8_t *raw_frame, InputFrame *data, u_int32_t frame_height, u_int32_t frame_width) { // TODO: Error-checking unsigned long i, j; for (i = 0; i < data->num_rects; i++) { InputRect *rect = &data->rects[i]; for (j = 0; j < rect->height; j++) { int rect_line = rect->y + j; int frame_line = frame_height - rect_line - j; u_int8_t *raw_frame_line = raw_frame + 4 * frame_width * frame_line; // go to the correct line of the frame. u_int8_t *rect_data_line = rect->data + 4 * rect->width * j; // go to the correct line of the rect data. memcpy(raw_frame_line + 4 * rect->x, rect_data_line, sizeof(u_int8_t) * rect->width * 4); } } }