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

📄 pctestbed.cpp

📁 JPEG解压软件,包含PC端的测试程序,程序结构比较清晰
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PCTestBed.cpp : Defines the entry point for the application.
//

#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>


#include "stdafx.h"
#include "resource.h"

#include <commdlg.h>
#include "AMComDef.h"
#include "AmMemStream.h"
#include "jpegDecoder.h"
#include "idct.h"
#include "Draw.h"
#include <shellapi.h>

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;	
HWND      ghWnd;							// current instance
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text
TCHAR szOpenFile[MAX_PATH];
TCHAR szOpennNextFile[MAX_PATH];
TCHAR szFolder[MAX_PATH];

USER_DATA* pUserData;
// for drag
int		nXOffset = 0;
int		nYOffset = 0;
int		nPreXpos = 0;
int		nPreYpos = 0;
BOOL	bMouseDown = FALSE;

int     gnResampleWidth = 1200;
int     gnResampleHeight = 900;

int     RealWidth = 0 ;
int     RealHeight = 0 ;
int     JpegError = 0 ;
int		RValue;
int		GValue;
int		BValue;

int		nTotalTime = -1;
int		nInterval = 0;
BOOL	bPaused = FALSE;	
HANDLE	hFind = NULL;
WIN32_FIND_DATA fd;

// Foward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK AllFileDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK	ResampleDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
void				OnFileOpen(HWND hWnd);
void				OnPaint(HWND hWnd);
void				OnSpace();
BOOL				OnEscape();
void				OnReDraw(HWND hWnd, int nXpos, int nYpos); 
BOOL				GetAllFileInFolder(LPCSTR strFolder);

//#define TEST_MODULES
//#define TEST_SPEED 

void WTF( DWORD db) 
{
	FILE * pF= fopen( "f:\\miniJPEG.txt" , "a+" ) ; 
	fprintf( pF , "Time=%d\r\n\r\n" , db ) ; 
	fclose( pF ) ; 
}

#ifdef TEST_MODULES

LPCSTR FunctionName[16] = {"Decolor",NULL};

void WTF2 (int TimeList[], int nCount)
{
	FILE *pF = fopen( "f:\\miniJPEG.txt" , "a+" ) ; 	
	SYSTEMTIME systemTime;
	memset(&systemTime, 0, sizeof(SYSTEMTIME));
	::GetLocalTime(&systemTime);
	TCHAR pstrTime[MAX_PATH];
	sprintf(pstrTime, "%d-%d-%d, %d:%d", systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute);

	for (int i=0; i<nCount; i++) {
		fprintf( pF , "Function %s 's Time = %d , Test Time is: %s\r\n\r\n", FunctionName[i], TimeList[i], pstrTime) ;
	}
	fclose( pF ) ; 
}

#endif

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
#ifdef TEST_MODULES
	CDraw Draw ; 
	USER_DATA Data ; 

	gnResampleWidth = 0;
	gnResampleHeight = 0;
	Draw.DrawJPEG( "d:\\DSCF0003.JPG", &Data, &nTotalTime ) ; 

	RValue	= Data.RValue / Data.PixelsNum;
	GValue	= Data.GValue / Data.PixelsNum;
	BValue	= Data.BValue / Data.PixelsNum;

//	WTF2(CT_List,1); 

	if( Data.hDib)
		GlobalFree( (HANDLE)Data.hDib) ;
	return 0L ; 
#else
	#ifdef TEST_SPEED
		gnResampleWidth = 360;
		gnResampleHeight = 240;

		CDraw Draw ; 
		USER_DATA Data ; 
		memset( &Data , 0 , sizeof( USER_DATA )) ; 
//		DWORD da= ::GetTickCount() ; 
		Draw.DrawJPEG( "F:\\10.JPG", &Data, &nTotalTime ) ; 
		DWORD db= nTotalTime;//::GetTickCount()-da ; 

 		WTF( db) ; 

		if( Data.hDib) {
			LPBITMAPINFOHEADER pBi = (LPBITMAPINFOHEADER)::GlobalLock((HANDLE)Data.hDib);

			FILE * pF= fopen( "f:\\miniJPEG.txt" , "a+" ) ; 
			fprintf( pF , "New Width=%d,  New Height=%d\r\n\r\n", pBi->biWidth, pBi->biHeight); 
			fclose( pF ) ;

			::GlobalUnlock((HANDLE)Data.hDib);
			GlobalFree( (HANDLE)Data.hDib) ;
		}

		return 0L ; 
	#endif
#endif
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	memset(szOpenFile,0,sizeof(szOpenFile));

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_PCTESTBED, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_PCTESTBED);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (msg.hwnd!=NULL) {
			if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
	}

	return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_PCTESTBED);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= (LPCSTR)IDC_PCTESTBED;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ::DragAcceptFiles(hWnd,TRUE);

   ShowWindow(hWnd, nCmdShow|SW_MAXIMIZE);
   UpdateWindow(hWnd);

   ghWnd = hWnd;

//  ::SetCursor(::LoadCursor(NULL, IDC_HAND)); 
   
    pUserData = (USER_DATA*)malloc(sizeof(USER_DATA));
    pUserData->hDib = NULL;	

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;	
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);	

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				case IDM_SPA:
					OnSpace();
					break;
				case IDM_OPEN:	
					{
						OPENFILENAME openFileName;
						memset(&openFileName,0,sizeof(openFileName));
						openFileName.lStructSize = sizeof(OPENFILENAME);
						openFileName.hwndOwner = hWnd;
						LPCTSTR szFileFilter = _T("JPEG Files(*.jpg,*.jpeg)\0*.jpg;*.jpeg\0\0");
						openFileName.lpstrFilter = szFileFilter;
						openFileName.lpstrFile = szOpenFile;
						openFileName.nMaxFile = MAX_PATH;
						openFileName.Flags = OFN_PATHMUSTEXIST |  OFN_OVERWRITEPROMPT;

						::GetOpenFileName(&openFileName);
						OnFileOpen(hWnd);		
					}
					break;
				case ID_FILE_OPEN:
					{
						OPENFILENAME openFileName;
						memset(&openFileName,0,sizeof(openFileName));
						openFileName.lStructSize = sizeof(OPENFILENAME);
						openFileName.hwndOwner = hWnd;
						LPCTSTR szFileFilter = _T("JPEG Files(*.jpg,*.jpeg)\0*.jpg;*.jpeg\0\0");
						openFileName.lpstrFilter = szFileFilter;
						openFileName.lpstrFile = szOpenFile;
						openFileName.nMaxFile = MAX_PATH;
						openFileName.Flags = OFN_PATHMUSTEXIST |  OFN_OVERWRITEPROMPT;

						::GetOpenFileName(&openFileName);
						OnFileOpen(hWnd);					
					}
					break;
				case IDM_SELECT_RESAMPLE:

⌨️ 快捷键说明

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