Skip to content

Commit 11348bb

Browse files
committed
add bmp_parse
1 parent 8b78384 commit 11348bb

File tree

8 files changed

+393
-0
lines changed

8 files changed

+393
-0
lines changed

BMP_Parse/BMPFile.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include "BMPFile.h"
2+
3+
CBMPFile::CBMPFile()
4+
{
5+
m_pData = NULL;
6+
}
7+
8+
CBMPFile::~CBMPFile()
9+
{
10+
if (m_pData)
11+
{
12+
delete []m_pData;
13+
m_pData = NULL;
14+
}
15+
}
16+
17+
bool CBMPFile::LoadFile(const char* strFile)
18+
{
19+
if (!strFile)
20+
{
21+
printf("strFile is null. \n");
22+
return false;
23+
}
24+
FILE* pFile = fopen(strFile, "rb");
25+
if (!pFile)
26+
{
27+
printf("fopen is failed. \n");
28+
return false;
29+
}
30+
fseek(pFile, 0, SEEK_END);
31+
m_iSize = ftell(pFile);
32+
byte_ptr pData = new byte[m_iSize];
33+
fseek(pFile, 0, SEEK_SET);
34+
if (m_iSize != fread(pData, sizeof(byte), m_iSize, pFile))
35+
{
36+
printf("read file is failed. \n");
37+
return false;
38+
}
39+
fclose(pFile);
40+
41+
bool bResult = ReadData(pData, m_iSize);
42+
delete[]pData;
43+
pData = NULL;
44+
return bResult;
45+
}
46+
47+
bool CBMPFile::SaveFile(const char* strFile, RECT rt)
48+
{
49+
return true;
50+
}
51+
52+
void CBMPFile::Display()
53+
{
54+
printf("************************ BITMAP FILE HEADER ************************\n");
55+
printf("\t bfType \t : %d \n", m_bmpFileHeader.bfType);
56+
printf("\t bfSize \t : %d \n", m_bmpFileHeader.bfSize);
57+
printf("\t bfReserved1 \t : %d \n", m_bmpFileHeader.bfReserved1);
58+
printf("\t bfReserved2 \t : %d \n", m_bmpFileHeader.bfReserved2);
59+
printf("\t bfOffBits \t : %d \n", m_bmpFileHeader.bfOffBits);
60+
61+
printf("************************ BITMAP INFO HEADER ************************\n");
62+
printf("\t biSize \t : %d \n", m_bmpInfoHeader.biSize);
63+
printf("\t biWidth \t : %d \n", m_bmpInfoHeader.biWidth);
64+
printf("\t biHeight \t : %d \n", m_bmpInfoHeader.biHeight);
65+
printf("\t biPlanes \t : %d \n", m_bmpInfoHeader.biPlanes);
66+
printf("\t biBitCount \t : %d \n", m_bmpInfoHeader.biBitCount);
67+
printf("\t biCompression \t : %d \n", m_bmpInfoHeader.biCompression);
68+
printf("\t biSizeImage \t : %d \n", m_bmpInfoHeader.biSizeImage);
69+
printf("\t biXPelsPerMeter \t : %d \n", m_bmpInfoHeader.biXPelsPerMeter);
70+
printf("\t biYPelsPerMeter \t : %d \n", m_bmpInfoHeader.biYPelsPerMeter);
71+
printf("\t biClrUsed \t : %d \n", m_bmpInfoHeader.biClrUsed);
72+
printf("\t biClrImportant \t : %d \n", m_bmpInfoHeader.biClrImportant);
73+
74+
printf("************************ BITMAP DATA ************************\n");
75+
int iSize = min(100, m_bmpInfoHeader.biSizeImage);
76+
for (int i = 0; i < iSize; i++)
77+
{
78+
printf(" %02X ", m_pData[i]);
79+
}
80+
printf(" ...");
81+
}
82+
83+
bool CBMPFile::ReadData(byte_ptr pData, int iSize)
84+
{
85+
int iFileHeaderSize = sizeof(m_bmpFileHeader);
86+
memcpy(&m_bmpFileHeader, pData, iFileHeaderSize);
87+
pData += iFileHeaderSize;
88+
int iInfoHeaderSize = sizeof(m_bmpInfoHeader);
89+
memcpy(&m_bmpInfoHeader, pData, iInfoHeaderSize);
90+
pData += iInfoHeaderSize;
91+
92+
switch (m_bmpInfoHeader.biBitCount)
93+
{
94+
case 24:
95+
{
96+
// ÎÞµ÷É«°å;
97+
int iImageSize = m_bmpInfoHeader.biSizeImage;
98+
if (m_pData)
99+
{
100+
delete []m_pData;
101+
}
102+
m_pData = new byte[iImageSize];
103+
memcpy(m_pData, pData, iImageSize);
104+
}
105+
break;
106+
case 32:
107+
{
108+
}
109+
break;
110+
default:
111+
break;
112+
}
113+
114+
return true;
115+
}
116+
117+
bool CBMPFile::WriteData(byte_ptr pData, int &iSize, double dStart, double dEnd)
118+
{
119+
return true;
120+
}

BMP_Parse/BMPFile.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
#include "bytes.h"
3+
#include <windows.h>
4+
5+
class CBMPFile
6+
{
7+
public:
8+
CBMPFile();
9+
~CBMPFile();
10+
11+
public:
12+
// 加载文件,读取数据;
13+
bool LoadFile(const char* strFile);
14+
15+
bool SaveFile(const char* strFile, RECT rt = {0});
16+
17+
// 显示;
18+
void Display();
19+
20+
protected:
21+
// 解析数据;
22+
bool ReadData(byte_ptr pData, int iSize);
23+
// 打包数据;
24+
bool WriteData(byte_ptr pData, int &iSize, double dStart, double dEnd);
25+
26+
public:
27+
BITMAPFILEHEADER m_bmpFileHeader;
28+
BITMAPINFOHEADER m_bmpInfoHeader;
29+
byte* m_pData;
30+
int m_iSize;
31+
};
32+

BMP_Parse/BMP_Parse.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.21005.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BMP_Parse", "BMP_Parse.vcxproj", "{40DF3618-E7AE-4272-A075-B2CB810EFFCC}"
7+
EndProject
8+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FLV_Parse", "..\FLV_Parse\FLV_Parse.vcxproj", "{11C3C385-D48D-4EE8-B59A-1F0D272838F7}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Win32 = Debug|Win32
13+
Release|Win32 = Release|Win32
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Debug|Win32.ActiveCfg = Debug|Win32
17+
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Debug|Win32.Build.0 = Debug|Win32
18+
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Release|Win32.ActiveCfg = Release|Win32
19+
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Release|Win32.Build.0 = Release|Win32
20+
{11C3C385-D48D-4EE8-B59A-1F0D272838F7}.Debug|Win32.ActiveCfg = Debug|Win32
21+
{11C3C385-D48D-4EE8-B59A-1F0D272838F7}.Debug|Win32.Build.0 = Debug|Win32
22+
{11C3C385-D48D-4EE8-B59A-1F0D272838F7}.Release|Win32.ActiveCfg = Release|Win32
23+
{11C3C385-D48D-4EE8-B59A-1F0D272838F7}.Release|Win32.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

BMP_Parse/BMP_Parse.vcxproj

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>{40DF3618-E7AE-4272-A075-B2CB810EFFCC}</ProjectGuid>
15+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
16+
<Keyword>ManagedCProj</Keyword>
17+
<RootNamespace>BMP_Parse</RootNamespace>
18+
</PropertyGroup>
19+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
21+
<ConfigurationType>Application</ConfigurationType>
22+
<UseDebugLibraries>true</UseDebugLibraries>
23+
<PlatformToolset>v120</PlatformToolset>
24+
<CLRSupport>true</CLRSupport>
25+
<CharacterSet>Unicode</CharacterSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>false</UseDebugLibraries>
30+
<PlatformToolset>v120</PlatformToolset>
31+
<CLRSupport>true</CLRSupport>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
35+
<ImportGroup Label="ExtensionSettings">
36+
</ImportGroup>
37+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
38+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
39+
</ImportGroup>
40+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
41+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
42+
</ImportGroup>
43+
<PropertyGroup Label="UserMacros" />
44+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
45+
<LinkIncremental>true</LinkIncremental>
46+
<OutDir>../bin_d</OutDir>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
49+
<LinkIncremental>false</LinkIncremental>
50+
</PropertyGroup>
51+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
52+
<ClCompile>
53+
<WarningLevel>Level3</WarningLevel>
54+
<Optimization>Disabled</Optimization>
55+
<PreprocessorDefinitions>WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
56+
</ClCompile>
57+
<Link>
58+
<GenerateDebugInformation>true</GenerateDebugInformation>
59+
<AdditionalDependencies />
60+
</Link>
61+
</ItemDefinitionGroup>
62+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<ClCompile>
64+
<WarningLevel>Level3</WarningLevel>
65+
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
66+
</ClCompile>
67+
<Link>
68+
<GenerateDebugInformation>true</GenerateDebugInformation>
69+
<AdditionalDependencies />
70+
</Link>
71+
</ItemDefinitionGroup>
72+
<ItemGroup>
73+
<ClInclude Include="BMPFile.h" />
74+
<ClInclude Include="bytes.h" />
75+
</ItemGroup>
76+
<ItemGroup>
77+
<ClCompile Include="BMPFile.cpp" />
78+
<ClCompile Include="main.cpp" />
79+
</ItemGroup>
80+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
81+
<ImportGroup Label="ExtensionTargets">
82+
</ImportGroup>
83+
</Project>

BMP_Parse/BMP_Parse.vcxproj.filters

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="源文件">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="头文件">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="资源文件">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="BMPFile.h">
19+
<Filter>头文件</Filter>
20+
</ClInclude>
21+
<ClInclude Include="bytes.h">
22+
<Filter>头文件</Filter>
23+
</ClInclude>
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClCompile Include="BMPFile.cpp">
27+
<Filter>源文件</Filter>
28+
</ClCompile>
29+
<ClCompile Include="main.cpp">
30+
<Filter>源文件</Filter>
31+
</ClCompile>
32+
</ItemGroup>
33+
</Project>

BMP_Parse/BMP_Parse.vcxproj.user

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
4+
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
5+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
6+
</PropertyGroup>
7+
</Project>

BMP_Parse/bytes.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#ifndef __BYTES_H__
2+
#define __BYTES_H__
3+
#include <wchar.h>
4+
#include <stdio.h>
5+
#include <assert.h>
6+
7+
#ifdef _WIN32
8+
/* Windows is little endian only */
9+
#define __LITTLE_ENDIAN 1234
10+
#define __BIG_ENDIAN 4321
11+
#define __BYTE_ORDER __LITTLE_ENDIAN
12+
#define __FLOAT_WORD_ORDER __BYTE_ORDER
13+
14+
typedef unsigned char byte;
15+
typedef unsigned char uint8_t;
16+
typedef unsigned short uint16_t;
17+
typedef unsigned int uint32_t;
18+
typedef unsigned long long uint64_t;
19+
20+
typedef byte* byte_ptr;
21+
22+
#else /* !_WIN32 */
23+
24+
#include <sys/param.h>
25+
26+
#if defined(BYTE_ORDER) && !defined(__BYTE_ORDER)
27+
#define __BYTE_ORDER BYTE_ORDER
28+
#endif
29+
30+
#if defined(BIG_ENDIAN) && !defined(__BIG_ENDIAN)
31+
#define __BIG_ENDIAN BIG_ENDIAN
32+
#endif
33+
34+
#if defined(LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN)
35+
#define __LITTLE_ENDIAN LITTLE_ENDIAN
36+
#endif
37+
38+
#endif /* !_WIN32 */
39+
#include <string>
40+
41+
/* define default endianness */
42+
#ifndef __LITTLE_ENDIAN
43+
#define __LITTLE_ENDIAN 1234
44+
#endif
45+
46+
#ifndef __BIG_ENDIAN
47+
#define __BIG_ENDIAN 4321
48+
#endif
49+
50+
#ifndef __BYTE_ORDER
51+
#warning "Byte order not defined on your system, assuming little endian!"
52+
#define __BYTE_ORDER __LITTLE_ENDIAN
53+
#endif
54+
55+
/* ok, we assume to have the same float word order and byte order if float word order is not defined */
56+
#ifndef __FLOAT_WORD_ORDER
57+
#warning "Float word order not defined, assuming the same as byte order!"
58+
#define __FLOAT_WORD_ORDER __BYTE_ORDER
59+
#endif
60+
61+
#if !defined(__BYTE_ORDER) || !defined(__FLOAT_WORD_ORDER)
62+
#error "Undefined byte or float word order!"
63+
#endif
64+
65+
#if __FLOAT_WORD_ORDER != __BIG_ENDIAN && __FLOAT_WORD_ORDER != __LITTLE_ENDIAN
66+
#error "Unknown/unsupported float word order!"
67+
#endif
68+
69+
#if __BYTE_ORDER != __BIG_ENDIAN && __BYTE_ORDER != __LITTLE_ENDIAN
70+
#error "Unknown/unsupported byte order!"
71+
#endif
72+
73+
// 将pData后的iCount字节转换为数字
74+
int BytesToInt(byte_ptr pData, int iCount);
75+
// 将pData后的iCount字节转换为字符串;
76+
std::string BytesToStr(byte_ptr pData, int iCount);
77+
78+
#endif

0 commit comments

Comments
 (0)