static int fields_filter_video(TCModuleInstance *self, vframe_list_t *frame) { FieldsPrivateData *pd = NULL; uint8_t *f1 = NULL, *f2 = NULL, *b1 = NULL, *b2 = NULL; int width, height; TC_MODULE_SELF_CHECK(self, "filter"); TC_MODULE_SELF_CHECK(frame, "filter"); pd = self->userdata; width = frame->v_width * (pd->rgb_mode ? 3 : 1); height = frame->v_height; f1 = frame->video_buf; f2 = frame->video_buf + width; b1 = pd->buffer; b2 = pd->buffer + width; switch (pd->field_ops) { case FIELD_OP_FLIP: swap_fields(pd->buffer, f1, f2, width, height); break; case FIELD_OP_SHIFT: copy_field(pd->buf_field ? b2 : b1, f2, width, height); copy_field(f2, f1, width, height); copy_field(f1, pd->buf_field ? b1 : b2, width, height); break; case FIELD_OP_SHIFTFLIP: // Shift + Flip is the same result as just delaying the second field by // one frame, so do that because it's faster. copy_field(pd->buf_field ? b1 : b2, f2, width, height); copy_field(f2, pd->buf_field ? b2 : b1, width, height); break; case FIELD_OP_FLIPSHIFT: // Flip + Shift is the same result as just delaying the first field by // one frame, so do that because it's faster. copy_field(pd->buf_field ? b1 : b2, f1, width, height); copy_field(f1, pd->buf_field ? b2 : b1, width, height); // Chroma information is usually taken from the top field, which we're // shifting here. We probably should move the chroma info with it, but // this will be used so rarely (and this is only an issue in YUV mode // anyway, which is not reccomended to start with) that it's probably not // worth bothering. break; } pd->buf_field ^= 1; return TC_OK; }
int main(int argc, char **argv) { double a = 0.5; //!< Diffusion constant field current, previous; //!< Current and previous temperature fields double dt; //!< Time step int nsteps = 500; //!< Number of time steps int rows = 200; //!< Field dimensions with default values int cols = 200; char input_file[64]; //!< Name of the optional input file int image_interval = 10; //!< Image output interval int iter; /* Following combinations of command line arguments are possible: No arguments: use default field dimensions and number of time steps One argument: read initial field from a given file Two arguments: initial field from file and number of time steps Three arguments: field dimensions (rows,cols) and number of time steps */ switch (argc) { case 1: // use defaults initialize_field_metadata(¤t, rows, cols); initialize_field_metadata(&previous, rows, cols); initialize(¤t, &previous); break; case 2: // Initial field from a file strncpy(input_file, argv[1], 64); read_input(¤t, &previous, input_file); break; case 3: // Initial field from a file strncpy(input_file, argv[1], 64); read_input(¤t, &previous, input_file); // Number of time steps nsteps = atoi(argv[2]); break; case 4: // Field dimensions rows = atoi(argv[1]); cols = atoi(argv[2]); initialize_field_metadata(¤t, rows, cols); initialize_field_metadata(&previous, rows, cols); initialize(¤t, &previous); // Number of time steps nsteps = atoi(argv[3]); break; default: printf("Unsupported number of command line arguments\n"); return -1; } // Output the initial field output(¤t, 0); // Largest stable time step dt = current.dx2 * current.dy2 / (2.0 * a * (current.dx2 + current.dy2)); // Time evolve for (iter = 1; iter < nsteps; iter++) { evolve(¤t, &previous, a, dt); // output every 10 iteration if (iter % image_interval == 0) output(¤t, iter); // make current field to be previous for next iteration step swap_fields(¤t, &previous); } finalize(¤t, &previous); return 0; }