免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 13169 | 回复: 25
打印 上一主题 下一主题

技术宅。Bad Apple 在 linux 中 字符 动画已完成。[内有观看地址] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-10-09 23:48 |只看该作者 |倒序浏览
地址在此: http://bad-apple.no-ip.org


这是我自己架设的网站服务器,所以网速可能不尽人意。

我上传youku 后 ,会附加上 youku 地址 。。。

制作方法:

1,mplayer -vo jpeg bad_apple.flv

     将bad apple 的视频一帧一帧的截取出来。

2,写一个shell脚本,然后执行。
  1. #!/bin/bash
  2. pa="../tif/"
  3. for var in `ls | grep jpg`
  4. do
  5.     convert -sample 120 `echo $var` `echo $pa$var|sed 's/...$/tif/'`
  6. done
复制代码
将所有的jpg图片 转成tif 图片,并且移动到 ../tif/ 目录中。


3,写一个程序,将tif图片转成纯 ansii 文件。(需要shell脚本配合执行)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <tiffio.h>
  4. #include <string.h>
  5. int main (int argc,char *argv[])
  6. {
  7.     TIFF *image;
  8.     FILE *file;
  9.     uint16 photo,bps,spp;
  10.     uint32 width,height;
  11.     char *buffer;
  12.     tsize_t strip_size;
  13.     unsigned long image_size,image_offset,res,count;
  14.     int strip_max,strip_count,m=0,n=0,rgb=0,argv_len;
  15.     char *new,*add="-ansii",ansi;
  16.     argv_len=strlen(argv[1]);
  17.     if((new=(char *)malloc(sizeof(char)*(argv_len+3)))==NULL)
  18.     {
  19.         perror("malloc failure\n");exit(1);
  20.     }
  21.     strncpy(new,argv[1],strlen(argv[1])-4);
  22.     strcat(new,add);
  23.     //printf("%s\n",new);
  24.     if((file=fopen(new,"w"))==NULL)
  25.     {
  26.         perror("Creat File Failure\n");exit(1);
  27.     }
  28.     if((image=TIFFOpen(argv[1],"r"))==NULL)
  29.     {
  30.         perror("Can't open image\n");exit(1);
  31.     }
  32.     if(TIFFGetField(image,TIFFTAG_BITSPERSAMPLE,&bps)==0 ||
  33.        TIFFGetField(image,TIFFTAG_SAMPLESPERPIXEL,&spp)==0 ||
  34.        TIFFGetField(image,TIFFTAG_PHOTOMETRIC,&photo)==0
  35.     )
  36.     {
  37.         perror("Unsupported file\n");exit(1);
  38.     }
  39.     TIFFGetField(image,TIFFTAG_IMAGEWIDTH,&width);
  40.     TIFFGetField(image,TIFFTAG_IMAGELENGTH,&height);
  41.     image_size=height*width*spp+1;
  42.     strip_size=TIFFStripSize(image);
  43.     strip_max=TIFFNumberOfStrips(image);
  44.     image_offset=0;
  45.     if((buffer=(char *)_TIFFmalloc(sizeof(unsigned long)*image_size))==NULL)
  46.     {
  47.         perror("Malloc failure\n");exit(1);
  48.     }
  49.     for(strip_count=0;strip_count<strip_max;strip_count++)
  50.     {
  51.         if((res=TIFFReadEncodedStrip(image,strip_count,buffer+image_offset,strip_size))==-1)
  52.         {
  53.         perror("Read Error\n");exit(1);
  54.         }
  55.         image_offset+=res;
  56.     }
  57.         for(count=0;count<image_size-1;count++)
  58.             {
  59.             ++m;
  60.             rgb+=buffer[count];
  61.             if(m==spp)
  62.                 {
  63.                 ++n;
  64.                 ansi=rgb>=0?'@':' ';
  65.                 fputc(ansi,file);
  66.                 fputc(ansi,file);
  67.                 if(n==width) {fputc('\n',file);n=0;}
  68.                 rgb=0;
  69.                 m=0;
  70.                 }
  71.             }
  72.     TIFFClose(image);
  73.     _TIFFfree(buffer);
  74.     fclose(file);
  75.     free(new);
  76.     exit(0);
  77. }
复制代码
因为我先研究的tiff图片,所以就先入为主了。不想再去研究jpeg  png 等图片。如果我要是会jpeg png 编程的话 ,就可以省去第二步。

同样,将生成的 纯ansii文件 存在 ../ansii 中。


4, 写一个程序,来还原动画。原理很简单,就是不断的读入那些 ansii 文件,显示,然后清屏。。。就这样不断循环,保持和原视频同样的帧率。
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <curses.h>
  6. #include <time.h>
  7. #include <sys/time.h>

  8. void stop (int usec)
  9. {
  10.     struct timeval tv;
  11.     tv.tv_sec=0;
  12.     tv.tv_usec=usec;
  13.     select(0,NULL,NULL,NULL,&tv);
  14. }
  15. int main ()
  16. {
  17.     int a[8]={0,0,0,0,0,0,0,0},n;
  18.     char name[]={'.','/','a','n','s','i','i','/','a','a','a','a','a','a','a','a','-','a','n','s','i','i'};
  19.     char *vul="0123456789",*buffer;
  20.     FILE *souce_file;
  21.     WINDOW *apple;
  22.     initscr();noecho();curs_set(0);
  23.     clear();
  24.     if(COLS<240 || LINES<90)
  25.     {
  26.         mvprintw(LINES/2,COLS/2-24,"Your screen is NOT big enough.X=%d<240.Y=%d<90\n",COLS,LINES);
  27.         refresh();sleep(3);endwin();exit(0);
  28.     }
  29.     if((apple=newwin(90,241,LINES/2-45,COLS/2-120))==NULL)
  30.     {
  31.         perror("Creat Window Failure\n");endwin();exit(1);
  32.     }

  33.     if((buffer=(char *)malloc(sizeof(char)*241*90))==NULL)
  34.     {
  35.         perror("Malloc Failure\n");delwin(apple);endwin();exit(1);
  36.     }
  37.     *(buffer+241*90-1)='\0';
  38.     while(1)
  39.     {
  40.         wmove(apple,0,0);
  41.         ++a[7];
  42.         for(n=7;n>0;n--)
  43.         {
  44.             if(a[n]>9)
  45.             {
  46.                 a[n]%=10;
  47.                 ++a[n-1];
  48.             }
  49.             if(a[n-1]<10) break;
  50.         }
  51.         for(n=0;n<8;n++)
  52.             *(name+8+n)=*(vul+a[n]);
  53.         if((souce_file=fopen(name,"r"))==NULL) break;
  54.         for(n=0;n<241*90-1;n++)
  55.             buffer[n]=fgetc(souce_file);
  56.         fclose(souce_file);
  57.         wprintw(apple,"%s",buffer);
  58.         wrefresh(apple);
  59.         stop(64000);
  60.     }
  61.     sleep(1);
  62.     free(buffer);
  63.     delwin(apple);
  64.     endwin();
  65.     exit(0);
  66. }
复制代码
完.

论坛徽章:
0
2 [报告]
发表于 2010-10-10 09:41 |只看该作者
呵呵,友情帮顶。
支持

论坛徽章:
0
3 [报告]
发表于 2010-10-10 12:33 |只看该作者
上午停电了 ,早上很多人都反应打不开网址。。。

论坛徽章:
0
4 [报告]
发表于 2010-10-10 18:34 |只看该作者
定 大牛!

论坛徽章:
0
5 [报告]
发表于 2010-10-10 18:58 |只看该作者
认识的一个人做了一个字符的bad apple os~

论坛徽章:
0
6 [报告]
发表于 2010-10-10 22:03 |只看该作者
认识的一个人做了一个字符的bad apple os~
davelv 发表于 2010-10-10 18:58




什么???


可有连接?

论坛徽章:
0
7 [报告]
发表于 2010-10-10 22:07 |只看该作者

论坛徽章:
0
8 [报告]
发表于 2010-10-10 22:19 |只看该作者
davelv 发表于 2010-10-10 22:07



   
感谢

论坛徽章:
0
9 [报告]
发表于 2010-10-10 22:24 |只看该作者
怎么看效果? 一片漆黑。。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
10 [报告]
发表于 2010-10-10 22:26 |只看该作者
真牛逼
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP