home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / GraKa / Picasso96Develop / Examples / WriteTrueColorData.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-03  |  3.8 KB  |  148 lines

  1. /***********************************************************************
  2. * This is an example that shows how to use p96WriteTrueColorData
  3. * Program terminates when space bar or any mouse button is pressed!
  4. *
  5. * alx (Mon Dec 30 12:09:35 1996)
  6. ***********************************************************************/
  7.  
  8. #include    <proto/exec.h>
  9. #include    <proto/dos.h>
  10. #include    <proto/intuition.h>
  11. #include    <proto/picasso96.h>
  12.  
  13. #include    <intuition/screens.h>
  14. #include    <exec/memory.h>
  15.  
  16. #include    <math.h>
  17. #include    <stdio.h>
  18. #include    <stdlib.h>
  19.  
  20. #define WIDTH 160
  21. #define HEIGHT 160
  22.  
  23. /* for ReadArgs */
  24. char template[]="Width=W/N,Height=H/N,Depth=D/N";
  25. LONG array[]={    0, 0, 0 };
  26.  
  27. /* p96WriteTrueColorData only works on True- and HiColorModes */
  28.  
  29. #define HiColorFormats        (RGBFF_R5G6B5|RGBFF_R5G5B5|RGBFF_R5G6B5PC|RGBFF_R5G5B5PC|RGBFF_B5G6R5PC|RGBFF_B5G5R5PC)
  30. #define TrueColorFormats    (RGBFF_R8G8B8|RGBFF_B8G8R8)
  31. #define TrueAlphaFormats    (RGBFF_R8G8B8A8|RGBFF_B8G8R8A8|RGBFF_A8R8G8B8|RGBFF_A8B8G8R8)
  32. #define UsefulFormats        (HiColorFormats|TrueColorFormats|TrueAlphaFormats)
  33.  
  34. struct Library        *P96Base;
  35. WORD    Pens[] = {~0};
  36.  
  37. void main(void){
  38.     struct Screen            *sc;
  39.     struct Window            *win;
  40.     struct RDArgs            *rda;
  41.     ULONG                        DisplayID;
  42.     WORD                        width=640, height=480, depth=24;
  43.     
  44.     int                        i;
  45.     
  46.     /* get user parameters */
  47.  
  48.     if(rda=ReadArgs(template,array,NULL)){
  49.         if(array[0])    width =*((LONG *)array[0]);
  50.         if(array[1])    height=*((LONG *)array[1]);
  51.         if(array[2])    depth =*((LONG *)array[2]);
  52.         FreeArgs(rda);
  53.     }
  54.  
  55.     if(P96Base=OpenLibrary("Picasso96API.library",2)){
  56.  
  57.         DisplayID=p96BestModeIDTags(
  58.                                         P96BIDTAG_NominalWidth, width,
  59.                                         P96BIDTAG_NominalHeight, height,
  60.                                         P96BIDTAG_Depth, depth,
  61.                                         P96BIDTAG_FormatsAllowed, UsefulFormats,
  62.                                         TAG_DONE);
  63.  
  64.         if(sc = p96OpenScreenTags(
  65.                                         P96SA_DisplayID, DisplayID,
  66.                                         P96SA_Width, width,
  67.                                         P96SA_Height, height,
  68.                                         P96SA_Depth, depth,
  69.                                         P96SA_AutoScroll, TRUE,
  70.                                         P96SA_Pens, Pens,
  71.                                         P96SA_Title, "WriteTrueColorData Test",
  72.                                         TAG_DONE)){
  73.  
  74.             if(win=OpenWindowTags(NULL,
  75.                                             WA_CustomScreen, sc,
  76.                                             WA_Backdrop, TRUE,
  77.                                             WA_Borderless, TRUE,
  78.                                             WA_SimpleRefresh, TRUE,
  79.                                             WA_RMBTrap, TRUE,
  80.                                             WA_Activate, TRUE,
  81.                                             WA_IDCMP, IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS,
  82.                                             TAG_END)){
  83.  
  84.                 BOOL    quit = FALSE;
  85.                 UBYTE    *reddata, *greendata, *bluedata;
  86.  
  87.                 reddata   = AllocVec(WIDTH*HEIGHT, MEMF_ANY);
  88.                 greendata = AllocVec(WIDTH*HEIGHT, MEMF_ANY);
  89.                 bluedata  = AllocVec(WIDTH*HEIGHT, MEMF_ANY);
  90.  
  91.                 if(reddata && greendata && bluedata){
  92.  
  93.                     struct TrueColorInfo    tci;
  94.                     BPTR    file;
  95.  
  96.                     tci.PixelDistance = 1;
  97.                     tci.BytesPerRow = WIDTH;
  98.                     tci.RedData = reddata; 
  99.                     tci.GreenData = greendata; 
  100.                     tci.BlueData = bluedata; 
  101.  
  102.                     /* load red data */
  103.  
  104.                     if(file=Open("Symbol.red", MODE_OLDFILE)){
  105.                         Read(file, reddata, WIDTH*HEIGHT);
  106.                         Close(file);
  107.                     }
  108.                     if(file=Open("Symbol.green", MODE_OLDFILE)){
  109.                         Read(file, greendata, WIDTH*HEIGHT);
  110.                         Close(file);
  111.                     }
  112.                     if(file=Open("Symbol.blue", MODE_OLDFILE)){
  113.                         Read(file, bluedata, WIDTH*HEIGHT);
  114.                         Close(file);
  115.                     }
  116.  
  117.                     /* paint something on the screen */
  118.  
  119.                     p96WriteTrueColorData(&tci,0,0,win->RPort,50,50,WIDTH,HEIGHT);
  120.                 }
  121.  
  122.                 FreeVec(reddata);
  123.                 FreeVec(greendata);
  124.                 FreeVec(bluedata);
  125.  
  126.                 /* wait for input */
  127.  
  128.                 do{
  129.                     struct IntuiMessage    *imsg;
  130.  
  131.                     WaitPort(win->UserPort);
  132.                     while(imsg=(struct IntuiMessage *)GetMsg(win->UserPort)){
  133.                         if((imsg->Class==IDCMP_MOUSEBUTTONS) || ((imsg->Class==IDCMP_RAWKEY) && (imsg->Code==0x40))){
  134.  
  135.                             // press MOUSEBUTTONS or SPACE bar to end program
  136.                             quit=TRUE;
  137.                         }
  138.                         ReplyMsg((struct Message *)imsg);
  139.                     }
  140.                 }while(!quit);
  141.                 CloseWindow(win);
  142.             }
  143.             p96CloseScreen(sc);
  144.         }
  145.         CloseLibrary(P96Base);
  146.     }
  147. }
  148.