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

📄 hal_drw2.c

📁 epson公司的一个关于s1d13706的低层驱动程序
💻 C
字号:
/*
**===========================================================================
** HAL_DWR2.C - This file contains all the routines for seGetPixel()
**---------------------------------------------------------------------------
** Copyright (c) 2000, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/

#include "hal.h"
#include "assert.h"
#include "nonsefns.h"

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

static const char Revision[] = "HAL_DRW2.C=$Revision: 8 $";

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

DWORD _GetPixel1bpp(DWORD StartLinearAddress, int BytesPerScanline, long x, long y)
   {
   unsigned left, right;
   long bytes;

   long StartOffset = (long)y * BytesPerScanline + (long)(x / 8);

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


   StartOffset += StartLinearAddress;

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

   left = 0xFF >> (x & 0x07);
   bytes = (x+1)/8 - x/8 - 1;
   right = 0xFF >> ((x+1) & 0x07);
   right = ~right;

   if (bytes < 0)
      left &= right;


#ifdef LINEAR_ADDRESSES_SUPPORTED
   return (DWORD) (*bpt >> (7 - (x & 0x07))) & 0x01;
#else
   return (DWORD) ((_READXB(bpt) & left) >> (7 - (x & 0x07)));
#endif
   }

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

DWORD _GetPixel2bpp(DWORD StartLinearAddress, int BytesPerScanline, long x, long y)
   {
   unsigned left, right;
   long bytes;

   long StartOffset = (long)y * BytesPerScanline + (long)(x / 4);

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


   StartOffset += StartLinearAddress;

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

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

   if (bytes < 0)
      left &= right;


#ifdef LINEAR_ADDRESSES_SUPPORTED
   return (DWORD) (*bpt >> (6 - (x & 0x03)*2)) & 0x03;
#else
   return (DWORD) ((_READXB(bpt) & left) >> (6 - (x & 0x03)*2)) & 0x03;
#endif
   }

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

DWORD _GetPixel4bpp(DWORD StartLinearAddress, int BytesPerScanline, long x, long y)
   {
   unsigned left, right;
   long bytes;

   long StartOffset = (long)y * BytesPerScanline + (long)(x / 2);

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


   StartOffset += StartLinearAddress;

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

   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
   return (DWORD) (*bpt >> (4 - (x & 0x01)*4)) & 0x0f;
#else
   return (DWORD) ((_READXB(bpt) & left) >> (4 - (x & 0x01)*4)) & 0x0f;
#endif
   }

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

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

   StartOffset += StartLinearAddress;


#ifdef LINEAR_ADDRESSES_SUPPORTED
   return (DWORD) (*(BYTE *) StartOffset);
#else
   return (DWORD) _READXB(StartOffset);
#endif
   }

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

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

   StartOffset += StartLinearAddress;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   color = (DWORD) (*(WORD *) StartOffset);

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

   return color;
   }

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

DWORD seGetMainWinPixel(long x, long y)
   {
	unsigned BytesPerScanline;

   x += _MainWinSurface.xOffset;

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

	BytesPerScanline = seGetMainWinBytesPerScanline();


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

	   case 2:
		   return _GetPixel2bpp(_MainWinSurface.LinearAddress, BytesPerScanline, x, y);

	   case 4:
		   return _GetPixel4bpp(_MainWinSurface.LinearAddress, BytesPerScanline, x, y);

	   case 8:
      default:
		   return _GetPixel8bpp(_MainWinSurface.LinearAddress, BytesPerScanline, x, y);

	   case 16:
		   return _GetPixel16bpp(_MainWinSurface.LinearAddress, BytesPerScanline, x, y);
      }
   }

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

DWORD seGetSubWinPixel(long x, long y)
   {
	unsigned BytesPerScanline;

   x += _SubWinSurface.xOffset;

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


	BytesPerScanline = seGetSubWinBytesPerScanline();


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

	   case 2:
		   return _GetPixel2bpp(_SubWinSurface.LinearAddress, BytesPerScanline, x, y);
		   break;

	   case 4:
		   return _GetPixel4bpp(_SubWinSurface.LinearAddress, BytesPerScanline, x, y);
		   break;

	   case 8:
      default:
		   return _GetPixel8bpp(_SubWinSurface.LinearAddress, BytesPerScanline, x, y);
		   break;

	   case 16:
		   return _GetPixel16bpp(_SubWinSurface.LinearAddress, BytesPerScanline, x, y);
		   break;
      }
   }

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

DWORD seGetPixel(long x, long y)
   {
	unsigned BytesPerScanline;
   unsigned BitsPerPixel;

   x += _ActiveImageSurface->xOffset;

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


	BytesPerScanline = seGetBytesPerScanline();


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

   /*
   ** If horizontal or vertical lines, use the following optimized
   ** functions.
   */
	switch (BitsPerPixel)
      {
	   case 1:
		   return _GetPixel1bpp(_ActiveImageSurface->LinearAddress, BytesPerScanline, x, y);

	   case 2:
		   return _GetPixel2bpp(_ActiveImageSurface->LinearAddress, BytesPerScanline, x, y);

	   case 4:
		   return _GetPixel4bpp(_ActiveImageSurface->LinearAddress, BytesPerScanline, x, y);

	   case 8:
      default:
		   return _GetPixel8bpp(_ActiveImageSurface->LinearAddress, BytesPerScanline, x, y);

	   case 16:
		   return _GetPixel16bpp(_ActiveImageSurface->LinearAddress, BytesPerScanline, x, y);
      }
   }

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

⌨️ 快捷键说明

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