void intro_csv() { int i; int sn; int r, g, b; /* define those as static, or the compiler optimizes the stack a bit too much */ static struct tmu_td tmu_task; static struct tmu_vertex src_vertices[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex dst_vertices[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; tmu_task.flags = 0; tmu_task.hmeshlast = HMESHLAST; tmu_task.vmeshlast = VMESHLAST; tmu_task.brightness = 62; tmu_task.chromakey = 0; tmu_task.srcmesh = &src_vertices[0][0]; tmu_task.srchres = vga_hres; tmu_task.srcvres = vga_vres; tmu_task.dstmesh = &dst_vertices[0][0]; tmu_task.dsthres = vga_hres; tmu_task.dstvres = vga_vres; tmu_task.profile = 0; tmu_task.callback = tmu_complete; tmu_task.user = NULL; make_mesh(&src_vertices[0][0], &dst_vertices[0][0], 100000); sn = 0; for(i=0;i<DURATION;i++) { tmu_task.srcfbuf = vga_frontbuffer; tmu_task.dstfbuf = vga_backbuffer; if(i > (DURATION/3)) make_mesh(&src_vertices[0][0], &dst_vertices[0][0], 100000-(4000*(i-DURATION/3)/DURATION)); if(i > (DURATION/2)) { r = 2*(DURATION-(i-DURATION/2))/DURATION; g = 63*(DURATION-(i-DURATION/2))/DURATION; b = 0; } else { r = 2; g = 63; b = 0; } tmu_wait = 0; tmu_submit_task(&tmu_task); while(!tmu_wait); if((rand() % 4) == 0) { draw_text((rand() % vga_hres) + 1 , (rand() % vga_vres) + 2, MAKERGB565(r, g, b), csv_strings[sn]); sn++; if(sn == NSTRINGS) sn = 0; flush_bridge_cache(); } vga_swap_buffers(); } for(i=0;i<POST;i++) { tmu_task.srcfbuf = vga_frontbuffer; tmu_task.dstfbuf = vga_backbuffer; tmu_wait = 0; tmu_submit_task(&tmu_task); while(!tmu_wait); vga_swap_buffers(); } }
int main(int argc, char *argv[]) { char *finname; char *foutname; char *c; FILE *fin, *fout; gdImagePtr im; int x, y; if(argc != 2) { fprintf(stderr, "Usage: %s <file.png>\n", argv[0]); return 1; } finname = argv[1]; foutname = strdup(finname); if(!foutname) { perror("strdup"); return 1; } c = strrchr(foutname, '.'); if(!c || strcasecmp(c, ".png")) { fprintf(stderr, "Incorrect filename - must end with '.png'\n"); free(foutname); return 1; } c[1] = 'r'; c[2] = 'a'; c[3] = 'w'; fin = fopen(finname, "rb"); if(!fin) { perror("Unable to open input file"); free(foutname); return 1; } fout = fopen(foutname, "wb"); if(!fout) { perror("Unable to open output file"); free(foutname); return 1; } im = gdImageCreateFromPng(fin); if(!im) { fprintf(stderr, "Unable to read PNG format\n"); return 1; } for(y=0;y<gdImageSY(im);y++) for(x=0;x<gdImageSX(im);x++) { int c; unsigned short int o; c = gdImageGetPixel(im, x, y); o = MAKERGB565(gdImageRed(im, c), gdImageGreen(im, c), gdImageBlue(im, c)); o = HTOBE(o); fwrite(&o, 2, 1, fout); } fclose(fin); if(fclose(fout) != 0) { perror("fclose"); gdImageDestroy(im); free(foutname); return 1; } gdImageDestroy(im); free(foutname); return 0; }