X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=src%2Fjpeg2swf.c;h=a9a413caeabfbe774395289cdec6ed705f519785;hp=6483a8228fe0263e77f8380d5a0f025c38b75c75;hb=0e8807d9a620e8932bc67653321eaae1436fdd43;hpb=e448c7a56df8e289c9dbd5b8d87753addd541091 diff --git a/src/jpeg2swf.c b/src/jpeg2swf.c index 6483a82..a9a413c 100644 --- a/src/jpeg2swf.c +++ b/src/jpeg2swf.c @@ -27,12 +27,18 @@ struct int max_image_height; int force_width; int force_height; + int prescale; int nfiles; int verbose; - char * files[MAX_INPUT_FILES]; char * outfile; } global; +struct +{ char * filename; + int scale; + int quality; +} image[MAX_INPUT_FILES]; + TAG * MovieStart(SWF * swf,int framerate,int dx,int dy) { TAG * t; RGBA rgb; @@ -58,7 +64,7 @@ int MovieFinish(SWF * swf,TAG * t,char * sname) if ((!isatty(so))&&(!sname)) handle = so; else - { if (!sname) sname = "out.swf"; + { if (!sname) sname = "output.swf"; handle = open(sname,O_RDWR|O_CREAT|O_TRUNC,0666); } if FAILED(swf_WriteSWF(handle,swf)) if (VERBOSE(1)) fprintf(stderr,"Unable to write output file: %s\n",sname); @@ -68,7 +74,7 @@ int MovieFinish(SWF * swf,TAG * t,char * sname) return 0; } -TAG * MovieAddFrame(SWF * swf,TAG * t,char * sname,int quality,int id) +TAG * MovieAddFrame(SWF * swf,TAG * t,char * sname,int quality,int scale,int id) { SHAPE * s; SRECT r; MATRIX m; @@ -89,6 +95,12 @@ TAG * MovieAddFrame(SWF * swf,TAG * t,char * sname,int quality,int id) jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo,f); jpeg_read_header(&cinfo, TRUE); + + if (scale>1) + { cinfo.scale_num = 1; + cinfo.scale_denom = scale; + } + jpeg_start_decompress(&cinfo); t = swf_InsertTag(t,ST_DEFINEBITSJPEG2); @@ -97,14 +109,30 @@ TAG * MovieAddFrame(SWF * swf,TAG * t,char * sname,int quality,int id) out = swf_SetJPEGBitsStart(t,cinfo.output_width,cinfo.output_height,quality); scanline = (U8*)malloc(4*cinfo.output_width); - + + // the following code is a duplication of swf_SetJPEGBits in ../lib/modules/swfbits.c if (scanline) { int y; U8 * js = scanline; - for (y=0;y=0;x--) { + js[x*3] = js[x*3+1] = js[x*3+2] = js[x]; + } + swf_SetJPEGBitsLines(out,(U8**)&js,1); + } + } + else if(cinfo.out_color_space == JCS_RGB) + { + for (y=0;y1) + { cinfo.scale_num = 1; + cinfo.scale_denom = global.prescale; + + jpeg_calc_output_dimensions(&cinfo); + + width = cinfo.output_width; + height = cinfo.output_height; + } + else + { width = cinfo.image_width; + height = cinfo.image_height; + } + // Get image dimensions - if (global.max_image_width=MAX_INPUT_FILES) { if (VERBOSE(1)) fprintf(stderr, "Error: Too many input files.\n"); @@ -278,14 +337,16 @@ int args_callback_command(char*arg,char*next) // actually used as filename } void args_callback_usage(char*name) -{ fprintf(stderr,"Usage: %s imagefiles[.jpg]|[.jpeg] [...] [-options [value]]\n",name); +{ fprintf(stderr,"Usage: %s [-options [value]] imagefiles[.jpg]|[.jpeg] [...]\n",name); fprintf(stderr,"-q quality (quality) Set JPEG compression quality (1-100)\n"); + fprintf(stderr,"-s denominator (scale) 2, 4 or 8: Reduce image size to 1/2, 1/4, 1/8\n"); fprintf(stderr,"-r framerate (rate) Set movie framerate (100/sec)\n"); fprintf(stderr,"-o outputfile (output) Set name for SWF output file\n"); - fprintf(stderr,"-v level (verbose) Set verbose level (0=quiet, 1=default, 2=debug)\n"); fprintf(stderr,"-X pixel (width) Force movie width to scale (default: autodetect)\n"); fprintf(stderr,"-Y pixel (height) Force movie height to scale (default: autodetect)\n"); + fprintf(stderr,"-v level (verbose) Set verbose level (0=quiet, 1=default, 2=debug)\n"); fprintf(stderr,"-V (version) Print version information and exit\n"); + fprintf(stderr,"The following options can be set independently for each image: -q -s\n"); } @@ -298,6 +359,7 @@ int main(int argc, char ** argv) global.quality = 60; global.framerate = 100; global.verbose = 1; + global.prescale = 1; processargs(argc, argv); @@ -309,9 +371,11 @@ int main(int argc, char ** argv) { int i; for (i=0;i