home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / dev / misc / MC.lha / MC / mc_bleed.c < prev    next >
C/C++ Source or Header  |  1995-10-31  |  7KB  |  274 lines

  1. /******************************************************************************
  2. **                                         **
  3. ** MultiColor-Demo-Bleed                             **
  4. **                                         **
  5. **---------------------------------------------------------------------------**
  6. ** V2.0 vom 01.10.95                                 **
  7. ******************************************************************************/
  8.  
  9. #include "sc:source/mc/multicolor.h"
  10.  
  11. /* Protos */
  12.  
  13. void OpenAll(void);
  14. void CloseAll(void);
  15. void Bleed(UWORD eg1,UWORD eg2,UWORD eg3,UWORD eg4);
  16. void Usage(void);
  17.  
  18. /* defines */
  19.  
  20. extern struct ExecBase        *SysBase;
  21. struct IntuitionBase        *IntuitionBase=0l;
  22. struct GfxBase                *GfxBase=0l;
  23. struct Screen                *scr=0l;
  24. struct Window                *win=0l;
  25. MCHandle                    *mch=0l;
  26.  
  27. struct TagItem scrtags[]={
  28.     SA_Left,        0,
  29.     SA_Top,         0,
  30.     SA_Width,        0,
  31.     SA_Height,        0,
  32.     SA_Depth,        0,
  33.     SA_Colors,        0l,
  34.     SA_Type,        CUSTOMSCREEN,
  35.     SA_DisplayID,    PAL_MONITOR_ID,
  36.     TAG_DONE
  37. };
  38.  
  39. struct TagItem wintags[]={
  40.     WA_Left,        0,
  41.     WA_Top,         0,
  42.     WA_Width,        0,
  43.     WA_Height,        0,
  44.     WA_IDCMP,        IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY,
  45.     WA_Flags,        WFLG_SMART_REFRESH|WFLG_RMBTRAP|WFLG_BORDERLESS|WFLG_ACTIVATE,
  46.     WA_CustomScreen,0l,
  47.     TAG_DONE
  48. };
  49.  
  50. /* Funktions */
  51.  
  52. void OpenAll(void)
  53. {
  54. //    if(!(IntuitionBase=OpenLibrary("intuition.library",37))) CloseAll();
  55.     if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39))) CloseAll();
  56.     if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37))) CloseAll();
  57.  
  58.     if(!(scr=OpenScreenTagList(0l,scrtags))) CloseAll();
  59.     wintags[6].ti_Data=(ULONG)scr;
  60.  
  61.     if(!(win=OpenWindowTagList(0l,wintags))) CloseAll();
  62. }
  63.  
  64. void CloseAll(void)
  65. {
  66.     if(win)                 CloseWindow(win);
  67.     if(scr)                 CloseScreen(scr);
  68.     if(GfxBase)             CloseLibrary((struct Library *)GfxBase);
  69.     if(IntuitionBase)       CloseLibrary((struct Library *)IntuitionBase);
  70.     exit(0);
  71. }
  72.  
  73. void Bleed(UWORD eg1,UWORD eg2,UWORD eg3,UWORD eg4)
  74. {
  75.     struct IntuiMessage *imsg;
  76.     ULONG iclass;
  77.     USHORT icode;
  78.     register UBYTE quit=0;
  79.     register UWORD x,y;
  80.     MCPoint edge[4],akt,t1,t2;
  81.     MCPoint v1d,/*v1s,*/v2d,/*v2s,*/h1d/*,h1s*/;
  82. //    FILE *filer=0l,*fileg=0l,*fileb=0l;
  83. //    UBYTE color;
  84.  
  85.     edge[0].r=(eg1&0xF00)>>4;
  86.     edge[0].g=(eg1&0x0F0);
  87.     edge[0].b=(eg1&0x00F)<<4;
  88.     edge[1].r=(eg2&0xF00)>>4;
  89.     edge[1].g=(eg2&0x0F0);
  90.     edge[1].b=(eg2&0x00F)<<4;
  91.     edge[2].r=(eg3&0xF00)>>4;
  92.     edge[2].g=(eg3&0x0F0);
  93.     edge[2].b=(eg3&0x00F)<<4;
  94.     edge[3].r=(eg4&0xF00)>>4;
  95.     edge[3].g=(eg4&0x0F0);
  96.     edge[3].b=(eg4&0x00F)<<4;
  97.  
  98.     v1d.r=edge[3].r-edge[0].r;//v1s.r=v1d.r/(double)mch->yres;
  99.     v1d.g=edge[3].g-edge[0].g;//v1s.g=v1d.g/(double)mch->yres;
  100.     v1d.b=edge[3].b-edge[0].b;//v1s.b=v1d.b/(double)mch->yres;
  101.     v2d.r=edge[2].r-edge[1].r;//v2s.r=v2d.r/(double)mch->yres;
  102.     v2d.g=edge[2].g-edge[1].g;//v2s.g=v2d.g/(double)mch->yres;
  103.     v2d.b=edge[2].b-edge[1].b;//v2s.b=v2d.b/(double)mch->yres;
  104.  
  105. //    filer=fopen("xh3:test.r","wb");
  106. //    fileg=fopen("xh3:test.g","wb");
  107. //    fileb=fopen("xh3:test.b","wb");
  108.  
  109. //    if(filer && fileg && fileb)
  110. //    {
  111.         for(y=0;y<mch->yres;y++)
  112.         {
  113.         t1.r=edge[0].r+v1d.r*y/mch->yres;
  114.         t1.g=edge[0].g+v1d.g*y/mch->yres;
  115.         t1.b=edge[0].b+v1d.b*y/mch->yres;
  116.         t2.r=edge[1].r+v2d.r*y/mch->yres;
  117.         t2.g=edge[1].g+v2d.g*y/mch->yres;
  118.         t2.b=edge[1].b+v2d.b*y/mch->yres;
  119.         h1d.r=t2.r-t1.r;//h1s.r=h1d.r/(double)mch->xres;
  120.         h1d.g=t2.g-t1.g;//h1s.g=h1d.g/(double)mch->xres;
  121.         h1d.b=t2.b-t1.b;//h1s.b=h1d.b/(double)mch->xres;
  122.         for(x=0;x<mch->xres;x++)
  123.         {
  124.             akt.r=t1.r+h1d.r*x/mch->xres;
  125.             akt.g=t1.g+h1d.g*x/mch->xres;
  126.             akt.b=t1.b+h1d.b*x/mch->xres;
  127. //            color=(UBYTE)(255.0*akt.r);fwrite(&color,1,1,filer);
  128. //            color=(UBYTE)(255.0*akt.g);fwrite(&color,1,1,fileg);
  129. //            color=(UBYTE)(255.0*akt.b);fwrite(&color,1,1,fileb);
  130.             MC_PutPixel(mch,x,y,&akt);
  131.             if (imsg=(struct IntuiMessage *)GetMsg(win->UserPort))
  132.             {
  133.             ReplyMsg((struct Message *)imsg);
  134.             quit=1;
  135.             break;
  136.             }
  137.         }
  138.         if (quit)
  139.             break;
  140.         }
  141. //        fclose(fileb);
  142. //        fclose(fileg);
  143. //        fclose(filer);
  144. //    }
  145.     while(!quit)
  146.     {
  147.     WaitPort(win->UserPort);
  148.     while(imsg=(struct IntuiMessage *)GetMsg(win->UserPort))
  149.     {
  150.         iclass  =imsg->Class;
  151.         icode   =imsg->Code;
  152.         ReplyMsg((struct Message *)imsg);
  153.         switch(iclass)
  154.         {
  155.         case IDCMP_RAWKEY:
  156.         switch(icode)
  157.         {
  158.             case 0x45:            /* ESC */
  159.             case 0x40:            /* Space */
  160.             quit=1;break;
  161.         }
  162.         break;
  163.         }
  164.     }
  165.     }
  166. }
  167.  
  168. void Usage(void)
  169. {
  170.     printf("Usage \n");
  171.     printf("\tmc_bleed typ res\n");
  172.     printf("\tres\\typ | 0=ECS | 1=AGA,GFX-Card\n");
  173.     printf("\t--------+-------+---------------\n");
  174.     printf("\t e (ehb)| 64    | -             \n");
  175.     printf("\t l (low)| 32    | 256           \n");
  176.     printf("\t h (hi )| 16    | 256           \n");
  177.     printf("\t s (shi)| --    | 256           \n");
  178.     printf("\t--------+-------+---------------\n");
  179. }
  180.  
  181. void main(int argc,char *argv[])
  182. {
  183.     UBYTE dep,typ,fail=0;
  184.     char res;
  185.     UWORD eg1=0xF00,eg2=0x0F0,eg3=0x00F,eg4=0xFFF;
  186.  
  187.     if(argc>=3)
  188.     {
  189.     typ=atoi(argv[1])&1;
  190.     res=argv[2][0];
  191.     if(argc>=4) eg1=strtol(argv[3],NULL,0);
  192.     if(argc>=5) eg2=strtol(argv[4],NULL,0);
  193.     if(argc>=6) eg3=strtol(argv[5],NULL,0);
  194.     if(argc>=7) eg4=strtol(argv[6],NULL,0);
  195.  
  196.     switch(typ)
  197.     {
  198.     case 0:     /* ECS */
  199.         switch(res)
  200.         {
  201.         case 'E':
  202.         case 'e':
  203.         scrtags[4].ti_Data=dep=6;
  204.         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  205.         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  206.         scrtags[7].ti_Data|=EXTRAHALFBRITELACE_KEY;
  207.         break;
  208.         case 'L':
  209.         case 'l':
  210.         scrtags[4].ti_Data=dep=5;
  211.         wintags[2].ti_Data=scrtags[2].ti_Data=354; /* 236 */
  212.         wintags[3].ti_Data=scrtags[3].ti_Data=552; /* 276 */
  213.         scrtags[7].ti_Data|=LORESLACE_KEY;
  214.         break;
  215.         case 'H':
  216.         case 'h':
  217.         scrtags[4].ti_Data=dep=4;
  218.         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  219.         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  220.         scrtags[7].ti_Data|=HIRESLACE_KEY;
  221.         break;
  222.         case 'S':
  223.         case 's':
  224.         fail=1;
  225.         break;
  226.         }
  227.         break;
  228.     case 1:     /* AGA,GFX-Card */
  229.         switch(res)
  230.         {
  231.             case 'E':
  232.             case 'e':
  233.                 fail=1;
  234.                 break;
  235.             case 'L':
  236.             case 'l':
  237.                 scrtags[4].ti_Data=dep=8;
  238.                 wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  239.                 wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  240.                 scrtags[7].ti_Data|=LORESLACE_KEY;
  241.                 break;
  242.             case 'H':
  243.             case 'h':
  244.                 scrtags[4].ti_Data=dep=8;
  245.                 wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  246.                 wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  247.                 scrtags[7].ti_Data|=HIRESLACE_KEY;
  248.                 break;
  249.             case 'S':
  250.             case 's':
  251.                 scrtags[4].ti_Data=dep=8;
  252.                 wintags[2].ti_Data=scrtags[2].ti_Data=1416;        /* 944 */
  253.                 wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  254.                 scrtags[7].ti_Data|=SUPERLACE_KEY;
  255.                 break;
  256.         }
  257.         break;
  258.     }
  259.  
  260.     if(!fail)
  261.     {
  262.         OpenAll();
  263.         if(mch=MC_Init(scr,win,dep))
  264.         {
  265.         Bleed(eg1,eg2,eg3,eg4);
  266.         MC_Free(mch);
  267.         }
  268.     }
  269.     else Usage();
  270.     }
  271.     else Usage();
  272.     CloseAll();
  273. }
  274.