Skip to content

Commit 8817e06

Browse files
committed
WIP Preparing to add UNO support to ColorPaletteSampler
1 parent 11af2d4 commit 8817e06

10 files changed

Lines changed: 28 additions & 12 deletions

File tree

components/ColorAnalyzer/samples/ColorPaletteSampler/BaseColorSample.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<local:ColorPaletteSamplerToolkitSampleBase.Resources>
1515
<helpers:ColorPaletteSampler x:Name="ColorPaletteSampler">
1616
<helpers:ColorPaletteSampler.Source>
17-
<helpers:UIColorSource Source="{x:Bind SampledImage}" />
17+
<!--<helpers:UIColorSource Source="{x:Bind SampledImage}" />-->
18+
<helpers:UrlColorSource Source="{x:Bind SelectedImageUrl, Mode=OneWay}" />
1819
</helpers:ColorPaletteSampler.Source>
1920
<helpers:BaseColorPaletteSelector x:Name="BaseColorPalette" MinColorCount="3" />
2021
</helpers:ColorPaletteSampler>

components/ColorAnalyzer/samples/ColorPaletteSampler/ColorWeightSample.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<local:ColorPaletteSamplerToolkitSampleBase.Resources>
1515
<helpers:ColorPaletteSampler x:Name="ColorPaletteSampler">
1616
<helpers:ColorPaletteSampler.Source>
17-
<helpers:UIColorSource Source="{x:Bind SampledImage}" />
17+
<!--<helpers:UIColorSource Source="{x:Bind SampledImage}" />-->
18+
<helpers:UrlColorSource Source="{x:Bind SelectedImageUrl, Mode=OneWay}" />
1819
</helpers:ColorPaletteSampler.Source>
1920
<helpers:ColorWeightPaletteSelector x:Name="ColorWeightPalette" MinColorCount="5" />
2021
</helpers:ColorPaletteSampler>

components/ColorAnalyzer/samples/ColorPaletteSampler/MultiplePaletteSelectorSample.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<local:ColorPaletteSamplerToolkitSampleBase.Resources>
1515
<helpers:ColorPaletteSampler x:Name="ColorPaletteSampler">
1616
<helpers:ColorPaletteSampler.Source>
17-
<helpers:UIColorSource Source="{x:Bind SampledImage}" />
17+
<!--<helpers:UIColorSource Source="{x:Bind SampledImage}" />-->
18+
<helpers:UrlColorSource Source="{x:Bind SelectedImageUrl, Mode=OneWay}" />
1819
</helpers:ColorPaletteSampler.Source>
1920
<helpers:AccentColorPaletteSelector x:Name="AccentPalette" MinColorCount="1" />
2021
<helpers:BaseColorPaletteSelector x:Name="BaseColorPalette" MinColorCount="1" />

components/ColorAnalyzer/src/ColorPaletteSampler/ColorSources/ColorSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace CommunityToolkit.WinUI.Helpers;
77
/// <summary>
88
/// A base class for a color data source in the <see cref="ColorPaletteSampler"/>.
99
/// </summary>
10-
public abstract class ColorSource : DependencyObject
10+
public abstract partial class ColorSource : DependencyObject
1111
{
1212
/// <summary>
1313
/// An event invoked when the source pixels changed.

components/ColorAnalyzer/src/ColorPaletteSampler/ColorSources/StreamColorSource.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ public Stream? Source
2929
/// <inheritdoc/>
3030
public override async Task<Stream?> GetPixelDataAsync(int requestedSamples)
3131
{
32-
// TODO: Sample the data
32+
#if !HAS_UNO
3333
var decoder = await BitmapDecoder.CreateAsync(Source.AsRandomAccessStream());
3434
var pixelData = await decoder.GetPixelDataAsync();
3535
var bytes = pixelData.DetachPixelData();
3636
return new MemoryStream(bytes);
37+
#else
38+
// NOTE: This assumes raw pixel data.
39+
// TODO: Uses some form of image processing
40+
return Source;
41+
#endif
3742
}
3843

3944
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

components/ColorAnalyzer/src/ColorPaletteSampler/ColorSources/UIColorSource.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#if !HAS_UNO
56

67
using System.Numerics;
78

@@ -63,3 +64,5 @@ private static void OnSourceChanged(DependencyObject d, DependencyPropertyChange
6364
source.InvokeSourceUpdated();
6465
}
6566
}
67+
68+
#endif

components/ColorAnalyzer/src/ColorPaletteSampler/ColorSources/UrlColorSource.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ public string? Source
3434
if (Source is null)
3535
return null;
3636

37-
// TODO: Sample the data
3837
var stream = await RandomAccessStreamReference.CreateFromUri(new Uri(Source)).OpenReadAsync();
38+
#if !HAS_UNO
3939
var decoder = await BitmapDecoder.CreateAsync(stream);
4040
var pixelData = await decoder.GetPixelDataAsync();
4141
var bytes = pixelData.DetachPixelData();
4242
return new MemoryStream(bytes);
43+
#else
44+
// NOTE: This assumes raw pixel data.
45+
// TODO: Uses some form of image processing
46+
return stream.AsStream();
47+
#endif
4348
}
4449

4550
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

components/ColorAnalyzer/src/ColorPaletteSampler/PaletteSelectors/ColorPaletteSelector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace CommunityToolkit.WinUI.Helpers;
99
/// <summary>
1010
/// A base class for selecting colors from a palette extracted by the <see cref="ColorPaletteSampler"/>.
1111
/// </summary>
12-
public abstract class ColorPaletteSelector : DependencyObject
12+
public abstract partial class ColorPaletteSelector : DependencyObject
1313
{
1414
private IEnumerable<PaletteColor>? _palette;
1515

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project>
2-
<PropertyGroup>
3-
<!--
2+
<PropertyGroup>
3+
<!--
44
MultiTarget is a custom property that indicates which target a project is designed to be built for / run on.
55
Used to create project references, generate solution files, enable/disable TargetFrameworks, and build nuget packages.
66
-->
77
<!-- Uno is not currently supported because this component depends on the RenderTargetBitmap.-->
8-
<MultiTarget>uwp;wasdk;</MultiTarget>
9-
</PropertyGroup>
8+
<MultiTarget>uwp;wasdk;</MultiTarget>
9+
</PropertyGroup>
1010
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.101",
3+
"version": "10.0.101",
44
"rollForward": "latestFeature"
55
},
66
"msbuild-sdks":

0 commit comments

Comments
 (0)