Skip to content

Commit 9ad7850

Browse files
committed
+ VC++图像处理程序设计
1 parent d72c929 commit 9ad7850

File tree

589 files changed

+62409
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

589 files changed

+62409
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#include "stdafx.h"
2+
#include "cdib.h"
3+
#include "windowsx.h"
4+
#include "math.h"
5+
#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
6+
7+
CDib::CDib()
8+
{
9+
size=0;
10+
}
11+
12+
CDib::~CDib()
13+
{
14+
GlobalFreePtr(m_pBitmapInfo);
15+
}
16+
17+
void CDib::LoadFile(const char* dibFileName)
18+
{
19+
strcpy(m_fileName,dibFileName);
20+
CFile dibFile(m_fileName, CFile::modeRead);
21+
dibFile.Read((void*)&bitmapFileHeader,sizeof(BITMAPFILEHEADER));
22+
if (bitmapFileHeader.bfType == 0x4d42)
23+
{
24+
DWORD fileLength = dibFile.GetLength();
25+
size = fileLength -sizeof(BITMAPFILEHEADER);
26+
pDib =(BYTE*)GlobalAllocPtr(GMEM_MOVEABLE, size);
27+
dibFile.Read((void*)pDib, size);
28+
dibFile.Close();
29+
m_pBitmapInfo = (BITMAPINFO*) pDib;
30+
m_pBitmapInfoHeader = (BITMAPINFOHEADER*) pDib;
31+
m_pRGB = (RGBQUAD*)(pDib +
32+
m_pBitmapInfoHeader->biSize);
33+
int m_numberOfColors = GetNumberOfColors();
34+
if (m_pBitmapInfoHeader->biClrUsed == 0)
35+
m_pBitmapInfoHeader->biClrUsed =
36+
m_numberOfColors;
37+
DWORD colorTableSize = m_numberOfColors *
38+
sizeof(RGBQUAD);
39+
m_pData = pDib + m_pBitmapInfoHeader->biSize
40+
+ colorTableSize;
41+
m_pBitmapInfoHeader->biSizeImage = GetSize();
42+
43+
if (m_pRGB == (RGBQUAD*)m_pData) // No color table
44+
m_pRGB = NULL;
45+
46+
m_valid = TRUE;
47+
}
48+
else
49+
{
50+
m_valid = FALSE;
51+
AfxMessageBox("This isn't a bitmap file!");
52+
}
53+
}
54+
55+
BOOL CDib::IsValid()
56+
{
57+
return m_valid;
58+
}
59+
60+
char* CDib::GetFileName()
61+
{
62+
return m_fileName;
63+
}
64+
65+
UINT CDib::GetWidth()
66+
{
67+
return (UINT) m_pBitmapInfoHeader->biWidth;
68+
}
69+
70+
UINT CDib::GetHeight()
71+
{
72+
return (UINT) m_pBitmapInfoHeader->biHeight;
73+
}
74+
75+
DWORD CDib::GetSize()
76+
{
77+
if (m_pBitmapInfoHeader->biSizeImage != 0)
78+
return m_pBitmapInfoHeader->biSizeImage;
79+
else
80+
{
81+
DWORD height = (DWORD) GetHeight();
82+
DWORD width = (DWORD) GetWidth();
83+
return height * width;
84+
}
85+
}
86+
87+
UINT CDib::GetNumberOfColors()
88+
{
89+
int numberOfColors;
90+
91+
if ((m_pBitmapInfoHeader->biClrUsed == 0) &&
92+
(m_pBitmapInfoHeader->biBitCount < 9))
93+
{
94+
switch (m_pBitmapInfoHeader->biBitCount)
95+
{
96+
case 1: numberOfColors = 2; break;
97+
case 4: numberOfColors = 16; break;
98+
case 8: numberOfColors = 256;
99+
}
100+
}
101+
else
102+
numberOfColors = (int) m_pBitmapInfoHeader->biClrUsed;
103+
104+
return numberOfColors;
105+
}
106+
107+
BYTE* CDib::GetData()
108+
{
109+
return m_pData;
110+
}
111+
112+
RGBQUAD* CDib::GetRGB()
113+
{
114+
return m_pRGB;
115+
}
116+
117+
BITMAPINFO* CDib::GetInfo()
118+
{
119+
return m_pBitmapInfo;
120+
}
121+
122+
WORD CDib::PaletteSize(LPBYTE lpDIB)
123+
{
124+
return (DIBNumColors(lpDIB) * sizeof(RGBTRIPLE));
125+
}
126+
127+
WORD CDib::DIBNumColors(LPBYTE lpDIB)
128+
{
129+
WORD wBitCount; // DIB bit count
130+
wBitCount = ((LPBITMAPCOREHEADER)lpDIB)->bcBitCount;
131+
switch (wBitCount)
132+
{
133+
case 1:
134+
return 2;
135+
case 4:
136+
return 16;
137+
case 8:
138+
return 256;
139+
default:
140+
return 0;
141+
}
142+
}
143+
144+
void CDib::SaveFile(const CString filename)
145+
{
146+
strcpy(m_fileName,filename);
147+
CFile dibFile(m_fileName, CFile::modeCreate|CFile::modeWrite);
148+
dibFile.Write((void*)&bitmapFileHeader,sizeof(BITMAPFILEHEADER));
149+
dibFile.Write((void*)pDib, size);
150+
dibFile.Close();
151+
152+
}
153+
154+
DWORD CDib::GetDibWidthBytes()
155+
{
156+
byBitCount=m_pBitmapInfoHeader->biBitCount;
157+
LONG nWidth=m_pBitmapInfoHeader->biWidth;
158+
159+
dwWidthBytes = (DWORD)m_pBitmapInfoHeader->biWidth; //8-bits
160+
if(byBitCount == 1) dwWidthBytes = (nWidth + 7) / 8;
161+
else if(byBitCount == 4) dwWidthBytes = (nWidth + 1) / 2;
162+
else if(byBitCount == 24) dwWidthBytes = 3 * nWidth ;
163+
164+
while((dwWidthBytes & 3) != 0)dwWidthBytes++;
165+
166+
return dwWidthBytes;
167+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef __CDIB_H
2+
#define __CDIB_H
3+
4+
class CDib : public CObject
5+
{
6+
public:
7+
RGBQUAD* m_pRGB;
8+
BYTE *m_pData;
9+
UINT m_numberOfColors;
10+
BOOL m_valid;
11+
BITMAPFILEHEADER bitmapFileHeader;
12+
13+
BITMAPINFOHEADER* m_pBitmapInfoHeader;
14+
BITMAPINFO* m_pBitmapInfo;
15+
BYTE* pDib;
16+
DWORD size;
17+
int byBitCount;
18+
DWORD dwWidthBytes;
19+
public:
20+
CDib();
21+
~CDib();
22+
23+
char m_fileName[256];
24+
char* GetFileName();
25+
BOOL IsValid();
26+
DWORD GetSize();
27+
UINT GetWidth();
28+
UINT GetHeight();
29+
UINT GetNumberOfColors();
30+
RGBQUAD* GetRGB();
31+
BYTE* GetData();
32+
33+
BITMAPINFO* GetInfo();
34+
35+
WORD PaletteSize(LPBYTE lpDIB);
36+
WORD DIBNumColors(LPBYTE lpDIB);
37+
void SaveFile(const CString filename);
38+
39+
public:
40+
DWORD GetDibWidthBytes();
41+
void LoadFile(const char* dibFileName);
42+
43+
};
44+
45+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// DELSMALL.cpp : implementation file
2+
//
3+
4+
#include "stdafx.h"
5+
#include "DSplit.h"
6+
#include "DELSMALL.h"
7+
8+
#ifdef _DEBUG
9+
#define new DEBUG_NEW
10+
#undef THIS_FILE
11+
static char THIS_FILE[] = __FILE__;
12+
#endif
13+
14+
/////////////////////////////////////////////////////////////////////////////
15+
// DELSMALL dialog
16+
17+
18+
DELSMALL::DELSMALL(CWnd* pParent /*=NULL*/)
19+
: CDialog(DELSMALL::IDD, pParent)
20+
{
21+
//{{AFX_DATA_INIT(DELSMALL)
22+
m_delsmall = 0;
23+
//}}AFX_DATA_INIT
24+
}
25+
26+
27+
void DELSMALL::DoDataExchange(CDataExchange* pDX)
28+
{
29+
CDialog::DoDataExchange(pDX);
30+
//{{AFX_DATA_MAP(DELSMALL)
31+
DDX_Text(pDX, IDC_EDITDEL, m_delsmall);
32+
//}}AFX_DATA_MAP
33+
}
34+
35+
36+
BEGIN_MESSAGE_MAP(DELSMALL, CDialog)
37+
//{{AFX_MSG_MAP(DELSMALL)
38+
// NOTE: the ClassWizard will add message map macros here
39+
//}}AFX_MSG_MAP
40+
END_MESSAGE_MAP()
41+
42+
/////////////////////////////////////////////////////////////////////////////
43+
// DELSMALL message handlers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#if !defined(AFX_DELSMALL_H__D42AF56A_17EC_4054_A131_CD4A30604464__INCLUDED_)
2+
#define AFX_DELSMALL_H__D42AF56A_17EC_4054_A131_CD4A30604464__INCLUDED_
3+
4+
#if _MSC_VER > 1000
5+
#pragma once
6+
#endif // _MSC_VER > 1000
7+
// DELSMALL.h : header file
8+
//
9+
10+
/////////////////////////////////////////////////////////////////////////////
11+
// DELSMALL dialog
12+
13+
class DELSMALL : public CDialog
14+
{
15+
// Construction
16+
public:
17+
DELSMALL(CWnd* pParent = NULL); // standard constructor
18+
19+
// Dialog Data
20+
//{{AFX_DATA(DELSMALL)
21+
enum { IDD = IDD_DELSMALL_DLG };
22+
int m_delsmall;
23+
//}}AFX_DATA
24+
25+
26+
// Overrides
27+
// ClassWizard generated virtual function overrides
28+
//{{AFX_VIRTUAL(DELSMALL)
29+
protected:
30+
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
31+
//}}AFX_VIRTUAL
32+
33+
// Implementation
34+
protected:
35+
36+
// Generated message map functions
37+
//{{AFX_MSG(DELSMALL)
38+
// NOTE: the ClassWizard will add member functions here
39+
//}}AFX_MSG
40+
DECLARE_MESSAGE_MAP()
41+
};
42+
43+
//{{AFX_INSERT_LOCATION}}
44+
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
45+
46+
#endif // !defined(AFX_DELSMALL_H__D42AF56A_17EC_4054_A131_CD4A30604464__INCLUDED_)

0 commit comments

Comments
 (0)