Changeset 657
- Timestamp:
- Mar 22, 2006, 2:12:54 PM (16 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/configure.ac
r652 r657 60 60 AC_DEFINE(HAVE_SLEEP, 1, [Define to 1 if you have the `Sleep' function.])], 61 61 [AC_MSG_RESULT(no)]) 62 62 63 AC_MSG_CHECKING(for fsin/fcos) 63 64 AC_TRY_COMPILE([],[asm("fsin\n\tfcos");], … … 65 66 AC_DEFINE(HAVE_FSIN_FCOS, 1, [Define to 1 if you have the `fsin' and `fcos' operands.])], 66 67 [AC_MSG_RESULT(no)]) 68 69 AC_MSG_CHECKING(for fldln2/fxch/fyl2x) 70 AC_TRY_COMPILE([],[asm("fldln2; fldln2; fxch; fyl2x");], 71 [AC_MSG_RESULT(yes) 72 AC_DEFINE(HAVE_FLDLN2, 1, [Define to 1 if you have the `fldln2' and other floating points operands.])], 73 [AC_MSG_RESULT(no)]) 74 67 75 AC_CHECK_LIB(m, sin, MATH_LIBS="${MATH_LIBS} -lm") 68 76 -
libcaca/trunk/cucul/bitmap.c
r653 r657 32 32 #include "cucul.h" 33 33 #include "cucul_internals.h" 34 35 #define CP437 0 34 36 35 37 /* … … 58 60 59 61 /* RGB palette for the new colour picker */ 60 static int rgb_palette[] =62 static int const rgb_palette[] = 61 63 { 62 64 0x0, 0x0, 0x0, … … 78 80 }; 79 81 80 static int rgb_weight[] =82 static int const rgb_weight[] = 81 83 { 82 84 //2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2 … … 107 109 */ 108 110 static void mask2shift(unsigned int, int *, int *); 111 static float gammapow(float x, float y); 109 112 110 113 static void get_rgba_default(struct cucul_bitmap const *, uint8_t *, int, int, … … 175 178 } 176 179 180 static float gammapow(float x, float y) 181 { 182 #ifdef HAVE_FLDLN2 183 register double logx; 184 register long double v, e; 185 #else 186 register float tmp, t, r; 187 int i; 188 #endif 189 190 if(x == 0.0) 191 return y == 0.0 ? 1.0 : 0.0; 192 193 #ifdef HAVE_FLDLN2 194 /* FIXME: this can be optimised by directly calling fyl2x for x and y */ 195 asm volatile("fldln2; fxch; fyl2x" 196 : "=t" (logx) : "0" (x) : "st(1)"); 197 198 asm volatile("fldl2e\n\t" 199 "fmul %%st(1)\n\t" 200 "fst %%st(1)\n\t" 201 "frndint\n\t" 202 "fxch\n\t" 203 "fsub %%st(1)\n\t" 204 "f2xm1\n\t" 205 : "=t" (v), "=u" (e) : "0" (y * logx)); 206 v += 1.0; 207 asm volatile("fscale" 208 : "=t" (v) : "0" (v), "u" (e)); 209 return v; 210 #else 211 /* Compute ln(x) as ln(1+t) where t = x - 1, x ∈ ]0,1[ 212 * ln(1+t) = t - t^2/2 + t^3/3 - t^4/4 + t^5/5 ... 213 * The convergence is quite slow, especially when x is near 0. */ 214 tmp = t = r = x - 1.0; 215 for(i = 2; i < 30; i++) 216 { 217 r *= -t; 218 tmp += r / i; 219 } 220 221 /* Compute x^-y as e^t where t = y*ln(x): 222 * e^t = 1 + t/1! + t^2/2! + t^3/3! + t^4/4! + t^5/5! ... 223 * The convergence is a lot faster here, thanks to the factorial. */ 224 r = t = - y * tmp; 225 tmp = 1.0 + t; 226 for(i = 2; i < 16; i++) 227 { 228 r = r * t / i; 229 tmp += r; 230 } 231 232 /* Return x^y as 1/(x^-y) */ 233 return 1.0 / tmp; 234 #endif 235 } 236 177 237 /** 178 238 * \brief Create an internal bitmap object. … … 313 373 314 374 for(i = 0; i < 4096; i++) 315 bitmap->gammatab[i] = 4096.0 * cucul_powf((float)i / 4096.0, 1.0 / gamma);375 bitmap->gammatab[i] = 4096.0 * gammapow((float)i / 4096.0, 1.0 / gamma); 316 376 } 317 377 … … 449 509 /* FIXME: choose better characters! */ 450 510 #if !defined(_DOXYGEN_SKIP_ME) 451 # define DCHMAX ((sizeof(density_chars)/sizeof( char const)/4)-1)511 # define DCHMAX ((sizeof(density_chars)/sizeof(*density_chars))) 452 512 #endif 453 static char const density_chars[] = 454 " " 455 "...." 456 "::::" 457 ";=;=" 458 "tftf" 459 "%$%$" 460 "SK&Z" 461 "XWGM" 462 "@@@@" 463 "8888" 464 "####" 465 "????"; 513 static char const * density_chars[] = 514 { 515 #if CP437 516 " ", ":", "░", "▒", "?" 517 /* "0", "1", "2", "3", "?" */ 518 #else 519 " ", ".", ":", ";", "t", "%", "S", "X", "@", "8", "?" 520 #endif 521 }; 466 522 467 523 int x, y, w, h, pitch, deltax, deltay; … … 553 609 554 610 enum cucul_color outfg = 0, outbg = 0; 555 char outch;611 char const *outch; 556 612 557 613 r = g = b = a = 0; … … 676 732 } 677 733 } 678 outch = density_chars[ 4 *ch];734 outch = density_chars[ch]; 679 735 680 736 if(qq->dithering == CUCUL_DITHERING_FSTEIN) … … 696 752 else if(ch > (int)(DCHMAX - 1)) 697 753 ch = DCHMAX - 1; 698 outch = density_chars[ 4 *ch];754 outch = density_chars[ch]; 699 755 700 756 if(qq->dithering == CUCUL_DITHERING_FSTEIN) … … 724 780 /* Now output the character */ 725 781 cucul_set_color(qq, outfg, outbg); 726 cucul_put char(qq, x, y, outch);782 cucul_putstr(qq, x, y, outch); 727 783 728 784 _increment_dither();
Note: See TracChangeset
for help on using the changeset viewer.