EXPORT BOOL WINAPI mhsp_SWFBitmap_buf(HSPEXINFO *hei, int p2, int p3, int p4) { unsigned char *buf, *buf2; int size, size2; SWFInput input; SWFBitmap *p1; lstrcpy(funcname, "SWFBitmap_buf"); p1 = (SWFBitmap *)hei->HspFunc_prm_getv(); buf = (unsigned char *)hei->HspFunc_prm_getv(); size = hei->HspFunc_prm_geti(); buf2 = (unsigned char *)hei->HspFunc_prm_getv(); size2 = hei->HspFunc_prm_getdi(0); input = newSWFInput_allocedBuffer(buf, size); if (size2 && isJPEG(input)) { SWFInput_seek(input, 0, SEEK_SET); *p1 = (SWFBitmap)newSWFJpegWithAlpha_fromInput(input, newSWFInput_allocedBuffer(buf2, size2)); } #ifdef JAMING else if (isDBL(input) || isJPEG(input)) #else else if (isDBL(input) || isJPEG(input) || isGIF(input) || isPNG(input) || isBMP(input)) #endif { SWFInput_seek(input, 0, SEEK_SET); *p1 = newSWFBitmap_fromInput(newSWFInput_allocedBuffer(buf, size)); } else { return -1; } if (!mhsp_bitmap) { mhsp_bitmap = *p1; } return 0; }
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); }
EXPORT BOOL WINAPI mhsp_SWFBitmap(HSPEXINFO *hei, int p2, int p3, int p4) { FILE *fp1, *fp2; char filename[MHSP_STRMAX], alpha[MHSP_STRMAX]; SWFInput input; SWFBitmap *p1; lstrcpy(funcname, "SWFBitmap"); p1 = (SWFBitmap *)hei->HspFunc_prm_getv(); lstrcpyn(filename, hei->HspFunc_prm_gets(), MHSP_STRMAX); lstrcpyn(alpha, hei->HspFunc_prm_getds(""), MHSP_STRMAX); fp1 = fopen(filename, "rb"); if (!fp1) { return 1; } input = newSWFInput_file(fp1); fp2 = fopen(alpha, "rb"); if (fp2 && isJPEG(input)) { SWFInput_seek(input, 0, SEEK_SET); *p1 = (SWFBitmap)newSWFJpegWithAlpha_fromInput(input, newSWFInput_file(fp2)); } #ifdef JAMING else if (isDBL(input) || isJPEG(input)) #else else if (isDBL(input) || isJPEG(input) || isGIF(input) || isPNG(input) || isBMP(input)) #endif { SWFInput_seek(input, 0, SEEK_SET); *p1 = newSWFBitmap_fromInput(input); } else { return -1; /* 非対応フォーマット */ } if (!mhsp_bitmap) { mhsp_bitmap = *p1; } 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; }