home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / DSHJ2 / METAMAKE.BAK < prev    next >
Encoding:
Text File  |  2001-02-10  |  12.3 KB  |  515 lines

  1. /*************************************************************************/
  2. /* METAMAKE.C                                 */
  3. /* DATE CREATED:  0/0/0                             */
  4. /* LAST MODIFIED: 09/21/88                         */
  5. /*************************************************************************/
  6.  
  7. #include    <osbind.h>
  8. #include    <gemdefs.h>
  9. #include    "alert.h"
  10.  
  11. #define GDP        11
  12. #define LINE_WIDTH    16
  13. #define MARKER_HEIGHT    19
  14. #define VST_HEIGHT    12
  15. #define VST_POINT    107
  16. #define V_UPDATE    4
  17. #define ARC        2
  18. #define PIE        3
  19. #define CIRCLE        4
  20. #define ELLIPSE        5
  21. #define ELLARC        6
  22. #define ELLPIE        7
  23. #define JUSTEXT        10
  24. #define V_CLEAR        3
  25. #define VGTEXT        8
  26. #define ESCAPE        5
  27. #define V_WRITE        99
  28. #define V_CLIP        129
  29.  
  30. extern    int    contrl[], intin[], ptsin[], intout[], ptsout[];
  31. extern  int    ptsarray[];
  32.  
  33. extern  FDB    page_MFDB;
  34. extern  FDB    laser_MFDB;
  35. extern    int    mhandle;    /* memory driver handle        */
  36. extern     int     phandle;
  37.  
  38. extern  int     scan_xres;
  39. extern  long    scanptr;
  40.  
  41. extern  int    print_flag;
  42. extern  char *get_lcmem();
  43. extern  int     hpage_size;
  44. extern  int     vpage_size;
  45. extern  char    fbuffer[];
  46. extern  char *dpath1;
  47. extern  char *dpath2;
  48. extern  char *dpath3;
  49. extern  char *dpath4;
  50. extern  int scan_xres,scan_yres;
  51. extern  int mxres,myres;
  52. extern  unsigned long page_ptr;
  53.  
  54. extern  int mnumfnt;
  55. extern  int pnumfnt;
  56.  
  57. int font_flag;
  58.  
  59.  
  60. long readswap();
  61.  
  62. int    meta_wd, meta_ht;
  63. int    formw, formy;
  64.  
  65. int logo[16] = {
  66.          0x05a0,0x5a0,0x5a0,0x5a0,0xdb0,0x0db0,0x1db8,0x399c,
  67.          0x799e,0x718e,0x718e,0x6186,0x4182,0,0,0
  68.            };
  69.  
  70. long    readswap(handle, length, buffer)
  71. long    length;
  72. int    handle;
  73. register char    *buffer;
  74. {
  75.     register long    count;
  76.         long bytes_read;
  77.     char    temp;
  78.  
  79.     bytes_read = Fread(handle,length,buffer);
  80.     for (count = 0;count < bytes_read;count += 2) {
  81.       temp         = buffer[count];
  82.       buffer[count]  = buffer[count+1];
  83.       buffer[count+1]= temp;
  84.     }
  85.     return(bytes_read);
  86. }
  87.  
  88. mtadjx(x)
  89. int    x;
  90. {
  91.     return((int)(((long)x * (long)formw) / (long)meta_wd));
  92. }
  93.  
  94. mtadjy(y)
  95. int    y;
  96. {
  97.     return((int)(((long)y * (long)formy) / (long)meta_ht));
  98. }
  99.  
  100.  
  101. /********************************/
  102. /*    MetaFile display    */
  103. /********************************/
  104. meta_make(handle, mx, my,mw,mh)
  105. register int    handle;
  106. int    mx, my, mw, mh;
  107. {
  108.    int  x1,y1,wid,ht;
  109.    register int    i;
  110.    int  dummy, header_length;
  111.    int    pagex, pagey, llx, lly, urx, ury;
  112.    register int  thandle;
  113.  
  114.    /*    first word is 0fffh    */
  115.    Fread(handle, 2L, &dummy);
  116.  
  117.    /*    read length of header in words    */
  118.    readswap(handle, 2L, &header_length);
  119.  
  120.    /*    skip over version number    */
  121.    Fread(handle, 2L, &dummy);
  122.  
  123.    /*    get scaling factors    */
  124.    readswap(handle, 2L, &dummy);    /* rc_ndc not used    */
  125.    readswap(handle, 2L, &dummy);    /* minx not used    */
  126.    readswap(handle, 2L, &dummy);    /* miny not used    */
  127.    readswap(handle, 2L, &dummy);    /* maxx not used    */
  128.    readswap(handle, 2L, &dummy);    /* maxy not used    */
  129.    readswap(handle, 2L, &pagex);
  130.    readswap(handle, 2L, &pagey);
  131.    readswap(handle, 2L, &llx);
  132.    readswap(handle, 2L, &lly);
  133.    readswap(handle, 2L, &urx);
  134.    readswap(handle, 2L, &ury);
  135.  
  136.    /*    seek past the header    */
  137.    Fseek((long)header_length * 2L, handle, 0);
  138.  
  139.    meta_wd    = urx - llx + 1;
  140.    meta_ht    = lly - ury + 1;
  141.  
  142.  
  143.    if(print_flag== 1)  /* Convert to pixels and scale  */
  144.    {
  145.         mutolas(mx,my,&x1,&y1);
  146.         mutolas(mw,mh,&wid,&ht);
  147.         thandle = phandle;
  148.    }
  149.    else if(!print_flag)
  150.    {
  151.         mutopage(mx,my,&x1,&y1,0);
  152.         mutopage(mw,mh,&wid,&ht,1);
  153.         thandle = mhandle;
  154.    }
  155.    else if(print_flag == 2)
  156.    {                    /* Special case for repel image */
  157.     mutomem(mx,my,&x1,&y1);
  158.     mutomem(mw,mh,&wid,&ht);
  159.     thandle = mhandle;
  160.     GDvq_extnd(mhandle,0,intout,scan_xres,scan_yres,&scanptr);
  161.    }
  162.  
  163.    formw = wid;
  164.    formy = ht;
  165.  
  166.    for (;;) {
  167.     /*    read opcode    */
  168.     readswap(handle, 2L, &contrl[0]);
  169.     if (contrl[0]==0xFFFF) break;
  170.  
  171.     /*    read vertex count    */
  172.     readswap(handle, 2L, &contrl[1]);
  173.       
  174.     /*    read integer count    */
  175.     readswap(handle, 2L, &contrl[3]);
  176.  
  177.     /*    read sub-opcode        */
  178.     readswap(handle, 2L, &contrl[5]);
  179.       
  180.     /*    read in points and swap    */
  181.     readswap(handle, (long)contrl[1] * 4L, ptsin);
  182.  
  183.     /*    transform co-ords    */
  184.     switch (contrl[0]) {
  185.     case GDP:
  186.        switch (contrl[5]) {
  187.        case CIRCLE:
  188.        case ARC:
  189.        case PIE:
  190.        case ELLIPSE:
  191.        case ELLPIE:
  192.        case ELLARC:
  193.        case JUSTEXT:
  194.         ptsin[0] = x1 + mtadjx(ptsin[0]-llx);
  195.         ptsin[1] = y1 + mtadjy(ptsin[1]-ury);
  196.         for (i = 2;i < (contrl[1] * 2);i += 2) {
  197.            ptsin[i]   = mtadjx(ptsin[i]  );
  198.            ptsin[i+1] = mtadjy(ptsin[i+1]);
  199.         }
  200.         break;
  201.        default:
  202.         goto others;
  203.        }
  204.        break;
  205.     case LINE_WIDTH:
  206.     case MARKER_HEIGHT:
  207.     case VST_HEIGHT:
  208.        ptsin[0] = mtadjx(ptsin[0]);
  209.        ptsin[1] = mtadjy(ptsin[1]);
  210.        break;
  211.     default:
  212.     others:
  213.        for (i = 0;i < (contrl[1] * 2);i += 2) {
  214.         ptsin[i]   = x1 + mtadjx(ptsin[i]  -llx);
  215.         ptsin[i+1] = y1 + mtadjy(ptsin[i+1]-ury);
  216.        }
  217.        break;
  218.     }
  219.  
  220.     /*    read in ints and swap    */
  221.     readswap(handle, (long)contrl[3] * 2L, intin);
  222.  
  223.     /*    for scaled image, change vst_point to vst_height
  224.         and transform sizes    */
  225.     if (contrl[0] == VST_POINT) {
  226.       contrl[0] = VST_HEIGHT;
  227.       contrl[1] = 1;
  228.       contrl[3] = 0;
  229.       ptsin[0]  = 0;
  230.       ptsin[1]  = (int)(((long)intin[0] *3L* (long)formy)/ (long)pagey);
  231.     }
  232.  
  233.     if((contrl[0] != V_UPDATE) && (contrl[0] != V_CLEAR) &&
  234.            (contrl[0] != V_CLIP))
  235.     {
  236.           if(
  237.               ((contrl[0] == VGTEXT) ||
  238.           ((contrl[0] == GDP) && (contrl[5] == JUSTEXT)))
  239.             )
  240.           {
  241.          if(((phandle == thandle) && pnumfnt) ||
  242.             ((mhandle == thandle) && mnumfnt) )
  243.          {
  244.               contrl[6] = thandle;
  245.            vdi();
  246.          }
  247.           }
  248.           else
  249.       {
  250.          if(contrl[0] == ESCAPE)
  251.          {
  252.         if(contrl[5] != V_WRITE)
  253.         {
  254.                contrl[6] = thandle;
  255.                vdi();
  256.         }
  257.              }
  258.              else
  259.              {    
  260.            contrl[6] = thandle;
  261.            vdi();
  262.          }
  263.           }
  264.     }
  265.    }
  266.    if(print_flag == 2)
  267.     GDvq_extnd(mhandle,0,intout,mxres,myres,&page_ptr);    
  268.  
  269.    vsf_udpat(thandle,logo,1);        /* user pattern to Atari Logo*/
  270.    vsl_type(thandle,1);            /* Line type to solid         */
  271.    vsl_width(thandle,1);        /* Line width to 1         */
  272.    vsl_ends(thandle,0,0);        /* end points to squares...  */
  273.  
  274.    vswr_mode(thandle,1);        /* set to replace...         */
  275.    vst_color(thandle,1);        /* set text, fill and line   */
  276.    vsf_color(thandle,1);        /* color index to 1         */
  277.    vsl_color(thandle,1);   
  278. }
  279.  
  280.  
  281.  
  282. /********************************/
  283. /*    IMG File display    */
  284. /********************************/
  285. disp_img(filename,x1,y1,x2,y2)
  286. register char    *filename;
  287. int    x1,y1,x2,y2;
  288. {
  289.     int     thandle;
  290.     register int    i;
  291.     int    tx1,ty1,tx2,ty2;
  292.  
  293.        if(print_flag == 1)  /* Convert to pixels and scale  */
  294.        {
  295.            mutolas(x1,y1,&tx1,&ty1);
  296.            mutolas(x2,y2,&tx2,&ty2);
  297.            thandle = phandle;
  298.        }
  299.        else if(!print_flag)
  300.        {
  301.            mutopage(x1,y1,&tx1,&ty1,0);
  302.            mutopage(x2,y2,&tx2,&ty2,0);
  303.            thandle = mhandle;
  304.        }
  305.     else if(print_flag == 2)
  306.         {
  307.        mutomem(x1,y1,&tx1,&ty1);
  308.        mutomem(x2,y2,&tx2,&ty2);
  309.        thandle = mhandle;
  310.        GDvq_extnd(mhandle,0,intout,scan_xres,scan_yres,&scanptr);       
  311.         }
  312.     
  313.     contrl[0] = 5;
  314.     contrl[1] = 2;
  315.     contrl[2] = 0;
  316.     contrl[4] = 0;
  317.     contrl[5] = 23;
  318.     contrl[6] = thandle;
  319.     intin[0]  = intin[1] = intin[2] = intin[3] = intin[4] = 0;
  320.  
  321.     for (i = 0;filename[i];intin[i+5] = (int)filename[i++]);
  322.     contrl[3] = i + 5;
  323.  
  324.     ptsin[0]  = tx1;
  325.     ptsin[1]  = ty1;
  326.     ptsin[2]  = tx2;
  327.     ptsin[3]  = ty2;
  328.     vdi();
  329. /*    if(print_flag == 0 || print_flag == 2)*/
  330.         v_clear_disp_list(mhandle);        /* Frees up image buffers */
  331.     if(print_flag == 2)
  332.         GDvq_extnd(mhandle,0,intout,mxres,myres,&page_ptr);
  333.  
  334. }
  335.  
  336.  
  337. /********************************/
  338. /*    NEO File display    */
  339. /********************************/
  340. disp_neo(grbuf,cobuf,x1,y1,w,h)
  341. unsigned char    *grbuf;
  342. unsigned    *cobuf;
  343. int    x1, y1;
  344. int     w,h;
  345. {
  346.         int tmp;
  347.  
  348.     struct    {
  349.       unsigned char    *sMF;    /* +00 Source Memory Form base address    */
  350.       unsigned    swb;    /* +04 Width of memory form (in bytes)    */
  351.       unsigned    sx;    /* +06 Xmin of source rectangle        */
  352.       unsigned    sy;    /* +08 Ymin of source rectangle        */
  353.       unsigned    sw;    /* +10 Width    (in pixels)        */
  354.       unsigned    sh;    /* +12 Height    (in pixels)        */
  355.  
  356.       unsigned long    dMF;    /* +14 Target Memory Form base address    */
  357.       unsigned    dwb;    /* +18 Width of memory form (in bytes)    */
  358.       unsigned    dx;    /* +20 Xmin of target rectangle        */
  359.       unsigned    dy;    /* +22 Ymin of target rectangle        */
  360.       unsigned    dw;    /* +24 Width    (in pixels)        */
  361.       unsigned    dh;    /* +26 Height    (in pixels)        */
  362.     }    neo;
  363.  
  364.     neo.sMF    = grbuf;
  365.     neo.swb    = 160;
  366.     neo.sx    = 0;
  367.     neo.sy    = 0;
  368.     neo.sw    = 320;
  369.     neo.sh    = 200;
  370.  
  371.     if(x1 < 0)
  372.     {
  373.         neo.sx = scale_iv(abs(x1),320,w);
  374.         w  -= abs(x1);
  375.         x1 = 0;
  376.         neo.sw -= neo.sx;
  377.     }
  378.             
  379.     if((x1 + w) > hpage_size) 
  380.     {
  381.             tmp = (x1 + w) - hpage_size; 
  382.         neo.sw -= scale_iv(tmp,320,w);
  383.         w -= tmp;
  384.       }
  385.         
  386.         if(y1 < 0)
  387.     {
  388.             neo.sy = scale_iv(abs(y1),200,h);
  389.         h -= abs(y1);
  390.         y1 = 0;
  391.         neo.sh -= neo.sy;
  392.     }
  393.  
  394.     if((y1 + h) > vpage_size)
  395.     {
  396.             tmp = (y1 + h) - vpage_size;
  397.           neo.sh -= scale_iv(tmp,200,h);
  398.         h -= tmp;
  399.     }
  400.     
  401.         if(print_flag == 1)  /* Convert to pixels and scale  */
  402.         {
  403.             mutolas(x1,y1,&neo.dx,&neo.dy);
  404.             mutolas(w,h,&neo.dw,&neo.dh);
  405.            neo.dMF = laser_MFDB.fd_addr;
  406.            neo.dwb = laser_MFDB.fd_w/8;
  407.            neo.dwb += 1;
  408.            neo.dwb &= 0xFFFE;
  409.            neo.dw--;
  410.         }
  411.         else if(!print_flag)
  412.         {
  413.             mutopage(x1,y1,&neo.dx,&neo.dy,0);
  414.             mutopage(w,h,&neo.dw,&neo.dh,1);
  415.            neo.dMF    = page_MFDB.fd_addr;
  416.            neo.dwb    = page_MFDB.fd_w / 8;
  417.            neo.dwb += 1;
  418.            neo.dwb &= 0xFFFE;
  419.            neo.dw--;
  420.         }
  421.     else if(print_flag == 2)
  422.     {
  423.            mutomem(x1,y1,&neo.dx,&neo.dy);
  424.            mutomem(w,h,&neo.dw,&neo.dh);
  425.            neo.dMF  = scanptr;
  426.            neo.dwb  = scan_xres / 8;
  427.            neo.dwb += 1;
  428.            neo.dwb &= 0xFFFe;
  429.            neo.dw--;
  430.     }
  431.  
  432.     haftone(&neo,cobuf);
  433. }
  434.  
  435.  
  436.  
  437. /****************************************************************
  438. *    Function Name :        insert_graphic()        *
  439. *    Desc :    This routine handles graphics file insertion.    *
  440. *    Calling convention :    insert_graphic(cmd_ptr,arg)    *
  441. *        unsigned char    cmd_ptr : pointer to command    *
  442. *        unsigned    arg : argument value        *
  443. ****************************************************************/
  444. insert_graphic()
  445. {
  446.     unsigned char    *gfile;
  447.     long    grbuf;
  448.     int    cobuf[16];
  449.     register int    fid;
  450.     int    w, h, pw, ph;
  451.  
  452.     
  453.    gfile    = &ptsarray[5];      /* graphics image DOS filename    */
  454.    strcpy(fbuffer,dpath3);
  455.    strcat(fbuffer,gfile);
  456.    if (((fid = Fopen(fbuffer,0)) <= 0)) 
  457.    {
  458.       alert_cntre(ALERT16);
  459.       return;
  460.    }
  461.    switch((int)ptsarray[4]) {
  462.     case 0    :                /* NEOchrome image    */
  463.         grbuf = (long)get_lcmem(32000L);
  464.         if(!grbuf)
  465.         {
  466.            alert_cntre(ALERT32);
  467.            Fclose(fid);
  468.            return;
  469.         }
  470.         Fseek(4L,fid,0);        /* skip first 4 bytes    */
  471.         Fread(fid,32L,cobuf);        /* read color buffer    */
  472.         Fseek(128L,fid,0);        /* skip 128bytes header */
  473.         Fread(fid,32000L,grbuf);    /* read file bit block    */
  474.         disp_neo(grbuf,cobuf,ptsarray[0],ptsarray[1],
  475.               ptsarray[2] - ptsarray[0],
  476.               ptsarray[3] - ptsarray[1]);
  477.         free(grbuf);            /* free graphics buffer */
  478.         break;
  479.     case 1    :                /* IMG (Gem bit) image    */
  480.         Fseek(8L,fid,0);        /* skip 8 bytes header    */
  481.         Fread(fid,2L,&pw);        /* read pixel micron W    */
  482.         Fread(fid,2L,&ph);        /* read pixel micron H    */
  483.         Fread(fid,2L,&w);        /* read width  of page    */
  484.         Fread(fid,2L,&h);        /* read height of page    */
  485.         disp_img(fbuffer,ptsarray[0],ptsarray[1],
  486.              ptsarray[2],ptsarray[3]);
  487.         break;
  488.     case 2    :                /* Gem Metafile image    */
  489.         meta_make(fid,ptsarray[0],ptsarray[1],
  490.               ptsarray[2] - ptsarray[0],
  491.               ptsarray[3] - ptsarray[1]);
  492.         break;
  493.  
  494.     case 3  :                /* PI1 Degas Low Rez    */
  495.         grbuf = (long)get_lcmem(32000L);
  496.         if(!grbuf)
  497.         {
  498.            alert_cntre(ALERT32);
  499.            Fclose(fid);
  500.            return;
  501.         }
  502.         Fseek(2L,fid,0);        /* skip first 2 bytes    */
  503.         Fread(fid,32L,cobuf);        /* read color buffer    */
  504.         Fseek(34L,fid,0);        /* skip 34 bytes header */
  505.         Fread(fid,32000L,grbuf);    /* read file bit block    */
  506.         disp_neo(grbuf,cobuf,ptsarray[0],ptsarray[1],
  507.               ptsarray[2] - ptsarray[0],
  508.               ptsarray[3] - ptsarray[1]);
  509.         free(grbuf);            /* free graphics buffer */
  510.         break;
  511.    }
  512.    Fclose(fid);                /* close graphics file    */
  513.  
  514. }
  515.