From 0534ee54aaf7fc82a1f8b4f565e1e277619173d6 Mon Sep 17 00:00:00 2001 From: kramm Date: Mon, 22 Oct 2001 15:37:03 +0000 Subject: [PATCH] added new tool (jpeg2swf) --- src/Makefile.am | 7 +- src/Makefile.in | 24 ++- src/jpeg2swf.1 | 43 ++++++ src/jpeg2swf.c | 442 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 506 insertions(+), 10 deletions(-) create mode 100644 src/jpeg2swf.1 create mode 100644 src/jpeg2swf.c diff --git a/src/Makefile.am b/src/Makefile.am index 6b50cee..1b9426b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,13 +1,12 @@ ## Process this file with automake to produce Makefile.in -bin_PROGRAMS = swfcombine swfstrings swfdump +bin_PROGRAMS = swfcombine swfstrings swfdump jpeg2swf +jpeg2swf_SOURCES = jpeg2swf.c swfdump_SOURCES = swfdump.c swfcombine_SOURCES = bitio.c bitio.h reloc.c reloc.h combine.c combine.h flash.c flash.h swfcombine.c types.h swfstrings_SOURCES = swfstrings.c +jpeg2swf_LINK = $(CCLD) ../lib/rfxswf.o -o $@ swfdump_LINK = $(CCLD) ../lib/rfxswf.o -o $@ swfcombine_LINK = $(CCLD) ../lib/log.o -o $@ swfstrings_LINK = $(CCLD) ../lib/log.o ../lib/rfxswf.o -o $@ -##LIBS = -##swfcombine_LIBS = -##swfstrings_LIBS = -ljpeg man_MANS = swfcombine.1 swfstrings.1 swfdump.1 diff --git a/src/Makefile.in b/src/Makefile.in index d87977b..3843b14 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -69,10 +69,12 @@ PACKAGE = @PACKAGE@ RANLIB = @RANLIB@ VERSION = @VERSION@ -bin_PROGRAMS = swfcombine swfstrings swfdump +bin_PROGRAMS = swfcombine swfstrings swfdump jpeg2swf +jpeg2swf_SOURCES = jpeg2swf.c swfdump_SOURCES = swfdump.c swfcombine_SOURCES = bitio.c bitio.h reloc.c reloc.h combine.c combine.h flash.c flash.h swfcombine.c types.h swfstrings_SOURCES = swfstrings.c +jpeg2swf_LINK = $(CCLD) ../lib/rfxswf.o -o $@ swfdump_LINK = $(CCLD) ../lib/rfxswf.o -o $@ swfcombine_LINK = $(CCLD) ../lib/log.o -o $@ swfstrings_LINK = $(CCLD) ../lib/log.o ../lib/rfxswf.o -o $@ @@ -80,7 +82,8 @@ man_MANS = swfcombine.1 swfstrings.1 swfdump.1 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = -bin_PROGRAMS = swfcombine$(EXEEXT) swfstrings$(EXEEXT) swfdump$(EXEEXT) +bin_PROGRAMS = swfcombine$(EXEEXT) swfstrings$(EXEEXT) swfdump$(EXEEXT) \ +jpeg2swf$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) @@ -100,6 +103,10 @@ swfdump_OBJECTS = swfdump.o swfdump_LDADD = $(LDADD) swfdump_DEPENDENCIES = swfdump_LDFLAGS = +jpeg2swf_OBJECTS = jpeg2swf.o +jpeg2swf_LDADD = $(LDADD) +jpeg2swf_DEPENDENCIES = +jpeg2swf_LDFLAGS = CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) @@ -115,10 +122,11 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP_ENV = --best -DEP_FILES = .deps/bitio.P .deps/combine.P .deps/flash.P .deps/reloc.P \ -.deps/swfcombine.P .deps/swfdump.P .deps/swfstrings.P -SOURCES = $(swfcombine_SOURCES) $(swfstrings_SOURCES) $(swfdump_SOURCES) -OBJECTS = $(swfcombine_OBJECTS) $(swfstrings_OBJECTS) $(swfdump_OBJECTS) +DEP_FILES = .deps/bitio.P .deps/combine.P .deps/flash.P \ +.deps/jpeg2swf.P .deps/reloc.P .deps/swfcombine.P .deps/swfdump.P \ +.deps/swfstrings.P +SOURCES = $(swfcombine_SOURCES) $(swfstrings_SOURCES) $(swfdump_SOURCES) $(jpeg2swf_SOURCES) +OBJECTS = $(swfcombine_OBJECTS) $(swfstrings_OBJECTS) $(swfdump_OBJECTS) $(jpeg2swf_OBJECTS) all: all-redirect .SUFFIXES: @@ -184,6 +192,10 @@ swfdump$(EXEEXT): $(swfdump_OBJECTS) $(swfdump_DEPENDENCIES) @rm -f swfdump$(EXEEXT) $(swfdump_LINK) $(swfdump_LDFLAGS) $(swfdump_OBJECTS) $(swfdump_LDADD) $(LIBS) +jpeg2swf$(EXEEXT): $(jpeg2swf_OBJECTS) $(jpeg2swf_DEPENDENCIES) + @rm -f jpeg2swf$(EXEEXT) + $(jpeg2swf_LINK) $(jpeg2swf_LDFLAGS) $(jpeg2swf_OBJECTS) $(jpeg2swf_LDADD) $(LIBS) + install-man1: $(mkinstalldirs) $(DESTDIR)$(man1dir) @list='$(man1_MANS)'; \ diff --git a/src/jpeg2swf.1 b/src/jpeg2swf.1 new file mode 100644 index 0000000..3b0af78 --- /dev/null +++ b/src/jpeg2swf.1 @@ -0,0 +1,43 @@ +.TH jpeg2swf "1" "October 2001" "jpeg2swf" "swftools" +.SH NAME +jpeg2swf - convert one or more pictures to swf +.SH Synopsis +.B jpeg2swf +.SH DESCRIPTION +Takes a number of jpeg files and converts them to a swf movie, one +picture per frame. +.PP +(SWF files are animation files which can be displayed in Web Browsers using +the Flash Plugin) +.SH OPTIONS +.TP +\fB\-h\fR, \fB\-\-help\fR +Print short help message and exit +.TP +\fR\-V\fR, \fB\-\-version\fR +Print version info and exit +.TP +\fB\-o\fR, \fB\-\-output\fR \fIfilename\fR +Explicitly specify output file. (Otherwise, output will go to stdout) +.TP +\fB\-q\fR, \fB\-\-quality\fR \fIquality\fR +Set JPEG compression quality (1-100) +.TP +\fB\-r\fR, \fB\-\-framerate\fR \fIrate\fR +Set movie framerate (100/sec) +.TP +\fB\-v\fR, \fB\-\-verbose\fR \fIlevel\fR +Set verbosity level (0=quiet, 1=default, 2=debug) +.TP +\fB\-X\fR, \fB\-\-width\fR \fIscale\fR +Force movie width to \fIscale\fR (default: autodetect) +.TP +\fB\-Y\fR, \fB\-\-height\fR \fIscale\fR +Force movie height to \fIscale\fR (default: autodetect) + +.SH AUTHORS + +Rainer Böhme +.TP +Matthias Kramm + diff --git a/src/jpeg2swf.c b/src/jpeg2swf.c new file mode 100644 index 0000000..17e6226 --- /dev/null +++ b/src/jpeg2swf.c @@ -0,0 +1,442 @@ +/* jpeg2swf.c + + JPEG to SWF converter tool + + Part of the swftools package. + + Copyright (c) 2001 Rainer Böhme + + This file is distributed under the GPL, see file COPYING for details + +*/ + +#include +#include +#include +#include +#include "../lib/rfxswf.h" + +#include "args.h" // not really a header ;-) + +#define MAX_INPUT_FILES 1024 +#define VERBOSE(x) (global.verbose>=x) + +struct +{ int quality; + int framerate; + int max_image_width; + int max_image_height; + int force_width; + int force_height; + int nfiles; + int verbose; + char * files[MAX_INPUT_FILES]; + char * outfile; +} global; + +TAG * MovieStart(SWF * swf,int framerate,int dx,int dy) +{ TAG * t; + RGBA rgb; + + memset(swf,0x00,sizeof(SWF)); + + swf->FileVersion = 4; + swf->FrameRate = (25600/framerate); + swf->MovieSize.xmax = dx*20; + swf->MovieSize.ymax = dy*20; + + t = swf->FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + + rgb.r = rgb.g = rgb.b = rgb.a = 0x00; + SetRGB(t,&rgb); + + return t; +} + +int MovieFinish(SWF * swf,TAG * t,char * sname) +{ int handle, so = fileno(stdout); + t = InsertTag(t,ST_END); + + if ((!isatty(so))&&(!sname)) handle = so; + else + { if (!sname) sname = "out.swf"; + handle = open(sname,O_RDWR|O_CREAT|O_TRUNC,0666); + } + if FAILED(WriteSWF(handle,swf)) if (VERBOSE(1)) fprintf(stderr,"Unable to write output file: %s\n",sname); + if (handle!=so) close(handle); + + FreeTags(swf); + return 0; +} + +TAG * MovieAddFrame(SWF * swf,TAG * t,char * sname,int quality,int id) +{ SHAPE * s; + SRECT r; + MATRIX m; + int fs; + + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + LPJPEGBITS out; + FILE * f; + U8 * scanline; + + if ((f=fopen(sname,"rb"))==NULL) + { if (VERBOSE(1)) fprintf(stderr,"Read access failed: %s\n",sname); + return t; + } + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo,f); + jpeg_read_header(&cinfo, TRUE); + jpeg_start_decompress(&cinfo); + + t = InsertTag(t,ST_DEFINEBITSJPEG2); + + SetU16(t,id); // id + + out = SetJPEGBitsStart(t,cinfo.output_width,cinfo.output_height,quality); + scanline = (U8*)malloc(4*cinfo.output_width); + + if (scanline) + { int y; + U8 * js = scanline; + for (y=0;yMovieSize.xmax-(int)cinfo.output_width*20)/2; + m.ty = (swf->MovieSize.ymax-(int)cinfo.output_height*20)/2; + ObjectPlace(t,id+1,1,&m,NULL,NULL); + + t = InsertTag(t,ST_SHOWFRAME); + + jpeg_finish_decompress(&cinfo); + fclose(f); + + return t; +} + +int CheckInputFile(char * fname,char ** realname) +{ struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + FILE * f; + char * s = malloc(strlen(fname)+5); + + if (!s) exit(2); + (*realname) = s; + strcpy(s,fname); + + // Check whether file exists (with typical extensions) + + if ((f=fopen(s,"rb"))==NULL) + { sprintf(s,"%s.jpg",fname); + if ((f=fopen(s,"rb"))==NULL) + { sprintf(s,"%s.jpeg",fname); + if ((f=fopen(s,"rb"))==NULL) + { sprintf(s,"%s.JPG",fname); + if ((f=fopen(s,"rb"))==NULL) + { sprintf(s,"%s.JPEG",fname); + if ((f=fopen(s,"rb"))==NULL) + return 0; + } + } + } + } + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo,f); + jpeg_read_header(&cinfo, TRUE); + + // Get image dimensions + + if (global.max_image_width100)) + { if (VERBOSE(1)) fprintf(stderr,"Error: You must specify a valid quality between 1 and 100.\n"); + exit(1); + } + res = 1; + break; + + case 'r': + if (val) global.framerate = atoi(val); + if ((global.framerate<1)||(global.framerate>5000)) + { if (VERBOSE(1)) fprintf(stderr,"Error: You must specify a valid framerate between 1 and 10000.\n"); + exit(1); + } + res = 1; + break; + + case 'o': + if (val) global.outfile = val; res = 1; break; + + case 'v': + if (val) global.verbose = atoi(val); res = 1; break; + + case 'X': + if (val) global.force_width = atoi(val); res = 1; break; + + case 'Y': + if (val) global.force_height = atoi(val); res = 1; break; + + case 'V': + printf("jpeg2swf - part of swftools 0.0.1\n");exit(0); + + default: + res = -1; + break; + } + + if (res<0) + { if (VERBOSE(1)) fprintf(stderr,"Unknown option: -v%s\n",arg); + return 0; + } + return res; +} + +struct options_t +{ char*shortoption; + char*longoption; +} options[] = +{{"q","quality"}, + {"o","output"}, + {"r","rate"}, + {"v","verbose"}, + {"X","width"}, + {"Y","height"}, + {"v","verbose"}, + {"V","version"} +}; + +int args_callback_longoption(char*name,char*val) { + int t; + for(t=0;t=MAX_INPUT_FILES) + { if (VERBOSE(1)) fprintf(stderr, "Error: Too many input files.\n"); + exit(1); + } + } + return 0; +} + +void args_callback_usage(char*name) +{ fprintf(stderr,"Usage: %s imagefiles[.jpg]|[.jpeg] [...] [-options [value]]\n",name); + fprintf(stderr,"-q quality (quality) Set JPEG compression quality (1-100)\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 (version) Print version information and exit\n"); +} + + +int main(int argc, char ** argv) +{ SWF swf; + TAG * t; + + memset(&global,0x00,sizeof(global)); + + global.quality = 60; + global.framerate = 100; + global.verbose = 1; + + processargs(argc, argv); + + if (VERBOSE(2)) fprintf(stderr,"Processing %i file(s)...\n",global.nfiles); + + t = MovieStart(&swf,global.framerate, + global.force_width?global.force_width:global.max_image_width, + global.force_height?global.force_height:global.max_image_height); + + { int i; + for (i=0;i