- t = swf_InsertTag(t,ST_DEFINESHAPE);
-
- swf_ShapeNew(&s);
- swf_GetMatrix(NULL,&m);
- m.sx = 20*0x10000;
- m.sy = 20*0x10000;
- fs = swf_ShapeAddBitmapFillStyle(s,&m,id,0);
-
- swf_SetU16(t,id+1); // id
-
-
- r.xmin = r.ymin = 0;
- r.xmax = cinfo.output_width*20;
- r.ymax = cinfo.output_height*20;
- swf_SetRect(t,&r);
-
- swf_SetShapeHeader(t,s);
-
- swf_ShapeSetAll(t,s,0,0,0,fs,0);
- swf_ShapeSetLine(t,s,r.xmax,0);
- swf_ShapeSetLine(t,s,0,r.ymax);
- swf_ShapeSetLine(t,s,-r.xmax,0);
- swf_ShapeSetLine(t,s,0,-r.ymax);
-
- swf_ShapeSetEnd(t);
-
- t = swf_InsertTag(t,ST_REMOVEOBJECT2);
- swf_SetU16(t,1); // depth
-
- t = swf_InsertTag(t,ST_PLACEOBJECT2);
-
- swf_GetMatrix(NULL,&m);
- m.tx = (swf->movieSize.xmax-(int)cinfo.output_width*20)/2;
- m.ty = (swf->movieSize.ymax-(int)cinfo.output_height*20)/2;
- swf_ObjectPlace(t,id+1,1,&m,NULL,NULL);
-
- t = swf_InsertTag(t,ST_SHOWFRAME);
-
- jpeg_finish_decompress(&cinfo);
- fclose(f);
-
- return t;
+ for (y=0;y<cinfo.output_height;y++) {
+ int x;
+ jpeg_read_scanlines(&cinfo,&buf,1);
+
+ if(cinfo.out_color_space == JCS_GRAYSCALE) {
+ for(x=0;x<cinfo.output_width;x++) {
+ js[x].r = js[x].g = js[x].b = buf[x];
+ }
+ } else if(cinfo.out_color_space == JCS_RGB) {
+ for (x=0;x<cinfo.output_width;x++)
+ {
+ js[x].r = buf[x*3+0];
+ js[x].g = buf[x*3+1];
+ js[x].b = buf[x*3+2];
+ }
+ } else if(cinfo.out_color_space == JCS_YCCK) {
+ //FIXME
+ fprintf(stderr, "Error: Can't convert YCCK to RGB.\n");
+ return -1;
+ } else if(cinfo.out_color_space == JCS_YCbCr) {
+ for(x=0;x<cinfo.output_width;x++) {
+ int y = buf[x*3+0];
+ int u = buf[x*3+1];
+ int v = buf[x*3+1];
+ js[x].r = y + ((360*(v-128))>>8);
+ js[x].g = y - ((88*(u-128)+183*(v-128))>>8);
+ js[x].b = y + ((455 * (u-128))>>8);
+ }
+ }
+ else if(cinfo.out_color_space == JCS_CMYK)
+ {
+ for(x=0;x<cinfo.output_width;x++) {
+ int white = 255 - buf[x*4+3];
+ js[x].r = white - ((buf[x*4]*white)>>8);
+ js[x].g = white - ((buf[x*4+1]*white)>>8);
+ js[x].b = white - ((buf[x*4+2]*white)>>8);
+ }
+ }
+ js += cinfo.output_width;
+ }
+
+ jpeg_finish_decompress(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+
+ free(buf);
+ *pic2 = pic;
+ return 1;
+}
+
+
+int frame = 0;
+TAG *MovieAddFrame(SWF * swf, TAG * t, char *sname, int quality,
+ int width, int height)
+{
+ SHAPE *s;
+ SRECT r;
+ MATRIX m;
+ int fs;
+ int movie_width = swf->movieSize.xmax - swf->movieSize.xmin;
+ int movie_height = swf->movieSize.ymax - swf->movieSize.ymin;
+
+ if(global.mx) {
+ int sizex, sizey;
+ RGBA * pic2;
+ SWFPLACEOBJECT obj;
+ int quant=0;
+ getJPEG(sname, &sizex, &sizey, &pic2);
+ if(sizex != stream.owidth || sizey != stream.oheight) {
+ fprintf(stderr, "All images must have the same dimensions if using -m!");
+ exit(1);
+ }
+
+ t = swf_InsertTag(t, ST_VIDEOFRAME);
+ swf_SetU16(t, 0xf00d);
+ quant = 1+(30-(30*quality)/100);
+ if(!(frame%20)) {
+ swf_SetVideoStreamIFrame(t, &stream, pic2, quant);
+ } else {
+ swf_SetVideoStreamPFrame(t, &stream, pic2, quant);
+ }
+
+ t = swf_InsertTag(t, ST_PLACEOBJECT2);
+ swf_GetPlaceObject(0, &obj);
+ if(frame==0) {
+ obj.depth = 1;
+ obj.id = 0xf00d;
+ } else {
+ obj.depth = 1;
+ obj.move = 1;
+ obj.ratio = frame;
+ }
+ swf_SetPlaceObject(t,&obj);
+
+ t = swf_InsertTag(t, ST_SHOWFRAME);
+ } else {
+ t = swf_InsertTag(t, ST_DEFINEBITSJPEG2);
+ swf_SetU16(t, global.next_id); // id
+ swf_SetJPEGBits(t,sname,quality);
+
+ t = swf_InsertTag(t, ST_DEFINESHAPE);
+ swf_ShapeNew(&s);
+ swf_GetMatrix(NULL, &m);
+ if (global.fit_to_movie) {
+ m.sx = 0x10000 * movie_width / width;
+ m.sy = 0x10000 * movie_height / height;
+ width = movie_width / 20;
+ height = movie_height / 20;
+ } else {
+ m.sx = 20 * 0x10000;
+ m.sy = 20 * 0x10000;
+ }
+ m.tx = 0;
+ m.ty = 0;
+ fs = swf_ShapeAddBitmapFillStyle(s, &m, global.next_id, 1);
+ global.next_id++;
+ swf_SetU16(t, global.next_id); // id
+ r.xmin = 0;
+ r.ymin = 0;
+ r.xmax = r.xmin + width * 20;
+ r.ymax = r.ymin + height * 20;
+ swf_SetRect(t, &r);
+ swf_SetShapeHeader(t, s);
+ swf_ShapeSetAll(t, s, r.xmin, r.ymin, 0, fs, 0);
+ swf_ShapeSetLine(t, s, r.xmax - r.xmin, 0);
+ swf_ShapeSetLine(t, s, 0, r.ymax - r.ymin);
+ swf_ShapeSetLine(t, s, -r.xmax + r.xmin, 0);
+ swf_ShapeSetLine(t, s, 0, -r.ymax + r.ymin);
+ swf_ShapeSetEnd(t);
+
+ if(frame) {
+ t = swf_InsertTag(t, ST_REMOVEOBJECT2);
+ swf_SetU16(t, 1); // depth
+ }
+
+ t = swf_InsertTag(t, ST_PLACEOBJECT2);
+ swf_GetMatrix(NULL, &m);
+ m.sx = (int)(0x10000 * global.scale);
+ m.sy = (int)(0x10000 * global.scale);
+
+ if(custom_move) {
+ m.tx = move_x*20;
+ m.ty = move_y*20;
+ } else {
+ m.tx = (movie_width - (width * global.scale * 20)) / 2;
+ m.ty = (movie_height - (height * global.scale * 20)) / 2;
+ }
+ swf_ObjectPlace(t, global.next_id, 1, &m, NULL, NULL);
+ global.next_id++;
+ t = swf_InsertTag(t, ST_SHOWFRAME);
+ }
+ frame++;
+
+ return t;