home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-101 / dtpic.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  7KB  |  142 lines

  1. ; /* Compiled with SAS/C 6.56.  Run from CLI only.
  2. sc DATA=NEAR NMINC STRMERGE NOSTKCHK IGNORE=73 dtpic.c
  3. slink from lib:c.o dtpic.o TO dtpic LIBRARY lib:sc.lib lib:amiga.lib
  4. quit ; */
  5.  
  6. #include <exec/types.h>
  7. #include <datatypes/datatypes.h>      /* Datatypes definitions we need */
  8. #include <datatypes/pictureclass.h>
  9. #include <stdio.h>
  10.  
  11. #include <clib/exec_protos.h>         /* Prototypes for system functions */
  12. #include <clib/intuition_protos.h>
  13. #include <clib/alib_protos.h>
  14. #include <clib/datatypes_protos.h>
  15. #include <clib/graphics_protos.h>
  16.  
  17. #ifdef LATTICE
  18. int CXBRK(void)    { return(0); }     /* Disable SAS/C CTRL-C handling */
  19. int chkabort(void) { return(0); }
  20. #endif
  21.  
  22. struct Library *IntuitionBase=NULL;   /* System library bases */
  23. struct Library *GfxBase=NULL;
  24. struct Library *DataTypesBase=NULL;
  25.  
  26. VOID main(int argc, char **argv)
  27. {
  28. APTR dtobject=NULL;                   /* Pointer to a datatypes object       */
  29. ULONG res;                            /* Variable for function return values */
  30. struct dtFrameBox mydtFrameBox;       /* Use this with DTM_FRAMEBOX method   */
  31. struct FrameInfo myFrameInfo;         /* For info returned from DTM_FRAMEBOX */
  32. struct gpLayout mygpLayout;           /* Use this with DTM_PROCLAYOUT method */
  33.  
  34. ULONG modeID = INVALID_ID;            /* Variables for storing the display */
  35. struct Screen *myScreen=NULL;         /* environment information obtained  */
  36. struct BitMap *bm = NULL;             /* the datatype object.              */
  37. ULONG *cregs = NULL;
  38. ULONG i,r,g,b,numcolors;
  39.  
  40. if (IntuitionBase=OpenLibrary("intuition.library",39L))
  41.   {
  42.   if (GfxBase=OpenLibrary("graphics.library",39L))
  43.     {
  44.     if(DataTypesBase=OpenLibrary("datatypes.library",0L))
  45.         {
  46.         if(argc > 1 ) /* CLI only, at least one argument please.  */
  47.             {
  48.             /* Attempt to create a picture object in memory from the file    */
  49.             /* name given by the user in the command line.  If we wanted to  */
  50.             /* show the picture in a screen set up ahead of time, we could   */
  51.             /* set PDTA_Remap to TRUE and provide a pointer to the screen    */
  52.             /* with the PDTA_Screen tag (datatypes.library handles the rest).*/
  53.             /* However in this case we want to first find out the attributes */
  54.             /* of the picture object and set up a matching screen and do the */
  55.             /* remapping later.  Therefore PDTA_Remap is set to false.       */
  56.             /* The group ID tag ensures that we get only a picture file type.*/
  57.             if (dtobject = NewDTObject(argv[1], PDTA_Remap,  FALSE,
  58.                                                 DTA_GroupID, GID_PICTURE,
  59.                                                 TAG_END) )
  60.                 {
  61.                 /* Here we want to find the display environment required by  */
  62.                 /* this picture.  To do that, perform the DTM_FRAMEBOX method */
  63.                 /* on the object.  The datatypes library fills in the struct */
  64.                 /* FrameBox you give it with the info on the display needed.  */
  65.                 mydtFrameBox.MethodID         = DTM_FRAMEBOX;
  66.                 mydtFrameBox.dtf_GInfo        = NULL;
  67.                 mydtFrameBox.dtf_ContentsInfo = NULL;
  68.                 mydtFrameBox.dtf_FrameInfo    = &myFrameInfo;
  69.                 mydtFrameBox.dtf_SizeFrameInfo= sizeof (struct FrameInfo);
  70.                 mydtFrameBox.dtf_FrameFlags   = 0L;
  71.  
  72.                 /* The return value from DTM_FRAMEBOX is currently undefined */
  73.                 res = DoMethodA(dtobject, &mydtFrameBox);
  74.  
  75.                 /* OK, now do the layout (remap) of the object on our process */
  76.                 mygpLayout.MethodID   = DTM_PROCLAYOUT;
  77.                 mygpLayout.gpl_GInfo  = NULL;
  78.                 mygpLayout.gpl_Initial= 1L;
  79.  
  80.                 /* The return value of DTM_PROCLAYOUT is non-zero for success */
  81.                 if( res = DoMethodA(dtobject, &mygpLayout) )
  82.                    {
  83.                    /* Get the attributes of this picture object.  You could  */
  84.                    /* use a series of GetAttr() function calls here instead.  */
  85.                    res = GetDTAttrs(dtobject, PDTA_ModeID, &modeID,
  86.                                               PDTA_CRegs, &cregs,
  87.                                               PDTA_BitMap, &bm,
  88.                                               TAG_END);
  89.  
  90.                    /* Did we get all threee attributes? */
  91.                    if( (modeID!=INVALID_ID) && (cregs) && (bm) )
  92.                        {
  93.                        /* Open a screen that matches the picture object */
  94.                        if( myScreen = OpenScreenTags( NULL,
  95.                            SA_Width,     myFrameInfo.fri_Dimensions.Width,
  96.                            SA_Height,    myFrameInfo.fri_Dimensions.Height,
  97.                            SA_Depth,     myFrameInfo.fri_Dimensions.Depth,
  98.                            SA_DisplayID, modeID,
  99.                            SA_BitMap,    bm,
  100.                            TAG_END) )
  101.                            {
  102.                            /* Now fill in the color registers for this screen */
  103.                            numcolors = 2<<(myFrameInfo.fri_Dimensions.Depth-1);
  104.                            for( i=0; i < numcolors; i++ )
  105.                               {
  106.                               r = cregs[i * 3 + 0];
  107.                               g = cregs[i * 3 + 1];
  108.                               b = cregs[i * 3 + 2];
  109.                               SetRGB32(&myScreen->ViewPort, i, r, g, b);
  110.                               }
  111.  
  112.                            printf("Ctrl-C in this window to quit\n");
  113.                            /* Wait for the user to have a look...  */
  114.                            Wait(SIGBREAKF_CTRL_C);
  115.  
  116.                            CloseScreen(myScreen);
  117.                            }
  118.                        else printf("Couldn't open required screen\n");
  119.                        }
  120.                    else printf("Couldn't get picture attributes\n");
  121.  
  122.                   DisposeDTObject(dtobject);
  123.                   }
  124.                else printf("Couldn't perform PROC_LAYOUT\n");
  125.                }
  126.             else printf("Couldn't create new object or not a picture file\n");
  127.             }
  128.         else printf("Give a file name too.\n");
  129.  
  130.         CloseLibrary(DataTypesBase);
  131.         }
  132.     else printf("Can't open datatypes library\n");
  133.  
  134.     CloseLibrary(GfxBase);
  135.     }
  136.   else printf("Can't open V39 graphics\n");
  137.  
  138.   CloseLibrary(IntuitionBase);
  139.   }
  140. else printf("Can't open V39 Intuition\n");
  141. }
  142.