static PyObject * _minrep(PyObject *self, PyObject *args) { // compares two cyclic strings and returns alphabetically smallest // cyclic shift of the string which contains the smallest such shift // from the pair Py_buffer inputA, inputB, *tmp; if (!PyArg_ParseTuple(args, "y*y*", &inputA, &inputB)) { return NULL; } unsigned int inputA_msp, inputB_msp, inputA_period, inputB_period; inputA_msp = MSP(inputA.len, inputA.buf, &inputA_period); inputB_msp = MSP(inputB.len, inputB.buf, &inputB_period); // positive result: A < B, negative result: A > B, zero: A == B int result = COMPARE2(inputA.len, inputB.len, inputA.buf, inputB.buf, inputA_msp, inputB_msp); // decide between A and B unsigned int tmp_msp; if (result > 0) { // A < B tmp_msp = inputA_msp; tmp = &inputA; } else if (result < 0) { // B < A tmp_msp = inputB_msp; tmp = &inputB; } else if (inputB.len < inputA.len) { // A == B, len(B) < len(A) tmp_msp = inputB_msp; tmp = &inputB; } else { // A == B, len(A) <= len(B) tmp_msp = inputA_msp; tmp = &inputA; } minrep_inplace_msp(tmp->buf, tmp->len, tmp_msp); return Py_BuildValue("s#", tmp->buf, tmp->len); }
int ShapeWipeMain::process_realtime(VFrame *incoming, VFrame *outgoing) { unsigned char *pattern_row; int col_offset; unsigned char threshold; unsigned char value; int i,j,k; int opacity; init_shapes(); load_configuration(); int w = incoming->get_w(); int h = incoming->get_h(); if (strncmp(filename, last_read_filename, BCTEXTLEN) || strncmp(shape_name, current_name, BCTEXTLEN) || preserve_aspect != last_preserve_aspect) { reset_pattern_image(); } if (!pattern_image) { read_pattern_image(w, h); strncpy(last_read_filename, filename, BCTEXTLEN); strncpy(current_name, shape_name, BCTEXTLEN); last_preserve_aspect = preserve_aspect; } if (!pattern_image) { fprintf(stderr, "Shape Wipe: cannot load shape %s\n", filename); return 0; } if (direction) { threshold = (unsigned char)( (float)PluginClient::get_source_position() / (float)PluginClient::get_total_len() * (float)(max_value - min_value)) + min_value; } else { threshold = (unsigned char)((max_value - min_value) - ( (float)PluginClient::get_source_position() / (float)PluginClient::get_total_len() * (float)(max_value - min_value))) + min_value; } if (antialias) { if (direction) { /* Top left corner */ opacity = 0; COMPARE1(0,0); COMPARE1(0,1); COMPARE1(1,0); COMPARE1(1,1); BLEND(0,0,4.0); /* Top edge */ for (k = 1; k < w-1; k++) { opacity = 0; COMPARE1(0,k-1); COMPARE1(0,k); COMPARE1(0,k+1); COMPARE1(1,k-1); COMPARE1(1,k); COMPARE1(1,k+1); BLEND(0,k,6.0); } /* Top right corner */ opacity = 0; COMPARE1(0,w-1); COMPARE1(0,w-2); COMPARE1(1,w-1); COMPARE1(1,w-2); BLEND(0,w-1,4.0); /* Left edge */ for (j = 1; j < h-1; j++) { opacity = 0; COMPARE1(j-1,0); COMPARE1(j,0); COMPARE1(j+1,0); COMPARE1(j-1,1); COMPARE1(j,1); COMPARE1(j+1,1); BLEND(j,0,6.0); } /* Middle */ for (j = 1; j < h-1; j++) { for (k = 1; k < w-1; k++) { opacity = 0; COMPARE1(j-1,k-1); COMPARE1(j,k-1); COMPARE1(j+1,k-1); COMPARE1(j-1,k); COMPARE1(j,k); COMPARE1(j+1,k); COMPARE1(j-1,k+1); COMPARE1(j,k+1); COMPARE1(j+1,k+1); BLEND(j,k,9.0); } } /* Right edge */ for (j = 1; j < h-1; j++) { opacity = 0; COMPARE1(j-1,w-1); COMPARE1(j,w-1); COMPARE1(j+1,w-1); COMPARE1(j-1,w-2); COMPARE1(j,w-2); COMPARE1(j+1,w-2); BLEND(j,w-1,6.0); } /* Bottom left corner */ opacity = 0; COMPARE1(h-1,0); COMPARE1(h-1,1); COMPARE1(h-2,0); COMPARE1(h-2,1); BLEND(h-1,0,4.0); /* Bottom edge */ for (k = 1; k < w-1; k++) { opacity = 0; COMPARE1(h-1,k-1); COMPARE1(h-1,k); COMPARE1(h-1,k+1); COMPARE1(h-2,k-1); COMPARE1(h-2,k); COMPARE1(h-2,k+1); BLEND(h-1,k,6.0); } /* Bottom right corner */ opacity = 0; COMPARE1(h-1,w-1); COMPARE1(h-1,w-2); COMPARE1(h-2,w-1); COMPARE1(h-2,w-2); BLEND(h-1,w-1,4.0); } else { /* Top left corner */ opacity = 0; COMPARE2(0,0); COMPARE2(0,1); COMPARE2(1,0); COMPARE2(1,1); BLEND(0,0,4.0); /* Top edge */ for (k = 1; k < w-1; k++) { opacity = 0; COMPARE2(0,k-1); COMPARE2(0,k); COMPARE2(0,k+1); COMPARE2(1,k-1); COMPARE2(1,k); COMPARE2(1,k+1); BLEND(0,k,6.0); } /* Top right corner */ opacity = 0; COMPARE2(0,w-1); COMPARE2(0,w-2); COMPARE2(1,w-1); COMPARE2(1,w-2); BLEND(0,w-1,4.0); /* Left edge */ for (j = 1; j < h-1; j++) { opacity = 0; COMPARE2(j-1,0); COMPARE2(j,0); COMPARE2(j+1,0); COMPARE2(j-1,1); COMPARE2(j,1); COMPARE2(j+1,1); BLEND(j,0,6.0); } /* Middle */ for (j = 1; j < h-1; j++) { for (k = 1; k < w-1; k++) { opacity = 0; COMPARE2(j-1,k-1); COMPARE2(j,k-1); COMPARE2(j+1,k-1); COMPARE2(j-1,k); COMPARE2(j,k); COMPARE2(j+1,k); COMPARE2(j-1,k+1); COMPARE2(j,k+1); COMPARE2(j+1,k+1); BLEND(j,k,9.0); } } /* Right edge */ for (j = 1; j < h-1; j++) { opacity = 0; COMPARE2(j-1,w-1); COMPARE2(j,w-1); COMPARE2(j+1,w-1); COMPARE2(j-1,w-2); COMPARE2(j,w-2); COMPARE2(j+1,w-2); BLEND(j,w-1,6.0); } /* Bottom left corner */ opacity = 0; COMPARE2(h-1,0); COMPARE2(h-1,1); COMPARE2(h-2,0); COMPARE2(h-2,1); BLEND(h-1,0,4.0); /* Bottom edge */ for (k = 1; k < w-1; k++) { opacity = 0; COMPARE2(h-1,k-1); COMPARE2(h-1,k); COMPARE2(h-1,k+1); COMPARE2(h-2,k-1); COMPARE2(h-2,k); COMPARE2(h-2,k+1); BLEND(h-1,k,6.0); } /* Bottom right corner */ opacity = 0; COMPARE2(h-1,w-1); COMPARE2(h-1,w-2); COMPARE2(h-2,w-1); COMPARE2(h-2,w-2); BLEND(h-1,w-1,4.0); } } else { switch(incoming->get_color_model()) { case BC_RGB_FLOAT: SHAPEWIPE(float, 3) break; case BC_RGB888: case BC_YUV888: SHAPEWIPE(unsigned char, 3) break; case BC_RGBA_FLOAT: SHAPEWIPE(float, 4) break; case BC_RGBA8888: case BC_YUVA8888: SHAPEWIPE(unsigned char, 4) break; case BC_RGB161616: case BC_YUV161616: SHAPEWIPE(uint16_t, 3) break; case BC_RGBA16161616: case BC_YUVA16161616: SHAPEWIPE(uint16_t, 4) break; } } return 0; }