< prev index next >

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

Print this page
rev 59106 : imported patch client


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


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


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


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


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


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


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

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


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


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



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