comparison TOOLS/subfont-c/subfont.c @ 7022:ef9f4c1a3345

using precalculated src*om[][] table -> 25% faster.
author arpi
date Fri, 16 Aug 2002 16:35:43 +0000
parents d27dd694e5ea
children 273e374311c6
comparison
equal deleted inserted replaced
7021:d27dd694e5ea 7022:ef9f4c1a3345
501 void outline( 501 void outline(
502 unsigned char *s, 502 unsigned char *s,
503 unsigned char *t, 503 unsigned char *t,
504 int width, 504 int width,
505 int height, 505 int height,
506 int *m, 506 unsigned char *m,
507 int r, 507 int r,
508 int mwidth) { 508 int mwidth,
509 int msize) {
509 510
510 int x, y; 511 int x, y;
511 #if 1 512 #if 1
512 for (y = 0; y<height; y++) { 513 for (y = 0; y<height; y++) {
513 for (x = 0; x<width; x++) { 514 for (x = 0; x<width; x++) {
523 const int x1=(x<r) ? r-x : 0; 524 const int x1=(x<r) ? r-x : 0;
524 const int y1=(y<r) ? r-y : 0; 525 const int y1=(y<r) ? r-y : 0;
525 const int x2=(x+r>=width ) ? r+width -x : 2*r+1; 526 const int x2=(x+r>=width ) ? r+width -x : 2*r+1;
526 const int y2=(y+r>=height) ? r+height-y : 2*r+1; 527 const int y2=(y+r>=height) ? r+height-y : 2*r+1;
527 register unsigned char *dstp= t + (y1+y-r)* width + x-r; 528 register unsigned char *dstp= t + (y1+y-r)* width + x-r;
528 register int *mp = m + y1 *mwidth; 529 //register int *mp = m + y1 *mwidth;
530 register unsigned char *mp= m + msize*src + y1*mwidth;
529 int my; 531 int my;
530 532
531 for(my= y1; my<y2; my++){ 533 for(my= y1; my<y2; my++){
532 // unsigned char *dstp= t + (my+y-r)* width + x-r; 534 // unsigned char *dstp= t + (my+y-r)* width + x-r;
533 // int *mp = m + my *mwidth; 535 // int *mp = m + my *mwidth;
534 register int mx; 536 register int mx;
535 for(mx= x1; mx<x2; mx++){ 537 for(mx= x1; mx<x2; mx++){
536 const int tmp= (src*mp[mx] + 128)>>8; 538 // const int tmp= (src*mp[mx] + 128)>>8;
537 if(dstp[mx] < tmp) dstp[mx]= tmp; 539 // if(dstp[mx] < tmp) dstp[mx]= tmp;
540 if(dstp[mx] < mp[mx]) dstp[mx]= mp[mx];
538 } 541 }
539 dstp+=width; 542 dstp+=width;
540 mp+=mwidth; 543 mp+=mwidth;
541 } 544 }
542 } 545 }
679 unsigned int ttime; 682 unsigned int ttime;
680 int const g_r = ceil(radius); 683 int const g_r = ceil(radius);
681 int const o_r = ceil(thickness); 684 int const o_r = ceil(thickness);
682 int const g_w = 2*g_r+1; // matrix size 685 int const g_w = 2*g_r+1; // matrix size
683 int const o_w = 2*o_r+1; // matrix size 686 int const o_w = 2*o_r+1; // matrix size
687 int const o_size = o_w * o_w;
684 double const A = log(1.0/base)/(radius*radius*2); 688 double const A = log(1.0/base)/(radius*radius*2);
685 689
686 int mx, my, i; 690 int mx, my, i;
687 unsigned volume = 0; // volume under Gaussian area is exactly -pi*base/A 691 unsigned volume = 0; // volume under Gaussian area is exactly -pi*base/A
688 692
689 unsigned *g = (unsigned*)malloc(g_w * sizeof(unsigned)); 693 unsigned *g = (unsigned*)malloc(g_w * sizeof(unsigned));
690 unsigned *om = (unsigned*)malloc(o_w*o_w * sizeof(unsigned)); 694 unsigned *om = (unsigned*)malloc(o_w*o_w * sizeof(unsigned));
691 if (g==NULL || om==NULL) ERROR("malloc failed."); 695 unsigned char *omt = malloc(o_size*256);
696 unsigned char *omtp = omt;
697
698 if (g==NULL || om==NULL || omt==NULL) ERROR("malloc failed.");
692 699
693 // gaussian curve 700 // gaussian curve
694 for (i = 0; i<g_w; ++i) { 701 for (i = 0; i<g_w; ++i) {
695 g[i] = (unsigned)(exp(A * (i-g_r)*(i-g_r)) * base + .5); 702 g[i] = (unsigned)(exp(A * (i-g_r)*(i-g_r)) * base + .5);
696 volume+= g[i]; 703 volume+= g[i];
709 } 716 }
710 if (DEBUG) eprintf("\n"); 717 if (DEBUG) eprintf("\n");
711 } 718 }
712 if (DEBUG) eprintf("\n"); 719 if (DEBUG) eprintf("\n");
713 720
721 // outline table:
722 for(i=0;i<256;i++){
723 for(mx=0;mx<o_size;mx++) *(omtp++) = (i*om[mx] + (base/2))/base;
724 }
714 725
715 ttime=GetTimer(); 726 ttime=GetTimer();
716 if(thickness==1.0) 727 if(thickness==1.0)
717 outline1(bbuffer, abuffer, width, height); // FAST solid 1 pixel outline 728 outline1(bbuffer, abuffer, width, height); // FAST solid 1 pixel outline
718 else 729 else
719 outline(bbuffer, abuffer, width, height, om, o_r, o_w); // solid outline 730 outline(bbuffer, abuffer, width, height, omt, o_r, o_w, o_size); // solid outline
720 //outline(bbuffer, abuffer, width, height, gm, g_r, g_w); // Gaussian outline 731 //outline(bbuffer, abuffer, width, height, gm, g_r, g_w); // Gaussian outline
721 ttime=GetTimer()-ttime; 732 ttime=GetTimer()-ttime;
722 printf("outline: %7d us\n",ttime); 733 printf("outline: %7d us\n",ttime);
723 734
724 ttime=GetTimer(); 735 ttime=GetTimer();