Skip to content

Commit

Permalink
Change QuanizerResult::color_to_count to match RankedSuggestion signa…
Browse files Browse the repository at this point in the history
…ture

PiperOrigin-RevId: 588900384
  • Loading branch information
Material Eng authored and copybara-github committed Dec 7, 2023
1 parent f5d03da commit 1217346
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions cpp/quantize/celebi_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ TEST(CelebiTest, OneRed) {
pixels.push_back(0xffff0000);
QuantizerResult result = QuantizeCelebi(pixels, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xffff0000], 1);
EXPECT_EQ(result.color_to_count[0xffff0000], 1u);
}

TEST(CelebiTest, OneGreen) {
std::vector<Argb> pixels;
pixels.push_back(0xff00ff00);
QuantizerResult result = QuantizeCelebi(pixels, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xff00ff00], 1);
EXPECT_EQ(result.color_to_count[0xff00ff00], 1u);
}

TEST(CelebiTest, OneBlue) {
std::vector<Argb> pixels;
pixels.push_back(0xff0000ff);
QuantizerResult result = QuantizeCelebi(pixels, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xff0000ff], 1);
EXPECT_EQ(result.color_to_count[0xff0000ff], 1u);
}

TEST(CelebiTest, FiveBlue) {
Expand All @@ -76,7 +76,7 @@ TEST(CelebiTest, FiveBlue) {
}
QuantizerResult result = QuantizeCelebi(pixels, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xff0000ff], 5);
EXPECT_EQ(result.color_to_count[0xff0000ff], 5u);
}

TEST(CelebiTest, OneRedOneGreenOneBlue) {
Expand All @@ -86,9 +86,9 @@ TEST(CelebiTest, OneRedOneGreenOneBlue) {
pixels.push_back(0xff0000ff);
QuantizerResult result = QuantizeCelebi(pixels, 256);
EXPECT_EQ(result.color_to_count.size(), 3u);
EXPECT_EQ(result.color_to_count[0xffff0000], 1);
EXPECT_EQ(result.color_to_count[0xff00ff00], 1);
EXPECT_EQ(result.color_to_count[0xff0000ff], 1);
EXPECT_EQ(result.color_to_count[0xffff0000], 1u);
EXPECT_EQ(result.color_to_count[0xff00ff00], 1u);
EXPECT_EQ(result.color_to_count[0xff0000ff], 1u);
}

TEST(CelebiTest, TwoRedThreeGreen) {
Expand All @@ -100,8 +100,8 @@ TEST(CelebiTest, TwoRedThreeGreen) {
pixels.push_back(0xff00ff00);
QuantizerResult result = QuantizeCelebi(pixels, 256);
EXPECT_EQ(result.color_to_count.size(), 2u);
EXPECT_EQ(result.color_to_count[0xffff0000], 2);
EXPECT_EQ(result.color_to_count[0xff00ff00], 3);
EXPECT_EQ(result.color_to_count[0xffff0000], 2u);
EXPECT_EQ(result.color_to_count[0xff00ff00], 3u);
}

TEST(CelebiTest, NoColors) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/quantize/wsmeans.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ QuantizerResult QuantizeWsmeans(const std::vector<Argb>& input_pixels,

// Constructs the quantizer result to return.

std::map<Argb, int> color_to_count;
std::map<Argb, uint32_t> color_to_count;
for (size_t i = 0; i < swatches.size(); i++) {
color_to_count[swatches[i].argb] = swatches[i].population;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/quantize/wsmeans.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace material_color_utilities {

struct QuantizerResult {
std::map<Argb, int> color_to_count;
std::map<Argb, uint32_t> color_to_count;
std::map<Argb, Argb> input_pixel_to_cluster_pixel;
};

Expand Down
10 changes: 5 additions & 5 deletions cpp/quantize/wsmeans_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ TEST(WsmeansTest, OneRedAndO) {
std::vector<Argb> starting_clusters;
QuantizerResult result = QuantizeWsmeans(pixels, starting_clusters, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xff141216], 1);
EXPECT_EQ(result.color_to_count[0xff141216], 1u);
}

TEST(WsmeansTest, OneRed) {
Expand All @@ -60,7 +60,7 @@ TEST(WsmeansTest, OneRed) {
std::vector<Argb> starting_clusters;
QuantizerResult result = QuantizeWsmeans(pixels, starting_clusters, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xffff0000], 1);
EXPECT_EQ(result.color_to_count[0xffff0000], 1u);
}

TEST(WsmeansTest, OneGreen) {
Expand All @@ -69,7 +69,7 @@ TEST(WsmeansTest, OneGreen) {
std::vector<Argb> starting_clusters;
QuantizerResult result = QuantizeWsmeans(pixels, starting_clusters, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xff00ff00], 1);
EXPECT_EQ(result.color_to_count[0xff00ff00], 1u);
}

TEST(WsmeansTest, OneBlue) {
Expand All @@ -78,7 +78,7 @@ TEST(WsmeansTest, OneBlue) {
std::vector<Argb> starting_clusters;
QuantizerResult result = QuantizeWsmeans(pixels, starting_clusters, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xff0000ff], 1);
EXPECT_EQ(result.color_to_count[0xff0000ff], 1u);
}

TEST(WsmeansTest, FiveBlue) {
Expand All @@ -89,7 +89,7 @@ TEST(WsmeansTest, FiveBlue) {
std::vector<Argb> starting_clusters;
QuantizerResult result = QuantizeWsmeans(pixels, starting_clusters, 256);
EXPECT_EQ(result.color_to_count.size(), 1u);
EXPECT_EQ(result.color_to_count[0xff0000ff], 5);
EXPECT_EQ(result.color_to_count[0xff0000ff], 5u);
}

} // namespace
Expand Down

0 comments on commit 1217346

Please sign in to comment.