📄 bmp.c
字号:
/**==========================================================================\
*** BMP.C - Demo program to show all colors & patterns on all modes
*** Copyright (c) 2000, 2001 Epson Research and Development, Inc.
*** All rights reserved.
\*==========================================================================*/
#include <fcntl.h>
#include <math.h>
#include <malloc.h>
#ifdef INTEL_DOS
#include <unistd.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "hal.h"
#include "bmp.h"
#include "appcfg.h"
#ifdef INCLUDE_CONIO_H // Check if it's OK to include conio.h
#include <io.h>
#include <conio.h>
#endif
#ifdef INCLUDE_TIME_H // Check if it's OK to include time.h
#include <time.h>
#endif
/*-------------------------------------------------external functions------*/
static const char Revision[] = "BMP.C=$Revision: 10 $";
/*----------------------------------------------------------variables------*/
/* ======= global variables ======== */
int gbInitRegisters;
int gbImgCompress;
unsigned SurfaceDisplayMode[MAX_DISP_SURFACE];
int LcdOrientation;
int VerboseMode = FALSE;
int NumberOfSurfaces;
int CommonMemoryBlockForAllDisplays;
int ActiveSurfaceNumber;
char *filename[MAX_DISP_SURFACE];
int BmpCount;
int MoveSubWinAroundScreenTime;
BOOL ReverseDisplayBytes = FALSE;
int CmdDisplaySurface;
DWORD SubWinWidth, SubWinHeight;
BYTE MainWinLut[256*3];
BYTE SubWinLut[256*3];
/* ======== static variables ======== */
const char szVersion[] = "1.02";
#ifdef BUILD_WITH_INTERNAL_BMP_IMAGES
static BYTE ImgBuf[2048];
#endif
/* ======== static functions ======== */
unsigned Show13706(char *fname);
void CheckBpp(unsigned bpp);
unsigned ShowBMP(char *fname, unsigned DstX, unsigned DstY);
#if defined(INTEL_W32) || defined(INTEL_DOS)
void seLineBlt( BYTE far *pImgBuf, unsigned ImgWidth, unsigned DstX, unsigned Y, unsigned VirtualWidth, unsigned PhysicalWidth, unsigned Bpp );
#else
void seLineBlt( BYTE *pImgBuf, unsigned ImgWidth, unsigned DstX, unsigned Y, unsigned VirtualWidth, unsigned PhysicalWidth, unsigned Bpp );
#endif
//======================================
#ifdef BUILD_WITH_INTERNAL_BMP_IMAGES
unsigned ShowCompressed( unsigned char *ptr, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp );
unsigned ShowUncompressed( unsigned char *ptr, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp );
#else
unsigned ShowCompressed( int ff, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp );
unsigned ShowUncompressed( int ff, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp );
#endif
//======================================
#if defined(INTEL_W32) || defined(INTEL_DOS)
void Translate( BYTE far *pImgBuf, unsigned LineWidth, unsigned Bpp );
#else
void Translate( BYTE *pImgBuf, unsigned LineWidth, unsigned Bpp );
#endif
/*========================================================================*/
int main(int argc, char *argv[])
{
int surface;
unsigned val;
int error = 0;
unsigned width, height;
int count;
DWORD x1, y1, x2, y2;
DWORD x1_tmp, y1_tmp, x2_tmp, y2_tmp;
int dx, dy;
InitializeGlobalVariables();
DisplayCopyright();
#ifndef BUILD_WITH_INTERNAL_BMP_IMAGES
if ( (argc>8) || (argc<2) )
{
DisplayUsage();
return FAIL;
}
#endif
if ((error = ParseCommandLine(argc, argv)) != 0)
return error;
if ((error = RegisterDevice(&HalInfo)) != 0)
return error;
seCheckEndian(&ReverseDisplayBytes);
GetSubWinBmpSize();
if (gbInitRegisters)
{
if ((error = InitRegisters()) != 0)
return error;
}
if (!UpdateLcdOrientation())
return 1;
if ((error = HandleSelectedSurface()) != 0)
return error;
val = 0;
if (BmpCount == 1)
filename[1] = filename[0];
if (NumberOfSurfaces < BmpCount)
NumberOfSurfaces = BmpCount;
for (surface = 0; surface < NumberOfSurfaces; ++surface)
{
SetActiveSurfaceNumber(surface);
val = Show13706(filename[surface]);
if (val > 0)
return val;
}
if ((SurfaceDisplayMode[0] & SUB_WIN) ||
(SurfaceDisplayMode[1] & SUB_WIN))
{
if (CommonMemoryBlockForAllDisplays)
seUseMainWinImageForSubWin();
seGetSubWinCoordinates(&x1, &y1, &x2, &y2);
//
// Randomly move around screen
//
seGetMainWinResolution(&width, &height);
if (MoveSubWinAroundScreenTime != 0)
{
#ifndef BUILD_WITH_INTERNAL_BMP_IMAGES
srand((unsigned) time(NULL));
#endif
dx = ((rand() * 3L) / RAND_MAX) - 1;
dy = ((rand() * 3L) / RAND_MAX) - 1;
for (count = 0; (count <= MoveSubWinAroundScreenTime) || (MoveSubWinAroundScreenTime < 0);)
{
x1_tmp = (x1 + ((dx * 32L) / (signed) seGetBitsPerPixel()));
y1_tmp = y1 + dy * 2;
x2_tmp = (x2 + ((dx * 32L) / (signed) seGetBitsPerPixel()));
y2_tmp = y2 + dy * 2;
if ((x1_tmp >= 0) && (y1_tmp >= 0) &&
(x2_tmp >= 0) && (y2_tmp >= 0) &&
(x1_tmp < width) && (y1_tmp < height) &&
(x2_tmp < width) && (y2_tmp < height) &&
!((x1_tmp == x1) && (y1_tmp == y1) &&
(x2_tmp == x2) && (y2_tmp == y2)) )
{
x1 = x1_tmp;
y1 = y1_tmp;
x2 = x2_tmp;
y2 = y2_tmp;
// printf("(%d, %d) (%d, %d)\n", x1, y1, x2, y2);
seSetSubWinCoordinates(x1, y1, x2, y2);
seDelay(1);
++count;
}
else
{
dx = ((rand() * 3L) / RAND_MAX) - 1;
dy = ((rand() * 3L) / RAND_MAX) - 1;
}
}
}
}
return val;
}
/*------------------------------------GetSubWinBmpSize()-----*/
void GetSubWinBmpSize(void)
{
WORD bpp;
unsigned width, height;
//
// Determine dimensions of sub-window (if enabled)
//
seGetMainWinResolution(&width, &height);
SubWinWidth = (DWORD) width;
SubWinHeight = (DWORD) height;
if (BmpCount == 2)
{
GetBMPInfo(filename[1], &SubWinWidth, &SubWinHeight, &bpp, SubWinLut);
if (SubWinWidth > (DWORD) width)
SubWinWidth = (DWORD) width;
if (SubWinHeight > (DWORD) height)
SubWinHeight = (DWORD) height;
}
}
/*-------------------------------------------Show13706()------*/
unsigned Show13706(char *fname)
{
if (gbInitRegisters)
seDisplayBlank(TRUE);
ShowBMP(fname, 0, 0);
if (gbInitRegisters)
seDisplayBlank(FALSE);
#if defined(INTEL_W32) || defined(INTEL_DOS)
if (kbhit() && (getch() == ESC))
exit(1);
#endif
return SUCCEED;
}
/*---------------------------------------------GetBMPInfo( )------*/
#ifdef BUILD_WITH_INTERNAL_BMP_IMAGES
void GetBMPInfo(char *fname, DWORD *width, DWORD *height, WORD *BitsPerPixel, BYTE *pLut)
{
static BITMAPFILEHEADER bfh;
static BITMAPINFOHEADER inf;
WORD bfType;
const unsigned char *ptr;
int i;
RGBQUAD rgbQ;
if (!strcmpi(fname, "SUBWIN"))
ptr = SubWinBmp;
else
ptr = MainWinBmp;
memcpy(&bfh, ptr, sizeof(BITMAPFILEHEADER));
ptr += sizeof(BITMAPFILEHEADER);
if (ReverseDisplayBytes)
{
((BYTE *) &bfType)[0] = ((BYTE *) &bfh.bfType)[1];
((BYTE *) &bfType)[1] = ((BYTE *) &bfh.bfType)[0];
bfh.bfType = bfType;
}
if( bfh.bfType != BFT_BMAP )
{
printf("\nERROR: '%s' is not a valid bitmap file.\n",fname);
exit(1);
}
memcpy(&inf, ptr, sizeof(BITMAPINFOHEADER));
ptr += sizeof(BITMAPINFOHEADER);
if (ReverseDisplayBytes)
{
*BitsPerPixel = 0;
*width = 0;
*height = 0;
((BYTE *) BitsPerPixel)[0] = ((BYTE *) &inf.biBitCount)[1];
((BYTE *) BitsPerPixel)[1] = ((BYTE *) &inf.biBitCount)[0];
((BYTE *) width)[0] = ((BYTE *) &inf.biWidth)[3];
((BYTE *) width)[1] = ((BYTE *) &inf.biWidth)[2];
((BYTE *) width)[2] = ((BYTE *) &inf.biWidth)[1];
((BYTE *) width)[3] = ((BYTE *) &inf.biWidth)[0];
((BYTE *) height)[0] = ((BYTE *) &inf.biHeight)[3];
((BYTE *) height)[1] = ((BYTE *) &inf.biHeight)[2];
((BYTE *) height)[2] = ((BYTE *) &inf.biHeight)[1];
((BYTE *) height)[3] = ((BYTE *) &inf.biHeight)[0];
}
else
{
*BitsPerPixel = inf.biBitCount;
*width = (unsigned) inf.biWidth;
*height = (unsigned) inf.biHeight;
}
if (*BitsPerPixel <= 8) /* no DAC for 16 Bpp */
{
/* Init LUT entries */
for ( i=0; i < (1 << *BitsPerPixel); i++ )
{
memcpy(&rgbQ, ptr, sizeof(RGBQUAD));
ptr += sizeof(RGBQUAD);
*pLut++ = rgbQ.rgbRed;
*pLut++ = rgbQ.rgbGreen;
*pLut++ = rgbQ.rgbBlue;
}
}
}
//----------------------
#else
//----------------------
void GetBMPInfo(char *fname, DWORD *width, DWORD *height, WORD *BitsPerPixel, BYTE *pLut)
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER inf;
int ff, i;
RGBQUAD rgbQ;
if( (ff = open(fname,O_RDONLY | O_BINARY)) == -1 )
{
printf("\nERROR: Failed to open BMP file:'%s'\n", fname);
DisplayCopyright();
DisplayUsage();
close(ff);
exit(1);
}
read(ff,&bfh,sizeof(BITMAPFILEHEADER));
if( bfh.bfType != BFT_BMAP )
{
printf("\nERROR: '%s' is not a valid bitmap file.\n",fname);
close(ff);
exit(1);
}
read(ff,&inf,sizeof(BITMAPINFOHEADER));
*BitsPerPixel = inf.biBitCount;
*width = (unsigned) inf.biWidth;
*height = (unsigned) inf.biHeight;
if (*BitsPerPixel <= 8) /* no DAC for 16 Bpp */
{
/* Init LUT entries */
for ( i=0; i < (1 << (*BitsPerPixel)); i++ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -