/* * Creates a shape filled with bitmap */ SWFShape newSWFShapeFromBitmap(SWFBitmap bitmap, int flag) { SWFShape shape = newSWFShape(); SWFFillStyle fill; int width, height; if ( flag != SWFFILL_TILED_BITMAP && flag != SWFFILL_CLIPPED_BITMAP) { SWF_error("Invalid bitmap fill flag"); } fill = SWFShape_addBitmapFillStyle(shape, bitmap, flag); width = SWFBitmap_getWidth(bitmap); height = SWFBitmap_getHeight(bitmap); SWFShape_setRightFillStyle(shape, fill); // XXX - scale shouldn't be hardcoded! (here, or in newSWFBitmapFillStyle) SWFShape_drawScaledLine(shape, width * 20, 0); SWFShape_drawScaledLine(shape, 0, height * 20); SWFShape_drawScaledLine(shape, -width * 20, 0); SWFShape_drawScaledLine(shape, 0, -height * 20); return shape; }
static void embed_image(SWFMovie movie, char *f) { SWFFill fill; SWFBitmap bm; SWFShape shape; SWFMovieClip clip; SWFDisplayItem it, it2; FILE *raster; SWFInput in; int height, width; char *name; if (!(raster = fopen (f, "rb"))) { fprintf (stdout, "%s: %s\n", f, strerror (errno)); exit(1); } if (!(in = newSWFInput_file(raster))) { fprintf (stdout, "Can't create SWFInput from file\n"); exit(1); } if (!(bm = newSWFBitmap_fromInput (in))) { fprintf (stdout, "Error creating bitmap"); exit(1); } height = SWFBitmap_getHeight(bm); width = SWFBitmap_getWidth(bm); shape = newSWFShape(); SWFShape_movePenTo(shape, 0, 0); fill = SWFShape_addBitmapFill(shape, bm, SWFFILL_CLIPPED_BITMAP); SWFShape_setRightFill(shape, fill); SWFShape_drawLineTo(shape, width, 0); SWFShape_drawLineTo(shape, width, height); SWFShape_drawLineTo(shape, 0, height); SWFShape_drawLineTo(shape, 0, 0); clip = newSWFMovieClip(); it2 = SWFMovieClip_add(clip, (SWFBlock)shape); SWFMovieClip_nextFrame(clip); it = SWFMovie_add(mo, (SWFBlock)clip); name = base_name(f); SWFDisplayItem_setName(it, name); free(name); }
int main(int argc, char *argv[]) { SWFMovie m; SWFShape shape; SWFBitmap b; SWFFill fill; SWFDisplayItem i; FILE *file_bitmap; float n; float height; float width; char *imageFile = "backyard.jpg"; Ming_init(argc, argv); Ming_useSWFVersion(5); m = newSWFMovie(); shape = newSWFShape(); if(!(file_bitmap = fopen(imageFile,"rb"))) { printf("Couldn't find file '%s'", imageFile); } b = (SWFCharacter) newSWFJpegBitmap(file_bitmap); SWFMovie_setDimension(m, SWFBitmap_getWidth(b), SWFBitmap_getHeight(b)); fill = SWFShape_addBitmapFill(shape, b, SWFFILL_TILED_BITMAP); SWFShape_setRightFill(shape, fill); height = (float) SWFBitmap_getHeight(b); width = (float) SWFBitmap_getWidth(b); SWFShape_drawLineTo(shape, width, 0.00); SWFShape_drawLineTo(shape, width, height); SWFShape_drawLineTo(shape, 0.00, height); SWFShape_drawLineTo(shape, 0.00, 0.00); i = SWFMovie_add(m, (SWFBlock) shape); for(n=0; n<20.0; ++n) { SWFDisplayItem_multColor(i, 1.0- n/10.0, 1.0, 1.0, 1.0); SWFDisplayItem_addColor(i, 0xff* n/20.0, 0, 0, 0); SWFMovie_nextFrame(m); } for(n=20.0; n>0; --n) { SWFDisplayItem_multColor(i, 1.0- n/10.0, 1.0, 1.0, 1.0); SWFDisplayItem_addColor(i, 0xff* n/20.0, 0, 0, 0); SWFMovie_nextFrame(m); } SWFMovie_save(m, "cxform.swf"); fclose(file_bitmap); /* Do not close earlier or an error will happen */ return 0; }
int main(int argc, char **argv) { SWFMovie mo; SWFInput in; SWFBitmap bitmap; SWFShape shpSmt; SWFShape shpHrd; SWFMovieClip mc; SWFDisplayItem it; int swfversion; SWFFont font; SWFMovieClip dejagnuclip; char outputFilename[256]; FILE* imgfile; if ( argc < 2 ) { fprintf(stderr, "Usage: %s <swf_version>\n", argv[0]); exit(EXIT_FAILURE); } swfversion = atoi(argv[1]); sprintf(outputFilename, "BitmapSmoothingTest-v%d.swf", swfversion); /********************************************* * * Initialization * *********************************************/ puts("Setting things up"); Ming_init(); Ming_useSWFVersion (swfversion); mo = newSWFMovieWithVersion(swfversion); /**************************************************** * Create filled shapes mc ****************************************************/ imgfile = fopen(MEDIADIR"/vstroke.png", "rb"); if (!imgfile) { fprintf(stderr, "Failed to open bitmap file"); return EXIT_FAILURE; } // Note that recent ming version have the more convenient // newSWFInput_filename() function, but we want to support // older versions. in = newSWFInput_file(imgfile); bitmap = newSWFBitmap_fromInput(in); if (!bitmap) { return EXIT_FAILURE; } shpSmt = newSWFShapeFromBitmap(bitmap, SWFFILL_CLIPPED_BITMAP); shpHrd = newSWFShapeFromBitmap(bitmap, SWFFILL_NONSMOOTHED_CLIPPED_BITMAP); mc = newSWFMovieClip(); SWFMovieClip_add(mc, (SWFBlock)shpSmt); it = SWFMovieClip_add(mc, (SWFBlock)shpHrd); SWFDisplayItem_moveTo(it, 0, 5); SWFMovieClip_nextFrame(mc); /**************************************************** * Create filled shapes mc, and scale it ****************************************************/ it = SWFMovie_add(mo, (SWFBlock)mc); SWFDisplayItem_scaleTo(it, 30, 10); SWFMovie_setDimension(mo, SWFBitmap_getWidth(bitmap)*30, 500); /**************************************************** * Add dejagnu clip ****************************************************/ font = get_default_font(MEDIADIR); dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 200, 200); it = SWFMovie_add(mo, (SWFBlock)dejagnuclip); SWFDisplayItem_setDepth(it, 200); SWFDisplayItem_move(it, 0, 100); /**************************************************** * TODO: Add actions ****************************************************/ /**************************************************** * Save things up ****************************************************/ printf("Saving %s\n", outputFilename); SWFMovie_nextFrame(mo); /* showFrame */ SWFMovie_save(mo, outputFilename); fclose(imgfile); return EXIT_SUCCESS; }
EXPORT BOOL WINAPI bmp_getWidth(int *p1, int p2, int p3, int p4) { lstrcpy(funcname, "bmp_getWidth"); *p1 = SWFBitmap_getWidth(mhsp_bitmap); return 0; }