Changeset 40730
- Timestamp:
- May 14, 2019, 2:38:41 PM (7 years ago)
- Location:
- branches/eam_branches/ohana.20190329/src/libkapa
- Files:
-
- 3 edited
-
include/kapa.h (modified) (4 diffs)
-
src/KapaWindow.c (modified) (1 diff)
-
src/bDrawFuncs.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20190329/src/libkapa/include/kapa.h
r40558 r40730 172 172 int Nx, Ny, Nbyte; 173 173 bDrawColor **pixels; 174 char **mask; 174 175 png_color *palette; 175 176 int Npalette; 177 176 178 // current drawing values: 177 179 int bWeight; … … 256 258 int KapaGetImageData (int fd, KapaImageData *graphmode); 257 259 int KapaSetToolbox (int fd, int location); 260 int KapaSetSmoothSigma (int fd, float sigma); 258 261 259 262 /* KapaColors */ … … 292 295 bDrawBuffer *bDrawBufferCreate (int Nx, int Ny, int Nbyte, png_color *palette, int Npalette); 293 296 void bDrawBufferFree (bDrawBuffer *buffer); 297 int bDrawMerge (bDrawBuffer *base, bDrawBuffer *layer); 294 298 void bDrawSetBuffer (bDrawBuffer *buffer); 295 299 void bDrawSetColor (bDrawBuffer *buffer, bDrawColor color); … … 312 316 void bDrawTriOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3); 313 317 void bDrawTriFill (bDrawBuffer *buffer, double x1, double y1, double dx, double dy); 318 319 void bDrawSmooth (bDrawBuffer *buffer, float sigma); 314 320 315 321 /* bDrawRotFont.c */ -
branches/eam_branches/ohana.20190329/src/libkapa/src/KapaWindow.c
r40570 r40730 455 455 } 456 456 457 int KapaSetSmoothSigma (int fd, float sigma) { 458 459 KiiSendCommand (fd, 4, "SIGM"); 460 KiiSendMessage (fd, "%4.1f ", sigma); 461 KiiWaitAnswer (fd, "DONE"); 462 return (TRUE); 463 } -
branches/eam_branches/ohana.20190329/src/libkapa/src/bDrawFuncs.c
r40572 r40730 1 1 # include <kapa_internal.h> 2 2 3 // move these to the bDrawBuffer type 4 // static int bWeight; 5 // static int bType; 6 // static bDrawColor bColor; 7 // static bDrawColor bColor_R; 8 // static bDrawColor bColor_G; 9 // static bDrawColor bColor_B; 10 // static bDrawBuffer *bBuffer; 3 // buffer->pixels carries the plot image 4 // buffer->mask is 0 if the pixel is untouched, 1 if the pixel has data 11 5 12 6 void bDrawCircleSingle (bDrawBuffer *buffer, double xc, double yc, double radius); 7 8 int bDrawMerge (bDrawBuffer *base, bDrawBuffer *layer) { 9 10 // the two bDrawBuffers must match in size and depth 11 12 if (base->Nx != layer->Nx) return FALSE; 13 if (base->Ny != layer->Ny) return FALSE; 14 if (base->Nbyte != layer->Nbyte) return FALSE; 15 16 for (int j = 0; j < base->Ny; j++) { 17 for (int i = 0; i < base->Nx; i++) { 18 19 if (!layer->mask[j][i]) continue; 20 21 // completely opaque top layer: 22 if (base->Nbyte == 1) { 23 base->pixels[j][i] = layer->pixels[j][i]; 24 } else { 25 base->pixels[j][3*i+0] = layer->pixels[j][3*i+0]; 26 base->pixels[j][3*i+1] = layer->pixels[j][3*i+1]; 27 base->pixels[j][3*i+2] = layer->pixels[j][3*i+2]; 28 } 29 } 30 } 31 return TRUE; 32 } 13 33 14 34 // create a drawing buffer with either 1 or 3 byte colors … … 35 55 36 56 ALLOCATE (buffer[0].pixels, bDrawColor *, Ny); 57 ALLOCATE (buffer[0].mask, char *, Ny); 37 58 for (i = 0; i < Ny; i++) { 38 59 ALLOCATE (buffer[0].pixels[i], bDrawColor, Nbyte*Nx); 60 ALLOCATE (buffer[0].mask[i], char, Nx); 39 61 for (j = 0; j < Nx; j++) { 40 62 if (Nbyte == 1) { … … 45 67 buffer[0].pixels[i][3*j+2] = white_B; 46 68 } 69 buffer[0].mask[i][j] = 0; // for now: 0 = no data, 1 = data 47 70 } 48 71 } … … 63 86 for (i = 0; i < buffer[0].Ny; i++) { 64 87 free (buffer[0].pixels[i]); 88 free (buffer[0].mask[i]); 65 89 } 66 90 free (buffer[0].pixels); 67 free (buffer[0].palette); 91 free (buffer[0].mask); 92 // free (buffer[0].palette); 68 93 free (buffer); 69 94 return; … … 121 146 buffer[0].pixels[y][x] = buffer->bColor; 122 147 } else { 123 // buffer[0].pixels[y][3*x+0] = buffer->bColor_R; 124 // buffer[0].pixels[y][3*x+1] = buffer->bColor_G; 125 // buffer[0].pixels[y][3*x+2] = buffer->bColor_B; 126 buffer[0].pixels[y][3*x+0] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[y][3*x+0] + alpha * buffer->bColor_R)); 148 buffer[0].pixels[y][3*x+0] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[y][3*x+0] + alpha * buffer->bColor_R)); // was just buffer->bColor_R, etc 127 149 buffer[0].pixels[y][3*x+1] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[y][3*x+1] + alpha * buffer->bColor_G)); 128 150 buffer[0].pixels[y][3*x+2] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[y][3*x+2] + alpha * buffer->bColor_B)); 129 151 } 152 buffer[0].mask[y][x] = 1; 130 153 return; 131 154 } … … 299 322 buffer[0].pixels[Y][3*i+1] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[Y][3*i+1] + alpha * buffer->bColor_G)); 300 323 buffer[0].pixels[Y][3*i+2] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[Y][3*i+2] + alpha * buffer->bColor_B)); 301 // buffer[0].pixels[Y][3*i+0] = buffer->bColor_R; 302 // buffer[0].pixels[Y][3*i+1] = buffer->bColor_G; 303 // buffer[0].pixels[Y][3*i+2] = buffer->bColor_B; 304 } 324 } 325 buffer[0].mask[Y][i] = 1; 305 326 } 306 327 return; … … 326 347 buffer[0].pixels[i][3*X+1] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[i][3*X+1] + alpha * buffer->bColor_G)); 327 348 buffer[0].pixels[i][3*X+2] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[i][3*X+2] + alpha * buffer->bColor_B)); 328 // buffer[0].pixels[i][3*X+0] = buffer->bColor_R; 329 // buffer[0].pixels[i][3*X+1] = buffer->bColor_G; 330 // buffer[0].pixels[i][3*X+2] = buffer->bColor_B; 331 } 349 } 350 buffer[0].mask[i][X] = 1; 332 351 } 333 352 return; … … 648 667 } 649 668 669 // run a smoothing kernel on each channel for anti-aliasing 670 // XXX I need to consider the mask as well 671 void bDrawSmooth (bDrawBuffer *buffer, float sigma) { 672 673 // generate a temp buffer for storage of the smoothed result 674 int Nx = buffer[0].Nx; 675 int Ny = buffer[0].Ny; 676 ALLOCATE_PTR (temp, bDrawColor, Nx*Ny); 677 678 //* build a 1D gaussian 679 int Nsigma = 2; 680 int Ns = (int) (Nsigma*sigma + 0.5); 681 int Ngauss = 2*Ns + 1; 682 ALLOCATE_PTR (gaussnorm, float, Ngauss); 683 float *gauss = &gaussnorm[Ns]; 684 for (int i = -Ns; i < Ns + 1; i++) { 685 gauss[i] = exp ((i*i)/(-2*sigma*sigma)); 686 } 687 688 // NOTE XXX: need to handle Nbyte = 1 or 3 689 int Nchannel = 3; 690 691 // we need to smooth the 3 channels independently, do this as three passes 692 for (int ch = 0; ch < Nchannel; ch++) { 693 694 // smooth in X direction 695 for (int j = 0; j < Ny; j++) { 696 bDrawColor *vi = (bDrawColor *) &buffer[0].pixels[j][ch]; 697 bDrawColor *vo = &temp[j*Nx]; 698 for (int i = 0; i < Nx; i++, vo++, vi += Nchannel) { 699 float g = 0.0, s = 0.0; 700 for (int n = -Ns; n <= Ns; n++) { 701 if (i+n < 0) continue; 702 if (i+n >= Nx) continue; 703 s += gauss[n]*vi[Nchannel*n]; 704 g += gauss[n]; 705 } 706 *vo = s / g; 707 } 708 } 709 710 // NOTE: output maps back into original image 711 // careful on the counting 712 713 /* smooth in Y direction */ 714 for (int i = 0; i < Nx; i++) { 715 bDrawColor *vi = &temp[i]; 716 for (int j = 0; j < Ny; j++) { 717 float g = 0.0, s = 0.0; 718 for (int n = -Ns; n <= Ns; n++) { 719 if (j+n < 0) continue; 720 if (j+n >= Ny) continue; 721 s += gauss[n]*vi[(n+j)*Nx]; // vi is a single-index array, so this is stepping by rows 722 g += gauss[n]; 723 } 724 buffer[0].pixels[j][Nchannel*i + ch] = s / g; 725 } 726 } 727 } 728 729 // smooth the mask 730 ALLOCATE_PTR (temp_mask, float, Nx*Ny); 731 732 // smooth in X direction 733 for (int j = 0; j < Ny; j++) { 734 char *vi = (char *) &buffer[0].mask[j][0]; 735 float *vo = &temp_mask[j*Nx]; 736 for (int i = 0; i < Nx; i++, vo++, vi++) { 737 float g = 0.0, s = 0.0; 738 for (int n = -Ns; n <= Ns; n++) { 739 if (i+n < 0) continue; 740 if (i+n >= Nx) continue; 741 s += gauss[n]*vi[n]; 742 g += gauss[n]; 743 } 744 *vo = s / g; 745 } 746 } 747 748 // NOTE: output maps back into original image 749 // careful on the counting 750 751 /* smooth in Y direction */ 752 for (int i = 0; i < Nx; i++) { 753 float *vi = &temp_mask[i]; 754 for (int j = 0; j < Ny; j++) { 755 float g = 0.0, s = 0.0; 756 for (int n = -Ns; n <= Ns; n++) { 757 if (j+n < 0) continue; 758 if (j+n >= Ny) continue; 759 s += gauss[n]*vi[(n+j)*Nx]; // vi is a single-index array, so this is stepping by rows 760 g += gauss[n]; 761 } 762 buffer[0].mask[j][i] = (s / g > 0.05) ? 1 : 0; 763 } 764 } 765 766 free (temp); 767 free (temp_mask); 768 free (gaussnorm); 769 770 return; 771 } 772 650 773 /* 774 NOTES on Bresenham-style circles: 651 775 the discriminant of inside or outside the circle is: 652 776
Note:
See TracChangeset
for help on using the changeset viewer.
