📄 hal_drw2.c
字号:
/*
**===========================================================================
** HAL_DWR2.C - This file contains all the routines for seGetPixel()
**---------------------------------------------------------------------------
** Copyright (c) 1997, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/
#if defined(INTEL_W32) || defined(INTEL_DOS)
#include <stdio.h>
#endif
#include "hal.h"
#include "assert.h"
#include "nonsefns.h"
/*-------------------------------------------------------------------------*/
static const char Revision[] = "HAL_DRW2.C=$Revision: 15 $";
/*-------------------------------------------------------------------------*/
DWORD _GetPixel2bpp(DWORD StartLinearAddress, int BytesPerScanline, long x, long y)
{
unsigned left, right;
long bytes;
long StartOffset = (long)y * BytesPerScanline + (long)(x / 4);
#ifdef INTEL_DOS
DWORD bpt;
#else
BYTE *bpt;
#endif
StartOffset += StartLinearAddress;
#ifdef INTEL_DOS
bpt = StartOffset;
#else
bpt = (BYTE*) 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 INTEL_DOS
return (DWORD) ((_READXB(bpt) & left) >> (6 - (x & 0x03)*2)) & 0x03;
#else
return (DWORD) (*bpt >> (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 INTEL_DOS
DWORD bpt;
#else
BYTE *bpt;
#endif
StartOffset += StartLinearAddress;
#ifdef INTEL_DOS
bpt = StartOffset;
#else
bpt = (BYTE*) 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 INTEL_DOS
return (DWORD) ((_READXB(bpt) & left) >> (4 - (x & 0x01)*4)) & 0x0f;
#else
return (DWORD) (*bpt >> (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 INTEL_DOS
return (DWORD) _READXB(StartOffset);
#else
return (DWORD) (*(BYTE *) 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 INTEL_DOS
color = (DWORD) _READXW(StartOffset);
#else
color = (DWORD) (*(WORD *) StartOffset);
if (_EndianReverseBytes)
color = ((color & 0xFF) << 8) | ((color >> 8) & 0xFF);
#endif
return color;
}
/*-------------------------------------------------------------------------*/
DWORD seGetLcdPixel(long x, long y)
{
unsigned BytesPerScanline;
unsigned BitsPerPixel;
#ifdef INTEL_DOS
if (_LcdSurface.LinearAddress == -1)
return (DWORD) -1;
#else
if (_LcdSurface.LinearAddress == 0)
return (DWORD) -1;
#endif
BytesPerScanline = seGetLcdBytesPerScanline();
/*
** Switch based on the pixel depth (BPP)
*/
BitsPerPixel = seGetLcdBitsPerPixel();
/*
** If horizontal or vertical lines, use the following optimized
** functions.
*/
switch (BitsPerPixel)
{
case 2:
return _GetPixel2bpp(_LcdSurface.LinearAddress, BytesPerScanline, x, y);
case 4:
return _GetPixel4bpp(_LcdSurface.LinearAddress, BytesPerScanline, x, y);
case 8:
default:
return _GetPixel8bpp(_LcdSurface.LinearAddress, BytesPerScanline, x, y);
case 15:
case 16:
return _GetPixel16bpp(_LcdSurface.LinearAddress, BytesPerScanline, x, y);
}
}
/*-------------------------------------------------------------------------*/
DWORD seGetCrtPixel(long x, long y)
{
unsigned BytesPerScanline;
unsigned BitsPerPixel;
unsigned regDisplayMode;
DWORD val;
#ifdef INTEL_DOS
if (_CrtTvSurface.LinearAddress == -1)
return (DWORD) -1;
#else
if (_CrtTvSurface.LinearAddress == 0)
return (DWORD) -1;
#endif
// If in rotate90 mode, get into landscape mode
regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode & ~0x40);
BytesPerScanline = seGetCrtBytesPerScanline();
/*
** Switch based on the pixel depth (BPP)
*/
BitsPerPixel = seGetCrtBitsPerPixel();
/*
** If horizontal or vertical lines, use the following optimized
** functions.
*/
switch (BitsPerPixel)
{
case 2:
val = _GetPixel2bpp(_CrtTvSurface.LinearAddress, BytesPerScanline, x, y);
break;
case 4:
val = _GetPixel4bpp(_CrtTvSurface.LinearAddress, BytesPerScanline, x, y);
break;
case 8:
default:
val = _GetPixel8bpp(_CrtTvSurface.LinearAddress, BytesPerScanline, x, y);
break;
case 15:
case 16:
val = _GetPixel16bpp(_CrtTvSurface.LinearAddress, BytesPerScanline, x, y);
break;
}
// Restore previous mode (rotate90 or landscape)
seWriteRegByte(REG_DISPLAY_MODE, regDisplayMode);
return val;
}
/*-------------------------------------------------------------------------*/
DWORD seGetTvPixel(long x, long y)
{
return seGetCrtPixel(x, y);
}
/*-------------------------------------------------------------------------*/
DWORD seGetPixel(long x, long y)
{
unsigned BytesPerScanline;
unsigned BitsPerPixel;
#ifdef INTEL_DOS
if (_ActiveImageSurface->LinearAddress == -1)
return (DWORD) -1;
#else
if (_ActiveImageSurface->LinearAddress == 0)
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 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 15:
case 16:
return _GetPixel16bpp(_ActiveImageSurface->LinearAddress, BytesPerScanline, x, y);
}
}
/*-------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -