image collapse_images_horz(image *ims, int n) { int color = 1; int border = 1; int h,w,c; int size = ims[0].h; h = size; w = (ims[0].w + border) * n - border; c = ims[0].c; if(c != 3 || !color){ h = (h+border)*c - border; c = 1; } image filters = make_image(w, h, c); int i,j; for(i = 0; i < n; ++i){ int w_offset = i*(size+border); image copy = copy_image(ims[i]); //normalize_image(copy); if(c == 3 && color){ embed_image(copy, filters, w_offset, 0); } else{ for(j = 0; j < copy.c; ++j){ int h_offset = j*(size+border); image layer = get_image_layer(copy, j); embed_image(layer, filters, w_offset, h_offset); free_image(layer); } } free_image(copy); } return filters; }
int main(int argc, char **argv) { Image<float> input(10, 10, 3); for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { input(x, y, 0) = sinf(x*y+1); input(x, y, 1) = cosf(x*y+1); input(x, y, 2) = sqrtf(x*x+y*y); } } Image<float> output(10, 10, 3); embed_image(input, output); // We expected the color channels to be flipped and multiplied by 0.5 for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { for (int c = 0; c < 3; c++) { float correct = input(x, y, 2-c) * 0.5f; if (fabs(output(x, y, c) - correct) > 0.0001f) { printf("output(%d, %d, %d) was %f instead of %f\n", x, y, c, output(x, y, c), correct); } } } } printf("Success!\n"); return 0; }
image collapse_image_layers(image source, int border) { int h = source.h; h = (h+border)*source.c - border; image dest = make_image(source.w, h, 1); int i; for(i = 0; i < source.c; ++i){ image layer = get_image_layer(source, i); int h_offset = i*(source.h+border); embed_image(layer, dest, 0, h_offset); free_image(layer); } return dest; }
int main (int argc, char **argv) { int width=640, height=480; /* default stage size */ int i; int swfcompression = DEFSWFCOMPRESSION; float framerate = 12.0; /* * Allow network access from locally-loaded movies. * * 0 = file access * 1 = network access * -1 = unspecified (omit the tag if SWF < 8, file access otherwise) * * By default is unspecified. */ int networkAccess = -1; int usedfiles = 0; struct stat statbuf; int debug_parser = 0; #ifdef HAVE_GETOPT_LONG struct option opts[] = { {"dont-preprocess", 0, 0, 'p'}, {"frame-rate", 1, 0, 'r'}, {"swfversion", 1, 0, 'v'}, {"bgcolor", 1, 0, 'b'}, {"compression", 1, 0, 'c'}, {"includepath", 1, 0, 'I'}, {"define", 1, 0, 'D'}, {"size", 1, 0, 's'}, {"network-access", 1, 0, 'n'}, {"output", 1, 0, 'o'}, {"import", 1, 0, 'i'}, {"version", 0, 0, 'V'}, {"help", 0, 0, 'h'}, {"debug", 0, 0, 'd'}, {"init-action", 1, 0, 'a'}, {0, 0, 0, 0} }; int opts_idx; #endif int c; char *me; cppargs = malloc(cppargsize); sprintf(cppargs, "%s", DEFAULT_FLAGS); //cppargs[0] = '\0'; me = argv[0]; while (1) { #define BUFSIZE 1024 char buf [BUFSIZE]; const char *optstring = "Vhpds:r:D:I:v:c:b:i:o:a:n:"; #ifdef HAVE_GETOPT_LONG c = getopt_long (argc, argv, optstring, opts, &opts_idx); #else c = getopt (argc, argv, optstring); #endif if (c == -1) break; switch (c) { case 'p': makeswf_set_dopreprocess(0); break; case 's': if ( sscanf(optarg, "%dx%d", &width, &height) != 2 ) { usage(argv[0], EXIT_FAILURE); } break; case 'n': { if ( ! strcasecmp(optarg, "network") ) { networkAccess = 1; } else if ( ! strcasecmp(optarg, "file") ) { networkAccess = 0; } else { fprintf(stderr, "Network access must be 'network' or 'file'\n"); exit(1); } break; } case 'v': if ( sscanf(optarg, "%d", &swfversion) != 1 ) { usage(argv[0], EXIT_FAILURE); } makeswf_set_swfversion(swfversion); break; case 'b': if ( sscanf(optarg, "%lx", &bgcolor) != 1 ) { usage(argv[0], EXIT_FAILURE); } useBgColor=1; break; case 'c': if ( sscanf(optarg, "%d", &swfcompression) != 1 ) { usage(argv[0], EXIT_FAILURE); } if ( swfcompression < -1 || swfcompression > 9 ) { fprintf(stderr, "Compression level must be in the range -1..9\n"); exit(1); } break; case 'r': if ( sscanf(optarg, "%f", &framerate) != 1 ) { usage(argv[0], EXIT_FAILURE); } break; case 'I': snprintf(buf, BUFSIZE-1, " -I%s", optarg); buf[BUFSIZE-1]='\0'; makeswf_append_cpparg(buf); break; case 'i': add_import_spec(optarg); break; case 'o': outputfile = optarg; break; case 'D': // yes, you can smash the stack ... snprintf(buf, BUFSIZE-1, " -D%s", optarg); buf[BUFSIZE-1]='\0'; makeswf_append_cpparg(buf); break; case 'd': debug_parser = 1; break; case 'a': add_init_action_spec(optarg); break; case 'V': printf("%s\n", RCSID); printf("Copyright (C) 2001-2006 \"Sandro Santilli\" <*****@*****.**>.\n"); printf("Released under the GNU General Public License.\n"); exit(EXIT_SUCCESS); case 'h': usage(argv[0], EXIT_SUCCESS); default: usage(argv[0], EXIT_FAILURE); break; } } argv+=optind; argc-=optind; if ( argc < 1 ) usage(me, EXIT_FAILURE); if ( stat(outputfile, &statbuf) ) { // should warn about overriding (-f ?) } if ( Ming_init() ) { fprintf(stderr, "Ming initialization error\n"); exit(EXIT_FAILURE); } Ming_setWarnFunction(warningHandler); //Ming_setErrorFunction(compileError); Ming_useSWFVersion(swfversion); Ming_setSWFCompression(swfcompression); mo = newSWFMovie(); if ( networkAccess >= 0 ) SWFMovie_setNetworkAccess(mo, networkAccess); SWFMovie_setDimension(mo, (float)width, (float)height); SWFMovie_setRate(mo, framerate); if ( useBgColor ) { SWFMovie_setBackground(mo, bgcolor >> 16, (bgcolor&0x00FF00) >> 8, (bgcolor&0x0000FF)); } printf("Output file name: %s\n", outputfile); printf("Output compression level: %d\n", swfcompression); printf("Output SWF version: %d\n", swfversion); /* * Add imports */ if ( numimport_specs ) add_imports(); for ( i=0; i<argc; i++ ) { SWFAction ac; char *filename = argv[i]; char ppfile[PATH_MAX]; FileType type = getFileType(filename); compile_init_actions(i, debug_parser); if ( type == SWF ) { printf("Adding prebuilt clip %s to frame %d... ", filename, i); embed_swf(mo, filename); } else if ( type == BITMAP ) { printf("Adding bitmap %s to frame %d... ", filename, i); embed_image(mo, filename); } else { sprintf(ppfile, "%s.frame%d.pp", outputfile, i); ac = makeswf_compile_source(filename, ppfile, debug_parser); printf("Adding %s to frame %d... ", filename, i); SWFMovie_add(mo, (SWFBlock)ac); } printf("done.\n"); usedfiles++; SWFMovie_nextFrame(mo); } if ( i <= max_init_action_frame ) { fprintf(stderr, "WARNING: following init actions for frames > %d have been discarded:\n", i-1); for (;i<=max_init_action_frame; ++i) { print_init_actions(i, stderr); } } if ( ! usedfiles ) { printf("No valid input files\n"); return 1; } printf("Saving output to %s... ", outputfile); fflush(stdout); SWFMovie_save(mo, outputfile); printf("done.\n"); return 0; }