Пример #1
0
BOOL CStdBitmap::Enlarge(int iWdt, int iHgt) {
  if (!Bits) return FALSE;
  iWdt = Max(iWdt, (int)Info.biWidth);
  iHgt = Max(iHgt, (int)Abs(Info.biHeight));
  if (!((iWdt > Info.biWidth) || (iHgt > Abs(Info.biHeight)))) return FALSE;
  int nPitch = DWordAligned(iWdt * Info.biBitCount / 8);
  int nSize = nPitch * iHgt;
  BYTE *nBits;
  if (!(nBits = new BYTE[nSize])) return FALSE;
  ZeroMem(nBits, nSize);
  iHgt *= Sign(Info.biHeight);
  StdBlit((uint8_t *)Bits, Info.Pitch(), Info.biHeight, 0, 0, Info.biWidth,
          Info.biHeight, (uint8_t *)nBits, nPitch, iHgt, 0, 0, Info.biWidth,
          Info.biHeight, Info.biBitCount / 8);
  Info.biWidth = iWdt;
  Info.biHeight = iHgt;
  Info.biSizeImage = nSize;
  delete[] Bits;
  Bits = nBits;
  return TRUE;
}
Пример #2
0
void CBitmap256Info::Set(int iWdt, int iHgt, BYTE *bypPalette)
	{
	Default();
  // Set header
  Head.bfType=*((WORD*)"BM");
  Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+DWordAligned(iWdt)*iHgt;
  Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);
  // Set bitmap info
  Info.biSize=sizeof(BITMAPINFOHEADER);
  Info.biWidth=iWdt;
  Info.biHeight=iHgt;
  Info.biPlanes=1;
  Info.biBitCount=8;
  Info.biCompression=0;
  Info.biSizeImage=iWdt*iHgt;
  Info.biClrUsed=Info.biClrImportant=256;
	// Set palette
  for (int cnt=0; cnt<256; cnt++)
    {
    Colors[cnt].rgbRed	 = bypPalette[cnt*3+0];
    Colors[cnt].rgbGreen = bypPalette[cnt*3+1];
    Colors[cnt].rgbBlue  = bypPalette[cnt*3+2];
    }    
	}
Пример #3
0
bool CSurface8::Read(CStdStream &hGroup)
{
	int cnt,lcnt;
	C4BMP256Info BitmapInfo;
	// read bmpinfo-header
	if (!hGroup.Read(&BitmapInfo,sizeof(C4BMPInfo))) return false;
	// is it 8bpp?
	if (BitmapInfo.Info.biBitCount == 8)
	{
		if (!hGroup.Read(((BYTE *) &BitmapInfo)+sizeof(C4BMPInfo),sizeof(BitmapInfo)-sizeof(C4BMPInfo))) return false;
		if (!hGroup.Advance(BitmapInfo.FileBitsOffset())) return false;
	}
	else
	{
		// read 24bpp
		if (BitmapInfo.Info.biBitCount != 24) return false;
		if (!hGroup.Advance(((C4BMPInfo) BitmapInfo).FileBitsOffset())) return false;
	}
	// no 8bpp-surface in newgfx!
	// needs to be kept for some special surfaces
	//f8BitSfc=false;

	// Create and lock surface
	if (!Create(BitmapInfo.Info.biWidth,BitmapInfo.Info.biHeight)) return false;

	if (BitmapInfo.Info.biBitCount == 8)
	{
		// Copy palette
		for (cnt=0; cnt<256; cnt++)
		{
			pPal->Colors[cnt] = C4RGB(BitmapInfo.Colors[cnt].rgbRed,
			                          BitmapInfo.Colors[cnt].rgbGreen,
			                          BitmapInfo.Colors[cnt].rgbBlue);
		}
	}

	// create line buffer
	int iBufSize=DWordAligned(BitmapInfo.Info.biWidth*BitmapInfo.Info.biBitCount/8);
	BYTE *pBuf = new BYTE[iBufSize];
	// Read lines
	for (lcnt=Hgt-1; lcnt>=0; lcnt--)
	{
		if (!hGroup.Read(pBuf, iBufSize))
			{ Clear(); delete [] pBuf; return false; }
		BYTE *pPix=pBuf;
		for (int x=0; x<BitmapInfo.Info.biWidth; ++x)
			switch (BitmapInfo.Info.biBitCount)
			{
			case 8:
				SetPix(x, lcnt, *pPix++);
				break;
			case 24:
				return false;
				break;
			}
	}
	// free buffer again
	delete [] pBuf;

	return true;
}
Пример #4
0
void C4BMP256Info::Set(int iWdt, int iHgt, CStdPalette *Palette)
{
    Default();
    // Set header
    Head.bfType=*((const WORD*)"BM");
    Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+DWordAligned(iWdt)*iHgt;
    Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);
    // Set bitmap info
    Info.biSize=sizeof(BITMAPINFOHEADER);
    Info.biWidth=iWdt;
    Info.biHeight=iHgt;
    Info.biPlanes=1;
    Info.biBitCount=8;
    Info.biCompression=0;
    Info.biSizeImage=iWdt*iHgt;
    Info.biClrUsed=Info.biClrImportant=256;
    // Set palette
    for (int cnt=0; cnt<256; cnt++)
    {
        Colors[cnt].rgbRed   = GetRedValue(Palette->Colors[cnt]);
        Colors[cnt].rgbGreen = GetGreenValue(Palette->Colors[cnt]);
        Colors[cnt].rgbBlue  = GetBlueValue(Palette->Colors[cnt]);
    }
}