Skip to content

Commit

Permalink
提交填充YUV数据的例程。
Browse files Browse the repository at this point in the history
添加VS2010工程文件。
遗留:YUV420竖条还有问题。

Signed-off-by: latelee <[email protected]>
  • Loading branch information
latelee committed Mar 6, 2014
1 parent 2928e66 commit 040de16
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 25 deletions.
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,15 @@ int main(int argc, char* argv[])
//save_bmp420("yuvfile/suzie_qcif_yuv420p_00.yuv", "suzie_qcif_0.bmp", 176, 144);

// OK
//save_bmp422("yuvfile/tulips_yuv422_prog_planar_qcif.yuv", "tulips_yuv422_qcif_0.bmp", 176, 144);
save_bmp422("yuvfile/colorbar_cif_yuv422p.yuv", "colorbar_cif_yuv422p.bmp", 352, 288);

// OK
//save_bmp422sp("yuvfile/yuv422sp_3000x1024.yuv", "test.bmp", 3000, 1024);

// SP转P
//ConvertImage("yuvfile/yuv422sp_3000x1024.yuv", "yuvfile/yuv422p.yuv", 3000, 1024);

save_bmp420("yuvfile/suzie_qcif_yuv420p_00.yuv", "suzie_qcif_1.bmp", 176, 144);
//save_bmp420("yuvfile/suzie_qcif_yuv420p_00.yuv", "suzie_qcif_1.bmp", 176, 144);


return 0;
Expand Down
6 changes: 4 additions & 2 deletions make_yuv/fill_yuvdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void fill_yuv_yuv420_1(unsigned char* buffer, int width, int height)
unsigned char u = (g_test_yuv[index] & 0x00ff00) >> 8;
unsigned char v = (g_test_yuv[index] & 0x0000ff);

for (j=0; j<width*3/2; j+=4)
for (j=0; j<width; j+=4)
{
p_y[0] = y;
p_y[1] = y;
Expand All @@ -181,6 +181,7 @@ void fill_yuv_yuv420_1(unsigned char* buffer, int width, int height)

// yuv420
// 竖条
// 还有问题,继续找
void fill_yuv_yuv420_2(unsigned char* buffer, int width, int height)
{
unsigned char *src = buffer;
Expand All @@ -196,6 +197,7 @@ void fill_yuv_yuv420_2(unsigned char* buffer, int width, int height)
// 计出每种颜色有多少像素
int slice = width / YUV_NUM;

printf("slice: %d\n", slice);
for (i = 0; i < height; i++)
{
// 按竖条填充每一行的像素
Expand All @@ -205,7 +207,7 @@ void fill_yuv_yuv420_2(unsigned char* buffer, int width, int height)
unsigned char y = (g_test_yuv[index] & 0xff0000 ) >> 16;
unsigned char u = (g_test_yuv[index] & 0x00ff00) >> 8;
unsigned char v = (g_test_yuv[index] & 0x0000ff);
for (k = 0; k < slice*2; k += 4) // 一种颜色
for (k = 0; k < slice; k += 4) // 一种颜色
{
p_y[0] = y;
p_y[1] = y;
Expand Down
49 changes: 28 additions & 21 deletions make_yuv/main.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

#include "fill_yuvdata.h"
#include "file_utils.h"

// 8的整数倍,否则颜色可能错位
#define WIDTH 720
#define HEGHT 480

int main(void)
{
printf("test of writing yuv...\n");
unsigned char* buffer = (unsigned char*)malloc(WIDTH*HEGHT*sizeof(char)*3/2);
//fill_yuv_uyvy_1(WIDTH, HEGHT);
//fill_yuv_uyvy_2(WIDTH, HEGHT);
fill_yuv_yuv420_1(buffer, WIDTH, HEGHT);
write_file("yuv.yuv", (char*)buffer, WIDTH*HEGHT*3/2);
return 0;
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

#include "fill_yuvdata.h"
#include "file_utils.h"

// 8的整数倍,否则颜色可能错位
#define WIDTH 720
#define HEGHT 480

// yuv422是w*h*2
// yuv420是w*h*3/2
#define FILE_SIZE (WIDTH*HEGHT*3/2)

int main(void)
{
printf("test of writing yuv...\n");
unsigned char* buffer = (unsigned char*)malloc(FILE_SIZE);
// ok
//fill_yuv_uyvy_2(buffer, WIDTH, HEGHT);
// ok
//fill_yuv_yuv422_2(buffer, WIDTH, HEGHT);
// _1 ok _2 not ok
fill_yuv_yuv420_2(buffer, WIDTH, HEGHT);
write_file("yuv.yuv", (char*)buffer, FILE_SIZE);
return 0;
}
1 change: 1 addition & 0 deletions yuvfile/colorbar_cif_yuv422p.yuv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions yuvrgb.sln
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yuvrgb", "yuvrgb.vcxproj", "{4CCDBF90-E213-475E-87EA-17F822257EFA}"
Expand Down
103 changes: 103 additions & 0 deletions yuvrgb.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4CCDBF90-E213-475E-87EA-17F822257EFA}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(OutDir)yuvrgb.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)yuvrgb.pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(OutDir)yuvrgb.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="bmp_utils.c" />
<ClCompile Include="main.cpp" />
<ClCompile Include="rgb2yuv.c" />
<ClCompile Include="yuv2rgb.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bmp_utils.h" />
<ClInclude Include="rgb2yuv.h" />
<ClInclude Include="yuv2rgb.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
42 changes: 42 additions & 0 deletions yuvrgb.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="bmp_utils.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="rgb2yuv.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="yuv2rgb.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="bmp_utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rgb2yuv.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="yuv2rgb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions yuvrgb.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

0 comments on commit 040de16

Please sign in to comment.