home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / viewer / SVLIBS81.LHA / superview-lib / Programmers / Example_SVDrivers / ECS / SD_BufferSubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-13  |  9.4 KB  |  313 lines

  1.  
  2.  /* SD_BufferSubs.c
  3.     - Functions for handling external drivers -
  4.     (c) 1990-94 by Andreas R. Kleinert
  5.     Last changes : 11.06.1994
  6.  */
  7.  
  8. #include "svdriver.h"
  9.  
  10. ULONG __saveds __asm SVD_SetGfxBuffer(      register __a1 struct SVDriverHandle *SVDriverHandle_a1, register __a2 struct SV_GfxBuffer *buffer, register __a3 ULONG future);
  11. ULONG __saveds __asm SVD_DisplayGfxBuffer(  register __a1 struct SVDriverHandle *SVDriverHandle_a1, register __a2 ULONG future);
  12.  
  13. long __saveds __stdargs SVLI_SVDScreen(struct SVDriverHandle *SVDriverHandle, ULONG ai_mode_id);
  14. long __saveds __stdargs SVLI_SVDSetCMAP(struct SVDriverHandle *SVDriverHandle, struct Screen *screen, long colornum);
  15.  
  16.  
  17. /* *************************************************** */
  18. /* *                             * */
  19. /* * SVD_SetGfxBuffer :                              * */
  20. /* *                             * */
  21. /* *************************************************** */
  22.  
  23. ULONG __saveds __asm SVD_SetGfxBuffer(  register __a1 struct SVDriverHandle *SVDriverHandle_a1, register __a2 struct SV_GfxBuffer *buffer, register __a3 ULONG future)
  24. {
  25.  struct SVDriverHandle *SVDriverHandle = SVDriverHandle_a1;
  26.  ULONG retval = SVERR_NO_ERROR;
  27.  
  28.  if(!SVDriverHandle) return(SVERR_NO_HANDLE);
  29.  
  30.  if(!buffer) return(SVERR_ILLEGAL_ACCESS);
  31.  
  32.  SVDriverHandle->ah_SV_GfxBuffer = buffer;
  33.  
  34.  return(retval);
  35. }
  36.  
  37. /* *************************************************** */
  38. /* *                             * */
  39. /* * SVD_DisplayGfxBuffer :                          * */
  40. /* *                             * */
  41. /* *************************************************** */
  42.  
  43. ULONG __saveds __asm SVD_DisplayGfxBuffer(  register __a1 struct SVDriverHandle *SVDriverHandle_a1, register __a2 ULONG future)
  44. {
  45.  struct SVDriverHandle *SVDriverHandle = SVDriverHandle_a1;
  46.  ULONG retval = SVERR_NO_ERROR;
  47.  ULONG width, height, depth, colnum, linebytes, bmpwidth, mode_id, j;
  48.  UBYTE *buffer, *bufferptr, *planeptr;
  49.  
  50.  struct RastPort *rp;
  51.  struct BitMap     *bm;
  52.  struct ViewPort *vp;
  53.  
  54.  if(!SVDriverHandle->ah_SV_GfxBuffer) return(SVERR_ILLEGAL_ACCESS);
  55.  
  56.  bufferptr = buffer = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Buffer;
  57.  if(!buffer) return(SVERR_ILLEGAL_ACCESS);
  58.  
  59.  if(SVDriverHandle->ah_SV_GfxBuffer->svgfx_BufferType > SVGFX_BUFFERTYPE_ONEPLANE) return(SVERR_ACTION_NOT_SUPPORTED);
  60.  
  61.  /* Open Screen */
  62.  
  63.  mode_id = SVDriverHandle->ah_SV_GfxBuffer->svgfx_ViewMode32;
  64.  
  65.  if(!SVLI_SVDScreen(SVDriverHandle, mode_id)) return(SVERR_NO_SCREEN);
  66.  
  67.  rp = (struct RastPort *) &(SVDriverHandle->ah_Screen->RastPort);
  68.  bm = (struct BitMap   *) SVDriverHandle->ah_Screen->RastPort.BitMap;
  69.  vp = (struct ViewPort *) &(SVDriverHandle->ah_Screen->ViewPort);
  70.  
  71.  width     = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Width;
  72.  height    = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Height;
  73.  depth     = SVDriverHandle->ah_SV_GfxBuffer->svgfx_ColorDepth;
  74.  colnum    = 1 << depth;
  75.  
  76.  bmpwidth = ((width + 31) >> 5) << 5;
  77.  
  78.  if(SVDriverHandle->ah_SV_GfxBuffer->svgfx_BufferType == SVGFX_BUFFERTYPE_BITPLANE)
  79.        linebytes = (long) SVDriverHandle->ah_SV_GfxBuffer->svgfx_BytesPerLine;
  80.   else linebytes = (long) bm->BytesPerRow;
  81.  
  82.  
  83.  /* Read Palette */
  84.  
  85.  SVLI_SVDSetCMAP(SVDriverHandle, SVDriverHandle->ah_Screen, colnum);
  86.  
  87.  
  88.  /* Decoding */
  89.  
  90.  planeptr  = (UBYTE *) N;
  91.  
  92.  if(SVDriverHandle->ah_SV_GfxBuffer->svgfx_BufferType == SVGFX_BUFFERTYPE_BITPLANE)
  93.   {
  94.    if(linebytes == bm->BytesPerRow)
  95.     {
  96.      ULONG prod_1 = height * linebytes;
  97.  
  98.      for(j=0;j<depth;j++) CopyMem(bufferptr + j*prod_1, bm->Planes[j], prod_1);
  99.     }else
  100.     {
  101.               ULONG copybytes, pskipbytes, buf_ptradd1;
  102.      register ULONG i, j;
  103.      register UBYTE *bptr, *pptr;
  104.  
  105.      pskipbytes = bm->BytesPerRow;
  106.  
  107.      if(pskipbytes < linebytes) copybytes = pskipbytes;
  108.       else                      copybytes = linebytes;
  109.  
  110.      buf_ptradd1 = height*linebytes;
  111.  
  112.      for(j=0;j<depth;j++)
  113.       {
  114.        bptr = (UBYTE *) bufferptr + (buf_ptradd1 * j);
  115.        pptr = (UBYTE *) bm->Planes[j];
  116.  
  117.        for(i=0; i<height; i++)
  118.         {
  119.          CopyMem(bptr, pptr, copybytes);
  120.  
  121.          bptr += linebytes;
  122.          pptr += pskipbytes;
  123.         }
  124.       }
  125.     }
  126.   }
  127.  
  128.  if(SVDriverHandle->ah_SV_GfxBuffer->svgfx_BufferType == SVGFX_BUFFERTYPE_ONEPLANE)
  129.   {
  130.    if(depth <= 8)
  131.     {
  132.      /* Maybe, there are Graphic Cards, which allow 8 Bits colordepth
  133.         via an intuition-compatible AGA-emulation, but nevertheless
  134.         we cannot use V39-functions as in AGA.svdriver !!!
  135.      */
  136.  
  137.      register struct RastPort *tmp_rp;
  138.      register UWORD            i, j;
  139.      register UBYTE           *bptr;
  140.  
  141.      tmp_rp = (APTR) AllocVec(sizeof(struct RastPort), MEMF_CLEAR|MEMF_PUBLIC);
  142.      if(tmp_rp)
  143.       {
  144.        InitRastPort(tmp_rp);
  145.  
  146.        tmp_rp->BitMap = AllocVec(sizeof(struct BitMap), MEMF_CLEAR|MEMF_PUBLIC);
  147.        if(tmp_rp->BitMap)
  148.         {
  149.          InitBitMap(tmp_rp->BitMap, depth, bmpwidth, 1);
  150.  
  151.          for(i=0; i<depth; i++)
  152.           {
  153.            tmp_rp->BitMap->Planes[i] = (APTR) AllocRaster(bmpwidth, 1);
  154.            if(!tmp_rp->BitMap->Planes[i])
  155.             {
  156.              retval = SVERR_NO_MEMORY;
  157.  
  158.              break;
  159.             }
  160.           }
  161.  
  162.          if(!retval)
  163.           {
  164.            bptr = bufferptr;
  165.  
  166.            for(j=0; j<height; j++, bptr+=width) WritePixelLine8(rp, 0, j, width, bptr, tmp_rp);
  167.           }
  168.  
  169.          for(i=0; i<8; i++) if(tmp_rp->BitMap->Planes[i]) FreeRaster(tmp_rp->BitMap->Planes[i], bmpwidth, 1);
  170.  
  171.          FreeVec(tmp_rp->BitMap);
  172.         }else retval = SVERR_NO_MEMORY;
  173.  
  174.        FreeVec(tmp_rp);
  175.       }else retval = SVERR_NO_MEMORY;
  176.  
  177.     }else
  178.     {
  179.      /* Insert code for handling color depths > 8
  180.         (future AGA or AAA features ?)
  181.      */
  182.  
  183.      retval = SVERR_UNKNOWN_PARAMETERS;
  184.     }
  185.   }
  186.  
  187.  ScreenToFront(SVDriverHandle->ah_Screen);
  188.  
  189.  return(retval);
  190. }
  191.  
  192. /* *************************************************** */
  193. /* *                             * */
  194. /* * SVLI_SVDScreen : SVD Screen Opening Function    * */
  195. /* *                             * */
  196. /* *************************************************** */
  197.  
  198. struct TextAttr __aligned chip topazfont = { (STRPTR) "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT };
  199.  
  200. long __saveds __stdargs SVLI_SVDScreen(struct SVDriverHandle *SVDriverHandle, ULONG ai_mode_id)
  201. {
  202.  long ai_width, ai_height, ai_depth;
  203.  struct Rectangle __aligned rect;
  204.  
  205.  if(!SVDriverHandle->ah_SV_GfxBuffer) return(FALSE);
  206.  
  207.  
  208.  /* Get and set Standard Screen Dimensions */
  209.  
  210.  ai_width  = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Width;
  211.  ai_height = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Height;
  212.  ai_depth  = SVDriverHandle->ah_SV_GfxBuffer->svgfx_ColorDepth;
  213.  
  214.  
  215.  /* Get and/or set Screen, Window and IDCMP Flags */
  216.  
  217.  if(!SVDriverHandle->ah_ScreenType)  SVDriverHandle->ah_ScreenType  = CUSTOMSCREEN;
  218.  if(!SVDriverHandle->ah_WindowIDCMP) SVDriverHandle->ah_WindowIDCMP = IDCMP_MOUSEBUTTONS | IDCMP_VANILLAKEY;
  219.  if(!SVDriverHandle->ah_WindowFlags) SVDriverHandle->ah_WindowFlags = WFLG_BACKDROP | WFLG_BORDERLESS | WFLG_NOCAREREFRESH | WFLG_SIMPLE_REFRESH;
  220.  
  221.  if(!QueryOverscan(ai_mode_id, &rect, OSCAN_TEXT))
  222.   {
  223.    rect.MinX = 0;
  224.    rect.MaxX = ai_width;
  225.    rect.MinY = 0;
  226.    rect.MaxY = ai_height;
  227.   }
  228.  
  229.  /* Open Screen like needed for SVD Displaying */
  230.  
  231.  SVDriverHandle->ah_Screen = OpenScreenTags( NULL, SA_Left,        0,
  232.                                         SA_Top,       0,
  233.                                        SA_Width,       ai_width,
  234.                                    SA_Height,       ai_height,
  235.                                    SA_Depth,       ai_depth,
  236.                                    SA_Font,      &topazfont,
  237.                                    SA_Type,       SVDriverHandle->ah_ScreenType,
  238.                                    SA_DisplayID,   ai_mode_id,
  239.                                    SA_Title,       "Please wait ...",
  240.                                    SA_AutoScroll,  TRUE,
  241.                                    SA_DClip,       &rect,
  242.                                    SA_Behind,      TRUE,
  243.                                    TAG_END );
  244.  
  245.  if(!SVDriverHandle->ah_Screen) return(FALSE);
  246.  
  247.  
  248.  /* Open Window like needed for SVD Displaying */
  249.  
  250.  SVDriverHandle->ah_Window = OpenWindowTags(N,
  251.                 WA_Left,         0,
  252.                 WA_Top,         0,
  253.                 WA_Width,         SVDriverHandle->ah_Screen->Width,
  254.                 WA_Height,         SVDriverHandle->ah_Screen->Height,
  255.                 WA_DetailPen,    1,
  256.                 WA_BlockPen,     2,
  257.                 WA_IDCMP,         SVDriverHandle->ah_WindowIDCMP,
  258.                 WA_Flags,         SVDriverHandle->ah_WindowFlags,
  259.                 WA_CustomScreen, SVDriverHandle->ah_Screen,
  260.                 TAG_END,         N);
  261.  
  262.  if(!SVDriverHandle->ah_Window) return(FALSE);
  263.  
  264.  ActivateWindow(SVDriverHandle->ah_Window);
  265.  
  266.  return(TRUE);
  267. }
  268.  
  269. /* *************************************************** */
  270. /* *                             * */
  271. /* * SVLI_SVDSetCMAP : Set ColorMap (RGB8 / RGB 32)  * */
  272. /* *                             * */
  273. /* *************************************************** */
  274.  
  275. long __saveds __stdargs SVLI_SVDSetCMAP(struct SVDriverHandle *SVDriverHandle, struct Screen *screen, long colornum)
  276. {
  277.  struct ViewPort *vp;
  278.  long i;
  279.  
  280.  if(SVDriverHandle && screen)
  281.   {
  282.    vp = (struct ViewPort *) &(screen->ViewPort);
  283.  
  284.    if(OS_VER < 39)
  285.     {
  286.      /* Standard / ECS "4 Bit of 12 Bit" Colors (RGB4) */
  287.  
  288.      for(i=0;i<colornum;i++) SetRGB4(vp, i, SVDriverHandle->ah_SV_GfxBuffer->svgfx_Colors[i][0]>>4, SVDriverHandle->ah_SV_GfxBuffer->svgfx_Colors[i][1]>>4, SVDriverHandle->ah_SV_GfxBuffer->svgfx_Colors[i][2]>>4);
  289.     }else
  290.     {
  291.      /* AGA "8 Bit of 32 Bit" Colors (RGB32) */
  292.  
  293.      ULONG r,g,b;
  294.  
  295.      for(i=0;i<colornum;i++)
  296.       {
  297.        r  = (ULONG) SVDriverHandle->ah_SV_GfxBuffer->svgfx_Colors[i][0];
  298.        r |= (r<<24 | r<<16 | r<<8);
  299.  
  300.        g  = (ULONG) SVDriverHandle->ah_SV_GfxBuffer->svgfx_Colors[i][1];
  301.        g |= (g<<24 | g<<16 | g<<8);
  302.  
  303.        b  = (ULONG) SVDriverHandle->ah_SV_GfxBuffer->svgfx_Colors[i][2];
  304.        b |= (b<<24 | b<<16 | b<<8);
  305.  
  306.        SetRGB32(vp, i, r, g, b);
  307.       }
  308.     }
  309.   }
  310.  
  311.  return(FALSE);
  312. }
  313.