Skip to content

Commit

Permalink
first iteration :)
Browse files Browse the repository at this point in the history
  • Loading branch information
KSemenenko committed Jun 21, 2016
1 parent 745b3a8 commit fab0d5e
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 376 deletions.
4 changes: 1 addition & 3 deletions ColorThief.Android/ColorThief.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\ColorThieft.Shared\SharedAssemblyInfo.cs">
Expand All @@ -51,7 +49,7 @@
<Compile Include="ColorThief.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="..\ColorThieft.Shared\ColorThieft.Shared.projitems" Label="Shared" />
<Import Project="..\ColorThieft.Shared\ColorThieftShared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
27 changes: 16 additions & 11 deletions ColorThief.Android/ColorThief.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Android.Graphics;

namespace ColorThief
{
Expand Down Expand Up @@ -74,15 +75,19 @@ private CMap GetColorMap(Bitmap sourceImage, int colorCount, int quality = Defau

private IEnumerable<int> GetIntFromPixel(Bitmap bmp)
{
for(var x = 0; x < bmp.Width; x++)
for (var x = 0; x < bmp.Width; x++)
{
for(var y = 0; y < bmp.Height; y++)
for (var y = 0; y < bmp.Height; y++)
{
var clr = bmp.GetPixel(x, y);
yield return clr.B;
yield return clr.G;
yield return clr.R;
yield return clr.A;
var clr = BitConverter.GetBytes(bmp.GetPixel(x, y));

if (!BitConverter.IsLittleEndian)
Array.Reverse(clr);

yield return (int)clr[3]; //B;
yield return (int)clr[2]; //G;
yield return (int)clr[1]; //R;
yield return (int)clr[0]; //A;
}
}
}
Expand All @@ -96,7 +101,7 @@ private int[][] GetPixelsFast(Bitmap sourceImage, int quality, bool ignoreWhite)
const int colorDepth = 4;

var expectedDataLength = pixelCount * colorDepth;
if(expectedDataLength != pixels.Length)
if (expectedDataLength != pixels.Length)
{
throw new ArgumentException("(expectedDataLength = "
+ expectedDataLength + ") != (pixels.length = "
Expand All @@ -114,7 +119,7 @@ private int[][] GetPixelsFast(Bitmap sourceImage, int quality, bool ignoreWhite)
var numUsedPixels = 0;
var pixelArray = new int[numRegardedPixels][];

for(var i = 0; i < pixelCount; i += quality)
for (var i = 0; i < pixelCount; i += quality)
{
var offset = i * 4;
var b = pixels[offset];
Expand All @@ -123,9 +128,9 @@ private int[][] GetPixelsFast(Bitmap sourceImage, int quality, bool ignoreWhite)
var a = pixels[offset + 3];

// If pixel is mostly opaque and not white
if(a >= 125 && !(ignoreWhite && r > 250 && g > 250 && b > 250))
if (a >= 125 && !(ignoreWhite && r > 250 && g > 250 && b > 250))
{
pixelArray[numUsedPixels] = new[] {r, g, b};
pixelArray[numUsedPixels] = new[] { r, g, b };
numUsedPixels++;
}
}
Expand Down
8 changes: 3 additions & 5 deletions ColorThief.Desktop.v45/ColorThief.Desktop.v45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@
<DocumentationFile>bin\Release\ColorThief.Desktop.v45.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\ColorThieft.Shared\SharedAssemblyInfo.cs">
Expand All @@ -49,6 +46,7 @@
<Compile Include="ColorThief.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="..\ColorThieft.Shared\ColorThieftShared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
13 changes: 7 additions & 6 deletions ColorThief.Desktop.v45/ColorThief.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace ColorThief
Expand Down Expand Up @@ -74,9 +75,9 @@ private CMap GetColorMap(Bitmap sourceImage, int colorCount, int quality = Defau

private IEnumerable<int> GetIntFromPixel(Bitmap bmp)
{
for(var x = 0; x < bmp.Width; x++)
for (var x = 0; x < bmp.Width; x++)
{
for(var y = 0; y < bmp.Height; y++)
for (var y = 0; y < bmp.Height; y++)
{
var clr = bmp.GetPixel(x, y);
yield return clr.B;
Expand All @@ -96,7 +97,7 @@ private int[][] GetPixelsFast(Bitmap sourceImage, int quality, bool ignoreWhite)
const int colorDepth = 4;

var expectedDataLength = pixelCount * colorDepth;
if(expectedDataLength != pixels.Length)
if (expectedDataLength != pixels.Length)
{
throw new ArgumentException("(expectedDataLength = "
+ expectedDataLength + ") != (pixels.length = "
Expand All @@ -114,7 +115,7 @@ private int[][] GetPixelsFast(Bitmap sourceImage, int quality, bool ignoreWhite)
var numUsedPixels = 0;
var pixelArray = new int[numRegardedPixels][];

for(var i = 0; i < pixelCount; i += quality)
for (var i = 0; i < pixelCount; i += quality)
{
var offset = i * 4;
var b = pixels[offset];
Expand All @@ -123,9 +124,9 @@ private int[][] GetPixelsFast(Bitmap sourceImage, int quality, bool ignoreWhite)
var a = pixels[offset + 3];

// If pixel is mostly opaque and not white
if(a >= 125 && !(ignoreWhite && r > 250 && g > 250 && b > 250))
if (a >= 125 && !(ignoreWhite && r > 250 && g > 250 && b > 250))
{
pixelArray[numUsedPixels] = new[] {r, g, b};
pixelArray[numUsedPixels] = new[] { r, g, b };
numUsedPixels++;
}
}
Expand Down
12 changes: 6 additions & 6 deletions ColorThief.Desktop.v46/ColorThief.Desktop.v46.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@
<DocumentationFile>bin\Release\ColorThief.Desktop.v46.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\ColorThief.Desktop.v45\ColorThief.cs">
<Link>ColorThief.cs</Link>
</Compile>
<Compile Include="..\ColorThieft.Shared\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ColorThief.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="..\ColorThieft.Shared\ColorThieftShared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
139 changes: 0 additions & 139 deletions ColorThief.Desktop.v46/ColorThief.cs

This file was deleted.

2 changes: 1 addition & 1 deletion ColorThief.Portable/ColorThief.Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
<Compile Include="ColorThief.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="..\ColorThieft.Shared\ColorThieft.Shared.projitems" Label="Shared" />
<Import Project="..\ColorThieft.Shared\ColorThieftShared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
</Project>
Loading

0 comments on commit fab0d5e

Please sign in to comment.