📄 bmp.c
字号:
{
read(ff,&rgbQ,sizeof(RGBQUAD));
*pLut++ = rgbQ.rgbRed;
*pLut++ = rgbQ.rgbGreen;
*pLut++ = rgbQ.rgbBlue;
}
}
close(ff);
}
#endif
/*---------------------------------------------ShowBMP( )------*/
#ifdef BUILD_WITH_INTERNAL_BMP_IMAGES
unsigned ShowBMP(char *fname, unsigned DstX, unsigned DstY)
{
static BITMAPFILEHEADER bfh;
static BITMAPINFOHEADER inf;
static RGBQUAD rgbQ;
int i;
WORD BitsPerPixel, DesiredBitsPerPixel;
unsigned ImgWidth, ImgHeight;
unsigned nWidth, nHeight;
int tmp;
unsigned BytesPerScanline;
BYTE *pLut;
unsigned VirtualWidth, VirtualHeight;
WORD bfType;
BYTE LUT[256*3];
unsigned char *ptr;
if (!strcmpi(fname, "SUBWIN"))
ptr = (unsigned char *) SubWinBmp;
else
ptr = (unsigned char *) 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);
return FAIL;
}
memcpy(&inf, ptr, sizeof(BITMAPINFOHEADER));
ptr += sizeof(BITMAPINFOHEADER);
if (ReverseDisplayBytes)
{
BitsPerPixel = 0;
ImgWidth = 0;
ImgHeight = 0;
((BYTE *) &BitsPerPixel)[0] = ((BYTE *) &inf.biBitCount)[1];
((BYTE *) &BitsPerPixel)[1] = ((BYTE *) &inf.biBitCount)[0];
((BYTE *) &ImgWidth)[0] = ((BYTE *) &inf.biWidth)[3];
((BYTE *) &ImgWidth)[1] = ((BYTE *) &inf.biWidth)[2];
((BYTE *) &ImgWidth)[2] = ((BYTE *) &inf.biWidth)[1];
((BYTE *) &ImgWidth)[3] = ((BYTE *) &inf.biWidth)[0];
((BYTE *) &ImgHeight)[0] = ((BYTE *) &inf.biHeight)[3];
((BYTE *) &ImgHeight)[1] = ((BYTE *) &inf.biHeight)[2];
((BYTE *) &ImgHeight)[2] = ((BYTE *) &inf.biHeight)[1];
((BYTE *) &ImgHeight)[3] = ((BYTE *) &inf.biHeight)[0];
}
else
{
BitsPerPixel = inf.biBitCount;
ImgWidth = (unsigned) inf.biWidth;
ImgHeight = (unsigned) inf.biHeight;
}
if (inf.biCompression)
gbImgCompress = TRUE;
else
gbImgCompress = FALSE;
if (VerboseMode)
{
printf("Image Size: %d x %d x %d bits-per-pixel\n",
ImgWidth, ImgHeight, BitsPerPixel);
printf("Compression: ");
if (gbImgCompress)
printf("YES\n");
else
printf("NO\n");
}
if (BitsPerPixel == 24)
DesiredBitsPerPixel = 16;
else
DesiredBitsPerPixel = BitsPerPixel;
seGetResolution( &nWidth, &nHeight );
if (ImgHeight > nHeight)
VirtualHeight = ImgHeight;
else
VirtualHeight = nHeight;
seGetResolution(&VirtualWidth, &VirtualHeight);
BytesPerScanline = seGetBytesPerScanline();
if (BitsPerPixel >= 15)
tmp = 16;
else
tmp = BitsPerPixel;
VirtualWidth = (unsigned) (BytesPerScanline * 8L / tmp);
if (BitsPerPixel <= 8) /* no DAC for 16 Bpp */
{
/* Init LUT entries */
pLut = &LUT[0];
for ( i=0; i < (1 << BitsPerPixel); i++ )
{
memcpy(&rgbQ, ptr, sizeof(RGBQUAD));
ptr += sizeof(RGBQUAD);
*pLut++ = rgbQ.rgbRed;
*pLut++ = rgbQ.rgbGreen;
*pLut++ = rgbQ.rgbBlue;
}
}
if ( gbImgCompress == FALSE )
ShowUncompressed( ptr, DstX, DstY, ImgHeight, ImgWidth, VirtualWidth, VirtualHeight, nWidth, BitsPerPixel );
else
ShowCompressed( ptr, DstX, DstY, ImgHeight, ImgWidth, VirtualWidth, VirtualHeight, nWidth, BitsPerPixel );
if (BitsPerPixel <= 8) /* no DAC for 16 Bpp */
seWriteLut( LUT, (1 << BitsPerPixel) );
return SUCCEED;
}
//----------------------
#else
//----------------------
unsigned ShowBMP(char *fname, unsigned DstX, unsigned DstY)
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER inf;
RGBQUAD rgbQ;
int ff, i;
unsigned BitsPerPixel, DesiredBitsPerPixel;
unsigned ImgWidth, ImgHeight;
unsigned nWidth, nHeight;
int tmp;
unsigned BytesPerScanline;
BYTE *pLut;
unsigned VirtualWidth, VirtualHeight;
BYTE LUT[256*3];
if( (ff = open(fname,O_RDONLY | O_BINARY)) == -1 )
{
printf("\nERROR: Failed to open BMP file:'%s'\n", fname);
DisplayCopyright();
DisplayUsage();
close(ff);
return FAIL;
}
read(ff,&bfh,sizeof(BITMAPFILEHEADER));
if( bfh.bfType != BFT_BMAP )
{
printf("\nERROR: '%s' is not a valid bitmap file.\n",fname);
close(ff);
return FAIL;
}
read(ff,&inf,sizeof(BITMAPINFOHEADER));
BitsPerPixel = inf.biBitCount;
ImgWidth = (unsigned) inf.biWidth;
ImgHeight = (unsigned) inf.biHeight;
if (inf.biCompression)
gbImgCompress = TRUE;
else
gbImgCompress = FALSE;
if (VerboseMode)
{
printf("Image Size: %d x %d x %d bits-per-pixel\n",
ImgWidth, ImgHeight, BitsPerPixel);
printf("Compression: ");
if (gbImgCompress)
printf("YES\n");
else
printf("NO\n");
}
if (BitsPerPixel == 24)
DesiredBitsPerPixel = 16;
else
DesiredBitsPerPixel = BitsPerPixel;
seGetResolution( &nWidth, &nHeight );
if (ImgHeight > nHeight)
VirtualHeight = ImgHeight;
else
VirtualHeight = nHeight;
seGetResolution(&VirtualWidth, &VirtualHeight);
BytesPerScanline = seGetBytesPerScanline();
if (BitsPerPixel >= 15)
tmp = 16;
else
tmp = BitsPerPixel;
VirtualWidth = (unsigned) (BytesPerScanline * 8L / tmp);
if (BitsPerPixel <= 8) /* no DAC for 16 Bpp */
{
/* Init LUT entries */
pLut = &LUT[0];
for ( i=0; i< (1 << BitsPerPixel); i++ )
{
read(ff,&rgbQ,sizeof(RGBQUAD));
*pLut++ = rgbQ.rgbRed;
*pLut++ = rgbQ.rgbGreen;
*pLut++ = rgbQ.rgbBlue;
}
}
if ( gbImgCompress == FALSE )
ShowUncompressed( ff, DstX, DstY, ImgHeight, ImgWidth, VirtualWidth, VirtualHeight, nWidth, BitsPerPixel );
else
ShowCompressed( ff, DstX, DstY, ImgHeight, ImgWidth, VirtualWidth, VirtualHeight, nWidth, BitsPerPixel );
if (BitsPerPixel <= 8) /* no DAC for 16 Bpp */
seWriteLut( LUT, (1 << BitsPerPixel) );
close(ff);
return SUCCEED;
}
#endif
/*---------------------------------------------LineBlt( )------*/
//
// Because VirtualWidth is always 1024 in SwivelView 90/270 modes, it is necessary
// to determine how wide the display is with PhysicalWidth. PhysicalWidth, for a panel
// of 640x480 in SwivelView 90/270, is 480 pixels wide.
//
#if defined(INTEL_W32) || defined(INTEL_DOS)
void LineBlt( BYTE far *pImgBuf, unsigned ImgWidth, unsigned DstX, unsigned DstY, unsigned VirtualWidth, unsigned PhysicalWidth, unsigned Bpp, DWORD DispLinearAddr )
#else
void LineBlt( BYTE *pImgBuf, unsigned ImgWidth, unsigned DstX, unsigned DstY, unsigned VirtualWidth, unsigned PhysicalWidth, unsigned Bpp, DWORD DispLinearAddr )
#endif
{
DWORD DstAddr;
unsigned regDisplayMode;
DWORD Count;
DWORD Mask;
DWORD val, val2, val3;
DWORD *dwImgBuf;
/* adjust ImgWidth */
if ( ImgWidth > (PhysicalWidth-DstX) )
{
ImgWidth = PhysicalWidth-DstX;
}
regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
DstAddr = DispLinearAddr - seGetLinearDisplayAddress();
if (DstAddr > seGetInstalledMemorySize())
DstAddr = 0;
DstAddr += ((DWORD)DstY*(DWORD)VirtualWidth + DstX) * Bpp / 8;
if (DstAddr < 0x140000)
{
dwImgBuf = (DWORD *) pImgBuf;
Count = ImgWidth * Bpp;
Mask = (1 << (Count & 31)) - 1;
Count >>= 5;
do
{
val = *dwImgBuf++;
seWriteDisplayDwords(DstAddr, val, 1);
DstAddr += sizeof (long);
--Count;
} while (Count);
val = *dwImgBuf;
val2 = seReadDisplayDword(DstAddr);
val3 = (val & Mask) | (val2 & ~Mask);
seWriteDisplayDwords(DstAddr, val3, 1);
}
}
/*---------------------------------------------seLineBlt( )------*/
#if defined(INTEL_W32) || defined(INTEL_DOS)
void seLineBlt( BYTE far *pImgBuf, unsigned ImgWidth, unsigned DstX, unsigned DstY, unsigned VirtualWidth, unsigned PhysicalWidth, unsigned Bpp )
#else
void seLineBlt( BYTE *pImgBuf, unsigned ImgWidth, unsigned DstX, unsigned DstY, unsigned VirtualWidth, unsigned PhysicalWidth, unsigned Bpp )
#endif
{
switch (CalcDisplaySurfaceCombination())
{
default:
case SURFACE_MAIN_WIN0:
seSetMainWinAsActiveSurface();
LineBlt(pImgBuf, ImgWidth, DstX, DstY, VirtualWidth, PhysicalWidth, Bpp, seGetSurfaceLinearAddress());
break;
case SURFACE_MAIN_WIN0_SUB_WIN1:
case SURFACE_MAIN_AND_SUB_WIN0:
if (GetActiveSurfaceNumber() == 0)
seSetMainWinAsActiveSurface();
else if (GetActiveSurfaceNumber() == 1)
seSetSubWinAsActiveSurface();
LineBlt(pImgBuf, ImgWidth, DstX, DstY, VirtualWidth, PhysicalWidth, Bpp, seGetSurfaceLinearAddress());
break;
}
}
/*-----------------------------------------------------------------------*/
/* we only support RLE_8 & RLE_4 format */
/*-----------------------------------------------------------------------*/
#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 LineCount=0;
unsigned LineWidth=0;
unsigned ColumnCount=0;
unsigned Val, Y, tmp1, i;
WORD tmp;
unsigned PreReadLine=0;
#if defined(INTEL_W32) || defined(INTEL_DOS)
BYTE far * pTmp;
BYTE far *pImgBuf;
#else
BYTE *pTmp;
BYTE *pImgBuf;
#endif
unsigned DesiredBpp;
int forever = TRUE;
unsigned len;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -