Skip to content

Commit 490d40c

Browse files
committed
First update
Coloring framework Scaling Histogram Framework
1 parent 8a93c87 commit 490d40c

35 files changed

+525
-95
lines changed

.vs/mandel/v14/.suo

42 KB
Binary file not shown.

Mandel.vcxproj

+34-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<PropertyGroup Label="Globals">
2222
<ProjectGuid>{E1D8F191-6378-4B79-B39E-BAF47F6CCFEC}</ProjectGuid>
2323
<RootNamespace>Mandel</RootNamespace>
24-
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
24+
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
2525
</PropertyGroup>
2626
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2727
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -68,7 +68,10 @@
6868
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6969
</ImportGroup>
7070
<PropertyGroup Label="UserMacros" />
71-
<PropertyGroup />
71+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
72+
<LinkIncremental>
73+
</LinkIncremental>
74+
</PropertyGroup>
7275
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7376
<ClCompile>
7477
<WarningLevel>Level3</WarningLevel>
@@ -83,7 +86,19 @@
8386
<Optimization>Disabled</Optimization>
8487
<SDLCheck>true</SDLCheck>
8588
<OpenMPSupport>true</OpenMPSupport>
89+
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
90+
<IntrinsicFunctions>true</IntrinsicFunctions>
91+
<WholeProgramOptimization>
92+
</WholeProgramOptimization>
93+
<StringPooling>true</StringPooling>
94+
<FunctionLevelLinking>true</FunctionLevelLinking>
95+
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
96+
<RuntimeTypeInfo>true</RuntimeTypeInfo>
8697
</ClCompile>
98+
<Link>
99+
<LinkTimeCodeGeneration>
100+
</LinkTimeCodeGeneration>
101+
</Link>
87102
</ItemDefinitionGroup>
88103
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
89104
<ClCompile>
@@ -101,27 +116,42 @@
101116
</ItemDefinitionGroup>
102117
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
103118
<ClCompile>
104-
<WarningLevel>Level3</WarningLevel>
105-
<Optimization>MaxSpeed</Optimization>
119+
<WarningLevel>EnableAllWarnings</WarningLevel>
120+
<Optimization>Full</Optimization>
106121
<FunctionLevelLinking>true</FunctionLevelLinking>
107122
<IntrinsicFunctions>true</IntrinsicFunctions>
108123
<SDLCheck>true</SDLCheck>
109124
<OpenMPSupport>true</OpenMPSupport>
125+
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
126+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
127+
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
128+
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
129+
<StringPooling>true</StringPooling>
130+
<MinimalRebuild>true</MinimalRebuild>
131+
<WholeProgramOptimization>
132+
</WholeProgramOptimization>
110133
</ClCompile>
111134
<Link>
112135
<EnableCOMDATFolding>true</EnableCOMDATFolding>
113136
<OptimizeReferences>true</OptimizeReferences>
137+
<LargeAddressAware>
138+
</LargeAddressAware>
139+
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
114140
</Link>
115141
</ItemDefinitionGroup>
116142
<ItemGroup>
143+
<ClCompile Include="color.c" />
117144
<ClCompile Include="getopt.c" />
118145
<ClCompile Include="mandel.c" />
119146
<ClCompile Include="mandel_avx.c" />
120147
<ClCompile Include="mandel_sse2.c" />
148+
<ClCompile Include="palette.c" />
121149
</ItemGroup>
122150
<ItemGroup>
123151
<ClInclude Include="getopt.h" />
152+
<ClInclude Include="color.h" />
124153
<ClInclude Include="mandel.h" />
154+
<ClInclude Include="palette.h" />
125155
</ItemGroup>
126156
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
127157
<ImportGroup Label="ExtensionTargets">

Mandel.vcxproj.user

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

color.c

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <assert.h>
2+
#include "color.h"
3+
#include <math.h>
4+
5+
extern inline void color_pixel(channel* image, size_t scan, size_t y, size_t x, color rgb)
6+
{
7+
for (int i = 0; i < 3; ++i) {
8+
image[y * scan * 3 + x * 3 + i] = rgb[i];
9+
}
10+
}
11+
12+
extern inline void rgb_pixel(channel* image, size_t scan, size_t y, size_t x, channel r, channel g, channel b)
13+
{
14+
image[y * scan * 3 + x * 3 + 0] = r;
15+
image[y * scan * 3 + x * 3 + 1] = g;
16+
image[y * scan * 3 + x * 3 + 2] = b;
17+
}
18+
19+
extern inline color color_from_rgb(color color, channel r, channel g, channel b)
20+
{
21+
color[0] = r;
22+
color[1] = g;
23+
color[2] = b;
24+
return color;
25+
}
26+
27+
extern inline void rgb_from_color(color color, channel* r, channel* g, channel* b)
28+
{
29+
*r = color[0];
30+
*g = color[1];
31+
*b = color[2];
32+
}
33+
34+
extern inline channel linear_map_channel(float val, float min, float max, float density, Scaling_Mode mode)
35+
{
36+
return (channel) linear_map_index(val, min, max, density, 256, mode);
37+
}
38+
39+
//Grossly optimize this based on chosen-use case - lots of redundant computations are being done here
40+
extern inline size_t linear_map_index(float val, float min, float max, float density, size_t colors, Scaling_Mode mode)
41+
{
42+
assert((max > min) && (val <= max) && (val >= min));
43+
//drop these if the values involved are guaranteed to be always +ve
44+
/*min = fabsf(min);
45+
max = fabsf(max);
46+
val = fabsf(val);*/
47+
switch (mode) {
48+
case LINEAR:
49+
return ((size_t)(((val - min) / (max - min)) * density) % colors);
50+
case LOG:
51+
if(val == 0 || max == 0)
52+
{
53+
return 0;
54+
}
55+
if(min == 0 || min == 1)
56+
{
57+
return ((size_t)((logf(val) / logf(max)) * density) % colors);
58+
}
59+
return ((size_t)((logf(val / min) / logf(max / min)) * density) % colors);
60+
case SQRT:
61+
{
62+
float minsqrt = sqrtf(min);
63+
return ((size_t)(((sqrtf(val) - minsqrt) / (sqrtf(max) - minsqrt)) * density) % colors);
64+
}
65+
}
66+
}
67+
68+
extern inline color lerp(color result, color fromcolor, color tocolor, float bias)
69+
{
70+
assert((bias >= 0) && (bias <= 1));
71+
for (int i = 0; i < 3; ++i)
72+
{
73+
result[i] = (channel)(fromcolor[i] * bias + tocolor[i] * (1 - bias));
74+
}
75+
return result;
76+
}

color.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
#include <stddef.h>
3+
4+
5+
typedef unsigned char channel;
6+
typedef channel* color;
7+
8+
typedef enum Scaling_Modes
9+
{
10+
SQRT, LOG, LINEAR
11+
} Scaling_Mode;
12+
13+
inline color lerp(color result, color fromcolor, color tocolor, float bias);
14+
inline color color_from_rgb(color color, channel r, channel g, channel b);
15+
inline void rgb_from_color(color color, channel * r, channel* g, channel* b);
16+
inline channel linear_map_channel(float val, float min, float max, float density, Scaling_Mode mode);
17+
inline size_t linear_map_index(float val, float min, float max, float density, size_t colors, Scaling_Mode mode);
18+
inline void color_pixel(channel* image, size_t scan, size_t y, size_t x, color rgb);
19+
inline void rgb_pixel(channel* image, size_t scan, size_t y, size_t x, channel r, channel g, channel b);

0 commit comments

Comments
 (0)