home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / indispensabili / grafica / amipeg_1.1 / src / gray.c < prev    next >
C/C++ Source or Header  |  1997-12-02  |  4KB  |  158 lines

  1.  
  2. #include <exec/exec.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/screens.h>
  5. #include <dos/dos.h>
  6. #include <libraries/asl.h>
  7.  
  8. #include <proto/asl.h>
  9. #include <proto/exec.h>
  10. #include <proto/graphics.h>
  11. #include <proto/intuition.h>
  12. #include <proto/dos.h>
  13. #include <proto/asyncio.h>
  14.  
  15. #include "video.h"
  16. #include "proto.h"
  17.  
  18. struct RastPort temprp;
  19. struct BitMap tempbm;
  20. int plane, i;
  21.  
  22. static void Quit(char *why, int failcode)
  23. {
  24.     puts(why);
  25.     exit(failcode);
  26. }
  27.  
  28. void DrawGrayImage(void *data, int x, int y)
  29. {
  30. /*    int win_x = cyber_window->Width - cyber_window->BorderLeft - cyber_window->BorderRight;
  31.     int win_y = cyber_window->Height - cyber_window->BorderTop - cyber_window->BorderBottom;
  32.  
  33.     if(win_x == x && win_y == y)
  34. */
  35.     {
  36.         WritePixelArray8(cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, cyber_window->BorderLeft + x - 1, cyber_window->BorderTop + y - 1, data, &temprp);
  37.     }
  38. }
  39.  
  40. static void output_term(void)
  41. {
  42.     close_timer();
  43.  
  44.     if(input)
  45.     {
  46.         CloseAsync(input);
  47.         input = NULL;
  48.     }
  49.  
  50.     for(i = 0; i < plane; i++)
  51.         FreeRaster(tempbm.Planes[i], cyber_screen->Width, 1);
  52.  
  53.     if(cyber_window)
  54.         CloseWindow(cyber_window);
  55.     
  56.     if(cyber_screen)
  57.         CloseScreen(cyber_screen);
  58.  
  59.     if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  60.     if (GfxBase) CloseLibrary((struct Library *) GfxBase);
  61. }
  62.  
  63. int get_modeid(void)
  64. {
  65.     struct ScreenModeRequester *scrMdReq;
  66.     int modeid = 0xffffffff;
  67.  
  68.     if(scrMdReq = AllocAslRequestTags(ASL_ScreenModeRequest,
  69.                                                                         ASLSM_MinWidth, 200,
  70.                                                                         ASLSM_MinHeight, 200,
  71.                                                                         ASLSM_MinDepth, 8,
  72.                                                                         ASLSM_MaxDepth, 8,
  73.                                                                         TAG_DONE))
  74.     {
  75.         if(AslRequestTags(scrMdReq, TAG_DONE))
  76.             modeid = scrMdReq->sm_DisplayID;
  77.  
  78.         FreeAslRequest(scrMdReq);
  79.     }
  80.  
  81.     return(modeid);
  82. }
  83.  
  84. void init_gray(void)
  85. {
  86.     atexit(output_term);
  87.  
  88.     if ((GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",37))==NULL)
  89.         Quit("graphics.library is too old, <V37",25);
  90.     if ((IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",37))==NULL)
  91.         Quit("intuition.library is too old, <V37",25);
  92.  
  93. }
  94.  
  95. unsigned long InitGrayDisplay(unsigned long modeid)
  96. {
  97.     int rgb = 0;
  98.     UWORD pens[] =
  99.     {
  100.         0xf0, 0x40, 0x70, 0xff, 0x0, 0x80, 0xff, 0xc0, 0xa0, 0x0, 0xff, 0x80,
  101.         ~0
  102.     };
  103.  
  104.     init_gray();
  105.  
  106.         if((modeid != 0xffffffff) || (modeid = get_modeid()) != 0xffffffff)
  107.         {
  108.             if(cyber_screen = OpenScreenTags(NULL,
  109.                             SA_Width, STDSCREENWIDTH,
  110.                             SA_Height, STDSCREENHEIGHT,
  111.                             SA_DisplayID, modeid,
  112.                             SA_Title, (UBYTE *)"aMiPEG 1.0 by Michael Rausch and Miloslaw Smyk",
  113.                             SA_Depth, 8,
  114.                             SA_Pens, &pens,
  115.                             SA_SysFont, 1,
  116. //                            SA_BackFill, LAYERS_BACKFILL,
  117.                             TAG_DONE))
  118.             {
  119.  
  120.                 /* set palette to 0 - 255 */
  121.                 for(i = 0; i < 256; i++)
  122.                 {
  123.                     SetRGB32(&cyber_screen->ViewPort,i,rgb,rgb,rgb);
  124.                     rgb += 0x01010101;
  125.                 }
  126.  
  127.                 if(cyber_window = OpenWindowTags(NULL,
  128.                                     WA_CustomScreen, cyber_screen,
  129.                                     WA_Flags, WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_SIZEBBOTTOM | WFLG_ACTIVATE,
  130.                     WA_IDCMP, CLOSEWINDOW | MOUSEBUTTONS | VANILLAKEY,
  131.                     WA_InnerWidth, 160,
  132.                     WA_InnerHeight,120,
  133.                     WA_MaxWidth, ~0,
  134.                     WA_MaxHeight, ~0,
  135.                     WA_MinWidth, 60,
  136.                     WA_MinHeight, 60,
  137.                     WA_Title, "Playing MPEG animation",
  138.                     TAG_DONE))
  139.                 {
  140.                     InitRastPort(&temprp);
  141.                     InitBitMap(&tempbm, cyber_window->RPort->BitMap->Depth, cyber_screen->Width, 1);
  142.                     temprp.BitMap = &tempbm;
  143.  
  144.                     for (plane = 0; plane < tempbm.Depth; plane++)
  145.                         if(!(tempbm.Planes[plane] = AllocRaster(cyber_screen->Width, 1)))
  146.                             break;
  147.  
  148.                     if(plane != tempbm.Depth)
  149.                         modeid = 0xffffffff;
  150.  
  151.                     return(modeid);
  152.                 }
  153.             }
  154.         }
  155.  
  156.     Quit("aMiPEG: unable to open screen/window...", 25);
  157. }
  158.