Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<menuet/os.h>
  4. #include<mpeg.h>
  5.  
  6. ImageDesc I;
  7. FILE * fmpeg=NULL;
  8.  
  9. char * vblit_buffer=NULL;
  10. char * bitmap_buffer=NULL;
  11. int line_width;
  12.  
  13. int blit_x_offs=0;
  14. int blit_y_offs=0;
  15.  
  16. int win_size_x=0;
  17. int win_size_y=0;
  18.  
  19. unsigned long inter_frame_delay;
  20.  
  21. char player_window_title[256];
  22. char loaded_file_name[256];
  23.  
  24. enum {
  25.  st_STOP=0,st_PLAYING=1,st_PAUSE=2,st_NOMOVIE=3
  26. } play_state=st_NOMOVIE;
  27.  
  28. #define __convert_line(from,to) \
  29. { \
  30.     int d0,d1,d2; \
  31.     __asm__ __volatile__( \
  32.         "1:\n\t" \
  33.         "lodsw\n\t" \
  34.         "stosw\n\t" \
  35.         "lodsw\n\t" \
  36.         "stosb\n\t" \
  37.         "loop 1b" \
  38.         :"=&c"(d0),"=&S"(d1),"=&D"(d2) \
  39.         :"0"(line_width),"1"(from),"2"(to)); \
  40. }
  41.  
  42. void convert_output_image(void)
  43. {
  44.  char * src=bitmap_buffer;
  45.  char * dst=vblit_buffer;
  46.  int i;
  47.  for(i=0;i<I.Height;i++)
  48.  {
  49.   __convert_line(src,dst);
  50.   src+=line_width;
  51.   dst+=line_width;
  52.  }
  53. }
  54.  
  55. int reload_mpg(const char * fname)
  56. {
  57.  if(fmpeg) fclose(fmpeg);
  58.  fmpeg=fopen(fname,"rb");
  59.  if(!fmpeg) return -1;
  60.  SetMPEGOption(MPEG_DITHER,FULL_COLOR_DITHER);
  61.  OpenMPEG(fmpeg,&I);
  62.  line_width=I.Width;
  63.  vblit_buffer=(char *)realloc(vblit_buffer,I.Width*I.Height*3);
  64.  bitmap_buffer=(char *)realloc(bitmap_buffer,I.Width*I.Height*4);
  65.  return 0;
  66. }
  67.  
  68. void close_mpg(void)
  69. {
  70.  if(fmpeg) fclose(fmpeg);
  71.  if(vblit_buffer) free(vblit_buffer);
  72.  if(bitmap_buffer) free(bitmap_buffer);
  73.  vblit_buffer=NULL;
  74.  bitmap_buffer=NULL;
  75.  fmpeg=NULL;
  76. }
  77.  
  78. void rewind_mpg(void)
  79. {
  80.  RewindMPEG(fmpeg,&I);
  81. }
  82.  
  83. int play_mpg_frame(void)
  84. {
  85.  if(!GetMPEGFrame(bitmap_buffer)) return -1;
  86.  convert_output_image();
  87.  __menuet__putimage(blit_x_offs,blit_y_offs,I.Width,I.Height,vblit_buffer);
  88.  return 0;
  89. }
  90.  
  91. void set_player_wnd_title(char * fname)
  92. {
  93.  int i;
  94.  if(!fname || play_state==st_NOMOVIE)
  95.   fname="No movie loaded";
  96.  i=sprintf(player_window_title,"Menuet MPEG player - %s",fname);
  97.  __menuet__write_text(4,4,0xffffff,player_window_title,i);
  98. }
  99.  
  100. static char * player_buttons1[]={" ||  ","  >  ","  ## ","  /\\ ","  \\/ "};
  101. static char * player_buttons2[]={"pause","play ","stop ","eject","load "};
  102.  
  103. #define BUTT_SIZE_X  (5*8)
  104. #define BUTT_SIZE_Y  (2*12)
  105.  
  106. void paint_player_buttons(void)
  107. {
  108.  int xpos,ypos,i;
  109.  xpos=5;
  110.  ypos=20;
  111.  for(i=0;i<5;i++)
  112.  {
  113.   __menuet__make_button(xpos,ypos,BUTT_SIZE_X,BUTT_SIZE_Y,i+2,0x40000000);
  114.  }
  115. }
  116.  
  117. void paint_player_window(void)
  118. {
  119.  __menuet__window_redraw(1);
  120.  if(play_state==st_NOMOVIE)
  121.  {
  122.   win_size_x=40*8;
  123.   win_size_y=200;
  124.  } else {
  125.   win_size_x=max(40*8,I.Width+20);
  126.   win_size_y=max(200,I.Height+50);
  127.  }
  128.  __menuet__define_window(100,100,win_size_x,win_size_y,0x03000080,
  129.                          0x800000FF,0x000080);
  130.  set_player_wnd_title(loaded_file_name);
  131.  if(play_state!=st_NOMOVIE)
  132.  {
  133.   blit_x_offs=10;
  134.   blit_y_offs=40;
  135.   __menuet__putimage(blit_x_offs,blit_y_offs,I.Width,I.Height,vblit_buffer);
  136.  }
  137.  paint_player_buttons();
  138.  __menuet__window_redraw(2);
  139. }
  140.