- const char *filename0 = argc >= (optind + 1) ? argv[optind] : "test1499.png";
- const char *filename1 = argc >= (optind + 2) ? argv[optind + 1] : "test1500.png";
- const char *flow_filename = argc >= (optind + 3) ? argv[optind + 2] : "flow.flo";
-
- // Load pictures.
- unsigned width1, height1, width2, height2;
- GLuint tex0 = load_texture(filename0, &width1, &height1, WITHOUT_MIPMAPS);
- GLuint tex1 = load_texture(filename1, &width2, &height2, WITHOUT_MIPMAPS);
-
- if (width1 != width2 || height1 != height2) {
- fprintf(stderr, "Image dimensions don't match (%dx%d versus %dx%d)\n",
- width1, height1, width2, height2);
- exit(1);
- }
-
- // Set up some PBOs to do asynchronous readback.
- GLuint pbos[5];
- glCreateBuffers(5, pbos);
- for (int i = 0; i < 5; ++i) {
- glNamedBufferData(pbos[i], width1 * height1 * 2 * sizeof(float), nullptr, GL_STREAM_READ);
- spare_pbos.push(pbos[i]);
- }
-
- int levels = find_num_levels(width1, height1);
- GLuint tex0_gray, tex1_gray;
- glCreateTextures(GL_TEXTURE_2D, 1, &tex0_gray);
- glCreateTextures(GL_TEXTURE_2D, 1, &tex1_gray);
- glTextureStorage2D(tex0_gray, levels, GL_R8, width1, height1);
- glTextureStorage2D(tex1_gray, levels, GL_R8, width1, height1);
-
- GrayscaleConversion gray;
- gray.exec(tex0, tex0_gray, width1, height1);
- glDeleteTextures(1, &tex0);
- glGenerateTextureMipmap(tex0_gray);
-
- gray.exec(tex1, tex1_gray, width1, height1);
- glDeleteTextures(1, &tex1);
- glGenerateTextureMipmap(tex1_gray);
-
- DISComputeFlow compute_flow(width1, height1);
- GLuint final_tex = compute_flow.exec(tex0_gray, tex1_gray, DISComputeFlow::RESIZE_FLOW_TO_FULL_SIZE);
-
- schedule_read(final_tex, width1, height1, filename0, filename1, flow_filename, "flow.ppm");
- compute_flow.release_texture(final_tex);
-
- // See if there are more flows on the command line (ie., more than three arguments),
- // and if so, process them.
- int num_flows = (argc - optind) / 3;
- for (int i = 1; i < num_flows; ++i) {
- const char *filename0 = argv[optind + i * 3 + 0];
- const char *filename1 = argv[optind + i * 3 + 1];
- const char *flow_filename = argv[optind + i * 3 + 2];
- GLuint width, height;
- GLuint tex0 = load_texture(filename0, &width, &height, WITHOUT_MIPMAPS);
- if (width != width1 || height != height1) {
- fprintf(stderr, "%s: Image dimensions don't match (%dx%d versus %dx%d)\n",
- filename0, width, height, width1, height1);
- exit(1);
- }
- gray.exec(tex0, tex0_gray, width, height);
- glGenerateTextureMipmap(tex0_gray);
- glDeleteTextures(1, &tex0);
-
- GLuint tex1 = load_texture(filename1, &width, &height, WITHOUT_MIPMAPS);
- if (width != width1 || height != height1) {
- fprintf(stderr, "%s: Image dimensions don't match (%dx%d versus %dx%d)\n",
- filename1, width, height, width1, height1);
- exit(1);