Changeset 16228 for trunk/Ohana/src/kapa2/src/Remap24.c
- Timestamp:
- Jan 24, 2008, 5:45:18 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/kapa2/src/Remap24.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/kapa2/src/Remap24.c
r16011 r16228 1 1 # include "Ximage.h" 2 3 static float slope = 1.0;4 static float start = 0.0;5 static int MaxValue = 255;6 7 // XXX inline this if needed8 static int PixelLookup(float value) {9 int out;10 out = MIN (MAX (slope * value - start, 0), MaxValue);11 return (out);12 }13 2 14 3 void Remap24 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) { … … 17 6 int i_start, i_end, j_start, j_end; 18 7 int dropback, extra; /* this is a bit of a kludge... */ 19 int dx, dy, DX, DY , pixelN;20 double expand, Rx, Ry, X, Y;8 int dx, dy, DX, DY; 9 double expand, Sx, Sy, Ix, Iy; 21 10 int expand_in, expand_out; 22 11 unsigned char *out_pix, *out_pix2, *data; 23 float *imdata,*in_pix, *in_pix2;24 unsigned char pixel1[256], pixel2[256], pixel3[256];12 unsigned short *in_pix, *in_pix2; 13 unsigned char *pixel1, *pixel2, *pixel3; 25 14 unsigned char pixvalue1, pixvalue2, pixvalue3; 26 unsigned long back;27 15 unsigned char back1, back2, back3; 28 16 17 ALLOCATE (pixel1, unsigned char, graphic[0].Npixels); 18 ALLOCATE (pixel2, unsigned char, graphic[0].Npixels); 19 ALLOCATE (pixel3, unsigned char, graphic[0].Npixels); 20 29 21 // local arrays for pixel values 30 for (i = 0; i < 256; i++) { /* set up pixel array */22 for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */ 31 23 pixel1[i] = 0x0000ff & graphic[0].cmap[i].pixel; 32 24 pixel2[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 8); 33 25 pixel3[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 16); 34 26 } 35 back = graphic[0].back; 36 back1 = 0x0000ff & back; 37 back2 = 0x0000ff & (back >> 8); 38 back3 = 0x0000ff & (back >> 16); 39 40 // define the color transform parameters 41 MaxValue = graphic[0].Npixels - 1; 42 if (image[0].image[0].range != 0.0) { 43 slope = graphic[0].Npixels / image[0].image[0].range; 44 start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range; 45 } else { 46 slope = 1.0; 47 start = image[0].image[0].zero; 48 } 27 back1 = 0x0000ff & (graphic[0].back >> 0); 28 back2 = 0x0000ff & (graphic[0].back >> 8); 29 back3 = 0x0000ff & (graphic[0].back >> 16); 49 30 50 31 // set up expansions … … 70 51 71 52 /* X,Y are the image coordinates of the first image pixel */ 72 X= MAX(0.5*(DX - dx*expand) - image[0].X, 0);73 if ((int) X != X)74 X = (int) X+ 1;53 Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0); 54 if ((int)Ix != Ix) 55 Ix = (int) Ix + 1; 75 56 else 76 X = (int) X;77 Y= MAX(0.5*(DY - dy*expand) - image[0].Y, 0);78 if ((int) Y != Y)79 Y = (int) Y+ 1;57 Ix = (int) Ix; 58 Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0); 59 if ((int)Iy != Iy) 60 Iy = (int) Iy + 1; 80 61 else 81 Y = (int) Y;62 Iy = (int) Iy; 82 63 83 /* Rx,Ry are the screen coordinates of the first image pixel */84 Rx = (X+ image[0].X - 0.5*DX)/expand + 0.5*dx;85 Ry = (Y+ image[0].Y - 0.5*DY)/expand + 0.5*dy;64 /* Sx,Sy are the screen coordinates of the first image pixel */ 65 Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx; 66 Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy; 86 67 87 i_start = MIN (MAX ( Rx, 0), dx - expand_out + 1);88 j_start = MIN (MAX ( Ry, 0), dy - expand_out + 1);68 i_start = MIN (MAX (Sx, 0), dx - expand_out + 1); 69 j_start = MIN (MAX (Sy, 0), dy - expand_out + 1); 89 70 90 71 if (image[0].expand > 0) { 91 i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX- X) + Rx), 0);92 j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY- Y) + Ry), 0);72 i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0); 73 j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0); 93 74 } else { 94 i_end = MAX (MIN (dx, (DX- X)/expand + Rx), 0);95 j_end = MAX (MIN (dy, (DY- Y)/expand + Ry), 0);75 i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0); 76 j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0); 96 77 } 97 78 … … 100 81 101 82 data = out_pix = (unsigned char *) image[0].picture.data; 102 imdata = (float *) matrix[0].buffer; 103 in_pix = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)]; 83 in_pix = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)]; 104 84 105 85 /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/ … … 133 113 if (expand_out == 1) { 134 114 for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) { 135 pixelN = PixelLookup(*in_pix2); 136 out_pix[0] = pixel1[pixelN]; 137 out_pix[1] = pixel2[pixelN]; 138 out_pix[2] = pixel3[pixelN]; 115 out_pix[0] = pixel1[*in_pix2]; 116 out_pix[1] = pixel2[*in_pix2]; 117 out_pix[2] = pixel3[*in_pix2]; 139 118 } 140 119 } else { 141 120 for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) { 142 pixelN = PixelLookup(*in_pix2); 143 pixvalue1 = pixel1[pixelN]; 144 pixvalue2 = pixel2[pixelN]; 145 pixvalue3 = pixel3[pixelN]; 121 pixvalue1 = pixel1[*in_pix2]; 122 pixvalue2 = pixel2[*in_pix2]; 123 pixvalue3 = pixel3[*in_pix2]; 146 124 out_pix2 = out_pix; 147 125 for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) { … … 185 163 image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 186 164 image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 32, 0); 165 166 free (pixel1); 167 free (pixel2); 168 free (pixel3); 187 169 } 188 170
Note:
See TracChangeset
for help on using the changeset viewer.
