bool encode_load_input_images(int argc, char **argv, Images &images) { int nb_input_images = argc-1; while(argc>1) { Image image; v_printf(2,"\r"); if (!image.load(argv[0])) { e_printf("Could not read input file: %s\n", argv[0]); return false; }; images.push_back(std::move(image)); Image& last_image = images.back(); if (last_image.rows() != images[0].rows() || last_image.cols() != images[0].cols()) { e_printf("Dimensions of all input images should be the same!\n"); e_printf(" First image is %ux%u\n",images[0].cols(),images[0].rows()); e_printf(" This image is %ux%u: %s\n",last_image.cols(),last_image.rows(),argv[0]); return false; } if (last_image.numPlanes() < images[0].numPlanes()) { if (images[0].numPlanes() == 3) last_image.ensure_chroma(); else if (images[0].numPlanes() == 4) last_image.ensure_alpha(); else { e_printf("Problem while loading input images, please report this.\n"); return false; } } else if (last_image.numPlanes() > images[0].numPlanes()) { if (last_image.numPlanes() == 3) { for (Image& i : images) i.ensure_chroma(); } else if (last_image.numPlanes() == 4) { for (Image& i : images) i.ensure_alpha(); } else { e_printf("Problem while loading input images, please report this.\n"); return false; } } argc--; argv++; if (nb_input_images>1) {v_printf(2," (%i/%i) ",(int)images.size(),nb_input_images); v_printf(4,"\n");} } v_printf(2,"\n"); return true; }
bool encode_load_input_images(int argc, char **argv, Images &images) { int nb_input_images = argc-1; while(argc>1) { Image image; v_printf(2,"\r"); if (!image.load(argv[0])) { e_printf("Could not read input file: %s\n", argv[0]); return false; }; images.push_back(std::move(image)); const Image& last_image = images.back(); if (last_image.rows() != images[0].rows() || last_image.cols() != images[0].cols() || last_image.numPlanes() != images[0].numPlanes()) { e_printf("Dimensions of all input images should be the same!\n"); e_printf(" First image is %ux%u, %i channels.\n",images[0].cols(),images[0].rows(),images[0].numPlanes()); e_printf(" This image is %ux%u, %i channels: %s\n",last_image.cols(),last_image.rows(),last_image.numPlanes(),argv[0]); return false; } argc--; argv++; if (nb_input_images>1) {v_printf(2," (%i/%i) ",(int)images.size(),nb_input_images); v_printf(4,"\n");} } v_printf(2,"\n"); return true; }
bool encode_load_input_images(int argc, char **argv, Images &images, flif_options &options) { int nb_input_images = argc-1; int nb_actual_images = 0; metadata_options md; md.icc = options.color_profile; md.xmp = options.metadata; md.exif = options.metadata; while(argc>1) { int maxlength = strlen(argv[0])+100; std::vector<char> vfilename(maxlength); char *filename = argv[0]; int framecounter = 0; int stop_searching = 0; bool multiple=false; if (!file_exists(argv[0]) && strchr(argv[0],'%')) { multiple=true; filename = &vfilename[0]; } for ( ; framecounter < 0xFFFFFFF && stop_searching < 1000; framecounter++ ) { if (multiple) { snprintf(filename,maxlength,argv[0],framecounter); if (!file_exists(filename)) { stop_searching++; continue; } stop_searching = 0; } Image image; if (options.keep_palette) image.palette = true; // tells the PNG loader to keep palette intact v_printf_tty(2,"\r"); if (!image.load(filename,md)) { e_printf("Could not read input file: %s\n", argv[0]); return false; }; if (image.numPlanes() > 0) { nb_actual_images++; images.push_back(std::move(image)); Image& last_image = images.back(); if (last_image.rows() != images[0].rows() || last_image.cols() != images[0].cols()) { e_printf("Dimensions of all input images should be the same!\n"); e_printf(" First image is %ux%u\n",images[0].cols(),images[0].rows()); e_printf(" This image is %ux%u: %s\n",last_image.cols(),last_image.rows(),filename); return false; } if (last_image.numPlanes() < images[0].numPlanes()) { if (images[0].numPlanes() == 3) last_image.ensure_chroma(); else if (images[0].numPlanes() == 4) last_image.ensure_alpha(); else { e_printf("Problem while loading input images, please report this.\n"); return false; } } else if (last_image.numPlanes() > images[0].numPlanes()) { if (last_image.numPlanes() == 3) { for (Image& i : images) i.ensure_chroma(); } else if (last_image.numPlanes() == 4) { for (Image& i : images) i.ensure_alpha(); } else { e_printf("Problem while loading input images, please report this.\n"); return false; } } } else { if (images.size() == 0) { e_printf("First specify the actual image(s), then the metadata.\n"); return false; } for (size_t i=0; i<image.metadata.size(); i++) images[0].metadata.push_back(image.metadata[i]); } if (nb_input_images>1) {v_printf(2," (%i/%i) ",(int)images.size(),nb_input_images); v_printf(4,"\n");} if (!multiple) break; } argc--; argv++; } if (nb_actual_images > 0) return true; e_printf("Error: no actual input images to be encoded!\n"); return false; }
bool handle_encode_arguments(int argc, char **argv, Images &images, int palette_size, int acb, flifEncodingOptional method, int lookback, int learn_repeats, int frame_delay) { int nb_input_images = argc-1; while(argc>1) { Image image; v_printf(2,"\r"); if (!image.load(argv[0])) { e_printf("Could not read input file: %s\n", argv[0]); return 2; }; images.push_back(std::move(image)); const Image& last_image = images.back(); if (last_image.rows() != images[0].rows() || last_image.cols() != images[0].cols() || last_image.numPlanes() != images[0].numPlanes()) { e_printf("Dimensions of all input images should be the same!\n"); e_printf(" First image is %ux%u, %i channels.\n",images[0].cols(),images[0].rows(),images[0].numPlanes()); e_printf(" This image is %ux%u, %i channels: %s\n",last_image.cols(),last_image.rows(),last_image.numPlanes(),argv[0]); return 2; } argc--; argv++; if (nb_input_images>1) {v_printf(2," (%i/%i) ",(int)images.size(),nb_input_images); v_printf(4,"\n");} } v_printf(2,"\n"); bool flat=true; for (Image &image : images) if (image.uses_alpha()) flat=false; if (flat && images[0].numPlanes() == 4) { v_printf(2,"Alpha channel not actually used, dropping it.\n"); for (Image &image : images) image.drop_alpha(); } uint64_t nb_pixels = (uint64_t)images[0].rows() * images[0].cols(); std::vector<std::string> desc; desc.push_back("YIQ"); // convert RGB(A) to YIQ(A) desc.push_back("BND"); // get the bounds of the color spaces if (palette_size > 0) desc.push_back("PLA"); // try palette (including alpha) if (palette_size > 0) desc.push_back("PLT"); // try palette (without alpha) if (acb == -1) { // not specified if ACB should be used if (nb_pixels > 10000) desc.push_back("ACB"); // try auto color buckets on large images } else if (acb) desc.push_back("ACB"); // try auto color buckets if forced if (method.o == Optional::undefined) { // no method specified, pick one heuristically if (nb_pixels < 10000) method.encoding=flifEncoding::nonInterlaced; // if the image is small, not much point in doing interlacing else method.encoding=flifEncoding::interlaced; // default method: interlacing } if (images.size() > 1) { desc.push_back("DUP"); // find duplicate frames desc.push_back("FRS"); // get the shapes of the frames if (lookback != 0) desc.push_back("FRA"); // make a "deep" alpha channel (negative values are transparent to some previous frame) } if (learn_repeats < 0) { // no number of repeats specified, pick a number heuristically learn_repeats = TREE_LEARN_REPEATS; if (nb_pixels < 5000) learn_repeats--; // avoid large trees for small images if (learn_repeats < 0) learn_repeats=0; } FILE *file = fopen(argv[0],"wb"); if (!file) return false; FileIO fio(file, argv[0]); return flif_encode(fio, images, desc, method.encoding, learn_repeats, acb, frame_delay, palette_size, lookback); }