- Timestamp:
- Oct 24, 2007, 1:02:40 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/tools/sortchars.c
r1841 r1842 26 26 27 27 #define GLYPHS 0x7f 28 #define FONT 1/* 0 or 1 */28 #define FONT 0 /* 0 or 1 */ 29 29 #define DX 2 30 30 #define DY 3 … … 40 40 { 41 41 0, 4, 6, 8, 9, 10, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15 42 //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15 42 43 }; 43 44 44 45 static int distance(uint16_t, uint16_t); 46 static void testcircle(void); 45 47 46 48 int main(int argc, char *argv[]) … … 175 177 cucul_free_canvas(cv); 176 178 179 testcircle(); 180 177 181 return 0; 178 182 } 179 183 180 static int distance(uint16_t a, uint16_t b)184 static int distance(uint16_t mychar, uint16_t x) 181 185 { 182 186 int i, d = 0; … … 184 188 for(i = 0; i < DX * DY; i++) 185 189 { 186 int x = (int)(a & (RANGE - 1)) - (int)(b& (RANGE - 1));187 d += x * x;188 a/= RANGE;189 b/= RANGE;190 int t = (int)(mychar & (RANGE - 1)) - (int)(x & (RANGE - 1)); 191 d += t > 0 ? 1 * t : -2 * t; 192 mychar /= RANGE; 193 x /= RANGE; 190 194 } 191 195 … … 193 197 } 194 198 199 #define WIDTH 40 200 #define HEIGHT 18 201 202 static void testcircle(void) 203 { 204 char utf8[7]; 205 uint8_t *buf = malloc(256 * 256); 206 uint16_t *dst = malloc(WIDTH * DX * HEIGHT * DY * sizeof(uint16_t)); 207 int x, y, ret; 208 209 memset(buf, 0, 256 * 256); 210 memset(dst, 0, WIDTH * DX * HEIGHT * DY); 211 212 /* Fill image */ 213 for(y = 0; y < 256; y++) 214 for(x = 0; x < 256; x++) 215 { 216 int dist2 = (x - 128) * (x - 128) + (y - 128) * (y - 128); 217 if(dist2 < 25000 && dist2 > 18000) 218 buf[y * 256 + x] = 255; 219 else if(dist2 < 14000 && dist2 > 9000) 220 buf[y * 256 + x] = 204; 221 else if(dist2 < 6000 && dist2 > 3000) 222 buf[y * 256 + x] = 153; 223 else if(dist2 < 1600 && dist2 > 300) 224 buf[y * 256 + x] = 102; 225 } 226 227 /* Parse image */ 228 for(y = 0; y < HEIGHT * DY; y++) 229 for(x = 0; x < WIDTH * DX; x++) 230 dst[y * WIDTH * DX + x] = (int)buf[(y * 256 / (HEIGHT * DY)) * 256 + (x * 256 / (WIDTH * DX))] * RANGE / 256; 231 232 for(y = 0; y < HEIGHT; y++) 233 { 234 for(x = 0; x < WIDTH; x++) 235 { 236 uint16_t bits = 0; 237 int i, j; 238 for(j = 0; j < DY; j++) 239 for(i = 0; i < DX; i++) 240 { 241 bits *= RANGE; 242 bits |= dst[(y * DY + j) * WIDTH * DX + x * DX + i]; 243 } 244 245 ret = cucul_utf32_to_utf8(utf8, bestchar[bits]); 246 utf8[ret] = '\0'; 247 printf("%s", utf8); 248 } 249 250 printf("\n"); 251 } 252 } 253
Note: See TracChangeset
for help on using the changeset viewer.