home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / libs / prooflibrary_21 / examples / show / main.c next >
Encoding:
C/C++ Source or Header  |  1999-03-12  |  5.4 KB  |  195 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include <exec/execbase.h>
  5. #include <exec/memory.h>
  6. #include <exec/types.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/intuitionbase.h>
  9. #include <cybergraphics/cybergraphics.h>
  10.  
  11. #include <proof/proof.h>
  12. #include <proof/proof_protos.h>
  13. #include <proof/proof_pragmas.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/cybergraphics_protos.h>
  19.  
  20. #include <pragmas/exec_pragmas.h>
  21. #include <pragmas/dos_pragmas.h>
  22. #include <pragmas/intuition_pragmas.h>
  23. #include <pragmas/cybergraphics_pragmas.h>
  24.  
  25. /* Function prototypes */
  26. void ViewProof( struct Proof *pf );
  27.  
  28. /* Global variables */
  29. extern struct Library *DOSBase;
  30. struct Library *IntuitionBase, *ProofBase, *CyberGfxBase;
  31.  
  32. char *version = "$VER: ProofShow 1.1 (25.2.99)";
  33.  
  34. void main( int argc, char **argv )
  35. {
  36.     struct Proof *pf = NULL;
  37.     ULONG err;
  38.     char *iname;
  39.  
  40.     CyberGfxBase = OpenLibrary( "cybergraphics.library", NULL );
  41.     IntuitionBase = OpenLibrary( "intuition.library", NULL );
  42.     ProofBase = OpenLibrary( "proof.library", NULL );
  43.     if ( IntuitionBase != NULL && ProofBase != NULL && CyberGfxBase != NULL )
  44.     {
  45.         if ( argc > 1 )
  46.         {
  47.             if ( IsProof( argv[1], TAG_DONE ) == FALSE )
  48.             {
  49.                 printf( "File %s is not a proof file\n", FilePart( argv[1] ) );
  50.             }
  51.             else
  52.             {
  53.                 err = LoadProof( argv[1], &pf, TAG_DONE );
  54.                 if ( err == PFERR_NONE )
  55.                 {
  56.                     char *str;
  57.                     UBYTE ub1, ub2;
  58.                     BOOL bo;
  59.                     WORD wo1, wo2;
  60.                     ULONG ul1, ul2;
  61.  
  62.                     GetProofAttrs( pf, PFN_ProofPathName, &str, TAG_DONE );
  63.                     printf( "*ProofPathName=%s\n", str );
  64.  
  65.                     printf( "ProofHeader:\n" );
  66.                     GetProofAttrs( pf, PFN_ProofVersion, &ub1, TAG_DONE );
  67.                     printf( " Version=%d\n", ub1 );
  68.                     GetProofAttrs( pf, PFN_ProofLinked, &bo, TAG_DONE );
  69.                     printf( " Linked=%s\n", bo ? "yes" : "no" );
  70.                     GetProofAttrs( pf, PFN_ProofWidth, &ub1, PFN_ProofHeight, &ub2, TAG_DONE );
  71.                     printf( " Dimensions=%d x %d\n", ub1, ub2 );
  72.                     GetProofAttrs( pf, PFN_ProofQuestionable, &bo, TAG_DONE );
  73.                     printf( " Questionable=%s\n", bo ? "yes" : "no" );
  74.                     GetProofAttrs( pf, PFN_ProofAspectX, &wo1, PFN_ProofAspectY, &wo2, TAG_DONE );
  75.                     printf( " Aspect=%d, %d\n", wo1, wo2 );
  76.  
  77.                     if ( ValidProofDesc( pf ) )
  78.                     {
  79.                         printf( "ProofDescription:\n" );
  80.                         GetProofAttrs( pf, PFN_ImageWidth, &ul1, PFN_ImageHeight, &ul2, TAG_DONE );
  81.                         printf( " Dimensions=%d x %d\n", ul1, ul2 );
  82.                         GetProofAttrs( pf, PFN_ImageFileSize, &ul1, TAG_DONE );
  83.                         printf( " FileSize=%d\n", ul1 );
  84.                         GetProofAttrs( pf, PFN_ImageType, &ub1, TAG_DONE );
  85.                         printf( " ImageType=%d\n", ub1 );
  86.                         GetProofAttrs( pf, PFN_TextImageType, &str, TAG_DONE );
  87.                         printf( " TextImageType=%s\n", str );
  88.  
  89.                         GetProofAttrs( pf, PFN_CategoryOwner, &ub1, TAG_DONE );
  90.                         printf( " CategoryOwner=%d\n", ub1 );
  91.  
  92.                         GetProofAttrs( pf, PFN_ImageGroup, &ub1, TAG_DONE );
  93.                         printf( " ImageGroup=%d\n", ub1 );
  94.  
  95.                         GetProofAttrs( pf, PFN_ImageCategory, &ul1, TAG_DONE );
  96.                         printf( " ImageCategory=%d\n", ul1 );
  97.  
  98.                         GetProofAttrs( pf, PFN_ImageDepth, &ub1, TAG_DONE );
  99.                         printf( " Depth=%d\n", ub1 );
  100.                         GetProofAttrs( pf, PFN_ImageFormat, &ub1, TAG_DONE );
  101.                         printf( " Format=%d\n", ub1 );
  102.                     }
  103.  
  104.                     err = GetProofAttrs( pf, PFN_ImageName, &iname, TAG_DONE );
  105.                     if ( err == PFERR_NONE )
  106.                     {
  107.                         printf( "Original image name: %s\n", iname );
  108.                     } else printf("Image name:%ld\n",err);
  109.  
  110.                     err = GetProofAttrs( pf, PFN_ImagePath, &iname, TAG_DONE );
  111.                     if ( err == PFERR_NONE )
  112.                     {
  113.                         printf( "Original image path: %s\n", iname );
  114.                     } else printf("Image path:%ld\n",err);
  115.  
  116.                     ViewProof( pf );
  117.  
  118.                     FreeProof( &pf );
  119.                 }
  120.                 else printf( "Error=%ld\n", err );
  121.             }
  122.         }
  123.         else printf( "Usage: ShowProof <filename>\n" );
  124.     }
  125.  
  126.     if ( ProofBase != NULL ) CloseLibrary( ProofBase );
  127.     if ( IntuitionBase != NULL ) CloseLibrary( IntuitionBase );
  128.     if ( CyberGfxBase != NULL ) CloseLibrary( CyberGfxBase );
  129. }
  130.  
  131. void ViewProof( struct Proof *pf )
  132. {
  133.     ULONG DisplayID;
  134.     struct Screen *scr;
  135.     struct Window *win;
  136.     struct Message *msg;
  137.     UBYTE pw, ph;
  138.  
  139.     DisplayID = BestCModeIDTags( CYBRBIDTG_NominalWidth, 640,
  140.         CYBRBIDTG_NominalHeight, 480,
  141.         CYBRBIDTG_Depth, 24,
  142.         TAG_DONE );
  143.  
  144.     if ( DisplayID != INVALID_ID )
  145.     {
  146.         scr = OpenScreenTags( NULL,
  147.             SA_Title, "Proof",
  148.             SA_DisplayID, DisplayID,
  149.             SA_Depth, GetCyberIDAttr( CYBRIDATTR_DEPTH, DisplayID ),
  150.             TAG_DONE );
  151.  
  152.         GetProofAttrs( pf, PFN_ProofWidth, &pw, PFN_ProofHeight, &ph, TAG_DONE );
  153.  
  154.         if ( scr != NULL )
  155.         {
  156.             win = OpenWindowTags( NULL,
  157.                 WA_Title, "Proof",
  158.                 WA_Flags,WFLG_ACTIVATE|WFLG_SIMPLE_REFRESH|
  159.                     WFLG_SIZEGADGET|WFLG_RMBTRAP|WFLG_DRAGBAR|
  160.                     WFLG_DEPTHGADGET|WFLG_CLOSEGADGET,
  161.                 WA_IDCMP,
  162.                     IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|
  163.                     IDCMP_SIZEVERIFY|IDCMP_NEWSIZE|IDCMP_RAWKEY,
  164.                 WA_Left, 16,
  165.                 WA_Top, scr->BarHeight+16,
  166.                 WA_Width, pw,
  167.                 WA_Height, ph,
  168.                 WA_CustomScreen, scr,
  169.                 TAG_DONE );
  170.             if ( win != NULL )
  171.             {
  172.                 UBYTE *rgb;
  173.  
  174.                 rgb = AllocVec( pw * ph * 3, MEMF_PUBLIC | MEMF_CLEAR );
  175.                 if ( rgb != NULL )
  176.                 {
  177.                     if ( ConvertFromProof( pf, PFN_RGBTripletBuffer, rgb, TAG_DONE ) == PFERR_NONE )
  178.                     {
  179.                         WritePixelArray( rgb, 0, 0, pw * 3, win->RPort, 0, 0, pw, ph, RECTFMT_RGB );
  180.  
  181.                         Wait( 1L << win->UserPort->mp_SigBit );
  182.                         while ( ( msg = GetMsg( win->UserPort ) ) != NULL ) ReplyMsg( msg );
  183.                     }
  184.  
  185.                     FreeVec( rgb );
  186.                 }
  187.  
  188.                 CloseWindow( win );
  189.             }
  190.  
  191.             CloseScreen( scr );
  192.         }
  193.     }
  194. }
  195.