⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capture.c

📁 超级解霸源代码。纯c语言写的。适合有一定编程基础的开发人员用来学习提高
💻 C
📖 第 1 页 / 共 2 页
字号:
		{
		PalPtr[i].rgbBlue 	*=4;
		PalPtr[i].rgbGreen	*=4;
		PalPtr[i].rgbRed 	*=4;
		}
}
static	void	PaletteChange(char R,char G,char B)
{
	int	i;
	PalPtr=(LPRGBQUAD)(GlobalLock(Bmp256CPalMem)+sizeof(BITMAPINFOHEADER));
	for(i=0;i<256;i++)
		{
		PalPtr[i].rgbBlue +=B;
		PalPtr[i].rgbGreen+=G;
		PalPtr[i].rgbRed  +=R;
		}
	GlobalUnlock(Bmp256CPalMem);
}
BYTE far * 	IndexPtr;
static	void	TranslateTo256Colors(void)
{
	int	i,j;
	int	Pal;
	BYTE	R,G,B;
	DWORD	IndexOffset=0;
	DWORD	RGBOffset=0;
	HCURSOR	hWaitCursor,hOldCursor;

	hWaitCursor=LoadCursor(NULL,IDC_WAIT);
	hOldCursor=SetCursor(hWaitCursor);
	PalPtr=(LPRGBQUAD)(GlobalLock(Bmp256CPalMem)+sizeof(BITMAPINFOHEADER));
	IndexPtr=GlobalLock(Bmp256CMem);
	FilehMemPtr=GlobalLock(FilehMem);
	for(i=0;i<VCDHigh;i++)
		for(j=0;j<352;j++)
			{
			_ES=FilehMem;	//RGB memory
			_EBX=RGBOffset;
			__emit__(0x26,0x67,0x8B,0x03);//asm ax,es:[ebx]
			__emit__(0x26,0x67,0x8A,0x53,0x02);//asm dl,es:[ebx+2]
			asm	shr	al,2	//B
			asm	shr	ah,2	//G
			asm	shr	dl,2	//R
			Pal=SearchLong();//RGB is 64 level,It is 6:6:6
			_ES=Bmp256CMem;	//Index memory
			_EBX=IndexOffset;
			_AL=Pal;
			__emit__(0x26,0x67,0x88,0x03);//asm mov es:[ebx],al
			RGBOffset+=3;
			IndexOffset++;
			}
	PaletteNormal();
	GlobalUnlock(Bmp256CPalMem);
	GlobalUnlock(Bmp256CMem);
	GlobalUnlock(FilehMem);
	SetCursor(hOldCursor);
}
static	HPALETTE	CreateCapturePalette(void)
{
	HPALETTE	CapturehPal;	//The 256 Color Capture hPalette
	LOGPALETTE FAR* lpPal;

	lpPal=(LOGPALETTE FAR*)(GlobalLock(Bmp256CPalMem)+sizeof(BITMAPINFOHEADER)-4);
	lpPal->palNumEntries 	= 256;
	lpPal->palVersion 	= 0x300;
	CapturehPal=CreatePalette(lpPal);
	GlobalUnlock(Bmp256CPalMem);
	return	CapturehPal;
}
static	void	CreateBitmapInfoHeader(void)
{
	BITMAPINFOHEADER far *	BmpInfoPtr;

	BmpInfoPtr=(BITMAPINFOHEADER far *)GlobalLock(Bmp256CPalMem);
	BmpInfoPtr->biSize		=sizeof(BITMAPINFOHEADER);
	BmpInfoPtr->biWidth		=352;
	BmpInfoPtr->biHeight		=VCDHigh;
	BmpInfoPtr->biPlanes		=1;
	BmpInfoPtr->biBitCount		=8;
	BmpInfoPtr->biCompression	=0;
	BmpInfoPtr->biSizeImage		=352L*VCDHigh;
	BmpInfoPtr->biXPelsPerMeter	=0;
	BmpInfoPtr->biYPelsPerMeter	=0;
	BmpInfoPtr->biClrUsed		=256;
	BmpInfoPtr->biClrImportant	=256;
}
static	void	PASCAL	SavePalette(HFILE hFile)
{
	PalPtr=(LPRGBQUAD)(GlobalLock(Bmp256CPalMem)+sizeof(BITMAPINFOHEADER));
	_lwrite(hFile,PalPtr,0x400);
	GlobalUnlock(Bmp256CPalMem);
}
static	void	PASCAL	SaveImage256(HFILE hFile)
{
	IndexPtr=GlobalLock(Bmp256CMem);
	_hwrite(hFile,IndexPtr,352L*VCDHigh);
	GlobalUnlock(Bmp256CMem);
}
////////////////////// PCX ///////////////////////
typedef struct PCXHEADERtag
	{
	BYTE 	ManuFacturer;	// 0A
	BYTE 	Version;
	BYTE 	Encoding;   	// 1
	BYTE 	Bits;
	WORD	XMin,YMin;
	WORD	XMax,YMax;
	WORD	Width;
	WORD	High;
	BYTE	Palette[16][3];	// 16 Colors
	BYTE	Reserved;
	BYTE	Planes;
	WORD	BytesOfLine;
	WORD	PaletteType;
	BYTE	Filler[58];
	} PCXHEADER;		// 128 Bytes
PCXHEADER	PCXHeader=
	{
	10,
	5,
	1,
	8,
	0,0,
	351,239,	//XMax,YMax
	640,480,	//Width,High
	{
	{0x00,0x00,0x00},{0x10,0x10,0x10},{0x20,0x20,0x20},{0x30,0x30,0x30},
	{0x40,0x40,0x40},{0x50,0x50,0x50},{0x60,0x60,0x60},{0x70,0x70,0x70},
	{0x80,0x80,0x80},{0x90,0x90,0x90},{0xA0,0xA0,0xA0},{0xB0,0xB0,0xB0},
	{0xC0,0xC0,0xC0},{0xD0,0xD0,0xD0},{0xE0,0xE0,0xE0},{0xF0,0xF0,0xF0}
	},
	0,
	1,
	352,
	1,
	0
	};
static	void	WritePCXHeader(HFILE hFile)
{
	PCXHeader.High=VCDHigh;
	PCXHeader.YMax=VCDHigh-1;
	_lwrite(hFile,&PCXHeader,sizeof(PCXHeader));
}
DWORD	PCXSize=0;
static	void	WriteToMemory(BYTE Pixel)
{
	_ES=FilehMem;
	_EBX=PCXSize;
	asm	mov	al,Pixel
	__emit__(0x26,0x67,0x88,0x03);//asm es:[ebx],al
	PCXSize++;
}
static	void	SavePCXImage256(HFILE hFile)
{
	BYTE	Pixel,OldPixel,Count;
	int	i,j;
	DWORD	Offset;

	PCXSize=0;
	IndexPtr=GlobalLock(Bmp256CMem);
	FilehMemPtr=GlobalLock(FilehMem);
	for(j=0;j<VCDHigh;j++)
		{
		Offset=352L*(VCDHigh-j-1);
		Count=0;
		for(i=0;i<352;i++)
			{
			_ES=Bmp256CMem;
			_EBX=Offset;
			__emit__(0x26,0x67,0x8A,0x03);//asm mov	al,es:[ebx]
			Pixel=_AL;
			if(i==0){
				OldPixel=Pixel;
				Count++;
				}
			else	{
				if(OldPixel!=Pixel || Count>=0x3F)
					{
					if(Count==1)
						{
						if((OldPixel&0xC0)==0xC0)
							{//the Pixel >=0xC0
							Count=0xC1;
							WriteToMemory(Count);
							WriteToMemory(OldPixel);
							}
						else	{
							WriteToMemory(OldPixel);
							}
						}
					else	{//Count != 0
						Count|=0xC0;
						WriteToMemory(Count);
						WriteToMemory(OldPixel);
						}
					OldPixel=Pixel;
					Count=0;
					}
				Count++;
				}
			Offset++;
			}
		if(Count>1)//Save left
			{
			Count|=0xC0;
			WriteToMemory(Count);
			WriteToMemory(OldPixel);
			}
		else	{
			if(Count==1)
				{
				if((OldPixel&0xC0)==0xC0)
					{//the Pixel >=0xC0
					Count=0xC1;
					WriteToMemory(Count);
					WriteToMemory(OldPixel);
					}
				else	{
					WriteToMemory(OldPixel);
					}
				}
			}
		}
	GlobalUnlock(Bmp256CMem);
	_hwrite(hFile,FilehMemPtr,PCXSize);
	GlobalUnlock(FilehMem);
}
static	void	SavePCXPalette(HFILE hFile)
{
	int		i;
	BYTE far *	Ptr;

	PalPtr=(LPRGBQUAD)(GlobalLock(Bmp256CPalMem)+sizeof(BITMAPINFOHEADER));
	Ptr=FilehMemPtr=GlobalLock(FilehMem);
	*Ptr++=0x0C;
	for(i=0;i<256;i++)
		{
		*Ptr++=PalPtr[i].rgbRed;
		*Ptr++=PalPtr[i].rgbGreen;
		*Ptr++=PalPtr[i].rgbBlue;
		}
	_lwrite(hFile,FilehMemPtr,769);
	GlobalUnlock(Bmp256CPalMem);
	GlobalUnlock(FilehMem);
}
DWORD	huge	PASCAL	Modify256ColorProc(HWND hwnd,WORD message,WORD wParam,LONG lParam);
static	void	BuildFile(HFILE hFile,int Index)
{
	PictureType=Index;
	switch(Index)
		{
		case 1:	Write24BitBMPHeader(hFile);//Write the bmp file header
			Decode24BitsToFile(hFile);	//Decode the Picture to file
			break;
		case 2: //Double Size 24 bit bitmap
			WriteD24BitBMPHeader(hFile);//Write the bmp file header
			DecodeD24BitsToFile(hFile);	//Decode the Picture to file
			break;
		case 3:	Write8BitBMPHeader(hFile);//Write the bmp file header
			Decode8BitsGrayScaleToFile(hFile);//Decode the Picture to file
			break;
		case 4: Write8BitBMPHeader(hFile);//256 Color BMP header
			Decode24BitsToMemory();//Decode to 24 bit ture colors
			Allocate256ColorMemory();
			///////////// To 256 Colors //////////////
			PalCount=0;Default=6;
			TranslateTo256Colors();//Decode to 256 Colors
			if(Chinese) DialogBox(hInst,"Modify256CC",NULL,(DLGPROC)Modify256ColorProc);
			else DialogBox(hInst,"Modify256C",NULL,(DLGPROC)Modify256ColorProc);
			//////////////////////////////////////////
			SavePalette(hFile);
			SaveImage256(hFile);
			FreeAllMemory();
			break;
		case 5: WritePCXHeader(hFile);
			Decode24BitsToMemory();//Decode to 24 bit ture colors
			Allocate256ColorMemory();
			///////////// To 256 Colors //////////////
			PalCount=0;Default=6;
			TranslateTo256Colors();//Decode to 256 Colors
			if(Chinese)	DialogBox(hInst,"Modify256CC",NULL,(DLGPROC)Modify256ColorProc);
			else	DialogBox(hInst,"Modify256C",NULL,(DLGPROC)Modify256ColorProc);
			//////////////////////////////////////////
			SavePCXImage256(hFile);
			SavePCXPalette(hFile);
			FreeAllMemory();
			break;
		}
}
extern	char	Buffer[80];
static	void	GetDirPath(void)
{
	int	Ret;
	char	tmpBuffer[128];

	GetCWD(Buffer,sizeof(Buffer));
	lstrcpy(tmpBuffer,Buffer);
	lstrcat(tmpBuffer,"\\STHMPEG.INI");
	Ret=GetPrivateProfileString("SthAV","SavePicturePath","",DirName,sizeof(DirName),tmpBuffer);
	if(Ret==0)//Read from INI file.
		{
		GetCWD(DirName,sizeof(DirName));
		}
}
static	void	SavePath(void)
{
	GetCWD(DirName,sizeof(DirName));
	GoHome();		//Change to Locate Dir.
	lstrcat(Buffer,"\\STHMPEG.INI");	//The Buffer got prev
	WritePrivateProfileString("SthAV","SavePicturePath",DirName,Buffer);
}
static	void	PASCAL	SaveVideoPicture(void)
{
	lstrcpy(FileName,DefaultBmpName);
	///////////////////////////////////////
	GetDirPath();
	///////////////////////////////////////
	ofn.lStructSize	 	= sizeof(OPENFILENAME);
	ofn.hwndOwner 		= AudioMainWindow;
	ofn.lpstrFilter 	= Filter;
	ofn.nFilterIndex	= 1;
	ofn.lpstrFile		= FileName;
	ofn.nMaxFile 		= sizeof(FileName);
	ofn.lpstrInitialDir 	= DirName;
	ofn.lpstrTitle		= BmpTitle;
	ofn.lpstrFileTitle 	= FileTitle;
	ofn.nMaxFileTitle 	= sizeof(FileTitle);
	ofn.lpstrCustomFilter 	= NULL;
	ofn.nMaxCustFilter 	= 0L;
	ofn.nFileOffset 	= 0;
	ofn.nFileExtension 	= 0;
	ofn.lpstrDefExt 	= NULL;
	ofn.lCustData 		= 0L;
	ofn.lpfnHook 		= NULL;
	ofn.lpTemplateName 	= NULL;
	ofn.Flags 		= OFN_OVERWRITEPROMPT //| OFN_SHOWHELP
				| OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;;
	if(GetSaveFileName(&ofn))
		{
		// Perform file operations. Decode Video to BMP File.
		HFILE	hFile;
		hFile=_lcreat(FileName,0);
		if(hFile==HFILE_ERROR)
			{
			MessageBox(NULL,"Create File Error !","ERROR",MB_ICONSTOP);
			return;
			}
		BuildFile(hFile,ofn.nFilterIndex);
		_lclose(hFile);
		}
	SavePath();
}
///////////////////////////////////////////////////////////////
extern	int	Playing;
extern	int	DisplayPreView;
extern	HWND 	ShowVideo;
int	Caputuring=0;
void	PASCAL FAR	CapturePicture(void)	//API
{
	int	CurPlayState;
	MSG	msg;

	if(Caputuring)	return;
	Caputuring=1;
	CurPlayState=Playing;
	DisplayPreView=0;
	//////////////if playing stop it ///////////
	if(Playing)
		{//Stop playing
		SendMessage(MainWindow,WM_KEYDOWN,VK_SPACE,0L);
		SendMessage(MainWindow,WM_KEYUP,VK_SPACE,0L);
		}
	////////// Wait when not playing.
	while(Playing)
		{//Wait Stop playing.
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
			{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			}
		}
	/////////////// Dialog Box input file name ////////////
	SaveVideoPicture();
	//////////////if stop playing restart it //////////////
	if(CurPlayState)
		{//Restart playing
		SendMessage(MainWindow,WM_KEYDOWN,VK_SPACE,0L);
		SendMessage(MainWindow,WM_KEYUP,VK_SPACE,0L);
		}
	Caputuring=0;	//End Capture Video
	DisplayPreView=1;
	if(CurPlayState==0)//On stop state repaint the preview.
		InvalidateRect(ShowVideo,NULL,TRUE);//Update the preview area
}
//////////////////////// Dialog Box Proc ///////////////////
static	void	DisplayThePicture(HDC hdc)
{
	HPALETTE	CapturehPal;	//The 256 Color Capture hPalette
	HPALETTE	hOldPal;
	BITMAPINFOHEADER far *	BmpInfoPtr;

	CapturehPal=CreateCapturePalette();//Create Palette
	CreateBitmapInfoHeader();//Create Bitmap info
	IndexPtr=GlobalLock(Bmp256CMem);
	BmpInfoPtr=(BITMAPINFOHEADER far *)GlobalLock(Bmp256CPalMem);
	hOldPal=SelectPalette(hdc,CapturehPal,FALSE);
	RealizePalette(hdc);
	SetDIBitsToDevice(hdc,0,0,352,VCDHigh,0,0,0,VCDHigh,IndexPtr,
				(BITMAPINFO FAR*)BmpInfoPtr,DIB_RGB_COLORS);
	SelectPalette(hdc,hOldPal,FALSE);
	GlobalUnlock(Bmp256CMem);
	GlobalUnlock(Bmp256CPalMem);
	DeleteObject(CapturehPal);
}
#pragma	warn -par
DWORD	huge	PASCAL	Modify256ColorProc(HWND hwnd,WORD message,WORD wParam,LONG lParam)
{
	PAINTSTRUCT 	ps;
	HDC		hdc;
	char		Buffer[16];

	switch(message)
		{
		case 	WM_INITDIALOG:
			return TRUE;
		case	WM_PAINT:
			hdc=BeginPaint(hwnd,&ps);
			DisplayThePicture(hdc);
			EndPaint(hwnd,&ps);
			break;
		case	WM_COMMAND:
			switch(wParam)
				{
				case 1://OK
				EndDialog(hwnd,wParam);
				return TRUE;
				// R
				case 100://--
				case 101://++
					if(wParam==100) PaletteChange(-4,0,0);
					else PaletteChange(4,0,0);
					hdc=GetDC(hwnd);
					DisplayThePicture(hdc);
					ReleaseDC(hwnd,hdc);
					break;
				// G
				case 102://--
				case 103://++
					if(wParam==102) PaletteChange(0,-4,0);
					else PaletteChange(0,4,0);
					hdc=GetDC(hwnd);
					DisplayThePicture(hdc);
					ReleaseDC(hwnd,hdc);
					break;
				// B
				case 104://--
				case 105://++
					if(wParam==104) PaletteChange(0,0,-4);
					else PaletteChange(0,0,4);
					hdc=GetDC(hwnd);
					DisplayThePicture(hdc);
					ReleaseDC(hwnd,hdc);
					break;
				// Level
				case 106:Default-=2;	//--
				case 107:Default++;	//++
					if(Default<0)
						{
						Default=0;
						break;
						}
					if(Default>99)
						{
						Default=99;
						break;
						}
					PalCount=0;
					wsprintf(Buffer,"%d",Default);
					SetDlgItemText(hwnd,200,Buffer);
					TranslateTo256Colors();
					hdc=GetDC(hwnd);
					DisplayThePicture(hdc);
					ReleaseDC(hwnd,hdc);
					break;
				}
			break;
		case	WM_CLOSE:
			EndDialog(hwnd,wParam);
			return TRUE;
		}
	return FALSE;
}
#pragma	warn .par

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -