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

  1. /******************************************************************************
  2. **                                         **
  3. ** MultiColor-Demo-PicView                             **
  4. **                                         **
  5. **---------------------------------------------------------------------------**
  6. ** V2.0 vom 02.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 PicView(char *name,WORD ro,WORD go,WORD bo);
  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 PicView(char *name,WORD ro,WORD go,WORD bo)
  74. {
  75.     struct IntuiMessage *imsg;
  76.     ULONG iclass;
  77.     USHORT icode;
  78.     UBYTE quit=0,color;
  79.     MCPoint akt;
  80.     FILE *in_r,*in_g,*in_b;
  81.     register int x,y;
  82.     char name_r[200],name_g[200],name_b[200];
  83.  
  84.     sprintf(name_r,"%s.r",name);
  85.     sprintf(name_g,"%s.g",name);
  86.     sprintf(name_b,"%s.b",name);
  87.  
  88.     if(in_r=fopen(name_r,"rb"))
  89.     {
  90.         if(in_g=fopen(name_g,"rb"))
  91.         {
  92.         if(in_b=fopen(name_b,"rb"))
  93.         {
  94.             for(y=0;y<mch->yres && !quit;y++)
  95.             {
  96.             for(x=0;x<mch->xres;x++)
  97.             {
  98.                 color=fgetc(in_r);
  99.                 akt.r=ro+color;
  100.                 if (akt.r < 0)
  101.                 akt.r=0;
  102.                 else if (akt.r>255)
  103.                 akt.r=255;
  104.                 color=fgetc(in_g);
  105.                 akt.g=ro+color;
  106.                 if (akt.g < 0)
  107.                 akt.g=0;
  108.                 else if (akt.g>255)
  109.                 akt.g=255;
  110.                 color=fgetc(in_b);
  111.                 akt.b=bo+color;
  112.                 if (akt.b < 0)
  113.                 akt.b=0;
  114.                 else if (akt.b>255)
  115.                 akt.b=255;
  116.                 MC_PutPixel(mch,x,y,&akt);
  117.  
  118.                 if(imsg=(struct IntuiMessage *)GetMsg(win->UserPort))
  119.                 {
  120.                 ReplyMsg((struct Message *)imsg);
  121.                 quit=1;
  122.                 break;
  123.                 }
  124.             }
  125.             }
  126.             fclose(in_b);
  127.         }
  128.         fclose(in_g);
  129.         }
  130.         fclose(in_r);
  131.     }
  132.     while(!quit)
  133.     {
  134.         WaitPort(win->UserPort);
  135.         while(imsg=(struct IntuiMessage *)GetMsg(win->UserPort))
  136.         {
  137.             iclass    =imsg->Class;
  138.             icode    =imsg->Code;
  139.             ReplyMsg((struct Message *)imsg);
  140.             switch(iclass)
  141.             {
  142.                 case IDCMP_RAWKEY:
  143.                     switch(icode)
  144.                     {
  145.                         case 0x45:        /* ESC */
  146.                         case 0x40:        /* Space */
  147.                             quit=1;break;
  148.                     }
  149.                     break;
  150.             }
  151.         }
  152.     }
  153. }
  154.  
  155. void Usage(void)
  156. {
  157.     printf("Usage \n");
  158.     printf("\tmc_picview typ res name\n");
  159.     printf("\tres\\typ | 0=ECS | 1=AGA,GFX-Card\n");
  160.     printf("\t--------+-------+---------------\n");
  161.     printf("\t e (ehb)| 64    | -             \n");
  162.     printf("\t l (low)| 32    | 256           \n");
  163.     printf("\t h (hi )| 16    | 256           \n");
  164.     printf("\t s (shi)| --    | 256           \n");
  165.     printf("\t--------+-------+---------------\n");
  166.     printf("\n\tname  raw-picturefile\n");
  167. }
  168.  
  169. void main(int argc,char *argv[])
  170. {
  171.     UBYTE dep,typ,fail=0;
  172.     char res;
  173.     WORD ro=0,go=0,bo=0;
  174.  
  175.     if(argc>=4)
  176.     {
  177.         typ=atoi(argv[1])&1;
  178.         res=argv[2][0];
  179.         if(argc>=5) ro=atof(argv[4])*255;
  180.         if(argc>=6) ro=atof(argv[5])*255;
  181.         if(argc>=7) ro=atof(argv[6])*255;
  182.  
  183.         switch(typ)
  184.         {
  185.             case 0:     /* ECS */
  186.                 switch(res)
  187.                 {
  188.                     case 'E':
  189.                     case 'e':
  190.                         scrtags[4].ti_Data=dep=6;
  191.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  192.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  193.                         scrtags[7].ti_Data|=EXTRAHALFBRITELACE_KEY;
  194.                         break;
  195.                     case 'L':
  196.                     case 'l':
  197.                         scrtags[4].ti_Data=dep=5;
  198.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  199.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  200.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  201.                         break;
  202.                     case 'H':
  203.                     case 'h':
  204.                         scrtags[4].ti_Data=dep=4;
  205.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  206.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  207.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  208.                         break;
  209.                     case 'S':
  210.                     case 's':
  211.                         fail=1;
  212.                         break;
  213.                 }
  214.                 break;
  215.             case 1:     /* AGA,GFX-Card */
  216.                 switch(res)
  217.                 {
  218.                     case 'E':
  219.                     case 'e':
  220.                         fail=1;
  221.                         break;
  222.                     case 'L':
  223.                     case 'l':
  224.                         scrtags[4].ti_Data=dep=8;
  225.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  226.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  227.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  228.                         break;
  229.                     case 'H':
  230.                     case 'h':
  231.                         scrtags[4].ti_Data=dep=8;
  232.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  233.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  234.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  235.                         break;
  236.                     case 'S':
  237.                     case 's':
  238.                         scrtags[4].ti_Data=dep=8;
  239.                         wintags[2].ti_Data=scrtags[2].ti_Data=1416;        /* 944 */
  240.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  241.                         scrtags[7].ti_Data|=SUPERLACE_KEY;
  242.                         break;
  243.                 }
  244.                 break;
  245.         }
  246.  
  247.         if(!fail)
  248.         {
  249.             OpenAll();
  250.             if(mch=MC_Init(scr,win,dep))
  251.             {
  252.                 PicView(argv[3],ro,go,bo);
  253.                 MC_Free(mch);
  254.             }
  255.         }
  256.         else Usage();
  257.     }
  258.     else Usage();
  259.     CloseAll();
  260. }
  261.