Skip to content

Commit

Permalink
[M3][Color] Interal changes
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 492161895
  • Loading branch information
Material Design Team authored and leticiarossi committed Dec 1, 2022
1 parent 4bdfb8b commit ef76670
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import androidx.annotation.RestrictTo;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

// TODO(b/254603377): Use copybara to release material color utilities library directly to github.
Expand All @@ -34,7 +34,7 @@ public final class QuantizerMap implements Quantizer {

@Override
public QuantizerResult quantize(int[] pixels, int colorCount) {
final HashMap<Integer, Integer> pixelByCount = new HashMap<>();
final Map<Integer, Integer> pixelByCount = new LinkedHashMap<>();
for (int pixel : pixels) {
final Integer currentPixelCount = pixelByCount.get(pixel);
final int newPixelCount = currentPixelCount == null ? 1 : currentPixelCount + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

import androidx.annotation.RestrictTo;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;

// TODO(b/254603377): Use copybara to release material color utilities library directly to github.
/**
Expand Down Expand Up @@ -75,7 +76,10 @@ public int compareTo(Distance other) {
*/
public static Map<Integer, Integer> quantize(
int[] inputPixels, int[] startingClusters, int maxColors) {
Map<Integer, Integer> pixelToCount = new HashMap<>();
// Uses a seeded random number generator to ensure consistent results.
Random random = new Random(0x42688);

Map<Integer, Integer> pixelToCount = new LinkedHashMap<>();
double[][] points = new double[inputPixels.length][];
int[] pixels = new int[inputPixels.length];
PointProvider pointProvider = new PointProviderLab();
Expand Down Expand Up @@ -121,7 +125,7 @@ public static Map<Integer, Integer> quantize(

int[] clusterIndices = new int[pointCount];
for (int i = 0; i < pointCount; i++) {
clusterIndices[i] = (int) Math.floor(Math.random() * clusterCount);
clusterIndices[i] = random.nextInt(clusterCount);
}

int[][] indexMatrix = new int[clusterCount][];
Expand Down Expand Up @@ -215,7 +219,7 @@ public static Map<Integer, Integer> quantize(
}
}

Map<Integer, Integer> argbToPopulation = new HashMap<>();
Map<Integer, Integer> argbToPopulation = new LinkedHashMap<>();
for (int i = 0; i < clusterCount; i++) {
int count = pixelCountSums[i];
if (count == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import androidx.annotation.RestrictTo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -57,7 +57,7 @@ public QuantizerResult quantize(int[] pixels, int colorCount) {
createMoments();
CreateBoxesResult createBoxesResult = createBoxes(colorCount);
List<Integer> colors = createResult(createBoxesResult.resultCount);
HashMap<Integer, Integer> resultMap = new HashMap<>();
Map<Integer, Integer> resultMap = new LinkedHashMap<>();
for (int color : colors) {
resultMap.put(color, 0);
}
Expand Down

0 comments on commit ef76670

Please sign in to comment.