home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 580a.lha / HDFView_v3.01 / source.LZH / source / src / drawImage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-03  |  2.7 KB  |  109 lines

  1. #include    <exec/types.h>
  2. #include    <intuition/intuition.h>
  3. #include    <graphics/gfxmacros.h>
  4.  
  5. #include    <proto/intuition.h>
  6. #include    <proto/graphics.h>
  7.  
  8. #include    "View_define.h"
  9. #include    "ViewProtos.h"
  10. #include    "hame.h"
  11.  
  12. extern      struct HamePort   *hamePort;
  13. extern      struct Library    *HameBase;
  14. extern      struct Screen     *gScreen;
  15.  
  16.  
  17. /* Draw the image */
  18. int
  19. drawImage (struct Window *win,
  20.          char *image,
  21.          int width, int height,int mode)
  22. {
  23.    
  24.    register int  j,i;
  25.    char *data=image;
  26.    int level, level0;
  27.    int factor=8;
  28.    int ht, wt;
  29.    
  30.    setColors(mode);
  31.  
  32.    if( (mode==COLORS_32) || (mode==COLORS_LACE_32) || 
  33.       (mode==COLORS_16) || (mode==COLORS_LACE_16) ) 
  34.    {               
  35. /* This is meant to try to cut down on drawing time. I have
  36.    noticed that many images have some background color that makes
  37.    up a large part of the image. So here I look at the first
  38.    entry in the image array and flood the background with that
  39.    color. Then whenever the image has the entry again I don't have to
  40.    draw anything. It would be better perhaps to search for the most
  41.    common color and use that instead. */
  42.    
  43.       if( (mode==COLORS_16) || (mode==COLORS_LACE_16) ) factor=16;
  44.        
  45.       level0 = (int)(*image)/factor; 
  46.       SetAPen(win->RPort,level0);
  47.       RectFill(win->RPort,0,0, win->Width,win->Height); 
  48.     
  49.     
  50.     /* Do the actual drawing */        
  51.       for(j=0;j<height;j++)
  52.       {
  53.          for(i=0;i<width;i++)
  54.          {
  55.             level = (int)(*data)/factor;
  56.             if( (level != level0) && 
  57.                   (i<win->Width) && (j<win->Height) )
  58.             { 
  59.                SetAPen(win->RPort,level);
  60.                WritePixel(win->RPort,i,j);
  61.             }
  62.             data++;
  63.          }
  64.       }
  65.    }
  66.  
  67.  
  68.        
  69. if( (mode==HAME) || (mode==HAME_LACE) )
  70. {
  71.        if(mode==HAME_LACE) ht = win->Height-8;
  72.        else ht = win->Height-4;      
  73.        wt = win->Width/2;
  74.  
  75.       level0 = (int)(*data);
  76.        HAME_SetAPen(hamePort,level0);
  77.        HAME_Box(hamePort,0,0, wt,ht, 1);
  78.  
  79.        HAME_SetAPen(hamePort,255);
  80.        HAME_Line(hamePort,0,0,0,ht);
  81.        
  82.        HAME_8BitRender(hamePort,data,1,0,width,height);
  83.              
  84.  /*      for(i=1;i<height+1;i++)
  85.        {
  86.          HAME_LockLayer(hamePort); 
  87.          for(j=1;j<width+1;j++)
  88.          {
  89.             level = (int)(*data);
  90.             if( (i<win->Height-1) && (j<win->Width-1) && (level!=level0) )
  91.             {
  92.                HAME_SetAPen(hamePort,level);
  93.                HAME_WritePixel(hamePort, j, i);
  94.             }
  95.             data++;
  96.          }
  97.          HAME_UnlockLayer(hamePort);
  98.       }
  99.       */
  100. }          
  101.       
  102.    if(gScreen) ScreenToFront(gScreen);    
  103.    return(1);
  104. }   
  105.  
  106.  
  107.  
  108.  
  109.