< prev index next >

src/java.desktop/share/native/libmlib_image/mlib_ImageConv_16nw.c

Print this page
rev 59106 : imported patch client


 146 /***************************************************************/
 147 #define DEF_VARS(type)                                          \
 148   type     *adr_src, *sl, *sp = NULL;                           \
 149   type     *adr_dst, *dl, *dp = NULL;                           \
 150   FTYPE    *pbuff = buff;                                       \
 151   mlib_s32 wid, hgt, sll, dll;                                  \
 152   mlib_s32 nchannel, chan1;                                     \
 153   mlib_s32 i, j, c
 154 
 155 /***************************************************************/
 156 #define GET_SRC_DST_PARAMETERS(type)                            \
 157   hgt = mlib_ImageGetHeight(src);                               \
 158   wid = mlib_ImageGetWidth(src);                                \
 159   nchannel = mlib_ImageGetChannels(src);                        \
 160   sll = mlib_ImageGetStride(src) / sizeof(type);                \
 161   dll = mlib_ImageGetStride(dst) / sizeof(type);                \
 162   adr_src = (type *)mlib_ImageGetData(src);                     \
 163   adr_dst = (type *)mlib_ImageGetData(dst)
 164 
 165 /***************************************************************/
 166 #ifndef __sparc
 167 
 168 #if IMG_TYPE == 1
 169 
 170 /* Test for the presence of any "1" bit in bits
 171    8 to 31 of val. If present, then val is either
 172    negative or >255. If over/underflows of 8 bits
 173    are uncommon, then this technique can be a win,
 174    since only a single test, rather than two, is
 175    necessary to determine if clamping is needed.
 176    On the other hand, if over/underflows are common,
 177    it adds an extra test.
 178 */
 179 #define CLAMP_STORE(dst, val)                                   \
 180   if (val & 0xffffff00) {                                       \
 181     if (val < MLIB_U8_MIN)                                      \
 182       dst = MLIB_U8_MIN;                                        \
 183     else                                                        \
 184       dst = MLIB_U8_MAX;                                        \
 185   } else {                                                      \
 186     dst = (mlib_u8)val;                                         \
 187   }


 190 
 191 #define CLAMP_STORE(dst, val)                                   \
 192   if (val >= MLIB_S16_MAX)                                      \
 193     dst = MLIB_S16_MAX;                                         \
 194   else if (val <= MLIB_S16_MIN)                                 \
 195     dst = MLIB_S16_MIN;                                         \
 196   else                                                          \
 197     dst = (mlib_s16)val
 198 
 199 #elif IMG_TYPE == 3
 200 
 201 #define CLAMP_STORE(dst, val)                                   \
 202   if (val >= MLIB_U16_MAX)                                      \
 203     dst = MLIB_U16_MAX;                                         \
 204   else if (val <= MLIB_U16_MIN)                                 \
 205     dst = MLIB_U16_MIN;                                         \
 206   else                                                          \
 207     dst = (mlib_u16)val
 208 
 209 #endif /* IMG_TYPE == 1 */
 210 #endif /* __sparc */
 211 
 212 /***************************************************************/
 213 #define MAX_KER   7
 214 #define MAX_N    15
 215 
 216 static mlib_status mlib_ImageConv1xN(mlib_image       *dst,
 217                                      const mlib_image *src,
 218                                      const mlib_d64   *k,
 219                                      mlib_s32         n,
 220                                      mlib_s32         dn,
 221                                      mlib_s32         cmask)
 222 {
 223   FTYPE    buff[BUFF_SIZE];
 224   mlib_s32 off, kh;
 225   mlib_s32 d0, d1;
 226   const FTYPE    *pk;
 227   FTYPE    k0, k1, k2, k3;
 228   FTYPE    p0, p1, p2, p3, p4;
 229   DEF_VARS(DTYPE);
 230   DTYPE    *sl_c, *dl_c, *sl0;


 836         sp += chan1;
 837         dp += chan1;
 838       }
 839 
 840       for (l = 0; l < (m - 1); l++) buffn[wid + l] = sp[l*chan1];
 841 
 842       /* next line */
 843       sl += sll;
 844       dl += dll;
 845 
 846       buff_ind++;
 847 
 848       if (buff_ind >= n + 1) buff_ind = 0;
 849     }
 850   }
 851 
 852   FREE_AND_RETURN_STATUS;
 853 }
 854 
 855 /***************************************************************/
 856 #ifndef __sparc /* for x86, using integer multiplies is faster */
 857 
 858 #define STORE_RES(res, x)                                       \
 859   x >>= shift2;                                                 \
 860   CLAMP_STORE(res, x)
 861 
 862 mlib_status CONV_FUNC_I(MxN)(mlib_image       *dst,
 863                              const mlib_image *src,
 864                              const mlib_s32   *kernel,
 865                              mlib_s32         m,
 866                              mlib_s32         n,
 867                              mlib_s32         dm,
 868                              mlib_s32         dn,
 869                              mlib_s32         scale,
 870                              mlib_s32         cmask)
 871 {
 872   mlib_s32 buff[BUFF_SIZE], *buffd = buff;
 873   mlib_s32 l, off, kw;
 874   mlib_s32 d0, d1, shift1, shift2;
 875   mlib_s32 k0, k1, k2, k3, k4, k5, k6;
 876   mlib_s32 p0, p1, p2, p3, p4, p5, p6, p7;


1247             pk ++;
1248           }
1249         }
1250 
1251         STORE_RES(dp[0], s);
1252 
1253         sp += chan1;
1254         dp += chan1;
1255       }
1256 
1257       sl += sll;
1258       dl += dll;
1259     }
1260   }
1261 
1262   if (buffd != buff) mlib_free(buffd);
1263   if (k != k_locl) mlib_free(k);
1264 
1265   return MLIB_SUCCESS;
1266 }
1267 
1268 /***************************************************************/
1269 #endif /* __sparc ( for x86, using integer multiplies is faster ) */
1270 
1271 /***************************************************************/


 146 /***************************************************************/
 147 #define DEF_VARS(type)                                          \
 148   type     *adr_src, *sl, *sp = NULL;                           \
 149   type     *adr_dst, *dl, *dp = NULL;                           \
 150   FTYPE    *pbuff = buff;                                       \
 151   mlib_s32 wid, hgt, sll, dll;                                  \
 152   mlib_s32 nchannel, chan1;                                     \
 153   mlib_s32 i, j, c
 154 
 155 /***************************************************************/
 156 #define GET_SRC_DST_PARAMETERS(type)                            \
 157   hgt = mlib_ImageGetHeight(src);                               \
 158   wid = mlib_ImageGetWidth(src);                                \
 159   nchannel = mlib_ImageGetChannels(src);                        \
 160   sll = mlib_ImageGetStride(src) / sizeof(type);                \
 161   dll = mlib_ImageGetStride(dst) / sizeof(type);                \
 162   adr_src = (type *)mlib_ImageGetData(src);                     \
 163   adr_dst = (type *)mlib_ImageGetData(dst)
 164 
 165 /***************************************************************/


 166 #if IMG_TYPE == 1
 167 
 168 /* Test for the presence of any "1" bit in bits
 169    8 to 31 of val. If present, then val is either
 170    negative or >255. If over/underflows of 8 bits
 171    are uncommon, then this technique can be a win,
 172    since only a single test, rather than two, is
 173    necessary to determine if clamping is needed.
 174    On the other hand, if over/underflows are common,
 175    it adds an extra test.
 176 */
 177 #define CLAMP_STORE(dst, val)                                   \
 178   if (val & 0xffffff00) {                                       \
 179     if (val < MLIB_U8_MIN)                                      \
 180       dst = MLIB_U8_MIN;                                        \
 181     else                                                        \
 182       dst = MLIB_U8_MAX;                                        \
 183   } else {                                                      \
 184     dst = (mlib_u8)val;                                         \
 185   }


 188 
 189 #define CLAMP_STORE(dst, val)                                   \
 190   if (val >= MLIB_S16_MAX)                                      \
 191     dst = MLIB_S16_MAX;                                         \
 192   else if (val <= MLIB_S16_MIN)                                 \
 193     dst = MLIB_S16_MIN;                                         \
 194   else                                                          \
 195     dst = (mlib_s16)val
 196 
 197 #elif IMG_TYPE == 3
 198 
 199 #define CLAMP_STORE(dst, val)                                   \
 200   if (val >= MLIB_U16_MAX)                                      \
 201     dst = MLIB_U16_MAX;                                         \
 202   else if (val <= MLIB_U16_MIN)                                 \
 203     dst = MLIB_U16_MIN;                                         \
 204   else                                                          \
 205     dst = (mlib_u16)val
 206 
 207 #endif /* IMG_TYPE == 1 */

 208 
 209 /***************************************************************/
 210 #define MAX_KER   7
 211 #define MAX_N    15
 212 
 213 static mlib_status mlib_ImageConv1xN(mlib_image       *dst,
 214                                      const mlib_image *src,
 215                                      const mlib_d64   *k,
 216                                      mlib_s32         n,
 217                                      mlib_s32         dn,
 218                                      mlib_s32         cmask)
 219 {
 220   FTYPE    buff[BUFF_SIZE];
 221   mlib_s32 off, kh;
 222   mlib_s32 d0, d1;
 223   const FTYPE    *pk;
 224   FTYPE    k0, k1, k2, k3;
 225   FTYPE    p0, p1, p2, p3, p4;
 226   DEF_VARS(DTYPE);
 227   DTYPE    *sl_c, *dl_c, *sl0;


 833         sp += chan1;
 834         dp += chan1;
 835       }
 836 
 837       for (l = 0; l < (m - 1); l++) buffn[wid + l] = sp[l*chan1];
 838 
 839       /* next line */
 840       sl += sll;
 841       dl += dll;
 842 
 843       buff_ind++;
 844 
 845       if (buff_ind >= n + 1) buff_ind = 0;
 846     }
 847   }
 848 
 849   FREE_AND_RETURN_STATUS;
 850 }
 851 
 852 /***************************************************************/
 853 /* for x86, using integer multiplies is faster */
 854 
 855 #define STORE_RES(res, x)                                       \
 856   x >>= shift2;                                                 \
 857   CLAMP_STORE(res, x)
 858 
 859 mlib_status CONV_FUNC_I(MxN)(mlib_image       *dst,
 860                              const mlib_image *src,
 861                              const mlib_s32   *kernel,
 862                              mlib_s32         m,
 863                              mlib_s32         n,
 864                              mlib_s32         dm,
 865                              mlib_s32         dn,
 866                              mlib_s32         scale,
 867                              mlib_s32         cmask)
 868 {
 869   mlib_s32 buff[BUFF_SIZE], *buffd = buff;
 870   mlib_s32 l, off, kw;
 871   mlib_s32 d0, d1, shift1, shift2;
 872   mlib_s32 k0, k1, k2, k3, k4, k5, k6;
 873   mlib_s32 p0, p1, p2, p3, p4, p5, p6, p7;


1244             pk ++;
1245           }
1246         }
1247 
1248         STORE_RES(dp[0], s);
1249 
1250         sp += chan1;
1251         dp += chan1;
1252       }
1253 
1254       sl += sll;
1255       dl += dll;
1256     }
1257   }
1258 
1259   if (buffd != buff) mlib_free(buffd);
1260   if (k != k_locl) mlib_free(k);
1261 
1262   return MLIB_SUCCESS;
1263 }



1264 
1265 /***************************************************************/
< prev index next >