home *** CD-ROM | disk | FTP | other *** search
/ Kyūkyoku!! X68000 Emulator / X68000Book.dat / mac / OLS / X68000 / Ko-Window / gvto6511.lzh / gv_to65.c next >
C/C++ Source or Header  |  1995-02-16  |  4KB  |  172 lines

  1. /*
  2.     Copyright 1995 Ogasawara Hiroyuki(COR.)
  3. */
  4.  
  5. #include    <corlib.h>
  6. #include    <sys_doslib.h>
  7.  
  8. #include    "Sesse.inc"
  9.  
  10. #define        PROG        "GV_to65 v1.10"
  11.  
  12. #define        GVIEWWIN    "gview.win"
  13. #define        XSIZE        86
  14. #define        YSIZE        16
  15.  
  16. int        WindowHeapSize= 1024*0;
  17.  
  18. static void
  19. WaitMark()
  20. {
  21.     MouseSetPattern( 1, &SessePattern, 7, 3 );
  22.     MS_SEL( 1 );
  23. }
  24.  
  25. static void
  26. MakeNewGWin( ng, gp )
  27. UGraphic    *ng, *gp;
  28. {
  29.     EventInfo    info;
  30.     info.option= EventUser;
  31.     info.ComBuffer= ng;
  32.     info.ComData= UserGraphic;
  33.     PidSendEvent( GVIEWWIN, &info, TRUE );
  34.     MFREE( ng->buf );
  35. }
  36.  
  37.  
  38. GV_Small( gp )
  39. UGraphic    *gp;
  40. {
  41.     UGraphic    ng;
  42.     unsigned short    *str= MALLOC( gp->h*gp->v*2/4 ),
  43.             *ptr= (void*)gp->buf;
  44.     int        y;
  45.     WaitMark();
  46.     if( (int)(ng.buf= str) < 0 )
  47.         return    FALSE;
  48.     for( y= gp->v/2-1 ; y >= 0 ; y-- ){
  49.         int    x;
  50.         for( x= gp->h/2-1 ; x-- >= 0 ;){
  51.             unsigned int    a= *ptr++,
  52.                     b= *ptr++,
  53.                     c= ptr[gp->h-2],
  54.                     d= ptr[gp->h-1];
  55.             *str++=
  56.     ((((a&0xf800)+(b&0xf800)+(c&0xf800)+(d&0xf800))>>2)&0xf800)+
  57.     ((((a&0x07c0)+(b&0x07c0)+(c&0x07c0)+(d&0x07c0))>>2)&0x07c0)+
  58.     ((((a&0x003e)+(b&0x003e)+(c&0x003e)+(d&0x003e))>>2)&0x003e);
  59.         }
  60.         ptr+= gp->h;
  61.     }
  62.     ng.h= gp->h/2;
  63.     ng.v= gp->v/2;
  64.     ng.palet= NULL;
  65.     ng.color= WindowAttrGraphic65536;
  66.     MakeNewGWin( &ng, gp );
  67.     MS_SEL( 0 );
  68.     return    TRUE;
  69. }
  70.  
  71. GV_to65( gp )
  72. UGraphic    *gp;
  73. {
  74.     if( gp->color == WindowAttrGraphic65536 && !gp->palet )
  75.         return    GV_Small( gp );
  76.     WaitMark();
  77.     {
  78.         UGraphic    ng;
  79.         unsigned short    *str= MALLOC( gp->h*gp->v*2/4 );
  80.         unsigned char    *ptr= (void*)gp->buf;
  81.         int    x, y;
  82.         if( (int)(ng.buf= str) < 0 )
  83.             return    FALSE;
  84.         for( y= 0 ; y< gp->v/2 ; y++, ptr+= gp->h ){
  85.             for( x= 0 ; x< gp->h/2 ; x++, ptr+= 2 ){
  86.                 unsigned int    a= gp->palet[ptr[0]],
  87.                         b= gp->palet[ptr[1]],
  88.                         c= gp->palet[ptr[gp->h]],
  89.                         d= gp->palet[ptr[gp->h+1]];
  90.                 *str++=
  91.         ((((a&0xf800)+(b&0xf800)+(c&0xf800)+(d&0xf800))>>2)&0xf800)+
  92.         ((((a&0x07c0)+(b&0x07c0)+(c&0x07c0)+(d&0x07c0))>>2)&0x07c0)+
  93.         ((((a&0x003e)+(b&0x003e)+(c&0x003e)+(d&0x003e))>>2)&0x003e);
  94.             }
  95.         }
  96.         ng.h= gp->h/2;
  97.         ng.v= gp->v/2;
  98.         ng.palet= NULL;
  99.         ng.color= WindowAttrGraphic65536;
  100.         MakeNewGWin( &ng, gp );
  101.     }
  102.     MS_SEL( 0 );
  103.     return    TRUE;
  104. }
  105.  
  106.  
  107. static int
  108. EventExec( wp, info )
  109. WindowID    wp;
  110. EventInfo    *info;
  111. {
  112.     DrawBuf    dbuf[4];
  113.     switch( info->option ){
  114.         case EventOpen:
  115.             WindowSetEventAttr( wp,  EventOpenON|EventRedrawON
  116.                 |EventCloseON|EventMouseSwitchON|EventIconifyON
  117.                 |EventUserON );
  118.             WindowRedraw( wp );
  119.             return    TRUE;
  120.         case EventIconify:
  121.             IconEnt( wp, PROG, AttrDefault, 12 );
  122.             return    TRUE;
  123.         case EventRedraw:
  124.             DrawSetClear( dbuf, ColorGray );
  125.             DrawSetSymbol( dbuf+1, 3, 1, PROG, AttrDefault|4, 12 );
  126.             WindowDraw( wp, dbuf, 2 );
  127.             return    TRUE;
  128.         case EventClose:
  129.             WindowClose( wp );
  130.             WindowConnectionClose();
  131.             return    TRUE;
  132.         case EventUser:
  133.             switch( info->ComData ){
  134.             case UserGraphic:
  135.                 GV_to65( info->ComBuffer );
  136.                 return    TRUE;
  137.             case UserString:
  138.             case UserPaste:
  139.             case UserStrings:
  140.                 break;
  141.             }
  142.             return    FALSE;
  143.  
  144.         case EventMouseSwitch:
  145.             if( info->LeftON ){
  146.                 ConsoleOpen();
  147.                 ConsolePrint(
  148. "\r\n" PROG " 1995 COR.\r\n"
  149. "------------------------------------------------------------------------\r\n"
  150. "16/256/65536ÉFëµæ£âfü[â^é≡1/4é╔Åkżò╧è╖é╡üA65536ÉFëµæ£é┼Åoù═é╡é▄é╖üBôⁿÅo\r\n"
  151. "ù═é═ EventUser é╠ UserGraphic é┼ìséóé▄é╖üBÅoù═é╠é╜é▀é╔ gview é¬òKùvé┼é╖üB\r\n"
  152. "------------------------------------------------------------------------\r\n"
  153.                 );
  154.                 return    TRUE;
  155.             }
  156.             return    FALSE;
  157.     }
  158.     return    FALSE;
  159. }
  160.  
  161.  
  162. void
  163. WindowMain( argc, argv )
  164. char    **argv;
  165. {
  166.     int    x= 300, y= 0;
  167.     argc= AnalyzeArgs( argc, argv, &x, &y, NULL, NULL );
  168.     WindowTitleOpen( x, y, XSIZE, YSIZE, NULL, " ",
  169.                         Close|Push|Icon, EventExec );
  170. }
  171.  
  172.