⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hal_draw.c

📁 一个图形显示芯片s1d13505的应用程序
💻 C
📖 第 1 页 / 共 2 页
字号:
   UINT left;
   UINT right;
   long bytes;

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

   BYTE *bpt;

   /* for 1bpp, 2bpp, 4bpp & 8bpp:
    * bitpos =  (PixelsPerByte - x % PixelsPerByte -1)*BitsPerPixel 
    * for 15bpp & 16 bpp mode, bitpos = 0
    */

   StartOffset += StartLogicalAddr;
   color &= 0xf;

   bpt = (BYTE*) StartOffset;

   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;

         *bpt &= ~left;
         *bpt |= (color & left);
         return;
         }

      *bpt &= ~left;
      *bpt |= (color & left);

      bpt++;

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

      *bpt &= ~right;
      *bpt |= (color & right);

      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)
         {
         *bpt &= ~mask;
         *bpt |= color;
         }
      return;
      }
   }

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

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

   BYTE *bpt;

   /* for 1bpp, 2bpp, 4bpp & 8bpp:
    * bitpos =  (PixelsPerByte - x % PixelsPerByte -1)*BitsPerPixel 
    * for 15bpp & 16 bpp mode, bitpos = 0
    */

   StartOffset += StartLogicalAddr;
   color &= 0xff;

   bpt = (BYTE*) StartOffset;

   *bpt = (BYTE) color;
   }

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

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

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

   BYTE *bpt;
   long x;

   StartOffset += StartLogicalAddr;
   color &= 0xff;

   bpt = (BYTE*) StartOffset;

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

      for (x = x1; x < x2; x++)
         *bpt++ = (BYTE)color;
      return;
      }

   if (x1 == x2)  /* vert. line */
      {
      for (y = y1; y < y2; y++, bpt += BytesPerScanline)
         {
         *bpt = (BYTE) color;
         }
      return;
      }
   }

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

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

   WORD *wpt;

   /* for 1bpp, 2bpp, 4bpp & 8bpp:
    * bitpos =  (PixelsPerByte - x % PixelsPerByte -1)*BitsPerPixel 
    * for 15bpp & 16 bpp mode, bitpos = 0
    */

   int WordsPerScanline = BytesPerScanline/2;

   StartOffset += StartLogicalAddr;

   wpt = (WORD*) StartOffset;

#ifndef LCEVBSH3
   color =  ((color & 0xFF) << 8) | ((color >> 8) & 0xFF);
#endif

   *wpt = (WORD) color;
   }

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

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

   WORD *wpt;
   long x, y;

   int WordsPerScanline = BytesPerScanline/2;

   StartOffset += StartLogicalAddr;

   wpt = (WORD *) StartOffset;

#ifndef LCEVBSH3
   color =  ((color & 0xFF) << 8) | ((color >> 8) & 0xFF);
#endif

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

      for (x = x1; x < x2; x++)
         *wpt++ = (WORD)color;
      return;
      }

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

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

int seSetPixel( int seReserved1, long x, long y, DWORD color )
   {
	UINT BytesPerScanline;
   UINT BitsPerPixel;

	ASSERT ( 0 == seReserved1 );

	seGetBytesPerScanline( seReserved1, &BytesPerScanline );


	/*
	** Switch based on the pixel depth (BPP)
	*/
   seGetBitsPerPixel(seReserved1, &BitsPerPixel);

   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */
	switch (BitsPerPixel)
      {
	   case 1:
		   Pixel1bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, color);
		   break;

	   case 2:
		   Pixel2bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, color);
		   break;

	   case 4:
		   Pixel4bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, color);
		   break;

	   case 8:
		   Pixel8bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, color);
		   break;

	   case 15:
	   case 16:
		   Pixel16bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, color);
		   break;

	   default:
		   DPF( ERROR: should never get here!!! );
		   break;
      }

	return ERR_OK;
   }

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

int seDrawLine( int seReserved1, long x1, long y1, long x2, long y2, DWORD color )
   {
	UINT BytesPerScanline;
   UINT BitsPerPixel;

	ASSERT ( 0 == seReserved1 );

	seGetBytesPerScanline( seReserved1, &BytesPerScanline );


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


	/*
	** Switch based on the pixel depth (BPP)
	*/
   seGetBitsPerPixel(seReserved1, &BitsPerPixel);

   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */

   if ((x1 == x2) || (y1 == y2))
      {
	  if (y1 > y2) 
         {
         Swap(&y1, &y2);
         }
  
	   switch (BitsPerPixel)
   	   {
		   case 1:
			   Line1bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color);
			   break;

		   case 2:
			   Line2bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color);
			   break;

		   case 4:
			   Line4bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color);
			   break;

		   case 8:
			   Line8bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color);
			   break;

		   case 15:
		   case 16:
			   Line16bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color);
			   break;

		   default:
			   DPF( ERROR: should never get here!!! );
			   break;
   	   }
      }
/*
** Diagonal lines
*/

   else

      {
	   switch (BitsPerPixel)
   	   {
		   case 1:
			   Line(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color, Pixel1bpp);
			   break;

		   case 2:
			   Line(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color, Pixel2bpp);
			   break;

		   case 4:
			   Line(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color, Pixel4bpp);
			   break;

		   case 8:
			   Line(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color, Pixel8bpp);
			   break;

		   case 15:
		   case 16:
			   Line(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y2, color, Pixel16bpp);
			   break;

		   default:
			   DPF( ERROR: should never get here!!! );
			   break;
   	   }
      }

	return ERR_OK;
   }

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

int seDrawRect( int seReserved1, long x1, long y1, long x2, long y2, DWORD color, BOOL SolidFill )
   {
	UINT BytesPerScanline;
   UINT BitsPerPixel;
   void (*linefn)(DWORD,int,long,long,long,long,DWORD);
   long y;

	ASSERT( 0 == seReserved1 );

	DPF( In seDrawRect() );

   if (y1 > y2)
      {
      y = y2;
      y2 = y1;
      y1 = y;
      }


	seGetBytesPerScanline( seReserved1, &BytesPerScanline );
   seGetBitsPerPixel(seReserved1, &BitsPerPixel);


   switch (BitsPerPixel)
      {
      case 1:
         linefn = Line1bpp;
         break;

      case 2:
         linefn = Line2bpp;
         break;

      case 4:
         linefn = Line4bpp;
         break;

      case 8:
         linefn = Line8bpp;
         break;

      case 15:
      case 16:
         linefn = Line16bpp;
         break;
      }

	if (SolidFill)
      {
	   for (y = y1; y <= y2; y++)
		   (*linefn)(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y, x2, y, color);
	   }
	else
      {
	   (*linefn)(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x2, y1, color);
	   (*linefn)(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y2, x2, y2, color);
	   (*linefn)(DispLogicalAddr[seReserved1], BytesPerScanline, x1, y1, x1, y2, color);
	   (*linefn)(DispLogicalAddr[seReserved1], BytesPerScanline, x2, y1, x2, y2, color);
	   }

	return ERR_OK;
   }

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

int seDrawEllipse(int seReserved1, long xc, long yc, long xr, long yr, DWORD color, BOOL SolidFill)
   {
	UINT BytesPerScanline;
   UINT BitsPerPixel;

	ASSERT( 0 == seReserved1 );
	DPF( In seDrawEllipse() );

   /*
   ** Solid fill not currently implemented
   */
   SolidFill = FALSE;


	seGetBytesPerScanline( seReserved1, &BytesPerScanline );
   seGetBitsPerPixel(seReserved1, &BitsPerPixel);

   switch (BitsPerPixel)
      {
      case 1:
         Ellipse(DispLogicalAddr[seReserved1], BytesPerScanline, xc, yc, xr, yr, color, Pixel1bpp);
         break;

      case 2:
         Ellipse(DispLogicalAddr[seReserved1], BytesPerScanline, xc, yc, xr, yr, color, Pixel2bpp);
         break;

      case 4:
         Ellipse(DispLogicalAddr[seReserved1], BytesPerScanline, xc, yc, xr, yr, color, Pixel4bpp);
         break;

      case 8:
         Ellipse(DispLogicalAddr[seReserved1], BytesPerScanline, xc, yc, xr, yr, color, Pixel8bpp);
         break;

      case 15:
      case 16:
         Ellipse(DispLogicalAddr[seReserved1], BytesPerScanline, xc, yc, xr, yr, color, Pixel16bpp);
         break;
      }

   return ERR_OK;
   }

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

int seDrawCircle( int seReserved1, long xCenter, long yCenter, long radius, DWORD color, BOOL SolidFill )
   {
	ASSERT( 0 == seReserved1 );
	DPF( In seDrawCircle() );

   return seDrawEllipse(seReserved1, xCenter, yCenter, radius, radius, color, SolidFill);
   }

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

// int seMoveBlt( int seReserved1, int SrcX, int SrcY, int DestX, int DestY, int Width, int Height );
// int seReadBlt( int seReserved1, LPBYTE pSystemMemory, int SrcX, int SrcY, int DestX, int DestY, int Width, int Height );
// int seWriteBlt( int seReserved1, LPBYTE pSystemMemory, int SrcX, int SrcY, int DestX, int DestY, int Width, int Height );

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

⌨️ 快捷键说明

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