home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / xaes_new / image.c < prev    next >
C/C++ Source or Header  |  1994-09-19  |  5KB  |  208 lines

  1. /********************************************************************
  2.  *                                                                1.00*
  3.  *    XAES: Image manipulation module                                    *
  4.  *    Code by Ken Hollis and Karl Anders 0ygard                        *
  5.  *                                                                    *
  6.  *    This modules deals with all image transforming and scaling etc.    *
  7.  *    These routines don't like XAES too much.  I will go ahead        *
  8.  *    and add Christian Grunenberg's routines from E_GEM.                *
  9.  *                                                                    *
  10.  ********************************************************************/
  11.  
  12. #include <vdi.h>
  13.  
  14. #include "xaes.h"
  15.  
  16. #ifndef __IMAGES__
  17. #define __IMAGES__
  18. #endif
  19.  
  20. /*
  21.  *    Scale coordinates
  22.  */
  23. LOCAL void scale_coords(int *w, int *h)
  24. {
  25.     *w = (((*w) * image_w) + 7) >> 4;
  26.     *h = (((*h) * image_h) + 7) >> 4;
  27. }
  28.  
  29. /*
  30.  *    Initialize mfdb block
  31.  *
  32.  *    *fm = mfdb to initialize
  33.  *    w = width of mfdb
  34.  *    h = height of mfdb
  35.  *    st = 0/1 - standardformat/dependent
  36.  *    pl = bitplanes
  37.  */
  38. GLOBAL void init_mfdb(MFDB *fm, int *adr, int w, int h, int st, int pl)
  39. {
  40.     fm->fd_addr        = adr;
  41.     fm->fd_w        = (w + 15) & 0xfff0;
  42.     fm->fd_h        = h;
  43.     fm->fd_wdwidth    = fm->fd_w >> 4;
  44.     fm->fd_stand    = st;
  45.     fm->fd_nplanes    = pl;
  46. }
  47.  
  48. /*
  49.  *    Scale image
  50.  *
  51.  *    *src = pointer to image to scale
  52.  *    w, h = width and heigth of image
  53.  *    mode = scaling mode
  54.  *    *b_w, *b_h = pointers to integers to contain new width and height
  55.  *
  56.  *    Returns: nothing
  57.  */
  58. GLOBAL void scale_img(int *src, int w, int h, int mode, int *b_w, int *b_h)
  59. {
  60.     if (src && big_img != TRUE) {
  61.         int pxy[8], dark = mode & DARK_SCALING, vr_mode = dark ? S_OR_D : S_ONLY;
  62.         MFDB image;
  63.         int n_w = w, n_h = h;
  64.  
  65.         scale_coords(&n_w, &n_h);
  66.         *b_w = n_w;
  67.         *b_h = n_h;
  68.  
  69.         init_mfdb(&image, src, w, h, 0, 1);
  70.  
  71.         if (n_h < h) {
  72.             int y, n_y, l_y, flag = TRUE;
  73.  
  74.             pxy[0] = pxy[4] = l_y = n_y = y = 0;
  75.             pxy[2] = pxy[6] = w - 1;
  76.  
  77.             for (; y < h; y++) {
  78.                 if (n_y >= h || dark || y == (h - 1)) {
  79.                     pxy[1] = pxy[3] = y;
  80.                     pxy[5] = pxy[7] = l_y;
  81.                     vro_cpyfm(VDIhandle, flag ? 3 : vr_mode, pxy, &image, &image);
  82.                     if (n_y >= h) {
  83.                         n_y -= h;
  84.                         l_y++;
  85.                         flag = TRUE;
  86.                     }
  87.                     else
  88.                         flag = FALSE;
  89.                 }
  90.                 n_y += n_h;
  91.             }
  92.  
  93.             for (y = n_h - 1; y < h; y++) {
  94.                 pxy[1] = pxy[3] = pxy[5] = pxy[7] = y;
  95.                 vro_cpyfm(VDIhandle, 0, pxy, &image, &image);
  96.             }
  97.             h = n_h;
  98.         }
  99.  
  100.         if (n_w < w) {
  101.             int x, n_x, l_x, flag = TRUE;
  102.  
  103.             pxy[1] = pxy[5] = l_x = n_x = x = 0;
  104.             pxy[3] = pxy[7] = h - 1;
  105.  
  106.             for (; x < w; x++) {
  107.                 if (n_x >= w || dark || x == (w - 1)) {
  108.                     pxy[0] = pxy[2] = x;
  109.                     pxy[4] = pxy[6] = l_x;
  110.                     vro_cpyfm(VDIhandle, (flag) ? 3 : vr_mode, pxy, &image, &image);
  111.  
  112.                     if (n_x >= w) {
  113.                         n_x -= w;
  114.                         l_x++;
  115.                         flag = TRUE;
  116.                     } else
  117.                         flag = FALSE;
  118.                 }
  119.                 n_x += n_w;
  120.             }
  121.  
  122.             for (x = n_w - 1; x < w; x++) {
  123.                 pxy[0] = pxy[2] = pxy[4] = pxy[6] = x;
  124.                 vro_cpyfm(VDIhandle, 0, pxy, &image, &image);
  125.             }
  126.         }
  127.     }
  128. }
  129.  
  130.  
  131. /*
  132.  *    Scale image/bitmap object
  133.  *
  134.  *    *obj = pointer to object to transform
  135.  *    mode = scaling mode (NO_SCALING/SCALING, TEST_SCALING/DARK_SCALING)
  136.  *
  137.  *    Returns: nothing
  138.  */
  139. GLOBAL void scale_image(OBJECT *obj, int mode)
  140. {
  141.     if (mode & SCALING) {
  142.         int dummy;
  143.  
  144.         if (big_img) {
  145.             obj->ob_x += ((gr_cw - (image_w >> 1)) * (obj->ob_width / gr_cw)) >> 1;
  146.             obj->ob_y += ((gr_ch - image_h) * (obj->ob_height / gr_ch)) >> 1;
  147.         } else
  148.             if (obj->ob_type == G_ICON) {
  149.                 ICONBLK *icn = obj->ob_spec.iconblk;
  150.     
  151.                 if (icn->ib_hicon > 3) {
  152.                     scale_img(icn->ib_pdata, icn->ib_wicon, icn->ib_hicon, mode, &dummy, &dummy);
  153.                     scale_img(icn->ib_pmask, icn->ib_wicon, icn->ib_hicon, mode, &dummy, &icn->ib_hicon);
  154.                     scale_coords(&icn->ib_xicon, &icn->ib_yicon);
  155.                     scale_coords(&icn->ib_xtext, &icn->ib_ytext);
  156.                     scale_coords(&icn->ib_xchar, &icn->ib_ychar);
  157.                 }
  158.             } else {
  159.                 BITBLK *blk = obj->ob_spec.bitblk;
  160.     
  161.                 if (blk->bi_hl > 3) {
  162.                     scale_img(blk->bi_pdata, blk->bi_wb << 3, blk->bi_hl, mode, &dummy, &blk->bi_hl);
  163.                     scale_coords(&blk->bi_x, &blk->bi_y);
  164.                 }
  165.             }
  166.     }
  167. }
  168.  
  169.  
  170. /*
  171.  *    Transforms standard raster into device dependent raster
  172.  *
  173.  *    w = width of raster
  174.  *    h = height of raster
  175.  *    *data = pointer to raster data
  176.  */
  177. GLOBAL void vdi_trans(int w, int h, void *data)
  178. {
  179.     if (data) {
  180.         MFDB src, dst;
  181.  
  182.         init_mfdb(&src, (int *) data, w, h, 1, 1);
  183.         init_mfdb(&dst, (int *) data, w, h, 0, 1);
  184.  
  185.         vr_trnfm(VDIhandle, &src, &dst);
  186.     }
  187. }
  188.  
  189.  
  190. /*
  191.  *    Transform icon or bitmap into device dependent raster
  192.  *
  193.  *    *obj = pointer to object
  194.  */
  195. GLOBAL void trans_image(OBJECT *obj)
  196. {
  197.     if (obj->ob_type == G_ICON) {
  198.         ICONBLK *icn = obj->ob_spec.iconblk;
  199.  
  200.         vdi_trans(icn->ib_wicon, icn->ib_hicon, icn->ib_pmask);
  201.         vdi_trans(icn->ib_wicon, icn->ib_hicon, icn->ib_pdata);
  202.     } else {
  203.         BITBLK *img = obj->ob_spec.bitblk;
  204.  
  205.         vdi_trans(img->bi_wb << 3, img->bi_hl, img->bi_pdata);
  206.     }
  207. }
  208.