hal_draw.c

来自「epson公司的一个关于s1d13706的低层驱动程序」· C语言 代码 · 共 1,567 行 · 第 1/3 页

C
1,567
字号
#else
   bpt = StartOffset;
#endif

   color |= (color << 4);

   left = 0xFF >> ((x & 0x1)*4);
   bytes = (x+1)/2 - x/2 - 1;
   right = 0xFF >> (((x+1) & 0x1)*4);
   right = ~right;

   if (bytes < 0)
      left &= right;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   *bpt &= ~left;
   *bpt |= (color & left);
#else
   val = (BYTE) ((_READXB(bpt) & ~left) | (color & left));
   _WRITEXB(bpt, val);
#endif
   }

/*-------------------------------------------------------------------------*/

/*
** For horizontal/vertical lines only
*/
void _Line4bpp(DWORD StartLinearAddress, int BytesPerScanline, long x1, long y1, long x2, long y2, DWORD color)
   {
   long y;
   unsigned left;
   unsigned right;
   long bytes;

   long StartOffset = (long)y1 * BytesPerScanline + 
                       (long)(x1 / 2);

#ifdef LINEAR_ADDRESSES_SUPPORTED
   BYTE *bpt;
#else
   BYTE val;
   DWORD bpt;
#endif

   StartOffset += StartLinearAddress;
   color &= 0xf;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   bpt = (BYTE*) StartOffset;
#else
   bpt = StartOffset;
#endif

   if (y1 == y2)  /* horiz. line */
      {
      ++x2;  /* include the last point in the line */

      left  =   0xFF >> ((x1 & 0x1)*4);
      right = ~(0xFF >> ((x2 & 0x1)*4));
      bytes = x2/2 - x1/2 - 1;

      color |= (color << 4);

      if (bytes < 0)       /* one byte only */
         {
         left &= right;

#ifdef LINEAR_ADDRESSES_SUPPORTED
         *bpt &= ~left;
         *bpt |= (color & left);
#else
         val = _READXB(bpt);
         val &= ~left;
         val |= (color & left);
         _WRITEXB(bpt, val);
#endif
         return;
         }

#ifdef LINEAR_ADDRESSES_SUPPORTED
      *bpt &= ~left;
      *bpt |= (color & left);
#else
      val = _READXB(bpt);
      val &= ~left;
      val |= (color & left);
      _WRITEXB(bpt, val);
#endif

      bpt++;

#ifdef LINEAR_ADDRESSES_SUPPORTED
      while (bytes-- > 0)
         *bpt++ = (BYTE) color;

      *bpt &= ~right;
      *bpt |= (color & right);
#else
      _asmWriteBytes(bpt, (unsigned) color, (DWORD) bytes);
      bpt += bytes;

      val = _READXB(bpt);
      val &= ~right;
      val |= (color & right);
      _WRITEXB(bpt, val);
#endif

      return;
      }

   if (x1 == x2)  /* vert. line */
      {
      BYTE BitPosition = (BYTE) ((1 - (x1 & 0x1)) <<2);
      BYTE mask = (BYTE) (0xf << BitPosition);
      color <<= BitPosition;

      for (y = y1; y < y2; y++, bpt += BytesPerScanline)
         {
#ifdef LINEAR_ADDRESSES_SUPPORTED
         *bpt &= ~mask;
         *bpt |= color;
#else
         val = _READXB(bpt);
         val &= ~mask;
         val |= color;
         _WRITEXB(bpt, val);
#endif
         }
      return;
      }
   }

/*-------------------------------------------------------------------------*/

void _Pixel8bpp(DWORD StartLinearAddress, int BytesPerScanline, long x, long y, DWORD color)
   {
   long StartOffset = (long)y * BytesPerScanline + (long)(x);

#ifdef LINEAR_ADDRESSES_SUPPORTED
   BYTE *bpt;
#else
   DWORD bpt;
#endif

   StartOffset += StartLinearAddress;
   color &= 0xff;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   bpt = (BYTE*) StartOffset;
   *bpt = (BYTE) color;
#else
   bpt = StartOffset;
   _WRITEXB(bpt, (BYTE) color);
#endif
   }

/*-------------------------------------------------------------------------*/

/*
** For horizontal/vertical lines only
*/
void _Line8bpp(DWORD StartLinearAddress, int BytesPerScanline, long x1, long y1, long x2, long y2, DWORD color)
   {
   long y;

   long StartOffset;
   long Offset = (long)y1 * BytesPerScanline + (long)(x1);

#ifdef LINEAR_ADDRESSES_SUPPORTED
   BYTE *bpt;
   long x;
#else
   DWORD bpt;
#endif

   StartOffset = StartLinearAddress + Offset;
   color &= 0xff;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   bpt = (BYTE*) StartOffset;
#else
   bpt = StartOffset;
#endif

   if (y1 == y2)  /* horiz. line */
      {
      ++x2;  /* include the last point in the line */

#ifdef LINEAR_ADDRESSES_SUPPORTED
      for (x = x1; x < x2; x++)
         *bpt++ = (BYTE)color;
#else
      _asmWriteBytes(bpt, (unsigned) color, (DWORD) (x2 - x1));
#endif

      bpt += (x2 - x1 + 1);

      return;
      }

   if (x1 == x2)  /* vert. line */
      {
      for (y = y1; y < y2; y++, bpt += BytesPerScanline)
         {
#ifdef LINEAR_ADDRESSES_SUPPORTED
         *bpt = (BYTE) color;
#else
         _WRITEXB(bpt, (BYTE) color);
#endif
         }

      return;
      }
   }

/*-------------------------------------------------------------------------*/

void _Pixel16bpp(DWORD StartLinearAddress, int BytesPerScanline, long x, long y, DWORD color)
   {
   long StartOffset = (long)y * BytesPerScanline + (long)(x*2);

#ifdef LINEAR_ADDRESSES_SUPPORTED
   WORD *wpt;
#else
   DWORD wpt;
#endif


   StartOffset += StartLinearAddress;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   wpt = (WORD*) StartOffset;

   if (_EndianReverseDisplayBytes && !_AllowHardwareDisplaySwapping)
      color =  ((color & 0xFF) << 8) | ((color >> 8) & 0xFF);
#else
   wpt = StartOffset;
#endif


#ifdef LINEAR_ADDRESSES_SUPPORTED
   *wpt = (WORD) color;
#else
   _WRITEXW(wpt, (WORD) color);
#endif
   }

/*-------------------------------------------------------------------------*/

/*
** For horizontal/vertical lines only
*/
void _Line16bpp(DWORD StartLinearAddress, int BytesPerScanline,long x1,long y1,long x2,long y2,DWORD color)
   {
   long StartOffset = (long)y1 * BytesPerScanline + 
                       (long)(x1*2);

#ifdef LINEAR_ADDRESSES_SUPPORTED
   WORD *wpt;
   long x, y;
   int WordsPerScanline;
#else
   long y;
   DWORD wpt;
#endif


   StartOffset += StartLinearAddress;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   wpt = (WORD *) StartOffset;

   if (_EndianReverseDisplayBytes && !_AllowHardwareDisplaySwapping)
      color =  ((color & 0xFF) << 8) | ((color >> 8) & 0xFF);
#else
   wpt = StartOffset;
#endif

   if (y1 == y2)  /* horiz. line */
      {
      ++x2;  /* include the last point in the line */

#ifdef LINEAR_ADDRESSES_SUPPORTED
      for (x = x1; x < x2; x++)
         *wpt++ = (WORD)color;
#else
      _asmWriteWords(wpt, (unsigned) color, (WORD) (x2 - x1));
#endif
      return;
      }


#ifdef LINEAR_ADDRESSES_SUPPORTED
   WordsPerScanline = BytesPerScanline / 2;

   if (x1 == x2)  /* vert. line */
      {
      for (y = y1; y < y2; y++, wpt += WordsPerScanline)
         {
         *wpt = (WORD) color;
         }
      return;
      }
#else
   if (x1 == x2)  /* vert. line */
      {
      for (y = y1; y < y2; y++, wpt += BytesPerScanline)
         {
         _WRITEXW(wpt, (WORD) color);
         }
      return;
      }
#endif
   }

/*-------------------------------------------------------------------------*/

void seSetMainWinPixel(long x, long y, DWORD color)
   {
	unsigned BytesPerScanline;
   DWORD LinearAddress;

   x += _MainWinSurface.xOffset;

	BytesPerScanline = seGetMainWinBytesPerScanline();
 	LinearAddress = _MainWinSurface.LinearAddress;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   if (LinearAddress == 0)
      return;
#else
   if (LinearAddress == -1)
      return;
#endif


   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */
	switch (seGetBitsPerPixel())
      {
      case 1:
		   _Pixel1bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

      case 2:
		   _Pixel2bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 4:
		   _Pixel4bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 8:
		   _Pixel8bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 16:
		   _Pixel16bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;
      }
   }

/*-------------------------------------------------------------------------*/

void seSetSubWinPixel(long x, long y, DWORD color)
   {
	unsigned BytesPerScanline;
   DWORD LinearAddress;

   x += _SubWinSurface.xOffset;

	BytesPerScanline = seGetSubWinBytesPerScanline();

 	LinearAddress = _SubWinSurface.LinearAddress;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   if (LinearAddress == 0)
      return;
#else
   if (LinearAddress == -1)
      return;
#endif


   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */
	switch (seGetBitsPerPixel())
      {
	   case 1:
		   _Pixel1bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 2:
		   _Pixel2bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 4:
		   _Pixel4bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 8:
		   _Pixel8bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 16:
		   _Pixel16bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;
      }
   }

/*-------------------------------------------------------------------------*/

void seSetPixel(long x, long y, DWORD color)
   {
	unsigned BytesPerScanline;
   DWORD LinearAddress;

   x += _ActiveImageSurface->xOffset;

	BytesPerScanline = seGetBytesPerScanline();

 	LinearAddress = _ActiveImageSurface->LinearAddress;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   if (LinearAddress == 0)
      return;
#else
   if (LinearAddress == -1)
      return;
#endif


   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */
	switch (seGetBitsPerPixel())
      {
	   case 1:
		   _Pixel1bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 2:
		   _Pixel2bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 4:
		   _Pixel4bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 8:
		   _Pixel8bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;

	   case 16:
		   _Pixel16bpp(LinearAddress, BytesPerScanline, x, y, color);
		   break;
      }
   }

/*-------------------------------------------------------------------------*/

void seDrawMainWinLine(long x1, long y1, long x2, long y2, DWORD color)
   {
	unsigned BytesPerScanline;
   unsigned BitsPerPixel;
   DWORD LinearAddress;

   x1 += _MainWinSurface.xOffset;
   x2 += _MainWinSurface.xOffset;

	BytesPerScanline = seGetMainWinBytesPerScanline();

   if (x1 > x2)
      {
      _Swap(&x1, &x2);
      _Swap(&y1, &y2);
      }


	/*
	** Switch based on the pixel depth (BPP)
	*/
   BitsPerPixel = seGetBitsPerPixel();

 	LinearAddress = _MainWinSurface.LinearAddress;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   if (LinearAddress == 0)
      return;
#else
   if (LinearAddress == -1)
      return;
#endif


/*
** Diagonal lines
*/
	switch (BitsPerPixel)
      {
      case 1:
   	   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel1bpp);
		   break;

      case 2:
   	   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel2bpp);
		   break;

	   case 4:
   	   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel4bpp);
		   break;

	   case 8:
		   _Line(LinearAddress, BytesPerScanline, x1, y1, x2, y2, color, _Pixel8bpp);
		   break;

	   case 16:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?