IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17457


Ignore:
Timestamp:
Apr 21, 2008, 8:16:58 AM (18 years ago)
Author:
eugene
Message:

the mask/keep region functions were evaluating the operator (strcmp) inside the inner loop; fixed this for a big speed savings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageMaskOps.c

    r12431 r17457  
    88 *  @author David Robbins, MHPCC
    99 *
    10  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2007-03-14 00:39:50 $
     10 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2008-04-21 18:16:58 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4444        return;
    4545    }
    46     for (int j = 0; j < image->numRows; j++) {
    47         for (int i = 0; i < image->numCols; i++) {
    48             if ( (j + image->row0) >= region.y0 &&
    49                     (j + image->row0) <= region.y1 &&
    50                     (i + image->col0) >= region.x0 &&
    51                     (i + image->col0) <= region.x1 ) {
    52                 if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
    53                     image->data.PS_TYPE_MASK_DATA[j][i] &= maskValue;
    54                 } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
    55                     image->data.PS_TYPE_MASK_DATA[j][i] |= maskValue;
    56                 } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
    57                     image->data.PS_TYPE_MASK_DATA[j][i] = maskValue;
    58                 } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
    59                     image->data.PS_TYPE_MASK_DATA[j][i] ^= maskValue;
    60                 } else {
    61                     psError(PS_ERR_BAD_PARAMETER_VALUE,true,
    62                             "The logical operation specified is incorrect\n");
    63                     return;
    64                 }
    65             }
    66         }
    67     }
    68     /*
    69         for (int iy = 0; iy < image->numRows; iy++) {
    70             for (int ix = 0; ix < image->numCols; ix++) {
    71                 if (ix + image->col0 >=  region.x0)
    72                     continue;
    73                 if (ix + image->col0 <= region.x1)
    74                     continue;
    75                 if (iy + image->row0 >=  region.y0)
    76                     continue;
    77                 if (iy + image->row0 <= region.y1)
    78                     continue;
    79                 if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
    80                     image->data.PS_TYPE_MASK_DATA[iy][ix] &= maskValue;
    81                 } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
    82                     image->data.PS_TYPE_MASK_DATA[iy][ix] |= maskValue;
    83                 } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
    84                     image->data.PS_TYPE_MASK_DATA[iy][ix] = maskValue;
    85                 } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
    86                     image->data.PS_TYPE_MASK_DATA[iy][ix] ^= maskValue;
    87                 }
    88             }
    89         }
    90     */
     46
     47
     48# define MASK_IT(OP) \
     49      for (int j = 0; j < image->numRows; j++) { \
     50        if ((j + image->row0) < region.y0) continue; \
     51        if ((j + image->row0) > region.y1) continue; /* is this correct (not >= ?) */ \
     52        for (int i = 0; i < image->numCols; i++) { \
     53          if ((i + image->col0) < region.x0) continue; \
     54          if ((i + image->col0) > region.x1) continue; /* is this correct (not >= ?) */ \
     55          image->data.PS_TYPE_MASK_DATA[j][i] OP maskValue; \
     56        } \
     57      }
     58
     59    if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
     60      MASK_IT (&=);
     61      return;
     62    }
     63    if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
     64      MASK_IT (|=);
     65      return;
     66    }
     67    if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
     68      MASK_IT (=);
     69      return;
     70    }
     71    if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
     72      MASK_IT (^=);
     73      return;
     74    }
     75
     76    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
     77            "The logical operation specified is incorrect\n");
     78    return;
    9179}
    9280
     
    10391        return;
    10492    }
    105     for (int j = 0; j < image->numRows; j++) {
    106         for (int i = 0; i < image->numCols; i++) {
    107             if ( (j + image->row0) < region.y0 ||
    108                     (j + image->row0) > region.y1 ||
    109                     (i + image->col0) < region.x0 ||
    110                     (i + image->col0) > region.x1 ) {
    111                 if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
    112                     image->data.PS_TYPE_MASK_DATA[j][i] &= maskValue;
    113                 } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
    114                     image->data.PS_TYPE_MASK_DATA[j][i] |= maskValue;
    115                 } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
    116                     image->data.PS_TYPE_MASK_DATA[j][i] = maskValue;
    117                 } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
    118                     image->data.PS_TYPE_MASK_DATA[j][i] ^= maskValue;
    119                 } else {
    120                     psError(PS_ERR_BAD_PARAMETER_VALUE,true,
    121                             "The logical operation specified is incorrect\n");
    122                     return;
    123                 }
    124             }
    125         }
    126     }
    127     /*
    128         for (int iy = 0; iy < image->numRows; iy++) {
    129             for (int ix = 0; ix < image->numCols; ix++) {
    130                 if (ix + image->col0 <  region.x0)
    131                     goto maskit;
    132                 if (ix + image->col0 > region.x1)
    133                     goto maskit;
    134                 if (iy + image->row0 <  region.y0)
    135                     goto maskit;
    136                 if (iy + image->row0 > region.y1)
    137                     goto maskit;
    138                 continue;
    139     maskit:
    140                 if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
    141                     image->data.PS_TYPE_MASK_DATA[iy][ix] &= maskValue;
    142                 } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
    143                     image->data.PS_TYPE_MASK_DATA[iy][ix] |= maskValue;
    144                 } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
    145                     image->data.PS_TYPE_MASK_DATA[iy][ix] = maskValue;
    146                 } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
    147                     image->data.PS_TYPE_MASK_DATA[iy][ix] ^= maskValue;
    148                 }
    149             }Robert DeSonia, MHPCC
    150     *  @author Ross Harman, MHPCC
    151         }
    152     */
     93
     94
     95# define KEEP_IT(OP) \
     96    for (int j = 0; j < image->numRows; j++) { \
     97      for (int i = 0; i < image->numCols; i++) { \
     98        if ((j + image->row0) < region.y0 || \
     99            (j + image->row0) > region.y1 || \
     100            (i + image->col0) < region.x0 || \
     101            (i + image->col0) > region.x1 ) { \
     102          image->data.PS_TYPE_MASK_DATA[j][i] OP maskValue; \
     103        } } }
     104
     105    if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
     106      KEEP_IT(&=);
     107      return;
     108    }
     109    if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
     110      KEEP_IT(|=);
     111      return;
     112    }
     113    if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
     114      KEEP_IT(=);
     115      return;
     116    }
     117    if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
     118      KEEP_IT(^=);
     119      return;
     120    }
     121    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
     122            "The logical operation specified is incorrect\n");
     123    return;
    153124}
    154125
     
    168139    }
    169140
    170 
    171141    double dx, dy, r2, R2;
    172142
    173143    R2 = PS_SQR(radius);
    174144
    175     for (int iy = 0; iy < image->numRows; iy++) {
    176         for (int ix = 0; ix < image->numCols; ix++) {
    177             dx = ix + image->col0 - x;
    178             dy = iy + image->row0 - y;
    179             r2 = PS_SQR(dx) + PS_SQR(dy);
    180             if (r2 <= R2) {
    181                 if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
    182                     image->data.PS_TYPE_MASK_DATA[iy][ix] &= maskValue;
    183                 } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
    184                     image->data.PS_TYPE_MASK_DATA[iy][ix] |= maskValue;
    185                 } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
    186                     image->data.PS_TYPE_MASK_DATA[iy][ix] = maskValue;
    187                 } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
    188                     image->data.PS_TYPE_MASK_DATA[iy][ix] ^= maskValue;
    189                 } else {
    190                     psError(PS_ERR_BAD_PARAMETER_VALUE,true,
    191                             "The logical operation specified is incorrect\n");
    192                     return;
    193                 }
    194             }
    195         }
    196     }
     145# define MASK_IT_CIRCLE(OP) \
     146    for (int iy = 0; iy < image->numRows; iy++) { \
     147        for (int ix = 0; ix < image->numCols; ix++) { \
     148            dx = ix + image->col0 - x; \
     149            dy = iy + image->row0 - y; \
     150            r2 = PS_SQR(dx) + PS_SQR(dy); \
     151            if (r2 <= R2) { \
     152              image->data.PS_TYPE_MASK_DATA[iy][ix] OP maskValue; \
     153            } } }
     154
     155    if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
     156      MASK_IT_CIRCLE (&=);
     157      return;
     158    }
     159    if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
     160      MASK_IT_CIRCLE (|=);
     161      return;
     162    }
     163    if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
     164      MASK_IT_CIRCLE (=);
     165      return;
     166    }
     167    if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
     168      MASK_IT_CIRCLE (^=);
     169      return;
     170    }
     171
     172    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
     173            "The logical operation specified is incorrect\n");
     174    return;
    197175}
    198176
     
    216194    R2 = PS_SQR(radius);
    217195
    218     for (int iy = 0; iy < image->numRows; iy++) {
    219         for (int ix = 0; ix < image->numCols; ix++) {
    220             dx = ix + image->col0 - x;
    221             dy = iy + image->row0 - y;
    222             r2 = PS_SQR(dx) + PS_SQR(dy);
    223             if (r2 > R2) {
    224                 if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
    225                     image->data.PS_TYPE_MASK_DATA[iy][ix] &= maskValue;
    226                 } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
    227                     image->data.PS_TYPE_MASK_DATA[iy][ix] |= maskValue;
    228                 } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
    229                     image->data.PS_TYPE_MASK_DATA[iy][ix] = maskValue;
    230                 } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
    231                     image->data.PS_TYPE_MASK_DATA[iy][ix] ^= maskValue;
    232                 } else {
    233                     psError(PS_ERR_BAD_PARAMETER_VALUE,true,
    234                             "The logical operation specified is incorrect\n");
    235                     return;
    236                 }
    237             }
    238         }
    239     }
     196# define KEEP_IT_CIRCLE(OP) \
     197    for (int iy = 0; iy < image->numRows; iy++) { \
     198        for (int ix = 0; ix < image->numCols; ix++) { \
     199            dx = ix + image->col0 - x; \
     200            dy = iy + image->row0 - y; \
     201            r2 = PS_SQR(dx) + PS_SQR(dy); \
     202            if (r2 > R2) { \
     203              image->data.PS_TYPE_MASK_DATA[iy][ix] OP maskValue; \
     204            } } }
     205
     206    if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
     207      KEEP_IT_CIRCLE (&=);
     208      return;
     209    }
     210    if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
     211      KEEP_IT_CIRCLE (|=);
     212      return;
     213    }
     214    if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
     215      KEEP_IT_CIRCLE (=);
     216      return;
     217    }
     218    if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
     219      KEEP_IT_CIRCLE (^=);
     220      return;
     221    }
     222
     223    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
     224            "The logical operation specified is incorrect\n");
     225    return;
    240226}
    241227
Note: See TracChangeset for help on using the changeset viewer.