📄 hal_drw2.c
字号:
/*
**===========================================================================
** HAL_DWR2.C - This file contains all the routines for seGetPixel()
**---------------------------------------------------------------------------
** Copyright (c) 1997, 1998 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/
#ifdef INTEL
#include <stdio.h>
#endif
#include "hal.h"
#include "assert.h"
#include "nonsefns.h"
extern LPHAL_STRUCT HalInfoArray[MAX_DEVICE];
static const char Revision[] = "HAL_DRW2.C=$Revision: 3 $";
/*-------------------------------------------------------------------------*/
void GetPixel1bpp(DWORD StartLogicalAddr, int BytesPerScanline, long x, long y, DWORD *pColor)
{
UINT left, right;
long bytes;
long StartOffset = (long)y * BytesPerScanline + (long)(x / 8);
BYTE *bpt;
/* for 1bpp, 2bpp, 4bpp & 8bpp:
* bitpos = (PixelsPerByte - x % PixelsPerByte -1)*BitsPerPixel
* for 15bpp & 16 bpp mode, bitpos = 0
*/
StartOffset += StartLogicalAddr;
bpt = (BYTE*) StartOffset;
left = 0xFF >> (x & 0x7);
bytes = (x+1)/8 - x/8 - 1;
right = 0xFF >> ((x+1) & 0x7);
right = ~right;
if (bytes < 0)
left &= right;
*pColor = (DWORD) (*bpt >> (7 - (x & 0x07))) & 0x01;
}
/*-------------------------------------------------------------------------*/
void GetPixel2bpp(DWORD StartLogicalAddr, int BytesPerScanline, long x, long y, DWORD *pColor)
{
UINT left, right;
long bytes;
long StartOffset = (long)y * BytesPerScanline + (long)(x / 4);
BYTE *bpt;
/* for 1bpp, 2bpp, 4bpp & 8bpp:
* bitpos = (PixelsPerByte - x % PixelsPerByte -1)*BitsPerPixel
* for 15bpp & 16 bpp mode, bitpos = 0
*/
StartOffset += StartLogicalAddr;
bpt = (BYTE*) StartOffset;
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;
*pColor = (DWORD) (*bpt >> (6 - (x & 0x03)*2)) & 0x03;
}
/*-------------------------------------------------------------------------*/
void GetPixel4bpp(DWORD StartLogicalAddr, int BytesPerScanline, long x, long y, DWORD *pColor)
{
UINT left, right;
long bytes;
long StartOffset = (long)y * BytesPerScanline + (long)(x / 2);
BYTE *bpt;
/* for 1bpp, 2bpp, 4bpp & 8bpp:
* bitpos = (PixelsPerByte - x % PixelsPerByte -1)*BitsPerPixel
* for 15bpp & 16 bpp mode, bitpos = 0
*/
StartOffset += StartLogicalAddr;
bpt = (BYTE*) StartOffset;
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;
*pColor = (DWORD) (*bpt >> (4 - (x & 0x01)*4)) & 0x0f;
}
/*-------------------------------------------------------------------------*/
void GetPixel8bpp(DWORD StartLogicalAddr, int BytesPerScanline, long x, long y, DWORD *pColor)
{
long StartOffset = (long)y * BytesPerScanline + (long)(x);
/* for 1bpp, 2bpp, 4bpp & 8bpp:
* bitpos = (PixelsPerByte - x % PixelsPerByte -1)*BitsPerPixel
* for 15bpp & 16 bpp mode, bitpos = 0
*/
StartOffset += StartLogicalAddr;
*pColor = (DWORD) (*(BYTE *) StartOffset);
}
/*-------------------------------------------------------------------------*/
void GetPixel16bpp(DWORD StartLogicalAddr, int BytesPerScanline, long x, long y, DWORD *pColor)
{
long StartOffset = (long)y * BytesPerScanline + (long)(x*2);
/* for 1bpp, 2bpp, 4bpp & 8bpp:
* bitpos = (PixelsPerByte - x % PixelsPerByte -1)*BitsPerPixel
* for 15bpp & 16 bpp mode, bitpos = 0
*/
int WordsPerScanline = BytesPerScanline/2;
StartOffset += StartLogicalAddr;
*pColor = (DWORD) (*(WORD *) StartOffset);
#ifndef LCEVBSH3
*pColor = ((*pColor & 0xFF) << 8) | ((*pColor >> 8) & 0xFF);
#endif
}
/*-------------------------------------------------------------------------*/
int seGetPixel( int seReserved1, long x, long y, DWORD *pColor )
{
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:
GetPixel1bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, pColor);
break;
case 2:
GetPixel2bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, pColor);
break;
case 4:
GetPixel4bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, pColor);
break;
case 8:
GetPixel8bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, pColor);
break;
case 15:
case 16:
GetPixel16bpp(DispLogicalAddr[seReserved1], BytesPerScanline, x, y, pColor);
break;
default:
DPF( ERROR: should never get here!!! );
break;
}
return ERR_OK;
}
/*-------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -