misc.c

Go to the documentation of this file.
00001 /***********************************************************************
00002  * 
00003  * scan345: misc.c
00004  *
00005  * Copyright by:        Dr. Claudio Klein
00006  *                      X-ray Research GmbH, Hamburg
00007  *
00008  * Version:     3.0
00009  * Date:        31/10/2000
00010  *
00011  * Subroutines included in this file:
00012  * --------------------------------- 
00013  * Function: rotate_i2 = rotates image clockwise 90. deg (short)
00014  * Function: rotate_ch = rotates image clockwise 90. deg (char)
00015  * Function: rotate_i4 = rotates image clockwise 90. deg (int)
00016  * Function: rotate_i4_anti = rotates image anticlockwise 90. deg
00017  * Function: rotate_i2_anti = rotates image anticlockwise 90. deg
00018  * Function: rotate_ch_anti = rotates image anticlockwise 90. deg
00019  * Function: wtext = puts message in text field of main window
00020  * 
00021  ***********************************************************************/
00022 #include <stdio.h>
00023 #include <math.h>
00024 #include <ctype.h>
00025 
00026 void            rotate_i2               (unsigned short *, int);
00027 void            rotate_ch               (unsigned char  *, int);
00028 void            rotate_i4               (unsigned int   *, int);
00029 void            rotate_i4_anti          (unsigned int   *, int);
00030 void            rotate_i2_anti          (unsigned short *, int);
00031 void            rotate_ch_anti          (unsigned char  *, int);
00032 void            wtext                   (int             , char *);
00033 
00034 /******************************************************************
00035  * Function: rotate_i4_anti = rotates image anticlockwise by 90. deg
00036  *
00037  *                      0 1 2       2 5 8
00038  *                      3 4 5  -->  1 4 7
00039  *                      6 7 8       0 3 6
00040  *
00041  *                      x,y -> y,(width-1-x)
00042  *
00043  ******************************************************************/
00044 void rotate_i4_anti(unsigned int *data, int nx)
00045 {
00046   register unsigned int *ptr1, *ptr2, *ptr3, *ptr4, temp;
00047   register int            i, j;
00048   int                     nx2 = (nx+1)/2;
00049 
00050   for ( i=nx/2; i--; ) {
00051 
00052     /* Set pointer addresses */
00053 
00054     j    = nx2 - 1;
00055     ptr1 = data + nx*i        + j;          /* 1. Quadrant */
00056     ptr2 = data + nx*j        + nx-1-i;     /* 2. Quadrant */
00057     ptr3 = data + nx*(nx-1-i) + nx-1-j;     /* 4. Quadrant */
00058     ptr4 = data + nx*(nx-1-j) + i;          /* 3. Quadrant */
00059 
00060     for ( j = nx2; j--; ) {
00061 
00062       /* Restack: anticlockwise rotation by 90.0 */
00063       temp  = *ptr1;
00064       *ptr1 = *ptr2;
00065       *ptr2 = *ptr3;
00066       *ptr3 = *ptr4;
00067       *ptr4 = temp;
00068 
00069       /* Increase pointer */
00070       ptr1 --;
00071       ptr2 -= nx;
00072       ptr3 ++;
00073       ptr4 += nx;
00074     }
00075   }
00076 }
00077 
00078 /******************************************************************
00079  * Function: rotate_i2_anti = rotates image anticlockwise by 90. deg
00080  *
00081  *                      0 1 2       2 5 8
00082  *                      3 4 5  -->  1 4 7
00083  *                      6 7 8       0 3 6
00084  *
00085  *                      x,y -> y,(width-1-x)
00086  *
00087  ******************************************************************/
00088 void rotate_i2_anti(unsigned short *data, int nx)
00089 {
00090   register unsigned short *ptr1, *ptr2, *ptr3, *ptr4, temp;
00091   register int            i, j;
00092   int                     nx2 = (nx+1)/2;
00093 
00094   for ( i=nx/2; i--; ) {
00095 
00096     /* Set pointer addresses */
00097 
00098     j    = nx2 - 1;
00099     ptr1 = data + nx*i        + j;          /* 1. Quadrant */
00100     ptr2 = data + nx*j        + nx-1-i;     /* 2. Quadrant */
00101     ptr3 = data + nx*(nx-1-i) + nx-1-j;     /* 4. Quadrant */
00102     ptr4 = data + nx*(nx-1-j) + i;          /* 3. Quadrant */
00103 
00104     for ( j = nx2; j--; ) {
00105 
00106       /* Restack: anticlockwise rotation by 90.0 */
00107       temp  = *ptr1;
00108       *ptr1 = *ptr2;
00109       *ptr2 = *ptr3;
00110       *ptr3 = *ptr4;
00111       *ptr4 = temp;
00112 
00113       /* Increase pointer */
00114       ptr1 --;
00115       ptr2 -= nx;
00116       ptr3 ++;
00117       ptr4 += nx;
00118     }
00119   }
00120 }
00121 
00122 /******************************************************************
00123  * Function: rotate_ch_anti    = rotates image anticlockwise by 90. deg
00124  *
00125  *                      0 1 2       2 5 8
00126  *                      3 4 5  -->  1 4 7
00127  *                      6 7 8       0 3 6
00128  *
00129  *                      x,y -> y,(width-1-x)
00130  *
00131  ******************************************************************/
00132 void rotate_ch_anti(unsigned char *data, int nx)
00133 {
00134   register unsigned char *ptr1, *ptr2, *ptr3, *ptr4, temp;
00135   register int            i, j;
00136   int                     nx2 = (nx+1)/2;
00137 
00138   for ( i=nx/2; i--; ) {
00139 
00140     /* Set pointer addresses */
00141 
00142     j    = nx2 - 1;
00143     ptr1 = data + nx*i        + j;          /* 1. Quadrant */
00144     ptr2 = data + nx*j        + nx-1-i;     /* 2. Quadrant */
00145     ptr3 = data + nx*(nx-1-i) + nx-1-j;     /* 4. Quadrant */
00146     ptr4 = data + nx*(nx-1-j) + i;          /* 3. Quadrant */
00147 
00148     for ( j = nx2; j--; ) {
00149 
00150       /* Restack: anticlockwise rotation by 90.0 */
00151       temp  = *ptr1;
00152       *ptr1 = *ptr2;
00153       *ptr2 = *ptr3;
00154       *ptr3 = *ptr4;
00155       *ptr4 = temp;
00156 
00157       /* Increase pointer */
00158       ptr1 --;
00159       ptr2 -= nx;
00160       ptr3 ++;
00161       ptr4 += nx;
00162     }
00163   }
00164 }
00165 
00166 /******************************************************************
00167  * Function: rotate_i4 = rotates INT array clockwise by 90. deg
00168  *
00169  *                      0 1 2       2 5 8
00170  *                      3 4 5  -->  1 4 7
00171  *                      6 7 8       0 3 6
00172  *
00173  *                      x,y -> y,(width-1-x)
00174  *
00175  ******************************************************************/
00176 void rotate_i4(unsigned int *data, int nx)
00177 {
00178   register unsigned int         *ptr1, *ptr2, *ptr3, *ptr4, temp;
00179   register int          i, j;
00180   int                   nx2 = (nx+1)/2;
00181 
00182   for ( i=nx/2; i--; ) {
00183 
00184     /* Set pointer addresses */
00185 
00186     j    = nx2 - 1;
00187     ptr1 = data + nx*i        + j;              /* 1. Quadrant */
00188     ptr2 = data + nx*j        + nx-1-i; /* 2. Quadrant */
00189     ptr3 = data + nx*(nx-1-i) + nx-1-j; /* 4. Quadrant */
00190     ptr4 = data + nx*(nx-1-j) + i;              /* 3. Quadrant */
00191 
00192     for ( j = nx2; j--; ) {
00193 
00194       /* Restack: clockwise rotation by 90.0 */
00195       temp  = *ptr4;
00196       *ptr4 = *ptr3;
00197       *ptr3 = *ptr2;
00198       *ptr2 = *ptr1;
00199       *ptr1 = temp;
00200 
00201       /* Increase pointer */
00202       ptr1 --;
00203       ptr2 -= nx;
00204       ptr3 ++;
00205       ptr4 += nx;
00206     }
00207   }
00208 }
00209 
00210 /******************************************************************
00211  * Function: rotate_i2 = rotates image clockwise by 90. deg
00212  *
00213  *                      0 1 2       2 5 8
00214  *                      3 4 5  -->  1 4 7
00215  *                      6 7 8       0 3 6
00216  *
00217  *                      x,y -> y,(width-1-x)
00218  *
00219  ******************************************************************/
00220 void rotate_i2(unsigned short *data, int nx)
00221 {
00222   register unsigned short *ptr1, *ptr2, *ptr3, *ptr4, temp;
00223   register int            i, j;
00224   int                     nx2 = (nx+1)/2;
00225 
00226   for ( i=nx/2; i--; ) {
00227 
00228     /* Set pointer addresses */
00229 
00230     j    = nx2 - 1;
00231     ptr1 = data + nx*i        + j;          /* 1. Quadrant */
00232     ptr2 = data + nx*j        + nx-1-i;     /* 2. Quadrant */
00233     ptr3 = data + nx*(nx-1-i) + nx-1-j;     /* 4. Quadrant */
00234     ptr4 = data + nx*(nx-1-j) + i;          /* 3. Quadrant */
00235 
00236     for ( j = nx2; j--; ) {
00237 
00238       /* Restack: clockwise rotation by 90.0 */
00239       temp  = *ptr4;
00240       *ptr4 = *ptr3;
00241       *ptr3 = *ptr2;
00242       *ptr2 = *ptr1;
00243       *ptr1 = temp;
00244 
00245       /* Increase pointer */
00246       ptr1 --;
00247       ptr2 -= nx;
00248       ptr3 ++;
00249       ptr4 += nx;
00250     }
00251   }
00252 }
00253 
00254 /******************************************************************
00255  * Function: rotate_ch = rotates image clockwise by 90. deg
00256  *
00257  *                      0 1 2       2 5 8
00258  *                      3 4 5  -->  1 4 7
00259  *                      6 7 8       0 3 6
00260  *
00261  *                      x,y -> y,(width-1-x)
00262  *
00263  ******************************************************************/
00264 void rotate_ch(unsigned char  *data, int nx)
00265 {
00266   register unsigned char  *ptr1, *ptr2, *ptr3, *ptr4, temp;
00267   register int            i, j;
00268   int                     nx2 = (nx+1)/2;
00269 
00270   for ( i=nx/2; i--; ) {
00271 
00272     /* Set pointer addresses */
00273 
00274     j    = nx2 - 1;
00275     ptr1 = data + nx*i        + j;          /* 1. Quadrant */
00276     ptr2 = data + nx*j        + nx-1-i;     /* 2. Quadrant */
00277     ptr3 = data + nx*(nx-1-i) + nx-1-j;     /* 4. Quadrant */
00278     ptr4 = data + nx*(nx-1-j) + i;          /* 3. Quadrant */
00279 
00280     for ( j = nx2; j--; ) {
00281 
00282       /* Restack: clockwise rotation by 90.0 */
00283       temp  = *ptr4;
00284       *ptr4 = *ptr3;
00285       *ptr3 = *ptr2;
00286       *ptr2 = *ptr1;
00287       *ptr1 = temp;
00288 
00289       /* Increase pointer */
00290       ptr1 --;
00291       ptr2 -= nx;
00292       ptr3 ++;
00293       ptr4 += nx;
00294     }
00295   }
00296 }
00297 
00298 /******************************************************************
00299  * Function: text = puts message in text field of main window
00300  ******************************************************************/
00301 void 
00302 wtext(int type, char *mess)
00303 {
00304   /* extern FILE *fpout; */
00305   if ( type == 1 ) {
00306     fprintf( stdout, "mar345 ERROR: %s\n", mess );
00307   }
00308   else {
00309     fprintf( stdout, "mar345 WARNING: %s\n", mess );
00310   }
00311 }