Changeset 25290
- Timestamp:
- Sep 8, 2009, 4:23:41 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090715/Ohana/src/kapa2/src/CursorOps.c
r16270 r25290 2 2 3 3 // input coordinates are relative to the picture bounding box 4 // XXX pre-calculate fexpand, Xc, Yc when expand is set? 4 5 void Picture_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) { 5 6 … … 14 15 15 16 // pixel coordinates in picture frame 16 dx = expand*(x2 - 0.5*picture[0].dx); 17 dy = expand*(y2 - 0.5*picture[0].dy); 17 dx = expand*(x2 - (int)(0.5*picture[0].dx)); 18 dy = expand*(y2 - (int)(0.5*picture[0].dy)); 19 20 // set the true center (image and screen pixel boundaries must be aligned) 21 // Xc = (int)(picture[0].Xc / expand) * expand; 22 // Yc = (int)(picture[0].Yc / expand) * expand; 18 23 19 24 // picture[0].X,Y is the image coordinate in the center of the picture 20 *x1 = picture[0].flipx ? picture[0].X - dx : picture[0].X+ dx;21 *y1 = picture[0].flipy ? picture[0].Y - dy : picture[0].Y+ dy;25 *x1 = picture[0].flipx ? picture[0].Xc - dx : picture[0].Xc + dx; 26 *y1 = picture[0].flipy ? picture[0].Yc - dy : picture[0].Yc + dy; 22 27 } 23 28 … … 46 51 } 47 52 53 // set the true center (image and screen pixel boundaries must be aligned) 54 // Xc = ((int)(picture[0].Xc * expand)) / expand; 55 // Yc = ((int)(picture[0].Yc * expand)) / expand; 56 48 57 // pixel coordinates in picture frame 49 dx = picture[0].flipx ? picture[0].X - x2 : x2 - picture[0].X;50 dy = picture[0].flipy ? picture[0].Y - y2 : y2 - picture[0].Y;58 dx = picture[0].flipx ? picture[0].Xc - x2 : x2 - picture[0].Xc; 59 dy = picture[0].flipy ? picture[0].Yc - y2 : y2 - picture[0].Yc; 51 60 52 *x1 = expand*dx + 0.5*picture[0].dx;53 *y1 = expand*dy + 0.5*picture[0].dy;61 *x1 = expand*dx + (int)(0.5*picture[0].dx); 62 *y1 = expand*dy + (int)(0.5*picture[0].dy); 54 63 } 55 64 … … 66 75 67 76 // input coordinates are relative to the picture bounding box 68 void Picture_Lower (int *i_start, int *j_start, Matrix *matrix, Picture *picture) {77 void Picture_Lower (int *i_start, int *j_start, int *I_start, int *J_start, Matrix *matrix, Picture *picture) { 69 78 70 79 double Ix, Iy, Sx, Sy; … … 72 81 // Ix, Iy are the image coordinates of the specified screen pixel 73 82 Picture_to_Image (&Ix, &Iy, 0.0, 0.0, picture); 74 75 // Ix, Iy are now limited to valid image coordinates76 Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);77 Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);78 83 79 84 // round up (down) to nearest pixel boundary … … 84 89 Iy = picture[0].flipy ? (int)(Iy) : (int)(Iy) + 1; 85 90 } 91 92 // Ix, Iy are now limited to valid image coordinates 93 Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]); 94 Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]); 95 96 // I_start, J_start are the first displayed image pixel 97 *I_start = Ix; 98 *J_start = Iy; 86 99 87 100 // Sx, Sy are the screen coordinates of the Ix,Iy pixel … … 94 107 95 108 // input coordinates are relative to the picture bounding box 96 void Picture_Upper (int *i_end, int *j_end, Matrix *matrix, Picture *picture) {109 void Picture_Upper (int *i_end, int *j_end, int i_start, int j_start, Matrix *matrix, Picture *picture) { 97 110 111 int nExtra; 98 112 double Ix, Iy, Sx, Sy; 99 113 … … 101 115 Picture_to_Image (&Ix, &Iy, picture[0].dx, picture[0].dy, picture); 102 116 117 // round down (up) to nearest pixel boundary 118 if (Ix > (int)(Ix)) { 119 Ix = picture[0].flipx ? (int)(Ix) + 1: (int)(Ix); 120 } 121 if (Iy > (int)(Iy)) { 122 Iy = picture[0].flipy ? (int)(Iy) + 1: (int)(Iy); 123 } 124 103 125 // Ix, Iy are now limited to valid image coordinates 104 126 Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]); 105 127 Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]); 106 128 107 // round down (up) to nearest pixel boundary 108 if (Ix > (int)(Ix)) { 109 Ix = picture[0].flipx ? (int)(Ix) + 1 : (int)(Ix); 110 } 111 if (Iy > (int)(Iy)) { 112 Iy = picture[0].flipy ? (int)(Iy) + 1: (int)(Iy); 113 } 129 // I_end, J_end are the last displayed image pixel 130 // *I_end = Ix; 131 // *J_end = Iy; 114 132 115 133 // Sx, Sy are the screen coordinates of the Ix,Iy pixel … … 119 137 *i_end = MIN (MAX (Sx, 0), picture[0].dx); 120 138 *j_end = MIN (MAX (Sy, 0), picture[0].dy); 139 140 // round off error can leave us with a small number of extra pixels here. 141 if (picture[0].expand > 1) { 142 nExtra = (*i_end - i_start) % picture[0].expand; 143 *i_end -= nExtra; 144 nExtra = (*j_end - j_start) % picture[0].expand; 145 *j_end -= nExtra; 146 } 121 147 }
Note:
See TracChangeset
for help on using the changeset viewer.
