📄 demo.c
字号:
/**==========================================================================\
*** DEMO.C - Demo program to show SwivelView mode with sub-window fixed to
*** side of display.
*** 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 "demo.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[] = "DEMO.C=$Revision: 3 $";
/*----------------------------------------------------------variables------*/
/* ======= global variables ======== */
int gbInitRegisters;
int gbImgCompress;
unsigned SurfaceDisplayMode[MAX_DISP_SURFACE];
int LcdOrientation;
int VerboseMode = FALSE;
int UseKeyboard = FALSE;
int NumberOfSurfaces;
int CommonMemoryBlockForAllDisplays;
int ActiveSurfaceNumber;
char *filename[MAX_DISP_SURFACE];
int BmpCount;
BOOL ReverseDisplayBytes = FALSE;
DWORD SubWinBmpWidth, SubWinBmpHeight;
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, unsigned surface);
void CheckBpp(unsigned bpp);
unsigned ShowBMP(char *fname, unsigned DstX, unsigned DstY, unsigned surface);
#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
void WaitForVndp(void);
//======================================
#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;
unsigned forever = TRUE;
DWORD SubWinOffsetAddr = 0;
DWORD SubWinLinearAddr = 0;
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], surface);
if (val > 0)
return val;
}
if ((SurfaceDisplayMode[0] & SUB_WIN) ||
(SurfaceDisplayMode[1] & SUB_WIN))
{
seSetSubWinAsActiveSurface();
seGetSubWinResolution(&width, &height);
SubWinOffsetAddr = seGetSurfaceOffsetAddress();
SubWinLinearAddr = seGetSurfaceLinearAddress();
if (!InitImageTranslation(width, height))
{
printf("ERROR: Could not allocate memory for memory buffers.\n");
exit(1);
}
// Landscape
CopySubWin2Buffer(SubWinLinearAddr);
TranslateLandscapeBottomToLandscapeRight();
CopyBuffer2SubWin(SubWinLinearAddr);
CopySubWin2Buffer(SubWinLinearAddr);
TranslateToRotate90();
CopyBuffer2SubWin(SubWinLinearAddr);
SetRotate90(SubWinLinearAddr);
WaitForVndp();
seMainWinDisplayBlank(FALSE);
if (UseKeyboard)
{
printf("Press any key to rotate display.\n");
printf("Press ESC to exit.\n");
}
else
printf("Display rotates every 3 seconds.\n");
while (forever)
{
if (UseKeyboard)
{
if (getch() == ESC)
exit(0);
}
else
seDelay(3);
// SwivelView 180
CopySubWin2Buffer(SubWinLinearAddr);
TranslateToRotate180();
WaitForVndp();
seMainWinDisplayBlank(TRUE);
CopyBuffer2SubWin(SubWinLinearAddr);
SetRotate180(SubWinLinearAddr);
WaitForVndp();
seMainWinDisplayBlank(FALSE);
if (UseKeyboard)
{
if (getch() == ESC)
exit(0);
}
else
seDelay(3);
// SwivelView 270
CopySubWin2Buffer(SubWinLinearAddr);
TranslateToRotate90();
WaitForVndp();
seMainWinDisplayBlank(TRUE);
CopyBuffer2SubWin(SubWinLinearAddr);
SetRotate270(SubWinLinearAddr);
WaitForVndp();
seMainWinDisplayBlank(FALSE);
if (UseKeyboard)
{
if (getch() == ESC)
exit(0);
}
else
seDelay(3);
// Landscape
CopySubWin2Buffer(SubWinLinearAddr);
TranslateToRotate180();
WaitForVndp();
seMainWinDisplayBlank(TRUE);
CopyBuffer2SubWin(SubWinLinearAddr);
SetRotateLandscape(SubWinLinearAddr);
WaitForVndp();
seMainWinDisplayBlank(FALSE);
if (UseKeyboard)
{
if (getch() == ESC)
exit(0);
}
else
seDelay(3);
// SwivelView 90
CopySubWin2Buffer(SubWinLinearAddr);
TranslateToRotate90();
WaitForVndp();
seMainWinDisplayBlank(TRUE);
CopyBuffer2SubWin(SubWinLinearAddr);
SetRotate90(SubWinLinearAddr);
WaitForVndp();
seMainWinDisplayBlank(FALSE);
}
}
return val;
}
/*------------------------------------GetSubWinBmpSize()-----*/
void GetSubWinBmpSize(void)
{
WORD bpp;
unsigned width, height;
//
// Determine dimensions of sub-window (if enabled)
//
seGetMainWinResolution(&width, &height);
SubWinBmpWidth = (DWORD) width;
SubWinBmpHeight = (DWORD) height;
if (BmpCount == 2)
{
GetBMPInfo(filename[1], &SubWinBmpWidth, &SubWinBmpHeight, &bpp, SubWinLut);
if (SubWinBmpWidth > (DWORD) width)
SubWinBmpWidth = (DWORD) width;
if (SubWinBmpHeight > (DWORD) height)
SubWinBmpHeight = (DWORD) height;
}
// width and height must be a multiple of 32 / bpp
if (SubWinBmpWidth != ((SubWinBmpWidth / (32 / bpp)) * (32 / bpp)))
++SubWinBmpWidth;
if (SubWinBmpHeight != ((SubWinBmpHeight / (32 / bpp)) * (32 / bpp)))
++SubWinBmpHeight;
}
/*-------------------------------------------Show13706()------*/
unsigned Show13706(char *fname, unsigned surface)
{
ShowBMP(fname, 0, 0, surface);
#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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -