Subversion Repositories RepoView

Rev

Rev 34 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34 Rev 36
Line 1... Line 1...
1
/* $Id: avatar.c 34 2024-08-22 02:50:46Z nishi $ */
1
/* $Id: avatar.c 36 2024-08-22 02:54:07Z nishi $ */
2
 
2
 
3
#include "rv_avatar.h"
3
#include "rv_avatar.h"
4
 
4
 
5
#include "rv_md5.h"
5
#include "rv_md5.h"
6
 
6
 
7
#include <stdio.h>
7
#include <stdio.h>
8
#include <stdlib.h>
8
#include <stdlib.h>
9
 
9
 
10
#include <png.h>
10
#include <png.h>
11
 
11
 
12
int hex_to_num(const char* hex, int len) {
12
int hex_to_num_len(const char* hex, int len) {
13
	int i;
13
	int i;
14
	int num = 0;
14
	int num = 0;
15
	for(i = 0; i < len; i++) {
15
	for(i = 0; i < len; i++) {
16
		num = num << 4;
16
		num = num << 4;
17
		if(hex[i] >= '0' && hex[i] <= '9') {
17
		if(hex[i] >= '0' && hex[i] <= '9') {
Line 27... Line 27...
27
 
27
 
28
char* generate_ident(const char* username, int* r, int* g, int* b) {
28
char* generate_ident(const char* username, int* r, int* g, int* b) {
29
	char* ident = malloc(25);
29
	char* ident = malloc(25);
30
	char* hash = rv_md5(username);
30
	char* hash = rv_md5(username);
31
 
31
 
32
	double h = hex_to_num(hash + 32 - 2 - 2 - 3, 3);
32
	double h = hex_to_num_len(hash + 32 - 2 - 2 - 3, 3);
33
	double s = hex_to_num(hash + 32 - 2 - 2, 2);
33
	double s = hex_to_num_len(hash + 32 - 2 - 2, 2);
34
	double v = hex_to_num(hash + 32 - 2, 2);
34
	double v = hex_to_num_len(hash + 32 - 2, 2);
35
 
35
 
36
	h = h * 360 / 4095;
36
	h = h * 360 / 4095;
37
	s = 65 - s * 20 / 255;
37
	s = 65 - s * 20 / 255;
38
	v = 75 - v * 20 / 255;
38
	v = 75 - v * 20 / 255;
39
 
39