コード例 #1
0
//************************************************************************
BOOL CDib::LoadFromResource(HINSTANCE hInstance, LPCSTR szResource, BOOL fDecodeRLE)
//************************************************************************
{
	HRSRC hDibRes;
	HGLOBAL hDib;
	LPTR lpDib;
	LPBITMAPINFO lpbmInfo; 
	DWORD dwBits;

	if ( !(hDibRes = FindResource(hInstance, szResource, RT_BITMAP)) )
		return(FALSE);
	if (! (hDib = LoadResource(hInstance, hDibRes)) )
		return(FALSE);
	lpDib = (LPTR)LockResource(hDib);
	if (!lpDib)
		return(FALSE);
	lpbmInfo = (LPBITMAPINFO)lpDib;
	m_bmiHeader = lpbmInfo->bmiHeader;
	FixHeader();
	hmemcpy(m_rgbQuad, lpbmInfo->bmiColors, GetNumColors() * sizeof(RGBQUAD));
	lpDib += m_bmiHeader.biSize + (GetNumColors() * sizeof(RGBQUAD));

	// Can we get enough memory to hold the DIB bits
	if ( (m_lp = AllocX( dwBits = GetSizeImage(), GMEM_ZEROINIT )) != NULL )
		hmemcpy(m_lp, lpDib, dwBits);
	UnlockResource(hDib);
	FreeResource(hDib);

	return(CheckDecodeRLE(fDecodeRLE));
}
コード例 #2
0
ファイル: strngs.cpp プロジェクト: 0xkasun/Dummy_Tes
BOOL8 STRING::operator!=(const STRING& str) const {
  FixHeader();
  str.FixHeader();
  const STRING_HEADER* str_header = str.GetHeader();
  const STRING_HEADER* this_header = GetHeader();
  int this_used = this_header->used_;
  int str_used  = str_header->used_;

  return (this_used != str_used)
         || (memcmp(GetCStr(), str.GetCStr(), this_used) != 0);
}
コード例 #3
0
ファイル: strngs.cpp プロジェクト: 0xkasun/Dummy_Tes
BOOL8 STRING::operator!=(const char* cstr) const {
  FixHeader();
  const STRING_HEADER* this_header = GetHeader();

  if (cstr == NULL)
    return this_header->used_ > 1;  // either '\0' or NULL
  else {
    inT32 length = strlen(cstr) + 1;
    return (this_header->used_ != length)
            || (memcmp(GetCStr(), cstr, length) != 0);
  }
}
コード例 #4
0
ファイル: hmp.cpp プロジェクト: corpsofengineers/ffed3d
//buf = HMP image, br = HMP image size, out_size = output MIDI image size
extern "C" void* load_hmp(BYTE* buf,DWORD br,DWORD* out_size)
{
	MIDIHEADER mhd = {1,0,0xC0};
	BYTE * max = buf+br;
	BYTE* ptr = buf;
	CWriteBuf* dst=wb_create();
	DWORD n1,n2;
	dst->writedword(_rv('MThd'));
	dst->writedword(_rv(6));
	dst->write(0,sizeof(mhd));
	ptr = buf+0x30;
	mhd.trax = *ptr;
	dst->write(hmp_track0,sizeof(hmp_track0));

	while(*(WORD*)ptr != 0x2FFF && ptr < max - 4-7) ptr++;
	ptr+=7;
	if (ptr == max-4) { dst->freebuf(); delete dst; return 0; }
	UINT n;

	for(n=1;n<mhd.trax;n++)
	{
		dst->writedword(_rv('MTrk'));
		n1 = *(DWORD*)ptr - 12;
		if (ptr + n1 > max) { dst->freebuf(); delete dst; return 0; }
		ptr += 8;
		
		UINT ts_ofs=dst->get_offs();
		dst->writedword(0);
		if (!(n2=ProcessTrack(ptr,dst,n1)))
			{ dst->freebuf(); delete dst; return 0; }
		
		dst->writedwordoffs(_rv(n2),ts_ofs);
		ptr += n1 + 4;
	}
	FixHeader(mhd);
	dst->writeoffs(&mhd,sizeof(mhd),8);


	UINT f_sz;
	BYTE* r=(BYTE*)dst->finish(&f_sz);
	delete dst;
	if (r)
	{
		if (out_size) *out_size=f_sz;
		return r;
	}
	else
	{
		return 0;
	}
}
コード例 #5
0
ファイル: strngs.cpp プロジェクト: 0xkasun/Dummy_Tes
STRING STRING::operator+(const char ch) const {
  STRING result;
  FixHeader();
  const STRING_HEADER* this_header = GetHeader();
  int this_used = this_header->used_;
  char* result_cstr = result.ensure_cstr(this_used + 1);
  STRING_HEADER* result_header = result.GetHeader();
  int result_used = result_header->used_;

  // copies '\0' but we'll overwrite that
  memcpy(result_cstr, GetCStr(), this_used);
  result_cstr[result_used] = ch;      // overwrite old '\0'
  result_cstr[result_used + 1] = '\0';  // append on '\0'
  ++result_header->used_;

  assert(InvariantOk());
  return result;
}
コード例 #6
0
ファイル: strngs.cpp プロジェクト: 0xkasun/Dummy_Tes
STRING& STRING::operator+=(const char ch) {
  if (ch == '\0')
    return *this;

  FixHeader();
  int   this_used = GetHeader()->used_;
  char* this_cstr = ensure_cstr(this_used + 1);
  STRING_HEADER* this_header = GetHeader();

  if (this_used > 0)
    --this_used; // undo old empty null if there was one

  this_cstr[this_used++] = ch;   // append ch to end
  this_cstr[this_used++] = '\0'; // append '\0' after ch
  this_header->used_ = this_used;

  assert(InvariantOk());
  return *this;
}
コード例 #7
0
ファイル: strngs.cpp プロジェクト: 0xkasun/Dummy_Tes
STRING & STRING::operator+=(const STRING& str) {
  FixHeader();
  str.FixHeader();
  const STRING_HEADER* str_header = str.GetHeader();
  const char* str_cstr = str.GetCStr();
  int  str_used  = str_header->used_;
  int  this_used = GetHeader()->used_;
  char* this_cstr = ensure_cstr(this_used + str_used);

  STRING_HEADER* this_header = GetHeader();  // after ensure for realloc

  if (this_used > 1) {
    memcpy(this_cstr + this_used - 1, str_cstr, str_used);
    this_header->used_ += str_used - 1;  // overwrite '\0'
  } else {
    memcpy(this_cstr, str_cstr, str_used);
    this_header->used_ = str_used;
  }

  assert(InvariantOk());
  return *this;
}
コード例 #8
0
ファイル: strngs.cpp プロジェクト: 0xkasun/Dummy_Tes
STRING&  STRING::operator+=(const char *str) {
  if (!str || !*str)  // empty string has no effect
    return *this;

  FixHeader();
  int len = strlen(str) + 1;
  int this_used = GetHeader()->used_;
  char* this_cstr = ensure_cstr(this_used + len);
  STRING_HEADER* this_header = GetHeader();  // after ensure for realloc

  // if we had non-empty string then append overwriting old '\0'
  // otherwise replace
  if (this_used > 0) {
    memcpy(this_cstr + this_used - 1, str, len);
    this_header->used_ += len - 1;
  } else {
    memcpy(this_cstr, str, len);
    this_header->used_ = len;
  }

  assert(InvariantOk());
  return *this;
}
コード例 #9
0
int main(int argc, char **argv)
{
	FILE *outfile = NULL;
	char *tempname = NULL;
	int j=0;
	
	if(argc!=3)
	{
		printf("usage: %s infolder outpack\n",argv[0]);
		return 0;
	}
	
	outfile = fopen(argv[2],"wb");
	tempname = (char*)calloc(strlen(argv[1])+4,sizeof(char));
	sprintf(tempname,"%s\\*",argv[1]);
	
	parsedir(tempname);
	FixHeader();
	WriteHeader(outfile);
	
	chdir(argv[1]);
	WriteFiles(outfile);
	chdir("..");
	
	free(tempname);
	
	while((ftell(outfile)%4)!=0)
	{
		fwrite(&pad[j],1,1,outfile);
		j = 1-j;
	}
	
	fclose(outfile);
	
	return 0;
}
コード例 #10
0
//************************************************************************
BOOL CDib::Create( int bits, int dx, int dy )
//************************************************************************
{
	DWORD dwSizeImage;
	int i;
	LPDWORD pdw;

	dwSizeImage = dy * (DWORD)((dx * bits/8+3)&~3);
	if ( !(m_lp = AllocX( dwSizeImage + 1024, GMEM_ZEROINIT )) )
		{
		return FALSE;
		}

#ifdef UNUSED // We can't use this because of a problem noted in DibToDCBlt()
	//	Get WinG to recommend the fastest DIB format
	//	Orientation = ( m_bmiHeader.biHeight < 0 ? -1 : 1 ); 
	if ( WinGRecommendDIBFormat( (LPBITMAPINFO)&m_bmiHeader ) )
		{ // make sure it's 8bpp
		m_bmiHeader.biWidth			*= dx;
		m_bmiHeader.biHeight		*= dy;
		m_bmiHeader.biBitCount		= bits;
		m_bmiHeader.biCompression	= BI_RGB;
		}
	else
#endif
		{ // set it up ourselves
		m_bmiHeader.biSize			= sizeof(BITMAPINFOHEADER);
		m_bmiHeader.biPlanes		= 1;
		m_bmiHeader.biSizeImage		= dwSizeImage;
		m_bmiHeader.biXPelsPerMeter = 0 ;
		m_bmiHeader.biYPelsPerMeter = 0 ;
		m_bmiHeader.biClrUsed		= 0 ;
		m_bmiHeader.biClrImportant	= 0 ;
		m_bmiHeader.biWidth			= dx;
		m_bmiHeader.biHeight		= dy;
		m_bmiHeader.biBitCount		= bits;
		m_bmiHeader.biCompression	= BI_RGB;
		}

	if (bits == 4)
		m_bmiHeader.biClrUsed = 16;
	else
	if (bits == 8)
		m_bmiHeader.biClrUsed = 256;

	pdw = (LPDWORD)m_rgbQuad;
	for (i=0; i<(int)m_bmiHeader.biClrUsed/16; i++)
		{
		*pdw++ = 0x00000000;	// 0000	 black
		*pdw++ = 0x00800000;	// 0001	 dark red
		*pdw++ = 0x00008000;	// 0010	 dark green
		*pdw++ = 0x00808000;	// 0011	 mustard
		*pdw++ = 0x00000080;	// 0100	 dark blue
		*pdw++ = 0x00800080;	// 0101	 purple
		*pdw++ = 0x00008080;	// 0110	 dark turquoise
		*pdw++ = 0x00C0C0C0;	// 1000	 gray
		*pdw++ = 0x00808080;	// 0111	 dark gray
		*pdw++ = 0x00FF0000;	// 1001	 red
		*pdw++ = 0x0000FF00;	// 1010	 green
		*pdw++ = 0x00FFFF00;	// 1011	 yellow
		*pdw++ = 0x000000FF;	// 1100	 blue
		*pdw++ = 0x00FF00FF;	// 1101	 pink (magenta)
		*pdw++ = 0x0000FFFF;	// 1110	 cyan
		*pdw++ = 0x00FFFFFF;	// 1111	 white
		}

	FixHeader();
	return TRUE;
}
コード例 #11
0
//	Will read a file in DIB format and return a global HANDLE to its
//	BITMAPINFO.	 This function will work with both "old" and "new"
//	bitmap formats, but will always return a "new" BITMAPINFO
//************************************************************************
BOOL CDib::ReadBitmapInfo( HFILE fh )
//************************************************************************
{
	DWORD off, size;
	HANDLE hbi = NULL;
	int i, nNumColors;
	LPRGBQUAD pRgb;
	BITMAPINFOHEADER bi;
	BITMAPCOREHEADER bc;
	BITMAPFILEHEADER bf;

	if ( fh < 0 )
		return FALSE;

	off = _llseek(fh,0L,SEEK_CUR);

	if (sizeof(bf) != _lread(fh,(LPSTR)&bf,sizeof(bf)))
		return FALSE;

	// do we have a RC HEADER?
	if (bf.bfType != BFT_BITMAP)
		{
		bf.bfOffBits = 0L;
		_llseek(fh,off,SEEK_SET);
		}

	if (sizeof(bi) != _lread(fh,(LPSTR)&bi,sizeof(bi)))
		return FALSE;

	// what type of bitmap info is this?
	if ( (size = bi.biSize) == sizeof(BITMAPCOREHEADER) )
		{
			bc = *(LPBITMAPCOREHEADER)&bi;
			bi.biSize				= sizeof(BITMAPINFOHEADER);
			bi.biWidth				= (DWORD)bc.bcWidth;
			bi.biHeight				= (DWORD)bc.bcHeight;
			bi.biPlanes				= (UINT)bc.bcPlanes;
			bi.biBitCount			= (UINT)bc.bcBitCount;
			bi.biCompression		= BI_RGB;
			bi.biSizeImage			= 0;
			bi.biXPelsPerMeter		= 0;
			bi.biYPelsPerMeter		= 0;
			bi.biClrUsed			= 0;
			bi.biClrImportant		= 0;
			_llseek(fh,(long)sizeof(BITMAPCOREHEADER)-sizeof(BITMAPINFOHEADER),SEEK_CUR);
		}

	//!!! hack for BI_BITFIELDS
	if ( bi.biCompression == BI_BITFIELDS && !bi.biClrUsed )
		bi.biClrUsed = 3;

	// Copy in the bitmap info header
	m_bmiHeader = bi;
	FixHeader();
	nNumColors = GetNumColors();
	pRgb = GetColors();

	if (nNumColors)
		{
		if (size == sizeof(BITMAPCOREHEADER))
			{
			// convert old color table (3 byte entries) to new (4 byte entries)
			_lread(fh,(LPVOID)pRgb,nNumColors * sizeof(RGBTRIPLE));

			for (i=nNumColors-1; i>=0; i--)
				{
				RGBQUAD rgb;

				rgb.rgbRed		= ((LPRGBTRIPLE)pRgb)[i].rgbtRed;
				rgb.rgbBlue		= ((LPRGBTRIPLE)pRgb)[i].rgbtBlue;
				rgb.rgbGreen	= ((LPRGBTRIPLE)pRgb)[i].rgbtGreen;
				rgb.rgbReserved = (BYTE)0;

				pRgb[i] = rgb;
				}
			}
		else
			{
			_lread(fh,(LPVOID)pRgb,nNumColors * sizeof(RGBQUAD));
			}
		}

	if (bf.bfOffBits)
		_llseek(fh,off + bf.bfOffBits,SEEK_SET);

	return TRUE;
}
コード例 #12
0
ファイル: strngs.cpp プロジェクト: 0xkasun/Dummy_Tes
inT32 STRING::length() const {
  FixHeader();
  return GetHeader()->used_ - 1;
}