Exemplo n.º 1
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;
	}

	// 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;
}
Exemplo n.º 2
0
bool C4Surface::ReadBMP(CStdStream &hGroup, int iFlags)
{
	int 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),
		                 std::min(sizeof(BitmapInfo)-sizeof(C4BMPInfo),sizeof(BitmapInfo)-sizeof(C4BMPInfo)+BitmapInfo.FileBitsOffset())))
			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;
	}

	// Create and lock surface
	if (!Create(BitmapInfo.Info.biWidth,BitmapInfo.Info.biHeight, iFlags)) return false;
	if (!Lock()) { Clear(); return false; }

	// 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:
				SetPixDw(x, lcnt, C4RGB(
				         BitmapInfo.Colors[*pPix].rgbRed,
				         BitmapInfo.Colors[*pPix].rgbGreen,
				         BitmapInfo.Colors[*pPix].rgbBlue));
				++pPix;
				break;
			case 24:
				SetPixDw(x, lcnt, C4RGB(pPix[0], pPix[1], pPix[2]));
				pPix+=3;
				break;
			}
	}
	// free buffer again
	delete [] pBuf;

	Unlock();

	return true;
}
Exemplo n.º 3
0
bool CSurface8::Read(CStdStream &hGroup, bool fOwnPal) {
  int cnt, lcnt, iLineRest;
  CBitmap256Info BitmapInfo;
  // read bmpinfo-header
  if (!hGroup.Read(&BitmapInfo, sizeof(CBitmapInfo))) return FALSE;
  // is it 8bpp?
  if (BitmapInfo.Info.biBitCount == 8) {
    if (!hGroup.Read(((BYTE *)&BitmapInfo) + sizeof(CBitmapInfo),
                     sizeof(BitmapInfo) - sizeof(CBitmapInfo)))
      return FALSE;
    if (!hGroup.Advance(BitmapInfo.FileBitsOffset())) return FALSE;
  } else {
    // read 24bpp
    if (BitmapInfo.Info.biBitCount != 24) return FALSE;
    if (!hGroup.Advance(((CBitmapInfo)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, fOwnPal))
    return FALSE;

  if (BitmapInfo.Info.biBitCount == 8) {
    if (HasOwnPal()) {
      // Copy palette
      for (cnt = 0; cnt < 256; cnt++) {
        pPal->Colors[cnt * 3 + 0] = BitmapInfo.Colors[cnt].rgbRed;
        pPal->Colors[cnt * 3 + 1] = BitmapInfo.Colors[cnt].rgbGreen;
        pPal->Colors[cnt * 3 + 2] = BitmapInfo.Colors[cnt].rgbBlue;
        pPal->Alpha[cnt] = 0;
      }
    }
  }

  // create line buffer
  int iBufSize =
      DWordAligned(BitmapInfo.Info.biWidth * BitmapInfo.Info.biBitCount / 8);
  BYTE *pBuf = new BYTE[iBufSize];
  // Read lines
  iLineRest = DWordAligned(BitmapInfo.Info.biWidth) - BitmapInfo.Info.biWidth;
  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;
}