home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / xv310a / xvdflt.c < prev    next >
Text File  |  1995-06-12  |  16KB  |  364 lines

  1. /*
  2.  * xvdflt.c - load routine for 'default' XV image
  3.  *
  4.  * LoadDfltPic()  -  loads up 'pic'  note:  can't fail(!)
  5.  */
  6.  
  7. #include "copyright.h"
  8.  
  9. #include "xv.h"
  10.  
  11. #include "bits/logo_top"
  12. #include "bits/logo_bot"
  13. #include "bits/logo_out"
  14. #include "bits/xv_jhb"
  15. #include "bits/xv_cpyrt"
  16. #include "bits/xv_rev"
  17. #include "bits/xv_ver"
  18. #include "bits/xf_left"
  19. #include "bits/xf_right"
  20. #include "bits/font5x9.h"
  21.  
  22.  
  23. #ifndef USEOLDPIC
  24. #  include "xvdflt.h"  
  25. #endif
  26.  
  27.  
  28.  
  29. #define DWIDE 480
  30. #define DHIGH 270
  31.  
  32. static void loadOldDfltPic  PARM((PICINFO *));
  33. static void setcolor       PARM((PICINFO *, int, int, int, int));
  34. static void gen_bg         PARM((byte *, PICINFO *));
  35.  
  36.  
  37. /*******************************************/
  38. void LoadDfltPic(pinfo)
  39.      PICINFO *pinfo;
  40. {
  41.   char  str[256];
  42.   byte *dfltpic;
  43.   int   i, j, k, xdpline, nbytes;
  44.  
  45. #ifdef USEOLDPIC
  46.  
  47.   loadOldDfltPic(pinfo);
  48.  
  49. #else /* !USEOLDPIC */
  50.  
  51.   if (!ncols) {
  52.     loadOldDfltPic(pinfo);
  53.     return;
  54.   }
  55.  
  56.   dfltpic = (byte *) calloc((size_t) XVDFLT_WIDE * XVDFLT_HIGH, (size_t) 1);
  57.   if (!dfltpic) FatalError("couldn't malloc 'dfltpic' in LoadDfltPic()");
  58.  
  59.  
  60.   /* copy image from xvdflt_pic[] array */
  61.   xdpline = 0;
  62.   for (i=0; i<XVDFLT_HIGH; i++) {
  63.     nbytes = 0;
  64.     while (nbytes < XVDFLT_WIDE) {
  65.       char *sp;
  66.       byte *dp;
  67.  
  68.       j = XVDFLT_WIDE - nbytes;
  69.       if (j > XVDFLT_PARTLEN) j = XVDFLT_PARTLEN;
  70.  
  71.       sp = xvdflt_pic[xdpline];
  72.       dp = dfltpic + i*XVDFLT_WIDE + nbytes;
  73.       for (k=0; k<j; k++) {
  74.     int c1,c2;
  75.     c1 = *sp++;  c2 = *sp++;
  76.     if (c1>='a') c1 = 10+(c1-'a');
  77.                 else c1 = c1-'0';
  78.  
  79.     if (c2>='a') c2 = 10+(c2-'a');
  80.                 else c2 = c2-'0';
  81.  
  82.     *dp++ = (byte) ((c1<<4) | c2);
  83.       }
  84.  
  85.       nbytes += j;
  86.       xdpline++;
  87.     }
  88.   }
  89.  
  90.   /* load up colormaps */
  91.   for (i=0; i<256; i++) {
  92.     pinfo->r[i] = xvdflt_r[i];
  93.     pinfo->g[i] = xvdflt_g[i];
  94.     pinfo->b[i] = xvdflt_b[i];
  95.   }
  96.  
  97.  
  98.   setcolor(pinfo, 250, 248,184,120);   /* revdate */
  99.   setcolor(pinfo, 251, 255,255,255);   /* regstr  */
  100.   setcolor(pinfo, 252,   0,  0,  0);   /* black background for text */
  101.  
  102.  
  103.   xbm2pic((byte *) xv_cpyrt_bits, xv_cpyrt_width, xv_cpyrt_height, 
  104.        dfltpic, DWIDE, DHIGH, DWIDE/2+1, 203+1, 252);
  105.   xbm2pic((byte *) xv_cpyrt_bits, xv_cpyrt_width, xv_cpyrt_height, 
  106.        dfltpic, DWIDE, DHIGH, DWIDE/2,   203, 250);
  107.  
  108.   i = xv_ver_width + xv_rev_width + 30;
  109.  
  110.   xbm2pic((byte *) xv_ver_bits, xv_ver_width, xv_ver_height, 
  111.        dfltpic, DWIDE, DHIGH, DWIDE/2 - (i/2) + xv_ver_width/2+1, 220+1,252);
  112.   xbm2pic((byte *) xv_rev_bits, xv_rev_width, xv_rev_height, 
  113.        dfltpic, DWIDE, DHIGH, DWIDE/2 + (i/2) - xv_rev_width/2+1, 220+1,252);
  114.  
  115.   xbm2pic((byte *) xv_ver_bits, xv_ver_width, xv_ver_height, 
  116.        dfltpic, DWIDE, DHIGH, DWIDE/2 - (i/2) + xv_ver_width/2, 220, 250);
  117.   xbm2pic((byte *) xv_rev_bits, xv_rev_width, xv_rev_height, 
  118.        dfltpic, DWIDE, DHIGH, DWIDE/2 + (i/2) - xv_rev_width/2, 220, 250);
  119.  
  120.   strcpy(str,"Press <right> mouse button for menu.");
  121.   DrawStr2Pic(str, DWIDE/2+1, 241+1, dfltpic, DWIDE, DHIGH, 252);
  122.   DrawStr2Pic(str, DWIDE/2, 241, dfltpic, DWIDE, DHIGH, 250);
  123.  
  124.  
  125. #ifdef REGSTR
  126.   strcpy(str,REGSTR);
  127. #else
  128.   strcpy(str,"UNREGISTERED COPY:  See 'About XV' for registration info.");
  129. #endif
  130.  
  131.   DrawStr2Pic(str, DWIDE/2+1, 258+1, dfltpic, DWIDE, DHIGH, 252);
  132.   DrawStr2Pic(str, DWIDE/2, 258, dfltpic, DWIDE, DHIGH, 251);
  133.  
  134.  
  135.   pinfo->pic     = dfltpic;
  136.   pinfo->w       = XVDFLT_WIDE;
  137.   pinfo->h       = XVDFLT_HIGH;
  138.   pinfo->type    = PIC8;
  139.   pinfo->frmType = F_GIF;
  140.   pinfo->colType = F_FULLCOLOR;
  141.  
  142.   pinfo->normw   = pinfo->w;
  143.   pinfo->normh   = pinfo->h;
  144.  
  145.   sprintf(pinfo->fullInfo, "<8-bit internal>");
  146.   sprintf(pinfo->shrtInfo, "%dx%d image.", XVDFLT_WIDE, XVDFLT_HIGH);
  147.   pinfo->comment = (char *) NULL;
  148.  
  149. #endif /* !USEOLDPIC */
  150. }
  151.  
  152.  
  153.  
  154. /*******************************************/
  155. static void loadOldDfltPic(pinfo)
  156.      PICINFO *pinfo;
  157. {
  158.   /* load up the stuff XV expects us to load up */
  159.  
  160.   char str[256];
  161.   byte *dfltpic;
  162.   int   i, j, k;
  163.  
  164.   dfltpic = (byte *) calloc((size_t) DWIDE * DHIGH, (size_t) 1);
  165.   if (!dfltpic) FatalError("couldn't malloc 'dfltpic' in LoadDfltPic()");
  166.  
  167.  
  168.   if (ncols) {    /* draw fish texture */
  169.     for (i=k=0; i<DHIGH; i+=xf_left_height) {
  170.       for (j=0; j<DWIDE; j+=xf_left_width) {
  171.     k++;
  172.     if (k&1) 
  173.       xbm2pic((byte *) xf_left_bits, xf_left_width, xf_left_height,
  174.           dfltpic, DWIDE, DHIGH, j + xf_left_width/2,
  175.           i + xf_left_height/2, 1);
  176.       }
  177.     }
  178.   }
  179.  
  180.  
  181.  
  182.   xbm2pic((byte *) xvpic_logo_out_bits, xvpic_logo_out_width, 
  183.       xvpic_logo_out_height, dfltpic, DWIDE, DHIGH, DWIDE/2 + 10, 80, 103);
  184.  
  185.   xbm2pic((byte *) xvpic_logo_top_bits, xvpic_logo_top_width, 
  186.       xvpic_logo_top_height, dfltpic, DWIDE, DHIGH, DWIDE/2 + 10, 80, 100);
  187.  
  188.   xbm2pic((byte *) xvpic_logo_bot_bits, xvpic_logo_bot_width, 
  189.       xvpic_logo_bot_height, dfltpic, DWIDE, DHIGH, DWIDE/2 + 10, 80, 101);
  190.  
  191.  
  192.  
  193.   xbm2pic((byte *) xv_jhb_bits, xv_jhb_width, xv_jhb_height, 
  194.        dfltpic, DWIDE, DHIGH, DWIDE/2, 160, 102);
  195.  
  196.   xbm2pic((byte *) xv_cpyrt_bits, xv_cpyrt_width, xv_cpyrt_height, 
  197.        dfltpic, DWIDE, DHIGH, DWIDE/2, 203, 102);
  198.  
  199.   i = xv_ver_width + xv_rev_width + 30;
  200.  
  201.   xbm2pic((byte *) xv_ver_bits, xv_ver_width, xv_ver_height, 
  202.        dfltpic, DWIDE, DHIGH, DWIDE/2 - (i/2) + xv_ver_width/2, 220, 102);
  203.  
  204.   xbm2pic((byte *) xv_rev_bits, xv_rev_width, xv_rev_height, 
  205.        dfltpic, DWIDE, DHIGH, DWIDE/2 + (i/2) - xv_rev_width/2, 220, 102);
  206.  
  207.   strcpy(str,"Press <right> mouse button for menu.");
  208.   DrawStr2Pic(str, DWIDE/2, 241, dfltpic, DWIDE, DHIGH, 102);
  209.  
  210.   strcpy(str,"UNREGISTERED COPY:  See 'About XV' for registration info.");
  211.  
  212. #ifdef REGSTR
  213.   strcpy(str,REGSTR);
  214. #endif
  215.  
  216.   DrawStr2Pic(str, DWIDE/2, 258, dfltpic, DWIDE, DHIGH, 104);
  217.  
  218.   setcolor(pinfo, 0, 225,  150, 255);  /* top-left fish color */
  219.   setcolor(pinfo, 15, 55,    0,  77);  /* bot-right fish color */
  220.   setcolor(pinfo, 16, 150, 150, 255);  /* top-left background color */
  221.   setcolor(pinfo, 63,   0,   0,  77);  /* bottom-right background color */
  222.  
  223.   if (ncols) gen_bg(dfltpic, pinfo);
  224.  
  225.   /* set up colormap */
  226.   setcolor(pinfo, 100, 255,213, 25);   /* XV top half */
  227.   setcolor(pinfo, 101, 255,000,000);   /* XV bottom half */
  228.   setcolor(pinfo, 102, 255,208,000);   /* jhb + fish + revdate */
  229.   setcolor(pinfo, 103, 220,220,220);   /* XV backlighting */
  230.   setcolor(pinfo, 104, 255,255,255);   /* registration string */
  231.  
  232.   if (ncols==0) {
  233.     setcolor(pinfo,   0, 0, 0, 0);
  234.     setcolor(pinfo, 102,255,255,255);
  235.     setcolor(pinfo, 103,255,255,255);
  236.     setcolor(pinfo, 104,255,255,255);
  237.   }
  238.  
  239.   pinfo->pic     = dfltpic;
  240.   pinfo->w       = DWIDE;
  241.   pinfo->h       = DHIGH;
  242.   pinfo->type    = PIC8;
  243.   pinfo->frmType = F_GIF;
  244.   pinfo->colType = F_FULLCOLOR;
  245.  
  246.   sprintf(pinfo->fullInfo, "<8-bit internal>");
  247.   sprintf(pinfo->shrtInfo, "%dx%d image.",DWIDE, DHIGH);
  248.   pinfo->comment = (char *) NULL;
  249. }
  250.  
  251.  
  252.  
  253. /*******************************************/
  254. void xbm2pic(bits, bwide, bhigh, pic, pwide, phigh, cx, cy, col)
  255.      byte *bits;
  256.      byte *pic;
  257.      int   bwide, bhigh, pwide, phigh, cx, cy, col;
  258. /*******************************************/
  259. {
  260.   /* draws an X bitmap into an 8-bit 'pic'.  Only '1' bits from the bitmap
  261.      are drawn (in color 'col').  '0' bits are ignored */
  262.  
  263.   int     i, j, k, bit, x, y;
  264.   byte   *pptr, *bptr;
  265.  
  266.   y = cy - bhigh/2;
  267.  
  268.   for (i=0; i<bhigh; i++,y++) {
  269.     if ( (y>=0) && (y<phigh) ) {
  270.       pptr = pic + y * pwide;
  271.       bptr = (byte *) bits + i * ((bwide+7)/8);
  272.       x = cx - bwide/2;
  273.  
  274.       k = *bptr;
  275.       for (j=0,bit=0; j<bwide; j++, bit = (++bit)&7, x++) {
  276.     if (!bit) k = *bptr++;
  277.     if ( (k&1) && (x>=0) && (x<pwide))
  278.       pptr[x] = col;
  279.  
  280.     k = k >> 1;
  281.       }
  282.     }
  283.   }
  284. }  
  285.  
  286.  
  287. /*******************************************/
  288. static void setcolor(pinfo, i, rv, gv, bv)
  289.      PICINFO *pinfo;
  290.      int i, rv, gv, bv;
  291. {
  292.   pinfo->r[i] = rv;
  293.   pinfo->g[i] = gv;
  294.   pinfo->b[i] = bv;
  295. }
  296.  
  297.  
  298. /*******************************************/
  299. static void gen_bg(dfltpic, pinfo)
  300.      byte    *dfltpic;
  301.      PICINFO *pinfo;
  302. {
  303.   int i,j,k, dr, dg, db;
  304.   byte *pp;
  305.  
  306.   pp = dfltpic;
  307.   for (i=0; i<DHIGH; i++)
  308.     for (j=0; j<DWIDE; j++, pp++) {
  309.       if (*pp == 0) {
  310.     *pp = 16 + ((i+j) * 48) / (DHIGH + DWIDE);
  311.       }
  312.       else if (*pp == 1) {
  313.     *pp = ((i+j) * 16) / (DHIGH + DWIDE);
  314.       }
  315.     }
  316.  
  317.  
  318.   /* color gradient in cells 0-15 */
  319.   for (i=1; i<15; i++) {
  320.     dr = (int) pinfo->r[15] - (int) pinfo->r[0];
  321.     dg = (int) pinfo->g[15] - (int) pinfo->g[0];
  322.     db = (int) pinfo->b[15] - (int) pinfo->b[0];
  323.  
  324.     setcolor(pinfo, i, (int) pinfo->r[0] + (dr * i) / 15,
  325.                    (int) pinfo->g[0] + (dg * i) / 15,
  326.                        (int) pinfo->b[0] + (db * i) / 15);
  327.   }
  328.  
  329.   /* color gradient in cells 16-63 */
  330.   for (i=17, j=1; i<63; i++,j++) {
  331.     dr = (int) pinfo->r[63] - (int) pinfo->r[16];
  332.     dg = (int) pinfo->g[63] - (int) pinfo->g[16];
  333.     db = (int) pinfo->b[63] - (int) pinfo->b[16];
  334.  
  335.     setcolor(pinfo, i, (int) pinfo->r[16] + (dr * j)/47,
  336.                        (int) pinfo->g[16] + (dg * j)/47,
  337.                        (int) pinfo->b[16] + (db * j)/47);
  338.   }
  339. }
  340.  
  341.  
  342.  
  343. /*******************************************/
  344. void DrawStr2Pic(str, cx, cy, pic, pw, ph, col)
  345.      char *str;
  346.      byte *pic;
  347.      int   cx, cy, pw, ph, col;
  348. {
  349.   /* draw string (in 5x9 font) centered around cx,cy, in color 'col' */
  350.  
  351.   int  i;
  352.  
  353.   i = strlen(str);
  354.   if (!i) return;
  355.  
  356.   cx -= ((i-1) * 3);
  357.  
  358.   for ( ; *str; str++, cx+=6) {
  359.     i = (byte) *str;
  360.     if (i >= 32 && i < 128) 
  361.       xbm2pic(font5x9[i - 32], 5, 9, pic, pw, ph, cx, cy, col);
  362.   }
  363. }