home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Painting / XiPaint3.2-Aminet11.lzx / XiPaint / Developer / Modules / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-06  |  5.3 KB  |  207 lines

  1. /* Last Change: Thomas /   3. August 1995  07:27:56 */
  2.  
  3. // Multipic Loader/Saver
  4. /****  System-Includes  ****/
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include <exec/exec.h>
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <exec/execbase.h>
  14. #include <exec/ports.h>
  15.  
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20.  
  21.  
  22. /****  benötigte Strukturen und Kommandos  ****/
  23.  
  24. #include "XiUser.h"
  25.  
  26.  
  27. /****  Prototypes der verwendeten Funktionen  ****/
  28.  
  29. int main(int argc, char **argv);
  30.  
  31. void WaitReply(struct MsgPort *ReplyPort, struct Message *WaitMsg);
  32.  
  33.  
  34.  
  35. #define KENNUNG "XIPAINT-EXTERNAL000"
  36. struct xi_ext_header{
  37.   char key[20];             // XIPAINT-EXTERNAL000
  38.   WORD version, revision;   // From XiPaint
  39.   char what;                // L=Loader, S=Saver, F=Filter
  40.   char format[20];          // Which format
  41.   char author[40];          // Name and Copyright from Author
  42.   WORD dver, drev;          // Version of this driver
  43.   char f24,f16,f8,f4,f2,f1; // supported depths (0/1) (saver!)
  44.   char alpha,clut,cmap;     // 0/1
  45.   };
  46.  
  47.  
  48. struct io_pic{
  49.   struct io_pic *next;    // For internal chaining
  50.   UWORD picw, pich;       // Real Picdimension
  51.   UWORD memw, memh;       // Memory-Dimension (for loading)
  52.   char *memory;           // Memory to save from
  53.   char name[128];         // Full name with path for saver
  54.   char param[128];        // Special parameter from user
  55.   char port[30];          // Name of the XiPaint - Port
  56.   UWORD xdpi, ydpi;       // DPI-Chunk
  57.   char depth;             // 1,2,4,8,16,24
  58.   char jpegf;             // Jpeg loss factor
  59.   char jpegs;             // Jpeg smooth 0/1
  60.   char *clut;             // Pointer to a clut (clutf-entries)
  61.   struct xi_ext_header ext; //
  62.   /*                       Nur für dieses Modul ... */
  63.   char proname[80];       // Projektname
  64.   WORD brushnr;           // Brushnummer
  65.   char todo;              // Brush/Load/pAlette
  66.   };
  67.  
  68. struct xi_ext_header info =
  69. {
  70.   "XIPAINT-EXTERNAL000",
  71.   3,2,
  72.   'L',
  73.   "TESTFORMAT",
  74.   "Thomas Dorn/MacroSystem",
  75.   1,0,
  76.   1,0,0,0,0,0,
  77.   0,0,0,
  78. };
  79.  
  80. struct xi_ext_header info2 =
  81. {
  82.   "XIPAINT-EXTERNAL000",
  83.   3,2,
  84.   'S',
  85.   "TESTFORMAT2",
  86.   "Thomas Dorn",
  87.   1,0,
  88.   1,0,0,0,0,0,
  89.   0,0,0,
  90. };
  91.  
  92. void usage (char *pname)
  93. {
  94.   fprintf(stderr,"Usage: %s [-n filename]\n",pname);
  95.   exit( EXIT_FAILURE);
  96. }
  97.  
  98. int main(int argc, char **argv)
  99.   {
  100.     struct io_pic io;
  101.     struct MsgPort *XiUserPort, *XiReplyPort;
  102.     struct XiMessage XiMsg;
  103.     short i=1, j;
  104.  
  105.   memset(&io,0,sizeof(io_pic);
  106.   io.todo = 'P';    // New Project is default
  107.  
  108.   // Auswerten der Kommandozeile (natuerlich nicht sooo)
  109.   strcpy(io.name,argv[1]);
  110.  
  111.  
  112. /**  Finden des User-Ports  **/
  113.  
  114.     if ( (XiUserPort = FindPort((UBYTE *)"xiuser.port")) == NULL )
  115.       {
  116.         printf(" User-Port nicht gefunden, läuft XiPaint überhaupt ???\n");
  117.         exit(40);
  118.       }
  119.     printf("xiuser.port gefunden\n");
  120.  
  121. /**  einen Reply-Port einrichten  **/
  122.  
  123.     if ( (XiReplyPort = CreatePort(NULL, 0)) == NULL )
  124.       {
  125.         printf(" Konnte den Reply-Port nicht einrichten !!\n");
  126.         exit(40);
  127.       }
  128.     printf("Replyport errichtet\n");
  129.  
  130. /**  Initialisieren der Message (kann nach Reply wiederverwendet werden)  **/
  131.  
  132.     memset(&XiMsg, 0, sizeof(struct XiMessage));
  133.  
  134.  
  135.     XiMsg.ExecMess.mn_Node.ln_Type = NT_MESSAGE;
  136.     XiMsg.ExecMess.mn_Node.ln_Pri = 0;
  137.     XiMsg.ExecMess.mn_Length = sizeof(struct XiMessage);
  138.     XiMsg.ExecMess.mn_ReplyPort = XiReplyPort;
  139.     XiMsg.Label = 0x12345678;                           /* Erkennungsmarke für XiPaint, sehr wichtig !!!! */
  140.  
  141.     printf("xiMsg initialisiert\n");
  142.  
  143.  
  144.      // Brushmem holen
  145.  
  146.     XiMsg.Command = XI_NEW_BRUSH;                             /* Kommando ausfüllen */
  147.     XiMsg.Width = 100;                                          /* Größe des Projekts */
  148.     XiMsg.Height = 100;
  149.  
  150.     PutMsg(XiUserPort, (struct Message *)&XiMsg);               /* Message absenden */
  151.     WaitReply(XiReplyPort, (struct Message *)&XiMsg);           /* Warten auf Reply, siehe Fkt. unten */
  152.  
  153.     if ( XiMsg.Success == TRUE )                        /* Aktion war erfolgreich */
  154.       {
  155.         printf("Bruhs erzeugt,  Größe  %d x %d\n", XiMsg.Width, XiMsg.Height);
  156.  
  157.         for(j=50; j<80; j++)                           /* Zeichnen eines grünen Rechteckes -> Test */
  158.           {
  159.             for(i=50; i<80; i++)
  160.               {
  161.                 *((ULONG *)XiMsg.Memory + j * XiMsg.Width + i ) = 0xFFFF00FF;
  162.               }
  163.           }
  164.         // Brush in Liste aufnehmen
  165.  
  166.         XiMsg.Command = XI_UPDATE_BRUSH;                      /* Kommando ausfüllen */
  167.  
  168.         PutMsg(XiUserPort, (struct Message *)&XiMsg);           /* Message absenden */
  169.         WaitReply(XiReplyPort, (struct Message *)&XiMsg);       /* Warten auf Reply, siehe Fkt. unten, Erfolgscheck nicht notwendig */
  170.       }
  171.     else
  172.       {
  173.         printf(" Konnte Brush nicht erzeugen -> Ende !!\n");
  174.         exit(0);
  175.       }
  176.  
  177. /**  Aufräumen und Ende  **/
  178.  
  179.     DeletePort(XiReplyPort);
  180.     exit(0);
  181.   }
  182.  
  183.  
  184.  
  185. /************
  186.  
  187.   Funktion wartet solange, bis die gesendete Message "WaitMsg" von an den
  188.   Reply-Port zurückgekommen ist
  189.  
  190. ************/
  191.  
  192. void WaitReply(struct MsgPort *ReplyPort, struct Message *WaitMsg)
  193.   {
  194.     struct Message *OkMsg;
  195.     BOOL Loop=TRUE;
  196.  
  197.     while(Loop)
  198.       {
  199.         WaitPort(ReplyPort);
  200.  
  201.         while( OkMsg = GetMsg(ReplyPort) )
  202.           {
  203.             if ( OkMsg == WaitMsg )
  204.                 Loop = FALSE;
  205.           }
  206.       }
  207.   }