File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
components/ColorAnalyzer/src/ColorPaletteSampler Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -104,11 +104,13 @@ private async Task<Vector3[]> SampleSourcePixelColorsAsync(int sampleCount)
104104
105105 // Read the stream into a a color array
106106 const int bytesPerPixel = 4 ;
107- var samples = new Vector3 [ ( int ) pixelByteStream . Length / bytesPerPixel ] ;
107+ var samples = new Vector3 [ sampleCount ] ;
108108
109109 // Iterate through the stream reading a pixel (4 bytes) at a time
110110 // and storing them as a Vector3. Opacity info is dropped.
111111 int colorIndex = 0 ;
112+ var step = ( pixelByteStream . Length / sampleCount ) ;
113+ step -= step % 4 ;
112114#if NET7_0_OR_GREATER
113115 Span < byte > pixelBytes = stackalloc byte [ bytesPerPixel ] ;
114116 while ( pixelByteStream . Read ( pixelBytes ) == bytesPerPixel )
@@ -124,6 +126,9 @@ private async Task<Vector3[]> SampleSourcePixelColorsAsync(int sampleCount)
124126 // Take the red, green, and blue channels to make a floating-point space color.
125127 samples [ colorIndex ] = new Vector3 ( pixelBytes [ 2 ] , pixelBytes [ 1 ] , pixelBytes [ 0 ] ) / byte . MaxValue ;
126128 colorIndex ++ ;
129+
130+ // Advance by step amount
131+ pixelByteStream . Position += step ;
127132 }
128133
129134 // If we skipped any pixels, trim the span
You can’t perform that action at this time.
0 commit comments