-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update README.md
- Loading branch information
Showing
7 changed files
with
419 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.23107.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Multithreading", "Multithreading\Multithreading.vcxproj", "{1F13832B-3582-43A3-8A9C-47F09665CFA6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1F13832B-3582-43A3-8A9C-47F09665CFA6}.Debug|x64.ActiveCfg = Debug|x64 | ||
{1F13832B-3582-43A3-8A9C-47F09665CFA6}.Debug|x64.Build.0 = Debug|x64 | ||
{1F13832B-3582-43A3-8A9C-47F09665CFA6}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{1F13832B-3582-43A3-8A9C-47F09665CFA6}.Debug|x86.Build.0 = Debug|Win32 | ||
{1F13832B-3582-43A3-8A9C-47F09665CFA6}.Release|x64.ActiveCfg = Release|x64 | ||
{1F13832B-3582-43A3-8A9C-47F09665CFA6}.Release|x64.Build.0 = Release|x64 | ||
{1F13832B-3582-43A3-8A9C-47F09665CFA6}.Release|x86.ActiveCfg = Release|Win32 | ||
{1F13832B-3582-43A3-8A9C-47F09665CFA6}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="14.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> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>{1F13832B-3582-43A3-8A9C-47F09665CFA6}</ProjectGuid> | ||
<RootNamespace>Multithreading</RootNamespace> | ||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp" /> | ||
<ClCompile Include="PPM.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="PPM.h" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;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;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="PPM.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="PPM.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#include "PPM.h" | ||
#include <iostream> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <exception> | ||
|
||
PPM::PPM() | ||
{ | ||
initialize(); | ||
} | ||
|
||
//create a PPM object and fill it with data stored in source | ||
PPM::PPM(const std::string & fileName) | ||
{ | ||
initialize(); | ||
read(fileName); | ||
} | ||
|
||
//create an "empty" PPM image with a given width and height | ||
PPM::PPM(const unsigned int width, const unsigned int height) | ||
{ | ||
initialize(); | ||
|
||
_width = width; | ||
_height = height; | ||
_lineNumber = height; | ||
_columnsNumber = width; | ||
_size = width * height; | ||
|
||
_r.resize(_size, 0); | ||
_g.resize(_size, 0); | ||
_b.resize(_size, 0); | ||
} | ||
|
||
//free memory when object is destroyed | ||
PPM::~PPM() | ||
{ | ||
|
||
} | ||
|
||
//read PPM image from filename | ||
void PPM::read(const std::string & fileName) | ||
{ | ||
//initialize stream | ||
std::ifstream input(fileName.c_str(), std::ios::in | std::ios::binary); | ||
|
||
//if file open successfully | ||
if (input.is_open()) { | ||
std::string line; | ||
std::getline(input, line); | ||
|
||
if (line != "P6") { | ||
std::cout << "Error. Unrecognized file format" << std::endl; | ||
} | ||
|
||
std::getline(input, line); | ||
while (line[0] == '#') { | ||
std::getline(input, line); | ||
} | ||
|
||
std::stringstream dimension(line); | ||
|
||
try { | ||
dimension >> _width; | ||
dimension >> _height; | ||
_lineNumber = _height; | ||
_columnsNumber = _width; | ||
} | ||
catch (std::exception & exception) { | ||
std::cout << "Header file format error." << exception.what() << std::endl; | ||
return; | ||
} | ||
|
||
std::getline(input, line); | ||
std::stringstream maximumValue(line); | ||
|
||
try { | ||
maximumValue >> _maximumColumn; | ||
} | ||
catch (std::exception & exception) { | ||
std::cout << "Header file format error." << exception.what() << std::endl; | ||
return; | ||
} | ||
|
||
_size = _width * _height; | ||
|
||
_r.reserve(_size); | ||
_g.reserve(_size); | ||
_b.reserve(_size); | ||
|
||
//Set data for R,G,B | ||
char data; | ||
for (unsigned int i = 0; i < _size; ++i) { | ||
input.read(&data, 1); | ||
_r[i] = (unsigned char)data; | ||
_g[i] = (unsigned char)data; | ||
_b[i] = (unsigned char)data; | ||
} | ||
} | ||
else { | ||
std::cout << "Error. Unable to open " << fileName << std::endl; | ||
} | ||
|
||
//Close the stream | ||
input.close(); | ||
} | ||
|
||
//write PPM image to filename | ||
void PPM::write(const std::string & fileName) | ||
{ | ||
//Initialize the stream | ||
std::ofstream output(fileName.c_str(), std::ios::out | std::ios::binary); | ||
|
||
if (output.is_open) { | ||
|
||
output << "P6\n"; | ||
output << _width; | ||
output << " "; | ||
output << _height << "\n"; | ||
output << _maximumColumn << "\n"; | ||
|
||
char data; | ||
for (unsigned int i = 0; i < _size; ++i) { | ||
data = (char)_r[i]; | ||
output.write(&data, 1); | ||
data = (char)_g[i]; | ||
output.write(&data, 1); | ||
data = (char)_b[i]; | ||
output.write(&data, 1); | ||
} | ||
} | ||
else { | ||
std::cout << "Error. Unable to open " << fileName << std::endl; | ||
} | ||
|
||
//Close the stream | ||
output.close(); | ||
} | ||
|
||
void PPM::initialize() | ||
{ | ||
_width = 0; | ||
_height = 0; | ||
_maximumColumn = 255; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
#ifndef PPM_H | ||
#define PPM_H | ||
|
||
//references from https://github.com/sol-prog/threads/blob/master/image_processing/ppm.cpp | ||
#include <string> | ||
#include <vector> | ||
|
||
class PPM | ||
{ | ||
public: | ||
PPM(); | ||
|
||
//create a PPM object and fill it with data stored in source | ||
PPM(const std::string & fileName); | ||
|
||
//create an "empty" PPM image with a given width and height | ||
PPM(const unsigned int width, const unsigned int height); | ||
|
||
//free memory when object is destroyed | ||
~PPM(); | ||
|
||
//read PPM image from filename | ||
void read(const std::string & fileName); | ||
|
||
//write PPM image to filename | ||
void write(const std::string & fileName); | ||
|
||
private: | ||
bool isAllocated; | ||
void initialize(); | ||
|
||
//information about PPM file(height and width) | ||
unsigned int _lineNumber; | ||
unsigned int _columnsNumber; | ||
|
||
//arrays for storing R,G,B values | ||
std::vector< unsigned char > _r; | ||
std::vector< unsigned char > _g; | ||
std::vector< unsigned char > _b; | ||
|
||
unsigned int _height; | ||
unsigned int _width; | ||
unsigned int _maximumColumn; | ||
|
||
//total number of elements(pixels) | ||
unsigned int _size; | ||
|
||
}; | ||
|
||
#endif |
Oops, something went wrong.