Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve user avatars design #1777

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,76 @@
package bisq.desktop.components.cathash;

import bisq.common.util.MathUtils;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedHashMap;
import java.util.Map;

@Slf4j
public class BucketConfig {
static final String DIGIT = "#";
static final String SHAPE_NUMBER = "#SHAPE_NUMBER#";

private static final Bucket BG = new Bucket(16, 0);
private static final Bucket BG_OVERLAY = new Bucket(32, 1);
private static final Bucket BODY_AND_FACE = new Bucket(16, 2);
private static final Bucket CHEST_AND_EARS = new Bucket(16, 3);
private static final Bucket CHEST_OVERLAY = new Bucket(3, 4);
private static final Bucket EARS_OVERLAY = new Bucket(3, 5);
private static final Bucket FACE_OVERLAY = new Bucket(17, 6);
private static final Bucket EYES = new Bucket(16, 7);
private static final Bucket NOSE = new Bucket(6, 8);
private static final Bucket WHISKERS = new Bucket(7, 9);

private static final int BG0_COUNT = 16;
private static final int BG1_COUNT = 16;
private static final int EARS0_COUNT = 16;
private static final int EARS1_COUNT = 3;
private static final int FACE0_COUNT = 16;
private static final int FACE1_COUNT = 9;
private static final int EYES0_COUNT = 16;
private static final int NOSE0_COUNT = 6;
private static final int WHISKERS0_COUNT = 7;
// Shape picker
private static final Bucket BODY_SHAPE = new Bucket(2, 10);
private static final Bucket CHEST_SHAPE = new Bucket(2, 11);
private static final Bucket EARS_SHAPE = new Bucket(2, 12);
private static final Bucket FACE_SHAPE = new Bucket(5, 13);

private static final int[] BUCKET_SIZES = new int[]{BG0_COUNT, BG1_COUNT, EARS0_COUNT, EARS1_COUNT, FACE0_COUNT,
FACE1_COUNT, EYES0_COUNT, NOSE0_COUNT, WHISKERS0_COUNT};
private static final int[] BUCKET_SIZES = new int[]{
BG.getCount(),
BG_OVERLAY.getCount(),
BODY_AND_FACE.getCount(),
CHEST_AND_EARS.getCount(),
CHEST_OVERLAY.getCount(),
EARS_OVERLAY.getCount(),
FACE_OVERLAY.getCount(),
EYES.getCount(),
NOSE.getCount(),
WHISKERS.getCount(),
BODY_SHAPE.getCount(),
CHEST_SHAPE.getCount(),
EARS_SHAPE.getCount(),
FACE_SHAPE.getCount()
};

private static final String[] PATH_TEMPLATES;
private static final Map<String, PathTemplateEncoding> PATH_TEMPLATES_WITH_ENCODING;

static {
String postFix = ".png";
PATH_TEMPLATES = new String[]{
"bg0/" + DIGIT + postFix,
"bg1/" + DIGIT + postFix,
"ears0/" + DIGIT + postFix,
"ears1/" + DIGIT + postFix,
"face0/" + DIGIT + postFix,
"face1/" + DIGIT + postFix,
"eyes0/" + DIGIT + postFix,
"nose0/" + DIGIT + postFix,
"whiskers0/" + DIGIT + postFix
};
PATH_TEMPLATES_WITH_ENCODING = new LinkedHashMap<>();

PATH_TEMPLATES_WITH_ENCODING.put("bg/bg_0/" + DIGIT + postFix, new PathTemplateEncoding(BG.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("bg/bg_1/" + DIGIT + postFix, new PathTemplateEncoding(BG_OVERLAY.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("body/body" + SHAPE_NUMBER + "/" + DIGIT + postFix,
new PathTemplateEncoding(BODY_AND_FACE.getIdx(), BODY_SHAPE.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("chest/chest" + SHAPE_NUMBER + "_0/" + DIGIT + postFix,
new PathTemplateEncoding(CHEST_AND_EARS.getIdx(), CHEST_SHAPE.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("chest/chest" + SHAPE_NUMBER + "_1/" + DIGIT + postFix,
new PathTemplateEncoding(CHEST_OVERLAY.getIdx(), CHEST_SHAPE.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("ears/ears" + SHAPE_NUMBER + "_0/" + DIGIT + postFix,
new PathTemplateEncoding(CHEST_AND_EARS.getIdx(), EARS_SHAPE.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("ears/ears" + SHAPE_NUMBER + "_1/" + DIGIT + postFix,
new PathTemplateEncoding(EARS_OVERLAY.getIdx(), EARS_SHAPE.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("face/face" + SHAPE_NUMBER + "_0/" + DIGIT + postFix,
new PathTemplateEncoding(BODY_AND_FACE.getIdx(), FACE_SHAPE.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("face/face" + SHAPE_NUMBER + "_1/" + DIGIT + postFix,
new PathTemplateEncoding(FACE_OVERLAY.getIdx(), FACE_SHAPE.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("eyes/" + DIGIT + postFix, new PathTemplateEncoding(EYES.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("nose/" + DIGIT + postFix, new PathTemplateEncoding(NOSE.getIdx()));
PATH_TEMPLATES_WITH_ENCODING.put("whiskers/" + DIGIT + postFix, new PathTemplateEncoding(WHISKERS.getIdx()));

long numCombinations = getNumCombinations();
log.info("Number of combinations: 2^{} = {}", MathUtils.getLog2(numCombinations), numCombinations);
Expand All @@ -61,8 +97,8 @@ static int[] getBucketSizes() {
return BUCKET_SIZES;
}

static String[] getPathTemplates() {
return PATH_TEMPLATES;
static Map<String, PathTemplateEncoding> getPathTemplatesWithEncoding() {
return PATH_TEMPLATES_WITH_ENCODING;
}

static long getNumCombinations() {
Expand All @@ -72,4 +108,30 @@ static long getNumCombinations() {
}
return result;
}

@Getter
static class Bucket {
int count;
int idx;

public Bucket(int count, int idx) {
this.count = count;
this.idx = idx;
}
}

@Getter
static class PathTemplateEncoding {
Integer itemIdx;
Integer shapeIdx;

public PathTemplateEncoding(Integer itemIdx) {
this(itemIdx, null);
}

public PathTemplateEncoding(Integer itemIdx, Integer shapeIdx) {
this.itemIdx = itemIdx;
this.shapeIdx = shapeIdx;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package bisq.desktop.components.cathash;

import java.math.BigInteger;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class BucketEncoder {
/**
Expand All @@ -38,16 +40,26 @@ static int[] encode(BigInteger input, int[] bucketSizes) {
return result;
}

static String[] toPaths(int[] buckets, String[] pathTemplates) {
String[] paths = new String[buckets.length];
for (int facet = 0; facet < buckets.length; facet++) {
int bucketValue = buckets[facet];
paths[facet] = generatePath(pathTemplates[facet], bucketValue);
}
static String[] toPaths(int[] buckets, Map<String, BucketConfig.PathTemplateEncoding> pathTemplatesWithEncoding) {
String[] paths = new String[pathTemplatesWithEncoding.size()];
AtomicInteger idx = new AtomicInteger(0);
pathTemplatesWithEncoding.forEach((path, encoding) -> {
Integer shapeNumber = encoding.shapeIdx != null ? buckets[encoding.shapeIdx] : null;
int itemNumber = buckets[encoding.itemIdx];
paths[idx.getAndIncrement()] = shapeNumber != null
? generatePath(path, shapeNumber, itemNumber)
: generatePath(path, itemNumber);
});
return paths;
}

private static String generatePath(String pathTemplate, int shapeNumber, int index) {
return pathTemplate
.replaceAll(BucketConfig.SHAPE_NUMBER, String.format("%1d", shapeNumber))
.replaceAll(BucketConfig.DIGIT, String.format("%02d", index));
}

private static String generatePath(String pathTemplate, int index) {
return pathTemplate.replaceAll(BucketConfig.DIGIT, String.format("%02d", index));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static Image getImage(byte[] pubKeyHash, byte[] powSolution, boolean useC
}

int[] buckets = BucketEncoder.encode(input, BucketConfig.getBucketSizes());
String[] paths = BucketEncoder.toPaths(buckets, BucketConfig.getPathTemplates());
String[] paths = BucketEncoder.toPaths(buckets, BucketConfig.getPathTemplatesWithEncoding());
Image image = ImageUtil.composeImage(paths, SIZE, SIZE);
if (useCache && CACHE.size() < MAX_CACHE_SIZE) {
CACHE.put(input, image);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading
Loading